ips.c
Upload User: jlfgdled
Upload Date: 2013-04-10
Package Size: 33168k
Code Size: 274k
Development Platform:

Unix_Linux

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