blob: 28eab07935ba3101c17f061c79468ccba94aef63 [file] [log] [blame]
Thomas Gleixnere3976af2020-09-08 14:34:47 +02001// SPDX-License-Identifier: GPL-2.0-only
David Somayajuluafaf5a22006-09-19 10:28:00 -07002/*
3 * QLogic iSCSI HBA Driver
Vikas Chaudhary4a4f51e2013-08-16 07:03:04 -04004 * Copyright (c) 2003-2013 QLogic Corporation
David Somayajuluafaf5a22006-09-19 10:28:00 -07005 */
6
7#include "ql4_def.h"
David C Somayajulue08c1822007-05-23 18:14:34 -07008#include "ql4_glbl.h"
9#include "ql4_dbg.h"
10#include "ql4_inline.h"
11
David Somayajuluafaf5a22006-09-19 10:28:00 -070012#include <scsi/scsi_tcq.h>
13
Karen Higgins16ed55f2009-07-15 15:03:02 -050014static int
15qla4xxx_space_in_req_ring(struct scsi_qla_host *ha, uint16_t req_cnt)
16{
17 uint16_t cnt;
18
19 /* Calculate number of free request entries. */
20 if ((req_cnt + 2) >= ha->req_q_count) {
Vikas Chaudharyb173a1322010-07-30 14:26:08 +053021 cnt = (uint16_t) ha->isp_ops->rd_shdw_req_q_out(ha);
Karen Higgins16ed55f2009-07-15 15:03:02 -050022 if (ha->request_in < cnt)
23 ha->req_q_count = cnt - ha->request_in;
24 else
25 ha->req_q_count = REQUEST_QUEUE_DEPTH -
26 (ha->request_in - cnt);
27 }
28
29 /* Check if room for request in request ring. */
30 if ((req_cnt + 2) < ha->req_q_count)
31 return 1;
32 else
33 return 0;
34}
35
36static void qla4xxx_advance_req_ring_ptr(struct scsi_qla_host *ha)
37{
38 /* Advance request queue pointer */
39 if (ha->request_in == (REQUEST_QUEUE_DEPTH - 1)) {
40 ha->request_in = 0;
41 ha->request_ptr = ha->request_ring;
42 } else {
43 ha->request_in++;
44 ha->request_ptr++;
45 }
46}
47
David Somayajuluafaf5a22006-09-19 10:28:00 -070048/**
49 * qla4xxx_get_req_pkt - returns a valid entry in request queue.
50 * @ha: Pointer to host adapter structure.
51 * @queue_entry: Pointer to pointer to queue entry structure
52 *
53 * This routine performs the following tasks:
54 * - returns the current request_in pointer (if queue not full)
55 * - advances the request_in pointer
56 * - checks for queue full
57 **/
Adrian Bunk47975472007-04-26 00:35:16 -070058static int qla4xxx_get_req_pkt(struct scsi_qla_host *ha,
59 struct queue_entry **queue_entry)
David Somayajuluafaf5a22006-09-19 10:28:00 -070060{
Karen Higgins16ed55f2009-07-15 15:03:02 -050061 uint16_t req_cnt = 1;
David Somayajuluafaf5a22006-09-19 10:28:00 -070062
Karen Higgins16ed55f2009-07-15 15:03:02 -050063 if (qla4xxx_space_in_req_ring(ha, req_cnt)) {
64 *queue_entry = ha->request_ptr;
David Somayajuluafaf5a22006-09-19 10:28:00 -070065 memset(*queue_entry, 0, sizeof(**queue_entry));
Karen Higgins16ed55f2009-07-15 15:03:02 -050066
67 qla4xxx_advance_req_ring_ptr(ha);
68 ha->req_q_count -= req_cnt;
69 return QLA_SUCCESS;
David Somayajuluafaf5a22006-09-19 10:28:00 -070070 }
71
Karen Higgins16ed55f2009-07-15 15:03:02 -050072 return QLA_ERROR;
David Somayajuluafaf5a22006-09-19 10:28:00 -070073}
74
75/**
76 * qla4xxx_send_marker_iocb - issues marker iocb to HBA
77 * @ha: Pointer to host adapter structure.
78 * @ddb_entry: Pointer to device database entry
79 * @lun: SCSI LUN
Lee Jones67b8b932020-07-21 17:41:30 +010080 * @mrkr_mod: marker identifier
David Somayajuluafaf5a22006-09-19 10:28:00 -070081 *
82 * This routine issues a marker IOCB.
83 **/
David C Somayajulu9d562912008-03-19 11:23:03 -070084int qla4xxx_send_marker_iocb(struct scsi_qla_host *ha,
Hannes Reinecke9cb78c12014-06-25 15:27:36 +020085 struct ddb_entry *ddb_entry, uint64_t lun, uint16_t mrkr_mod)
David Somayajuluafaf5a22006-09-19 10:28:00 -070086{
Mathieu Desnoyers1c3f0b82007-10-18 23:41:04 -070087 struct qla4_marker_entry *marker_entry;
David Somayajuluafaf5a22006-09-19 10:28:00 -070088 unsigned long flags = 0;
89 uint8_t status = QLA_SUCCESS;
90
91 /* Acquire hardware specific lock */
92 spin_lock_irqsave(&ha->hardware_lock, flags);
93
94 /* Get pointer to the queue entry for the marker */
95 if (qla4xxx_get_req_pkt(ha, (struct queue_entry **) &marker_entry) !=
96 QLA_SUCCESS) {
97 status = QLA_ERROR;
98 goto exit_send_marker;
99 }
100
101 /* Put the marker in the request queue */
102 marker_entry->hdr.entryType = ET_MARKER;
103 marker_entry->hdr.entryCount = 1;
104 marker_entry->target = cpu_to_le16(ddb_entry->fw_ddb_index);
David C Somayajulu9d562912008-03-19 11:23:03 -0700105 marker_entry->modifier = cpu_to_le16(mrkr_mod);
David Somayajuluafaf5a22006-09-19 10:28:00 -0700106 int_to_scsilun(lun, &marker_entry->lun);
107 wmb();
108
109 /* Tell ISP it's got a new I/O request */
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +0530110 ha->isp_ops->queue_iocb(ha);
David Somayajuluafaf5a22006-09-19 10:28:00 -0700111
112exit_send_marker:
113 spin_unlock_irqrestore(&ha->hardware_lock, flags);
114 return status;
115}
116
Karen Higgins16ed55f2009-07-15 15:03:02 -0500117static struct continuation_t1_entry *
118qla4xxx_alloc_cont_entry(struct scsi_qla_host *ha)
David Somayajuluafaf5a22006-09-19 10:28:00 -0700119{
120 struct continuation_t1_entry *cont_entry;
121
122 cont_entry = (struct continuation_t1_entry *)ha->request_ptr;
123
Karen Higgins16ed55f2009-07-15 15:03:02 -0500124 qla4xxx_advance_req_ring_ptr(ha);
David Somayajuluafaf5a22006-09-19 10:28:00 -0700125
126 /* Load packet defaults */
127 cont_entry->hdr.entryType = ET_CONTINUE;
128 cont_entry->hdr.entryCount = 1;
129 cont_entry->hdr.systemDefined = (uint8_t) cpu_to_le16(ha->request_in);
130
131 return cont_entry;
132}
133
Adrian Bunk47975472007-04-26 00:35:16 -0700134static uint16_t qla4xxx_calc_request_entries(uint16_t dsds)
David Somayajuluafaf5a22006-09-19 10:28:00 -0700135{
136 uint16_t iocbs;
137
138 iocbs = 1;
139 if (dsds > COMMAND_SEG) {
140 iocbs += (dsds - COMMAND_SEG) / CONTINUE_SEG;
141 if ((dsds - COMMAND_SEG) % CONTINUE_SEG)
142 iocbs++;
143 }
144 return iocbs;
145}
146
Adrian Bunk47975472007-04-26 00:35:16 -0700147static void qla4xxx_build_scsi_iocbs(struct srb *srb,
148 struct command_t3_entry *cmd_entry,
149 uint16_t tot_dsds)
David Somayajuluafaf5a22006-09-19 10:28:00 -0700150{
151 struct scsi_qla_host *ha;
152 uint16_t avail_dsds;
153 struct data_seg_a64 *cur_dsd;
154 struct scsi_cmnd *cmd;
FUJITA Tomonori5f7186c2007-05-26 14:08:20 +0900155 struct scatterlist *sg;
156 int i;
David Somayajuluafaf5a22006-09-19 10:28:00 -0700157
158 cmd = srb->cmd;
159 ha = srb->ha;
160
FUJITA Tomonori5f7186c2007-05-26 14:08:20 +0900161 if (!scsi_bufflen(cmd) || cmd->sc_data_direction == DMA_NONE) {
David Somayajuluafaf5a22006-09-19 10:28:00 -0700162 /* No data being transferred */
Dwaipayan Ray33529012021-07-16 16:58:52 +0530163 cmd_entry->ttlByteCnt = cpu_to_le32(0);
David Somayajuluafaf5a22006-09-19 10:28:00 -0700164 return;
165 }
166
167 avail_dsds = COMMAND_SEG;
168 cur_dsd = (struct data_seg_a64 *) & (cmd_entry->dataseg[0]);
169
FUJITA Tomonori5f7186c2007-05-26 14:08:20 +0900170 scsi_for_each_sg(cmd, sg, tot_dsds, i) {
171 dma_addr_t sle_dma;
David Somayajuluafaf5a22006-09-19 10:28:00 -0700172
FUJITA Tomonori5f7186c2007-05-26 14:08:20 +0900173 /* Allocate additional continuation packets? */
174 if (avail_dsds == 0) {
175 struct continuation_t1_entry *cont_entry;
David Somayajuluafaf5a22006-09-19 10:28:00 -0700176
FUJITA Tomonori5f7186c2007-05-26 14:08:20 +0900177 cont_entry = qla4xxx_alloc_cont_entry(ha);
178 cur_dsd =
179 (struct data_seg_a64 *)
180 &cont_entry->dataseg[0];
181 avail_dsds = CONTINUE_SEG;
David Somayajuluafaf5a22006-09-19 10:28:00 -0700182 }
FUJITA Tomonori5f7186c2007-05-26 14:08:20 +0900183
184 sle_dma = sg_dma_address(sg);
185 cur_dsd->base.addrLow = cpu_to_le32(LSDW(sle_dma));
186 cur_dsd->base.addrHigh = cpu_to_le32(MSDW(sle_dma));
187 cur_dsd->count = cpu_to_le32(sg_dma_len(sg));
188 avail_dsds--;
189
190 cur_dsd++;
David Somayajuluafaf5a22006-09-19 10:28:00 -0700191 }
192}
193
Vikas Chaudhary6e7b4292012-08-22 07:55:08 -0400194void qla4_83xx_queue_iocb(struct scsi_qla_host *ha)
195{
196 writel(ha->request_in, &ha->qla4_83xx_reg->req_q_in);
197 readl(&ha->qla4_83xx_reg->req_q_in);
198}
199
200void qla4_83xx_complete_iocb(struct scsi_qla_host *ha)
201{
202 writel(ha->response_out, &ha->qla4_83xx_reg->rsp_q_out);
203 readl(&ha->qla4_83xx_reg->rsp_q_out);
204}
205
David Somayajuluafaf5a22006-09-19 10:28:00 -0700206/**
Vikas Chaudharyf8086f42012-08-22 07:54:59 -0400207 * qla4_82xx_queue_iocb - Tell ISP it's got new request(s)
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +0530208 * @ha: pointer to host adapter structure.
209 *
210 * This routine notifies the ISP that one or more new request
211 * queue entries have been placed on the request queue.
212 **/
Vikas Chaudharyf8086f42012-08-22 07:54:59 -0400213void qla4_82xx_queue_iocb(struct scsi_qla_host *ha)
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +0530214{
215 uint32_t dbval = 0;
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +0530216
217 dbval = 0x14 | (ha->func_num << 5);
218 dbval = dbval | (0 << 8) | (ha->request_in << 16);
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +0530219
Vikas Chaudharyf8086f42012-08-22 07:54:59 -0400220 qla4_82xx_wr_32(ha, ha->nx_db_wr_ptr, ha->request_in);
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +0530221}
222
223/**
Vikas Chaudharyf8086f42012-08-22 07:54:59 -0400224 * qla4_82xx_complete_iocb - Tell ISP we're done with response(s)
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +0530225 * @ha: pointer to host adapter structure.
226 *
227 * This routine notifies the ISP that one or more response/completion
228 * queue entries have been processed by the driver.
229 * This also clears the interrupt.
230 **/
Vikas Chaudharyf8086f42012-08-22 07:54:59 -0400231void qla4_82xx_complete_iocb(struct scsi_qla_host *ha)
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +0530232{
Vikas Chaudhary7664a1f2012-08-22 07:55:00 -0400233 writel(ha->response_out, &ha->qla4_82xx_reg->rsp_q_out);
234 readl(&ha->qla4_82xx_reg->rsp_q_out);
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +0530235}
236
237/**
238 * qla4xxx_queue_iocb - Tell ISP it's got new request(s)
239 * @ha: pointer to host adapter structure.
240 *
241 * This routine is notifies the ISP that one or more new request
242 * queue entries have been placed on the request queue.
243 **/
244void qla4xxx_queue_iocb(struct scsi_qla_host *ha)
245{
246 writel(ha->request_in, &ha->reg->req_q_in);
247 readl(&ha->reg->req_q_in);
248}
249
250/**
251 * qla4xxx_complete_iocb - Tell ISP we're done with response(s)
252 * @ha: pointer to host adapter structure.
253 *
254 * This routine is notifies the ISP that one or more response/completion
255 * queue entries have been processed by the driver.
256 * This also clears the interrupt.
257 **/
258void qla4xxx_complete_iocb(struct scsi_qla_host *ha)
259{
260 writel(ha->response_out, &ha->reg->rsp_q_out);
261 readl(&ha->reg->rsp_q_out);
262}
263
264/**
David Somayajuluafaf5a22006-09-19 10:28:00 -0700265 * qla4xxx_send_command_to_isp - issues command to HBA
266 * @ha: pointer to host adapter structure.
267 * @srb: pointer to SCSI Request Block to be sent to ISP
268 *
269 * This routine is called by qla4xxx_queuecommand to build an ISP
270 * command and pass it to the ISP for execution.
271 **/
272int qla4xxx_send_command_to_isp(struct scsi_qla_host *ha, struct srb * srb)
273{
274 struct scsi_cmnd *cmd = srb->cmd;
275 struct ddb_entry *ddb_entry;
276 struct command_t3_entry *cmd_entry;
FUJITA Tomonori5f7186c2007-05-26 14:08:20 +0900277 int nseg;
David Somayajuluafaf5a22006-09-19 10:28:00 -0700278 uint16_t tot_dsds;
279 uint16_t req_cnt;
David Somayajuluafaf5a22006-09-19 10:28:00 -0700280 unsigned long flags;
David Somayajuluafaf5a22006-09-19 10:28:00 -0700281 uint32_t index;
David Somayajuluafaf5a22006-09-19 10:28:00 -0700282
283 /* Get real lun and adapter */
284 ddb_entry = srb->ddb;
285
David Somayajuluafaf5a22006-09-19 10:28:00 -0700286 tot_dsds = 0;
287
288 /* Acquire hardware specific lock */
289 spin_lock_irqsave(&ha->hardware_lock, flags);
290
Bart Van Assche924b3d72021-08-09 16:03:42 -0700291 index = scsi_cmd_to_rq(cmd)->tag;
David Somayajuluafaf5a22006-09-19 10:28:00 -0700292
Karen Higgins16ed55f2009-07-15 15:03:02 -0500293 /*
294 * Check to see if adapter is online before placing request on
295 * request queue. If a reset occurs and a request is in the queue,
296 * the firmware will still attempt to process the request, retrieving
297 * garbage for pointers.
298 */
299 if (!test_bit(AF_ONLINE, &ha->flags)) {
300 DEBUG2(printk("scsi%ld: %s: Adapter OFFLINE! "
301 "Do not issue command.\n",
302 ha->host_no, __func__));
303 goto queuing_error;
304 }
305
David Somayajuluafaf5a22006-09-19 10:28:00 -0700306 /* Calculate the number of request entries needed. */
FUJITA Tomonori5f7186c2007-05-26 14:08:20 +0900307 nseg = scsi_dma_map(cmd);
308 if (nseg < 0)
309 goto queuing_error;
310 tot_dsds = nseg;
David Somayajuluafaf5a22006-09-19 10:28:00 -0700311
David Somayajuluafaf5a22006-09-19 10:28:00 -0700312 req_cnt = qla4xxx_calc_request_entries(tot_dsds);
Karen Higgins16ed55f2009-07-15 15:03:02 -0500313 if (!qla4xxx_space_in_req_ring(ha, req_cnt))
David Somayajuluafaf5a22006-09-19 10:28:00 -0700314 goto queuing_error;
315
316 /* total iocbs active */
Karen Higgins5b1c1bf2013-01-20 23:51:00 -0500317 if ((ha->iocb_cnt + req_cnt) >= ha->iocb_hiwat)
David Somayajuluafaf5a22006-09-19 10:28:00 -0700318 goto queuing_error;
319
320 /* Build command packet */
321 cmd_entry = (struct command_t3_entry *) ha->request_ptr;
322 memset(cmd_entry, 0, sizeof(struct command_t3_entry));
323 cmd_entry->hdr.entryType = ET_COMMAND;
324 cmd_entry->handle = cpu_to_le32(index);
325 cmd_entry->target = cpu_to_le16(ddb_entry->fw_ddb_index);
David Somayajuluafaf5a22006-09-19 10:28:00 -0700326
327 int_to_scsilun(cmd->device->lun, &cmd_entry->lun);
FUJITA Tomonori5f7186c2007-05-26 14:08:20 +0900328 cmd_entry->ttlByteCnt = cpu_to_le32(scsi_bufflen(cmd));
David Somayajuluafaf5a22006-09-19 10:28:00 -0700329 memcpy(cmd_entry->cdb, cmd->cmnd, cmd->cmd_len);
330 cmd_entry->dataSegCnt = cpu_to_le16(tot_dsds);
331 cmd_entry->hdr.entryCount = req_cnt;
332
333 /* Set data transfer direction control flags
334 * NOTE: Look at data_direction bits iff there is data to be
335 * transferred, as the data direction bit is sometimed filled
336 * in when there is no data to be transferred */
337 cmd_entry->control_flags = CF_NO_DATA;
FUJITA Tomonori5f7186c2007-05-26 14:08:20 +0900338 if (scsi_bufflen(cmd)) {
David Somayajuluafaf5a22006-09-19 10:28:00 -0700339 if (cmd->sc_data_direction == DMA_TO_DEVICE)
340 cmd_entry->control_flags = CF_WRITE;
341 else if (cmd->sc_data_direction == DMA_FROM_DEVICE)
342 cmd_entry->control_flags = CF_READ;
David C Somayajulud9150582006-11-15 17:38:40 -0800343
FUJITA Tomonori5f7186c2007-05-26 14:08:20 +0900344 ha->bytes_xfered += scsi_bufflen(cmd);
David C Somayajulud9150582006-11-15 17:38:40 -0800345 if (ha->bytes_xfered & ~0xFFFFF){
346 ha->total_mbytes_xferred += ha->bytes_xfered >> 20;
347 ha->bytes_xfered &= 0xFFFFF;
348 }
David Somayajuluafaf5a22006-09-19 10:28:00 -0700349 }
350
351 /* Set tagged queueing control flags */
352 cmd_entry->control_flags |= CF_SIMPLE_TAG;
David Somayajuluafaf5a22006-09-19 10:28:00 -0700353
Karen Higgins16ed55f2009-07-15 15:03:02 -0500354 qla4xxx_advance_req_ring_ptr(ha);
David Somayajuluafaf5a22006-09-19 10:28:00 -0700355 qla4xxx_build_scsi_iocbs(srb, cmd_entry, tot_dsds);
356 wmb();
357
Vikas Chaudhary53698872010-04-28 11:41:59 +0530358 srb->cmd->host_scribble = (unsigned char *)(unsigned long)index;
David Somayajuluafaf5a22006-09-19 10:28:00 -0700359
360 /* update counters */
361 srb->state = SRB_ACTIVE_STATE;
362 srb->flags |= SRB_DMA_VALID;
363
364 /* Track IOCB used */
365 ha->iocb_cnt += req_cnt;
366 srb->iocb_cnt = req_cnt;
367 ha->req_q_count -= req_cnt;
368
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +0530369 ha->isp_ops->queue_iocb(ha);
David Somayajuluafaf5a22006-09-19 10:28:00 -0700370 spin_unlock_irqrestore(&ha->hardware_lock, flags);
371
372 return QLA_SUCCESS;
373
374queuing_error:
FUJITA Tomonori5f7186c2007-05-26 14:08:20 +0900375 if (tot_dsds)
376 scsi_dma_unmap(cmd);
David Somayajuluafaf5a22006-09-19 10:28:00 -0700377
David Somayajuluafaf5a22006-09-19 10:28:00 -0700378 spin_unlock_irqrestore(&ha->hardware_lock, flags);
379
380 return QLA_ERROR;
381}
382
Manish Rangankarb3a271a2011-07-25 13:48:53 -0500383int qla4xxx_send_passthru0(struct iscsi_task *task)
384{
385 struct passthru0 *passthru_iocb;
386 struct iscsi_session *sess = task->conn->session;
387 struct ddb_entry *ddb_entry = sess->dd_data;
388 struct scsi_qla_host *ha = ddb_entry->ha;
389 struct ql4_task_data *task_data = task->dd_data;
390 uint16_t ctrl_flags = 0;
391 unsigned long flags;
392 int ret = QLA_ERROR;
393
394 spin_lock_irqsave(&ha->hardware_lock, flags);
395 task_data->iocb_req_cnt = 1;
396 /* Put the IOCB on the request queue */
397 if (!qla4xxx_space_in_req_ring(ha, task_data->iocb_req_cnt))
398 goto queuing_error;
399
400 passthru_iocb = (struct passthru0 *) ha->request_ptr;
401
402 memset(passthru_iocb, 0, sizeof(struct passthru0));
403 passthru_iocb->hdr.entryType = ET_PASSTHRU0;
404 passthru_iocb->hdr.systemDefined = SD_ISCSI_PDU;
405 passthru_iocb->hdr.entryCount = task_data->iocb_req_cnt;
406 passthru_iocb->handle = task->itt;
407 passthru_iocb->target = cpu_to_le16(ddb_entry->fw_ddb_index);
408 passthru_iocb->timeout = cpu_to_le16(PT_DEFAULT_TIMEOUT);
409
410 /* Setup the out & in DSDs */
Manish Rangankar69ca2162011-10-07 16:55:50 -0700411 if (task_data->req_len) {
Manish Rangankarb3a271a2011-07-25 13:48:53 -0500412 memcpy((uint8_t *)task_data->req_buffer +
413 sizeof(struct iscsi_hdr), task->data, task->data_count);
414 ctrl_flags |= PT_FLAG_SEND_BUFFER;
415 passthru_iocb->out_dsd.base.addrLow =
416 cpu_to_le32(LSDW(task_data->req_dma));
417 passthru_iocb->out_dsd.base.addrHigh =
418 cpu_to_le32(MSDW(task_data->req_dma));
419 passthru_iocb->out_dsd.count =
420 cpu_to_le32(task->data_count +
421 sizeof(struct iscsi_hdr));
422 }
423 if (task_data->resp_len) {
424 passthru_iocb->in_dsd.base.addrLow =
425 cpu_to_le32(LSDW(task_data->resp_dma));
426 passthru_iocb->in_dsd.base.addrHigh =
427 cpu_to_le32(MSDW(task_data->resp_dma));
428 passthru_iocb->in_dsd.count =
429 cpu_to_le32(task_data->resp_len);
430 }
431
432 ctrl_flags |= (PT_FLAG_ISCSI_PDU | PT_FLAG_WAIT_4_RESPONSE);
433 passthru_iocb->control_flags = cpu_to_le16(ctrl_flags);
434
435 /* Update the request pointer */
436 qla4xxx_advance_req_ring_ptr(ha);
437 wmb();
438
439 /* Track IOCB used */
440 ha->iocb_cnt += task_data->iocb_req_cnt;
441 ha->req_q_count -= task_data->iocb_req_cnt;
442 ha->isp_ops->queue_iocb(ha);
443 ret = QLA_SUCCESS;
444
445queuing_error:
446 spin_unlock_irqrestore(&ha->hardware_lock, flags);
447 return ret;
448}
Vikas Chaudharyc0b9d3f2012-02-13 18:30:49 +0530449
450static struct mrb *qla4xxx_get_new_mrb(struct scsi_qla_host *ha)
451{
452 struct mrb *mrb;
453
454 mrb = kzalloc(sizeof(*mrb), GFP_KERNEL);
455 if (!mrb)
456 return mrb;
457
458 mrb->ha = ha;
459 return mrb;
460}
461
Vikas Chaudharya7380a62012-02-27 03:08:56 -0800462static int qla4xxx_send_mbox_iocb(struct scsi_qla_host *ha, struct mrb *mrb,
463 uint32_t *in_mbox)
Vikas Chaudharyc0b9d3f2012-02-13 18:30:49 +0530464{
465 int rval = QLA_SUCCESS;
466 uint32_t i;
467 unsigned long flags;
468 uint32_t index = 0;
469
470 /* Acquire hardware specific lock */
471 spin_lock_irqsave(&ha->hardware_lock, flags);
472
473 /* Get pointer to the queue entry for the marker */
474 rval = qla4xxx_get_req_pkt(ha, (struct queue_entry **) &(mrb->mbox));
475 if (rval != QLA_SUCCESS)
476 goto exit_mbox_iocb;
477
478 index = ha->mrb_index;
479 /* get valid mrb index*/
480 for (i = 0; i < MAX_MRB; i++) {
481 index++;
482 if (index == MAX_MRB)
483 index = 1;
484 if (ha->active_mrb_array[index] == NULL) {
485 ha->mrb_index = index;
486 break;
487 }
488 }
489
490 mrb->iocb_cnt = 1;
491 ha->active_mrb_array[index] = mrb;
492 mrb->mbox->handle = index;
493 mrb->mbox->hdr.entryType = ET_MBOX_CMD;
494 mrb->mbox->hdr.entryCount = mrb->iocb_cnt;
495 memcpy(mrb->mbox->in_mbox, in_mbox, 32);
496 mrb->mbox_cmd = in_mbox[0];
497 wmb();
498
Vikas Chaudharyd5228442013-05-02 03:42:10 -0400499 ha->iocb_cnt += mrb->iocb_cnt;
Vikas Chaudharyc0b9d3f2012-02-13 18:30:49 +0530500 ha->isp_ops->queue_iocb(ha);
501exit_mbox_iocb:
502 spin_unlock_irqrestore(&ha->hardware_lock, flags);
503 return rval;
504}
505
506int qla4xxx_ping_iocb(struct scsi_qla_host *ha, uint32_t options,
507 uint32_t payload_size, uint32_t pid, uint8_t *ipaddr)
508{
509 uint32_t in_mbox[8];
510 struct mrb *mrb = NULL;
511 int rval = QLA_SUCCESS;
512
513 memset(in_mbox, 0, sizeof(in_mbox));
514
515 mrb = qla4xxx_get_new_mrb(ha);
516 if (!mrb) {
517 DEBUG2(ql4_printk(KERN_WARNING, ha, "%s: fail to get new mrb\n",
518 __func__));
519 rval = QLA_ERROR;
520 goto exit_ping;
521 }
522
523 in_mbox[0] = MBOX_CMD_PING;
524 in_mbox[1] = options;
525 memcpy(&in_mbox[2], &ipaddr[0], 4);
526 memcpy(&in_mbox[3], &ipaddr[4], 4);
527 memcpy(&in_mbox[4], &ipaddr[8], 4);
528 memcpy(&in_mbox[5], &ipaddr[12], 4);
529 in_mbox[6] = payload_size;
530
531 mrb->pid = pid;
532 rval = qla4xxx_send_mbox_iocb(ha, mrb, in_mbox);
533
534 if (rval != QLA_SUCCESS)
535 goto exit_ping;
536
537 return rval;
538exit_ping:
539 kfree(mrb);
540 return rval;
541}