78
78
_ret; \
79
79
})
80
80
81
+ static u32 ufs_query_desc_max_size [] = {
82
+ QUERY_DESC_DEVICE_MAX_SIZE ,
83
+ QUERY_DESC_CONFIGURAION_MAX_SIZE ,
84
+ QUERY_DESC_UNIT_MAX_SIZE ,
85
+ QUERY_DESC_RFU_MAX_SIZE ,
86
+ QUERY_DESC_INTERCONNECT_MAX_SIZE ,
87
+ QUERY_DESC_STRING_MAX_SIZE ,
88
+ QUERY_DESC_RFU_MAX_SIZE ,
89
+ QUERY_DESC_GEOMETRY_MAZ_SIZE ,
90
+ QUERY_DESC_POWER_MAX_SIZE ,
91
+ QUERY_DESC_RFU_MAX_SIZE ,
92
+ };
93
+
81
94
enum {
82
95
UFSHCD_MAX_CHANNEL = 0 ,
83
96
UFSHCD_MAX_ID = 1 ,
@@ -124,8 +137,6 @@ static void ufshcd_tmc_handler(struct ufs_hba *hba);
124
137
static void ufshcd_async_scan (void * data , async_cookie_t cookie );
125
138
static int ufshcd_reset_and_restore (struct ufs_hba * hba );
126
139
static int ufshcd_clear_tm_cmd (struct ufs_hba * hba , int tag );
127
- static int ufshcd_read_sdev_qdepth (struct ufs_hba * hba ,
128
- struct scsi_device * sdev );
129
140
130
141
/*
131
142
* ufshcd_wait_for_register - wait for register value to change
@@ -1392,6 +1403,115 @@ static int ufshcd_query_descriptor(struct ufs_hba *hba,
1392
1403
return err ;
1393
1404
}
1394
1405
1406
+ /**
1407
+ * ufshcd_read_desc_param - read the specified descriptor parameter
1408
+ * @hba: Pointer to adapter instance
1409
+ * @desc_id: descriptor idn value
1410
+ * @desc_index: descriptor index
1411
+ * @param_offset: offset of the parameter to read
1412
+ * @param_read_buf: pointer to buffer where parameter would be read
1413
+ * @param_size: sizeof(param_read_buf)
1414
+ *
1415
+ * Return 0 in case of success, non-zero otherwise
1416
+ */
1417
+ static int ufshcd_read_desc_param (struct ufs_hba * hba ,
1418
+ enum desc_idn desc_id ,
1419
+ int desc_index ,
1420
+ u32 param_offset ,
1421
+ u8 * param_read_buf ,
1422
+ u32 param_size )
1423
+ {
1424
+ int ret ;
1425
+ u8 * desc_buf ;
1426
+ u32 buff_len ;
1427
+ bool is_kmalloc = true;
1428
+
1429
+ /* safety checks */
1430
+ if (desc_id >= QUERY_DESC_IDN_MAX )
1431
+ return - EINVAL ;
1432
+
1433
+ buff_len = ufs_query_desc_max_size [desc_id ];
1434
+ if ((param_offset + param_size ) > buff_len )
1435
+ return - EINVAL ;
1436
+
1437
+ if (!param_offset && (param_size == buff_len )) {
1438
+ /* memory space already available to hold full descriptor */
1439
+ desc_buf = param_read_buf ;
1440
+ is_kmalloc = false;
1441
+ } else {
1442
+ /* allocate memory to hold full descriptor */
1443
+ desc_buf = kmalloc (buff_len , GFP_KERNEL );
1444
+ if (!desc_buf )
1445
+ return - ENOMEM ;
1446
+ }
1447
+
1448
+ ret = ufshcd_query_descriptor (hba , UPIU_QUERY_OPCODE_READ_DESC ,
1449
+ desc_id , desc_index , 0 , desc_buf ,
1450
+ & buff_len );
1451
+
1452
+ if (ret || (buff_len < ufs_query_desc_max_size [desc_id ]) ||
1453
+ (desc_buf [QUERY_DESC_LENGTH_OFFSET ] !=
1454
+ ufs_query_desc_max_size [desc_id ])
1455
+ || (desc_buf [QUERY_DESC_DESC_TYPE_OFFSET ] != desc_id )) {
1456
+ dev_err (hba -> dev , "%s: Failed reading descriptor. desc_id %d param_offset %d buff_len %d ret %d" ,
1457
+ __func__ , desc_id , param_offset , buff_len , ret );
1458
+ if (!ret )
1459
+ ret = - EINVAL ;
1460
+
1461
+ goto out ;
1462
+ }
1463
+
1464
+ if (is_kmalloc )
1465
+ memcpy (param_read_buf , & desc_buf [param_offset ], param_size );
1466
+ out :
1467
+ if (is_kmalloc )
1468
+ kfree (desc_buf );
1469
+ return ret ;
1470
+ }
1471
+
1472
+ static inline int ufshcd_read_desc (struct ufs_hba * hba ,
1473
+ enum desc_idn desc_id ,
1474
+ int desc_index ,
1475
+ u8 * buf ,
1476
+ u32 size )
1477
+ {
1478
+ return ufshcd_read_desc_param (hba , desc_id , desc_index , 0 , buf , size );
1479
+ }
1480
+
1481
+ static inline int ufshcd_read_power_desc (struct ufs_hba * hba ,
1482
+ u8 * buf ,
1483
+ u32 size )
1484
+ {
1485
+ return ufshcd_read_desc (hba , QUERY_DESC_IDN_POWER , 0 , buf , size );
1486
+ }
1487
+
1488
+ /**
1489
+ * ufshcd_read_unit_desc_param - read the specified unit descriptor parameter
1490
+ * @hba: Pointer to adapter instance
1491
+ * @lun: lun id
1492
+ * @param_offset: offset of the parameter to read
1493
+ * @param_read_buf: pointer to buffer where parameter would be read
1494
+ * @param_size: sizeof(param_read_buf)
1495
+ *
1496
+ * Return 0 in case of success, non-zero otherwise
1497
+ */
1498
+ static inline int ufshcd_read_unit_desc_param (struct ufs_hba * hba ,
1499
+ int lun ,
1500
+ enum unit_desc_param param_offset ,
1501
+ u8 * param_read_buf ,
1502
+ u32 param_size )
1503
+ {
1504
+ /*
1505
+ * Unit descriptors are only available for general purpose LUs (LUN id
1506
+ * from 0 to 7) and RPMB Well known LU.
1507
+ */
1508
+ if (lun >= UFS_UPIU_MAX_GENERAL_LUN )
1509
+ return - EOPNOTSUPP ;
1510
+
1511
+ return ufshcd_read_desc_param (hba , QUERY_DESC_IDN_UNIT , lun ,
1512
+ param_offset , param_read_buf , param_size );
1513
+ }
1514
+
1395
1515
/**
1396
1516
* ufshcd_memory_alloc - allocate memory for host memory space data structures
1397
1517
* @hba: per adapter instance
@@ -2011,7 +2131,8 @@ static int ufshcd_verify_dev_init(struct ufs_hba *hba)
2011
2131
static int ufshcd_slave_alloc (struct scsi_device * sdev )
2012
2132
{
2013
2133
struct ufs_hba * hba ;
2014
- int lun_qdepth ;
2134
+ u8 lun_qdepth ;
2135
+ int ret ;
2015
2136
2016
2137
hba = shost_priv (sdev -> host );
2017
2138
sdev -> tagged_supported = 1 ;
@@ -2026,8 +2147,12 @@ static int ufshcd_slave_alloc(struct scsi_device *sdev)
2026
2147
/* REPORT SUPPORTED OPERATION CODES is not supported */
2027
2148
sdev -> no_report_opcodes = 1 ;
2028
2149
2029
- lun_qdepth = ufshcd_read_sdev_qdepth (hba , sdev );
2030
- if (lun_qdepth <= 0 )
2150
+ ret = ufshcd_read_unit_desc_param (hba ,
2151
+ sdev -> lun ,
2152
+ UNIT_DESC_PARAM_LU_Q_DEPTH ,
2153
+ & lun_qdepth ,
2154
+ sizeof (lun_qdepth ));
2155
+ if (!ret || !lun_qdepth )
2031
2156
/* eventually, we can figure out the real queue depth */
2032
2157
lun_qdepth = hba -> nutrs ;
2033
2158
else
@@ -3117,38 +3242,6 @@ static int ufshcd_eh_host_reset_handler(struct scsi_cmnd *cmd)
3117
3242
return err ;
3118
3243
}
3119
3244
3120
- /**
3121
- * ufshcd_read_sdev_qdepth - read the lun command queue depth
3122
- * @hba: Pointer to adapter instance
3123
- * @sdev: pointer to SCSI device
3124
- *
3125
- * Return in case of success the lun's queue depth else error.
3126
- */
3127
- static int ufshcd_read_sdev_qdepth (struct ufs_hba * hba ,
3128
- struct scsi_device * sdev )
3129
- {
3130
- int ret ;
3131
- int buff_len = UNIT_DESC_MAX_SIZE ;
3132
- u8 desc_buf [UNIT_DESC_MAX_SIZE ];
3133
-
3134
- ret = ufshcd_query_descriptor (hba , UPIU_QUERY_OPCODE_READ_DESC ,
3135
- QUERY_DESC_IDN_UNIT , sdev -> lun , 0 , desc_buf , & buff_len );
3136
-
3137
- if (ret || (buff_len < UNIT_DESC_PARAM_LU_Q_DEPTH )) {
3138
- dev_err (hba -> dev ,
3139
- "%s:Failed reading unit descriptor. len = %d ret = %d"
3140
- , __func__ , buff_len , ret );
3141
- if (!ret )
3142
- ret = - EINVAL ;
3143
-
3144
- goto out ;
3145
- }
3146
-
3147
- ret = desc_buf [UNIT_DESC_PARAM_LU_Q_DEPTH ] & 0xFF ;
3148
- out :
3149
- return ret ;
3150
- }
3151
-
3152
3245
/**
3153
3246
* ufshcd_async_scan - asynchronous execution for link startup
3154
3247
* @data: data pointer to pass to this function
0 commit comments