forked from ~ljy/RK356X_SDK_RELEASE

hc
2024-05-11 04dd17822334871b23ea2862f7798fb0e0007777
kernel/drivers/usb/gadget/function/f_mass_storage.c
....@@ -47,7 +47,7 @@
4747 *
4848 * For more information about MSF and in particular its module
4949 * parameters and sysfs interface read the
50
- * <Documentation/usb/mass-storage.txt> file.
50
+ * <Documentation/usb/mass-storage.rst> file.
5151 */
5252
5353 /*
....@@ -216,6 +216,7 @@
216216 #include <linux/freezer.h>
217217 #include <linux/module.h>
218218 #include <linux/uaccess.h>
219
+#include <asm/unaligned.h>
219220
220221 #include <linux/usb/ch9.h>
221222 #include <linux/usb/gadget.h>
....@@ -408,7 +409,7 @@
408409 common->state = new_state;
409410 common->exception_arg = arg;
410411 if (common->thread_task)
411
- send_sig_info(SIGUSR1, SEND_SIG_FORCED,
412
+ send_sig_info(SIGUSR1, SEND_SIG_PRIV,
412413 common->thread_task);
413414 }
414415 spin_unlock_irqrestore(&common->lock, flags);
....@@ -950,7 +951,7 @@
950951 {
951952 struct file *filp = curlun->filp;
952953 struct inode *inode = file_inode(filp);
953
- unsigned long rc;
954
+ unsigned long __maybe_unused rc;
954955
955956 rc = invalidate_mapping_pages(inode->i_mapping, 0, -1);
956957 VLDBG(curlun, "invalidate_mapping_pages -> %ld\n", rc);
....@@ -1187,25 +1188,72 @@
11871188 int msf = common->cmnd[1] & 0x02;
11881189 int start_track = common->cmnd[6];
11891190 u8 *buf = (u8 *)bh->buf;
1191
+ u8 format;
1192
+ int i, len;
1193
+
1194
+ format = common->cmnd[2] & 0xf;
11901195
11911196 if ((common->cmnd[1] & ~0x02) != 0 || /* Mask away MSF */
1192
- start_track > 1) {
1197
+ (start_track > 1 && format != 0x1)) {
11931198 curlun->sense_data = SS_INVALID_FIELD_IN_CDB;
11941199 return -EINVAL;
11951200 }
11961201
1197
- memset(buf, 0, 20);
1198
- buf[1] = (20-2); /* TOC data length */
1199
- buf[2] = 1; /* First track number */
1200
- buf[3] = 1; /* Last track number */
1201
- buf[5] = 0x16; /* Data track, copying allowed */
1202
- buf[6] = 0x01; /* Only track is number 1 */
1203
- store_cdrom_address(&buf[8], msf, 0);
1202
+ /*
1203
+ * Check if CDB is old style SFF-8020i
1204
+ * i.e. format is in 2 MSBs of byte 9
1205
+ * Mac OS-X host sends us this.
1206
+ */
1207
+ if (format == 0)
1208
+ format = (common->cmnd[9] >> 6) & 0x3;
12041209
1205
- buf[13] = 0x16; /* Lead-out track is data */
1206
- buf[14] = 0xAA; /* Lead-out track number */
1207
- store_cdrom_address(&buf[16], msf, curlun->num_sectors);
1208
- return 20;
1210
+ switch (format) {
1211
+ case 0: /* Formatted TOC */
1212
+ case 1: /* Multi-session info */
1213
+ len = 4 + 2*8; /* 4 byte header + 2 descriptors */
1214
+ memset(buf, 0, len);
1215
+ buf[1] = len - 2; /* TOC Length excludes length field */
1216
+ buf[2] = 1; /* First track number */
1217
+ buf[3] = 1; /* Last track number */
1218
+ buf[5] = 0x16; /* Data track, copying allowed */
1219
+ buf[6] = 0x01; /* Only track is number 1 */
1220
+ store_cdrom_address(&buf[8], msf, 0);
1221
+
1222
+ buf[13] = 0x16; /* Lead-out track is data */
1223
+ buf[14] = 0xAA; /* Lead-out track number */
1224
+ store_cdrom_address(&buf[16], msf, curlun->num_sectors);
1225
+ return len;
1226
+
1227
+ case 2:
1228
+ /* Raw TOC */
1229
+ len = 4 + 3*11; /* 4 byte header + 3 descriptors */
1230
+ memset(buf, 0, len); /* Header + A0, A1 & A2 descriptors */
1231
+ buf[1] = len - 2; /* TOC Length excludes length field */
1232
+ buf[2] = 1; /* First complete session */
1233
+ buf[3] = 1; /* Last complete session */
1234
+
1235
+ buf += 4;
1236
+ /* fill in A0, A1 and A2 points */
1237
+ for (i = 0; i < 3; i++) {
1238
+ buf[0] = 1; /* Session number */
1239
+ buf[1] = 0x16; /* Data track, copying allowed */
1240
+ /* 2 - Track number 0 -> TOC */
1241
+ buf[3] = 0xA0 + i; /* A0, A1, A2 point */
1242
+ /* 4, 5, 6 - Min, sec, frame is zero */
1243
+ buf[8] = 1; /* Pmin: last track number */
1244
+ buf += 11; /* go to next track descriptor */
1245
+ }
1246
+ buf -= 11; /* go back to A2 descriptor */
1247
+
1248
+ /* For A2, 7, 8, 9, 10 - zero, Pmin, Psec, Pframe of Lead out */
1249
+ store_cdrom_address(&buf[7], msf, curlun->num_sectors);
1250
+ return len;
1251
+
1252
+ default:
1253
+ /* PMA, ATIP, CD-TEXT not supported/required */
1254
+ curlun->sense_data = SS_INVALID_FIELD_IN_CDB;
1255
+ return -EINVAL;
1256
+ }
12091257 }
12101258
12111259 static int do_mode_sense(struct fsg_common *common, struct fsg_buffhd *bh)
....@@ -1932,7 +1980,7 @@
19321980 common->data_size_from_cmnd =
19331981 get_unaligned_be16(&common->cmnd[7]);
19341982 reply = check_command(common, 10, DATA_DIR_TO_HOST,
1935
- (7<<6) | (1<<1), 1,
1983
+ (0xf<<6) | (3<<1), 1,
19361984 "READ TOC");
19371985 if (reply == 0)
19381986 reply = do_read_toc(common, bh);
....@@ -2038,7 +2086,6 @@
20382086 case RELEASE:
20392087 case RESERVE:
20402088 case SEND_DIAGNOSTIC:
2041
- /* Fall through */
20422089
20432090 default:
20442091 unknown_cmnd:
....@@ -2301,6 +2348,16 @@
23012348 {
23022349 struct fsg_dev *fsg = fsg_from_func(f);
23032350
2351
+ /* Disable the endpoints */
2352
+ if (fsg->bulk_in_enabled) {
2353
+ usb_ep_disable(fsg->bulk_in);
2354
+ fsg->bulk_in_enabled = 0;
2355
+ }
2356
+ if (fsg->bulk_out_enabled) {
2357
+ usb_ep_disable(fsg->bulk_out);
2358
+ fsg->bulk_out_enabled = 0;
2359
+ }
2360
+
23042361 __raise_exception(fsg->common, FSG_STATE_CONFIG_CHANGE, NULL);
23052362 }
23062363
....@@ -2321,7 +2378,7 @@
23212378 * into a high-priority EXIT exception.
23222379 */
23232380 for (;;) {
2324
- int sig = kernel_dequeue_signal(NULL);
2381
+ int sig = kernel_dequeue_signal();
23252382 if (!sig)
23262383 break;
23272384 if (sig != SIGUSR1) {
....@@ -3436,6 +3493,7 @@
34363493
34373494 DECLARE_USB_FUNCTION_INIT(mass_storage, fsg_alloc_inst, fsg_alloc);
34383495 MODULE_LICENSE("GPL");
3496
+MODULE_IMPORT_NS(VFS_internal_I_am_really_a_filesystem_and_am_NOT_a_driver);
34393497 MODULE_AUTHOR("Michal Nazarewicz");
34403498
34413499 /************************* Module parameters *************************/