Merge branch 'for-38-rc2' of git://codeaurora.org/quic/kernel/davidb/linux-msm
[linux-2.6/cjktty.git] / drivers / target / target_core_scdb.c
blobdc6fed037ab3876b208ab8f5b8c08f69a2883eea
1 /*******************************************************************************
2 * Filename: target_core_scdb.c
4 * This file contains the generic target engine Split CDB related functions.
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
11 * Nicholas A. Bellinger <nab@kernel.org>
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.
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.
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.
27 ******************************************************************************/
29 #include <linux/net.h>
30 #include <linux/string.h>
31 #include <scsi/scsi.h>
32 #include <asm/unaligned.h>
34 #include <target/target_core_base.h>
35 #include <target/target_core_transport.h>
37 #include "target_core_scdb.h"
39 /* split_cdb_XX_6():
41 * 21-bit LBA w/ 8-bit SECTORS
43 void split_cdb_XX_6(
44 unsigned long long lba,
45 u32 *sectors,
46 unsigned char *cdb)
48 cdb[1] = (lba >> 16) & 0x1f;
49 cdb[2] = (lba >> 8) & 0xff;
50 cdb[3] = lba & 0xff;
51 cdb[4] = *sectors & 0xff;
54 /* split_cdb_XX_10():
56 * 32-bit LBA w/ 16-bit SECTORS
58 void split_cdb_XX_10(
59 unsigned long long lba,
60 u32 *sectors,
61 unsigned char *cdb)
63 put_unaligned_be32(lba, &cdb[2]);
64 put_unaligned_be16(*sectors, &cdb[7]);
67 /* split_cdb_XX_12():
69 * 32-bit LBA w/ 32-bit SECTORS
71 void split_cdb_XX_12(
72 unsigned long long lba,
73 u32 *sectors,
74 unsigned char *cdb)
76 put_unaligned_be32(lba, &cdb[2]);
77 put_unaligned_be32(*sectors, &cdb[6]);
80 /* split_cdb_XX_16():
82 * 64-bit LBA w/ 32-bit SECTORS
84 void split_cdb_XX_16(
85 unsigned long long lba,
86 u32 *sectors,
87 unsigned char *cdb)
89 put_unaligned_be64(lba, &cdb[2]);
90 put_unaligned_be32(*sectors, &cdb[10]);
94 * split_cdb_XX_32():
96 * 64-bit LBA w/ 32-bit SECTORS such as READ_32, WRITE_32 and emulated XDWRITEREAD_32
98 void split_cdb_XX_32(
99 unsigned long long lba,
100 u32 *sectors,
101 unsigned char *cdb)
103 put_unaligned_be64(lba, &cdb[12]);
104 put_unaligned_be32(*sectors, &cdb[28]);