target_core_scdb.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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. #include <linux/net.h>
  29. #include <linux/string.h>
  30. #include <scsi/scsi.h>
  31. #include <asm/unaligned.h>
  32. #include <target/target_core_base.h>
  33. #include <target/target_core_transport.h>
  34. #include "target_core_scdb.h"
  35. /* split_cdb_XX_6():
  36. *
  37. * 21-bit LBA w/ 8-bit SECTORS
  38. */
  39. void split_cdb_XX_6(
  40. unsigned long long lba,
  41. u32 *sectors,
  42. unsigned char *cdb)
  43. {
  44. cdb[1] = (lba >> 16) & 0x1f;
  45. cdb[2] = (lba >> 8) & 0xff;
  46. cdb[3] = lba & 0xff;
  47. cdb[4] = *sectors & 0xff;
  48. }
  49. /* split_cdb_XX_10():
  50. *
  51. * 32-bit LBA w/ 16-bit SECTORS
  52. */
  53. void split_cdb_XX_10(
  54. unsigned long long lba,
  55. u32 *sectors,
  56. unsigned char *cdb)
  57. {
  58. put_unaligned_be32(lba, &cdb[2]);
  59. put_unaligned_be16(*sectors, &cdb[7]);
  60. }
  61. /* split_cdb_XX_12():
  62. *
  63. * 32-bit LBA w/ 32-bit SECTORS
  64. */
  65. void split_cdb_XX_12(
  66. unsigned long long lba,
  67. u32 *sectors,
  68. unsigned char *cdb)
  69. {
  70. put_unaligned_be32(lba, &cdb[2]);
  71. put_unaligned_be32(*sectors, &cdb[6]);
  72. }
  73. /* split_cdb_XX_16():
  74. *
  75. * 64-bit LBA w/ 32-bit SECTORS
  76. */
  77. void split_cdb_XX_16(
  78. unsigned long long lba,
  79. u32 *sectors,
  80. unsigned char *cdb)
  81. {
  82. put_unaligned_be64(lba, &cdb[2]);
  83. put_unaligned_be32(*sectors, &cdb[10]);
  84. }
  85. /*
  86. * split_cdb_XX_32():
  87. *
  88. * 64-bit LBA w/ 32-bit SECTORS such as READ_32, WRITE_32 and emulated XDWRITEREAD_32
  89. */
  90. void split_cdb_XX_32(
  91. unsigned long long lba,
  92. u32 *sectors,
  93. unsigned char *cdb)
  94. {
  95. put_unaligned_be64(lba, &cdb[12]);
  96. put_unaligned_be32(*sectors, &cdb[28]);
  97. }