isci: Intel(R) C600 Series Chipset Storage Control Unit Driver
[platform/adaptation/renesas_rcar/renesas_kernel.git] / drivers / scsi / isci / events.c
1 /*
2  * This file is provided under a dual BSD/GPLv2 license.  When using or
3  * redistributing this file, you may do so under either license.
4  *
5  * GPL LICENSE SUMMARY
6  *
7  * Copyright(c) 2008 - 2011 Intel Corporation. All rights reserved.
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of version 2 of the GNU General Public License as
11  * published by the Free Software Foundation.
12  *
13  * This program is distributed in the hope that it will be useful, but
14  * WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16  * General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
21  * The full GNU General Public License is included in this distribution
22  * in the file called LICENSE.GPL.
23  *
24  * BSD LICENSE
25  *
26  * Copyright(c) 2008 - 2011 Intel Corporation. All rights reserved.
27  * All rights reserved.
28  *
29  * Redistribution and use in source and binary forms, with or without
30  * modification, are permitted provided that the following conditions
31  * are met:
32  *
33  *   * Redistributions of source code must retain the above copyright
34  *     notice, this list of conditions and the following disclaimer.
35  *   * Redistributions in binary form must reproduce the above copyright
36  *     notice, this list of conditions and the following disclaimer in
37  *     the documentation and/or other materials provided with the
38  *     distribution.
39  *   * Neither the name of Intel Corporation nor the names of its
40  *     contributors may be used to endorse or promote products derived
41  *     from this software without specific prior written permission.
42  *
43  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
44  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
45  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
46  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
47  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
48  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
49  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
50  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
51  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
52  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
53  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
54  */
55
56
57 /**
58  * This file contains isci module object implementation.
59  *
60  *
61  */
62
63 #include "isci.h"
64 #include "request.h"
65 #include "sata.h"
66 #include "task.h"
67
68 /**
69  * scic_cb_timer_create() - This callback method asks the user to create a
70  *    timer and provide a handle for this timer for use in further timer
71  *    interactions. The appropriate isci timer object function is called to
72  *    create a timer object.
73  * @timer_callback: This parameter specifies the callback method to be invoked
74  *    whenever the timer expires.
75  * @controller: This parameter specifies the controller with which this timer
76  *    is to be associated.
77  * @cookie: This parameter specifies a piece of information that the user must
78  *    retain.  This cookie is to be supplied by the user anytime a timeout
79  *    occurs for the created timer.
80  *
81  * This method returns a handle to a timer object created by the user.  The
82  * handle will be utilized for all further interactions relating to this timer.
83  */
84 void *scic_cb_timer_create(
85         struct scic_sds_controller *controller,
86         void (*timer_callback)(void *),
87         void *cookie)
88 {
89         struct isci_host *isci_host;
90         struct isci_timer *timer = NULL;
91
92         isci_host = (struct isci_host *)sci_object_get_association(controller);
93
94         dev_dbg(&isci_host->pdev->dev,
95                 "%s: isci_host = %p",
96                 __func__, isci_host);
97
98         timer = isci_timer_create(&isci_host->timer_list_struct,
99                                   isci_host,
100                                   cookie,
101                                   timer_callback);
102
103         dev_dbg(&isci_host->pdev->dev, "%s: timer = %p\n", __func__, timer);
104
105         return (void *)timer;
106 }
107
108
109 /**
110  * scic_cb_timer_start() - This callback method asks the user to start the
111  *    supplied timer. The appropriate isci timer object function is called to
112  *    start the timer.
113  * @controller: This parameter specifies the controller with which this timer
114  *    is to associated.
115  * @timer: This parameter specifies the timer to be started.
116  * @milliseconds: This parameter specifies the number of milliseconds for which
117  *    to stall.  The operating system driver is allowed to round this value up
118  *    where necessary.
119  *
120  */
121 void scic_cb_timer_start(
122         struct scic_sds_controller *controller,
123         void *timer,
124         u32 milliseconds)
125 {
126         struct isci_host *isci_host;
127
128         isci_host =
129                 (struct isci_host *)sci_object_get_association(controller);
130
131         dev_dbg(&isci_host->pdev->dev,
132                 "%s: isci_host = %p, timer = %p, milliseconds = %d\n",
133                 __func__, isci_host, timer, milliseconds);
134
135         isci_timer_start((struct isci_timer *)timer, milliseconds);
136
137 }
138
139 /**
140  * scic_cb_timer_stop() - This callback method asks the user to stop the
141  *    supplied timer. The appropriate isci timer object function is called to
142  *    stop the timer.
143  * @controller: This parameter specifies the controller with which this timer
144  *    is to associated.
145  * @timer: This parameter specifies the timer to be stopped.
146  *
147  */
148 void scic_cb_timer_stop(
149         struct scic_sds_controller *controller,
150         void *timer)
151 {
152         struct isci_host *isci_host;
153
154         isci_host =
155                 (struct isci_host *)sci_object_get_association(controller);
156
157         dev_dbg(&isci_host->pdev->dev,
158                 "%s: isci_host = %p, timer = %p\n",
159                 __func__, isci_host, timer);
160
161         isci_timer_stop((struct isci_timer *)timer);
162 }
163
164 /**
165  * scic_cb_controller_start_complete() - This user callback will inform the
166  *    user that the controller has finished the start process. The associated
167  *    isci host adapter's start_complete function is called.
168  * @controller: This parameter specifies the controller that was started.
169  * @completion_status: This parameter specifies the results of the start
170  *    operation.  SCI_SUCCESS indicates successful completion.
171  *
172  */
173 void scic_cb_controller_start_complete(
174         struct scic_sds_controller *controller,
175         enum sci_status completion_status)
176 {
177         struct isci_host *isci_host =
178                 (struct isci_host *)sci_object_get_association(controller);
179
180         dev_dbg(&isci_host->pdev->dev,
181                 "%s: isci_host = %p\n", __func__, isci_host);
182
183         isci_host_start_complete(isci_host, completion_status);
184 }
185
186 /**
187  * scic_cb_controller_stop_complete() - This user callback will inform the user
188  *    that the controller has finished the stop process. The associated isci
189  *    host adapter's start_complete function is called.
190  * @controller: This parameter specifies the controller that was stopped.
191  * @completion_status: This parameter specifies the results of the stop
192  *    operation.  SCI_SUCCESS indicates successful completion.
193  *
194  */
195 void scic_cb_controller_stop_complete(
196         struct scic_sds_controller *controller,
197         enum sci_status completion_status)
198 {
199         struct isci_host *isci_host =
200                 (struct isci_host *)sci_object_get_association(controller);
201
202         dev_dbg(&isci_host->pdev->dev,
203                 "%s: status = 0x%x\n", __func__, completion_status);
204         isci_host_stop_complete(isci_host, completion_status);
205 }
206
207 /**
208  * scic_cb_io_request_complete() - This user callback will inform the user that
209  *    an IO request has completed.
210  * @controller: This parameter specifies the controller on which the IO is
211  *    completing.
212  * @remote_device: This parameter specifies the remote device on which this IO
213  *    request is completing.
214  * @io_request: This parameter specifies the IO request that has completed.
215  * @completion_status: This parameter specifies the results of the IO request
216  *    operation.  SCI_SUCCESS indicates successful completion.
217  *
218  */
219 void scic_cb_io_request_complete(
220         struct scic_sds_controller *controller,
221         struct scic_sds_remote_device *remote_device,
222         struct scic_sds_request *scic_io_request,
223         enum sci_io_status completion_status)
224 {
225         struct isci_request *request;
226         struct isci_host *isci_host;
227
228         isci_host =
229                 (struct isci_host *)sci_object_get_association(controller);
230
231         request =
232                 (struct isci_request *)sci_object_get_association(
233                         scic_io_request
234                         );
235
236         isci_request_io_request_complete(isci_host,
237                                          request,
238                                          completion_status);
239 }
240
241 /**
242  * scic_cb_task_request_complete() - This user callback will inform the user
243  *    that a task management request completed.
244  * @controller: This parameter specifies the controller on which the task
245  *    management request is completing.
246  * @remote_device: This parameter specifies the remote device on which this
247  *    task management request is completing.
248  * @task_request: This parameter specifies the task management request that has
249  *    completed.
250  * @completion_status: This parameter specifies the results of the IO request
251  *    operation.  SCI_SUCCESS indicates successful completion.
252  *
253  */
254 void scic_cb_task_request_complete(
255         struct scic_sds_controller *controller,
256         struct scic_sds_remote_device *remote_device,
257         struct scic_sds_request *scic_task_request,
258         enum sci_task_status completion_status)
259 {
260         struct isci_request *request;
261         struct isci_host *isci_host;
262
263         isci_host =
264                 (struct isci_host *)sci_object_get_association(controller);
265
266         request =
267                 (struct isci_request *)sci_object_get_association(
268                         scic_task_request);
269
270         isci_task_request_complete(isci_host, request, completion_status);
271 }
272
273 /**
274  * scic_cb_port_stop_complete() - This method informs the user when a stop
275  *    operation on the port has completed.
276  * @controller: This parameter represents the controller which contains the
277  *    port.
278  * @port: This parameter specifies the SCI port object for which the callback
279  *    is being invoked.
280  * @completion_status: This parameter specifies the status for the operation
281  *    being completed.
282  *
283  */
284 void scic_cb_port_stop_complete(
285         struct scic_sds_controller *controller,
286         struct scic_sds_port *port,
287         enum sci_status completion_status)
288 {
289         pr_warn("%s:************************************************\n",
290                 __func__);
291 }
292
293 /**
294  * scic_cb_port_hard_reset_complete() - This method informs the user when a
295  *    hard reset on the port has completed.  This hard reset could have been
296  *    initiated by the user or by the remote port.
297  * @controller: This parameter represents the controller which contains the
298  *    port.
299  * @port: This parameter specifies the SCI port object for which the callback
300  *    is being invoked.
301  * @completion_status: This parameter specifies the status for the operation
302  *    being completed.
303  *
304  */
305 void scic_cb_port_hard_reset_complete(
306         struct scic_sds_controller *controller,
307         struct scic_sds_port *port,
308         enum sci_status completion_status)
309 {
310         struct isci_port *isci_port
311                 = (struct isci_port *)sci_object_get_association(port);
312
313         isci_port_hard_reset_complete(isci_port, completion_status);
314 }
315
316 /**
317  * scic_cb_port_ready() - This method informs the user that the port is now in
318  *    a ready state and can be utilized to issue IOs.
319  * @controller: This parameter represents the controller which contains the
320  *    port.
321  * @port: This parameter specifies the SCI port object for which the callback
322  *    is being invoked.
323  *
324  */
325 void scic_cb_port_ready(
326         struct scic_sds_controller *controller,
327         struct scic_sds_port *port)
328 {
329         struct isci_port *isci_port;
330         struct isci_host *isci_host;
331
332         isci_host =
333                 (struct isci_host *)sci_object_get_association(controller);
334
335         isci_port =
336                 (struct isci_port *)sci_object_get_association(port);
337
338         dev_dbg(&isci_host->pdev->dev,
339                 "%s: isci_port = %p\n", __func__, isci_port);
340
341         isci_port_ready(isci_host, isci_port);
342 }
343
344 /**
345  * scic_cb_port_not_ready() - This method informs the user that the port is now
346  *    not in a ready (i.e. busy) state and can't be utilized to issue IOs.
347  * @controller: This parameter represents the controller which contains the
348  *    port.
349  * @port: This parameter specifies the SCI port object for which the callback
350  *    is being invoked.
351  *
352  */
353 void scic_cb_port_not_ready(
354         struct scic_sds_controller *controller,
355         struct scic_sds_port *port,
356         u32 reason_code)
357 {
358         struct isci_port *isci_port;
359         struct isci_host *isci_host;
360
361         isci_host =
362                 (struct isci_host *)sci_object_get_association(controller);
363
364         isci_port =
365                 (struct isci_port *)sci_object_get_association(port);
366
367         dev_dbg(&isci_host->pdev->dev,
368                 "%s: isci_port = %p\n", __func__, isci_port);
369
370         isci_port_not_ready(isci_host, isci_port);
371 }
372
373 /**
374  * scic_cb_port_invalid_link_up() - This method informs the SCI Core user that
375  *    a phy/link became ready, but the phy is not allowed in the port.  In some
376  *    situations the underlying hardware only allows for certain phy to port
377  *    mappings.  If these mappings are violated, then this API is invoked.
378  * @controller: This parameter represents the controller which contains the
379  *    port.
380  * @port: This parameter specifies the SCI port object for which the callback
381  *    is being invoked.
382  * @phy: This parameter specifies the phy that came ready, but the phy can't be
383  *    a valid member of the port.
384  *
385  */
386 void scic_cb_port_invalid_link_up(
387         struct scic_sds_controller *controller,
388         struct scic_sds_port *port,
389         struct scic_sds_phy *phy)
390 {
391         pr_warn("%s:************************************************\n",
392                 __func__);
393 }
394
395 /**
396  * scic_cb_port_bc_change_primitive_received() - This callback method informs
397  *    the user that a broadcast change primitive was received.
398  * @controller: This parameter represents the controller which contains the
399  *    port.
400  * @port: This parameter specifies the SCI port object for which the callback
401  *    is being invoked.  For instances where the phy on which the primitive was
402  *    received is not part of a port, this parameter will be
403  *    SCI_INVALID_HANDLE_T.
404  * @phy: This parameter specifies the phy on which the primitive was received.
405  *
406  */
407 void scic_cb_port_bc_change_primitive_received(
408         struct scic_sds_controller *controller,
409         struct scic_sds_port *port,
410         struct scic_sds_phy *phy)
411 {
412         struct isci_host *isci_host;
413
414         isci_host =
415                 (struct isci_host *)sci_object_get_association(controller);
416
417         dev_dbg(&isci_host->pdev->dev,
418                 "%s: port = %p, phy = %p\n", __func__, port, phy);
419         isci_port_bc_change_received(isci_host, port, phy);
420 }
421
422
423
424
425 /**
426  * scic_cb_port_link_up() - This callback method informs the user that a phy
427  *    has become operational and is capable of communicating with the remote
428  *    end point.
429  * @controller: This parameter represents the controller associated with the
430  *    phy.
431  * @port: This parameter specifies the port object for which the user callback
432  *    is being invoked.  There may be conditions where this parameter can be
433  *    SCI_INVALID_HANDLE
434  * @phy: This parameter specifies the phy object for which the user callback is
435  *    being invoked.
436  *
437  * none.
438  */
439 void scic_cb_port_link_up(
440         struct scic_sds_controller *controller,
441         struct scic_sds_port *port,
442         struct scic_sds_phy *phy)
443 {
444         struct isci_host *isci_host;
445
446         isci_host =
447                 (struct isci_host *)sci_object_get_association(controller);
448
449         dev_dbg(&isci_host->pdev->dev,
450                 "%s: phy = %p\n", __func__, phy);
451
452         isci_port_link_up(isci_host, port, phy);
453 }
454
455 /**
456  * scic_cb_port_link_down() - This callback method informs the user that a phy
457  *    is no longer operational and is not capable of communicating with the
458  *    remote end point.
459  * @controller: This parameter represents the controller associated with the
460  *    phy.
461  * @port: This parameter specifies the port object for which the user callback
462  *    is being invoked.  There may be conditions where this parameter can be
463  *    SCI_INVALID_HANDLE
464  * @phy: This parameter specifies the phy object for which the user callback is
465  *    being invoked.
466  *
467  * none.
468  */
469 void scic_cb_port_link_down(
470         struct scic_sds_controller *controller,
471         struct scic_sds_port *port,
472         struct scic_sds_phy *phy)
473 {
474         struct isci_host *isci_host;
475         struct isci_phy *isci_phy;
476         struct isci_port *isci_port;
477
478         isci_host =
479                 (struct isci_host *)sci_object_get_association(controller);
480
481         isci_phy =
482                 (struct isci_phy *)sci_object_get_association(phy);
483
484         isci_port =
485                 (struct isci_port *)sci_object_get_association(port);
486
487         dev_dbg(&isci_host->pdev->dev,
488                 "%s: isci_port = %p\n", __func__, isci_port);
489
490         isci_port_link_down(isci_host, isci_phy, isci_port);
491 }
492
493 /**
494  * scic_cb_remote_device_start_complete() - This user callback method will
495  *    inform the user that a start operation has completed.
496  * @controller: This parameter specifies the core controller associated with
497  *    the completion callback.
498  * @remote_device: This parameter specifies the remote device associated with
499  *    the completion callback.
500  * @completion_status: This parameter specifies the completion status for the
501  *    operation.
502  *
503  */
504 void scic_cb_remote_device_start_complete(
505         struct scic_sds_controller *controller,
506         struct scic_sds_remote_device *remote_device,
507         enum sci_status completion_status)
508 {
509         struct isci_host *isci_host;
510         struct isci_remote_device *isci_device;
511
512         isci_host =
513                 (struct isci_host *)sci_object_get_association(controller);
514
515         isci_device =
516                 (struct isci_remote_device *)sci_object_get_association(
517                         remote_device
518                         );
519
520         dev_dbg(&isci_host->pdev->dev,
521                 "%s: isci_device = %p\n", __func__, isci_device);
522
523         isci_remote_device_start_complete(
524                 isci_host, isci_device, completion_status);
525
526 }
527
528 /**
529  * scic_cb_remote_device_stop_complete() - This user callback method will
530  *    inform the user that a stop operation has completed.
531  * @controller: This parameter specifies the core controller associated with
532  *    the completion callback.
533  * @remote_device: This parameter specifies the remote device associated with
534  *    the completion callback.
535  * @completion_status: This parameter specifies the completion status for the
536  *    operation.
537  *
538  */
539 void scic_cb_remote_device_stop_complete(
540         struct scic_sds_controller *controller,
541         struct scic_sds_remote_device *remote_device,
542         enum sci_status completion_status)
543 {
544         struct isci_host *isci_host;
545         struct isci_remote_device *isci_device;
546
547         isci_host =
548                 (struct isci_host *)sci_object_get_association(controller);
549
550         isci_device =
551                 (struct isci_remote_device *)sci_object_get_association(
552                         remote_device
553                         );
554
555         dev_dbg(&isci_host->pdev->dev,
556                 "%s: isci_device = %p\n", __func__, isci_device);
557
558         isci_remote_device_stop_complete(
559                 isci_host, isci_device, completion_status);
560
561 }
562
563 /**
564  * scic_cb_remote_device_ready() - This user callback method will inform the
565  *    user that a remote device is now capable of handling IO requests.
566  * @controller: This parameter specifies the core controller associated with
567  *    the completion callback.
568  * @remote_device: This parameter specifies the remote device associated with
569  *    the callback.
570  *
571  */
572 void scic_cb_remote_device_ready(
573         struct scic_sds_controller *controller,
574         struct scic_sds_remote_device *remote_device)
575 {
576         struct isci_remote_device *isci_device =
577                 (struct isci_remote_device *)
578                 sci_object_get_association(remote_device);
579
580         dev_dbg(&isci_device->isci_port->isci_host->pdev->dev,
581                 "%s: isci_device = %p\n", __func__, isci_device);
582
583         isci_remote_device_ready(isci_device);
584 }
585
586 /**
587  * scic_cb_remote_device_not_ready() - This user callback method will inform
588  *    the user that a remote device is no longer capable of handling IO
589  *    requests (until a ready callback is invoked).
590  * @controller: This parameter specifies the core controller associated with
591  *    the completion callback.
592  * @remote_device: This parameter specifies the remote device associated with
593  *    the callback.
594  * @reason_code: This parameter specifies the reason for the remote device
595  *    going to a not ready state.
596  *
597  */
598 void scic_cb_remote_device_not_ready(
599         struct scic_sds_controller *controller,
600         struct scic_sds_remote_device *remote_device,
601         u32 reason_code)
602 {
603         struct isci_remote_device *isci_device =
604                 (struct isci_remote_device *)
605                 sci_object_get_association(remote_device);
606
607         struct isci_host *isci_host;
608
609         isci_host =
610                 (struct isci_host *)sci_object_get_association(controller);
611
612         dev_dbg(&isci_host->pdev->dev,
613                 "%s: isci_device = %p, reason_code = %x\n",
614                 __func__, isci_device, reason_code);
615
616         isci_remote_device_not_ready(isci_device, reason_code);
617 }
618
619