-
Notifications
You must be signed in to change notification settings - Fork 13
/
UFSHPB_Device_Driver.patch
4227 lines (4199 loc) · 117 KB
/
UFSHPB_Device_Driver.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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
diff -urN iu_board_exynos_legacy/iu_board_exynos/drivers/scsi/ufs/Kconfig iu_board_exynos_DDv1.3.5/iu_board_exynos/drivers/scsi/ufs/Kconfig
--- iu_board_exynos_legacy/iu_board_exynos/drivers/scsi/ufs/Kconfig 2018-06-27 16:36:27.213891989 +0900
+++ iu_board_exynos_DDv1.3.5/iu_board_exynos/drivers/scsi/ufs/Kconfig 2018-06-27 16:55:41.805891896 +0900
@@ -3,6 +3,7 @@
#
# This code is based on drivers/scsi/ufs/Kconfig
# Copyright (C) 2011-2013 Samsung India Software Operations
+# Copyright (c) 2017-2018 Samsung Electronics Co., Ltd.
#
# Authors:
# Santosh Yaraganavi <santosh.sy@samsung.com>
@@ -94,6 +95,12 @@
If you have a controller with this interface, say Y here.
If unsure, say N.
+
+config UFSHPB
+ bool "UFSHPB (EXPERIMENTAL)"
+ depends on SCSI_UFSHCD
+ ---help---
+ UFSHPB v1.0 test driver
choice
prompt "Option for self-test failure"
diff -urN iu_board_exynos_legacy/iu_board_exynos/drivers/scsi/ufs/Makefile iu_board_exynos_DDv1.3.5/iu_board_exynos/drivers/scsi/ufs/Makefile
--- iu_board_exynos_legacy/iu_board_exynos/drivers/scsi/ufs/Makefile 2018-06-27 16:36:27.213891989 +0900
+++ iu_board_exynos_DDv1.3.5/iu_board_exynos/drivers/scsi/ufs/Makefile 2018-06-27 16:55:27.693891897 +0900
@@ -1,5 +1,6 @@
# UFSHCD makefile
obj-$(CONFIG_SCSI_UFSHCD) += ufshcd.o ufs_quirks.o
+obj-$(CONFIG_UFSHPB) += ufshpb.o
obj-$(CONFIG_SCSI_UFSHCD_PCI) += ufshcd-pci.o
obj-$(CONFIG_SCSI_UFSHCD_PLATFORM) += ufshcd-pltfrm.o
obj-$(CONFIG_SCSI_UFS_EXYNOS) += ufs-exynos.o
diff -urN iu_board_exynos_legacy/iu_board_exynos/drivers/scsi/ufs/ufs.h iu_board_exynos_DDv1.3.5/iu_board_exynos/drivers/scsi/ufs/ufs.h
--- iu_board_exynos_legacy/iu_board_exynos/drivers/scsi/ufs/ufs.h 2018-06-27 16:36:27.213891989 +0900
+++ iu_board_exynos_DDv1.3.5/iu_board_exynos/drivers/scsi/ufs/ufs.h 2018-06-27 16:55:41.805891896 +0900
@@ -3,6 +3,7 @@
*
* This code is based on drivers/scsi/ufs/ufs.h
* Copyright (C) 2011-2013 Samsung India Software Operations
+ * Copyright (c) 2017-2018 Samsung Electronics Co., Ltd.
*
* Authors:
* Santosh Yaraganavi <santosh.sy@samsung.com>
@@ -72,6 +73,16 @@
UFS_UPIU_RPMB_WLUN = 0xC4,
};
+/**
+ * ufs_is_valid_unit_desc_lun - checks if the given LUN has a unit descriptor
+ * @lun: LU number to check
+ * @return: true if the lun has a matching unit descriptor, false otherwise
+ */
+static inline bool ufs_is_valid_unit_desc_lun(u8 lun)
+{
+ return (lun == UFS_UPIU_RPMB_WLUN || (lun < UFS_UPIU_MAX_GENERAL_LUN));
+}
+
/*
* UFS Protocol Information Unit related definitions
*/
@@ -129,9 +140,15 @@
/* Flag idn for Query Requests*/
enum flag_idn {
- QUERY_FLAG_IDN_FDEVICEINIT = 0x01,
- QUERY_FLAG_IDN_PWR_ON_WPE = 0x03,
- QUERY_FLAG_IDN_BKOPS_EN = 0x04,
+ QUERY_FLAG_IDN_FDEVICEINIT = 0x01,
+ QUERY_FLAG_IDN_PERMANENT_WPE = 0x02,
+ QUERY_FLAG_IDN_PWR_ON_WPE = 0x03,
+ QUERY_FLAG_IDN_BKOPS_EN = 0x04,
+ QUERY_FLAG_IDN_RESERVED1 = 0x05,
+ QUERY_FLAG_IDN_PURGE_ENABLE = 0x06,
+ QUERY_FLAG_IDN_RESERVED2 = 0x07,
+ QUERY_FLAG_IDN_FPHYRESOURCEREMOVAL = 0x08,
+ QUERY_FLAG_IDN_BUSY_RTC = 0x09,
};
/* Attribute idn for Query requests */
@@ -181,13 +198,13 @@
QUERY_DESC_DEVICE_MAX_SIZE = 0x40,
QUERY_DESC_CONFIGURAION_MAX_SIZE = 0x90,
QUERY_DESC_UNIT_MAX_SIZE = 0x23,
+ QUERY_DESC_GEOMETRY_MAX_SIZE = 0x44,
QUERY_DESC_INTERCONNECT_MAX_SIZE = 0x06,
/*
* Max. 126 UNICODE characters (2 bytes per character) plus 2 bytes
* of descriptor header.
*/
QUERY_DESC_STRING_MAX_SIZE = 0xFE,
- QUERY_DESC_GEOMETRY_MAZ_SIZE = 0x44,
QUERY_DESC_POWER_MAX_SIZE = 0x62,
QUERY_DESC_HEALTH_MAX_SIZE = 0x37,
QUERY_DESC_RFU_MAX_SIZE = 0x00,
@@ -211,6 +228,11 @@
UNIT_DESC_PARAM_PHY_MEM_RSRC_CNT = 0x18,
UNIT_DESC_PARAM_CTX_CAPABILITIES = 0x20,
UNIT_DESC_PARAM_LARGE_UNIT_SIZE_M1 = 0x22,
+#if defined(CONFIG_UFSHPB)
+ UNIT_DESC_HPB_LU_MAX_ACTIVE_REGIONS = 0x23,
+ UNIT_DESC_HPB_LU_PIN_REGION_START_OFFSET = 0x25,
+ UNIT_DESC_HPB_LU_NUM_PIN_REGIONS = 0x27,
+#endif
};
/*
@@ -322,6 +344,20 @@
DEVICE_DESC_PARAM_UD_LEN = 0x1B,
DEVICE_DESC_PARAM_RTT_CAP = 0x1C,
DEVICE_DESC_PARAM_FRQ_RTC = 0x1D,
+ DEVICE_DESC_PARAM_FEAT_SUP = 0x1F,
+#if defined(CONFIG_UFSHPB)
+ DEVICE_DESC_PARAM_HPB_VER = 0x40,
+#endif
+};
+
+enum geometry_desc_param {
+ GEOMETRY_DESC_SEGMENT_SIZE = 0x0D,
+#if defined(CONFIG_UFSHPB)
+ GEOMETRY_DESC_HPB_REGION_SIZE = 0x48,
+ GEOMETRY_DESC_HPB_NUMBER_LU = 0x49,
+ GEOMETRY_DESC_HPB_SUBREGION_SIZE = 0x4A,
+ GEOMETRY_DESC_HPB_DEVICE_MAX_ACTIVE_REGIONS = 0x4B,
+#endif
};
enum health_device_desc_param {
diff -urN iu_board_exynos_legacy/iu_board_exynos/drivers/scsi/ufs/ufshcd.c iu_board_exynos_DDv1.3.5/iu_board_exynos/drivers/scsi/ufs/ufshcd.c
--- iu_board_exynos_legacy/iu_board_exynos/drivers/scsi/ufs/ufshcd.c 2018-06-27 16:36:27.213891989 +0900
+++ iu_board_exynos_DDv1.3.5/iu_board_exynos/drivers/scsi/ufs/ufshcd.c 2018-06-27 16:55:41.805891896 +0900
@@ -4,6 +4,7 @@
* This code is based on drivers/scsi/ufs/ufshcd.c
* Copyright (C) 2011-2013 Samsung India Software Operations
* Copyright (c) 2013-2014, The Linux Foundation. All rights reserved.
+ * Copyright (c) 2017-2018 Samsung Electronics Co., Ltd.
*
* Authors:
* Santosh Yaraganavi <santosh.sy@samsung.com>
@@ -51,6 +52,7 @@
#include "unipro.h"
#include "ufs-exynos.h"
#include "ufs_quirks.h"
+#include <scsi/ufs/ioctl.h>
#if defined(CONFIG_UFS_FMP_ECRYPT_FS)
#include <fmp_derive_iv.h>
@@ -113,7 +115,7 @@
QUERY_DESC_INTERCONNECT_MAX_SIZE,
QUERY_DESC_STRING_MAX_SIZE,
QUERY_DESC_RFU_MAX_SIZE,
- QUERY_DESC_GEOMETRY_MAZ_SIZE,
+ QUERY_DESC_GEOMETRY_MAX_SIZE,
QUERY_DESC_POWER_MAX_SIZE,
QUERY_DESC_HEALTH_MAX_SIZE,
QUERY_DESC_RFU_MAX_SIZE,
@@ -126,13 +128,6 @@
UFSHCD_CAN_QUEUE = 32,
};
-/* UFSHCD states */
-enum {
- UFSHCD_STATE_RESET,
- UFSHCD_STATE_ERROR,
- UFSHCD_STATE_OPERATIONAL,
-};
-
/* UFSHCD error handling flags */
enum {
UFSHCD_EH_IN_PROGRESS = (1 << 0),
@@ -1513,9 +1508,19 @@
switch (lrbp->command_type) {
case UTP_CMD_TYPE_SCSI:
if (likely(lrbp->cmd)) {
+#if defined(CONFIG_UFSHPB)
+ if (hba->ufshpb_state == HPB_PRESENT
+ && hba->issue_ioctl == true)
+ lrbp->lun = 0x7F;
+#endif
ufshcd_prepare_req_desc_hdr(lrbp, &upiu_flags,
lrbp->cmd->sc_data_direction);
ufshcd_prepare_utp_scsi_cmd_upiu(lrbp, upiu_flags);
+#if defined(CONFIG_UFSHPB)
+ if (hba->ufshpb_state == HPB_PRESENT
+ && hba->issue_ioctl == false)
+ ufshpb_prep_fn(hba, lrbp);
+#endif
} else {
ret = -EINVAL;
}
@@ -2041,13 +2046,19 @@
return err;
}
+#if defined(CONFIG_UFSHPB)
+int ufshcd_query_descriptor(struct ufs_hba *hba,
+ enum query_opcode opcode, u8 idn, u8 index,
+ u8 selector, u8 *desc_buf, int *buf_len)
+#else
static int ufshcd_query_descriptor(struct ufs_hba *hba,
enum query_opcode opcode, u8 idn, u8 index,
u8 selector, u8 *desc_buf, int *buf_len)
+#endif
{
struct ufs_query_req *request;
struct ufs_query_res *response;
- int err;
+ int err = 0;
BUG_ON(!hba);
@@ -3382,7 +3393,6 @@
/* REPORT SUPPORTED OPERATION CODES is not supported */
sdev->no_report_opcodes = 1;
-
ufshcd_set_queue_depth(sdev);
ufshcd_get_lu_power_on_wp_status(hba, sdev);
@@ -3430,10 +3440,23 @@
static int ufshcd_slave_configure(struct scsi_device *sdev)
{
struct request_queue *q = sdev->request_queue;
+#if defined(CONFIG_UFSHPB)
+ struct ufs_hba *hba;
+#endif
blk_queue_update_dma_pad(q, PRDT_DATA_BYTE_COUNT_PAD - 1);
blk_queue_max_segment_size(q, PRDT_DATA_BYTE_COUNT_MAX);
blk_queue_update_dma_alignment(q, PAGE_SIZE - 1);
+#if defined(CONFIG_UFSHPB)
+ hba = shost_priv(sdev->host);
+
+ if (sdev->lun < UFS_UPIU_MAX_GENERAL_LUN) {
+ hba->sdev_ufs_lu[sdev->lun] = sdev;
+
+ printk("%s:%d: ufshpb set lun %d sdev %p q %p n",
+ __func__, __LINE__, sdev->lun, sdev, sdev->request_queue);
+ }
+#endif
return 0;
}
@@ -3569,6 +3592,11 @@
if (ufshcd_is_exception_event(lrbp->ucd_rsp_ptr) &&
scsi_host_in_recovery(hba->host))
schedule_work(&hba->eeh_work);
+#if defined(CONFIG_UFSHPB)
+ if (hba->ufshpb_state == HPB_PRESENT &&
+ scsi_status == SAM_STAT_GOOD)
+ ufshpb_rsp_upiu(hba, lrbp);
+#endif
break;
case UPIU_TRANSACTION_REJECT_UPIU:
/* TODO: handle Reject UPIU Response */
@@ -4319,10 +4347,17 @@
}
}
spin_lock_irqsave(host->host_lock, flags);
+#if defined(CONFIG_UFSHPB)
+ hba->ufshpb_state = HPB_RESET;
+#endif
__ufshcd_transfer_req_compl(hba, DID_RESET);
spin_unlock_irqrestore(host->host_lock, flags);
out:
if (!err) {
+#if defined(CONFIG_UFSHPB)
+ schedule_delayed_work(&hba->ufshpb_init_work,
+ msecs_to_jiffies(10));
+#endif
err = SUCCESS;
} else {
dev_err(hba->dev, "%s: failed with err %d\n", __func__, err);
@@ -4465,6 +4500,9 @@
hba->ufshcd_state = UFSHCD_STATE_RESET;
ufshcd_set_eh_in_progress(hba);
ufshcd_hba_stop(hba);
+#if defined(CONFIG_UFSHPB)
+ hba->ufshpb_state = HPB_RESET;
+#endif
spin_unlock_irqrestore(hba->host->host_lock, flags);
/* Establish the link again and restore the device */
@@ -4795,7 +4833,6 @@
int re_cnt = 0;
int ret;
unsigned long flags;
-
retry:
ret = ufshcd_hba_enable(hba);
if (ret)
@@ -4894,6 +4931,11 @@
ufshcd_hba_exit(hba);
}
+#if defined(CONFIG_UFSHPB)
+ INIT_DELAYED_WORK(&hba->ufshpb_init_work, ufshpb_init_handler);
+ schedule_delayed_work(&hba->ufshpb_init_work, msecs_to_jiffies(0));
+#endif
+
return ret;
}
@@ -4909,6 +4951,395 @@
ufshcd_probe_hba(hba);
}
+#if defined(CONFIG_UFSHPB)
+static void print_buf(unsigned char *buf)
+{
+ int i, max;
+
+ max = buf[0];
+
+ for (i = 0 ; i < max ; i++) {
+ if (i % 16 == 0)
+ printk("(0x%.2x) :", i);
+ printk(" %.2x", buf[i]);
+
+ if ((i + 1) % 16 == 0)
+ printk("\n");
+ }
+
+ printk("\n");
+}
+
+static int ufshcd_query_desc_for_ufshpb(struct ufs_hba *hba, int lun,
+ struct ufs_ioctl_query_data *ioctl_data, void __user *buffer)
+{
+ unsigned char *kernel_buf;
+ int opcode, selector;
+ int err = 0;
+ int index = 0;
+ int length = 0;
+
+ opcode = ioctl_data->opcode & 0xffff;
+ selector = 1;
+
+ if (ioctl_data->idn == QUERY_DESC_IDN_STRING) {
+ kernel_buf = kzalloc(IOCTL_DEV_CTX_MAX_SIZE, GFP_KERNEL);
+ } else {
+ kernel_buf = kzalloc(QUERY_DESC_MAX_SIZE, GFP_KERNEL);
+ }
+
+ if (!kernel_buf) {
+ err = -ENOMEM;
+ goto out;
+ }
+
+ switch (opcode) {
+ case UPIU_QUERY_OPCODE_WRITE_DESC:
+ err = copy_from_user(kernel_buf, buffer +
+ sizeof(struct ufs_ioctl_query_data),
+ ioctl_data->buf_size);
+ printk("%s:%d bufsize %d\n", __func__, __LINE__,
+ ioctl_data->buf_size);
+ print_buf(kernel_buf);
+ if (err)
+ goto out_release_mem;
+ break;
+
+ case UPIU_QUERY_OPCODE_READ_DESC:
+ switch (ioctl_data->idn) {
+ case QUERY_DESC_IDN_UNIT:
+ if (!ufs_is_valid_unit_desc_lun(lun)) {
+ dev_err(hba->dev,
+ "%s: No unit descriptor for lun 0x%x\n",
+ __func__, lun);
+ err = -EINVAL;
+ goto out_release_mem;
+ }
+ index = lun;
+ printk("%s:%d read lu desc lun: %d\n",
+ __func__, __LINE__, index);
+ break;
+
+ case QUERY_DESC_IDN_STRING:
+ if (!ufs_is_valid_unit_desc_lun(lun)) {
+ dev_err(hba->dev,
+ "%s: No unit descriptor for lun 0x%x\n",
+ __func__, lun);
+ err = -EINVAL;
+ goto out_release_mem;
+ }
+ err = ufshpb_issue_req_dev_ctx(hba->ufshpb_lup[lun], kernel_buf, ioctl_data->buf_size);
+ if (err < 0)
+ goto out_release_mem;
+
+ goto copy_buffer;
+
+ case QUERY_DESC_IDN_DEVICE:
+ case QUERY_DESC_IDN_GEOMETRY:
+ case QUERY_DESC_IDN_CONFIGURAION:
+ break;
+
+ default:
+ printk("%s:%d invalid idn %d\n", __func__, __LINE__,
+ ioctl_data->idn);
+ err = -EINVAL;
+ goto out_release_mem;
+ }
+ break;
+ default:
+ err = -EINVAL;
+ printk("%s:%d invalid opcode %d\n", __func__, __LINE__,
+ opcode);
+ goto out_release_mem;
+ }
+
+ length = ioctl_data->buf_size;
+
+ err = ufshcd_query_descriptor(hba, opcode, ioctl_data->idn, index,
+ selector, kernel_buf, &length);
+ if (err)
+ goto out_release_mem;
+ printk("%s:%d (len 0x%x) %.2x %.2x %.2x %.2x : %.2x %.2x %.2x %.2x\n",
+ __func__, __LINE__, length,
+ kernel_buf[0], kernel_buf[1], kernel_buf[2], kernel_buf[3],
+ kernel_buf[4], kernel_buf[5], kernel_buf[6], kernel_buf[7]);
+
+copy_buffer:
+ if (opcode == UPIU_QUERY_OPCODE_READ_DESC) {
+ err = copy_to_user(buffer, ioctl_data,
+ sizeof(struct ufs_ioctl_query_data));
+ if (err)
+ printk("%s:%d Failed copying back to user.\n",
+ __func__, __LINE__);
+ err = copy_to_user(buffer + sizeof(struct ufs_ioctl_query_data),
+ kernel_buf, ioctl_data->buf_size);
+ if (err)
+ printk("%s:%d Failed copying back to user : rsp_buffer.\n",
+ __func__, __LINE__);
+ }
+
+out_release_mem:
+ kfree(kernel_buf);
+out:
+ return err;
+}
+#endif
+
+/**
+ * ufshcd_query_ioctl - perform user read queries
+ * @hba: per-adapter instance
+ * @lun: used for lun specific queries
+ * @buffer: user space buffer for reading and submitting query data and params
+ * @return: 0 for success negative error code otherwise
+ *
+ * Expected/Submitted buffer structure is struct ufs_ioctl_query_data.
+ * It will read the opcode, idn and buf_length parameters, and, put the
+ * response in the buffer field while updating the used size in buf_length.
+ */
+static int ufshcd_query_ioctl(struct ufs_hba *hba, u8 lun, void __user *buffer)
+{
+ struct ufs_ioctl_query_data *ioctl_data;
+ int err = 0;
+ int length = 0;
+ void *data_ptr;
+ bool flag;
+ u32 att;
+ u8 index;
+ u8 *desc = NULL;
+
+ ioctl_data = kzalloc(sizeof(struct ufs_ioctl_query_data), GFP_KERNEL);
+ if (!ioctl_data) {
+ dev_err(hba->dev, "%s: Failed allocating %zu bytes\n", __func__,
+ sizeof(struct ufs_ioctl_query_data));
+ err = -ENOMEM;
+ goto out;
+ }
+
+ /* extract params from user buffer */
+ err = copy_from_user(ioctl_data, buffer,
+ sizeof(struct ufs_ioctl_query_data));
+ if (err) {
+ dev_err(hba->dev,
+ "%s: Failed copying buffer from user, err %d\n",
+ __func__, err);
+ goto out_release_mem;
+ }
+
+#if defined(CONFIG_UFSHPB)
+ printk("UFS-IOCTL: op %u idn %u size %u \n",
+ ioctl_data->opcode, ioctl_data->idn, ioctl_data->buf_size);
+ printk("%s:%d ufshpb code 0x%x opcode 0x%x\n",
+ __func__, __LINE__, ((ioctl_data->opcode & 0xffff0000) >> 16),
+ ioctl_data->opcode & 0xffff);
+
+ if ((ioctl_data->opcode & 0xffff0000) >> 16 == HPB_QUERY_OPCODE) {
+ err = ufshcd_query_desc_for_ufshpb(hba, lun, ioctl_data, buffer);
+ kfree(ioctl_data);
+ goto out;
+ }
+#endif
+
+ /* verify legal parameters & send query */
+ switch (ioctl_data->opcode) {
+ case UPIU_QUERY_OPCODE_READ_DESC:
+ switch (ioctl_data->idn) {
+ case QUERY_DESC_IDN_DEVICE:
+ case QUERY_DESC_IDN_CONFIGURAION:
+ case QUERY_DESC_IDN_INTERCONNECT:
+ case QUERY_DESC_IDN_GEOMETRY:
+ case QUERY_DESC_IDN_POWER:
+ case QUERY_DESC_IDN_HEALTH:
+ index = 0;
+ break;
+ case QUERY_DESC_IDN_UNIT:
+ if (!ufs_is_valid_unit_desc_lun(lun)) {
+ dev_err(hba->dev,
+ "%s: No unit descriptor for lun 0x%x\n",
+ __func__, lun);
+ err = -EINVAL;
+ goto out_release_mem;
+ }
+ index = lun;
+ printk("UFSTEST %s:%d index %d lun %d \n",
+ __func__, __LINE__, index, lun);
+ break;
+ default:
+ goto out_einval;
+ }
+ length = min_t(int, QUERY_DESC_MAX_SIZE,
+ ioctl_data->buf_size);
+ desc = kzalloc(length, GFP_KERNEL);
+ if (!desc) {
+ dev_err(hba->dev, "%s: Failed allocating %d bytes\n",
+ __func__, length);
+ err = -ENOMEM;
+ goto out_release_mem;
+ }
+ err = ufshcd_query_descriptor(hba, ioctl_data->opcode,
+ ioctl_data->idn, index, 0, desc, &length);
+ break;
+ case UPIU_QUERY_OPCODE_READ_ATTR:
+ switch (ioctl_data->idn) {
+ case QUERY_ATTR_IDN_BOOT_LU_EN:
+ case QUERY_ATTR_IDN_POWER_MODE:
+ case QUERY_ATTR_IDN_ACTIVE_ICC_LVL:
+ case QUERY_ATTR_IDN_OOO_DATA_EN:
+ case QUERY_ATTR_IDN_BKOPS_STATUS:
+ case QUERY_ATTR_IDN_PURGE_STATUS:
+ case QUERY_ATTR_IDN_MAX_DATA_IN:
+ case QUERY_ATTR_IDN_MAX_DATA_OUT:
+ case QUERY_ATTR_IDN_REF_CLK_FREQ:
+ case QUERY_ATTR_IDN_CONF_DESC_LOCK:
+ case QUERY_ATTR_IDN_MAX_NUM_OF_RTT:
+ case QUERY_ATTR_IDN_EE_CONTROL:
+ case QUERY_ATTR_IDN_EE_STATUS:
+ case QUERY_ATTR_IDN_SECONDS_PASSED:
+ index = 0;
+ break;
+ case QUERY_ATTR_IDN_DYN_CAP_NEEDED:
+ case QUERY_ATTR_IDN_CORR_PRG_BLK_NUM:
+ index = lun;
+ break;
+ default:
+ goto out_einval;
+ }
+ err = ufshcd_query_attr(hba, ioctl_data->opcode,
+ ioctl_data->idn, index, 0, &att);
+ printk("%s:%d query_attr opcode %d idn %d index %d att %u\n",
+ __func__, __LINE__, ioctl_data->opcode,
+ ioctl_data->idn, index, att);
+ break;
+ case UPIU_QUERY_OPCODE_READ_FLAG:
+ switch (ioctl_data->idn) {
+ case QUERY_FLAG_IDN_FDEVICEINIT:
+ case QUERY_FLAG_IDN_PERMANENT_WPE:
+ case QUERY_FLAG_IDN_PWR_ON_WPE:
+ case QUERY_FLAG_IDN_BKOPS_EN:
+ case QUERY_FLAG_IDN_PURGE_ENABLE:
+ case QUERY_FLAG_IDN_FPHYRESOURCEREMOVAL:
+ case QUERY_FLAG_IDN_BUSY_RTC:
+ break;
+ default:
+ goto out_einval;
+ }
+ err = ufshcd_query_flag(hba, ioctl_data->opcode,
+ ioctl_data->idn, &flag);
+ break;
+ default:
+ goto out_einval;
+ }
+
+ if (err) {
+ dev_err(hba->dev, "%s: Query for idn %d failed\n", __func__,
+ ioctl_data->idn);
+ goto out_release_mem;
+ }
+
+ /*
+ * copy response data
+ * As we might end up reading less data then what is specified in
+ * "ioct_data->buf_size". So we are updating "ioct_data->
+ * buf_size" to what exactly we have read.
+ */
+ switch (ioctl_data->opcode) {
+ case UPIU_QUERY_OPCODE_READ_DESC:
+ ioctl_data->buf_size = min_t(int, ioctl_data->buf_size, length);
+ data_ptr = desc;
+ break;
+ case UPIU_QUERY_OPCODE_READ_ATTR:
+ ioctl_data->buf_size = sizeof(u32);
+ data_ptr = &att;
+ break;
+ case UPIU_QUERY_OPCODE_READ_FLAG:
+ ioctl_data->buf_size = 1;
+ data_ptr = &flag;
+ break;
+ default:
+ BUG_ON(true);
+ }
+
+ /* copy to user */
+ err = copy_to_user(buffer, ioctl_data,
+ sizeof(struct ufs_ioctl_query_data));
+ if (err)
+ dev_err(hba->dev, "%s: Failed copying back to user.\n",
+ __func__);
+ err = copy_to_user(buffer + sizeof(struct ufs_ioctl_query_data),
+ data_ptr, ioctl_data->buf_size);
+ if (err)
+ dev_err(hba->dev, "%s: err %d copying back to user.\n",
+ __func__, err);
+ goto out_release_mem;
+
+out_einval:
+ dev_err(hba->dev,
+ "%s: illegal ufs query ioctl data, opcode 0x%x, idn 0x%x\n",
+ __func__, ioctl_data->opcode, (unsigned int)ioctl_data->idn);
+ err = -EINVAL;
+out_release_mem:
+ kfree(ioctl_data);
+ kfree(desc);
+out:
+ return err;
+}
+
+/**
+ * ufshcd_ioctl - ufs ioctl callback registered in scsi_host
+ * @dev: scsi device required for per LUN queries
+ * @cmd: command opcode
+ * @buffer: user space buffer for transferring data
+ *
+ * Supported commands:
+ * UFS_IOCTL_QUERY
+ */
+static int ufshcd_ioctl(struct scsi_device *dev, int cmd, void __user *buffer)
+{
+ struct ufs_hba *hba = shost_priv(dev->host);
+ int err = 0;
+
+ printk("[%s%d] cmd:0x%x \n", __func__, __LINE__, cmd);
+
+ BUG_ON(!hba);
+ if (!buffer) {
+ if (cmd != SCSI_UFS_REQUEST_SENSE) {
+ dev_err(hba->dev, "%s: User buffer is NULL!\n", __func__);
+ return -EINVAL;
+ }
+ }
+ switch (cmd) {
+#if 0
+ case SCSI_UFS_REQUEST_SENSE:
+ err = ufshcd_send_request_sense(hba, hba->sdev_rpmb);
+ if (err) {
+ dev_warn(hba->dev, "%s failed to clear uac on rpmb(w-lu) %d\n",
+ __func__, err);
+ }
+ hba->host->wlun_clr_uac = false;
+ break;
+#endif
+ case UFS_IOCTL_QUERY:
+ //pm_runtime_get_sync(hba->dev);
+ printk("UFSTEST %s:%d sdev %p lun %d\n", __func__, __LINE__,
+ dev, dev->lun);
+ err = ufshcd_query_ioctl(hba,
+ ufshcd_scsi_to_upiu_lun(dev->lun), buffer);
+ //pm_runtime_put_sync(hba->dev);
+ break;
+#if 0
+ case UFS_IOCTL_BLKROSET:
+ err = -ENOIOCTLCMD;
+ break;
+#endif
+ default:
+ err = -EINVAL;
+// dev_err(hba->dev, "%s: Illegal ufs-IOCTL cmd %d\n", __func__,
+// cmd);
+ break;
+ }
+
+ return err;
+}
+
static struct scsi_host_template ufshcd_driver_template = {
.module = THIS_MODULE,
.name = UFSHCD,
@@ -4919,9 +5350,15 @@
.slave_destroy = ufshcd_slave_destroy,
.change_queue_depth = ufshcd_change_queue_depth,
//.eh_abort_handler = ufshcd_abort,
- //.eh_device_reset_handler = ufshcd_eh_device_reset_handler,
- //.eh_host_reset_handler = ufshcd_eh_host_reset_handler,
- //.eh_timed_out = ufshcd_eh_timed_out,
+// .eh_device_reset_handler = ufshcd_eh_device_reset_handler,
+// .eh_host_reset_handler = ufshcd_eh_host_reset_handler,
+// .eh_timed_out = ufshcd_eh_timed_out,
+ .ioctl = ufshcd_ioctl,
+#if defined(CONFIG_UFSHPB)
+#ifdef CONFIG_COMPAT
+ .compat_ioctl = ufshcd_ioctl,
+#endif
+#endif
.this_id = -1,
.sg_tablesize = SG_ALL,
.cmd_per_lun = UFSHCD_CMD_PER_LUN,
@@ -5987,6 +6424,9 @@
*/
void ufshcd_remove(struct ufs_hba *hba)
{
+#if defined(CONFIG_UFSHPB)
+ ufshpb_release(hba, HPB_NEED_INIT);
+#endif
scsi_remove_host(hba->host);
/* disable interrupts */
ufshcd_disable_intr(hba, hba->intr_mask);
@@ -6283,6 +6723,9 @@
*/
ufshcd_set_ufs_dev_poweroff(hba);
+#if defined(CONFIG_UFSHPB)
+ hba->ufshpb_state = HPB_NEED_INIT;
+#endif
async_schedule(ufshcd_async_scan, hba);
return 0;
diff -urN iu_board_exynos_legacy/iu_board_exynos/drivers/scsi/ufs/ufshcd.h iu_board_exynos_DDv1.3.5/iu_board_exynos/drivers/scsi/ufs/ufshcd.h
--- iu_board_exynos_legacy/iu_board_exynos/drivers/scsi/ufs/ufshcd.h 2018-06-27 16:36:27.213891989 +0900
+++ iu_board_exynos_DDv1.3.5/iu_board_exynos/drivers/scsi/ufs/ufshcd.h 2018-06-27 16:55:41.805891896 +0900
@@ -3,6 +3,7 @@
*
* This code is based on drivers/scsi/ufs/ufshcd.h
* Copyright (C) 2011-2013 Samsung India Software Operations
+ * Copyright (c) 2017-2018 Samsung Electronics Co., Ltd.
*
* Authors:
* Santosh Yaraganavi <santosh.sy@samsung.com>
@@ -63,8 +64,13 @@
#include <scsi/scsi_dbg.h>
#include <scsi/scsi_eh.h>
+#include <scsi/scsi_ioctl.h>
+
#include "ufs.h"
#include "ufshci.h"
+#if defined(CONFIG_UFSHPB)
+#include "ufshpb.h"
+#endif
#define UFSHCD "ufshcd"
#define UFSHCD_DRIVER_VERSION "0.2"
@@ -78,6 +84,13 @@
DEV_CMD_TYPE_QUERY = 0x1,
};
+/* UFSHCD states */
+enum {
+ UFSHCD_STATE_RESET,
+ UFSHCD_STATE_ERROR,
+ UFSHCD_STATE_OPERATIONAL,
+};
+
/**
* struct uic_command - UIC command structure
* @command: UIC command
@@ -508,6 +521,15 @@
uint32_t self_test_mode;
struct ufshcd_sg_entry *ucd_prdt_ptr_st;
+#if defined(CONFIG_UFSHPB)
+ struct ufshpb_lu *ufshpb_lup[UFS_UPIU_MAX_GENERAL_LUN];
+ struct delayed_work ufshpb_init_work;
+ struct work_struct ufshpb_eh_work;
+ int ufshpb_state;
+ struct scsi_device *sdev_ufs_lu[UFS_UPIU_MAX_GENERAL_LUN];
+ bool issue_ioctl;
+#endif
+
/* UFSHCI doesn't support DWORD size in UTRD */
#define UFSHCI_QUIRK_BROKEN_DWORD_UTRD BIT(0)
#define UFSHCI_QUIRK_BROKEN_REQ_LIST_CLR BIT(1)
@@ -652,6 +674,10 @@
int ufshcd_read_device_desc(struct ufs_hba *hba, u8 *buf, u32 size);
int ufshcd_read_health_desc(struct ufs_hba *hba, u8 *buf, u32 size);
+#if defined(CONFIG_UFSHPB)
+int ufshcd_query_descriptor(struct ufs_hba *hba, enum query_opcode opcode,
+ u8 idn, u8 index, u8 selector, u8 *desc_buf, int *buf_len);
+#endif
#define ASCII_STD true
#define UTF16_STD false
diff -urN iu_board_exynos_legacy/iu_board_exynos/drivers/scsi/ufs/ufshpb.c iu_board_exynos_DDv1.3.5/iu_board_exynos/drivers/scsi/ufs/ufshpb.c
--- iu_board_exynos_legacy/iu_board_exynos/drivers/scsi/ufs/ufshpb.c 1970-01-01 09:00:00.000000000 +0900
+++ iu_board_exynos_DDv1.3.5/iu_board_exynos/drivers/scsi/ufs/ufshpb.c 2018-06-27 16:55:41.805891896 +0900
@@ -0,0 +1,2986 @@
+/*
+ * Universal Flash Storage Host Performance Booster
+ *
+ * Copyright (C) 2017-2018 Samsung Electronics Co., Ltd.
+ *
+ * Authors:
+ * Yongmyung Lee <ymhungry.lee@samsung.com>
+ * Jinyoung Choi <j-young.choi@samsung.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ * See the COPYING file in the top-level directory or visit
+ * <http://www.gnu.org/licenses/gpl-2.0.html>
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * This program is provided "AS IS" and "WITH ALL FAULTS" and
+ * without warranty of any kind. You are solely responsible for
+ * determining the appropriateness of using and distributing
+ * the program and assume all risks associated with your exercise
+ * of rights with respect to the program, including but not limited
+ * to infringement of third party rights, the risks and costs of
+ * program errors, damage to or loss of data, programs or equipment,
+ * and unavailability or interruption of operations. Under no
+ * circumstances will the contributor of this Program be liable for
+ * any damages of any kind arising from your use or distribution of
+ * this program.
+ *
+ * The Linux Foundation chooses to take subject only to the GPLv2
+ * license terms, and distributes only under these terms.
+ */
+
+#include <linux/slab.h>
+#include <linux/blkdev.h>
+#include <scsi/scsi.h>
+#include <linux/sysfs.h>
+#include <linux/blktrace_api.h>
+
+#include "../../../block/blk.h"
+
+#include "ufs.h"
+#include "ufshcd.h"
+#include "ufshpb.h"
+
+/*
+ * UFSHPB DEBUG
+ * */
+#define INFO_MSG(msg, args...) printk(KERN_INFO "%s:%d " msg "\n", \
+ __func__, __LINE__, ##args)
+#define INIT_INFO(msg, args...) INFO_MSG(msg, ##args)
+#define RELEASE_INFO(msg, args...) INFO_MSG(msg, ##args)
+#define SYSFS_INFO(msg, args...) INFO_MSG(msg, ##args)
+#define ERR_MSG(msg, args...) printk(KERN_ERR "%s:%d " msg "\n", \
+ __func__, __LINE__, ##args)
+#define WARNING_MSG(msg, args...) printk(KERN_WARNING "%s:%d " msg "\n", \
+ __func__, __LINE__, ##args)
+
+#define HPB_DEBUG(hpb, msg, args...) \
+ do { if (hpb->debug) \
+ printk(KERN_ERR "%s:%d " msg "\n", \
+ __func__, __LINE__, ##args); \
+ } while (0)
+
+#define TMSG(hpb, args...) \
+ do { if (hpb->hba->sdev_ufs_lu[hpb->lun] && \
+ hpb->hba->sdev_ufs_lu[hpb->lun]->request_queue) \
+ blk_add_trace_msg( \
+ hpb->hba->sdev_ufs_lu[hpb->lun]->request_queue, \
+ ##args); \
+ } while (0)
+
+/*
+ * debug variables
+ */
+int alloc_mctx;
+
+/*
+ * define global constants
+ */
+static int sects_per_blk_shift;
+static int bits_per_dword_shift;
+static int bits_per_dword_mask;
+static int bits_per_byte_shift;
+
+static int ufshpb_create_sysfs(struct ufs_hba *hba,
+ struct ufshpb_lu *hpb);
+static void ufshpb_error_handler(struct work_struct *work);
+static void ufshpb_evict_region(struct ufshpb_lu *hpb,
+ struct ufshpb_region *cb);
+
+static inline void
+ufshpb_get_bit_offset(struct ufshpb_lu *hpb, int subregion_offset,
+ int *dword, int *offset)
+{
+ *dword = subregion_offset >> bits_per_dword_shift;
+ *offset = subregion_offset & bits_per_dword_mask;
+}
+
+/* called with hpb_lock (irq) */
+static bool
+ufshpb_ppn_dirty_check(struct ufshpb_lu *hpb, struct ufshpb_subregion *cp,
+ int subregion_offset)
+{
+ bool is_dirty;
+ unsigned int bit_dword, bit_offset;
+
+ ufshpb_get_bit_offset(hpb, subregion_offset,
+ &bit_dword, &bit_offset);
+
+ if (!cp->mctx->ppn_dirty)
+ return false;
+
+ is_dirty = cp->mctx->ppn_dirty[bit_dword] &
+ (1 << bit_offset) ? true : false;
+
+ return is_dirty;
+}
+
+static void ufshpb_ppn_prep(struct ufshpb_lu *hpb, struct ufshcd_lrb *lrbp,
+ unsigned long long ppn)
+{
+ unsigned char cmd[16] = { 0 };
+
+ /*
+ * [14] = Grounp Number, [15] = Transfer length
+ */
+ cmd[0] = READ_16;
+ cmd[2] = lrbp->cmd->cmnd[2];
+ cmd[3] = lrbp->cmd->cmnd[3];
+ cmd[4] = lrbp->cmd->cmnd[4];
+ cmd[5] = lrbp->cmd->cmnd[5];
+ cmd[6] = GET_BYTE_7(ppn);
+ cmd[7] = GET_BYTE_6(ppn);
+ cmd[8] = GET_BYTE_5(ppn);
+ cmd[9] = GET_BYTE_4(ppn);
+ cmd[10] = GET_BYTE_3(ppn);
+ cmd[11] = GET_BYTE_2(ppn);
+ cmd[12] = GET_BYTE_1(ppn);
+ cmd[13] = GET_BYTE_0(ppn);
+ cmd[14] = 0x11;
+ cmd[15] = 0x01;
+
+ memcpy(lrbp->cmd->cmnd, cmd, MAX_CDB_SIZE);
+ memcpy(lrbp->ucd_req_ptr->sc.cdb, cmd, MAX_CDB_SIZE);
+}
+
+/* called with hpb_lock (irq) */
+static inline void
+ufshpb_set_dirty_bits(struct ufshpb_lu *hpb, struct ufshpb_region *cb,
+ struct ufshpb_subregion *cp, int dword, int offset,
+ unsigned int count)
+{
+ const unsigned long mask = ((1UL << count) - 1) & 0xffffffff;
+
+ if (cb->region_state == HPBREGION_INACTIVE)
+ return;
+
+ BUG_ON(!cp->mctx);
+ cp->mctx->ppn_dirty[dword] |= (mask << offset);
+}
+
+static void
+ufshpb_set_dirty(struct ufshpb_lu *hpb, struct ufshcd_lrb *lrbp, int region,
+ int subregion, int subregion_offset)
+{
+ struct ufshpb_region *cb;
+ struct ufshpb_subregion *cp;
+ int count;
+ int bit_count, bit_dword, bit_offset;
+
+ count = blk_rq_sectors(lrbp->cmd->request) >> sects_per_blk_shift;
+ ufshpb_get_bit_offset(hpb, subregion_offset,
+ &bit_dword, &bit_offset);
+
+ do {
+ bit_count = min(count, BITS_PER_DWORD - bit_offset);
+
+ cb = hpb->region_tbl + region;
+ cp = cb->subregion_tbl + subregion;
+
+ ufshpb_set_dirty_bits(hpb, cb, cp,
+ bit_dword, bit_offset, bit_count);
+
+ bit_offset = 0;
+ bit_dword++;
+