]> git.kernelconcepts.de Git - karo-tx-linux.git/blob - drivers/usb/gadget/fsl_updater.h
ENGR00140950 mfg: fix the bug that ubiformat utility breaks utp protocol
[karo-tx-linux.git] / drivers / usb / gadget / fsl_updater.h
1 /*
2  * Freescale UUT driver
3  *
4  * Copyright 2008-2013 Freescale Semiconductor, Inc.
5  * Copyright 2008-2009 Embedded Alley Solutions, Inc All Rights Reserved.
6  */
7
8 /*
9  * The code contained herein is licensed under the GNU General Public
10  * License. You may obtain a copy of the GNU General Public License
11  * Version 2 or later at the following locations:
12  *
13  * http://www.opensource.org/licenses/gpl-license.html
14  * http://www.gnu.org/copyleft/gpl.html
15  */
16
17 #ifndef __FSL_UPDATER_H
18 #define __FSL_UPDATER_H
19
20 #include <linux/miscdevice.h>
21 #include <linux/list.h>
22 #include <linux/vmalloc.h>
23 #include <linux/ioctl.h>
24 /* #include <mach/hardware.h> */
25
26 static int utp_init(struct fsg_dev *fsg);
27 static void utp_exit(struct fsg_dev *fsg);
28 static ssize_t utp_file_read(struct file *file,
29                              char __user *buf,
30                              size_t size,
31                              loff_t *off);
32
33 static ssize_t utp_file_write(struct file *file,
34                               const char __user *buf,
35                               size_t size,
36                               loff_t *off);
37
38 static long utp_ioctl(struct file *file,
39               unsigned int cmd, unsigned long arg);
40 static struct utp_user_data *utp_user_data_alloc(size_t size);
41 static void utp_user_data_free(struct utp_user_data *uud);
42 static int utp_get_sense(struct fsg_dev *fsg);
43 static int utp_do_read(struct fsg_dev *fsg, void *data, size_t size);
44 static int utp_do_write(struct fsg_dev *fsg, void *data, size_t size);
45 static inline void utp_set_sense(struct fsg_dev *fsg, u16 code, u64 reply);
46 static int utp_handle_message(struct fsg_dev *fsg,
47                               char *cdb_data,
48                               int default_reply);
49
50 #define UTP_REPLY_PASS          0
51 #define UTP_REPLY_EXIT          0x8001
52 #define UTP_REPLY_BUSY          0x8002
53 #define UTP_REPLY_SIZE          0x8003
54 #define UTP_SENSE_KEY           9
55
56 #define UTP_MINOR               222
57 /* MISC_DYNAMIC_MINOR would be better, but... */
58
59 #define UTP_COMMAND_SIZE        80
60
61 #define UTP_SS_EXIT(fsg, r)     utp_set_sense(fsg, UTP_REPLY_EXIT, (u64)r)
62 #define UTP_SS_PASS(fsg)        utp_set_sense(fsg, UTP_REPLY_PASS, 0)
63 #define UTP_SS_BUSY(fsg, r)     utp_set_sense(fsg, UTP_REPLY_BUSY, (u64)r)
64 #define UTP_SS_SIZE(fsg, r)     utp_set_sense(fsg, UTP_REPLY_SIZE, (u64)r)
65
66 #define UTP_IOCTL_BASE  'U'
67 #define UTP_GET_CPU_ID  _IOR(UTP_IOCTL_BASE, 0, int)
68 /* the structure of utp message which is mapped to 16-byte SCSI CBW's CDB */
69 #pragma pack(1)
70 struct utp_msg {
71         u8  f0;
72         u8  utp_msg_type;
73         u32 utp_msg_tag;
74         union {
75                 struct {
76                         u32 param_lsb;
77                         u32 param_msb;
78                 };
79                 u64 param;
80         };
81 };
82
83 enum utp_msg_type {
84         UTP_POLL = 0,
85         UTP_EXEC,
86         UTP_GET,
87         UTP_PUT,
88 };
89
90 static struct utp_context {
91         wait_queue_head_t wq;
92         wait_queue_head_t list_full_wq;
93         struct mutex lock;
94         struct list_head read;
95         struct list_head write;
96         u32 sd, sdinfo, sdinfo_h;                       /* sense data */
97         int processed;
98         u8 *buffer;
99         u32 counter;
100         u64 utp_version;
101         u32 cur_state;
102 } utp_context;
103
104 static const struct file_operations utp_fops = {
105         .open   = nonseekable_open,
106         .read   = utp_file_read,
107         .write  = utp_file_write,
108         /* .ioctl  = utp_ioctl, */
109         .unlocked_ioctl  = utp_ioctl,
110 };
111
112 static struct miscdevice utp_dev = {
113         .minor  = UTP_MINOR,
114         .name   = "utp",
115         .fops   = &utp_fops,
116 };
117
118 #define UTP_FLAG_COMMAND        0x00000001
119 #define UTP_FLAG_DATA           0x00000002
120 #define UTP_FLAG_STATUS         0x00000004
121 #define UTP_FLAG_REPORT_BUSY    0x10000000
122 struct utp_message {
123         u32     flags;
124         size_t  size;
125         union {
126                 struct {
127                         u64 payload;
128                         char command[1];
129                 };
130                 struct {
131                         size_t bufsize;
132                         u8 data[1];
133                 };
134                 u32 status;
135         };
136 };
137
138 struct utp_user_data {
139         struct  list_head       link;
140         struct  utp_message     data;
141 };
142 #pragma pack()
143
144 static inline struct utp_context *UTP_CTX(struct fsg_dev *fsg)
145 {
146         return (struct utp_context *)fsg->utp;
147 }
148
149 #endif /* __FSL_UPDATER_H */
150