blob: 847e6874e1a83193fd595065f290012b9f4a0542 [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 */
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/**
70 * scic_cb_stall_execution() - This method is called when the core requires the
71 * OS driver to stall execution. This method is utilized during
72 * initialization or non-performance paths only.
73 * @microseconds: This parameter specifies the number of microseconds for which
74 * to stall. The operating system driver is allowed to round this value up
75 * where necessary.
76 *
77 * none.
78 */
79void scic_cb_stall_execution(
80 u32 microseconds)
81{
82 udelay(microseconds);
83}
84
85
86/**
87 * scic_cb_io_request_get_physical_address() - This callback method asks the
88 * user to provide the physical address for the supplied virtual address
89 * when building an io request object.
90 * @controller: This parameter is the core controller object handle.
91 * @io_request: This parameter is the io request object handle for which the
92 * physical address is being requested.
93 *
94 *
95 */
96void scic_cb_io_request_get_physical_address(
97 struct scic_sds_controller *controller,
98 struct scic_sds_request *io_request,
99 void *virtual_address,
100 dma_addr_t *physical_address)
101{
102 struct isci_request *request =
103 (struct isci_request *)sci_object_get_association(io_request);
104
105 char *requested_address = (char *)virtual_address;
106 char *base_address = (char *)request;
107
108 BUG_ON(requested_address < base_address);
109 BUG_ON((requested_address - base_address) >=
110 request->request_alloc_size);
111
112 *physical_address = request->request_daddr +
113 (requested_address - base_address);
114}
115
116/**
117 * scic_cb_io_request_get_transfer_length() - This callback method asks the
118 * user to provide the number of bytes to be transfered as part of this
119 * request.
120 * @scic_user_io_request: This parameter points to the user's IO request
121 * object. It is a cookie that allows the user to provide the necessary
122 * information for this callback.
123 *
124 * This method returns the number of payload data bytes to be transfered for
125 * this IO request.
126 */
127u32 scic_cb_io_request_get_transfer_length(
128 void *scic_user_io_request)
129{
130 return isci_request_io_request_get_transfer_length(
131 scic_user_io_request
132 );
133}
134
135
136/**
137 * scic_cb_io_request_get_data_direction() - This callback method asks the user
138 * to provide the data direction for this request.
139 * @scic_user_io_request: This parameter points to the user's IO request
140 * object. It is a cookie that allows the user to provide the necessary
141 * information for this callback.
142 *
143 * This method returns the value of SCI_IO_REQUEST_DATA_OUT or
144 * SCI_IO_REQUEST_DATA_IN, or SCI_IO_REQUEST_NO_DATA.
145 */
146SCI_IO_REQUEST_DATA_DIRECTION scic_cb_io_request_get_data_direction(
147 void *scic_user_io_request)
148{
149 return isci_request_io_request_get_data_direction(
150 scic_user_io_request
151 );
152}
153
154
155/**
156 * scic_cb_io_request_get_next_sge() - This callback method asks the user to
157 * provide the address to where the next Scatter-Gather Element is located.
158 * @scic_user_io_request: This parameter points to the user's IO request
159 * object. It is a cookie that allows the user to provide the necessary
160 * information for this callback.
161 * @current_sge_address: This parameter specifies the address for the current
162 * SGE (i.e. the one that has just processed).
163 *
164 * An address specifying the location for the next scatter gather element to be
165 * processed.
166 */
167void scic_cb_io_request_get_next_sge(
168 void *scic_user_io_request,
169 void *current_sge_address,
170 void **next_sge)
171{
172 *next_sge = isci_request_io_request_get_next_sge(
173 scic_user_io_request,
174 current_sge_address
175 );
176}
177
178/**
179 * scic_cb_sge_get_address_field() - This callback method asks the user to
180 * provide the contents of the "address" field in the Scatter-Gather Element.
181 * @scic_user_io_request: This parameter points to the user's IO request
182 * object. It is a cookie that allows the user to provide the necessary
183 * information for this callback.
184 * @sge_address: This parameter specifies the address for the SGE from which to
185 * retrieve the address field.
186 *
187 * A physical address specifying the contents of the SGE's address field.
188 */
189dma_addr_t scic_cb_sge_get_address_field(
190 void *scic_user_io_request,
191 void *sge_address)
192{
193 return isci_request_sge_get_address_field(
194 scic_user_io_request,
195 sge_address
196 );
197}
198
199/**
200 * scic_cb_sge_get_length_field() - This callback method asks the user to
201 * provide the contents of the "length" field in the Scatter-Gather Element.
202 * @scic_user_io_request: This parameter points to the user's IO request
203 * object. It is a cookie that allows the user to provide the necessary
204 * information for this callback.
205 * @sge_address: This parameter specifies the address for the SGE from which to
206 * retrieve the address field.
207 *
208 * This method returns the length field specified inside the SGE referenced by
209 * the sge_address parameter.
210 */
211u32 scic_cb_sge_get_length_field(
212 void *scic_user_io_request,
213 void *sge_address)
214{
215 return isci_request_sge_get_length_field(
216 scic_user_io_request,
217 sge_address
218 );
219}
220
221/**
222 * scic_cb_ssp_io_request_get_cdb_address() - This callback method asks the
223 * user to provide the address for the command descriptor block (CDB)
224 * associated with this IO request.
225 * @scic_user_io_request: This parameter points to the user's IO request
226 * object. It is a cookie that allows the user to provide the necessary
227 * information for this callback.
228 *
229 * This method returns the virtual address of the CDB.
230 */
231void *scic_cb_ssp_io_request_get_cdb_address(
232 void *scic_user_io_request)
233{
234 return isci_request_ssp_io_request_get_cdb_address(
235 scic_user_io_request
236 );
237}
238
239/**
240 * scic_cb_ssp_io_request_get_cdb_length() - This callback method asks the user
241 * to provide the length of the command descriptor block (CDB) associated
242 * with this IO request.
243 * @scic_user_io_request: This parameter points to the user's IO request
244 * object. It is a cookie that allows the user to provide the necessary
245 * information for this callback.
246 *
247 * This method returns the length of the CDB.
248 */
249u32 scic_cb_ssp_io_request_get_cdb_length(
250 void *scic_user_io_request)
251{
252 return isci_request_ssp_io_request_get_cdb_length(
253 scic_user_io_request
254 );
255}
256
257/**
258 * scic_cb_ssp_io_request_get_lun() - This callback method asks the user to
259 * provide the Logical Unit (LUN) associated with this IO request.
260 * @scic_user_io_request: This parameter points to the user's IO request
261 * object. It is a cookie that allows the user to provide the necessary
262 * information for this callback.
263 *
264 * This method returns the LUN associated with this request. This should be u64?
265 */
266u32 scic_cb_ssp_io_request_get_lun(
267 void *scic_user_io_request)
268{
269 return isci_request_ssp_io_request_get_lun(scic_user_io_request);
270}
271
272/**
273 * scic_cb_ssp_io_request_get_task_attribute() - This callback method asks the
274 * user to provide the task attribute associated with this IO request.
275 * @scic_user_io_request: This parameter points to the user's IO request
276 * object. It is a cookie that allows the user to provide the necessary
277 * information for this callback.
278 *
279 * This method returns the task attribute associated with this IO request.
280 */
281u32 scic_cb_ssp_io_request_get_task_attribute(
282 void *scic_user_io_request)
283{
284 return isci_request_ssp_io_request_get_task_attribute(
285 scic_user_io_request
286 );
287}
288
289/**
290 * scic_cb_ssp_io_request_get_command_priority() - This callback method asks
291 * the user to provide the command priority associated with this IO request.
292 * @scic_user_io_request: This parameter points to the user's IO request
293 * object. It is a cookie that allows the user to provide the necessary
294 * information for this callback.
295 *
296 * This method returns the command priority associated with this IO request.
297 */
298u32 scic_cb_ssp_io_request_get_command_priority(
299 void *scic_user_io_request)
300{
301 return isci_request_ssp_io_request_get_command_priority(
302 scic_user_io_request
303 );
304}
305
306/**
307 * scic_cb_ssp_task_request_get_lun() - This method returns the Logical Unit to
308 * be utilized for this task management request.
309 * @scic_user_task_request: This parameter points to the user's task request
310 * object. It is a cookie that allows the user to provide the necessary
311 * information for this callback.
312 *
313 * This method returns the LUN associated with this request. This should be u64?
314 */
315u32 scic_cb_ssp_task_request_get_lun(
316 void *scic_user_task_request)
317{
318 return isci_task_ssp_request_get_lun(
319 (struct isci_request *)scic_user_task_request
320 );
321}
322
323/**
324 * scic_cb_ssp_task_request_get_function() - This method returns the task
325 * management function to be utilized for this task request.
326 * @scic_user_task_request: This parameter points to the user's task request
327 * object. It is a cookie that allows the user to provide the necessary
328 * information for this callback.
329 *
330 * This method returns an unsigned byte representing the task management
331 * function to be performed.
332 */
333u8 scic_cb_ssp_task_request_get_function(
334 void *scic_user_task_request)
335{
336 return isci_task_ssp_request_get_function(
337 (struct isci_request *)scic_user_task_request
338 );
339}
340
341/**
342 * scic_cb_ssp_task_request_get_io_tag_to_manage() - This method returns the
343 * task management IO tag to be managed. Depending upon the task management
344 * function the value returned from this method may be ignored.
345 * @scic_user_task_request: This parameter points to the user's task request
346 * object. It is a cookie that allows the user to provide the necessary
347 * information for this callback.
348 *
349 * This method returns an unsigned 16-bit word depicting the IO tag to be
350 * managed.
351 */
352u16 scic_cb_ssp_task_request_get_io_tag_to_manage(
353 void *scic_user_task_request)
354{
355 return isci_task_ssp_request_get_io_tag_to_manage(
356 (struct isci_request *)scic_user_task_request
357 );
358}
359
360/**
361 * scic_cb_ssp_task_request_get_response_data_address() - This callback method
362 * asks the user to provide the virtual address of the response data buffer
363 * for the supplied IO request.
364 * @scic_user_task_request: This parameter points to the user's task request
365 * object. It is a cookie that allows the user to provide the necessary
366 * information for this callback.
367 *
368 * This method returns the virtual address for the response data buffer
369 * associated with this IO request.
370 */
371void *scic_cb_ssp_task_request_get_response_data_address(
372 void *scic_user_task_request)
373{
374 return isci_task_ssp_request_get_response_data_address(
375 (struct isci_request *)scic_user_task_request
376 );
377}
378
379/**
380 * scic_cb_ssp_task_request_get_response_data_length() - This callback method
381 * asks the user to provide the length of the response data buffer for the
382 * supplied IO request.
383 * @scic_user_task_request: This parameter points to the user's task request
384 * object. It is a cookie that allows the user to provide the necessary
385 * information for this callback.
386 *
387 * This method returns the length of the response buffer data associated with
388 * this IO request.
389 */
390u32 scic_cb_ssp_task_request_get_response_data_length(
391 void *scic_user_task_request)
392{
393 return isci_task_ssp_request_get_response_data_length(
394 (struct isci_request *)scic_user_task_request
395 );
396}
397
398#if !defined(DISABLE_ATAPI)
399/**
400 * scic_cb_stp_packet_io_request_get_cdb_address() - This user callback asks
401 * the user to provide stp packet io's the CDB address.
402 * @scic_user_io_request:
403 *
404 * The packet IO's cdb adress.
405 */
406void *scic_cb_stp_packet_io_request_get_cdb_address(
407 void *scic_user_io_request)
408{
409 return isci_request_stp_packet_io_request_get_cdb_address(
410 scic_user_io_request
411 );
412}
413
414
415/**
416 * scic_cb_stp_packet_io_request_get_cdb_length() - This user callback asks the
417 * user to provide stp packet io's the CDB length.
418 * @scic_user_io_request:
419 *
420 * The packet IO's cdb length.
421 */
422u32 scic_cb_stp_packet_io_request_get_cdb_length(
423 void *scic_user_io_request)
424{
425 return isci_request_stp_packet_io_request_get_cdb_length(
426 scic_user_io_request
427 );
428}
429#endif /* #if !defined(DISABLE_ATAPI) */
430
431
432/**
433 * scic_cb_io_request_do_copy_rx_frames() - This callback method asks the user
434 * if the received RX frame data is to be copied to the SGL or should be
435 * stored by the SCI core to be retrieved later with the
436 * scic_io_request_get_rx_frame().
437 * @scic_user_io_request: This parameter points to the user's IO request
438 * object. It is a cookie that allows the user to provide the necessary
439 * information for this callback.
440 *
441 * This method returns true if the SCI core should copy the received frame data
442 * to the SGL location or false if the SCI user wants to retrieve the frame
443 * data at a later time.
444 */
445bool scic_cb_io_request_do_copy_rx_frames(
446 void *scic_user_io_request)
447{
448 struct sas_task *task
449 = isci_request_access_task(
450 (struct isci_request *)scic_user_io_request
451 );
452
453 return (task->data_dir == DMA_NONE) ? false : true;
454}
455
456/**
457 * scic_cb_get_virtual_address() - This callback method asks the user to
458 * provide the virtual address for the supplied physical address.
459 * @controller: This parameter is the core controller object handle.
460 * @physical_address: This parameter is the physical address which is to be
461 * returned as a virtual address.
462 *
463 * The method returns the virtual address for the supplied physical address.
464 */
465void *scic_cb_get_virtual_address(
466 struct scic_sds_controller *controller,
467 dma_addr_t physical_address)
468{
469 void *virt_addr = (void *)phys_to_virt(physical_address);
470
471 return virt_addr;
472}
473
474/**
475 * scic_cb_request_get_sat_protocol() - This callback method asks the user to
476 * return the SAT protocol definition for this IO request. This method is
477 * only called by the SCI core if the request type constructed is SATA.
478 * @scic_user_io_request: This parameter points to the user's IO request
479 * object. It is a cookie that allows the user to provide the necessary
480 * information for this callback.
481 *
482 * This method returns one of the sat.h defined protocols for the given io
483 * request.
484 */
485u8 scic_cb_request_get_sat_protocol(
486 void *scic_user_io_request)
487{
488 return isci_sata_get_sat_protocol(
489 (struct isci_request *)scic_user_io_request
490 );
491}