aboutsummaryrefslogtreecommitdiff
path: root/sys/dev/isci/scil/scif_sas_sati_binding.h
blob: 329efd7794f952e1a4cc2d36b62d8d6655a44098 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
/*-
 * This file is provided under a dual BSD/GPLv2 license.  When using or
 * redistributing this file, you may do so under either license.
 *
 * GPL LICENSE SUMMARY
 *
 * Copyright(c) 2008 - 2011 Intel Corporation. All rights reserved.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of version 2 of the GNU General Public License as
 * published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
 * The full GNU General Public License is included in this distribution
 * in the file called LICENSE.GPL.
 *
 * BSD LICENSE
 *
 * Copyright(c) 2008 - 2011 Intel Corporation. All rights reserved.
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 *
 *   * Redistributions of source code must retain the above copyright
 *     notice, this list of conditions and the following disclaimer.
 *   * Redistributions in binary form must reproduce the above copyright
 *     notice, this list of conditions and the following disclaimer in
 *     the documentation and/or other materials provided with the
 *     distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 * $FreeBSD$
 */
#ifndef _SCIF_SAS_SATI_BINDING_H_
#define _SCIF_SAS_SATI_BINDING_H_

/**
 * @file
 *
 * @brief This file contains the SATI (SCSI to ATA Translation Implementation)
 *        callback implementations that can be implemented by the SCI
 *        Framework (or core in some cases).
 */

