ips.c
上传用户:lgb322
上传日期:2013-02-24
资源大小:30529k
文件大小:261k
源码类别:

嵌入式Linux

开发平台:

Unix_Linux

  1.    /* Remove the item from the active queue */
  2.    ips_removeq_scb(&ha->scb_activelist, scb);
  3.    if (!scb->scsi_cmd)
  4.       /* internal commands are handled in do_ipsintr */
  5.       return ;
  6.    DEBUG_VAR(2, "(%s%d) ips_chkstatus: cmd 0x%X id %d (%d %d %d)",
  7.              ips_name,
  8.              ha->host_num,
  9.              scb->cdb[0],
  10.              scb->cmd.basic_io.command_id,
  11.              scb->bus,
  12.              scb->target_id,
  13.              scb->lun);
  14. #ifndef NO_IPS_CMDLINE
  15.    if ((scb->scsi_cmd) && (ips_is_passthru(scb->scsi_cmd)))
  16.       /* passthru - just returns the raw result */
  17.       return ;
  18. #endif
  19.    errcode = DID_OK;
  20.    if (((basic_status & IPS_GSC_STATUS_MASK) == IPS_CMD_SUCCESS) ||
  21.        ((basic_status & IPS_GSC_STATUS_MASK) == IPS_CMD_RECOVERED_ERROR)) {
  22.       if (scb->bus == 0) {
  23.          if ((basic_status & IPS_GSC_STATUS_MASK) == IPS_CMD_RECOVERED_ERROR) {
  24.             DEBUG_VAR(1, "(%s%d) Recovered Logical Drive Error OpCode: %x, BSB: %x, ESB: %x",
  25.                       ips_name, ha->host_num,
  26.                       scb->cmd.basic_io.op_code, basic_status, ext_status);
  27.          }
  28.          switch (scb->scsi_cmd->cmnd[0]) {
  29.          case ALLOW_MEDIUM_REMOVAL:
  30.          case REZERO_UNIT:
  31.          case ERASE:
  32.          case WRITE_FILEMARKS:
  33.          case SPACE:
  34.             errcode = DID_ERROR;
  35.             break;
  36.          case START_STOP:
  37.             break;
  38.          case TEST_UNIT_READY:
  39.             if (!ips_online(ha, scb)) {
  40.                errcode = DID_TIME_OUT;
  41.             }
  42.             break;
  43.          case INQUIRY:
  44.             if (ips_online(ha, scb)) {
  45.                ips_inquiry(ha, scb);
  46.             } else {
  47.                errcode = DID_TIME_OUT;
  48.             }
  49.             break;
  50.          case REQUEST_SENSE:
  51.             ips_reqsen(ha, scb);
  52.             break;
  53.          case READ_6:
  54.          case WRITE_6:
  55.          case READ_10:
  56.          case WRITE_10:
  57.          case RESERVE:
  58.          case RELEASE:
  59.             break;
  60.          case MODE_SENSE:
  61.             if (!ips_online(ha, scb) || !ips_msense(ha, scb)) {
  62.                errcode = DID_ERROR;
  63.             }
  64.             break;
  65.          case READ_CAPACITY:
  66.             if (ips_online(ha, scb))
  67.                ips_rdcap(ha, scb);
  68.             else {
  69.                errcode = DID_TIME_OUT;
  70.             }
  71.             break;
  72.          case SEND_DIAGNOSTIC:
  73.          case REASSIGN_BLOCKS:
  74.             break;
  75.          case FORMAT_UNIT:
  76.             errcode = DID_ERROR;
  77.             break;
  78.          case SEEK_10:
  79.          case VERIFY:
  80.          case READ_DEFECT_DATA:
  81.          case READ_BUFFER:
  82.          case WRITE_BUFFER:
  83.             break;
  84.          default:
  85.             errcode = DID_ERROR;
  86.          } /* end switch */
  87.          scb->scsi_cmd->result = errcode << 16;
  88.       } else { /* bus == 0 */
  89.          /* restrict access to physical drives */
  90.          if ((scb->scsi_cmd->cmnd[0] == INQUIRY) &&
  91.              ((((char *) scb->scsi_cmd->buffer)[0] & 0x1f) == TYPE_DISK)) {
  92.             scb->scsi_cmd->result = DID_TIME_OUT << 16;
  93.          }
  94.       } /* else */
  95.    } else { /* recovered error / success */
  96.       if (scb->bus == 0) {
  97.          DEBUG_VAR(1, "(%s%d) Unrecovered Logical Drive Error OpCode: %x, BSB: %x, ESB: %x",
  98.                    ips_name, ha->host_num,
  99.                    scb->cmd.basic_io.op_code, basic_status, ext_status);
  100.       }
  101.       ips_map_status(ha, scb, sp);
  102.    } /* else */
  103. }
  104. /****************************************************************************/
  105. /*                                                                          */
  106. /* Routine Name: ips_online                                                 */
  107. /*                                                                          */
  108. /* Routine Description:                                                     */
  109. /*                                                                          */
  110. /*   Determine if a logical drive is online                                 */
  111. /*                                                                          */
  112. /****************************************************************************/
  113. static int
  114. ips_online(ips_ha_t *ha, ips_scb_t *scb) {
  115.    METHOD_TRACE("ips_online", 1);
  116.    if (scb->target_id >= IPS_MAX_LD)
  117.       return (0);
  118.    if ((scb->basic_status & IPS_GSC_STATUS_MASK) > 1) {
  119.       memset(&ha->adapt->logical_drive_info, 0, sizeof(ha->adapt->logical_drive_info));
  120.       return (0);
  121.    }
  122.    if (ha->adapt->logical_drive_info.drive_info[scb->target_id].state != IPS_LD_OFFLINE &&
  123.        ha->adapt->logical_drive_info.drive_info[scb->target_id].state != IPS_LD_FREE &&
  124.        ha->adapt->logical_drive_info.drive_info[scb->target_id].state != IPS_LD_CRS &&
  125.        ha->adapt->logical_drive_info.drive_info[scb->target_id].state != IPS_LD_SYS)
  126.       return (1);
  127.    else
  128.       return (0);
  129. }
  130. /****************************************************************************/
  131. /*                                                                          */
  132. /* Routine Name: ips_inquiry                                                */
  133. /*                                                                          */
  134. /* Routine Description:                                                     */
  135. /*                                                                          */
  136. /*   Simulate an inquiry command to a logical drive                         */
  137. /*                                                                          */
  138. /****************************************************************************/
  139. static int
  140. ips_inquiry(ips_ha_t *ha, ips_scb_t *scb) {
  141.    IPS_SCSI_INQ_DATA inquiry;
  142.    METHOD_TRACE("ips_inquiry", 1);
  143.    memset(&inquiry, 0, sizeof(IPS_SCSI_INQ_DATA));
  144.    inquiry.DeviceType = IPS_SCSI_INQ_TYPE_DASD;
  145.    inquiry.DeviceTypeQualifier = IPS_SCSI_INQ_LU_CONNECTED;
  146.    inquiry.Version = IPS_SCSI_INQ_REV2;
  147.    inquiry.ResponseDataFormat = IPS_SCSI_INQ_RD_REV2;
  148.    inquiry.AdditionalLength = 31;
  149.    inquiry.Flags[0] = IPS_SCSI_INQ_Address16;
  150.    inquiry.Flags[1] = IPS_SCSI_INQ_WBus16 | IPS_SCSI_INQ_Sync;
  151.    strncpy(inquiry.VendorId, "IBM     ", 8);
  152.    strncpy(inquiry.ProductId, "SERVERAID       ", 16);
  153.    strncpy(inquiry.ProductRevisionLevel, "1.00", 4);
  154.    memcpy(scb->scsi_cmd->request_buffer, &inquiry, scb->scsi_cmd->request_bufflen);
  155.    return (1);
  156. }
  157. /****************************************************************************/
  158. /*                                                                          */
  159. /* Routine Name: ips_rdcap                                                  */
  160. /*                                                                          */
  161. /* Routine Description:                                                     */
  162. /*                                                                          */
  163. /*   Simulate a read capacity command to a logical drive                    */
  164. /*                                                                          */
  165. /****************************************************************************/
  166. static int
  167. ips_rdcap(ips_ha_t *ha, ips_scb_t *scb) {
  168.    IPS_SCSI_CAPACITY *cap;
  169.    METHOD_TRACE("ips_rdcap", 1);
  170.    if (scb->scsi_cmd->bufflen < 8)
  171.       return (0);
  172.    cap = (IPS_SCSI_CAPACITY *) scb->scsi_cmd->request_buffer;
  173.    cap->lba = cpu_to_be32(le32_to_cpu(ha->adapt->logical_drive_info.drive_info[scb->target_id].sector_count) - 1);
  174.    cap->len = cpu_to_be32((u_int32_t) IPS_BLKSIZE);
  175.    return (1);
  176. }
  177. /****************************************************************************/
  178. /*                                                                          */
  179. /* Routine Name: ips_msense                                                 */
  180. /*                                                                          */
  181. /* Routine Description:                                                     */
  182. /*                                                                          */
  183. /*   Simulate a mode sense command to a logical drive                       */
  184. /*                                                                          */
  185. /****************************************************************************/
  186. static int
  187. ips_msense(ips_ha_t *ha, ips_scb_t *scb) {
  188.    u_int16_t               heads;
  189.    u_int16_t               sectors;
  190.    u_int32_t               cylinders;
  191.    IPS_SCSI_MODE_PAGE_DATA mdata;
  192.    METHOD_TRACE("ips_msense", 1);
  193.    if (le32_to_cpu(ha->enq->ulDriveSize[scb->target_id]) > 0x400000 &&
  194.        (ha->enq->ucMiscFlag & 0x8) == 0) {
  195.       heads = IPS_NORM_HEADS;
  196.       sectors = IPS_NORM_SECTORS;
  197.    } else {
  198.       heads = IPS_COMP_HEADS;
  199.       sectors = IPS_COMP_SECTORS;
  200.    }
  201.    cylinders = (le32_to_cpu(ha->enq->ulDriveSize[scb->target_id]) - 1) / (heads * sectors);
  202.    memset(&mdata, 0, sizeof(IPS_SCSI_MODE_PAGE_DATA));
  203.    mdata.hdr.BlockDescLength = 8;
  204.    switch (scb->scsi_cmd->cmnd[2] & 0x3f) {
  205.    case 0x03: /* page 3 */
  206.       mdata.pdata.pg3.PageCode = 3;
  207.       mdata.pdata.pg3.PageLength = sizeof(IPS_SCSI_MODE_PAGE3);
  208.       mdata.hdr.DataLength = 3 + mdata.hdr.BlockDescLength + mdata.pdata.pg3.PageLength;
  209.       mdata.pdata.pg3.TracksPerZone = 0;
  210.       mdata.pdata.pg3.AltSectorsPerZone = 0;
  211.       mdata.pdata.pg3.AltTracksPerZone = 0;
  212.       mdata.pdata.pg3.AltTracksPerVolume = 0;
  213.       mdata.pdata.pg3.SectorsPerTrack = cpu_to_be16(sectors);
  214.       mdata.pdata.pg3.BytesPerSector = cpu_to_be16(IPS_BLKSIZE);
  215.       mdata.pdata.pg3.Interleave = cpu_to_be16(1);
  216.       mdata.pdata.pg3.TrackSkew = 0;
  217.       mdata.pdata.pg3.CylinderSkew = 0;
  218.       mdata.pdata.pg3.flags = IPS_SCSI_MP3_SoftSector;
  219.       break;
  220.    case 0x4:
  221.       mdata.pdata.pg4.PageCode = 4;
  222.       mdata.pdata.pg4.PageLength = sizeof(IPS_SCSI_MODE_PAGE4);
  223.       mdata.hdr.DataLength = 3 + mdata.hdr.BlockDescLength + mdata.pdata.pg4.PageLength;
  224.       mdata.pdata.pg4.CylindersHigh = cpu_to_be16((cylinders >> 8) & 0xFFFF);
  225.       mdata.pdata.pg4.CylindersLow = (cylinders & 0xFF);
  226.       mdata.pdata.pg4.Heads = heads;
  227.       mdata.pdata.pg4.WritePrecompHigh = 0;
  228.       mdata.pdata.pg4.WritePrecompLow = 0;
  229.       mdata.pdata.pg4.ReducedWriteCurrentHigh = 0;
  230.       mdata.pdata.pg4.ReducedWriteCurrentLow = 0;
  231.       mdata.pdata.pg4.StepRate = cpu_to_be16(1);
  232.       mdata.pdata.pg4.LandingZoneHigh = 0;
  233.       mdata.pdata.pg4.LandingZoneLow = 0;
  234.       mdata.pdata.pg4.flags = 0;
  235.       mdata.pdata.pg4.RotationalOffset = 0;
  236.       mdata.pdata.pg4.MediumRotationRate = 0;
  237.       break;
  238.    default:
  239.       return (0);
  240.    } /* end switch */
  241.    memcpy(scb->scsi_cmd->request_buffer, &mdata, scb->scsi_cmd->request_bufflen);
  242.    return (1);
  243. }
  244. /****************************************************************************/
  245. /*                                                                          */
  246. /* Routine Name: ips_reqsen                                                 */
  247. /*                                                                          */
  248. /* Routine Description:                                                     */
  249. /*                                                                          */
  250. /*   Simulate a request sense command to a logical drive                    */
  251. /*                                                                          */
  252. /****************************************************************************/
  253. static int
  254. ips_reqsen(ips_ha_t *ha, ips_scb_t *scb) {
  255.    IPS_SCSI_REQSEN reqsen;
  256.    METHOD_TRACE("ips_reqsen", 1);
  257.    memset(&reqsen, 0, sizeof(IPS_SCSI_REQSEN));
  258.    reqsen.ResponseCode = IPS_SCSI_REQSEN_VALID | IPS_SCSI_REQSEN_CURRENT_ERR;
  259.    reqsen.AdditionalLength = 10;
  260.    reqsen.AdditionalSenseCode = IPS_SCSI_REQSEN_NO_SENSE;
  261.    reqsen.AdditionalSenseCodeQual = IPS_SCSI_REQSEN_NO_SENSE;
  262.    memcpy(scb->scsi_cmd->request_buffer, &reqsen, scb->scsi_cmd->request_bufflen);
  263.    return (1);
  264. }
  265. /****************************************************************************/
  266. /*                                                                          */
  267. /* Routine Name: ips_free                                                   */
  268. /*                                                                          */
  269. /* Routine Description:                                                     */
  270. /*                                                                          */
  271. /*   Free any allocated space for this controller                           */
  272. /*                                                                          */
  273. /****************************************************************************/
  274. static void
  275. ips_free(ips_ha_t *ha) {
  276.    int i;
  277.    METHOD_TRACE("ips_free", 1);
  278.    if (ha) {
  279.       if (ha->enq) {
  280.          kfree(ha->enq);
  281.          ha->enq = NULL;
  282.       }
  283.       if (ha->conf) {
  284.          kfree(ha->conf);
  285.          ha->conf = NULL;
  286.       }
  287.       if (ha->adapt) {
  288.          kfree(ha->adapt);
  289.          ha->adapt = NULL;
  290.       }
  291.       if (ha->nvram) {
  292.          kfree(ha->nvram);
  293.          ha->nvram = NULL;
  294.       }
  295.       if (ha->subsys) {
  296.          kfree(ha->subsys);
  297.          ha->subsys = NULL;
  298.       }
  299.       if (ha->dummy) {
  300.          kfree(ha->dummy);
  301.          ha->dummy = NULL;
  302.       }
  303.       if (ha->ioctl_data) {
  304.          free_pages((unsigned long) ha->ioctl_data, ha->ioctl_order);
  305.          ha->ioctl_data = NULL;
  306.          ha->ioctl_datasize = 0;
  307.          ha->ioctl_order = 0;
  308.       }
  309.       if (ha->scbs) {
  310.          for (i = 0; i < ha->max_cmds; i++) {
  311.             if (ha->scbs[i].sg_list)
  312.                kfree(ha->scbs[i].sg_list);
  313.          }
  314.          kfree(ha->scbs);
  315.          ha->scbs = NULL;
  316.       } /* end if */
  317.       /* free memory mapped (if applicable) */
  318.       if (ha->mem_ptr) {
  319.          iounmap(ha->ioremap_ptr);
  320.          ha->ioremap_ptr = NULL;
  321.          ha->mem_ptr = NULL;
  322.       }
  323. #if LINUX_VERSION_CODE >= LinuxVersionCode(2,3,17)
  324.       if (ha->mem_addr) 
  325.           release_mem_region(ha->mem_addr, ha->mem_len);
  326. #endif
  327.       ha->mem_addr = 0;
  328.    }
  329. }
  330. /****************************************************************************/
  331. /*                                                                          */
  332. /* Routine Name: ips_allocatescbs                                           */
  333. /*                                                                          */
  334. /* Routine Description:                                                     */
  335. /*                                                                          */
  336. /*   Allocate the command blocks                                            */
  337. /*                                                                          */
  338. /****************************************************************************/
  339. static int
  340. ips_allocatescbs(ips_ha_t *ha) {
  341.    ips_scb_t *scb_p;
  342.    int        i;
  343.    METHOD_TRACE("ips_allocatescbs", 1);
  344.    /* Allocate memory for the CCBs */
  345.    ha->scbs = (ips_scb_t *) kmalloc(ha->max_cmds * sizeof(ips_scb_t), GFP_KERNEL);
  346.    if (ha->scbs == NULL)
  347.       return 0;
  348.    memset(ha->scbs, 0, ha->max_cmds * sizeof(ips_scb_t));
  349.    for (i = 0; i < ha->max_cmds; i++) {
  350.       scb_p = &ha->scbs[i];
  351.       /* allocate S/G list */
  352.       scb_p->sg_list = (IPS_SG_LIST *) kmalloc(sizeof(IPS_SG_LIST) * IPS_MAX_SG, GFP_ATOMIC);
  353.       if (! scb_p->sg_list)
  354.          return (0);
  355.       /* add to the free list */
  356.       if (i < ha->max_cmds - 1) {
  357.          scb_p->q_next = ha->scb_freelist;
  358.          ha->scb_freelist = scb_p;
  359.       }
  360.    }
  361.    /* success */
  362.    return (1);
  363. }
  364. /****************************************************************************/
  365. /*                                                                          */
  366. /* Routine Name: ips_init_scb                                               */
  367. /*                                                                          */
  368. /* Routine Description:                                                     */
  369. /*                                                                          */
  370. /*   Initialize a CCB to default values                                     */
  371. /*                                                                          */
  372. /****************************************************************************/
  373. static void
  374. ips_init_scb(ips_ha_t *ha, ips_scb_t *scb) {
  375.    IPS_SG_LIST *sg_list;
  376.    METHOD_TRACE("ips_init_scb", 1);
  377.    if (scb == NULL)
  378.       return ;
  379.    sg_list = scb->sg_list;
  380.    /* zero fill */
  381.    memset(scb, 0, sizeof(ips_scb_t));
  382.    memset(ha->dummy, 0, sizeof(IPS_IO_CMD));
  383.    /* Initialize dummy command bucket */
  384.    ha->dummy->op_code = 0xFF;
  385.    ha->dummy->ccsar = cpu_to_le32(VIRT_TO_BUS(ha->dummy));
  386.    ha->dummy->command_id = IPS_MAX_CMDS;
  387.    /* set bus address of scb */
  388.    scb->scb_busaddr = VIRT_TO_BUS(scb);
  389.    scb->sg_list = sg_list;
  390.    /* Neptune Fix */
  391.    scb->cmd.basic_io.cccr = cpu_to_le32((u_int32_t) IPS_BIT_ILE);
  392.    scb->cmd.basic_io.ccsar = cpu_to_le32(VIRT_TO_BUS(ha->dummy));
  393. }
  394. /****************************************************************************/
  395. /*                                                                          */
  396. /* Routine Name: ips_get_scb                                                */
  397. /*                                                                          */
  398. /* Routine Description:                                                     */
  399. /*                                                                          */
  400. /*   Initialize a CCB to default values                                     */
  401. /*                                                                          */
  402. /* ASSUMED to be callled from within a lock                                 */
  403. /*                                                                          */
  404. /****************************************************************************/
  405. static ips_scb_t *
  406. ips_getscb(ips_ha_t *ha) {
  407.    ips_scb_t     *scb;
  408.    unsigned long  cpu_flags;
  409.    METHOD_TRACE("ips_getscb", 1);
  410.    IPS_SCB_LOCK(cpu_flags);
  411.    if ((scb = ha->scb_freelist) == NULL) {
  412.       IPS_SCB_UNLOCK(cpu_flags);
  413.       return (NULL);
  414.    }
  415.    ha->scb_freelist = scb->q_next;
  416.    scb->q_next = NULL;
  417.    IPS_SCB_UNLOCK(cpu_flags);
  418.    ips_init_scb(ha, scb);
  419.    return (scb);
  420. }
  421. /****************************************************************************/
  422. /*                                                                          */
  423. /* Routine Name: ips_free_scb                                               */
  424. /*                                                                          */
  425. /* Routine Description:                                                     */
  426. /*                                                                          */
  427. /*   Return an unused CCB back to the free list                             */
  428. /*                                                                          */
  429. /* ASSUMED to be called from within a lock                                  */
  430. /*                                                                          */
  431. /****************************************************************************/
  432. static void
  433. ips_freescb(ips_ha_t *ha, ips_scb_t *scb) {
  434.    unsigned long cpu_flags;
  435.    METHOD_TRACE("ips_freescb", 1);
  436.    /* check to make sure this is not our "special" scb */
  437.    if (IPS_COMMAND_ID(ha, scb) < (ha->max_cmds - 1)) {
  438.       IPS_SCB_LOCK(cpu_flags);
  439.       scb->q_next = ha->scb_freelist;
  440.       ha->scb_freelist = scb;
  441.       IPS_SCB_UNLOCK(cpu_flags);
  442.    }
  443. }
  444. /****************************************************************************/
  445. /*                                                                          */
  446. /* Routine Name: ips_isinit_copperhead                                      */
  447. /*                                                                          */
  448. /* Routine Description:                                                     */
  449. /*                                                                          */
  450. /*   Reset the controller                                                   */
  451. /*                                                                          */
  452. /****************************************************************************/
  453. static int
  454. ips_isinit_copperhead(ips_ha_t *ha) {
  455.    u_int8_t scpr;
  456.    u_int8_t isr;
  457.    METHOD_TRACE("ips_isinit_copperhead", 1);
  458.    isr = inb(ha->io_addr + IPS_REG_HISR);
  459.    scpr = inb(ha->io_addr + IPS_REG_SCPR);
  460.    if (((isr & IPS_BIT_EI) == 0) && ((scpr & IPS_BIT_EBM) == 0))
  461.        return (0);
  462.    else
  463.        return (1);
  464. }
  465. /****************************************************************************/
  466. /*                                                                          */
  467. /* Routine Name: ips_isinit_copperhead_memio                                */
  468. /*                                                                          */
  469. /* Routine Description:                                                     */
  470. /*                                                                          */
  471. /*   Reset the controller                                                   */
  472. /*                                                                          */
  473. /****************************************************************************/
  474. static int
  475. ips_isinit_copperhead_memio(ips_ha_t *ha) {
  476.    u_int8_t isr=0;
  477.    u_int8_t scpr;
  478.    METHOD_TRACE("ips_is_init_copperhead_memio", 1);
  479.    isr = readb(ha->mem_ptr + IPS_REG_HISR);
  480.    scpr = readb(ha->mem_ptr + IPS_REG_SCPR);
  481.    if (((isr & IPS_BIT_EI) == 0) && ((scpr & IPS_BIT_EBM) == 0))
  482.        return (0);
  483.    else
  484.        return (1);
  485. }
  486. /****************************************************************************/
  487. /*                                                                          */
  488. /* Routine Name: ips_isinit_morpheus                                        */
  489. /*                                                                          */
  490. /* Routine Description:                                                     */
  491. /*                                                                          */
  492. /*   Reset the controller                                                   */
  493. /*                                                                          */
  494. /****************************************************************************/
  495. static int
  496. ips_isinit_morpheus(ips_ha_t *ha) {
  497.    u_int32_t post;
  498.    u_int32_t bits;
  499.    METHOD_TRACE("ips_is_init_morpheus", 1);
  500.    post = le32_to_cpu(readl(ha->mem_ptr + IPS_REG_I960_MSG0));
  501.    bits = le32_to_cpu(readl(ha->mem_ptr + IPS_REG_I2O_HIR));
  502.    if (post == 0)
  503.        return (0);
  504.    else if (bits & 0x3)
  505.        return (0);
  506.    else
  507.        return (1);
  508. }
  509. /****************************************************************************/
  510. /*                                                                          */
  511. /* Routine Name: ips_enable_int_copperhead                                  */
  512. /*                                                                          */
  513. /* Routine Description:                                                     */
  514. /*   Turn on interrupts                                                     */
  515. /*                                                                          */
  516. /****************************************************************************/
  517. static void
  518. ips_enable_int_copperhead(ips_ha_t *ha) {
  519.    METHOD_TRACE("ips_enable_int_copperhead", 1);
  520.    outb(ha->io_addr + IPS_REG_HISR, IPS_BIT_EI);
  521. }
  522. /****************************************************************************/
  523. /*                                                                          */
  524. /* Routine Name: ips_enable_int_copperhead_memio                            */
  525. /*                                                                          */
  526. /* Routine Description:                                                     */
  527. /*   Turn on interrupts                                                     */
  528. /*                                                                          */
  529. /****************************************************************************/
  530. static void
  531. ips_enable_int_copperhead_memio(ips_ha_t *ha) {
  532.    METHOD_TRACE("ips_enable_int_copperhead_memio", 1);
  533.    writeb(IPS_BIT_EI, ha->mem_ptr + IPS_REG_HISR);
  534. }
  535. /****************************************************************************/
  536. /*                                                                          */
  537. /* Routine Name: ips_enable_int_morpheus                                    */
  538. /*                                                                          */
  539. /* Routine Description:                                                     */
  540. /*   Turn on interrupts                                                     */
  541. /*                                                                          */
  542. /****************************************************************************/
  543. static void
  544. ips_enable_int_morpheus(ips_ha_t *ha) {
  545.    u_int32_t  Oimr;
  546.    METHOD_TRACE("ips_enable_int_morpheus", 1);
  547.    Oimr = le32_to_cpu(readl(ha->mem_ptr + IPS_REG_I960_OIMR));
  548.    Oimr &= ~0x08;
  549.    writel(cpu_to_le32(Oimr), ha->mem_ptr + IPS_REG_I960_OIMR);
  550. }
  551. /****************************************************************************/
  552. /*                                                                          */
  553. /* Routine Name: ips_init_copperhead                                        */
  554. /*                                                                          */
  555. /* Routine Description:                                                     */
  556. /*                                                                          */
  557. /*   Initialize a copperhead controller                                     */
  558. /*                                                                          */
  559. /****************************************************************************/
  560. static int
  561. ips_init_copperhead(ips_ha_t *ha) {
  562.    u_int8_t  Isr;
  563.    u_int8_t  Cbsp;
  564.    u_int8_t  PostByte[IPS_MAX_POST_BYTES];
  565.    u_int8_t  ConfigByte[IPS_MAX_CONFIG_BYTES];
  566.    int i, j;
  567.    METHOD_TRACE("ips_init_copperhead", 1);
  568.    for (i = 0; i < IPS_MAX_POST_BYTES; i++) {
  569.       for (j = 0; j < 45; j++) {
  570.          Isr = inb(ha->io_addr + IPS_REG_HISR);
  571.          if (Isr & IPS_BIT_GHI)
  572.             break;
  573.          MDELAY(IPS_ONE_SEC);
  574.       }
  575.       if (j >= 45)
  576.          /* error occurred */
  577.          return (0);
  578.       PostByte[i] = inb(ha->io_addr + IPS_REG_ISPR);
  579.       outb(Isr, ha->io_addr + IPS_REG_HISR);
  580.    }
  581.    if (PostByte[0] < IPS_GOOD_POST_STATUS) {
  582.       printk(KERN_WARNING "(%s%d) reset controller fails (post status %x %x).n",
  583.              ips_name, ha->host_num, PostByte[0], PostByte[1]);
  584.       return (0);
  585.    }
  586.    for (i = 0; i < IPS_MAX_CONFIG_BYTES; i++) {
  587.       for (j = 0; j < 240; j++) {
  588.          Isr = inb(ha->io_addr + IPS_REG_HISR);
  589.          if (Isr & IPS_BIT_GHI)
  590.             break;
  591.          MDELAY(IPS_ONE_SEC);    /* 1 sec */
  592.       }
  593.       if (j >= 240)
  594.          /* error occurred */
  595.          return (0);
  596.       ConfigByte[i] = inb(ha->io_addr + IPS_REG_ISPR);
  597.       outb(Isr, ha->io_addr + IPS_REG_HISR);
  598.    }
  599.    for (i = 0; i < 240; i++) {
  600.       Cbsp = inb(ha->io_addr + IPS_REG_CBSP);
  601.       if ((Cbsp & IPS_BIT_OP) == 0)
  602.          break;
  603.       MDELAY(IPS_ONE_SEC);
  604.    }
  605.    if (i >= 240)
  606.       /* reset failed */
  607.       return (0);
  608.    /* setup CCCR */
  609.    outl(cpu_to_le32(0x1010), ha->io_addr + IPS_REG_CCCR);
  610.    /* Enable busmastering */
  611.    outb(IPS_BIT_EBM, ha->io_addr + IPS_REG_SCPR);
  612.    if (ha->revision_id == IPS_REVID_TROMBONE64)
  613.       /* fix for anaconda64 */
  614.       outl(0, ha->io_addr + IPS_REG_NDAE);
  615.    /* Enable interrupts */
  616.    outb(IPS_BIT_EI, ha->io_addr + IPS_REG_HISR);
  617.    return (1);
  618. }
  619. /****************************************************************************/
  620. /*                                                                          */
  621. /* Routine Name: ips_init_copperhead_memio                                  */
  622. /*                                                                          */
  623. /* Routine Description:                                                     */
  624. /*                                                                          */
  625. /*   Initialize a copperhead controller with memory mapped I/O              */
  626. /*                                                                          */
  627. /****************************************************************************/
  628. static int
  629. ips_init_copperhead_memio(ips_ha_t *ha) {
  630.    u_int8_t  Isr=0;
  631.    u_int8_t  Cbsp;
  632.    u_int8_t  PostByte[IPS_MAX_POST_BYTES];
  633.    u_int8_t  ConfigByte[IPS_MAX_CONFIG_BYTES];
  634.    int i, j;
  635.    METHOD_TRACE("ips_init_copperhead_memio", 1);
  636.    for (i = 0; i < IPS_MAX_POST_BYTES; i++) {
  637.       for (j = 0; j < 45; j++) {
  638.          Isr = readb(ha->mem_ptr + IPS_REG_HISR);
  639.          if (Isr & IPS_BIT_GHI)
  640.             break;
  641.          MDELAY(IPS_ONE_SEC);
  642.       }
  643.       if (j >= 45)
  644.          /* error occurred */
  645.          return (0);
  646.       PostByte[i] = readb(ha->mem_ptr + IPS_REG_ISPR);
  647.       writeb(Isr, ha->mem_ptr + IPS_REG_HISR);
  648.    }
  649.    if (PostByte[0] < IPS_GOOD_POST_STATUS) {
  650.       printk(KERN_WARNING "(%s%d) reset controller fails (post status %x %x).n",
  651.              ips_name, ha->host_num, PostByte[0], PostByte[1]);
  652.       return (0);
  653.    }
  654.    for (i = 0; i < IPS_MAX_CONFIG_BYTES; i++) {
  655.       for (j = 0; j < 240; j++) {
  656.          Isr = readb(ha->mem_ptr + IPS_REG_HISR);
  657.          if (Isr & IPS_BIT_GHI)
  658.             break;
  659.          MDELAY(IPS_ONE_SEC); /* 100 msec */
  660.       }
  661.       if (j >= 240)
  662.          /* error occurred */
  663.          return (0);
  664.       ConfigByte[i] = readb(ha->mem_ptr + IPS_REG_ISPR);
  665.       writeb(Isr, ha->mem_ptr + IPS_REG_HISR);
  666.    }
  667.    for (i = 0; i < 240; i++) {
  668.       Cbsp = readb(ha->mem_ptr + IPS_REG_CBSP);
  669.       if ((Cbsp & IPS_BIT_OP) == 0)
  670.          break;
  671.       MDELAY(IPS_ONE_SEC);
  672.    }
  673.    if (i >= 240)
  674.       /* error occurred */
  675.       return (0);
  676.    /* setup CCCR */
  677.    writel(cpu_to_le32(0x1010), ha->mem_ptr + IPS_REG_CCCR);
  678.    /* Enable busmastering */
  679.    writeb(IPS_BIT_EBM, ha->mem_ptr + IPS_REG_SCPR);
  680.    if (ha->revision_id == IPS_REVID_TROMBONE64)
  681.       /* fix for anaconda64 */
  682.       writel(0, ha->mem_ptr + IPS_REG_NDAE);
  683.    /* Enable interrupts */
  684.    writeb(IPS_BIT_EI, ha->mem_ptr + IPS_REG_HISR);
  685.    /* if we get here then everything went OK */
  686.    return (1);
  687. }
  688. /****************************************************************************/
  689. /*                                                                          */
  690. /* Routine Name: ips_init_morpheus                                          */
  691. /*                                                                          */
  692. /* Routine Description:                                                     */
  693. /*                                                                          */
  694. /*   Initialize a morpheus controller                                       */
  695. /*                                                                          */
  696. /****************************************************************************/
  697. static int
  698. ips_init_morpheus(ips_ha_t *ha) {
  699.    u_int32_t Post;
  700.    u_int32_t Config;
  701.    u_int32_t Isr;
  702.    u_int32_t Oimr;
  703.    int       i;
  704.    METHOD_TRACE("ips_init_morpheus", 1);
  705.    /* Wait up to 45 secs for Post */
  706.    for (i = 0; i < 45; i++) {
  707.       Isr = le32_to_cpu(readl(ha->mem_ptr + IPS_REG_I2O_HIR));
  708.       if (Isr & IPS_BIT_I960_MSG0I)
  709.          break;
  710.       MDELAY(IPS_ONE_SEC);
  711.    }
  712.    if (i >= 45) {
  713.       /* error occurred */
  714.       printk(KERN_WARNING "(%s%d) timeout waiting for post.n",
  715.              ips_name, ha->host_num);
  716.       return (0);
  717.    }
  718.    Post = le32_to_cpu(readl(ha->mem_ptr + IPS_REG_I960_MSG0));
  719.    /* Clear the interrupt bit */
  720.    Isr = (u_int32_t) IPS_BIT_I960_MSG0I;
  721.    writel(cpu_to_le32(Isr), ha->mem_ptr + IPS_REG_I2O_HIR);
  722.    if (Post < (IPS_GOOD_POST_STATUS << 8)) {
  723.       printk(KERN_WARNING "(%s%d) reset controller fails (post status %x).n",
  724.              ips_name, ha->host_num, Post);
  725.       return (0);
  726.    }
  727.    /* Wait up to 240 secs for config bytes */
  728.    for (i = 0; i < 240; i++) {
  729.       Isr = le32_to_cpu(readl(ha->mem_ptr + IPS_REG_I2O_HIR));
  730.       if (Isr & IPS_BIT_I960_MSG1I)
  731.          break;
  732.       MDELAY(IPS_ONE_SEC); /* 100 msec */
  733.    }
  734.    if (i >= 240) {
  735.       /* error occurred */
  736.       printk(KERN_WARNING "(%s%d) timeout waiting for config.n",
  737.              ips_name, ha->host_num);
  738.       return (0);
  739.    }
  740.    Config = le32_to_cpu(readl(ha->mem_ptr + IPS_REG_I960_MSG1));
  741.    /* Clear interrupt bit */
  742.    Isr = (u_int32_t) IPS_BIT_I960_MSG1I;
  743.    writel(cpu_to_le32(Isr), ha->mem_ptr + IPS_REG_I2O_HIR);
  744.    /* Turn on the interrupts */
  745.    Oimr = le32_to_cpu(readl(ha->mem_ptr + IPS_REG_I960_OIMR));
  746.    Oimr &= ~0x8;
  747.    writel(cpu_to_le32(Oimr), ha->mem_ptr + IPS_REG_I960_OIMR);
  748.    /* if we get here then everything went OK */
  749.    return (1);
  750. }
  751. /****************************************************************************/
  752. /*                                                                          */
  753. /* Routine Name: ips_reset_copperhead                                       */
  754. /*                                                                          */
  755. /* Routine Description:                                                     */
  756. /*                                                                          */
  757. /*   Reset the controller                                                   */
  758. /*                                                                          */
  759. /****************************************************************************/
  760. static int
  761. ips_reset_copperhead(ips_ha_t *ha) {
  762.    int reset_counter;
  763.    unsigned long cpu_flags;
  764.    METHOD_TRACE("ips_reset_copperhead", 1);
  765.    DEBUG_VAR(1, "(%s%d) ips_reset_copperhead: io addr: %x, irq: %d",
  766.              ips_name, ha->host_num, ha->io_addr, ha->irq);
  767.    IPS_HA_LOCK(cpu_flags);
  768.    reset_counter = 0;
  769.    while (reset_counter < 2) {
  770.       reset_counter++;
  771.       outb(IPS_BIT_RST, ha->io_addr + IPS_REG_SCPR);
  772.       MDELAY(IPS_ONE_SEC);
  773.       outb(0, ha->io_addr + IPS_REG_SCPR);
  774.       MDELAY(IPS_ONE_SEC);
  775.       if ((*ha->func.init)(ha))
  776.          break;
  777.       else if (reset_counter >= 2) {
  778.          IPS_HA_UNLOCK(cpu_flags);
  779.          return (0);
  780.       }
  781.    }
  782.    IPS_HA_UNLOCK(cpu_flags);
  783.    return (1);
  784. }
  785. /****************************************************************************/
  786. /*                                                                          */
  787. /* Routine Name: ips_reset_copperhead_memio                                 */
  788. /*                                                                          */
  789. /* Routine Description:                                                     */
  790. /*                                                                          */
  791. /*   Reset the controller                                                   */
  792. /*                                                                          */
  793. /****************************************************************************/
  794. static int
  795. ips_reset_copperhead_memio(ips_ha_t *ha) {
  796.    int reset_counter;
  797.    unsigned long cpu_flags;
  798.    METHOD_TRACE("ips_reset_copperhead_memio", 1);
  799.    DEBUG_VAR(1, "(%s%d) ips_reset_copperhead_memio: mem addr: %x, irq: %d",
  800.              ips_name, ha->host_num, ha->mem_addr, ha->irq);
  801.    IPS_HA_LOCK(cpu_flags);
  802.    reset_counter = 0;
  803.    while (reset_counter < 2) {
  804.       reset_counter++;
  805.       writeb(IPS_BIT_RST, ha->mem_ptr + IPS_REG_SCPR);
  806.       MDELAY(IPS_ONE_SEC);
  807.       writeb(0, ha->mem_ptr + IPS_REG_SCPR);
  808.       MDELAY(IPS_ONE_SEC);
  809.       if ((*ha->func.init)(ha))
  810.          break;
  811.       else if (reset_counter >= 2) {
  812.          IPS_HA_UNLOCK(cpu_flags);
  813.          return (0);
  814.       }
  815.    }
  816.    IPS_HA_UNLOCK(cpu_flags);
  817.    return (1);
  818. }
  819. /****************************************************************************/
  820. /*                                                                          */
  821. /* Routine Name: ips_reset_morpheus                                         */
  822. /*                                                                          */
  823. /* Routine Description:                                                     */
  824. /*                                                                          */
  825. /*   Reset the controller                                                   */
  826. /*                                                                          */
  827. /****************************************************************************/
  828. static int
  829. ips_reset_morpheus(ips_ha_t *ha) {
  830.    int           reset_counter;
  831.    u_int8_t      junk;
  832.    unsigned long cpu_flags;
  833.    METHOD_TRACE("ips_reset_morpheus", 1);
  834.    DEBUG_VAR(1, "(%s%d) ips_reset_morpheus: mem addr: %x, irq: %d",
  835.              ips_name, ha->host_num, ha->mem_addr, ha->irq);
  836.    IPS_HA_LOCK(cpu_flags);
  837.    reset_counter = 0;
  838.    while (reset_counter < 2) {
  839.       reset_counter++;
  840.       writel(cpu_to_le32(0x80000000), ha->mem_ptr + IPS_REG_I960_IDR);
  841.       /* Delay for 5 sec */
  842.       MDELAY(5 * IPS_ONE_SEC);
  843.       /* Do a PCI config read to wait for adapter */
  844.       pci_read_config_byte(ha->pcidev, 4, &junk);
  845.       if ((*ha->func.init)(ha))
  846.          break;
  847.       else if (reset_counter >= 2) {
  848.          IPS_HA_UNLOCK(cpu_flags);
  849.          return (0);
  850.       }
  851.    }
  852.    IPS_HA_UNLOCK(cpu_flags);
  853.    return (1);
  854. }
  855. /****************************************************************************/
  856. /*                                                                          */
  857. /* Routine Name: ips_statinit                                               */
  858. /*                                                                          */
  859. /* Routine Description:                                                     */
  860. /*                                                                          */
  861. /*   Initialize the status queues on the controller                         */
  862. /*                                                                          */
  863. /****************************************************************************/
  864. static void
  865. ips_statinit(ips_ha_t *ha) {
  866.    u_int32_t phys_status_start;
  867.    METHOD_TRACE("ips_statinit", 1);
  868.    ha->adapt->p_status_start = ha->adapt->status;
  869.    ha->adapt->p_status_end = ha->adapt->status + IPS_MAX_CMDS;
  870.    ha->adapt->p_status_tail = ha->adapt->status;
  871.    phys_status_start = VIRT_TO_BUS(ha->adapt->status);
  872.    outl(cpu_to_le32(phys_status_start), ha->io_addr + IPS_REG_SQSR);
  873.    outl(cpu_to_le32(phys_status_start + IPS_STATUS_Q_SIZE), ha->io_addr + IPS_REG_SQER);
  874.    outl(cpu_to_le32(phys_status_start + IPS_STATUS_SIZE), ha->io_addr + IPS_REG_SQHR);
  875.    outl(cpu_to_le32(phys_status_start), ha->io_addr + IPS_REG_SQTR);
  876.    ha->adapt->hw_status_start = phys_status_start;
  877.    ha->adapt->hw_status_tail = phys_status_start;
  878. }
  879. /****************************************************************************/
  880. /*                                                                          */
  881. /* Routine Name: ips_statinit_memio                                         */
  882. /*                                                                          */
  883. /* Routine Description:                                                     */
  884. /*                                                                          */
  885. /*   Initialize the status queues on the controller                         */
  886. /*                                                                          */
  887. /****************************************************************************/
  888. static void
  889. ips_statinit_memio(ips_ha_t *ha) {
  890.    u_int32_t phys_status_start;
  891.    METHOD_TRACE("ips_statinit_memio", 1);
  892.    ha->adapt->p_status_start = ha->adapt->status;
  893.    ha->adapt->p_status_end = ha->adapt->status + IPS_MAX_CMDS;
  894.    ha->adapt->p_status_tail = ha->adapt->status;
  895.    phys_status_start = VIRT_TO_BUS(ha->adapt->status);
  896.    writel(cpu_to_le32(phys_status_start), ha->mem_ptr + IPS_REG_SQSR);
  897.    writel(cpu_to_le32(phys_status_start + IPS_STATUS_Q_SIZE), ha->mem_ptr + IPS_REG_SQER);
  898.    writel(cpu_to_le32(phys_status_start + IPS_STATUS_SIZE), ha->mem_ptr + IPS_REG_SQHR);
  899.    writel(cpu_to_le32(phys_status_start), ha->mem_ptr + IPS_REG_SQTR);
  900.    ha->adapt->hw_status_start = phys_status_start;
  901.    ha->adapt->hw_status_tail = phys_status_start;
  902. }
  903. /****************************************************************************/
  904. /*                                                                          */
  905. /* Routine Name: ips_statupd_copperhead                                     */
  906. /*                                                                          */
  907. /* Routine Description:                                                     */
  908. /*                                                                          */
  909. /*   Remove an element from the status queue                                */
  910. /*                                                                          */
  911. /****************************************************************************/
  912. static u_int32_t
  913. ips_statupd_copperhead(ips_ha_t *ha) {
  914.    METHOD_TRACE("ips_statupd_copperhead", 1);
  915.    if (ha->adapt->p_status_tail != ha->adapt->p_status_end) {
  916.       ha->adapt->p_status_tail++;
  917.       ha->adapt->hw_status_tail += sizeof(IPS_STATUS);
  918.    } else {
  919.       ha->adapt->p_status_tail = ha->adapt->p_status_start;
  920.       ha->adapt->hw_status_tail = ha->adapt->hw_status_start;
  921.    }
  922.    outl(cpu_to_le32(ha->adapt->hw_status_tail), ha->io_addr + IPS_REG_SQTR);
  923.    return (ha->adapt->p_status_tail->value);
  924. }
  925. /****************************************************************************/
  926. /*                                                                          */
  927. /* Routine Name: ips_statupd_copperhead_memio                               */
  928. /*                                                                          */
  929. /* Routine Description:                                                     */
  930. /*                                                                          */
  931. /*   Remove an element from the status queue                                */
  932. /*                                                                          */
  933. /****************************************************************************/
  934. static u_int32_t
  935. ips_statupd_copperhead_memio(ips_ha_t *ha) {
  936.    METHOD_TRACE("ips_statupd_copperhead_memio", 1);
  937.    if (ha->adapt->p_status_tail != ha->adapt->p_status_end) {
  938.       ha->adapt->p_status_tail++;
  939.       ha->adapt->hw_status_tail += sizeof(IPS_STATUS);
  940.    } else {
  941.       ha->adapt->p_status_tail = ha->adapt->p_status_start;
  942.       ha->adapt->hw_status_tail = ha->adapt->hw_status_start;
  943.    }
  944.    writel(cpu_to_le32(ha->adapt->hw_status_tail), ha->mem_ptr + IPS_REG_SQTR);
  945.    return (ha->adapt->p_status_tail->value);
  946. }
  947. /****************************************************************************/
  948. /*                                                                          */
  949. /* Routine Name: ips_statupd_morpheus                                       */
  950. /*                                                                          */
  951. /* Routine Description:                                                     */
  952. /*                                                                          */
  953. /*   Remove an element from the status queue                                */
  954. /*                                                                          */
  955. /****************************************************************************/
  956. static u_int32_t
  957. ips_statupd_morpheus(ips_ha_t *ha) {
  958.    u_int32_t val;
  959.    METHOD_TRACE("ips_statupd_morpheus", 1);
  960.    val = le32_to_cpu(readl(ha->mem_ptr + IPS_REG_I2O_OUTMSGQ));
  961.    return (val);
  962. }
  963. /****************************************************************************/
  964. /*                                                                          */
  965. /* Routine Name: ips_issue_copperhead                                       */
  966. /*                                                                          */
  967. /* Routine Description:                                                     */
  968. /*                                                                          */
  969. /*   Send a command down to the controller                                  */
  970. /*                                                                          */
  971. /****************************************************************************/
  972. static int
  973. ips_issue_copperhead(ips_ha_t *ha, ips_scb_t *scb) {
  974.    u_int32_t TimeOut;
  975.    u_int32_t val;
  976.    unsigned long cpu_flags;
  977.    METHOD_TRACE("ips_issue_copperhead", 1);
  978.    if (scb->scsi_cmd) {
  979.       DEBUG_VAR(2, "(%s%d) ips_issue: cmd 0x%X id %d (%d %d %d)",
  980.                 ips_name,
  981.                 ha->host_num,
  982.                 scb->cdb[0],
  983.                 scb->cmd.basic_io.command_id,
  984.                 scb->bus,
  985.                 scb->target_id,
  986.                 scb->lun);
  987.    } else {
  988.       DEBUG_VAR(2, KERN_NOTICE "(%s%d) ips_issue: logical cmd id %d",
  989.                 ips_name,
  990.                 ha->host_num,
  991.                 scb->cmd.basic_io.command_id);
  992.    }
  993.    IPS_HA_LOCK(cpu_flags);
  994.    TimeOut = 0;
  995.    while ((val = le32_to_cpu(inl(ha->io_addr + IPS_REG_CCCR))) & IPS_BIT_SEM) {
  996.       udelay(1000);
  997.       if (++TimeOut >= IPS_SEM_TIMEOUT) {
  998.          if (!(val & IPS_BIT_START_STOP))
  999.             break;
  1000.          printk(KERN_WARNING "(%s%d) ips_issue val [0x%x].n",
  1001.                 ips_name, ha->host_num, val);
  1002.          printk(KERN_WARNING "(%s%d) ips_issue semaphore chk timeout.n",
  1003.                 ips_name, ha->host_num);
  1004.          IPS_HA_UNLOCK(cpu_flags);
  1005.          return (IPS_FAILURE);
  1006.       } /* end if */
  1007.    } /* end while */
  1008.    outl(cpu_to_le32(scb->scb_busaddr), ha->io_addr + IPS_REG_CCSAR);
  1009.    outw(cpu_to_le32(IPS_BIT_START_CMD), ha->io_addr + IPS_REG_CCCR);
  1010.    IPS_HA_UNLOCK(cpu_flags);
  1011.    return (IPS_SUCCESS);
  1012. }
  1013. /****************************************************************************/
  1014. /*                                                                          */
  1015. /* Routine Name: ips_issue_copperhead_memio                                 */
  1016. /*                                                                          */
  1017. /* Routine Description:                                                     */
  1018. /*                                                                          */
  1019. /*   Send a command down to the controller                                  */
  1020. /*                                                                          */
  1021. /****************************************************************************/
  1022. static int
  1023. ips_issue_copperhead_memio(ips_ha_t *ha, ips_scb_t *scb) {
  1024.    u_int32_t     TimeOut;
  1025.    u_int32_t     val;
  1026.    unsigned long cpu_flags;
  1027.    METHOD_TRACE("ips_issue_copperhead_memio", 1);
  1028.    if (scb->scsi_cmd) {
  1029.       DEBUG_VAR(2, "(%s%d) ips_issue: cmd 0x%X id %d (%d %d %d)",
  1030.                 ips_name,
  1031.                 ha->host_num,
  1032.                 scb->cdb[0],
  1033.                 scb->cmd.basic_io.command_id,
  1034.                 scb->bus,
  1035.                 scb->target_id,
  1036.                 scb->lun);
  1037.    } else {
  1038.       DEBUG_VAR(2, "(%s%d) ips_issue: logical cmd id %d",
  1039.                 ips_name,
  1040.                 ha->host_num,
  1041.                 scb->cmd.basic_io.command_id);
  1042.    }
  1043.    IPS_HA_LOCK(cpu_flags);
  1044.    TimeOut = 0;
  1045.    while ((val = le32_to_cpu(readl(ha->mem_ptr + IPS_REG_CCCR))) & IPS_BIT_SEM) {
  1046.       udelay(1000);
  1047.       if (++TimeOut >= IPS_SEM_TIMEOUT) {
  1048.          if (!(val & IPS_BIT_START_STOP))
  1049.             break;
  1050.          printk(KERN_WARNING "(%s%d) ips_issue val [0x%x].n",
  1051.                 ips_name, ha->host_num, val);
  1052.          printk(KERN_WARNING "(%s%d) ips_issue semaphore chk timeout.n",
  1053.                 ips_name, ha->host_num);
  1054.          IPS_HA_UNLOCK(cpu_flags);
  1055.          return (IPS_FAILURE);
  1056.       } /* end if */
  1057.    } /* end while */
  1058.    writel(cpu_to_le32(scb->scb_busaddr), ha->mem_ptr + IPS_REG_CCSAR);
  1059.    writel(cpu_to_le32(IPS_BIT_START_CMD), ha->mem_ptr + IPS_REG_CCCR);
  1060.    IPS_HA_UNLOCK(cpu_flags);
  1061.    return (IPS_SUCCESS);
  1062. }
  1063. /****************************************************************************/
  1064. /*                                                                          */
  1065. /* Routine Name: ips_issue_i2o                                              */
  1066. /*                                                                          */
  1067. /* Routine Description:                                                     */
  1068. /*                                                                          */
  1069. /*   Send a command down to the controller                                  */
  1070. /*                                                                          */
  1071. /****************************************************************************/
  1072. static int
  1073. ips_issue_i2o(ips_ha_t *ha, ips_scb_t *scb) {
  1074.    unsigned long cpu_flags;
  1075.    METHOD_TRACE("ips_issue_i2o", 1);
  1076.    if (scb->scsi_cmd) {
  1077.       DEBUG_VAR(2, "(%s%d) ips_issue: cmd 0x%X id %d (%d %d %d)",
  1078.                 ips_name,
  1079.                 ha->host_num,
  1080.                 scb->cdb[0],
  1081.                 scb->cmd.basic_io.command_id,
  1082.                 scb->bus,
  1083.                 scb->target_id,
  1084.                 scb->lun);
  1085.    } else {
  1086.       DEBUG_VAR(2, "(%s%d) ips_issue: logical cmd id %d",
  1087.                 ips_name,
  1088.                 ha->host_num,
  1089.                 scb->cmd.basic_io.command_id);
  1090.    }
  1091.    IPS_HA_LOCK(cpu_flags);
  1092.    outl(cpu_to_le32(scb->scb_busaddr), ha->io_addr + IPS_REG_I2O_INMSGQ);
  1093.    IPS_HA_UNLOCK(cpu_flags);
  1094.    return (IPS_SUCCESS);
  1095. }
  1096. /****************************************************************************/
  1097. /*                                                                          */
  1098. /* Routine Name: ips_issue_i2o_memio                                        */
  1099. /*                                                                          */
  1100. /* Routine Description:                                                     */
  1101. /*                                                                          */
  1102. /*   Send a command down to the controller                                  */
  1103. /*                                                                          */
  1104. /****************************************************************************/
  1105. static int
  1106. ips_issue_i2o_memio(ips_ha_t *ha, ips_scb_t *scb) {
  1107.    unsigned long cpu_flags;
  1108.    METHOD_TRACE("ips_issue_i2o_memio", 1);
  1109.    if (scb->scsi_cmd) {
  1110.       DEBUG_VAR(2, "(%s%d) ips_issue: cmd 0x%X id %d (%d %d %d)",
  1111.                 ips_name,
  1112.                 ha->host_num,
  1113.                 scb->cdb[0],
  1114.                 scb->cmd.basic_io.command_id,
  1115.                 scb->bus,
  1116.                 scb->target_id,
  1117.                 scb->lun);
  1118.    } else {
  1119.       DEBUG_VAR(2, "(%s%d) ips_issue: logical cmd id %d",
  1120.                 ips_name,
  1121.                 ha->host_num,
  1122.                 scb->cmd.basic_io.command_id);
  1123.    }
  1124.    IPS_HA_LOCK(cpu_flags);
  1125.    writel(cpu_to_le32(scb->scb_busaddr), ha->mem_ptr + IPS_REG_I2O_INMSGQ);
  1126.    IPS_HA_UNLOCK(cpu_flags);
  1127.    return (IPS_SUCCESS);
  1128. }
  1129. /****************************************************************************/
  1130. /*                                                                          */
  1131. /* Routine Name: ips_isintr_copperhead                                      */
  1132. /*                                                                          */
  1133. /* Routine Description:                                                     */
  1134. /*                                                                          */
  1135. /*   Test to see if an interrupt is for us                                  */
  1136. /*                                                                          */
  1137. /****************************************************************************/
  1138. static int
  1139. ips_isintr_copperhead(ips_ha_t *ha) {
  1140.    u_int8_t Isr;
  1141.    METHOD_TRACE("ips_isintr_copperhead", 2);
  1142.    Isr = inb(ha->io_addr + IPS_REG_HISR);
  1143.    if (Isr == 0xFF)
  1144.       /* ?!?! Nothing really there */
  1145.       return (0);
  1146.    if (Isr & IPS_BIT_SCE)
  1147.       return (1);
  1148.    else if (Isr & (IPS_BIT_SQO | IPS_BIT_GHI)) {
  1149.       /* status queue overflow or GHI */
  1150.       /* just clear the interrupt */
  1151.       outb(Isr, ha->io_addr + IPS_REG_HISR);
  1152.    }
  1153.    return (0);
  1154. }
  1155. /****************************************************************************/
  1156. /*                                                                          */
  1157. /* Routine Name: ips_isintr_copperhead_memio                                */
  1158. /*                                                                          */
  1159. /* Routine Description:                                                     */
  1160. /*                                                                          */
  1161. /*   Test to see if an interrupt is for us                                  */
  1162. /*                                                                          */
  1163. /****************************************************************************/
  1164. static int
  1165. ips_isintr_copperhead_memio(ips_ha_t *ha) {
  1166.    u_int8_t Isr;
  1167.    METHOD_TRACE("ips_isintr_memio", 2);
  1168.    Isr = readb(ha->mem_ptr + IPS_REG_HISR);
  1169.    if (Isr == 0xFF)
  1170.       /* ?!?! Nothing really there */
  1171.       return (0);
  1172.    if (Isr & IPS_BIT_SCE)
  1173.       return (1);
  1174.    else if (Isr & (IPS_BIT_SQO | IPS_BIT_GHI)) {
  1175.       /* status queue overflow or GHI */
  1176.       /* just clear the interrupt */
  1177.       writeb(Isr, ha->mem_ptr + IPS_REG_HISR);
  1178.    }
  1179.    return (0);
  1180. }
  1181. /****************************************************************************/
  1182. /*                                                                          */
  1183. /* Routine Name: ips_isintr_morpheus                                        */
  1184. /*                                                                          */
  1185. /* Routine Description:                                                     */
  1186. /*                                                                          */
  1187. /*   Test to see if an interrupt is for us                                  */
  1188. /*                                                                          */
  1189. /****************************************************************************/
  1190. static int
  1191. ips_isintr_morpheus(ips_ha_t *ha) {
  1192.    u_int32_t Isr;
  1193.    METHOD_TRACE("ips_isintr_morpheus", 2);
  1194.    Isr = le32_to_cpu(readl(ha->mem_ptr + IPS_REG_I2O_HIR));
  1195.    if (Isr & IPS_BIT_I2O_OPQI)
  1196.       return (1);
  1197.    else
  1198.       return (0);
  1199. }
  1200. /****************************************************************************/
  1201. /*                                                                          */
  1202. /* Routine Name: ips_wait                                                   */
  1203. /*                                                                          */
  1204. /* Routine Description:                                                     */
  1205. /*                                                                          */
  1206. /*   Wait for a command to complete                                         */
  1207. /*                                                                          */
  1208. /****************************************************************************/
  1209. static int
  1210. ips_wait(ips_ha_t *ha, int time, int intr) {
  1211.    int        ret;
  1212.    u_int8_t   done;
  1213.    METHOD_TRACE("ips_wait", 1);
  1214.    ret = IPS_FAILURE;
  1215.    done = FALSE;
  1216.    time *= IPS_ONE_SEC; /* convert seconds to milliseconds */
  1217.    while ((time > 0) && (!done)) {
  1218.       if (intr == IPS_INTR_ON) {
  1219.          if (ha->waitflag == FALSE) {
  1220.             ret = IPS_SUCCESS;
  1221.             done = TRUE;
  1222.             break;
  1223.          }
  1224.       } else if (intr == IPS_INTR_IORL) {
  1225.          if (ha->waitflag == FALSE) {
  1226.             /*
  1227.              * controller generated an interrupt to
  1228.              * acknowledge completion of the command
  1229.              * and ips_intr() has serviced the interrupt.
  1230.              */
  1231.             ret = IPS_SUCCESS;
  1232.             done = TRUE;
  1233.             break;
  1234.          }
  1235.          /*
  1236.           * NOTE: we already have the io_request_lock so
  1237.           * even if we get an interrupt it won't get serviced
  1238.           * until after we finish.
  1239.           */
  1240.          while (test_and_set_bit(IPS_IN_INTR, &ha->flags))
  1241.             udelay(1000);
  1242.          (*ha->func.intr)(ha);
  1243.          clear_bit(IPS_IN_INTR, &ha->flags);
  1244.       } else if (intr == IPS_INTR_HAL) {
  1245.          if (ha->waitflag == FALSE) {
  1246.             /*
  1247.              * controller generated an interrupt to
  1248.              * acknowledge completion of the command
  1249.              * and ips_intr() has serviced the interrupt.
  1250.              */
  1251.             ret = IPS_SUCCESS;
  1252.             done = TRUE;
  1253.             break;
  1254.          }
  1255.          /*
  1256.           * NOTE: since we were not called with the iorequest lock
  1257.           * we must obtain it before we can call the interrupt handler.
  1258.           * We were called under the HA lock so we can assume that interrupts
  1259.           * are masked.
  1260.           */
  1261.          spin_lock(&io_request_lock);
  1262.          while (test_and_set_bit(IPS_IN_INTR, &ha->flags))
  1263.             udelay(1000);
  1264.          (*ha->func.intr)(ha);
  1265.          clear_bit(IPS_IN_INTR, &ha->flags);
  1266.          spin_unlock(&io_request_lock);
  1267.       }
  1268.       udelay(1000); /* 1 milisecond */
  1269.       time--;
  1270.    }
  1271.    return (ret);
  1272. }
  1273. /****************************************************************************/
  1274. /*                                                                          */
  1275. /* Routine Name: ips_write_driver_status                                    */
  1276. /*                                                                          */
  1277. /* Routine Description:                                                     */
  1278. /*                                                                          */
  1279. /*   Write OS/Driver version to Page 5 of the nvram on the controller       */
  1280. /*                                                                          */
  1281. /****************************************************************************/
  1282. static int
  1283. ips_write_driver_status(ips_ha_t *ha, int intr) {
  1284.    METHOD_TRACE("ips_write_driver_status", 1);
  1285.    if (!ips_readwrite_page5(ha, FALSE, intr)) {
  1286.       printk(KERN_WARNING "(%s%d) unable to read NVRAM page 5.n",
  1287.              ips_name, ha->host_num);
  1288.       return (0);
  1289.    }
  1290.    /* check to make sure the page has a valid */
  1291.    /* signature */
  1292.    if (le32_to_cpu(ha->nvram->signature) != IPS_NVRAM_P5_SIG) {
  1293.       DEBUG_VAR(1, "(%s%d) NVRAM page 5 has an invalid signature: %X.",
  1294.                 ips_name, ha->host_num, ha->nvram->signature);
  1295.       return (1);
  1296.    }
  1297.    DEBUG_VAR(2, "(%s%d) Ad Type: %d, Ad Slot: %d, BIOS: %c%c%c%c %c%c%c%c.",
  1298.              ips_name, ha->host_num, le16_to_cpu(ha->nvram->adapter_type),
  1299.              ha->nvram->adapter_slot,
  1300.              ha->nvram->bios_high[0], ha->nvram->bios_high[1],
  1301.              ha->nvram->bios_high[2], ha->nvram->bios_high[3],
  1302.              ha->nvram->bios_low[0], ha->nvram->bios_low[1],
  1303.              ha->nvram->bios_low[2], ha->nvram->bios_low[3]);
  1304.    ips_get_bios_version(ha, intr);
  1305.    /* change values (as needed) */
  1306.    ha->nvram->operating_system = IPS_OS_LINUX;
  1307.    ha->nvram->adapter_type = ha->ad_type;
  1308.    strncpy((char *) ha->nvram->driver_high, IPS_VERSION_HIGH, 4);
  1309.    strncpy((char *) ha->nvram->driver_low, IPS_VERSION_LOW, 4);
  1310.    strncpy((char *) ha->nvram->bios_high, ha->bios_version, 4);
  1311.    strncpy((char *) ha->nvram->bios_low, ha->bios_version + 4, 4);
  1312.    /* now update the page */
  1313.    if (!ips_readwrite_page5(ha, TRUE, intr)) {
  1314.       printk(KERN_WARNING "(%s%d) unable to write NVRAM page 5.n",
  1315.              ips_name, ha->host_num);
  1316.       return (0);
  1317.    }
  1318.    /* IF NVRAM Page 5 is OK, Use it for Slot Number Info Because Linux Doesn't Do Slots */
  1319.    ha->slot_num = ha->nvram->adapter_slot;
  1320.    return (1);
  1321. }
  1322. /****************************************************************************/
  1323. /*                                                                          */
  1324. /* Routine Name: ips_read_adapter_status                                    */
  1325. /*                                                                          */
  1326. /* Routine Description:                                                     */
  1327. /*                                                                          */
  1328. /*   Do an Inquiry command to the adapter                                   */
  1329. /*                                                                          */
  1330. /****************************************************************************/
  1331. static int
  1332. ips_read_adapter_status(ips_ha_t *ha, int intr) {
  1333.    ips_scb_t *scb;
  1334.    int        ret;
  1335.    METHOD_TRACE("ips_read_adapter_status", 1);
  1336.    scb = &ha->scbs[ha->max_cmds-1];
  1337.    ips_init_scb(ha, scb);
  1338.    scb->timeout = ips_cmd_timeout;
  1339.    scb->cdb[0] = IPS_CMD_ENQUIRY;
  1340.    scb->cmd.basic_io.op_code = IPS_CMD_ENQUIRY;
  1341.    scb->cmd.basic_io.command_id = IPS_COMMAND_ID(ha, scb);
  1342.    scb->cmd.basic_io.sg_count = 0;
  1343.    scb->cmd.basic_io.sg_addr = cpu_to_le32(VIRT_TO_BUS(ha->enq));
  1344.    scb->cmd.basic_io.lba = 0;
  1345.    scb->cmd.basic_io.sector_count = 0;
  1346.    scb->cmd.basic_io.log_drv = 0;
  1347.    scb->cmd.basic_io.reserved = 0;
  1348.    /* send command */
  1349.    if (((ret = ips_send_wait(ha, scb, ips_cmd_timeout, intr)) == IPS_FAILURE) ||
  1350.        (ret == IPS_SUCCESS_IMM) ||
  1351.        ((scb->basic_status & IPS_GSC_STATUS_MASK) > 1))
  1352.       return (0);
  1353.    return (1);
  1354. }
  1355. /****************************************************************************/
  1356. /*                                                                          */
  1357. /* Routine Name: ips_read_subsystem_parameters                              */
  1358. /*                                                                          */
  1359. /* Routine Description:                                                     */
  1360. /*                                                                          */
  1361. /*   Read subsystem parameters from the adapter                             */
  1362. /*                                                                          */
  1363. /****************************************************************************/
  1364. static int
  1365. ips_read_subsystem_parameters(ips_ha_t *ha, int intr) {
  1366.    ips_scb_t *scb;
  1367.    int        ret;
  1368.    METHOD_TRACE("ips_read_subsystem_parameters", 1);
  1369.    scb = &ha->scbs[ha->max_cmds-1];
  1370.    ips_init_scb(ha, scb);
  1371.    scb->timeout = ips_cmd_timeout;
  1372.    scb->cdb[0] = IPS_CMD_GET_SUBSYS;
  1373.    scb->cmd.basic_io.op_code = IPS_CMD_GET_SUBSYS;
  1374.    scb->cmd.basic_io.command_id = IPS_COMMAND_ID(ha, scb);
  1375.    scb->cmd.basic_io.sg_count = 0;
  1376.    scb->cmd.basic_io.sg_addr = cpu_to_le32(VIRT_TO_BUS(ha->subsys));
  1377.    scb->cmd.basic_io.lba = 0;
  1378.    scb->cmd.basic_io.sector_count = 0;
  1379.    scb->cmd.basic_io.log_drv = 0;
  1380.    scb->cmd.basic_io.reserved = 0;
  1381.    /* send command */
  1382.    if (((ret = ips_send_wait(ha, scb, ips_cmd_timeout, intr)) == IPS_FAILURE) ||
  1383.        (ret == IPS_SUCCESS_IMM) ||
  1384.        ((scb->basic_status & IPS_GSC_STATUS_MASK) > 1))
  1385.       return (0);
  1386.    return (1);
  1387. }
  1388. /****************************************************************************/
  1389. /*                                                                          */
  1390. /* Routine Name: ips_read_config                                            */
  1391. /*                                                                          */
  1392. /* Routine Description:                                                     */
  1393. /*                                                                          */
  1394. /*   Read the configuration on the adapter                                  */
  1395. /*                                                                          */
  1396. /****************************************************************************/
  1397. static int
  1398. ips_read_config(ips_ha_t *ha, int intr) {
  1399.    ips_scb_t *scb;
  1400.    int        i;
  1401.    int        ret;
  1402.    METHOD_TRACE("ips_read_config", 1);
  1403.    /* set defaults for initiator IDs */
  1404.    for (i = 0; i < 4; i++)
  1405.       ha->conf->init_id[i] = 7;
  1406.    scb = &ha->scbs[ha->max_cmds-1];
  1407.    ips_init_scb(ha, scb);
  1408.    scb->timeout = ips_cmd_timeout;
  1409.    scb->cdb[0] = IPS_CMD_READ_CONF;
  1410.    scb->cmd.basic_io.op_code = IPS_CMD_READ_CONF;
  1411.    scb->cmd.basic_io.command_id = IPS_COMMAND_ID(ha, scb);
  1412.    scb->cmd.basic_io.sg_addr = cpu_to_le32(VIRT_TO_BUS(ha->conf));
  1413.    /* send command */
  1414.    if (((ret = ips_send_wait(ha, scb, ips_cmd_timeout, intr)) == IPS_FAILURE) ||
  1415.        (ret == IPS_SUCCESS_IMM) ||
  1416.        ((scb->basic_status & IPS_GSC_STATUS_MASK) > 1)) {
  1417.       memset(ha->conf, 0, sizeof(IPS_CONF));
  1418.       /* reset initiator IDs */
  1419.       for (i = 0; i < 4; i++)
  1420.          ha->conf->init_id[i] = 7;
  1421.       return (0);
  1422.    }
  1423.    return (1);
  1424. }
  1425. /****************************************************************************/
  1426. /*                                                                          */
  1427. /* Routine Name: ips_readwrite_page5                                        */
  1428. /*                                                                          */
  1429. /* Routine Description:                                                     */
  1430. /*                                                                          */
  1431. /*   Read nvram page 5 from the adapter                                     */
  1432. /*                                                                          */
  1433. /****************************************************************************/
  1434. static int
  1435. ips_readwrite_page5(ips_ha_t *ha, int write, int intr) {
  1436.    ips_scb_t *scb;
  1437.    int        ret;
  1438.    METHOD_TRACE("ips_readwrite_page5", 1);
  1439.    scb = &ha->scbs[ha->max_cmds-1];
  1440.    ips_init_scb(ha, scb);
  1441.    scb->timeout = ips_cmd_timeout;
  1442.    scb->cdb[0] = IPS_CMD_RW_NVRAM_PAGE;
  1443.    scb->cmd.nvram.op_code = IPS_CMD_RW_NVRAM_PAGE;
  1444.    scb->cmd.nvram.command_id = IPS_COMMAND_ID(ha, scb);
  1445.    scb->cmd.nvram.page = 5;
  1446.    scb->cmd.nvram.write = write;
  1447.    scb->cmd.nvram.buffer_addr = cpu_to_le32(VIRT_TO_BUS(ha->nvram));
  1448.    scb->cmd.nvram.reserved = 0;
  1449.    scb->cmd.nvram.reserved2 = 0;
  1450.    /* issue the command */
  1451.    if (((ret = ips_send_wait(ha, scb, ips_cmd_timeout, intr)) == IPS_FAILURE) ||
  1452.        (ret == IPS_SUCCESS_IMM) ||
  1453.        ((scb->basic_status & IPS_GSC_STATUS_MASK) > 1)) {
  1454.       memset(ha->nvram, 0, sizeof(IPS_NVRAM_P5));
  1455.       return (0);
  1456.    }
  1457.    return (1);
  1458. }
  1459. /****************************************************************************/
  1460. /*                                                                          */
  1461. /* Routine Name: ips_clear_adapter                                          */
  1462. /*                                                                          */
  1463. /* Routine Description:                                                     */
  1464. /*                                                                          */
  1465. /*   Clear the stripe lock tables                                           */
  1466. /*                                                                          */
  1467. /****************************************************************************/
  1468. static int
  1469. ips_clear_adapter(ips_ha_t *ha, int intr) {
  1470.    ips_scb_t *scb;
  1471.    int        ret;
  1472.    METHOD_TRACE("ips_clear_adapter", 1);
  1473.    scb = &ha->scbs[ha->max_cmds-1];
  1474.    ips_init_scb(ha, scb);
  1475.    scb->timeout = ips_reset_timeout;
  1476.    scb->cdb[0] = IPS_CMD_CONFIG_SYNC;
  1477.    scb->cmd.config_sync.op_code = IPS_CMD_CONFIG_SYNC;
  1478.    scb->cmd.config_sync.command_id = IPS_COMMAND_ID(ha, scb);
  1479.    scb->cmd.config_sync.channel = 0;
  1480.    scb->cmd.config_sync.source_target = IPS_POCL;
  1481.    scb->cmd.config_sync.reserved = 0;
  1482.    scb->cmd.config_sync.reserved2 = 0;
  1483.    scb->cmd.config_sync.reserved3 = 0;
  1484.    /* issue command */
  1485.    if (((ret = ips_send_wait(ha, scb, ips_reset_timeout, intr)) == IPS_FAILURE) ||
  1486.        (ret == IPS_SUCCESS_IMM) ||
  1487.        ((scb->basic_status & IPS_GSC_STATUS_MASK) > 1))
  1488.       return (0);
  1489.    /* send unlock stripe command */
  1490.    ips_init_scb(ha, scb);
  1491.    scb->cdb[0] = IPS_CMD_ERROR_TABLE;
  1492.    scb->timeout = ips_reset_timeout;
  1493.    scb->cmd.unlock_stripe.op_code = IPS_CMD_ERROR_TABLE;
  1494.    scb->cmd.unlock_stripe.command_id = IPS_COMMAND_ID(ha, scb);
  1495.    scb->cmd.unlock_stripe.log_drv = 0;
  1496.    scb->cmd.unlock_stripe.control = IPS_CSL;
  1497.    scb->cmd.unlock_stripe.reserved = 0;
  1498.    scb->cmd.unlock_stripe.reserved2 = 0;
  1499.    scb->cmd.unlock_stripe.reserved3 = 0;
  1500.    /* issue command */
  1501.    if (((ret = ips_send_wait(ha, scb, ips_cmd_timeout, intr)) == IPS_FAILURE) ||
  1502.        (ret == IPS_SUCCESS_IMM) ||
  1503.        ((scb->basic_status & IPS_GSC_STATUS_MASK) > 1))
  1504.       return (0);
  1505.    return (1);
  1506. }
  1507. /****************************************************************************/
  1508. /*                                                                          */
  1509. /* Routine Name: ips_ffdc_reset                                             */
  1510. /*                                                                          */
  1511. /* Routine Description:                                                     */
  1512. /*                                                                          */
  1513. /*   FFDC: write reset info                                                 */
  1514. /*                                                                          */
  1515. /****************************************************************************/
  1516. static void
  1517. ips_ffdc_reset(ips_ha_t *ha, int intr) {
  1518.    ips_scb_t *scb;
  1519.    METHOD_TRACE("ips_ffdc_reset", 1);
  1520.    scb = &ha->scbs[ha->max_cmds-1];
  1521.    ips_init_scb(ha, scb);
  1522.    scb->timeout = ips_cmd_timeout;
  1523.    scb->cdb[0] = IPS_CMD_FFDC;
  1524.    scb->cmd.ffdc.op_code = IPS_CMD_FFDC;
  1525.    scb->cmd.ffdc.command_id = IPS_COMMAND_ID(ha, scb);
  1526.    scb->cmd.ffdc.reset_count = ha->reset_count;
  1527.    scb->cmd.ffdc.reset_type = 0x80;
  1528.    /* convert time to what the card wants */
  1529.    ips_fix_ffdc_time(ha, scb, ha->last_ffdc);
  1530.    /* issue command */
  1531.    ips_send_wait(ha, scb, ips_cmd_timeout, intr);
  1532. }
  1533. /****************************************************************************/
  1534. /*                                                                          */
  1535. /* Routine Name: ips_ffdc_time                                              */
  1536. /*                                                                          */
  1537. /* Routine Description:                                                     */
  1538. /*                                                                          */
  1539. /*   FFDC: write time info                                                  */
  1540. /*                                                                          */
  1541. /****************************************************************************/
  1542. static void
  1543. ips_ffdc_time(ips_ha_t *ha, int intr) {
  1544.    ips_scb_t *scb;
  1545.    METHOD_TRACE("ips_ffdc_time", 1);
  1546.    DEBUG_VAR(1, "(%s%d) Sending time update.",
  1547.              ips_name, ha->host_num);
  1548.    scb = &ha->scbs[ha->max_cmds-1];
  1549.    ips_init_scb(ha, scb);
  1550.    scb->timeout = ips_cmd_timeout;
  1551.    scb->cdb[0] = IPS_CMD_FFDC;
  1552.    scb->cmd.ffdc.op_code = IPS_CMD_FFDC;
  1553.    scb->cmd.ffdc.command_id = IPS_COMMAND_ID(ha, scb);
  1554.    scb->cmd.ffdc.reset_count = 0;
  1555.    scb->cmd.ffdc.reset_type = 0x80;
  1556.    /* convert time to what the card wants */
  1557.    ips_fix_ffdc_time(ha, scb, ha->last_ffdc);
  1558.    /* issue command */
  1559.    ips_send_wait(ha, scb, ips_cmd_timeout, intr);
  1560. }
  1561. /****************************************************************************/
  1562. /*                                                                          */
  1563. /* Routine Name: ips_fix_ffdc_time                                          */
  1564. /*                                                                          */
  1565. /* Routine Description:                                                     */
  1566. /*   Adjust time_t to what the card wants                                   */
  1567. /*                                                                          */
  1568. /****************************************************************************/
  1569. static void
  1570. ips_fix_ffdc_time(ips_ha_t *ha, ips_scb_t *scb, time_t current_time) {
  1571.    long days;
  1572.    long rem;
  1573.    int  i;
  1574.    int  year;
  1575.    int  yleap;
  1576.    int  year_lengths[2] = { IPS_DAYS_NORMAL_YEAR, IPS_DAYS_LEAP_YEAR };
  1577.    int  month_lengths[12][2] = { {31, 31},
  1578.                                  {28, 29},
  1579.                                  {31, 31},
  1580.                                  {30, 30},
  1581.                                  {31, 31},
  1582.                                  {30, 30},
  1583.                                  {31, 31},
  1584.                                  {31, 31},
  1585.                                  {30, 30},
  1586.                                  {31, 31},
  1587.                                  {30, 30},
  1588.                                  {31, 31} };
  1589.    METHOD_TRACE("ips_fix_ffdc_time", 1);
  1590.    days = current_time / IPS_SECS_DAY;
  1591.    rem = current_time % IPS_SECS_DAY;
  1592.    scb->cmd.ffdc.hour = (rem / IPS_SECS_HOUR);
  1593.    rem = rem % IPS_SECS_HOUR;
  1594.    scb->cmd.ffdc.minute = (rem / IPS_SECS_MIN);
  1595.    scb->cmd.ffdc.second = (rem % IPS_SECS_MIN);
  1596.    year = IPS_EPOCH_YEAR;
  1597.    while (days < 0 || days >= year_lengths[yleap = IPS_IS_LEAP_YEAR(year)]) {
  1598.       int newy;
  1599.       newy = year + (days / IPS_DAYS_NORMAL_YEAR);
  1600.       if (days < 0)
  1601.          --newy;
  1602.       days -= (newy - year) * IPS_DAYS_NORMAL_YEAR +
  1603.          IPS_NUM_LEAP_YEARS_THROUGH(newy - 1) -
  1604.          IPS_NUM_LEAP_YEARS_THROUGH(year - 1);
  1605.       year = newy;
  1606.    }
  1607.    scb->cmd.ffdc.yearH = year / 100;
  1608.    scb->cmd.ffdc.yearL = year % 100;
  1609.    for (i = 0; days >= month_lengths[i][yleap]; ++i)
  1610.       days -= month_lengths[i][yleap];
  1611.    scb->cmd.ffdc.month = i + 1;
  1612.    scb->cmd.ffdc.day = days + 1;
  1613. }
  1614. /****************************************************************************
  1615.  * BIOS Flash Routines                                                      *
  1616.  ****************************************************************************/
  1617. /****************************************************************************/
  1618. /*                                                                          */
  1619. /* Routine Name: ips_erase_bios                                             */
  1620. /*                                                                          */
  1621. /* Routine Description:                                                     */
  1622. /*   Erase the BIOS on the adapter                                          */
  1623. /*                                                                          */
  1624. /****************************************************************************/
  1625. static int
  1626. ips_erase_bios(ips_ha_t *ha) {
  1627.    int      timeout;
  1628.    u_int8_t status=0;
  1629.    METHOD_TRACE("ips_erase_bios", 1);
  1630.    status = 0;
  1631.    /* Clear the status register */
  1632.    outl(0, ha->io_addr + IPS_REG_FLAP);
  1633.    if (ha->revision_id == IPS_REVID_TROMBONE64)
  1634.       udelay(5); /* 5 us */
  1635.    outb(0x50, ha->io_addr + IPS_REG_FLDP);
  1636.    if (ha->revision_id == IPS_REVID_TROMBONE64)
  1637.       udelay(5); /* 5 us */
  1638.    /* Erase Setup */
  1639.    outb(0x20, ha->io_addr + IPS_REG_FLDP);
  1640.    if (ha->revision_id == IPS_REVID_TROMBONE64)
  1641.       udelay(5); /* 5 us */
  1642.    /* Erase Confirm */
  1643.    outb(0xD0, ha->io_addr + IPS_REG_FLDP);
  1644.    if (ha->revision_id == IPS_REVID_TROMBONE64)
  1645.       udelay(5); /* 5 us */
  1646.    /* Erase Status */
  1647.    outb(0x70, ha->io_addr + IPS_REG_FLDP);
  1648.    if (ha->revision_id == IPS_REVID_TROMBONE64)
  1649.       udelay(5); /* 5 us */
  1650.    timeout = 80000; /* 80 seconds */
  1651.    while (timeout > 0) {
  1652.       if (ha->revision_id == IPS_REVID_TROMBONE64) {
  1653.          outl(0, ha->io_addr + IPS_REG_FLAP);
  1654.          udelay(5); /* 5 us */
  1655.       }
  1656.       status = inb(ha->io_addr + IPS_REG_FLDP);
  1657.       if (status & 0x80)
  1658.          break;
  1659.       MDELAY(1);
  1660.       timeout--;
  1661.    }
  1662.    /* check for timeout */
  1663.    if (timeout <= 0) {
  1664.       /* timeout */
  1665.       /* try to suspend the erase */
  1666.       outb(0xB0, ha->io_addr + IPS_REG_FLDP);
  1667.       if (ha->revision_id == IPS_REVID_TROMBONE64)
  1668.          udelay(5); /* 5 us */
  1669.       /* wait for 10 seconds */
  1670.       timeout = 10000;
  1671.       while (timeout > 0) {
  1672.          if (ha->revision_id == IPS_REVID_TROMBONE64) {
  1673.             outl(0, ha->io_addr + IPS_REG_FLAP);
  1674.             udelay(5); /* 5 us */
  1675.          }
  1676.          status = inb(ha->io_addr + IPS_REG_FLDP);
  1677.          if (status & 0xC0)
  1678.             break;
  1679.          MDELAY(1);
  1680.          timeout--;
  1681.       }
  1682.       return (1);
  1683.    }
  1684.    /* check for valid VPP */
  1685.    if (status & 0x08)
  1686.       /* VPP failure */
  1687.       return (1);
  1688.    /* check for succesful flash */
  1689.    if (status & 0x30)
  1690.       /* sequence error */
  1691.       return (1);
  1692.    /* Otherwise, we were successful */
  1693.    /* clear status */
  1694.    outb(0x50, ha->io_addr + IPS_REG_FLDP);
  1695.    if (ha->revision_id == IPS_REVID_TROMBONE64)
  1696.       udelay(5); /* 5 us */
  1697.    /* enable reads */
  1698.    outb(0xFF, ha->io_addr + IPS_REG_FLDP);
  1699.    if (ha->revision_id == IPS_REVID_TROMBONE64)
  1700.       udelay(5); /* 5 us */
  1701.    return (0);
  1702. }
  1703. /****************************************************************************/
  1704. /*                                                                          */
  1705. /* Routine Name: ips_erase_bios_memio                                       */
  1706. /*                                                                          */
  1707. /* Routine Description:                                                     */
  1708. /*   Erase the BIOS on the adapter                                          */
  1709. /*                                                                          */
  1710. /****************************************************************************/
  1711. static int
  1712. ips_erase_bios_memio(ips_ha_t *ha) {
  1713.    int      timeout;
  1714.    u_int8_t status;
  1715.    METHOD_TRACE("ips_erase_bios_memio", 1);
  1716.    status = 0;
  1717.    /* Clear the status register */
  1718.    writel(0, ha->mem_ptr + IPS_REG_FLAP);
  1719.    if (ha->revision_id == IPS_REVID_TROMBONE64)
  1720.       udelay(5); /* 5 us */
  1721.    writeb(0x50, ha->mem_ptr + IPS_REG_FLDP);
  1722.    if (ha->revision_id == IPS_REVID_TROMBONE64)
  1723.       udelay(5); /* 5 us */
  1724.    /* Erase Setup */
  1725.    writeb(0x20, ha->mem_ptr + IPS_REG_FLDP);
  1726.    if (ha->revision_id == IPS_REVID_TROMBONE64)
  1727.       udelay(5); /* 5 us */
  1728.    /* Erase Confirm */
  1729.    writeb(0xD0, ha->mem_ptr + IPS_REG_FLDP);
  1730.    if (ha->revision_id == IPS_REVID_TROMBONE64)
  1731.       udelay(5); /* 5 us */
  1732.    /* Erase Status */
  1733.    writeb(0x70, ha->mem_ptr + IPS_REG_FLDP);
  1734.    if (ha->revision_id == IPS_REVID_TROMBONE64)
  1735.       udelay(5); /* 5 us */
  1736.    timeout = 80000; /* 80 seconds */
  1737.    while (timeout > 0) {
  1738.       if (ha->revision_id == IPS_REVID_TROMBONE64) {
  1739.          writel(0, ha->mem_ptr + IPS_REG_FLAP);
  1740.          udelay(5); /* 5 us */
  1741.       }
  1742.       status = readb(ha->mem_ptr + IPS_REG_FLDP);
  1743.       if (status & 0x80)
  1744.          break;
  1745.       MDELAY(1);
  1746.       timeout--;
  1747.    }
  1748.    /* check for timeout */
  1749.    if (timeout <= 0) {
  1750.       /* timeout */
  1751.       /* try to suspend the erase */
  1752.       writeb(0xB0, ha->mem_ptr + IPS_REG_FLDP);
  1753.       if (ha->revision_id == IPS_REVID_TROMBONE64)
  1754.          udelay(5); /* 5 us */
  1755.       /* wait for 10 seconds */
  1756.       timeout = 10000;
  1757.       while (timeout > 0) {
  1758.          if (ha->revision_id == IPS_REVID_TROMBONE64) {
  1759.             writel(0, ha->mem_ptr + IPS_REG_FLAP);
  1760.             udelay(5); /* 5 us */
  1761.          }
  1762.          status = readb(ha->mem_ptr + IPS_REG_FLDP);
  1763.          if (status & 0xC0)
  1764.             break;
  1765.          MDELAY(1);
  1766.          timeout--;
  1767.       }
  1768.       return (1);
  1769.    }
  1770.    /* check for valid VPP */
  1771.    if (status & 0x08)
  1772.       /* VPP failure */
  1773.       return (1);
  1774.    /* check for succesful flash */
  1775.    if (status & 0x30)
  1776.       /* sequence error */
  1777.       return (1);
  1778.    /* Otherwise, we were successful */
  1779.    /* clear status */
  1780.    writeb(0x50, ha->mem_ptr + IPS_REG_FLDP);
  1781.    if (ha->revision_id == IPS_REVID_TROMBONE64)
  1782.       udelay(5); /* 5 us */
  1783.    /* enable reads */
  1784.    writeb(0xFF, ha->mem_ptr + IPS_REG_FLDP);
  1785.    if (ha->revision_id == IPS_REVID_TROMBONE64)
  1786.       udelay(5); /* 5 us */
  1787.    return (0);
  1788. }
  1789. /****************************************************************************/
  1790. /*                                                                          */
  1791. /* Routine Name: ips_program_bios                                           */
  1792. /*                                                                          */
  1793. /* Routine Description:                                                     */
  1794. /*   Program the BIOS on the adapter                                        */
  1795. /*                                                                          */
  1796. /****************************************************************************/
  1797. static int
  1798. ips_program_bios(ips_ha_t *ha, char *buffer, u_int32_t buffersize, u_int32_t offset) {
  1799.    int      i;
  1800.    int      timeout;
  1801.    u_int8_t status=0;
  1802.    METHOD_TRACE("ips_program_bios", 1);
  1803.    status = 0;
  1804.    for (i = 0; i < buffersize; i++) {
  1805.       /* write a byte */
  1806.       outl(cpu_to_le32(i + offset), ha->io_addr + IPS_REG_FLAP);
  1807.       if (ha->revision_id == IPS_REVID_TROMBONE64)
  1808.          udelay(5); /* 5 us */
  1809.       outb(0x40, ha->io_addr + IPS_REG_FLDP);
  1810.       if (ha->revision_id == IPS_REVID_TROMBONE64)
  1811.          udelay(5); /* 5 us */
  1812.       outb(buffer[i], ha->io_addr + IPS_REG_FLDP);
  1813.       if (ha->revision_id == IPS_REVID_TROMBONE64)
  1814.          udelay(5); /* 5 us */
  1815.       /* wait up to one second */
  1816.       timeout = 1000;
  1817.       while (timeout > 0) {
  1818.          if (ha->revision_id == IPS_REVID_TROMBONE64) {
  1819.             outl(0, ha->io_addr + IPS_REG_FLAP);
  1820.             udelay(5); /* 5 us */
  1821.          }
  1822.          status = inb(ha->io_addr + IPS_REG_FLDP);
  1823.          if (status & 0x80)
  1824.             break;
  1825.          MDELAY(1);
  1826.          timeout--;
  1827.       }
  1828.       if (timeout == 0) {
  1829.          /* timeout error */
  1830.          outl(0, ha->io_addr + IPS_REG_FLAP);
  1831.          if (ha->revision_id == IPS_REVID_TROMBONE64)
  1832.             udelay(5); /* 5 us */
  1833.          outb(0xFF, ha->io_addr + IPS_REG_FLDP);
  1834.          if (ha->revision_id == IPS_REVID_TROMBONE64)
  1835.             udelay(5); /* 5 us */
  1836.          return (1);
  1837.       }
  1838.       /* check the status */
  1839.       if (status & 0x18) {
  1840.          /* programming error */
  1841.          outl(0, ha->io_addr + IPS_REG_FLAP);
  1842.          if (ha->revision_id == IPS_REVID_TROMBONE64)
  1843.             udelay(5); /* 5 us */
  1844.          outb(0xFF, ha->io_addr + IPS_REG_FLDP);
  1845.          if (ha->revision_id == IPS_REVID_TROMBONE64)
  1846.             udelay(5); /* 5 us */
  1847.          return (1);
  1848.       }
  1849.    } /* end for */
  1850.    /* Enable reading */
  1851.    outl(0, ha->io_addr + IPS_REG_FLAP);
  1852.    if (ha->revision_id == IPS_REVID_TROMBONE64)
  1853.       udelay(5); /* 5 us */
  1854.    outb(0xFF, ha->io_addr + IPS_REG_FLDP);
  1855.    if (ha->revision_id == IPS_REVID_TROMBONE64)
  1856.       udelay(5); /* 5 us */
  1857.    return (0);
  1858. }
  1859. /****************************************************************************/
  1860. /*                                                                          */
  1861. /* Routine Name: ips_program_bios_memio                                     */
  1862. /*                                                                          */
  1863. /* Routine Description:                                                     */
  1864. /*   Program the BIOS on the adapter                                        */
  1865. /*                                                                          */
  1866. /****************************************************************************/
  1867. static int
  1868. ips_program_bios_memio(ips_ha_t *ha, char *buffer, u_int32_t buffersize, u_int32_t offset) {
  1869.    int      i;
  1870.    int      timeout;
  1871.    u_int8_t status=0;
  1872.    METHOD_TRACE("ips_program_bios_memio", 1);
  1873.    status = 0;
  1874.    for (i = 0; i < buffersize; i++) {
  1875.       /* write a byte */
  1876.       writel(cpu_to_le32(i + offset), ha->mem_ptr + IPS_REG_FLAP);
  1877.       if (ha->revision_id == IPS_REVID_TROMBONE64)
  1878.          udelay(5); /* 5 us */
  1879.       writeb(0x40, ha->mem_ptr + IPS_REG_FLDP);
  1880.       if (ha->revision_id == IPS_REVID_TROMBONE64)
  1881.          udelay(5); /* 5 us */
  1882.       writeb(buffer[i], ha->mem_ptr + IPS_REG_FLDP);
  1883.       if (ha->revision_id == IPS_REVID_TROMBONE64)
  1884.          udelay(5); /* 5 us */
  1885.       /* wait up to one second */
  1886.       timeout = 1000;
  1887.       while (timeout > 0) {
  1888.          if (ha->revision_id == IPS_REVID_TROMBONE64) {
  1889.             writel(0, ha->mem_ptr + IPS_REG_FLAP);
  1890.             udelay(5); /* 5 us */
  1891.          }
  1892.          status = readb(ha->mem_ptr + IPS_REG_FLDP);
  1893.          if (status & 0x80)
  1894.             break;
  1895.          MDELAY(1);
  1896.          timeout--;
  1897.       }
  1898.       if (timeout == 0) {
  1899.          /* timeout error */
  1900.          writel(0, ha->mem_ptr + IPS_REG_FLAP);
  1901.          if (ha->revision_id == IPS_REVID_TROMBONE64)
  1902.             udelay(5); /* 5 us */
  1903.          writeb(0xFF, ha->mem_ptr + IPS_REG_FLDP);
  1904.          if (ha->revision_id == IPS_REVID_TROMBONE64)
  1905.             udelay(5); /* 5 us */
  1906.          return (1);
  1907.       }
  1908.       /* check the status */
  1909.       if (status & 0x18) {
  1910.          /* programming error */
  1911.          writel(0, ha->mem_ptr + IPS_REG_FLAP);
  1912.          if (ha->revision_id == IPS_REVID_TROMBONE64)
  1913.             udelay(5); /* 5 us */
  1914.          writeb(0xFF, ha->mem_ptr + IPS_REG_FLDP);
  1915.          if (ha->revision_id == IPS_REVID_TROMBONE64)
  1916.             udelay(5); /* 5 us */
  1917.          return (1);
  1918.       }
  1919.    } /* end for */
  1920.    /* Enable reading */
  1921.    writel(0, ha->mem_ptr + IPS_REG_FLAP);
  1922.    if (ha->revision_id == IPS_REVID_TROMBONE64)
  1923.       udelay(5); /* 5 us */
  1924.    writeb(0xFF, ha->mem_ptr + IPS_REG_FLDP);
  1925.    if (ha->revision_id == IPS_REVID_TROMBONE64)
  1926.       udelay(5); /* 5 us */
  1927.    return (0);
  1928. }
  1929. /****************************************************************************/
  1930. /*                                                                          */
  1931. /* Routine Name: ips_verify_bios                                            */
  1932. /*                                                                          */
  1933. /* Routine Description:                                                     */
  1934. /*   Verify the BIOS on the adapter                                         */
  1935. /*                                                                          */
  1936. /****************************************************************************/
  1937. static int
  1938. ips_verify_bios(ips_ha_t *ha, char *buffer, u_int32_t buffersize, u_int32_t offset) {
  1939.    u_int8_t checksum;
  1940.    int      i;
  1941.    METHOD_TRACE("ips_verify_bios", 1);
  1942.    /* test 1st byte */
  1943.    outl(0, ha->io_addr + IPS_REG_FLAP);
  1944.    if (ha->revision_id == IPS_REVID_TROMBONE64)
  1945.       udelay(5); /* 5 us */
  1946.    if (inb(ha->io_addr + IPS_REG_FLDP) != 0x55)
  1947.       return (1);
  1948.    outl(cpu_to_le32(1), ha->io_addr + IPS_REG_FLAP);
  1949.    if (ha->revision_id == IPS_REVID_TROMBONE64)
  1950.       udelay(5); /* 5 us */
  1951.    if (inb(ha->io_addr + IPS_REG_FLDP) != 0xAA)
  1952.       return (1);
  1953.    checksum = 0xff;
  1954.    for (i = 2; i < buffersize; i++) {
  1955.       outl(cpu_to_le32(i + offset), ha->io_addr + IPS_REG_FLAP);
  1956.       if (ha->revision_id == IPS_REVID_TROMBONE64)
  1957.          udelay(5); /* 5 us */
  1958.       checksum = (u_int8_t) checksum + inb(ha->io_addr + IPS_REG_FLDP);
  1959.    }
  1960.    if (checksum != 0)
  1961.       /* failure */
  1962.       return (1);
  1963.    else
  1964.       /* success */
  1965.       return (0);
  1966. }
  1967. /****************************************************************************/
  1968. /*                                                                          */
  1969. /* Routine Name: ips_verify_bios_memio                                      */
  1970. /*                                                                          */
  1971. /* Routine Description:                                                     */
  1972. /*   Verify the BIOS on the adapter                                         */
  1973. /*                                                                          */
  1974. /****************************************************************************/
  1975. static int
  1976. ips_verify_bios_memio(ips_ha_t *ha, char *buffer, u_int32_t buffersize, u_int32_t offset) {
  1977.    u_int8_t checksum;
  1978.    int      i;
  1979.    METHOD_TRACE("ips_verify_bios_memio", 1);
  1980.    /* test 1st byte */
  1981.    writel(0, ha->mem_ptr + IPS_REG_FLAP);
  1982.    if (ha->revision_id == IPS_REVID_TROMBONE64)
  1983.       udelay(5); /* 5 us */
  1984.    if (readb(ha->mem_ptr + IPS_REG_FLDP) != 0x55)
  1985.       return (1);
  1986.    writel(1, ha->mem_ptr + IPS_REG_FLAP);
  1987.    if (ha->revision_id == IPS_REVID_TROMBONE64)
  1988.       udelay(5); /* 5 us */
  1989.    if (readb(ha->mem_ptr + IPS_REG_FLDP) != 0xAA)
  1990.       return (1);
  1991.    checksum = 0xff;
  1992.    for (i = 2; i < buffersize; i++) {
  1993.       writel(cpu_to_le32(i + offset), ha->mem_ptr + IPS_REG_FLAP);
  1994.       if (ha->revision_id == IPS_REVID_TROMBONE64)
  1995.          udelay(5); /* 5 us */
  1996.       checksum = (u_int8_t) checksum + readb(ha->mem_ptr + IPS_REG_FLDP);
  1997.    }
  1998.    if (checksum != 0)
  1999.       /* failure */
  2000.       return (1);
  2001.    else
  2002.       /* success */
  2003.       return (0);
  2004. }
  2005. #if defined (MODULE) || (LINUX_VERSION_CODE >= LinuxVersionCode(2,4,0))
  2006. static Scsi_Host_Template driver_template = IPS;
  2007. #include "scsi_module.c"
  2008. #endif
  2009. /*
  2010.  * Overrides for Emacs so that we almost follow Linus's tabbing style.
  2011.  * Emacs will notice this stuff at the end of the file and automatically
  2012.  * adjust the settings for this buffer only.  This must remain at the end
  2013.  * of the file.
  2014.  * ---------------------------------------------------------------------------
  2015.  * Local variables:
  2016.  * c-indent-level: 2
  2017.  * c-brace-imaginary-offset: 0
  2018.  * c-brace-offset: -2
  2019.  * c-argdecl-indent: 2
  2020.  * c-label-offset: -2
  2021.  * c-continued-statement-offset: 2
  2022.  * c-continued-brace-offset: 0
  2023.  * indent-tabs-mode: nil
  2024.  * tab-width: 8
  2025.  * End:
  2026.  */