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

scsi: ufs: creates wrapper functions for vops

In order to simplify the code a set of wrapper functions is created
to test and call each of the variant operations.

Reviewed-by: Akinobu Mita <akinobu.mita@gmail.com>
Reviewed-by: Subhash Jadavani <subhashj@codeaurora.org>
Reviewed-by: Gilad Broner <gbroner@codeaurora.org>
Signed-off-by: Yaniv Gardi <ygardi@codeaurora.org>
Tested-by: Alim Akhtar <alim.akhtar@samsung.com>
Reviewed-by: Hannes Reinecke <hare@suse.de>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>

authored by

Yaniv Gardi and committed by
Martin K. Petersen
0263bcd0 1ce5898a

+137 -66
-1
drivers/scsi/ufs/ufs-qcom.c
··· 1049 1049 .suspend = ufs_qcom_suspend, 1050 1050 .resume = ufs_qcom_resume, 1051 1051 }; 1052 - EXPORT_SYMBOL(ufs_hba_qcom_vops); 1053 1052 1054 1053 MODULE_LICENSE("GPL v2");
+39 -65
drivers/scsi/ufs/ufshcd.c
··· 271 271 */ 272 272 static inline u32 ufshcd_get_ufs_version(struct ufs_hba *hba) 273 273 { 274 - if (hba->quirks & UFSHCD_QUIRK_BROKEN_UFS_HCI_VERSION) { 275 - if (hba->vops && hba->vops->get_ufs_hci_version) 276 - return hba->vops->get_ufs_hci_version(hba); 277 - } 274 + if (hba->quirks & UFSHCD_QUIRK_BROKEN_UFS_HCI_VERSION) 275 + return ufshcd_vops_get_ufs_hci_version(hba); 278 276 279 277 return ufshcd_readl(hba, REG_UFS_VERSION); 280 278 } ··· 2471 2473 dev_err(hba->dev, 2472 2474 "%s: power mode change failed %d\n", __func__, ret); 2473 2475 } else { 2474 - if (hba->vops && hba->vops->pwr_change_notify) 2475 - hba->vops->pwr_change_notify(hba, 2476 - POST_CHANGE, NULL, pwr_mode); 2476 + ufshcd_vops_pwr_change_notify(hba, POST_CHANGE, NULL, 2477 + pwr_mode); 2477 2478 2478 2479 memcpy(&hba->pwr_info, pwr_mode, 2479 2480 sizeof(struct ufs_pa_layer_attr)); ··· 2492 2495 struct ufs_pa_layer_attr final_params = { 0 }; 2493 2496 int ret; 2494 2497 2495 - if (hba->vops && hba->vops->pwr_change_notify) 2496 - hba->vops->pwr_change_notify(hba, 2497 - PRE_CHANGE, desired_pwr_mode, &final_params); 2498 - else 2498 + ret = ufshcd_vops_pwr_change_notify(hba, PRE_CHANGE, 2499 + desired_pwr_mode, &final_params); 2500 + 2501 + if (ret) 2499 2502 memcpy(&final_params, desired_pwr_mode, sizeof(final_params)); 2500 2503 2501 2504 ret = ufshcd_change_power_mode(hba, &final_params); ··· 2644 2647 /* UniPro link is disabled at this point */ 2645 2648 ufshcd_set_link_off(hba); 2646 2649 2647 - if (hba->vops && hba->vops->hce_enable_notify) 2648 - hba->vops->hce_enable_notify(hba, PRE_CHANGE); 2650 + ufshcd_vops_hce_enable_notify(hba, PRE_CHANGE); 2649 2651 2650 2652 /* start controller initialization sequence */ 2651 2653 ufshcd_hba_start(hba); ··· 2677 2681 /* enable UIC related interrupts */ 2678 2682 ufshcd_enable_intr(hba, UFSHCD_UIC_MASK); 2679 2683 2680 - if (hba->vops && hba->vops->hce_enable_notify) 2681 - hba->vops->hce_enable_notify(hba, POST_CHANGE); 2684 + ufshcd_vops_hce_enable_notify(hba, POST_CHANGE); 2682 2685 2683 2686 return 0; 2684 2687 } ··· 2730 2735 int retries = DME_LINKSTARTUP_RETRIES; 2731 2736 2732 2737 do { 2733 - if (hba->vops && hba->vops->link_startup_notify) 2734 - hba->vops->link_startup_notify(hba, PRE_CHANGE); 2738 + ufshcd_vops_link_startup_notify(hba, PRE_CHANGE); 2735 2739 2736 2740 ret = ufshcd_dme_link_startup(hba); 2737 2741 ··· 2761 2767 } 2762 2768 2763 2769 /* Include any host controller configuration via UIC commands */ 2764 - if (hba->vops && hba->vops->link_startup_notify) { 2765 - ret = hba->vops->link_startup_notify(hba, POST_CHANGE); 2766 - if (ret) 2767 - goto out; 2768 - } 2770 + ret = ufshcd_vops_link_startup_notify(hba, POST_CHANGE); 2771 + if (ret) 2772 + goto out; 2769 2773 2770 2774 ret = ufshcd_make_hba_operational(hba); 2771 2775 out: ··· 4570 4578 } 4571 4579 } 4572 4580 4573 - if (hba->vops && hba->vops->setup_clocks) 4574 - ret = hba->vops->setup_clocks(hba, on); 4581 + ret = ufshcd_vops_setup_clocks(hba, on); 4575 4582 out: 4576 4583 if (ret) { 4577 4584 list_for_each_entry(clki, head, list) { ··· 4636 4645 if (!hba->vops) 4637 4646 goto out; 4638 4647 4639 - if (hba->vops->init) { 4640 - err = hba->vops->init(hba); 4641 - if (err) 4642 - goto out; 4643 - } 4648 + err = ufshcd_vops_init(hba); 4649 + if (err) 4650 + goto out; 4644 4651 4645 - if (hba->vops->setup_regulators) { 4646 - err = hba->vops->setup_regulators(hba, true); 4647 - if (err) 4648 - goto out_exit; 4649 - } 4652 + err = ufshcd_vops_setup_regulators(hba, true); 4653 + if (err) 4654 + goto out_exit; 4650 4655 4651 4656 goto out; 4652 4657 4653 4658 out_exit: 4654 - if (hba->vops->exit) 4655 - hba->vops->exit(hba); 4659 + ufshcd_vops_exit(hba); 4656 4660 out: 4657 4661 if (err) 4658 4662 dev_err(hba->dev, "%s: variant %s init failed err %d\n", 4659 - __func__, hba->vops ? hba->vops->name : "", err); 4663 + __func__, ufshcd_get_var_name(hba), err); 4660 4664 return err; 4661 4665 } 4662 4666 ··· 4660 4674 if (!hba->vops) 4661 4675 return; 4662 4676 4663 - if (hba->vops->setup_clocks) 4664 - hba->vops->setup_clocks(hba, false); 4677 + ufshcd_vops_setup_clocks(hba, false); 4665 4678 4666 - if (hba->vops->setup_regulators) 4667 - hba->vops->setup_regulators(hba, false); 4679 + ufshcd_vops_setup_regulators(hba, false); 4668 4680 4669 - if (hba->vops->exit) 4670 - hba->vops->exit(hba); 4681 + ufshcd_vops_exit(hba); 4671 4682 } 4672 4683 4673 4684 static int ufshcd_hba_init(struct ufs_hba *hba) ··· 5041 5058 * vendor specific host controller register space call them before the 5042 5059 * host clocks are ON. 5043 5060 */ 5044 - if (hba->vops && hba->vops->suspend) { 5045 - ret = hba->vops->suspend(hba, pm_op); 5046 - if (ret) 5047 - goto set_link_active; 5048 - } 5061 + ret = ufshcd_vops_suspend(hba, pm_op); 5062 + if (ret) 5063 + goto set_link_active; 5049 5064 5050 - if (hba->vops && hba->vops->setup_clocks) { 5051 - ret = hba->vops->setup_clocks(hba, false); 5052 - if (ret) 5053 - goto vops_resume; 5054 - } 5065 + ret = ufshcd_vops_setup_clocks(hba, false); 5066 + if (ret) 5067 + goto vops_resume; 5055 5068 5056 5069 if (!ufshcd_is_link_active(hba)) 5057 5070 ufshcd_setup_clocks(hba, false); ··· 5058 5079 hba->clk_gating.state = CLKS_OFF; 5059 5080 /* 5060 5081 * Disable the host irq as host controller as there won't be any 5061 - * host controller trasanction expected till resume. 5082 + * host controller transaction expected till resume. 5062 5083 */ 5063 5084 ufshcd_disable_irq(hba); 5064 5085 /* Put the host controller in low power mode if possible */ ··· 5066 5087 goto out; 5067 5088 5068 5089 vops_resume: 5069 - if (hba->vops && hba->vops->resume) 5070 - hba->vops->resume(hba, pm_op); 5090 + ufshcd_vops_resume(hba, pm_op); 5071 5091 set_link_active: 5072 5092 ufshcd_vreg_set_hpm(hba); 5073 5093 if (ufshcd_is_link_hibern8(hba) && !ufshcd_uic_hibern8_exit(hba)) ··· 5122 5144 * vendor specific host controller register space call them when the 5123 5145 * host clocks are ON. 5124 5146 */ 5125 - if (hba->vops && hba->vops->resume) { 5126 - ret = hba->vops->resume(hba, pm_op); 5127 - if (ret) 5128 - goto disable_vreg; 5129 - } 5147 + ret = ufshcd_vops_resume(hba, pm_op); 5148 + if (ret) 5149 + goto disable_vreg; 5130 5150 5131 5151 if (ufshcd_is_link_hibern8(hba)) { 5132 5152 ret = ufshcd_uic_hibern8_exit(hba); ··· 5165 5189 set_old_link_state: 5166 5190 ufshcd_link_state_transition(hba, old_link_state, 0); 5167 5191 vendor_suspend: 5168 - if (hba->vops && hba->vops->suspend) 5169 - hba->vops->suspend(hba, pm_op); 5192 + ufshcd_vops_suspend(hba, pm_op); 5170 5193 disable_vreg: 5171 5194 ufshcd_vreg_set_lpm(hba); 5172 5195 disable_irq_and_vops_clks: ··· 5438 5463 dev_dbg(hba->dev, "%s: clk: %s, rate: %lu\n", __func__, 5439 5464 clki->name, clk_get_rate(clki->clk)); 5440 5465 } 5441 - if (hba->vops->clk_scale_notify) 5442 - hba->vops->clk_scale_notify(hba); 5466 + ufshcd_vops_clk_scale_notify(hba); 5443 5467 out: 5444 5468 return ret; 5445 5469 }
+98
drivers/scsi/ufs/ufshcd.h
··· 674 674 675 675 int ufshcd_hold(struct ufs_hba *hba, bool async); 676 676 void ufshcd_release(struct ufs_hba *hba); 677 + 678 + /* Wrapper functions for safely calling variant operations */ 679 + static inline const char *ufshcd_get_var_name(struct ufs_hba *hba) 680 + { 681 + if (hba->vops) 682 + return hba->vops->name; 683 + return ""; 684 + } 685 + 686 + static inline int ufshcd_vops_init(struct ufs_hba *hba) 687 + { 688 + if (hba->vops && hba->vops->init) 689 + return hba->vops->init(hba); 690 + 691 + return 0; 692 + } 693 + 694 + static inline void ufshcd_vops_exit(struct ufs_hba *hba) 695 + { 696 + if (hba->vops && hba->vops->exit) 697 + return hba->vops->exit(hba); 698 + } 699 + 700 + static inline u32 ufshcd_vops_get_ufs_hci_version(struct ufs_hba *hba) 701 + { 702 + if (hba->vops && hba->vops->get_ufs_hci_version) 703 + return hba->vops->get_ufs_hci_version(hba); 704 + 705 + return ufshcd_readl(hba, REG_UFS_VERSION); 706 + } 707 + 708 + static inline void ufshcd_vops_clk_scale_notify(struct ufs_hba *hba) 709 + { 710 + if (hba->vops && hba->vops->clk_scale_notify) 711 + return hba->vops->clk_scale_notify(hba); 712 + } 713 + 714 + static inline int ufshcd_vops_setup_clocks(struct ufs_hba *hba, bool on) 715 + { 716 + if (hba->vops && hba->vops->setup_clocks) 717 + return hba->vops->setup_clocks(hba, on); 718 + 719 + return 0; 720 + } 721 + 722 + static inline int ufshcd_vops_setup_regulators(struct ufs_hba *hba, bool status) 723 + { 724 + if (hba->vops && hba->vops->setup_regulators) 725 + return hba->vops->setup_regulators(hba, status); 726 + 727 + return 0; 728 + } 729 + 730 + static inline int ufshcd_vops_hce_enable_notify(struct ufs_hba *hba, 731 + bool status) 732 + { 733 + if (hba->vops && hba->vops->hce_enable_notify) 734 + return hba->vops->hce_enable_notify(hba, status); 735 + 736 + return 0; 737 + } 738 + static inline int ufshcd_vops_link_startup_notify(struct ufs_hba *hba, 739 + bool status) 740 + { 741 + if (hba->vops && hba->vops->link_startup_notify) 742 + return hba->vops->link_startup_notify(hba, status); 743 + 744 + return 0; 745 + } 746 + 747 + static inline int ufshcd_vops_pwr_change_notify(struct ufs_hba *hba, 748 + bool status, 749 + struct ufs_pa_layer_attr *dev_max_params, 750 + struct ufs_pa_layer_attr *dev_req_params) 751 + { 752 + if (hba->vops && hba->vops->pwr_change_notify) 753 + return hba->vops->pwr_change_notify(hba, status, 754 + dev_max_params, dev_req_params); 755 + 756 + return -ENOTSUPP; 757 + } 758 + 759 + static inline int ufshcd_vops_suspend(struct ufs_hba *hba, enum ufs_pm_op op) 760 + { 761 + if (hba->vops && hba->vops->suspend) 762 + return hba->vops->suspend(hba, op); 763 + 764 + return 0; 765 + } 766 + 767 + static inline int ufshcd_vops_resume(struct ufs_hba *hba, enum ufs_pm_op op) 768 + { 769 + if (hba->vops && hba->vops->resume) 770 + return hba->vops->resume(hba, op); 771 + 772 + return 0; 773 + } 774 + 677 775 #endif /* End of Header */