Andrew Vasquez | fa90c54 | 2005-10-27 11:10:08 -0700 | [diff] [blame] | 1 | /* |
| 2 | * QLogic Fibre Channel HBA Driver |
Andrew Vasquez | 07e264b | 2011-03-30 11:46:23 -0700 | [diff] [blame] | 3 | * Copyright (c) 2003-2011 QLogic Corporation |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4 | * |
Andrew Vasquez | fa90c54 | 2005-10-27 11:10:08 -0700 | [diff] [blame] | 5 | * See LICENSE.qla2xxx for copyright and licensing details. |
| 6 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7 | #include "qla_def.h" |
| 8 | |
| 9 | #include <linux/blkdev.h> |
| 10 | #include <linux/delay.h> |
| 11 | |
| 12 | #include <scsi/scsi_tcq.h> |
| 13 | |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 14 | static void qla2x00_isp_cmd(struct scsi_qla_host *, struct req_que *); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15 | |
Anirban Chakraborty | 59e0b8b | 2009-06-03 09:55:19 -0700 | [diff] [blame] | 16 | static void qla25xx_set_que(srb_t *, struct rsp_que **); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17 | /** |
| 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 | */ |
| 23 | static inline uint16_t |
Harish Zunjarrao | 49fd462 | 2008-09-11 21:22:47 -0700 | [diff] [blame] | 24 | qla2x00_get_cmd_direction(srb_t *sp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 25 | { |
| 26 | uint16_t cflags; |
| 27 | |
| 28 | cflags = 0; |
| 29 | |
| 30 | /* Set transfer direction */ |
Harish Zunjarrao | 49fd462 | 2008-09-11 21:22:47 -0700 | [diff] [blame] | 31 | if (sp->cmd->sc_data_direction == DMA_TO_DEVICE) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 32 | cflags = CF_WRITE; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 33 | sp->fcport->vha->hw->qla_stats.output_bytes += |
Harish Zunjarrao | 49fd462 | 2008-09-11 21:22:47 -0700 | [diff] [blame] | 34 | scsi_bufflen(sp->cmd); |
| 35 | } else if (sp->cmd->sc_data_direction == DMA_FROM_DEVICE) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 36 | cflags = CF_READ; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 37 | sp->fcport->vha->hw->qla_stats.input_bytes += |
Harish Zunjarrao | 49fd462 | 2008-09-11 21:22:47 -0700 | [diff] [blame] | 38 | scsi_bufflen(sp->cmd); |
| 39 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 40 | 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 | */ |
| 51 | uint16_t |
| 52 | qla2x00_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 | */ |
| 73 | uint16_t |
| 74 | qla2x00_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 | */ |
| 93 | static inline cont_entry_t * |
Anirban Chakraborty | 67c2e93 | 2009-04-06 22:33:42 -0700 | [diff] [blame] | 94 | qla2x00_prep_cont_type0_iocb(struct scsi_qla_host *vha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 95 | { |
| 96 | cont_entry_t *cont_pkt; |
Anirban Chakraborty | 67c2e93 | 2009-04-06 22:33:42 -0700 | [diff] [blame] | 97 | struct req_que *req = vha->req; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 98 | /* Adjust ring index. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 99 | req->ring_index++; |
| 100 | if (req->ring_index == req->length) { |
| 101 | req->ring_index = 0; |
| 102 | req->ring_ptr = req->ring; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 103 | } else { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 104 | req->ring_ptr++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 105 | } |
| 106 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 107 | cont_pkt = (cont_entry_t *)req->ring_ptr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 108 | |
| 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 | */ |
| 122 | static inline cont_a64_entry_t * |
Giridhar Malavali | 0d2aa38 | 2011-11-18 09:02:21 -0800 | [diff] [blame] | 123 | qla2x00_prep_cont_type1_iocb(scsi_qla_host_t *vha, struct req_que *req) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 124 | { |
| 125 | cont_a64_entry_t *cont_pkt; |
| 126 | |
| 127 | /* Adjust ring index. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 128 | req->ring_index++; |
| 129 | if (req->ring_index == req->length) { |
| 130 | req->ring_index = 0; |
| 131 | req->ring_ptr = req->ring; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 132 | } else { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 133 | req->ring_ptr++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 134 | } |
| 135 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 136 | cont_pkt = (cont_a64_entry_t *)req->ring_ptr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 137 | |
| 138 | /* Load packet defaults. */ |
| 139 | *((uint32_t *)(&cont_pkt->entry_type)) = |
| 140 | __constant_cpu_to_le32(CONTINUE_A64_TYPE); |
| 141 | |
| 142 | return (cont_pkt); |
| 143 | } |
| 144 | |
Arun Easi | bad7500 | 2010-05-04 15:01:30 -0700 | [diff] [blame] | 145 | static inline int |
| 146 | qla24xx_configure_prot_mode(srb_t *sp, uint16_t *fw_prot_opts) |
| 147 | { |
| 148 | uint8_t guard = scsi_host_get_guard(sp->cmd->device->host); |
| 149 | |
| 150 | /* We only support T10 DIF right now */ |
| 151 | if (guard != SHOST_DIX_GUARD_CRC) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 152 | ql_dbg(ql_dbg_io, sp->fcport->vha, 0x3007, |
| 153 | "Unsupported guard: %d for cmd=%p.\n", guard, sp->cmd); |
Arun Easi | bad7500 | 2010-05-04 15:01:30 -0700 | [diff] [blame] | 154 | return 0; |
| 155 | } |
| 156 | |
| 157 | /* We always use DIFF Bundling for best performance */ |
| 158 | *fw_prot_opts = 0; |
| 159 | |
| 160 | /* Translate SCSI opcode to a protection opcode */ |
| 161 | switch (scsi_get_prot_op(sp->cmd)) { |
| 162 | case SCSI_PROT_READ_STRIP: |
| 163 | *fw_prot_opts |= PO_MODE_DIF_REMOVE; |
| 164 | break; |
| 165 | case SCSI_PROT_WRITE_INSERT: |
| 166 | *fw_prot_opts |= PO_MODE_DIF_INSERT; |
| 167 | break; |
| 168 | case SCSI_PROT_READ_INSERT: |
| 169 | *fw_prot_opts |= PO_MODE_DIF_INSERT; |
| 170 | break; |
| 171 | case SCSI_PROT_WRITE_STRIP: |
| 172 | *fw_prot_opts |= PO_MODE_DIF_REMOVE; |
| 173 | break; |
| 174 | case SCSI_PROT_READ_PASS: |
| 175 | *fw_prot_opts |= PO_MODE_DIF_PASS; |
| 176 | break; |
| 177 | case SCSI_PROT_WRITE_PASS: |
| 178 | *fw_prot_opts |= PO_MODE_DIF_PASS; |
| 179 | break; |
| 180 | default: /* Normal Request */ |
| 181 | *fw_prot_opts |= PO_MODE_DIF_PASS; |
| 182 | break; |
| 183 | } |
| 184 | |
| 185 | return scsi_prot_sg_count(sp->cmd); |
| 186 | } |
| 187 | |
| 188 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 189 | * qla2x00_build_scsi_iocbs_32() - Build IOCB command utilizing 32bit |
| 190 | * capable IOCB types. |
| 191 | * |
| 192 | * @sp: SRB command to process |
| 193 | * @cmd_pkt: Command type 2 IOCB |
| 194 | * @tot_dsds: Total number of segments to transfer |
| 195 | */ |
| 196 | void qla2x00_build_scsi_iocbs_32(srb_t *sp, cmd_entry_t *cmd_pkt, |
| 197 | uint16_t tot_dsds) |
| 198 | { |
| 199 | uint16_t avail_dsds; |
| 200 | uint32_t *cur_dsd; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 201 | scsi_qla_host_t *vha; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 202 | struct scsi_cmnd *cmd; |
FUJITA Tomonori | 385d70b | 2007-05-26 01:55:38 +0900 | [diff] [blame] | 203 | struct scatterlist *sg; |
| 204 | int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 205 | |
| 206 | cmd = sp->cmd; |
| 207 | |
| 208 | /* Update entry type to indicate Command Type 2 IOCB */ |
| 209 | *((uint32_t *)(&cmd_pkt->entry_type)) = |
| 210 | __constant_cpu_to_le32(COMMAND_TYPE); |
| 211 | |
| 212 | /* No data transfer */ |
FUJITA Tomonori | 385d70b | 2007-05-26 01:55:38 +0900 | [diff] [blame] | 213 | if (!scsi_bufflen(cmd) || cmd->sc_data_direction == DMA_NONE) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 214 | cmd_pkt->byte_count = __constant_cpu_to_le32(0); |
| 215 | return; |
| 216 | } |
| 217 | |
Andrew Vasquez | 444786d | 2009-01-05 11:18:10 -0800 | [diff] [blame] | 218 | vha = sp->fcport->vha; |
Harish Zunjarrao | 49fd462 | 2008-09-11 21:22:47 -0700 | [diff] [blame] | 219 | cmd_pkt->control_flags |= cpu_to_le16(qla2x00_get_cmd_direction(sp)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 220 | |
| 221 | /* Three DSDs are available in the Command Type 2 IOCB */ |
| 222 | avail_dsds = 3; |
| 223 | cur_dsd = (uint32_t *)&cmd_pkt->dseg_0_address; |
| 224 | |
| 225 | /* Load data segments */ |
FUJITA Tomonori | 385d70b | 2007-05-26 01:55:38 +0900 | [diff] [blame] | 226 | scsi_for_each_sg(cmd, sg, tot_dsds, i) { |
| 227 | cont_entry_t *cont_pkt; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 228 | |
FUJITA Tomonori | 385d70b | 2007-05-26 01:55:38 +0900 | [diff] [blame] | 229 | /* Allocate additional continuation packets? */ |
| 230 | if (avail_dsds == 0) { |
| 231 | /* |
| 232 | * Seven DSDs are available in the Continuation |
| 233 | * Type 0 IOCB. |
| 234 | */ |
Anirban Chakraborty | 67c2e93 | 2009-04-06 22:33:42 -0700 | [diff] [blame] | 235 | cont_pkt = qla2x00_prep_cont_type0_iocb(vha); |
FUJITA Tomonori | 385d70b | 2007-05-26 01:55:38 +0900 | [diff] [blame] | 236 | cur_dsd = (uint32_t *)&cont_pkt->dseg_0_address; |
| 237 | avail_dsds = 7; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 238 | } |
FUJITA Tomonori | 385d70b | 2007-05-26 01:55:38 +0900 | [diff] [blame] | 239 | |
| 240 | *cur_dsd++ = cpu_to_le32(sg_dma_address(sg)); |
| 241 | *cur_dsd++ = cpu_to_le32(sg_dma_len(sg)); |
| 242 | avail_dsds--; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 243 | } |
| 244 | } |
| 245 | |
| 246 | /** |
| 247 | * qla2x00_build_scsi_iocbs_64() - Build IOCB command utilizing 64bit |
| 248 | * capable IOCB types. |
| 249 | * |
| 250 | * @sp: SRB command to process |
| 251 | * @cmd_pkt: Command type 3 IOCB |
| 252 | * @tot_dsds: Total number of segments to transfer |
| 253 | */ |
| 254 | void qla2x00_build_scsi_iocbs_64(srb_t *sp, cmd_entry_t *cmd_pkt, |
| 255 | uint16_t tot_dsds) |
| 256 | { |
| 257 | uint16_t avail_dsds; |
| 258 | uint32_t *cur_dsd; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 259 | scsi_qla_host_t *vha; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 260 | struct scsi_cmnd *cmd; |
FUJITA Tomonori | 385d70b | 2007-05-26 01:55:38 +0900 | [diff] [blame] | 261 | struct scatterlist *sg; |
| 262 | int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 263 | |
| 264 | cmd = sp->cmd; |
| 265 | |
| 266 | /* Update entry type to indicate Command Type 3 IOCB */ |
| 267 | *((uint32_t *)(&cmd_pkt->entry_type)) = |
| 268 | __constant_cpu_to_le32(COMMAND_A64_TYPE); |
| 269 | |
| 270 | /* No data transfer */ |
FUJITA Tomonori | 385d70b | 2007-05-26 01:55:38 +0900 | [diff] [blame] | 271 | if (!scsi_bufflen(cmd) || cmd->sc_data_direction == DMA_NONE) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 272 | cmd_pkt->byte_count = __constant_cpu_to_le32(0); |
| 273 | return; |
| 274 | } |
| 275 | |
Andrew Vasquez | 444786d | 2009-01-05 11:18:10 -0800 | [diff] [blame] | 276 | vha = sp->fcport->vha; |
Harish Zunjarrao | 49fd462 | 2008-09-11 21:22:47 -0700 | [diff] [blame] | 277 | cmd_pkt->control_flags |= cpu_to_le16(qla2x00_get_cmd_direction(sp)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 278 | |
| 279 | /* Two DSDs are available in the Command Type 3 IOCB */ |
| 280 | avail_dsds = 2; |
| 281 | cur_dsd = (uint32_t *)&cmd_pkt->dseg_0_address; |
| 282 | |
| 283 | /* Load data segments */ |
FUJITA Tomonori | 385d70b | 2007-05-26 01:55:38 +0900 | [diff] [blame] | 284 | scsi_for_each_sg(cmd, sg, tot_dsds, i) { |
| 285 | dma_addr_t sle_dma; |
| 286 | cont_a64_entry_t *cont_pkt; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 287 | |
FUJITA Tomonori | 385d70b | 2007-05-26 01:55:38 +0900 | [diff] [blame] | 288 | /* Allocate additional continuation packets? */ |
| 289 | if (avail_dsds == 0) { |
| 290 | /* |
| 291 | * Five DSDs are available in the Continuation |
| 292 | * Type 1 IOCB. |
| 293 | */ |
Giridhar Malavali | 0d2aa38 | 2011-11-18 09:02:21 -0800 | [diff] [blame] | 294 | cont_pkt = qla2x00_prep_cont_type1_iocb(vha, vha->req); |
FUJITA Tomonori | 385d70b | 2007-05-26 01:55:38 +0900 | [diff] [blame] | 295 | cur_dsd = (uint32_t *)cont_pkt->dseg_0_address; |
| 296 | avail_dsds = 5; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 297 | } |
FUJITA Tomonori | 385d70b | 2007-05-26 01:55:38 +0900 | [diff] [blame] | 298 | |
| 299 | sle_dma = sg_dma_address(sg); |
| 300 | *cur_dsd++ = cpu_to_le32(LSD(sle_dma)); |
| 301 | *cur_dsd++ = cpu_to_le32(MSD(sle_dma)); |
| 302 | *cur_dsd++ = cpu_to_le32(sg_dma_len(sg)); |
| 303 | avail_dsds--; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 304 | } |
| 305 | } |
| 306 | |
| 307 | /** |
| 308 | * qla2x00_start_scsi() - Send a SCSI command to the ISP |
| 309 | * @sp: command to send to the ISP |
| 310 | * |
Bjorn Helgaas | cc3ef7b | 2008-09-11 21:22:51 -0700 | [diff] [blame] | 311 | * Returns non-zero if a failure occurred, else zero. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 312 | */ |
| 313 | int |
| 314 | qla2x00_start_scsi(srb_t *sp) |
| 315 | { |
FUJITA Tomonori | 385d70b | 2007-05-26 01:55:38 +0900 | [diff] [blame] | 316 | int ret, nseg; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 317 | unsigned long flags; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 318 | scsi_qla_host_t *vha; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 319 | struct scsi_cmnd *cmd; |
| 320 | uint32_t *clr_ptr; |
| 321 | uint32_t index; |
| 322 | uint32_t handle; |
| 323 | cmd_entry_t *cmd_pkt; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 324 | uint16_t cnt; |
| 325 | uint16_t req_cnt; |
| 326 | uint16_t tot_dsds; |
Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame] | 327 | struct device_reg_2xxx __iomem *reg; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 328 | struct qla_hw_data *ha; |
| 329 | struct req_que *req; |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 330 | struct rsp_que *rsp; |
Andrew Vasquez | ff2fc42 | 2011-02-23 15:27:15 -0800 | [diff] [blame] | 331 | char tag[2]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 332 | |
| 333 | /* Setup device pointers. */ |
| 334 | ret = 0; |
Andrew Vasquez | 444786d | 2009-01-05 11:18:10 -0800 | [diff] [blame] | 335 | vha = sp->fcport->vha; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 336 | ha = vha->hw; |
Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame] | 337 | reg = &ha->iobase->isp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 338 | cmd = sp->cmd; |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 339 | req = ha->req_q_map[0]; |
| 340 | rsp = ha->rsp_q_map[0]; |
| 8302192 | 2005-04-17 15:10:41 -0500 | [diff] [blame] | 341 | /* So we know we haven't pci_map'ed anything yet */ |
| 342 | tot_dsds = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 343 | |
| 344 | /* Send marker if required */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 345 | if (vha->marker_needed != 0) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 346 | if (qla2x00_marker(vha, req, rsp, 0, 0, MK_SYNC_ALL) != |
| 347 | QLA_SUCCESS) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 348 | return (QLA_FUNCTION_FAILED); |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 349 | } |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 350 | vha->marker_needed = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 351 | } |
| 352 | |
| 353 | /* Acquire ring specific lock */ |
Andrew Vasquez | c9c5ced | 2008-07-24 08:31:49 -0700 | [diff] [blame] | 354 | spin_lock_irqsave(&ha->hardware_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 355 | |
| 356 | /* Check for room in outstanding command list. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 357 | handle = req->current_outstanding_cmd; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 358 | for (index = 1; index < MAX_OUTSTANDING_COMMANDS; index++) { |
| 359 | handle++; |
| 360 | if (handle == MAX_OUTSTANDING_COMMANDS) |
| 361 | handle = 1; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 362 | if (!req->outstanding_cmds[handle]) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 363 | break; |
| 364 | } |
| 365 | if (index == MAX_OUTSTANDING_COMMANDS) |
| 366 | goto queuing_error; |
| 367 | |
| 8302192 | 2005-04-17 15:10:41 -0500 | [diff] [blame] | 368 | /* Map the sg table so we have an accurate count of sg entries needed */ |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 369 | if (scsi_sg_count(cmd)) { |
| 370 | nseg = dma_map_sg(&ha->pdev->dev, scsi_sglist(cmd), |
| 371 | scsi_sg_count(cmd), cmd->sc_data_direction); |
| 372 | if (unlikely(!nseg)) |
| 373 | goto queuing_error; |
| 374 | } else |
| 375 | nseg = 0; |
| 376 | |
FUJITA Tomonori | 385d70b | 2007-05-26 01:55:38 +0900 | [diff] [blame] | 377 | tot_dsds = nseg; |
| 8302192 | 2005-04-17 15:10:41 -0500 | [diff] [blame] | 378 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 379 | /* Calculate the number of request entries needed. */ |
Andrew Vasquez | fd34f55 | 2007-07-19 15:06:00 -0700 | [diff] [blame] | 380 | req_cnt = ha->isp_ops->calc_req_entries(tot_dsds); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 381 | if (req->cnt < (req_cnt + 2)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 382 | cnt = RD_REG_WORD_RELAXED(ISP_REQ_Q_OUT(ha, reg)); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 383 | if (req->ring_index < cnt) |
| 384 | req->cnt = cnt - req->ring_index; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 385 | else |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 386 | req->cnt = req->length - |
| 387 | (req->ring_index - cnt); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 388 | } |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 389 | if (req->cnt < (req_cnt + 2)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 390 | goto queuing_error; |
| 391 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 392 | /* Build command packet */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 393 | req->current_outstanding_cmd = handle; |
| 394 | req->outstanding_cmds[handle] = sp; |
Andrew Vasquez | cf53b06 | 2009-08-20 11:06:04 -0700 | [diff] [blame] | 395 | sp->handle = handle; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 396 | sp->cmd->host_scribble = (unsigned char *)(unsigned long)handle; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 397 | req->cnt -= req_cnt; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 398 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 399 | cmd_pkt = (cmd_entry_t *)req->ring_ptr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 400 | cmd_pkt->handle = handle; |
| 401 | /* Zero out remaining portion of packet. */ |
| 402 | clr_ptr = (uint32_t *)cmd_pkt + 2; |
| 403 | memset(clr_ptr, 0, REQUEST_ENTRY_SIZE - 8); |
| 404 | cmd_pkt->dseg_count = cpu_to_le16(tot_dsds); |
| 405 | |
| bdf7962 | 2005-04-17 15:06:53 -0500 | [diff] [blame] | 406 | /* Set target ID and LUN number*/ |
| 407 | SET_TARGET_ID(ha, cmd_pkt->target, sp->fcport->loop_id); |
| 408 | cmd_pkt->lun = cpu_to_le16(sp->cmd->device->lun); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 409 | |
| 410 | /* Update tagged queuing modifier */ |
Andrew Vasquez | ff2fc42 | 2011-02-23 15:27:15 -0800 | [diff] [blame] | 411 | if (scsi_populate_tag_msg(cmd, tag)) { |
| 412 | switch (tag[0]) { |
| 413 | case HEAD_OF_QUEUE_TAG: |
| 414 | cmd_pkt->control_flags = |
| 415 | __constant_cpu_to_le16(CF_HEAD_TAG); |
| 416 | break; |
| 417 | case ORDERED_QUEUE_TAG: |
| 418 | cmd_pkt->control_flags = |
| 419 | __constant_cpu_to_le16(CF_ORDERED_TAG); |
| 420 | break; |
| 421 | default: |
| 422 | cmd_pkt->control_flags = |
| 423 | __constant_cpu_to_le16(CF_SIMPLE_TAG); |
| 424 | break; |
| 425 | } |
| 426 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 427 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 428 | /* Load SCSI command packet. */ |
| 429 | memcpy(cmd_pkt->scsi_cdb, cmd->cmnd, cmd->cmd_len); |
FUJITA Tomonori | 385d70b | 2007-05-26 01:55:38 +0900 | [diff] [blame] | 430 | cmd_pkt->byte_count = cpu_to_le32((uint32_t)scsi_bufflen(cmd)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 431 | |
| 432 | /* Build IOCB segments */ |
Andrew Vasquez | fd34f55 | 2007-07-19 15:06:00 -0700 | [diff] [blame] | 433 | ha->isp_ops->build_iocbs(sp, cmd_pkt, tot_dsds); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 434 | |
| 435 | /* Set total data segment count. */ |
| 436 | cmd_pkt->entry_count = (uint8_t)req_cnt; |
| 437 | wmb(); |
| 438 | |
| 439 | /* Adjust ring index. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 440 | req->ring_index++; |
| 441 | if (req->ring_index == req->length) { |
| 442 | req->ring_index = 0; |
| 443 | req->ring_ptr = req->ring; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 444 | } else |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 445 | req->ring_ptr++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 446 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 447 | sp->flags |= SRB_DMA_VALID; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 448 | |
| 449 | /* Set chip new ring index. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 450 | WRT_REG_WORD(ISP_REQ_Q_IN(ha, reg), req->ring_index); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 451 | RD_REG_WORD_RELAXED(ISP_REQ_Q_IN(ha, reg)); /* PCI Posting. */ |
| 452 | |
Andrew Vasquez | 4fdfefe | 2005-10-27 11:09:48 -0700 | [diff] [blame] | 453 | /* Manage unprocessed RIO/ZIO commands in response queue. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 454 | if (vha->flags.process_response_queue && |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 455 | rsp->ring_ptr->signature != RESPONSE_PROCESSED) |
| 456 | qla2x00_process_response_queue(rsp); |
Andrew Vasquez | 4fdfefe | 2005-10-27 11:09:48 -0700 | [diff] [blame] | 457 | |
Andrew Vasquez | c9c5ced | 2008-07-24 08:31:49 -0700 | [diff] [blame] | 458 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 459 | return (QLA_SUCCESS); |
| 460 | |
| 461 | queuing_error: |
FUJITA Tomonori | 385d70b | 2007-05-26 01:55:38 +0900 | [diff] [blame] | 462 | if (tot_dsds) |
| 463 | scsi_dma_unmap(cmd); |
| 464 | |
Andrew Vasquez | c9c5ced | 2008-07-24 08:31:49 -0700 | [diff] [blame] | 465 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 466 | |
| 467 | return (QLA_FUNCTION_FAILED); |
| 468 | } |
| 469 | |
| 470 | /** |
| 471 | * qla2x00_marker() - Send a marker IOCB to the firmware. |
| 472 | * @ha: HA context |
| 473 | * @loop_id: loop ID |
| 474 | * @lun: LUN |
| 475 | * @type: marker modifier |
| 476 | * |
| 477 | * Can be called from both normal and interrupt context. |
| 478 | * |
Bjorn Helgaas | cc3ef7b | 2008-09-11 21:22:51 -0700 | [diff] [blame] | 479 | * Returns non-zero if a failure occurred, else zero. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 480 | */ |
Andrew Vasquez | 3dbe756 | 2010-07-23 15:28:37 +0500 | [diff] [blame] | 481 | static int |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 482 | __qla2x00_marker(struct scsi_qla_host *vha, struct req_que *req, |
| 483 | struct rsp_que *rsp, uint16_t loop_id, |
| 484 | uint16_t lun, uint8_t type) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 485 | { |
Andrew Vasquez | 2b6c0ce | 2005-07-06 10:31:17 -0700 | [diff] [blame] | 486 | mrk_entry_t *mrk; |
| 487 | struct mrk_entry_24xx *mrk24; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 488 | struct qla_hw_data *ha = vha->hw; |
| 489 | scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 490 | |
Andrew Vasquez | 2b6c0ce | 2005-07-06 10:31:17 -0700 | [diff] [blame] | 491 | mrk24 = NULL; |
Giridhar Malavali | 99b8212 | 2011-11-18 09:03:17 -0800 | [diff] [blame^] | 492 | req = ha->req_q_map[0]; |
Giridhar Malavali | d94d10e | 2010-07-23 15:28:23 +0500 | [diff] [blame] | 493 | mrk = (mrk_entry_t *)qla2x00_alloc_iocbs(vha, 0); |
Andrew Vasquez | 2b6c0ce | 2005-07-06 10:31:17 -0700 | [diff] [blame] | 494 | if (mrk == NULL) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 495 | ql_log(ql_log_warn, base_vha, 0x3026, |
| 496 | "Failed to allocate Marker IOCB.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 497 | |
| 498 | return (QLA_FUNCTION_FAILED); |
| 499 | } |
| 500 | |
Andrew Vasquez | 2b6c0ce | 2005-07-06 10:31:17 -0700 | [diff] [blame] | 501 | mrk->entry_type = MARKER_TYPE; |
| 502 | mrk->modifier = type; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 503 | if (type != MK_SYNC_ALL) { |
Andrew Vasquez | e428924 | 2007-07-19 15:05:56 -0700 | [diff] [blame] | 504 | if (IS_FWI2_CAPABLE(ha)) { |
Andrew Vasquez | 2b6c0ce | 2005-07-06 10:31:17 -0700 | [diff] [blame] | 505 | 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 Sundar | b797b6d | 2006-08-01 13:48:13 -0700 | [diff] [blame] | 509 | host_to_fcp_swap(mrk24->lun, sizeof(mrk24->lun)); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 510 | mrk24->vp_index = vha->vp_idx; |
Anirban Chakraborty | 2afa19a | 2009-04-06 22:33:40 -0700 | [diff] [blame] | 511 | mrk24->handle = MAKE_HANDLE(req->id, mrk24->handle); |
Andrew Vasquez | 2b6c0ce | 2005-07-06 10:31:17 -0700 | [diff] [blame] | 512 | } else { |
| 513 | SET_TARGET_ID(ha, mrk->target, loop_id); |
| 514 | mrk->lun = cpu_to_le16(lun); |
| 515 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 516 | } |
| 517 | wmb(); |
| 518 | |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 519 | qla2x00_isp_cmd(vha, req); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 520 | |
| 521 | return (QLA_SUCCESS); |
| 522 | } |
| 523 | |
Andrew Vasquez | fa2a1ce | 2005-07-06 10:32:07 -0700 | [diff] [blame] | 524 | int |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 525 | qla2x00_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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 528 | { |
| 529 | int ret; |
| 530 | unsigned long flags = 0; |
| 531 | |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 532 | 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 535 | |
| 536 | return (ret); |
| 537 | } |
| 538 | |
| 539 | /** |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 540 | * 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 Bunk | 413975a | 2006-06-30 02:33:06 -0700 | [diff] [blame] | 545 | static void |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 546 | qla2x00_isp_cmd(struct scsi_qla_host *vha, struct req_que *req) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 547 | { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 548 | struct qla_hw_data *ha = vha->hw; |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 549 | device_reg_t __iomem *reg = ISP_QUE_REG(ha, req->id); |
Anirban Chakraborty | 17d9863 | 2008-12-18 10:06:15 -0800 | [diff] [blame] | 550 | struct device_reg_2xxx __iomem *ioreg = &ha->iobase->isp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 551 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 552 | 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 556 | |
| 557 | /* Adjust ring index. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 558 | req->ring_index++; |
| 559 | if (req->ring_index == req->length) { |
| 560 | req->ring_index = 0; |
| 561 | req->ring_ptr = req->ring; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 562 | } else |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 563 | req->ring_ptr++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 564 | |
| 565 | /* Set chip new ring index. */ |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 566 | 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 Chakraborty | 17d9863 | 2008-12-18 10:06:15 -0800 | [diff] [blame] | 586 | WRT_REG_DWORD(®->isp25mq.req_q_in, req->ring_index); |
| 587 | RD_REG_DWORD(&ioreg->hccr); |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 588 | } else { |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 589 | if (IS_FWI2_CAPABLE(ha)) { |
| 590 | WRT_REG_DWORD(®->isp24.req_q_in, req->ring_index); |
| 591 | RD_REG_DWORD_RELAXED(®->isp24.req_q_in); |
| 592 | } else { |
| 593 | WRT_REG_WORD(ISP_REQ_Q_IN(ha, ®->isp), |
| 594 | req->ring_index); |
| 595 | RD_REG_WORD_RELAXED(ISP_REQ_Q_IN(ha, ®->isp)); |
| 596 | } |
Andrew Vasquez | 2b6c0ce | 2005-07-06 10:31:17 -0700 | [diff] [blame] | 597 | } |
| 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 Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 609 | inline uint16_t |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 610 | qla24xx_calc_iocbs(scsi_qla_host_t *vha, uint16_t dsds) |
Andrew Vasquez | 2b6c0ce | 2005-07-06 10:31:17 -0700 | [diff] [blame] | 611 | { |
| 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 Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 631 | inline void |
Andrew Vasquez | 2b6c0ce | 2005-07-06 10:31:17 -0700 | [diff] [blame] | 632 | qla24xx_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 Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 637 | scsi_qla_host_t *vha; |
Andrew Vasquez | 2b6c0ce | 2005-07-06 10:31:17 -0700 | [diff] [blame] | 638 | struct scsi_cmnd *cmd; |
FUJITA Tomonori | 385d70b | 2007-05-26 01:55:38 +0900 | [diff] [blame] | 639 | struct scatterlist *sg; |
| 640 | int i; |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 641 | struct req_que *req; |
Andrew Vasquez | 2b6c0ce | 2005-07-06 10:31:17 -0700 | [diff] [blame] | 642 | |
| 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 Tomonori | 385d70b | 2007-05-26 01:55:38 +0900 | [diff] [blame] | 650 | if (!scsi_bufflen(cmd) || cmd->sc_data_direction == DMA_NONE) { |
Andrew Vasquez | 2b6c0ce | 2005-07-06 10:31:17 -0700 | [diff] [blame] | 651 | cmd_pkt->byte_count = __constant_cpu_to_le32(0); |
| 652 | return; |
| 653 | } |
| 654 | |
Andrew Vasquez | 444786d | 2009-01-05 11:18:10 -0800 | [diff] [blame] | 655 | vha = sp->fcport->vha; |
Anirban Chakraborty | 67c2e93 | 2009-04-06 22:33:42 -0700 | [diff] [blame] | 656 | req = vha->req; |
Andrew Vasquez | 2b6c0ce | 2005-07-06 10:31:17 -0700 | [diff] [blame] | 657 | |
| 658 | /* Set transfer direction */ |
Harish Zunjarrao | 49fd462 | 2008-09-11 21:22:47 -0700 | [diff] [blame] | 659 | if (cmd->sc_data_direction == DMA_TO_DEVICE) { |
Andrew Vasquez | 2b6c0ce | 2005-07-06 10:31:17 -0700 | [diff] [blame] | 660 | cmd_pkt->task_mgmt_flags = |
| 661 | __constant_cpu_to_le16(TMF_WRITE_DATA); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 662 | sp->fcport->vha->hw->qla_stats.output_bytes += |
Harish Zunjarrao | 49fd462 | 2008-09-11 21:22:47 -0700 | [diff] [blame] | 663 | scsi_bufflen(sp->cmd); |
| 664 | } else if (cmd->sc_data_direction == DMA_FROM_DEVICE) { |
Andrew Vasquez | 2b6c0ce | 2005-07-06 10:31:17 -0700 | [diff] [blame] | 665 | cmd_pkt->task_mgmt_flags = |
| 666 | __constant_cpu_to_le16(TMF_READ_DATA); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 667 | sp->fcport->vha->hw->qla_stats.input_bytes += |
Harish Zunjarrao | 49fd462 | 2008-09-11 21:22:47 -0700 | [diff] [blame] | 668 | scsi_bufflen(sp->cmd); |
| 669 | } |
Andrew Vasquez | 2b6c0ce | 2005-07-06 10:31:17 -0700 | [diff] [blame] | 670 | |
| 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 Vasquez | 2b6c0ce | 2005-07-06 10:31:17 -0700 | [diff] [blame] | 676 | |
FUJITA Tomonori | 385d70b | 2007-05-26 01:55:38 +0900 | [diff] [blame] | 677 | scsi_for_each_sg(cmd, sg, tot_dsds, i) { |
| 678 | dma_addr_t sle_dma; |
| 679 | cont_a64_entry_t *cont_pkt; |
Andrew Vasquez | 2b6c0ce | 2005-07-06 10:31:17 -0700 | [diff] [blame] | 680 | |
FUJITA Tomonori | 385d70b | 2007-05-26 01:55:38 +0900 | [diff] [blame] | 681 | /* Allocate additional continuation packets? */ |
| 682 | if (avail_dsds == 0) { |
| 683 | /* |
| 684 | * Five DSDs are available in the Continuation |
| 685 | * Type 1 IOCB. |
| 686 | */ |
Giridhar Malavali | 0d2aa38 | 2011-11-18 09:02:21 -0800 | [diff] [blame] | 687 | cont_pkt = qla2x00_prep_cont_type1_iocb(vha, vha->req); |
FUJITA Tomonori | 385d70b | 2007-05-26 01:55:38 +0900 | [diff] [blame] | 688 | cur_dsd = (uint32_t *)cont_pkt->dseg_0_address; |
| 689 | avail_dsds = 5; |
Andrew Vasquez | 2b6c0ce | 2005-07-06 10:31:17 -0700 | [diff] [blame] | 690 | } |
FUJITA Tomonori | 385d70b | 2007-05-26 01:55:38 +0900 | [diff] [blame] | 691 | |
| 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 Vasquez | 2b6c0ce | 2005-07-06 10:31:17 -0700 | [diff] [blame] | 697 | } |
| 698 | } |
| 699 | |
Arun Easi | bad7500 | 2010-05-04 15:01:30 -0700 | [diff] [blame] | 700 | struct 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 | */ |
| 711 | static inline void |
Arun Easi | e02587d | 2011-08-16 11:29:23 -0700 | [diff] [blame] | 712 | qla24xx_set_t10dif_tags(srb_t *sp, struct fw_dif_context *pkt, |
Arun Easi | bad7500 | 2010-05-04 15:01:30 -0700 | [diff] [blame] | 713 | unsigned int protcnt) |
| 714 | { |
Arun Easi | e02587d | 2011-08-16 11:29:23 -0700 | [diff] [blame] | 715 | struct scsi_cmnd *cmd = sp->cmd; |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 716 | scsi_qla_host_t *vha = shost_priv(cmd->device->host); |
Arun Easi | bad7500 | 2010-05-04 15:01:30 -0700 | [diff] [blame] | 717 | |
| 718 | switch (scsi_get_prot_type(cmd)) { |
Arun Easi | bad7500 | 2010-05-04 15:01:30 -0700 | [diff] [blame] | 719 | case SCSI_PROT_DIF_TYPE0: |
Arun Easi | 8cb2049 | 2011-08-16 11:29:22 -0700 | [diff] [blame] | 720 | /* |
| 721 | * No check for ql2xenablehba_err_chk, as it would be an |
| 722 | * I/O error if hba tag generation is not done. |
| 723 | */ |
| 724 | pkt->ref_tag = cpu_to_le32((uint32_t) |
| 725 | (0xffffffff & scsi_get_lba(cmd))); |
Arun Easi | e02587d | 2011-08-16 11:29:23 -0700 | [diff] [blame] | 726 | |
| 727 | if (!qla2x00_hba_err_chk_enabled(sp)) |
| 728 | break; |
| 729 | |
Arun Easi | 8cb2049 | 2011-08-16 11:29:22 -0700 | [diff] [blame] | 730 | pkt->ref_tag_mask[0] = 0xff; |
| 731 | pkt->ref_tag_mask[1] = 0xff; |
| 732 | pkt->ref_tag_mask[2] = 0xff; |
| 733 | pkt->ref_tag_mask[3] = 0xff; |
Arun Easi | bad7500 | 2010-05-04 15:01:30 -0700 | [diff] [blame] | 734 | break; |
| 735 | |
| 736 | /* |
| 737 | * For TYPE 2 protection: 16 bit GUARD + 32 bit REF tag has to |
| 738 | * match LBA in CDB + N |
| 739 | */ |
| 740 | case SCSI_PROT_DIF_TYPE2: |
Arun Easi | e02587d | 2011-08-16 11:29:23 -0700 | [diff] [blame] | 741 | pkt->app_tag = __constant_cpu_to_le16(0); |
| 742 | pkt->app_tag_mask[0] = 0x0; |
| 743 | pkt->app_tag_mask[1] = 0x0; |
Arun Easi | 0c47087 | 2010-07-23 15:28:38 +0500 | [diff] [blame] | 744 | |
| 745 | pkt->ref_tag = cpu_to_le32((uint32_t) |
| 746 | (0xffffffff & scsi_get_lba(cmd))); |
| 747 | |
Arun Easi | e02587d | 2011-08-16 11:29:23 -0700 | [diff] [blame] | 748 | if (!qla2x00_hba_err_chk_enabled(sp)) |
| 749 | break; |
| 750 | |
Arun Easi | 0c47087 | 2010-07-23 15:28:38 +0500 | [diff] [blame] | 751 | /* enable ALL bytes of the ref tag */ |
| 752 | pkt->ref_tag_mask[0] = 0xff; |
| 753 | pkt->ref_tag_mask[1] = 0xff; |
| 754 | pkt->ref_tag_mask[2] = 0xff; |
| 755 | pkt->ref_tag_mask[3] = 0xff; |
Arun Easi | bad7500 | 2010-05-04 15:01:30 -0700 | [diff] [blame] | 756 | break; |
| 757 | |
| 758 | /* For Type 3 protection: 16 bit GUARD only */ |
| 759 | case SCSI_PROT_DIF_TYPE3: |
| 760 | pkt->ref_tag_mask[0] = pkt->ref_tag_mask[1] = |
| 761 | pkt->ref_tag_mask[2] = pkt->ref_tag_mask[3] = |
| 762 | 0x00; |
| 763 | break; |
| 764 | |
| 765 | /* |
| 766 | * For TYpe 1 protection: 16 bit GUARD tag, 32 bit REF tag, and |
| 767 | * 16 bit app tag. |
| 768 | */ |
| 769 | case SCSI_PROT_DIF_TYPE1: |
Arun Easi | e02587d | 2011-08-16 11:29:23 -0700 | [diff] [blame] | 770 | pkt->ref_tag = cpu_to_le32((uint32_t) |
| 771 | (0xffffffff & scsi_get_lba(cmd))); |
| 772 | pkt->app_tag = __constant_cpu_to_le16(0); |
| 773 | pkt->app_tag_mask[0] = 0x0; |
| 774 | pkt->app_tag_mask[1] = 0x0; |
| 775 | |
| 776 | if (!qla2x00_hba_err_chk_enabled(sp)) |
Arun Easi | bad7500 | 2010-05-04 15:01:30 -0700 | [diff] [blame] | 777 | break; |
| 778 | |
Arun Easi | bad7500 | 2010-05-04 15:01:30 -0700 | [diff] [blame] | 779 | /* enable ALL bytes of the ref tag */ |
| 780 | pkt->ref_tag_mask[0] = 0xff; |
| 781 | pkt->ref_tag_mask[1] = 0xff; |
| 782 | pkt->ref_tag_mask[2] = 0xff; |
| 783 | pkt->ref_tag_mask[3] = 0xff; |
| 784 | break; |
| 785 | } |
| 786 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 787 | ql_dbg(ql_dbg_io, vha, 0x3009, |
| 788 | "Setting protection Tags: (BIG) ref tag = 0x%x, app tag = 0x%x, " |
| 789 | "prot SG count %d, cmd lba 0x%x, prot_type=%u cmd=%p.\n", |
| 790 | pkt->ref_tag, pkt->app_tag, protcnt, (int)scsi_get_lba(cmd), |
| 791 | scsi_get_prot_type(cmd), cmd); |
Arun Easi | bad7500 | 2010-05-04 15:01:30 -0700 | [diff] [blame] | 792 | } |
| 793 | |
Arun Easi | 8cb2049 | 2011-08-16 11:29:22 -0700 | [diff] [blame] | 794 | struct qla2_sgx { |
| 795 | dma_addr_t dma_addr; /* OUT */ |
| 796 | uint32_t dma_len; /* OUT */ |
Arun Easi | bad7500 | 2010-05-04 15:01:30 -0700 | [diff] [blame] | 797 | |
Arun Easi | 8cb2049 | 2011-08-16 11:29:22 -0700 | [diff] [blame] | 798 | uint32_t tot_bytes; /* IN */ |
| 799 | struct scatterlist *cur_sg; /* IN */ |
| 800 | |
| 801 | /* for book keeping, bzero on initial invocation */ |
| 802 | uint32_t bytes_consumed; |
| 803 | uint32_t num_bytes; |
| 804 | uint32_t tot_partial; |
| 805 | |
| 806 | /* for debugging */ |
| 807 | uint32_t num_sg; |
| 808 | srb_t *sp; |
| 809 | }; |
| 810 | |
| 811 | static int |
| 812 | qla24xx_get_one_block_sg(uint32_t blk_sz, struct qla2_sgx *sgx, |
| 813 | uint32_t *partial) |
| 814 | { |
| 815 | struct scatterlist *sg; |
| 816 | uint32_t cumulative_partial, sg_len; |
| 817 | dma_addr_t sg_dma_addr; |
| 818 | |
| 819 | if (sgx->num_bytes == sgx->tot_bytes) |
| 820 | return 0; |
| 821 | |
| 822 | sg = sgx->cur_sg; |
| 823 | cumulative_partial = sgx->tot_partial; |
| 824 | |
| 825 | sg_dma_addr = sg_dma_address(sg); |
| 826 | sg_len = sg_dma_len(sg); |
| 827 | |
| 828 | sgx->dma_addr = sg_dma_addr + sgx->bytes_consumed; |
| 829 | |
| 830 | if ((cumulative_partial + (sg_len - sgx->bytes_consumed)) >= blk_sz) { |
| 831 | sgx->dma_len = (blk_sz - cumulative_partial); |
| 832 | sgx->tot_partial = 0; |
| 833 | sgx->num_bytes += blk_sz; |
| 834 | *partial = 0; |
| 835 | } else { |
| 836 | sgx->dma_len = sg_len - sgx->bytes_consumed; |
| 837 | sgx->tot_partial += sgx->dma_len; |
| 838 | *partial = 1; |
| 839 | } |
| 840 | |
| 841 | sgx->bytes_consumed += sgx->dma_len; |
| 842 | |
| 843 | if (sg_len == sgx->bytes_consumed) { |
| 844 | sg = sg_next(sg); |
| 845 | sgx->num_sg++; |
| 846 | sgx->cur_sg = sg; |
| 847 | sgx->bytes_consumed = 0; |
| 848 | } |
| 849 | |
| 850 | return 1; |
| 851 | } |
| 852 | |
| 853 | static int |
| 854 | qla24xx_walk_and_build_sglist_no_difb(struct qla_hw_data *ha, srb_t *sp, |
| 855 | uint32_t *dsd, uint16_t tot_dsds) |
| 856 | { |
| 857 | void *next_dsd; |
| 858 | uint8_t avail_dsds = 0; |
| 859 | uint32_t dsd_list_len; |
| 860 | struct dsd_dma *dsd_ptr; |
| 861 | struct scatterlist *sg_prot; |
| 862 | uint32_t *cur_dsd = dsd; |
| 863 | uint16_t used_dsds = tot_dsds; |
| 864 | |
| 865 | uint32_t prot_int; |
| 866 | uint32_t partial; |
| 867 | struct qla2_sgx sgx; |
| 868 | dma_addr_t sle_dma; |
| 869 | uint32_t sle_dma_len, tot_prot_dma_len = 0; |
| 870 | struct scsi_cmnd *cmd = sp->cmd; |
| 871 | |
| 872 | prot_int = cmd->device->sector_size; |
| 873 | |
| 874 | memset(&sgx, 0, sizeof(struct qla2_sgx)); |
| 875 | sgx.tot_bytes = scsi_bufflen(sp->cmd); |
| 876 | sgx.cur_sg = scsi_sglist(sp->cmd); |
| 877 | sgx.sp = sp; |
| 878 | |
| 879 | sg_prot = scsi_prot_sglist(sp->cmd); |
| 880 | |
| 881 | while (qla24xx_get_one_block_sg(prot_int, &sgx, &partial)) { |
| 882 | |
| 883 | sle_dma = sgx.dma_addr; |
| 884 | sle_dma_len = sgx.dma_len; |
| 885 | alloc_and_fill: |
| 886 | /* Allocate additional continuation packets? */ |
| 887 | if (avail_dsds == 0) { |
| 888 | avail_dsds = (used_dsds > QLA_DSDS_PER_IOCB) ? |
| 889 | QLA_DSDS_PER_IOCB : used_dsds; |
| 890 | dsd_list_len = (avail_dsds + 1) * 12; |
| 891 | used_dsds -= avail_dsds; |
| 892 | |
| 893 | /* allocate tracking DS */ |
| 894 | dsd_ptr = kzalloc(sizeof(struct dsd_dma), GFP_ATOMIC); |
| 895 | if (!dsd_ptr) |
| 896 | return 1; |
| 897 | |
| 898 | /* allocate new list */ |
| 899 | dsd_ptr->dsd_addr = next_dsd = |
| 900 | dma_pool_alloc(ha->dl_dma_pool, GFP_ATOMIC, |
| 901 | &dsd_ptr->dsd_list_dma); |
| 902 | |
| 903 | if (!next_dsd) { |
| 904 | /* |
| 905 | * Need to cleanup only this dsd_ptr, rest |
| 906 | * will be done by sp_free_dma() |
| 907 | */ |
| 908 | kfree(dsd_ptr); |
| 909 | return 1; |
| 910 | } |
| 911 | |
| 912 | list_add_tail(&dsd_ptr->list, |
| 913 | &((struct crc_context *)sp->ctx)->dsd_list); |
| 914 | |
| 915 | sp->flags |= SRB_CRC_CTX_DSD_VALID; |
| 916 | |
| 917 | /* add new list to cmd iocb or last list */ |
| 918 | *cur_dsd++ = cpu_to_le32(LSD(dsd_ptr->dsd_list_dma)); |
| 919 | *cur_dsd++ = cpu_to_le32(MSD(dsd_ptr->dsd_list_dma)); |
| 920 | *cur_dsd++ = dsd_list_len; |
| 921 | cur_dsd = (uint32_t *)next_dsd; |
| 922 | } |
| 923 | *cur_dsd++ = cpu_to_le32(LSD(sle_dma)); |
| 924 | *cur_dsd++ = cpu_to_le32(MSD(sle_dma)); |
| 925 | *cur_dsd++ = cpu_to_le32(sle_dma_len); |
| 926 | avail_dsds--; |
| 927 | |
| 928 | if (partial == 0) { |
| 929 | /* Got a full protection interval */ |
| 930 | sle_dma = sg_dma_address(sg_prot) + tot_prot_dma_len; |
| 931 | sle_dma_len = 8; |
| 932 | |
| 933 | tot_prot_dma_len += sle_dma_len; |
| 934 | if (tot_prot_dma_len == sg_dma_len(sg_prot)) { |
| 935 | tot_prot_dma_len = 0; |
| 936 | sg_prot = sg_next(sg_prot); |
| 937 | } |
| 938 | |
| 939 | partial = 1; /* So as to not re-enter this block */ |
| 940 | goto alloc_and_fill; |
| 941 | } |
| 942 | } |
| 943 | /* Null termination */ |
| 944 | *cur_dsd++ = 0; |
| 945 | *cur_dsd++ = 0; |
| 946 | *cur_dsd++ = 0; |
| 947 | return 0; |
| 948 | } |
Arun Easi | bad7500 | 2010-05-04 15:01:30 -0700 | [diff] [blame] | 949 | static int |
| 950 | qla24xx_walk_and_build_sglist(struct qla_hw_data *ha, srb_t *sp, uint32_t *dsd, |
| 951 | uint16_t tot_dsds) |
| 952 | { |
| 953 | void *next_dsd; |
| 954 | uint8_t avail_dsds = 0; |
| 955 | uint32_t dsd_list_len; |
| 956 | struct dsd_dma *dsd_ptr; |
| 957 | struct scatterlist *sg; |
| 958 | uint32_t *cur_dsd = dsd; |
| 959 | int i; |
| 960 | uint16_t used_dsds = tot_dsds; |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 961 | scsi_qla_host_t *vha = shost_priv(sp->cmd->device->host); |
Arun Easi | bad7500 | 2010-05-04 15:01:30 -0700 | [diff] [blame] | 962 | |
| 963 | uint8_t *cp; |
| 964 | |
| 965 | scsi_for_each_sg(sp->cmd, sg, tot_dsds, i) { |
| 966 | dma_addr_t sle_dma; |
| 967 | |
| 968 | /* Allocate additional continuation packets? */ |
| 969 | if (avail_dsds == 0) { |
| 970 | avail_dsds = (used_dsds > QLA_DSDS_PER_IOCB) ? |
| 971 | QLA_DSDS_PER_IOCB : used_dsds; |
| 972 | dsd_list_len = (avail_dsds + 1) * 12; |
| 973 | used_dsds -= avail_dsds; |
| 974 | |
| 975 | /* allocate tracking DS */ |
| 976 | dsd_ptr = kzalloc(sizeof(struct dsd_dma), GFP_ATOMIC); |
| 977 | if (!dsd_ptr) |
| 978 | return 1; |
| 979 | |
| 980 | /* allocate new list */ |
| 981 | dsd_ptr->dsd_addr = next_dsd = |
| 982 | dma_pool_alloc(ha->dl_dma_pool, GFP_ATOMIC, |
| 983 | &dsd_ptr->dsd_list_dma); |
| 984 | |
| 985 | if (!next_dsd) { |
| 986 | /* |
| 987 | * Need to cleanup only this dsd_ptr, rest |
| 988 | * will be done by sp_free_dma() |
| 989 | */ |
| 990 | kfree(dsd_ptr); |
| 991 | return 1; |
| 992 | } |
| 993 | |
| 994 | list_add_tail(&dsd_ptr->list, |
| 995 | &((struct crc_context *)sp->ctx)->dsd_list); |
| 996 | |
| 997 | sp->flags |= SRB_CRC_CTX_DSD_VALID; |
| 998 | |
| 999 | /* add new list to cmd iocb or last list */ |
| 1000 | *cur_dsd++ = cpu_to_le32(LSD(dsd_ptr->dsd_list_dma)); |
| 1001 | *cur_dsd++ = cpu_to_le32(MSD(dsd_ptr->dsd_list_dma)); |
| 1002 | *cur_dsd++ = dsd_list_len; |
| 1003 | cur_dsd = (uint32_t *)next_dsd; |
| 1004 | } |
| 1005 | sle_dma = sg_dma_address(sg); |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1006 | ql_dbg(ql_dbg_io, vha, 0x300a, |
| 1007 | "sg entry %d - addr=0x%x 0x%x, " "len=%d for cmd=%p.\n", |
Joe Perches | d8424f6 | 2011-11-18 09:03:06 -0800 | [diff] [blame] | 1008 | i, LSD(sle_dma), MSD(sle_dma), sg_dma_len(sg), |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1009 | sp->cmd); |
Arun Easi | bad7500 | 2010-05-04 15:01:30 -0700 | [diff] [blame] | 1010 | *cur_dsd++ = cpu_to_le32(LSD(sle_dma)); |
| 1011 | *cur_dsd++ = cpu_to_le32(MSD(sle_dma)); |
| 1012 | *cur_dsd++ = cpu_to_le32(sg_dma_len(sg)); |
| 1013 | avail_dsds--; |
| 1014 | |
| 1015 | if (scsi_get_prot_op(sp->cmd) == SCSI_PROT_WRITE_PASS) { |
| 1016 | cp = page_address(sg_page(sg)) + sg->offset; |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1017 | ql_dbg(ql_dbg_io, vha, 0x300b, |
| 1018 | "User data buffer=%p for cmd=%p.\n", cp, sp->cmd); |
Arun Easi | bad7500 | 2010-05-04 15:01:30 -0700 | [diff] [blame] | 1019 | } |
| 1020 | } |
| 1021 | /* Null termination */ |
| 1022 | *cur_dsd++ = 0; |
| 1023 | *cur_dsd++ = 0; |
| 1024 | *cur_dsd++ = 0; |
| 1025 | return 0; |
| 1026 | } |
| 1027 | |
| 1028 | static int |
| 1029 | qla24xx_walk_and_build_prot_sglist(struct qla_hw_data *ha, srb_t *sp, |
| 1030 | uint32_t *dsd, |
| 1031 | uint16_t tot_dsds) |
| 1032 | { |
| 1033 | void *next_dsd; |
| 1034 | uint8_t avail_dsds = 0; |
| 1035 | uint32_t dsd_list_len; |
| 1036 | struct dsd_dma *dsd_ptr; |
| 1037 | struct scatterlist *sg; |
| 1038 | int i; |
| 1039 | struct scsi_cmnd *cmd; |
| 1040 | uint32_t *cur_dsd = dsd; |
| 1041 | uint16_t used_dsds = tot_dsds; |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1042 | scsi_qla_host_t *vha = pci_get_drvdata(ha->pdev); |
Arun Easi | bad7500 | 2010-05-04 15:01:30 -0700 | [diff] [blame] | 1043 | uint8_t *cp; |
| 1044 | |
| 1045 | |
| 1046 | cmd = sp->cmd; |
| 1047 | scsi_for_each_prot_sg(cmd, sg, tot_dsds, i) { |
| 1048 | dma_addr_t sle_dma; |
| 1049 | |
| 1050 | /* Allocate additional continuation packets? */ |
| 1051 | if (avail_dsds == 0) { |
| 1052 | avail_dsds = (used_dsds > QLA_DSDS_PER_IOCB) ? |
| 1053 | QLA_DSDS_PER_IOCB : used_dsds; |
| 1054 | dsd_list_len = (avail_dsds + 1) * 12; |
| 1055 | used_dsds -= avail_dsds; |
| 1056 | |
| 1057 | /* allocate tracking DS */ |
| 1058 | dsd_ptr = kzalloc(sizeof(struct dsd_dma), GFP_ATOMIC); |
| 1059 | if (!dsd_ptr) |
| 1060 | return 1; |
| 1061 | |
| 1062 | /* allocate new list */ |
| 1063 | dsd_ptr->dsd_addr = next_dsd = |
| 1064 | dma_pool_alloc(ha->dl_dma_pool, GFP_ATOMIC, |
| 1065 | &dsd_ptr->dsd_list_dma); |
| 1066 | |
| 1067 | if (!next_dsd) { |
| 1068 | /* |
| 1069 | * Need to cleanup only this dsd_ptr, rest |
| 1070 | * will be done by sp_free_dma() |
| 1071 | */ |
| 1072 | kfree(dsd_ptr); |
| 1073 | return 1; |
| 1074 | } |
| 1075 | |
| 1076 | list_add_tail(&dsd_ptr->list, |
| 1077 | &((struct crc_context *)sp->ctx)->dsd_list); |
| 1078 | |
| 1079 | sp->flags |= SRB_CRC_CTX_DSD_VALID; |
| 1080 | |
| 1081 | /* add new list to cmd iocb or last list */ |
| 1082 | *cur_dsd++ = cpu_to_le32(LSD(dsd_ptr->dsd_list_dma)); |
| 1083 | *cur_dsd++ = cpu_to_le32(MSD(dsd_ptr->dsd_list_dma)); |
| 1084 | *cur_dsd++ = dsd_list_len; |
| 1085 | cur_dsd = (uint32_t *)next_dsd; |
| 1086 | } |
| 1087 | sle_dma = sg_dma_address(sg); |
| 1088 | if (scsi_get_prot_op(sp->cmd) == SCSI_PROT_WRITE_PASS) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1089 | ql_dbg(ql_dbg_io, vha, 0x3027, |
| 1090 | "%s(): %p, sg_entry %d - " |
| 1091 | "addr=0x%x0x%x, len=%d.\n", |
| 1092 | __func__, cur_dsd, i, |
| 1093 | LSD(sle_dma), MSD(sle_dma), sg_dma_len(sg)); |
Arun Easi | bad7500 | 2010-05-04 15:01:30 -0700 | [diff] [blame] | 1094 | } |
| 1095 | *cur_dsd++ = cpu_to_le32(LSD(sle_dma)); |
| 1096 | *cur_dsd++ = cpu_to_le32(MSD(sle_dma)); |
| 1097 | *cur_dsd++ = cpu_to_le32(sg_dma_len(sg)); |
| 1098 | |
| 1099 | if (scsi_get_prot_op(sp->cmd) == SCSI_PROT_WRITE_PASS) { |
| 1100 | cp = page_address(sg_page(sg)) + sg->offset; |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1101 | ql_dbg(ql_dbg_io, vha, 0x3028, |
| 1102 | "%s(): Protection Data buffer = %p.\n", __func__, |
| 1103 | cp); |
Arun Easi | bad7500 | 2010-05-04 15:01:30 -0700 | [diff] [blame] | 1104 | } |
| 1105 | avail_dsds--; |
| 1106 | } |
| 1107 | /* Null termination */ |
| 1108 | *cur_dsd++ = 0; |
| 1109 | *cur_dsd++ = 0; |
| 1110 | *cur_dsd++ = 0; |
| 1111 | return 0; |
| 1112 | } |
| 1113 | |
| 1114 | /** |
| 1115 | * qla24xx_build_scsi_crc_2_iocbs() - Build IOCB command utilizing Command |
| 1116 | * Type 6 IOCB types. |
| 1117 | * |
| 1118 | * @sp: SRB command to process |
| 1119 | * @cmd_pkt: Command type 3 IOCB |
| 1120 | * @tot_dsds: Total number of segments to transfer |
| 1121 | */ |
| 1122 | static inline int |
| 1123 | qla24xx_build_scsi_crc_2_iocbs(srb_t *sp, struct cmd_type_crc_2 *cmd_pkt, |
| 1124 | uint16_t tot_dsds, uint16_t tot_prot_dsds, uint16_t fw_prot_opts) |
| 1125 | { |
| 1126 | uint32_t *cur_dsd, *fcp_dl; |
| 1127 | scsi_qla_host_t *vha; |
| 1128 | struct scsi_cmnd *cmd; |
| 1129 | struct scatterlist *cur_seg; |
| 1130 | int sgc; |
Arun Easi | 8cb2049 | 2011-08-16 11:29:22 -0700 | [diff] [blame] | 1131 | uint32_t total_bytes = 0; |
Arun Easi | bad7500 | 2010-05-04 15:01:30 -0700 | [diff] [blame] | 1132 | uint32_t data_bytes; |
| 1133 | uint32_t dif_bytes; |
| 1134 | uint8_t bundling = 1; |
| 1135 | uint16_t blk_size; |
| 1136 | uint8_t *clr_ptr; |
| 1137 | struct crc_context *crc_ctx_pkt = NULL; |
| 1138 | struct qla_hw_data *ha; |
| 1139 | uint8_t additional_fcpcdb_len; |
| 1140 | uint16_t fcp_cmnd_len; |
| 1141 | struct fcp_cmnd *fcp_cmnd; |
| 1142 | dma_addr_t crc_ctx_dma; |
Andrew Vasquez | ff2fc42 | 2011-02-23 15:27:15 -0800 | [diff] [blame] | 1143 | char tag[2]; |
Arun Easi | bad7500 | 2010-05-04 15:01:30 -0700 | [diff] [blame] | 1144 | |
| 1145 | cmd = sp->cmd; |
| 1146 | |
| 1147 | sgc = 0; |
| 1148 | /* Update entry type to indicate Command Type CRC_2 IOCB */ |
| 1149 | *((uint32_t *)(&cmd_pkt->entry_type)) = |
| 1150 | __constant_cpu_to_le32(COMMAND_TYPE_CRC_2); |
| 1151 | |
Arun Easi | bad7500 | 2010-05-04 15:01:30 -0700 | [diff] [blame] | 1152 | vha = sp->fcport->vha; |
| 1153 | ha = vha->hw; |
| 1154 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1155 | /* No data transfer */ |
| 1156 | data_bytes = scsi_bufflen(cmd); |
| 1157 | if (!data_bytes || cmd->sc_data_direction == DMA_NONE) { |
| 1158 | cmd_pkt->byte_count = __constant_cpu_to_le32(0); |
| 1159 | return QLA_SUCCESS; |
| 1160 | } |
Arun Easi | bad7500 | 2010-05-04 15:01:30 -0700 | [diff] [blame] | 1161 | |
| 1162 | cmd_pkt->vp_index = sp->fcport->vp_idx; |
| 1163 | |
| 1164 | /* Set transfer direction */ |
| 1165 | if (cmd->sc_data_direction == DMA_TO_DEVICE) { |
| 1166 | cmd_pkt->control_flags = |
| 1167 | __constant_cpu_to_le16(CF_WRITE_DATA); |
| 1168 | } else if (cmd->sc_data_direction == DMA_FROM_DEVICE) { |
| 1169 | cmd_pkt->control_flags = |
| 1170 | __constant_cpu_to_le16(CF_READ_DATA); |
| 1171 | } |
| 1172 | |
Arun Easi | 8cb2049 | 2011-08-16 11:29:22 -0700 | [diff] [blame] | 1173 | if ((scsi_get_prot_op(sp->cmd) == SCSI_PROT_READ_INSERT) || |
| 1174 | (scsi_get_prot_op(sp->cmd) == SCSI_PROT_WRITE_STRIP) || |
| 1175 | (scsi_get_prot_op(sp->cmd) == SCSI_PROT_READ_STRIP) || |
| 1176 | (scsi_get_prot_op(sp->cmd) == SCSI_PROT_WRITE_INSERT)) |
Arun Easi | bad7500 | 2010-05-04 15:01:30 -0700 | [diff] [blame] | 1177 | bundling = 0; |
| 1178 | |
| 1179 | /* Allocate CRC context from global pool */ |
| 1180 | crc_ctx_pkt = sp->ctx = dma_pool_alloc(ha->dl_dma_pool, |
| 1181 | GFP_ATOMIC, &crc_ctx_dma); |
| 1182 | |
| 1183 | if (!crc_ctx_pkt) |
| 1184 | goto crc_queuing_error; |
| 1185 | |
| 1186 | /* Zero out CTX area. */ |
| 1187 | clr_ptr = (uint8_t *)crc_ctx_pkt; |
| 1188 | memset(clr_ptr, 0, sizeof(*crc_ctx_pkt)); |
| 1189 | |
| 1190 | crc_ctx_pkt->crc_ctx_dma = crc_ctx_dma; |
| 1191 | |
| 1192 | sp->flags |= SRB_CRC_CTX_DMA_VALID; |
| 1193 | |
| 1194 | /* Set handle */ |
| 1195 | crc_ctx_pkt->handle = cmd_pkt->handle; |
| 1196 | |
| 1197 | INIT_LIST_HEAD(&crc_ctx_pkt->dsd_list); |
| 1198 | |
Arun Easi | e02587d | 2011-08-16 11:29:23 -0700 | [diff] [blame] | 1199 | qla24xx_set_t10dif_tags(sp, (struct fw_dif_context *) |
Arun Easi | bad7500 | 2010-05-04 15:01:30 -0700 | [diff] [blame] | 1200 | &crc_ctx_pkt->ref_tag, tot_prot_dsds); |
| 1201 | |
| 1202 | cmd_pkt->crc_context_address[0] = cpu_to_le32(LSD(crc_ctx_dma)); |
| 1203 | cmd_pkt->crc_context_address[1] = cpu_to_le32(MSD(crc_ctx_dma)); |
| 1204 | cmd_pkt->crc_context_len = CRC_CONTEXT_LEN_FW; |
| 1205 | |
| 1206 | /* Determine SCSI command length -- align to 4 byte boundary */ |
| 1207 | if (cmd->cmd_len > 16) { |
Arun Easi | bad7500 | 2010-05-04 15:01:30 -0700 | [diff] [blame] | 1208 | additional_fcpcdb_len = cmd->cmd_len - 16; |
| 1209 | if ((cmd->cmd_len % 4) != 0) { |
| 1210 | /* SCSI cmd > 16 bytes must be multiple of 4 */ |
| 1211 | goto crc_queuing_error; |
| 1212 | } |
| 1213 | fcp_cmnd_len = 12 + cmd->cmd_len + 4; |
| 1214 | } else { |
| 1215 | additional_fcpcdb_len = 0; |
| 1216 | fcp_cmnd_len = 12 + 16 + 4; |
| 1217 | } |
| 1218 | |
| 1219 | fcp_cmnd = &crc_ctx_pkt->fcp_cmnd; |
| 1220 | |
| 1221 | fcp_cmnd->additional_cdb_len = additional_fcpcdb_len; |
| 1222 | if (cmd->sc_data_direction == DMA_TO_DEVICE) |
| 1223 | fcp_cmnd->additional_cdb_len |= 1; |
| 1224 | else if (cmd->sc_data_direction == DMA_FROM_DEVICE) |
| 1225 | fcp_cmnd->additional_cdb_len |= 2; |
| 1226 | |
| 1227 | int_to_scsilun(sp->cmd->device->lun, &fcp_cmnd->lun); |
| 1228 | memcpy(fcp_cmnd->cdb, cmd->cmnd, cmd->cmd_len); |
| 1229 | cmd_pkt->fcp_cmnd_dseg_len = cpu_to_le16(fcp_cmnd_len); |
| 1230 | cmd_pkt->fcp_cmnd_dseg_address[0] = cpu_to_le32( |
| 1231 | LSD(crc_ctx_dma + CRC_CONTEXT_FCPCMND_OFF)); |
| 1232 | cmd_pkt->fcp_cmnd_dseg_address[1] = cpu_to_le32( |
| 1233 | MSD(crc_ctx_dma + CRC_CONTEXT_FCPCMND_OFF)); |
Uwe Kleine-König | 65155b3 | 2010-06-11 12:17:01 +0200 | [diff] [blame] | 1234 | fcp_cmnd->task_management = 0; |
Arun Easi | bad7500 | 2010-05-04 15:01:30 -0700 | [diff] [blame] | 1235 | |
Andrew Vasquez | ff2fc42 | 2011-02-23 15:27:15 -0800 | [diff] [blame] | 1236 | /* |
| 1237 | * Update tagged queuing modifier if using command tag queuing |
| 1238 | */ |
| 1239 | if (scsi_populate_tag_msg(cmd, tag)) { |
| 1240 | switch (tag[0]) { |
| 1241 | case HEAD_OF_QUEUE_TAG: |
| 1242 | fcp_cmnd->task_attribute = TSK_HEAD_OF_QUEUE; |
| 1243 | break; |
| 1244 | case ORDERED_QUEUE_TAG: |
| 1245 | fcp_cmnd->task_attribute = TSK_ORDERED; |
| 1246 | break; |
| 1247 | default: |
| 1248 | fcp_cmnd->task_attribute = 0; |
| 1249 | break; |
| 1250 | } |
| 1251 | } else { |
| 1252 | fcp_cmnd->task_attribute = 0; |
| 1253 | } |
| 1254 | |
Arun Easi | bad7500 | 2010-05-04 15:01:30 -0700 | [diff] [blame] | 1255 | cmd_pkt->fcp_rsp_dseg_len = 0; /* Let response come in status iocb */ |
| 1256 | |
Arun Easi | bad7500 | 2010-05-04 15:01:30 -0700 | [diff] [blame] | 1257 | /* Compute dif len and adjust data len to incude protection */ |
Arun Easi | bad7500 | 2010-05-04 15:01:30 -0700 | [diff] [blame] | 1258 | dif_bytes = 0; |
| 1259 | blk_size = cmd->device->sector_size; |
Arun Easi | 8cb2049 | 2011-08-16 11:29:22 -0700 | [diff] [blame] | 1260 | dif_bytes = (data_bytes / blk_size) * 8; |
| 1261 | |
| 1262 | switch (scsi_get_prot_op(sp->cmd)) { |
| 1263 | case SCSI_PROT_READ_INSERT: |
| 1264 | case SCSI_PROT_WRITE_STRIP: |
| 1265 | total_bytes = data_bytes; |
| 1266 | data_bytes += dif_bytes; |
| 1267 | break; |
| 1268 | |
| 1269 | case SCSI_PROT_READ_STRIP: |
| 1270 | case SCSI_PROT_WRITE_INSERT: |
| 1271 | case SCSI_PROT_READ_PASS: |
| 1272 | case SCSI_PROT_WRITE_PASS: |
| 1273 | total_bytes = data_bytes + dif_bytes; |
| 1274 | break; |
| 1275 | default: |
| 1276 | BUG(); |
Arun Easi | bad7500 | 2010-05-04 15:01:30 -0700 | [diff] [blame] | 1277 | } |
| 1278 | |
Arun Easi | e02587d | 2011-08-16 11:29:23 -0700 | [diff] [blame] | 1279 | if (!qla2x00_hba_err_chk_enabled(sp)) |
Arun Easi | bad7500 | 2010-05-04 15:01:30 -0700 | [diff] [blame] | 1280 | fw_prot_opts |= 0x10; /* Disable Guard tag checking */ |
| 1281 | |
| 1282 | if (!bundling) { |
| 1283 | cur_dsd = (uint32_t *) &crc_ctx_pkt->u.nobundling.data_address; |
| 1284 | } else { |
| 1285 | /* |
| 1286 | * Configure Bundling if we need to fetch interlaving |
| 1287 | * protection PCI accesses |
| 1288 | */ |
| 1289 | fw_prot_opts |= PO_ENABLE_DIF_BUNDLING; |
| 1290 | crc_ctx_pkt->u.bundling.dif_byte_count = cpu_to_le32(dif_bytes); |
| 1291 | crc_ctx_pkt->u.bundling.dseg_count = cpu_to_le16(tot_dsds - |
| 1292 | tot_prot_dsds); |
| 1293 | cur_dsd = (uint32_t *) &crc_ctx_pkt->u.bundling.data_address; |
| 1294 | } |
| 1295 | |
| 1296 | /* Finish the common fields of CRC pkt */ |
| 1297 | crc_ctx_pkt->blk_size = cpu_to_le16(blk_size); |
| 1298 | crc_ctx_pkt->prot_opts = cpu_to_le16(fw_prot_opts); |
| 1299 | crc_ctx_pkt->byte_count = cpu_to_le32(data_bytes); |
| 1300 | crc_ctx_pkt->guard_seed = __constant_cpu_to_le16(0); |
| 1301 | /* Fibre channel byte count */ |
| 1302 | cmd_pkt->byte_count = cpu_to_le32(total_bytes); |
| 1303 | fcp_dl = (uint32_t *)(crc_ctx_pkt->fcp_cmnd.cdb + 16 + |
| 1304 | additional_fcpcdb_len); |
| 1305 | *fcp_dl = htonl(total_bytes); |
| 1306 | |
Arun Easi | 0c47087 | 2010-07-23 15:28:38 +0500 | [diff] [blame] | 1307 | if (!data_bytes || cmd->sc_data_direction == DMA_NONE) { |
Arun Easi | 0c47087 | 2010-07-23 15:28:38 +0500 | [diff] [blame] | 1308 | cmd_pkt->byte_count = __constant_cpu_to_le32(0); |
| 1309 | return QLA_SUCCESS; |
| 1310 | } |
Arun Easi | bad7500 | 2010-05-04 15:01:30 -0700 | [diff] [blame] | 1311 | /* Walks data segments */ |
| 1312 | |
| 1313 | cmd_pkt->control_flags |= |
| 1314 | __constant_cpu_to_le16(CF_DATA_SEG_DESCR_ENABLE); |
Arun Easi | 8cb2049 | 2011-08-16 11:29:22 -0700 | [diff] [blame] | 1315 | |
| 1316 | if (!bundling && tot_prot_dsds) { |
| 1317 | if (qla24xx_walk_and_build_sglist_no_difb(ha, sp, |
| 1318 | cur_dsd, tot_dsds)) |
| 1319 | goto crc_queuing_error; |
| 1320 | } else if (qla24xx_walk_and_build_sglist(ha, sp, cur_dsd, |
Arun Easi | bad7500 | 2010-05-04 15:01:30 -0700 | [diff] [blame] | 1321 | (tot_dsds - tot_prot_dsds))) |
| 1322 | goto crc_queuing_error; |
| 1323 | |
| 1324 | if (bundling && tot_prot_dsds) { |
| 1325 | /* Walks dif segments */ |
| 1326 | cur_seg = scsi_prot_sglist(cmd); |
| 1327 | cmd_pkt->control_flags |= |
| 1328 | __constant_cpu_to_le16(CF_DIF_SEG_DESCR_ENABLE); |
| 1329 | cur_dsd = (uint32_t *) &crc_ctx_pkt->u.bundling.dif_address; |
| 1330 | if (qla24xx_walk_and_build_prot_sglist(ha, sp, cur_dsd, |
| 1331 | tot_prot_dsds)) |
| 1332 | goto crc_queuing_error; |
| 1333 | } |
| 1334 | return QLA_SUCCESS; |
| 1335 | |
| 1336 | crc_queuing_error: |
Arun Easi | bad7500 | 2010-05-04 15:01:30 -0700 | [diff] [blame] | 1337 | /* Cleanup will be performed by the caller */ |
| 1338 | |
| 1339 | return QLA_FUNCTION_FAILED; |
| 1340 | } |
Andrew Vasquez | 2b6c0ce | 2005-07-06 10:31:17 -0700 | [diff] [blame] | 1341 | |
| 1342 | /** |
| 1343 | * qla24xx_start_scsi() - Send a SCSI command to the ISP |
| 1344 | * @sp: command to send to the ISP |
| 1345 | * |
Bjorn Helgaas | cc3ef7b | 2008-09-11 21:22:51 -0700 | [diff] [blame] | 1346 | * Returns non-zero if a failure occurred, else zero. |
Andrew Vasquez | 2b6c0ce | 2005-07-06 10:31:17 -0700 | [diff] [blame] | 1347 | */ |
| 1348 | int |
| 1349 | qla24xx_start_scsi(srb_t *sp) |
| 1350 | { |
FUJITA Tomonori | 385d70b | 2007-05-26 01:55:38 +0900 | [diff] [blame] | 1351 | int ret, nseg; |
Andrew Vasquez | 2b6c0ce | 2005-07-06 10:31:17 -0700 | [diff] [blame] | 1352 | unsigned long flags; |
Andrew Vasquez | 2b6c0ce | 2005-07-06 10:31:17 -0700 | [diff] [blame] | 1353 | uint32_t *clr_ptr; |
| 1354 | uint32_t index; |
| 1355 | uint32_t handle; |
| 1356 | struct cmd_type_7 *cmd_pkt; |
Andrew Vasquez | 2b6c0ce | 2005-07-06 10:31:17 -0700 | [diff] [blame] | 1357 | uint16_t cnt; |
| 1358 | uint16_t req_cnt; |
| 1359 | uint16_t tot_dsds; |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 1360 | struct req_que *req = NULL; |
| 1361 | struct rsp_que *rsp = NULL; |
| 1362 | struct scsi_cmnd *cmd = sp->cmd; |
Andrew Vasquez | 444786d | 2009-01-05 11:18:10 -0800 | [diff] [blame] | 1363 | struct scsi_qla_host *vha = sp->fcport->vha; |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 1364 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | ff2fc42 | 2011-02-23 15:27:15 -0800 | [diff] [blame] | 1365 | char tag[2]; |
Andrew Vasquez | 2b6c0ce | 2005-07-06 10:31:17 -0700 | [diff] [blame] | 1366 | |
| 1367 | /* Setup device pointers. */ |
| 1368 | ret = 0; |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 1369 | |
Anirban Chakraborty | 59e0b8b | 2009-06-03 09:55:19 -0700 | [diff] [blame] | 1370 | qla25xx_set_que(sp, &rsp); |
| 1371 | req = vha->req; |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 1372 | |
Andrew Vasquez | 2b6c0ce | 2005-07-06 10:31:17 -0700 | [diff] [blame] | 1373 | /* So we know we haven't pci_map'ed anything yet */ |
| 1374 | tot_dsds = 0; |
| 1375 | |
| 1376 | /* Send marker if required */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1377 | if (vha->marker_needed != 0) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1378 | if (qla2x00_marker(vha, req, rsp, 0, 0, MK_SYNC_ALL) != |
| 1379 | QLA_SUCCESS) |
Andrew Vasquez | 2b6c0ce | 2005-07-06 10:31:17 -0700 | [diff] [blame] | 1380 | return QLA_FUNCTION_FAILED; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1381 | vha->marker_needed = 0; |
Andrew Vasquez | 2b6c0ce | 2005-07-06 10:31:17 -0700 | [diff] [blame] | 1382 | } |
| 1383 | |
| 1384 | /* Acquire ring specific lock */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1385 | spin_lock_irqsave(&ha->hardware_lock, flags); |
Andrew Vasquez | 2b6c0ce | 2005-07-06 10:31:17 -0700 | [diff] [blame] | 1386 | |
| 1387 | /* Check for room in outstanding command list. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1388 | handle = req->current_outstanding_cmd; |
Andrew Vasquez | 2b6c0ce | 2005-07-06 10:31:17 -0700 | [diff] [blame] | 1389 | for (index = 1; index < MAX_OUTSTANDING_COMMANDS; index++) { |
| 1390 | handle++; |
| 1391 | if (handle == MAX_OUTSTANDING_COMMANDS) |
| 1392 | handle = 1; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1393 | if (!req->outstanding_cmds[handle]) |
Andrew Vasquez | 2b6c0ce | 2005-07-06 10:31:17 -0700 | [diff] [blame] | 1394 | break; |
| 1395 | } |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1396 | if (index == MAX_OUTSTANDING_COMMANDS) { |
Andrew Vasquez | 2b6c0ce | 2005-07-06 10:31:17 -0700 | [diff] [blame] | 1397 | goto queuing_error; |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1398 | } |
Andrew Vasquez | 2b6c0ce | 2005-07-06 10:31:17 -0700 | [diff] [blame] | 1399 | |
| 1400 | /* Map the sg table so we have an accurate count of sg entries needed */ |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 1401 | if (scsi_sg_count(cmd)) { |
| 1402 | nseg = dma_map_sg(&ha->pdev->dev, scsi_sglist(cmd), |
| 1403 | scsi_sg_count(cmd), cmd->sc_data_direction); |
| 1404 | if (unlikely(!nseg)) |
Andrew Vasquez | 2b6c0ce | 2005-07-06 10:31:17 -0700 | [diff] [blame] | 1405 | goto queuing_error; |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 1406 | } else |
| 1407 | nseg = 0; |
| 1408 | |
FUJITA Tomonori | 385d70b | 2007-05-26 01:55:38 +0900 | [diff] [blame] | 1409 | tot_dsds = nseg; |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1410 | req_cnt = qla24xx_calc_iocbs(vha, tot_dsds); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1411 | if (req->cnt < (req_cnt + 2)) { |
Andrew Vasquez | 0802999 | 2009-03-24 09:07:55 -0700 | [diff] [blame] | 1412 | cnt = RD_REG_DWORD_RELAXED(req->req_q_out); |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 1413 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1414 | if (req->ring_index < cnt) |
| 1415 | req->cnt = cnt - req->ring_index; |
Andrew Vasquez | 2b6c0ce | 2005-07-06 10:31:17 -0700 | [diff] [blame] | 1416 | else |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1417 | req->cnt = req->length - |
| 1418 | (req->ring_index - cnt); |
Andrew Vasquez | 2b6c0ce | 2005-07-06 10:31:17 -0700 | [diff] [blame] | 1419 | } |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1420 | if (req->cnt < (req_cnt + 2)) |
Andrew Vasquez | 2b6c0ce | 2005-07-06 10:31:17 -0700 | [diff] [blame] | 1421 | goto queuing_error; |
Andrew Vasquez | 2b6c0ce | 2005-07-06 10:31:17 -0700 | [diff] [blame] | 1422 | |
| 1423 | /* Build command packet. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1424 | req->current_outstanding_cmd = handle; |
| 1425 | req->outstanding_cmds[handle] = sp; |
Andrew Vasquez | cf53b06 | 2009-08-20 11:06:04 -0700 | [diff] [blame] | 1426 | sp->handle = handle; |
Andrew Vasquez | 2b6c0ce | 2005-07-06 10:31:17 -0700 | [diff] [blame] | 1427 | sp->cmd->host_scribble = (unsigned char *)(unsigned long)handle; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1428 | req->cnt -= req_cnt; |
Andrew Vasquez | 2b6c0ce | 2005-07-06 10:31:17 -0700 | [diff] [blame] | 1429 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1430 | cmd_pkt = (struct cmd_type_7 *)req->ring_ptr; |
Anirban Chakraborty | 2afa19a | 2009-04-06 22:33:40 -0700 | [diff] [blame] | 1431 | cmd_pkt->handle = MAKE_HANDLE(req->id, handle); |
Andrew Vasquez | 2b6c0ce | 2005-07-06 10:31:17 -0700 | [diff] [blame] | 1432 | |
| 1433 | /* Zero out remaining portion of packet. */ |
James Bottomley | 72df832 | 2005-10-28 14:41:19 -0500 | [diff] [blame] | 1434 | /* tagged queuing modifier -- default is TSK_SIMPLE (0). */ |
Andrew Vasquez | 2b6c0ce | 2005-07-06 10:31:17 -0700 | [diff] [blame] | 1435 | clr_ptr = (uint32_t *)cmd_pkt + 2; |
| 1436 | memset(clr_ptr, 0, REQUEST_ENTRY_SIZE - 8); |
| 1437 | cmd_pkt->dseg_count = cpu_to_le16(tot_dsds); |
| 1438 | |
| 1439 | /* Set NPORT-ID and LUN number*/ |
| 1440 | cmd_pkt->nport_handle = cpu_to_le16(sp->fcport->loop_id); |
| 1441 | cmd_pkt->port_id[0] = sp->fcport->d_id.b.al_pa; |
| 1442 | cmd_pkt->port_id[1] = sp->fcport->d_id.b.area; |
| 1443 | cmd_pkt->port_id[2] = sp->fcport->d_id.b.domain; |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 1444 | cmd_pkt->vp_index = sp->fcport->vp_idx; |
Andrew Vasquez | 2b6c0ce | 2005-07-06 10:31:17 -0700 | [diff] [blame] | 1445 | |
Andrew Vasquez | 661c3f6 | 2005-10-27 11:09:58 -0700 | [diff] [blame] | 1446 | int_to_scsilun(sp->cmd->device->lun, &cmd_pkt->lun); |
andrew.vasquez@qlogic.com | 0d4be12 | 2006-02-07 08:45:35 -0800 | [diff] [blame] | 1447 | host_to_fcp_swap((uint8_t *)&cmd_pkt->lun, sizeof(cmd_pkt->lun)); |
Andrew Vasquez | 2b6c0ce | 2005-07-06 10:31:17 -0700 | [diff] [blame] | 1448 | |
Andrew Vasquez | ff2fc42 | 2011-02-23 15:27:15 -0800 | [diff] [blame] | 1449 | /* Update tagged queuing modifier -- default is TSK_SIMPLE (0). */ |
| 1450 | if (scsi_populate_tag_msg(cmd, tag)) { |
| 1451 | switch (tag[0]) { |
| 1452 | case HEAD_OF_QUEUE_TAG: |
| 1453 | cmd_pkt->task = TSK_HEAD_OF_QUEUE; |
| 1454 | break; |
| 1455 | case ORDERED_QUEUE_TAG: |
| 1456 | cmd_pkt->task = TSK_ORDERED; |
| 1457 | break; |
| 1458 | } |
| 1459 | } |
| 1460 | |
Andrew Vasquez | 2b6c0ce | 2005-07-06 10:31:17 -0700 | [diff] [blame] | 1461 | /* Load SCSI command packet. */ |
| 1462 | memcpy(cmd_pkt->fcp_cdb, cmd->cmnd, cmd->cmd_len); |
| 1463 | host_to_fcp_swap(cmd_pkt->fcp_cdb, sizeof(cmd_pkt->fcp_cdb)); |
| 1464 | |
FUJITA Tomonori | 385d70b | 2007-05-26 01:55:38 +0900 | [diff] [blame] | 1465 | cmd_pkt->byte_count = cpu_to_le32((uint32_t)scsi_bufflen(cmd)); |
Andrew Vasquez | 2b6c0ce | 2005-07-06 10:31:17 -0700 | [diff] [blame] | 1466 | |
| 1467 | /* Build IOCB segments */ |
| 1468 | qla24xx_build_scsi_iocbs(sp, cmd_pkt, tot_dsds); |
| 1469 | |
| 1470 | /* Set total data segment count. */ |
| 1471 | cmd_pkt->entry_count = (uint8_t)req_cnt; |
Anirban Chakraborty | 2afa19a | 2009-04-06 22:33:40 -0700 | [diff] [blame] | 1472 | /* Specify response queue number where completion should happen */ |
| 1473 | cmd_pkt->entry_status = (uint8_t) rsp->id; |
Andrew Vasquez | 2b6c0ce | 2005-07-06 10:31:17 -0700 | [diff] [blame] | 1474 | wmb(); |
Andrew Vasquez | 2b6c0ce | 2005-07-06 10:31:17 -0700 | [diff] [blame] | 1475 | /* Adjust ring index. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1476 | req->ring_index++; |
| 1477 | if (req->ring_index == req->length) { |
| 1478 | req->ring_index = 0; |
| 1479 | req->ring_ptr = req->ring; |
Andrew Vasquez | 2b6c0ce | 2005-07-06 10:31:17 -0700 | [diff] [blame] | 1480 | } else |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1481 | req->ring_ptr++; |
Andrew Vasquez | 2b6c0ce | 2005-07-06 10:31:17 -0700 | [diff] [blame] | 1482 | |
| 1483 | sp->flags |= SRB_DMA_VALID; |
Andrew Vasquez | 2b6c0ce | 2005-07-06 10:31:17 -0700 | [diff] [blame] | 1484 | |
| 1485 | /* Set chip new ring index. */ |
Andrew Vasquez | 0802999 | 2009-03-24 09:07:55 -0700 | [diff] [blame] | 1486 | WRT_REG_DWORD(req->req_q_in, req->ring_index); |
| 1487 | RD_REG_DWORD_RELAXED(&ha->iobase->isp24.hccr); |
Andrew Vasquez | 2b6c0ce | 2005-07-06 10:31:17 -0700 | [diff] [blame] | 1488 | |
Andrew Vasquez | 4fdfefe | 2005-10-27 11:09:48 -0700 | [diff] [blame] | 1489 | /* Manage unprocessed RIO/ZIO commands in response queue. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1490 | if (vha->flags.process_response_queue && |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 1491 | rsp->ring_ptr->signature != RESPONSE_PROCESSED) |
Anirban Chakraborty | 2afa19a | 2009-04-06 22:33:40 -0700 | [diff] [blame] | 1492 | qla24xx_process_response_queue(vha, rsp); |
Andrew Vasquez | 4fdfefe | 2005-10-27 11:09:48 -0700 | [diff] [blame] | 1493 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1494 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
Andrew Vasquez | 2b6c0ce | 2005-07-06 10:31:17 -0700 | [diff] [blame] | 1495 | return QLA_SUCCESS; |
| 1496 | |
| 1497 | queuing_error: |
FUJITA Tomonori | 385d70b | 2007-05-26 01:55:38 +0900 | [diff] [blame] | 1498 | if (tot_dsds) |
| 1499 | scsi_dma_unmap(cmd); |
| 1500 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1501 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
Andrew Vasquez | 2b6c0ce | 2005-07-06 10:31:17 -0700 | [diff] [blame] | 1502 | |
| 1503 | return QLA_FUNCTION_FAILED; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1504 | } |
Anirban Chakraborty | 68ca949 | 2009-04-06 22:33:41 -0700 | [diff] [blame] | 1505 | |
Arun Easi | bad7500 | 2010-05-04 15:01:30 -0700 | [diff] [blame] | 1506 | |
| 1507 | /** |
| 1508 | * qla24xx_dif_start_scsi() - Send a SCSI command to the ISP |
| 1509 | * @sp: command to send to the ISP |
| 1510 | * |
| 1511 | * Returns non-zero if a failure occurred, else zero. |
| 1512 | */ |
| 1513 | int |
| 1514 | qla24xx_dif_start_scsi(srb_t *sp) |
| 1515 | { |
| 1516 | int nseg; |
| 1517 | unsigned long flags; |
| 1518 | uint32_t *clr_ptr; |
| 1519 | uint32_t index; |
| 1520 | uint32_t handle; |
| 1521 | uint16_t cnt; |
| 1522 | uint16_t req_cnt = 0; |
| 1523 | uint16_t tot_dsds; |
| 1524 | uint16_t tot_prot_dsds; |
| 1525 | uint16_t fw_prot_opts = 0; |
| 1526 | struct req_que *req = NULL; |
| 1527 | struct rsp_que *rsp = NULL; |
| 1528 | struct scsi_cmnd *cmd = sp->cmd; |
| 1529 | struct scsi_qla_host *vha = sp->fcport->vha; |
| 1530 | struct qla_hw_data *ha = vha->hw; |
| 1531 | struct cmd_type_crc_2 *cmd_pkt; |
| 1532 | uint32_t status = 0; |
| 1533 | |
| 1534 | #define QDSS_GOT_Q_SPACE BIT_0 |
| 1535 | |
Arun Easi | 0c47087 | 2010-07-23 15:28:38 +0500 | [diff] [blame] | 1536 | /* Only process protection or >16 cdb in this routine */ |
| 1537 | if (scsi_get_prot_op(cmd) == SCSI_PROT_NORMAL) { |
| 1538 | if (cmd->cmd_len <= 16) |
| 1539 | return qla24xx_start_scsi(sp); |
| 1540 | } |
Arun Easi | bad7500 | 2010-05-04 15:01:30 -0700 | [diff] [blame] | 1541 | |
| 1542 | /* Setup device pointers. */ |
| 1543 | |
| 1544 | qla25xx_set_que(sp, &rsp); |
| 1545 | req = vha->req; |
| 1546 | |
| 1547 | /* So we know we haven't pci_map'ed anything yet */ |
| 1548 | tot_dsds = 0; |
| 1549 | |
| 1550 | /* Send marker if required */ |
| 1551 | if (vha->marker_needed != 0) { |
| 1552 | if (qla2x00_marker(vha, req, rsp, 0, 0, MK_SYNC_ALL) != |
| 1553 | QLA_SUCCESS) |
| 1554 | return QLA_FUNCTION_FAILED; |
| 1555 | vha->marker_needed = 0; |
| 1556 | } |
| 1557 | |
| 1558 | /* Acquire ring specific lock */ |
| 1559 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 1560 | |
| 1561 | /* Check for room in outstanding command list. */ |
| 1562 | handle = req->current_outstanding_cmd; |
| 1563 | for (index = 1; index < MAX_OUTSTANDING_COMMANDS; index++) { |
| 1564 | handle++; |
| 1565 | if (handle == MAX_OUTSTANDING_COMMANDS) |
| 1566 | handle = 1; |
| 1567 | if (!req->outstanding_cmds[handle]) |
| 1568 | break; |
| 1569 | } |
| 1570 | |
| 1571 | if (index == MAX_OUTSTANDING_COMMANDS) |
| 1572 | goto queuing_error; |
| 1573 | |
| 1574 | /* Compute number of required data segments */ |
| 1575 | /* Map the sg table so we have an accurate count of sg entries needed */ |
| 1576 | if (scsi_sg_count(cmd)) { |
| 1577 | nseg = dma_map_sg(&ha->pdev->dev, scsi_sglist(cmd), |
| 1578 | scsi_sg_count(cmd), cmd->sc_data_direction); |
| 1579 | if (unlikely(!nseg)) |
| 1580 | goto queuing_error; |
| 1581 | else |
| 1582 | sp->flags |= SRB_DMA_VALID; |
Arun Easi | 8cb2049 | 2011-08-16 11:29:22 -0700 | [diff] [blame] | 1583 | |
| 1584 | if ((scsi_get_prot_op(cmd) == SCSI_PROT_READ_INSERT) || |
| 1585 | (scsi_get_prot_op(cmd) == SCSI_PROT_WRITE_STRIP)) { |
| 1586 | struct qla2_sgx sgx; |
| 1587 | uint32_t partial; |
| 1588 | |
| 1589 | memset(&sgx, 0, sizeof(struct qla2_sgx)); |
| 1590 | sgx.tot_bytes = scsi_bufflen(cmd); |
| 1591 | sgx.cur_sg = scsi_sglist(cmd); |
| 1592 | sgx.sp = sp; |
| 1593 | |
| 1594 | nseg = 0; |
| 1595 | while (qla24xx_get_one_block_sg( |
| 1596 | cmd->device->sector_size, &sgx, &partial)) |
| 1597 | nseg++; |
| 1598 | } |
Arun Easi | bad7500 | 2010-05-04 15:01:30 -0700 | [diff] [blame] | 1599 | } else |
| 1600 | nseg = 0; |
| 1601 | |
| 1602 | /* number of required data segments */ |
| 1603 | tot_dsds = nseg; |
| 1604 | |
| 1605 | /* Compute number of required protection segments */ |
| 1606 | if (qla24xx_configure_prot_mode(sp, &fw_prot_opts)) { |
| 1607 | nseg = dma_map_sg(&ha->pdev->dev, scsi_prot_sglist(cmd), |
| 1608 | scsi_prot_sg_count(cmd), cmd->sc_data_direction); |
| 1609 | if (unlikely(!nseg)) |
| 1610 | goto queuing_error; |
| 1611 | else |
| 1612 | sp->flags |= SRB_CRC_PROT_DMA_VALID; |
Arun Easi | 8cb2049 | 2011-08-16 11:29:22 -0700 | [diff] [blame] | 1613 | |
| 1614 | if ((scsi_get_prot_op(cmd) == SCSI_PROT_READ_INSERT) || |
| 1615 | (scsi_get_prot_op(cmd) == SCSI_PROT_WRITE_STRIP)) { |
| 1616 | nseg = scsi_bufflen(cmd) / cmd->device->sector_size; |
| 1617 | } |
Arun Easi | bad7500 | 2010-05-04 15:01:30 -0700 | [diff] [blame] | 1618 | } else { |
| 1619 | nseg = 0; |
| 1620 | } |
| 1621 | |
| 1622 | req_cnt = 1; |
| 1623 | /* Total Data and protection sg segment(s) */ |
| 1624 | tot_prot_dsds = nseg; |
| 1625 | tot_dsds += nseg; |
| 1626 | if (req->cnt < (req_cnt + 2)) { |
| 1627 | cnt = RD_REG_DWORD_RELAXED(req->req_q_out); |
| 1628 | |
| 1629 | if (req->ring_index < cnt) |
| 1630 | req->cnt = cnt - req->ring_index; |
| 1631 | else |
| 1632 | req->cnt = req->length - |
| 1633 | (req->ring_index - cnt); |
| 1634 | } |
| 1635 | |
| 1636 | if (req->cnt < (req_cnt + 2)) |
| 1637 | goto queuing_error; |
| 1638 | |
| 1639 | status |= QDSS_GOT_Q_SPACE; |
| 1640 | |
| 1641 | /* Build header part of command packet (excluding the OPCODE). */ |
| 1642 | req->current_outstanding_cmd = handle; |
| 1643 | req->outstanding_cmds[handle] = sp; |
Arun Easi | 8cb2049 | 2011-08-16 11:29:22 -0700 | [diff] [blame] | 1644 | sp->handle = handle; |
Arun Easi | bad7500 | 2010-05-04 15:01:30 -0700 | [diff] [blame] | 1645 | sp->cmd->host_scribble = (unsigned char *)(unsigned long)handle; |
| 1646 | req->cnt -= req_cnt; |
| 1647 | |
| 1648 | /* Fill-in common area */ |
| 1649 | cmd_pkt = (struct cmd_type_crc_2 *)req->ring_ptr; |
| 1650 | cmd_pkt->handle = MAKE_HANDLE(req->id, handle); |
| 1651 | |
| 1652 | clr_ptr = (uint32_t *)cmd_pkt + 2; |
| 1653 | memset(clr_ptr, 0, REQUEST_ENTRY_SIZE - 8); |
| 1654 | |
| 1655 | /* Set NPORT-ID and LUN number*/ |
| 1656 | cmd_pkt->nport_handle = cpu_to_le16(sp->fcport->loop_id); |
| 1657 | cmd_pkt->port_id[0] = sp->fcport->d_id.b.al_pa; |
| 1658 | cmd_pkt->port_id[1] = sp->fcport->d_id.b.area; |
| 1659 | cmd_pkt->port_id[2] = sp->fcport->d_id.b.domain; |
| 1660 | |
| 1661 | int_to_scsilun(sp->cmd->device->lun, &cmd_pkt->lun); |
| 1662 | host_to_fcp_swap((uint8_t *)&cmd_pkt->lun, sizeof(cmd_pkt->lun)); |
| 1663 | |
| 1664 | /* Total Data and protection segment(s) */ |
| 1665 | cmd_pkt->dseg_count = cpu_to_le16(tot_dsds); |
| 1666 | |
| 1667 | /* Build IOCB segments and adjust for data protection segments */ |
| 1668 | if (qla24xx_build_scsi_crc_2_iocbs(sp, (struct cmd_type_crc_2 *) |
| 1669 | req->ring_ptr, tot_dsds, tot_prot_dsds, fw_prot_opts) != |
| 1670 | QLA_SUCCESS) |
| 1671 | goto queuing_error; |
| 1672 | |
| 1673 | cmd_pkt->entry_count = (uint8_t)req_cnt; |
| 1674 | /* Specify response queue number where completion should happen */ |
| 1675 | cmd_pkt->entry_status = (uint8_t) rsp->id; |
| 1676 | cmd_pkt->timeout = __constant_cpu_to_le16(0); |
| 1677 | wmb(); |
| 1678 | |
| 1679 | /* Adjust ring index. */ |
| 1680 | req->ring_index++; |
| 1681 | if (req->ring_index == req->length) { |
| 1682 | req->ring_index = 0; |
| 1683 | req->ring_ptr = req->ring; |
| 1684 | } else |
| 1685 | req->ring_ptr++; |
| 1686 | |
| 1687 | /* Set chip new ring index. */ |
| 1688 | WRT_REG_DWORD(req->req_q_in, req->ring_index); |
| 1689 | RD_REG_DWORD_RELAXED(&ha->iobase->isp24.hccr); |
| 1690 | |
| 1691 | /* Manage unprocessed RIO/ZIO commands in response queue. */ |
| 1692 | if (vha->flags.process_response_queue && |
| 1693 | rsp->ring_ptr->signature != RESPONSE_PROCESSED) |
| 1694 | qla24xx_process_response_queue(vha, rsp); |
| 1695 | |
| 1696 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 1697 | |
| 1698 | return QLA_SUCCESS; |
| 1699 | |
| 1700 | queuing_error: |
| 1701 | if (status & QDSS_GOT_Q_SPACE) { |
| 1702 | req->outstanding_cmds[handle] = NULL; |
| 1703 | req->cnt += req_cnt; |
| 1704 | } |
| 1705 | /* Cleanup will be performed by the caller (queuecommand) */ |
| 1706 | |
| 1707 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
Arun Easi | bad7500 | 2010-05-04 15:01:30 -0700 | [diff] [blame] | 1708 | return QLA_FUNCTION_FAILED; |
| 1709 | } |
| 1710 | |
| 1711 | |
Anirban Chakraborty | 59e0b8b | 2009-06-03 09:55:19 -0700 | [diff] [blame] | 1712 | static void qla25xx_set_que(srb_t *sp, struct rsp_que **rsp) |
Anirban Chakraborty | 68ca949 | 2009-04-06 22:33:41 -0700 | [diff] [blame] | 1713 | { |
| 1714 | struct scsi_cmnd *cmd = sp->cmd; |
Anirban Chakraborty | 68ca949 | 2009-04-06 22:33:41 -0700 | [diff] [blame] | 1715 | struct qla_hw_data *ha = sp->fcport->vha->hw; |
| 1716 | int affinity = cmd->request->cpu; |
| 1717 | |
Anirban Chakraborty | 7163ea8 | 2009-08-05 09:18:40 -0700 | [diff] [blame] | 1718 | if (ha->flags.cpu_affinity_enabled && affinity >= 0 && |
Anirban Chakraborty | 59e0b8b | 2009-06-03 09:55:19 -0700 | [diff] [blame] | 1719 | affinity < ha->max_rsp_queues - 1) |
Anirban Chakraborty | 68ca949 | 2009-04-06 22:33:41 -0700 | [diff] [blame] | 1720 | *rsp = ha->rsp_q_map[affinity + 1]; |
Anirban Chakraborty | 59e0b8b | 2009-06-03 09:55:19 -0700 | [diff] [blame] | 1721 | else |
Anirban Chakraborty | 68ca949 | 2009-04-06 22:33:41 -0700 | [diff] [blame] | 1722 | *rsp = ha->rsp_q_map[0]; |
Anirban Chakraborty | 68ca949 | 2009-04-06 22:33:41 -0700 | [diff] [blame] | 1723 | } |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 1724 | |
| 1725 | /* Generic Control-SRB manipulation functions. */ |
Giridhar Malavali | d94d10e | 2010-07-23 15:28:23 +0500 | [diff] [blame] | 1726 | void * |
| 1727 | qla2x00_alloc_iocbs(scsi_qla_host_t *vha, srb_t *sp) |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 1728 | { |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 1729 | struct qla_hw_data *ha = vha->hw; |
| 1730 | struct req_que *req = ha->req_q_map[0]; |
| 1731 | device_reg_t __iomem *reg = ISP_QUE_REG(ha, req->id); |
| 1732 | uint32_t index, handle; |
| 1733 | request_t *pkt; |
| 1734 | uint16_t cnt, req_cnt; |
| 1735 | |
| 1736 | pkt = NULL; |
| 1737 | req_cnt = 1; |
Giridhar Malavali | d94d10e | 2010-07-23 15:28:23 +0500 | [diff] [blame] | 1738 | handle = 0; |
| 1739 | |
| 1740 | if (!sp) |
| 1741 | goto skip_cmd_array; |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 1742 | |
| 1743 | /* Check for room in outstanding command list. */ |
| 1744 | handle = req->current_outstanding_cmd; |
| 1745 | for (index = 1; index < MAX_OUTSTANDING_COMMANDS; index++) { |
| 1746 | handle++; |
| 1747 | if (handle == MAX_OUTSTANDING_COMMANDS) |
| 1748 | handle = 1; |
| 1749 | if (!req->outstanding_cmds[handle]) |
| 1750 | break; |
| 1751 | } |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1752 | if (index == MAX_OUTSTANDING_COMMANDS) { |
| 1753 | ql_log(ql_log_warn, vha, 0x700b, |
| 1754 | "No room on oustanding cmd array.\n"); |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 1755 | goto queuing_error; |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1756 | } |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 1757 | |
Giridhar Malavali | d94d10e | 2010-07-23 15:28:23 +0500 | [diff] [blame] | 1758 | /* Prep command array. */ |
| 1759 | req->current_outstanding_cmd = handle; |
| 1760 | req->outstanding_cmds[handle] = sp; |
| 1761 | sp->handle = handle; |
| 1762 | |
| 1763 | skip_cmd_array: |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 1764 | /* Check for room on request queue. */ |
| 1765 | if (req->cnt < req_cnt) { |
| 1766 | if (ha->mqenable) |
| 1767 | cnt = RD_REG_DWORD(®->isp25mq.req_q_out); |
Giridhar Malavali | d94d10e | 2010-07-23 15:28:23 +0500 | [diff] [blame] | 1768 | else if (IS_QLA82XX(ha)) |
| 1769 | cnt = RD_REG_DWORD(®->isp82.req_q_out); |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 1770 | else if (IS_FWI2_CAPABLE(ha)) |
| 1771 | cnt = RD_REG_DWORD(®->isp24.req_q_out); |
| 1772 | else |
| 1773 | cnt = qla2x00_debounce_register( |
| 1774 | ISP_REQ_Q_OUT(ha, ®->isp)); |
| 1775 | |
| 1776 | if (req->ring_index < cnt) |
| 1777 | req->cnt = cnt - req->ring_index; |
| 1778 | else |
| 1779 | req->cnt = req->length - |
| 1780 | (req->ring_index - cnt); |
| 1781 | } |
| 1782 | if (req->cnt < req_cnt) |
| 1783 | goto queuing_error; |
| 1784 | |
| 1785 | /* Prep packet */ |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 1786 | req->cnt -= req_cnt; |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 1787 | pkt = req->ring_ptr; |
| 1788 | memset(pkt, 0, REQUEST_ENTRY_SIZE); |
| 1789 | pkt->entry_count = req_cnt; |
| 1790 | pkt->handle = handle; |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 1791 | |
| 1792 | queuing_error: |
| 1793 | return pkt; |
| 1794 | } |
| 1795 | |
| 1796 | static void |
| 1797 | qla2x00_start_iocbs(srb_t *sp) |
| 1798 | { |
| 1799 | struct qla_hw_data *ha = sp->fcport->vha->hw; |
| 1800 | struct req_que *req = ha->req_q_map[0]; |
| 1801 | device_reg_t __iomem *reg = ISP_QUE_REG(ha, req->id); |
| 1802 | struct device_reg_2xxx __iomem *ioreg = &ha->iobase->isp; |
| 1803 | |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 1804 | if (IS_QLA82XX(ha)) { |
| 1805 | qla82xx_start_iocbs(sp); |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 1806 | } else { |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 1807 | /* Adjust ring index. */ |
| 1808 | req->ring_index++; |
| 1809 | if (req->ring_index == req->length) { |
| 1810 | req->ring_index = 0; |
| 1811 | req->ring_ptr = req->ring; |
| 1812 | } else |
| 1813 | req->ring_ptr++; |
| 1814 | |
| 1815 | /* Set chip new ring index. */ |
| 1816 | if (ha->mqenable) { |
| 1817 | WRT_REG_DWORD(®->isp25mq.req_q_in, req->ring_index); |
| 1818 | RD_REG_DWORD(&ioreg->hccr); |
| 1819 | } else if (IS_QLA82XX(ha)) { |
| 1820 | qla82xx_start_iocbs(sp); |
| 1821 | } else if (IS_FWI2_CAPABLE(ha)) { |
| 1822 | WRT_REG_DWORD(®->isp24.req_q_in, req->ring_index); |
| 1823 | RD_REG_DWORD_RELAXED(®->isp24.req_q_in); |
| 1824 | } else { |
| 1825 | WRT_REG_WORD(ISP_REQ_Q_IN(ha, ®->isp), |
| 1826 | req->ring_index); |
| 1827 | RD_REG_WORD_RELAXED(ISP_REQ_Q_IN(ha, ®->isp)); |
| 1828 | } |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 1829 | } |
| 1830 | } |
| 1831 | |
| 1832 | static void |
| 1833 | qla24xx_login_iocb(srb_t *sp, struct logio_entry_24xx *logio) |
| 1834 | { |
Madhuranath Iyengar | 4916392 | 2010-05-04 15:01:28 -0700 | [diff] [blame] | 1835 | struct srb_ctx *ctx = sp->ctx; |
| 1836 | struct srb_iocb *lio = ctx->u.iocb_cmd; |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 1837 | |
| 1838 | logio->entry_type = LOGINOUT_PORT_IOCB_TYPE; |
| 1839 | logio->control_flags = cpu_to_le16(LCF_COMMAND_PLOGI); |
Madhuranath Iyengar | 4916392 | 2010-05-04 15:01:28 -0700 | [diff] [blame] | 1840 | if (lio->u.logio.flags & SRB_LOGIN_COND_PLOGI) |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 1841 | logio->control_flags |= cpu_to_le16(LCF_COND_PLOGI); |
Madhuranath Iyengar | 4916392 | 2010-05-04 15:01:28 -0700 | [diff] [blame] | 1842 | if (lio->u.logio.flags & SRB_LOGIN_SKIP_PRLI) |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 1843 | logio->control_flags |= cpu_to_le16(LCF_SKIP_PRLI); |
| 1844 | logio->nport_handle = cpu_to_le16(sp->fcport->loop_id); |
| 1845 | logio->port_id[0] = sp->fcport->d_id.b.al_pa; |
| 1846 | logio->port_id[1] = sp->fcport->d_id.b.area; |
| 1847 | logio->port_id[2] = sp->fcport->d_id.b.domain; |
| 1848 | logio->vp_index = sp->fcport->vp_idx; |
| 1849 | } |
| 1850 | |
| 1851 | static void |
| 1852 | qla2x00_login_iocb(srb_t *sp, struct mbx_entry *mbx) |
| 1853 | { |
| 1854 | struct qla_hw_data *ha = sp->fcport->vha->hw; |
Madhuranath Iyengar | 4916392 | 2010-05-04 15:01:28 -0700 | [diff] [blame] | 1855 | struct srb_ctx *ctx = sp->ctx; |
| 1856 | struct srb_iocb *lio = ctx->u.iocb_cmd; |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 1857 | uint16_t opts; |
| 1858 | |
Giridhar Malavali | b963752 | 2010-05-28 15:08:15 -0700 | [diff] [blame] | 1859 | mbx->entry_type = MBX_IOCB_TYPE; |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 1860 | SET_TARGET_ID(ha, mbx->loop_id, sp->fcport->loop_id); |
| 1861 | mbx->mb0 = cpu_to_le16(MBC_LOGIN_FABRIC_PORT); |
Madhuranath Iyengar | 4916392 | 2010-05-04 15:01:28 -0700 | [diff] [blame] | 1862 | opts = lio->u.logio.flags & SRB_LOGIN_COND_PLOGI ? BIT_0 : 0; |
| 1863 | opts |= lio->u.logio.flags & SRB_LOGIN_SKIP_PRLI ? BIT_1 : 0; |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 1864 | if (HAS_EXTENDED_IDS(ha)) { |
| 1865 | mbx->mb1 = cpu_to_le16(sp->fcport->loop_id); |
| 1866 | mbx->mb10 = cpu_to_le16(opts); |
| 1867 | } else { |
| 1868 | mbx->mb1 = cpu_to_le16((sp->fcport->loop_id << 8) | opts); |
| 1869 | } |
| 1870 | mbx->mb2 = cpu_to_le16(sp->fcport->d_id.b.domain); |
| 1871 | mbx->mb3 = cpu_to_le16(sp->fcport->d_id.b.area << 8 | |
| 1872 | sp->fcport->d_id.b.al_pa); |
| 1873 | mbx->mb9 = cpu_to_le16(sp->fcport->vp_idx); |
| 1874 | } |
| 1875 | |
| 1876 | static void |
| 1877 | qla24xx_logout_iocb(srb_t *sp, struct logio_entry_24xx *logio) |
| 1878 | { |
| 1879 | logio->entry_type = LOGINOUT_PORT_IOCB_TYPE; |
| 1880 | logio->control_flags = |
| 1881 | cpu_to_le16(LCF_COMMAND_LOGO|LCF_IMPL_LOGO); |
| 1882 | logio->nport_handle = cpu_to_le16(sp->fcport->loop_id); |
| 1883 | logio->port_id[0] = sp->fcport->d_id.b.al_pa; |
| 1884 | logio->port_id[1] = sp->fcport->d_id.b.area; |
| 1885 | logio->port_id[2] = sp->fcport->d_id.b.domain; |
| 1886 | logio->vp_index = sp->fcport->vp_idx; |
| 1887 | } |
| 1888 | |
| 1889 | static void |
| 1890 | qla2x00_logout_iocb(srb_t *sp, struct mbx_entry *mbx) |
| 1891 | { |
| 1892 | struct qla_hw_data *ha = sp->fcport->vha->hw; |
| 1893 | |
Giridhar Malavali | b963752 | 2010-05-28 15:08:15 -0700 | [diff] [blame] | 1894 | mbx->entry_type = MBX_IOCB_TYPE; |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 1895 | SET_TARGET_ID(ha, mbx->loop_id, sp->fcport->loop_id); |
| 1896 | mbx->mb0 = cpu_to_le16(MBC_LOGOUT_FABRIC_PORT); |
| 1897 | mbx->mb1 = HAS_EXTENDED_IDS(ha) ? |
| 1898 | cpu_to_le16(sp->fcport->loop_id): |
| 1899 | cpu_to_le16(sp->fcport->loop_id << 8); |
| 1900 | mbx->mb2 = cpu_to_le16(sp->fcport->d_id.b.domain); |
| 1901 | mbx->mb3 = cpu_to_le16(sp->fcport->d_id.b.area << 8 | |
| 1902 | sp->fcport->d_id.b.al_pa); |
| 1903 | mbx->mb9 = cpu_to_le16(sp->fcport->vp_idx); |
| 1904 | /* Implicit: mbx->mbx10 = 0. */ |
| 1905 | } |
| 1906 | |
Giridhar Malavali | 9a069e1 | 2010-01-12 13:02:47 -0800 | [diff] [blame] | 1907 | static void |
Andrew Vasquez | 5ff1d58 | 2010-05-04 15:01:26 -0700 | [diff] [blame] | 1908 | qla24xx_adisc_iocb(srb_t *sp, struct logio_entry_24xx *logio) |
| 1909 | { |
| 1910 | logio->entry_type = LOGINOUT_PORT_IOCB_TYPE; |
| 1911 | logio->control_flags = cpu_to_le16(LCF_COMMAND_ADISC); |
| 1912 | logio->nport_handle = cpu_to_le16(sp->fcport->loop_id); |
| 1913 | logio->vp_index = sp->fcport->vp_idx; |
| 1914 | } |
| 1915 | |
| 1916 | static void |
| 1917 | qla2x00_adisc_iocb(srb_t *sp, struct mbx_entry *mbx) |
| 1918 | { |
| 1919 | struct qla_hw_data *ha = sp->fcport->vha->hw; |
| 1920 | |
| 1921 | mbx->entry_type = MBX_IOCB_TYPE; |
| 1922 | SET_TARGET_ID(ha, mbx->loop_id, sp->fcport->loop_id); |
| 1923 | mbx->mb0 = cpu_to_le16(MBC_GET_PORT_DATABASE); |
| 1924 | if (HAS_EXTENDED_IDS(ha)) { |
| 1925 | mbx->mb1 = cpu_to_le16(sp->fcport->loop_id); |
| 1926 | mbx->mb10 = cpu_to_le16(BIT_0); |
| 1927 | } else { |
| 1928 | mbx->mb1 = cpu_to_le16((sp->fcport->loop_id << 8) | BIT_0); |
| 1929 | } |
| 1930 | mbx->mb2 = cpu_to_le16(MSW(ha->async_pd_dma)); |
| 1931 | mbx->mb3 = cpu_to_le16(LSW(ha->async_pd_dma)); |
| 1932 | mbx->mb6 = cpu_to_le16(MSW(MSD(ha->async_pd_dma))); |
| 1933 | mbx->mb7 = cpu_to_le16(LSW(MSD(ha->async_pd_dma))); |
| 1934 | mbx->mb9 = cpu_to_le16(sp->fcport->vp_idx); |
| 1935 | } |
| 1936 | |
| 1937 | static void |
Madhuranath Iyengar | 3822263 | 2010-05-04 15:01:29 -0700 | [diff] [blame] | 1938 | qla24xx_tm_iocb(srb_t *sp, struct tsk_mgmt_entry *tsk) |
| 1939 | { |
| 1940 | uint32_t flags; |
| 1941 | unsigned int lun; |
| 1942 | struct fc_port *fcport = sp->fcport; |
| 1943 | scsi_qla_host_t *vha = fcport->vha; |
| 1944 | struct qla_hw_data *ha = vha->hw; |
| 1945 | struct srb_ctx *ctx = sp->ctx; |
| 1946 | struct srb_iocb *iocb = ctx->u.iocb_cmd; |
| 1947 | struct req_que *req = vha->req; |
| 1948 | |
| 1949 | flags = iocb->u.tmf.flags; |
| 1950 | lun = iocb->u.tmf.lun; |
| 1951 | |
| 1952 | tsk->entry_type = TSK_MGMT_IOCB_TYPE; |
| 1953 | tsk->entry_count = 1; |
| 1954 | tsk->handle = MAKE_HANDLE(req->id, tsk->handle); |
| 1955 | tsk->nport_handle = cpu_to_le16(fcport->loop_id); |
| 1956 | tsk->timeout = cpu_to_le16(ha->r_a_tov / 10 * 2); |
| 1957 | tsk->control_flags = cpu_to_le32(flags); |
| 1958 | tsk->port_id[0] = fcport->d_id.b.al_pa; |
| 1959 | tsk->port_id[1] = fcport->d_id.b.area; |
| 1960 | tsk->port_id[2] = fcport->d_id.b.domain; |
| 1961 | tsk->vp_index = fcport->vp_idx; |
| 1962 | |
| 1963 | if (flags == TCF_LUN_RESET) { |
| 1964 | int_to_scsilun(lun, &tsk->lun); |
| 1965 | host_to_fcp_swap((uint8_t *)&tsk->lun, |
| 1966 | sizeof(tsk->lun)); |
| 1967 | } |
| 1968 | } |
| 1969 | |
| 1970 | static void |
Giridhar Malavali | 9a069e1 | 2010-01-12 13:02:47 -0800 | [diff] [blame] | 1971 | qla24xx_els_iocb(srb_t *sp, struct els_entry_24xx *els_iocb) |
| 1972 | { |
Madhuranath Iyengar | 4916392 | 2010-05-04 15:01:28 -0700 | [diff] [blame] | 1973 | struct fc_bsg_job *bsg_job = ((struct srb_ctx *)sp->ctx)->u.bsg_job; |
Giridhar Malavali | 9a069e1 | 2010-01-12 13:02:47 -0800 | [diff] [blame] | 1974 | |
| 1975 | els_iocb->entry_type = ELS_IOCB_TYPE; |
| 1976 | els_iocb->entry_count = 1; |
| 1977 | els_iocb->sys_define = 0; |
| 1978 | els_iocb->entry_status = 0; |
| 1979 | els_iocb->handle = sp->handle; |
| 1980 | els_iocb->nport_handle = cpu_to_le16(sp->fcport->loop_id); |
| 1981 | els_iocb->tx_dsd_count = __constant_cpu_to_le16(bsg_job->request_payload.sg_cnt); |
| 1982 | els_iocb->vp_index = sp->fcport->vp_idx; |
| 1983 | els_iocb->sof_type = EST_SOFI3; |
| 1984 | els_iocb->rx_dsd_count = __constant_cpu_to_le16(bsg_job->reply_payload.sg_cnt); |
| 1985 | |
Madhuranath Iyengar | 4916392 | 2010-05-04 15:01:28 -0700 | [diff] [blame] | 1986 | els_iocb->opcode = |
| 1987 | (((struct srb_ctx *)sp->ctx)->type == SRB_ELS_CMD_RPT) ? |
| 1988 | bsg_job->request->rqst_data.r_els.els_code : |
| 1989 | bsg_job->request->rqst_data.h_els.command_code; |
Giridhar Malavali | 9a069e1 | 2010-01-12 13:02:47 -0800 | [diff] [blame] | 1990 | els_iocb->port_id[0] = sp->fcport->d_id.b.al_pa; |
| 1991 | els_iocb->port_id[1] = sp->fcport->d_id.b.area; |
| 1992 | els_iocb->port_id[2] = sp->fcport->d_id.b.domain; |
| 1993 | els_iocb->control_flags = 0; |
| 1994 | els_iocb->rx_byte_count = |
| 1995 | cpu_to_le32(bsg_job->reply_payload.payload_len); |
| 1996 | els_iocb->tx_byte_count = |
| 1997 | cpu_to_le32(bsg_job->request_payload.payload_len); |
| 1998 | |
| 1999 | els_iocb->tx_address[0] = cpu_to_le32(LSD(sg_dma_address |
| 2000 | (bsg_job->request_payload.sg_list))); |
| 2001 | els_iocb->tx_address[1] = cpu_to_le32(MSD(sg_dma_address |
| 2002 | (bsg_job->request_payload.sg_list))); |
| 2003 | els_iocb->tx_len = cpu_to_le32(sg_dma_len |
| 2004 | (bsg_job->request_payload.sg_list)); |
| 2005 | |
| 2006 | els_iocb->rx_address[0] = cpu_to_le32(LSD(sg_dma_address |
| 2007 | (bsg_job->reply_payload.sg_list))); |
| 2008 | els_iocb->rx_address[1] = cpu_to_le32(MSD(sg_dma_address |
| 2009 | (bsg_job->reply_payload.sg_list))); |
| 2010 | els_iocb->rx_len = cpu_to_le32(sg_dma_len |
| 2011 | (bsg_job->reply_payload.sg_list)); |
| 2012 | } |
| 2013 | |
| 2014 | static void |
Harish Zunjarrao | 9bc4f4f | 2010-07-23 15:28:32 +0500 | [diff] [blame] | 2015 | qla2x00_ct_iocb(srb_t *sp, ms_iocb_entry_t *ct_iocb) |
| 2016 | { |
| 2017 | uint16_t avail_dsds; |
| 2018 | uint32_t *cur_dsd; |
| 2019 | struct scatterlist *sg; |
| 2020 | int index; |
| 2021 | uint16_t tot_dsds; |
| 2022 | scsi_qla_host_t *vha = sp->fcport->vha; |
| 2023 | struct qla_hw_data *ha = vha->hw; |
| 2024 | struct fc_bsg_job *bsg_job = ((struct srb_ctx *)sp->ctx)->u.bsg_job; |
| 2025 | int loop_iterartion = 0; |
| 2026 | int cont_iocb_prsnt = 0; |
| 2027 | int entry_count = 1; |
| 2028 | |
| 2029 | memset(ct_iocb, 0, sizeof(ms_iocb_entry_t)); |
| 2030 | ct_iocb->entry_type = CT_IOCB_TYPE; |
| 2031 | ct_iocb->entry_status = 0; |
| 2032 | ct_iocb->handle1 = sp->handle; |
| 2033 | SET_TARGET_ID(ha, ct_iocb->loop_id, sp->fcport->loop_id); |
| 2034 | ct_iocb->status = __constant_cpu_to_le16(0); |
| 2035 | ct_iocb->control_flags = __constant_cpu_to_le16(0); |
| 2036 | ct_iocb->timeout = 0; |
| 2037 | ct_iocb->cmd_dsd_count = |
| 2038 | __constant_cpu_to_le16(bsg_job->request_payload.sg_cnt); |
| 2039 | ct_iocb->total_dsd_count = |
| 2040 | __constant_cpu_to_le16(bsg_job->request_payload.sg_cnt + 1); |
| 2041 | ct_iocb->req_bytecount = |
| 2042 | cpu_to_le32(bsg_job->request_payload.payload_len); |
| 2043 | ct_iocb->rsp_bytecount = |
| 2044 | cpu_to_le32(bsg_job->reply_payload.payload_len); |
| 2045 | |
| 2046 | ct_iocb->dseg_req_address[0] = cpu_to_le32(LSD(sg_dma_address |
| 2047 | (bsg_job->request_payload.sg_list))); |
| 2048 | ct_iocb->dseg_req_address[1] = cpu_to_le32(MSD(sg_dma_address |
| 2049 | (bsg_job->request_payload.sg_list))); |
| 2050 | ct_iocb->dseg_req_length = ct_iocb->req_bytecount; |
| 2051 | |
| 2052 | ct_iocb->dseg_rsp_address[0] = cpu_to_le32(LSD(sg_dma_address |
| 2053 | (bsg_job->reply_payload.sg_list))); |
| 2054 | ct_iocb->dseg_rsp_address[1] = cpu_to_le32(MSD(sg_dma_address |
| 2055 | (bsg_job->reply_payload.sg_list))); |
| 2056 | ct_iocb->dseg_rsp_length = ct_iocb->rsp_bytecount; |
| 2057 | |
| 2058 | avail_dsds = 1; |
| 2059 | cur_dsd = (uint32_t *)ct_iocb->dseg_rsp_address; |
| 2060 | index = 0; |
| 2061 | tot_dsds = bsg_job->reply_payload.sg_cnt; |
| 2062 | |
| 2063 | for_each_sg(bsg_job->reply_payload.sg_list, sg, tot_dsds, index) { |
| 2064 | dma_addr_t sle_dma; |
| 2065 | cont_a64_entry_t *cont_pkt; |
| 2066 | |
| 2067 | /* Allocate additional continuation packets? */ |
| 2068 | if (avail_dsds == 0) { |
| 2069 | /* |
| 2070 | * Five DSDs are available in the Cont. |
| 2071 | * Type 1 IOCB. |
| 2072 | */ |
Giridhar Malavali | 0d2aa38 | 2011-11-18 09:02:21 -0800 | [diff] [blame] | 2073 | cont_pkt = qla2x00_prep_cont_type1_iocb(vha, |
| 2074 | vha->hw->req_q_map[0]); |
Harish Zunjarrao | 9bc4f4f | 2010-07-23 15:28:32 +0500 | [diff] [blame] | 2075 | cur_dsd = (uint32_t *) cont_pkt->dseg_0_address; |
| 2076 | avail_dsds = 5; |
| 2077 | cont_iocb_prsnt = 1; |
| 2078 | entry_count++; |
| 2079 | } |
| 2080 | |
| 2081 | sle_dma = sg_dma_address(sg); |
| 2082 | *cur_dsd++ = cpu_to_le32(LSD(sle_dma)); |
| 2083 | *cur_dsd++ = cpu_to_le32(MSD(sle_dma)); |
| 2084 | *cur_dsd++ = cpu_to_le32(sg_dma_len(sg)); |
| 2085 | loop_iterartion++; |
| 2086 | avail_dsds--; |
| 2087 | } |
| 2088 | ct_iocb->entry_count = entry_count; |
| 2089 | } |
| 2090 | |
| 2091 | static void |
Giridhar Malavali | 9a069e1 | 2010-01-12 13:02:47 -0800 | [diff] [blame] | 2092 | qla24xx_ct_iocb(srb_t *sp, struct ct_entry_24xx *ct_iocb) |
| 2093 | { |
| 2094 | uint16_t avail_dsds; |
| 2095 | uint32_t *cur_dsd; |
| 2096 | struct scatterlist *sg; |
| 2097 | int index; |
| 2098 | uint16_t tot_dsds; |
| 2099 | scsi_qla_host_t *vha = sp->fcport->vha; |
Giridhar Malavali | 0d2aa38 | 2011-11-18 09:02:21 -0800 | [diff] [blame] | 2100 | struct qla_hw_data *ha = vha->hw; |
Madhuranath Iyengar | 4916392 | 2010-05-04 15:01:28 -0700 | [diff] [blame] | 2101 | struct fc_bsg_job *bsg_job = ((struct srb_ctx *)sp->ctx)->u.bsg_job; |
Giridhar Malavali | 9a069e1 | 2010-01-12 13:02:47 -0800 | [diff] [blame] | 2102 | int loop_iterartion = 0; |
| 2103 | int cont_iocb_prsnt = 0; |
| 2104 | int entry_count = 1; |
| 2105 | |
| 2106 | ct_iocb->entry_type = CT_IOCB_TYPE; |
| 2107 | ct_iocb->entry_status = 0; |
| 2108 | ct_iocb->sys_define = 0; |
| 2109 | ct_iocb->handle = sp->handle; |
| 2110 | |
| 2111 | ct_iocb->nport_handle = cpu_to_le16(sp->fcport->loop_id); |
| 2112 | ct_iocb->vp_index = sp->fcport->vp_idx; |
| 2113 | ct_iocb->comp_status = __constant_cpu_to_le16(0); |
| 2114 | |
| 2115 | ct_iocb->cmd_dsd_count = |
| 2116 | __constant_cpu_to_le16(bsg_job->request_payload.sg_cnt); |
| 2117 | ct_iocb->timeout = 0; |
| 2118 | ct_iocb->rsp_dsd_count = |
| 2119 | __constant_cpu_to_le16(bsg_job->reply_payload.sg_cnt); |
| 2120 | ct_iocb->rsp_byte_count = |
| 2121 | cpu_to_le32(bsg_job->reply_payload.payload_len); |
| 2122 | ct_iocb->cmd_byte_count = |
| 2123 | cpu_to_le32(bsg_job->request_payload.payload_len); |
| 2124 | ct_iocb->dseg_0_address[0] = cpu_to_le32(LSD(sg_dma_address |
| 2125 | (bsg_job->request_payload.sg_list))); |
| 2126 | ct_iocb->dseg_0_address[1] = cpu_to_le32(MSD(sg_dma_address |
| 2127 | (bsg_job->request_payload.sg_list))); |
| 2128 | ct_iocb->dseg_0_len = cpu_to_le32(sg_dma_len |
| 2129 | (bsg_job->request_payload.sg_list)); |
| 2130 | |
| 2131 | avail_dsds = 1; |
| 2132 | cur_dsd = (uint32_t *)ct_iocb->dseg_1_address; |
| 2133 | index = 0; |
| 2134 | tot_dsds = bsg_job->reply_payload.sg_cnt; |
| 2135 | |
| 2136 | for_each_sg(bsg_job->reply_payload.sg_list, sg, tot_dsds, index) { |
| 2137 | dma_addr_t sle_dma; |
| 2138 | cont_a64_entry_t *cont_pkt; |
| 2139 | |
| 2140 | /* Allocate additional continuation packets? */ |
| 2141 | if (avail_dsds == 0) { |
| 2142 | /* |
| 2143 | * Five DSDs are available in the Cont. |
| 2144 | * Type 1 IOCB. |
| 2145 | */ |
Giridhar Malavali | 0d2aa38 | 2011-11-18 09:02:21 -0800 | [diff] [blame] | 2146 | cont_pkt = qla2x00_prep_cont_type1_iocb(vha, |
| 2147 | ha->req_q_map[0]); |
Giridhar Malavali | 9a069e1 | 2010-01-12 13:02:47 -0800 | [diff] [blame] | 2148 | cur_dsd = (uint32_t *) cont_pkt->dseg_0_address; |
| 2149 | avail_dsds = 5; |
| 2150 | cont_iocb_prsnt = 1; |
| 2151 | entry_count++; |
| 2152 | } |
| 2153 | |
| 2154 | sle_dma = sg_dma_address(sg); |
| 2155 | *cur_dsd++ = cpu_to_le32(LSD(sle_dma)); |
| 2156 | *cur_dsd++ = cpu_to_le32(MSD(sle_dma)); |
| 2157 | *cur_dsd++ = cpu_to_le32(sg_dma_len(sg)); |
| 2158 | loop_iterartion++; |
| 2159 | avail_dsds--; |
| 2160 | } |
| 2161 | ct_iocb->entry_count = entry_count; |
| 2162 | } |
| 2163 | |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 2164 | int |
| 2165 | qla2x00_start_sp(srb_t *sp) |
| 2166 | { |
| 2167 | int rval; |
| 2168 | struct qla_hw_data *ha = sp->fcport->vha->hw; |
| 2169 | void *pkt; |
| 2170 | struct srb_ctx *ctx = sp->ctx; |
| 2171 | unsigned long flags; |
| 2172 | |
| 2173 | rval = QLA_FUNCTION_FAILED; |
| 2174 | spin_lock_irqsave(&ha->hardware_lock, flags); |
Giridhar Malavali | d94d10e | 2010-07-23 15:28:23 +0500 | [diff] [blame] | 2175 | pkt = qla2x00_alloc_iocbs(sp->fcport->vha, sp); |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2176 | if (!pkt) { |
| 2177 | ql_log(ql_log_warn, sp->fcport->vha, 0x700c, |
| 2178 | "qla2x00_alloc_iocbs failed.\n"); |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 2179 | goto done; |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2180 | } |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 2181 | |
| 2182 | rval = QLA_SUCCESS; |
| 2183 | switch (ctx->type) { |
| 2184 | case SRB_LOGIN_CMD: |
| 2185 | IS_FWI2_CAPABLE(ha) ? |
Andrew Vasquez | 5ff1d58 | 2010-05-04 15:01:26 -0700 | [diff] [blame] | 2186 | qla24xx_login_iocb(sp, pkt) : |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 2187 | qla2x00_login_iocb(sp, pkt); |
| 2188 | break; |
| 2189 | case SRB_LOGOUT_CMD: |
| 2190 | IS_FWI2_CAPABLE(ha) ? |
Andrew Vasquez | 5ff1d58 | 2010-05-04 15:01:26 -0700 | [diff] [blame] | 2191 | qla24xx_logout_iocb(sp, pkt) : |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 2192 | qla2x00_logout_iocb(sp, pkt); |
| 2193 | break; |
Giridhar Malavali | 9a069e1 | 2010-01-12 13:02:47 -0800 | [diff] [blame] | 2194 | case SRB_ELS_CMD_RPT: |
| 2195 | case SRB_ELS_CMD_HST: |
| 2196 | qla24xx_els_iocb(sp, pkt); |
| 2197 | break; |
| 2198 | case SRB_CT_CMD: |
Harish Zunjarrao | 9bc4f4f | 2010-07-23 15:28:32 +0500 | [diff] [blame] | 2199 | IS_FWI2_CAPABLE(ha) ? |
| 2200 | qla24xx_ct_iocb(sp, pkt) : |
| 2201 | qla2x00_ct_iocb(sp, pkt); |
Giridhar Malavali | 9a069e1 | 2010-01-12 13:02:47 -0800 | [diff] [blame] | 2202 | break; |
Andrew Vasquez | 5ff1d58 | 2010-05-04 15:01:26 -0700 | [diff] [blame] | 2203 | case SRB_ADISC_CMD: |
| 2204 | IS_FWI2_CAPABLE(ha) ? |
| 2205 | qla24xx_adisc_iocb(sp, pkt) : |
| 2206 | qla2x00_adisc_iocb(sp, pkt); |
| 2207 | break; |
Madhuranath Iyengar | 3822263 | 2010-05-04 15:01:29 -0700 | [diff] [blame] | 2208 | case SRB_TM_CMD: |
| 2209 | qla24xx_tm_iocb(sp, pkt); |
| 2210 | break; |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 2211 | default: |
| 2212 | break; |
| 2213 | } |
| 2214 | |
| 2215 | wmb(); |
| 2216 | qla2x00_start_iocbs(sp); |
| 2217 | done: |
| 2218 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 2219 | return rval; |
| 2220 | } |