blob: 47b259190b5af900f36a7bb9f281968f114cc0a0 [file] [log] [blame]
David Somayajuluafaf5a22006-09-19 10:28:00 -07001/*
2 * QLogic iSCSI HBA Driver
Vikas Chaudhary7d01d062010-12-02 22:12:51 -08003 * Copyright (c) 2003-2010 QLogic Corporation
David Somayajuluafaf5a22006-09-19 10:28:00 -07004 *
5 * See LICENSE.qla4xxx for copyright and licensing details.
6 */
7
8#include "ql4_def.h"
David C Somayajuluc0e344c2007-05-23 18:03:27 -07009#include "ql4_glbl.h"
10#include "ql4_dbg.h"
11#include "ql4_inline.h"
David Somayajuluafaf5a22006-09-19 10:28:00 -070012
13
14/**
15 * qla4xxx_mailbox_command - issues mailbox commands
16 * @ha: Pointer to host adapter structure.
17 * @inCount: number of mailbox registers to load.
18 * @outCount: number of mailbox registers to return.
19 * @mbx_cmd: data pointer for mailbox in registers.
20 * @mbx_sts: data pointer for mailbox out registers.
21 *
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +053022 * This routine isssue mailbox commands and waits for completion.
David Somayajuluafaf5a22006-09-19 10:28:00 -070023 * If outCount is 0, this routine completes successfully WITHOUT waiting
24 * for the mailbox command to complete.
25 **/
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +053026int qla4xxx_mailbox_command(struct scsi_qla_host *ha, uint8_t inCount,
27 uint8_t outCount, uint32_t *mbx_cmd,
28 uint32_t *mbx_sts)
David Somayajuluafaf5a22006-09-19 10:28:00 -070029{
30 int status = QLA_ERROR;
31 uint8_t i;
32 u_long wait_count;
33 uint32_t intr_status;
34 unsigned long flags = 0;
Prasanna Mumbai99b53bf2011-03-21 03:34:25 -070035 uint32_t dev_state;
David Somayajuluafaf5a22006-09-19 10:28:00 -070036
37 /* Make sure that pointers are valid */
38 if (!mbx_cmd || !mbx_sts) {
39 DEBUG2(printk("scsi%ld: %s: Invalid mbx_cmd or mbx_sts "
40 "pointer\n", ha->host_no, __func__));
David C Somayajulu477ffb92007-01-22 12:26:11 -080041 return status;
42 }
Nilesh Javali21033632010-07-30 14:28:07 +053043
Prasanna Mumbai99b53bf2011-03-21 03:34:25 -070044 if (is_qla8022(ha)) {
45 if (test_bit(AF_FW_RECOVERY, &ha->flags)) {
46 DEBUG2(ql4_printk(KERN_WARNING, ha, "scsi%ld: %s: "
47 "prematurely completing mbx cmd as firmware "
48 "recovery detected\n", ha->host_no, __func__));
49 return status;
50 }
51 /* Do not send any mbx cmd if h/w is in failed state*/
52 qla4_8xxx_idc_lock(ha);
53 dev_state = qla4_8xxx_rd_32(ha, QLA82XX_CRB_DEV_STATE);
54 qla4_8xxx_idc_unlock(ha);
55 if (dev_state == QLA82XX_DEV_FAILED) {
56 ql4_printk(KERN_WARNING, ha, "scsi%ld: %s: H/W is in "
57 "failed state, do not send any mailbox commands\n",
58 ha->host_no, __func__);
59 return status;
60 }
Nilesh Javali21033632010-07-30 14:28:07 +053061 }
62
Lalit Chandivade2232be02010-07-30 14:38:47 +053063 if ((is_aer_supported(ha)) &&
64 (test_bit(AF_PCI_CHANNEL_IO_PERM_FAILURE, &ha->flags))) {
65 DEBUG2(printk(KERN_WARNING "scsi%ld: %s: Perm failure on EEH, "
66 "timeout MBX Exiting.\n", ha->host_no, __func__));
67 return status;
68 }
69
David C Somayajulu477ffb92007-01-22 12:26:11 -080070 /* Mailbox code active */
71 wait_count = MBOX_TOV * 100;
72
73 while (wait_count--) {
74 mutex_lock(&ha->mbox_sem);
75 if (!test_bit(AF_MBOX_COMMAND, &ha->flags)) {
76 set_bit(AF_MBOX_COMMAND, &ha->flags);
77 mutex_unlock(&ha->mbox_sem);
78 break;
79 }
80 mutex_unlock(&ha->mbox_sem);
81 if (!wait_count) {
82 DEBUG2(printk("scsi%ld: %s: mbox_sem failed\n",
83 ha->host_no, __func__));
84 return status;
85 }
86 msleep(10);
David Somayajuluafaf5a22006-09-19 10:28:00 -070087 }
88
89 /* To prevent overwriting mailbox registers for a command that has
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +053090 * not yet been serviced, check to see if an active command
91 * (AEN, IOCB, etc.) is interrupting, then service it.
David Somayajuluafaf5a22006-09-19 10:28:00 -070092 * -----------------------------------------------------------------
93 */
94 spin_lock_irqsave(&ha->hardware_lock, flags);
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +053095
Lalit Chandivadee6b07df2010-12-02 22:12:27 -080096 if (!is_qla8022(ha)) {
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +053097 intr_status = readl(&ha->reg->ctrl_status);
98 if (intr_status & CSR_SCSI_PROCESSOR_INTR) {
99 /* Service existing interrupt */
100 ha->isp_ops->interrupt_service_routine(ha, intr_status);
101 clear_bit(AF_MBOX_COMMAND_DONE, &ha->flags);
102 }
David Somayajuluafaf5a22006-09-19 10:28:00 -0700103 }
104
David Somayajuluafaf5a22006-09-19 10:28:00 -0700105 ha->mbox_status_count = outCount;
106 for (i = 0; i < outCount; i++)
107 ha->mbox_status[i] = 0;
108
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +0530109 if (is_qla8022(ha)) {
110 /* Load all mailbox registers, except mailbox 0. */
111 DEBUG5(
112 printk("scsi%ld: %s: Cmd ", ha->host_no, __func__);
113 for (i = 0; i < inCount; i++)
114 printk("mb%d=%04x ", i, mbx_cmd[i]);
115 printk("\n"));
David Somayajuluafaf5a22006-09-19 10:28:00 -0700116
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +0530117 for (i = 1; i < inCount; i++)
118 writel(mbx_cmd[i], &ha->qla4_8xxx_reg->mailbox_in[i]);
119 writel(mbx_cmd[0], &ha->qla4_8xxx_reg->mailbox_in[0]);
120 readl(&ha->qla4_8xxx_reg->mailbox_in[0]);
121 writel(HINT_MBX_INT_PENDING, &ha->qla4_8xxx_reg->hint);
122 } else {
123 /* Load all mailbox registers, except mailbox 0. */
124 for (i = 1; i < inCount; i++)
125 writel(mbx_cmd[i], &ha->reg->mailbox[i]);
126
127 /* Wakeup firmware */
128 writel(mbx_cmd[0], &ha->reg->mailbox[0]);
129 readl(&ha->reg->mailbox[0]);
130 writel(set_rmask(CSR_INTR_RISC), &ha->reg->ctrl_status);
131 readl(&ha->reg->ctrl_status);
132 }
133
David Somayajuluafaf5a22006-09-19 10:28:00 -0700134 spin_unlock_irqrestore(&ha->hardware_lock, flags);
135
136 /* Wait for completion */
David Somayajuluafaf5a22006-09-19 10:28:00 -0700137
138 /*
139 * If we don't want status, don't wait for the mailbox command to
140 * complete. For example, MBOX_CMD_RESET_FW doesn't return status,
141 * you must poll the inbound Interrupt Mask for completion.
142 */
143 if (outCount == 0) {
144 status = QLA_SUCCESS;
David Somayajuluafaf5a22006-09-19 10:28:00 -0700145 goto mbox_exit;
146 }
David Somayajuluafaf5a22006-09-19 10:28:00 -0700147
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +0530148 /*
149 * Wait for completion: Poll or completion queue
150 */
151 if (test_bit(AF_IRQ_ATTACHED, &ha->flags) &&
152 test_bit(AF_INTERRUPTS_ON, &ha->flags) &&
153 test_bit(AF_ONLINE, &ha->flags) &&
154 !test_bit(AF_HBA_GOING_AWAY, &ha->flags)) {
155 /* Do not poll for completion. Use completion queue */
156 set_bit(AF_MBOX_COMMAND_NOPOLL, &ha->flags);
157 wait_for_completion_timeout(&ha->mbx_intr_comp, MBOX_TOV * HZ);
158 clear_bit(AF_MBOX_COMMAND_NOPOLL, &ha->flags);
159 } else {
160 /* Poll for command to complete */
161 wait_count = jiffies + MBOX_TOV * HZ;
162 while (test_bit(AF_MBOX_COMMAND_DONE, &ha->flags) == 0) {
163 if (time_after_eq(jiffies, wait_count))
164 break;
Lalit Chandivade2232be02010-07-30 14:38:47 +0530165
David Somayajuluafaf5a22006-09-19 10:28:00 -0700166 /*
167 * Service the interrupt.
168 * The ISR will save the mailbox status registers
169 * to a temporary storage location in the adapter
170 * structure.
171 */
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +0530172
173 spin_lock_irqsave(&ha->hardware_lock, flags);
174 if (is_qla8022(ha)) {
175 intr_status =
176 readl(&ha->qla4_8xxx_reg->host_int);
177 if (intr_status & ISRX_82XX_RISC_INT) {
178 ha->mbox_status_count = outCount;
179 intr_status =
180 readl(&ha->qla4_8xxx_reg->host_status);
181 ha->isp_ops->interrupt_service_routine(
182 ha, intr_status);
183 if (test_bit(AF_INTERRUPTS_ON,
184 &ha->flags) &&
185 test_bit(AF_INTx_ENABLED,
186 &ha->flags))
187 qla4_8xxx_wr_32(ha,
188 ha->nx_legacy_intr.tgt_mask_reg,
189 0xfbff);
190 }
191 } else {
192 intr_status = readl(&ha->reg->ctrl_status);
193 if (intr_status & INTR_PENDING) {
194 /*
195 * Service the interrupt.
196 * The ISR will save the mailbox status
197 * registers to a temporary storage
198 * location in the adapter structure.
199 */
200 ha->mbox_status_count = outCount;
201 ha->isp_ops->interrupt_service_routine(
202 ha, intr_status);
203 }
204 }
205 spin_unlock_irqrestore(&ha->hardware_lock, flags);
206 msleep(10);
David Somayajuluafaf5a22006-09-19 10:28:00 -0700207 }
David Somayajuluafaf5a22006-09-19 10:28:00 -0700208 }
David Somayajuluafaf5a22006-09-19 10:28:00 -0700209
210 /* Check for mailbox timeout. */
211 if (!test_bit(AF_MBOX_COMMAND_DONE, &ha->flags)) {
Nilesh Javali21033632010-07-30 14:28:07 +0530212 if (is_qla8022(ha) &&
213 test_bit(AF_FW_RECOVERY, &ha->flags)) {
214 DEBUG2(ql4_printk(KERN_INFO, ha,
215 "scsi%ld: %s: prematurely completing mbx cmd as "
216 "firmware recovery detected\n",
217 ha->host_no, __func__));
218 goto mbox_exit;
219 }
David Somayajuluafaf5a22006-09-19 10:28:00 -0700220 DEBUG2(printk("scsi%ld: Mailbox Cmd 0x%08X timed out ...,"
221 " Scheduling Adapter Reset\n", ha->host_no,
222 mbx_cmd[0]));
223 ha->mailbox_timeout_count++;
224 mbx_sts[0] = (-1);
225 set_bit(DPC_RESET_HA, &ha->dpc_flags);
226 goto mbox_exit;
227 }
228
229 /*
230 * Copy the mailbox out registers to the caller's mailbox in/out
231 * structure.
232 */
233 spin_lock_irqsave(&ha->hardware_lock, flags);
234 for (i = 0; i < outCount; i++)
235 mbx_sts[i] = ha->mbox_status[i];
236
237 /* Set return status and error flags (if applicable). */
238 switch (ha->mbox_status[0]) {
239 case MBOX_STS_COMMAND_COMPLETE:
240 status = QLA_SUCCESS;
241 break;
242
243 case MBOX_STS_INTERMEDIATE_COMPLETION:
244 status = QLA_SUCCESS;
245 break;
246
247 case MBOX_STS_BUSY:
248 DEBUG2( printk("scsi%ld: %s: Cmd = %08X, ISP BUSY\n",
249 ha->host_no, __func__, mbx_cmd[0]));
250 ha->mailbox_timeout_count++;
251 break;
252
253 default:
254 DEBUG2(printk("scsi%ld: %s: **** FAILED, cmd = %08X, "
255 "sts = %08X ****\n", ha->host_no, __func__,
256 mbx_cmd[0], mbx_sts[0]));
257 break;
258 }
259 spin_unlock_irqrestore(&ha->hardware_lock, flags);
260
261mbox_exit:
David C Somayajulu477ffb92007-01-22 12:26:11 -0800262 mutex_lock(&ha->mbox_sem);
David Somayajuluafaf5a22006-09-19 10:28:00 -0700263 clear_bit(AF_MBOX_COMMAND, &ha->flags);
David Somayajuluafaf5a22006-09-19 10:28:00 -0700264 mutex_unlock(&ha->mbox_sem);
David C Somayajulu477ffb92007-01-22 12:26:11 -0800265 clear_bit(AF_MBOX_COMMAND_DONE, &ha->flags);
David Somayajuluafaf5a22006-09-19 10:28:00 -0700266
267 return status;
268}
269
Nilesh Javali21033632010-07-30 14:28:07 +0530270void qla4xxx_mailbox_premature_completion(struct scsi_qla_host *ha)
271{
272 set_bit(AF_FW_RECOVERY, &ha->flags);
273 ql4_printk(KERN_INFO, ha, "scsi%ld: %s: set FW RECOVERY!\n",
274 ha->host_no, __func__);
275
276 if (test_bit(AF_MBOX_COMMAND, &ha->flags)) {
277 if (test_bit(AF_MBOX_COMMAND_NOPOLL, &ha->flags)) {
278 complete(&ha->mbx_intr_comp);
279 ql4_printk(KERN_INFO, ha, "scsi%ld: %s: Due to fw "
280 "recovery, doing premature completion of "
281 "mbx cmd\n", ha->host_no, __func__);
282
283 } else {
284 set_bit(AF_MBOX_COMMAND_DONE, &ha->flags);
285 ql4_printk(KERN_INFO, ha, "scsi%ld: %s: Due to fw "
286 "recovery, doing premature completion of "
287 "polling mbx cmd\n", ha->host_no, __func__);
288 }
289 }
290}
291
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +0530292static uint8_t
Vikas Chaudhary2a49a782010-04-28 11:37:07 +0530293qla4xxx_set_ifcb(struct scsi_qla_host *ha, uint32_t *mbox_cmd,
294 uint32_t *mbox_sts, dma_addr_t init_fw_cb_dma)
295{
296 memset(mbox_cmd, 0, sizeof(mbox_cmd[0]) * MBOX_REG_COUNT);
297 memset(mbox_sts, 0, sizeof(mbox_sts[0]) * MBOX_REG_COUNT);
Shyam Sundar2657c802010-10-06 22:50:29 -0700298
299 if (is_qla8022(ha))
300 qla4_8xxx_wr_32(ha, ha->nx_db_wr_ptr, 0);
301
Vikas Chaudhary2a49a782010-04-28 11:37:07 +0530302 mbox_cmd[0] = MBOX_CMD_INITIALIZE_FIRMWARE;
303 mbox_cmd[1] = 0;
304 mbox_cmd[2] = LSDW(init_fw_cb_dma);
305 mbox_cmd[3] = MSDW(init_fw_cb_dma);
306 mbox_cmd[4] = sizeof(struct addr_ctrl_blk);
307 mbox_cmd[5] = (IFCB_VER_MAX << 8) | IFCB_VER_MIN;
308
309 if (qla4xxx_mailbox_command(ha, 6, 6, mbox_cmd, mbox_sts) !=
310 QLA_SUCCESS) {
311 DEBUG2(printk(KERN_WARNING "scsi%ld: %s: "
312 "MBOX_CMD_INITIALIZE_FIRMWARE"
313 " failed w/ status %04X\n",
314 ha->host_no, __func__, mbox_sts[0]));
315 return QLA_ERROR;
316 }
317 return QLA_SUCCESS;
318}
319
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +0530320static uint8_t
Vikas Chaudhary2a49a782010-04-28 11:37:07 +0530321qla4xxx_get_ifcb(struct scsi_qla_host *ha, uint32_t *mbox_cmd,
322 uint32_t *mbox_sts, dma_addr_t init_fw_cb_dma)
323{
324 memset(mbox_cmd, 0, sizeof(mbox_cmd[0]) * MBOX_REG_COUNT);
325 memset(mbox_sts, 0, sizeof(mbox_sts[0]) * MBOX_REG_COUNT);
326 mbox_cmd[0] = MBOX_CMD_GET_INIT_FW_CTRL_BLOCK;
327 mbox_cmd[2] = LSDW(init_fw_cb_dma);
328 mbox_cmd[3] = MSDW(init_fw_cb_dma);
329 mbox_cmd[4] = sizeof(struct addr_ctrl_blk);
330
331 if (qla4xxx_mailbox_command(ha, 5, 5, mbox_cmd, mbox_sts) !=
332 QLA_SUCCESS) {
333 DEBUG2(printk(KERN_WARNING "scsi%ld: %s: "
334 "MBOX_CMD_GET_INIT_FW_CTRL_BLOCK"
335 " failed w/ status %04X\n",
336 ha->host_no, __func__, mbox_sts[0]));
337 return QLA_ERROR;
338 }
339 return QLA_SUCCESS;
340}
341
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +0530342static void
Vikas Chaudhary2a49a782010-04-28 11:37:07 +0530343qla4xxx_update_local_ip(struct scsi_qla_host *ha,
344 struct addr_ctrl_blk *init_fw_cb)
345{
346 /* Save IPv4 Address Info */
347 memcpy(ha->ip_address, init_fw_cb->ipv4_addr,
348 min(sizeof(ha->ip_address), sizeof(init_fw_cb->ipv4_addr)));
349 memcpy(ha->subnet_mask, init_fw_cb->ipv4_subnet,
350 min(sizeof(ha->subnet_mask), sizeof(init_fw_cb->ipv4_subnet)));
351 memcpy(ha->gateway, init_fw_cb->ipv4_gw_addr,
352 min(sizeof(ha->gateway), sizeof(init_fw_cb->ipv4_gw_addr)));
353
354 if (is_ipv6_enabled(ha)) {
355 /* Save IPv6 Address */
356 ha->ipv6_link_local_state = init_fw_cb->ipv6_lnk_lcl_addr_state;
357 ha->ipv6_addr0_state = init_fw_cb->ipv6_addr0_state;
358 ha->ipv6_addr1_state = init_fw_cb->ipv6_addr1_state;
359 ha->ipv6_default_router_state = init_fw_cb->ipv6_dflt_rtr_state;
360 ha->ipv6_link_local_addr.in6_u.u6_addr8[0] = 0xFE;
361 ha->ipv6_link_local_addr.in6_u.u6_addr8[1] = 0x80;
362
363 memcpy(&ha->ipv6_link_local_addr.in6_u.u6_addr8[8],
364 init_fw_cb->ipv6_if_id,
365 min(sizeof(ha->ipv6_link_local_addr)/2,
366 sizeof(init_fw_cb->ipv6_if_id)));
367 memcpy(&ha->ipv6_addr0, init_fw_cb->ipv6_addr0,
368 min(sizeof(ha->ipv6_addr0),
369 sizeof(init_fw_cb->ipv6_addr0)));
370 memcpy(&ha->ipv6_addr1, init_fw_cb->ipv6_addr1,
371 min(sizeof(ha->ipv6_addr1),
372 sizeof(init_fw_cb->ipv6_addr1)));
373 memcpy(&ha->ipv6_default_router_addr,
374 init_fw_cb->ipv6_dflt_rtr_addr,
375 min(sizeof(ha->ipv6_default_router_addr),
376 sizeof(init_fw_cb->ipv6_dflt_rtr_addr)));
377 }
378}
379
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +0530380static uint8_t
Vikas Chaudhary2a49a782010-04-28 11:37:07 +0530381qla4xxx_update_local_ifcb(struct scsi_qla_host *ha,
382 uint32_t *mbox_cmd,
383 uint32_t *mbox_sts,
384 struct addr_ctrl_blk *init_fw_cb,
385 dma_addr_t init_fw_cb_dma)
386{
387 if (qla4xxx_get_ifcb(ha, mbox_cmd, mbox_sts, init_fw_cb_dma)
388 != QLA_SUCCESS) {
389 DEBUG2(printk(KERN_WARNING
390 "scsi%ld: %s: Failed to get init_fw_ctrl_blk\n",
391 ha->host_no, __func__));
392 return QLA_ERROR;
393 }
394
395 DEBUG2(qla4xxx_dump_buffer(init_fw_cb, sizeof(struct addr_ctrl_blk)));
396
397 /* Save some info in adapter structure. */
398 ha->acb_version = init_fw_cb->acb_version;
399 ha->firmware_options = le16_to_cpu(init_fw_cb->fw_options);
400 ha->tcp_options = le16_to_cpu(init_fw_cb->ipv4_tcp_opts);
401 ha->ipv4_options = le16_to_cpu(init_fw_cb->ipv4_ip_opts);
402 ha->ipv4_addr_state = le16_to_cpu(init_fw_cb->ipv4_addr_state);
403 ha->heartbeat_interval = init_fw_cb->hb_interval;
404 memcpy(ha->name_string, init_fw_cb->iscsi_name,
405 min(sizeof(ha->name_string),
406 sizeof(init_fw_cb->iscsi_name)));
407 /*memcpy(ha->alias, init_fw_cb->Alias,
408 min(sizeof(ha->alias), sizeof(init_fw_cb->Alias)));*/
409
410 /* Save Command Line Paramater info */
Vikas Chaudhary2a49a782010-04-28 11:37:07 +0530411 ha->discovery_wait = ql4xdiscoverywait;
412
413 if (ha->acb_version == ACB_SUPPORTED) {
414 ha->ipv6_options = init_fw_cb->ipv6_opts;
415 ha->ipv6_addl_options = init_fw_cb->ipv6_addtl_opts;
416 }
417 qla4xxx_update_local_ip(ha, init_fw_cb);
418
419 return QLA_SUCCESS;
420}
421
David Somayajuluafaf5a22006-09-19 10:28:00 -0700422/**
423 * qla4xxx_initialize_fw_cb - initializes firmware control block.
424 * @ha: Pointer to host adapter structure.
425 **/
426int qla4xxx_initialize_fw_cb(struct scsi_qla_host * ha)
427{
Vikas Chaudhary2a49a782010-04-28 11:37:07 +0530428 struct addr_ctrl_blk *init_fw_cb;
David Somayajuluafaf5a22006-09-19 10:28:00 -0700429 dma_addr_t init_fw_cb_dma;
430 uint32_t mbox_cmd[MBOX_REG_COUNT];
431 uint32_t mbox_sts[MBOX_REG_COUNT];
432 int status = QLA_ERROR;
433
434 init_fw_cb = dma_alloc_coherent(&ha->pdev->dev,
Vikas Chaudhary2a49a782010-04-28 11:37:07 +0530435 sizeof(struct addr_ctrl_blk),
David Somayajuluafaf5a22006-09-19 10:28:00 -0700436 &init_fw_cb_dma, GFP_KERNEL);
437 if (init_fw_cb == NULL) {
438 DEBUG2(printk("scsi%ld: %s: Unable to alloc init_cb\n",
439 ha->host_no, __func__));
Prasanna Mumbaibeabe7c2010-07-10 14:49:38 +0530440 goto exit_init_fw_cb_no_free;
David Somayajuluafaf5a22006-09-19 10:28:00 -0700441 }
Vikas Chaudhary2a49a782010-04-28 11:37:07 +0530442 memset(init_fw_cb, 0, sizeof(struct addr_ctrl_blk));
David Somayajuluafaf5a22006-09-19 10:28:00 -0700443
444 /* Get Initialize Firmware Control Block. */
445 memset(&mbox_cmd, 0, sizeof(mbox_cmd));
446 memset(&mbox_sts, 0, sizeof(mbox_sts));
David C Somayajuluc0e344c2007-05-23 18:03:27 -0700447
Vikas Chaudhary2a49a782010-04-28 11:37:07 +0530448 if (qla4xxx_get_ifcb(ha, &mbox_cmd[0], &mbox_sts[0], init_fw_cb_dma) !=
David Somayajuluafaf5a22006-09-19 10:28:00 -0700449 QLA_SUCCESS) {
450 dma_free_coherent(&ha->pdev->dev,
Vikas Chaudhary2a49a782010-04-28 11:37:07 +0530451 sizeof(struct addr_ctrl_blk),
David Somayajuluafaf5a22006-09-19 10:28:00 -0700452 init_fw_cb, init_fw_cb_dma);
Vikas Chaudhary2a49a782010-04-28 11:37:07 +0530453 goto exit_init_fw_cb;
David Somayajuluafaf5a22006-09-19 10:28:00 -0700454 }
455
456 /* Initialize request and response queues. */
457 qla4xxx_init_rings(ha);
458
459 /* Fill in the request and response queue information. */
Vikas Chaudhary2a49a782010-04-28 11:37:07 +0530460 init_fw_cb->rqq_consumer_idx = cpu_to_le16(ha->request_out);
461 init_fw_cb->compq_producer_idx = cpu_to_le16(ha->response_in);
462 init_fw_cb->rqq_len = __constant_cpu_to_le16(REQUEST_QUEUE_DEPTH);
463 init_fw_cb->compq_len = __constant_cpu_to_le16(RESPONSE_QUEUE_DEPTH);
464 init_fw_cb->rqq_addr_lo = cpu_to_le32(LSDW(ha->request_dma));
465 init_fw_cb->rqq_addr_hi = cpu_to_le32(MSDW(ha->request_dma));
466 init_fw_cb->compq_addr_lo = cpu_to_le32(LSDW(ha->response_dma));
467 init_fw_cb->compq_addr_hi = cpu_to_le32(MSDW(ha->response_dma));
468 init_fw_cb->shdwreg_addr_lo = cpu_to_le32(LSDW(ha->shadow_regs_dma));
469 init_fw_cb->shdwreg_addr_hi = cpu_to_le32(MSDW(ha->shadow_regs_dma));
David Somayajuluafaf5a22006-09-19 10:28:00 -0700470
471 /* Set up required options. */
Vikas Chaudhary2a49a782010-04-28 11:37:07 +0530472 init_fw_cb->fw_options |=
David Somayajuluafaf5a22006-09-19 10:28:00 -0700473 __constant_cpu_to_le16(FWOPT_SESSION_MODE |
474 FWOPT_INITIATOR_MODE);
Shyam Sundar2657c802010-10-06 22:50:29 -0700475
476 if (is_qla8022(ha))
477 init_fw_cb->fw_options |=
478 __constant_cpu_to_le16(FWOPT_ENABLE_CRBDB);
479
Vikas Chaudhary2a49a782010-04-28 11:37:07 +0530480 init_fw_cb->fw_options &= __constant_cpu_to_le16(~FWOPT_TARGET_MODE);
David Somayajuluafaf5a22006-09-19 10:28:00 -0700481
Vikas Chaudhary2a49a782010-04-28 11:37:07 +0530482 if (qla4xxx_set_ifcb(ha, &mbox_cmd[0], &mbox_sts[0], init_fw_cb_dma)
483 != QLA_SUCCESS) {
484 DEBUG2(printk(KERN_WARNING
485 "scsi%ld: %s: Failed to set init_fw_ctrl_blk\n",
486 ha->host_no, __func__));
487 goto exit_init_fw_cb;
David Somayajuluafaf5a22006-09-19 10:28:00 -0700488 }
Vikas Chaudhary2a49a782010-04-28 11:37:07 +0530489
490 if (qla4xxx_update_local_ifcb(ha, &mbox_cmd[0], &mbox_sts[0],
491 init_fw_cb, init_fw_cb_dma) != QLA_SUCCESS) {
492 DEBUG2(printk("scsi%ld: %s: Failed to update local ifcb\n",
493 ha->host_no, __func__));
494 goto exit_init_fw_cb;
495 }
496 status = QLA_SUCCESS;
497
498exit_init_fw_cb:
499 dma_free_coherent(&ha->pdev->dev, sizeof(struct addr_ctrl_blk),
500 init_fw_cb, init_fw_cb_dma);
Prasanna Mumbaibeabe7c2010-07-10 14:49:38 +0530501exit_init_fw_cb_no_free:
David Somayajuluafaf5a22006-09-19 10:28:00 -0700502 return status;
503}
504
505/**
506 * qla4xxx_get_dhcp_ip_address - gets HBA ip address via DHCP
507 * @ha: Pointer to host adapter structure.
508 **/
509int qla4xxx_get_dhcp_ip_address(struct scsi_qla_host * ha)
510{
Vikas Chaudhary2a49a782010-04-28 11:37:07 +0530511 struct addr_ctrl_blk *init_fw_cb;
David Somayajuluafaf5a22006-09-19 10:28:00 -0700512 dma_addr_t init_fw_cb_dma;
513 uint32_t mbox_cmd[MBOX_REG_COUNT];
514 uint32_t mbox_sts[MBOX_REG_COUNT];
515
516 init_fw_cb = dma_alloc_coherent(&ha->pdev->dev,
Vikas Chaudhary2a49a782010-04-28 11:37:07 +0530517 sizeof(struct addr_ctrl_blk),
David Somayajuluafaf5a22006-09-19 10:28:00 -0700518 &init_fw_cb_dma, GFP_KERNEL);
519 if (init_fw_cb == NULL) {
520 printk("scsi%ld: %s: Unable to alloc init_cb\n", ha->host_no,
521 __func__);
Prasanna Mumbaibeabe7c2010-07-10 14:49:38 +0530522 return QLA_ERROR;
David Somayajuluafaf5a22006-09-19 10:28:00 -0700523 }
524
525 /* Get Initialize Firmware Control Block. */
Vikas Chaudhary2a49a782010-04-28 11:37:07 +0530526 memset(init_fw_cb, 0, sizeof(struct addr_ctrl_blk));
527 if (qla4xxx_get_ifcb(ha, &mbox_cmd[0], &mbox_sts[0], init_fw_cb_dma) !=
David Somayajuluafaf5a22006-09-19 10:28:00 -0700528 QLA_SUCCESS) {
529 DEBUG2(printk("scsi%ld: %s: Failed to get init_fw_ctrl_blk\n",
530 ha->host_no, __func__));
531 dma_free_coherent(&ha->pdev->dev,
Vikas Chaudhary2a49a782010-04-28 11:37:07 +0530532 sizeof(struct addr_ctrl_blk),
David Somayajuluafaf5a22006-09-19 10:28:00 -0700533 init_fw_cb, init_fw_cb_dma);
534 return QLA_ERROR;
535 }
536
537 /* Save IP Address. */
Vikas Chaudhary2a49a782010-04-28 11:37:07 +0530538 qla4xxx_update_local_ip(ha, init_fw_cb);
539 dma_free_coherent(&ha->pdev->dev, sizeof(struct addr_ctrl_blk),
540 init_fw_cb, init_fw_cb_dma);
David Somayajuluafaf5a22006-09-19 10:28:00 -0700541
542 return QLA_SUCCESS;
543}
544
545/**
546 * qla4xxx_get_firmware_state - gets firmware state of HBA
547 * @ha: Pointer to host adapter structure.
548 **/
549int qla4xxx_get_firmware_state(struct scsi_qla_host * ha)
550{
551 uint32_t mbox_cmd[MBOX_REG_COUNT];
552 uint32_t mbox_sts[MBOX_REG_COUNT];
553
554 /* Get firmware version */
555 memset(&mbox_cmd, 0, sizeof(mbox_cmd));
556 memset(&mbox_sts, 0, sizeof(mbox_sts));
David C Somayajuluc0e344c2007-05-23 18:03:27 -0700557
David Somayajuluafaf5a22006-09-19 10:28:00 -0700558 mbox_cmd[0] = MBOX_CMD_GET_FW_STATE;
David C Somayajuluc0e344c2007-05-23 18:03:27 -0700559
560 if (qla4xxx_mailbox_command(ha, MBOX_REG_COUNT, 4, &mbox_cmd[0], &mbox_sts[0]) !=
David Somayajuluafaf5a22006-09-19 10:28:00 -0700561 QLA_SUCCESS) {
562 DEBUG2(printk("scsi%ld: %s: MBOX_CMD_GET_FW_STATE failed w/ "
563 "status %04X\n", ha->host_no, __func__,
564 mbox_sts[0]));
565 return QLA_ERROR;
566 }
567 ha->firmware_state = mbox_sts[1];
568 ha->board_id = mbox_sts[2];
569 ha->addl_fw_state = mbox_sts[3];
570 DEBUG2(printk("scsi%ld: %s firmware_state=0x%x\n",
571 ha->host_no, __func__, ha->firmware_state);)
572
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +0530573 return QLA_SUCCESS;
David Somayajuluafaf5a22006-09-19 10:28:00 -0700574}
575
576/**
577 * qla4xxx_get_firmware_status - retrieves firmware status
578 * @ha: Pointer to host adapter structure.
579 **/
580int qla4xxx_get_firmware_status(struct scsi_qla_host * ha)
581{
582 uint32_t mbox_cmd[MBOX_REG_COUNT];
583 uint32_t mbox_sts[MBOX_REG_COUNT];
584
585 /* Get firmware version */
586 memset(&mbox_cmd, 0, sizeof(mbox_cmd));
587 memset(&mbox_sts, 0, sizeof(mbox_sts));
David C Somayajuluc0e344c2007-05-23 18:03:27 -0700588
David Somayajuluafaf5a22006-09-19 10:28:00 -0700589 mbox_cmd[0] = MBOX_CMD_GET_FW_STATUS;
David C Somayajuluc0e344c2007-05-23 18:03:27 -0700590
591 if (qla4xxx_mailbox_command(ha, MBOX_REG_COUNT, 3, &mbox_cmd[0], &mbox_sts[0]) !=
David Somayajuluafaf5a22006-09-19 10:28:00 -0700592 QLA_SUCCESS) {
593 DEBUG2(printk("scsi%ld: %s: MBOX_CMD_GET_FW_STATUS failed w/ "
594 "status %04X\n", ha->host_no, __func__,
595 mbox_sts[0]));
596 return QLA_ERROR;
597 }
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +0530598
599 ql4_printk(KERN_INFO, ha, "%ld firmare IOCBs available (%d).\n",
Vikas Chaudharyf581a3f2010-10-06 22:47:48 -0700600 ha->host_no, mbox_sts[2]);
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +0530601
David Somayajuluafaf5a22006-09-19 10:28:00 -0700602 return QLA_SUCCESS;
603}
604
605/**
606 * qla4xxx_get_fwddb_entry - retrieves firmware ddb entry
607 * @ha: Pointer to host adapter structure.
608 * @fw_ddb_index: Firmware's device database index
609 * @fw_ddb_entry: Pointer to firmware's device database entry structure
610 * @num_valid_ddb_entries: Pointer to number of valid ddb entries
611 * @next_ddb_index: Pointer to next valid device database index
612 * @fw_ddb_device_state: Pointer to device state
613 **/
614int qla4xxx_get_fwddb_entry(struct scsi_qla_host *ha,
615 uint16_t fw_ddb_index,
616 struct dev_db_entry *fw_ddb_entry,
617 dma_addr_t fw_ddb_entry_dma,
618 uint32_t *num_valid_ddb_entries,
619 uint32_t *next_ddb_index,
620 uint32_t *fw_ddb_device_state,
621 uint32_t *conn_err_detail,
622 uint16_t *tcp_source_port_num,
623 uint16_t *connection_id)
624{
625 int status = QLA_ERROR;
Vikas Chaudhary2a49a782010-04-28 11:37:07 +0530626 uint16_t options;
David Somayajuluafaf5a22006-09-19 10:28:00 -0700627 uint32_t mbox_cmd[MBOX_REG_COUNT];
628 uint32_t mbox_sts[MBOX_REG_COUNT];
629
630 /* Make sure the device index is valid */
631 if (fw_ddb_index >= MAX_DDB_ENTRIES) {
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +0530632 DEBUG2(printk("scsi%ld: %s: ddb [%d] out of range.\n",
David Somayajuluafaf5a22006-09-19 10:28:00 -0700633 ha->host_no, __func__, fw_ddb_index));
634 goto exit_get_fwddb;
635 }
636 memset(&mbox_cmd, 0, sizeof(mbox_cmd));
637 memset(&mbox_sts, 0, sizeof(mbox_sts));
David C Somayajuluc0e344c2007-05-23 18:03:27 -0700638
David Somayajuluafaf5a22006-09-19 10:28:00 -0700639 mbox_cmd[0] = MBOX_CMD_GET_DATABASE_ENTRY;
640 mbox_cmd[1] = (uint32_t) fw_ddb_index;
641 mbox_cmd[2] = LSDW(fw_ddb_entry_dma);
642 mbox_cmd[3] = MSDW(fw_ddb_entry_dma);
David C Somayajuluc0e344c2007-05-23 18:03:27 -0700643 mbox_cmd[4] = sizeof(struct dev_db_entry);
644
645 if (qla4xxx_mailbox_command(ha, MBOX_REG_COUNT, 7, &mbox_cmd[0], &mbox_sts[0]) ==
David Somayajuluafaf5a22006-09-19 10:28:00 -0700646 QLA_ERROR) {
647 DEBUG2(printk("scsi%ld: %s: MBOX_CMD_GET_DATABASE_ENTRY failed"
648 " with status 0x%04X\n", ha->host_no, __func__,
649 mbox_sts[0]));
650 goto exit_get_fwddb;
651 }
652 if (fw_ddb_index != mbox_sts[1]) {
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +0530653 DEBUG2(printk("scsi%ld: %s: ddb mismatch [%d] != [%d].\n",
David Somayajuluafaf5a22006-09-19 10:28:00 -0700654 ha->host_no, __func__, fw_ddb_index,
655 mbox_sts[1]));
656 goto exit_get_fwddb;
657 }
658 if (fw_ddb_entry) {
Vikas Chaudhary2a49a782010-04-28 11:37:07 +0530659 options = le16_to_cpu(fw_ddb_entry->options);
660 if (options & DDB_OPT_IPV6_DEVICE) {
Vikas Chaudharyc2660df2010-07-10 14:51:02 +0530661 ql4_printk(KERN_INFO, ha, "%s: DDB[%d] MB0 %04x Tot %d "
Vikas Chaudhary2a49a782010-04-28 11:37:07 +0530662 "Next %d State %04x ConnErr %08x %pI6 "
663 ":%04d \"%s\"\n", __func__, fw_ddb_index,
664 mbox_sts[0], mbox_sts[2], mbox_sts[3],
665 mbox_sts[4], mbox_sts[5],
666 fw_ddb_entry->ip_addr,
667 le16_to_cpu(fw_ddb_entry->port),
668 fw_ddb_entry->iscsi_name);
669 } else {
Vikas Chaudharyc2660df2010-07-10 14:51:02 +0530670 ql4_printk(KERN_INFO, ha, "%s: DDB[%d] MB0 %04x Tot %d "
Vikas Chaudhary2a49a782010-04-28 11:37:07 +0530671 "Next %d State %04x ConnErr %08x %pI4 "
672 ":%04d \"%s\"\n", __func__, fw_ddb_index,
673 mbox_sts[0], mbox_sts[2], mbox_sts[3],
674 mbox_sts[4], mbox_sts[5],
675 fw_ddb_entry->ip_addr,
676 le16_to_cpu(fw_ddb_entry->port),
677 fw_ddb_entry->iscsi_name);
678 }
David Somayajuluafaf5a22006-09-19 10:28:00 -0700679 }
680 if (num_valid_ddb_entries)
681 *num_valid_ddb_entries = mbox_sts[2];
682 if (next_ddb_index)
683 *next_ddb_index = mbox_sts[3];
684 if (fw_ddb_device_state)
685 *fw_ddb_device_state = mbox_sts[4];
686
687 /*
688 * RA: This mailbox has been changed to pass connection error and
689 * details. Its true for ISP4010 as per Version E - Not sure when it
690 * was changed. Get the time2wait from the fw_dd_entry field :
691 * default_time2wait which we call it as minTime2Wait DEV_DB_ENTRY
692 * struct.
693 */
694 if (conn_err_detail)
695 *conn_err_detail = mbox_sts[5];
696 if (tcp_source_port_num)
Randy Dunlap14823382010-04-22 11:02:14 -0700697 *tcp_source_port_num = (uint16_t) (mbox_sts[6] >> 16);
David Somayajuluafaf5a22006-09-19 10:28:00 -0700698 if (connection_id)
699 *connection_id = (uint16_t) mbox_sts[6] & 0x00FF;
700 status = QLA_SUCCESS;
701
702exit_get_fwddb:
703 return status;
704}
705
706/**
707 * qla4xxx_set_fwddb_entry - sets a ddb entry.
708 * @ha: Pointer to host adapter structure.
709 * @fw_ddb_index: Firmware's device database index
710 * @fw_ddb_entry: Pointer to firmware's ddb entry structure, or NULL.
711 *
712 * This routine initializes or updates the adapter's device database
713 * entry for the specified device. It also triggers a login for the
714 * specified device. Therefore, it may also be used as a secondary
715 * login routine when a NULL pointer is specified for the fw_ddb_entry.
716 **/
717int qla4xxx_set_ddb_entry(struct scsi_qla_host * ha, uint16_t fw_ddb_index,
718 dma_addr_t fw_ddb_entry_dma)
719{
720 uint32_t mbox_cmd[MBOX_REG_COUNT];
721 uint32_t mbox_sts[MBOX_REG_COUNT];
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +0530722 int status;
David Somayajuluafaf5a22006-09-19 10:28:00 -0700723
724 /* Do not wait for completion. The firmware will send us an
725 * ASTS_DATABASE_CHANGED (0x8014) to notify us of the login status.
726 */
727 memset(&mbox_cmd, 0, sizeof(mbox_cmd));
728 memset(&mbox_sts, 0, sizeof(mbox_sts));
729
730 mbox_cmd[0] = MBOX_CMD_SET_DATABASE_ENTRY;
731 mbox_cmd[1] = (uint32_t) fw_ddb_index;
732 mbox_cmd[2] = LSDW(fw_ddb_entry_dma);
733 mbox_cmd[3] = MSDW(fw_ddb_entry_dma);
David C Somayajuluc0e344c2007-05-23 18:03:27 -0700734 mbox_cmd[4] = sizeof(struct dev_db_entry);
735
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +0530736 status = qla4xxx_mailbox_command(ha, MBOX_REG_COUNT, 5, &mbox_cmd[0],
737 &mbox_sts[0]);
738 DEBUG2(printk("scsi%ld: %s: status=%d mbx0=0x%x mbx4=0x%x\n",
739 ha->host_no, __func__, status, mbox_sts[0], mbox_sts[4]);)
740
741 return status;
David Somayajuluafaf5a22006-09-19 10:28:00 -0700742}
743
David Somayajuluafaf5a22006-09-19 10:28:00 -0700744/**
745 * qla4xxx_get_crash_record - retrieves crash record.
746 * @ha: Pointer to host adapter structure.
747 *
748 * This routine retrieves a crash record from the QLA4010 after an 8002h aen.
749 **/
750void qla4xxx_get_crash_record(struct scsi_qla_host * ha)
751{
752 uint32_t mbox_cmd[MBOX_REG_COUNT];
753 uint32_t mbox_sts[MBOX_REG_COUNT];
754 struct crash_record *crash_record = NULL;
755 dma_addr_t crash_record_dma = 0;
756 uint32_t crash_record_size = 0;
David C Somayajuluc0e344c2007-05-23 18:03:27 -0700757
David Somayajuluafaf5a22006-09-19 10:28:00 -0700758 memset(&mbox_cmd, 0, sizeof(mbox_cmd));
759 memset(&mbox_sts, 0, sizeof(mbox_cmd));
760
761 /* Get size of crash record. */
762 mbox_cmd[0] = MBOX_CMD_GET_CRASH_RECORD;
David C Somayajuluc0e344c2007-05-23 18:03:27 -0700763
764 if (qla4xxx_mailbox_command(ha, MBOX_REG_COUNT, 5, &mbox_cmd[0], &mbox_sts[0]) !=
David Somayajuluafaf5a22006-09-19 10:28:00 -0700765 QLA_SUCCESS) {
766 DEBUG2(printk("scsi%ld: %s: ERROR: Unable to retrieve size!\n",
767 ha->host_no, __func__));
768 goto exit_get_crash_record;
769 }
770 crash_record_size = mbox_sts[4];
771 if (crash_record_size == 0) {
772 DEBUG2(printk("scsi%ld: %s: ERROR: Crash record size is 0!\n",
773 ha->host_no, __func__));
774 goto exit_get_crash_record;
775 }
776
777 /* Alloc Memory for Crash Record. */
778 crash_record = dma_alloc_coherent(&ha->pdev->dev, crash_record_size,
779 &crash_record_dma, GFP_KERNEL);
780 if (crash_record == NULL)
781 goto exit_get_crash_record;
782
783 /* Get Crash Record. */
David C Somayajuluc0e344c2007-05-23 18:03:27 -0700784 memset(&mbox_cmd, 0, sizeof(mbox_cmd));
785 memset(&mbox_sts, 0, sizeof(mbox_cmd));
786
David Somayajuluafaf5a22006-09-19 10:28:00 -0700787 mbox_cmd[0] = MBOX_CMD_GET_CRASH_RECORD;
788 mbox_cmd[2] = LSDW(crash_record_dma);
789 mbox_cmd[3] = MSDW(crash_record_dma);
790 mbox_cmd[4] = crash_record_size;
David C Somayajuluc0e344c2007-05-23 18:03:27 -0700791
792 if (qla4xxx_mailbox_command(ha, MBOX_REG_COUNT, 5, &mbox_cmd[0], &mbox_sts[0]) !=
David Somayajuluafaf5a22006-09-19 10:28:00 -0700793 QLA_SUCCESS)
794 goto exit_get_crash_record;
795
796 /* Dump Crash Record. */
797
798exit_get_crash_record:
799 if (crash_record)
800 dma_free_coherent(&ha->pdev->dev, crash_record_size,
801 crash_record, crash_record_dma);
802}
803
804/**
805 * qla4xxx_get_conn_event_log - retrieves connection event log
806 * @ha: Pointer to host adapter structure.
807 **/
808void qla4xxx_get_conn_event_log(struct scsi_qla_host * ha)
809{
810 uint32_t mbox_cmd[MBOX_REG_COUNT];
811 uint32_t mbox_sts[MBOX_REG_COUNT];
812 struct conn_event_log_entry *event_log = NULL;
813 dma_addr_t event_log_dma = 0;
814 uint32_t event_log_size = 0;
815 uint32_t num_valid_entries;
816 uint32_t oldest_entry = 0;
817 uint32_t max_event_log_entries;
818 uint8_t i;
819
820
821 memset(&mbox_cmd, 0, sizeof(mbox_cmd));
822 memset(&mbox_sts, 0, sizeof(mbox_cmd));
823
824 /* Get size of crash record. */
825 mbox_cmd[0] = MBOX_CMD_GET_CONN_EVENT_LOG;
David C Somayajuluc0e344c2007-05-23 18:03:27 -0700826
827 if (qla4xxx_mailbox_command(ha, MBOX_REG_COUNT, 5, &mbox_cmd[0], &mbox_sts[0]) !=
David Somayajuluafaf5a22006-09-19 10:28:00 -0700828 QLA_SUCCESS)
829 goto exit_get_event_log;
830
831 event_log_size = mbox_sts[4];
832 if (event_log_size == 0)
833 goto exit_get_event_log;
834
835 /* Alloc Memory for Crash Record. */
836 event_log = dma_alloc_coherent(&ha->pdev->dev, event_log_size,
837 &event_log_dma, GFP_KERNEL);
838 if (event_log == NULL)
839 goto exit_get_event_log;
840
841 /* Get Crash Record. */
David C Somayajuluc0e344c2007-05-23 18:03:27 -0700842 memset(&mbox_cmd, 0, sizeof(mbox_cmd));
843 memset(&mbox_sts, 0, sizeof(mbox_cmd));
844
David Somayajuluafaf5a22006-09-19 10:28:00 -0700845 mbox_cmd[0] = MBOX_CMD_GET_CONN_EVENT_LOG;
846 mbox_cmd[2] = LSDW(event_log_dma);
847 mbox_cmd[3] = MSDW(event_log_dma);
David C Somayajuluc0e344c2007-05-23 18:03:27 -0700848
849 if (qla4xxx_mailbox_command(ha, MBOX_REG_COUNT, 5, &mbox_cmd[0], &mbox_sts[0]) !=
David Somayajuluafaf5a22006-09-19 10:28:00 -0700850 QLA_SUCCESS) {
851 DEBUG2(printk("scsi%ld: %s: ERROR: Unable to retrieve event "
852 "log!\n", ha->host_no, __func__));
853 goto exit_get_event_log;
854 }
855
856 /* Dump Event Log. */
857 num_valid_entries = mbox_sts[1];
858
859 max_event_log_entries = event_log_size /
860 sizeof(struct conn_event_log_entry);
861
862 if (num_valid_entries > max_event_log_entries)
863 oldest_entry = num_valid_entries % max_event_log_entries;
864
865 DEBUG3(printk("scsi%ld: Connection Event Log Dump (%d entries):\n",
866 ha->host_no, num_valid_entries));
867
Andrew Vasquez11010fe2006-10-06 09:54:59 -0700868 if (ql4xextended_error_logging == 3) {
David Somayajuluafaf5a22006-09-19 10:28:00 -0700869 if (oldest_entry == 0) {
870 /* Circular Buffer has not wrapped around */
871 for (i=0; i < num_valid_entries; i++) {
872 qla4xxx_dump_buffer((uint8_t *)event_log+
873 (i*sizeof(*event_log)),
874 sizeof(*event_log));
875 }
876 }
877 else {
878 /* Circular Buffer has wrapped around -
879 * display accordingly*/
880 for (i=oldest_entry; i < max_event_log_entries; i++) {
881 qla4xxx_dump_buffer((uint8_t *)event_log+
882 (i*sizeof(*event_log)),
883 sizeof(*event_log));
884 }
885 for (i=0; i < oldest_entry; i++) {
886 qla4xxx_dump_buffer((uint8_t *)event_log+
887 (i*sizeof(*event_log)),
888 sizeof(*event_log));
889 }
890 }
891 }
892
893exit_get_event_log:
894 if (event_log)
895 dma_free_coherent(&ha->pdev->dev, event_log_size, event_log,
896 event_log_dma);
897}
898
899/**
Vikas Chaudhary09a0f712010-04-28 11:42:24 +0530900 * qla4xxx_abort_task - issues Abort Task
901 * @ha: Pointer to host adapter structure.
902 * @srb: Pointer to srb entry
903 *
904 * This routine performs a LUN RESET on the specified target/lun.
905 * The caller must ensure that the ddb_entry and lun_entry pointers
906 * are valid before calling this routine.
907 **/
908int qla4xxx_abort_task(struct scsi_qla_host *ha, struct srb *srb)
909{
910 uint32_t mbox_cmd[MBOX_REG_COUNT];
911 uint32_t mbox_sts[MBOX_REG_COUNT];
912 struct scsi_cmnd *cmd = srb->cmd;
913 int status = QLA_SUCCESS;
914 unsigned long flags = 0;
915 uint32_t index;
916
917 /*
918 * Send abort task command to ISP, so that the ISP will return
919 * request with ABORT status
920 */
921 memset(&mbox_cmd, 0, sizeof(mbox_cmd));
922 memset(&mbox_sts, 0, sizeof(mbox_sts));
923
924 spin_lock_irqsave(&ha->hardware_lock, flags);
925 index = (unsigned long)(unsigned char *)cmd->host_scribble;
926 spin_unlock_irqrestore(&ha->hardware_lock, flags);
927
928 /* Firmware already posted completion on response queue */
929 if (index == MAX_SRBS)
930 return status;
931
932 mbox_cmd[0] = MBOX_CMD_ABORT_TASK;
Karen Higgins6790d4f2010-12-02 22:12:22 -0800933 mbox_cmd[1] = srb->ddb->fw_ddb_index;
Vikas Chaudhary09a0f712010-04-28 11:42:24 +0530934 mbox_cmd[2] = index;
935 /* Immediate Command Enable */
936 mbox_cmd[5] = 0x01;
937
938 qla4xxx_mailbox_command(ha, MBOX_REG_COUNT, 5, &mbox_cmd[0],
939 &mbox_sts[0]);
940 if (mbox_sts[0] != MBOX_STS_COMMAND_COMPLETE) {
941 status = QLA_ERROR;
942
943 DEBUG2(printk(KERN_WARNING "scsi%ld:%d:%d: abort task FAILED: "
944 "mbx0=%04X, mb1=%04X, mb2=%04X, mb3=%04X, mb4=%04X\n",
945 ha->host_no, cmd->device->id, cmd->device->lun, mbox_sts[0],
946 mbox_sts[1], mbox_sts[2], mbox_sts[3], mbox_sts[4]));
947 }
948
949 return status;
950}
951
952/**
David Somayajuluafaf5a22006-09-19 10:28:00 -0700953 * qla4xxx_reset_lun - issues LUN Reset
954 * @ha: Pointer to host adapter structure.
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +0530955 * @ddb_entry: Pointer to device database entry
956 * @lun: lun number
David Somayajuluafaf5a22006-09-19 10:28:00 -0700957 *
958 * This routine performs a LUN RESET on the specified target/lun.
959 * The caller must ensure that the ddb_entry and lun_entry pointers
960 * are valid before calling this routine.
961 **/
962int qla4xxx_reset_lun(struct scsi_qla_host * ha, struct ddb_entry * ddb_entry,
963 int lun)
964{
965 uint32_t mbox_cmd[MBOX_REG_COUNT];
966 uint32_t mbox_sts[MBOX_REG_COUNT];
967 int status = QLA_SUCCESS;
968
969 DEBUG2(printk("scsi%ld:%d:%d: lun reset issued\n", ha->host_no,
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +0530970 ddb_entry->fw_ddb_index, lun));
David Somayajuluafaf5a22006-09-19 10:28:00 -0700971
972 /*
973 * Send lun reset command to ISP, so that the ISP will return all
974 * outstanding requests with RESET status
975 */
976 memset(&mbox_cmd, 0, sizeof(mbox_cmd));
977 memset(&mbox_sts, 0, sizeof(mbox_sts));
David C Somayajuluc0e344c2007-05-23 18:03:27 -0700978
David Somayajuluafaf5a22006-09-19 10:28:00 -0700979 mbox_cmd[0] = MBOX_CMD_LUN_RESET;
980 mbox_cmd[1] = ddb_entry->fw_ddb_index;
981 mbox_cmd[2] = lun << 8;
982 mbox_cmd[5] = 0x01; /* Immediate Command Enable */
David C Somayajuluc0e344c2007-05-23 18:03:27 -0700983
984 qla4xxx_mailbox_command(ha, MBOX_REG_COUNT, 1, &mbox_cmd[0], &mbox_sts[0]);
David Somayajuluafaf5a22006-09-19 10:28:00 -0700985 if (mbox_sts[0] != MBOX_STS_COMMAND_COMPLETE &&
986 mbox_sts[0] != MBOX_STS_COMMAND_ERROR)
987 status = QLA_ERROR;
988
989 return status;
990}
991
Mike Christiece545032008-02-29 18:25:20 -0600992/**
993 * qla4xxx_reset_target - issues target Reset
994 * @ha: Pointer to host adapter structure.
995 * @db_entry: Pointer to device database entry
996 * @un_entry: Pointer to lun entry structure
997 *
998 * This routine performs a TARGET RESET on the specified target.
999 * The caller must ensure that the ddb_entry pointers
1000 * are valid before calling this routine.
1001 **/
1002int qla4xxx_reset_target(struct scsi_qla_host *ha,
1003 struct ddb_entry *ddb_entry)
1004{
1005 uint32_t mbox_cmd[MBOX_REG_COUNT];
1006 uint32_t mbox_sts[MBOX_REG_COUNT];
1007 int status = QLA_SUCCESS;
1008
1009 DEBUG2(printk("scsi%ld:%d: target reset issued\n", ha->host_no,
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05301010 ddb_entry->fw_ddb_index));
Mike Christiece545032008-02-29 18:25:20 -06001011
1012 /*
1013 * Send target reset command to ISP, so that the ISP will return all
1014 * outstanding requests with RESET status
1015 */
1016 memset(&mbox_cmd, 0, sizeof(mbox_cmd));
1017 memset(&mbox_sts, 0, sizeof(mbox_sts));
1018
1019 mbox_cmd[0] = MBOX_CMD_TARGET_WARM_RESET;
1020 mbox_cmd[1] = ddb_entry->fw_ddb_index;
1021 mbox_cmd[5] = 0x01; /* Immediate Command Enable */
1022
1023 qla4xxx_mailbox_command(ha, MBOX_REG_COUNT, 1, &mbox_cmd[0],
1024 &mbox_sts[0]);
1025 if (mbox_sts[0] != MBOX_STS_COMMAND_COMPLETE &&
1026 mbox_sts[0] != MBOX_STS_COMMAND_ERROR)
1027 status = QLA_ERROR;
1028
1029 return status;
1030}
David Somayajuluafaf5a22006-09-19 10:28:00 -07001031
1032int qla4xxx_get_flash(struct scsi_qla_host * ha, dma_addr_t dma_addr,
1033 uint32_t offset, uint32_t len)
1034{
1035 uint32_t mbox_cmd[MBOX_REG_COUNT];
1036 uint32_t mbox_sts[MBOX_REG_COUNT];
1037
1038 memset(&mbox_cmd, 0, sizeof(mbox_cmd));
1039 memset(&mbox_sts, 0, sizeof(mbox_sts));
David C Somayajuluc0e344c2007-05-23 18:03:27 -07001040
David Somayajuluafaf5a22006-09-19 10:28:00 -07001041 mbox_cmd[0] = MBOX_CMD_READ_FLASH;
1042 mbox_cmd[1] = LSDW(dma_addr);
1043 mbox_cmd[2] = MSDW(dma_addr);
1044 mbox_cmd[3] = offset;
1045 mbox_cmd[4] = len;
David C Somayajuluc0e344c2007-05-23 18:03:27 -07001046
1047 if (qla4xxx_mailbox_command(ha, MBOX_REG_COUNT, 2, &mbox_cmd[0], &mbox_sts[0]) !=
David Somayajuluafaf5a22006-09-19 10:28:00 -07001048 QLA_SUCCESS) {
1049 DEBUG2(printk("scsi%ld: %s: MBOX_CMD_READ_FLASH, failed w/ "
1050 "status %04X %04X, offset %08x, len %08x\n", ha->host_no,
1051 __func__, mbox_sts[0], mbox_sts[1], offset, len));
1052 return QLA_ERROR;
1053 }
1054 return QLA_SUCCESS;
1055}
1056
1057/**
1058 * qla4xxx_get_fw_version - gets firmware version
1059 * @ha: Pointer to host adapter structure.
1060 *
1061 * Retrieves the firmware version on HBA. In QLA4010, mailboxes 2 & 3 may
1062 * hold an address for data. Make sure that we write 0 to those mailboxes,
1063 * if unused.
1064 **/
1065int qla4xxx_get_fw_version(struct scsi_qla_host * ha)
1066{
1067 uint32_t mbox_cmd[MBOX_REG_COUNT];
1068 uint32_t mbox_sts[MBOX_REG_COUNT];
1069
1070 /* Get firmware version. */
1071 memset(&mbox_cmd, 0, sizeof(mbox_cmd));
1072 memset(&mbox_sts, 0, sizeof(mbox_sts));
David C Somayajuluc0e344c2007-05-23 18:03:27 -07001073
David Somayajuluafaf5a22006-09-19 10:28:00 -07001074 mbox_cmd[0] = MBOX_CMD_ABOUT_FW;
David C Somayajuluc0e344c2007-05-23 18:03:27 -07001075
1076 if (qla4xxx_mailbox_command(ha, MBOX_REG_COUNT, 5, &mbox_cmd[0], &mbox_sts[0]) !=
David Somayajuluafaf5a22006-09-19 10:28:00 -07001077 QLA_SUCCESS) {
1078 DEBUG2(printk("scsi%ld: %s: MBOX_CMD_ABOUT_FW failed w/ "
1079 "status %04X\n", ha->host_no, __func__, mbox_sts[0]));
1080 return QLA_ERROR;
1081 }
1082
1083 /* Save firmware version information. */
1084 ha->firmware_version[0] = mbox_sts[1];
1085 ha->firmware_version[1] = mbox_sts[2];
1086 ha->patch_number = mbox_sts[3];
1087 ha->build_number = mbox_sts[4];
1088
1089 return QLA_SUCCESS;
1090}
1091
Adrian Bunk47975472007-04-26 00:35:16 -07001092static int qla4xxx_get_default_ddb(struct scsi_qla_host *ha,
1093 dma_addr_t dma_addr)
David Somayajuluafaf5a22006-09-19 10:28:00 -07001094{
1095 uint32_t mbox_cmd[MBOX_REG_COUNT];
1096 uint32_t mbox_sts[MBOX_REG_COUNT];
1097
1098 memset(&mbox_cmd, 0, sizeof(mbox_cmd));
1099 memset(&mbox_sts, 0, sizeof(mbox_sts));
1100
1101 mbox_cmd[0] = MBOX_CMD_GET_DATABASE_ENTRY_DEFAULTS;
1102 mbox_cmd[2] = LSDW(dma_addr);
1103 mbox_cmd[3] = MSDW(dma_addr);
1104
David C Somayajuluc0e344c2007-05-23 18:03:27 -07001105 if (qla4xxx_mailbox_command(ha, MBOX_REG_COUNT, 1, &mbox_cmd[0], &mbox_sts[0]) !=
David Somayajuluafaf5a22006-09-19 10:28:00 -07001106 QLA_SUCCESS) {
1107 DEBUG2(printk("scsi%ld: %s: failed status %04X\n",
1108 ha->host_no, __func__, mbox_sts[0]));
1109 return QLA_ERROR;
1110 }
1111 return QLA_SUCCESS;
1112}
1113
Adrian Bunk47975472007-04-26 00:35:16 -07001114static int qla4xxx_req_ddb_entry(struct scsi_qla_host *ha, uint32_t *ddb_index)
David Somayajuluafaf5a22006-09-19 10:28:00 -07001115{
1116 uint32_t mbox_cmd[MBOX_REG_COUNT];
1117 uint32_t mbox_sts[MBOX_REG_COUNT];
1118
1119 memset(&mbox_cmd, 0, sizeof(mbox_cmd));
1120 memset(&mbox_sts, 0, sizeof(mbox_sts));
1121
1122 mbox_cmd[0] = MBOX_CMD_REQUEST_DATABASE_ENTRY;
1123 mbox_cmd[1] = MAX_PRST_DEV_DB_ENTRIES;
1124
David C Somayajuluc0e344c2007-05-23 18:03:27 -07001125 if (qla4xxx_mailbox_command(ha, MBOX_REG_COUNT, 3, &mbox_cmd[0], &mbox_sts[0]) !=
David Somayajuluafaf5a22006-09-19 10:28:00 -07001126 QLA_SUCCESS) {
1127 if (mbox_sts[0] == MBOX_STS_COMMAND_ERROR) {
1128 *ddb_index = mbox_sts[2];
1129 } else {
1130 DEBUG2(printk("scsi%ld: %s: failed status %04X\n",
1131 ha->host_no, __func__, mbox_sts[0]));
1132 return QLA_ERROR;
1133 }
1134 } else {
1135 *ddb_index = MAX_PRST_DEV_DB_ENTRIES;
1136 }
1137
1138 return QLA_SUCCESS;
1139}
1140
1141
1142int qla4xxx_send_tgts(struct scsi_qla_host *ha, char *ip, uint16_t port)
1143{
1144 struct dev_db_entry *fw_ddb_entry;
1145 dma_addr_t fw_ddb_entry_dma;
1146 uint32_t ddb_index;
1147 int ret_val = QLA_SUCCESS;
1148
1149
1150 fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev,
1151 sizeof(*fw_ddb_entry),
1152 &fw_ddb_entry_dma, GFP_KERNEL);
1153 if (!fw_ddb_entry) {
1154 DEBUG2(printk("scsi%ld: %s: Unable to allocate dma buffer.\n",
1155 ha->host_no, __func__));
1156 ret_val = QLA_ERROR;
Prasanna Mumbaibeabe7c2010-07-10 14:49:38 +05301157 goto exit_send_tgts_no_free;
David Somayajuluafaf5a22006-09-19 10:28:00 -07001158 }
1159
1160 ret_val = qla4xxx_get_default_ddb(ha, fw_ddb_entry_dma);
1161 if (ret_val != QLA_SUCCESS)
Prasanna Mumbaibeabe7c2010-07-10 14:49:38 +05301162 goto exit_send_tgts;
David Somayajuluafaf5a22006-09-19 10:28:00 -07001163
1164 ret_val = qla4xxx_req_ddb_entry(ha, &ddb_index);
1165 if (ret_val != QLA_SUCCESS)
Prasanna Mumbaibeabe7c2010-07-10 14:49:38 +05301166 goto exit_send_tgts;
David Somayajuluafaf5a22006-09-19 10:28:00 -07001167
David C Somayajuluc0e344c2007-05-23 18:03:27 -07001168 memset(fw_ddb_entry->iscsi_alias, 0,
1169 sizeof(fw_ddb_entry->iscsi_alias));
David Somayajuluafaf5a22006-09-19 10:28:00 -07001170
David C Somayajuluc0e344c2007-05-23 18:03:27 -07001171 memset(fw_ddb_entry->iscsi_name, 0,
1172 sizeof(fw_ddb_entry->iscsi_name));
David Somayajuluafaf5a22006-09-19 10:28:00 -07001173
David C Somayajuluc0e344c2007-05-23 18:03:27 -07001174 memset(fw_ddb_entry->ip_addr, 0, sizeof(fw_ddb_entry->ip_addr));
1175 memset(fw_ddb_entry->tgt_addr, 0,
1176 sizeof(fw_ddb_entry->tgt_addr));
David Somayajuluafaf5a22006-09-19 10:28:00 -07001177
1178 fw_ddb_entry->options = (DDB_OPT_DISC_SESSION | DDB_OPT_TARGET);
David C Somayajuluc0e344c2007-05-23 18:03:27 -07001179 fw_ddb_entry->port = cpu_to_le16(ntohs(port));
David Somayajuluafaf5a22006-09-19 10:28:00 -07001180
David C Somayajuluc0e344c2007-05-23 18:03:27 -07001181 fw_ddb_entry->ip_addr[0] = *ip;
1182 fw_ddb_entry->ip_addr[1] = *(ip + 1);
1183 fw_ddb_entry->ip_addr[2] = *(ip + 2);
1184 fw_ddb_entry->ip_addr[3] = *(ip + 3);
David Somayajuluafaf5a22006-09-19 10:28:00 -07001185
1186 ret_val = qla4xxx_set_ddb_entry(ha, ddb_index, fw_ddb_entry_dma);
1187
Prasanna Mumbaibeabe7c2010-07-10 14:49:38 +05301188exit_send_tgts:
David Somayajuluafaf5a22006-09-19 10:28:00 -07001189 dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
1190 fw_ddb_entry, fw_ddb_entry_dma);
Prasanna Mumbaibeabe7c2010-07-10 14:49:38 +05301191exit_send_tgts_no_free:
David Somayajuluafaf5a22006-09-19 10:28:00 -07001192 return ret_val;
1193}
1194