forked from clearlinux-pkgs/linux-iot-lts2018
-
Notifications
You must be signed in to change notification settings - Fork 0
/
0026-scsi-ufs-store-device-serial-number.patch
154 lines (132 loc) · 4.34 KB
/
0026-scsi-ufs-store-device-serial-number.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
From 76b04633d28429c2800fc694d315bd2f3acfff30 Mon Sep 17 00:00:00 2001
From: Tomas Winkler <[email protected]>
Date: Thu, 14 May 2015 00:00:59 +0300
Subject: [PATCH 11/22] scsi: ufs: store device serial number.
Retrieve device serial number and store it for RPMB subsystem use.
V9: rebase
v10: Fix Kdoc
Change-Id: Ieee7f85696f6614cd2f3c81403124159ea85b77e
Signed-off-by: Tomas Winkler <[email protected]>
Signed-off-by: Alexander Usyskin <[email protected]>
---
drivers/scsi/ufs/ufs.h | 4 ++++
drivers/scsi/ufs/ufshcd.c | 35 +++++++++++++++++++++++++++++------
2 files changed, 33 insertions(+), 6 deletions(-)
diff --git a/drivers/scsi/ufs/ufs.h b/drivers/scsi/ufs/ufs.h
index c9774b59b6bf..b60dfcb5f009 100644
--- a/drivers/scsi/ufs/ufs.h
+++ b/drivers/scsi/ufs/ufs.h
@@ -614,10 +614,14 @@ struct ufs_dev_info {
*
* @wmanufacturerid: card details
* @model: card model
+ * @serial_no: serial number
+ * @serial_no_len: serial number string length
*/
struct ufs_dev_desc {
u16 wmanufacturerid;
char *model;
+ char *serial_no;
+ size_t serial_no_len;
};
/**
diff --git a/drivers/scsi/ufs/ufshcd.c b/drivers/scsi/ufs/ufshcd.c
index 3d8b47055b6c..e32741957288 100644
--- a/drivers/scsi/ufs/ufshcd.c
+++ b/drivers/scsi/ufs/ufshcd.c
@@ -43,6 +43,7 @@
#include <linux/nls.h>
#include <linux/of.h>
#include <linux/bitfield.h>
+#include <linux/string.h>
#include <linux/rpmb.h>
#include "ufshcd.h"
@@ -6366,12 +6367,19 @@ static struct rpmb_ops ufshcd_rpmb_dev_ops = {
};
-static inline void ufshcd_rpmb_add(struct ufs_hba *hba)
+static inline void ufshcd_rpmb_add(struct ufs_hba *hba,
+ struct ufs_dev_desc *dev_desc)
{
struct rpmb_dev *rdev;
u8 rpmb_rw_size = 1;
int ret;
+ ufshcd_rpmb_dev_ops.dev_id = kmemdup(dev_desc->serial_no,
+ dev_desc->serial_no_len,
+ GFP_KERNEL);
+ if (ufshcd_rpmb_dev_ops.dev_id)
+ ufshcd_rpmb_dev_ops.dev_id_len = dev_desc->serial_no_len;
+
ret = scsi_device_get(hba->sdev_ufs_rpmb);
if (ret)
goto out_put_dev;
@@ -6415,6 +6423,9 @@ static inline void ufshcd_rpmb_remove(struct ufs_hba *hba)
scsi_device_put(hba->sdev_ufs_rpmb);
hba->sdev_ufs_rpmb = NULL;
+ kfree(ufshcd_rpmb_dev_ops.dev_id);
+ ufshcd_rpmb_dev_ops.dev_id = NULL;
+
spin_unlock_irqrestore(hba->host->host_lock, flags);
}
@@ -6488,7 +6499,7 @@ static int ufs_get_device_desc(struct ufs_hba *hba,
{
int err;
size_t buff_len;
- u8 model_index;
+ u8 index;
u8 *desc_buf;
if (!dev_desc)
@@ -6516,8 +6527,8 @@ static int ufs_get_device_desc(struct ufs_hba *hba,
dev_desc->wmanufacturerid = desc_buf[DEVICE_DESC_PARAM_MANF_ID] << 8 |
desc_buf[DEVICE_DESC_PARAM_MANF_ID + 1];
- model_index = desc_buf[DEVICE_DESC_PARAM_PRDCT_NAME];
- err = ufshcd_read_string_desc(hba, model_index,
+ index = desc_buf[DEVICE_DESC_PARAM_PRDCT_NAME];
+ err = ufshcd_read_string_desc(hba, index,
&dev_desc->model, SD_ASCII_STD);
if (err < 0) {
dev_err(hba->dev, "%s: Failed reading Product Name. err = %d\n",
@@ -6525,6 +6536,14 @@ static int ufs_get_device_desc(struct ufs_hba *hba,
goto out;
}
+ index = desc_buf[DEVICE_DESC_PARAM_SN];
+ err = ufshcd_read_string_desc(hba, index, &dev_desc->serial_no, SD_RAW);
+ if (err < 0) {
+ dev_err(hba->dev, "%s: Failed reading Serial No. err = %d\n",
+ __func__, err);
+ goto out;
+ }
+
/*
* ufshcd_read_string_desc returns size of the string
* reset the error value
@@ -6540,6 +6559,9 @@ static void ufs_put_device_desc(struct ufs_dev_desc *dev_desc)
{
kfree(dev_desc->model);
dev_desc->model = NULL;
+
+ kfree(dev_desc->serial_no);
+ dev_desc->serial_no = NULL;
}
static void ufs_fixup_device_setup(struct ufs_hba *hba,
@@ -6835,7 +6857,6 @@ static int ufshcd_probe_hba(struct ufs_hba *hba)
}
ufs_fixup_device_setup(hba, &card);
- ufs_put_device_desc(&card);
ufshcd_tune_unipro_params(hba);
@@ -6885,7 +6906,7 @@ static int ufshcd_probe_hba(struct ufs_hba *hba)
if (ufshcd_scsi_add_wlus(hba))
goto out;
- ufshcd_rpmb_add(hba);
+ ufshcd_rpmb_add(hba, &card);
/* Initialize devfreq after UFS device is detected */
if (ufshcd_is_clkscaling_supported(hba)) {
@@ -6909,6 +6930,8 @@ static int ufshcd_probe_hba(struct ufs_hba *hba)
hba->is_init_prefetch = true;
out:
+
+ ufs_put_device_desc(&card);
/*
* If we failed to initialize the device or the device is not
* present, turn off the power/clocks etc.
--
2.19.1