"Fossies" - the Fresh Open Source Software Archive

Member "open-fcoe-3.19/libhbalinux/scsi.c" (15 Apr 2015, 5004 Bytes) of package /linux/misc/open-fcoe-3.19.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "scsi.c" see the Fossies "Dox" file reference documentation.

    1 /*
    2  * Copyright (c) 2008, Intel Corporation.
    3  *
    4  * This program is free software; you can redistribute it and/or modify it
    5  * under the terms and conditions of the GNU Lesser General Public License,
    6  * version 2.1, as published by the Free Software Foundation.
    7  *
    8  * This program is distributed in the hope it will be useful, but WITHOUT
    9  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   10  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License
   11  * for more details.
   12  *
   13  * You should have received a copy of the GNU Lesser General Public License
   14  * along with this program; if not, write to the Free Software Foundation, Inc.,
   15  * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
   16  *
   17  */
   18 
   19 #include "utils.h"
   20 #include "api_lib.h"
   21 #include "adapt_impl.h"
   22 #include "bind_impl.h"
   23 #include "fc_scsi.h"
   24 
   25 /*
   26  * Inquiry V1.
   27  */
   28 HBA_STATUS
   29 scsi_inquiry_v1(HBA_HANDLE handle, HBA_WWN disc_wwpn, HBA_UINT64 fc_lun,
   30             HBA_UINT8 evpd, HBA_UINT32 page_code, void *resp,
   31             HBA_UINT32 resp_len, void *sense, HBA_UINT32 sense_len)
   32 {
   33     struct port_info *pp;
   34     char sg_name[50];
   35     HBA_UINT8 stat;
   36     HBA_STATUS status;
   37 
   38     /*
   39      * Find port.
   40      */
   41     pp = adapter_get_port(handle, 0);
   42     if (pp == NULL)
   43         return HBA_STATUS_ERROR_INVALID_HANDLE;
   44 
   45     if (get_binding_sg_name(
   46         pp, disc_wwpn, fc_lun, sg_name, sizeof(sg_name)) != 0)
   47         return HBA_STATUS_ERROR_TARGET_LUN;
   48 
   49     status = sg_issue_inquiry(sg_name, evpd ? SCSI_INQF_EVPD : 0, page_code,
   50                 resp, &resp_len, &stat, sense, &sense_len);
   51     if (status == HBA_STATUS_OK && stat == SCSI_ST_CHECK)
   52         status = HBA_STATUS_SCSI_CHECK_CONDITION;
   53 
   54     return status;
   55 }
   56 
   57 /*
   58  * Inquiry V2.
   59  */
   60 HBA_STATUS
   61 scsi_inquiry_v2(HBA_HANDLE handle, HBA_WWN wwpn, HBA_WWN disc_wwpn,
   62             HBA_UINT64 fc_lun, HBA_UINT8 cdb_byte1,
   63             HBA_UINT8 cdb_byte2, void *resp, HBA_UINT32 *resp_lenp,
   64             HBA_UINT8 *statp, void *sense, HBA_UINT32 *sense_lenp)
   65 {
   66     struct port_info *pp;
   67     char sg_name[50];
   68 
   69     /*
   70      * Find port.
   71      */
   72     pp = adapter_get_port_by_wwn(handle, wwpn, NULL);
   73     if (pp == NULL)
   74         return HBA_STATUS_ERROR_ILLEGAL_WWN;
   75 
   76     if (get_binding_sg_name(
   77         pp, disc_wwpn, fc_lun, sg_name, sizeof(sg_name)) != 0)
   78         return HBA_STATUS_ERROR_TARGET_LUN;
   79 
   80     return sg_issue_inquiry(sg_name, cdb_byte1, cdb_byte2,
   81                    resp, resp_lenp, statp, sense, sense_lenp);
   82 }
   83 
   84 /*
   85  * Read capacity V1.
   86  */
   87 HBA_STATUS
   88 scsi_read_capacity_v1(HBA_HANDLE handle, HBA_WWN disc_wwpn,
   89               HBA_UINT64 fc_lun, void *resp,
   90               HBA_UINT32 resp_len, void *sense,
   91               HBA_UINT32 sense_len)
   92 {
   93     struct port_info *pp;
   94     char sg_name[50];
   95     HBA_UINT8 stat;
   96     HBA_STATUS status;
   97 
   98     /*
   99      * Find port.
  100      */
  101     pp = adapter_get_port(handle, 0);
  102     if (pp == NULL)
  103         return HBA_STATUS_ERROR_INVALID_HANDLE;
  104 
  105     if (get_binding_sg_name(
  106         pp, disc_wwpn, fc_lun, sg_name, sizeof(sg_name)) != 0)
  107         return HBA_STATUS_ERROR_TARGET_LUN;
  108 
  109     status = sg_issue_read_capacity(sg_name, resp, &resp_len,
  110                  &stat, sense, &sense_len);
  111     if (status == HBA_STATUS_OK && stat == SCSI_ST_CHECK)
  112         status = HBA_STATUS_SCSI_CHECK_CONDITION;
  113 
  114     return status;
  115 }
  116 
  117 /*
  118  * Read capacity V2.
  119  */
  120 HBA_STATUS
  121 scsi_read_capacity_v2(HBA_HANDLE handle, HBA_WWN wwpn,
  122               HBA_WWN disc_wwpn, HBA_UINT64 fc_lun,
  123               void *resp, HBA_UINT32 *resp_lenp,
  124               HBA_UINT8 *statp, void *sense,
  125               HBA_UINT32 *sense_lenp)
  126 {
  127     struct port_info *pp;
  128     char sg_name[50];
  129 
  130     /*
  131      * Find port.
  132      */
  133     pp = adapter_get_port_by_wwn(handle, wwpn, NULL);
  134     if (pp == NULL)
  135         return HBA_STATUS_ERROR_ILLEGAL_WWN;
  136 
  137     if (get_binding_sg_name(
  138         pp, disc_wwpn, fc_lun, sg_name, sizeof(sg_name)) != 0)
  139         return HBA_STATUS_ERROR_TARGET_LUN;
  140 
  141     return sg_issue_read_capacity(sg_name, resp, resp_lenp,
  142                 statp, sense, sense_lenp);
  143 }
  144 
  145 /*
  146  * Report LUNS V1.
  147  */
  148 HBA_STATUS
  149 scsi_report_luns_v1(HBA_HANDLE handle, HBA_WWN disc_wwpn,
  150             void *resp, HBA_UINT32 resp_len,
  151             void *sense, HBA_UINT32 sense_len)
  152 {
  153     struct port_info *pp;
  154     char sg_name[50];
  155     HBA_UINT8 stat;
  156     HBA_STATUS status;
  157 
  158     /*
  159      * Find port.
  160      */
  161     pp = adapter_get_port(handle, 0);
  162     if (pp == NULL)
  163         return HBA_STATUS_ERROR_INVALID_HANDLE;
  164 
  165     if (get_binding_sg_name(
  166         pp, disc_wwpn, 0, sg_name, sizeof(sg_name)) != 0)
  167         return HBA_STATUS_ERROR_TARGET_PORT_WWN;
  168 
  169     status = sg_issue_report_luns(sg_name, resp, &resp_len,
  170                     &stat, sense, &sense_len);
  171     if (status == HBA_STATUS_OK && stat == SCSI_ST_CHECK)
  172         status = HBA_STATUS_SCSI_CHECK_CONDITION;
  173 
  174     return status;
  175 }
  176 
  177 /*
  178  * Report LUNS V2.
  179  */
  180 HBA_STATUS
  181 scsi_report_luns_v2(HBA_HANDLE handle, HBA_WWN wwpn,
  182             HBA_WWN disc_wwpn, void *resp,
  183             HBA_UINT32 *resp_lenp, HBA_UINT8 *statp,
  184             void *sense, HBA_UINT32 *sense_lenp)
  185 {
  186     struct port_info *pp;
  187     char sg_name[50];
  188 
  189     /*
  190      * Find port.
  191      */
  192     pp = adapter_get_port_by_wwn(handle, wwpn, NULL);
  193     if (pp == NULL)
  194         return HBA_STATUS_ERROR_ILLEGAL_WWN;
  195 
  196     if (get_binding_sg_name(
  197         pp, disc_wwpn, 0, sg_name, sizeof(sg_name)) != 0)
  198         return HBA_STATUS_ERROR_TARGET_PORT_WWN;
  199 
  200     return sg_issue_report_luns(sg_name, resp, resp_lenp,
  201                   statp, sense, sense_lenp);
  202 }
  203