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