diff options
Diffstat (limited to 'drivers/target/target_core_scdb.c')
-rw-r--r-- | drivers/target/target_core_scdb.c | 105 |
1 files changed, 105 insertions, 0 deletions
diff --git a/drivers/target/target_core_scdb.c b/drivers/target/target_core_scdb.c new file mode 100644 index 000000000000..dc6fed037ab3 --- /dev/null +++ b/drivers/target/target_core_scdb.c | |||
@@ -0,0 +1,105 @@ | |||
1 | /******************************************************************************* | ||
2 | * Filename: target_core_scdb.c | ||
3 | * | ||
4 | * This file contains the generic target engine Split CDB related functions. | ||
5 | * | ||
6 | * Copyright (c) 2004-2005 PyX Technologies, Inc. | ||
7 | * Copyright (c) 2005, 2006, 2007 SBE, Inc. | ||
8 | * Copyright (c) 2007-2010 Rising Tide Systems | ||
9 | * Copyright (c) 2008-2010 Linux-iSCSI.org | ||
10 | * | ||
11 | * Nicholas A. Bellinger <nab@kernel.org> | ||
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 as published by | ||
15 | * the Free Software Foundation; either version 2 of the License, or | ||
16 | * (at your option) any later version. | ||
17 | * | ||
18 | * This program is distributed in the hope that it will be useful, | ||
19 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
20 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
21 | * GNU General Public License for more details. | ||
22 | * | ||
23 | * You should have received a copy of the GNU General Public License | ||
24 | * along with this program; if not, write to the Free Software | ||
25 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | ||
26 | * | ||
27 | ******************************************************************************/ | ||
28 | |||
29 | #include <linux/net.h> | ||
30 | #include <linux/string.h> | ||
31 | #include <scsi/scsi.h> | ||
32 | #include <asm/unaligned.h> | ||
33 | |||
34 | #include <target/target_core_base.h> | ||
35 | #include <target/target_core_transport.h> | ||
36 | |||
37 | #include "target_core_scdb.h" | ||
38 | |||
39 | /* split_cdb_XX_6(): | ||
40 | * | ||
41 | * 21-bit LBA w/ 8-bit SECTORS | ||
42 | */ | ||
43 | void split_cdb_XX_6( | ||
44 | unsigned long long lba, | ||
45 | u32 *sectors, | ||
46 | unsigned char *cdb) | ||
47 | { | ||
48 | cdb[1] = (lba >> 16) & 0x1f; | ||
49 | cdb[2] = (lba >> 8) & 0xff; | ||
50 | cdb[3] = lba & 0xff; | ||
51 | cdb[4] = *sectors & 0xff; | ||
52 | } | ||
53 | |||
54 | /* split_cdb_XX_10(): | ||
55 | * | ||
56 | * 32-bit LBA w/ 16-bit SECTORS | ||
57 | */ | ||
58 | void split_cdb_XX_10( | ||
59 | unsigned long long lba, | ||
60 | u32 *sectors, | ||
61 | unsigned char *cdb) | ||
62 | { | ||
63 | put_unaligned_be32(lba, &cdb[2]); | ||
64 | put_unaligned_be16(*sectors, &cdb[7]); | ||
65 | } | ||
66 | |||
67 | /* split_cdb_XX_12(): | ||
68 | * | ||
69 | * 32-bit LBA w/ 32-bit SECTORS | ||
70 | */ | ||
71 | void split_cdb_XX_12( | ||
72 | unsigned long long lba, | ||
73 | u32 *sectors, | ||
74 | unsigned char *cdb) | ||
75 | { | ||
76 | put_unaligned_be32(lba, &cdb[2]); | ||
77 | put_unaligned_be32(*sectors, &cdb[6]); | ||
78 | } | ||
79 | |||
80 | /* split_cdb_XX_16(): | ||
81 | * | ||
82 | * 64-bit LBA w/ 32-bit SECTORS | ||
83 | */ | ||
84 | void split_cdb_XX_16( | ||
85 | unsigned long long lba, | ||
86 | u32 *sectors, | ||
87 | unsigned char *cdb) | ||
88 | { | ||
89 | put_unaligned_be64(lba, &cdb[2]); | ||
90 | put_unaligned_be32(*sectors, &cdb[10]); | ||
91 | } | ||
92 | |||
93 | /* | ||
94 | * split_cdb_XX_32(): | ||
95 | * | ||
96 | * 64-bit LBA w/ 32-bit SECTORS such as READ_32, WRITE_32 and emulated XDWRITEREAD_32 | ||
97 | */ | ||
98 | void split_cdb_XX_32( | ||
99 | unsigned long long lba, | ||
100 | u32 *sectors, | ||
101 | unsigned char *cdb) | ||
102 | { | ||
103 | put_unaligned_be64(lba, &cdb[12]); | ||
104 | put_unaligned_be32(*sectors, &cdb[28]); | ||
105 | } | ||