blob: de733a77780342e5c4e523d34d6435f5d61c1d12 [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);
Vikas Chaudhary943c1572011-08-01 03:26:13 -0700336 ha->ip_config.eth_mtu_size =
337 le16_to_cpu(init_fw_cb->eth_mtu_size);
Vikas Chaudhary2ada7fc2011-08-01 03:26:19 -0700338 ha->ip_config.ipv4_port = le16_to_cpu(init_fw_cb->ipv4_port);
Vikas Chaudhary2bab08f2011-07-25 13:48:39 -0500339
340 if (ha->acb_version == ACB_SUPPORTED) {
341 ha->ip_config.ipv6_options = le16_to_cpu(init_fw_cb->ipv6_opts);
342 ha->ip_config.ipv6_addl_options =
343 le16_to_cpu(init_fw_cb->ipv6_addtl_opts);
344 }
345
Vikas Chaudhary2a49a782010-04-28 11:37:07 +0530346 /* Save IPv4 Address Info */
Vikas Chaudhary2bab08f2011-07-25 13:48:39 -0500347 memcpy(ha->ip_config.ip_address, init_fw_cb->ipv4_addr,
348 min(sizeof(ha->ip_config.ip_address),
349 sizeof(init_fw_cb->ipv4_addr)));
350 memcpy(ha->ip_config.subnet_mask, init_fw_cb->ipv4_subnet,
351 min(sizeof(ha->ip_config.subnet_mask),
352 sizeof(init_fw_cb->ipv4_subnet)));
353 memcpy(ha->ip_config.gateway, init_fw_cb->ipv4_gw_addr,
354 min(sizeof(ha->ip_config.gateway),
355 sizeof(init_fw_cb->ipv4_gw_addr)));
Vikas Chaudhary2a49a782010-04-28 11:37:07 +0530356
Vikas Chaudhary6ac73e82011-07-25 13:48:49 -0500357 ha->ip_config.ipv4_vlan_tag = be16_to_cpu(init_fw_cb->ipv4_vlan_tag);
358
Vikas Chaudhary2a49a782010-04-28 11:37:07 +0530359 if (is_ipv6_enabled(ha)) {
360 /* Save IPv6 Address */
Vikas Chaudhary2bab08f2011-07-25 13:48:39 -0500361 ha->ip_config.ipv6_link_local_state =
362 le16_to_cpu(init_fw_cb->ipv6_lnk_lcl_addr_state);
363 ha->ip_config.ipv6_addr0_state =
364 le16_to_cpu(init_fw_cb->ipv6_addr0_state);
365 ha->ip_config.ipv6_addr1_state =
366 le16_to_cpu(init_fw_cb->ipv6_addr1_state);
367 ha->ip_config.ipv6_default_router_state =
368 le16_to_cpu(init_fw_cb->ipv6_dflt_rtr_state);
369 ha->ip_config.ipv6_link_local_addr.in6_u.u6_addr8[0] = 0xFE;
370 ha->ip_config.ipv6_link_local_addr.in6_u.u6_addr8[1] = 0x80;
Vikas Chaudhary2a49a782010-04-28 11:37:07 +0530371
Vikas Chaudhary2bab08f2011-07-25 13:48:39 -0500372 memcpy(&ha->ip_config.ipv6_link_local_addr.in6_u.u6_addr8[8],
373 init_fw_cb->ipv6_if_id,
374 min(sizeof(ha->ip_config.ipv6_link_local_addr)/2,
375 sizeof(init_fw_cb->ipv6_if_id)));
376 memcpy(&ha->ip_config.ipv6_addr0, init_fw_cb->ipv6_addr0,
377 min(sizeof(ha->ip_config.ipv6_addr0),
378 sizeof(init_fw_cb->ipv6_addr0)));
379 memcpy(&ha->ip_config.ipv6_addr1, init_fw_cb->ipv6_addr1,
380 min(sizeof(ha->ip_config.ipv6_addr1),
381 sizeof(init_fw_cb->ipv6_addr1)));
382 memcpy(&ha->ip_config.ipv6_default_router_addr,
383 init_fw_cb->ipv6_dflt_rtr_addr,
384 min(sizeof(ha->ip_config.ipv6_default_router_addr),
385 sizeof(init_fw_cb->ipv6_dflt_rtr_addr)));
Vikas Chaudhary6ac73e82011-07-25 13:48:49 -0500386 ha->ip_config.ipv6_vlan_tag =
387 be16_to_cpu(init_fw_cb->ipv6_vlan_tag);
Vikas Chaudhary2ada7fc2011-08-01 03:26:19 -0700388 ha->ip_config.ipv6_port = le16_to_cpu(init_fw_cb->ipv6_port);
Vikas Chaudhary2a49a782010-04-28 11:37:07 +0530389 }
390}
391
Mike Christied00efe32011-07-25 13:48:38 -0500392uint8_t
Vikas Chaudhary2a49a782010-04-28 11:37:07 +0530393qla4xxx_update_local_ifcb(struct scsi_qla_host *ha,
394 uint32_t *mbox_cmd,
395 uint32_t *mbox_sts,
396 struct addr_ctrl_blk *init_fw_cb,
397 dma_addr_t init_fw_cb_dma)
398{
399 if (qla4xxx_get_ifcb(ha, mbox_cmd, mbox_sts, init_fw_cb_dma)
400 != QLA_SUCCESS) {
401 DEBUG2(printk(KERN_WARNING
402 "scsi%ld: %s: Failed to get init_fw_ctrl_blk\n",
403 ha->host_no, __func__));
404 return QLA_ERROR;
405 }
406
407 DEBUG2(qla4xxx_dump_buffer(init_fw_cb, sizeof(struct addr_ctrl_blk)));
408
409 /* Save some info in adapter structure. */
410 ha->acb_version = init_fw_cb->acb_version;
411 ha->firmware_options = le16_to_cpu(init_fw_cb->fw_options);
Vikas Chaudhary2a49a782010-04-28 11:37:07 +0530412 ha->heartbeat_interval = init_fw_cb->hb_interval;
413 memcpy(ha->name_string, init_fw_cb->iscsi_name,
414 min(sizeof(ha->name_string),
415 sizeof(init_fw_cb->iscsi_name)));
416 /*memcpy(ha->alias, init_fw_cb->Alias,
417 min(sizeof(ha->alias), sizeof(init_fw_cb->Alias)));*/
418
Vikas Chaudhary2a49a782010-04-28 11:37:07 +0530419 qla4xxx_update_local_ip(ha, init_fw_cb);
420
421 return QLA_SUCCESS;
422}
423
David Somayajuluafaf5a22006-09-19 10:28:00 -0700424/**
425 * qla4xxx_initialize_fw_cb - initializes firmware control block.
426 * @ha: Pointer to host adapter structure.
427 **/
428int qla4xxx_initialize_fw_cb(struct scsi_qla_host * ha)
429{
Vikas Chaudhary2a49a782010-04-28 11:37:07 +0530430 struct addr_ctrl_blk *init_fw_cb;
David Somayajuluafaf5a22006-09-19 10:28:00 -0700431 dma_addr_t init_fw_cb_dma;
432 uint32_t mbox_cmd[MBOX_REG_COUNT];
433 uint32_t mbox_sts[MBOX_REG_COUNT];
434 int status = QLA_ERROR;
435
436 init_fw_cb = dma_alloc_coherent(&ha->pdev->dev,
Vikas Chaudhary2a49a782010-04-28 11:37:07 +0530437 sizeof(struct addr_ctrl_blk),
David Somayajuluafaf5a22006-09-19 10:28:00 -0700438 &init_fw_cb_dma, GFP_KERNEL);
439 if (init_fw_cb == NULL) {
440 DEBUG2(printk("scsi%ld: %s: Unable to alloc init_cb\n",
441 ha->host_no, __func__));
Prasanna Mumbaibeabe7c2010-07-10 14:49:38 +0530442 goto exit_init_fw_cb_no_free;
David Somayajuluafaf5a22006-09-19 10:28:00 -0700443 }
Vikas Chaudhary2a49a782010-04-28 11:37:07 +0530444 memset(init_fw_cb, 0, sizeof(struct addr_ctrl_blk));
David Somayajuluafaf5a22006-09-19 10:28:00 -0700445
446 /* Get Initialize Firmware Control Block. */
447 memset(&mbox_cmd, 0, sizeof(mbox_cmd));
448 memset(&mbox_sts, 0, sizeof(mbox_sts));
David C Somayajuluc0e344c2007-05-23 18:03:27 -0700449
Vikas Chaudhary2a49a782010-04-28 11:37:07 +0530450 if (qla4xxx_get_ifcb(ha, &mbox_cmd[0], &mbox_sts[0], init_fw_cb_dma) !=
David Somayajuluafaf5a22006-09-19 10:28:00 -0700451 QLA_SUCCESS) {
452 dma_free_coherent(&ha->pdev->dev,
Vikas Chaudhary2a49a782010-04-28 11:37:07 +0530453 sizeof(struct addr_ctrl_blk),
David Somayajuluafaf5a22006-09-19 10:28:00 -0700454 init_fw_cb, init_fw_cb_dma);
Vikas Chaudhary2a49a782010-04-28 11:37:07 +0530455 goto exit_init_fw_cb;
David Somayajuluafaf5a22006-09-19 10:28:00 -0700456 }
457
458 /* Initialize request and response queues. */
459 qla4xxx_init_rings(ha);
460
461 /* Fill in the request and response queue information. */
Vikas Chaudhary2a49a782010-04-28 11:37:07 +0530462 init_fw_cb->rqq_consumer_idx = cpu_to_le16(ha->request_out);
463 init_fw_cb->compq_producer_idx = cpu_to_le16(ha->response_in);
464 init_fw_cb->rqq_len = __constant_cpu_to_le16(REQUEST_QUEUE_DEPTH);
465 init_fw_cb->compq_len = __constant_cpu_to_le16(RESPONSE_QUEUE_DEPTH);
466 init_fw_cb->rqq_addr_lo = cpu_to_le32(LSDW(ha->request_dma));
467 init_fw_cb->rqq_addr_hi = cpu_to_le32(MSDW(ha->request_dma));
468 init_fw_cb->compq_addr_lo = cpu_to_le32(LSDW(ha->response_dma));
469 init_fw_cb->compq_addr_hi = cpu_to_le32(MSDW(ha->response_dma));
470 init_fw_cb->shdwreg_addr_lo = cpu_to_le32(LSDW(ha->shadow_regs_dma));
471 init_fw_cb->shdwreg_addr_hi = cpu_to_le32(MSDW(ha->shadow_regs_dma));
David Somayajuluafaf5a22006-09-19 10:28:00 -0700472
473 /* Set up required options. */
Vikas Chaudhary2a49a782010-04-28 11:37:07 +0530474 init_fw_cb->fw_options |=
David Somayajuluafaf5a22006-09-19 10:28:00 -0700475 __constant_cpu_to_le16(FWOPT_SESSION_MODE |
476 FWOPT_INITIATOR_MODE);
Shyam Sundar2657c802010-10-06 22:50:29 -0700477
478 if (is_qla8022(ha))
479 init_fw_cb->fw_options |=
480 __constant_cpu_to_le16(FWOPT_ENABLE_CRBDB);
481
Vikas Chaudhary2a49a782010-04-28 11:37:07 +0530482 init_fw_cb->fw_options &= __constant_cpu_to_le16(~FWOPT_TARGET_MODE);
David Somayajuluafaf5a22006-09-19 10:28:00 -0700483
Prasanna Mumbaid32cee32011-03-21 03:34:35 -0700484 init_fw_cb->add_fw_options = 0;
485 init_fw_cb->add_fw_options |=
Manish Rangankarb3a271a2011-07-25 13:48:53 -0500486 __constant_cpu_to_le16(ADFWOPT_SERIALIZE_TASK_MGMT);
487 init_fw_cb->add_fw_options |=
488 __constant_cpu_to_le16(ADFWOPT_AUTOCONN_DISABLE);
Prasanna Mumbaid32cee32011-03-21 03:34:35 -0700489
Vikas Chaudhary2a49a782010-04-28 11:37:07 +0530490 if (qla4xxx_set_ifcb(ha, &mbox_cmd[0], &mbox_sts[0], init_fw_cb_dma)
491 != QLA_SUCCESS) {
492 DEBUG2(printk(KERN_WARNING
493 "scsi%ld: %s: Failed to set init_fw_ctrl_blk\n",
494 ha->host_no, __func__));
495 goto exit_init_fw_cb;
David Somayajuluafaf5a22006-09-19 10:28:00 -0700496 }
Vikas Chaudhary2a49a782010-04-28 11:37:07 +0530497
498 if (qla4xxx_update_local_ifcb(ha, &mbox_cmd[0], &mbox_sts[0],
499 init_fw_cb, init_fw_cb_dma) != QLA_SUCCESS) {
500 DEBUG2(printk("scsi%ld: %s: Failed to update local ifcb\n",
501 ha->host_no, __func__));
502 goto exit_init_fw_cb;
503 }
504 status = QLA_SUCCESS;
505
506exit_init_fw_cb:
507 dma_free_coherent(&ha->pdev->dev, sizeof(struct addr_ctrl_blk),
508 init_fw_cb, init_fw_cb_dma);
Prasanna Mumbaibeabe7c2010-07-10 14:49:38 +0530509exit_init_fw_cb_no_free:
David Somayajuluafaf5a22006-09-19 10:28:00 -0700510 return status;
511}
512
513/**
514 * qla4xxx_get_dhcp_ip_address - gets HBA ip address via DHCP
515 * @ha: Pointer to host adapter structure.
516 **/
517int qla4xxx_get_dhcp_ip_address(struct scsi_qla_host * ha)
518{
Vikas Chaudhary2a49a782010-04-28 11:37:07 +0530519 struct addr_ctrl_blk *init_fw_cb;
David Somayajuluafaf5a22006-09-19 10:28:00 -0700520 dma_addr_t init_fw_cb_dma;
521 uint32_t mbox_cmd[MBOX_REG_COUNT];
522 uint32_t mbox_sts[MBOX_REG_COUNT];
523
524 init_fw_cb = dma_alloc_coherent(&ha->pdev->dev,
Vikas Chaudhary2a49a782010-04-28 11:37:07 +0530525 sizeof(struct addr_ctrl_blk),
David Somayajuluafaf5a22006-09-19 10:28:00 -0700526 &init_fw_cb_dma, GFP_KERNEL);
527 if (init_fw_cb == NULL) {
528 printk("scsi%ld: %s: Unable to alloc init_cb\n", ha->host_no,
529 __func__);
Prasanna Mumbaibeabe7c2010-07-10 14:49:38 +0530530 return QLA_ERROR;
David Somayajuluafaf5a22006-09-19 10:28:00 -0700531 }
532
533 /* Get Initialize Firmware Control Block. */
Vikas Chaudhary2a49a782010-04-28 11:37:07 +0530534 memset(init_fw_cb, 0, sizeof(struct addr_ctrl_blk));
535 if (qla4xxx_get_ifcb(ha, &mbox_cmd[0], &mbox_sts[0], init_fw_cb_dma) !=
David Somayajuluafaf5a22006-09-19 10:28:00 -0700536 QLA_SUCCESS) {
537 DEBUG2(printk("scsi%ld: %s: Failed to get init_fw_ctrl_blk\n",
538 ha->host_no, __func__));
539 dma_free_coherent(&ha->pdev->dev,
Vikas Chaudhary2a49a782010-04-28 11:37:07 +0530540 sizeof(struct addr_ctrl_blk),
David Somayajuluafaf5a22006-09-19 10:28:00 -0700541 init_fw_cb, init_fw_cb_dma);
542 return QLA_ERROR;
543 }
544
545 /* Save IP Address. */
Vikas Chaudhary2a49a782010-04-28 11:37:07 +0530546 qla4xxx_update_local_ip(ha, init_fw_cb);
547 dma_free_coherent(&ha->pdev->dev, sizeof(struct addr_ctrl_blk),
548 init_fw_cb, init_fw_cb_dma);
David Somayajuluafaf5a22006-09-19 10:28:00 -0700549
550 return QLA_SUCCESS;
551}
552
553/**
554 * qla4xxx_get_firmware_state - gets firmware state of HBA
555 * @ha: Pointer to host adapter structure.
556 **/
557int qla4xxx_get_firmware_state(struct scsi_qla_host * ha)
558{
559 uint32_t mbox_cmd[MBOX_REG_COUNT];
560 uint32_t mbox_sts[MBOX_REG_COUNT];
561
562 /* Get firmware version */
563 memset(&mbox_cmd, 0, sizeof(mbox_cmd));
564 memset(&mbox_sts, 0, sizeof(mbox_sts));
David C Somayajuluc0e344c2007-05-23 18:03:27 -0700565
David Somayajuluafaf5a22006-09-19 10:28:00 -0700566 mbox_cmd[0] = MBOX_CMD_GET_FW_STATE;
David C Somayajuluc0e344c2007-05-23 18:03:27 -0700567
568 if (qla4xxx_mailbox_command(ha, MBOX_REG_COUNT, 4, &mbox_cmd[0], &mbox_sts[0]) !=
David Somayajuluafaf5a22006-09-19 10:28:00 -0700569 QLA_SUCCESS) {
570 DEBUG2(printk("scsi%ld: %s: MBOX_CMD_GET_FW_STATE failed w/ "
571 "status %04X\n", ha->host_no, __func__,
572 mbox_sts[0]));
573 return QLA_ERROR;
574 }
575 ha->firmware_state = mbox_sts[1];
576 ha->board_id = mbox_sts[2];
577 ha->addl_fw_state = mbox_sts[3];
578 DEBUG2(printk("scsi%ld: %s firmware_state=0x%x\n",
579 ha->host_no, __func__, ha->firmware_state);)
580
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +0530581 return QLA_SUCCESS;
David Somayajuluafaf5a22006-09-19 10:28:00 -0700582}
583
584/**
585 * qla4xxx_get_firmware_status - retrieves firmware status
586 * @ha: Pointer to host adapter structure.
587 **/
588int qla4xxx_get_firmware_status(struct scsi_qla_host * ha)
589{
590 uint32_t mbox_cmd[MBOX_REG_COUNT];
591 uint32_t mbox_sts[MBOX_REG_COUNT];
592
593 /* Get firmware version */
594 memset(&mbox_cmd, 0, sizeof(mbox_cmd));
595 memset(&mbox_sts, 0, sizeof(mbox_sts));
David C Somayajuluc0e344c2007-05-23 18:03:27 -0700596
David Somayajuluafaf5a22006-09-19 10:28:00 -0700597 mbox_cmd[0] = MBOX_CMD_GET_FW_STATUS;
David C Somayajuluc0e344c2007-05-23 18:03:27 -0700598
599 if (qla4xxx_mailbox_command(ha, MBOX_REG_COUNT, 3, &mbox_cmd[0], &mbox_sts[0]) !=
David Somayajuluafaf5a22006-09-19 10:28:00 -0700600 QLA_SUCCESS) {
601 DEBUG2(printk("scsi%ld: %s: MBOX_CMD_GET_FW_STATUS failed w/ "
602 "status %04X\n", ha->host_no, __func__,
603 mbox_sts[0]));
604 return QLA_ERROR;
605 }
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +0530606
607 ql4_printk(KERN_INFO, ha, "%ld firmare IOCBs available (%d).\n",
Vikas Chaudharyf581a3f2010-10-06 22:47:48 -0700608 ha->host_no, mbox_sts[2]);
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +0530609
David Somayajuluafaf5a22006-09-19 10:28:00 -0700610 return QLA_SUCCESS;
611}
612
613/**
614 * qla4xxx_get_fwddb_entry - retrieves firmware ddb entry
615 * @ha: Pointer to host adapter structure.
616 * @fw_ddb_index: Firmware's device database index
617 * @fw_ddb_entry: Pointer to firmware's device database entry structure
618 * @num_valid_ddb_entries: Pointer to number of valid ddb entries
619 * @next_ddb_index: Pointer to next valid device database index
620 * @fw_ddb_device_state: Pointer to device state
621 **/
622int qla4xxx_get_fwddb_entry(struct scsi_qla_host *ha,
623 uint16_t fw_ddb_index,
624 struct dev_db_entry *fw_ddb_entry,
625 dma_addr_t fw_ddb_entry_dma,
626 uint32_t *num_valid_ddb_entries,
627 uint32_t *next_ddb_index,
628 uint32_t *fw_ddb_device_state,
629 uint32_t *conn_err_detail,
630 uint16_t *tcp_source_port_num,
631 uint16_t *connection_id)
632{
633 int status = QLA_ERROR;
Vikas Chaudhary2a49a782010-04-28 11:37:07 +0530634 uint16_t options;
David Somayajuluafaf5a22006-09-19 10:28:00 -0700635 uint32_t mbox_cmd[MBOX_REG_COUNT];
636 uint32_t mbox_sts[MBOX_REG_COUNT];
637
638 /* Make sure the device index is valid */
639 if (fw_ddb_index >= MAX_DDB_ENTRIES) {
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +0530640 DEBUG2(printk("scsi%ld: %s: ddb [%d] out of range.\n",
David Somayajuluafaf5a22006-09-19 10:28:00 -0700641 ha->host_no, __func__, fw_ddb_index));
642 goto exit_get_fwddb;
643 }
644 memset(&mbox_cmd, 0, sizeof(mbox_cmd));
645 memset(&mbox_sts, 0, sizeof(mbox_sts));
David C Somayajuluc0e344c2007-05-23 18:03:27 -0700646
David Somayajuluafaf5a22006-09-19 10:28:00 -0700647 mbox_cmd[0] = MBOX_CMD_GET_DATABASE_ENTRY;
648 mbox_cmd[1] = (uint32_t) fw_ddb_index;
649 mbox_cmd[2] = LSDW(fw_ddb_entry_dma);
650 mbox_cmd[3] = MSDW(fw_ddb_entry_dma);
David C Somayajuluc0e344c2007-05-23 18:03:27 -0700651 mbox_cmd[4] = sizeof(struct dev_db_entry);
652
653 if (qla4xxx_mailbox_command(ha, MBOX_REG_COUNT, 7, &mbox_cmd[0], &mbox_sts[0]) ==
David Somayajuluafaf5a22006-09-19 10:28:00 -0700654 QLA_ERROR) {
655 DEBUG2(printk("scsi%ld: %s: MBOX_CMD_GET_DATABASE_ENTRY failed"
656 " with status 0x%04X\n", ha->host_no, __func__,
657 mbox_sts[0]));
658 goto exit_get_fwddb;
659 }
660 if (fw_ddb_index != mbox_sts[1]) {
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +0530661 DEBUG2(printk("scsi%ld: %s: ddb mismatch [%d] != [%d].\n",
David Somayajuluafaf5a22006-09-19 10:28:00 -0700662 ha->host_no, __func__, fw_ddb_index,
663 mbox_sts[1]));
664 goto exit_get_fwddb;
665 }
666 if (fw_ddb_entry) {
Vikas Chaudhary2a49a782010-04-28 11:37:07 +0530667 options = le16_to_cpu(fw_ddb_entry->options);
668 if (options & DDB_OPT_IPV6_DEVICE) {
Vikas Chaudharyc2660df2010-07-10 14:51:02 +0530669 ql4_printk(KERN_INFO, ha, "%s: DDB[%d] MB0 %04x Tot %d "
Vikas Chaudhary2a49a782010-04-28 11:37:07 +0530670 "Next %d State %04x ConnErr %08x %pI6 "
671 ":%04d \"%s\"\n", __func__, fw_ddb_index,
672 mbox_sts[0], mbox_sts[2], mbox_sts[3],
673 mbox_sts[4], mbox_sts[5],
674 fw_ddb_entry->ip_addr,
675 le16_to_cpu(fw_ddb_entry->port),
676 fw_ddb_entry->iscsi_name);
677 } else {
Vikas Chaudharyc2660df2010-07-10 14:51:02 +0530678 ql4_printk(KERN_INFO, ha, "%s: DDB[%d] MB0 %04x Tot %d "
Vikas Chaudhary2a49a782010-04-28 11:37:07 +0530679 "Next %d State %04x ConnErr %08x %pI4 "
680 ":%04d \"%s\"\n", __func__, fw_ddb_index,
681 mbox_sts[0], mbox_sts[2], mbox_sts[3],
682 mbox_sts[4], mbox_sts[5],
683 fw_ddb_entry->ip_addr,
684 le16_to_cpu(fw_ddb_entry->port),
685 fw_ddb_entry->iscsi_name);
686 }
David Somayajuluafaf5a22006-09-19 10:28:00 -0700687 }
688 if (num_valid_ddb_entries)
689 *num_valid_ddb_entries = mbox_sts[2];
690 if (next_ddb_index)
691 *next_ddb_index = mbox_sts[3];
692 if (fw_ddb_device_state)
693 *fw_ddb_device_state = mbox_sts[4];
694
695 /*
696 * RA: This mailbox has been changed to pass connection error and
697 * details. Its true for ISP4010 as per Version E - Not sure when it
698 * was changed. Get the time2wait from the fw_dd_entry field :
699 * default_time2wait which we call it as minTime2Wait DEV_DB_ENTRY
700 * struct.
701 */
702 if (conn_err_detail)
703 *conn_err_detail = mbox_sts[5];
704 if (tcp_source_port_num)
Randy Dunlap14823382010-04-22 11:02:14 -0700705 *tcp_source_port_num = (uint16_t) (mbox_sts[6] >> 16);
David Somayajuluafaf5a22006-09-19 10:28:00 -0700706 if (connection_id)
707 *connection_id = (uint16_t) mbox_sts[6] & 0x00FF;
708 status = QLA_SUCCESS;
709
710exit_get_fwddb:
711 return status;
712}
713
Manish Rangankarb3a271a2011-07-25 13:48:53 -0500714int qla4xxx_conn_open(struct scsi_qla_host *ha, uint16_t fw_ddb_index)
715{
716 uint32_t mbox_cmd[MBOX_REG_COUNT];
717 uint32_t mbox_sts[MBOX_REG_COUNT];
718 int status;
719
720 memset(&mbox_cmd, 0, sizeof(mbox_cmd));
721 memset(&mbox_sts, 0, sizeof(mbox_sts));
722
723 mbox_cmd[0] = MBOX_CMD_CONN_OPEN;
724 mbox_cmd[1] = fw_ddb_index;
725
726 status = qla4xxx_mailbox_command(ha, MBOX_REG_COUNT, 2, &mbox_cmd[0],
727 &mbox_sts[0]);
728 DEBUG2(ql4_printk(KERN_INFO, ha,
729 "%s: status = %d mbx0 = 0x%x mbx1 = 0x%x\n",
730 __func__, status, mbox_sts[0], mbox_sts[1]));
731 return status;
732}
733
David Somayajuluafaf5a22006-09-19 10:28:00 -0700734/**
735 * qla4xxx_set_fwddb_entry - sets a ddb entry.
736 * @ha: Pointer to host adapter structure.
737 * @fw_ddb_index: Firmware's device database index
Manish Rangankarb3a271a2011-07-25 13:48:53 -0500738 * @fw_ddb_entry_dma: dma address of ddb entry
739 * @mbx_sts: mailbox 0 to be returned or NULL
David Somayajuluafaf5a22006-09-19 10:28:00 -0700740 *
741 * This routine initializes or updates the adapter's device database
Manish Rangankarb3a271a2011-07-25 13:48:53 -0500742 * entry for the specified device.
David Somayajuluafaf5a22006-09-19 10:28:00 -0700743 **/
744int qla4xxx_set_ddb_entry(struct scsi_qla_host * ha, uint16_t fw_ddb_index,
Manish Rangankarb3a271a2011-07-25 13:48:53 -0500745 dma_addr_t fw_ddb_entry_dma, uint32_t *mbx_sts)
David Somayajuluafaf5a22006-09-19 10:28:00 -0700746{
747 uint32_t mbox_cmd[MBOX_REG_COUNT];
748 uint32_t mbox_sts[MBOX_REG_COUNT];
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +0530749 int status;
David Somayajuluafaf5a22006-09-19 10:28:00 -0700750
751 /* Do not wait for completion. The firmware will send us an
752 * ASTS_DATABASE_CHANGED (0x8014) to notify us of the login status.
753 */
754 memset(&mbox_cmd, 0, sizeof(mbox_cmd));
755 memset(&mbox_sts, 0, sizeof(mbox_sts));
756
757 mbox_cmd[0] = MBOX_CMD_SET_DATABASE_ENTRY;
758 mbox_cmd[1] = (uint32_t) fw_ddb_index;
759 mbox_cmd[2] = LSDW(fw_ddb_entry_dma);
760 mbox_cmd[3] = MSDW(fw_ddb_entry_dma);
David C Somayajuluc0e344c2007-05-23 18:03:27 -0700761 mbox_cmd[4] = sizeof(struct dev_db_entry);
762
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +0530763 status = qla4xxx_mailbox_command(ha, MBOX_REG_COUNT, 5, &mbox_cmd[0],
Manish Rangankarb3a271a2011-07-25 13:48:53 -0500764 &mbox_sts[0]);
765 if (mbx_sts)
766 *mbx_sts = mbox_sts[0];
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +0530767 DEBUG2(printk("scsi%ld: %s: status=%d mbx0=0x%x mbx4=0x%x\n",
768 ha->host_no, __func__, status, mbox_sts[0], mbox_sts[4]);)
769
770 return status;
David Somayajuluafaf5a22006-09-19 10:28:00 -0700771}
772
Manish Rangankarb3a271a2011-07-25 13:48:53 -0500773int qla4xxx_session_logout_ddb(struct scsi_qla_host *ha,
774 struct ddb_entry *ddb_entry, int options)
775{
776 int status;
777 uint32_t mbox_cmd[MBOX_REG_COUNT];
778 uint32_t mbox_sts[MBOX_REG_COUNT];
779
780 memset(&mbox_cmd, 0, sizeof(mbox_cmd));
781 memset(&mbox_sts, 0, sizeof(mbox_sts));
782
783 mbox_cmd[0] = MBOX_CMD_CONN_CLOSE_SESS_LOGOUT;
784 mbox_cmd[1] = ddb_entry->fw_ddb_index;
785 mbox_cmd[3] = options;
786
787 status = qla4xxx_mailbox_command(ha, MBOX_REG_COUNT, 2, &mbox_cmd[0],
788 &mbox_sts[0]);
789 if (status != QLA_SUCCESS) {
790 DEBUG2(ql4_printk(KERN_INFO, ha,
791 "%s: MBOX_CMD_CONN_CLOSE_SESS_LOGOUT "
792 "failed sts %04X %04X", __func__,
793 mbox_sts[0], mbox_sts[1]));
794 }
795
796 return status;
797}
798
David Somayajuluafaf5a22006-09-19 10:28:00 -0700799/**
800 * qla4xxx_get_crash_record - retrieves crash record.
801 * @ha: Pointer to host adapter structure.
802 *
803 * This routine retrieves a crash record from the QLA4010 after an 8002h aen.
804 **/
805void qla4xxx_get_crash_record(struct scsi_qla_host * ha)
806{
807 uint32_t mbox_cmd[MBOX_REG_COUNT];
808 uint32_t mbox_sts[MBOX_REG_COUNT];
809 struct crash_record *crash_record = NULL;
810 dma_addr_t crash_record_dma = 0;
811 uint32_t crash_record_size = 0;
David C Somayajuluc0e344c2007-05-23 18:03:27 -0700812
David Somayajuluafaf5a22006-09-19 10:28:00 -0700813 memset(&mbox_cmd, 0, sizeof(mbox_cmd));
814 memset(&mbox_sts, 0, sizeof(mbox_cmd));
815
816 /* Get size of crash record. */
817 mbox_cmd[0] = MBOX_CMD_GET_CRASH_RECORD;
David C Somayajuluc0e344c2007-05-23 18:03:27 -0700818
819 if (qla4xxx_mailbox_command(ha, MBOX_REG_COUNT, 5, &mbox_cmd[0], &mbox_sts[0]) !=
David Somayajuluafaf5a22006-09-19 10:28:00 -0700820 QLA_SUCCESS) {
821 DEBUG2(printk("scsi%ld: %s: ERROR: Unable to retrieve size!\n",
822 ha->host_no, __func__));
823 goto exit_get_crash_record;
824 }
825 crash_record_size = mbox_sts[4];
826 if (crash_record_size == 0) {
827 DEBUG2(printk("scsi%ld: %s: ERROR: Crash record size is 0!\n",
828 ha->host_no, __func__));
829 goto exit_get_crash_record;
830 }
831
832 /* Alloc Memory for Crash Record. */
833 crash_record = dma_alloc_coherent(&ha->pdev->dev, crash_record_size,
834 &crash_record_dma, GFP_KERNEL);
835 if (crash_record == NULL)
836 goto exit_get_crash_record;
837
838 /* Get Crash Record. */
David C Somayajuluc0e344c2007-05-23 18:03:27 -0700839 memset(&mbox_cmd, 0, sizeof(mbox_cmd));
840 memset(&mbox_sts, 0, sizeof(mbox_cmd));
841
David Somayajuluafaf5a22006-09-19 10:28:00 -0700842 mbox_cmd[0] = MBOX_CMD_GET_CRASH_RECORD;
843 mbox_cmd[2] = LSDW(crash_record_dma);
844 mbox_cmd[3] = MSDW(crash_record_dma);
845 mbox_cmd[4] = crash_record_size;
David C Somayajuluc0e344c2007-05-23 18:03:27 -0700846
847 if (qla4xxx_mailbox_command(ha, MBOX_REG_COUNT, 5, &mbox_cmd[0], &mbox_sts[0]) !=
David Somayajuluafaf5a22006-09-19 10:28:00 -0700848 QLA_SUCCESS)
849 goto exit_get_crash_record;
850
851 /* Dump Crash Record. */
852
853exit_get_crash_record:
854 if (crash_record)
855 dma_free_coherent(&ha->pdev->dev, crash_record_size,
856 crash_record, crash_record_dma);
857}
858
859/**
860 * qla4xxx_get_conn_event_log - retrieves connection event log
861 * @ha: Pointer to host adapter structure.
862 **/
863void qla4xxx_get_conn_event_log(struct scsi_qla_host * ha)
864{
865 uint32_t mbox_cmd[MBOX_REG_COUNT];
866 uint32_t mbox_sts[MBOX_REG_COUNT];
867 struct conn_event_log_entry *event_log = NULL;
868 dma_addr_t event_log_dma = 0;
869 uint32_t event_log_size = 0;
870 uint32_t num_valid_entries;
871 uint32_t oldest_entry = 0;
872 uint32_t max_event_log_entries;
873 uint8_t i;
874
875
876 memset(&mbox_cmd, 0, sizeof(mbox_cmd));
877 memset(&mbox_sts, 0, sizeof(mbox_cmd));
878
879 /* Get size of crash record. */
880 mbox_cmd[0] = MBOX_CMD_GET_CONN_EVENT_LOG;
David C Somayajuluc0e344c2007-05-23 18:03:27 -0700881
882 if (qla4xxx_mailbox_command(ha, MBOX_REG_COUNT, 5, &mbox_cmd[0], &mbox_sts[0]) !=
David Somayajuluafaf5a22006-09-19 10:28:00 -0700883 QLA_SUCCESS)
884 goto exit_get_event_log;
885
886 event_log_size = mbox_sts[4];
887 if (event_log_size == 0)
888 goto exit_get_event_log;
889
890 /* Alloc Memory for Crash Record. */
891 event_log = dma_alloc_coherent(&ha->pdev->dev, event_log_size,
892 &event_log_dma, GFP_KERNEL);
893 if (event_log == NULL)
894 goto exit_get_event_log;
895
896 /* Get Crash Record. */
David C Somayajuluc0e344c2007-05-23 18:03:27 -0700897 memset(&mbox_cmd, 0, sizeof(mbox_cmd));
898 memset(&mbox_sts, 0, sizeof(mbox_cmd));
899
David Somayajuluafaf5a22006-09-19 10:28:00 -0700900 mbox_cmd[0] = MBOX_CMD_GET_CONN_EVENT_LOG;
901 mbox_cmd[2] = LSDW(event_log_dma);
902 mbox_cmd[3] = MSDW(event_log_dma);
David C Somayajuluc0e344c2007-05-23 18:03:27 -0700903
904 if (qla4xxx_mailbox_command(ha, MBOX_REG_COUNT, 5, &mbox_cmd[0], &mbox_sts[0]) !=
David Somayajuluafaf5a22006-09-19 10:28:00 -0700905 QLA_SUCCESS) {
906 DEBUG2(printk("scsi%ld: %s: ERROR: Unable to retrieve event "
907 "log!\n", ha->host_no, __func__));
908 goto exit_get_event_log;
909 }
910
911 /* Dump Event Log. */
912 num_valid_entries = mbox_sts[1];
913
914 max_event_log_entries = event_log_size /
915 sizeof(struct conn_event_log_entry);
916
917 if (num_valid_entries > max_event_log_entries)
918 oldest_entry = num_valid_entries % max_event_log_entries;
919
920 DEBUG3(printk("scsi%ld: Connection Event Log Dump (%d entries):\n",
921 ha->host_no, num_valid_entries));
922
Andrew Vasquez11010fe2006-10-06 09:54:59 -0700923 if (ql4xextended_error_logging == 3) {
David Somayajuluafaf5a22006-09-19 10:28:00 -0700924 if (oldest_entry == 0) {
925 /* Circular Buffer has not wrapped around */
926 for (i=0; i < num_valid_entries; i++) {
927 qla4xxx_dump_buffer((uint8_t *)event_log+
928 (i*sizeof(*event_log)),
929 sizeof(*event_log));
930 }
931 }
932 else {
933 /* Circular Buffer has wrapped around -
934 * display accordingly*/
935 for (i=oldest_entry; i < max_event_log_entries; i++) {
936 qla4xxx_dump_buffer((uint8_t *)event_log+
937 (i*sizeof(*event_log)),
938 sizeof(*event_log));
939 }
940 for (i=0; i < oldest_entry; i++) {
941 qla4xxx_dump_buffer((uint8_t *)event_log+
942 (i*sizeof(*event_log)),
943 sizeof(*event_log));
944 }
945 }
946 }
947
948exit_get_event_log:
949 if (event_log)
950 dma_free_coherent(&ha->pdev->dev, event_log_size, event_log,
951 event_log_dma);
952}
953
954/**
Vikas Chaudhary09a0f712010-04-28 11:42:24 +0530955 * qla4xxx_abort_task - issues Abort Task
956 * @ha: Pointer to host adapter structure.
957 * @srb: Pointer to srb entry
958 *
959 * This routine performs a LUN RESET on the specified target/lun.
960 * The caller must ensure that the ddb_entry and lun_entry pointers
961 * are valid before calling this routine.
962 **/
963int qla4xxx_abort_task(struct scsi_qla_host *ha, struct srb *srb)
964{
965 uint32_t mbox_cmd[MBOX_REG_COUNT];
966 uint32_t mbox_sts[MBOX_REG_COUNT];
967 struct scsi_cmnd *cmd = srb->cmd;
968 int status = QLA_SUCCESS;
969 unsigned long flags = 0;
970 uint32_t index;
971
972 /*
973 * Send abort task command to ISP, so that the ISP will return
974 * request with ABORT status
975 */
976 memset(&mbox_cmd, 0, sizeof(mbox_cmd));
977 memset(&mbox_sts, 0, sizeof(mbox_sts));
978
979 spin_lock_irqsave(&ha->hardware_lock, flags);
980 index = (unsigned long)(unsigned char *)cmd->host_scribble;
981 spin_unlock_irqrestore(&ha->hardware_lock, flags);
982
983 /* Firmware already posted completion on response queue */
984 if (index == MAX_SRBS)
985 return status;
986
987 mbox_cmd[0] = MBOX_CMD_ABORT_TASK;
Karen Higgins6790d4f2010-12-02 22:12:22 -0800988 mbox_cmd[1] = srb->ddb->fw_ddb_index;
Vikas Chaudhary09a0f712010-04-28 11:42:24 +0530989 mbox_cmd[2] = index;
990 /* Immediate Command Enable */
991 mbox_cmd[5] = 0x01;
992
993 qla4xxx_mailbox_command(ha, MBOX_REG_COUNT, 5, &mbox_cmd[0],
994 &mbox_sts[0]);
995 if (mbox_sts[0] != MBOX_STS_COMMAND_COMPLETE) {
996 status = QLA_ERROR;
997
998 DEBUG2(printk(KERN_WARNING "scsi%ld:%d:%d: abort task FAILED: "
999 "mbx0=%04X, mb1=%04X, mb2=%04X, mb3=%04X, mb4=%04X\n",
1000 ha->host_no, cmd->device->id, cmd->device->lun, mbox_sts[0],
1001 mbox_sts[1], mbox_sts[2], mbox_sts[3], mbox_sts[4]));
1002 }
1003
1004 return status;
1005}
1006
1007/**
David Somayajuluafaf5a22006-09-19 10:28:00 -07001008 * qla4xxx_reset_lun - issues LUN Reset
1009 * @ha: Pointer to host adapter structure.
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05301010 * @ddb_entry: Pointer to device database entry
1011 * @lun: lun number
David Somayajuluafaf5a22006-09-19 10:28:00 -07001012 *
1013 * This routine performs a LUN RESET on the specified target/lun.
1014 * The caller must ensure that the ddb_entry and lun_entry pointers
1015 * are valid before calling this routine.
1016 **/
1017int qla4xxx_reset_lun(struct scsi_qla_host * ha, struct ddb_entry * ddb_entry,
1018 int lun)
1019{
1020 uint32_t mbox_cmd[MBOX_REG_COUNT];
1021 uint32_t mbox_sts[MBOX_REG_COUNT];
1022 int status = QLA_SUCCESS;
1023
1024 DEBUG2(printk("scsi%ld:%d:%d: lun reset issued\n", ha->host_no,
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05301025 ddb_entry->fw_ddb_index, lun));
David Somayajuluafaf5a22006-09-19 10:28:00 -07001026
1027 /*
1028 * Send lun reset command to ISP, so that the ISP will return all
1029 * outstanding requests with RESET status
1030 */
1031 memset(&mbox_cmd, 0, sizeof(mbox_cmd));
1032 memset(&mbox_sts, 0, sizeof(mbox_sts));
David C Somayajuluc0e344c2007-05-23 18:03:27 -07001033
David Somayajuluafaf5a22006-09-19 10:28:00 -07001034 mbox_cmd[0] = MBOX_CMD_LUN_RESET;
1035 mbox_cmd[1] = ddb_entry->fw_ddb_index;
1036 mbox_cmd[2] = lun << 8;
1037 mbox_cmd[5] = 0x01; /* Immediate Command Enable */
David C Somayajuluc0e344c2007-05-23 18:03:27 -07001038
1039 qla4xxx_mailbox_command(ha, MBOX_REG_COUNT, 1, &mbox_cmd[0], &mbox_sts[0]);
David Somayajuluafaf5a22006-09-19 10:28:00 -07001040 if (mbox_sts[0] != MBOX_STS_COMMAND_COMPLETE &&
1041 mbox_sts[0] != MBOX_STS_COMMAND_ERROR)
1042 status = QLA_ERROR;
1043
1044 return status;
1045}
1046
Mike Christiece545032008-02-29 18:25:20 -06001047/**
1048 * qla4xxx_reset_target - issues target Reset
1049 * @ha: Pointer to host adapter structure.
1050 * @db_entry: Pointer to device database entry
1051 * @un_entry: Pointer to lun entry structure
1052 *
1053 * This routine performs a TARGET RESET on the specified target.
1054 * The caller must ensure that the ddb_entry pointers
1055 * are valid before calling this routine.
1056 **/
1057int qla4xxx_reset_target(struct scsi_qla_host *ha,
1058 struct ddb_entry *ddb_entry)
1059{
1060 uint32_t mbox_cmd[MBOX_REG_COUNT];
1061 uint32_t mbox_sts[MBOX_REG_COUNT];
1062 int status = QLA_SUCCESS;
1063
1064 DEBUG2(printk("scsi%ld:%d: target reset issued\n", ha->host_no,
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05301065 ddb_entry->fw_ddb_index));
Mike Christiece545032008-02-29 18:25:20 -06001066
1067 /*
1068 * Send target reset command to ISP, so that the ISP will return all
1069 * outstanding requests with RESET status
1070 */
1071 memset(&mbox_cmd, 0, sizeof(mbox_cmd));
1072 memset(&mbox_sts, 0, sizeof(mbox_sts));
1073
1074 mbox_cmd[0] = MBOX_CMD_TARGET_WARM_RESET;
1075 mbox_cmd[1] = ddb_entry->fw_ddb_index;
1076 mbox_cmd[5] = 0x01; /* Immediate Command Enable */
1077
1078 qla4xxx_mailbox_command(ha, MBOX_REG_COUNT, 1, &mbox_cmd[0],
1079 &mbox_sts[0]);
1080 if (mbox_sts[0] != MBOX_STS_COMMAND_COMPLETE &&
1081 mbox_sts[0] != MBOX_STS_COMMAND_ERROR)
1082 status = QLA_ERROR;
1083
1084 return status;
1085}
David Somayajuluafaf5a22006-09-19 10:28:00 -07001086
1087int qla4xxx_get_flash(struct scsi_qla_host * ha, dma_addr_t dma_addr,
1088 uint32_t offset, uint32_t len)
1089{
1090 uint32_t mbox_cmd[MBOX_REG_COUNT];
1091 uint32_t mbox_sts[MBOX_REG_COUNT];
1092
1093 memset(&mbox_cmd, 0, sizeof(mbox_cmd));
1094 memset(&mbox_sts, 0, sizeof(mbox_sts));
David C Somayajuluc0e344c2007-05-23 18:03:27 -07001095
David Somayajuluafaf5a22006-09-19 10:28:00 -07001096 mbox_cmd[0] = MBOX_CMD_READ_FLASH;
1097 mbox_cmd[1] = LSDW(dma_addr);
1098 mbox_cmd[2] = MSDW(dma_addr);
1099 mbox_cmd[3] = offset;
1100 mbox_cmd[4] = len;
David C Somayajuluc0e344c2007-05-23 18:03:27 -07001101
1102 if (qla4xxx_mailbox_command(ha, MBOX_REG_COUNT, 2, &mbox_cmd[0], &mbox_sts[0]) !=
David Somayajuluafaf5a22006-09-19 10:28:00 -07001103 QLA_SUCCESS) {
1104 DEBUG2(printk("scsi%ld: %s: MBOX_CMD_READ_FLASH, failed w/ "
1105 "status %04X %04X, offset %08x, len %08x\n", ha->host_no,
1106 __func__, mbox_sts[0], mbox_sts[1], offset, len));
1107 return QLA_ERROR;
1108 }
1109 return QLA_SUCCESS;
1110}
1111
1112/**
Harish Zunjarrao7ad633c2011-05-17 23:17:11 -07001113 * qla4xxx_about_firmware - gets FW, iscsi draft and boot loader version
David Somayajuluafaf5a22006-09-19 10:28:00 -07001114 * @ha: Pointer to host adapter structure.
1115 *
Harish Zunjarrao7ad633c2011-05-17 23:17:11 -07001116 * Retrieves the FW version, iSCSI draft version & bootloader version of HBA.
1117 * Mailboxes 2 & 3 may hold an address for data. Make sure that we write 0 to
1118 * those mailboxes, if unused.
David Somayajuluafaf5a22006-09-19 10:28:00 -07001119 **/
Harish Zunjarrao7ad633c2011-05-17 23:17:11 -07001120int qla4xxx_about_firmware(struct scsi_qla_host *ha)
David Somayajuluafaf5a22006-09-19 10:28:00 -07001121{
Harish Zunjarrao7ad633c2011-05-17 23:17:11 -07001122 struct about_fw_info *about_fw = NULL;
1123 dma_addr_t about_fw_dma;
David Somayajuluafaf5a22006-09-19 10:28:00 -07001124 uint32_t mbox_cmd[MBOX_REG_COUNT];
1125 uint32_t mbox_sts[MBOX_REG_COUNT];
Harish Zunjarrao7ad633c2011-05-17 23:17:11 -07001126 int status = QLA_ERROR;
David Somayajuluafaf5a22006-09-19 10:28:00 -07001127
Harish Zunjarrao7ad633c2011-05-17 23:17:11 -07001128 about_fw = dma_alloc_coherent(&ha->pdev->dev,
1129 sizeof(struct about_fw_info),
1130 &about_fw_dma, GFP_KERNEL);
1131 if (!about_fw) {
1132 DEBUG2(ql4_printk(KERN_ERR, ha, "%s: Unable to alloc memory "
1133 "for about_fw\n", __func__));
1134 return status;
1135 }
1136
1137 memset(about_fw, 0, sizeof(struct about_fw_info));
David Somayajuluafaf5a22006-09-19 10:28:00 -07001138 memset(&mbox_cmd, 0, sizeof(mbox_cmd));
1139 memset(&mbox_sts, 0, sizeof(mbox_sts));
David C Somayajuluc0e344c2007-05-23 18:03:27 -07001140
David Somayajuluafaf5a22006-09-19 10:28:00 -07001141 mbox_cmd[0] = MBOX_CMD_ABOUT_FW;
Harish Zunjarrao7ad633c2011-05-17 23:17:11 -07001142 mbox_cmd[2] = LSDW(about_fw_dma);
1143 mbox_cmd[3] = MSDW(about_fw_dma);
1144 mbox_cmd[4] = sizeof(struct about_fw_info);
David C Somayajuluc0e344c2007-05-23 18:03:27 -07001145
Harish Zunjarrao7ad633c2011-05-17 23:17:11 -07001146 status = qla4xxx_mailbox_command(ha, MBOX_REG_COUNT, MBOX_REG_COUNT,
1147 &mbox_cmd[0], &mbox_sts[0]);
1148 if (status != QLA_SUCCESS) {
1149 DEBUG2(ql4_printk(KERN_WARNING, ha, "%s: MBOX_CMD_ABOUT_FW "
1150 "failed w/ status %04X\n", __func__,
1151 mbox_sts[0]));
1152 goto exit_about_fw;
David Somayajuluafaf5a22006-09-19 10:28:00 -07001153 }
1154
Harish Zunjarrao7ad633c2011-05-17 23:17:11 -07001155 /* Save version information. */
1156 ha->firmware_version[0] = le16_to_cpu(about_fw->fw_major);
1157 ha->firmware_version[1] = le16_to_cpu(about_fw->fw_minor);
1158 ha->patch_number = le16_to_cpu(about_fw->fw_patch);
1159 ha->build_number = le16_to_cpu(about_fw->fw_build);
1160 ha->iscsi_major = le16_to_cpu(about_fw->iscsi_major);
1161 ha->iscsi_minor = le16_to_cpu(about_fw->iscsi_minor);
1162 ha->bootload_major = le16_to_cpu(about_fw->bootload_major);
1163 ha->bootload_minor = le16_to_cpu(about_fw->bootload_minor);
1164 ha->bootload_patch = le16_to_cpu(about_fw->bootload_patch);
1165 ha->bootload_build = le16_to_cpu(about_fw->bootload_build);
1166 status = QLA_SUCCESS;
David Somayajuluafaf5a22006-09-19 10:28:00 -07001167
Harish Zunjarrao7ad633c2011-05-17 23:17:11 -07001168exit_about_fw:
1169 dma_free_coherent(&ha->pdev->dev, sizeof(struct about_fw_info),
1170 about_fw, about_fw_dma);
1171 return status;
David Somayajuluafaf5a22006-09-19 10:28:00 -07001172}
1173
Manish Rangankarb3a271a2011-07-25 13:48:53 -05001174static int qla4xxx_get_default_ddb(struct scsi_qla_host *ha, uint32_t options,
Adrian Bunk47975472007-04-26 00:35:16 -07001175 dma_addr_t dma_addr)
David Somayajuluafaf5a22006-09-19 10:28:00 -07001176{
1177 uint32_t mbox_cmd[MBOX_REG_COUNT];
1178 uint32_t mbox_sts[MBOX_REG_COUNT];
1179
1180 memset(&mbox_cmd, 0, sizeof(mbox_cmd));
1181 memset(&mbox_sts, 0, sizeof(mbox_sts));
1182
1183 mbox_cmd[0] = MBOX_CMD_GET_DATABASE_ENTRY_DEFAULTS;
Manish Rangankarb3a271a2011-07-25 13:48:53 -05001184 mbox_cmd[1] = options;
David Somayajuluafaf5a22006-09-19 10:28:00 -07001185 mbox_cmd[2] = LSDW(dma_addr);
1186 mbox_cmd[3] = MSDW(dma_addr);
1187
David C Somayajuluc0e344c2007-05-23 18:03:27 -07001188 if (qla4xxx_mailbox_command(ha, MBOX_REG_COUNT, 1, &mbox_cmd[0], &mbox_sts[0]) !=
David Somayajuluafaf5a22006-09-19 10:28:00 -07001189 QLA_SUCCESS) {
1190 DEBUG2(printk("scsi%ld: %s: failed status %04X\n",
1191 ha->host_no, __func__, mbox_sts[0]));
1192 return QLA_ERROR;
1193 }
1194 return QLA_SUCCESS;
1195}
1196
Manish Rangankarb3a271a2011-07-25 13:48:53 -05001197int qla4xxx_req_ddb_entry(struct scsi_qla_host *ha, uint32_t ddb_index,
1198 uint32_t *mbx_sts)
David Somayajuluafaf5a22006-09-19 10:28:00 -07001199{
Manish Rangankarb3a271a2011-07-25 13:48:53 -05001200 int status;
David Somayajuluafaf5a22006-09-19 10:28:00 -07001201 uint32_t mbox_cmd[MBOX_REG_COUNT];
1202 uint32_t mbox_sts[MBOX_REG_COUNT];
1203
1204 memset(&mbox_cmd, 0, sizeof(mbox_cmd));
1205 memset(&mbox_sts, 0, sizeof(mbox_sts));
1206
1207 mbox_cmd[0] = MBOX_CMD_REQUEST_DATABASE_ENTRY;
Manish Rangankarb3a271a2011-07-25 13:48:53 -05001208 mbox_cmd[1] = ddb_index;
David Somayajuluafaf5a22006-09-19 10:28:00 -07001209
Manish Rangankarb3a271a2011-07-25 13:48:53 -05001210 status = qla4xxx_mailbox_command(ha, MBOX_REG_COUNT, 1, &mbox_cmd[0],
1211 &mbox_sts[0]);
1212 if (status != QLA_SUCCESS) {
1213 DEBUG2(ql4_printk(KERN_ERR, ha, "%s: failed status %04X\n",
1214 __func__, mbox_sts[0]));
David Somayajuluafaf5a22006-09-19 10:28:00 -07001215 }
1216
Manish Rangankarb3a271a2011-07-25 13:48:53 -05001217 *mbx_sts = mbox_sts[0];
1218 return status;
David Somayajuluafaf5a22006-09-19 10:28:00 -07001219}
1220
Manish Rangankarb3a271a2011-07-25 13:48:53 -05001221int qla4xxx_clear_ddb_entry(struct scsi_qla_host *ha, uint32_t ddb_index)
1222{
1223 int status;
1224 uint32_t mbox_cmd[MBOX_REG_COUNT];
1225 uint32_t mbox_sts[MBOX_REG_COUNT];
1226
1227 memset(&mbox_cmd, 0, sizeof(mbox_cmd));
1228 memset(&mbox_sts, 0, sizeof(mbox_sts));
1229
1230 mbox_cmd[0] = MBOX_CMD_CLEAR_DATABASE_ENTRY;
1231 mbox_cmd[1] = ddb_index;
1232
1233 status = qla4xxx_mailbox_command(ha, 2, 1, &mbox_cmd[0],
1234 &mbox_sts[0]);
1235 if (status != QLA_SUCCESS) {
1236 DEBUG2(ql4_printk(KERN_ERR, ha, "%s: failed status %04X\n",
1237 __func__, mbox_sts[0]));
1238 }
1239
1240 return status;
1241}
1242
Mike Christied00efe32011-07-25 13:48:38 -05001243int qla4xxx_set_flash(struct scsi_qla_host *ha, dma_addr_t dma_addr,
1244 uint32_t offset, uint32_t length, uint32_t options)
1245{
1246 uint32_t mbox_cmd[MBOX_REG_COUNT];
1247 uint32_t mbox_sts[MBOX_REG_COUNT];
1248 int status = QLA_SUCCESS;
1249
1250 memset(&mbox_cmd, 0, sizeof(mbox_cmd));
1251 memset(&mbox_sts, 0, sizeof(mbox_sts));
1252
1253 mbox_cmd[0] = MBOX_CMD_WRITE_FLASH;
1254 mbox_cmd[1] = LSDW(dma_addr);
1255 mbox_cmd[2] = MSDW(dma_addr);
1256 mbox_cmd[3] = offset;
1257 mbox_cmd[4] = length;
1258 mbox_cmd[5] = options;
1259
1260 status = qla4xxx_mailbox_command(ha, 6, 2, &mbox_cmd[0], &mbox_sts[0]);
1261 if (status != QLA_SUCCESS) {
1262 DEBUG2(ql4_printk(KERN_WARNING, ha, "%s: MBOX_CMD_WRITE_FLASH "
1263 "failed w/ status %04X, mbx1 %04X\n",
1264 __func__, mbox_sts[0], mbox_sts[1]));
1265 }
1266 return status;
1267}
1268
Manish Rangankar2a991c22011-07-25 13:48:55 -05001269int qla4xxx_bootdb_by_index(struct scsi_qla_host *ha,
1270 struct dev_db_entry *fw_ddb_entry,
1271 dma_addr_t fw_ddb_entry_dma, uint16_t ddb_index)
1272{
1273 uint32_t dev_db_start_offset = FLASH_OFFSET_DB_INFO;
1274 uint32_t dev_db_end_offset;
1275 int status = QLA_ERROR;
1276
1277 memset(fw_ddb_entry, 0, sizeof(*fw_ddb_entry));
1278
1279 dev_db_start_offset += (ddb_index * sizeof(*fw_ddb_entry));
1280 dev_db_end_offset = FLASH_OFFSET_DB_END;
1281
1282 if (dev_db_start_offset > dev_db_end_offset) {
1283 DEBUG2(ql4_printk(KERN_ERR, ha,
1284 "%s:Invalid DDB index %d", __func__,
1285 ddb_index));
1286 goto exit_bootdb_failed;
1287 }
1288
1289 if (qla4xxx_get_flash(ha, fw_ddb_entry_dma, dev_db_start_offset,
1290 sizeof(*fw_ddb_entry)) != QLA_SUCCESS) {
1291 ql4_printk(KERN_ERR, ha, "scsi%ld: %s: Get Flash"
1292 "failed\n", ha->host_no, __func__);
1293 goto exit_bootdb_failed;
1294 }
1295
1296 if (fw_ddb_entry->cookie == DDB_VALID_COOKIE)
1297 status = QLA_SUCCESS;
1298
1299exit_bootdb_failed:
1300 return status;
1301}
1302
1303int qla4xxx_get_chap(struct scsi_qla_host *ha, char *username, char *password,
1304 uint16_t idx)
1305{
1306 int ret = 0;
1307 int rval = QLA_ERROR;
1308 uint32_t offset = 0;
1309 struct ql4_chap_table *chap_table;
1310 dma_addr_t chap_dma;
1311
1312 chap_table = dma_pool_alloc(ha->chap_dma_pool, GFP_KERNEL, &chap_dma);
1313 if (chap_table == NULL) {
1314 ret = -ENOMEM;
1315 goto exit_get_chap;
1316 }
1317
1318 memset(chap_table, 0, sizeof(struct ql4_chap_table));
1319
1320 offset = 0x06000000 | (idx * sizeof(struct ql4_chap_table));
1321
1322 rval = qla4xxx_get_flash(ha, chap_dma, offset,
1323 sizeof(struct ql4_chap_table));
1324 if (rval != QLA_SUCCESS) {
1325 ret = -EINVAL;
1326 goto exit_get_chap;
1327 }
1328
1329 DEBUG2(ql4_printk(KERN_INFO, ha, "Chap Cookie: x%x\n",
1330 __le16_to_cpu(chap_table->cookie)));
1331
1332 if (__le16_to_cpu(chap_table->cookie) != CHAP_VALID_COOKIE) {
1333 ql4_printk(KERN_ERR, ha, "No valid chap entry found\n");
1334 goto exit_get_chap;
1335 }
1336
1337 strncpy(password, chap_table->secret, QL4_CHAP_MAX_SECRET_LEN);
1338 strncpy(username, chap_table->name, QL4_CHAP_MAX_NAME_LEN);
1339 chap_table->cookie = __constant_cpu_to_le16(CHAP_VALID_COOKIE);
1340
1341exit_get_chap:
1342 dma_pool_free(ha->chap_dma_pool, chap_table, chap_dma);
1343 return ret;
1344}
1345
Manish Rangankarb3a271a2011-07-25 13:48:53 -05001346static int qla4xxx_set_chap(struct scsi_qla_host *ha, char *username,
1347 char *password, uint16_t idx, int bidi)
1348{
1349 int ret = 0;
1350 int rval = QLA_ERROR;
1351 uint32_t offset = 0;
1352 struct ql4_chap_table *chap_table;
1353 dma_addr_t chap_dma;
1354
1355 chap_table = dma_pool_alloc(ha->chap_dma_pool, GFP_KERNEL, &chap_dma);
1356 if (chap_table == NULL) {
1357 ret = -ENOMEM;
1358 goto exit_set_chap;
1359 }
1360
1361 memset(chap_table, 0, sizeof(struct ql4_chap_table));
1362 if (bidi)
1363 chap_table->flags |= BIT_6; /* peer */
1364 else
1365 chap_table->flags |= BIT_7; /* local */
1366 chap_table->secret_len = strlen(password);
1367 strncpy(chap_table->secret, password, MAX_CHAP_SECRET_LEN);
1368 strncpy(chap_table->name, username, MAX_CHAP_NAME_LEN);
1369 chap_table->cookie = __constant_cpu_to_le16(CHAP_VALID_COOKIE);
1370 offset = 0x06000000 | (idx * sizeof(struct ql4_chap_table));
1371 rval = qla4xxx_set_flash(ha, chap_dma, offset,
1372 sizeof(struct ql4_chap_table),
1373 FLASH_OPT_RMW_COMMIT);
1374 dma_pool_free(ha->chap_dma_pool, chap_table, chap_dma);
1375 if (rval != QLA_SUCCESS)
1376 ret = -EINVAL;
1377
1378exit_set_chap:
1379 return ret;
1380}
1381
Mike Christied00efe32011-07-25 13:48:38 -05001382int qla4xxx_conn_close_sess_logout(struct scsi_qla_host *ha,
1383 uint16_t fw_ddb_index,
1384 uint16_t connection_id,
1385 uint16_t option)
1386{
1387 uint32_t mbox_cmd[MBOX_REG_COUNT];
1388 uint32_t mbox_sts[MBOX_REG_COUNT];
1389 int status = QLA_SUCCESS;
1390
1391 memset(&mbox_cmd, 0, sizeof(mbox_cmd));
1392 memset(&mbox_sts, 0, sizeof(mbox_sts));
1393
1394 mbox_cmd[0] = MBOX_CMD_CONN_CLOSE_SESS_LOGOUT;
1395 mbox_cmd[1] = fw_ddb_index;
1396 mbox_cmd[2] = connection_id;
1397 mbox_cmd[3] = option;
1398
1399 status = qla4xxx_mailbox_command(ha, 4, 2, &mbox_cmd[0], &mbox_sts[0]);
1400 if (status != QLA_SUCCESS) {
1401 DEBUG2(ql4_printk(KERN_WARNING, ha, "%s: MBOX_CMD_CONN_CLOSE "
1402 "option %04x failed w/ status %04X %04X\n",
1403 __func__, option, mbox_sts[0], mbox_sts[1]));
1404 }
1405 return status;
1406}
1407
1408int qla4xxx_disable_acb(struct scsi_qla_host *ha)
1409{
1410 uint32_t mbox_cmd[MBOX_REG_COUNT];
1411 uint32_t mbox_sts[MBOX_REG_COUNT];
1412 int status = QLA_SUCCESS;
1413
1414 memset(&mbox_cmd, 0, sizeof(mbox_cmd));
1415 memset(&mbox_sts, 0, sizeof(mbox_sts));
1416
1417 mbox_cmd[0] = MBOX_CMD_DISABLE_ACB;
1418
1419 status = qla4xxx_mailbox_command(ha, 8, 5, &mbox_cmd[0], &mbox_sts[0]);
1420 if (status != QLA_SUCCESS) {
1421 DEBUG2(ql4_printk(KERN_WARNING, ha, "%s: MBOX_CMD_DISABLE_ACB "
1422 "failed w/ status %04X %04X %04X", __func__,
1423 mbox_sts[0], mbox_sts[1], mbox_sts[2]));
1424 }
1425 return status;
1426}
1427
Harish Zunjarrao60854912011-08-12 02:51:27 -07001428int qla4xxx_get_acb(struct scsi_qla_host *ha, dma_addr_t acb_dma,
1429 uint32_t acb_type, uint32_t len)
Mike Christied00efe32011-07-25 13:48:38 -05001430{
Harish Zunjarrao60854912011-08-12 02:51:27 -07001431 uint32_t mbox_cmd[MBOX_REG_COUNT];
1432 uint32_t mbox_sts[MBOX_REG_COUNT];
Mike Christied00efe32011-07-25 13:48:38 -05001433 int status = QLA_SUCCESS;
1434
Harish Zunjarrao60854912011-08-12 02:51:27 -07001435 memset(&mbox_cmd, 0, sizeof(mbox_cmd));
1436 memset(&mbox_sts, 0, sizeof(mbox_sts));
1437
Mike Christied00efe32011-07-25 13:48:38 -05001438 mbox_cmd[0] = MBOX_CMD_GET_ACB;
Harish Zunjarrao60854912011-08-12 02:51:27 -07001439 mbox_cmd[1] = acb_type;
Mike Christied00efe32011-07-25 13:48:38 -05001440 mbox_cmd[2] = LSDW(acb_dma);
1441 mbox_cmd[3] = MSDW(acb_dma);
Harish Zunjarrao60854912011-08-12 02:51:27 -07001442 mbox_cmd[4] = len;
Mike Christied00efe32011-07-25 13:48:38 -05001443
1444 status = qla4xxx_mailbox_command(ha, 5, 5, &mbox_cmd[0], &mbox_sts[0]);
1445 if (status != QLA_SUCCESS) {
1446 DEBUG2(ql4_printk(KERN_WARNING, ha, "%s: MBOX_CMD_GET_ACB "
1447 "failed w/ status %04X\n", __func__,
1448 mbox_sts[0]));
1449 }
1450 return status;
1451}
1452
1453int qla4xxx_set_acb(struct scsi_qla_host *ha, uint32_t *mbox_cmd,
1454 uint32_t *mbox_sts, dma_addr_t acb_dma)
1455{
1456 int status = QLA_SUCCESS;
1457
1458 memset(mbox_cmd, 0, sizeof(mbox_cmd[0]) * MBOX_REG_COUNT);
1459 memset(mbox_sts, 0, sizeof(mbox_sts[0]) * MBOX_REG_COUNT);
1460 mbox_cmd[0] = MBOX_CMD_SET_ACB;
1461 mbox_cmd[1] = 0; /* Primary ACB */
1462 mbox_cmd[2] = LSDW(acb_dma);
1463 mbox_cmd[3] = MSDW(acb_dma);
1464 mbox_cmd[4] = sizeof(struct addr_ctrl_blk);
1465
1466 status = qla4xxx_mailbox_command(ha, 5, 5, &mbox_cmd[0], &mbox_sts[0]);
1467 if (status != QLA_SUCCESS) {
1468 DEBUG2(ql4_printk(KERN_WARNING, ha, "%s: MBOX_CMD_SET_ACB "
1469 "failed w/ status %04X\n", __func__,
1470 mbox_sts[0]));
1471 }
1472 return status;
1473}
Manish Rangankarb3a271a2011-07-25 13:48:53 -05001474
1475int qla4xxx_set_param_ddbentry(struct scsi_qla_host *ha,
1476 struct ddb_entry *ddb_entry,
1477 struct iscsi_cls_conn *cls_conn,
1478 uint32_t *mbx_sts)
1479{
1480 struct dev_db_entry *fw_ddb_entry;
1481 struct iscsi_conn *conn;
1482 struct iscsi_session *sess;
1483 struct qla_conn *qla_conn;
1484 struct sockaddr *dst_addr;
1485 dma_addr_t fw_ddb_entry_dma;
1486 int status = QLA_SUCCESS;
1487 int rval = 0;
1488 struct sockaddr_in *addr;
1489 struct sockaddr_in6 *addr6;
1490 char *ip;
1491 uint16_t iscsi_opts = 0;
1492 uint32_t options = 0;
1493 uint16_t idx;
1494 int max_chap_entries = 0;
1495
1496 fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
1497 &fw_ddb_entry_dma, GFP_KERNEL);
1498 if (!fw_ddb_entry) {
1499 DEBUG2(ql4_printk(KERN_ERR, ha,
1500 "%s: Unable to allocate dma buffer.\n",
1501 __func__));
1502 rval = -ENOMEM;
1503 goto exit_set_param_no_free;
1504 }
1505
1506 conn = cls_conn->dd_data;
1507 qla_conn = conn->dd_data;
1508 sess = conn->session;
1509 dst_addr = &qla_conn->qla_ep->dst_addr;
1510
1511 if (dst_addr->sa_family == AF_INET6)
1512 options |= IPV6_DEFAULT_DDB_ENTRY;
1513
1514 status = qla4xxx_get_default_ddb(ha, options, fw_ddb_entry_dma);
1515 if (status == QLA_ERROR) {
1516 rval = -EINVAL;
1517 goto exit_set_param;
1518 }
1519
1520 iscsi_opts = le16_to_cpu(fw_ddb_entry->iscsi_options);
1521 memset(fw_ddb_entry->iscsi_alias, 0, sizeof(fw_ddb_entry->iscsi_alias));
1522
1523 memset(fw_ddb_entry->iscsi_name, 0, sizeof(fw_ddb_entry->iscsi_name));
1524
1525 if (sess->targetname != NULL) {
1526 memcpy(fw_ddb_entry->iscsi_name, sess->targetname,
1527 min(strlen(sess->targetname),
1528 sizeof(fw_ddb_entry->iscsi_name)));
1529 }
1530
1531 memset(fw_ddb_entry->ip_addr, 0, sizeof(fw_ddb_entry->ip_addr));
1532 memset(fw_ddb_entry->tgt_addr, 0, sizeof(fw_ddb_entry->tgt_addr));
1533
1534 fw_ddb_entry->options = DDB_OPT_TARGET | DDB_OPT_AUTO_SENDTGTS_DISABLE;
1535
1536 if (dst_addr->sa_family == AF_INET) {
1537 addr = (struct sockaddr_in *)dst_addr;
1538 ip = (char *)&addr->sin_addr;
1539 memcpy(fw_ddb_entry->ip_addr, ip, IP_ADDR_LEN);
1540 fw_ddb_entry->port = cpu_to_le16(ntohs(addr->sin_port));
1541 DEBUG2(ql4_printk(KERN_INFO, ha,
1542 "%s: Destination Address [%pI4]: index [%d]\n",
1543 __func__, fw_ddb_entry->ip_addr,
1544 ddb_entry->fw_ddb_index));
1545 } else if (dst_addr->sa_family == AF_INET6) {
1546 addr6 = (struct sockaddr_in6 *)dst_addr;
1547 ip = (char *)&addr6->sin6_addr;
1548 memcpy(fw_ddb_entry->ip_addr, ip, IPv6_ADDR_LEN);
1549 fw_ddb_entry->port = cpu_to_le16(ntohs(addr6->sin6_port));
1550 fw_ddb_entry->options |= DDB_OPT_IPV6_DEVICE;
1551 DEBUG2(ql4_printk(KERN_INFO, ha,
1552 "%s: Destination Address [%pI6]: index [%d]\n",
1553 __func__, fw_ddb_entry->ip_addr,
1554 ddb_entry->fw_ddb_index));
1555 } else {
1556 ql4_printk(KERN_ERR, ha,
1557 "%s: Failed to get IP Address\n",
1558 __func__);
1559 rval = -EINVAL;
1560 goto exit_set_param;
1561 }
1562
1563 if (is_qla8022(ha))
1564 max_chap_entries = MAX_CHAP_ENTRIES_82XX;
1565 else
1566 max_chap_entries = MAX_CHAP_ENTRIES_40XX;
1567 /* CHAP */
1568 if (sess->username != NULL && sess->password != NULL) {
1569 if (strlen(sess->username) && strlen(sess->password)) {
1570 iscsi_opts |= BIT_7;
1571 idx = ddb_entry->fw_ddb_index * 2;
1572 if (idx > max_chap_entries) {
1573 ql4_printk(KERN_ERR, ha,
1574 "%s: Invalid ddb or chap index\n",
1575 __func__);
1576 rval = -EINVAL;
1577 goto exit_set_param;
1578 }
1579
1580 rval = qla4xxx_set_chap(ha, sess->username,
1581 sess->password, idx, 0);
1582 if (rval)
1583 goto exit_set_param;
1584
1585 fw_ddb_entry->chap_tbl_idx = cpu_to_le16(idx);
1586 }
1587 }
1588
1589 if (sess->username_in != NULL && sess->password_in != NULL) {
1590 /* Check if BIDI CHAP */
1591 if (strlen(sess->username_in) && strlen(sess->password_in)) {
1592 iscsi_opts |= BIT_4;
1593 idx = (ddb_entry->fw_ddb_index * 2) + 1;
1594 if (idx > max_chap_entries) {
1595 ql4_printk(KERN_ERR, ha,
1596 "%s: Invalid ddb or bidi chap "
1597 "index\n", __func__);
1598 rval = -EINVAL;
1599 goto exit_set_param;
1600 }
1601 rval = qla4xxx_set_chap(ha, sess->username_in,
1602 sess->password_in, idx, 0);
1603 if (rval)
1604 goto exit_set_param;
1605 }
1606 }
1607
1608 if (sess->initial_r2t_en)
1609 iscsi_opts |= BIT_10;
1610
1611 if (sess->imm_data_en)
1612 iscsi_opts |= BIT_11;
1613
1614 fw_ddb_entry->iscsi_options = cpu_to_le16(iscsi_opts);
1615
1616 if (conn->max_recv_dlength)
1617 fw_ddb_entry->iscsi_max_rcv_data_seg_len =
1618 __constant_cpu_to_le16((conn->max_recv_dlength / BYTE_UNITS));
1619
1620 if (sess->max_r2t)
1621 fw_ddb_entry->iscsi_max_outsnd_r2t = cpu_to_le16(sess->max_r2t);
1622
1623 if (sess->first_burst)
1624 fw_ddb_entry->iscsi_first_burst_len =
1625 __constant_cpu_to_le16((sess->first_burst / BYTE_UNITS));
1626
1627 if (sess->max_burst)
1628 fw_ddb_entry->iscsi_max_burst_len =
1629 __constant_cpu_to_le16((sess->max_burst / BYTE_UNITS));
1630
1631 if (sess->time2wait)
1632 fw_ddb_entry->iscsi_def_time2wait =
1633 cpu_to_le16(sess->time2wait);
1634
1635 if (sess->time2retain)
1636 fw_ddb_entry->iscsi_def_time2retain =
1637 cpu_to_le16(sess->time2retain);
1638
1639 status = qla4xxx_set_ddb_entry(ha, ddb_entry->fw_ddb_index,
1640 fw_ddb_entry_dma, mbx_sts);
1641
1642 if (status != QLA_SUCCESS)
1643 rval = -EINVAL;
1644exit_set_param:
1645 dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
1646 fw_ddb_entry, fw_ddb_entry_dma);
1647exit_set_param_no_free:
1648 return rval;
1649}
1650
1651int qla4xxx_get_mgmt_data(struct scsi_qla_host *ha, uint16_t fw_ddb_index,
1652 uint16_t stats_size, dma_addr_t stats_dma)
1653{
1654 int status = QLA_SUCCESS;
1655 uint32_t mbox_cmd[MBOX_REG_COUNT];
1656 uint32_t mbox_sts[MBOX_REG_COUNT];
1657
1658 memset(mbox_cmd, 0, sizeof(mbox_cmd[0]) * MBOX_REG_COUNT);
1659 memset(mbox_sts, 0, sizeof(mbox_sts[0]) * MBOX_REG_COUNT);
1660 mbox_cmd[0] = MBOX_CMD_GET_MANAGEMENT_DATA;
1661 mbox_cmd[1] = fw_ddb_index;
1662 mbox_cmd[2] = LSDW(stats_dma);
1663 mbox_cmd[3] = MSDW(stats_dma);
1664 mbox_cmd[4] = stats_size;
1665
1666 status = qla4xxx_mailbox_command(ha, 5, 1, &mbox_cmd[0], &mbox_sts[0]);
1667 if (status != QLA_SUCCESS) {
1668 DEBUG2(ql4_printk(KERN_WARNING, ha,
1669 "%s: MBOX_CMD_GET_MANAGEMENT_DATA "
1670 "failed w/ status %04X\n", __func__,
1671 mbox_sts[0]));
1672 }
1673 return status;
1674}
Harish Zunjarrao8b0402e2011-08-01 03:26:15 -07001675
1676int qla4xxx_get_ip_state(struct scsi_qla_host *ha, uint32_t acb_idx,
1677 uint32_t ip_idx, uint32_t *sts)
1678{
1679 uint32_t mbox_cmd[MBOX_REG_COUNT];
1680 uint32_t mbox_sts[MBOX_REG_COUNT];
1681 int status = QLA_SUCCESS;
1682
1683 memset(&mbox_cmd, 0, sizeof(mbox_cmd));
1684 memset(&mbox_sts, 0, sizeof(mbox_sts));
1685 mbox_cmd[0] = MBOX_CMD_GET_IP_ADDR_STATE;
1686 mbox_cmd[1] = acb_idx;
1687 mbox_cmd[2] = ip_idx;
1688
1689 status = qla4xxx_mailbox_command(ha, 3, 8, &mbox_cmd[0], &mbox_sts[0]);
1690 if (status != QLA_SUCCESS) {
1691 DEBUG2(ql4_printk(KERN_WARNING, ha, "%s: "
1692 "MBOX_CMD_GET_IP_ADDR_STATE failed w/ "
1693 "status %04X\n", __func__, mbox_sts[0]));
1694 }
1695 memcpy(sts, mbox_sts, sizeof(mbox_sts));
1696 return status;
1697}
Harish Zunjarrao7c07d132011-08-01 03:26:16 -07001698
1699int qla4xxx_get_nvram(struct scsi_qla_host *ha, dma_addr_t nvram_dma,
1700 uint32_t offset, uint32_t size)
1701{
1702 int status = QLA_SUCCESS;
1703 uint32_t mbox_cmd[MBOX_REG_COUNT];
1704 uint32_t mbox_sts[MBOX_REG_COUNT];
1705
1706 memset(&mbox_cmd, 0, sizeof(mbox_cmd));
1707 memset(&mbox_sts, 0, sizeof(mbox_sts));
1708
1709 mbox_cmd[0] = MBOX_CMD_GET_NVRAM;
1710 mbox_cmd[1] = LSDW(nvram_dma);
1711 mbox_cmd[2] = MSDW(nvram_dma);
1712 mbox_cmd[3] = offset;
1713 mbox_cmd[4] = size;
1714
1715 status = qla4xxx_mailbox_command(ha, MBOX_REG_COUNT, 1, &mbox_cmd[0],
1716 &mbox_sts[0]);
1717 if (status != QLA_SUCCESS) {
1718 DEBUG2(ql4_printk(KERN_ERR, ha, "scsi%ld: %s: failed "
1719 "status %04X\n", ha->host_no, __func__,
1720 mbox_sts[0]));
1721 }
1722 return status;
1723}
1724
1725int qla4xxx_set_nvram(struct scsi_qla_host *ha, dma_addr_t nvram_dma,
1726 uint32_t offset, uint32_t size)
1727{
1728 int status = QLA_SUCCESS;
1729 uint32_t mbox_cmd[MBOX_REG_COUNT];
1730 uint32_t mbox_sts[MBOX_REG_COUNT];
1731
1732 memset(&mbox_cmd, 0, sizeof(mbox_cmd));
1733 memset(&mbox_sts, 0, sizeof(mbox_sts));
1734
1735 mbox_cmd[0] = MBOX_CMD_SET_NVRAM;
1736 mbox_cmd[1] = LSDW(nvram_dma);
1737 mbox_cmd[2] = MSDW(nvram_dma);
1738 mbox_cmd[3] = offset;
1739 mbox_cmd[4] = size;
1740
1741 status = qla4xxx_mailbox_command(ha, MBOX_REG_COUNT, 1, &mbox_cmd[0],
1742 &mbox_sts[0]);
1743 if (status != QLA_SUCCESS) {
1744 DEBUG2(ql4_printk(KERN_ERR, ha, "scsi%ld: %s: failed "
1745 "status %04X\n", ha->host_no, __func__,
1746 mbox_sts[0]));
1747 }
1748 return status;
1749}
Harish Zunjarrao5232f802011-08-12 02:51:26 -07001750
1751int qla4xxx_restore_factory_defaults(struct scsi_qla_host *ha,
1752 uint32_t region, uint32_t field0,
1753 uint32_t field1)
1754{
1755 int status = QLA_SUCCESS;
1756 uint32_t mbox_cmd[MBOX_REG_COUNT];
1757 uint32_t mbox_sts[MBOX_REG_COUNT];
1758
1759 memset(&mbox_cmd, 0, sizeof(mbox_cmd));
1760 memset(&mbox_sts, 0, sizeof(mbox_sts));
1761
1762 mbox_cmd[0] = MBOX_CMD_RESTORE_FACTORY_DEFAULTS;
1763 mbox_cmd[3] = region;
1764 mbox_cmd[4] = field0;
1765 mbox_cmd[5] = field1;
1766
1767 status = qla4xxx_mailbox_command(ha, MBOX_REG_COUNT, 3, &mbox_cmd[0],
1768 &mbox_sts[0]);
1769 if (status != QLA_SUCCESS) {
1770 DEBUG2(ql4_printk(KERN_ERR, ha, "scsi%ld: %s: failed "
1771 "status %04X\n", ha->host_no, __func__,
1772 mbox_sts[0]));
1773 }
1774 return status;
1775}