"SfR Fresh" - the SfR Freeware/Shareware Archive

Member "mapscsi-0.0.11/qlogic_api.c" of archive mapscsi-0.0.11.tar.gz:


As a special service "SfR Fresh" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file. That can be also achieved for any archive member file by clicking within an archive contents listing on the first character of the file(path) respectively on the according byte size field.
    1 #include <stdio.h>
    2 #include <stdlib.h>
    3 
    4 #include "scsi_api.h"
    5 #include "qlogic_api.h"
    6 
    7 
    8 static fc_device_t *qldev_head;
    9 
   10 int qlogic_probe(int fd)
   11 {
   12     QL_IOCTL ql;
   13     QL_DISC_PORT qlport;
   14     QL_SCSI_ADDR qlscsi;
   15     int ql_num, i, j, k;
   16     fc_device_t *qldev;
   17 
   18     if(qldev_head) return; /* already probed */
   19 
   20     if(msizeof(QL_IOCTL, Signature) == 4)
   21       strcpy((char*)&ql.Signature, "QLOG");
   22     else if(msizeof(QL_IOCTL, Signature) == 8)
   23       strcpy((char*)&ql.Signature, "QLOGIC");
   24     ql.Version = QL_VERSION;
   25     if(ioctl(fd, QL_IOCTL_STARTIOCTL, &ql) < 0) {
   26       fprintf(stderr, "qlogic_probe: QL_IOCTL_STARTIOCTL failed\n");
   27       return;
   28     }
   29 
   30     if(!qldev_head) qldev = qldev_head = calloc(1, sizeof(fc_device_t));
   31 
   32     ql_num =  ql.Instance;
   33     for(i=0; i<ql_num && i < 5; i++) {
   34       ql.Instance = i;
   35       if(ioctl(fd, QL_IOCTL_SETINSTANCE, &ql) < 0) {
   36 	fprintf(stderr, "qlogic_probe: QL_IOCTL_SETINSTANCE failed\n");
   37 	return;
   38       }
   39       for(j=0; j < QL_MAX_FIBRE_DEVICES; j++) {
   40 	ql.SubCode = QL_IOCTL_SC_QUERY_DISC_PORT;
   41 	ql.ResponseAdr = &qlport;
   42 	ql.ResponseLen = sizeof(qlport);
   43 	ql.Instance = j;
   44 	if(ioctl(fd, QL_IOCTL_QUERY, &ql) >= 0) {
   45 	  if(ql.Status == QL_STATUS_DEV_NOT_FOUND ||
   46 	     ql.DetailStatus == QL_STATUS_DEV_NOT_FOUND) break;
   47 	  ql.RequestAdr = qlport.WWPN;
   48 	  ql.RequestLen = QL_DEF_WWN_NAME_SIZE;
   49 	  ql.ResponseAdr = &qlscsi;
   50 	  ql.ResponseLen = sizeof(qlscsi);
   51 	  if(ioctl(fd, QL_IOCTL_WWPN_TO_SCSIADDR, &ql) >= 0) {
   52 #ifdef DEBUG
   53 	  printf("host=%d wwn=%02x%02x%02x%02x%02x%02x%02x%02x id=%d\n",
   54 		 ql.HbaSelect,
   55 		 qlport.WWPN[0], qlport.WWPN[1], qlport.WWPN[2],
   56 		 qlport.WWPN[3], qlport.WWPN[4], qlport.WWPN[5],
   57 		 qlport.WWPN[6], qlport.WWPN[7], qlscsi.Target);
   58 #endif
   59 	  sprintf(qldev->wwpn, "%02x%02x%02x%02x%02x%02x%02x%02x",
   60 		  qlport.WWPN[0], qlport.WWPN[1], qlport.WWPN[2],
   61 		  qlport.WWPN[3], qlport.WWPN[4], qlport.WWPN[5],
   62 		  qlport.WWPN[6], qlport.WWPN[7]);
   63 	  sprintf(qldev->wwnn, "%02x%02x%02x%02x%02x%02x%02x%02x",
   64 		  qlport.WWNN[0], qlport.WWNN[1], qlport.WWNN[2],
   65 		  qlport.WWNN[3], qlport.WWNN[4], qlport.WWNN[5],
   66 		  qlport.WWNN[6], qlport.WWNN[7]);
   67 	  sprintf(qldev->portid, "%02x%02x%02x",
   68 		  qlport.Id[1], qlport.Id[2], qlport.Id[3]);
   69 	  qldev->loopid = qlport.LoopID;
   70 	  qldev->host = ql.HbaSelect;
   71 	  qldev->id = qlscsi.Target;
   72 	  qldev->next = calloc(1, sizeof(fc_device_t));
   73 	  qldev = qldev->next;
   74 
   75 	  }
   76 	}
   77       }
   78     }
   79 
   80 }
   81 
   82 int qlogic_map_wwn_to_sd()
   83 {
   84     fc_device_t *qldev = qldev_head;
   85     scsi_device_t *scsidev;
   86     int lun;
   87 
   88     if(!qldev) return;
   89     while(qldev->next) {
   90       for(lun=0; lun<256; lun++) {
   91 	/* all luns have the same WWPN */
   92 	if(scsidev = find_dev_by_loc(qldev->host, 0, qldev->id, lun)) {
   93 	  scsidev->isfc = 1;
   94 	  strcpy(scsidev->wwpn, qldev->wwpn);
   95 	  strcpy(scsidev->wwnn, qldev->wwnn);
   96 	  strcpy(scsidev->portid, qldev->portid);
   97 	  scsidev->loopid = qldev->loopid;
   98 	}
   99       }
  100       qldev = qldev->next;
  101     }
  102 
  103 }
  104 
  105 void qlogic_free()
  106 {
  107     fc_device_t *qldev = qldev_head;
  108 
  109     if(!qldev) return;
  110     while(qldev->next) {
  111       fc_device_t *t = qldev;
  112       qldev = qldev->next;
  113       free(t);
  114     }
  115     qldev_head = NULL;
  116 }