blob: 09ad3ce60064ebc7939e1f08d31e585e25b5f478 [file] [log] [blame]
Andrew Vasquezfa90c542005-10-27 11:10:08 -07001/*
2 * QLogic Fibre Channel HBA Driver
Andrew Vasquez07e264b2011-03-30 11:46:23 -07003 * Copyright (c) 2003-2011 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 void qla2x00_isp_cmd(struct scsi_qla_host *, struct req_que *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070015
Anirban Chakraborty59e0b8b2009-06-03 09:55:19 -070016static void qla25xx_set_que(srb_t *, struct rsp_que **);
Linus Torvalds1da177e2005-04-16 15:20:36 -070017/**
18 * qla2x00_get_cmd_direction() - Determine control_flag data direction.
19 * @cmd: SCSI command
20 *
21 * Returns the proper CF_* direction based on CDB.
22 */
23static inline uint16_t
Harish Zunjarrao49fd4622008-09-11 21:22:47 -070024qla2x00_get_cmd_direction(srb_t *sp)
Linus Torvalds1da177e2005-04-16 15:20:36 -070025{
26 uint16_t cflags;
27
28 cflags = 0;
29
30 /* Set transfer direction */
Harish Zunjarrao49fd4622008-09-11 21:22:47 -070031 if (sp->cmd->sc_data_direction == DMA_TO_DEVICE) {
Linus Torvalds1da177e2005-04-16 15:20:36 -070032 cflags = CF_WRITE;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -080033 sp->fcport->vha->hw->qla_stats.output_bytes +=
Harish Zunjarrao49fd4622008-09-11 21:22:47 -070034 scsi_bufflen(sp->cmd);
35 } else if (sp->cmd->sc_data_direction == DMA_FROM_DEVICE) {
Linus Torvalds1da177e2005-04-16 15:20:36 -070036 cflags = CF_READ;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -080037 sp->fcport->vha->hw->qla_stats.input_bytes +=
Harish Zunjarrao49fd4622008-09-11 21:22:47 -070038 scsi_bufflen(sp->cmd);
39 }
Linus Torvalds1da177e2005-04-16 15:20:36 -070040 return (cflags);
41}
42
43/**
44 * qla2x00_calc_iocbs_32() - Determine number of Command Type 2 and
45 * Continuation Type 0 IOCBs to allocate.
46 *
47 * @dsds: number of data segment decriptors needed
48 *
49 * Returns the number of IOCB entries needed to store @dsds.
50 */
51uint16_t
52qla2x00_calc_iocbs_32(uint16_t dsds)
53{
54 uint16_t iocbs;
55
56 iocbs = 1;
57 if (dsds > 3) {
58 iocbs += (dsds - 3) / 7;
59 if ((dsds - 3) % 7)
60 iocbs++;
61 }
62 return (iocbs);
63}
64
65/**
66 * qla2x00_calc_iocbs_64() - Determine number of Command Type 3 and
67 * Continuation Type 1 IOCBs to allocate.
68 *
69 * @dsds: number of data segment decriptors needed
70 *
71 * Returns the number of IOCB entries needed to store @dsds.
72 */
73uint16_t
74qla2x00_calc_iocbs_64(uint16_t dsds)
75{
76 uint16_t iocbs;
77
78 iocbs = 1;
79 if (dsds > 2) {
80 iocbs += (dsds - 2) / 5;
81 if ((dsds - 2) % 5)
82 iocbs++;
83 }
84 return (iocbs);
85}
86
87/**
88 * qla2x00_prep_cont_type0_iocb() - Initialize a Continuation Type 0 IOCB.
89 * @ha: HA context
90 *
91 * Returns a pointer to the Continuation Type 0 IOCB packet.
92 */
93static inline cont_entry_t *
Anirban Chakraborty67c2e932009-04-06 22:33:42 -070094qla2x00_prep_cont_type0_iocb(struct scsi_qla_host *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -070095{
96 cont_entry_t *cont_pkt;
Anirban Chakraborty67c2e932009-04-06 22:33:42 -070097 struct req_que *req = vha->req;
Linus Torvalds1da177e2005-04-16 15:20:36 -070098 /* Adjust ring index. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -080099 req->ring_index++;
100 if (req->ring_index == req->length) {
101 req->ring_index = 0;
102 req->ring_ptr = req->ring;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700103 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800104 req->ring_ptr++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700105 }
106
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800107 cont_pkt = (cont_entry_t *)req->ring_ptr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700108
109 /* Load packet defaults. */
110 *((uint32_t *)(&cont_pkt->entry_type)) =
111 __constant_cpu_to_le32(CONTINUE_TYPE);
112
113 return (cont_pkt);
114}
115
116/**
117 * qla2x00_prep_cont_type1_iocb() - Initialize a Continuation Type 1 IOCB.
118 * @ha: HA context
119 *
120 * Returns a pointer to the continuation type 1 IOCB packet.
121 */
122static inline cont_a64_entry_t *
Anirban Chakraborty67c2e932009-04-06 22:33:42 -0700123qla2x00_prep_cont_type1_iocb(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124{
125 cont_a64_entry_t *cont_pkt;
126
Anirban Chakraborty67c2e932009-04-06 22:33:42 -0700127 struct req_que *req = vha->req;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700128 /* Adjust ring index. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800129 req->ring_index++;
130 if (req->ring_index == req->length) {
131 req->ring_index = 0;
132 req->ring_ptr = req->ring;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700133 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800134 req->ring_ptr++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700135 }
136
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800137 cont_pkt = (cont_a64_entry_t *)req->ring_ptr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700138
139 /* Load packet defaults. */
140 *((uint32_t *)(&cont_pkt->entry_type)) =
141 __constant_cpu_to_le32(CONTINUE_A64_TYPE);
142
143 return (cont_pkt);
144}
145
Arun Easibad75002010-05-04 15:01:30 -0700146static inline int
147qla24xx_configure_prot_mode(srb_t *sp, uint16_t *fw_prot_opts)
148{
149 uint8_t guard = scsi_host_get_guard(sp->cmd->device->host);
150
151 /* We only support T10 DIF right now */
152 if (guard != SHOST_DIX_GUARD_CRC) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700153 ql_dbg(ql_dbg_io, sp->fcport->vha, 0x3007,
154 "Unsupported guard: %d for cmd=%p.\n", guard, sp->cmd);
Arun Easibad75002010-05-04 15:01:30 -0700155 return 0;
156 }
157
158 /* We always use DIFF Bundling for best performance */
159 *fw_prot_opts = 0;
160
161 /* Translate SCSI opcode to a protection opcode */
162 switch (scsi_get_prot_op(sp->cmd)) {
163 case SCSI_PROT_READ_STRIP:
164 *fw_prot_opts |= PO_MODE_DIF_REMOVE;
165 break;
166 case SCSI_PROT_WRITE_INSERT:
167 *fw_prot_opts |= PO_MODE_DIF_INSERT;
168 break;
169 case SCSI_PROT_READ_INSERT:
170 *fw_prot_opts |= PO_MODE_DIF_INSERT;
171 break;
172 case SCSI_PROT_WRITE_STRIP:
173 *fw_prot_opts |= PO_MODE_DIF_REMOVE;
174 break;
175 case SCSI_PROT_READ_PASS:
176 *fw_prot_opts |= PO_MODE_DIF_PASS;
177 break;
178 case SCSI_PROT_WRITE_PASS:
179 *fw_prot_opts |= PO_MODE_DIF_PASS;
180 break;
181 default: /* Normal Request */
182 *fw_prot_opts |= PO_MODE_DIF_PASS;
183 break;
184 }
185
186 return scsi_prot_sg_count(sp->cmd);
187}
188
189/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700190 * qla2x00_build_scsi_iocbs_32() - Build IOCB command utilizing 32bit
191 * capable IOCB types.
192 *
193 * @sp: SRB command to process
194 * @cmd_pkt: Command type 2 IOCB
195 * @tot_dsds: Total number of segments to transfer
196 */
197void qla2x00_build_scsi_iocbs_32(srb_t *sp, cmd_entry_t *cmd_pkt,
198 uint16_t tot_dsds)
199{
200 uint16_t avail_dsds;
201 uint32_t *cur_dsd;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800202 scsi_qla_host_t *vha;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700203 struct scsi_cmnd *cmd;
FUJITA Tomonori385d70b2007-05-26 01:55:38 +0900204 struct scatterlist *sg;
205 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700206
207 cmd = sp->cmd;
208
209 /* Update entry type to indicate Command Type 2 IOCB */
210 *((uint32_t *)(&cmd_pkt->entry_type)) =
211 __constant_cpu_to_le32(COMMAND_TYPE);
212
213 /* No data transfer */
FUJITA Tomonori385d70b2007-05-26 01:55:38 +0900214 if (!scsi_bufflen(cmd) || cmd->sc_data_direction == DMA_NONE) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700215 cmd_pkt->byte_count = __constant_cpu_to_le32(0);
216 return;
217 }
218
Andrew Vasquez444786d2009-01-05 11:18:10 -0800219 vha = sp->fcport->vha;
Harish Zunjarrao49fd4622008-09-11 21:22:47 -0700220 cmd_pkt->control_flags |= cpu_to_le16(qla2x00_get_cmd_direction(sp));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700221
222 /* Three DSDs are available in the Command Type 2 IOCB */
223 avail_dsds = 3;
224 cur_dsd = (uint32_t *)&cmd_pkt->dseg_0_address;
225
226 /* Load data segments */
FUJITA Tomonori385d70b2007-05-26 01:55:38 +0900227 scsi_for_each_sg(cmd, sg, tot_dsds, i) {
228 cont_entry_t *cont_pkt;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700229
FUJITA Tomonori385d70b2007-05-26 01:55:38 +0900230 /* Allocate additional continuation packets? */
231 if (avail_dsds == 0) {
232 /*
233 * Seven DSDs are available in the Continuation
234 * Type 0 IOCB.
235 */
Anirban Chakraborty67c2e932009-04-06 22:33:42 -0700236 cont_pkt = qla2x00_prep_cont_type0_iocb(vha);
FUJITA Tomonori385d70b2007-05-26 01:55:38 +0900237 cur_dsd = (uint32_t *)&cont_pkt->dseg_0_address;
238 avail_dsds = 7;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700239 }
FUJITA Tomonori385d70b2007-05-26 01:55:38 +0900240
241 *cur_dsd++ = cpu_to_le32(sg_dma_address(sg));
242 *cur_dsd++ = cpu_to_le32(sg_dma_len(sg));
243 avail_dsds--;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700244 }
245}
246
247/**
248 * qla2x00_build_scsi_iocbs_64() - Build IOCB command utilizing 64bit
249 * capable IOCB types.
250 *
251 * @sp: SRB command to process
252 * @cmd_pkt: Command type 3 IOCB
253 * @tot_dsds: Total number of segments to transfer
254 */
255void qla2x00_build_scsi_iocbs_64(srb_t *sp, cmd_entry_t *cmd_pkt,
256 uint16_t tot_dsds)
257{
258 uint16_t avail_dsds;
259 uint32_t *cur_dsd;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800260 scsi_qla_host_t *vha;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700261 struct scsi_cmnd *cmd;
FUJITA Tomonori385d70b2007-05-26 01:55:38 +0900262 struct scatterlist *sg;
263 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700264
265 cmd = sp->cmd;
266
267 /* Update entry type to indicate Command Type 3 IOCB */
268 *((uint32_t *)(&cmd_pkt->entry_type)) =
269 __constant_cpu_to_le32(COMMAND_A64_TYPE);
270
271 /* No data transfer */
FUJITA Tomonori385d70b2007-05-26 01:55:38 +0900272 if (!scsi_bufflen(cmd) || cmd->sc_data_direction == DMA_NONE) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700273 cmd_pkt->byte_count = __constant_cpu_to_le32(0);
274 return;
275 }
276
Andrew Vasquez444786d2009-01-05 11:18:10 -0800277 vha = sp->fcport->vha;
Harish Zunjarrao49fd4622008-09-11 21:22:47 -0700278 cmd_pkt->control_flags |= cpu_to_le16(qla2x00_get_cmd_direction(sp));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700279
280 /* Two DSDs are available in the Command Type 3 IOCB */
281 avail_dsds = 2;
282 cur_dsd = (uint32_t *)&cmd_pkt->dseg_0_address;
283
284 /* Load data segments */
FUJITA Tomonori385d70b2007-05-26 01:55:38 +0900285 scsi_for_each_sg(cmd, sg, tot_dsds, i) {
286 dma_addr_t sle_dma;
287 cont_a64_entry_t *cont_pkt;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700288
FUJITA Tomonori385d70b2007-05-26 01:55:38 +0900289 /* Allocate additional continuation packets? */
290 if (avail_dsds == 0) {
291 /*
292 * Five DSDs are available in the Continuation
293 * Type 1 IOCB.
294 */
Anirban Chakraborty67c2e932009-04-06 22:33:42 -0700295 cont_pkt = qla2x00_prep_cont_type1_iocb(vha);
FUJITA Tomonori385d70b2007-05-26 01:55:38 +0900296 cur_dsd = (uint32_t *)cont_pkt->dseg_0_address;
297 avail_dsds = 5;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700298 }
FUJITA Tomonori385d70b2007-05-26 01:55:38 +0900299
300 sle_dma = sg_dma_address(sg);
301 *cur_dsd++ = cpu_to_le32(LSD(sle_dma));
302 *cur_dsd++ = cpu_to_le32(MSD(sle_dma));
303 *cur_dsd++ = cpu_to_le32(sg_dma_len(sg));
304 avail_dsds--;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700305 }
306}
307
308/**
309 * qla2x00_start_scsi() - Send a SCSI command to the ISP
310 * @sp: command to send to the ISP
311 *
Bjorn Helgaascc3ef7b2008-09-11 21:22:51 -0700312 * Returns non-zero if a failure occurred, else zero.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700313 */
314int
315qla2x00_start_scsi(srb_t *sp)
316{
FUJITA Tomonori385d70b2007-05-26 01:55:38 +0900317 int ret, nseg;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700318 unsigned long flags;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800319 scsi_qla_host_t *vha;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700320 struct scsi_cmnd *cmd;
321 uint32_t *clr_ptr;
322 uint32_t index;
323 uint32_t handle;
324 cmd_entry_t *cmd_pkt;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700325 uint16_t cnt;
326 uint16_t req_cnt;
327 uint16_t tot_dsds;
Andrew Vasquez3d716442005-07-06 10:30:26 -0700328 struct device_reg_2xxx __iomem *reg;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800329 struct qla_hw_data *ha;
330 struct req_que *req;
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800331 struct rsp_que *rsp;
Andrew Vasquezff2fc422011-02-23 15:27:15 -0800332 char tag[2];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700333
334 /* Setup device pointers. */
335 ret = 0;
Andrew Vasquez444786d2009-01-05 11:18:10 -0800336 vha = sp->fcport->vha;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800337 ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -0700338 reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700339 cmd = sp->cmd;
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800340 req = ha->req_q_map[0];
341 rsp = ha->rsp_q_map[0];
83021922005-04-17 15:10:41 -0500342 /* So we know we haven't pci_map'ed anything yet */
343 tot_dsds = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700344
345 /* Send marker if required */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800346 if (vha->marker_needed != 0) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700347 if (qla2x00_marker(vha, req, rsp, 0, 0, MK_SYNC_ALL) !=
348 QLA_SUCCESS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700349 return (QLA_FUNCTION_FAILED);
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700350 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800351 vha->marker_needed = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700352 }
353
354 /* Acquire ring specific lock */
Andrew Vasquezc9c5ced2008-07-24 08:31:49 -0700355 spin_lock_irqsave(&ha->hardware_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700356
357 /* Check for room in outstanding command list. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800358 handle = req->current_outstanding_cmd;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700359 for (index = 1; index < MAX_OUTSTANDING_COMMANDS; index++) {
360 handle++;
361 if (handle == MAX_OUTSTANDING_COMMANDS)
362 handle = 1;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800363 if (!req->outstanding_cmds[handle])
Linus Torvalds1da177e2005-04-16 15:20:36 -0700364 break;
365 }
366 if (index == MAX_OUTSTANDING_COMMANDS)
367 goto queuing_error;
368
83021922005-04-17 15:10:41 -0500369 /* Map the sg table so we have an accurate count of sg entries needed */
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700370 if (scsi_sg_count(cmd)) {
371 nseg = dma_map_sg(&ha->pdev->dev, scsi_sglist(cmd),
372 scsi_sg_count(cmd), cmd->sc_data_direction);
373 if (unlikely(!nseg))
374 goto queuing_error;
375 } else
376 nseg = 0;
377
FUJITA Tomonori385d70b2007-05-26 01:55:38 +0900378 tot_dsds = nseg;
83021922005-04-17 15:10:41 -0500379
Linus Torvalds1da177e2005-04-16 15:20:36 -0700380 /* Calculate the number of request entries needed. */
Andrew Vasquezfd34f552007-07-19 15:06:00 -0700381 req_cnt = ha->isp_ops->calc_req_entries(tot_dsds);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800382 if (req->cnt < (req_cnt + 2)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700383 cnt = RD_REG_WORD_RELAXED(ISP_REQ_Q_OUT(ha, reg));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800384 if (req->ring_index < cnt)
385 req->cnt = cnt - req->ring_index;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700386 else
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800387 req->cnt = req->length -
388 (req->ring_index - cnt);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700389 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800390 if (req->cnt < (req_cnt + 2))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700391 goto queuing_error;
392
Linus Torvalds1da177e2005-04-16 15:20:36 -0700393 /* Build command packet */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800394 req->current_outstanding_cmd = handle;
395 req->outstanding_cmds[handle] = sp;
Andrew Vasquezcf53b062009-08-20 11:06:04 -0700396 sp->handle = handle;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700397 sp->cmd->host_scribble = (unsigned char *)(unsigned long)handle;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800398 req->cnt -= req_cnt;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700399
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800400 cmd_pkt = (cmd_entry_t *)req->ring_ptr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700401 cmd_pkt->handle = handle;
402 /* Zero out remaining portion of packet. */
403 clr_ptr = (uint32_t *)cmd_pkt + 2;
404 memset(clr_ptr, 0, REQUEST_ENTRY_SIZE - 8);
405 cmd_pkt->dseg_count = cpu_to_le16(tot_dsds);
406
bdf79622005-04-17 15:06:53 -0500407 /* Set target ID and LUN number*/
408 SET_TARGET_ID(ha, cmd_pkt->target, sp->fcport->loop_id);
409 cmd_pkt->lun = cpu_to_le16(sp->cmd->device->lun);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700410
411 /* Update tagged queuing modifier */
Andrew Vasquezff2fc422011-02-23 15:27:15 -0800412 if (scsi_populate_tag_msg(cmd, tag)) {
413 switch (tag[0]) {
414 case HEAD_OF_QUEUE_TAG:
415 cmd_pkt->control_flags =
416 __constant_cpu_to_le16(CF_HEAD_TAG);
417 break;
418 case ORDERED_QUEUE_TAG:
419 cmd_pkt->control_flags =
420 __constant_cpu_to_le16(CF_ORDERED_TAG);
421 break;
422 default:
423 cmd_pkt->control_flags =
424 __constant_cpu_to_le16(CF_SIMPLE_TAG);
425 break;
426 }
427 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700428
Linus Torvalds1da177e2005-04-16 15:20:36 -0700429 /* Load SCSI command packet. */
430 memcpy(cmd_pkt->scsi_cdb, cmd->cmnd, cmd->cmd_len);
FUJITA Tomonori385d70b2007-05-26 01:55:38 +0900431 cmd_pkt->byte_count = cpu_to_le32((uint32_t)scsi_bufflen(cmd));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700432
433 /* Build IOCB segments */
Andrew Vasquezfd34f552007-07-19 15:06:00 -0700434 ha->isp_ops->build_iocbs(sp, cmd_pkt, tot_dsds);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700435
436 /* Set total data segment count. */
437 cmd_pkt->entry_count = (uint8_t)req_cnt;
438 wmb();
439
440 /* Adjust ring index. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800441 req->ring_index++;
442 if (req->ring_index == req->length) {
443 req->ring_index = 0;
444 req->ring_ptr = req->ring;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700445 } else
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800446 req->ring_ptr++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700447
Linus Torvalds1da177e2005-04-16 15:20:36 -0700448 sp->flags |= SRB_DMA_VALID;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700449
450 /* Set chip new ring index. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800451 WRT_REG_WORD(ISP_REQ_Q_IN(ha, reg), req->ring_index);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700452 RD_REG_WORD_RELAXED(ISP_REQ_Q_IN(ha, reg)); /* PCI Posting. */
453
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -0700454 /* Manage unprocessed RIO/ZIO commands in response queue. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800455 if (vha->flags.process_response_queue &&
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800456 rsp->ring_ptr->signature != RESPONSE_PROCESSED)
457 qla2x00_process_response_queue(rsp);
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -0700458
Andrew Vasquezc9c5ced2008-07-24 08:31:49 -0700459 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700460 return (QLA_SUCCESS);
461
462queuing_error:
FUJITA Tomonori385d70b2007-05-26 01:55:38 +0900463 if (tot_dsds)
464 scsi_dma_unmap(cmd);
465
Andrew Vasquezc9c5ced2008-07-24 08:31:49 -0700466 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700467
468 return (QLA_FUNCTION_FAILED);
469}
470
471/**
472 * qla2x00_marker() - Send a marker IOCB to the firmware.
473 * @ha: HA context
474 * @loop_id: loop ID
475 * @lun: LUN
476 * @type: marker modifier
477 *
478 * Can be called from both normal and interrupt context.
479 *
Bjorn Helgaascc3ef7b2008-09-11 21:22:51 -0700480 * Returns non-zero if a failure occurred, else zero.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700481 */
Andrew Vasquez3dbe7562010-07-23 15:28:37 +0500482static int
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800483__qla2x00_marker(struct scsi_qla_host *vha, struct req_que *req,
484 struct rsp_que *rsp, uint16_t loop_id,
485 uint16_t lun, uint8_t type)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700486{
Andrew Vasquez2b6c0ce2005-07-06 10:31:17 -0700487 mrk_entry_t *mrk;
488 struct mrk_entry_24xx *mrk24;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800489 struct qla_hw_data *ha = vha->hw;
490 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700491
Andrew Vasquez2b6c0ce2005-07-06 10:31:17 -0700492 mrk24 = NULL;
Giridhar Malavalid94d10e2010-07-23 15:28:23 +0500493 mrk = (mrk_entry_t *)qla2x00_alloc_iocbs(vha, 0);
Andrew Vasquez2b6c0ce2005-07-06 10:31:17 -0700494 if (mrk == NULL) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700495 ql_log(ql_log_warn, base_vha, 0x3026,
496 "Failed to allocate Marker IOCB.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700497
498 return (QLA_FUNCTION_FAILED);
499 }
500
Andrew Vasquez2b6c0ce2005-07-06 10:31:17 -0700501 mrk->entry_type = MARKER_TYPE;
502 mrk->modifier = type;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700503 if (type != MK_SYNC_ALL) {
Andrew Vasqueze4289242007-07-19 15:05:56 -0700504 if (IS_FWI2_CAPABLE(ha)) {
Andrew Vasquez2b6c0ce2005-07-06 10:31:17 -0700505 mrk24 = (struct mrk_entry_24xx *) mrk;
506 mrk24->nport_handle = cpu_to_le16(loop_id);
507 mrk24->lun[1] = LSB(lun);
508 mrk24->lun[2] = MSB(lun);
Shyam Sundarb797b6d2006-08-01 13:48:13 -0700509 host_to_fcp_swap(mrk24->lun, sizeof(mrk24->lun));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800510 mrk24->vp_index = vha->vp_idx;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700511 mrk24->handle = MAKE_HANDLE(req->id, mrk24->handle);
Andrew Vasquez2b6c0ce2005-07-06 10:31:17 -0700512 } else {
513 SET_TARGET_ID(ha, mrk->target, loop_id);
514 mrk->lun = cpu_to_le16(lun);
515 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700516 }
517 wmb();
518
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800519 qla2x00_isp_cmd(vha, req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700520
521 return (QLA_SUCCESS);
522}
523
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700524int
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800525qla2x00_marker(struct scsi_qla_host *vha, struct req_que *req,
526 struct rsp_que *rsp, uint16_t loop_id, uint16_t lun,
527 uint8_t type)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700528{
529 int ret;
530 unsigned long flags = 0;
531
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800532 spin_lock_irqsave(&vha->hw->hardware_lock, flags);
533 ret = __qla2x00_marker(vha, req, rsp, loop_id, lun, type);
534 spin_unlock_irqrestore(&vha->hw->hardware_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700535
536 return (ret);
537}
538
539/**
Linus Torvalds1da177e2005-04-16 15:20:36 -0700540 * qla2x00_isp_cmd() - Modify the request ring pointer.
541 * @ha: HA context
542 *
543 * Note: The caller must hold the hardware lock before calling this routine.
544 */
Adrian Bunk413975a2006-06-30 02:33:06 -0700545static void
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800546qla2x00_isp_cmd(struct scsi_qla_host *vha, struct req_que *req)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700547{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800548 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800549 device_reg_t __iomem *reg = ISP_QUE_REG(ha, req->id);
Anirban Chakraborty17d98632008-12-18 10:06:15 -0800550 struct device_reg_2xxx __iomem *ioreg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700551
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700552 ql_dbg(ql_dbg_io + ql_dbg_buffer, vha, 0x302d,
553 "IOCB data:\n");
554 ql_dump_buffer(ql_dbg_io + ql_dbg_buffer, vha, 0x302e,
555 (uint8_t *)req->ring_ptr, REQUEST_ENTRY_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700556
557 /* Adjust ring index. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800558 req->ring_index++;
559 if (req->ring_index == req->length) {
560 req->ring_index = 0;
561 req->ring_ptr = req->ring;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700562 } else
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800563 req->ring_ptr++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700564
565 /* Set chip new ring index. */
Giridhar Malavalia9083012010-04-12 17:59:55 -0700566 if (IS_QLA82XX(ha)) {
567 uint32_t dbval = 0x04 | (ha->portnum << 5);
568
569 /* write, read and verify logic */
570 dbval = dbval | (req->id << 8) | (req->ring_index << 16);
571 if (ql2xdbwr)
572 qla82xx_wr_32(ha, ha->nxdb_wr_ptr, dbval);
573 else {
574 WRT_REG_DWORD(
575 (unsigned long __iomem *)ha->nxdb_wr_ptr,
576 dbval);
577 wmb();
578 while (RD_REG_DWORD(ha->nxdb_rd_ptr) != dbval) {
579 WRT_REG_DWORD((unsigned long __iomem *)
580 ha->nxdb_wr_ptr, dbval);
581 wmb();
582 }
583 }
584 } else if (ha->mqenable) {
585 /* Set chip new ring index. */
Anirban Chakraborty17d98632008-12-18 10:06:15 -0800586 WRT_REG_DWORD(&reg->isp25mq.req_q_in, req->ring_index);
587 RD_REG_DWORD(&ioreg->hccr);
Giridhar Malavalia9083012010-04-12 17:59:55 -0700588 } else {
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800589 if (IS_FWI2_CAPABLE(ha)) {
590 WRT_REG_DWORD(&reg->isp24.req_q_in, req->ring_index);
591 RD_REG_DWORD_RELAXED(&reg->isp24.req_q_in);
592 } else {
593 WRT_REG_WORD(ISP_REQ_Q_IN(ha, &reg->isp),
594 req->ring_index);
595 RD_REG_WORD_RELAXED(ISP_REQ_Q_IN(ha, &reg->isp));
596 }
Andrew Vasquez2b6c0ce2005-07-06 10:31:17 -0700597 }
598
599}
600
601/**
602 * qla24xx_calc_iocbs() - Determine number of Command Type 3 and
603 * Continuation Type 1 IOCBs to allocate.
604 *
605 * @dsds: number of data segment decriptors needed
606 *
607 * Returns the number of IOCB entries needed to store @dsds.
608 */
Giridhar Malavalia9083012010-04-12 17:59:55 -0700609inline uint16_t
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700610qla24xx_calc_iocbs(scsi_qla_host_t *vha, uint16_t dsds)
Andrew Vasquez2b6c0ce2005-07-06 10:31:17 -0700611{
612 uint16_t iocbs;
613
614 iocbs = 1;
615 if (dsds > 1) {
616 iocbs += (dsds - 1) / 5;
617 if ((dsds - 1) % 5)
618 iocbs++;
619 }
620 return iocbs;
621}
622
623/**
624 * qla24xx_build_scsi_iocbs() - Build IOCB command utilizing Command Type 7
625 * IOCB types.
626 *
627 * @sp: SRB command to process
628 * @cmd_pkt: Command type 3 IOCB
629 * @tot_dsds: Total number of segments to transfer
630 */
Giridhar Malavalia9083012010-04-12 17:59:55 -0700631inline void
Andrew Vasquez2b6c0ce2005-07-06 10:31:17 -0700632qla24xx_build_scsi_iocbs(srb_t *sp, struct cmd_type_7 *cmd_pkt,
633 uint16_t tot_dsds)
634{
635 uint16_t avail_dsds;
636 uint32_t *cur_dsd;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800637 scsi_qla_host_t *vha;
Andrew Vasquez2b6c0ce2005-07-06 10:31:17 -0700638 struct scsi_cmnd *cmd;
FUJITA Tomonori385d70b2007-05-26 01:55:38 +0900639 struct scatterlist *sg;
640 int i;
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800641 struct req_que *req;
Andrew Vasquez2b6c0ce2005-07-06 10:31:17 -0700642
643 cmd = sp->cmd;
644
645 /* Update entry type to indicate Command Type 3 IOCB */
646 *((uint32_t *)(&cmd_pkt->entry_type)) =
647 __constant_cpu_to_le32(COMMAND_TYPE_7);
648
649 /* No data transfer */
FUJITA Tomonori385d70b2007-05-26 01:55:38 +0900650 if (!scsi_bufflen(cmd) || cmd->sc_data_direction == DMA_NONE) {
Andrew Vasquez2b6c0ce2005-07-06 10:31:17 -0700651 cmd_pkt->byte_count = __constant_cpu_to_le32(0);
652 return;
653 }
654
Andrew Vasquez444786d2009-01-05 11:18:10 -0800655 vha = sp->fcport->vha;
Anirban Chakraborty67c2e932009-04-06 22:33:42 -0700656 req = vha->req;
Andrew Vasquez2b6c0ce2005-07-06 10:31:17 -0700657
658 /* Set transfer direction */
Harish Zunjarrao49fd4622008-09-11 21:22:47 -0700659 if (cmd->sc_data_direction == DMA_TO_DEVICE) {
Andrew Vasquez2b6c0ce2005-07-06 10:31:17 -0700660 cmd_pkt->task_mgmt_flags =
661 __constant_cpu_to_le16(TMF_WRITE_DATA);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800662 sp->fcport->vha->hw->qla_stats.output_bytes +=
Harish Zunjarrao49fd4622008-09-11 21:22:47 -0700663 scsi_bufflen(sp->cmd);
664 } else if (cmd->sc_data_direction == DMA_FROM_DEVICE) {
Andrew Vasquez2b6c0ce2005-07-06 10:31:17 -0700665 cmd_pkt->task_mgmt_flags =
666 __constant_cpu_to_le16(TMF_READ_DATA);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800667 sp->fcport->vha->hw->qla_stats.input_bytes +=
Harish Zunjarrao49fd4622008-09-11 21:22:47 -0700668 scsi_bufflen(sp->cmd);
669 }
Andrew Vasquez2b6c0ce2005-07-06 10:31:17 -0700670
671 /* One DSD is available in the Command Type 3 IOCB */
672 avail_dsds = 1;
673 cur_dsd = (uint32_t *)&cmd_pkt->dseg_0_address;
674
675 /* Load data segments */
Andrew Vasquez2b6c0ce2005-07-06 10:31:17 -0700676
FUJITA Tomonori385d70b2007-05-26 01:55:38 +0900677 scsi_for_each_sg(cmd, sg, tot_dsds, i) {
678 dma_addr_t sle_dma;
679 cont_a64_entry_t *cont_pkt;
Andrew Vasquez2b6c0ce2005-07-06 10:31:17 -0700680
FUJITA Tomonori385d70b2007-05-26 01:55:38 +0900681 /* Allocate additional continuation packets? */
682 if (avail_dsds == 0) {
683 /*
684 * Five DSDs are available in the Continuation
685 * Type 1 IOCB.
686 */
Anirban Chakraborty67c2e932009-04-06 22:33:42 -0700687 cont_pkt = qla2x00_prep_cont_type1_iocb(vha);
FUJITA Tomonori385d70b2007-05-26 01:55:38 +0900688 cur_dsd = (uint32_t *)cont_pkt->dseg_0_address;
689 avail_dsds = 5;
Andrew Vasquez2b6c0ce2005-07-06 10:31:17 -0700690 }
FUJITA Tomonori385d70b2007-05-26 01:55:38 +0900691
692 sle_dma = sg_dma_address(sg);
693 *cur_dsd++ = cpu_to_le32(LSD(sle_dma));
694 *cur_dsd++ = cpu_to_le32(MSD(sle_dma));
695 *cur_dsd++ = cpu_to_le32(sg_dma_len(sg));
696 avail_dsds--;
Andrew Vasquez2b6c0ce2005-07-06 10:31:17 -0700697 }
698}
699
Arun Easibad75002010-05-04 15:01:30 -0700700struct fw_dif_context {
701 uint32_t ref_tag;
702 uint16_t app_tag;
703 uint8_t ref_tag_mask[4]; /* Validation/Replacement Mask*/
704 uint8_t app_tag_mask[2]; /* Validation/Replacement Mask*/
705};
706
707/*
708 * qla24xx_set_t10dif_tags_from_cmd - Extract Ref and App tags from SCSI command
709 *
710 */
711static inline void
712qla24xx_set_t10dif_tags(struct scsi_cmnd *cmd, struct fw_dif_context *pkt,
713 unsigned int protcnt)
714{
715 struct sd_dif_tuple *spt;
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700716 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
Arun Easibad75002010-05-04 15:01:30 -0700717 unsigned char op = scsi_get_prot_op(cmd);
718
719 switch (scsi_get_prot_type(cmd)) {
Arun Easibad75002010-05-04 15:01:30 -0700720 case SCSI_PROT_DIF_TYPE0:
Arun Easi8cb20492011-08-16 11:29:22 -0700721 /*
722 * No check for ql2xenablehba_err_chk, as it would be an
723 * I/O error if hba tag generation is not done.
724 */
725 pkt->ref_tag = cpu_to_le32((uint32_t)
726 (0xffffffff & scsi_get_lba(cmd)));
727 pkt->ref_tag_mask[0] = 0xff;
728 pkt->ref_tag_mask[1] = 0xff;
729 pkt->ref_tag_mask[2] = 0xff;
730 pkt->ref_tag_mask[3] = 0xff;
Arun Easibad75002010-05-04 15:01:30 -0700731 break;
732
733 /*
734 * For TYPE 2 protection: 16 bit GUARD + 32 bit REF tag has to
735 * match LBA in CDB + N
736 */
737 case SCSI_PROT_DIF_TYPE2:
Arun Easi8cb20492011-08-16 11:29:22 -0700738 if (!qla2x00_hba_err_chk_enabled(op))
Arun Easi0c470872010-07-23 15:28:38 +0500739 break;
740
741 if (scsi_prot_sg_count(cmd)) {
742 spt = page_address(sg_page(scsi_prot_sglist(cmd))) +
743 scsi_prot_sglist(cmd)[0].offset;
744 pkt->app_tag = swab32(spt->app_tag);
745 pkt->app_tag_mask[0] = 0xff;
746 pkt->app_tag_mask[1] = 0xff;
747 }
748
749 pkt->ref_tag = cpu_to_le32((uint32_t)
750 (0xffffffff & scsi_get_lba(cmd)));
751
752 /* enable ALL bytes of the ref tag */
753 pkt->ref_tag_mask[0] = 0xff;
754 pkt->ref_tag_mask[1] = 0xff;
755 pkt->ref_tag_mask[2] = 0xff;
756 pkt->ref_tag_mask[3] = 0xff;
Arun Easibad75002010-05-04 15:01:30 -0700757 break;
758
759 /* For Type 3 protection: 16 bit GUARD only */
760 case SCSI_PROT_DIF_TYPE3:
761 pkt->ref_tag_mask[0] = pkt->ref_tag_mask[1] =
762 pkt->ref_tag_mask[2] = pkt->ref_tag_mask[3] =
763 0x00;
764 break;
765
766 /*
767 * For TYpe 1 protection: 16 bit GUARD tag, 32 bit REF tag, and
768 * 16 bit app tag.
769 */
770 case SCSI_PROT_DIF_TYPE1:
Arun Easi8cb20492011-08-16 11:29:22 -0700771 if (!qla2x00_hba_err_chk_enabled(op))
Arun Easibad75002010-05-04 15:01:30 -0700772 break;
773
774 if (protcnt && (op == SCSI_PROT_WRITE_STRIP ||
775 op == SCSI_PROT_WRITE_PASS)) {
776 spt = page_address(sg_page(scsi_prot_sglist(cmd))) +
777 scsi_prot_sglist(cmd)[0].offset;
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700778 ql_dbg(ql_dbg_io, vha, 0x3008,
779 "LBA from user %p, lba = 0x%x for cmd=%p.\n",
780 spt, (int)spt->ref_tag, cmd);
Arun Easibad75002010-05-04 15:01:30 -0700781 pkt->ref_tag = swab32(spt->ref_tag);
782 pkt->app_tag_mask[0] = 0x0;
783 pkt->app_tag_mask[1] = 0x0;
784 } else {
785 pkt->ref_tag = cpu_to_le32((uint32_t)
786 (0xffffffff & scsi_get_lba(cmd)));
787 pkt->app_tag = __constant_cpu_to_le16(0);
788 pkt->app_tag_mask[0] = 0x0;
789 pkt->app_tag_mask[1] = 0x0;
790 }
791 /* enable ALL bytes of the ref tag */
792 pkt->ref_tag_mask[0] = 0xff;
793 pkt->ref_tag_mask[1] = 0xff;
794 pkt->ref_tag_mask[2] = 0xff;
795 pkt->ref_tag_mask[3] = 0xff;
796 break;
797 }
798
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700799 ql_dbg(ql_dbg_io, vha, 0x3009,
800 "Setting protection Tags: (BIG) ref tag = 0x%x, app tag = 0x%x, "
801 "prot SG count %d, cmd lba 0x%x, prot_type=%u cmd=%p.\n",
802 pkt->ref_tag, pkt->app_tag, protcnt, (int)scsi_get_lba(cmd),
803 scsi_get_prot_type(cmd), cmd);
Arun Easibad75002010-05-04 15:01:30 -0700804}
805
Arun Easi8cb20492011-08-16 11:29:22 -0700806struct qla2_sgx {
807 dma_addr_t dma_addr; /* OUT */
808 uint32_t dma_len; /* OUT */
Arun Easibad75002010-05-04 15:01:30 -0700809
Arun Easi8cb20492011-08-16 11:29:22 -0700810 uint32_t tot_bytes; /* IN */
811 struct scatterlist *cur_sg; /* IN */
812
813 /* for book keeping, bzero on initial invocation */
814 uint32_t bytes_consumed;
815 uint32_t num_bytes;
816 uint32_t tot_partial;
817
818 /* for debugging */
819 uint32_t num_sg;
820 srb_t *sp;
821};
822
823static int
824qla24xx_get_one_block_sg(uint32_t blk_sz, struct qla2_sgx *sgx,
825 uint32_t *partial)
826{
827 struct scatterlist *sg;
828 uint32_t cumulative_partial, sg_len;
829 dma_addr_t sg_dma_addr;
830
831 if (sgx->num_bytes == sgx->tot_bytes)
832 return 0;
833
834 sg = sgx->cur_sg;
835 cumulative_partial = sgx->tot_partial;
836
837 sg_dma_addr = sg_dma_address(sg);
838 sg_len = sg_dma_len(sg);
839
840 sgx->dma_addr = sg_dma_addr + sgx->bytes_consumed;
841
842 if ((cumulative_partial + (sg_len - sgx->bytes_consumed)) >= blk_sz) {
843 sgx->dma_len = (blk_sz - cumulative_partial);
844 sgx->tot_partial = 0;
845 sgx->num_bytes += blk_sz;
846 *partial = 0;
847 } else {
848 sgx->dma_len = sg_len - sgx->bytes_consumed;
849 sgx->tot_partial += sgx->dma_len;
850 *partial = 1;
851 }
852
853 sgx->bytes_consumed += sgx->dma_len;
854
855 if (sg_len == sgx->bytes_consumed) {
856 sg = sg_next(sg);
857 sgx->num_sg++;
858 sgx->cur_sg = sg;
859 sgx->bytes_consumed = 0;
860 }
861
862 return 1;
863}
864
865static int
866qla24xx_walk_and_build_sglist_no_difb(struct qla_hw_data *ha, srb_t *sp,
867 uint32_t *dsd, uint16_t tot_dsds)
868{
869 void *next_dsd;
870 uint8_t avail_dsds = 0;
871 uint32_t dsd_list_len;
872 struct dsd_dma *dsd_ptr;
873 struct scatterlist *sg_prot;
874 uint32_t *cur_dsd = dsd;
875 uint16_t used_dsds = tot_dsds;
876
877 uint32_t prot_int;
878 uint32_t partial;
879 struct qla2_sgx sgx;
880 dma_addr_t sle_dma;
881 uint32_t sle_dma_len, tot_prot_dma_len = 0;
882 struct scsi_cmnd *cmd = sp->cmd;
883
884 prot_int = cmd->device->sector_size;
885
886 memset(&sgx, 0, sizeof(struct qla2_sgx));
887 sgx.tot_bytes = scsi_bufflen(sp->cmd);
888 sgx.cur_sg = scsi_sglist(sp->cmd);
889 sgx.sp = sp;
890
891 sg_prot = scsi_prot_sglist(sp->cmd);
892
893 while (qla24xx_get_one_block_sg(prot_int, &sgx, &partial)) {
894
895 sle_dma = sgx.dma_addr;
896 sle_dma_len = sgx.dma_len;
897alloc_and_fill:
898 /* Allocate additional continuation packets? */
899 if (avail_dsds == 0) {
900 avail_dsds = (used_dsds > QLA_DSDS_PER_IOCB) ?
901 QLA_DSDS_PER_IOCB : used_dsds;
902 dsd_list_len = (avail_dsds + 1) * 12;
903 used_dsds -= avail_dsds;
904
905 /* allocate tracking DS */
906 dsd_ptr = kzalloc(sizeof(struct dsd_dma), GFP_ATOMIC);
907 if (!dsd_ptr)
908 return 1;
909
910 /* allocate new list */
911 dsd_ptr->dsd_addr = next_dsd =
912 dma_pool_alloc(ha->dl_dma_pool, GFP_ATOMIC,
913 &dsd_ptr->dsd_list_dma);
914
915 if (!next_dsd) {
916 /*
917 * Need to cleanup only this dsd_ptr, rest
918 * will be done by sp_free_dma()
919 */
920 kfree(dsd_ptr);
921 return 1;
922 }
923
924 list_add_tail(&dsd_ptr->list,
925 &((struct crc_context *)sp->ctx)->dsd_list);
926
927 sp->flags |= SRB_CRC_CTX_DSD_VALID;
928
929 /* add new list to cmd iocb or last list */
930 *cur_dsd++ = cpu_to_le32(LSD(dsd_ptr->dsd_list_dma));
931 *cur_dsd++ = cpu_to_le32(MSD(dsd_ptr->dsd_list_dma));
932 *cur_dsd++ = dsd_list_len;
933 cur_dsd = (uint32_t *)next_dsd;
934 }
935 *cur_dsd++ = cpu_to_le32(LSD(sle_dma));
936 *cur_dsd++ = cpu_to_le32(MSD(sle_dma));
937 *cur_dsd++ = cpu_to_le32(sle_dma_len);
938 avail_dsds--;
939
940 if (partial == 0) {
941 /* Got a full protection interval */
942 sle_dma = sg_dma_address(sg_prot) + tot_prot_dma_len;
943 sle_dma_len = 8;
944
945 tot_prot_dma_len += sle_dma_len;
946 if (tot_prot_dma_len == sg_dma_len(sg_prot)) {
947 tot_prot_dma_len = 0;
948 sg_prot = sg_next(sg_prot);
949 }
950
951 partial = 1; /* So as to not re-enter this block */
952 goto alloc_and_fill;
953 }
954 }
955 /* Null termination */
956 *cur_dsd++ = 0;
957 *cur_dsd++ = 0;
958 *cur_dsd++ = 0;
959 return 0;
960}
Arun Easibad75002010-05-04 15:01:30 -0700961static int
962qla24xx_walk_and_build_sglist(struct qla_hw_data *ha, srb_t *sp, uint32_t *dsd,
963 uint16_t tot_dsds)
964{
965 void *next_dsd;
966 uint8_t avail_dsds = 0;
967 uint32_t dsd_list_len;
968 struct dsd_dma *dsd_ptr;
969 struct scatterlist *sg;
970 uint32_t *cur_dsd = dsd;
971 int i;
972 uint16_t used_dsds = tot_dsds;
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700973 scsi_qla_host_t *vha = shost_priv(sp->cmd->device->host);
Arun Easibad75002010-05-04 15:01:30 -0700974
975 uint8_t *cp;
976
977 scsi_for_each_sg(sp->cmd, sg, tot_dsds, i) {
978 dma_addr_t sle_dma;
979
980 /* Allocate additional continuation packets? */
981 if (avail_dsds == 0) {
982 avail_dsds = (used_dsds > QLA_DSDS_PER_IOCB) ?
983 QLA_DSDS_PER_IOCB : used_dsds;
984 dsd_list_len = (avail_dsds + 1) * 12;
985 used_dsds -= avail_dsds;
986
987 /* allocate tracking DS */
988 dsd_ptr = kzalloc(sizeof(struct dsd_dma), GFP_ATOMIC);
989 if (!dsd_ptr)
990 return 1;
991
992 /* allocate new list */
993 dsd_ptr->dsd_addr = next_dsd =
994 dma_pool_alloc(ha->dl_dma_pool, GFP_ATOMIC,
995 &dsd_ptr->dsd_list_dma);
996
997 if (!next_dsd) {
998 /*
999 * Need to cleanup only this dsd_ptr, rest
1000 * will be done by sp_free_dma()
1001 */
1002 kfree(dsd_ptr);
1003 return 1;
1004 }
1005
1006 list_add_tail(&dsd_ptr->list,
1007 &((struct crc_context *)sp->ctx)->dsd_list);
1008
1009 sp->flags |= SRB_CRC_CTX_DSD_VALID;
1010
1011 /* add new list to cmd iocb or last list */
1012 *cur_dsd++ = cpu_to_le32(LSD(dsd_ptr->dsd_list_dma));
1013 *cur_dsd++ = cpu_to_le32(MSD(dsd_ptr->dsd_list_dma));
1014 *cur_dsd++ = dsd_list_len;
1015 cur_dsd = (uint32_t *)next_dsd;
1016 }
1017 sle_dma = sg_dma_address(sg);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001018 ql_dbg(ql_dbg_io, vha, 0x300a,
1019 "sg entry %d - addr=0x%x 0x%x, " "len=%d for cmd=%p.\n",
1020 cur_dsd, i, LSD(sle_dma), MSD(sle_dma), sg_dma_len(sg),
1021 sp->cmd);
Arun Easibad75002010-05-04 15:01:30 -07001022 *cur_dsd++ = cpu_to_le32(LSD(sle_dma));
1023 *cur_dsd++ = cpu_to_le32(MSD(sle_dma));
1024 *cur_dsd++ = cpu_to_le32(sg_dma_len(sg));
1025 avail_dsds--;
1026
1027 if (scsi_get_prot_op(sp->cmd) == SCSI_PROT_WRITE_PASS) {
1028 cp = page_address(sg_page(sg)) + sg->offset;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001029 ql_dbg(ql_dbg_io, vha, 0x300b,
1030 "User data buffer=%p for cmd=%p.\n", cp, sp->cmd);
Arun Easibad75002010-05-04 15:01:30 -07001031 }
1032 }
1033 /* Null termination */
1034 *cur_dsd++ = 0;
1035 *cur_dsd++ = 0;
1036 *cur_dsd++ = 0;
1037 return 0;
1038}
1039
1040static int
1041qla24xx_walk_and_build_prot_sglist(struct qla_hw_data *ha, srb_t *sp,
1042 uint32_t *dsd,
1043 uint16_t tot_dsds)
1044{
1045 void *next_dsd;
1046 uint8_t avail_dsds = 0;
1047 uint32_t dsd_list_len;
1048 struct dsd_dma *dsd_ptr;
1049 struct scatterlist *sg;
1050 int i;
1051 struct scsi_cmnd *cmd;
1052 uint32_t *cur_dsd = dsd;
1053 uint16_t used_dsds = tot_dsds;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001054 scsi_qla_host_t *vha = pci_get_drvdata(ha->pdev);
Arun Easibad75002010-05-04 15:01:30 -07001055 uint8_t *cp;
1056
1057
1058 cmd = sp->cmd;
1059 scsi_for_each_prot_sg(cmd, sg, tot_dsds, i) {
1060 dma_addr_t sle_dma;
1061
1062 /* Allocate additional continuation packets? */
1063 if (avail_dsds == 0) {
1064 avail_dsds = (used_dsds > QLA_DSDS_PER_IOCB) ?
1065 QLA_DSDS_PER_IOCB : used_dsds;
1066 dsd_list_len = (avail_dsds + 1) * 12;
1067 used_dsds -= avail_dsds;
1068
1069 /* allocate tracking DS */
1070 dsd_ptr = kzalloc(sizeof(struct dsd_dma), GFP_ATOMIC);
1071 if (!dsd_ptr)
1072 return 1;
1073
1074 /* allocate new list */
1075 dsd_ptr->dsd_addr = next_dsd =
1076 dma_pool_alloc(ha->dl_dma_pool, GFP_ATOMIC,
1077 &dsd_ptr->dsd_list_dma);
1078
1079 if (!next_dsd) {
1080 /*
1081 * Need to cleanup only this dsd_ptr, rest
1082 * will be done by sp_free_dma()
1083 */
1084 kfree(dsd_ptr);
1085 return 1;
1086 }
1087
1088 list_add_tail(&dsd_ptr->list,
1089 &((struct crc_context *)sp->ctx)->dsd_list);
1090
1091 sp->flags |= SRB_CRC_CTX_DSD_VALID;
1092
1093 /* add new list to cmd iocb or last list */
1094 *cur_dsd++ = cpu_to_le32(LSD(dsd_ptr->dsd_list_dma));
1095 *cur_dsd++ = cpu_to_le32(MSD(dsd_ptr->dsd_list_dma));
1096 *cur_dsd++ = dsd_list_len;
1097 cur_dsd = (uint32_t *)next_dsd;
1098 }
1099 sle_dma = sg_dma_address(sg);
1100 if (scsi_get_prot_op(sp->cmd) == SCSI_PROT_WRITE_PASS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001101 ql_dbg(ql_dbg_io, vha, 0x3027,
1102 "%s(): %p, sg_entry %d - "
1103 "addr=0x%x0x%x, len=%d.\n",
1104 __func__, cur_dsd, i,
1105 LSD(sle_dma), MSD(sle_dma), sg_dma_len(sg));
Arun Easibad75002010-05-04 15:01:30 -07001106 }
1107 *cur_dsd++ = cpu_to_le32(LSD(sle_dma));
1108 *cur_dsd++ = cpu_to_le32(MSD(sle_dma));
1109 *cur_dsd++ = cpu_to_le32(sg_dma_len(sg));
1110
1111 if (scsi_get_prot_op(sp->cmd) == SCSI_PROT_WRITE_PASS) {
1112 cp = page_address(sg_page(sg)) + sg->offset;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001113 ql_dbg(ql_dbg_io, vha, 0x3028,
1114 "%s(): Protection Data buffer = %p.\n", __func__,
1115 cp);
Arun Easibad75002010-05-04 15:01:30 -07001116 }
1117 avail_dsds--;
1118 }
1119 /* Null termination */
1120 *cur_dsd++ = 0;
1121 *cur_dsd++ = 0;
1122 *cur_dsd++ = 0;
1123 return 0;
1124}
1125
1126/**
1127 * qla24xx_build_scsi_crc_2_iocbs() - Build IOCB command utilizing Command
1128 * Type 6 IOCB types.
1129 *
1130 * @sp: SRB command to process
1131 * @cmd_pkt: Command type 3 IOCB
1132 * @tot_dsds: Total number of segments to transfer
1133 */
1134static inline int
1135qla24xx_build_scsi_crc_2_iocbs(srb_t *sp, struct cmd_type_crc_2 *cmd_pkt,
1136 uint16_t tot_dsds, uint16_t tot_prot_dsds, uint16_t fw_prot_opts)
1137{
1138 uint32_t *cur_dsd, *fcp_dl;
1139 scsi_qla_host_t *vha;
1140 struct scsi_cmnd *cmd;
1141 struct scatterlist *cur_seg;
1142 int sgc;
Arun Easi8cb20492011-08-16 11:29:22 -07001143 uint32_t total_bytes = 0;
Arun Easibad75002010-05-04 15:01:30 -07001144 uint32_t data_bytes;
1145 uint32_t dif_bytes;
1146 uint8_t bundling = 1;
1147 uint16_t blk_size;
1148 uint8_t *clr_ptr;
1149 struct crc_context *crc_ctx_pkt = NULL;
1150 struct qla_hw_data *ha;
1151 uint8_t additional_fcpcdb_len;
1152 uint16_t fcp_cmnd_len;
1153 struct fcp_cmnd *fcp_cmnd;
1154 dma_addr_t crc_ctx_dma;
Andrew Vasquezff2fc422011-02-23 15:27:15 -08001155 char tag[2];
Arun Easibad75002010-05-04 15:01:30 -07001156
1157 cmd = sp->cmd;
1158
1159 sgc = 0;
1160 /* Update entry type to indicate Command Type CRC_2 IOCB */
1161 *((uint32_t *)(&cmd_pkt->entry_type)) =
1162 __constant_cpu_to_le32(COMMAND_TYPE_CRC_2);
1163
Arun Easibad75002010-05-04 15:01:30 -07001164 vha = sp->fcport->vha;
1165 ha = vha->hw;
1166
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001167 /* No data transfer */
1168 data_bytes = scsi_bufflen(cmd);
1169 if (!data_bytes || cmd->sc_data_direction == DMA_NONE) {
1170 cmd_pkt->byte_count = __constant_cpu_to_le32(0);
1171 return QLA_SUCCESS;
1172 }
Arun Easibad75002010-05-04 15:01:30 -07001173
1174 cmd_pkt->vp_index = sp->fcport->vp_idx;
1175
1176 /* Set transfer direction */
1177 if (cmd->sc_data_direction == DMA_TO_DEVICE) {
1178 cmd_pkt->control_flags =
1179 __constant_cpu_to_le16(CF_WRITE_DATA);
1180 } else if (cmd->sc_data_direction == DMA_FROM_DEVICE) {
1181 cmd_pkt->control_flags =
1182 __constant_cpu_to_le16(CF_READ_DATA);
1183 }
1184
Arun Easi8cb20492011-08-16 11:29:22 -07001185 if ((scsi_get_prot_op(sp->cmd) == SCSI_PROT_READ_INSERT) ||
1186 (scsi_get_prot_op(sp->cmd) == SCSI_PROT_WRITE_STRIP) ||
1187 (scsi_get_prot_op(sp->cmd) == SCSI_PROT_READ_STRIP) ||
1188 (scsi_get_prot_op(sp->cmd) == SCSI_PROT_WRITE_INSERT))
Arun Easibad75002010-05-04 15:01:30 -07001189 bundling = 0;
1190
1191 /* Allocate CRC context from global pool */
1192 crc_ctx_pkt = sp->ctx = dma_pool_alloc(ha->dl_dma_pool,
1193 GFP_ATOMIC, &crc_ctx_dma);
1194
1195 if (!crc_ctx_pkt)
1196 goto crc_queuing_error;
1197
1198 /* Zero out CTX area. */
1199 clr_ptr = (uint8_t *)crc_ctx_pkt;
1200 memset(clr_ptr, 0, sizeof(*crc_ctx_pkt));
1201
1202 crc_ctx_pkt->crc_ctx_dma = crc_ctx_dma;
1203
1204 sp->flags |= SRB_CRC_CTX_DMA_VALID;
1205
1206 /* Set handle */
1207 crc_ctx_pkt->handle = cmd_pkt->handle;
1208
1209 INIT_LIST_HEAD(&crc_ctx_pkt->dsd_list);
1210
1211 qla24xx_set_t10dif_tags(cmd, (struct fw_dif_context *)
1212 &crc_ctx_pkt->ref_tag, tot_prot_dsds);
1213
1214 cmd_pkt->crc_context_address[0] = cpu_to_le32(LSD(crc_ctx_dma));
1215 cmd_pkt->crc_context_address[1] = cpu_to_le32(MSD(crc_ctx_dma));
1216 cmd_pkt->crc_context_len = CRC_CONTEXT_LEN_FW;
1217
1218 /* Determine SCSI command length -- align to 4 byte boundary */
1219 if (cmd->cmd_len > 16) {
Arun Easibad75002010-05-04 15:01:30 -07001220 additional_fcpcdb_len = cmd->cmd_len - 16;
1221 if ((cmd->cmd_len % 4) != 0) {
1222 /* SCSI cmd > 16 bytes must be multiple of 4 */
1223 goto crc_queuing_error;
1224 }
1225 fcp_cmnd_len = 12 + cmd->cmd_len + 4;
1226 } else {
1227 additional_fcpcdb_len = 0;
1228 fcp_cmnd_len = 12 + 16 + 4;
1229 }
1230
1231 fcp_cmnd = &crc_ctx_pkt->fcp_cmnd;
1232
1233 fcp_cmnd->additional_cdb_len = additional_fcpcdb_len;
1234 if (cmd->sc_data_direction == DMA_TO_DEVICE)
1235 fcp_cmnd->additional_cdb_len |= 1;
1236 else if (cmd->sc_data_direction == DMA_FROM_DEVICE)
1237 fcp_cmnd->additional_cdb_len |= 2;
1238
1239 int_to_scsilun(sp->cmd->device->lun, &fcp_cmnd->lun);
Mike Hernandez85727e12010-11-23 16:52:46 -08001240 host_to_fcp_swap((uint8_t *)&fcp_cmnd->lun, sizeof(fcp_cmnd->lun));
Arun Easibad75002010-05-04 15:01:30 -07001241 memcpy(fcp_cmnd->cdb, cmd->cmnd, cmd->cmd_len);
1242 cmd_pkt->fcp_cmnd_dseg_len = cpu_to_le16(fcp_cmnd_len);
1243 cmd_pkt->fcp_cmnd_dseg_address[0] = cpu_to_le32(
1244 LSD(crc_ctx_dma + CRC_CONTEXT_FCPCMND_OFF));
1245 cmd_pkt->fcp_cmnd_dseg_address[1] = cpu_to_le32(
1246 MSD(crc_ctx_dma + CRC_CONTEXT_FCPCMND_OFF));
Uwe Kleine-König65155b32010-06-11 12:17:01 +02001247 fcp_cmnd->task_management = 0;
Arun Easibad75002010-05-04 15:01:30 -07001248
Andrew Vasquezff2fc422011-02-23 15:27:15 -08001249 /*
1250 * Update tagged queuing modifier if using command tag queuing
1251 */
1252 if (scsi_populate_tag_msg(cmd, tag)) {
1253 switch (tag[0]) {
1254 case HEAD_OF_QUEUE_TAG:
1255 fcp_cmnd->task_attribute = TSK_HEAD_OF_QUEUE;
1256 break;
1257 case ORDERED_QUEUE_TAG:
1258 fcp_cmnd->task_attribute = TSK_ORDERED;
1259 break;
1260 default:
1261 fcp_cmnd->task_attribute = 0;
1262 break;
1263 }
1264 } else {
1265 fcp_cmnd->task_attribute = 0;
1266 }
1267
Arun Easibad75002010-05-04 15:01:30 -07001268 cmd_pkt->fcp_rsp_dseg_len = 0; /* Let response come in status iocb */
1269
Arun Easibad75002010-05-04 15:01:30 -07001270 /* Compute dif len and adjust data len to incude protection */
Arun Easibad75002010-05-04 15:01:30 -07001271 dif_bytes = 0;
1272 blk_size = cmd->device->sector_size;
Arun Easi8cb20492011-08-16 11:29:22 -07001273 dif_bytes = (data_bytes / blk_size) * 8;
1274
1275 switch (scsi_get_prot_op(sp->cmd)) {
1276 case SCSI_PROT_READ_INSERT:
1277 case SCSI_PROT_WRITE_STRIP:
1278 total_bytes = data_bytes;
1279 data_bytes += dif_bytes;
1280 break;
1281
1282 case SCSI_PROT_READ_STRIP:
1283 case SCSI_PROT_WRITE_INSERT:
1284 case SCSI_PROT_READ_PASS:
1285 case SCSI_PROT_WRITE_PASS:
1286 total_bytes = data_bytes + dif_bytes;
1287 break;
1288 default:
1289 BUG();
Arun Easibad75002010-05-04 15:01:30 -07001290 }
1291
Arun Easi8cb20492011-08-16 11:29:22 -07001292 if (!qla2x00_hba_err_chk_enabled(scsi_get_prot_op(cmd)))
Arun Easibad75002010-05-04 15:01:30 -07001293 fw_prot_opts |= 0x10; /* Disable Guard tag checking */
1294
1295 if (!bundling) {
1296 cur_dsd = (uint32_t *) &crc_ctx_pkt->u.nobundling.data_address;
1297 } else {
1298 /*
1299 * Configure Bundling if we need to fetch interlaving
1300 * protection PCI accesses
1301 */
1302 fw_prot_opts |= PO_ENABLE_DIF_BUNDLING;
1303 crc_ctx_pkt->u.bundling.dif_byte_count = cpu_to_le32(dif_bytes);
1304 crc_ctx_pkt->u.bundling.dseg_count = cpu_to_le16(tot_dsds -
1305 tot_prot_dsds);
1306 cur_dsd = (uint32_t *) &crc_ctx_pkt->u.bundling.data_address;
1307 }
1308
1309 /* Finish the common fields of CRC pkt */
1310 crc_ctx_pkt->blk_size = cpu_to_le16(blk_size);
1311 crc_ctx_pkt->prot_opts = cpu_to_le16(fw_prot_opts);
1312 crc_ctx_pkt->byte_count = cpu_to_le32(data_bytes);
1313 crc_ctx_pkt->guard_seed = __constant_cpu_to_le16(0);
1314 /* Fibre channel byte count */
1315 cmd_pkt->byte_count = cpu_to_le32(total_bytes);
1316 fcp_dl = (uint32_t *)(crc_ctx_pkt->fcp_cmnd.cdb + 16 +
1317 additional_fcpcdb_len);
1318 *fcp_dl = htonl(total_bytes);
1319
Arun Easi0c470872010-07-23 15:28:38 +05001320 if (!data_bytes || cmd->sc_data_direction == DMA_NONE) {
Arun Easi0c470872010-07-23 15:28:38 +05001321 cmd_pkt->byte_count = __constant_cpu_to_le32(0);
1322 return QLA_SUCCESS;
1323 }
Arun Easibad75002010-05-04 15:01:30 -07001324 /* Walks data segments */
1325
1326 cmd_pkt->control_flags |=
1327 __constant_cpu_to_le16(CF_DATA_SEG_DESCR_ENABLE);
Arun Easi8cb20492011-08-16 11:29:22 -07001328
1329 if (!bundling && tot_prot_dsds) {
1330 if (qla24xx_walk_and_build_sglist_no_difb(ha, sp,
1331 cur_dsd, tot_dsds))
1332 goto crc_queuing_error;
1333 } else if (qla24xx_walk_and_build_sglist(ha, sp, cur_dsd,
Arun Easibad75002010-05-04 15:01:30 -07001334 (tot_dsds - tot_prot_dsds)))
1335 goto crc_queuing_error;
1336
1337 if (bundling && tot_prot_dsds) {
1338 /* Walks dif segments */
1339 cur_seg = scsi_prot_sglist(cmd);
1340 cmd_pkt->control_flags |=
1341 __constant_cpu_to_le16(CF_DIF_SEG_DESCR_ENABLE);
1342 cur_dsd = (uint32_t *) &crc_ctx_pkt->u.bundling.dif_address;
1343 if (qla24xx_walk_and_build_prot_sglist(ha, sp, cur_dsd,
1344 tot_prot_dsds))
1345 goto crc_queuing_error;
1346 }
1347 return QLA_SUCCESS;
1348
1349crc_queuing_error:
Arun Easibad75002010-05-04 15:01:30 -07001350 /* Cleanup will be performed by the caller */
1351
1352 return QLA_FUNCTION_FAILED;
1353}
Andrew Vasquez2b6c0ce2005-07-06 10:31:17 -07001354
1355/**
1356 * qla24xx_start_scsi() - Send a SCSI command to the ISP
1357 * @sp: command to send to the ISP
1358 *
Bjorn Helgaascc3ef7b2008-09-11 21:22:51 -07001359 * Returns non-zero if a failure occurred, else zero.
Andrew Vasquez2b6c0ce2005-07-06 10:31:17 -07001360 */
1361int
1362qla24xx_start_scsi(srb_t *sp)
1363{
FUJITA Tomonori385d70b2007-05-26 01:55:38 +09001364 int ret, nseg;
Andrew Vasquez2b6c0ce2005-07-06 10:31:17 -07001365 unsigned long flags;
Andrew Vasquez2b6c0ce2005-07-06 10:31:17 -07001366 uint32_t *clr_ptr;
1367 uint32_t index;
1368 uint32_t handle;
1369 struct cmd_type_7 *cmd_pkt;
Andrew Vasquez2b6c0ce2005-07-06 10:31:17 -07001370 uint16_t cnt;
1371 uint16_t req_cnt;
1372 uint16_t tot_dsds;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001373 struct req_que *req = NULL;
1374 struct rsp_que *rsp = NULL;
1375 struct scsi_cmnd *cmd = sp->cmd;
Andrew Vasquez444786d2009-01-05 11:18:10 -08001376 struct scsi_qla_host *vha = sp->fcport->vha;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001377 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezff2fc422011-02-23 15:27:15 -08001378 char tag[2];
Andrew Vasquez2b6c0ce2005-07-06 10:31:17 -07001379
1380 /* Setup device pointers. */
1381 ret = 0;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001382
Anirban Chakraborty59e0b8b2009-06-03 09:55:19 -07001383 qla25xx_set_que(sp, &rsp);
1384 req = vha->req;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001385
Andrew Vasquez2b6c0ce2005-07-06 10:31:17 -07001386 /* So we know we haven't pci_map'ed anything yet */
1387 tot_dsds = 0;
1388
1389 /* Send marker if required */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001390 if (vha->marker_needed != 0) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001391 if (qla2x00_marker(vha, req, rsp, 0, 0, MK_SYNC_ALL) !=
1392 QLA_SUCCESS)
Andrew Vasquez2b6c0ce2005-07-06 10:31:17 -07001393 return QLA_FUNCTION_FAILED;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001394 vha->marker_needed = 0;
Andrew Vasquez2b6c0ce2005-07-06 10:31:17 -07001395 }
1396
1397 /* Acquire ring specific lock */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001398 spin_lock_irqsave(&ha->hardware_lock, flags);
Andrew Vasquez2b6c0ce2005-07-06 10:31:17 -07001399
1400 /* Check for room in outstanding command list. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001401 handle = req->current_outstanding_cmd;
Andrew Vasquez2b6c0ce2005-07-06 10:31:17 -07001402 for (index = 1; index < MAX_OUTSTANDING_COMMANDS; index++) {
1403 handle++;
1404 if (handle == MAX_OUTSTANDING_COMMANDS)
1405 handle = 1;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001406 if (!req->outstanding_cmds[handle])
Andrew Vasquez2b6c0ce2005-07-06 10:31:17 -07001407 break;
1408 }
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001409 if (index == MAX_OUTSTANDING_COMMANDS) {
Andrew Vasquez2b6c0ce2005-07-06 10:31:17 -07001410 goto queuing_error;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001411 }
Andrew Vasquez2b6c0ce2005-07-06 10:31:17 -07001412
1413 /* Map the sg table so we have an accurate count of sg entries needed */
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001414 if (scsi_sg_count(cmd)) {
1415 nseg = dma_map_sg(&ha->pdev->dev, scsi_sglist(cmd),
1416 scsi_sg_count(cmd), cmd->sc_data_direction);
1417 if (unlikely(!nseg))
Andrew Vasquez2b6c0ce2005-07-06 10:31:17 -07001418 goto queuing_error;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001419 } else
1420 nseg = 0;
1421
FUJITA Tomonori385d70b2007-05-26 01:55:38 +09001422 tot_dsds = nseg;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001423 req_cnt = qla24xx_calc_iocbs(vha, tot_dsds);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001424 if (req->cnt < (req_cnt + 2)) {
Andrew Vasquez08029992009-03-24 09:07:55 -07001425 cnt = RD_REG_DWORD_RELAXED(req->req_q_out);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001426
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001427 if (req->ring_index < cnt)
1428 req->cnt = cnt - req->ring_index;
Andrew Vasquez2b6c0ce2005-07-06 10:31:17 -07001429 else
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001430 req->cnt = req->length -
1431 (req->ring_index - cnt);
Andrew Vasquez2b6c0ce2005-07-06 10:31:17 -07001432 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001433 if (req->cnt < (req_cnt + 2))
Andrew Vasquez2b6c0ce2005-07-06 10:31:17 -07001434 goto queuing_error;
Andrew Vasquez2b6c0ce2005-07-06 10:31:17 -07001435
1436 /* Build command packet. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001437 req->current_outstanding_cmd = handle;
1438 req->outstanding_cmds[handle] = sp;
Andrew Vasquezcf53b062009-08-20 11:06:04 -07001439 sp->handle = handle;
Andrew Vasquez2b6c0ce2005-07-06 10:31:17 -07001440 sp->cmd->host_scribble = (unsigned char *)(unsigned long)handle;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001441 req->cnt -= req_cnt;
Andrew Vasquez2b6c0ce2005-07-06 10:31:17 -07001442
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001443 cmd_pkt = (struct cmd_type_7 *)req->ring_ptr;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001444 cmd_pkt->handle = MAKE_HANDLE(req->id, handle);
Andrew Vasquez2b6c0ce2005-07-06 10:31:17 -07001445
1446 /* Zero out remaining portion of packet. */
James Bottomley72df8322005-10-28 14:41:19 -05001447 /* tagged queuing modifier -- default is TSK_SIMPLE (0). */
Andrew Vasquez2b6c0ce2005-07-06 10:31:17 -07001448 clr_ptr = (uint32_t *)cmd_pkt + 2;
1449 memset(clr_ptr, 0, REQUEST_ENTRY_SIZE - 8);
1450 cmd_pkt->dseg_count = cpu_to_le16(tot_dsds);
1451
1452 /* Set NPORT-ID and LUN number*/
1453 cmd_pkt->nport_handle = cpu_to_le16(sp->fcport->loop_id);
1454 cmd_pkt->port_id[0] = sp->fcport->d_id.b.al_pa;
1455 cmd_pkt->port_id[1] = sp->fcport->d_id.b.area;
1456 cmd_pkt->port_id[2] = sp->fcport->d_id.b.domain;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001457 cmd_pkt->vp_index = sp->fcport->vp_idx;
Andrew Vasquez2b6c0ce2005-07-06 10:31:17 -07001458
Andrew Vasquez661c3f62005-10-27 11:09:58 -07001459 int_to_scsilun(sp->cmd->device->lun, &cmd_pkt->lun);
andrew.vasquez@qlogic.com0d4be122006-02-07 08:45:35 -08001460 host_to_fcp_swap((uint8_t *)&cmd_pkt->lun, sizeof(cmd_pkt->lun));
Andrew Vasquez2b6c0ce2005-07-06 10:31:17 -07001461
Andrew Vasquezff2fc422011-02-23 15:27:15 -08001462 /* Update tagged queuing modifier -- default is TSK_SIMPLE (0). */
1463 if (scsi_populate_tag_msg(cmd, tag)) {
1464 switch (tag[0]) {
1465 case HEAD_OF_QUEUE_TAG:
1466 cmd_pkt->task = TSK_HEAD_OF_QUEUE;
1467 break;
1468 case ORDERED_QUEUE_TAG:
1469 cmd_pkt->task = TSK_ORDERED;
1470 break;
1471 }
1472 }
1473
Andrew Vasquez2b6c0ce2005-07-06 10:31:17 -07001474 /* Load SCSI command packet. */
1475 memcpy(cmd_pkt->fcp_cdb, cmd->cmnd, cmd->cmd_len);
1476 host_to_fcp_swap(cmd_pkt->fcp_cdb, sizeof(cmd_pkt->fcp_cdb));
1477
FUJITA Tomonori385d70b2007-05-26 01:55:38 +09001478 cmd_pkt->byte_count = cpu_to_le32((uint32_t)scsi_bufflen(cmd));
Andrew Vasquez2b6c0ce2005-07-06 10:31:17 -07001479
1480 /* Build IOCB segments */
1481 qla24xx_build_scsi_iocbs(sp, cmd_pkt, tot_dsds);
1482
1483 /* Set total data segment count. */
1484 cmd_pkt->entry_count = (uint8_t)req_cnt;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001485 /* Specify response queue number where completion should happen */
1486 cmd_pkt->entry_status = (uint8_t) rsp->id;
Andrew Vasquez2b6c0ce2005-07-06 10:31:17 -07001487 wmb();
Andrew Vasquez2b6c0ce2005-07-06 10:31:17 -07001488 /* Adjust ring index. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001489 req->ring_index++;
1490 if (req->ring_index == req->length) {
1491 req->ring_index = 0;
1492 req->ring_ptr = req->ring;
Andrew Vasquez2b6c0ce2005-07-06 10:31:17 -07001493 } else
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001494 req->ring_ptr++;
Andrew Vasquez2b6c0ce2005-07-06 10:31:17 -07001495
1496 sp->flags |= SRB_DMA_VALID;
Andrew Vasquez2b6c0ce2005-07-06 10:31:17 -07001497
1498 /* Set chip new ring index. */
Andrew Vasquez08029992009-03-24 09:07:55 -07001499 WRT_REG_DWORD(req->req_q_in, req->ring_index);
1500 RD_REG_DWORD_RELAXED(&ha->iobase->isp24.hccr);
Andrew Vasquez2b6c0ce2005-07-06 10:31:17 -07001501
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07001502 /* Manage unprocessed RIO/ZIO commands in response queue. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001503 if (vha->flags.process_response_queue &&
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001504 rsp->ring_ptr->signature != RESPONSE_PROCESSED)
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001505 qla24xx_process_response_queue(vha, rsp);
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07001506
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001507 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Andrew Vasquez2b6c0ce2005-07-06 10:31:17 -07001508 return QLA_SUCCESS;
1509
1510queuing_error:
FUJITA Tomonori385d70b2007-05-26 01:55:38 +09001511 if (tot_dsds)
1512 scsi_dma_unmap(cmd);
1513
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001514 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Andrew Vasquez2b6c0ce2005-07-06 10:31:17 -07001515
1516 return QLA_FUNCTION_FAILED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001517}
Anirban Chakraborty68ca9492009-04-06 22:33:41 -07001518
Arun Easibad75002010-05-04 15:01:30 -07001519
1520/**
1521 * qla24xx_dif_start_scsi() - Send a SCSI command to the ISP
1522 * @sp: command to send to the ISP
1523 *
1524 * Returns non-zero if a failure occurred, else zero.
1525 */
1526int
1527qla24xx_dif_start_scsi(srb_t *sp)
1528{
1529 int nseg;
1530 unsigned long flags;
1531 uint32_t *clr_ptr;
1532 uint32_t index;
1533 uint32_t handle;
1534 uint16_t cnt;
1535 uint16_t req_cnt = 0;
1536 uint16_t tot_dsds;
1537 uint16_t tot_prot_dsds;
1538 uint16_t fw_prot_opts = 0;
1539 struct req_que *req = NULL;
1540 struct rsp_que *rsp = NULL;
1541 struct scsi_cmnd *cmd = sp->cmd;
1542 struct scsi_qla_host *vha = sp->fcport->vha;
1543 struct qla_hw_data *ha = vha->hw;
1544 struct cmd_type_crc_2 *cmd_pkt;
1545 uint32_t status = 0;
1546
1547#define QDSS_GOT_Q_SPACE BIT_0
1548
Arun Easi0c470872010-07-23 15:28:38 +05001549 /* Only process protection or >16 cdb in this routine */
1550 if (scsi_get_prot_op(cmd) == SCSI_PROT_NORMAL) {
1551 if (cmd->cmd_len <= 16)
1552 return qla24xx_start_scsi(sp);
1553 }
Arun Easibad75002010-05-04 15:01:30 -07001554
1555 /* Setup device pointers. */
1556
1557 qla25xx_set_que(sp, &rsp);
1558 req = vha->req;
1559
1560 /* So we know we haven't pci_map'ed anything yet */
1561 tot_dsds = 0;
1562
1563 /* Send marker if required */
1564 if (vha->marker_needed != 0) {
1565 if (qla2x00_marker(vha, req, rsp, 0, 0, MK_SYNC_ALL) !=
1566 QLA_SUCCESS)
1567 return QLA_FUNCTION_FAILED;
1568 vha->marker_needed = 0;
1569 }
1570
1571 /* Acquire ring specific lock */
1572 spin_lock_irqsave(&ha->hardware_lock, flags);
1573
1574 /* Check for room in outstanding command list. */
1575 handle = req->current_outstanding_cmd;
1576 for (index = 1; index < MAX_OUTSTANDING_COMMANDS; index++) {
1577 handle++;
1578 if (handle == MAX_OUTSTANDING_COMMANDS)
1579 handle = 1;
1580 if (!req->outstanding_cmds[handle])
1581 break;
1582 }
1583
1584 if (index == MAX_OUTSTANDING_COMMANDS)
1585 goto queuing_error;
1586
1587 /* Compute number of required data segments */
1588 /* Map the sg table so we have an accurate count of sg entries needed */
1589 if (scsi_sg_count(cmd)) {
1590 nseg = dma_map_sg(&ha->pdev->dev, scsi_sglist(cmd),
1591 scsi_sg_count(cmd), cmd->sc_data_direction);
1592 if (unlikely(!nseg))
1593 goto queuing_error;
1594 else
1595 sp->flags |= SRB_DMA_VALID;
Arun Easi8cb20492011-08-16 11:29:22 -07001596
1597 if ((scsi_get_prot_op(cmd) == SCSI_PROT_READ_INSERT) ||
1598 (scsi_get_prot_op(cmd) == SCSI_PROT_WRITE_STRIP)) {
1599 struct qla2_sgx sgx;
1600 uint32_t partial;
1601
1602 memset(&sgx, 0, sizeof(struct qla2_sgx));
1603 sgx.tot_bytes = scsi_bufflen(cmd);
1604 sgx.cur_sg = scsi_sglist(cmd);
1605 sgx.sp = sp;
1606
1607 nseg = 0;
1608 while (qla24xx_get_one_block_sg(
1609 cmd->device->sector_size, &sgx, &partial))
1610 nseg++;
1611 }
Arun Easibad75002010-05-04 15:01:30 -07001612 } else
1613 nseg = 0;
1614
1615 /* number of required data segments */
1616 tot_dsds = nseg;
1617
1618 /* Compute number of required protection segments */
1619 if (qla24xx_configure_prot_mode(sp, &fw_prot_opts)) {
1620 nseg = dma_map_sg(&ha->pdev->dev, scsi_prot_sglist(cmd),
1621 scsi_prot_sg_count(cmd), cmd->sc_data_direction);
1622 if (unlikely(!nseg))
1623 goto queuing_error;
1624 else
1625 sp->flags |= SRB_CRC_PROT_DMA_VALID;
Arun Easi8cb20492011-08-16 11:29:22 -07001626
1627 if ((scsi_get_prot_op(cmd) == SCSI_PROT_READ_INSERT) ||
1628 (scsi_get_prot_op(cmd) == SCSI_PROT_WRITE_STRIP)) {
1629 nseg = scsi_bufflen(cmd) / cmd->device->sector_size;
1630 }
Arun Easibad75002010-05-04 15:01:30 -07001631 } else {
1632 nseg = 0;
1633 }
1634
1635 req_cnt = 1;
1636 /* Total Data and protection sg segment(s) */
1637 tot_prot_dsds = nseg;
1638 tot_dsds += nseg;
1639 if (req->cnt < (req_cnt + 2)) {
1640 cnt = RD_REG_DWORD_RELAXED(req->req_q_out);
1641
1642 if (req->ring_index < cnt)
1643 req->cnt = cnt - req->ring_index;
1644 else
1645 req->cnt = req->length -
1646 (req->ring_index - cnt);
1647 }
1648
1649 if (req->cnt < (req_cnt + 2))
1650 goto queuing_error;
1651
1652 status |= QDSS_GOT_Q_SPACE;
1653
1654 /* Build header part of command packet (excluding the OPCODE). */
1655 req->current_outstanding_cmd = handle;
1656 req->outstanding_cmds[handle] = sp;
Arun Easi8cb20492011-08-16 11:29:22 -07001657 sp->handle = handle;
Arun Easibad75002010-05-04 15:01:30 -07001658 sp->cmd->host_scribble = (unsigned char *)(unsigned long)handle;
1659 req->cnt -= req_cnt;
1660
1661 /* Fill-in common area */
1662 cmd_pkt = (struct cmd_type_crc_2 *)req->ring_ptr;
1663 cmd_pkt->handle = MAKE_HANDLE(req->id, handle);
1664
1665 clr_ptr = (uint32_t *)cmd_pkt + 2;
1666 memset(clr_ptr, 0, REQUEST_ENTRY_SIZE - 8);
1667
1668 /* Set NPORT-ID and LUN number*/
1669 cmd_pkt->nport_handle = cpu_to_le16(sp->fcport->loop_id);
1670 cmd_pkt->port_id[0] = sp->fcport->d_id.b.al_pa;
1671 cmd_pkt->port_id[1] = sp->fcport->d_id.b.area;
1672 cmd_pkt->port_id[2] = sp->fcport->d_id.b.domain;
1673
1674 int_to_scsilun(sp->cmd->device->lun, &cmd_pkt->lun);
1675 host_to_fcp_swap((uint8_t *)&cmd_pkt->lun, sizeof(cmd_pkt->lun));
1676
1677 /* Total Data and protection segment(s) */
1678 cmd_pkt->dseg_count = cpu_to_le16(tot_dsds);
1679
1680 /* Build IOCB segments and adjust for data protection segments */
1681 if (qla24xx_build_scsi_crc_2_iocbs(sp, (struct cmd_type_crc_2 *)
1682 req->ring_ptr, tot_dsds, tot_prot_dsds, fw_prot_opts) !=
1683 QLA_SUCCESS)
1684 goto queuing_error;
1685
1686 cmd_pkt->entry_count = (uint8_t)req_cnt;
1687 /* Specify response queue number where completion should happen */
1688 cmd_pkt->entry_status = (uint8_t) rsp->id;
1689 cmd_pkt->timeout = __constant_cpu_to_le16(0);
1690 wmb();
1691
1692 /* Adjust ring index. */
1693 req->ring_index++;
1694 if (req->ring_index == req->length) {
1695 req->ring_index = 0;
1696 req->ring_ptr = req->ring;
1697 } else
1698 req->ring_ptr++;
1699
1700 /* Set chip new ring index. */
1701 WRT_REG_DWORD(req->req_q_in, req->ring_index);
1702 RD_REG_DWORD_RELAXED(&ha->iobase->isp24.hccr);
1703
1704 /* Manage unprocessed RIO/ZIO commands in response queue. */
1705 if (vha->flags.process_response_queue &&
1706 rsp->ring_ptr->signature != RESPONSE_PROCESSED)
1707 qla24xx_process_response_queue(vha, rsp);
1708
1709 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1710
1711 return QLA_SUCCESS;
1712
1713queuing_error:
1714 if (status & QDSS_GOT_Q_SPACE) {
1715 req->outstanding_cmds[handle] = NULL;
1716 req->cnt += req_cnt;
1717 }
1718 /* Cleanup will be performed by the caller (queuecommand) */
1719
1720 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Arun Easibad75002010-05-04 15:01:30 -07001721 return QLA_FUNCTION_FAILED;
1722}
1723
1724
Anirban Chakraborty59e0b8b2009-06-03 09:55:19 -07001725static void qla25xx_set_que(srb_t *sp, struct rsp_que **rsp)
Anirban Chakraborty68ca9492009-04-06 22:33:41 -07001726{
1727 struct scsi_cmnd *cmd = sp->cmd;
Anirban Chakraborty68ca9492009-04-06 22:33:41 -07001728 struct qla_hw_data *ha = sp->fcport->vha->hw;
1729 int affinity = cmd->request->cpu;
1730
Anirban Chakraborty7163ea82009-08-05 09:18:40 -07001731 if (ha->flags.cpu_affinity_enabled && affinity >= 0 &&
Anirban Chakraborty59e0b8b2009-06-03 09:55:19 -07001732 affinity < ha->max_rsp_queues - 1)
Anirban Chakraborty68ca9492009-04-06 22:33:41 -07001733 *rsp = ha->rsp_q_map[affinity + 1];
Anirban Chakraborty59e0b8b2009-06-03 09:55:19 -07001734 else
Anirban Chakraborty68ca9492009-04-06 22:33:41 -07001735 *rsp = ha->rsp_q_map[0];
Anirban Chakraborty68ca9492009-04-06 22:33:41 -07001736}
Andrew Vasquezac280b62009-08-20 11:06:05 -07001737
1738/* Generic Control-SRB manipulation functions. */
Giridhar Malavalid94d10e2010-07-23 15:28:23 +05001739void *
1740qla2x00_alloc_iocbs(scsi_qla_host_t *vha, srb_t *sp)
Andrew Vasquezac280b62009-08-20 11:06:05 -07001741{
Andrew Vasquezac280b62009-08-20 11:06:05 -07001742 struct qla_hw_data *ha = vha->hw;
1743 struct req_que *req = ha->req_q_map[0];
1744 device_reg_t __iomem *reg = ISP_QUE_REG(ha, req->id);
1745 uint32_t index, handle;
1746 request_t *pkt;
1747 uint16_t cnt, req_cnt;
1748
1749 pkt = NULL;
1750 req_cnt = 1;
Giridhar Malavalid94d10e2010-07-23 15:28:23 +05001751 handle = 0;
1752
1753 if (!sp)
1754 goto skip_cmd_array;
Andrew Vasquezac280b62009-08-20 11:06:05 -07001755
1756 /* Check for room in outstanding command list. */
1757 handle = req->current_outstanding_cmd;
1758 for (index = 1; index < MAX_OUTSTANDING_COMMANDS; index++) {
1759 handle++;
1760 if (handle == MAX_OUTSTANDING_COMMANDS)
1761 handle = 1;
1762 if (!req->outstanding_cmds[handle])
1763 break;
1764 }
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001765 if (index == MAX_OUTSTANDING_COMMANDS) {
1766 ql_log(ql_log_warn, vha, 0x700b,
1767 "No room on oustanding cmd array.\n");
Andrew Vasquezac280b62009-08-20 11:06:05 -07001768 goto queuing_error;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001769 }
Andrew Vasquezac280b62009-08-20 11:06:05 -07001770
Giridhar Malavalid94d10e2010-07-23 15:28:23 +05001771 /* Prep command array. */
1772 req->current_outstanding_cmd = handle;
1773 req->outstanding_cmds[handle] = sp;
1774 sp->handle = handle;
1775
1776skip_cmd_array:
Andrew Vasquezac280b62009-08-20 11:06:05 -07001777 /* Check for room on request queue. */
1778 if (req->cnt < req_cnt) {
1779 if (ha->mqenable)
1780 cnt = RD_REG_DWORD(&reg->isp25mq.req_q_out);
Giridhar Malavalid94d10e2010-07-23 15:28:23 +05001781 else if (IS_QLA82XX(ha))
1782 cnt = RD_REG_DWORD(&reg->isp82.req_q_out);
Andrew Vasquezac280b62009-08-20 11:06:05 -07001783 else if (IS_FWI2_CAPABLE(ha))
1784 cnt = RD_REG_DWORD(&reg->isp24.req_q_out);
1785 else
1786 cnt = qla2x00_debounce_register(
1787 ISP_REQ_Q_OUT(ha, &reg->isp));
1788
1789 if (req->ring_index < cnt)
1790 req->cnt = cnt - req->ring_index;
1791 else
1792 req->cnt = req->length -
1793 (req->ring_index - cnt);
1794 }
1795 if (req->cnt < req_cnt)
1796 goto queuing_error;
1797
1798 /* Prep packet */
Andrew Vasquezac280b62009-08-20 11:06:05 -07001799 req->cnt -= req_cnt;
Andrew Vasquezac280b62009-08-20 11:06:05 -07001800 pkt = req->ring_ptr;
1801 memset(pkt, 0, REQUEST_ENTRY_SIZE);
1802 pkt->entry_count = req_cnt;
1803 pkt->handle = handle;
Andrew Vasquezac280b62009-08-20 11:06:05 -07001804
1805queuing_error:
1806 return pkt;
1807}
1808
1809static void
1810qla2x00_start_iocbs(srb_t *sp)
1811{
1812 struct qla_hw_data *ha = sp->fcport->vha->hw;
1813 struct req_que *req = ha->req_q_map[0];
1814 device_reg_t __iomem *reg = ISP_QUE_REG(ha, req->id);
1815 struct device_reg_2xxx __iomem *ioreg = &ha->iobase->isp;
1816
Giridhar Malavalia9083012010-04-12 17:59:55 -07001817 if (IS_QLA82XX(ha)) {
1818 qla82xx_start_iocbs(sp);
Andrew Vasquezac280b62009-08-20 11:06:05 -07001819 } else {
Giridhar Malavalia9083012010-04-12 17:59:55 -07001820 /* Adjust ring index. */
1821 req->ring_index++;
1822 if (req->ring_index == req->length) {
1823 req->ring_index = 0;
1824 req->ring_ptr = req->ring;
1825 } else
1826 req->ring_ptr++;
1827
1828 /* Set chip new ring index. */
1829 if (ha->mqenable) {
1830 WRT_REG_DWORD(&reg->isp25mq.req_q_in, req->ring_index);
1831 RD_REG_DWORD(&ioreg->hccr);
1832 } else if (IS_QLA82XX(ha)) {
1833 qla82xx_start_iocbs(sp);
1834 } else if (IS_FWI2_CAPABLE(ha)) {
1835 WRT_REG_DWORD(&reg->isp24.req_q_in, req->ring_index);
1836 RD_REG_DWORD_RELAXED(&reg->isp24.req_q_in);
1837 } else {
1838 WRT_REG_WORD(ISP_REQ_Q_IN(ha, &reg->isp),
1839 req->ring_index);
1840 RD_REG_WORD_RELAXED(ISP_REQ_Q_IN(ha, &reg->isp));
1841 }
Andrew Vasquezac280b62009-08-20 11:06:05 -07001842 }
1843}
1844
1845static void
1846qla24xx_login_iocb(srb_t *sp, struct logio_entry_24xx *logio)
1847{
Madhuranath Iyengar49163922010-05-04 15:01:28 -07001848 struct srb_ctx *ctx = sp->ctx;
1849 struct srb_iocb *lio = ctx->u.iocb_cmd;
Andrew Vasquezac280b62009-08-20 11:06:05 -07001850
1851 logio->entry_type = LOGINOUT_PORT_IOCB_TYPE;
1852 logio->control_flags = cpu_to_le16(LCF_COMMAND_PLOGI);
Madhuranath Iyengar49163922010-05-04 15:01:28 -07001853 if (lio->u.logio.flags & SRB_LOGIN_COND_PLOGI)
Andrew Vasquezac280b62009-08-20 11:06:05 -07001854 logio->control_flags |= cpu_to_le16(LCF_COND_PLOGI);
Madhuranath Iyengar49163922010-05-04 15:01:28 -07001855 if (lio->u.logio.flags & SRB_LOGIN_SKIP_PRLI)
Andrew Vasquezac280b62009-08-20 11:06:05 -07001856 logio->control_flags |= cpu_to_le16(LCF_SKIP_PRLI);
1857 logio->nport_handle = cpu_to_le16(sp->fcport->loop_id);
1858 logio->port_id[0] = sp->fcport->d_id.b.al_pa;
1859 logio->port_id[1] = sp->fcport->d_id.b.area;
1860 logio->port_id[2] = sp->fcport->d_id.b.domain;
1861 logio->vp_index = sp->fcport->vp_idx;
1862}
1863
1864static void
1865qla2x00_login_iocb(srb_t *sp, struct mbx_entry *mbx)
1866{
1867 struct qla_hw_data *ha = sp->fcport->vha->hw;
Madhuranath Iyengar49163922010-05-04 15:01:28 -07001868 struct srb_ctx *ctx = sp->ctx;
1869 struct srb_iocb *lio = ctx->u.iocb_cmd;
Andrew Vasquezac280b62009-08-20 11:06:05 -07001870 uint16_t opts;
1871
Giridhar Malavalib9637522010-05-28 15:08:15 -07001872 mbx->entry_type = MBX_IOCB_TYPE;
Andrew Vasquezac280b62009-08-20 11:06:05 -07001873 SET_TARGET_ID(ha, mbx->loop_id, sp->fcport->loop_id);
1874 mbx->mb0 = cpu_to_le16(MBC_LOGIN_FABRIC_PORT);
Madhuranath Iyengar49163922010-05-04 15:01:28 -07001875 opts = lio->u.logio.flags & SRB_LOGIN_COND_PLOGI ? BIT_0 : 0;
1876 opts |= lio->u.logio.flags & SRB_LOGIN_SKIP_PRLI ? BIT_1 : 0;
Andrew Vasquezac280b62009-08-20 11:06:05 -07001877 if (HAS_EXTENDED_IDS(ha)) {
1878 mbx->mb1 = cpu_to_le16(sp->fcport->loop_id);
1879 mbx->mb10 = cpu_to_le16(opts);
1880 } else {
1881 mbx->mb1 = cpu_to_le16((sp->fcport->loop_id << 8) | opts);
1882 }
1883 mbx->mb2 = cpu_to_le16(sp->fcport->d_id.b.domain);
1884 mbx->mb3 = cpu_to_le16(sp->fcport->d_id.b.area << 8 |
1885 sp->fcport->d_id.b.al_pa);
1886 mbx->mb9 = cpu_to_le16(sp->fcport->vp_idx);
1887}
1888
1889static void
1890qla24xx_logout_iocb(srb_t *sp, struct logio_entry_24xx *logio)
1891{
1892 logio->entry_type = LOGINOUT_PORT_IOCB_TYPE;
1893 logio->control_flags =
1894 cpu_to_le16(LCF_COMMAND_LOGO|LCF_IMPL_LOGO);
1895 logio->nport_handle = cpu_to_le16(sp->fcport->loop_id);
1896 logio->port_id[0] = sp->fcport->d_id.b.al_pa;
1897 logio->port_id[1] = sp->fcport->d_id.b.area;
1898 logio->port_id[2] = sp->fcport->d_id.b.domain;
1899 logio->vp_index = sp->fcport->vp_idx;
1900}
1901
1902static void
1903qla2x00_logout_iocb(srb_t *sp, struct mbx_entry *mbx)
1904{
1905 struct qla_hw_data *ha = sp->fcport->vha->hw;
1906
Giridhar Malavalib9637522010-05-28 15:08:15 -07001907 mbx->entry_type = MBX_IOCB_TYPE;
Andrew Vasquezac280b62009-08-20 11:06:05 -07001908 SET_TARGET_ID(ha, mbx->loop_id, sp->fcport->loop_id);
1909 mbx->mb0 = cpu_to_le16(MBC_LOGOUT_FABRIC_PORT);
1910 mbx->mb1 = HAS_EXTENDED_IDS(ha) ?
1911 cpu_to_le16(sp->fcport->loop_id):
1912 cpu_to_le16(sp->fcport->loop_id << 8);
1913 mbx->mb2 = cpu_to_le16(sp->fcport->d_id.b.domain);
1914 mbx->mb3 = cpu_to_le16(sp->fcport->d_id.b.area << 8 |
1915 sp->fcport->d_id.b.al_pa);
1916 mbx->mb9 = cpu_to_le16(sp->fcport->vp_idx);
1917 /* Implicit: mbx->mbx10 = 0. */
1918}
1919
Giridhar Malavali9a069e12010-01-12 13:02:47 -08001920static void
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07001921qla24xx_adisc_iocb(srb_t *sp, struct logio_entry_24xx *logio)
1922{
1923 logio->entry_type = LOGINOUT_PORT_IOCB_TYPE;
1924 logio->control_flags = cpu_to_le16(LCF_COMMAND_ADISC);
1925 logio->nport_handle = cpu_to_le16(sp->fcport->loop_id);
1926 logio->vp_index = sp->fcport->vp_idx;
1927}
1928
1929static void
1930qla2x00_adisc_iocb(srb_t *sp, struct mbx_entry *mbx)
1931{
1932 struct qla_hw_data *ha = sp->fcport->vha->hw;
1933
1934 mbx->entry_type = MBX_IOCB_TYPE;
1935 SET_TARGET_ID(ha, mbx->loop_id, sp->fcport->loop_id);
1936 mbx->mb0 = cpu_to_le16(MBC_GET_PORT_DATABASE);
1937 if (HAS_EXTENDED_IDS(ha)) {
1938 mbx->mb1 = cpu_to_le16(sp->fcport->loop_id);
1939 mbx->mb10 = cpu_to_le16(BIT_0);
1940 } else {
1941 mbx->mb1 = cpu_to_le16((sp->fcport->loop_id << 8) | BIT_0);
1942 }
1943 mbx->mb2 = cpu_to_le16(MSW(ha->async_pd_dma));
1944 mbx->mb3 = cpu_to_le16(LSW(ha->async_pd_dma));
1945 mbx->mb6 = cpu_to_le16(MSW(MSD(ha->async_pd_dma)));
1946 mbx->mb7 = cpu_to_le16(LSW(MSD(ha->async_pd_dma)));
1947 mbx->mb9 = cpu_to_le16(sp->fcport->vp_idx);
1948}
1949
1950static void
Madhuranath Iyengar38222632010-05-04 15:01:29 -07001951qla24xx_tm_iocb(srb_t *sp, struct tsk_mgmt_entry *tsk)
1952{
1953 uint32_t flags;
1954 unsigned int lun;
1955 struct fc_port *fcport = sp->fcport;
1956 scsi_qla_host_t *vha = fcport->vha;
1957 struct qla_hw_data *ha = vha->hw;
1958 struct srb_ctx *ctx = sp->ctx;
1959 struct srb_iocb *iocb = ctx->u.iocb_cmd;
1960 struct req_que *req = vha->req;
1961
1962 flags = iocb->u.tmf.flags;
1963 lun = iocb->u.tmf.lun;
1964
1965 tsk->entry_type = TSK_MGMT_IOCB_TYPE;
1966 tsk->entry_count = 1;
1967 tsk->handle = MAKE_HANDLE(req->id, tsk->handle);
1968 tsk->nport_handle = cpu_to_le16(fcport->loop_id);
1969 tsk->timeout = cpu_to_le16(ha->r_a_tov / 10 * 2);
1970 tsk->control_flags = cpu_to_le32(flags);
1971 tsk->port_id[0] = fcport->d_id.b.al_pa;
1972 tsk->port_id[1] = fcport->d_id.b.area;
1973 tsk->port_id[2] = fcport->d_id.b.domain;
1974 tsk->vp_index = fcport->vp_idx;
1975
1976 if (flags == TCF_LUN_RESET) {
1977 int_to_scsilun(lun, &tsk->lun);
1978 host_to_fcp_swap((uint8_t *)&tsk->lun,
1979 sizeof(tsk->lun));
1980 }
1981}
1982
1983static void
Giridhar Malavali9a069e12010-01-12 13:02:47 -08001984qla24xx_els_iocb(srb_t *sp, struct els_entry_24xx *els_iocb)
1985{
Madhuranath Iyengar49163922010-05-04 15:01:28 -07001986 struct fc_bsg_job *bsg_job = ((struct srb_ctx *)sp->ctx)->u.bsg_job;
Giridhar Malavali9a069e12010-01-12 13:02:47 -08001987
1988 els_iocb->entry_type = ELS_IOCB_TYPE;
1989 els_iocb->entry_count = 1;
1990 els_iocb->sys_define = 0;
1991 els_iocb->entry_status = 0;
1992 els_iocb->handle = sp->handle;
1993 els_iocb->nport_handle = cpu_to_le16(sp->fcport->loop_id);
1994 els_iocb->tx_dsd_count = __constant_cpu_to_le16(bsg_job->request_payload.sg_cnt);
1995 els_iocb->vp_index = sp->fcport->vp_idx;
1996 els_iocb->sof_type = EST_SOFI3;
1997 els_iocb->rx_dsd_count = __constant_cpu_to_le16(bsg_job->reply_payload.sg_cnt);
1998
Madhuranath Iyengar49163922010-05-04 15:01:28 -07001999 els_iocb->opcode =
2000 (((struct srb_ctx *)sp->ctx)->type == SRB_ELS_CMD_RPT) ?
2001 bsg_job->request->rqst_data.r_els.els_code :
2002 bsg_job->request->rqst_data.h_els.command_code;
Giridhar Malavali9a069e12010-01-12 13:02:47 -08002003 els_iocb->port_id[0] = sp->fcport->d_id.b.al_pa;
2004 els_iocb->port_id[1] = sp->fcport->d_id.b.area;
2005 els_iocb->port_id[2] = sp->fcport->d_id.b.domain;
2006 els_iocb->control_flags = 0;
2007 els_iocb->rx_byte_count =
2008 cpu_to_le32(bsg_job->reply_payload.payload_len);
2009 els_iocb->tx_byte_count =
2010 cpu_to_le32(bsg_job->request_payload.payload_len);
2011
2012 els_iocb->tx_address[0] = cpu_to_le32(LSD(sg_dma_address
2013 (bsg_job->request_payload.sg_list)));
2014 els_iocb->tx_address[1] = cpu_to_le32(MSD(sg_dma_address
2015 (bsg_job->request_payload.sg_list)));
2016 els_iocb->tx_len = cpu_to_le32(sg_dma_len
2017 (bsg_job->request_payload.sg_list));
2018
2019 els_iocb->rx_address[0] = cpu_to_le32(LSD(sg_dma_address
2020 (bsg_job->reply_payload.sg_list)));
2021 els_iocb->rx_address[1] = cpu_to_le32(MSD(sg_dma_address
2022 (bsg_job->reply_payload.sg_list)));
2023 els_iocb->rx_len = cpu_to_le32(sg_dma_len
2024 (bsg_job->reply_payload.sg_list));
2025}
2026
2027static void
Harish Zunjarrao9bc4f4f2010-07-23 15:28:32 +05002028qla2x00_ct_iocb(srb_t *sp, ms_iocb_entry_t *ct_iocb)
2029{
2030 uint16_t avail_dsds;
2031 uint32_t *cur_dsd;
2032 struct scatterlist *sg;
2033 int index;
2034 uint16_t tot_dsds;
2035 scsi_qla_host_t *vha = sp->fcport->vha;
2036 struct qla_hw_data *ha = vha->hw;
2037 struct fc_bsg_job *bsg_job = ((struct srb_ctx *)sp->ctx)->u.bsg_job;
2038 int loop_iterartion = 0;
2039 int cont_iocb_prsnt = 0;
2040 int entry_count = 1;
2041
2042 memset(ct_iocb, 0, sizeof(ms_iocb_entry_t));
2043 ct_iocb->entry_type = CT_IOCB_TYPE;
2044 ct_iocb->entry_status = 0;
2045 ct_iocb->handle1 = sp->handle;
2046 SET_TARGET_ID(ha, ct_iocb->loop_id, sp->fcport->loop_id);
2047 ct_iocb->status = __constant_cpu_to_le16(0);
2048 ct_iocb->control_flags = __constant_cpu_to_le16(0);
2049 ct_iocb->timeout = 0;
2050 ct_iocb->cmd_dsd_count =
2051 __constant_cpu_to_le16(bsg_job->request_payload.sg_cnt);
2052 ct_iocb->total_dsd_count =
2053 __constant_cpu_to_le16(bsg_job->request_payload.sg_cnt + 1);
2054 ct_iocb->req_bytecount =
2055 cpu_to_le32(bsg_job->request_payload.payload_len);
2056 ct_iocb->rsp_bytecount =
2057 cpu_to_le32(bsg_job->reply_payload.payload_len);
2058
2059 ct_iocb->dseg_req_address[0] = cpu_to_le32(LSD(sg_dma_address
2060 (bsg_job->request_payload.sg_list)));
2061 ct_iocb->dseg_req_address[1] = cpu_to_le32(MSD(sg_dma_address
2062 (bsg_job->request_payload.sg_list)));
2063 ct_iocb->dseg_req_length = ct_iocb->req_bytecount;
2064
2065 ct_iocb->dseg_rsp_address[0] = cpu_to_le32(LSD(sg_dma_address
2066 (bsg_job->reply_payload.sg_list)));
2067 ct_iocb->dseg_rsp_address[1] = cpu_to_le32(MSD(sg_dma_address
2068 (bsg_job->reply_payload.sg_list)));
2069 ct_iocb->dseg_rsp_length = ct_iocb->rsp_bytecount;
2070
2071 avail_dsds = 1;
2072 cur_dsd = (uint32_t *)ct_iocb->dseg_rsp_address;
2073 index = 0;
2074 tot_dsds = bsg_job->reply_payload.sg_cnt;
2075
2076 for_each_sg(bsg_job->reply_payload.sg_list, sg, tot_dsds, index) {
2077 dma_addr_t sle_dma;
2078 cont_a64_entry_t *cont_pkt;
2079
2080 /* Allocate additional continuation packets? */
2081 if (avail_dsds == 0) {
2082 /*
2083 * Five DSDs are available in the Cont.
2084 * Type 1 IOCB.
2085 */
2086 cont_pkt = qla2x00_prep_cont_type1_iocb(vha);
2087 cur_dsd = (uint32_t *) cont_pkt->dseg_0_address;
2088 avail_dsds = 5;
2089 cont_iocb_prsnt = 1;
2090 entry_count++;
2091 }
2092
2093 sle_dma = sg_dma_address(sg);
2094 *cur_dsd++ = cpu_to_le32(LSD(sle_dma));
2095 *cur_dsd++ = cpu_to_le32(MSD(sle_dma));
2096 *cur_dsd++ = cpu_to_le32(sg_dma_len(sg));
2097 loop_iterartion++;
2098 avail_dsds--;
2099 }
2100 ct_iocb->entry_count = entry_count;
2101}
2102
2103static void
Giridhar Malavali9a069e12010-01-12 13:02:47 -08002104qla24xx_ct_iocb(srb_t *sp, struct ct_entry_24xx *ct_iocb)
2105{
2106 uint16_t avail_dsds;
2107 uint32_t *cur_dsd;
2108 struct scatterlist *sg;
2109 int index;
2110 uint16_t tot_dsds;
2111 scsi_qla_host_t *vha = sp->fcport->vha;
Madhuranath Iyengar49163922010-05-04 15:01:28 -07002112 struct fc_bsg_job *bsg_job = ((struct srb_ctx *)sp->ctx)->u.bsg_job;
Giridhar Malavali9a069e12010-01-12 13:02:47 -08002113 int loop_iterartion = 0;
2114 int cont_iocb_prsnt = 0;
2115 int entry_count = 1;
2116
2117 ct_iocb->entry_type = CT_IOCB_TYPE;
2118 ct_iocb->entry_status = 0;
2119 ct_iocb->sys_define = 0;
2120 ct_iocb->handle = sp->handle;
2121
2122 ct_iocb->nport_handle = cpu_to_le16(sp->fcport->loop_id);
2123 ct_iocb->vp_index = sp->fcport->vp_idx;
2124 ct_iocb->comp_status = __constant_cpu_to_le16(0);
2125
2126 ct_iocb->cmd_dsd_count =
2127 __constant_cpu_to_le16(bsg_job->request_payload.sg_cnt);
2128 ct_iocb->timeout = 0;
2129 ct_iocb->rsp_dsd_count =
2130 __constant_cpu_to_le16(bsg_job->reply_payload.sg_cnt);
2131 ct_iocb->rsp_byte_count =
2132 cpu_to_le32(bsg_job->reply_payload.payload_len);
2133 ct_iocb->cmd_byte_count =
2134 cpu_to_le32(bsg_job->request_payload.payload_len);
2135 ct_iocb->dseg_0_address[0] = cpu_to_le32(LSD(sg_dma_address
2136 (bsg_job->request_payload.sg_list)));
2137 ct_iocb->dseg_0_address[1] = cpu_to_le32(MSD(sg_dma_address
2138 (bsg_job->request_payload.sg_list)));
2139 ct_iocb->dseg_0_len = cpu_to_le32(sg_dma_len
2140 (bsg_job->request_payload.sg_list));
2141
2142 avail_dsds = 1;
2143 cur_dsd = (uint32_t *)ct_iocb->dseg_1_address;
2144 index = 0;
2145 tot_dsds = bsg_job->reply_payload.sg_cnt;
2146
2147 for_each_sg(bsg_job->reply_payload.sg_list, sg, tot_dsds, index) {
2148 dma_addr_t sle_dma;
2149 cont_a64_entry_t *cont_pkt;
2150
2151 /* Allocate additional continuation packets? */
2152 if (avail_dsds == 0) {
2153 /*
2154 * Five DSDs are available in the Cont.
2155 * Type 1 IOCB.
2156 */
2157 cont_pkt = qla2x00_prep_cont_type1_iocb(vha);
2158 cur_dsd = (uint32_t *) cont_pkt->dseg_0_address;
2159 avail_dsds = 5;
2160 cont_iocb_prsnt = 1;
2161 entry_count++;
2162 }
2163
2164 sle_dma = sg_dma_address(sg);
2165 *cur_dsd++ = cpu_to_le32(LSD(sle_dma));
2166 *cur_dsd++ = cpu_to_le32(MSD(sle_dma));
2167 *cur_dsd++ = cpu_to_le32(sg_dma_len(sg));
2168 loop_iterartion++;
2169 avail_dsds--;
2170 }
2171 ct_iocb->entry_count = entry_count;
2172}
2173
Andrew Vasquezac280b62009-08-20 11:06:05 -07002174int
2175qla2x00_start_sp(srb_t *sp)
2176{
2177 int rval;
2178 struct qla_hw_data *ha = sp->fcport->vha->hw;
2179 void *pkt;
2180 struct srb_ctx *ctx = sp->ctx;
2181 unsigned long flags;
2182
2183 rval = QLA_FUNCTION_FAILED;
2184 spin_lock_irqsave(&ha->hardware_lock, flags);
Giridhar Malavalid94d10e2010-07-23 15:28:23 +05002185 pkt = qla2x00_alloc_iocbs(sp->fcport->vha, sp);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002186 if (!pkt) {
2187 ql_log(ql_log_warn, sp->fcport->vha, 0x700c,
2188 "qla2x00_alloc_iocbs failed.\n");
Andrew Vasquezac280b62009-08-20 11:06:05 -07002189 goto done;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002190 }
Andrew Vasquezac280b62009-08-20 11:06:05 -07002191
2192 rval = QLA_SUCCESS;
2193 switch (ctx->type) {
2194 case SRB_LOGIN_CMD:
2195 IS_FWI2_CAPABLE(ha) ?
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07002196 qla24xx_login_iocb(sp, pkt) :
Andrew Vasquezac280b62009-08-20 11:06:05 -07002197 qla2x00_login_iocb(sp, pkt);
2198 break;
2199 case SRB_LOGOUT_CMD:
2200 IS_FWI2_CAPABLE(ha) ?
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07002201 qla24xx_logout_iocb(sp, pkt) :
Andrew Vasquezac280b62009-08-20 11:06:05 -07002202 qla2x00_logout_iocb(sp, pkt);
2203 break;
Giridhar Malavali9a069e12010-01-12 13:02:47 -08002204 case SRB_ELS_CMD_RPT:
2205 case SRB_ELS_CMD_HST:
2206 qla24xx_els_iocb(sp, pkt);
2207 break;
2208 case SRB_CT_CMD:
Harish Zunjarrao9bc4f4f2010-07-23 15:28:32 +05002209 IS_FWI2_CAPABLE(ha) ?
2210 qla24xx_ct_iocb(sp, pkt) :
2211 qla2x00_ct_iocb(sp, pkt);
Giridhar Malavali9a069e12010-01-12 13:02:47 -08002212 break;
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07002213 case SRB_ADISC_CMD:
2214 IS_FWI2_CAPABLE(ha) ?
2215 qla24xx_adisc_iocb(sp, pkt) :
2216 qla2x00_adisc_iocb(sp, pkt);
2217 break;
Madhuranath Iyengar38222632010-05-04 15:01:29 -07002218 case SRB_TM_CMD:
2219 qla24xx_tm_iocb(sp, pkt);
2220 break;
Andrew Vasquezac280b62009-08-20 11:06:05 -07002221 default:
2222 break;
2223 }
2224
2225 wmb();
2226 qla2x00_start_iocbs(sp);
2227done:
2228 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2229 return rval;
2230}