blob: f6da85e3f2af994a91a88020dc2b1165af6f3436 [file] [log] [blame]
Dan Williams6f231dd2011-07-02 22:56:22 -07001/*
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 */
Dan Williams88f3b622011-04-22 19:18:03 -070055#include "intel_sas.h"
Dan Williamsab2e8f72011-04-27 16:32:45 -070056#include "intel_ata.h"
Dan Williams6f231dd2011-07-02 22:56:22 -070057#include "isci.h"
Dan Williams6f231dd2011-07-02 22:56:22 -070058#include "port.h"
59#include "remote_device.h"
60#include "request.h"
Dan Williams88f3b622011-04-22 19:18:03 -070061#include "scic_controller.h"
62#include "scic_io_request.h"
63#include "scic_phy.h"
64#include "scic_port.h"
65#include "scic_sds_controller.h"
66#include "scic_sds_phy.h"
67#include "scic_sds_port.h"
68#include "remote_node_context.h"
69#include "scic_sds_request.h"
70#include "sci_environment.h"
71#include "sci_util.h"
72#include "scu_event_codes.h"
Dan Williams6f231dd2011-07-02 22:56:22 -070073#include "task.h"
74
Dan Williamsab2e8f72011-04-27 16:32:45 -070075/**
76 * isci_remote_device_change_state() - This function gets the status of the
77 * remote_device object.
78 * @isci_device: This parameter points to the isci_remote_device object
79 *
80 * status of the object as a isci_status enum.
81 */
82void isci_remote_device_change_state(
83 struct isci_remote_device *isci_device,
84 enum isci_status status)
85{
86 unsigned long flags;
87
88 spin_lock_irqsave(&isci_device->state_lock, flags);
89 isci_device->status = status;
90 spin_unlock_irqrestore(&isci_device->state_lock, flags);
91}
92
93/**
94 * isci_remote_device_not_ready() - This function is called by the scic when
95 * the remote device is not ready. We mark the isci device as ready (not
96 * "ready_for_io") and signal the waiting proccess.
97 * @isci_host: This parameter specifies the isci host object.
98 * @isci_device: This parameter specifies the remote device
99 *
100 */
101static void isci_remote_device_not_ready(struct isci_host *ihost,
102 struct isci_remote_device *idev, u32 reason)
103{
104 dev_dbg(&ihost->pdev->dev,
105 "%s: isci_device = %p\n", __func__, idev);
106
107 if (reason == SCIC_REMOTE_DEVICE_NOT_READY_STOP_REQUESTED)
108 isci_remote_device_change_state(idev, isci_stopping);
109 else
110 /* device ready is actually a "not ready for io" state. */
111 isci_remote_device_change_state(idev, isci_ready);
112}
113
114/**
115 * isci_remote_device_ready() - This function is called by the scic when the
116 * remote device is ready. We mark the isci device as ready and signal the
117 * waiting proccess.
118 * @ihost: our valid isci_host
119 * @idev: remote device
120 *
121 */
122static void isci_remote_device_ready(struct isci_host *ihost, struct isci_remote_device *idev)
123{
124 dev_dbg(&ihost->pdev->dev,
125 "%s: idev = %p\n", __func__, idev);
126
127 isci_remote_device_change_state(idev, isci_ready_for_io);
128 if (test_and_clear_bit(IDEV_START_PENDING, &idev->flags))
129 wake_up(&ihost->eventq);
130}
131
132
133
Dan Williams88f3b622011-04-22 19:18:03 -0700134enum sci_status scic_remote_device_stop(
135 struct scic_sds_remote_device *sci_dev,
136 u32 timeout)
137{
138 return sci_dev->state_handlers->stop_handler(sci_dev);
139}
Dan Williams6f231dd2011-07-02 22:56:22 -0700140
141
Dan Williams88f3b622011-04-22 19:18:03 -0700142enum sci_status scic_remote_device_reset(
143 struct scic_sds_remote_device *sci_dev)
144{
145 return sci_dev->state_handlers->reset_handler(sci_dev);
146}
147
148
149enum sci_status scic_remote_device_reset_complete(
150 struct scic_sds_remote_device *sci_dev)
151{
152 return sci_dev->state_handlers->reset_complete_handler(sci_dev);
153}
154
155
156enum sas_linkrate scic_remote_device_get_connection_rate(
157 struct scic_sds_remote_device *sci_dev)
158{
159 return sci_dev->connection_rate;
160}
161
Dan Williams88f3b622011-04-22 19:18:03 -0700162/**
163 *
164 *
165 * Remote device timer requirements
166 */
167#define SCIC_SDS_REMOTE_DEVICE_MINIMUM_TIMER_COUNT (0)
168#define SCIC_SDS_REMOTE_DEVICE_MAXIMUM_TIMER_COUNT (SCI_MAX_REMOTE_DEVICES)
169
170
171/**
172 *
173 * @sci_dev: The remote device for which the suspend is being requested.
174 *
175 * This method invokes the remote device suspend state handler. enum sci_status
176 */
177enum sci_status scic_sds_remote_device_suspend(
178 struct scic_sds_remote_device *sci_dev,
179 u32 suspend_type)
180{
181 return sci_dev->state_handlers->suspend_handler(sci_dev, suspend_type);
182}
183
184/**
185 *
186 * @sci_dev: The remote device for which the event handling is being
187 * requested.
188 * @frame_index: This is the frame index that is being processed.
189 *
190 * This method invokes the frame handler for the remote device state machine
191 * enum sci_status
192 */
193enum sci_status scic_sds_remote_device_frame_handler(
194 struct scic_sds_remote_device *sci_dev,
195 u32 frame_index)
196{
197 return sci_dev->state_handlers->frame_handler(sci_dev, frame_index);
198}
199
200/**
201 *
202 * @sci_dev: The remote device for which the event handling is being
203 * requested.
204 * @event_code: This is the event code that is to be processed.
205 *
206 * This method invokes the remote device event handler. enum sci_status
207 */
208enum sci_status scic_sds_remote_device_event_handler(
209 struct scic_sds_remote_device *sci_dev,
210 u32 event_code)
211{
212 return sci_dev->state_handlers->event_handler(sci_dev, event_code);
213}
214
215/**
216 *
217 * @controller: The controller that is starting the io request.
218 * @sci_dev: The remote device for which the start io handling is being
219 * requested.
220 * @io_request: The io request that is being started.
221 *
222 * This method invokes the remote device start io handler. enum sci_status
223 */
224enum sci_status scic_sds_remote_device_start_io(
225 struct scic_sds_controller *controller,
226 struct scic_sds_remote_device *sci_dev,
227 struct scic_sds_request *io_request)
228{
229 return sci_dev->state_handlers->start_io_handler(
230 sci_dev, io_request);
231}
232
233/**
234 *
235 * @controller: The controller that is completing the io request.
236 * @sci_dev: The remote device for which the complete io handling is being
237 * requested.
238 * @io_request: The io request that is being completed.
239 *
240 * This method invokes the remote device complete io handler. enum sci_status
241 */
242enum sci_status scic_sds_remote_device_complete_io(
243 struct scic_sds_controller *controller,
244 struct scic_sds_remote_device *sci_dev,
245 struct scic_sds_request *io_request)
246{
247 return sci_dev->state_handlers->complete_io_handler(
248 sci_dev, io_request);
249}
250
251/**
252 *
253 * @controller: The controller that is starting the task request.
254 * @sci_dev: The remote device for which the start task handling is being
255 * requested.
256 * @io_request: The task request that is being started.
257 *
258 * This method invokes the remote device start task handler. enum sci_status
259 */
260enum sci_status scic_sds_remote_device_start_task(
261 struct scic_sds_controller *controller,
262 struct scic_sds_remote_device *sci_dev,
263 struct scic_sds_request *io_request)
264{
265 return sci_dev->state_handlers->start_task_handler(
266 sci_dev, io_request);
267}
268
269/**
270 *
Dan Williams88f3b622011-04-22 19:18:03 -0700271 * @sci_dev:
272 * @request:
273 *
274 * This method takes the request and bulids an appropriate SCU context for the
275 * request and then requests the controller to post the request. none
276 */
277void scic_sds_remote_device_post_request(
278 struct scic_sds_remote_device *sci_dev,
279 u32 request)
280{
281 u32 context;
282
283 context = scic_sds_remote_device_build_command_context(sci_dev, request);
284
285 scic_sds_controller_post_request(
286 scic_sds_remote_device_get_controller(sci_dev),
287 context
288 );
289}
290
Dan Williamsab2e8f72011-04-27 16:32:45 -0700291/* called once the remote node context is ready to be freed.
Dan Williams88f3b622011-04-22 19:18:03 -0700292 * The remote device can now report that its stop operation is complete. none
293 */
Dan Williamsab2e8f72011-04-27 16:32:45 -0700294static void scic_sds_cb_remote_device_rnc_destruct_complete(void *_dev)
Dan Williams88f3b622011-04-22 19:18:03 -0700295{
Dan Williamsab2e8f72011-04-27 16:32:45 -0700296 struct scic_sds_remote_device *sci_dev = _dev;
Dan Williams88f3b622011-04-22 19:18:03 -0700297
298 BUG_ON(sci_dev->started_request_count != 0);
Dan Williams88f3b622011-04-22 19:18:03 -0700299 sci_base_state_machine_change_state(&sci_dev->state_machine,
300 SCI_BASE_REMOTE_DEVICE_STATE_STOPPED);
301}
302
Dan Williamsab2e8f72011-04-27 16:32:45 -0700303/* called once the remote node context has transisitioned to a
Dan Williams88f3b622011-04-22 19:18:03 -0700304 * ready state. This is the indication that the remote device object can also
Dan Williamsab2e8f72011-04-27 16:32:45 -0700305 * transition to ready.
Dan Williams88f3b622011-04-22 19:18:03 -0700306 */
Dan Williamsab2e8f72011-04-27 16:32:45 -0700307static void scic_sds_remote_device_resume_complete_handler(void *_dev)
Dan Williams88f3b622011-04-22 19:18:03 -0700308{
Dan Williamsab2e8f72011-04-27 16:32:45 -0700309 struct scic_sds_remote_device *sci_dev = _dev;
310 enum scic_sds_remote_device_states state;
Dan Williams88f3b622011-04-22 19:18:03 -0700311
Dan Williamsab2e8f72011-04-27 16:32:45 -0700312 state = sci_dev->state_machine.current_state_id;
313 switch (state) {
314 case SCI_BASE_REMOTE_DEVICE_STATE_READY:
315 case SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_IDLE:
316 case SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_CMD:
317 case SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_NCQ:
318 case SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_NCQ_ERROR:
319 case SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_AWAIT_RESET:
320 case SCIC_SDS_SMP_REMOTE_DEVICE_READY_SUBSTATE_IDLE:
321 case SCIC_SDS_SMP_REMOTE_DEVICE_READY_SUBSTATE_CMD:
322 break;
323 default:
324 /* go 'ready' if we are not already in a ready state */
325 sci_base_state_machine_change_state(&sci_dev->state_machine,
326 SCI_BASE_REMOTE_DEVICE_STATE_READY);
327 break;
Dan Williams88f3b622011-04-22 19:18:03 -0700328 }
329}
330
331/**
332 *
333 * @device: This parameter specifies the device for which the request is being
334 * started.
335 * @request: This parameter specifies the request being started.
336 * @status: This parameter specifies the current start operation status.
337 *
338 * This method will perform the STP request start processing common to IO
339 * requests and task requests of all types. none
340 */
Dan Williamsab2e8f72011-04-27 16:32:45 -0700341static void scic_sds_remote_device_start_request(
Dan Williams88f3b622011-04-22 19:18:03 -0700342 struct scic_sds_remote_device *sci_dev,
343 struct scic_sds_request *sci_req,
344 enum sci_status status)
345{
346 /* We still have a fault in starting the io complete it on the port */
347 if (status == SCI_SUCCESS)
348 scic_sds_remote_device_increment_request_count(sci_dev);
349 else{
350 sci_dev->owning_port->state_handlers->complete_io_handler(
351 sci_dev->owning_port, sci_dev, sci_req
352 );
353 }
354}
355
356
357/**
358 *
359 * @request: This parameter specifies the request being continued.
360 *
361 * This method will continue to post tc for a STP request. This method usually
362 * serves as a callback when RNC gets resumed during a task management
363 * sequence. none
364 */
Dan Williamsab2e8f72011-04-27 16:32:45 -0700365static void scic_sds_remote_device_continue_request(void *dev)
Dan Williams88f3b622011-04-22 19:18:03 -0700366{
367 struct scic_sds_remote_device *sci_dev = dev;
368
369 /* we need to check if this request is still valid to continue. */
370 if (sci_dev->working_request)
371 scic_controller_continue_io(sci_dev->working_request);
372}
373
374/**
375 * This method will terminate all of the IO requests in the controllers IO
376 * request table that were targeted for this device.
377 * @sci_dev: This parameter specifies the remote device for which to
378 * attempt to terminate all requests.
379 *
380 * This method returns an indication as to whether all requests were
381 * successfully terminated. If a single request fails to be terminated, then
382 * this method will return the failure.
383 */
384static enum sci_status scic_sds_remote_device_terminate_requests(
385 struct scic_sds_remote_device *sci_dev)
386{
387 enum sci_status status = SCI_SUCCESS;
388 enum sci_status terminate_status = SCI_SUCCESS;
389 struct scic_sds_request *sci_req;
390 u32 index;
391 u32 request_count = sci_dev->started_request_count;
392
393 for (index = 0;
394 (index < SCI_MAX_IO_REQUESTS) && (request_count > 0);
395 index++) {
396 sci_req = sci_dev->owning_port->owning_controller->io_request_table[index];
397
398 if ((sci_req != NULL) && (sci_req->target_device == sci_dev)) {
399 terminate_status = scic_controller_terminate_request(
400 sci_dev->owning_port->owning_controller,
401 sci_dev,
402 sci_req
403 );
404
405 if (terminate_status != SCI_SUCCESS)
406 status = terminate_status;
407
408 request_count--;
409 }
410 }
411
412 return status;
413}
414
415static enum sci_status
416default_device_handler(struct scic_sds_remote_device *sci_dev,
417 const char *func)
418{
419 dev_warn(scirdev_to_dev(sci_dev),
420 "%s: in wrong state: %d\n", func,
421 sci_base_state_machine_get_state(&sci_dev->state_machine));
422 return SCI_FAILURE_INVALID_STATE;
423}
424
Dan Williamsab2e8f72011-04-27 16:32:45 -0700425static enum sci_status scic_sds_remote_device_default_start_handler(
Dan Williams88f3b622011-04-22 19:18:03 -0700426 struct scic_sds_remote_device *sci_dev)
427{
428 return default_device_handler(sci_dev, __func__);
429}
430
431static enum sci_status scic_sds_remote_device_default_stop_handler(
432 struct scic_sds_remote_device *sci_dev)
433{
434 return default_device_handler(sci_dev, __func__);
435}
436
Dan Williamsab2e8f72011-04-27 16:32:45 -0700437static enum sci_status scic_sds_remote_device_default_fail_handler(
Dan Williams88f3b622011-04-22 19:18:03 -0700438 struct scic_sds_remote_device *sci_dev)
439{
440 return default_device_handler(sci_dev, __func__);
441}
442
Dan Williamsab2e8f72011-04-27 16:32:45 -0700443static enum sci_status scic_sds_remote_device_default_destruct_handler(
Dan Williams88f3b622011-04-22 19:18:03 -0700444 struct scic_sds_remote_device *sci_dev)
445{
446 return default_device_handler(sci_dev, __func__);
447}
448
Dan Williamsab2e8f72011-04-27 16:32:45 -0700449static enum sci_status scic_sds_remote_device_default_reset_handler(
Dan Williams88f3b622011-04-22 19:18:03 -0700450 struct scic_sds_remote_device *sci_dev)
451{
452 return default_device_handler(sci_dev, __func__);
453}
454
Dan Williamsab2e8f72011-04-27 16:32:45 -0700455static enum sci_status scic_sds_remote_device_default_reset_complete_handler(
Dan Williams88f3b622011-04-22 19:18:03 -0700456 struct scic_sds_remote_device *sci_dev)
457{
458 return default_device_handler(sci_dev, __func__);
459}
460
Dan Williamsab2e8f72011-04-27 16:32:45 -0700461static enum sci_status scic_sds_remote_device_default_suspend_handler(
Dan Williams88f3b622011-04-22 19:18:03 -0700462 struct scic_sds_remote_device *sci_dev, u32 suspend_type)
463{
464 return default_device_handler(sci_dev, __func__);
465}
466
Dan Williamsab2e8f72011-04-27 16:32:45 -0700467static enum sci_status scic_sds_remote_device_default_resume_handler(
Dan Williams88f3b622011-04-22 19:18:03 -0700468 struct scic_sds_remote_device *sci_dev)
469{
470 return default_device_handler(sci_dev, __func__);
471}
472
473/**
474 *
475 * @device: The struct scic_sds_remote_device which is then cast into a
476 * struct scic_sds_remote_device.
477 * @event_code: The event code that the struct scic_sds_controller wants the device
478 * object to process.
479 *
480 * This method is the default event handler. It will call the RNC state
481 * machine handler for any RNC events otherwise it will log a warning and
482 * returns a failure. enum sci_status SCI_FAILURE_INVALID_STATE
483 */
484static enum sci_status scic_sds_remote_device_core_event_handler(
485 struct scic_sds_remote_device *sci_dev,
486 u32 event_code,
487 bool is_ready_state)
488{
489 enum sci_status status;
490
491 switch (scu_get_event_type(event_code)) {
492 case SCU_EVENT_TYPE_RNC_OPS_MISC:
493 case SCU_EVENT_TYPE_RNC_SUSPEND_TX:
494 case SCU_EVENT_TYPE_RNC_SUSPEND_TX_RX:
495 status = scic_sds_remote_node_context_event_handler(&sci_dev->rnc, event_code);
496 break;
497 case SCU_EVENT_TYPE_PTX_SCHEDULE_EVENT:
498
499 if (scu_get_event_code(event_code) == SCU_EVENT_IT_NEXUS_TIMEOUT) {
500 status = SCI_SUCCESS;
501
502 /* Suspend the associated RNC */
503 scic_sds_remote_node_context_suspend(&sci_dev->rnc,
504 SCI_SOFTWARE_SUSPENSION,
505 NULL, NULL);
506
507 dev_dbg(scirdev_to_dev(sci_dev),
508 "%s: device: %p event code: %x: %s\n",
509 __func__, sci_dev, event_code,
510 (is_ready_state)
511 ? "I_T_Nexus_Timeout event"
512 : "I_T_Nexus_Timeout event in wrong state");
513
514 break;
515 }
516 /* Else, fall through and treat as unhandled... */
517
518 default:
519 dev_dbg(scirdev_to_dev(sci_dev),
520 "%s: device: %p event code: %x: %s\n",
521 __func__, sci_dev, event_code,
522 (is_ready_state)
523 ? "unexpected event"
524 : "unexpected event in wrong state");
525 status = SCI_FAILURE_INVALID_STATE;
526 break;
527 }
528
529 return status;
530}
531/**
532 *
533 * @device: The struct scic_sds_remote_device which is then cast into a
534 * struct scic_sds_remote_device.
535 * @event_code: The event code that the struct scic_sds_controller wants the device
536 * object to process.
537 *
538 * This method is the default event handler. It will call the RNC state
539 * machine handler for any RNC events otherwise it will log a warning and
540 * returns a failure. enum sci_status SCI_FAILURE_INVALID_STATE
541 */
542static enum sci_status scic_sds_remote_device_default_event_handler(
543 struct scic_sds_remote_device *sci_dev,
544 u32 event_code)
545{
546 return scic_sds_remote_device_core_event_handler(sci_dev,
547 event_code,
548 false);
549}
550
551/**
552 *
553 * @device: The struct scic_sds_remote_device which is then cast into a
554 * struct scic_sds_remote_device.
555 * @frame_index: The frame index for which the struct scic_sds_controller wants this
556 * device object to process.
557 *
558 * This method is the default unsolicited frame handler. It logs a warning,
559 * releases the frame and returns a failure. enum sci_status
560 * SCI_FAILURE_INVALID_STATE
561 */
Dan Williamsab2e8f72011-04-27 16:32:45 -0700562static enum sci_status scic_sds_remote_device_default_frame_handler(
Dan Williams88f3b622011-04-22 19:18:03 -0700563 struct scic_sds_remote_device *sci_dev,
564 u32 frame_index)
565{
566 dev_warn(scirdev_to_dev(sci_dev),
567 "%s: SCIC Remote Device requested to handle frame %x "
568 "while in wrong state %d\n",
569 __func__,
570 frame_index,
571 sci_base_state_machine_get_state(
572 &sci_dev->state_machine));
573
574 /* Return the frame back to the controller */
575 scic_sds_controller_release_frame(
576 scic_sds_remote_device_get_controller(sci_dev), frame_index
577 );
578
579 return SCI_FAILURE_INVALID_STATE;
580}
581
Dan Williamsab2e8f72011-04-27 16:32:45 -0700582static enum sci_status scic_sds_remote_device_default_start_request_handler(
Dan Williams88f3b622011-04-22 19:18:03 -0700583 struct scic_sds_remote_device *sci_dev,
584 struct scic_sds_request *request)
585{
586 return default_device_handler(sci_dev, __func__);
587}
588
Dan Williamsab2e8f72011-04-27 16:32:45 -0700589static enum sci_status scic_sds_remote_device_default_complete_request_handler(
Dan Williams88f3b622011-04-22 19:18:03 -0700590 struct scic_sds_remote_device *sci_dev,
591 struct scic_sds_request *request)
592{
593 return default_device_handler(sci_dev, __func__);
594}
595
Dan Williamsab2e8f72011-04-27 16:32:45 -0700596static enum sci_status scic_sds_remote_device_default_continue_request_handler(
Dan Williams88f3b622011-04-22 19:18:03 -0700597 struct scic_sds_remote_device *sci_dev,
598 struct scic_sds_request *request)
599{
600 return default_device_handler(sci_dev, __func__);
601}
602
603/**
604 *
605 * @device: The struct scic_sds_remote_device which is then cast into a
606 * struct scic_sds_remote_device.
607 * @frame_index: The frame index for which the struct scic_sds_controller wants this
608 * device object to process.
609 *
610 * This method is a general ssp frame handler. In most cases the device object
611 * needs to route the unsolicited frame processing to the io request object.
612 * This method decodes the tag for the io request object and routes the
613 * unsolicited frame to that object. enum sci_status SCI_FAILURE_INVALID_STATE
614 */
Dan Williamsab2e8f72011-04-27 16:32:45 -0700615static enum sci_status scic_sds_remote_device_general_frame_handler(
Dan Williams88f3b622011-04-22 19:18:03 -0700616 struct scic_sds_remote_device *sci_dev,
617 u32 frame_index)
618{
619 enum sci_status result;
620 struct sci_ssp_frame_header *frame_header;
621 struct scic_sds_request *io_request;
622
623 result = scic_sds_unsolicited_frame_control_get_header(
624 &(scic_sds_remote_device_get_controller(sci_dev)->uf_control),
625 frame_index,
626 (void **)&frame_header
627 );
628
629 if (SCI_SUCCESS == result) {
630 io_request = scic_sds_controller_get_io_request_from_tag(
631 scic_sds_remote_device_get_controller(sci_dev), frame_header->tag);
632
633 if ((io_request == NULL)
634 || (io_request->target_device != sci_dev)) {
635 /*
636 * We could not map this tag to a valid IO request
637 * Just toss the frame and continue */
638 scic_sds_controller_release_frame(
639 scic_sds_remote_device_get_controller(sci_dev), frame_index
640 );
641 } else {
642 /* The IO request is now in charge of releasing the frame */
643 result = io_request->state_handlers->frame_handler(
644 io_request, frame_index);
645 }
646 }
647
648 return result;
649}
650
651/**
652 *
653 * @[in]: sci_dev This is the device object that is receiving the event.
654 * @[in]: event_code The event code to process.
655 *
656 * This is a common method for handling events reported to the remote device
657 * from the controller object. enum sci_status
658 */
Dan Williamsab2e8f72011-04-27 16:32:45 -0700659static enum sci_status scic_sds_remote_device_general_event_handler(
Dan Williams88f3b622011-04-22 19:18:03 -0700660 struct scic_sds_remote_device *sci_dev,
661 u32 event_code)
662{
663 return scic_sds_remote_device_core_event_handler(sci_dev,
664 event_code,
665 true);
666}
667
668/*
669 * *****************************************************************************
670 * * STOPPED STATE HANDLERS
671 * ***************************************************************************** */
672
673/**
674 *
675 * @device:
676 *
677 * This method takes the struct scic_sds_remote_device from a stopped state and
678 * attempts to start it. The RNC buffer for the device is constructed and the
679 * device state machine is transitioned to the
680 * SCIC_BASE_REMOTE_DEVICE_STATE_STARTING. enum sci_status SCI_SUCCESS if there is
681 * an RNC buffer available to construct the remote device.
682 * SCI_FAILURE_INSUFFICIENT_RESOURCES if there is no RNC buffer available in
683 * which to construct the remote device.
684 */
685static enum sci_status scic_sds_remote_device_stopped_state_start_handler(
686 struct scic_sds_remote_device *sci_dev)
687{
688 enum sci_status status;
689
690 status = scic_sds_remote_node_context_resume(&sci_dev->rnc,
691 scic_sds_remote_device_resume_complete_handler, sci_dev);
692
693 if (status == SCI_SUCCESS)
694 sci_base_state_machine_change_state(&sci_dev->state_machine,
695 SCI_BASE_REMOTE_DEVICE_STATE_STARTING);
696
697 return status;
698}
699
700static enum sci_status scic_sds_remote_device_stopped_state_stop_handler(
701 struct scic_sds_remote_device *sci_dev)
702{
703 return SCI_SUCCESS;
704}
705
706/**
707 *
708 * @sci_dev: The struct scic_sds_remote_device which is cast into a
709 * struct scic_sds_remote_device.
710 *
711 * This method will destruct a struct scic_sds_remote_device that is in a stopped
712 * state. This is the only state from which a destruct request will succeed.
713 * The RNi for this struct scic_sds_remote_device is returned to the free pool and the
714 * device object transitions to the SCI_BASE_REMOTE_DEVICE_STATE_FINAL.
715 * enum sci_status SCI_SUCCESS
716 */
717static enum sci_status scic_sds_remote_device_stopped_state_destruct_handler(
718 struct scic_sds_remote_device *sci_dev)
719{
720 struct scic_sds_controller *scic;
721
722 scic = scic_sds_remote_device_get_controller(sci_dev);
723 scic_sds_controller_free_remote_node_context(scic, sci_dev,
724 sci_dev->rnc.remote_node_index);
725 sci_dev->rnc.remote_node_index = SCIC_SDS_REMOTE_NODE_CONTEXT_INVALID_INDEX;
726
727 sci_base_state_machine_change_state(&sci_dev->state_machine,
728 SCI_BASE_REMOTE_DEVICE_STATE_FINAL);
729
730 return SCI_SUCCESS;
731}
732
733/*
734 * *****************************************************************************
735 * * STARTING STATE HANDLERS
736 * ***************************************************************************** */
737
738static enum sci_status scic_sds_remote_device_starting_state_stop_handler(
739 struct scic_sds_remote_device *sci_dev)
740{
741 /*
742 * This device has not yet started so there had better be no IO requests
743 */
744 BUG_ON(sci_dev->started_request_count != 0);
745
746 /*
747 * Destroy the remote node context
748 */
749 scic_sds_remote_node_context_destruct(&sci_dev->rnc,
750 scic_sds_cb_remote_device_rnc_destruct_complete, sci_dev);
751
752 /*
753 * Transition to the stopping state and wait for the remote node to
754 * complete being posted and invalidated.
755 */
756 sci_base_state_machine_change_state(&sci_dev->state_machine,
757 SCI_BASE_REMOTE_DEVICE_STATE_STOPPING);
758
759 return SCI_SUCCESS;
760}
761
Dan Williamsab2e8f72011-04-27 16:32:45 -0700762static enum sci_status scic_sds_remote_device_ready_state_stop_handler(
Dan Williams88f3b622011-04-22 19:18:03 -0700763 struct scic_sds_remote_device *sci_dev)
764{
765 enum sci_status status = SCI_SUCCESS;
766
767 /* Request the parent state machine to transition to the stopping state */
768 sci_base_state_machine_change_state(&sci_dev->state_machine,
769 SCI_BASE_REMOTE_DEVICE_STATE_STOPPING);
770
771 if (sci_dev->started_request_count == 0) {
772 scic_sds_remote_node_context_destruct(&sci_dev->rnc,
773 scic_sds_cb_remote_device_rnc_destruct_complete,
774 sci_dev);
775 } else
776 status = scic_sds_remote_device_terminate_requests(sci_dev);
777
778 return status;
779}
780
781/**
782 *
783 * @device: The struct scic_sds_remote_device object which is cast to a
784 * struct scic_sds_remote_device object.
785 *
786 * This is the ready state device reset handler enum sci_status
787 */
Dan Williamsab2e8f72011-04-27 16:32:45 -0700788static enum sci_status scic_sds_remote_device_ready_state_reset_handler(
Dan Williams88f3b622011-04-22 19:18:03 -0700789 struct scic_sds_remote_device *sci_dev)
790{
791 /* Request the parent state machine to transition to the stopping state */
792 sci_base_state_machine_change_state(&sci_dev->state_machine,
793 SCI_BASE_REMOTE_DEVICE_STATE_RESETTING);
794
795 return SCI_SUCCESS;
796}
797
798/*
799 * This method will attempt to start a task request for this device object. The
800 * remote device object will issue the start request for the task and if
801 * successful it will start the request for the port object then increment its
802 * own requet count. enum sci_status SCI_SUCCESS if the task request is started for
803 * this device object. SCI_FAILURE_INSUFFICIENT_RESOURCES if the io request
804 * object could not get the resources to start.
805 */
806static enum sci_status scic_sds_remote_device_ready_state_start_task_handler(
807 struct scic_sds_remote_device *sci_dev,
808 struct scic_sds_request *request)
809{
810 enum sci_status result;
811
812 /* See if the port is in a state where we can start the IO request */
813 result = scic_sds_port_start_io(
814 scic_sds_remote_device_get_port(sci_dev), sci_dev, request);
815
816 if (result == SCI_SUCCESS) {
817 result = scic_sds_remote_node_context_start_task(&sci_dev->rnc,
818 request);
819 if (result == SCI_SUCCESS)
820 result = scic_sds_request_start(request);
821
822 scic_sds_remote_device_start_request(sci_dev, request, result);
823 }
824
825 return result;
826}
827
828/*
829 * This method will attempt to start an io request for this device object. The
830 * remote device object will issue the start request for the io and if
831 * successful it will start the request for the port object then increment its
832 * own requet count. enum sci_status SCI_SUCCESS if the io request is started for
833 * this device object. SCI_FAILURE_INSUFFICIENT_RESOURCES if the io request
834 * object could not get the resources to start.
835 */
836static enum sci_status scic_sds_remote_device_ready_state_start_io_handler(
837 struct scic_sds_remote_device *sci_dev,
838 struct scic_sds_request *request)
839{
840 enum sci_status result;
841
842 /* See if the port is in a state where we can start the IO request */
843 result = scic_sds_port_start_io(
844 scic_sds_remote_device_get_port(sci_dev), sci_dev, request);
845
846 if (result == SCI_SUCCESS) {
847 result = scic_sds_remote_node_context_start_io(&sci_dev->rnc, request);
848 if (result == SCI_SUCCESS)
849 result = scic_sds_request_start(request);
850
851 scic_sds_remote_device_start_request(sci_dev, request, result);
852 }
853
854 return result;
855}
856
857/*
858 * This method will complete the request for the remote device object. The
859 * method will call the completion handler for the request object and if
860 * successful it will complete the request on the port object then decrement
861 * its own started_request_count. enum sci_status
862 */
863static enum sci_status scic_sds_remote_device_ready_state_complete_request_handler(
864 struct scic_sds_remote_device *sci_dev,
865 struct scic_sds_request *request)
866{
867 enum sci_status result;
868
869 result = scic_sds_request_complete(request);
870
871 if (result != SCI_SUCCESS)
872 return result;
873
874 /* See if the port is in a state
875 * where we can start the IO request */
876 result = scic_sds_port_complete_io(
877 scic_sds_remote_device_get_port(sci_dev),
878 sci_dev, request);
879
880 if (result == SCI_SUCCESS)
881 scic_sds_remote_device_decrement_request_count(sci_dev);
882
883 return result;
884}
885
886/*
887 * *****************************************************************************
888 * * STOPPING STATE HANDLERS
889 * ***************************************************************************** */
890
891/**
892 *
893 * @sci_dev: The struct scic_sds_remote_device which is cast into a
894 * struct scic_sds_remote_device.
895 *
896 * This method will stop a struct scic_sds_remote_device that is already in the
897 * SCI_BASE_REMOTE_DEVICE_STATE_STOPPING state. This is not considered an error
898 * since we allow a stop request on a device that is alreay stopping or
899 * stopped. enum sci_status SCI_SUCCESS
900 */
901static enum sci_status scic_sds_remote_device_stopping_state_stop_handler(
902 struct scic_sds_remote_device *device)
903{
904 /*
905 * All requests should have been terminated, but if there is an
906 * attempt to stop a device already in the stopping state, then
907 * try again to terminate. */
908 return scic_sds_remote_device_terminate_requests(device);
909}
910
911
912/**
913 *
914 * @device: The device object for which the request is completing.
915 * @request: The task request that is being completed.
916 *
917 * This method completes requests for this struct scic_sds_remote_device while it is
918 * in the SCI_BASE_REMOTE_DEVICE_STATE_STOPPING state. This method calls the
919 * complete method for the request object and if that is successful the port
920 * object is called to complete the task request. Then the device object itself
921 * completes the task request. If struct scic_sds_remote_device started_request_count
922 * goes to 0 and the invalidate RNC request has completed the device object can
923 * transition to the SCI_BASE_REMOTE_DEVICE_STATE_STOPPED. enum sci_status
924 */
925static enum sci_status scic_sds_remote_device_stopping_state_complete_request_handler(
926 struct scic_sds_remote_device *sci_dev,
927 struct scic_sds_request *request)
928{
929 enum sci_status status = SCI_SUCCESS;
930
931 status = scic_sds_request_complete(request);
932
933 if (status != SCI_SUCCESS)
934 return status;
935
936 status = scic_sds_port_complete_io(scic_sds_remote_device_get_port(sci_dev),
937 sci_dev, request);
938 if (status != SCI_SUCCESS)
939 return status;
940
941 scic_sds_remote_device_decrement_request_count(sci_dev);
942
943 if (scic_sds_remote_device_get_request_count(sci_dev) == 0)
944 scic_sds_remote_node_context_destruct(&sci_dev->rnc,
945 scic_sds_cb_remote_device_rnc_destruct_complete,
946 sci_dev);
947 return SCI_SUCCESS;
948}
949
Dan Williams88f3b622011-04-22 19:18:03 -0700950static enum sci_status scic_sds_remote_device_resetting_state_reset_complete_handler(
951 struct scic_sds_remote_device *sci_dev)
952{
Dan Williamsab2e8f72011-04-27 16:32:45 -0700953 sci_base_state_machine_change_state(&sci_dev->state_machine,
954 SCI_BASE_REMOTE_DEVICE_STATE_READY);
Dan Williams88f3b622011-04-22 19:18:03 -0700955
956 return SCI_SUCCESS;
957}
958
Dan Williams88f3b622011-04-22 19:18:03 -0700959static enum sci_status scic_sds_remote_device_resetting_state_stop_handler(
960 struct scic_sds_remote_device *sci_dev)
961{
962 sci_base_state_machine_change_state(
963 &sci_dev->state_machine,
964 SCI_BASE_REMOTE_DEVICE_STATE_STOPPING
965 );
966
967 return SCI_SUCCESS;
968}
969
Dan Williamsab2e8f72011-04-27 16:32:45 -0700970/* complete requests for this device while it is in the
971 * SCI_BASE_REMOTE_DEVICE_STATE_RESETTING state. This method calls the complete
972 * method for the request object and if that is successful the port object is
973 * called to complete the task request. Then the device object itself completes
974 * the task request. enum sci_status
Dan Williams88f3b622011-04-22 19:18:03 -0700975 */
976static enum sci_status scic_sds_remote_device_resetting_state_complete_request_handler(
977 struct scic_sds_remote_device *sci_dev,
978 struct scic_sds_request *request)
979{
980 enum sci_status status = SCI_SUCCESS;
981
982 status = scic_sds_request_complete(request);
983
984 if (status == SCI_SUCCESS) {
985 status = scic_sds_port_complete_io(
986 scic_sds_remote_device_get_port(sci_dev),
987 sci_dev, request);
988
989 if (status == SCI_SUCCESS) {
990 scic_sds_remote_device_decrement_request_count(sci_dev);
991 }
992 }
993
994 return status;
995}
996
Dan Williamsab2e8f72011-04-27 16:32:45 -0700997static enum sci_status scic_sds_stp_remote_device_complete_request(struct scic_sds_remote_device *sci_dev,
998 struct scic_sds_request *sci_req)
999{
1000 enum sci_status status;
1001
1002 status = scic_sds_io_request_complete(sci_req);
1003 if (status != SCI_SUCCESS)
1004 goto out;
1005
1006 status = scic_sds_port_complete_io(sci_dev->owning_port, sci_dev, sci_req);
1007 if (status != SCI_SUCCESS)
1008 goto out;
1009
1010 scic_sds_remote_device_decrement_request_count(sci_dev);
1011 if (sci_req->sci_status == SCI_FAILURE_REMOTE_DEVICE_RESET_REQUIRED) {
1012 /* This request causes hardware error, device needs to be Lun Reset.
1013 * So here we force the state machine to IDLE state so the rest IOs
1014 * can reach RNC state handler, these IOs will be completed by RNC with
1015 * status of "DEVICE_RESET_REQUIRED", instead of "INVALID STATE".
1016 */
1017 sci_base_state_machine_change_state(&sci_dev->state_machine,
1018 SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_AWAIT_RESET);
1019 } else if (scic_sds_remote_device_get_request_count(sci_dev) == 0)
1020 sci_base_state_machine_change_state(&sci_dev->state_machine,
1021 SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_IDLE);
1022
1023
1024 out:
1025 if (status != SCI_SUCCESS)
1026 dev_err(scirdev_to_dev(sci_dev),
1027 "%s: Port:0x%p Device:0x%p Request:0x%p Status:0x%x "
1028 "could not complete\n", __func__, sci_dev->owning_port,
1029 sci_dev, sci_req, status);
1030
1031 return status;
1032}
1033
1034/* scic_sds_stp_remote_device_ready_substate_start_request_handler - start stp
1035 * @device: The target device a task management request towards to.
1036 * @request: The task request.
1037 *
1038 * This is the READY NCQ substate handler to start task management request. In
1039 * this routine, we suspend and resume the RNC. enum sci_status Always return
1040 * SCI_FAILURE_RESET_DEVICE_PARTIAL_SUCCESS status to let
1041 * controller_start_task_handler know that the controller can't post TC for
1042 * task request yet, instead, when RNC gets resumed, a controller_continue_task
1043 * callback will be called.
1044 */
1045static enum sci_status scic_sds_stp_remote_device_ready_substate_start_request_handler(
1046 struct scic_sds_remote_device *device,
1047 struct scic_sds_request *request)
1048{
1049 enum sci_status status;
1050
1051 /* Will the port allow the io request to start? */
1052 status = device->owning_port->state_handlers->start_io_handler(
1053 device->owning_port, device, request);
1054 if (status != SCI_SUCCESS)
1055 return status;
1056
1057 status = scic_sds_remote_node_context_start_task(&device->rnc, request);
1058 if (status != SCI_SUCCESS)
1059 goto out;
1060
1061 status = request->state_handlers->start_handler(request);
1062 if (status != SCI_SUCCESS)
1063 goto out;
1064
1065 /*
1066 * Note: If the remote device state is not IDLE this will replace
1067 * the request that probably resulted in the task management request.
1068 */
1069 device->working_request = request;
1070 sci_base_state_machine_change_state(&device->state_machine,
1071 SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_CMD);
1072
1073 /*
1074 * The remote node context must cleanup the TCi to NCQ mapping table.
1075 * The only way to do this correctly is to either write to the TLCR
1076 * register or to invalidate and repost the RNC. In either case the
1077 * remote node context state machine will take the correct action when
1078 * the remote node context is suspended and later resumed.
1079 */
1080 scic_sds_remote_node_context_suspend(&device->rnc,
1081 SCI_SOFTWARE_SUSPENSION, NULL, NULL);
1082 scic_sds_remote_node_context_resume(&device->rnc,
1083 scic_sds_remote_device_continue_request,
1084 device);
1085
1086out:
1087 scic_sds_remote_device_start_request(device, request, status);
1088 /*
1089 * We need to let the controller start request handler know that it can't
1090 * post TC yet. We will provide a callback function to post TC when RNC gets
1091 * resumed.
1092 */
1093 return SCI_FAILURE_RESET_DEVICE_PARTIAL_SUCCESS;
1094}
1095
1096/* handle the start io operation for a sata device that is in the command idle
1097 * state. - Evalute the type of IO request to be started - If its an NCQ
1098 * request change to NCQ substate - If its any other command change to the CMD
1099 * substate
1100 *
1101 * If this is a softreset we may want to have a different substate.
1102 */
1103static enum sci_status scic_sds_stp_remote_device_ready_idle_substate_start_io_handler(
1104 struct scic_sds_remote_device *sci_dev,
1105 struct scic_sds_request *request)
1106{
1107 enum sci_status status;
1108 struct isci_request *isci_request = request->ireq;
1109 enum scic_sds_remote_device_states new_state;
1110
1111 /* Will the port allow the io request to start? */
1112 status = sci_dev->owning_port->state_handlers->start_io_handler(
1113 sci_dev->owning_port, sci_dev, request);
1114 if (status != SCI_SUCCESS)
1115 return status;
1116
1117 status = scic_sds_remote_node_context_start_io(&sci_dev->rnc, request);
1118 if (status != SCI_SUCCESS)
1119 goto out;
1120
1121 status = request->state_handlers->start_handler(request);
1122 if (status != SCI_SUCCESS)
1123 goto out;
1124
1125 if (isci_sata_get_sat_protocol(isci_request) == SAT_PROTOCOL_FPDMA)
1126 new_state = SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_NCQ;
1127 else {
1128 sci_dev->working_request = request;
1129 new_state = SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_CMD;
1130 }
1131 sci_base_state_machine_change_state(&sci_dev->state_machine, new_state);
1132out:
1133 scic_sds_remote_device_start_request(sci_dev, request, status);
1134 return status;
1135}
1136
1137
1138static enum sci_status scic_sds_stp_remote_device_ready_idle_substate_event_handler(
1139 struct scic_sds_remote_device *sci_dev,
1140 u32 event_code)
1141{
1142 enum sci_status status;
1143
1144 status = scic_sds_remote_device_general_event_handler(sci_dev, event_code);
1145 if (status != SCI_SUCCESS)
1146 return status;
1147
1148 /* We pick up suspension events to handle specifically to this state. We
1149 * resume the RNC right away. enum sci_status
1150 */
1151 if (scu_get_event_type(event_code) == SCU_EVENT_TYPE_RNC_SUSPEND_TX ||
1152 scu_get_event_type(event_code) == SCU_EVENT_TYPE_RNC_SUSPEND_TX_RX)
1153 status = scic_sds_remote_node_context_resume(&sci_dev->rnc, NULL, NULL);
1154
1155 return status;
1156}
1157
1158static enum sci_status scic_sds_stp_remote_device_ready_ncq_substate_start_io_handler(
1159 struct scic_sds_remote_device *sci_dev,
1160 struct scic_sds_request *request)
1161{
1162 enum sci_status status;
1163 struct isci_request *isci_request = request->ireq;
1164 scic_sds_port_io_request_handler_t start_io;
1165
1166 if (isci_sata_get_sat_protocol(isci_request) == SAT_PROTOCOL_FPDMA) {
1167 start_io = sci_dev->owning_port->state_handlers->start_io_handler;
1168 status = start_io(sci_dev->owning_port, sci_dev, request);
1169 if (status != SCI_SUCCESS)
1170 return status;
1171
1172 status = scic_sds_remote_node_context_start_io(&sci_dev->rnc, request);
1173 if (status != SCI_SUCCESS)
1174 return status;
1175
1176 status = request->state_handlers->start_handler(request);
1177
1178 scic_sds_remote_device_start_request(sci_dev, request, status);
1179 } else
1180 status = SCI_FAILURE_INVALID_STATE;
1181
1182 return status;
1183}
1184
1185static enum sci_status scic_sds_stp_remote_device_ready_ncq_substate_frame_handler(struct scic_sds_remote_device *sci_dev,
1186 u32 frame_index)
1187{
1188 enum sci_status status;
1189 struct sata_fis_header *frame_header;
1190 struct scic_sds_controller *scic = sci_dev->owning_port->owning_controller;
1191
1192 status = scic_sds_unsolicited_frame_control_get_header(&scic->uf_control,
1193 frame_index,
1194 (void **)&frame_header);
1195 if (status != SCI_SUCCESS)
1196 return status;
1197
1198 if (frame_header->fis_type == SATA_FIS_TYPE_SETDEVBITS &&
1199 (frame_header->status & ATA_STATUS_REG_ERROR_BIT)) {
1200 sci_dev->not_ready_reason = SCIC_REMOTE_DEVICE_NOT_READY_SATA_SDB_ERROR_FIS_RECEIVED;
1201
1202 /* TODO Check sactive and complete associated IO if any. */
1203
1204 sci_base_state_machine_change_state(&sci_dev->state_machine,
1205 SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_NCQ_ERROR);
1206 } else if (frame_header->fis_type == SATA_FIS_TYPE_REGD2H &&
1207 (frame_header->status & ATA_STATUS_REG_ERROR_BIT)) {
1208 /*
1209 * Some devices return D2H FIS when an NCQ error is detected.
1210 * Treat this like an SDB error FIS ready reason.
1211 */
1212 sci_dev->not_ready_reason = SCIC_REMOTE_DEVICE_NOT_READY_SATA_SDB_ERROR_FIS_RECEIVED;
1213
1214 sci_base_state_machine_change_state(&sci_dev->state_machine,
1215 SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_NCQ_ERROR);
1216 } else
1217 status = SCI_FAILURE;
1218
1219 scic_sds_controller_release_frame(scic, frame_index);
1220
1221 return status;
1222}
1223
1224static enum sci_status scic_sds_stp_remote_device_ready_cmd_substate_start_io_handler(
1225 struct scic_sds_remote_device *device,
1226 struct scic_sds_request *request)
1227{
1228 /* device is already handling a command it can not accept new commands
1229 * until this one is complete.
1230 */
1231 return SCI_FAILURE_INVALID_STATE;
1232}
1233
1234static enum sci_status scic_sds_stp_remote_device_ready_cmd_substate_suspend_handler(
1235 struct scic_sds_remote_device *sci_dev,
1236 u32 suspend_type)
1237{
1238 enum sci_status status;
1239
1240 status = scic_sds_remote_node_context_suspend(&sci_dev->rnc,
1241 suspend_type, NULL, NULL);
1242
1243 return status;
1244}
1245
1246static enum sci_status scic_sds_stp_remote_device_ready_cmd_substate_frame_handler(
1247 struct scic_sds_remote_device *sci_dev,
1248 u32 frame_index)
1249{
1250 /* The device doe not process any UF received from the hardware while
1251 * in this state. All unsolicited frames are forwarded to the io
1252 * request object.
1253 */
1254 return scic_sds_io_request_frame_handler(sci_dev->working_request,
1255 frame_index);
1256}
1257
1258static enum sci_status scic_sds_stp_remote_device_ready_await_reset_substate_start_io_handler(
1259 struct scic_sds_remote_device *device,
1260 struct scic_sds_request *request)
1261{
1262 return SCI_FAILURE_REMOTE_DEVICE_RESET_REQUIRED;
1263}
1264
1265static enum sci_status scic_sds_stp_remote_device_ready_await_reset_substate_complete_request_handler(
1266 struct scic_sds_remote_device *device,
1267 struct scic_sds_request *request)
1268{
1269 struct scic_sds_request *sci_req = request;
1270 enum sci_status status;
1271
1272 status = scic_sds_io_request_complete(sci_req);
1273 if (status != SCI_SUCCESS)
1274 goto out;
1275
1276 status = scic_sds_port_complete_io(device->owning_port, device, sci_req);
1277 if (status != SCI_SUCCESS)
1278 goto out;
1279
1280 scic_sds_remote_device_decrement_request_count(device);
1281 out:
1282 if (status != SCI_SUCCESS)
1283 dev_err(scirdev_to_dev(device),
1284 "%s: Port:0x%p Device:0x%p Request:0x%p Status:0x%x "
1285 "could not complete\n",
1286 __func__, device->owning_port, device, sci_req, status);
1287
1288 return status;
1289}
1290
1291static void scic_sds_stp_remote_device_ready_idle_substate_resume_complete_handler(void *_dev)
1292{
1293 struct scic_sds_remote_device *sci_dev = _dev;
1294 struct isci_remote_device *idev = sci_dev_to_idev(sci_dev);
1295 struct scic_sds_controller *scic = sci_dev->owning_port->owning_controller;
1296
1297 /* For NCQ operation we do not issue a isci_remote_device_not_ready().
1298 * As a result, avoid sending the ready notification.
1299 */
1300 if (sci_dev->state_machine.previous_state_id != SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_NCQ)
1301 isci_remote_device_ready(scic->ihost, idev);
1302}
1303
1304static enum sci_status scic_sds_smp_remote_device_ready_idle_substate_start_io_handler(
1305 struct scic_sds_remote_device *sci_dev,
1306 struct scic_sds_request *sci_req)
1307{
1308 enum sci_status status;
1309
1310 /* Will the port allow the io request to start? */
1311 status = sci_dev->owning_port->state_handlers->start_io_handler(
1312 sci_dev->owning_port, sci_dev, sci_req);
1313 if (status != SCI_SUCCESS)
1314 return status;
1315
1316 status = scic_sds_remote_node_context_start_io(&sci_dev->rnc, sci_req);
1317 if (status != SCI_SUCCESS)
1318 return status;
1319
1320 status = scic_sds_request_start(sci_req);
1321 if (status != SCI_SUCCESS)
1322 return status;
1323
1324 sci_dev->working_request = sci_req;
1325 sci_base_state_machine_change_state(&sci_dev->state_machine,
1326 SCIC_SDS_SMP_REMOTE_DEVICE_READY_SUBSTATE_CMD);
1327
1328 scic_sds_remote_device_start_request(sci_dev, sci_req, status);
1329
1330 return status;
1331}
1332
1333static enum sci_status scic_sds_smp_remote_device_ready_cmd_substate_start_io_handler(
1334 struct scic_sds_remote_device *device,
1335 struct scic_sds_request *request)
1336{
1337 /* device is already handling a command it can not accept new commands
1338 * until this one is complete.
1339 */
1340 return SCI_FAILURE_INVALID_STATE;
1341}
1342
1343static enum sci_status
1344scic_sds_smp_remote_device_ready_cmd_substate_complete_io_handler(struct scic_sds_remote_device *sci_dev,
1345 struct scic_sds_request *sci_req)
1346{
1347 enum sci_status status;
1348
1349 status = scic_sds_io_request_complete(sci_req);
1350 if (status != SCI_SUCCESS)
1351 return status;
1352
1353 status = scic_sds_port_complete_io(sci_dev->owning_port, sci_dev, sci_req);
1354 if (status != SCI_SUCCESS) {
1355 dev_err(scirdev_to_dev(sci_dev),
1356 "%s: SCIC SDS Remote Device 0x%p io request "
1357 "0x%p could not be completd on the port 0x%p "
1358 "failed with status %d.\n", __func__, sci_dev, sci_req,
1359 sci_dev->owning_port, status);
1360 return status;
1361 }
1362
1363 scic_sds_remote_device_decrement_request_count(sci_dev);
1364 sci_base_state_machine_change_state(&sci_dev->state_machine,
1365 SCIC_SDS_SMP_REMOTE_DEVICE_READY_SUBSTATE_IDLE);
1366
1367 return status;
1368}
1369
1370static enum sci_status scic_sds_smp_remote_device_ready_cmd_substate_frame_handler(
1371 struct scic_sds_remote_device *sci_dev,
1372 u32 frame_index)
1373{
1374 enum sci_status status;
1375
1376 /* The device does not process any UF received from the hardware while
1377 * in this state. All unsolicited frames are forwarded to the io request
1378 * object.
1379 */
1380 status = scic_sds_io_request_frame_handler(
1381 sci_dev->working_request,
1382 frame_index
1383 );
1384
1385 return status;
1386}
1387
Dan Williams88f3b622011-04-22 19:18:03 -07001388static const struct scic_sds_remote_device_state_handler scic_sds_remote_device_state_handler_table[] = {
1389 [SCI_BASE_REMOTE_DEVICE_STATE_INITIAL] = {
1390 .start_handler = scic_sds_remote_device_default_start_handler,
1391 .stop_handler = scic_sds_remote_device_default_stop_handler,
1392 .fail_handler = scic_sds_remote_device_default_fail_handler,
1393 .destruct_handler = scic_sds_remote_device_default_destruct_handler,
1394 .reset_handler = scic_sds_remote_device_default_reset_handler,
1395 .reset_complete_handler = scic_sds_remote_device_default_reset_complete_handler,
1396 .start_io_handler = scic_sds_remote_device_default_start_request_handler,
1397 .complete_io_handler = scic_sds_remote_device_default_complete_request_handler,
1398 .continue_io_handler = scic_sds_remote_device_default_continue_request_handler,
1399 .start_task_handler = scic_sds_remote_device_default_start_request_handler,
1400 .complete_task_handler = scic_sds_remote_device_default_complete_request_handler,
1401 .suspend_handler = scic_sds_remote_device_default_suspend_handler,
1402 .resume_handler = scic_sds_remote_device_default_resume_handler,
1403 .event_handler = scic_sds_remote_device_default_event_handler,
1404 .frame_handler = scic_sds_remote_device_default_frame_handler
1405 },
1406 [SCI_BASE_REMOTE_DEVICE_STATE_STOPPED] = {
1407 .start_handler = scic_sds_remote_device_stopped_state_start_handler,
1408 .stop_handler = scic_sds_remote_device_stopped_state_stop_handler,
1409 .fail_handler = scic_sds_remote_device_default_fail_handler,
1410 .destruct_handler = scic_sds_remote_device_stopped_state_destruct_handler,
1411 .reset_handler = scic_sds_remote_device_default_reset_handler,
1412 .reset_complete_handler = scic_sds_remote_device_default_reset_complete_handler,
1413 .start_io_handler = scic_sds_remote_device_default_start_request_handler,
1414 .complete_io_handler = scic_sds_remote_device_default_complete_request_handler,
1415 .continue_io_handler = scic_sds_remote_device_default_continue_request_handler,
1416 .start_task_handler = scic_sds_remote_device_default_start_request_handler,
1417 .complete_task_handler = scic_sds_remote_device_default_complete_request_handler,
1418 .suspend_handler = scic_sds_remote_device_default_suspend_handler,
1419 .resume_handler = scic_sds_remote_device_default_resume_handler,
1420 .event_handler = scic_sds_remote_device_default_event_handler,
1421 .frame_handler = scic_sds_remote_device_default_frame_handler
1422 },
1423 [SCI_BASE_REMOTE_DEVICE_STATE_STARTING] = {
1424 .start_handler = scic_sds_remote_device_default_start_handler,
1425 .stop_handler = scic_sds_remote_device_starting_state_stop_handler,
1426 .fail_handler = scic_sds_remote_device_default_fail_handler,
1427 .destruct_handler = scic_sds_remote_device_default_destruct_handler,
1428 .reset_handler = scic_sds_remote_device_default_reset_handler,
1429 .reset_complete_handler = scic_sds_remote_device_default_reset_complete_handler,
1430 .start_io_handler = scic_sds_remote_device_default_start_request_handler,
1431 .complete_io_handler = scic_sds_remote_device_default_complete_request_handler,
1432 .continue_io_handler = scic_sds_remote_device_default_continue_request_handler,
1433 .start_task_handler = scic_sds_remote_device_default_start_request_handler,
1434 .complete_task_handler = scic_sds_remote_device_default_complete_request_handler,
1435 .suspend_handler = scic_sds_remote_device_default_suspend_handler,
1436 .resume_handler = scic_sds_remote_device_default_resume_handler,
1437 .event_handler = scic_sds_remote_device_general_event_handler,
1438 .frame_handler = scic_sds_remote_device_default_frame_handler
1439 },
1440 [SCI_BASE_REMOTE_DEVICE_STATE_READY] = {
1441 .start_handler = scic_sds_remote_device_default_start_handler,
1442 .stop_handler = scic_sds_remote_device_ready_state_stop_handler,
1443 .fail_handler = scic_sds_remote_device_default_fail_handler,
1444 .destruct_handler = scic_sds_remote_device_default_destruct_handler,
1445 .reset_handler = scic_sds_remote_device_ready_state_reset_handler,
1446 .reset_complete_handler = scic_sds_remote_device_default_reset_complete_handler,
1447 .start_io_handler = scic_sds_remote_device_ready_state_start_io_handler,
1448 .complete_io_handler = scic_sds_remote_device_ready_state_complete_request_handler,
1449 .continue_io_handler = scic_sds_remote_device_default_continue_request_handler,
1450 .start_task_handler = scic_sds_remote_device_ready_state_start_task_handler,
1451 .complete_task_handler = scic_sds_remote_device_ready_state_complete_request_handler,
1452 .suspend_handler = scic_sds_remote_device_default_suspend_handler,
1453 .resume_handler = scic_sds_remote_device_default_resume_handler,
1454 .event_handler = scic_sds_remote_device_general_event_handler,
1455 .frame_handler = scic_sds_remote_device_general_frame_handler,
1456 },
Dan Williamsab2e8f72011-04-27 16:32:45 -07001457 [SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_IDLE] = {
1458 .start_handler = scic_sds_remote_device_default_start_handler,
1459 .stop_handler = scic_sds_remote_device_ready_state_stop_handler,
1460 .fail_handler = scic_sds_remote_device_default_fail_handler,
1461 .destruct_handler = scic_sds_remote_device_default_destruct_handler,
1462 .reset_handler = scic_sds_remote_device_ready_state_reset_handler,
1463 .reset_complete_handler = scic_sds_remote_device_default_reset_complete_handler,
1464 .start_io_handler = scic_sds_stp_remote_device_ready_idle_substate_start_io_handler,
1465 .complete_io_handler = scic_sds_remote_device_default_complete_request_handler,
1466 .continue_io_handler = scic_sds_remote_device_default_continue_request_handler,
1467 .start_task_handler = scic_sds_stp_remote_device_ready_substate_start_request_handler,
1468 .complete_task_handler = scic_sds_remote_device_default_complete_request_handler,
1469 .suspend_handler = scic_sds_remote_device_default_suspend_handler,
1470 .resume_handler = scic_sds_remote_device_default_resume_handler,
1471 .event_handler = scic_sds_stp_remote_device_ready_idle_substate_event_handler,
1472 .frame_handler = scic_sds_remote_device_default_frame_handler
1473 },
1474 [SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_CMD] = {
1475 .start_handler = scic_sds_remote_device_default_start_handler,
1476 .stop_handler = scic_sds_remote_device_ready_state_stop_handler,
1477 .fail_handler = scic_sds_remote_device_default_fail_handler,
1478 .destruct_handler = scic_sds_remote_device_default_destruct_handler,
1479 .reset_handler = scic_sds_remote_device_ready_state_reset_handler,
1480 .reset_complete_handler = scic_sds_remote_device_default_reset_complete_handler,
1481 .start_io_handler = scic_sds_stp_remote_device_ready_cmd_substate_start_io_handler,
1482 .complete_io_handler = scic_sds_stp_remote_device_complete_request,
1483 .continue_io_handler = scic_sds_remote_device_default_continue_request_handler,
1484 .start_task_handler = scic_sds_stp_remote_device_ready_substate_start_request_handler,
1485 .complete_task_handler = scic_sds_stp_remote_device_complete_request,
1486 .suspend_handler = scic_sds_stp_remote_device_ready_cmd_substate_suspend_handler,
1487 .resume_handler = scic_sds_remote_device_default_resume_handler,
1488 .event_handler = scic_sds_remote_device_general_event_handler,
1489 .frame_handler = scic_sds_stp_remote_device_ready_cmd_substate_frame_handler
1490 },
1491 [SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_NCQ] = {
1492 .start_handler = scic_sds_remote_device_default_start_handler,
1493 .stop_handler = scic_sds_remote_device_ready_state_stop_handler,
1494 .fail_handler = scic_sds_remote_device_default_fail_handler,
1495 .destruct_handler = scic_sds_remote_device_default_destruct_handler,
1496 .reset_handler = scic_sds_remote_device_ready_state_reset_handler,
1497 .reset_complete_handler = scic_sds_remote_device_default_reset_complete_handler,
1498 .start_io_handler = scic_sds_stp_remote_device_ready_ncq_substate_start_io_handler,
1499 .complete_io_handler = scic_sds_stp_remote_device_complete_request,
1500 .continue_io_handler = scic_sds_remote_device_default_continue_request_handler,
1501 .start_task_handler = scic_sds_stp_remote_device_ready_substate_start_request_handler,
1502 .complete_task_handler = scic_sds_stp_remote_device_complete_request,
1503 .suspend_handler = scic_sds_remote_device_default_suspend_handler,
1504 .resume_handler = scic_sds_remote_device_default_resume_handler,
1505 .event_handler = scic_sds_remote_device_general_event_handler,
1506 .frame_handler = scic_sds_stp_remote_device_ready_ncq_substate_frame_handler
1507 },
1508 [SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_NCQ_ERROR] = {
1509 .start_handler = scic_sds_remote_device_default_start_handler,
1510 .stop_handler = scic_sds_remote_device_ready_state_stop_handler,
1511 .fail_handler = scic_sds_remote_device_default_fail_handler,
1512 .destruct_handler = scic_sds_remote_device_default_destruct_handler,
1513 .reset_handler = scic_sds_remote_device_ready_state_reset_handler,
1514 .reset_complete_handler = scic_sds_remote_device_default_reset_complete_handler,
1515 .start_io_handler = scic_sds_remote_device_default_start_request_handler,
1516 .complete_io_handler = scic_sds_stp_remote_device_complete_request,
1517 .continue_io_handler = scic_sds_remote_device_default_continue_request_handler,
1518 .start_task_handler = scic_sds_stp_remote_device_ready_substate_start_request_handler,
1519 .complete_task_handler = scic_sds_stp_remote_device_complete_request,
1520 .suspend_handler = scic_sds_remote_device_default_suspend_handler,
1521 .resume_handler = scic_sds_remote_device_default_resume_handler,
1522 .event_handler = scic_sds_remote_device_general_event_handler,
1523 .frame_handler = scic_sds_remote_device_general_frame_handler
1524 },
1525 [SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_AWAIT_RESET] = {
1526 .start_handler = scic_sds_remote_device_default_start_handler,
1527 .stop_handler = scic_sds_remote_device_ready_state_stop_handler,
1528 .fail_handler = scic_sds_remote_device_default_fail_handler,
1529 .destruct_handler = scic_sds_remote_device_default_destruct_handler,
1530 .reset_handler = scic_sds_remote_device_ready_state_reset_handler,
1531 .reset_complete_handler = scic_sds_remote_device_default_reset_complete_handler,
1532 .start_io_handler = scic_sds_stp_remote_device_ready_await_reset_substate_start_io_handler,
1533 .complete_io_handler = scic_sds_stp_remote_device_ready_await_reset_substate_complete_request_handler,
1534 .continue_io_handler = scic_sds_remote_device_default_continue_request_handler,
1535 .start_task_handler = scic_sds_stp_remote_device_ready_substate_start_request_handler,
1536 .complete_task_handler = scic_sds_stp_remote_device_complete_request,
1537 .suspend_handler = scic_sds_remote_device_default_suspend_handler,
1538 .resume_handler = scic_sds_remote_device_default_resume_handler,
1539 .event_handler = scic_sds_remote_device_general_event_handler,
1540 .frame_handler = scic_sds_remote_device_general_frame_handler
1541 },
1542 [SCIC_SDS_SMP_REMOTE_DEVICE_READY_SUBSTATE_IDLE] = {
1543 .start_handler = scic_sds_remote_device_default_start_handler,
1544 .stop_handler = scic_sds_remote_device_ready_state_stop_handler,
1545 .fail_handler = scic_sds_remote_device_default_fail_handler,
1546 .destruct_handler = scic_sds_remote_device_default_destruct_handler,
1547 .reset_handler = scic_sds_remote_device_default_reset_handler,
1548 .reset_complete_handler = scic_sds_remote_device_default_reset_complete_handler,
1549 .start_io_handler = scic_sds_smp_remote_device_ready_idle_substate_start_io_handler,
1550 .complete_io_handler = scic_sds_remote_device_default_complete_request_handler,
1551 .continue_io_handler = scic_sds_remote_device_default_continue_request_handler,
1552 .start_task_handler = scic_sds_remote_device_default_start_request_handler,
1553 .complete_task_handler = scic_sds_remote_device_default_complete_request_handler,
1554 .suspend_handler = scic_sds_remote_device_default_suspend_handler,
1555 .resume_handler = scic_sds_remote_device_default_resume_handler,
1556 .event_handler = scic_sds_remote_device_general_event_handler,
1557 .frame_handler = scic_sds_remote_device_default_frame_handler
1558 },
1559 [SCIC_SDS_SMP_REMOTE_DEVICE_READY_SUBSTATE_CMD] = {
1560 .start_handler = scic_sds_remote_device_default_start_handler,
1561 .stop_handler = scic_sds_remote_device_ready_state_stop_handler,
1562 .fail_handler = scic_sds_remote_device_default_fail_handler,
1563 .destruct_handler = scic_sds_remote_device_default_destruct_handler,
1564 .reset_handler = scic_sds_remote_device_default_reset_handler,
1565 .reset_complete_handler = scic_sds_remote_device_default_reset_complete_handler,
1566 .start_io_handler = scic_sds_smp_remote_device_ready_cmd_substate_start_io_handler,
1567 .complete_io_handler = scic_sds_smp_remote_device_ready_cmd_substate_complete_io_handler,
1568 .continue_io_handler = scic_sds_remote_device_default_continue_request_handler,
1569 .start_task_handler = scic_sds_remote_device_default_start_request_handler,
1570 .complete_task_handler = scic_sds_remote_device_default_complete_request_handler,
1571 .suspend_handler = scic_sds_remote_device_default_suspend_handler,
1572 .resume_handler = scic_sds_remote_device_default_resume_handler,
1573 .event_handler = scic_sds_remote_device_general_event_handler,
1574 .frame_handler = scic_sds_smp_remote_device_ready_cmd_substate_frame_handler
1575 },
Dan Williams88f3b622011-04-22 19:18:03 -07001576 [SCI_BASE_REMOTE_DEVICE_STATE_STOPPING] = {
1577 .start_handler = scic_sds_remote_device_default_start_handler,
1578 .stop_handler = scic_sds_remote_device_stopping_state_stop_handler,
1579 .fail_handler = scic_sds_remote_device_default_fail_handler,
1580 .destruct_handler = scic_sds_remote_device_default_destruct_handler,
1581 .reset_handler = scic_sds_remote_device_default_reset_handler,
1582 .reset_complete_handler = scic_sds_remote_device_default_reset_complete_handler,
1583 .start_io_handler = scic_sds_remote_device_default_start_request_handler,
1584 .complete_io_handler = scic_sds_remote_device_stopping_state_complete_request_handler,
1585 .continue_io_handler = scic_sds_remote_device_default_continue_request_handler,
1586 .start_task_handler = scic_sds_remote_device_default_start_request_handler,
1587 .complete_task_handler = scic_sds_remote_device_stopping_state_complete_request_handler,
1588 .suspend_handler = scic_sds_remote_device_default_suspend_handler,
1589 .resume_handler = scic_sds_remote_device_default_resume_handler,
1590 .event_handler = scic_sds_remote_device_general_event_handler,
1591 .frame_handler = scic_sds_remote_device_general_frame_handler
1592 },
1593 [SCI_BASE_REMOTE_DEVICE_STATE_FAILED] = {
1594 .start_handler = scic_sds_remote_device_default_start_handler,
1595 .stop_handler = scic_sds_remote_device_default_stop_handler,
1596 .fail_handler = scic_sds_remote_device_default_fail_handler,
1597 .destruct_handler = scic_sds_remote_device_default_destruct_handler,
1598 .reset_handler = scic_sds_remote_device_default_reset_handler,
1599 .reset_complete_handler = scic_sds_remote_device_default_reset_complete_handler,
1600 .start_io_handler = scic_sds_remote_device_default_start_request_handler,
1601 .complete_io_handler = scic_sds_remote_device_default_complete_request_handler,
1602 .continue_io_handler = scic_sds_remote_device_default_continue_request_handler,
1603 .start_task_handler = scic_sds_remote_device_default_start_request_handler,
1604 .complete_task_handler = scic_sds_remote_device_default_complete_request_handler,
1605 .suspend_handler = scic_sds_remote_device_default_suspend_handler,
1606 .resume_handler = scic_sds_remote_device_default_resume_handler,
1607 .event_handler = scic_sds_remote_device_default_event_handler,
1608 .frame_handler = scic_sds_remote_device_general_frame_handler
1609 },
1610 [SCI_BASE_REMOTE_DEVICE_STATE_RESETTING] = {
1611 .start_handler = scic_sds_remote_device_default_start_handler,
1612 .stop_handler = scic_sds_remote_device_resetting_state_stop_handler,
1613 .fail_handler = scic_sds_remote_device_default_fail_handler,
1614 .destruct_handler = scic_sds_remote_device_default_destruct_handler,
1615 .reset_handler = scic_sds_remote_device_default_reset_handler,
1616 .reset_complete_handler = scic_sds_remote_device_resetting_state_reset_complete_handler,
1617 .start_io_handler = scic_sds_remote_device_default_start_request_handler,
1618 .complete_io_handler = scic_sds_remote_device_resetting_state_complete_request_handler,
1619 .continue_io_handler = scic_sds_remote_device_default_continue_request_handler,
1620 .start_task_handler = scic_sds_remote_device_default_start_request_handler,
1621 .complete_task_handler = scic_sds_remote_device_resetting_state_complete_request_handler,
1622 .suspend_handler = scic_sds_remote_device_default_suspend_handler,
1623 .resume_handler = scic_sds_remote_device_default_resume_handler,
1624 .event_handler = scic_sds_remote_device_default_event_handler,
1625 .frame_handler = scic_sds_remote_device_general_frame_handler
1626 },
1627 [SCI_BASE_REMOTE_DEVICE_STATE_FINAL] = {
1628 .start_handler = scic_sds_remote_device_default_start_handler,
1629 .stop_handler = scic_sds_remote_device_default_stop_handler,
1630 .fail_handler = scic_sds_remote_device_default_fail_handler,
1631 .destruct_handler = scic_sds_remote_device_default_destruct_handler,
1632 .reset_handler = scic_sds_remote_device_default_reset_handler,
1633 .reset_complete_handler = scic_sds_remote_device_default_reset_complete_handler,
1634 .start_io_handler = scic_sds_remote_device_default_start_request_handler,
1635 .complete_io_handler = scic_sds_remote_device_default_complete_request_handler,
1636 .continue_io_handler = scic_sds_remote_device_default_continue_request_handler,
1637 .start_task_handler = scic_sds_remote_device_default_start_request_handler,
1638 .complete_task_handler = scic_sds_remote_device_default_complete_request_handler,
1639 .suspend_handler = scic_sds_remote_device_default_suspend_handler,
1640 .resume_handler = scic_sds_remote_device_default_resume_handler,
1641 .event_handler = scic_sds_remote_device_default_event_handler,
1642 .frame_handler = scic_sds_remote_device_default_frame_handler
1643 }
1644};
1645
Maciej Patelczyk9a0fff72011-04-28 22:06:01 +00001646static void scic_sds_remote_device_initial_state_enter(void *object)
Dan Williams88f3b622011-04-22 19:18:03 -07001647{
Maciej Patelczyk5d937e92011-04-28 22:06:21 +00001648 struct scic_sds_remote_device *sci_dev = object;
Dan Williams88f3b622011-04-22 19:18:03 -07001649
Dan Williams88f3b622011-04-22 19:18:03 -07001650 SET_STATE_HANDLER(sci_dev, scic_sds_remote_device_state_handler_table,
1651 SCI_BASE_REMOTE_DEVICE_STATE_INITIAL);
1652
1653 /* Initial state is a transitional state to the stopped state */
1654 sci_base_state_machine_change_state(&sci_dev->state_machine,
1655 SCI_BASE_REMOTE_DEVICE_STATE_STOPPED);
1656}
1657
1658/**
Dan Williams88f3b622011-04-22 19:18:03 -07001659 * scic_remote_device_destruct() - free remote node context and destruct
1660 * @remote_device: This parameter specifies the remote device to be destructed.
1661 *
1662 * Remote device objects are a limited resource. As such, they must be
1663 * protected. Thus calls to construct and destruct are mutually exclusive and
1664 * non-reentrant. The return value shall indicate if the device was
1665 * successfully destructed or if some failure occurred. enum sci_status This value
1666 * is returned if the device is successfully destructed.
1667 * SCI_FAILURE_INVALID_REMOTE_DEVICE This value is returned if the supplied
1668 * device isn't valid (e.g. it's already been destoryed, the handle isn't
1669 * valid, etc.).
1670 */
1671static enum sci_status scic_remote_device_destruct(struct scic_sds_remote_device *sci_dev)
1672{
1673 return sci_dev->state_handlers->destruct_handler(sci_dev);
1674}
1675
Dan Williams6f231dd2011-07-02 22:56:22 -07001676/**
1677 * isci_remote_device_deconstruct() - This function frees an isci_remote_device.
Dan Williamsd9c37392011-03-03 17:59:32 -08001678 * @ihost: This parameter specifies the isci host object.
1679 * @idev: This parameter specifies the remote device to be freed.
Dan Williams6f231dd2011-07-02 22:56:22 -07001680 *
1681 */
Dan Williamsd9c37392011-03-03 17:59:32 -08001682static void isci_remote_device_deconstruct(struct isci_host *ihost, struct isci_remote_device *idev)
Dan Williams6f231dd2011-07-02 22:56:22 -07001683{
Dan Williamsd9c37392011-03-03 17:59:32 -08001684 dev_dbg(&ihost->pdev->dev,
1685 "%s: isci_device = %p\n", __func__, idev);
Dan Williams6f231dd2011-07-02 22:56:22 -07001686
1687 /* There should not be any outstanding io's. All paths to
1688 * here should go through isci_remote_device_nuke_requests.
1689 * If we hit this condition, we will need a way to complete
1690 * io requests in process */
Dan Williamsd9c37392011-03-03 17:59:32 -08001691 while (!list_empty(&idev->reqs_in_process)) {
Dan Williams6f231dd2011-07-02 22:56:22 -07001692
Dan Williamsd9c37392011-03-03 17:59:32 -08001693 dev_err(&ihost->pdev->dev,
Dan Williams6f231dd2011-07-02 22:56:22 -07001694 "%s: ** request list not empty! **\n", __func__);
1695 BUG();
1696 }
1697
Dan Williams57f20f42011-04-21 18:14:45 -07001698 scic_remote_device_destruct(&idev->sci);
Dan Williamsd9c37392011-03-03 17:59:32 -08001699 idev->domain_dev->lldd_dev = NULL;
1700 idev->domain_dev = NULL;
1701 idev->isci_port = NULL;
1702 list_del_init(&idev->node);
Dan Williams6ad31fe2011-03-04 12:10:29 -08001703
Dan Williamsd9c37392011-03-03 17:59:32 -08001704 clear_bit(IDEV_START_PENDING, &idev->flags);
1705 clear_bit(IDEV_STOP_PENDING, &idev->flags);
1706 wake_up(&ihost->eventq);
Dan Williams6f231dd2011-07-02 22:56:22 -07001707}
1708
Dan Williams88f3b622011-04-22 19:18:03 -07001709/**
1710 * isci_remote_device_stop_complete() - This function is called by the scic
1711 * when the remote device stop has completed. We mark the isci device as not
1712 * ready and remove the isci remote device.
1713 * @ihost: This parameter specifies the isci host object.
1714 * @idev: This parameter specifies the remote device.
1715 * @status: This parameter specifies status of the completion.
1716 *
1717 */
1718static void isci_remote_device_stop_complete(struct isci_host *ihost,
1719 struct isci_remote_device *idev)
1720{
1721 dev_dbg(&ihost->pdev->dev, "%s: complete idev = %p\n", __func__, idev);
1722
1723 isci_remote_device_change_state(idev, isci_stopped);
1724
1725 /* after stop, we can tear down resources. */
1726 isci_remote_device_deconstruct(ihost, idev);
1727}
1728
Maciej Patelczyk9a0fff72011-04-28 22:06:01 +00001729static void scic_sds_remote_device_stopped_state_enter(void *object)
Dan Williams88f3b622011-04-22 19:18:03 -07001730{
Maciej Patelczyk5d937e92011-04-28 22:06:21 +00001731 struct scic_sds_remote_device *sci_dev = object;
Dan Williams88f3b622011-04-22 19:18:03 -07001732 struct scic_sds_controller *scic;
1733 struct isci_remote_device *idev;
1734 struct isci_host *ihost;
1735 u32 prev_state;
1736
Dan Williams88f3b622011-04-22 19:18:03 -07001737 scic = scic_sds_remote_device_get_controller(sci_dev);
Maciej Patelczykd3757c32011-04-28 22:06:06 +00001738 ihost = scic->ihost;
Maciej Patelczyk5d937e92011-04-28 22:06:21 +00001739 idev = sci_dev_to_idev(sci_dev);
Dan Williams88f3b622011-04-22 19:18:03 -07001740
1741 SET_STATE_HANDLER(sci_dev, scic_sds_remote_device_state_handler_table,
1742 SCI_BASE_REMOTE_DEVICE_STATE_STOPPED);
1743
1744 /* If we are entering from the stopping state let the SCI User know that
1745 * the stop operation has completed.
1746 */
1747 prev_state = sci_dev->state_machine.previous_state_id;
1748 if (prev_state == SCI_BASE_REMOTE_DEVICE_STATE_STOPPING)
1749 isci_remote_device_stop_complete(ihost, idev);
1750
1751 scic_sds_controller_remote_device_stopped(scic, sci_dev);
1752}
1753
Maciej Patelczyk9a0fff72011-04-28 22:06:01 +00001754static void scic_sds_remote_device_starting_state_enter(void *object)
Dan Williams88f3b622011-04-22 19:18:03 -07001755{
Maciej Patelczyk5d937e92011-04-28 22:06:21 +00001756 struct scic_sds_remote_device *sci_dev = object;
Dan Williams88f3b622011-04-22 19:18:03 -07001757 struct scic_sds_controller *scic = scic_sds_remote_device_get_controller(sci_dev);
Maciej Patelczykd3757c32011-04-28 22:06:06 +00001758 struct isci_host *ihost = scic->ihost;
Maciej Patelczyk5d937e92011-04-28 22:06:21 +00001759 struct isci_remote_device *idev = sci_dev_to_idev(sci_dev);
Dan Williams88f3b622011-04-22 19:18:03 -07001760
1761 SET_STATE_HANDLER(sci_dev, scic_sds_remote_device_state_handler_table,
1762 SCI_BASE_REMOTE_DEVICE_STATE_STARTING);
1763
1764 isci_remote_device_not_ready(ihost, idev,
1765 SCIC_REMOTE_DEVICE_NOT_READY_START_REQUESTED);
1766}
1767
Maciej Patelczyk9a0fff72011-04-28 22:06:01 +00001768static void scic_sds_remote_device_ready_state_enter(void *object)
Dan Williams88f3b622011-04-22 19:18:03 -07001769{
Maciej Patelczyk5d937e92011-04-28 22:06:21 +00001770 struct scic_sds_remote_device *sci_dev = object;
Dan Williamsab2e8f72011-04-27 16:32:45 -07001771 struct scic_sds_controller *scic = sci_dev->owning_port->owning_controller;
1772 struct domain_device *dev = sci_dev_to_domain(sci_dev);
Dan Williams88f3b622011-04-22 19:18:03 -07001773
1774 SET_STATE_HANDLER(sci_dev,
1775 scic_sds_remote_device_state_handler_table,
1776 SCI_BASE_REMOTE_DEVICE_STATE_READY);
1777
1778 scic->remote_device_sequence[sci_dev->rnc.remote_node_index]++;
1779
Dan Williamsab2e8f72011-04-27 16:32:45 -07001780 if (dev->dev_type == SATA_DEV || (dev->tproto & SAS_PROTOCOL_SATA)) {
1781 sci_base_state_machine_change_state(&sci_dev->state_machine,
1782 SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_IDLE);
1783 } else if (dev_is_expander(dev)) {
1784 sci_base_state_machine_change_state(&sci_dev->state_machine,
1785 SCIC_SDS_SMP_REMOTE_DEVICE_READY_SUBSTATE_IDLE);
1786 } else
1787 isci_remote_device_ready(scic->ihost, sci_dev_to_idev(sci_dev));
Dan Williams88f3b622011-04-22 19:18:03 -07001788}
1789
Maciej Patelczyk9a0fff72011-04-28 22:06:01 +00001790static void scic_sds_remote_device_ready_state_exit(void *object)
Dan Williams88f3b622011-04-22 19:18:03 -07001791{
Maciej Patelczyk5d937e92011-04-28 22:06:21 +00001792 struct scic_sds_remote_device *sci_dev = object;
Dan Williamsab2e8f72011-04-27 16:32:45 -07001793 struct domain_device *dev = sci_dev_to_domain(sci_dev);
1794
1795 if (dev->dev_type == SAS_END_DEV) {
1796 struct scic_sds_controller *scic = sci_dev->owning_port->owning_controller;
Maciej Patelczyk5d937e92011-04-28 22:06:21 +00001797 struct isci_remote_device *idev = sci_dev_to_idev(sci_dev);
Dan Williams88f3b622011-04-22 19:18:03 -07001798
Dan Williamsab2e8f72011-04-27 16:32:45 -07001799 isci_remote_device_not_ready(scic->ihost, idev,
Dan Williams88f3b622011-04-22 19:18:03 -07001800 SCIC_REMOTE_DEVICE_NOT_READY_STOP_REQUESTED);
1801 }
1802}
1803
Maciej Patelczyk9a0fff72011-04-28 22:06:01 +00001804static void scic_sds_remote_device_stopping_state_enter(void *object)
Dan Williams88f3b622011-04-22 19:18:03 -07001805{
Maciej Patelczyk5d937e92011-04-28 22:06:21 +00001806 struct scic_sds_remote_device *sci_dev = object;
Dan Williams88f3b622011-04-22 19:18:03 -07001807
1808 SET_STATE_HANDLER(
1809 sci_dev,
1810 scic_sds_remote_device_state_handler_table,
1811 SCI_BASE_REMOTE_DEVICE_STATE_STOPPING
1812 );
1813}
1814
Maciej Patelczyk9a0fff72011-04-28 22:06:01 +00001815static void scic_sds_remote_device_failed_state_enter(void *object)
Dan Williams88f3b622011-04-22 19:18:03 -07001816{
Maciej Patelczyk5d937e92011-04-28 22:06:21 +00001817 struct scic_sds_remote_device *sci_dev = object;
Dan Williams88f3b622011-04-22 19:18:03 -07001818
1819 SET_STATE_HANDLER(
1820 sci_dev,
1821 scic_sds_remote_device_state_handler_table,
1822 SCI_BASE_REMOTE_DEVICE_STATE_FAILED
1823 );
1824}
1825
Maciej Patelczyk9a0fff72011-04-28 22:06:01 +00001826static void scic_sds_remote_device_resetting_state_enter(void *object)
Dan Williams88f3b622011-04-22 19:18:03 -07001827{
Maciej Patelczyk5d937e92011-04-28 22:06:21 +00001828 struct scic_sds_remote_device *sci_dev = object;
Dan Williams88f3b622011-04-22 19:18:03 -07001829
1830 SET_STATE_HANDLER(
1831 sci_dev,
1832 scic_sds_remote_device_state_handler_table,
1833 SCI_BASE_REMOTE_DEVICE_STATE_RESETTING
1834 );
1835
1836 scic_sds_remote_node_context_suspend(
1837 &sci_dev->rnc, SCI_SOFTWARE_SUSPENSION, NULL, NULL);
1838}
1839
Maciej Patelczyk9a0fff72011-04-28 22:06:01 +00001840static void scic_sds_remote_device_resetting_state_exit(void *object)
Dan Williams88f3b622011-04-22 19:18:03 -07001841{
Maciej Patelczyk5d937e92011-04-28 22:06:21 +00001842 struct scic_sds_remote_device *sci_dev = object;
Dan Williams88f3b622011-04-22 19:18:03 -07001843
1844 scic_sds_remote_node_context_resume(&sci_dev->rnc, NULL, NULL);
1845}
1846
Maciej Patelczyk9a0fff72011-04-28 22:06:01 +00001847static void scic_sds_remote_device_final_state_enter(void *object)
Dan Williams88f3b622011-04-22 19:18:03 -07001848{
Maciej Patelczyk5d937e92011-04-28 22:06:21 +00001849 struct scic_sds_remote_device *sci_dev = object;
Dan Williams88f3b622011-04-22 19:18:03 -07001850
1851 SET_STATE_HANDLER(
1852 sci_dev,
1853 scic_sds_remote_device_state_handler_table,
1854 SCI_BASE_REMOTE_DEVICE_STATE_FINAL
1855 );
1856}
1857
Dan Williamsab2e8f72011-04-27 16:32:45 -07001858static void scic_sds_stp_remote_device_ready_idle_substate_enter(void *object)
1859{
1860 struct scic_sds_remote_device *sci_dev = object;
1861
1862 SET_STATE_HANDLER(sci_dev, scic_sds_remote_device_state_handler_table,
1863 SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_IDLE);
1864
1865 sci_dev->working_request = NULL;
1866 if (scic_sds_remote_node_context_is_ready(&sci_dev->rnc)) {
1867 /*
1868 * Since the RNC is ready, it's alright to finish completion
1869 * processing (e.g. signal the remote device is ready). */
1870 scic_sds_stp_remote_device_ready_idle_substate_resume_complete_handler(sci_dev);
1871 } else {
1872 scic_sds_remote_node_context_resume(&sci_dev->rnc,
1873 scic_sds_stp_remote_device_ready_idle_substate_resume_complete_handler,
1874 sci_dev);
1875 }
1876}
1877
1878static void scic_sds_stp_remote_device_ready_cmd_substate_enter(void *object)
1879{
1880 struct scic_sds_remote_device *sci_dev = object;
1881 struct scic_sds_controller *scic = scic_sds_remote_device_get_controller(sci_dev);
1882
1883 BUG_ON(sci_dev->working_request == NULL);
1884
1885 SET_STATE_HANDLER(sci_dev, scic_sds_remote_device_state_handler_table,
1886 SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_CMD);
1887
1888 isci_remote_device_not_ready(scic->ihost, sci_dev_to_idev(sci_dev),
1889 SCIC_REMOTE_DEVICE_NOT_READY_SATA_REQUEST_STARTED);
1890}
1891
1892static void scic_sds_stp_remote_device_ready_ncq_substate_enter(void *object)
1893{
1894 struct scic_sds_remote_device *sci_dev = object;
1895
1896 SET_STATE_HANDLER(sci_dev, scic_sds_remote_device_state_handler_table,
1897 SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_NCQ);
1898}
1899
1900static void scic_sds_stp_remote_device_ready_ncq_error_substate_enter(void *object)
1901{
1902 struct scic_sds_remote_device *sci_dev = object;
1903 struct scic_sds_controller *scic = scic_sds_remote_device_get_controller(sci_dev);
1904 struct isci_remote_device *idev = sci_dev_to_idev(sci_dev);
1905
1906 SET_STATE_HANDLER(sci_dev, scic_sds_remote_device_state_handler_table,
1907 SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_NCQ_ERROR);
1908
1909 if (sci_dev->not_ready_reason == SCIC_REMOTE_DEVICE_NOT_READY_SATA_SDB_ERROR_FIS_RECEIVED)
1910 isci_remote_device_not_ready(scic->ihost, idev,
1911 sci_dev->not_ready_reason);
1912}
1913
1914static void scic_sds_stp_remote_device_ready_await_reset_substate_enter(void *object)
1915{
1916 struct scic_sds_remote_device *sci_dev = object;
1917
1918 SET_STATE_HANDLER(sci_dev, scic_sds_remote_device_state_handler_table,
1919 SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_AWAIT_RESET);
1920}
1921
1922static void scic_sds_smp_remote_device_ready_idle_substate_enter(void *object)
1923{
1924 struct scic_sds_remote_device *sci_dev = object;
1925 struct scic_sds_controller *scic = scic_sds_remote_device_get_controller(sci_dev);
1926
1927 SET_STATE_HANDLER(sci_dev, scic_sds_remote_device_state_handler_table,
1928 SCIC_SDS_SMP_REMOTE_DEVICE_READY_SUBSTATE_IDLE);
1929
1930 isci_remote_device_ready(scic->ihost, sci_dev_to_idev(sci_dev));
1931}
1932
1933static void scic_sds_smp_remote_device_ready_cmd_substate_enter(void *object)
1934{
1935 struct scic_sds_remote_device *sci_dev = object;
1936 struct scic_sds_controller *scic = scic_sds_remote_device_get_controller(sci_dev);
1937
1938 BUG_ON(sci_dev->working_request == NULL);
1939
1940 SET_STATE_HANDLER(sci_dev, scic_sds_remote_device_state_handler_table,
1941 SCIC_SDS_SMP_REMOTE_DEVICE_READY_SUBSTATE_CMD);
1942
1943 isci_remote_device_not_ready(scic->ihost, sci_dev_to_idev(sci_dev),
1944 SCIC_REMOTE_DEVICE_NOT_READY_SMP_REQUEST_STARTED);
1945}
1946
1947static void scic_sds_smp_remote_device_ready_cmd_substate_exit(void *object)
1948{
1949 struct scic_sds_remote_device *sci_dev = object;
1950
1951 sci_dev->working_request = NULL;
1952}
Dan Williams88f3b622011-04-22 19:18:03 -07001953
1954static const struct sci_base_state scic_sds_remote_device_state_table[] = {
1955 [SCI_BASE_REMOTE_DEVICE_STATE_INITIAL] = {
1956 .enter_state = scic_sds_remote_device_initial_state_enter,
1957 },
1958 [SCI_BASE_REMOTE_DEVICE_STATE_STOPPED] = {
1959 .enter_state = scic_sds_remote_device_stopped_state_enter,
1960 },
1961 [SCI_BASE_REMOTE_DEVICE_STATE_STARTING] = {
1962 .enter_state = scic_sds_remote_device_starting_state_enter,
1963 },
1964 [SCI_BASE_REMOTE_DEVICE_STATE_READY] = {
1965 .enter_state = scic_sds_remote_device_ready_state_enter,
1966 .exit_state = scic_sds_remote_device_ready_state_exit
1967 },
Dan Williamsab2e8f72011-04-27 16:32:45 -07001968 [SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_IDLE] = {
1969 .enter_state = scic_sds_stp_remote_device_ready_idle_substate_enter,
1970 },
1971 [SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_CMD] = {
1972 .enter_state = scic_sds_stp_remote_device_ready_cmd_substate_enter,
1973 },
1974 [SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_NCQ] = {
1975 .enter_state = scic_sds_stp_remote_device_ready_ncq_substate_enter,
1976 },
1977 [SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_NCQ_ERROR] = {
1978 .enter_state = scic_sds_stp_remote_device_ready_ncq_error_substate_enter,
1979 },
1980 [SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_AWAIT_RESET] = {
1981 .enter_state = scic_sds_stp_remote_device_ready_await_reset_substate_enter,
1982 },
1983 [SCIC_SDS_SMP_REMOTE_DEVICE_READY_SUBSTATE_IDLE] = {
1984 .enter_state = scic_sds_smp_remote_device_ready_idle_substate_enter,
1985 },
1986 [SCIC_SDS_SMP_REMOTE_DEVICE_READY_SUBSTATE_CMD] = {
1987 .enter_state = scic_sds_smp_remote_device_ready_cmd_substate_enter,
1988 .exit_state = scic_sds_smp_remote_device_ready_cmd_substate_exit,
1989 },
Dan Williams88f3b622011-04-22 19:18:03 -07001990 [SCI_BASE_REMOTE_DEVICE_STATE_STOPPING] = {
1991 .enter_state = scic_sds_remote_device_stopping_state_enter,
1992 },
1993 [SCI_BASE_REMOTE_DEVICE_STATE_FAILED] = {
1994 .enter_state = scic_sds_remote_device_failed_state_enter,
1995 },
1996 [SCI_BASE_REMOTE_DEVICE_STATE_RESETTING] = {
1997 .enter_state = scic_sds_remote_device_resetting_state_enter,
1998 .exit_state = scic_sds_remote_device_resetting_state_exit
1999 },
2000 [SCI_BASE_REMOTE_DEVICE_STATE_FINAL] = {
2001 .enter_state = scic_sds_remote_device_final_state_enter,
2002 },
2003};
2004
2005/**
Dan Williamsb87ee302011-04-25 11:48:29 -07002006 * scic_remote_device_construct() - common construction
Dan Williams88f3b622011-04-22 19:18:03 -07002007 * @sci_port: SAS/SATA port through which this device is accessed.
2008 * @sci_dev: remote device to construct
2009 *
Dan Williamsb87ee302011-04-25 11:48:29 -07002010 * This routine just performs benign initialization and does not
2011 * allocate the remote_node_context which is left to
2012 * scic_remote_device_[de]a_construct(). scic_remote_device_destruct()
2013 * frees the remote_node_context(s) for the device.
Dan Williams88f3b622011-04-22 19:18:03 -07002014 */
2015static void scic_remote_device_construct(struct scic_sds_port *sci_port,
2016 struct scic_sds_remote_device *sci_dev)
2017{
2018 sci_dev->owning_port = sci_port;
2019 sci_dev->started_request_count = 0;
Dan Williams88f3b622011-04-22 19:18:03 -07002020
2021 sci_base_state_machine_construct(
2022 &sci_dev->state_machine,
Maciej Patelczyk5d937e92011-04-28 22:06:21 +00002023 sci_dev,
Dan Williams88f3b622011-04-22 19:18:03 -07002024 scic_sds_remote_device_state_table,
2025 SCI_BASE_REMOTE_DEVICE_STATE_INITIAL
2026 );
2027
2028 sci_base_state_machine_start(
2029 &sci_dev->state_machine
2030 );
2031
2032 scic_sds_remote_node_context_construct(&sci_dev->rnc,
2033 SCIC_SDS_REMOTE_NODE_CONTEXT_INVALID_INDEX);
Dan Williams88f3b622011-04-22 19:18:03 -07002034}
2035
2036/**
Dan Williamsb87ee302011-04-25 11:48:29 -07002037 * scic_remote_device_da_construct() - construct direct attached device.
Dan Williams88f3b622011-04-22 19:18:03 -07002038 *
Dan Williamsb87ee302011-04-25 11:48:29 -07002039 * The information (e.g. IAF, Signature FIS, etc.) necessary to build
2040 * the device is known to the SCI Core since it is contained in the
2041 * scic_phy object. Remote node context(s) is/are a global resource
2042 * allocated by this routine, freed by scic_remote_device_destruct().
2043 *
2044 * Returns:
2045 * SCI_FAILURE_DEVICE_EXISTS - device has already been constructed.
2046 * SCI_FAILURE_UNSUPPORTED_PROTOCOL - e.g. sas device attached to
2047 * sata-only controller instance.
2048 * SCI_FAILURE_INSUFFICIENT_RESOURCES - remote node contexts exhausted.
Dan Williams88f3b622011-04-22 19:18:03 -07002049 */
Dan Williamsb87ee302011-04-25 11:48:29 -07002050static enum sci_status scic_remote_device_da_construct(struct scic_sds_port *sci_port,
2051 struct scic_sds_remote_device *sci_dev)
Dan Williams88f3b622011-04-22 19:18:03 -07002052{
2053 enum sci_status status;
Dan Williamsa1a113b2011-04-21 18:44:45 -07002054 struct domain_device *dev = sci_dev_to_domain(sci_dev);
Dan Williams88f3b622011-04-22 19:18:03 -07002055
Dan Williamsb87ee302011-04-25 11:48:29 -07002056 scic_remote_device_construct(sci_port, sci_dev);
2057
Dan Williams88f3b622011-04-22 19:18:03 -07002058 /*
2059 * This information is request to determine how many remote node context
2060 * entries will be needed to store the remote node.
2061 */
Dan Williams88f3b622011-04-22 19:18:03 -07002062 sci_dev->is_direct_attached = true;
Dan Williamsa1a113b2011-04-21 18:44:45 -07002063 status = scic_sds_controller_allocate_remote_node_context(sci_port->owning_controller,
2064 sci_dev,
Dan Williamsab2e8f72011-04-27 16:32:45 -07002065 &sci_dev->rnc.remote_node_index);
Dan Williams88f3b622011-04-22 19:18:03 -07002066
Dan Williamsa1a113b2011-04-21 18:44:45 -07002067 if (status != SCI_SUCCESS)
2068 return status;
Dan Williams88f3b622011-04-22 19:18:03 -07002069
Dan Williamsab2e8f72011-04-27 16:32:45 -07002070 if (dev->dev_type == SAS_END_DEV || dev->dev_type == SATA_DEV ||
2071 (dev->tproto & SAS_PROTOCOL_STP) || dev_is_expander(dev))
2072 /* pass */;
2073 else
Dan Williamsa1a113b2011-04-21 18:44:45 -07002074 return SCI_FAILURE_UNSUPPORTED_PROTOCOL;
Dan Williams88f3b622011-04-22 19:18:03 -07002075
Dan Williamsa1a113b2011-04-21 18:44:45 -07002076 sci_dev->connection_rate = scic_sds_port_get_max_allowed_speed(sci_port);
Dan Williams88f3b622011-04-22 19:18:03 -07002077
Dan Williamsa1a113b2011-04-21 18:44:45 -07002078 /* / @todo Should I assign the port width by reading all of the phys on the port? */
2079 sci_dev->device_port_width = 1;
Dan Williams88f3b622011-04-22 19:18:03 -07002080
Dan Williamsa1a113b2011-04-21 18:44:45 -07002081 return SCI_SUCCESS;
Dan Williams88f3b622011-04-22 19:18:03 -07002082}
2083
Dan Williams88f3b622011-04-22 19:18:03 -07002084/**
Dan Williamsb87ee302011-04-25 11:48:29 -07002085 * scic_remote_device_ea_construct() - construct expander attached device
Dan Williams88f3b622011-04-22 19:18:03 -07002086 *
Dan Williamsb87ee302011-04-25 11:48:29 -07002087 * Remote node context(s) is/are a global resource allocated by this
2088 * routine, freed by scic_remote_device_destruct().
2089 *
2090 * Returns:
2091 * SCI_FAILURE_DEVICE_EXISTS - device has already been constructed.
2092 * SCI_FAILURE_UNSUPPORTED_PROTOCOL - e.g. sas device attached to
2093 * sata-only controller instance.
2094 * SCI_FAILURE_INSUFFICIENT_RESOURCES - remote node contexts exhausted.
Dan Williams88f3b622011-04-22 19:18:03 -07002095 */
Dan Williamsb87ee302011-04-25 11:48:29 -07002096static enum sci_status scic_remote_device_ea_construct(struct scic_sds_port *sci_port,
Dan Williams00d680e2011-04-25 14:29:29 -07002097 struct scic_sds_remote_device *sci_dev)
Dan Williams88f3b622011-04-22 19:18:03 -07002098{
Dan Williamsa1a113b2011-04-21 18:44:45 -07002099 struct domain_device *dev = sci_dev_to_domain(sci_dev);
Dan Williams88f3b622011-04-22 19:18:03 -07002100 enum sci_status status;
Dan Williams88f3b622011-04-22 19:18:03 -07002101
Dan Williamsb87ee302011-04-25 11:48:29 -07002102 scic_remote_device_construct(sci_port, sci_dev);
Dan Williams88f3b622011-04-22 19:18:03 -07002103
Dan Williamsab2e8f72011-04-27 16:32:45 -07002104 status = scic_sds_controller_allocate_remote_node_context(sci_port->owning_controller,
2105 sci_dev,
2106 &sci_dev->rnc.remote_node_index);
Dan Williamsa1a113b2011-04-21 18:44:45 -07002107 if (status != SCI_SUCCESS)
2108 return status;
Dan Williams88f3b622011-04-22 19:18:03 -07002109
Dan Williamsab2e8f72011-04-27 16:32:45 -07002110 if (dev->dev_type == SAS_END_DEV || dev->dev_type == SATA_DEV ||
2111 (dev->tproto & SAS_PROTOCOL_STP) || dev_is_expander(dev))
2112 /* pass */;
2113 else
2114 return SCI_FAILURE_UNSUPPORTED_PROTOCOL;
Dan Williams88f3b622011-04-22 19:18:03 -07002115
Dan Williamsa1a113b2011-04-21 18:44:45 -07002116 /*
2117 * For SAS-2 the physical link rate is actually a logical link
2118 * rate that incorporates multiplexing. The SCU doesn't
2119 * incorporate multiplexing and for the purposes of the
2120 * connection the logical link rate is that same as the
2121 * physical. Furthermore, the SAS-2 and SAS-1.1 fields overlay
2122 * one another, so this code works for both situations. */
2123 sci_dev->connection_rate = min_t(u16, scic_sds_port_get_max_allowed_speed(sci_port),
Dan Williams00d680e2011-04-25 14:29:29 -07002124 dev->linkrate);
Dan Williams88f3b622011-04-22 19:18:03 -07002125
Dan Williamsa1a113b2011-04-21 18:44:45 -07002126 /* / @todo Should I assign the port width by reading all of the phys on the port? */
2127 sci_dev->device_port_width = 1;
Dan Williams88f3b622011-04-22 19:18:03 -07002128
Dan Williamsab2e8f72011-04-27 16:32:45 -07002129 return SCI_SUCCESS;
Dan Williams88f3b622011-04-22 19:18:03 -07002130}
2131
2132/**
2133 * scic_remote_device_start() - This method will start the supplied remote
2134 * device. This method enables normal IO requests to flow through to the
2135 * remote device.
2136 * @remote_device: This parameter specifies the device to be started.
2137 * @timeout: This parameter specifies the number of milliseconds in which the
2138 * start operation should complete.
2139 *
2140 * An indication of whether the device was successfully started. SCI_SUCCESS
2141 * This value is returned if the device was successfully started.
2142 * SCI_FAILURE_INVALID_PHY This value is returned if the user attempts to start
2143 * the device when there have been no phys added to it.
2144 */
2145static enum sci_status scic_remote_device_start(struct scic_sds_remote_device *sci_dev,
2146 u32 timeout)
2147{
2148 return sci_dev->state_handlers->start_handler(sci_dev);
2149}
Dan Williams6f231dd2011-07-02 22:56:22 -07002150
Dan Williams00d680e2011-04-25 14:29:29 -07002151static enum sci_status isci_remote_device_construct(struct isci_port *iport,
2152 struct isci_remote_device *idev)
Dan Williams6f231dd2011-07-02 22:56:22 -07002153{
Dan Williams00d680e2011-04-25 14:29:29 -07002154 struct scic_sds_port *sci_port = iport->sci_port_handle;
2155 struct isci_host *ihost = iport->isci_host;
2156 struct domain_device *dev = idev->domain_dev;
2157 enum sci_status status;
Dan Williams6f231dd2011-07-02 22:56:22 -07002158
Dan Williams00d680e2011-04-25 14:29:29 -07002159 if (dev->parent && dev_is_expander(dev->parent))
2160 status = scic_remote_device_ea_construct(sci_port, &idev->sci);
2161 else
2162 status = scic_remote_device_da_construct(sci_port, &idev->sci);
Dan Williams6f231dd2011-07-02 22:56:22 -07002163
2164 if (status != SCI_SUCCESS) {
Dan Williams00d680e2011-04-25 14:29:29 -07002165 dev_dbg(&ihost->pdev->dev, "%s: construct failed: %d\n",
2166 __func__, status);
Dan Williams6f231dd2011-07-02 22:56:22 -07002167
2168 return status;
2169 }
2170
Dan Williams6f231dd2011-07-02 22:56:22 -07002171 /* start the device. */
Dan Williams00d680e2011-04-25 14:29:29 -07002172 status = scic_remote_device_start(&idev->sci, ISCI_REMOTE_DEVICE_START_TIMEOUT);
Dan Williams6f231dd2011-07-02 22:56:22 -07002173
Dan Williams00d680e2011-04-25 14:29:29 -07002174 if (status != SCI_SUCCESS)
2175 dev_warn(&ihost->pdev->dev, "remote device start failed: %d\n",
2176 status);
Dan Williams6f231dd2011-07-02 22:56:22 -07002177
2178 return status;
2179}
2180
Dan Williams4393aa42011-03-31 13:10:44 -07002181void isci_remote_device_nuke_requests(struct isci_host *ihost, struct isci_remote_device *idev)
Dan Williams6f231dd2011-07-02 22:56:22 -07002182{
2183 DECLARE_COMPLETION_ONSTACK(aborted_task_completion);
Dan Williams6f231dd2011-07-02 22:56:22 -07002184
Dan Williams4393aa42011-03-31 13:10:44 -07002185 dev_dbg(&ihost->pdev->dev,
2186 "%s: idev = %p\n", __func__, idev);
Dan Williams6f231dd2011-07-02 22:56:22 -07002187
2188 /* Cleanup all requests pending for this device. */
Dan Williams4393aa42011-03-31 13:10:44 -07002189 isci_terminate_pending_requests(ihost, idev, terminating);
Dan Williams6f231dd2011-07-02 22:56:22 -07002190
Dan Williams4393aa42011-03-31 13:10:44 -07002191 dev_dbg(&ihost->pdev->dev,
2192 "%s: idev = %p, done\n", __func__, idev);
Dan Williams6f231dd2011-07-02 22:56:22 -07002193}
2194
Dan Williams6f231dd2011-07-02 22:56:22 -07002195/**
2196 * This function builds the isci_remote_device when a libsas dev_found message
2197 * is received.
2198 * @isci_host: This parameter specifies the isci host object.
2199 * @port: This parameter specifies the isci_port conected to this device.
2200 *
2201 * pointer to new isci_remote_device.
2202 */
2203static struct isci_remote_device *
Dan Williamsd9c37392011-03-03 17:59:32 -08002204isci_remote_device_alloc(struct isci_host *ihost, struct isci_port *iport)
Dan Williams6f231dd2011-07-02 22:56:22 -07002205{
Dan Williamsd9c37392011-03-03 17:59:32 -08002206 struct isci_remote_device *idev;
2207 int i;
Dan Williams6f231dd2011-07-02 22:56:22 -07002208
Dan Williamsd9c37392011-03-03 17:59:32 -08002209 for (i = 0; i < SCI_MAX_REMOTE_DEVICES; i++) {
Dan Williams57f20f42011-04-21 18:14:45 -07002210 idev = &ihost->devices[i];
Dan Williamsd9c37392011-03-03 17:59:32 -08002211 if (!test_and_set_bit(IDEV_ALLOCATED, &idev->flags))
2212 break;
2213 }
Dan Williams6f231dd2011-07-02 22:56:22 -07002214
Dan Williamsd9c37392011-03-03 17:59:32 -08002215 if (i >= SCI_MAX_REMOTE_DEVICES) {
2216 dev_warn(&ihost->pdev->dev, "%s: failed\n", __func__);
Dan Williams6f231dd2011-07-02 22:56:22 -07002217 return NULL;
2218 }
2219
Bartosz Barcinski6cb4d6b2011-04-12 17:28:43 -07002220 if (WARN_ONCE(!list_empty(&idev->reqs_in_process), "found requests in process\n"))
2221 return NULL;
2222
2223 if (WARN_ONCE(!list_empty(&idev->node), "found non-idle remote device\n"))
2224 return NULL;
2225
Dan Williamsd9c37392011-03-03 17:59:32 -08002226 isci_remote_device_change_state(idev, isci_freed);
Dan Williams6f231dd2011-07-02 22:56:22 -07002227
Dan Williamsd9c37392011-03-03 17:59:32 -08002228 return idev;
Dan Williams6f231dd2011-07-02 22:56:22 -07002229}
Dan Williams6f231dd2011-07-02 22:56:22 -07002230
2231/**
Dan Williams6f231dd2011-07-02 22:56:22 -07002232 * isci_remote_device_stop() - This function is called internally to stop the
2233 * remote device.
2234 * @isci_host: This parameter specifies the isci host object.
2235 * @isci_device: This parameter specifies the remote device.
2236 *
2237 * The status of the scic request to stop.
2238 */
Dan Williams6ad31fe2011-03-04 12:10:29 -08002239enum sci_status isci_remote_device_stop(struct isci_host *ihost, struct isci_remote_device *idev)
Dan Williams6f231dd2011-07-02 22:56:22 -07002240{
2241 enum sci_status status;
2242 unsigned long flags;
Dan Williams6f231dd2011-07-02 22:56:22 -07002243
Dan Williams6ad31fe2011-03-04 12:10:29 -08002244 dev_dbg(&ihost->pdev->dev,
2245 "%s: isci_device = %p\n", __func__, idev);
Dan Williams6f231dd2011-07-02 22:56:22 -07002246
Dan Williams6ad31fe2011-03-04 12:10:29 -08002247 isci_remote_device_change_state(idev, isci_stopping);
Jeff Skirvin6e2802a2011-03-08 20:32:16 -07002248
2249 /* Kill all outstanding requests. */
Dan Williams4393aa42011-03-31 13:10:44 -07002250 isci_remote_device_nuke_requests(ihost, idev);
Jeff Skirvin6e2802a2011-03-08 20:32:16 -07002251
Dan Williams6ad31fe2011-03-04 12:10:29 -08002252 set_bit(IDEV_STOP_PENDING, &idev->flags);
Dan Williams6f231dd2011-07-02 22:56:22 -07002253
Dan Williams6ad31fe2011-03-04 12:10:29 -08002254 spin_lock_irqsave(&ihost->scic_lock, flags);
Dan Williams57f20f42011-04-21 18:14:45 -07002255 status = scic_remote_device_stop(&idev->sci, 50);
Dan Williams6ad31fe2011-03-04 12:10:29 -08002256 spin_unlock_irqrestore(&ihost->scic_lock, flags);
Dan Williams6f231dd2011-07-02 22:56:22 -07002257
2258 /* Wait for the stop complete callback. */
Dan Williamsd9c37392011-03-03 17:59:32 -08002259 if (status == SCI_SUCCESS) {
Dan Williams6ad31fe2011-03-04 12:10:29 -08002260 wait_for_device_stop(ihost, idev);
Dan Williamsd9c37392011-03-03 17:59:32 -08002261 clear_bit(IDEV_ALLOCATED, &idev->flags);
2262 }
Dan Williams6f231dd2011-07-02 22:56:22 -07002263
Dan Williams6ad31fe2011-03-04 12:10:29 -08002264 dev_dbg(&ihost->pdev->dev,
2265 "%s: idev = %p - after completion wait\n",
2266 __func__, idev);
Dan Williams6f231dd2011-07-02 22:56:22 -07002267
Dan Williams6f231dd2011-07-02 22:56:22 -07002268 return status;
2269}
2270
2271/**
2272 * isci_remote_device_gone() - This function is called by libsas when a domain
2273 * device is removed.
2274 * @domain_device: This parameter specifies the libsas domain device.
2275 *
2276 */
Dan Williams6ad31fe2011-03-04 12:10:29 -08002277void isci_remote_device_gone(struct domain_device *dev)
Dan Williams6f231dd2011-07-02 22:56:22 -07002278{
Dan Williams4393aa42011-03-31 13:10:44 -07002279 struct isci_host *ihost = dev_to_ihost(dev);
Dan Williams6ad31fe2011-03-04 12:10:29 -08002280 struct isci_remote_device *idev = dev->lldd_dev;
Dan Williams6f231dd2011-07-02 22:56:22 -07002281
Dan Williams6ad31fe2011-03-04 12:10:29 -08002282 dev_dbg(&ihost->pdev->dev,
Dan Williams6f231dd2011-07-02 22:56:22 -07002283 "%s: domain_device = %p, isci_device = %p, isci_port = %p\n",
Dan Williams6ad31fe2011-03-04 12:10:29 -08002284 __func__, dev, idev, idev->isci_port);
Dan Williams6f231dd2011-07-02 22:56:22 -07002285
Dan Williams6ad31fe2011-03-04 12:10:29 -08002286 isci_remote_device_stop(ihost, idev);
Dan Williams6f231dd2011-07-02 22:56:22 -07002287}
2288
2289
2290/**
2291 * isci_remote_device_found() - This function is called by libsas when a remote
2292 * device is discovered. A remote device object is created and started. the
2293 * function then sleeps until the sci core device started message is
2294 * received.
2295 * @domain_device: This parameter specifies the libsas domain device.
2296 *
2297 * status, zero indicates success.
2298 */
2299int isci_remote_device_found(struct domain_device *domain_dev)
2300{
Dan Williams4393aa42011-03-31 13:10:44 -07002301 struct isci_host *isci_host = dev_to_ihost(domain_dev);
Dan Williams6f231dd2011-07-02 22:56:22 -07002302 struct isci_port *isci_port;
2303 struct isci_phy *isci_phy;
2304 struct asd_sas_port *sas_port;
2305 struct asd_sas_phy *sas_phy;
2306 struct isci_remote_device *isci_device;
2307 enum sci_status status;
Dan Williams6f231dd2011-07-02 22:56:22 -07002308
Dan Williams6f231dd2011-07-02 22:56:22 -07002309 dev_dbg(&isci_host->pdev->dev,
2310 "%s: domain_device = %p\n", __func__, domain_dev);
2311
Dan Williams0cf89d12011-02-18 09:25:07 -08002312 wait_for_start(isci_host);
2313
Dan Williams6f231dd2011-07-02 22:56:22 -07002314 sas_port = domain_dev->port;
2315 sas_phy = list_first_entry(&sas_port->phy_list, struct asd_sas_phy,
2316 port_phy_el);
2317 isci_phy = to_isci_phy(sas_phy);
2318 isci_port = isci_phy->isci_port;
2319
2320 /* we are being called for a device on this port,
2321 * so it has to come up eventually
2322 */
2323 wait_for_completion(&isci_port->start_complete);
2324
2325 if ((isci_stopping == isci_port_get_state(isci_port)) ||
2326 (isci_stopped == isci_port_get_state(isci_port)))
2327 return -ENODEV;
2328
2329 isci_device = isci_remote_device_alloc(isci_host, isci_port);
Dan Williamsd9c37392011-03-03 17:59:32 -08002330 if (!isci_device)
2331 return -ENODEV;
Dan Williams6f231dd2011-07-02 22:56:22 -07002332
2333 INIT_LIST_HEAD(&isci_device->node);
2334 domain_dev->lldd_dev = isci_device;
2335 isci_device->domain_dev = domain_dev;
2336 isci_device->isci_port = isci_port;
2337 isci_remote_device_change_state(isci_device, isci_starting);
2338
2339
Dan Williams1a380452011-03-03 18:01:43 -08002340 spin_lock_irq(&isci_host->scic_lock);
Dan Williams6f231dd2011-07-02 22:56:22 -07002341 list_add_tail(&isci_device->node, &isci_port->remote_dev_list);
2342
Dan Williams6ad31fe2011-03-04 12:10:29 -08002343 set_bit(IDEV_START_PENDING, &isci_device->flags);
Dan Williams6f231dd2011-07-02 22:56:22 -07002344 status = isci_remote_device_construct(isci_port, isci_device);
Dan Williams1a380452011-03-03 18:01:43 -08002345 spin_unlock_irq(&isci_host->scic_lock);
Dan Williams6f231dd2011-07-02 22:56:22 -07002346
Dan Williams6f231dd2011-07-02 22:56:22 -07002347 dev_dbg(&isci_host->pdev->dev,
2348 "%s: isci_device = %p\n",
2349 __func__, isci_device);
2350
2351 if (status != SCI_SUCCESS) {
2352
Dan Williams1a380452011-03-03 18:01:43 -08002353 spin_lock_irq(&isci_host->scic_lock);
Dan Williams6f231dd2011-07-02 22:56:22 -07002354 isci_remote_device_deconstruct(
2355 isci_host,
2356 isci_device
2357 );
Dan Williams1a380452011-03-03 18:01:43 -08002358 spin_unlock_irq(&isci_host->scic_lock);
Dan Williams6f231dd2011-07-02 22:56:22 -07002359 return -ENODEV;
2360 }
2361
Dan Williams6ad31fe2011-03-04 12:10:29 -08002362 /* wait for the device ready callback. */
2363 wait_for_device_start(isci_host, isci_device);
2364
Dan Williams6f231dd2011-07-02 22:56:22 -07002365 return 0;
2366}
2367/**
2368 * isci_device_is_reset_pending() - This function will check if there is any
2369 * pending reset condition on the device.
2370 * @request: This parameter is the isci_device object.
2371 *
2372 * true if there is a reset pending for the device.
2373 */
2374bool isci_device_is_reset_pending(
2375 struct isci_host *isci_host,
2376 struct isci_remote_device *isci_device)
2377{
2378 struct isci_request *isci_request;
2379 struct isci_request *tmp_req;
2380 bool reset_is_pending = false;
2381 unsigned long flags;
2382
2383 dev_dbg(&isci_host->pdev->dev,
2384 "%s: isci_device = %p\n", __func__, isci_device);
2385
2386 spin_lock_irqsave(&isci_host->scic_lock, flags);
2387
2388 /* Check for reset on all pending requests. */
2389 list_for_each_entry_safe(isci_request, tmp_req,
2390 &isci_device->reqs_in_process, dev_node) {
2391 dev_dbg(&isci_host->pdev->dev,
2392 "%s: isci_device = %p request = %p\n",
2393 __func__, isci_device, isci_request);
2394
2395 if (isci_request->ttype == io_task) {
Dan Williams6f231dd2011-07-02 22:56:22 -07002396 struct sas_task *task = isci_request_access_task(
2397 isci_request);
2398
Bartosz Barcinski467e8552011-04-12 17:28:41 -07002399 spin_lock(&task->task_state_lock);
Dan Williams6f231dd2011-07-02 22:56:22 -07002400 if (task->task_state_flags & SAS_TASK_NEED_DEV_RESET)
2401 reset_is_pending = true;
Bartosz Barcinski467e8552011-04-12 17:28:41 -07002402 spin_unlock(&task->task_state_lock);
Dan Williams6f231dd2011-07-02 22:56:22 -07002403 }
2404 }
2405
2406 spin_unlock_irqrestore(&isci_host->scic_lock, flags);
2407
2408 dev_dbg(&isci_host->pdev->dev,
2409 "%s: isci_device = %p reset_is_pending = %d\n",
2410 __func__, isci_device, reset_is_pending);
2411
2412 return reset_is_pending;
2413}
2414
2415/**
2416 * isci_device_clear_reset_pending() - This function will clear if any pending
2417 * reset condition flags on the device.
2418 * @request: This parameter is the isci_device object.
2419 *
2420 * true if there is a reset pending for the device.
2421 */
Dan Williams4393aa42011-03-31 13:10:44 -07002422void isci_device_clear_reset_pending(struct isci_host *ihost, struct isci_remote_device *idev)
Dan Williams6f231dd2011-07-02 22:56:22 -07002423{
2424 struct isci_request *isci_request;
2425 struct isci_request *tmp_req;
Dan Williams6f231dd2011-07-02 22:56:22 -07002426 unsigned long flags = 0;
2427
Dan Williams4393aa42011-03-31 13:10:44 -07002428 dev_dbg(&ihost->pdev->dev, "%s: idev=%p, ihost=%p\n",
2429 __func__, idev, ihost);
Dan Williams6f231dd2011-07-02 22:56:22 -07002430
Dan Williams4393aa42011-03-31 13:10:44 -07002431 spin_lock_irqsave(&ihost->scic_lock, flags);
Dan Williams6f231dd2011-07-02 22:56:22 -07002432
2433 /* Clear reset pending on all pending requests. */
2434 list_for_each_entry_safe(isci_request, tmp_req,
Dan Williams4393aa42011-03-31 13:10:44 -07002435 &idev->reqs_in_process, dev_node) {
2436 dev_dbg(&ihost->pdev->dev, "%s: idev = %p request = %p\n",
2437 __func__, idev, isci_request);
Dan Williams6f231dd2011-07-02 22:56:22 -07002438
2439 if (isci_request->ttype == io_task) {
2440
2441 unsigned long flags2;
2442 struct sas_task *task = isci_request_access_task(
2443 isci_request);
2444
2445 spin_lock_irqsave(&task->task_state_lock, flags2);
2446 task->task_state_flags &= ~SAS_TASK_NEED_DEV_RESET;
2447 spin_unlock_irqrestore(&task->task_state_lock, flags2);
2448 }
2449 }
Dan Williams4393aa42011-03-31 13:10:44 -07002450 spin_unlock_irqrestore(&ihost->scic_lock, flags);
Dan Williams6f231dd2011-07-02 22:56:22 -07002451}