LCOV - code coverage report
Current view: top level - spdk/lib/scsi - scsi.c (source / functions) Hit Total Coverage
Test: Combined Lines: 26 36 72.2 %
Date: 2024-07-15 21:04:32 Functions: 7 8 87.5 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 5 12 41.7 %

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

Generated by: LCOV version 1.14