scsi: ufs: Put SCSI host after remove it
A message that is not in the archive (sent off-list or not yet received): [email protected]
PATCH v2 1/3 scsi: ufs: Put SCSI host after remove it
In ufshcd_remove(), after SCSI host is removed, put it once so that its resources can be released.
--- drivers/scsi/ufs/ufshcd.c | 1 + 1 file changed, 1 insertion(+)
drivers/scsi/ufs/ufshcd.c +1 -0
@@ -8251,6 +8251,7 @@ void ufshcd_remove(struct ufs_hba *hba)ufs_bsg_remove (hba);ufs_sysfs_remove_nodes (hba->dev);scsi_remove_host (hba->host); +scsi_host_put (hba->host);/* disable interrupts */ ufshcd_disable_intr (hba, hba->intr_mask);ufshcd_hba_stop (hba, true);
Signature · 2 lines
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project
Quoted 6 lines
In
ufshcd_remove(), after SCSI host is removed, put it once so that its resources can be released.Signed-off-by Can Guo <[email protected]>
This is not really part of this patchset, is it?
Quoted 19 lines
--- drivers/scsi/ufs/ufshcd.c | 1 + 1 file changed, 1 insertion(+)drivers/scsi/ufs/ufshcd.c index renamed from drivers/scsi/ufs/ufshcd.c +0
-0b5966fa..a86b0fd 100644
drivers/scsi/ufs/ufshcd.c +1
-1@@ -8251,6 +8251,7 @@ void ufshcd_remove(struct ufs_hba *hba)ufs_bsg_remove (hba);ufs_sysfs_remove_nodes (hba->dev);scsi_remove_host (hba->host); +scsi_host_put (hba->host);/* disable interrupts */ ufshcd_disable_intr (hba, hba->intr_mask);ufshcd_hba_stop (hba, true); --The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project
Quoted 8 lines · Avri Altman
Quoted 5 lines
In
ufshcd_remove(), after SCSI host is removed, put it once so that its resources can be released.Signed-off-by Can Guo <[email protected]>This is not really part of this patchset, is it?
Hi Avri,
I put this change in the same patchset due to
#1. The main patch has dependency on it
#2. Consider a scenario where platform driver is also compiled as a module, say ufs_qcom.ko.
In this case, we have two modules, ufs-qcom.ko and ufs-bsg.ko. If do
insmod ufs-qcom.ko
then rmmod ufs-qcom.ko and do insmod ufs-qcom.ko again, without this
change, because scsi
host was not release, the new scsi host will have a different host
number, meaning
hba->host->host_no will be 1, but not 0. Now if do insmod ufs-bsg.ko
now, the ufs-bsg dev
created in /dev/bsg/ will be ufs-bsg1, but not ufs-bsg0. If keep
trying these operations,
the ufs-bsg device's name will be messed up. This change make sure
after ufs-qcom.ko is removed
and installed back, its hba->host->host_no stays 0, so that ufs-bsg
device name stays same.
Thanks,
Can Guo.
Quoted 19 lines
Quoted 19 lines
--- drivers/scsi/ufs/ufshcd.c | 1 + 1 file changed, 1 insertion(+)drivers/scsi/ufs/ufshcd.c index renamed from drivers/scsi/ufs/ufshcd.c +0
-0b5966fa..a86b0fd 100644
drivers/scsi/ufs/ufshcd.c +1
-1@@ -8251,6 +8251,7 @@ void ufshcd_remove(struct ufs_hba *hba)ufs_bsg_remove (hba);ufs_sysfs_remove_nodes (hba->dev);scsi_remove_host (hba->host); +scsi_host_put (hba->host);/* disable interrupts */ ufshcd_disable_intr (hba, hba->intr_mask);ufshcd_hba_stop (hba, true); --The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project
A message that is not in the archive (sent off-list or not yet received): 0101016ef4a3e5f5-915372c8-5e1e-4db5-b3da-f97f7ca963e4-000000@us-west-2.amazonses.com
Quoted 23 lines · Avri Altman
Quoted 8 lines
Quoted 5 lines
In
ufshcd_remove(), after SCSI host is removed, put it once so that its resources can be released.Signed-off-by Can Guo <[email protected]>This is not really part of this patchset, is it?
Hi Avri,
I put this change in the same patchset due to #1. The main patch has dependency on it #2. Consider a scenario where platform driver is also compiled as a module, say ufs_qcom.ko.
In this case, we have two modules, ufs-qcom.ko and ufs-bsg.ko. If do insmod
ufs-qcom.ko
then rmmod ufs-qcom.ko and do insmod ufs-qcom.ko again, without this
change, because scsi
host was not release, the new scsi host will have a different host number,
meaning
Quoted 8 lines
hba->host->host_no will be 1, but not 0. Now if do insmod ufs-bsg.ko now,the ufs-bsg dev
created in/dev/bsg/will be ufs-bsg1, but not ufs-bsg0. If keep trying these
operations,
the ufs-bsg device's name will be messed up. This change make sure after ufs-
qcom.ko is removedand installed back, its hba->host->host_no stays 0, so that ufs-bsg devicename stays same.
Looks like we needed to manage the ufs-bsg nodes using an IDA, instead of host_no?
Quoted 24 lines
Thanks,
Can Guo.
Quoted 19 lines
Quoted 19 lines
--- drivers/scsi/ufs/ufshcd.c | 1 + 1 file changed, 1 insertion(+)drivers/scsi/ufs/ufshcd.c +1
-1@@ -8251,6 +8251,7 @@ void ufshcd_remove(struct ufs_hba *hba)ufs_bsg_remove (hba);ufs_sysfs_remove_nodes (hba->dev);scsi_remove_host (hba->host); +scsi_host_put (hba->host);/* disable interrupts */ ufshcd_disable_intr (hba, hba->intr_mask);ufshcd_hba_stop (hba, true); --The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project
Quoted 38 lines · Avri Altman
Quoted 35 lines · Avri Altman
Quoted 8 lines
Quoted 5 lines
In
ufshcd_remove(), after SCSI host is removed, put it once so that its resources can be released.Signed-off-by Can Guo <[email protected]>This is not really part of this patchset, is it?
Hi Avri,
I put this change in the same patchset due to #1. The main patch has dependency on it #2. Consider a scenario where platform driver is also compiled as a module, say ufs_qcom.ko.
In this case, we have two modules, ufs-qcom.ko and ufs-bsg.ko. If
do insmod
ufs-qcom.ko
then rmmod ufs-qcom.ko and do insmod ufs-qcom.ko again, without
this
change, because scsi
host was not release, the new scsi host will have a different
host number,
meaninghba->host->host_no will be 1, but not 0. Now if do insmodufs-bsg.ko now,
the ufs-bsg dev
created in/dev/bsg/will be ufs-bsg1, but not ufs-bsg0. If keep
trying these
operations,
the ufs-bsg device's name will be messed up. This change make
sure after ufs-
qcom.ko is removedQuoted 3 lines
and installed back, its hba->host->host_no stays 0, so thatufs-bsg device
name stays same.
Quoted 4 lines
Looks like we needed to manage the ufs-bsg nodes using an IDA, instead of
host_no?
Marking one ufs-bsg dev with host_no still has its advantage. If we have more than one hba host, we can find the right ufs-bsgX dev by reading the sg/sd/bsg device's host->host_unique_id (through SCSI_IOCTL_GET_IDLUN for example). But If ufs-bsg has its own ID, we will lost this "mapping".
Thanks,
Can Guo.
Quoted 24 lines
Quoted 24 lines
Thanks,
Can Guo.
Quoted 19 lines
Quoted 19 lines
--- drivers/scsi/ufs/ufshcd.c | 1 + 1 file changed, 1 insertion(+)drivers/scsi/ufs/ufshcd.c +1
-1@@ -8251,6 +8251,7 @@ void ufshcd_remove(struct ufs_hba *hba)ufs_bsg_remove (hba);ufs_sysfs_remove_nodes (hba->dev);scsi_remove_host (hba->host); +scsi_host_put (hba->host);/* disable interrupts */ ufshcd_disable_intr (hba, hba->intr_mask);ufshcd_hba_stop (hba, true); --The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project
A message that is not in the archive (sent off-list or not yet received): 0101016ef4c6065b-3e4428fc-71f8-40cf-a7fa-bc633a2b9fda-000000@us-west-2.amazonses.com
Quoted 38 lines · Avri Altman
Quoted 31 lines
Quoted 23 lines · Avri Altman
Quoted 8 lines
Quoted 5 lines
In
ufshcd_remove(), after SCSI host is removed, put it once so that its resources can be released.Signed-off-by Can Guo <[email protected]>This is not really part of this patchset, is it?
Hi Avri,
I put this change in the same patchset due to #1. The main patch has dependency on it #2. Consider a scenario where platform driver is also compiled as a module, say ufs_qcom.ko.
In this case, we have two modules, ufs-qcom.ko and ufs-bsg.ko.
If do insmod ufs-qcom.ko
then rmmod ufs-qcom.ko and do insmod ufs-qcom.ko again, without
this change, because scsi
host was not release, the new scsi host will have a different
host number, meaningQuoted 8 lines
hba->host->host_no will be 1, but not 0. Now if do insmodufs-bsg.ko now, the ufs-bsg dev
created in/dev/bsg/will be ufs-bsg1, but not ufs-bsg0. If keep
trying these operations,
the ufs-bsg device's name will be messed up. This change make
sure after ufs- qcom.ko is removedand installed back, its hba->host->host_no stays 0, so thatufs-bsg device name stays same.
Quoted 4 lines
Looks like we needed to manage the ufs-bsg nodes using an IDA, instead of
host_no?
Quoted 4 lines
Marking one ufs-bsg dev with
host_nostill has its advantage. If we have more than one hba host, we can find the right ufs-bsgX dev by reading the sg/sd/bsg device'shost->host_unique_id(throughSCSI_IOCTL_GET_IDLUNfor example). But If ufs-bsg has its own ID, we will lost this "mapping".
OK.
PATCH v2 2/3 scsi: ufs: Modulize ufs-bsg
In reply to a message not in the archiveIn order to improve the flexibility of ufs-bsg, modulizing it is a good choice. This change introduces tristate to ufs-bsg to allow users compile it as an external module.
--- drivers/scsi/ufs/Kconfig | 3 ++- drivers/scsi/ufs/Makefile | 2 +- drivers/scsi/ufs/ufs_bsg.c | 49 +++++++++++++++++++++++++++++++++++++++++++--- drivers/scsi/ufs/ufs_bsg.h | 8 -------- drivers/scsi/ufs/ufshcd.c | 36 ++++++++++++++++++++++++++++++---- drivers/scsi/ufs/ufshcd.h | 7 ++++++- 6 files changed, 87 insertions(+), 18 deletions(-)
drivers/scsi/ufs/Kconfig +2 -1
@@ -38,6 +38,7 @@ config SCSI_UFSHCD select PM_DEVFREQ select DEVFREQ_GOV_SIMPLE_ONDEMAND select NLS + select BLK_DEV_BSGLIB ---help--- This selects the support for UFS devices in Linux, say Y and make sure that you know the name of your UFS host adapter (the card
@@ -143,7 +144,7 @@ config SCSI_UFS_TI_J721E If unsure, say N. config SCSI_UFS_BSG - bool "Universal Flash Storage BSG device node" + tristate "Universal Flash Storage BSG device node" depends on SCSI_UFSHCD select BLK_DEV_BSGLIB help
drivers/scsi/ufs/Makefile +1 -1
@@ -6,7 +6,7 @@ obj-$(CONFIG_SCSI_UFS_CDNS_PLATFORM) += cdns-pltfrm.o obj-$(CONFIG_SCSI_UFS_QCOM) += ufs-qcom.o obj-$(CONFIG_SCSI_UFSHCD) += ufshcd-core.o ufshcd-core-y += ufshcd.o ufs-sysfs.o -ufshcd-core-$(CONFIG_SCSI_UFS_BSG) += ufs_bsg.o +obj-$(CONFIG_SCSI_UFS_BSG) += ufs_bsg.o obj-$(CONFIG_SCSI_UFSHCD_PCI) += ufshcd-pci.o obj-$(CONFIG_SCSI_UFSHCD_PLATFORM) += ufshcd-pltfrm.o obj-$(CONFIG_SCSI_UFS_HISI) += ufs-hisi.o
drivers/scsi/ufs/ufs_bsg.c +46 -3
85 lines not on this page · raw message
drivers/scsi/ufs/ufs_bsg.h +0 -8
@@ -12,12 +12,4 @@#include "ufshcd.h" #include "ufs.h" -#ifdef CONFIG_SCSI_UFS_BSG -void ufs_bsg_remove (struct ufs_hba *hba); -int ufs_bsg_probe (struct ufs_hba *hba); -#else -static inline void ufs_bsg_remove (struct ufs_hba *hba) {} -static inline int ufs_bsg_probe (struct ufs_hba *hba) {return 0 ; } -#endif -#endif /* UFS_BSG_H */
drivers/scsi/ufs/ufshcd.c +32 -4
@@ -108,6 +108,22 @@ 16, 4, buf, __len, false); \ }while (0 ) +static LIST_HEAD(ufs_hba_list); +static DEFINE_MUTEX (ufs_hba_list_lock); + +void ufshcd_get_hba_list_lock (struct list_head **list) +{ +mutex_lock (&ufs_hba_list_lock); + *list = &ufs_hba_list; +} +EXPORT_SYMBOL_GPL (ufshcd_get_hba_list_lock); + +void ufshcd_put_hba_list_unlock (void ) +{ +mutex_unlock (&ufs_hba_list_lock); +} +EXPORT_SYMBOL_GPL (ufshcd_put_hba_list_unlock); +int ufshcd_dump_regs (struct ufs_hba *hba,size_t offset,size_t len,const char *prefix) {
@@ -2093,6 +2109,7 @@ int ufshcd_send_uic_cmd(struct ufs_hba *hba, struct uic_command *uic_cmd)ufshcd_release (hba);return ret; } +EXPORT_SYMBOL_GPL (ufshcd_send_uic_cmd);/** * ufshcd_map_sg - Map scatter-gather list to prdt
@@ -6024,6 +6041,7 @@ int ufshcd_exec_raw_upiu_cmd(struct ufs_hba *hba,return err; } +EXPORT_SYMBOL_GPL (ufshcd_exec_raw_upiu_cmd);/** * ufshcd_eh_device_reset_handler - device reset handler registered to
@@ -7043,9 +7061,6 @@ static int ufshcd_probe_hba(struct ufs_hba *hba) } hba->clk_scaling.is_allowed = true; } - -ufs_bsg_probe (hba); -scsi_scan_host (hba->host);pm_runtime_put_sync (hba->dev); }
@@ -8248,7 +8263,16 @@ int ufshcd_shutdown(struct ufs_hba *hba)*/ void ufshcd_remove (struct ufs_hba *hba) { -ufs_bsg_remove (hba); +struct device *bsg_dev = hba->bsg_dev; + +mutex_lock (&ufs_hba_list_lock); +list_del (&hba->list); +if (hba->bsg_queue) { +bsg_remove_queue (hba->bsg_queue); +device_del (bsg_dev); +put_device (bsg_dev); + } +mutex_unlock (&ufs_hba_list_lock);ufs_sysfs_remove_nodes (hba->dev);scsi_remove_host (hba->host);scsi_host_put (hba->host);
@@ -8494,6 +8518,10 @@ int ufshcd_init(struct ufs_hba *hba, void __iomem *mmio_base, unsigned int irq)async_schedule (ufshcd_async_scan, hba);ufs_sysfs_add_nodes (hba->dev); +mutex_lock (&ufs_hba_list_lock); +list_add_tail (&hba->list, &ufs_hba_list); +mutex_unlock (&ufs_hba_list_lock); +return 0 ; out_remove_scsi_host:
drivers/scsi/ufs/ufshcd.h +6 -1
@@ -74,6 +74,9 @@struct ufs_hba ; +void ufshcd_get_hba_list_lock (struct list_head **list); +void ufshcd_put_hba_list_unlock (void ); +enum dev_cmd_type {DEV_CMD_TYPE_NOP =0x0 ,DEV_CMD_TYPE_QUERY =0x1 ,
@@ -473,6 +476,7 @@ struct ufs_stats {/** * struct ufs_hba - per adapter private structure +* @list: Anchored at ufs_hba_list * @mmio_base: UFSHCI base register address * @ucdl_base_addr: UFS Command Descriptor base address * @utrdl_base_addr: UTP Transfer Request Descriptor base address
@@ -527,6 +531,7 @@ struct ufs_stats {* @scsi_block_reqs_cnt: reference counting for scsi block requests */ struct ufs_hba { +struct list_head list;void __iomem *mmio_base;/* Virtual memory reference */
@@ -734,7 +739,7 @@ struct ufs_hba {struct ufs_desc_size desc_size;atomic_t scsi_block_reqs_cnt; -struct device bsg_dev; +struct device *bsg_dev;struct request_queue *bsg_queue; };
Signature · 2 lines
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project
Re: [PATCH v2 2/3] scsi: ufs: Modulize ufs-bsg
Quoted 3 lines · Can Guo
In order to improve the flexibility of ufs-bsg, modulizing it is a good choice. This change introduces tristate to ufs-bsg to allow users compile it as an external module.
Can you please elaborate on what this "flexibility" is and why it's a good thing?
Quoted 16 lines
Signed-off-by Can Guo <[email protected]>--- drivers/scsi/ufs/Kconfig | 3 ++- drivers/scsi/ufs/Makefile | 2 +- drivers/scsi/ufs/ufs_bsg.c | 49 +++++++++++++++++++++++++++++++++++++++++++--- drivers/scsi/ufs/ufs_bsg.h | 8 -------- drivers/scsi/ufs/ufshcd.c | 36 ++++++++++++++++++++++++++++++---- drivers/scsi/ufs/ufshcd.h | 7 ++++++- 6 files changed, 87 insertions(+), 18 deletions(-)drivers/scsi/ufs/Kconfig +0
-0
drivers/scsi/ufs/Kconfig config SCSI_UFSHCD · line 41
Quoted 4 lines
drivers/scsi/ufs/Kconfig +1
-0@@ -38,6 +38,7 @@ config SCSI_UFSHCD select PM_DEVFREQ select DEVFREQ_GOV_SIMPLE_ONDEMAND select NLS + select BLK_DEV_BSGLIB
Why is this needed?
Quoted 87 lines
drivers/scsi/ufs/Kconfig +1
-1---help--- This selects the support for UFS devices in Linux, say Y and make sure that you know the name of your UFS host adapter (the card@@ -143,7 +144,7 @@ config SCSI_UFS_TI_J721E If unsure, say N. config SCSI_UFS_BSG - bool "Universal Flash Storage BSG device node" + tristate "Universal Flash Storage BSG device node" depends on SCSI_UFSHCD select BLK_DEV_BSGLIB helpdrivers/scsi/ufs/Makefile +1
-1@@ -6,7 +6,7 @@ obj-$(CONFIG_SCSI_UFS_CDNS_PLATFORM) += cdns-pltfrm.o obj-$(CONFIG_SCSI_UFS_QCOM) += ufs-qcom.o obj-$(CONFIG_SCSI_UFSHCD) += ufshcd-core.o ufshcd-core-y += ufshcd.o ufs-sysfs.o -ufshcd-core-$(CONFIG_SCSI_UFS_BSG) += ufs_bsg.o +obj-$(CONFIG_SCSI_UFS_BSG) += ufs_bsg.o obj-$(CONFIG_SCSI_UFSHCD_PCI) += ufshcd-pci.o obj-$(CONFIG_SCSI_UFSHCD_PLATFORM) += ufshcd-pltfrm.o obj-$(CONFIG_SCSI_UFS_HISI) += ufs-hisi.odrivers/scsi/ufs/ufs_bsg.c +15
-3@@ -164,13 +164,15 @@ static int ufs_bsg_request(struct bsg_job *job)*/ void ufs_bsg_remove (struct ufs_hba *hba) { -struct device *bsg_dev = &hba->bsg_dev; +struct device *bsg_dev = hba->bsg_dev;if (!hba->bsg_queue)return ;bsg_remove_queue (hba->bsg_queue); + hba->bsg_dev =NULL ; + hba->bsg_queue =NULL ;device_del (bsg_dev);put_device (bsg_dev); }@@ -178,6 +180,7 @@ void ufs_bsg_remove(struct ufs_hba *hba)static inline void ufs_bsg_node_release (struct device *dev) {put_device (dev->parent); +kfree (dev); }/** @@ -186,14 +189,19 @@ static inline void ufs_bsg_node_release(struct device *dev)* * Called during initial loading of the driver, and before scsi_scan_host. */ -int ufs_bsg_probe (struct ufs_hba *hba) +static int ufs_bsg_probe (struct ufs_hba *hba) { -struct device *bsg_dev = &hba->bsg_dev; +struct device *bsg_dev;struct Scsi_Host *shost = hba->host;struct device *parent = &shost->shost_gendev;struct request_queue *q;int ret; + bsg_dev =kzalloc (sizeof (*bsg_dev),GFP_KERNEL ); +if (!bsg_dev) +return -ENOMEM ; + + hba->bsg_dev = bsg_dev;device_initialize (bsg_dev); bsg_dev->parent =get_device (parent);@@ -217,6 +225,41 @@ int ufs_bsg_probe(struct ufs_hba *hba) out:dev_err (bsg_dev,"fail to initialize a bsg dev %d\n" , shost->host_no); + hba->bsg_dev =NULL ;put_device (bsg_dev);return ret; } + +static int __init ufs_bsg_init (void ) +{
drivers/scsi/ufs/ufs_bsg.c int ufs_bsg_probe(struct ufs_hba *hba) · line 244
Quoted 10 lines
drivers/scsi/ufs/ufs_bsg.c +10
-0+struct list_head *hba_list =NULL ; +struct ufs_hba *hba; +int ret =0 ; + +ufshcd_get_hba_list_lock (&hba_list); +list_for_each_entry (hba, hba_list, list) { + ret =ufs_bsg_probe (hba); +if (ret) +break ; + }
So what happens if I go CONFIG_SCSI_UFS_BSG=y andCONFIG_SCSI_UFS_QCOM=y?
Wouldn't that mean that ufs_bsg_init() is called before ufshcd_init() has added the controller to the list? And even in the even that they are both =m, what happens if they are invoked in the "wrong" order?
Quoted 10 lines
drivers/scsi/ufs/ufs_bsg.c +10
-0+ufshcd_put_hba_list_unlock (); + +return ret; +} + +static void __exit ufs_bsg_exit(void) +{ +struct list_head *hba_list =NULL ; +struct ufs_hba *hba; +
drivers/scsi/ufs/ufs_bsg.c int ufs_bsg_probe(struct ufs_hba *hba) · line 264
Quoted 10 lines
drivers/scsi/ufs/ufs_bsg.c +10
-0+ufshcd_get_hba_list_lock (&hba_list); +list_for_each_entry (hba, hba_list, list) +ufs_bsg_remove (hba); +ufshcd_put_hba_list_unlock (); +} + +late_initcall_sync (ufs_bsg_init); +module_exit (ufs_bsg_exit); + +MODULE_ALIAS ("ufs-bsg" );
The purpose of MODULE_ALIAS() is to facilitate module autoloading, but as you probe the bsg device from the initcall of the bsg driver itself I don't see how that would happen, and as such I don't think this alias has a purpose.
Quoted 73 lines
drivers/scsi/ufs/ufs_bsg.c +1
-0+MODULE_LICENSE ("GPL v2" );drivers/scsi/ufs/ufs_bsg.h +0
-8@@ -12,12 +12,4 @@#include "ufshcd.h" #include "ufs.h" -#ifdef CONFIG_SCSI_UFS_BSG -void ufs_bsg_remove (struct ufs_hba *hba); -int ufs_bsg_probe (struct ufs_hba *hba); -#else -static inline void ufs_bsg_remove (struct ufs_hba *hba) {} -static inline int ufs_bsg_probe (struct ufs_hba *hba) {return 0 ; } -#endif -#endif /* UFS_BSG_H */ drivers/scsi/ufs/ufshcd.c +18
-3@@ -108,6 +108,22 @@ 16, 4, buf, __len, false); \ }while (0 ) +static LIST_HEAD(ufs_hba_list); +static DEFINE_MUTEX (ufs_hba_list_lock); + +void ufshcd_get_hba_list_lock (struct list_head **list) +{ +mutex_lock (&ufs_hba_list_lock); + *list = &ufs_hba_list; +} +EXPORT_SYMBOL_GPL (ufshcd_get_hba_list_lock); + +void ufshcd_put_hba_list_unlock (void ) +{ +mutex_unlock (&ufs_hba_list_lock); +} +EXPORT_SYMBOL_GPL (ufshcd_put_hba_list_unlock); +int ufshcd_dump_regs (struct ufs_hba *hba,size_t offset,size_t len,const char *prefix) {@@ -2093,6 +2109,7 @@ int ufshcd_send_uic_cmd(struct ufs_hba *hba, struct uic_command *uic_cmd)ufshcd_release (hba);return ret; } +EXPORT_SYMBOL_GPL (ufshcd_send_uic_cmd);/** * ufshcd_map_sg - Map scatter-gather list to prdt @@ -6024,6 +6041,7 @@ int ufshcd_exec_raw_upiu_cmd(struct ufs_hba *hba,return err; } +EXPORT_SYMBOL_GPL (ufshcd_exec_raw_upiu_cmd);/** * ufshcd_eh_device_reset_handler - device reset handler registered to @@ -7043,9 +7061,6 @@ static int ufshcd_probe_hba(struct ufs_hba *hba) } hba->clk_scaling.is_allowed = true; } - -ufs_bsg_probe (hba); -scsi_scan_host (hba->host);pm_runtime_put_sync (hba->dev); }@@ -8248,7 +8263,16 @@ int ufshcd_shutdown(struct ufs_hba *hba)*/
drivers/scsi/ufs/ufshcd.c int ufshcd_shutdown(struct ufs_hba *hba) · line 8272
Quoted 10 lines
drivers/scsi/ufs/ufshcd.c +7
-1void ufshcd_remove (struct ufs_hba *hba) { -ufs_bsg_remove (hba); +struct device *bsg_dev = hba->bsg_dev; + +mutex_lock (&ufs_hba_list_lock); +list_del (&hba->list); +if (hba->bsg_queue) { +bsg_remove_queue (hba->bsg_queue); +device_del (bsg_dev);
Am I reading this correct in that you probe the bsg_dev form initcall and you delete it as the ufshcd instance is removed? That's not okay.
Regards,
Bjorn
Quoted 60 lines
drivers/scsi/ufs/ufshcd.c +7
-0+put_device (bsg_dev); + } +mutex_unlock (&ufs_hba_list_lock);ufs_sysfs_remove_nodes (hba->dev);scsi_remove_host (hba->host);scsi_host_put (hba->host);@@ -8494,6 +8518,10 @@ int ufshcd_init(struct ufs_hba *hba, void __iomem *mmio_base, unsigned int irq)async_schedule (ufshcd_async_scan, hba);ufs_sysfs_add_nodes (hba->dev); +mutex_lock (&ufs_hba_list_lock); +list_add_tail (&hba->list, &ufs_hba_list); +mutex_unlock (&ufs_hba_list_lock); +return 0 ; out_remove_scsi_host:drivers/scsi/ufs/ufshcd.h +6
-1@@ -74,6 +74,9 @@struct ufs_hba ; +void ufshcd_get_hba_list_lock (struct list_head **list); +void ufshcd_put_hba_list_unlock (void ); +enum dev_cmd_type {DEV_CMD_TYPE_NOP =0x0 ,DEV_CMD_TYPE_QUERY =0x1 ,@@ -473,6 +476,7 @@ struct ufs_stats {/** * struct ufs_hba - per adapter private structure +* @list: Anchored at ufs_hba_list * @mmio_base: UFSHCI base register address * @ucdl_base_addr: UFS Command Descriptor base address * @utrdl_base_addr: UTP Transfer Request Descriptor base address @@ -527,6 +531,7 @@ struct ufs_stats {* @scsi_block_reqs_cnt: reference counting for scsi block requests */ struct ufs_hba { +struct list_head list;void __iomem *mmio_base;/* Virtual memory reference */ @@ -734,7 +739,7 @@ struct ufs_hba {struct ufs_desc_size desc_size;atomic_t scsi_block_reqs_cnt; -struct device bsg_dev; +struct device *bsg_dev;struct request_queue *bsg_queue; };Signature · 2 lines
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project
Re: [PATCH v2 2/3] scsi: ufs: Modulize ufs-bsg
Quoted 9 lines · Bjorn Andersson
Quoted 3 lines · Can Guo
In order to improve the flexibility of ufs-bsg, modulizing it is a good choice. This change introduces tristate to ufs-bsg to allow users compile it as an external module.
Can you please elaborate on what this "flexibility" is and why it's a good thing?
ufs-bsg is a helpful gadget for debug/test purpose. But neither disabling it nor enabling it is the best way on a commercialized device. Disabling it means we cannot use it, while enabling it by default will expose all the DEVM/UIC/TM interfaces to user space, which is not "safe" on a commercialized device to let users play with it. Making it a module can resolve this, because only vendors can install it as they have the root permissions.
Quoted 12 lines
Quoted 12 lines
Signed-off-by Can Guo <[email protected]>--- drivers/scsi/ufs/Kconfig | 3 ++- drivers/scsi/ufs/Makefile | 2 +- drivers/scsi/ufs/ufs_bsg.c | 49 +++++++++++++++++++++++++++++++++++++++++++--- drivers/scsi/ufs/ufs_bsg.h | 8 -------- drivers/scsi/ufs/ufshcd.c | 36 ++++++++++++++++++++++++++++++---- drivers/scsi/ufs/ufshcd.h | 7 ++++++- 6 files changed, 87 insertions(+), 18 deletions(-)
Quoted 12 lines
drivers/scsi/ufs/Kconfig config SCSI_UFSHCD · line 41
Quoted 9 lines
drivers/scsi/ufs/Kconfig +1
-0@@ -38,6 +38,7 @@ config SCSI_UFSHCD select PM_DEVFREQ select DEVFREQ_GOV_SIMPLE_ONDEMAND select NLS + select BLK_DEV_BSGLIBWhy is this needed?
Because ufshcd.c needs to call some funcs defined in bsg lib.
Quoted 104 lines
Quoted 90 lines
drivers/scsi/ufs/Kconfig +1
-1---help--- This selects the support for UFS devices in Linux, say Y and make sure that you know the name of your UFS host adapter (the card@@ -143,7 +144,7 @@ config SCSI_UFS_TI_J721E If unsure, say N. config SCSI_UFS_BSG - bool "Universal Flash Storage BSG device node" + tristate "Universal Flash Storage BSG device node" depends on SCSI_UFSHCD select BLK_DEV_BSGLIB helpdrivers/scsi/ufs/Makefile +1
-1@@ -6,7 +6,7 @@ obj-$(CONFIG_SCSI_UFS_CDNS_PLATFORM) += cdns-pltfrm.o obj-$(CONFIG_SCSI_UFS_QCOM) += ufs-qcom.o obj-$(CONFIG_SCSI_UFSHCD) += ufshcd-core.o ufshcd-core-y += ufshcd.o ufs-sysfs.o -ufshcd-core-$(CONFIG_SCSI_UFS_BSG) += ufs_bsg.o +obj-$(CONFIG_SCSI_UFS_BSG) += ufs_bsg.o obj-$(CONFIG_SCSI_UFSHCD_PCI) += ufshcd-pci.o obj-$(CONFIG_SCSI_UFSHCD_PLATFORM) += ufshcd-pltfrm.o obj-$(CONFIG_SCSI_UFS_HISI) += ufs-hisi.odrivers/scsi/ufs/ufs_bsg.c +4
-1@@ -164,13 +164,15 @@ static int ufs_bsg_request(struct bsg_job *job)*/ void ufs_bsg_remove (struct ufs_hba *hba) { -struct device *bsg_dev = &hba->bsg_dev; +struct device *bsg_dev = hba->bsg_dev;if (!hba->bsg_queue)return ;bsg_remove_queue (hba->bsg_queue); + hba->bsg_dev =NULL ; + hba->bsg_queue =NULL ;device_del (bsg_dev);put_device (bsg_dev); }@@ -178,6 +180,7 @@ void ufs_bsg_remove(struct ufs_hba *hba)static inline void ufs_bsg_node_release (struct device *dev) {put_device (dev->parent); +kfree (dev); }/** @@ -186,14 +189,19 @@ static inline void ufs_bsg_node_release(struct device *dev) * * Called during initial loading of the driver, and before
scsi_scan_host.
*/drivers/scsi/ufs/ufs_bsg.c +11
-2-int ufs_bsg_probe (struct ufs_hba *hba) +static int ufs_bsg_probe (struct ufs_hba *hba) { -struct device *bsg_dev = &hba->bsg_dev; +struct device *bsg_dev;struct Scsi_Host *shost = hba->host;struct device *parent = &shost->shost_gendev;struct request_queue *q;int ret; + bsg_dev =kzalloc (sizeof (*bsg_dev),GFP_KERNEL ); +if (!bsg_dev) +return -ENOMEM ; + + hba->bsg_dev = bsg_dev;device_initialize (bsg_dev); bsg_dev->parent =get_device (parent);@@ -217,6 +225,41 @@ int ufs_bsg_probe(struct ufs_hba *hba) out:dev_err (bsg_dev,"fail to initialize a bsg dev %d\n" , shost->host_no); + hba->bsg_dev =NULL ;put_device (bsg_dev);return ret; } + +static int __init ufs_bsg_init (void ) +{drivers/scsi/ufs/ufs_bsg.c int ufs_bsg_probe(struct ufs_hba *hba) · line 244
Quoted 10 lines
drivers/scsi/ufs/ufs_bsg.c +10
-0+struct list_head *hba_list =NULL ; +struct ufs_hba *hba; +int ret =0 ; + +ufshcd_get_hba_list_lock (&hba_list); +list_for_each_entry (hba, hba_list, list) { + ret =ufs_bsg_probe (hba); +if (ret) +break ; + }So what happens if I go
CONFIG_SCSI_UFS_BSG=yandCONFIG_SCSI_UFS_QCOM=y?
Quoted 4 lines
Wouldn't that mean that
ufs_bsg_init()is called beforeufshcd_init()has added the controller to the list? And even in the even that they are both =m, what happens if they are invoked in the "wrong" order?
In the case that CONFIG_SCSI_UFS_BSG=y and CONFIG_SCSI_UFS_QCOM=y, I give late_initcall_sync(ufs_bsg_init) to make sure ufs_bsg_init is invoked only after platform driver is probed. I tested this combination.
In the case that both of them are "m", installing ufs-bsg before ufs-qcom is installed would have no effect as ufs_hba_list is empty, which is expected. And in real cases, as the UFS is the boot device, UFS driver will always be probed during bootup.
Quoted 17 lines
Quoted 17 lines
drivers/scsi/ufs/ufs_bsg.c +17
-0+ufshcd_put_hba_list_unlock (); + +return ret; +} + +static void __exit ufs_bsg_exit(void) +{ +struct list_head *hba_list =NULL ; +struct ufs_hba *hba; + +ufshcd_get_hba_list_lock (&hba_list); +list_for_each_entry (hba, hba_list, list) +ufs_bsg_remove (hba); +ufshcd_put_hba_list_unlock (); +} + +late_initcall_sync (ufs_bsg_init);
Quoted 9 lines
drivers/scsi/ufs/ufs_bsg.c int ufs_bsg_probe(struct ufs_hba *hba) · line 264
Quoted 3 lines
drivers/scsi/ufs/ufs_bsg.c +3
-0+module_exit (ufs_bsg_exit); + +MODULE_ALIAS ("ufs-bsg" );The purpose of
MODULE_ALIAS()is to facilitate module autoloading, but as you probe the bsg device from the initcall of the bsg driver itself I don't see how that would happen, and as such I don't think this alias has a purpose.
Good point, will remove it.
Quoted 90 lines
Quoted 76 lines
drivers/scsi/ufs/ufs_bsg.c +1
-0+MODULE_LICENSE ("GPL v2" );drivers/scsi/ufs/ufs_bsg.h +0
-8@@ -12,12 +12,4 @@#include "ufshcd.h" #include "ufs.h" -#ifdef CONFIG_SCSI_UFS_BSG -void ufs_bsg_remove (struct ufs_hba *hba); -int ufs_bsg_probe (struct ufs_hba *hba); -#else -static inline void ufs_bsg_remove (struct ufs_hba *hba) {} -static inline int ufs_bsg_probe (struct ufs_hba *hba) {return 0 ; } -#endif -#endif /* UFS_BSG_H */ drivers/scsi/ufs/ufshcd.c +17
-0@@ -108,6 +108,22 @@ 16, 4, buf, __len, false); \ }while (0 ) +static LIST_HEAD(ufs_hba_list); +static DEFINE_MUTEX (ufs_hba_list_lock); + +void ufshcd_get_hba_list_lock (struct list_head **list) +{ +mutex_lock (&ufs_hba_list_lock); + *list = &ufs_hba_list; +} +EXPORT_SYMBOL_GPL (ufshcd_get_hba_list_lock); + +void ufshcd_put_hba_list_unlock (void ) +{ +mutex_unlock (&ufs_hba_list_lock); +} +EXPORT_SYMBOL_GPL (ufshcd_put_hba_list_unlock); +int ufshcd_dump_regs (struct ufs_hba *hba,size_t offset,size_t len,const char *prefix) {@@ -2093,6 +2109,7 @@ int ufshcd_send_uic_cmd(struct ufs_hba *hba, struct uic_command *uic_cmd)ufshcd_release (hba );return ret; } +EXPORT_SYMBOL_GPL (ufshcd_send_uic_cmd);/** *
ufshcd_map_sg- Map scatter-gather list to prdtdrivers/scsi/ufs/ufshcd.c +1
-0@@ -6024,6 +6041,7 @@ int ufshcd_exec_raw_upiu_cmd(struct ufs_hba *hba, return err; } +EXPORT_SYMBOL_GPL (ufshcd_exec_raw_upiu_cmd);/** *
ufshcd_eh_device_reset_handler- device reset handler registered
todrivers/scsi/ufs/ufshcd.c +0
-3@@ -7043,9 +7061,6 @@ static int ufshcd_probe_hba(struct ufs_hba *hba) } hba->clk_scaling.is_allowed = true; } - -ufs_bsg_probe (hba); -scsi_scan_host (hba->host);pm_runtime_put_sync (hba->dev); }@@ -8248,7 +8263,16 @@ int ufshcd_shutdown(struct ufs_hba *hba)*/ drivers/scsi/ufs/ufshcd.c int ufshcd_shutdown(struct ufs_hba *hba) · line 8272
Quoted 10 lines
drivers/scsi/ufs/ufshcd.c +7
-1void ufshcd_remove (struct ufs_hba *hba) { -ufs_bsg_remove (hba); +struct device *bsg_dev = hba->bsg_dev; + +mutex_lock (&ufs_hba_list_lock); +list_del (&hba->list); +if (hba->bsg_queue) { +bsg_remove_queue (hba->bsg_queue); +device_del (bsg_dev);Am I reading this correct in that you probe the
bsg_devform initcall and you delete it as the ufshcd instance is removed? That's not okay.
Quoted 3 lines
Regards,
Bjorn
If ufshcd is removed, its ufs-bsg, if exists, should also be removed. Could you please enlighten me a better way to do this? Thanks.
Regards,
Can Guo.
Quoted 61 lines
Quoted 61 lines
drivers/scsi/ufs/ufshcd.c +7
-0+put_device (bsg_dev); + } +mutex_unlock (&ufs_hba_list_lock);ufs_sysfs_remove_nodes (hba->dev);scsi_remove_host (hba->host);scsi_host_put (hba->host);@@ -8494,6 +8518,10 @@ int ufshcd_init(struct ufs_hba *hba, void __iomem *mmio_base, unsigned int irq)async_schedule (ufshcd_async_scan ,hba );ufs_sysfs_add_nodes (hba->dev); +mutex_lock (&ufs_hba_list_lock); +list_add_tail (&hba->list, &ufs_hba_list); +mutex_unlock (&ufs_hba_list_lock); +return 0 ;
out_remove_scsi_host:drivers/scsi/ufs/ufshcd.h +6
-2@@ -74,6 +74,9 @@struct ufs_hba ; +void ufshcd_get_hba_list_lock (struct list_head **list); +void ufshcd_put_hba_list_unlock (void ); +enum dev_cmd_type {DEV_CMD_TYPE_NOP =0x0 ,DEV_CMD_TYPE_QUERY =0x1 ,@@ -473,6 +476,7 @@ struct ufs_stats {/** * struct ufs_hba - per adapter private structure +* @list: Anchored at ufs_hba_list * @mmio_base: UFSHCI base register address * @ucdl_base_addr: UFS Command Descriptor base address * @utrdl_base_addr: UTP Transfer Request Descriptor base address @@ -527,6 +531,7 @@ struct ufs_stats {* @scsi_block_reqs_cnt: reference counting for scsi block requests */ struct ufs_hba { +struct list_head list;void __iomem *mmio_base;/* Virtual memory reference */ @@ -734,7 +739,7 @@ struct ufs_hba {struct ufs_desc_size desc_size;atomic_t scsi_block_reqs_cnt; -struct device bsg_dev; +struct device *bsg_dev;struct request_queue *bsg_queue; }; --The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project
A message that is not in the archive (sent off-list or not yet received): 0101016ef8b2e2f8-72260b08-e6ad-42fc-bd4b-4a0a72c5c9b3-000000@us-west-2.amazonses.com
Re: [PATCH v2 2/3] scsi: ufs: Modulize ufs-bsg
Quoted 157 lines · On Wed 11 Dec 22:01 PST 2019, [email protected] wrote:
Quoted 11 lines · Bjorn Andersson
Quoted 5 lines · Can Guo
In order to improve the flexibility of ufs-bsg, modulizing it is a good
choice. This change introduces tristate to ufs-bsg to allow users compile
it as an external module.Can you please elaborate on what this "flexibility" is and why it's a good thing?
ufs-bsg is a helpful gadget for debug/test purpose. But neither disabling it nor enabling it is the best way on a commercialized device. Disabling it means we cannot use it, while enabling it by default will expose all the DEVM/UIC/TM interfaces to user space, which is not "safe" on a commercialized device to let users play with it. Making it a module can resolve this, because only vendors can install it as they have the root permissions.
Quoted 12 lines
Quoted 12 lines
Signed-off-by Can Guo <[email protected]>--- drivers/scsi/ufs/Kconfig | 3 ++- drivers/scsi/ufs/Makefile | 2 +- drivers/scsi/ufs/ufs_bsg.c | 49 +++++++++++++++++++++++++++++++++++++++++++--- drivers/scsi/ufs/ufs_bsg.h | 8 -------- drivers/scsi/ufs/ufshcd.c | 36 ++++++++++++++++++++++++++++++---- drivers/scsi/ufs/ufshcd.h | 7 ++++++- 6 files changed, 87 insertions(+), 18 deletions(-)Quoted 12 lines
drivers/scsi/ufs/Kconfig config SCSI_UFSHCD · line 41
Quoted 9 lines
drivers/scsi/ufs/Kconfig +1
-0@@ -38,6 +38,7 @@ config SCSI_UFSHCD select PM_DEVFREQ select DEVFREQ_GOV_SIMPLE_ONDEMAND select NLS + select BLK_DEV_BSGLIBWhy is this needed?
Because
ufshcd.cneeds to call some funcs defined in bsg lib.Quoted 104 lines
Quoted 90 lines
drivers/scsi/ufs/Kconfig +1
-1---help--- This selects the support for UFS devices in Linux, say Y and make sure that you know the name of your UFS host adapter (the card@@ -143,7 +144,7 @@ config SCSI_UFS_TI_J721E If unsure, say N. config SCSI_UFS_BSG - bool "Universal Flash Storage BSG device node" + tristate "Universal Flash Storage BSG device node" depends on SCSI_UFSHCD select BLK_DEV_BSGLIB helpdrivers/scsi/ufs/Makefile +1
-1@@ -6,7 +6,7 @@ obj-$(CONFIG_SCSI_UFS_CDNS_PLATFORM) += cdns-pltfrm.o obj-$(CONFIG_SCSI_UFS_QCOM) += ufs-qcom.o obj-$(CONFIG_SCSI_UFSHCD) += ufshcd-core.o ufshcd-core-y += ufshcd.o ufs-sysfs.o -ufshcd-core-$(CONFIG_SCSI_UFS_BSG) += ufs_bsg.o +obj-$(CONFIG_SCSI_UFS_BSG) += ufs_bsg.o obj-$(CONFIG_SCSI_UFSHCD_PCI) += ufshcd-pci.o obj-$(CONFIG_SCSI_UFSHCD_PLATFORM) += ufshcd-pltfrm.o obj-$(CONFIG_SCSI_UFS_HISI) += ufs-hisi.odrivers/scsi/ufs/ufs_bsg.c +4
-1@@ -164,13 +164,15 @@ static int ufs_bsg_request(struct bsg_job *job)*/ void ufs_bsg_remove (struct ufs_hba *hba) { -struct device *bsg_dev = &hba->bsg_dev; +struct device *bsg_dev = hba->bsg_dev;if (!hba->bsg_queue)return ;bsg_remove_queue (hba->bsg_queue); + hba->bsg_dev =NULL ; + hba->bsg_queue =NULL ;device_del (bsg_dev);put_device (bsg_dev); }@@ -178,6 +180,7 @@ void ufs_bsg_remove(struct ufs_hba *hba)static inline void ufs_bsg_node_release (struct device *dev) {put_device (dev->parent); +kfree (dev); }/** @@ -186,14 +189,19 @@ static inline void ufs_bsg_node_release(struct device *dev) * * Called during initial loading of the driver, and before
scsi_scan_host.
*/drivers/scsi/ufs/ufs_bsg.c +11
-2-int ufs_bsg_probe (struct ufs_hba *hba) +static int ufs_bsg_probe (struct ufs_hba *hba) { -struct device *bsg_dev = &hba->bsg_dev; +struct device *bsg_dev;struct Scsi_Host *shost = hba->host;struct device *parent = &shost->shost_gendev;struct request_queue *q;int ret; + bsg_dev =kzalloc (sizeof (*bsg_dev),GFP_KERNEL ); +if (!bsg_dev) +return -ENOMEM ; + + hba->bsg_dev = bsg_dev;device_initialize (bsg_dev); bsg_dev->parent =get_device (parent);@@ -217,6 +225,41 @@ int ufs_bsg_probe(struct ufs_hba *hba) out:dev_err (bsg_dev,"fail to initialize a bsg dev %d\n" , shost->host_no); + hba->bsg_dev =NULL ;put_device (bsg_dev);return ret; } + +static int __init ufs_bsg_init (void ) +{drivers/scsi/ufs/ufs_bsg.c int ufs_bsg_probe(struct ufs_hba *hba) · line 244
Quoted 10 lines
drivers/scsi/ufs/ufs_bsg.c +10
-0+struct list_head *hba_list =NULL ; +struct ufs_hba *hba; +int ret =0 ; + +ufshcd_get_hba_list_lock (&hba_list); +list_for_each_entry (hba, hba_list, list) { + ret =ufs_bsg_probe (hba); +if (ret) +break ; + }So what happens if I go
CONFIG_SCSI_UFS_BSG=yandCONFIG_SCSI_UFS_QCOM=y?Quoted 4 lines
Wouldn't that mean that
ufs_bsg_init()is called beforeufshcd_init()has added the controller to the list? And even in the even that they are both =m, what happens if they are invoked in the "wrong" order?
Quoted 7 lines
In the case that
CONFIG_SCSI_UFS_BSG=yandCONFIG_SCSI_UFS_QCOM=y, I givelate_initcall_sync(ufs_bsg_init)to make sureufs_bsg_initis invoked only after platform driver is probed. I tested this combination.In the case that both of them are "m", installing ufs-bsg before ufs-qcom is installed would have no effect as
ufs_hba_listis empty, which is expected.
Why is it the expected behavior that bsg may or may not probe depending on the driver load order and potentially timing of the initialization.
Quoted 3 lines
And in real cases, as the UFS is the boot device, UFS driver will always be probed during bootup.
The UFS driver will load and probe because it's mentioned in the devicetree, but if either the ufs drivers or any of its dependencies (phy, resets, clocks, etc) are built as modules it might very well finish probing after lateinitcall.
So in the even that the bsg is =y and any of these drivers are =m, or if you're having bad luck with your timing, the list will be empty.
As described below, if bsg=m, then there's nothing that will load the module and the bsg will not probe...
[..]
Quoted 1 line
Quoted 1 line
Quoted 1 line
drivers/scsi/ufs/ufshcd.c +0
-0
[..]
Quoted 14 lines
Quoted 14 lines
drivers/scsi/ufs/ufshcd.c int ufshcd_shutdown(struct ufs_hba *hba) · line 8272
Quoted 10 lines
void
ufshcd_remove(struct ufs_hba *hba)
{drivers/scsi/ufs/ufshcd.c +7
-1-ufs_bsg_remove (hba); +struct device *bsg_dev = hba->bsg_dev; + +mutex_lock (&ufs_hba_list_lock); +list_del (&hba->list); +if (hba->bsg_queue) { +bsg_remove_queue (hba->bsg_queue); +device_del (bsg_dev);Am I reading this correct in that you probe the
bsg_devform initcall and you delete it as the ufshcd instance is removed? That's not okay.
Quoted 7 lines
Quoted 3 lines
Regards,
BjornIf ufshcd is removed, its ufs-bsg, if exists, should also be removed. Could you please enlighten me a better way to do this? Thanks.
It's the asymmetry that I don't like.
Perhaps if you instead make ufshcd platform_device_register_data() the bsg device you would solve the probe ordering, the remove will be symmetric and module autoloading will work as well (although then you need a MODULE_ALIAS of platform:device-name).
Regards,
Bjorn
RE: [PATCH v2 2/3] scsi: ufs: Modulize ufs-bsg
Quoted 17 lines · On Wed 11 Dec 22:01 PST 2019, [email protected] wrote:
Quoted 12 lines · Bjorn Andersson
Quoted 9 lines · Can Guo
Quoted 4 lines
In order to improve the flexibility of ufs-bsg, modulizing it is a good choice. This change introduces tristate to ufs-bsg to allow users compile it as an external module.
Can you please elaborate on what this "flexibility" is and why it's a good thing?
Quoted 7 lines
Quoted 7 lines
ufs-bsg is a helpful gadget for debug/test purpose. But neither disabling it nor enabling it is the best way on a commercialized device. Disabling it means we cannot use it, while enabling it by default will expose all the DEVM/UIC/TM interfaces to user space, which is not "safe" on a commercialized device to let users play with it. Making it a module can resolve this, because only vendors can install it as they have the root permissions.
Agree.
We see that the public ufs-utils (https://github.com/westerndigitalcorporation/ufs-utils) that uses this infrastructure, is gaining momentum, and currently being used not only by chipset and flash vendors,
but by end customers as well.
This change will e.g. enable, field application engineers to debug issues in a safer mode.
Quoted 157 lines
Quoted 137 lines
Quoted 13 lines
Quoted 13 lines
Signed-off-by Can Guo <[email protected]>--- drivers/scsi/ufs/Kconfig | 3 ++- drivers/scsi/ufs/Makefile | 2 +- drivers/scsi/ufs/ufs_bsg.c | 49 +++++++++++++++++++++++++++++++++++++++++++--- drivers/scsi/ufs/ufs_bsg.h | 8 -------- drivers/scsi/ufs/ufshcd.c | 36 ++++++++++++++++++++++++++++++---- drivers/scsi/ufs/ufshcd.h | 7 ++++++- 6 files changed, 87 insertions(+), 18 deletions(-)Quoted 12 lines
drivers/scsi/ufs/Kconfig config SCSI_UFSHCD · line 41
Quoted 9 lines
drivers/scsi/ufs/Kconfig +1
-0@@ -38,6 +38,7 @@ config SCSI_UFSHCD select PM_DEVFREQ select DEVFREQ_GOV_SIMPLE_ONDEMAND select NLS + select BLK_DEV_BSGLIBWhy is this needed?
Because
ufshcd.cneeds to call some funcs defined in bsg lib.Quoted 104 lines
Quoted 90 lines
drivers/scsi/ufs/Kconfig +1
-1---help--- This selects the support for UFS devices in Linux, say Y and make sure that you know the name of your UFS host adapter (the card@@ -143,7 +144,7 @@ config SCSI_UFS_TI_J721E If unsure, say N. config SCSI_UFS_BSG - bool "Universal Flash Storage BSG device node" + tristate "Universal Flash Storage BSG device node" depends on SCSI_UFSHCD select BLK_DEV_BSGLIB helpdrivers/scsi/ufs/Makefile +0
-0@@ -6,7 +6,7 @@ obj-$(CONFIG_SCSI_UFS_CDNS_PLATFORM) +=cdns-pltfrm.o
obj-$(CONFIG_SCSI_UFS_QCOM) += ufs-qcom.o
obj-$(CONFIG_SCSI_UFSHCD) += ufshcd-core.o
ufshcd-core-y += ufshcd.o ufs-sysfs.odrivers/scsi/ufs/Makefile +1
-1-ufshcd-core-$(CONFIG_SCSI_UFS_BSG) += ufs_bsg.o +obj-$(CONFIG_SCSI_UFS_BSG) += ufs_bsg.o obj-$(CONFIG_SCSI_UFSHCD_PCI) += ufshcd-pci.o obj-$(CONFIG_SCSI_UFSHCD_PLATFORM) += ufshcd-pltfrm.o obj-$(CONFIG_SCSI_UFS_HISI) += ufs-hisi.o diff --git
a/drivers/scsi/ufs/ufs_bsg.cb/drivers/scsi/ufs/ufs_bsg.cindex 3a2e68f..302222f 100644drivers/scsi/ufs/ufs_bsg.c +4
-1@@ -164,13 +164,15 @@ static int ufs_bsg_request(struct bsg_job *job)*/ void ufs_bsg_remove (struct ufs_hba *hba) { -struct device *bsg_dev = &hba->bsg_dev; +struct device *bsg_dev = hba->bsg_dev;if (!hba->bsg_queue)return ;bsg_remove_queue (hba->bsg_queue); + hba->bsg_dev =NULL ; + hba->bsg_queue =NULL ;device_del (bsg_dev);put_device (bsg_dev); }@@ -178,6 +180,7 @@ void ufs_bsg_remove(struct ufs_hba *hba)static inline void ufs_bsg_node_release (struct device *dev) {put_device (dev->parent); +kfree (dev); }/** @@ -186,14 +189,19 @@ static inline void ufs_bsg_node_release(struct device *dev) * * Called during initial loading of the driver, and before
scsi_scan_host.
*/drivers/scsi/ufs/ufs_bsg.c +11
-2-int ufs_bsg_probe (struct ufs_hba *hba) +static int ufs_bsg_probe (struct ufs_hba *hba) { -struct device *bsg_dev = &hba->bsg_dev; +struct device *bsg_dev;struct Scsi_Host *shost = hba->host;struct device *parent = &shost->shost_gendev;struct request_queue *q;int ret; + bsg_dev =kzalloc (sizeof (*bsg_dev),GFP_KERNEL ); +if (!bsg_dev) +return -ENOMEM ; + + hba->bsg_dev = bsg_dev;device_initialize (bsg_dev); bsg_dev->parent =get_device (parent);@@ -217,6 +225,41 @@ int ufs_bsg_probe(struct ufs_hba *hba) out:dev_err (bsg_dev,"fail to initialize a bsg dev %d\n" , shost->host_no); + hba->bsg_dev =NULL ;put_device (bsg_dev);return ret; } + +static int __init ufs_bsg_init (void ) +{drivers/scsi/ufs/ufs_bsg.c int ufs_bsg_probe(struct ufs_hba *hba) · line 244
Quoted 10 lines
drivers/scsi/ufs/ufs_bsg.c +10
-0+struct list_head *hba_list =NULL ; +struct ufs_hba *hba; +int ret =0 ; + +ufshcd_get_hba_list_lock (&hba_list); +list_for_each_entry (hba, hba_list, list) { + ret =ufs_bsg_probe (hba); +if (ret) +break ; + }So what happens if I go
CONFIG_SCSI_UFS_BSG=yandCONFIG_SCSI_UFS_QCOM=y?Quoted 4 lines
Wouldn't that mean that
ufs_bsg_init()is called beforeufshcd_init()has added the controller to the list? And even in the even that they are both =m, what happens if they are invoked in the "wrong" order?Quoted 7 lines
In the case that
CONFIG_SCSI_UFS_BSG=yandCONFIG_SCSI_UFS_QCOM=y, I givelate_initcall_sync(ufs_bsg_init)to make sureufs_bsg_initis invoked only after platform driver is probed. I tested this combination.In the case that both of them are "m", installing ufs-bsg before ufs-qcom is installed would have no effect as
ufs_hba_listis empty, which is expected.Why is it the expected behavior that bsg may or may not probe depending on the driver load order and potentially timing of the initialization.
Quoted 3 lines
And in real cases, as the UFS is the boot device, UFS driver will always be probed during bootup.
The UFS driver will load and probe because it's mentioned in the devicetree, but if either the ufs drivers or any of its dependencies (phy, resets, clocks, etc) are built as modules it might very well finish probing after lateinitcall.
Quoted 5 lines
So in the even that the bsg is =y and any of these drivers are =m, or if you're having bad luck with your timing, the list will be empty.
As described below, if bsg=m, then there's nothing that will load the module and the bsg will not probe...
Right.
bsg=y and ufshcd=m is a bad idea, and should be avoided.
Quoted 35 lines
[..]
Quoted 1 line
Quoted 1 line
Quoted 1 line
drivers/scsi/ufs/ufshcd.c +0
-0[..]
Quoted 14 lines
Quoted 14 lines
drivers/scsi/ufs/ufshcd.c int ufshcd_shutdown(struct ufs_hba *hba) · line 8272
Quoted 10 lines
void
ufshcd_remove(struct ufs_hba *hba)
{
-ufs_bsg_remove(hba);
+ struct device*bsg_dev=hba->bsg_dev;drivers/scsi/ufs/ufshcd.c +6
-0+ +mutex_lock (&ufs_hba_list_lock); +list_del (&hba->list); +if (hba->bsg_queue) { +bsg_remove_queue (hba->bsg_queue); +device_del (bsg_dev);Am I reading this correct in that you probe the
bsg_devform initcall and you delete it as the ufshcd instance is removed? That's not okay.Quoted 7 lines
Quoted 3 lines
Regards,
BjornIf ufshcd is removed, its ufs-bsg, if exists, should also be removed. Could you please enlighten me a better way to do this? Thanks.
It's the asymmetry that I don't like.
Perhaps if you instead make ufshcd
platform_device_register_data()the bsg device you would solve the probe ordering, the remove will be symmetric and module autoloading will work as well (although then you need aMODULE_ALIASof platform:device-name).Regards,
Bjorn
Re: [PATCH v2 2/3] scsi: ufs: Modulize ufs-bsg
Quoted 22 lines · Avri Altman
Quoted 15 lines · On Wed 11 Dec 22:01 PST 2019, [email protected] wrote:
Quoted 12 lines · Bjorn Andersson
Quoted 9 lines · Can Guo
Quoted 4 lines
In order to improve the flexibility of ufs-bsg, modulizing it is a good choice. This change introduces tristate to ufs-bsg to allow users compile it as an external module.
Can you please elaborate on what this "flexibility" is and why it's a good thing?
Quoted 7 lines
Quoted 7 lines
ufs-bsg is a helpful gadget for debug/test purpose. But neither disabling it nor enabling it is the best way on a commercialized device. Disabling it means we cannot use it, while enabling it by default will expose all the DEVM/UIC/TM interfaces to user space, which is not "safe" on a commercialized device to let users play with it. Making it a module can resolve this, because only vendors can install it as they have the root permissions.
Quoted 10 lines
Agree.
We see that the public ufs-utils
(https://github.com/westerndigitalcorporation/ufs-utils) that uses this infrastructure,
is gaining momentum, and currently being used not only by chipset and flash vendors,
but by end customers as well.
This change will e.g. enable, field application engineers to debug issues in a safer mode.
True, thank you for the comments.
Quoted 157 lines
Quoted 157 lines
Quoted 137 lines
Quoted 13 lines
Quoted 13 lines
Signed-off-by Can Guo <[email protected]>--- drivers/scsi/ufs/Kconfig | 3 ++- drivers/scsi/ufs/Makefile | 2 +- drivers/scsi/ufs/ufs_bsg.c | 49 +++++++++++++++++++++++++++++++++++++++++++--- drivers/scsi/ufs/ufs_bsg.h | 8 -------- drivers/scsi/ufs/ufshcd.c | 36 ++++++++++++++++++++++++++++++---- drivers/scsi/ufs/ufshcd.h | 7 ++++++- 6 files changed, 87 insertions(+), 18 deletions(-)Quoted 12 lines
drivers/scsi/ufs/Kconfig config SCSI_UFSHCD · line 41
Quoted 9 lines
drivers/scsi/ufs/Kconfig +1
-0@@ -38,6 +38,7 @@ config SCSI_UFSHCD select PM_DEVFREQ select DEVFREQ_GOV_SIMPLE_ONDEMAND select NLS + select BLK_DEV_BSGLIBWhy is this needed?
Because
ufshcd.cneeds to call some funcs defined in bsg lib.Quoted 104 lines
Quoted 90 lines
drivers/scsi/ufs/Kconfig +1
-1---help--- This selects the support for UFS devices in Linux, say Y and make sure that you know the name of your UFS host adapter (the card@@ -143,7 +144,7 @@ config SCSI_UFS_TI_J721E If unsure, say N. config SCSI_UFS_BSG - bool "Universal Flash Storage BSG device node" + tristate "Universal Flash Storage BSG device node" depends on SCSI_UFSHCD select BLK_DEV_BSGLIB helpdrivers/scsi/ufs/Makefile +0
-0@@ -6,7 +6,7 @@ obj-$(CONFIG_SCSI_UFS_CDNS_PLATFORM) +=cdns-pltfrm.o
obj-$(CONFIG_SCSI_UFS_QCOM) += ufs-qcom.o
obj-$(CONFIG_SCSI_UFSHCD) += ufshcd-core.o
ufshcd-core-y += ufshcd.o ufs-sysfs.odrivers/scsi/ufs/Makefile +1
-1-ufshcd-core-$(CONFIG_SCSI_UFS_BSG) += ufs_bsg.o +obj-$(CONFIG_SCSI_UFS_BSG) += ufs_bsg.o obj-$(CONFIG_SCSI_UFSHCD_PCI) += ufshcd-pci.o obj-$(CONFIG_SCSI_UFSHCD_PLATFORM) += ufshcd-pltfrm.o obj-$(CONFIG_SCSI_UFS_HISI) += ufs-hisi.o diff --git
a/drivers/scsi/ufs/ufs_bsg.cb/drivers/scsi/ufs/ufs_bsg.cindex 3a2e68f..302222f 100644drivers/scsi/ufs/ufs_bsg.c +4
-1@@ -164,13 +164,15 @@ static int ufs_bsg_request(struct bsg_job *job)*/ void ufs_bsg_remove (struct ufs_hba *hba) { -struct device *bsg_dev = &hba->bsg_dev; +struct device *bsg_dev = hba->bsg_dev;if (!hba->bsg_queue)return ;bsg_remove_queue (hba->bsg_queue); + hba->bsg_dev =NULL ; + hba->bsg_queue =NULL ;device_del (bsg_dev);put_device (bsg_dev); }@@ -178,6 +180,7 @@ void ufs_bsg_remove(struct ufs_hba *hba)static inline void ufs_bsg_node_release (struct device *dev) {put_device (dev->parent); +kfree (dev); }/** @@ -186,14 +189,19 @@ static inline void ufs_bsg_node_release(struct device *dev) * * Called during initial loading of the driver, and before
scsi_scan_host.
*/drivers/scsi/ufs/ufs_bsg.c +11
-2-int ufs_bsg_probe (struct ufs_hba *hba) +static int ufs_bsg_probe (struct ufs_hba *hba) { -struct device *bsg_dev = &hba->bsg_dev; +struct device *bsg_dev;struct Scsi_Host *shost = hba->host;struct device *parent = &shost->shost_gendev;struct request_queue *q;int ret; + bsg_dev =kzalloc (sizeof (*bsg_dev),GFP_KERNEL ); +if (!bsg_dev) +return -ENOMEM ; + + hba->bsg_dev = bsg_dev;device_initialize (bsg_dev); bsg_dev->parent =get_device (parent);@@ -217,6 +225,41 @@ int ufs_bsg_probe(struct ufs_hba *hba) out:dev_err (bsg_dev,"fail to initialize a bsg dev %d\n" , shost->host_no); + hba->bsg_dev =NULL ;put_device (bsg_dev);return ret; } + +static int __init ufs_bsg_init (void ) +{drivers/scsi/ufs/ufs_bsg.c int ufs_bsg_probe(struct ufs_hba *hba) · line 244
Quoted 10 lines
drivers/scsi/ufs/ufs_bsg.c +10
-0+struct list_head *hba_list =NULL ; +struct ufs_hba *hba; +int ret =0 ; + +ufshcd_get_hba_list_lock (&hba_list); +list_for_each_entry (hba, hba_list, list) { + ret =ufs_bsg_probe (hba); +if (ret) +break ; + }So what happens if I go
CONFIG_SCSI_UFS_BSG=yandCONFIG_SCSI_UFS_QCOM=y?Quoted 4 lines
Wouldn't that mean that
ufs_bsg_init()is called beforeufshcd_init()has added the controller to the list? And even in the even that they are both =m, what happens if they are invoked in the "wrong" order?Quoted 7 lines
In the case that
CONFIG_SCSI_UFS_BSG=yandCONFIG_SCSI_UFS_QCOM=y, I givelate_initcall_sync(ufs_bsg_init)to make sureufs_bsg_initis invoked only after platform driver is probed. I tested this combination.In the case that both of them are "m", installing ufs-bsg before ufs-qcom is installed would have no effect as
ufs_hba_listis empty, which is expected.Why is it the expected behavior that bsg may or may not probe depending on the driver load order and potentially timing of the initialization.
Quoted 3 lines
And in real cases, as the UFS is the boot device, UFS driver will always be probed during bootup.
The UFS driver will load and probe because it's mentioned in the devicetree, but if either the ufs drivers or any of its dependencies (phy, resets, clocks, etc) are built as modules it might very well finish probing after lateinitcall.
Quoted 8 lines
Quoted 5 lines
So in the even that the bsg is =y and any of these drivers are =m, or if you're having bad luck with your timing, the list will be empty.
As described below, if bsg=m, then there's nothing that will load the module and the bsg will not probe...
Right.
bsg=y and ufshcd=m is a bad idea, and should be avoided.
Yeah, I will get it addressed in the next patchset.
Thanks,
Can Guo.
Quoted 35 lines
Quoted 35 lines
[..]
Quoted 1 line
Quoted 1 line
Quoted 1 line
drivers/scsi/ufs/ufshcd.c +0
-0[..]
Quoted 14 lines
Quoted 14 lines
drivers/scsi/ufs/ufshcd.c int ufshcd_shutdown(struct ufs_hba *hba) · line 8272
Quoted 10 lines
void
ufshcd_remove(struct ufs_hba *hba)
{
-ufs_bsg_remove(hba);
+ struct device*bsg_dev=hba->bsg_dev;drivers/scsi/ufs/ufshcd.c +6
-0+ +mutex_lock (&ufs_hba_list_lock); +list_del (&hba->list); +if (hba->bsg_queue) { +bsg_remove_queue (hba->bsg_queue); +device_del (bsg_dev);Am I reading this correct in that you probe the
bsg_devform initcall and you delete it as the ufshcd instance is removed? That's not okay.Quoted 7 lines
Quoted 3 lines
Regards,
BjornIf ufshcd is removed, its ufs-bsg, if exists, should also be removed. Could you please enlighten me a better way to do this? Thanks.
It's the asymmetry that I don't like.
Perhaps if you instead make ufshcd
platform_device_register_data()the bsg device you would solve the probe ordering, the remove will be symmetric and module autoloading will work as well (although then you need aMODULE_ALIASof platform:device-name).Regards,
Bjorn
A message that is not in the archive (sent off-list or not yet received): 0101016efb07efac-32cf270a-68dd-455a-b037-9fac2f3834cd-000000@us-west-2.amazonses.com
Re: [PATCH v2 2/3] scsi: ufs: Modulize ufs-bsg
Quoted 4 lines · On Thu 12 Dec 08:53 PST 2019, [email protected] wrote:
Quoted 3 lines · Avri Altman
Quoted 3 lines · On Wed 11 Dec 22:01 PST 2019, [email protected] wrote:
Quoted 2 lines · Bjorn Andersson
Quoted 1 line · Can Guo
[..]
Quoted 13 lines
Quoted 13 lines
Quoted 13 lines
Quoted 3 lines
And in real cases, as the UFS is the boot device, UFS driver will always be probed during bootup.
The UFS driver will load and probe because it's mentioned in the devicetree, but if either the ufs drivers or any of its dependencies (phy, resets, clocks, etc) are built as modules it might very well finish probing after lateinitcall.
So in the even that the bsg is =y and any of these drivers are =m, or if
you're having bad luck with your timing, the list will be empty.
Quoted 8 lines
Quoted 5 lines
Quoted 2 lines
As described below, if bsg=m, then there's nothing that will load the module and the bsg will not probe...
Right.
bsg=y and ufshcd=m is a bad idea, and should be avoided.Yeah, I will get it addressed in the next patchset.
If you build this around platform_device_register_data() from ufshcd I don't see a reason to add additional restrictions on this combination (even though it might not make much sense for people to use this combination).
Regards,
Bjorn
Re: [PATCH v2 2/3] scsi: ufs: Modulize ufs-bsg
Quoted 29 lines · Bjorn Andersson
Quoted 4 lines · On Thu 12 Dec 08:53 PST 2019, [email protected] wrote:
Quoted 3 lines · Avri Altman
Quoted 3 lines · On Wed 11 Dec 22:01 PST 2019, [email protected] wrote:
Quoted 2 lines · Bjorn Andersson
Quoted 1 line · Can Guo
[..]
Quoted 13 lines
Quoted 13 lines
Quoted 13 lines
Quoted 3 lines
And in real cases, as the UFS is the boot device, UFS driver will always be probed during bootup.
The UFS driver will load and probe because it's mentioned in the devicetree, but if either the ufs drivers or any of its dependencies (phy, resets, clocks, etc) are built as modules it might very well finish probing after lateinitcall.
So in the even that the bsg is =y and any of these drivers are =m, or if
you're having bad luck with your timing, the list will be empty.Quoted 8 lines
Quoted 5 lines
Quoted 2 lines
As described below, if bsg=m, then there's nothing that will load the module and the bsg will not probe...
Right.
bsg=y and ufshcd=m is a bad idea, and should be avoided.Yeah, I will get it addressed in the next patchset.
Quoted 7 lines
If you build this around
platform_device_register_data()from ufshcd I don't see a reason to add additional restrictions on this combination (even though it might not make much sense for people to use this combination).Regards,
Bjorn
Agree, thanks.
Regards,
Can Guo.
RE: [PATCH v2 2/3] scsi: ufs: Modulize ufs-bsg
Quoted 39 lines · Bjorn Andersson
Quoted 34 lines · On Thu 12 Dec 08:53 PST 2019, [email protected] wrote:
Quoted 5 lines · Avri Altman
Quoted 3 lines
Quoted 3 lines · On Wed 11 Dec 22:01 PST 2019, [email protected] wrote:
Quoted 2 lines · Bjorn Andersson
Quoted 1 line · Can Guo
[..]
Quoted 13 lines
Quoted 13 lines
Quoted 13 lines
Quoted 3 lines
And in real cases, as the UFS is the boot device, UFS driver will always be probed during bootup.
The UFS driver will load and probe because it's mentioned in the devicetree, but if either the ufs drivers or any of its dependencies (phy, resets, clocks, etc) are built as modules it might very well finish probing after lateinitcall.
So in the even that the bsg is =y and any of these drivers are =m, or if you're having bad luck with your timing, the list will be empty.
Quoted 8 lines
Quoted 5 lines
Quoted 2 lines
As described below, if bsg=m, then there's nothing that will load the module and the bsg will not probe...
Right.
bsg=y and ufshcd=m is a bad idea, and should be avoided.Yeah, I will get it addressed in the next patchset.
If you build this around
platform_device_register_data()from ufshcd I don't see a reason to add additional restrictions on this combination (even though it might not make much sense for people to use this combination).
Quoted 4 lines
Quoted 2 lines
Regards,
BjornAgree, thanks.
While at it, maybe you can add few words in the "BSG Support" paragraph, In Documentation/scsi/ufs.txt.
Thanks,
Avri
Re: [PATCH v2 2/3] scsi: ufs: Modulize ufs-bsg
In reply to Bjorn AnderssonQuoted 212 lines · Bjorn Andersson
Quoted 157 lines · On Wed 11 Dec 22:01 PST 2019, [email protected] wrote:
Quoted 11 lines · Bjorn Andersson
Quoted 5 lines · Can Guo
In order to improve the flexibility of ufs-bsg, modulizing it is a good
choice. This change introduces tristate to ufs-bsg to allow users compile
it as an external module.Can you please elaborate on what this "flexibility" is and why it's a good thing?
ufs-bsg is a helpful gadget for debug/test purpose. But neither disabling it nor enabling it is the best way on a commercialized device. Disabling it means we cannot use it, while enabling it by default will expose all the DEVM/UIC/TM interfaces to user space, which is not "safe" on a commercialized device to let users play with it. Making it a module can resolve this, because only vendors can install it as they have the root permissions.
Quoted 12 lines
Quoted 12 lines
Signed-off-by Can Guo <[email protected]>--- drivers/scsi/ufs/Kconfig | 3 ++- drivers/scsi/ufs/Makefile | 2 +- drivers/scsi/ufs/ufs_bsg.c | 49 +++++++++++++++++++++++++++++++++++++++++++--- drivers/scsi/ufs/ufs_bsg.h | 8 -------- drivers/scsi/ufs/ufshcd.c | 36 ++++++++++++++++++++++++++++++---- drivers/scsi/ufs/ufshcd.h | 7 ++++++- 6 files changed, 87 insertions(+), 18 deletions(-)Quoted 12 lines
drivers/scsi/ufs/Kconfig config SCSI_UFSHCD · line 41
Quoted 9 lines
drivers/scsi/ufs/Kconfig +1
-0@@ -38,6 +38,7 @@ config SCSI_UFSHCD select PM_DEVFREQ select DEVFREQ_GOV_SIMPLE_ONDEMAND select NLS + select BLK_DEV_BSGLIBWhy is this needed?
Because
ufshcd.cneeds to call some funcs defined in bsg lib.Quoted 104 lines
Quoted 90 lines
drivers/scsi/ufs/Kconfig +1
-1---help--- This selects the support for UFS devices in Linux, say Y and make sure that you know the name of your UFS host adapter (the card@@ -143,7 +144,7 @@ config SCSI_UFS_TI_J721E If unsure, say N. config SCSI_UFS_BSG - bool "Universal Flash Storage BSG device node" + tristate "Universal Flash Storage BSG device node" depends on SCSI_UFSHCD select BLK_DEV_BSGLIB helpdrivers/scsi/ufs/Makefile +1
-1@@ -6,7 +6,7 @@ obj-$(CONFIG_SCSI_UFS_CDNS_PLATFORM) += cdns-pltfrm.o obj-$(CONFIG_SCSI_UFS_QCOM) += ufs-qcom.o obj-$(CONFIG_SCSI_UFSHCD) += ufshcd-core.o ufshcd-core-y += ufshcd.o ufs-sysfs.o -ufshcd-core-$(CONFIG_SCSI_UFS_BSG) += ufs_bsg.o +obj-$(CONFIG_SCSI_UFS_BSG) += ufs_bsg.o obj-$(CONFIG_SCSI_UFSHCD_PCI) += ufshcd-pci.o obj-$(CONFIG_SCSI_UFSHCD_PLATFORM) += ufshcd-pltfrm.o obj-$(CONFIG_SCSI_UFS_HISI) += ufs-hisi.odrivers/scsi/ufs/ufs_bsg.c +4
-1@@ -164,13 +164,15 @@ static int ufs_bsg_request(struct bsg_job *job)*/ void ufs_bsg_remove (struct ufs_hba *hba) { -struct device *bsg_dev = &hba->bsg_dev; +struct device *bsg_dev = hba->bsg_dev;if (!hba->bsg_queue)return ;bsg_remove_queue (hba->bsg_queue); + hba->bsg_dev =NULL ; + hba->bsg_queue =NULL ;device_del (bsg_dev);put_device (bsg_dev); }@@ -178,6 +180,7 @@ void ufs_bsg_remove(struct ufs_hba *hba)static inline void ufs_bsg_node_release (struct device *dev) {put_device (dev->parent); +kfree (dev); }/** @@ -186,14 +189,19 @@ static inline void ufs_bsg_node_release(struct device *dev) * * Called during initial loading of the driver, and before
scsi_scan_host.
*/drivers/scsi/ufs/ufs_bsg.c +11
-2-int ufs_bsg_probe (struct ufs_hba *hba) +static int ufs_bsg_probe (struct ufs_hba *hba) { -struct device *bsg_dev = &hba->bsg_dev; +struct device *bsg_dev;struct Scsi_Host *shost = hba->host;struct device *parent = &shost->shost_gendev;struct request_queue *q;int ret; + bsg_dev =kzalloc (sizeof (*bsg_dev),GFP_KERNEL ); +if (!bsg_dev) +return -ENOMEM ; + + hba->bsg_dev = bsg_dev;device_initialize (bsg_dev); bsg_dev->parent =get_device (parent);@@ -217,6 +225,41 @@ int ufs_bsg_probe(struct ufs_hba *hba) out:dev_err (bsg_dev,"fail to initialize a bsg dev %d\n" , shost->host_no); + hba->bsg_dev =NULL ;put_device (bsg_dev);return ret; } + +static int __init ufs_bsg_init (void ) +{drivers/scsi/ufs/ufs_bsg.c int ufs_bsg_probe(struct ufs_hba *hba) · line 244
Quoted 10 lines
drivers/scsi/ufs/ufs_bsg.c +10
-0+struct list_head *hba_list =NULL ; +struct ufs_hba *hba; +int ret =0 ; + +ufshcd_get_hba_list_lock (&hba_list); +list_for_each_entry (hba, hba_list, list) { + ret =ufs_bsg_probe (hba); +if (ret) +break ; + }So what happens if I go
CONFIG_SCSI_UFS_BSG=yandCONFIG_SCSI_UFS_QCOM=y?Quoted 4 lines
Wouldn't that mean that
ufs_bsg_init()is called beforeufshcd_init()has added the controller to the list? And even in the even that they are both =m, what happens if they are invoked in the "wrong" order?Quoted 7 lines
In the case that
CONFIG_SCSI_UFS_BSG=yandCONFIG_SCSI_UFS_QCOM=y, I givelate_initcall_sync(ufs_bsg_init)to make sureufs_bsg_initis invoked only after platform driver is probed. I tested this combination.In the case that both of them are "m", installing ufs-bsg before ufs-qcom is installed would have no effect as
ufs_hba_listis empty, which is expected.Why is it the expected behavior that bsg may or may not probe depending on the driver load order and potentially timing of the initialization.
Quoted 3 lines
And in real cases, as the UFS is the boot device, UFS driver will always be probed during bootup.
The UFS driver will load and probe because it's mentioned in the devicetree, but if either the ufs drivers or any of its dependencies (phy, resets, clocks, etc) are built as modules it might very well finish probing after lateinitcall.
So in the even that the bsg is =y and any of these drivers are =m, or if you're having bad luck with your timing, the list will be empty.
As described below, if bsg=m, then there's nothing that will load the module and the bsg will not probe...
[..]
Quoted 1 line
Quoted 1 line
Quoted 1 line
drivers/scsi/ufs/ufshcd.c +0
-0[..]
Quoted 14 lines
Quoted 14 lines
drivers/scsi/ufs/ufshcd.c int ufshcd_shutdown(struct ufs_hba *hba) · line 8272
Quoted 10 lines
void
ufshcd_remove(struct ufs_hba *hba)
{drivers/scsi/ufs/ufshcd.c +7
-1-ufs_bsg_remove (hba); +struct device *bsg_dev = hba->bsg_dev; + +mutex_lock (&ufs_hba_list_lock); +list_del (&hba->list); +if (hba->bsg_queue) { +bsg_remove_queue (hba->bsg_queue); +device_del (bsg_dev);Am I reading this correct in that you probe the
bsg_devform initcall and you delete it as the ufshcd instance is removed? That's not okay.Quoted 7 lines
Quoted 3 lines
Regards,
BjornIf ufshcd is removed, its ufs-bsg, if exists, should also be removed. Could you please enlighten me a better way to do this? Thanks.
It's the asymmetry that I don't like.
Quoted 7 lines
Perhaps if you instead make ufshcd
platform_device_register_data()the bsg device you would solve the probe ordering, the remove will be symmetric and module autoloading will work as well (although then you need aMODULE_ALIASof platform:device-name).Regards,
Bjorn
Thanks for the suggestion! I didn't even think about this before. I will go with the platform_device_register_data() way, it will be much easier. After I get my new patchset tested I will upload it for review.
Best Regards,
Can Guo.
Re: [PATCH v2 2/3] scsi: ufs: Modulize ufs-bsg
In reply to Bjorn AnderssonQuoted 6 lines · Bjorn Andersson
It's the asymmetry that I don't like.
Perhaps if you instead make ufshcd
platform_device_register_data()the bsg device you would solve the probe ordering, the remove will be symmetric and module autoloading will work as well (although then you need aMODULE_ALIASof platform:device-name).
Hi Bjorn,
From Documentation/driver-api/driver-model/platform.rst:
"Platform devices are devices that typically appear as autonomous entities in the system. This includes legacy port-based devices and host bridges to peripheral buses, and most controllers integrated into system-on-chip platforms. What they usually have in common is direct addressing from a CPU bus. Rarely, a platform_device will be connected through a segment of some other kind of bus; but its registers will still be directly addressable."
Do you agree that the above description is not a good match for the ufs-bsg kernel module?
Thanks,
Bart.
Re: [PATCH v2 2/3] scsi: ufs: Modulize ufs-bsg
Quoted 19 lines · Bart Van Assche
Quoted 6 lines · Bjorn Andersson
It's the asymmetry that I don't like.
Perhaps if you instead make ufshcd
platform_device_register_data()the bsg device you would solve the probe ordering, the remove will be symmetric and module autoloading will work as well (although then you need aMODULE_ALIASof platform:device-name).Hi Bjorn,
From
Documentation/driver-api/driver-model/platform.rst:
"Platform devices are devices that typically appear as autonomous entities in the system. This includes legacy port-based devices and host bridges to peripheral buses, and most controllers integrated into system-on-chip platforms. What they usually have in common is direct addressing from a CPU bus. Rarely, aplatform_devicewill be connected through a segment of some other kind of bus; but its registers will still be directly addressable."
Quoted 6 lines
Do you agree that the above description is not a good match for the ufs-bsg kernel module?
Thanks,
Bart.
Hi Bart,
I missed this one.
How about making it a plain device and add it from ufs driver?
Thanks,
Can Guo.
Re: [PATCH v2 2/3] scsi: ufs: Modulize ufs-bsg
Quoted 20 lines · On 12/15/19 8:36 PM, [email protected] wrote:
Quoted 19 lines · Bart Van Assche
Quoted 6 lines · Bjorn Andersson
It's the asymmetry that I don't like.
Perhaps if you instead make ufshcd
platform_device_register_data()the bsg device you would solve the probe ordering, the remove will be symmetric and module autoloading will work as well (although then you need aMODULE_ALIASof platform:device-name).Hi Bjorn,
From
Documentation/driver-api/driver-model/platform.rst:
"Platform devices are devices that typically appear as autonomous entities in the system. This includes legacy port-based devices and host bridges to peripheral buses, and most controllers integrated into system-on-chip platforms. What they usually have in common is direct addressing from a CPU bus. Rarely, aplatform_devicewill be connected through a segment of some other kind of bus; but its registers will still be directly addressable."
Quoted 5 lines
Quoted 2 lines
Do you agree that the above description is not a good match for the ufs-bsg kernel module?
I missed this one.
How about making it a plain device and add it from ufs driver?
Hi Can,
Since the ufs_bsg kernel module already creates one device node under /dev/bsg for each UFS host I don't think that we need to create any additional device nodes for ufs-bsg devices. My proposal is to modify the original patch 2/3 from this series as follows:
* Use module_init() instead of late_initcall_sync().
* Remove the ufshcd_get_hba_list_lock() and
ufshcd_put_hba_list_unlock() functions.
* Implement a notification mechanism in the UFS core that invokes a
callback function after an UFS host has been created and also after an
UFS host has been removed.
* Register for these notifications from inside the ufs-bsg driver.
* During registration for notifications, invoke the UFS host creation
callback function for all known UFS hosts.
* If the UFS core is unloaded, invoke the UFS host removal callback
function for all known UFS hosts.
I think there are several examples of similar notification mechanisms in the Linux kernel, e.g. the probe and remove callback functions in struct pci_driver.
Bart.
Re: [PATCH v2 2/3] scsi: ufs: Modulize ufs-bsg
Quoted 29 lines · Bart Van Assche
Quoted 20 lines · On 12/15/19 8:36 PM, [email protected] wrote:
Quoted 19 lines · Bart Van Assche
Quoted 6 lines · Bjorn Andersson
It's the asymmetry that I don't like.
Perhaps if you instead make ufshcd
platform_device_register_data()the bsg device you would solve the probe ordering, the remove will be symmetric and module autoloading will work as well (although then you need aMODULE_ALIASof platform:device-name).Hi Bjorn,
From
Documentation/driver-api/driver-model/platform.rst:
"Platform devices are devices that typically appear as autonomous entities in the system. This includes legacy port-based devices and host bridges to peripheral buses, and most controllers integrated into system-on-chip platforms. What they usually have in common is direct addressing from a CPU bus. Rarely, aplatform_devicewill be connected through a segment of some other kind of bus; but its registers will still be directly addressable."Quoted 5 lines
Quoted 2 lines
Do you agree that the above description is not a good match for the ufs-bsg kernel module?
I missed this one.
How about making it a plain device and add it from ufs driver?Hi Can,
Quoted 10 lines
Since the
ufs_bsgkernel module already creates one device node under/dev/bsgfor each UFS host I don't think that we need to create any additional device nodes for ufs-bsg devices. My proposal is to modify the original patch 2/3 from this series as follows:
* Usemodule_init()instead oflate_initcall_sync().
* Remove theufshcd_get_hba_list_lock()andufshcd_put_hba_list_unlock()functions.
* Implement a notification mechanism in the UFS core that invokes a callback function after an UFS host has been created and also after an UFS host has been removed.
You want to be a bus and have a device on it.
Quoted 1 line
* Register for these notifications from inside the ufs-bsg driver.
You want to be a bus.
Quoted 2 lines
* During registration for notifications, invoke the UFS host creation callback function for all known UFS hosts.
You want to be a bus.
Quoted 2 lines
* If the UFS core is unloaded, invoke the UFS host removal callback function for all known UFS hosts.
Again, a bus would do all of this for you "for free", right?
Take a look at the crazy "virtual bus" code that the RDMA people are proposing if you want to try to use something like that, or just take 200 lines of code and be your own bus and devices that hang off of it. That sounds exactly what you are looking for here.
Quoted 3 lines
I think there are several examples of similar notification mechanisms in the Linux kernel, e.g. the probe and remove callback functions in struct
pci_driver.
Look, a bus! :)
thanks,
greg k-h
Re: [PATCH v2 2/3] scsi: ufs: Modulize ufs-bsg
In reply to Bart Van AsscheQuoted 46 lines · Bart Van Assche
Quoted 20 lines · On 12/15/19 8:36 PM, [email protected] wrote:
Quoted 19 lines · Bart Van Assche
Quoted 6 lines · Bjorn Andersson
It's the asymmetry that I don't like.
Perhaps if you instead make ufshcd
platform_device_register_data()the bsg device you would solve the probe ordering, the remove will be symmetric and module autoloading will work as well (although then you need aMODULE_ALIASof platform:device-name).Hi Bjorn,
From
Documentation/driver-api/driver-model/platform.rst:
"Platform devices are devices that typically appear as autonomous entities in the system. This includes legacy port-based devices and host bridges to peripheral buses, and most controllers integrated into system-on-chip platforms. What they usually have in common is direct addressing from a CPU bus. Rarely, aplatform_devicewill be connected through a segment of some other kind of bus; but its registers will still be directly addressable."Quoted 5 lines
Quoted 2 lines
Do you agree that the above description is not a good match for the ufs-bsg kernel module?
I missed this one.
How about making it a plain device and add it from ufs driver?Hi Can,
Since the
ufs_bsgkernel module already creates one device node under/dev/bsgfor each UFS host I don't think that we need to create any additional device nodes for ufs-bsg devices. My proposal is to modify the original patch 2/3 from this series as follows:
* Usemodule_init()instead oflate_initcall_sync().
* Remove theufshcd_get_hba_list_lock()andufshcd_put_hba_list_unlock()functions.
* Implement a notification mechanism in the UFS core that invokes a callback function after an UFS host has been created and also after
an
UFS host has been removed.
* Register for these notifications from inside the ufs-bsg driver.
* During registration for notifications, invoke the UFS host creation callback function for all known UFS hosts.
* If the UFS core is unloaded, invoke the UFS host removal callback function for all known UFS hosts.
Quoted 5 lines
I think there are several examples of similar notification mechanisms in the Linux kernel, e.g. the probe and remove callback functions in struct
pci_driver.Bart.
Hi Bart,
Even in the current ufs_bsg.c, it creates two devices, one is ufs-bsg, one is the char dev node under /dev/bsg. Why this becomes a problem after make it a module?
I took a look into the pci_driver, it is no different than making ufs-bsg a plain device. The only special place about pci_driver is that it has its own probe() and remove(), and the probe() in its bus_type calls the probe() in pci_driver. Meaning the bus->probe() is an intermediate call used to pass whatever needed by pci_driver->probe().
Of course we can also do this, but isn't it too much for ufs-bsg? For our case, calling set_dev_drvdata(bsg_dev, hba) to pass hba to ufs_bsg.c would be enough.
If you take a look at the V3 patch, the change makes the ufs_bsg.c much conciser. platform_device_register_data() does everything for us, initialize the device, set device name, provide the match func, bus type and release func.
Since ufs-bsg is somewhat not a platform device, we can still add it as a plain device, just need a few more lines to get it initialized. This allows us leverage kernel's device driver model. Just like Greg commented, we don't need to re-implement the mechanism again.
Thanks,
Can Guo.
Re: [PATCH v2 2/3] scsi: ufs: Modulize ufs-bsg
Quoted 19 lines · On 12/17/19 12:56 AM, [email protected] wrote:
Even in the current
ufs_bsg.c, it creates two devices, one is ufs-bsg, one is the char dev node under/dev/bsg. Why this becomes a problem after make it a module?I took a look into the
pci_driver, it is no different than making ufs-bsg a plain device. The only special place aboutpci_driveris that it has its ownprobe()andremove(), and theprobe()in itsbus_typecalls theprobe()inpci_driver. Meaning thebus->probe()is an intermediate call used to pass whatever needed bypci_driver->probe().Of course we can also do this, but isn't it too much for ufs-bsg? For our case, calling
set_dev_drvdata(bsg_dev, hba)to pass hba toufs_bsg.cwould be enough.If you take a look at the V3 patch, the change makes the
ufs_bsg.cmuch conciser.platform_device_register_data()does everything for us, initialize the device, set device name, provide the match func, bus type and release func.
Quoted 4 lines
Since ufs-bsg is somewhat not a platform device, we can still add it as a plain device, just need a few more lines to get it initialized. This allows us leverage kernel's device driver model. Just like Greg commented, we don't need to re-implement the mechanism again.
Hi Can,
Since ufs-bsg is not a platform device I think it would be wrong to model ufs-bsg devices as platform devices.
Please have a look at the bus_register() and bus_unregister() functions as Greg KH asked. Using the bus abstraction is not that hard. An example is e.g. available in the scsi_debug driver, namely the pseudo_lld_bus.
Thanks,
Bart.
Re: [PATCH v2 2/3] scsi: ufs: Modulize ufs-bsg
Quoted 30 lines · Bart Van Assche
Quoted 19 lines · On 12/17/19 12:56 AM, [email protected] wrote:
Even in the current
ufs_bsg.c, it creates two devices, one is ufs-bsg, one is the char dev node under/dev/bsg. Why this becomes a problem after make it a module?I took a look into the
pci_driver, it is no different than making ufs-bsg a plain device. The only special place aboutpci_driveris that it has its ownprobe()andremove(), and theprobe()in itsbus_typecalls theprobe()inpci_driver. Meaning thebus->probe()is an intermediate call used to pass whatever needed bypci_driver->probe().Of course we can also do this, but isn't it too much for ufs-bsg? For our case, calling
set_dev_drvdata(bsg_dev, hba)to pass hba toufs_bsg.cwould be enough.If you take a look at the V3 patch, the change makes the
ufs_bsg.cmuch conciser.platform_device_register_data()does everything for us, initialize the device, set device name, provide the match func, bus type and release func.Quoted 4 lines
Since ufs-bsg is somewhat not a platform device, we can still add it as a plain device, just need a few more lines to get it initialized. This allows us leverage kernel's device driver model. Just like Greg commented, we don't need to re-implement the mechanism again.
Hi Can,
Since ufs-bsg is not a platform device I think it would be wrong to model ufs-bsg devices as platform devices.
Quoted 8 lines
Please have a look at the
bus_register()andbus_unregister()functions as Greg KH asked. Using the bus abstraction is not that hard. An example is e.g. available in thescsi_debugdriver, namely thepseudo_lld_bus.Thanks,
Bart.
Hi Bart,
Yes, I am talking the same here. Since platform device is not an option for ufs-bsg, to make it a plain device we would need to do bus_register() and bus_unregister(). And also do device_initialize() and device_add().
Thanks,
Can Guo.
A message that is not in the archive (sent off-list or not yet received): 0101016ef425ed74-071c2ec2-5aeb-44fa-8889-d9ec60192d44-000000@us-west-2.amazonses.com
Re: [PATCH v2 2/3] scsi: ufs: Modulize ufs-bsg
Hi,
Quoted 6 lines · Can Guo
In order to improve the flexibility of ufs-bsg, modulizing it is a good choice. This change introduces tristate to ufs-bsg to allow users compile it as an external module.
Signed-off-by Can Guo <[email protected]>---
[...]
Quoted 19 lines
(quoted diff) +7
-2-int ufs_bsg_probe(struct ufs_hba *hba) +static int ufs_bsg_probe(struct ufs_hba *hba) { - struct device *bsg_dev = &hba->bsg_dev; + struct device *bsg_dev; struct Scsi_Host *shost = hba->host; struct device *parent = &shost->shost_gendev; struct request_queue *q; int ret; + bsg_dev = kzalloc(sizeof(*bsg_dev), GFP_KERNEL); + if (!bsg_dev) + return -ENOMEM; + + hba->bsg_dev = bsg_dev; device_initialize(bsg_dev); bsg_dev->parent = get_device(parent);
Review int ufs_bsg_probe(struct ufs_hba *hba) · line 228
Quoted 4 lines
(quoted diff) +1
-0@@ -217,6 +225,41 @@ int ufs_bsg_probe(struct ufs_hba *hba) out: dev_err(bsg_dev, "fail to initialize a bsg dev %d\n", shost->host_no); + hba->bsg_dev = NULL;
Don't we need to free the associated memory before assigning to NULL? Alternatively can allocation be made with devm_ APIs instead?
Quoted 6 lines
(quoted diff) +3
-0put_device(bsg_dev); return ret; } + +static int __init ufs_bsg_init(void) +{
Review int ufs_bsg_probe(struct ufs_hba *hba) · line 244
Quoted 10 lines
(quoted diff) +10
-0+ struct list_head *hba_list = NULL; + struct ufs_hba *hba; + int ret = 0; + + ufshcd_get_hba_list_lock(&hba_list); + list_for_each_entry(hba, hba_list, list) { + ret = ufs_bsg_probe(hba); + if (ret) + break; + }
So IIUC, if ufs_bsg_probe() fails for one of the hba instances in the list, then we fail to create bsg device for all remaining instances that follow, which seems too harsh.
Regards
Vignesh
A message that is not in the archive (sent off-list or not yet received): 0101016ef425e749-1808e138-740e-4036-922f-7a49ec02c2b8-000000@us-west-2.amazonses.com
Re: [PATCH v2 2/3] scsi: ufs: Modulize ufs-bsg
Quoted 3 lines · Can Guo
In order to improve the flexibility of ufs-bsg, modulizing it is a good choice. This change introduces tristate to ufs-bsg to allow users compile it as an external module.
Did you perhaps mean "modularize" instead of "modulize"? Additionally, should "modulizing" perhaps be changed into "modularizing"?
drivers/scsi/ufs/Kconfig config SCSI_UFSHCD · line 44
Quoted 12 lines
drivers/scsi/ufs/Kconfig +1
-0@@ -38,6 +38,7 @@ config SCSI_UFSHCD select PM_DEVFREQ select DEVFREQ_GOV_SIMPLE_ONDEMAND select NLS + select BLK_DEV_BSGLIB ---help--- This selects the support for UFS devices in Linux, say Y and make sure that you know the name of your UFS host adapter (the card
I do not understand the above change. Doesn't moving the BSG code into a separate module remove the dependency of SCSI_UFSHCD on BLK_DEV_BSGLIB?
Quoted 6 lines
drivers/scsi/ufs/Kconfig +6
-0+static int __init ufs_bsg_init(void) +{ + struct list_head *hba_list = NULL; + struct ufs_hba *hba; + int ret = 0; +
drivers/scsi/ufs/Kconfig
Quoted 10 lines
drivers/scsi/ufs/Kconfig +10
-0+ ufshcd_get_hba_list_lock(&hba_list); + list_for_each_entry(hba, hba_list, list) { + ret = ufs_bsg_probe(hba); + if (ret) + break; + } + ufshcd_put_hba_list_unlock(); + + return ret; +}
What if ufs_bsg_probe() succeeds for some UFS adapters but not for others? Shouldn't ufs_bgs_remove() be called in that case for the adapters for which ufs_bsg_probe() succeeded?
drivers/scsi/ufs/Kconfig
Quoted 2 lines
drivers/scsi/ufs/Kconfig +2
-0+late_initcall_sync(ufs_bsg_init); +module_exit(ufs_bsg_exit);
Why late_initcall_sync() instead of module_init()?
Quoted 7 lines
drivers/scsi/ufs/ufshcd.c +0
-0@@ -108,6 +108,22 @@ 16, 4, buf, __len, false); \ }while (0 )
drivers/scsi/ufs/ufshcd.c line 119
Quoted 10 lines
drivers/scsi/ufs/ufshcd.c +9
-0+static LIST_HEAD (ufs_hba_list); +static DEFINE_MUTEX (ufs_hba_list_lock); + +void ufshcd_get_hba_list_lock (struct list_head **list) +{ +mutex_lock (&ufs_hba_list_lock); + *list = &ufs_hba_list; +} +EXPORT_SYMBOL_GPL (ufshcd_get_hba_list_lock);
Please make ufshcd_get_hba_list_lock() return the list_head pointer instead of the above.
Thanks,
Bart.