aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/scsi/qla2xxx/qla_iocb.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/scsi/qla2xxx/qla_iocb.c')
-rw-r--r--drivers/scsi/qla2xxx/qla_iocb.c242
1 files changed, 93 insertions, 149 deletions
diff --git a/drivers/scsi/qla2xxx/qla_iocb.c b/drivers/scsi/qla2xxx/qla_iocb.c
index c5b3c610a32a..c71863ff5489 100644
--- a/drivers/scsi/qla2xxx/qla_iocb.c
+++ b/drivers/scsi/qla2xxx/qla_iocb.c
@@ -155,6 +155,8 @@ void qla2x00_build_scsi_iocbs_32(srb_t *sp, cmd_entry_t *cmd_pkt,
155 uint32_t *cur_dsd; 155 uint32_t *cur_dsd;
156 scsi_qla_host_t *ha; 156 scsi_qla_host_t *ha;
157 struct scsi_cmnd *cmd; 157 struct scsi_cmnd *cmd;
158 struct scatterlist *sg;
159 int i;
158 160
159 cmd = sp->cmd; 161 cmd = sp->cmd;
160 162
@@ -163,7 +165,7 @@ void qla2x00_build_scsi_iocbs_32(srb_t *sp, cmd_entry_t *cmd_pkt,
163 __constant_cpu_to_le32(COMMAND_TYPE); 165 __constant_cpu_to_le32(COMMAND_TYPE);
164 166
165 /* No data transfer */ 167 /* No data transfer */
166 if (cmd->request_bufflen == 0 || cmd->sc_data_direction == DMA_NONE) { 168 if (!scsi_bufflen(cmd) || cmd->sc_data_direction == DMA_NONE) {
167 cmd_pkt->byte_count = __constant_cpu_to_le32(0); 169 cmd_pkt->byte_count = __constant_cpu_to_le32(0);
168 return; 170 return;
169 } 171 }
@@ -177,35 +179,23 @@ void qla2x00_build_scsi_iocbs_32(srb_t *sp, cmd_entry_t *cmd_pkt,
177 cur_dsd = (uint32_t *)&cmd_pkt->dseg_0_address; 179 cur_dsd = (uint32_t *)&cmd_pkt->dseg_0_address;
178 180
179 /* Load data segments */ 181 /* Load data segments */
180 if (cmd->use_sg != 0) { 182 scsi_for_each_sg(cmd, sg, tot_dsds, i) {
181 struct scatterlist *cur_seg; 183 cont_entry_t *cont_pkt;
182 struct scatterlist *end_seg; 184
183 185 /* Allocate additional continuation packets? */
184 cur_seg = (struct scatterlist *)cmd->request_buffer; 186 if (avail_dsds == 0) {
185 end_seg = cur_seg + tot_dsds; 187 /*
186 while (cur_seg < end_seg) { 188 * Seven DSDs are available in the Continuation
187 cont_entry_t *cont_pkt; 189 * Type 0 IOCB.
188 190 */
189 /* Allocate additional continuation packets? */ 191 cont_pkt = qla2x00_prep_cont_type0_iocb(ha);
190 if (avail_dsds == 0) { 192 cur_dsd = (uint32_t *)&cont_pkt->dseg_0_address;
191 /* 193 avail_dsds = 7;
192 * Seven DSDs are available in the Continuation
193 * Type 0 IOCB.
194 */
195 cont_pkt = qla2x00_prep_cont_type0_iocb(ha);
196 cur_dsd = (uint32_t *)&cont_pkt->dseg_0_address;
197 avail_dsds = 7;
198 }
199
200 *cur_dsd++ = cpu_to_le32(sg_dma_address(cur_seg));
201 *cur_dsd++ = cpu_to_le32(sg_dma_len(cur_seg));
202 avail_dsds--;
203
204 cur_seg++;
205 } 194 }
206 } else { 195
207 *cur_dsd++ = cpu_to_le32(sp->dma_handle); 196 *cur_dsd++ = cpu_to_le32(sg_dma_address(sg));
208 *cur_dsd++ = cpu_to_le32(cmd->request_bufflen); 197 *cur_dsd++ = cpu_to_le32(sg_dma_len(sg));
198 avail_dsds--;
209 } 199 }
210} 200}
211 201
@@ -224,6 +214,8 @@ void qla2x00_build_scsi_iocbs_64(srb_t *sp, cmd_entry_t *cmd_pkt,
224 uint32_t *cur_dsd; 214 uint32_t *cur_dsd;
225 scsi_qla_host_t *ha; 215 scsi_qla_host_t *ha;
226 struct scsi_cmnd *cmd; 216 struct scsi_cmnd *cmd;
217 struct scatterlist *sg;
218 int i;
227 219
228 cmd = sp->cmd; 220 cmd = sp->cmd;
229 221
@@ -232,7 +224,7 @@ void qla2x00_build_scsi_iocbs_64(srb_t *sp, cmd_entry_t *cmd_pkt,
232 __constant_cpu_to_le32(COMMAND_A64_TYPE); 224 __constant_cpu_to_le32(COMMAND_A64_TYPE);
233 225
234 /* No data transfer */ 226 /* No data transfer */
235 if (cmd->request_bufflen == 0 || cmd->sc_data_direction == DMA_NONE) { 227 if (!scsi_bufflen(cmd) || cmd->sc_data_direction == DMA_NONE) {
236 cmd_pkt->byte_count = __constant_cpu_to_le32(0); 228 cmd_pkt->byte_count = __constant_cpu_to_le32(0);
237 return; 229 return;
238 } 230 }
@@ -246,39 +238,26 @@ void qla2x00_build_scsi_iocbs_64(srb_t *sp, cmd_entry_t *cmd_pkt,
246 cur_dsd = (uint32_t *)&cmd_pkt->dseg_0_address; 238 cur_dsd = (uint32_t *)&cmd_pkt->dseg_0_address;
247 239
248 /* Load data segments */ 240 /* Load data segments */
249 if (cmd->use_sg != 0) { 241 scsi_for_each_sg(cmd, sg, tot_dsds, i) {
250 struct scatterlist *cur_seg; 242 dma_addr_t sle_dma;
251 struct scatterlist *end_seg; 243 cont_a64_entry_t *cont_pkt;
252 244
253 cur_seg = (struct scatterlist *)cmd->request_buffer; 245 /* Allocate additional continuation packets? */
254 end_seg = cur_seg + tot_dsds; 246 if (avail_dsds == 0) {
255 while (cur_seg < end_seg) { 247 /*
256 dma_addr_t sle_dma; 248 * Five DSDs are available in the Continuation
257 cont_a64_entry_t *cont_pkt; 249 * Type 1 IOCB.
258 250 */
259 /* Allocate additional continuation packets? */ 251 cont_pkt = qla2x00_prep_cont_type1_iocb(ha);
260 if (avail_dsds == 0) { 252 cur_dsd = (uint32_t *)cont_pkt->dseg_0_address;
261 /* 253 avail_dsds = 5;
262 * Five DSDs are available in the Continuation
263 * Type 1 IOCB.
264 */
265 cont_pkt = qla2x00_prep_cont_type1_iocb(ha);
266 cur_dsd = (uint32_t *)cont_pkt->dseg_0_address;
267 avail_dsds = 5;
268 }
269
270 sle_dma = sg_dma_address(cur_seg);
271 *cur_dsd++ = cpu_to_le32(LSD(sle_dma));
272 *cur_dsd++ = cpu_to_le32(MSD(sle_dma));
273 *cur_dsd++ = cpu_to_le32(sg_dma_len(cur_seg));
274 avail_dsds--;
275
276 cur_seg++;
277 } 254 }
278 } else { 255
279 *cur_dsd++ = cpu_to_le32(LSD(sp->dma_handle)); 256 sle_dma = sg_dma_address(sg);
280 *cur_dsd++ = cpu_to_le32(MSD(sp->dma_handle)); 257 *cur_dsd++ = cpu_to_le32(LSD(sle_dma));
281 *cur_dsd++ = cpu_to_le32(cmd->request_bufflen); 258 *cur_dsd++ = cpu_to_le32(MSD(sle_dma));
259 *cur_dsd++ = cpu_to_le32(sg_dma_len(sg));
260 avail_dsds--;
282 } 261 }
283} 262}
284 263
@@ -291,7 +270,7 @@ void qla2x00_build_scsi_iocbs_64(srb_t *sp, cmd_entry_t *cmd_pkt,
291int 270int
292qla2x00_start_scsi(srb_t *sp) 271qla2x00_start_scsi(srb_t *sp)
293{ 272{
294 int ret; 273 int ret, nseg;
295 unsigned long flags; 274 unsigned long flags;
296 scsi_qla_host_t *ha; 275 scsi_qla_host_t *ha;
297 struct scsi_cmnd *cmd; 276 struct scsi_cmnd *cmd;
@@ -299,7 +278,6 @@ qla2x00_start_scsi(srb_t *sp)
299 uint32_t index; 278 uint32_t index;
300 uint32_t handle; 279 uint32_t handle;
301 cmd_entry_t *cmd_pkt; 280 cmd_entry_t *cmd_pkt;
302 struct scatterlist *sg;
303 uint16_t cnt; 281 uint16_t cnt;
304 uint16_t req_cnt; 282 uint16_t req_cnt;
305 uint16_t tot_dsds; 283 uint16_t tot_dsds;
@@ -337,23 +315,15 @@ qla2x00_start_scsi(srb_t *sp)
337 goto queuing_error; 315 goto queuing_error;
338 316
339 /* Map the sg table so we have an accurate count of sg entries needed */ 317 /* Map the sg table so we have an accurate count of sg entries needed */
340 if (cmd->use_sg) { 318 if (scsi_sg_count(cmd)) {
341 sg = (struct scatterlist *) cmd->request_buffer; 319 nseg = dma_map_sg(&ha->pdev->dev, scsi_sglist(cmd),
342 tot_dsds = pci_map_sg(ha->pdev, sg, cmd->use_sg, 320 scsi_sg_count(cmd), cmd->sc_data_direction);
343 cmd->sc_data_direction); 321 if (unlikely(!nseg))
344 if (tot_dsds == 0)
345 goto queuing_error;
346 } else if (cmd->request_bufflen) {
347 dma_addr_t req_dma;
348
349 req_dma = pci_map_single(ha->pdev, cmd->request_buffer,
350 cmd->request_bufflen, cmd->sc_data_direction);
351 if (dma_mapping_error(req_dma))
352 goto queuing_error; 322 goto queuing_error;
323 } else
324 nseg = 0;
353 325
354 sp->dma_handle = req_dma; 326 tot_dsds = nseg;
355 tot_dsds = 1;
356 }
357 327
358 /* Calculate the number of request entries needed. */ 328 /* Calculate the number of request entries needed. */
359 req_cnt = ha->isp_ops.calc_req_entries(tot_dsds); 329 req_cnt = ha->isp_ops.calc_req_entries(tot_dsds);
@@ -391,7 +361,7 @@ qla2x00_start_scsi(srb_t *sp)
391 361
392 /* Load SCSI command packet. */ 362 /* Load SCSI command packet. */
393 memcpy(cmd_pkt->scsi_cdb, cmd->cmnd, cmd->cmd_len); 363 memcpy(cmd_pkt->scsi_cdb, cmd->cmnd, cmd->cmd_len);
394 cmd_pkt->byte_count = cpu_to_le32((uint32_t)cmd->request_bufflen); 364 cmd_pkt->byte_count = cpu_to_le32((uint32_t)scsi_bufflen(cmd));
395 365
396 /* Build IOCB segments */ 366 /* Build IOCB segments */
397 ha->isp_ops.build_iocbs(sp, cmd_pkt, tot_dsds); 367 ha->isp_ops.build_iocbs(sp, cmd_pkt, tot_dsds);
@@ -423,14 +393,9 @@ qla2x00_start_scsi(srb_t *sp)
423 return (QLA_SUCCESS); 393 return (QLA_SUCCESS);
424 394
425queuing_error: 395queuing_error:
426 if (cmd->use_sg && tot_dsds) { 396 if (tot_dsds)
427 sg = (struct scatterlist *) cmd->request_buffer; 397 scsi_dma_unmap(cmd);
428 pci_unmap_sg(ha->pdev, sg, cmd->use_sg, 398
429 cmd->sc_data_direction);
430 } else if (tot_dsds) {
431 pci_unmap_single(ha->pdev, sp->dma_handle,
432 cmd->request_bufflen, cmd->sc_data_direction);
433 }
434 spin_unlock_irqrestore(&ha->hardware_lock, flags); 399 spin_unlock_irqrestore(&ha->hardware_lock, flags);
435 400
436 return (QLA_FUNCTION_FAILED); 401 return (QLA_FUNCTION_FAILED);
@@ -453,9 +418,10 @@ __qla2x00_marker(scsi_qla_host_t *ha, uint16_t loop_id, uint16_t lun,
453{ 418{
454 mrk_entry_t *mrk; 419 mrk_entry_t *mrk;
455 struct mrk_entry_24xx *mrk24; 420 struct mrk_entry_24xx *mrk24;
421 scsi_qla_host_t *pha = to_qla_parent(ha);
456 422
457 mrk24 = NULL; 423 mrk24 = NULL;
458 mrk = (mrk_entry_t *)qla2x00_req_pkt(ha); 424 mrk = (mrk_entry_t *)qla2x00_req_pkt(pha);
459 if (mrk == NULL) { 425 if (mrk == NULL) {
460 DEBUG2_3(printk("%s(%ld): failed to allocate Marker IOCB.\n", 426 DEBUG2_3(printk("%s(%ld): failed to allocate Marker IOCB.\n",
461 __func__, ha->host_no)); 427 __func__, ha->host_no));
@@ -472,6 +438,7 @@ __qla2x00_marker(scsi_qla_host_t *ha, uint16_t loop_id, uint16_t lun,
472 mrk24->lun[1] = LSB(lun); 438 mrk24->lun[1] = LSB(lun);
473 mrk24->lun[2] = MSB(lun); 439 mrk24->lun[2] = MSB(lun);
474 host_to_fcp_swap(mrk24->lun, sizeof(mrk24->lun)); 440 host_to_fcp_swap(mrk24->lun, sizeof(mrk24->lun));
441 mrk24->vp_index = ha->vp_idx;
475 } else { 442 } else {
476 SET_TARGET_ID(ha, mrk->target, loop_id); 443 SET_TARGET_ID(ha, mrk->target, loop_id);
477 mrk->lun = cpu_to_le16(lun); 444 mrk->lun = cpu_to_le16(lun);
@@ -479,7 +446,7 @@ __qla2x00_marker(scsi_qla_host_t *ha, uint16_t loop_id, uint16_t lun,
479 } 446 }
480 wmb(); 447 wmb();
481 448
482 qla2x00_isp_cmd(ha); 449 qla2x00_isp_cmd(pha);
483 450
484 return (QLA_SUCCESS); 451 return (QLA_SUCCESS);
485} 452}
@@ -642,6 +609,8 @@ qla24xx_build_scsi_iocbs(srb_t *sp, struct cmd_type_7 *cmd_pkt,
642 uint32_t *cur_dsd; 609 uint32_t *cur_dsd;
643 scsi_qla_host_t *ha; 610 scsi_qla_host_t *ha;
644 struct scsi_cmnd *cmd; 611 struct scsi_cmnd *cmd;
612 struct scatterlist *sg;
613 int i;
645 614
646 cmd = sp->cmd; 615 cmd = sp->cmd;
647 616
@@ -650,7 +619,7 @@ qla24xx_build_scsi_iocbs(srb_t *sp, struct cmd_type_7 *cmd_pkt,
650 __constant_cpu_to_le32(COMMAND_TYPE_7); 619 __constant_cpu_to_le32(COMMAND_TYPE_7);
651 620
652 /* No data transfer */ 621 /* No data transfer */
653 if (cmd->request_bufflen == 0 || cmd->sc_data_direction == DMA_NONE) { 622 if (!scsi_bufflen(cmd) || cmd->sc_data_direction == DMA_NONE) {
654 cmd_pkt->byte_count = __constant_cpu_to_le32(0); 623 cmd_pkt->byte_count = __constant_cpu_to_le32(0);
655 return; 624 return;
656 } 625 }
@@ -670,39 +639,27 @@ qla24xx_build_scsi_iocbs(srb_t *sp, struct cmd_type_7 *cmd_pkt,
670 cur_dsd = (uint32_t *)&cmd_pkt->dseg_0_address; 639 cur_dsd = (uint32_t *)&cmd_pkt->dseg_0_address;
671 640
672 /* Load data segments */ 641 /* Load data segments */
673 if (cmd->use_sg != 0) { 642
674 struct scatterlist *cur_seg; 643 scsi_for_each_sg(cmd, sg, tot_dsds, i) {
675 struct scatterlist *end_seg; 644 dma_addr_t sle_dma;
676 645 cont_a64_entry_t *cont_pkt;
677 cur_seg = (struct scatterlist *)cmd->request_buffer; 646
678 end_seg = cur_seg + tot_dsds; 647 /* Allocate additional continuation packets? */
679 while (cur_seg < end_seg) { 648 if (avail_dsds == 0) {
680 dma_addr_t sle_dma; 649 /*
681 cont_a64_entry_t *cont_pkt; 650 * Five DSDs are available in the Continuation
682 651 * Type 1 IOCB.
683 /* Allocate additional continuation packets? */ 652 */
684 if (avail_dsds == 0) { 653 cont_pkt = qla2x00_prep_cont_type1_iocb(ha);
685 /* 654 cur_dsd = (uint32_t *)cont_pkt->dseg_0_address;
686 * Five DSDs are available in the Continuation 655 avail_dsds = 5;
687 * Type 1 IOCB.
688 */
689 cont_pkt = qla2x00_prep_cont_type1_iocb(ha);
690 cur_dsd = (uint32_t *)cont_pkt->dseg_0_address;
691 avail_dsds = 5;
692 }
693
694 sle_dma = sg_dma_address(cur_seg);
695 *cur_dsd++ = cpu_to_le32(LSD(sle_dma));
696 *cur_dsd++ = cpu_to_le32(MSD(sle_dma));
697 *cur_dsd++ = cpu_to_le32(sg_dma_len(cur_seg));
698 avail_dsds--;
699
700 cur_seg++;
701 } 656 }
702 } else { 657
703 *cur_dsd++ = cpu_to_le32(LSD(sp->dma_handle)); 658 sle_dma = sg_dma_address(sg);
704 *cur_dsd++ = cpu_to_le32(MSD(sp->dma_handle)); 659 *cur_dsd++ = cpu_to_le32(LSD(sle_dma));
705 *cur_dsd++ = cpu_to_le32(cmd->request_bufflen); 660 *cur_dsd++ = cpu_to_le32(MSD(sle_dma));
661 *cur_dsd++ = cpu_to_le32(sg_dma_len(sg));
662 avail_dsds--;
706 } 663 }
707} 664}
708 665
@@ -716,7 +673,7 @@ qla24xx_build_scsi_iocbs(srb_t *sp, struct cmd_type_7 *cmd_pkt,
716int 673int
717qla24xx_start_scsi(srb_t *sp) 674qla24xx_start_scsi(srb_t *sp)
718{ 675{
719 int ret; 676 int ret, nseg;
720 unsigned long flags; 677 unsigned long flags;
721 scsi_qla_host_t *ha; 678 scsi_qla_host_t *ha;
722 struct scsi_cmnd *cmd; 679 struct scsi_cmnd *cmd;
@@ -724,7 +681,6 @@ qla24xx_start_scsi(srb_t *sp)
724 uint32_t index; 681 uint32_t index;
725 uint32_t handle; 682 uint32_t handle;
726 struct cmd_type_7 *cmd_pkt; 683 struct cmd_type_7 *cmd_pkt;
727 struct scatterlist *sg;
728 uint16_t cnt; 684 uint16_t cnt;
729 uint16_t req_cnt; 685 uint16_t req_cnt;
730 uint16_t tot_dsds; 686 uint16_t tot_dsds;
@@ -762,23 +718,15 @@ qla24xx_start_scsi(srb_t *sp)
762 goto queuing_error; 718 goto queuing_error;
763 719
764 /* Map the sg table so we have an accurate count of sg entries needed */ 720 /* Map the sg table so we have an accurate count of sg entries needed */
765 if (cmd->use_sg) { 721 if (scsi_sg_count(cmd)) {
766 sg = (struct scatterlist *) cmd->request_buffer; 722 nseg = dma_map_sg(&ha->pdev->dev, scsi_sglist(cmd),
767 tot_dsds = pci_map_sg(ha->pdev, sg, cmd->use_sg, 723 scsi_sg_count(cmd), cmd->sc_data_direction);
768 cmd->sc_data_direction); 724 if (unlikely(!nseg))
769 if (tot_dsds == 0)
770 goto queuing_error;
771 } else if (cmd->request_bufflen) {
772 dma_addr_t req_dma;
773
774 req_dma = pci_map_single(ha->pdev, cmd->request_buffer,
775 cmd->request_bufflen, cmd->sc_data_direction);
776 if (dma_mapping_error(req_dma))
777 goto queuing_error; 725 goto queuing_error;
726 } else
727 nseg = 0;
778 728
779 sp->dma_handle = req_dma; 729 tot_dsds = nseg;
780 tot_dsds = 1;
781 }
782 730
783 req_cnt = qla24xx_calc_iocbs(tot_dsds); 731 req_cnt = qla24xx_calc_iocbs(tot_dsds);
784 if (ha->req_q_cnt < (req_cnt + 2)) { 732 if (ha->req_q_cnt < (req_cnt + 2)) {
@@ -813,6 +761,7 @@ qla24xx_start_scsi(srb_t *sp)
813 cmd_pkt->port_id[0] = sp->fcport->d_id.b.al_pa; 761 cmd_pkt->port_id[0] = sp->fcport->d_id.b.al_pa;
814 cmd_pkt->port_id[1] = sp->fcport->d_id.b.area; 762 cmd_pkt->port_id[1] = sp->fcport->d_id.b.area;
815 cmd_pkt->port_id[2] = sp->fcport->d_id.b.domain; 763 cmd_pkt->port_id[2] = sp->fcport->d_id.b.domain;
764 cmd_pkt->vp_index = sp->fcport->vp_idx;
816 765
817 int_to_scsilun(sp->cmd->device->lun, &cmd_pkt->lun); 766 int_to_scsilun(sp->cmd->device->lun, &cmd_pkt->lun);
818 host_to_fcp_swap((uint8_t *)&cmd_pkt->lun, sizeof(cmd_pkt->lun)); 767 host_to_fcp_swap((uint8_t *)&cmd_pkt->lun, sizeof(cmd_pkt->lun));
@@ -821,7 +770,7 @@ qla24xx_start_scsi(srb_t *sp)
821 memcpy(cmd_pkt->fcp_cdb, cmd->cmnd, cmd->cmd_len); 770 memcpy(cmd_pkt->fcp_cdb, cmd->cmnd, cmd->cmd_len);
822 host_to_fcp_swap(cmd_pkt->fcp_cdb, sizeof(cmd_pkt->fcp_cdb)); 771 host_to_fcp_swap(cmd_pkt->fcp_cdb, sizeof(cmd_pkt->fcp_cdb));
823 772
824 cmd_pkt->byte_count = cpu_to_le32((uint32_t)cmd->request_bufflen); 773 cmd_pkt->byte_count = cpu_to_le32((uint32_t)scsi_bufflen(cmd));
825 774
826 /* Build IOCB segments */ 775 /* Build IOCB segments */
827 qla24xx_build_scsi_iocbs(sp, cmd_pkt, tot_dsds); 776 qla24xx_build_scsi_iocbs(sp, cmd_pkt, tot_dsds);
@@ -853,14 +802,9 @@ qla24xx_start_scsi(srb_t *sp)
853 return QLA_SUCCESS; 802 return QLA_SUCCESS;
854 803
855queuing_error: 804queuing_error:
856 if (cmd->use_sg && tot_dsds) { 805 if (tot_dsds)
857 sg = (struct scatterlist *) cmd->request_buffer; 806 scsi_dma_unmap(cmd);
858 pci_unmap_sg(ha->pdev, sg, cmd->use_sg, 807
859 cmd->sc_data_direction);
860 } else if (tot_dsds) {
861 pci_unmap_single(ha->pdev, sp->dma_handle,
862 cmd->request_bufflen, cmd->sc_data_direction);
863 }
864 spin_unlock_irqrestore(&ha->hardware_lock, flags); 808 spin_unlock_irqrestore(&ha->hardware_lock, flags);
865 809
866 return QLA_FUNCTION_FAILED; 810 return QLA_FUNCTION_FAILED;