blob: f0dc6b321c8d508326cdcd40723663440e4df461 [file] [log] [blame]
David Somayajuluafaf5a22006-09-19 10:28:00 -07001/*
2 * QLogic iSCSI HBA Driver
Vikas Chaudhary4a4f51e2013-08-16 07:03:04 -04003 * Copyright (c) 2003-2013 QLogic Corporation
David Somayajuluafaf5a22006-09-19 10:28:00 -07004 *
5 * See LICENSE.qla4xxx for copyright and licensing details.
6 */
7
Adheer Chandravanshieee06a02013-07-08 08:33:10 -04008#include <linux/ctype.h>
David Somayajuluafaf5a22006-09-19 10:28:00 -07009#include "ql4_def.h"
David C Somayajuluc0e344c2007-05-23 18:03:27 -070010#include "ql4_glbl.h"
11#include "ql4_dbg.h"
12#include "ql4_inline.h"
Manish Dusanecfb27872012-09-20 07:35:01 -040013#include "ql4_version.h"
David Somayajuluafaf5a22006-09-19 10:28:00 -070014
Vikas Chaudhary33693c72012-08-22 07:55:04 -040015void qla4xxx_queue_mbox_cmd(struct scsi_qla_host *ha, uint32_t *mbx_cmd,
16 int in_count)
17{
18 int i;
19
20 /* Load all mailbox registers, except mailbox 0. */
21 for (i = 1; i < in_count; i++)
22 writel(mbx_cmd[i], &ha->reg->mailbox[i]);
23
24 /* Wakeup firmware */
25 writel(mbx_cmd[0], &ha->reg->mailbox[0]);
26 readl(&ha->reg->mailbox[0]);
27 writel(set_rmask(CSR_INTR_RISC), &ha->reg->ctrl_status);
28 readl(&ha->reg->ctrl_status);
29}
30
31void qla4xxx_process_mbox_intr(struct scsi_qla_host *ha, int out_count)
32{
33 int intr_status;
34
35 intr_status = readl(&ha->reg->ctrl_status);
36 if (intr_status & INTR_PENDING) {
37 /*
38 * Service the interrupt.
39 * The ISR will save the mailbox status registers
40 * to a temporary storage location in the adapter structure.
41 */
42 ha->mbox_status_count = out_count;
43 ha->isp_ops->interrupt_service_routine(ha, intr_status);
44 }
45}
David Somayajuluafaf5a22006-09-19 10:28:00 -070046
47/**
Vikas Chaudhary5c19b922012-11-23 06:58:38 -050048 * qla4xxx_is_intr_poll_mode – Are we allowed to poll for interrupts?
49 * @ha: Pointer to host adapter structure.
50 * @ret: 1=polling mode, 0=non-polling mode
51 **/
52static int qla4xxx_is_intr_poll_mode(struct scsi_qla_host *ha)
53{
54 int rval = 1;
55
Vikas Chaudharyb37ca412013-08-16 07:03:02 -040056 if (is_qla8032(ha) || is_qla8042(ha)) {
Vikas Chaudhary5c19b922012-11-23 06:58:38 -050057 if (test_bit(AF_IRQ_ATTACHED, &ha->flags) &&
58 test_bit(AF_83XX_MBOX_INTR_ON, &ha->flags))
59 rval = 0;
60 } else {
61 if (test_bit(AF_IRQ_ATTACHED, &ha->flags) &&
62 test_bit(AF_INTERRUPTS_ON, &ha->flags) &&
63 test_bit(AF_ONLINE, &ha->flags) &&
64 !test_bit(AF_HA_REMOVAL, &ha->flags))
65 rval = 0;
66 }
67
68 return rval;
69}
70
71/**
David Somayajuluafaf5a22006-09-19 10:28:00 -070072 * qla4xxx_mailbox_command - issues mailbox commands
73 * @ha: Pointer to host adapter structure.
74 * @inCount: number of mailbox registers to load.
75 * @outCount: number of mailbox registers to return.
76 * @mbx_cmd: data pointer for mailbox in registers.
77 * @mbx_sts: data pointer for mailbox out registers.
78 *
Justin P. Mattock70f23fd2011-05-10 10:16:21 +020079 * This routine issue mailbox commands and waits for completion.
David Somayajuluafaf5a22006-09-19 10:28:00 -070080 * If outCount is 0, this routine completes successfully WITHOUT waiting
81 * for the mailbox command to complete.
82 **/
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +053083int qla4xxx_mailbox_command(struct scsi_qla_host *ha, uint8_t inCount,
84 uint8_t outCount, uint32_t *mbx_cmd,
85 uint32_t *mbx_sts)
David Somayajuluafaf5a22006-09-19 10:28:00 -070086{
87 int status = QLA_ERROR;
88 uint8_t i;
89 u_long wait_count;
David Somayajuluafaf5a22006-09-19 10:28:00 -070090 unsigned long flags = 0;
Prasanna Mumbai99b53bf2011-03-21 03:34:25 -070091 uint32_t dev_state;
David Somayajuluafaf5a22006-09-19 10:28:00 -070092
93 /* Make sure that pointers are valid */
94 if (!mbx_cmd || !mbx_sts) {
95 DEBUG2(printk("scsi%ld: %s: Invalid mbx_cmd or mbx_sts "
96 "pointer\n", ha->host_no, __func__));
David C Somayajulu477ffb92007-01-22 12:26:11 -080097 return status;
98 }
Nilesh Javali21033632010-07-30 14:28:07 +053099
Mike Christie13483732011-12-01 21:38:41 -0600100 if (is_qla40XX(ha)) {
101 if (test_bit(AF_HA_REMOVAL, &ha->flags)) {
102 DEBUG2(ql4_printk(KERN_WARNING, ha, "scsi%ld: %s: "
103 "prematurely completing mbx cmd as "
104 "adapter removal detected\n",
105 ha->host_no, __func__));
106 return status;
107 }
108 }
109
Lalit Chandivade2232be02010-07-30 14:38:47 +0530110 if ((is_aer_supported(ha)) &&
111 (test_bit(AF_PCI_CHANNEL_IO_PERM_FAILURE, &ha->flags))) {
112 DEBUG2(printk(KERN_WARNING "scsi%ld: %s: Perm failure on EEH, "
113 "timeout MBX Exiting.\n", ha->host_no, __func__));
114 return status;
115 }
116
David C Somayajulu477ffb92007-01-22 12:26:11 -0800117 /* Mailbox code active */
118 wait_count = MBOX_TOV * 100;
119
120 while (wait_count--) {
121 mutex_lock(&ha->mbox_sem);
122 if (!test_bit(AF_MBOX_COMMAND, &ha->flags)) {
123 set_bit(AF_MBOX_COMMAND, &ha->flags);
124 mutex_unlock(&ha->mbox_sem);
125 break;
126 }
127 mutex_unlock(&ha->mbox_sem);
128 if (!wait_count) {
129 DEBUG2(printk("scsi%ld: %s: mbox_sem failed\n",
130 ha->host_no, __func__));
131 return status;
132 }
133 msleep(10);
David Somayajuluafaf5a22006-09-19 10:28:00 -0700134 }
135
Vikas Chaudhary6e7b4292012-08-22 07:55:08 -0400136 if (is_qla80XX(ha)) {
Lalit Chandivade5f50aa32012-04-23 22:32:32 -0700137 if (test_bit(AF_FW_RECOVERY, &ha->flags)) {
138 DEBUG2(ql4_printk(KERN_WARNING, ha,
139 "scsi%ld: %s: prematurely completing mbx cmd as firmware recovery detected\n",
140 ha->host_no, __func__));
141 goto mbox_exit;
142 }
143 /* Do not send any mbx cmd if h/w is in failed state*/
Vikas Chaudhary33693c72012-08-22 07:55:04 -0400144 ha->isp_ops->idc_lock(ha);
145 dev_state = qla4_8xxx_rd_direct(ha, QLA8XXX_CRB_DEV_STATE);
146 ha->isp_ops->idc_unlock(ha);
Vikas Chaudharyde8c72d2012-08-22 09:14:24 -0400147 if (dev_state == QLA8XXX_DEV_FAILED) {
Lalit Chandivade5f50aa32012-04-23 22:32:32 -0700148 ql4_printk(KERN_WARNING, ha,
149 "scsi%ld: %s: H/W is in failed state, do not send any mailbox commands\n",
150 ha->host_no, __func__);
151 goto mbox_exit;
152 }
153 }
154
David Somayajuluafaf5a22006-09-19 10:28:00 -0700155 spin_lock_irqsave(&ha->hardware_lock, flags);
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +0530156
David Somayajuluafaf5a22006-09-19 10:28:00 -0700157 ha->mbox_status_count = outCount;
158 for (i = 0; i < outCount; i++)
159 ha->mbox_status[i] = 0;
160
Vikas Chaudhary33693c72012-08-22 07:55:04 -0400161 /* Queue the mailbox command to the firmware */
162 ha->isp_ops->queue_mailbox_command(ha, mbx_cmd, inCount);
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +0530163
David Somayajuluafaf5a22006-09-19 10:28:00 -0700164 spin_unlock_irqrestore(&ha->hardware_lock, flags);
165
166 /* Wait for completion */
David Somayajuluafaf5a22006-09-19 10:28:00 -0700167
168 /*
169 * If we don't want status, don't wait for the mailbox command to
170 * complete. For example, MBOX_CMD_RESET_FW doesn't return status,
171 * you must poll the inbound Interrupt Mask for completion.
172 */
173 if (outCount == 0) {
174 status = QLA_SUCCESS;
David Somayajuluafaf5a22006-09-19 10:28:00 -0700175 goto mbox_exit;
176 }
David Somayajuluafaf5a22006-09-19 10:28:00 -0700177
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +0530178 /*
179 * Wait for completion: Poll or completion queue
180 */
Vikas Chaudhary5c19b922012-11-23 06:58:38 -0500181 if (qla4xxx_is_intr_poll_mode(ha)) {
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +0530182 /* Poll for command to complete */
183 wait_count = jiffies + MBOX_TOV * HZ;
184 while (test_bit(AF_MBOX_COMMAND_DONE, &ha->flags) == 0) {
185 if (time_after_eq(jiffies, wait_count))
186 break;
David Somayajuluafaf5a22006-09-19 10:28:00 -0700187 /*
188 * Service the interrupt.
189 * The ISR will save the mailbox status registers
190 * to a temporary storage location in the adapter
191 * structure.
192 */
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +0530193 spin_lock_irqsave(&ha->hardware_lock, flags);
Vikas Chaudhary33693c72012-08-22 07:55:04 -0400194 ha->isp_ops->process_mailbox_interrupt(ha, outCount);
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +0530195 spin_unlock_irqrestore(&ha->hardware_lock, flags);
196 msleep(10);
David Somayajuluafaf5a22006-09-19 10:28:00 -0700197 }
Vikas Chaudhary5c19b922012-11-23 06:58:38 -0500198 } else {
199 /* Do not poll for completion. Use completion queue */
200 set_bit(AF_MBOX_COMMAND_NOPOLL, &ha->flags);
201 wait_for_completion_timeout(&ha->mbx_intr_comp, MBOX_TOV * HZ);
202 clear_bit(AF_MBOX_COMMAND_NOPOLL, &ha->flags);
David Somayajuluafaf5a22006-09-19 10:28:00 -0700203 }
David Somayajuluafaf5a22006-09-19 10:28:00 -0700204
205 /* Check for mailbox timeout. */
206 if (!test_bit(AF_MBOX_COMMAND_DONE, &ha->flags)) {
Vikas Chaudhary6e7b4292012-08-22 07:55:08 -0400207 if (is_qla80XX(ha) &&
Nilesh Javali21033632010-07-30 14:28:07 +0530208 test_bit(AF_FW_RECOVERY, &ha->flags)) {
209 DEBUG2(ql4_printk(KERN_INFO, ha,
210 "scsi%ld: %s: prematurely completing mbx cmd as "
211 "firmware recovery detected\n",
212 ha->host_no, __func__));
213 goto mbox_exit;
214 }
David Somayajuluafaf5a22006-09-19 10:28:00 -0700215 DEBUG2(printk("scsi%ld: Mailbox Cmd 0x%08X timed out ...,"
216 " Scheduling Adapter Reset\n", ha->host_no,
217 mbx_cmd[0]));
218 ha->mailbox_timeout_count++;
219 mbx_sts[0] = (-1);
220 set_bit(DPC_RESET_HA, &ha->dpc_flags);
Giridhar Malavalie6bd0eb2012-01-11 02:44:16 -0800221 if (is_qla8022(ha)) {
222 ql4_printk(KERN_INFO, ha,
223 "disabling pause transmit on port 0 & 1.\n");
Vikas Chaudharyf8086f42012-08-22 07:54:59 -0400224 qla4_82xx_wr_32(ha, QLA82XX_CRB_NIU + 0x98,
Giridhar Malavalie6bd0eb2012-01-11 02:44:16 -0800225 CRB_NIU_XG_PAUSE_CTL_P0 |
226 CRB_NIU_XG_PAUSE_CTL_P1);
Vikas Chaudharyb37ca412013-08-16 07:03:02 -0400227 } else if (is_qla8032(ha) || is_qla8042(ha)) {
Tej Parkash546fef22012-09-20 07:35:12 -0400228 ql4_printk(KERN_INFO, ha, " %s: disabling pause transmit on port 0 & 1.\n",
229 __func__);
230 qla4_83xx_disable_pause(ha);
Giridhar Malavalie6bd0eb2012-01-11 02:44:16 -0800231 }
David Somayajuluafaf5a22006-09-19 10:28:00 -0700232 goto mbox_exit;
233 }
234
235 /*
236 * Copy the mailbox out registers to the caller's mailbox in/out
237 * structure.
238 */
239 spin_lock_irqsave(&ha->hardware_lock, flags);
240 for (i = 0; i < outCount; i++)
241 mbx_sts[i] = ha->mbox_status[i];
242
243 /* Set return status and error flags (if applicable). */
244 switch (ha->mbox_status[0]) {
245 case MBOX_STS_COMMAND_COMPLETE:
246 status = QLA_SUCCESS;
247 break;
248
249 case MBOX_STS_INTERMEDIATE_COMPLETION:
250 status = QLA_SUCCESS;
251 break;
252
253 case MBOX_STS_BUSY:
254 DEBUG2( printk("scsi%ld: %s: Cmd = %08X, ISP BUSY\n",
255 ha->host_no, __func__, mbx_cmd[0]));
256 ha->mailbox_timeout_count++;
257 break;
258
259 default:
260 DEBUG2(printk("scsi%ld: %s: **** FAILED, cmd = %08X, "
261 "sts = %08X ****\n", ha->host_no, __func__,
262 mbx_cmd[0], mbx_sts[0]));
263 break;
264 }
265 spin_unlock_irqrestore(&ha->hardware_lock, flags);
266
267mbox_exit:
David C Somayajulu477ffb92007-01-22 12:26:11 -0800268 mutex_lock(&ha->mbox_sem);
David Somayajuluafaf5a22006-09-19 10:28:00 -0700269 clear_bit(AF_MBOX_COMMAND, &ha->flags);
David Somayajuluafaf5a22006-09-19 10:28:00 -0700270 mutex_unlock(&ha->mbox_sem);
David C Somayajulu477ffb92007-01-22 12:26:11 -0800271 clear_bit(AF_MBOX_COMMAND_DONE, &ha->flags);
David Somayajuluafaf5a22006-09-19 10:28:00 -0700272
273 return status;
274}
275
Tej Parkash068237c82012-05-18 04:41:44 -0400276/**
277 * qla4xxx_get_minidump_template - Get the firmware template
278 * @ha: Pointer to host adapter structure.
279 * @phys_addr: dma address for template
280 *
281 * Obtain the minidump template from firmware during initialization
282 * as it may not be available when minidump is desired.
283 **/
284int qla4xxx_get_minidump_template(struct scsi_qla_host *ha,
285 dma_addr_t phys_addr)
286{
287 uint32_t mbox_cmd[MBOX_REG_COUNT];
288 uint32_t mbox_sts[MBOX_REG_COUNT];
289 int status;
290
291 memset(&mbox_cmd, 0, sizeof(mbox_cmd));
292 memset(&mbox_sts, 0, sizeof(mbox_sts));
293
294 mbox_cmd[0] = MBOX_CMD_MINIDUMP;
295 mbox_cmd[1] = MINIDUMP_GET_TMPLT_SUBCOMMAND;
296 mbox_cmd[2] = LSDW(phys_addr);
297 mbox_cmd[3] = MSDW(phys_addr);
298 mbox_cmd[4] = ha->fw_dump_tmplt_size;
299 mbox_cmd[5] = 0;
300
301 status = qla4xxx_mailbox_command(ha, MBOX_REG_COUNT, 2, &mbox_cmd[0],
302 &mbox_sts[0]);
303 if (status != QLA_SUCCESS) {
304 DEBUG2(ql4_printk(KERN_INFO, ha,
305 "scsi%ld: %s: Cmd = %08X, mbx[0] = 0x%04x, mbx[1] = 0x%04x\n",
306 ha->host_no, __func__, mbox_cmd[0],
307 mbox_sts[0], mbox_sts[1]));
308 }
309 return status;
310}
311
312/**
313 * qla4xxx_req_template_size - Get minidump template size from firmware.
314 * @ha: Pointer to host adapter structure.
315 **/
316int qla4xxx_req_template_size(struct scsi_qla_host *ha)
317{
318 uint32_t mbox_cmd[MBOX_REG_COUNT];
319 uint32_t mbox_sts[MBOX_REG_COUNT];
320 int status;
321
322 memset(&mbox_cmd, 0, sizeof(mbox_cmd));
323 memset(&mbox_sts, 0, sizeof(mbox_sts));
324
325 mbox_cmd[0] = MBOX_CMD_MINIDUMP;
326 mbox_cmd[1] = MINIDUMP_GET_SIZE_SUBCOMMAND;
327
328 status = qla4xxx_mailbox_command(ha, MBOX_REG_COUNT, 8, &mbox_cmd[0],
329 &mbox_sts[0]);
330 if (status == QLA_SUCCESS) {
331 ha->fw_dump_tmplt_size = mbox_sts[1];
332 DEBUG2(ql4_printk(KERN_INFO, ha,
333 "%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",
334 __func__, mbox_sts[0], mbox_sts[1],
335 mbox_sts[2], mbox_sts[3], mbox_sts[4],
336 mbox_sts[5], mbox_sts[6], mbox_sts[7]));
337 if (ha->fw_dump_tmplt_size == 0)
338 status = QLA_ERROR;
339 } else {
340 ql4_printk(KERN_WARNING, ha,
341 "%s: Error sts[0]=0x%04x, mbx[1]=0x%04x\n",
342 __func__, mbox_sts[0], mbox_sts[1]);
343 status = QLA_ERROR;
344 }
345
346 return status;
347}
348
Nilesh Javali21033632010-07-30 14:28:07 +0530349void qla4xxx_mailbox_premature_completion(struct scsi_qla_host *ha)
350{
351 set_bit(AF_FW_RECOVERY, &ha->flags);
352 ql4_printk(KERN_INFO, ha, "scsi%ld: %s: set FW RECOVERY!\n",
353 ha->host_no, __func__);
354
355 if (test_bit(AF_MBOX_COMMAND, &ha->flags)) {
356 if (test_bit(AF_MBOX_COMMAND_NOPOLL, &ha->flags)) {
357 complete(&ha->mbx_intr_comp);
358 ql4_printk(KERN_INFO, ha, "scsi%ld: %s: Due to fw "
359 "recovery, doing premature completion of "
360 "mbx cmd\n", ha->host_no, __func__);
361
362 } else {
363 set_bit(AF_MBOX_COMMAND_DONE, &ha->flags);
364 ql4_printk(KERN_INFO, ha, "scsi%ld: %s: Due to fw "
365 "recovery, doing premature completion of "
366 "polling mbx cmd\n", ha->host_no, __func__);
367 }
368 }
369}
370
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +0530371static uint8_t
Vikas Chaudhary2a49a782010-04-28 11:37:07 +0530372qla4xxx_set_ifcb(struct scsi_qla_host *ha, uint32_t *mbox_cmd,
373 uint32_t *mbox_sts, dma_addr_t init_fw_cb_dma)
374{
375 memset(mbox_cmd, 0, sizeof(mbox_cmd[0]) * MBOX_REG_COUNT);
376 memset(mbox_sts, 0, sizeof(mbox_sts[0]) * MBOX_REG_COUNT);
Shyam Sundar2657c802010-10-06 22:50:29 -0700377
378 if (is_qla8022(ha))
Vikas Chaudharyf8086f42012-08-22 07:54:59 -0400379 qla4_82xx_wr_32(ha, ha->nx_db_wr_ptr, 0);
Shyam Sundar2657c802010-10-06 22:50:29 -0700380
Vikas Chaudhary2a49a782010-04-28 11:37:07 +0530381 mbox_cmd[0] = MBOX_CMD_INITIALIZE_FIRMWARE;
382 mbox_cmd[1] = 0;
383 mbox_cmd[2] = LSDW(init_fw_cb_dma);
384 mbox_cmd[3] = MSDW(init_fw_cb_dma);
385 mbox_cmd[4] = sizeof(struct addr_ctrl_blk);
386 mbox_cmd[5] = (IFCB_VER_MAX << 8) | IFCB_VER_MIN;
387
388 if (qla4xxx_mailbox_command(ha, 6, 6, mbox_cmd, mbox_sts) !=
389 QLA_SUCCESS) {
390 DEBUG2(printk(KERN_WARNING "scsi%ld: %s: "
391 "MBOX_CMD_INITIALIZE_FIRMWARE"
392 " failed w/ status %04X\n",
393 ha->host_no, __func__, mbox_sts[0]));
394 return QLA_ERROR;
395 }
396 return QLA_SUCCESS;
397}
398
Mike Christied00efe32011-07-25 13:48:38 -0500399uint8_t
Vikas Chaudhary2a49a782010-04-28 11:37:07 +0530400qla4xxx_get_ifcb(struct scsi_qla_host *ha, uint32_t *mbox_cmd,
401 uint32_t *mbox_sts, dma_addr_t init_fw_cb_dma)
402{
403 memset(mbox_cmd, 0, sizeof(mbox_cmd[0]) * MBOX_REG_COUNT);
404 memset(mbox_sts, 0, sizeof(mbox_sts[0]) * MBOX_REG_COUNT);
405 mbox_cmd[0] = MBOX_CMD_GET_INIT_FW_CTRL_BLOCK;
406 mbox_cmd[2] = LSDW(init_fw_cb_dma);
407 mbox_cmd[3] = MSDW(init_fw_cb_dma);
408 mbox_cmd[4] = sizeof(struct addr_ctrl_blk);
409
410 if (qla4xxx_mailbox_command(ha, 5, 5, mbox_cmd, mbox_sts) !=
411 QLA_SUCCESS) {
412 DEBUG2(printk(KERN_WARNING "scsi%ld: %s: "
413 "MBOX_CMD_GET_INIT_FW_CTRL_BLOCK"
414 " failed w/ status %04X\n",
415 ha->host_no, __func__, mbox_sts[0]));
416 return QLA_ERROR;
417 }
418 return QLA_SUCCESS;
419}
420
Harish Zunjarraof8e93412013-10-18 09:01:42 -0400421uint8_t qla4xxx_set_ipaddr_state(uint8_t fw_ipaddr_state)
422{
423 uint8_t ipaddr_state;
424
425 switch (fw_ipaddr_state) {
426 case IP_ADDRSTATE_UNCONFIGURED:
427 ipaddr_state = ISCSI_IPDDRESS_STATE_UNCONFIGURED;
428 break;
429 case IP_ADDRSTATE_INVALID:
430 ipaddr_state = ISCSI_IPDDRESS_STATE_INVALID;
431 break;
432 case IP_ADDRSTATE_ACQUIRING:
433 ipaddr_state = ISCSI_IPDDRESS_STATE_ACQUIRING;
434 break;
435 case IP_ADDRSTATE_TENTATIVE:
436 ipaddr_state = ISCSI_IPDDRESS_STATE_TENTATIVE;
437 break;
438 case IP_ADDRSTATE_DEPRICATED:
439 ipaddr_state = ISCSI_IPDDRESS_STATE_DEPRECATED;
440 break;
441 case IP_ADDRSTATE_PREFERRED:
442 ipaddr_state = ISCSI_IPDDRESS_STATE_VALID;
443 break;
444 case IP_ADDRSTATE_DISABLING:
445 ipaddr_state = ISCSI_IPDDRESS_STATE_DISABLING;
446 break;
447 default:
448 ipaddr_state = ISCSI_IPDDRESS_STATE_UNCONFIGURED;
449 }
450 return ipaddr_state;
451}
452
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +0530453static void
Vikas Chaudhary2a49a782010-04-28 11:37:07 +0530454qla4xxx_update_local_ip(struct scsi_qla_host *ha,
Vikas Chaudhary2bab08f2011-07-25 13:48:39 -0500455 struct addr_ctrl_blk *init_fw_cb)
Vikas Chaudhary2a49a782010-04-28 11:37:07 +0530456{
Vikas Chaudhary2bab08f2011-07-25 13:48:39 -0500457 ha->ip_config.tcp_options = le16_to_cpu(init_fw_cb->ipv4_tcp_opts);
458 ha->ip_config.ipv4_options = le16_to_cpu(init_fw_cb->ipv4_ip_opts);
459 ha->ip_config.ipv4_addr_state =
Harish Zunjarraof8e93412013-10-18 09:01:42 -0400460 qla4xxx_set_ipaddr_state(init_fw_cb->ipv4_addr_state);
Vikas Chaudhary943c1572011-08-01 03:26:13 -0700461 ha->ip_config.eth_mtu_size =
462 le16_to_cpu(init_fw_cb->eth_mtu_size);
Vikas Chaudhary2ada7fc2011-08-01 03:26:19 -0700463 ha->ip_config.ipv4_port = le16_to_cpu(init_fw_cb->ipv4_port);
Vikas Chaudhary2bab08f2011-07-25 13:48:39 -0500464
465 if (ha->acb_version == ACB_SUPPORTED) {
466 ha->ip_config.ipv6_options = le16_to_cpu(init_fw_cb->ipv6_opts);
467 ha->ip_config.ipv6_addl_options =
468 le16_to_cpu(init_fw_cb->ipv6_addtl_opts);
Harish Zunjarraof8e93412013-10-18 09:01:42 -0400469 ha->ip_config.ipv6_tcp_options =
470 le16_to_cpu(init_fw_cb->ipv6_tcp_opts);
Vikas Chaudhary2bab08f2011-07-25 13:48:39 -0500471 }
472
Vikas Chaudhary2a49a782010-04-28 11:37:07 +0530473 /* Save IPv4 Address Info */
Vikas Chaudhary2bab08f2011-07-25 13:48:39 -0500474 memcpy(ha->ip_config.ip_address, init_fw_cb->ipv4_addr,
475 min(sizeof(ha->ip_config.ip_address),
476 sizeof(init_fw_cb->ipv4_addr)));
477 memcpy(ha->ip_config.subnet_mask, init_fw_cb->ipv4_subnet,
478 min(sizeof(ha->ip_config.subnet_mask),
479 sizeof(init_fw_cb->ipv4_subnet)));
480 memcpy(ha->ip_config.gateway, init_fw_cb->ipv4_gw_addr,
481 min(sizeof(ha->ip_config.gateway),
482 sizeof(init_fw_cb->ipv4_gw_addr)));
Vikas Chaudhary2a49a782010-04-28 11:37:07 +0530483
Vikas Chaudhary6ac73e82011-07-25 13:48:49 -0500484 ha->ip_config.ipv4_vlan_tag = be16_to_cpu(init_fw_cb->ipv4_vlan_tag);
Harish Zunjarraof8e93412013-10-18 09:01:42 -0400485 ha->ip_config.control = init_fw_cb->control;
486 ha->ip_config.tcp_wsf = init_fw_cb->ipv4_tcp_wsf;
487 ha->ip_config.ipv4_tos = init_fw_cb->ipv4_tos;
488 ha->ip_config.ipv4_cache_id = init_fw_cb->ipv4_cacheid;
489 ha->ip_config.ipv4_alt_cid_len = init_fw_cb->ipv4_dhcp_alt_cid_len;
490 memcpy(ha->ip_config.ipv4_alt_cid, init_fw_cb->ipv4_dhcp_alt_cid,
491 min(sizeof(ha->ip_config.ipv4_alt_cid),
492 sizeof(init_fw_cb->ipv4_dhcp_alt_cid)));
493 ha->ip_config.ipv4_vid_len = init_fw_cb->ipv4_dhcp_vid_len;
494 memcpy(ha->ip_config.ipv4_vid, init_fw_cb->ipv4_dhcp_vid,
495 min(sizeof(ha->ip_config.ipv4_vid),
496 sizeof(init_fw_cb->ipv4_dhcp_vid)));
497 ha->ip_config.ipv4_ttl = init_fw_cb->ipv4_ttl;
498 ha->ip_config.def_timeout = le16_to_cpu(init_fw_cb->def_timeout);
499 ha->ip_config.abort_timer = init_fw_cb->abort_timer;
500 ha->ip_config.iscsi_options = le16_to_cpu(init_fw_cb->iscsi_opts);
501 ha->ip_config.iscsi_max_pdu_size =
502 le16_to_cpu(init_fw_cb->iscsi_max_pdu_size);
503 ha->ip_config.iscsi_first_burst_len =
504 le16_to_cpu(init_fw_cb->iscsi_fburst_len);
505 ha->ip_config.iscsi_max_outstnd_r2t =
506 le16_to_cpu(init_fw_cb->iscsi_max_outstnd_r2t);
507 ha->ip_config.iscsi_max_burst_len =
508 le16_to_cpu(init_fw_cb->iscsi_max_burst_len);
509 memcpy(ha->ip_config.iscsi_name, init_fw_cb->iscsi_name,
510 min(sizeof(ha->ip_config.iscsi_name),
511 sizeof(init_fw_cb->iscsi_name)));
Vikas Chaudhary6ac73e82011-07-25 13:48:49 -0500512
Vikas Chaudhary2a49a782010-04-28 11:37:07 +0530513 if (is_ipv6_enabled(ha)) {
514 /* Save IPv6 Address */
Vikas Chaudhary2bab08f2011-07-25 13:48:39 -0500515 ha->ip_config.ipv6_link_local_state =
Harish Zunjarraof8e93412013-10-18 09:01:42 -0400516 qla4xxx_set_ipaddr_state(init_fw_cb->ipv6_lnk_lcl_addr_state);
Vikas Chaudhary2bab08f2011-07-25 13:48:39 -0500517 ha->ip_config.ipv6_addr0_state =
Harish Zunjarraof8e93412013-10-18 09:01:42 -0400518 qla4xxx_set_ipaddr_state(init_fw_cb->ipv6_addr0_state);
Vikas Chaudhary2bab08f2011-07-25 13:48:39 -0500519 ha->ip_config.ipv6_addr1_state =
Harish Zunjarraof8e93412013-10-18 09:01:42 -0400520 qla4xxx_set_ipaddr_state(init_fw_cb->ipv6_addr1_state);
521
522 switch (le16_to_cpu(init_fw_cb->ipv6_dflt_rtr_state)) {
523 case IPV6_RTRSTATE_UNKNOWN:
524 ha->ip_config.ipv6_default_router_state =
525 ISCSI_ROUTER_STATE_UNKNOWN;
526 break;
527 case IPV6_RTRSTATE_MANUAL:
528 ha->ip_config.ipv6_default_router_state =
529 ISCSI_ROUTER_STATE_MANUAL;
530 break;
531 case IPV6_RTRSTATE_ADVERTISED:
532 ha->ip_config.ipv6_default_router_state =
533 ISCSI_ROUTER_STATE_ADVERTISED;
534 break;
535 case IPV6_RTRSTATE_STALE:
536 ha->ip_config.ipv6_default_router_state =
537 ISCSI_ROUTER_STATE_STALE;
538 break;
539 default:
540 ha->ip_config.ipv6_default_router_state =
541 ISCSI_ROUTER_STATE_UNKNOWN;
542 }
543
Vikas Chaudhary2bab08f2011-07-25 13:48:39 -0500544 ha->ip_config.ipv6_link_local_addr.in6_u.u6_addr8[0] = 0xFE;
545 ha->ip_config.ipv6_link_local_addr.in6_u.u6_addr8[1] = 0x80;
Vikas Chaudhary2a49a782010-04-28 11:37:07 +0530546
Vikas Chaudhary2bab08f2011-07-25 13:48:39 -0500547 memcpy(&ha->ip_config.ipv6_link_local_addr.in6_u.u6_addr8[8],
548 init_fw_cb->ipv6_if_id,
549 min(sizeof(ha->ip_config.ipv6_link_local_addr)/2,
550 sizeof(init_fw_cb->ipv6_if_id)));
551 memcpy(&ha->ip_config.ipv6_addr0, init_fw_cb->ipv6_addr0,
552 min(sizeof(ha->ip_config.ipv6_addr0),
553 sizeof(init_fw_cb->ipv6_addr0)));
554 memcpy(&ha->ip_config.ipv6_addr1, init_fw_cb->ipv6_addr1,
555 min(sizeof(ha->ip_config.ipv6_addr1),
556 sizeof(init_fw_cb->ipv6_addr1)));
557 memcpy(&ha->ip_config.ipv6_default_router_addr,
558 init_fw_cb->ipv6_dflt_rtr_addr,
559 min(sizeof(ha->ip_config.ipv6_default_router_addr),
560 sizeof(init_fw_cb->ipv6_dflt_rtr_addr)));
Vikas Chaudhary6ac73e82011-07-25 13:48:49 -0500561 ha->ip_config.ipv6_vlan_tag =
562 be16_to_cpu(init_fw_cb->ipv6_vlan_tag);
Vikas Chaudhary2ada7fc2011-08-01 03:26:19 -0700563 ha->ip_config.ipv6_port = le16_to_cpu(init_fw_cb->ipv6_port);
Harish Zunjarraof8e93412013-10-18 09:01:42 -0400564 ha->ip_config.ipv6_cache_id = init_fw_cb->ipv6_cache_id;
565 ha->ip_config.ipv6_flow_lbl =
566 le16_to_cpu(init_fw_cb->ipv6_flow_lbl);
567 ha->ip_config.ipv6_traffic_class =
568 init_fw_cb->ipv6_traffic_class;
569 ha->ip_config.ipv6_hop_limit = init_fw_cb->ipv6_hop_limit;
570 ha->ip_config.ipv6_nd_reach_time =
571 le32_to_cpu(init_fw_cb->ipv6_nd_reach_time);
572 ha->ip_config.ipv6_nd_rexmit_timer =
573 le32_to_cpu(init_fw_cb->ipv6_nd_rexmit_timer);
574 ha->ip_config.ipv6_nd_stale_timeout =
575 le32_to_cpu(init_fw_cb->ipv6_nd_stale_timeout);
576 ha->ip_config.ipv6_dup_addr_detect_count =
577 init_fw_cb->ipv6_dup_addr_detect_count;
578 ha->ip_config.ipv6_gw_advrt_mtu =
579 le32_to_cpu(init_fw_cb->ipv6_gw_advrt_mtu);
580 ha->ip_config.ipv6_tcp_wsf = init_fw_cb->ipv6_tcp_wsf;
Vikas Chaudhary2a49a782010-04-28 11:37:07 +0530581 }
582}
583
Mike Christied00efe32011-07-25 13:48:38 -0500584uint8_t
Vikas Chaudhary2a49a782010-04-28 11:37:07 +0530585qla4xxx_update_local_ifcb(struct scsi_qla_host *ha,
586 uint32_t *mbox_cmd,
587 uint32_t *mbox_sts,
588 struct addr_ctrl_blk *init_fw_cb,
589 dma_addr_t init_fw_cb_dma)
590{
591 if (qla4xxx_get_ifcb(ha, mbox_cmd, mbox_sts, init_fw_cb_dma)
592 != QLA_SUCCESS) {
593 DEBUG2(printk(KERN_WARNING
594 "scsi%ld: %s: Failed to get init_fw_ctrl_blk\n",
595 ha->host_no, __func__));
596 return QLA_ERROR;
597 }
598
599 DEBUG2(qla4xxx_dump_buffer(init_fw_cb, sizeof(struct addr_ctrl_blk)));
600
601 /* Save some info in adapter structure. */
602 ha->acb_version = init_fw_cb->acb_version;
603 ha->firmware_options = le16_to_cpu(init_fw_cb->fw_options);
Vikas Chaudhary2a49a782010-04-28 11:37:07 +0530604 ha->heartbeat_interval = init_fw_cb->hb_interval;
605 memcpy(ha->name_string, init_fw_cb->iscsi_name,
606 min(sizeof(ha->name_string),
607 sizeof(init_fw_cb->iscsi_name)));
Mike Christie13483732011-12-01 21:38:41 -0600608 ha->def_timeout = le16_to_cpu(init_fw_cb->def_timeout);
Vikas Chaudhary2a49a782010-04-28 11:37:07 +0530609 /*memcpy(ha->alias, init_fw_cb->Alias,
610 min(sizeof(ha->alias), sizeof(init_fw_cb->Alias)));*/
611
Vikas Chaudhary2a49a782010-04-28 11:37:07 +0530612 qla4xxx_update_local_ip(ha, init_fw_cb);
613
614 return QLA_SUCCESS;
615}
616
David Somayajuluafaf5a22006-09-19 10:28:00 -0700617/**
618 * qla4xxx_initialize_fw_cb - initializes firmware control block.
619 * @ha: Pointer to host adapter structure.
620 **/
621int qla4xxx_initialize_fw_cb(struct scsi_qla_host * ha)
622{
Vikas Chaudhary2a49a782010-04-28 11:37:07 +0530623 struct addr_ctrl_blk *init_fw_cb;
David Somayajuluafaf5a22006-09-19 10:28:00 -0700624 dma_addr_t init_fw_cb_dma;
625 uint32_t mbox_cmd[MBOX_REG_COUNT];
626 uint32_t mbox_sts[MBOX_REG_COUNT];
627 int status = QLA_ERROR;
628
629 init_fw_cb = dma_alloc_coherent(&ha->pdev->dev,
Vikas Chaudhary2a49a782010-04-28 11:37:07 +0530630 sizeof(struct addr_ctrl_blk),
David Somayajuluafaf5a22006-09-19 10:28:00 -0700631 &init_fw_cb_dma, GFP_KERNEL);
632 if (init_fw_cb == NULL) {
633 DEBUG2(printk("scsi%ld: %s: Unable to alloc init_cb\n",
634 ha->host_no, __func__));
Prasanna Mumbaibeabe7c2010-07-10 14:49:38 +0530635 goto exit_init_fw_cb_no_free;
David Somayajuluafaf5a22006-09-19 10:28:00 -0700636 }
Vikas Chaudhary2a49a782010-04-28 11:37:07 +0530637 memset(init_fw_cb, 0, sizeof(struct addr_ctrl_blk));
David Somayajuluafaf5a22006-09-19 10:28:00 -0700638
639 /* Get Initialize Firmware Control Block. */
640 memset(&mbox_cmd, 0, sizeof(mbox_cmd));
641 memset(&mbox_sts, 0, sizeof(mbox_sts));
David C Somayajuluc0e344c2007-05-23 18:03:27 -0700642
Vikas Chaudhary2a49a782010-04-28 11:37:07 +0530643 if (qla4xxx_get_ifcb(ha, &mbox_cmd[0], &mbox_sts[0], init_fw_cb_dma) !=
David Somayajuluafaf5a22006-09-19 10:28:00 -0700644 QLA_SUCCESS) {
645 dma_free_coherent(&ha->pdev->dev,
Vikas Chaudhary2a49a782010-04-28 11:37:07 +0530646 sizeof(struct addr_ctrl_blk),
David Somayajuluafaf5a22006-09-19 10:28:00 -0700647 init_fw_cb, init_fw_cb_dma);
Vikas Chaudhary2a49a782010-04-28 11:37:07 +0530648 goto exit_init_fw_cb;
David Somayajuluafaf5a22006-09-19 10:28:00 -0700649 }
650
651 /* Initialize request and response queues. */
652 qla4xxx_init_rings(ha);
653
654 /* Fill in the request and response queue information. */
Vikas Chaudhary2a49a782010-04-28 11:37:07 +0530655 init_fw_cb->rqq_consumer_idx = cpu_to_le16(ha->request_out);
656 init_fw_cb->compq_producer_idx = cpu_to_le16(ha->response_in);
657 init_fw_cb->rqq_len = __constant_cpu_to_le16(REQUEST_QUEUE_DEPTH);
658 init_fw_cb->compq_len = __constant_cpu_to_le16(RESPONSE_QUEUE_DEPTH);
659 init_fw_cb->rqq_addr_lo = cpu_to_le32(LSDW(ha->request_dma));
660 init_fw_cb->rqq_addr_hi = cpu_to_le32(MSDW(ha->request_dma));
661 init_fw_cb->compq_addr_lo = cpu_to_le32(LSDW(ha->response_dma));
662 init_fw_cb->compq_addr_hi = cpu_to_le32(MSDW(ha->response_dma));
663 init_fw_cb->shdwreg_addr_lo = cpu_to_le32(LSDW(ha->shadow_regs_dma));
664 init_fw_cb->shdwreg_addr_hi = cpu_to_le32(MSDW(ha->shadow_regs_dma));
David Somayajuluafaf5a22006-09-19 10:28:00 -0700665
666 /* Set up required options. */
Vikas Chaudhary2a49a782010-04-28 11:37:07 +0530667 init_fw_cb->fw_options |=
David Somayajuluafaf5a22006-09-19 10:28:00 -0700668 __constant_cpu_to_le16(FWOPT_SESSION_MODE |
669 FWOPT_INITIATOR_MODE);
Shyam Sundar2657c802010-10-06 22:50:29 -0700670
Vikas Chaudhary6e7b4292012-08-22 07:55:08 -0400671 if (is_qla80XX(ha))
Shyam Sundar2657c802010-10-06 22:50:29 -0700672 init_fw_cb->fw_options |=
673 __constant_cpu_to_le16(FWOPT_ENABLE_CRBDB);
674
Vikas Chaudhary2a49a782010-04-28 11:37:07 +0530675 init_fw_cb->fw_options &= __constant_cpu_to_le16(~FWOPT_TARGET_MODE);
David Somayajuluafaf5a22006-09-19 10:28:00 -0700676
Prasanna Mumbaid32cee32011-03-21 03:34:35 -0700677 init_fw_cb->add_fw_options = 0;
678 init_fw_cb->add_fw_options |=
Manish Rangankarb3a271a2011-07-25 13:48:53 -0500679 __constant_cpu_to_le16(ADFWOPT_SERIALIZE_TASK_MGMT);
680 init_fw_cb->add_fw_options |=
681 __constant_cpu_to_le16(ADFWOPT_AUTOCONN_DISABLE);
Prasanna Mumbaid32cee32011-03-21 03:34:35 -0700682
Vikas Chaudhary2a49a782010-04-28 11:37:07 +0530683 if (qla4xxx_set_ifcb(ha, &mbox_cmd[0], &mbox_sts[0], init_fw_cb_dma)
684 != QLA_SUCCESS) {
685 DEBUG2(printk(KERN_WARNING
686 "scsi%ld: %s: Failed to set init_fw_ctrl_blk\n",
687 ha->host_no, __func__));
688 goto exit_init_fw_cb;
David Somayajuluafaf5a22006-09-19 10:28:00 -0700689 }
Vikas Chaudhary2a49a782010-04-28 11:37:07 +0530690
691 if (qla4xxx_update_local_ifcb(ha, &mbox_cmd[0], &mbox_sts[0],
692 init_fw_cb, init_fw_cb_dma) != QLA_SUCCESS) {
693 DEBUG2(printk("scsi%ld: %s: Failed to update local ifcb\n",
694 ha->host_no, __func__));
695 goto exit_init_fw_cb;
696 }
697 status = QLA_SUCCESS;
698
699exit_init_fw_cb:
700 dma_free_coherent(&ha->pdev->dev, sizeof(struct addr_ctrl_blk),
701 init_fw_cb, init_fw_cb_dma);
Prasanna Mumbaibeabe7c2010-07-10 14:49:38 +0530702exit_init_fw_cb_no_free:
David Somayajuluafaf5a22006-09-19 10:28:00 -0700703 return status;
704}
705
706/**
707 * qla4xxx_get_dhcp_ip_address - gets HBA ip address via DHCP
708 * @ha: Pointer to host adapter structure.
709 **/
710int qla4xxx_get_dhcp_ip_address(struct scsi_qla_host * ha)
711{
Vikas Chaudhary2a49a782010-04-28 11:37:07 +0530712 struct addr_ctrl_blk *init_fw_cb;
David Somayajuluafaf5a22006-09-19 10:28:00 -0700713 dma_addr_t init_fw_cb_dma;
714 uint32_t mbox_cmd[MBOX_REG_COUNT];
715 uint32_t mbox_sts[MBOX_REG_COUNT];
716
717 init_fw_cb = dma_alloc_coherent(&ha->pdev->dev,
Vikas Chaudhary2a49a782010-04-28 11:37:07 +0530718 sizeof(struct addr_ctrl_blk),
David Somayajuluafaf5a22006-09-19 10:28:00 -0700719 &init_fw_cb_dma, GFP_KERNEL);
720 if (init_fw_cb == NULL) {
721 printk("scsi%ld: %s: Unable to alloc init_cb\n", ha->host_no,
722 __func__);
Prasanna Mumbaibeabe7c2010-07-10 14:49:38 +0530723 return QLA_ERROR;
David Somayajuluafaf5a22006-09-19 10:28:00 -0700724 }
725
726 /* Get Initialize Firmware Control Block. */
Vikas Chaudhary2a49a782010-04-28 11:37:07 +0530727 memset(init_fw_cb, 0, sizeof(struct addr_ctrl_blk));
728 if (qla4xxx_get_ifcb(ha, &mbox_cmd[0], &mbox_sts[0], init_fw_cb_dma) !=
David Somayajuluafaf5a22006-09-19 10:28:00 -0700729 QLA_SUCCESS) {
730 DEBUG2(printk("scsi%ld: %s: Failed to get init_fw_ctrl_blk\n",
731 ha->host_no, __func__));
732 dma_free_coherent(&ha->pdev->dev,
Vikas Chaudhary2a49a782010-04-28 11:37:07 +0530733 sizeof(struct addr_ctrl_blk),
David Somayajuluafaf5a22006-09-19 10:28:00 -0700734 init_fw_cb, init_fw_cb_dma);
735 return QLA_ERROR;
736 }
737
738 /* Save IP Address. */
Vikas Chaudhary2a49a782010-04-28 11:37:07 +0530739 qla4xxx_update_local_ip(ha, init_fw_cb);
740 dma_free_coherent(&ha->pdev->dev, sizeof(struct addr_ctrl_blk),
741 init_fw_cb, init_fw_cb_dma);
David Somayajuluafaf5a22006-09-19 10:28:00 -0700742
743 return QLA_SUCCESS;
744}
745
746/**
747 * qla4xxx_get_firmware_state - gets firmware state of HBA
748 * @ha: Pointer to host adapter structure.
749 **/
750int qla4xxx_get_firmware_state(struct scsi_qla_host * ha)
751{
752 uint32_t mbox_cmd[MBOX_REG_COUNT];
753 uint32_t mbox_sts[MBOX_REG_COUNT];
754
755 /* Get firmware version */
756 memset(&mbox_cmd, 0, sizeof(mbox_cmd));
757 memset(&mbox_sts, 0, sizeof(mbox_sts));
David C Somayajuluc0e344c2007-05-23 18:03:27 -0700758
David Somayajuluafaf5a22006-09-19 10:28:00 -0700759 mbox_cmd[0] = MBOX_CMD_GET_FW_STATE;
David C Somayajuluc0e344c2007-05-23 18:03:27 -0700760
761 if (qla4xxx_mailbox_command(ha, MBOX_REG_COUNT, 4, &mbox_cmd[0], &mbox_sts[0]) !=
David Somayajuluafaf5a22006-09-19 10:28:00 -0700762 QLA_SUCCESS) {
763 DEBUG2(printk("scsi%ld: %s: MBOX_CMD_GET_FW_STATE failed w/ "
764 "status %04X\n", ha->host_no, __func__,
765 mbox_sts[0]));
766 return QLA_ERROR;
767 }
768 ha->firmware_state = mbox_sts[1];
769 ha->board_id = mbox_sts[2];
770 ha->addl_fw_state = mbox_sts[3];
771 DEBUG2(printk("scsi%ld: %s firmware_state=0x%x\n",
772 ha->host_no, __func__, ha->firmware_state);)
773
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +0530774 return QLA_SUCCESS;
David Somayajuluafaf5a22006-09-19 10:28:00 -0700775}
776
777/**
778 * qla4xxx_get_firmware_status - retrieves firmware status
779 * @ha: Pointer to host adapter structure.
780 **/
781int qla4xxx_get_firmware_status(struct scsi_qla_host * ha)
782{
783 uint32_t mbox_cmd[MBOX_REG_COUNT];
784 uint32_t mbox_sts[MBOX_REG_COUNT];
785
786 /* Get firmware version */
787 memset(&mbox_cmd, 0, sizeof(mbox_cmd));
788 memset(&mbox_sts, 0, sizeof(mbox_sts));
David C Somayajuluc0e344c2007-05-23 18:03:27 -0700789
David Somayajuluafaf5a22006-09-19 10:28:00 -0700790 mbox_cmd[0] = MBOX_CMD_GET_FW_STATUS;
David C Somayajuluc0e344c2007-05-23 18:03:27 -0700791
792 if (qla4xxx_mailbox_command(ha, MBOX_REG_COUNT, 3, &mbox_cmd[0], &mbox_sts[0]) !=
David Somayajuluafaf5a22006-09-19 10:28:00 -0700793 QLA_SUCCESS) {
794 DEBUG2(printk("scsi%ld: %s: MBOX_CMD_GET_FW_STATUS failed w/ "
795 "status %04X\n", ha->host_no, __func__,
796 mbox_sts[0]));
797 return QLA_ERROR;
798 }
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +0530799
Karen Higgins5b1c1bf2013-01-20 23:51:00 -0500800 /* High-water mark of IOCBs */
801 ha->iocb_hiwat = mbox_sts[2];
802 DEBUG2(ql4_printk(KERN_INFO, ha,
803 "%s: firmware IOCBs available = %d\n", __func__,
804 ha->iocb_hiwat));
805
806 if (ha->iocb_hiwat > IOCB_HIWAT_CUSHION)
807 ha->iocb_hiwat -= IOCB_HIWAT_CUSHION;
808
809 /* Ideally, we should not enter this code, as the # of firmware
810 * IOCBs is hard-coded in the firmware. We set a default
811 * iocb_hiwat here just in case */
812 if (ha->iocb_hiwat == 0) {
813 ha->iocb_hiwat = REQUEST_QUEUE_DEPTH / 4;
814 DEBUG2(ql4_printk(KERN_WARNING, ha,
815 "%s: Setting IOCB's to = %d\n", __func__,
816 ha->iocb_hiwat));
817 }
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +0530818
David Somayajuluafaf5a22006-09-19 10:28:00 -0700819 return QLA_SUCCESS;
820}
821
822/**
823 * qla4xxx_get_fwddb_entry - retrieves firmware ddb entry
824 * @ha: Pointer to host adapter structure.
825 * @fw_ddb_index: Firmware's device database index
826 * @fw_ddb_entry: Pointer to firmware's device database entry structure
827 * @num_valid_ddb_entries: Pointer to number of valid ddb entries
828 * @next_ddb_index: Pointer to next valid device database index
829 * @fw_ddb_device_state: Pointer to device state
830 **/
831int qla4xxx_get_fwddb_entry(struct scsi_qla_host *ha,
832 uint16_t fw_ddb_index,
833 struct dev_db_entry *fw_ddb_entry,
834 dma_addr_t fw_ddb_entry_dma,
835 uint32_t *num_valid_ddb_entries,
836 uint32_t *next_ddb_index,
837 uint32_t *fw_ddb_device_state,
838 uint32_t *conn_err_detail,
839 uint16_t *tcp_source_port_num,
840 uint16_t *connection_id)
841{
842 int status = QLA_ERROR;
Vikas Chaudhary2a49a782010-04-28 11:37:07 +0530843 uint16_t options;
David Somayajuluafaf5a22006-09-19 10:28:00 -0700844 uint32_t mbox_cmd[MBOX_REG_COUNT];
845 uint32_t mbox_sts[MBOX_REG_COUNT];
846
847 /* Make sure the device index is valid */
848 if (fw_ddb_index >= MAX_DDB_ENTRIES) {
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +0530849 DEBUG2(printk("scsi%ld: %s: ddb [%d] out of range.\n",
David Somayajuluafaf5a22006-09-19 10:28:00 -0700850 ha->host_no, __func__, fw_ddb_index));
851 goto exit_get_fwddb;
852 }
853 memset(&mbox_cmd, 0, sizeof(mbox_cmd));
854 memset(&mbox_sts, 0, sizeof(mbox_sts));
Lalit Chandivade981c9822012-02-13 18:30:41 +0530855 if (fw_ddb_entry)
856 memset(fw_ddb_entry, 0, sizeof(struct dev_db_entry));
David C Somayajuluc0e344c2007-05-23 18:03:27 -0700857
David Somayajuluafaf5a22006-09-19 10:28:00 -0700858 mbox_cmd[0] = MBOX_CMD_GET_DATABASE_ENTRY;
859 mbox_cmd[1] = (uint32_t) fw_ddb_index;
860 mbox_cmd[2] = LSDW(fw_ddb_entry_dma);
861 mbox_cmd[3] = MSDW(fw_ddb_entry_dma);
David C Somayajuluc0e344c2007-05-23 18:03:27 -0700862 mbox_cmd[4] = sizeof(struct dev_db_entry);
863
864 if (qla4xxx_mailbox_command(ha, MBOX_REG_COUNT, 7, &mbox_cmd[0], &mbox_sts[0]) ==
David Somayajuluafaf5a22006-09-19 10:28:00 -0700865 QLA_ERROR) {
866 DEBUG2(printk("scsi%ld: %s: MBOX_CMD_GET_DATABASE_ENTRY failed"
867 " with status 0x%04X\n", ha->host_no, __func__,
868 mbox_sts[0]));
869 goto exit_get_fwddb;
870 }
871 if (fw_ddb_index != mbox_sts[1]) {
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +0530872 DEBUG2(printk("scsi%ld: %s: ddb mismatch [%d] != [%d].\n",
David Somayajuluafaf5a22006-09-19 10:28:00 -0700873 ha->host_no, __func__, fw_ddb_index,
874 mbox_sts[1]));
875 goto exit_get_fwddb;
876 }
877 if (fw_ddb_entry) {
Vikas Chaudhary2a49a782010-04-28 11:37:07 +0530878 options = le16_to_cpu(fw_ddb_entry->options);
879 if (options & DDB_OPT_IPV6_DEVICE) {
Vikas Chaudharyc2660df2010-07-10 14:51:02 +0530880 ql4_printk(KERN_INFO, ha, "%s: DDB[%d] MB0 %04x Tot %d "
Vikas Chaudhary2a49a782010-04-28 11:37:07 +0530881 "Next %d State %04x ConnErr %08x %pI6 "
882 ":%04d \"%s\"\n", __func__, fw_ddb_index,
883 mbox_sts[0], mbox_sts[2], mbox_sts[3],
884 mbox_sts[4], mbox_sts[5],
885 fw_ddb_entry->ip_addr,
886 le16_to_cpu(fw_ddb_entry->port),
887 fw_ddb_entry->iscsi_name);
888 } else {
Vikas Chaudharyc2660df2010-07-10 14:51:02 +0530889 ql4_printk(KERN_INFO, ha, "%s: DDB[%d] MB0 %04x Tot %d "
Vikas Chaudhary2a49a782010-04-28 11:37:07 +0530890 "Next %d State %04x ConnErr %08x %pI4 "
891 ":%04d \"%s\"\n", __func__, fw_ddb_index,
892 mbox_sts[0], mbox_sts[2], mbox_sts[3],
893 mbox_sts[4], mbox_sts[5],
894 fw_ddb_entry->ip_addr,
895 le16_to_cpu(fw_ddb_entry->port),
896 fw_ddb_entry->iscsi_name);
897 }
David Somayajuluafaf5a22006-09-19 10:28:00 -0700898 }
899 if (num_valid_ddb_entries)
900 *num_valid_ddb_entries = mbox_sts[2];
901 if (next_ddb_index)
902 *next_ddb_index = mbox_sts[3];
903 if (fw_ddb_device_state)
904 *fw_ddb_device_state = mbox_sts[4];
905
906 /*
907 * RA: This mailbox has been changed to pass connection error and
908 * details. Its true for ISP4010 as per Version E - Not sure when it
909 * was changed. Get the time2wait from the fw_dd_entry field :
910 * default_time2wait which we call it as minTime2Wait DEV_DB_ENTRY
911 * struct.
912 */
913 if (conn_err_detail)
914 *conn_err_detail = mbox_sts[5];
915 if (tcp_source_port_num)
Randy Dunlap14823382010-04-22 11:02:14 -0700916 *tcp_source_port_num = (uint16_t) (mbox_sts[6] >> 16);
David Somayajuluafaf5a22006-09-19 10:28:00 -0700917 if (connection_id)
918 *connection_id = (uint16_t) mbox_sts[6] & 0x00FF;
919 status = QLA_SUCCESS;
920
921exit_get_fwddb:
922 return status;
923}
924
Manish Rangankarb3a271a2011-07-25 13:48:53 -0500925int qla4xxx_conn_open(struct scsi_qla_host *ha, uint16_t fw_ddb_index)
926{
927 uint32_t mbox_cmd[MBOX_REG_COUNT];
928 uint32_t mbox_sts[MBOX_REG_COUNT];
929 int status;
930
931 memset(&mbox_cmd, 0, sizeof(mbox_cmd));
932 memset(&mbox_sts, 0, sizeof(mbox_sts));
933
934 mbox_cmd[0] = MBOX_CMD_CONN_OPEN;
935 mbox_cmd[1] = fw_ddb_index;
936
937 status = qla4xxx_mailbox_command(ha, MBOX_REG_COUNT, 2, &mbox_cmd[0],
938 &mbox_sts[0]);
939 DEBUG2(ql4_printk(KERN_INFO, ha,
940 "%s: status = %d mbx0 = 0x%x mbx1 = 0x%x\n",
941 __func__, status, mbox_sts[0], mbox_sts[1]));
942 return status;
943}
944
David Somayajuluafaf5a22006-09-19 10:28:00 -0700945/**
946 * qla4xxx_set_fwddb_entry - sets a ddb entry.
947 * @ha: Pointer to host adapter structure.
948 * @fw_ddb_index: Firmware's device database index
Manish Rangankarb3a271a2011-07-25 13:48:53 -0500949 * @fw_ddb_entry_dma: dma address of ddb entry
950 * @mbx_sts: mailbox 0 to be returned or NULL
David Somayajuluafaf5a22006-09-19 10:28:00 -0700951 *
952 * This routine initializes or updates the adapter's device database
Manish Rangankarb3a271a2011-07-25 13:48:53 -0500953 * entry for the specified device.
David Somayajuluafaf5a22006-09-19 10:28:00 -0700954 **/
955int qla4xxx_set_ddb_entry(struct scsi_qla_host * ha, uint16_t fw_ddb_index,
Manish Rangankarb3a271a2011-07-25 13:48:53 -0500956 dma_addr_t fw_ddb_entry_dma, uint32_t *mbx_sts)
David Somayajuluafaf5a22006-09-19 10:28:00 -0700957{
958 uint32_t mbox_cmd[MBOX_REG_COUNT];
959 uint32_t mbox_sts[MBOX_REG_COUNT];
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +0530960 int status;
David Somayajuluafaf5a22006-09-19 10:28:00 -0700961
962 /* Do not wait for completion. The firmware will send us an
963 * ASTS_DATABASE_CHANGED (0x8014) to notify us of the login status.
964 */
965 memset(&mbox_cmd, 0, sizeof(mbox_cmd));
966 memset(&mbox_sts, 0, sizeof(mbox_sts));
967
968 mbox_cmd[0] = MBOX_CMD_SET_DATABASE_ENTRY;
969 mbox_cmd[1] = (uint32_t) fw_ddb_index;
970 mbox_cmd[2] = LSDW(fw_ddb_entry_dma);
971 mbox_cmd[3] = MSDW(fw_ddb_entry_dma);
David C Somayajuluc0e344c2007-05-23 18:03:27 -0700972 mbox_cmd[4] = sizeof(struct dev_db_entry);
973
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +0530974 status = qla4xxx_mailbox_command(ha, MBOX_REG_COUNT, 5, &mbox_cmd[0],
Manish Rangankarb3a271a2011-07-25 13:48:53 -0500975 &mbox_sts[0]);
976 if (mbx_sts)
977 *mbx_sts = mbox_sts[0];
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +0530978 DEBUG2(printk("scsi%ld: %s: status=%d mbx0=0x%x mbx4=0x%x\n",
979 ha->host_no, __func__, status, mbox_sts[0], mbox_sts[4]);)
980
981 return status;
David Somayajuluafaf5a22006-09-19 10:28:00 -0700982}
983
Manish Rangankarb3a271a2011-07-25 13:48:53 -0500984int qla4xxx_session_logout_ddb(struct scsi_qla_host *ha,
985 struct ddb_entry *ddb_entry, int options)
986{
987 int status;
988 uint32_t mbox_cmd[MBOX_REG_COUNT];
989 uint32_t mbox_sts[MBOX_REG_COUNT];
990
991 memset(&mbox_cmd, 0, sizeof(mbox_cmd));
992 memset(&mbox_sts, 0, sizeof(mbox_sts));
993
994 mbox_cmd[0] = MBOX_CMD_CONN_CLOSE_SESS_LOGOUT;
995 mbox_cmd[1] = ddb_entry->fw_ddb_index;
996 mbox_cmd[3] = options;
997
998 status = qla4xxx_mailbox_command(ha, MBOX_REG_COUNT, 2, &mbox_cmd[0],
999 &mbox_sts[0]);
1000 if (status != QLA_SUCCESS) {
1001 DEBUG2(ql4_printk(KERN_INFO, ha,
1002 "%s: MBOX_CMD_CONN_CLOSE_SESS_LOGOUT "
1003 "failed sts %04X %04X", __func__,
1004 mbox_sts[0], mbox_sts[1]));
Nilesh Javalide2efea2013-12-16 06:49:40 -05001005 if ((mbox_sts[0] == MBOX_STS_COMMAND_ERROR) &&
1006 (mbox_sts[1] == DDB_NOT_LOGGED_IN)) {
1007 set_bit(DDB_CONN_CLOSE_FAILURE, &ddb_entry->flags);
1008 }
Manish Rangankarb3a271a2011-07-25 13:48:53 -05001009 }
1010
1011 return status;
1012}
1013
David Somayajuluafaf5a22006-09-19 10:28:00 -07001014/**
1015 * qla4xxx_get_crash_record - retrieves crash record.
1016 * @ha: Pointer to host adapter structure.
1017 *
1018 * This routine retrieves a crash record from the QLA4010 after an 8002h aen.
1019 **/
1020void qla4xxx_get_crash_record(struct scsi_qla_host * ha)
1021{
1022 uint32_t mbox_cmd[MBOX_REG_COUNT];
1023 uint32_t mbox_sts[MBOX_REG_COUNT];
1024 struct crash_record *crash_record = NULL;
1025 dma_addr_t crash_record_dma = 0;
1026 uint32_t crash_record_size = 0;
David C Somayajuluc0e344c2007-05-23 18:03:27 -07001027
David Somayajuluafaf5a22006-09-19 10:28:00 -07001028 memset(&mbox_cmd, 0, sizeof(mbox_cmd));
1029 memset(&mbox_sts, 0, sizeof(mbox_cmd));
1030
1031 /* Get size of crash record. */
1032 mbox_cmd[0] = MBOX_CMD_GET_CRASH_RECORD;
David C Somayajuluc0e344c2007-05-23 18:03:27 -07001033
1034 if (qla4xxx_mailbox_command(ha, MBOX_REG_COUNT, 5, &mbox_cmd[0], &mbox_sts[0]) !=
David Somayajuluafaf5a22006-09-19 10:28:00 -07001035 QLA_SUCCESS) {
1036 DEBUG2(printk("scsi%ld: %s: ERROR: Unable to retrieve size!\n",
1037 ha->host_no, __func__));
1038 goto exit_get_crash_record;
1039 }
1040 crash_record_size = mbox_sts[4];
1041 if (crash_record_size == 0) {
1042 DEBUG2(printk("scsi%ld: %s: ERROR: Crash record size is 0!\n",
1043 ha->host_no, __func__));
1044 goto exit_get_crash_record;
1045 }
1046
1047 /* Alloc Memory for Crash Record. */
1048 crash_record = dma_alloc_coherent(&ha->pdev->dev, crash_record_size,
1049 &crash_record_dma, GFP_KERNEL);
1050 if (crash_record == NULL)
1051 goto exit_get_crash_record;
1052
1053 /* Get Crash Record. */
David C Somayajuluc0e344c2007-05-23 18:03:27 -07001054 memset(&mbox_cmd, 0, sizeof(mbox_cmd));
1055 memset(&mbox_sts, 0, sizeof(mbox_cmd));
1056
David Somayajuluafaf5a22006-09-19 10:28:00 -07001057 mbox_cmd[0] = MBOX_CMD_GET_CRASH_RECORD;
1058 mbox_cmd[2] = LSDW(crash_record_dma);
1059 mbox_cmd[3] = MSDW(crash_record_dma);
1060 mbox_cmd[4] = crash_record_size;
David C Somayajuluc0e344c2007-05-23 18:03:27 -07001061
1062 if (qla4xxx_mailbox_command(ha, MBOX_REG_COUNT, 5, &mbox_cmd[0], &mbox_sts[0]) !=
David Somayajuluafaf5a22006-09-19 10:28:00 -07001063 QLA_SUCCESS)
1064 goto exit_get_crash_record;
1065
1066 /* Dump Crash Record. */
1067
1068exit_get_crash_record:
1069 if (crash_record)
1070 dma_free_coherent(&ha->pdev->dev, crash_record_size,
1071 crash_record, crash_record_dma);
1072}
1073
1074/**
1075 * qla4xxx_get_conn_event_log - retrieves connection event log
1076 * @ha: Pointer to host adapter structure.
1077 **/
1078void qla4xxx_get_conn_event_log(struct scsi_qla_host * ha)
1079{
1080 uint32_t mbox_cmd[MBOX_REG_COUNT];
1081 uint32_t mbox_sts[MBOX_REG_COUNT];
1082 struct conn_event_log_entry *event_log = NULL;
1083 dma_addr_t event_log_dma = 0;
1084 uint32_t event_log_size = 0;
1085 uint32_t num_valid_entries;
1086 uint32_t oldest_entry = 0;
1087 uint32_t max_event_log_entries;
1088 uint8_t i;
1089
David Somayajuluafaf5a22006-09-19 10:28:00 -07001090 memset(&mbox_cmd, 0, sizeof(mbox_cmd));
1091 memset(&mbox_sts, 0, sizeof(mbox_cmd));
1092
1093 /* Get size of crash record. */
1094 mbox_cmd[0] = MBOX_CMD_GET_CONN_EVENT_LOG;
David C Somayajuluc0e344c2007-05-23 18:03:27 -07001095
1096 if (qla4xxx_mailbox_command(ha, MBOX_REG_COUNT, 5, &mbox_cmd[0], &mbox_sts[0]) !=
David Somayajuluafaf5a22006-09-19 10:28:00 -07001097 QLA_SUCCESS)
1098 goto exit_get_event_log;
1099
1100 event_log_size = mbox_sts[4];
1101 if (event_log_size == 0)
1102 goto exit_get_event_log;
1103
1104 /* Alloc Memory for Crash Record. */
1105 event_log = dma_alloc_coherent(&ha->pdev->dev, event_log_size,
1106 &event_log_dma, GFP_KERNEL);
1107 if (event_log == NULL)
1108 goto exit_get_event_log;
1109
1110 /* Get Crash Record. */
David C Somayajuluc0e344c2007-05-23 18:03:27 -07001111 memset(&mbox_cmd, 0, sizeof(mbox_cmd));
1112 memset(&mbox_sts, 0, sizeof(mbox_cmd));
1113
David Somayajuluafaf5a22006-09-19 10:28:00 -07001114 mbox_cmd[0] = MBOX_CMD_GET_CONN_EVENT_LOG;
1115 mbox_cmd[2] = LSDW(event_log_dma);
1116 mbox_cmd[3] = MSDW(event_log_dma);
David C Somayajuluc0e344c2007-05-23 18:03:27 -07001117
1118 if (qla4xxx_mailbox_command(ha, MBOX_REG_COUNT, 5, &mbox_cmd[0], &mbox_sts[0]) !=
David Somayajuluafaf5a22006-09-19 10:28:00 -07001119 QLA_SUCCESS) {
1120 DEBUG2(printk("scsi%ld: %s: ERROR: Unable to retrieve event "
1121 "log!\n", ha->host_no, __func__));
1122 goto exit_get_event_log;
1123 }
1124
1125 /* Dump Event Log. */
1126 num_valid_entries = mbox_sts[1];
1127
1128 max_event_log_entries = event_log_size /
1129 sizeof(struct conn_event_log_entry);
1130
1131 if (num_valid_entries > max_event_log_entries)
1132 oldest_entry = num_valid_entries % max_event_log_entries;
1133
1134 DEBUG3(printk("scsi%ld: Connection Event Log Dump (%d entries):\n",
1135 ha->host_no, num_valid_entries));
1136
Andrew Vasquez11010fe2006-10-06 09:54:59 -07001137 if (ql4xextended_error_logging == 3) {
David Somayajuluafaf5a22006-09-19 10:28:00 -07001138 if (oldest_entry == 0) {
1139 /* Circular Buffer has not wrapped around */
1140 for (i=0; i < num_valid_entries; i++) {
1141 qla4xxx_dump_buffer((uint8_t *)event_log+
1142 (i*sizeof(*event_log)),
1143 sizeof(*event_log));
1144 }
1145 }
1146 else {
1147 /* Circular Buffer has wrapped around -
1148 * display accordingly*/
1149 for (i=oldest_entry; i < max_event_log_entries; i++) {
1150 qla4xxx_dump_buffer((uint8_t *)event_log+
1151 (i*sizeof(*event_log)),
1152 sizeof(*event_log));
1153 }
1154 for (i=0; i < oldest_entry; i++) {
1155 qla4xxx_dump_buffer((uint8_t *)event_log+
1156 (i*sizeof(*event_log)),
1157 sizeof(*event_log));
1158 }
1159 }
1160 }
1161
1162exit_get_event_log:
1163 if (event_log)
1164 dma_free_coherent(&ha->pdev->dev, event_log_size, event_log,
1165 event_log_dma);
1166}
1167
1168/**
Vikas Chaudhary09a0f712010-04-28 11:42:24 +05301169 * qla4xxx_abort_task - issues Abort Task
1170 * @ha: Pointer to host adapter structure.
1171 * @srb: Pointer to srb entry
1172 *
1173 * This routine performs a LUN RESET on the specified target/lun.
1174 * The caller must ensure that the ddb_entry and lun_entry pointers
1175 * are valid before calling this routine.
1176 **/
1177int qla4xxx_abort_task(struct scsi_qla_host *ha, struct srb *srb)
1178{
1179 uint32_t mbox_cmd[MBOX_REG_COUNT];
1180 uint32_t mbox_sts[MBOX_REG_COUNT];
1181 struct scsi_cmnd *cmd = srb->cmd;
1182 int status = QLA_SUCCESS;
1183 unsigned long flags = 0;
1184 uint32_t index;
1185
1186 /*
1187 * Send abort task command to ISP, so that the ISP will return
1188 * request with ABORT status
1189 */
1190 memset(&mbox_cmd, 0, sizeof(mbox_cmd));
1191 memset(&mbox_sts, 0, sizeof(mbox_sts));
1192
1193 spin_lock_irqsave(&ha->hardware_lock, flags);
1194 index = (unsigned long)(unsigned char *)cmd->host_scribble;
1195 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1196
1197 /* Firmware already posted completion on response queue */
1198 if (index == MAX_SRBS)
1199 return status;
1200
1201 mbox_cmd[0] = MBOX_CMD_ABORT_TASK;
Karen Higgins6790d4f2010-12-02 22:12:22 -08001202 mbox_cmd[1] = srb->ddb->fw_ddb_index;
Vikas Chaudhary09a0f712010-04-28 11:42:24 +05301203 mbox_cmd[2] = index;
1204 /* Immediate Command Enable */
1205 mbox_cmd[5] = 0x01;
1206
1207 qla4xxx_mailbox_command(ha, MBOX_REG_COUNT, 5, &mbox_cmd[0],
1208 &mbox_sts[0]);
1209 if (mbox_sts[0] != MBOX_STS_COMMAND_COMPLETE) {
1210 status = QLA_ERROR;
1211
1212 DEBUG2(printk(KERN_WARNING "scsi%ld:%d:%d: abort task FAILED: "
1213 "mbx0=%04X, mb1=%04X, mb2=%04X, mb3=%04X, mb4=%04X\n",
1214 ha->host_no, cmd->device->id, cmd->device->lun, mbox_sts[0],
1215 mbox_sts[1], mbox_sts[2], mbox_sts[3], mbox_sts[4]));
1216 }
1217
1218 return status;
1219}
1220
1221/**
David Somayajuluafaf5a22006-09-19 10:28:00 -07001222 * qla4xxx_reset_lun - issues LUN Reset
1223 * @ha: Pointer to host adapter structure.
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05301224 * @ddb_entry: Pointer to device database entry
1225 * @lun: lun number
David Somayajuluafaf5a22006-09-19 10:28:00 -07001226 *
1227 * This routine performs a LUN RESET on the specified target/lun.
1228 * The caller must ensure that the ddb_entry and lun_entry pointers
1229 * are valid before calling this routine.
1230 **/
1231int qla4xxx_reset_lun(struct scsi_qla_host * ha, struct ddb_entry * ddb_entry,
1232 int lun)
1233{
1234 uint32_t mbox_cmd[MBOX_REG_COUNT];
1235 uint32_t mbox_sts[MBOX_REG_COUNT];
Vikas Chaudharyae3ae252013-03-07 05:43:11 -05001236 uint32_t scsi_lun[2];
David Somayajuluafaf5a22006-09-19 10:28:00 -07001237 int status = QLA_SUCCESS;
1238
1239 DEBUG2(printk("scsi%ld:%d:%d: lun reset issued\n", ha->host_no,
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05301240 ddb_entry->fw_ddb_index, lun));
David Somayajuluafaf5a22006-09-19 10:28:00 -07001241
1242 /*
1243 * Send lun reset command to ISP, so that the ISP will return all
1244 * outstanding requests with RESET status
1245 */
1246 memset(&mbox_cmd, 0, sizeof(mbox_cmd));
1247 memset(&mbox_sts, 0, sizeof(mbox_sts));
Vikas Chaudharyae3ae252013-03-07 05:43:11 -05001248 int_to_scsilun(lun, (struct scsi_lun *) scsi_lun);
David C Somayajuluc0e344c2007-05-23 18:03:27 -07001249
David Somayajuluafaf5a22006-09-19 10:28:00 -07001250 mbox_cmd[0] = MBOX_CMD_LUN_RESET;
1251 mbox_cmd[1] = ddb_entry->fw_ddb_index;
Vikas Chaudharyae3ae252013-03-07 05:43:11 -05001252 /* FW expects LUN bytes 0-3 in Incoming Mailbox 2
1253 * (LUN byte 0 is LSByte, byte 3 is MSByte) */
1254 mbox_cmd[2] = cpu_to_le32(scsi_lun[0]);
1255 /* FW expects LUN bytes 4-7 in Incoming Mailbox 3
1256 * (LUN byte 4 is LSByte, byte 7 is MSByte) */
1257 mbox_cmd[3] = cpu_to_le32(scsi_lun[1]);
David Somayajuluafaf5a22006-09-19 10:28:00 -07001258 mbox_cmd[5] = 0x01; /* Immediate Command Enable */
David C Somayajuluc0e344c2007-05-23 18:03:27 -07001259
1260 qla4xxx_mailbox_command(ha, MBOX_REG_COUNT, 1, &mbox_cmd[0], &mbox_sts[0]);
David Somayajuluafaf5a22006-09-19 10:28:00 -07001261 if (mbox_sts[0] != MBOX_STS_COMMAND_COMPLETE &&
1262 mbox_sts[0] != MBOX_STS_COMMAND_ERROR)
1263 status = QLA_ERROR;
1264
1265 return status;
1266}
1267
Mike Christiece545032008-02-29 18:25:20 -06001268/**
1269 * qla4xxx_reset_target - issues target Reset
1270 * @ha: Pointer to host adapter structure.
1271 * @db_entry: Pointer to device database entry
1272 * @un_entry: Pointer to lun entry structure
1273 *
1274 * This routine performs a TARGET RESET on the specified target.
1275 * The caller must ensure that the ddb_entry pointers
1276 * are valid before calling this routine.
1277 **/
1278int qla4xxx_reset_target(struct scsi_qla_host *ha,
1279 struct ddb_entry *ddb_entry)
1280{
1281 uint32_t mbox_cmd[MBOX_REG_COUNT];
1282 uint32_t mbox_sts[MBOX_REG_COUNT];
1283 int status = QLA_SUCCESS;
1284
1285 DEBUG2(printk("scsi%ld:%d: target reset issued\n", ha->host_no,
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05301286 ddb_entry->fw_ddb_index));
Mike Christiece545032008-02-29 18:25:20 -06001287
1288 /*
1289 * Send target reset command to ISP, so that the ISP will return all
1290 * outstanding requests with RESET status
1291 */
1292 memset(&mbox_cmd, 0, sizeof(mbox_cmd));
1293 memset(&mbox_sts, 0, sizeof(mbox_sts));
1294
1295 mbox_cmd[0] = MBOX_CMD_TARGET_WARM_RESET;
1296 mbox_cmd[1] = ddb_entry->fw_ddb_index;
1297 mbox_cmd[5] = 0x01; /* Immediate Command Enable */
1298
1299 qla4xxx_mailbox_command(ha, MBOX_REG_COUNT, 1, &mbox_cmd[0],
1300 &mbox_sts[0]);
1301 if (mbox_sts[0] != MBOX_STS_COMMAND_COMPLETE &&
1302 mbox_sts[0] != MBOX_STS_COMMAND_ERROR)
1303 status = QLA_ERROR;
1304
1305 return status;
1306}
David Somayajuluafaf5a22006-09-19 10:28:00 -07001307
1308int qla4xxx_get_flash(struct scsi_qla_host * ha, dma_addr_t dma_addr,
1309 uint32_t offset, uint32_t len)
1310{
1311 uint32_t mbox_cmd[MBOX_REG_COUNT];
1312 uint32_t mbox_sts[MBOX_REG_COUNT];
1313
1314 memset(&mbox_cmd, 0, sizeof(mbox_cmd));
1315 memset(&mbox_sts, 0, sizeof(mbox_sts));
David C Somayajuluc0e344c2007-05-23 18:03:27 -07001316
David Somayajuluafaf5a22006-09-19 10:28:00 -07001317 mbox_cmd[0] = MBOX_CMD_READ_FLASH;
1318 mbox_cmd[1] = LSDW(dma_addr);
1319 mbox_cmd[2] = MSDW(dma_addr);
1320 mbox_cmd[3] = offset;
1321 mbox_cmd[4] = len;
David C Somayajuluc0e344c2007-05-23 18:03:27 -07001322
1323 if (qla4xxx_mailbox_command(ha, MBOX_REG_COUNT, 2, &mbox_cmd[0], &mbox_sts[0]) !=
David Somayajuluafaf5a22006-09-19 10:28:00 -07001324 QLA_SUCCESS) {
1325 DEBUG2(printk("scsi%ld: %s: MBOX_CMD_READ_FLASH, failed w/ "
1326 "status %04X %04X, offset %08x, len %08x\n", ha->host_no,
1327 __func__, mbox_sts[0], mbox_sts[1], offset, len));
1328 return QLA_ERROR;
1329 }
1330 return QLA_SUCCESS;
1331}
1332
1333/**
Harish Zunjarrao7ad633c2011-05-17 23:17:11 -07001334 * qla4xxx_about_firmware - gets FW, iscsi draft and boot loader version
David Somayajuluafaf5a22006-09-19 10:28:00 -07001335 * @ha: Pointer to host adapter structure.
1336 *
Harish Zunjarrao7ad633c2011-05-17 23:17:11 -07001337 * Retrieves the FW version, iSCSI draft version & bootloader version of HBA.
1338 * Mailboxes 2 & 3 may hold an address for data. Make sure that we write 0 to
1339 * those mailboxes, if unused.
David Somayajuluafaf5a22006-09-19 10:28:00 -07001340 **/
Harish Zunjarrao7ad633c2011-05-17 23:17:11 -07001341int qla4xxx_about_firmware(struct scsi_qla_host *ha)
David Somayajuluafaf5a22006-09-19 10:28:00 -07001342{
Harish Zunjarrao7ad633c2011-05-17 23:17:11 -07001343 struct about_fw_info *about_fw = NULL;
1344 dma_addr_t about_fw_dma;
David Somayajuluafaf5a22006-09-19 10:28:00 -07001345 uint32_t mbox_cmd[MBOX_REG_COUNT];
1346 uint32_t mbox_sts[MBOX_REG_COUNT];
Harish Zunjarrao7ad633c2011-05-17 23:17:11 -07001347 int status = QLA_ERROR;
David Somayajuluafaf5a22006-09-19 10:28:00 -07001348
Harish Zunjarrao7ad633c2011-05-17 23:17:11 -07001349 about_fw = dma_alloc_coherent(&ha->pdev->dev,
1350 sizeof(struct about_fw_info),
1351 &about_fw_dma, GFP_KERNEL);
1352 if (!about_fw) {
1353 DEBUG2(ql4_printk(KERN_ERR, ha, "%s: Unable to alloc memory "
1354 "for about_fw\n", __func__));
1355 return status;
1356 }
1357
1358 memset(about_fw, 0, sizeof(struct about_fw_info));
David Somayajuluafaf5a22006-09-19 10:28:00 -07001359 memset(&mbox_cmd, 0, sizeof(mbox_cmd));
1360 memset(&mbox_sts, 0, sizeof(mbox_sts));
David C Somayajuluc0e344c2007-05-23 18:03:27 -07001361
David Somayajuluafaf5a22006-09-19 10:28:00 -07001362 mbox_cmd[0] = MBOX_CMD_ABOUT_FW;
Harish Zunjarrao7ad633c2011-05-17 23:17:11 -07001363 mbox_cmd[2] = LSDW(about_fw_dma);
1364 mbox_cmd[3] = MSDW(about_fw_dma);
1365 mbox_cmd[4] = sizeof(struct about_fw_info);
David C Somayajuluc0e344c2007-05-23 18:03:27 -07001366
Harish Zunjarrao7ad633c2011-05-17 23:17:11 -07001367 status = qla4xxx_mailbox_command(ha, MBOX_REG_COUNT, MBOX_REG_COUNT,
1368 &mbox_cmd[0], &mbox_sts[0]);
1369 if (status != QLA_SUCCESS) {
1370 DEBUG2(ql4_printk(KERN_WARNING, ha, "%s: MBOX_CMD_ABOUT_FW "
1371 "failed w/ status %04X\n", __func__,
1372 mbox_sts[0]));
1373 goto exit_about_fw;
David Somayajuluafaf5a22006-09-19 10:28:00 -07001374 }
1375
Harish Zunjarrao7ad633c2011-05-17 23:17:11 -07001376 /* Save version information. */
Adheer Chandravanshieee06a02013-07-08 08:33:10 -04001377 ha->fw_info.fw_major = le16_to_cpu(about_fw->fw_major);
1378 ha->fw_info.fw_minor = le16_to_cpu(about_fw->fw_minor);
1379 ha->fw_info.fw_patch = le16_to_cpu(about_fw->fw_patch);
1380 ha->fw_info.fw_build = le16_to_cpu(about_fw->fw_build);
1381 memcpy(ha->fw_info.fw_build_date, about_fw->fw_build_date,
1382 sizeof(about_fw->fw_build_date));
1383 memcpy(ha->fw_info.fw_build_time, about_fw->fw_build_time,
1384 sizeof(about_fw->fw_build_time));
1385 strcpy((char *)ha->fw_info.fw_build_user,
1386 skip_spaces((char *)about_fw->fw_build_user));
1387 ha->fw_info.fw_load_source = le16_to_cpu(about_fw->fw_load_source);
1388 ha->fw_info.iscsi_major = le16_to_cpu(about_fw->iscsi_major);
1389 ha->fw_info.iscsi_minor = le16_to_cpu(about_fw->iscsi_minor);
1390 ha->fw_info.bootload_major = le16_to_cpu(about_fw->bootload_major);
1391 ha->fw_info.bootload_minor = le16_to_cpu(about_fw->bootload_minor);
1392 ha->fw_info.bootload_patch = le16_to_cpu(about_fw->bootload_patch);
1393 ha->fw_info.bootload_build = le16_to_cpu(about_fw->bootload_build);
1394 strcpy((char *)ha->fw_info.extended_timestamp,
1395 skip_spaces((char *)about_fw->extended_timestamp));
1396
1397 ha->fw_uptime_secs = le32_to_cpu(mbox_sts[5]);
1398 ha->fw_uptime_msecs = le32_to_cpu(mbox_sts[6]);
Harish Zunjarrao7ad633c2011-05-17 23:17:11 -07001399 status = QLA_SUCCESS;
David Somayajuluafaf5a22006-09-19 10:28:00 -07001400
Harish Zunjarrao7ad633c2011-05-17 23:17:11 -07001401exit_about_fw:
1402 dma_free_coherent(&ha->pdev->dev, sizeof(struct about_fw_info),
1403 about_fw, about_fw_dma);
1404 return status;
David Somayajuluafaf5a22006-09-19 10:28:00 -07001405}
1406
Adheer Chandravanshi1e9e2be2013-03-22 07:41:31 -04001407int qla4xxx_get_default_ddb(struct scsi_qla_host *ha, uint32_t options,
1408 dma_addr_t dma_addr)
David Somayajuluafaf5a22006-09-19 10:28:00 -07001409{
1410 uint32_t mbox_cmd[MBOX_REG_COUNT];
1411 uint32_t mbox_sts[MBOX_REG_COUNT];
1412
1413 memset(&mbox_cmd, 0, sizeof(mbox_cmd));
1414 memset(&mbox_sts, 0, sizeof(mbox_sts));
1415
1416 mbox_cmd[0] = MBOX_CMD_GET_DATABASE_ENTRY_DEFAULTS;
Manish Rangankarb3a271a2011-07-25 13:48:53 -05001417 mbox_cmd[1] = options;
David Somayajuluafaf5a22006-09-19 10:28:00 -07001418 mbox_cmd[2] = LSDW(dma_addr);
1419 mbox_cmd[3] = MSDW(dma_addr);
1420
David C Somayajuluc0e344c2007-05-23 18:03:27 -07001421 if (qla4xxx_mailbox_command(ha, MBOX_REG_COUNT, 1, &mbox_cmd[0], &mbox_sts[0]) !=
David Somayajuluafaf5a22006-09-19 10:28:00 -07001422 QLA_SUCCESS) {
1423 DEBUG2(printk("scsi%ld: %s: failed status %04X\n",
1424 ha->host_no, __func__, mbox_sts[0]));
1425 return QLA_ERROR;
1426 }
1427 return QLA_SUCCESS;
1428}
1429
Manish Rangankarb3a271a2011-07-25 13:48:53 -05001430int qla4xxx_req_ddb_entry(struct scsi_qla_host *ha, uint32_t ddb_index,
1431 uint32_t *mbx_sts)
David Somayajuluafaf5a22006-09-19 10:28:00 -07001432{
Manish Rangankarb3a271a2011-07-25 13:48:53 -05001433 int status;
David Somayajuluafaf5a22006-09-19 10:28:00 -07001434 uint32_t mbox_cmd[MBOX_REG_COUNT];
1435 uint32_t mbox_sts[MBOX_REG_COUNT];
1436
1437 memset(&mbox_cmd, 0, sizeof(mbox_cmd));
1438 memset(&mbox_sts, 0, sizeof(mbox_sts));
1439
1440 mbox_cmd[0] = MBOX_CMD_REQUEST_DATABASE_ENTRY;
Manish Rangankarb3a271a2011-07-25 13:48:53 -05001441 mbox_cmd[1] = ddb_index;
David Somayajuluafaf5a22006-09-19 10:28:00 -07001442
Manish Rangankarb3a271a2011-07-25 13:48:53 -05001443 status = qla4xxx_mailbox_command(ha, MBOX_REG_COUNT, 1, &mbox_cmd[0],
1444 &mbox_sts[0]);
1445 if (status != QLA_SUCCESS) {
1446 DEBUG2(ql4_printk(KERN_ERR, ha, "%s: failed status %04X\n",
1447 __func__, mbox_sts[0]));
David Somayajuluafaf5a22006-09-19 10:28:00 -07001448 }
1449
Manish Rangankarb3a271a2011-07-25 13:48:53 -05001450 *mbx_sts = mbox_sts[0];
1451 return status;
David Somayajuluafaf5a22006-09-19 10:28:00 -07001452}
1453
Manish Rangankarb3a271a2011-07-25 13:48:53 -05001454int qla4xxx_clear_ddb_entry(struct scsi_qla_host *ha, uint32_t ddb_index)
1455{
1456 int status;
1457 uint32_t mbox_cmd[MBOX_REG_COUNT];
1458 uint32_t mbox_sts[MBOX_REG_COUNT];
1459
1460 memset(&mbox_cmd, 0, sizeof(mbox_cmd));
1461 memset(&mbox_sts, 0, sizeof(mbox_sts));
1462
1463 mbox_cmd[0] = MBOX_CMD_CLEAR_DATABASE_ENTRY;
1464 mbox_cmd[1] = ddb_index;
1465
1466 status = qla4xxx_mailbox_command(ha, 2, 1, &mbox_cmd[0],
1467 &mbox_sts[0]);
1468 if (status != QLA_SUCCESS) {
1469 DEBUG2(ql4_printk(KERN_ERR, ha, "%s: failed status %04X\n",
1470 __func__, mbox_sts[0]));
1471 }
1472
1473 return status;
1474}
1475
Mike Christied00efe32011-07-25 13:48:38 -05001476int qla4xxx_set_flash(struct scsi_qla_host *ha, dma_addr_t dma_addr,
1477 uint32_t offset, uint32_t length, uint32_t options)
1478{
1479 uint32_t mbox_cmd[MBOX_REG_COUNT];
1480 uint32_t mbox_sts[MBOX_REG_COUNT];
1481 int status = QLA_SUCCESS;
1482
1483 memset(&mbox_cmd, 0, sizeof(mbox_cmd));
1484 memset(&mbox_sts, 0, sizeof(mbox_sts));
1485
1486 mbox_cmd[0] = MBOX_CMD_WRITE_FLASH;
1487 mbox_cmd[1] = LSDW(dma_addr);
1488 mbox_cmd[2] = MSDW(dma_addr);
1489 mbox_cmd[3] = offset;
1490 mbox_cmd[4] = length;
1491 mbox_cmd[5] = options;
1492
1493 status = qla4xxx_mailbox_command(ha, 6, 2, &mbox_cmd[0], &mbox_sts[0]);
1494 if (status != QLA_SUCCESS) {
1495 DEBUG2(ql4_printk(KERN_WARNING, ha, "%s: MBOX_CMD_WRITE_FLASH "
1496 "failed w/ status %04X, mbx1 %04X\n",
1497 __func__, mbox_sts[0], mbox_sts[1]));
1498 }
1499 return status;
1500}
1501
Manish Rangankar2a991c22011-07-25 13:48:55 -05001502int qla4xxx_bootdb_by_index(struct scsi_qla_host *ha,
1503 struct dev_db_entry *fw_ddb_entry,
1504 dma_addr_t fw_ddb_entry_dma, uint16_t ddb_index)
1505{
1506 uint32_t dev_db_start_offset = FLASH_OFFSET_DB_INFO;
1507 uint32_t dev_db_end_offset;
1508 int status = QLA_ERROR;
1509
1510 memset(fw_ddb_entry, 0, sizeof(*fw_ddb_entry));
1511
1512 dev_db_start_offset += (ddb_index * sizeof(*fw_ddb_entry));
1513 dev_db_end_offset = FLASH_OFFSET_DB_END;
1514
1515 if (dev_db_start_offset > dev_db_end_offset) {
1516 DEBUG2(ql4_printk(KERN_ERR, ha,
1517 "%s:Invalid DDB index %d", __func__,
1518 ddb_index));
1519 goto exit_bootdb_failed;
1520 }
1521
1522 if (qla4xxx_get_flash(ha, fw_ddb_entry_dma, dev_db_start_offset,
1523 sizeof(*fw_ddb_entry)) != QLA_SUCCESS) {
1524 ql4_printk(KERN_ERR, ha, "scsi%ld: %s: Get Flash"
1525 "failed\n", ha->host_no, __func__);
1526 goto exit_bootdb_failed;
1527 }
1528
1529 if (fw_ddb_entry->cookie == DDB_VALID_COOKIE)
1530 status = QLA_SUCCESS;
1531
1532exit_bootdb_failed:
1533 return status;
1534}
1535
Adheer Chandravanshi1e9e2be2013-03-22 07:41:31 -04001536int qla4xxx_flashdb_by_index(struct scsi_qla_host *ha,
1537 struct dev_db_entry *fw_ddb_entry,
1538 dma_addr_t fw_ddb_entry_dma, uint16_t ddb_index)
1539{
Adheer Chandravanshi039acc12013-04-05 07:06:06 -04001540 uint32_t dev_db_start_offset;
Adheer Chandravanshi1e9e2be2013-03-22 07:41:31 -04001541 uint32_t dev_db_end_offset;
1542 int status = QLA_ERROR;
1543
1544 memset(fw_ddb_entry, 0, sizeof(*fw_ddb_entry));
1545
1546 if (is_qla40XX(ha)) {
1547 dev_db_start_offset = FLASH_OFFSET_DB_INFO;
Adheer Chandravanshi039acc12013-04-05 07:06:06 -04001548 dev_db_end_offset = FLASH_OFFSET_DB_END;
Adheer Chandravanshi1e9e2be2013-03-22 07:41:31 -04001549 } else {
1550 dev_db_start_offset = FLASH_RAW_ACCESS_ADDR +
1551 (ha->hw.flt_region_ddb << 2);
1552 /* flt_ddb_size is DDB table size for both ports
1553 * so divide it by 2 to calculate the offset for second port
1554 */
1555 if (ha->port_num == 1)
1556 dev_db_start_offset += (ha->hw.flt_ddb_size / 2);
Adheer Chandravanshi039acc12013-04-05 07:06:06 -04001557
1558 dev_db_end_offset = dev_db_start_offset +
1559 (ha->hw.flt_ddb_size / 2);
Adheer Chandravanshi1e9e2be2013-03-22 07:41:31 -04001560 }
1561
Adheer Chandravanshi1e9e2be2013-03-22 07:41:31 -04001562 dev_db_start_offset += (ddb_index * sizeof(*fw_ddb_entry));
1563
1564 if (dev_db_start_offset > dev_db_end_offset) {
1565 DEBUG2(ql4_printk(KERN_ERR, ha,
1566 "%s:Invalid DDB index %d", __func__,
1567 ddb_index));
1568 goto exit_fdb_failed;
1569 }
1570
1571 if (qla4xxx_get_flash(ha, fw_ddb_entry_dma, dev_db_start_offset,
1572 sizeof(*fw_ddb_entry)) != QLA_SUCCESS) {
1573 ql4_printk(KERN_ERR, ha, "scsi%ld: %s: Get Flash failed\n",
1574 ha->host_no, __func__);
1575 goto exit_fdb_failed;
1576 }
1577
1578 if (fw_ddb_entry->cookie == DDB_VALID_COOKIE)
1579 status = QLA_SUCCESS;
1580
1581exit_fdb_failed:
1582 return status;
1583}
1584
Manish Rangankar2a991c22011-07-25 13:48:55 -05001585int qla4xxx_get_chap(struct scsi_qla_host *ha, char *username, char *password,
1586 uint16_t idx)
1587{
1588 int ret = 0;
1589 int rval = QLA_ERROR;
Lalit Chandivade45494152011-10-07 16:55:42 -07001590 uint32_t offset = 0, chap_size;
Manish Rangankar2a991c22011-07-25 13:48:55 -05001591 struct ql4_chap_table *chap_table;
1592 dma_addr_t chap_dma;
1593
1594 chap_table = dma_pool_alloc(ha->chap_dma_pool, GFP_KERNEL, &chap_dma);
Dan Carpenter50e92912013-01-30 10:07:31 +03001595 if (chap_table == NULL)
1596 return -ENOMEM;
Manish Rangankar2a991c22011-07-25 13:48:55 -05001597
Lalit Chandivade45494152011-10-07 16:55:42 -07001598 chap_size = sizeof(struct ql4_chap_table);
1599 memset(chap_table, 0, chap_size);
Manish Rangankar2a991c22011-07-25 13:48:55 -05001600
Lalit Chandivade45494152011-10-07 16:55:42 -07001601 if (is_qla40XX(ha))
1602 offset = FLASH_CHAP_OFFSET | (idx * chap_size);
1603 else {
1604 offset = FLASH_RAW_ACCESS_ADDR + (ha->hw.flt_region_chap << 2);
1605 /* flt_chap_size is CHAP table size for both ports
1606 * so divide it by 2 to calculate the offset for second port
1607 */
1608 if (ha->port_num == 1)
1609 offset += (ha->hw.flt_chap_size / 2);
1610 offset += (idx * chap_size);
1611 }
Manish Rangankar2a991c22011-07-25 13:48:55 -05001612
Lalit Chandivade45494152011-10-07 16:55:42 -07001613 rval = qla4xxx_get_flash(ha, chap_dma, offset, chap_size);
Manish Rangankar2a991c22011-07-25 13:48:55 -05001614 if (rval != QLA_SUCCESS) {
1615 ret = -EINVAL;
1616 goto exit_get_chap;
1617 }
1618
1619 DEBUG2(ql4_printk(KERN_INFO, ha, "Chap Cookie: x%x\n",
1620 __le16_to_cpu(chap_table->cookie)));
1621
1622 if (__le16_to_cpu(chap_table->cookie) != CHAP_VALID_COOKIE) {
1623 ql4_printk(KERN_ERR, ha, "No valid chap entry found\n");
1624 goto exit_get_chap;
1625 }
1626
1627 strncpy(password, chap_table->secret, QL4_CHAP_MAX_SECRET_LEN);
1628 strncpy(username, chap_table->name, QL4_CHAP_MAX_NAME_LEN);
1629 chap_table->cookie = __constant_cpu_to_le16(CHAP_VALID_COOKIE);
1630
1631exit_get_chap:
1632 dma_pool_free(ha->chap_dma_pool, chap_table, chap_dma);
1633 return ret;
1634}
1635
Adheer Chandravanshi26ffd7b2013-09-17 07:54:49 -04001636/**
1637 * qla4xxx_set_chap - Make a chap entry at the given index
1638 * @ha: pointer to adapter structure
1639 * @username: CHAP username to set
1640 * @password: CHAP password to set
1641 * @idx: CHAP index at which to make the entry
1642 * @bidi: type of chap entry (chap_in or chap_out)
1643 *
1644 * Create chap entry at the given index with the information provided.
1645 *
1646 * Note: Caller should acquire the chap lock before getting here.
1647 **/
1648int qla4xxx_set_chap(struct scsi_qla_host *ha, char *username, char *password,
1649 uint16_t idx, int bidi)
Manish Rangankarb3a271a2011-07-25 13:48:53 -05001650{
1651 int ret = 0;
1652 int rval = QLA_ERROR;
1653 uint32_t offset = 0;
1654 struct ql4_chap_table *chap_table;
Adheer Chandravanshib1d0b632013-09-17 07:54:47 -04001655 uint32_t chap_size = 0;
Manish Rangankarb3a271a2011-07-25 13:48:53 -05001656 dma_addr_t chap_dma;
1657
1658 chap_table = dma_pool_alloc(ha->chap_dma_pool, GFP_KERNEL, &chap_dma);
1659 if (chap_table == NULL) {
1660 ret = -ENOMEM;
1661 goto exit_set_chap;
1662 }
1663
1664 memset(chap_table, 0, sizeof(struct ql4_chap_table));
1665 if (bidi)
1666 chap_table->flags |= BIT_6; /* peer */
1667 else
1668 chap_table->flags |= BIT_7; /* local */
1669 chap_table->secret_len = strlen(password);
1670 strncpy(chap_table->secret, password, MAX_CHAP_SECRET_LEN);
1671 strncpy(chap_table->name, username, MAX_CHAP_NAME_LEN);
1672 chap_table->cookie = __constant_cpu_to_le16(CHAP_VALID_COOKIE);
Adheer Chandravanshib1d0b632013-09-17 07:54:47 -04001673
1674 if (is_qla40XX(ha)) {
1675 chap_size = MAX_CHAP_ENTRIES_40XX * sizeof(*chap_table);
1676 offset = FLASH_CHAP_OFFSET;
1677 } else { /* Single region contains CHAP info for both ports which is
1678 * divided into half for each port.
1679 */
1680 chap_size = ha->hw.flt_chap_size / 2;
1681 offset = FLASH_RAW_ACCESS_ADDR + (ha->hw.flt_region_chap << 2);
1682 if (ha->port_num == 1)
1683 offset += chap_size;
1684 }
1685
1686 offset += (idx * sizeof(struct ql4_chap_table));
Manish Rangankarb3a271a2011-07-25 13:48:53 -05001687 rval = qla4xxx_set_flash(ha, chap_dma, offset,
1688 sizeof(struct ql4_chap_table),
1689 FLASH_OPT_RMW_COMMIT);
Lalit Chandivade45494152011-10-07 16:55:42 -07001690
1691 if (rval == QLA_SUCCESS && ha->chap_list) {
1692 /* Update ha chap_list cache */
1693 memcpy((struct ql4_chap_table *)ha->chap_list + idx,
1694 chap_table, sizeof(struct ql4_chap_table));
1695 }
Manish Rangankarb3a271a2011-07-25 13:48:53 -05001696 dma_pool_free(ha->chap_dma_pool, chap_table, chap_dma);
1697 if (rval != QLA_SUCCESS)
1698 ret = -EINVAL;
1699
1700exit_set_chap:
1701 return ret;
1702}
1703
Adheer Chandravanshi1e9e2be2013-03-22 07:41:31 -04001704
1705int qla4xxx_get_uni_chap_at_index(struct scsi_qla_host *ha, char *username,
1706 char *password, uint16_t chap_index)
1707{
1708 int rval = QLA_ERROR;
1709 struct ql4_chap_table *chap_table = NULL;
1710 int max_chap_entries;
1711
1712 if (!ha->chap_list) {
1713 ql4_printk(KERN_ERR, ha, "Do not have CHAP table cache\n");
1714 rval = QLA_ERROR;
1715 goto exit_uni_chap;
1716 }
1717
1718 if (!username || !password) {
1719 ql4_printk(KERN_ERR, ha, "No memory for username & secret\n");
1720 rval = QLA_ERROR;
1721 goto exit_uni_chap;
1722 }
1723
1724 if (is_qla80XX(ha))
1725 max_chap_entries = (ha->hw.flt_chap_size / 2) /
1726 sizeof(struct ql4_chap_table);
1727 else
1728 max_chap_entries = MAX_CHAP_ENTRIES_40XX;
1729
1730 if (chap_index > max_chap_entries) {
1731 ql4_printk(KERN_ERR, ha, "Invalid Chap index\n");
1732 rval = QLA_ERROR;
1733 goto exit_uni_chap;
1734 }
1735
1736 mutex_lock(&ha->chap_sem);
1737 chap_table = (struct ql4_chap_table *)ha->chap_list + chap_index;
1738 if (chap_table->cookie != __constant_cpu_to_le16(CHAP_VALID_COOKIE)) {
1739 rval = QLA_ERROR;
1740 goto exit_unlock_uni_chap;
1741 }
1742
Adheer Chandravanshi33519ae2013-09-17 07:54:44 -04001743 if (!(chap_table->flags & BIT_7)) {
Adheer Chandravanshi1e9e2be2013-03-22 07:41:31 -04001744 ql4_printk(KERN_ERR, ha, "Unidirectional entry not set\n");
1745 rval = QLA_ERROR;
1746 goto exit_unlock_uni_chap;
1747 }
1748
1749 strncpy(password, chap_table->secret, MAX_CHAP_SECRET_LEN);
1750 strncpy(username, chap_table->name, MAX_CHAP_NAME_LEN);
1751
1752 rval = QLA_SUCCESS;
1753
1754exit_unlock_uni_chap:
1755 mutex_unlock(&ha->chap_sem);
1756exit_uni_chap:
1757 return rval;
1758}
1759
Lalit Chandivade45494152011-10-07 16:55:42 -07001760/**
1761 * qla4xxx_get_chap_index - Get chap index given username and secret
1762 * @ha: pointer to adapter structure
1763 * @username: CHAP username to be searched
1764 * @password: CHAP password to be searched
1765 * @bidi: Is this a BIDI CHAP
1766 * @chap_index: CHAP index to be returned
1767 *
1768 * Match the username and password in the chap_list, return the index if a
1769 * match is found. If a match is not found then add the entry in FLASH and
1770 * return the index at which entry is written in the FLASH.
1771 **/
Mike Christiefca9f042012-02-27 03:08:54 -08001772int qla4xxx_get_chap_index(struct scsi_qla_host *ha, char *username,
1773 char *password, int bidi, uint16_t *chap_index)
Lalit Chandivade45494152011-10-07 16:55:42 -07001774{
1775 int i, rval;
1776 int free_index = -1;
1777 int found_index = 0;
1778 int max_chap_entries = 0;
1779 struct ql4_chap_table *chap_table;
1780
Vikas Chaudharyd11b0ca2013-03-22 07:08:31 -04001781 if (is_qla80XX(ha))
Lalit Chandivade45494152011-10-07 16:55:42 -07001782 max_chap_entries = (ha->hw.flt_chap_size / 2) /
1783 sizeof(struct ql4_chap_table);
1784 else
1785 max_chap_entries = MAX_CHAP_ENTRIES_40XX;
1786
1787 if (!ha->chap_list) {
1788 ql4_printk(KERN_ERR, ha, "Do not have CHAP table cache\n");
1789 return QLA_ERROR;
1790 }
1791
Mike Christiefca9f042012-02-27 03:08:54 -08001792 if (!username || !password) {
1793 ql4_printk(KERN_ERR, ha, "Do not have username and psw\n");
1794 return QLA_ERROR;
1795 }
1796
Lalit Chandivade45494152011-10-07 16:55:42 -07001797 mutex_lock(&ha->chap_sem);
1798 for (i = 0; i < max_chap_entries; i++) {
1799 chap_table = (struct ql4_chap_table *)ha->chap_list + i;
1800 if (chap_table->cookie !=
1801 __constant_cpu_to_le16(CHAP_VALID_COOKIE)) {
1802 if (i > MAX_RESRV_CHAP_IDX && free_index == -1)
1803 free_index = i;
1804 continue;
1805 }
1806 if (bidi) {
1807 if (chap_table->flags & BIT_7)
1808 continue;
1809 } else {
1810 if (chap_table->flags & BIT_6)
1811 continue;
1812 }
1813 if (!strncmp(chap_table->secret, password,
1814 MAX_CHAP_SECRET_LEN) &&
1815 !strncmp(chap_table->name, username,
1816 MAX_CHAP_NAME_LEN)) {
1817 *chap_index = i;
1818 found_index = 1;
1819 break;
1820 }
1821 }
1822
1823 /* If chap entry is not present and a free index is available then
1824 * write the entry in flash
1825 */
1826 if (!found_index && free_index != -1) {
1827 rval = qla4xxx_set_chap(ha, username, password,
1828 free_index, bidi);
1829 if (!rval) {
1830 *chap_index = free_index;
1831 found_index = 1;
1832 }
1833 }
1834
1835 mutex_unlock(&ha->chap_sem);
1836
1837 if (found_index)
1838 return QLA_SUCCESS;
1839 return QLA_ERROR;
1840}
1841
Mike Christied00efe32011-07-25 13:48:38 -05001842int qla4xxx_conn_close_sess_logout(struct scsi_qla_host *ha,
1843 uint16_t fw_ddb_index,
1844 uint16_t connection_id,
1845 uint16_t option)
1846{
1847 uint32_t mbox_cmd[MBOX_REG_COUNT];
1848 uint32_t mbox_sts[MBOX_REG_COUNT];
1849 int status = QLA_SUCCESS;
1850
1851 memset(&mbox_cmd, 0, sizeof(mbox_cmd));
1852 memset(&mbox_sts, 0, sizeof(mbox_sts));
1853
1854 mbox_cmd[0] = MBOX_CMD_CONN_CLOSE_SESS_LOGOUT;
1855 mbox_cmd[1] = fw_ddb_index;
1856 mbox_cmd[2] = connection_id;
1857 mbox_cmd[3] = option;
1858
1859 status = qla4xxx_mailbox_command(ha, 4, 2, &mbox_cmd[0], &mbox_sts[0]);
1860 if (status != QLA_SUCCESS) {
1861 DEBUG2(ql4_printk(KERN_WARNING, ha, "%s: MBOX_CMD_CONN_CLOSE "
1862 "option %04x failed w/ status %04X %04X\n",
1863 __func__, option, mbox_sts[0], mbox_sts[1]));
1864 }
1865 return status;
1866}
1867
Nilesh Javali7ab284c2013-08-16 07:03:03 -04001868/**
1869 * qla4_84xx_extend_idc_tmo - Extend IDC Timeout.
1870 * @ha: Pointer to host adapter structure.
1871 * @ext_tmo: idc timeout value
1872 *
1873 * Requests firmware to extend the idc timeout value.
1874 **/
1875static int qla4_84xx_extend_idc_tmo(struct scsi_qla_host *ha, uint32_t ext_tmo)
1876{
1877 uint32_t mbox_cmd[MBOX_REG_COUNT];
1878 uint32_t mbox_sts[MBOX_REG_COUNT];
1879 int status;
1880
1881 memset(&mbox_cmd, 0, sizeof(mbox_cmd));
1882 memset(&mbox_sts, 0, sizeof(mbox_sts));
1883 ext_tmo &= 0xf;
1884
1885 mbox_cmd[0] = MBOX_CMD_IDC_TIME_EXTEND;
1886 mbox_cmd[1] = ((ha->idc_info.request_desc & 0xfffff0ff) |
1887 (ext_tmo << 8)); /* new timeout */
1888 mbox_cmd[2] = ha->idc_info.info1;
1889 mbox_cmd[3] = ha->idc_info.info2;
1890 mbox_cmd[4] = ha->idc_info.info3;
1891
1892 status = qla4xxx_mailbox_command(ha, MBOX_REG_COUNT, MBOX_REG_COUNT,
1893 mbox_cmd, mbox_sts);
1894 if (status != QLA_SUCCESS) {
1895 DEBUG2(ql4_printk(KERN_INFO, ha,
1896 "scsi%ld: %s: failed status %04X\n",
1897 ha->host_no, __func__, mbox_sts[0]));
1898 return QLA_ERROR;
1899 } else {
1900 ql4_printk(KERN_INFO, ha, "%s: IDC timeout extended by %d secs\n",
1901 __func__, ext_tmo);
1902 }
1903
1904 return QLA_SUCCESS;
1905}
1906
Mike Christied00efe32011-07-25 13:48:38 -05001907int qla4xxx_disable_acb(struct scsi_qla_host *ha)
1908{
1909 uint32_t mbox_cmd[MBOX_REG_COUNT];
1910 uint32_t mbox_sts[MBOX_REG_COUNT];
1911 int status = QLA_SUCCESS;
1912
1913 memset(&mbox_cmd, 0, sizeof(mbox_cmd));
1914 memset(&mbox_sts, 0, sizeof(mbox_sts));
1915
1916 mbox_cmd[0] = MBOX_CMD_DISABLE_ACB;
1917
1918 status = qla4xxx_mailbox_command(ha, 8, 5, &mbox_cmd[0], &mbox_sts[0]);
1919 if (status != QLA_SUCCESS) {
1920 DEBUG2(ql4_printk(KERN_WARNING, ha, "%s: MBOX_CMD_DISABLE_ACB "
1921 "failed w/ status %04X %04X %04X", __func__,
1922 mbox_sts[0], mbox_sts[1], mbox_sts[2]));
Nilesh Javali7ab284c2013-08-16 07:03:03 -04001923 } else {
1924 if (is_qla8042(ha) &&
1925 (mbox_sts[0] != MBOX_STS_COMMAND_COMPLETE)) {
1926 /*
1927 * Disable ACB mailbox command takes time to complete
1928 * based on the total number of targets connected.
1929 * For 512 targets, it took approximately 5 secs to
1930 * complete. Setting the timeout value to 8, with the 3
1931 * secs buffer.
1932 */
1933 qla4_84xx_extend_idc_tmo(ha, IDC_EXTEND_TOV);
1934 if (!wait_for_completion_timeout(&ha->disable_acb_comp,
1935 IDC_EXTEND_TOV * HZ)) {
1936 ql4_printk(KERN_WARNING, ha, "%s: Disable ACB Completion not received\n",
1937 __func__);
1938 }
1939 }
Mike Christied00efe32011-07-25 13:48:38 -05001940 }
1941 return status;
1942}
1943
Harish Zunjarrao60854912011-08-12 02:51:27 -07001944int qla4xxx_get_acb(struct scsi_qla_host *ha, dma_addr_t acb_dma,
1945 uint32_t acb_type, uint32_t len)
Mike Christied00efe32011-07-25 13:48:38 -05001946{
Harish Zunjarrao60854912011-08-12 02:51:27 -07001947 uint32_t mbox_cmd[MBOX_REG_COUNT];
1948 uint32_t mbox_sts[MBOX_REG_COUNT];
Mike Christied00efe32011-07-25 13:48:38 -05001949 int status = QLA_SUCCESS;
1950
Harish Zunjarrao60854912011-08-12 02:51:27 -07001951 memset(&mbox_cmd, 0, sizeof(mbox_cmd));
1952 memset(&mbox_sts, 0, sizeof(mbox_sts));
1953
Mike Christied00efe32011-07-25 13:48:38 -05001954 mbox_cmd[0] = MBOX_CMD_GET_ACB;
Harish Zunjarrao60854912011-08-12 02:51:27 -07001955 mbox_cmd[1] = acb_type;
Mike Christied00efe32011-07-25 13:48:38 -05001956 mbox_cmd[2] = LSDW(acb_dma);
1957 mbox_cmd[3] = MSDW(acb_dma);
Harish Zunjarrao60854912011-08-12 02:51:27 -07001958 mbox_cmd[4] = len;
Mike Christied00efe32011-07-25 13:48:38 -05001959
1960 status = qla4xxx_mailbox_command(ha, 5, 5, &mbox_cmd[0], &mbox_sts[0]);
1961 if (status != QLA_SUCCESS) {
1962 DEBUG2(ql4_printk(KERN_WARNING, ha, "%s: MBOX_CMD_GET_ACB "
1963 "failed w/ status %04X\n", __func__,
1964 mbox_sts[0]));
1965 }
1966 return status;
1967}
1968
1969int qla4xxx_set_acb(struct scsi_qla_host *ha, uint32_t *mbox_cmd,
1970 uint32_t *mbox_sts, dma_addr_t acb_dma)
1971{
1972 int status = QLA_SUCCESS;
1973
1974 memset(mbox_cmd, 0, sizeof(mbox_cmd[0]) * MBOX_REG_COUNT);
1975 memset(mbox_sts, 0, sizeof(mbox_sts[0]) * MBOX_REG_COUNT);
1976 mbox_cmd[0] = MBOX_CMD_SET_ACB;
1977 mbox_cmd[1] = 0; /* Primary ACB */
1978 mbox_cmd[2] = LSDW(acb_dma);
1979 mbox_cmd[3] = MSDW(acb_dma);
1980 mbox_cmd[4] = sizeof(struct addr_ctrl_blk);
1981
1982 status = qla4xxx_mailbox_command(ha, 5, 5, &mbox_cmd[0], &mbox_sts[0]);
1983 if (status != QLA_SUCCESS) {
1984 DEBUG2(ql4_printk(KERN_WARNING, ha, "%s: MBOX_CMD_SET_ACB "
1985 "failed w/ status %04X\n", __func__,
1986 mbox_sts[0]));
1987 }
1988 return status;
1989}
Manish Rangankarb3a271a2011-07-25 13:48:53 -05001990
1991int qla4xxx_set_param_ddbentry(struct scsi_qla_host *ha,
1992 struct ddb_entry *ddb_entry,
1993 struct iscsi_cls_conn *cls_conn,
1994 uint32_t *mbx_sts)
1995{
1996 struct dev_db_entry *fw_ddb_entry;
1997 struct iscsi_conn *conn;
1998 struct iscsi_session *sess;
1999 struct qla_conn *qla_conn;
2000 struct sockaddr *dst_addr;
2001 dma_addr_t fw_ddb_entry_dma;
2002 int status = QLA_SUCCESS;
2003 int rval = 0;
2004 struct sockaddr_in *addr;
2005 struct sockaddr_in6 *addr6;
2006 char *ip;
2007 uint16_t iscsi_opts = 0;
2008 uint32_t options = 0;
Manish Rangankar173269e2012-02-27 03:08:55 -08002009 uint16_t idx, *ptid;
Manish Rangankarb3a271a2011-07-25 13:48:53 -05002010
2011 fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
2012 &fw_ddb_entry_dma, GFP_KERNEL);
2013 if (!fw_ddb_entry) {
2014 DEBUG2(ql4_printk(KERN_ERR, ha,
2015 "%s: Unable to allocate dma buffer.\n",
2016 __func__));
2017 rval = -ENOMEM;
2018 goto exit_set_param_no_free;
2019 }
2020
2021 conn = cls_conn->dd_data;
2022 qla_conn = conn->dd_data;
2023 sess = conn->session;
Manish Rangankard46bdeb12012-08-07 07:57:13 -04002024 dst_addr = (struct sockaddr *)&qla_conn->qla_ep->dst_addr;
Manish Rangankarb3a271a2011-07-25 13:48:53 -05002025
2026 if (dst_addr->sa_family == AF_INET6)
2027 options |= IPV6_DEFAULT_DDB_ENTRY;
2028
2029 status = qla4xxx_get_default_ddb(ha, options, fw_ddb_entry_dma);
2030 if (status == QLA_ERROR) {
2031 rval = -EINVAL;
2032 goto exit_set_param;
2033 }
2034
Manish Rangankar173269e2012-02-27 03:08:55 -08002035 ptid = (uint16_t *)&fw_ddb_entry->isid[1];
2036 *ptid = cpu_to_le16((uint16_t)ddb_entry->sess->target_id);
2037
2038 DEBUG2(ql4_printk(KERN_INFO, ha, "ISID [%02x%02x%02x%02x%02x%02x]\n",
2039 fw_ddb_entry->isid[5], fw_ddb_entry->isid[4],
2040 fw_ddb_entry->isid[3], fw_ddb_entry->isid[2],
2041 fw_ddb_entry->isid[1], fw_ddb_entry->isid[0]));
2042
Manish Rangankarb3a271a2011-07-25 13:48:53 -05002043 iscsi_opts = le16_to_cpu(fw_ddb_entry->iscsi_options);
2044 memset(fw_ddb_entry->iscsi_alias, 0, sizeof(fw_ddb_entry->iscsi_alias));
2045
2046 memset(fw_ddb_entry->iscsi_name, 0, sizeof(fw_ddb_entry->iscsi_name));
2047
2048 if (sess->targetname != NULL) {
2049 memcpy(fw_ddb_entry->iscsi_name, sess->targetname,
2050 min(strlen(sess->targetname),
2051 sizeof(fw_ddb_entry->iscsi_name)));
2052 }
2053
2054 memset(fw_ddb_entry->ip_addr, 0, sizeof(fw_ddb_entry->ip_addr));
2055 memset(fw_ddb_entry->tgt_addr, 0, sizeof(fw_ddb_entry->tgt_addr));
2056
2057 fw_ddb_entry->options = DDB_OPT_TARGET | DDB_OPT_AUTO_SENDTGTS_DISABLE;
2058
2059 if (dst_addr->sa_family == AF_INET) {
2060 addr = (struct sockaddr_in *)dst_addr;
2061 ip = (char *)&addr->sin_addr;
2062 memcpy(fw_ddb_entry->ip_addr, ip, IP_ADDR_LEN);
2063 fw_ddb_entry->port = cpu_to_le16(ntohs(addr->sin_port));
2064 DEBUG2(ql4_printk(KERN_INFO, ha,
2065 "%s: Destination Address [%pI4]: index [%d]\n",
2066 __func__, fw_ddb_entry->ip_addr,
2067 ddb_entry->fw_ddb_index));
2068 } else if (dst_addr->sa_family == AF_INET6) {
2069 addr6 = (struct sockaddr_in6 *)dst_addr;
2070 ip = (char *)&addr6->sin6_addr;
2071 memcpy(fw_ddb_entry->ip_addr, ip, IPv6_ADDR_LEN);
2072 fw_ddb_entry->port = cpu_to_le16(ntohs(addr6->sin6_port));
2073 fw_ddb_entry->options |= DDB_OPT_IPV6_DEVICE;
2074 DEBUG2(ql4_printk(KERN_INFO, ha,
2075 "%s: Destination Address [%pI6]: index [%d]\n",
2076 __func__, fw_ddb_entry->ip_addr,
2077 ddb_entry->fw_ddb_index));
2078 } else {
2079 ql4_printk(KERN_ERR, ha,
2080 "%s: Failed to get IP Address\n",
2081 __func__);
2082 rval = -EINVAL;
2083 goto exit_set_param;
2084 }
2085
Manish Rangankarb3a271a2011-07-25 13:48:53 -05002086 /* CHAP */
2087 if (sess->username != NULL && sess->password != NULL) {
2088 if (strlen(sess->username) && strlen(sess->password)) {
2089 iscsi_opts |= BIT_7;
Manish Rangankarb3a271a2011-07-25 13:48:53 -05002090
Lalit Chandivade45494152011-10-07 16:55:42 -07002091 rval = qla4xxx_get_chap_index(ha, sess->username,
2092 sess->password,
2093 LOCAL_CHAP, &idx);
Manish Rangankarb3a271a2011-07-25 13:48:53 -05002094 if (rval)
2095 goto exit_set_param;
2096
2097 fw_ddb_entry->chap_tbl_idx = cpu_to_le16(idx);
2098 }
2099 }
2100
2101 if (sess->username_in != NULL && sess->password_in != NULL) {
2102 /* Check if BIDI CHAP */
2103 if (strlen(sess->username_in) && strlen(sess->password_in)) {
2104 iscsi_opts |= BIT_4;
Lalit Chandivade45494152011-10-07 16:55:42 -07002105
2106 rval = qla4xxx_get_chap_index(ha, sess->username_in,
2107 sess->password_in,
2108 BIDI_CHAP, &idx);
Manish Rangankarb3a271a2011-07-25 13:48:53 -05002109 if (rval)
2110 goto exit_set_param;
2111 }
2112 }
2113
2114 if (sess->initial_r2t_en)
2115 iscsi_opts |= BIT_10;
2116
2117 if (sess->imm_data_en)
2118 iscsi_opts |= BIT_11;
2119
2120 fw_ddb_entry->iscsi_options = cpu_to_le16(iscsi_opts);
2121
2122 if (conn->max_recv_dlength)
2123 fw_ddb_entry->iscsi_max_rcv_data_seg_len =
2124 __constant_cpu_to_le16((conn->max_recv_dlength / BYTE_UNITS));
2125
2126 if (sess->max_r2t)
2127 fw_ddb_entry->iscsi_max_outsnd_r2t = cpu_to_le16(sess->max_r2t);
2128
2129 if (sess->first_burst)
2130 fw_ddb_entry->iscsi_first_burst_len =
2131 __constant_cpu_to_le16((sess->first_burst / BYTE_UNITS));
2132
2133 if (sess->max_burst)
2134 fw_ddb_entry->iscsi_max_burst_len =
2135 __constant_cpu_to_le16((sess->max_burst / BYTE_UNITS));
2136
2137 if (sess->time2wait)
2138 fw_ddb_entry->iscsi_def_time2wait =
2139 cpu_to_le16(sess->time2wait);
2140
2141 if (sess->time2retain)
2142 fw_ddb_entry->iscsi_def_time2retain =
2143 cpu_to_le16(sess->time2retain);
2144
2145 status = qla4xxx_set_ddb_entry(ha, ddb_entry->fw_ddb_index,
2146 fw_ddb_entry_dma, mbx_sts);
2147
2148 if (status != QLA_SUCCESS)
2149 rval = -EINVAL;
2150exit_set_param:
2151 dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
2152 fw_ddb_entry, fw_ddb_entry_dma);
2153exit_set_param_no_free:
2154 return rval;
2155}
2156
2157int qla4xxx_get_mgmt_data(struct scsi_qla_host *ha, uint16_t fw_ddb_index,
2158 uint16_t stats_size, dma_addr_t stats_dma)
2159{
2160 int status = QLA_SUCCESS;
2161 uint32_t mbox_cmd[MBOX_REG_COUNT];
2162 uint32_t mbox_sts[MBOX_REG_COUNT];
2163
2164 memset(mbox_cmd, 0, sizeof(mbox_cmd[0]) * MBOX_REG_COUNT);
2165 memset(mbox_sts, 0, sizeof(mbox_sts[0]) * MBOX_REG_COUNT);
2166 mbox_cmd[0] = MBOX_CMD_GET_MANAGEMENT_DATA;
2167 mbox_cmd[1] = fw_ddb_index;
2168 mbox_cmd[2] = LSDW(stats_dma);
2169 mbox_cmd[3] = MSDW(stats_dma);
2170 mbox_cmd[4] = stats_size;
2171
2172 status = qla4xxx_mailbox_command(ha, 5, 1, &mbox_cmd[0], &mbox_sts[0]);
2173 if (status != QLA_SUCCESS) {
2174 DEBUG2(ql4_printk(KERN_WARNING, ha,
2175 "%s: MBOX_CMD_GET_MANAGEMENT_DATA "
2176 "failed w/ status %04X\n", __func__,
2177 mbox_sts[0]));
2178 }
2179 return status;
2180}
Harish Zunjarrao8b0402e2011-08-01 03:26:15 -07002181
2182int qla4xxx_get_ip_state(struct scsi_qla_host *ha, uint32_t acb_idx,
2183 uint32_t ip_idx, uint32_t *sts)
2184{
2185 uint32_t mbox_cmd[MBOX_REG_COUNT];
2186 uint32_t mbox_sts[MBOX_REG_COUNT];
2187 int status = QLA_SUCCESS;
2188
2189 memset(&mbox_cmd, 0, sizeof(mbox_cmd));
2190 memset(&mbox_sts, 0, sizeof(mbox_sts));
2191 mbox_cmd[0] = MBOX_CMD_GET_IP_ADDR_STATE;
2192 mbox_cmd[1] = acb_idx;
2193 mbox_cmd[2] = ip_idx;
2194
2195 status = qla4xxx_mailbox_command(ha, 3, 8, &mbox_cmd[0], &mbox_sts[0]);
2196 if (status != QLA_SUCCESS) {
2197 DEBUG2(ql4_printk(KERN_WARNING, ha, "%s: "
2198 "MBOX_CMD_GET_IP_ADDR_STATE failed w/ "
2199 "status %04X\n", __func__, mbox_sts[0]));
2200 }
2201 memcpy(sts, mbox_sts, sizeof(mbox_sts));
2202 return status;
2203}
Harish Zunjarrao7c07d132011-08-01 03:26:16 -07002204
2205int qla4xxx_get_nvram(struct scsi_qla_host *ha, dma_addr_t nvram_dma,
2206 uint32_t offset, uint32_t size)
2207{
2208 int status = QLA_SUCCESS;
2209 uint32_t mbox_cmd[MBOX_REG_COUNT];
2210 uint32_t mbox_sts[MBOX_REG_COUNT];
2211
2212 memset(&mbox_cmd, 0, sizeof(mbox_cmd));
2213 memset(&mbox_sts, 0, sizeof(mbox_sts));
2214
2215 mbox_cmd[0] = MBOX_CMD_GET_NVRAM;
2216 mbox_cmd[1] = LSDW(nvram_dma);
2217 mbox_cmd[2] = MSDW(nvram_dma);
2218 mbox_cmd[3] = offset;
2219 mbox_cmd[4] = size;
2220
2221 status = qla4xxx_mailbox_command(ha, MBOX_REG_COUNT, 1, &mbox_cmd[0],
2222 &mbox_sts[0]);
2223 if (status != QLA_SUCCESS) {
2224 DEBUG2(ql4_printk(KERN_ERR, ha, "scsi%ld: %s: failed "
2225 "status %04X\n", ha->host_no, __func__,
2226 mbox_sts[0]));
2227 }
2228 return status;
2229}
2230
2231int qla4xxx_set_nvram(struct scsi_qla_host *ha, dma_addr_t nvram_dma,
2232 uint32_t offset, uint32_t size)
2233{
2234 int status = QLA_SUCCESS;
2235 uint32_t mbox_cmd[MBOX_REG_COUNT];
2236 uint32_t mbox_sts[MBOX_REG_COUNT];
2237
2238 memset(&mbox_cmd, 0, sizeof(mbox_cmd));
2239 memset(&mbox_sts, 0, sizeof(mbox_sts));
2240
2241 mbox_cmd[0] = MBOX_CMD_SET_NVRAM;
2242 mbox_cmd[1] = LSDW(nvram_dma);
2243 mbox_cmd[2] = MSDW(nvram_dma);
2244 mbox_cmd[3] = offset;
2245 mbox_cmd[4] = size;
2246
2247 status = qla4xxx_mailbox_command(ha, MBOX_REG_COUNT, 1, &mbox_cmd[0],
2248 &mbox_sts[0]);
2249 if (status != QLA_SUCCESS) {
2250 DEBUG2(ql4_printk(KERN_ERR, ha, "scsi%ld: %s: failed "
2251 "status %04X\n", ha->host_no, __func__,
2252 mbox_sts[0]));
2253 }
2254 return status;
2255}
Harish Zunjarrao5232f802011-08-12 02:51:26 -07002256
2257int qla4xxx_restore_factory_defaults(struct scsi_qla_host *ha,
2258 uint32_t region, uint32_t field0,
2259 uint32_t field1)
2260{
2261 int status = QLA_SUCCESS;
2262 uint32_t mbox_cmd[MBOX_REG_COUNT];
2263 uint32_t mbox_sts[MBOX_REG_COUNT];
2264
2265 memset(&mbox_cmd, 0, sizeof(mbox_cmd));
2266 memset(&mbox_sts, 0, sizeof(mbox_sts));
2267
2268 mbox_cmd[0] = MBOX_CMD_RESTORE_FACTORY_DEFAULTS;
2269 mbox_cmd[3] = region;
2270 mbox_cmd[4] = field0;
2271 mbox_cmd[5] = field1;
2272
2273 status = qla4xxx_mailbox_command(ha, MBOX_REG_COUNT, 3, &mbox_cmd[0],
2274 &mbox_sts[0]);
2275 if (status != QLA_SUCCESS) {
2276 DEBUG2(ql4_printk(KERN_ERR, ha, "scsi%ld: %s: failed "
2277 "status %04X\n", ha->host_no, __func__,
2278 mbox_sts[0]));
2279 }
2280 return status;
2281}
Manish Dusanecfb27872012-09-20 07:35:01 -04002282
2283/**
2284 * qla4_8xxx_set_param - set driver version in firmware.
2285 * @ha: Pointer to host adapter structure.
2286 * @param: Parameter to set i.e driver version
2287 **/
2288int qla4_8xxx_set_param(struct scsi_qla_host *ha, int param)
2289{
2290 uint32_t mbox_cmd[MBOX_REG_COUNT];
2291 uint32_t mbox_sts[MBOX_REG_COUNT];
2292 uint32_t status;
2293
2294 memset(&mbox_cmd, 0, sizeof(mbox_cmd));
2295 memset(&mbox_sts, 0, sizeof(mbox_sts));
2296
2297 mbox_cmd[0] = MBOX_CMD_SET_PARAM;
2298 if (param == SET_DRVR_VERSION) {
2299 mbox_cmd[1] = SET_DRVR_VERSION;
2300 strncpy((char *)&mbox_cmd[2], QLA4XXX_DRIVER_VERSION,
2301 MAX_DRVR_VER_LEN);
2302 } else {
2303 ql4_printk(KERN_ERR, ha, "%s: invalid parameter 0x%x\n",
2304 __func__, param);
2305 status = QLA_ERROR;
2306 goto exit_set_param;
2307 }
2308
2309 status = qla4xxx_mailbox_command(ha, MBOX_REG_COUNT, 2, mbox_cmd,
2310 mbox_sts);
2311 if (status == QLA_ERROR)
2312 ql4_printk(KERN_ERR, ha, "%s: failed status %04X\n",
2313 __func__, mbox_sts[0]);
2314
2315exit_set_param:
2316 return status;
2317}
Nilesh Javali320a61d2012-09-20 07:35:10 -04002318
2319/**
2320 * qla4_83xx_post_idc_ack - post IDC ACK
2321 * @ha: Pointer to host adapter structure.
2322 *
2323 * Posts IDC ACK for IDC Request Notification AEN.
2324 **/
2325int qla4_83xx_post_idc_ack(struct scsi_qla_host *ha)
2326{
2327 uint32_t mbox_cmd[MBOX_REG_COUNT];
2328 uint32_t mbox_sts[MBOX_REG_COUNT];
2329 int status;
2330
2331 memset(&mbox_cmd, 0, sizeof(mbox_cmd));
2332 memset(&mbox_sts, 0, sizeof(mbox_sts));
2333
2334 mbox_cmd[0] = MBOX_CMD_IDC_ACK;
2335 mbox_cmd[1] = ha->idc_info.request_desc;
2336 mbox_cmd[2] = ha->idc_info.info1;
2337 mbox_cmd[3] = ha->idc_info.info2;
2338 mbox_cmd[4] = ha->idc_info.info3;
2339
2340 status = qla4xxx_mailbox_command(ha, MBOX_REG_COUNT, MBOX_REG_COUNT,
2341 mbox_cmd, mbox_sts);
2342 if (status == QLA_ERROR)
2343 ql4_printk(KERN_ERR, ha, "%s: failed status %04X\n", __func__,
2344 mbox_sts[0]);
2345 else
Nilesh Javali7ab284c2013-08-16 07:03:03 -04002346 ql4_printk(KERN_INFO, ha, "%s: IDC ACK posted\n", __func__);
Nilesh Javali320a61d2012-09-20 07:35:10 -04002347
2348 return status;
2349}
Nilesh Javali7ab284c2013-08-16 07:03:03 -04002350
2351int qla4_84xx_config_acb(struct scsi_qla_host *ha, int acb_config)
2352{
2353 uint32_t mbox_cmd[MBOX_REG_COUNT];
2354 uint32_t mbox_sts[MBOX_REG_COUNT];
2355 struct addr_ctrl_blk *acb = NULL;
2356 uint32_t acb_len = sizeof(struct addr_ctrl_blk);
2357 int rval = QLA_SUCCESS;
2358 dma_addr_t acb_dma;
2359
2360 acb = dma_alloc_coherent(&ha->pdev->dev,
2361 sizeof(struct addr_ctrl_blk),
2362 &acb_dma, GFP_KERNEL);
2363 if (!acb) {
2364 ql4_printk(KERN_ERR, ha, "%s: Unable to alloc acb\n", __func__);
2365 rval = QLA_ERROR;
2366 goto exit_config_acb;
2367 }
2368 memset(acb, 0, acb_len);
2369
2370 switch (acb_config) {
2371 case ACB_CONFIG_DISABLE:
2372 rval = qla4xxx_get_acb(ha, acb_dma, 0, acb_len);
2373 if (rval != QLA_SUCCESS)
2374 goto exit_free_acb;
2375
2376 rval = qla4xxx_disable_acb(ha);
2377 if (rval != QLA_SUCCESS)
2378 goto exit_free_acb;
2379
2380 if (!ha->saved_acb)
2381 ha->saved_acb = kzalloc(acb_len, GFP_KERNEL);
2382
2383 if (!ha->saved_acb) {
2384 ql4_printk(KERN_ERR, ha, "%s: Unable to alloc acb\n",
2385 __func__);
2386 rval = QLA_ERROR;
2387 goto exit_config_acb;
2388 }
2389 memcpy(ha->saved_acb, acb, acb_len);
2390 break;
2391 case ACB_CONFIG_SET:
2392
2393 if (!ha->saved_acb) {
2394 ql4_printk(KERN_ERR, ha, "%s: Can't set ACB, Saved ACB not available\n",
2395 __func__);
2396 rval = QLA_ERROR;
2397 goto exit_free_acb;
2398 }
2399
2400 memcpy(acb, ha->saved_acb, acb_len);
2401 kfree(ha->saved_acb);
2402 ha->saved_acb = NULL;
2403
2404 rval = qla4xxx_set_acb(ha, &mbox_cmd[0], &mbox_sts[0], acb_dma);
2405 if (rval != QLA_SUCCESS)
2406 goto exit_free_acb;
2407
2408 break;
2409 default:
2410 ql4_printk(KERN_ERR, ha, "%s: Invalid ACB Configuration\n",
2411 __func__);
2412 }
2413
2414exit_free_acb:
2415 dma_free_coherent(&ha->pdev->dev, sizeof(struct addr_ctrl_blk), acb,
2416 acb_dma);
2417exit_config_acb:
2418 DEBUG2(ql4_printk(KERN_INFO, ha,
2419 "%s %s\n", __func__,
2420 rval == QLA_SUCCESS ? "SUCCEEDED" : "FAILED"));
2421 return rval;
2422}
Vikas Chaudharydf86f772013-11-22 05:28:17 -05002423
2424int qla4_83xx_get_port_config(struct scsi_qla_host *ha, uint32_t *config)
2425{
2426 uint32_t mbox_cmd[MBOX_REG_COUNT];
2427 uint32_t mbox_sts[MBOX_REG_COUNT];
2428 int status;
2429
2430 memset(&mbox_cmd, 0, sizeof(mbox_cmd));
2431 memset(&mbox_sts, 0, sizeof(mbox_sts));
2432
2433 mbox_cmd[0] = MBOX_CMD_GET_PORT_CONFIG;
2434
2435 status = qla4xxx_mailbox_command(ha, MBOX_REG_COUNT, MBOX_REG_COUNT,
2436 mbox_cmd, mbox_sts);
2437 if (status == QLA_SUCCESS)
2438 *config = mbox_sts[1];
2439 else
2440 ql4_printk(KERN_ERR, ha, "%s: failed status %04X\n", __func__,
2441 mbox_sts[0]);
2442
2443 return status;
2444}
2445
2446int qla4_83xx_set_port_config(struct scsi_qla_host *ha, uint32_t *config)
2447{
2448 uint32_t mbox_cmd[MBOX_REG_COUNT];
2449 uint32_t mbox_sts[MBOX_REG_COUNT];
2450 int status;
2451
2452 memset(&mbox_cmd, 0, sizeof(mbox_cmd));
2453 memset(&mbox_sts, 0, sizeof(mbox_sts));
2454
2455 mbox_cmd[0] = MBOX_CMD_SET_PORT_CONFIG;
2456 mbox_cmd[1] = *config;
2457
2458 status = qla4xxx_mailbox_command(ha, MBOX_REG_COUNT, MBOX_REG_COUNT,
2459 mbox_cmd, mbox_sts);
2460 if (status != QLA_SUCCESS)
2461 ql4_printk(KERN_ERR, ha, "%s: failed status %04X\n", __func__,
2462 mbox_sts[0]);
2463
2464 return status;
2465}