blob: 3fd021a57e5904e801577f51153fa6a10292d139 [file] [log] [blame]
Boaz Harrosh02941a52009-01-25 16:55:30 +02001/*
2 * osd_initiator - Main body of the osd initiator library.
3 *
4 * Note: The file does not contain the advanced security functionality which
5 * is only needed by the security_manager's initiators.
6 *
7 * Copyright (C) 2008 Panasas Inc. All rights reserved.
8 *
9 * Authors:
10 * Boaz Harrosh <bharrosh@panasas.com>
11 * Benny Halevy <bhalevy@panasas.com>
12 *
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License version 2
15 *
16 * Redistribution and use in source and binary forms, with or without
17 * modification, are permitted provided that the following conditions
18 * are met:
19 *
20 * 1. Redistributions of source code must retain the above copyright
21 * notice, this list of conditions and the following disclaimer.
22 * 2. Redistributions in binary form must reproduce the above copyright
23 * notice, this list of conditions and the following disclaimer in the
24 * documentation and/or other materials provided with the distribution.
25 * 3. Neither the name of the Panasas company nor the names of its
26 * contributors may be used to endorse or promote products derived
27 * from this software without specific prior written permission.
28 *
29 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
30 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
31 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
32 * DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
33 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
34 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
35 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
36 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
37 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
38 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
39 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
40 */
41
42#include <scsi/osd_initiator.h>
43#include <scsi/osd_sec.h>
44#include <scsi/scsi_device.h>
45
46#include "osd_debug.h"
47
Boaz Harrosh4ef1a3d2009-01-25 16:59:50 +020048#ifndef __unused
49# define __unused __attribute__((unused))
50#endif
51
Boaz Harrosh02941a52009-01-25 16:55:30 +020052enum { OSD_REQ_RETRIES = 1 };
53
54MODULE_AUTHOR("Boaz Harrosh <bharrosh@panasas.com>");
55MODULE_DESCRIPTION("open-osd initiator library libosd.ko");
56MODULE_LICENSE("GPL");
57
58static inline void build_test(void)
59{
60 /* structures were not packed */
61 BUILD_BUG_ON(sizeof(struct osd_capability) != OSD_CAP_LEN);
62 BUILD_BUG_ON(sizeof(struct osdv1_cdb) != OSDv1_TOTAL_CDB_LEN);
63}
64
65static unsigned _osd_req_cdb_len(struct osd_request *or)
66{
67 return OSDv1_TOTAL_CDB_LEN;
68}
69
Boaz Harrosh4ef1a3d2009-01-25 16:59:50 +020070static unsigned _osd_req_alist_elem_size(struct osd_request *or, unsigned len)
71{
72 return osdv1_attr_list_elem_size(len);
73}
74
75static unsigned _osd_req_alist_size(struct osd_request *or, void *list_head)
76{
77 return osdv1_list_size(list_head);
78}
79
80static unsigned _osd_req_sizeof_alist_header(struct osd_request *or)
81{
82 return sizeof(struct osdv1_attributes_list_header);
83}
84
85static void _osd_req_set_alist_type(struct osd_request *or,
86 void *list, int list_type)
87{
88 struct osdv1_attributes_list_header *attr_list = list;
89
90 memset(attr_list, 0, sizeof(*attr_list));
91 attr_list->type = list_type;
92}
93
94static bool _osd_req_is_alist_type(struct osd_request *or,
95 void *list, int list_type)
96{
97 if (!list)
98 return false;
99
100 if (1) {
101 struct osdv1_attributes_list_header *attr_list = list;
102
103 return attr_list->type == list_type;
104 }
105}
106
Boaz Harrosh3e086132009-01-25 17:05:07 +0200107/* This is for List-objects not Attributes-Lists */
108static void _osd_req_encode_olist(struct osd_request *or,
109 struct osd_obj_id_list *list)
110{
111 struct osd_cdb_head *cdbh = osd_cdb_head(&or->cdb);
112
113 cdbh->v1.list_identifier = list->list_identifier;
114 cdbh->v1.start_address = list->continuation_id;
115}
116
Boaz Harrosh4ef1a3d2009-01-25 16:59:50 +0200117static osd_cdb_offset osd_req_encode_offset(struct osd_request *or,
118 u64 offset, unsigned *padding)
119{
120 return __osd_encode_offset(offset, padding,
121 OSDv1_OFFSET_MIN_SHIFT, OSD_OFFSET_MAX_SHIFT);
122}
123
Boaz Harrosh345c4352009-01-25 17:03:07 +0200124static struct osd_security_parameters *
125_osd_req_sec_params(struct osd_request *or)
126{
127 struct osd_cdb *ocdb = &or->cdb;
128
129 return &ocdb->v1.sec_params;
130}
131
Boaz Harrosh02941a52009-01-25 16:55:30 +0200132void osd_dev_init(struct osd_dev *osdd, struct scsi_device *scsi_device)
133{
134 memset(osdd, 0, sizeof(*osdd));
135 osdd->scsi_device = scsi_device;
136 osdd->def_timeout = BLK_DEFAULT_SG_TIMEOUT;
137 /* TODO: Allocate pools for osd_request attributes ... */
138}
139EXPORT_SYMBOL(osd_dev_init);
140
141void osd_dev_fini(struct osd_dev *osdd)
142{
143 /* TODO: De-allocate pools */
144
145 osdd->scsi_device = NULL;
146}
147EXPORT_SYMBOL(osd_dev_fini);
148
149static struct osd_request *_osd_request_alloc(gfp_t gfp)
150{
151 struct osd_request *or;
152
153 /* TODO: Use mempool with one saved request */
154 or = kzalloc(sizeof(*or), gfp);
155 return or;
156}
157
158static void _osd_request_free(struct osd_request *or)
159{
160 kfree(or);
161}
162
163struct osd_request *osd_start_request(struct osd_dev *dev, gfp_t gfp)
164{
165 struct osd_request *or;
166
167 or = _osd_request_alloc(gfp);
168 if (!or)
169 return NULL;
170
171 or->osd_dev = dev;
172 or->alloc_flags = gfp;
173 or->timeout = dev->def_timeout;
174 or->retries = OSD_REQ_RETRIES;
175
176 return or;
177}
178EXPORT_SYMBOL(osd_start_request);
179
180/*
181 * If osd_finalize_request() was called but the request was not executed through
182 * the block layer, then we must release BIOs.
183 */
184static void _abort_unexecuted_bios(struct request *rq)
185{
186 struct bio *bio;
187
188 while ((bio = rq->bio) != NULL) {
189 rq->bio = bio->bi_next;
190 bio_endio(bio, 0);
191 }
192}
193
Boaz Harrosh4ef1a3d2009-01-25 16:59:50 +0200194static void _osd_free_seg(struct osd_request *or __unused,
195 struct _osd_req_data_segment *seg)
196{
197 if (!seg->buff || !seg->alloc_size)
198 return;
199
200 kfree(seg->buff);
201 seg->buff = NULL;
202 seg->alloc_size = 0;
203}
204
Boaz Harrosh02941a52009-01-25 16:55:30 +0200205void osd_end_request(struct osd_request *or)
206{
207 struct request *rq = or->request;
208
Boaz Harrosh4ef1a3d2009-01-25 16:59:50 +0200209 _osd_free_seg(or, &or->set_attr);
210 _osd_free_seg(or, &or->enc_get_attr);
211 _osd_free_seg(or, &or->get_attr);
212
Boaz Harrosh02941a52009-01-25 16:55:30 +0200213 if (rq) {
214 if (rq->next_rq) {
215 _abort_unexecuted_bios(rq->next_rq);
216 blk_put_request(rq->next_rq);
217 }
218
219 _abort_unexecuted_bios(rq);
220 blk_put_request(rq);
221 }
222 _osd_request_free(or);
223}
224EXPORT_SYMBOL(osd_end_request);
225
226int osd_execute_request(struct osd_request *or)
227{
228 return blk_execute_rq(or->request->q, NULL, or->request, 0);
229}
230EXPORT_SYMBOL(osd_execute_request);
231
232static void osd_request_async_done(struct request *req, int error)
233{
234 struct osd_request *or = req->end_io_data;
235
236 or->async_error = error;
237
238 if (error)
239 OSD_DEBUG("osd_request_async_done error recieved %d\n", error);
240
241 if (or->async_done)
242 or->async_done(or, or->async_private);
243 else
244 osd_end_request(or);
245}
246
247int osd_execute_request_async(struct osd_request *or,
248 osd_req_done_fn *done, void *private)
249{
250 or->request->end_io_data = or;
251 or->async_private = private;
252 or->async_done = done;
253
254 blk_execute_rq_nowait(or->request->q, NULL, or->request, 0,
255 osd_request_async_done);
256 return 0;
257}
258EXPORT_SYMBOL(osd_execute_request_async);
259
Boaz Harrosh4ef1a3d2009-01-25 16:59:50 +0200260u8 sg_out_pad_buffer[1 << OSDv1_OFFSET_MIN_SHIFT];
261u8 sg_in_pad_buffer[1 << OSDv1_OFFSET_MIN_SHIFT];
262
263static int _osd_realloc_seg(struct osd_request *or,
264 struct _osd_req_data_segment *seg, unsigned max_bytes)
265{
266 void *buff;
267
268 if (seg->alloc_size >= max_bytes)
269 return 0;
270
271 buff = krealloc(seg->buff, max_bytes, or->alloc_flags);
272 if (!buff) {
273 OSD_ERR("Failed to Realloc %d-bytes was-%d\n", max_bytes,
274 seg->alloc_size);
275 return -ENOMEM;
276 }
277
278 memset(buff + seg->alloc_size, 0, max_bytes - seg->alloc_size);
279 seg->buff = buff;
280 seg->alloc_size = max_bytes;
281 return 0;
282}
283
284static int _alloc_set_attr_list(struct osd_request *or,
285 const struct osd_attr *oa, unsigned nelem, unsigned add_bytes)
286{
287 unsigned total_bytes = add_bytes;
288
289 for (; nelem; --nelem, ++oa)
290 total_bytes += _osd_req_alist_elem_size(or, oa->len);
291
292 OSD_DEBUG("total_bytes=%d\n", total_bytes);
293 return _osd_realloc_seg(or, &or->set_attr, total_bytes);
294}
295
296static int _alloc_get_attr_desc(struct osd_request *or, unsigned max_bytes)
297{
298 OSD_DEBUG("total_bytes=%d\n", max_bytes);
299 return _osd_realloc_seg(or, &or->enc_get_attr, max_bytes);
300}
301
302static int _alloc_get_attr_list(struct osd_request *or)
303{
304 OSD_DEBUG("total_bytes=%d\n", or->get_attr.total_bytes);
305 return _osd_realloc_seg(or, &or->get_attr, or->get_attr.total_bytes);
306}
307
Boaz Harrosh02941a52009-01-25 16:55:30 +0200308/*
309 * Common to all OSD commands
310 */
311
312static void _osdv1_req_encode_common(struct osd_request *or,
313 __be16 act, const struct osd_obj_id *obj, u64 offset, u64 len)
314{
315 struct osdv1_cdb *ocdb = &or->cdb.v1;
316
317 /*
318 * For speed, the commands
319 * OSD_ACT_PERFORM_SCSI_COMMAND , V1 0x8F7E, V2 0x8F7C
320 * OSD_ACT_SCSI_TASK_MANAGEMENT , V1 0x8F7F, V2 0x8F7D
321 * are not supported here. Should pass zero and set after the call
322 */
323 act &= cpu_to_be16(~0x0080); /* V1 action code */
324
325 OSD_DEBUG("OSDv1 execute opcode 0x%x\n", be16_to_cpu(act));
326
327 ocdb->h.varlen_cdb.opcode = VARIABLE_LENGTH_CMD;
328 ocdb->h.varlen_cdb.additional_cdb_length = OSD_ADDITIONAL_CDB_LENGTH;
329 ocdb->h.varlen_cdb.service_action = act;
330
331 ocdb->h.partition = cpu_to_be64(obj->partition);
332 ocdb->h.object = cpu_to_be64(obj->id);
333 ocdb->h.v1.length = cpu_to_be64(len);
334 ocdb->h.v1.start_address = cpu_to_be64(offset);
335}
336
337static void _osd_req_encode_common(struct osd_request *or,
338 __be16 act, const struct osd_obj_id *obj, u64 offset, u64 len)
339{
340 _osdv1_req_encode_common(or, act, obj, offset, len);
341}
342
343/*
344 * Device commands
345 */
Boaz Harroshae30c992009-01-25 17:07:14 +0200346/*TODO: void osd_req_set_master_seed_xchg(struct osd_request *, ...); */
347/*TODO: void osd_req_set_master_key(struct osd_request *, ...); */
348
Boaz Harrosh02941a52009-01-25 16:55:30 +0200349void osd_req_format(struct osd_request *or, u64 tot_capacity)
350{
351 _osd_req_encode_common(or, OSD_ACT_FORMAT_OSD, &osd_root_object, 0,
352 tot_capacity);
353}
354EXPORT_SYMBOL(osd_req_format);
355
Boaz Harrosh3e086132009-01-25 17:05:07 +0200356int osd_req_list_dev_partitions(struct osd_request *or,
357 osd_id initial_id, struct osd_obj_id_list *list, unsigned nelem)
358{
359 return osd_req_list_partition_objects(or, 0, initial_id, list, nelem);
360}
361EXPORT_SYMBOL(osd_req_list_dev_partitions);
362
363static void _osd_req_encode_flush(struct osd_request *or,
364 enum osd_options_flush_scope_values op)
365{
366 struct osd_cdb_head *ocdb = osd_cdb_head(&or->cdb);
367
368 ocdb->command_specific_options = op;
369}
370
371void osd_req_flush_obsd(struct osd_request *or,
372 enum osd_options_flush_scope_values op)
373{
374 _osd_req_encode_common(or, OSD_ACT_FLUSH_OSD, &osd_root_object, 0, 0);
375 _osd_req_encode_flush(or, op);
376}
377EXPORT_SYMBOL(osd_req_flush_obsd);
378
Boaz Harroshae30c992009-01-25 17:07:14 +0200379/*TODO: void osd_req_perform_scsi_command(struct osd_request *,
380 const u8 *cdb, ...); */
381/*TODO: void osd_req_task_management(struct osd_request *, ...); */
382
Boaz Harrosh02941a52009-01-25 16:55:30 +0200383/*
384 * Partition commands
385 */
386static void _osd_req_encode_partition(struct osd_request *or,
387 __be16 act, osd_id partition)
388{
389 struct osd_obj_id par = {
390 .partition = partition,
391 .id = 0,
392 };
393
394 _osd_req_encode_common(or, act, &par, 0, 0);
395}
396
397void osd_req_create_partition(struct osd_request *or, osd_id partition)
398{
399 _osd_req_encode_partition(or, OSD_ACT_CREATE_PARTITION, partition);
400}
401EXPORT_SYMBOL(osd_req_create_partition);
402
403void osd_req_remove_partition(struct osd_request *or, osd_id partition)
404{
405 _osd_req_encode_partition(or, OSD_ACT_REMOVE_PARTITION, partition);
406}
407EXPORT_SYMBOL(osd_req_remove_partition);
408
Boaz Harroshae30c992009-01-25 17:07:14 +0200409/*TODO: void osd_req_set_partition_key(struct osd_request *,
410 osd_id partition, u8 new_key_id[OSD_CRYPTO_KEYID_SIZE],
411 u8 seed[OSD_CRYPTO_SEED_SIZE]); */
412
Boaz Harrosh3e086132009-01-25 17:05:07 +0200413static int _osd_req_list_objects(struct osd_request *or,
414 __be16 action, const struct osd_obj_id *obj, osd_id initial_id,
415 struct osd_obj_id_list *list, unsigned nelem)
416{
417 struct request_queue *q = or->osd_dev->scsi_device->request_queue;
418 u64 len = nelem * sizeof(osd_id) + sizeof(*list);
419 struct bio *bio;
420
421 _osd_req_encode_common(or, action, obj, (u64)initial_id, len);
422
423 if (list->list_identifier)
424 _osd_req_encode_olist(or, list);
425
426 WARN_ON(or->in.bio);
427 bio = bio_map_kern(q, list, len, or->alloc_flags);
428 if (!bio) {
429 OSD_ERR("!!! Failed to allocate list_objects BIO\n");
430 return -ENOMEM;
431 }
432
433 bio->bi_rw &= ~(1 << BIO_RW);
434 or->in.bio = bio;
435 or->in.total_bytes = bio->bi_size;
436 return 0;
437}
438
439int osd_req_list_partition_collections(struct osd_request *or,
440 osd_id partition, osd_id initial_id, struct osd_obj_id_list *list,
441 unsigned nelem)
442{
443 struct osd_obj_id par = {
444 .partition = partition,
445 .id = 0,
446 };
447
448 return osd_req_list_collection_objects(or, &par, initial_id, list,
449 nelem);
450}
451EXPORT_SYMBOL(osd_req_list_partition_collections);
452
453int osd_req_list_partition_objects(struct osd_request *or,
454 osd_id partition, osd_id initial_id, struct osd_obj_id_list *list,
455 unsigned nelem)
456{
457 struct osd_obj_id par = {
458 .partition = partition,
459 .id = 0,
460 };
461
462 return _osd_req_list_objects(or, OSD_ACT_LIST, &par, initial_id, list,
463 nelem);
464}
465EXPORT_SYMBOL(osd_req_list_partition_objects);
466
467void osd_req_flush_partition(struct osd_request *or,
468 osd_id partition, enum osd_options_flush_scope_values op)
469{
470 _osd_req_encode_partition(or, OSD_ACT_FLUSH_PARTITION, partition);
471 _osd_req_encode_flush(or, op);
472}
473EXPORT_SYMBOL(osd_req_flush_partition);
474
475/*
476 * Collection commands
477 */
Boaz Harroshae30c992009-01-25 17:07:14 +0200478/*TODO: void osd_req_create_collection(struct osd_request *,
479 const struct osd_obj_id *); */
480/*TODO: void osd_req_remove_collection(struct osd_request *,
481 const struct osd_obj_id *); */
482
Boaz Harrosh3e086132009-01-25 17:05:07 +0200483int osd_req_list_collection_objects(struct osd_request *or,
484 const struct osd_obj_id *obj, osd_id initial_id,
485 struct osd_obj_id_list *list, unsigned nelem)
486{
487 return _osd_req_list_objects(or, OSD_ACT_LIST_COLLECTION, obj,
488 initial_id, list, nelem);
489}
490EXPORT_SYMBOL(osd_req_list_collection_objects);
491
Boaz Harroshae30c992009-01-25 17:07:14 +0200492/*TODO: void query(struct osd_request *, ...); V2 */
493
Boaz Harrosh3e086132009-01-25 17:05:07 +0200494void osd_req_flush_collection(struct osd_request *or,
495 const struct osd_obj_id *obj, enum osd_options_flush_scope_values op)
496{
497 _osd_req_encode_common(or, OSD_ACT_FLUSH_PARTITION, obj, 0, 0);
498 _osd_req_encode_flush(or, op);
499}
500EXPORT_SYMBOL(osd_req_flush_collection);
501
Boaz Harroshae30c992009-01-25 17:07:14 +0200502/*TODO: void get_member_attrs(struct osd_request *, ...); V2 */
503/*TODO: void set_member_attrs(struct osd_request *, ...); V2 */
504
Boaz Harrosh02941a52009-01-25 16:55:30 +0200505/*
506 * Object commands
507 */
508void osd_req_create_object(struct osd_request *or, struct osd_obj_id *obj)
509{
510 _osd_req_encode_common(or, OSD_ACT_CREATE, obj, 0, 0);
511}
512EXPORT_SYMBOL(osd_req_create_object);
513
514void osd_req_remove_object(struct osd_request *or, struct osd_obj_id *obj)
515{
516 _osd_req_encode_common(or, OSD_ACT_REMOVE, obj, 0, 0);
517}
518EXPORT_SYMBOL(osd_req_remove_object);
519
Boaz Harroshae30c992009-01-25 17:07:14 +0200520
521/*TODO: void osd_req_create_multi(struct osd_request *or,
522 struct osd_obj_id *first, struct osd_obj_id_list *list, unsigned nelem);
523*/
524
Boaz Harrosh02941a52009-01-25 16:55:30 +0200525void osd_req_write(struct osd_request *or,
526 const struct osd_obj_id *obj, struct bio *bio, u64 offset)
527{
528 _osd_req_encode_common(or, OSD_ACT_WRITE, obj, offset, bio->bi_size);
529 WARN_ON(or->out.bio || or->out.total_bytes);
530 bio->bi_rw |= (1 << BIO_RW);
531 or->out.bio = bio;
532 or->out.total_bytes = bio->bi_size;
533}
534EXPORT_SYMBOL(osd_req_write);
535
Boaz Harroshae30c992009-01-25 17:07:14 +0200536/*TODO: void osd_req_append(struct osd_request *,
537 const struct osd_obj_id *, struct bio *data_out); */
538/*TODO: void osd_req_create_write(struct osd_request *,
539 const struct osd_obj_id *, struct bio *data_out, u64 offset); */
540/*TODO: void osd_req_clear(struct osd_request *,
541 const struct osd_obj_id *, u64 offset, u64 len); */
542/*TODO: void osd_req_punch(struct osd_request *,
543 const struct osd_obj_id *, u64 offset, u64 len); V2 */
544
Boaz Harrosh3e086132009-01-25 17:05:07 +0200545void osd_req_flush_object(struct osd_request *or,
546 const struct osd_obj_id *obj, enum osd_options_flush_scope_values op,
547 /*V2*/ u64 offset, /*V2*/ u64 len)
548{
549 _osd_req_encode_common(or, OSD_ACT_FLUSH, obj, offset, len);
550 _osd_req_encode_flush(or, op);
551}
552EXPORT_SYMBOL(osd_req_flush_object);
553
Boaz Harrosh02941a52009-01-25 16:55:30 +0200554void osd_req_read(struct osd_request *or,
555 const struct osd_obj_id *obj, struct bio *bio, u64 offset)
556{
557 _osd_req_encode_common(or, OSD_ACT_READ, obj, offset, bio->bi_size);
558 WARN_ON(or->in.bio || or->in.total_bytes);
559 bio->bi_rw &= ~(1 << BIO_RW);
560 or->in.bio = bio;
561 or->in.total_bytes = bio->bi_size;
562}
563EXPORT_SYMBOL(osd_req_read);
564
Boaz Harrosh4ef1a3d2009-01-25 16:59:50 +0200565void osd_req_get_attributes(struct osd_request *or,
566 const struct osd_obj_id *obj)
567{
568 _osd_req_encode_common(or, OSD_ACT_GET_ATTRIBUTES, obj, 0, 0);
569}
570EXPORT_SYMBOL(osd_req_get_attributes);
571
572void osd_req_set_attributes(struct osd_request *or,
573 const struct osd_obj_id *obj)
574{
575 _osd_req_encode_common(or, OSD_ACT_SET_ATTRIBUTES, obj, 0, 0);
576}
577EXPORT_SYMBOL(osd_req_set_attributes);
578
579/*
580 * Attributes List-mode
581 */
582
583int osd_req_add_set_attr_list(struct osd_request *or,
584 const struct osd_attr *oa, unsigned nelem)
585{
586 unsigned total_bytes = or->set_attr.total_bytes;
587 void *attr_last;
588 int ret;
589
590 if (or->attributes_mode &&
591 or->attributes_mode != OSD_CDB_GET_SET_ATTR_LISTS) {
592 WARN_ON(1);
593 return -EINVAL;
594 }
595 or->attributes_mode = OSD_CDB_GET_SET_ATTR_LISTS;
596
597 if (!total_bytes) { /* first-time: allocate and put list header */
598 total_bytes = _osd_req_sizeof_alist_header(or);
599 ret = _alloc_set_attr_list(or, oa, nelem, total_bytes);
600 if (ret)
601 return ret;
602 _osd_req_set_alist_type(or, or->set_attr.buff,
603 OSD_ATTR_LIST_SET_RETRIEVE);
604 }
605 attr_last = or->set_attr.buff + total_bytes;
606
607 for (; nelem; --nelem) {
608 struct osd_attributes_list_element *attr;
609 unsigned elem_size = _osd_req_alist_elem_size(or, oa->len);
610
611 total_bytes += elem_size;
612 if (unlikely(or->set_attr.alloc_size < total_bytes)) {
613 or->set_attr.total_bytes = total_bytes - elem_size;
614 ret = _alloc_set_attr_list(or, oa, nelem, total_bytes);
615 if (ret)
616 return ret;
617 attr_last =
618 or->set_attr.buff + or->set_attr.total_bytes;
619 }
620
621 attr = attr_last;
622 attr->attr_page = cpu_to_be32(oa->attr_page);
623 attr->attr_id = cpu_to_be32(oa->attr_id);
624 attr->attr_bytes = cpu_to_be16(oa->len);
625 memcpy(attr->attr_val, oa->val_ptr, oa->len);
626
627 attr_last += elem_size;
628 ++oa;
629 }
630
631 or->set_attr.total_bytes = total_bytes;
632 return 0;
633}
634EXPORT_SYMBOL(osd_req_add_set_attr_list);
635
636static int _append_map_kern(struct request *req,
637 void *buff, unsigned len, gfp_t flags)
638{
639 struct bio *bio;
640 int ret;
641
642 bio = bio_map_kern(req->q, buff, len, flags);
643 if (IS_ERR(bio)) {
644 OSD_ERR("Failed bio_map_kern(%p, %d) => %ld\n", buff, len,
645 PTR_ERR(bio));
646 return PTR_ERR(bio);
647 }
648 ret = blk_rq_append_bio(req->q, req, bio);
649 if (ret) {
650 OSD_ERR("Failed blk_rq_append_bio(%p) => %d\n", bio, ret);
651 bio_put(bio);
652 }
653 return ret;
654}
655
656static int _req_append_segment(struct osd_request *or,
657 unsigned padding, struct _osd_req_data_segment *seg,
658 struct _osd_req_data_segment *last_seg, struct _osd_io_info *io)
659{
660 void *pad_buff;
661 int ret;
662
663 if (padding) {
664 /* check if we can just add it to last buffer */
665 if (last_seg &&
666 (padding <= last_seg->alloc_size - last_seg->total_bytes))
667 pad_buff = last_seg->buff + last_seg->total_bytes;
668 else
669 pad_buff = io->pad_buff;
670
671 ret = _append_map_kern(io->req, pad_buff, padding,
672 or->alloc_flags);
673 if (ret)
674 return ret;
675 io->total_bytes += padding;
676 }
677
678 ret = _append_map_kern(io->req, seg->buff, seg->total_bytes,
679 or->alloc_flags);
680 if (ret)
681 return ret;
682
683 io->total_bytes += seg->total_bytes;
684 OSD_DEBUG("padding=%d buff=%p total_bytes=%d\n", padding, seg->buff,
685 seg->total_bytes);
686 return 0;
687}
688
689static int _osd_req_finalize_set_attr_list(struct osd_request *or)
690{
691 struct osd_cdb_head *cdbh = osd_cdb_head(&or->cdb);
692 unsigned padding;
693 int ret;
694
695 if (!or->set_attr.total_bytes) {
696 cdbh->attrs_list.set_attr_offset = OSD_OFFSET_UNUSED;
697 return 0;
698 }
699
700 cdbh->attrs_list.set_attr_bytes = cpu_to_be32(or->set_attr.total_bytes);
701 cdbh->attrs_list.set_attr_offset =
702 osd_req_encode_offset(or, or->out.total_bytes, &padding);
703
704 ret = _req_append_segment(or, padding, &or->set_attr,
705 or->out.last_seg, &or->out);
706 if (ret)
707 return ret;
708
709 or->out.last_seg = &or->set_attr;
710 return 0;
711}
712
713int osd_req_add_get_attr_list(struct osd_request *or,
714 const struct osd_attr *oa, unsigned nelem)
715{
716 unsigned total_bytes = or->enc_get_attr.total_bytes;
717 void *attr_last;
718 int ret;
719
720 if (or->attributes_mode &&
721 or->attributes_mode != OSD_CDB_GET_SET_ATTR_LISTS) {
722 WARN_ON(1);
723 return -EINVAL;
724 }
725 or->attributes_mode = OSD_CDB_GET_SET_ATTR_LISTS;
726
727 /* first time calc data-in list header size */
728 if (!or->get_attr.total_bytes)
729 or->get_attr.total_bytes = _osd_req_sizeof_alist_header(or);
730
731 /* calc data-out info */
732 if (!total_bytes) { /* first-time: allocate and put list header */
733 unsigned max_bytes;
734
735 total_bytes = _osd_req_sizeof_alist_header(or);
736 max_bytes = total_bytes +
737 nelem * sizeof(struct osd_attributes_list_attrid);
738 ret = _alloc_get_attr_desc(or, max_bytes);
739 if (ret)
740 return ret;
741
742 _osd_req_set_alist_type(or, or->enc_get_attr.buff,
743 OSD_ATTR_LIST_GET);
744 }
745 attr_last = or->enc_get_attr.buff + total_bytes;
746
747 for (; nelem; --nelem) {
748 struct osd_attributes_list_attrid *attrid;
749 const unsigned cur_size = sizeof(*attrid);
750
751 total_bytes += cur_size;
752 if (unlikely(or->enc_get_attr.alloc_size < total_bytes)) {
753 or->enc_get_attr.total_bytes = total_bytes - cur_size;
754 ret = _alloc_get_attr_desc(or,
755 total_bytes + nelem * sizeof(*attrid));
756 if (ret)
757 return ret;
758 attr_last = or->enc_get_attr.buff +
759 or->enc_get_attr.total_bytes;
760 }
761
762 attrid = attr_last;
763 attrid->attr_page = cpu_to_be32(oa->attr_page);
764 attrid->attr_id = cpu_to_be32(oa->attr_id);
765
766 attr_last += cur_size;
767
768 /* calc data-in size */
769 or->get_attr.total_bytes +=
770 _osd_req_alist_elem_size(or, oa->len);
771 ++oa;
772 }
773
774 or->enc_get_attr.total_bytes = total_bytes;
775
776 OSD_DEBUG(
777 "get_attr.total_bytes=%u(%u) enc_get_attr.total_bytes=%u(%Zu)\n",
778 or->get_attr.total_bytes,
779 or->get_attr.total_bytes - _osd_req_sizeof_alist_header(or),
780 or->enc_get_attr.total_bytes,
781 (or->enc_get_attr.total_bytes - _osd_req_sizeof_alist_header(or))
782 / sizeof(struct osd_attributes_list_attrid));
783
784 return 0;
785}
786EXPORT_SYMBOL(osd_req_add_get_attr_list);
787
788static int _osd_req_finalize_get_attr_list(struct osd_request *or)
789{
790 struct osd_cdb_head *cdbh = osd_cdb_head(&or->cdb);
791 unsigned out_padding;
792 unsigned in_padding;
793 int ret;
794
795 if (!or->enc_get_attr.total_bytes) {
796 cdbh->attrs_list.get_attr_desc_offset = OSD_OFFSET_UNUSED;
797 cdbh->attrs_list.get_attr_offset = OSD_OFFSET_UNUSED;
798 return 0;
799 }
800
801 ret = _alloc_get_attr_list(or);
802 if (ret)
803 return ret;
804
805 /* The out-going buffer info update */
806 OSD_DEBUG("out-going\n");
807 cdbh->attrs_list.get_attr_desc_bytes =
808 cpu_to_be32(or->enc_get_attr.total_bytes);
809
810 cdbh->attrs_list.get_attr_desc_offset =
811 osd_req_encode_offset(or, or->out.total_bytes, &out_padding);
812
813 ret = _req_append_segment(or, out_padding, &or->enc_get_attr,
814 or->out.last_seg, &or->out);
815 if (ret)
816 return ret;
817 or->out.last_seg = &or->enc_get_attr;
818
819 /* The incoming buffer info update */
820 OSD_DEBUG("in-coming\n");
821 cdbh->attrs_list.get_attr_alloc_length =
822 cpu_to_be32(or->get_attr.total_bytes);
823
824 cdbh->attrs_list.get_attr_offset =
825 osd_req_encode_offset(or, or->in.total_bytes, &in_padding);
826
827 ret = _req_append_segment(or, in_padding, &or->get_attr, NULL,
828 &or->in);
829 if (ret)
830 return ret;
831 or->in.last_seg = &or->get_attr;
832
833 return 0;
834}
835
836int osd_req_decode_get_attr_list(struct osd_request *or,
837 struct osd_attr *oa, int *nelem, void **iterator)
838{
839 unsigned cur_bytes, returned_bytes;
840 int n;
841 const unsigned sizeof_attr_list = _osd_req_sizeof_alist_header(or);
842 void *cur_p;
843
844 if (!_osd_req_is_alist_type(or, or->get_attr.buff,
845 OSD_ATTR_LIST_SET_RETRIEVE)) {
846 oa->attr_page = 0;
847 oa->attr_id = 0;
848 oa->val_ptr = NULL;
849 oa->len = 0;
850 *iterator = NULL;
851 return 0;
852 }
853
854 if (*iterator) {
855 BUG_ON((*iterator < or->get_attr.buff) ||
856 (or->get_attr.buff + or->get_attr.alloc_size < *iterator));
857 cur_p = *iterator;
858 cur_bytes = (*iterator - or->get_attr.buff) - sizeof_attr_list;
859 returned_bytes = or->get_attr.total_bytes;
860 } else { /* first time decode the list header */
861 cur_bytes = sizeof_attr_list;
862 returned_bytes = _osd_req_alist_size(or, or->get_attr.buff) +
863 sizeof_attr_list;
864
865 cur_p = or->get_attr.buff + sizeof_attr_list;
866
867 if (returned_bytes > or->get_attr.alloc_size) {
868 OSD_DEBUG("target report: space was not big enough! "
869 "Allocate=%u Needed=%u\n",
870 or->get_attr.alloc_size,
871 returned_bytes + sizeof_attr_list);
872
873 returned_bytes =
874 or->get_attr.alloc_size - sizeof_attr_list;
875 }
876 or->get_attr.total_bytes = returned_bytes;
877 }
878
879 for (n = 0; (n < *nelem) && (cur_bytes < returned_bytes); ++n) {
880 struct osd_attributes_list_element *attr = cur_p;
881 unsigned inc;
882
883 oa->len = be16_to_cpu(attr->attr_bytes);
884 inc = _osd_req_alist_elem_size(or, oa->len);
885 OSD_DEBUG("oa->len=%d inc=%d cur_bytes=%d\n",
886 oa->len, inc, cur_bytes);
887 cur_bytes += inc;
888 if (cur_bytes > returned_bytes) {
889 OSD_ERR("BAD FOOD from target. list not valid!"
890 "c=%d r=%d n=%d\n",
891 cur_bytes, returned_bytes, n);
892 oa->val_ptr = NULL;
893 break;
894 }
895
896 oa->attr_page = be32_to_cpu(attr->attr_page);
897 oa->attr_id = be32_to_cpu(attr->attr_id);
898 oa->val_ptr = attr->attr_val;
899
900 cur_p += inc;
901 ++oa;
902 }
903
904 *iterator = (returned_bytes - cur_bytes) ? cur_p : NULL;
905 *nelem = n;
906 return returned_bytes - cur_bytes;
907}
908EXPORT_SYMBOL(osd_req_decode_get_attr_list);
909
910/*
911 * Attributes Page-mode
912 */
913
914int osd_req_add_get_attr_page(struct osd_request *or,
915 u32 page_id, void *attar_page, unsigned max_page_len,
916 const struct osd_attr *set_one_attr)
917{
918 struct osd_cdb_head *cdbh = osd_cdb_head(&or->cdb);
919
920 if (or->attributes_mode &&
921 or->attributes_mode != OSD_CDB_GET_ATTR_PAGE_SET_ONE) {
922 WARN_ON(1);
923 return -EINVAL;
924 }
925 or->attributes_mode = OSD_CDB_GET_ATTR_PAGE_SET_ONE;
926
927 or->get_attr.buff = attar_page;
928 or->get_attr.total_bytes = max_page_len;
929
930 or->set_attr.buff = set_one_attr->val_ptr;
931 or->set_attr.total_bytes = set_one_attr->len;
932
933 cdbh->attrs_page.get_attr_page = cpu_to_be32(page_id);
934 cdbh->attrs_page.get_attr_alloc_length = cpu_to_be32(max_page_len);
935 /* ocdb->attrs_page.get_attr_offset; */
936
937 cdbh->attrs_page.set_attr_page = cpu_to_be32(set_one_attr->attr_page);
938 cdbh->attrs_page.set_attr_id = cpu_to_be32(set_one_attr->attr_id);
939 cdbh->attrs_page.set_attr_length = cpu_to_be32(set_one_attr->len);
940 /* ocdb->attrs_page.set_attr_offset; */
941 return 0;
942}
943EXPORT_SYMBOL(osd_req_add_get_attr_page);
944
945static int _osd_req_finalize_attr_page(struct osd_request *or)
946{
947 struct osd_cdb_head *cdbh = osd_cdb_head(&or->cdb);
948 unsigned in_padding, out_padding;
949 int ret;
950
951 /* returned page */
952 cdbh->attrs_page.get_attr_offset =
953 osd_req_encode_offset(or, or->in.total_bytes, &in_padding);
954
955 ret = _req_append_segment(or, in_padding, &or->get_attr, NULL,
956 &or->in);
957 if (ret)
958 return ret;
959
960 /* set one value */
961 cdbh->attrs_page.set_attr_offset =
962 osd_req_encode_offset(or, or->out.total_bytes, &out_padding);
963
964 ret = _req_append_segment(or, out_padding, &or->enc_get_attr, NULL,
965 &or->out);
966 return ret;
967}
968
Boaz Harrosh345c4352009-01-25 17:03:07 +0200969static int _osd_req_finalize_data_integrity(struct osd_request *or,
970 bool has_in, bool has_out, const u8 *cap_key)
971{
972 struct osd_security_parameters *sec_parms = _osd_req_sec_params(or);
973 int ret;
974
975 if (!osd_is_sec_alldata(sec_parms))
976 return 0;
977
978 if (has_out) {
979 struct _osd_req_data_segment seg = {
980 .buff = &or->out_data_integ,
981 .total_bytes = sizeof(or->out_data_integ),
982 };
983 unsigned pad;
984
985 or->out_data_integ.data_bytes = cpu_to_be64(
986 or->out.bio ? or->out.bio->bi_size : 0);
987 or->out_data_integ.set_attributes_bytes = cpu_to_be64(
988 or->set_attr.total_bytes);
989 or->out_data_integ.get_attributes_bytes = cpu_to_be64(
990 or->enc_get_attr.total_bytes);
991
992 sec_parms->data_out_integrity_check_offset =
993 osd_req_encode_offset(or, or->out.total_bytes, &pad);
994
995 ret = _req_append_segment(or, pad, &seg, or->out.last_seg,
996 &or->out);
997 if (ret)
998 return ret;
999 or->out.last_seg = NULL;
1000
1001 /* they are now all chained to request sign them all together */
1002 osd_sec_sign_data(&or->out_data_integ, or->out.req->bio,
1003 cap_key);
1004 }
1005
1006 if (has_in) {
1007 struct _osd_req_data_segment seg = {
1008 .buff = &or->in_data_integ,
1009 .total_bytes = sizeof(or->in_data_integ),
1010 };
1011 unsigned pad;
1012
1013 sec_parms->data_in_integrity_check_offset =
1014 osd_req_encode_offset(or, or->in.total_bytes, &pad);
1015
1016 ret = _req_append_segment(or, pad, &seg, or->in.last_seg,
1017 &or->in);
1018 if (ret)
1019 return ret;
1020
1021 or->in.last_seg = NULL;
1022 }
1023
1024 return 0;
1025}
1026
Boaz Harrosh02941a52009-01-25 16:55:30 +02001027/*
1028 * osd_finalize_request and helpers
1029 */
1030
1031static int _init_blk_request(struct osd_request *or,
1032 bool has_in, bool has_out)
1033{
1034 gfp_t flags = or->alloc_flags;
1035 struct scsi_device *scsi_device = or->osd_dev->scsi_device;
1036 struct request_queue *q = scsi_device->request_queue;
1037 struct request *req;
1038 int ret = -ENOMEM;
1039
1040 req = blk_get_request(q, has_out, flags);
1041 if (!req)
1042 goto out;
1043
1044 or->request = req;
1045 req->cmd_type = REQ_TYPE_BLOCK_PC;
1046 req->timeout = or->timeout;
1047 req->retries = or->retries;
1048 req->sense = or->sense;
1049 req->sense_len = 0;
1050
1051 if (has_out) {
1052 or->out.req = req;
1053 if (has_in) {
1054 /* allocate bidi request */
1055 req = blk_get_request(q, READ, flags);
1056 if (!req) {
1057 OSD_DEBUG("blk_get_request for bidi failed\n");
1058 goto out;
1059 }
1060 req->cmd_type = REQ_TYPE_BLOCK_PC;
1061 or->in.req = or->request->next_rq = req;
1062 }
1063 } else if (has_in)
1064 or->in.req = req;
1065
1066 ret = 0;
1067out:
1068 OSD_DEBUG("or=%p has_in=%d has_out=%d => %d, %p\n",
1069 or, has_in, has_out, ret, or->request);
1070 return ret;
1071}
1072
1073int osd_finalize_request(struct osd_request *or,
1074 u8 options, const void *cap, const u8 *cap_key)
1075{
1076 struct osd_cdb_head *cdbh = osd_cdb_head(&or->cdb);
1077 bool has_in, has_out;
1078 int ret;
1079
1080 if (options & OSD_REQ_FUA)
1081 cdbh->options |= OSD_CDB_FUA;
1082
1083 if (options & OSD_REQ_DPO)
1084 cdbh->options |= OSD_CDB_DPO;
1085
1086 if (options & OSD_REQ_BYPASS_TIMESTAMPS)
1087 cdbh->timestamp_control = OSD_CDB_BYPASS_TIMESTAMPS;
1088
1089 osd_set_caps(&or->cdb, cap);
1090
1091 has_in = or->in.bio || or->get_attr.total_bytes;
1092 has_out = or->out.bio || or->set_attr.total_bytes ||
1093 or->enc_get_attr.total_bytes;
1094
1095 ret = _init_blk_request(or, has_in, has_out);
1096 if (ret) {
1097 OSD_DEBUG("_init_blk_request failed\n");
1098 return ret;
1099 }
1100
1101 if (or->out.bio) {
1102 ret = blk_rq_append_bio(or->request->q, or->out.req,
1103 or->out.bio);
1104 if (ret) {
1105 OSD_DEBUG("blk_rq_append_bio out failed\n");
1106 return ret;
1107 }
1108 OSD_DEBUG("out bytes=%llu (bytes_req=%u)\n",
1109 _LLU(or->out.total_bytes), or->out.req->data_len);
1110 }
1111 if (or->in.bio) {
1112 ret = blk_rq_append_bio(or->request->q, or->in.req, or->in.bio);
1113 if (ret) {
1114 OSD_DEBUG("blk_rq_append_bio in failed\n");
1115 return ret;
1116 }
1117 OSD_DEBUG("in bytes=%llu (bytes_req=%u)\n",
1118 _LLU(or->in.total_bytes), or->in.req->data_len);
1119 }
1120
Boaz Harrosh4ef1a3d2009-01-25 16:59:50 +02001121 or->out.pad_buff = sg_out_pad_buffer;
1122 or->in.pad_buff = sg_in_pad_buffer;
1123
Boaz Harrosh02941a52009-01-25 16:55:30 +02001124 if (!or->attributes_mode)
1125 or->attributes_mode = OSD_CDB_GET_SET_ATTR_LISTS;
1126 cdbh->command_specific_options |= or->attributes_mode;
Boaz Harrosh4ef1a3d2009-01-25 16:59:50 +02001127 if (or->attributes_mode == OSD_CDB_GET_ATTR_PAGE_SET_ONE) {
1128 ret = _osd_req_finalize_attr_page(or);
1129 } else {
1130 /* TODO: I think that for the GET_ATTR command these 2 should
1131 * be reversed to keep them in execution order (for embeded
1132 * targets with low memory footprint)
1133 */
1134 ret = _osd_req_finalize_set_attr_list(or);
1135 if (ret) {
1136 OSD_DEBUG("_osd_req_finalize_set_attr_list failed\n");
1137 return ret;
1138 }
1139
1140 ret = _osd_req_finalize_get_attr_list(or);
1141 if (ret) {
1142 OSD_DEBUG("_osd_req_finalize_get_attr_list failed\n");
1143 return ret;
1144 }
1145 }
Boaz Harrosh02941a52009-01-25 16:55:30 +02001146
Boaz Harrosh345c4352009-01-25 17:03:07 +02001147 ret = _osd_req_finalize_data_integrity(or, has_in, has_out, cap_key);
1148 if (ret)
1149 return ret;
1150
1151 osd_sec_sign_cdb(&or->cdb, cap_key);
1152
Boaz Harrosh02941a52009-01-25 16:55:30 +02001153 or->request->cmd = or->cdb.buff;
1154 or->request->cmd_len = _osd_req_cdb_len(or);
1155
1156 return 0;
1157}
1158EXPORT_SYMBOL(osd_finalize_request);
1159
1160/*
1161 * Implementation of osd_sec.h API
1162 * TODO: Move to a separate osd_sec.c file at a later stage.
1163 */
1164
1165enum { OSD_SEC_CAP_V1_ALL_CAPS =
1166 OSD_SEC_CAP_APPEND | OSD_SEC_CAP_OBJ_MGMT | OSD_SEC_CAP_REMOVE |
1167 OSD_SEC_CAP_CREATE | OSD_SEC_CAP_SET_ATTR | OSD_SEC_CAP_GET_ATTR |
1168 OSD_SEC_CAP_WRITE | OSD_SEC_CAP_READ | OSD_SEC_CAP_POL_SEC |
1169 OSD_SEC_CAP_GLOBAL | OSD_SEC_CAP_DEV_MGMT
1170};
1171
1172void osd_sec_init_nosec_doall_caps(void *caps,
1173 const struct osd_obj_id *obj, bool is_collection, const bool is_v1)
1174{
1175 struct osd_capability *cap = caps;
1176 u8 type;
1177 u8 descriptor_type;
1178
1179 if (likely(obj->id)) {
1180 if (unlikely(is_collection)) {
1181 type = OSD_SEC_OBJ_COLLECTION;
1182 descriptor_type = is_v1 ? OSD_SEC_OBJ_DESC_OBJ :
1183 OSD_SEC_OBJ_DESC_COL;
1184 } else {
1185 type = OSD_SEC_OBJ_USER;
1186 descriptor_type = OSD_SEC_OBJ_DESC_OBJ;
1187 }
1188 WARN_ON(!obj->partition);
1189 } else {
1190 type = obj->partition ? OSD_SEC_OBJ_PARTITION :
1191 OSD_SEC_OBJ_ROOT;
1192 descriptor_type = OSD_SEC_OBJ_DESC_PAR;
1193 }
1194
1195 memset(cap, 0, sizeof(*cap));
1196
1197 cap->h.format = OSD_SEC_CAP_FORMAT_VER1;
1198 cap->h.integrity_algorithm__key_version = 0; /* MAKE_BYTE(0, 0); */
1199 cap->h.security_method = OSD_SEC_NOSEC;
1200/* cap->expiration_time;
1201 cap->AUDIT[30-10];
1202 cap->discriminator[42-30];
1203 cap->object_created_time; */
1204 cap->h.object_type = type;
1205 osd_sec_set_caps(&cap->h, OSD_SEC_CAP_V1_ALL_CAPS);
1206 cap->h.object_descriptor_type = descriptor_type;
1207 cap->od.obj_desc.policy_access_tag = 0;
1208 cap->od.obj_desc.allowed_partition_id = cpu_to_be64(obj->partition);
1209 cap->od.obj_desc.allowed_object_id = cpu_to_be64(obj->id);
1210}
1211EXPORT_SYMBOL(osd_sec_init_nosec_doall_caps);
1212
1213void osd_set_caps(struct osd_cdb *cdb, const void *caps)
1214{
1215 memcpy(&cdb->v1.caps, caps, OSDv1_CAP_LEN);
1216}
Boaz Harrosh4ef1a3d2009-01-25 16:59:50 +02001217
Boaz Harrosh345c4352009-01-25 17:03:07 +02001218bool osd_is_sec_alldata(struct osd_security_parameters *sec_parms __unused)
1219{
1220 return false;
1221}
1222
1223void osd_sec_sign_cdb(struct osd_cdb *ocdb __unused, const u8 *cap_key __unused)
1224{
1225}
1226
1227void osd_sec_sign_data(void *data_integ __unused,
1228 struct bio *bio __unused, const u8 *cap_key __unused)
1229{
1230}
1231
Boaz Harrosh4ef1a3d2009-01-25 16:59:50 +02001232/*
1233 * Declared in osd_protocol.h
1234 * 4.12.5 Data-In and Data-Out buffer offsets
1235 * byte offset = mantissa * (2^(exponent+8))
1236 * Returns the smallest allowed encoded offset that contains given @offset
1237 * The actual encoded offset returned is @offset + *@padding.
1238 */
1239osd_cdb_offset __osd_encode_offset(
1240 u64 offset, unsigned *padding, int min_shift, int max_shift)
1241{
1242 u64 try_offset = -1, mod, align;
1243 osd_cdb_offset be32_offset;
1244 int shift;
1245
1246 *padding = 0;
1247 if (!offset)
1248 return 0;
1249
1250 for (shift = min_shift; shift < max_shift; ++shift) {
1251 try_offset = offset >> shift;
1252 if (try_offset < (1 << OSD_OFFSET_MAX_BITS))
1253 break;
1254 }
1255
1256 BUG_ON(shift == max_shift);
1257
1258 align = 1 << shift;
1259 mod = offset & (align - 1);
1260 if (mod) {
1261 *padding = align - mod;
1262 try_offset += 1;
1263 }
1264
1265 try_offset |= ((shift - 8) & 0xf) << 28;
1266 be32_offset = cpu_to_be32((u32)try_offset);
1267
1268 OSD_DEBUG("offset=%llu mantissa=%llu exp=%d encoded=%x pad=%d\n",
1269 _LLU(offset), _LLU(try_offset & 0x0FFFFFFF), shift,
1270 be32_offset, *padding);
1271 return be32_offset;
1272}