LCOV - code coverage report
Current view: top level - lib/scsi - scsi.c (source / functions) Hit Total Coverage
Test: ut_cov_unit.info Lines: 4 37 10.8 %
Date: 2024-12-15 17:33:10 Functions: 3 8 37.5 %

          Line data    Source code
       1             : /*   SPDX-License-Identifier: BSD-3-Clause
       2             :  *   Copyright (C) 2008-2012 Daisuke Aoyama <aoyama@peach.ne.jp>.
       3             :  *   Copyright (C) 2016 Intel Corporation.
       4             :  *   All rights reserved.
       5             :  */
       6             : 
       7             : #include "scsi_internal.h"
       8             : #include "spdk/util.h"
       9             : 
      10             : int
      11           1 : spdk_scsi_init(void)
      12             : {
      13           1 :         return 0;
      14             : }
      15             : 
      16             : void
      17           0 : spdk_scsi_fini(void)
      18             : {
      19           0 : }
      20             : 
      21             : static void
      22           0 : scsi_trace(void)
      23             : {
      24           0 :         spdk_trace_register_owner_type(OWNER_TYPE_SCSI_DEV, 'd');
      25           0 :         spdk_trace_register_object(OBJECT_SCSI_TASK, 't');
      26           0 :         spdk_trace_register_description("SCSI_TASK_DONE", TRACE_SCSI_TASK_DONE,
      27             :                                         OWNER_TYPE_SCSI_DEV, OBJECT_SCSI_TASK, 0,
      28             :                                         SPDK_TRACE_ARG_TYPE_INT, "");
      29           0 :         spdk_trace_register_description("SCSI_TASK_START", TRACE_SCSI_TASK_START,
      30             :                                         OWNER_TYPE_SCSI_DEV, OBJECT_SCSI_TASK, 0,
      31             :                                         SPDK_TRACE_ARG_TYPE_INT, "");
      32           0 : }
      33           1 : SPDK_TRACE_REGISTER_FN(scsi_trace, "scsi", TRACE_GROUP_SCSI)
      34             : 
      35             : uint64_t
      36           0 : spdk_scsi_lun_id_int_to_fmt(int lun_id)
      37             : {
      38             :         uint64_t fmt_lun, method;
      39             : 
      40           0 :         if (lun_id < 0x0100) {
      41             :                 /* below 256 */
      42           0 :                 method = 0x00U;
      43           0 :                 fmt_lun = (method & 0x03U) << 62;
      44           0 :                 fmt_lun |= ((uint64_t)lun_id & 0x00ffU) << 48;
      45           0 :         } else if (lun_id < 0x4000) {
      46             :                 /* below 16384 */
      47           0 :                 method = 0x01U;
      48           0 :                 fmt_lun = (method & 0x03U) << 62;
      49           0 :                 fmt_lun |= ((uint64_t)lun_id & 0x3fffU) << 48;
      50             :         } else {
      51             :                 /* XXX */
      52           0 :                 fmt_lun = 0;
      53             :         }
      54             : 
      55           0 :         return fmt_lun;
      56             : }
      57             : 
      58             : int
      59           0 : spdk_scsi_lun_id_fmt_to_int(uint64_t fmt_lun)
      60             : {
      61             :         uint64_t method;
      62             :         int lun_i;
      63             : 
      64           0 :         method = (fmt_lun >> 62) & 0x03U;
      65           0 :         fmt_lun = fmt_lun >> 48;
      66           0 :         if (method == 0x00U) {
      67           0 :                 lun_i = (int)(fmt_lun & 0x00ffU);
      68           0 :         } else if (method == 0x01U) {
      69           0 :                 lun_i = (int)(fmt_lun & 0x3fffU);
      70             :         } else {
      71           0 :                 lun_i = 0xffffU;
      72             :         }
      73           0 :         return lun_i;
      74             : }
      75             : 
      76             : struct scsi_sbc_opcode_string {
      77             :         enum spdk_sbc_opcode opc;
      78             :         const char *str;
      79             : };
      80             : 
      81             : static const struct scsi_sbc_opcode_string scsi_sbc_opcode_strings[] = {
      82             :         { SPDK_SBC_COMPARE_AND_WRITE, "COMPARE AND WRITE" },
      83             :         { SPDK_SBC_FORMAT_UNIT, "FORMAT UNIT" },
      84             :         { SPDK_SBC_GET_LBA_STATUS, "GET LBA STATUS" },
      85             :         { SPDK_SBC_ORWRITE_16, "ORWRITE 16" },
      86             :         { SPDK_SBC_PRE_FETCH_10, "PRE FETCH 10" },
      87             :         { SPDK_SBC_PRE_FETCH_16, "PRE FETCH 16" },
      88             :         { SPDK_SBC_READ_6, "READ 6" },
      89             :         { SPDK_SBC_READ_10, "READ 10" },
      90             :         { SPDK_SBC_READ_12, "READ 12" },
      91             :         { SPDK_SBC_READ_16, "READ 16" },
      92             :         { SPDK_SBC_READ_ATTRIBUTE, "READ ATTRIBUTE" },
      93             :         { SPDK_SBC_READ_BUFFER, "READ BUFFER" },
      94             :         { SPDK_SBC_READ_CAPACITY_10, "READ CAPACITY 10" },
      95             :         { SPDK_SBC_READ_DEFECT_DATA_10, "READ DEFECT DATA 10" },
      96             :         { SPDK_SBC_READ_DEFECT_DATA_12, "READ DEFECT DATA 12" },
      97             :         { SPDK_SBC_READ_LONG_10, "READ LONG 10" },
      98             :         { SPDK_SBC_REASSIGN_BLOCKS, "REASSIGN BLOCKS" },
      99             :         { SPDK_SBC_SANITIZE, "SANITIZE" },
     100             :         { SPDK_SBC_START_STOP_UNIT, "START STOP UNIT" },
     101             :         { SPDK_SBC_SYNCHRONIZE_CACHE_10, "SYNCHRONIZE CACHE 10" },
     102             :         { SPDK_SBC_SYNCHRONIZE_CACHE_16, "SYNCHRONIZE CACHE 16" },
     103             :         { SPDK_SBC_UNMAP, "UNMAP" },
     104             :         { SPDK_SBC_VERIFY_10, "VERIFY 10" },
     105             :         { SPDK_SBC_VERIFY_12, "VERIFY 12" },
     106             :         { SPDK_SBC_VERIFY_16, "VERIFY 16" },
     107             :         { SPDK_SBC_WRITE_6, "WRITE 6" },
     108             :         { SPDK_SBC_WRITE_10, "WRITE 10" },
     109             :         { SPDK_SBC_WRITE_12, "WRITE 12" },
     110             :         { SPDK_SBC_WRITE_16, "WRITE 16" },
     111             :         { SPDK_SBC_WRITE_AND_VERIFY_10, "WRITE AND VERIFY 10" },
     112             :         { SPDK_SBC_WRITE_AND_VERIFY_12, "WRITE AND VERIFY 12" },
     113             :         { SPDK_SBC_WRITE_AND_VERIFY_16, "WRITE AND VERIFY 16" },
     114             :         { SPDK_SBC_WRITE_LONG_10, "WRITE LONG 10" },
     115             :         { SPDK_SBC_WRITE_SAME_10, "WRITE SAME 10" },
     116             :         { SPDK_SBC_WRITE_SAME_16, "WRITE SAME 16" },
     117             :         { SPDK_SBC_XDREAD_10, "XDREAD 10" },
     118             :         { SPDK_SBC_XDWRITE_10, "XDWRITE 10" },
     119             :         { SPDK_SBC_XDWRITEREAD_10, "XDWRITEREAD 10" },
     120             :         { SPDK_SBC_XPWRITE_10, "XPWRITE 10" }
     121             : };
     122             : 
     123             : const char *
     124           0 : spdk_scsi_sbc_opcode_string(uint8_t opcode, uint16_t sa)
     125             : {
     126             :         uint8_t i;
     127             : 
     128             :         /* FIXME: sa is unsupported currently, support variable length CDBs if necessary */
     129           0 :         for (i = 0; i < SPDK_COUNTOF(scsi_sbc_opcode_strings); i++) {
     130           0 :                 if (scsi_sbc_opcode_strings[i].opc == opcode) {
     131           0 :                         return scsi_sbc_opcode_strings[i].str;
     132             :                 }
     133             :         }
     134             : 
     135           0 :         return "UNKNOWN";
     136             : }
     137             : 
     138           1 : SPDK_LOG_REGISTER_COMPONENT(scsi)

Generated by: LCOV version 1.15