@@ -100,7 +100,6 @@ static u32 ufs_query_desc_max_size[] = {
100
100
enum {
101
101
UFSHCD_MAX_CHANNEL = 0 ,
102
102
UFSHCD_MAX_ID = 1 ,
103
- UFSHCD_MAX_LUNS = 8 ,
104
103
UFSHCD_CMD_PER_LUN = 32 ,
105
104
UFSHCD_CAN_QUEUE = 32 ,
106
105
};
@@ -901,6 +900,21 @@ static int ufshcd_compose_upiu(struct ufs_hba *hba, struct ufshcd_lrb *lrbp)
901
900
return ret ;
902
901
}
903
902
903
+ /*
904
+ * ufshcd_scsi_to_upiu_lun - maps scsi LUN to UPIU LUN
905
+ * @scsi_lun: scsi LUN id
906
+ *
907
+ * Returns UPIU LUN id
908
+ */
909
+ static inline u8 ufshcd_scsi_to_upiu_lun (unsigned int scsi_lun )
910
+ {
911
+ if (scsi_is_wlun (scsi_lun ))
912
+ return (scsi_lun & UFS_UPIU_MAX_UNIT_NUM_ID )
913
+ | UFS_UPIU_WLUN_ID ;
914
+ else
915
+ return scsi_lun & UFS_UPIU_MAX_UNIT_NUM_ID ;
916
+ }
917
+
904
918
/**
905
919
* ufshcd_upiu_wlun_to_scsi_wlun - maps UPIU W-LUN id to SCSI W-LUN ID
906
920
* @scsi_lun: UPIU W-LUN id
@@ -970,7 +984,7 @@ static int ufshcd_queuecommand(struct Scsi_Host *host, struct scsi_cmnd *cmd)
970
984
lrbp -> sense_bufflen = SCSI_SENSE_BUFFERSIZE ;
971
985
lrbp -> sense_buffer = cmd -> sense_buffer ;
972
986
lrbp -> task_tag = tag ;
973
- lrbp -> lun = cmd -> device -> lun ;
987
+ lrbp -> lun = ufshcd_scsi_to_upiu_lun ( cmd -> device -> lun ) ;
974
988
lrbp -> intr_cmd = false;
975
989
lrbp -> command_type = UTP_CMD_TYPE_SCSI ;
976
990
@@ -1524,7 +1538,7 @@ static inline int ufshcd_read_unit_desc_param(struct ufs_hba *hba,
1524
1538
* Unit descriptors are only available for general purpose LUs (LUN id
1525
1539
* from 0 to 7) and RPMB Well known LU.
1526
1540
*/
1527
- if (lun >= UFS_UPIU_MAX_GENERAL_LUN )
1541
+ if (lun != UFS_UPIU_RPMB_WLUN && ( lun >= UFS_UPIU_MAX_GENERAL_LUN ) )
1528
1542
return - EOPNOTSUPP ;
1529
1543
1530
1544
return ufshcd_read_desc_param (hba , QUERY_DESC_IDN_UNIT , lun ,
@@ -2154,6 +2168,44 @@ static int ufshcd_verify_dev_init(struct ufs_hba *hba)
2154
2168
return err ;
2155
2169
}
2156
2170
2171
+ /**
2172
+ * ufshcd_set_queue_depth - set lun queue depth
2173
+ * @sdev: pointer to SCSI device
2174
+ *
2175
+ * Read bLUQueueDepth value and activate scsi tagged command
2176
+ * queueing. For WLUN, queue depth is set to 1. For best-effort
2177
+ * cases (bLUQueueDepth = 0) the queue depth is set to a maximum
2178
+ * value that host can queue.
2179
+ */
2180
+ static void ufshcd_set_queue_depth (struct scsi_device * sdev )
2181
+ {
2182
+ int ret = 0 ;
2183
+ u8 lun_qdepth ;
2184
+ struct ufs_hba * hba ;
2185
+
2186
+ hba = shost_priv (sdev -> host );
2187
+
2188
+ lun_qdepth = hba -> nutrs ;
2189
+ ret = ufshcd_read_unit_desc_param (hba ,
2190
+ ufshcd_scsi_to_upiu_lun (sdev -> lun ),
2191
+ UNIT_DESC_PARAM_LU_Q_DEPTH ,
2192
+ & lun_qdepth ,
2193
+ sizeof (lun_qdepth ));
2194
+
2195
+ /* Some WLUN doesn't support unit descriptor */
2196
+ if (ret == - EOPNOTSUPP )
2197
+ lun_qdepth = 1 ;
2198
+ else if (!lun_qdepth )
2199
+ /* eventually, we can figure out the real queue depth */
2200
+ lun_qdepth = hba -> nutrs ;
2201
+ else
2202
+ lun_qdepth = min_t (int , lun_qdepth , hba -> nutrs );
2203
+
2204
+ dev_dbg (hba -> dev , "%s: activate tcq with queue depth %d\n" ,
2205
+ __func__ , lun_qdepth );
2206
+ scsi_activate_tcq (sdev , lun_qdepth );
2207
+ }
2208
+
2157
2209
/**
2158
2210
* ufshcd_slave_alloc - handle initial SCSI device configurations
2159
2211
* @sdev: pointer to SCSI device
@@ -2163,8 +2215,6 @@ static int ufshcd_verify_dev_init(struct ufs_hba *hba)
2163
2215
static int ufshcd_slave_alloc (struct scsi_device * sdev )
2164
2216
{
2165
2217
struct ufs_hba * hba ;
2166
- u8 lun_qdepth ;
2167
- int ret ;
2168
2218
2169
2219
hba = shost_priv (sdev -> host );
2170
2220
sdev -> tagged_supported = 1 ;
@@ -2179,20 +2229,8 @@ static int ufshcd_slave_alloc(struct scsi_device *sdev)
2179
2229
/* REPORT SUPPORTED OPERATION CODES is not supported */
2180
2230
sdev -> no_report_opcodes = 1 ;
2181
2231
2182
- ret = ufshcd_read_unit_desc_param (hba ,
2183
- sdev -> lun ,
2184
- UNIT_DESC_PARAM_LU_Q_DEPTH ,
2185
- & lun_qdepth ,
2186
- sizeof (lun_qdepth ));
2187
- if (!ret || !lun_qdepth )
2188
- /* eventually, we can figure out the real queue depth */
2189
- lun_qdepth = hba -> nutrs ;
2190
- else
2191
- lun_qdepth = min_t (int , lun_qdepth , hba -> nutrs );
2192
2232
2193
- dev_dbg (hba -> dev , "%s: activate tcq with queue depth %d\n" ,
2194
- __func__ , lun_qdepth );
2195
- scsi_activate_tcq (sdev , lun_qdepth );
2233
+ ufshcd_set_queue_depth (sdev );
2196
2234
2197
2235
return 0 ;
2198
2236
}
@@ -2255,6 +2293,9 @@ static void ufshcd_slave_destroy(struct scsi_device *sdev)
2255
2293
2256
2294
hba = shost_priv (sdev -> host );
2257
2295
scsi_deactivate_tcq (sdev , hba -> nutrs );
2296
+ /* Drop the reference as it won't be needed anymore */
2297
+ if (ufshcd_scsi_to_upiu_lun (sdev -> lun ) == UFS_UPIU_UFS_DEVICE_WLUN )
2298
+ hba -> sdev_ufs_device = NULL ;
2258
2299
}
2259
2300
2260
2301
/**
@@ -2972,7 +3013,10 @@ static int ufshcd_issue_tm_cmd(struct ufs_hba *hba, int lun_id, int task_id,
2972
3013
lun_id , task_tag );
2973
3014
task_req_upiup -> header .dword_1 =
2974
3015
UPIU_HEADER_DWORD (0 , tm_function , 0 , 0 );
2975
-
3016
+ /*
3017
+ * The host shall provide the same value for LUN field in the basic
3018
+ * header and for Input Parameter.
3019
+ */
2976
3020
task_req_upiup -> input_param1 = cpu_to_be32 (lun_id );
2977
3021
task_req_upiup -> input_param2 = cpu_to_be32 (task_id );
2978
3022
@@ -4121,7 +4165,7 @@ int ufshcd_init(struct ufs_hba *hba, void __iomem *mmio_base, unsigned int irq)
4121
4165
host -> can_queue = hba -> nutrs ;
4122
4166
host -> cmd_per_lun = hba -> nutrs ;
4123
4167
host -> max_id = UFSHCD_MAX_ID ;
4124
- host -> max_lun = UFSHCD_MAX_LUNS ;
4168
+ host -> max_lun = UFS_MAX_LUNS ;
4125
4169
host -> max_channel = UFSHCD_MAX_CHANNEL ;
4126
4170
host -> unique_id = host -> host_no ;
4127
4171
host -> max_cmd_len = MAX_CDB_SIZE ;
0 commit comments