5dbc82af8883bdf8ccfe9aa13409662497eb3dff
[mirror/winof/.git] / ulp / srp / kernel / srp_cmd.h
1 /*\r
2  * Copyright (c) 2005 SilverStorm Technologies.  All rights reserved.\r
3  *\r
4  * This software is available to you under the OpenIB.org BSD license\r
5  * below:\r
6  *\r
7  *     Redistribution and use in source and binary forms, with or\r
8  *     without modification, are permitted provided that the following\r
9  *     conditions are met:\r
10  *\r
11  *      - Redistributions of source code must retain the above\r
12  *        copyright notice, this list of conditions and the following\r
13  *        disclaimer.\r
14  *\r
15  *      - Redistributions in binary form must reproduce the above\r
16  *        copyright notice, this list of conditions and the following\r
17  *        disclaimer in the documentation and/or other materials\r
18  *        provided with the distribution.\r
19  *\r
20  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,\r
21  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\r
22  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND\r
23  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS\r
24  * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN\r
25  * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\r
26  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\r
27  * SOFTWARE.\r
28  *\r
29  * $Id$\r
30  */\r
31 \r
32 \r
33 #ifndef SRP_CMD_H_INCLUDED\r
34 #define SRP_CMD_H_INCLUDED\r
35 \r
36 #include "srp.h"\r
37 #include "srp_iu_buffer.h"\r
38 #include "srp_information_unit.h"\r
39 \r
40 /* set_srp_command_tag */\r
41 /*!\r
42 Sets the tag field of a command information unit\r
43 \r
44 @param p_information_unit - pointer to the IU structure\r
45 @param iu_tag             - tag value of IU\r
46 \r
47 @return - none\r
48 */\r
49 static inline\r
50 void\r
51 set_srp_command_tag(\r
52         IN OUT  srp_cmd_t   *p_information_unit,\r
53         IN      uint64_t    iu_tag )\r
54 {\r
55         set_srp_information_unit_tag( ( srp_information_unit_t* ) p_information_unit, iu_tag );\r
56 }\r
57 \r
58 /* init_srp_command */\r
59 /*!\r
60 Initializes the command IU to zeroes\r
61 and sets the IU type to command\r
62 and sets the tag to the value supplied\r
63 \r
64 @param p_information_unit - pointer to the IU structure\r
65 @param iu_tag             - tag value to be used for the req/rsp pair\r
66 \r
67 @return - none\r
68 */\r
69 static inline\r
70 void\r
71 init_srp_command(\r
72         IN OUT  srp_cmd_t   *p_information_unit,\r
73         IN      uint64_t    iu_tag )\r
74 {\r
75         init_srp_iu_buffer( ( srp_iu_buffer_t* ) p_information_unit, SRP_CMD ) ;\r
76         set_srp_command_tag( p_information_unit, iu_tag );\r
77 }\r
78 \r
79 /* set_srp_command_data_out_buffer_desc_fmt */\r
80 /*!\r
81 sets the data out buffer descriptor format value\r
82 \r
83 @param p_information_unit       - pointer to the IU structure\r
84 @param data_out_buffer_desc_fmt - buffer descriptor format value\r
85 \r
86 @return - none\r
87 */\r
88 static inline\r
89 void\r
90 set_srp_command_data_out_buffer_desc_fmt(\r
91         IN OUT  srp_cmd_t                       *p_information_unit,\r
92         IN      DATA_BUFFER_DESCRIPTOR_FORMAT   data_out_buffer_desc_fmt )\r
93 {\r
94         p_information_unit->data_out_in_buffer_desc_fmt =\r
95                 ( p_information_unit->data_out_in_buffer_desc_fmt & 0x0F ) | ( (uint8_t)data_out_buffer_desc_fmt << 4 );\r
96 }\r
97 \r
98 /* set_srp_command_data_in_buffer_desc_fmt */\r
99 /*!\r
100 sets the data in buffer descriptor format value\r
101 \r
102 @param p_information_unit      - pointer to the IU structure\r
103 @param data_in_buffer_desc_fmt - buffer descriptor format value\r
104 \r
105 @return - none\r
106 */\r
107 static inline\r
108 void\r
109 set_srp_command_data_in_buffer_desc_fmt(\r
110         IN OUT  srp_cmd_t                       *p_information_unit,\r
111         IN      DATA_BUFFER_DESCRIPTOR_FORMAT   data_in_buffer_desc_fmt )\r
112 {\r
113         p_information_unit->data_out_in_buffer_desc_fmt = ( p_information_unit->data_out_in_buffer_desc_fmt & 0xF0 ) | (uint8_t)data_in_buffer_desc_fmt;\r
114 }\r
115 \r
116 /* set_srp_command_data_out_buffer_desc_count */\r
117 /*!\r
118 sets the data out buffer descriptor count value\r
119 \r
120 @param p_information_unit       - pointer to the IU structure\r
121 @param data_out_buffer_desc_count - buffer descriptor count value\r
122 \r
123 @return - none\r
124 */\r
125 static inline\r
126 void\r
127 set_srp_command_data_out_buffer_desc_count(\r
128         IN OUT  srp_cmd_t   *p_information_unit,\r
129         IN      uint8_t     data_out_buffer_desc_count )\r
130 {\r
131         p_information_unit->data_out_buffer_desc_count = data_out_buffer_desc_count;\r
132 }\r
133 \r
134 /* set_srp_command_data_in_buffer_desc_count */\r
135 /*!\r
136 sets the data in buffer descriptor count value\r
137 \r
138 @param p_information_unit        - pointer to the IU structure\r
139 @param data_in_buffer_desc_count - buffer descriptor count value\r
140 \r
141 @return - none\r
142 */\r
143 static inline\r
144 void\r
145 set_srp_command_data_in_buffer_desc_count(\r
146         IN OUT  srp_cmd_t   *p_information_unit,\r
147         IN      uint8_t     data_in_buffer_desc_count )\r
148 {\r
149         p_information_unit->data_in_buffer_desc_count = data_in_buffer_desc_count;\r
150 }\r
151 \r
152 /* set_srp_command_logical_unit_number */\r
153 /*!\r
154 Sets the logical unit number for the command IU\r
155 \r
156 @param p_information_unit  - pointer to the IU structure\r
157 @param logical_unit_number - logical unit number for request\r
158 \r
159 @return - none\r
160 */\r
161 static inline\r
162 void\r
163 set_srp_command_logical_unit_number(\r
164         IN OUT  srp_cmd_t   *p_information_unit,\r
165         IN      uint64_t    logical_unit_number )\r
166 {\r
167         p_information_unit->logical_unit_number = logical_unit_number;\r
168 }\r
169 \r
170 /* set_srp_command_task_attribute */\r
171 /*!\r
172 Sets the task attribute for the command IU\r
173 \r
174 @param p_information_unit - pointer to the IU structure\r
175 @param task_attribute     - task attribute for the request\r
176 \r
177 @return - none\r
178 */\r
179 static inline\r
180 void\r
181 set_srp_command_task_attribute(\r
182         IN OUT  srp_cmd_t               *p_information_unit,\r
183         IN      TASK_ATTRIBUTE_VALUE    task_attribute )\r
184 {\r
185         p_information_unit->flags1 = ( p_information_unit->flags1 & 0xF8 ) | ( (uint8_t)task_attribute );\r
186 }\r
187 \r
188 /* set_srp_command_additional_cdb_length */\r
189 /*!\r
190 Sets the additional CDB length for the command IU\r
191 \r
192 @param p_information_unit    - pointer to the IU structure\r
193 @param additional_cdb_length - additional CDB length for the request\r
194 \r
195 @return - none\r
196 */\r
197 static inline\r
198 void\r
199 set_srp_command_additional_cdb_length(\r
200         IN OUT  srp_cmd_t   *p_information_unit,\r
201         IN      uint8_t     additional_cdb_length )\r
202 {\r
203         p_information_unit->flags2 = ( p_information_unit->flags2 & 0x03 ) | ( additional_cdb_length << 2 );\r
204 }\r
205 \r
206 /* setup_srp_command */\r
207 /*!\r
208 Initializes and sets the Srp command IU to the values supplied\r
209 \r
210 @param p_information_unit         - pointer to the IU structure\r
211 @param iu_tag                     - tag value to be used for the req/rsp pair\r
212 @param data_out_buffer_desc_fmt   - buffer descriptor format value\r
213 @param data_in_buffer_desc_fmt    - buffer descriptor format value\r
214 @param data_out_buffer_desc_count - buffer descriptor count value\r
215 @param data_in_buffer_desc_count  - buffer descriptor count value\r
216 @param logical_unit_number        - logical unit number for request\r
217 @param task_attribute             - task attribute for the request\r
218 @param additional_cdb_length      - additional CDB length for the request\r
219 \r
220 @return - pointer to the CDB\r
221 */\r
222 static inline\r
223 uint8_t*\r
224 setup_srp_command(\r
225         IN OUT  srp_cmd_t                   *p_information_unit,\r
226         IN  uint64_t                        iu_tag,\r
227         IN  DATA_BUFFER_DESCRIPTOR_FORMAT   data_out_buffer_desc_fmt,\r
228         IN  DATA_BUFFER_DESCRIPTOR_FORMAT   data_in_buffer_desc_fmt,\r
229         IN  uint8_t                         data_out_buffer_desc_count,\r
230         IN  uint8_t                         data_in_buffer_desc_count,\r
231         IN  uint64_t                        logical_unit_number,\r
232         IN  TASK_ATTRIBUTE_VALUE            task_attribute,\r
233         IN  uint8_t                         additional_cdb_length )\r
234 {\r
235         init_srp_command( p_information_unit, iu_tag );\r
236         set_srp_command_data_out_buffer_desc_fmt( p_information_unit, data_out_buffer_desc_fmt );\r
237         set_srp_command_data_in_buffer_desc_fmt( p_information_unit, data_in_buffer_desc_fmt );\r
238         set_srp_command_data_out_buffer_desc_count( p_information_unit, data_out_buffer_desc_count );\r
239         set_srp_command_data_in_buffer_desc_count( p_information_unit, data_in_buffer_desc_count );\r
240         set_srp_command_logical_unit_number( p_information_unit, logical_unit_number );\r
241         set_srp_command_task_attribute( p_information_unit, task_attribute );\r
242         set_srp_command_additional_cdb_length( p_information_unit, additional_cdb_length );\r
243         return( p_information_unit->cdb );\r
244 }\r
245 \r
246 /* get_srp_command_tag */\r
247 /*!\r
248 Returns the value of the tag field of a AsyncEvent request\r
249 \r
250 @param p_information_unit - pointer to the IU structure\r
251 \r
252 @return - tag value\r
253 */\r
254 static inline\r
255 uint64_t\r
256 get_srp_command_tag(\r
257         IN  srp_cmd_t   *p_information_unit )\r
258 {\r
259         return( get_srp_information_unit_tag( ( srp_information_unit_t* ) p_information_unit ) );\r
260 }\r
261 \r
262 /* get_srp_command_data_out_buffer_desc_fmt */\r
263 /*!\r
264 Returns the value of the data out buffer descriptor format field of a command\r
265 \r
266 @param p_information_unit - pointer to the IU structure\r
267 \r
268 @return - data out buffer descriptor format value\r
269 */\r
270 static inline\r
271 DATA_BUFFER_DESCRIPTOR_FORMAT\r
272 get_srp_command_data_out_buffer_desc_fmt(\r
273         IN  srp_cmd_t   *p_information_unit )\r
274 {\r
275         return( ( DATA_BUFFER_DESCRIPTOR_FORMAT ) ( p_information_unit->data_out_in_buffer_desc_fmt >> 4 ) );\r
276 }\r
277 \r
278 /* get_srp_command_data_in_buffer_desc_fmt */\r
279 /*!\r
280 Returns the value of the data in buffer descriptor format field of a command\r
281 \r
282 @param p_information_unit - pointer to the IU structure\r
283 \r
284 @return - data in buffer descriptor format value\r
285 */\r
286 static inline\r
287 DATA_BUFFER_DESCRIPTOR_FORMAT\r
288 get_srp_command_data_in_buffer_desc_fmt(\r
289         IN  srp_cmd_t   *p_information_unit )\r
290 {\r
291         return( ( DATA_BUFFER_DESCRIPTOR_FORMAT ) ( p_information_unit->data_out_in_buffer_desc_fmt & 0x0F ) );\r
292 }\r
293 \r
294 /* get_srp_command_data_out_buffer_desc_count */\r
295 /*!\r
296 Returns the value of the data out buffer descriptor count field of a command\r
297 \r
298 @param p_information_unit - pointer to the IU structure\r
299 \r
300 @return - data out buffer descriptor count value\r
301 */\r
302 static inline\r
303 uint8_t\r
304 get_srp_command_data_out_buffer_desc_count(\r
305         IN  srp_cmd_t   *p_information_unit )\r
306 {\r
307         return( p_information_unit->data_out_buffer_desc_count );\r
308 }\r
309 \r
310 /* get_srp_command_data_in_buffer_desc_count */\r
311 /*!\r
312 Returns the value of the data in buffer descriptor count field of a command\r
313 \r
314 @param p_information_unit - pointer to the IU structure\r
315 \r
316 @return - data in buffer descriptor count value\r
317 */\r
318 static inline\r
319 uint8_t\r
320 get_srp_command_data_in_buffer_desc_count(\r
321         IN  srp_cmd_t   *p_information_unit )\r
322 {\r
323         return( p_information_unit->data_in_buffer_desc_count );\r
324 }\r
325 \r
326 /* get_srp_command_logical_unit_number */\r
327 /*!\r
328 Returns the value of the logical unit number field of a command IU\r
329 \r
330 @param p_information_unit - pointer to the IU structure\r
331 \r
332 @return - logical unit number value\r
333 */\r
334 static inline\r
335 uint64_t\r
336 get_srp_command_logical_unit_number(\r
337         IN  srp_cmd_t   *p_information_unit )\r
338 {\r
339         return( p_information_unit->logical_unit_number );\r
340 }\r
341 \r
342 /* get_srp_command_task_attribute */\r
343 /*!\r
344 Returns the value of the task attribute field of a command\r
345 \r
346 @param p_information_unit - pointer to the IU structure\r
347 \r
348 @return - task attribute value\r
349 */\r
350 static inline\r
351 TASK_ATTRIBUTE_VALUE\r
352 get_srp_command_task_attribute(\r
353         IN  srp_cmd_t   *p_information_unit )\r
354 {\r
355         return( ( TASK_ATTRIBUTE_VALUE ) ( p_information_unit->flags1 & 0x07 ) );\r
356 }\r
357 \r
358 /* get_srp_command_additional_cdb_length */\r
359 /*!\r
360 Returns the value of the additional CDB length field of a command\r
361 \r
362 @param p_information_unit - pointer to the IU structure\r
363 \r
364 @return - additional CDB length value\r
365 */\r
366 static inline\r
367 uint8_t\r
368 get_srp_command_additional_cdb_length(\r
369         IN  srp_cmd_t   *p_information_unit )\r
370 {\r
371         return( ( uint8_t ) ( p_information_unit->flags2 & 0xFC ) >> 2 );\r
372 }\r
373 \r
374 /* get_srp_command_cdb */\r
375 /*!\r
376 Returns a pointer to the CDB field of a command\r
377 \r
378 @param p_information_unit - pointer to the IU structure\r
379 \r
380 @return - pointer to the CDB\r
381 */\r
382 static inline\r
383 uint8_t*\r
384 get_srp_command_cdb(\r
385         IN  srp_cmd_t   *p_information_unit )\r
386 {\r
387         return( p_information_unit->cdb );\r
388 }\r
389 \r
390 /* get_srp_command_additional_cdb */\r
391 /*!\r
392 Returns a pointer to the additional CDB field of a command\r
393 \r
394 @param p_information_unit - pointer to the IU structure\r
395 \r
396 @return - pointer to the additional CDB\r
397 */\r
398 static inline\r
399 uint8_t*\r
400 get_srp_command_additional_cdb(\r
401         IN  srp_cmd_t   *p_information_unit )\r
402 {\r
403         if( get_srp_command_additional_cdb_length( p_information_unit ) == 0 )\r
404         {\r
405                 return( NULL );\r
406         }\r
407 \r
408         return( p_information_unit->additional_cdb );\r
409 }\r
410 \r
411 /* get_srp_command_data_out_buffer_desc */\r
412 /*!\r
413 Returns a pointer to the data out buffer desc field of a command\r
414 \r
415 WARNING!!!! Set the additional CDB length before this call so the\r
416                         offset can be correctly calculated\r
417 \r
418 @param p_information_unit - pointer to the IU structure\r
419 \r
420 @return - pointer to data out buffer desc\r
421 */\r
422 static inline\r
423 srp_memory_descriptor_t*\r
424 get_srp_command_data_out_buffer_desc(\r
425         IN  srp_cmd_t   *p_information_unit )\r
426 {\r
427         if( get_srp_command_data_out_buffer_desc_fmt( p_information_unit ) == DBDF_NO_DATA_BUFFER_DESCRIPTOR_PRESENT )\r
428         {\r
429                 return( NULL );\r
430         }\r
431 \r
432         return( ( srp_memory_descriptor_t* ) ( p_information_unit->additional_cdb + ( get_srp_command_additional_cdb_length( p_information_unit ) * 4 ) ) );\r
433 }\r
434 \r
435 /* get_srp_command_data_in_buffer_desc */\r
436 /*!\r
437 Returns a pointer to the data in buffer desc field of a command\r
438 \r
439 WARNING!!!! Set the additional CDB length and data out buffer descriptor count\r
440                         before this call so the offset can be correctly calculated\r
441 \r
442 @param p_information_unit - pointer to the IU structure\r
443 \r
444 @return - pointer to data in buffer desc\r
445 */\r
446 static inline\r
447 srp_memory_descriptor_t*\r
448 get_srp_command_data_in_buffer_desc(\r
449         IN  srp_cmd_t   *p_information_unit )\r
450 {\r
451         if( get_srp_command_data_in_buffer_desc_fmt( p_information_unit ) == DBDF_NO_DATA_BUFFER_DESCRIPTOR_PRESENT )\r
452         {\r
453                 return( NULL );\r
454         }\r
455 \r
456         return( ( srp_memory_descriptor_t* ) ( p_information_unit->additional_cdb +\r
457                                                                                  ( get_srp_command_additional_cdb_length( p_information_unit ) * 4 ) +\r
458                                                                                  ( get_srp_command_data_out_buffer_desc_count( p_information_unit ) * sizeof( srp_memory_descriptor_t ) ) ) );\r
459 }\r
460 \r
461 /* get_srp_command_buffer_desc */\r
462 /*!\r
463 Returns a pointer to the start of the data buffer descs of a command\r
464 \r
465 WARNING!!!! Set the additional CDB length before this call so the\r
466                         offset can be correctly calculated\r
467 \r
468 @param p_information_unit - pointer to the IU structure\r
469 \r
470 @return - pointer to start of data buffer descs block\r
471 */\r
472 static inline\r
473 srp_memory_descriptor_t*\r
474 get_srp_command_buffer_desc(\r
475         IN  srp_cmd_t   *p_information_unit )\r
476 {\r
477         return( ( srp_memory_descriptor_t* ) ( p_information_unit->additional_cdb + ( get_srp_command_additional_cdb_length( p_information_unit ) * 4 ) ) );\r
478 }\r
479 \r
480 \r
481 /* get_srp_command_Length */\r
482 /*!\r
483 Returns the size in bytes of the Srp command IU\r
484 \r
485 @param p_information_unit - pointer to the IU structure\r
486 \r
487 @return - used length of command IU buffer\r
488 */\r
489 static inline\r
490 uint32_t\r
491 get_srp_command_length(\r
492         IN  srp_cmd_t *p_information_unit )\r
493 {\r
494         /* do not include additional cdb field in the sizeof the IU. add it's length and data out/in buffer desc counts to the structure size */\r
495         return( ( sizeof( *p_information_unit ) - sizeof( p_information_unit->additional_cdb ) ) +\r
496                         ( get_srp_command_additional_cdb_length( p_information_unit ) * 4 ) +\r
497                         ( get_srp_command_data_out_buffer_desc_count( p_information_unit ) * sizeof( srp_memory_descriptor_t ) ) +\r
498                         ( get_srp_command_data_in_buffer_desc_count( p_information_unit )  * sizeof( srp_memory_descriptor_t ) ) );\r
499 }\r
500 \r
501 /* set_srp_command_from_host_to_network */\r
502 /*!\r
503 Swaps the IU fields from Host to Network ordering\r
504 \r
505 @param p_information_unit - pointer to the IU structure\r
506 \r
507 @return - none\r
508 */\r
509 \r
510 static inline\r
511 void\r
512 set_srp_command_from_host_to_network(\r
513         IN OUT  srp_cmd_t   *p_information_unit )\r
514 {\r
515         srp_memory_descriptor_t *p_memory_descriptor;\r
516         int                     buffer_desc_count = get_srp_command_data_in_buffer_desc_count( p_information_unit ) +\r
517                                                                                                 get_srp_command_data_out_buffer_desc_count( p_information_unit );\r
518         int                     i;\r
519 \r
520         set_srp_information_unit_from_host_to_network( ( srp_information_unit_t* ) p_information_unit );\r
521         p_information_unit->logical_unit_number = cl_hton64( p_information_unit->logical_unit_number );\r
522 \r
523         p_memory_descriptor = get_srp_command_buffer_desc( p_information_unit );\r
524 \r
525         for( i = 0; i < buffer_desc_count; i++, p_memory_descriptor++ )\r
526         {\r
527                 p_memory_descriptor->virtual_address = cl_hton64( p_memory_descriptor->virtual_address );\r
528                 p_memory_descriptor->data_length = cl_hton32( p_memory_descriptor->data_length );\r
529         }\r
530 }\r
531 \r
532 /* set_srp_command_from_network_to_host */\r
533 /*!\r
534 Swaps the IU fields from Network to Host ordering\r
535 \r
536 @param p_information_unit - pointer to the IU structure\r
537 \r
538 @return - none\r
539 */\r
540 \r
541 static inline\r
542 void\r
543 set_srp_command_from_network_to_host(\r
544         IN OUT  srp_cmd_t   *p_information_unit )\r
545 {\r
546         set_srp_command_from_host_to_network ( p_information_unit );\r
547 }\r
548 \r
549 #endif /* SRP_CMD_H_INCLUDED */\r