"Fossies" - the Fresh Open Source Software Archive

Member "open-fcoe-3.19/libHBAAPI/hbaapitest.c" (15 Apr 2015, 12278 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 "hbaapitest.c" see the Fossies "Dox" file reference documentation.

    1 /*
    2  * Description
    3  *  hbaapitest.c - Sample application which uses the common library API for
    4  *                        HBA requests.
    5  *
    6  * License:
    7  *  The contents of this file are subject to the SNIA Public License
    8  *  Version 1.0 (the "License"); you may not use this file except in
    9  *  compliance with the License. You may obtain a copy of the License at
   10  *
   11  *  /http://www.snia.org/English/Resources/Code/OpenSource.html
   12  *
   13  *  Software distributed under the License is distributed on an "AS IS"
   14  *  basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
   15  *  the License for the specific language governing rights and limitations
   16  *  under the License.
   17  *
   18  * The Original Code is  SNIA HBA API Sample Application
   19  *
   20  * The Initial Developer of the Original Code is:
   21  *  Dixon Hutchinson, Legato Systems, Inc. (dhutchin@legato.com)
   22  *
   23  * Contributor(s):
   24  *
   25  ***************************************************************************
   26  */
   27 
   28 
   29 
   30 #include <stdio.h>
   31 #ifndef WIN32
   32 #include <dlfcn.h> /* Dynamic library support for Solaris */
   33 #include <time.h>
   34 #endif
   35 #include "hbaapi.h"
   36 
   37 /*** Came from JNI **********************************************************
   38 ** Utility function that treats the passed value as an array of bytes, then
   39 ** formats and prints them in ASCII Hex format.  This function will
   40 ** optionally insert spaces into the output string at specified intervals.
   41 ****************************************************************************/
   42 
   43 void PrintHexString(void *Data, int Length, int Break)
   44 {
   45     int j;
   46     unsigned char *pc = (unsigned char *)Data;
   47 
   48     for (j=1; j<=Length; j++) {
   49         printf("%02X", (int)*pc++);
   50         if ( (Break != 0) && (!(j % Break))) {
   51             printf(" ");
   52         }
   53     }
   54 
   55 }
   56 /**** Came from JNI**********************************************************
   57 ** Utility function that formats and prints the World Wide Name.  The WWN
   58 ** is assumed to be represented as a char (byte) array of length 8.
   59 ****************************************************************************/
   60 
   61 void PrintWWN(unsigned char *pWwn)
   62 {
   63     PrintHexString(pWwn, 8, 0);
   64 }
   65 
   66 main() {
   67     int i, pi, j, dpi, ti, bi;
   68     HBA_STATUS retval;
   69     HBA_UINT32 hba_cnt;
   70     char namebuf[1028];
   71     HBA_HANDLE hba_handle;
   72     HBA_ADAPTERATTRIBUTES hba_attrs;
   73     HBA_PORTATTRIBUTES hba_portattrs;
   74     HBA_PORTSTATISTICS hba_portstats;
   75     HBA_PORTATTRIBUTES hba_disc_pattrs;
   76 #define MAPENTRIES  512
   77     union{
   78     HBA_FCPTARGETMAPPING    fcp_tmap;
   79     struct {
   80         HBA_UINT32      cnt;
   81         HBA_FCPSCSIENTRY    entry[MAPENTRIES];
   82     }fcp_tmapi;
   83     }MAPU;
   84 #define BINDENTRIES 512
   85     union{
   86     HBA_FCPBINDING      fcp_tbind;
   87     struct {
   88         HBA_UINT32      cnt;
   89         HBA_FCPBINDINGENTRY entry[BINDENTRIES];
   90     }fcp_tbindi;
   91     }BINDU;
   92 
   93 
   94     printf("HBA API Library version is %d\n", HBA_GetVersion());
   95 
   96     retval = HBA_LoadLibrary();
   97 
   98     if(retval != HBA_STATUS_OK) {
   99     perror("HBA_LoadLibrary");
  100     exit(1);
  101     }
  102 
  103     hba_cnt = HBA_GetNumberOfAdapters();
  104 
  105     printf("Number of HBA's is %d\n", hba_cnt);
  106     if(hba_cnt == 0) {
  107     fprintf(stderr, "not enough adapters\n");
  108     exit(1);
  109     }
  110 
  111     for(i = 0; i < hba_cnt; i++) {
  112     if((retval = HBA_GetAdapterName(i, namebuf)) != HBA_STATUS_OK) {
  113         fprintf(stderr, "Failure of HBA_GetAdapterName: %d\n", retval);
  114         continue;
  115     }
  116     printf("\n********************************************"
  117         "\nAdapter number %d is named: %s\n",
  118         i, namebuf);
  119     if((hba_handle = HBA_OpenAdapter(namebuf)) == 0) {
  120         fprintf(stderr, "Failure of HBA_OpenAdapter\n");
  121         perror("HBA_OpenAdapter");
  122         continue;
  123     }
  124     if((retval = HBA_GetAdapterAttributes(hba_handle, &hba_attrs))
  125        != HBA_STATUS_OK) {
  126         fprintf(stderr,
  127             "Failure of HBA_GetAdapterAttributes:%d\n",
  128             retval);
  129         goto close;
  130     }
  131     printf("Adapter Attributes\n");
  132     printf("   Manufacturer:%s:\n", hba_attrs.Manufacturer);
  133     printf("   SerialNumber:%s:\n", hba_attrs.SerialNumber);
  134     printf("   Model:%s:\n", hba_attrs.Model);
  135     printf("   ModelDesc:%s:\n", hba_attrs.ModelDescription);
  136     printf("   NodeWWN:0x"); PrintWWN(hba_attrs.NodeWWN.wwn); printf("\n");
  137     printf("   NodeSymName:%s:\n", hba_attrs.NodeSymbolicName);
  138     printf("   HardwareVersion:%s:\n", hba_attrs.HardwareVersion);
  139     printf("   DriverVersion:%s:\n", hba_attrs.DriverVersion);
  140     printf("   OptionROMVersion:%s:\n", hba_attrs.OptionROMVersion);
  141     printf("   FirmwareVersion:%s:\n", hba_attrs.FirmwareVersion);
  142     printf("   VendorSpecificID:%d:\n", hba_attrs.VendorSpecificID);
  143     printf("   NumberOfPorts:%d:\n", hba_attrs.NumberOfPorts);
  144     printf("   DriverName:%s:\n", hba_attrs.DriverName);
  145 
  146     for(pi = 0; pi < hba_attrs.NumberOfPorts; pi++) {
  147         retval = HBA_GetAdapterPortAttributes(hba_handle, pi, &hba_portattrs);
  148         if(retval != HBA_STATUS_OK) {
  149         fprintf(stderr,
  150             "Failure of HBA_GetAdapterPortAttributes for pi=%d,"
  151             "status=%d\n",
  152             pi, retval);
  153         goto close;
  154         }
  155         printf("  PortIndex:%d\n", pi);
  156         printf("   Adapter Port Attributes\n");
  157         printf("     NodeWWN:0x");
  158         PrintWWN(hba_portattrs.NodeWWN.wwn); printf("\n");
  159         printf("     PortWWN:0x");
  160         PrintWWN(hba_portattrs.PortWWN.wwn); printf("\n");
  161         printf("     PortFcId:0x%06lX\n", hba_portattrs.PortFcId);
  162         printf("     PortType:%d\n", hba_portattrs.PortType);
  163         printf("     PortState:%d\n", hba_portattrs.PortState);
  164         printf("     PortSupportedClassofService:%d\n",
  165            hba_portattrs.PortSupportedClassofService);
  166         printf("     PortSupportedFc4Types:");
  167         for(j = 0; j < 32; j++) {
  168         printf(" %02X", hba_portattrs.PortSupportedFc4Types.bits[j]);
  169         }
  170         printf("\n");
  171         printf("     PortActiveFc4Types:");
  172         for(j = 0; j < 32; j++) {
  173         printf(" %02X", hba_portattrs.PortActiveFc4Types.bits[j]);
  174         }
  175         printf("\n");
  176         printf("     PortSymbolicName:%s:\n", hba_portattrs.PortSymbolicName);
  177         printf("     OSDeviceName:%s:\n", hba_portattrs.OSDeviceName);
  178         printf("     PortSupportedSpeed:%d\n",
  179            hba_portattrs.PortSupportedSpeed);
  180         printf("     PortSpeed:%d\n", hba_portattrs.PortSpeed);
  181         printf("     PortMaxFrameSize:%d\n", hba_portattrs.PortMaxFrameSize);
  182         printf("     FabricName:0x");
  183         PrintWWN(hba_portattrs.FabricName.wwn); printf("\n");
  184         printf("     NumberofDiscoveredPorts:%d\n",
  185            hba_portattrs.NumberofDiscoveredPorts);
  186 
  187         retval = HBA_GetPortStatistics(hba_handle, pi, &hba_portstats);
  188         if(retval != HBA_STATUS_OK && retval != HBA_STATUS_ERROR_NOT_SUPPORTED) {
  189         fprintf(stderr,
  190             "Failure of HBA_GetPortStatistics for pi=%d,"
  191             "status=%d\n",
  192             pi, retval);
  193         goto close;
  194         }
  195         printf("   Adapter Port Statistics:\n");
  196         if(retval == HBA_STATUS_ERROR_NOT_SUPPORTED) {
  197         printf("     Port Statistics not supported by this HBA\n");
  198         } else {
  199         printf("     SecondsSinceLastReset: %lld\n",
  200                hba_portstats.SecondsSinceLastReset);
  201         printf("     TxFrames: %lld\n", hba_portstats.TxFrames);
  202         printf("     TxWords: %lld\n", hba_portstats.TxWords);
  203         printf("     RxFrames: %lld\n", hba_portstats.RxFrames);
  204         printf("     RxWords: %lld\n", hba_portstats.RxWords);
  205         printf("     LIPCount: %lld\n", hba_portstats.LIPCount);
  206         printf("     NOSCount: %lld\n", hba_portstats.NOSCount);
  207         printf("     ErrorFrames: %lld\n", hba_portstats.ErrorFrames);
  208         printf("     DumpedFrames: %lld\n", hba_portstats.DumpedFrames);
  209         printf("     LinkFailureCount: %lld\n",
  210                hba_portstats.LinkFailureCount);
  211         printf("     LossOfSyncCount: %lld\n", hba_portstats.LossOfSyncCount);
  212         printf("     LossOfSignalCount: %lld\n",
  213                hba_portstats.LossOfSignalCount);
  214         printf("     PrimitiveSeqProtocolErrCount: %lld\n",
  215                hba_portstats.PrimitiveSeqProtocolErrCount);
  216         printf("     InvalidTxWordCount: %lld\n",
  217                hba_portstats.InvalidTxWordCount);
  218         printf("     InvalidCRCCount: %lld\n", hba_portstats.InvalidCRCCount);
  219         }
  220         for(dpi = 0; dpi < hba_portattrs.NumberofDiscoveredPorts; dpi++) {
  221         retval = HBA_GetDiscoveredPortAttributes(hba_handle, pi, dpi,
  222                              &hba_disc_pattrs);
  223         if(retval != HBA_STATUS_OK) {
  224             fprintf(stderr,
  225                 "Failure of HBA_GetDiscoveredPortAttributes\n"
  226                 "for pi=%d, for dpi=%d, status=%d\n",
  227                 pi, dpi, retval);
  228             goto close;
  229         }
  230         printf("   Discovered Port Attributes (index=%d)\n", dpi);
  231         printf("     NodeWWN:0x");
  232         PrintWWN( hba_disc_pattrs.NodeWWN.wwn); printf("\n");
  233         printf("     PortWWN:0x");
  234         PrintWWN(hba_disc_pattrs.PortWWN.wwn); printf("\n");
  235         printf("     PortFcId:0x%06lX\n", hba_disc_pattrs.PortFcId);
  236         printf("     PortType:%d\n", hba_disc_pattrs.PortType);
  237         printf("     PortState:%d\n", hba_disc_pattrs.PortState);
  238         printf("     PortSupportedClassofService:%d\n",
  239                hba_disc_pattrs.PortSupportedClassofService);
  240         printf("     PortSupportedFc4Types:");
  241         for(j = 0; j < 32; j++) {
  242             printf(" %02X", hba_disc_pattrs.PortSupportedFc4Types.bits[j]);
  243         }
  244         printf("\n");
  245         printf("     PortActiveFc4Types:");
  246         for(j = 0; j < 32; j++) {
  247             printf(" %02X", hba_disc_pattrs.PortActiveFc4Types.bits[j]);
  248         }
  249         printf("\n");
  250         printf("     PortSymbolicName:%s:\n", hba_disc_pattrs.PortSymbolicName);
  251         printf("     OSDeviceName:%s:\n", hba_disc_pattrs.OSDeviceName);
  252         printf("     PortSupportedSpeed:%d\n",
  253                hba_disc_pattrs.PortSupportedSpeed);
  254         printf("     PortSpeed:%d\n", hba_disc_pattrs.PortSpeed);
  255         printf("     PortMaxFrameSize:%d\n", hba_disc_pattrs.PortMaxFrameSize);
  256         printf("     FabricName:0x");
  257         PrintWWN(hba_disc_pattrs.FabricName.wwn); printf("\n");
  258         printf("     NumberofDiscoveredPorts:%d\n",
  259                hba_disc_pattrs.NumberofDiscoveredPorts);
  260         {
  261 
  262             char large_buf[1024];
  263             char large_buf2[1024];
  264             retval = HBA_SendReportLUNs(hba_handle, hba_disc_pattrs.PortWWN,
  265                         large_buf, sizeof(large_buf),
  266                         large_buf2, sizeof(large_buf2));
  267         }
  268         }
  269     }
  270     MAPU.fcp_tmapi.cnt = MAPENTRIES;
  271     retval = HBA_GetFcpTargetMapping(hba_handle, &MAPU.fcp_tmap);
  272     if(retval != HBA_STATUS_OK) {
  273         fprintf(stderr, "failure of HBA_GetFcpTargetMapping, status=%d\n",
  274             retval);
  275         goto close;
  276     }
  277     printf("Target Mappings: %d\n", MAPU.fcp_tmap.NumberOfEntries);
  278     for(ti = 0; ti < MAPU.fcp_tmap.NumberOfEntries; ti++) {
  279         printf("scsiID:%s:c%ut%us%u\n",
  280            MAPU.fcp_tmap.entry[ti].ScsiId.OSDeviceName,
  281            MAPU.fcp_tmap.entry[ti].ScsiId.ScsiBusNumber,
  282            MAPU.fcp_tmap.entry[ti].ScsiId.ScsiTargetNumber,
  283            MAPU.fcp_tmap.entry[ti].ScsiId.ScsiOSLun);
  284         printf("FcpId: ID:%06x, NWWN:0x",MAPU.fcp_tmap.entry[ti].FcpId.FcId);
  285         PrintWWN(MAPU.fcp_tmap.entry[ti].FcpId.NodeWWN.wwn);
  286         printf(" PWWN:0x");
  287         PrintWWN(MAPU.fcp_tmap.entry[ti].FcpId.PortWWN.wwn);
  288         printf(" FcpLun:0x%llX\n", MAPU.fcp_tmap.entry[ti].FcpId.FcpLun);
  289             printf("FcpId: ID:%06x, NWWN:0x",MAPU.fcp_tmap.entry[ti].FcpId.FcId);
  290         PrintWWN(MAPU.fcp_tmap.entry[ti].FcpId.NodeWWN.wwn);
  291         printf(" PWWN:0x");
  292         PrintWWN(MAPU.fcp_tmap.entry[ti].FcpId.PortWWN.wwn);
  293         printf(" FcpLun:0x%llX\n\n",
  294                    MAPU.fcp_tmap.entry[ti].FcpId.FcpLun);
  295     }
  296     BINDU.fcp_tbindi.cnt = BINDENTRIES;
  297     retval = HBA_GetFcpPersistentBinding(hba_handle, &BINDU.fcp_tbind);
  298     if(retval == HBA_STATUS_OK) {
  299         printf("Persistant Bindings: %d\n", BINDU.fcp_tbind.NumberOfEntries);
  300         for(bi = 0; bi < BINDU.fcp_tbind.NumberOfEntries; bi++) {
  301         printf("BindingType:%s\n",
  302                (BINDU.fcp_tbind.entry[bi].type == TO_D_ID)?
  303                "TO_D_ID" : "TO_WWN");
  304         printf("scsiID:%s:c%ut%us%u\n",
  305                BINDU.fcp_tbind.entry[bi].ScsiId.OSDeviceName,
  306                BINDU.fcp_tbind.entry[bi].ScsiId.ScsiBusNumber,
  307                BINDU.fcp_tbind.entry[bi].ScsiId.ScsiTargetNumber,
  308                BINDU.fcp_tbind.entry[bi].ScsiId.ScsiOSLun);
  309         printf("FcpId: ID:%06x, NWWN:0x",
  310                BINDU.fcp_tbind.entry[bi].FcpId.FcId);
  311         PrintWWN(BINDU.fcp_tbind.entry[bi].FcpId.NodeWWN.wwn);
  312         printf(" PWWN:0x");
  313         PrintWWN(BINDU.fcp_tbind.entry[bi].FcpId.PortWWN.wwn);
  314         printf(" FcpLun:0x%llX\n",
  315                BINDU.fcp_tbind.entry[bi].FcpId.FcpLun);
  316 
  317         printf("FcId:%d\n\n", BINDU.fcp_tbind.entry[bi].FcId);
  318 
  319         }
  320     } else if (retval == HBA_STATUS_ERROR_NOT_SUPPORTED) {
  321         printf("HBA_GetFcpPersistantBinding is not supported\n");
  322     } else {
  323         fprintf(stderr, "failure of HBA_GetFcpPersistantBinding, status=%d\n",
  324             retval);
  325         goto close;
  326     }
  327 
  328     close:
  329     HBA_CloseAdapter(hba_handle);
  330     }
  331 }