Andrew Vasquez | fa90c54 | 2005-10-27 11:10:08 -0700 | [diff] [blame] | 1 | /* |
| 2 | * QLogic Fibre Channel HBA Driver |
| 3 | * Copyright (c) 2003-2005 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 | |
| 14 | static inline uint16_t qla2x00_get_cmd_direction(struct scsi_cmnd *cmd); |
| 15 | static inline cont_entry_t *qla2x00_prep_cont_type0_iocb(scsi_qla_host_t *); |
| 16 | static inline cont_a64_entry_t *qla2x00_prep_cont_type1_iocb(scsi_qla_host_t *); |
| 17 | static request_t *qla2x00_req_pkt(scsi_qla_host_t *ha); |
Adrian Bunk | 413975a | 2006-06-30 02:33:06 -0700 | [diff] [blame] | 18 | static void qla2x00_isp_cmd(scsi_qla_host_t *ha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 19 | |
| 20 | /** |
| 21 | * qla2x00_get_cmd_direction() - Determine control_flag data direction. |
| 22 | * @cmd: SCSI command |
| 23 | * |
| 24 | * Returns the proper CF_* direction based on CDB. |
| 25 | */ |
| 26 | static inline uint16_t |
| 27 | qla2x00_get_cmd_direction(struct scsi_cmnd *cmd) |
| 28 | { |
| 29 | uint16_t cflags; |
| 30 | |
| 31 | cflags = 0; |
| 32 | |
| 33 | /* Set transfer direction */ |
| 34 | if (cmd->sc_data_direction == DMA_TO_DEVICE) |
| 35 | cflags = CF_WRITE; |
| 36 | else if (cmd->sc_data_direction == DMA_FROM_DEVICE) |
| 37 | cflags = CF_READ; |
| 38 | return (cflags); |
| 39 | } |
| 40 | |
| 41 | /** |
| 42 | * qla2x00_calc_iocbs_32() - Determine number of Command Type 2 and |
| 43 | * Continuation Type 0 IOCBs to allocate. |
| 44 | * |
| 45 | * @dsds: number of data segment decriptors needed |
| 46 | * |
| 47 | * Returns the number of IOCB entries needed to store @dsds. |
| 48 | */ |
| 49 | uint16_t |
| 50 | qla2x00_calc_iocbs_32(uint16_t dsds) |
| 51 | { |
| 52 | uint16_t iocbs; |
| 53 | |
| 54 | iocbs = 1; |
| 55 | if (dsds > 3) { |
| 56 | iocbs += (dsds - 3) / 7; |
| 57 | if ((dsds - 3) % 7) |
| 58 | iocbs++; |
| 59 | } |
| 60 | return (iocbs); |
| 61 | } |
| 62 | |
| 63 | /** |
| 64 | * qla2x00_calc_iocbs_64() - Determine number of Command Type 3 and |
| 65 | * Continuation Type 1 IOCBs to allocate. |
| 66 | * |
| 67 | * @dsds: number of data segment decriptors needed |
| 68 | * |
| 69 | * Returns the number of IOCB entries needed to store @dsds. |
| 70 | */ |
| 71 | uint16_t |
| 72 | qla2x00_calc_iocbs_64(uint16_t dsds) |
| 73 | { |
| 74 | uint16_t iocbs; |
| 75 | |
| 76 | iocbs = 1; |
| 77 | if (dsds > 2) { |
| 78 | iocbs += (dsds - 2) / 5; |
| 79 | if ((dsds - 2) % 5) |
| 80 | iocbs++; |
| 81 | } |
| 82 | return (iocbs); |
| 83 | } |
| 84 | |
| 85 | /** |
| 86 | * qla2x00_prep_cont_type0_iocb() - Initialize a Continuation Type 0 IOCB. |
| 87 | * @ha: HA context |
| 88 | * |
| 89 | * Returns a pointer to the Continuation Type 0 IOCB packet. |
| 90 | */ |
| 91 | static inline cont_entry_t * |
| 92 | qla2x00_prep_cont_type0_iocb(scsi_qla_host_t *ha) |
| 93 | { |
| 94 | cont_entry_t *cont_pkt; |
| 95 | |
| 96 | /* Adjust ring index. */ |
| 97 | ha->req_ring_index++; |
| 98 | if (ha->req_ring_index == ha->request_q_length) { |
| 99 | ha->req_ring_index = 0; |
| 100 | ha->request_ring_ptr = ha->request_ring; |
| 101 | } else { |
| 102 | ha->request_ring_ptr++; |
| 103 | } |
| 104 | |
| 105 | cont_pkt = (cont_entry_t *)ha->request_ring_ptr; |
| 106 | |
| 107 | /* Load packet defaults. */ |
| 108 | *((uint32_t *)(&cont_pkt->entry_type)) = |
| 109 | __constant_cpu_to_le32(CONTINUE_TYPE); |
| 110 | |
| 111 | return (cont_pkt); |
| 112 | } |
| 113 | |
| 114 | /** |
| 115 | * qla2x00_prep_cont_type1_iocb() - Initialize a Continuation Type 1 IOCB. |
| 116 | * @ha: HA context |
| 117 | * |
| 118 | * Returns a pointer to the continuation type 1 IOCB packet. |
| 119 | */ |
| 120 | static inline cont_a64_entry_t * |
| 121 | qla2x00_prep_cont_type1_iocb(scsi_qla_host_t *ha) |
| 122 | { |
| 123 | cont_a64_entry_t *cont_pkt; |
| 124 | |
| 125 | /* Adjust ring index. */ |
| 126 | ha->req_ring_index++; |
| 127 | if (ha->req_ring_index == ha->request_q_length) { |
| 128 | ha->req_ring_index = 0; |
| 129 | ha->request_ring_ptr = ha->request_ring; |
| 130 | } else { |
| 131 | ha->request_ring_ptr++; |
| 132 | } |
| 133 | |
| 134 | cont_pkt = (cont_a64_entry_t *)ha->request_ring_ptr; |
| 135 | |
| 136 | /* Load packet defaults. */ |
| 137 | *((uint32_t *)(&cont_pkt->entry_type)) = |
| 138 | __constant_cpu_to_le32(CONTINUE_A64_TYPE); |
| 139 | |
| 140 | return (cont_pkt); |
| 141 | } |
| 142 | |
| 143 | /** |
| 144 | * qla2x00_build_scsi_iocbs_32() - Build IOCB command utilizing 32bit |
| 145 | * capable IOCB types. |
| 146 | * |
| 147 | * @sp: SRB command to process |
| 148 | * @cmd_pkt: Command type 2 IOCB |
| 149 | * @tot_dsds: Total number of segments to transfer |
| 150 | */ |
| 151 | void qla2x00_build_scsi_iocbs_32(srb_t *sp, cmd_entry_t *cmd_pkt, |
| 152 | uint16_t tot_dsds) |
| 153 | { |
| 154 | uint16_t avail_dsds; |
| 155 | uint32_t *cur_dsd; |
| 156 | scsi_qla_host_t *ha; |
| 157 | struct scsi_cmnd *cmd; |
FUJITA Tomonori | 385d70b | 2007-05-26 01:55:38 +0900 | [diff] [blame^] | 158 | struct scatterlist *sg; |
| 159 | int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 160 | |
| 161 | cmd = sp->cmd; |
| 162 | |
| 163 | /* Update entry type to indicate Command Type 2 IOCB */ |
| 164 | *((uint32_t *)(&cmd_pkt->entry_type)) = |
| 165 | __constant_cpu_to_le32(COMMAND_TYPE); |
| 166 | |
| 167 | /* No data transfer */ |
FUJITA Tomonori | 385d70b | 2007-05-26 01:55:38 +0900 | [diff] [blame^] | 168 | if (!scsi_bufflen(cmd) || cmd->sc_data_direction == DMA_NONE) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 169 | cmd_pkt->byte_count = __constant_cpu_to_le32(0); |
| 170 | return; |
| 171 | } |
| 172 | |
| 173 | ha = sp->ha; |
| 174 | |
| 175 | cmd_pkt->control_flags |= cpu_to_le16(qla2x00_get_cmd_direction(cmd)); |
| 176 | |
| 177 | /* Three DSDs are available in the Command Type 2 IOCB */ |
| 178 | avail_dsds = 3; |
| 179 | cur_dsd = (uint32_t *)&cmd_pkt->dseg_0_address; |
| 180 | |
| 181 | /* Load data segments */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 182 | |
FUJITA Tomonori | 385d70b | 2007-05-26 01:55:38 +0900 | [diff] [blame^] | 183 | scsi_for_each_sg(cmd, sg, tot_dsds, i) { |
| 184 | cont_entry_t *cont_pkt; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 185 | |
FUJITA Tomonori | 385d70b | 2007-05-26 01:55:38 +0900 | [diff] [blame^] | 186 | /* Allocate additional continuation packets? */ |
| 187 | if (avail_dsds == 0) { |
| 188 | /* |
| 189 | * Seven DSDs are available in the Continuation |
| 190 | * Type 0 IOCB. |
| 191 | */ |
| 192 | cont_pkt = qla2x00_prep_cont_type0_iocb(ha); |
| 193 | cur_dsd = (uint32_t *)&cont_pkt->dseg_0_address; |
| 194 | avail_dsds = 7; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 195 | } |
FUJITA Tomonori | 385d70b | 2007-05-26 01:55:38 +0900 | [diff] [blame^] | 196 | |
| 197 | *cur_dsd++ = cpu_to_le32(sg_dma_address(sg)); |
| 198 | *cur_dsd++ = cpu_to_le32(sg_dma_len(sg)); |
| 199 | avail_dsds--; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 200 | } |
| 201 | } |
| 202 | |
| 203 | /** |
| 204 | * qla2x00_build_scsi_iocbs_64() - Build IOCB command utilizing 64bit |
| 205 | * capable IOCB types. |
| 206 | * |
| 207 | * @sp: SRB command to process |
| 208 | * @cmd_pkt: Command type 3 IOCB |
| 209 | * @tot_dsds: Total number of segments to transfer |
| 210 | */ |
| 211 | void qla2x00_build_scsi_iocbs_64(srb_t *sp, cmd_entry_t *cmd_pkt, |
| 212 | uint16_t tot_dsds) |
| 213 | { |
| 214 | uint16_t avail_dsds; |
| 215 | uint32_t *cur_dsd; |
| 216 | scsi_qla_host_t *ha; |
| 217 | struct scsi_cmnd *cmd; |
FUJITA Tomonori | 385d70b | 2007-05-26 01:55:38 +0900 | [diff] [blame^] | 218 | struct scatterlist *sg; |
| 219 | int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 220 | |
| 221 | cmd = sp->cmd; |
| 222 | |
| 223 | /* Update entry type to indicate Command Type 3 IOCB */ |
| 224 | *((uint32_t *)(&cmd_pkt->entry_type)) = |
| 225 | __constant_cpu_to_le32(COMMAND_A64_TYPE); |
| 226 | |
| 227 | /* No data transfer */ |
FUJITA Tomonori | 385d70b | 2007-05-26 01:55:38 +0900 | [diff] [blame^] | 228 | if (!scsi_bufflen(cmd) || cmd->sc_data_direction == DMA_NONE) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 229 | cmd_pkt->byte_count = __constant_cpu_to_le32(0); |
| 230 | return; |
| 231 | } |
| 232 | |
| 233 | ha = sp->ha; |
| 234 | |
| 235 | cmd_pkt->control_flags |= cpu_to_le16(qla2x00_get_cmd_direction(cmd)); |
| 236 | |
| 237 | /* Two DSDs are available in the Command Type 3 IOCB */ |
| 238 | avail_dsds = 2; |
| 239 | cur_dsd = (uint32_t *)&cmd_pkt->dseg_0_address; |
| 240 | |
| 241 | /* Load data segments */ |
FUJITA Tomonori | 385d70b | 2007-05-26 01:55:38 +0900 | [diff] [blame^] | 242 | scsi_for_each_sg(cmd, sg, tot_dsds, i) { |
| 243 | dma_addr_t sle_dma; |
| 244 | cont_a64_entry_t *cont_pkt; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 245 | |
FUJITA Tomonori | 385d70b | 2007-05-26 01:55:38 +0900 | [diff] [blame^] | 246 | /* Allocate additional continuation packets? */ |
| 247 | if (avail_dsds == 0) { |
| 248 | /* |
| 249 | * Five DSDs are available in the Continuation |
| 250 | * Type 1 IOCB. |
| 251 | */ |
| 252 | cont_pkt = qla2x00_prep_cont_type1_iocb(ha); |
| 253 | cur_dsd = (uint32_t *)cont_pkt->dseg_0_address; |
| 254 | avail_dsds = 5; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 255 | } |
FUJITA Tomonori | 385d70b | 2007-05-26 01:55:38 +0900 | [diff] [blame^] | 256 | |
| 257 | sle_dma = sg_dma_address(sg); |
| 258 | *cur_dsd++ = cpu_to_le32(LSD(sle_dma)); |
| 259 | *cur_dsd++ = cpu_to_le32(MSD(sle_dma)); |
| 260 | *cur_dsd++ = cpu_to_le32(sg_dma_len(sg)); |
| 261 | avail_dsds--; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 262 | } |
| 263 | } |
| 264 | |
| 265 | /** |
| 266 | * qla2x00_start_scsi() - Send a SCSI command to the ISP |
| 267 | * @sp: command to send to the ISP |
| 268 | * |
| 269 | * Returns non-zero if a failure occured, else zero. |
| 270 | */ |
| 271 | int |
| 272 | qla2x00_start_scsi(srb_t *sp) |
| 273 | { |
FUJITA Tomonori | 385d70b | 2007-05-26 01:55:38 +0900 | [diff] [blame^] | 274 | int ret, nseg; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 275 | unsigned long flags; |
| 276 | scsi_qla_host_t *ha; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 277 | struct scsi_cmnd *cmd; |
| 278 | uint32_t *clr_ptr; |
| 279 | uint32_t index; |
| 280 | uint32_t handle; |
| 281 | cmd_entry_t *cmd_pkt; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 282 | uint16_t cnt; |
| 283 | uint16_t req_cnt; |
| 284 | uint16_t tot_dsds; |
Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame] | 285 | struct device_reg_2xxx __iomem *reg; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 286 | |
| 287 | /* Setup device pointers. */ |
| 288 | ret = 0; |
| bdf7962 | 2005-04-17 15:06:53 -0500 | [diff] [blame] | 289 | ha = sp->ha; |
Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame] | 290 | reg = &ha->iobase->isp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 291 | cmd = sp->cmd; |
| 8302192 | 2005-04-17 15:10:41 -0500 | [diff] [blame] | 292 | /* So we know we haven't pci_map'ed anything yet */ |
| 293 | tot_dsds = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 294 | |
| 295 | /* Send marker if required */ |
| 296 | if (ha->marker_needed != 0) { |
| 297 | if (qla2x00_marker(ha, 0, 0, MK_SYNC_ALL) != QLA_SUCCESS) { |
| 298 | return (QLA_FUNCTION_FAILED); |
| 299 | } |
| 300 | ha->marker_needed = 0; |
| 301 | } |
| 302 | |
| 303 | /* Acquire ring specific lock */ |
| 304 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 305 | |
| 306 | /* Check for room in outstanding command list. */ |
| 307 | handle = ha->current_outstanding_cmd; |
| 308 | for (index = 1; index < MAX_OUTSTANDING_COMMANDS; index++) { |
| 309 | handle++; |
| 310 | if (handle == MAX_OUTSTANDING_COMMANDS) |
| 311 | handle = 1; |
| 312 | if (ha->outstanding_cmds[handle] == 0) |
| 313 | break; |
| 314 | } |
| 315 | if (index == MAX_OUTSTANDING_COMMANDS) |
| 316 | goto queuing_error; |
| 317 | |
| 8302192 | 2005-04-17 15:10:41 -0500 | [diff] [blame] | 318 | /* Map the sg table so we have an accurate count of sg entries needed */ |
FUJITA Tomonori | 385d70b | 2007-05-26 01:55:38 +0900 | [diff] [blame^] | 319 | nseg = scsi_dma_map(cmd); |
| 320 | if (nseg < 0) |
| 321 | goto queuing_error; |
| 322 | tot_dsds = nseg; |
| 8302192 | 2005-04-17 15:10:41 -0500 | [diff] [blame] | 323 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 324 | /* Calculate the number of request entries needed. */ |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 325 | req_cnt = ha->isp_ops.calc_req_entries(tot_dsds); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 326 | if (ha->req_q_cnt < (req_cnt + 2)) { |
| 327 | cnt = RD_REG_WORD_RELAXED(ISP_REQ_Q_OUT(ha, reg)); |
| 328 | if (ha->req_ring_index < cnt) |
| 329 | ha->req_q_cnt = cnt - ha->req_ring_index; |
| 330 | else |
| 331 | ha->req_q_cnt = ha->request_q_length - |
| 332 | (ha->req_ring_index - cnt); |
| 333 | } |
| 334 | if (ha->req_q_cnt < (req_cnt + 2)) |
| 335 | goto queuing_error; |
| 336 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 337 | /* Build command packet */ |
| 338 | ha->current_outstanding_cmd = handle; |
| 339 | ha->outstanding_cmds[handle] = sp; |
| 340 | sp->ha = ha; |
| 341 | sp->cmd->host_scribble = (unsigned char *)(unsigned long)handle; |
| 342 | ha->req_q_cnt -= req_cnt; |
| 343 | |
| 344 | cmd_pkt = (cmd_entry_t *)ha->request_ring_ptr; |
| 345 | cmd_pkt->handle = handle; |
| 346 | /* Zero out remaining portion of packet. */ |
| 347 | clr_ptr = (uint32_t *)cmd_pkt + 2; |
| 348 | memset(clr_ptr, 0, REQUEST_ENTRY_SIZE - 8); |
| 349 | cmd_pkt->dseg_count = cpu_to_le16(tot_dsds); |
| 350 | |
| bdf7962 | 2005-04-17 15:06:53 -0500 | [diff] [blame] | 351 | /* Set target ID and LUN number*/ |
| 352 | SET_TARGET_ID(ha, cmd_pkt->target, sp->fcport->loop_id); |
| 353 | cmd_pkt->lun = cpu_to_le16(sp->cmd->device->lun); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 354 | |
| 355 | /* Update tagged queuing modifier */ |
| 356 | cmd_pkt->control_flags = __constant_cpu_to_le16(CF_SIMPLE_TAG); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 357 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 358 | /* Load SCSI command packet. */ |
| 359 | memcpy(cmd_pkt->scsi_cdb, cmd->cmnd, cmd->cmd_len); |
FUJITA Tomonori | 385d70b | 2007-05-26 01:55:38 +0900 | [diff] [blame^] | 360 | cmd_pkt->byte_count = cpu_to_le32((uint32_t)scsi_bufflen(cmd)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 361 | |
| 362 | /* Build IOCB segments */ |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 363 | ha->isp_ops.build_iocbs(sp, cmd_pkt, tot_dsds); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 364 | |
| 365 | /* Set total data segment count. */ |
| 366 | cmd_pkt->entry_count = (uint8_t)req_cnt; |
| 367 | wmb(); |
| 368 | |
| 369 | /* Adjust ring index. */ |
| 370 | ha->req_ring_index++; |
| 371 | if (ha->req_ring_index == ha->request_q_length) { |
| 372 | ha->req_ring_index = 0; |
| 373 | ha->request_ring_ptr = ha->request_ring; |
| 374 | } else |
| 375 | ha->request_ring_ptr++; |
| 376 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 377 | sp->flags |= SRB_DMA_VALID; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 378 | |
| 379 | /* Set chip new ring index. */ |
| 380 | WRT_REG_WORD(ISP_REQ_Q_IN(ha, reg), ha->req_ring_index); |
| 381 | RD_REG_WORD_RELAXED(ISP_REQ_Q_IN(ha, reg)); /* PCI Posting. */ |
| 382 | |
Andrew Vasquez | 4fdfefe | 2005-10-27 11:09:48 -0700 | [diff] [blame] | 383 | /* Manage unprocessed RIO/ZIO commands in response queue. */ |
| 384 | if (ha->flags.process_response_queue && |
| 385 | ha->response_ring_ptr->signature != RESPONSE_PROCESSED) |
| 386 | qla2x00_process_response_queue(ha); |
| 387 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 388 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 389 | return (QLA_SUCCESS); |
| 390 | |
| 391 | queuing_error: |
FUJITA Tomonori | 385d70b | 2007-05-26 01:55:38 +0900 | [diff] [blame^] | 392 | if (tot_dsds) |
| 393 | scsi_dma_unmap(cmd); |
| 394 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 395 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 396 | |
| 397 | return (QLA_FUNCTION_FAILED); |
| 398 | } |
| 399 | |
| 400 | /** |
| 401 | * qla2x00_marker() - Send a marker IOCB to the firmware. |
| 402 | * @ha: HA context |
| 403 | * @loop_id: loop ID |
| 404 | * @lun: LUN |
| 405 | * @type: marker modifier |
| 406 | * |
| 407 | * Can be called from both normal and interrupt context. |
| 408 | * |
| 409 | * Returns non-zero if a failure occured, else zero. |
| 410 | */ |
Andrew Vasquez | fa2a1ce | 2005-07-06 10:32:07 -0700 | [diff] [blame] | 411 | int |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 412 | __qla2x00_marker(scsi_qla_host_t *ha, uint16_t loop_id, uint16_t lun, |
| 413 | uint8_t type) |
| 414 | { |
Andrew Vasquez | 2b6c0ce | 2005-07-06 10:31:17 -0700 | [diff] [blame] | 415 | mrk_entry_t *mrk; |
| 416 | struct mrk_entry_24xx *mrk24; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 417 | |
Andrew Vasquez | 2b6c0ce | 2005-07-06 10:31:17 -0700 | [diff] [blame] | 418 | mrk24 = NULL; |
| 419 | mrk = (mrk_entry_t *)qla2x00_req_pkt(ha); |
| 420 | if (mrk == NULL) { |
| 421 | DEBUG2_3(printk("%s(%ld): failed to allocate Marker IOCB.\n", |
| 422 | __func__, ha->host_no)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 423 | |
| 424 | return (QLA_FUNCTION_FAILED); |
| 425 | } |
| 426 | |
Andrew Vasquez | 2b6c0ce | 2005-07-06 10:31:17 -0700 | [diff] [blame] | 427 | mrk->entry_type = MARKER_TYPE; |
| 428 | mrk->modifier = type; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 429 | if (type != MK_SYNC_ALL) { |
andrew.vasquez@qlogic.com | 044cc6c | 2006-03-09 14:27:13 -0800 | [diff] [blame] | 430 | if (IS_QLA24XX(ha) || IS_QLA54XX(ha)) { |
Andrew Vasquez | 2b6c0ce | 2005-07-06 10:31:17 -0700 | [diff] [blame] | 431 | mrk24 = (struct mrk_entry_24xx *) mrk; |
| 432 | mrk24->nport_handle = cpu_to_le16(loop_id); |
| 433 | mrk24->lun[1] = LSB(lun); |
| 434 | mrk24->lun[2] = MSB(lun); |
Shyam Sundar | b797b6d | 2006-08-01 13:48:13 -0700 | [diff] [blame] | 435 | host_to_fcp_swap(mrk24->lun, sizeof(mrk24->lun)); |
Andrew Vasquez | 2b6c0ce | 2005-07-06 10:31:17 -0700 | [diff] [blame] | 436 | } else { |
| 437 | SET_TARGET_ID(ha, mrk->target, loop_id); |
| 438 | mrk->lun = cpu_to_le16(lun); |
| 439 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 440 | } |
| 441 | wmb(); |
| 442 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 443 | qla2x00_isp_cmd(ha); |
| 444 | |
| 445 | return (QLA_SUCCESS); |
| 446 | } |
| 447 | |
Andrew Vasquez | fa2a1ce | 2005-07-06 10:32:07 -0700 | [diff] [blame] | 448 | int |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 449 | qla2x00_marker(scsi_qla_host_t *ha, uint16_t loop_id, uint16_t lun, |
| 450 | uint8_t type) |
| 451 | { |
| 452 | int ret; |
| 453 | unsigned long flags = 0; |
| 454 | |
| 455 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 456 | ret = __qla2x00_marker(ha, loop_id, lun, type); |
| 457 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 458 | |
| 459 | return (ret); |
| 460 | } |
| 461 | |
| 462 | /** |
| 463 | * qla2x00_req_pkt() - Retrieve a request packet from the request ring. |
| 464 | * @ha: HA context |
| 465 | * |
| 466 | * Note: The caller must hold the hardware lock before calling this routine. |
| 467 | * |
| 468 | * Returns NULL if function failed, else, a pointer to the request packet. |
| 469 | */ |
| 470 | static request_t * |
| 471 | qla2x00_req_pkt(scsi_qla_host_t *ha) |
| 472 | { |
Andrew Vasquez | 2b6c0ce | 2005-07-06 10:31:17 -0700 | [diff] [blame] | 473 | device_reg_t __iomem *reg = ha->iobase; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 474 | request_t *pkt = NULL; |
| 475 | uint16_t cnt; |
| 476 | uint32_t *dword_ptr; |
| 477 | uint32_t timer; |
| 478 | uint16_t req_cnt = 1; |
| 479 | |
| 480 | /* Wait 1 second for slot. */ |
| 481 | for (timer = HZ; timer; timer--) { |
| 482 | if ((req_cnt + 2) >= ha->req_q_cnt) { |
| 483 | /* Calculate number of free request entries. */ |
andrew.vasquez@qlogic.com | 044cc6c | 2006-03-09 14:27:13 -0800 | [diff] [blame] | 484 | if (IS_QLA24XX(ha) || IS_QLA54XX(ha)) |
Andrew Vasquez | 2b6c0ce | 2005-07-06 10:31:17 -0700 | [diff] [blame] | 485 | cnt = (uint16_t)RD_REG_DWORD( |
| 486 | ®->isp24.req_q_out); |
| 487 | else |
| 488 | cnt = qla2x00_debounce_register( |
| 489 | ISP_REQ_Q_OUT(ha, ®->isp)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 490 | if (ha->req_ring_index < cnt) |
| 491 | ha->req_q_cnt = cnt - ha->req_ring_index; |
| 492 | else |
| 493 | ha->req_q_cnt = ha->request_q_length - |
| 494 | (ha->req_ring_index - cnt); |
| 495 | } |
| 496 | /* If room for request in request ring. */ |
| 497 | if ((req_cnt + 2) < ha->req_q_cnt) { |
| 498 | ha->req_q_cnt--; |
| 499 | pkt = ha->request_ring_ptr; |
| 500 | |
| 501 | /* Zero out packet. */ |
| 502 | dword_ptr = (uint32_t *)pkt; |
| 503 | for (cnt = 0; cnt < REQUEST_ENTRY_SIZE / 4; cnt++) |
| 504 | *dword_ptr++ = 0; |
| 505 | |
| 506 | /* Set system defined field. */ |
| 507 | pkt->sys_define = (uint8_t)ha->req_ring_index; |
| 508 | |
| 509 | /* Set entry count. */ |
| 510 | pkt->entry_count = 1; |
| 511 | |
| 512 | break; |
| 513 | } |
| 514 | |
| 515 | /* Release ring specific lock */ |
| 516 | spin_unlock(&ha->hardware_lock); |
| 517 | |
| 518 | udelay(2); /* 2 us */ |
| 519 | |
| 520 | /* Check for pending interrupts. */ |
| 521 | /* During init we issue marker directly */ |
| 522 | if (!ha->marker_needed) |
| 523 | qla2x00_poll(ha); |
| 524 | |
| 525 | spin_lock_irq(&ha->hardware_lock); |
| 526 | } |
| 527 | if (!pkt) { |
| 528 | DEBUG2_3(printk("%s(): **** FAILED ****\n", __func__)); |
| 529 | } |
| 530 | |
| 531 | return (pkt); |
| 532 | } |
| 533 | |
| 534 | /** |
| 535 | * qla2x00_isp_cmd() - Modify the request ring pointer. |
| 536 | * @ha: HA context |
| 537 | * |
| 538 | * Note: The caller must hold the hardware lock before calling this routine. |
| 539 | */ |
Adrian Bunk | 413975a | 2006-06-30 02:33:06 -0700 | [diff] [blame] | 540 | static void |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 541 | qla2x00_isp_cmd(scsi_qla_host_t *ha) |
| 542 | { |
Andrew Vasquez | 2b6c0ce | 2005-07-06 10:31:17 -0700 | [diff] [blame] | 543 | device_reg_t __iomem *reg = ha->iobase; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 544 | |
| 545 | DEBUG5(printk("%s(): IOCB data:\n", __func__)); |
| 546 | DEBUG5(qla2x00_dump_buffer( |
| 547 | (uint8_t *)ha->request_ring_ptr, REQUEST_ENTRY_SIZE)); |
| 548 | |
| 549 | /* Adjust ring index. */ |
| 550 | ha->req_ring_index++; |
| 551 | if (ha->req_ring_index == ha->request_q_length) { |
| 552 | ha->req_ring_index = 0; |
| 553 | ha->request_ring_ptr = ha->request_ring; |
| 554 | } else |
| 555 | ha->request_ring_ptr++; |
| 556 | |
| 557 | /* Set chip new ring index. */ |
andrew.vasquez@qlogic.com | 044cc6c | 2006-03-09 14:27:13 -0800 | [diff] [blame] | 558 | if (IS_QLA24XX(ha) || IS_QLA54XX(ha)) { |
Andrew Vasquez | 2b6c0ce | 2005-07-06 10:31:17 -0700 | [diff] [blame] | 559 | WRT_REG_DWORD(®->isp24.req_q_in, ha->req_ring_index); |
| 560 | RD_REG_DWORD_RELAXED(®->isp24.req_q_in); |
| 561 | } else { |
| 562 | WRT_REG_WORD(ISP_REQ_Q_IN(ha, ®->isp), ha->req_ring_index); |
| 563 | RD_REG_WORD_RELAXED(ISP_REQ_Q_IN(ha, ®->isp)); |
| 564 | } |
| 565 | |
| 566 | } |
| 567 | |
| 568 | /** |
| 569 | * qla24xx_calc_iocbs() - Determine number of Command Type 3 and |
| 570 | * Continuation Type 1 IOCBs to allocate. |
| 571 | * |
| 572 | * @dsds: number of data segment decriptors needed |
| 573 | * |
| 574 | * Returns the number of IOCB entries needed to store @dsds. |
| 575 | */ |
| 576 | static inline uint16_t |
| 577 | qla24xx_calc_iocbs(uint16_t dsds) |
| 578 | { |
| 579 | uint16_t iocbs; |
| 580 | |
| 581 | iocbs = 1; |
| 582 | if (dsds > 1) { |
| 583 | iocbs += (dsds - 1) / 5; |
| 584 | if ((dsds - 1) % 5) |
| 585 | iocbs++; |
| 586 | } |
| 587 | return iocbs; |
| 588 | } |
| 589 | |
| 590 | /** |
| 591 | * qla24xx_build_scsi_iocbs() - Build IOCB command utilizing Command Type 7 |
| 592 | * IOCB types. |
| 593 | * |
| 594 | * @sp: SRB command to process |
| 595 | * @cmd_pkt: Command type 3 IOCB |
| 596 | * @tot_dsds: Total number of segments to transfer |
| 597 | */ |
| 598 | static inline void |
| 599 | qla24xx_build_scsi_iocbs(srb_t *sp, struct cmd_type_7 *cmd_pkt, |
| 600 | uint16_t tot_dsds) |
| 601 | { |
| 602 | uint16_t avail_dsds; |
| 603 | uint32_t *cur_dsd; |
| 604 | scsi_qla_host_t *ha; |
| 605 | struct scsi_cmnd *cmd; |
FUJITA Tomonori | 385d70b | 2007-05-26 01:55:38 +0900 | [diff] [blame^] | 606 | struct scatterlist *sg; |
| 607 | int i; |
Andrew Vasquez | 2b6c0ce | 2005-07-06 10:31:17 -0700 | [diff] [blame] | 608 | |
| 609 | cmd = sp->cmd; |
| 610 | |
| 611 | /* Update entry type to indicate Command Type 3 IOCB */ |
| 612 | *((uint32_t *)(&cmd_pkt->entry_type)) = |
| 613 | __constant_cpu_to_le32(COMMAND_TYPE_7); |
| 614 | |
| 615 | /* No data transfer */ |
FUJITA Tomonori | 385d70b | 2007-05-26 01:55:38 +0900 | [diff] [blame^] | 616 | if (!scsi_bufflen(cmd) || cmd->sc_data_direction == DMA_NONE) { |
Andrew Vasquez | 2b6c0ce | 2005-07-06 10:31:17 -0700 | [diff] [blame] | 617 | cmd_pkt->byte_count = __constant_cpu_to_le32(0); |
| 618 | return; |
| 619 | } |
| 620 | |
| 621 | ha = sp->ha; |
| 622 | |
| 623 | /* Set transfer direction */ |
| 624 | if (cmd->sc_data_direction == DMA_TO_DEVICE) |
| 625 | cmd_pkt->task_mgmt_flags = |
| 626 | __constant_cpu_to_le16(TMF_WRITE_DATA); |
| 627 | else if (cmd->sc_data_direction == DMA_FROM_DEVICE) |
| 628 | cmd_pkt->task_mgmt_flags = |
| 629 | __constant_cpu_to_le16(TMF_READ_DATA); |
| 630 | |
| 631 | /* One DSD is available in the Command Type 3 IOCB */ |
| 632 | avail_dsds = 1; |
| 633 | cur_dsd = (uint32_t *)&cmd_pkt->dseg_0_address; |
| 634 | |
| 635 | /* Load data segments */ |
Andrew Vasquez | 2b6c0ce | 2005-07-06 10:31:17 -0700 | [diff] [blame] | 636 | |
FUJITA Tomonori | 385d70b | 2007-05-26 01:55:38 +0900 | [diff] [blame^] | 637 | scsi_for_each_sg(cmd, sg, tot_dsds, i) { |
| 638 | dma_addr_t sle_dma; |
| 639 | cont_a64_entry_t *cont_pkt; |
Andrew Vasquez | 2b6c0ce | 2005-07-06 10:31:17 -0700 | [diff] [blame] | 640 | |
FUJITA Tomonori | 385d70b | 2007-05-26 01:55:38 +0900 | [diff] [blame^] | 641 | /* Allocate additional continuation packets? */ |
| 642 | if (avail_dsds == 0) { |
| 643 | /* |
| 644 | * Five DSDs are available in the Continuation |
| 645 | * Type 1 IOCB. |
| 646 | */ |
| 647 | cont_pkt = qla2x00_prep_cont_type1_iocb(ha); |
| 648 | cur_dsd = (uint32_t *)cont_pkt->dseg_0_address; |
| 649 | avail_dsds = 5; |
Andrew Vasquez | 2b6c0ce | 2005-07-06 10:31:17 -0700 | [diff] [blame] | 650 | } |
FUJITA Tomonori | 385d70b | 2007-05-26 01:55:38 +0900 | [diff] [blame^] | 651 | |
| 652 | sle_dma = sg_dma_address(sg); |
| 653 | *cur_dsd++ = cpu_to_le32(LSD(sle_dma)); |
| 654 | *cur_dsd++ = cpu_to_le32(MSD(sle_dma)); |
| 655 | *cur_dsd++ = cpu_to_le32(sg_dma_len(sg)); |
| 656 | avail_dsds--; |
Andrew Vasquez | 2b6c0ce | 2005-07-06 10:31:17 -0700 | [diff] [blame] | 657 | } |
| 658 | } |
| 659 | |
| 660 | |
| 661 | /** |
| 662 | * qla24xx_start_scsi() - Send a SCSI command to the ISP |
| 663 | * @sp: command to send to the ISP |
| 664 | * |
| 665 | * Returns non-zero if a failure occured, else zero. |
| 666 | */ |
| 667 | int |
| 668 | qla24xx_start_scsi(srb_t *sp) |
| 669 | { |
FUJITA Tomonori | 385d70b | 2007-05-26 01:55:38 +0900 | [diff] [blame^] | 670 | int ret, nseg; |
Andrew Vasquez | 2b6c0ce | 2005-07-06 10:31:17 -0700 | [diff] [blame] | 671 | unsigned long flags; |
| 672 | scsi_qla_host_t *ha; |
| 673 | struct scsi_cmnd *cmd; |
| 674 | uint32_t *clr_ptr; |
| 675 | uint32_t index; |
| 676 | uint32_t handle; |
| 677 | struct cmd_type_7 *cmd_pkt; |
Andrew Vasquez | 2b6c0ce | 2005-07-06 10:31:17 -0700 | [diff] [blame] | 678 | uint16_t cnt; |
| 679 | uint16_t req_cnt; |
| 680 | uint16_t tot_dsds; |
Linus Torvalds | db776a1 | 2005-07-26 14:50:02 -0700 | [diff] [blame] | 681 | struct device_reg_24xx __iomem *reg; |
Andrew Vasquez | 2b6c0ce | 2005-07-06 10:31:17 -0700 | [diff] [blame] | 682 | |
| 683 | /* Setup device pointers. */ |
| 684 | ret = 0; |
| 685 | ha = sp->ha; |
| 686 | reg = &ha->iobase->isp24; |
| 687 | cmd = sp->cmd; |
| 688 | /* So we know we haven't pci_map'ed anything yet */ |
| 689 | tot_dsds = 0; |
| 690 | |
| 691 | /* Send marker if required */ |
| 692 | if (ha->marker_needed != 0) { |
| 693 | if (qla2x00_marker(ha, 0, 0, MK_SYNC_ALL) != QLA_SUCCESS) { |
| 694 | return QLA_FUNCTION_FAILED; |
| 695 | } |
| 696 | ha->marker_needed = 0; |
| 697 | } |
| 698 | |
| 699 | /* Acquire ring specific lock */ |
| 700 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 701 | |
| 702 | /* Check for room in outstanding command list. */ |
| 703 | handle = ha->current_outstanding_cmd; |
| 704 | for (index = 1; index < MAX_OUTSTANDING_COMMANDS; index++) { |
| 705 | handle++; |
| 706 | if (handle == MAX_OUTSTANDING_COMMANDS) |
| 707 | handle = 1; |
| 708 | if (ha->outstanding_cmds[handle] == 0) |
| 709 | break; |
| 710 | } |
| 711 | if (index == MAX_OUTSTANDING_COMMANDS) |
| 712 | goto queuing_error; |
| 713 | |
| 714 | /* Map the sg table so we have an accurate count of sg entries needed */ |
FUJITA Tomonori | 385d70b | 2007-05-26 01:55:38 +0900 | [diff] [blame^] | 715 | nseg = scsi_dma_map(cmd); |
| 716 | if (nseg < 0) |
Andrew Vasquez | 2b6c0ce | 2005-07-06 10:31:17 -0700 | [diff] [blame] | 717 | goto queuing_error; |
FUJITA Tomonori | 385d70b | 2007-05-26 01:55:38 +0900 | [diff] [blame^] | 718 | tot_dsds = nseg; |
Andrew Vasquez | 2b6c0ce | 2005-07-06 10:31:17 -0700 | [diff] [blame] | 719 | |
| 720 | req_cnt = qla24xx_calc_iocbs(tot_dsds); |
| 721 | if (ha->req_q_cnt < (req_cnt + 2)) { |
| 722 | cnt = (uint16_t)RD_REG_DWORD_RELAXED(®->req_q_out); |
| 723 | if (ha->req_ring_index < cnt) |
| 724 | ha->req_q_cnt = cnt - ha->req_ring_index; |
| 725 | else |
| 726 | ha->req_q_cnt = ha->request_q_length - |
| 727 | (ha->req_ring_index - cnt); |
| 728 | } |
Andrew Vasquez | 131736d | 2005-08-26 19:09:20 -0700 | [diff] [blame] | 729 | if (ha->req_q_cnt < (req_cnt + 2)) |
Andrew Vasquez | 2b6c0ce | 2005-07-06 10:31:17 -0700 | [diff] [blame] | 730 | goto queuing_error; |
Andrew Vasquez | 2b6c0ce | 2005-07-06 10:31:17 -0700 | [diff] [blame] | 731 | |
| 732 | /* Build command packet. */ |
| 733 | ha->current_outstanding_cmd = handle; |
| 734 | ha->outstanding_cmds[handle] = sp; |
| 735 | sp->ha = ha; |
| 736 | sp->cmd->host_scribble = (unsigned char *)(unsigned long)handle; |
| 737 | ha->req_q_cnt -= req_cnt; |
| 738 | |
| 739 | cmd_pkt = (struct cmd_type_7 *)ha->request_ring_ptr; |
| 740 | cmd_pkt->handle = handle; |
| 741 | |
| 742 | /* Zero out remaining portion of packet. */ |
James Bottomley | 72df832 | 2005-10-28 14:41:19 -0500 | [diff] [blame] | 743 | /* tagged queuing modifier -- default is TSK_SIMPLE (0). */ |
Andrew Vasquez | 2b6c0ce | 2005-07-06 10:31:17 -0700 | [diff] [blame] | 744 | clr_ptr = (uint32_t *)cmd_pkt + 2; |
| 745 | memset(clr_ptr, 0, REQUEST_ENTRY_SIZE - 8); |
| 746 | cmd_pkt->dseg_count = cpu_to_le16(tot_dsds); |
| 747 | |
| 748 | /* Set NPORT-ID and LUN number*/ |
| 749 | cmd_pkt->nport_handle = cpu_to_le16(sp->fcport->loop_id); |
| 750 | cmd_pkt->port_id[0] = sp->fcport->d_id.b.al_pa; |
| 751 | cmd_pkt->port_id[1] = sp->fcport->d_id.b.area; |
| 752 | cmd_pkt->port_id[2] = sp->fcport->d_id.b.domain; |
| 753 | |
Andrew Vasquez | 661c3f6 | 2005-10-27 11:09:58 -0700 | [diff] [blame] | 754 | int_to_scsilun(sp->cmd->device->lun, &cmd_pkt->lun); |
andrew.vasquez@qlogic.com | 0d4be12 | 2006-02-07 08:45:35 -0800 | [diff] [blame] | 755 | 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] | 756 | |
Andrew Vasquez | 2b6c0ce | 2005-07-06 10:31:17 -0700 | [diff] [blame] | 757 | /* Load SCSI command packet. */ |
| 758 | memcpy(cmd_pkt->fcp_cdb, cmd->cmnd, cmd->cmd_len); |
| 759 | host_to_fcp_swap(cmd_pkt->fcp_cdb, sizeof(cmd_pkt->fcp_cdb)); |
| 760 | |
FUJITA Tomonori | 385d70b | 2007-05-26 01:55:38 +0900 | [diff] [blame^] | 761 | cmd_pkt->byte_count = cpu_to_le32((uint32_t)scsi_bufflen(cmd)); |
Andrew Vasquez | 2b6c0ce | 2005-07-06 10:31:17 -0700 | [diff] [blame] | 762 | |
| 763 | /* Build IOCB segments */ |
| 764 | qla24xx_build_scsi_iocbs(sp, cmd_pkt, tot_dsds); |
| 765 | |
| 766 | /* Set total data segment count. */ |
| 767 | cmd_pkt->entry_count = (uint8_t)req_cnt; |
| 768 | wmb(); |
| 769 | |
| 770 | /* Adjust ring index. */ |
| 771 | ha->req_ring_index++; |
| 772 | if (ha->req_ring_index == ha->request_q_length) { |
| 773 | ha->req_ring_index = 0; |
| 774 | ha->request_ring_ptr = ha->request_ring; |
| 775 | } else |
| 776 | ha->request_ring_ptr++; |
| 777 | |
| 778 | sp->flags |= SRB_DMA_VALID; |
Andrew Vasquez | 2b6c0ce | 2005-07-06 10:31:17 -0700 | [diff] [blame] | 779 | |
| 780 | /* Set chip new ring index. */ |
| 781 | WRT_REG_DWORD(®->req_q_in, ha->req_ring_index); |
| 782 | RD_REG_DWORD_RELAXED(®->req_q_in); /* PCI Posting. */ |
| 783 | |
Andrew Vasquez | 4fdfefe | 2005-10-27 11:09:48 -0700 | [diff] [blame] | 784 | /* Manage unprocessed RIO/ZIO commands in response queue. */ |
| 785 | if (ha->flags.process_response_queue && |
| 786 | ha->response_ring_ptr->signature != RESPONSE_PROCESSED) |
| 787 | qla24xx_process_response_queue(ha); |
| 788 | |
Andrew Vasquez | 2b6c0ce | 2005-07-06 10:31:17 -0700 | [diff] [blame] | 789 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 790 | return QLA_SUCCESS; |
| 791 | |
| 792 | queuing_error: |
FUJITA Tomonori | 385d70b | 2007-05-26 01:55:38 +0900 | [diff] [blame^] | 793 | if (tot_dsds) |
| 794 | scsi_dma_unmap(cmd); |
| 795 | |
Andrew Vasquez | 2b6c0ce | 2005-07-06 10:31:17 -0700 | [diff] [blame] | 796 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 797 | |
| 798 | return QLA_FUNCTION_FAILED; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 799 | } |