Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Merge tag 'scsi-misc' of git://git.kernel.org/pub/scm/linux/kernel/git/jejb/scsi

Pull SCSI updates from James Bottomley:
"Updates to the usual drivers (ufs, lpfc, qla2xxx, mpi3mr, libsas) and
the usual minor updates and bug fixes but no significant core changes"

* tag 'scsi-misc' of git://git.kernel.org/pub/scm/linux/kernel/git/jejb/scsi: (116 commits)
scsi: storvsc: Handle additional SRB status values
scsi: libsas: Delete sas_ata_task.retry_count
scsi: libsas: Delete sas_ata_task.stp_affil_pol
scsi: libsas: Delete sas_ata_task.set_affil_pol
scsi: libsas: Delete sas_ssp_task.task_prio
scsi: libsas: Delete sas_ssp_task.enable_first_burst
scsi: libsas: Delete sas_ssp_task.retry_count
scsi: libsas: Delete struct scsi_core
scsi: libsas: Delete enum sas_phy_type
scsi: libsas: Delete enum sas_class
scsi: libsas: Delete sas_ha_struct.lldd_module
scsi: target: Fix write perf due to unneeded throttling
scsi: lpfc: Do not abuse UUID APIs and LPFC_COMPRESS_VMID_SIZE
scsi: pm8001: Remove unused declarations
scsi: fcoe: Fix potential deadlock on &fip->ctlr_lock
scsi: elx: sli4: Remove code duplication
scsi: bfa: Replace one-element array with flexible-array member in struct fc_rscn_pl_s
scsi: qla2xxx: Remove unused declarations
scsi: pmcraid: Use pci_dev_id() to simplify the code
scsi: pm80xx: Set RETFIS when requested by libsas
...

+1876 -4559
-247
Documentation/ABI/testing/sysfs-driver-ufs
··· 1437 1437 If avail_wb_buff < wb_flush_threshold, it indicates that WriteBooster buffer needs to 1438 1438 be flushed, otherwise it is not necessary. 1439 1439 1440 - What: /sys/bus/platform/drivers/ufshcd/*/device_descriptor/hpb_version 1441 - What: /sys/bus/platform/devices/*.ufs/device_descriptor/hpb_version 1442 - Date: June 2021 1443 - Contact: Daejun Park <daejun7.park@samsung.com> 1444 - Description: This entry shows the HPB specification version. 1445 - The full information about the descriptor can be found in the UFS 1446 - HPB (Host Performance Booster) Extension specifications. 1447 - Example: version 1.2.3 = 0123h 1448 - 1449 - The file is read only. 1450 - 1451 - What: /sys/bus/platform/drivers/ufshcd/*/device_descriptor/hpb_control 1452 - What: /sys/bus/platform/devices/*.ufs/device_descriptor/hpb_control 1453 - Date: June 2021 1454 - Contact: Daejun Park <daejun7.park@samsung.com> 1455 - Description: This entry shows an indication of the HPB control mode. 1456 - 00h: Host control mode 1457 - 01h: Device control mode 1458 - 1459 - The file is read only. 1460 - 1461 - What: /sys/bus/platform/drivers/ufshcd/*/geometry_descriptor/hpb_region_size 1462 - What: /sys/bus/platform/devices/*.ufs/geometry_descriptor/hpb_region_size 1463 - Date: June 2021 1464 - Contact: Daejun Park <daejun7.park@samsung.com> 1465 - Description: This entry shows the bHPBRegionSize which can be calculated 1466 - as in the following (in bytes): 1467 - HPB Region size = 512B * 2^bHPBRegionSize 1468 - 1469 - The file is read only. 1470 - 1471 - What: /sys/bus/platform/drivers/ufshcd/*/geometry_descriptor/hpb_number_lu 1472 - What: /sys/bus/platform/devices/*.ufs/geometry_descriptor/hpb_number_lu 1473 - Date: June 2021 1474 - Contact: Daejun Park <daejun7.park@samsung.com> 1475 - Description: This entry shows the maximum number of HPB LU supported by 1476 - the device. 1477 - 00h: HPB is not supported by the device. 1478 - 01h ~ 20h: Maximum number of HPB LU supported by the device 1479 - 1480 - The file is read only. 1481 - 1482 - What: /sys/bus/platform/drivers/ufshcd/*/geometry_descriptor/hpb_subregion_size 1483 - What: /sys/bus/platform/devices/*.ufs/geometry_descriptor/hpb_subregion_size 1484 - Date: June 2021 1485 - Contact: Daejun Park <daejun7.park@samsung.com> 1486 - Description: This entry shows the bHPBSubRegionSize, which can be 1487 - calculated as in the following (in bytes) and shall be a multiple of 1488 - logical block size: 1489 - HPB Sub-Region size = 512B x 2^bHPBSubRegionSize 1490 - bHPBSubRegionSize shall not exceed bHPBRegionSize. 1491 - 1492 - The file is read only. 1493 - 1494 - What: /sys/bus/platform/drivers/ufshcd/*/geometry_descriptor/hpb_max_active_regions 1495 - What: /sys/bus/platform/devices/*.ufs/geometry_descriptor/hpb_max_active_regions 1496 - Date: June 2021 1497 - Contact: Daejun Park <daejun7.park@samsung.com> 1498 - Description: This entry shows the maximum number of active HPB regions that 1499 - is supported by the device. 1500 - 1501 - The file is read only. 1502 - 1503 - What: /sys/class/scsi_device/*/device/unit_descriptor/hpb_lu_max_active_regions 1504 - Date: June 2021 1505 - Contact: Daejun Park <daejun7.park@samsung.com> 1506 - Description: This entry shows the maximum number of HPB regions assigned to 1507 - the HPB logical unit. 1508 - 1509 - The file is read only. 1510 - 1511 - What: /sys/class/scsi_device/*/device/unit_descriptor/hpb_pinned_region_start_offset 1512 - Date: June 2021 1513 - Contact: Daejun Park <daejun7.park@samsung.com> 1514 - Description: This entry shows the start offset of HPB pinned region. 1515 - 1516 - The file is read only. 1517 - 1518 - What: /sys/class/scsi_device/*/device/unit_descriptor/hpb_number_pinned_regions 1519 - Date: June 2021 1520 - Contact: Daejun Park <daejun7.park@samsung.com> 1521 - Description: This entry shows the number of HPB pinned regions assigned to 1522 - the HPB logical unit. 1523 - 1524 - The file is read only. 1525 - 1526 - What: /sys/class/scsi_device/*/device/hpb_stats/hit_cnt 1527 - Date: June 2021 1528 - Contact: Daejun Park <daejun7.park@samsung.com> 1529 - Description: This entry shows the number of reads that changed to HPB read. 1530 - 1531 - The file is read only. 1532 - 1533 - What: /sys/class/scsi_device/*/device/hpb_stats/miss_cnt 1534 - Date: June 2021 1535 - Contact: Daejun Park <daejun7.park@samsung.com> 1536 - Description: This entry shows the number of reads that cannot be changed to 1537 - HPB read. 1538 - 1539 - The file is read only. 1540 - 1541 - What: /sys/class/scsi_device/*/device/hpb_stats/rcmd_noti_cnt 1542 - Date: June 2021 1543 - Contact: Daejun Park <daejun7.park@samsung.com> 1544 - Description: This entry shows the number of response UPIUs that has 1545 - recommendations for activating sub-regions and/or inactivating region. 1546 - 1547 - The file is read only. 1548 - 1549 - What: /sys/class/scsi_device/*/device/hpb_stats/rcmd_active_cnt 1550 - Date: June 2021 1551 - Contact: Daejun Park <daejun7.park@samsung.com> 1552 - Description: For the HPB device control mode, this entry shows the number of 1553 - active sub-regions recommended by response UPIUs. For the HPB host control 1554 - mode, this entry shows the number of active sub-regions recommended by the 1555 - HPB host control mode heuristic algorithm. 1556 - 1557 - The file is read only. 1558 - 1559 - What: /sys/class/scsi_device/*/device/hpb_stats/rcmd_inactive_cnt 1560 - Date: June 2021 1561 - Contact: Daejun Park <daejun7.park@samsung.com> 1562 - Description: For the HPB device control mode, this entry shows the number of 1563 - inactive regions recommended by response UPIUs. For the HPB host control 1564 - mode, this entry shows the number of inactive regions recommended by the 1565 - HPB host control mode heuristic algorithm. 1566 - 1567 - The file is read only. 1568 - 1569 - What: /sys/class/scsi_device/*/device/hpb_stats/map_req_cnt 1570 - Date: June 2021 1571 - Contact: Daejun Park <daejun7.park@samsung.com> 1572 - Description: This entry shows the number of read buffer commands for 1573 - activating sub-regions recommended by response UPIUs. 1574 - 1575 - The file is read only. 1576 - 1577 - What: /sys/class/scsi_device/*/device/hpb_params/requeue_timeout_ms 1578 - Date: June 2021 1579 - Contact: Daejun Park <daejun7.park@samsung.com> 1580 - Description: This entry shows the requeue timeout threshold for write buffer 1581 - command in ms. The value can be changed by writing an integer to 1582 - this entry. 1583 - 1584 - What: /sys/bus/platform/drivers/ufshcd/*/attributes/max_data_size_hpb_single_cmd 1585 - What: /sys/bus/platform/devices/*.ufs/attributes/max_data_size_hpb_single_cmd 1586 - Date: June 2021 1587 - Contact: Daejun Park <daejun7.park@samsung.com> 1588 - Description: This entry shows the maximum HPB data size for using a single HPB 1589 - command. 1590 - 1591 - === ======== 1592 - 00h 4KB 1593 - 01h 8KB 1594 - 02h 12KB 1595 - ... 1596 - FFh 1024KB 1597 - === ======== 1598 - 1599 - The file is read only. 1600 - 1601 - What: /sys/bus/platform/drivers/ufshcd/*/flags/hpb_enable 1602 - What: /sys/bus/platform/devices/*.ufs/flags/hpb_enable 1603 - Date: June 2021 1604 - Contact: Daejun Park <daejun7.park@samsung.com> 1605 - Description: This entry shows the status of HPB. 1606 - 1607 - == ============================ 1608 - 0 HPB is not enabled. 1609 - 1 HPB is enabled 1610 - == ============================ 1611 - 1612 - The file is read only. 1613 - 1614 1440 Contact: Daniil Lunev <dlunev@chromium.org> 1615 1441 What: /sys/bus/platform/drivers/ufshcd/*/capabilities/ 1616 1442 What: /sys/bus/platform/devices/*.ufs/capabilities/ ··· 1474 1648 1475 1649 The file is read only. 1476 1650 1477 - What: /sys/class/scsi_device/*/device/hpb_param_sysfs/activation_thld 1478 - Date: February 2021 1479 - Contact: Avri Altman <avri.altman@wdc.com> 1480 - Description: In host control mode, reads are the major source of activation 1481 - trials. Once this threshold hs met, the region is added to the 1482 - "to-be-activated" list. Since we reset the read counter upon 1483 - write, this include sending a rb command updating the region 1484 - ppn as well. 1485 - 1486 - What: /sys/class/scsi_device/*/device/hpb_param_sysfs/normalization_factor 1487 - Date: February 2021 1488 - Contact: Avri Altman <avri.altman@wdc.com> 1489 - Description: In host control mode, we think of the regions as "buckets". 1490 - Those buckets are being filled with reads, and emptied on write. 1491 - We use entries_per_srgn - the amount of blocks in a subregion as 1492 - our bucket size. This applies because HPB1.0 only handles 1493 - single-block reads. Once the bucket size is crossed, we trigger 1494 - a normalization work - not only to avoid overflow, but mainly 1495 - because we want to keep those counters normalized, as we are 1496 - using those reads as a comparative score, to make various decisions. 1497 - The normalization is dividing (shift right) the read counter by 1498 - the normalization_factor. If during consecutive normalizations 1499 - an active region has exhausted its reads - inactivate it. 1500 - 1501 - What: /sys/class/scsi_device/*/device/hpb_param_sysfs/eviction_thld_enter 1502 - Date: February 2021 1503 - Contact: Avri Altman <avri.altman@wdc.com> 1504 - Description: Region deactivation is often due to the fact that eviction took 1505 - place: A region becomes active at the expense of another. This is 1506 - happening when the max-active-regions limit has been crossed. 1507 - In host mode, eviction is considered an extreme measure. We 1508 - want to verify that the entering region has enough reads, and 1509 - the exiting region has much fewer reads. eviction_thld_enter is 1510 - the min reads that a region must have in order to be considered 1511 - a candidate for evicting another region. 1512 - 1513 - What: /sys/class/scsi_device/*/device/hpb_param_sysfs/eviction_thld_exit 1514 - Date: February 2021 1515 - Contact: Avri Altman <avri.altman@wdc.com> 1516 - Description: Same as above for the exiting region. A region is considered to 1517 - be a candidate for eviction only if it has fewer reads than 1518 - eviction_thld_exit. 1519 - 1520 - What: /sys/class/scsi_device/*/device/hpb_param_sysfs/read_timeout_ms 1521 - Date: February 2021 1522 - Contact: Avri Altman <avri.altman@wdc.com> 1523 - Description: In order not to hang on to "cold" regions, we inactivate 1524 - a region that has no READ access for a predefined amount of 1525 - time - read_timeout_ms. If read_timeout_ms has expired, and the 1526 - region is dirty, it is less likely that we can make any use of 1527 - HPB reading it so we inactivate it. Still, deactivation has 1528 - its overhead, and we may still benefit from HPB reading this 1529 - region if it is clean - see read_timeout_expiries. 1530 - 1531 - What: /sys/class/scsi_device/*/device/hpb_param_sysfs/read_timeout_expiries 1532 - Date: February 2021 1533 - Contact: Avri Altman <avri.altman@wdc.com> 1534 - Description: If the region read timeout has expired, but the region is clean, 1535 - just re-wind its timer for another spin. Do that as long as it 1536 - is clean and did not exhaust its read_timeout_expiries threshold. 1537 - 1538 - What: /sys/class/scsi_device/*/device/hpb_param_sysfs/timeout_polling_interval_ms 1539 - Date: February 2021 1540 - Contact: Avri Altman <avri.altman@wdc.com> 1541 - Description: The frequency with which the delayed worker that checks the 1542 - read_timeouts is awakened. 1543 - 1544 - What: /sys/class/scsi_device/*/device/hpb_param_sysfs/inflight_map_req 1545 - Date: February 2021 1546 - Contact: Avri Altman <avri.altman@wdc.com> 1547 - Description: In host control mode the host is the originator of map requests. 1548 - To avoid flooding the device with map requests, use a simple throttling 1549 - mechanism that limits the number of inflight map requests.
+2 -2
Documentation/scsi/scsi_mid_low_api.rst
··· 1190 1190 - pointer to scsi_device object that this command is 1191 1191 associated with. 1192 1192 resid 1193 - - an LLD should set this signed integer to the requested 1193 + - an LLD should set this unsigned integer to the requested 1194 1194 transfer length (i.e. 'request_bufflen') less the number 1195 1195 of bytes that are actually transferred. 'resid' is 1196 1196 preset to 0 so an LLD can ignore it if it cannot detect 1197 - underruns (overruns should be rare). If possible an LLD 1197 + underruns (overruns should not be reported). An LLD 1198 1198 should set 'resid' prior to invoking 'done'. The most 1199 1199 interesting case is data transfers from a SCSI target 1200 1200 device (e.g. READs) that underrun.
-4
drivers/infiniband/ulp/srp/ib_srp.c
··· 1979 1979 1980 1980 if (unlikely(rsp->flags & SRP_RSP_FLAG_DIUNDER)) 1981 1981 scsi_set_resid(scmnd, be32_to_cpu(rsp->data_in_res_cnt)); 1982 - else if (unlikely(rsp->flags & SRP_RSP_FLAG_DIOVER)) 1983 - scsi_set_resid(scmnd, -be32_to_cpu(rsp->data_in_res_cnt)); 1984 1982 else if (unlikely(rsp->flags & SRP_RSP_FLAG_DOUNDER)) 1985 1983 scsi_set_resid(scmnd, be32_to_cpu(rsp->data_out_res_cnt)); 1986 - else if (unlikely(rsp->flags & SRP_RSP_FLAG_DOOVER)) 1987 - scsi_set_resid(scmnd, -be32_to_cpu(rsp->data_out_res_cnt)); 1988 1984 1989 1985 srp_free_req(ch, req, scmnd, 1990 1986 be32_to_cpu(rsp->req_lim_delta));
+1 -1
drivers/scsi/Kconfig
··· 836 836 837 837 config SCSI_IZIP_EPP16 838 838 bool "ppa/imm option - Use slow (but safe) EPP-16" 839 - depends on SCSI_PPA || SCSI_IMM 839 + depends on SCSI_IMM 840 840 help 841 841 EPP (Enhanced Parallel Port) is a standard for parallel ports which 842 842 allows them to act as expansion buses that can handle up to 64
+2 -14
drivers/scsi/aic7xxx/aicasm/Makefile
··· 61 61 clean: 62 62 rm -f $(clean-files) 63 63 64 - # Create a dependency chain in generated files 65 - # to avoid concurrent invocations of the single 66 - # rule that builds them all. 67 - $(OUTDIR)/aicasm_gram.c: $(OUTDIR)/aicasm_gram.h 68 64 $(OUTDIR)/aicasm_gram.c $(OUTDIR)/aicasm_gram.h: aicasm_gram.y 69 - $(YACC) $(YFLAGS) -b $(<:.y=) $< 70 - mv $(<:.y=).tab.c $(OUTDIR)/$(<:.y=.c) 71 - mv $(<:.y=).tab.h $(OUTDIR)/$(<:.y=.h) 65 + $(YACC) $(YFLAGS) -b $(<:.y=) $< -o $(OUTDIR)/$(<:.y=.c) 72 66 73 - # Create a dependency chain in generated files 74 - # to avoid concurrent invocations of the single 75 - # rule that builds them all. 76 - $(OUTDIR)/aicasm_macro_gram.c: $(OUTDIR)/aicasm_macro_gram.h 77 67 $(OUTDIR)/aicasm_macro_gram.c $(OUTDIR)/aicasm_macro_gram.h: aicasm_macro_gram.y 78 - $(YACC) $(YFLAGS) -b $(<:.y=) -p mm $< 79 - mv $(<:.y=).tab.c $(OUTDIR)/$(<:.y=.c) 80 - mv $(<:.y=).tab.h $(OUTDIR)/$(<:.y=.h) 68 + $(YACC) $(YFLAGS) -b $(<:.y=) -p mm $< -o $(OUTDIR)/$(<:.y=.c) 81 69 82 70 $(OUTDIR)/aicasm_scan.c: aicasm_scan.l 83 71 $(LEX) $(LFLAGS) -o $@ $<
+1
drivers/scsi/aic7xxx/aicasm/aicasm_symbol.c
··· 52 52 #include <stdlib.h> 53 53 #include <string.h> 54 54 #include <sysexits.h> 55 + #include <ctype.h> 55 56 56 57 #include "aicasm_symbol.h" 57 58 #include "aicasm.h"
+1 -3
drivers/scsi/aic94xx/aic94xx_hwi.c
··· 28 28 if (asd_ha->hw_prof.sas_addr[0]) 29 29 return 0; 30 30 31 - return sas_request_addr(asd_ha->sas_ha.core.shost, 31 + return sas_request_addr(asd_ha->sas_ha.shost, 32 32 asd_ha->hw_prof.sas_addr); 33 33 } 34 34 ··· 72 72 struct asd_sas_phy *sas_phy = &phy->sas_phy; 73 73 74 74 sas_phy->enabled = 1; 75 - sas_phy->class = SAS; 76 75 sas_phy->iproto = SAS_PROTOCOL_ALL; 77 76 sas_phy->tproto = 0; 78 - sas_phy->type = PHY_TYPE_PHYSICAL; 79 77 sas_phy->role = PHY_ROLE_INITIATOR; 80 78 sas_phy->oob_mode = OOB_NOT_CONNECTED; 81 79 sas_phy->linkrate = SAS_LINK_RATE_UNKNOWN;
+3 -4
drivers/scsi/aic94xx/aic94xx_init.c
··· 667 667 } 668 668 669 669 asd_ha->sas_ha.sas_ha_name = (char *) asd_ha->name; 670 - asd_ha->sas_ha.lldd_module = THIS_MODULE; 671 670 asd_ha->sas_ha.sas_addr = &asd_ha->hw_prof.sas_addr[0]; 672 671 673 672 for (i = 0; i < ASD_MAX_PHYS; i++) { ··· 687 688 688 689 err = sas_unregister_ha(&asd_ha->sas_ha); 689 690 690 - sas_remove_host(asd_ha->sas_ha.core.shost); 691 - scsi_host_put(asd_ha->sas_ha.core.shost); 691 + sas_remove_host(asd_ha->sas_ha.shost); 692 + scsi_host_put(asd_ha->sas_ha.shost); 692 693 693 694 kfree(asd_ha->sas_ha.sas_phy); 694 695 kfree(asd_ha->sas_ha.sas_port); ··· 738 739 asd_printk("found %s, device %s\n", asd_ha->name, pci_name(dev)); 739 740 740 741 SHOST_TO_SAS_HA(shost) = &asd_ha->sas_ha; 741 - asd_ha->sas_ha.core.shost = shost; 742 + asd_ha->sas_ha.shost = shost; 742 743 shost->transportt = aic94xx_transport_template; 743 744 shost->max_id = ~0; 744 745 shost->max_lun = ~0;
+2 -10
drivers/scsi/aic94xx/aic94xx_task.c
··· 388 388 flags |= data_dir_flags[task->data_dir]; 389 389 scb->ata_task.ata_flags = flags; 390 390 391 - scb->ata_task.retry_count = task->ata_task.retry_count; 391 + scb->ata_task.retry_count = 0; 392 392 393 - flags = 0; 394 - if (task->ata_task.set_affil_pol) 395 - flags |= SET_AFFIL_POLICY; 396 - if (task->ata_task.stp_affil_pol) 397 - flags |= STP_AFFIL_POLICY; 398 - scb->ata_task.flags = flags; 393 + scb->ata_task.flags = 0; 399 394 } 400 395 ascb->tasklet_complete = asd_task_tasklet_complete; 401 396 ··· 480 485 scb->ssp_task.ssp_frame.tptt = cpu_to_be16(0xFFFF); 481 486 482 487 memcpy(scb->ssp_task.ssp_cmd.lun, task->ssp_task.LUN, 8); 483 - if (task->ssp_task.enable_first_burst) 484 - scb->ssp_task.ssp_cmd.efb_prio_attr |= EFB_MASK; 485 - scb->ssp_task.ssp_cmd.efb_prio_attr |= (task->ssp_task.task_prio << 3); 486 488 scb->ssp_task.ssp_cmd.efb_prio_attr |= (task->ssp_task.task_attr & 7); 487 489 memcpy(scb->ssp_task.ssp_cmd.cdb, task->ssp_task.cmd->cmnd, 488 490 task->ssp_task.cmd->cmd_len);
+2 -2
drivers/scsi/arcmsr/arcmsr_hba.c
··· 1715 1715 arcmsr_flush_adapter_cache(acb); 1716 1716 } 1717 1717 1718 - static int arcmsr_module_init(void) 1718 + static int __init arcmsr_module_init(void) 1719 1719 { 1720 1720 int error = 0; 1721 1721 error = pci_register_driver(&arcmsr_pci_driver); 1722 1722 return error; 1723 1723 } 1724 1724 1725 - static void arcmsr_module_exit(void) 1725 + static void __exit arcmsr_module_exit(void) 1726 1726 { 1727 1727 pci_unregister_driver(&arcmsr_pci_driver); 1728 1728 }
+4
drivers/scsi/be2iscsi/be_iscsi.c
··· 450 450 } 451 451 452 452 nla_for_each_attr(attrib, data, dt_len, rm_len) { 453 + /* ignore nla_type as it is never used */ 454 + if (nla_len(attrib) < sizeof(*iface_param)) 455 + return -EINVAL; 456 + 453 457 iface_param = nla_data(attrib); 454 458 455 459 if (iface_param->param_type != ISCSI_NET_PARAM)
+1 -1
drivers/scsi/bfa/bfa_fc.h
··· 800 800 u8 command; 801 801 u8 pagelen; 802 802 __be16 payldlen; 803 - struct fc_rscn_event_s event[1]; 803 + struct fc_rscn_event_s event[]; 804 804 }; 805 805 806 806 /*
+1 -1
drivers/scsi/bfa/bfa_fcbuild.c
··· 1051 1051 rscn->event[0].format = FC_RSCN_FORMAT_PORTID; 1052 1052 rscn->event[0].portid = s_id; 1053 1053 1054 - return sizeof(struct fc_rscn_pl_s); 1054 + return struct_size(rscn, event, 1); 1055 1055 } 1056 1056 1057 1057 u16
+2 -6
drivers/scsi/elx/libefc_sli/sli4.c
··· 2317 2317 SLI4_GENERIC_CONTEXT_VPI << SLI4_BLS_RSP_WQE_CT_SHFT; 2318 2318 bls->context_tag = cpu_to_le16(params->vpi); 2319 2319 2320 - if (params->s_id != U32_MAX) 2321 - bls->local_n_port_id_dword |= 2322 - cpu_to_le32(params->s_id & 0x00ffffff); 2323 - else 2324 - bls->local_n_port_id_dword |= 2325 - cpu_to_le32(params->s_id & 0x00ffffff); 2320 + bls->local_n_port_id_dword |= 2321 + cpu_to_le32(params->s_id & 0x00ffffff); 2326 2322 2327 2323 dw_ridflags = (dw_ridflags & ~SLI4_BLS_RSP_RID) | 2328 2324 (params->d_id & SLI4_BLS_RSP_RID);
+12 -8
drivers/scsi/fcoe/fcoe_ctlr.c
··· 319 319 { 320 320 struct fcoe_fcf *sel; 321 321 struct fcoe_fcf *fcf; 322 + unsigned long flags; 322 323 323 324 mutex_lock(&fip->ctlr_mutex); 324 - spin_lock_bh(&fip->ctlr_lock); 325 + spin_lock_irqsave(&fip->ctlr_lock, flags); 325 326 326 327 kfree_skb(fip->flogi_req); 327 328 fip->flogi_req = NULL; 328 329 list_for_each_entry(fcf, &fip->fcfs, list) 329 330 fcf->flogi_sent = 0; 330 331 331 - spin_unlock_bh(&fip->ctlr_lock); 332 + spin_unlock_irqrestore(&fip->ctlr_lock, flags); 332 333 sel = fip->sel_fcf; 333 334 334 335 if (sel && ether_addr_equal(sel->fcf_mac, fip->dest_addr)) ··· 700 699 { 701 700 struct fc_frame *fp; 702 701 struct fc_frame_header *fh; 702 + unsigned long flags; 703 703 u16 old_xid; 704 704 u8 op; 705 705 u8 mac[ETH_ALEN]; ··· 734 732 op = FIP_DT_FLOGI; 735 733 if (fip->mode == FIP_MODE_VN2VN) 736 734 break; 737 - spin_lock_bh(&fip->ctlr_lock); 735 + spin_lock_irqsave(&fip->ctlr_lock, flags); 738 736 kfree_skb(fip->flogi_req); 739 737 fip->flogi_req = skb; 740 738 fip->flogi_req_send = 1; 741 - spin_unlock_bh(&fip->ctlr_lock); 739 + spin_unlock_irqrestore(&fip->ctlr_lock, flags); 742 740 schedule_work(&fip->timer_work); 743 741 return -EINPROGRESS; 744 742 case ELS_FDISC: ··· 1707 1705 static int fcoe_ctlr_flogi_retry(struct fcoe_ctlr *fip) 1708 1706 { 1709 1707 struct fcoe_fcf *fcf; 1708 + unsigned long flags; 1710 1709 int error; 1711 1710 1712 1711 mutex_lock(&fip->ctlr_mutex); 1713 - spin_lock_bh(&fip->ctlr_lock); 1712 + spin_lock_irqsave(&fip->ctlr_lock, flags); 1714 1713 LIBFCOE_FIP_DBG(fip, "re-sending FLOGI - reselect\n"); 1715 1714 fcf = fcoe_ctlr_select(fip); 1716 1715 if (!fcf || fcf->flogi_sent) { ··· 1722 1719 fcoe_ctlr_solicit(fip, NULL); 1723 1720 error = fcoe_ctlr_flogi_send_locked(fip); 1724 1721 } 1725 - spin_unlock_bh(&fip->ctlr_lock); 1722 + spin_unlock_irqrestore(&fip->ctlr_lock, flags); 1726 1723 mutex_unlock(&fip->ctlr_mutex); 1727 1724 return error; 1728 1725 } ··· 1739 1736 static void fcoe_ctlr_flogi_send(struct fcoe_ctlr *fip) 1740 1737 { 1741 1738 struct fcoe_fcf *fcf; 1739 + unsigned long flags; 1742 1740 1743 - spin_lock_bh(&fip->ctlr_lock); 1741 + spin_lock_irqsave(&fip->ctlr_lock, flags); 1744 1742 fcf = fip->sel_fcf; 1745 1743 if (!fcf || !fip->flogi_req_send) 1746 1744 goto unlock; ··· 1768 1764 } else /* XXX */ 1769 1765 LIBFCOE_FIP_DBG(fip, "No FCF selected - defer send\n"); 1770 1766 unlock: 1771 - spin_unlock_bh(&fip->ctlr_lock); 1767 + spin_unlock_irqrestore(&fip->ctlr_lock, flags); 1772 1768 } 1773 1769 1774 1770 /**
-5
drivers/scsi/gvp11.c
··· 50 50 51 51 static int gvp11_xfer_mask = 0; 52 52 53 - void gvp11_setup(char *str, int *ints) 54 - { 55 - gvp11_xfer_mask = ints[1]; 56 - } 57 - 58 53 static int dma_setup(struct scsi_cmnd *cmd, int dir_in) 59 54 { 60 55 struct scsi_pointer *scsi_pointer = WD33C93_scsi_pointer(cmd);
+3 -11
drivers/scsi/hisi_sas/hisi_sas_main.c
··· 1018 1018 phy->minimum_linkrate = SAS_LINK_RATE_1_5_GBPS; 1019 1019 phy->maximum_linkrate = hisi_hba->hw->phy_get_max_linkrate(); 1020 1020 sas_phy->enabled = (phy_no < hisi_hba->n_phy) ? 1 : 0; 1021 - sas_phy->class = SAS; 1022 1021 sas_phy->iproto = SAS_PROTOCOL_ALL; 1023 1022 sas_phy->tproto = 0; 1024 - sas_phy->type = PHY_TYPE_PHYSICAL; 1025 1023 sas_phy->role = PHY_ROLE_INITIATOR; 1026 1024 sas_phy->oob_mode = OOB_NOT_CONNECTED; 1027 1025 sas_phy->linkrate = SAS_LINK_RATE_UNKNOWN; ··· 1063 1065 1064 1066 static void hisi_sas_port_notify_formed(struct asd_sas_phy *sas_phy) 1065 1067 { 1066 - struct sas_ha_struct *sas_ha = sas_phy->ha; 1067 - struct hisi_hba *hisi_hba = sas_ha->lldd_ha; 1068 1068 struct hisi_sas_phy *phy = sas_phy->lldd_phy; 1069 1069 struct asd_sas_port *sas_port = sas_phy->port; 1070 1070 struct hisi_sas_port *port; 1071 - unsigned long flags; 1072 1071 1073 1072 if (!sas_port) 1074 1073 return; 1075 1074 1076 1075 port = to_hisi_sas_port(sas_port); 1077 - spin_lock_irqsave(&hisi_hba->lock, flags); 1078 1076 port->port_attached = 1; 1079 1077 port->id = phy->port_id; 1080 1078 phy->port = port; 1081 1079 sas_port->lldd_port = port; 1082 - spin_unlock_irqrestore(&hisi_hba->lock, flags); 1083 1080 } 1084 1081 1085 1082 static void hisi_sas_do_release_task(struct hisi_hba *hisi_hba, struct sas_task *task, ··· 2512 2519 2513 2520 sha->sas_ha_name = DRV_NAME; 2514 2521 sha->dev = hisi_hba->dev; 2515 - sha->lldd_module = THIS_MODULE; 2516 2522 sha->sas_addr = &hisi_hba->sas_addr[0]; 2517 2523 sha->num_phys = hisi_hba->n_phy; 2518 - sha->core.shost = hisi_hba->shost; 2524 + sha->shost = hisi_hba->shost; 2519 2525 2520 2526 for (i = 0; i < hisi_hba->n_phy; i++) { 2521 2527 sha->sas_phy[i] = &hisi_hba->phy[i].sas_phy; ··· 2556 2564 { 2557 2565 struct sas_ha_struct *sha = platform_get_drvdata(pdev); 2558 2566 struct hisi_hba *hisi_hba = sha->lldd_ha; 2559 - struct Scsi_Host *shost = sha->core.shost; 2567 + struct Scsi_Host *shost = sha->shost; 2560 2568 2561 2569 del_timer_sync(&hisi_hba->timer); 2562 2570 2563 2571 sas_unregister_ha(sha); 2564 - sas_remove_host(sha->core.shost); 2572 + sas_remove_host(shost); 2565 2573 2566 2574 hisi_sas_free(hisi_hba); 2567 2575 scsi_host_put(shost);
+2 -7
drivers/scsi/hisi_sas/hisi_sas_v1_hw.c
··· 960 960 struct scsi_cmnd *scsi_cmnd = ssp_task->cmd; 961 961 struct sas_tmf_task *tmf = slot->tmf; 962 962 int has_data = 0, priority = !!tmf; 963 - u8 *buf_cmd, fburst = 0; 963 + u8 *buf_cmd; 964 964 u32 dw1, dw2; 965 965 966 966 /* create header */ ··· 1018 1018 1019 1019 buf_cmd = hisi_sas_cmd_hdr_addr_mem(slot) + 1020 1020 sizeof(struct ssp_frame_hdr); 1021 - if (task->ssp_task.enable_first_burst) { 1022 - fburst = (1 << 7); 1023 - dw2 |= 1 << CMD_HDR_FIRST_BURST_OFF; 1024 - } 1025 1021 hdr->dw2 = cpu_to_le32(dw2); 1026 1022 1027 1023 memcpy(buf_cmd, &task->ssp_task.LUN, 8); 1028 1024 if (!tmf) { 1029 - buf_cmd[9] = fburst | task->ssp_task.task_attr | 1030 - (task->ssp_task.task_prio << 3); 1025 + buf_cmd[9] = task->ssp_task.task_attr; 1031 1026 memcpy(buf_cmd + 12, task->ssp_task.cmd->cmnd, 1032 1027 task->ssp_task.cmd->cmd_len); 1033 1028 } else {
+10 -4
drivers/scsi/hisi_sas/hisi_sas_v2_hw.c
··· 1798 1798 1799 1799 memcpy(buf_cmd, &task->ssp_task.LUN, 8); 1800 1800 if (!tmf) { 1801 - buf_cmd[9] = task->ssp_task.task_attr | 1802 - (task->ssp_task.task_prio << 3); 1801 + buf_cmd[9] = task->ssp_task.task_attr; 1803 1802 memcpy(buf_cmd + 12, task->ssp_task.cmd->cmnd, 1804 1803 task->ssp_task.cmd->cmd_len); 1805 1804 } else { ··· 2025 2026 u16 dma_tx_err_type = le16_to_cpu(err_record->dma_tx_err_type); 2026 2027 u16 sipc_rx_err_type = le16_to_cpu(err_record->sipc_rx_err_type); 2027 2028 u32 dma_rx_err_type = le32_to_cpu(err_record->dma_rx_err_type); 2029 + struct hisi_sas_complete_v2_hdr *complete_queue = 2030 + hisi_hba->complete_hdr[slot->cmplt_queue]; 2031 + struct hisi_sas_complete_v2_hdr *complete_hdr = 2032 + &complete_queue[slot->cmplt_queue_slot]; 2033 + u32 dw0 = le32_to_cpu(complete_hdr->dw0); 2028 2034 int error = -1; 2029 2035 2030 2036 if (err_phase == 1) { ··· 2314 2310 break; 2315 2311 } 2316 2312 } 2317 - hisi_sas_sata_done(task, slot); 2313 + if (dw0 & CMPLT_HDR_RSPNS_XFRD_MSK) 2314 + hisi_sas_sata_done(task, slot); 2318 2315 } 2319 2316 break; 2320 2317 default: ··· 2448 2443 case SAS_PROTOCOL_SATA | SAS_PROTOCOL_STP: 2449 2444 { 2450 2445 ts->stat = SAS_SAM_STAT_GOOD; 2451 - hisi_sas_sata_done(task, slot); 2446 + if (dw0 & CMPLT_HDR_RSPNS_XFRD_MSK) 2447 + hisi_sas_sata_done(task, slot); 2452 2448 break; 2453 2449 } 2454 2450 default:
+16 -11
drivers/scsi/hisi_sas/hisi_sas_v3_hw.c
··· 1326 1326 1327 1327 memcpy(buf_cmd, &task->ssp_task.LUN, 8); 1328 1328 if (!tmf) { 1329 - buf_cmd[9] = ssp_task->task_attr | (ssp_task->task_prio << 3); 1329 + buf_cmd[9] = ssp_task->task_attr; 1330 1330 memcpy(buf_cmd + 12, scsi_cmnd->cmnd, scsi_cmnd->cmd_len); 1331 1331 } else { 1332 1332 buf_cmd[10] = tmf->tmf; ··· 2257 2257 ts->stat = SAS_OPEN_REJECT; 2258 2258 ts->open_rej_reason = SAS_OREJ_RSVD_RETRY; 2259 2259 } 2260 - hisi_sas_sata_done(task, slot); 2260 + if (dw0 & CMPLT_HDR_RSPNS_XFRD_MSK) 2261 + hisi_sas_sata_done(task, slot); 2261 2262 break; 2262 2263 case SAS_PROTOCOL_SMP: 2263 2264 ts->stat = SAS_SAM_STAT_CHECK_CONDITION; ··· 2385 2384 case SAS_PROTOCOL_STP: 2386 2385 case SAS_PROTOCOL_SATA | SAS_PROTOCOL_STP: 2387 2386 ts->stat = SAS_SAM_STAT_GOOD; 2388 - hisi_sas_sata_done(task, slot); 2387 + if (dw0 & CMPLT_HDR_RSPNS_XFRD_MSK) 2388 + hisi_sas_sata_done(task, slot); 2389 2389 break; 2390 2390 default: 2391 2391 ts->stat = SAS_SAM_STAT_CHECK_CONDITION; ··· 3106 3104 3107 3105 static void debugfs_snapshot_prepare_v3_hw(struct hisi_hba *hisi_hba) 3108 3106 { 3109 - set_bit(HISI_SAS_REJECT_CMD_BIT, &hisi_hba->flags); 3107 + struct Scsi_Host *shost = hisi_hba->shost; 3110 3108 3111 - hisi_sas_write32(hisi_hba, DLVRY_QUEUE_ENABLE, 0); 3112 - 3109 + scsi_block_requests(shost); 3113 3110 wait_cmds_complete_timeout_v3_hw(hisi_hba, 100, 5000); 3114 3111 3112 + set_bit(HISI_SAS_REJECT_CMD_BIT, &hisi_hba->flags); 3115 3113 hisi_sas_sync_cqs(hisi_hba); 3114 + hisi_sas_write32(hisi_hba, DLVRY_QUEUE_ENABLE, 0); 3116 3115 } 3117 3116 3118 3117 static void debugfs_snapshot_restore_v3_hw(struct hisi_hba *hisi_hba) 3119 3118 { 3119 + struct Scsi_Host *shost = hisi_hba->shost; 3120 + 3120 3121 hisi_sas_write32(hisi_hba, DLVRY_QUEUE_ENABLE, 3121 3122 (u32)((1ULL << hisi_hba->queue_count) - 1)); 3122 3123 3123 3124 clear_bit(HISI_SAS_REJECT_CMD_BIT, &hisi_hba->flags); 3125 + scsi_unblock_requests(shost); 3124 3126 } 3125 3127 3126 3128 static void read_iost_itct_cache_v3_hw(struct hisi_hba *hisi_hba, ··· 4582 4576 debugfs_read_fifo_data_v3_hw(phy); 4583 4577 4584 4578 debugfs_show_row_32_v3_hw(s, 0, HISI_SAS_FIFO_DATA_DW_SIZE * 4, 4585 - phy->fifo.rd_data); 4579 + (__le32 *)phy->fifo.rd_data); 4586 4580 4587 4581 return 0; 4588 4582 } ··· 4956 4950 4957 4951 sha->sas_phy = arr_phy; 4958 4952 sha->sas_port = arr_port; 4959 - sha->core.shost = shost; 4953 + sha->shost = shost; 4960 4954 sha->lldd_ha = hisi_hba; 4961 4955 4962 4956 shost->transportt = hisi_sas_stt; ··· 4973 4967 4974 4968 sha->sas_ha_name = DRV_NAME; 4975 4969 sha->dev = dev; 4976 - sha->lldd_module = THIS_MODULE; 4977 4970 sha->sas_addr = &hisi_hba->sas_addr[0]; 4978 4971 sha->num_phys = hisi_hba->n_phy; 4979 4972 ··· 5060 5055 struct device *dev = &pdev->dev; 5061 5056 struct sas_ha_struct *sha = dev_get_drvdata(dev); 5062 5057 struct hisi_hba *hisi_hba = sha->lldd_ha; 5063 - struct Scsi_Host *shost = sha->core.shost; 5058 + struct Scsi_Host *shost = sha->shost; 5064 5059 5065 5060 pm_runtime_get_noresume(dev); 5066 5061 del_timer_sync(&hisi_hba->timer); 5067 5062 5068 5063 sas_unregister_ha(sha); 5069 5064 flush_workqueue(hisi_hba->wq); 5070 - sas_remove_host(sha->core.shost); 5065 + sas_remove_host(shost); 5071 5066 5072 5067 hisi_sas_v3_destroy_irqs(pdev, hisi_hba); 5073 5068 hisi_sas_free(hisi_hba);
+2 -2
drivers/scsi/hosts.c
··· 537 537 static int __scsi_host_match(struct device *dev, const void *data) 538 538 { 539 539 struct Scsi_Host *p; 540 - const unsigned short *hostnum = data; 540 + const unsigned int *hostnum = data; 541 541 542 542 p = class_to_shost(dev); 543 543 return p->host_no == *hostnum; ··· 554 554 * that scsi_host_get() took. The put_device() below dropped 555 555 * the reference from class_find_device(). 556 556 **/ 557 - struct Scsi_Host *scsi_host_lookup(unsigned short hostnum) 557 + struct Scsi_Host *scsi_host_lookup(unsigned int hostnum) 558 558 { 559 559 struct device *cdev; 560 560 struct Scsi_Host *shost = NULL;
+1 -1
drivers/scsi/isci/host.h
··· 306 306 307 307 static inline struct Scsi_Host *to_shost(struct isci_host *ihost) 308 308 { 309 - return ihost->sas_ha.core.shost; 309 + return ihost->sas_ha.shost; 310 310 } 311 311 312 312 #define for_each_isci_host(id, ihost, pdev) \
+3 -6
drivers/scsi/isci/init.c
··· 250 250 return -ENOMEM; 251 251 252 252 sas_ha->sas_ha_name = DRV_NAME; 253 - sas_ha->lldd_module = THIS_MODULE; 254 253 sas_ha->sas_addr = &isci_host->phys[0].sas_addr[0]; 255 254 256 255 for (i = 0; i < SCI_MAX_PHYS; i++) { ··· 263 264 264 265 sas_ha->strict_wide_ports = 1; 265 266 266 - sas_register_ha(sas_ha); 267 - 268 - return 0; 267 + return sas_register_ha(sas_ha); 269 268 } 270 269 271 270 static void isci_unregister(struct isci_host *isci_host) ··· 572 575 goto err_shost; 573 576 574 577 SHOST_TO_SAS_HA(shost) = &ihost->sas_ha; 575 - ihost->sas_ha.core.shost = shost; 578 + ihost->sas_ha.shost = shost; 576 579 shost->transportt = isci_transport_template; 577 580 578 581 shost->max_id = ~0; ··· 727 730 sas_prep_resume_ha(&ihost->sas_ha); 728 731 729 732 isci_host_init(ihost); 730 - isci_host_start(ihost->sas_ha.core.shost); 733 + isci_host_start(ihost->sas_ha.shost); 731 734 wait_for_start(ihost); 732 735 733 736 sas_resume_ha(&ihost->sas_ha);
-2
drivers/scsi/isci/phy.c
··· 1404 1404 iphy->sas_phy.ha = &ihost->sas_ha; 1405 1405 iphy->sas_phy.lldd_phy = iphy; 1406 1406 iphy->sas_phy.enabled = 1; 1407 - iphy->sas_phy.class = SAS; 1408 1407 iphy->sas_phy.iproto = SAS_PROTOCOL_ALL; 1409 1408 iphy->sas_phy.tproto = 0; 1410 - iphy->sas_phy.type = PHY_TYPE_PHYSICAL; 1411 1409 iphy->sas_phy.role = PHY_ROLE_INITIATOR; 1412 1410 iphy->sas_phy.oob_mode = OOB_NOT_CONNECTED; 1413 1411 iphy->sas_phy.linkrate = SAS_LINK_RATE_UNKNOWN;
+1 -1
drivers/scsi/isci/request.c
··· 180 180 cmd_iu->_r_a = 0; 181 181 cmd_iu->_r_b = 0; 182 182 cmd_iu->en_fburst = 0; /* unsupported */ 183 - cmd_iu->task_prio = task->ssp_task.task_prio; 183 + cmd_iu->task_prio = 0; 184 184 cmd_iu->task_attr = task->ssp_task.task_attr; 185 185 cmd_iu->_r_c = 0; 186 186
+7 -5
drivers/scsi/libsas/sas_ata.c
··· 162 162 struct ata_port *ap = qc->ap; 163 163 struct domain_device *dev = ap->private_data; 164 164 struct sas_ha_struct *sas_ha = dev->port->ha; 165 - struct Scsi_Host *host = sas_ha->core.shost; 165 + struct Scsi_Host *host = sas_ha->shost; 166 166 struct sas_internal *i = to_sas_internal(host->transportt); 167 167 168 168 /* TODO: we should try to remove that unlock */ ··· 201 201 task->data_dir = qc->dma_dir; 202 202 } 203 203 task->scatter = qc->sg; 204 - task->ata_task.retry_count = 1; 205 204 qc->lldd_task = task; 206 205 207 206 task->ata_task.use_ncq = ata_is_ncq(qc->tf.protocol); 208 207 task->ata_task.dma_xfer = ata_is_dma(qc->tf.protocol); 208 + 209 + if (qc->flags & ATA_QCFLAG_RESULT_TF) 210 + task->ata_task.return_fis_on_success = 1; 209 211 210 212 if (qc->scsicmd) 211 213 ASSIGN_SAS_TASK(qc->scsicmd, task); ··· 237 235 238 236 static struct sas_internal *dev_to_sas_internal(struct domain_device *dev) 239 237 { 240 - return to_sas_internal(dev->port->ha->core.shost->transportt); 238 + return to_sas_internal(dev->port->ha->shost->transportt); 241 239 } 242 240 243 241 static int sas_get_ata_command_set(struct domain_device *dev) ··· 586 584 int sas_ata_init(struct domain_device *found_dev) 587 585 { 588 586 struct sas_ha_struct *ha = found_dev->port->ha; 589 - struct Scsi_Host *shost = ha->core.shost; 587 + struct Scsi_Host *shost = ha->shost; 590 588 struct ata_host *ata_host; 591 589 struct ata_port *ap; 592 590 int rc; ··· 824 822 struct sas_ha_struct *ha = dev->port->ha; 825 823 826 824 sas_ata_printk(KERN_DEBUG, dev, "dev error handler\n"); 827 - ata_scsi_port_error_handler(ha->core.shost, ap); 825 + ata_scsi_port_error_handler(ha->shost, ap); 828 826 sas_put_device(dev); 829 827 } 830 828
+4 -4
drivers/scsi/libsas/sas_discover.c
··· 170 170 { 171 171 int res = 0; 172 172 struct sas_ha_struct *sas_ha = dev->port->ha; 173 - struct Scsi_Host *shost = sas_ha->core.shost; 173 + struct Scsi_Host *shost = sas_ha->shost; 174 174 struct sas_internal *i = to_sas_internal(shost->transportt); 175 175 176 176 if (!i->dft->lldd_dev_found) ··· 192 192 void sas_notify_lldd_dev_gone(struct domain_device *dev) 193 193 { 194 194 struct sas_ha_struct *sas_ha = dev->port->ha; 195 - struct Scsi_Host *shost = sas_ha->core.shost; 195 + struct Scsi_Host *shost = sas_ha->shost; 196 196 struct sas_internal *i = to_sas_internal(shost->transportt); 197 197 198 198 if (!i->dft->lldd_dev_gone) ··· 234 234 struct domain_device *dev; 235 235 struct sas_discovery_event *ev = to_sas_discovery_event(work); 236 236 struct asd_sas_port *port = ev->port; 237 - struct Scsi_Host *shost = port->ha->core.shost; 237 + struct Scsi_Host *shost = port->ha->shost; 238 238 struct sas_internal *si = to_sas_internal(shost->transportt); 239 239 240 240 clear_bit(DISCE_SUSPEND, &port->disc.pending); ··· 373 373 static void sas_abort_device_scsi_cmds(struct domain_device *dev) 374 374 { 375 375 struct sas_ha_struct *sas_ha = dev->port->ha; 376 - struct Scsi_Host *shost = sas_ha->core.shost; 376 + struct Scsi_Host *shost = sas_ha->shost; 377 377 378 378 if (dev_is_expander(dev->dev_type)) 379 379 return;
+1 -1
drivers/scsi/libsas/sas_expander.c
··· 37 37 int res, retry; 38 38 struct sas_task *task = NULL; 39 39 struct sas_internal *i = 40 - to_sas_internal(dev->port->ha->core.shost->transportt); 40 + to_sas_internal(dev->port->ha->shost->transportt); 41 41 struct sas_ha_struct *ha = dev->port->ha; 42 42 43 43 pm_runtime_get_sync(ha->dev);
+2 -2
drivers/scsi/libsas/sas_host_smp.c
··· 114 114 u8 reg_type, u8 reg_index, u8 reg_count, 115 115 u8 *req_data) 116 116 { 117 - struct sas_internal *i = to_sas_internal(sas_ha->core.shost->transportt); 117 + struct sas_internal *i = to_sas_internal(sas_ha->shost->transportt); 118 118 int written; 119 119 120 120 if (i->dft->lldd_write_gpio == NULL) { ··· 182 182 enum sas_linkrate max, u8 *resp_data) 183 183 { 184 184 struct sas_internal *i = 185 - to_sas_internal(sas_ha->core.shost->transportt); 185 + to_sas_internal(sas_ha->shost->transportt); 186 186 struct sas_phy_linkrates rates; 187 187 struct asd_sas_phy *asd_phy; 188 188
+8 -8
drivers/scsi/libsas/sas_init.c
··· 183 183 struct sas_ha_struct *sas_ha = SHOST_TO_SAS_HA(shost); 184 184 struct asd_sas_phy *asd_phy = sas_ha->sas_phy[phy->number]; 185 185 struct sas_internal *i = 186 - to_sas_internal(sas_ha->core.shost->transportt); 186 + to_sas_internal(sas_ha->shost->transportt); 187 187 188 188 return i->dft->lldd_control_phy(asd_phy, PHY_FUNC_GET_EVENTS, NULL); 189 189 } ··· 232 232 struct sas_ha_struct *sas_ha = SHOST_TO_SAS_HA(shost); 233 233 struct asd_sas_phy *asd_phy = sas_ha->sas_phy[phy->number]; 234 234 struct sas_internal *i = 235 - to_sas_internal(sas_ha->core.shost->transportt); 235 + to_sas_internal(sas_ha->shost->transportt); 236 236 237 237 if (!hard_reset && sas_try_ata_reset(asd_phy) == 0) 238 238 return 0; ··· 266 266 struct sas_ha_struct *sas_ha = SHOST_TO_SAS_HA(shost); 267 267 struct asd_sas_phy *asd_phy = sas_ha->sas_phy[phy->number]; 268 268 struct sas_internal *i = 269 - to_sas_internal(sas_ha->core.shost->transportt); 269 + to_sas_internal(sas_ha->shost->transportt); 270 270 271 271 if (enable) 272 272 ret = transport_sas_phy_reset(phy, 0); ··· 303 303 struct sas_ha_struct *sas_ha = SHOST_TO_SAS_HA(shost); 304 304 struct asd_sas_phy *asd_phy = sas_ha->sas_phy[phy->number]; 305 305 struct sas_internal *i = 306 - to_sas_internal(sas_ha->core.shost->transportt); 306 + to_sas_internal(sas_ha->shost->transportt); 307 307 308 308 ret = i->dft->lldd_control_phy(asd_phy, reset_type, NULL); 309 309 } else { ··· 339 339 struct sas_ha_struct *sas_ha = SHOST_TO_SAS_HA(shost); 340 340 struct asd_sas_phy *asd_phy = sas_ha->sas_phy[phy->number]; 341 341 struct sas_internal *i = 342 - to_sas_internal(sas_ha->core.shost->transportt); 342 + to_sas_internal(sas_ha->shost->transportt); 343 343 344 344 ret = i->dft->lldd_control_phy(asd_phy, PHY_FUNC_SET_LINK_RATE, 345 345 rates); ··· 438 438 /* all phys are back up or timed out, turn on i/o so we can 439 439 * flush out disks that did not return 440 440 */ 441 - scsi_unblock_requests(ha->core.shost); 441 + scsi_unblock_requests(ha->shost); 442 442 if (drain) 443 443 sas_drain_work(ha); 444 444 clear_bit(SAS_HA_RESUMING, &ha->state); ··· 468 468 int i; 469 469 470 470 sas_disable_events(ha); 471 - scsi_block_requests(ha->core.shost); 471 + scsi_block_requests(ha->shost); 472 472 for (i = 0; i < ha->num_phys; i++) { 473 473 struct asd_sas_port *port = ha->sas_port[i]; 474 474 ··· 641 641 struct asd_sas_event *event; 642 642 struct sas_ha_struct *sas_ha = phy->ha; 643 643 struct sas_internal *i = 644 - to_sas_internal(sas_ha->core.shost->transportt); 644 + to_sas_internal(sas_ha->shost->transportt); 645 645 646 646 event = kmem_cache_zalloc(sas_event_cache, gfp_flags); 647 647 if (!event)
-7
drivers/scsi/libsas/sas_internal.h
··· 41 41 42 42 void sas_scsi_recover_host(struct Scsi_Host *shost); 43 43 44 - int sas_show_class(enum sas_class class, char *buf); 45 - int sas_show_proto(enum sas_protocol proto, char *buf); 46 - int sas_show_linkrate(enum sas_linkrate linkrate, char *buf); 47 - int sas_show_oob_mode(enum sas_oob_mode oob_mode, char *buf); 48 - 49 44 int sas_register_phys(struct sas_ha_struct *sas_ha); 50 - void sas_unregister_phys(struct sas_ha_struct *sas_ha); 51 45 52 46 struct asd_sas_event *sas_alloc_event(struct asd_sas_phy *phy, gfp_t gfp_flags); 53 47 void sas_free_event(struct asd_sas_event *event); ··· 85 91 int sas_get_phy_attached_dev(struct domain_device *dev, int phy_id, 86 92 u8 *sas_addr, enum sas_device_type *type); 87 93 int sas_try_ata_reset(struct asd_sas_phy *phy); 88 - void sas_hae_reset(struct work_struct *work); 89 94 90 95 void sas_free_device(struct kref *kref); 91 96 void sas_destruct_devices(struct asd_sas_port *port);
+4 -4
drivers/scsi/libsas/sas_phy.c
··· 38 38 struct sas_ha_struct *sas_ha = phy->ha; 39 39 struct asd_sas_port *port = phy->port; 40 40 struct sas_internal *i = 41 - to_sas_internal(sas_ha->core.shost->transportt); 41 + to_sas_internal(sas_ha->shost->transportt); 42 42 43 43 sas_deform_port(phy, 1); 44 44 ··· 66 66 struct asd_sas_phy *phy = ev->phy; 67 67 struct sas_ha_struct *sas_ha = phy->ha; 68 68 struct sas_internal *i = 69 - to_sas_internal(sas_ha->core.shost->transportt); 69 + to_sas_internal(sas_ha->shost->transportt); 70 70 71 71 phy->error = 0; 72 72 i->dft->lldd_control_phy(phy, PHY_FUNC_RELEASE_SPINUP_HOLD, NULL); ··· 95 95 struct asd_sas_phy *phy = ev->phy; 96 96 struct sas_ha_struct *sas_ha = phy->ha; 97 97 struct sas_internal *i = 98 - to_sas_internal(sas_ha->core.shost->transportt); 98 + to_sas_internal(sas_ha->shost->transportt); 99 99 100 100 if (phy->enabled) { 101 101 int ret; ··· 131 131 spin_lock_init(&phy->sas_prim_lock); 132 132 phy->frame_rcvd_size = 0; 133 133 134 - phy->phy = sas_phy_alloc(&sas_ha->core.shost->shost_gendev, i); 134 + phy->phy = sas_phy_alloc(&sas_ha->shost->shost_gendev, i); 135 135 if (!phy->phy) 136 136 return -ENOMEM; 137 137
+3 -5
drivers/scsi/libsas/sas_port.c
··· 28 28 struct domain_device *dev, *n; 29 29 struct asd_sas_port *port = phy->port; 30 30 struct sas_ha_struct *sas_ha = phy->ha; 31 - struct sas_internal *si = to_sas_internal(sas_ha->core.shost->transportt); 31 + struct sas_internal *si = to_sas_internal(sas_ha->shost->transportt); 32 32 33 33 if (si->dft->lldd_port_formed) 34 34 si->dft->lldd_port_formed(phy); ··· 83 83 memcpy(port->sas_addr, phy->sas_addr, SAS_ADDR_SIZE); 84 84 85 85 if (*(u64 *)port->attached_sas_addr == 0) { 86 - port->class = phy->class; 87 86 memcpy(port->attached_sas_addr, phy->attached_sas_addr, 88 87 SAS_ADDR_SIZE); 89 88 port->iproto = phy->iproto; ··· 108 109 struct asd_sas_port *port = phy->port; 109 110 struct domain_device *port_dev = NULL; 110 111 struct sas_internal *si = 111 - to_sas_internal(sas_ha->core.shost->transportt); 112 + to_sas_internal(sas_ha->shost->transportt); 112 113 unsigned long flags; 113 114 114 115 if (port) { ··· 211 212 struct sas_ha_struct *sas_ha = phy->ha; 212 213 struct asd_sas_port *port = phy->port; 213 214 struct sas_internal *si = 214 - to_sas_internal(sas_ha->core.shost->transportt); 215 + to_sas_internal(sas_ha->shost->transportt); 215 216 struct domain_device *dev; 216 217 unsigned long flags; 217 218 ··· 248 249 INIT_LIST_HEAD(&port->phy_list); 249 250 memset(port->sas_addr, 0, SAS_ADDR_SIZE); 250 251 memset(port->attached_sas_addr, 0, SAS_ADDR_SIZE); 251 - port->class = 0; 252 252 port->iproto = 0; 253 253 port->tproto = 0; 254 254 port->oob_mode = 0;
+7 -8
drivers/scsi/libsas/sas_scsi_host.c
··· 142 142 task->dev = dev; 143 143 task->task_proto = task->dev->tproto; /* BUG_ON(!SSP) */ 144 144 145 - task->ssp_task.retry_count = 1; 146 145 int_to_scsilun(cmd->device->lun, &lun); 147 146 memcpy(task->ssp_task.LUN, &lun.scsi_lun, 8); 148 147 task->ssp_task.task_attr = TASK_ATTR_SIMPLE; ··· 278 279 unsigned long flags; 279 280 int i, res; 280 281 struct sas_internal *si = 281 - to_sas_internal(task->dev->port->ha->core.shost->transportt); 282 + to_sas_internal(task->dev->port->ha->shost->transportt); 282 283 283 284 for (i = 0; i < 5; i++) { 284 285 pr_notice("%s: aborting task 0x%p\n", __func__, task); ··· 326 327 int res = TMF_RESP_FUNC_FAILED; 327 328 struct scsi_lun lun; 328 329 struct sas_internal *i = 329 - to_sas_internal(dev->port->ha->core.shost->transportt); 330 + to_sas_internal(dev->port->ha->shost->transportt); 330 331 331 332 int_to_scsilun(cmd->device->lun, &lun); 332 333 ··· 354 355 { 355 356 int res = TMF_RESP_FUNC_FAILED; 356 357 struct sas_internal *i = 357 - to_sas_internal(dev->port->ha->core.shost->transportt); 358 + to_sas_internal(dev->port->ha->shost->transportt); 358 359 359 360 pr_notice("I_T nexus reset for dev %016llx\n", 360 361 SAS_ADDR(dev->sas_addr)); ··· 409 410 spin_unlock_irq(&ha->lock); 410 411 411 412 /* make sure SCSI EH is complete */ 412 - if (scsi_host_in_recovery(ha->core.shost)) { 413 + if (scsi_host_in_recovery(ha->shost)) { 413 414 msleep(10); 414 415 goto retry; 415 416 } ··· 439 440 set_bit(SAS_DEV_EH_PENDING, &dev->state); 440 441 set_bit(reset_type, &dev->state); 441 442 int_to_scsilun(lun, &dev->ssp_dev.reset_lun); 442 - scsi_schedule_eh(ha->core.shost); 443 + scsi_schedule_eh(ha->shost); 443 444 } 444 445 spin_unlock_irq(&ha->lock); 445 446 ··· 924 925 unsigned int qid, void *data) 925 926 { 926 927 struct sas_ha_struct *ha = device->port->ha; 927 - struct sas_internal *i = to_sas_internal(ha->core.shost->transportt); 928 + struct sas_internal *i = to_sas_internal(ha->shost->transportt); 928 929 struct sas_task *task = NULL; 929 930 int res, retry; 930 931 ··· 1014 1015 { 1015 1016 struct sas_task *task; 1016 1017 struct sas_internal *i = 1017 - to_sas_internal(device->port->ha->core.shost->transportt); 1018 + to_sas_internal(device->port->ha->shost->transportt); 1018 1019 int res, retry; 1019 1020 1020 1021 for (retry = 0; retry < TASK_RETRY; retry++) {
+21 -2
drivers/scsi/lpfc/lpfc.h
··· 309 309 #define LPFC_VMID_TIMER 300 /* timer interval in seconds */ 310 310 311 311 #define LPFC_MAX_VMID_SIZE 256 312 - #define LPFC_COMPRESS_VMID_SIZE 16 313 312 314 313 union lpfc_vmid_io_tag { 315 314 u32 app_id; /* App Id vmid */ ··· 666 667 uint32_t cfg_first_burst_size; 667 668 uint32_t dev_loss_tmo_changed; 668 669 /* VMID parameters */ 669 - u8 lpfc_vmid_host_uuid[LPFC_COMPRESS_VMID_SIZE]; 670 + u8 lpfc_vmid_host_uuid[16]; 670 671 u32 max_vmid; /* maximum VMIDs allowed per port */ 671 672 u32 cur_vmid_cnt; /* Current VMID count */ 672 673 #define LPFC_MIN_VMID 4 ··· 871 872 enum lpfc_hba_bit_flags { 872 873 FABRIC_COMANDS_BLOCKED, 873 874 HBA_PCI_ERR, 875 + MBX_TMO_ERR, 874 876 }; 875 877 876 878 struct lpfc_hba { ··· 1708 1708 1709 1709 return cpu_it; 1710 1710 } 1711 + /** 1712 + * lpfc_next_present_cpu - Finds next present CPU after n 1713 + * @n: the cpu prior to search 1714 + * 1715 + * Note: If no next present cpu, then fallback to first present cpu. 1716 + * 1717 + **/ 1718 + static inline unsigned int lpfc_next_present_cpu(int n) 1719 + { 1720 + unsigned int cpu; 1721 + 1722 + cpu = cpumask_next(n, cpu_present_mask); 1723 + 1724 + if (cpu >= nr_cpu_ids) 1725 + cpu = cpumask_first(cpu_present_mask); 1726 + 1727 + return cpu; 1728 + } 1729 + 1711 1730 /** 1712 1731 * lpfc_sli4_mod_hba_eq_delay - update EQ delay 1713 1732 * @phba: Pointer to HBA context object.
+101 -35
drivers/scsi/lpfc/lpfc_attr.c
··· 2127 2127 uint32_t *mrpi, uint32_t *arpi, 2128 2128 uint32_t *mvpi, uint32_t *avpi) 2129 2129 { 2130 - struct lpfc_mbx_read_config *rd_config; 2131 2130 LPFC_MBOXQ_t *pmboxq; 2132 2131 MAILBOX_t *pmb; 2133 2132 int rc = 0; 2134 - uint32_t max_vpi; 2133 + struct lpfc_sli4_hba *sli4_hba; 2134 + struct lpfc_max_cfg_param *max_cfg_param; 2135 + u16 rsrc_ext_cnt, rsrc_ext_size, max_vpi; 2135 2136 2136 2137 /* 2137 2138 * prevent udev from issuing mailbox commands until the port is ··· 2168 2167 } 2169 2168 2170 2169 if (phba->sli_rev == LPFC_SLI_REV4) { 2171 - rd_config = &pmboxq->u.mqe.un.rd_config; 2172 - if (mrpi) 2173 - *mrpi = bf_get(lpfc_mbx_rd_conf_rpi_count, rd_config); 2174 - if (arpi) 2175 - *arpi = bf_get(lpfc_mbx_rd_conf_rpi_count, rd_config) - 2176 - phba->sli4_hba.max_cfg_param.rpi_used; 2177 - if (mxri) 2178 - *mxri = bf_get(lpfc_mbx_rd_conf_xri_count, rd_config); 2179 - if (axri) 2180 - *axri = bf_get(lpfc_mbx_rd_conf_xri_count, rd_config) - 2181 - phba->sli4_hba.max_cfg_param.xri_used; 2170 + sli4_hba = &phba->sli4_hba; 2171 + max_cfg_param = &sli4_hba->max_cfg_param; 2182 2172 2183 - /* Account for differences with SLI-3. Get vpi count from 2184 - * mailbox data and subtract one for max vpi value. 2185 - */ 2186 - max_vpi = (bf_get(lpfc_mbx_rd_conf_vpi_count, rd_config) > 0) ? 2187 - (bf_get(lpfc_mbx_rd_conf_vpi_count, rd_config) - 1) : 0; 2173 + /* Normally, extents are not used */ 2174 + if (!phba->sli4_hba.extents_in_use) { 2175 + if (mrpi) 2176 + *mrpi = max_cfg_param->max_rpi; 2177 + if (mxri) 2178 + *mxri = max_cfg_param->max_xri; 2179 + if (mvpi) { 2180 + max_vpi = max_cfg_param->max_vpi; 2188 2181 2189 - /* Limit the max we support */ 2190 - if (max_vpi > LPFC_MAX_VPI) 2191 - max_vpi = LPFC_MAX_VPI; 2192 - if (mvpi) 2193 - *mvpi = max_vpi; 2194 - if (avpi) 2195 - *avpi = max_vpi - phba->sli4_hba.max_cfg_param.vpi_used; 2182 + /* Limit the max we support */ 2183 + if (max_vpi > LPFC_MAX_VPI) 2184 + max_vpi = LPFC_MAX_VPI; 2185 + *mvpi = max_vpi; 2186 + } 2187 + } else { /* Extents in use */ 2188 + if (mrpi) { 2189 + if (lpfc_sli4_get_avail_extnt_rsrc(phba, 2190 + LPFC_RSC_TYPE_FCOE_RPI, 2191 + &rsrc_ext_cnt, 2192 + &rsrc_ext_size)) { 2193 + rc = 0; 2194 + goto free_pmboxq; 2195 + } 2196 + 2197 + *mrpi = rsrc_ext_cnt * rsrc_ext_size; 2198 + } 2199 + 2200 + if (mxri) { 2201 + if (lpfc_sli4_get_avail_extnt_rsrc(phba, 2202 + LPFC_RSC_TYPE_FCOE_XRI, 2203 + &rsrc_ext_cnt, 2204 + &rsrc_ext_size)) { 2205 + rc = 0; 2206 + goto free_pmboxq; 2207 + } 2208 + 2209 + *mxri = rsrc_ext_cnt * rsrc_ext_size; 2210 + } 2211 + 2212 + if (mvpi) { 2213 + if (lpfc_sli4_get_avail_extnt_rsrc(phba, 2214 + LPFC_RSC_TYPE_FCOE_VPI, 2215 + &rsrc_ext_cnt, 2216 + &rsrc_ext_size)) { 2217 + rc = 0; 2218 + goto free_pmboxq; 2219 + } 2220 + 2221 + max_vpi = rsrc_ext_cnt * rsrc_ext_size; 2222 + 2223 + /* Limit the max we support */ 2224 + if (max_vpi > LPFC_MAX_VPI) 2225 + max_vpi = LPFC_MAX_VPI; 2226 + *mvpi = max_vpi; 2227 + } 2228 + } 2196 2229 } else { 2197 2230 if (mrpi) 2198 2231 *mrpi = pmb->un.varRdConfig.max_rpi; ··· 2247 2212 } 2248 2213 } 2249 2214 2215 + /* Success */ 2216 + rc = 1; 2217 + 2218 + free_pmboxq: 2250 2219 mempool_free(pmboxq, phba->mbox_mem_pool); 2251 - return 1; 2220 + return rc; 2252 2221 } 2253 2222 2254 2223 /** ··· 2304 2265 struct Scsi_Host *shost = class_to_shost(dev); 2305 2266 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; 2306 2267 struct lpfc_hba *phba = vport->phba; 2307 - uint32_t cnt, acnt; 2268 + struct lpfc_sli4_hba *sli4_hba; 2269 + struct lpfc_max_cfg_param *max_cfg_param; 2270 + u32 cnt = 0, acnt = 0; 2308 2271 2309 - if (lpfc_get_hba_info(phba, NULL, NULL, &cnt, &acnt, NULL, NULL)) 2310 - return scnprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt)); 2272 + if (phba->sli_rev == LPFC_SLI_REV4) { 2273 + sli4_hba = &phba->sli4_hba; 2274 + max_cfg_param = &sli4_hba->max_cfg_param; 2275 + return scnprintf(buf, PAGE_SIZE, "%d\n", 2276 + max_cfg_param->rpi_used); 2277 + } else { 2278 + if (lpfc_get_hba_info(phba, NULL, NULL, &cnt, &acnt, NULL, NULL)) 2279 + return scnprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt)); 2280 + } 2311 2281 return scnprintf(buf, PAGE_SIZE, "Unknown\n"); 2312 2282 } 2313 2283 ··· 2369 2321 struct Scsi_Host *shost = class_to_shost(dev); 2370 2322 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; 2371 2323 struct lpfc_hba *phba = vport->phba; 2372 - uint32_t cnt, acnt; 2324 + struct lpfc_sli4_hba *sli4_hba; 2325 + struct lpfc_max_cfg_param *max_cfg_param; 2326 + u32 cnt = 0, acnt = 0; 2373 2327 2374 - if (lpfc_get_hba_info(phba, &cnt, &acnt, NULL, NULL, NULL, NULL)) 2375 - return scnprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt)); 2328 + if (phba->sli_rev == LPFC_SLI_REV4) { 2329 + sli4_hba = &phba->sli4_hba; 2330 + max_cfg_param = &sli4_hba->max_cfg_param; 2331 + return scnprintf(buf, PAGE_SIZE, "%d\n", 2332 + max_cfg_param->xri_used); 2333 + } else { 2334 + if (lpfc_get_hba_info(phba, &cnt, &acnt, NULL, NULL, NULL, NULL)) 2335 + return scnprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt)); 2336 + } 2376 2337 return scnprintf(buf, PAGE_SIZE, "Unknown\n"); 2377 2338 } 2378 2339 ··· 2434 2377 struct Scsi_Host *shost = class_to_shost(dev); 2435 2378 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; 2436 2379 struct lpfc_hba *phba = vport->phba; 2437 - uint32_t cnt, acnt; 2380 + struct lpfc_sli4_hba *sli4_hba; 2381 + struct lpfc_max_cfg_param *max_cfg_param; 2382 + u32 cnt = 0, acnt = 0; 2438 2383 2439 - if (lpfc_get_hba_info(phba, NULL, NULL, NULL, NULL, &cnt, &acnt)) 2440 - return scnprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt)); 2384 + if (phba->sli_rev == LPFC_SLI_REV4) { 2385 + sli4_hba = &phba->sli4_hba; 2386 + max_cfg_param = &sli4_hba->max_cfg_param; 2387 + return scnprintf(buf, PAGE_SIZE, "%d\n", 2388 + max_cfg_param->vpi_used); 2389 + } else { 2390 + if (lpfc_get_hba_info(phba, NULL, NULL, NULL, NULL, &cnt, &acnt)) 2391 + return scnprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt)); 2392 + } 2441 2393 return scnprintf(buf, PAGE_SIZE, "Unknown\n"); 2442 2394 } 2443 2395
+14 -6
drivers/scsi/lpfc/lpfc_ct.c
··· 1557 1557 ndlp->nlp_fc4_type |= NLP_FC4_FCP; 1558 1558 if (fc4_data_1 & LPFC_FC4_TYPE_BITMASK) 1559 1559 ndlp->nlp_fc4_type |= NLP_FC4_NVME; 1560 - lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, 1560 + lpfc_printf_vlog(vport, KERN_INFO, 1561 + LOG_DISCOVERY | LOG_NODE, 1561 1562 "3064 Setting ndlp x%px, DID x%06x " 1562 1563 "with FC4 x%08x, Data: x%08x x%08x " 1563 1564 "%d\n", ··· 1569 1568 if (ndlp->nlp_state == NLP_STE_REG_LOGIN_ISSUE && 1570 1569 ndlp->nlp_fc4_type) { 1571 1570 ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE; 1572 - 1573 - lpfc_nlp_set_state(vport, ndlp, 1574 - NLP_STE_PRLI_ISSUE); 1575 - lpfc_issue_els_prli(vport, ndlp, 0); 1571 + /* This is a fabric topology so if discovery 1572 + * started with an unsolicited PLOGI, don't 1573 + * send a PRLI. Targets don't issue PLOGI or 1574 + * PRLI when acting as a target. Likely this is 1575 + * an initiator function. 1576 + */ 1577 + if (!(ndlp->nlp_flag & NLP_RCV_PLOGI)) { 1578 + lpfc_nlp_set_state(vport, ndlp, 1579 + NLP_STE_PRLI_ISSUE); 1580 + lpfc_issue_els_prli(vport, ndlp, 0); 1581 + } 1576 1582 } else if (!ndlp->nlp_fc4_type) { 1577 1583 /* If fc4 type is still unknown, then LOGO */ 1578 1584 lpfc_printf_vlog(vport, KERN_INFO, 1579 - LOG_DISCOVERY, 1585 + LOG_DISCOVERY | LOG_NODE, 1580 1586 "6443 Sending LOGO ndlp x%px," 1581 1587 "DID x%06x with fc4_type: " 1582 1588 "x%08x, state: %d\n",
+49 -21
drivers/scsi/lpfc/lpfc_els.c
··· 1041 1041 !(ndlp->fc4_xpt_flags & SCSI_XPT_REGD)) 1042 1042 lpfc_nlp_put(ndlp); 1043 1043 1044 - lpfc_printf_vlog(vport, KERN_WARNING, LOG_TRACE_EVENT, 1044 + lpfc_printf_vlog(vport, KERN_WARNING, LOG_ELS, 1045 1045 "0150 FLOGI failure Status:x%x/x%x " 1046 1046 "xri x%x TMO:x%x refcnt %d\n", 1047 1047 ulp_status, ulp_word4, cmdiocb->sli4_xritag, ··· 1091 1091 if (!lpfc_error_lost_link(vport, ulp_status, ulp_word4)) 1092 1092 lpfc_issue_reg_vfi(vport); 1093 1093 1094 - lpfc_nlp_put(ndlp); 1095 1094 goto out; 1096 1095 } 1097 1096 goto flogifail; ··· 1331 1332 if (phba->cfg_vmid_priority_tagging) { 1332 1333 sp->cmn.priority_tagging = 1; 1333 1334 /* lpfc_vmid_host_uuid is combination of wwpn and wwnn */ 1334 - if (uuid_is_null((uuid_t *)vport->lpfc_vmid_host_uuid)) { 1335 + if (!memchr_inv(vport->lpfc_vmid_host_uuid, 0, 1336 + sizeof(vport->lpfc_vmid_host_uuid))) { 1335 1337 memcpy(vport->lpfc_vmid_host_uuid, phba->wwpn, 1336 1338 sizeof(phba->wwpn)); 1337 1339 memcpy(&vport->lpfc_vmid_host_uuid[8], phba->wwnn, ··· 2377 2377 /* PRLI failed */ 2378 2378 lpfc_printf_vlog(vport, mode, loglevel, 2379 2379 "2754 PRLI failure DID:%06X Status:x%x/x%x, " 2380 - "data: x%x x%x\n", 2380 + "data: x%x x%x x%x\n", 2381 2381 ndlp->nlp_DID, ulp_status, 2382 2382 ulp_word4, ndlp->nlp_state, 2383 - ndlp->fc4_prli_sent); 2383 + ndlp->fc4_prli_sent, ndlp->nlp_flag); 2384 2384 2385 2385 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */ 2386 2386 if (!lpfc_error_lost_link(vport, ulp_status, ulp_word4)) ··· 2391 2391 * mismatch typically caused by an RSCN. Skip any 2392 2392 * processing to allow recovery. 2393 2393 */ 2394 - if (ndlp->nlp_state >= NLP_STE_PLOGI_ISSUE && 2395 - ndlp->nlp_state <= NLP_STE_REG_LOGIN_ISSUE) { 2394 + if ((ndlp->nlp_state >= NLP_STE_PLOGI_ISSUE && 2395 + ndlp->nlp_state <= NLP_STE_REG_LOGIN_ISSUE) || 2396 + (ndlp->nlp_state == NLP_STE_NPR_NODE && 2397 + ndlp->nlp_flag & NLP_DELAY_TMO)) { 2396 2398 lpfc_printf_vlog(vport, KERN_WARNING, LOG_NODE, 2397 - "2784 PRLI cmpl: state mismatch " 2399 + "2784 PRLI cmpl: Allow Node recovery " 2398 2400 "DID x%06x nstate x%x nflag x%x\n", 2399 2401 ndlp->nlp_DID, ndlp->nlp_state, 2400 2402 ndlp->nlp_flag); 2401 - goto out; 2403 + goto out; 2402 2404 } 2403 2405 2404 2406 /* ··· 6168 6166 npr->TaskRetryIdReq = 1; 6169 6167 } 6170 6168 npr->acceptRspCode = PRLI_REQ_EXECUTED; 6171 - npr->estabImagePair = 1; 6169 + 6170 + /* Set image pair for complementary pairs only. */ 6171 + if (ndlp->nlp_type & NLP_FCP_TARGET) 6172 + npr->estabImagePair = 1; 6173 + else 6174 + npr->estabImagePair = 0; 6172 6175 npr->readXferRdyDis = 1; 6173 6176 npr->ConfmComplAllowed = 1; 6174 6177 npr->prliType = PRLI_FCP_TYPE; 6175 6178 npr->initiatorFunc = 1; 6179 + 6180 + /* Xmit PRLI ACC response tag <ulpIoTag> */ 6181 + lpfc_printf_vlog(vport, KERN_INFO, 6182 + LOG_ELS | LOG_NODE | LOG_DISCOVERY, 6183 + "6014 FCP issue PRLI ACC imgpair %d " 6184 + "retry %d task %d\n", 6185 + npr->estabImagePair, 6186 + npr->Retry, npr->TaskRetryIdReq); 6187 + 6176 6188 } else if (prli_fc4_req == PRLI_NVME_TYPE) { 6177 6189 /* Respond with an NVME PRLI Type */ 6178 6190 npr_nvme = (struct lpfc_nvme_prli *) pcmd; ··· 9604 9588 lpfc_els_flush_cmd(struct lpfc_vport *vport) 9605 9589 { 9606 9590 LIST_HEAD(abort_list); 9591 + LIST_HEAD(cancel_list); 9607 9592 struct lpfc_hba *phba = vport->phba; 9608 9593 struct lpfc_sli_ring *pring; 9609 9594 struct lpfc_iocbq *tmp_iocb, *piocb; 9610 9595 u32 ulp_command; 9611 9596 unsigned long iflags = 0; 9597 + bool mbx_tmo_err; 9612 9598 9613 9599 lpfc_fabric_abort_vport(vport); 9614 9600 ··· 9632 9614 if (phba->sli_rev == LPFC_SLI_REV4) 9633 9615 spin_lock(&pring->ring_lock); 9634 9616 9617 + mbx_tmo_err = test_bit(MBX_TMO_ERR, &phba->bit_flags); 9635 9618 /* First we need to issue aborts to outstanding cmds on txcmpl */ 9636 9619 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) { 9637 - if (piocb->cmd_flag & LPFC_IO_LIBDFC) 9620 + if (piocb->cmd_flag & LPFC_IO_LIBDFC && !mbx_tmo_err) 9638 9621 continue; 9639 9622 9640 9623 if (piocb->vport != vport) 9641 9624 continue; 9642 9625 9643 - if (piocb->cmd_flag & LPFC_DRIVER_ABORTED) 9626 + if (piocb->cmd_flag & LPFC_DRIVER_ABORTED && !mbx_tmo_err) 9644 9627 continue; 9645 9628 9646 9629 /* On the ELS ring we can have ELS_REQUESTs or ··· 9660 9641 */ 9661 9642 if (phba->link_state == LPFC_LINK_DOWN) 9662 9643 piocb->cmd_cmpl = lpfc_cmpl_els_link_down; 9663 - } 9664 - if (ulp_command == CMD_GEN_REQUEST64_CR) 9644 + } else if (ulp_command == CMD_GEN_REQUEST64_CR || 9645 + mbx_tmo_err) 9665 9646 list_add_tail(&piocb->dlist, &abort_list); 9666 9647 } 9667 9648 ··· 9673 9654 list_for_each_entry_safe(piocb, tmp_iocb, &abort_list, dlist) { 9674 9655 spin_lock_irqsave(&phba->hbalock, iflags); 9675 9656 list_del_init(&piocb->dlist); 9676 - lpfc_sli_issue_abort_iotag(phba, pring, piocb, NULL); 9657 + if (mbx_tmo_err) 9658 + list_move_tail(&piocb->list, &cancel_list); 9659 + else 9660 + lpfc_sli_issue_abort_iotag(phba, pring, piocb, NULL); 9661 + 9677 9662 spin_unlock_irqrestore(&phba->hbalock, iflags); 9678 9663 } 9679 - /* Make sure HBA is alive */ 9680 - lpfc_issue_hb_tmo(phba); 9664 + if (!list_empty(&cancel_list)) 9665 + lpfc_sli_cancel_iocbs(phba, &cancel_list, IOSTAT_LOCAL_REJECT, 9666 + IOERR_SLI_ABORTED); 9667 + else 9668 + /* Make sure HBA is alive */ 9669 + lpfc_issue_hb_tmo(phba); 9681 9670 9682 9671 if (!list_empty(&abort_list)) 9683 9672 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT, ··· 12358 12331 elsiocb->vmid_tag.vmid_context = vmid_context; 12359 12332 pcmd = (u8 *)elsiocb->cmd_dmabuf->virt; 12360 12333 12361 - if (uuid_is_null((uuid_t *)vport->lpfc_vmid_host_uuid)) 12334 + if (!memchr_inv(vport->lpfc_vmid_host_uuid, 0, 12335 + sizeof(vport->lpfc_vmid_host_uuid))) 12362 12336 memcpy(vport->lpfc_vmid_host_uuid, vmid->host_vmid, 12363 - LPFC_COMPRESS_VMID_SIZE); 12337 + sizeof(vport->lpfc_vmid_host_uuid)); 12364 12338 12365 12339 *((u32 *)(pcmd)) = ELS_CMD_UVEM; 12366 12340 len = (u32 *)(pcmd + 4); ··· 12371 12343 vem_id_desc->tag = be32_to_cpu(VEM_ID_DESC_TAG); 12372 12344 vem_id_desc->length = be32_to_cpu(LPFC_UVEM_VEM_ID_DESC_SIZE); 12373 12345 memcpy(vem_id_desc->vem_id, vport->lpfc_vmid_host_uuid, 12374 - LPFC_COMPRESS_VMID_SIZE); 12346 + sizeof(vem_id_desc->vem_id)); 12375 12347 12376 12348 inst_desc = (struct instantiated_ve_desc *)(pcmd + 32); 12377 12349 inst_desc->tag = be32_to_cpu(INSTANTIATED_VE_DESC_TAG); 12378 12350 inst_desc->length = be32_to_cpu(LPFC_UVEM_VE_MAP_DESC_SIZE); 12379 12351 memcpy(inst_desc->global_vem_id, vmid->host_vmid, 12380 - LPFC_COMPRESS_VMID_SIZE); 12352 + sizeof(inst_desc->global_vem_id)); 12381 12353 12382 12354 bf_set(lpfc_instantiated_nport_id, inst_desc, vport->fc_myDID); 12383 12355 bf_set(lpfc_instantiated_local_id, inst_desc,
+52 -25
drivers/scsi/lpfc/lpfc_hbadisc.c
··· 169 169 170 170 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_NODE, 171 171 "3181 dev_loss_callbk x%06x, rport x%px flg x%x " 172 - "load_flag x%x refcnt %d state %d xpt x%x\n", 172 + "load_flag x%x refcnt %u state %d xpt x%x\n", 173 173 ndlp->nlp_DID, ndlp->rport, ndlp->nlp_flag, 174 174 vport->load_flag, kref_read(&ndlp->kref), 175 175 ndlp->nlp_state, ndlp->fc4_xpt_flags); 176 176 177 - /* Don't schedule a worker thread event if the vport is going down. 178 - * The teardown process cleans up the node via lpfc_drop_node. 179 - */ 177 + /* Don't schedule a worker thread event if the vport is going down. */ 180 178 if (vport->load_flag & FC_UNLOADING) { 181 - ((struct lpfc_rport_data *)rport->dd_data)->pnode = NULL; 179 + spin_lock_irqsave(&ndlp->lock, iflags); 182 180 ndlp->rport = NULL; 183 181 184 - ndlp->fc4_xpt_flags &= ~SCSI_XPT_REGD; 185 - /* clear the NLP_XPT_REGD if the node is not registered 186 - * with nvme-fc 182 + /* The scsi_transport is done with the rport so lpfc cannot 183 + * call to unregister. Remove the scsi transport reference 184 + * and clean up the SCSI transport node details. 187 185 */ 188 - if (ndlp->fc4_xpt_flags == NLP_XPT_REGD) 189 - ndlp->fc4_xpt_flags &= ~NLP_XPT_REGD; 186 + if (ndlp->fc4_xpt_flags & (NLP_XPT_REGD | SCSI_XPT_REGD)) { 187 + ndlp->fc4_xpt_flags &= ~SCSI_XPT_REGD; 190 188 191 - /* Remove the node reference from remote_port_add now. 192 - * The driver will not call remote_port_delete. 189 + /* NVME transport-registered rports need the 190 + * NLP_XPT_REGD flag to complete an unregister. 191 + */ 192 + if (!(ndlp->fc4_xpt_flags & NVME_XPT_REGD)) 193 + ndlp->fc4_xpt_flags &= ~NLP_XPT_REGD; 194 + spin_unlock_irqrestore(&ndlp->lock, iflags); 195 + lpfc_nlp_put(ndlp); 196 + spin_lock_irqsave(&ndlp->lock, iflags); 197 + } 198 + 199 + /* Only 1 thread can drop the initial node reference. If 200 + * another thread has set NLP_DROPPED, this thread is done. 193 201 */ 194 - lpfc_nlp_put(ndlp); 202 + if (!(ndlp->nlp_flag & NLP_DROPPED)) { 203 + ndlp->nlp_flag |= NLP_DROPPED; 204 + spin_unlock_irqrestore(&ndlp->lock, iflags); 205 + lpfc_nlp_put(ndlp); 206 + spin_lock_irqsave(&ndlp->lock, iflags); 207 + } 208 + 209 + spin_unlock_irqrestore(&ndlp->lock, iflags); 195 210 return; 196 211 } 197 212 ··· 4701 4686 spin_lock_irqsave(&ndlp->lock, iflags); 4702 4687 if (!(ndlp->fc4_xpt_flags & NLP_XPT_REGD)) { 4703 4688 spin_unlock_irqrestore(&ndlp->lock, iflags); 4704 - lpfc_printf_vlog(vport, KERN_INFO, LOG_SLI, 4689 + lpfc_printf_vlog(vport, KERN_INFO, 4690 + LOG_ELS | LOG_NODE | LOG_DISCOVERY, 4705 4691 "0999 %s Not regd: ndlp x%px rport x%px DID " 4706 4692 "x%x FLG x%x XPT x%x\n", 4707 4693 __func__, ndlp, ndlp->rport, ndlp->nlp_DID, ··· 4718 4702 vport->phba->nport_event_cnt++; 4719 4703 lpfc_unregister_remote_port(ndlp); 4720 4704 } else if (!ndlp->rport) { 4721 - lpfc_printf_vlog(vport, KERN_INFO, LOG_SLI, 4705 + lpfc_printf_vlog(vport, KERN_INFO, 4706 + LOG_ELS | LOG_NODE | LOG_DISCOVERY, 4722 4707 "1999 %s NDLP in devloss x%px DID x%x FLG x%x" 4723 - " XPT x%x refcnt %d\n", 4708 + " XPT x%x refcnt %u\n", 4724 4709 __func__, ndlp, ndlp->nlp_DID, ndlp->nlp_flag, 4725 4710 ndlp->fc4_xpt_flags, 4726 4711 kref_read(&ndlp->kref)); ··· 4971 4954 { 4972 4955 /* 4973 4956 * Use of lpfc_drop_node and UNUSED list: lpfc_drop_node should 4974 - * be used if we wish to issue the "last" lpfc_nlp_put() to remove 4975 - * the ndlp from the vport. The ndlp marked as UNUSED on the list 4976 - * until ALL other outstanding threads have completed. We check 4977 - * that the ndlp not already in the UNUSED state before we proceed. 4957 + * be used when lpfc wants to remove the "last" lpfc_nlp_put() to 4958 + * release the ndlp from the vport when conditions are correct. 4978 4959 */ 4979 4960 if (ndlp->nlp_state == NLP_STE_UNUSED_NODE) 4980 4961 return; 4981 4962 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNUSED_NODE); 4982 - ndlp->nlp_flag |= NLP_DROPPED; 4983 4963 if (vport->phba->sli_rev == LPFC_SLI_REV4) { 4984 4964 lpfc_cleanup_vports_rrqs(vport, ndlp); 4985 4965 lpfc_unreg_rpi(vport, ndlp); 4986 4966 } 4987 4967 4988 - lpfc_nlp_put(ndlp); 4989 - return; 4968 + /* NLP_DROPPED means another thread already removed the initial 4969 + * reference from lpfc_nlp_init. If set, don't drop it again and 4970 + * introduce an imbalance. 4971 + */ 4972 + spin_lock_irq(&ndlp->lock); 4973 + if (!(ndlp->nlp_flag & NLP_DROPPED)) { 4974 + ndlp->nlp_flag |= NLP_DROPPED; 4975 + spin_unlock_irq(&ndlp->lock); 4976 + lpfc_nlp_put(ndlp); 4977 + return; 4978 + } 4979 + spin_unlock_irq(&ndlp->lock); 4990 4980 } 4991 4981 4992 4982 /* ··· 5781 5757 (NLP_FCP_TARGET | NLP_NVME_TARGET))) 5782 5758 return NULL; 5783 5759 5784 - lpfc_disc_state_machine(vport, ndlp, NULL, 5785 - NLP_EVT_DEVICE_RECOVERY); 5760 + if (ndlp->nlp_state > NLP_STE_UNUSED_NODE && 5761 + ndlp->nlp_state < NLP_STE_PRLI_ISSUE) { 5762 + lpfc_disc_state_machine(vport, ndlp, NULL, 5763 + NLP_EVT_DEVICE_RECOVERY); 5764 + } 5786 5765 5787 5766 spin_lock_irq(&ndlp->lock); 5788 5767 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
+2
drivers/scsi/lpfc/lpfc_hw.h
··· 764 764 #define PRLI_PREDEF_CONFIG 0x5 765 765 #define PRLI_PARTIAL_SUCCESS 0x6 766 766 #define PRLI_INVALID_PAGE_CNT 0x7 767 + #define PRLI_INV_SRV_PARM 0x8 768 + 767 769 uint8_t word0Reserved3; /* FC Parm Word 0, bit 0:7 */ 768 770 769 771 uint32_t origProcAssoc; /* FC Parm Word 1, bit 0:31 */
+25 -28
drivers/scsi/lpfc/lpfc_init.c
··· 2123 2123 en_rn_msg = false; 2124 2124 } else if (reg_err1 == SLIPORT_ERR1_REG_ERR_CODE_2 && 2125 2125 reg_err2 == SLIPORT_ERR2_REG_FORCED_DUMP) 2126 - lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, 2126 + lpfc_printf_log(phba, KERN_ERR, LOG_SLI, 2127 2127 "3144 Port Down: Debug Dump\n"); 2128 2128 else if (reg_err1 == SLIPORT_ERR1_REG_ERR_CODE_2 && 2129 2129 reg_err2 == SLIPORT_ERR2_REG_FUNC_PROVISON) ··· 7550 7550 void 7551 7551 lpfc_reset_hba(struct lpfc_hba *phba) 7552 7552 { 7553 + int rc = 0; 7554 + 7553 7555 /* If resets are disabled then set error state and return. */ 7554 7556 if (!phba->cfg_enable_hba_reset) { 7555 7557 phba->link_state = LPFC_HBA_ERROR; ··· 7562 7560 if (phba->sli.sli_flag & LPFC_SLI_ACTIVE) { 7563 7561 lpfc_offline_prep(phba, LPFC_MBX_WAIT); 7564 7562 } else { 7563 + if (test_bit(MBX_TMO_ERR, &phba->bit_flags)) { 7564 + /* Perform a PCI function reset to start from clean */ 7565 + rc = lpfc_pci_function_reset(phba); 7566 + lpfc_els_flush_all_cmd(phba); 7567 + } 7565 7568 lpfc_offline_prep(phba, LPFC_MBX_NO_WAIT); 7566 7569 lpfc_sli_flush_io_rings(phba); 7567 7570 } 7568 7571 lpfc_offline(phba); 7569 - lpfc_sli_brdrestart(phba); 7570 - lpfc_online(phba); 7571 - lpfc_unblock_mgmt_io(phba); 7572 + clear_bit(MBX_TMO_ERR, &phba->bit_flags); 7573 + if (unlikely(rc)) { 7574 + lpfc_printf_log(phba, KERN_ERR, LOG_SLI, 7575 + "8888 PCI function reset failed rc %x\n", 7576 + rc); 7577 + } else { 7578 + lpfc_sli_brdrestart(phba); 7579 + lpfc_online(phba); 7580 + lpfc_unblock_mgmt_io(phba); 7581 + } 7572 7582 } 7573 7583 7574 7584 /** ··· 12512 12498 (new_cpup->eq != LPFC_VECTOR_MAP_EMPTY) && 12513 12499 (new_cpup->phys_id == cpup->phys_id)) 12514 12500 goto found_same; 12515 - new_cpu = cpumask_next( 12516 - new_cpu, cpu_present_mask); 12517 - if (new_cpu >= nr_cpu_ids) 12518 - new_cpu = first_cpu; 12501 + new_cpu = lpfc_next_present_cpu(new_cpu); 12519 12502 } 12520 12503 /* At this point, we leave the CPU as unassigned */ 12521 12504 continue; ··· 12524 12513 * chance of having multiple unassigned CPU entries 12525 12514 * selecting the same IRQ. 12526 12515 */ 12527 - start_cpu = cpumask_next(new_cpu, cpu_present_mask); 12528 - if (start_cpu >= nr_cpu_ids) 12529 - start_cpu = first_cpu; 12516 + start_cpu = lpfc_next_present_cpu(new_cpu); 12530 12517 12531 12518 lpfc_printf_log(phba, KERN_INFO, LOG_INIT, 12532 12519 "3337 Set Affinity: CPU %d " ··· 12557 12548 if (!(new_cpup->flag & LPFC_CPU_MAP_UNASSIGN) && 12558 12549 (new_cpup->eq != LPFC_VECTOR_MAP_EMPTY)) 12559 12550 goto found_any; 12560 - new_cpu = cpumask_next( 12561 - new_cpu, cpu_present_mask); 12562 - if (new_cpu >= nr_cpu_ids) 12563 - new_cpu = first_cpu; 12551 + new_cpu = lpfc_next_present_cpu(new_cpu); 12564 12552 } 12565 12553 /* We should never leave an entry unassigned */ 12566 12554 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, ··· 12573 12567 * chance of having multiple unassigned CPU entries 12574 12568 * selecting the same IRQ. 12575 12569 */ 12576 - start_cpu = cpumask_next(new_cpu, cpu_present_mask); 12577 - if (start_cpu >= nr_cpu_ids) 12578 - start_cpu = first_cpu; 12570 + start_cpu = lpfc_next_present_cpu(new_cpu); 12579 12571 12580 12572 lpfc_printf_log(phba, KERN_INFO, LOG_INIT, 12581 12573 "3338 Set Affinity: CPU %d " ··· 12644 12640 new_cpup->core_id == cpup->core_id) { 12645 12641 goto found_hdwq; 12646 12642 } 12647 - new_cpu = cpumask_next(new_cpu, cpu_present_mask); 12648 - if (new_cpu >= nr_cpu_ids) 12649 - new_cpu = first_cpu; 12643 + new_cpu = lpfc_next_present_cpu(new_cpu); 12650 12644 } 12651 12645 12652 12646 /* If we can't match both phys_id and core_id, ··· 12656 12654 if (new_cpup->hdwq != LPFC_VECTOR_MAP_EMPTY && 12657 12655 new_cpup->phys_id == cpup->phys_id) 12658 12656 goto found_hdwq; 12659 - 12660 - new_cpu = cpumask_next(new_cpu, cpu_present_mask); 12661 - if (new_cpu >= nr_cpu_ids) 12662 - new_cpu = first_cpu; 12657 + new_cpu = lpfc_next_present_cpu(new_cpu); 12663 12658 } 12664 12659 12665 12660 /* Otherwise just round robin on cfg_hdw_queue */ ··· 12665 12666 goto logit; 12666 12667 found_hdwq: 12667 12668 /* We found an available entry, copy the IRQ info */ 12668 - start_cpu = cpumask_next(new_cpu, cpu_present_mask); 12669 - if (start_cpu >= nr_cpu_ids) 12670 - start_cpu = first_cpu; 12669 + start_cpu = lpfc_next_present_cpu(new_cpu); 12671 12670 cpup->hdwq = new_cpup->hdwq; 12672 12671 logit: 12673 12672 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
+54 -40
drivers/scsi/lpfc/lpfc_nportdisc.c
··· 1 1 /******************************************************************* 2 2 * This file is part of the Emulex Linux Device Driver for * 3 3 * Fibre Channel Host Bus Adapters. * 4 - * Copyright (C) 2017-2022 Broadcom. All Rights Reserved. The term * 4 + * Copyright (C) 2017-2023 Broadcom. All Rights Reserved. The term * 5 5 * “Broadcom” refers to Broadcom Inc. and/or its subsidiaries. * 6 6 * Copyright (C) 2004-2016 Emulex. All rights reserved. * 7 7 * EMULEX and SLI are trademarks of Emulex. * ··· 879 879 spin_unlock_irq(shost->host_lock); 880 880 lpfc_retry_pport_discovery(phba); 881 881 } 882 - } else if ((!(ndlp->nlp_type & NLP_FABRIC) && 883 - ((ndlp->nlp_type & NLP_FCP_TARGET) || 884 - (ndlp->nlp_type & NLP_NVME_TARGET) || 885 - (vport->fc_flag & FC_PT2PT))) || 886 - (ndlp->nlp_state == NLP_STE_ADISC_ISSUE)) { 887 - /* Only try to re-login if this is NOT a Fabric Node 888 - * AND the remote NPORT is a FCP/NVME Target or we 889 - * are in pt2pt mode. NLP_STE_ADISC_ISSUE is a special 890 - * case for LOGO as a response to ADISC behavior. 891 - */ 892 - mod_timer(&ndlp->nlp_delayfunc, 893 - jiffies + msecs_to_jiffies(1000 * 1)); 894 - spin_lock_irq(&ndlp->lock); 895 - ndlp->nlp_flag |= NLP_DELAY_TMO; 896 - spin_unlock_irq(&ndlp->lock); 882 + } else { 883 + lpfc_printf_vlog(vport, KERN_INFO, 884 + LOG_NODE | LOG_ELS | LOG_DISCOVERY, 885 + "3203 LOGO recover nport x%06x state x%x " 886 + "ntype x%x fc_flag x%x\n", 887 + ndlp->nlp_DID, ndlp->nlp_state, 888 + ndlp->nlp_type, vport->fc_flag); 897 889 898 - ndlp->nlp_last_elscmd = ELS_CMD_PLOGI; 890 + /* Special cases for rports that recover post LOGO. */ 891 + if ((!(ndlp->nlp_type == NLP_FABRIC) && 892 + (ndlp->nlp_type & (NLP_FCP_TARGET | NLP_NVME_TARGET) || 893 + vport->fc_flag & FC_PT2PT)) || 894 + (ndlp->nlp_state >= NLP_STE_ADISC_ISSUE || 895 + ndlp->nlp_state <= NLP_STE_PRLI_ISSUE)) { 896 + mod_timer(&ndlp->nlp_delayfunc, 897 + jiffies + msecs_to_jiffies(1000 * 1)); 898 + spin_lock_irq(&ndlp->lock); 899 + ndlp->nlp_flag |= NLP_DELAY_TMO; 900 + spin_unlock_irq(&ndlp->lock); 901 + ndlp->nlp_last_elscmd = ELS_CMD_PLOGI; 902 + lpfc_printf_vlog(vport, KERN_INFO, 903 + LOG_NODE | LOG_ELS | LOG_DISCOVERY, 904 + "3204 Start nlpdelay on DID x%06x " 905 + "nflag x%x lastels x%x ref cnt %u", 906 + ndlp->nlp_DID, ndlp->nlp_flag, 907 + ndlp->nlp_last_elscmd, 908 + kref_read(&ndlp->kref)); 909 + } 899 910 } 900 911 out: 901 912 /* Unregister from backend, could have been skipped due to ADISC */ ··· 1865 1854 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg; 1866 1855 LPFC_MBOXQ_t *mb; 1867 1856 LPFC_MBOXQ_t *nextmb; 1868 - struct lpfc_nodelist *ns_ndlp; 1869 1857 1870 1858 cmdiocb = (struct lpfc_iocbq *) arg; 1871 1859 ··· 1891 1881 } 1892 1882 } 1893 1883 spin_unlock_irq(&phba->hbalock); 1894 - 1895 - /* software abort if any GID_FT is outstanding */ 1896 - if (vport->cfg_enable_fc4_type != LPFC_ENABLE_FCP) { 1897 - ns_ndlp = lpfc_findnode_did(vport, NameServer_DID); 1898 - if (ns_ndlp) 1899 - lpfc_els_abort(phba, ns_ndlp); 1900 - } 1901 1884 1902 1885 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO); 1903 1886 return ndlp->nlp_state; ··· 2151 2148 struct lpfc_nvme_prli *nvpr; 2152 2149 void *temp_ptr; 2153 2150 u32 ulp_status; 2151 + bool acc_imode_sps = false; 2154 2152 2155 2153 cmdiocb = (struct lpfc_iocbq *) arg; 2156 2154 rspiocb = cmdiocb->rsp_iocb; ··· 2186 2182 goto out_err; 2187 2183 } 2188 2184 2189 - if (npr && (npr->acceptRspCode == PRLI_REQ_EXECUTED) && 2190 - (npr->prliType == PRLI_FCP_TYPE)) { 2191 - lpfc_printf_vlog(vport, KERN_INFO, LOG_NVME_DISC, 2192 - "6028 FCP NPR PRLI Cmpl Init %d Target %d\n", 2193 - npr->initiatorFunc, 2194 - npr->targetFunc); 2195 - if (npr->initiatorFunc) 2196 - ndlp->nlp_type |= NLP_FCP_INITIATOR; 2197 - if (npr->targetFunc) { 2198 - ndlp->nlp_type |= NLP_FCP_TARGET; 2199 - if (npr->writeXferRdyDis) 2200 - ndlp->nlp_flag |= NLP_FIRSTBURST; 2201 - } 2202 - if (npr->Retry) 2203 - ndlp->nlp_fcp_info |= NLP_FCP_2_DEVICE; 2185 + if (npr && npr->prliType == PRLI_FCP_TYPE) { 2186 + lpfc_printf_vlog(vport, KERN_INFO, 2187 + LOG_ELS | LOG_NODE | LOG_DISCOVERY, 2188 + "6028 FCP NPR PRLI Cmpl Init %d Target %d " 2189 + "EIP %d AccCode x%x\n", 2190 + npr->initiatorFunc, npr->targetFunc, 2191 + npr->estabImagePair, npr->acceptRspCode); 2204 2192 2193 + if (npr->acceptRspCode == PRLI_INV_SRV_PARM) { 2194 + /* Strict initiators don't establish an image pair. */ 2195 + if (npr->initiatorFunc && !npr->targetFunc && 2196 + !npr->estabImagePair) 2197 + acc_imode_sps = true; 2198 + } 2199 + 2200 + if (npr->acceptRspCode == PRLI_REQ_EXECUTED || acc_imode_sps) { 2201 + if (npr->initiatorFunc) 2202 + ndlp->nlp_type |= NLP_FCP_INITIATOR; 2203 + if (npr->targetFunc) { 2204 + ndlp->nlp_type |= NLP_FCP_TARGET; 2205 + if (npr->writeXferRdyDis) 2206 + ndlp->nlp_flag |= NLP_FIRSTBURST; 2207 + } 2208 + if (npr->Retry) 2209 + ndlp->nlp_fcp_info |= NLP_FCP_2_DEVICE; 2210 + } 2205 2211 } else if (nvpr && 2206 2212 (bf_get_be32(prli_acc_rsp_code, nvpr) == 2207 2213 PRLI_REQ_EXECUTED) &&
+5 -11
drivers/scsi/lpfc/lpfc_nvme.c
··· 1864 1864 struct lpfc_nvme_fcpreq_priv *freqpriv; 1865 1865 unsigned long flags; 1866 1866 int ret_val; 1867 - struct nvme_fc_cmd_iu *cp; 1868 1867 1869 1868 /* Validate pointers. LLDD fault handling with transport does 1870 1869 * have timing races. ··· 1987 1988 return; 1988 1989 } 1989 1990 1990 - /* 1991 - * Get Command Id from cmd to plug into response. This 1992 - * code is not needed in the next NVME Transport drop. 1993 - */ 1994 - cp = (struct nvme_fc_cmd_iu *)lpfc_nbuf->nvmeCmd->cmdaddr; 1995 1991 lpfc_printf_vlog(vport, KERN_INFO, LOG_NVME_ABTS, 1996 1992 "6138 Transport Abort NVME Request Issued for " 1997 - "ox_id x%x nvme opcode x%x nvme cmd_id x%x\n", 1998 - nvmereq_wqe->sli4_xritag, cp->sqe.common.opcode, 1999 - cp->sqe.common.command_id); 1993 + "ox_id x%x\n", 1994 + nvmereq_wqe->sli4_xritag); 2000 1995 return; 2001 1996 2002 1997 out_unlock: ··· 2503 2510 lpfc_printf_vlog(vport, KERN_ERR, 2504 2511 LOG_TRACE_EVENT, 2505 2512 "6031 RemotePort Registration failed " 2506 - "err: %d, DID x%06x\n", 2507 - ret, ndlp->nlp_DID); 2513 + "err: %d, DID x%06x ref %u\n", 2514 + ret, ndlp->nlp_DID, kref_read(&ndlp->kref)); 2515 + lpfc_nlp_put(ndlp); 2508 2516 } 2509 2517 2510 2518 return ret;
+1 -4
drivers/scsi/lpfc/lpfc_nvmet.c
··· 1620 1620 cpu = cpumask_first(cpu_present_mask); 1621 1621 continue; 1622 1622 } 1623 - cpu = cpumask_next(cpu, cpu_present_mask); 1624 - if (cpu == nr_cpu_ids) 1625 - cpu = cpumask_first(cpu_present_mask); 1626 - 1623 + cpu = lpfc_next_present_cpu(cpu); 1627 1624 } 1628 1625 1629 1626 for_each_present_cpu(i) {
+7 -1
drivers/scsi/lpfc/lpfc_sli.c
··· 3935 3935 uint64_t sli_intr, cnt; 3936 3936 3937 3937 phba = from_timer(phba, t, eratt_poll); 3938 + if (!(phba->hba_flag & HBA_SETUP)) 3939 + return; 3938 3940 3939 3941 /* Here we will also keep track of interrupts per sec of the hba */ 3940 3942 sli_intr = phba->sli.slistat.sli_intr; ··· 7695 7693 spin_unlock_irq(&phba->hbalock); 7696 7694 } else { 7697 7695 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, 7698 - "3161 Failure to post sgl to port.\n"); 7696 + "3161 Failure to post sgl to port,status %x " 7697 + "blkcnt %d totalcnt %d postcnt %d\n", 7698 + status, block_cnt, total_cnt, post_cnt); 7699 7699 return -EIO; 7700 7700 } 7701 7701 ··· 8482 8478 spin_unlock_irq(&phba->hbalock); 8483 8479 } 8484 8480 } 8481 + phba->hba_flag &= ~HBA_SETUP; 8485 8482 8486 8483 lpfc_sli4_dip(phba); 8487 8484 ··· 9287 9282 * would get IOCB_ERROR from lpfc_sli_issue_iocb, allowing 9288 9283 * it to fail all outstanding SCSI IO. 9289 9284 */ 9285 + set_bit(MBX_TMO_ERR, &phba->bit_flags); 9290 9286 spin_lock_irq(&phba->pport->work_port_lock); 9291 9287 phba->pport->work_port_events &= ~WORKER_MBOX_TMO; 9292 9288 spin_unlock_irq(&phba->pport->work_port_lock);
+1 -1
drivers/scsi/lpfc/lpfc_version.h
··· 20 20 * included with this package. * 21 21 *******************************************************************/ 22 22 23 - #define LPFC_DRIVER_VERSION "14.2.0.13" 23 + #define LPFC_DRIVER_VERSION "14.2.0.14" 24 24 #define LPFC_DRIVER_NAME "lpfc" 25 25 26 26 /* Used for SLI 2/3 */
+1 -1
drivers/scsi/megaraid/megaraid_mbox.c
··· 438 438 439 439 440 440 // set up PCI related soft state and other pre-known parameters 441 - adapter->unique_id = pdev->bus->number << 8 | pdev->devfn; 441 + adapter->unique_id = pci_dev_id(pdev); 442 442 adapter->irq = pdev->irq; 443 443 adapter->pdev = pdev; 444 444
+1 -1
drivers/scsi/megaraid/megaraid_sas_base.c
··· 7518 7518 */ 7519 7519 instance->pdev = pdev; 7520 7520 instance->host = host; 7521 - instance->unique_id = pdev->bus->number << 8 | pdev->devfn; 7521 + instance->unique_id = pci_dev_id(pdev); 7522 7522 instance->init_id = MEGASAS_DEFAULT_INIT_ID; 7523 7523 7524 7524 megasas_set_adapter_type(instance);
+1 -1
drivers/scsi/mpi3mr/mpi/mpi30_cnfg.h
··· 1482 1482 #define MPI3_SECURITY1_KEY_RECORD_MAX 1 1483 1483 #endif 1484 1484 #ifndef MPI3_SECURITY1_PAD_MAX 1485 - #define MPI3_SECURITY1_PAD_MAX 1 1485 + #define MPI3_SECURITY1_PAD_MAX 4 1486 1486 #endif 1487 1487 union mpi3_security1_key_data { 1488 1488 __le32 dword[128];
+1
drivers/scsi/mpi3mr/mpi/mpi30_ioc.h
··· 600 600 __le16 threshold_count; 601 601 __le16 attached_dev_handle; 602 602 __le16 reserved12; 603 + __le32 reserved14; 603 604 }; 604 605 605 606 #define MPI3_EVENT_PCI_ERROR_RC_THRESHOLD_EXCEEDED (0x00)
+1 -1
drivers/scsi/mpi3mr/mpi/mpi30_transport.h
··· 18 18 19 19 #define MPI3_VERSION_MAJOR (3) 20 20 #define MPI3_VERSION_MINOR (0) 21 - #define MPI3_VERSION_UNIT (27) 21 + #define MPI3_VERSION_UNIT (28) 22 22 #define MPI3_VERSION_DEV (0) 23 23 #define MPI3_DEVHANDLE_INVALID (0xffff) 24 24 struct mpi3_sysif_oper_queue_indexes {
+19 -4
drivers/scsi/mpi3mr/mpi3mr.h
··· 55 55 extern int prot_mask; 56 56 extern atomic64_t event_counter; 57 57 58 - #define MPI3MR_DRIVER_VERSION "8.4.1.0.0" 59 - #define MPI3MR_DRIVER_RELDATE "16-March-2023" 58 + #define MPI3MR_DRIVER_VERSION "8.5.0.0.0" 59 + #define MPI3MR_DRIVER_RELDATE "24-July-2023" 60 60 61 61 #define MPI3MR_DRIVER_NAME "mpi3mr" 62 62 #define MPI3MR_DRIVER_LICENSE "GPL" ··· 66 66 #define MPI3MR_NAME_LENGTH 32 67 67 #define IOCNAME "%s: " 68 68 69 - #define MPI3MR_MAX_SECTORS 2048 69 + #define MPI3MR_DEFAULT_MAX_IO_SIZE (1 * 1024 * 1024) 70 70 71 71 /* Definitions for internal SGL and Chain SGL buffers */ 72 72 #define MPI3MR_PAGE_SIZE_4K 4096 73 - #define MPI3MR_SG_DEPTH (MPI3MR_PAGE_SIZE_4K / sizeof(struct mpi3_sge_common)) 73 + #define MPI3MR_DEFAULT_SGL_ENTRIES 256 74 + #define MPI3MR_MAX_SGL_ENTRIES 2048 74 75 75 76 /* Definitions for MAX values for shost */ 76 77 #define MPI3MR_MAX_CMDS_LUN 128 ··· 207 206 */ 208 207 #define MPI3MR_MAX_APP_XFER_SECTORS (2048 + 512) 209 208 209 + #define MPI3MR_WRITE_SAME_MAX_LEN_256_BLKS 256 210 + #define MPI3MR_WRITE_SAME_MAX_LEN_2048_BLKS 2048 211 + 210 212 /** 211 213 * struct mpi3mr_nvme_pt_sge - Structure to store SGEs for NVMe 212 214 * Encapsulated commands. ··· 327 323 u16 max_perids; 328 324 u16 max_pds; 329 325 u16 max_sasexpanders; 326 + u32 max_data_length; 330 327 u16 max_sasinitiators; 331 328 u16 max_enclosures; 332 329 u16 max_pcie_switches; ··· 681 676 * @io_unit_port: IO Unit port ID 682 677 * @non_stl: Is this device not to be attached with SAS TL 683 678 * @io_throttle_enabled: I/O throttling needed or not 679 + * @wslen: Write same max length 684 680 * @q_depth: Device specific Queue Depth 685 681 * @wwid: World wide ID 686 682 * @enclosure_logical_id: Enclosure logical identifier ··· 704 698 u8 io_unit_port; 705 699 u8 non_stl; 706 700 u8 io_throttle_enabled; 701 + u16 wslen; 707 702 u16 q_depth; 708 703 u64 wwid; 709 704 u64 enclosure_logical_id; ··· 758 751 * @dev_removed: Device removed in the Firmware 759 752 * @dev_removedelay: Device is waiting to be removed in FW 760 753 * @dev_type: Device type 754 + * @dev_nvme_dif: Device is NVMe DIF enabled 755 + * @wslen: Write same max length 761 756 * @io_throttle_enabled: I/O throttling needed or not 762 757 * @io_divert: Flag indicates io divert is on or off for the dev 763 758 * @throttle_group: Pointer to throttle group info ··· 776 767 u8 dev_removed; 777 768 u8 dev_removedelay; 778 769 u8 dev_type; 770 + u8 dev_nvme_dif; 771 + u16 wslen; 779 772 u8 io_throttle_enabled; 780 773 u8 io_divert; 781 774 struct mpi3mr_throttle_group_info *throttle_group; ··· 793 782 * @ncq_prio_enable: NCQ priority enable for SATA device 794 783 * @pend_count: Counter to track pending I/Os during error 795 784 * handling 785 + * @wslen: Write same max length 796 786 */ 797 787 struct mpi3mr_sdev_priv_data { 798 788 struct mpi3mr_stgt_priv_data *tgt_priv_data; 799 789 u32 lun_id; 800 790 u8 ncq_prio_enable; 801 791 u32 pend_count; 792 + u16 wslen; 802 793 }; 803 794 804 795 /** ··· 972 959 * @stop_drv_processing: Stop all command processing 973 960 * @device_refresh_on: Don't process the events until devices are refreshed 974 961 * @max_host_ios: Maximum host I/O count 962 + * @max_sgl_entries: Max SGL entries per I/O 975 963 * @chain_buf_count: Chain buffer count 976 964 * @chain_buf_pool: Chain buffer pool 977 965 * @chain_sgl_list: Chain SGL list ··· 1143 1129 u16 max_host_ios; 1144 1130 spinlock_t tgtdev_lock; 1145 1131 struct list_head tgtdev_list; 1132 + u16 max_sgl_entries; 1146 1133 1147 1134 u32 chain_buf_count; 1148 1135 struct dma_pool *chain_buf_pool;
+28 -9
drivers/scsi/mpi3mr/mpi3mr_fw.c
··· 1163 1163 return -EPERM; 1164 1164 } 1165 1165 1166 + if (mrioc->shost->max_sectors != (mrioc->facts.max_data_length / 512)) 1167 + ioc_err(mrioc, "Warning: The maximum data transfer length\n" 1168 + "\tchanged after reset: previous(%d), new(%d),\n" 1169 + "the driver cannot change this at run time\n", 1170 + mrioc->shost->max_sectors * 512, mrioc->facts.max_data_length); 1171 + 1166 1172 if ((mrioc->sas_transport_enabled) && (mrioc->facts.ioc_capabilities & 1167 1173 MPI3_IOCFACTS_CAPABILITY_MULTIPATH_ENABLED)) 1168 1174 ioc_err(mrioc, ··· 2349 2343 ioc_err(mrioc, "Issue IOUCTL time_stamp: command timed out\n"); 2350 2344 mrioc->init_cmds.is_waiting = 0; 2351 2345 if (!(mrioc->init_cmds.state & MPI3MR_CMD_RESET)) 2352 - mpi3mr_soft_reset_handler(mrioc, 2353 - MPI3MR_RESET_FROM_TSU_TIMEOUT, 1); 2346 + mpi3mr_check_rh_fault_ioc(mrioc, 2347 + MPI3MR_RESET_FROM_TSU_TIMEOUT); 2354 2348 retval = -1; 2355 2349 goto out_unlock; 2356 2350 } ··· 2862 2856 le16_to_cpu(facts_data->max_pcie_switches); 2863 2857 mrioc->facts.max_sasexpanders = 2864 2858 le16_to_cpu(facts_data->max_sas_expanders); 2859 + mrioc->facts.max_data_length = le16_to_cpu(facts_data->max_data_length); 2865 2860 mrioc->facts.max_sasinitiators = 2866 2861 le16_to_cpu(facts_data->max_sas_initiators); 2867 2862 mrioc->facts.max_enclosures = le16_to_cpu(facts_data->max_enclosures); ··· 2900 2893 mrioc->facts.io_throttle_high = 2901 2894 le16_to_cpu(facts_data->io_throttle_high); 2902 2895 2896 + if (mrioc->facts.max_data_length == 2897 + MPI3_IOCFACTS_MAX_DATA_LENGTH_NOT_REPORTED) 2898 + mrioc->facts.max_data_length = MPI3MR_DEFAULT_MAX_IO_SIZE; 2899 + else 2900 + mrioc->facts.max_data_length *= MPI3MR_PAGE_SIZE_4K; 2903 2901 /* Store in 512b block count */ 2904 2902 if (mrioc->facts.io_throttle_data_length) 2905 2903 mrioc->io_throttle_data_length = 2906 2904 (mrioc->facts.io_throttle_data_length * 2 * 4); 2907 2905 else 2908 2906 /* set the length to 1MB + 1K to disable throttle */ 2909 - mrioc->io_throttle_data_length = MPI3MR_MAX_SECTORS + 2; 2907 + mrioc->io_throttle_data_length = (mrioc->facts.max_data_length / 512) + 2; 2910 2908 2911 2909 mrioc->io_throttle_high = (mrioc->facts.io_throttle_high * 2 * 1024); 2912 2910 mrioc->io_throttle_low = (mrioc->facts.io_throttle_low * 2 * 1024); ··· 2926 2914 ioc_info(mrioc, "SGEModMask 0x%x SGEModVal 0x%x SGEModShift 0x%x ", 2927 2915 mrioc->facts.sge_mod_mask, mrioc->facts.sge_mod_value, 2928 2916 mrioc->facts.sge_mod_shift); 2929 - ioc_info(mrioc, "DMA mask %d InitialPE status 0x%x\n", 2917 + ioc_info(mrioc, "DMA mask %d InitialPE status 0x%x max_data_len (%d)\n", 2930 2918 mrioc->facts.dma_mask, (facts_flags & 2931 - MPI3_IOCFACTS_FLAGS_INITIAL_PORT_ENABLE_MASK)); 2919 + MPI3_IOCFACTS_FLAGS_INITIAL_PORT_ENABLE_MASK), mrioc->facts.max_data_length); 2932 2920 ioc_info(mrioc, 2933 2921 "max_dev_per_throttle_group(%d), max_throttle_groups(%d)\n", 2934 2922 mrioc->facts.max_dev_per_tg, mrioc->facts.max_io_throttle_group); ··· 3371 3359 if (!(mrioc->init_cmds.state & MPI3MR_CMD_COMPLETE)) { 3372 3360 ioc_err(mrioc, "Issue EvtNotify: command timed out\n"); 3373 3361 if (!(mrioc->init_cmds.state & MPI3MR_CMD_RESET)) 3374 - mpi3mr_soft_reset_handler(mrioc, 3375 - MPI3MR_RESET_FROM_EVTACK_TIMEOUT, 1); 3362 + mpi3mr_check_rh_fault_ioc(mrioc, 3363 + MPI3MR_RESET_FROM_EVTACK_TIMEOUT); 3376 3364 retval = -1; 3377 3365 goto out_unlock; 3378 3366 } ··· 3426 3414 if (!mrioc->chain_sgl_list) 3427 3415 goto out_failed; 3428 3416 3429 - sz = MPI3MR_PAGE_SIZE_4K; 3417 + if (mrioc->max_sgl_entries > (mrioc->facts.max_data_length / 3418 + MPI3MR_PAGE_SIZE_4K)) 3419 + mrioc->max_sgl_entries = mrioc->facts.max_data_length / 3420 + MPI3MR_PAGE_SIZE_4K; 3421 + sz = mrioc->max_sgl_entries * sizeof(struct mpi3_sge_common); 3422 + ioc_info(mrioc, "number of sgl entries=%d chain buffer size=%dKB\n", 3423 + mrioc->max_sgl_entries, sz/1024); 3424 + 3430 3425 mrioc->chain_buf_pool = dma_pool_create("chain_buf pool", 3431 3426 &mrioc->pdev->dev, sz, 16, 0); 3432 3427 if (!mrioc->chain_buf_pool) { ··· 3832 3813 } 3833 3814 3834 3815 mrioc->max_host_ios = mrioc->facts.max_reqs - MPI3MR_INTERNAL_CMDS_RESVD; 3835 - 3816 + mrioc->shost->max_sectors = mrioc->facts.max_data_length / 512; 3836 3817 mrioc->num_io_throttle_group = mrioc->facts.max_io_throttle_group; 3837 3818 atomic_set(&mrioc->pend_large_data_sz, 0); 3838 3819
+127 -28
drivers/scsi/mpi3mr/mpi3mr_os.c
··· 33 33 module_param(logging_level, int, 0); 34 34 MODULE_PARM_DESC(logging_level, 35 35 " bits for enabling additional logging info (default=0)"); 36 + static int max_sgl_entries = MPI3MR_DEFAULT_SGL_ENTRIES; 37 + module_param(max_sgl_entries, int, 0444); 38 + MODULE_PARM_DESC(max_sgl_entries, 39 + "Preferred max number of SG entries to be used for a single I/O\n" 40 + "The actual value will be determined by the driver\n" 41 + "(Minimum=256, Maximum=2048, default=256)"); 36 42 37 43 /* Forward declarations*/ 38 44 static void mpi3mr_send_event_ack(struct mpi3mr_ioc *mrioc, u8 event, ··· 430 424 tgt_priv->io_throttle_enabled = 0; 431 425 tgt_priv->io_divert = 0; 432 426 tgt_priv->throttle_group = NULL; 427 + tgt_priv->wslen = 0; 433 428 if (tgtdev->host_exposed) 434 429 atomic_set(&tgt_priv->block_io, 1); 435 430 } ··· 1041 1034 void mpi3mr_rfresh_tgtdevs(struct mpi3mr_ioc *mrioc) 1042 1035 { 1043 1036 struct mpi3mr_tgt_dev *tgtdev, *tgtdev_next; 1037 + struct mpi3mr_stgt_priv_data *tgt_priv; 1038 + 1039 + dprint_reset(mrioc, "refresh target devices: check for removals\n"); 1040 + list_for_each_entry_safe(tgtdev, tgtdev_next, &mrioc->tgtdev_list, 1041 + list) { 1042 + if ((tgtdev->dev_handle == MPI3MR_INVALID_DEV_HANDLE) && 1043 + tgtdev->host_exposed && tgtdev->starget && 1044 + tgtdev->starget->hostdata) { 1045 + tgt_priv = tgtdev->starget->hostdata; 1046 + tgt_priv->dev_removed = 1; 1047 + atomic_set(&tgt_priv->block_io, 0); 1048 + } 1049 + } 1044 1050 1045 1051 list_for_each_entry_safe(tgtdev, tgtdev_next, &mrioc->tgtdev_list, 1046 1052 list) { ··· 1122 1102 tgtdev->io_throttle_enabled = 1123 1103 (flags & MPI3_DEVICE0_FLAGS_IO_THROTTLING_REQUIRED) ? 1 : 0; 1124 1104 1105 + switch (flags & MPI3_DEVICE0_FLAGS_MAX_WRITE_SAME_MASK) { 1106 + case MPI3_DEVICE0_FLAGS_MAX_WRITE_SAME_256_LB: 1107 + tgtdev->wslen = MPI3MR_WRITE_SAME_MAX_LEN_256_BLKS; 1108 + break; 1109 + case MPI3_DEVICE0_FLAGS_MAX_WRITE_SAME_2048_LB: 1110 + tgtdev->wslen = MPI3MR_WRITE_SAME_MAX_LEN_2048_BLKS; 1111 + break; 1112 + case MPI3_DEVICE0_FLAGS_MAX_WRITE_SAME_NO_LIMIT: 1113 + default: 1114 + tgtdev->wslen = 0; 1115 + break; 1116 + } 1125 1117 1126 1118 if (tgtdev->starget && tgtdev->starget->hostdata) { 1127 1119 scsi_tgt_priv_data = (struct mpi3mr_stgt_priv_data *) ··· 1145 1113 tgtdev->io_throttle_enabled; 1146 1114 if (is_added == true) 1147 1115 atomic_set(&scsi_tgt_priv_data->block_io, 0); 1116 + scsi_tgt_priv_data->wslen = tgtdev->wslen; 1148 1117 } 1149 1118 1150 1119 switch (dev_pg0->access_status) { ··· 3446 3413 scsi_bufflen(scmd)); 3447 3414 return -ENOMEM; 3448 3415 } 3449 - if (sges_left > MPI3MR_SG_DEPTH) { 3416 + if (sges_left > mrioc->max_sgl_entries) { 3450 3417 sdev_printk(KERN_ERR, scmd->device, 3451 3418 "scsi_dma_map returned unsupported sge count %d!\n", 3452 3419 sges_left); ··· 3967 3934 } 3968 3935 3969 3936 /** 3937 + * mpi3mr_setup_divert_ws - Setup Divert IO flag for write same 3938 + * @mrioc: Adapter instance reference 3939 + * @scmd: SCSI command reference 3940 + * @scsiio_req: MPI3 SCSI IO request 3941 + * @scsiio_flags: Pointer to MPI3 SCSI IO Flags 3942 + * @wslen: write same max length 3943 + * 3944 + * Gets values of unmap, ndob and number of blocks from write 3945 + * same scsi io and based on these values it sets divert IO flag 3946 + * and reason for diverting IO to firmware. 3947 + * 3948 + * Return: Nothing 3949 + */ 3950 + static inline void mpi3mr_setup_divert_ws(struct mpi3mr_ioc *mrioc, 3951 + struct scsi_cmnd *scmd, struct mpi3_scsi_io_request *scsiio_req, 3952 + u32 *scsiio_flags, u16 wslen) 3953 + { 3954 + u8 unmap = 0, ndob = 0; 3955 + u8 opcode = scmd->cmnd[0]; 3956 + u32 num_blocks = 0; 3957 + u16 sa = (scmd->cmnd[8] << 8) | (scmd->cmnd[9]); 3958 + 3959 + if (opcode == WRITE_SAME_16) { 3960 + unmap = scmd->cmnd[1] & 0x08; 3961 + ndob = scmd->cmnd[1] & 0x01; 3962 + num_blocks = get_unaligned_be32(scmd->cmnd + 10); 3963 + } else if ((opcode == VARIABLE_LENGTH_CMD) && (sa == WRITE_SAME_32)) { 3964 + unmap = scmd->cmnd[10] & 0x08; 3965 + ndob = scmd->cmnd[10] & 0x01; 3966 + num_blocks = get_unaligned_be32(scmd->cmnd + 28); 3967 + } else 3968 + return; 3969 + 3970 + if ((unmap) && (ndob) && (num_blocks > wslen)) { 3971 + scsiio_req->msg_flags |= 3972 + MPI3_SCSIIO_MSGFLAGS_DIVERT_TO_FIRMWARE; 3973 + *scsiio_flags |= 3974 + MPI3_SCSIIO_FLAGS_DIVERT_REASON_WRITE_SAME_TOO_LARGE; 3975 + } 3976 + } 3977 + 3978 + /** 3970 3979 * mpi3mr_eh_host_reset - Host reset error handling callback 3971 3980 * @scmd: SCSI command reference 3972 3981 * ··· 4505 4430 unsigned long flags; 4506 4431 int retval = 0; 4507 4432 struct sas_rphy *rphy = NULL; 4508 - bool update_stgt_priv_data = false; 4509 4433 4510 4434 scsi_tgt_priv_data = kzalloc(sizeof(*scsi_tgt_priv_data), GFP_KERNEL); 4511 4435 if (!scsi_tgt_priv_data) ··· 4513 4439 starget->hostdata = scsi_tgt_priv_data; 4514 4440 4515 4441 spin_lock_irqsave(&mrioc->tgtdev_lock, flags); 4516 - 4517 4442 if (starget->channel == mrioc->scsi_device_channel) { 4518 4443 tgt_dev = __mpi3mr_get_tgtdev_by_perst_id(mrioc, starget->id); 4519 - if (tgt_dev && !tgt_dev->is_hidden) 4520 - update_stgt_priv_data = true; 4521 - else 4444 + if (tgt_dev && !tgt_dev->is_hidden) { 4445 + scsi_tgt_priv_data->starget = starget; 4446 + scsi_tgt_priv_data->dev_handle = tgt_dev->dev_handle; 4447 + scsi_tgt_priv_data->perst_id = tgt_dev->perst_id; 4448 + scsi_tgt_priv_data->dev_type = tgt_dev->dev_type; 4449 + scsi_tgt_priv_data->tgt_dev = tgt_dev; 4450 + tgt_dev->starget = starget; 4451 + atomic_set(&scsi_tgt_priv_data->block_io, 0); 4452 + retval = 0; 4453 + if ((tgt_dev->dev_type == MPI3_DEVICE_DEVFORM_PCIE) && 4454 + ((tgt_dev->dev_spec.pcie_inf.dev_info & 4455 + MPI3_DEVICE0_PCIE_DEVICE_INFO_TYPE_MASK) == 4456 + MPI3_DEVICE0_PCIE_DEVICE_INFO_TYPE_NVME_DEVICE) && 4457 + ((tgt_dev->dev_spec.pcie_inf.dev_info & 4458 + MPI3_DEVICE0_PCIE_DEVICE_INFO_PITYPE_MASK) != 4459 + MPI3_DEVICE0_PCIE_DEVICE_INFO_PITYPE_0)) 4460 + scsi_tgt_priv_data->dev_nvme_dif = 1; 4461 + scsi_tgt_priv_data->io_throttle_enabled = tgt_dev->io_throttle_enabled; 4462 + scsi_tgt_priv_data->wslen = tgt_dev->wslen; 4463 + if (tgt_dev->dev_type == MPI3_DEVICE_DEVFORM_VD) 4464 + scsi_tgt_priv_data->throttle_group = tgt_dev->dev_spec.vd_inf.tg; 4465 + } else 4522 4466 retval = -ENXIO; 4523 4467 } else if (mrioc->sas_transport_enabled && !starget->channel) { 4524 4468 rphy = dev_to_rphy(starget->dev.parent); 4525 4469 tgt_dev = __mpi3mr_get_tgtdev_by_addr_and_rphy(mrioc, 4526 4470 rphy->identify.sas_address, rphy); 4527 4471 if (tgt_dev && !tgt_dev->is_hidden && !tgt_dev->non_stl && 4528 - (tgt_dev->dev_type == MPI3_DEVICE_DEVFORM_SAS_SATA)) 4529 - update_stgt_priv_data = true; 4530 - else 4472 + (tgt_dev->dev_type == MPI3_DEVICE_DEVFORM_SAS_SATA)) { 4473 + scsi_tgt_priv_data->starget = starget; 4474 + scsi_tgt_priv_data->dev_handle = tgt_dev->dev_handle; 4475 + scsi_tgt_priv_data->perst_id = tgt_dev->perst_id; 4476 + scsi_tgt_priv_data->dev_type = tgt_dev->dev_type; 4477 + scsi_tgt_priv_data->tgt_dev = tgt_dev; 4478 + scsi_tgt_priv_data->io_throttle_enabled = tgt_dev->io_throttle_enabled; 4479 + scsi_tgt_priv_data->wslen = tgt_dev->wslen; 4480 + tgt_dev->starget = starget; 4481 + atomic_set(&scsi_tgt_priv_data->block_io, 0); 4482 + retval = 0; 4483 + } else 4531 4484 retval = -ENXIO; 4532 - } 4533 - 4534 - if (update_stgt_priv_data) { 4535 - scsi_tgt_priv_data->starget = starget; 4536 - scsi_tgt_priv_data->dev_handle = tgt_dev->dev_handle; 4537 - scsi_tgt_priv_data->perst_id = tgt_dev->perst_id; 4538 - scsi_tgt_priv_data->dev_type = tgt_dev->dev_type; 4539 - scsi_tgt_priv_data->tgt_dev = tgt_dev; 4540 - tgt_dev->starget = starget; 4541 - atomic_set(&scsi_tgt_priv_data->block_io, 0); 4542 - retval = 0; 4543 - scsi_tgt_priv_data->io_throttle_enabled = 4544 - tgt_dev->io_throttle_enabled; 4545 - if (tgt_dev->dev_type == MPI3_DEVICE_DEVFORM_VD) 4546 - scsi_tgt_priv_data->throttle_group = 4547 - tgt_dev->dev_spec.vd_inf.tg; 4548 4485 } 4549 4486 spin_unlock_irqrestore(&mrioc->tgtdev_lock, flags); 4550 4487 ··· 4817 4732 4818 4733 mpi3mr_setup_eedp(mrioc, scmd, scsiio_req); 4819 4734 4735 + if (stgt_priv_data->wslen) 4736 + mpi3mr_setup_divert_ws(mrioc, scmd, scsiio_req, &scsiio_flags, 4737 + stgt_priv_data->wslen); 4738 + 4820 4739 memcpy(scsiio_req->cdb.cdb32, scmd->cmnd, scmd->cmd_len); 4821 4740 scsiio_req->data_length = cpu_to_le32(scsi_bufflen(scmd)); 4822 4741 scsiio_req->dev_handle = cpu_to_le16(dev_handle); ··· 4907 4818 .no_write_same = 1, 4908 4819 .can_queue = 1, 4909 4820 .this_id = -1, 4910 - .sg_tablesize = MPI3MR_SG_DEPTH, 4821 + .sg_tablesize = MPI3MR_DEFAULT_SGL_ENTRIES, 4911 4822 /* max xfer supported is 1M (2K in 512 byte sized sectors) 4912 4823 */ 4913 - .max_sectors = 2048, 4824 + .max_sectors = (MPI3MR_DEFAULT_MAX_IO_SIZE / 512), 4914 4825 .cmd_per_lun = MPI3MR_MAX_CMDS_LUN, 4915 4826 .max_segment_size = 0xffffffff, 4916 4827 .track_queue_depth = 1, ··· 5093 5004 mrioc->pdev = pdev; 5094 5005 mrioc->stop_bsgs = 1; 5095 5006 5007 + mrioc->max_sgl_entries = max_sgl_entries; 5008 + if (max_sgl_entries > MPI3MR_MAX_SGL_ENTRIES) 5009 + mrioc->max_sgl_entries = MPI3MR_MAX_SGL_ENTRIES; 5010 + else if (max_sgl_entries < MPI3MR_DEFAULT_SGL_ENTRIES) 5011 + mrioc->max_sgl_entries = MPI3MR_DEFAULT_SGL_ENTRIES; 5012 + else { 5013 + mrioc->max_sgl_entries /= MPI3MR_DEFAULT_SGL_ENTRIES; 5014 + mrioc->max_sgl_entries *= MPI3MR_DEFAULT_SGL_ENTRIES; 5015 + } 5016 + 5096 5017 /* init shost parameters */ 5097 5018 shost->max_cmd_len = MPI3MR_MAX_CDB_LENGTH; 5098 5019 shost->max_lun = -1; ··· 5167 5068 shost->nr_maps = 3; 5168 5069 5169 5070 shost->can_queue = mrioc->max_host_ios; 5170 - shost->sg_tablesize = MPI3MR_SG_DEPTH; 5071 + shost->sg_tablesize = mrioc->max_sgl_entries; 5171 5072 shost->max_id = mrioc->facts.max_perids + 1; 5172 5073 5173 5074 retval = scsi_add_host(shost, &pdev->dev);
+2 -5
drivers/scsi/mvsas/mv_init.c
··· 84 84 phy->port = NULL; 85 85 timer_setup(&phy->timer, NULL, 0); 86 86 sas_phy->enabled = (phy_id < mvi->chip->n_phy) ? 1 : 0; 87 - sas_phy->class = SAS; 88 87 sas_phy->iproto = SAS_PROTOCOL_ALL; 89 88 sas_phy->tproto = 0; 90 - sas_phy->type = PHY_TYPE_PHYSICAL; 91 89 sas_phy->role = PHY_ROLE_INITIATOR; 92 90 sas_phy->oob_mode = OOB_NOT_CONNECTED; 93 91 sas_phy->linkrate = SAS_LINK_RATE_UNKNOWN; ··· 414 416 415 417 sha->sas_phy = arr_phy; 416 418 sha->sas_port = arr_port; 417 - sha->core.shost = shost; 419 + sha->shost = shost; 418 420 419 421 sha->lldd_ha = kzalloc(sizeof(struct mvs_prv_info), GFP_KERNEL); 420 422 if (!sha->lldd_ha) ··· 456 458 457 459 sha->sas_ha_name = DRV_NAME; 458 460 sha->dev = mvi->dev; 459 - sha->lldd_module = THIS_MODULE; 460 461 sha->sas_addr = &mvi->sas_addr[0]; 461 462 462 463 sha->num_phys = nr_core * chip_info->n_phy; ··· 470 473 shost->sg_tablesize = min_t(u16, SG_ALL, MVS_MAX_SG); 471 474 shost->can_queue = can_queue; 472 475 mvi->shost->cmd_per_lun = MVS_QUEUE_SIZE; 473 - sha->core.shost = mvi->shost; 476 + sha->shost = mvi->shost; 474 477 } 475 478 476 479 static void mvs_init_sas_add(struct mvs_info *mvi)
+2 -7
drivers/scsi/mvsas/mv_sas.c
··· 564 564 void *buf_prd; 565 565 struct ssp_frame_hdr *ssp_hdr; 566 566 void *buf_tmp; 567 - u8 *buf_cmd, *buf_oaf, fburst = 0; 567 + u8 *buf_cmd, *buf_oaf; 568 568 dma_addr_t buf_tmp_dma; 569 569 u32 flags; 570 570 u32 resp_len, req_len, i, tag = tei->tag; ··· 582 582 (phy_mask << TXQ_PHY_SHIFT)); 583 583 584 584 flags = MCH_RETRY; 585 - if (task->ssp_task.enable_first_burst) { 586 - flags |= MCH_FBURST; 587 - fburst = (1 << 7); 588 - } 589 585 if (is_tmf) 590 586 flags |= (MCH_SSP_FR_TASK << MCH_SSP_FR_TYPE_SHIFT); 591 587 else ··· 663 667 memcpy(buf_cmd, &task->ssp_task.LUN, 8); 664 668 665 669 if (ssp_hdr->frame_type != SSP_TASK) { 666 - buf_cmd[9] = fburst | task->ssp_task.task_attr | 667 - (task->ssp_task.task_prio << 3); 670 + buf_cmd[9] = task->ssp_task.task_attr; 668 671 memcpy(buf_cmd + 12, task->ssp_task.cmd->cmnd, 669 672 task->ssp_task.cmd->cmd_len); 670 673 } else{
+1 -1
drivers/scsi/mvumi.c
··· 2490 2490 2491 2491 mhba->pdev = pdev; 2492 2492 mhba->shost = host; 2493 - mhba->unique_id = pdev->bus->number << 8 | pdev->devfn; 2493 + mhba->unique_id = pci_dev_id(pdev); 2494 2494 2495 2495 ret = mvumi_init_fw(mhba); 2496 2496 if (ret)
+6 -6
drivers/scsi/pm8001/pm8001_hwi.c
··· 4053 4053 ssp_cmd.data_len = cpu_to_le32(task->total_xfer_len); 4054 4054 ssp_cmd.device_id = cpu_to_le32(pm8001_dev->device_id); 4055 4055 ssp_cmd.tag = cpu_to_le32(tag); 4056 - if (task->ssp_task.enable_first_burst) 4057 - ssp_cmd.ssp_iu.efb_prio_attr |= 0x80; 4058 - ssp_cmd.ssp_iu.efb_prio_attr |= (task->ssp_task.task_prio << 3); 4059 4056 ssp_cmd.ssp_iu.efb_prio_attr |= (task->ssp_task.task_attr & 7); 4060 4057 memcpy(ssp_cmd.ssp_iu.cdb, task->ssp_task.cmd->cmnd, 4061 4058 task->ssp_task.cmd->cmd_len); ··· 4092 4095 u32 hdr_tag, ncg_tag = 0; 4093 4096 u64 phys_addr; 4094 4097 u32 ATAP = 0x0; 4095 - u32 dir; 4098 + u32 dir, retfis = 0; 4096 4099 u32 opc = OPC_INB_SATA_HOST_OPSTART; 4097 4100 4098 4101 memset(&sata_cmd, 0, sizeof(sata_cmd)); ··· 4121 4124 sata_cmd.tag = cpu_to_le32(tag); 4122 4125 sata_cmd.device_id = cpu_to_le32(pm8001_ha_dev->device_id); 4123 4126 sata_cmd.data_len = cpu_to_le32(task->total_xfer_len); 4124 - sata_cmd.ncqtag_atap_dir_m = 4125 - cpu_to_le32(((ncg_tag & 0xff)<<16)|((ATAP & 0x3f) << 10) | dir); 4127 + if (task->ata_task.return_fis_on_success) 4128 + retfis = 1; 4129 + sata_cmd.retfis_ncqtag_atap_dir_m = 4130 + cpu_to_le32((retfis << 24) | ((ncg_tag & 0xff) << 16) | 4131 + ((ATAP & 0x3f) << 10) | dir); 4126 4132 sata_cmd.sata_fis = task->ata_task.fis; 4127 4133 if (likely(!task->ata_task.device_control_reg_update)) 4128 4134 sata_cmd.sata_fis.flags |= 0x80;/* C=1: update ATA cmd reg */
+1 -1
drivers/scsi/pm8001/pm8001_hwi.h
··· 515 515 __le32 tag; 516 516 __le32 device_id; 517 517 __le32 data_len; 518 - __le32 ncqtag_atap_dir_m; 518 + __le32 retfis_ncqtag_atap_dir_m; 519 519 struct host_to_dev_fis sata_fis; 520 520 u32 reserved1; 521 521 u32 reserved2;
+1 -4
drivers/scsi/pm8001/pm8001_init.c
··· 162 162 phy->minimum_linkrate = SAS_LINK_RATE_1_5_GBPS; 163 163 phy->maximum_linkrate = SAS_LINK_RATE_6_0_GBPS; 164 164 sas_phy->enabled = (phy_id < pm8001_ha->chip->n_phy) ? 1 : 0; 165 - sas_phy->class = SAS; 166 165 sas_phy->iproto = SAS_PROTOCOL_ALL; 167 166 sas_phy->tproto = 0; 168 - sas_phy->type = PHY_TYPE_PHYSICAL; 169 167 sas_phy->role = PHY_ROLE_INITIATOR; 170 168 sas_phy->oob_mode = OOB_NOT_CONNECTED; 171 169 sas_phy->linkrate = SAS_LINK_RATE_UNKNOWN; ··· 652 654 sha->sas_ha_name = DRV_NAME; 653 655 sha->dev = pm8001_ha->dev; 654 656 sha->strict_wide_ports = 1; 655 - sha->lldd_module = THIS_MODULE; 656 657 sha->sas_addr = &pm8001_ha->sas_addr[0]; 657 658 sha->num_phys = chip_info->n_phy; 658 - sha->core.shost = shost; 659 + sha->shost = shost; 659 660 } 660 661 661 662 /**
-2
drivers/scsi/pm8001/pm8001_sas.h
··· 702 702 void *piomb); 703 703 int pm8001_mpi_general_event(struct pm8001_hba_info *pm8001_ha, void *piomb); 704 704 int pm8001_mpi_task_abort_resp(struct pm8001_hba_info *pm8001_ha, void *piomb); 705 - struct sas_task *pm8001_alloc_task(void); 706 - void pm8001_free_task(struct sas_task *task); 707 705 void pm8001_tag_free(struct pm8001_hba_info *pm8001_ha, u32 tag); 708 706 struct pm8001_device *pm8001_find_dev(struct pm8001_hba_info *pm8001_ha, 709 707 u32 device_id);
+11 -16
drivers/scsi/pm8001/pm80xx_hwi.c
··· 4316 4316 ssp_cmd.data_len = cpu_to_le32(task->total_xfer_len); 4317 4317 ssp_cmd.device_id = cpu_to_le32(pm8001_dev->device_id); 4318 4318 ssp_cmd.tag = cpu_to_le32(tag); 4319 - if (task->ssp_task.enable_first_burst) 4320 - ssp_cmd.ssp_iu.efb_prio_attr = 0x80; 4321 - ssp_cmd.ssp_iu.efb_prio_attr |= (task->ssp_task.task_prio << 3); 4322 4319 ssp_cmd.ssp_iu.efb_prio_attr |= (task->ssp_task.task_attr & 7); 4323 4320 memcpy(ssp_cmd.ssp_iu.cdb, task->ssp_task.cmd->cmnd, 4324 4321 task->ssp_task.cmd->cmd_len); ··· 4454 4457 u64 phys_addr, end_addr; 4455 4458 u32 end_addr_high, end_addr_low; 4456 4459 u32 ATAP = 0x0; 4457 - u32 dir; 4460 + u32 dir, retfis = 0; 4458 4461 u32 opc = OPC_INB_SATA_HOST_OPSTART; 4459 4462 memset(&sata_cmd, 0, sizeof(sata_cmd)); 4460 4463 ··· 4484 4487 sata_cmd.tag = cpu_to_le32(tag); 4485 4488 sata_cmd.device_id = cpu_to_le32(pm8001_ha_dev->device_id); 4486 4489 sata_cmd.data_len = cpu_to_le32(task->total_xfer_len); 4487 - 4490 + if (task->ata_task.return_fis_on_success) 4491 + retfis = 1; 4488 4492 sata_cmd.sata_fis = task->ata_task.fis; 4489 4493 if (likely(!task->ata_task.device_control_reg_update)) 4490 4494 sata_cmd.sata_fis.flags |= 0x80;/* C=1: update ATA cmd reg */ ··· 4498 4500 "Encryption enabled.Sending Encrypt SATA cmd 0x%x\n", 4499 4501 sata_cmd.sata_fis.command); 4500 4502 opc = OPC_INB_SATA_DIF_ENC_IO; 4501 - 4502 - /* set encryption bit */ 4503 - sata_cmd.ncqtag_atap_dir_m_dad = 4504 - cpu_to_le32(((ncg_tag & 0xff)<<16)| 4505 - ((ATAP & 0x3f) << 10) | 0x20 | dir); 4506 - /* dad (bit 0-1) is 0 */ 4503 + /* set encryption bit; dad (bits 0-1) is 0 */ 4504 + sata_cmd.retfis_ncqtag_atap_dir_m_dad = 4505 + cpu_to_le32((retfis << 24) | ((ncg_tag & 0xff) << 16) | 4506 + ((ATAP & 0x3f) << 10) | 0x20 | dir); 4507 4507 /* fill in PRD (scatter/gather) table, if any */ 4508 4508 if (task->num_scatter > 1) { 4509 4509 pm8001_chip_make_sg(task->scatter, ··· 4564 4568 pm8001_dbg(pm8001_ha, IO, 4565 4569 "Sending Normal SATA command 0x%x inb %x\n", 4566 4570 sata_cmd.sata_fis.command, q_index); 4567 - /* dad (bit 0-1) is 0 */ 4568 - sata_cmd.ncqtag_atap_dir_m_dad = 4569 - cpu_to_le32(((ncg_tag & 0xff)<<16) | 4570 - ((ATAP & 0x3f) << 10) | dir); 4571 - 4571 + /* dad (bits 0-1) is 0 */ 4572 + sata_cmd.retfis_ncqtag_atap_dir_m_dad = 4573 + cpu_to_le32((retfis << 24) | ((ncg_tag & 0xff) << 16) | 4574 + ((ATAP & 0x3f) << 10) | dir); 4572 4575 /* fill in PRD (scatter/gather) table, if any */ 4573 4576 if (task->num_scatter > 1) { 4574 4577 pm8001_chip_make_sg(task->scatter,
+1 -1
drivers/scsi/pm8001/pm80xx_hwi.h
··· 731 731 __le32 tag; 732 732 __le32 device_id; 733 733 __le32 data_len; 734 - __le32 ncqtag_atap_dir_m_dad; 734 + __le32 retfis_ncqtag_atap_dir_m_dad; 735 735 struct host_to_dev_fis sata_fis; 736 736 u32 reserved1; 737 737 u32 reserved2; /* dword 11. rsvd for normal I/O. */
+1 -2
drivers/scsi/pmcraid.c
··· 3584 3584 struct Scsi_Host *shost = class_to_shost(dev); 3585 3585 struct pmcraid_instance *pinstance = 3586 3586 (struct pmcraid_instance *)shost->hostdata; 3587 - u32 adapter_id = (pinstance->pdev->bus->number << 8) | 3588 - pinstance->pdev->devfn; 3587 + u32 adapter_id = pci_dev_id(pinstance->pdev); 3589 3588 u32 aen_group = pmcraid_event_family.id; 3590 3589 3591 3590 return snprintf(buf, PAGE_SIZE,
+43 -41
drivers/scsi/ppa.c
··· 45 45 46 46 #include "ppa.h" 47 47 48 + static unsigned int mode = PPA_AUTODETECT; 49 + module_param(mode, uint, 0644); 50 + MODULE_PARM_DESC(mode, "Transfer mode (0 = Autodetect, 1 = SPP 4-bit, " 51 + "2 = SPP 8-bit, 3 = EPP 8-bit, 4 = EPP 16-bit, 5 = EPP 32-bit"); 52 + 48 53 static struct scsi_pointer *ppa_scsi_pointer(struct scsi_cmnd *cmd) 49 54 { 50 55 return scsi_cmd_priv(cmd); ··· 162 157 return 0; 163 158 } 164 159 165 - static int device_check(ppa_struct *dev); 160 + static int device_check(ppa_struct *dev, bool autodetect); 166 161 167 162 #if PPA_DEBUG > 0 168 163 #define ppa_fail(x,y) printk("ppa: ppa_fail(%i) from %s at line %d\n",\ ··· 307 302 case PPA_EPP_8: 308 303 epp_reset(ppb); 309 304 w_ctr(ppb, 0x4); 310 - #ifdef CONFIG_SCSI_IZIP_EPP16 311 - if (!(((long) buffer | len) & 0x01)) 312 - outsw(ppb + 4, buffer, len >> 1); 313 - #else 314 - if (!(((long) buffer | len) & 0x03)) 305 + if (dev->mode == PPA_EPP_32 && !(((long) buffer | len) & 0x01)) 315 306 outsl(ppb + 4, buffer, len >> 2); 316 - #endif 307 + else if (dev->mode == PPA_EPP_16 && !(((long) buffer | len) & 0x03)) 308 + outsw(ppb + 4, buffer, len >> 1); 317 309 else 318 310 outsb(ppb + 4, buffer, len); 319 311 w_ctr(ppb, 0xc); ··· 357 355 case PPA_EPP_8: 358 356 epp_reset(ppb); 359 357 w_ctr(ppb, 0x24); 360 - #ifdef CONFIG_SCSI_IZIP_EPP16 361 - if (!(((long) buffer | len) & 0x01)) 362 - insw(ppb + 4, buffer, len >> 1); 363 - #else 364 - if (!(((long) buffer | len) & 0x03)) 358 + if (dev->mode == PPA_EPP_32 && !(((long) buffer | len) & 0x03)) 365 359 insl(ppb + 4, buffer, len >> 2); 366 - #endif 360 + else if (dev->mode == PPA_EPP_16 && !(((long) buffer | len) & 0x01)) 361 + insw(ppb + 4, buffer, len >> 1); 367 362 else 368 363 insb(ppb + 4, buffer, len); 369 364 w_ctr(ppb, 0x2c); ··· 468 469 { 469 470 int retv; 470 471 unsigned short ppb = dev->base; 472 + bool autodetect = dev->mode == PPA_AUTODETECT; 473 + 474 + if (autodetect) { 475 + int modes = dev->dev->port->modes; 476 + int ppb_hi = dev->dev->port->base_hi; 477 + 478 + /* Mode detection works up the chain of speed 479 + * This avoids a nasty if-then-else-if-... tree 480 + */ 481 + dev->mode = PPA_NIBBLE; 482 + 483 + if (modes & PARPORT_MODE_TRISTATE) 484 + dev->mode = PPA_PS2; 485 + 486 + if (modes & PARPORT_MODE_ECP) { 487 + w_ecr(ppb_hi, 0x20); 488 + dev->mode = PPA_PS2; 489 + } 490 + if ((modes & PARPORT_MODE_EPP) && (modes & PARPORT_MODE_ECP)) 491 + w_ecr(ppb_hi, 0x80); 492 + } 471 493 472 494 ppa_disconnect(dev); 473 495 ppa_connect(dev, CONNECT_NORMAL); ··· 512 492 if (retv) 513 493 return -EIO; 514 494 515 - return device_check(dev); 495 + return device_check(dev, autodetect); 516 496 } 517 497 518 498 static inline int ppa_send_command(struct scsi_cmnd *cmd) ··· 657 637 case DID_OK: 658 638 break; 659 639 case DID_NO_CONNECT: 660 - printk(KERN_DEBUG "ppa: no device at SCSI ID %i\n", cmd->device->target); 640 + printk(KERN_DEBUG "ppa: no device at SCSI ID %i\n", scmd_id(cmd)); 661 641 break; 662 642 case DID_BUS_BUSY: 663 643 printk(KERN_DEBUG "ppa: BUS BUSY - EPP timeout detected\n"); ··· 903 883 return SUCCESS; 904 884 } 905 885 906 - static int device_check(ppa_struct *dev) 886 + static int device_check(ppa_struct *dev, bool autodetect) 907 887 { 908 888 /* This routine looks for a device and then attempts to use EPP 909 889 to send a command. If all goes as planned then EPP is available. */ ··· 915 895 old_mode = dev->mode; 916 896 for (loop = 0; loop < 8; loop++) { 917 897 /* Attempt to use EPP for Test Unit Ready */ 918 - if ((ppb & 0x0007) == 0x0000) 919 - dev->mode = PPA_EPP_32; 898 + if (autodetect && (ppb & 0x0007) == 0x0000) 899 + dev->mode = PPA_EPP_8; 920 900 921 901 second_pass: 922 902 ppa_connect(dev, CONNECT_EPP_MAYBE); ··· 944 924 udelay(1000); 945 925 ppa_disconnect(dev); 946 926 udelay(1000); 947 - if (dev->mode == PPA_EPP_32) { 927 + if (dev->mode != old_mode) { 948 928 dev->mode = old_mode; 949 929 goto second_pass; 950 930 } ··· 967 947 udelay(1000); 968 948 ppa_disconnect(dev); 969 949 udelay(1000); 970 - if (dev->mode == PPA_EPP_32) { 950 + if (dev->mode != old_mode) { 971 951 dev->mode = old_mode; 972 952 goto second_pass; 973 953 } ··· 1046 1026 DEFINE_WAIT(wait); 1047 1027 ppa_struct *dev, *temp; 1048 1028 int ports; 1049 - int modes, ppb, ppb_hi; 1050 1029 int err = -ENOMEM; 1051 1030 struct pardev_cb ppa_cb; 1052 1031 ··· 1053 1034 if (!dev) 1054 1035 return -ENOMEM; 1055 1036 dev->base = -1; 1056 - dev->mode = PPA_AUTODETECT; 1037 + dev->mode = mode < PPA_UNKNOWN ? mode : PPA_AUTODETECT; 1057 1038 dev->recon_tmo = PPA_RECON_TMO; 1058 1039 init_waitqueue_head(&waiting); 1059 1040 temp = find_parent(); ··· 1088 1069 } 1089 1070 dev->waiting = NULL; 1090 1071 finish_wait(&waiting, &wait); 1091 - ppb = dev->base = dev->dev->port->base; 1092 - ppb_hi = dev->dev->port->base_hi; 1093 - w_ctr(ppb, 0x0c); 1094 - modes = dev->dev->port->modes; 1095 - 1096 - /* Mode detection works up the chain of speed 1097 - * This avoids a nasty if-then-else-if-... tree 1098 - */ 1099 - dev->mode = PPA_NIBBLE; 1100 - 1101 - if (modes & PARPORT_MODE_TRISTATE) 1102 - dev->mode = PPA_PS2; 1103 - 1104 - if (modes & PARPORT_MODE_ECP) { 1105 - w_ecr(ppb_hi, 0x20); 1106 - dev->mode = PPA_PS2; 1107 - } 1108 - if ((modes & PARPORT_MODE_EPP) && (modes & PARPORT_MODE_ECP)) 1109 - w_ecr(ppb_hi, 0x80); 1072 + dev->base = dev->dev->port->base; 1073 + w_ctr(dev->base, 0x0c); 1110 1074 1111 1075 /* Done configuration */ 1112 1076
-4
drivers/scsi/ppa.h
··· 107 107 "PS/2", 108 108 "EPP 8 bit", 109 109 "EPP 16 bit", 110 - #ifdef CONFIG_SCSI_IZIP_EPP16 111 - "EPP 16 bit", 112 - #else 113 110 "EPP 32 bit", 114 - #endif 115 111 "Unknown"}; 116 112 117 113 /* other options */
+2
drivers/scsi/qedf/qedf_dbg.h
··· 59 59 #define QEDF_LOG_NOTICE 0x40000000 /* Notice logs */ 60 60 #define QEDF_LOG_WARN 0x80000000 /* Warning logs */ 61 61 62 + #define QEDF_DEBUGFS_LOG_LEN (2 * PAGE_SIZE) 63 + 62 64 /* Debug context structure */ 63 65 struct qedf_dbg_ctx { 64 66 unsigned int host_no;
+21 -14
drivers/scsi/qedf/qedf_debugfs.c
··· 8 8 #include <linux/uaccess.h> 9 9 #include <linux/debugfs.h> 10 10 #include <linux/module.h> 11 + #include <linux/vmalloc.h> 11 12 12 13 #include "qedf.h" 13 14 #include "qedf_dbg.h" ··· 99 98 qedf_dbg_fp_int_cmd_read(struct file *filp, char __user *buffer, size_t count, 100 99 loff_t *ppos) 101 100 { 101 + ssize_t ret; 102 102 size_t cnt = 0; 103 + char *cbuf; 103 104 int id; 104 105 struct qedf_fastpath *fp = NULL; 105 106 struct qedf_dbg_ctx *qedf_dbg = ··· 111 108 112 109 QEDF_INFO(qedf_dbg, QEDF_LOG_DEBUGFS, "entered\n"); 113 110 114 - cnt = sprintf(buffer, "\nFastpath I/O completions\n\n"); 111 + cbuf = vmalloc(QEDF_DEBUGFS_LOG_LEN); 112 + if (!cbuf) 113 + return 0; 114 + 115 + cnt += scnprintf(cbuf + cnt, QEDF_DEBUGFS_LOG_LEN - cnt, "\nFastpath I/O completions\n\n"); 115 116 116 117 for (id = 0; id < qedf->num_queues; id++) { 117 118 fp = &(qedf->fp_array[id]); 118 119 if (fp->sb_id == QEDF_SB_ID_NULL) 119 120 continue; 120 - cnt += sprintf((buffer + cnt), "#%d: %lu\n", id, 121 - fp->completions); 121 + cnt += scnprintf(cbuf + cnt, QEDF_DEBUGFS_LOG_LEN - cnt, 122 + "#%d: %lu\n", id, fp->completions); 122 123 } 123 124 124 - cnt = min_t(int, count, cnt - *ppos); 125 - *ppos += cnt; 126 - return cnt; 125 + ret = simple_read_from_buffer(buffer, count, ppos, cbuf, cnt); 126 + 127 + vfree(cbuf); 128 + 129 + return ret; 127 130 } 128 131 129 132 static ssize_t ··· 147 138 loff_t *ppos) 148 139 { 149 140 int cnt; 141 + char cbuf[32]; 150 142 struct qedf_dbg_ctx *qedf_dbg = 151 143 (struct qedf_dbg_ctx *)filp->private_data; 152 144 153 145 QEDF_INFO(qedf_dbg, QEDF_LOG_DEBUGFS, "debug mask=0x%x\n", qedf_debug); 154 - cnt = sprintf(buffer, "debug mask = 0x%x\n", qedf_debug); 146 + cnt = scnprintf(cbuf, sizeof(cbuf), "debug mask = 0x%x\n", qedf_debug); 155 147 156 - cnt = min_t(int, count, cnt - *ppos); 157 - *ppos += cnt; 158 - return cnt; 148 + return simple_read_from_buffer(buffer, count, ppos, cbuf, cnt); 159 149 } 160 150 161 151 static ssize_t ··· 193 185 size_t count, loff_t *ppos) 194 186 { 195 187 int cnt; 188 + char cbuf[7]; 196 189 struct qedf_dbg_ctx *qedf_dbg = 197 190 (struct qedf_dbg_ctx *)filp->private_data; 198 191 struct qedf_ctx *qedf = container_of(qedf_dbg, 199 192 struct qedf_ctx, dbg_ctx); 200 193 201 194 QEDF_INFO(qedf_dbg, QEDF_LOG_DEBUGFS, "entered\n"); 202 - cnt = sprintf(buffer, "%s\n", 195 + cnt = scnprintf(cbuf, sizeof(cbuf), "%s\n", 203 196 qedf->stop_io_on_error ? "true" : "false"); 204 197 205 - cnt = min_t(int, count, cnt - *ppos); 206 - *ppos += cnt; 207 - return cnt; 198 + return simple_read_from_buffer(buffer, count, ppos, cbuf, cnt); 208 199 } 209 200 210 201 static ssize_t
+5 -4
drivers/scsi/qla2xxx/qla_def.h
··· 466 466 } 467 467 468 468 struct tmf_arg { 469 + struct list_head tmf_elem; 469 470 struct qla_qpair *qpair; 470 471 struct fc_port *fcport; 471 472 struct scsi_qla_host *vha; ··· 2542 2541 typedef struct fc_port { 2543 2542 struct list_head list; 2544 2543 struct scsi_qla_host *vha; 2545 - struct list_head tmf_pending; 2546 2544 2547 2545 unsigned int conf_compl_supported:1; 2548 2546 unsigned int deleted:2; ··· 2562 2562 unsigned int do_prli_nvme:1; 2563 2563 2564 2564 uint8_t nvme_flag; 2565 - uint8_t active_tmf; 2566 - #define MAX_ACTIVE_TMF 8 2567 - 2568 2565 uint8_t node_name[WWN_SIZE]; 2569 2566 uint8_t port_name[WWN_SIZE]; 2570 2567 port_id_t d_id; ··· 4653 4656 uint32_t flt_region_aux_img_status_sec; 4654 4657 }; 4655 4658 uint8_t active_image; 4659 + uint8_t active_tmf; 4660 + #define MAX_ACTIVE_TMF 8 4656 4661 4657 4662 /* Needed for BEACON */ 4658 4663 uint16_t beacon_blink_led; ··· 4669 4670 4670 4671 struct qla_msix_entry *msix_entries; 4671 4672 4673 + struct list_head tmf_pending; 4674 + struct list_head tmf_active; 4672 4675 struct list_head vp_list; /* list of VP */ 4673 4676 unsigned long vp_idx_map[(MAX_MULTI_ID_FABRIC / 8) / 4674 4677 sizeof(unsigned long)];
+1 -10
drivers/scsi/qla2xxx/qla_gbl.h
··· 48 48 extern void qla2x00_els_dcmd2_free(scsi_qla_host_t *vha, 49 49 struct els_plogi *els_plogi); 50 50 51 - extern void qla2x00_update_fcports(scsi_qla_host_t *); 52 - 53 51 extern int qla2x00_abort_isp(scsi_qla_host_t *); 54 52 extern void qla2x00_abort_isp_cleanup(scsi_qla_host_t *); 55 53 extern void qla2x00_quiesce_io(scsi_qla_host_t *); ··· 141 143 void qla_edif_clear_appdata(struct scsi_qla_host *vha, 142 144 struct fc_port *fcport); 143 145 const char *sc_to_str(uint16_t cmd); 146 + void qla_adjust_iocb_limit(scsi_qla_host_t *vha); 144 147 145 148 /* 146 149 * Global Data in qla_os.c source file. ··· 204 205 uint16_t *); 205 206 extern int qla2x00_post_async_adisc_work(struct scsi_qla_host *, fc_port_t *, 206 207 uint16_t *); 207 - extern int qla2x00_post_async_adisc_done_work(struct scsi_qla_host *, 208 - fc_port_t *, uint16_t *); 209 208 extern int qla2x00_set_exlogins_buffer(struct scsi_qla_host *); 210 209 extern void qla2x00_free_exlogin_buffer(struct qla_hw_data *); 211 210 extern int qla2x00_set_exchoffld_buffer(struct scsi_qla_host *); ··· 213 216 214 217 extern struct scsi_qla_host *qla2x00_create_host(const struct scsi_host_template *, 215 218 struct qla_hw_data *); 216 - extern void qla2x00_free_host(struct scsi_qla_host *); 217 219 extern void qla2x00_relogin(struct scsi_qla_host *); 218 220 extern void qla2x00_do_work(struct scsi_qla_host *); 219 221 extern void qla2x00_free_fcports(struct scsi_qla_host *); ··· 234 238 235 239 extern int qla2x00_post_uevent_work(struct scsi_qla_host *, u32); 236 240 extern void qla2x00_disable_board_on_pci_error(struct work_struct *); 237 - extern void qla_eeh_work(struct work_struct *); 238 241 extern void qla2x00_sp_compl(srb_t *sp, int); 239 242 extern void qla2xxx_qpair_sp_free_dma(srb_t *sp); 240 243 extern void qla2xxx_qpair_sp_compl(srb_t *sp, int); 241 244 extern void qla24xx_sched_upd_fcport(fc_port_t *); 242 - void qla2x00_handle_login_done_event(struct scsi_qla_host *, fc_port_t *, 243 - uint16_t *); 244 245 int qla24xx_post_gnl_work(struct scsi_qla_host *, fc_port_t *); 245 246 int qla24xx_post_relogin_work(struct scsi_qla_host *vha); 246 247 void qla2x00_wait_for_sess_deletion(scsi_qla_host_t *); ··· 721 728 int qla24xx_async_gpsc(scsi_qla_host_t *, fc_port_t *); 722 729 void qla24xx_handle_gpsc_event(scsi_qla_host_t *, struct event_arg *); 723 730 int qla2x00_mgmt_svr_login(scsi_qla_host_t *); 724 - void qla24xx_handle_gffid_event(scsi_qla_host_t *vha, struct event_arg *ea); 725 731 int qla24xx_async_gffid(scsi_qla_host_t *vha, fc_port_t *fcport, bool); 726 732 int qla24xx_async_gpnft(scsi_qla_host_t *, u8, srb_t *); 727 733 void qla24xx_async_gpnft_done(scsi_qla_host_t *, srb_t *); ··· 843 851 844 852 /* Interrupt related */ 845 853 extern irqreturn_t qla82xx_intr_handler(int, void *); 846 - extern irqreturn_t qla82xx_msi_handler(int, void *); 847 854 extern irqreturn_t qla82xx_msix_default(int, void *); 848 855 extern irqreturn_t qla82xx_msix_rsp_q(int, void *); 849 856 extern void qla82xx_enable_intrs(struct qla_hw_data *);
+135 -82
drivers/scsi/qla2xxx/qla_init.c
··· 508 508 void qla24xx_handle_adisc_event(scsi_qla_host_t *vha, struct event_arg *ea) 509 509 { 510 510 struct fc_port *fcport = ea->fcport; 511 + unsigned long flags; 511 512 512 513 ql_dbg(ql_dbg_disc, vha, 0x20d2, 513 514 "%s %8phC DS %d LS %d rc %d login %d|%d rscn %d|%d lid %d\n", ··· 523 522 ql_dbg(ql_dbg_disc, vha, 0x2066, 524 523 "%s %8phC: adisc fail: post delete\n", 525 524 __func__, ea->fcport->port_name); 525 + 526 + spin_lock_irqsave(&vha->work_lock, flags); 526 527 /* deleted = 0 & logout_on_delete = force fw cleanup */ 527 - fcport->deleted = 0; 528 + if (fcport->deleted == QLA_SESS_DELETED) 529 + fcport->deleted = 0; 530 + 528 531 fcport->logout_on_delete = 1; 532 + spin_unlock_irqrestore(&vha->work_lock, flags); 533 + 529 534 qlt_schedule_sess_for_deletion(ea->fcport); 530 535 return; 531 536 } ··· 1141 1134 u16 *mb; 1142 1135 1143 1136 if (!vha->flags.online || (fcport->flags & FCF_ASYNC_SENT)) 1144 - return rval; 1137 + goto done; 1145 1138 1146 1139 ql_dbg(ql_dbg_disc, vha, 0x20d9, 1147 1140 "Async-gnlist WWPN %8phC \n", fcport->port_name); ··· 1195 1188 done_free_sp: 1196 1189 /* ref: INIT */ 1197 1190 kref_put(&sp->cmd_kref, qla2x00_sp_release); 1191 + fcport->flags &= ~(FCF_ASYNC_SENT); 1198 1192 done: 1199 - fcport->flags &= ~(FCF_ASYNC_ACTIVE | FCF_ASYNC_SENT); 1193 + fcport->flags &= ~(FCF_ASYNC_ACTIVE); 1200 1194 return rval; 1201 1195 } 1202 1196 ··· 1454 1446 1455 1447 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags); 1456 1448 ea->fcport->login_gen++; 1457 - ea->fcport->deleted = 0; 1458 1449 ea->fcport->logout_on_delete = 1; 1459 1450 1460 1451 if (!ea->fcport->login_succ && !IS_SW_RESV_ADDR(ea->fcport->d_id)) { ··· 2003 1996 int rc, h; 2004 1997 unsigned long flags; 2005 1998 2006 - if (sp->type == SRB_MARKER) { 2007 - complete(&tmf->u.tmf.comp); 2008 - return; 2009 - } 1999 + if (sp->type == SRB_MARKER) 2000 + rc = QLA_FUNCTION_FAILED; 2001 + else 2002 + rc = qla24xx_async_abort_cmd(sp, false); 2010 2003 2011 - rc = qla24xx_async_abort_cmd(sp, false); 2012 2004 if (rc) { 2013 2005 spin_lock_irqsave(sp->qpair->qp_lock_ptr, flags); 2014 2006 for (h = 1; h < sp->qpair->req->num_outstanding_cmds; h++) { ··· 2038 2032 complete(&tmf->u.tmf.comp); 2039 2033 } 2040 2034 2041 - #define START_SP_W_RETRIES(_sp, _rval) \ 2035 + #define START_SP_W_RETRIES(_sp, _rval, _chip_gen, _login_gen) \ 2042 2036 {\ 2043 2037 int cnt = 5; \ 2044 2038 do { \ 2039 + if (_chip_gen != sp->vha->hw->chip_reset || _login_gen != sp->fcport->login_gen) {\ 2040 + _rval = EINVAL; \ 2041 + break; \ 2042 + } \ 2045 2043 _rval = qla2x00_start_sp(_sp); \ 2046 2044 if (_rval == EAGAIN) \ 2047 2045 msleep(1); \ ··· 2068 2058 srb_t *sp; 2069 2059 int rval = QLA_FUNCTION_FAILED; 2070 2060 fc_port_t *fcport = arg->fcport; 2061 + u32 chip_gen, login_gen; 2071 2062 2072 2063 if (TMF_NOT_READY(arg->fcport)) { 2073 2064 ql_dbg(ql_dbg_taskm, vha, 0x8039, ··· 2077 2066 arg->modifier, arg->lun, arg->qpair->id); 2078 2067 return QLA_SUSPENDED; 2079 2068 } 2069 + 2070 + chip_gen = vha->hw->chip_reset; 2071 + login_gen = fcport->login_gen; 2080 2072 2081 2073 /* ref: INIT */ 2082 2074 sp = qla2xxx_get_qpair_sp(vha, arg->qpair, fcport, GFP_KERNEL); ··· 2098 2084 tm_iocb->u.tmf.loop_id = fcport->loop_id; 2099 2085 tm_iocb->u.tmf.vp_index = vha->vp_idx; 2100 2086 2101 - START_SP_W_RETRIES(sp, rval); 2087 + START_SP_W_RETRIES(sp, rval, chip_gen, login_gen); 2102 2088 2103 2089 ql_dbg(ql_dbg_taskm, vha, 0x8006, 2104 2090 "Async-marker hdl=%x loop-id=%x portid=%06x modifier=%x lun=%lld qp=%d rval %d.\n", ··· 2137 2123 complete(&tmf->u.tmf.comp); 2138 2124 } 2139 2125 2126 + static int qla_tmf_wait(struct tmf_arg *arg) 2127 + { 2128 + /* there are only 2 types of error handling that reaches here, lun or target reset */ 2129 + if (arg->flags & (TCF_LUN_RESET | TCF_ABORT_TASK_SET | TCF_CLEAR_TASK_SET)) 2130 + return qla2x00_eh_wait_for_pending_commands(arg->vha, 2131 + arg->fcport->d_id.b24, arg->lun, WAIT_LUN); 2132 + else 2133 + return qla2x00_eh_wait_for_pending_commands(arg->vha, 2134 + arg->fcport->d_id.b24, arg->lun, WAIT_TARGET); 2135 + } 2136 + 2140 2137 static int 2141 2138 __qla2x00_async_tm_cmd(struct tmf_arg *arg) 2142 2139 { ··· 2155 2130 struct srb_iocb *tm_iocb; 2156 2131 srb_t *sp; 2157 2132 int rval = QLA_FUNCTION_FAILED; 2158 - 2159 2133 fc_port_t *fcport = arg->fcport; 2134 + u32 chip_gen, login_gen; 2135 + u64 jif; 2160 2136 2161 2137 if (TMF_NOT_READY(arg->fcport)) { 2162 2138 ql_dbg(ql_dbg_taskm, vha, 0x8032, ··· 2166 2140 arg->modifier, arg->lun, arg->qpair->id); 2167 2141 return QLA_SUSPENDED; 2168 2142 } 2143 + 2144 + chip_gen = vha->hw->chip_reset; 2145 + login_gen = fcport->login_gen; 2169 2146 2170 2147 /* ref: INIT */ 2171 2148 sp = qla2xxx_get_qpair_sp(vha, arg->qpair, fcport, GFP_KERNEL); ··· 2187 2158 tm_iocb->u.tmf.flags = arg->flags; 2188 2159 tm_iocb->u.tmf.lun = arg->lun; 2189 2160 2190 - START_SP_W_RETRIES(sp, rval); 2161 + START_SP_W_RETRIES(sp, rval, chip_gen, login_gen); 2191 2162 2192 2163 ql_dbg(ql_dbg_taskm, vha, 0x802f, 2193 2164 "Async-tmf hdl=%x loop-id=%x portid=%06x ctrl=%x lun=%lld qp=%d rval=%x.\n", ··· 2205 2176 "TM IOCB failed (%x).\n", rval); 2206 2177 } 2207 2178 2208 - if (!test_bit(UNLOADING, &vha->dpc_flags) && !IS_QLAFX00(vha->hw)) 2209 - rval = qla26xx_marker(arg); 2179 + if (!test_bit(UNLOADING, &vha->dpc_flags) && !IS_QLAFX00(vha->hw)) { 2180 + jif = jiffies; 2181 + if (qla_tmf_wait(arg)) { 2182 + ql_log(ql_log_info, vha, 0x803e, 2183 + "Waited %u ms Nexus=%ld:%06x:%llu.\n", 2184 + jiffies_to_msecs(jiffies - jif), vha->host_no, 2185 + fcport->d_id.b24, arg->lun); 2186 + } 2187 + 2188 + if (chip_gen == vha->hw->chip_reset && login_gen == fcport->login_gen) { 2189 + rval = qla26xx_marker(arg); 2190 + } else { 2191 + ql_log(ql_log_info, vha, 0x803e, 2192 + "Skip Marker due to disruption. Nexus=%ld:%06x:%llu.\n", 2193 + vha->host_no, fcport->d_id.b24, arg->lun); 2194 + rval = QLA_FUNCTION_FAILED; 2195 + } 2196 + } 2210 2197 2211 2198 done_free_sp: 2212 2199 /* ref: INIT */ ··· 2231 2186 return rval; 2232 2187 } 2233 2188 2234 - static void qla_put_tmf(fc_port_t *fcport) 2189 + static void qla_put_tmf(struct tmf_arg *arg) 2235 2190 { 2236 - struct scsi_qla_host *vha = fcport->vha; 2191 + struct scsi_qla_host *vha = arg->vha; 2237 2192 struct qla_hw_data *ha = vha->hw; 2238 2193 unsigned long flags; 2239 2194 2240 2195 spin_lock_irqsave(&ha->tgt.sess_lock, flags); 2241 - fcport->active_tmf--; 2196 + ha->active_tmf--; 2197 + list_del(&arg->tmf_elem); 2242 2198 spin_unlock_irqrestore(&ha->tgt.sess_lock, flags); 2243 2199 } 2244 2200 2245 2201 static 2246 - int qla_get_tmf(fc_port_t *fcport) 2202 + int qla_get_tmf(struct tmf_arg *arg) 2247 2203 { 2248 - struct scsi_qla_host *vha = fcport->vha; 2204 + struct scsi_qla_host *vha = arg->vha; 2249 2205 struct qla_hw_data *ha = vha->hw; 2250 2206 unsigned long flags; 2207 + fc_port_t *fcport = arg->fcport; 2251 2208 int rc = 0; 2252 - LIST_HEAD(tmf_elem); 2209 + struct tmf_arg *t; 2253 2210 2254 2211 spin_lock_irqsave(&ha->tgt.sess_lock, flags); 2255 - list_add_tail(&tmf_elem, &fcport->tmf_pending); 2212 + list_for_each_entry(t, &ha->tmf_active, tmf_elem) { 2213 + if (t->fcport == arg->fcport && t->lun == arg->lun) { 2214 + /* reject duplicate TMF */ 2215 + ql_log(ql_log_warn, vha, 0x802c, 2216 + "found duplicate TMF. Nexus=%ld:%06x:%llu.\n", 2217 + vha->host_no, fcport->d_id.b24, arg->lun); 2218 + spin_unlock_irqrestore(&ha->tgt.sess_lock, flags); 2219 + return -EINVAL; 2220 + } 2221 + } 2256 2222 2257 - while (fcport->active_tmf >= MAX_ACTIVE_TMF) { 2223 + list_add_tail(&arg->tmf_elem, &ha->tmf_pending); 2224 + while (ha->active_tmf >= MAX_ACTIVE_TMF) { 2258 2225 spin_unlock_irqrestore(&ha->tgt.sess_lock, flags); 2259 2226 2260 2227 msleep(1); ··· 2278 2221 rc = EIO; 2279 2222 break; 2280 2223 } 2281 - if (fcport->active_tmf < MAX_ACTIVE_TMF && 2282 - list_is_first(&tmf_elem, &fcport->tmf_pending)) 2224 + if (ha->active_tmf < MAX_ACTIVE_TMF && 2225 + list_is_first(&arg->tmf_elem, &ha->tmf_pending)) 2283 2226 break; 2284 2227 } 2285 2228 2286 - list_del(&tmf_elem); 2229 + list_del(&arg->tmf_elem); 2287 2230 2288 - if (!rc) 2289 - fcport->active_tmf++; 2231 + if (!rc) { 2232 + ha->active_tmf++; 2233 + list_add_tail(&arg->tmf_elem, &ha->tmf_active); 2234 + } 2290 2235 2291 2236 spin_unlock_irqrestore(&ha->tgt.sess_lock, flags); 2292 2237 ··· 2300 2241 uint32_t tag) 2301 2242 { 2302 2243 struct scsi_qla_host *vha = fcport->vha; 2303 - struct qla_qpair *qpair; 2304 2244 struct tmf_arg a; 2305 - int i, rval = QLA_SUCCESS; 2245 + int rval = QLA_SUCCESS; 2306 2246 2307 2247 if (TMF_NOT_READY(fcport)) 2308 2248 return QLA_SUSPENDED; ··· 2309 2251 a.vha = fcport->vha; 2310 2252 a.fcport = fcport; 2311 2253 a.lun = lun; 2254 + a.flags = flags; 2255 + INIT_LIST_HEAD(&a.tmf_elem); 2256 + 2312 2257 if (flags & (TCF_LUN_RESET|TCF_ABORT_TASK_SET|TCF_CLEAR_TASK_SET|TCF_CLEAR_ACA)) { 2313 2258 a.modifier = MK_SYNC_ID_LUN; 2314 - 2315 - if (qla_get_tmf(fcport)) 2316 - return QLA_FUNCTION_FAILED; 2317 2259 } else { 2318 2260 a.modifier = MK_SYNC_ID; 2319 2261 } 2320 2262 2321 - if (vha->hw->mqenable) { 2322 - for (i = 0; i < vha->hw->num_qpairs; i++) { 2323 - qpair = vha->hw->queue_pair_map[i]; 2324 - if (!qpair) 2325 - continue; 2326 - 2327 - if (TMF_NOT_READY(fcport)) { 2328 - ql_log(ql_log_warn, vha, 0x8026, 2329 - "Unable to send TM due to disruption.\n"); 2330 - rval = QLA_SUSPENDED; 2331 - break; 2332 - } 2333 - 2334 - a.qpair = qpair; 2335 - a.flags = flags|TCF_NOTMCMD_TO_TARGET; 2336 - rval = __qla2x00_async_tm_cmd(&a); 2337 - if (rval) 2338 - break; 2339 - } 2340 - } 2341 - 2342 - if (rval) 2343 - goto bailout; 2263 + if (qla_get_tmf(&a)) 2264 + return QLA_FUNCTION_FAILED; 2344 2265 2345 2266 a.qpair = vha->hw->base_qpair; 2346 - a.flags = flags; 2347 2267 rval = __qla2x00_async_tm_cmd(&a); 2348 2268 2349 - bailout: 2350 - if (a.modifier == MK_SYNC_ID_LUN) 2351 - qla_put_tmf(fcport); 2352 - 2269 + qla_put_tmf(&a); 2353 2270 return rval; 2354 2271 } 2355 2272 ··· 4180 4147 return ha->flags.lr_detected; 4181 4148 } 4182 4149 4183 - void qla_init_iocb_limit(scsi_qla_host_t *vha) 4150 + static void __qla_adjust_iocb_limit(struct qla_qpair *qpair) 4184 4151 { 4185 - u16 i, num_qps; 4186 - u32 limit; 4187 - struct qla_hw_data *ha = vha->hw; 4152 + u8 num_qps; 4153 + u16 limit; 4154 + struct qla_hw_data *ha = qpair->vha->hw; 4188 4155 4189 4156 num_qps = ha->num_qpairs + 1; 4190 4157 limit = (ha->orig_fw_iocb_count * QLA_IOCB_PCT_LIMIT) / 100; 4191 4158 4192 - ha->base_qpair->fwres.iocbs_total = ha->orig_fw_iocb_count; 4193 - ha->base_qpair->fwres.iocbs_limit = limit; 4194 - ha->base_qpair->fwres.iocbs_qp_limit = limit / num_qps; 4195 - ha->base_qpair->fwres.iocbs_used = 0; 4159 + qpair->fwres.iocbs_total = ha->orig_fw_iocb_count; 4160 + qpair->fwres.iocbs_limit = limit; 4161 + qpair->fwres.iocbs_qp_limit = limit / num_qps; 4196 4162 4197 - ha->base_qpair->fwres.exch_total = ha->orig_fw_xcb_count; 4198 - ha->base_qpair->fwres.exch_limit = (ha->orig_fw_xcb_count * 4199 - QLA_IOCB_PCT_LIMIT) / 100; 4163 + qpair->fwres.exch_total = ha->orig_fw_xcb_count; 4164 + qpair->fwres.exch_limit = (ha->orig_fw_xcb_count * 4165 + QLA_IOCB_PCT_LIMIT) / 100; 4166 + } 4167 + 4168 + void qla_init_iocb_limit(scsi_qla_host_t *vha) 4169 + { 4170 + u8 i; 4171 + struct qla_hw_data *ha = vha->hw; 4172 + 4173 + __qla_adjust_iocb_limit(ha->base_qpair); 4174 + ha->base_qpair->fwres.iocbs_used = 0; 4200 4175 ha->base_qpair->fwres.exch_used = 0; 4201 4176 4202 4177 for (i = 0; i < ha->max_qpairs; i++) { 4203 4178 if (ha->queue_pair_map[i]) { 4204 - ha->queue_pair_map[i]->fwres.iocbs_total = 4205 - ha->orig_fw_iocb_count; 4206 - ha->queue_pair_map[i]->fwres.iocbs_limit = limit; 4207 - ha->queue_pair_map[i]->fwres.iocbs_qp_limit = 4208 - limit / num_qps; 4179 + __qla_adjust_iocb_limit(ha->queue_pair_map[i]); 4209 4180 ha->queue_pair_map[i]->fwres.iocbs_used = 0; 4210 - ha->queue_pair_map[i]->fwres.exch_total = ha->orig_fw_xcb_count; 4211 - ha->queue_pair_map[i]->fwres.exch_limit = 4212 - (ha->orig_fw_xcb_count * QLA_IOCB_PCT_LIMIT) / 100; 4213 4181 ha->queue_pair_map[i]->fwres.exch_used = 0; 4214 4182 } 4183 + } 4184 + } 4185 + 4186 + void qla_adjust_iocb_limit(scsi_qla_host_t *vha) 4187 + { 4188 + u8 i; 4189 + struct qla_hw_data *ha = vha->hw; 4190 + 4191 + __qla_adjust_iocb_limit(ha->base_qpair); 4192 + 4193 + for (i = 0; i < ha->max_qpairs; i++) { 4194 + if (ha->queue_pair_map[i]) 4195 + __qla_adjust_iocb_limit(ha->queue_pair_map[i]); 4215 4196 } 4216 4197 } 4217 4198 ··· 4824 4777 if (ha->flags.edif_enabled) 4825 4778 mid_init_cb->init_cb.frame_payload_size = cpu_to_le16(ELS_MAX_PAYLOAD); 4826 4779 4780 + QLA_FW_STARTED(ha); 4827 4781 rval = qla2x00_init_firmware(vha, ha->init_cb_size); 4828 4782 next_check: 4829 4783 if (rval) { 4784 + QLA_FW_STOPPED(ha); 4830 4785 ql_log(ql_log_fatal, vha, 0x00d2, 4831 4786 "Init Firmware **** FAILED ****.\n"); 4832 4787 } else { 4833 4788 ql_dbg(ql_dbg_init, vha, 0x00d3, 4834 4789 "Init Firmware -- success.\n"); 4835 - QLA_FW_STARTED(ha); 4836 4790 vha->u_ql2xexchoffld = vha->u_ql2xiniexchg = 0; 4837 4791 } 4838 4792 ··· 5554 5506 INIT_WORK(&fcport->reg_work, qla_register_fcport_fn); 5555 5507 INIT_LIST_HEAD(&fcport->gnl_entry); 5556 5508 INIT_LIST_HEAD(&fcport->list); 5557 - INIT_LIST_HEAD(&fcport->tmf_pending); 5558 5509 5559 5510 INIT_LIST_HEAD(&fcport->sess_cmd_list); 5560 5511 spin_lock_init(&fcport->sess_cmd_lock); ··· 6137 6090 void 6138 6091 qla2x00_update_fcport(scsi_qla_host_t *vha, fc_port_t *fcport) 6139 6092 { 6093 + unsigned long flags; 6094 + 6140 6095 if (IS_SW_RESV_ADDR(fcport->d_id)) 6141 6096 return; 6142 6097 ··· 6148 6099 qla2x00_set_fcport_disc_state(fcport, DSC_UPD_FCPORT); 6149 6100 fcport->login_retry = vha->hw->login_retry_count; 6150 6101 fcport->flags &= ~(FCF_LOGIN_NEEDED | FCF_ASYNC_SENT); 6102 + 6103 + spin_lock_irqsave(&vha->work_lock, flags); 6151 6104 fcport->deleted = 0; 6105 + spin_unlock_irqrestore(&vha->work_lock, flags); 6106 + 6152 6107 if (vha->hw->current_topology == ISP_CFG_NL) 6153 6108 fcport->logout_on_delete = 0; 6154 6109 else
+1
drivers/scsi/qla2xxx/qla_iocb.c
··· 3882 3882 { 3883 3883 mrk->entry_type = MARKER_TYPE; 3884 3884 mrk->modifier = sp->u.iocb_cmd.u.tmf.modifier; 3885 + mrk->handle = make_handle(sp->qpair->req->id, sp->handle); 3885 3886 if (sp->u.iocb_cmd.u.tmf.modifier != MK_SYNC_ALL) { 3886 3887 mrk->nport_handle = cpu_to_le16(sp->u.iocb_cmd.u.tmf.loop_id); 3887 3888 int_to_scsilun(sp->u.iocb_cmd.u.tmf.lun, (struct scsi_lun *)&mrk->lun);
+5 -2
drivers/scsi/qla2xxx/qla_isr.c
··· 1121 1121 unsigned long flags; 1122 1122 fc_port_t *fcport = NULL; 1123 1123 1124 - if (!vha->hw->flags.fw_started) 1124 + if (!vha->hw->flags.fw_started) { 1125 + ql_log(ql_log_warn, vha, 0x50ff, 1126 + "Dropping AEN - %04x %04x %04x %04x.\n", 1127 + mb[0], mb[1], mb[2], mb[3]); 1125 1128 return; 1129 + } 1126 1130 1127 1131 /* Setup to process RIO completion. */ 1128 1132 handle_cnt = 0; ··· 2543 2539 case CS_PORT_BUSY: 2544 2540 case CS_INCOMPLETE: 2545 2541 case CS_PORT_UNAVAILABLE: 2546 - case CS_TIMEOUT: 2547 2542 case CS_RESET: 2548 2543 if (atomic_read(&fcport->state) == FCS_ONLINE) { 2549 2544 ql_dbg(ql_dbg_disc, fcport->vha, 0x3021,
+3
drivers/scsi/qla2xxx/qla_mbx.c
··· 2213 2213 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1054, 2214 2214 "Entered %s.\n", __func__); 2215 2215 2216 + if (!ha->flags.fw_started) 2217 + return QLA_FUNCTION_FAILED; 2218 + 2216 2219 mcp->mb[0] = MBC_GET_FIRMWARE_STATE; 2217 2220 mcp->out_mb = MBX_0; 2218 2221 if (IS_FWI2_CAPABLE(vha->hw))
+2 -1
drivers/scsi/qla2xxx/qla_nvme.c
··· 132 132 "Failed to allocate qpair\n"); 133 133 return -EINVAL; 134 134 } 135 + qla_adjust_iocb_limit(vha); 135 136 } 136 137 *handle = qpair; 137 138 ··· 668 667 669 668 rval = qla2x00_start_nvme_mq(sp); 670 669 if (rval != QLA_SUCCESS) { 671 - ql_log(ql_log_warn, vha, 0x212d, 670 + ql_dbg(ql_dbg_io + ql_dbg_verbose, vha, 0x212d, 672 671 "qla2x00_start_nvme_mq failed = %d\n", rval); 673 672 sp->priv = NULL; 674 673 priv->sp = NULL;
+7 -4
drivers/scsi/qla2xxx/qla_os.c
··· 1488 1488 goto eh_reset_failed; 1489 1489 } 1490 1490 err = 3; 1491 - if (qla2x00_eh_wait_for_pending_commands(vha, sdev->id, 1492 - sdev->lun, WAIT_LUN) != QLA_SUCCESS) { 1491 + if (qla2x00_eh_wait_for_pending_commands(vha, fcport->d_id.b24, 1492 + cmd->device->lun, 1493 + WAIT_LUN) != QLA_SUCCESS) { 1493 1494 ql_log(ql_log_warn, vha, 0x800d, 1494 1495 "wait for pending cmds failed for cmd=%p.\n", cmd); 1495 1496 goto eh_reset_failed; ··· 1556 1555 goto eh_reset_failed; 1557 1556 } 1558 1557 err = 3; 1559 - if (qla2x00_eh_wait_for_pending_commands(vha, sdev->id, 1560 - 0, WAIT_TARGET) != QLA_SUCCESS) { 1558 + if (qla2x00_eh_wait_for_pending_commands(vha, fcport->d_id.b24, 0, 1559 + WAIT_TARGET) != QLA_SUCCESS) { 1561 1560 ql_log(ql_log_warn, vha, 0x800d, 1562 1561 "wait for pending cmds failed for cmd=%p.\n", cmd); 1563 1562 goto eh_reset_failed; ··· 3010 3009 atomic_set(&ha->num_pend_mbx_stage3, 0); 3011 3010 atomic_set(&ha->zio_threshold, DEFAULT_ZIO_THRESHOLD); 3012 3011 ha->last_zio_threshold = DEFAULT_ZIO_THRESHOLD; 3012 + INIT_LIST_HEAD(&ha->tmf_pending); 3013 + INIT_LIST_HEAD(&ha->tmf_active); 3013 3014 3014 3015 /* Assign ISP specific operations. */ 3015 3016 if (IS_QLA2100(ha)) {
+7 -7
drivers/scsi/qla2xxx/qla_target.c
··· 1068 1068 (struct imm_ntfy_from_isp *)sess->iocb, SRB_NACK_LOGO); 1069 1069 } 1070 1070 1071 - spin_lock_irqsave(&vha->work_lock, flags); 1072 - sess->flags &= ~FCF_ASYNC_SENT; 1073 - spin_unlock_irqrestore(&vha->work_lock, flags); 1074 - 1075 1071 spin_lock_irqsave(&ha->tgt.sess_lock, flags); 1076 1072 if (sess->se_sess) { 1077 1073 sess->se_sess = NULL; ··· 1077 1081 1078 1082 qla2x00_set_fcport_disc_state(sess, DSC_DELETED); 1079 1083 sess->fw_login_state = DSC_LS_PORT_UNAVAIL; 1080 - sess->deleted = QLA_SESS_DELETED; 1081 1084 1082 1085 if (sess->login_succ && !IS_SW_RESV_ADDR(sess->d_id)) { 1083 1086 vha->fcport_count--; ··· 1128 1133 1129 1134 sess->explicit_logout = 0; 1130 1135 spin_unlock_irqrestore(&ha->tgt.sess_lock, flags); 1131 - sess->free_pending = 0; 1132 1136 1133 1137 qla2x00_dfs_remove_rport(vha, sess); 1138 + 1139 + spin_lock_irqsave(&vha->work_lock, flags); 1140 + sess->flags &= ~FCF_ASYNC_SENT; 1141 + sess->deleted = QLA_SESS_DELETED; 1142 + sess->free_pending = 0; 1143 + spin_unlock_irqrestore(&vha->work_lock, flags); 1134 1144 1135 1145 ql_dbg(ql_dbg_disc, vha, 0xf001, 1136 1146 "Unregistration of sess %p %8phC finished fcp_cnt %d\n", ··· 1185 1185 * management from being sent. 1186 1186 */ 1187 1187 sess->flags |= FCF_ASYNC_SENT; 1188 + sess->deleted = QLA_SESS_DELETION_IN_PROGRESS; 1188 1189 spin_unlock_irqrestore(&sess->vha->work_lock, flags); 1189 1190 1190 1191 if (sess->se_sess) 1191 1192 vha->hw->tgt.tgt_ops->clear_nacl_from_fcport_map(sess); 1192 1193 1193 - sess->deleted = QLA_SESS_DELETION_IN_PROGRESS; 1194 1194 qla2x00_set_fcport_disc_state(sess, DSC_DELETE_PEND); 1195 1195 sess->last_rscn_gen = sess->rscn_gen; 1196 1196 sess->last_login_gen = sess->login_gen;
+2 -2
drivers/scsi/qla2xxx/qla_version.h
··· 6 6 /* 7 7 * Driver version 8 8 */ 9 - #define QLA2XXX_VERSION "10.02.08.400-k" 9 + #define QLA2XXX_VERSION "10.02.08.500-k" 10 10 11 11 #define QLA_DRIVER_MAJOR_VER 10 12 12 #define QLA_DRIVER_MINOR_VER 2 13 13 #define QLA_DRIVER_PATCH_VER 8 14 - #define QLA_DRIVER_BETA_VER 400 14 + #define QLA_DRIVER_BETA_VER 500
+15
drivers/scsi/qla4xxx/ql4_os.c
··· 968 968 memset(&chap_rec, 0, sizeof(chap_rec)); 969 969 970 970 nla_for_each_attr(attr, data, len, rem) { 971 + if (nla_len(attr) < sizeof(*param_info)) { 972 + rc = -EINVAL; 973 + goto exit_set_chap; 974 + } 975 + 971 976 param_info = nla_data(attr); 972 977 973 978 switch (param_info->param) { ··· 2755 2750 } 2756 2751 2757 2752 nla_for_each_attr(attr, data, len, rem) { 2753 + if (nla_len(attr) < sizeof(*iface_param)) { 2754 + rval = -EINVAL; 2755 + goto exit_init_fw_cb; 2756 + } 2757 + 2758 2758 iface_param = nla_data(attr); 2759 2759 2760 2760 if (iface_param->param_type == ISCSI_NET_PARAM) { ··· 8114 8104 8115 8105 memset((void *)&chap_tbl, 0, sizeof(chap_tbl)); 8116 8106 nla_for_each_attr(attr, data, len, rem) { 8107 + if (nla_len(attr) < sizeof(*fnode_param)) { 8108 + rc = -EINVAL; 8109 + goto exit_set_param; 8110 + } 8111 + 8117 8112 fnode_param = nla_data(attr); 8118 8113 8119 8114 switch (fnode_param->param) {
+2 -2
drivers/scsi/qlogicpti.c
··· 28 28 #include <linux/jiffies.h> 29 29 #include <linux/dma-mapping.h> 30 30 #include <linux/of.h> 31 - #include <linux/of_device.h> 31 + #include <linux/platform_device.h> 32 32 #include <linux/firmware.h> 33 33 #include <linux/pgtable.h> 34 34 ··· 843 843 return 0; 844 844 } 845 845 846 - const char *qlogicpti_info(struct Scsi_Host *host) 846 + static const char *qlogicpti_info(struct Scsi_Host *host) 847 847 { 848 848 static char buf[80]; 849 849 struct qlogicpti *qpti = (struct qlogicpti *) host->hostdata;
-2
drivers/scsi/scsi_priv.h
··· 103 103 void scsi_eh_done(struct scsi_cmnd *scmd); 104 104 105 105 /* scsi_lib.c */ 106 - extern int scsi_maybe_unblock_host(struct scsi_device *sdev); 107 106 extern void scsi_device_unbusy(struct scsi_device *sdev, struct scsi_cmnd *cmd); 108 107 extern void scsi_queue_insert(struct scsi_cmnd *cmd, int reason); 109 108 extern void scsi_io_completion(struct scsi_cmnd *, unsigned int); ··· 154 155 extern int scsi_sysfs_register(void); 155 156 extern void scsi_sysfs_unregister(void); 156 157 extern void scsi_sysfs_device_initialize(struct scsi_device *); 157 - extern int scsi_sysfs_target_initialize(struct scsi_device *); 158 158 extern struct scsi_transport_template blank_transport_template; 159 159 extern void __scsi_remove_device(struct scsi_device *); 160 160
+51 -29
drivers/scsi/scsi_transport_iscsi.c
··· 3014 3014 } 3015 3015 3016 3016 static int 3017 - iscsi_if_set_param(struct iscsi_transport *transport, struct iscsi_uevent *ev) 3017 + iscsi_if_set_param(struct iscsi_transport *transport, struct iscsi_uevent *ev, u32 rlen) 3018 3018 { 3019 3019 char *data = (char*)ev + sizeof(*ev); 3020 3020 struct iscsi_cls_conn *conn; 3021 3021 struct iscsi_cls_session *session; 3022 3022 int err = 0, value = 0, state; 3023 3023 3024 - if (ev->u.set_param.len > PAGE_SIZE) 3024 + if (ev->u.set_param.len > rlen || 3025 + ev->u.set_param.len > PAGE_SIZE) 3025 3026 return -EINVAL; 3026 3027 3027 3028 session = iscsi_session_lookup(ev->u.set_param.sid); 3028 3029 conn = iscsi_conn_lookup(ev->u.set_param.sid, ev->u.set_param.cid); 3029 3030 if (!conn || !session) 3031 + return -EINVAL; 3032 + 3033 + /* data will be regarded as NULL-ended string, do length check */ 3034 + if (strlen(data) > ev->u.set_param.len) 3030 3035 return -EINVAL; 3031 3036 3032 3037 switch (ev->u.set_param.param) { ··· 3123 3118 3124 3119 static int 3125 3120 iscsi_if_transport_ep(struct iscsi_transport *transport, 3126 - struct iscsi_uevent *ev, int msg_type) 3121 + struct iscsi_uevent *ev, int msg_type, u32 rlen) 3127 3122 { 3128 3123 struct iscsi_endpoint *ep; 3129 3124 int rc = 0; ··· 3131 3126 switch (msg_type) { 3132 3127 case ISCSI_UEVENT_TRANSPORT_EP_CONNECT_THROUGH_HOST: 3133 3128 case ISCSI_UEVENT_TRANSPORT_EP_CONNECT: 3134 - rc = iscsi_if_ep_connect(transport, ev, msg_type); 3129 + if (rlen < sizeof(struct sockaddr)) 3130 + rc = -EINVAL; 3131 + else 3132 + rc = iscsi_if_ep_connect(transport, ev, msg_type); 3135 3133 break; 3136 3134 case ISCSI_UEVENT_TRANSPORT_EP_POLL: 3137 3135 if (!transport->ep_poll) ··· 3158 3150 3159 3151 static int 3160 3152 iscsi_tgt_dscvr(struct iscsi_transport *transport, 3161 - struct iscsi_uevent *ev) 3153 + struct iscsi_uevent *ev, u32 rlen) 3162 3154 { 3163 3155 struct Scsi_Host *shost; 3164 3156 struct sockaddr *dst_addr; 3165 3157 int err; 3158 + 3159 + if (rlen < sizeof(*dst_addr)) 3160 + return -EINVAL; 3166 3161 3167 3162 if (!transport->tgt_dscvr) 3168 3163 return -EINVAL; ··· 3187 3176 3188 3177 static int 3189 3178 iscsi_set_host_param(struct iscsi_transport *transport, 3190 - struct iscsi_uevent *ev) 3179 + struct iscsi_uevent *ev, u32 rlen) 3191 3180 { 3192 3181 char *data = (char*)ev + sizeof(*ev); 3193 3182 struct Scsi_Host *shost; ··· 3196 3185 if (!transport->set_host_param) 3197 3186 return -ENOSYS; 3198 3187 3199 - if (ev->u.set_host_param.len > PAGE_SIZE) 3188 + if (ev->u.set_host_param.len > rlen || 3189 + ev->u.set_host_param.len > PAGE_SIZE) 3200 3190 return -EINVAL; 3201 3191 3202 3192 shost = scsi_host_lookup(ev->u.set_host_param.host_no); ··· 3207 3195 return -ENODEV; 3208 3196 } 3209 3197 3198 + /* see similar check in iscsi_if_set_param() */ 3199 + if (strlen(data) > ev->u.set_host_param.len) 3200 + return -EINVAL; 3201 + 3210 3202 err = transport->set_host_param(shost, ev->u.set_host_param.param, 3211 3203 data, ev->u.set_host_param.len); 3212 3204 scsi_host_put(shost); ··· 3218 3202 } 3219 3203 3220 3204 static int 3221 - iscsi_set_path(struct iscsi_transport *transport, struct iscsi_uevent *ev) 3205 + iscsi_set_path(struct iscsi_transport *transport, struct iscsi_uevent *ev, u32 rlen) 3222 3206 { 3223 3207 struct Scsi_Host *shost; 3224 3208 struct iscsi_path *params; 3225 3209 int err; 3210 + 3211 + if (rlen < sizeof(*params)) 3212 + return -EINVAL; 3226 3213 3227 3214 if (!transport->set_path) 3228 3215 return -ENOSYS; ··· 3286 3267 } 3287 3268 3288 3269 static int 3289 - iscsi_send_ping(struct iscsi_transport *transport, struct iscsi_uevent *ev) 3270 + iscsi_send_ping(struct iscsi_transport *transport, struct iscsi_uevent *ev, u32 rlen) 3290 3271 { 3291 3272 struct Scsi_Host *shost; 3292 3273 struct sockaddr *dst_addr; 3293 3274 int err; 3275 + 3276 + if (rlen < sizeof(*dst_addr)) 3277 + return -EINVAL; 3294 3278 3295 3279 if (!transport->send_ping) 3296 3280 return -ENOSYS; ··· 3792 3770 } 3793 3771 3794 3772 static int iscsi_if_transport_conn(struct iscsi_transport *transport, 3795 - struct nlmsghdr *nlh) 3773 + struct nlmsghdr *nlh, u32 pdu_len) 3796 3774 { 3797 3775 struct iscsi_uevent *ev = nlmsg_data(nlh); 3798 3776 struct iscsi_cls_session *session; 3799 3777 struct iscsi_cls_conn *conn = NULL; 3800 3778 struct iscsi_endpoint *ep; 3801 - uint32_t pdu_len; 3802 3779 int err = 0; 3803 3780 3804 3781 switch (nlh->nlmsg_type) { ··· 3882 3861 3883 3862 break; 3884 3863 case ISCSI_UEVENT_SEND_PDU: 3885 - pdu_len = nlh->nlmsg_len - sizeof(*nlh) - sizeof(*ev); 3886 - 3887 3864 if ((ev->u.send_pdu.hdr_size > pdu_len) || 3888 3865 (ev->u.send_pdu.data_size > (pdu_len - ev->u.send_pdu.hdr_size))) { 3889 3866 err = -EINVAL; ··· 3911 3892 struct iscsi_internal *priv; 3912 3893 struct iscsi_cls_session *session; 3913 3894 struct iscsi_endpoint *ep = NULL; 3895 + u32 rlen; 3914 3896 3915 3897 if (!netlink_capable(skb, CAP_SYS_ADMIN)) 3916 3898 return -EPERM; ··· 3930 3910 return -EINVAL; 3931 3911 3932 3912 portid = NETLINK_CB(skb).portid; 3913 + 3914 + /* 3915 + * Even though the remaining payload may not be regarded as nlattr, 3916 + * (like address or something else), calculate the remaining length 3917 + * here to ease following length checks. 3918 + */ 3919 + rlen = nlmsg_attrlen(nlh, sizeof(*ev)); 3933 3920 3934 3921 switch (nlh->nlmsg_type) { 3935 3922 case ISCSI_UEVENT_CREATE_SESSION: ··· 3994 3967 err = -EINVAL; 3995 3968 break; 3996 3969 case ISCSI_UEVENT_SET_PARAM: 3997 - err = iscsi_if_set_param(transport, ev); 3970 + err = iscsi_if_set_param(transport, ev, rlen); 3998 3971 break; 3999 3972 case ISCSI_UEVENT_CREATE_CONN: 4000 3973 case ISCSI_UEVENT_DESTROY_CONN: ··· 4002 3975 case ISCSI_UEVENT_START_CONN: 4003 3976 case ISCSI_UEVENT_BIND_CONN: 4004 3977 case ISCSI_UEVENT_SEND_PDU: 4005 - err = iscsi_if_transport_conn(transport, nlh); 3978 + err = iscsi_if_transport_conn(transport, nlh, rlen); 4006 3979 break; 4007 3980 case ISCSI_UEVENT_GET_STATS: 4008 3981 err = iscsi_if_get_stats(transport, nlh); ··· 4011 3984 case ISCSI_UEVENT_TRANSPORT_EP_POLL: 4012 3985 case ISCSI_UEVENT_TRANSPORT_EP_DISCONNECT: 4013 3986 case ISCSI_UEVENT_TRANSPORT_EP_CONNECT_THROUGH_HOST: 4014 - err = iscsi_if_transport_ep(transport, ev, nlh->nlmsg_type); 3987 + err = iscsi_if_transport_ep(transport, ev, nlh->nlmsg_type, rlen); 4015 3988 break; 4016 3989 case ISCSI_UEVENT_TGT_DSCVR: 4017 - err = iscsi_tgt_dscvr(transport, ev); 3990 + err = iscsi_tgt_dscvr(transport, ev, rlen); 4018 3991 break; 4019 3992 case ISCSI_UEVENT_SET_HOST_PARAM: 4020 - err = iscsi_set_host_param(transport, ev); 3993 + err = iscsi_set_host_param(transport, ev, rlen); 4021 3994 break; 4022 3995 case ISCSI_UEVENT_PATH_UPDATE: 4023 - err = iscsi_set_path(transport, ev); 3996 + err = iscsi_set_path(transport, ev, rlen); 4024 3997 break; 4025 3998 case ISCSI_UEVENT_SET_IFACE_PARAMS: 4026 - err = iscsi_set_iface_params(transport, ev, 4027 - nlmsg_attrlen(nlh, sizeof(*ev))); 3999 + err = iscsi_set_iface_params(transport, ev, rlen); 4028 4000 break; 4029 4001 case ISCSI_UEVENT_PING: 4030 - err = iscsi_send_ping(transport, ev); 4002 + err = iscsi_send_ping(transport, ev, rlen); 4031 4003 break; 4032 4004 case ISCSI_UEVENT_GET_CHAP: 4033 4005 err = iscsi_get_chap(transport, nlh); ··· 4035 4009 err = iscsi_delete_chap(transport, ev); 4036 4010 break; 4037 4011 case ISCSI_UEVENT_SET_FLASHNODE_PARAMS: 4038 - err = iscsi_set_flashnode_param(transport, ev, 4039 - nlmsg_attrlen(nlh, 4040 - sizeof(*ev))); 4012 + err = iscsi_set_flashnode_param(transport, ev, rlen); 4041 4013 break; 4042 4014 case ISCSI_UEVENT_NEW_FLASHNODE: 4043 - err = iscsi_new_flashnode(transport, ev, 4044 - nlmsg_attrlen(nlh, sizeof(*ev))); 4015 + err = iscsi_new_flashnode(transport, ev, rlen); 4045 4016 break; 4046 4017 case ISCSI_UEVENT_DEL_FLASHNODE: 4047 4018 err = iscsi_del_flashnode(transport, ev); ··· 4053 4030 err = iscsi_logout_flashnode_sid(transport, ev); 4054 4031 break; 4055 4032 case ISCSI_UEVENT_SET_CHAP: 4056 - err = iscsi_set_chap(transport, ev, 4057 - nlmsg_attrlen(nlh, sizeof(*ev))); 4033 + err = iscsi_set_chap(transport, ev, rlen); 4058 4034 break; 4059 4035 case ISCSI_UEVENT_GET_HOST_STATS: 4060 4036 err = iscsi_get_host_stats(transport, nlh);
+7
drivers/scsi/storvsc_drv.c
··· 316 316 #define SRB_STATUS_ABORTED 0x02 317 317 #define SRB_STATUS_ERROR 0x04 318 318 #define SRB_STATUS_INVALID_REQUEST 0x06 319 + #define SRB_STATUS_TIMEOUT 0x09 320 + #define SRB_STATUS_SELECTION_TIMEOUT 0x0A 321 + #define SRB_STATUS_BUS_RESET 0x0E 319 322 #define SRB_STATUS_DATA_OVERRUN 0x12 320 323 #define SRB_STATUS_INVALID_LUN 0x20 321 324 #define SRB_STATUS_INTERNAL_ERROR 0x30 ··· 984 981 case SRB_STATUS_ABORTED: 985 982 case SRB_STATUS_INVALID_REQUEST: 986 983 case SRB_STATUS_INTERNAL_ERROR: 984 + case SRB_STATUS_TIMEOUT: 985 + case SRB_STATUS_SELECTION_TIMEOUT: 986 + case SRB_STATUS_BUS_RESET: 987 + case SRB_STATUS_DATA_OVERRUN: 987 988 if (vm_srb->srb_status & SRB_STATUS_AUTOSENSE_VALID) { 988 989 /* Check for capacity change */ 989 990 if ((asc == 0x2a) && (ascq == 0x9)) {
+2 -1
drivers/scsi/sun_esp.c
··· 12 12 #include <linux/init.h> 13 13 #include <linux/dma-mapping.h> 14 14 #include <linux/of.h> 15 - #include <linux/of_device.h> 15 + #include <linux/of_platform.h> 16 + #include <linux/platform_device.h> 16 17 #include <linux/gfp.h> 17 18 18 19 #include <asm/irq.h>
+36 -38
drivers/target/iscsi/iscsi_target_configfs.c
··· 45 45 46 46 tpg_np_new = iscsit_tpg_locate_child_np(tpg_np, type); 47 47 if (tpg_np_new) 48 - rb = sprintf(page, "1\n"); 48 + rb = sysfs_emit(page, "1\n"); 49 49 else 50 - rb = sprintf(page, "0\n"); 50 + rb = sysfs_emit(page, "0\n"); 51 51 52 52 return rb; 53 53 } ··· 282 282 { \ 283 283 struct se_node_acl *se_nacl = attrib_to_nacl(item); \ 284 284 struct iscsi_node_acl *nacl = to_iscsi_nacl(se_nacl); \ 285 - return sprintf(page, "%u\n", nacl->node_attrib.name); \ 285 + return sysfs_emit(page, "%u\n", nacl->node_attrib.name); \ 286 286 } \ 287 287 \ 288 288 static ssize_t iscsi_nacl_attrib_##name##_store(struct config_item *item,\ ··· 320 320 struct se_node_acl *se_nacl = attrib_to_nacl(item); 321 321 struct iscsi_node_acl *nacl = to_iscsi_nacl(se_nacl); 322 322 323 - return sprintf(page, "%d\n", nacl->node_attrib.authentication); 323 + return sysfs_emit(page, "%d\n", nacl->node_attrib.authentication); 324 324 } 325 325 326 326 static ssize_t iscsi_nacl_attrib_authentication_store(struct config_item *item, ··· 533 533 spin_lock_bh(&se_nacl->nacl_sess_lock); 534 534 se_sess = se_nacl->nacl_sess; 535 535 if (!se_sess) { 536 - rb += sprintf(page+rb, "No active iSCSI Session for Initiator" 536 + rb += sysfs_emit_at(page, rb, "No active iSCSI Session for Initiator" 537 537 " Endpoint: %s\n", se_nacl->initiatorname); 538 538 } else { 539 539 sess = se_sess->fabric_sess_ptr; 540 540 541 - rb += sprintf(page+rb, "InitiatorName: %s\n", 541 + rb += sysfs_emit_at(page, rb, "InitiatorName: %s\n", 542 542 sess->sess_ops->InitiatorName); 543 - rb += sprintf(page+rb, "InitiatorAlias: %s\n", 543 + rb += sysfs_emit_at(page, rb, "InitiatorAlias: %s\n", 544 544 sess->sess_ops->InitiatorAlias); 545 545 546 - rb += sprintf(page+rb, 546 + rb += sysfs_emit_at(page, rb, 547 547 "LIO Session ID: %u ISID: 0x%6ph TSIH: %hu ", 548 548 sess->sid, sess->isid, sess->tsih); 549 - rb += sprintf(page+rb, "SessionType: %s\n", 549 + rb += sysfs_emit_at(page, rb, "SessionType: %s\n", 550 550 (sess->sess_ops->SessionType) ? 551 551 "Discovery" : "Normal"); 552 - rb += sprintf(page+rb, "Session State: "); 552 + rb += sysfs_emit_at(page, rb, "Session State: "); 553 553 switch (sess->session_state) { 554 554 case TARG_SESS_STATE_FREE: 555 - rb += sprintf(page+rb, "TARG_SESS_FREE\n"); 555 + rb += sysfs_emit_at(page, rb, "TARG_SESS_FREE\n"); 556 556 break; 557 557 case TARG_SESS_STATE_ACTIVE: 558 - rb += sprintf(page+rb, "TARG_SESS_STATE_ACTIVE\n"); 558 + rb += sysfs_emit_at(page, rb, "TARG_SESS_STATE_ACTIVE\n"); 559 559 break; 560 560 case TARG_SESS_STATE_LOGGED_IN: 561 - rb += sprintf(page+rb, "TARG_SESS_STATE_LOGGED_IN\n"); 561 + rb += sysfs_emit_at(page, rb, "TARG_SESS_STATE_LOGGED_IN\n"); 562 562 break; 563 563 case TARG_SESS_STATE_FAILED: 564 - rb += sprintf(page+rb, "TARG_SESS_STATE_FAILED\n"); 564 + rb += sysfs_emit_at(page, rb, "TARG_SESS_STATE_FAILED\n"); 565 565 break; 566 566 case TARG_SESS_STATE_IN_CONTINUE: 567 - rb += sprintf(page+rb, "TARG_SESS_STATE_IN_CONTINUE\n"); 567 + rb += sysfs_emit_at(page, rb, "TARG_SESS_STATE_IN_CONTINUE\n"); 568 568 break; 569 569 default: 570 - rb += sprintf(page+rb, "ERROR: Unknown Session" 570 + rb += sysfs_emit_at(page, rb, "ERROR: Unknown Session" 571 571 " State!\n"); 572 572 break; 573 573 } 574 574 575 - rb += sprintf(page+rb, "---------------------[iSCSI Session" 575 + rb += sysfs_emit_at(page, rb, "---------------------[iSCSI Session" 576 576 " Values]-----------------------\n"); 577 - rb += sprintf(page+rb, " CmdSN/WR : CmdSN/WC : ExpCmdSN" 577 + rb += sysfs_emit_at(page, rb, " CmdSN/WR : CmdSN/WC : ExpCmdSN" 578 578 " : MaxCmdSN : ITT : TTT\n"); 579 579 max_cmd_sn = (u32) atomic_read(&sess->max_cmd_sn); 580 - rb += sprintf(page+rb, " 0x%08x 0x%08x 0x%08x 0x%08x" 580 + rb += sysfs_emit_at(page, rb, " 0x%08x 0x%08x 0x%08x 0x%08x" 581 581 " 0x%08x 0x%08x\n", 582 582 sess->cmdsn_window, 583 583 (max_cmd_sn - sess->exp_cmd_sn) + 1, 584 584 sess->exp_cmd_sn, max_cmd_sn, 585 585 sess->init_task_tag, sess->targ_xfer_tag); 586 - rb += sprintf(page+rb, "----------------------[iSCSI" 586 + rb += sysfs_emit_at(page, rb, "----------------------[iSCSI" 587 587 " Connections]-------------------------\n"); 588 588 589 589 spin_lock(&sess->conn_lock); 590 590 list_for_each_entry(conn, &sess->sess_conn_list, conn_list) { 591 - rb += sprintf(page+rb, "CID: %hu Connection" 591 + rb += sysfs_emit_at(page, rb, "CID: %hu Connection" 592 592 " State: ", conn->cid); 593 593 switch (conn->conn_state) { 594 594 case TARG_CONN_STATE_FREE: 595 - rb += sprintf(page+rb, 595 + rb += sysfs_emit_at(page, rb, 596 596 "TARG_CONN_STATE_FREE\n"); 597 597 break; 598 598 case TARG_CONN_STATE_XPT_UP: 599 - rb += sprintf(page+rb, 599 + rb += sysfs_emit_at(page, rb, 600 600 "TARG_CONN_STATE_XPT_UP\n"); 601 601 break; 602 602 case TARG_CONN_STATE_IN_LOGIN: 603 - rb += sprintf(page+rb, 603 + rb += sysfs_emit_at(page, rb, 604 604 "TARG_CONN_STATE_IN_LOGIN\n"); 605 605 break; 606 606 case TARG_CONN_STATE_LOGGED_IN: 607 - rb += sprintf(page+rb, 607 + rb += sysfs_emit_at(page, rb, 608 608 "TARG_CONN_STATE_LOGGED_IN\n"); 609 609 break; 610 610 case TARG_CONN_STATE_IN_LOGOUT: 611 - rb += sprintf(page+rb, 611 + rb += sysfs_emit_at(page, rb, 612 612 "TARG_CONN_STATE_IN_LOGOUT\n"); 613 613 break; 614 614 case TARG_CONN_STATE_LOGOUT_REQUESTED: 615 - rb += sprintf(page+rb, 615 + rb += sysfs_emit_at(page, rb, 616 616 "TARG_CONN_STATE_LOGOUT_REQUESTED\n"); 617 617 break; 618 618 case TARG_CONN_STATE_CLEANUP_WAIT: 619 - rb += sprintf(page+rb, 619 + rb += sysfs_emit_at(page, rb, 620 620 "TARG_CONN_STATE_CLEANUP_WAIT\n"); 621 621 break; 622 622 default: 623 - rb += sprintf(page+rb, 623 + rb += sysfs_emit_at(page, rb, 624 624 "ERROR: Unknown Connection State!\n"); 625 625 break; 626 626 } 627 627 628 - rb += sprintf(page+rb, " Address %pISc %s", &conn->login_sockaddr, 628 + rb += sysfs_emit_at(page, rb, " Address %pISc %s", &conn->login_sockaddr, 629 629 (conn->network_transport == ISCSI_TCP) ? 630 630 "TCP" : "SCTP"); 631 - rb += sprintf(page+rb, " StatSN: 0x%08x\n", 631 + rb += sysfs_emit_at(page, rb, " StatSN: 0x%08x\n", 632 632 conn->stat_sn); 633 633 } 634 634 spin_unlock(&sess->conn_lock); ··· 641 641 static ssize_t lio_target_nacl_cmdsn_depth_show(struct config_item *item, 642 642 char *page) 643 643 { 644 - return sprintf(page, "%u\n", acl_to_nacl(item)->queue_depth); 644 + return sysfs_emit(page, "%u\n", acl_to_nacl(item)->queue_depth); 645 645 } 646 646 647 647 static ssize_t lio_target_nacl_cmdsn_depth_store(struct config_item *item, ··· 750 750 if (iscsit_get_tpg(tpg) < 0) \ 751 751 return -EINVAL; \ 752 752 \ 753 - rb = sprintf(page, "%u\n", tpg->tpg_attrib.name); \ 753 + rb = sysfs_emit(page, "%u\n", tpg->tpg_attrib.name); \ 754 754 iscsit_put_tpg(tpg); \ 755 755 return rb; \ 756 756 } \ ··· 783 783 784 784 DEF_TPG_ATTRIB(authentication); 785 785 DEF_TPG_ATTRIB(login_timeout); 786 - DEF_TPG_ATTRIB(netif_timeout); 787 786 DEF_TPG_ATTRIB(generate_node_acls); 788 787 DEF_TPG_ATTRIB(default_cmdsn_depth); 789 788 DEF_TPG_ATTRIB(cache_dynamic_acls); ··· 798 799 static struct configfs_attribute *lio_target_tpg_attrib_attrs[] = { 799 800 &iscsi_tpg_attrib_attr_authentication, 800 801 &iscsi_tpg_attrib_attr_login_timeout, 801 - &iscsi_tpg_attrib_attr_netif_timeout, 802 802 &iscsi_tpg_attrib_attr_generate_node_acls, 803 803 &iscsi_tpg_attrib_attr_default_cmdsn_depth, 804 804 &iscsi_tpg_attrib_attr_cache_dynamic_acls, ··· 1136 1138 static ssize_t lio_target_wwn_lio_version_show(struct config_item *item, 1137 1139 char *page) 1138 1140 { 1139 - return sprintf(page, "Datera Inc. iSCSI Target "ISCSIT_VERSION"\n"); 1141 + return sysfs_emit(page, "Datera Inc. iSCSI Target %s\n", ISCSIT_VERSION); 1140 1142 } 1141 1143 1142 1144 CONFIGFS_ATTR_RO(lio_target_wwn_, lio_version); ··· 1144 1146 static ssize_t lio_target_wwn_cpus_allowed_list_show( 1145 1147 struct config_item *item, char *page) 1146 1148 { 1147 - return sprintf(page, "%*pbl\n", 1149 + return sysfs_emit(page, "%*pbl\n", 1148 1150 cpumask_pr_args(iscsit_global->allowed_cpumask)); 1149 1151 } 1150 1152 ··· 1281 1283 { 1282 1284 struct iscsi_node_auth *discovery_auth = &iscsit_global->discovery_acl.node_auth; 1283 1285 1284 - return sprintf(page, "%d\n", discovery_auth->enforce_discovery_auth); 1286 + return sysfs_emit(page, "%d\n", discovery_auth->enforce_discovery_auth); 1285 1287 } 1286 1288 1287 1289 static ssize_t iscsi_disc_enforce_discovery_auth_store(struct config_item *item,
-26
drivers/target/iscsi/iscsi_target_tpg.c
··· 211 211 212 212 a->authentication = TA_AUTHENTICATION; 213 213 a->login_timeout = TA_LOGIN_TIMEOUT; 214 - a->netif_timeout = TA_NETIF_TIMEOUT; 215 214 a->default_cmdsn_depth = TA_DEFAULT_CMDSN_DEPTH; 216 215 a->generate_node_acls = TA_GENERATE_NODE_ACLS; 217 216 a->cache_dynamic_acls = TA_CACHE_DYNAMIC_ACLS; ··· 661 662 a->login_timeout = login_timeout; 662 663 pr_debug("Set Logout Timeout to %u for Target Portal Group" 663 664 " %hu\n", a->login_timeout, tpg->tpgt); 664 - 665 - return 0; 666 - } 667 - 668 - int iscsit_ta_netif_timeout( 669 - struct iscsi_portal_group *tpg, 670 - u32 netif_timeout) 671 - { 672 - struct iscsi_tpg_attrib *a = &tpg->tpg_attrib; 673 - 674 - if (netif_timeout > TA_NETIF_TIMEOUT_MAX) { 675 - pr_err("Requested Network Interface Timeout %u larger" 676 - " than maximum %u\n", netif_timeout, 677 - TA_NETIF_TIMEOUT_MAX); 678 - return -EINVAL; 679 - } else if (netif_timeout < TA_NETIF_TIMEOUT_MIN) { 680 - pr_err("Requested Network Interface Timeout %u smaller" 681 - " than minimum %u\n", netif_timeout, 682 - TA_NETIF_TIMEOUT_MIN); 683 - return -EINVAL; 684 - } 685 - 686 - a->netif_timeout = netif_timeout; 687 - pr_debug("Set Network Interface Timeout to %u for" 688 - " Target Portal Group %hu\n", a->netif_timeout, tpg->tpgt); 689 665 690 666 return 0; 691 667 }
-1
drivers/target/iscsi/iscsi_target_tpg.h
··· 38 38 struct iscsi_tpg_np *); 39 39 extern int iscsit_ta_authentication(struct iscsi_portal_group *, u32); 40 40 extern int iscsit_ta_login_timeout(struct iscsi_portal_group *, u32); 41 - extern int iscsit_ta_netif_timeout(struct iscsi_portal_group *, u32); 42 41 extern int iscsit_ta_generate_node_acls(struct iscsi_portal_group *, u32); 43 42 extern int iscsit_ta_default_cmdsn_depth(struct iscsi_portal_group *, u32); 44 43 extern int iscsit_ta_cache_dynamic_acls(struct iscsi_portal_group *, u32);
+6 -1
drivers/target/target_core_iblock.c
··· 739 739 740 740 if (data_direction == DMA_TO_DEVICE) { 741 741 struct iblock_dev *ib_dev = IBLOCK_DEV(dev); 742 + 743 + /* 744 + * Set bits to indicate WRITE_ODIRECT so we are not throttled 745 + * by WBT. 746 + */ 747 + opf = REQ_OP_WRITE | REQ_SYNC | REQ_IDLE; 742 748 /* 743 749 * Force writethrough using REQ_FUA if a volatile write cache 744 750 * is not enabled, or if initiator set the Force Unit Access bit. 745 751 */ 746 - opf = REQ_OP_WRITE; 747 752 miter_dir = SG_MITER_TO_SG; 748 753 if (bdev_fua(ib_dev->ibd_bd)) { 749 754 if (cmd->se_cmd_flags & SCF_FUA)
-8
drivers/ufs/core/Kconfig
··· 35 35 capabilities of the UFS device (if present) to perform crypto 36 36 operations on data being transferred to/from the device. 37 37 38 - config SCSI_UFS_HPB 39 - bool "Support UFS Host Performance Booster" 40 - help 41 - The UFS HPB feature improves random read performance. It caches 42 - L2P (logical to physical) map of UFS to host DRAM. The driver uses HPB 43 - read command by piggybacking physical page number for bypassing FTL (flash 44 - translation layer)'s L2P address translation. 45 - 46 38 config SCSI_UFS_FAULT_INJECTION 47 39 bool "UFS Fault Injection Support" 48 40 depends on FAULT_INJECTION
-1
drivers/ufs/core/Makefile
··· 5 5 ufshcd-core-$(CONFIG_DEBUG_FS) += ufs-debugfs.o 6 6 ufshcd-core-$(CONFIG_SCSI_UFS_BSG) += ufs_bsg.o 7 7 ufshcd-core-$(CONFIG_SCSI_UFS_CRYPTO) += ufshcd-crypto.o 8 - ufshcd-core-$(CONFIG_SCSI_UFS_HPB) += ufshpb.o 9 8 ufshcd-core-$(CONFIG_SCSI_UFS_FAULT_INJECTION) += ufs-fault-injection.o 10 9 ufshcd-core-$(CONFIG_SCSI_UFS_HWMON) += ufs-hwmon.o
+2 -1
drivers/ufs/core/ufs-hwmon.c
··· 127 127 return err; 128 128 } 129 129 130 - static umode_t ufs_hwmon_is_visible(const void *_data, enum hwmon_sensor_types type, u32 attr, 130 + static umode_t ufs_hwmon_is_visible(const void *data, 131 + enum hwmon_sensor_types type, u32 attr, 131 132 int channel) 132 133 { 133 134 if (type != hwmon_temp)
+16 -18
drivers/ufs/core/ufs-mcq.c
··· 97 97 val |= FIELD_PREP(MCQ_CFG_MAC_MASK, max_active_cmds); 98 98 ufshcd_writel(hba, val, REG_UFS_MCQ_CFG); 99 99 } 100 + EXPORT_SYMBOL_GPL(ufshcd_mcq_config_mac); 100 101 101 102 /** 102 103 * ufshcd_mcq_req_to_hwq - find the hardware queue on which the ··· 105 104 * @hba: per adapter instance 106 105 * @req: pointer to the request to be issued 107 106 * 108 - * Returns the hardware queue instance on which the request would 107 + * Return: the hardware queue instance on which the request would 109 108 * be queued. 110 109 */ 111 110 struct ufs_hw_queue *ufshcd_mcq_req_to_hwq(struct ufs_hba *hba, ··· 121 120 * ufshcd_mcq_decide_queue_depth - decide the queue depth 122 121 * @hba: per adapter instance 123 122 * 124 - * Returns queue-depth on success, non-zero on error 123 + * Return: queue-depth on success, non-zero on error 125 124 * 126 125 * MAC - Max. Active Command of the Host Controller (HC) 127 126 * HC wouldn't send more than this commands to the device. ··· 246 245 { 247 246 return readl(mcq_opr_base(hba, OPR_CQIS, i) + REG_CQIS); 248 247 } 248 + EXPORT_SYMBOL_GPL(ufshcd_mcq_read_cqis); 249 249 250 250 void ufshcd_mcq_write_cqis(struct ufs_hba *hba, u32 val, int i) 251 251 { ··· 390 388 MCQ_CFG_n(REG_SQATTR, i)); 391 389 } 392 390 } 391 + EXPORT_SYMBOL_GPL(ufshcd_mcq_make_queues_operational); 393 392 394 393 void ufshcd_mcq_enable_esi(struct ufs_hba *hba) 395 394 { ··· 490 487 /** 491 488 * ufshcd_mcq_sq_cleanup - Clean up submission queue resources 492 489 * associated with the pending command. 493 - * @hba - per adapter instance. 494 - * @task_tag - The command's task tag. 490 + * @hba: per adapter instance. 491 + * @task_tag: The command's task tag. 495 492 * 496 - * Returns 0 for success; error code otherwise. 493 + * Return: 0 for success; error code otherwise. 497 494 */ 498 495 int ufshcd_mcq_sq_cleanup(struct ufs_hba *hba, int task_tag) 499 496 { ··· 554 551 * Write the sqe's Command Type to 0xF. The host controller will not 555 552 * fetch any sqe with Command Type = 0xF. 556 553 * 557 - * @utrd - UTP Transfer Request Descriptor to be nullified. 554 + * @utrd: UTP Transfer Request Descriptor to be nullified. 558 555 */ 559 556 static void ufshcd_mcq_nullify_sqe(struct utp_transfer_req_desc *utrd) 560 557 { 561 - u32 dword_0; 562 - 563 - dword_0 = le32_to_cpu(utrd->header.dword_0); 564 - dword_0 &= ~UPIU_COMMAND_TYPE_MASK; 565 - dword_0 |= FIELD_PREP(UPIU_COMMAND_TYPE_MASK, 0xF); 566 - utrd->header.dword_0 = cpu_to_le32(dword_0); 558 + utrd->header.command_type = 0xf; 567 559 } 568 560 569 561 /** ··· 566 568 * If the command is in the submission queue and not issued to the device yet, 567 569 * nullify the sqe so the host controller will skip fetching the sqe. 568 570 * 569 - * @hba - per adapter instance. 570 - * @hwq - Hardware Queue to be searched. 571 - * @task_tag - The command's task tag. 571 + * @hba: per adapter instance. 572 + * @hwq: Hardware Queue to be searched. 573 + * @task_tag: The command's task tag. 572 574 * 573 - * Returns true if the SQE containing the command is present in the SQ 575 + * Return: true if the SQE containing the command is present in the SQ 574 576 * (not fetched by the controller); returns false if the SQE is not in the SQ. 575 577 */ 576 578 static bool ufshcd_mcq_sqe_search(struct ufs_hba *hba, ··· 619 621 620 622 /** 621 623 * ufshcd_mcq_abort - Abort the command in MCQ. 622 - * @cmd - The command to be aborted. 624 + * @cmd: The command to be aborted. 623 625 * 624 - * Returns SUCCESS or FAILED error codes 626 + * Return: SUCCESS or FAILED error codes 625 627 */ 626 628 int ufshcd_mcq_abort(struct scsi_cmnd *cmd) 627 629 {
-22
drivers/ufs/core/ufs-sysfs.c
··· 718 718 UFS_DEVICE_DESC_PARAM(number_of_secure_wpa, _NUM_SEC_WPA, 1); 719 719 UFS_DEVICE_DESC_PARAM(psa_max_data_size, _PSA_MAX_DATA, 4); 720 720 UFS_DEVICE_DESC_PARAM(psa_state_timeout, _PSA_TMT, 1); 721 - UFS_DEVICE_DESC_PARAM(hpb_version, _HPB_VER, 2); 722 - UFS_DEVICE_DESC_PARAM(hpb_control, _HPB_CONTROL, 1); 723 721 UFS_DEVICE_DESC_PARAM(ext_feature_sup, _EXT_UFS_FEATURE_SUP, 4); 724 722 UFS_DEVICE_DESC_PARAM(wb_presv_us_en, _WB_PRESRV_USRSPC_EN, 1); 725 723 UFS_DEVICE_DESC_PARAM(wb_type, _WB_TYPE, 1); ··· 750 752 &dev_attr_number_of_secure_wpa.attr, 751 753 &dev_attr_psa_max_data_size.attr, 752 754 &dev_attr_psa_state_timeout.attr, 753 - &dev_attr_hpb_version.attr, 754 - &dev_attr_hpb_control.attr, 755 755 &dev_attr_ext_feature_sup.attr, 756 756 &dev_attr_wb_presv_us_en.attr, 757 757 &dev_attr_wb_type.attr, ··· 823 827 _ENM4_MAX_NUM_UNITS, 4); 824 828 UFS_GEOMETRY_DESC_PARAM(enh4_memory_capacity_adjustment_factor, 825 829 _ENM4_CAP_ADJ_FCTR, 2); 826 - UFS_GEOMETRY_DESC_PARAM(hpb_region_size, _HPB_REGION_SIZE, 1); 827 - UFS_GEOMETRY_DESC_PARAM(hpb_number_lu, _HPB_NUMBER_LU, 1); 828 - UFS_GEOMETRY_DESC_PARAM(hpb_subregion_size, _HPB_SUBREGION_SIZE, 1); 829 - UFS_GEOMETRY_DESC_PARAM(hpb_max_active_regions, _HPB_MAX_ACTIVE_REGS, 2); 830 830 UFS_GEOMETRY_DESC_PARAM(wb_max_alloc_units, _WB_MAX_ALLOC_UNITS, 4); 831 831 UFS_GEOMETRY_DESC_PARAM(wb_max_wb_luns, _WB_MAX_WB_LUNS, 1); 832 832 UFS_GEOMETRY_DESC_PARAM(wb_buff_cap_adj, _WB_BUFF_CAP_ADJ, 1); ··· 860 868 &dev_attr_enh3_memory_capacity_adjustment_factor.attr, 861 869 &dev_attr_enh4_memory_max_alloc_units.attr, 862 870 &dev_attr_enh4_memory_capacity_adjustment_factor.attr, 863 - &dev_attr_hpb_region_size.attr, 864 - &dev_attr_hpb_number_lu.attr, 865 - &dev_attr_hpb_subregion_size.attr, 866 - &dev_attr_hpb_max_active_regions.attr, 867 871 &dev_attr_wb_max_alloc_units.attr, 868 872 &dev_attr_wb_max_wb_luns.attr, 869 873 &dev_attr_wb_buff_cap_adj.attr, ··· 1120 1132 UFS_FLAG(wb_enable, _WB_EN); 1121 1133 UFS_FLAG(wb_flush_en, _WB_BUFF_FLUSH_EN); 1122 1134 UFS_FLAG(wb_flush_during_h8, _WB_BUFF_FLUSH_DURING_HIBERN8); 1123 - UFS_FLAG(hpb_enable, _HPB_EN); 1124 1135 1125 1136 static struct attribute *ufs_sysfs_device_flags[] = { 1126 1137 &dev_attr_device_init.attr, ··· 1133 1146 &dev_attr_wb_enable.attr, 1134 1147 &dev_attr_wb_flush_en.attr, 1135 1148 &dev_attr_wb_flush_during_h8.attr, 1136 - &dev_attr_hpb_enable.attr, 1137 1149 NULL, 1138 1150 }; 1139 1151 ··· 1179 1193 static DEVICE_ATTR_RO(_name) 1180 1194 1181 1195 UFS_ATTRIBUTE(boot_lun_enabled, _BOOT_LU_EN); 1182 - UFS_ATTRIBUTE(max_data_size_hpb_single_cmd, _MAX_HPB_SINGLE_CMD); 1183 1196 UFS_ATTRIBUTE(current_power_mode, _POWER_MODE); 1184 1197 UFS_ATTRIBUTE(active_icc_level, _ACTIVE_ICC_LVL); 1185 1198 UFS_ATTRIBUTE(ooo_data_enabled, _OOO_DATA_EN); ··· 1202 1217 1203 1218 static struct attribute *ufs_sysfs_attributes[] = { 1204 1219 &dev_attr_boot_lun_enabled.attr, 1205 - &dev_attr_max_data_size_hpb_single_cmd.attr, 1206 1220 &dev_attr_current_power_mode.attr, 1207 1221 &dev_attr_active_icc_level.attr, 1208 1222 &dev_attr_ooo_data_enabled.attr, ··· 1275 1291 UFS_UNIT_DESC_PARAM(physical_memory_resourse_count, _PHY_MEM_RSRC_CNT, 8); 1276 1292 UFS_UNIT_DESC_PARAM(context_capabilities, _CTX_CAPABILITIES, 2); 1277 1293 UFS_UNIT_DESC_PARAM(large_unit_granularity, _LARGE_UNIT_SIZE_M1, 1); 1278 - UFS_UNIT_DESC_PARAM(hpb_lu_max_active_regions, _HPB_LU_MAX_ACTIVE_RGNS, 2); 1279 - UFS_UNIT_DESC_PARAM(hpb_pinned_region_start_offset, _HPB_PIN_RGN_START_OFF, 2); 1280 - UFS_UNIT_DESC_PARAM(hpb_number_pinned_regions, _HPB_NUM_PIN_RGNS, 2); 1281 1294 UFS_UNIT_DESC_PARAM(wb_buf_alloc_units, _WB_BUF_ALLOC_UNITS, 4); 1282 1295 1283 1296 static struct attribute *ufs_sysfs_unit_descriptor[] = { ··· 1292 1311 &dev_attr_physical_memory_resourse_count.attr, 1293 1312 &dev_attr_context_capabilities.attr, 1294 1313 &dev_attr_large_unit_granularity.attr, 1295 - &dev_attr_hpb_lu_max_active_regions.attr, 1296 - &dev_attr_hpb_pinned_region_start_offset.attr, 1297 - &dev_attr_hpb_number_pinned_regions.attr, 1298 1314 &dev_attr_wb_buf_alloc_units.attr, 1299 1315 NULL, 1300 1316 };
+2
drivers/ufs/core/ufs_bsg.c
··· 232 232 * @hba: per adapter object 233 233 * 234 234 * Called during initial loading of the driver, and before scsi_scan_host. 235 + * 236 + * Returns: 0 (success). 235 237 */ 236 238 int ufs_bsg_probe(struct ufs_hba *hba) 237 239 {
+10 -10
drivers/ufs/core/ufshcd-crypto.h
··· 26 26 } 27 27 28 28 static inline void 29 - ufshcd_prepare_req_desc_hdr_crypto(struct ufshcd_lrb *lrbp, u32 *dword_0, 30 - u32 *dword_1, u32 *dword_3) 29 + ufshcd_prepare_req_desc_hdr_crypto(struct ufshcd_lrb *lrbp, 30 + struct request_desc_header *h) 31 31 { 32 - if (lrbp->crypto_key_slot >= 0) { 33 - *dword_0 |= UTP_REQ_DESC_CRYPTO_ENABLE_CMD; 34 - *dword_0 |= lrbp->crypto_key_slot; 35 - *dword_1 = lower_32_bits(lrbp->data_unit_num); 36 - *dword_3 = upper_32_bits(lrbp->data_unit_num); 37 - } 32 + if (lrbp->crypto_key_slot < 0) 33 + return; 34 + h->enable_crypto = 1; 35 + h->cci = lrbp->crypto_key_slot; 36 + h->dunl = cpu_to_le32(lower_32_bits(lrbp->data_unit_num)); 37 + h->dunu = cpu_to_le32(upper_32_bits(lrbp->data_unit_num)); 38 38 } 39 39 40 40 bool ufshcd_crypto_enable(struct ufs_hba *hba); ··· 51 51 struct ufshcd_lrb *lrbp) { } 52 52 53 53 static inline void 54 - ufshcd_prepare_req_desc_hdr_crypto(struct ufshcd_lrb *lrbp, u32 *dword_0, 55 - u32 *dword_1, u32 *dword_3) { } 54 + ufshcd_prepare_req_desc_hdr_crypto(struct ufshcd_lrb *lrbp, 55 + struct request_desc_header *h) { } 56 56 57 57 static inline bool ufshcd_crypto_enable(struct ufs_hba *hba) 58 58 {
+2 -2
drivers/ufs/core/ufshcd-priv.h
··· 93 93 int ufshcd_exec_raw_upiu_cmd(struct ufs_hba *hba, 94 94 struct utp_upiu_req *req_upiu, 95 95 struct utp_upiu_req *rsp_upiu, 96 - int msgcode, 96 + enum upiu_request_transaction msgcode, 97 97 u8 *desc_buff, int *buff_len, 98 98 enum query_opcode desc_op); 99 99 ··· 294 294 * ufshcd_scsi_to_upiu_lun - maps scsi LUN to UPIU LUN 295 295 * @scsi_lun: scsi LUN id 296 296 * 297 - * Returns UPIU LUN id 297 + * Return: UPIU LUN id 298 298 */ 299 299 static inline u8 ufshcd_scsi_to_upiu_lun(unsigned int scsi_lun) 300 300 {
+304 -323
drivers/ufs/core/ufshcd.c
··· 34 34 #include "ufs-fault-injection.h" 35 35 #include "ufs_bsg.h" 36 36 #include "ufshcd-crypto.h" 37 - #include "ufshpb.h" 38 37 #include <asm/unaligned.h> 39 38 40 39 #define CREATE_TRACE_POINTS ··· 237 238 /* UFS cards deviations table */ 238 239 { .wmanufacturerid = UFS_VENDOR_MICRON, 239 240 .model = UFS_ANY_MODEL, 240 - .quirk = UFS_DEVICE_QUIRK_DELAY_BEFORE_LPM | 241 - UFS_DEVICE_QUIRK_SWAP_L2P_ENTRY_FOR_HPB_READ }, 241 + .quirk = UFS_DEVICE_QUIRK_DELAY_BEFORE_LPM }, 242 242 { .wmanufacturerid = UFS_VENDOR_SAMSUNG, 243 243 .model = UFS_ANY_MODEL, 244 244 .quirk = UFS_DEVICE_QUIRK_DELAY_BEFORE_LPM | ··· 701 703 * @interval_us: polling interval in microseconds 702 704 * @timeout_ms: timeout in milliseconds 703 705 * 704 - * Return: 705 - * -ETIMEDOUT on error, zero on success. 706 + * Return: -ETIMEDOUT on error, zero on success. 706 707 */ 707 708 static int ufshcd_wait_for_register(struct ufs_hba *hba, u32 reg, u32 mask, 708 709 u32 val, unsigned long interval_us, ··· 729 732 * ufshcd_get_intr_mask - Get the interrupt bit mask 730 733 * @hba: Pointer to adapter instance 731 734 * 732 - * Returns interrupt bit mask per version 735 + * Return: interrupt bit mask per version 733 736 */ 734 737 static inline u32 ufshcd_get_intr_mask(struct ufs_hba *hba) 735 738 { ··· 745 748 * ufshcd_get_ufs_version - Get the UFS version supported by the HBA 746 749 * @hba: Pointer to adapter instance 747 750 * 748 - * Returns UFSHCI version supported by the controller 751 + * Return: UFSHCI version supported by the controller 749 752 */ 750 753 static inline u32 ufshcd_get_ufs_version(struct ufs_hba *hba) 751 754 { ··· 772 775 * the host controller 773 776 * @hba: pointer to adapter instance 774 777 * 775 - * Returns true if device present, false if no device detected 778 + * Return: true if device present, false if no device detected 776 779 */ 777 780 static inline bool ufshcd_is_device_present(struct ufs_hba *hba) 778 781 { ··· 785 788 * @cqe: pointer to the completion queue entry 786 789 * 787 790 * This function is used to get the OCS field from UTRD 788 - * Returns the OCS field in the UTRD 791 + * 792 + * Return: the OCS field in the UTRD. 789 793 */ 790 794 static enum utp_ocs ufshcd_get_tr_ocs(struct ufshcd_lrb *lrbp, 791 795 struct cq_entry *cqe) ··· 794 796 if (cqe) 795 797 return le32_to_cpu(cqe->status) & MASK_OCS; 796 798 797 - return le32_to_cpu(lrbp->utr_descriptor_ptr->header.dword_2) & MASK_OCS; 799 + return lrbp->utr_descriptor_ptr->header.ocs & MASK_OCS; 798 800 } 799 801 800 802 /** ··· 839 841 * ufshcd_get_lists_status - Check UCRDY, UTRLRDY and UTMRLRDY 840 842 * @reg: Register value of host controller status 841 843 * 842 - * Returns integer, 0 on Success and positive value if failed 844 + * Return: 0 on success; a positive value if failed. 843 845 */ 844 846 static inline int ufshcd_get_lists_status(u32 reg) 845 847 { ··· 851 853 * @hba: Pointer to adapter instance 852 854 * 853 855 * This function gets the result of UIC command completion 854 - * Returns 0 on success, non zero value on error 856 + * 857 + * Return: 0 on success; non-zero value on error. 855 858 */ 856 859 static inline int ufshcd_get_uic_cmd_result(struct ufs_hba *hba) 857 860 { ··· 865 866 * @hba: Pointer to adapter instance 866 867 * 867 868 * This function gets UIC command argument3 868 - * Returns 0 on success, non zero value on error 869 + * 870 + * Return: 0 on success; non-zero value on error. 869 871 */ 870 872 static inline u32 ufshcd_get_dme_attr_val(struct ufs_hba *hba) 871 873 { ··· 876 876 /** 877 877 * ufshcd_get_req_rsp - returns the TR response transaction type 878 878 * @ucd_rsp_ptr: pointer to response UPIU 879 + * 880 + * Return: UPIU type. 879 881 */ 880 - static inline int 882 + static inline enum upiu_response_transaction 881 883 ufshcd_get_req_rsp(struct utp_upiu_rsp *ucd_rsp_ptr) 882 884 { 883 - return be32_to_cpu(ucd_rsp_ptr->header.dword_0) >> 24; 884 - } 885 - 886 - /** 887 - * ufshcd_get_rsp_upiu_result - Get the result from response UPIU 888 - * @ucd_rsp_ptr: pointer to response UPIU 889 - * 890 - * This function gets the response status and scsi_status from response UPIU 891 - * Returns the response result code. 892 - */ 893 - static inline int 894 - ufshcd_get_rsp_upiu_result(struct utp_upiu_rsp *ucd_rsp_ptr) 895 - { 896 - return be32_to_cpu(ucd_rsp_ptr->header.dword_1) & MASK_RSP_UPIU_RESULT; 897 - } 898 - 899 - /* 900 - * ufshcd_get_rsp_upiu_data_seg_len - Get the data segment length 901 - * from response UPIU 902 - * @ucd_rsp_ptr: pointer to response UPIU 903 - * 904 - * Return the data segment length. 905 - */ 906 - static inline unsigned int 907 - ufshcd_get_rsp_upiu_data_seg_len(struct utp_upiu_rsp *ucd_rsp_ptr) 908 - { 909 - return be32_to_cpu(ucd_rsp_ptr->header.dword_2) & 910 - MASK_RSP_UPIU_DATA_SEG_LEN; 885 + return ucd_rsp_ptr->header.transaction_code; 911 886 } 912 887 913 888 /** ··· 892 917 * The function checks if the device raised an exception event indicated in 893 918 * the Device Information field of response UPIU. 894 919 * 895 - * Returns true if exception is raised, false otherwise. 920 + * Return: true if exception is raised, false otherwise. 896 921 */ 897 922 static inline bool ufshcd_is_exception_event(struct utp_upiu_rsp *ucd_rsp_ptr) 898 923 { 899 - return be32_to_cpu(ucd_rsp_ptr->header.dword_2) & 900 - MASK_RSP_EXCEPTION_EVENT; 924 + return ucd_rsp_ptr->header.device_information & 1; 901 925 } 902 926 903 927 /** ··· 967 993 * ufshcd_is_hba_active - Get controller state 968 994 * @hba: per adapter instance 969 995 * 970 - * Returns true if and only if the controller is active. 996 + * Return: true if and only if the controller is active. 971 997 */ 972 - static inline bool ufshcd_is_hba_active(struct ufs_hba *hba) 998 + bool ufshcd_is_hba_active(struct ufs_hba *hba) 973 999 { 974 1000 return ufshcd_readl(hba, REG_CONTROLLER_ENABLE) & CONTROLLER_ENABLE; 975 1001 } 1002 + EXPORT_SYMBOL_GPL(ufshcd_is_hba_active); 976 1003 977 1004 u32 ufshcd_get_local_unipro_ver(struct ufs_hba *hba) 978 1005 { ··· 1004 1029 * @hba: per adapter instance 1005 1030 * @scale_up: If True, set max possible frequency othewise set low frequency 1006 1031 * 1007 - * Returns 0 if successful 1008 - * Returns < 0 for any other errors 1032 + * Return: 0 if successful; < 0 upon failure. 1009 1033 */ 1010 1034 static int ufshcd_set_clk_freq(struct ufs_hba *hba, bool scale_up) 1011 1035 { ··· 1066 1092 * @hba: per adapter instance 1067 1093 * @scale_up: True if scaling up and false if scaling down 1068 1094 * 1069 - * Returns 0 if successful 1070 - * Returns < 0 for any other errors 1095 + * Return: 0 if successful; < 0 upon failure. 1071 1096 */ 1072 1097 static int ufshcd_scale_clks(struct ufs_hba *hba, bool scale_up) 1073 1098 { ··· 1097 1124 * @hba: per adapter instance 1098 1125 * @scale_up: True if scaling up and false if scaling down 1099 1126 * 1100 - * Returns true if scaling is required, false otherwise. 1127 + * Return: true if scaling is required, false otherwise. 1101 1128 */ 1102 1129 static bool ufshcd_is_devfreq_scaling_required(struct ufs_hba *hba, 1103 1130 bool scale_up) ··· 1214 1241 * @hba: per adapter instance 1215 1242 * @scale_up: True for scaling up gear and false for scaling down 1216 1243 * 1217 - * Returns 0 for success, 1218 - * Returns -EBUSY if scaling can't happen at this time 1219 - * Returns non-zero for any other errors 1244 + * Return: 0 for success; -EBUSY if scaling can't happen at this time; 1245 + * non-zero for any other errors. 1220 1246 */ 1221 1247 static int ufshcd_scale_gear(struct ufs_hba *hba, bool scale_up) 1222 1248 { ··· 1305 1333 * @hba: per adapter instance 1306 1334 * @scale_up: True for scaling up and false for scalin down 1307 1335 * 1308 - * Returns 0 for success, 1309 - * Returns -EBUSY if scaling can't happen at this time 1310 - * Returns non-zero for any other errors 1336 + * Return: 0 for success; -EBUSY if scaling can't happen at this time; non-zero 1337 + * for any other errors. 1311 1338 */ 1312 1339 static int ufshcd_devfreq_scale(struct ufs_hba *hba, bool scale_up) 1313 1340 { ··· 2196 2225 static inline void ufshcd_copy_sense_data(struct ufshcd_lrb *lrbp) 2197 2226 { 2198 2227 u8 *const sense_buffer = lrbp->cmd->sense_buffer; 2228 + u16 resp_len; 2199 2229 int len; 2200 2230 2201 - if (sense_buffer && 2202 - ufshcd_get_rsp_upiu_data_seg_len(lrbp->ucd_rsp_ptr)) { 2231 + resp_len = be16_to_cpu(lrbp->ucd_rsp_ptr->header.data_segment_length); 2232 + if (sense_buffer && resp_len) { 2203 2233 int len_to_copy; 2204 2234 2205 2235 len = be16_to_cpu(lrbp->ucd_rsp_ptr->sr.sense_data_len); ··· 2216 2244 * descriptor 2217 2245 * @hba: per adapter instance 2218 2246 * @lrbp: pointer to local reference block 2247 + * 2248 + * Return: 0 upon success; < 0 upon failure. 2219 2249 */ 2220 2250 static 2221 2251 int ufshcd_copy_query_response(struct ufs_hba *hba, struct ufshcd_lrb *lrbp) ··· 2235 2261 u16 buf_len; 2236 2262 2237 2263 /* data segment length */ 2238 - resp_len = be32_to_cpu(lrbp->ucd_rsp_ptr->header.dword_2) & 2239 - MASK_QUERY_DATA_SEG_LEN; 2264 + resp_len = be16_to_cpu(lrbp->ucd_rsp_ptr->header 2265 + .data_segment_length); 2240 2266 buf_len = be16_to_cpu( 2241 2267 hba->dev_cmd.query.request.upiu_req.length); 2242 2268 if (likely(buf_len >= resp_len)) { ··· 2294 2320 * ufshcd_ready_for_uic_cmd - Check if controller is ready 2295 2321 * to accept UIC commands 2296 2322 * @hba: per adapter instance 2297 - * Return true on success, else false 2323 + * 2324 + * Return: true on success, else false. 2298 2325 */ 2299 2326 static inline bool ufshcd_ready_for_uic_cmd(struct ufs_hba *hba) 2300 2327 { ··· 2307 2332 * @hba: Pointer to adapter instance 2308 2333 * 2309 2334 * This function gets the UPMCRS field of HCS register 2310 - * Returns value of UPMCRS field 2335 + * 2336 + * Return: value of UPMCRS field. 2311 2337 */ 2312 2338 static inline u8 ufshcd_get_upmcrs(struct ufs_hba *hba) 2313 2339 { ··· 2346 2370 * @hba: per adapter instance 2347 2371 * @uic_cmd: UIC command 2348 2372 * 2349 - * Returns 0 only if success. 2373 + * Return: 0 only if success. 2350 2374 */ 2351 2375 static int 2352 2376 ufshcd_wait_for_uic_cmd(struct ufs_hba *hba, struct uic_command *uic_cmd) ··· 2385 2409 * @uic_cmd: UIC command 2386 2410 * @completion: initialize the completion only if this is set to true 2387 2411 * 2388 - * Returns 0 only if success. 2412 + * Return: 0 only if success. 2389 2413 */ 2390 2414 static int 2391 2415 __ufshcd_send_uic_cmd(struct ufs_hba *hba, struct uic_command *uic_cmd, ··· 2414 2438 * @hba: per adapter instance 2415 2439 * @uic_cmd: UIC command 2416 2440 * 2417 - * Returns 0 only if success. 2441 + * Return: 0 only if success. 2418 2442 */ 2419 2443 int ufshcd_send_uic_cmd(struct ufs_hba *hba, struct uic_command *uic_cmd) 2420 2444 { ··· 2491 2515 * @hba: per adapter instance 2492 2516 * @lrbp: pointer to local reference block 2493 2517 * 2494 - * Returns 0 in case of success, non-zero value in case of failure 2518 + * Return: 0 in case of success, non-zero value in case of failure. 2495 2519 */ 2496 2520 static int ufshcd_map_sg(struct ufs_hba *hba, struct ufshcd_lrb *lrbp) 2497 2521 { ··· 2560 2584 enum dma_data_direction cmd_dir, int ehs_length) 2561 2585 { 2562 2586 struct utp_transfer_req_desc *req_desc = lrbp->utr_descriptor_ptr; 2563 - u32 data_direction; 2564 - u32 dword_0; 2565 - u32 dword_1 = 0; 2566 - u32 dword_3 = 0; 2587 + struct request_desc_header *h = &req_desc->header; 2588 + enum utp_data_direction data_direction; 2589 + 2590 + *h = (typeof(*h)){ }; 2567 2591 2568 2592 if (cmd_dir == DMA_FROM_DEVICE) { 2569 2593 data_direction = UTP_DEVICE_TO_HOST; ··· 2576 2600 *upiu_flags = UPIU_CMD_FLAGS_NONE; 2577 2601 } 2578 2602 2579 - dword_0 = data_direction | (lrbp->command_type << UPIU_COMMAND_TYPE_OFFSET) | 2580 - ehs_length << 8; 2603 + h->command_type = lrbp->command_type; 2604 + h->data_direction = data_direction; 2605 + h->ehs_length = ehs_length; 2606 + 2581 2607 if (lrbp->intr_cmd) 2582 - dword_0 |= UTP_REQ_DESC_INT_CMD; 2608 + h->interrupt = 1; 2583 2609 2584 2610 /* Prepare crypto related dwords */ 2585 - ufshcd_prepare_req_desc_hdr_crypto(lrbp, &dword_0, &dword_1, &dword_3); 2611 + ufshcd_prepare_req_desc_hdr_crypto(lrbp, h); 2586 2612 2587 - /* Transfer request descriptor header fields */ 2588 - req_desc->header.dword_0 = cpu_to_le32(dword_0); 2589 - req_desc->header.dword_1 = cpu_to_le32(dword_1); 2590 2613 /* 2591 2614 * assigning invalid value for command status. Controller 2592 2615 * updates OCS on command completion, with the command 2593 2616 * status 2594 2617 */ 2595 - req_desc->header.dword_2 = 2596 - cpu_to_le32(OCS_INVALID_COMMAND_STATUS); 2597 - req_desc->header.dword_3 = cpu_to_le32(dword_3); 2618 + h->ocs = OCS_INVALID_COMMAND_STATUS; 2598 2619 2599 2620 req_desc->prd_table_length = 0; 2600 2621 } ··· 2609 2636 struct utp_upiu_req *ucd_req_ptr = lrbp->ucd_req_ptr; 2610 2637 unsigned short cdb_len; 2611 2638 2612 - /* command descriptor fields */ 2613 - ucd_req_ptr->header.dword_0 = UPIU_HEADER_DWORD( 2614 - UPIU_TRANSACTION_COMMAND, upiu_flags, 2615 - lrbp->lun, lrbp->task_tag); 2616 - ucd_req_ptr->header.dword_1 = UPIU_HEADER_DWORD( 2617 - UPIU_COMMAND_SET_TYPE_SCSI, 0, 0, 0); 2618 - 2619 - /* Total EHS length and Data segment length will be zero */ 2620 - ucd_req_ptr->header.dword_2 = 0; 2639 + ucd_req_ptr->header = (struct utp_upiu_header){ 2640 + .transaction_code = UPIU_TRANSACTION_COMMAND, 2641 + .flags = upiu_flags, 2642 + .lun = lrbp->lun, 2643 + .task_tag = lrbp->task_tag, 2644 + .command_set_type = UPIU_COMMAND_SET_TYPE_SCSI, 2645 + }; 2621 2646 2622 2647 ucd_req_ptr->sc.exp_data_transfer_len = cpu_to_be32(cmd->sdb.length); 2623 2648 ··· 2640 2669 u16 len = be16_to_cpu(query->request.upiu_req.length); 2641 2670 2642 2671 /* Query request header */ 2643 - ucd_req_ptr->header.dword_0 = UPIU_HEADER_DWORD( 2644 - UPIU_TRANSACTION_QUERY_REQ, upiu_flags, 2645 - lrbp->lun, lrbp->task_tag); 2646 - ucd_req_ptr->header.dword_1 = UPIU_HEADER_DWORD( 2647 - 0, query->request.query_func, 0, 0); 2648 - 2649 - /* Data segment length only need for WRITE_DESC */ 2650 - if (query->request.upiu_req.opcode == UPIU_QUERY_OPCODE_WRITE_DESC) 2651 - ucd_req_ptr->header.dword_2 = 2652 - UPIU_HEADER_DWORD(0, 0, (len >> 8), (u8)len); 2653 - else 2654 - ucd_req_ptr->header.dword_2 = 0; 2672 + ucd_req_ptr->header = (struct utp_upiu_header){ 2673 + .transaction_code = UPIU_TRANSACTION_QUERY_REQ, 2674 + .flags = upiu_flags, 2675 + .lun = lrbp->lun, 2676 + .task_tag = lrbp->task_tag, 2677 + .query_function = query->request.query_func, 2678 + /* Data segment length only need for WRITE_DESC */ 2679 + .data_segment_length = 2680 + query->request.upiu_req.opcode == 2681 + UPIU_QUERY_OPCODE_WRITE_DESC ? 2682 + cpu_to_be16(len) : 2683 + 0, 2684 + }; 2655 2685 2656 2686 /* Copy the Query Request buffer as is */ 2657 2687 memcpy(&ucd_req_ptr->qr, &query->request.upiu_req, ··· 2671 2699 2672 2700 memset(ucd_req_ptr, 0, sizeof(struct utp_upiu_req)); 2673 2701 2674 - /* command descriptor fields */ 2675 - ucd_req_ptr->header.dword_0 = 2676 - UPIU_HEADER_DWORD( 2677 - UPIU_TRANSACTION_NOP_OUT, 0, 0, lrbp->task_tag); 2678 - /* clear rest of the fields of basic header */ 2679 - ucd_req_ptr->header.dword_1 = 0; 2680 - ucd_req_ptr->header.dword_2 = 0; 2702 + ucd_req_ptr->header = (struct utp_upiu_header){ 2703 + .transaction_code = UPIU_TRANSACTION_NOP_OUT, 2704 + .task_tag = lrbp->task_tag, 2705 + }; 2681 2706 2682 2707 memset(lrbp->ucd_rsp_ptr, 0, sizeof(struct utp_upiu_rsp)); 2683 2708 } ··· 2684 2715 * for Device Management Purposes 2685 2716 * @hba: per adapter instance 2686 2717 * @lrbp: pointer to local reference block 2718 + * 2719 + * Return: 0 upon success; < 0 upon failure. 2687 2720 */ 2688 2721 static int ufshcd_compose_devman_upiu(struct ufs_hba *hba, 2689 2722 struct ufshcd_lrb *lrbp) ··· 2714 2743 * for SCSI Purposes 2715 2744 * @hba: per adapter instance 2716 2745 * @lrbp: pointer to local reference block 2746 + * 2747 + * Return: 0 upon success; < 0 upon failure. 2717 2748 */ 2718 2749 static int ufshcd_comp_scsi_upiu(struct ufs_hba *hba, struct ufshcd_lrb *lrbp) 2719 2750 { ··· 2741 2768 * ufshcd_upiu_wlun_to_scsi_wlun - maps UPIU W-LUN id to SCSI W-LUN ID 2742 2769 * @upiu_wlun_id: UPIU W-LUN id 2743 2770 * 2744 - * Returns SCSI W-LUN id 2771 + * Return: SCSI W-LUN id. 2745 2772 */ 2746 2773 static inline u16 ufshcd_upiu_wlun_to_scsi_wlun(u8 upiu_wlun_id) 2747 2774 { ··· 2812 2839 * @host: SCSI host pointer 2813 2840 * @cmd: command from SCSI Midlayer 2814 2841 * 2815 - * Returns 0 for success, non-zero in case of failure 2842 + * Return: 0 for success, non-zero in case of failure. 2816 2843 */ 2817 2844 static int ufshcd_queuecommand(struct Scsi_Host *host, struct scsi_cmnd *cmd) 2818 2845 { ··· 2881 2908 2882 2909 lrbp->req_abort_skip = false; 2883 2910 2884 - ufshpb_prep(hba, lrbp); 2885 - 2886 2911 ufshcd_comp_scsi_upiu(hba, lrbp); 2887 2912 2888 2913 err = ufshcd_map_sg(hba, lrbp); ··· 2923 2952 * Check with the block layer if the command is inflight 2924 2953 * @cmd: command to check. 2925 2954 * 2926 - * Returns true if command is inflight; false if not. 2955 + * Return: true if command is inflight; false if not. 2927 2956 */ 2928 2957 bool ufshcd_cmd_inflight(struct scsi_cmnd *cmd) 2929 2958 { ··· 2978 3007 mask, ~mask, 1000, 1000); 2979 3008 } 2980 3009 2981 - static int 2982 - ufshcd_check_query_response(struct ufs_hba *hba, struct ufshcd_lrb *lrbp) 2983 - { 2984 - struct ufs_query_res *query_res = &hba->dev_cmd.query.response; 2985 - 2986 - /* Get the UPIU response */ 2987 - query_res->response = ufshcd_get_rsp_upiu_result(lrbp->ucd_rsp_ptr) >> 2988 - UPIU_RSP_CODE_OFFSET; 2989 - return query_res->response; 2990 - } 2991 - 2992 3010 /** 2993 3011 * ufshcd_dev_cmd_completion() - handles device management command responses 2994 3012 * @hba: per adapter instance 2995 3013 * @lrbp: pointer to local reference block 3014 + * 3015 + * Return: 0 upon success; < 0 upon failure. 2996 3016 */ 2997 3017 static int 2998 3018 ufshcd_dev_cmd_completion(struct ufs_hba *hba, struct ufshcd_lrb *lrbp) 2999 3019 { 3000 - int resp; 3020 + enum upiu_response_transaction resp; 3001 3021 int err = 0; 3002 3022 3003 3023 hba->ufs_stats.last_hibern8_exit_tstamp = ktime_set(0, 0); ··· 3002 3040 __func__, resp); 3003 3041 } 3004 3042 break; 3005 - case UPIU_TRANSACTION_QUERY_RSP: 3006 - err = ufshcd_check_query_response(hba, lrbp); 3007 - if (!err) 3043 + case UPIU_TRANSACTION_QUERY_RSP: { 3044 + u8 response = lrbp->ucd_rsp_ptr->header.response; 3045 + 3046 + if (response == 0) 3008 3047 err = ufshcd_copy_query_response(hba, lrbp); 3009 3048 break; 3049 + } 3010 3050 case UPIU_TRANSACTION_REJECT_UPIU: 3011 3051 /* TODO: handle Reject UPIU Response */ 3012 3052 err = -EPERM; ··· 3123 3159 * @cmd_type: specifies the type (NOP, Query...) 3124 3160 * @timeout: timeout in milliseconds 3125 3161 * 3162 + * Return: 0 upon success; < 0 upon failure. 3163 + * 3126 3164 * NOTE: Since there is only one available tag for device management commands, 3127 3165 * it is expected you hold the hba->dev_cmd.lock mutex. 3128 3166 */ ··· 3216 3250 * @index: flag index to access 3217 3251 * @flag_res: the flag value after the query request completes 3218 3252 * 3219 - * Returns 0 for success, non-zero in case of failure 3253 + * Return: 0 for success, non-zero in case of failure. 3220 3254 */ 3221 3255 int ufshcd_query_flag(struct ufs_hba *hba, enum query_opcode opcode, 3222 3256 enum flag_idn idn, u8 index, bool *flag_res) ··· 3285 3319 * @selector: selector field 3286 3320 * @attr_val: the attribute value after the query request completes 3287 3321 * 3288 - * Returns 0 for success, non-zero in case of failure 3322 + * Return: 0 for success, non-zero in case of failure. 3289 3323 */ 3290 3324 int ufshcd_query_attr(struct ufs_hba *hba, enum query_opcode opcode, 3291 3325 enum attr_idn idn, u8 index, u8 selector, u32 *attr_val) ··· 3350 3384 * @attr_val: the attribute value after the query request 3351 3385 * completes 3352 3386 * 3353 - * Returns 0 for success, non-zero in case of failure 3387 + * Return: 0 for success, non-zero in case of failure. 3354 3388 */ 3355 3389 int ufshcd_query_attr_retry(struct ufs_hba *hba, 3356 3390 enum query_opcode opcode, enum attr_idn idn, u8 index, u8 selector, ··· 3448 3482 * @desc_buf: the buffer that contains the descriptor 3449 3483 * @buf_len: length parameter passed to the device 3450 3484 * 3451 - * Returns 0 for success, non-zero in case of failure. 3452 3485 * The buf_len parameter will contain, on return, the length parameter 3453 3486 * received on the response. 3487 + * 3488 + * Return: 0 for success, non-zero in case of failure. 3454 3489 */ 3455 3490 int ufshcd_query_descriptor_retry(struct ufs_hba *hba, 3456 3491 enum query_opcode opcode, ··· 3481 3514 * @param_read_buf: pointer to buffer where parameter would be read 3482 3515 * @param_size: sizeof(param_read_buf) 3483 3516 * 3484 - * Return 0 in case of success, non-zero otherwise 3517 + * Return: 0 in case of success, non-zero otherwise. 3485 3518 */ 3486 3519 int ufshcd_read_desc_param(struct ufs_hba *hba, 3487 3520 enum desc_idn desc_id, ··· 3661 3694 * @param_read_buf: pointer to buffer where parameter would be read 3662 3695 * @param_size: sizeof(param_read_buf) 3663 3696 * 3664 - * Return 0 in case of success, non-zero otherwise 3697 + * Return: 0 in case of success, non-zero otherwise. 3665 3698 */ 3666 3699 static inline int ufshcd_read_unit_desc_param(struct ufs_hba *hba, 3667 3700 int lun, ··· 3716 3749 * (UTMRDL) 3717 3750 * 4. Allocate memory for local reference block(lrb). 3718 3751 * 3719 - * Returns 0 for success, non-zero in case of failure 3752 + * Return: 0 for success, non-zero in case of failure. 3720 3753 */ 3721 3754 static int ufshcd_memory_alloc(struct ufs_hba *hba) 3722 3755 { ··· 3863 3896 * Once the Unipro links are up, the device connected to the controller 3864 3897 * is detected. 3865 3898 * 3866 - * Returns 0 on success, non-zero value on failure 3899 + * Return: 0 on success, non-zero value on failure. 3867 3900 */ 3868 3901 static int ufshcd_dme_link_startup(struct ufs_hba *hba) 3869 3902 { ··· 3885 3918 * DME_RESET command is issued in order to reset UniPro stack. 3886 3919 * This function now deals with cold reset. 3887 3920 * 3888 - * Returns 0 on success, non-zero value on failure 3921 + * Return: 0 on success, non-zero value on failure. 3889 3922 */ 3890 3923 static int ufshcd_dme_reset(struct ufs_hba *hba) 3891 3924 { ··· 3924 3957 * 3925 3958 * DME_ENABLE command is issued in order to enable UniPro stack. 3926 3959 * 3927 - * Returns 0 on success, non-zero value on failure 3960 + * Return: 0 on success, non-zero value on failure. 3928 3961 */ 3929 3962 static int ufshcd_dme_enable(struct ufs_hba *hba) 3930 3963 { ··· 3980 4013 * @mib_val: setting value as uic command argument3 3981 4014 * @peer: indicate whether peer or local 3982 4015 * 3983 - * Returns 0 on success, non-zero value on failure 4016 + * Return: 0 on success, non-zero value on failure. 3984 4017 */ 3985 4018 int ufshcd_dme_set_attr(struct ufs_hba *hba, u32 attr_sel, 3986 4019 u8 attr_set, u32 mib_val, u8 peer) ··· 4024 4057 * @mib_val: the value of the attribute as returned by the UIC command 4025 4058 * @peer: indicate whether peer or local 4026 4059 * 4027 - * Returns 0 on success, non-zero value on failure 4060 + * Return: 0 on success, non-zero value on failure. 4028 4061 */ 4029 4062 int ufshcd_dme_get_attr(struct ufs_hba *hba, u32 attr_sel, 4030 4063 u32 *mib_val, u8 peer) ··· 4105 4138 * addition to normal UIC command completion Status (UCCS). This function only 4106 4139 * returns after the relevant status bits indicate the completion. 4107 4140 * 4108 - * Returns 0 on success, non-zero value on failure 4141 + * Return: 0 on success, non-zero value on failure. 4109 4142 */ 4110 4143 static int ufshcd_uic_pwr_ctrl(struct ufs_hba *hba, struct uic_command *cmd) 4111 4144 { ··· 4195 4228 * @hba: per adapter instance 4196 4229 * @mode: powr mode value 4197 4230 * 4198 - * Returns 0 on success, non-zero value on failure 4231 + * Return: 0 on success, non-zero value on failure. 4199 4232 */ 4200 4233 int ufshcd_uic_change_pwr_mode(struct ufs_hba *hba, u8 mode) 4201 4234 { ··· 4347 4380 { 4348 4381 hba->pwr_info.gear_rx = UFS_PWM_G1; 4349 4382 hba->pwr_info.gear_tx = UFS_PWM_G1; 4350 - hba->pwr_info.lane_rx = 1; 4351 - hba->pwr_info.lane_tx = 1; 4383 + hba->pwr_info.lane_rx = UFS_LANE_1; 4384 + hba->pwr_info.lane_tx = UFS_LANE_1; 4352 4385 hba->pwr_info.pwr_rx = SLOWAUTO_MODE; 4353 4386 hba->pwr_info.pwr_tx = SLOWAUTO_MODE; 4354 4387 hba->pwr_info.hs_rate = 0; ··· 4357 4390 /** 4358 4391 * ufshcd_get_max_pwr_mode - reads the max power mode negotiated with device 4359 4392 * @hba: per-adapter instance 4393 + * 4394 + * Return: 0 upon success; < 0 upon failure. 4360 4395 */ 4361 4396 static int ufshcd_get_max_pwr_mode(struct ufs_hba *hba) 4362 4397 { ··· 4516 4547 * ufshcd_config_pwr_mode - configure a new power mode 4517 4548 * @hba: per-adapter instance 4518 4549 * @desired_pwr_mode: desired power configuration 4550 + * 4551 + * Return: 0 upon success; < 0 upon failure. 4519 4552 */ 4520 4553 int ufshcd_config_pwr_mode(struct ufs_hba *hba, 4521 4554 struct ufs_pa_layer_attr *desired_pwr_mode) ··· 4542 4571 * @hba: per-adapter instance 4543 4572 * 4544 4573 * Set fDeviceInit flag and poll until device toggles it. 4574 + * 4575 + * Return: 0 upon success; < 0 upon failure. 4545 4576 */ 4546 4577 static int ufshcd_complete_dev_init(struct ufs_hba *hba) 4547 4578 { ··· 4594 4621 * 3. Program UTRL and UTMRL base address 4595 4622 * 4. Configure run-stop-registers 4596 4623 * 4597 - * Returns 0 on success, non-zero value on failure 4624 + * Return: 0 on success, non-zero value on failure. 4598 4625 */ 4599 4626 int ufshcd_make_hba_operational(struct ufs_hba *hba) 4600 4627 { ··· 4675 4702 * sequence kicks off. When controller is ready it will set 4676 4703 * the Host Controller Enable bit to 1. 4677 4704 * 4678 - * Returns 0 on success, non-zero value on failure 4705 + * Return: 0 on success, non-zero value on failure. 4679 4706 */ 4680 4707 static int ufshcd_hba_execute_hce(struct ufs_hba *hba) 4681 4708 { ··· 4820 4847 * ufshcd_link_startup - Initialize unipro link startup 4821 4848 * @hba: per adapter instance 4822 4849 * 4823 - * Returns 0 for success, non-zero in case of failure 4850 + * Return: 0 for success, non-zero in case of failure. 4824 4851 */ 4825 4852 static int ufshcd_link_startup(struct ufs_hba *hba) 4826 4853 { ··· 4915 4942 * If the UTP layer at the device side is not initialized, it may 4916 4943 * not respond with NOP IN UPIU within timeout of %NOP_OUT_TIMEOUT 4917 4944 * and we retry sending NOP OUT for %NOP_OUT_RETRIES iterations. 4945 + * 4946 + * Return: 0 upon success; < 0 upon failure. 4918 4947 */ 4919 4948 static int ufshcd_verify_dev_init(struct ufs_hba *hba) 4920 4949 { ··· 5041 5066 * ufshcd_slave_alloc - handle initial SCSI device configurations 5042 5067 * @sdev: pointer to SCSI device 5043 5068 * 5044 - * Returns success 5069 + * Return: success. 5045 5070 */ 5046 5071 static int ufshcd_slave_alloc(struct scsi_device *sdev) 5047 5072 { ··· 5077 5102 * @depth: required depth to set 5078 5103 * 5079 5104 * Change queue depth and make sure the max. limits are not crossed. 5105 + * 5106 + * Return: new queue depth. 5080 5107 */ 5081 5108 static int ufshcd_change_queue_depth(struct scsi_device *sdev, int depth) 5082 5109 { 5083 5110 return scsi_change_queue_depth(sdev, min(depth, sdev->host->can_queue)); 5084 5111 } 5085 5112 5086 - static void ufshcd_hpb_destroy(struct ufs_hba *hba, struct scsi_device *sdev) 5087 - { 5088 - /* skip well-known LU */ 5089 - if ((sdev->lun >= UFS_UPIU_MAX_UNIT_NUM_ID) || 5090 - !(hba->dev_info.hpb_enabled) || !ufshpb_is_allowed(hba)) 5091 - return; 5092 - 5093 - ufshpb_destroy_lu(hba, sdev); 5094 - } 5095 - 5096 - static void ufshcd_hpb_configure(struct ufs_hba *hba, struct scsi_device *sdev) 5097 - { 5098 - /* skip well-known LU */ 5099 - if ((sdev->lun >= UFS_UPIU_MAX_UNIT_NUM_ID) || 5100 - !(hba->dev_info.hpb_enabled) || !ufshpb_is_allowed(hba)) 5101 - return; 5102 - 5103 - ufshpb_init_hpb_lu(hba, sdev); 5104 - } 5105 - 5106 5113 /** 5107 5114 * ufshcd_slave_configure - adjust SCSI device configurations 5108 5115 * @sdev: pointer to SCSI device 5116 + * 5117 + * Return: 0 (success). 5109 5118 */ 5110 5119 static int ufshcd_slave_configure(struct scsi_device *sdev) 5111 5120 { 5112 5121 struct ufs_hba *hba = shost_priv(sdev->host); 5113 5122 struct request_queue *q = sdev->request_queue; 5114 - 5115 - ufshcd_hpb_configure(hba, sdev); 5116 5123 5117 5124 blk_queue_update_dma_pad(q, PRDT_DATA_BYTE_COUNT_PAD - 1); 5118 5125 if (hba->quirks & UFSHCD_QUIRK_4KB_DMA_ALIGNMENT) ··· 5130 5173 5131 5174 hba = shost_priv(sdev->host); 5132 5175 5133 - ufshcd_hpb_destroy(hba, sdev); 5134 - 5135 5176 /* Drop the reference as it won't be needed anymore */ 5136 5177 if (ufshcd_scsi_to_upiu_lun(sdev->lun) == UFS_UPIU_UFS_DEVICE_WLUN) { 5137 5178 spin_lock_irqsave(hba->host->host_lock, flags); ··· 5163 5208 * @lrbp: pointer to local reference block of completed command 5164 5209 * @scsi_status: SCSI command status 5165 5210 * 5166 - * Returns value base on SCSI command status 5211 + * Return: value base on SCSI command status. 5167 5212 */ 5168 5213 static inline int 5169 5214 ufshcd_scsi_cmd_status(struct ufshcd_lrb *lrbp, int scsi_status) ··· 5197 5242 * @lrbp: pointer to local reference block of completed command 5198 5243 * @cqe: pointer to the completion queue entry 5199 5244 * 5200 - * Returns result of the command to notify SCSI midlayer 5245 + * Return: result of the command to notify SCSI midlayer. 5201 5246 */ 5202 5247 static inline int 5203 5248 ufshcd_transfer_rsp_status(struct ufs_hba *hba, struct ufshcd_lrb *lrbp, ··· 5206 5251 int result = 0; 5207 5252 int scsi_status; 5208 5253 enum utp_ocs ocs; 5254 + u8 upiu_flags; 5255 + u32 resid; 5209 5256 5210 - scsi_set_resid(lrbp->cmd, 5211 - be32_to_cpu(lrbp->ucd_rsp_ptr->sr.residual_transfer_count)); 5257 + upiu_flags = lrbp->ucd_rsp_ptr->header.flags; 5258 + resid = be32_to_cpu(lrbp->ucd_rsp_ptr->sr.residual_transfer_count); 5259 + /* 5260 + * Test !overflow instead of underflow to support UFS devices that do 5261 + * not set either flag. 5262 + */ 5263 + if (resid && !(upiu_flags & UPIU_RSP_FLAG_OVERFLOW)) 5264 + scsi_set_resid(lrbp->cmd, resid); 5212 5265 5213 5266 /* overall command status of utrd */ 5214 5267 ocs = ufshcd_get_tr_ocs(lrbp, cqe); 5215 5268 5216 5269 if (hba->quirks & UFSHCD_QUIRK_BROKEN_OCS_FATAL_ERROR) { 5217 - if (be32_to_cpu(lrbp->ucd_rsp_ptr->header.dword_1) & 5218 - MASK_RSP_UPIU_RESULT) 5270 + if (lrbp->ucd_rsp_ptr->header.response || 5271 + lrbp->ucd_rsp_ptr->header.status) 5219 5272 ocs = OCS_SUCCESS; 5220 5273 } 5221 5274 5222 5275 switch (ocs) { 5223 5276 case OCS_SUCCESS: 5224 - result = ufshcd_get_req_rsp(lrbp->ucd_rsp_ptr); 5225 5277 hba->ufs_stats.last_hibern8_exit_tstamp = ktime_set(0, 0); 5226 - switch (result) { 5278 + switch (ufshcd_get_req_rsp(lrbp->ucd_rsp_ptr)) { 5227 5279 case UPIU_TRANSACTION_RESPONSE: 5228 - /* 5229 - * get the response UPIU result to extract 5230 - * the SCSI command status 5231 - */ 5232 - result = ufshcd_get_rsp_upiu_result(lrbp->ucd_rsp_ptr); 5233 - 5234 5280 /* 5235 5281 * get the result based on SCSI status response 5236 5282 * to notify the SCSI midlayer of the command status 5237 5283 */ 5238 - scsi_status = result & MASK_SCSI_STATUS; 5284 + scsi_status = lrbp->ucd_rsp_ptr->header.status; 5239 5285 result = ufshcd_scsi_cmd_status(lrbp, scsi_status); 5240 5286 5241 5287 /* ··· 5256 5300 ufshcd_is_exception_event(lrbp->ucd_rsp_ptr)) 5257 5301 /* Flushed in suspend */ 5258 5302 schedule_work(&hba->eeh_work); 5259 - 5260 - if (scsi_status == SAM_STAT_GOOD) 5261 - ufshpb_rsp_upiu(hba, lrbp); 5262 5303 break; 5263 5304 case UPIU_TRANSACTION_REJECT_UPIU: 5264 5305 /* TODO: handle Reject UPIU Response */ ··· 5325 5372 * @hba: per adapter instance 5326 5373 * @intr_status: interrupt status generated by the controller 5327 5374 * 5328 - * Returns 5375 + * Return: 5329 5376 * IRQ_HANDLED - If interrupt is valid 5330 5377 * IRQ_NONE - If invalid interrupt 5331 5378 */ ··· 5401 5448 if (hba->dev_cmd.complete) { 5402 5449 if (cqe) { 5403 5450 ocs = le32_to_cpu(cqe->status) & MASK_OCS; 5404 - lrbp->utr_descriptor_ptr->header.dword_2 = 5405 - cpu_to_le32(ocs); 5451 + lrbp->utr_descriptor_ptr->header.ocs = ocs; 5406 5452 } 5407 5453 complete(hba->dev_cmd.complete); 5408 5454 ufshcd_clk_scaling_update_busy(hba); ··· 5444 5492 } 5445 5493 5446 5494 /* 5447 - * Returns > 0 if one or more commands have been completed or 0 if no 5495 + * Return: > 0 if one or more commands have been completed or 0 if no 5448 5496 * requests have been completed. 5449 5497 */ 5450 5498 static int ufshcd_poll(struct Scsi_Host *shost, unsigned int queue_num) ··· 5534 5582 * ufshcd_transfer_req_compl - handle SCSI and query command completion 5535 5583 * @hba: per adapter instance 5536 5584 * 5537 - * Returns 5585 + * Return: 5538 5586 * IRQ_HANDLED - If interrupt is valid 5539 5587 * IRQ_NONE - If invalid interrupt 5540 5588 */ ··· 5611 5659 * Disables exception event in the device so that the EVENT_ALERT 5612 5660 * bit is not set. 5613 5661 * 5614 - * Returns zero on success, non-zero error value on failure. 5662 + * Return: zero on success, non-zero error value on failure. 5615 5663 */ 5616 5664 static inline int ufshcd_disable_ee(struct ufs_hba *hba, u16 mask) 5617 5665 { ··· 5626 5674 * Enable corresponding exception event in the device to allow 5627 5675 * device to alert host in critical scenarios. 5628 5676 * 5629 - * Returns zero on success, non-zero error value on failure. 5677 + * Return: zero on success, non-zero error value on failure. 5630 5678 */ 5631 5679 static inline int ufshcd_enable_ee(struct ufs_hba *hba, u16 mask) 5632 5680 { ··· 5642 5690 * as the device is allowed to manage its own way of handling background 5643 5691 * operations. 5644 5692 * 5645 - * Returns zero on success, non-zero on failure. 5693 + * Return: zero on success, non-zero on failure. 5646 5694 */ 5647 5695 static int ufshcd_enable_auto_bkops(struct ufs_hba *hba) 5648 5696 { ··· 5681 5729 * host is idle so that BKOPS are managed effectively without any negative 5682 5730 * impacts. 5683 5731 * 5684 - * Returns zero on success, non-zero on failure. 5732 + * Return: zero on success, non-zero on failure. 5685 5733 */ 5686 5734 static int ufshcd_disable_auto_bkops(struct ufs_hba *hba) 5687 5735 { ··· 5757 5805 * bkops_status is greater than or equal to "status" argument passed to 5758 5806 * this function, disable otherwise. 5759 5807 * 5760 - * Returns 0 for success, non-zero in case of failure. 5808 + * Return: 0 for success, non-zero in case of failure. 5761 5809 * 5762 5810 * NOTE: Caller of this function can check the "hba->auto_bkops_enabled" flag 5763 5811 * to know whether auto bkops is enabled or disabled after this function ··· 5798 5846 * 5799 5847 * If BKOPs is enabled, this function returns 0, 1 if the bkops in not enabled 5800 5848 * and negative error value for any other failure. 5849 + * 5850 + * Return: 0 upon success; < 0 upon failure. 5801 5851 */ 5802 5852 static int ufshcd_urgent_bkops(struct ufs_hba *hba) 5803 5853 { ··· 6111 6157 * to recover from the DL NAC errors or not. 6112 6158 * @hba: per-adapter instance 6113 6159 * 6114 - * Returns true if error handling is required, false otherwise 6160 + * Return: true if error handling is required, false otherwise. 6115 6161 */ 6116 6162 static bool ufshcd_quirk_dl_nac_errors(struct ufs_hba *hba) 6117 6163 { ··· 6338 6384 return false; 6339 6385 } 6340 6386 6387 + static bool ufshcd_abort_one(struct request *rq, void *priv) 6388 + { 6389 + int *ret = priv; 6390 + u32 tag = rq->tag; 6391 + struct scsi_cmnd *cmd = blk_mq_rq_to_pdu(rq); 6392 + struct scsi_device *sdev = cmd->device; 6393 + struct Scsi_Host *shost = sdev->host; 6394 + struct ufs_hba *hba = shost_priv(shost); 6395 + 6396 + *ret = ufshcd_try_to_abort_task(hba, tag); 6397 + dev_err(hba->dev, "Aborting tag %d / CDB %#02x %s\n", tag, 6398 + hba->lrb[tag].cmd ? hba->lrb[tag].cmd->cmnd[0] : -1, 6399 + *ret ? "failed" : "succeeded"); 6400 + return *ret == 0; 6401 + } 6402 + 6403 + /** 6404 + * ufshcd_abort_all - Abort all pending commands. 6405 + * @hba: Host bus adapter pointer. 6406 + * 6407 + * Return: true if and only if the host controller needs to be reset. 6408 + */ 6341 6409 static bool ufshcd_abort_all(struct ufs_hba *hba) 6342 6410 { 6343 - bool needs_reset = false; 6344 - int tag, ret; 6411 + int tag, ret = 0; 6345 6412 6346 - if (is_mcq_enabled(hba)) { 6347 - struct ufshcd_lrb *lrbp; 6348 - int tag; 6413 + blk_mq_tagset_busy_iter(&hba->host->tag_set, ufshcd_abort_one, &ret); 6414 + if (ret) 6415 + goto out; 6349 6416 6350 - for (tag = 0; tag < hba->nutrs; tag++) { 6351 - lrbp = &hba->lrb[tag]; 6352 - if (!ufshcd_cmd_inflight(lrbp->cmd)) 6353 - continue; 6354 - ret = ufshcd_try_to_abort_task(hba, tag); 6355 - dev_err(hba->dev, "Aborting tag %d / CDB %#02x %s\n", tag, 6356 - hba->lrb[tag].cmd ? hba->lrb[tag].cmd->cmnd[0] : -1, 6357 - ret ? "failed" : "succeeded"); 6358 - if (ret) { 6359 - needs_reset = true; 6360 - goto out; 6361 - } 6362 - } 6363 - } else { 6364 - /* Clear pending transfer requests */ 6365 - for_each_set_bit(tag, &hba->outstanding_reqs, hba->nutrs) { 6366 - ret = ufshcd_try_to_abort_task(hba, tag); 6367 - dev_err(hba->dev, "Aborting tag %d / CDB %#02x %s\n", tag, 6368 - hba->lrb[tag].cmd ? hba->lrb[tag].cmd->cmnd[0] : -1, 6369 - ret ? "failed" : "succeeded"); 6370 - if (ret) { 6371 - needs_reset = true; 6372 - goto out; 6373 - } 6374 - } 6375 - } 6376 6417 /* Clear pending task management requests */ 6377 6418 for_each_set_bit(tag, &hba->outstanding_tasks, hba->nutmrs) { 6378 - if (ufshcd_clear_tm_cmd(hba, tag)) { 6379 - needs_reset = true; 6419 + ret = ufshcd_clear_tm_cmd(hba, tag); 6420 + if (ret) 6380 6421 goto out; 6381 - } 6382 6422 } 6383 6423 6384 6424 out: 6385 6425 /* Complete the requests that are cleared by s/w */ 6386 6426 ufshcd_complete_requests(hba, false); 6387 6427 6388 - return needs_reset; 6428 + return ret != 0; 6389 6429 } 6390 6430 6391 6431 /** ··· 6566 6618 * ufshcd_update_uic_error - check and set fatal UIC error flags. 6567 6619 * @hba: per-adapter instance 6568 6620 * 6569 - * Returns 6621 + * Return: 6570 6622 * IRQ_HANDLED - If interrupt is valid 6571 6623 * IRQ_NONE - If invalid interrupt 6572 6624 */ ··· 6659 6711 * @hba: per-adapter instance 6660 6712 * @intr_status: interrupt status generated by the controller 6661 6713 * 6662 - * Returns 6714 + * Return: 6663 6715 * IRQ_HANDLED - If interrupt is valid 6664 6716 * IRQ_NONE - If invalid interrupt 6665 6717 */ ··· 6735 6787 * ufshcd_tmc_handler - handle task management function completion 6736 6788 * @hba: per adapter instance 6737 6789 * 6738 - * Returns 6790 + * Return: 6739 6791 * IRQ_HANDLED - If interrupt is valid 6740 6792 * IRQ_NONE - If invalid interrupt 6741 6793 */ ··· 6764 6816 * ufshcd_handle_mcq_cq_events - handle MCQ completion queue events 6765 6817 * @hba: per adapter instance 6766 6818 * 6767 - * Returns IRQ_HANDLED if interrupt is handled 6819 + * Return: IRQ_HANDLED if interrupt is handled. 6768 6820 */ 6769 6821 static irqreturn_t ufshcd_handle_mcq_cq_events(struct ufs_hba *hba) 6770 6822 { ··· 6799 6851 * @hba: per adapter instance 6800 6852 * @intr_status: contains interrupts generated by the controller 6801 6853 * 6802 - * Returns 6854 + * Return: 6803 6855 * IRQ_HANDLED - If interrupt is valid 6804 6856 * IRQ_NONE - If invalid interrupt 6805 6857 */ ··· 6830 6882 * @irq: irq number 6831 6883 * @__hba: pointer to adapter instance 6832 6884 * 6833 - * Returns 6885 + * Return: 6834 6886 * IRQ_HANDLED - If interrupt is valid 6835 6887 * IRQ_NONE - If invalid interrupt 6836 6888 */ ··· 6926 6978 WARN_ONCE(task_tag < 0 || task_tag >= hba->nutmrs, "Invalid tag %d\n", 6927 6979 task_tag); 6928 6980 hba->tmf_rqs[req->tag] = req; 6929 - treq->upiu_req.req_header.dword_0 |= cpu_to_be32(task_tag); 6981 + treq->upiu_req.req_header.task_tag = task_tag; 6930 6982 6931 6983 memcpy(hba->utmrdl_base_addr + task_tag, treq, sizeof(*treq)); 6932 6984 ufshcd_vops_setup_task_mgmt(hba, task_tag, tm_function); ··· 6979 7031 * @tm_function: task management function opcode 6980 7032 * @tm_response: task management service response return value 6981 7033 * 6982 - * Returns non-zero value on error, zero on success. 7034 + * Return: non-zero value on error, zero on success. 6983 7035 */ 6984 7036 static int ufshcd_issue_tm_cmd(struct ufs_hba *hba, int lun_id, int task_id, 6985 7037 u8 tm_function, u8 *tm_response) 6986 7038 { 6987 - struct utp_task_req_desc treq = { { 0 }, }; 7039 + struct utp_task_req_desc treq = { }; 6988 7040 enum utp_ocs ocs_value; 6989 7041 int err; 6990 7042 6991 7043 /* Configure task request descriptor */ 6992 - treq.header.dword_0 = cpu_to_le32(UTP_REQ_DESC_INT_CMD); 6993 - treq.header.dword_2 = cpu_to_le32(OCS_INVALID_COMMAND_STATUS); 7044 + treq.header.interrupt = 1; 7045 + treq.header.ocs = OCS_INVALID_COMMAND_STATUS; 6994 7046 6995 7047 /* Configure task request UPIU */ 6996 - treq.upiu_req.req_header.dword_0 = cpu_to_be32(lun_id << 8) | 6997 - cpu_to_be32(UPIU_TRANSACTION_TASK_REQ << 24); 6998 - treq.upiu_req.req_header.dword_1 = cpu_to_be32(tm_function << 16); 7048 + treq.upiu_req.req_header.transaction_code = UPIU_TRANSACTION_TASK_REQ; 7049 + treq.upiu_req.req_header.lun = lun_id; 7050 + treq.upiu_req.req_header.tm_function = tm_function; 6999 7051 7000 7052 /* 7001 7053 * The host shall provide the same value for LUN field in the basic ··· 7008 7060 if (err == -ETIMEDOUT) 7009 7061 return err; 7010 7062 7011 - ocs_value = le32_to_cpu(treq.header.dword_2) & MASK_OCS; 7063 + ocs_value = treq.header.ocs & MASK_OCS; 7012 7064 if (ocs_value != OCS_SUCCESS) 7013 7065 dev_err(hba->dev, "%s: failed, ocs = 0x%x\n", 7014 7066 __func__, ocs_value); ··· 7034 7086 * 7035 7087 * Since there is only one available tag for device management commands, 7036 7088 * the caller is expected to hold the hba->dev_cmd.lock mutex. 7089 + * 7090 + * Return: 0 upon success; < 0 upon failure. 7037 7091 */ 7038 7092 static int ufshcd_issue_devman_upiu_cmd(struct ufs_hba *hba, 7039 7093 struct utp_upiu_req *req_upiu, ··· 7069 7119 lrbp->command_type = UTP_CMD_TYPE_UFS_STORAGE; 7070 7120 7071 7121 /* update the task tag in the request upiu */ 7072 - req_upiu->header.dword_0 |= cpu_to_be32(tag); 7122 + req_upiu->header.task_tag = tag; 7073 7123 7074 7124 ufshcd_prepare_req_desc_hdr(lrbp, &upiu_flags, DMA_NONE, 0); 7075 7125 ··· 7102 7152 memcpy(rsp_upiu, lrbp->ucd_rsp_ptr, sizeof(*rsp_upiu)); 7103 7153 if (desc_buff && desc_op == UPIU_QUERY_OPCODE_READ_DESC) { 7104 7154 u8 *descp = (u8 *)lrbp->ucd_rsp_ptr + sizeof(*rsp_upiu); 7105 - u16 resp_len = be32_to_cpu(lrbp->ucd_rsp_ptr->header.dword_2) & 7106 - MASK_QUERY_DATA_SEG_LEN; 7155 + u16 resp_len = be16_to_cpu(lrbp->ucd_rsp_ptr->header 7156 + .data_segment_length); 7107 7157 7108 7158 if (*buff_len >= resp_len) { 7109 7159 memcpy(desc_buff, descp, resp_len); ··· 7137 7187 * Management requests. 7138 7188 * It is up to the caller to fill the upiu conent properly, as it will 7139 7189 * be copied without any further input validations. 7190 + * 7191 + * Return: 0 upon success; < 0 upon failure. 7140 7192 */ 7141 7193 int ufshcd_exec_raw_upiu_cmd(struct ufs_hba *hba, 7142 7194 struct utp_upiu_req *req_upiu, 7143 7195 struct utp_upiu_req *rsp_upiu, 7144 - int msgcode, 7196 + enum upiu_request_transaction msgcode, 7145 7197 u8 *desc_buff, int *buff_len, 7146 7198 enum query_opcode desc_op) 7147 7199 { 7148 7200 int err; 7149 7201 enum dev_cmd_type cmd_type = DEV_CMD_TYPE_QUERY; 7150 - struct utp_task_req_desc treq = { { 0 }, }; 7202 + struct utp_task_req_desc treq = { }; 7151 7203 enum utp_ocs ocs_value; 7152 - u8 tm_f = be32_to_cpu(req_upiu->header.dword_1) >> 16 & MASK_TM_FUNC; 7204 + u8 tm_f = req_upiu->header.tm_function; 7153 7205 7154 7206 switch (msgcode) { 7155 7207 case UPIU_TRANSACTION_NOP_OUT: ··· 7168 7216 7169 7217 break; 7170 7218 case UPIU_TRANSACTION_TASK_REQ: 7171 - treq.header.dword_0 = cpu_to_le32(UTP_REQ_DESC_INT_CMD); 7172 - treq.header.dword_2 = cpu_to_le32(OCS_INVALID_COMMAND_STATUS); 7219 + treq.header.interrupt = 1; 7220 + treq.header.ocs = OCS_INVALID_COMMAND_STATUS; 7173 7221 7174 7222 memcpy(&treq.upiu_req, req_upiu, sizeof(*req_upiu)); 7175 7223 ··· 7177 7225 if (err == -ETIMEDOUT) 7178 7226 break; 7179 7227 7180 - ocs_value = le32_to_cpu(treq.header.dword_2) & MASK_OCS; 7228 + ocs_value = treq.header.ocs & MASK_OCS; 7181 7229 if (ocs_value != OCS_SUCCESS) { 7182 7230 dev_err(hba->dev, "%s: failed, ocs = 0x%x\n", __func__, 7183 7231 ocs_value); ··· 7207 7255 * @sg_list: Pointer to SG list when DATA IN/OUT UPIU is required in ARPMB operation 7208 7256 * @dir: DMA direction 7209 7257 * 7210 - * Returns zero on success, non-zero on failure 7258 + * Return: zero on success, non-zero on failure. 7211 7259 */ 7212 7260 int ufshcd_advanced_rpmb_req_handler(struct ufs_hba *hba, struct utp_upiu_req *req_upiu, 7213 7261 struct utp_upiu_req *rsp_upiu, struct ufs_ehs *req_ehs, ··· 7243 7291 ufshcd_prepare_req_desc_hdr(lrbp, &upiu_flags, dir, 2); 7244 7292 7245 7293 /* update the task tag and LUN in the request upiu */ 7246 - req_upiu->header.dword_0 |= cpu_to_be32(upiu_flags << 16 | UFS_UPIU_RPMB_WLUN << 8 | tag); 7294 + req_upiu->header.flags = upiu_flags; 7295 + req_upiu->header.lun = UFS_UPIU_RPMB_WLUN; 7296 + req_upiu->header.task_tag = tag; 7247 7297 7248 7298 /* copy the UPIU(contains CDB) request as it is */ 7249 7299 memcpy(lrbp->ucd_req_ptr, req_upiu, sizeof(*lrbp->ucd_req_ptr)); ··· 7267 7313 /* Just copy the upiu response as it is */ 7268 7314 memcpy(rsp_upiu, lrbp->ucd_rsp_ptr, sizeof(*rsp_upiu)); 7269 7315 /* Get the response UPIU result */ 7270 - result = ufshcd_get_rsp_upiu_result(lrbp->ucd_rsp_ptr); 7316 + result = (lrbp->ucd_rsp_ptr->header.response << 8) | 7317 + lrbp->ucd_rsp_ptr->header.status; 7271 7318 7272 - ehs_len = be32_to_cpu(lrbp->ucd_rsp_ptr->header.dword_2) >> 24; 7319 + ehs_len = lrbp->ucd_rsp_ptr->header.ehs_length; 7273 7320 /* 7274 7321 * Since the bLength in EHS indicates the total size of the EHS Header and EHS Data 7275 7322 * in 32 Byte units, the value of the bLength Request/Response for Advanced RPMB ··· 7296 7341 * ufshcd_eh_device_reset_handler() - Reset a single logical unit. 7297 7342 * @cmd: SCSI command pointer 7298 7343 * 7299 - * Returns SUCCESS/FAILED 7344 + * Return: SUCCESS or FAILED. 7300 7345 */ 7301 7346 static int ufshcd_eh_device_reset_handler(struct scsi_cmnd *cmd) 7302 7347 { ··· 7391 7436 * issued. To avoid that, first issue UFS_QUERY_TASK to check if the command is 7392 7437 * really issued and then try to abort it. 7393 7438 * 7394 - * Returns zero on success, non-zero on failure 7439 + * Return: zero on success, non-zero on failure. 7395 7440 */ 7396 7441 int ufshcd_try_to_abort_task(struct ufs_hba *hba, int tag) 7397 7442 { ··· 7479 7524 * ufshcd_abort - scsi host template eh_abort_handler callback 7480 7525 * @cmd: SCSI command pointer 7481 7526 * 7482 - * Returns SUCCESS/FAILED 7527 + * Return: SUCCESS or FAILED. 7483 7528 */ 7484 7529 static int ufshcd_abort(struct scsi_cmnd *cmd) 7485 7530 { ··· 7604 7649 * local and remote (device) Uni-Pro stack and the attributes 7605 7650 * are reset to default state. 7606 7651 * 7607 - * Returns zero on success, non-zero on failure 7652 + * Return: zero on success, non-zero on failure. 7608 7653 */ 7609 7654 static int ufshcd_host_reset_and_restore(struct ufs_hba *hba) 7610 7655 { ··· 7614 7659 * Stop the host controller and complete the requests 7615 7660 * cleared by h/w 7616 7661 */ 7617 - ufshpb_toggle_state(hba, HPB_PRESENT, HPB_RESET); 7618 7662 ufshcd_hba_stop(hba); 7619 7663 hba->silence_err_logs = true; 7620 7664 ufshcd_complete_requests(hba, true); ··· 7641 7687 * Reset and recover device, host and re-establish link. This 7642 7688 * is helpful to recover the communication in fatal error conditions. 7643 7689 * 7644 - * Returns zero on success, non-zero on failure 7690 + * Return: zero on success, non-zero on failure. 7645 7691 */ 7646 7692 static int ufshcd_reset_and_restore(struct ufs_hba *hba) 7647 7693 { ··· 7699 7745 * ufshcd_eh_host_reset_handler - host reset handler registered to scsi layer 7700 7746 * @cmd: SCSI command pointer 7701 7747 * 7702 - * Returns SUCCESS/FAILED 7748 + * Return: SUCCESS or FAILED. 7703 7749 */ 7704 7750 static int ufshcd_eh_host_reset_handler(struct scsi_cmnd *cmd) 7705 7751 { ··· 7731 7777 * @start_scan: row at the desc table to start scan from 7732 7778 * @buff: power descriptor buffer 7733 7779 * 7734 - * Returns calculated max ICC level for specific regulator 7780 + * Return: calculated max ICC level for specific regulator. 7735 7781 */ 7736 7782 static u32 ufshcd_get_max_icc_level(int sup_curr_uA, u32 start_scan, 7737 7783 const char *buff) ··· 7777 7823 * @hba: per-adapter instance 7778 7824 * @desc_buf: power descriptor buffer to extract ICC levels from. 7779 7825 * 7780 - * Returns calculated ICC level 7826 + * Return: calculated ICC level. 7781 7827 */ 7782 7828 static u32 ufshcd_find_max_sup_active_icc_level(struct ufs_hba *hba, 7783 7829 const u8 *desc_buf) ··· 7886 7932 * This function adds scsi device instances for each of all well known LUs 7887 7933 * (except "REPORT LUNS" LU). 7888 7934 * 7889 - * Returns zero on success (all required W-LUs are added successfully), 7935 + * Return: zero on success (all required W-LUs are added successfully), 7890 7936 * non-zero error value on failure (if failed to add any of the required W-LU). 7891 7937 */ 7892 7938 static int ufshcd_scsi_add_wlus(struct ufs_hba *hba) ··· 8076 8122 { 8077 8123 int err; 8078 8124 u8 model_index; 8079 - u8 b_ufs_feature_sup; 8080 8125 u8 *desc_buf; 8081 8126 struct ufs_dev_info *dev_info = &hba->dev_info; 8082 8127 ··· 8104 8151 dev_info->wspecversion = desc_buf[DEVICE_DESC_PARAM_SPEC_VER] << 8 | 8105 8152 desc_buf[DEVICE_DESC_PARAM_SPEC_VER + 1]; 8106 8153 dev_info->bqueuedepth = desc_buf[DEVICE_DESC_PARAM_Q_DPTH]; 8107 - b_ufs_feature_sup = desc_buf[DEVICE_DESC_PARAM_UFS_FEAT]; 8108 8154 8109 8155 model_index = desc_buf[DEVICE_DESC_PARAM_PRDCT_NAME]; 8110 - 8111 - if (dev_info->wspecversion >= UFS_DEV_HPB_SUPPORT_VERSION && 8112 - (b_ufs_feature_sup & UFS_DEV_HPB_SUPPORT)) { 8113 - bool hpb_en = false; 8114 - 8115 - ufshpb_get_dev_info(hba, desc_buf); 8116 - 8117 - if (!ufshpb_is_legacy(hba)) 8118 - err = ufshcd_query_flag_retry(hba, 8119 - UPIU_QUERY_OPCODE_READ_FLAG, 8120 - QUERY_FLAG_IDN_HPB_EN, 0, 8121 - &hpb_en); 8122 - 8123 - if (ufshpb_is_legacy(hba) || (!err && hpb_en)) 8124 - dev_info->hpb_enabled = true; 8125 - } 8126 8156 8127 8157 err = ufshcd_read_string_desc(hba, model_index, 8128 8158 &dev_info->model, SD_ASCII_STD); ··· 8155 8219 * RX_MIN_ACTIVATETIME_CAPABILITY attribute. This optimal value can help reduce 8156 8220 * the hibern8 exit latency. 8157 8221 * 8158 - * Returns zero on success, non-zero error value on failure. 8222 + * Return: zero on success, non-zero error value on failure. 8159 8223 */ 8160 8224 static int ufshcd_tune_pa_tactivate(struct ufs_hba *hba) 8161 8225 { ··· 8190 8254 * TX_HIBERN8TIME_CAPABILITY & peer M-PHY's RX_HIBERN8TIME_CAPABILITY. 8191 8255 * This optimal value can help reduce the hibern8 exit latency. 8192 8256 * 8193 - * Returns zero on success, non-zero error value on failure. 8257 + * Return: zero on success, non-zero error value on failure. 8194 8258 */ 8195 8259 static int ufshcd_tune_pa_hibern8time(struct ufs_hba *hba) 8196 8260 { ··· 8232 8296 * PA_TACTIVATE, we need to enable UFS_DEVICE_QUIRK_HOST_PA_TACTIVATE quirk 8233 8297 * for such devices. 8234 8298 * 8235 - * Returns zero on success, non-zero error value on failure. 8299 + * Return: zero on success, non-zero error value on failure. 8236 8300 */ 8237 8301 static int ufshcd_quirk_tune_host_pa_tactivate(struct ufs_hba *hba) 8238 8302 { ··· 8340 8404 hba->dev_info.max_lu_supported = 32; 8341 8405 else if (desc_buf[GEOMETRY_DESC_PARAM_MAX_NUM_LUN] == 0) 8342 8406 hba->dev_info.max_lu_supported = 8; 8343 - 8344 - if (desc_buf[QUERY_DESC_LENGTH_OFFSET] >= 8345 - GEOMETRY_DESC_PARAM_HPB_MAX_ACTIVE_REGS) 8346 - ufshpb_get_geo_info(hba, desc_buf); 8347 8407 8348 8408 out: 8349 8409 kfree(desc_buf); ··· 8490 8558 /** 8491 8559 * ufshcd_add_lus - probe and add UFS logical units 8492 8560 * @hba: per-adapter instance 8561 + * 8562 + * Return: 0 upon success; < 0 upon failure. 8493 8563 */ 8494 8564 static int ufshcd_add_lus(struct ufs_hba *hba) 8495 8565 { ··· 8518 8584 } 8519 8585 8520 8586 ufs_bsg_probe(hba); 8521 - ufshpb_init(hba); 8522 8587 scsi_scan_host(hba->host); 8523 8588 pm_runtime_put_sync(hba->dev); 8524 8589 ··· 8703 8770 * @init_dev_params: whether or not to call ufshcd_device_params_init(). 8704 8771 * 8705 8772 * Execute link-startup and verify device initialization 8773 + * 8774 + * Return: 0 upon success; < 0 upon failure. 8706 8775 */ 8707 8776 static int ufshcd_probe_hba(struct ufs_hba *hba, bool init_dev_params) 8708 8777 { ··· 8753 8818 /* Enable Auto-Hibernate if configured */ 8754 8819 ufshcd_auto_hibern8_enable(hba); 8755 8820 8756 - ufshpb_toggle_state(hba, HPB_RESET, HPB_PRESENT); 8757 8821 out: 8758 8822 spin_lock_irqsave(hba->host->host_lock, flags); 8759 8823 if (ret) ··· 8822 8888 static const struct attribute_group *ufshcd_driver_groups[] = { 8823 8889 &ufs_sysfs_unit_descriptor_group, 8824 8890 &ufs_sysfs_lun_attributes_group, 8825 - #ifdef CONFIG_SCSI_UFS_HPB 8826 - &ufs_sysfs_hpb_stat_group, 8827 - &ufs_sysfs_hpb_param_group, 8828 - #endif 8829 8891 NULL, 8830 8892 }; 8831 8893 ··· 9165 9235 9166 9236 err = ufshcd_vops_init(hba); 9167 9237 if (err) 9168 - dev_err(hba->dev, "%s: variant %s init failed err %d\n", 9169 - __func__, ufshcd_get_var_name(hba), err); 9238 + dev_err_probe(hba->dev, err, 9239 + "%s: variant %s init failed with err %d\n", 9240 + __func__, ufshcd_get_var_name(hba), err); 9170 9241 out: 9171 9242 return err; 9172 9243 } ··· 9276 9345 * @hba: per adapter instance 9277 9346 * @pwr_mode: device power mode to set 9278 9347 * 9279 - * Returns 0 if requested power mode is set successfully 9280 - * Returns < 0 if failed to set the requested power mode 9348 + * Return: 0 if requested power mode is set successfully; 9349 + * < 0 if failed to set the requested power mode. 9281 9350 */ 9282 9351 static int ufshcd_set_dev_pwr_mode(struct ufs_hba *hba, 9283 9352 enum ufs_dev_pwr_mode pwr_mode) ··· 9507 9576 req_link_state = UIC_LINK_OFF_STATE; 9508 9577 } 9509 9578 9510 - ufshpb_suspend(hba); 9511 - 9512 9579 /* 9513 9580 * If we can't transition into any of the low power modes 9514 9581 * just gate the clocks. ··· 9660 9731 ufshcd_update_evt_hist(hba, UFS_EVT_WL_SUSP_ERR, (u32)ret); 9661 9732 hba->clk_gating.is_suspended = false; 9662 9733 ufshcd_release(hba); 9663 - ufshpb_resume(hba); 9664 9734 } 9665 9735 hba->pm_op_in_progress = false; 9666 9736 return ret; ··· 9740 9812 /* Enable Auto-Hibernate if configured */ 9741 9813 ufshcd_auto_hibern8_enable(hba); 9742 9814 9743 - ufshpb_resume(hba); 9744 9815 goto out; 9745 9816 9746 9817 set_old_link_state: ··· 9861 9934 * 9862 9935 * This function will put disable irqs, turn off clocks 9863 9936 * and set vreg and hba-vreg in lpm mode. 9937 + * 9938 + * Return: 0 upon success; < 0 upon failure. 9864 9939 */ 9865 9940 static int ufshcd_suspend(struct ufs_hba *hba) 9866 9941 { ··· 9900 9971 * This function basically turns on the regulators, clocks and 9901 9972 * irqs of the hba. 9902 9973 * 9903 - * Returns 0 for success and non-zero for failure 9974 + * Return: 0 for success and non-zero for failure. 9904 9975 */ 9905 9976 static int ufshcd_resume(struct ufs_hba *hba) 9906 9977 { ··· 9941 10012 * Executed before putting the system into a sleep state in which the contents 9942 10013 * of main memory are preserved. 9943 10014 * 9944 - * Returns 0 for success and non-zero for failure 10015 + * Return: 0 for success and non-zero for failure. 9945 10016 */ 9946 10017 int ufshcd_system_suspend(struct device *dev) 9947 10018 { ··· 9968 10039 * Executed after waking the system up from a sleep state in which the contents 9969 10040 * of main memory were preserved. 9970 10041 * 9971 - * Returns 0 for success and non-zero for failure 10042 + * Return: 0 for success and non-zero for failure. 9972 10043 */ 9973 10044 int ufshcd_system_resume(struct device *dev) 9974 10045 { ··· 9998 10069 * 9999 10070 * Check the description of ufshcd_suspend() function for more details. 10000 10071 * 10001 - * Returns 0 for success and non-zero for failure 10072 + * Return: 0 for success and non-zero for failure. 10002 10073 */ 10003 10074 int ufshcd_runtime_suspend(struct device *dev) 10004 10075 { ··· 10024 10095 * 10025 10096 * 1. Turn on all the controller related clocks 10026 10097 * 2. Turn ON VCC rail 10098 + * 10099 + * Return: 0 upon success; < 0 upon failure. 10027 10100 */ 10028 10101 int ufshcd_runtime_resume(struct device *dev) 10029 10102 { ··· 10083 10152 ufshcd_rpm_get_sync(hba); 10084 10153 ufs_hwmon_remove(hba); 10085 10154 ufs_bsg_remove(hba); 10086 - ufshpb_remove(hba); 10087 10155 ufs_sysfs_remove_nodes(hba->dev); 10088 10156 blk_mq_destroy_queue(hba->tmf_queue); 10089 10157 blk_put_queue(hba->tmf_queue); ··· 10160 10230 * addressing capability 10161 10231 * @hba: per adapter instance 10162 10232 * 10163 - * Returns 0 for success, non-zero for failure 10233 + * Return: 0 for success, non-zero for failure. 10164 10234 */ 10165 10235 static int ufshcd_set_dma_mask(struct ufs_hba *hba) 10166 10236 { ··· 10175 10245 * ufshcd_alloc_host - allocate Host Bus Adapter (HBA) 10176 10246 * @dev: pointer to device handle 10177 10247 * @hba_handle: driver private handle 10178 - * Returns 0 on success, non-zero value on failure 10248 + * 10249 + * Return: 0 on success, non-zero value on failure. 10179 10250 */ 10180 10251 int ufshcd_alloc_host(struct device *dev, struct ufs_hba **hba_handle) 10181 10252 { ··· 10232 10301 * @hba: per-adapter instance 10233 10302 * @mmio_base: base register address 10234 10303 * @irq: Interrupt line of device 10235 - * Returns 0 on success, non-zero value on failure 10304 + * 10305 + * Return: 0 on success, non-zero value on failure. 10236 10306 */ 10237 10307 int ufshcd_init(struct ufs_hba *hba, void __iomem *mmio_base, unsigned int irq) 10238 10308 { ··· 10564 10632 SET_RUNTIME_PM_OPS(ufshcd_wl_runtime_suspend, ufshcd_wl_runtime_resume, NULL) 10565 10633 }; 10566 10634 10635 + static void ufshcd_check_header_layout(void) 10636 + { 10637 + /* 10638 + * gcc compilers before version 10 cannot do constant-folding for 10639 + * sub-byte bitfields. Hence skip the layout checks for gcc 9 and 10640 + * before. 10641 + */ 10642 + if (IS_ENABLED(CONFIG_CC_IS_GCC) && CONFIG_GCC_VERSION < 100000) 10643 + return; 10644 + 10645 + BUILD_BUG_ON(((u8 *)&(struct request_desc_header){ 10646 + .cci = 3})[0] != 3); 10647 + 10648 + BUILD_BUG_ON(((u8 *)&(struct request_desc_header){ 10649 + .ehs_length = 2})[1] != 2); 10650 + 10651 + BUILD_BUG_ON(((u8 *)&(struct request_desc_header){ 10652 + .enable_crypto = 1})[2] 10653 + != 0x80); 10654 + 10655 + BUILD_BUG_ON((((u8 *)&(struct request_desc_header){ 10656 + .command_type = 5, 10657 + .data_direction = 3, 10658 + .interrupt = 1, 10659 + })[3]) != ((5 << 4) | (3 << 1) | 1)); 10660 + 10661 + BUILD_BUG_ON(((__le32 *)&(struct request_desc_header){ 10662 + .dunl = cpu_to_le32(0xdeadbeef)})[1] != 10663 + cpu_to_le32(0xdeadbeef)); 10664 + 10665 + BUILD_BUG_ON(((u8 *)&(struct request_desc_header){ 10666 + .ocs = 4})[8] != 4); 10667 + 10668 + BUILD_BUG_ON(((u8 *)&(struct request_desc_header){ 10669 + .cds = 5})[9] != 5); 10670 + 10671 + BUILD_BUG_ON(((__le32 *)&(struct request_desc_header){ 10672 + .dunu = cpu_to_le32(0xbadcafe)})[3] != 10673 + cpu_to_le32(0xbadcafe)); 10674 + 10675 + BUILD_BUG_ON(((u8 *)&(struct utp_upiu_header){ 10676 + .iid = 0xf })[4] != 0xf0); 10677 + 10678 + BUILD_BUG_ON(((u8 *)&(struct utp_upiu_header){ 10679 + .command_set_type = 0xf })[4] != 0xf); 10680 + } 10681 + 10567 10682 /* 10568 10683 * ufs_dev_wlun_template - describes ufs device wlun 10569 10684 * ufs-device wlun - used to send pm commands ··· 10635 10656 static int __init ufshcd_core_init(void) 10636 10657 { 10637 10658 int ret; 10659 + 10660 + ufshcd_check_header_layout(); 10638 10661 10639 10662 ufs_debugfs_init(); 10640 10663
-2668
drivers/ufs/core/ufshpb.c
··· 1 - // SPDX-License-Identifier: GPL-2.0 2 - /* 3 - * Universal Flash Storage Host Performance Booster 4 - * 5 - * Copyright (C) 2017-2021 Samsung Electronics Co., Ltd. 6 - * 7 - * Authors: 8 - * Yongmyung Lee <ymhungry.lee@samsung.com> 9 - * Jinyoung Choi <j-young.choi@samsung.com> 10 - */ 11 - 12 - #include <asm/unaligned.h> 13 - #include <linux/delay.h> 14 - #include <linux/device.h> 15 - #include <linux/module.h> 16 - #include <scsi/scsi_cmnd.h> 17 - 18 - #include "ufshcd-priv.h" 19 - #include "ufshpb.h" 20 - #include "../../scsi/sd.h" 21 - 22 - #define ACTIVATION_THRESHOLD 8 /* 8 IOs */ 23 - #define READ_TO_MS 1000 24 - #define READ_TO_EXPIRIES 100 25 - #define POLLING_INTERVAL_MS 200 26 - #define THROTTLE_MAP_REQ_DEFAULT 1 27 - 28 - /* memory management */ 29 - static struct kmem_cache *ufshpb_mctx_cache; 30 - static mempool_t *ufshpb_mctx_pool; 31 - static mempool_t *ufshpb_page_pool; 32 - /* A cache size of 2MB can cache ppn in the 1GB range. */ 33 - static unsigned int ufshpb_host_map_kbytes = SZ_2K; 34 - static int tot_active_srgn_pages; 35 - 36 - static struct workqueue_struct *ufshpb_wq; 37 - 38 - static void ufshpb_update_active_info(struct ufshpb_lu *hpb, int rgn_idx, 39 - int srgn_idx); 40 - 41 - bool ufshpb_is_allowed(struct ufs_hba *hba) 42 - { 43 - return !(hba->ufshpb_dev.hpb_disabled); 44 - } 45 - 46 - /* HPB version 1.0 is called as legacy version. */ 47 - bool ufshpb_is_legacy(struct ufs_hba *hba) 48 - { 49 - return hba->ufshpb_dev.is_legacy; 50 - } 51 - 52 - static struct ufshpb_lu *ufshpb_get_hpb_data(struct scsi_device *sdev) 53 - { 54 - return sdev->hostdata; 55 - } 56 - 57 - static int ufshpb_get_state(struct ufshpb_lu *hpb) 58 - { 59 - return atomic_read(&hpb->hpb_state); 60 - } 61 - 62 - static void ufshpb_set_state(struct ufshpb_lu *hpb, int state) 63 - { 64 - atomic_set(&hpb->hpb_state, state); 65 - } 66 - 67 - static int ufshpb_is_valid_srgn(struct ufshpb_region *rgn, 68 - struct ufshpb_subregion *srgn) 69 - { 70 - return rgn->rgn_state != HPB_RGN_INACTIVE && 71 - srgn->srgn_state == HPB_SRGN_VALID; 72 - } 73 - 74 - static bool ufshpb_is_read_cmd(struct scsi_cmnd *cmd) 75 - { 76 - return req_op(scsi_cmd_to_rq(cmd)) == REQ_OP_READ; 77 - } 78 - 79 - static bool ufshpb_is_write_or_discard(struct scsi_cmnd *cmd) 80 - { 81 - return op_is_write(req_op(scsi_cmd_to_rq(cmd))) || 82 - op_is_discard(req_op(scsi_cmd_to_rq(cmd))); 83 - } 84 - 85 - static bool ufshpb_is_supported_chunk(struct ufshpb_lu *hpb, int transfer_len) 86 - { 87 - return transfer_len <= hpb->pre_req_max_tr_len; 88 - } 89 - 90 - static bool ufshpb_is_general_lun(int lun) 91 - { 92 - return lun < UFS_UPIU_MAX_UNIT_NUM_ID; 93 - } 94 - 95 - static bool ufshpb_is_pinned_region(struct ufshpb_lu *hpb, int rgn_idx) 96 - { 97 - return hpb->lu_pinned_end != PINNED_NOT_SET && 98 - rgn_idx >= hpb->lu_pinned_start && rgn_idx <= hpb->lu_pinned_end; 99 - } 100 - 101 - static void ufshpb_kick_map_work(struct ufshpb_lu *hpb) 102 - { 103 - bool ret = false; 104 - unsigned long flags; 105 - 106 - if (ufshpb_get_state(hpb) != HPB_PRESENT) 107 - return; 108 - 109 - spin_lock_irqsave(&hpb->rsp_list_lock, flags); 110 - if (!list_empty(&hpb->lh_inact_rgn) || !list_empty(&hpb->lh_act_srgn)) 111 - ret = true; 112 - spin_unlock_irqrestore(&hpb->rsp_list_lock, flags); 113 - 114 - if (ret) 115 - queue_work(ufshpb_wq, &hpb->map_work); 116 - } 117 - 118 - static bool ufshpb_is_hpb_rsp_valid(struct ufs_hba *hba, 119 - struct ufshcd_lrb *lrbp, 120 - struct utp_hpb_rsp *rsp_field) 121 - { 122 - /* Check HPB_UPDATE_ALERT */ 123 - if (!(lrbp->ucd_rsp_ptr->header.dword_2 & 124 - UPIU_HEADER_DWORD(0, 2, 0, 0))) 125 - return false; 126 - 127 - if (be16_to_cpu(rsp_field->sense_data_len) != DEV_SENSE_SEG_LEN || 128 - rsp_field->desc_type != DEV_DES_TYPE || 129 - rsp_field->additional_len != DEV_ADDITIONAL_LEN || 130 - rsp_field->active_rgn_cnt > MAX_ACTIVE_NUM || 131 - rsp_field->inactive_rgn_cnt > MAX_INACTIVE_NUM || 132 - rsp_field->hpb_op == HPB_RSP_NONE || 133 - (rsp_field->hpb_op == HPB_RSP_REQ_REGION_UPDATE && 134 - !rsp_field->active_rgn_cnt && !rsp_field->inactive_rgn_cnt)) 135 - return false; 136 - 137 - if (!ufshpb_is_general_lun(rsp_field->lun)) { 138 - dev_warn(hba->dev, "ufshpb: lun(%d) not supported\n", 139 - lrbp->lun); 140 - return false; 141 - } 142 - 143 - return true; 144 - } 145 - 146 - static void ufshpb_iterate_rgn(struct ufshpb_lu *hpb, int rgn_idx, int srgn_idx, 147 - int srgn_offset, int cnt, bool set_dirty) 148 - { 149 - struct ufshpb_region *rgn; 150 - struct ufshpb_subregion *srgn, *prev_srgn = NULL; 151 - int set_bit_len; 152 - int bitmap_len; 153 - unsigned long flags; 154 - 155 - next_srgn: 156 - rgn = hpb->rgn_tbl + rgn_idx; 157 - srgn = rgn->srgn_tbl + srgn_idx; 158 - 159 - if (likely(!srgn->is_last)) 160 - bitmap_len = hpb->entries_per_srgn; 161 - else 162 - bitmap_len = hpb->last_srgn_entries; 163 - 164 - if ((srgn_offset + cnt) > bitmap_len) 165 - set_bit_len = bitmap_len - srgn_offset; 166 - else 167 - set_bit_len = cnt; 168 - 169 - spin_lock_irqsave(&hpb->rgn_state_lock, flags); 170 - if (rgn->rgn_state != HPB_RGN_INACTIVE) { 171 - if (set_dirty) { 172 - if (srgn->srgn_state == HPB_SRGN_VALID) 173 - bitmap_set(srgn->mctx->ppn_dirty, srgn_offset, 174 - set_bit_len); 175 - } else if (hpb->is_hcm) { 176 - /* rewind the read timer for lru regions */ 177 - rgn->read_timeout = ktime_add_ms(ktime_get(), 178 - rgn->hpb->params.read_timeout_ms); 179 - rgn->read_timeout_expiries = 180 - rgn->hpb->params.read_timeout_expiries; 181 - } 182 - } 183 - spin_unlock_irqrestore(&hpb->rgn_state_lock, flags); 184 - 185 - if (hpb->is_hcm && prev_srgn != srgn) { 186 - bool activate = false; 187 - 188 - spin_lock(&rgn->rgn_lock); 189 - if (set_dirty) { 190 - rgn->reads -= srgn->reads; 191 - srgn->reads = 0; 192 - set_bit(RGN_FLAG_DIRTY, &rgn->rgn_flags); 193 - } else { 194 - srgn->reads++; 195 - rgn->reads++; 196 - if (srgn->reads == hpb->params.activation_thld) 197 - activate = true; 198 - } 199 - spin_unlock(&rgn->rgn_lock); 200 - 201 - if (activate || 202 - test_and_clear_bit(RGN_FLAG_UPDATE, &rgn->rgn_flags)) { 203 - spin_lock_irqsave(&hpb->rsp_list_lock, flags); 204 - ufshpb_update_active_info(hpb, rgn_idx, srgn_idx); 205 - spin_unlock_irqrestore(&hpb->rsp_list_lock, flags); 206 - dev_dbg(&hpb->sdev_ufs_lu->sdev_dev, 207 - "activate region %d-%d\n", rgn_idx, srgn_idx); 208 - } 209 - 210 - prev_srgn = srgn; 211 - } 212 - 213 - srgn_offset = 0; 214 - if (++srgn_idx == hpb->srgns_per_rgn) { 215 - srgn_idx = 0; 216 - rgn_idx++; 217 - } 218 - 219 - cnt -= set_bit_len; 220 - if (cnt > 0) 221 - goto next_srgn; 222 - } 223 - 224 - static bool ufshpb_test_ppn_dirty(struct ufshpb_lu *hpb, int rgn_idx, 225 - int srgn_idx, int srgn_offset, int cnt) 226 - { 227 - struct ufshpb_region *rgn; 228 - struct ufshpb_subregion *srgn; 229 - int bitmap_len; 230 - int bit_len; 231 - 232 - next_srgn: 233 - rgn = hpb->rgn_tbl + rgn_idx; 234 - srgn = rgn->srgn_tbl + srgn_idx; 235 - 236 - if (!ufshpb_is_valid_srgn(rgn, srgn)) 237 - return true; 238 - 239 - /* 240 - * If the region state is active, mctx must be allocated. 241 - * In this case, check whether the region is evicted or 242 - * mctx allocation fail. 243 - */ 244 - if (unlikely(!srgn->mctx)) { 245 - dev_err(&hpb->sdev_ufs_lu->sdev_dev, 246 - "no mctx in region %d subregion %d.\n", 247 - srgn->rgn_idx, srgn->srgn_idx); 248 - return true; 249 - } 250 - 251 - if (likely(!srgn->is_last)) 252 - bitmap_len = hpb->entries_per_srgn; 253 - else 254 - bitmap_len = hpb->last_srgn_entries; 255 - 256 - if ((srgn_offset + cnt) > bitmap_len) 257 - bit_len = bitmap_len - srgn_offset; 258 - else 259 - bit_len = cnt; 260 - 261 - if (find_next_bit(srgn->mctx->ppn_dirty, bit_len + srgn_offset, 262 - srgn_offset) < bit_len + srgn_offset) 263 - return true; 264 - 265 - srgn_offset = 0; 266 - if (++srgn_idx == hpb->srgns_per_rgn) { 267 - srgn_idx = 0; 268 - rgn_idx++; 269 - } 270 - 271 - cnt -= bit_len; 272 - if (cnt > 0) 273 - goto next_srgn; 274 - 275 - return false; 276 - } 277 - 278 - static inline bool is_rgn_dirty(struct ufshpb_region *rgn) 279 - { 280 - return test_bit(RGN_FLAG_DIRTY, &rgn->rgn_flags); 281 - } 282 - 283 - static int ufshpb_fill_ppn_from_page(struct ufshpb_lu *hpb, 284 - struct ufshpb_map_ctx *mctx, int pos, 285 - int len, __be64 *ppn_buf) 286 - { 287 - struct page *page; 288 - int index, offset; 289 - int copied; 290 - 291 - index = pos / (PAGE_SIZE / HPB_ENTRY_SIZE); 292 - offset = pos % (PAGE_SIZE / HPB_ENTRY_SIZE); 293 - 294 - if ((offset + len) <= (PAGE_SIZE / HPB_ENTRY_SIZE)) 295 - copied = len; 296 - else 297 - copied = (PAGE_SIZE / HPB_ENTRY_SIZE) - offset; 298 - 299 - page = mctx->m_page[index]; 300 - if (unlikely(!page)) { 301 - dev_err(&hpb->sdev_ufs_lu->sdev_dev, 302 - "error. cannot find page in mctx\n"); 303 - return -ENOMEM; 304 - } 305 - 306 - memcpy(ppn_buf, page_address(page) + (offset * HPB_ENTRY_SIZE), 307 - copied * HPB_ENTRY_SIZE); 308 - 309 - return copied; 310 - } 311 - 312 - static void 313 - ufshpb_get_pos_from_lpn(struct ufshpb_lu *hpb, unsigned long lpn, int *rgn_idx, 314 - int *srgn_idx, int *offset) 315 - { 316 - int rgn_offset; 317 - 318 - *rgn_idx = lpn >> hpb->entries_per_rgn_shift; 319 - rgn_offset = lpn & hpb->entries_per_rgn_mask; 320 - *srgn_idx = rgn_offset >> hpb->entries_per_srgn_shift; 321 - *offset = rgn_offset & hpb->entries_per_srgn_mask; 322 - } 323 - 324 - static void 325 - ufshpb_set_hpb_read_to_upiu(struct ufs_hba *hba, struct ufshcd_lrb *lrbp, 326 - __be64 ppn, u8 transfer_len) 327 - { 328 - unsigned char *cdb = lrbp->cmd->cmnd; 329 - __be64 ppn_tmp = ppn; 330 - cdb[0] = UFSHPB_READ; 331 - 332 - if (hba->dev_quirks & UFS_DEVICE_QUIRK_SWAP_L2P_ENTRY_FOR_HPB_READ) 333 - ppn_tmp = (__force __be64)swab64((__force u64)ppn); 334 - 335 - /* ppn value is stored as big-endian in the host memory */ 336 - memcpy(&cdb[6], &ppn_tmp, sizeof(__be64)); 337 - cdb[14] = transfer_len; 338 - cdb[15] = 0; 339 - 340 - lrbp->cmd->cmd_len = UFS_CDB_SIZE; 341 - } 342 - 343 - /* 344 - * This function will set up HPB read command using host-side L2P map data. 345 - */ 346 - int ufshpb_prep(struct ufs_hba *hba, struct ufshcd_lrb *lrbp) 347 - { 348 - struct ufshpb_lu *hpb; 349 - struct ufshpb_region *rgn; 350 - struct ufshpb_subregion *srgn; 351 - struct scsi_cmnd *cmd = lrbp->cmd; 352 - u32 lpn; 353 - __be64 ppn; 354 - unsigned long flags; 355 - int transfer_len, rgn_idx, srgn_idx, srgn_offset; 356 - int err = 0; 357 - 358 - hpb = ufshpb_get_hpb_data(cmd->device); 359 - if (!hpb) 360 - return -ENODEV; 361 - 362 - if (ufshpb_get_state(hpb) == HPB_INIT) 363 - return -ENODEV; 364 - 365 - if (ufshpb_get_state(hpb) != HPB_PRESENT) { 366 - dev_notice(&hpb->sdev_ufs_lu->sdev_dev, 367 - "%s: ufshpb state is not PRESENT", __func__); 368 - return -ENODEV; 369 - } 370 - 371 - if (blk_rq_is_passthrough(scsi_cmd_to_rq(cmd)) || 372 - (!ufshpb_is_write_or_discard(cmd) && 373 - !ufshpb_is_read_cmd(cmd))) 374 - return 0; 375 - 376 - transfer_len = sectors_to_logical(cmd->device, 377 - blk_rq_sectors(scsi_cmd_to_rq(cmd))); 378 - if (unlikely(!transfer_len)) 379 - return 0; 380 - 381 - lpn = sectors_to_logical(cmd->device, blk_rq_pos(scsi_cmd_to_rq(cmd))); 382 - ufshpb_get_pos_from_lpn(hpb, lpn, &rgn_idx, &srgn_idx, &srgn_offset); 383 - rgn = hpb->rgn_tbl + rgn_idx; 384 - srgn = rgn->srgn_tbl + srgn_idx; 385 - 386 - /* If command type is WRITE or DISCARD, set bitmap as dirty */ 387 - if (ufshpb_is_write_or_discard(cmd)) { 388 - ufshpb_iterate_rgn(hpb, rgn_idx, srgn_idx, srgn_offset, 389 - transfer_len, true); 390 - return 0; 391 - } 392 - 393 - if (!ufshpb_is_supported_chunk(hpb, transfer_len)) 394 - return 0; 395 - 396 - if (hpb->is_hcm) { 397 - /* 398 - * in host control mode, reads are the main source for 399 - * activation trials. 400 - */ 401 - ufshpb_iterate_rgn(hpb, rgn_idx, srgn_idx, srgn_offset, 402 - transfer_len, false); 403 - 404 - /* keep those counters normalized */ 405 - if (rgn->reads > hpb->entries_per_srgn) 406 - schedule_work(&hpb->ufshpb_normalization_work); 407 - } 408 - 409 - spin_lock_irqsave(&hpb->rgn_state_lock, flags); 410 - if (ufshpb_test_ppn_dirty(hpb, rgn_idx, srgn_idx, srgn_offset, 411 - transfer_len)) { 412 - hpb->stats.miss_cnt++; 413 - spin_unlock_irqrestore(&hpb->rgn_state_lock, flags); 414 - return 0; 415 - } 416 - 417 - err = ufshpb_fill_ppn_from_page(hpb, srgn->mctx, srgn_offset, 1, &ppn); 418 - spin_unlock_irqrestore(&hpb->rgn_state_lock, flags); 419 - if (unlikely(err < 0)) { 420 - /* 421 - * In this case, the region state is active, 422 - * but the ppn table is not allocated. 423 - * Make sure that ppn table must be allocated on 424 - * active state. 425 - */ 426 - dev_err(hba->dev, "get ppn failed. err %d\n", err); 427 - return err; 428 - } 429 - 430 - ufshpb_set_hpb_read_to_upiu(hba, lrbp, ppn, transfer_len); 431 - 432 - hpb->stats.hit_cnt++; 433 - return 0; 434 - } 435 - 436 - static struct ufshpb_req *ufshpb_get_req(struct ufshpb_lu *hpb, int rgn_idx, 437 - enum req_op op, bool atomic) 438 - { 439 - struct ufshpb_req *rq; 440 - struct request *req; 441 - int retries = HPB_MAP_REQ_RETRIES; 442 - 443 - rq = kmem_cache_alloc(hpb->map_req_cache, GFP_KERNEL); 444 - if (!rq) 445 - return NULL; 446 - 447 - retry: 448 - req = blk_mq_alloc_request(hpb->sdev_ufs_lu->request_queue, op, 449 - BLK_MQ_REQ_NOWAIT); 450 - 451 - if (!atomic && (PTR_ERR(req) == -EWOULDBLOCK) && (--retries > 0)) { 452 - usleep_range(3000, 3100); 453 - goto retry; 454 - } 455 - 456 - if (IS_ERR(req)) 457 - goto free_rq; 458 - 459 - rq->hpb = hpb; 460 - rq->req = req; 461 - rq->rb.rgn_idx = rgn_idx; 462 - 463 - return rq; 464 - 465 - free_rq: 466 - kmem_cache_free(hpb->map_req_cache, rq); 467 - return NULL; 468 - } 469 - 470 - static void ufshpb_put_req(struct ufshpb_lu *hpb, struct ufshpb_req *rq) 471 - { 472 - blk_mq_free_request(rq->req); 473 - kmem_cache_free(hpb->map_req_cache, rq); 474 - } 475 - 476 - static struct ufshpb_req *ufshpb_get_map_req(struct ufshpb_lu *hpb, 477 - struct ufshpb_subregion *srgn) 478 - { 479 - struct ufshpb_req *map_req; 480 - struct bio *bio; 481 - unsigned long flags; 482 - 483 - if (hpb->is_hcm && 484 - hpb->num_inflight_map_req >= hpb->params.inflight_map_req) { 485 - dev_info(&hpb->sdev_ufs_lu->sdev_dev, 486 - "map_req throttle. inflight %d throttle %d", 487 - hpb->num_inflight_map_req, 488 - hpb->params.inflight_map_req); 489 - return NULL; 490 - } 491 - 492 - map_req = ufshpb_get_req(hpb, srgn->rgn_idx, REQ_OP_DRV_IN, false); 493 - if (!map_req) 494 - return NULL; 495 - 496 - bio = bio_alloc(NULL, hpb->pages_per_srgn, 0, GFP_KERNEL); 497 - if (!bio) { 498 - ufshpb_put_req(hpb, map_req); 499 - return NULL; 500 - } 501 - 502 - map_req->bio = bio; 503 - 504 - map_req->rb.srgn_idx = srgn->srgn_idx; 505 - map_req->rb.mctx = srgn->mctx; 506 - 507 - spin_lock_irqsave(&hpb->param_lock, flags); 508 - hpb->num_inflight_map_req++; 509 - spin_unlock_irqrestore(&hpb->param_lock, flags); 510 - 511 - return map_req; 512 - } 513 - 514 - static void ufshpb_put_map_req(struct ufshpb_lu *hpb, 515 - struct ufshpb_req *map_req) 516 - { 517 - unsigned long flags; 518 - 519 - bio_put(map_req->bio); 520 - ufshpb_put_req(hpb, map_req); 521 - 522 - spin_lock_irqsave(&hpb->param_lock, flags); 523 - hpb->num_inflight_map_req--; 524 - spin_unlock_irqrestore(&hpb->param_lock, flags); 525 - } 526 - 527 - static int ufshpb_clear_dirty_bitmap(struct ufshpb_lu *hpb, 528 - struct ufshpb_subregion *srgn) 529 - { 530 - struct ufshpb_region *rgn; 531 - u32 num_entries = hpb->entries_per_srgn; 532 - 533 - if (!srgn->mctx) { 534 - dev_err(&hpb->sdev_ufs_lu->sdev_dev, 535 - "no mctx in region %d subregion %d.\n", 536 - srgn->rgn_idx, srgn->srgn_idx); 537 - return -1; 538 - } 539 - 540 - if (unlikely(srgn->is_last)) 541 - num_entries = hpb->last_srgn_entries; 542 - 543 - bitmap_zero(srgn->mctx->ppn_dirty, num_entries); 544 - 545 - rgn = hpb->rgn_tbl + srgn->rgn_idx; 546 - clear_bit(RGN_FLAG_DIRTY, &rgn->rgn_flags); 547 - 548 - return 0; 549 - } 550 - 551 - static void ufshpb_update_active_info(struct ufshpb_lu *hpb, int rgn_idx, 552 - int srgn_idx) 553 - { 554 - struct ufshpb_region *rgn; 555 - struct ufshpb_subregion *srgn; 556 - 557 - rgn = hpb->rgn_tbl + rgn_idx; 558 - srgn = rgn->srgn_tbl + srgn_idx; 559 - 560 - list_del_init(&rgn->list_inact_rgn); 561 - 562 - if (list_empty(&srgn->list_act_srgn)) 563 - list_add_tail(&srgn->list_act_srgn, &hpb->lh_act_srgn); 564 - 565 - hpb->stats.rcmd_active_cnt++; 566 - } 567 - 568 - static void ufshpb_update_inactive_info(struct ufshpb_lu *hpb, int rgn_idx) 569 - { 570 - struct ufshpb_region *rgn; 571 - struct ufshpb_subregion *srgn; 572 - int srgn_idx; 573 - 574 - rgn = hpb->rgn_tbl + rgn_idx; 575 - 576 - for_each_sub_region(rgn, srgn_idx, srgn) 577 - list_del_init(&srgn->list_act_srgn); 578 - 579 - if (list_empty(&rgn->list_inact_rgn)) 580 - list_add_tail(&rgn->list_inact_rgn, &hpb->lh_inact_rgn); 581 - 582 - hpb->stats.rcmd_inactive_cnt++; 583 - } 584 - 585 - static void ufshpb_activate_subregion(struct ufshpb_lu *hpb, 586 - struct ufshpb_subregion *srgn) 587 - { 588 - struct ufshpb_region *rgn; 589 - 590 - /* 591 - * If there is no mctx in subregion 592 - * after I/O progress for HPB_READ_BUFFER, the region to which the 593 - * subregion belongs was evicted. 594 - * Make sure the region must not evict in I/O progress 595 - */ 596 - if (!srgn->mctx) { 597 - dev_err(&hpb->sdev_ufs_lu->sdev_dev, 598 - "no mctx in region %d subregion %d.\n", 599 - srgn->rgn_idx, srgn->srgn_idx); 600 - srgn->srgn_state = HPB_SRGN_INVALID; 601 - return; 602 - } 603 - 604 - rgn = hpb->rgn_tbl + srgn->rgn_idx; 605 - 606 - if (unlikely(rgn->rgn_state == HPB_RGN_INACTIVE)) { 607 - dev_err(&hpb->sdev_ufs_lu->sdev_dev, 608 - "region %d subregion %d evicted\n", 609 - srgn->rgn_idx, srgn->srgn_idx); 610 - srgn->srgn_state = HPB_SRGN_INVALID; 611 - return; 612 - } 613 - srgn->srgn_state = HPB_SRGN_VALID; 614 - } 615 - 616 - static enum rq_end_io_ret ufshpb_umap_req_compl_fn(struct request *req, 617 - blk_status_t error) 618 - { 619 - struct ufshpb_req *umap_req = req->end_io_data; 620 - 621 - ufshpb_put_req(umap_req->hpb, umap_req); 622 - return RQ_END_IO_NONE; 623 - } 624 - 625 - static enum rq_end_io_ret ufshpb_map_req_compl_fn(struct request *req, 626 - blk_status_t error) 627 - { 628 - struct ufshpb_req *map_req = req->end_io_data; 629 - struct ufshpb_lu *hpb = map_req->hpb; 630 - struct ufshpb_subregion *srgn; 631 - unsigned long flags; 632 - 633 - srgn = hpb->rgn_tbl[map_req->rb.rgn_idx].srgn_tbl + 634 - map_req->rb.srgn_idx; 635 - 636 - ufshpb_clear_dirty_bitmap(hpb, srgn); 637 - spin_lock_irqsave(&hpb->rgn_state_lock, flags); 638 - ufshpb_activate_subregion(hpb, srgn); 639 - spin_unlock_irqrestore(&hpb->rgn_state_lock, flags); 640 - 641 - ufshpb_put_map_req(map_req->hpb, map_req); 642 - return RQ_END_IO_NONE; 643 - } 644 - 645 - static void ufshpb_set_unmap_cmd(unsigned char *cdb, struct ufshpb_region *rgn) 646 - { 647 - cdb[0] = UFSHPB_WRITE_BUFFER; 648 - cdb[1] = rgn ? UFSHPB_WRITE_BUFFER_INACT_SINGLE_ID : 649 - UFSHPB_WRITE_BUFFER_INACT_ALL_ID; 650 - if (rgn) 651 - put_unaligned_be16(rgn->rgn_idx, &cdb[2]); 652 - cdb[9] = 0x00; 653 - } 654 - 655 - static void ufshpb_set_read_buf_cmd(unsigned char *cdb, int rgn_idx, 656 - int srgn_idx, int srgn_mem_size) 657 - { 658 - cdb[0] = UFSHPB_READ_BUFFER; 659 - cdb[1] = UFSHPB_READ_BUFFER_ID; 660 - 661 - put_unaligned_be16(rgn_idx, &cdb[2]); 662 - put_unaligned_be16(srgn_idx, &cdb[4]); 663 - put_unaligned_be24(srgn_mem_size, &cdb[6]); 664 - 665 - cdb[9] = 0x00; 666 - } 667 - 668 - static void ufshpb_execute_umap_req(struct ufshpb_lu *hpb, 669 - struct ufshpb_req *umap_req, 670 - struct ufshpb_region *rgn) 671 - { 672 - struct request *req = umap_req->req; 673 - struct scsi_cmnd *scmd = blk_mq_rq_to_pdu(req); 674 - 675 - req->timeout = 0; 676 - req->end_io_data = umap_req; 677 - req->end_io = ufshpb_umap_req_compl_fn; 678 - 679 - ufshpb_set_unmap_cmd(scmd->cmnd, rgn); 680 - scmd->cmd_len = HPB_WRITE_BUFFER_CMD_LENGTH; 681 - 682 - blk_execute_rq_nowait(req, true); 683 - 684 - hpb->stats.umap_req_cnt++; 685 - } 686 - 687 - static int ufshpb_execute_map_req(struct ufshpb_lu *hpb, 688 - struct ufshpb_req *map_req, bool last) 689 - { 690 - struct request_queue *q; 691 - struct request *req; 692 - struct scsi_cmnd *scmd; 693 - int mem_size = hpb->srgn_mem_size; 694 - int ret = 0; 695 - int i; 696 - 697 - q = hpb->sdev_ufs_lu->request_queue; 698 - for (i = 0; i < hpb->pages_per_srgn; i++) { 699 - ret = bio_add_pc_page(q, map_req->bio, map_req->rb.mctx->m_page[i], 700 - PAGE_SIZE, 0); 701 - if (ret != PAGE_SIZE) { 702 - dev_err(&hpb->sdev_ufs_lu->sdev_dev, 703 - "bio_add_pc_page fail %d - %d\n", 704 - map_req->rb.rgn_idx, map_req->rb.srgn_idx); 705 - return ret; 706 - } 707 - } 708 - 709 - req = map_req->req; 710 - 711 - blk_rq_append_bio(req, map_req->bio); 712 - 713 - req->end_io_data = map_req; 714 - req->end_io = ufshpb_map_req_compl_fn; 715 - 716 - if (unlikely(last)) 717 - mem_size = hpb->last_srgn_entries * HPB_ENTRY_SIZE; 718 - 719 - scmd = blk_mq_rq_to_pdu(req); 720 - ufshpb_set_read_buf_cmd(scmd->cmnd, map_req->rb.rgn_idx, 721 - map_req->rb.srgn_idx, mem_size); 722 - scmd->cmd_len = HPB_READ_BUFFER_CMD_LENGTH; 723 - 724 - blk_execute_rq_nowait(req, true); 725 - 726 - hpb->stats.map_req_cnt++; 727 - return 0; 728 - } 729 - 730 - static struct ufshpb_map_ctx *ufshpb_get_map_ctx(struct ufshpb_lu *hpb, 731 - bool last) 732 - { 733 - struct ufshpb_map_ctx *mctx; 734 - u32 num_entries = hpb->entries_per_srgn; 735 - int i, j; 736 - 737 - mctx = mempool_alloc(ufshpb_mctx_pool, GFP_KERNEL); 738 - if (!mctx) 739 - return NULL; 740 - 741 - mctx->m_page = kmem_cache_alloc(hpb->m_page_cache, GFP_KERNEL); 742 - if (!mctx->m_page) 743 - goto release_mctx; 744 - 745 - if (unlikely(last)) 746 - num_entries = hpb->last_srgn_entries; 747 - 748 - mctx->ppn_dirty = bitmap_zalloc(num_entries, GFP_KERNEL); 749 - if (!mctx->ppn_dirty) 750 - goto release_m_page; 751 - 752 - for (i = 0; i < hpb->pages_per_srgn; i++) { 753 - mctx->m_page[i] = mempool_alloc(ufshpb_page_pool, GFP_KERNEL); 754 - if (!mctx->m_page[i]) { 755 - for (j = 0; j < i; j++) 756 - mempool_free(mctx->m_page[j], ufshpb_page_pool); 757 - goto release_ppn_dirty; 758 - } 759 - clear_page(page_address(mctx->m_page[i])); 760 - } 761 - 762 - return mctx; 763 - 764 - release_ppn_dirty: 765 - bitmap_free(mctx->ppn_dirty); 766 - release_m_page: 767 - kmem_cache_free(hpb->m_page_cache, mctx->m_page); 768 - release_mctx: 769 - mempool_free(mctx, ufshpb_mctx_pool); 770 - return NULL; 771 - } 772 - 773 - static void ufshpb_put_map_ctx(struct ufshpb_lu *hpb, 774 - struct ufshpb_map_ctx *mctx) 775 - { 776 - int i; 777 - 778 - for (i = 0; i < hpb->pages_per_srgn; i++) 779 - mempool_free(mctx->m_page[i], ufshpb_page_pool); 780 - 781 - bitmap_free(mctx->ppn_dirty); 782 - kmem_cache_free(hpb->m_page_cache, mctx->m_page); 783 - mempool_free(mctx, ufshpb_mctx_pool); 784 - } 785 - 786 - static int ufshpb_check_srgns_issue_state(struct ufshpb_lu *hpb, 787 - struct ufshpb_region *rgn) 788 - { 789 - struct ufshpb_subregion *srgn; 790 - int srgn_idx; 791 - 792 - for_each_sub_region(rgn, srgn_idx, srgn) 793 - if (srgn->srgn_state == HPB_SRGN_ISSUED) 794 - return -EPERM; 795 - 796 - return 0; 797 - } 798 - 799 - static void ufshpb_read_to_handler(struct work_struct *work) 800 - { 801 - struct ufshpb_lu *hpb = container_of(work, struct ufshpb_lu, 802 - ufshpb_read_to_work.work); 803 - struct victim_select_info *lru_info = &hpb->lru_info; 804 - struct ufshpb_region *rgn, *next_rgn; 805 - unsigned long flags; 806 - unsigned int poll; 807 - LIST_HEAD(expired_list); 808 - 809 - if (test_and_set_bit(TIMEOUT_WORK_RUNNING, &hpb->work_data_bits)) 810 - return; 811 - 812 - spin_lock_irqsave(&hpb->rgn_state_lock, flags); 813 - 814 - list_for_each_entry_safe(rgn, next_rgn, &lru_info->lh_lru_rgn, 815 - list_lru_rgn) { 816 - bool timedout = ktime_after(ktime_get(), rgn->read_timeout); 817 - 818 - if (timedout) { 819 - rgn->read_timeout_expiries--; 820 - if (is_rgn_dirty(rgn) || 821 - rgn->read_timeout_expiries == 0) 822 - list_add(&rgn->list_expired_rgn, &expired_list); 823 - else 824 - rgn->read_timeout = ktime_add_ms(ktime_get(), 825 - hpb->params.read_timeout_ms); 826 - } 827 - } 828 - 829 - spin_unlock_irqrestore(&hpb->rgn_state_lock, flags); 830 - 831 - list_for_each_entry_safe(rgn, next_rgn, &expired_list, 832 - list_expired_rgn) { 833 - list_del_init(&rgn->list_expired_rgn); 834 - spin_lock_irqsave(&hpb->rsp_list_lock, flags); 835 - ufshpb_update_inactive_info(hpb, rgn->rgn_idx); 836 - spin_unlock_irqrestore(&hpb->rsp_list_lock, flags); 837 - } 838 - 839 - ufshpb_kick_map_work(hpb); 840 - 841 - clear_bit(TIMEOUT_WORK_RUNNING, &hpb->work_data_bits); 842 - 843 - poll = hpb->params.timeout_polling_interval_ms; 844 - schedule_delayed_work(&hpb->ufshpb_read_to_work, 845 - msecs_to_jiffies(poll)); 846 - } 847 - 848 - static void ufshpb_add_lru_info(struct victim_select_info *lru_info, 849 - struct ufshpb_region *rgn) 850 - { 851 - rgn->rgn_state = HPB_RGN_ACTIVE; 852 - list_add_tail(&rgn->list_lru_rgn, &lru_info->lh_lru_rgn); 853 - atomic_inc(&lru_info->active_cnt); 854 - if (rgn->hpb->is_hcm) { 855 - rgn->read_timeout = 856 - ktime_add_ms(ktime_get(), 857 - rgn->hpb->params.read_timeout_ms); 858 - rgn->read_timeout_expiries = 859 - rgn->hpb->params.read_timeout_expiries; 860 - } 861 - } 862 - 863 - static void ufshpb_hit_lru_info(struct victim_select_info *lru_info, 864 - struct ufshpb_region *rgn) 865 - { 866 - list_move_tail(&rgn->list_lru_rgn, &lru_info->lh_lru_rgn); 867 - } 868 - 869 - static struct ufshpb_region *ufshpb_victim_lru_info(struct ufshpb_lu *hpb) 870 - { 871 - struct victim_select_info *lru_info = &hpb->lru_info; 872 - struct ufshpb_region *rgn, *victim_rgn = NULL; 873 - 874 - list_for_each_entry(rgn, &lru_info->lh_lru_rgn, list_lru_rgn) { 875 - if (ufshpb_check_srgns_issue_state(hpb, rgn)) 876 - continue; 877 - 878 - /* 879 - * in host control mode, verify that the exiting region 880 - * has fewer reads 881 - */ 882 - if (hpb->is_hcm && 883 - rgn->reads > hpb->params.eviction_thld_exit) 884 - continue; 885 - 886 - victim_rgn = rgn; 887 - break; 888 - } 889 - 890 - if (!victim_rgn) 891 - dev_err(&hpb->sdev_ufs_lu->sdev_dev, 892 - "%s: no region allocated\n", 893 - __func__); 894 - 895 - return victim_rgn; 896 - } 897 - 898 - static void ufshpb_cleanup_lru_info(struct victim_select_info *lru_info, 899 - struct ufshpb_region *rgn) 900 - { 901 - list_del_init(&rgn->list_lru_rgn); 902 - rgn->rgn_state = HPB_RGN_INACTIVE; 903 - atomic_dec(&lru_info->active_cnt); 904 - } 905 - 906 - static void ufshpb_purge_active_subregion(struct ufshpb_lu *hpb, 907 - struct ufshpb_subregion *srgn) 908 - { 909 - if (srgn->srgn_state != HPB_SRGN_UNUSED) { 910 - ufshpb_put_map_ctx(hpb, srgn->mctx); 911 - srgn->srgn_state = HPB_SRGN_UNUSED; 912 - srgn->mctx = NULL; 913 - } 914 - } 915 - 916 - static int ufshpb_issue_umap_req(struct ufshpb_lu *hpb, 917 - struct ufshpb_region *rgn, 918 - bool atomic) 919 - { 920 - struct ufshpb_req *umap_req; 921 - int rgn_idx = rgn ? rgn->rgn_idx : 0; 922 - 923 - umap_req = ufshpb_get_req(hpb, rgn_idx, REQ_OP_DRV_OUT, atomic); 924 - if (!umap_req) 925 - return -ENOMEM; 926 - 927 - ufshpb_execute_umap_req(hpb, umap_req, rgn); 928 - 929 - return 0; 930 - } 931 - 932 - static int ufshpb_issue_umap_single_req(struct ufshpb_lu *hpb, 933 - struct ufshpb_region *rgn) 934 - { 935 - return ufshpb_issue_umap_req(hpb, rgn, true); 936 - } 937 - 938 - static void __ufshpb_evict_region(struct ufshpb_lu *hpb, 939 - struct ufshpb_region *rgn) 940 - { 941 - struct victim_select_info *lru_info; 942 - struct ufshpb_subregion *srgn; 943 - int srgn_idx; 944 - 945 - lru_info = &hpb->lru_info; 946 - 947 - dev_dbg(&hpb->sdev_ufs_lu->sdev_dev, "evict region %d\n", rgn->rgn_idx); 948 - 949 - ufshpb_cleanup_lru_info(lru_info, rgn); 950 - 951 - for_each_sub_region(rgn, srgn_idx, srgn) 952 - ufshpb_purge_active_subregion(hpb, srgn); 953 - } 954 - 955 - static int ufshpb_evict_region(struct ufshpb_lu *hpb, struct ufshpb_region *rgn) 956 - { 957 - unsigned long flags; 958 - int ret = 0; 959 - 960 - spin_lock_irqsave(&hpb->rgn_state_lock, flags); 961 - if (rgn->rgn_state == HPB_RGN_PINNED) { 962 - dev_warn(&hpb->sdev_ufs_lu->sdev_dev, 963 - "pinned region cannot drop-out. region %d\n", 964 - rgn->rgn_idx); 965 - goto out; 966 - } 967 - 968 - if (!list_empty(&rgn->list_lru_rgn)) { 969 - if (ufshpb_check_srgns_issue_state(hpb, rgn)) { 970 - ret = -EBUSY; 971 - goto out; 972 - } 973 - 974 - if (hpb->is_hcm) { 975 - spin_unlock_irqrestore(&hpb->rgn_state_lock, flags); 976 - ret = ufshpb_issue_umap_single_req(hpb, rgn); 977 - spin_lock_irqsave(&hpb->rgn_state_lock, flags); 978 - if (ret) 979 - goto out; 980 - } 981 - 982 - __ufshpb_evict_region(hpb, rgn); 983 - } 984 - out: 985 - spin_unlock_irqrestore(&hpb->rgn_state_lock, flags); 986 - return ret; 987 - } 988 - 989 - static int ufshpb_issue_map_req(struct ufshpb_lu *hpb, 990 - struct ufshpb_region *rgn, 991 - struct ufshpb_subregion *srgn) 992 - { 993 - struct ufshpb_req *map_req; 994 - unsigned long flags; 995 - int ret; 996 - int err = -EAGAIN; 997 - bool alloc_required = false; 998 - enum HPB_SRGN_STATE state = HPB_SRGN_INVALID; 999 - 1000 - spin_lock_irqsave(&hpb->rgn_state_lock, flags); 1001 - 1002 - if (ufshpb_get_state(hpb) != HPB_PRESENT) { 1003 - dev_notice(&hpb->sdev_ufs_lu->sdev_dev, 1004 - "%s: ufshpb state is not PRESENT\n", __func__); 1005 - goto unlock_out; 1006 - } 1007 - 1008 - if ((rgn->rgn_state == HPB_RGN_INACTIVE) && 1009 - (srgn->srgn_state == HPB_SRGN_INVALID)) { 1010 - err = 0; 1011 - goto unlock_out; 1012 - } 1013 - 1014 - if (srgn->srgn_state == HPB_SRGN_UNUSED) 1015 - alloc_required = true; 1016 - 1017 - /* 1018 - * If the subregion is already ISSUED state, 1019 - * a specific event (e.g., GC or wear-leveling, etc.) occurs in 1020 - * the device and HPB response for map loading is received. 1021 - * In this case, after finishing the HPB_READ_BUFFER, 1022 - * the next HPB_READ_BUFFER is performed again to obtain the latest 1023 - * map data. 1024 - */ 1025 - if (srgn->srgn_state == HPB_SRGN_ISSUED) 1026 - goto unlock_out; 1027 - 1028 - srgn->srgn_state = HPB_SRGN_ISSUED; 1029 - spin_unlock_irqrestore(&hpb->rgn_state_lock, flags); 1030 - 1031 - if (alloc_required) { 1032 - srgn->mctx = ufshpb_get_map_ctx(hpb, srgn->is_last); 1033 - if (!srgn->mctx) { 1034 - dev_err(&hpb->sdev_ufs_lu->sdev_dev, 1035 - "get map_ctx failed. region %d - %d\n", 1036 - rgn->rgn_idx, srgn->srgn_idx); 1037 - state = HPB_SRGN_UNUSED; 1038 - goto change_srgn_state; 1039 - } 1040 - } 1041 - 1042 - map_req = ufshpb_get_map_req(hpb, srgn); 1043 - if (!map_req) 1044 - goto change_srgn_state; 1045 - 1046 - 1047 - ret = ufshpb_execute_map_req(hpb, map_req, srgn->is_last); 1048 - if (ret) { 1049 - dev_err(&hpb->sdev_ufs_lu->sdev_dev, 1050 - "%s: issue map_req failed: %d, region %d - %d\n", 1051 - __func__, ret, srgn->rgn_idx, srgn->srgn_idx); 1052 - goto free_map_req; 1053 - } 1054 - return 0; 1055 - 1056 - free_map_req: 1057 - ufshpb_put_map_req(hpb, map_req); 1058 - change_srgn_state: 1059 - spin_lock_irqsave(&hpb->rgn_state_lock, flags); 1060 - srgn->srgn_state = state; 1061 - unlock_out: 1062 - spin_unlock_irqrestore(&hpb->rgn_state_lock, flags); 1063 - return err; 1064 - } 1065 - 1066 - static int ufshpb_add_region(struct ufshpb_lu *hpb, struct ufshpb_region *rgn) 1067 - { 1068 - struct ufshpb_region *victim_rgn = NULL; 1069 - struct victim_select_info *lru_info = &hpb->lru_info; 1070 - unsigned long flags; 1071 - int ret = 0; 1072 - 1073 - spin_lock_irqsave(&hpb->rgn_state_lock, flags); 1074 - /* 1075 - * If region belongs to lru_list, just move the region 1076 - * to the front of lru list because the state of the region 1077 - * is already active-state. 1078 - */ 1079 - if (!list_empty(&rgn->list_lru_rgn)) { 1080 - ufshpb_hit_lru_info(lru_info, rgn); 1081 - goto out; 1082 - } 1083 - 1084 - if (rgn->rgn_state == HPB_RGN_INACTIVE) { 1085 - if (atomic_read(&lru_info->active_cnt) == 1086 - lru_info->max_lru_active_cnt) { 1087 - /* 1088 - * If the maximum number of active regions 1089 - * is exceeded, evict the least recently used region. 1090 - * This case may occur when the device responds 1091 - * to the eviction information late. 1092 - * It is okay to evict the least recently used region, 1093 - * because the device could detect this region 1094 - * by not issuing HPB_READ 1095 - * 1096 - * in host control mode, verify that the entering 1097 - * region has enough reads 1098 - */ 1099 - if (hpb->is_hcm && 1100 - rgn->reads < hpb->params.eviction_thld_enter) { 1101 - ret = -EACCES; 1102 - goto out; 1103 - } 1104 - 1105 - victim_rgn = ufshpb_victim_lru_info(hpb); 1106 - if (!victim_rgn) { 1107 - dev_warn(&hpb->sdev_ufs_lu->sdev_dev, 1108 - "cannot get victim region %s\n", 1109 - hpb->is_hcm ? "" : "error"); 1110 - ret = -ENOMEM; 1111 - goto out; 1112 - } 1113 - 1114 - dev_dbg(&hpb->sdev_ufs_lu->sdev_dev, 1115 - "LRU full (%d), choose victim %d\n", 1116 - atomic_read(&lru_info->active_cnt), 1117 - victim_rgn->rgn_idx); 1118 - 1119 - if (hpb->is_hcm) { 1120 - spin_unlock_irqrestore(&hpb->rgn_state_lock, 1121 - flags); 1122 - ret = ufshpb_issue_umap_single_req(hpb, 1123 - victim_rgn); 1124 - spin_lock_irqsave(&hpb->rgn_state_lock, 1125 - flags); 1126 - if (ret) 1127 - goto out; 1128 - } 1129 - 1130 - __ufshpb_evict_region(hpb, victim_rgn); 1131 - } 1132 - 1133 - /* 1134 - * When a region is added to lru_info list_head, 1135 - * it is guaranteed that the subregion has been 1136 - * assigned all mctx. If failed, try to receive mctx again 1137 - * without being added to lru_info list_head 1138 - */ 1139 - ufshpb_add_lru_info(lru_info, rgn); 1140 - } 1141 - out: 1142 - spin_unlock_irqrestore(&hpb->rgn_state_lock, flags); 1143 - return ret; 1144 - } 1145 - /** 1146 - *ufshpb_submit_region_inactive() - submit a region to be inactivated later 1147 - *@hpb: per-LU HPB instance 1148 - *@region_index: the index associated with the region that will be inactivated later 1149 - */ 1150 - static void ufshpb_submit_region_inactive(struct ufshpb_lu *hpb, int region_index) 1151 - { 1152 - int subregion_index; 1153 - struct ufshpb_region *rgn; 1154 - struct ufshpb_subregion *srgn; 1155 - 1156 - /* 1157 - * Remove this region from active region list and add it to inactive list 1158 - */ 1159 - spin_lock(&hpb->rsp_list_lock); 1160 - ufshpb_update_inactive_info(hpb, region_index); 1161 - spin_unlock(&hpb->rsp_list_lock); 1162 - 1163 - rgn = hpb->rgn_tbl + region_index; 1164 - 1165 - /* 1166 - * Set subregion state to be HPB_SRGN_INVALID, there will no HPB read on this subregion 1167 - */ 1168 - spin_lock(&hpb->rgn_state_lock); 1169 - if (rgn->rgn_state != HPB_RGN_INACTIVE) { 1170 - for (subregion_index = 0; subregion_index < rgn->srgn_cnt; subregion_index++) { 1171 - srgn = rgn->srgn_tbl + subregion_index; 1172 - if (srgn->srgn_state == HPB_SRGN_VALID) 1173 - srgn->srgn_state = HPB_SRGN_INVALID; 1174 - } 1175 - } 1176 - spin_unlock(&hpb->rgn_state_lock); 1177 - } 1178 - 1179 - static void ufshpb_rsp_req_region_update(struct ufshpb_lu *hpb, 1180 - struct utp_hpb_rsp *rsp_field) 1181 - { 1182 - struct ufshpb_region *rgn; 1183 - struct ufshpb_subregion *srgn; 1184 - int i, rgn_i, srgn_i; 1185 - 1186 - BUILD_BUG_ON(sizeof(struct ufshpb_active_field) != HPB_ACT_FIELD_SIZE); 1187 - /* 1188 - * If the active region and the inactive region are the same, 1189 - * we will inactivate this region. 1190 - * The device could check this (region inactivated) and 1191 - * will response the proper active region information 1192 - */ 1193 - for (i = 0; i < rsp_field->active_rgn_cnt; i++) { 1194 - rgn_i = 1195 - be16_to_cpu(rsp_field->hpb_active_field[i].active_rgn); 1196 - srgn_i = 1197 - be16_to_cpu(rsp_field->hpb_active_field[i].active_srgn); 1198 - 1199 - rgn = hpb->rgn_tbl + rgn_i; 1200 - if (hpb->is_hcm && 1201 - (rgn->rgn_state != HPB_RGN_ACTIVE || is_rgn_dirty(rgn))) { 1202 - /* 1203 - * in host control mode, subregion activation 1204 - * recommendations are only allowed to active regions. 1205 - * Also, ignore recommendations for dirty regions - the 1206 - * host will make decisions concerning those by himself 1207 - */ 1208 - continue; 1209 - } 1210 - 1211 - dev_dbg(&hpb->sdev_ufs_lu->sdev_dev, 1212 - "activate(%d) region %d - %d\n", i, rgn_i, srgn_i); 1213 - 1214 - spin_lock(&hpb->rsp_list_lock); 1215 - ufshpb_update_active_info(hpb, rgn_i, srgn_i); 1216 - spin_unlock(&hpb->rsp_list_lock); 1217 - 1218 - srgn = rgn->srgn_tbl + srgn_i; 1219 - 1220 - /* blocking HPB_READ */ 1221 - spin_lock(&hpb->rgn_state_lock); 1222 - if (srgn->srgn_state == HPB_SRGN_VALID) 1223 - srgn->srgn_state = HPB_SRGN_INVALID; 1224 - spin_unlock(&hpb->rgn_state_lock); 1225 - } 1226 - 1227 - if (hpb->is_hcm) { 1228 - /* 1229 - * in host control mode the device is not allowed to inactivate 1230 - * regions 1231 - */ 1232 - goto out; 1233 - } 1234 - 1235 - for (i = 0; i < rsp_field->inactive_rgn_cnt; i++) { 1236 - rgn_i = be16_to_cpu(rsp_field->hpb_inactive_field[i]); 1237 - dev_dbg(&hpb->sdev_ufs_lu->sdev_dev, "inactivate(%d) region %d\n", i, rgn_i); 1238 - ufshpb_submit_region_inactive(hpb, rgn_i); 1239 - } 1240 - 1241 - out: 1242 - dev_dbg(&hpb->sdev_ufs_lu->sdev_dev, "Noti: #ACT %u #INACT %u\n", 1243 - rsp_field->active_rgn_cnt, rsp_field->inactive_rgn_cnt); 1244 - 1245 - if (ufshpb_get_state(hpb) == HPB_PRESENT) 1246 - queue_work(ufshpb_wq, &hpb->map_work); 1247 - } 1248 - 1249 - /* 1250 - * Set the flags of all active regions to RGN_FLAG_UPDATE to let host side reload L2P entries later 1251 - */ 1252 - static void ufshpb_set_regions_update(struct ufshpb_lu *hpb) 1253 - { 1254 - struct victim_select_info *lru_info = &hpb->lru_info; 1255 - struct ufshpb_region *rgn; 1256 - unsigned long flags; 1257 - 1258 - spin_lock_irqsave(&hpb->rgn_state_lock, flags); 1259 - 1260 - list_for_each_entry(rgn, &lru_info->lh_lru_rgn, list_lru_rgn) 1261 - set_bit(RGN_FLAG_UPDATE, &rgn->rgn_flags); 1262 - 1263 - spin_unlock_irqrestore(&hpb->rgn_state_lock, flags); 1264 - } 1265 - 1266 - static void ufshpb_dev_reset_handler(struct ufs_hba *hba) 1267 - { 1268 - struct scsi_device *sdev; 1269 - struct ufshpb_lu *hpb; 1270 - 1271 - __shost_for_each_device(sdev, hba->host) { 1272 - hpb = ufshpb_get_hpb_data(sdev); 1273 - if (!hpb) 1274 - continue; 1275 - 1276 - if (hpb->is_hcm) { 1277 - /* 1278 - * For the HPB host control mode, in case device powered up and lost HPB 1279 - * information, we will set the region flag to be RGN_FLAG_UPDATE, it will 1280 - * let host reload its L2P entries(reactivate region in the UFS device). 1281 - */ 1282 - ufshpb_set_regions_update(hpb); 1283 - } else { 1284 - /* 1285 - * For the HPB device control mode, if host side receives 02h:HPB Operation 1286 - * in UPIU response, which means device recommends the host side should 1287 - * inactivate all active regions. Here we add all active regions to inactive 1288 - * list, they will be inactivated later in ufshpb_map_work_handler(). 1289 - */ 1290 - struct victim_select_info *lru_info = &hpb->lru_info; 1291 - struct ufshpb_region *rgn; 1292 - 1293 - list_for_each_entry(rgn, &lru_info->lh_lru_rgn, list_lru_rgn) 1294 - ufshpb_submit_region_inactive(hpb, rgn->rgn_idx); 1295 - 1296 - if (ufshpb_get_state(hpb) == HPB_PRESENT) 1297 - queue_work(ufshpb_wq, &hpb->map_work); 1298 - } 1299 - } 1300 - } 1301 - 1302 - /* 1303 - * This function will parse recommended active subregion information in sense 1304 - * data field of response UPIU with SAM_STAT_GOOD state. 1305 - */ 1306 - void ufshpb_rsp_upiu(struct ufs_hba *hba, struct ufshcd_lrb *lrbp) 1307 - { 1308 - struct ufshpb_lu *hpb = ufshpb_get_hpb_data(lrbp->cmd->device); 1309 - struct utp_hpb_rsp *rsp_field = &lrbp->ucd_rsp_ptr->hr; 1310 - int data_seg_len; 1311 - 1312 - data_seg_len = be32_to_cpu(lrbp->ucd_rsp_ptr->header.dword_2) 1313 - & MASK_RSP_UPIU_DATA_SEG_LEN; 1314 - 1315 - /* If data segment length is zero, rsp_field is not valid */ 1316 - if (!data_seg_len) 1317 - return; 1318 - 1319 - if (unlikely(lrbp->lun != rsp_field->lun)) { 1320 - struct scsi_device *sdev; 1321 - bool found = false; 1322 - 1323 - __shost_for_each_device(sdev, hba->host) { 1324 - hpb = ufshpb_get_hpb_data(sdev); 1325 - 1326 - if (!hpb) 1327 - continue; 1328 - 1329 - if (rsp_field->lun == hpb->lun) { 1330 - found = true; 1331 - break; 1332 - } 1333 - } 1334 - 1335 - if (!found) 1336 - return; 1337 - } 1338 - 1339 - if (!hpb) 1340 - return; 1341 - 1342 - if (ufshpb_get_state(hpb) == HPB_INIT) 1343 - return; 1344 - 1345 - if ((ufshpb_get_state(hpb) != HPB_PRESENT) && 1346 - (ufshpb_get_state(hpb) != HPB_SUSPEND)) { 1347 - dev_notice(&hpb->sdev_ufs_lu->sdev_dev, 1348 - "%s: ufshpb state is not PRESENT/SUSPEND\n", 1349 - __func__); 1350 - return; 1351 - } 1352 - 1353 - BUILD_BUG_ON(sizeof(struct utp_hpb_rsp) != UTP_HPB_RSP_SIZE); 1354 - 1355 - if (!ufshpb_is_hpb_rsp_valid(hba, lrbp, rsp_field)) 1356 - return; 1357 - 1358 - hpb->stats.rcmd_noti_cnt++; 1359 - 1360 - switch (rsp_field->hpb_op) { 1361 - case HPB_RSP_REQ_REGION_UPDATE: 1362 - if (data_seg_len != DEV_DATA_SEG_LEN) 1363 - dev_warn(&hpb->sdev_ufs_lu->sdev_dev, 1364 - "%s: data seg length is not same.\n", 1365 - __func__); 1366 - ufshpb_rsp_req_region_update(hpb, rsp_field); 1367 - break; 1368 - case HPB_RSP_DEV_RESET: 1369 - dev_warn(&hpb->sdev_ufs_lu->sdev_dev, 1370 - "UFS device lost HPB information during PM.\n"); 1371 - ufshpb_dev_reset_handler(hba); 1372 - 1373 - break; 1374 - default: 1375 - dev_notice(&hpb->sdev_ufs_lu->sdev_dev, 1376 - "hpb_op is not available: %d\n", 1377 - rsp_field->hpb_op); 1378 - break; 1379 - } 1380 - } 1381 - 1382 - static void ufshpb_add_active_list(struct ufshpb_lu *hpb, 1383 - struct ufshpb_region *rgn, 1384 - struct ufshpb_subregion *srgn) 1385 - { 1386 - if (!list_empty(&rgn->list_inact_rgn)) 1387 - return; 1388 - 1389 - if (!list_empty(&srgn->list_act_srgn)) { 1390 - list_move(&srgn->list_act_srgn, &hpb->lh_act_srgn); 1391 - return; 1392 - } 1393 - 1394 - list_add(&srgn->list_act_srgn, &hpb->lh_act_srgn); 1395 - } 1396 - 1397 - static void ufshpb_add_pending_evict_list(struct ufshpb_lu *hpb, 1398 - struct ufshpb_region *rgn, 1399 - struct list_head *pending_list) 1400 - { 1401 - struct ufshpb_subregion *srgn; 1402 - int srgn_idx; 1403 - 1404 - if (!list_empty(&rgn->list_inact_rgn)) 1405 - return; 1406 - 1407 - for_each_sub_region(rgn, srgn_idx, srgn) 1408 - if (!list_empty(&srgn->list_act_srgn)) 1409 - return; 1410 - 1411 - list_add_tail(&rgn->list_inact_rgn, pending_list); 1412 - } 1413 - 1414 - static void ufshpb_run_active_subregion_list(struct ufshpb_lu *hpb) 1415 - { 1416 - struct ufshpb_region *rgn; 1417 - struct ufshpb_subregion *srgn; 1418 - unsigned long flags; 1419 - int ret = 0; 1420 - 1421 - spin_lock_irqsave(&hpb->rsp_list_lock, flags); 1422 - while ((srgn = list_first_entry_or_null(&hpb->lh_act_srgn, 1423 - struct ufshpb_subregion, 1424 - list_act_srgn))) { 1425 - if (ufshpb_get_state(hpb) == HPB_SUSPEND) 1426 - break; 1427 - 1428 - list_del_init(&srgn->list_act_srgn); 1429 - spin_unlock_irqrestore(&hpb->rsp_list_lock, flags); 1430 - 1431 - rgn = hpb->rgn_tbl + srgn->rgn_idx; 1432 - ret = ufshpb_add_region(hpb, rgn); 1433 - if (ret) 1434 - goto active_failed; 1435 - 1436 - ret = ufshpb_issue_map_req(hpb, rgn, srgn); 1437 - if (ret) { 1438 - dev_err(&hpb->sdev_ufs_lu->sdev_dev, 1439 - "issue map_req failed. ret %d, region %d - %d\n", 1440 - ret, rgn->rgn_idx, srgn->srgn_idx); 1441 - goto active_failed; 1442 - } 1443 - spin_lock_irqsave(&hpb->rsp_list_lock, flags); 1444 - } 1445 - spin_unlock_irqrestore(&hpb->rsp_list_lock, flags); 1446 - return; 1447 - 1448 - active_failed: 1449 - dev_err(&hpb->sdev_ufs_lu->sdev_dev, "failed to activate region %d - %d, will retry\n", 1450 - rgn->rgn_idx, srgn->srgn_idx); 1451 - spin_lock_irqsave(&hpb->rsp_list_lock, flags); 1452 - ufshpb_add_active_list(hpb, rgn, srgn); 1453 - spin_unlock_irqrestore(&hpb->rsp_list_lock, flags); 1454 - } 1455 - 1456 - static void ufshpb_run_inactive_region_list(struct ufshpb_lu *hpb) 1457 - { 1458 - struct ufshpb_region *rgn; 1459 - unsigned long flags; 1460 - int ret; 1461 - LIST_HEAD(pending_list); 1462 - 1463 - spin_lock_irqsave(&hpb->rsp_list_lock, flags); 1464 - while ((rgn = list_first_entry_or_null(&hpb->lh_inact_rgn, 1465 - struct ufshpb_region, 1466 - list_inact_rgn))) { 1467 - if (ufshpb_get_state(hpb) == HPB_SUSPEND) 1468 - break; 1469 - 1470 - list_del_init(&rgn->list_inact_rgn); 1471 - spin_unlock_irqrestore(&hpb->rsp_list_lock, flags); 1472 - 1473 - ret = ufshpb_evict_region(hpb, rgn); 1474 - if (ret) { 1475 - spin_lock_irqsave(&hpb->rsp_list_lock, flags); 1476 - ufshpb_add_pending_evict_list(hpb, rgn, &pending_list); 1477 - spin_unlock_irqrestore(&hpb->rsp_list_lock, flags); 1478 - } 1479 - 1480 - spin_lock_irqsave(&hpb->rsp_list_lock, flags); 1481 - } 1482 - 1483 - list_splice(&pending_list, &hpb->lh_inact_rgn); 1484 - spin_unlock_irqrestore(&hpb->rsp_list_lock, flags); 1485 - } 1486 - 1487 - static void ufshpb_normalization_work_handler(struct work_struct *work) 1488 - { 1489 - struct ufshpb_lu *hpb = container_of(work, struct ufshpb_lu, 1490 - ufshpb_normalization_work); 1491 - int rgn_idx; 1492 - u8 factor = hpb->params.normalization_factor; 1493 - 1494 - for (rgn_idx = 0; rgn_idx < hpb->rgns_per_lu; rgn_idx++) { 1495 - struct ufshpb_region *rgn = hpb->rgn_tbl + rgn_idx; 1496 - int srgn_idx; 1497 - 1498 - spin_lock(&rgn->rgn_lock); 1499 - rgn->reads = 0; 1500 - for (srgn_idx = 0; srgn_idx < hpb->srgns_per_rgn; srgn_idx++) { 1501 - struct ufshpb_subregion *srgn = rgn->srgn_tbl + srgn_idx; 1502 - 1503 - srgn->reads >>= factor; 1504 - rgn->reads += srgn->reads; 1505 - } 1506 - spin_unlock(&rgn->rgn_lock); 1507 - 1508 - if (rgn->rgn_state != HPB_RGN_ACTIVE || rgn->reads) 1509 - continue; 1510 - 1511 - /* if region is active but has no reads - inactivate it */ 1512 - spin_lock(&hpb->rsp_list_lock); 1513 - ufshpb_update_inactive_info(hpb, rgn->rgn_idx); 1514 - spin_unlock(&hpb->rsp_list_lock); 1515 - } 1516 - } 1517 - 1518 - static void ufshpb_map_work_handler(struct work_struct *work) 1519 - { 1520 - struct ufshpb_lu *hpb = container_of(work, struct ufshpb_lu, map_work); 1521 - 1522 - if (ufshpb_get_state(hpb) != HPB_PRESENT) { 1523 - dev_notice(&hpb->sdev_ufs_lu->sdev_dev, 1524 - "%s: ufshpb state is not PRESENT\n", __func__); 1525 - return; 1526 - } 1527 - 1528 - ufshpb_run_inactive_region_list(hpb); 1529 - ufshpb_run_active_subregion_list(hpb); 1530 - } 1531 - 1532 - /* 1533 - * this function doesn't need to hold lock due to be called in init. 1534 - * (rgn_state_lock, rsp_list_lock, etc..) 1535 - */ 1536 - static int ufshpb_init_pinned_active_region(struct ufs_hba *hba, 1537 - struct ufshpb_lu *hpb, 1538 - struct ufshpb_region *rgn) 1539 - { 1540 - struct ufshpb_subregion *srgn; 1541 - int srgn_idx, i; 1542 - int err = 0; 1543 - 1544 - for_each_sub_region(rgn, srgn_idx, srgn) { 1545 - srgn->mctx = ufshpb_get_map_ctx(hpb, srgn->is_last); 1546 - srgn->srgn_state = HPB_SRGN_INVALID; 1547 - if (!srgn->mctx) { 1548 - err = -ENOMEM; 1549 - dev_err(hba->dev, 1550 - "alloc mctx for pinned region failed\n"); 1551 - goto release; 1552 - } 1553 - 1554 - list_add_tail(&srgn->list_act_srgn, &hpb->lh_act_srgn); 1555 - } 1556 - 1557 - rgn->rgn_state = HPB_RGN_PINNED; 1558 - return 0; 1559 - 1560 - release: 1561 - for (i = 0; i < srgn_idx; i++) { 1562 - srgn = rgn->srgn_tbl + i; 1563 - ufshpb_put_map_ctx(hpb, srgn->mctx); 1564 - } 1565 - return err; 1566 - } 1567 - 1568 - static void ufshpb_init_subregion_tbl(struct ufshpb_lu *hpb, 1569 - struct ufshpb_region *rgn, bool last) 1570 - { 1571 - int srgn_idx; 1572 - struct ufshpb_subregion *srgn; 1573 - 1574 - for_each_sub_region(rgn, srgn_idx, srgn) { 1575 - INIT_LIST_HEAD(&srgn->list_act_srgn); 1576 - 1577 - srgn->rgn_idx = rgn->rgn_idx; 1578 - srgn->srgn_idx = srgn_idx; 1579 - srgn->srgn_state = HPB_SRGN_UNUSED; 1580 - } 1581 - 1582 - if (unlikely(last && hpb->last_srgn_entries)) 1583 - srgn->is_last = true; 1584 - } 1585 - 1586 - static int ufshpb_alloc_subregion_tbl(struct ufshpb_lu *hpb, 1587 - struct ufshpb_region *rgn, int srgn_cnt) 1588 - { 1589 - rgn->srgn_tbl = kvcalloc(srgn_cnt, sizeof(struct ufshpb_subregion), 1590 - GFP_KERNEL); 1591 - if (!rgn->srgn_tbl) 1592 - return -ENOMEM; 1593 - 1594 - rgn->srgn_cnt = srgn_cnt; 1595 - return 0; 1596 - } 1597 - 1598 - static void ufshpb_lu_parameter_init(struct ufs_hba *hba, 1599 - struct ufshpb_lu *hpb, 1600 - struct ufshpb_dev_info *hpb_dev_info, 1601 - struct ufshpb_lu_info *hpb_lu_info) 1602 - { 1603 - u32 entries_per_rgn; 1604 - u64 rgn_mem_size, tmp; 1605 - 1606 - if (ufshpb_is_legacy(hba)) 1607 - hpb->pre_req_max_tr_len = HPB_LEGACY_CHUNK_HIGH; 1608 - else 1609 - hpb->pre_req_max_tr_len = hpb_dev_info->max_hpb_single_cmd; 1610 - 1611 - hpb->lu_pinned_start = hpb_lu_info->pinned_start; 1612 - hpb->lu_pinned_end = hpb_lu_info->num_pinned ? 1613 - (hpb_lu_info->pinned_start + hpb_lu_info->num_pinned - 1) 1614 - : PINNED_NOT_SET; 1615 - hpb->lru_info.max_lru_active_cnt = 1616 - hpb_lu_info->max_active_rgns - hpb_lu_info->num_pinned; 1617 - 1618 - rgn_mem_size = (1ULL << hpb_dev_info->rgn_size) * HPB_RGN_SIZE_UNIT 1619 - * HPB_ENTRY_SIZE; 1620 - do_div(rgn_mem_size, HPB_ENTRY_BLOCK_SIZE); 1621 - hpb->srgn_mem_size = (1ULL << hpb_dev_info->srgn_size) 1622 - * HPB_RGN_SIZE_UNIT / HPB_ENTRY_BLOCK_SIZE * HPB_ENTRY_SIZE; 1623 - 1624 - tmp = rgn_mem_size; 1625 - do_div(tmp, HPB_ENTRY_SIZE); 1626 - entries_per_rgn = (u32)tmp; 1627 - hpb->entries_per_rgn_shift = ilog2(entries_per_rgn); 1628 - hpb->entries_per_rgn_mask = entries_per_rgn - 1; 1629 - 1630 - hpb->entries_per_srgn = hpb->srgn_mem_size / HPB_ENTRY_SIZE; 1631 - hpb->entries_per_srgn_shift = ilog2(hpb->entries_per_srgn); 1632 - hpb->entries_per_srgn_mask = hpb->entries_per_srgn - 1; 1633 - 1634 - tmp = rgn_mem_size; 1635 - do_div(tmp, hpb->srgn_mem_size); 1636 - hpb->srgns_per_rgn = (int)tmp; 1637 - 1638 - hpb->rgns_per_lu = DIV_ROUND_UP(hpb_lu_info->num_blocks, 1639 - entries_per_rgn); 1640 - hpb->srgns_per_lu = DIV_ROUND_UP(hpb_lu_info->num_blocks, 1641 - (hpb->srgn_mem_size / HPB_ENTRY_SIZE)); 1642 - hpb->last_srgn_entries = hpb_lu_info->num_blocks 1643 - % (hpb->srgn_mem_size / HPB_ENTRY_SIZE); 1644 - 1645 - hpb->pages_per_srgn = DIV_ROUND_UP(hpb->srgn_mem_size, PAGE_SIZE); 1646 - 1647 - if (hpb_dev_info->control_mode == HPB_HOST_CONTROL) 1648 - hpb->is_hcm = true; 1649 - } 1650 - 1651 - static int ufshpb_alloc_region_tbl(struct ufs_hba *hba, struct ufshpb_lu *hpb) 1652 - { 1653 - struct ufshpb_region *rgn_table, *rgn; 1654 - int rgn_idx, i; 1655 - int ret = 0; 1656 - 1657 - rgn_table = kvcalloc(hpb->rgns_per_lu, sizeof(struct ufshpb_region), 1658 - GFP_KERNEL); 1659 - if (!rgn_table) 1660 - return -ENOMEM; 1661 - 1662 - for (rgn_idx = 0; rgn_idx < hpb->rgns_per_lu; rgn_idx++) { 1663 - int srgn_cnt = hpb->srgns_per_rgn; 1664 - bool last_srgn = false; 1665 - 1666 - rgn = rgn_table + rgn_idx; 1667 - rgn->rgn_idx = rgn_idx; 1668 - 1669 - spin_lock_init(&rgn->rgn_lock); 1670 - 1671 - INIT_LIST_HEAD(&rgn->list_inact_rgn); 1672 - INIT_LIST_HEAD(&rgn->list_lru_rgn); 1673 - INIT_LIST_HEAD(&rgn->list_expired_rgn); 1674 - 1675 - if (rgn_idx == hpb->rgns_per_lu - 1) { 1676 - srgn_cnt = ((hpb->srgns_per_lu - 1) % 1677 - hpb->srgns_per_rgn) + 1; 1678 - last_srgn = true; 1679 - } 1680 - 1681 - ret = ufshpb_alloc_subregion_tbl(hpb, rgn, srgn_cnt); 1682 - if (ret) 1683 - goto release_srgn_table; 1684 - ufshpb_init_subregion_tbl(hpb, rgn, last_srgn); 1685 - 1686 - if (ufshpb_is_pinned_region(hpb, rgn_idx)) { 1687 - ret = ufshpb_init_pinned_active_region(hba, hpb, rgn); 1688 - if (ret) 1689 - goto release_srgn_table; 1690 - } else { 1691 - rgn->rgn_state = HPB_RGN_INACTIVE; 1692 - } 1693 - 1694 - rgn->rgn_flags = 0; 1695 - rgn->hpb = hpb; 1696 - } 1697 - 1698 - hpb->rgn_tbl = rgn_table; 1699 - 1700 - return 0; 1701 - 1702 - release_srgn_table: 1703 - for (i = 0; i <= rgn_idx; i++) 1704 - kvfree(rgn_table[i].srgn_tbl); 1705 - 1706 - kvfree(rgn_table); 1707 - return ret; 1708 - } 1709 - 1710 - static void ufshpb_destroy_subregion_tbl(struct ufshpb_lu *hpb, 1711 - struct ufshpb_region *rgn) 1712 - { 1713 - int srgn_idx; 1714 - struct ufshpb_subregion *srgn; 1715 - 1716 - for_each_sub_region(rgn, srgn_idx, srgn) 1717 - if (srgn->srgn_state != HPB_SRGN_UNUSED) { 1718 - srgn->srgn_state = HPB_SRGN_UNUSED; 1719 - ufshpb_put_map_ctx(hpb, srgn->mctx); 1720 - } 1721 - } 1722 - 1723 - static void ufshpb_destroy_region_tbl(struct ufshpb_lu *hpb) 1724 - { 1725 - int rgn_idx; 1726 - 1727 - for (rgn_idx = 0; rgn_idx < hpb->rgns_per_lu; rgn_idx++) { 1728 - struct ufshpb_region *rgn; 1729 - 1730 - rgn = hpb->rgn_tbl + rgn_idx; 1731 - if (rgn->rgn_state != HPB_RGN_INACTIVE) { 1732 - rgn->rgn_state = HPB_RGN_INACTIVE; 1733 - 1734 - ufshpb_destroy_subregion_tbl(hpb, rgn); 1735 - } 1736 - 1737 - kvfree(rgn->srgn_tbl); 1738 - } 1739 - 1740 - kvfree(hpb->rgn_tbl); 1741 - } 1742 - 1743 - /* SYSFS functions */ 1744 - #define ufshpb_sysfs_attr_show_func(__name) \ 1745 - static ssize_t __name##_show(struct device *dev, \ 1746 - struct device_attribute *attr, char *buf) \ 1747 - { \ 1748 - struct scsi_device *sdev = to_scsi_device(dev); \ 1749 - struct ufshpb_lu *hpb = ufshpb_get_hpb_data(sdev); \ 1750 - \ 1751 - if (!hpb) \ 1752 - return -ENODEV; \ 1753 - \ 1754 - return sysfs_emit(buf, "%llu\n", hpb->stats.__name); \ 1755 - } \ 1756 - \ 1757 - static DEVICE_ATTR_RO(__name) 1758 - 1759 - ufshpb_sysfs_attr_show_func(hit_cnt); 1760 - ufshpb_sysfs_attr_show_func(miss_cnt); 1761 - ufshpb_sysfs_attr_show_func(rcmd_noti_cnt); 1762 - ufshpb_sysfs_attr_show_func(rcmd_active_cnt); 1763 - ufshpb_sysfs_attr_show_func(rcmd_inactive_cnt); 1764 - ufshpb_sysfs_attr_show_func(map_req_cnt); 1765 - ufshpb_sysfs_attr_show_func(umap_req_cnt); 1766 - 1767 - static struct attribute *hpb_dev_stat_attrs[] = { 1768 - &dev_attr_hit_cnt.attr, 1769 - &dev_attr_miss_cnt.attr, 1770 - &dev_attr_rcmd_noti_cnt.attr, 1771 - &dev_attr_rcmd_active_cnt.attr, 1772 - &dev_attr_rcmd_inactive_cnt.attr, 1773 - &dev_attr_map_req_cnt.attr, 1774 - &dev_attr_umap_req_cnt.attr, 1775 - NULL, 1776 - }; 1777 - 1778 - struct attribute_group ufs_sysfs_hpb_stat_group = { 1779 - .name = "hpb_stats", 1780 - .attrs = hpb_dev_stat_attrs, 1781 - }; 1782 - 1783 - /* SYSFS functions */ 1784 - #define ufshpb_sysfs_param_show_func(__name) \ 1785 - static ssize_t __name##_show(struct device *dev, \ 1786 - struct device_attribute *attr, char *buf) \ 1787 - { \ 1788 - struct scsi_device *sdev = to_scsi_device(dev); \ 1789 - struct ufshpb_lu *hpb = ufshpb_get_hpb_data(sdev); \ 1790 - \ 1791 - if (!hpb) \ 1792 - return -ENODEV; \ 1793 - \ 1794 - return sysfs_emit(buf, "%d\n", hpb->params.__name); \ 1795 - } 1796 - 1797 - ufshpb_sysfs_param_show_func(requeue_timeout_ms); 1798 - static ssize_t 1799 - requeue_timeout_ms_store(struct device *dev, struct device_attribute *attr, 1800 - const char *buf, size_t count) 1801 - { 1802 - struct scsi_device *sdev = to_scsi_device(dev); 1803 - struct ufshpb_lu *hpb = ufshpb_get_hpb_data(sdev); 1804 - int val; 1805 - 1806 - if (!hpb) 1807 - return -ENODEV; 1808 - 1809 - if (kstrtouint(buf, 0, &val)) 1810 - return -EINVAL; 1811 - 1812 - if (val < 0) 1813 - return -EINVAL; 1814 - 1815 - hpb->params.requeue_timeout_ms = val; 1816 - 1817 - return count; 1818 - } 1819 - static DEVICE_ATTR_RW(requeue_timeout_ms); 1820 - 1821 - ufshpb_sysfs_param_show_func(activation_thld); 1822 - static ssize_t 1823 - activation_thld_store(struct device *dev, struct device_attribute *attr, 1824 - const char *buf, size_t count) 1825 - { 1826 - struct scsi_device *sdev = to_scsi_device(dev); 1827 - struct ufshpb_lu *hpb = ufshpb_get_hpb_data(sdev); 1828 - int val; 1829 - 1830 - if (!hpb) 1831 - return -ENODEV; 1832 - 1833 - if (!hpb->is_hcm) 1834 - return -EOPNOTSUPP; 1835 - 1836 - if (kstrtouint(buf, 0, &val)) 1837 - return -EINVAL; 1838 - 1839 - if (val <= 0) 1840 - return -EINVAL; 1841 - 1842 - hpb->params.activation_thld = val; 1843 - 1844 - return count; 1845 - } 1846 - static DEVICE_ATTR_RW(activation_thld); 1847 - 1848 - ufshpb_sysfs_param_show_func(normalization_factor); 1849 - static ssize_t 1850 - normalization_factor_store(struct device *dev, struct device_attribute *attr, 1851 - const char *buf, size_t count) 1852 - { 1853 - struct scsi_device *sdev = to_scsi_device(dev); 1854 - struct ufshpb_lu *hpb = ufshpb_get_hpb_data(sdev); 1855 - int val; 1856 - 1857 - if (!hpb) 1858 - return -ENODEV; 1859 - 1860 - if (!hpb->is_hcm) 1861 - return -EOPNOTSUPP; 1862 - 1863 - if (kstrtouint(buf, 0, &val)) 1864 - return -EINVAL; 1865 - 1866 - if (val <= 0 || val > ilog2(hpb->entries_per_srgn)) 1867 - return -EINVAL; 1868 - 1869 - hpb->params.normalization_factor = val; 1870 - 1871 - return count; 1872 - } 1873 - static DEVICE_ATTR_RW(normalization_factor); 1874 - 1875 - ufshpb_sysfs_param_show_func(eviction_thld_enter); 1876 - static ssize_t 1877 - eviction_thld_enter_store(struct device *dev, struct device_attribute *attr, 1878 - const char *buf, size_t count) 1879 - { 1880 - struct scsi_device *sdev = to_scsi_device(dev); 1881 - struct ufshpb_lu *hpb = ufshpb_get_hpb_data(sdev); 1882 - int val; 1883 - 1884 - if (!hpb) 1885 - return -ENODEV; 1886 - 1887 - if (!hpb->is_hcm) 1888 - return -EOPNOTSUPP; 1889 - 1890 - if (kstrtouint(buf, 0, &val)) 1891 - return -EINVAL; 1892 - 1893 - if (val <= hpb->params.eviction_thld_exit) 1894 - return -EINVAL; 1895 - 1896 - hpb->params.eviction_thld_enter = val; 1897 - 1898 - return count; 1899 - } 1900 - static DEVICE_ATTR_RW(eviction_thld_enter); 1901 - 1902 - ufshpb_sysfs_param_show_func(eviction_thld_exit); 1903 - static ssize_t 1904 - eviction_thld_exit_store(struct device *dev, struct device_attribute *attr, 1905 - const char *buf, size_t count) 1906 - { 1907 - struct scsi_device *sdev = to_scsi_device(dev); 1908 - struct ufshpb_lu *hpb = ufshpb_get_hpb_data(sdev); 1909 - int val; 1910 - 1911 - if (!hpb) 1912 - return -ENODEV; 1913 - 1914 - if (!hpb->is_hcm) 1915 - return -EOPNOTSUPP; 1916 - 1917 - if (kstrtouint(buf, 0, &val)) 1918 - return -EINVAL; 1919 - 1920 - if (val <= hpb->params.activation_thld) 1921 - return -EINVAL; 1922 - 1923 - hpb->params.eviction_thld_exit = val; 1924 - 1925 - return count; 1926 - } 1927 - static DEVICE_ATTR_RW(eviction_thld_exit); 1928 - 1929 - ufshpb_sysfs_param_show_func(read_timeout_ms); 1930 - static ssize_t 1931 - read_timeout_ms_store(struct device *dev, struct device_attribute *attr, 1932 - const char *buf, size_t count) 1933 - { 1934 - struct scsi_device *sdev = to_scsi_device(dev); 1935 - struct ufshpb_lu *hpb = ufshpb_get_hpb_data(sdev); 1936 - int val; 1937 - 1938 - if (!hpb) 1939 - return -ENODEV; 1940 - 1941 - if (!hpb->is_hcm) 1942 - return -EOPNOTSUPP; 1943 - 1944 - if (kstrtouint(buf, 0, &val)) 1945 - return -EINVAL; 1946 - 1947 - /* read_timeout >> timeout_polling_interval */ 1948 - if (val < hpb->params.timeout_polling_interval_ms * 2) 1949 - return -EINVAL; 1950 - 1951 - hpb->params.read_timeout_ms = val; 1952 - 1953 - return count; 1954 - } 1955 - static DEVICE_ATTR_RW(read_timeout_ms); 1956 - 1957 - ufshpb_sysfs_param_show_func(read_timeout_expiries); 1958 - static ssize_t 1959 - read_timeout_expiries_store(struct device *dev, struct device_attribute *attr, 1960 - const char *buf, size_t count) 1961 - { 1962 - struct scsi_device *sdev = to_scsi_device(dev); 1963 - struct ufshpb_lu *hpb = ufshpb_get_hpb_data(sdev); 1964 - int val; 1965 - 1966 - if (!hpb) 1967 - return -ENODEV; 1968 - 1969 - if (!hpb->is_hcm) 1970 - return -EOPNOTSUPP; 1971 - 1972 - if (kstrtouint(buf, 0, &val)) 1973 - return -EINVAL; 1974 - 1975 - if (val <= 0) 1976 - return -EINVAL; 1977 - 1978 - hpb->params.read_timeout_expiries = val; 1979 - 1980 - return count; 1981 - } 1982 - static DEVICE_ATTR_RW(read_timeout_expiries); 1983 - 1984 - ufshpb_sysfs_param_show_func(timeout_polling_interval_ms); 1985 - static ssize_t 1986 - timeout_polling_interval_ms_store(struct device *dev, 1987 - struct device_attribute *attr, 1988 - const char *buf, size_t count) 1989 - { 1990 - struct scsi_device *sdev = to_scsi_device(dev); 1991 - struct ufshpb_lu *hpb = ufshpb_get_hpb_data(sdev); 1992 - int val; 1993 - 1994 - if (!hpb) 1995 - return -ENODEV; 1996 - 1997 - if (!hpb->is_hcm) 1998 - return -EOPNOTSUPP; 1999 - 2000 - if (kstrtouint(buf, 0, &val)) 2001 - return -EINVAL; 2002 - 2003 - /* timeout_polling_interval << read_timeout */ 2004 - if (val <= 0 || val > hpb->params.read_timeout_ms / 2) 2005 - return -EINVAL; 2006 - 2007 - hpb->params.timeout_polling_interval_ms = val; 2008 - 2009 - return count; 2010 - } 2011 - static DEVICE_ATTR_RW(timeout_polling_interval_ms); 2012 - 2013 - ufshpb_sysfs_param_show_func(inflight_map_req); 2014 - static ssize_t inflight_map_req_store(struct device *dev, 2015 - struct device_attribute *attr, 2016 - const char *buf, size_t count) 2017 - { 2018 - struct scsi_device *sdev = to_scsi_device(dev); 2019 - struct ufshpb_lu *hpb = ufshpb_get_hpb_data(sdev); 2020 - int val; 2021 - 2022 - if (!hpb) 2023 - return -ENODEV; 2024 - 2025 - if (!hpb->is_hcm) 2026 - return -EOPNOTSUPP; 2027 - 2028 - if (kstrtouint(buf, 0, &val)) 2029 - return -EINVAL; 2030 - 2031 - if (val <= 0 || val > hpb->sdev_ufs_lu->queue_depth - 1) 2032 - return -EINVAL; 2033 - 2034 - hpb->params.inflight_map_req = val; 2035 - 2036 - return count; 2037 - } 2038 - static DEVICE_ATTR_RW(inflight_map_req); 2039 - 2040 - static void ufshpb_hcm_param_init(struct ufshpb_lu *hpb) 2041 - { 2042 - hpb->params.activation_thld = ACTIVATION_THRESHOLD; 2043 - hpb->params.normalization_factor = 1; 2044 - hpb->params.eviction_thld_enter = (ACTIVATION_THRESHOLD << 5); 2045 - hpb->params.eviction_thld_exit = (ACTIVATION_THRESHOLD << 4); 2046 - hpb->params.read_timeout_ms = READ_TO_MS; 2047 - hpb->params.read_timeout_expiries = READ_TO_EXPIRIES; 2048 - hpb->params.timeout_polling_interval_ms = POLLING_INTERVAL_MS; 2049 - hpb->params.inflight_map_req = THROTTLE_MAP_REQ_DEFAULT; 2050 - } 2051 - 2052 - static struct attribute *hpb_dev_param_attrs[] = { 2053 - &dev_attr_requeue_timeout_ms.attr, 2054 - &dev_attr_activation_thld.attr, 2055 - &dev_attr_normalization_factor.attr, 2056 - &dev_attr_eviction_thld_enter.attr, 2057 - &dev_attr_eviction_thld_exit.attr, 2058 - &dev_attr_read_timeout_ms.attr, 2059 - &dev_attr_read_timeout_expiries.attr, 2060 - &dev_attr_timeout_polling_interval_ms.attr, 2061 - &dev_attr_inflight_map_req.attr, 2062 - NULL, 2063 - }; 2064 - 2065 - struct attribute_group ufs_sysfs_hpb_param_group = { 2066 - .name = "hpb_params", 2067 - .attrs = hpb_dev_param_attrs, 2068 - }; 2069 - 2070 - static int ufshpb_pre_req_mempool_init(struct ufshpb_lu *hpb) 2071 - { 2072 - struct ufshpb_req *pre_req = NULL, *t; 2073 - int qd = hpb->sdev_ufs_lu->queue_depth / 2; 2074 - int i; 2075 - 2076 - INIT_LIST_HEAD(&hpb->lh_pre_req_free); 2077 - 2078 - hpb->pre_req = kcalloc(qd, sizeof(struct ufshpb_req), GFP_KERNEL); 2079 - hpb->throttle_pre_req = qd; 2080 - hpb->num_inflight_pre_req = 0; 2081 - 2082 - if (!hpb->pre_req) 2083 - goto release_mem; 2084 - 2085 - for (i = 0; i < qd; i++) { 2086 - pre_req = hpb->pre_req + i; 2087 - INIT_LIST_HEAD(&pre_req->list_req); 2088 - pre_req->req = NULL; 2089 - 2090 - pre_req->bio = bio_alloc(NULL, 1, 0, GFP_KERNEL); 2091 - if (!pre_req->bio) 2092 - goto release_mem; 2093 - 2094 - pre_req->wb.m_page = alloc_page(GFP_KERNEL | __GFP_ZERO); 2095 - if (!pre_req->wb.m_page) { 2096 - bio_put(pre_req->bio); 2097 - goto release_mem; 2098 - } 2099 - 2100 - list_add_tail(&pre_req->list_req, &hpb->lh_pre_req_free); 2101 - } 2102 - 2103 - return 0; 2104 - release_mem: 2105 - list_for_each_entry_safe(pre_req, t, &hpb->lh_pre_req_free, list_req) { 2106 - list_del_init(&pre_req->list_req); 2107 - bio_put(pre_req->bio); 2108 - __free_page(pre_req->wb.m_page); 2109 - } 2110 - 2111 - kfree(hpb->pre_req); 2112 - return -ENOMEM; 2113 - } 2114 - 2115 - static void ufshpb_pre_req_mempool_destroy(struct ufshpb_lu *hpb) 2116 - { 2117 - struct ufshpb_req *pre_req = NULL; 2118 - int i; 2119 - 2120 - for (i = 0; i < hpb->throttle_pre_req; i++) { 2121 - pre_req = hpb->pre_req + i; 2122 - bio_put(hpb->pre_req[i].bio); 2123 - if (!pre_req->wb.m_page) 2124 - __free_page(hpb->pre_req[i].wb.m_page); 2125 - list_del_init(&pre_req->list_req); 2126 - } 2127 - 2128 - kfree(hpb->pre_req); 2129 - } 2130 - 2131 - static void ufshpb_stat_init(struct ufshpb_lu *hpb) 2132 - { 2133 - hpb->stats.hit_cnt = 0; 2134 - hpb->stats.miss_cnt = 0; 2135 - hpb->stats.rcmd_noti_cnt = 0; 2136 - hpb->stats.rcmd_active_cnt = 0; 2137 - hpb->stats.rcmd_inactive_cnt = 0; 2138 - hpb->stats.map_req_cnt = 0; 2139 - hpb->stats.umap_req_cnt = 0; 2140 - } 2141 - 2142 - static void ufshpb_param_init(struct ufshpb_lu *hpb) 2143 - { 2144 - hpb->params.requeue_timeout_ms = HPB_REQUEUE_TIME_MS; 2145 - if (hpb->is_hcm) 2146 - ufshpb_hcm_param_init(hpb); 2147 - } 2148 - 2149 - static int ufshpb_lu_hpb_init(struct ufs_hba *hba, struct ufshpb_lu *hpb) 2150 - { 2151 - int ret; 2152 - 2153 - spin_lock_init(&hpb->rgn_state_lock); 2154 - spin_lock_init(&hpb->rsp_list_lock); 2155 - spin_lock_init(&hpb->param_lock); 2156 - 2157 - INIT_LIST_HEAD(&hpb->lru_info.lh_lru_rgn); 2158 - INIT_LIST_HEAD(&hpb->lh_act_srgn); 2159 - INIT_LIST_HEAD(&hpb->lh_inact_rgn); 2160 - INIT_LIST_HEAD(&hpb->list_hpb_lu); 2161 - 2162 - INIT_WORK(&hpb->map_work, ufshpb_map_work_handler); 2163 - if (hpb->is_hcm) { 2164 - INIT_WORK(&hpb->ufshpb_normalization_work, 2165 - ufshpb_normalization_work_handler); 2166 - INIT_DELAYED_WORK(&hpb->ufshpb_read_to_work, 2167 - ufshpb_read_to_handler); 2168 - } 2169 - 2170 - hpb->map_req_cache = kmem_cache_create("ufshpb_req_cache", 2171 - sizeof(struct ufshpb_req), 0, 0, NULL); 2172 - if (!hpb->map_req_cache) { 2173 - dev_err(hba->dev, "ufshpb(%d) ufshpb_req_cache create fail", 2174 - hpb->lun); 2175 - return -ENOMEM; 2176 - } 2177 - 2178 - hpb->m_page_cache = kmem_cache_create("ufshpb_m_page_cache", 2179 - sizeof(struct page *) * hpb->pages_per_srgn, 2180 - 0, 0, NULL); 2181 - if (!hpb->m_page_cache) { 2182 - dev_err(hba->dev, "ufshpb(%d) ufshpb_m_page_cache create fail", 2183 - hpb->lun); 2184 - ret = -ENOMEM; 2185 - goto release_req_cache; 2186 - } 2187 - 2188 - ret = ufshpb_pre_req_mempool_init(hpb); 2189 - if (ret) { 2190 - dev_err(hba->dev, "ufshpb(%d) pre_req_mempool init fail", 2191 - hpb->lun); 2192 - goto release_m_page_cache; 2193 - } 2194 - 2195 - ret = ufshpb_alloc_region_tbl(hba, hpb); 2196 - if (ret) 2197 - goto release_pre_req_mempool; 2198 - 2199 - ufshpb_stat_init(hpb); 2200 - ufshpb_param_init(hpb); 2201 - 2202 - if (hpb->is_hcm) { 2203 - unsigned int poll; 2204 - 2205 - poll = hpb->params.timeout_polling_interval_ms; 2206 - schedule_delayed_work(&hpb->ufshpb_read_to_work, 2207 - msecs_to_jiffies(poll)); 2208 - } 2209 - 2210 - return 0; 2211 - 2212 - release_pre_req_mempool: 2213 - ufshpb_pre_req_mempool_destroy(hpb); 2214 - release_m_page_cache: 2215 - kmem_cache_destroy(hpb->m_page_cache); 2216 - release_req_cache: 2217 - kmem_cache_destroy(hpb->map_req_cache); 2218 - return ret; 2219 - } 2220 - 2221 - static struct ufshpb_lu * 2222 - ufshpb_alloc_hpb_lu(struct ufs_hba *hba, struct scsi_device *sdev, 2223 - struct ufshpb_dev_info *hpb_dev_info, 2224 - struct ufshpb_lu_info *hpb_lu_info) 2225 - { 2226 - struct ufshpb_lu *hpb; 2227 - int ret; 2228 - 2229 - hpb = kzalloc(sizeof(struct ufshpb_lu), GFP_KERNEL); 2230 - if (!hpb) 2231 - return NULL; 2232 - 2233 - hpb->lun = sdev->lun; 2234 - hpb->sdev_ufs_lu = sdev; 2235 - 2236 - ufshpb_lu_parameter_init(hba, hpb, hpb_dev_info, hpb_lu_info); 2237 - 2238 - ret = ufshpb_lu_hpb_init(hba, hpb); 2239 - if (ret) { 2240 - dev_err(hba->dev, "hpb lu init failed. ret %d", ret); 2241 - goto release_hpb; 2242 - } 2243 - 2244 - sdev->hostdata = hpb; 2245 - return hpb; 2246 - 2247 - release_hpb: 2248 - kfree(hpb); 2249 - return NULL; 2250 - } 2251 - 2252 - static void ufshpb_discard_rsp_lists(struct ufshpb_lu *hpb) 2253 - { 2254 - struct ufshpb_region *rgn, *next_rgn; 2255 - struct ufshpb_subregion *srgn, *next_srgn; 2256 - unsigned long flags; 2257 - 2258 - /* 2259 - * If the device reset occurred, the remaining HPB region information 2260 - * may be stale. Therefore, by discarding the lists of HPB response 2261 - * that remained after reset, we prevent unnecessary work. 2262 - */ 2263 - spin_lock_irqsave(&hpb->rsp_list_lock, flags); 2264 - list_for_each_entry_safe(rgn, next_rgn, &hpb->lh_inact_rgn, 2265 - list_inact_rgn) 2266 - list_del_init(&rgn->list_inact_rgn); 2267 - 2268 - list_for_each_entry_safe(srgn, next_srgn, &hpb->lh_act_srgn, 2269 - list_act_srgn) 2270 - list_del_init(&srgn->list_act_srgn); 2271 - spin_unlock_irqrestore(&hpb->rsp_list_lock, flags); 2272 - } 2273 - 2274 - static void ufshpb_cancel_jobs(struct ufshpb_lu *hpb) 2275 - { 2276 - if (hpb->is_hcm) { 2277 - cancel_delayed_work_sync(&hpb->ufshpb_read_to_work); 2278 - cancel_work_sync(&hpb->ufshpb_normalization_work); 2279 - } 2280 - cancel_work_sync(&hpb->map_work); 2281 - } 2282 - 2283 - static bool ufshpb_check_hpb_reset_query(struct ufs_hba *hba) 2284 - { 2285 - int err = 0; 2286 - bool flag_res = true; 2287 - int try; 2288 - 2289 - /* wait for the device to complete HPB reset query */ 2290 - for (try = 0; try < HPB_RESET_REQ_RETRIES; try++) { 2291 - dev_dbg(hba->dev, 2292 - "%s: start flag reset polling %d times\n", 2293 - __func__, try); 2294 - 2295 - /* Poll fHpbReset flag to be cleared */ 2296 - err = ufshcd_query_flag(hba, UPIU_QUERY_OPCODE_READ_FLAG, 2297 - QUERY_FLAG_IDN_HPB_RESET, 0, &flag_res); 2298 - 2299 - if (err) { 2300 - dev_err(hba->dev, 2301 - "%s: reading fHpbReset flag failed with error %d\n", 2302 - __func__, err); 2303 - return flag_res; 2304 - } 2305 - 2306 - if (!flag_res) 2307 - goto out; 2308 - 2309 - usleep_range(1000, 1100); 2310 - } 2311 - if (flag_res) { 2312 - dev_err(hba->dev, 2313 - "%s: fHpbReset was not cleared by the device\n", 2314 - __func__); 2315 - } 2316 - out: 2317 - return flag_res; 2318 - } 2319 - 2320 - /** 2321 - * ufshpb_toggle_state - switch HPB state of all LUs 2322 - * @hba: per-adapter instance 2323 - * @src: expected current HPB state 2324 - * @dest: target HPB state to switch to 2325 - */ 2326 - void ufshpb_toggle_state(struct ufs_hba *hba, enum UFSHPB_STATE src, enum UFSHPB_STATE dest) 2327 - { 2328 - struct ufshpb_lu *hpb; 2329 - struct scsi_device *sdev; 2330 - 2331 - shost_for_each_device(sdev, hba->host) { 2332 - hpb = ufshpb_get_hpb_data(sdev); 2333 - 2334 - if (!hpb || ufshpb_get_state(hpb) != src) 2335 - continue; 2336 - ufshpb_set_state(hpb, dest); 2337 - 2338 - if (dest == HPB_RESET) { 2339 - ufshpb_cancel_jobs(hpb); 2340 - ufshpb_discard_rsp_lists(hpb); 2341 - } 2342 - } 2343 - } 2344 - 2345 - void ufshpb_suspend(struct ufs_hba *hba) 2346 - { 2347 - struct ufshpb_lu *hpb; 2348 - struct scsi_device *sdev; 2349 - 2350 - shost_for_each_device(sdev, hba->host) { 2351 - hpb = ufshpb_get_hpb_data(sdev); 2352 - if (!hpb || ufshpb_get_state(hpb) != HPB_PRESENT) 2353 - continue; 2354 - 2355 - ufshpb_set_state(hpb, HPB_SUSPEND); 2356 - ufshpb_cancel_jobs(hpb); 2357 - } 2358 - } 2359 - 2360 - void ufshpb_resume(struct ufs_hba *hba) 2361 - { 2362 - struct ufshpb_lu *hpb; 2363 - struct scsi_device *sdev; 2364 - 2365 - shost_for_each_device(sdev, hba->host) { 2366 - hpb = ufshpb_get_hpb_data(sdev); 2367 - if (!hpb || ufshpb_get_state(hpb) != HPB_SUSPEND) 2368 - continue; 2369 - 2370 - ufshpb_set_state(hpb, HPB_PRESENT); 2371 - ufshpb_kick_map_work(hpb); 2372 - if (hpb->is_hcm) { 2373 - unsigned int poll = hpb->params.timeout_polling_interval_ms; 2374 - 2375 - schedule_delayed_work(&hpb->ufshpb_read_to_work, msecs_to_jiffies(poll)); 2376 - } 2377 - } 2378 - } 2379 - 2380 - static int ufshpb_get_lu_info(struct ufs_hba *hba, int lun, 2381 - struct ufshpb_lu_info *hpb_lu_info) 2382 - { 2383 - u16 max_active_rgns; 2384 - u8 lu_enable; 2385 - int size = QUERY_DESC_MAX_SIZE; 2386 - int ret; 2387 - char desc_buf[QUERY_DESC_MAX_SIZE]; 2388 - 2389 - ufshcd_rpm_get_sync(hba); 2390 - ret = ufshcd_query_descriptor_retry(hba, UPIU_QUERY_OPCODE_READ_DESC, 2391 - QUERY_DESC_IDN_UNIT, lun, 0, 2392 - desc_buf, &size); 2393 - ufshcd_rpm_put_sync(hba); 2394 - 2395 - if (ret) { 2396 - dev_err(hba->dev, 2397 - "%s: idn: %d lun: %d query request failed", 2398 - __func__, QUERY_DESC_IDN_UNIT, lun); 2399 - return ret; 2400 - } 2401 - 2402 - lu_enable = desc_buf[UNIT_DESC_PARAM_LU_ENABLE]; 2403 - if (lu_enable != LU_ENABLED_HPB_FUNC) 2404 - return -ENODEV; 2405 - 2406 - max_active_rgns = get_unaligned_be16( 2407 - desc_buf + UNIT_DESC_PARAM_HPB_LU_MAX_ACTIVE_RGNS); 2408 - if (!max_active_rgns) { 2409 - dev_err(hba->dev, 2410 - "lun %d wrong number of max active regions\n", lun); 2411 - return -ENODEV; 2412 - } 2413 - 2414 - hpb_lu_info->num_blocks = get_unaligned_be64( 2415 - desc_buf + UNIT_DESC_PARAM_LOGICAL_BLK_COUNT); 2416 - hpb_lu_info->pinned_start = get_unaligned_be16( 2417 - desc_buf + UNIT_DESC_PARAM_HPB_PIN_RGN_START_OFF); 2418 - hpb_lu_info->num_pinned = get_unaligned_be16( 2419 - desc_buf + UNIT_DESC_PARAM_HPB_NUM_PIN_RGNS); 2420 - hpb_lu_info->max_active_rgns = max_active_rgns; 2421 - 2422 - return 0; 2423 - } 2424 - 2425 - void ufshpb_destroy_lu(struct ufs_hba *hba, struct scsi_device *sdev) 2426 - { 2427 - struct ufshpb_lu *hpb = ufshpb_get_hpb_data(sdev); 2428 - 2429 - if (!hpb) 2430 - return; 2431 - 2432 - ufshpb_set_state(hpb, HPB_FAILED); 2433 - 2434 - sdev = hpb->sdev_ufs_lu; 2435 - sdev->hostdata = NULL; 2436 - 2437 - ufshpb_cancel_jobs(hpb); 2438 - 2439 - ufshpb_pre_req_mempool_destroy(hpb); 2440 - ufshpb_destroy_region_tbl(hpb); 2441 - 2442 - kmem_cache_destroy(hpb->map_req_cache); 2443 - kmem_cache_destroy(hpb->m_page_cache); 2444 - 2445 - list_del_init(&hpb->list_hpb_lu); 2446 - 2447 - kfree(hpb); 2448 - } 2449 - 2450 - static void ufshpb_hpb_lu_prepared(struct ufs_hba *hba) 2451 - { 2452 - int pool_size; 2453 - struct ufshpb_lu *hpb; 2454 - struct scsi_device *sdev; 2455 - bool init_success; 2456 - 2457 - if (tot_active_srgn_pages == 0) { 2458 - ufshpb_remove(hba); 2459 - return; 2460 - } 2461 - 2462 - init_success = !ufshpb_check_hpb_reset_query(hba); 2463 - 2464 - pool_size = PAGE_ALIGN(ufshpb_host_map_kbytes * SZ_1K) / PAGE_SIZE; 2465 - if (pool_size > tot_active_srgn_pages) { 2466 - mempool_resize(ufshpb_mctx_pool, tot_active_srgn_pages); 2467 - mempool_resize(ufshpb_page_pool, tot_active_srgn_pages); 2468 - } 2469 - 2470 - shost_for_each_device(sdev, hba->host) { 2471 - hpb = ufshpb_get_hpb_data(sdev); 2472 - if (!hpb) 2473 - continue; 2474 - 2475 - if (init_success) { 2476 - ufshpb_set_state(hpb, HPB_PRESENT); 2477 - if ((hpb->lu_pinned_end - hpb->lu_pinned_start) > 0) 2478 - queue_work(ufshpb_wq, &hpb->map_work); 2479 - } else { 2480 - dev_err(hba->dev, "destroy HPB lu %d\n", hpb->lun); 2481 - ufshpb_destroy_lu(hba, sdev); 2482 - } 2483 - } 2484 - 2485 - if (!init_success) 2486 - ufshpb_remove(hba); 2487 - } 2488 - 2489 - void ufshpb_init_hpb_lu(struct ufs_hba *hba, struct scsi_device *sdev) 2490 - { 2491 - struct ufshpb_lu *hpb; 2492 - int ret; 2493 - struct ufshpb_lu_info hpb_lu_info = { 0 }; 2494 - int lun = sdev->lun; 2495 - 2496 - if (lun >= hba->dev_info.max_lu_supported) 2497 - goto out; 2498 - 2499 - ret = ufshpb_get_lu_info(hba, lun, &hpb_lu_info); 2500 - if (ret) 2501 - goto out; 2502 - 2503 - hpb = ufshpb_alloc_hpb_lu(hba, sdev, &hba->ufshpb_dev, 2504 - &hpb_lu_info); 2505 - if (!hpb) 2506 - goto out; 2507 - 2508 - tot_active_srgn_pages += hpb_lu_info.max_active_rgns * 2509 - hpb->srgns_per_rgn * hpb->pages_per_srgn; 2510 - 2511 - out: 2512 - /* All LUs are initialized */ 2513 - if (atomic_dec_and_test(&hba->ufshpb_dev.slave_conf_cnt)) 2514 - ufshpb_hpb_lu_prepared(hba); 2515 - } 2516 - 2517 - static int ufshpb_init_mem_wq(struct ufs_hba *hba) 2518 - { 2519 - int ret; 2520 - unsigned int pool_size; 2521 - 2522 - ufshpb_mctx_cache = kmem_cache_create("ufshpb_mctx_cache", 2523 - sizeof(struct ufshpb_map_ctx), 2524 - 0, 0, NULL); 2525 - if (!ufshpb_mctx_cache) { 2526 - dev_err(hba->dev, "ufshpb: cannot init mctx cache\n"); 2527 - return -ENOMEM; 2528 - } 2529 - 2530 - pool_size = PAGE_ALIGN(ufshpb_host_map_kbytes * SZ_1K) / PAGE_SIZE; 2531 - dev_info(hba->dev, "%s:%d ufshpb_host_map_kbytes %u pool_size %u\n", 2532 - __func__, __LINE__, ufshpb_host_map_kbytes, pool_size); 2533 - 2534 - ufshpb_mctx_pool = mempool_create_slab_pool(pool_size, 2535 - ufshpb_mctx_cache); 2536 - if (!ufshpb_mctx_pool) { 2537 - dev_err(hba->dev, "ufshpb: cannot init mctx pool\n"); 2538 - ret = -ENOMEM; 2539 - goto release_mctx_cache; 2540 - } 2541 - 2542 - ufshpb_page_pool = mempool_create_page_pool(pool_size, 0); 2543 - if (!ufshpb_page_pool) { 2544 - dev_err(hba->dev, "ufshpb: cannot init page pool\n"); 2545 - ret = -ENOMEM; 2546 - goto release_mctx_pool; 2547 - } 2548 - 2549 - ufshpb_wq = alloc_workqueue("ufshpb-wq", 2550 - WQ_UNBOUND | WQ_MEM_RECLAIM, 0); 2551 - if (!ufshpb_wq) { 2552 - dev_err(hba->dev, "ufshpb: alloc workqueue failed\n"); 2553 - ret = -ENOMEM; 2554 - goto release_page_pool; 2555 - } 2556 - 2557 - return 0; 2558 - 2559 - release_page_pool: 2560 - mempool_destroy(ufshpb_page_pool); 2561 - release_mctx_pool: 2562 - mempool_destroy(ufshpb_mctx_pool); 2563 - release_mctx_cache: 2564 - kmem_cache_destroy(ufshpb_mctx_cache); 2565 - return ret; 2566 - } 2567 - 2568 - void ufshpb_get_geo_info(struct ufs_hba *hba, u8 *geo_buf) 2569 - { 2570 - struct ufshpb_dev_info *hpb_info = &hba->ufshpb_dev; 2571 - int max_active_rgns = 0; 2572 - int hpb_num_lu; 2573 - 2574 - hpb_num_lu = geo_buf[GEOMETRY_DESC_PARAM_HPB_NUMBER_LU]; 2575 - if (hpb_num_lu == 0) { 2576 - dev_err(hba->dev, "No HPB LU supported\n"); 2577 - hpb_info->hpb_disabled = true; 2578 - return; 2579 - } 2580 - 2581 - hpb_info->rgn_size = geo_buf[GEOMETRY_DESC_PARAM_HPB_REGION_SIZE]; 2582 - hpb_info->srgn_size = geo_buf[GEOMETRY_DESC_PARAM_HPB_SUBREGION_SIZE]; 2583 - max_active_rgns = get_unaligned_be16(geo_buf + 2584 - GEOMETRY_DESC_PARAM_HPB_MAX_ACTIVE_REGS); 2585 - 2586 - if (hpb_info->rgn_size == 0 || hpb_info->srgn_size == 0 || 2587 - max_active_rgns == 0) { 2588 - dev_err(hba->dev, "No HPB supported device\n"); 2589 - hpb_info->hpb_disabled = true; 2590 - return; 2591 - } 2592 - } 2593 - 2594 - void ufshpb_get_dev_info(struct ufs_hba *hba, u8 *desc_buf) 2595 - { 2596 - struct ufshpb_dev_info *hpb_dev_info = &hba->ufshpb_dev; 2597 - int version, ret; 2598 - int max_single_cmd; 2599 - 2600 - hpb_dev_info->control_mode = desc_buf[DEVICE_DESC_PARAM_HPB_CONTROL]; 2601 - 2602 - version = get_unaligned_be16(desc_buf + DEVICE_DESC_PARAM_HPB_VER); 2603 - if ((version != HPB_SUPPORT_VERSION) && 2604 - (version != HPB_SUPPORT_LEGACY_VERSION)) { 2605 - dev_err(hba->dev, "%s: HPB %x version is not supported.\n", 2606 - __func__, version); 2607 - hpb_dev_info->hpb_disabled = true; 2608 - return; 2609 - } 2610 - 2611 - if (version == HPB_SUPPORT_LEGACY_VERSION) 2612 - hpb_dev_info->is_legacy = true; 2613 - 2614 - /* 2615 - * Get the number of user logical unit to check whether all 2616 - * scsi_device finish initialization 2617 - */ 2618 - hpb_dev_info->num_lu = desc_buf[DEVICE_DESC_PARAM_NUM_LU]; 2619 - 2620 - if (hpb_dev_info->is_legacy) 2621 - return; 2622 - 2623 - ret = ufshcd_query_attr_retry(hba, UPIU_QUERY_OPCODE_READ_ATTR, 2624 - QUERY_ATTR_IDN_MAX_HPB_SINGLE_CMD, 0, 0, &max_single_cmd); 2625 - 2626 - if (ret) 2627 - hpb_dev_info->max_hpb_single_cmd = HPB_LEGACY_CHUNK_HIGH; 2628 - else 2629 - hpb_dev_info->max_hpb_single_cmd = min(max_single_cmd + 1, HPB_MULTI_CHUNK_HIGH); 2630 - } 2631 - 2632 - void ufshpb_init(struct ufs_hba *hba) 2633 - { 2634 - struct ufshpb_dev_info *hpb_dev_info = &hba->ufshpb_dev; 2635 - int try; 2636 - int ret; 2637 - 2638 - if (!ufshpb_is_allowed(hba) || !hba->dev_info.hpb_enabled) 2639 - return; 2640 - 2641 - if (ufshpb_init_mem_wq(hba)) { 2642 - hpb_dev_info->hpb_disabled = true; 2643 - return; 2644 - } 2645 - 2646 - atomic_set(&hpb_dev_info->slave_conf_cnt, hpb_dev_info->num_lu); 2647 - tot_active_srgn_pages = 0; 2648 - /* issue HPB reset query */ 2649 - for (try = 0; try < HPB_RESET_REQ_RETRIES; try++) { 2650 - ret = ufshcd_query_flag(hba, UPIU_QUERY_OPCODE_SET_FLAG, 2651 - QUERY_FLAG_IDN_HPB_RESET, 0, NULL); 2652 - if (!ret) 2653 - break; 2654 - } 2655 - } 2656 - 2657 - void ufshpb_remove(struct ufs_hba *hba) 2658 - { 2659 - mempool_destroy(ufshpb_page_pool); 2660 - mempool_destroy(ufshpb_mctx_pool); 2661 - kmem_cache_destroy(ufshpb_mctx_cache); 2662 - 2663 - destroy_workqueue(ufshpb_wq); 2664 - } 2665 - 2666 - module_param(ufshpb_host_map_kbytes, uint, 0644); 2667 - MODULE_PARM_DESC(ufshpb_host_map_kbytes, 2668 - "ufshpb host mapping memory kilo-bytes for ufshpb memory-pool");
-318
drivers/ufs/core/ufshpb.h
··· 1 - /* SPDX-License-Identifier: GPL-2.0 */ 2 - /* 3 - * Universal Flash Storage Host Performance Booster 4 - * 5 - * Copyright (C) 2017-2021 Samsung Electronics Co., Ltd. 6 - * 7 - * Authors: 8 - * Yongmyung Lee <ymhungry.lee@samsung.com> 9 - * Jinyoung Choi <j-young.choi@samsung.com> 10 - */ 11 - 12 - #ifndef _UFSHPB_H_ 13 - #define _UFSHPB_H_ 14 - 15 - /* hpb response UPIU macro */ 16 - #define HPB_RSP_NONE 0x0 17 - #define HPB_RSP_REQ_REGION_UPDATE 0x1 18 - #define HPB_RSP_DEV_RESET 0x2 19 - #define MAX_ACTIVE_NUM 2 20 - #define MAX_INACTIVE_NUM 2 21 - #define DEV_DATA_SEG_LEN 0x14 22 - #define DEV_SENSE_SEG_LEN 0x12 23 - #define DEV_DES_TYPE 0x80 24 - #define DEV_ADDITIONAL_LEN 0x10 25 - 26 - /* hpb map & entries macro */ 27 - #define HPB_RGN_SIZE_UNIT 512 28 - #define HPB_ENTRY_BLOCK_SIZE SZ_4K 29 - #define HPB_ENTRY_SIZE 0x8 30 - #define PINNED_NOT_SET U32_MAX 31 - 32 - /* hpb support chunk size */ 33 - #define HPB_LEGACY_CHUNK_HIGH 1 34 - #define HPB_MULTI_CHUNK_HIGH 255 35 - 36 - /* hpb vender defined opcode */ 37 - #define UFSHPB_READ 0xF8 38 - #define UFSHPB_READ_BUFFER 0xF9 39 - #define UFSHPB_READ_BUFFER_ID 0x01 40 - #define UFSHPB_WRITE_BUFFER 0xFA 41 - #define UFSHPB_WRITE_BUFFER_INACT_SINGLE_ID 0x01 42 - #define UFSHPB_WRITE_BUFFER_PREFETCH_ID 0x02 43 - #define UFSHPB_WRITE_BUFFER_INACT_ALL_ID 0x03 44 - #define HPB_WRITE_BUFFER_CMD_LENGTH 10 45 - #define MAX_HPB_READ_ID 0x7F 46 - #define HPB_READ_BUFFER_CMD_LENGTH 10 47 - #define LU_ENABLED_HPB_FUNC 0x02 48 - 49 - #define HPB_RESET_REQ_RETRIES 10 50 - #define HPB_MAP_REQ_RETRIES 5 51 - #define HPB_REQUEUE_TIME_MS 0 52 - 53 - #define HPB_SUPPORT_VERSION 0x200 54 - #define HPB_SUPPORT_LEGACY_VERSION 0x100 55 - 56 - enum UFSHPB_MODE { 57 - HPB_HOST_CONTROL, 58 - HPB_DEVICE_CONTROL, 59 - }; 60 - 61 - enum UFSHPB_STATE { 62 - HPB_INIT, 63 - HPB_PRESENT, 64 - HPB_SUSPEND, 65 - HPB_FAILED, 66 - HPB_RESET, 67 - }; 68 - 69 - enum HPB_RGN_STATE { 70 - HPB_RGN_INACTIVE, 71 - HPB_RGN_ACTIVE, 72 - /* pinned regions are always active */ 73 - HPB_RGN_PINNED, 74 - }; 75 - 76 - enum HPB_SRGN_STATE { 77 - HPB_SRGN_UNUSED, 78 - HPB_SRGN_INVALID, 79 - HPB_SRGN_VALID, 80 - HPB_SRGN_ISSUED, 81 - }; 82 - 83 - /** 84 - * struct ufshpb_lu_info - UFSHPB logical unit related info 85 - * @num_blocks: the number of logical block 86 - * @pinned_start: the start region number of pinned region 87 - * @num_pinned: the number of pinned regions 88 - * @max_active_rgns: maximum number of active regions 89 - */ 90 - struct ufshpb_lu_info { 91 - int num_blocks; 92 - int pinned_start; 93 - int num_pinned; 94 - int max_active_rgns; 95 - }; 96 - 97 - struct ufshpb_map_ctx { 98 - struct page **m_page; 99 - unsigned long *ppn_dirty; 100 - }; 101 - 102 - struct ufshpb_subregion { 103 - struct ufshpb_map_ctx *mctx; 104 - enum HPB_SRGN_STATE srgn_state; 105 - int rgn_idx; 106 - int srgn_idx; 107 - bool is_last; 108 - 109 - /* subregion reads - for host mode */ 110 - unsigned int reads; 111 - 112 - /* below information is used by rsp_list */ 113 - struct list_head list_act_srgn; 114 - }; 115 - 116 - struct ufshpb_region { 117 - struct ufshpb_lu *hpb; 118 - struct ufshpb_subregion *srgn_tbl; 119 - enum HPB_RGN_STATE rgn_state; 120 - int rgn_idx; 121 - int srgn_cnt; 122 - 123 - /* below information is used by rsp_list */ 124 - struct list_head list_inact_rgn; 125 - 126 - /* below information is used by lru */ 127 - struct list_head list_lru_rgn; 128 - unsigned long rgn_flags; 129 - #define RGN_FLAG_DIRTY 0 130 - #define RGN_FLAG_UPDATE 1 131 - 132 - /* region reads - for host mode */ 133 - spinlock_t rgn_lock; 134 - unsigned int reads; 135 - /* region "cold" timer - for host mode */ 136 - ktime_t read_timeout; 137 - unsigned int read_timeout_expiries; 138 - struct list_head list_expired_rgn; 139 - }; 140 - 141 - #define for_each_sub_region(rgn, i, srgn) \ 142 - for ((i) = 0; \ 143 - ((i) < (rgn)->srgn_cnt) && ((srgn) = &(rgn)->srgn_tbl[i]); \ 144 - (i)++) 145 - 146 - /** 147 - * struct ufshpb_req - HPB related request structure (write/read buffer) 148 - * @req: block layer request structure 149 - * @bio: bio for this request 150 - * @hpb: ufshpb_lu structure that related to 151 - * @list_req: ufshpb_req mempool list 152 - * @sense: store its sense data 153 - * @mctx: L2P map information 154 - * @rgn_idx: target region index 155 - * @srgn_idx: target sub-region index 156 - * @lun: target logical unit number 157 - * @m_page: L2P map information data for pre-request 158 - * @len: length of host-side cached L2P map in m_page 159 - * @lpn: start LPN of L2P map in m_page 160 - */ 161 - struct ufshpb_req { 162 - struct request *req; 163 - struct bio *bio; 164 - struct ufshpb_lu *hpb; 165 - struct list_head list_req; 166 - union { 167 - struct { 168 - struct ufshpb_map_ctx *mctx; 169 - unsigned int rgn_idx; 170 - unsigned int srgn_idx; 171 - unsigned int lun; 172 - } rb; 173 - struct { 174 - struct page *m_page; 175 - unsigned int len; 176 - unsigned long lpn; 177 - } wb; 178 - }; 179 - }; 180 - 181 - struct victim_select_info { 182 - struct list_head lh_lru_rgn; /* LRU list of regions */ 183 - int max_lru_active_cnt; /* supported hpb #region - pinned #region */ 184 - atomic_t active_cnt; 185 - }; 186 - 187 - /** 188 - * ufshpb_params - ufs hpb parameters 189 - * @requeue_timeout_ms - requeue threshold of wb command (0x2) 190 - * @activation_thld - min reads [IOs] to activate/update a region 191 - * @normalization_factor - shift right the region's reads 192 - * @eviction_thld_enter - min reads [IOs] for the entering region in eviction 193 - * @eviction_thld_exit - max reads [IOs] for the exiting region in eviction 194 - * @read_timeout_ms - timeout [ms] from the last read IO to the region 195 - * @read_timeout_expiries - amount of allowable timeout expireis 196 - * @timeout_polling_interval_ms - frequency in which timeouts are checked 197 - * @inflight_map_req - number of inflight map requests 198 - */ 199 - struct ufshpb_params { 200 - unsigned int requeue_timeout_ms; 201 - unsigned int activation_thld; 202 - unsigned int normalization_factor; 203 - unsigned int eviction_thld_enter; 204 - unsigned int eviction_thld_exit; 205 - unsigned int read_timeout_ms; 206 - unsigned int read_timeout_expiries; 207 - unsigned int timeout_polling_interval_ms; 208 - unsigned int inflight_map_req; 209 - }; 210 - 211 - struct ufshpb_stats { 212 - u64 hit_cnt; 213 - u64 miss_cnt; 214 - u64 rcmd_noti_cnt; 215 - u64 rcmd_active_cnt; 216 - u64 rcmd_inactive_cnt; 217 - u64 map_req_cnt; 218 - u64 pre_req_cnt; 219 - u64 umap_req_cnt; 220 - }; 221 - 222 - struct ufshpb_lu { 223 - int lun; 224 - struct scsi_device *sdev_ufs_lu; 225 - 226 - spinlock_t rgn_state_lock; /* for protect rgn/srgn state */ 227 - struct ufshpb_region *rgn_tbl; 228 - 229 - atomic_t hpb_state; 230 - 231 - spinlock_t rsp_list_lock; 232 - struct list_head lh_act_srgn; /* hold rsp_list_lock */ 233 - struct list_head lh_inact_rgn; /* hold rsp_list_lock */ 234 - 235 - /* pre request information */ 236 - struct ufshpb_req *pre_req; 237 - int num_inflight_pre_req; 238 - int throttle_pre_req; 239 - int num_inflight_map_req; /* hold param_lock */ 240 - spinlock_t param_lock; 241 - 242 - struct list_head lh_pre_req_free; 243 - int pre_req_max_tr_len; 244 - 245 - /* cached L2P map management worker */ 246 - struct work_struct map_work; 247 - 248 - /* for selecting victim */ 249 - struct victim_select_info lru_info; 250 - struct work_struct ufshpb_normalization_work; 251 - struct delayed_work ufshpb_read_to_work; 252 - unsigned long work_data_bits; 253 - #define TIMEOUT_WORK_RUNNING 0 254 - 255 - /* pinned region information */ 256 - u32 lu_pinned_start; 257 - u32 lu_pinned_end; 258 - 259 - /* HPB related configuration */ 260 - u32 rgns_per_lu; 261 - u32 srgns_per_lu; 262 - u32 last_srgn_entries; 263 - int srgns_per_rgn; 264 - u32 srgn_mem_size; 265 - u32 entries_per_rgn_mask; 266 - u32 entries_per_rgn_shift; 267 - u32 entries_per_srgn; 268 - u32 entries_per_srgn_mask; 269 - u32 entries_per_srgn_shift; 270 - u32 pages_per_srgn; 271 - 272 - bool is_hcm; 273 - 274 - struct ufshpb_stats stats; 275 - struct ufshpb_params params; 276 - 277 - struct kmem_cache *map_req_cache; 278 - struct kmem_cache *m_page_cache; 279 - 280 - struct list_head list_hpb_lu; 281 - }; 282 - 283 - struct ufs_hba; 284 - struct ufshcd_lrb; 285 - 286 - #ifndef CONFIG_SCSI_UFS_HPB 287 - static int ufshpb_prep(struct ufs_hba *hba, struct ufshcd_lrb *lrbp) { return 0; } 288 - static void ufshpb_rsp_upiu(struct ufs_hba *hba, struct ufshcd_lrb *lrbp) {} 289 - static void ufshpb_resume(struct ufs_hba *hba) {} 290 - static void ufshpb_suspend(struct ufs_hba *hba) {} 291 - static void ufshpb_toggle_state(struct ufs_hba *hba, enum UFSHPB_STATE src, enum UFSHPB_STATE dest) {} 292 - static void ufshpb_init(struct ufs_hba *hba) {} 293 - static void ufshpb_init_hpb_lu(struct ufs_hba *hba, struct scsi_device *sdev) {} 294 - static void ufshpb_destroy_lu(struct ufs_hba *hba, struct scsi_device *sdev) {} 295 - static void ufshpb_remove(struct ufs_hba *hba) {} 296 - static bool ufshpb_is_allowed(struct ufs_hba *hba) { return false; } 297 - static void ufshpb_get_geo_info(struct ufs_hba *hba, u8 *geo_buf) {} 298 - static void ufshpb_get_dev_info(struct ufs_hba *hba, u8 *desc_buf) {} 299 - static bool ufshpb_is_legacy(struct ufs_hba *hba) { return false; } 300 - #else 301 - int ufshpb_prep(struct ufs_hba *hba, struct ufshcd_lrb *lrbp); 302 - void ufshpb_rsp_upiu(struct ufs_hba *hba, struct ufshcd_lrb *lrbp); 303 - void ufshpb_resume(struct ufs_hba *hba); 304 - void ufshpb_suspend(struct ufs_hba *hba); 305 - void ufshpb_toggle_state(struct ufs_hba *hba, enum UFSHPB_STATE src, enum UFSHPB_STATE dest); 306 - void ufshpb_init(struct ufs_hba *hba); 307 - void ufshpb_init_hpb_lu(struct ufs_hba *hba, struct scsi_device *sdev); 308 - void ufshpb_destroy_lu(struct ufs_hba *hba, struct scsi_device *sdev); 309 - void ufshpb_remove(struct ufs_hba *hba); 310 - bool ufshpb_is_allowed(struct ufs_hba *hba); 311 - void ufshpb_get_geo_info(struct ufs_hba *hba, u8 *geo_buf); 312 - void ufshpb_get_dev_info(struct ufs_hba *hba, u8 *desc_buf); 313 - bool ufshpb_is_legacy(struct ufs_hba *hba); 314 - extern struct attribute_group ufs_sysfs_hpb_stat_group; 315 - extern struct attribute_group ufs_sysfs_hpb_param_group; 316 - #endif 317 - 318 - #endif /* End of Header */
+11 -16
drivers/ufs/host/cdns-pltfrm.c
··· 101 101 } 102 102 103 103 /** 104 - * cdns_ufs_set_hclkdiv() 105 - * Sets HCLKDIV register value based on the core_clk 104 + * cdns_ufs_set_hclkdiv() - set HCLKDIV register value based on the core_clk. 106 105 * @hba: host controller instance 107 106 * 108 - * Return zero for success and non-zero for failure 107 + * Return: zero for success and non-zero for failure. 109 108 */ 110 109 static int cdns_ufs_set_hclkdiv(struct ufs_hba *hba) 111 110 { ··· 142 143 } 143 144 144 145 /** 145 - * cdns_ufs_hce_enable_notify() 146 - * Called before and after HCE enable bit is set. 146 + * cdns_ufs_hce_enable_notify() - set HCLKDIV register 147 147 * @hba: host controller instance 148 148 * @status: notify stage (pre, post change) 149 149 * 150 - * Return zero for success and non-zero for failure 150 + * Return: zero for success and non-zero for failure. 151 151 */ 152 152 static int cdns_ufs_hce_enable_notify(struct ufs_hba *hba, 153 153 enum ufs_notify_change_status status) ··· 158 160 } 159 161 160 162 /** 161 - * cdns_ufs_hibern8_notify() 162 - * Called around hibern8 enter/exit. 163 + * cdns_ufs_hibern8_notify() - save and restore L4 attributes. 163 164 * @hba: host controller instance 164 165 * @cmd: UIC Command 165 166 * @status: notify stage (pre, post change) 166 - * 167 167 */ 168 168 static void cdns_ufs_hibern8_notify(struct ufs_hba *hba, enum uic_cmd_dme cmd, 169 169 enum ufs_notify_change_status status) ··· 173 177 } 174 178 175 179 /** 176 - * cdns_ufs_link_startup_notify() 177 - * Called before and after Link startup is carried out. 180 + * cdns_ufs_link_startup_notify() - handle link startup. 178 181 * @hba: host controller instance 179 182 * @status: notify stage (pre, post change) 180 183 * 181 - * Return zero for success and non-zero for failure 184 + * Return: zero for success and non-zero for failure. 182 185 */ 183 186 static int cdns_ufs_link_startup_notify(struct ufs_hba *hba, 184 187 enum ufs_notify_change_status status) ··· 207 212 * cdns_ufs_init - performs additional ufs initialization 208 213 * @hba: host controller instance 209 214 * 210 - * Returns status of initialization 215 + * Return: status of initialization. 211 216 */ 212 217 static int cdns_ufs_init(struct ufs_hba *hba) 213 218 { ··· 230 235 * cdns_ufs_m31_16nm_phy_initialization - performs m31 phy initialization 231 236 * @hba: host controller instance 232 237 * 233 - * Always returns 0 238 + * Return: 0 (success). 234 239 */ 235 240 static int cdns_ufs_m31_16nm_phy_initialization(struct ufs_hba *hba) 236 241 { ··· 279 284 * cdns_ufs_pltfrm_probe - probe routine of the driver 280 285 * @pdev: pointer to platform device handle 281 286 * 282 - * Return zero for success and non-zero for failure 287 + * Return: zero for success and non-zero for failure. 283 288 */ 284 289 static int cdns_ufs_pltfrm_probe(struct platform_device *pdev) 285 290 { ··· 303 308 * cdns_ufs_pltfrm_remove - removes the ufs driver 304 309 * @pdev: pointer to platform device handle 305 310 * 306 - * Always returns 0 311 + * Return: 0 (success). 307 312 */ 308 313 static int cdns_ufs_pltfrm_remove(struct platform_device *pdev) 309 314 {
+1 -1
drivers/ufs/host/tc-dwc-g210-pci.c
··· 51 51 * @pdev: pointer to PCI device handle 52 52 * @id: PCI device id 53 53 * 54 - * Returns 0 on success, non-zero value on failure 54 + * Return: 0 on success, non-zero value on failure. 55 55 */ 56 56 static int 57 57 tc_dwc_g210_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id)
+12 -20
drivers/ufs/host/tc-dwc-g210.c
··· 17 17 #include "tc-dwc-g210.h" 18 18 19 19 /** 20 - * tc_dwc_g210_setup_40bit_rmmi() 21 - * This function configures Synopsys TC specific atributes (40-bit RMMI) 20 + * tc_dwc_g210_setup_40bit_rmmi() - configure 40-bit RMMI. 22 21 * @hba: Pointer to drivers structure 23 22 * 24 - * Returns 0 on success or non-zero value on failure 23 + * Return: 0 on success or non-zero value on failure. 25 24 */ 26 25 static int tc_dwc_g210_setup_40bit_rmmi(struct ufs_hba *hba) 27 26 { ··· 80 81 } 81 82 82 83 /** 83 - * tc_dwc_g210_setup_20bit_rmmi_lane0() 84 - * This function configures Synopsys TC 20-bit RMMI Lane 0 84 + * tc_dwc_g210_setup_20bit_rmmi_lane0() - configure 20-bit RMMI Lane 0. 85 85 * @hba: Pointer to drivers structure 86 86 * 87 - * Returns 0 on success or non-zero value on failure 87 + * Return: 0 on success or non-zero value on failure. 88 88 */ 89 89 static int tc_dwc_g210_setup_20bit_rmmi_lane0(struct ufs_hba *hba) 90 90 { ··· 132 134 } 133 135 134 136 /** 135 - * tc_dwc_g210_setup_20bit_rmmi_lane1() 136 - * This function configures Synopsys TC 20-bit RMMI Lane 1 137 + * tc_dwc_g210_setup_20bit_rmmi_lane1() - configure 20-bit RMMI Lane 1. 137 138 * @hba: Pointer to drivers structure 138 139 * 139 - * Returns 0 on success or non-zero value on failure 140 + * Return: 0 on success or non-zero value on failure. 140 141 */ 141 142 static int tc_dwc_g210_setup_20bit_rmmi_lane1(struct ufs_hba *hba) 142 143 { ··· 208 211 } 209 212 210 213 /** 211 - * tc_dwc_g210_setup_20bit_rmmi() 212 - * This function configures Synopsys TC specific atributes (20-bit RMMI) 214 + * tc_dwc_g210_setup_20bit_rmmi() - configure 20-bit RMMI. 213 215 * @hba: Pointer to drivers structure 214 216 * 215 - * Returns 0 on success or non-zero value on failure 217 + * Return: 0 on success or non-zero value on failure. 216 218 */ 217 219 static int tc_dwc_g210_setup_20bit_rmmi(struct ufs_hba *hba) 218 220 { ··· 247 251 } 248 252 249 253 /** 250 - * tc_dwc_g210_config_40_bit() 251 - * This function configures Local (host) Synopsys 40-bit TC specific attributes 252 - * 254 + * tc_dwc_g210_config_40_bit() - configure 40-bit TC specific attributes. 253 255 * @hba: Pointer to drivers structure 254 256 * 255 - * Returns 0 on success non-zero value on failure 257 + * Return: 0 on success non-zero value on failure. 256 258 */ 257 259 int tc_dwc_g210_config_40_bit(struct ufs_hba *hba) 258 260 { ··· 277 283 EXPORT_SYMBOL(tc_dwc_g210_config_40_bit); 278 284 279 285 /** 280 - * tc_dwc_g210_config_20_bit() 281 - * This function configures Local (host) Synopsys 20-bit TC specific attributes 282 - * 286 + * tc_dwc_g210_config_20_bit() - configure 20-bit TC specific attributes. 283 287 * @hba: Pointer to drivers structure 284 288 * 285 - * Returns 0 on success non-zero value on failure 289 + * Return: 0 on success non-zero value on failure. 286 290 */ 287 291 int tc_dwc_g210_config_20_bit(struct ufs_hba *hba) 288 292 {
+2
drivers/ufs/host/ti-j721e-ufs.c
··· 81 81 { }, 82 82 }; 83 83 84 + MODULE_DEVICE_TABLE(of, ti_j721e_ufs_of_match); 85 + 84 86 static struct platform_driver ti_j721e_ufs_driver = { 85 87 .probe = ti_j721e_ufs_probe, 86 88 .remove = ti_j721e_ufs_remove,
+175 -5
drivers/ufs/host/ufs-mediatek.c
··· 14 14 #include <linux/of.h> 15 15 #include <linux/of_address.h> 16 16 #include <linux/of_device.h> 17 + #include <linux/of_platform.h> 17 18 #include <linux/phy/phy.h> 18 19 #include <linux/platform_device.h> 19 20 #include <linux/pm_qos.h> ··· 28 27 #include <ufs/unipro.h> 29 28 #include "ufs-mediatek.h" 30 29 30 + static int ufs_mtk_config_mcq(struct ufs_hba *hba, bool irq); 31 + 31 32 #define CREATE_TRACE_POINTS 32 33 #include "ufs-mediatek-trace.h" 34 + #undef CREATE_TRACE_POINTS 35 + 36 + #define MAX_SUPP_MAC 64 37 + #define MCQ_QUEUE_OFFSET(c) ((((c) >> 16) & 0xFF) * 0x200) 33 38 34 39 static const struct ufs_dev_quirk ufs_mtk_dev_fixups[] = { 35 40 { .wmanufacturerid = UFS_ANY_VENDOR, ··· 666 659 * @on: If true, enable clocks else disable them. 667 660 * @status: PRE_CHANGE or POST_CHANGE notify 668 661 * 669 - * Returns 0 on success, non-zero on failure. 662 + * Return: 0 on success, non-zero on failure. 670 663 */ 671 664 static int ufs_mtk_setup_clocks(struct ufs_hba *hba, bool on, 672 665 enum ufs_notify_change_status status) ··· 847 840 } 848 841 } 849 842 843 + static void ufs_mtk_init_mcq_irq(struct ufs_hba *hba) 844 + { 845 + struct ufs_mtk_host *host = ufshcd_get_variant(hba); 846 + struct platform_device *pdev; 847 + int i; 848 + int irq; 849 + 850 + host->mcq_nr_intr = UFSHCD_MAX_Q_NR; 851 + pdev = container_of(hba->dev, struct platform_device, dev); 852 + 853 + for (i = 0; i < host->mcq_nr_intr; i++) { 854 + /* irq index 0 is legacy irq, sq/cq irq start from index 1 */ 855 + irq = platform_get_irq(pdev, i + 1); 856 + if (irq < 0) { 857 + host->mcq_intr_info[i].irq = MTK_MCQ_INVALID_IRQ; 858 + goto failed; 859 + } 860 + host->mcq_intr_info[i].hba = hba; 861 + host->mcq_intr_info[i].irq = irq; 862 + dev_info(hba->dev, "get platform mcq irq: %d, %d\n", i, irq); 863 + } 864 + 865 + return; 866 + failed: 867 + /* invalidate irq info */ 868 + for (i = 0; i < host->mcq_nr_intr; i++) 869 + host->mcq_intr_info[i].irq = MTK_MCQ_INVALID_IRQ; 870 + 871 + host->mcq_nr_intr = 0; 872 + } 873 + 850 874 /** 851 875 * ufs_mtk_init - find other essential mmio bases 852 876 * @hba: host controller instance ··· 885 847 * Binds PHY with controller and powers up PHY enabling clocks 886 848 * and regulators. 887 849 * 888 - * Returns -EPROBE_DEFER if binding fails, returns negative error 850 + * Return: -EPROBE_DEFER if binding fails, returns negative error 889 851 * on phy power up failure and returns zero on success. 890 852 */ 891 853 static int ufs_mtk_init(struct ufs_hba *hba) ··· 913 875 914 876 /* Initialize host capability */ 915 877 ufs_mtk_init_host_caps(hba); 878 + 879 + ufs_mtk_init_mcq_irq(hba); 916 880 917 881 err = ufs_mtk_bind_mphy(hba); 918 882 if (err) ··· 1213 1173 else 1214 1174 return err; 1215 1175 1216 - err = ufshcd_make_hba_operational(hba); 1176 + if (!hba->mcq_enabled) { 1177 + err = ufshcd_make_hba_operational(hba); 1178 + } else { 1179 + ufs_mtk_config_mcq(hba, false); 1180 + ufshcd_mcq_make_queues_operational(hba); 1181 + ufshcd_mcq_config_mac(hba, hba->nutrs); 1182 + /* Enable MCQ mode */ 1183 + ufshcd_writel(hba, ufshcd_readl(hba, REG_UFS_MEM_CFG) | 0x1, 1184 + REG_UFS_MEM_CFG); 1185 + } 1186 + 1217 1187 if (err) 1218 1188 return err; 1219 1189 ··· 1547 1497 return 0; 1548 1498 } 1549 1499 1500 + static int ufs_mtk_get_hba_mac(struct ufs_hba *hba) 1501 + { 1502 + return MAX_SUPP_MAC; 1503 + } 1504 + 1505 + static int ufs_mtk_op_runtime_config(struct ufs_hba *hba) 1506 + { 1507 + struct ufshcd_mcq_opr_info_t *opr; 1508 + int i; 1509 + 1510 + hba->mcq_opr[OPR_SQD].offset = REG_UFS_MTK_SQD; 1511 + hba->mcq_opr[OPR_SQIS].offset = REG_UFS_MTK_SQIS; 1512 + hba->mcq_opr[OPR_CQD].offset = REG_UFS_MTK_CQD; 1513 + hba->mcq_opr[OPR_CQIS].offset = REG_UFS_MTK_CQIS; 1514 + 1515 + for (i = 0; i < OPR_MAX; i++) { 1516 + opr = &hba->mcq_opr[i]; 1517 + opr->stride = REG_UFS_MCQ_STRIDE; 1518 + opr->base = hba->mmio_base + opr->offset; 1519 + } 1520 + 1521 + return 0; 1522 + } 1523 + 1524 + static int ufs_mtk_mcq_config_resource(struct ufs_hba *hba) 1525 + { 1526 + struct ufs_mtk_host *host = ufshcd_get_variant(hba); 1527 + 1528 + /* fail mcq initialization if interrupt is not filled properly */ 1529 + if (!host->mcq_nr_intr) { 1530 + dev_info(hba->dev, "IRQs not ready. MCQ disabled."); 1531 + return -EINVAL; 1532 + } 1533 + 1534 + hba->mcq_base = hba->mmio_base + MCQ_QUEUE_OFFSET(hba->mcq_capabilities); 1535 + return 0; 1536 + } 1537 + 1538 + static irqreturn_t ufs_mtk_mcq_intr(int irq, void *__intr_info) 1539 + { 1540 + struct ufs_mtk_mcq_intr_info *mcq_intr_info = __intr_info; 1541 + struct ufs_hba *hba = mcq_intr_info->hba; 1542 + struct ufs_hw_queue *hwq; 1543 + u32 events; 1544 + int qid = mcq_intr_info->qid; 1545 + 1546 + hwq = &hba->uhq[qid]; 1547 + 1548 + events = ufshcd_mcq_read_cqis(hba, qid); 1549 + if (events) 1550 + ufshcd_mcq_write_cqis(hba, events, qid); 1551 + 1552 + if (events & UFSHCD_MCQ_CQIS_TAIL_ENT_PUSH_STS) 1553 + ufshcd_mcq_poll_cqe_lock(hba, hwq); 1554 + 1555 + return IRQ_HANDLED; 1556 + } 1557 + 1558 + static int ufs_mtk_config_mcq_irq(struct ufs_hba *hba) 1559 + { 1560 + struct ufs_mtk_host *host = ufshcd_get_variant(hba); 1561 + u32 irq, i; 1562 + int ret; 1563 + 1564 + for (i = 0; i < host->mcq_nr_intr; i++) { 1565 + irq = host->mcq_intr_info[i].irq; 1566 + if (irq == MTK_MCQ_INVALID_IRQ) { 1567 + dev_err(hba->dev, "invalid irq. %d\n", i); 1568 + return -ENOPARAM; 1569 + } 1570 + 1571 + host->mcq_intr_info[i].qid = i; 1572 + ret = devm_request_irq(hba->dev, irq, ufs_mtk_mcq_intr, 0, UFSHCD, 1573 + &host->mcq_intr_info[i]); 1574 + 1575 + dev_dbg(hba->dev, "request irq %d intr %s\n", irq, ret ? "failed" : ""); 1576 + 1577 + if (ret) { 1578 + dev_err(hba->dev, "Cannot request irq %d\n", ret); 1579 + return ret; 1580 + } 1581 + } 1582 + 1583 + return 0; 1584 + } 1585 + 1586 + static int ufs_mtk_config_mcq(struct ufs_hba *hba, bool irq) 1587 + { 1588 + struct ufs_mtk_host *host = ufshcd_get_variant(hba); 1589 + int ret = 0; 1590 + 1591 + if (!host->mcq_set_intr) { 1592 + /* Disable irq option register */ 1593 + ufshcd_rmwl(hba, MCQ_INTR_EN_MSK, 0, REG_UFS_MMIO_OPT_CTRL_0); 1594 + 1595 + if (irq) { 1596 + ret = ufs_mtk_config_mcq_irq(hba); 1597 + if (ret) 1598 + return ret; 1599 + } 1600 + 1601 + host->mcq_set_intr = true; 1602 + } 1603 + 1604 + ufshcd_rmwl(hba, MCQ_AH8, MCQ_AH8, REG_UFS_MMIO_OPT_CTRL_0); 1605 + ufshcd_rmwl(hba, MCQ_INTR_EN_MSK, MCQ_MULTI_INTR_EN, REG_UFS_MMIO_OPT_CTRL_0); 1606 + 1607 + return 0; 1608 + } 1609 + 1610 + static int ufs_mtk_config_esi(struct ufs_hba *hba) 1611 + { 1612 + return ufs_mtk_config_mcq(hba, true); 1613 + } 1614 + 1550 1615 /* 1551 1616 * struct ufs_hba_mtk_vops - UFS MTK specific variant operations 1552 1617 * ··· 1685 1520 .event_notify = ufs_mtk_event_notify, 1686 1521 .config_scaling_param = ufs_mtk_config_scaling_param, 1687 1522 .clk_scale_notify = ufs_mtk_clk_scale_notify, 1523 + /* mcq vops */ 1524 + .get_hba_mac = ufs_mtk_get_hba_mac, 1525 + .op_runtime_config = ufs_mtk_op_runtime_config, 1526 + .mcq_config_resource = ufs_mtk_mcq_config_resource, 1527 + .config_esi = ufs_mtk_config_esi, 1688 1528 }; 1689 1529 1690 1530 /** 1691 1531 * ufs_mtk_probe - probe routine of the driver 1692 1532 * @pdev: pointer to Platform device handle 1693 1533 * 1694 - * Return zero for success and non-zero for failure 1534 + * Return: zero for success and non-zero for failure. 1695 1535 */ 1696 1536 static int ufs_mtk_probe(struct platform_device *pdev) 1697 1537 { ··· 1736 1566 1737 1567 out: 1738 1568 if (err) 1739 - dev_info(dev, "probe failed %d\n", err); 1569 + dev_err(dev, "probe failed %d\n", err); 1740 1570 1741 1571 of_node_put(reset_node); 1742 1572 return err;
+33
drivers/ufs/host/ufs-mediatek.h
··· 11 11 #include <linux/soc/mediatek/mtk_sip_svc.h> 12 12 13 13 /* 14 + * MCQ define and struct 15 + */ 16 + #define UFSHCD_MAX_Q_NR 8 17 + #define MTK_MCQ_INVALID_IRQ 0xFFFF 18 + 19 + /* REG_UFS_MMIO_OPT_CTRL_0 160h */ 20 + #define EHS_EN BIT(0) 21 + #define PFM_IMPV BIT(1) 22 + #define MCQ_MULTI_INTR_EN BIT(2) 23 + #define MCQ_CMB_INTR_EN BIT(3) 24 + #define MCQ_AH8 BIT(4) 25 + 26 + #define MCQ_INTR_EN_MSK (MCQ_MULTI_INTR_EN | MCQ_CMB_INTR_EN) 27 + 28 + /* 14 29 * Vendor specific UFSHCI Registers 15 30 */ 16 31 #define REG_UFS_XOUFS_CTRL 0x140 17 32 #define REG_UFS_REFCLK_CTRL 0x144 33 + #define REG_UFS_MMIO_OPT_CTRL_0 0x160 18 34 #define REG_UFS_EXTREG 0x2100 19 35 #define REG_UFS_MPHYCTRL 0x2200 20 36 #define REG_UFS_MTK_IP_VER 0x2240 ··· 41 25 #define REG_UFS_DEBUG_SEL_B1 0x22D4 42 26 #define REG_UFS_DEBUG_SEL_B2 0x22D8 43 27 #define REG_UFS_DEBUG_SEL_B3 0x22DC 28 + 29 + #define REG_UFS_MTK_SQD 0x2800 30 + #define REG_UFS_MTK_SQIS 0x2814 31 + #define REG_UFS_MTK_CQD 0x281C 32 + #define REG_UFS_MTK_CQIS 0x2824 33 + 34 + #define REG_UFS_MCQ_STRIDE 0x30 44 35 45 36 /* 46 37 * Ref-clk control ··· 159 136 u8 major; 160 137 }; 161 138 139 + struct ufs_mtk_mcq_intr_info { 140 + struct ufs_hba *hba; 141 + u32 irq; 142 + u8 qid; 143 + }; 144 + 162 145 struct ufs_mtk_host { 163 146 struct phy *mphy; 164 147 struct pm_qos_request pm_qos_req; ··· 184 155 u16 ref_clk_ungating_wait_us; 185 156 u16 ref_clk_gating_wait_us; 186 157 u32 ip_ver; 158 + 159 + bool mcq_set_intr; 160 + int mcq_nr_intr; 161 + struct ufs_mtk_mcq_intr_info mcq_intr_info[UFSHCD_MAX_Q_NR]; 187 162 }; 188 163 189 164 /*
+153 -21
drivers/ufs/host/ufs-qcom.c
··· 7 7 #include <linux/time.h> 8 8 #include <linux/clk.h> 9 9 #include <linux/delay.h> 10 + #include <linux/interconnect.h> 10 11 #include <linux/module.h> 11 12 #include <linux/of.h> 12 13 #include <linux/platform_device.h> ··· 45 44 TSTBUS_WRAPPER, 46 45 TSTBUS_UNIPRO, 47 46 TSTBUS_MAX, 47 + }; 48 + 49 + #define QCOM_UFS_MAX_GEAR 4 50 + #define QCOM_UFS_MAX_LANE 2 51 + 52 + enum { 53 + MODE_MIN, 54 + MODE_PWM, 55 + MODE_HS_RA, 56 + MODE_HS_RB, 57 + MODE_MAX, 58 + }; 59 + 60 + static const struct __ufs_qcom_bw_table { 61 + u32 mem_bw; 62 + u32 cfg_bw; 63 + } ufs_qcom_bw_table[MODE_MAX + 1][QCOM_UFS_MAX_GEAR + 1][QCOM_UFS_MAX_LANE + 1] = { 64 + [MODE_MIN][0][0] = { 0, 0 }, /* Bandwidth values in KB/s */ 65 + [MODE_PWM][UFS_PWM_G1][UFS_LANE_1] = { 922, 1000 }, 66 + [MODE_PWM][UFS_PWM_G2][UFS_LANE_1] = { 1844, 1000 }, 67 + [MODE_PWM][UFS_PWM_G3][UFS_LANE_1] = { 3688, 1000 }, 68 + [MODE_PWM][UFS_PWM_G4][UFS_LANE_1] = { 7376, 1000 }, 69 + [MODE_PWM][UFS_PWM_G1][UFS_LANE_2] = { 1844, 1000 }, 70 + [MODE_PWM][UFS_PWM_G2][UFS_LANE_2] = { 3688, 1000 }, 71 + [MODE_PWM][UFS_PWM_G3][UFS_LANE_2] = { 7376, 1000 }, 72 + [MODE_PWM][UFS_PWM_G4][UFS_LANE_2] = { 14752, 1000 }, 73 + [MODE_HS_RA][UFS_HS_G1][UFS_LANE_1] = { 127796, 1000 }, 74 + [MODE_HS_RA][UFS_HS_G2][UFS_LANE_1] = { 255591, 1000 }, 75 + [MODE_HS_RA][UFS_HS_G3][UFS_LANE_1] = { 1492582, 102400 }, 76 + [MODE_HS_RA][UFS_HS_G4][UFS_LANE_1] = { 2915200, 204800 }, 77 + [MODE_HS_RA][UFS_HS_G1][UFS_LANE_2] = { 255591, 1000 }, 78 + [MODE_HS_RA][UFS_HS_G2][UFS_LANE_2] = { 511181, 1000 }, 79 + [MODE_HS_RA][UFS_HS_G3][UFS_LANE_2] = { 1492582, 204800 }, 80 + [MODE_HS_RA][UFS_HS_G4][UFS_LANE_2] = { 2915200, 409600 }, 81 + [MODE_HS_RB][UFS_HS_G1][UFS_LANE_1] = { 149422, 1000 }, 82 + [MODE_HS_RB][UFS_HS_G2][UFS_LANE_1] = { 298189, 1000 }, 83 + [MODE_HS_RB][UFS_HS_G3][UFS_LANE_1] = { 1492582, 102400 }, 84 + [MODE_HS_RB][UFS_HS_G4][UFS_LANE_1] = { 2915200, 204800 }, 85 + [MODE_HS_RB][UFS_HS_G1][UFS_LANE_2] = { 298189, 1000 }, 86 + [MODE_HS_RB][UFS_HS_G2][UFS_LANE_2] = { 596378, 1000 }, 87 + [MODE_HS_RB][UFS_HS_G3][UFS_LANE_2] = { 1492582, 204800 }, 88 + [MODE_HS_RB][UFS_HS_G4][UFS_LANE_2] = { 2915200, 409600 }, 89 + [MODE_MAX][0][0] = { 7643136, 307200 }, 48 90 }; 49 91 50 92 static struct ufs_qcom_host *ufs_qcom_hosts[MAX_UFS_QCOM_HOSTS]; ··· 529 485 } 530 486 531 487 /* 532 - * Returns zero for success and non-zero in case of a failure 488 + * Return: zero for success and non-zero in case of a failure. 533 489 */ 534 490 static int ufs_qcom_cfg_timers(struct ufs_hba *hba, u32 gear, 535 491 u32 hs, u32 rate, bool update_link_startup_timer) ··· 833 789 } 834 790 } 835 791 792 + static int ufs_qcom_icc_set_bw(struct ufs_qcom_host *host, u32 mem_bw, u32 cfg_bw) 793 + { 794 + struct device *dev = host->hba->dev; 795 + int ret; 796 + 797 + ret = icc_set_bw(host->icc_ddr, 0, mem_bw); 798 + if (ret < 0) { 799 + dev_err(dev, "failed to set bandwidth request: %d\n", ret); 800 + return ret; 801 + } 802 + 803 + ret = icc_set_bw(host->icc_cpu, 0, cfg_bw); 804 + if (ret < 0) { 805 + dev_err(dev, "failed to set bandwidth request: %d\n", ret); 806 + return ret; 807 + } 808 + 809 + return 0; 810 + } 811 + 812 + static struct __ufs_qcom_bw_table ufs_qcom_get_bw_table(struct ufs_qcom_host *host) 813 + { 814 + struct ufs_pa_layer_attr *p = &host->dev_req_params; 815 + int gear = max_t(u32, p->gear_rx, p->gear_tx); 816 + int lane = max_t(u32, p->lane_rx, p->lane_tx); 817 + 818 + if (ufshcd_is_hs_mode(p)) { 819 + if (p->hs_rate == PA_HS_MODE_B) 820 + return ufs_qcom_bw_table[MODE_HS_RB][gear][lane]; 821 + else 822 + return ufs_qcom_bw_table[MODE_HS_RA][gear][lane]; 823 + } else { 824 + return ufs_qcom_bw_table[MODE_PWM][gear][lane]; 825 + } 826 + } 827 + 828 + static int ufs_qcom_icc_update_bw(struct ufs_qcom_host *host) 829 + { 830 + struct __ufs_qcom_bw_table bw_table; 831 + 832 + bw_table = ufs_qcom_get_bw_table(host); 833 + 834 + return ufs_qcom_icc_set_bw(host, bw_table.mem_bw, bw_table.cfg_bw); 835 + } 836 + 836 837 static int ufs_qcom_pwr_change_notify(struct ufs_hba *hba, 837 838 enum ufs_notify_change_status status, 838 839 struct ufs_pa_layer_attr *dev_max_params, ··· 940 851 /* cache the power mode parameters to use internally */ 941 852 memcpy(&host->dev_req_params, 942 853 dev_req_params, sizeof(*dev_req_params)); 854 + 855 + ufs_qcom_icc_update_bw(host); 943 856 944 857 /* disable the device ref clock if entered PWM mode */ 945 858 if (ufshcd_is_hs_mode(&hba->pwr_info) && ··· 1055 964 * @on: If true, enable clocks else disable them. 1056 965 * @status: PRE_CHANGE or POST_CHANGE notify 1057 966 * 1058 - * Returns 0 on success, non-zero on failure. 967 + * Return: 0 on success, non-zero on failure. 1059 968 */ 1060 969 static int ufs_qcom_setup_clocks(struct ufs_hba *hba, bool on, 1061 970 enum ufs_notify_change_status status) ··· 1072 981 1073 982 switch (status) { 1074 983 case PRE_CHANGE: 1075 - if (!on) { 984 + if (on) { 985 + ufs_qcom_icc_update_bw(host); 986 + } else { 1076 987 if (!ufs_qcom_is_link_active(hba)) { 1077 988 /* disable device ref_clk */ 1078 989 ufs_qcom_dev_ref_clk_ctrl(host, false); ··· 1086 993 /* enable the device ref clock for HS mode*/ 1087 994 if (ufshcd_is_hs_mode(&hba->pwr_info)) 1088 995 ufs_qcom_dev_ref_clk_ctrl(host, true); 996 + } else { 997 + ufs_qcom_icc_set_bw(host, ufs_qcom_bw_table[MODE_MIN][0][0].mem_bw, 998 + ufs_qcom_bw_table[MODE_MIN][0][0].cfg_bw); 1089 999 } 1090 1000 break; 1091 1001 } ··· 1127 1031 .deassert = ufs_qcom_reset_deassert, 1128 1032 }; 1129 1033 1034 + static int ufs_qcom_icc_init(struct ufs_qcom_host *host) 1035 + { 1036 + struct device *dev = host->hba->dev; 1037 + int ret; 1038 + 1039 + host->icc_ddr = devm_of_icc_get(dev, "ufs-ddr"); 1040 + if (IS_ERR(host->icc_ddr)) 1041 + return dev_err_probe(dev, PTR_ERR(host->icc_ddr), 1042 + "failed to acquire interconnect path\n"); 1043 + 1044 + host->icc_cpu = devm_of_icc_get(dev, "cpu-ufs"); 1045 + if (IS_ERR(host->icc_cpu)) 1046 + return dev_err_probe(dev, PTR_ERR(host->icc_cpu), 1047 + "failed to acquire interconnect path\n"); 1048 + 1049 + /* 1050 + * Set Maximum bandwidth vote before initializing the UFS controller and 1051 + * device. Ideally, a minimal interconnect vote would suffice for the 1052 + * initialization, but a max vote would allow faster initialization. 1053 + */ 1054 + ret = ufs_qcom_icc_set_bw(host, ufs_qcom_bw_table[MODE_MAX][0][0].mem_bw, 1055 + ufs_qcom_bw_table[MODE_MAX][0][0].cfg_bw); 1056 + if (ret < 0) 1057 + return dev_err_probe(dev, ret, "failed to set bandwidth request\n"); 1058 + 1059 + return 0; 1060 + } 1061 + 1130 1062 /** 1131 1063 * ufs_qcom_init - bind phy with controller 1132 1064 * @hba: host controller instance ··· 1162 1038 * Binds PHY with controller and powers up PHY enabling clocks 1163 1039 * and regulators. 1164 1040 * 1165 - * Returns -EPROBE_DEFER if binding fails, returns negative error 1041 + * Return: -EPROBE_DEFER if binding fails, returns negative error 1166 1042 * on phy power up failure and returns zero on success. 1167 1043 */ 1168 1044 static int ufs_qcom_init(struct ufs_hba *hba) ··· 1208 1084 goto out_variant_clear; 1209 1085 } 1210 1086 } 1087 + 1088 + err = ufs_qcom_icc_init(host); 1089 + if (err) 1090 + goto out_variant_clear; 1211 1091 1212 1092 host->device_reset = devm_gpiod_get_optional(dev, "reset", 1213 1093 GPIOD_OUT_HIGH); ··· 1382 1254 struct ufs_pa_layer_attr *dev_req_params = &host->dev_req_params; 1383 1255 int err = 0; 1384 1256 1257 + /* check the host controller state before sending hibern8 cmd */ 1258 + if (!ufshcd_is_hba_active(hba)) 1259 + return 0; 1260 + 1385 1261 if (status == PRE_CHANGE) { 1386 1262 err = ufshcd_uic_hibern8_enter(hba); 1387 1263 if (err) ··· 1414 1282 dev_req_params->pwr_rx, 1415 1283 dev_req_params->hs_rate, 1416 1284 false); 1285 + ufs_qcom_icc_update_bw(host); 1417 1286 ufshcd_uic_hibern8_exit(hba); 1418 1287 } 1419 1288 ··· 1616 1483 struct devfreq_simple_ondemand_data *d) 1617 1484 { 1618 1485 p->polling_ms = 60; 1486 + p->timer = DEVFREQ_TIMER_DELAYED; 1619 1487 d->upthreshold = 70; 1620 1488 d->downdifferential = 5; 1621 1489 } ··· 1777 1643 ufshcd_mcq_config_esi(hba, msg); 1778 1644 } 1779 1645 1780 - static irqreturn_t ufs_qcom_mcq_esi_handler(int irq, void *__hba) 1646 + static irqreturn_t ufs_qcom_mcq_esi_handler(int irq, void *data) 1781 1647 { 1782 - struct ufs_hba *hba = __hba; 1783 - struct ufs_qcom_host *host = ufshcd_get_variant(hba); 1784 - u32 id = irq - host->esi_base; 1648 + struct msi_desc *desc = data; 1649 + struct device *dev = msi_desc_to_dev(desc); 1650 + struct ufs_hba *hba = dev_get_drvdata(dev); 1651 + u32 id = desc->msi_index; 1785 1652 struct ufs_hw_queue *hwq = &hba->uhq[id]; 1786 1653 1787 1654 ufshcd_mcq_write_cqis(hba, 0x1, id); ··· 1800 1665 1801 1666 if (host->esi_enabled) 1802 1667 return 0; 1803 - else if (host->esi_base < 0) 1804 - return -EINVAL; 1805 1668 1806 1669 /* 1807 1670 * 1. We only handle CQs as of now. ··· 1808 1675 nr_irqs = hba->nr_hw_queues - hba->nr_queues[HCTX_TYPE_POLL]; 1809 1676 ret = platform_msi_domain_alloc_irqs(hba->dev, nr_irqs, 1810 1677 ufs_qcom_write_msi_msg); 1811 - if (ret) 1678 + if (ret) { 1679 + dev_err(hba->dev, "Failed to request Platform MSI %d\n", ret); 1812 1680 goto out; 1681 + } 1813 1682 1683 + msi_lock_descs(hba->dev); 1814 1684 msi_for_each_desc(desc, hba->dev, MSI_DESC_ALL) { 1815 - if (!desc->msi_index) 1816 - host->esi_base = desc->irq; 1817 - 1818 1685 ret = devm_request_irq(hba->dev, desc->irq, 1819 1686 ufs_qcom_mcq_esi_handler, 1820 - IRQF_SHARED, "qcom-mcq-esi", hba); 1687 + IRQF_SHARED, "qcom-mcq-esi", desc); 1821 1688 if (ret) { 1822 1689 dev_err(hba->dev, "%s: Fail to request IRQ for %d, err = %d\n", 1823 1690 __func__, desc->irq, ret); ··· 1825 1692 break; 1826 1693 } 1827 1694 } 1695 + msi_unlock_descs(hba->dev); 1828 1696 1829 1697 if (ret) { 1830 1698 /* Rewind */ 1699 + msi_lock_descs(hba->dev); 1831 1700 msi_for_each_desc(desc, hba->dev, MSI_DESC_ALL) { 1832 1701 if (desc == failed_desc) 1833 1702 break; 1834 1703 devm_free_irq(hba->dev, desc->irq, hba); 1835 1704 } 1705 + msi_unlock_descs(hba->dev); 1836 1706 platform_msi_domain_free_irqs(hba->dev); 1837 1707 } else { 1838 1708 if (host->hw_ver.major == 6 && host->hw_ver.minor == 0 && ··· 1848 1712 } 1849 1713 1850 1714 out: 1851 - if (ret) { 1852 - host->esi_base = -1; 1853 - dev_warn(hba->dev, "Failed to request Platform MSI %d\n", ret); 1854 - } else { 1715 + if (!ret) 1855 1716 host->esi_enabled = true; 1856 - } 1857 1717 1858 1718 return ret; 1859 1719 } ··· 1889 1757 * ufs_qcom_probe - probe routine of the driver 1890 1758 * @pdev: pointer to Platform device handle 1891 1759 * 1892 - * Return zero for success and non-zero for failure 1760 + * Return: zero for success and non-zero for failure. 1893 1761 */ 1894 1762 static int ufs_qcom_probe(struct platform_device *pdev) 1895 1763 {
+3 -1
drivers/ufs/host/ufs-qcom.h
··· 206 206 struct clk *tx_l1_sync_clk; 207 207 bool is_lane_clks_enabled; 208 208 209 + struct icc_path *icc_ddr; 210 + struct icc_path *icc_cpu; 211 + 209 212 #ifdef CONFIG_SCSI_UFS_CRYPTO 210 213 struct qcom_ice *ice; 211 214 #endif ··· 229 226 230 227 u32 hs_gear; 231 228 232 - int esi_base; 233 229 bool esi_enabled; 234 230 }; 235 231
+1 -1
drivers/ufs/host/ufs-renesas.c
··· 12 12 #include <linux/kernel.h> 13 13 #include <linux/module.h> 14 14 #include <linux/of.h> 15 - #include <linux/of_device.h> 15 + #include <linux/platform_device.h> 16 16 #include <linux/pm_runtime.h> 17 17 #include <ufs/ufshcd.h> 18 18
+9 -13
drivers/ufs/host/ufshcd-dwc.c
··· 34 34 EXPORT_SYMBOL(ufshcd_dwc_dme_set_attrs); 35 35 36 36 /** 37 - * ufshcd_dwc_program_clk_div() 38 - * This function programs the clk divider value. This value is needed to 39 - * provide 1 microsecond tick to unipro layer. 37 + * ufshcd_dwc_program_clk_div() - program clock divider. 40 38 * @hba: Private Structure pointer 41 39 * @divider_val: clock divider value to be programmed 42 40 * ··· 45 47 } 46 48 47 49 /** 48 - * ufshcd_dwc_link_is_up() 49 - * Check if link is up 50 + * ufshcd_dwc_link_is_up() - check if link is up. 50 51 * @hba: private structure pointer 51 52 * 52 - * Returns 0 on success, non-zero value on failure 53 + * Return: 0 on success, non-zero value on failure. 53 54 */ 54 55 static int ufshcd_dwc_link_is_up(struct ufs_hba *hba) 55 56 { ··· 65 68 } 66 69 67 70 /** 68 - * ufshcd_dwc_connection_setup() 71 + * ufshcd_dwc_connection_setup() - configure unipro attributes. 72 + * @hba: pointer to drivers private data 73 + * 69 74 * This function configures both the local side (host) and the peer side 70 75 * (device) unipro attributes to establish the connection to application/ 71 76 * cport. ··· 75 76 * have this connection setup on reset. But invoking this function does no 76 77 * harm and should be fine even working with any ufs device. 77 78 * 78 - * @hba: pointer to drivers private data 79 - * 80 - * Returns 0 on success non-zero value on failure 79 + * Return: 0 on success non-zero value on failure. 81 80 */ 82 81 static int ufshcd_dwc_connection_setup(struct ufs_hba *hba) 83 82 { ··· 104 107 } 105 108 106 109 /** 107 - * ufshcd_dwc_link_startup_notify() 108 - * UFS Host DWC specific link startup sequence 110 + * ufshcd_dwc_link_startup_notify() - program clock divider. 109 111 * @hba: private structure pointer 110 112 * @status: Callback notify status 111 113 * 112 - * Returns 0 on success, non-zero value on failure 114 + * Return: 0 on success, non-zero value on failure. 113 115 */ 114 116 int ufshcd_dwc_link_startup_notify(struct ufs_hba *hba, 115 117 enum ufs_notify_change_status status)
+2 -1
drivers/ufs/host/ufshcd-pci.c
··· 524 524 * @pdev: pointer to PCI device handle 525 525 * @id: PCI device id 526 526 * 527 - * Returns 0 on success, non-zero value on failure 527 + * Return: 0 on success, non-zero value on failure. 528 528 */ 529 529 static int 530 530 ufshcd_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id) ··· 590 590 }; 591 591 592 592 static const struct pci_device_id ufshcd_pci_tbl[] = { 593 + { PCI_VENDOR_ID_REDHAT, 0x0013, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, 593 594 { PCI_VENDOR_ID_SAMSUNG, 0xC00C, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, 594 595 { PCI_VDEVICE(INTEL, 0x9DFA), (kernel_ulong_t)&ufs_intel_cnl_hba_vops }, 595 596 { PCI_VDEVICE(INTEL, 0x4B41), (kernel_ulong_t)&ufs_intel_ehl_hba_vops },
+8 -5
drivers/ufs/host/ufshcd-pltfrm.c
··· 166 166 * If any of the supplies are not defined it is assumed that they are always-on 167 167 * and hence return zero. If the property is defined but parsing is failed 168 168 * then return corresponding error. 169 + * 170 + * Return: 0 upon success; < 0 upon failure. 169 171 */ 170 172 static int ufshcd_parse_regulator_info(struct ufs_hba *hba) 171 173 { ··· 214 212 * @dev_max: pointer to device attributes 215 213 * @agreed_pwr: returned agreed attributes 216 214 * 217 - * Returns 0 on success, non-zero value on failure 215 + * Return: 0 on success, non-zero value on failure. 218 216 */ 219 217 int ufshcd_get_pwr_dev_param(const struct ufs_dev_params *pltfrm_param, 220 218 const struct ufs_pa_layer_attr *dev_max, ··· 307 305 void ufshcd_init_pwr_dev_param(struct ufs_dev_params *dev_param) 308 306 { 309 307 *dev_param = (struct ufs_dev_params){ 310 - .tx_lanes = 2, 311 - .rx_lanes = 2, 308 + .tx_lanes = UFS_LANE_2, 309 + .rx_lanes = UFS_LANE_2, 312 310 .hs_rx_gear = UFS_HS_G3, 313 311 .hs_tx_gear = UFS_HS_G3, 314 312 .pwm_rx_gear = UFS_PWM_G4, ··· 328 326 * @pdev: pointer to Platform device handle 329 327 * @vops: pointer to variant ops 330 328 * 331 - * Returns 0 on success, non-zero value on failure 329 + * Return: 0 on success, non-zero value on failure. 332 330 */ 333 331 int ufshcd_pltfrm_init(struct platform_device *pdev, 334 332 const struct ufs_hba_variant_ops *vops) ··· 375 373 376 374 err = ufshcd_init(hba, mmio_base, irq); 377 375 if (err) { 378 - dev_err(dev, "Initialization failed\n"); 376 + dev_err_probe(dev, err, "Initialization failed with error %d\n", 377 + err); 379 378 goto dealloc_host; 380 379 } 381 380
+2 -30
include/scsi/libsas.h
··· 23 23 24 24 struct block_device; 25 25 26 - enum sas_class { 27 - SAS, 28 - EXPANDER 29 - }; 30 - 31 26 enum sas_phy_role { 32 27 PHY_ROLE_NONE = 0, 33 28 PHY_ROLE_TARGET = 0x40, 34 29 PHY_ROLE_INITIATOR = 0x80, 35 - }; 36 - 37 - enum sas_phy_type { 38 - PHY_TYPE_PHYSICAL, 39 - PHY_TYPE_VIRTUAL 40 30 }; 41 31 42 32 /* The events are mnemonically described in sas_dump.c ··· 248 258 /* public: */ 249 259 int id; 250 260 251 - enum sas_class class; 252 261 u8 sas_addr[SAS_ADDR_SIZE]; 253 262 u8 attached_sas_addr[SAS_ADDR_SIZE]; 254 263 enum sas_protocol iproto; ··· 308 319 int enabled; /* must be set */ 309 320 310 321 int id; /* must be set */ 311 - enum sas_class class; 312 322 enum sas_protocol iproto; 313 323 enum sas_protocol tproto; 314 324 315 - enum sas_phy_type type; 316 325 enum sas_phy_role role; 317 326 enum sas_oob_mode oob_mode; 318 327 enum sas_linkrate linkrate; ··· 333 346 void *lldd_phy; /* not touched by the sas_class_code */ 334 347 }; 335 348 336 - struct scsi_core { 337 - struct Scsi_Host *shost; 338 - 339 - }; 340 - 341 349 enum sas_ha_state { 342 350 SAS_HA_REGISTERED, 343 351 SAS_HA_DRAINING, ··· 353 371 354 372 struct mutex disco_mutex; 355 373 356 - struct scsi_core core; 374 + struct Scsi_Host *shost; 357 375 358 376 /* public: */ 359 377 char *sas_ha_name; 360 378 struct device *dev; /* should be set */ 361 - struct module *lldd_module; /* should be set */ 362 379 363 380 struct workqueue_struct *event_q; 364 381 struct workqueue_struct *disco_q; ··· 525 544 struct host_to_dev_fis fis; 526 545 u8 atapi_packet[16]; /* 0 if not ATAPI task */ 527 546 528 - u8 retry_count; /* hardware retry, should be > 0 */ 529 - 530 547 u8 dma_xfer:1; /* PIO:0 or DMA:1 */ 531 548 u8 use_ncq:1; 532 - u8 set_affil_pol:1; 533 - u8 stp_affil_pol:1; 549 + u8 return_fis_on_success:1; 534 550 535 551 u8 device_control_reg_update:1; 536 552 ··· 560 582 }; 561 583 562 584 struct sas_ssp_task { 563 - u8 retry_count; /* hardware retry, should be > 0 */ 564 - 565 585 u8 LUN[8]; 566 - u8 enable_first_burst:1; 567 586 enum task_attribute task_attr; 568 - u8 task_prio; 569 587 struct scsi_cmnd *cmd; 570 588 }; 571 589 ··· 700 726 extern struct device_attribute dev_attr_phy_event_threshold; 701 727 702 728 int sas_discover_root_expander(struct domain_device *); 703 - 704 - void sas_init_ex_attr(void); 705 729 706 730 int sas_ex_revalidate_domain(struct domain_device *); 707 731
+1 -1
include/scsi/scsi_host.h
··· 769 769 extern struct Scsi_Host *scsi_host_get(struct Scsi_Host *); 770 770 extern int scsi_host_busy(struct Scsi_Host *shost); 771 771 extern void scsi_host_put(struct Scsi_Host *t); 772 - extern struct Scsi_Host *scsi_host_lookup(unsigned short); 772 + extern struct Scsi_Host *scsi_host_lookup(unsigned int hostnum); 773 773 extern const char *scsi_host_state_name(enum scsi_host_state); 774 774 extern void scsi_host_complete_all_commands(struct Scsi_Host *shost, 775 775 enum scsi_host_status status);
-1
include/scsi/scsi_transport_iscsi.h
··· 472 472 uint32_t iface_type, 473 473 uint32_t iface_num, int dd_size); 474 474 extern void iscsi_destroy_iface(struct iscsi_iface *iface); 475 - extern struct iscsi_iface *iscsi_lookup_iface(int handle); 476 475 extern char *iscsi_get_port_speed_name(struct Scsi_Host *shost); 477 476 extern char *iscsi_get_port_state_name(struct Scsi_Host *shost); 478 477 extern int iscsi_is_session_dev(const struct device *dev);
-4
include/target/iscsi/iscsi_target_core.h
··· 50 50 #define TA_LOGIN_TIMEOUT 15 51 51 #define TA_LOGIN_TIMEOUT_MAX 30 52 52 #define TA_LOGIN_TIMEOUT_MIN 5 53 - #define TA_NETIF_TIMEOUT 2 54 - #define TA_NETIF_TIMEOUT_MAX 15 55 - #define TA_NETIF_TIMEOUT_MIN 2 56 53 #define TA_GENERATE_NODE_ACLS 0 57 54 #define TA_DEFAULT_CMDSN_DEPTH 64 58 55 #define TA_DEFAULT_CMDSN_DEPTH_MAX 512 ··· 770 773 struct iscsi_tpg_attrib { 771 774 u32 authentication; 772 775 u32 login_timeout; 773 - u32 netif_timeout; 774 776 u32 generate_node_acls; 775 777 u32 cache_dynamic_acls; 776 778 u32 default_cmdsn_depth;
+49 -3
include/uapi/scsi/scsi_bsg_ufs.h
··· 8 8 #ifndef SCSI_BSG_UFS_H 9 9 #define SCSI_BSG_UFS_H 10 10 11 + #include <asm/byteorder.h> 11 12 #include <linux/types.h> 12 13 /* 13 14 * This file intended to be included by both kernel and user space ··· 41 40 * @dword_0: UPIU header DW-0 42 41 * @dword_1: UPIU header DW-1 43 42 * @dword_2: UPIU header DW-2 43 + * 44 + * @transaction_code: Type of request or response. See also enum 45 + * upiu_request_transaction and enum upiu_response_transaction. 46 + * @flags: UPIU flags. The meaning of individual flags depends on the 47 + * transaction code. 48 + * @lun: Logical unit number. 49 + * @task_tag: Task tag. 50 + * @iid: Initiator ID. 51 + * @command_set_type: 0 for SCSI command set; 1 for UFS specific. 52 + * @tm_function: Task management function in case of a task management request 53 + * UPIU. 54 + * @query_function: Query function in case of a query request UPIU. 55 + * @response: 0 for success; 1 for failure. 56 + * @status: SCSI status if this is the header of a response to a SCSI command. 57 + * @ehs_length: EHS length in units of 32 bytes. 58 + * @device_information: 59 + * @data_segment_length: data segment length. 44 60 */ 45 61 struct utp_upiu_header { 46 - __be32 dword_0; 47 - __be32 dword_1; 48 - __be32 dword_2; 62 + union { 63 + struct { 64 + __be32 dword_0; 65 + __be32 dword_1; 66 + __be32 dword_2; 67 + }; 68 + struct { 69 + __u8 transaction_code; 70 + __u8 flags; 71 + __u8 lun; 72 + __u8 task_tag; 73 + #if defined(__BIG_ENDIAN) 74 + __u8 iid: 4; 75 + __u8 command_set_type: 4; 76 + #elif defined(__LITTLE_ENDIAN) 77 + __u8 command_set_type: 4; 78 + __u8 iid: 4; 79 + #else 80 + #error 81 + #endif 82 + union { 83 + __u8 tm_function; 84 + __u8 query_function; 85 + }; 86 + __u8 response; 87 + __u8 status; 88 + __u8 ehs_length; 89 + __u8 device_information; 90 + __be16 data_segment_length; 91 + }; 92 + }; 49 93 }; 50 94 51 95 /**
+15 -75
include/ufs/ufs.h
··· 11 11 #ifndef _UFS_H 12 12 #define _UFS_H 13 13 14 - #include <linux/mutex.h> 14 + #include <linux/bitops.h> 15 15 #include <linux/types.h> 16 16 #include <uapi/scsi/scsi_bsg_ufs.h> 17 + 18 + /* 19 + * Using static_assert() is not allowed in UAPI header files. Hence the check 20 + * in this header file of the size of struct utp_upiu_header. 21 + */ 22 + static_assert(sizeof(struct utp_upiu_header) == 12); 17 23 18 24 #define GENERAL_UPIU_REQUEST_SIZE (sizeof(struct utp_upiu_req)) 19 25 #define QUERY_DESC_MAX_SIZE 255 ··· 29 23 (sizeof(struct utp_upiu_header))) 30 24 #define UFS_SENSE_SIZE 18 31 25 32 - #define UPIU_HEADER_DWORD(byte3, byte2, byte1, byte0)\ 33 - cpu_to_be32((byte3 << 24) | (byte2 << 16) |\ 34 - (byte1 << 8) | (byte0)) 35 26 /* 36 27 * UFS device may have standard LUs and LUN id could be from 0x00 to 37 28 * 0x7F. Standard LUs use "Peripheral Device Addressing Format". ··· 79 76 }; 80 77 81 78 /* UTP UPIU Transaction Codes Initiator to Target */ 82 - enum { 79 + enum upiu_request_transaction { 83 80 UPIU_TRANSACTION_NOP_OUT = 0x00, 84 81 UPIU_TRANSACTION_COMMAND = 0x01, 85 82 UPIU_TRANSACTION_DATA_OUT = 0x02, ··· 88 85 }; 89 86 90 87 /* UTP UPIU Transaction Codes Target to Initiator */ 91 - enum { 88 + enum upiu_response_transaction { 92 89 UPIU_TRANSACTION_NOP_IN = 0x20, 93 90 UPIU_TRANSACTION_RESPONSE = 0x21, 94 91 UPIU_TRANSACTION_DATA_IN = 0x22, ··· 103 100 UPIU_CMD_FLAGS_NONE = 0x00, 104 101 UPIU_CMD_FLAGS_WRITE = 0x20, 105 102 UPIU_CMD_FLAGS_READ = 0x40, 103 + }; 104 + 105 + /* UPIU response flags */ 106 + enum { 107 + UPIU_RSP_FLAG_UNDERFLOW = 0x20, 108 + UPIU_RSP_FLAG_OVERFLOW = 0x40, 106 109 }; 107 110 108 111 /* UPIU Task Attributes */ ··· 475 466 UPIU_COMMAND_SET_TYPE_QUERY = 0x2, 476 467 }; 477 468 478 - /* UTP Transfer Request Command Offset */ 479 - #define UPIU_COMMAND_TYPE_OFFSET 28 480 - 481 469 /* Offset of the response code in the UPIU header */ 482 470 #define UPIU_RSP_CODE_OFFSET 8 483 471 484 472 enum { 485 - MASK_SCSI_STATUS = 0xFF, 486 - MASK_TASK_RESPONSE = 0xFF00, 487 - MASK_RSP_UPIU_RESULT = 0xFFFF, 488 - MASK_QUERY_DATA_SEG_LEN = 0xFFFF, 489 - MASK_RSP_UPIU_DATA_SEG_LEN = 0xFFFF, 490 - MASK_RSP_EXCEPTION_EVENT = 0x10000, 491 473 MASK_TM_SERVICE_RESP = 0xFF, 492 - MASK_TM_FUNC = 0xFF, 493 474 }; 494 475 495 476 /* Task management service response */ ··· 515 516 u8 sense_data[UFS_SENSE_SIZE]; 516 517 }; 517 518 518 - struct ufshpb_active_field { 519 - __be16 active_rgn; 520 - __be16 active_srgn; 521 - }; 522 - #define HPB_ACT_FIELD_SIZE 4 523 - 524 - /** 525 - * struct utp_hpb_rsp - Response UPIU structure 526 - * @residual_transfer_count: Residual transfer count DW-3 527 - * @reserved1: Reserved double words DW-4 to DW-7 528 - * @sense_data_len: Sense data length DW-8 U16 529 - * @desc_type: Descriptor type of sense data 530 - * @additional_len: Additional length of sense data 531 - * @hpb_op: HPB operation type 532 - * @lun: LUN of response UPIU 533 - * @active_rgn_cnt: Active region count 534 - * @inactive_rgn_cnt: Inactive region count 535 - * @hpb_active_field: Recommended to read HPB region and subregion 536 - * @hpb_inactive_field: To be inactivated HPB region and subregion 537 - */ 538 - struct utp_hpb_rsp { 539 - __be32 residual_transfer_count; 540 - __be32 reserved1[4]; 541 - __be16 sense_data_len; 542 - u8 desc_type; 543 - u8 additional_len; 544 - u8 hpb_op; 545 - u8 lun; 546 - u8 active_rgn_cnt; 547 - u8 inactive_rgn_cnt; 548 - struct ufshpb_active_field hpb_active_field[2]; 549 - __be16 hpb_inactive_field[2]; 550 - }; 551 - #define UTP_HPB_RSP_SIZE 40 552 - 553 519 /** 554 520 * struct utp_upiu_rsp - general upiu response structure 555 521 * @header: UPIU header structure DW-0 to DW-2 ··· 525 561 struct utp_upiu_header header; 526 562 union { 527 563 struct utp_cmd_rsp sr; 528 - struct utp_hpb_rsp hr; 529 564 struct utp_upiu_query qr; 530 565 }; 531 - }; 532 - 533 - /** 534 - * struct ufs_query_req - parameters for building a query request 535 - * @query_func: UPIU header query function 536 - * @upiu_req: the query request data 537 - */ 538 - struct ufs_query_req { 539 - u8 query_func; 540 - struct utp_upiu_query upiu_req; 541 - }; 542 - 543 - /** 544 - * struct ufs_query_resp - UPIU QUERY 545 - * @response: device response code 546 - * @upiu_res: query response data 547 - */ 548 - struct ufs_query_res { 549 - u8 response; 550 - struct utp_upiu_query upiu_res; 551 566 }; 552 567 553 568 /* ··· 563 620 u32 clk_gating_wait_us; 564 621 /* Stores the depth of queue in UFS device */ 565 622 u8 bqueuedepth; 566 - 567 - /* UFS HPB related flag */ 568 - bool hpb_enabled; 569 623 570 624 /* UFS WB related flags */ 571 625 bool wb_enabled;
-6
include/ufs/ufs_quirks.h
··· 107 107 */ 108 108 #define UFS_DEVICE_QUIRK_DELAY_AFTER_LPM (1 << 11) 109 109 110 - /* 111 - * Some UFS devices require L2P entry should be swapped before being sent to the 112 - * UFS device for HPB READ command. 113 - */ 114 - #define UFS_DEVICE_QUIRK_SWAP_L2P_ENTRY_FOR_HPB_READ (1 << 12) 115 - 116 110 #endif /* UFS_QUIRKS_H_ */
+24 -36
include/ufs/ufshcd.h
··· 20 20 #include <linux/pm_runtime.h> 21 21 #include <linux/dma-direction.h> 22 22 #include <scsi/scsi_device.h> 23 + #include <scsi/scsi_host.h> 23 24 #include <ufs/unipro.h> 24 25 #include <ufs/ufs.h> 25 26 #include <ufs/ufs_quirks.h> ··· 200 199 #endif 201 200 202 201 bool req_abort_skip; 202 + }; 203 + 204 + /** 205 + * struct ufs_query_req - parameters for building a query request 206 + * @query_func: UPIU header query function 207 + * @upiu_req: the query request data 208 + */ 209 + struct ufs_query_req { 210 + u8 query_func; 211 + struct utp_upiu_query upiu_req; 212 + }; 213 + 214 + /** 215 + * struct ufs_query_resp - UPIU QUERY 216 + * @response: device response code 217 + * @upiu_res: query response data 218 + */ 219 + struct ufs_query_res { 220 + struct utp_upiu_query upiu_res; 203 221 }; 204 222 205 223 /** ··· 729 709 u32 wb_flush_threshold; 730 710 }; 731 711 732 - #ifdef CONFIG_SCSI_UFS_HPB 733 - /** 734 - * struct ufshpb_dev_info - UFSHPB device related info 735 - * @num_lu: the number of user logical unit to check whether all lu finished 736 - * initialization 737 - * @rgn_size: device reported HPB region size 738 - * @srgn_size: device reported HPB sub-region size 739 - * @slave_conf_cnt: counter to check all lu finished initialization 740 - * @hpb_disabled: flag to check if HPB is disabled 741 - * @max_hpb_single_cmd: device reported bMAX_DATA_SIZE_FOR_SINGLE_CMD value 742 - * @is_legacy: flag to check HPB 1.0 743 - * @control_mode: either host or device 744 - */ 745 - struct ufshpb_dev_info { 746 - int num_lu; 747 - int rgn_size; 748 - int srgn_size; 749 - atomic_t slave_conf_cnt; 750 - bool hpb_disabled; 751 - u8 max_hpb_single_cmd; 752 - bool is_legacy; 753 - u8 control_mode; 754 - }; 755 - #endif 756 - 757 712 struct ufs_hba_monitor { 758 713 unsigned long chunk_size; 759 714 ··· 889 894 * @rpm_dev_flush_recheck_work: used to suspend from RPM (runtime power 890 895 * management) after the UFS device has finished a WriteBooster buffer 891 896 * flush or auto BKOP. 892 - * @ufshpb_dev: information related to HPB (Host Performance Booster). 893 897 * @monitor: statistics about UFS commands 894 898 * @crypto_capabilities: Content of crypto capabilities register (0x100) 895 899 * @crypto_cap_array: Array of crypto capabilities ··· 1043 1049 struct device bsg_dev; 1044 1050 struct request_queue *bsg_queue; 1045 1051 struct delayed_work rpm_dev_flush_recheck_work; 1046 - 1047 - #ifdef CONFIG_SCSI_UFS_HPB 1048 - struct ufshpb_dev_info ufshpb_dev; 1049 - #endif 1050 1052 1051 1053 struct ufs_hba_monitor monitor; 1052 1054 ··· 1244 1254 void ufshcd_update_evt_hist(struct ufs_hba *hba, u32 id, u32 val); 1245 1255 void ufshcd_hba_stop(struct ufs_hba *hba); 1246 1256 void ufshcd_schedule_eh_work(struct ufs_hba *hba); 1257 + void ufshcd_mcq_config_mac(struct ufs_hba *hba, u32 max_active_cmds); 1258 + u32 ufshcd_mcq_read_cqis(struct ufs_hba *hba, int i); 1247 1259 void ufshcd_mcq_write_cqis(struct ufs_hba *hba, u32 val, int i); 1248 1260 unsigned long ufshcd_mcq_poll_cqe_lock(struct ufs_hba *hba, 1249 1261 struct ufs_hw_queue *hwq); 1262 + void ufshcd_mcq_make_queues_operational(struct ufs_hba *hba); 1250 1263 void ufshcd_mcq_enable_esi(struct ufs_hba *hba); 1251 1264 void ufshcd_mcq_config_esi(struct ufs_hba *hba, struct msi_msg *msg); 1252 1265 ··· 1376 1383 1377 1384 int ufshcd_send_uic_cmd(struct ufs_hba *hba, struct uic_command *uic_cmd); 1378 1385 1379 - int ufshcd_exec_raw_upiu_cmd(struct ufs_hba *hba, 1380 - struct utp_upiu_req *req_upiu, 1381 - struct utp_upiu_req *rsp_upiu, 1382 - int msgcode, 1383 - u8 *desc_buff, int *buff_len, 1384 - enum query_opcode desc_op); 1385 1386 int ufshcd_advanced_rpmb_req_handler(struct ufs_hba *hba, struct utp_upiu_req *req_upiu, 1386 1387 struct utp_upiu_req *rsp_upiu, struct ufs_ehs *ehs_req, 1387 1388 struct ufs_ehs *ehs_rsp, int sg_cnt, ··· 1385 1398 int ufshcd_suspend_prepare(struct device *dev); 1386 1399 int __ufshcd_suspend_prepare(struct device *dev, bool rpm_ok_for_spm); 1387 1400 void ufshcd_resume_complete(struct device *dev); 1401 + bool ufshcd_is_hba_active(struct ufs_hba *hba); 1388 1402 1389 1403 /* Wrapper functions for safely calling variant operations */ 1390 1404 static inline int ufshcd_vops_init(struct ufs_hba *hba)
+35 -16
include/ufs/ufshci.h
··· 11 11 #ifndef _UFSHCI_H 12 12 #define _UFSHCI_H 13 13 14 - #include <scsi/scsi_host.h> 14 + #include <linux/types.h> 15 + #include <ufs/ufs.h> 15 16 16 17 enum { 17 18 TASK_REQ_UPIU_SIZE_DWORDS = 8, ··· 127 126 }; 128 127 129 128 #define SQ_ICU_ERR_CODE_MASK GENMASK(7, 4) 130 - #define UPIU_COMMAND_TYPE_MASK GENMASK(31, 28) 131 129 #define UFS_MASK(mask, offset) ((mask) << (offset)) 132 130 133 131 /* UFS Version 08h */ ··· 438 438 UTP_SCSI_COMMAND = 0x00000000, 439 439 UTP_NATIVE_UFS_COMMAND = 0x10000000, 440 440 UTP_DEVICE_MANAGEMENT_FUNCTION = 0x20000000, 441 - UTP_REQ_DESC_INT_CMD = 0x01000000, 442 - UTP_REQ_DESC_CRYPTO_ENABLE_CMD = 0x00800000, 443 441 }; 444 442 445 443 /* UTP Transfer Request Data Direction (DD) */ 446 - enum { 447 - UTP_NO_DATA_TRANSFER = 0x00000000, 448 - UTP_HOST_TO_DEVICE = 0x02000000, 449 - UTP_DEVICE_TO_HOST = 0x04000000, 444 + enum utp_data_direction { 445 + UTP_NO_DATA_TRANSFER = 0, 446 + UTP_HOST_TO_DEVICE = 1, 447 + UTP_DEVICE_TO_HOST = 2, 450 448 }; 451 449 452 450 /* Overall command status values */ ··· 503 505 504 506 /** 505 507 * struct request_desc_header - Descriptor Header common to both UTRD and UTMRD 506 - * @dword0: Descriptor Header DW0 507 - * @dword1: Descriptor Header DW1 508 - * @dword2: Descriptor Header DW2 509 - * @dword3: Descriptor Header DW3 510 508 */ 511 509 struct request_desc_header { 512 - __le32 dword_0; 513 - __le32 dword_1; 514 - __le32 dword_2; 515 - __le32 dword_3; 510 + u8 cci; 511 + u8 ehs_length; 512 + #if defined(__BIG_ENDIAN) 513 + u8 enable_crypto:1; 514 + u8 reserved2:7; 515 + 516 + u8 command_type:4; 517 + u8 reserved1:1; 518 + u8 data_direction:2; 519 + u8 interrupt:1; 520 + #elif defined(__LITTLE_ENDIAN) 521 + u8 reserved2:7; 522 + u8 enable_crypto:1; 523 + 524 + u8 interrupt:1; 525 + u8 data_direction:2; 526 + u8 reserved1:1; 527 + u8 command_type:4; 528 + #else 529 + #error 530 + #endif 531 + 532 + __le32 dunl; 533 + u8 ocs; 534 + u8 cds; 535 + __le16 ldbc; 536 + __le32 dunu; 516 537 }; 538 + 539 + static_assert(sizeof(struct request_desc_header) == 16); 517 540 518 541 /** 519 542 * struct utp_transfer_req_desc - UTP Transfer Request Descriptor (UTRD)
+6
include/ufs/unipro.h
··· 230 230 UFS_HS_G5 /* HS Gear 5 */ 231 231 }; 232 232 233 + enum ufs_lanes { 234 + UFS_LANE_DONT_CHANGE, /* Don't change Lane */ 235 + UFS_LANE_1, /* Lane 1 (default for reset) */ 236 + UFS_LANE_2, /* Lane 2 */ 237 + }; 238 + 233 239 enum ufs_unipro_ver { 234 240 UFS_UNIPRO_VER_RESERVED = 0, 235 241 UFS_UNIPRO_VER_1_40 = 1, /* UniPro version 1.40 */