blob: 73324fba64bc70ba07945ca9eeda8400edf1ac28 [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
Vikas Chaudhary33693c72012-08-22 07:55:04 -040013void qla4xxx_queue_mbox_cmd(struct scsi_qla_host *ha, uint32_t *mbx_cmd,
14 int in_count)
15{
16 int i;
17
18 /* Load all mailbox registers, except mailbox 0. */
19 for (i = 1; i < in_count; i++)
20 writel(mbx_cmd[i], &ha->reg->mailbox[i]);
21
22 /* Wakeup firmware */
23 writel(mbx_cmd[0], &ha->reg->mailbox[0]);
24 readl(&ha->reg->mailbox[0]);
25 writel(set_rmask(CSR_INTR_RISC), &ha->reg->ctrl_status);
26 readl(&ha->reg->ctrl_status);
27}
28
29void qla4xxx_process_mbox_intr(struct scsi_qla_host *ha, int out_count)
30{
31 int intr_status;
32
33 intr_status = readl(&ha->reg->ctrl_status);
34 if (intr_status & INTR_PENDING) {
35 /*
36 * Service the interrupt.
37 * The ISR will save the mailbox status registers
38 * to a temporary storage location in the adapter structure.
39 */
40 ha->mbox_status_count = out_count;
41 ha->isp_ops->interrupt_service_routine(ha, intr_status);
42 }
43}
David Somayajuluafaf5a22006-09-19 10:28:00 -070044
45/**
46 * qla4xxx_mailbox_command - issues mailbox commands
47 * @ha: Pointer to host adapter structure.
48 * @inCount: number of mailbox registers to load.
49 * @outCount: number of mailbox registers to return.
50 * @mbx_cmd: data pointer for mailbox in registers.
51 * @mbx_sts: data pointer for mailbox out registers.
52 *
Justin P. Mattock70f23fd2011-05-10 10:16:21 +020053 * This routine issue mailbox commands and waits for completion.
David Somayajuluafaf5a22006-09-19 10:28:00 -070054 * If outCount is 0, this routine completes successfully WITHOUT waiting
55 * for the mailbox command to complete.
56 **/
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +053057int qla4xxx_mailbox_command(struct scsi_qla_host *ha, uint8_t inCount,
58 uint8_t outCount, uint32_t *mbx_cmd,
59 uint32_t *mbx_sts)
David Somayajuluafaf5a22006-09-19 10:28:00 -070060{
61 int status = QLA_ERROR;
62 uint8_t i;
63 u_long wait_count;
David Somayajuluafaf5a22006-09-19 10:28:00 -070064 unsigned long flags = 0;
Prasanna Mumbai99b53bf2011-03-21 03:34:25 -070065 uint32_t dev_state;
David Somayajuluafaf5a22006-09-19 10:28:00 -070066
67 /* Make sure that pointers are valid */
68 if (!mbx_cmd || !mbx_sts) {
69 DEBUG2(printk("scsi%ld: %s: Invalid mbx_cmd or mbx_sts "
70 "pointer\n", ha->host_no, __func__));
David C Somayajulu477ffb92007-01-22 12:26:11 -080071 return status;
72 }
Nilesh Javali21033632010-07-30 14:28:07 +053073
Mike Christie13483732011-12-01 21:38:41 -060074 if (is_qla40XX(ha)) {
75 if (test_bit(AF_HA_REMOVAL, &ha->flags)) {
76 DEBUG2(ql4_printk(KERN_WARNING, ha, "scsi%ld: %s: "
77 "prematurely completing mbx cmd as "
78 "adapter removal detected\n",
79 ha->host_no, __func__));
80 return status;
81 }
82 }
83
Lalit Chandivade2232be02010-07-30 14:38:47 +053084 if ((is_aer_supported(ha)) &&
85 (test_bit(AF_PCI_CHANNEL_IO_PERM_FAILURE, &ha->flags))) {
86 DEBUG2(printk(KERN_WARNING "scsi%ld: %s: Perm failure on EEH, "
87 "timeout MBX Exiting.\n", ha->host_no, __func__));
88 return status;
89 }
90
David C Somayajulu477ffb92007-01-22 12:26:11 -080091 /* Mailbox code active */
92 wait_count = MBOX_TOV * 100;
93
94 while (wait_count--) {
95 mutex_lock(&ha->mbox_sem);
96 if (!test_bit(AF_MBOX_COMMAND, &ha->flags)) {
97 set_bit(AF_MBOX_COMMAND, &ha->flags);
98 mutex_unlock(&ha->mbox_sem);
99 break;
100 }
101 mutex_unlock(&ha->mbox_sem);
102 if (!wait_count) {
103 DEBUG2(printk("scsi%ld: %s: mbox_sem failed\n",
104 ha->host_no, __func__));
105 return status;
106 }
107 msleep(10);
David Somayajuluafaf5a22006-09-19 10:28:00 -0700108 }
109
Lalit Chandivade5f50aa32012-04-23 22:32:32 -0700110 if (is_qla8022(ha)) {
111 if (test_bit(AF_FW_RECOVERY, &ha->flags)) {
112 DEBUG2(ql4_printk(KERN_WARNING, ha,
113 "scsi%ld: %s: prematurely completing mbx cmd as firmware recovery detected\n",
114 ha->host_no, __func__));
115 goto mbox_exit;
116 }
117 /* Do not send any mbx cmd if h/w is in failed state*/
Vikas Chaudhary33693c72012-08-22 07:55:04 -0400118 ha->isp_ops->idc_lock(ha);
119 dev_state = qla4_8xxx_rd_direct(ha, QLA8XXX_CRB_DEV_STATE);
120 ha->isp_ops->idc_unlock(ha);
Vikas Chaudharyde8c72d2012-08-22 09:14:24 -0400121 if (dev_state == QLA8XXX_DEV_FAILED) {
Lalit Chandivade5f50aa32012-04-23 22:32:32 -0700122 ql4_printk(KERN_WARNING, ha,
123 "scsi%ld: %s: H/W is in failed state, do not send any mailbox commands\n",
124 ha->host_no, __func__);
125 goto mbox_exit;
126 }
127 }
128
David Somayajuluafaf5a22006-09-19 10:28:00 -0700129 spin_lock_irqsave(&ha->hardware_lock, flags);
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +0530130
David Somayajuluafaf5a22006-09-19 10:28:00 -0700131 ha->mbox_status_count = outCount;
132 for (i = 0; i < outCount; i++)
133 ha->mbox_status[i] = 0;
134
Vikas Chaudhary33693c72012-08-22 07:55:04 -0400135 /* Queue the mailbox command to the firmware */
136 ha->isp_ops->queue_mailbox_command(ha, mbx_cmd, inCount);
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +0530137
David Somayajuluafaf5a22006-09-19 10:28:00 -0700138 spin_unlock_irqrestore(&ha->hardware_lock, flags);
139
140 /* Wait for completion */
David Somayajuluafaf5a22006-09-19 10:28:00 -0700141
142 /*
143 * If we don't want status, don't wait for the mailbox command to
144 * complete. For example, MBOX_CMD_RESET_FW doesn't return status,
145 * you must poll the inbound Interrupt Mask for completion.
146 */
147 if (outCount == 0) {
148 status = QLA_SUCCESS;
David Somayajuluafaf5a22006-09-19 10:28:00 -0700149 goto mbox_exit;
150 }
David Somayajuluafaf5a22006-09-19 10:28:00 -0700151
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +0530152 /*
153 * Wait for completion: Poll or completion queue
154 */
155 if (test_bit(AF_IRQ_ATTACHED, &ha->flags) &&
156 test_bit(AF_INTERRUPTS_ON, &ha->flags) &&
157 test_bit(AF_ONLINE, &ha->flags) &&
Karen Higgins7eece5a2011-03-21 03:34:29 -0700158 !test_bit(AF_HA_REMOVAL, &ha->flags)) {
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +0530159 /* Do not poll for completion. Use completion queue */
160 set_bit(AF_MBOX_COMMAND_NOPOLL, &ha->flags);
161 wait_for_completion_timeout(&ha->mbx_intr_comp, MBOX_TOV * HZ);
162 clear_bit(AF_MBOX_COMMAND_NOPOLL, &ha->flags);
163 } else {
164 /* Poll for command to complete */
165 wait_count = jiffies + MBOX_TOV * HZ;
166 while (test_bit(AF_MBOX_COMMAND_DONE, &ha->flags) == 0) {
167 if (time_after_eq(jiffies, wait_count))
168 break;
Lalit Chandivade2232be02010-07-30 14:38:47 +0530169
David Somayajuluafaf5a22006-09-19 10:28:00 -0700170 /*
171 * Service the interrupt.
172 * The ISR will save the mailbox status registers
173 * to a temporary storage location in the adapter
174 * structure.
175 */
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +0530176
177 spin_lock_irqsave(&ha->hardware_lock, flags);
Vikas Chaudhary33693c72012-08-22 07:55:04 -0400178 ha->isp_ops->process_mailbox_interrupt(ha, outCount);
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +0530179 spin_unlock_irqrestore(&ha->hardware_lock, flags);
180 msleep(10);
David Somayajuluafaf5a22006-09-19 10:28:00 -0700181 }
David Somayajuluafaf5a22006-09-19 10:28:00 -0700182 }
David Somayajuluafaf5a22006-09-19 10:28:00 -0700183
184 /* Check for mailbox timeout. */
185 if (!test_bit(AF_MBOX_COMMAND_DONE, &ha->flags)) {
Nilesh Javali21033632010-07-30 14:28:07 +0530186 if (is_qla8022(ha) &&
187 test_bit(AF_FW_RECOVERY, &ha->flags)) {
188 DEBUG2(ql4_printk(KERN_INFO, ha,
189 "scsi%ld: %s: prematurely completing mbx cmd as "
190 "firmware recovery detected\n",
191 ha->host_no, __func__));
192 goto mbox_exit;
193 }
David Somayajuluafaf5a22006-09-19 10:28:00 -0700194 DEBUG2(printk("scsi%ld: Mailbox Cmd 0x%08X timed out ...,"
195 " Scheduling Adapter Reset\n", ha->host_no,
196 mbx_cmd[0]));
197 ha->mailbox_timeout_count++;
198 mbx_sts[0] = (-1);
199 set_bit(DPC_RESET_HA, &ha->dpc_flags);
Giridhar Malavalie6bd0eb2012-01-11 02:44:16 -0800200 if (is_qla8022(ha)) {
201 ql4_printk(KERN_INFO, ha,
202 "disabling pause transmit on port 0 & 1.\n");
Vikas Chaudharyf8086f42012-08-22 07:54:59 -0400203 qla4_82xx_wr_32(ha, QLA82XX_CRB_NIU + 0x98,
Giridhar Malavalie6bd0eb2012-01-11 02:44:16 -0800204 CRB_NIU_XG_PAUSE_CTL_P0 |
205 CRB_NIU_XG_PAUSE_CTL_P1);
206 }
David Somayajuluafaf5a22006-09-19 10:28:00 -0700207 goto mbox_exit;
208 }
209
210 /*
211 * Copy the mailbox out registers to the caller's mailbox in/out
212 * structure.
213 */
214 spin_lock_irqsave(&ha->hardware_lock, flags);
215 for (i = 0; i < outCount; i++)
216 mbx_sts[i] = ha->mbox_status[i];
217
218 /* Set return status and error flags (if applicable). */
219 switch (ha->mbox_status[0]) {
220 case MBOX_STS_COMMAND_COMPLETE:
221 status = QLA_SUCCESS;
222 break;
223
224 case MBOX_STS_INTERMEDIATE_COMPLETION:
225 status = QLA_SUCCESS;
226 break;
227
228 case MBOX_STS_BUSY:
229 DEBUG2( printk("scsi%ld: %s: Cmd = %08X, ISP BUSY\n",
230 ha->host_no, __func__, mbx_cmd[0]));
231 ha->mailbox_timeout_count++;
232 break;
233
234 default:
235 DEBUG2(printk("scsi%ld: %s: **** FAILED, cmd = %08X, "
236 "sts = %08X ****\n", ha->host_no, __func__,
237 mbx_cmd[0], mbx_sts[0]));
238 break;
239 }
240 spin_unlock_irqrestore(&ha->hardware_lock, flags);
241
242mbox_exit:
David C Somayajulu477ffb92007-01-22 12:26:11 -0800243 mutex_lock(&ha->mbox_sem);
David Somayajuluafaf5a22006-09-19 10:28:00 -0700244 clear_bit(AF_MBOX_COMMAND, &ha->flags);
David Somayajuluafaf5a22006-09-19 10:28:00 -0700245 mutex_unlock(&ha->mbox_sem);
David C Somayajulu477ffb92007-01-22 12:26:11 -0800246 clear_bit(AF_MBOX_COMMAND_DONE, &ha->flags);
David Somayajuluafaf5a22006-09-19 10:28:00 -0700247
248 return status;
249}
250
Tej Parkash068237c82012-05-18 04:41:44 -0400251/**
252 * qla4xxx_get_minidump_template - Get the firmware template
253 * @ha: Pointer to host adapter structure.
254 * @phys_addr: dma address for template
255 *
256 * Obtain the minidump template from firmware during initialization
257 * as it may not be available when minidump is desired.
258 **/
259int qla4xxx_get_minidump_template(struct scsi_qla_host *ha,
260 dma_addr_t phys_addr)
261{
262 uint32_t mbox_cmd[MBOX_REG_COUNT];
263 uint32_t mbox_sts[MBOX_REG_COUNT];
264 int status;
265
266 memset(&mbox_cmd, 0, sizeof(mbox_cmd));
267 memset(&mbox_sts, 0, sizeof(mbox_sts));
268
269 mbox_cmd[0] = MBOX_CMD_MINIDUMP;
270 mbox_cmd[1] = MINIDUMP_GET_TMPLT_SUBCOMMAND;
271 mbox_cmd[2] = LSDW(phys_addr);
272 mbox_cmd[3] = MSDW(phys_addr);
273 mbox_cmd[4] = ha->fw_dump_tmplt_size;
274 mbox_cmd[5] = 0;
275
276 status = qla4xxx_mailbox_command(ha, MBOX_REG_COUNT, 2, &mbox_cmd[0],
277 &mbox_sts[0]);
278 if (status != QLA_SUCCESS) {
279 DEBUG2(ql4_printk(KERN_INFO, ha,
280 "scsi%ld: %s: Cmd = %08X, mbx[0] = 0x%04x, mbx[1] = 0x%04x\n",
281 ha->host_no, __func__, mbox_cmd[0],
282 mbox_sts[0], mbox_sts[1]));
283 }
284 return status;
285}
286
287/**
288 * qla4xxx_req_template_size - Get minidump template size from firmware.
289 * @ha: Pointer to host adapter structure.
290 **/
291int qla4xxx_req_template_size(struct scsi_qla_host *ha)
292{
293 uint32_t mbox_cmd[MBOX_REG_COUNT];
294 uint32_t mbox_sts[MBOX_REG_COUNT];
295 int status;
296
297 memset(&mbox_cmd, 0, sizeof(mbox_cmd));
298 memset(&mbox_sts, 0, sizeof(mbox_sts));
299
300 mbox_cmd[0] = MBOX_CMD_MINIDUMP;
301 mbox_cmd[1] = MINIDUMP_GET_SIZE_SUBCOMMAND;
302
303 status = qla4xxx_mailbox_command(ha, MBOX_REG_COUNT, 8, &mbox_cmd[0],
304 &mbox_sts[0]);
305 if (status == QLA_SUCCESS) {
306 ha->fw_dump_tmplt_size = mbox_sts[1];
307 DEBUG2(ql4_printk(KERN_INFO, ha,
308 "%s: sts[0]=0x%04x, template size=0x%04x, size_cm_02=0x%04x, size_cm_04=0x%04x, size_cm_08=0x%04x, size_cm_10=0x%04x, size_cm_FF=0x%04x, version=0x%04x\n",
309 __func__, mbox_sts[0], mbox_sts[1],
310 mbox_sts[2], mbox_sts[3], mbox_sts[4],
311 mbox_sts[5], mbox_sts[6], mbox_sts[7]));
312 if (ha->fw_dump_tmplt_size == 0)
313 status = QLA_ERROR;
314 } else {
315 ql4_printk(KERN_WARNING, ha,
316 "%s: Error sts[0]=0x%04x, mbx[1]=0x%04x\n",
317 __func__, mbox_sts[0], mbox_sts[1]);
318 status = QLA_ERROR;
319 }
320
321 return status;
322}
323
Nilesh Javali21033632010-07-30 14:28:07 +0530324void qla4xxx_mailbox_premature_completion(struct scsi_qla_host *ha)
325{
326 set_bit(AF_FW_RECOVERY, &ha->flags);
327 ql4_printk(KERN_INFO, ha, "scsi%ld: %s: set FW RECOVERY!\n",
328 ha->host_no, __func__);
329
330 if (test_bit(AF_MBOX_COMMAND, &ha->flags)) {
331 if (test_bit(AF_MBOX_COMMAND_NOPOLL, &ha->flags)) {
332 complete(&ha->mbx_intr_comp);
333 ql4_printk(KERN_INFO, ha, "scsi%ld: %s: Due to fw "
334 "recovery, doing premature completion of "
335 "mbx cmd\n", ha->host_no, __func__);
336
337 } else {
338 set_bit(AF_MBOX_COMMAND_DONE, &ha->flags);
339 ql4_printk(KERN_INFO, ha, "scsi%ld: %s: Due to fw "
340 "recovery, doing premature completion of "
341 "polling mbx cmd\n", ha->host_no, __func__);
342 }
343 }
344}
345
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +0530346static uint8_t
Vikas Chaudhary2a49a782010-04-28 11:37:07 +0530347qla4xxx_set_ifcb(struct scsi_qla_host *ha, uint32_t *mbox_cmd,
348 uint32_t *mbox_sts, dma_addr_t init_fw_cb_dma)
349{
350 memset(mbox_cmd, 0, sizeof(mbox_cmd[0]) * MBOX_REG_COUNT);
351 memset(mbox_sts, 0, sizeof(mbox_sts[0]) * MBOX_REG_COUNT);
Shyam Sundar2657c802010-10-06 22:50:29 -0700352
353 if (is_qla8022(ha))
Vikas Chaudharyf8086f42012-08-22 07:54:59 -0400354 qla4_82xx_wr_32(ha, ha->nx_db_wr_ptr, 0);
Shyam Sundar2657c802010-10-06 22:50:29 -0700355
Vikas Chaudhary2a49a782010-04-28 11:37:07 +0530356 mbox_cmd[0] = MBOX_CMD_INITIALIZE_FIRMWARE;
357 mbox_cmd[1] = 0;
358 mbox_cmd[2] = LSDW(init_fw_cb_dma);
359 mbox_cmd[3] = MSDW(init_fw_cb_dma);
360 mbox_cmd[4] = sizeof(struct addr_ctrl_blk);
361 mbox_cmd[5] = (IFCB_VER_MAX << 8) | IFCB_VER_MIN;
362
363 if (qla4xxx_mailbox_command(ha, 6, 6, mbox_cmd, mbox_sts) !=
364 QLA_SUCCESS) {
365 DEBUG2(printk(KERN_WARNING "scsi%ld: %s: "
366 "MBOX_CMD_INITIALIZE_FIRMWARE"
367 " failed w/ status %04X\n",
368 ha->host_no, __func__, mbox_sts[0]));
369 return QLA_ERROR;
370 }
371 return QLA_SUCCESS;
372}
373
Mike Christied00efe32011-07-25 13:48:38 -0500374uint8_t
Vikas Chaudhary2a49a782010-04-28 11:37:07 +0530375qla4xxx_get_ifcb(struct scsi_qla_host *ha, uint32_t *mbox_cmd,
376 uint32_t *mbox_sts, dma_addr_t init_fw_cb_dma)
377{
378 memset(mbox_cmd, 0, sizeof(mbox_cmd[0]) * MBOX_REG_COUNT);
379 memset(mbox_sts, 0, sizeof(mbox_sts[0]) * MBOX_REG_COUNT);
380 mbox_cmd[0] = MBOX_CMD_GET_INIT_FW_CTRL_BLOCK;
381 mbox_cmd[2] = LSDW(init_fw_cb_dma);
382 mbox_cmd[3] = MSDW(init_fw_cb_dma);
383 mbox_cmd[4] = sizeof(struct addr_ctrl_blk);
384
385 if (qla4xxx_mailbox_command(ha, 5, 5, mbox_cmd, mbox_sts) !=
386 QLA_SUCCESS) {
387 DEBUG2(printk(KERN_WARNING "scsi%ld: %s: "
388 "MBOX_CMD_GET_INIT_FW_CTRL_BLOCK"
389 " failed w/ status %04X\n",
390 ha->host_no, __func__, mbox_sts[0]));
391 return QLA_ERROR;
392 }
393 return QLA_SUCCESS;
394}
395
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +0530396static void
Vikas Chaudhary2a49a782010-04-28 11:37:07 +0530397qla4xxx_update_local_ip(struct scsi_qla_host *ha,
Vikas Chaudhary2bab08f2011-07-25 13:48:39 -0500398 struct addr_ctrl_blk *init_fw_cb)
Vikas Chaudhary2a49a782010-04-28 11:37:07 +0530399{
Vikas Chaudhary2bab08f2011-07-25 13:48:39 -0500400 ha->ip_config.tcp_options = le16_to_cpu(init_fw_cb->ipv4_tcp_opts);
401 ha->ip_config.ipv4_options = le16_to_cpu(init_fw_cb->ipv4_ip_opts);
402 ha->ip_config.ipv4_addr_state =
403 le16_to_cpu(init_fw_cb->ipv4_addr_state);
Vikas Chaudhary943c1572011-08-01 03:26:13 -0700404 ha->ip_config.eth_mtu_size =
405 le16_to_cpu(init_fw_cb->eth_mtu_size);
Vikas Chaudhary2ada7fc2011-08-01 03:26:19 -0700406 ha->ip_config.ipv4_port = le16_to_cpu(init_fw_cb->ipv4_port);
Vikas Chaudhary2bab08f2011-07-25 13:48:39 -0500407
408 if (ha->acb_version == ACB_SUPPORTED) {
409 ha->ip_config.ipv6_options = le16_to_cpu(init_fw_cb->ipv6_opts);
410 ha->ip_config.ipv6_addl_options =
411 le16_to_cpu(init_fw_cb->ipv6_addtl_opts);
412 }
413
Vikas Chaudhary2a49a782010-04-28 11:37:07 +0530414 /* Save IPv4 Address Info */
Vikas Chaudhary2bab08f2011-07-25 13:48:39 -0500415 memcpy(ha->ip_config.ip_address, init_fw_cb->ipv4_addr,
416 min(sizeof(ha->ip_config.ip_address),
417 sizeof(init_fw_cb->ipv4_addr)));
418 memcpy(ha->ip_config.subnet_mask, init_fw_cb->ipv4_subnet,
419 min(sizeof(ha->ip_config.subnet_mask),
420 sizeof(init_fw_cb->ipv4_subnet)));
421 memcpy(ha->ip_config.gateway, init_fw_cb->ipv4_gw_addr,
422 min(sizeof(ha->ip_config.gateway),
423 sizeof(init_fw_cb->ipv4_gw_addr)));
Vikas Chaudhary2a49a782010-04-28 11:37:07 +0530424
Vikas Chaudhary6ac73e82011-07-25 13:48:49 -0500425 ha->ip_config.ipv4_vlan_tag = be16_to_cpu(init_fw_cb->ipv4_vlan_tag);
426
Vikas Chaudhary2a49a782010-04-28 11:37:07 +0530427 if (is_ipv6_enabled(ha)) {
428 /* Save IPv6 Address */
Vikas Chaudhary2bab08f2011-07-25 13:48:39 -0500429 ha->ip_config.ipv6_link_local_state =
430 le16_to_cpu(init_fw_cb->ipv6_lnk_lcl_addr_state);
431 ha->ip_config.ipv6_addr0_state =
432 le16_to_cpu(init_fw_cb->ipv6_addr0_state);
433 ha->ip_config.ipv6_addr1_state =
434 le16_to_cpu(init_fw_cb->ipv6_addr1_state);
435 ha->ip_config.ipv6_default_router_state =
436 le16_to_cpu(init_fw_cb->ipv6_dflt_rtr_state);
437 ha->ip_config.ipv6_link_local_addr.in6_u.u6_addr8[0] = 0xFE;
438 ha->ip_config.ipv6_link_local_addr.in6_u.u6_addr8[1] = 0x80;
Vikas Chaudhary2a49a782010-04-28 11:37:07 +0530439
Vikas Chaudhary2bab08f2011-07-25 13:48:39 -0500440 memcpy(&ha->ip_config.ipv6_link_local_addr.in6_u.u6_addr8[8],
441 init_fw_cb->ipv6_if_id,
442 min(sizeof(ha->ip_config.ipv6_link_local_addr)/2,
443 sizeof(init_fw_cb->ipv6_if_id)));
444 memcpy(&ha->ip_config.ipv6_addr0, init_fw_cb->ipv6_addr0,
445 min(sizeof(ha->ip_config.ipv6_addr0),
446 sizeof(init_fw_cb->ipv6_addr0)));
447 memcpy(&ha->ip_config.ipv6_addr1, init_fw_cb->ipv6_addr1,
448 min(sizeof(ha->ip_config.ipv6_addr1),
449 sizeof(init_fw_cb->ipv6_addr1)));
450 memcpy(&ha->ip_config.ipv6_default_router_addr,
451 init_fw_cb->ipv6_dflt_rtr_addr,
452 min(sizeof(ha->ip_config.ipv6_default_router_addr),
453 sizeof(init_fw_cb->ipv6_dflt_rtr_addr)));
Vikas Chaudhary6ac73e82011-07-25 13:48:49 -0500454 ha->ip_config.ipv6_vlan_tag =
455 be16_to_cpu(init_fw_cb->ipv6_vlan_tag);
Vikas Chaudhary2ada7fc2011-08-01 03:26:19 -0700456 ha->ip_config.ipv6_port = le16_to_cpu(init_fw_cb->ipv6_port);
Vikas Chaudhary2a49a782010-04-28 11:37:07 +0530457 }
458}
459
Mike Christied00efe32011-07-25 13:48:38 -0500460uint8_t
Vikas Chaudhary2a49a782010-04-28 11:37:07 +0530461qla4xxx_update_local_ifcb(struct scsi_qla_host *ha,
462 uint32_t *mbox_cmd,
463 uint32_t *mbox_sts,
464 struct addr_ctrl_blk *init_fw_cb,
465 dma_addr_t init_fw_cb_dma)
466{
467 if (qla4xxx_get_ifcb(ha, mbox_cmd, mbox_sts, init_fw_cb_dma)
468 != QLA_SUCCESS) {
469 DEBUG2(printk(KERN_WARNING
470 "scsi%ld: %s: Failed to get init_fw_ctrl_blk\n",
471 ha->host_no, __func__));
472 return QLA_ERROR;
473 }
474
475 DEBUG2(qla4xxx_dump_buffer(init_fw_cb, sizeof(struct addr_ctrl_blk)));
476
477 /* Save some info in adapter structure. */
478 ha->acb_version = init_fw_cb->acb_version;
479 ha->firmware_options = le16_to_cpu(init_fw_cb->fw_options);
Vikas Chaudhary2a49a782010-04-28 11:37:07 +0530480 ha->heartbeat_interval = init_fw_cb->hb_interval;
481 memcpy(ha->name_string, init_fw_cb->iscsi_name,
482 min(sizeof(ha->name_string),
483 sizeof(init_fw_cb->iscsi_name)));
Mike Christie13483732011-12-01 21:38:41 -0600484 ha->def_timeout = le16_to_cpu(init_fw_cb->def_timeout);
Vikas Chaudhary2a49a782010-04-28 11:37:07 +0530485 /*memcpy(ha->alias, init_fw_cb->Alias,
486 min(sizeof(ha->alias), sizeof(init_fw_cb->Alias)));*/
487
Vikas Chaudhary2a49a782010-04-28 11:37:07 +0530488 qla4xxx_update_local_ip(ha, init_fw_cb);
489
490 return QLA_SUCCESS;
491}
492
David Somayajuluafaf5a22006-09-19 10:28:00 -0700493/**
494 * qla4xxx_initialize_fw_cb - initializes firmware control block.
495 * @ha: Pointer to host adapter structure.
496 **/
497int qla4xxx_initialize_fw_cb(struct scsi_qla_host * ha)
498{
Vikas Chaudhary2a49a782010-04-28 11:37:07 +0530499 struct addr_ctrl_blk *init_fw_cb;
David Somayajuluafaf5a22006-09-19 10:28:00 -0700500 dma_addr_t init_fw_cb_dma;
501 uint32_t mbox_cmd[MBOX_REG_COUNT];
502 uint32_t mbox_sts[MBOX_REG_COUNT];
503 int status = QLA_ERROR;
504
505 init_fw_cb = dma_alloc_coherent(&ha->pdev->dev,
Vikas Chaudhary2a49a782010-04-28 11:37:07 +0530506 sizeof(struct addr_ctrl_blk),
David Somayajuluafaf5a22006-09-19 10:28:00 -0700507 &init_fw_cb_dma, GFP_KERNEL);
508 if (init_fw_cb == NULL) {
509 DEBUG2(printk("scsi%ld: %s: Unable to alloc init_cb\n",
510 ha->host_no, __func__));
Prasanna Mumbaibeabe7c2010-07-10 14:49:38 +0530511 goto exit_init_fw_cb_no_free;
David Somayajuluafaf5a22006-09-19 10:28:00 -0700512 }
Vikas Chaudhary2a49a782010-04-28 11:37:07 +0530513 memset(init_fw_cb, 0, sizeof(struct addr_ctrl_blk));
David Somayajuluafaf5a22006-09-19 10:28:00 -0700514
515 /* Get Initialize Firmware Control Block. */
516 memset(&mbox_cmd, 0, sizeof(mbox_cmd));
517 memset(&mbox_sts, 0, sizeof(mbox_sts));
David C Somayajuluc0e344c2007-05-23 18:03:27 -0700518
Vikas Chaudhary2a49a782010-04-28 11:37:07 +0530519 if (qla4xxx_get_ifcb(ha, &mbox_cmd[0], &mbox_sts[0], init_fw_cb_dma) !=
David Somayajuluafaf5a22006-09-19 10:28:00 -0700520 QLA_SUCCESS) {
521 dma_free_coherent(&ha->pdev->dev,
Vikas Chaudhary2a49a782010-04-28 11:37:07 +0530522 sizeof(struct addr_ctrl_blk),
David Somayajuluafaf5a22006-09-19 10:28:00 -0700523 init_fw_cb, init_fw_cb_dma);
Vikas Chaudhary2a49a782010-04-28 11:37:07 +0530524 goto exit_init_fw_cb;
David Somayajuluafaf5a22006-09-19 10:28:00 -0700525 }
526
527 /* Initialize request and response queues. */
528 qla4xxx_init_rings(ha);
529
530 /* Fill in the request and response queue information. */
Vikas Chaudhary2a49a782010-04-28 11:37:07 +0530531 init_fw_cb->rqq_consumer_idx = cpu_to_le16(ha->request_out);
532 init_fw_cb->compq_producer_idx = cpu_to_le16(ha->response_in);
533 init_fw_cb->rqq_len = __constant_cpu_to_le16(REQUEST_QUEUE_DEPTH);
534 init_fw_cb->compq_len = __constant_cpu_to_le16(RESPONSE_QUEUE_DEPTH);
535 init_fw_cb->rqq_addr_lo = cpu_to_le32(LSDW(ha->request_dma));
536 init_fw_cb->rqq_addr_hi = cpu_to_le32(MSDW(ha->request_dma));
537 init_fw_cb->compq_addr_lo = cpu_to_le32(LSDW(ha->response_dma));
538 init_fw_cb->compq_addr_hi = cpu_to_le32(MSDW(ha->response_dma));
539 init_fw_cb->shdwreg_addr_lo = cpu_to_le32(LSDW(ha->shadow_regs_dma));
540 init_fw_cb->shdwreg_addr_hi = cpu_to_le32(MSDW(ha->shadow_regs_dma));
David Somayajuluafaf5a22006-09-19 10:28:00 -0700541
542 /* Set up required options. */
Vikas Chaudhary2a49a782010-04-28 11:37:07 +0530543 init_fw_cb->fw_options |=
David Somayajuluafaf5a22006-09-19 10:28:00 -0700544 __constant_cpu_to_le16(FWOPT_SESSION_MODE |
545 FWOPT_INITIATOR_MODE);
Shyam Sundar2657c802010-10-06 22:50:29 -0700546
547 if (is_qla8022(ha))
548 init_fw_cb->fw_options |=
549 __constant_cpu_to_le16(FWOPT_ENABLE_CRBDB);
550
Vikas Chaudhary2a49a782010-04-28 11:37:07 +0530551 init_fw_cb->fw_options &= __constant_cpu_to_le16(~FWOPT_TARGET_MODE);
David Somayajuluafaf5a22006-09-19 10:28:00 -0700552
Prasanna Mumbaid32cee32011-03-21 03:34:35 -0700553 init_fw_cb->add_fw_options = 0;
554 init_fw_cb->add_fw_options |=
Manish Rangankarb3a271a2011-07-25 13:48:53 -0500555 __constant_cpu_to_le16(ADFWOPT_SERIALIZE_TASK_MGMT);
556 init_fw_cb->add_fw_options |=
557 __constant_cpu_to_le16(ADFWOPT_AUTOCONN_DISABLE);
Prasanna Mumbaid32cee32011-03-21 03:34:35 -0700558
Vikas Chaudhary2a49a782010-04-28 11:37:07 +0530559 if (qla4xxx_set_ifcb(ha, &mbox_cmd[0], &mbox_sts[0], init_fw_cb_dma)
560 != QLA_SUCCESS) {
561 DEBUG2(printk(KERN_WARNING
562 "scsi%ld: %s: Failed to set init_fw_ctrl_blk\n",
563 ha->host_no, __func__));
564 goto exit_init_fw_cb;
David Somayajuluafaf5a22006-09-19 10:28:00 -0700565 }
Vikas Chaudhary2a49a782010-04-28 11:37:07 +0530566
567 if (qla4xxx_update_local_ifcb(ha, &mbox_cmd[0], &mbox_sts[0],
568 init_fw_cb, init_fw_cb_dma) != QLA_SUCCESS) {
569 DEBUG2(printk("scsi%ld: %s: Failed to update local ifcb\n",
570 ha->host_no, __func__));
571 goto exit_init_fw_cb;
572 }
573 status = QLA_SUCCESS;
574
575exit_init_fw_cb:
576 dma_free_coherent(&ha->pdev->dev, sizeof(struct addr_ctrl_blk),
577 init_fw_cb, init_fw_cb_dma);
Prasanna Mumbaibeabe7c2010-07-10 14:49:38 +0530578exit_init_fw_cb_no_free:
David Somayajuluafaf5a22006-09-19 10:28:00 -0700579 return status;
580}
581
582/**
583 * qla4xxx_get_dhcp_ip_address - gets HBA ip address via DHCP
584 * @ha: Pointer to host adapter structure.
585 **/
586int qla4xxx_get_dhcp_ip_address(struct scsi_qla_host * ha)
587{
Vikas Chaudhary2a49a782010-04-28 11:37:07 +0530588 struct addr_ctrl_blk *init_fw_cb;
David Somayajuluafaf5a22006-09-19 10:28:00 -0700589 dma_addr_t init_fw_cb_dma;
590 uint32_t mbox_cmd[MBOX_REG_COUNT];
591 uint32_t mbox_sts[MBOX_REG_COUNT];
592
593 init_fw_cb = dma_alloc_coherent(&ha->pdev->dev,
Vikas Chaudhary2a49a782010-04-28 11:37:07 +0530594 sizeof(struct addr_ctrl_blk),
David Somayajuluafaf5a22006-09-19 10:28:00 -0700595 &init_fw_cb_dma, GFP_KERNEL);
596 if (init_fw_cb == NULL) {
597 printk("scsi%ld: %s: Unable to alloc init_cb\n", ha->host_no,
598 __func__);
Prasanna Mumbaibeabe7c2010-07-10 14:49:38 +0530599 return QLA_ERROR;
David Somayajuluafaf5a22006-09-19 10:28:00 -0700600 }
601
602 /* Get Initialize Firmware Control Block. */
Vikas Chaudhary2a49a782010-04-28 11:37:07 +0530603 memset(init_fw_cb, 0, sizeof(struct addr_ctrl_blk));
604 if (qla4xxx_get_ifcb(ha, &mbox_cmd[0], &mbox_sts[0], init_fw_cb_dma) !=
David Somayajuluafaf5a22006-09-19 10:28:00 -0700605 QLA_SUCCESS) {
606 DEBUG2(printk("scsi%ld: %s: Failed to get init_fw_ctrl_blk\n",
607 ha->host_no, __func__));
608 dma_free_coherent(&ha->pdev->dev,
Vikas Chaudhary2a49a782010-04-28 11:37:07 +0530609 sizeof(struct addr_ctrl_blk),
David Somayajuluafaf5a22006-09-19 10:28:00 -0700610 init_fw_cb, init_fw_cb_dma);
611 return QLA_ERROR;
612 }
613
614 /* Save IP Address. */
Vikas Chaudhary2a49a782010-04-28 11:37:07 +0530615 qla4xxx_update_local_ip(ha, init_fw_cb);
616 dma_free_coherent(&ha->pdev->dev, sizeof(struct addr_ctrl_blk),
617 init_fw_cb, init_fw_cb_dma);
David Somayajuluafaf5a22006-09-19 10:28:00 -0700618
619 return QLA_SUCCESS;
620}
621
622/**
623 * qla4xxx_get_firmware_state - gets firmware state of HBA
624 * @ha: Pointer to host adapter structure.
625 **/
626int qla4xxx_get_firmware_state(struct scsi_qla_host * ha)
627{
628 uint32_t mbox_cmd[MBOX_REG_COUNT];
629 uint32_t mbox_sts[MBOX_REG_COUNT];
630
631 /* Get firmware version */
632 memset(&mbox_cmd, 0, sizeof(mbox_cmd));
633 memset(&mbox_sts, 0, sizeof(mbox_sts));
David C Somayajuluc0e344c2007-05-23 18:03:27 -0700634
David Somayajuluafaf5a22006-09-19 10:28:00 -0700635 mbox_cmd[0] = MBOX_CMD_GET_FW_STATE;
David C Somayajuluc0e344c2007-05-23 18:03:27 -0700636
637 if (qla4xxx_mailbox_command(ha, MBOX_REG_COUNT, 4, &mbox_cmd[0], &mbox_sts[0]) !=
David Somayajuluafaf5a22006-09-19 10:28:00 -0700638 QLA_SUCCESS) {
639 DEBUG2(printk("scsi%ld: %s: MBOX_CMD_GET_FW_STATE failed w/ "
640 "status %04X\n", ha->host_no, __func__,
641 mbox_sts[0]));
642 return QLA_ERROR;
643 }
644 ha->firmware_state = mbox_sts[1];
645 ha->board_id = mbox_sts[2];
646 ha->addl_fw_state = mbox_sts[3];
647 DEBUG2(printk("scsi%ld: %s firmware_state=0x%x\n",
648 ha->host_no, __func__, ha->firmware_state);)
649
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +0530650 return QLA_SUCCESS;
David Somayajuluafaf5a22006-09-19 10:28:00 -0700651}
652
653/**
654 * qla4xxx_get_firmware_status - retrieves firmware status
655 * @ha: Pointer to host adapter structure.
656 **/
657int qla4xxx_get_firmware_status(struct scsi_qla_host * ha)
658{
659 uint32_t mbox_cmd[MBOX_REG_COUNT];
660 uint32_t mbox_sts[MBOX_REG_COUNT];
661
662 /* Get firmware version */
663 memset(&mbox_cmd, 0, sizeof(mbox_cmd));
664 memset(&mbox_sts, 0, sizeof(mbox_sts));
David C Somayajuluc0e344c2007-05-23 18:03:27 -0700665
David Somayajuluafaf5a22006-09-19 10:28:00 -0700666 mbox_cmd[0] = MBOX_CMD_GET_FW_STATUS;
David C Somayajuluc0e344c2007-05-23 18:03:27 -0700667
668 if (qla4xxx_mailbox_command(ha, MBOX_REG_COUNT, 3, &mbox_cmd[0], &mbox_sts[0]) !=
David Somayajuluafaf5a22006-09-19 10:28:00 -0700669 QLA_SUCCESS) {
670 DEBUG2(printk("scsi%ld: %s: MBOX_CMD_GET_FW_STATUS failed w/ "
671 "status %04X\n", ha->host_no, __func__,
672 mbox_sts[0]));
673 return QLA_ERROR;
674 }
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +0530675
Vikas Chaudhary3573bfb2012-02-27 03:08:57 -0800676 ql4_printk(KERN_INFO, ha, "%ld firmware IOCBs available (%d).\n",
Vikas Chaudharyf581a3f2010-10-06 22:47:48 -0700677 ha->host_no, mbox_sts[2]);
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +0530678
David Somayajuluafaf5a22006-09-19 10:28:00 -0700679 return QLA_SUCCESS;
680}
681
682/**
683 * qla4xxx_get_fwddb_entry - retrieves firmware ddb entry
684 * @ha: Pointer to host adapter structure.
685 * @fw_ddb_index: Firmware's device database index
686 * @fw_ddb_entry: Pointer to firmware's device database entry structure
687 * @num_valid_ddb_entries: Pointer to number of valid ddb entries
688 * @next_ddb_index: Pointer to next valid device database index
689 * @fw_ddb_device_state: Pointer to device state
690 **/
691int qla4xxx_get_fwddb_entry(struct scsi_qla_host *ha,
692 uint16_t fw_ddb_index,
693 struct dev_db_entry *fw_ddb_entry,
694 dma_addr_t fw_ddb_entry_dma,
695 uint32_t *num_valid_ddb_entries,
696 uint32_t *next_ddb_index,
697 uint32_t *fw_ddb_device_state,
698 uint32_t *conn_err_detail,
699 uint16_t *tcp_source_port_num,
700 uint16_t *connection_id)
701{
702 int status = QLA_ERROR;
Vikas Chaudhary2a49a782010-04-28 11:37:07 +0530703 uint16_t options;
David Somayajuluafaf5a22006-09-19 10:28:00 -0700704 uint32_t mbox_cmd[MBOX_REG_COUNT];
705 uint32_t mbox_sts[MBOX_REG_COUNT];
706
707 /* Make sure the device index is valid */
708 if (fw_ddb_index >= MAX_DDB_ENTRIES) {
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +0530709 DEBUG2(printk("scsi%ld: %s: ddb [%d] out of range.\n",
David Somayajuluafaf5a22006-09-19 10:28:00 -0700710 ha->host_no, __func__, fw_ddb_index));
711 goto exit_get_fwddb;
712 }
713 memset(&mbox_cmd, 0, sizeof(mbox_cmd));
714 memset(&mbox_sts, 0, sizeof(mbox_sts));
Lalit Chandivade981c9822012-02-13 18:30:41 +0530715 if (fw_ddb_entry)
716 memset(fw_ddb_entry, 0, sizeof(struct dev_db_entry));
David C Somayajuluc0e344c2007-05-23 18:03:27 -0700717
David Somayajuluafaf5a22006-09-19 10:28:00 -0700718 mbox_cmd[0] = MBOX_CMD_GET_DATABASE_ENTRY;
719 mbox_cmd[1] = (uint32_t) fw_ddb_index;
720 mbox_cmd[2] = LSDW(fw_ddb_entry_dma);
721 mbox_cmd[3] = MSDW(fw_ddb_entry_dma);
David C Somayajuluc0e344c2007-05-23 18:03:27 -0700722 mbox_cmd[4] = sizeof(struct dev_db_entry);
723
724 if (qla4xxx_mailbox_command(ha, MBOX_REG_COUNT, 7, &mbox_cmd[0], &mbox_sts[0]) ==
David Somayajuluafaf5a22006-09-19 10:28:00 -0700725 QLA_ERROR) {
726 DEBUG2(printk("scsi%ld: %s: MBOX_CMD_GET_DATABASE_ENTRY failed"
727 " with status 0x%04X\n", ha->host_no, __func__,
728 mbox_sts[0]));
729 goto exit_get_fwddb;
730 }
731 if (fw_ddb_index != mbox_sts[1]) {
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +0530732 DEBUG2(printk("scsi%ld: %s: ddb mismatch [%d] != [%d].\n",
David Somayajuluafaf5a22006-09-19 10:28:00 -0700733 ha->host_no, __func__, fw_ddb_index,
734 mbox_sts[1]));
735 goto exit_get_fwddb;
736 }
737 if (fw_ddb_entry) {
Vikas Chaudhary2a49a782010-04-28 11:37:07 +0530738 options = le16_to_cpu(fw_ddb_entry->options);
739 if (options & DDB_OPT_IPV6_DEVICE) {
Vikas Chaudharyc2660df2010-07-10 14:51:02 +0530740 ql4_printk(KERN_INFO, ha, "%s: DDB[%d] MB0 %04x Tot %d "
Vikas Chaudhary2a49a782010-04-28 11:37:07 +0530741 "Next %d State %04x ConnErr %08x %pI6 "
742 ":%04d \"%s\"\n", __func__, fw_ddb_index,
743 mbox_sts[0], mbox_sts[2], mbox_sts[3],
744 mbox_sts[4], mbox_sts[5],
745 fw_ddb_entry->ip_addr,
746 le16_to_cpu(fw_ddb_entry->port),
747 fw_ddb_entry->iscsi_name);
748 } else {
Vikas Chaudharyc2660df2010-07-10 14:51:02 +0530749 ql4_printk(KERN_INFO, ha, "%s: DDB[%d] MB0 %04x Tot %d "
Vikas Chaudhary2a49a782010-04-28 11:37:07 +0530750 "Next %d State %04x ConnErr %08x %pI4 "
751 ":%04d \"%s\"\n", __func__, fw_ddb_index,
752 mbox_sts[0], mbox_sts[2], mbox_sts[3],
753 mbox_sts[4], mbox_sts[5],
754 fw_ddb_entry->ip_addr,
755 le16_to_cpu(fw_ddb_entry->port),
756 fw_ddb_entry->iscsi_name);
757 }
David Somayajuluafaf5a22006-09-19 10:28:00 -0700758 }
759 if (num_valid_ddb_entries)
760 *num_valid_ddb_entries = mbox_sts[2];
761 if (next_ddb_index)
762 *next_ddb_index = mbox_sts[3];
763 if (fw_ddb_device_state)
764 *fw_ddb_device_state = mbox_sts[4];
765
766 /*
767 * RA: This mailbox has been changed to pass connection error and
768 * details. Its true for ISP4010 as per Version E - Not sure when it
769 * was changed. Get the time2wait from the fw_dd_entry field :
770 * default_time2wait which we call it as minTime2Wait DEV_DB_ENTRY
771 * struct.
772 */
773 if (conn_err_detail)
774 *conn_err_detail = mbox_sts[5];
775 if (tcp_source_port_num)
Randy Dunlap14823382010-04-22 11:02:14 -0700776 *tcp_source_port_num = (uint16_t) (mbox_sts[6] >> 16);
David Somayajuluafaf5a22006-09-19 10:28:00 -0700777 if (connection_id)
778 *connection_id = (uint16_t) mbox_sts[6] & 0x00FF;
779 status = QLA_SUCCESS;
780
781exit_get_fwddb:
782 return status;
783}
784
Manish Rangankarb3a271a2011-07-25 13:48:53 -0500785int qla4xxx_conn_open(struct scsi_qla_host *ha, uint16_t fw_ddb_index)
786{
787 uint32_t mbox_cmd[MBOX_REG_COUNT];
788 uint32_t mbox_sts[MBOX_REG_COUNT];
789 int status;
790
791 memset(&mbox_cmd, 0, sizeof(mbox_cmd));
792 memset(&mbox_sts, 0, sizeof(mbox_sts));
793
794 mbox_cmd[0] = MBOX_CMD_CONN_OPEN;
795 mbox_cmd[1] = fw_ddb_index;
796
797 status = qla4xxx_mailbox_command(ha, MBOX_REG_COUNT, 2, &mbox_cmd[0],
798 &mbox_sts[0]);
799 DEBUG2(ql4_printk(KERN_INFO, ha,
800 "%s: status = %d mbx0 = 0x%x mbx1 = 0x%x\n",
801 __func__, status, mbox_sts[0], mbox_sts[1]));
802 return status;
803}
804
David Somayajuluafaf5a22006-09-19 10:28:00 -0700805/**
806 * qla4xxx_set_fwddb_entry - sets a ddb entry.
807 * @ha: Pointer to host adapter structure.
808 * @fw_ddb_index: Firmware's device database index
Manish Rangankarb3a271a2011-07-25 13:48:53 -0500809 * @fw_ddb_entry_dma: dma address of ddb entry
810 * @mbx_sts: mailbox 0 to be returned or NULL
David Somayajuluafaf5a22006-09-19 10:28:00 -0700811 *
812 * This routine initializes or updates the adapter's device database
Manish Rangankarb3a271a2011-07-25 13:48:53 -0500813 * entry for the specified device.
David Somayajuluafaf5a22006-09-19 10:28:00 -0700814 **/
815int qla4xxx_set_ddb_entry(struct scsi_qla_host * ha, uint16_t fw_ddb_index,
Manish Rangankarb3a271a2011-07-25 13:48:53 -0500816 dma_addr_t fw_ddb_entry_dma, uint32_t *mbx_sts)
David Somayajuluafaf5a22006-09-19 10:28:00 -0700817{
818 uint32_t mbox_cmd[MBOX_REG_COUNT];
819 uint32_t mbox_sts[MBOX_REG_COUNT];
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +0530820 int status;
David Somayajuluafaf5a22006-09-19 10:28:00 -0700821
822 /* Do not wait for completion. The firmware will send us an
823 * ASTS_DATABASE_CHANGED (0x8014) to notify us of the login status.
824 */
825 memset(&mbox_cmd, 0, sizeof(mbox_cmd));
826 memset(&mbox_sts, 0, sizeof(mbox_sts));
827
828 mbox_cmd[0] = MBOX_CMD_SET_DATABASE_ENTRY;
829 mbox_cmd[1] = (uint32_t) fw_ddb_index;
830 mbox_cmd[2] = LSDW(fw_ddb_entry_dma);
831 mbox_cmd[3] = MSDW(fw_ddb_entry_dma);
David C Somayajuluc0e344c2007-05-23 18:03:27 -0700832 mbox_cmd[4] = sizeof(struct dev_db_entry);
833
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +0530834 status = qla4xxx_mailbox_command(ha, MBOX_REG_COUNT, 5, &mbox_cmd[0],
Manish Rangankarb3a271a2011-07-25 13:48:53 -0500835 &mbox_sts[0]);
836 if (mbx_sts)
837 *mbx_sts = mbox_sts[0];
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +0530838 DEBUG2(printk("scsi%ld: %s: status=%d mbx0=0x%x mbx4=0x%x\n",
839 ha->host_no, __func__, status, mbox_sts[0], mbox_sts[4]);)
840
841 return status;
David Somayajuluafaf5a22006-09-19 10:28:00 -0700842}
843
Manish Rangankarb3a271a2011-07-25 13:48:53 -0500844int qla4xxx_session_logout_ddb(struct scsi_qla_host *ha,
845 struct ddb_entry *ddb_entry, int options)
846{
847 int status;
848 uint32_t mbox_cmd[MBOX_REG_COUNT];
849 uint32_t mbox_sts[MBOX_REG_COUNT];
850
851 memset(&mbox_cmd, 0, sizeof(mbox_cmd));
852 memset(&mbox_sts, 0, sizeof(mbox_sts));
853
854 mbox_cmd[0] = MBOX_CMD_CONN_CLOSE_SESS_LOGOUT;
855 mbox_cmd[1] = ddb_entry->fw_ddb_index;
856 mbox_cmd[3] = options;
857
858 status = qla4xxx_mailbox_command(ha, MBOX_REG_COUNT, 2, &mbox_cmd[0],
859 &mbox_sts[0]);
860 if (status != QLA_SUCCESS) {
861 DEBUG2(ql4_printk(KERN_INFO, ha,
862 "%s: MBOX_CMD_CONN_CLOSE_SESS_LOGOUT "
863 "failed sts %04X %04X", __func__,
864 mbox_sts[0], mbox_sts[1]));
865 }
866
867 return status;
868}
869
David Somayajuluafaf5a22006-09-19 10:28:00 -0700870/**
871 * qla4xxx_get_crash_record - retrieves crash record.
872 * @ha: Pointer to host adapter structure.
873 *
874 * This routine retrieves a crash record from the QLA4010 after an 8002h aen.
875 **/
876void qla4xxx_get_crash_record(struct scsi_qla_host * ha)
877{
878 uint32_t mbox_cmd[MBOX_REG_COUNT];
879 uint32_t mbox_sts[MBOX_REG_COUNT];
880 struct crash_record *crash_record = NULL;
881 dma_addr_t crash_record_dma = 0;
882 uint32_t crash_record_size = 0;
David C Somayajuluc0e344c2007-05-23 18:03:27 -0700883
David Somayajuluafaf5a22006-09-19 10:28:00 -0700884 memset(&mbox_cmd, 0, sizeof(mbox_cmd));
885 memset(&mbox_sts, 0, sizeof(mbox_cmd));
886
887 /* Get size of crash record. */
888 mbox_cmd[0] = MBOX_CMD_GET_CRASH_RECORD;
David C Somayajuluc0e344c2007-05-23 18:03:27 -0700889
890 if (qla4xxx_mailbox_command(ha, MBOX_REG_COUNT, 5, &mbox_cmd[0], &mbox_sts[0]) !=
David Somayajuluafaf5a22006-09-19 10:28:00 -0700891 QLA_SUCCESS) {
892 DEBUG2(printk("scsi%ld: %s: ERROR: Unable to retrieve size!\n",
893 ha->host_no, __func__));
894 goto exit_get_crash_record;
895 }
896 crash_record_size = mbox_sts[4];
897 if (crash_record_size == 0) {
898 DEBUG2(printk("scsi%ld: %s: ERROR: Crash record size is 0!\n",
899 ha->host_no, __func__));
900 goto exit_get_crash_record;
901 }
902
903 /* Alloc Memory for Crash Record. */
904 crash_record = dma_alloc_coherent(&ha->pdev->dev, crash_record_size,
905 &crash_record_dma, GFP_KERNEL);
906 if (crash_record == NULL)
907 goto exit_get_crash_record;
908
909 /* Get Crash Record. */
David C Somayajuluc0e344c2007-05-23 18:03:27 -0700910 memset(&mbox_cmd, 0, sizeof(mbox_cmd));
911 memset(&mbox_sts, 0, sizeof(mbox_cmd));
912
David Somayajuluafaf5a22006-09-19 10:28:00 -0700913 mbox_cmd[0] = MBOX_CMD_GET_CRASH_RECORD;
914 mbox_cmd[2] = LSDW(crash_record_dma);
915 mbox_cmd[3] = MSDW(crash_record_dma);
916 mbox_cmd[4] = crash_record_size;
David C Somayajuluc0e344c2007-05-23 18:03:27 -0700917
918 if (qla4xxx_mailbox_command(ha, MBOX_REG_COUNT, 5, &mbox_cmd[0], &mbox_sts[0]) !=
David Somayajuluafaf5a22006-09-19 10:28:00 -0700919 QLA_SUCCESS)
920 goto exit_get_crash_record;
921
922 /* Dump Crash Record. */
923
924exit_get_crash_record:
925 if (crash_record)
926 dma_free_coherent(&ha->pdev->dev, crash_record_size,
927 crash_record, crash_record_dma);
928}
929
930/**
931 * qla4xxx_get_conn_event_log - retrieves connection event log
932 * @ha: Pointer to host adapter structure.
933 **/
934void qla4xxx_get_conn_event_log(struct scsi_qla_host * ha)
935{
936 uint32_t mbox_cmd[MBOX_REG_COUNT];
937 uint32_t mbox_sts[MBOX_REG_COUNT];
938 struct conn_event_log_entry *event_log = NULL;
939 dma_addr_t event_log_dma = 0;
940 uint32_t event_log_size = 0;
941 uint32_t num_valid_entries;
942 uint32_t oldest_entry = 0;
943 uint32_t max_event_log_entries;
944 uint8_t i;
945
David Somayajuluafaf5a22006-09-19 10:28:00 -0700946 memset(&mbox_cmd, 0, sizeof(mbox_cmd));
947 memset(&mbox_sts, 0, sizeof(mbox_cmd));
948
949 /* Get size of crash record. */
950 mbox_cmd[0] = MBOX_CMD_GET_CONN_EVENT_LOG;
David C Somayajuluc0e344c2007-05-23 18:03:27 -0700951
952 if (qla4xxx_mailbox_command(ha, MBOX_REG_COUNT, 5, &mbox_cmd[0], &mbox_sts[0]) !=
David Somayajuluafaf5a22006-09-19 10:28:00 -0700953 QLA_SUCCESS)
954 goto exit_get_event_log;
955
956 event_log_size = mbox_sts[4];
957 if (event_log_size == 0)
958 goto exit_get_event_log;
959
960 /* Alloc Memory for Crash Record. */
961 event_log = dma_alloc_coherent(&ha->pdev->dev, event_log_size,
962 &event_log_dma, GFP_KERNEL);
963 if (event_log == NULL)
964 goto exit_get_event_log;
965
966 /* Get Crash Record. */
David C Somayajuluc0e344c2007-05-23 18:03:27 -0700967 memset(&mbox_cmd, 0, sizeof(mbox_cmd));
968 memset(&mbox_sts, 0, sizeof(mbox_cmd));
969
David Somayajuluafaf5a22006-09-19 10:28:00 -0700970 mbox_cmd[0] = MBOX_CMD_GET_CONN_EVENT_LOG;
971 mbox_cmd[2] = LSDW(event_log_dma);
972 mbox_cmd[3] = MSDW(event_log_dma);
David C Somayajuluc0e344c2007-05-23 18:03:27 -0700973
974 if (qla4xxx_mailbox_command(ha, MBOX_REG_COUNT, 5, &mbox_cmd[0], &mbox_sts[0]) !=
David Somayajuluafaf5a22006-09-19 10:28:00 -0700975 QLA_SUCCESS) {
976 DEBUG2(printk("scsi%ld: %s: ERROR: Unable to retrieve event "
977 "log!\n", ha->host_no, __func__));
978 goto exit_get_event_log;
979 }
980
981 /* Dump Event Log. */
982 num_valid_entries = mbox_sts[1];
983
984 max_event_log_entries = event_log_size /
985 sizeof(struct conn_event_log_entry);
986
987 if (num_valid_entries > max_event_log_entries)
988 oldest_entry = num_valid_entries % max_event_log_entries;
989
990 DEBUG3(printk("scsi%ld: Connection Event Log Dump (%d entries):\n",
991 ha->host_no, num_valid_entries));
992
Andrew Vasquez11010fe2006-10-06 09:54:59 -0700993 if (ql4xextended_error_logging == 3) {
David Somayajuluafaf5a22006-09-19 10:28:00 -0700994 if (oldest_entry == 0) {
995 /* Circular Buffer has not wrapped around */
996 for (i=0; i < num_valid_entries; i++) {
997 qla4xxx_dump_buffer((uint8_t *)event_log+
998 (i*sizeof(*event_log)),
999 sizeof(*event_log));
1000 }
1001 }
1002 else {
1003 /* Circular Buffer has wrapped around -
1004 * display accordingly*/
1005 for (i=oldest_entry; i < max_event_log_entries; i++) {
1006 qla4xxx_dump_buffer((uint8_t *)event_log+
1007 (i*sizeof(*event_log)),
1008 sizeof(*event_log));
1009 }
1010 for (i=0; i < oldest_entry; i++) {
1011 qla4xxx_dump_buffer((uint8_t *)event_log+
1012 (i*sizeof(*event_log)),
1013 sizeof(*event_log));
1014 }
1015 }
1016 }
1017
1018exit_get_event_log:
1019 if (event_log)
1020 dma_free_coherent(&ha->pdev->dev, event_log_size, event_log,
1021 event_log_dma);
1022}
1023
1024/**
Vikas Chaudhary09a0f712010-04-28 11:42:24 +05301025 * qla4xxx_abort_task - issues Abort Task
1026 * @ha: Pointer to host adapter structure.
1027 * @srb: Pointer to srb entry
1028 *
1029 * This routine performs a LUN RESET on the specified target/lun.
1030 * The caller must ensure that the ddb_entry and lun_entry pointers
1031 * are valid before calling this routine.
1032 **/
1033int qla4xxx_abort_task(struct scsi_qla_host *ha, struct srb *srb)
1034{
1035 uint32_t mbox_cmd[MBOX_REG_COUNT];
1036 uint32_t mbox_sts[MBOX_REG_COUNT];
1037 struct scsi_cmnd *cmd = srb->cmd;
1038 int status = QLA_SUCCESS;
1039 unsigned long flags = 0;
1040 uint32_t index;
1041
1042 /*
1043 * Send abort task command to ISP, so that the ISP will return
1044 * request with ABORT status
1045 */
1046 memset(&mbox_cmd, 0, sizeof(mbox_cmd));
1047 memset(&mbox_sts, 0, sizeof(mbox_sts));
1048
1049 spin_lock_irqsave(&ha->hardware_lock, flags);
1050 index = (unsigned long)(unsigned char *)cmd->host_scribble;
1051 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1052
1053 /* Firmware already posted completion on response queue */
1054 if (index == MAX_SRBS)
1055 return status;
1056
1057 mbox_cmd[0] = MBOX_CMD_ABORT_TASK;
Karen Higgins6790d4f2010-12-02 22:12:22 -08001058 mbox_cmd[1] = srb->ddb->fw_ddb_index;
Vikas Chaudhary09a0f712010-04-28 11:42:24 +05301059 mbox_cmd[2] = index;
1060 /* Immediate Command Enable */
1061 mbox_cmd[5] = 0x01;
1062
1063 qla4xxx_mailbox_command(ha, MBOX_REG_COUNT, 5, &mbox_cmd[0],
1064 &mbox_sts[0]);
1065 if (mbox_sts[0] != MBOX_STS_COMMAND_COMPLETE) {
1066 status = QLA_ERROR;
1067
1068 DEBUG2(printk(KERN_WARNING "scsi%ld:%d:%d: abort task FAILED: "
1069 "mbx0=%04X, mb1=%04X, mb2=%04X, mb3=%04X, mb4=%04X\n",
1070 ha->host_no, cmd->device->id, cmd->device->lun, mbox_sts[0],
1071 mbox_sts[1], mbox_sts[2], mbox_sts[3], mbox_sts[4]));
1072 }
1073
1074 return status;
1075}
1076
1077/**
David Somayajuluafaf5a22006-09-19 10:28:00 -07001078 * qla4xxx_reset_lun - issues LUN Reset
1079 * @ha: Pointer to host adapter structure.
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05301080 * @ddb_entry: Pointer to device database entry
1081 * @lun: lun number
David Somayajuluafaf5a22006-09-19 10:28:00 -07001082 *
1083 * This routine performs a LUN RESET on the specified target/lun.
1084 * The caller must ensure that the ddb_entry and lun_entry pointers
1085 * are valid before calling this routine.
1086 **/
1087int qla4xxx_reset_lun(struct scsi_qla_host * ha, struct ddb_entry * ddb_entry,
1088 int lun)
1089{
1090 uint32_t mbox_cmd[MBOX_REG_COUNT];
1091 uint32_t mbox_sts[MBOX_REG_COUNT];
1092 int status = QLA_SUCCESS;
1093
1094 DEBUG2(printk("scsi%ld:%d:%d: lun reset issued\n", ha->host_no,
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05301095 ddb_entry->fw_ddb_index, lun));
David Somayajuluafaf5a22006-09-19 10:28:00 -07001096
1097 /*
1098 * Send lun reset command to ISP, so that the ISP will return all
1099 * outstanding requests with RESET status
1100 */
1101 memset(&mbox_cmd, 0, sizeof(mbox_cmd));
1102 memset(&mbox_sts, 0, sizeof(mbox_sts));
David C Somayajuluc0e344c2007-05-23 18:03:27 -07001103
David Somayajuluafaf5a22006-09-19 10:28:00 -07001104 mbox_cmd[0] = MBOX_CMD_LUN_RESET;
1105 mbox_cmd[1] = ddb_entry->fw_ddb_index;
1106 mbox_cmd[2] = lun << 8;
1107 mbox_cmd[5] = 0x01; /* Immediate Command Enable */
David C Somayajuluc0e344c2007-05-23 18:03:27 -07001108
1109 qla4xxx_mailbox_command(ha, MBOX_REG_COUNT, 1, &mbox_cmd[0], &mbox_sts[0]);
David Somayajuluafaf5a22006-09-19 10:28:00 -07001110 if (mbox_sts[0] != MBOX_STS_COMMAND_COMPLETE &&
1111 mbox_sts[0] != MBOX_STS_COMMAND_ERROR)
1112 status = QLA_ERROR;
1113
1114 return status;
1115}
1116
Mike Christiece545032008-02-29 18:25:20 -06001117/**
1118 * qla4xxx_reset_target - issues target Reset
1119 * @ha: Pointer to host adapter structure.
1120 * @db_entry: Pointer to device database entry
1121 * @un_entry: Pointer to lun entry structure
1122 *
1123 * This routine performs a TARGET RESET on the specified target.
1124 * The caller must ensure that the ddb_entry pointers
1125 * are valid before calling this routine.
1126 **/
1127int qla4xxx_reset_target(struct scsi_qla_host *ha,
1128 struct ddb_entry *ddb_entry)
1129{
1130 uint32_t mbox_cmd[MBOX_REG_COUNT];
1131 uint32_t mbox_sts[MBOX_REG_COUNT];
1132 int status = QLA_SUCCESS;
1133
1134 DEBUG2(printk("scsi%ld:%d: target reset issued\n", ha->host_no,
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05301135 ddb_entry->fw_ddb_index));
Mike Christiece545032008-02-29 18:25:20 -06001136
1137 /*
1138 * Send target reset command to ISP, so that the ISP will return all
1139 * outstanding requests with RESET status
1140 */
1141 memset(&mbox_cmd, 0, sizeof(mbox_cmd));
1142 memset(&mbox_sts, 0, sizeof(mbox_sts));
1143
1144 mbox_cmd[0] = MBOX_CMD_TARGET_WARM_RESET;
1145 mbox_cmd[1] = ddb_entry->fw_ddb_index;
1146 mbox_cmd[5] = 0x01; /* Immediate Command Enable */
1147
1148 qla4xxx_mailbox_command(ha, MBOX_REG_COUNT, 1, &mbox_cmd[0],
1149 &mbox_sts[0]);
1150 if (mbox_sts[0] != MBOX_STS_COMMAND_COMPLETE &&
1151 mbox_sts[0] != MBOX_STS_COMMAND_ERROR)
1152 status = QLA_ERROR;
1153
1154 return status;
1155}
David Somayajuluafaf5a22006-09-19 10:28:00 -07001156
1157int qla4xxx_get_flash(struct scsi_qla_host * ha, dma_addr_t dma_addr,
1158 uint32_t offset, uint32_t len)
1159{
1160 uint32_t mbox_cmd[MBOX_REG_COUNT];
1161 uint32_t mbox_sts[MBOX_REG_COUNT];
1162
1163 memset(&mbox_cmd, 0, sizeof(mbox_cmd));
1164 memset(&mbox_sts, 0, sizeof(mbox_sts));
David C Somayajuluc0e344c2007-05-23 18:03:27 -07001165
David Somayajuluafaf5a22006-09-19 10:28:00 -07001166 mbox_cmd[0] = MBOX_CMD_READ_FLASH;
1167 mbox_cmd[1] = LSDW(dma_addr);
1168 mbox_cmd[2] = MSDW(dma_addr);
1169 mbox_cmd[3] = offset;
1170 mbox_cmd[4] = len;
David C Somayajuluc0e344c2007-05-23 18:03:27 -07001171
1172 if (qla4xxx_mailbox_command(ha, MBOX_REG_COUNT, 2, &mbox_cmd[0], &mbox_sts[0]) !=
David Somayajuluafaf5a22006-09-19 10:28:00 -07001173 QLA_SUCCESS) {
1174 DEBUG2(printk("scsi%ld: %s: MBOX_CMD_READ_FLASH, failed w/ "
1175 "status %04X %04X, offset %08x, len %08x\n", ha->host_no,
1176 __func__, mbox_sts[0], mbox_sts[1], offset, len));
1177 return QLA_ERROR;
1178 }
1179 return QLA_SUCCESS;
1180}
1181
1182/**
Harish Zunjarrao7ad633c2011-05-17 23:17:11 -07001183 * qla4xxx_about_firmware - gets FW, iscsi draft and boot loader version
David Somayajuluafaf5a22006-09-19 10:28:00 -07001184 * @ha: Pointer to host adapter structure.
1185 *
Harish Zunjarrao7ad633c2011-05-17 23:17:11 -07001186 * Retrieves the FW version, iSCSI draft version & bootloader version of HBA.
1187 * Mailboxes 2 & 3 may hold an address for data. Make sure that we write 0 to
1188 * those mailboxes, if unused.
David Somayajuluafaf5a22006-09-19 10:28:00 -07001189 **/
Harish Zunjarrao7ad633c2011-05-17 23:17:11 -07001190int qla4xxx_about_firmware(struct scsi_qla_host *ha)
David Somayajuluafaf5a22006-09-19 10:28:00 -07001191{
Harish Zunjarrao7ad633c2011-05-17 23:17:11 -07001192 struct about_fw_info *about_fw = NULL;
1193 dma_addr_t about_fw_dma;
David Somayajuluafaf5a22006-09-19 10:28:00 -07001194 uint32_t mbox_cmd[MBOX_REG_COUNT];
1195 uint32_t mbox_sts[MBOX_REG_COUNT];
Harish Zunjarrao7ad633c2011-05-17 23:17:11 -07001196 int status = QLA_ERROR;
David Somayajuluafaf5a22006-09-19 10:28:00 -07001197
Harish Zunjarrao7ad633c2011-05-17 23:17:11 -07001198 about_fw = dma_alloc_coherent(&ha->pdev->dev,
1199 sizeof(struct about_fw_info),
1200 &about_fw_dma, GFP_KERNEL);
1201 if (!about_fw) {
1202 DEBUG2(ql4_printk(KERN_ERR, ha, "%s: Unable to alloc memory "
1203 "for about_fw\n", __func__));
1204 return status;
1205 }
1206
1207 memset(about_fw, 0, sizeof(struct about_fw_info));
David Somayajuluafaf5a22006-09-19 10:28:00 -07001208 memset(&mbox_cmd, 0, sizeof(mbox_cmd));
1209 memset(&mbox_sts, 0, sizeof(mbox_sts));
David C Somayajuluc0e344c2007-05-23 18:03:27 -07001210
David Somayajuluafaf5a22006-09-19 10:28:00 -07001211 mbox_cmd[0] = MBOX_CMD_ABOUT_FW;
Harish Zunjarrao7ad633c2011-05-17 23:17:11 -07001212 mbox_cmd[2] = LSDW(about_fw_dma);
1213 mbox_cmd[3] = MSDW(about_fw_dma);
1214 mbox_cmd[4] = sizeof(struct about_fw_info);
David C Somayajuluc0e344c2007-05-23 18:03:27 -07001215
Harish Zunjarrao7ad633c2011-05-17 23:17:11 -07001216 status = qla4xxx_mailbox_command(ha, MBOX_REG_COUNT, MBOX_REG_COUNT,
1217 &mbox_cmd[0], &mbox_sts[0]);
1218 if (status != QLA_SUCCESS) {
1219 DEBUG2(ql4_printk(KERN_WARNING, ha, "%s: MBOX_CMD_ABOUT_FW "
1220 "failed w/ status %04X\n", __func__,
1221 mbox_sts[0]));
1222 goto exit_about_fw;
David Somayajuluafaf5a22006-09-19 10:28:00 -07001223 }
1224
Harish Zunjarrao7ad633c2011-05-17 23:17:11 -07001225 /* Save version information. */
1226 ha->firmware_version[0] = le16_to_cpu(about_fw->fw_major);
1227 ha->firmware_version[1] = le16_to_cpu(about_fw->fw_minor);
1228 ha->patch_number = le16_to_cpu(about_fw->fw_patch);
1229 ha->build_number = le16_to_cpu(about_fw->fw_build);
1230 ha->iscsi_major = le16_to_cpu(about_fw->iscsi_major);
1231 ha->iscsi_minor = le16_to_cpu(about_fw->iscsi_minor);
1232 ha->bootload_major = le16_to_cpu(about_fw->bootload_major);
1233 ha->bootload_minor = le16_to_cpu(about_fw->bootload_minor);
1234 ha->bootload_patch = le16_to_cpu(about_fw->bootload_patch);
1235 ha->bootload_build = le16_to_cpu(about_fw->bootload_build);
1236 status = QLA_SUCCESS;
David Somayajuluafaf5a22006-09-19 10:28:00 -07001237
Harish Zunjarrao7ad633c2011-05-17 23:17:11 -07001238exit_about_fw:
1239 dma_free_coherent(&ha->pdev->dev, sizeof(struct about_fw_info),
1240 about_fw, about_fw_dma);
1241 return status;
David Somayajuluafaf5a22006-09-19 10:28:00 -07001242}
1243
Manish Rangankarb3a271a2011-07-25 13:48:53 -05001244static int qla4xxx_get_default_ddb(struct scsi_qla_host *ha, uint32_t options,
Adrian Bunk47975472007-04-26 00:35:16 -07001245 dma_addr_t dma_addr)
David Somayajuluafaf5a22006-09-19 10:28:00 -07001246{
1247 uint32_t mbox_cmd[MBOX_REG_COUNT];
1248 uint32_t mbox_sts[MBOX_REG_COUNT];
1249
1250 memset(&mbox_cmd, 0, sizeof(mbox_cmd));
1251 memset(&mbox_sts, 0, sizeof(mbox_sts));
1252
1253 mbox_cmd[0] = MBOX_CMD_GET_DATABASE_ENTRY_DEFAULTS;
Manish Rangankarb3a271a2011-07-25 13:48:53 -05001254 mbox_cmd[1] = options;
David Somayajuluafaf5a22006-09-19 10:28:00 -07001255 mbox_cmd[2] = LSDW(dma_addr);
1256 mbox_cmd[3] = MSDW(dma_addr);
1257
David C Somayajuluc0e344c2007-05-23 18:03:27 -07001258 if (qla4xxx_mailbox_command(ha, MBOX_REG_COUNT, 1, &mbox_cmd[0], &mbox_sts[0]) !=
David Somayajuluafaf5a22006-09-19 10:28:00 -07001259 QLA_SUCCESS) {
1260 DEBUG2(printk("scsi%ld: %s: failed status %04X\n",
1261 ha->host_no, __func__, mbox_sts[0]));
1262 return QLA_ERROR;
1263 }
1264 return QLA_SUCCESS;
1265}
1266
Manish Rangankarb3a271a2011-07-25 13:48:53 -05001267int qla4xxx_req_ddb_entry(struct scsi_qla_host *ha, uint32_t ddb_index,
1268 uint32_t *mbx_sts)
David Somayajuluafaf5a22006-09-19 10:28:00 -07001269{
Manish Rangankarb3a271a2011-07-25 13:48:53 -05001270 int status;
David Somayajuluafaf5a22006-09-19 10:28:00 -07001271 uint32_t mbox_cmd[MBOX_REG_COUNT];
1272 uint32_t mbox_sts[MBOX_REG_COUNT];
1273
1274 memset(&mbox_cmd, 0, sizeof(mbox_cmd));
1275 memset(&mbox_sts, 0, sizeof(mbox_sts));
1276
1277 mbox_cmd[0] = MBOX_CMD_REQUEST_DATABASE_ENTRY;
Manish Rangankarb3a271a2011-07-25 13:48:53 -05001278 mbox_cmd[1] = ddb_index;
David Somayajuluafaf5a22006-09-19 10:28:00 -07001279
Manish Rangankarb3a271a2011-07-25 13:48:53 -05001280 status = qla4xxx_mailbox_command(ha, MBOX_REG_COUNT, 1, &mbox_cmd[0],
1281 &mbox_sts[0]);
1282 if (status != QLA_SUCCESS) {
1283 DEBUG2(ql4_printk(KERN_ERR, ha, "%s: failed status %04X\n",
1284 __func__, mbox_sts[0]));
David Somayajuluafaf5a22006-09-19 10:28:00 -07001285 }
1286
Manish Rangankarb3a271a2011-07-25 13:48:53 -05001287 *mbx_sts = mbox_sts[0];
1288 return status;
David Somayajuluafaf5a22006-09-19 10:28:00 -07001289}
1290
Manish Rangankarb3a271a2011-07-25 13:48:53 -05001291int qla4xxx_clear_ddb_entry(struct scsi_qla_host *ha, uint32_t ddb_index)
1292{
1293 int status;
1294 uint32_t mbox_cmd[MBOX_REG_COUNT];
1295 uint32_t mbox_sts[MBOX_REG_COUNT];
1296
1297 memset(&mbox_cmd, 0, sizeof(mbox_cmd));
1298 memset(&mbox_sts, 0, sizeof(mbox_sts));
1299
1300 mbox_cmd[0] = MBOX_CMD_CLEAR_DATABASE_ENTRY;
1301 mbox_cmd[1] = ddb_index;
1302
1303 status = qla4xxx_mailbox_command(ha, 2, 1, &mbox_cmd[0],
1304 &mbox_sts[0]);
1305 if (status != QLA_SUCCESS) {
1306 DEBUG2(ql4_printk(KERN_ERR, ha, "%s: failed status %04X\n",
1307 __func__, mbox_sts[0]));
1308 }
1309
1310 return status;
1311}
1312
Mike Christied00efe32011-07-25 13:48:38 -05001313int qla4xxx_set_flash(struct scsi_qla_host *ha, dma_addr_t dma_addr,
1314 uint32_t offset, uint32_t length, uint32_t options)
1315{
1316 uint32_t mbox_cmd[MBOX_REG_COUNT];
1317 uint32_t mbox_sts[MBOX_REG_COUNT];
1318 int status = QLA_SUCCESS;
1319
1320 memset(&mbox_cmd, 0, sizeof(mbox_cmd));
1321 memset(&mbox_sts, 0, sizeof(mbox_sts));
1322
1323 mbox_cmd[0] = MBOX_CMD_WRITE_FLASH;
1324 mbox_cmd[1] = LSDW(dma_addr);
1325 mbox_cmd[2] = MSDW(dma_addr);
1326 mbox_cmd[3] = offset;
1327 mbox_cmd[4] = length;
1328 mbox_cmd[5] = options;
1329
1330 status = qla4xxx_mailbox_command(ha, 6, 2, &mbox_cmd[0], &mbox_sts[0]);
1331 if (status != QLA_SUCCESS) {
1332 DEBUG2(ql4_printk(KERN_WARNING, ha, "%s: MBOX_CMD_WRITE_FLASH "
1333 "failed w/ status %04X, mbx1 %04X\n",
1334 __func__, mbox_sts[0], mbox_sts[1]));
1335 }
1336 return status;
1337}
1338
Manish Rangankar2a991c22011-07-25 13:48:55 -05001339int qla4xxx_bootdb_by_index(struct scsi_qla_host *ha,
1340 struct dev_db_entry *fw_ddb_entry,
1341 dma_addr_t fw_ddb_entry_dma, uint16_t ddb_index)
1342{
1343 uint32_t dev_db_start_offset = FLASH_OFFSET_DB_INFO;
1344 uint32_t dev_db_end_offset;
1345 int status = QLA_ERROR;
1346
1347 memset(fw_ddb_entry, 0, sizeof(*fw_ddb_entry));
1348
1349 dev_db_start_offset += (ddb_index * sizeof(*fw_ddb_entry));
1350 dev_db_end_offset = FLASH_OFFSET_DB_END;
1351
1352 if (dev_db_start_offset > dev_db_end_offset) {
1353 DEBUG2(ql4_printk(KERN_ERR, ha,
1354 "%s:Invalid DDB index %d", __func__,
1355 ddb_index));
1356 goto exit_bootdb_failed;
1357 }
1358
1359 if (qla4xxx_get_flash(ha, fw_ddb_entry_dma, dev_db_start_offset,
1360 sizeof(*fw_ddb_entry)) != QLA_SUCCESS) {
1361 ql4_printk(KERN_ERR, ha, "scsi%ld: %s: Get Flash"
1362 "failed\n", ha->host_no, __func__);
1363 goto exit_bootdb_failed;
1364 }
1365
1366 if (fw_ddb_entry->cookie == DDB_VALID_COOKIE)
1367 status = QLA_SUCCESS;
1368
1369exit_bootdb_failed:
1370 return status;
1371}
1372
1373int qla4xxx_get_chap(struct scsi_qla_host *ha, char *username, char *password,
1374 uint16_t idx)
1375{
1376 int ret = 0;
1377 int rval = QLA_ERROR;
Lalit Chandivade45494152011-10-07 16:55:42 -07001378 uint32_t offset = 0, chap_size;
Manish Rangankar2a991c22011-07-25 13:48:55 -05001379 struct ql4_chap_table *chap_table;
1380 dma_addr_t chap_dma;
1381
1382 chap_table = dma_pool_alloc(ha->chap_dma_pool, GFP_KERNEL, &chap_dma);
1383 if (chap_table == NULL) {
1384 ret = -ENOMEM;
1385 goto exit_get_chap;
1386 }
1387
Lalit Chandivade45494152011-10-07 16:55:42 -07001388 chap_size = sizeof(struct ql4_chap_table);
1389 memset(chap_table, 0, chap_size);
Manish Rangankar2a991c22011-07-25 13:48:55 -05001390
Lalit Chandivade45494152011-10-07 16:55:42 -07001391 if (is_qla40XX(ha))
1392 offset = FLASH_CHAP_OFFSET | (idx * chap_size);
1393 else {
1394 offset = FLASH_RAW_ACCESS_ADDR + (ha->hw.flt_region_chap << 2);
1395 /* flt_chap_size is CHAP table size for both ports
1396 * so divide it by 2 to calculate the offset for second port
1397 */
1398 if (ha->port_num == 1)
1399 offset += (ha->hw.flt_chap_size / 2);
1400 offset += (idx * chap_size);
1401 }
Manish Rangankar2a991c22011-07-25 13:48:55 -05001402
Lalit Chandivade45494152011-10-07 16:55:42 -07001403 rval = qla4xxx_get_flash(ha, chap_dma, offset, chap_size);
Manish Rangankar2a991c22011-07-25 13:48:55 -05001404 if (rval != QLA_SUCCESS) {
1405 ret = -EINVAL;
1406 goto exit_get_chap;
1407 }
1408
1409 DEBUG2(ql4_printk(KERN_INFO, ha, "Chap Cookie: x%x\n",
1410 __le16_to_cpu(chap_table->cookie)));
1411
1412 if (__le16_to_cpu(chap_table->cookie) != CHAP_VALID_COOKIE) {
1413 ql4_printk(KERN_ERR, ha, "No valid chap entry found\n");
1414 goto exit_get_chap;
1415 }
1416
1417 strncpy(password, chap_table->secret, QL4_CHAP_MAX_SECRET_LEN);
1418 strncpy(username, chap_table->name, QL4_CHAP_MAX_NAME_LEN);
1419 chap_table->cookie = __constant_cpu_to_le16(CHAP_VALID_COOKIE);
1420
1421exit_get_chap:
1422 dma_pool_free(ha->chap_dma_pool, chap_table, chap_dma);
1423 return ret;
1424}
1425
Manish Rangankarb3a271a2011-07-25 13:48:53 -05001426static int qla4xxx_set_chap(struct scsi_qla_host *ha, char *username,
1427 char *password, uint16_t idx, int bidi)
1428{
1429 int ret = 0;
1430 int rval = QLA_ERROR;
1431 uint32_t offset = 0;
1432 struct ql4_chap_table *chap_table;
1433 dma_addr_t chap_dma;
1434
1435 chap_table = dma_pool_alloc(ha->chap_dma_pool, GFP_KERNEL, &chap_dma);
1436 if (chap_table == NULL) {
1437 ret = -ENOMEM;
1438 goto exit_set_chap;
1439 }
1440
1441 memset(chap_table, 0, sizeof(struct ql4_chap_table));
1442 if (bidi)
1443 chap_table->flags |= BIT_6; /* peer */
1444 else
1445 chap_table->flags |= BIT_7; /* local */
1446 chap_table->secret_len = strlen(password);
1447 strncpy(chap_table->secret, password, MAX_CHAP_SECRET_LEN);
1448 strncpy(chap_table->name, username, MAX_CHAP_NAME_LEN);
1449 chap_table->cookie = __constant_cpu_to_le16(CHAP_VALID_COOKIE);
Lalit Chandivade45494152011-10-07 16:55:42 -07001450 offset = FLASH_CHAP_OFFSET | (idx * sizeof(struct ql4_chap_table));
Manish Rangankarb3a271a2011-07-25 13:48:53 -05001451 rval = qla4xxx_set_flash(ha, chap_dma, offset,
1452 sizeof(struct ql4_chap_table),
1453 FLASH_OPT_RMW_COMMIT);
Lalit Chandivade45494152011-10-07 16:55:42 -07001454
1455 if (rval == QLA_SUCCESS && ha->chap_list) {
1456 /* Update ha chap_list cache */
1457 memcpy((struct ql4_chap_table *)ha->chap_list + idx,
1458 chap_table, sizeof(struct ql4_chap_table));
1459 }
Manish Rangankarb3a271a2011-07-25 13:48:53 -05001460 dma_pool_free(ha->chap_dma_pool, chap_table, chap_dma);
1461 if (rval != QLA_SUCCESS)
1462 ret = -EINVAL;
1463
1464exit_set_chap:
1465 return ret;
1466}
1467
Lalit Chandivade45494152011-10-07 16:55:42 -07001468/**
1469 * qla4xxx_get_chap_index - Get chap index given username and secret
1470 * @ha: pointer to adapter structure
1471 * @username: CHAP username to be searched
1472 * @password: CHAP password to be searched
1473 * @bidi: Is this a BIDI CHAP
1474 * @chap_index: CHAP index to be returned
1475 *
1476 * Match the username and password in the chap_list, return the index if a
1477 * match is found. If a match is not found then add the entry in FLASH and
1478 * return the index at which entry is written in the FLASH.
1479 **/
Mike Christiefca9f042012-02-27 03:08:54 -08001480int qla4xxx_get_chap_index(struct scsi_qla_host *ha, char *username,
1481 char *password, int bidi, uint16_t *chap_index)
Lalit Chandivade45494152011-10-07 16:55:42 -07001482{
1483 int i, rval;
1484 int free_index = -1;
1485 int found_index = 0;
1486 int max_chap_entries = 0;
1487 struct ql4_chap_table *chap_table;
1488
1489 if (is_qla8022(ha))
1490 max_chap_entries = (ha->hw.flt_chap_size / 2) /
1491 sizeof(struct ql4_chap_table);
1492 else
1493 max_chap_entries = MAX_CHAP_ENTRIES_40XX;
1494
1495 if (!ha->chap_list) {
1496 ql4_printk(KERN_ERR, ha, "Do not have CHAP table cache\n");
1497 return QLA_ERROR;
1498 }
1499
Mike Christiefca9f042012-02-27 03:08:54 -08001500 if (!username || !password) {
1501 ql4_printk(KERN_ERR, ha, "Do not have username and psw\n");
1502 return QLA_ERROR;
1503 }
1504
Lalit Chandivade45494152011-10-07 16:55:42 -07001505 mutex_lock(&ha->chap_sem);
1506 for (i = 0; i < max_chap_entries; i++) {
1507 chap_table = (struct ql4_chap_table *)ha->chap_list + i;
1508 if (chap_table->cookie !=
1509 __constant_cpu_to_le16(CHAP_VALID_COOKIE)) {
1510 if (i > MAX_RESRV_CHAP_IDX && free_index == -1)
1511 free_index = i;
1512 continue;
1513 }
1514 if (bidi) {
1515 if (chap_table->flags & BIT_7)
1516 continue;
1517 } else {
1518 if (chap_table->flags & BIT_6)
1519 continue;
1520 }
1521 if (!strncmp(chap_table->secret, password,
1522 MAX_CHAP_SECRET_LEN) &&
1523 !strncmp(chap_table->name, username,
1524 MAX_CHAP_NAME_LEN)) {
1525 *chap_index = i;
1526 found_index = 1;
1527 break;
1528 }
1529 }
1530
1531 /* If chap entry is not present and a free index is available then
1532 * write the entry in flash
1533 */
1534 if (!found_index && free_index != -1) {
1535 rval = qla4xxx_set_chap(ha, username, password,
1536 free_index, bidi);
1537 if (!rval) {
1538 *chap_index = free_index;
1539 found_index = 1;
1540 }
1541 }
1542
1543 mutex_unlock(&ha->chap_sem);
1544
1545 if (found_index)
1546 return QLA_SUCCESS;
1547 return QLA_ERROR;
1548}
1549
Mike Christied00efe32011-07-25 13:48:38 -05001550int qla4xxx_conn_close_sess_logout(struct scsi_qla_host *ha,
1551 uint16_t fw_ddb_index,
1552 uint16_t connection_id,
1553 uint16_t option)
1554{
1555 uint32_t mbox_cmd[MBOX_REG_COUNT];
1556 uint32_t mbox_sts[MBOX_REG_COUNT];
1557 int status = QLA_SUCCESS;
1558
1559 memset(&mbox_cmd, 0, sizeof(mbox_cmd));
1560 memset(&mbox_sts, 0, sizeof(mbox_sts));
1561
1562 mbox_cmd[0] = MBOX_CMD_CONN_CLOSE_SESS_LOGOUT;
1563 mbox_cmd[1] = fw_ddb_index;
1564 mbox_cmd[2] = connection_id;
1565 mbox_cmd[3] = option;
1566
1567 status = qla4xxx_mailbox_command(ha, 4, 2, &mbox_cmd[0], &mbox_sts[0]);
1568 if (status != QLA_SUCCESS) {
1569 DEBUG2(ql4_printk(KERN_WARNING, ha, "%s: MBOX_CMD_CONN_CLOSE "
1570 "option %04x failed w/ status %04X %04X\n",
1571 __func__, option, mbox_sts[0], mbox_sts[1]));
1572 }
1573 return status;
1574}
1575
1576int qla4xxx_disable_acb(struct scsi_qla_host *ha)
1577{
1578 uint32_t mbox_cmd[MBOX_REG_COUNT];
1579 uint32_t mbox_sts[MBOX_REG_COUNT];
1580 int status = QLA_SUCCESS;
1581
1582 memset(&mbox_cmd, 0, sizeof(mbox_cmd));
1583 memset(&mbox_sts, 0, sizeof(mbox_sts));
1584
1585 mbox_cmd[0] = MBOX_CMD_DISABLE_ACB;
1586
1587 status = qla4xxx_mailbox_command(ha, 8, 5, &mbox_cmd[0], &mbox_sts[0]);
1588 if (status != QLA_SUCCESS) {
1589 DEBUG2(ql4_printk(KERN_WARNING, ha, "%s: MBOX_CMD_DISABLE_ACB "
1590 "failed w/ status %04X %04X %04X", __func__,
1591 mbox_sts[0], mbox_sts[1], mbox_sts[2]));
1592 }
1593 return status;
1594}
1595
Harish Zunjarrao60854912011-08-12 02:51:27 -07001596int qla4xxx_get_acb(struct scsi_qla_host *ha, dma_addr_t acb_dma,
1597 uint32_t acb_type, uint32_t len)
Mike Christied00efe32011-07-25 13:48:38 -05001598{
Harish Zunjarrao60854912011-08-12 02:51:27 -07001599 uint32_t mbox_cmd[MBOX_REG_COUNT];
1600 uint32_t mbox_sts[MBOX_REG_COUNT];
Mike Christied00efe32011-07-25 13:48:38 -05001601 int status = QLA_SUCCESS;
1602
Harish Zunjarrao60854912011-08-12 02:51:27 -07001603 memset(&mbox_cmd, 0, sizeof(mbox_cmd));
1604 memset(&mbox_sts, 0, sizeof(mbox_sts));
1605
Mike Christied00efe32011-07-25 13:48:38 -05001606 mbox_cmd[0] = MBOX_CMD_GET_ACB;
Harish Zunjarrao60854912011-08-12 02:51:27 -07001607 mbox_cmd[1] = acb_type;
Mike Christied00efe32011-07-25 13:48:38 -05001608 mbox_cmd[2] = LSDW(acb_dma);
1609 mbox_cmd[3] = MSDW(acb_dma);
Harish Zunjarrao60854912011-08-12 02:51:27 -07001610 mbox_cmd[4] = len;
Mike Christied00efe32011-07-25 13:48:38 -05001611
1612 status = qla4xxx_mailbox_command(ha, 5, 5, &mbox_cmd[0], &mbox_sts[0]);
1613 if (status != QLA_SUCCESS) {
1614 DEBUG2(ql4_printk(KERN_WARNING, ha, "%s: MBOX_CMD_GET_ACB "
1615 "failed w/ status %04X\n", __func__,
1616 mbox_sts[0]));
1617 }
1618 return status;
1619}
1620
1621int qla4xxx_set_acb(struct scsi_qla_host *ha, uint32_t *mbox_cmd,
1622 uint32_t *mbox_sts, dma_addr_t acb_dma)
1623{
1624 int status = QLA_SUCCESS;
1625
1626 memset(mbox_cmd, 0, sizeof(mbox_cmd[0]) * MBOX_REG_COUNT);
1627 memset(mbox_sts, 0, sizeof(mbox_sts[0]) * MBOX_REG_COUNT);
1628 mbox_cmd[0] = MBOX_CMD_SET_ACB;
1629 mbox_cmd[1] = 0; /* Primary ACB */
1630 mbox_cmd[2] = LSDW(acb_dma);
1631 mbox_cmd[3] = MSDW(acb_dma);
1632 mbox_cmd[4] = sizeof(struct addr_ctrl_blk);
1633
1634 status = qla4xxx_mailbox_command(ha, 5, 5, &mbox_cmd[0], &mbox_sts[0]);
1635 if (status != QLA_SUCCESS) {
1636 DEBUG2(ql4_printk(KERN_WARNING, ha, "%s: MBOX_CMD_SET_ACB "
1637 "failed w/ status %04X\n", __func__,
1638 mbox_sts[0]));
1639 }
1640 return status;
1641}
Manish Rangankarb3a271a2011-07-25 13:48:53 -05001642
1643int qla4xxx_set_param_ddbentry(struct scsi_qla_host *ha,
1644 struct ddb_entry *ddb_entry,
1645 struct iscsi_cls_conn *cls_conn,
1646 uint32_t *mbx_sts)
1647{
1648 struct dev_db_entry *fw_ddb_entry;
1649 struct iscsi_conn *conn;
1650 struct iscsi_session *sess;
1651 struct qla_conn *qla_conn;
1652 struct sockaddr *dst_addr;
1653 dma_addr_t fw_ddb_entry_dma;
1654 int status = QLA_SUCCESS;
1655 int rval = 0;
1656 struct sockaddr_in *addr;
1657 struct sockaddr_in6 *addr6;
1658 char *ip;
1659 uint16_t iscsi_opts = 0;
1660 uint32_t options = 0;
Manish Rangankar173269e2012-02-27 03:08:55 -08001661 uint16_t idx, *ptid;
Manish Rangankarb3a271a2011-07-25 13:48:53 -05001662
1663 fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
1664 &fw_ddb_entry_dma, GFP_KERNEL);
1665 if (!fw_ddb_entry) {
1666 DEBUG2(ql4_printk(KERN_ERR, ha,
1667 "%s: Unable to allocate dma buffer.\n",
1668 __func__));
1669 rval = -ENOMEM;
1670 goto exit_set_param_no_free;
1671 }
1672
1673 conn = cls_conn->dd_data;
1674 qla_conn = conn->dd_data;
1675 sess = conn->session;
Manish Rangankard46bdeb2012-08-07 07:57:13 -04001676 dst_addr = (struct sockaddr *)&qla_conn->qla_ep->dst_addr;
Manish Rangankarb3a271a2011-07-25 13:48:53 -05001677
1678 if (dst_addr->sa_family == AF_INET6)
1679 options |= IPV6_DEFAULT_DDB_ENTRY;
1680
1681 status = qla4xxx_get_default_ddb(ha, options, fw_ddb_entry_dma);
1682 if (status == QLA_ERROR) {
1683 rval = -EINVAL;
1684 goto exit_set_param;
1685 }
1686
Manish Rangankar173269e2012-02-27 03:08:55 -08001687 ptid = (uint16_t *)&fw_ddb_entry->isid[1];
1688 *ptid = cpu_to_le16((uint16_t)ddb_entry->sess->target_id);
1689
1690 DEBUG2(ql4_printk(KERN_INFO, ha, "ISID [%02x%02x%02x%02x%02x%02x]\n",
1691 fw_ddb_entry->isid[5], fw_ddb_entry->isid[4],
1692 fw_ddb_entry->isid[3], fw_ddb_entry->isid[2],
1693 fw_ddb_entry->isid[1], fw_ddb_entry->isid[0]));
1694
Manish Rangankarb3a271a2011-07-25 13:48:53 -05001695 iscsi_opts = le16_to_cpu(fw_ddb_entry->iscsi_options);
1696 memset(fw_ddb_entry->iscsi_alias, 0, sizeof(fw_ddb_entry->iscsi_alias));
1697
1698 memset(fw_ddb_entry->iscsi_name, 0, sizeof(fw_ddb_entry->iscsi_name));
1699
1700 if (sess->targetname != NULL) {
1701 memcpy(fw_ddb_entry->iscsi_name, sess->targetname,
1702 min(strlen(sess->targetname),
1703 sizeof(fw_ddb_entry->iscsi_name)));
1704 }
1705
1706 memset(fw_ddb_entry->ip_addr, 0, sizeof(fw_ddb_entry->ip_addr));
1707 memset(fw_ddb_entry->tgt_addr, 0, sizeof(fw_ddb_entry->tgt_addr));
1708
1709 fw_ddb_entry->options = DDB_OPT_TARGET | DDB_OPT_AUTO_SENDTGTS_DISABLE;
1710
1711 if (dst_addr->sa_family == AF_INET) {
1712 addr = (struct sockaddr_in *)dst_addr;
1713 ip = (char *)&addr->sin_addr;
1714 memcpy(fw_ddb_entry->ip_addr, ip, IP_ADDR_LEN);
1715 fw_ddb_entry->port = cpu_to_le16(ntohs(addr->sin_port));
1716 DEBUG2(ql4_printk(KERN_INFO, ha,
1717 "%s: Destination Address [%pI4]: index [%d]\n",
1718 __func__, fw_ddb_entry->ip_addr,
1719 ddb_entry->fw_ddb_index));
1720 } else if (dst_addr->sa_family == AF_INET6) {
1721 addr6 = (struct sockaddr_in6 *)dst_addr;
1722 ip = (char *)&addr6->sin6_addr;
1723 memcpy(fw_ddb_entry->ip_addr, ip, IPv6_ADDR_LEN);
1724 fw_ddb_entry->port = cpu_to_le16(ntohs(addr6->sin6_port));
1725 fw_ddb_entry->options |= DDB_OPT_IPV6_DEVICE;
1726 DEBUG2(ql4_printk(KERN_INFO, ha,
1727 "%s: Destination Address [%pI6]: index [%d]\n",
1728 __func__, fw_ddb_entry->ip_addr,
1729 ddb_entry->fw_ddb_index));
1730 } else {
1731 ql4_printk(KERN_ERR, ha,
1732 "%s: Failed to get IP Address\n",
1733 __func__);
1734 rval = -EINVAL;
1735 goto exit_set_param;
1736 }
1737
Manish Rangankarb3a271a2011-07-25 13:48:53 -05001738 /* CHAP */
1739 if (sess->username != NULL && sess->password != NULL) {
1740 if (strlen(sess->username) && strlen(sess->password)) {
1741 iscsi_opts |= BIT_7;
Manish Rangankarb3a271a2011-07-25 13:48:53 -05001742
Lalit Chandivade45494152011-10-07 16:55:42 -07001743 rval = qla4xxx_get_chap_index(ha, sess->username,
1744 sess->password,
1745 LOCAL_CHAP, &idx);
Manish Rangankarb3a271a2011-07-25 13:48:53 -05001746 if (rval)
1747 goto exit_set_param;
1748
1749 fw_ddb_entry->chap_tbl_idx = cpu_to_le16(idx);
1750 }
1751 }
1752
1753 if (sess->username_in != NULL && sess->password_in != NULL) {
1754 /* Check if BIDI CHAP */
1755 if (strlen(sess->username_in) && strlen(sess->password_in)) {
1756 iscsi_opts |= BIT_4;
Lalit Chandivade45494152011-10-07 16:55:42 -07001757
1758 rval = qla4xxx_get_chap_index(ha, sess->username_in,
1759 sess->password_in,
1760 BIDI_CHAP, &idx);
Manish Rangankarb3a271a2011-07-25 13:48:53 -05001761 if (rval)
1762 goto exit_set_param;
1763 }
1764 }
1765
1766 if (sess->initial_r2t_en)
1767 iscsi_opts |= BIT_10;
1768
1769 if (sess->imm_data_en)
1770 iscsi_opts |= BIT_11;
1771
1772 fw_ddb_entry->iscsi_options = cpu_to_le16(iscsi_opts);
1773
1774 if (conn->max_recv_dlength)
1775 fw_ddb_entry->iscsi_max_rcv_data_seg_len =
1776 __constant_cpu_to_le16((conn->max_recv_dlength / BYTE_UNITS));
1777
1778 if (sess->max_r2t)
1779 fw_ddb_entry->iscsi_max_outsnd_r2t = cpu_to_le16(sess->max_r2t);
1780
1781 if (sess->first_burst)
1782 fw_ddb_entry->iscsi_first_burst_len =
1783 __constant_cpu_to_le16((sess->first_burst / BYTE_UNITS));
1784
1785 if (sess->max_burst)
1786 fw_ddb_entry->iscsi_max_burst_len =
1787 __constant_cpu_to_le16((sess->max_burst / BYTE_UNITS));
1788
1789 if (sess->time2wait)
1790 fw_ddb_entry->iscsi_def_time2wait =
1791 cpu_to_le16(sess->time2wait);
1792
1793 if (sess->time2retain)
1794 fw_ddb_entry->iscsi_def_time2retain =
1795 cpu_to_le16(sess->time2retain);
1796
1797 status = qla4xxx_set_ddb_entry(ha, ddb_entry->fw_ddb_index,
1798 fw_ddb_entry_dma, mbx_sts);
1799
1800 if (status != QLA_SUCCESS)
1801 rval = -EINVAL;
1802exit_set_param:
1803 dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
1804 fw_ddb_entry, fw_ddb_entry_dma);
1805exit_set_param_no_free:
1806 return rval;
1807}
1808
1809int qla4xxx_get_mgmt_data(struct scsi_qla_host *ha, uint16_t fw_ddb_index,
1810 uint16_t stats_size, dma_addr_t stats_dma)
1811{
1812 int status = QLA_SUCCESS;
1813 uint32_t mbox_cmd[MBOX_REG_COUNT];
1814 uint32_t mbox_sts[MBOX_REG_COUNT];
1815
1816 memset(mbox_cmd, 0, sizeof(mbox_cmd[0]) * MBOX_REG_COUNT);
1817 memset(mbox_sts, 0, sizeof(mbox_sts[0]) * MBOX_REG_COUNT);
1818 mbox_cmd[0] = MBOX_CMD_GET_MANAGEMENT_DATA;
1819 mbox_cmd[1] = fw_ddb_index;
1820 mbox_cmd[2] = LSDW(stats_dma);
1821 mbox_cmd[3] = MSDW(stats_dma);
1822 mbox_cmd[4] = stats_size;
1823
1824 status = qla4xxx_mailbox_command(ha, 5, 1, &mbox_cmd[0], &mbox_sts[0]);
1825 if (status != QLA_SUCCESS) {
1826 DEBUG2(ql4_printk(KERN_WARNING, ha,
1827 "%s: MBOX_CMD_GET_MANAGEMENT_DATA "
1828 "failed w/ status %04X\n", __func__,
1829 mbox_sts[0]));
1830 }
1831 return status;
1832}
Harish Zunjarrao8b0402e2011-08-01 03:26:15 -07001833
1834int qla4xxx_get_ip_state(struct scsi_qla_host *ha, uint32_t acb_idx,
1835 uint32_t ip_idx, uint32_t *sts)
1836{
1837 uint32_t mbox_cmd[MBOX_REG_COUNT];
1838 uint32_t mbox_sts[MBOX_REG_COUNT];
1839 int status = QLA_SUCCESS;
1840
1841 memset(&mbox_cmd, 0, sizeof(mbox_cmd));
1842 memset(&mbox_sts, 0, sizeof(mbox_sts));
1843 mbox_cmd[0] = MBOX_CMD_GET_IP_ADDR_STATE;
1844 mbox_cmd[1] = acb_idx;
1845 mbox_cmd[2] = ip_idx;
1846
1847 status = qla4xxx_mailbox_command(ha, 3, 8, &mbox_cmd[0], &mbox_sts[0]);
1848 if (status != QLA_SUCCESS) {
1849 DEBUG2(ql4_printk(KERN_WARNING, ha, "%s: "
1850 "MBOX_CMD_GET_IP_ADDR_STATE failed w/ "
1851 "status %04X\n", __func__, mbox_sts[0]));
1852 }
1853 memcpy(sts, mbox_sts, sizeof(mbox_sts));
1854 return status;
1855}
Harish Zunjarrao7c07d132011-08-01 03:26:16 -07001856
1857int qla4xxx_get_nvram(struct scsi_qla_host *ha, dma_addr_t nvram_dma,
1858 uint32_t offset, uint32_t size)
1859{
1860 int status = QLA_SUCCESS;
1861 uint32_t mbox_cmd[MBOX_REG_COUNT];
1862 uint32_t mbox_sts[MBOX_REG_COUNT];
1863
1864 memset(&mbox_cmd, 0, sizeof(mbox_cmd));
1865 memset(&mbox_sts, 0, sizeof(mbox_sts));
1866
1867 mbox_cmd[0] = MBOX_CMD_GET_NVRAM;
1868 mbox_cmd[1] = LSDW(nvram_dma);
1869 mbox_cmd[2] = MSDW(nvram_dma);
1870 mbox_cmd[3] = offset;
1871 mbox_cmd[4] = size;
1872
1873 status = qla4xxx_mailbox_command(ha, MBOX_REG_COUNT, 1, &mbox_cmd[0],
1874 &mbox_sts[0]);
1875 if (status != QLA_SUCCESS) {
1876 DEBUG2(ql4_printk(KERN_ERR, ha, "scsi%ld: %s: failed "
1877 "status %04X\n", ha->host_no, __func__,
1878 mbox_sts[0]));
1879 }
1880 return status;
1881}
1882
1883int qla4xxx_set_nvram(struct scsi_qla_host *ha, dma_addr_t nvram_dma,
1884 uint32_t offset, uint32_t size)
1885{
1886 int status = QLA_SUCCESS;
1887 uint32_t mbox_cmd[MBOX_REG_COUNT];
1888 uint32_t mbox_sts[MBOX_REG_COUNT];
1889
1890 memset(&mbox_cmd, 0, sizeof(mbox_cmd));
1891 memset(&mbox_sts, 0, sizeof(mbox_sts));
1892
1893 mbox_cmd[0] = MBOX_CMD_SET_NVRAM;
1894 mbox_cmd[1] = LSDW(nvram_dma);
1895 mbox_cmd[2] = MSDW(nvram_dma);
1896 mbox_cmd[3] = offset;
1897 mbox_cmd[4] = size;
1898
1899 status = qla4xxx_mailbox_command(ha, MBOX_REG_COUNT, 1, &mbox_cmd[0],
1900 &mbox_sts[0]);
1901 if (status != QLA_SUCCESS) {
1902 DEBUG2(ql4_printk(KERN_ERR, ha, "scsi%ld: %s: failed "
1903 "status %04X\n", ha->host_no, __func__,
1904 mbox_sts[0]));
1905 }
1906 return status;
1907}
Harish Zunjarrao5232f802011-08-12 02:51:26 -07001908
1909int qla4xxx_restore_factory_defaults(struct scsi_qla_host *ha,
1910 uint32_t region, uint32_t field0,
1911 uint32_t field1)
1912{
1913 int status = QLA_SUCCESS;
1914 uint32_t mbox_cmd[MBOX_REG_COUNT];
1915 uint32_t mbox_sts[MBOX_REG_COUNT];
1916
1917 memset(&mbox_cmd, 0, sizeof(mbox_cmd));
1918 memset(&mbox_sts, 0, sizeof(mbox_sts));
1919
1920 mbox_cmd[0] = MBOX_CMD_RESTORE_FACTORY_DEFAULTS;
1921 mbox_cmd[3] = region;
1922 mbox_cmd[4] = field0;
1923 mbox_cmd[5] = field1;
1924
1925 status = qla4xxx_mailbox_command(ha, MBOX_REG_COUNT, 3, &mbox_cmd[0],
1926 &mbox_sts[0]);
1927 if (status != QLA_SUCCESS) {
1928 DEBUG2(ql4_printk(KERN_ERR, ha, "scsi%ld: %s: failed "
1929 "status %04X\n", ha->host_no, __func__,
1930 mbox_sts[0]));
1931 }
1932 return status;
1933}