12f245829Sagc /* 2*b6364952Sagc * IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. 3*b6364952Sagc * By downloading, copying, installing or using the software you agree 4*b6364952Sagc * to this license. If you do not agree to this license, do not 5*b6364952Sagc * download, install, copy or use the software. 62f245829Sagc * 72f245829Sagc * Intel License Agreement 82f245829Sagc * 92f245829Sagc * Copyright (c) 2000, Intel Corporation 102f245829Sagc * All rights reserved. 112f245829Sagc * 12*b6364952Sagc * Redistribution and use in source and binary forms, with or without 13*b6364952Sagc * modification, are permitted provided that the following conditions 14*b6364952Sagc * are met: 152f245829Sagc * 16*b6364952Sagc * -Redistributions of source code must retain the above copyright 17*b6364952Sagc * notice, this list of conditions and the following disclaimer. 182f245829Sagc * 19*b6364952Sagc * -Redistributions in binary form must reproduce the above copyright 20*b6364952Sagc * notice, this list of conditions and the following disclaimer in the 21*b6364952Sagc * documentation and/or other materials provided with the 22*b6364952Sagc * distribution. 232f245829Sagc * 24*b6364952Sagc * -The name of Intel Corporation may not be used to endorse or 25*b6364952Sagc * promote products derived from this software without specific prior 26*b6364952Sagc * written permission. 272f245829Sagc * 28*b6364952Sagc * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 29*b6364952Sagc * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 30*b6364952Sagc * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 31*b6364952Sagc * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL INTEL 32*b6364952Sagc * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 33*b6364952Sagc * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 34*b6364952Sagc * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 35*b6364952Sagc * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 36*b6364952Sagc * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 37*b6364952Sagc * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 38*b6364952Sagc * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 39*b6364952Sagc * SUCH DAMAGE. 402f245829Sagc */ 412f245829Sagc #ifndef OSD_H 422f245829Sagc #define OSD_H 432f245829Sagc 442f245829Sagc #include "config.h" 452f245829Sagc 462f245829Sagc #include <sys/types.h> 472f245829Sagc 482f245829Sagc #ifdef HAVE_STDINT_H 492f245829Sagc #include <stdint.h> 502f245829Sagc #endif 512f245829Sagc 522f245829Sagc #include "iscsiutil.h" 532f245829Sagc 542f245829Sagc #define OSD_VENDOR "NetBSD" 552f245829Sagc #define OSD_PRODUCT "NetBSD/Intel OSD" 562f245829Sagc #define OSD_VERSION 0 572f245829Sagc 582f245829Sagc /* 592f245829Sagc * OSD Configuration 602f245829Sagc */ 612f245829Sagc 622f245829Sagc #define CONFIG_OSD_CAPACITY_DFLT 1024 632f245829Sagc #define CONFIG_OSD_LUNS_DFLT 1 642f245829Sagc #define CONFIG_OSD_BASEDIR_DFLT "/tmp/iscsi_osd" 652f245829Sagc #define CONFIG_OSD_CDB_LEN 128 662f245829Sagc 672f245829Sagc /* 682f245829Sagc * OSD Service Actions 692f245829Sagc */ 702f245829Sagc 712f245829Sagc #define OSD_CREATE_GROUP 0x880B 722f245829Sagc #define OSD_REMOVE_GROUP 0x880C 732f245829Sagc #define OSD_CREATE 0x8802 742f245829Sagc #define OSD_REMOVE 0x880A 752f245829Sagc #define OSD_READ 0x8805 762f245829Sagc #define OSD_WRITE 0x8806 772f245829Sagc #define OSD_GET_ATTR 0x880E 782f245829Sagc #define OSD_SET_ATTR 0x880F 792f245829Sagc 802f245829Sagc /* 812f245829Sagc * OSD Arguments 822f245829Sagc */ 832f245829Sagc 842f245829Sagc typedef struct osd_args_t { 852f245829Sagc uint8_t opcode; 862f245829Sagc uint8_t control; 872f245829Sagc uint8_t security; 882f245829Sagc uint8_t add_cdb_len; 892f245829Sagc uint16_t service_action; 902f245829Sagc uint8_t options_byte; 912f245829Sagc uint8_t second_options_byte; 922f245829Sagc uint32_t GroupID; 932f245829Sagc uint64_t UserID; 942f245829Sagc uint32_t SessionID; 952f245829Sagc uint64_t length; 962f245829Sagc uint64_t offset; 972f245829Sagc uint32_t set_attributes_list_length; 982f245829Sagc uint32_t get_attributes_page; 992f245829Sagc uint32_t get_attributes_list_length; 1002f245829Sagc uint32_t get_attributes_allocation_length; 1012f245829Sagc } osd_args_t; 1022f245829Sagc 1032f245829Sagc #define OSD_ENCAP_CDB(ARGS, CDB) \ 1042f245829Sagc (CDB)[0] = (ARGS)->opcode; \ 1052f245829Sagc (CDB)[1] = (ARGS)->control; \ 1062f245829Sagc (CDB)[6] = (ARGS)->security; \ 1072f245829Sagc (CDB)[7] = (ARGS)->add_cdb_len; \ 1082f245829Sagc *((uint16_t *)((CDB)+8)) = ISCSI_HTONS((ARGS)->service_action); \ 1092f245829Sagc (CDB)[10] = (ARGS)->options_byte; \ 1102f245829Sagc (CDB)[11] = (ARGS)->second_options_byte; \ 1112f245829Sagc *((uint32_t *)((CDB)+12)) = ISCSI_HTONL((ARGS)->GroupID); \ 1122f245829Sagc *((uint64_t *)((CDB)+16)) = ISCSI_HTONLL((ARGS)->UserID); \ 1132f245829Sagc *((uint32_t *)((CDB)+24)) = ISCSI_HTONL((ARGS)->SessionID); \ 1142f245829Sagc *((uint64_t *)((CDB)+28)) = ISCSI_HTONLL((ARGS)->length); \ 1152f245829Sagc *((uint64_t *)((CDB)+36)) = ISCSI_HTONLL((ARGS)->offset); \ 1162f245829Sagc *((uint32_t *)((CDB)+44)) = ISCSI_HTONL((ARGS)->get_attributes_page); \ 1172f245829Sagc *((uint32_t *)((CDB)+48)) = ISCSI_HTONL((ARGS)->get_attributes_list_length); \ 1182f245829Sagc *((uint32_t *)((CDB)+52)) = ISCSI_HTONL((ARGS)->get_attributes_allocation_length); \ 1192f245829Sagc *((uint32_t *)((CDB)+72)) = ISCSI_HTONL((ARGS)->set_attributes_list_length); 1202f245829Sagc 1212f245829Sagc #define OSD_DECAP_CDB(CDB, EXT_CDB, ARGS) \ 1222f245829Sagc (ARGS)->opcode = (CDB)[0]; \ 1232f245829Sagc (ARGS)->control = (CDB)[1]; \ 1242f245829Sagc (ARGS)->security = (CDB)[6]; \ 1252f245829Sagc (ARGS)->add_cdb_len = (CDB)[7]; \ 1262f245829Sagc (ARGS)->service_action = ISCSI_NTOHS(*((uint16_t *)((CDB)+8))); \ 1272f245829Sagc (ARGS)->options_byte = (CDB)[10]; \ 1282f245829Sagc (ARGS)->second_options_byte = (CDB)[11]; \ 1292f245829Sagc (ARGS)->GroupID = ISCSI_NTOHL(*((uint32_t *)((CDB)+12))); \ 1302f245829Sagc (ARGS)->UserID = ISCSI_NTOHLL(*((uint64_t *)((EXT_CDB)-16+16))); \ 1312f245829Sagc (ARGS)->SessionID = ISCSI_NTOHL(*((uint32_t *)((EXT_CDB)-16+24))); \ 1322f245829Sagc (ARGS)->length = ISCSI_NTOHLL(*((uint64_t *)((EXT_CDB)-16+28))); \ 1332f245829Sagc (ARGS)->offset = ISCSI_NTOHLL(*((uint64_t *)((EXT_CDB)-16+36))); \ 1342f245829Sagc (ARGS)->get_attributes_page = ISCSI_NTOHL(*((uint32_t *)((EXT_CDB)-16+44))); \ 1352f245829Sagc (ARGS)->get_attributes_list_length = ISCSI_NTOHL(*((uint32_t *)((EXT_CDB)-16+48))); \ 1362f245829Sagc (ARGS)->get_attributes_allocation_length = ISCSI_NTOHL(*((uint32_t *)((EXT_CDB)-16+52))); \ 1372f245829Sagc (ARGS)->set_attributes_list_length = ISCSI_NTOHL(*((uint32_t *)((EXT_CDB)-16+72))); 1382f245829Sagc 1392f245829Sagc #define OSD_PRINT_CDB(CDB, EXT_CDB) \ 1402f245829Sagc PRINT("opcode = 0x%x\n", CDB[0]); \ 1412f245829Sagc PRINT("control = 0x%x\n", CDB[1]); \ 1422f245829Sagc PRINT("security = 0x%x\n", CDB[6]); \ 1432f245829Sagc PRINT("add_cdb_len = %u\n", CDB[7]); \ 1442f245829Sagc PRINT("service_action = 0x%x\n", ISCSI_NTOHS(*(uint16_t*)(CDB+8))); \ 1452f245829Sagc PRINT("options byte 1 = 0x%x\n", CDB[10]); \ 1462f245829Sagc PRINT("options byte 2 = 0x%x\n", CDB[11]); \ 1472f245829Sagc PRINT("group id = 0x%x\n", ISCSI_NTOHL(*(uint32_t*)(CDB+12))); \ 1482f245829Sagc PRINT("user id = 0x%llx\n", ISCSI_NTOHLL(*(uint64_t*)(EXT_CDB-16+16))); \ 1492f245829Sagc PRINT("session id = 0x%x\n", ISCSI_NTOHL(*(uint32_t*)(EXT_CDB-16+24))); \ 1502f245829Sagc PRINT("length = %llu\n", ISCSI_NTOHLL(*(uint64_t*)(EXT_CDB-16+28))); \ 1512f245829Sagc PRINT("offset = %llu\n", ISCSI_NTOHLL(*(uint64_t*)(EXT_CDB-16+36))); \ 1522f245829Sagc PRINT("get attr page = %u\n", ISCSI_NTOHL(*(uint32_t*)(EXT_CDB-16+44))); \ 1532f245829Sagc PRINT("get list len = %u\n", ISCSI_NTOHL(*(uint32_t*)(EXT_CDB-16+48))); \ 1542f245829Sagc PRINT("get alloc len = %u\n", ISCSI_NTOHL(*(uint32_t*)(EXT_CDB-16+52))); \ 1552f245829Sagc PRINT("set list len = %u\n", ISCSI_NTOHL(*(uint32_t*)(EXT_CDB-16+72))); 1562f245829Sagc 1572f245829Sagc #endif /* OSD_H */ 158