blob: 1003e48d22005e1104a18ac1a678a866fe161311 [file] [log] [blame]
David Somayajuluafaf5a22006-09-19 10:28:00 -07001/*
2 * QLogic iSCSI HBA Driver
3 * Copyright (c) 2003-2006 QLogic Corporation
4 *
5 * See LICENSE.qla4xxx for copyright and licensing details.
6 */
7
8#include "ql4_def.h"
David C Somayajuluc0e344c2007-05-23 18:03:27 -07009#include "ql4_glbl.h"
10#include "ql4_dbg.h"
11#include "ql4_inline.h"
David Somayajuluafaf5a22006-09-19 10:28:00 -070012
13
14/**
15 * qla4xxx_mailbox_command - issues mailbox commands
16 * @ha: Pointer to host adapter structure.
17 * @inCount: number of mailbox registers to load.
18 * @outCount: number of mailbox registers to return.
19 * @mbx_cmd: data pointer for mailbox in registers.
20 * @mbx_sts: data pointer for mailbox out registers.
21 *
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +053022 * This routine isssue mailbox commands and waits for completion.
David Somayajuluafaf5a22006-09-19 10:28:00 -070023 * If outCount is 0, this routine completes successfully WITHOUT waiting
24 * for the mailbox command to complete.
25 **/
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +053026int qla4xxx_mailbox_command(struct scsi_qla_host *ha, uint8_t inCount,
27 uint8_t outCount, uint32_t *mbx_cmd,
28 uint32_t *mbx_sts)
David Somayajuluafaf5a22006-09-19 10:28:00 -070029{
30 int status = QLA_ERROR;
31 uint8_t i;
32 u_long wait_count;
33 uint32_t intr_status;
34 unsigned long flags = 0;
David Somayajuluafaf5a22006-09-19 10:28:00 -070035
36 /* Make sure that pointers are valid */
37 if (!mbx_cmd || !mbx_sts) {
38 DEBUG2(printk("scsi%ld: %s: Invalid mbx_cmd or mbx_sts "
39 "pointer\n", ha->host_no, __func__));
David C Somayajulu477ffb92007-01-22 12:26:11 -080040 return status;
41 }
Nilesh Javali21033632010-07-30 14:28:07 +053042
43 if (is_qla8022(ha) &&
44 test_bit(AF_FW_RECOVERY, &ha->flags)) {
45 DEBUG2(ql4_printk(KERN_WARNING, ha, "scsi%ld: %s: prematurely "
46 "completing mbx cmd as firmware recovery detected\n",
47 ha->host_no, __func__));
48 return status;
49 }
50
David C Somayajulu477ffb92007-01-22 12:26:11 -080051 /* Mailbox code active */
52 wait_count = MBOX_TOV * 100;
53
54 while (wait_count--) {
55 mutex_lock(&ha->mbox_sem);
56 if (!test_bit(AF_MBOX_COMMAND, &ha->flags)) {
57 set_bit(AF_MBOX_COMMAND, &ha->flags);
58 mutex_unlock(&ha->mbox_sem);
59 break;
60 }
61 mutex_unlock(&ha->mbox_sem);
62 if (!wait_count) {
63 DEBUG2(printk("scsi%ld: %s: mbox_sem failed\n",
64 ha->host_no, __func__));
65 return status;
66 }
67 msleep(10);
David Somayajuluafaf5a22006-09-19 10:28:00 -070068 }
69
70 /* To prevent overwriting mailbox registers for a command that has
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +053071 * not yet been serviced, check to see if an active command
72 * (AEN, IOCB, etc.) is interrupting, then service it.
David Somayajuluafaf5a22006-09-19 10:28:00 -070073 * -----------------------------------------------------------------
74 */
75 spin_lock_irqsave(&ha->hardware_lock, flags);
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +053076
77 if (is_qla8022(ha)) {
78 intr_status = readl(&ha->qla4_8xxx_reg->host_int);
79 if (intr_status & ISRX_82XX_RISC_INT) {
80 /* Service existing interrupt */
81 DEBUG2(printk("scsi%ld: %s: "
82 "servicing existing interrupt\n",
83 ha->host_no, __func__));
84 intr_status = readl(&ha->qla4_8xxx_reg->host_status);
85 ha->isp_ops->interrupt_service_routine(ha, intr_status);
86 clear_bit(AF_MBOX_COMMAND_DONE, &ha->flags);
87 if (test_bit(AF_INTERRUPTS_ON, &ha->flags) &&
88 test_bit(AF_INTx_ENABLED, &ha->flags))
89 qla4_8xxx_wr_32(ha,
90 ha->nx_legacy_intr.tgt_mask_reg,
91 0xfbff);
92 }
93 } else {
94 intr_status = readl(&ha->reg->ctrl_status);
95 if (intr_status & CSR_SCSI_PROCESSOR_INTR) {
96 /* Service existing interrupt */
97 ha->isp_ops->interrupt_service_routine(ha, intr_status);
98 clear_bit(AF_MBOX_COMMAND_DONE, &ha->flags);
99 }
David Somayajuluafaf5a22006-09-19 10:28:00 -0700100 }
101
David Somayajuluafaf5a22006-09-19 10:28:00 -0700102 ha->mbox_status_count = outCount;
103 for (i = 0; i < outCount; i++)
104 ha->mbox_status[i] = 0;
105
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +0530106 if (is_qla8022(ha)) {
107 /* Load all mailbox registers, except mailbox 0. */
108 DEBUG5(
109 printk("scsi%ld: %s: Cmd ", ha->host_no, __func__);
110 for (i = 0; i < inCount; i++)
111 printk("mb%d=%04x ", i, mbx_cmd[i]);
112 printk("\n"));
David Somayajuluafaf5a22006-09-19 10:28:00 -0700113
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +0530114 for (i = 1; i < inCount; i++)
115 writel(mbx_cmd[i], &ha->qla4_8xxx_reg->mailbox_in[i]);
116 writel(mbx_cmd[0], &ha->qla4_8xxx_reg->mailbox_in[0]);
117 readl(&ha->qla4_8xxx_reg->mailbox_in[0]);
118 writel(HINT_MBX_INT_PENDING, &ha->qla4_8xxx_reg->hint);
119 } else {
120 /* Load all mailbox registers, except mailbox 0. */
121 for (i = 1; i < inCount; i++)
122 writel(mbx_cmd[i], &ha->reg->mailbox[i]);
123
124 /* Wakeup firmware */
125 writel(mbx_cmd[0], &ha->reg->mailbox[0]);
126 readl(&ha->reg->mailbox[0]);
127 writel(set_rmask(CSR_INTR_RISC), &ha->reg->ctrl_status);
128 readl(&ha->reg->ctrl_status);
129 }
130
David Somayajuluafaf5a22006-09-19 10:28:00 -0700131 spin_unlock_irqrestore(&ha->hardware_lock, flags);
132
133 /* Wait for completion */
David Somayajuluafaf5a22006-09-19 10:28:00 -0700134
135 /*
136 * If we don't want status, don't wait for the mailbox command to
137 * complete. For example, MBOX_CMD_RESET_FW doesn't return status,
138 * you must poll the inbound Interrupt Mask for completion.
139 */
140 if (outCount == 0) {
141 status = QLA_SUCCESS;
David Somayajuluafaf5a22006-09-19 10:28:00 -0700142 goto mbox_exit;
143 }
David Somayajuluafaf5a22006-09-19 10:28:00 -0700144
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +0530145 /*
146 * Wait for completion: Poll or completion queue
147 */
148 if (test_bit(AF_IRQ_ATTACHED, &ha->flags) &&
149 test_bit(AF_INTERRUPTS_ON, &ha->flags) &&
150 test_bit(AF_ONLINE, &ha->flags) &&
151 !test_bit(AF_HBA_GOING_AWAY, &ha->flags)) {
152 /* Do not poll for completion. Use completion queue */
153 set_bit(AF_MBOX_COMMAND_NOPOLL, &ha->flags);
154 wait_for_completion_timeout(&ha->mbx_intr_comp, MBOX_TOV * HZ);
155 clear_bit(AF_MBOX_COMMAND_NOPOLL, &ha->flags);
156 } else {
157 /* Poll for command to complete */
158 wait_count = jiffies + MBOX_TOV * HZ;
159 while (test_bit(AF_MBOX_COMMAND_DONE, &ha->flags) == 0) {
160 if (time_after_eq(jiffies, wait_count))
161 break;
David Somayajuluafaf5a22006-09-19 10:28:00 -0700162 /*
163 * Service the interrupt.
164 * The ISR will save the mailbox status registers
165 * to a temporary storage location in the adapter
166 * structure.
167 */
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +0530168
169 spin_lock_irqsave(&ha->hardware_lock, flags);
170 if (is_qla8022(ha)) {
171 intr_status =
172 readl(&ha->qla4_8xxx_reg->host_int);
173 if (intr_status & ISRX_82XX_RISC_INT) {
174 ha->mbox_status_count = outCount;
175 intr_status =
176 readl(&ha->qla4_8xxx_reg->host_status);
177 ha->isp_ops->interrupt_service_routine(
178 ha, intr_status);
179 if (test_bit(AF_INTERRUPTS_ON,
180 &ha->flags) &&
181 test_bit(AF_INTx_ENABLED,
182 &ha->flags))
183 qla4_8xxx_wr_32(ha,
184 ha->nx_legacy_intr.tgt_mask_reg,
185 0xfbff);
186 }
187 } else {
188 intr_status = readl(&ha->reg->ctrl_status);
189 if (intr_status & INTR_PENDING) {
190 /*
191 * Service the interrupt.
192 * The ISR will save the mailbox status
193 * registers to a temporary storage
194 * location in the adapter structure.
195 */
196 ha->mbox_status_count = outCount;
197 ha->isp_ops->interrupt_service_routine(
198 ha, intr_status);
199 }
200 }
201 spin_unlock_irqrestore(&ha->hardware_lock, flags);
202 msleep(10);
David Somayajuluafaf5a22006-09-19 10:28:00 -0700203 }
David Somayajuluafaf5a22006-09-19 10:28:00 -0700204 }
David Somayajuluafaf5a22006-09-19 10:28:00 -0700205
206 /* Check for mailbox timeout. */
207 if (!test_bit(AF_MBOX_COMMAND_DONE, &ha->flags)) {
Nilesh Javali21033632010-07-30 14:28:07 +0530208 if (is_qla8022(ha) &&
209 test_bit(AF_FW_RECOVERY, &ha->flags)) {
210 DEBUG2(ql4_printk(KERN_INFO, ha,
211 "scsi%ld: %s: prematurely completing mbx cmd as "
212 "firmware recovery detected\n",
213 ha->host_no, __func__));
214 goto mbox_exit;
215 }
David Somayajuluafaf5a22006-09-19 10:28:00 -0700216 DEBUG2(printk("scsi%ld: Mailbox Cmd 0x%08X timed out ...,"
217 " Scheduling Adapter Reset\n", ha->host_no,
218 mbx_cmd[0]));
219 ha->mailbox_timeout_count++;
220 mbx_sts[0] = (-1);
221 set_bit(DPC_RESET_HA, &ha->dpc_flags);
222 goto mbox_exit;
223 }
224
225 /*
226 * Copy the mailbox out registers to the caller's mailbox in/out
227 * structure.
228 */
229 spin_lock_irqsave(&ha->hardware_lock, flags);
230 for (i = 0; i < outCount; i++)
231 mbx_sts[i] = ha->mbox_status[i];
232
233 /* Set return status and error flags (if applicable). */
234 switch (ha->mbox_status[0]) {
235 case MBOX_STS_COMMAND_COMPLETE:
236 status = QLA_SUCCESS;
237 break;
238
239 case MBOX_STS_INTERMEDIATE_COMPLETION:
240 status = QLA_SUCCESS;
241 break;
242
243 case MBOX_STS_BUSY:
244 DEBUG2( printk("scsi%ld: %s: Cmd = %08X, ISP BUSY\n",
245 ha->host_no, __func__, mbx_cmd[0]));
246 ha->mailbox_timeout_count++;
247 break;
248
249 default:
250 DEBUG2(printk("scsi%ld: %s: **** FAILED, cmd = %08X, "
251 "sts = %08X ****\n", ha->host_no, __func__,
252 mbx_cmd[0], mbx_sts[0]));
253 break;
254 }
255 spin_unlock_irqrestore(&ha->hardware_lock, flags);
256
257mbox_exit:
David C Somayajulu477ffb92007-01-22 12:26:11 -0800258 mutex_lock(&ha->mbox_sem);
David Somayajuluafaf5a22006-09-19 10:28:00 -0700259 clear_bit(AF_MBOX_COMMAND, &ha->flags);
David Somayajuluafaf5a22006-09-19 10:28:00 -0700260 mutex_unlock(&ha->mbox_sem);
David C Somayajulu477ffb92007-01-22 12:26:11 -0800261 clear_bit(AF_MBOX_COMMAND_DONE, &ha->flags);
David Somayajuluafaf5a22006-09-19 10:28:00 -0700262
263 return status;
264}
265
Nilesh Javali21033632010-07-30 14:28:07 +0530266void qla4xxx_mailbox_premature_completion(struct scsi_qla_host *ha)
267{
268 set_bit(AF_FW_RECOVERY, &ha->flags);
269 ql4_printk(KERN_INFO, ha, "scsi%ld: %s: set FW RECOVERY!\n",
270 ha->host_no, __func__);
271
272 if (test_bit(AF_MBOX_COMMAND, &ha->flags)) {
273 if (test_bit(AF_MBOX_COMMAND_NOPOLL, &ha->flags)) {
274 complete(&ha->mbx_intr_comp);
275 ql4_printk(KERN_INFO, ha, "scsi%ld: %s: Due to fw "
276 "recovery, doing premature completion of "
277 "mbx cmd\n", ha->host_no, __func__);
278
279 } else {
280 set_bit(AF_MBOX_COMMAND_DONE, &ha->flags);
281 ql4_printk(KERN_INFO, ha, "scsi%ld: %s: Due to fw "
282 "recovery, doing premature completion of "
283 "polling mbx cmd\n", ha->host_no, __func__);
284 }
285 }
286}
287
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +0530288static uint8_t
Vikas Chaudhary2a49a782010-04-28 11:37:07 +0530289qla4xxx_set_ifcb(struct scsi_qla_host *ha, uint32_t *mbox_cmd,
290 uint32_t *mbox_sts, dma_addr_t init_fw_cb_dma)
291{
292 memset(mbox_cmd, 0, sizeof(mbox_cmd[0]) * MBOX_REG_COUNT);
293 memset(mbox_sts, 0, sizeof(mbox_sts[0]) * MBOX_REG_COUNT);
294 mbox_cmd[0] = MBOX_CMD_INITIALIZE_FIRMWARE;
295 mbox_cmd[1] = 0;
296 mbox_cmd[2] = LSDW(init_fw_cb_dma);
297 mbox_cmd[3] = MSDW(init_fw_cb_dma);
298 mbox_cmd[4] = sizeof(struct addr_ctrl_blk);
299 mbox_cmd[5] = (IFCB_VER_MAX << 8) | IFCB_VER_MIN;
300
301 if (qla4xxx_mailbox_command(ha, 6, 6, mbox_cmd, mbox_sts) !=
302 QLA_SUCCESS) {
303 DEBUG2(printk(KERN_WARNING "scsi%ld: %s: "
304 "MBOX_CMD_INITIALIZE_FIRMWARE"
305 " failed w/ status %04X\n",
306 ha->host_no, __func__, mbox_sts[0]));
307 return QLA_ERROR;
308 }
309 return QLA_SUCCESS;
310}
311
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +0530312static uint8_t
Vikas Chaudhary2a49a782010-04-28 11:37:07 +0530313qla4xxx_get_ifcb(struct scsi_qla_host *ha, uint32_t *mbox_cmd,
314 uint32_t *mbox_sts, dma_addr_t init_fw_cb_dma)
315{
316 memset(mbox_cmd, 0, sizeof(mbox_cmd[0]) * MBOX_REG_COUNT);
317 memset(mbox_sts, 0, sizeof(mbox_sts[0]) * MBOX_REG_COUNT);
318 mbox_cmd[0] = MBOX_CMD_GET_INIT_FW_CTRL_BLOCK;
319 mbox_cmd[2] = LSDW(init_fw_cb_dma);
320 mbox_cmd[3] = MSDW(init_fw_cb_dma);
321 mbox_cmd[4] = sizeof(struct addr_ctrl_blk);
322
323 if (qla4xxx_mailbox_command(ha, 5, 5, mbox_cmd, mbox_sts) !=
324 QLA_SUCCESS) {
325 DEBUG2(printk(KERN_WARNING "scsi%ld: %s: "
326 "MBOX_CMD_GET_INIT_FW_CTRL_BLOCK"
327 " failed w/ status %04X\n",
328 ha->host_no, __func__, mbox_sts[0]));
329 return QLA_ERROR;
330 }
331 return QLA_SUCCESS;
332}
333
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +0530334static void
Vikas Chaudhary2a49a782010-04-28 11:37:07 +0530335qla4xxx_update_local_ip(struct scsi_qla_host *ha,
336 struct addr_ctrl_blk *init_fw_cb)
337{
338 /* Save IPv4 Address Info */
339 memcpy(ha->ip_address, init_fw_cb->ipv4_addr,
340 min(sizeof(ha->ip_address), sizeof(init_fw_cb->ipv4_addr)));
341 memcpy(ha->subnet_mask, init_fw_cb->ipv4_subnet,
342 min(sizeof(ha->subnet_mask), sizeof(init_fw_cb->ipv4_subnet)));
343 memcpy(ha->gateway, init_fw_cb->ipv4_gw_addr,
344 min(sizeof(ha->gateway), sizeof(init_fw_cb->ipv4_gw_addr)));
345
346 if (is_ipv6_enabled(ha)) {
347 /* Save IPv6 Address */
348 ha->ipv6_link_local_state = init_fw_cb->ipv6_lnk_lcl_addr_state;
349 ha->ipv6_addr0_state = init_fw_cb->ipv6_addr0_state;
350 ha->ipv6_addr1_state = init_fw_cb->ipv6_addr1_state;
351 ha->ipv6_default_router_state = init_fw_cb->ipv6_dflt_rtr_state;
352 ha->ipv6_link_local_addr.in6_u.u6_addr8[0] = 0xFE;
353 ha->ipv6_link_local_addr.in6_u.u6_addr8[1] = 0x80;
354
355 memcpy(&ha->ipv6_link_local_addr.in6_u.u6_addr8[8],
356 init_fw_cb->ipv6_if_id,
357 min(sizeof(ha->ipv6_link_local_addr)/2,
358 sizeof(init_fw_cb->ipv6_if_id)));
359 memcpy(&ha->ipv6_addr0, init_fw_cb->ipv6_addr0,
360 min(sizeof(ha->ipv6_addr0),
361 sizeof(init_fw_cb->ipv6_addr0)));
362 memcpy(&ha->ipv6_addr1, init_fw_cb->ipv6_addr1,
363 min(sizeof(ha->ipv6_addr1),
364 sizeof(init_fw_cb->ipv6_addr1)));
365 memcpy(&ha->ipv6_default_router_addr,
366 init_fw_cb->ipv6_dflt_rtr_addr,
367 min(sizeof(ha->ipv6_default_router_addr),
368 sizeof(init_fw_cb->ipv6_dflt_rtr_addr)));
369 }
370}
371
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +0530372static uint8_t
Vikas Chaudhary2a49a782010-04-28 11:37:07 +0530373qla4xxx_update_local_ifcb(struct scsi_qla_host *ha,
374 uint32_t *mbox_cmd,
375 uint32_t *mbox_sts,
376 struct addr_ctrl_blk *init_fw_cb,
377 dma_addr_t init_fw_cb_dma)
378{
379 if (qla4xxx_get_ifcb(ha, mbox_cmd, mbox_sts, init_fw_cb_dma)
380 != QLA_SUCCESS) {
381 DEBUG2(printk(KERN_WARNING
382 "scsi%ld: %s: Failed to get init_fw_ctrl_blk\n",
383 ha->host_no, __func__));
384 return QLA_ERROR;
385 }
386
387 DEBUG2(qla4xxx_dump_buffer(init_fw_cb, sizeof(struct addr_ctrl_blk)));
388
389 /* Save some info in adapter structure. */
390 ha->acb_version = init_fw_cb->acb_version;
391 ha->firmware_options = le16_to_cpu(init_fw_cb->fw_options);
392 ha->tcp_options = le16_to_cpu(init_fw_cb->ipv4_tcp_opts);
393 ha->ipv4_options = le16_to_cpu(init_fw_cb->ipv4_ip_opts);
394 ha->ipv4_addr_state = le16_to_cpu(init_fw_cb->ipv4_addr_state);
395 ha->heartbeat_interval = init_fw_cb->hb_interval;
396 memcpy(ha->name_string, init_fw_cb->iscsi_name,
397 min(sizeof(ha->name_string),
398 sizeof(init_fw_cb->iscsi_name)));
399 /*memcpy(ha->alias, init_fw_cb->Alias,
400 min(sizeof(ha->alias), sizeof(init_fw_cb->Alias)));*/
401
402 /* Save Command Line Paramater info */
Vikas Chaudhary2a49a782010-04-28 11:37:07 +0530403 ha->discovery_wait = ql4xdiscoverywait;
404
405 if (ha->acb_version == ACB_SUPPORTED) {
406 ha->ipv6_options = init_fw_cb->ipv6_opts;
407 ha->ipv6_addl_options = init_fw_cb->ipv6_addtl_opts;
408 }
409 qla4xxx_update_local_ip(ha, init_fw_cb);
410
411 return QLA_SUCCESS;
412}
413
David Somayajuluafaf5a22006-09-19 10:28:00 -0700414/**
415 * qla4xxx_initialize_fw_cb - initializes firmware control block.
416 * @ha: Pointer to host adapter structure.
417 **/
418int qla4xxx_initialize_fw_cb(struct scsi_qla_host * ha)
419{
Vikas Chaudhary2a49a782010-04-28 11:37:07 +0530420 struct addr_ctrl_blk *init_fw_cb;
David Somayajuluafaf5a22006-09-19 10:28:00 -0700421 dma_addr_t init_fw_cb_dma;
422 uint32_t mbox_cmd[MBOX_REG_COUNT];
423 uint32_t mbox_sts[MBOX_REG_COUNT];
424 int status = QLA_ERROR;
425
426 init_fw_cb = dma_alloc_coherent(&ha->pdev->dev,
Vikas Chaudhary2a49a782010-04-28 11:37:07 +0530427 sizeof(struct addr_ctrl_blk),
David Somayajuluafaf5a22006-09-19 10:28:00 -0700428 &init_fw_cb_dma, GFP_KERNEL);
429 if (init_fw_cb == NULL) {
430 DEBUG2(printk("scsi%ld: %s: Unable to alloc init_cb\n",
431 ha->host_no, __func__));
Prasanna Mumbaibeabe7c2010-07-10 14:49:38 +0530432 goto exit_init_fw_cb_no_free;
David Somayajuluafaf5a22006-09-19 10:28:00 -0700433 }
Vikas Chaudhary2a49a782010-04-28 11:37:07 +0530434 memset(init_fw_cb, 0, sizeof(struct addr_ctrl_blk));
David Somayajuluafaf5a22006-09-19 10:28:00 -0700435
436 /* Get Initialize Firmware Control Block. */
437 memset(&mbox_cmd, 0, sizeof(mbox_cmd));
438 memset(&mbox_sts, 0, sizeof(mbox_sts));
David C Somayajuluc0e344c2007-05-23 18:03:27 -0700439
Vikas Chaudhary2a49a782010-04-28 11:37:07 +0530440 if (qla4xxx_get_ifcb(ha, &mbox_cmd[0], &mbox_sts[0], init_fw_cb_dma) !=
David Somayajuluafaf5a22006-09-19 10:28:00 -0700441 QLA_SUCCESS) {
442 dma_free_coherent(&ha->pdev->dev,
Vikas Chaudhary2a49a782010-04-28 11:37:07 +0530443 sizeof(struct addr_ctrl_blk),
David Somayajuluafaf5a22006-09-19 10:28:00 -0700444 init_fw_cb, init_fw_cb_dma);
Vikas Chaudhary2a49a782010-04-28 11:37:07 +0530445 goto exit_init_fw_cb;
David Somayajuluafaf5a22006-09-19 10:28:00 -0700446 }
447
448 /* Initialize request and response queues. */
449 qla4xxx_init_rings(ha);
450
451 /* Fill in the request and response queue information. */
Vikas Chaudhary2a49a782010-04-28 11:37:07 +0530452 init_fw_cb->rqq_consumer_idx = cpu_to_le16(ha->request_out);
453 init_fw_cb->compq_producer_idx = cpu_to_le16(ha->response_in);
454 init_fw_cb->rqq_len = __constant_cpu_to_le16(REQUEST_QUEUE_DEPTH);
455 init_fw_cb->compq_len = __constant_cpu_to_le16(RESPONSE_QUEUE_DEPTH);
456 init_fw_cb->rqq_addr_lo = cpu_to_le32(LSDW(ha->request_dma));
457 init_fw_cb->rqq_addr_hi = cpu_to_le32(MSDW(ha->request_dma));
458 init_fw_cb->compq_addr_lo = cpu_to_le32(LSDW(ha->response_dma));
459 init_fw_cb->compq_addr_hi = cpu_to_le32(MSDW(ha->response_dma));
460 init_fw_cb->shdwreg_addr_lo = cpu_to_le32(LSDW(ha->shadow_regs_dma));
461 init_fw_cb->shdwreg_addr_hi = cpu_to_le32(MSDW(ha->shadow_regs_dma));
David Somayajuluafaf5a22006-09-19 10:28:00 -0700462
463 /* Set up required options. */
Vikas Chaudhary2a49a782010-04-28 11:37:07 +0530464 init_fw_cb->fw_options |=
David Somayajuluafaf5a22006-09-19 10:28:00 -0700465 __constant_cpu_to_le16(FWOPT_SESSION_MODE |
466 FWOPT_INITIATOR_MODE);
Vikas Chaudhary2a49a782010-04-28 11:37:07 +0530467 init_fw_cb->fw_options &= __constant_cpu_to_le16(~FWOPT_TARGET_MODE);
David Somayajuluafaf5a22006-09-19 10:28:00 -0700468
Vikas Chaudhary2a49a782010-04-28 11:37:07 +0530469 if (qla4xxx_set_ifcb(ha, &mbox_cmd[0], &mbox_sts[0], init_fw_cb_dma)
470 != QLA_SUCCESS) {
471 DEBUG2(printk(KERN_WARNING
472 "scsi%ld: %s: Failed to set init_fw_ctrl_blk\n",
473 ha->host_no, __func__));
474 goto exit_init_fw_cb;
David Somayajuluafaf5a22006-09-19 10:28:00 -0700475 }
Vikas Chaudhary2a49a782010-04-28 11:37:07 +0530476
477 if (qla4xxx_update_local_ifcb(ha, &mbox_cmd[0], &mbox_sts[0],
478 init_fw_cb, init_fw_cb_dma) != QLA_SUCCESS) {
479 DEBUG2(printk("scsi%ld: %s: Failed to update local ifcb\n",
480 ha->host_no, __func__));
481 goto exit_init_fw_cb;
482 }
483 status = QLA_SUCCESS;
484
485exit_init_fw_cb:
486 dma_free_coherent(&ha->pdev->dev, sizeof(struct addr_ctrl_blk),
487 init_fw_cb, init_fw_cb_dma);
Prasanna Mumbaibeabe7c2010-07-10 14:49:38 +0530488exit_init_fw_cb_no_free:
David Somayajuluafaf5a22006-09-19 10:28:00 -0700489 return status;
490}
491
492/**
493 * qla4xxx_get_dhcp_ip_address - gets HBA ip address via DHCP
494 * @ha: Pointer to host adapter structure.
495 **/
496int qla4xxx_get_dhcp_ip_address(struct scsi_qla_host * ha)
497{
Vikas Chaudhary2a49a782010-04-28 11:37:07 +0530498 struct addr_ctrl_blk *init_fw_cb;
David Somayajuluafaf5a22006-09-19 10:28:00 -0700499 dma_addr_t init_fw_cb_dma;
500 uint32_t mbox_cmd[MBOX_REG_COUNT];
501 uint32_t mbox_sts[MBOX_REG_COUNT];
502
503 init_fw_cb = dma_alloc_coherent(&ha->pdev->dev,
Vikas Chaudhary2a49a782010-04-28 11:37:07 +0530504 sizeof(struct addr_ctrl_blk),
David Somayajuluafaf5a22006-09-19 10:28:00 -0700505 &init_fw_cb_dma, GFP_KERNEL);
506 if (init_fw_cb == NULL) {
507 printk("scsi%ld: %s: Unable to alloc init_cb\n", ha->host_no,
508 __func__);
Prasanna Mumbaibeabe7c2010-07-10 14:49:38 +0530509 return QLA_ERROR;
David Somayajuluafaf5a22006-09-19 10:28:00 -0700510 }
511
512 /* Get Initialize Firmware Control Block. */
Vikas Chaudhary2a49a782010-04-28 11:37:07 +0530513 memset(init_fw_cb, 0, sizeof(struct addr_ctrl_blk));
514 if (qla4xxx_get_ifcb(ha, &mbox_cmd[0], &mbox_sts[0], init_fw_cb_dma) !=
David Somayajuluafaf5a22006-09-19 10:28:00 -0700515 QLA_SUCCESS) {
516 DEBUG2(printk("scsi%ld: %s: Failed to get init_fw_ctrl_blk\n",
517 ha->host_no, __func__));
518 dma_free_coherent(&ha->pdev->dev,
Vikas Chaudhary2a49a782010-04-28 11:37:07 +0530519 sizeof(struct addr_ctrl_blk),
David Somayajuluafaf5a22006-09-19 10:28:00 -0700520 init_fw_cb, init_fw_cb_dma);
521 return QLA_ERROR;
522 }
523
524 /* Save IP Address. */
Vikas Chaudhary2a49a782010-04-28 11:37:07 +0530525 qla4xxx_update_local_ip(ha, init_fw_cb);
526 dma_free_coherent(&ha->pdev->dev, sizeof(struct addr_ctrl_blk),
527 init_fw_cb, init_fw_cb_dma);
David Somayajuluafaf5a22006-09-19 10:28:00 -0700528
529 return QLA_SUCCESS;
530}
531
532/**
533 * qla4xxx_get_firmware_state - gets firmware state of HBA
534 * @ha: Pointer to host adapter structure.
535 **/
536int qla4xxx_get_firmware_state(struct scsi_qla_host * ha)
537{
538 uint32_t mbox_cmd[MBOX_REG_COUNT];
539 uint32_t mbox_sts[MBOX_REG_COUNT];
540
541 /* Get firmware version */
542 memset(&mbox_cmd, 0, sizeof(mbox_cmd));
543 memset(&mbox_sts, 0, sizeof(mbox_sts));
David C Somayajuluc0e344c2007-05-23 18:03:27 -0700544
David Somayajuluafaf5a22006-09-19 10:28:00 -0700545 mbox_cmd[0] = MBOX_CMD_GET_FW_STATE;
David C Somayajuluc0e344c2007-05-23 18:03:27 -0700546
547 if (qla4xxx_mailbox_command(ha, MBOX_REG_COUNT, 4, &mbox_cmd[0], &mbox_sts[0]) !=
David Somayajuluafaf5a22006-09-19 10:28:00 -0700548 QLA_SUCCESS) {
549 DEBUG2(printk("scsi%ld: %s: MBOX_CMD_GET_FW_STATE failed w/ "
550 "status %04X\n", ha->host_no, __func__,
551 mbox_sts[0]));
552 return QLA_ERROR;
553 }
554 ha->firmware_state = mbox_sts[1];
555 ha->board_id = mbox_sts[2];
556 ha->addl_fw_state = mbox_sts[3];
557 DEBUG2(printk("scsi%ld: %s firmware_state=0x%x\n",
558 ha->host_no, __func__, ha->firmware_state);)
559
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +0530560 return QLA_SUCCESS;
David Somayajuluafaf5a22006-09-19 10:28:00 -0700561}
562
563/**
564 * qla4xxx_get_firmware_status - retrieves firmware status
565 * @ha: Pointer to host adapter structure.
566 **/
567int qla4xxx_get_firmware_status(struct scsi_qla_host * ha)
568{
569 uint32_t mbox_cmd[MBOX_REG_COUNT];
570 uint32_t mbox_sts[MBOX_REG_COUNT];
571
572 /* Get firmware version */
573 memset(&mbox_cmd, 0, sizeof(mbox_cmd));
574 memset(&mbox_sts, 0, sizeof(mbox_sts));
David C Somayajuluc0e344c2007-05-23 18:03:27 -0700575
David Somayajuluafaf5a22006-09-19 10:28:00 -0700576 mbox_cmd[0] = MBOX_CMD_GET_FW_STATUS;
David C Somayajuluc0e344c2007-05-23 18:03:27 -0700577
578 if (qla4xxx_mailbox_command(ha, MBOX_REG_COUNT, 3, &mbox_cmd[0], &mbox_sts[0]) !=
David Somayajuluafaf5a22006-09-19 10:28:00 -0700579 QLA_SUCCESS) {
580 DEBUG2(printk("scsi%ld: %s: MBOX_CMD_GET_FW_STATUS failed w/ "
581 "status %04X\n", ha->host_no, __func__,
582 mbox_sts[0]));
583 return QLA_ERROR;
584 }
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +0530585
586 ql4_printk(KERN_INFO, ha, "%ld firmare IOCBs available (%d).\n",
587 ha->host_no, mbox_cmd[2]);
588
David Somayajuluafaf5a22006-09-19 10:28:00 -0700589 return QLA_SUCCESS;
590}
591
592/**
593 * qla4xxx_get_fwddb_entry - retrieves firmware ddb entry
594 * @ha: Pointer to host adapter structure.
595 * @fw_ddb_index: Firmware's device database index
596 * @fw_ddb_entry: Pointer to firmware's device database entry structure
597 * @num_valid_ddb_entries: Pointer to number of valid ddb entries
598 * @next_ddb_index: Pointer to next valid device database index
599 * @fw_ddb_device_state: Pointer to device state
600 **/
601int qla4xxx_get_fwddb_entry(struct scsi_qla_host *ha,
602 uint16_t fw_ddb_index,
603 struct dev_db_entry *fw_ddb_entry,
604 dma_addr_t fw_ddb_entry_dma,
605 uint32_t *num_valid_ddb_entries,
606 uint32_t *next_ddb_index,
607 uint32_t *fw_ddb_device_state,
608 uint32_t *conn_err_detail,
609 uint16_t *tcp_source_port_num,
610 uint16_t *connection_id)
611{
612 int status = QLA_ERROR;
Vikas Chaudhary2a49a782010-04-28 11:37:07 +0530613 uint16_t options;
David Somayajuluafaf5a22006-09-19 10:28:00 -0700614 uint32_t mbox_cmd[MBOX_REG_COUNT];
615 uint32_t mbox_sts[MBOX_REG_COUNT];
616
617 /* Make sure the device index is valid */
618 if (fw_ddb_index >= MAX_DDB_ENTRIES) {
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +0530619 DEBUG2(printk("scsi%ld: %s: ddb [%d] out of range.\n",
David Somayajuluafaf5a22006-09-19 10:28:00 -0700620 ha->host_no, __func__, fw_ddb_index));
621 goto exit_get_fwddb;
622 }
623 memset(&mbox_cmd, 0, sizeof(mbox_cmd));
624 memset(&mbox_sts, 0, sizeof(mbox_sts));
David C Somayajuluc0e344c2007-05-23 18:03:27 -0700625
David Somayajuluafaf5a22006-09-19 10:28:00 -0700626 mbox_cmd[0] = MBOX_CMD_GET_DATABASE_ENTRY;
627 mbox_cmd[1] = (uint32_t) fw_ddb_index;
628 mbox_cmd[2] = LSDW(fw_ddb_entry_dma);
629 mbox_cmd[3] = MSDW(fw_ddb_entry_dma);
David C Somayajuluc0e344c2007-05-23 18:03:27 -0700630 mbox_cmd[4] = sizeof(struct dev_db_entry);
631
632 if (qla4xxx_mailbox_command(ha, MBOX_REG_COUNT, 7, &mbox_cmd[0], &mbox_sts[0]) ==
David Somayajuluafaf5a22006-09-19 10:28:00 -0700633 QLA_ERROR) {
634 DEBUG2(printk("scsi%ld: %s: MBOX_CMD_GET_DATABASE_ENTRY failed"
635 " with status 0x%04X\n", ha->host_no, __func__,
636 mbox_sts[0]));
637 goto exit_get_fwddb;
638 }
639 if (fw_ddb_index != mbox_sts[1]) {
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +0530640 DEBUG2(printk("scsi%ld: %s: ddb mismatch [%d] != [%d].\n",
David Somayajuluafaf5a22006-09-19 10:28:00 -0700641 ha->host_no, __func__, fw_ddb_index,
642 mbox_sts[1]));
643 goto exit_get_fwddb;
644 }
645 if (fw_ddb_entry) {
Vikas Chaudhary2a49a782010-04-28 11:37:07 +0530646 options = le16_to_cpu(fw_ddb_entry->options);
647 if (options & DDB_OPT_IPV6_DEVICE) {
Vikas Chaudharyc2660df2010-07-10 14:51:02 +0530648 ql4_printk(KERN_INFO, ha, "%s: DDB[%d] MB0 %04x Tot %d "
Vikas Chaudhary2a49a782010-04-28 11:37:07 +0530649 "Next %d State %04x ConnErr %08x %pI6 "
650 ":%04d \"%s\"\n", __func__, fw_ddb_index,
651 mbox_sts[0], mbox_sts[2], mbox_sts[3],
652 mbox_sts[4], mbox_sts[5],
653 fw_ddb_entry->ip_addr,
654 le16_to_cpu(fw_ddb_entry->port),
655 fw_ddb_entry->iscsi_name);
656 } else {
Vikas Chaudharyc2660df2010-07-10 14:51:02 +0530657 ql4_printk(KERN_INFO, ha, "%s: DDB[%d] MB0 %04x Tot %d "
Vikas Chaudhary2a49a782010-04-28 11:37:07 +0530658 "Next %d State %04x ConnErr %08x %pI4 "
659 ":%04d \"%s\"\n", __func__, fw_ddb_index,
660 mbox_sts[0], mbox_sts[2], mbox_sts[3],
661 mbox_sts[4], mbox_sts[5],
662 fw_ddb_entry->ip_addr,
663 le16_to_cpu(fw_ddb_entry->port),
664 fw_ddb_entry->iscsi_name);
665 }
David Somayajuluafaf5a22006-09-19 10:28:00 -0700666 }
667 if (num_valid_ddb_entries)
668 *num_valid_ddb_entries = mbox_sts[2];
669 if (next_ddb_index)
670 *next_ddb_index = mbox_sts[3];
671 if (fw_ddb_device_state)
672 *fw_ddb_device_state = mbox_sts[4];
673
674 /*
675 * RA: This mailbox has been changed to pass connection error and
676 * details. Its true for ISP4010 as per Version E - Not sure when it
677 * was changed. Get the time2wait from the fw_dd_entry field :
678 * default_time2wait which we call it as minTime2Wait DEV_DB_ENTRY
679 * struct.
680 */
681 if (conn_err_detail)
682 *conn_err_detail = mbox_sts[5];
683 if (tcp_source_port_num)
Randy Dunlap14823382010-04-22 11:02:14 -0700684 *tcp_source_port_num = (uint16_t) (mbox_sts[6] >> 16);
David Somayajuluafaf5a22006-09-19 10:28:00 -0700685 if (connection_id)
686 *connection_id = (uint16_t) mbox_sts[6] & 0x00FF;
687 status = QLA_SUCCESS;
688
689exit_get_fwddb:
690 return status;
691}
692
693/**
694 * qla4xxx_set_fwddb_entry - sets a ddb entry.
695 * @ha: Pointer to host adapter structure.
696 * @fw_ddb_index: Firmware's device database index
697 * @fw_ddb_entry: Pointer to firmware's ddb entry structure, or NULL.
698 *
699 * This routine initializes or updates the adapter's device database
700 * entry for the specified device. It also triggers a login for the
701 * specified device. Therefore, it may also be used as a secondary
702 * login routine when a NULL pointer is specified for the fw_ddb_entry.
703 **/
704int qla4xxx_set_ddb_entry(struct scsi_qla_host * ha, uint16_t fw_ddb_index,
705 dma_addr_t fw_ddb_entry_dma)
706{
707 uint32_t mbox_cmd[MBOX_REG_COUNT];
708 uint32_t mbox_sts[MBOX_REG_COUNT];
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +0530709 int status;
David Somayajuluafaf5a22006-09-19 10:28:00 -0700710
711 /* Do not wait for completion. The firmware will send us an
712 * ASTS_DATABASE_CHANGED (0x8014) to notify us of the login status.
713 */
714 memset(&mbox_cmd, 0, sizeof(mbox_cmd));
715 memset(&mbox_sts, 0, sizeof(mbox_sts));
716
717 mbox_cmd[0] = MBOX_CMD_SET_DATABASE_ENTRY;
718 mbox_cmd[1] = (uint32_t) fw_ddb_index;
719 mbox_cmd[2] = LSDW(fw_ddb_entry_dma);
720 mbox_cmd[3] = MSDW(fw_ddb_entry_dma);
David C Somayajuluc0e344c2007-05-23 18:03:27 -0700721 mbox_cmd[4] = sizeof(struct dev_db_entry);
722
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +0530723 status = qla4xxx_mailbox_command(ha, MBOX_REG_COUNT, 5, &mbox_cmd[0],
724 &mbox_sts[0]);
725 DEBUG2(printk("scsi%ld: %s: status=%d mbx0=0x%x mbx4=0x%x\n",
726 ha->host_no, __func__, status, mbox_sts[0], mbox_sts[4]);)
727
728 return status;
David Somayajuluafaf5a22006-09-19 10:28:00 -0700729}
730
David Somayajuluafaf5a22006-09-19 10:28:00 -0700731/**
732 * qla4xxx_get_crash_record - retrieves crash record.
733 * @ha: Pointer to host adapter structure.
734 *
735 * This routine retrieves a crash record from the QLA4010 after an 8002h aen.
736 **/
737void qla4xxx_get_crash_record(struct scsi_qla_host * ha)
738{
739 uint32_t mbox_cmd[MBOX_REG_COUNT];
740 uint32_t mbox_sts[MBOX_REG_COUNT];
741 struct crash_record *crash_record = NULL;
742 dma_addr_t crash_record_dma = 0;
743 uint32_t crash_record_size = 0;
David C Somayajuluc0e344c2007-05-23 18:03:27 -0700744
David Somayajuluafaf5a22006-09-19 10:28:00 -0700745 memset(&mbox_cmd, 0, sizeof(mbox_cmd));
746 memset(&mbox_sts, 0, sizeof(mbox_cmd));
747
748 /* Get size of crash record. */
749 mbox_cmd[0] = MBOX_CMD_GET_CRASH_RECORD;
David C Somayajuluc0e344c2007-05-23 18:03:27 -0700750
751 if (qla4xxx_mailbox_command(ha, MBOX_REG_COUNT, 5, &mbox_cmd[0], &mbox_sts[0]) !=
David Somayajuluafaf5a22006-09-19 10:28:00 -0700752 QLA_SUCCESS) {
753 DEBUG2(printk("scsi%ld: %s: ERROR: Unable to retrieve size!\n",
754 ha->host_no, __func__));
755 goto exit_get_crash_record;
756 }
757 crash_record_size = mbox_sts[4];
758 if (crash_record_size == 0) {
759 DEBUG2(printk("scsi%ld: %s: ERROR: Crash record size is 0!\n",
760 ha->host_no, __func__));
761 goto exit_get_crash_record;
762 }
763
764 /* Alloc Memory for Crash Record. */
765 crash_record = dma_alloc_coherent(&ha->pdev->dev, crash_record_size,
766 &crash_record_dma, GFP_KERNEL);
767 if (crash_record == NULL)
768 goto exit_get_crash_record;
769
770 /* Get Crash Record. */
David C Somayajuluc0e344c2007-05-23 18:03:27 -0700771 memset(&mbox_cmd, 0, sizeof(mbox_cmd));
772 memset(&mbox_sts, 0, sizeof(mbox_cmd));
773
David Somayajuluafaf5a22006-09-19 10:28:00 -0700774 mbox_cmd[0] = MBOX_CMD_GET_CRASH_RECORD;
775 mbox_cmd[2] = LSDW(crash_record_dma);
776 mbox_cmd[3] = MSDW(crash_record_dma);
777 mbox_cmd[4] = crash_record_size;
David C Somayajuluc0e344c2007-05-23 18:03:27 -0700778
779 if (qla4xxx_mailbox_command(ha, MBOX_REG_COUNT, 5, &mbox_cmd[0], &mbox_sts[0]) !=
David Somayajuluafaf5a22006-09-19 10:28:00 -0700780 QLA_SUCCESS)
781 goto exit_get_crash_record;
782
783 /* Dump Crash Record. */
784
785exit_get_crash_record:
786 if (crash_record)
787 dma_free_coherent(&ha->pdev->dev, crash_record_size,
788 crash_record, crash_record_dma);
789}
790
791/**
792 * qla4xxx_get_conn_event_log - retrieves connection event log
793 * @ha: Pointer to host adapter structure.
794 **/
795void qla4xxx_get_conn_event_log(struct scsi_qla_host * ha)
796{
797 uint32_t mbox_cmd[MBOX_REG_COUNT];
798 uint32_t mbox_sts[MBOX_REG_COUNT];
799 struct conn_event_log_entry *event_log = NULL;
800 dma_addr_t event_log_dma = 0;
801 uint32_t event_log_size = 0;
802 uint32_t num_valid_entries;
803 uint32_t oldest_entry = 0;
804 uint32_t max_event_log_entries;
805 uint8_t i;
806
807
808 memset(&mbox_cmd, 0, sizeof(mbox_cmd));
809 memset(&mbox_sts, 0, sizeof(mbox_cmd));
810
811 /* Get size of crash record. */
812 mbox_cmd[0] = MBOX_CMD_GET_CONN_EVENT_LOG;
David C Somayajuluc0e344c2007-05-23 18:03:27 -0700813
814 if (qla4xxx_mailbox_command(ha, MBOX_REG_COUNT, 5, &mbox_cmd[0], &mbox_sts[0]) !=
David Somayajuluafaf5a22006-09-19 10:28:00 -0700815 QLA_SUCCESS)
816 goto exit_get_event_log;
817
818 event_log_size = mbox_sts[4];
819 if (event_log_size == 0)
820 goto exit_get_event_log;
821
822 /* Alloc Memory for Crash Record. */
823 event_log = dma_alloc_coherent(&ha->pdev->dev, event_log_size,
824 &event_log_dma, GFP_KERNEL);
825 if (event_log == NULL)
826 goto exit_get_event_log;
827
828 /* Get Crash Record. */
David C Somayajuluc0e344c2007-05-23 18:03:27 -0700829 memset(&mbox_cmd, 0, sizeof(mbox_cmd));
830 memset(&mbox_sts, 0, sizeof(mbox_cmd));
831
David Somayajuluafaf5a22006-09-19 10:28:00 -0700832 mbox_cmd[0] = MBOX_CMD_GET_CONN_EVENT_LOG;
833 mbox_cmd[2] = LSDW(event_log_dma);
834 mbox_cmd[3] = MSDW(event_log_dma);
David C Somayajuluc0e344c2007-05-23 18:03:27 -0700835
836 if (qla4xxx_mailbox_command(ha, MBOX_REG_COUNT, 5, &mbox_cmd[0], &mbox_sts[0]) !=
David Somayajuluafaf5a22006-09-19 10:28:00 -0700837 QLA_SUCCESS) {
838 DEBUG2(printk("scsi%ld: %s: ERROR: Unable to retrieve event "
839 "log!\n", ha->host_no, __func__));
840 goto exit_get_event_log;
841 }
842
843 /* Dump Event Log. */
844 num_valid_entries = mbox_sts[1];
845
846 max_event_log_entries = event_log_size /
847 sizeof(struct conn_event_log_entry);
848
849 if (num_valid_entries > max_event_log_entries)
850 oldest_entry = num_valid_entries % max_event_log_entries;
851
852 DEBUG3(printk("scsi%ld: Connection Event Log Dump (%d entries):\n",
853 ha->host_no, num_valid_entries));
854
Andrew Vasquez11010fe2006-10-06 09:54:59 -0700855 if (ql4xextended_error_logging == 3) {
David Somayajuluafaf5a22006-09-19 10:28:00 -0700856 if (oldest_entry == 0) {
857 /* Circular Buffer has not wrapped around */
858 for (i=0; i < num_valid_entries; i++) {
859 qla4xxx_dump_buffer((uint8_t *)event_log+
860 (i*sizeof(*event_log)),
861 sizeof(*event_log));
862 }
863 }
864 else {
865 /* Circular Buffer has wrapped around -
866 * display accordingly*/
867 for (i=oldest_entry; i < max_event_log_entries; i++) {
868 qla4xxx_dump_buffer((uint8_t *)event_log+
869 (i*sizeof(*event_log)),
870 sizeof(*event_log));
871 }
872 for (i=0; i < oldest_entry; i++) {
873 qla4xxx_dump_buffer((uint8_t *)event_log+
874 (i*sizeof(*event_log)),
875 sizeof(*event_log));
876 }
877 }
878 }
879
880exit_get_event_log:
881 if (event_log)
882 dma_free_coherent(&ha->pdev->dev, event_log_size, event_log,
883 event_log_dma);
884}
885
886/**
Vikas Chaudhary09a0f712010-04-28 11:42:24 +0530887 * qla4xxx_abort_task - issues Abort Task
888 * @ha: Pointer to host adapter structure.
889 * @srb: Pointer to srb entry
890 *
891 * This routine performs a LUN RESET on the specified target/lun.
892 * The caller must ensure that the ddb_entry and lun_entry pointers
893 * are valid before calling this routine.
894 **/
895int qla4xxx_abort_task(struct scsi_qla_host *ha, struct srb *srb)
896{
897 uint32_t mbox_cmd[MBOX_REG_COUNT];
898 uint32_t mbox_sts[MBOX_REG_COUNT];
899 struct scsi_cmnd *cmd = srb->cmd;
900 int status = QLA_SUCCESS;
901 unsigned long flags = 0;
902 uint32_t index;
903
904 /*
905 * Send abort task command to ISP, so that the ISP will return
906 * request with ABORT status
907 */
908 memset(&mbox_cmd, 0, sizeof(mbox_cmd));
909 memset(&mbox_sts, 0, sizeof(mbox_sts));
910
911 spin_lock_irqsave(&ha->hardware_lock, flags);
912 index = (unsigned long)(unsigned char *)cmd->host_scribble;
913 spin_unlock_irqrestore(&ha->hardware_lock, flags);
914
915 /* Firmware already posted completion on response queue */
916 if (index == MAX_SRBS)
917 return status;
918
919 mbox_cmd[0] = MBOX_CMD_ABORT_TASK;
920 mbox_cmd[1] = srb->fw_ddb_index;
921 mbox_cmd[2] = index;
922 /* Immediate Command Enable */
923 mbox_cmd[5] = 0x01;
924
925 qla4xxx_mailbox_command(ha, MBOX_REG_COUNT, 5, &mbox_cmd[0],
926 &mbox_sts[0]);
927 if (mbox_sts[0] != MBOX_STS_COMMAND_COMPLETE) {
928 status = QLA_ERROR;
929
930 DEBUG2(printk(KERN_WARNING "scsi%ld:%d:%d: abort task FAILED: "
931 "mbx0=%04X, mb1=%04X, mb2=%04X, mb3=%04X, mb4=%04X\n",
932 ha->host_no, cmd->device->id, cmd->device->lun, mbox_sts[0],
933 mbox_sts[1], mbox_sts[2], mbox_sts[3], mbox_sts[4]));
934 }
935
936 return status;
937}
938
939/**
David Somayajuluafaf5a22006-09-19 10:28:00 -0700940 * qla4xxx_reset_lun - issues LUN Reset
941 * @ha: Pointer to host adapter structure.
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +0530942 * @ddb_entry: Pointer to device database entry
943 * @lun: lun number
David Somayajuluafaf5a22006-09-19 10:28:00 -0700944 *
945 * This routine performs a LUN RESET on the specified target/lun.
946 * The caller must ensure that the ddb_entry and lun_entry pointers
947 * are valid before calling this routine.
948 **/
949int qla4xxx_reset_lun(struct scsi_qla_host * ha, struct ddb_entry * ddb_entry,
950 int lun)
951{
952 uint32_t mbox_cmd[MBOX_REG_COUNT];
953 uint32_t mbox_sts[MBOX_REG_COUNT];
954 int status = QLA_SUCCESS;
955
956 DEBUG2(printk("scsi%ld:%d:%d: lun reset issued\n", ha->host_no,
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +0530957 ddb_entry->fw_ddb_index, lun));
David Somayajuluafaf5a22006-09-19 10:28:00 -0700958
959 /*
960 * Send lun reset command to ISP, so that the ISP will return all
961 * outstanding requests with RESET status
962 */
963 memset(&mbox_cmd, 0, sizeof(mbox_cmd));
964 memset(&mbox_sts, 0, sizeof(mbox_sts));
David C Somayajuluc0e344c2007-05-23 18:03:27 -0700965
David Somayajuluafaf5a22006-09-19 10:28:00 -0700966 mbox_cmd[0] = MBOX_CMD_LUN_RESET;
967 mbox_cmd[1] = ddb_entry->fw_ddb_index;
968 mbox_cmd[2] = lun << 8;
969 mbox_cmd[5] = 0x01; /* Immediate Command Enable */
David C Somayajuluc0e344c2007-05-23 18:03:27 -0700970
971 qla4xxx_mailbox_command(ha, MBOX_REG_COUNT, 1, &mbox_cmd[0], &mbox_sts[0]);
David Somayajuluafaf5a22006-09-19 10:28:00 -0700972 if (mbox_sts[0] != MBOX_STS_COMMAND_COMPLETE &&
973 mbox_sts[0] != MBOX_STS_COMMAND_ERROR)
974 status = QLA_ERROR;
975
976 return status;
977}
978
Mike Christiece545032008-02-29 18:25:20 -0600979/**
980 * qla4xxx_reset_target - issues target Reset
981 * @ha: Pointer to host adapter structure.
982 * @db_entry: Pointer to device database entry
983 * @un_entry: Pointer to lun entry structure
984 *
985 * This routine performs a TARGET RESET on the specified target.
986 * The caller must ensure that the ddb_entry pointers
987 * are valid before calling this routine.
988 **/
989int qla4xxx_reset_target(struct scsi_qla_host *ha,
990 struct ddb_entry *ddb_entry)
991{
992 uint32_t mbox_cmd[MBOX_REG_COUNT];
993 uint32_t mbox_sts[MBOX_REG_COUNT];
994 int status = QLA_SUCCESS;
995
996 DEBUG2(printk("scsi%ld:%d: target reset issued\n", ha->host_no,
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +0530997 ddb_entry->fw_ddb_index));
Mike Christiece545032008-02-29 18:25:20 -0600998
999 /*
1000 * Send target reset command to ISP, so that the ISP will return all
1001 * outstanding requests with RESET status
1002 */
1003 memset(&mbox_cmd, 0, sizeof(mbox_cmd));
1004 memset(&mbox_sts, 0, sizeof(mbox_sts));
1005
1006 mbox_cmd[0] = MBOX_CMD_TARGET_WARM_RESET;
1007 mbox_cmd[1] = ddb_entry->fw_ddb_index;
1008 mbox_cmd[5] = 0x01; /* Immediate Command Enable */
1009
1010 qla4xxx_mailbox_command(ha, MBOX_REG_COUNT, 1, &mbox_cmd[0],
1011 &mbox_sts[0]);
1012 if (mbox_sts[0] != MBOX_STS_COMMAND_COMPLETE &&
1013 mbox_sts[0] != MBOX_STS_COMMAND_ERROR)
1014 status = QLA_ERROR;
1015
1016 return status;
1017}
David Somayajuluafaf5a22006-09-19 10:28:00 -07001018
1019int qla4xxx_get_flash(struct scsi_qla_host * ha, dma_addr_t dma_addr,
1020 uint32_t offset, uint32_t len)
1021{
1022 uint32_t mbox_cmd[MBOX_REG_COUNT];
1023 uint32_t mbox_sts[MBOX_REG_COUNT];
1024
1025 memset(&mbox_cmd, 0, sizeof(mbox_cmd));
1026 memset(&mbox_sts, 0, sizeof(mbox_sts));
David C Somayajuluc0e344c2007-05-23 18:03:27 -07001027
David Somayajuluafaf5a22006-09-19 10:28:00 -07001028 mbox_cmd[0] = MBOX_CMD_READ_FLASH;
1029 mbox_cmd[1] = LSDW(dma_addr);
1030 mbox_cmd[2] = MSDW(dma_addr);
1031 mbox_cmd[3] = offset;
1032 mbox_cmd[4] = len;
David C Somayajuluc0e344c2007-05-23 18:03:27 -07001033
1034 if (qla4xxx_mailbox_command(ha, MBOX_REG_COUNT, 2, &mbox_cmd[0], &mbox_sts[0]) !=
David Somayajuluafaf5a22006-09-19 10:28:00 -07001035 QLA_SUCCESS) {
1036 DEBUG2(printk("scsi%ld: %s: MBOX_CMD_READ_FLASH, failed w/ "
1037 "status %04X %04X, offset %08x, len %08x\n", ha->host_no,
1038 __func__, mbox_sts[0], mbox_sts[1], offset, len));
1039 return QLA_ERROR;
1040 }
1041 return QLA_SUCCESS;
1042}
1043
1044/**
1045 * qla4xxx_get_fw_version - gets firmware version
1046 * @ha: Pointer to host adapter structure.
1047 *
1048 * Retrieves the firmware version on HBA. In QLA4010, mailboxes 2 & 3 may
1049 * hold an address for data. Make sure that we write 0 to those mailboxes,
1050 * if unused.
1051 **/
1052int qla4xxx_get_fw_version(struct scsi_qla_host * ha)
1053{
1054 uint32_t mbox_cmd[MBOX_REG_COUNT];
1055 uint32_t mbox_sts[MBOX_REG_COUNT];
1056
1057 /* Get firmware version. */
1058 memset(&mbox_cmd, 0, sizeof(mbox_cmd));
1059 memset(&mbox_sts, 0, sizeof(mbox_sts));
David C Somayajuluc0e344c2007-05-23 18:03:27 -07001060
David Somayajuluafaf5a22006-09-19 10:28:00 -07001061 mbox_cmd[0] = MBOX_CMD_ABOUT_FW;
David C Somayajuluc0e344c2007-05-23 18:03:27 -07001062
1063 if (qla4xxx_mailbox_command(ha, MBOX_REG_COUNT, 5, &mbox_cmd[0], &mbox_sts[0]) !=
David Somayajuluafaf5a22006-09-19 10:28:00 -07001064 QLA_SUCCESS) {
1065 DEBUG2(printk("scsi%ld: %s: MBOX_CMD_ABOUT_FW failed w/ "
1066 "status %04X\n", ha->host_no, __func__, mbox_sts[0]));
1067 return QLA_ERROR;
1068 }
1069
1070 /* Save firmware version information. */
1071 ha->firmware_version[0] = mbox_sts[1];
1072 ha->firmware_version[1] = mbox_sts[2];
1073 ha->patch_number = mbox_sts[3];
1074 ha->build_number = mbox_sts[4];
1075
1076 return QLA_SUCCESS;
1077}
1078
Adrian Bunk47975472007-04-26 00:35:16 -07001079static int qla4xxx_get_default_ddb(struct scsi_qla_host *ha,
1080 dma_addr_t dma_addr)
David Somayajuluafaf5a22006-09-19 10:28:00 -07001081{
1082 uint32_t mbox_cmd[MBOX_REG_COUNT];
1083 uint32_t mbox_sts[MBOX_REG_COUNT];
1084
1085 memset(&mbox_cmd, 0, sizeof(mbox_cmd));
1086 memset(&mbox_sts, 0, sizeof(mbox_sts));
1087
1088 mbox_cmd[0] = MBOX_CMD_GET_DATABASE_ENTRY_DEFAULTS;
1089 mbox_cmd[2] = LSDW(dma_addr);
1090 mbox_cmd[3] = MSDW(dma_addr);
1091
David C Somayajuluc0e344c2007-05-23 18:03:27 -07001092 if (qla4xxx_mailbox_command(ha, MBOX_REG_COUNT, 1, &mbox_cmd[0], &mbox_sts[0]) !=
David Somayajuluafaf5a22006-09-19 10:28:00 -07001093 QLA_SUCCESS) {
1094 DEBUG2(printk("scsi%ld: %s: failed status %04X\n",
1095 ha->host_no, __func__, mbox_sts[0]));
1096 return QLA_ERROR;
1097 }
1098 return QLA_SUCCESS;
1099}
1100
Adrian Bunk47975472007-04-26 00:35:16 -07001101static int qla4xxx_req_ddb_entry(struct scsi_qla_host *ha, uint32_t *ddb_index)
David Somayajuluafaf5a22006-09-19 10:28:00 -07001102{
1103 uint32_t mbox_cmd[MBOX_REG_COUNT];
1104 uint32_t mbox_sts[MBOX_REG_COUNT];
1105
1106 memset(&mbox_cmd, 0, sizeof(mbox_cmd));
1107 memset(&mbox_sts, 0, sizeof(mbox_sts));
1108
1109 mbox_cmd[0] = MBOX_CMD_REQUEST_DATABASE_ENTRY;
1110 mbox_cmd[1] = MAX_PRST_DEV_DB_ENTRIES;
1111
David C Somayajuluc0e344c2007-05-23 18:03:27 -07001112 if (qla4xxx_mailbox_command(ha, MBOX_REG_COUNT, 3, &mbox_cmd[0], &mbox_sts[0]) !=
David Somayajuluafaf5a22006-09-19 10:28:00 -07001113 QLA_SUCCESS) {
1114 if (mbox_sts[0] == MBOX_STS_COMMAND_ERROR) {
1115 *ddb_index = mbox_sts[2];
1116 } else {
1117 DEBUG2(printk("scsi%ld: %s: failed status %04X\n",
1118 ha->host_no, __func__, mbox_sts[0]));
1119 return QLA_ERROR;
1120 }
1121 } else {
1122 *ddb_index = MAX_PRST_DEV_DB_ENTRIES;
1123 }
1124
1125 return QLA_SUCCESS;
1126}
1127
1128
1129int qla4xxx_send_tgts(struct scsi_qla_host *ha, char *ip, uint16_t port)
1130{
1131 struct dev_db_entry *fw_ddb_entry;
1132 dma_addr_t fw_ddb_entry_dma;
1133 uint32_t ddb_index;
1134 int ret_val = QLA_SUCCESS;
1135
1136
1137 fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev,
1138 sizeof(*fw_ddb_entry),
1139 &fw_ddb_entry_dma, GFP_KERNEL);
1140 if (!fw_ddb_entry) {
1141 DEBUG2(printk("scsi%ld: %s: Unable to allocate dma buffer.\n",
1142 ha->host_no, __func__));
1143 ret_val = QLA_ERROR;
Prasanna Mumbaibeabe7c2010-07-10 14:49:38 +05301144 goto exit_send_tgts_no_free;
David Somayajuluafaf5a22006-09-19 10:28:00 -07001145 }
1146
1147 ret_val = qla4xxx_get_default_ddb(ha, fw_ddb_entry_dma);
1148 if (ret_val != QLA_SUCCESS)
Prasanna Mumbaibeabe7c2010-07-10 14:49:38 +05301149 goto exit_send_tgts;
David Somayajuluafaf5a22006-09-19 10:28:00 -07001150
1151 ret_val = qla4xxx_req_ddb_entry(ha, &ddb_index);
1152 if (ret_val != QLA_SUCCESS)
Prasanna Mumbaibeabe7c2010-07-10 14:49:38 +05301153 goto exit_send_tgts;
David Somayajuluafaf5a22006-09-19 10:28:00 -07001154
David C Somayajuluc0e344c2007-05-23 18:03:27 -07001155 memset(fw_ddb_entry->iscsi_alias, 0,
1156 sizeof(fw_ddb_entry->iscsi_alias));
David Somayajuluafaf5a22006-09-19 10:28:00 -07001157
David C Somayajuluc0e344c2007-05-23 18:03:27 -07001158 memset(fw_ddb_entry->iscsi_name, 0,
1159 sizeof(fw_ddb_entry->iscsi_name));
David Somayajuluafaf5a22006-09-19 10:28:00 -07001160
David C Somayajuluc0e344c2007-05-23 18:03:27 -07001161 memset(fw_ddb_entry->ip_addr, 0, sizeof(fw_ddb_entry->ip_addr));
1162 memset(fw_ddb_entry->tgt_addr, 0,
1163 sizeof(fw_ddb_entry->tgt_addr));
David Somayajuluafaf5a22006-09-19 10:28:00 -07001164
1165 fw_ddb_entry->options = (DDB_OPT_DISC_SESSION | DDB_OPT_TARGET);
David C Somayajuluc0e344c2007-05-23 18:03:27 -07001166 fw_ddb_entry->port = cpu_to_le16(ntohs(port));
David Somayajuluafaf5a22006-09-19 10:28:00 -07001167
David C Somayajuluc0e344c2007-05-23 18:03:27 -07001168 fw_ddb_entry->ip_addr[0] = *ip;
1169 fw_ddb_entry->ip_addr[1] = *(ip + 1);
1170 fw_ddb_entry->ip_addr[2] = *(ip + 2);
1171 fw_ddb_entry->ip_addr[3] = *(ip + 3);
David Somayajuluafaf5a22006-09-19 10:28:00 -07001172
1173 ret_val = qla4xxx_set_ddb_entry(ha, ddb_index, fw_ddb_entry_dma);
1174
Prasanna Mumbaibeabe7c2010-07-10 14:49:38 +05301175exit_send_tgts:
David Somayajuluafaf5a22006-09-19 10:28:00 -07001176 dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
1177 fw_ddb_entry, fw_ddb_entry_dma);
Prasanna Mumbaibeabe7c2010-07-10 14:49:38 +05301178exit_send_tgts_no_free:
David Somayajuluafaf5a22006-09-19 10:28:00 -07001179 return ret_val;
1180}
1181