diff options
Diffstat (limited to 'drivers/scsi/lpfc/lpfc_scsi.c')
-rw-r--r-- | drivers/scsi/lpfc/lpfc_scsi.c | 446 |
1 files changed, 297 insertions, 149 deletions
diff --git a/drivers/scsi/lpfc/lpfc_scsi.c b/drivers/scsi/lpfc/lpfc_scsi.c index 167b66dd34c7..a226c053c0f4 100644 --- a/drivers/scsi/lpfc/lpfc_scsi.c +++ b/drivers/scsi/lpfc/lpfc_scsi.c | |||
@@ -438,22 +438,23 @@ lpfc_scsi_dev_block(struct lpfc_hba *phba) | |||
438 | } | 438 | } |
439 | 439 | ||
440 | /** | 440 | /** |
441 | * lpfc_new_scsi_buf - Scsi buffer allocator | 441 | * lpfc_new_scsi_buf_s3 - Scsi buffer allocator for HBA with SLI3 IF spec |
442 | * @vport: The virtual port for which this call being executed. | 442 | * @vport: The virtual port for which this call being executed. |
443 | * @num_to_allocate: The requested number of buffers to allocate. | ||
443 | * | 444 | * |
444 | * This routine allocates a scsi buffer, which contains all the necessary | 445 | * This routine allocates a scsi buffer for device with SLI-3 interface spec, |
445 | * information needed to initiate a SCSI I/O. The non-DMAable buffer region | 446 | * the scsi buffer contains all the necessary information needed to initiate |
446 | * contains information to build the IOCB. The DMAable region contains | 447 | * a SCSI I/O. The non-DMAable buffer region contains information to build |
447 | * memory for the FCP CMND, FCP RSP, and the initial BPL. In addition to | 448 | * the IOCB. The DMAable region contains memory for the FCP CMND, FCP RSP, |
448 | * allocating memory, the FCP CMND and FCP RSP BDEs are setup in the BPL | 449 | * and the initial BPL. In addition to allocating memory, the FCP CMND and |
449 | * and the BPL BDE is setup in the IOCB. | 450 | * FCP RSP BDEs are setup in the BPL and the BPL BDE is setup in the IOCB. |
450 | * | 451 | * |
451 | * Return codes: | 452 | * Return codes: |
452 | * NULL - Error | 453 | * int - number of scsi buffers that were allocated. |
453 | * Pointer to lpfc_scsi_buf data structure - Success | 454 | * 0 = failure, less than num_to_alloc is a partial failure. |
454 | **/ | 455 | **/ |
455 | static struct lpfc_scsi_buf * | 456 | static int |
456 | lpfc_new_scsi_buf(struct lpfc_vport *vport) | 457 | lpfc_new_scsi_buf_s3(struct lpfc_vport *vport, int num_to_alloc) |
457 | { | 458 | { |
458 | struct lpfc_hba *phba = vport->phba; | 459 | struct lpfc_hba *phba = vport->phba; |
459 | struct lpfc_scsi_buf *psb; | 460 | struct lpfc_scsi_buf *psb; |
@@ -463,107 +464,134 @@ lpfc_new_scsi_buf(struct lpfc_vport *vport) | |||
463 | dma_addr_t pdma_phys_fcp_rsp; | 464 | dma_addr_t pdma_phys_fcp_rsp; |
464 | dma_addr_t pdma_phys_bpl; | 465 | dma_addr_t pdma_phys_bpl; |
465 | uint16_t iotag; | 466 | uint16_t iotag; |
467 | int bcnt; | ||
466 | 468 | ||
467 | psb = kzalloc(sizeof(struct lpfc_scsi_buf), GFP_KERNEL); | 469 | for (bcnt = 0; bcnt < num_to_alloc; bcnt++) { |
468 | if (!psb) | 470 | psb = kzalloc(sizeof(struct lpfc_scsi_buf), GFP_KERNEL); |
469 | return NULL; | 471 | if (!psb) |
472 | break; | ||
470 | 473 | ||
471 | /* | 474 | /* |
472 | * Get memory from the pci pool to map the virt space to pci bus space | 475 | * Get memory from the pci pool to map the virt space to pci |
473 | * for an I/O. The DMA buffer includes space for the struct fcp_cmnd, | 476 | * bus space for an I/O. The DMA buffer includes space for the |
474 | * struct fcp_rsp and the number of bde's necessary to support the | 477 | * struct fcp_cmnd, struct fcp_rsp and the number of bde's |
475 | * sg_tablesize. | 478 | * necessary to support the sg_tablesize. |
476 | */ | 479 | */ |
477 | psb->data = pci_pool_alloc(phba->lpfc_scsi_dma_buf_pool, GFP_KERNEL, | 480 | psb->data = pci_pool_alloc(phba->lpfc_scsi_dma_buf_pool, |
478 | &psb->dma_handle); | 481 | GFP_KERNEL, &psb->dma_handle); |
479 | if (!psb->data) { | 482 | if (!psb->data) { |
480 | kfree(psb); | 483 | kfree(psb); |
481 | return NULL; | 484 | break; |
482 | } | 485 | } |
483 | 486 | ||
484 | /* Initialize virtual ptrs to dma_buf region. */ | 487 | /* Initialize virtual ptrs to dma_buf region. */ |
485 | memset(psb->data, 0, phba->cfg_sg_dma_buf_size); | 488 | memset(psb->data, 0, phba->cfg_sg_dma_buf_size); |
486 | 489 | ||
487 | /* Allocate iotag for psb->cur_iocbq. */ | 490 | /* Allocate iotag for psb->cur_iocbq. */ |
488 | iotag = lpfc_sli_next_iotag(phba, &psb->cur_iocbq); | 491 | iotag = lpfc_sli_next_iotag(phba, &psb->cur_iocbq); |
489 | if (iotag == 0) { | 492 | if (iotag == 0) { |
490 | pci_pool_free(phba->lpfc_scsi_dma_buf_pool, | 493 | pci_pool_free(phba->lpfc_scsi_dma_buf_pool, |
491 | psb->data, psb->dma_handle); | 494 | psb->data, psb->dma_handle); |
492 | kfree (psb); | 495 | kfree(psb); |
493 | return NULL; | 496 | break; |
494 | } | 497 | } |
495 | psb->cur_iocbq.iocb_flag |= LPFC_IO_FCP; | 498 | psb->cur_iocbq.iocb_flag |= LPFC_IO_FCP; |
496 | 499 | ||
497 | psb->fcp_cmnd = psb->data; | 500 | psb->fcp_cmnd = psb->data; |
498 | psb->fcp_rsp = psb->data + sizeof(struct fcp_cmnd); | 501 | psb->fcp_rsp = psb->data + sizeof(struct fcp_cmnd); |
499 | psb->fcp_bpl = psb->data + sizeof(struct fcp_cmnd) + | 502 | psb->fcp_bpl = psb->data + sizeof(struct fcp_cmnd) + |
500 | sizeof(struct fcp_rsp); | ||
501 | |||
502 | /* Initialize local short-hand pointers. */ | ||
503 | bpl = psb->fcp_bpl; | ||
504 | pdma_phys_fcp_cmd = psb->dma_handle; | ||
505 | pdma_phys_fcp_rsp = psb->dma_handle + sizeof(struct fcp_cmnd); | ||
506 | pdma_phys_bpl = psb->dma_handle + sizeof(struct fcp_cmnd) + | ||
507 | sizeof(struct fcp_rsp); | 503 | sizeof(struct fcp_rsp); |
508 | 504 | ||
509 | /* | 505 | /* Initialize local short-hand pointers. */ |
510 | * The first two bdes are the FCP_CMD and FCP_RSP. The balance are sg | 506 | bpl = psb->fcp_bpl; |
511 | * list bdes. Initialize the first two and leave the rest for | 507 | pdma_phys_fcp_cmd = psb->dma_handle; |
512 | * queuecommand. | 508 | pdma_phys_fcp_rsp = psb->dma_handle + sizeof(struct fcp_cmnd); |
513 | */ | 509 | pdma_phys_bpl = psb->dma_handle + sizeof(struct fcp_cmnd) + |
514 | bpl[0].addrHigh = le32_to_cpu(putPaddrHigh(pdma_phys_fcp_cmd)); | 510 | sizeof(struct fcp_rsp); |
515 | bpl[0].addrLow = le32_to_cpu(putPaddrLow(pdma_phys_fcp_cmd)); | 511 | |
516 | bpl[0].tus.f.bdeSize = sizeof(struct fcp_cmnd); | 512 | /* |
517 | bpl[0].tus.f.bdeFlags = BUFF_TYPE_BDE_64; | 513 | * The first two bdes are the FCP_CMD and FCP_RSP. The balance |
518 | bpl[0].tus.w = le32_to_cpu(bpl[0].tus.w); | 514 | * are sg list bdes. Initialize the first two and leave the |
519 | 515 | * rest for queuecommand. | |
520 | /* Setup the physical region for the FCP RSP */ | 516 | */ |
521 | bpl[1].addrHigh = le32_to_cpu(putPaddrHigh(pdma_phys_fcp_rsp)); | 517 | bpl[0].addrHigh = le32_to_cpu(putPaddrHigh(pdma_phys_fcp_cmd)); |
522 | bpl[1].addrLow = le32_to_cpu(putPaddrLow(pdma_phys_fcp_rsp)); | 518 | bpl[0].addrLow = le32_to_cpu(putPaddrLow(pdma_phys_fcp_cmd)); |
523 | bpl[1].tus.f.bdeSize = sizeof(struct fcp_rsp); | 519 | bpl[0].tus.f.bdeSize = sizeof(struct fcp_cmnd); |
524 | bpl[1].tus.f.bdeFlags = BUFF_TYPE_BDE_64; | 520 | bpl[0].tus.f.bdeFlags = BUFF_TYPE_BDE_64; |
525 | bpl[1].tus.w = le32_to_cpu(bpl[1].tus.w); | 521 | bpl[0].tus.w = le32_to_cpu(bpl[0].tus.w); |
522 | |||
523 | /* Setup the physical region for the FCP RSP */ | ||
524 | bpl[1].addrHigh = le32_to_cpu(putPaddrHigh(pdma_phys_fcp_rsp)); | ||
525 | bpl[1].addrLow = le32_to_cpu(putPaddrLow(pdma_phys_fcp_rsp)); | ||
526 | bpl[1].tus.f.bdeSize = sizeof(struct fcp_rsp); | ||
527 | bpl[1].tus.f.bdeFlags = BUFF_TYPE_BDE_64; | ||
528 | bpl[1].tus.w = le32_to_cpu(bpl[1].tus.w); | ||
529 | |||
530 | /* | ||
531 | * Since the IOCB for the FCP I/O is built into this | ||
532 | * lpfc_scsi_buf, initialize it with all known data now. | ||
533 | */ | ||
534 | iocb = &psb->cur_iocbq.iocb; | ||
535 | iocb->un.fcpi64.bdl.ulpIoTag32 = 0; | ||
536 | if ((phba->sli_rev == 3) && | ||
537 | !(phba->sli3_options & LPFC_SLI3_BG_ENABLED)) { | ||
538 | /* fill in immediate fcp command BDE */ | ||
539 | iocb->un.fcpi64.bdl.bdeFlags = BUFF_TYPE_BDE_IMMED; | ||
540 | iocb->un.fcpi64.bdl.bdeSize = sizeof(struct fcp_cmnd); | ||
541 | iocb->un.fcpi64.bdl.addrLow = offsetof(IOCB_t, | ||
542 | unsli3.fcp_ext.icd); | ||
543 | iocb->un.fcpi64.bdl.addrHigh = 0; | ||
544 | iocb->ulpBdeCount = 0; | ||
545 | iocb->ulpLe = 0; | ||
546 | /* fill in responce BDE */ | ||
547 | iocb->unsli3.fcp_ext.rbde.tus.f.bdeFlags = | ||
548 | BUFF_TYPE_BDE_64; | ||
549 | iocb->unsli3.fcp_ext.rbde.tus.f.bdeSize = | ||
550 | sizeof(struct fcp_rsp); | ||
551 | iocb->unsli3.fcp_ext.rbde.addrLow = | ||
552 | putPaddrLow(pdma_phys_fcp_rsp); | ||
553 | iocb->unsli3.fcp_ext.rbde.addrHigh = | ||
554 | putPaddrHigh(pdma_phys_fcp_rsp); | ||
555 | } else { | ||
556 | iocb->un.fcpi64.bdl.bdeFlags = BUFF_TYPE_BLP_64; | ||
557 | iocb->un.fcpi64.bdl.bdeSize = | ||
558 | (2 * sizeof(struct ulp_bde64)); | ||
559 | iocb->un.fcpi64.bdl.addrLow = | ||
560 | putPaddrLow(pdma_phys_bpl); | ||
561 | iocb->un.fcpi64.bdl.addrHigh = | ||
562 | putPaddrHigh(pdma_phys_bpl); | ||
563 | iocb->ulpBdeCount = 1; | ||
564 | iocb->ulpLe = 1; | ||
565 | } | ||
566 | iocb->ulpClass = CLASS3; | ||
567 | psb->status = IOSTAT_SUCCESS; | ||
526 | 568 | ||
527 | /* | ||
528 | * Since the IOCB for the FCP I/O is built into this lpfc_scsi_buf, | ||
529 | * initialize it with all known data now. | ||
530 | */ | ||
531 | iocb = &psb->cur_iocbq.iocb; | ||
532 | iocb->un.fcpi64.bdl.ulpIoTag32 = 0; | ||
533 | if ((phba->sli_rev == 3) && | ||
534 | !(phba->sli3_options & LPFC_SLI3_BG_ENABLED)) { | ||
535 | /* fill in immediate fcp command BDE */ | ||
536 | iocb->un.fcpi64.bdl.bdeFlags = BUFF_TYPE_BDE_IMMED; | ||
537 | iocb->un.fcpi64.bdl.bdeSize = sizeof(struct fcp_cmnd); | ||
538 | iocb->un.fcpi64.bdl.addrLow = offsetof(IOCB_t, | ||
539 | unsli3.fcp_ext.icd); | ||
540 | iocb->un.fcpi64.bdl.addrHigh = 0; | ||
541 | iocb->ulpBdeCount = 0; | ||
542 | iocb->ulpLe = 0; | ||
543 | /* fill in responce BDE */ | ||
544 | iocb->unsli3.fcp_ext.rbde.tus.f.bdeFlags = BUFF_TYPE_BDE_64; | ||
545 | iocb->unsli3.fcp_ext.rbde.tus.f.bdeSize = | ||
546 | sizeof(struct fcp_rsp); | ||
547 | iocb->unsli3.fcp_ext.rbde.addrLow = | ||
548 | putPaddrLow(pdma_phys_fcp_rsp); | ||
549 | iocb->unsli3.fcp_ext.rbde.addrHigh = | ||
550 | putPaddrHigh(pdma_phys_fcp_rsp); | ||
551 | } else { | ||
552 | iocb->un.fcpi64.bdl.bdeFlags = BUFF_TYPE_BLP_64; | ||
553 | iocb->un.fcpi64.bdl.bdeSize = (2 * sizeof(struct ulp_bde64)); | ||
554 | iocb->un.fcpi64.bdl.addrLow = putPaddrLow(pdma_phys_bpl); | ||
555 | iocb->un.fcpi64.bdl.addrHigh = putPaddrHigh(pdma_phys_bpl); | ||
556 | iocb->ulpBdeCount = 1; | ||
557 | iocb->ulpLe = 1; | ||
558 | } | 569 | } |
559 | iocb->ulpClass = CLASS3; | ||
560 | 570 | ||
561 | return psb; | 571 | return bcnt; |
562 | } | 572 | } |
563 | 573 | ||
564 | /** | 574 | /** |
565 | * lpfc_get_scsi_buf - Get a scsi buffer from lpfc_scsi_buf_list list of Hba | 575 | * lpfc_new_scsi_buf - Wrapper funciton for scsi buffer allocator |
566 | * @phba: The Hba for which this call is being executed. | 576 | * @vport: The virtual port for which this call being executed. |
577 | * @num_to_allocate: The requested number of buffers to allocate. | ||
578 | * | ||
579 | * This routine wraps the actual SCSI buffer allocator function pointer from | ||
580 | * the lpfc_hba struct. | ||
581 | * | ||
582 | * Return codes: | ||
583 | * int - number of scsi buffers that were allocated. | ||
584 | * 0 = failure, less than num_to_alloc is a partial failure. | ||
585 | **/ | ||
586 | static inline int | ||
587 | lpfc_new_scsi_buf(struct lpfc_vport *vport, int num_to_alloc) | ||
588 | { | ||
589 | return vport->phba->lpfc_new_scsi_buf(vport, num_to_alloc); | ||
590 | } | ||
591 | |||
592 | /** | ||
593 | * lpfc_get_scsi_buf - Get a scsi buffer from lpfc_scsi_buf_list of the HBA | ||
594 | * @phba: The HBA for which this call is being executed. | ||
567 | * | 595 | * |
568 | * This routine removes a scsi buffer from head of @phba lpfc_scsi_buf_list list | 596 | * This routine removes a scsi buffer from head of @phba lpfc_scsi_buf_list list |
569 | * and returns to caller. | 597 | * and returns to caller. |
@@ -591,7 +619,7 @@ lpfc_get_scsi_buf(struct lpfc_hba * phba) | |||
591 | } | 619 | } |
592 | 620 | ||
593 | /** | 621 | /** |
594 | * lpfc_release_scsi_buf - Return a scsi buffer back to hba's lpfc_scsi_buf_list | 622 | * lpfc_release_scsi_buf - Return a scsi buffer back to hba scsi buf list |
595 | * @phba: The Hba for which this call is being executed. | 623 | * @phba: The Hba for which this call is being executed. |
596 | * @psb: The scsi buffer which is being released. | 624 | * @psb: The scsi buffer which is being released. |
597 | * | 625 | * |
@@ -599,7 +627,7 @@ lpfc_get_scsi_buf(struct lpfc_hba * phba) | |||
599 | * lpfc_scsi_buf_list list. | 627 | * lpfc_scsi_buf_list list. |
600 | **/ | 628 | **/ |
601 | static void | 629 | static void |
602 | lpfc_release_scsi_buf(struct lpfc_hba *phba, struct lpfc_scsi_buf *psb) | 630 | lpfc_release_scsi_buf_s3(struct lpfc_hba *phba, struct lpfc_scsi_buf *psb) |
603 | { | 631 | { |
604 | unsigned long iflag = 0; | 632 | unsigned long iflag = 0; |
605 | 633 | ||
@@ -610,21 +638,36 @@ lpfc_release_scsi_buf(struct lpfc_hba *phba, struct lpfc_scsi_buf *psb) | |||
610 | } | 638 | } |
611 | 639 | ||
612 | /** | 640 | /** |
613 | * lpfc_scsi_prep_dma_buf - Routine to do DMA mapping for scsi buffer | 641 | * lpfc_release_scsi_buf: Return a scsi buffer back to hba scsi buf list. |
642 | * @phba: The Hba for which this call is being executed. | ||
643 | * @psb: The scsi buffer which is being released. | ||
644 | * | ||
645 | * This routine releases @psb scsi buffer by adding it to tail of @phba | ||
646 | * lpfc_scsi_buf_list list. | ||
647 | **/ | ||
648 | static void | ||
649 | lpfc_release_scsi_buf(struct lpfc_hba *phba, struct lpfc_scsi_buf *psb) | ||
650 | { | ||
651 | |||
652 | phba->lpfc_release_scsi_buf(phba, psb); | ||
653 | } | ||
654 | |||
655 | /** | ||
656 | * lpfc_scsi_prep_dma_buf_s3 - DMA mapping for scsi buffer to SLI3 IF spec | ||
614 | * @phba: The Hba for which this call is being executed. | 657 | * @phba: The Hba for which this call is being executed. |
615 | * @lpfc_cmd: The scsi buffer which is going to be mapped. | 658 | * @lpfc_cmd: The scsi buffer which is going to be mapped. |
616 | * | 659 | * |
617 | * This routine does the pci dma mapping for scatter-gather list of scsi cmnd | 660 | * This routine does the pci dma mapping for scatter-gather list of scsi cmnd |
618 | * field of @lpfc_cmd. This routine scans through sg elements and format the | 661 | * field of @lpfc_cmd for device with SLI-3 interface spec. This routine scans |
619 | * bdea. This routine also initializes all IOCB fields which are dependent on | 662 | * through sg elements and format the bdea. This routine also initializes all |
620 | * scsi command request buffer. | 663 | * IOCB fields which are dependent on scsi command request buffer. |
621 | * | 664 | * |
622 | * Return codes: | 665 | * Return codes: |
623 | * 1 - Error | 666 | * 1 - Error |
624 | * 0 - Success | 667 | * 0 - Success |
625 | **/ | 668 | **/ |
626 | static int | 669 | static int |
627 | lpfc_scsi_prep_dma_buf(struct lpfc_hba *phba, struct lpfc_scsi_buf *lpfc_cmd) | 670 | lpfc_scsi_prep_dma_buf_s3(struct lpfc_hba *phba, struct lpfc_scsi_buf *lpfc_cmd) |
628 | { | 671 | { |
629 | struct scsi_cmnd *scsi_cmnd = lpfc_cmd->pCmd; | 672 | struct scsi_cmnd *scsi_cmnd = lpfc_cmd->pCmd; |
630 | struct scatterlist *sgel = NULL; | 673 | struct scatterlist *sgel = NULL; |
@@ -1412,6 +1455,24 @@ out: | |||
1412 | } | 1455 | } |
1413 | 1456 | ||
1414 | /** | 1457 | /** |
1458 | * lpfc_scsi_prep_dma_buf - Wrapper function for DMA mapping of scsi buffer | ||
1459 | * @phba: The Hba for which this call is being executed. | ||
1460 | * @lpfc_cmd: The scsi buffer which is going to be mapped. | ||
1461 | * | ||
1462 | * This routine wraps the actual DMA mapping function pointer from the | ||
1463 | * lpfc_hba struct. | ||
1464 | * | ||
1465 | * Return codes: | ||
1466 | * 1 - Error | ||
1467 | * 0 - Success | ||
1468 | **/ | ||
1469 | static inline int | ||
1470 | lpfc_scsi_prep_dma_buf(struct lpfc_hba *phba, struct lpfc_scsi_buf *lpfc_cmd) | ||
1471 | { | ||
1472 | return phba->lpfc_scsi_prep_dma_buf(phba, lpfc_cmd); | ||
1473 | } | ||
1474 | |||
1475 | /** | ||
1415 | * lpfc_send_scsi_error_event - Posts an event when there is SCSI error | 1476 | * lpfc_send_scsi_error_event - Posts an event when there is SCSI error |
1416 | * @phba: Pointer to hba context object. | 1477 | * @phba: Pointer to hba context object. |
1417 | * @vport: Pointer to vport object. | 1478 | * @vport: Pointer to vport object. |
@@ -1504,15 +1565,15 @@ lpfc_send_scsi_error_event(struct lpfc_hba *phba, struct lpfc_vport *vport, | |||
1504 | } | 1565 | } |
1505 | 1566 | ||
1506 | /** | 1567 | /** |
1507 | * lpfc_scsi_unprep_dma_buf - Routine to un-map DMA mapping of scatter gather | 1568 | * lpfc_scsi_unprep_dma_buf_s3 - Un-map DMA mapping of SG-list for SLI3 dev |
1508 | * @phba: The Hba for which this call is being executed. | 1569 | * @phba: The HBA for which this call is being executed. |
1509 | * @psb: The scsi buffer which is going to be un-mapped. | 1570 | * @psb: The scsi buffer which is going to be un-mapped. |
1510 | * | 1571 | * |
1511 | * This routine does DMA un-mapping of scatter gather list of scsi command | 1572 | * This routine does DMA un-mapping of scatter gather list of scsi command |
1512 | * field of @lpfc_cmd. | 1573 | * field of @lpfc_cmd for device with SLI-3 interface spec. |
1513 | **/ | 1574 | **/ |
1514 | static void | 1575 | static void |
1515 | lpfc_scsi_unprep_dma_buf(struct lpfc_hba * phba, struct lpfc_scsi_buf * psb) | 1576 | lpfc_scsi_unprep_dma_buf_s3(struct lpfc_hba *phba, struct lpfc_scsi_buf *psb) |
1516 | { | 1577 | { |
1517 | /* | 1578 | /* |
1518 | * There are only two special cases to consider. (1) the scsi command | 1579 | * There are only two special cases to consider. (1) the scsi command |
@@ -1529,6 +1590,20 @@ lpfc_scsi_unprep_dma_buf(struct lpfc_hba * phba, struct lpfc_scsi_buf * psb) | |||
1529 | } | 1590 | } |
1530 | 1591 | ||
1531 | /** | 1592 | /** |
1593 | * lpfc_scsi_unprep_dma_buf - Wrapper function for unmap DMA mapping of SG-list | ||
1594 | * @phba: The Hba for which this call is being executed. | ||
1595 | * @psb: The scsi buffer which is going to be un-mapped. | ||
1596 | * | ||
1597 | * This routine does DMA un-mapping of scatter gather list of scsi command | ||
1598 | * field of @lpfc_cmd for device with SLI-4 interface spec. | ||
1599 | **/ | ||
1600 | static void | ||
1601 | lpfc_scsi_unprep_dma_buf(struct lpfc_hba *phba, struct lpfc_scsi_buf *psb) | ||
1602 | { | ||
1603 | phba->lpfc_scsi_unprep_dma_buf(phba, psb); | ||
1604 | } | ||
1605 | |||
1606 | /** | ||
1532 | * lpfc_handler_fcp_err - FCP response handler | 1607 | * lpfc_handler_fcp_err - FCP response handler |
1533 | * @vport: The virtual port for which this call is being executed. | 1608 | * @vport: The virtual port for which this call is being executed. |
1534 | * @lpfc_cmd: Pointer to lpfc_scsi_buf data structure. | 1609 | * @lpfc_cmd: Pointer to lpfc_scsi_buf data structure. |
@@ -1676,7 +1751,7 @@ lpfc_handle_fcp_err(struct lpfc_vport *vport, struct lpfc_scsi_buf *lpfc_cmd, | |||
1676 | * lpfc_scsi_cmd_iocb_cmpl - Scsi cmnd IOCB completion routine | 1751 | * lpfc_scsi_cmd_iocb_cmpl - Scsi cmnd IOCB completion routine |
1677 | * @phba: The Hba for which this call is being executed. | 1752 | * @phba: The Hba for which this call is being executed. |
1678 | * @pIocbIn: The command IOCBQ for the scsi cmnd. | 1753 | * @pIocbIn: The command IOCBQ for the scsi cmnd. |
1679 | * @pIocbOut: The response IOCBQ for the scsi cmnd . | 1754 | * @pIocbOut: The response IOCBQ for the scsi cmnd. |
1680 | * | 1755 | * |
1681 | * This routine assigns scsi command result by looking into response IOCB | 1756 | * This routine assigns scsi command result by looking into response IOCB |
1682 | * status field appropriately. This routine handles QUEUE FULL condition as | 1757 | * status field appropriately. This routine handles QUEUE FULL condition as |
@@ -1957,16 +2032,16 @@ lpfc_fcpcmd_to_iocb(uint8_t *data, struct fcp_cmnd *fcp_cmnd) | |||
1957 | } | 2032 | } |
1958 | 2033 | ||
1959 | /** | 2034 | /** |
1960 | * lpfc_scsi_prep_cmnd - Routine to convert scsi cmnd to FCP information unit | 2035 | * lpfc_scsi_prep_cmnd_s3 - Convert scsi cmnd to FCP infor unit for SLI3 dev |
1961 | * @vport: The virtual port for which this call is being executed. | 2036 | * @vport: The virtual port for which this call is being executed. |
1962 | * @lpfc_cmd: The scsi command which needs to send. | 2037 | * @lpfc_cmd: The scsi command which needs to send. |
1963 | * @pnode: Pointer to lpfc_nodelist. | 2038 | * @pnode: Pointer to lpfc_nodelist. |
1964 | * | 2039 | * |
1965 | * This routine initializes fcp_cmnd and iocb data structure from scsi command | 2040 | * This routine initializes fcp_cmnd and iocb data structure from scsi command |
1966 | * to transfer. | 2041 | * to transfer for device with SLI3 interface spec. |
1967 | **/ | 2042 | **/ |
1968 | static void | 2043 | static void |
1969 | lpfc_scsi_prep_cmnd(struct lpfc_vport *vport, struct lpfc_scsi_buf *lpfc_cmd, | 2044 | lpfc_scsi_prep_cmnd_s3(struct lpfc_vport *vport, struct lpfc_scsi_buf *lpfc_cmd, |
1970 | struct lpfc_nodelist *pnode) | 2045 | struct lpfc_nodelist *pnode) |
1971 | { | 2046 | { |
1972 | struct lpfc_hba *phba = vport->phba; | 2047 | struct lpfc_hba *phba = vport->phba; |
@@ -2013,8 +2088,11 @@ lpfc_scsi_prep_cmnd(struct lpfc_vport *vport, struct lpfc_scsi_buf *lpfc_cmd, | |||
2013 | if (scsi_sg_count(scsi_cmnd)) { | 2088 | if (scsi_sg_count(scsi_cmnd)) { |
2014 | if (datadir == DMA_TO_DEVICE) { | 2089 | if (datadir == DMA_TO_DEVICE) { |
2015 | iocb_cmd->ulpCommand = CMD_FCP_IWRITE64_CR; | 2090 | iocb_cmd->ulpCommand = CMD_FCP_IWRITE64_CR; |
2016 | iocb_cmd->un.fcpi.fcpi_parm = 0; | 2091 | if (phba->sli_rev < LPFC_SLI_REV4) { |
2017 | iocb_cmd->ulpPU = 0; | 2092 | iocb_cmd->un.fcpi.fcpi_parm = 0; |
2093 | iocb_cmd->ulpPU = 0; | ||
2094 | } else | ||
2095 | iocb_cmd->ulpPU = PARM_READ_CHECK; | ||
2018 | fcp_cmnd->fcpCntl3 = WRITE_DATA; | 2096 | fcp_cmnd->fcpCntl3 = WRITE_DATA; |
2019 | phba->fc4OutputRequests++; | 2097 | phba->fc4OutputRequests++; |
2020 | } else { | 2098 | } else { |
@@ -2051,20 +2129,37 @@ lpfc_scsi_prep_cmnd(struct lpfc_vport *vport, struct lpfc_scsi_buf *lpfc_cmd, | |||
2051 | } | 2129 | } |
2052 | 2130 | ||
2053 | /** | 2131 | /** |
2054 | * lpfc_scsi_prep_task_mgmt_cmnd - Convert scsi TM cmnd to FCP information unit | 2132 | * lpfc_scsi_prep_cmnd - Wrapper func for convert scsi cmnd to FCP info unit |
2133 | * @vport: The virtual port for which this call is being executed. | ||
2134 | * @lpfc_cmd: The scsi command which needs to send. | ||
2135 | * @pnode: Pointer to lpfc_nodelist. | ||
2136 | * | ||
2137 | * This routine wraps the actual convert SCSI cmnd function pointer from | ||
2138 | * the lpfc_hba struct. | ||
2139 | **/ | ||
2140 | static inline void | ||
2141 | lpfc_scsi_prep_cmnd(struct lpfc_vport *vport, struct lpfc_scsi_buf *lpfc_cmd, | ||
2142 | struct lpfc_nodelist *pnode) | ||
2143 | { | ||
2144 | vport->phba->lpfc_scsi_prep_cmnd(vport, lpfc_cmd, pnode); | ||
2145 | } | ||
2146 | |||
2147 | /** | ||
2148 | * lpfc_scsi_prep_task_mgmt_cmnd_s3 - Convert SLI3 scsi TM cmd to FCP info unit | ||
2055 | * @vport: The virtual port for which this call is being executed. | 2149 | * @vport: The virtual port for which this call is being executed. |
2056 | * @lpfc_cmd: Pointer to lpfc_scsi_buf data structure. | 2150 | * @lpfc_cmd: Pointer to lpfc_scsi_buf data structure. |
2057 | * @lun: Logical unit number. | 2151 | * @lun: Logical unit number. |
2058 | * @task_mgmt_cmd: SCSI task management command. | 2152 | * @task_mgmt_cmd: SCSI task management command. |
2059 | * | 2153 | * |
2060 | * This routine creates FCP information unit corresponding to @task_mgmt_cmd. | 2154 | * This routine creates FCP information unit corresponding to @task_mgmt_cmd |
2155 | * for device with SLI-3 interface spec. | ||
2061 | * | 2156 | * |
2062 | * Return codes: | 2157 | * Return codes: |
2063 | * 0 - Error | 2158 | * 0 - Error |
2064 | * 1 - Success | 2159 | * 1 - Success |
2065 | **/ | 2160 | **/ |
2066 | static int | 2161 | static int |
2067 | lpfc_scsi_prep_task_mgmt_cmd(struct lpfc_vport *vport, | 2162 | lpfc_scsi_prep_task_mgmt_cmd_s3(struct lpfc_vport *vport, |
2068 | struct lpfc_scsi_buf *lpfc_cmd, | 2163 | struct lpfc_scsi_buf *lpfc_cmd, |
2069 | unsigned int lun, | 2164 | unsigned int lun, |
2070 | uint8_t task_mgmt_cmd) | 2165 | uint8_t task_mgmt_cmd) |
@@ -2114,6 +2209,67 @@ lpfc_scsi_prep_task_mgmt_cmd(struct lpfc_vport *vport, | |||
2114 | } | 2209 | } |
2115 | 2210 | ||
2116 | /** | 2211 | /** |
2212 | * lpfc_scsi_prep_task_mgmt_cmnd - Wrapper func convert scsi TM cmd to FCP info | ||
2213 | * @vport: The virtual port for which this call is being executed. | ||
2214 | * @lpfc_cmd: Pointer to lpfc_scsi_buf data structure. | ||
2215 | * @lun: Logical unit number. | ||
2216 | * @task_mgmt_cmd: SCSI task management command. | ||
2217 | * | ||
2218 | * This routine wraps the actual convert SCSI TM to FCP information unit | ||
2219 | * function pointer from the lpfc_hba struct. | ||
2220 | * | ||
2221 | * Return codes: | ||
2222 | * 0 - Error | ||
2223 | * 1 - Success | ||
2224 | **/ | ||
2225 | static inline int | ||
2226 | lpfc_scsi_prep_task_mgmt_cmd(struct lpfc_vport *vport, | ||
2227 | struct lpfc_scsi_buf *lpfc_cmd, | ||
2228 | unsigned int lun, | ||
2229 | uint8_t task_mgmt_cmd) | ||
2230 | { | ||
2231 | struct lpfc_hba *phba = vport->phba; | ||
2232 | |||
2233 | return phba->lpfc_scsi_prep_task_mgmt_cmd(vport, lpfc_cmd, lun, | ||
2234 | task_mgmt_cmd); | ||
2235 | } | ||
2236 | |||
2237 | /** | ||
2238 | * lpfc_scsi_api_table_setup - Set up scsi api fucntion jump table | ||
2239 | * @phba: The hba struct for which this call is being executed. | ||
2240 | * @dev_grp: The HBA PCI-Device group number. | ||
2241 | * | ||
2242 | * This routine sets up the SCSI interface API function jump table in @phba | ||
2243 | * struct. | ||
2244 | * Returns: 0 - success, -ENODEV - failure. | ||
2245 | **/ | ||
2246 | int | ||
2247 | lpfc_scsi_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp) | ||
2248 | { | ||
2249 | |||
2250 | switch (dev_grp) { | ||
2251 | case LPFC_PCI_DEV_LP: | ||
2252 | phba->lpfc_new_scsi_buf = lpfc_new_scsi_buf_s3; | ||
2253 | phba->lpfc_scsi_prep_dma_buf = lpfc_scsi_prep_dma_buf_s3; | ||
2254 | phba->lpfc_scsi_prep_cmnd = lpfc_scsi_prep_cmnd_s3; | ||
2255 | phba->lpfc_scsi_unprep_dma_buf = lpfc_scsi_unprep_dma_buf_s3; | ||
2256 | phba->lpfc_scsi_prep_task_mgmt_cmd = | ||
2257 | lpfc_scsi_prep_task_mgmt_cmd_s3; | ||
2258 | phba->lpfc_release_scsi_buf = lpfc_release_scsi_buf_s3; | ||
2259 | break; | ||
2260 | default: | ||
2261 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | ||
2262 | "1418 Invalid HBA PCI-device group: 0x%x\n", | ||
2263 | dev_grp); | ||
2264 | return -ENODEV; | ||
2265 | break; | ||
2266 | } | ||
2267 | phba->lpfc_get_scsi_buf = lpfc_get_scsi_buf; | ||
2268 | phba->lpfc_rampdown_queue_depth = lpfc_rampdown_queue_depth; | ||
2269 | return 0; | ||
2270 | } | ||
2271 | |||
2272 | /** | ||
2117 | * lpfc_taskmgmt_def_cmpl - IOCB completion routine for task management command | 2273 | * lpfc_taskmgmt_def_cmpl - IOCB completion routine for task management command |
2118 | * @phba: The Hba for which this call is being executed. | 2274 | * @phba: The Hba for which this call is being executed. |
2119 | * @cmdiocbq: Pointer to lpfc_iocbq data structure. | 2275 | * @cmdiocbq: Pointer to lpfc_iocbq data structure. |
@@ -2178,9 +2334,8 @@ lpfc_scsi_tgt_reset(struct lpfc_scsi_buf *lpfc_cmd, struct lpfc_vport *vport, | |||
2178 | lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP, | 2334 | lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP, |
2179 | "0702 Issue Target Reset to TGT %d Data: x%x x%x\n", | 2335 | "0702 Issue Target Reset to TGT %d Data: x%x x%x\n", |
2180 | tgt_id, rdata->pnode->nlp_rpi, rdata->pnode->nlp_flag); | 2336 | tgt_id, rdata->pnode->nlp_rpi, rdata->pnode->nlp_flag); |
2181 | status = lpfc_sli_issue_iocb_wait(phba, | 2337 | status = lpfc_sli_issue_iocb_wait(phba, LPFC_FCP_RING, |
2182 | &phba->sli.ring[phba->sli.fcp_ring], | 2338 | iocbq, iocbqrsp, lpfc_cmd->timeout); |
2183 | iocbq, iocbqrsp, lpfc_cmd->timeout); | ||
2184 | if (status != IOCB_SUCCESS) { | 2339 | if (status != IOCB_SUCCESS) { |
2185 | if (status == IOCB_TIMEDOUT) { | 2340 | if (status == IOCB_TIMEDOUT) { |
2186 | iocbq->iocb_cmpl = lpfc_tskmgmt_def_cmpl; | 2341 | iocbq->iocb_cmpl = lpfc_tskmgmt_def_cmpl; |
@@ -2305,7 +2460,6 @@ lpfc_queuecommand(struct scsi_cmnd *cmnd, void (*done) (struct scsi_cmnd *)) | |||
2305 | struct Scsi_Host *shost = cmnd->device->host; | 2460 | struct Scsi_Host *shost = cmnd->device->host; |
2306 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; | 2461 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
2307 | struct lpfc_hba *phba = vport->phba; | 2462 | struct lpfc_hba *phba = vport->phba; |
2308 | struct lpfc_sli *psli = &phba->sli; | ||
2309 | struct lpfc_rport_data *rdata = cmnd->device->hostdata; | 2463 | struct lpfc_rport_data *rdata = cmnd->device->hostdata; |
2310 | struct lpfc_nodelist *ndlp = rdata->pnode; | 2464 | struct lpfc_nodelist *ndlp = rdata->pnode; |
2311 | struct lpfc_scsi_buf *lpfc_cmd; | 2465 | struct lpfc_scsi_buf *lpfc_cmd; |
@@ -2427,7 +2581,7 @@ lpfc_queuecommand(struct scsi_cmnd *cmnd, void (*done) (struct scsi_cmnd *)) | |||
2427 | lpfc_scsi_prep_cmnd(vport, lpfc_cmd, ndlp); | 2581 | lpfc_scsi_prep_cmnd(vport, lpfc_cmd, ndlp); |
2428 | 2582 | ||
2429 | atomic_inc(&ndlp->cmd_pending); | 2583 | atomic_inc(&ndlp->cmd_pending); |
2430 | err = lpfc_sli_issue_iocb(phba, &phba->sli.ring[psli->fcp_ring], | 2584 | err = lpfc_sli_issue_iocb(phba, LPFC_FCP_RING, |
2431 | &lpfc_cmd->cur_iocbq, SLI_IOCB_RET_IOCB); | 2585 | &lpfc_cmd->cur_iocbq, SLI_IOCB_RET_IOCB); |
2432 | if (err) { | 2586 | if (err) { |
2433 | atomic_dec(&ndlp->cmd_pending); | 2587 | atomic_dec(&ndlp->cmd_pending); |
@@ -2490,7 +2644,6 @@ lpfc_abort_handler(struct scsi_cmnd *cmnd) | |||
2490 | struct Scsi_Host *shost = cmnd->device->host; | 2644 | struct Scsi_Host *shost = cmnd->device->host; |
2491 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; | 2645 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
2492 | struct lpfc_hba *phba = vport->phba; | 2646 | struct lpfc_hba *phba = vport->phba; |
2493 | struct lpfc_sli_ring *pring = &phba->sli.ring[phba->sli.fcp_ring]; | ||
2494 | struct lpfc_iocbq *iocb; | 2647 | struct lpfc_iocbq *iocb; |
2495 | struct lpfc_iocbq *abtsiocb; | 2648 | struct lpfc_iocbq *abtsiocb; |
2496 | struct lpfc_scsi_buf *lpfc_cmd; | 2649 | struct lpfc_scsi_buf *lpfc_cmd; |
@@ -2531,7 +2684,10 @@ lpfc_abort_handler(struct scsi_cmnd *cmnd) | |||
2531 | icmd = &abtsiocb->iocb; | 2684 | icmd = &abtsiocb->iocb; |
2532 | icmd->un.acxri.abortType = ABORT_TYPE_ABTS; | 2685 | icmd->un.acxri.abortType = ABORT_TYPE_ABTS; |
2533 | icmd->un.acxri.abortContextTag = cmd->ulpContext; | 2686 | icmd->un.acxri.abortContextTag = cmd->ulpContext; |
2534 | icmd->un.acxri.abortIoTag = cmd->ulpIoTag; | 2687 | if (phba->sli_rev == LPFC_SLI_REV4) |
2688 | icmd->un.acxri.abortIoTag = iocb->sli4_xritag; | ||
2689 | else | ||
2690 | icmd->un.acxri.abortIoTag = cmd->ulpIoTag; | ||
2535 | 2691 | ||
2536 | icmd->ulpLe = 1; | 2692 | icmd->ulpLe = 1; |
2537 | icmd->ulpClass = cmd->ulpClass; | 2693 | icmd->ulpClass = cmd->ulpClass; |
@@ -2542,7 +2698,8 @@ lpfc_abort_handler(struct scsi_cmnd *cmnd) | |||
2542 | 2698 | ||
2543 | abtsiocb->iocb_cmpl = lpfc_sli_abort_fcp_cmpl; | 2699 | abtsiocb->iocb_cmpl = lpfc_sli_abort_fcp_cmpl; |
2544 | abtsiocb->vport = vport; | 2700 | abtsiocb->vport = vport; |
2545 | if (lpfc_sli_issue_iocb(phba, pring, abtsiocb, 0) == IOCB_ERROR) { | 2701 | if (lpfc_sli_issue_iocb(phba, LPFC_FCP_RING, abtsiocb, 0) == |
2702 | IOCB_ERROR) { | ||
2546 | lpfc_sli_release_iocbq(phba, abtsiocb); | 2703 | lpfc_sli_release_iocbq(phba, abtsiocb); |
2547 | ret = FAILED; | 2704 | ret = FAILED; |
2548 | goto out; | 2705 | goto out; |
@@ -2668,8 +2825,7 @@ lpfc_device_reset_handler(struct scsi_cmnd *cmnd) | |||
2668 | "0703 Issue target reset to TGT %d LUN %d " | 2825 | "0703 Issue target reset to TGT %d LUN %d " |
2669 | "rpi x%x nlp_flag x%x\n", cmnd->device->id, | 2826 | "rpi x%x nlp_flag x%x\n", cmnd->device->id, |
2670 | cmnd->device->lun, pnode->nlp_rpi, pnode->nlp_flag); | 2827 | cmnd->device->lun, pnode->nlp_rpi, pnode->nlp_flag); |
2671 | status = lpfc_sli_issue_iocb_wait(phba, | 2828 | status = lpfc_sli_issue_iocb_wait(phba, LPFC_FCP_RING, |
2672 | &phba->sli.ring[phba->sli.fcp_ring], | ||
2673 | iocbq, iocbqrsp, lpfc_cmd->timeout); | 2829 | iocbq, iocbqrsp, lpfc_cmd->timeout); |
2674 | if (status == IOCB_TIMEDOUT) { | 2830 | if (status == IOCB_TIMEDOUT) { |
2675 | iocbq->iocb_cmpl = lpfc_tskmgmt_def_cmpl; | 2831 | iocbq->iocb_cmpl = lpfc_tskmgmt_def_cmpl; |
@@ -2825,11 +2981,10 @@ lpfc_slave_alloc(struct scsi_device *sdev) | |||
2825 | { | 2981 | { |
2826 | struct lpfc_vport *vport = (struct lpfc_vport *) sdev->host->hostdata; | 2982 | struct lpfc_vport *vport = (struct lpfc_vport *) sdev->host->hostdata; |
2827 | struct lpfc_hba *phba = vport->phba; | 2983 | struct lpfc_hba *phba = vport->phba; |
2828 | struct lpfc_scsi_buf *scsi_buf = NULL; | ||
2829 | struct fc_rport *rport = starget_to_rport(scsi_target(sdev)); | 2984 | struct fc_rport *rport = starget_to_rport(scsi_target(sdev)); |
2830 | uint32_t total = 0, i; | 2985 | uint32_t total = 0; |
2831 | uint32_t num_to_alloc = 0; | 2986 | uint32_t num_to_alloc = 0; |
2832 | unsigned long flags; | 2987 | int num_allocated = 0; |
2833 | 2988 | ||
2834 | if (!rport || fc_remote_port_chkready(rport)) | 2989 | if (!rport || fc_remote_port_chkready(rport)) |
2835 | return -ENXIO; | 2990 | return -ENXIO; |
@@ -2863,20 +3018,13 @@ lpfc_slave_alloc(struct scsi_device *sdev) | |||
2863 | (phba->cfg_hba_queue_depth - total)); | 3018 | (phba->cfg_hba_queue_depth - total)); |
2864 | num_to_alloc = phba->cfg_hba_queue_depth - total; | 3019 | num_to_alloc = phba->cfg_hba_queue_depth - total; |
2865 | } | 3020 | } |
2866 | 3021 | num_allocated = lpfc_new_scsi_buf(vport, num_to_alloc); | |
2867 | for (i = 0; i < num_to_alloc; i++) { | 3022 | if (num_to_alloc != num_allocated) { |
2868 | scsi_buf = lpfc_new_scsi_buf(vport); | 3023 | lpfc_printf_vlog(vport, KERN_WARNING, LOG_FCP, |
2869 | if (!scsi_buf) { | 3024 | "0708 Allocation request of %d " |
2870 | lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP, | 3025 | "command buffers did not succeed. " |
2871 | "0706 Failed to allocate " | 3026 | "Allocated %d buffers.\n", |
2872 | "command buffer\n"); | 3027 | num_to_alloc, num_allocated); |
2873 | break; | ||
2874 | } | ||
2875 | |||
2876 | spin_lock_irqsave(&phba->scsi_buf_list_lock, flags); | ||
2877 | phba->total_scsi_bufs++; | ||
2878 | list_add_tail(&scsi_buf->list, &phba->lpfc_scsi_buf_list); | ||
2879 | spin_unlock_irqrestore(&phba->scsi_buf_list_lock, flags); | ||
2880 | } | 3028 | } |
2881 | return 0; | 3029 | return 0; |
2882 | } | 3030 | } |