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