]>
Commit | Line | Data |
---|---|---|
e3976af5 | 1 | // SPDX-License-Identifier: GPL-2.0-only |
afaf5a2d DS |
2 | /* |
3 | * QLogic iSCSI HBA Driver | |
4a4f51e9 | 4 | * Copyright (c) 2003-2013 QLogic Corporation |
afaf5a2d DS |
5 | */ |
6 | ||
7 | #include "ql4_def.h" | |
e08c182c DS |
8 | #include "ql4_glbl.h" |
9 | #include "ql4_dbg.h" | |
10 | #include "ql4_inline.h" | |
11 | ||
afaf5a2d DS |
12 | #include <scsi/scsi_tcq.h> |
13 | ||
16ed55f9 KH |
14 | static int |
15 | qla4xxx_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) { | |
b173a132 | 21 | cnt = (uint16_t) ha->isp_ops->rd_shdw_req_q_out(ha); |
16ed55f9 KH |
22 | 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 | ||
36 | static 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 | ||
afaf5a2d DS |
48 | /** |
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 | **/ | |
47975477 AB |
58 | static int qla4xxx_get_req_pkt(struct scsi_qla_host *ha, |
59 | struct queue_entry **queue_entry) | |
afaf5a2d | 60 | { |
16ed55f9 | 61 | uint16_t req_cnt = 1; |
afaf5a2d | 62 | |
16ed55f9 KH |
63 | if (qla4xxx_space_in_req_ring(ha, req_cnt)) { |
64 | *queue_entry = ha->request_ptr; | |
afaf5a2d | 65 | memset(*queue_entry, 0, sizeof(**queue_entry)); |
16ed55f9 KH |
66 | |
67 | qla4xxx_advance_req_ring_ptr(ha); | |
68 | ha->req_q_count -= req_cnt; | |
69 | return QLA_SUCCESS; | |
afaf5a2d DS |
70 | } |
71 | ||
16ed55f9 | 72 | return QLA_ERROR; |
afaf5a2d DS |
73 | } |
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 | |
67b8b93a | 80 | * @mrkr_mod: marker identifier |
afaf5a2d DS |
81 | * |
82 | * This routine issues a marker IOCB. | |
83 | **/ | |
9d562913 | 84 | int qla4xxx_send_marker_iocb(struct scsi_qla_host *ha, |
9cb78c16 | 85 | struct ddb_entry *ddb_entry, uint64_t lun, uint16_t mrkr_mod) |
afaf5a2d | 86 | { |
1c3f0b8e | 87 | struct qla4_marker_entry *marker_entry; |
afaf5a2d DS |
88 | 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); | |
9d562913 | 105 | marker_entry->modifier = cpu_to_le16(mrkr_mod); |
afaf5a2d DS |
106 | int_to_scsilun(lun, &marker_entry->lun); |
107 | wmb(); | |
108 | ||
109 | /* Tell ISP it's got a new I/O request */ | |
f4f5df23 | 110 | ha->isp_ops->queue_iocb(ha); |
afaf5a2d DS |
111 | |
112 | exit_send_marker: | |
113 | spin_unlock_irqrestore(&ha->hardware_lock, flags); | |
114 | return status; | |
115 | } | |
116 | ||
16ed55f9 KH |
117 | static struct continuation_t1_entry * |
118 | qla4xxx_alloc_cont_entry(struct scsi_qla_host *ha) | |
afaf5a2d DS |
119 | { |
120 | struct continuation_t1_entry *cont_entry; | |
121 | ||
122 | cont_entry = (struct continuation_t1_entry *)ha->request_ptr; | |
123 | ||
16ed55f9 | 124 | qla4xxx_advance_req_ring_ptr(ha); |
afaf5a2d DS |
125 | |
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 | ||
47975477 | 134 | static uint16_t qla4xxx_calc_request_entries(uint16_t dsds) |
afaf5a2d DS |
135 | { |
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 | ||
47975477 AB |
147 | static void qla4xxx_build_scsi_iocbs(struct srb *srb, |
148 | struct command_t3_entry *cmd_entry, | |
149 | uint16_t tot_dsds) | |
afaf5a2d DS |
150 | { |
151 | struct scsi_qla_host *ha; | |
152 | uint16_t avail_dsds; | |
153 | struct data_seg_a64 *cur_dsd; | |
154 | struct scsi_cmnd *cmd; | |
5f7186c8 FT |
155 | struct scatterlist *sg; |
156 | int i; | |
afaf5a2d DS |
157 | |
158 | cmd = srb->cmd; | |
159 | ha = srb->ha; | |
160 | ||
5f7186c8 | 161 | if (!scsi_bufflen(cmd) || cmd->sc_data_direction == DMA_NONE) { |
afaf5a2d DS |
162 | /* No data being transferred */ |
163 | cmd_entry->ttlByteCnt = __constant_cpu_to_le32(0); | |
164 | return; | |
165 | } | |
166 | ||
167 | avail_dsds = COMMAND_SEG; | |
168 | cur_dsd = (struct data_seg_a64 *) & (cmd_entry->dataseg[0]); | |
169 | ||
5f7186c8 FT |
170 | scsi_for_each_sg(cmd, sg, tot_dsds, i) { |
171 | dma_addr_t sle_dma; | |
172 | ||
173 | /* Allocate additional continuation packets? */ | |
174 | if (avail_dsds == 0) { | |
175 | struct continuation_t1_entry *cont_entry; | |
176 | ||
177 | 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; | |
afaf5a2d | 182 | } |
5f7186c8 FT |
183 | |
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++; | |
afaf5a2d DS |
191 | } |
192 | } | |
193 | ||
6e7b4292 VC |
194 | void 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 | ||
200 | void 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 | ||
f4f5df23 | 206 | /** |
f8086f4f | 207 | * qla4_82xx_queue_iocb - Tell ISP it's got new request(s) |
f4f5df23 VC |
208 | * @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 | **/ | |
f8086f4f | 213 | void qla4_82xx_queue_iocb(struct scsi_qla_host *ha) |
f4f5df23 VC |
214 | { |
215 | uint32_t dbval = 0; | |
f4f5df23 VC |
216 | |
217 | dbval = 0x14 | (ha->func_num << 5); | |
218 | dbval = dbval | (0 << 8) | (ha->request_in << 16); | |
f4f5df23 | 219 | |
f8086f4f | 220 | qla4_82xx_wr_32(ha, ha->nx_db_wr_ptr, ha->request_in); |
f4f5df23 VC |
221 | } |
222 | ||
223 | /** | |
f8086f4f | 224 | * qla4_82xx_complete_iocb - Tell ISP we're done with response(s) |
f4f5df23 VC |
225 | * @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 | **/ | |
f8086f4f | 231 | void qla4_82xx_complete_iocb(struct scsi_qla_host *ha) |
f4f5df23 | 232 | { |
7664a1fd VC |
233 | writel(ha->response_out, &ha->qla4_82xx_reg->rsp_q_out); |
234 | readl(&ha->qla4_82xx_reg->rsp_q_out); | |
f4f5df23 VC |
235 | } |
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 | **/ | |
244 | void 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 | **/ | |
258 | void 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 | ||
afaf5a2d DS |
264 | /** |
265 | * 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 | **/ | |
272 | int 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; | |
5f7186c8 | 277 | int nseg; |
afaf5a2d DS |
278 | uint16_t tot_dsds; |
279 | uint16_t req_cnt; | |
afaf5a2d | 280 | unsigned long flags; |
afaf5a2d | 281 | uint32_t index; |
afaf5a2d DS |
282 | |
283 | /* Get real lun and adapter */ | |
284 | ddb_entry = srb->ddb; | |
285 | ||
afaf5a2d DS |
286 | tot_dsds = 0; |
287 | ||
288 | /* Acquire hardware specific lock */ | |
289 | spin_lock_irqsave(&ha->hardware_lock, flags); | |
290 | ||
291 | index = (uint32_t)cmd->request->tag; | |
292 | ||
16ed55f9 KH |
293 | /* |
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 | ||
afaf5a2d | 306 | /* Calculate the number of request entries needed. */ |
5f7186c8 FT |
307 | nseg = scsi_dma_map(cmd); |
308 | if (nseg < 0) | |
309 | goto queuing_error; | |
310 | tot_dsds = nseg; | |
311 | ||
afaf5a2d | 312 | req_cnt = qla4xxx_calc_request_entries(tot_dsds); |
16ed55f9 | 313 | if (!qla4xxx_space_in_req_ring(ha, req_cnt)) |
afaf5a2d DS |
314 | goto queuing_error; |
315 | ||
316 | /* total iocbs active */ | |
5b1c1bff | 317 | if ((ha->iocb_cnt + req_cnt) >= ha->iocb_hiwat) |
afaf5a2d DS |
318 | 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); | |
afaf5a2d DS |
326 | |
327 | int_to_scsilun(cmd->device->lun, &cmd_entry->lun); | |
5f7186c8 | 328 | cmd_entry->ttlByteCnt = cpu_to_le32(scsi_bufflen(cmd)); |
afaf5a2d DS |
329 | 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; | |
5f7186c8 | 338 | if (scsi_bufflen(cmd)) { |
afaf5a2d DS |
339 | 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; | |
d915058f | 343 | |
5f7186c8 | 344 | ha->bytes_xfered += scsi_bufflen(cmd); |
d915058f DS |
345 | if (ha->bytes_xfered & ~0xFFFFF){ |
346 | ha->total_mbytes_xferred += ha->bytes_xfered >> 20; | |
347 | ha->bytes_xfered &= 0xFFFFF; | |
348 | } | |
afaf5a2d DS |
349 | } |
350 | ||
351 | /* Set tagged queueing control flags */ | |
352 | cmd_entry->control_flags |= CF_SIMPLE_TAG; | |
afaf5a2d | 353 | |
16ed55f9 | 354 | qla4xxx_advance_req_ring_ptr(ha); |
afaf5a2d DS |
355 | qla4xxx_build_scsi_iocbs(srb, cmd_entry, tot_dsds); |
356 | wmb(); | |
357 | ||
5369887a | 358 | srb->cmd->host_scribble = (unsigned char *)(unsigned long)index; |
afaf5a2d DS |
359 | |
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 | ||
f4f5df23 | 369 | ha->isp_ops->queue_iocb(ha); |
afaf5a2d DS |
370 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
371 | ||
372 | return QLA_SUCCESS; | |
373 | ||
374 | queuing_error: | |
5f7186c8 FT |
375 | if (tot_dsds) |
376 | scsi_dma_unmap(cmd); | |
afaf5a2d | 377 | |
afaf5a2d DS |
378 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
379 | ||
380 | return QLA_ERROR; | |
381 | } | |
382 | ||
b3a271a9 MR |
383 | int 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 */ | |
69ca216e | 411 | if (task_data->req_len) { |
b3a271a9 MR |
412 | 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 | ||
445 | queuing_error: | |
446 | spin_unlock_irqrestore(&ha->hardware_lock, flags); | |
447 | return ret; | |
448 | } | |
c0b9d3f7 VC |
449 | |
450 | static 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 | ||
a7380a65 VC |
462 | static int qla4xxx_send_mbox_iocb(struct scsi_qla_host *ha, struct mrb *mrb, |
463 | uint32_t *in_mbox) | |
c0b9d3f7 VC |
464 | { |
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 | ||
d522844a | 499 | ha->iocb_cnt += mrb->iocb_cnt; |
c0b9d3f7 VC |
500 | ha->isp_ops->queue_iocb(ha); |
501 | exit_mbox_iocb: | |
502 | spin_unlock_irqrestore(&ha->hardware_lock, flags); | |
503 | return rval; | |
504 | } | |
505 | ||
506 | int 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; | |
538 | exit_ping: | |
539 | kfree(mrb); | |
540 | return rval; | |
541 | } |