Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
Andrew Vasquez | fa90c54 | 2005-10-27 11:10:08 -0700 | [diff] [blame] | 2 | * QLogic Fibre Channel HBA Driver |
| 3 | * Copyright (c) 2003-2005 QLogic Corporation |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4 | * |
Andrew Vasquez | fa90c54 | 2005-10-27 11:10:08 -0700 | [diff] [blame] | 5 | * See LICENSE.qla2xxx for copyright and licensing details. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6 | */ |
| 7 | #include "qla_def.h" |
| 8 | |
| 9 | #include <linux/delay.h> |
| 10 | |
| 11 | static void |
| 12 | qla2x00_mbx_sem_timeout(unsigned long data) |
| 13 | { |
| 14 | struct semaphore *sem_ptr = (struct semaphore *)data; |
| 15 | |
Andrew Vasquez | 744f11fd | 2006-06-23 16:11:05 -0700 | [diff] [blame] | 16 | DEBUG11(printk("qla2x00_sem_timeout: entered.\n")); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17 | |
| 18 | if (sem_ptr != NULL) { |
| 19 | up(sem_ptr); |
| 20 | } |
| 21 | |
Andrew Vasquez | 744f11fd | 2006-06-23 16:11:05 -0700 | [diff] [blame] | 22 | DEBUG11(printk("qla2x00_mbx_sem_timeout: exiting.\n")); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 23 | } |
| 24 | |
| 25 | /* |
| 26 | * qla2x00_mailbox_command |
| 27 | * Issue mailbox command and waits for completion. |
| 28 | * |
| 29 | * Input: |
| 30 | * ha = adapter block pointer. |
| 31 | * mcp = driver internal mbx struct pointer. |
| 32 | * |
| 33 | * Output: |
| 34 | * mb[MAX_MAILBOX_REGISTER_COUNT] = returned mailbox data. |
| 35 | * |
| 36 | * Returns: |
| 37 | * 0 : QLA_SUCCESS = cmd performed success |
| 38 | * 1 : QLA_FUNCTION_FAILED (error encountered) |
| 39 | * 6 : QLA_FUNCTION_TIMEOUT (timeout condition encountered) |
| 40 | * |
| 41 | * Context: |
| 42 | * Kernel context. |
| 43 | */ |
| 44 | static int |
| 45 | qla2x00_mailbox_command(scsi_qla_host_t *ha, mbx_cmd_t *mcp) |
| 46 | { |
| 47 | int rval; |
| 48 | unsigned long flags = 0; |
Andrew Vasquez | 1c7c635 | 2005-07-06 10:30:57 -0700 | [diff] [blame] | 49 | device_reg_t __iomem *reg = ha->iobase; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 50 | struct timer_list tmp_intr_timer; |
Andrew Vasquez | 1c7c635 | 2005-07-06 10:30:57 -0700 | [diff] [blame] | 51 | uint8_t abort_active; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 52 | uint8_t io_lock_on = ha->flags.init_done; |
| 53 | uint16_t command; |
| 54 | uint16_t *iptr; |
| 55 | uint16_t __iomem *optr; |
| 56 | uint32_t cnt; |
| 57 | uint32_t mboxes; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 58 | unsigned long wait_time; |
| 59 | |
| 60 | rval = QLA_SUCCESS; |
Andrew Vasquez | 1c7c635 | 2005-07-06 10:30:57 -0700 | [diff] [blame] | 61 | abort_active = test_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 62 | |
Andrew Vasquez | 744f11fd | 2006-06-23 16:11:05 -0700 | [diff] [blame] | 63 | DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no)); |
Andrew Vasquez | 1c7c635 | 2005-07-06 10:30:57 -0700 | [diff] [blame] | 64 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 65 | /* |
Andrew Vasquez | 1c7c635 | 2005-07-06 10:30:57 -0700 | [diff] [blame] | 66 | * Wait for active mailbox commands to finish by waiting at most tov |
| 67 | * seconds. This is to serialize actual issuing of mailbox cmds during |
| 68 | * non ISP abort time. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 69 | */ |
| 70 | if (!abort_active) { |
| 71 | if (qla2x00_down_timeout(&ha->mbx_cmd_sem, mcp->tov * HZ)) { |
| 72 | /* Timeout occurred. Return error. */ |
Andrew Vasquez | 1c7c635 | 2005-07-06 10:30:57 -0700 | [diff] [blame] | 73 | DEBUG2_3_11(printk("%s(%ld): cmd access timeout. " |
Andrew Vasquez | 744f11fd | 2006-06-23 16:11:05 -0700 | [diff] [blame] | 74 | "Exiting.\n", __func__, ha->host_no)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 75 | return QLA_FUNCTION_TIMEOUT; |
| 76 | } |
| 77 | } |
| 78 | |
| 79 | ha->flags.mbox_busy = 1; |
| 80 | /* Save mailbox command for debug */ |
| 81 | ha->mcp = mcp; |
| 82 | |
Andrew Vasquez | 1c7c635 | 2005-07-06 10:30:57 -0700 | [diff] [blame] | 83 | DEBUG11(printk("scsi(%ld): prepare to issue mbox cmd=0x%x.\n", |
Andrew Vasquez | 744f11fd | 2006-06-23 16:11:05 -0700 | [diff] [blame] | 84 | ha->host_no, mcp->mb[0])); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 85 | |
| 86 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 87 | |
| 88 | /* Load mailbox registers. */ |
andrew.vasquez@qlogic.com | 044cc6c | 2006-03-09 14:27:13 -0800 | [diff] [blame] | 89 | if (IS_QLA24XX(ha) || IS_QLA54XX(ha)) |
Andrew Vasquez | 1c7c635 | 2005-07-06 10:30:57 -0700 | [diff] [blame] | 90 | optr = (uint16_t __iomem *)®->isp24.mailbox0; |
| 91 | else |
| 92 | optr = (uint16_t __iomem *)MAILBOX_REG(ha, ®->isp, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 93 | |
| 94 | iptr = mcp->mb; |
| 95 | command = mcp->mb[0]; |
| 96 | mboxes = mcp->out_mb; |
| 97 | |
| 98 | for (cnt = 0; cnt < ha->mbx_count; cnt++) { |
| 99 | if (IS_QLA2200(ha) && cnt == 8) |
Andrew Vasquez | 1c7c635 | 2005-07-06 10:30:57 -0700 | [diff] [blame] | 100 | optr = |
| 101 | (uint16_t __iomem *)MAILBOX_REG(ha, ®->isp, 8); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 102 | if (mboxes & BIT_0) |
| 103 | WRT_REG_WORD(optr, *iptr); |
| 104 | |
| 105 | mboxes >>= 1; |
| 106 | optr++; |
| 107 | iptr++; |
| 108 | } |
| 109 | |
| 110 | #if defined(QL_DEBUG_LEVEL_1) |
Andrew Vasquez | 1c7c635 | 2005-07-06 10:30:57 -0700 | [diff] [blame] | 111 | printk("%s(%ld): Loaded MBX registers (displayed in bytes) = \n", |
| 112 | __func__, ha->host_no); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 113 | qla2x00_dump_buffer((uint8_t *)mcp->mb, 16); |
| 114 | printk("\n"); |
| 115 | qla2x00_dump_buffer(((uint8_t *)mcp->mb + 0x10), 16); |
| 116 | printk("\n"); |
| 117 | qla2x00_dump_buffer(((uint8_t *)mcp->mb + 0x20), 8); |
| 118 | printk("\n"); |
Andrew Vasquez | 1c7c635 | 2005-07-06 10:30:57 -0700 | [diff] [blame] | 119 | printk("%s(%ld): I/O address = %p.\n", __func__, ha->host_no, optr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 120 | qla2x00_dump_regs(ha); |
| 121 | #endif |
| 122 | |
| 123 | /* Issue set host interrupt command to send cmd out. */ |
| 124 | ha->flags.mbox_int = 0; |
| 125 | clear_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags); |
| 126 | |
| 127 | /* Unlock mbx registers and wait for interrupt */ |
Andrew Vasquez | 1c7c635 | 2005-07-06 10:30:57 -0700 | [diff] [blame] | 128 | DEBUG11(printk("%s(%ld): going to unlock irq & waiting for interrupt. " |
Andrew Vasquez | 744f11fd | 2006-06-23 16:11:05 -0700 | [diff] [blame] | 129 | "jiffies=%lx.\n", __func__, ha->host_no, jiffies)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 130 | |
| 131 | /* Wait for mbx cmd completion until timeout */ |
| 132 | |
| 133 | if (!abort_active && io_lock_on) { |
| 134 | /* sleep on completion semaphore */ |
Andrew Vasquez | 1c7c635 | 2005-07-06 10:30:57 -0700 | [diff] [blame] | 135 | DEBUG11(printk("%s(%ld): INTERRUPT MODE. Initializing timer.\n", |
Andrew Vasquez | 744f11fd | 2006-06-23 16:11:05 -0700 | [diff] [blame] | 136 | __func__, ha->host_no)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 137 | |
| 138 | init_timer(&tmp_intr_timer); |
| 139 | tmp_intr_timer.data = (unsigned long)&ha->mbx_intr_sem; |
| 140 | tmp_intr_timer.expires = jiffies + mcp->tov * HZ; |
| 141 | tmp_intr_timer.function = |
| 142 | (void (*)(unsigned long))qla2x00_mbx_sem_timeout; |
| 143 | |
Andrew Vasquez | 1c7c635 | 2005-07-06 10:30:57 -0700 | [diff] [blame] | 144 | DEBUG11(printk("%s(%ld): Adding timer.\n", __func__, |
Andrew Vasquez | 744f11fd | 2006-06-23 16:11:05 -0700 | [diff] [blame] | 145 | ha->host_no)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 146 | add_timer(&tmp_intr_timer); |
| 147 | |
Andrew Vasquez | 1c7c635 | 2005-07-06 10:30:57 -0700 | [diff] [blame] | 148 | DEBUG11(printk("%s(%ld): going to unlock & sleep. " |
Andrew Vasquez | 744f11fd | 2006-06-23 16:11:05 -0700 | [diff] [blame] | 149 | "time=0x%lx.\n", __func__, ha->host_no, jiffies)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 150 | |
| 151 | set_bit(MBX_INTR_WAIT, &ha->mbx_cmd_flags); |
| 152 | |
andrew.vasquez@qlogic.com | 044cc6c | 2006-03-09 14:27:13 -0800 | [diff] [blame] | 153 | if (IS_QLA24XX(ha) || IS_QLA54XX(ha)) |
Andrew Vasquez | 1c7c635 | 2005-07-06 10:30:57 -0700 | [diff] [blame] | 154 | WRT_REG_DWORD(®->isp24.hccr, HCCRX_SET_HOST_INT); |
| 155 | else |
| 156 | WRT_REG_WORD(®->isp.hccr, HCCR_SET_HOST_INT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 157 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 158 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 159 | /* Wait for either the timer to expire |
| 160 | * or the mbox completion interrupt |
| 161 | */ |
| 162 | down(&ha->mbx_intr_sem); |
| 163 | |
Andrew Vasquez | 1c7c635 | 2005-07-06 10:30:57 -0700 | [diff] [blame] | 164 | DEBUG11(printk("%s(%ld): waking up. time=0x%lx\n", __func__, |
Andrew Vasquez | 744f11fd | 2006-06-23 16:11:05 -0700 | [diff] [blame] | 165 | ha->host_no, jiffies)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 166 | clear_bit(MBX_INTR_WAIT, &ha->mbx_cmd_flags); |
| 167 | |
| 168 | /* delete the timer */ |
| 169 | del_timer(&tmp_intr_timer); |
| 170 | } else { |
Andrew Vasquez | 1c7c635 | 2005-07-06 10:30:57 -0700 | [diff] [blame] | 171 | DEBUG3_11(printk("%s(%ld): cmd=%x POLLING MODE.\n", __func__, |
Andrew Vasquez | 744f11fd | 2006-06-23 16:11:05 -0700 | [diff] [blame] | 172 | ha->host_no, command)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 173 | |
andrew.vasquez@qlogic.com | 044cc6c | 2006-03-09 14:27:13 -0800 | [diff] [blame] | 174 | if (IS_QLA24XX(ha) || IS_QLA54XX(ha)) |
Andrew Vasquez | 1c7c635 | 2005-07-06 10:30:57 -0700 | [diff] [blame] | 175 | WRT_REG_DWORD(®->isp24.hccr, HCCRX_SET_HOST_INT); |
| 176 | else |
| 177 | WRT_REG_WORD(®->isp.hccr, HCCR_SET_HOST_INT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 178 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 179 | |
| 180 | wait_time = jiffies + mcp->tov * HZ; /* wait at most tov secs */ |
| 181 | while (!ha->flags.mbox_int) { |
| 182 | if (time_after(jiffies, wait_time)) |
| 183 | break; |
| 184 | |
| 185 | /* Check for pending interrupts. */ |
| 186 | qla2x00_poll(ha); |
| 187 | |
andrew.vasquez@qlogic.com | 5998983 | 2006-01-13 17:05:10 -0800 | [diff] [blame] | 188 | if (command != MBC_LOAD_RISC_RAM_EXTENDED && |
| 189 | !ha->flags.mbox_int) |
| 190 | msleep(10); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 191 | } /* while */ |
| 192 | } |
| 193 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 194 | /* Check whether we timed out */ |
| 195 | if (ha->flags.mbox_int) { |
| 196 | uint16_t *iptr2; |
| 197 | |
Andrew Vasquez | 1c7c635 | 2005-07-06 10:30:57 -0700 | [diff] [blame] | 198 | DEBUG3_11(printk("%s(%ld): cmd %x completed.\n", __func__, |
Andrew Vasquez | 744f11fd | 2006-06-23 16:11:05 -0700 | [diff] [blame] | 199 | ha->host_no, command)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 200 | |
| 201 | /* Got interrupt. Clear the flag. */ |
| 202 | ha->flags.mbox_int = 0; |
| 203 | clear_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags); |
| 204 | |
Andrew Vasquez | 354d6b2 | 2005-04-23 02:47:27 -0400 | [diff] [blame] | 205 | if (ha->mailbox_out[0] != MBS_COMMAND_COMPLETE) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 206 | rval = QLA_FUNCTION_FAILED; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 207 | |
| 208 | /* Load return mailbox registers. */ |
| 209 | iptr2 = mcp->mb; |
| 210 | iptr = (uint16_t *)&ha->mailbox_out[0]; |
| 211 | mboxes = mcp->in_mb; |
| 212 | for (cnt = 0; cnt < ha->mbx_count; cnt++) { |
| 213 | if (mboxes & BIT_0) |
| 214 | *iptr2 = *iptr; |
| 215 | |
| 216 | mboxes >>= 1; |
| 217 | iptr2++; |
| 218 | iptr++; |
| 219 | } |
| 220 | } else { |
| 221 | |
| 222 | #if defined(QL_DEBUG_LEVEL_2) || defined(QL_DEBUG_LEVEL_3) || \ |
| 223 | defined(QL_DEBUG_LEVEL_11) |
Andrew Vasquez | 1c7c635 | 2005-07-06 10:30:57 -0700 | [diff] [blame] | 224 | uint16_t mb0; |
| 225 | uint32_t ictrl; |
| 226 | |
andrew.vasquez@qlogic.com | 044cc6c | 2006-03-09 14:27:13 -0800 | [diff] [blame] | 227 | if (IS_QLA24XX(ha) || IS_QLA54XX(ha)) { |
Andrew Vasquez | 1c7c635 | 2005-07-06 10:30:57 -0700 | [diff] [blame] | 228 | mb0 = RD_REG_WORD(®->isp24.mailbox0); |
| 229 | ictrl = RD_REG_DWORD(®->isp24.ictrl); |
| 230 | } else { |
Andrew Vasquez | cca5335 | 2005-08-26 19:08:30 -0700 | [diff] [blame] | 231 | mb0 = RD_MAILBOX_REG(ha, ®->isp, 0); |
Andrew Vasquez | 1c7c635 | 2005-07-06 10:30:57 -0700 | [diff] [blame] | 232 | ictrl = RD_REG_WORD(®->isp.ictrl); |
| 233 | } |
| 234 | printk("%s(%ld): **** MB Command Timeout for cmd %x ****\n", |
| 235 | __func__, ha->host_no, command); |
| 236 | printk("%s(%ld): icontrol=%x jiffies=%lx\n", __func__, |
| 237 | ha->host_no, ictrl, jiffies); |
| 238 | printk("%s(%ld): *** mailbox[0] = 0x%x ***\n", __func__, |
| 239 | ha->host_no, mb0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 240 | qla2x00_dump_regs(ha); |
| 241 | #endif |
| 242 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 243 | rval = QLA_FUNCTION_TIMEOUT; |
| 244 | } |
| 245 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 246 | ha->flags.mbox_busy = 0; |
| 247 | |
| 248 | /* Clean up */ |
| 249 | ha->mcp = NULL; |
| 250 | |
| 251 | if (!abort_active) { |
Andrew Vasquez | 1c7c635 | 2005-07-06 10:30:57 -0700 | [diff] [blame] | 252 | DEBUG11(printk("%s(%ld): checking for additional resp " |
Andrew Vasquez | 744f11fd | 2006-06-23 16:11:05 -0700 | [diff] [blame] | 253 | "interrupt.\n", __func__, ha->host_no)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 254 | |
| 255 | /* polling mode for non isp_abort commands. */ |
| 256 | qla2x00_poll(ha); |
| 257 | } |
| 258 | |
Andrew Vasquez | 1c7c635 | 2005-07-06 10:30:57 -0700 | [diff] [blame] | 259 | if (rval == QLA_FUNCTION_TIMEOUT && |
| 260 | mcp->mb[0] != MBC_GEN_SYSTEM_ERROR) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 261 | if (!io_lock_on || (mcp->flags & IOCTL_CMD)) { |
| 262 | /* not in dpc. schedule it for dpc to take over. */ |
Andrew Vasquez | 1c7c635 | 2005-07-06 10:30:57 -0700 | [diff] [blame] | 263 | DEBUG(printk("%s(%ld): timeout schedule " |
Andrew Vasquez | 744f11fd | 2006-06-23 16:11:05 -0700 | [diff] [blame] | 264 | "isp_abort_needed.\n", __func__, ha->host_no)); |
Andrew Vasquez | 1c7c635 | 2005-07-06 10:30:57 -0700 | [diff] [blame] | 265 | DEBUG2_3_11(printk("%s(%ld): timeout schedule " |
Andrew Vasquez | 744f11fd | 2006-06-23 16:11:05 -0700 | [diff] [blame] | 266 | "isp_abort_needed.\n", __func__, ha->host_no)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 267 | qla_printk(KERN_WARNING, ha, |
| 268 | "Mailbox command timeout occured. Scheduling ISP " |
| 269 | "abort.\n"); |
| 270 | set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags); |
Christoph Hellwig | 39a1124 | 2006-02-14 18:46:22 +0100 | [diff] [blame] | 271 | qla2xxx_wake_dpc(ha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 272 | } else if (!abort_active) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 273 | /* call abort directly since we are in the DPC thread */ |
Andrew Vasquez | 1c7c635 | 2005-07-06 10:30:57 -0700 | [diff] [blame] | 274 | DEBUG(printk("%s(%ld): timeout calling abort_isp\n", |
Andrew Vasquez | 744f11fd | 2006-06-23 16:11:05 -0700 | [diff] [blame] | 275 | __func__, ha->host_no)); |
Andrew Vasquez | 1c7c635 | 2005-07-06 10:30:57 -0700 | [diff] [blame] | 276 | DEBUG2_3_11(printk("%s(%ld): timeout calling " |
Andrew Vasquez | 744f11fd | 2006-06-23 16:11:05 -0700 | [diff] [blame] | 277 | "abort_isp\n", __func__, ha->host_no)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 278 | qla_printk(KERN_WARNING, ha, |
| 279 | "Mailbox command timeout occured. Issuing ISP " |
| 280 | "abort.\n"); |
| 281 | |
| 282 | set_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags); |
| 283 | clear_bit(ISP_ABORT_NEEDED, &ha->dpc_flags); |
| 284 | if (qla2x00_abort_isp(ha)) { |
Andrew Vasquez | 1c7c635 | 2005-07-06 10:30:57 -0700 | [diff] [blame] | 285 | /* Failed. retry later. */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 286 | set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags); |
| 287 | } |
| 288 | clear_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags); |
Andrew Vasquez | 1c7c635 | 2005-07-06 10:30:57 -0700 | [diff] [blame] | 289 | DEBUG(printk("%s(%ld): finished abort_isp\n", __func__, |
Andrew Vasquez | 744f11fd | 2006-06-23 16:11:05 -0700 | [diff] [blame] | 290 | ha->host_no)); |
Andrew Vasquez | 1c7c635 | 2005-07-06 10:30:57 -0700 | [diff] [blame] | 291 | DEBUG2_3_11(printk("%s(%ld): finished abort_isp\n", |
Andrew Vasquez | 744f11fd | 2006-06-23 16:11:05 -0700 | [diff] [blame] | 292 | __func__, ha->host_no)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 293 | } |
| 294 | } |
| 295 | |
| 296 | /* Allow next mbx cmd to come in. */ |
| 297 | if (!abort_active) |
| 298 | up(&ha->mbx_cmd_sem); |
| 299 | |
| 300 | if (rval) { |
Andrew Vasquez | 1c7c635 | 2005-07-06 10:30:57 -0700 | [diff] [blame] | 301 | DEBUG2_3_11(printk("%s(%ld): **** FAILED. mbx0=%x, mbx1=%x, " |
| 302 | "mbx2=%x, cmd=%x ****\n", __func__, ha->host_no, |
Andrew Vasquez | 744f11fd | 2006-06-23 16:11:05 -0700 | [diff] [blame] | 303 | mcp->mb[0], mcp->mb[1], mcp->mb[2], command)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 304 | } else { |
Andrew Vasquez | 744f11fd | 2006-06-23 16:11:05 -0700 | [diff] [blame] | 305 | DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 306 | } |
| 307 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 308 | return rval; |
| 309 | } |
| 310 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 311 | int |
andrew.vasquez@qlogic.com | 590f98e | 2006-01-13 17:05:37 -0800 | [diff] [blame] | 312 | qla2x00_load_ram(scsi_qla_host_t *ha, dma_addr_t req_dma, uint32_t risc_addr, |
| 313 | uint32_t risc_code_size) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 314 | { |
| 315 | int rval; |
| 316 | mbx_cmd_t mc; |
| 317 | mbx_cmd_t *mcp = &mc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 318 | |
| 319 | DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no)); |
| 320 | |
andrew.vasquez@qlogic.com | 044cc6c | 2006-03-09 14:27:13 -0800 | [diff] [blame] | 321 | if (MSW(risc_addr) || IS_QLA24XX(ha) || IS_QLA54XX(ha)) { |
andrew.vasquez@qlogic.com | 590f98e | 2006-01-13 17:05:37 -0800 | [diff] [blame] | 322 | mcp->mb[0] = MBC_LOAD_RISC_RAM_EXTENDED; |
| 323 | mcp->mb[8] = MSW(risc_addr); |
| 324 | mcp->out_mb = MBX_8|MBX_0; |
| 325 | } else { |
| 326 | mcp->mb[0] = MBC_LOAD_RISC_RAM; |
| 327 | mcp->out_mb = MBX_0; |
| 328 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 329 | mcp->mb[1] = LSW(risc_addr); |
| 330 | mcp->mb[2] = MSW(req_dma); |
| 331 | mcp->mb[3] = LSW(req_dma); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 332 | mcp->mb[6] = MSW(MSD(req_dma)); |
| 333 | mcp->mb[7] = LSW(MSD(req_dma)); |
andrew.vasquez@qlogic.com | 590f98e | 2006-01-13 17:05:37 -0800 | [diff] [blame] | 334 | mcp->out_mb |= MBX_7|MBX_6|MBX_3|MBX_2|MBX_1; |
andrew.vasquez@qlogic.com | 044cc6c | 2006-03-09 14:27:13 -0800 | [diff] [blame] | 335 | if (IS_QLA24XX(ha) || IS_QLA54XX(ha)) { |
Andrew Vasquez | 1c7c635 | 2005-07-06 10:30:57 -0700 | [diff] [blame] | 336 | mcp->mb[4] = MSW(risc_code_size); |
| 337 | mcp->mb[5] = LSW(risc_code_size); |
| 338 | mcp->out_mb |= MBX_5|MBX_4; |
| 339 | } else { |
| 340 | mcp->mb[4] = LSW(risc_code_size); |
| 341 | mcp->out_mb |= MBX_4; |
| 342 | } |
| 343 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 344 | mcp->in_mb = MBX_0; |
| 345 | mcp->tov = 30; |
| 346 | mcp->flags = 0; |
| 347 | rval = qla2x00_mailbox_command(ha, mcp); |
| 348 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 349 | if (rval != QLA_SUCCESS) { |
Andrew Vasquez | 1c7c635 | 2005-07-06 10:30:57 -0700 | [diff] [blame] | 350 | DEBUG2_3_11(printk("%s(%ld): failed=%x mb[0]=%x.\n", __func__, |
| 351 | ha->host_no, rval, mcp->mb[0])); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 352 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 353 | DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no)); |
| 354 | } |
| 355 | |
| 356 | return rval; |
| 357 | } |
| 358 | |
| 359 | /* |
| 360 | * qla2x00_execute_fw |
Andrew Vasquez | 1c7c635 | 2005-07-06 10:30:57 -0700 | [diff] [blame] | 361 | * Start adapter firmware. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 362 | * |
| 363 | * Input: |
Andrew Vasquez | 1c7c635 | 2005-07-06 10:30:57 -0700 | [diff] [blame] | 364 | * ha = adapter block pointer. |
| 365 | * TARGET_QUEUE_LOCK must be released. |
| 366 | * ADAPTER_STATE_LOCK must be released. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 367 | * |
| 368 | * Returns: |
Andrew Vasquez | 1c7c635 | 2005-07-06 10:30:57 -0700 | [diff] [blame] | 369 | * qla2x00 local function return status code. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 370 | * |
| 371 | * Context: |
Andrew Vasquez | 1c7c635 | 2005-07-06 10:30:57 -0700 | [diff] [blame] | 372 | * Kernel context. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 373 | */ |
| 374 | int |
Andrew Vasquez | 1c7c635 | 2005-07-06 10:30:57 -0700 | [diff] [blame] | 375 | qla2x00_execute_fw(scsi_qla_host_t *ha, uint32_t risc_addr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 376 | { |
| 377 | int rval; |
| 378 | mbx_cmd_t mc; |
| 379 | mbx_cmd_t *mcp = &mc; |
| 380 | |
Andrew Vasquez | 744f11fd | 2006-06-23 16:11:05 -0700 | [diff] [blame] | 381 | DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 382 | |
| 383 | mcp->mb[0] = MBC_EXECUTE_FIRMWARE; |
Andrew Vasquez | 1c7c635 | 2005-07-06 10:30:57 -0700 | [diff] [blame] | 384 | mcp->out_mb = MBX_0; |
| 385 | mcp->in_mb = MBX_0; |
andrew.vasquez@qlogic.com | 044cc6c | 2006-03-09 14:27:13 -0800 | [diff] [blame] | 386 | if (IS_QLA24XX(ha) || IS_QLA54XX(ha)) { |
Andrew Vasquez | 1c7c635 | 2005-07-06 10:30:57 -0700 | [diff] [blame] | 387 | mcp->mb[1] = MSW(risc_addr); |
| 388 | mcp->mb[2] = LSW(risc_addr); |
| 389 | mcp->mb[3] = 0; |
| 390 | mcp->out_mb |= MBX_3|MBX_2|MBX_1; |
| 391 | mcp->in_mb |= MBX_1; |
| 392 | } else { |
| 393 | mcp->mb[1] = LSW(risc_addr); |
| 394 | mcp->out_mb |= MBX_1; |
| 395 | if (IS_QLA2322(ha) || IS_QLA6322(ha)) { |
| 396 | mcp->mb[2] = 0; |
| 397 | mcp->out_mb |= MBX_2; |
| 398 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 399 | } |
| 400 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 401 | mcp->tov = 30; |
| 402 | mcp->flags = 0; |
| 403 | rval = qla2x00_mailbox_command(ha, mcp); |
| 404 | |
Andrew Vasquez | 1c7c635 | 2005-07-06 10:30:57 -0700 | [diff] [blame] | 405 | if (rval != QLA_SUCCESS) { |
| 406 | DEBUG2_3_11(printk("%s(%ld): failed=%x mb[0]=%x.\n", __func__, |
| 407 | ha->host_no, rval, mcp->mb[0])); |
| 408 | } else { |
andrew.vasquez@qlogic.com | 044cc6c | 2006-03-09 14:27:13 -0800 | [diff] [blame] | 409 | if (IS_QLA24XX(ha) || IS_QLA54XX(ha)) { |
Andrew Vasquez | 1c7c635 | 2005-07-06 10:30:57 -0700 | [diff] [blame] | 410 | DEBUG11(printk("%s(%ld): done exchanges=%x.\n", |
Andrew Vasquez | 744f11fd | 2006-06-23 16:11:05 -0700 | [diff] [blame] | 411 | __func__, ha->host_no, mcp->mb[1])); |
Andrew Vasquez | 1c7c635 | 2005-07-06 10:30:57 -0700 | [diff] [blame] | 412 | } else { |
| 413 | DEBUG11(printk("%s(%ld): done.\n", __func__, |
Andrew Vasquez | 744f11fd | 2006-06-23 16:11:05 -0700 | [diff] [blame] | 414 | ha->host_no)); |
Andrew Vasquez | 1c7c635 | 2005-07-06 10:30:57 -0700 | [diff] [blame] | 415 | } |
| 416 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 417 | |
| 418 | return rval; |
| 419 | } |
| 420 | |
| 421 | /* |
| 422 | * qla2x00_get_fw_version |
| 423 | * Get firmware version. |
| 424 | * |
| 425 | * Input: |
| 426 | * ha: adapter state pointer. |
| 427 | * major: pointer for major number. |
| 428 | * minor: pointer for minor number. |
| 429 | * subminor: pointer for subminor number. |
| 430 | * |
| 431 | * Returns: |
| 432 | * qla2x00 local function return status code. |
| 433 | * |
| 434 | * Context: |
| 435 | * Kernel context. |
| 436 | */ |
| 437 | void |
| 438 | qla2x00_get_fw_version(scsi_qla_host_t *ha, uint16_t *major, uint16_t *minor, |
| 439 | uint16_t *subminor, uint16_t *attributes, uint32_t *memory) |
| 440 | { |
| 441 | int rval; |
| 442 | mbx_cmd_t mc; |
| 443 | mbx_cmd_t *mcp = &mc; |
| 444 | |
| 445 | DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no)); |
| 446 | |
| 447 | mcp->mb[0] = MBC_GET_FIRMWARE_VERSION; |
| 448 | mcp->out_mb = MBX_0; |
| 449 | mcp->in_mb = MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0; |
| 450 | mcp->flags = 0; |
| 451 | mcp->tov = 30; |
| 452 | rval = qla2x00_mailbox_command(ha, mcp); |
| 453 | |
| 454 | /* Return mailbox data. */ |
| 455 | *major = mcp->mb[1]; |
| 456 | *minor = mcp->mb[2]; |
| 457 | *subminor = mcp->mb[3]; |
| 458 | *attributes = mcp->mb[6]; |
| 459 | if (IS_QLA2100(ha) || IS_QLA2200(ha)) |
| 460 | *memory = 0x1FFFF; /* Defaults to 128KB. */ |
| 461 | else |
| 462 | *memory = (mcp->mb[5] << 16) | mcp->mb[4]; |
| 463 | |
| 464 | if (rval != QLA_SUCCESS) { |
| 465 | /*EMPTY*/ |
| 466 | DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__, |
| 467 | ha->host_no, rval)); |
| 468 | } else { |
| 469 | /*EMPTY*/ |
| 470 | DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no)); |
| 471 | } |
| 472 | } |
| 473 | |
| 474 | /* |
| 475 | * qla2x00_get_fw_options |
| 476 | * Set firmware options. |
| 477 | * |
| 478 | * Input: |
| 479 | * ha = adapter block pointer. |
| 480 | * fwopt = pointer for firmware options. |
| 481 | * |
| 482 | * Returns: |
| 483 | * qla2x00 local function return status code. |
| 484 | * |
| 485 | * Context: |
| 486 | * Kernel context. |
| 487 | */ |
| 488 | int |
| 489 | qla2x00_get_fw_options(scsi_qla_host_t *ha, uint16_t *fwopts) |
| 490 | { |
| 491 | int rval; |
| 492 | mbx_cmd_t mc; |
| 493 | mbx_cmd_t *mcp = &mc; |
| 494 | |
| 495 | DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no)); |
| 496 | |
| 497 | mcp->mb[0] = MBC_GET_FIRMWARE_OPTION; |
| 498 | mcp->out_mb = MBX_0; |
| 499 | mcp->in_mb = MBX_3|MBX_2|MBX_1|MBX_0; |
| 500 | mcp->tov = 30; |
| 501 | mcp->flags = 0; |
| 502 | rval = qla2x00_mailbox_command(ha, mcp); |
| 503 | |
| 504 | if (rval != QLA_SUCCESS) { |
| 505 | /*EMPTY*/ |
| 506 | DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__, |
| 507 | ha->host_no, rval)); |
| 508 | } else { |
Andrew Vasquez | 1c7c635 | 2005-07-06 10:30:57 -0700 | [diff] [blame] | 509 | fwopts[0] = mcp->mb[0]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 510 | fwopts[1] = mcp->mb[1]; |
| 511 | fwopts[2] = mcp->mb[2]; |
| 512 | fwopts[3] = mcp->mb[3]; |
| 513 | |
| 514 | DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no)); |
| 515 | } |
| 516 | |
| 517 | return rval; |
| 518 | } |
| 519 | |
| 520 | |
| 521 | /* |
| 522 | * qla2x00_set_fw_options |
| 523 | * Set firmware options. |
| 524 | * |
| 525 | * Input: |
| 526 | * ha = adapter block pointer. |
| 527 | * fwopt = pointer for firmware options. |
| 528 | * |
| 529 | * Returns: |
| 530 | * qla2x00 local function return status code. |
| 531 | * |
| 532 | * Context: |
| 533 | * Kernel context. |
| 534 | */ |
| 535 | int |
| 536 | qla2x00_set_fw_options(scsi_qla_host_t *ha, uint16_t *fwopts) |
| 537 | { |
| 538 | int rval; |
| 539 | mbx_cmd_t mc; |
| 540 | mbx_cmd_t *mcp = &mc; |
| 541 | |
| 542 | DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no)); |
| 543 | |
| 544 | mcp->mb[0] = MBC_SET_FIRMWARE_OPTION; |
| 545 | mcp->mb[1] = fwopts[1]; |
| 546 | mcp->mb[2] = fwopts[2]; |
| 547 | mcp->mb[3] = fwopts[3]; |
Andrew Vasquez | 1c7c635 | 2005-07-06 10:30:57 -0700 | [diff] [blame] | 548 | mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 549 | mcp->in_mb = MBX_0; |
andrew.vasquez@qlogic.com | 044cc6c | 2006-03-09 14:27:13 -0800 | [diff] [blame] | 550 | if (IS_QLA24XX(ha) || IS_QLA54XX(ha)) { |
Andrew Vasquez | 1c7c635 | 2005-07-06 10:30:57 -0700 | [diff] [blame] | 551 | mcp->in_mb |= MBX_1; |
| 552 | } else { |
| 553 | mcp->mb[10] = fwopts[10]; |
| 554 | mcp->mb[11] = fwopts[11]; |
| 555 | mcp->mb[12] = 0; /* Undocumented, but used */ |
| 556 | mcp->out_mb |= MBX_12|MBX_11|MBX_10; |
| 557 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 558 | mcp->tov = 30; |
| 559 | mcp->flags = 0; |
| 560 | rval = qla2x00_mailbox_command(ha, mcp); |
| 561 | |
Andrew Vasquez | 1c7c635 | 2005-07-06 10:30:57 -0700 | [diff] [blame] | 562 | fwopts[0] = mcp->mb[0]; |
| 563 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 564 | if (rval != QLA_SUCCESS) { |
| 565 | /*EMPTY*/ |
Andrew Vasquez | 1c7c635 | 2005-07-06 10:30:57 -0700 | [diff] [blame] | 566 | DEBUG2_3_11(printk("%s(%ld): failed=%x (%x/%x).\n", __func__, |
| 567 | ha->host_no, rval, mcp->mb[0], mcp->mb[1])); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 568 | } else { |
| 569 | /*EMPTY*/ |
| 570 | DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no)); |
| 571 | } |
| 572 | |
| 573 | return rval; |
| 574 | } |
| 575 | |
| 576 | /* |
| 577 | * qla2x00_mbx_reg_test |
| 578 | * Mailbox register wrap test. |
| 579 | * |
| 580 | * Input: |
| 581 | * ha = adapter block pointer. |
| 582 | * TARGET_QUEUE_LOCK must be released. |
| 583 | * ADAPTER_STATE_LOCK must be released. |
| 584 | * |
| 585 | * Returns: |
| 586 | * qla2x00 local function return status code. |
| 587 | * |
| 588 | * Context: |
| 589 | * Kernel context. |
| 590 | */ |
| 591 | int |
| 592 | qla2x00_mbx_reg_test(scsi_qla_host_t *ha) |
| 593 | { |
| 594 | int rval; |
| 595 | mbx_cmd_t mc; |
| 596 | mbx_cmd_t *mcp = &mc; |
| 597 | |
Andrew Vasquez | 744f11fd | 2006-06-23 16:11:05 -0700 | [diff] [blame] | 598 | DEBUG11(printk("qla2x00_mbx_reg_test(%ld): entered.\n", ha->host_no)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 599 | |
| 600 | mcp->mb[0] = MBC_MAILBOX_REGISTER_TEST; |
| 601 | mcp->mb[1] = 0xAAAA; |
| 602 | mcp->mb[2] = 0x5555; |
| 603 | mcp->mb[3] = 0xAA55; |
| 604 | mcp->mb[4] = 0x55AA; |
| 605 | mcp->mb[5] = 0xA5A5; |
| 606 | mcp->mb[6] = 0x5A5A; |
| 607 | mcp->mb[7] = 0x2525; |
| 608 | mcp->out_mb = MBX_7|MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0; |
| 609 | mcp->in_mb = MBX_7|MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0; |
| 610 | mcp->tov = 30; |
| 611 | mcp->flags = 0; |
| 612 | rval = qla2x00_mailbox_command(ha, mcp); |
| 613 | |
| 614 | if (rval == QLA_SUCCESS) { |
| 615 | if (mcp->mb[1] != 0xAAAA || mcp->mb[2] != 0x5555 || |
| 616 | mcp->mb[3] != 0xAA55 || mcp->mb[4] != 0x55AA) |
| 617 | rval = QLA_FUNCTION_FAILED; |
| 618 | if (mcp->mb[5] != 0xA5A5 || mcp->mb[6] != 0x5A5A || |
| 619 | mcp->mb[7] != 0x2525) |
| 620 | rval = QLA_FUNCTION_FAILED; |
| 621 | } |
| 622 | |
| 623 | if (rval != QLA_SUCCESS) { |
| 624 | /*EMPTY*/ |
| 625 | DEBUG2_3_11(printk("qla2x00_mbx_reg_test(%ld): failed=%x.\n", |
Andrew Vasquez | 744f11fd | 2006-06-23 16:11:05 -0700 | [diff] [blame] | 626 | ha->host_no, rval)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 627 | } else { |
| 628 | /*EMPTY*/ |
| 629 | DEBUG11(printk("qla2x00_mbx_reg_test(%ld): done.\n", |
Andrew Vasquez | 744f11fd | 2006-06-23 16:11:05 -0700 | [diff] [blame] | 630 | ha->host_no)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 631 | } |
| 632 | |
| 633 | return rval; |
| 634 | } |
| 635 | |
| 636 | /* |
| 637 | * qla2x00_verify_checksum |
| 638 | * Verify firmware checksum. |
| 639 | * |
| 640 | * Input: |
| 641 | * ha = adapter block pointer. |
| 642 | * TARGET_QUEUE_LOCK must be released. |
| 643 | * ADAPTER_STATE_LOCK must be released. |
| 644 | * |
| 645 | * Returns: |
| 646 | * qla2x00 local function return status code. |
| 647 | * |
| 648 | * Context: |
| 649 | * Kernel context. |
| 650 | */ |
| 651 | int |
Andrew Vasquez | 1c7c635 | 2005-07-06 10:30:57 -0700 | [diff] [blame] | 652 | qla2x00_verify_checksum(scsi_qla_host_t *ha, uint32_t risc_addr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 653 | { |
| 654 | int rval; |
| 655 | mbx_cmd_t mc; |
| 656 | mbx_cmd_t *mcp = &mc; |
| 657 | |
Andrew Vasquez | 744f11fd | 2006-06-23 16:11:05 -0700 | [diff] [blame] | 658 | DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 659 | |
| 660 | mcp->mb[0] = MBC_VERIFY_CHECKSUM; |
Andrew Vasquez | 1c7c635 | 2005-07-06 10:30:57 -0700 | [diff] [blame] | 661 | mcp->out_mb = MBX_0; |
| 662 | mcp->in_mb = MBX_0; |
andrew.vasquez@qlogic.com | 044cc6c | 2006-03-09 14:27:13 -0800 | [diff] [blame] | 663 | if (IS_QLA24XX(ha) || IS_QLA54XX(ha)) { |
Andrew Vasquez | 1c7c635 | 2005-07-06 10:30:57 -0700 | [diff] [blame] | 664 | mcp->mb[1] = MSW(risc_addr); |
| 665 | mcp->mb[2] = LSW(risc_addr); |
| 666 | mcp->out_mb |= MBX_2|MBX_1; |
| 667 | mcp->in_mb |= MBX_2|MBX_1; |
| 668 | } else { |
| 669 | mcp->mb[1] = LSW(risc_addr); |
| 670 | mcp->out_mb |= MBX_1; |
| 671 | mcp->in_mb |= MBX_1; |
| 672 | } |
| 673 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 674 | mcp->tov = 30; |
| 675 | mcp->flags = 0; |
| 676 | rval = qla2x00_mailbox_command(ha, mcp); |
| 677 | |
| 678 | if (rval != QLA_SUCCESS) { |
Andrew Vasquez | 1c7c635 | 2005-07-06 10:30:57 -0700 | [diff] [blame] | 679 | DEBUG2_3_11(printk("%s(%ld): failed=%x chk sum=%x.\n", __func__, |
andrew.vasquez@qlogic.com | 044cc6c | 2006-03-09 14:27:13 -0800 | [diff] [blame] | 680 | ha->host_no, rval, (IS_QLA24XX(ha) || IS_QLA54XX(ha) ? |
Andrew Vasquez | 744f11fd | 2006-06-23 16:11:05 -0700 | [diff] [blame] | 681 | (mcp->mb[2] << 16) | mcp->mb[1]: mcp->mb[1]))); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 682 | } else { |
Andrew Vasquez | 744f11fd | 2006-06-23 16:11:05 -0700 | [diff] [blame] | 683 | DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 684 | } |
| 685 | |
| 686 | return rval; |
| 687 | } |
| 688 | |
| 689 | /* |
| 690 | * qla2x00_issue_iocb |
| 691 | * Issue IOCB using mailbox command |
| 692 | * |
| 693 | * Input: |
| 694 | * ha = adapter state pointer. |
| 695 | * buffer = buffer pointer. |
| 696 | * phys_addr = physical address of buffer. |
| 697 | * size = size of buffer. |
| 698 | * TARGET_QUEUE_LOCK must be released. |
| 699 | * ADAPTER_STATE_LOCK must be released. |
| 700 | * |
| 701 | * Returns: |
| 702 | * qla2x00 local function return status code. |
| 703 | * |
| 704 | * Context: |
| 705 | * Kernel context. |
| 706 | */ |
| 707 | int |
| 708 | qla2x00_issue_iocb(scsi_qla_host_t *ha, void* buffer, dma_addr_t phys_addr, |
| 709 | size_t size) |
| 710 | { |
| 711 | int rval; |
| 712 | mbx_cmd_t mc; |
| 713 | mbx_cmd_t *mcp = &mc; |
| 714 | |
| 715 | mcp->mb[0] = MBC_IOCB_COMMAND_A64; |
| 716 | mcp->mb[1] = 0; |
| 717 | mcp->mb[2] = MSW(phys_addr); |
| 718 | mcp->mb[3] = LSW(phys_addr); |
| 719 | mcp->mb[6] = MSW(MSD(phys_addr)); |
| 720 | mcp->mb[7] = LSW(MSD(phys_addr)); |
| 721 | mcp->out_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0; |
| 722 | mcp->in_mb = MBX_2|MBX_0; |
| 723 | mcp->tov = 30; |
| 724 | mcp->flags = 0; |
| 725 | rval = qla2x00_mailbox_command(ha, mcp); |
| 726 | |
| 727 | if (rval != QLA_SUCCESS) { |
| 728 | /*EMPTY*/ |
Andrew Vasquez | 1c7c635 | 2005-07-06 10:30:57 -0700 | [diff] [blame] | 729 | DEBUG(printk("qla2x00_issue_iocb(%ld): failed rval 0x%x\n", |
Andrew Vasquez | 744f11fd | 2006-06-23 16:11:05 -0700 | [diff] [blame] | 730 | ha->host_no, rval)); |
Andrew Vasquez | 1c7c635 | 2005-07-06 10:30:57 -0700 | [diff] [blame] | 731 | DEBUG2(printk("qla2x00_issue_iocb(%ld): failed rval 0x%x\n", |
Andrew Vasquez | 744f11fd | 2006-06-23 16:11:05 -0700 | [diff] [blame] | 732 | ha->host_no, rval)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 733 | } else { |
Andrew Vasquez | 8c958a9 | 2005-07-06 10:30:47 -0700 | [diff] [blame] | 734 | sts_entry_t *sts_entry = (sts_entry_t *) buffer; |
| 735 | |
| 736 | /* Mask reserved bits. */ |
| 737 | sts_entry->entry_status &= |
andrew.vasquez@qlogic.com | 044cc6c | 2006-03-09 14:27:13 -0800 | [diff] [blame] | 738 | IS_QLA24XX(ha) || IS_QLA54XX(ha) ? RF_MASK_24XX :RF_MASK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 739 | } |
| 740 | |
| 741 | return rval; |
| 742 | } |
| 743 | |
| 744 | /* |
| 745 | * qla2x00_abort_command |
| 746 | * Abort command aborts a specified IOCB. |
| 747 | * |
| 748 | * Input: |
| 749 | * ha = adapter block pointer. |
| 750 | * sp = SB structure pointer. |
| 751 | * |
| 752 | * Returns: |
| 753 | * qla2x00 local function return status code. |
| 754 | * |
| 755 | * Context: |
| 756 | * Kernel context. |
| 757 | */ |
| 758 | int |
| 759 | qla2x00_abort_command(scsi_qla_host_t *ha, srb_t *sp) |
| 760 | { |
| 761 | unsigned long flags = 0; |
| 762 | fc_port_t *fcport; |
| 763 | int rval; |
| 764 | uint32_t handle; |
| 765 | mbx_cmd_t mc; |
| 766 | mbx_cmd_t *mcp = &mc; |
| 767 | |
Andrew Vasquez | 744f11fd | 2006-06-23 16:11:05 -0700 | [diff] [blame] | 768 | DEBUG11(printk("qla2x00_abort_command(%ld): entered.\n", ha->host_no)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 769 | |
| bdf7962 | 2005-04-17 15:06:53 -0500 | [diff] [blame] | 770 | fcport = sp->fcport; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 771 | |
| 772 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 773 | for (handle = 1; handle < MAX_OUTSTANDING_COMMANDS; handle++) { |
| 774 | if (ha->outstanding_cmds[handle] == sp) |
| 775 | break; |
| 776 | } |
| 777 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 778 | |
| 779 | if (handle == MAX_OUTSTANDING_COMMANDS) { |
| 780 | /* command not found */ |
| 781 | return QLA_FUNCTION_FAILED; |
| 782 | } |
| 783 | |
| 784 | mcp->mb[0] = MBC_ABORT_COMMAND; |
| 785 | if (HAS_EXTENDED_IDS(ha)) |
| 786 | mcp->mb[1] = fcport->loop_id; |
| 787 | else |
| 788 | mcp->mb[1] = fcport->loop_id << 8; |
| 789 | mcp->mb[2] = (uint16_t)handle; |
| 790 | mcp->mb[3] = (uint16_t)(handle >> 16); |
| bdf7962 | 2005-04-17 15:06:53 -0500 | [diff] [blame] | 791 | mcp->mb[6] = (uint16_t)sp->cmd->device->lun; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 792 | mcp->out_mb = MBX_6|MBX_3|MBX_2|MBX_1|MBX_0; |
| 793 | mcp->in_mb = MBX_0; |
| 794 | mcp->tov = 30; |
| 795 | mcp->flags = 0; |
| 796 | rval = qla2x00_mailbox_command(ha, mcp); |
| 797 | |
| 798 | if (rval != QLA_SUCCESS) { |
| 799 | DEBUG2_3_11(printk("qla2x00_abort_command(%ld): failed=%x.\n", |
Andrew Vasquez | 744f11fd | 2006-06-23 16:11:05 -0700 | [diff] [blame] | 800 | ha->host_no, rval)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 801 | } else { |
| 802 | sp->flags |= SRB_ABORT_PENDING; |
| 803 | DEBUG11(printk("qla2x00_abort_command(%ld): done.\n", |
Andrew Vasquez | 744f11fd | 2006-06-23 16:11:05 -0700 | [diff] [blame] | 804 | ha->host_no)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 805 | } |
| 806 | |
| 807 | return rval; |
| 808 | } |
| 809 | |
| 810 | #if USE_ABORT_TGT |
| 811 | /* |
| 812 | * qla2x00_abort_target |
| 813 | * Issue abort target mailbox command. |
| 814 | * |
| 815 | * Input: |
| 816 | * ha = adapter block pointer. |
| 817 | * |
| 818 | * Returns: |
| 819 | * qla2x00 local function return status code. |
| 820 | * |
| 821 | * Context: |
| 822 | * Kernel context. |
| 823 | */ |
| 824 | int |
| 825 | qla2x00_abort_target(fc_port_t *fcport) |
| 826 | { |
| 827 | int rval; |
| 828 | mbx_cmd_t mc; |
| 829 | mbx_cmd_t *mcp = &mc; |
Andrew Vasquez | 1c7c635 | 2005-07-06 10:30:57 -0700 | [diff] [blame] | 830 | scsi_qla_host_t *ha; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 831 | |
Andrew Vasquez | 1c7c635 | 2005-07-06 10:30:57 -0700 | [diff] [blame] | 832 | if (fcport == NULL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 833 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 834 | |
Andrew Vasquez | 744f11fd | 2006-06-23 16:11:05 -0700 | [diff] [blame] | 835 | DEBUG11(printk("%s(%ld): entered.\n", __func__, fcport->ha->host_no)); |
Andrew Vasquez | 1c7c635 | 2005-07-06 10:30:57 -0700 | [diff] [blame] | 836 | |
| 837 | ha = fcport->ha; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 838 | mcp->mb[0] = MBC_ABORT_TARGET; |
| 839 | mcp->out_mb = MBX_2|MBX_1|MBX_0; |
Andrew Vasquez | 1c7c635 | 2005-07-06 10:30:57 -0700 | [diff] [blame] | 840 | if (HAS_EXTENDED_IDS(ha)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 841 | mcp->mb[1] = fcport->loop_id; |
| 842 | mcp->mb[10] = 0; |
| 843 | mcp->out_mb |= MBX_10; |
| 844 | } else { |
| 845 | mcp->mb[1] = fcport->loop_id << 8; |
| 846 | } |
Andrew Vasquez | 1c7c635 | 2005-07-06 10:30:57 -0700 | [diff] [blame] | 847 | mcp->mb[2] = ha->loop_reset_delay; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 848 | |
| 849 | mcp->in_mb = MBX_0; |
| 850 | mcp->tov = 30; |
| 851 | mcp->flags = 0; |
Andrew Vasquez | 1c7c635 | 2005-07-06 10:30:57 -0700 | [diff] [blame] | 852 | rval = qla2x00_mailbox_command(ha, mcp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 853 | |
| 854 | /* Issue marker command. */ |
Andrew Vasquez | 1c7c635 | 2005-07-06 10:30:57 -0700 | [diff] [blame] | 855 | ha->marker_needed = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 856 | |
| 857 | if (rval != QLA_SUCCESS) { |
| 858 | DEBUG2_3_11(printk("qla2x00_abort_target(%ld): failed=%x.\n", |
Andrew Vasquez | 744f11fd | 2006-06-23 16:11:05 -0700 | [diff] [blame] | 859 | ha->host_no, rval)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 860 | } else { |
| 861 | /*EMPTY*/ |
| 862 | DEBUG11(printk("qla2x00_abort_target(%ld): done.\n", |
Andrew Vasquez | 744f11fd | 2006-06-23 16:11:05 -0700 | [diff] [blame] | 863 | ha->host_no)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 864 | } |
| 865 | |
| 866 | return rval; |
| 867 | } |
| 868 | #endif |
| 869 | |
| 870 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 871 | * qla2x00_get_adapter_id |
| 872 | * Get adapter ID and topology. |
| 873 | * |
| 874 | * Input: |
| 875 | * ha = adapter block pointer. |
| 876 | * id = pointer for loop ID. |
| 877 | * al_pa = pointer for AL_PA. |
| 878 | * area = pointer for area. |
| 879 | * domain = pointer for domain. |
| 880 | * top = pointer for topology. |
| 881 | * TARGET_QUEUE_LOCK must be released. |
| 882 | * ADAPTER_STATE_LOCK must be released. |
| 883 | * |
| 884 | * Returns: |
| 885 | * qla2x00 local function return status code. |
| 886 | * |
| 887 | * Context: |
| 888 | * Kernel context. |
| 889 | */ |
| 890 | int |
| 891 | qla2x00_get_adapter_id(scsi_qla_host_t *ha, uint16_t *id, uint8_t *al_pa, |
| 892 | uint8_t *area, uint8_t *domain, uint16_t *top) |
| 893 | { |
| 894 | int rval; |
| 895 | mbx_cmd_t mc; |
| 896 | mbx_cmd_t *mcp = &mc; |
| 897 | |
| 898 | DEBUG11(printk("qla2x00_get_adapter_id(%ld): entered.\n", |
Andrew Vasquez | 744f11fd | 2006-06-23 16:11:05 -0700 | [diff] [blame] | 899 | ha->host_no)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 900 | |
| 901 | mcp->mb[0] = MBC_GET_ADAPTER_LOOP_ID; |
| 902 | mcp->out_mb = MBX_0; |
| 903 | mcp->in_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0; |
| 904 | mcp->tov = 30; |
| 905 | mcp->flags = 0; |
| 906 | rval = qla2x00_mailbox_command(ha, mcp); |
Ravi Anand | 33135aa | 2005-11-08 14:37:20 -0800 | [diff] [blame] | 907 | if (mcp->mb[0] == MBS_COMMAND_ERROR) |
| 908 | rval = QLA_COMMAND_ERROR; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 909 | |
| 910 | /* Return data. */ |
| 911 | *id = mcp->mb[1]; |
| 912 | *al_pa = LSB(mcp->mb[2]); |
| 913 | *area = MSB(mcp->mb[2]); |
| 914 | *domain = LSB(mcp->mb[3]); |
| 915 | *top = mcp->mb[6]; |
| 916 | |
| 917 | if (rval != QLA_SUCCESS) { |
| 918 | /*EMPTY*/ |
| 919 | DEBUG2_3_11(printk("qla2x00_get_adapter_id(%ld): failed=%x.\n", |
Andrew Vasquez | 744f11fd | 2006-06-23 16:11:05 -0700 | [diff] [blame] | 920 | ha->host_no, rval)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 921 | } else { |
| 922 | /*EMPTY*/ |
| 923 | DEBUG11(printk("qla2x00_get_adapter_id(%ld): done.\n", |
Andrew Vasquez | 744f11fd | 2006-06-23 16:11:05 -0700 | [diff] [blame] | 924 | ha->host_no)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 925 | } |
| 926 | |
| 927 | return rval; |
| 928 | } |
| 929 | |
| 930 | /* |
| 931 | * qla2x00_get_retry_cnt |
| 932 | * Get current firmware login retry count and delay. |
| 933 | * |
| 934 | * Input: |
| 935 | * ha = adapter block pointer. |
| 936 | * retry_cnt = pointer to login retry count. |
| 937 | * tov = pointer to login timeout value. |
| 938 | * |
| 939 | * Returns: |
| 940 | * qla2x00 local function return status code. |
| 941 | * |
| 942 | * Context: |
| 943 | * Kernel context. |
| 944 | */ |
| 945 | int |
| 946 | qla2x00_get_retry_cnt(scsi_qla_host_t *ha, uint8_t *retry_cnt, uint8_t *tov, |
| 947 | uint16_t *r_a_tov) |
| 948 | { |
| 949 | int rval; |
| 950 | uint16_t ratov; |
| 951 | mbx_cmd_t mc; |
| 952 | mbx_cmd_t *mcp = &mc; |
| 953 | |
| 954 | DEBUG11(printk("qla2x00_get_retry_cnt(%ld): entered.\n", |
Andrew Vasquez | 744f11fd | 2006-06-23 16:11:05 -0700 | [diff] [blame] | 955 | ha->host_no)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 956 | |
| 957 | mcp->mb[0] = MBC_GET_RETRY_COUNT; |
| 958 | mcp->out_mb = MBX_0; |
| 959 | mcp->in_mb = MBX_3|MBX_2|MBX_1|MBX_0; |
| 960 | mcp->tov = 30; |
| 961 | mcp->flags = 0; |
| 962 | rval = qla2x00_mailbox_command(ha, mcp); |
| 963 | |
| 964 | if (rval != QLA_SUCCESS) { |
| 965 | /*EMPTY*/ |
| 966 | DEBUG2_3_11(printk("qla2x00_get_retry_cnt(%ld): failed = %x.\n", |
Andrew Vasquez | 744f11fd | 2006-06-23 16:11:05 -0700 | [diff] [blame] | 967 | ha->host_no, mcp->mb[0])); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 968 | } else { |
| 969 | /* Convert returned data and check our values. */ |
| 970 | *r_a_tov = mcp->mb[3] / 2; |
| 971 | ratov = (mcp->mb[3]/2) / 10; /* mb[3] value is in 100ms */ |
| 972 | if (mcp->mb[1] * ratov > (*retry_cnt) * (*tov)) { |
| 973 | /* Update to the larger values */ |
| 974 | *retry_cnt = (uint8_t)mcp->mb[1]; |
| 975 | *tov = ratov; |
| 976 | } |
| 977 | |
| 978 | DEBUG11(printk("qla2x00_get_retry_cnt(%ld): done. mb3=%d " |
Andrew Vasquez | 744f11fd | 2006-06-23 16:11:05 -0700 | [diff] [blame] | 979 | "ratov=%d.\n", ha->host_no, mcp->mb[3], ratov)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 980 | } |
| 981 | |
| 982 | return rval; |
| 983 | } |
| 984 | |
| 985 | /* |
| 986 | * qla2x00_init_firmware |
| 987 | * Initialize adapter firmware. |
| 988 | * |
| 989 | * Input: |
| 990 | * ha = adapter block pointer. |
| 991 | * dptr = Initialization control block pointer. |
| 992 | * size = size of initialization control block. |
| 993 | * TARGET_QUEUE_LOCK must be released. |
| 994 | * ADAPTER_STATE_LOCK must be released. |
| 995 | * |
| 996 | * Returns: |
| 997 | * qla2x00 local function return status code. |
| 998 | * |
| 999 | * Context: |
| 1000 | * Kernel context. |
| 1001 | */ |
| 1002 | int |
| 1003 | qla2x00_init_firmware(scsi_qla_host_t *ha, uint16_t size) |
| 1004 | { |
| 1005 | int rval; |
| 1006 | mbx_cmd_t mc; |
| 1007 | mbx_cmd_t *mcp = &mc; |
| 1008 | |
| 1009 | DEBUG11(printk("qla2x00_init_firmware(%ld): entered.\n", |
Andrew Vasquez | 744f11fd | 2006-06-23 16:11:05 -0700 | [diff] [blame] | 1010 | ha->host_no)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1011 | |
| 1012 | mcp->mb[0] = MBC_INITIALIZE_FIRMWARE; |
| 1013 | mcp->mb[2] = MSW(ha->init_cb_dma); |
| 1014 | mcp->mb[3] = LSW(ha->init_cb_dma); |
| 1015 | mcp->mb[4] = 0; |
| 1016 | mcp->mb[5] = 0; |
| 1017 | mcp->mb[6] = MSW(MSD(ha->init_cb_dma)); |
| 1018 | mcp->mb[7] = LSW(MSD(ha->init_cb_dma)); |
| 1019 | mcp->out_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_0; |
| 1020 | mcp->in_mb = MBX_5|MBX_4|MBX_0; |
| 1021 | mcp->buf_size = size; |
| 1022 | mcp->flags = MBX_DMA_OUT; |
| 1023 | mcp->tov = 30; |
| 1024 | rval = qla2x00_mailbox_command(ha, mcp); |
| 1025 | |
| 1026 | if (rval != QLA_SUCCESS) { |
| 1027 | /*EMPTY*/ |
| 1028 | DEBUG2_3_11(printk("qla2x00_init_firmware(%ld): failed=%x " |
| 1029 | "mb0=%x.\n", |
Andrew Vasquez | 744f11fd | 2006-06-23 16:11:05 -0700 | [diff] [blame] | 1030 | ha->host_no, rval, mcp->mb[0])); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1031 | } else { |
| 1032 | /*EMPTY*/ |
| 1033 | DEBUG11(printk("qla2x00_init_firmware(%ld): done.\n", |
Andrew Vasquez | 744f11fd | 2006-06-23 16:11:05 -0700 | [diff] [blame] | 1034 | ha->host_no)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1035 | } |
| 1036 | |
| 1037 | return rval; |
| 1038 | } |
| 1039 | |
| 1040 | /* |
| 1041 | * qla2x00_get_port_database |
| 1042 | * Issue normal/enhanced get port database mailbox command |
| 1043 | * and copy device name as necessary. |
| 1044 | * |
| 1045 | * Input: |
| 1046 | * ha = adapter state pointer. |
| 1047 | * dev = structure pointer. |
| 1048 | * opt = enhanced cmd option byte. |
| 1049 | * |
| 1050 | * Returns: |
| 1051 | * qla2x00 local function return status code. |
| 1052 | * |
| 1053 | * Context: |
| 1054 | * Kernel context. |
| 1055 | */ |
| 1056 | int |
| 1057 | qla2x00_get_port_database(scsi_qla_host_t *ha, fc_port_t *fcport, uint8_t opt) |
| 1058 | { |
| 1059 | int rval; |
| 1060 | mbx_cmd_t mc; |
| 1061 | mbx_cmd_t *mcp = &mc; |
| 1062 | port_database_t *pd; |
Andrew Vasquez | 1c7c635 | 2005-07-06 10:30:57 -0700 | [diff] [blame] | 1063 | struct port_database_24xx *pd24; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1064 | dma_addr_t pd_dma; |
| 1065 | |
Andrew Vasquez | 744f11fd | 2006-06-23 16:11:05 -0700 | [diff] [blame] | 1066 | DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1067 | |
Andrew Vasquez | 1c7c635 | 2005-07-06 10:30:57 -0700 | [diff] [blame] | 1068 | pd24 = NULL; |
| 1069 | pd = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &pd_dma); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1070 | if (pd == NULL) { |
Andrew Vasquez | 1c7c635 | 2005-07-06 10:30:57 -0700 | [diff] [blame] | 1071 | DEBUG2_3(printk("%s(%ld): failed to allocate Port Database " |
| 1072 | "structure.\n", __func__, ha->host_no)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1073 | return QLA_MEMORY_ALLOC_FAILED; |
| 1074 | } |
Andrew Vasquez | 1c7c635 | 2005-07-06 10:30:57 -0700 | [diff] [blame] | 1075 | memset(pd, 0, max(PORT_DATABASE_SIZE, PORT_DATABASE_24XX_SIZE)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1076 | |
Andrew Vasquez | 1c7c635 | 2005-07-06 10:30:57 -0700 | [diff] [blame] | 1077 | mcp->mb[0] = MBC_GET_PORT_DATABASE; |
andrew.vasquez@qlogic.com | 044cc6c | 2006-03-09 14:27:13 -0800 | [diff] [blame] | 1078 | if (opt != 0 && !IS_QLA24XX(ha) && !IS_QLA54XX(ha)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1079 | mcp->mb[0] = MBC_ENHANCED_GET_PORT_DATABASE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1080 | mcp->mb[2] = MSW(pd_dma); |
| 1081 | mcp->mb[3] = LSW(pd_dma); |
| 1082 | mcp->mb[6] = MSW(MSD(pd_dma)); |
| 1083 | mcp->mb[7] = LSW(MSD(pd_dma)); |
Andrew Vasquez | 1c7c635 | 2005-07-06 10:30:57 -0700 | [diff] [blame] | 1084 | mcp->out_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1085 | mcp->in_mb = MBX_0; |
andrew.vasquez@qlogic.com | 044cc6c | 2006-03-09 14:27:13 -0800 | [diff] [blame] | 1086 | if (IS_QLA24XX(ha) || IS_QLA54XX(ha)) { |
Andrew Vasquez | 1c7c635 | 2005-07-06 10:30:57 -0700 | [diff] [blame] | 1087 | mcp->mb[1] = fcport->loop_id; |
| 1088 | mcp->mb[10] = opt; |
| 1089 | mcp->out_mb |= MBX_10|MBX_1; |
| 1090 | mcp->in_mb |= MBX_1; |
| 1091 | } else if (HAS_EXTENDED_IDS(ha)) { |
| 1092 | mcp->mb[1] = fcport->loop_id; |
| 1093 | mcp->mb[10] = opt; |
| 1094 | mcp->out_mb |= MBX_10|MBX_1; |
| 1095 | } else { |
| 1096 | mcp->mb[1] = fcport->loop_id << 8 | opt; |
| 1097 | mcp->out_mb |= MBX_1; |
| 1098 | } |
andrew.vasquez@qlogic.com | 044cc6c | 2006-03-09 14:27:13 -0800 | [diff] [blame] | 1099 | mcp->buf_size = (IS_QLA24XX(ha) || IS_QLA54XX(ha) ? |
Andrew Vasquez | 1c7c635 | 2005-07-06 10:30:57 -0700 | [diff] [blame] | 1100 | PORT_DATABASE_24XX_SIZE : PORT_DATABASE_SIZE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1101 | mcp->flags = MBX_DMA_IN; |
| 1102 | mcp->tov = (ha->login_timeout * 2) + (ha->login_timeout / 2); |
| 1103 | rval = qla2x00_mailbox_command(ha, mcp); |
| 1104 | if (rval != QLA_SUCCESS) |
| 1105 | goto gpd_error_out; |
| 1106 | |
andrew.vasquez@qlogic.com | 044cc6c | 2006-03-09 14:27:13 -0800 | [diff] [blame] | 1107 | if (IS_QLA24XX(ha) || IS_QLA54XX(ha)) { |
Andrew Vasquez | 1c7c635 | 2005-07-06 10:30:57 -0700 | [diff] [blame] | 1108 | pd24 = (struct port_database_24xx *) pd; |
| 1109 | |
| 1110 | /* Check for logged in state. */ |
| 1111 | if (pd24->current_login_state != PDS_PRLI_COMPLETE && |
| 1112 | pd24->last_login_state != PDS_PRLI_COMPLETE) { |
| 1113 | DEBUG2(printk("%s(%ld): Unable to verify " |
| 1114 | "login-state (%x/%x) for loop_id %x\n", |
| 1115 | __func__, ha->host_no, |
| 1116 | pd24->current_login_state, |
| 1117 | pd24->last_login_state, fcport->loop_id)); |
| 1118 | rval = QLA_FUNCTION_FAILED; |
| 1119 | goto gpd_error_out; |
| 1120 | } |
| 1121 | |
| 1122 | /* Names are little-endian. */ |
| 1123 | memcpy(fcport->node_name, pd24->node_name, WWN_SIZE); |
| 1124 | memcpy(fcport->port_name, pd24->port_name, WWN_SIZE); |
| 1125 | |
| 1126 | /* Get port_id of device. */ |
| 1127 | fcport->d_id.b.domain = pd24->port_id[0]; |
| 1128 | fcport->d_id.b.area = pd24->port_id[1]; |
| 1129 | fcport->d_id.b.al_pa = pd24->port_id[2]; |
| 1130 | fcport->d_id.b.rsvd_1 = 0; |
| 1131 | |
| 1132 | /* If not target must be initiator or unknown type. */ |
| 1133 | if ((pd24->prli_svc_param_word_3[0] & BIT_4) == 0) |
| 1134 | fcport->port_type = FCT_INITIATOR; |
| 1135 | else |
| 1136 | fcport->port_type = FCT_TARGET; |
| 1137 | } else { |
| 1138 | /* Check for logged in state. */ |
| 1139 | if (pd->master_state != PD_STATE_PORT_LOGGED_IN && |
| 1140 | pd->slave_state != PD_STATE_PORT_LOGGED_IN) { |
| 1141 | rval = QLA_FUNCTION_FAILED; |
| 1142 | goto gpd_error_out; |
| 1143 | } |
| 1144 | |
| 1145 | /* Names are little-endian. */ |
| 1146 | memcpy(fcport->node_name, pd->node_name, WWN_SIZE); |
| 1147 | memcpy(fcport->port_name, pd->port_name, WWN_SIZE); |
| 1148 | |
| 1149 | /* Get port_id of device. */ |
| 1150 | fcport->d_id.b.domain = pd->port_id[0]; |
| 1151 | fcport->d_id.b.area = pd->port_id[3]; |
| 1152 | fcport->d_id.b.al_pa = pd->port_id[2]; |
| 1153 | fcport->d_id.b.rsvd_1 = 0; |
| 1154 | |
| 1155 | /* Check for device require authentication. */ |
| 1156 | pd->common_features & BIT_5 ? (fcport->flags |= FCF_AUTH_REQ) : |
| 1157 | (fcport->flags &= ~FCF_AUTH_REQ); |
| 1158 | |
| 1159 | /* If not target must be initiator or unknown type. */ |
| 1160 | if ((pd->prli_svc_param_word_3[0] & BIT_4) == 0) |
| 1161 | fcport->port_type = FCT_INITIATOR; |
| 1162 | else |
| 1163 | fcport->port_type = FCT_TARGET; |
Andrew Vasquez | ad3e0ed | 2005-08-26 19:08:10 -0700 | [diff] [blame] | 1164 | |
| 1165 | /* Passback COS information. */ |
| 1166 | fcport->supported_classes = (pd->options & BIT_4) ? |
| 1167 | FC_COS_CLASS2: FC_COS_CLASS3; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1168 | } |
| 1169 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1170 | gpd_error_out: |
| 1171 | dma_pool_free(ha->s_dma_pool, pd, pd_dma); |
| 1172 | |
| 1173 | if (rval != QLA_SUCCESS) { |
Andrew Vasquez | 1c7c635 | 2005-07-06 10:30:57 -0700 | [diff] [blame] | 1174 | DEBUG2_3_11(printk("%s(%ld): failed=%x mb[0]=%x mb[1]=%x.\n", |
| 1175 | __func__, ha->host_no, rval, mcp->mb[0], mcp->mb[1])); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1176 | } else { |
Andrew Vasquez | 1c7c635 | 2005-07-06 10:30:57 -0700 | [diff] [blame] | 1177 | DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1178 | } |
| 1179 | |
| 1180 | return rval; |
| 1181 | } |
| 1182 | |
| 1183 | /* |
| 1184 | * qla2x00_get_firmware_state |
| 1185 | * Get adapter firmware state. |
| 1186 | * |
| 1187 | * Input: |
| 1188 | * ha = adapter block pointer. |
| 1189 | * dptr = pointer for firmware state. |
| 1190 | * TARGET_QUEUE_LOCK must be released. |
| 1191 | * ADAPTER_STATE_LOCK must be released. |
| 1192 | * |
| 1193 | * Returns: |
| 1194 | * qla2x00 local function return status code. |
| 1195 | * |
| 1196 | * Context: |
| 1197 | * Kernel context. |
| 1198 | */ |
| 1199 | int |
| 1200 | qla2x00_get_firmware_state(scsi_qla_host_t *ha, uint16_t *dptr) |
| 1201 | { |
| 1202 | int rval; |
| 1203 | mbx_cmd_t mc; |
| 1204 | mbx_cmd_t *mcp = &mc; |
| 1205 | |
| 1206 | DEBUG11(printk("qla2x00_get_firmware_state(%ld): entered.\n", |
Andrew Vasquez | 744f11fd | 2006-06-23 16:11:05 -0700 | [diff] [blame] | 1207 | ha->host_no)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1208 | |
| 1209 | mcp->mb[0] = MBC_GET_FIRMWARE_STATE; |
| 1210 | mcp->out_mb = MBX_0; |
| 1211 | mcp->in_mb = MBX_2|MBX_1|MBX_0; |
| 1212 | mcp->tov = 30; |
| 1213 | mcp->flags = 0; |
| 1214 | rval = qla2x00_mailbox_command(ha, mcp); |
| 1215 | |
| 1216 | /* Return firmware state. */ |
| 1217 | *dptr = mcp->mb[1]; |
| 1218 | |
| 1219 | if (rval != QLA_SUCCESS) { |
| 1220 | /*EMPTY*/ |
| 1221 | DEBUG2_3_11(printk("qla2x00_get_firmware_state(%ld): " |
Andrew Vasquez | 744f11fd | 2006-06-23 16:11:05 -0700 | [diff] [blame] | 1222 | "failed=%x.\n", ha->host_no, rval)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1223 | } else { |
| 1224 | /*EMPTY*/ |
| 1225 | DEBUG11(printk("qla2x00_get_firmware_state(%ld): done.\n", |
Andrew Vasquez | 744f11fd | 2006-06-23 16:11:05 -0700 | [diff] [blame] | 1226 | ha->host_no)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1227 | } |
| 1228 | |
| 1229 | return rval; |
| 1230 | } |
| 1231 | |
| 1232 | /* |
| 1233 | * qla2x00_get_port_name |
| 1234 | * Issue get port name mailbox command. |
| 1235 | * Returned name is in big endian format. |
| 1236 | * |
| 1237 | * Input: |
| 1238 | * ha = adapter block pointer. |
| 1239 | * loop_id = loop ID of device. |
| 1240 | * name = pointer for name. |
| 1241 | * TARGET_QUEUE_LOCK must be released. |
| 1242 | * ADAPTER_STATE_LOCK must be released. |
| 1243 | * |
| 1244 | * Returns: |
| 1245 | * qla2x00 local function return status code. |
| 1246 | * |
| 1247 | * Context: |
| 1248 | * Kernel context. |
| 1249 | */ |
| 1250 | int |
| 1251 | qla2x00_get_port_name(scsi_qla_host_t *ha, uint16_t loop_id, uint8_t *name, |
| 1252 | uint8_t opt) |
| 1253 | { |
| 1254 | int rval; |
| 1255 | mbx_cmd_t mc; |
| 1256 | mbx_cmd_t *mcp = &mc; |
| 1257 | |
| 1258 | DEBUG11(printk("qla2x00_get_port_name(%ld): entered.\n", |
Andrew Vasquez | 744f11fd | 2006-06-23 16:11:05 -0700 | [diff] [blame] | 1259 | ha->host_no)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1260 | |
| 1261 | mcp->mb[0] = MBC_GET_PORT_NAME; |
| 1262 | mcp->out_mb = MBX_1|MBX_0; |
| 1263 | if (HAS_EXTENDED_IDS(ha)) { |
| 1264 | mcp->mb[1] = loop_id; |
| 1265 | mcp->mb[10] = opt; |
| 1266 | mcp->out_mb |= MBX_10; |
| 1267 | } else { |
| 1268 | mcp->mb[1] = loop_id << 8 | opt; |
| 1269 | } |
| 1270 | |
| 1271 | mcp->in_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0; |
| 1272 | mcp->tov = 30; |
| 1273 | mcp->flags = 0; |
| 1274 | rval = qla2x00_mailbox_command(ha, mcp); |
| 1275 | |
| 1276 | if (rval != QLA_SUCCESS) { |
| 1277 | /*EMPTY*/ |
| 1278 | DEBUG2_3_11(printk("qla2x00_get_port_name(%ld): failed=%x.\n", |
Andrew Vasquez | 744f11fd | 2006-06-23 16:11:05 -0700 | [diff] [blame] | 1279 | ha->host_no, rval)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1280 | } else { |
| 1281 | if (name != NULL) { |
| 1282 | /* This function returns name in big endian. */ |
Richard Lary | 1196ae0 | 2007-03-22 10:53:19 -0500 | [diff] [blame] | 1283 | name[0] = MSB(mcp->mb[2]); |
| 1284 | name[1] = LSB(mcp->mb[2]); |
| 1285 | name[2] = MSB(mcp->mb[3]); |
| 1286 | name[3] = LSB(mcp->mb[3]); |
| 1287 | name[4] = MSB(mcp->mb[6]); |
| 1288 | name[5] = LSB(mcp->mb[6]); |
| 1289 | name[6] = MSB(mcp->mb[7]); |
| 1290 | name[7] = LSB(mcp->mb[7]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1291 | } |
| 1292 | |
| 1293 | DEBUG11(printk("qla2x00_get_port_name(%ld): done.\n", |
Andrew Vasquez | 744f11fd | 2006-06-23 16:11:05 -0700 | [diff] [blame] | 1294 | ha->host_no)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1295 | } |
| 1296 | |
| 1297 | return rval; |
| 1298 | } |
| 1299 | |
| 1300 | /* |
| 1301 | * qla2x00_lip_reset |
| 1302 | * Issue LIP reset mailbox command. |
| 1303 | * |
| 1304 | * Input: |
| 1305 | * ha = adapter block pointer. |
| 1306 | * TARGET_QUEUE_LOCK must be released. |
| 1307 | * ADAPTER_STATE_LOCK must be released. |
| 1308 | * |
| 1309 | * Returns: |
| 1310 | * qla2x00 local function return status code. |
| 1311 | * |
| 1312 | * Context: |
| 1313 | * Kernel context. |
| 1314 | */ |
| 1315 | int |
| 1316 | qla2x00_lip_reset(scsi_qla_host_t *ha) |
| 1317 | { |
| 1318 | int rval; |
| 1319 | mbx_cmd_t mc; |
| 1320 | mbx_cmd_t *mcp = &mc; |
| 1321 | |
Andrew Vasquez | 744f11fd | 2006-06-23 16:11:05 -0700 | [diff] [blame] | 1322 | DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1323 | |
andrew.vasquez@qlogic.com | 044cc6c | 2006-03-09 14:27:13 -0800 | [diff] [blame] | 1324 | if (IS_QLA24XX(ha) || IS_QLA54XX(ha)) { |
Andrew Vasquez | 1c7c635 | 2005-07-06 10:30:57 -0700 | [diff] [blame] | 1325 | mcp->mb[0] = MBC_LIP_FULL_LOGIN; |
Andrew Vasquez | 0c8c39a | 2006-12-13 19:20:30 -0800 | [diff] [blame] | 1326 | mcp->mb[1] = BIT_6; |
| 1327 | mcp->mb[2] = 0; |
| 1328 | mcp->mb[3] = ha->loop_reset_delay; |
Andrew Vasquez | 1c7c635 | 2005-07-06 10:30:57 -0700 | [diff] [blame] | 1329 | mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1330 | } else { |
Andrew Vasquez | 1c7c635 | 2005-07-06 10:30:57 -0700 | [diff] [blame] | 1331 | mcp->mb[0] = MBC_LIP_RESET; |
| 1332 | mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0; |
| 1333 | if (HAS_EXTENDED_IDS(ha)) { |
| 1334 | mcp->mb[1] = 0x00ff; |
| 1335 | mcp->mb[10] = 0; |
| 1336 | mcp->out_mb |= MBX_10; |
| 1337 | } else { |
| 1338 | mcp->mb[1] = 0xff00; |
| 1339 | } |
| 1340 | mcp->mb[2] = ha->loop_reset_delay; |
| 1341 | mcp->mb[3] = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1342 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1343 | mcp->in_mb = MBX_0; |
| 1344 | mcp->tov = 30; |
| 1345 | mcp->flags = 0; |
| 1346 | rval = qla2x00_mailbox_command(ha, mcp); |
| 1347 | |
| 1348 | if (rval != QLA_SUCCESS) { |
| 1349 | /*EMPTY*/ |
Andrew Vasquez | 1c7c635 | 2005-07-06 10:30:57 -0700 | [diff] [blame] | 1350 | DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", |
Andrew Vasquez | 744f11fd | 2006-06-23 16:11:05 -0700 | [diff] [blame] | 1351 | __func__, ha->host_no, rval)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1352 | } else { |
| 1353 | /*EMPTY*/ |
Andrew Vasquez | 744f11fd | 2006-06-23 16:11:05 -0700 | [diff] [blame] | 1354 | DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1355 | } |
| 1356 | |
| 1357 | return rval; |
| 1358 | } |
| 1359 | |
| 1360 | /* |
| 1361 | * qla2x00_send_sns |
| 1362 | * Send SNS command. |
| 1363 | * |
| 1364 | * Input: |
| 1365 | * ha = adapter block pointer. |
| 1366 | * sns = pointer for command. |
| 1367 | * cmd_size = command size. |
| 1368 | * buf_size = response/command size. |
| 1369 | * TARGET_QUEUE_LOCK must be released. |
| 1370 | * ADAPTER_STATE_LOCK must be released. |
| 1371 | * |
| 1372 | * Returns: |
| 1373 | * qla2x00 local function return status code. |
| 1374 | * |
| 1375 | * Context: |
| 1376 | * Kernel context. |
| 1377 | */ |
| 1378 | int |
| 1379 | qla2x00_send_sns(scsi_qla_host_t *ha, dma_addr_t sns_phys_address, |
| 1380 | uint16_t cmd_size, size_t buf_size) |
| 1381 | { |
| 1382 | int rval; |
| 1383 | mbx_cmd_t mc; |
| 1384 | mbx_cmd_t *mcp = &mc; |
| 1385 | |
| 1386 | DEBUG11(printk("qla2x00_send_sns(%ld): entered.\n", |
Andrew Vasquez | 744f11fd | 2006-06-23 16:11:05 -0700 | [diff] [blame] | 1387 | ha->host_no)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1388 | |
| 1389 | DEBUG11(printk("qla2x00_send_sns: retry cnt=%d ratov=%d total " |
Andrew Vasquez | 744f11fd | 2006-06-23 16:11:05 -0700 | [diff] [blame] | 1390 | "tov=%d.\n", ha->retry_count, ha->login_timeout, mcp->tov)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1391 | |
| 1392 | mcp->mb[0] = MBC_SEND_SNS_COMMAND; |
| 1393 | mcp->mb[1] = cmd_size; |
| 1394 | mcp->mb[2] = MSW(sns_phys_address); |
| 1395 | mcp->mb[3] = LSW(sns_phys_address); |
| 1396 | mcp->mb[6] = MSW(MSD(sns_phys_address)); |
| 1397 | mcp->mb[7] = LSW(MSD(sns_phys_address)); |
| 1398 | mcp->out_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0; |
| 1399 | mcp->in_mb = MBX_0|MBX_1; |
| 1400 | mcp->buf_size = buf_size; |
| 1401 | mcp->flags = MBX_DMA_OUT|MBX_DMA_IN; |
| 1402 | mcp->tov = (ha->login_timeout * 2) + (ha->login_timeout / 2); |
| 1403 | rval = qla2x00_mailbox_command(ha, mcp); |
| 1404 | |
| 1405 | if (rval != QLA_SUCCESS) { |
| 1406 | /*EMPTY*/ |
| 1407 | DEBUG(printk("qla2x00_send_sns(%ld): failed=%x mb[0]=%x " |
Andrew Vasquez | 744f11fd | 2006-06-23 16:11:05 -0700 | [diff] [blame] | 1408 | "mb[1]=%x.\n", ha->host_no, rval, mcp->mb[0], mcp->mb[1])); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1409 | DEBUG2_3_11(printk("qla2x00_send_sns(%ld): failed=%x mb[0]=%x " |
Andrew Vasquez | 744f11fd | 2006-06-23 16:11:05 -0700 | [diff] [blame] | 1410 | "mb[1]=%x.\n", ha->host_no, rval, mcp->mb[0], mcp->mb[1])); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1411 | } else { |
| 1412 | /*EMPTY*/ |
Andrew Vasquez | 744f11fd | 2006-06-23 16:11:05 -0700 | [diff] [blame] | 1413 | DEBUG11(printk("qla2x00_send_sns(%ld): done.\n", ha->host_no)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1414 | } |
| 1415 | |
| 1416 | return rval; |
| 1417 | } |
| 1418 | |
Andrew Vasquez | 1c7c635 | 2005-07-06 10:30:57 -0700 | [diff] [blame] | 1419 | int |
| 1420 | qla24xx_login_fabric(scsi_qla_host_t *ha, uint16_t loop_id, uint8_t domain, |
| 1421 | uint8_t area, uint8_t al_pa, uint16_t *mb, uint8_t opt) |
| 1422 | { |
| 1423 | int rval; |
| 1424 | |
| 1425 | struct logio_entry_24xx *lg; |
| 1426 | dma_addr_t lg_dma; |
| 1427 | uint32_t iop[2]; |
| 1428 | |
Andrew Vasquez | 744f11fd | 2006-06-23 16:11:05 -0700 | [diff] [blame] | 1429 | DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no)); |
Andrew Vasquez | 1c7c635 | 2005-07-06 10:30:57 -0700 | [diff] [blame] | 1430 | |
| 1431 | lg = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &lg_dma); |
| 1432 | if (lg == NULL) { |
| 1433 | DEBUG2_3(printk("%s(%ld): failed to allocate Login IOCB.\n", |
| 1434 | __func__, ha->host_no)); |
| 1435 | return QLA_MEMORY_ALLOC_FAILED; |
| 1436 | } |
| 1437 | memset(lg, 0, sizeof(struct logio_entry_24xx)); |
| 1438 | |
| 1439 | lg->entry_type = LOGINOUT_PORT_IOCB_TYPE; |
| 1440 | lg->entry_count = 1; |
| 1441 | lg->nport_handle = cpu_to_le16(loop_id); |
| 1442 | lg->control_flags = __constant_cpu_to_le16(LCF_COMMAND_PLOGI); |
| 1443 | if (opt & BIT_0) |
| 1444 | lg->control_flags |= __constant_cpu_to_le16(LCF_COND_PLOGI); |
Andrew Vasquez | 8baa51a | 2006-06-23 16:10:44 -0700 | [diff] [blame] | 1445 | if (opt & BIT_1) |
| 1446 | lg->control_flags |= __constant_cpu_to_le16(LCF_SKIP_PRLI); |
Andrew Vasquez | 1c7c635 | 2005-07-06 10:30:57 -0700 | [diff] [blame] | 1447 | lg->port_id[0] = al_pa; |
| 1448 | lg->port_id[1] = area; |
| 1449 | lg->port_id[2] = domain; |
| 1450 | rval = qla2x00_issue_iocb(ha, lg, lg_dma, 0); |
| 1451 | if (rval != QLA_SUCCESS) { |
| 1452 | DEBUG2_3_11(printk("%s(%ld): failed to issue Login IOCB " |
Andrew Vasquez | 744f11fd | 2006-06-23 16:11:05 -0700 | [diff] [blame] | 1453 | "(%x).\n", __func__, ha->host_no, rval)); |
Andrew Vasquez | 1c7c635 | 2005-07-06 10:30:57 -0700 | [diff] [blame] | 1454 | } else if (lg->entry_status != 0) { |
| 1455 | DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB " |
| 1456 | "-- error status (%x).\n", __func__, ha->host_no, |
| 1457 | lg->entry_status)); |
| 1458 | rval = QLA_FUNCTION_FAILED; |
| 1459 | } else if (lg->comp_status != __constant_cpu_to_le16(CS_COMPLETE)) { |
| 1460 | iop[0] = le32_to_cpu(lg->io_parameter[0]); |
| 1461 | iop[1] = le32_to_cpu(lg->io_parameter[1]); |
| 1462 | |
| 1463 | DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB " |
| 1464 | "-- completion status (%x) ioparam=%x/%x.\n", __func__, |
| 1465 | ha->host_no, le16_to_cpu(lg->comp_status), iop[0], |
| 1466 | iop[1])); |
| 1467 | |
| 1468 | switch (iop[0]) { |
| 1469 | case LSC_SCODE_PORTID_USED: |
| 1470 | mb[0] = MBS_PORT_ID_USED; |
| 1471 | mb[1] = LSW(iop[1]); |
| 1472 | break; |
| 1473 | case LSC_SCODE_NPORT_USED: |
| 1474 | mb[0] = MBS_LOOP_ID_USED; |
| 1475 | break; |
| 1476 | case LSC_SCODE_NOLINK: |
| 1477 | case LSC_SCODE_NOIOCB: |
| 1478 | case LSC_SCODE_NOXCB: |
| 1479 | case LSC_SCODE_CMD_FAILED: |
| 1480 | case LSC_SCODE_NOFABRIC: |
| 1481 | case LSC_SCODE_FW_NOT_READY: |
| 1482 | case LSC_SCODE_NOT_LOGGED_IN: |
| 1483 | case LSC_SCODE_NOPCB: |
| 1484 | case LSC_SCODE_ELS_REJECT: |
| 1485 | case LSC_SCODE_CMD_PARAM_ERR: |
| 1486 | case LSC_SCODE_NONPORT: |
| 1487 | case LSC_SCODE_LOGGED_IN: |
| 1488 | case LSC_SCODE_NOFLOGI_ACC: |
| 1489 | default: |
| 1490 | mb[0] = MBS_COMMAND_ERROR; |
| 1491 | break; |
| 1492 | } |
| 1493 | } else { |
Andrew Vasquez | 744f11fd | 2006-06-23 16:11:05 -0700 | [diff] [blame] | 1494 | DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no)); |
Andrew Vasquez | 1c7c635 | 2005-07-06 10:30:57 -0700 | [diff] [blame] | 1495 | |
| 1496 | iop[0] = le32_to_cpu(lg->io_parameter[0]); |
| 1497 | |
| 1498 | mb[0] = MBS_COMMAND_COMPLETE; |
| 1499 | mb[1] = 0; |
| 1500 | if (iop[0] & BIT_4) { |
| 1501 | if (iop[0] & BIT_8) |
| 1502 | mb[1] |= BIT_1; |
| 1503 | } else |
| 1504 | mb[1] = BIT_0; |
Andrew Vasquez | ad3e0ed | 2005-08-26 19:08:10 -0700 | [diff] [blame] | 1505 | |
| 1506 | /* Passback COS information. */ |
| 1507 | mb[10] = 0; |
| 1508 | if (lg->io_parameter[7] || lg->io_parameter[8]) |
| 1509 | mb[10] |= BIT_0; /* Class 2. */ |
| 1510 | if (lg->io_parameter[9] || lg->io_parameter[10]) |
| 1511 | mb[10] |= BIT_1; /* Class 3. */ |
Andrew Vasquez | 1c7c635 | 2005-07-06 10:30:57 -0700 | [diff] [blame] | 1512 | } |
| 1513 | |
| 1514 | dma_pool_free(ha->s_dma_pool, lg, lg_dma); |
| 1515 | |
| 1516 | return rval; |
| 1517 | } |
| 1518 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1519 | /* |
| 1520 | * qla2x00_login_fabric |
| 1521 | * Issue login fabric port mailbox command. |
| 1522 | * |
| 1523 | * Input: |
| 1524 | * ha = adapter block pointer. |
| 1525 | * loop_id = device loop ID. |
| 1526 | * domain = device domain. |
| 1527 | * area = device area. |
| 1528 | * al_pa = device AL_PA. |
| 1529 | * status = pointer for return status. |
| 1530 | * opt = command options. |
| 1531 | * TARGET_QUEUE_LOCK must be released. |
| 1532 | * ADAPTER_STATE_LOCK must be released. |
| 1533 | * |
| 1534 | * Returns: |
| 1535 | * qla2x00 local function return status code. |
| 1536 | * |
| 1537 | * Context: |
| 1538 | * Kernel context. |
| 1539 | */ |
| 1540 | int |
| 1541 | qla2x00_login_fabric(scsi_qla_host_t *ha, uint16_t loop_id, uint8_t domain, |
| 1542 | uint8_t area, uint8_t al_pa, uint16_t *mb, uint8_t opt) |
| 1543 | { |
| 1544 | int rval; |
| 1545 | mbx_cmd_t mc; |
| 1546 | mbx_cmd_t *mcp = &mc; |
| 1547 | |
Andrew Vasquez | 744f11fd | 2006-06-23 16:11:05 -0700 | [diff] [blame] | 1548 | DEBUG11(printk("qla2x00_login_fabric(%ld): entered.\n", ha->host_no)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1549 | |
| 1550 | mcp->mb[0] = MBC_LOGIN_FABRIC_PORT; |
| 1551 | mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0; |
| 1552 | if (HAS_EXTENDED_IDS(ha)) { |
| 1553 | mcp->mb[1] = loop_id; |
| 1554 | mcp->mb[10] = opt; |
| 1555 | mcp->out_mb |= MBX_10; |
| 1556 | } else { |
| 1557 | mcp->mb[1] = (loop_id << 8) | opt; |
| 1558 | } |
| 1559 | mcp->mb[2] = domain; |
| 1560 | mcp->mb[3] = area << 8 | al_pa; |
| 1561 | |
| 1562 | mcp->in_mb = MBX_7|MBX_6|MBX_2|MBX_1|MBX_0; |
| 1563 | mcp->tov = (ha->login_timeout * 2) + (ha->login_timeout / 2); |
| 1564 | mcp->flags = 0; |
| 1565 | rval = qla2x00_mailbox_command(ha, mcp); |
| 1566 | |
| 1567 | /* Return mailbox statuses. */ |
| 1568 | if (mb != NULL) { |
| 1569 | mb[0] = mcp->mb[0]; |
| 1570 | mb[1] = mcp->mb[1]; |
| 1571 | mb[2] = mcp->mb[2]; |
| 1572 | mb[6] = mcp->mb[6]; |
| 1573 | mb[7] = mcp->mb[7]; |
Andrew Vasquez | ad3e0ed | 2005-08-26 19:08:10 -0700 | [diff] [blame] | 1574 | /* COS retrieved from Get-Port-Database mailbox command. */ |
| 1575 | mb[10] = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1576 | } |
| 1577 | |
| 1578 | if (rval != QLA_SUCCESS) { |
| 1579 | /* RLU tmp code: need to change main mailbox_command function to |
| 1580 | * return ok even when the mailbox completion value is not |
| 1581 | * SUCCESS. The caller needs to be responsible to interpret |
| 1582 | * the return values of this mailbox command if we're not |
| 1583 | * to change too much of the existing code. |
| 1584 | */ |
| 1585 | if (mcp->mb[0] == 0x4001 || mcp->mb[0] == 0x4002 || |
| 1586 | mcp->mb[0] == 0x4003 || mcp->mb[0] == 0x4005 || |
| 1587 | mcp->mb[0] == 0x4006) |
| 1588 | rval = QLA_SUCCESS; |
| 1589 | |
| 1590 | /*EMPTY*/ |
| 1591 | DEBUG2_3_11(printk("qla2x00_login_fabric(%ld): failed=%x " |
| 1592 | "mb[0]=%x mb[1]=%x mb[2]=%x.\n", ha->host_no, rval, |
Andrew Vasquez | 744f11fd | 2006-06-23 16:11:05 -0700 | [diff] [blame] | 1593 | mcp->mb[0], mcp->mb[1], mcp->mb[2])); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1594 | } else { |
| 1595 | /*EMPTY*/ |
| 1596 | DEBUG11(printk("qla2x00_login_fabric(%ld): done.\n", |
Andrew Vasquez | 744f11fd | 2006-06-23 16:11:05 -0700 | [diff] [blame] | 1597 | ha->host_no)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1598 | } |
| 1599 | |
| 1600 | return rval; |
| 1601 | } |
| 1602 | |
| 1603 | /* |
| 1604 | * qla2x00_login_local_device |
| 1605 | * Issue login loop port mailbox command. |
Andrew Vasquez | fa2a1ce | 2005-07-06 10:32:07 -0700 | [diff] [blame] | 1606 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1607 | * Input: |
| 1608 | * ha = adapter block pointer. |
| 1609 | * loop_id = device loop ID. |
| 1610 | * opt = command options. |
Andrew Vasquez | fa2a1ce | 2005-07-06 10:32:07 -0700 | [diff] [blame] | 1611 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1612 | * Returns: |
| 1613 | * Return status code. |
Andrew Vasquez | fa2a1ce | 2005-07-06 10:32:07 -0700 | [diff] [blame] | 1614 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1615 | * Context: |
| 1616 | * Kernel context. |
Andrew Vasquez | fa2a1ce | 2005-07-06 10:32:07 -0700 | [diff] [blame] | 1617 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1618 | */ |
| 1619 | int |
andrew.vasquez@qlogic.com | 9a52a57 | 2006-03-09 14:27:44 -0800 | [diff] [blame] | 1620 | qla2x00_login_local_device(scsi_qla_host_t *ha, fc_port_t *fcport, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1621 | uint16_t *mb_ret, uint8_t opt) |
| 1622 | { |
| 1623 | int rval; |
| 1624 | mbx_cmd_t mc; |
| 1625 | mbx_cmd_t *mcp = &mc; |
| 1626 | |
andrew.vasquez@qlogic.com | 9a52a57 | 2006-03-09 14:27:44 -0800 | [diff] [blame] | 1627 | if (IS_QLA24XX(ha) || IS_QLA54XX(ha)) |
| 1628 | return qla24xx_login_fabric(ha, fcport->loop_id, |
| 1629 | fcport->d_id.b.domain, fcport->d_id.b.area, |
| 1630 | fcport->d_id.b.al_pa, mb_ret, opt); |
| 1631 | |
Andrew Vasquez | 744f11fd | 2006-06-23 16:11:05 -0700 | [diff] [blame] | 1632 | DEBUG3(printk("%s(%ld): entered.\n", __func__, ha->host_no)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1633 | |
| 1634 | mcp->mb[0] = MBC_LOGIN_LOOP_PORT; |
| 1635 | if (HAS_EXTENDED_IDS(ha)) |
andrew.vasquez@qlogic.com | 9a52a57 | 2006-03-09 14:27:44 -0800 | [diff] [blame] | 1636 | mcp->mb[1] = fcport->loop_id; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1637 | else |
andrew.vasquez@qlogic.com | 9a52a57 | 2006-03-09 14:27:44 -0800 | [diff] [blame] | 1638 | mcp->mb[1] = fcport->loop_id << 8; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1639 | mcp->mb[2] = opt; |
| 1640 | mcp->out_mb = MBX_2|MBX_1|MBX_0; |
| 1641 | mcp->in_mb = MBX_7|MBX_6|MBX_1|MBX_0; |
| 1642 | mcp->tov = (ha->login_timeout * 2) + (ha->login_timeout / 2); |
| 1643 | mcp->flags = 0; |
| 1644 | rval = qla2x00_mailbox_command(ha, mcp); |
| 1645 | |
| 1646 | /* Return mailbox statuses. */ |
| 1647 | if (mb_ret != NULL) { |
| 1648 | mb_ret[0] = mcp->mb[0]; |
| 1649 | mb_ret[1] = mcp->mb[1]; |
| 1650 | mb_ret[6] = mcp->mb[6]; |
| 1651 | mb_ret[7] = mcp->mb[7]; |
| 1652 | } |
| 1653 | |
| 1654 | if (rval != QLA_SUCCESS) { |
| 1655 | /* AV tmp code: need to change main mailbox_command function to |
| 1656 | * return ok even when the mailbox completion value is not |
| 1657 | * SUCCESS. The caller needs to be responsible to interpret |
| 1658 | * the return values of this mailbox command if we're not |
| 1659 | * to change too much of the existing code. |
| 1660 | */ |
| 1661 | if (mcp->mb[0] == 0x4005 || mcp->mb[0] == 0x4006) |
| 1662 | rval = QLA_SUCCESS; |
| 1663 | |
| 1664 | DEBUG(printk("%s(%ld): failed=%x mb[0]=%x mb[1]=%x " |
| 1665 | "mb[6]=%x mb[7]=%x.\n", __func__, ha->host_no, rval, |
Andrew Vasquez | 744f11fd | 2006-06-23 16:11:05 -0700 | [diff] [blame] | 1666 | mcp->mb[0], mcp->mb[1], mcp->mb[6], mcp->mb[7])); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1667 | DEBUG2_3(printk("%s(%ld): failed=%x mb[0]=%x mb[1]=%x " |
| 1668 | "mb[6]=%x mb[7]=%x.\n", __func__, ha->host_no, rval, |
Andrew Vasquez | 744f11fd | 2006-06-23 16:11:05 -0700 | [diff] [blame] | 1669 | mcp->mb[0], mcp->mb[1], mcp->mb[6], mcp->mb[7])); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1670 | } else { |
| 1671 | /*EMPTY*/ |
Andrew Vasquez | 744f11fd | 2006-06-23 16:11:05 -0700 | [diff] [blame] | 1672 | DEBUG3(printk("%s(%ld): done.\n", __func__, ha->host_no)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1673 | } |
| 1674 | |
| 1675 | return (rval); |
| 1676 | } |
| 1677 | |
Andrew Vasquez | 1c7c635 | 2005-07-06 10:30:57 -0700 | [diff] [blame] | 1678 | int |
| 1679 | qla24xx_fabric_logout(scsi_qla_host_t *ha, uint16_t loop_id, uint8_t domain, |
| 1680 | uint8_t area, uint8_t al_pa) |
| 1681 | { |
| 1682 | int rval; |
| 1683 | struct logio_entry_24xx *lg; |
| 1684 | dma_addr_t lg_dma; |
| 1685 | |
Andrew Vasquez | 744f11fd | 2006-06-23 16:11:05 -0700 | [diff] [blame] | 1686 | DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no)); |
Andrew Vasquez | 1c7c635 | 2005-07-06 10:30:57 -0700 | [diff] [blame] | 1687 | |
| 1688 | lg = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &lg_dma); |
| 1689 | if (lg == NULL) { |
| 1690 | DEBUG2_3(printk("%s(%ld): failed to allocate Logout IOCB.\n", |
| 1691 | __func__, ha->host_no)); |
| 1692 | return QLA_MEMORY_ALLOC_FAILED; |
| 1693 | } |
| 1694 | memset(lg, 0, sizeof(struct logio_entry_24xx)); |
| 1695 | |
| 1696 | lg->entry_type = LOGINOUT_PORT_IOCB_TYPE; |
| 1697 | lg->entry_count = 1; |
| 1698 | lg->nport_handle = cpu_to_le16(loop_id); |
| 1699 | lg->control_flags = |
Lalit Chandivade | b1372bc | 2007-01-29 10:22:22 -0800 | [diff] [blame] | 1700 | __constant_cpu_to_le16(LCF_COMMAND_LOGO|LCF_IMPL_LOGO); |
Andrew Vasquez | 1c7c635 | 2005-07-06 10:30:57 -0700 | [diff] [blame] | 1701 | lg->port_id[0] = al_pa; |
| 1702 | lg->port_id[1] = area; |
| 1703 | lg->port_id[2] = domain; |
| 1704 | rval = qla2x00_issue_iocb(ha, lg, lg_dma, 0); |
| 1705 | if (rval != QLA_SUCCESS) { |
| 1706 | DEBUG2_3_11(printk("%s(%ld): failed to issue Logout IOCB " |
Andrew Vasquez | 744f11fd | 2006-06-23 16:11:05 -0700 | [diff] [blame] | 1707 | "(%x).\n", __func__, ha->host_no, rval)); |
Andrew Vasquez | 1c7c635 | 2005-07-06 10:30:57 -0700 | [diff] [blame] | 1708 | } else if (lg->entry_status != 0) { |
| 1709 | DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB " |
| 1710 | "-- error status (%x).\n", __func__, ha->host_no, |
| 1711 | lg->entry_status)); |
| 1712 | rval = QLA_FUNCTION_FAILED; |
| 1713 | } else if (lg->comp_status != __constant_cpu_to_le16(CS_COMPLETE)) { |
| 1714 | DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB " |
| 1715 | "-- completion status (%x) ioparam=%x/%x.\n", __func__, |
| 1716 | ha->host_no, le16_to_cpu(lg->comp_status), |
| 1717 | le32_to_cpu(lg->io_parameter[0]), |
Andrew Vasquez | 744f11fd | 2006-06-23 16:11:05 -0700 | [diff] [blame] | 1718 | le32_to_cpu(lg->io_parameter[1]))); |
Andrew Vasquez | 1c7c635 | 2005-07-06 10:30:57 -0700 | [diff] [blame] | 1719 | } else { |
| 1720 | /*EMPTY*/ |
Andrew Vasquez | 744f11fd | 2006-06-23 16:11:05 -0700 | [diff] [blame] | 1721 | DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no)); |
Andrew Vasquez | 1c7c635 | 2005-07-06 10:30:57 -0700 | [diff] [blame] | 1722 | } |
| 1723 | |
| 1724 | dma_pool_free(ha->s_dma_pool, lg, lg_dma); |
| 1725 | |
| 1726 | return rval; |
| 1727 | } |
| 1728 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1729 | /* |
| 1730 | * qla2x00_fabric_logout |
| 1731 | * Issue logout fabric port mailbox command. |
| 1732 | * |
| 1733 | * Input: |
| 1734 | * ha = adapter block pointer. |
| 1735 | * loop_id = device loop ID. |
| 1736 | * TARGET_QUEUE_LOCK must be released. |
| 1737 | * ADAPTER_STATE_LOCK must be released. |
| 1738 | * |
| 1739 | * Returns: |
| 1740 | * qla2x00 local function return status code. |
| 1741 | * |
| 1742 | * Context: |
| 1743 | * Kernel context. |
| 1744 | */ |
| 1745 | int |
Andrew Vasquez | 1c7c635 | 2005-07-06 10:30:57 -0700 | [diff] [blame] | 1746 | qla2x00_fabric_logout(scsi_qla_host_t *ha, uint16_t loop_id, uint8_t domain, |
| 1747 | uint8_t area, uint8_t al_pa) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1748 | { |
| 1749 | int rval; |
| 1750 | mbx_cmd_t mc; |
| 1751 | mbx_cmd_t *mcp = &mc; |
| 1752 | |
| 1753 | DEBUG11(printk("qla2x00_fabric_logout(%ld): entered.\n", |
Andrew Vasquez | 744f11fd | 2006-06-23 16:11:05 -0700 | [diff] [blame] | 1754 | ha->host_no)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1755 | |
| 1756 | mcp->mb[0] = MBC_LOGOUT_FABRIC_PORT; |
| 1757 | mcp->out_mb = MBX_1|MBX_0; |
| 1758 | if (HAS_EXTENDED_IDS(ha)) { |
| 1759 | mcp->mb[1] = loop_id; |
| 1760 | mcp->mb[10] = 0; |
| 1761 | mcp->out_mb |= MBX_10; |
| 1762 | } else { |
| 1763 | mcp->mb[1] = loop_id << 8; |
| 1764 | } |
| 1765 | |
| 1766 | mcp->in_mb = MBX_1|MBX_0; |
| 1767 | mcp->tov = 30; |
| 1768 | mcp->flags = 0; |
| 1769 | rval = qla2x00_mailbox_command(ha, mcp); |
| 1770 | |
| 1771 | if (rval != QLA_SUCCESS) { |
| 1772 | /*EMPTY*/ |
| 1773 | DEBUG2_3_11(printk("qla2x00_fabric_logout(%ld): failed=%x " |
Andrew Vasquez | 744f11fd | 2006-06-23 16:11:05 -0700 | [diff] [blame] | 1774 | "mbx1=%x.\n", ha->host_no, rval, mcp->mb[1])); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1775 | } else { |
| 1776 | /*EMPTY*/ |
| 1777 | DEBUG11(printk("qla2x00_fabric_logout(%ld): done.\n", |
Andrew Vasquez | 744f11fd | 2006-06-23 16:11:05 -0700 | [diff] [blame] | 1778 | ha->host_no)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1779 | } |
| 1780 | |
| 1781 | return rval; |
| 1782 | } |
| 1783 | |
| 1784 | /* |
| 1785 | * qla2x00_full_login_lip |
| 1786 | * Issue full login LIP mailbox command. |
| 1787 | * |
| 1788 | * Input: |
| 1789 | * ha = adapter block pointer. |
| 1790 | * TARGET_QUEUE_LOCK must be released. |
| 1791 | * ADAPTER_STATE_LOCK must be released. |
| 1792 | * |
| 1793 | * Returns: |
| 1794 | * qla2x00 local function return status code. |
| 1795 | * |
| 1796 | * Context: |
| 1797 | * Kernel context. |
| 1798 | */ |
| 1799 | int |
| 1800 | qla2x00_full_login_lip(scsi_qla_host_t *ha) |
| 1801 | { |
| 1802 | int rval; |
| 1803 | mbx_cmd_t mc; |
| 1804 | mbx_cmd_t *mcp = &mc; |
| 1805 | |
| 1806 | DEBUG11(printk("qla2x00_full_login_lip(%ld): entered.\n", |
Andrew Vasquez | 744f11fd | 2006-06-23 16:11:05 -0700 | [diff] [blame] | 1807 | ha->host_no)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1808 | |
| 1809 | mcp->mb[0] = MBC_LIP_FULL_LOGIN; |
Andrew Vasquez | 0c8c39a | 2006-12-13 19:20:30 -0800 | [diff] [blame] | 1810 | mcp->mb[1] = IS_QLA24XX(ha) || IS_QLA54XX(ha) ? BIT_3: 0; |
| 1811 | mcp->mb[2] = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1812 | mcp->mb[3] = 0; |
| 1813 | mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0; |
| 1814 | mcp->in_mb = MBX_0; |
| 1815 | mcp->tov = 30; |
| 1816 | mcp->flags = 0; |
| 1817 | rval = qla2x00_mailbox_command(ha, mcp); |
| 1818 | |
| 1819 | if (rval != QLA_SUCCESS) { |
| 1820 | /*EMPTY*/ |
| 1821 | DEBUG2_3_11(printk("qla2x00_full_login_lip(%ld): failed=%x.\n", |
Andrew Vasquez | 744f11fd | 2006-06-23 16:11:05 -0700 | [diff] [blame] | 1822 | ha->host_no, rval)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1823 | } else { |
| 1824 | /*EMPTY*/ |
| 1825 | DEBUG11(printk("qla2x00_full_login_lip(%ld): done.\n", |
Andrew Vasquez | 744f11fd | 2006-06-23 16:11:05 -0700 | [diff] [blame] | 1826 | ha->host_no)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1827 | } |
| 1828 | |
| 1829 | return rval; |
| 1830 | } |
| 1831 | |
| 1832 | /* |
| 1833 | * qla2x00_get_id_list |
| 1834 | * |
| 1835 | * Input: |
| 1836 | * ha = adapter block pointer. |
| 1837 | * |
| 1838 | * Returns: |
| 1839 | * qla2x00 local function return status code. |
| 1840 | * |
| 1841 | * Context: |
| 1842 | * Kernel context. |
| 1843 | */ |
| 1844 | int |
| 1845 | qla2x00_get_id_list(scsi_qla_host_t *ha, void *id_list, dma_addr_t id_list_dma, |
| 1846 | uint16_t *entries) |
| 1847 | { |
| 1848 | int rval; |
| 1849 | mbx_cmd_t mc; |
| 1850 | mbx_cmd_t *mcp = &mc; |
| 1851 | |
| 1852 | DEBUG11(printk("qla2x00_get_id_list(%ld): entered.\n", |
Andrew Vasquez | 744f11fd | 2006-06-23 16:11:05 -0700 | [diff] [blame] | 1853 | ha->host_no)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1854 | |
| 1855 | if (id_list == NULL) |
| 1856 | return QLA_FUNCTION_FAILED; |
| 1857 | |
| 1858 | mcp->mb[0] = MBC_GET_ID_LIST; |
Andrew Vasquez | 1c7c635 | 2005-07-06 10:30:57 -0700 | [diff] [blame] | 1859 | mcp->out_mb = MBX_0; |
andrew.vasquez@qlogic.com | 044cc6c | 2006-03-09 14:27:13 -0800 | [diff] [blame] | 1860 | if (IS_QLA24XX(ha) || IS_QLA54XX(ha)) { |
Andrew Vasquez | 1c7c635 | 2005-07-06 10:30:57 -0700 | [diff] [blame] | 1861 | mcp->mb[2] = MSW(id_list_dma); |
| 1862 | mcp->mb[3] = LSW(id_list_dma); |
| 1863 | mcp->mb[6] = MSW(MSD(id_list_dma)); |
| 1864 | mcp->mb[7] = LSW(MSD(id_list_dma)); |
andrew.vasquez@qlogic.com | 247ec45 | 2006-02-07 08:45:40 -0800 | [diff] [blame] | 1865 | mcp->mb[8] = 0; |
| 1866 | mcp->out_mb |= MBX_8|MBX_7|MBX_6|MBX_3|MBX_2; |
Andrew Vasquez | 1c7c635 | 2005-07-06 10:30:57 -0700 | [diff] [blame] | 1867 | } else { |
| 1868 | mcp->mb[1] = MSW(id_list_dma); |
| 1869 | mcp->mb[2] = LSW(id_list_dma); |
| 1870 | mcp->mb[3] = MSW(MSD(id_list_dma)); |
| 1871 | mcp->mb[6] = LSW(MSD(id_list_dma)); |
| 1872 | mcp->out_mb |= MBX_6|MBX_3|MBX_2|MBX_1; |
| 1873 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1874 | mcp->in_mb = MBX_1|MBX_0; |
| 1875 | mcp->tov = 30; |
| 1876 | mcp->flags = 0; |
| 1877 | rval = qla2x00_mailbox_command(ha, mcp); |
| 1878 | |
| 1879 | if (rval != QLA_SUCCESS) { |
| 1880 | /*EMPTY*/ |
| 1881 | DEBUG2_3_11(printk("qla2x00_get_id_list(%ld): failed=%x.\n", |
Andrew Vasquez | 744f11fd | 2006-06-23 16:11:05 -0700 | [diff] [blame] | 1882 | ha->host_no, rval)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1883 | } else { |
| 1884 | *entries = mcp->mb[1]; |
| 1885 | DEBUG11(printk("qla2x00_get_id_list(%ld): done.\n", |
Andrew Vasquez | 744f11fd | 2006-06-23 16:11:05 -0700 | [diff] [blame] | 1886 | ha->host_no)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1887 | } |
| 1888 | |
| 1889 | return rval; |
| 1890 | } |
| 1891 | |
| 1892 | /* |
| 1893 | * qla2x00_get_resource_cnts |
| 1894 | * Get current firmware resource counts. |
| 1895 | * |
| 1896 | * Input: |
| 1897 | * ha = adapter block pointer. |
| 1898 | * |
| 1899 | * Returns: |
| 1900 | * qla2x00 local function return status code. |
| 1901 | * |
| 1902 | * Context: |
| 1903 | * Kernel context. |
| 1904 | */ |
| 1905 | int |
| 1906 | qla2x00_get_resource_cnts(scsi_qla_host_t *ha, uint16_t *cur_xchg_cnt, |
| 1907 | uint16_t *orig_xchg_cnt, uint16_t *cur_iocb_cnt, uint16_t *orig_iocb_cnt) |
| 1908 | { |
| 1909 | int rval; |
| 1910 | mbx_cmd_t mc; |
| 1911 | mbx_cmd_t *mcp = &mc; |
| 1912 | |
| 1913 | DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no)); |
| 1914 | |
| 1915 | mcp->mb[0] = MBC_GET_RESOURCE_COUNTS; |
| 1916 | mcp->out_mb = MBX_0; |
| 1917 | mcp->in_mb = MBX_10|MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0; |
| 1918 | mcp->tov = 30; |
| 1919 | mcp->flags = 0; |
| 1920 | rval = qla2x00_mailbox_command(ha, mcp); |
| 1921 | |
| 1922 | if (rval != QLA_SUCCESS) { |
| 1923 | /*EMPTY*/ |
| 1924 | DEBUG2_3_11(printk("%s(%ld): failed = %x.\n", __func__, |
Andrew Vasquez | 744f11fd | 2006-06-23 16:11:05 -0700 | [diff] [blame] | 1925 | ha->host_no, mcp->mb[0])); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1926 | } else { |
| 1927 | DEBUG11(printk("%s(%ld): done. mb1=%x mb2=%x mb3=%x mb6=%x " |
| 1928 | "mb7=%x mb10=%x.\n", __func__, ha->host_no, |
Andrew Vasquez | fa2a1ce | 2005-07-06 10:32:07 -0700 | [diff] [blame] | 1929 | mcp->mb[1], mcp->mb[2], mcp->mb[3], mcp->mb[6], mcp->mb[7], |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1930 | mcp->mb[10])); |
| 1931 | |
| 1932 | if (cur_xchg_cnt) |
| 1933 | *cur_xchg_cnt = mcp->mb[3]; |
| 1934 | if (orig_xchg_cnt) |
| 1935 | *orig_xchg_cnt = mcp->mb[6]; |
| 1936 | if (cur_iocb_cnt) |
| 1937 | *cur_iocb_cnt = mcp->mb[7]; |
| 1938 | if (orig_iocb_cnt) |
| 1939 | *orig_iocb_cnt = mcp->mb[10]; |
| 1940 | } |
| 1941 | |
| 1942 | return (rval); |
| 1943 | } |
| 1944 | |
| 1945 | #if defined(QL_DEBUG_LEVEL_3) |
| 1946 | /* |
| 1947 | * qla2x00_get_fcal_position_map |
| 1948 | * Get FCAL (LILP) position map using mailbox command |
| 1949 | * |
| 1950 | * Input: |
| 1951 | * ha = adapter state pointer. |
| 1952 | * pos_map = buffer pointer (can be NULL). |
| 1953 | * |
| 1954 | * Returns: |
| 1955 | * qla2x00 local function return status code. |
| 1956 | * |
| 1957 | * Context: |
| 1958 | * Kernel context. |
| 1959 | */ |
| 1960 | int |
| 1961 | qla2x00_get_fcal_position_map(scsi_qla_host_t *ha, char *pos_map) |
| 1962 | { |
| 1963 | int rval; |
| 1964 | mbx_cmd_t mc; |
| 1965 | mbx_cmd_t *mcp = &mc; |
| 1966 | char *pmap; |
| 1967 | dma_addr_t pmap_dma; |
| 1968 | |
| 1969 | pmap = dma_pool_alloc(ha->s_dma_pool, GFP_ATOMIC, &pmap_dma); |
| 1970 | if (pmap == NULL) { |
| 1971 | DEBUG2_3_11(printk("%s(%ld): **** Mem Alloc Failed ****", |
| 1972 | __func__, ha->host_no)); |
| 1973 | return QLA_MEMORY_ALLOC_FAILED; |
| 1974 | } |
| 1975 | memset(pmap, 0, FCAL_MAP_SIZE); |
| 1976 | |
| 1977 | mcp->mb[0] = MBC_GET_FC_AL_POSITION_MAP; |
| 1978 | mcp->mb[2] = MSW(pmap_dma); |
| 1979 | mcp->mb[3] = LSW(pmap_dma); |
| 1980 | mcp->mb[6] = MSW(MSD(pmap_dma)); |
| 1981 | mcp->mb[7] = LSW(MSD(pmap_dma)); |
| 1982 | mcp->out_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_0; |
| 1983 | mcp->in_mb = MBX_1|MBX_0; |
| 1984 | mcp->buf_size = FCAL_MAP_SIZE; |
| 1985 | mcp->flags = MBX_DMA_IN; |
| 1986 | mcp->tov = (ha->login_timeout * 2) + (ha->login_timeout / 2); |
| 1987 | rval = qla2x00_mailbox_command(ha, mcp); |
| 1988 | |
| 1989 | if (rval == QLA_SUCCESS) { |
| 1990 | DEBUG11(printk("%s(%ld): (mb0=%x/mb1=%x) FC/AL Position Map " |
| 1991 | "size (%x)\n", __func__, ha->host_no, mcp->mb[0], |
| 1992 | mcp->mb[1], (unsigned)pmap[0])); |
| 1993 | DEBUG11(qla2x00_dump_buffer(pmap, pmap[0] + 1)); |
| 1994 | |
| 1995 | if (pos_map) |
| 1996 | memcpy(pos_map, pmap, FCAL_MAP_SIZE); |
| 1997 | } |
| 1998 | dma_pool_free(ha->s_dma_pool, pmap, pmap_dma); |
| 1999 | |
| 2000 | if (rval != QLA_SUCCESS) { |
| 2001 | DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__, |
| 2002 | ha->host_no, rval)); |
| 2003 | } else { |
| 2004 | DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no)); |
| 2005 | } |
| 2006 | |
| 2007 | return rval; |
| 2008 | } |
andrew.vasquez@qlogic.com | 392e2f6 | 2006-01-31 16:05:02 -0800 | [diff] [blame] | 2009 | #endif |
Andrew Vasquez | 1c7c635 | 2005-07-06 10:30:57 -0700 | [diff] [blame] | 2010 | |
andrew.vasquez@qlogic.com | 392e2f6 | 2006-01-31 16:05:02 -0800 | [diff] [blame] | 2011 | /* |
| 2012 | * qla2x00_get_link_status |
| 2013 | * |
| 2014 | * Input: |
| 2015 | * ha = adapter block pointer. |
| 2016 | * loop_id = device loop ID. |
| 2017 | * ret_buf = pointer to link status return buffer. |
| 2018 | * |
| 2019 | * Returns: |
| 2020 | * 0 = success. |
| 2021 | * BIT_0 = mem alloc error. |
| 2022 | * BIT_1 = mailbox error. |
| 2023 | */ |
| 2024 | int |
| 2025 | qla2x00_get_link_status(scsi_qla_host_t *ha, uint16_t loop_id, |
| 2026 | link_stat_t *ret_buf, uint16_t *status) |
| 2027 | { |
| 2028 | int rval; |
| 2029 | mbx_cmd_t mc; |
| 2030 | mbx_cmd_t *mcp = &mc; |
| 2031 | link_stat_t *stat_buf; |
| 2032 | dma_addr_t stat_buf_dma; |
| 2033 | |
Andrew Vasquez | 744f11fd | 2006-06-23 16:11:05 -0700 | [diff] [blame] | 2034 | DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no)); |
andrew.vasquez@qlogic.com | 392e2f6 | 2006-01-31 16:05:02 -0800 | [diff] [blame] | 2035 | |
| 2036 | stat_buf = dma_pool_alloc(ha->s_dma_pool, GFP_ATOMIC, &stat_buf_dma); |
| 2037 | if (stat_buf == NULL) { |
| 2038 | DEBUG2_3_11(printk("%s(%ld): Failed to allocate memory.\n", |
| 2039 | __func__, ha->host_no)); |
| 2040 | return BIT_0; |
| 2041 | } |
| 2042 | memset(stat_buf, 0, sizeof(link_stat_t)); |
| 2043 | |
| 2044 | mcp->mb[0] = MBC_GET_LINK_STATUS; |
| 2045 | mcp->mb[2] = MSW(stat_buf_dma); |
| 2046 | mcp->mb[3] = LSW(stat_buf_dma); |
| 2047 | mcp->mb[6] = MSW(MSD(stat_buf_dma)); |
| 2048 | mcp->mb[7] = LSW(MSD(stat_buf_dma)); |
| 2049 | mcp->out_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_0; |
| 2050 | mcp->in_mb = MBX_0; |
andrew.vasquez@qlogic.com | 044cc6c | 2006-03-09 14:27:13 -0800 | [diff] [blame] | 2051 | if (IS_QLA24XX(ha) || IS_QLA54XX(ha)) { |
andrew.vasquez@qlogic.com | 392e2f6 | 2006-01-31 16:05:02 -0800 | [diff] [blame] | 2052 | mcp->mb[1] = loop_id; |
| 2053 | mcp->mb[4] = 0; |
| 2054 | mcp->mb[10] = 0; |
| 2055 | mcp->out_mb |= MBX_10|MBX_4|MBX_1; |
| 2056 | mcp->in_mb |= MBX_1; |
| 2057 | } else if (HAS_EXTENDED_IDS(ha)) { |
| 2058 | mcp->mb[1] = loop_id; |
| 2059 | mcp->mb[10] = 0; |
| 2060 | mcp->out_mb |= MBX_10|MBX_1; |
| 2061 | } else { |
| 2062 | mcp->mb[1] = loop_id << 8; |
| 2063 | mcp->out_mb |= MBX_1; |
| 2064 | } |
| 2065 | mcp->tov = 30; |
| 2066 | mcp->flags = IOCTL_CMD; |
| 2067 | rval = qla2x00_mailbox_command(ha, mcp); |
| 2068 | |
| 2069 | if (rval == QLA_SUCCESS) { |
| 2070 | if (mcp->mb[0] != MBS_COMMAND_COMPLETE) { |
| 2071 | DEBUG2_3_11(printk("%s(%ld): cmd failed. mbx0=%x.\n", |
Andrew Vasquez | 744f11fd | 2006-06-23 16:11:05 -0700 | [diff] [blame] | 2072 | __func__, ha->host_no, mcp->mb[0])); |
andrew.vasquez@qlogic.com | 392e2f6 | 2006-01-31 16:05:02 -0800 | [diff] [blame] | 2073 | status[0] = mcp->mb[0]; |
| 2074 | rval = BIT_1; |
| 2075 | } else { |
| 2076 | /* copy over data -- firmware data is LE. */ |
| 2077 | ret_buf->link_fail_cnt = |
| 2078 | le32_to_cpu(stat_buf->link_fail_cnt); |
| 2079 | ret_buf->loss_sync_cnt = |
| 2080 | le32_to_cpu(stat_buf->loss_sync_cnt); |
| 2081 | ret_buf->loss_sig_cnt = |
| 2082 | le32_to_cpu(stat_buf->loss_sig_cnt); |
| 2083 | ret_buf->prim_seq_err_cnt = |
| 2084 | le32_to_cpu(stat_buf->prim_seq_err_cnt); |
| 2085 | ret_buf->inval_xmit_word_cnt = |
| 2086 | le32_to_cpu(stat_buf->inval_xmit_word_cnt); |
| 2087 | ret_buf->inval_crc_cnt = |
| 2088 | le32_to_cpu(stat_buf->inval_crc_cnt); |
| 2089 | |
| 2090 | DEBUG11(printk("%s(%ld): stat dump: fail_cnt=%d " |
| 2091 | "loss_sync=%d loss_sig=%d seq_err=%d " |
| 2092 | "inval_xmt_word=%d inval_crc=%d.\n", __func__, |
| 2093 | ha->host_no, stat_buf->link_fail_cnt, |
| 2094 | stat_buf->loss_sync_cnt, stat_buf->loss_sig_cnt, |
| 2095 | stat_buf->prim_seq_err_cnt, |
| 2096 | stat_buf->inval_xmit_word_cnt, |
Andrew Vasquez | 744f11fd | 2006-06-23 16:11:05 -0700 | [diff] [blame] | 2097 | stat_buf->inval_crc_cnt)); |
andrew.vasquez@qlogic.com | 392e2f6 | 2006-01-31 16:05:02 -0800 | [diff] [blame] | 2098 | } |
| 2099 | } else { |
| 2100 | /* Failed. */ |
| 2101 | DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__, |
Andrew Vasquez | 744f11fd | 2006-06-23 16:11:05 -0700 | [diff] [blame] | 2102 | ha->host_no, rval)); |
andrew.vasquez@qlogic.com | 392e2f6 | 2006-01-31 16:05:02 -0800 | [diff] [blame] | 2103 | rval = BIT_1; |
| 2104 | } |
| 2105 | |
| 2106 | dma_pool_free(ha->s_dma_pool, stat_buf, stat_buf_dma); |
| 2107 | |
| 2108 | return rval; |
| 2109 | } |
| 2110 | |
| 2111 | int |
Andrew Vasquez | 1c7c635 | 2005-07-06 10:30:57 -0700 | [diff] [blame] | 2112 | qla24xx_get_isp_stats(scsi_qla_host_t *ha, uint32_t *dwbuf, uint32_t dwords, |
| 2113 | uint16_t *status) |
| 2114 | { |
| 2115 | int rval; |
| 2116 | mbx_cmd_t mc; |
| 2117 | mbx_cmd_t *mcp = &mc; |
| 2118 | uint32_t *sbuf, *siter; |
| 2119 | dma_addr_t sbuf_dma; |
| 2120 | |
Andrew Vasquez | 744f11fd | 2006-06-23 16:11:05 -0700 | [diff] [blame] | 2121 | DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no)); |
Andrew Vasquez | 1c7c635 | 2005-07-06 10:30:57 -0700 | [diff] [blame] | 2122 | |
| 2123 | if (dwords > (DMA_POOL_SIZE / 4)) { |
| 2124 | DEBUG2_3_11(printk("%s(%ld): Unabled to retrieve %d DWORDs " |
| 2125 | "(max %d).\n", __func__, ha->host_no, dwords, |
| 2126 | DMA_POOL_SIZE / 4)); |
| 2127 | return BIT_0; |
| 2128 | } |
| 2129 | sbuf = dma_pool_alloc(ha->s_dma_pool, GFP_ATOMIC, &sbuf_dma); |
| 2130 | if (sbuf == NULL) { |
| 2131 | DEBUG2_3_11(printk("%s(%ld): Failed to allocate memory.\n", |
| 2132 | __func__, ha->host_no)); |
| 2133 | return BIT_0; |
| 2134 | } |
| 2135 | memset(sbuf, 0, DMA_POOL_SIZE); |
| 2136 | |
| 2137 | mcp->mb[0] = MBC_GET_LINK_PRIV_STATS; |
| 2138 | mcp->mb[2] = MSW(sbuf_dma); |
| 2139 | mcp->mb[3] = LSW(sbuf_dma); |
| 2140 | mcp->mb[6] = MSW(MSD(sbuf_dma)); |
| 2141 | mcp->mb[7] = LSW(MSD(sbuf_dma)); |
| 2142 | mcp->mb[8] = dwords; |
| 2143 | mcp->mb[10] = 0; |
| 2144 | mcp->out_mb = MBX_10|MBX_8|MBX_7|MBX_6|MBX_3|MBX_2|MBX_0; |
| 2145 | mcp->in_mb = MBX_2|MBX_1|MBX_0; |
| 2146 | mcp->tov = 30; |
| 2147 | mcp->flags = IOCTL_CMD; |
| 2148 | rval = qla2x00_mailbox_command(ha, mcp); |
| 2149 | |
| 2150 | if (rval == QLA_SUCCESS) { |
| 2151 | if (mcp->mb[0] != MBS_COMMAND_COMPLETE) { |
| 2152 | DEBUG2_3_11(printk("%s(%ld): cmd failed. mbx0=%x.\n", |
| 2153 | __func__, ha->host_no, mcp->mb[0])); |
| 2154 | status[0] = mcp->mb[0]; |
| 2155 | rval = BIT_1; |
| 2156 | } else { |
| 2157 | /* Copy over data -- firmware data is LE. */ |
| 2158 | siter = sbuf; |
| 2159 | while (dwords--) |
| 2160 | *dwbuf++ = le32_to_cpu(*siter++); |
| 2161 | } |
| 2162 | } else { |
| 2163 | /* Failed. */ |
| 2164 | DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__, |
| 2165 | ha->host_no, rval)); |
| 2166 | rval = BIT_1; |
| 2167 | } |
| 2168 | |
| 2169 | dma_pool_free(ha->s_dma_pool, sbuf, sbuf_dma); |
| 2170 | |
| 2171 | return rval; |
| 2172 | } |
Andrew Vasquez | 1c7c635 | 2005-07-06 10:30:57 -0700 | [diff] [blame] | 2173 | |
| 2174 | int |
| 2175 | qla24xx_abort_command(scsi_qla_host_t *ha, srb_t *sp) |
| 2176 | { |
| 2177 | int rval; |
| 2178 | fc_port_t *fcport; |
| 2179 | unsigned long flags = 0; |
| 2180 | |
| 2181 | struct abort_entry_24xx *abt; |
| 2182 | dma_addr_t abt_dma; |
| 2183 | uint32_t handle; |
| 2184 | |
Andrew Vasquez | 744f11fd | 2006-06-23 16:11:05 -0700 | [diff] [blame] | 2185 | DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no)); |
Andrew Vasquez | 1c7c635 | 2005-07-06 10:30:57 -0700 | [diff] [blame] | 2186 | |
| 2187 | fcport = sp->fcport; |
Andrew Vasquez | 1c7c635 | 2005-07-06 10:30:57 -0700 | [diff] [blame] | 2188 | |
| 2189 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 2190 | for (handle = 1; handle < MAX_OUTSTANDING_COMMANDS; handle++) { |
| 2191 | if (ha->outstanding_cmds[handle] == sp) |
| 2192 | break; |
| 2193 | } |
| 2194 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 2195 | if (handle == MAX_OUTSTANDING_COMMANDS) { |
| 2196 | /* Command not found. */ |
| 2197 | return QLA_FUNCTION_FAILED; |
| 2198 | } |
| 2199 | |
| 2200 | abt = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &abt_dma); |
| 2201 | if (abt == NULL) { |
| 2202 | DEBUG2_3(printk("%s(%ld): failed to allocate Abort IOCB.\n", |
| 2203 | __func__, ha->host_no)); |
| 2204 | return QLA_MEMORY_ALLOC_FAILED; |
| 2205 | } |
| 2206 | memset(abt, 0, sizeof(struct abort_entry_24xx)); |
| 2207 | |
| 2208 | abt->entry_type = ABORT_IOCB_TYPE; |
| 2209 | abt->entry_count = 1; |
| 2210 | abt->nport_handle = cpu_to_le16(fcport->loop_id); |
| 2211 | abt->handle_to_abort = handle; |
| 2212 | abt->port_id[0] = fcport->d_id.b.al_pa; |
| 2213 | abt->port_id[1] = fcport->d_id.b.area; |
| 2214 | abt->port_id[2] = fcport->d_id.b.domain; |
| 2215 | rval = qla2x00_issue_iocb(ha, abt, abt_dma, 0); |
| 2216 | if (rval != QLA_SUCCESS) { |
| 2217 | DEBUG2_3_11(printk("%s(%ld): failed to issue IOCB (%x).\n", |
Andrew Vasquez | 744f11fd | 2006-06-23 16:11:05 -0700 | [diff] [blame] | 2218 | __func__, ha->host_no, rval)); |
Andrew Vasquez | 1c7c635 | 2005-07-06 10:30:57 -0700 | [diff] [blame] | 2219 | } else if (abt->entry_status != 0) { |
| 2220 | DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB " |
| 2221 | "-- error status (%x).\n", __func__, ha->host_no, |
| 2222 | abt->entry_status)); |
| 2223 | rval = QLA_FUNCTION_FAILED; |
| 2224 | } else if (abt->nport_handle != __constant_cpu_to_le16(0)) { |
| 2225 | DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB " |
| 2226 | "-- completion status (%x).\n", __func__, ha->host_no, |
Andrew Vasquez | 744f11fd | 2006-06-23 16:11:05 -0700 | [diff] [blame] | 2227 | le16_to_cpu(abt->nport_handle))); |
Andrew Vasquez | 1c7c635 | 2005-07-06 10:30:57 -0700 | [diff] [blame] | 2228 | rval = QLA_FUNCTION_FAILED; |
| 2229 | } else { |
Andrew Vasquez | 744f11fd | 2006-06-23 16:11:05 -0700 | [diff] [blame] | 2230 | DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no)); |
Andrew Vasquez | 1c7c635 | 2005-07-06 10:30:57 -0700 | [diff] [blame] | 2231 | sp->flags |= SRB_ABORT_PENDING; |
| 2232 | } |
| 2233 | |
| 2234 | dma_pool_free(ha->s_dma_pool, abt, abt_dma); |
| 2235 | |
| 2236 | return rval; |
| 2237 | } |
| 2238 | |
| 2239 | struct tsk_mgmt_cmd { |
| 2240 | union { |
| 2241 | struct tsk_mgmt_entry tsk; |
| 2242 | struct sts_entry_24xx sts; |
| 2243 | } p; |
| 2244 | }; |
| 2245 | |
| 2246 | int |
| 2247 | qla24xx_abort_target(fc_port_t *fcport) |
| 2248 | { |
| 2249 | int rval; |
| 2250 | struct tsk_mgmt_cmd *tsk; |
| 2251 | dma_addr_t tsk_dma; |
| 2252 | scsi_qla_host_t *ha; |
| 2253 | |
| 2254 | if (fcport == NULL) |
| 2255 | return 0; |
| 2256 | |
Andrew Vasquez | 744f11fd | 2006-06-23 16:11:05 -0700 | [diff] [blame] | 2257 | DEBUG11(printk("%s(%ld): entered.\n", __func__, fcport->ha->host_no)); |
Andrew Vasquez | 1c7c635 | 2005-07-06 10:30:57 -0700 | [diff] [blame] | 2258 | |
| 2259 | ha = fcport->ha; |
| 2260 | tsk = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &tsk_dma); |
| 2261 | if (tsk == NULL) { |
| 2262 | DEBUG2_3(printk("%s(%ld): failed to allocate Task Management " |
| 2263 | "IOCB.\n", __func__, ha->host_no)); |
| 2264 | return QLA_MEMORY_ALLOC_FAILED; |
| 2265 | } |
| 2266 | memset(tsk, 0, sizeof(struct tsk_mgmt_cmd)); |
| 2267 | |
| 2268 | tsk->p.tsk.entry_type = TSK_MGMT_IOCB_TYPE; |
| 2269 | tsk->p.tsk.entry_count = 1; |
| 2270 | tsk->p.tsk.nport_handle = cpu_to_le16(fcport->loop_id); |
| 2271 | tsk->p.tsk.timeout = __constant_cpu_to_le16(25); |
| 2272 | tsk->p.tsk.control_flags = __constant_cpu_to_le32(TCF_TARGET_RESET); |
| 2273 | tsk->p.tsk.port_id[0] = fcport->d_id.b.al_pa; |
| 2274 | tsk->p.tsk.port_id[1] = fcport->d_id.b.area; |
| 2275 | tsk->p.tsk.port_id[2] = fcport->d_id.b.domain; |
| 2276 | rval = qla2x00_issue_iocb(ha, tsk, tsk_dma, 0); |
| 2277 | if (rval != QLA_SUCCESS) { |
| 2278 | DEBUG2_3_11(printk("%s(%ld): failed to issue Target Reset IOCB " |
Andrew Vasquez | 744f11fd | 2006-06-23 16:11:05 -0700 | [diff] [blame] | 2279 | "(%x).\n", __func__, ha->host_no, rval)); |
Andrew Vasquez | 1c7c635 | 2005-07-06 10:30:57 -0700 | [diff] [blame] | 2280 | goto atarget_done; |
| 2281 | } else if (tsk->p.sts.entry_status != 0) { |
| 2282 | DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB " |
| 2283 | "-- error status (%x).\n", __func__, ha->host_no, |
| 2284 | tsk->p.sts.entry_status)); |
| 2285 | rval = QLA_FUNCTION_FAILED; |
| 2286 | goto atarget_done; |
| 2287 | } else if (tsk->p.sts.comp_status != |
| 2288 | __constant_cpu_to_le16(CS_COMPLETE)) { |
| 2289 | DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB " |
| 2290 | "-- completion status (%x).\n", __func__, |
Andrew Vasquez | 744f11fd | 2006-06-23 16:11:05 -0700 | [diff] [blame] | 2291 | ha->host_no, le16_to_cpu(tsk->p.sts.comp_status))); |
Andrew Vasquez | 1c7c635 | 2005-07-06 10:30:57 -0700 | [diff] [blame] | 2292 | rval = QLA_FUNCTION_FAILED; |
| 2293 | goto atarget_done; |
| 2294 | } |
| 2295 | |
| 2296 | /* Issue marker IOCB. */ |
| 2297 | rval = qla2x00_marker(ha, fcport->loop_id, 0, MK_SYNC_ID); |
| 2298 | if (rval != QLA_SUCCESS) { |
| 2299 | DEBUG2_3_11(printk("%s(%ld): failed to issue Marker IOCB " |
Andrew Vasquez | 744f11fd | 2006-06-23 16:11:05 -0700 | [diff] [blame] | 2300 | "(%x).\n", __func__, ha->host_no, rval)); |
Andrew Vasquez | 1c7c635 | 2005-07-06 10:30:57 -0700 | [diff] [blame] | 2301 | } else { |
Andrew Vasquez | 744f11fd | 2006-06-23 16:11:05 -0700 | [diff] [blame] | 2302 | DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no)); |
Andrew Vasquez | 1c7c635 | 2005-07-06 10:30:57 -0700 | [diff] [blame] | 2303 | } |
| 2304 | |
| 2305 | atarget_done: |
| 2306 | dma_pool_free(ha->s_dma_pool, tsk, tsk_dma); |
| 2307 | |
| 2308 | return rval; |
| 2309 | } |
| 2310 | |
| 2311 | int |
| 2312 | qla2x00_system_error(scsi_qla_host_t *ha) |
| 2313 | { |
| 2314 | int rval; |
| 2315 | mbx_cmd_t mc; |
| 2316 | mbx_cmd_t *mcp = &mc; |
| 2317 | |
andrew.vasquez@qlogic.com | 044cc6c | 2006-03-09 14:27:13 -0800 | [diff] [blame] | 2318 | if (!IS_QLA24XX(ha) && !IS_QLA54XX(ha)) |
Andrew Vasquez | 1c7c635 | 2005-07-06 10:30:57 -0700 | [diff] [blame] | 2319 | return QLA_FUNCTION_FAILED; |
| 2320 | |
| 2321 | DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no)); |
| 2322 | |
| 2323 | mcp->mb[0] = MBC_GEN_SYSTEM_ERROR; |
| 2324 | mcp->out_mb = MBX_0; |
| 2325 | mcp->in_mb = MBX_0; |
| 2326 | mcp->tov = 5; |
| 2327 | mcp->flags = 0; |
| 2328 | rval = qla2x00_mailbox_command(ha, mcp); |
| 2329 | |
| 2330 | if (rval != QLA_SUCCESS) { |
| 2331 | DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__, |
| 2332 | ha->host_no, rval)); |
| 2333 | } else { |
| 2334 | DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no)); |
| 2335 | } |
| 2336 | |
| 2337 | return rval; |
| 2338 | } |
| 2339 | |
| 2340 | /** |
| 2341 | * qla2x00_get_serdes_params() - |
| 2342 | * @ha: HA context |
| 2343 | * |
| 2344 | * Returns |
| 2345 | */ |
| 2346 | int |
| 2347 | qla2x00_get_serdes_params(scsi_qla_host_t *ha, uint16_t *sw_em_1g, |
| 2348 | uint16_t *sw_em_2g, uint16_t *sw_em_4g) |
| 2349 | { |
| 2350 | int rval; |
| 2351 | mbx_cmd_t mc; |
| 2352 | mbx_cmd_t *mcp = &mc; |
| 2353 | |
| 2354 | DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no)); |
| 2355 | |
| 2356 | mcp->mb[0] = MBC_SERDES_PARAMS; |
| 2357 | mcp->mb[1] = 0; |
| 2358 | mcp->out_mb = MBX_1|MBX_0; |
| 2359 | mcp->in_mb = MBX_4|MBX_3|MBX_2|MBX_0; |
| 2360 | mcp->tov = 30; |
| 2361 | mcp->flags = 0; |
| 2362 | rval = qla2x00_mailbox_command(ha, mcp); |
| 2363 | |
| 2364 | if (rval != QLA_SUCCESS) { |
| 2365 | /*EMPTY*/ |
| 2366 | DEBUG2_3_11(printk("%s(%ld): failed=%x (%x).\n", __func__, |
| 2367 | ha->host_no, rval, mcp->mb[0])); |
| 2368 | } else { |
| 2369 | DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no)); |
| 2370 | |
| 2371 | if (sw_em_1g) |
| 2372 | *sw_em_1g = mcp->mb[2]; |
| 2373 | if (sw_em_2g) |
| 2374 | *sw_em_2g = mcp->mb[3]; |
| 2375 | if (sw_em_4g) |
| 2376 | *sw_em_4g = mcp->mb[4]; |
| 2377 | } |
| 2378 | |
| 2379 | return rval; |
| 2380 | } |
| 2381 | |
| 2382 | /** |
| 2383 | * qla2x00_set_serdes_params() - |
| 2384 | * @ha: HA context |
| 2385 | * |
| 2386 | * Returns |
| 2387 | */ |
| 2388 | int |
| 2389 | qla2x00_set_serdes_params(scsi_qla_host_t *ha, uint16_t sw_em_1g, |
| 2390 | uint16_t sw_em_2g, uint16_t sw_em_4g) |
| 2391 | { |
| 2392 | int rval; |
| 2393 | mbx_cmd_t mc; |
| 2394 | mbx_cmd_t *mcp = &mc; |
| 2395 | |
| 2396 | DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no)); |
| 2397 | |
| 2398 | mcp->mb[0] = MBC_SERDES_PARAMS; |
| 2399 | mcp->mb[1] = BIT_0; |
andrew.vasquez@qlogic.com | fdbc683 | 2006-03-09 14:27:29 -0800 | [diff] [blame] | 2400 | mcp->mb[2] = sw_em_1g | BIT_15; |
| 2401 | mcp->mb[3] = sw_em_2g | BIT_15; |
| 2402 | mcp->mb[4] = sw_em_4g | BIT_15; |
Andrew Vasquez | 1c7c635 | 2005-07-06 10:30:57 -0700 | [diff] [blame] | 2403 | mcp->out_mb = MBX_4|MBX_3|MBX_2|MBX_1|MBX_0; |
| 2404 | mcp->in_mb = MBX_0; |
| 2405 | mcp->tov = 30; |
| 2406 | mcp->flags = 0; |
| 2407 | rval = qla2x00_mailbox_command(ha, mcp); |
| 2408 | |
| 2409 | if (rval != QLA_SUCCESS) { |
| 2410 | /*EMPTY*/ |
| 2411 | DEBUG2_3_11(printk("%s(%ld): failed=%x (%x).\n", __func__, |
| 2412 | ha->host_no, rval, mcp->mb[0])); |
| 2413 | } else { |
| 2414 | /*EMPTY*/ |
| 2415 | DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no)); |
| 2416 | } |
| 2417 | |
| 2418 | return rval; |
| 2419 | } |
Andrew Vasquez | f6ef3b1 | 2005-08-26 19:10:20 -0700 | [diff] [blame] | 2420 | |
| 2421 | int |
| 2422 | qla2x00_stop_firmware(scsi_qla_host_t *ha) |
| 2423 | { |
| 2424 | int rval; |
| 2425 | mbx_cmd_t mc; |
| 2426 | mbx_cmd_t *mcp = &mc; |
| 2427 | |
andrew.vasquez@qlogic.com | 044cc6c | 2006-03-09 14:27:13 -0800 | [diff] [blame] | 2428 | if (!IS_QLA24XX(ha) && !IS_QLA54XX(ha)) |
Andrew Vasquez | f6ef3b1 | 2005-08-26 19:10:20 -0700 | [diff] [blame] | 2429 | return QLA_FUNCTION_FAILED; |
| 2430 | |
| 2431 | DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no)); |
| 2432 | |
| 2433 | mcp->mb[0] = MBC_STOP_FIRMWARE; |
| 2434 | mcp->out_mb = MBX_0; |
| 2435 | mcp->in_mb = MBX_0; |
| 2436 | mcp->tov = 5; |
| 2437 | mcp->flags = 0; |
| 2438 | rval = qla2x00_mailbox_command(ha, mcp); |
| 2439 | |
| 2440 | if (rval != QLA_SUCCESS) { |
| 2441 | DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__, |
| 2442 | ha->host_no, rval)); |
| 2443 | } else { |
| 2444 | DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no)); |
| 2445 | } |
| 2446 | |
| 2447 | return rval; |
| 2448 | } |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 2449 | |
| 2450 | int |
| 2451 | qla2x00_trace_control(scsi_qla_host_t *ha, uint16_t ctrl, dma_addr_t eft_dma, |
| 2452 | uint16_t buffers) |
| 2453 | { |
| 2454 | int rval; |
| 2455 | mbx_cmd_t mc; |
| 2456 | mbx_cmd_t *mcp = &mc; |
| 2457 | |
| 2458 | if (!IS_QLA24XX(ha) && !IS_QLA54XX(ha)) |
| 2459 | return QLA_FUNCTION_FAILED; |
| 2460 | |
| 2461 | DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no)); |
| 2462 | |
| 2463 | mcp->mb[0] = MBC_TRACE_CONTROL; |
| 2464 | mcp->mb[1] = ctrl; |
| 2465 | mcp->out_mb = MBX_1|MBX_0; |
| 2466 | mcp->in_mb = MBX_1|MBX_0; |
| 2467 | if (ctrl == TC_ENABLE) { |
| 2468 | mcp->mb[2] = LSW(eft_dma); |
| 2469 | mcp->mb[3] = MSW(eft_dma); |
| 2470 | mcp->mb[4] = LSW(MSD(eft_dma)); |
| 2471 | mcp->mb[5] = MSW(MSD(eft_dma)); |
| 2472 | mcp->mb[6] = buffers; |
Andrew Vasquez | 87b2380 | 2006-12-13 19:20:25 -0800 | [diff] [blame] | 2473 | mcp->mb[7] = 0; |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 2474 | mcp->out_mb |= MBX_7|MBX_6|MBX_5|MBX_4|MBX_3|MBX_2; |
| 2475 | } |
| 2476 | mcp->tov = 30; |
| 2477 | mcp->flags = 0; |
| 2478 | rval = qla2x00_mailbox_command(ha, mcp); |
| 2479 | |
| 2480 | if (rval != QLA_SUCCESS) { |
| 2481 | DEBUG2_3_11(printk("%s(%ld): failed=%x mb[0]=%x mb[1]=%x.\n", |
| 2482 | __func__, ha->host_no, rval, mcp->mb[0], mcp->mb[1])); |
| 2483 | } else { |
| 2484 | DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no)); |
| 2485 | } |
| 2486 | |
| 2487 | return rval; |
| 2488 | } |
| 2489 | |
Andrew Vasquez | 88729e5 | 2006-06-23 16:10:50 -0700 | [diff] [blame] | 2490 | int |
| 2491 | qla2x00_read_sfp(scsi_qla_host_t *ha, dma_addr_t sfp_dma, uint16_t addr, |
| 2492 | uint16_t off, uint16_t count) |
| 2493 | { |
| 2494 | int rval; |
| 2495 | mbx_cmd_t mc; |
| 2496 | mbx_cmd_t *mcp = &mc; |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 2497 | |
Andrew Vasquez | 88729e5 | 2006-06-23 16:10:50 -0700 | [diff] [blame] | 2498 | if (!IS_QLA24XX(ha) && !IS_QLA54XX(ha)) |
| 2499 | return QLA_FUNCTION_FAILED; |
| 2500 | |
| 2501 | DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no)); |
| 2502 | |
| 2503 | mcp->mb[0] = MBC_READ_SFP; |
| 2504 | mcp->mb[1] = addr; |
| 2505 | mcp->mb[2] = MSW(sfp_dma); |
| 2506 | mcp->mb[3] = LSW(sfp_dma); |
| 2507 | mcp->mb[6] = MSW(MSD(sfp_dma)); |
| 2508 | mcp->mb[7] = LSW(MSD(sfp_dma)); |
| 2509 | mcp->mb[8] = count; |
| 2510 | mcp->mb[9] = off; |
| 2511 | mcp->mb[10] = 0; |
| 2512 | mcp->out_mb = MBX_10|MBX_9|MBX_8|MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0; |
| 2513 | mcp->in_mb = MBX_0; |
| 2514 | mcp->tov = 30; |
| 2515 | mcp->flags = 0; |
| 2516 | rval = qla2x00_mailbox_command(ha, mcp); |
| 2517 | |
| 2518 | if (rval != QLA_SUCCESS) { |
| 2519 | DEBUG2_3_11(printk("%s(%ld): failed=%x (%x).\n", __func__, |
| 2520 | ha->host_no, rval, mcp->mb[0])); |
| 2521 | } else { |
| 2522 | DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no)); |
| 2523 | } |
| 2524 | |
| 2525 | return rval; |
| 2526 | } |
Andrew Vasquez | d8b4521 | 2006-10-02 12:00:43 -0700 | [diff] [blame] | 2527 | |
| 2528 | int |
| 2529 | qla2x00_get_idma_speed(scsi_qla_host_t *ha, uint16_t loop_id, |
| 2530 | uint16_t *port_speed, uint16_t *mb) |
| 2531 | { |
| 2532 | int rval; |
| 2533 | mbx_cmd_t mc; |
| 2534 | mbx_cmd_t *mcp = &mc; |
| 2535 | |
| 2536 | if (!IS_QLA24XX(ha)) |
| 2537 | return QLA_FUNCTION_FAILED; |
| 2538 | |
| 2539 | DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no)); |
| 2540 | |
| 2541 | mcp->mb[0] = MBC_PORT_PARAMS; |
| 2542 | mcp->mb[1] = loop_id; |
| 2543 | mcp->mb[2] = mcp->mb[3] = mcp->mb[4] = mcp->mb[5] = 0; |
| 2544 | mcp->out_mb = MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0; |
| 2545 | mcp->in_mb = MBX_5|MBX_4|MBX_3|MBX_1|MBX_0; |
| 2546 | mcp->tov = 30; |
| 2547 | mcp->flags = 0; |
| 2548 | rval = qla2x00_mailbox_command(ha, mcp); |
| 2549 | |
| 2550 | /* Return mailbox statuses. */ |
| 2551 | if (mb != NULL) { |
| 2552 | mb[0] = mcp->mb[0]; |
| 2553 | mb[1] = mcp->mb[1]; |
| 2554 | mb[3] = mcp->mb[3]; |
| 2555 | mb[4] = mcp->mb[4]; |
| 2556 | mb[5] = mcp->mb[5]; |
| 2557 | } |
| 2558 | |
| 2559 | if (rval != QLA_SUCCESS) { |
| 2560 | DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__, |
| 2561 | ha->host_no, rval)); |
| 2562 | } else { |
| 2563 | DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no)); |
| 2564 | if (port_speed) |
| 2565 | *port_speed = mcp->mb[3]; |
| 2566 | } |
| 2567 | |
| 2568 | return rval; |
| 2569 | } |
| 2570 | |
| 2571 | int |
| 2572 | qla2x00_set_idma_speed(scsi_qla_host_t *ha, uint16_t loop_id, |
| 2573 | uint16_t port_speed, uint16_t *mb) |
| 2574 | { |
| 2575 | int rval; |
| 2576 | mbx_cmd_t mc; |
| 2577 | mbx_cmd_t *mcp = &mc; |
| 2578 | |
| 2579 | if (!IS_QLA24XX(ha)) |
| 2580 | return QLA_FUNCTION_FAILED; |
| 2581 | |
| 2582 | DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no)); |
| 2583 | |
| 2584 | mcp->mb[0] = MBC_PORT_PARAMS; |
| 2585 | mcp->mb[1] = loop_id; |
| 2586 | mcp->mb[2] = BIT_0; |
| 2587 | mcp->mb[3] = port_speed & (BIT_2|BIT_1|BIT_0); |
| 2588 | mcp->mb[4] = mcp->mb[5] = 0; |
| 2589 | mcp->out_mb = MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0; |
| 2590 | mcp->in_mb = MBX_5|MBX_4|MBX_3|MBX_1|MBX_0; |
| 2591 | mcp->tov = 30; |
| 2592 | mcp->flags = 0; |
| 2593 | rval = qla2x00_mailbox_command(ha, mcp); |
| 2594 | |
| 2595 | /* Return mailbox statuses. */ |
| 2596 | if (mb != NULL) { |
| 2597 | mb[0] = mcp->mb[0]; |
| 2598 | mb[1] = mcp->mb[1]; |
| 2599 | mb[3] = mcp->mb[3]; |
| 2600 | mb[4] = mcp->mb[4]; |
| 2601 | mb[5] = mcp->mb[5]; |
| 2602 | } |
| 2603 | |
| 2604 | if (rval != QLA_SUCCESS) { |
| 2605 | DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__, |
| 2606 | ha->host_no, rval)); |
| 2607 | } else { |
| 2608 | DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no)); |
| 2609 | } |
| 2610 | |
| 2611 | return rval; |
| 2612 | } |