#ifdef __cplusplus
extern "C" {
#endif // __cplusplus

#include <dev/isci/scil/scif_user_callback.h>
#include <dev/isci/scil/scif_io_request.h>
#include <dev/isci/scil/scif_remote_device.h>
#include <dev/isci/scil/scic_user_callback.h>
#include <dev/isci/scil/scic_io_request.h>
#include <dev/isci/scil/scic_remote_device.h>
//#include <dev/isci/scil/scic_sds_request.h>
//#include <dev/isci/scil/scu_task_context.h>
#include <dev/isci/scil/sci_object.h>
#include <dev/isci/scil/scif_sas_request.h>
#include <dev/isci/scil/sci_base_memory_descriptor_list.h>
#include <dev/isci/scil/scif_sas_stp_remote_device.h>
#include <dev/isci/scil/scif_sas_remote_device.h>
#include <dev/isci/scil/scif_sas_domain.h>
#include <dev/isci/scil/scif_sas_controller.h>
#include <dev/isci/scil/scic_sds_request.h>
#include <dev/isci/sci_environment.h>

// SATI callbacks fulfilled by the framework user.

#define sati_cb_get_data_byte(scsi_io, byte_offset, value)                    \
{                                                                             \
   U8 * virtual_address = scif_cb_io_request_get_virtual_address_from_sgl(    \
                             sci_object_get_association(scsi_io),(byte_offset)\
                          );                                                  \
   *(value) = *(virtual_address);                                             \
}

#define sati_cb_set_data_byte(scsi_io, byte_offset, value)                    \
{                                                                             \
   U8 * virtual_address = scif_cb_io_request_get_virtual_address_from_sgl(    \
                             sci_object_get_association(scsi_io),(byte_offset)\
                          );                                                  \
   *(virtual_address) = value;                                                \
}

#define sati_cb_get_cdb_address(scsi_io) \
   scif_cb_io_request_get_cdb_address(sci_object_get_association(scsi_io))

#define sati_cb_get_cdb_length(scsi_io)  \
   scif_cb_io_request_get_cdb_length(sci_object_get_association(scsi_io))

#define sati_cb_get_data_direction(scsi_io, sati_data_direction)              \
{                                                                             \
   SCI_IO_REQUEST_DATA_DIRECTION sci_data_direction =                         \
      scif_cb_io_request_get_data_direction(                                  \
         sci_object_get_association(scsi_io)                                  \
      );                                                                      \
   if (sci_data_direction == SCI_IO_REQUEST_DATA_IN)                          \
      *(sati_data_direction) = SATI_DATA_DIRECTION_IN;                        \
   else if (sci_data_direction == SCI_IO_REQUEST_DATA_OUT)                    \
      *(sati_data_direction) = SATI_DATA_DIRECTION_OUT;                       \
   else if (sci_data_direction == SCI_IO_REQUEST_NO_DATA)                     \
      *(sati_data_direction) = SATI_DATA_DIRECTION_NONE;                      \
}

#define sati_cb_get_lun(scsi_io) \
   scif_cb_io_request_get_lun(sci_object_get_association(scsi_io))

// SATI callbacks fulfilled by the framework.

/**
 * This method implements the functionality necessary to fulfill the
 * SCSI-to-ATA Translation requirements.  It ensures that the SAS
 * address for the remote device associated with the supplied IO
 * is written into the sas_address parameter.
 * For more information on the parameters utilized in this method,
 * please refer to sati_cb_device_get_sas_address().
 */
#define sati_cb_device_get_sas_address(scsi_io, sas_address)               \
{                                                                          \
   SCIF_SAS_REQUEST_T* fw_request = (SCIF_SAS_REQUEST_T*)scsi_io;          \
   SCI_REMOTE_DEVICE_HANDLE_T scic_device                                  \
      = scif_remote_device_get_scic_handle(fw_request->device);            \
   scic_remote_device_get_sas_address(scic_device, sas_address);           \
}

#define sati_cb_device_get_request_by_ncq_tag(scsi_io, ncq_tag, matching_req) \
{                                                                          \
   SCIF_SAS_REQUEST_T* fw_request = (SCIF_SAS_REQUEST_T*)scsi_io;          \
   SCIF_SAS_REMOTE_DEVICE_T* fw_device = fw_request->device;               \
   matching_req = scif_sas_stp_remote_device_get_request_by_ncq_tag(fw_device, ncq_tag);  \
}

#define sati_cb_io_request_complete(scsi_io, completion_status)            \
{                                                                          \
   SCIF_SAS_REQUEST_T* fw_request = (SCIF_SAS_REQUEST_T*)scsi_io;          \
   SCIF_SAS_REMOTE_DEVICE_T* fw_device = fw_request->device;               \
   SCIF_SAS_DOMAIN_T*  fw_domain = fw_device->domain;                      \
   SCIF_SAS_CONTROLLER_T* fw_controller = fw_domain->controller;           \
   scif_cb_io_request_complete(                                            \
      fw_controller, fw_device, fw_request, completion_status              \
   );                                                                      \
}

#define sati_cb_get_response_iu_address scif_io_request_get_response_iu_address
#define sati_cb_get_task_function       scic_cb_ssp_task_request_get_function

#define sati_cb_get_ata_data_address(the_ata_io)          \
   scic_io_request_get_rx_frame(                          \
      scif_io_request_get_scic_handle((the_ata_io)), 0    \
   )

#define sati_cb_get_h2d_register_fis_address(the_ata_io)  \
   (U8*) scic_stp_io_request_get_h2d_reg_address(         \
            scif_io_request_get_scic_handle((the_ata_io)) \
         )

#define sati_cb_get_d2h_register_fis_address(the_ata_io)  \
   (U8*) scic_stp_io_request_get_d2h_reg_address(         \
            scif_io_request_get_scic_handle((the_ata_io)) \
         )

#define sati_cb_allocate_dma_buffer(scsi_io, length, virt_address, phys_address_low, phys_address_high) \
{                                                                 \
   SCIF_SAS_REQUEST_T* fw_request = (SCIF_SAS_REQUEST_T*)scsi_io; \
   SCI_PHYSICAL_MEMORY_DESCRIPTOR_T mde;                          \
   mde.virtual_address = NULL;                                    \
   sci_base_mde_construct(                                        \
      &mde, 4, length, SCI_MDE_ATTRIBUTE_PHYSICALLY_CONTIGUOUS    \
   );                                                             \
   scif_cb_controller_allocate_memory(                            \
      fw_request->device->domain->controller, &mde                \
   );                                                             \
   *(virt_address)       = mde.virtual_address;                      \
   *(phys_address_low)   = sci_cb_physical_address_lower(mde.physical_address); \
   *(phys_address_high)  = sci_cb_physical_address_upper(mde.physical_address); \
}

#define sati_cb_free_dma_buffer(scsi_io, virt_address)         \
{                                                                 \
   SCIF_SAS_REQUEST_T* fw_request = (SCIF_SAS_REQUEST_T*)scsi_io; \
   SCI_PHYSICAL_MEMORY_DESCRIPTOR_T mde;                          \
   mde.virtual_address = virt_address;                         \
   sci_base_mde_construct(                                        \
      &mde, 4, 0, SCI_MDE_ATTRIBUTE_PHYSICALLY_CONTIGUOUS         \
   );                                                             \
   scif_cb_controller_free_memory(                                \
      fw_request->device->domain->controller, &mde                \
   );                                                             \
}

#define sati_cb_sgl_next_sge(scsi_io, ata_io, current_sge, next_sge) \
{ \
   /* For now just 2 SGEs are supported. */ \
   SCIC_SDS_REQUEST_T *scic_request; \
   SCU_SGL_ELEMENT_PAIR_T *sgl_pair; \
   scic_request = scif_io_request_get_scic_handle((scsi_io)); \
   sgl_pair     = scic_sds_request_get_sgl_element_pair(scic_request, 0); \
 \
   if ((current_sge) == NULL) \
   { \
      *(next_sge) = &(sgl_pair->A); \
   } \
   else \
   { \
      *(next_sge) = &(sgl_pair->B); \
   } \
}

#define sati_cb_sge_write(current_sge, phys_address_low, phys_address_high, byte_length) \
{ \
   SCU_SGL_ELEMENT_T * scu_sge = (SCU_SGL_ELEMENT_T*) (current_sge); \
   scu_sge->address_upper      = (phys_address_high); \
   scu_sge->address_lower      = (phys_address_low); \
   scu_sge->length             = (byte_length); \
   scu_sge->address_modifier   = 0; \
}

#define sati_cb_do_translate_response(request) \
    (request)->stp.sequence.is_translate_response_required

#ifdef __cplusplus
}
#endif // __cplusplus

#endif // _SCIF_SAS_SATI_BINDING_H_