blob: ea04b6cecfa18c27a81222a541ebeff2f0a0e0b7 [file] [log] [blame]
David Somayajuluafaf5a22006-09-19 10:28:00 -07001/*
2 * QLogic iSCSI HBA Driver
Vikas Chaudhary7d01d062010-12-02 22:12:51 -08003 * Copyright (c) 2003-2010 QLogic Corporation
David Somayajuluafaf5a22006-09-19 10:28:00 -07004 *
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 *
Justin P. Mattock70f23fd2011-05-10 10:16:21 +020022 * This routine issue 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;
Prasanna Mumbai99b53bf2011-03-21 03:34:25 -070035 uint32_t dev_state;
David Somayajuluafaf5a22006-09-19 10:28:00 -070036
37 /* Make sure that pointers are valid */
38 if (!mbx_cmd || !mbx_sts) {
39 DEBUG2(printk("scsi%ld: %s: Invalid mbx_cmd or mbx_sts "
40 "pointer\n", ha->host_no, __func__));
David C Somayajulu477ffb92007-01-22 12:26:11 -080041 return status;
42 }
Nilesh Javali21033632010-07-30 14:28:07 +053043
Prasanna Mumbai99b53bf2011-03-21 03:34:25 -070044 if (is_qla8022(ha)) {
45 if (test_bit(AF_FW_RECOVERY, &ha->flags)) {
46 DEBUG2(ql4_printk(KERN_WARNING, ha, "scsi%ld: %s: "
47 "prematurely completing mbx cmd as firmware "
48 "recovery detected\n", ha->host_no, __func__));
49 return status;
50 }
51 /* Do not send any mbx cmd if h/w is in failed state*/
52 qla4_8xxx_idc_lock(ha);
53 dev_state = qla4_8xxx_rd_32(ha, QLA82XX_CRB_DEV_STATE);
54 qla4_8xxx_idc_unlock(ha);
55 if (dev_state == QLA82XX_DEV_FAILED) {
56 ql4_printk(KERN_WARNING, ha, "scsi%ld: %s: H/W is in "
57 "failed state, do not send any mailbox commands\n",
58 ha->host_no, __func__);
59 return status;
60 }
Nilesh Javali21033632010-07-30 14:28:07 +053061 }
62
Lalit Chandivade2232be02010-07-30 14:38:47 +053063 if ((is_aer_supported(ha)) &&
64 (test_bit(AF_PCI_CHANNEL_IO_PERM_FAILURE, &ha->flags))) {
65 DEBUG2(printk(KERN_WARNING "scsi%ld: %s: Perm failure on EEH, "
66 "timeout MBX Exiting.\n", ha->host_no, __func__));
67 return status;
68 }
69
David C Somayajulu477ffb92007-01-22 12:26:11 -080070 /* Mailbox code active */
71 wait_count = MBOX_TOV * 100;
72
73 while (wait_count--) {
74 mutex_lock(&ha->mbox_sem);
75 if (!test_bit(AF_MBOX_COMMAND, &ha->flags)) {
76 set_bit(AF_MBOX_COMMAND, &ha->flags);
77 mutex_unlock(&ha->mbox_sem);
78 break;
79 }
80 mutex_unlock(&ha->mbox_sem);
81 if (!wait_count) {
82 DEBUG2(printk("scsi%ld: %s: mbox_sem failed\n",
83 ha->host_no, __func__));
84 return status;
85 }
86 msleep(10);
David Somayajuluafaf5a22006-09-19 10:28:00 -070087 }
88
David Somayajuluafaf5a22006-09-19 10:28:00 -070089 spin_lock_irqsave(&ha->hardware_lock, flags);
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +053090
David Somayajuluafaf5a22006-09-19 10:28:00 -070091 ha->mbox_status_count = outCount;
92 for (i = 0; i < outCount; i++)
93 ha->mbox_status[i] = 0;
94
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +053095 if (is_qla8022(ha)) {
96 /* Load all mailbox registers, except mailbox 0. */
97 DEBUG5(
98 printk("scsi%ld: %s: Cmd ", ha->host_no, __func__);
99 for (i = 0; i < inCount; i++)
100 printk("mb%d=%04x ", i, mbx_cmd[i]);
101 printk("\n"));
David Somayajuluafaf5a22006-09-19 10:28:00 -0700102
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +0530103 for (i = 1; i < inCount; i++)
104 writel(mbx_cmd[i], &ha->qla4_8xxx_reg->mailbox_in[i]);
105 writel(mbx_cmd[0], &ha->qla4_8xxx_reg->mailbox_in[0]);
106 readl(&ha->qla4_8xxx_reg->mailbox_in[0]);
107 writel(HINT_MBX_INT_PENDING, &ha->qla4_8xxx_reg->hint);
108 } else {
109 /* Load all mailbox registers, except mailbox 0. */
110 for (i = 1; i < inCount; i++)
111 writel(mbx_cmd[i], &ha->reg->mailbox[i]);
112
113 /* Wakeup firmware */
114 writel(mbx_cmd[0], &ha->reg->mailbox[0]);
115 readl(&ha->reg->mailbox[0]);
116 writel(set_rmask(CSR_INTR_RISC), &ha->reg->ctrl_status);
117 readl(&ha->reg->ctrl_status);
118 }
119
David Somayajuluafaf5a22006-09-19 10:28:00 -0700120 spin_unlock_irqrestore(&ha->hardware_lock, flags);
121
122 /* Wait for completion */
David Somayajuluafaf5a22006-09-19 10:28:00 -0700123
124 /*
125 * If we don't want status, don't wait for the mailbox command to
126 * complete. For example, MBOX_CMD_RESET_FW doesn't return status,
127 * you must poll the inbound Interrupt Mask for completion.
128 */
129 if (outCount == 0) {
130 status = QLA_SUCCESS;
David Somayajuluafaf5a22006-09-19 10:28:00 -0700131 goto mbox_exit;
132 }
David Somayajuluafaf5a22006-09-19 10:28:00 -0700133
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +0530134 /*
135 * Wait for completion: Poll or completion queue
136 */
137 if (test_bit(AF_IRQ_ATTACHED, &ha->flags) &&
138 test_bit(AF_INTERRUPTS_ON, &ha->flags) &&
139 test_bit(AF_ONLINE, &ha->flags) &&
Karen Higgins7eece5a2011-03-21 03:34:29 -0700140 !test_bit(AF_HA_REMOVAL, &ha->flags)) {
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +0530141 /* Do not poll for completion. Use completion queue */
142 set_bit(AF_MBOX_COMMAND_NOPOLL, &ha->flags);
143 wait_for_completion_timeout(&ha->mbx_intr_comp, MBOX_TOV * HZ);
144 clear_bit(AF_MBOX_COMMAND_NOPOLL, &ha->flags);
145 } else {
146 /* Poll for command to complete */
147 wait_count = jiffies + MBOX_TOV * HZ;
148 while (test_bit(AF_MBOX_COMMAND_DONE, &ha->flags) == 0) {
149 if (time_after_eq(jiffies, wait_count))
150 break;
Lalit Chandivade2232be02010-07-30 14:38:47 +0530151
David Somayajuluafaf5a22006-09-19 10:28:00 -0700152 /*
153 * Service the interrupt.
154 * The ISR will save the mailbox status registers
155 * to a temporary storage location in the adapter
156 * structure.
157 */
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +0530158
159 spin_lock_irqsave(&ha->hardware_lock, flags);
160 if (is_qla8022(ha)) {
161 intr_status =
162 readl(&ha->qla4_8xxx_reg->host_int);
163 if (intr_status & ISRX_82XX_RISC_INT) {
164 ha->mbox_status_count = outCount;
165 intr_status =
166 readl(&ha->qla4_8xxx_reg->host_status);
167 ha->isp_ops->interrupt_service_routine(
168 ha, intr_status);
169 if (test_bit(AF_INTERRUPTS_ON,
170 &ha->flags) &&
171 test_bit(AF_INTx_ENABLED,
172 &ha->flags))
173 qla4_8xxx_wr_32(ha,
174 ha->nx_legacy_intr.tgt_mask_reg,
175 0xfbff);
176 }
177 } else {
178 intr_status = readl(&ha->reg->ctrl_status);
179 if (intr_status & INTR_PENDING) {
180 /*
181 * Service the interrupt.
182 * The ISR will save the mailbox status
183 * registers to a temporary storage
184 * location in the adapter structure.
185 */
186 ha->mbox_status_count = outCount;
187 ha->isp_ops->interrupt_service_routine(
188 ha, intr_status);
189 }
190 }
191 spin_unlock_irqrestore(&ha->hardware_lock, flags);
192 msleep(10);
David Somayajuluafaf5a22006-09-19 10:28:00 -0700193 }
David Somayajuluafaf5a22006-09-19 10:28:00 -0700194 }
David Somayajuluafaf5a22006-09-19 10:28:00 -0700195
196 /* Check for mailbox timeout. */
197 if (!test_bit(AF_MBOX_COMMAND_DONE, &ha->flags)) {
Nilesh Javali21033632010-07-30 14:28:07 +0530198 if (is_qla8022(ha) &&
199 test_bit(AF_FW_RECOVERY, &ha->flags)) {
200 DEBUG2(ql4_printk(KERN_INFO, ha,
201 "scsi%ld: %s: prematurely completing mbx cmd as "
202 "firmware recovery detected\n",
203 ha->host_no, __func__));
204 goto mbox_exit;
205 }
David Somayajuluafaf5a22006-09-19 10:28:00 -0700206 DEBUG2(printk("scsi%ld: Mailbox Cmd 0x%08X timed out ...,"
207 " Scheduling Adapter Reset\n", ha->host_no,
208 mbx_cmd[0]));
209 ha->mailbox_timeout_count++;
210 mbx_sts[0] = (-1);
211 set_bit(DPC_RESET_HA, &ha->dpc_flags);
212 goto mbox_exit;
213 }
214
215 /*
216 * Copy the mailbox out registers to the caller's mailbox in/out
217 * structure.
218 */
219 spin_lock_irqsave(&ha->hardware_lock, flags);
220 for (i = 0; i < outCount; i++)
221 mbx_sts[i] = ha->mbox_status[i];
222
223 /* Set return status and error flags (if applicable). */
224 switch (ha->mbox_status[0]) {
225 case MBOX_STS_COMMAND_COMPLETE:
226 status = QLA_SUCCESS;
227 break;
228
229 case MBOX_STS_INTERMEDIATE_COMPLETION:
230 status = QLA_SUCCESS;
231 break;
232
233 case MBOX_STS_BUSY:
234 DEBUG2( printk("scsi%ld: %s: Cmd = %08X, ISP BUSY\n",
235 ha->host_no, __func__, mbx_cmd[0]));
236 ha->mailbox_timeout_count++;
237 break;
238
239 default:
240 DEBUG2(printk("scsi%ld: %s: **** FAILED, cmd = %08X, "
241 "sts = %08X ****\n", ha->host_no, __func__,
242 mbx_cmd[0], mbx_sts[0]));
243 break;
244 }
245 spin_unlock_irqrestore(&ha->hardware_lock, flags);
246
247mbox_exit:
David C Somayajulu477ffb92007-01-22 12:26:11 -0800248 mutex_lock(&ha->mbox_sem);
David Somayajuluafaf5a22006-09-19 10:28:00 -0700249 clear_bit(AF_MBOX_COMMAND, &ha->flags);
David Somayajuluafaf5a22006-09-19 10:28:00 -0700250 mutex_unlock(&ha->mbox_sem);
David C Somayajulu477ffb92007-01-22 12:26:11 -0800251 clear_bit(AF_MBOX_COMMAND_DONE, &ha->flags);
David Somayajuluafaf5a22006-09-19 10:28:00 -0700252
253 return status;
254}
255
Nilesh Javali21033632010-07-30 14:28:07 +0530256void qla4xxx_mailbox_premature_completion(struct scsi_qla_host *ha)
257{
258 set_bit(AF_FW_RECOVERY, &ha->flags);
259 ql4_printk(KERN_INFO, ha, "scsi%ld: %s: set FW RECOVERY!\n",
260 ha->host_no, __func__);
261
262 if (test_bit(AF_MBOX_COMMAND, &ha->flags)) {
263 if (test_bit(AF_MBOX_COMMAND_NOPOLL, &ha->flags)) {
264 complete(&ha->mbx_intr_comp);
265 ql4_printk(KERN_INFO, ha, "scsi%ld: %s: Due to fw "
266 "recovery, doing premature completion of "
267 "mbx cmd\n", ha->host_no, __func__);
268
269 } else {
270 set_bit(AF_MBOX_COMMAND_DONE, &ha->flags);
271 ql4_printk(KERN_INFO, ha, "scsi%ld: %s: Due to fw "
272 "recovery, doing premature completion of "
273 "polling mbx cmd\n", ha->host_no, __func__);
274 }
275 }
276}
277
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +0530278static uint8_t
Vikas Chaudhary2a49a782010-04-28 11:37:07 +0530279qla4xxx_set_ifcb(struct scsi_qla_host *ha, uint32_t *mbox_cmd,
280 uint32_t *mbox_sts, dma_addr_t init_fw_cb_dma)
281{
282 memset(mbox_cmd, 0, sizeof(mbox_cmd[0]) * MBOX_REG_COUNT);
283 memset(mbox_sts, 0, sizeof(mbox_sts[0]) * MBOX_REG_COUNT);
Shyam Sundar2657c802010-10-06 22:50:29 -0700284
285 if (is_qla8022(ha))
286 qla4_8xxx_wr_32(ha, ha->nx_db_wr_ptr, 0);
287
Vikas Chaudhary2a49a782010-04-28 11:37:07 +0530288 mbox_cmd[0] = MBOX_CMD_INITIALIZE_FIRMWARE;
289 mbox_cmd[1] = 0;
290 mbox_cmd[2] = LSDW(init_fw_cb_dma);
291 mbox_cmd[3] = MSDW(init_fw_cb_dma);
292 mbox_cmd[4] = sizeof(struct addr_ctrl_blk);
293 mbox_cmd[5] = (IFCB_VER_MAX << 8) | IFCB_VER_MIN;
294
295 if (qla4xxx_mailbox_command(ha, 6, 6, mbox_cmd, mbox_sts) !=
296 QLA_SUCCESS) {
297 DEBUG2(printk(KERN_WARNING "scsi%ld: %s: "
298 "MBOX_CMD_INITIALIZE_FIRMWARE"
299 " failed w/ status %04X\n",
300 ha->host_no, __func__, mbox_sts[0]));
301 return QLA_ERROR;
302 }
303 return QLA_SUCCESS;
304}
305
Mike Christied00efe32011-07-25 13:48:38 -0500306uint8_t
Vikas Chaudhary2a49a782010-04-28 11:37:07 +0530307qla4xxx_get_ifcb(struct scsi_qla_host *ha, uint32_t *mbox_cmd,
308 uint32_t *mbox_sts, dma_addr_t init_fw_cb_dma)
309{
310 memset(mbox_cmd, 0, sizeof(mbox_cmd[0]) * MBOX_REG_COUNT);
311 memset(mbox_sts, 0, sizeof(mbox_sts[0]) * MBOX_REG_COUNT);
312 mbox_cmd[0] = MBOX_CMD_GET_INIT_FW_CTRL_BLOCK;
313 mbox_cmd[2] = LSDW(init_fw_cb_dma);
314 mbox_cmd[3] = MSDW(init_fw_cb_dma);
315 mbox_cmd[4] = sizeof(struct addr_ctrl_blk);
316
317 if (qla4xxx_mailbox_command(ha, 5, 5, mbox_cmd, mbox_sts) !=
318 QLA_SUCCESS) {
319 DEBUG2(printk(KERN_WARNING "scsi%ld: %s: "
320 "MBOX_CMD_GET_INIT_FW_CTRL_BLOCK"
321 " failed w/ status %04X\n",
322 ha->host_no, __func__, mbox_sts[0]));
323 return QLA_ERROR;
324 }
325 return QLA_SUCCESS;
326}
327
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +0530328static void
Vikas Chaudhary2a49a782010-04-28 11:37:07 +0530329qla4xxx_update_local_ip(struct scsi_qla_host *ha,
Vikas Chaudhary2bab08f2011-07-25 13:48:39 -0500330 struct addr_ctrl_blk *init_fw_cb)
Vikas Chaudhary2a49a782010-04-28 11:37:07 +0530331{
Vikas Chaudhary2bab08f2011-07-25 13:48:39 -0500332 ha->ip_config.tcp_options = le16_to_cpu(init_fw_cb->ipv4_tcp_opts);
333 ha->ip_config.ipv4_options = le16_to_cpu(init_fw_cb->ipv4_ip_opts);
334 ha->ip_config.ipv4_addr_state =
335 le16_to_cpu(init_fw_cb->ipv4_addr_state);
336
337 if (ha->acb_version == ACB_SUPPORTED) {
338 ha->ip_config.ipv6_options = le16_to_cpu(init_fw_cb->ipv6_opts);
339 ha->ip_config.ipv6_addl_options =
340 le16_to_cpu(init_fw_cb->ipv6_addtl_opts);
341 }
342
Vikas Chaudhary2a49a782010-04-28 11:37:07 +0530343 /* Save IPv4 Address Info */
Vikas Chaudhary2bab08f2011-07-25 13:48:39 -0500344 memcpy(ha->ip_config.ip_address, init_fw_cb->ipv4_addr,
345 min(sizeof(ha->ip_config.ip_address),
346 sizeof(init_fw_cb->ipv4_addr)));
347 memcpy(ha->ip_config.subnet_mask, init_fw_cb->ipv4_subnet,
348 min(sizeof(ha->ip_config.subnet_mask),
349 sizeof(init_fw_cb->ipv4_subnet)));
350 memcpy(ha->ip_config.gateway, init_fw_cb->ipv4_gw_addr,
351 min(sizeof(ha->ip_config.gateway),
352 sizeof(init_fw_cb->ipv4_gw_addr)));
Vikas Chaudhary2a49a782010-04-28 11:37:07 +0530353
Vikas Chaudhary6ac73e82011-07-25 13:48:49 -0500354 ha->ip_config.ipv4_vlan_tag = be16_to_cpu(init_fw_cb->ipv4_vlan_tag);
355
Vikas Chaudhary2a49a782010-04-28 11:37:07 +0530356 if (is_ipv6_enabled(ha)) {
357 /* Save IPv6 Address */
Vikas Chaudhary2bab08f2011-07-25 13:48:39 -0500358 ha->ip_config.ipv6_link_local_state =
359 le16_to_cpu(init_fw_cb->ipv6_lnk_lcl_addr_state);
360 ha->ip_config.ipv6_addr0_state =
361 le16_to_cpu(init_fw_cb->ipv6_addr0_state);
362 ha->ip_config.ipv6_addr1_state =
363 le16_to_cpu(init_fw_cb->ipv6_addr1_state);
364 ha->ip_config.ipv6_default_router_state =
365 le16_to_cpu(init_fw_cb->ipv6_dflt_rtr_state);
366 ha->ip_config.ipv6_link_local_addr.in6_u.u6_addr8[0] = 0xFE;
367 ha->ip_config.ipv6_link_local_addr.in6_u.u6_addr8[1] = 0x80;
Vikas Chaudhary2a49a782010-04-28 11:37:07 +0530368
Vikas Chaudhary2bab08f2011-07-25 13:48:39 -0500369 memcpy(&ha->ip_config.ipv6_link_local_addr.in6_u.u6_addr8[8],
370 init_fw_cb->ipv6_if_id,
371 min(sizeof(ha->ip_config.ipv6_link_local_addr)/2,
372 sizeof(init_fw_cb->ipv6_if_id)));
373 memcpy(&ha->ip_config.ipv6_addr0, init_fw_cb->ipv6_addr0,
374 min(sizeof(ha->ip_config.ipv6_addr0),
375 sizeof(init_fw_cb->ipv6_addr0)));
376 memcpy(&ha->ip_config.ipv6_addr1, init_fw_cb->ipv6_addr1,
377 min(sizeof(ha->ip_config.ipv6_addr1),
378 sizeof(init_fw_cb->ipv6_addr1)));
379 memcpy(&ha->ip_config.ipv6_default_router_addr,
380 init_fw_cb->ipv6_dflt_rtr_addr,
381 min(sizeof(ha->ip_config.ipv6_default_router_addr),
382 sizeof(init_fw_cb->ipv6_dflt_rtr_addr)));
Vikas Chaudhary6ac73e82011-07-25 13:48:49 -0500383 ha->ip_config.ipv6_vlan_tag =
384 be16_to_cpu(init_fw_cb->ipv6_vlan_tag);
Vikas Chaudhary2a49a782010-04-28 11:37:07 +0530385 }
386}
387
Mike Christied00efe32011-07-25 13:48:38 -0500388uint8_t
Vikas Chaudhary2a49a782010-04-28 11:37:07 +0530389qla4xxx_update_local_ifcb(struct scsi_qla_host *ha,
390 uint32_t *mbox_cmd,
391 uint32_t *mbox_sts,
392 struct addr_ctrl_blk *init_fw_cb,
393 dma_addr_t init_fw_cb_dma)
394{
395 if (qla4xxx_get_ifcb(ha, mbox_cmd, mbox_sts, init_fw_cb_dma)
396 != QLA_SUCCESS) {
397 DEBUG2(printk(KERN_WARNING
398 "scsi%ld: %s: Failed to get init_fw_ctrl_blk\n",
399 ha->host_no, __func__));
400 return QLA_ERROR;
401 }
402
403 DEBUG2(qla4xxx_dump_buffer(init_fw_cb, sizeof(struct addr_ctrl_blk)));
404
405 /* Save some info in adapter structure. */
406 ha->acb_version = init_fw_cb->acb_version;
407 ha->firmware_options = le16_to_cpu(init_fw_cb->fw_options);
Vikas Chaudhary2a49a782010-04-28 11:37:07 +0530408 ha->heartbeat_interval = init_fw_cb->hb_interval;
409 memcpy(ha->name_string, init_fw_cb->iscsi_name,
410 min(sizeof(ha->name_string),
411 sizeof(init_fw_cb->iscsi_name)));
412 /*memcpy(ha->alias, init_fw_cb->Alias,
413 min(sizeof(ha->alias), sizeof(init_fw_cb->Alias)));*/
414
Vikas Chaudhary2a49a782010-04-28 11:37:07 +0530415 qla4xxx_update_local_ip(ha, init_fw_cb);
416
417 return QLA_SUCCESS;
418}
419
David Somayajuluafaf5a22006-09-19 10:28:00 -0700420/**
421 * qla4xxx_initialize_fw_cb - initializes firmware control block.
422 * @ha: Pointer to host adapter structure.
423 **/
424int qla4xxx_initialize_fw_cb(struct scsi_qla_host * ha)
425{
Vikas Chaudhary2a49a782010-04-28 11:37:07 +0530426 struct addr_ctrl_blk *init_fw_cb;
David Somayajuluafaf5a22006-09-19 10:28:00 -0700427 dma_addr_t init_fw_cb_dma;
428 uint32_t mbox_cmd[MBOX_REG_COUNT];
429 uint32_t mbox_sts[MBOX_REG_COUNT];
430 int status = QLA_ERROR;
431
432 init_fw_cb = dma_alloc_coherent(&ha->pdev->dev,
Vikas Chaudhary2a49a782010-04-28 11:37:07 +0530433 sizeof(struct addr_ctrl_blk),
David Somayajuluafaf5a22006-09-19 10:28:00 -0700434 &init_fw_cb_dma, GFP_KERNEL);
435 if (init_fw_cb == NULL) {
436 DEBUG2(printk("scsi%ld: %s: Unable to alloc init_cb\n",
437 ha->host_no, __func__));
Prasanna Mumbaibeabe7c2010-07-10 14:49:38 +0530438 goto exit_init_fw_cb_no_free;
David Somayajuluafaf5a22006-09-19 10:28:00 -0700439 }
Vikas Chaudhary2a49a782010-04-28 11:37:07 +0530440 memset(init_fw_cb, 0, sizeof(struct addr_ctrl_blk));
David Somayajuluafaf5a22006-09-19 10:28:00 -0700441
442 /* Get Initialize Firmware Control Block. */
443 memset(&mbox_cmd, 0, sizeof(mbox_cmd));
444 memset(&mbox_sts, 0, sizeof(mbox_sts));
David C Somayajuluc0e344c2007-05-23 18:03:27 -0700445
Vikas Chaudhary2a49a782010-04-28 11:37:07 +0530446 if (qla4xxx_get_ifcb(ha, &mbox_cmd[0], &mbox_sts[0], init_fw_cb_dma) !=
David Somayajuluafaf5a22006-09-19 10:28:00 -0700447 QLA_SUCCESS) {
448 dma_free_coherent(&ha->pdev->dev,
Vikas Chaudhary2a49a782010-04-28 11:37:07 +0530449 sizeof(struct addr_ctrl_blk),
David Somayajuluafaf5a22006-09-19 10:28:00 -0700450 init_fw_cb, init_fw_cb_dma);
Vikas Chaudhary2a49a782010-04-28 11:37:07 +0530451 goto exit_init_fw_cb;
David Somayajuluafaf5a22006-09-19 10:28:00 -0700452 }
453
454 /* Initialize request and response queues. */
455 qla4xxx_init_rings(ha);
456
457 /* Fill in the request and response queue information. */
Vikas Chaudhary2a49a782010-04-28 11:37:07 +0530458 init_fw_cb->rqq_consumer_idx = cpu_to_le16(ha->request_out);
459 init_fw_cb->compq_producer_idx = cpu_to_le16(ha->response_in);
460 init_fw_cb->rqq_len = __constant_cpu_to_le16(REQUEST_QUEUE_DEPTH);
461 init_fw_cb->compq_len = __constant_cpu_to_le16(RESPONSE_QUEUE_DEPTH);
462 init_fw_cb->rqq_addr_lo = cpu_to_le32(LSDW(ha->request_dma));
463 init_fw_cb->rqq_addr_hi = cpu_to_le32(MSDW(ha->request_dma));
464 init_fw_cb->compq_addr_lo = cpu_to_le32(LSDW(ha->response_dma));
465 init_fw_cb->compq_addr_hi = cpu_to_le32(MSDW(ha->response_dma));
466 init_fw_cb->shdwreg_addr_lo = cpu_to_le32(LSDW(ha->shadow_regs_dma));
467 init_fw_cb->shdwreg_addr_hi = cpu_to_le32(MSDW(ha->shadow_regs_dma));
David Somayajuluafaf5a22006-09-19 10:28:00 -0700468
469 /* Set up required options. */
Vikas Chaudhary2a49a782010-04-28 11:37:07 +0530470 init_fw_cb->fw_options |=
David Somayajuluafaf5a22006-09-19 10:28:00 -0700471 __constant_cpu_to_le16(FWOPT_SESSION_MODE |
472 FWOPT_INITIATOR_MODE);
Shyam Sundar2657c802010-10-06 22:50:29 -0700473
474 if (is_qla8022(ha))
475 init_fw_cb->fw_options |=
476 __constant_cpu_to_le16(FWOPT_ENABLE_CRBDB);
477
Vikas Chaudhary2a49a782010-04-28 11:37:07 +0530478 init_fw_cb->fw_options &= __constant_cpu_to_le16(~FWOPT_TARGET_MODE);
David Somayajuluafaf5a22006-09-19 10:28:00 -0700479
Prasanna Mumbaid32cee32011-03-21 03:34:35 -0700480 /* Set bit for "serialize task mgmt" all other bits need to be zero */
481 init_fw_cb->add_fw_options = 0;
482 init_fw_cb->add_fw_options |=
483 __constant_cpu_to_le16(SERIALIZE_TASK_MGMT);
484
Vikas Chaudhary2a49a782010-04-28 11:37:07 +0530485 if (qla4xxx_set_ifcb(ha, &mbox_cmd[0], &mbox_sts[0], init_fw_cb_dma)
486 != QLA_SUCCESS) {
487 DEBUG2(printk(KERN_WARNING
488 "scsi%ld: %s: Failed to set init_fw_ctrl_blk\n",
489 ha->host_no, __func__));
490 goto exit_init_fw_cb;
David Somayajuluafaf5a22006-09-19 10:28:00 -0700491 }
Vikas Chaudhary2a49a782010-04-28 11:37:07 +0530492
493 if (qla4xxx_update_local_ifcb(ha, &mbox_cmd[0], &mbox_sts[0],
494 init_fw_cb, init_fw_cb_dma) != QLA_SUCCESS) {
495 DEBUG2(printk("scsi%ld: %s: Failed to update local ifcb\n",
496 ha->host_no, __func__));
497 goto exit_init_fw_cb;
498 }
499 status = QLA_SUCCESS;
500
501exit_init_fw_cb:
502 dma_free_coherent(&ha->pdev->dev, sizeof(struct addr_ctrl_blk),
503 init_fw_cb, init_fw_cb_dma);
Prasanna Mumbaibeabe7c2010-07-10 14:49:38 +0530504exit_init_fw_cb_no_free:
David Somayajuluafaf5a22006-09-19 10:28:00 -0700505 return status;
506}
507
508/**
509 * qla4xxx_get_dhcp_ip_address - gets HBA ip address via DHCP
510 * @ha: Pointer to host adapter structure.
511 **/
512int qla4xxx_get_dhcp_ip_address(struct scsi_qla_host * ha)
513{
Vikas Chaudhary2a49a782010-04-28 11:37:07 +0530514 struct addr_ctrl_blk *init_fw_cb;
David Somayajuluafaf5a22006-09-19 10:28:00 -0700515 dma_addr_t init_fw_cb_dma;
516 uint32_t mbox_cmd[MBOX_REG_COUNT];
517 uint32_t mbox_sts[MBOX_REG_COUNT];
518
519 init_fw_cb = dma_alloc_coherent(&ha->pdev->dev,
Vikas Chaudhary2a49a782010-04-28 11:37:07 +0530520 sizeof(struct addr_ctrl_blk),
David Somayajuluafaf5a22006-09-19 10:28:00 -0700521 &init_fw_cb_dma, GFP_KERNEL);
522 if (init_fw_cb == NULL) {
523 printk("scsi%ld: %s: Unable to alloc init_cb\n", ha->host_no,
524 __func__);
Prasanna Mumbaibeabe7c2010-07-10 14:49:38 +0530525 return QLA_ERROR;
David Somayajuluafaf5a22006-09-19 10:28:00 -0700526 }
527
528 /* Get Initialize Firmware Control Block. */
Vikas Chaudhary2a49a782010-04-28 11:37:07 +0530529 memset(init_fw_cb, 0, sizeof(struct addr_ctrl_blk));
530 if (qla4xxx_get_ifcb(ha, &mbox_cmd[0], &mbox_sts[0], init_fw_cb_dma) !=
David Somayajuluafaf5a22006-09-19 10:28:00 -0700531 QLA_SUCCESS) {
532 DEBUG2(printk("scsi%ld: %s: Failed to get init_fw_ctrl_blk\n",
533 ha->host_no, __func__));
534 dma_free_coherent(&ha->pdev->dev,
Vikas Chaudhary2a49a782010-04-28 11:37:07 +0530535 sizeof(struct addr_ctrl_blk),
David Somayajuluafaf5a22006-09-19 10:28:00 -0700536 init_fw_cb, init_fw_cb_dma);
537 return QLA_ERROR;
538 }
539
540 /* Save IP Address. */
Vikas Chaudhary2a49a782010-04-28 11:37:07 +0530541 qla4xxx_update_local_ip(ha, init_fw_cb);
542 dma_free_coherent(&ha->pdev->dev, sizeof(struct addr_ctrl_blk),
543 init_fw_cb, init_fw_cb_dma);
David Somayajuluafaf5a22006-09-19 10:28:00 -0700544
545 return QLA_SUCCESS;
546}
547
548/**
549 * qla4xxx_get_firmware_state - gets firmware state of HBA
550 * @ha: Pointer to host adapter structure.
551 **/
552int qla4xxx_get_firmware_state(struct scsi_qla_host * ha)
553{
554 uint32_t mbox_cmd[MBOX_REG_COUNT];
555 uint32_t mbox_sts[MBOX_REG_COUNT];
556
557 /* Get firmware version */
558 memset(&mbox_cmd, 0, sizeof(mbox_cmd));
559 memset(&mbox_sts, 0, sizeof(mbox_sts));
David C Somayajuluc0e344c2007-05-23 18:03:27 -0700560
David Somayajuluafaf5a22006-09-19 10:28:00 -0700561 mbox_cmd[0] = MBOX_CMD_GET_FW_STATE;
David C Somayajuluc0e344c2007-05-23 18:03:27 -0700562
563 if (qla4xxx_mailbox_command(ha, MBOX_REG_COUNT, 4, &mbox_cmd[0], &mbox_sts[0]) !=
David Somayajuluafaf5a22006-09-19 10:28:00 -0700564 QLA_SUCCESS) {
565 DEBUG2(printk("scsi%ld: %s: MBOX_CMD_GET_FW_STATE failed w/ "
566 "status %04X\n", ha->host_no, __func__,
567 mbox_sts[0]));
568 return QLA_ERROR;
569 }
570 ha->firmware_state = mbox_sts[1];
571 ha->board_id = mbox_sts[2];
572 ha->addl_fw_state = mbox_sts[3];
573 DEBUG2(printk("scsi%ld: %s firmware_state=0x%x\n",
574 ha->host_no, __func__, ha->firmware_state);)
575
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +0530576 return QLA_SUCCESS;
David Somayajuluafaf5a22006-09-19 10:28:00 -0700577}
578
579/**
580 * qla4xxx_get_firmware_status - retrieves firmware status
581 * @ha: Pointer to host adapter structure.
582 **/
583int qla4xxx_get_firmware_status(struct scsi_qla_host * ha)
584{
585 uint32_t mbox_cmd[MBOX_REG_COUNT];
586 uint32_t mbox_sts[MBOX_REG_COUNT];
587
588 /* Get firmware version */
589 memset(&mbox_cmd, 0, sizeof(mbox_cmd));
590 memset(&mbox_sts, 0, sizeof(mbox_sts));
David C Somayajuluc0e344c2007-05-23 18:03:27 -0700591
David Somayajuluafaf5a22006-09-19 10:28:00 -0700592 mbox_cmd[0] = MBOX_CMD_GET_FW_STATUS;
David C Somayajuluc0e344c2007-05-23 18:03:27 -0700593
594 if (qla4xxx_mailbox_command(ha, MBOX_REG_COUNT, 3, &mbox_cmd[0], &mbox_sts[0]) !=
David Somayajuluafaf5a22006-09-19 10:28:00 -0700595 QLA_SUCCESS) {
596 DEBUG2(printk("scsi%ld: %s: MBOX_CMD_GET_FW_STATUS failed w/ "
597 "status %04X\n", ha->host_no, __func__,
598 mbox_sts[0]));
599 return QLA_ERROR;
600 }
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +0530601
602 ql4_printk(KERN_INFO, ha, "%ld firmare IOCBs available (%d).\n",
Vikas Chaudharyf581a3f2010-10-06 22:47:48 -0700603 ha->host_no, mbox_sts[2]);
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +0530604
David Somayajuluafaf5a22006-09-19 10:28:00 -0700605 return QLA_SUCCESS;
606}
607
608/**
609 * qla4xxx_get_fwddb_entry - retrieves firmware ddb entry
610 * @ha: Pointer to host adapter structure.
611 * @fw_ddb_index: Firmware's device database index
612 * @fw_ddb_entry: Pointer to firmware's device database entry structure
613 * @num_valid_ddb_entries: Pointer to number of valid ddb entries
614 * @next_ddb_index: Pointer to next valid device database index
615 * @fw_ddb_device_state: Pointer to device state
616 **/
617int qla4xxx_get_fwddb_entry(struct scsi_qla_host *ha,
618 uint16_t fw_ddb_index,
619 struct dev_db_entry *fw_ddb_entry,
620 dma_addr_t fw_ddb_entry_dma,
621 uint32_t *num_valid_ddb_entries,
622 uint32_t *next_ddb_index,
623 uint32_t *fw_ddb_device_state,
624 uint32_t *conn_err_detail,
625 uint16_t *tcp_source_port_num,
626 uint16_t *connection_id)
627{
628 int status = QLA_ERROR;
Vikas Chaudhary2a49a782010-04-28 11:37:07 +0530629 uint16_t options;
David Somayajuluafaf5a22006-09-19 10:28:00 -0700630 uint32_t mbox_cmd[MBOX_REG_COUNT];
631 uint32_t mbox_sts[MBOX_REG_COUNT];
632
633 /* Make sure the device index is valid */
634 if (fw_ddb_index >= MAX_DDB_ENTRIES) {
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +0530635 DEBUG2(printk("scsi%ld: %s: ddb [%d] out of range.\n",
David Somayajuluafaf5a22006-09-19 10:28:00 -0700636 ha->host_no, __func__, fw_ddb_index));
637 goto exit_get_fwddb;
638 }
639 memset(&mbox_cmd, 0, sizeof(mbox_cmd));
640 memset(&mbox_sts, 0, sizeof(mbox_sts));
David C Somayajuluc0e344c2007-05-23 18:03:27 -0700641
David Somayajuluafaf5a22006-09-19 10:28:00 -0700642 mbox_cmd[0] = MBOX_CMD_GET_DATABASE_ENTRY;
643 mbox_cmd[1] = (uint32_t) fw_ddb_index;
644 mbox_cmd[2] = LSDW(fw_ddb_entry_dma);
645 mbox_cmd[3] = MSDW(fw_ddb_entry_dma);
David C Somayajuluc0e344c2007-05-23 18:03:27 -0700646 mbox_cmd[4] = sizeof(struct dev_db_entry);
647
648 if (qla4xxx_mailbox_command(ha, MBOX_REG_COUNT, 7, &mbox_cmd[0], &mbox_sts[0]) ==
David Somayajuluafaf5a22006-09-19 10:28:00 -0700649 QLA_ERROR) {
650 DEBUG2(printk("scsi%ld: %s: MBOX_CMD_GET_DATABASE_ENTRY failed"
651 " with status 0x%04X\n", ha->host_no, __func__,
652 mbox_sts[0]));
653 goto exit_get_fwddb;
654 }
655 if (fw_ddb_index != mbox_sts[1]) {
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +0530656 DEBUG2(printk("scsi%ld: %s: ddb mismatch [%d] != [%d].\n",
David Somayajuluafaf5a22006-09-19 10:28:00 -0700657 ha->host_no, __func__, fw_ddb_index,
658 mbox_sts[1]));
659 goto exit_get_fwddb;
660 }
661 if (fw_ddb_entry) {
Vikas Chaudhary2a49a782010-04-28 11:37:07 +0530662 options = le16_to_cpu(fw_ddb_entry->options);
663 if (options & DDB_OPT_IPV6_DEVICE) {
Vikas Chaudharyc2660df2010-07-10 14:51:02 +0530664 ql4_printk(KERN_INFO, ha, "%s: DDB[%d] MB0 %04x Tot %d "
Vikas Chaudhary2a49a782010-04-28 11:37:07 +0530665 "Next %d State %04x ConnErr %08x %pI6 "
666 ":%04d \"%s\"\n", __func__, fw_ddb_index,
667 mbox_sts[0], mbox_sts[2], mbox_sts[3],
668 mbox_sts[4], mbox_sts[5],
669 fw_ddb_entry->ip_addr,
670 le16_to_cpu(fw_ddb_entry->port),
671 fw_ddb_entry->iscsi_name);
672 } else {
Vikas Chaudharyc2660df2010-07-10 14:51:02 +0530673 ql4_printk(KERN_INFO, ha, "%s: DDB[%d] MB0 %04x Tot %d "
Vikas Chaudhary2a49a782010-04-28 11:37:07 +0530674 "Next %d State %04x ConnErr %08x %pI4 "
675 ":%04d \"%s\"\n", __func__, fw_ddb_index,
676 mbox_sts[0], mbox_sts[2], mbox_sts[3],
677 mbox_sts[4], mbox_sts[5],
678 fw_ddb_entry->ip_addr,
679 le16_to_cpu(fw_ddb_entry->port),
680 fw_ddb_entry->iscsi_name);
681 }
David Somayajuluafaf5a22006-09-19 10:28:00 -0700682 }
683 if (num_valid_ddb_entries)
684 *num_valid_ddb_entries = mbox_sts[2];
685 if (next_ddb_index)
686 *next_ddb_index = mbox_sts[3];
687 if (fw_ddb_device_state)
688 *fw_ddb_device_state = mbox_sts[4];
689
690 /*
691 * RA: This mailbox has been changed to pass connection error and
692 * details. Its true for ISP4010 as per Version E - Not sure when it
693 * was changed. Get the time2wait from the fw_dd_entry field :
694 * default_time2wait which we call it as minTime2Wait DEV_DB_ENTRY
695 * struct.
696 */
697 if (conn_err_detail)
698 *conn_err_detail = mbox_sts[5];
699 if (tcp_source_port_num)
Randy Dunlap14823382010-04-22 11:02:14 -0700700 *tcp_source_port_num = (uint16_t) (mbox_sts[6] >> 16);
David Somayajuluafaf5a22006-09-19 10:28:00 -0700701 if (connection_id)
702 *connection_id = (uint16_t) mbox_sts[6] & 0x00FF;
703 status = QLA_SUCCESS;
704
705exit_get_fwddb:
706 return status;
707}
708
709/**
710 * qla4xxx_set_fwddb_entry - sets a ddb entry.
711 * @ha: Pointer to host adapter structure.
712 * @fw_ddb_index: Firmware's device database index
713 * @fw_ddb_entry: Pointer to firmware's ddb entry structure, or NULL.
714 *
715 * This routine initializes or updates the adapter's device database
716 * entry for the specified device. It also triggers a login for the
717 * specified device. Therefore, it may also be used as a secondary
718 * login routine when a NULL pointer is specified for the fw_ddb_entry.
719 **/
720int qla4xxx_set_ddb_entry(struct scsi_qla_host * ha, uint16_t fw_ddb_index,
721 dma_addr_t fw_ddb_entry_dma)
722{
723 uint32_t mbox_cmd[MBOX_REG_COUNT];
724 uint32_t mbox_sts[MBOX_REG_COUNT];
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +0530725 int status;
David Somayajuluafaf5a22006-09-19 10:28:00 -0700726
727 /* Do not wait for completion. The firmware will send us an
728 * ASTS_DATABASE_CHANGED (0x8014) to notify us of the login status.
729 */
730 memset(&mbox_cmd, 0, sizeof(mbox_cmd));
731 memset(&mbox_sts, 0, sizeof(mbox_sts));
732
733 mbox_cmd[0] = MBOX_CMD_SET_DATABASE_ENTRY;
734 mbox_cmd[1] = (uint32_t) fw_ddb_index;
735 mbox_cmd[2] = LSDW(fw_ddb_entry_dma);
736 mbox_cmd[3] = MSDW(fw_ddb_entry_dma);
David C Somayajuluc0e344c2007-05-23 18:03:27 -0700737 mbox_cmd[4] = sizeof(struct dev_db_entry);
738
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +0530739 status = qla4xxx_mailbox_command(ha, MBOX_REG_COUNT, 5, &mbox_cmd[0],
740 &mbox_sts[0]);
741 DEBUG2(printk("scsi%ld: %s: status=%d mbx0=0x%x mbx4=0x%x\n",
742 ha->host_no, __func__, status, mbox_sts[0], mbox_sts[4]);)
743
744 return status;
David Somayajuluafaf5a22006-09-19 10:28:00 -0700745}
746
David Somayajuluafaf5a22006-09-19 10:28:00 -0700747/**
748 * qla4xxx_get_crash_record - retrieves crash record.
749 * @ha: Pointer to host adapter structure.
750 *
751 * This routine retrieves a crash record from the QLA4010 after an 8002h aen.
752 **/
753void qla4xxx_get_crash_record(struct scsi_qla_host * ha)
754{
755 uint32_t mbox_cmd[MBOX_REG_COUNT];
756 uint32_t mbox_sts[MBOX_REG_COUNT];
757 struct crash_record *crash_record = NULL;
758 dma_addr_t crash_record_dma = 0;
759 uint32_t crash_record_size = 0;
David C Somayajuluc0e344c2007-05-23 18:03:27 -0700760
David Somayajuluafaf5a22006-09-19 10:28:00 -0700761 memset(&mbox_cmd, 0, sizeof(mbox_cmd));
762 memset(&mbox_sts, 0, sizeof(mbox_cmd));
763
764 /* Get size of crash record. */
765 mbox_cmd[0] = MBOX_CMD_GET_CRASH_RECORD;
David C Somayajuluc0e344c2007-05-23 18:03:27 -0700766
767 if (qla4xxx_mailbox_command(ha, MBOX_REG_COUNT, 5, &mbox_cmd[0], &mbox_sts[0]) !=
David Somayajuluafaf5a22006-09-19 10:28:00 -0700768 QLA_SUCCESS) {
769 DEBUG2(printk("scsi%ld: %s: ERROR: Unable to retrieve size!\n",
770 ha->host_no, __func__));
771 goto exit_get_crash_record;
772 }
773 crash_record_size = mbox_sts[4];
774 if (crash_record_size == 0) {
775 DEBUG2(printk("scsi%ld: %s: ERROR: Crash record size is 0!\n",
776 ha->host_no, __func__));
777 goto exit_get_crash_record;
778 }
779
780 /* Alloc Memory for Crash Record. */
781 crash_record = dma_alloc_coherent(&ha->pdev->dev, crash_record_size,
782 &crash_record_dma, GFP_KERNEL);
783 if (crash_record == NULL)
784 goto exit_get_crash_record;
785
786 /* Get Crash Record. */
David C Somayajuluc0e344c2007-05-23 18:03:27 -0700787 memset(&mbox_cmd, 0, sizeof(mbox_cmd));
788 memset(&mbox_sts, 0, sizeof(mbox_cmd));
789
David Somayajuluafaf5a22006-09-19 10:28:00 -0700790 mbox_cmd[0] = MBOX_CMD_GET_CRASH_RECORD;
791 mbox_cmd[2] = LSDW(crash_record_dma);
792 mbox_cmd[3] = MSDW(crash_record_dma);
793 mbox_cmd[4] = crash_record_size;
David C Somayajuluc0e344c2007-05-23 18:03:27 -0700794
795 if (qla4xxx_mailbox_command(ha, MBOX_REG_COUNT, 5, &mbox_cmd[0], &mbox_sts[0]) !=
David Somayajuluafaf5a22006-09-19 10:28:00 -0700796 QLA_SUCCESS)
797 goto exit_get_crash_record;
798
799 /* Dump Crash Record. */
800
801exit_get_crash_record:
802 if (crash_record)
803 dma_free_coherent(&ha->pdev->dev, crash_record_size,
804 crash_record, crash_record_dma);
805}
806
807/**
808 * qla4xxx_get_conn_event_log - retrieves connection event log
809 * @ha: Pointer to host adapter structure.
810 **/
811void qla4xxx_get_conn_event_log(struct scsi_qla_host * ha)
812{
813 uint32_t mbox_cmd[MBOX_REG_COUNT];
814 uint32_t mbox_sts[MBOX_REG_COUNT];
815 struct conn_event_log_entry *event_log = NULL;
816 dma_addr_t event_log_dma = 0;
817 uint32_t event_log_size = 0;
818 uint32_t num_valid_entries;
819 uint32_t oldest_entry = 0;
820 uint32_t max_event_log_entries;
821 uint8_t i;
822
823
824 memset(&mbox_cmd, 0, sizeof(mbox_cmd));
825 memset(&mbox_sts, 0, sizeof(mbox_cmd));
826
827 /* Get size of crash record. */
828 mbox_cmd[0] = MBOX_CMD_GET_CONN_EVENT_LOG;
David C Somayajuluc0e344c2007-05-23 18:03:27 -0700829
830 if (qla4xxx_mailbox_command(ha, MBOX_REG_COUNT, 5, &mbox_cmd[0], &mbox_sts[0]) !=
David Somayajuluafaf5a22006-09-19 10:28:00 -0700831 QLA_SUCCESS)
832 goto exit_get_event_log;
833
834 event_log_size = mbox_sts[4];
835 if (event_log_size == 0)
836 goto exit_get_event_log;
837
838 /* Alloc Memory for Crash Record. */
839 event_log = dma_alloc_coherent(&ha->pdev->dev, event_log_size,
840 &event_log_dma, GFP_KERNEL);
841 if (event_log == NULL)
842 goto exit_get_event_log;
843
844 /* Get Crash Record. */
David C Somayajuluc0e344c2007-05-23 18:03:27 -0700845 memset(&mbox_cmd, 0, sizeof(mbox_cmd));
846 memset(&mbox_sts, 0, sizeof(mbox_cmd));
847
David Somayajuluafaf5a22006-09-19 10:28:00 -0700848 mbox_cmd[0] = MBOX_CMD_GET_CONN_EVENT_LOG;
849 mbox_cmd[2] = LSDW(event_log_dma);
850 mbox_cmd[3] = MSDW(event_log_dma);
David C Somayajuluc0e344c2007-05-23 18:03:27 -0700851
852 if (qla4xxx_mailbox_command(ha, MBOX_REG_COUNT, 5, &mbox_cmd[0], &mbox_sts[0]) !=
David Somayajuluafaf5a22006-09-19 10:28:00 -0700853 QLA_SUCCESS) {
854 DEBUG2(printk("scsi%ld: %s: ERROR: Unable to retrieve event "
855 "log!\n", ha->host_no, __func__));
856 goto exit_get_event_log;
857 }
858
859 /* Dump Event Log. */
860 num_valid_entries = mbox_sts[1];
861
862 max_event_log_entries = event_log_size /
863 sizeof(struct conn_event_log_entry);
864
865 if (num_valid_entries > max_event_log_entries)
866 oldest_entry = num_valid_entries % max_event_log_entries;
867
868 DEBUG3(printk("scsi%ld: Connection Event Log Dump (%d entries):\n",
869 ha->host_no, num_valid_entries));
870
Andrew Vasquez11010fe2006-10-06 09:54:59 -0700871 if (ql4xextended_error_logging == 3) {
David Somayajuluafaf5a22006-09-19 10:28:00 -0700872 if (oldest_entry == 0) {
873 /* Circular Buffer has not wrapped around */
874 for (i=0; i < num_valid_entries; i++) {
875 qla4xxx_dump_buffer((uint8_t *)event_log+
876 (i*sizeof(*event_log)),
877 sizeof(*event_log));
878 }
879 }
880 else {
881 /* Circular Buffer has wrapped around -
882 * display accordingly*/
883 for (i=oldest_entry; i < max_event_log_entries; i++) {
884 qla4xxx_dump_buffer((uint8_t *)event_log+
885 (i*sizeof(*event_log)),
886 sizeof(*event_log));
887 }
888 for (i=0; i < oldest_entry; i++) {
889 qla4xxx_dump_buffer((uint8_t *)event_log+
890 (i*sizeof(*event_log)),
891 sizeof(*event_log));
892 }
893 }
894 }
895
896exit_get_event_log:
897 if (event_log)
898 dma_free_coherent(&ha->pdev->dev, event_log_size, event_log,
899 event_log_dma);
900}
901
902/**
Vikas Chaudhary09a0f712010-04-28 11:42:24 +0530903 * qla4xxx_abort_task - issues Abort Task
904 * @ha: Pointer to host adapter structure.
905 * @srb: Pointer to srb entry
906 *
907 * This routine performs a LUN RESET on the specified target/lun.
908 * The caller must ensure that the ddb_entry and lun_entry pointers
909 * are valid before calling this routine.
910 **/
911int qla4xxx_abort_task(struct scsi_qla_host *ha, struct srb *srb)
912{
913 uint32_t mbox_cmd[MBOX_REG_COUNT];
914 uint32_t mbox_sts[MBOX_REG_COUNT];
915 struct scsi_cmnd *cmd = srb->cmd;
916 int status = QLA_SUCCESS;
917 unsigned long flags = 0;
918 uint32_t index;
919
920 /*
921 * Send abort task command to ISP, so that the ISP will return
922 * request with ABORT status
923 */
924 memset(&mbox_cmd, 0, sizeof(mbox_cmd));
925 memset(&mbox_sts, 0, sizeof(mbox_sts));
926
927 spin_lock_irqsave(&ha->hardware_lock, flags);
928 index = (unsigned long)(unsigned char *)cmd->host_scribble;
929 spin_unlock_irqrestore(&ha->hardware_lock, flags);
930
931 /* Firmware already posted completion on response queue */
932 if (index == MAX_SRBS)
933 return status;
934
935 mbox_cmd[0] = MBOX_CMD_ABORT_TASK;
Karen Higgins6790d4f2010-12-02 22:12:22 -0800936 mbox_cmd[1] = srb->ddb->fw_ddb_index;
Vikas Chaudhary09a0f712010-04-28 11:42:24 +0530937 mbox_cmd[2] = index;
938 /* Immediate Command Enable */
939 mbox_cmd[5] = 0x01;
940
941 qla4xxx_mailbox_command(ha, MBOX_REG_COUNT, 5, &mbox_cmd[0],
942 &mbox_sts[0]);
943 if (mbox_sts[0] != MBOX_STS_COMMAND_COMPLETE) {
944 status = QLA_ERROR;
945
946 DEBUG2(printk(KERN_WARNING "scsi%ld:%d:%d: abort task FAILED: "
947 "mbx0=%04X, mb1=%04X, mb2=%04X, mb3=%04X, mb4=%04X\n",
948 ha->host_no, cmd->device->id, cmd->device->lun, mbox_sts[0],
949 mbox_sts[1], mbox_sts[2], mbox_sts[3], mbox_sts[4]));
950 }
951
952 return status;
953}
954
955/**
David Somayajuluafaf5a22006-09-19 10:28:00 -0700956 * qla4xxx_reset_lun - issues LUN Reset
957 * @ha: Pointer to host adapter structure.
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +0530958 * @ddb_entry: Pointer to device database entry
959 * @lun: lun number
David Somayajuluafaf5a22006-09-19 10:28:00 -0700960 *
961 * This routine performs a LUN RESET on the specified target/lun.
962 * The caller must ensure that the ddb_entry and lun_entry pointers
963 * are valid before calling this routine.
964 **/
965int qla4xxx_reset_lun(struct scsi_qla_host * ha, struct ddb_entry * ddb_entry,
966 int lun)
967{
968 uint32_t mbox_cmd[MBOX_REG_COUNT];
969 uint32_t mbox_sts[MBOX_REG_COUNT];
970 int status = QLA_SUCCESS;
971
972 DEBUG2(printk("scsi%ld:%d:%d: lun reset issued\n", ha->host_no,
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +0530973 ddb_entry->fw_ddb_index, lun));
David Somayajuluafaf5a22006-09-19 10:28:00 -0700974
975 /*
976 * Send lun reset command to ISP, so that the ISP will return all
977 * outstanding requests with RESET status
978 */
979 memset(&mbox_cmd, 0, sizeof(mbox_cmd));
980 memset(&mbox_sts, 0, sizeof(mbox_sts));
David C Somayajuluc0e344c2007-05-23 18:03:27 -0700981
David Somayajuluafaf5a22006-09-19 10:28:00 -0700982 mbox_cmd[0] = MBOX_CMD_LUN_RESET;
983 mbox_cmd[1] = ddb_entry->fw_ddb_index;
984 mbox_cmd[2] = lun << 8;
985 mbox_cmd[5] = 0x01; /* Immediate Command Enable */
David C Somayajuluc0e344c2007-05-23 18:03:27 -0700986
987 qla4xxx_mailbox_command(ha, MBOX_REG_COUNT, 1, &mbox_cmd[0], &mbox_sts[0]);
David Somayajuluafaf5a22006-09-19 10:28:00 -0700988 if (mbox_sts[0] != MBOX_STS_COMMAND_COMPLETE &&
989 mbox_sts[0] != MBOX_STS_COMMAND_ERROR)
990 status = QLA_ERROR;
991
992 return status;
993}
994
Mike Christiece545032008-02-29 18:25:20 -0600995/**
996 * qla4xxx_reset_target - issues target Reset
997 * @ha: Pointer to host adapter structure.
998 * @db_entry: Pointer to device database entry
999 * @un_entry: Pointer to lun entry structure
1000 *
1001 * This routine performs a TARGET RESET on the specified target.
1002 * The caller must ensure that the ddb_entry pointers
1003 * are valid before calling this routine.
1004 **/
1005int qla4xxx_reset_target(struct scsi_qla_host *ha,
1006 struct ddb_entry *ddb_entry)
1007{
1008 uint32_t mbox_cmd[MBOX_REG_COUNT];
1009 uint32_t mbox_sts[MBOX_REG_COUNT];
1010 int status = QLA_SUCCESS;
1011
1012 DEBUG2(printk("scsi%ld:%d: target reset issued\n", ha->host_no,
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05301013 ddb_entry->fw_ddb_index));
Mike Christiece545032008-02-29 18:25:20 -06001014
1015 /*
1016 * Send target reset command to ISP, so that the ISP will return all
1017 * outstanding requests with RESET status
1018 */
1019 memset(&mbox_cmd, 0, sizeof(mbox_cmd));
1020 memset(&mbox_sts, 0, sizeof(mbox_sts));
1021
1022 mbox_cmd[0] = MBOX_CMD_TARGET_WARM_RESET;
1023 mbox_cmd[1] = ddb_entry->fw_ddb_index;
1024 mbox_cmd[5] = 0x01; /* Immediate Command Enable */
1025
1026 qla4xxx_mailbox_command(ha, MBOX_REG_COUNT, 1, &mbox_cmd[0],
1027 &mbox_sts[0]);
1028 if (mbox_sts[0] != MBOX_STS_COMMAND_COMPLETE &&
1029 mbox_sts[0] != MBOX_STS_COMMAND_ERROR)
1030 status = QLA_ERROR;
1031
1032 return status;
1033}
David Somayajuluafaf5a22006-09-19 10:28:00 -07001034
1035int qla4xxx_get_flash(struct scsi_qla_host * ha, dma_addr_t dma_addr,
1036 uint32_t offset, uint32_t len)
1037{
1038 uint32_t mbox_cmd[MBOX_REG_COUNT];
1039 uint32_t mbox_sts[MBOX_REG_COUNT];
1040
1041 memset(&mbox_cmd, 0, sizeof(mbox_cmd));
1042 memset(&mbox_sts, 0, sizeof(mbox_sts));
David C Somayajuluc0e344c2007-05-23 18:03:27 -07001043
David Somayajuluafaf5a22006-09-19 10:28:00 -07001044 mbox_cmd[0] = MBOX_CMD_READ_FLASH;
1045 mbox_cmd[1] = LSDW(dma_addr);
1046 mbox_cmd[2] = MSDW(dma_addr);
1047 mbox_cmd[3] = offset;
1048 mbox_cmd[4] = len;
David C Somayajuluc0e344c2007-05-23 18:03:27 -07001049
1050 if (qla4xxx_mailbox_command(ha, MBOX_REG_COUNT, 2, &mbox_cmd[0], &mbox_sts[0]) !=
David Somayajuluafaf5a22006-09-19 10:28:00 -07001051 QLA_SUCCESS) {
1052 DEBUG2(printk("scsi%ld: %s: MBOX_CMD_READ_FLASH, failed w/ "
1053 "status %04X %04X, offset %08x, len %08x\n", ha->host_no,
1054 __func__, mbox_sts[0], mbox_sts[1], offset, len));
1055 return QLA_ERROR;
1056 }
1057 return QLA_SUCCESS;
1058}
1059
1060/**
Harish Zunjarrao7ad633c2011-05-17 23:17:11 -07001061 * qla4xxx_about_firmware - gets FW, iscsi draft and boot loader version
David Somayajuluafaf5a22006-09-19 10:28:00 -07001062 * @ha: Pointer to host adapter structure.
1063 *
Harish Zunjarrao7ad633c2011-05-17 23:17:11 -07001064 * Retrieves the FW version, iSCSI draft version & bootloader version of HBA.
1065 * Mailboxes 2 & 3 may hold an address for data. Make sure that we write 0 to
1066 * those mailboxes, if unused.
David Somayajuluafaf5a22006-09-19 10:28:00 -07001067 **/
Harish Zunjarrao7ad633c2011-05-17 23:17:11 -07001068int qla4xxx_about_firmware(struct scsi_qla_host *ha)
David Somayajuluafaf5a22006-09-19 10:28:00 -07001069{
Harish Zunjarrao7ad633c2011-05-17 23:17:11 -07001070 struct about_fw_info *about_fw = NULL;
1071 dma_addr_t about_fw_dma;
David Somayajuluafaf5a22006-09-19 10:28:00 -07001072 uint32_t mbox_cmd[MBOX_REG_COUNT];
1073 uint32_t mbox_sts[MBOX_REG_COUNT];
Harish Zunjarrao7ad633c2011-05-17 23:17:11 -07001074 int status = QLA_ERROR;
David Somayajuluafaf5a22006-09-19 10:28:00 -07001075
Harish Zunjarrao7ad633c2011-05-17 23:17:11 -07001076 about_fw = dma_alloc_coherent(&ha->pdev->dev,
1077 sizeof(struct about_fw_info),
1078 &about_fw_dma, GFP_KERNEL);
1079 if (!about_fw) {
1080 DEBUG2(ql4_printk(KERN_ERR, ha, "%s: Unable to alloc memory "
1081 "for about_fw\n", __func__));
1082 return status;
1083 }
1084
1085 memset(about_fw, 0, sizeof(struct about_fw_info));
David Somayajuluafaf5a22006-09-19 10:28:00 -07001086 memset(&mbox_cmd, 0, sizeof(mbox_cmd));
1087 memset(&mbox_sts, 0, sizeof(mbox_sts));
David C Somayajuluc0e344c2007-05-23 18:03:27 -07001088
David Somayajuluafaf5a22006-09-19 10:28:00 -07001089 mbox_cmd[0] = MBOX_CMD_ABOUT_FW;
Harish Zunjarrao7ad633c2011-05-17 23:17:11 -07001090 mbox_cmd[2] = LSDW(about_fw_dma);
1091 mbox_cmd[3] = MSDW(about_fw_dma);
1092 mbox_cmd[4] = sizeof(struct about_fw_info);
David C Somayajuluc0e344c2007-05-23 18:03:27 -07001093
Harish Zunjarrao7ad633c2011-05-17 23:17:11 -07001094 status = qla4xxx_mailbox_command(ha, MBOX_REG_COUNT, MBOX_REG_COUNT,
1095 &mbox_cmd[0], &mbox_sts[0]);
1096 if (status != QLA_SUCCESS) {
1097 DEBUG2(ql4_printk(KERN_WARNING, ha, "%s: MBOX_CMD_ABOUT_FW "
1098 "failed w/ status %04X\n", __func__,
1099 mbox_sts[0]));
1100 goto exit_about_fw;
David Somayajuluafaf5a22006-09-19 10:28:00 -07001101 }
1102
Harish Zunjarrao7ad633c2011-05-17 23:17:11 -07001103 /* Save version information. */
1104 ha->firmware_version[0] = le16_to_cpu(about_fw->fw_major);
1105 ha->firmware_version[1] = le16_to_cpu(about_fw->fw_minor);
1106 ha->patch_number = le16_to_cpu(about_fw->fw_patch);
1107 ha->build_number = le16_to_cpu(about_fw->fw_build);
1108 ha->iscsi_major = le16_to_cpu(about_fw->iscsi_major);
1109 ha->iscsi_minor = le16_to_cpu(about_fw->iscsi_minor);
1110 ha->bootload_major = le16_to_cpu(about_fw->bootload_major);
1111 ha->bootload_minor = le16_to_cpu(about_fw->bootload_minor);
1112 ha->bootload_patch = le16_to_cpu(about_fw->bootload_patch);
1113 ha->bootload_build = le16_to_cpu(about_fw->bootload_build);
1114 status = QLA_SUCCESS;
David Somayajuluafaf5a22006-09-19 10:28:00 -07001115
Harish Zunjarrao7ad633c2011-05-17 23:17:11 -07001116exit_about_fw:
1117 dma_free_coherent(&ha->pdev->dev, sizeof(struct about_fw_info),
1118 about_fw, about_fw_dma);
1119 return status;
David Somayajuluafaf5a22006-09-19 10:28:00 -07001120}
1121
Adrian Bunk47975472007-04-26 00:35:16 -07001122static int qla4xxx_get_default_ddb(struct scsi_qla_host *ha,
1123 dma_addr_t dma_addr)
David Somayajuluafaf5a22006-09-19 10:28:00 -07001124{
1125 uint32_t mbox_cmd[MBOX_REG_COUNT];
1126 uint32_t mbox_sts[MBOX_REG_COUNT];
1127
1128 memset(&mbox_cmd, 0, sizeof(mbox_cmd));
1129 memset(&mbox_sts, 0, sizeof(mbox_sts));
1130
1131 mbox_cmd[0] = MBOX_CMD_GET_DATABASE_ENTRY_DEFAULTS;
1132 mbox_cmd[2] = LSDW(dma_addr);
1133 mbox_cmd[3] = MSDW(dma_addr);
1134
David C Somayajuluc0e344c2007-05-23 18:03:27 -07001135 if (qla4xxx_mailbox_command(ha, MBOX_REG_COUNT, 1, &mbox_cmd[0], &mbox_sts[0]) !=
David Somayajuluafaf5a22006-09-19 10:28:00 -07001136 QLA_SUCCESS) {
1137 DEBUG2(printk("scsi%ld: %s: failed status %04X\n",
1138 ha->host_no, __func__, mbox_sts[0]));
1139 return QLA_ERROR;
1140 }
1141 return QLA_SUCCESS;
1142}
1143
Adrian Bunk47975472007-04-26 00:35:16 -07001144static int qla4xxx_req_ddb_entry(struct scsi_qla_host *ha, uint32_t *ddb_index)
David Somayajuluafaf5a22006-09-19 10:28:00 -07001145{
1146 uint32_t mbox_cmd[MBOX_REG_COUNT];
1147 uint32_t mbox_sts[MBOX_REG_COUNT];
1148
1149 memset(&mbox_cmd, 0, sizeof(mbox_cmd));
1150 memset(&mbox_sts, 0, sizeof(mbox_sts));
1151
1152 mbox_cmd[0] = MBOX_CMD_REQUEST_DATABASE_ENTRY;
1153 mbox_cmd[1] = MAX_PRST_DEV_DB_ENTRIES;
1154
David C Somayajuluc0e344c2007-05-23 18:03:27 -07001155 if (qla4xxx_mailbox_command(ha, MBOX_REG_COUNT, 3, &mbox_cmd[0], &mbox_sts[0]) !=
David Somayajuluafaf5a22006-09-19 10:28:00 -07001156 QLA_SUCCESS) {
1157 if (mbox_sts[0] == MBOX_STS_COMMAND_ERROR) {
1158 *ddb_index = mbox_sts[2];
1159 } else {
1160 DEBUG2(printk("scsi%ld: %s: failed status %04X\n",
1161 ha->host_no, __func__, mbox_sts[0]));
1162 return QLA_ERROR;
1163 }
1164 } else {
1165 *ddb_index = MAX_PRST_DEV_DB_ENTRIES;
1166 }
1167
1168 return QLA_SUCCESS;
1169}
1170
1171
1172int qla4xxx_send_tgts(struct scsi_qla_host *ha, char *ip, uint16_t port)
1173{
1174 struct dev_db_entry *fw_ddb_entry;
1175 dma_addr_t fw_ddb_entry_dma;
1176 uint32_t ddb_index;
1177 int ret_val = QLA_SUCCESS;
1178
1179
1180 fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev,
1181 sizeof(*fw_ddb_entry),
1182 &fw_ddb_entry_dma, GFP_KERNEL);
1183 if (!fw_ddb_entry) {
1184 DEBUG2(printk("scsi%ld: %s: Unable to allocate dma buffer.\n",
1185 ha->host_no, __func__));
1186 ret_val = QLA_ERROR;
Prasanna Mumbaibeabe7c2010-07-10 14:49:38 +05301187 goto exit_send_tgts_no_free;
David Somayajuluafaf5a22006-09-19 10:28:00 -07001188 }
1189
1190 ret_val = qla4xxx_get_default_ddb(ha, fw_ddb_entry_dma);
1191 if (ret_val != QLA_SUCCESS)
Prasanna Mumbaibeabe7c2010-07-10 14:49:38 +05301192 goto exit_send_tgts;
David Somayajuluafaf5a22006-09-19 10:28:00 -07001193
1194 ret_val = qla4xxx_req_ddb_entry(ha, &ddb_index);
1195 if (ret_val != QLA_SUCCESS)
Prasanna Mumbaibeabe7c2010-07-10 14:49:38 +05301196 goto exit_send_tgts;
David Somayajuluafaf5a22006-09-19 10:28:00 -07001197
David C Somayajuluc0e344c2007-05-23 18:03:27 -07001198 memset(fw_ddb_entry->iscsi_alias, 0,
1199 sizeof(fw_ddb_entry->iscsi_alias));
David Somayajuluafaf5a22006-09-19 10:28:00 -07001200
David C Somayajuluc0e344c2007-05-23 18:03:27 -07001201 memset(fw_ddb_entry->iscsi_name, 0,
1202 sizeof(fw_ddb_entry->iscsi_name));
David Somayajuluafaf5a22006-09-19 10:28:00 -07001203
David C Somayajuluc0e344c2007-05-23 18:03:27 -07001204 memset(fw_ddb_entry->ip_addr, 0, sizeof(fw_ddb_entry->ip_addr));
1205 memset(fw_ddb_entry->tgt_addr, 0,
1206 sizeof(fw_ddb_entry->tgt_addr));
David Somayajuluafaf5a22006-09-19 10:28:00 -07001207
1208 fw_ddb_entry->options = (DDB_OPT_DISC_SESSION | DDB_OPT_TARGET);
David C Somayajuluc0e344c2007-05-23 18:03:27 -07001209 fw_ddb_entry->port = cpu_to_le16(ntohs(port));
David Somayajuluafaf5a22006-09-19 10:28:00 -07001210
David C Somayajuluc0e344c2007-05-23 18:03:27 -07001211 fw_ddb_entry->ip_addr[0] = *ip;
1212 fw_ddb_entry->ip_addr[1] = *(ip + 1);
1213 fw_ddb_entry->ip_addr[2] = *(ip + 2);
1214 fw_ddb_entry->ip_addr[3] = *(ip + 3);
David Somayajuluafaf5a22006-09-19 10:28:00 -07001215
1216 ret_val = qla4xxx_set_ddb_entry(ha, ddb_index, fw_ddb_entry_dma);
1217
Prasanna Mumbaibeabe7c2010-07-10 14:49:38 +05301218exit_send_tgts:
David Somayajuluafaf5a22006-09-19 10:28:00 -07001219 dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
1220 fw_ddb_entry, fw_ddb_entry_dma);
Prasanna Mumbaibeabe7c2010-07-10 14:49:38 +05301221exit_send_tgts_no_free:
David Somayajuluafaf5a22006-09-19 10:28:00 -07001222 return ret_val;
1223}
1224
Mike Christied00efe32011-07-25 13:48:38 -05001225int qla4xxx_set_flash(struct scsi_qla_host *ha, dma_addr_t dma_addr,
1226 uint32_t offset, uint32_t length, uint32_t options)
1227{
1228 uint32_t mbox_cmd[MBOX_REG_COUNT];
1229 uint32_t mbox_sts[MBOX_REG_COUNT];
1230 int status = QLA_SUCCESS;
1231
1232 memset(&mbox_cmd, 0, sizeof(mbox_cmd));
1233 memset(&mbox_sts, 0, sizeof(mbox_sts));
1234
1235 mbox_cmd[0] = MBOX_CMD_WRITE_FLASH;
1236 mbox_cmd[1] = LSDW(dma_addr);
1237 mbox_cmd[2] = MSDW(dma_addr);
1238 mbox_cmd[3] = offset;
1239 mbox_cmd[4] = length;
1240 mbox_cmd[5] = options;
1241
1242 status = qla4xxx_mailbox_command(ha, 6, 2, &mbox_cmd[0], &mbox_sts[0]);
1243 if (status != QLA_SUCCESS) {
1244 DEBUG2(ql4_printk(KERN_WARNING, ha, "%s: MBOX_CMD_WRITE_FLASH "
1245 "failed w/ status %04X, mbx1 %04X\n",
1246 __func__, mbox_sts[0], mbox_sts[1]));
1247 }
1248 return status;
1249}
1250
1251int qla4xxx_conn_close_sess_logout(struct scsi_qla_host *ha,
1252 uint16_t fw_ddb_index,
1253 uint16_t connection_id,
1254 uint16_t option)
1255{
1256 uint32_t mbox_cmd[MBOX_REG_COUNT];
1257 uint32_t mbox_sts[MBOX_REG_COUNT];
1258 int status = QLA_SUCCESS;
1259
1260 memset(&mbox_cmd, 0, sizeof(mbox_cmd));
1261 memset(&mbox_sts, 0, sizeof(mbox_sts));
1262
1263 mbox_cmd[0] = MBOX_CMD_CONN_CLOSE_SESS_LOGOUT;
1264 mbox_cmd[1] = fw_ddb_index;
1265 mbox_cmd[2] = connection_id;
1266 mbox_cmd[3] = option;
1267
1268 status = qla4xxx_mailbox_command(ha, 4, 2, &mbox_cmd[0], &mbox_sts[0]);
1269 if (status != QLA_SUCCESS) {
1270 DEBUG2(ql4_printk(KERN_WARNING, ha, "%s: MBOX_CMD_CONN_CLOSE "
1271 "option %04x failed w/ status %04X %04X\n",
1272 __func__, option, mbox_sts[0], mbox_sts[1]));
1273 }
1274 return status;
1275}
1276
1277int qla4xxx_disable_acb(struct scsi_qla_host *ha)
1278{
1279 uint32_t mbox_cmd[MBOX_REG_COUNT];
1280 uint32_t mbox_sts[MBOX_REG_COUNT];
1281 int status = QLA_SUCCESS;
1282
1283 memset(&mbox_cmd, 0, sizeof(mbox_cmd));
1284 memset(&mbox_sts, 0, sizeof(mbox_sts));
1285
1286 mbox_cmd[0] = MBOX_CMD_DISABLE_ACB;
1287
1288 status = qla4xxx_mailbox_command(ha, 8, 5, &mbox_cmd[0], &mbox_sts[0]);
1289 if (status != QLA_SUCCESS) {
1290 DEBUG2(ql4_printk(KERN_WARNING, ha, "%s: MBOX_CMD_DISABLE_ACB "
1291 "failed w/ status %04X %04X %04X", __func__,
1292 mbox_sts[0], mbox_sts[1], mbox_sts[2]));
1293 }
1294 return status;
1295}
1296
1297int qla4xxx_get_acb(struct scsi_qla_host *ha, uint32_t *mbox_cmd,
1298 uint32_t *mbox_sts, dma_addr_t acb_dma)
1299{
1300 int status = QLA_SUCCESS;
1301
1302 memset(mbox_cmd, 0, sizeof(mbox_cmd[0]) * MBOX_REG_COUNT);
1303 memset(mbox_sts, 0, sizeof(mbox_sts[0]) * MBOX_REG_COUNT);
1304 mbox_cmd[0] = MBOX_CMD_GET_ACB;
1305 mbox_cmd[1] = 0; /* Primary ACB */
1306 mbox_cmd[2] = LSDW(acb_dma);
1307 mbox_cmd[3] = MSDW(acb_dma);
1308 mbox_cmd[4] = sizeof(struct addr_ctrl_blk);
1309
1310 status = qla4xxx_mailbox_command(ha, 5, 5, &mbox_cmd[0], &mbox_sts[0]);
1311 if (status != QLA_SUCCESS) {
1312 DEBUG2(ql4_printk(KERN_WARNING, ha, "%s: MBOX_CMD_GET_ACB "
1313 "failed w/ status %04X\n", __func__,
1314 mbox_sts[0]));
1315 }
1316 return status;
1317}
1318
1319int qla4xxx_set_acb(struct scsi_qla_host *ha, uint32_t *mbox_cmd,
1320 uint32_t *mbox_sts, dma_addr_t acb_dma)
1321{
1322 int status = QLA_SUCCESS;
1323
1324 memset(mbox_cmd, 0, sizeof(mbox_cmd[0]) * MBOX_REG_COUNT);
1325 memset(mbox_sts, 0, sizeof(mbox_sts[0]) * MBOX_REG_COUNT);
1326 mbox_cmd[0] = MBOX_CMD_SET_ACB;
1327 mbox_cmd[1] = 0; /* Primary ACB */
1328 mbox_cmd[2] = LSDW(acb_dma);
1329 mbox_cmd[3] = MSDW(acb_dma);
1330 mbox_cmd[4] = sizeof(struct addr_ctrl_blk);
1331
1332 status = qla4xxx_mailbox_command(ha, 5, 5, &mbox_cmd[0], &mbox_sts[0]);
1333 if (status != QLA_SUCCESS) {
1334 DEBUG2(ql4_printk(KERN_WARNING, ha, "%s: MBOX_CMD_SET_ACB "
1335 "failed w/ status %04X\n", __func__,
1336 mbox_sts[0]));
1337 }
1338 return status;
1339}