blob: 8861b88319fbcfea94fcef009bd4d6e1a4074cc1 [file] [log] [blame]
Andrew Vasquezfa90c542005-10-27 11:10:08 -07001/*
2 * QLogic Fibre Channel HBA Driver
Andrew Vasquez01e58d82008-04-03 13:13:13 -07003 * Copyright (c) 2003-2008 QLogic Corporation
Linus Torvalds1da177e2005-04-16 15:20:36 -07004 *
Andrew Vasquezfa90c542005-10-27 11:10:08 -07005 * See LICENSE.qla2xxx for copyright and licensing details.
6 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07007#include "qla_def.h"
8
9#include <linux/blkdev.h>
10#include <linux/delay.h>
11
12#include <scsi/scsi_tcq.h>
13
Anirban Chakraborty73208df2008-12-09 16:45:39 -080014static request_t *qla2x00_req_pkt(struct scsi_qla_host *, struct req_que *,
15 struct rsp_que *rsp);
16static void qla2x00_isp_cmd(struct scsi_qla_host *, struct req_que *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070017
Anirban Chakraborty59e0b8b2009-06-03 09:55:19 -070018static void qla25xx_set_que(srb_t *, struct rsp_que **);
Linus Torvalds1da177e2005-04-16 15:20:36 -070019/**
20 * qla2x00_get_cmd_direction() - Determine control_flag data direction.
21 * @cmd: SCSI command
22 *
23 * Returns the proper CF_* direction based on CDB.
24 */
25static inline uint16_t
Harish Zunjarrao49fd4622008-09-11 21:22:47 -070026qla2x00_get_cmd_direction(srb_t *sp)
Linus Torvalds1da177e2005-04-16 15:20:36 -070027{
28 uint16_t cflags;
29
30 cflags = 0;
31
32 /* Set transfer direction */
Harish Zunjarrao49fd4622008-09-11 21:22:47 -070033 if (sp->cmd->sc_data_direction == DMA_TO_DEVICE) {
Linus Torvalds1da177e2005-04-16 15:20:36 -070034 cflags = CF_WRITE;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -080035 sp->fcport->vha->hw->qla_stats.output_bytes +=
Harish Zunjarrao49fd4622008-09-11 21:22:47 -070036 scsi_bufflen(sp->cmd);
37 } else if (sp->cmd->sc_data_direction == DMA_FROM_DEVICE) {
Linus Torvalds1da177e2005-04-16 15:20:36 -070038 cflags = CF_READ;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -080039 sp->fcport->vha->hw->qla_stats.input_bytes +=
Harish Zunjarrao49fd4622008-09-11 21:22:47 -070040 scsi_bufflen(sp->cmd);
41 }
Linus Torvalds1da177e2005-04-16 15:20:36 -070042 return (cflags);
43}
44
45/**
46 * qla2x00_calc_iocbs_32() - Determine number of Command Type 2 and
47 * Continuation Type 0 IOCBs to allocate.
48 *
49 * @dsds: number of data segment decriptors needed
50 *
51 * Returns the number of IOCB entries needed to store @dsds.
52 */
53uint16_t
54qla2x00_calc_iocbs_32(uint16_t dsds)
55{
56 uint16_t iocbs;
57
58 iocbs = 1;
59 if (dsds > 3) {
60 iocbs += (dsds - 3) / 7;
61 if ((dsds - 3) % 7)
62 iocbs++;
63 }
64 return (iocbs);
65}
66
67/**
68 * qla2x00_calc_iocbs_64() - Determine number of Command Type 3 and
69 * Continuation Type 1 IOCBs to allocate.
70 *
71 * @dsds: number of data segment decriptors needed
72 *
73 * Returns the number of IOCB entries needed to store @dsds.
74 */
75uint16_t
76qla2x00_calc_iocbs_64(uint16_t dsds)
77{
78 uint16_t iocbs;
79
80 iocbs = 1;
81 if (dsds > 2) {
82 iocbs += (dsds - 2) / 5;
83 if ((dsds - 2) % 5)
84 iocbs++;
85 }
86 return (iocbs);
87}
88
89/**
90 * qla2x00_prep_cont_type0_iocb() - Initialize a Continuation Type 0 IOCB.
91 * @ha: HA context
92 *
93 * Returns a pointer to the Continuation Type 0 IOCB packet.
94 */
95static inline cont_entry_t *
Anirban Chakraborty67c2e932009-04-06 22:33:42 -070096qla2x00_prep_cont_type0_iocb(struct scsi_qla_host *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -070097{
98 cont_entry_t *cont_pkt;
Anirban Chakraborty67c2e932009-04-06 22:33:42 -070099 struct req_que *req = vha->req;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700100 /* Adjust ring index. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800101 req->ring_index++;
102 if (req->ring_index == req->length) {
103 req->ring_index = 0;
104 req->ring_ptr = req->ring;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700105 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800106 req->ring_ptr++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107 }
108
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800109 cont_pkt = (cont_entry_t *)req->ring_ptr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110
111 /* Load packet defaults. */
112 *((uint32_t *)(&cont_pkt->entry_type)) =
113 __constant_cpu_to_le32(CONTINUE_TYPE);
114
115 return (cont_pkt);
116}
117
118/**
119 * qla2x00_prep_cont_type1_iocb() - Initialize a Continuation Type 1 IOCB.
120 * @ha: HA context
121 *
122 * Returns a pointer to the continuation type 1 IOCB packet.
123 */
124static inline cont_a64_entry_t *
Anirban Chakraborty67c2e932009-04-06 22:33:42 -0700125qla2x00_prep_cont_type1_iocb(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700126{
127 cont_a64_entry_t *cont_pkt;
128
Anirban Chakraborty67c2e932009-04-06 22:33:42 -0700129 struct req_que *req = vha->req;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700130 /* Adjust ring index. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800131 req->ring_index++;
132 if (req->ring_index == req->length) {
133 req->ring_index = 0;
134 req->ring_ptr = req->ring;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700135 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800136 req->ring_ptr++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700137 }
138
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800139 cont_pkt = (cont_a64_entry_t *)req->ring_ptr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700140
141 /* Load packet defaults. */
142 *((uint32_t *)(&cont_pkt->entry_type)) =
143 __constant_cpu_to_le32(CONTINUE_A64_TYPE);
144
145 return (cont_pkt);
146}
147
148/**
149 * qla2x00_build_scsi_iocbs_32() - Build IOCB command utilizing 32bit
150 * capable IOCB types.
151 *
152 * @sp: SRB command to process
153 * @cmd_pkt: Command type 2 IOCB
154 * @tot_dsds: Total number of segments to transfer
155 */
156void qla2x00_build_scsi_iocbs_32(srb_t *sp, cmd_entry_t *cmd_pkt,
157 uint16_t tot_dsds)
158{
159 uint16_t avail_dsds;
160 uint32_t *cur_dsd;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800161 scsi_qla_host_t *vha;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700162 struct scsi_cmnd *cmd;
FUJITA Tomonori385d70b2007-05-26 01:55:38 +0900163 struct scatterlist *sg;
164 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700165
166 cmd = sp->cmd;
167
168 /* Update entry type to indicate Command Type 2 IOCB */
169 *((uint32_t *)(&cmd_pkt->entry_type)) =
170 __constant_cpu_to_le32(COMMAND_TYPE);
171
172 /* No data transfer */
FUJITA Tomonori385d70b2007-05-26 01:55:38 +0900173 if (!scsi_bufflen(cmd) || cmd->sc_data_direction == DMA_NONE) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700174 cmd_pkt->byte_count = __constant_cpu_to_le32(0);
175 return;
176 }
177
Andrew Vasquez444786d2009-01-05 11:18:10 -0800178 vha = sp->fcport->vha;
Harish Zunjarrao49fd4622008-09-11 21:22:47 -0700179 cmd_pkt->control_flags |= cpu_to_le16(qla2x00_get_cmd_direction(sp));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700180
181 /* Three DSDs are available in the Command Type 2 IOCB */
182 avail_dsds = 3;
183 cur_dsd = (uint32_t *)&cmd_pkt->dseg_0_address;
184
185 /* Load data segments */
FUJITA Tomonori385d70b2007-05-26 01:55:38 +0900186 scsi_for_each_sg(cmd, sg, tot_dsds, i) {
187 cont_entry_t *cont_pkt;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700188
FUJITA Tomonori385d70b2007-05-26 01:55:38 +0900189 /* Allocate additional continuation packets? */
190 if (avail_dsds == 0) {
191 /*
192 * Seven DSDs are available in the Continuation
193 * Type 0 IOCB.
194 */
Anirban Chakraborty67c2e932009-04-06 22:33:42 -0700195 cont_pkt = qla2x00_prep_cont_type0_iocb(vha);
FUJITA Tomonori385d70b2007-05-26 01:55:38 +0900196 cur_dsd = (uint32_t *)&cont_pkt->dseg_0_address;
197 avail_dsds = 7;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700198 }
FUJITA Tomonori385d70b2007-05-26 01:55:38 +0900199
200 *cur_dsd++ = cpu_to_le32(sg_dma_address(sg));
201 *cur_dsd++ = cpu_to_le32(sg_dma_len(sg));
202 avail_dsds--;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700203 }
204}
205
206/**
207 * qla2x00_build_scsi_iocbs_64() - Build IOCB command utilizing 64bit
208 * capable IOCB types.
209 *
210 * @sp: SRB command to process
211 * @cmd_pkt: Command type 3 IOCB
212 * @tot_dsds: Total number of segments to transfer
213 */
214void qla2x00_build_scsi_iocbs_64(srb_t *sp, cmd_entry_t *cmd_pkt,
215 uint16_t tot_dsds)
216{
217 uint16_t avail_dsds;
218 uint32_t *cur_dsd;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800219 scsi_qla_host_t *vha;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700220 struct scsi_cmnd *cmd;
FUJITA Tomonori385d70b2007-05-26 01:55:38 +0900221 struct scatterlist *sg;
222 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700223
224 cmd = sp->cmd;
225
226 /* Update entry type to indicate Command Type 3 IOCB */
227 *((uint32_t *)(&cmd_pkt->entry_type)) =
228 __constant_cpu_to_le32(COMMAND_A64_TYPE);
229
230 /* No data transfer */
FUJITA Tomonori385d70b2007-05-26 01:55:38 +0900231 if (!scsi_bufflen(cmd) || cmd->sc_data_direction == DMA_NONE) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700232 cmd_pkt->byte_count = __constant_cpu_to_le32(0);
233 return;
234 }
235
Andrew Vasquez444786d2009-01-05 11:18:10 -0800236 vha = sp->fcport->vha;
Harish Zunjarrao49fd4622008-09-11 21:22:47 -0700237 cmd_pkt->control_flags |= cpu_to_le16(qla2x00_get_cmd_direction(sp));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700238
239 /* Two DSDs are available in the Command Type 3 IOCB */
240 avail_dsds = 2;
241 cur_dsd = (uint32_t *)&cmd_pkt->dseg_0_address;
242
243 /* Load data segments */
FUJITA Tomonori385d70b2007-05-26 01:55:38 +0900244 scsi_for_each_sg(cmd, sg, tot_dsds, i) {
245 dma_addr_t sle_dma;
246 cont_a64_entry_t *cont_pkt;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700247
FUJITA Tomonori385d70b2007-05-26 01:55:38 +0900248 /* Allocate additional continuation packets? */
249 if (avail_dsds == 0) {
250 /*
251 * Five DSDs are available in the Continuation
252 * Type 1 IOCB.
253 */
Anirban Chakraborty67c2e932009-04-06 22:33:42 -0700254 cont_pkt = qla2x00_prep_cont_type1_iocb(vha);
FUJITA Tomonori385d70b2007-05-26 01:55:38 +0900255 cur_dsd = (uint32_t *)cont_pkt->dseg_0_address;
256 avail_dsds = 5;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700257 }
FUJITA Tomonori385d70b2007-05-26 01:55:38 +0900258
259 sle_dma = sg_dma_address(sg);
260 *cur_dsd++ = cpu_to_le32(LSD(sle_dma));
261 *cur_dsd++ = cpu_to_le32(MSD(sle_dma));
262 *cur_dsd++ = cpu_to_le32(sg_dma_len(sg));
263 avail_dsds--;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700264 }
265}
266
267/**
268 * qla2x00_start_scsi() - Send a SCSI command to the ISP
269 * @sp: command to send to the ISP
270 *
Bjorn Helgaascc3ef7b2008-09-11 21:22:51 -0700271 * Returns non-zero if a failure occurred, else zero.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700272 */
273int
274qla2x00_start_scsi(srb_t *sp)
275{
FUJITA Tomonori385d70b2007-05-26 01:55:38 +0900276 int ret, nseg;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700277 unsigned long flags;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800278 scsi_qla_host_t *vha;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700279 struct scsi_cmnd *cmd;
280 uint32_t *clr_ptr;
281 uint32_t index;
282 uint32_t handle;
283 cmd_entry_t *cmd_pkt;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700284 uint16_t cnt;
285 uint16_t req_cnt;
286 uint16_t tot_dsds;
Andrew Vasquez3d716442005-07-06 10:30:26 -0700287 struct device_reg_2xxx __iomem *reg;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800288 struct qla_hw_data *ha;
289 struct req_que *req;
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800290 struct rsp_que *rsp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700291
292 /* Setup device pointers. */
293 ret = 0;
Andrew Vasquez444786d2009-01-05 11:18:10 -0800294 vha = sp->fcport->vha;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800295 ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -0700296 reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700297 cmd = sp->cmd;
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800298 req = ha->req_q_map[0];
299 rsp = ha->rsp_q_map[0];
83021922005-04-17 15:10:41 -0500300 /* So we know we haven't pci_map'ed anything yet */
301 tot_dsds = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700302
303 /* Send marker if required */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800304 if (vha->marker_needed != 0) {
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800305 if (qla2x00_marker(vha, req, rsp, 0, 0, MK_SYNC_ALL)
306 != QLA_SUCCESS)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700307 return (QLA_FUNCTION_FAILED);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800308 vha->marker_needed = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700309 }
310
311 /* Acquire ring specific lock */
Andrew Vasquezc9c5ced2008-07-24 08:31:49 -0700312 spin_lock_irqsave(&ha->hardware_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700313
314 /* Check for room in outstanding command list. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800315 handle = req->current_outstanding_cmd;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700316 for (index = 1; index < MAX_OUTSTANDING_COMMANDS; index++) {
317 handle++;
318 if (handle == MAX_OUTSTANDING_COMMANDS)
319 handle = 1;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800320 if (!req->outstanding_cmds[handle])
Linus Torvalds1da177e2005-04-16 15:20:36 -0700321 break;
322 }
323 if (index == MAX_OUTSTANDING_COMMANDS)
324 goto queuing_error;
325
83021922005-04-17 15:10:41 -0500326 /* Map the sg table so we have an accurate count of sg entries needed */
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700327 if (scsi_sg_count(cmd)) {
328 nseg = dma_map_sg(&ha->pdev->dev, scsi_sglist(cmd),
329 scsi_sg_count(cmd), cmd->sc_data_direction);
330 if (unlikely(!nseg))
331 goto queuing_error;
332 } else
333 nseg = 0;
334
FUJITA Tomonori385d70b2007-05-26 01:55:38 +0900335 tot_dsds = nseg;
83021922005-04-17 15:10:41 -0500336
Linus Torvalds1da177e2005-04-16 15:20:36 -0700337 /* Calculate the number of request entries needed. */
Andrew Vasquezfd34f552007-07-19 15:06:00 -0700338 req_cnt = ha->isp_ops->calc_req_entries(tot_dsds);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800339 if (req->cnt < (req_cnt + 2)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700340 cnt = RD_REG_WORD_RELAXED(ISP_REQ_Q_OUT(ha, reg));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800341 if (req->ring_index < cnt)
342 req->cnt = cnt - req->ring_index;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700343 else
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800344 req->cnt = req->length -
345 (req->ring_index - cnt);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700346 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800347 if (req->cnt < (req_cnt + 2))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700348 goto queuing_error;
349
Linus Torvalds1da177e2005-04-16 15:20:36 -0700350 /* Build command packet */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800351 req->current_outstanding_cmd = handle;
352 req->outstanding_cmds[handle] = sp;
Andrew Vasquezcf53b062009-08-20 11:06:04 -0700353 sp->handle = handle;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700354 sp->cmd->host_scribble = (unsigned char *)(unsigned long)handle;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800355 req->cnt -= req_cnt;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700356
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800357 cmd_pkt = (cmd_entry_t *)req->ring_ptr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700358 cmd_pkt->handle = handle;
359 /* Zero out remaining portion of packet. */
360 clr_ptr = (uint32_t *)cmd_pkt + 2;
361 memset(clr_ptr, 0, REQUEST_ENTRY_SIZE - 8);
362 cmd_pkt->dseg_count = cpu_to_le16(tot_dsds);
363
bdf79622005-04-17 15:06:53 -0500364 /* Set target ID and LUN number*/
365 SET_TARGET_ID(ha, cmd_pkt->target, sp->fcport->loop_id);
366 cmd_pkt->lun = cpu_to_le16(sp->cmd->device->lun);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700367
368 /* Update tagged queuing modifier */
369 cmd_pkt->control_flags = __constant_cpu_to_le16(CF_SIMPLE_TAG);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700370
Linus Torvalds1da177e2005-04-16 15:20:36 -0700371 /* Load SCSI command packet. */
372 memcpy(cmd_pkt->scsi_cdb, cmd->cmnd, cmd->cmd_len);
FUJITA Tomonori385d70b2007-05-26 01:55:38 +0900373 cmd_pkt->byte_count = cpu_to_le32((uint32_t)scsi_bufflen(cmd));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700374
375 /* Build IOCB segments */
Andrew Vasquezfd34f552007-07-19 15:06:00 -0700376 ha->isp_ops->build_iocbs(sp, cmd_pkt, tot_dsds);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700377
378 /* Set total data segment count. */
379 cmd_pkt->entry_count = (uint8_t)req_cnt;
380 wmb();
381
382 /* Adjust ring index. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800383 req->ring_index++;
384 if (req->ring_index == req->length) {
385 req->ring_index = 0;
386 req->ring_ptr = req->ring;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700387 } else
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800388 req->ring_ptr++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700389
Linus Torvalds1da177e2005-04-16 15:20:36 -0700390 sp->flags |= SRB_DMA_VALID;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700391
392 /* Set chip new ring index. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800393 WRT_REG_WORD(ISP_REQ_Q_IN(ha, reg), req->ring_index);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700394 RD_REG_WORD_RELAXED(ISP_REQ_Q_IN(ha, reg)); /* PCI Posting. */
395
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -0700396 /* Manage unprocessed RIO/ZIO commands in response queue. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800397 if (vha->flags.process_response_queue &&
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800398 rsp->ring_ptr->signature != RESPONSE_PROCESSED)
399 qla2x00_process_response_queue(rsp);
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -0700400
Andrew Vasquezc9c5ced2008-07-24 08:31:49 -0700401 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700402 return (QLA_SUCCESS);
403
404queuing_error:
FUJITA Tomonori385d70b2007-05-26 01:55:38 +0900405 if (tot_dsds)
406 scsi_dma_unmap(cmd);
407
Andrew Vasquezc9c5ced2008-07-24 08:31:49 -0700408 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700409
410 return (QLA_FUNCTION_FAILED);
411}
412
413/**
414 * qla2x00_marker() - Send a marker IOCB to the firmware.
415 * @ha: HA context
416 * @loop_id: loop ID
417 * @lun: LUN
418 * @type: marker modifier
419 *
420 * Can be called from both normal and interrupt context.
421 *
Bjorn Helgaascc3ef7b2008-09-11 21:22:51 -0700422 * Returns non-zero if a failure occurred, else zero.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700423 */
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700424int
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800425__qla2x00_marker(struct scsi_qla_host *vha, struct req_que *req,
426 struct rsp_que *rsp, uint16_t loop_id,
427 uint16_t lun, uint8_t type)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700428{
Andrew Vasquez2b6c0ce2005-07-06 10:31:17 -0700429 mrk_entry_t *mrk;
430 struct mrk_entry_24xx *mrk24;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800431 struct qla_hw_data *ha = vha->hw;
432 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700433
Andrew Vasquez2b6c0ce2005-07-06 10:31:17 -0700434 mrk24 = NULL;
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800435 mrk = (mrk_entry_t *)qla2x00_req_pkt(vha, req, rsp);
Andrew Vasquez2b6c0ce2005-07-06 10:31:17 -0700436 if (mrk == NULL) {
437 DEBUG2_3(printk("%s(%ld): failed to allocate Marker IOCB.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800438 __func__, base_vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700439
440 return (QLA_FUNCTION_FAILED);
441 }
442
Andrew Vasquez2b6c0ce2005-07-06 10:31:17 -0700443 mrk->entry_type = MARKER_TYPE;
444 mrk->modifier = type;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700445 if (type != MK_SYNC_ALL) {
Andrew Vasqueze4289242007-07-19 15:05:56 -0700446 if (IS_FWI2_CAPABLE(ha)) {
Andrew Vasquez2b6c0ce2005-07-06 10:31:17 -0700447 mrk24 = (struct mrk_entry_24xx *) mrk;
448 mrk24->nport_handle = cpu_to_le16(loop_id);
449 mrk24->lun[1] = LSB(lun);
450 mrk24->lun[2] = MSB(lun);
Shyam Sundarb797b6d2006-08-01 13:48:13 -0700451 host_to_fcp_swap(mrk24->lun, sizeof(mrk24->lun));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800452 mrk24->vp_index = vha->vp_idx;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700453 mrk24->handle = MAKE_HANDLE(req->id, mrk24->handle);
Andrew Vasquez2b6c0ce2005-07-06 10:31:17 -0700454 } else {
455 SET_TARGET_ID(ha, mrk->target, loop_id);
456 mrk->lun = cpu_to_le16(lun);
457 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700458 }
459 wmb();
460
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800461 qla2x00_isp_cmd(vha, req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700462
463 return (QLA_SUCCESS);
464}
465
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700466int
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800467qla2x00_marker(struct scsi_qla_host *vha, struct req_que *req,
468 struct rsp_que *rsp, uint16_t loop_id, uint16_t lun,
469 uint8_t type)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700470{
471 int ret;
472 unsigned long flags = 0;
473
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800474 spin_lock_irqsave(&vha->hw->hardware_lock, flags);
475 ret = __qla2x00_marker(vha, req, rsp, loop_id, lun, type);
476 spin_unlock_irqrestore(&vha->hw->hardware_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700477
478 return (ret);
479}
480
481/**
482 * qla2x00_req_pkt() - Retrieve a request packet from the request ring.
483 * @ha: HA context
484 *
485 * Note: The caller must hold the hardware lock before calling this routine.
486 *
487 * Returns NULL if function failed, else, a pointer to the request packet.
488 */
489static request_t *
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800490qla2x00_req_pkt(struct scsi_qla_host *vha, struct req_que *req,
491 struct rsp_que *rsp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700492{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800493 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800494 device_reg_t __iomem *reg = ISP_QUE_REG(ha, req->id);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700495 request_t *pkt = NULL;
496 uint16_t cnt;
497 uint32_t *dword_ptr;
498 uint32_t timer;
499 uint16_t req_cnt = 1;
500
501 /* Wait 1 second for slot. */
502 for (timer = HZ; timer; timer--) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800503 if ((req_cnt + 2) >= req->cnt) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700504 /* Calculate number of free request entries. */
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800505 if (ha->mqenable)
506 cnt = (uint16_t)
507 RD_REG_DWORD(&reg->isp25mq.req_q_out);
508 else {
Giridhar Malavalia9083012010-04-12 17:59:55 -0700509 if (IS_QLA82XX(ha))
510 cnt = (uint16_t)RD_REG_DWORD(
511 &reg->isp82.req_q_out);
512 else if (IS_FWI2_CAPABLE(ha))
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800513 cnt = (uint16_t)RD_REG_DWORD(
514 &reg->isp24.req_q_out);
515 else
516 cnt = qla2x00_debounce_register(
517 ISP_REQ_Q_OUT(ha, &reg->isp));
518 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800519 if (req->ring_index < cnt)
520 req->cnt = cnt - req->ring_index;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700521 else
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800522 req->cnt = req->length -
523 (req->ring_index - cnt);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700524 }
525 /* If room for request in request ring. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800526 if ((req_cnt + 2) < req->cnt) {
527 req->cnt--;
528 pkt = req->ring_ptr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700529
530 /* Zero out packet. */
531 dword_ptr = (uint32_t *)pkt;
532 for (cnt = 0; cnt < REQUEST_ENTRY_SIZE / 4; cnt++)
533 *dword_ptr++ = 0;
534
Linus Torvalds1da177e2005-04-16 15:20:36 -0700535 /* Set entry count. */
536 pkt->entry_count = 1;
537
538 break;
539 }
540
541 /* Release ring specific lock */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800542 spin_unlock_irq(&ha->hardware_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700543
544 udelay(2); /* 2 us */
545
546 /* Check for pending interrupts. */
547 /* During init we issue marker directly */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800548 if (!vha->marker_needed && !vha->flags.init_done)
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800549 qla2x00_poll(rsp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700550 spin_lock_irq(&ha->hardware_lock);
551 }
552 if (!pkt) {
553 DEBUG2_3(printk("%s(): **** FAILED ****\n", __func__));
554 }
555
556 return (pkt);
557}
558
559/**
560 * qla2x00_isp_cmd() - Modify the request ring pointer.
561 * @ha: HA context
562 *
563 * Note: The caller must hold the hardware lock before calling this routine.
564 */
Adrian Bunk413975a2006-06-30 02:33:06 -0700565static void
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800566qla2x00_isp_cmd(struct scsi_qla_host *vha, struct req_que *req)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700567{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800568 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800569 device_reg_t __iomem *reg = ISP_QUE_REG(ha, req->id);
Anirban Chakraborty17d98632008-12-18 10:06:15 -0800570 struct device_reg_2xxx __iomem *ioreg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700571
572 DEBUG5(printk("%s(): IOCB data:\n", __func__));
573 DEBUG5(qla2x00_dump_buffer(
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800574 (uint8_t *)req->ring_ptr, REQUEST_ENTRY_SIZE));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700575
576 /* Adjust ring index. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800577 req->ring_index++;
578 if (req->ring_index == req->length) {
579 req->ring_index = 0;
580 req->ring_ptr = req->ring;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700581 } else
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800582 req->ring_ptr++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700583
584 /* Set chip new ring index. */
Giridhar Malavalia9083012010-04-12 17:59:55 -0700585 if (IS_QLA82XX(ha)) {
586 uint32_t dbval = 0x04 | (ha->portnum << 5);
587
588 /* write, read and verify logic */
589 dbval = dbval | (req->id << 8) | (req->ring_index << 16);
590 if (ql2xdbwr)
591 qla82xx_wr_32(ha, ha->nxdb_wr_ptr, dbval);
592 else {
593 WRT_REG_DWORD(
594 (unsigned long __iomem *)ha->nxdb_wr_ptr,
595 dbval);
596 wmb();
597 while (RD_REG_DWORD(ha->nxdb_rd_ptr) != dbval) {
598 WRT_REG_DWORD((unsigned long __iomem *)
599 ha->nxdb_wr_ptr, dbval);
600 wmb();
601 }
602 }
603 } else if (ha->mqenable) {
604 /* Set chip new ring index. */
Anirban Chakraborty17d98632008-12-18 10:06:15 -0800605 WRT_REG_DWORD(&reg->isp25mq.req_q_in, req->ring_index);
606 RD_REG_DWORD(&ioreg->hccr);
Giridhar Malavalia9083012010-04-12 17:59:55 -0700607 } else {
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800608 if (IS_FWI2_CAPABLE(ha)) {
609 WRT_REG_DWORD(&reg->isp24.req_q_in, req->ring_index);
610 RD_REG_DWORD_RELAXED(&reg->isp24.req_q_in);
611 } else {
612 WRT_REG_WORD(ISP_REQ_Q_IN(ha, &reg->isp),
613 req->ring_index);
614 RD_REG_WORD_RELAXED(ISP_REQ_Q_IN(ha, &reg->isp));
615 }
Andrew Vasquez2b6c0ce2005-07-06 10:31:17 -0700616 }
617
618}
619
620/**
621 * qla24xx_calc_iocbs() - Determine number of Command Type 3 and
622 * Continuation Type 1 IOCBs to allocate.
623 *
624 * @dsds: number of data segment decriptors needed
625 *
626 * Returns the number of IOCB entries needed to store @dsds.
627 */
Giridhar Malavalia9083012010-04-12 17:59:55 -0700628inline uint16_t
Andrew Vasquez2b6c0ce2005-07-06 10:31:17 -0700629qla24xx_calc_iocbs(uint16_t dsds)
630{
631 uint16_t iocbs;
632
633 iocbs = 1;
634 if (dsds > 1) {
635 iocbs += (dsds - 1) / 5;
636 if ((dsds - 1) % 5)
637 iocbs++;
638 }
639 return iocbs;
640}
641
642/**
643 * qla24xx_build_scsi_iocbs() - Build IOCB command utilizing Command Type 7
644 * IOCB types.
645 *
646 * @sp: SRB command to process
647 * @cmd_pkt: Command type 3 IOCB
648 * @tot_dsds: Total number of segments to transfer
649 */
Giridhar Malavalia9083012010-04-12 17:59:55 -0700650inline void
Andrew Vasquez2b6c0ce2005-07-06 10:31:17 -0700651qla24xx_build_scsi_iocbs(srb_t *sp, struct cmd_type_7 *cmd_pkt,
652 uint16_t tot_dsds)
653{
654 uint16_t avail_dsds;
655 uint32_t *cur_dsd;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800656 scsi_qla_host_t *vha;
Andrew Vasquez2b6c0ce2005-07-06 10:31:17 -0700657 struct scsi_cmnd *cmd;
FUJITA Tomonori385d70b2007-05-26 01:55:38 +0900658 struct scatterlist *sg;
659 int i;
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800660 struct req_que *req;
Andrew Vasquez2b6c0ce2005-07-06 10:31:17 -0700661
662 cmd = sp->cmd;
663
664 /* Update entry type to indicate Command Type 3 IOCB */
665 *((uint32_t *)(&cmd_pkt->entry_type)) =
666 __constant_cpu_to_le32(COMMAND_TYPE_7);
667
668 /* No data transfer */
FUJITA Tomonori385d70b2007-05-26 01:55:38 +0900669 if (!scsi_bufflen(cmd) || cmd->sc_data_direction == DMA_NONE) {
Andrew Vasquez2b6c0ce2005-07-06 10:31:17 -0700670 cmd_pkt->byte_count = __constant_cpu_to_le32(0);
671 return;
672 }
673
Andrew Vasquez444786d2009-01-05 11:18:10 -0800674 vha = sp->fcport->vha;
Anirban Chakraborty67c2e932009-04-06 22:33:42 -0700675 req = vha->req;
Andrew Vasquez2b6c0ce2005-07-06 10:31:17 -0700676
677 /* Set transfer direction */
Harish Zunjarrao49fd4622008-09-11 21:22:47 -0700678 if (cmd->sc_data_direction == DMA_TO_DEVICE) {
Andrew Vasquez2b6c0ce2005-07-06 10:31:17 -0700679 cmd_pkt->task_mgmt_flags =
680 __constant_cpu_to_le16(TMF_WRITE_DATA);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800681 sp->fcport->vha->hw->qla_stats.output_bytes +=
Harish Zunjarrao49fd4622008-09-11 21:22:47 -0700682 scsi_bufflen(sp->cmd);
683 } else if (cmd->sc_data_direction == DMA_FROM_DEVICE) {
Andrew Vasquez2b6c0ce2005-07-06 10:31:17 -0700684 cmd_pkt->task_mgmt_flags =
685 __constant_cpu_to_le16(TMF_READ_DATA);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800686 sp->fcport->vha->hw->qla_stats.input_bytes +=
Harish Zunjarrao49fd4622008-09-11 21:22:47 -0700687 scsi_bufflen(sp->cmd);
688 }
Andrew Vasquez2b6c0ce2005-07-06 10:31:17 -0700689
690 /* One DSD is available in the Command Type 3 IOCB */
691 avail_dsds = 1;
692 cur_dsd = (uint32_t *)&cmd_pkt->dseg_0_address;
693
694 /* Load data segments */
Andrew Vasquez2b6c0ce2005-07-06 10:31:17 -0700695
FUJITA Tomonori385d70b2007-05-26 01:55:38 +0900696 scsi_for_each_sg(cmd, sg, tot_dsds, i) {
697 dma_addr_t sle_dma;
698 cont_a64_entry_t *cont_pkt;
Andrew Vasquez2b6c0ce2005-07-06 10:31:17 -0700699
FUJITA Tomonori385d70b2007-05-26 01:55:38 +0900700 /* Allocate additional continuation packets? */
701 if (avail_dsds == 0) {
702 /*
703 * Five DSDs are available in the Continuation
704 * Type 1 IOCB.
705 */
Anirban Chakraborty67c2e932009-04-06 22:33:42 -0700706 cont_pkt = qla2x00_prep_cont_type1_iocb(vha);
FUJITA Tomonori385d70b2007-05-26 01:55:38 +0900707 cur_dsd = (uint32_t *)cont_pkt->dseg_0_address;
708 avail_dsds = 5;
Andrew Vasquez2b6c0ce2005-07-06 10:31:17 -0700709 }
FUJITA Tomonori385d70b2007-05-26 01:55:38 +0900710
711 sle_dma = sg_dma_address(sg);
712 *cur_dsd++ = cpu_to_le32(LSD(sle_dma));
713 *cur_dsd++ = cpu_to_le32(MSD(sle_dma));
714 *cur_dsd++ = cpu_to_le32(sg_dma_len(sg));
715 avail_dsds--;
Andrew Vasquez2b6c0ce2005-07-06 10:31:17 -0700716 }
717}
718
719
720/**
721 * qla24xx_start_scsi() - Send a SCSI command to the ISP
722 * @sp: command to send to the ISP
723 *
Bjorn Helgaascc3ef7b2008-09-11 21:22:51 -0700724 * Returns non-zero if a failure occurred, else zero.
Andrew Vasquez2b6c0ce2005-07-06 10:31:17 -0700725 */
726int
727qla24xx_start_scsi(srb_t *sp)
728{
FUJITA Tomonori385d70b2007-05-26 01:55:38 +0900729 int ret, nseg;
Andrew Vasquez2b6c0ce2005-07-06 10:31:17 -0700730 unsigned long flags;
Andrew Vasquez2b6c0ce2005-07-06 10:31:17 -0700731 uint32_t *clr_ptr;
732 uint32_t index;
733 uint32_t handle;
734 struct cmd_type_7 *cmd_pkt;
Andrew Vasquez2b6c0ce2005-07-06 10:31:17 -0700735 uint16_t cnt;
736 uint16_t req_cnt;
737 uint16_t tot_dsds;
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800738 struct req_que *req = NULL;
739 struct rsp_que *rsp = NULL;
740 struct scsi_cmnd *cmd = sp->cmd;
Andrew Vasquez444786d2009-01-05 11:18:10 -0800741 struct scsi_qla_host *vha = sp->fcport->vha;
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800742 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez2b6c0ce2005-07-06 10:31:17 -0700743
744 /* Setup device pointers. */
745 ret = 0;
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800746
Anirban Chakraborty59e0b8b2009-06-03 09:55:19 -0700747 qla25xx_set_que(sp, &rsp);
748 req = vha->req;
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800749
Andrew Vasquez2b6c0ce2005-07-06 10:31:17 -0700750 /* So we know we haven't pci_map'ed anything yet */
751 tot_dsds = 0;
752
753 /* Send marker if required */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800754 if (vha->marker_needed != 0) {
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800755 if (qla2x00_marker(vha, req, rsp, 0, 0, MK_SYNC_ALL)
756 != QLA_SUCCESS)
Andrew Vasquez2b6c0ce2005-07-06 10:31:17 -0700757 return QLA_FUNCTION_FAILED;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800758 vha->marker_needed = 0;
Andrew Vasquez2b6c0ce2005-07-06 10:31:17 -0700759 }
760
761 /* Acquire ring specific lock */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800762 spin_lock_irqsave(&ha->hardware_lock, flags);
Andrew Vasquez2b6c0ce2005-07-06 10:31:17 -0700763
764 /* Check for room in outstanding command list. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800765 handle = req->current_outstanding_cmd;
Andrew Vasquez2b6c0ce2005-07-06 10:31:17 -0700766 for (index = 1; index < MAX_OUTSTANDING_COMMANDS; index++) {
767 handle++;
768 if (handle == MAX_OUTSTANDING_COMMANDS)
769 handle = 1;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800770 if (!req->outstanding_cmds[handle])
Andrew Vasquez2b6c0ce2005-07-06 10:31:17 -0700771 break;
772 }
773 if (index == MAX_OUTSTANDING_COMMANDS)
774 goto queuing_error;
775
776 /* Map the sg table so we have an accurate count of sg entries needed */
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700777 if (scsi_sg_count(cmd)) {
778 nseg = dma_map_sg(&ha->pdev->dev, scsi_sglist(cmd),
779 scsi_sg_count(cmd), cmd->sc_data_direction);
780 if (unlikely(!nseg))
Andrew Vasquez2b6c0ce2005-07-06 10:31:17 -0700781 goto queuing_error;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700782 } else
783 nseg = 0;
784
FUJITA Tomonori385d70b2007-05-26 01:55:38 +0900785 tot_dsds = nseg;
Andrew Vasquez2b6c0ce2005-07-06 10:31:17 -0700786
787 req_cnt = qla24xx_calc_iocbs(tot_dsds);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800788 if (req->cnt < (req_cnt + 2)) {
Andrew Vasquez08029992009-03-24 09:07:55 -0700789 cnt = RD_REG_DWORD_RELAXED(req->req_q_out);
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800790
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800791 if (req->ring_index < cnt)
792 req->cnt = cnt - req->ring_index;
Andrew Vasquez2b6c0ce2005-07-06 10:31:17 -0700793 else
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800794 req->cnt = req->length -
795 (req->ring_index - cnt);
Andrew Vasquez2b6c0ce2005-07-06 10:31:17 -0700796 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800797 if (req->cnt < (req_cnt + 2))
Andrew Vasquez2b6c0ce2005-07-06 10:31:17 -0700798 goto queuing_error;
Andrew Vasquez2b6c0ce2005-07-06 10:31:17 -0700799
800 /* Build command packet. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800801 req->current_outstanding_cmd = handle;
802 req->outstanding_cmds[handle] = sp;
Andrew Vasquezcf53b062009-08-20 11:06:04 -0700803 sp->handle = handle;
Andrew Vasquez2b6c0ce2005-07-06 10:31:17 -0700804 sp->cmd->host_scribble = (unsigned char *)(unsigned long)handle;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800805 req->cnt -= req_cnt;
Andrew Vasquez2b6c0ce2005-07-06 10:31:17 -0700806
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800807 cmd_pkt = (struct cmd_type_7 *)req->ring_ptr;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700808 cmd_pkt->handle = MAKE_HANDLE(req->id, handle);
Andrew Vasquez2b6c0ce2005-07-06 10:31:17 -0700809
810 /* Zero out remaining portion of packet. */
James Bottomley72df8322005-10-28 14:41:19 -0500811 /* tagged queuing modifier -- default is TSK_SIMPLE (0). */
Andrew Vasquez2b6c0ce2005-07-06 10:31:17 -0700812 clr_ptr = (uint32_t *)cmd_pkt + 2;
813 memset(clr_ptr, 0, REQUEST_ENTRY_SIZE - 8);
814 cmd_pkt->dseg_count = cpu_to_le16(tot_dsds);
815
816 /* Set NPORT-ID and LUN number*/
817 cmd_pkt->nport_handle = cpu_to_le16(sp->fcport->loop_id);
818 cmd_pkt->port_id[0] = sp->fcport->d_id.b.al_pa;
819 cmd_pkt->port_id[1] = sp->fcport->d_id.b.area;
820 cmd_pkt->port_id[2] = sp->fcport->d_id.b.domain;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700821 cmd_pkt->vp_index = sp->fcport->vp_idx;
Andrew Vasquez2b6c0ce2005-07-06 10:31:17 -0700822
Andrew Vasquez661c3f62005-10-27 11:09:58 -0700823 int_to_scsilun(sp->cmd->device->lun, &cmd_pkt->lun);
andrew.vasquez@qlogic.com0d4be122006-02-07 08:45:35 -0800824 host_to_fcp_swap((uint8_t *)&cmd_pkt->lun, sizeof(cmd_pkt->lun));
Andrew Vasquez2b6c0ce2005-07-06 10:31:17 -0700825
Andrew Vasquez2b6c0ce2005-07-06 10:31:17 -0700826 /* Load SCSI command packet. */
827 memcpy(cmd_pkt->fcp_cdb, cmd->cmnd, cmd->cmd_len);
828 host_to_fcp_swap(cmd_pkt->fcp_cdb, sizeof(cmd_pkt->fcp_cdb));
829
FUJITA Tomonori385d70b2007-05-26 01:55:38 +0900830 cmd_pkt->byte_count = cpu_to_le32((uint32_t)scsi_bufflen(cmd));
Andrew Vasquez2b6c0ce2005-07-06 10:31:17 -0700831
832 /* Build IOCB segments */
833 qla24xx_build_scsi_iocbs(sp, cmd_pkt, tot_dsds);
834
835 /* Set total data segment count. */
836 cmd_pkt->entry_count = (uint8_t)req_cnt;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700837 /* Specify response queue number where completion should happen */
838 cmd_pkt->entry_status = (uint8_t) rsp->id;
Andrew Vasquez2b6c0ce2005-07-06 10:31:17 -0700839 wmb();
840
841 /* Adjust ring index. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800842 req->ring_index++;
843 if (req->ring_index == req->length) {
844 req->ring_index = 0;
845 req->ring_ptr = req->ring;
Andrew Vasquez2b6c0ce2005-07-06 10:31:17 -0700846 } else
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800847 req->ring_ptr++;
Andrew Vasquez2b6c0ce2005-07-06 10:31:17 -0700848
849 sp->flags |= SRB_DMA_VALID;
Andrew Vasquez2b6c0ce2005-07-06 10:31:17 -0700850
851 /* Set chip new ring index. */
Andrew Vasquez08029992009-03-24 09:07:55 -0700852 WRT_REG_DWORD(req->req_q_in, req->ring_index);
853 RD_REG_DWORD_RELAXED(&ha->iobase->isp24.hccr);
Andrew Vasquez2b6c0ce2005-07-06 10:31:17 -0700854
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -0700855 /* Manage unprocessed RIO/ZIO commands in response queue. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800856 if (vha->flags.process_response_queue &&
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800857 rsp->ring_ptr->signature != RESPONSE_PROCESSED)
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700858 qla24xx_process_response_queue(vha, rsp);
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -0700859
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800860 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Andrew Vasquez2b6c0ce2005-07-06 10:31:17 -0700861 return QLA_SUCCESS;
862
863queuing_error:
FUJITA Tomonori385d70b2007-05-26 01:55:38 +0900864 if (tot_dsds)
865 scsi_dma_unmap(cmd);
866
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800867 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Andrew Vasquez2b6c0ce2005-07-06 10:31:17 -0700868
869 return QLA_FUNCTION_FAILED;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700870}
Anirban Chakraborty68ca9492009-04-06 22:33:41 -0700871
Anirban Chakraborty59e0b8b2009-06-03 09:55:19 -0700872static void qla25xx_set_que(srb_t *sp, struct rsp_que **rsp)
Anirban Chakraborty68ca9492009-04-06 22:33:41 -0700873{
874 struct scsi_cmnd *cmd = sp->cmd;
Anirban Chakraborty68ca9492009-04-06 22:33:41 -0700875 struct qla_hw_data *ha = sp->fcport->vha->hw;
876 int affinity = cmd->request->cpu;
877
Anirban Chakraborty7163ea82009-08-05 09:18:40 -0700878 if (ha->flags.cpu_affinity_enabled && affinity >= 0 &&
Anirban Chakraborty59e0b8b2009-06-03 09:55:19 -0700879 affinity < ha->max_rsp_queues - 1)
Anirban Chakraborty68ca9492009-04-06 22:33:41 -0700880 *rsp = ha->rsp_q_map[affinity + 1];
Anirban Chakraborty59e0b8b2009-06-03 09:55:19 -0700881 else
Anirban Chakraborty68ca9492009-04-06 22:33:41 -0700882 *rsp = ha->rsp_q_map[0];
Anirban Chakraborty68ca9492009-04-06 22:33:41 -0700883}
Andrew Vasquezac280b62009-08-20 11:06:05 -0700884
885/* Generic Control-SRB manipulation functions. */
886
887static void *
888qla2x00_alloc_iocbs(srb_t *sp)
889{
890 scsi_qla_host_t *vha = sp->fcport->vha;
891 struct qla_hw_data *ha = vha->hw;
892 struct req_que *req = ha->req_q_map[0];
893 device_reg_t __iomem *reg = ISP_QUE_REG(ha, req->id);
894 uint32_t index, handle;
895 request_t *pkt;
896 uint16_t cnt, req_cnt;
897
898 pkt = NULL;
899 req_cnt = 1;
900
901 /* Check for room in outstanding command list. */
902 handle = req->current_outstanding_cmd;
903 for (index = 1; index < MAX_OUTSTANDING_COMMANDS; index++) {
904 handle++;
905 if (handle == MAX_OUTSTANDING_COMMANDS)
906 handle = 1;
907 if (!req->outstanding_cmds[handle])
908 break;
909 }
910 if (index == MAX_OUTSTANDING_COMMANDS)
911 goto queuing_error;
912
913 /* Check for room on request queue. */
914 if (req->cnt < req_cnt) {
915 if (ha->mqenable)
916 cnt = RD_REG_DWORD(&reg->isp25mq.req_q_out);
917 else if (IS_FWI2_CAPABLE(ha))
918 cnt = RD_REG_DWORD(&reg->isp24.req_q_out);
919 else
920 cnt = qla2x00_debounce_register(
921 ISP_REQ_Q_OUT(ha, &reg->isp));
922
923 if (req->ring_index < cnt)
924 req->cnt = cnt - req->ring_index;
925 else
926 req->cnt = req->length -
927 (req->ring_index - cnt);
928 }
929 if (req->cnt < req_cnt)
930 goto queuing_error;
931
932 /* Prep packet */
933 req->current_outstanding_cmd = handle;
934 req->outstanding_cmds[handle] = sp;
935 req->cnt -= req_cnt;
936
937 pkt = req->ring_ptr;
938 memset(pkt, 0, REQUEST_ENTRY_SIZE);
939 pkt->entry_count = req_cnt;
940 pkt->handle = handle;
941 sp->handle = handle;
942
943queuing_error:
944 return pkt;
945}
946
947static void
948qla2x00_start_iocbs(srb_t *sp)
949{
950 struct qla_hw_data *ha = sp->fcport->vha->hw;
951 struct req_que *req = ha->req_q_map[0];
952 device_reg_t __iomem *reg = ISP_QUE_REG(ha, req->id);
953 struct device_reg_2xxx __iomem *ioreg = &ha->iobase->isp;
954
Giridhar Malavalia9083012010-04-12 17:59:55 -0700955 if (IS_QLA82XX(ha)) {
956 qla82xx_start_iocbs(sp);
Andrew Vasquezac280b62009-08-20 11:06:05 -0700957 } else {
Giridhar Malavalia9083012010-04-12 17:59:55 -0700958 /* Adjust ring index. */
959 req->ring_index++;
960 if (req->ring_index == req->length) {
961 req->ring_index = 0;
962 req->ring_ptr = req->ring;
963 } else
964 req->ring_ptr++;
965
966 /* Set chip new ring index. */
967 if (ha->mqenable) {
968 WRT_REG_DWORD(&reg->isp25mq.req_q_in, req->ring_index);
969 RD_REG_DWORD(&ioreg->hccr);
970 } else if (IS_QLA82XX(ha)) {
971 qla82xx_start_iocbs(sp);
972 } else if (IS_FWI2_CAPABLE(ha)) {
973 WRT_REG_DWORD(&reg->isp24.req_q_in, req->ring_index);
974 RD_REG_DWORD_RELAXED(&reg->isp24.req_q_in);
975 } else {
976 WRT_REG_WORD(ISP_REQ_Q_IN(ha, &reg->isp),
977 req->ring_index);
978 RD_REG_WORD_RELAXED(ISP_REQ_Q_IN(ha, &reg->isp));
979 }
Andrew Vasquezac280b62009-08-20 11:06:05 -0700980 }
981}
982
983static void
984qla24xx_login_iocb(srb_t *sp, struct logio_entry_24xx *logio)
985{
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700986 struct srb_ctx *ctx = sp->ctx;
987 struct srb_iocb *lio = ctx->u.iocb_cmd;
Andrew Vasquezac280b62009-08-20 11:06:05 -0700988
989 logio->entry_type = LOGINOUT_PORT_IOCB_TYPE;
990 logio->control_flags = cpu_to_le16(LCF_COMMAND_PLOGI);
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700991 if (lio->u.logio.flags & SRB_LOGIN_COND_PLOGI)
Andrew Vasquezac280b62009-08-20 11:06:05 -0700992 logio->control_flags |= cpu_to_le16(LCF_COND_PLOGI);
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700993 if (lio->u.logio.flags & SRB_LOGIN_SKIP_PRLI)
Andrew Vasquezac280b62009-08-20 11:06:05 -0700994 logio->control_flags |= cpu_to_le16(LCF_SKIP_PRLI);
995 logio->nport_handle = cpu_to_le16(sp->fcport->loop_id);
996 logio->port_id[0] = sp->fcport->d_id.b.al_pa;
997 logio->port_id[1] = sp->fcport->d_id.b.area;
998 logio->port_id[2] = sp->fcport->d_id.b.domain;
999 logio->vp_index = sp->fcport->vp_idx;
1000}
1001
1002static void
1003qla2x00_login_iocb(srb_t *sp, struct mbx_entry *mbx)
1004{
1005 struct qla_hw_data *ha = sp->fcport->vha->hw;
Madhuranath Iyengar49163922010-05-04 15:01:28 -07001006 struct srb_ctx *ctx = sp->ctx;
1007 struct srb_iocb *lio = ctx->u.iocb_cmd;
Andrew Vasquezac280b62009-08-20 11:06:05 -07001008 uint16_t opts;
1009
1010 mbx->entry_type = MBX_IOCB_TYPE;;
1011 SET_TARGET_ID(ha, mbx->loop_id, sp->fcport->loop_id);
1012 mbx->mb0 = cpu_to_le16(MBC_LOGIN_FABRIC_PORT);
Madhuranath Iyengar49163922010-05-04 15:01:28 -07001013 opts = lio->u.logio.flags & SRB_LOGIN_COND_PLOGI ? BIT_0 : 0;
1014 opts |= lio->u.logio.flags & SRB_LOGIN_SKIP_PRLI ? BIT_1 : 0;
Andrew Vasquezac280b62009-08-20 11:06:05 -07001015 if (HAS_EXTENDED_IDS(ha)) {
1016 mbx->mb1 = cpu_to_le16(sp->fcport->loop_id);
1017 mbx->mb10 = cpu_to_le16(opts);
1018 } else {
1019 mbx->mb1 = cpu_to_le16((sp->fcport->loop_id << 8) | opts);
1020 }
1021 mbx->mb2 = cpu_to_le16(sp->fcport->d_id.b.domain);
1022 mbx->mb3 = cpu_to_le16(sp->fcport->d_id.b.area << 8 |
1023 sp->fcport->d_id.b.al_pa);
1024 mbx->mb9 = cpu_to_le16(sp->fcport->vp_idx);
1025}
1026
1027static void
1028qla24xx_logout_iocb(srb_t *sp, struct logio_entry_24xx *logio)
1029{
1030 logio->entry_type = LOGINOUT_PORT_IOCB_TYPE;
1031 logio->control_flags =
1032 cpu_to_le16(LCF_COMMAND_LOGO|LCF_IMPL_LOGO);
1033 logio->nport_handle = cpu_to_le16(sp->fcport->loop_id);
1034 logio->port_id[0] = sp->fcport->d_id.b.al_pa;
1035 logio->port_id[1] = sp->fcport->d_id.b.area;
1036 logio->port_id[2] = sp->fcport->d_id.b.domain;
1037 logio->vp_index = sp->fcport->vp_idx;
1038}
1039
1040static void
1041qla2x00_logout_iocb(srb_t *sp, struct mbx_entry *mbx)
1042{
1043 struct qla_hw_data *ha = sp->fcport->vha->hw;
1044
1045 mbx->entry_type = MBX_IOCB_TYPE;;
1046 SET_TARGET_ID(ha, mbx->loop_id, sp->fcport->loop_id);
1047 mbx->mb0 = cpu_to_le16(MBC_LOGOUT_FABRIC_PORT);
1048 mbx->mb1 = HAS_EXTENDED_IDS(ha) ?
1049 cpu_to_le16(sp->fcport->loop_id):
1050 cpu_to_le16(sp->fcport->loop_id << 8);
1051 mbx->mb2 = cpu_to_le16(sp->fcport->d_id.b.domain);
1052 mbx->mb3 = cpu_to_le16(sp->fcport->d_id.b.area << 8 |
1053 sp->fcport->d_id.b.al_pa);
1054 mbx->mb9 = cpu_to_le16(sp->fcport->vp_idx);
1055 /* Implicit: mbx->mbx10 = 0. */
1056}
1057
Giridhar Malavali9a069e12010-01-12 13:02:47 -08001058static void
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07001059qla24xx_adisc_iocb(srb_t *sp, struct logio_entry_24xx *logio)
1060{
1061 logio->entry_type = LOGINOUT_PORT_IOCB_TYPE;
1062 logio->control_flags = cpu_to_le16(LCF_COMMAND_ADISC);
1063 logio->nport_handle = cpu_to_le16(sp->fcport->loop_id);
1064 logio->vp_index = sp->fcport->vp_idx;
1065}
1066
1067static void
1068qla2x00_adisc_iocb(srb_t *sp, struct mbx_entry *mbx)
1069{
1070 struct qla_hw_data *ha = sp->fcport->vha->hw;
1071
1072 mbx->entry_type = MBX_IOCB_TYPE;
1073 SET_TARGET_ID(ha, mbx->loop_id, sp->fcport->loop_id);
1074 mbx->mb0 = cpu_to_le16(MBC_GET_PORT_DATABASE);
1075 if (HAS_EXTENDED_IDS(ha)) {
1076 mbx->mb1 = cpu_to_le16(sp->fcport->loop_id);
1077 mbx->mb10 = cpu_to_le16(BIT_0);
1078 } else {
1079 mbx->mb1 = cpu_to_le16((sp->fcport->loop_id << 8) | BIT_0);
1080 }
1081 mbx->mb2 = cpu_to_le16(MSW(ha->async_pd_dma));
1082 mbx->mb3 = cpu_to_le16(LSW(ha->async_pd_dma));
1083 mbx->mb6 = cpu_to_le16(MSW(MSD(ha->async_pd_dma)));
1084 mbx->mb7 = cpu_to_le16(LSW(MSD(ha->async_pd_dma)));
1085 mbx->mb9 = cpu_to_le16(sp->fcport->vp_idx);
1086}
1087
1088static void
Giridhar Malavali9a069e12010-01-12 13:02:47 -08001089qla24xx_els_iocb(srb_t *sp, struct els_entry_24xx *els_iocb)
1090{
Madhuranath Iyengar49163922010-05-04 15:01:28 -07001091 struct fc_bsg_job *bsg_job = ((struct srb_ctx *)sp->ctx)->u.bsg_job;
Giridhar Malavali9a069e12010-01-12 13:02:47 -08001092
1093 els_iocb->entry_type = ELS_IOCB_TYPE;
1094 els_iocb->entry_count = 1;
1095 els_iocb->sys_define = 0;
1096 els_iocb->entry_status = 0;
1097 els_iocb->handle = sp->handle;
1098 els_iocb->nport_handle = cpu_to_le16(sp->fcport->loop_id);
1099 els_iocb->tx_dsd_count = __constant_cpu_to_le16(bsg_job->request_payload.sg_cnt);
1100 els_iocb->vp_index = sp->fcport->vp_idx;
1101 els_iocb->sof_type = EST_SOFI3;
1102 els_iocb->rx_dsd_count = __constant_cpu_to_le16(bsg_job->reply_payload.sg_cnt);
1103
Madhuranath Iyengar49163922010-05-04 15:01:28 -07001104 els_iocb->opcode =
1105 (((struct srb_ctx *)sp->ctx)->type == SRB_ELS_CMD_RPT) ?
1106 bsg_job->request->rqst_data.r_els.els_code :
1107 bsg_job->request->rqst_data.h_els.command_code;
Giridhar Malavali9a069e12010-01-12 13:02:47 -08001108 els_iocb->port_id[0] = sp->fcport->d_id.b.al_pa;
1109 els_iocb->port_id[1] = sp->fcport->d_id.b.area;
1110 els_iocb->port_id[2] = sp->fcport->d_id.b.domain;
1111 els_iocb->control_flags = 0;
1112 els_iocb->rx_byte_count =
1113 cpu_to_le32(bsg_job->reply_payload.payload_len);
1114 els_iocb->tx_byte_count =
1115 cpu_to_le32(bsg_job->request_payload.payload_len);
1116
1117 els_iocb->tx_address[0] = cpu_to_le32(LSD(sg_dma_address
1118 (bsg_job->request_payload.sg_list)));
1119 els_iocb->tx_address[1] = cpu_to_le32(MSD(sg_dma_address
1120 (bsg_job->request_payload.sg_list)));
1121 els_iocb->tx_len = cpu_to_le32(sg_dma_len
1122 (bsg_job->request_payload.sg_list));
1123
1124 els_iocb->rx_address[0] = cpu_to_le32(LSD(sg_dma_address
1125 (bsg_job->reply_payload.sg_list)));
1126 els_iocb->rx_address[1] = cpu_to_le32(MSD(sg_dma_address
1127 (bsg_job->reply_payload.sg_list)));
1128 els_iocb->rx_len = cpu_to_le32(sg_dma_len
1129 (bsg_job->reply_payload.sg_list));
1130}
1131
1132static void
1133qla24xx_ct_iocb(srb_t *sp, struct ct_entry_24xx *ct_iocb)
1134{
1135 uint16_t avail_dsds;
1136 uint32_t *cur_dsd;
1137 struct scatterlist *sg;
1138 int index;
1139 uint16_t tot_dsds;
1140 scsi_qla_host_t *vha = sp->fcport->vha;
Madhuranath Iyengar49163922010-05-04 15:01:28 -07001141 struct fc_bsg_job *bsg_job = ((struct srb_ctx *)sp->ctx)->u.bsg_job;
Giridhar Malavali9a069e12010-01-12 13:02:47 -08001142 int loop_iterartion = 0;
1143 int cont_iocb_prsnt = 0;
1144 int entry_count = 1;
1145
1146 ct_iocb->entry_type = CT_IOCB_TYPE;
1147 ct_iocb->entry_status = 0;
1148 ct_iocb->sys_define = 0;
1149 ct_iocb->handle = sp->handle;
1150
1151 ct_iocb->nport_handle = cpu_to_le16(sp->fcport->loop_id);
1152 ct_iocb->vp_index = sp->fcport->vp_idx;
1153 ct_iocb->comp_status = __constant_cpu_to_le16(0);
1154
1155 ct_iocb->cmd_dsd_count =
1156 __constant_cpu_to_le16(bsg_job->request_payload.sg_cnt);
1157 ct_iocb->timeout = 0;
1158 ct_iocb->rsp_dsd_count =
1159 __constant_cpu_to_le16(bsg_job->reply_payload.sg_cnt);
1160 ct_iocb->rsp_byte_count =
1161 cpu_to_le32(bsg_job->reply_payload.payload_len);
1162 ct_iocb->cmd_byte_count =
1163 cpu_to_le32(bsg_job->request_payload.payload_len);
1164 ct_iocb->dseg_0_address[0] = cpu_to_le32(LSD(sg_dma_address
1165 (bsg_job->request_payload.sg_list)));
1166 ct_iocb->dseg_0_address[1] = cpu_to_le32(MSD(sg_dma_address
1167 (bsg_job->request_payload.sg_list)));
1168 ct_iocb->dseg_0_len = cpu_to_le32(sg_dma_len
1169 (bsg_job->request_payload.sg_list));
1170
1171 avail_dsds = 1;
1172 cur_dsd = (uint32_t *)ct_iocb->dseg_1_address;
1173 index = 0;
1174 tot_dsds = bsg_job->reply_payload.sg_cnt;
1175
1176 for_each_sg(bsg_job->reply_payload.sg_list, sg, tot_dsds, index) {
1177 dma_addr_t sle_dma;
1178 cont_a64_entry_t *cont_pkt;
1179
1180 /* Allocate additional continuation packets? */
1181 if (avail_dsds == 0) {
1182 /*
1183 * Five DSDs are available in the Cont.
1184 * Type 1 IOCB.
1185 */
1186 cont_pkt = qla2x00_prep_cont_type1_iocb(vha);
1187 cur_dsd = (uint32_t *) cont_pkt->dseg_0_address;
1188 avail_dsds = 5;
1189 cont_iocb_prsnt = 1;
1190 entry_count++;
1191 }
1192
1193 sle_dma = sg_dma_address(sg);
1194 *cur_dsd++ = cpu_to_le32(LSD(sle_dma));
1195 *cur_dsd++ = cpu_to_le32(MSD(sle_dma));
1196 *cur_dsd++ = cpu_to_le32(sg_dma_len(sg));
1197 loop_iterartion++;
1198 avail_dsds--;
1199 }
1200 ct_iocb->entry_count = entry_count;
1201}
1202
Andrew Vasquezac280b62009-08-20 11:06:05 -07001203int
1204qla2x00_start_sp(srb_t *sp)
1205{
1206 int rval;
1207 struct qla_hw_data *ha = sp->fcport->vha->hw;
1208 void *pkt;
1209 struct srb_ctx *ctx = sp->ctx;
1210 unsigned long flags;
1211
1212 rval = QLA_FUNCTION_FAILED;
1213 spin_lock_irqsave(&ha->hardware_lock, flags);
1214 pkt = qla2x00_alloc_iocbs(sp);
1215 if (!pkt)
1216 goto done;
1217
1218 rval = QLA_SUCCESS;
1219 switch (ctx->type) {
1220 case SRB_LOGIN_CMD:
1221 IS_FWI2_CAPABLE(ha) ?
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07001222 qla24xx_login_iocb(sp, pkt) :
Andrew Vasquezac280b62009-08-20 11:06:05 -07001223 qla2x00_login_iocb(sp, pkt);
1224 break;
1225 case SRB_LOGOUT_CMD:
1226 IS_FWI2_CAPABLE(ha) ?
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07001227 qla24xx_logout_iocb(sp, pkt) :
Andrew Vasquezac280b62009-08-20 11:06:05 -07001228 qla2x00_logout_iocb(sp, pkt);
1229 break;
Giridhar Malavali9a069e12010-01-12 13:02:47 -08001230 case SRB_ELS_CMD_RPT:
1231 case SRB_ELS_CMD_HST:
1232 qla24xx_els_iocb(sp, pkt);
1233 break;
1234 case SRB_CT_CMD:
1235 qla24xx_ct_iocb(sp, pkt);
1236 break;
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07001237 case SRB_ADISC_CMD:
1238 IS_FWI2_CAPABLE(ha) ?
1239 qla24xx_adisc_iocb(sp, pkt) :
1240 qla2x00_adisc_iocb(sp, pkt);
1241 break;
Andrew Vasquezac280b62009-08-20 11:06:05 -07001242 default:
1243 break;
1244 }
1245
1246 wmb();
1247 qla2x00_start_iocbs(sp);
1248done:
1249 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1250 return rval;
1251}