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