1e72c39c0692d17da4c7f08e20d6c57f7409415f7Andrzej Pietrasiewicz/*
2e72c39c0692d17da4c7f08e20d6c57f7409415f7Andrzej Pietrasiewicz * u_fs.h
3e72c39c0692d17da4c7f08e20d6c57f7409415f7Andrzej Pietrasiewicz *
4e72c39c0692d17da4c7f08e20d6c57f7409415f7Andrzej Pietrasiewicz * Utility definitions for the FunctionFS
5e72c39c0692d17da4c7f08e20d6c57f7409415f7Andrzej Pietrasiewicz *
6e72c39c0692d17da4c7f08e20d6c57f7409415f7Andrzej Pietrasiewicz * Copyright (c) 2013 Samsung Electronics Co., Ltd.
7e72c39c0692d17da4c7f08e20d6c57f7409415f7Andrzej Pietrasiewicz *		http://www.samsung.com
8e72c39c0692d17da4c7f08e20d6c57f7409415f7Andrzej Pietrasiewicz *
9e72c39c0692d17da4c7f08e20d6c57f7409415f7Andrzej Pietrasiewicz * Author: Andrzej Pietrasiewicz <andrzej.p@samsung.com>
10e72c39c0692d17da4c7f08e20d6c57f7409415f7Andrzej Pietrasiewicz *
11e72c39c0692d17da4c7f08e20d6c57f7409415f7Andrzej Pietrasiewicz * This program is free software; you can redistribute it and/or modify
12e72c39c0692d17da4c7f08e20d6c57f7409415f7Andrzej Pietrasiewicz * it under the terms of the GNU General Public License version 2 as
13e72c39c0692d17da4c7f08e20d6c57f7409415f7Andrzej Pietrasiewicz * published by the Free Software Foundation.
14e72c39c0692d17da4c7f08e20d6c57f7409415f7Andrzej Pietrasiewicz */
15e72c39c0692d17da4c7f08e20d6c57f7409415f7Andrzej Pietrasiewicz
16e72c39c0692d17da4c7f08e20d6c57f7409415f7Andrzej Pietrasiewicz#ifndef U_FFS_H
17e72c39c0692d17da4c7f08e20d6c57f7409415f7Andrzej Pietrasiewicz#define U_FFS_H
18e72c39c0692d17da4c7f08e20d6c57f7409415f7Andrzej Pietrasiewicz
19e72c39c0692d17da4c7f08e20d6c57f7409415f7Andrzej Pietrasiewicz#include <linux/usb/composite.h>
204b187fceec3c731815ff8e6a7317fd5ba50d1d5dAndrzej Pietrasiewicz#include <linux/list.h>
214b187fceec3c731815ff8e6a7317fd5ba50d1d5dAndrzej Pietrasiewicz#include <linux/mutex.h>
22e72c39c0692d17da4c7f08e20d6c57f7409415f7Andrzej Pietrasiewicz
235920cda627688c3229fd63157ff031f3f174175eAndrzej Pietrasiewicz#ifdef VERBOSE_DEBUG
245920cda627688c3229fd63157ff031f3f174175eAndrzej Pietrasiewicz#ifndef pr_vdebug
255920cda627688c3229fd63157ff031f3f174175eAndrzej Pietrasiewicz#  define pr_vdebug pr_debug
265920cda627688c3229fd63157ff031f3f174175eAndrzej Pietrasiewicz#endif /* pr_vdebug */
275920cda627688c3229fd63157ff031f3f174175eAndrzej Pietrasiewicz#  define ffs_dump_mem(prefix, ptr, len) \
285920cda627688c3229fd63157ff031f3f174175eAndrzej Pietrasiewicz	print_hex_dump_bytes(pr_fmt(prefix ": "), DUMP_PREFIX_NONE, ptr, len)
295920cda627688c3229fd63157ff031f3f174175eAndrzej Pietrasiewicz#else
305920cda627688c3229fd63157ff031f3f174175eAndrzej Pietrasiewicz#ifndef pr_vdebug
315920cda627688c3229fd63157ff031f3f174175eAndrzej Pietrasiewicz#  define pr_vdebug(...)                 do { } while (0)
325920cda627688c3229fd63157ff031f3f174175eAndrzej Pietrasiewicz#endif /* pr_vdebug */
335920cda627688c3229fd63157ff031f3f174175eAndrzej Pietrasiewicz#  define ffs_dump_mem(prefix, ptr, len) do { } while (0)
345920cda627688c3229fd63157ff031f3f174175eAndrzej Pietrasiewicz#endif /* VERBOSE_DEBUG */
355920cda627688c3229fd63157ff031f3f174175eAndrzej Pietrasiewicz
365920cda627688c3229fd63157ff031f3f174175eAndrzej Pietrasiewicz#define ENTER()    pr_vdebug("%s()\n", __func__)
375920cda627688c3229fd63157ff031f3f174175eAndrzej Pietrasiewicz
38b658499f0f0f4ebf21d09c7da62a46f66ffa67cbAndrzej Pietrasiewiczstruct f_fs_opts;
395920cda627688c3229fd63157ff031f3f174175eAndrzej Pietrasiewicz
40e72c39c0692d17da4c7f08e20d6c57f7409415f7Andrzej Pietrasiewiczstruct ffs_dev {
41e72c39c0692d17da4c7f08e20d6c57f7409415f7Andrzej Pietrasiewicz	const char *name;
42b658499f0f0f4ebf21d09c7da62a46f66ffa67cbAndrzej Pietrasiewicz	bool name_allocated;
43e72c39c0692d17da4c7f08e20d6c57f7409415f7Andrzej Pietrasiewicz	bool mounted;
44e72c39c0692d17da4c7f08e20d6c57f7409415f7Andrzej Pietrasiewicz	bool desc_ready;
454b187fceec3c731815ff8e6a7317fd5ba50d1d5dAndrzej Pietrasiewicz	bool single;
46e72c39c0692d17da4c7f08e20d6c57f7409415f7Andrzej Pietrasiewicz	struct ffs_data *ffs_data;
47b658499f0f0f4ebf21d09c7da62a46f66ffa67cbAndrzej Pietrasiewicz	struct f_fs_opts *opts;
484b187fceec3c731815ff8e6a7317fd5ba50d1d5dAndrzej Pietrasiewicz	struct list_head entry;
494b187fceec3c731815ff8e6a7317fd5ba50d1d5dAndrzej Pietrasiewicz
504b187fceec3c731815ff8e6a7317fd5ba50d1d5dAndrzej Pietrasiewicz	int (*ffs_ready_callback)(struct ffs_data *ffs);
514b187fceec3c731815ff8e6a7317fd5ba50d1d5dAndrzej Pietrasiewicz	void (*ffs_closed_callback)(struct ffs_data *ffs);
525920cda627688c3229fd63157ff031f3f174175eAndrzej Pietrasiewicz	void *(*ffs_acquire_dev_callback)(struct ffs_dev *dev);
535920cda627688c3229fd63157ff031f3f174175eAndrzej Pietrasiewicz	void (*ffs_release_dev_callback)(struct ffs_dev *dev);
54e72c39c0692d17da4c7f08e20d6c57f7409415f7Andrzej Pietrasiewicz};
55e72c39c0692d17da4c7f08e20d6c57f7409415f7Andrzej Pietrasiewicz
564b187fceec3c731815ff8e6a7317fd5ba50d1d5dAndrzej Pietrasiewiczextern struct mutex ffs_lock;
574b187fceec3c731815ff8e6a7317fd5ba50d1d5dAndrzej Pietrasiewicz
584b187fceec3c731815ff8e6a7317fd5ba50d1d5dAndrzej Pietrasiewiczstatic inline void ffs_dev_lock(void)
594b187fceec3c731815ff8e6a7317fd5ba50d1d5dAndrzej Pietrasiewicz{
604b187fceec3c731815ff8e6a7317fd5ba50d1d5dAndrzej Pietrasiewicz	mutex_lock(&ffs_lock);
614b187fceec3c731815ff8e6a7317fd5ba50d1d5dAndrzej Pietrasiewicz}
624b187fceec3c731815ff8e6a7317fd5ba50d1d5dAndrzej Pietrasiewicz
634b187fceec3c731815ff8e6a7317fd5ba50d1d5dAndrzej Pietrasiewiczstatic inline void ffs_dev_unlock(void)
644b187fceec3c731815ff8e6a7317fd5ba50d1d5dAndrzej Pietrasiewicz{
654b187fceec3c731815ff8e6a7317fd5ba50d1d5dAndrzej Pietrasiewicz	mutex_unlock(&ffs_lock);
664b187fceec3c731815ff8e6a7317fd5ba50d1d5dAndrzej Pietrasiewicz}
674b187fceec3c731815ff8e6a7317fd5ba50d1d5dAndrzej Pietrasiewicz
684b187fceec3c731815ff8e6a7317fd5ba50d1d5dAndrzej Pietrasiewiczint ffs_name_dev(struct ffs_dev *dev, const char *name);
694b187fceec3c731815ff8e6a7317fd5ba50d1d5dAndrzej Pietrasiewiczint ffs_single_dev(struct ffs_dev *dev);
704b187fceec3c731815ff8e6a7317fd5ba50d1d5dAndrzej Pietrasiewicz
715920cda627688c3229fd63157ff031f3f174175eAndrzej Pietrasiewiczstruct ffs_epfile;
725920cda627688c3229fd63157ff031f3f174175eAndrzej Pietrasiewiczstruct ffs_function;
735920cda627688c3229fd63157ff031f3f174175eAndrzej Pietrasiewicz
745920cda627688c3229fd63157ff031f3f174175eAndrzej Pietrasiewiczenum ffs_state {
755920cda627688c3229fd63157ff031f3f174175eAndrzej Pietrasiewicz	/*
765920cda627688c3229fd63157ff031f3f174175eAndrzej Pietrasiewicz	 * Waiting for descriptors and strings.
775920cda627688c3229fd63157ff031f3f174175eAndrzej Pietrasiewicz	 *
785920cda627688c3229fd63157ff031f3f174175eAndrzej Pietrasiewicz	 * In this state no open(2), read(2) or write(2) on epfiles
795920cda627688c3229fd63157ff031f3f174175eAndrzej Pietrasiewicz	 * may succeed (which should not be the problem as there
805920cda627688c3229fd63157ff031f3f174175eAndrzej Pietrasiewicz	 * should be no such files opened in the first place).
815920cda627688c3229fd63157ff031f3f174175eAndrzej Pietrasiewicz	 */
825920cda627688c3229fd63157ff031f3f174175eAndrzej Pietrasiewicz	FFS_READ_DESCRIPTORS,
835920cda627688c3229fd63157ff031f3f174175eAndrzej Pietrasiewicz	FFS_READ_STRINGS,
845920cda627688c3229fd63157ff031f3f174175eAndrzej Pietrasiewicz
855920cda627688c3229fd63157ff031f3f174175eAndrzej Pietrasiewicz	/*
865920cda627688c3229fd63157ff031f3f174175eAndrzej Pietrasiewicz	 * We've got descriptors and strings.  We are or have called
875920cda627688c3229fd63157ff031f3f174175eAndrzej Pietrasiewicz	 * functionfs_ready_callback().  functionfs_bind() may have
885920cda627688c3229fd63157ff031f3f174175eAndrzej Pietrasiewicz	 * been called but we don't know.
895920cda627688c3229fd63157ff031f3f174175eAndrzej Pietrasiewicz	 *
905920cda627688c3229fd63157ff031f3f174175eAndrzej Pietrasiewicz	 * This is the only state in which operations on epfiles may
915920cda627688c3229fd63157ff031f3f174175eAndrzej Pietrasiewicz	 * succeed.
925920cda627688c3229fd63157ff031f3f174175eAndrzej Pietrasiewicz	 */
935920cda627688c3229fd63157ff031f3f174175eAndrzej Pietrasiewicz	FFS_ACTIVE,
945920cda627688c3229fd63157ff031f3f174175eAndrzej Pietrasiewicz
955920cda627688c3229fd63157ff031f3f174175eAndrzej Pietrasiewicz	/*
965920cda627688c3229fd63157ff031f3f174175eAndrzej Pietrasiewicz	 * All endpoints have been closed.  This state is also set if
975920cda627688c3229fd63157ff031f3f174175eAndrzej Pietrasiewicz	 * we encounter an unrecoverable error.  The only
985920cda627688c3229fd63157ff031f3f174175eAndrzej Pietrasiewicz	 * unrecoverable error is situation when after reading strings
995920cda627688c3229fd63157ff031f3f174175eAndrzej Pietrasiewicz	 * from user space we fail to initialise epfiles or
1005920cda627688c3229fd63157ff031f3f174175eAndrzej Pietrasiewicz	 * functionfs_ready_callback() returns with error (<0).
1015920cda627688c3229fd63157ff031f3f174175eAndrzej Pietrasiewicz	 *
1025920cda627688c3229fd63157ff031f3f174175eAndrzej Pietrasiewicz	 * In this state no open(2), read(2) or write(2) (both on ep0
1035920cda627688c3229fd63157ff031f3f174175eAndrzej Pietrasiewicz	 * as well as epfile) may succeed (at this point epfiles are
1045920cda627688c3229fd63157ff031f3f174175eAndrzej Pietrasiewicz	 * unlinked and all closed so this is not a problem; ep0 is
1055920cda627688c3229fd63157ff031f3f174175eAndrzej Pietrasiewicz	 * also closed but ep0 file exists and so open(2) on ep0 must
1065920cda627688c3229fd63157ff031f3f174175eAndrzej Pietrasiewicz	 * fail).
1075920cda627688c3229fd63157ff031f3f174175eAndrzej Pietrasiewicz	 */
1085920cda627688c3229fd63157ff031f3f174175eAndrzej Pietrasiewicz	FFS_CLOSING
1095920cda627688c3229fd63157ff031f3f174175eAndrzej Pietrasiewicz};
1105920cda627688c3229fd63157ff031f3f174175eAndrzej Pietrasiewicz
1115920cda627688c3229fd63157ff031f3f174175eAndrzej Pietrasiewiczenum ffs_setup_state {
1125920cda627688c3229fd63157ff031f3f174175eAndrzej Pietrasiewicz	/* There is no setup request pending. */
1135920cda627688c3229fd63157ff031f3f174175eAndrzej Pietrasiewicz	FFS_NO_SETUP,
1145920cda627688c3229fd63157ff031f3f174175eAndrzej Pietrasiewicz	/*
1155920cda627688c3229fd63157ff031f3f174175eAndrzej Pietrasiewicz	 * User has read events and there was a setup request event
1165920cda627688c3229fd63157ff031f3f174175eAndrzej Pietrasiewicz	 * there.  The next read/write on ep0 will handle the
1175920cda627688c3229fd63157ff031f3f174175eAndrzej Pietrasiewicz	 * request.
1185920cda627688c3229fd63157ff031f3f174175eAndrzej Pietrasiewicz	 */
1195920cda627688c3229fd63157ff031f3f174175eAndrzej Pietrasiewicz	FFS_SETUP_PENDING,
1205920cda627688c3229fd63157ff031f3f174175eAndrzej Pietrasiewicz	/*
1215920cda627688c3229fd63157ff031f3f174175eAndrzej Pietrasiewicz	 * There was event pending but before user space handled it
1225920cda627688c3229fd63157ff031f3f174175eAndrzej Pietrasiewicz	 * some other event was introduced which canceled existing
1235920cda627688c3229fd63157ff031f3f174175eAndrzej Pietrasiewicz	 * setup.  If this state is set read/write on ep0 return
1245920cda627688c3229fd63157ff031f3f174175eAndrzej Pietrasiewicz	 * -EIDRM.  This state is only set when adding event.
1255920cda627688c3229fd63157ff031f3f174175eAndrzej Pietrasiewicz	 */
126e46318a00091e3e009363a516acc44a4a80e2ebbMichal Nazarewicz	FFS_SETUP_CANCELLED
1275920cda627688c3229fd63157ff031f3f174175eAndrzej Pietrasiewicz};
1285920cda627688c3229fd63157ff031f3f174175eAndrzej Pietrasiewicz
1295920cda627688c3229fd63157ff031f3f174175eAndrzej Pietrasiewiczstruct ffs_data {
1305920cda627688c3229fd63157ff031f3f174175eAndrzej Pietrasiewicz	struct usb_gadget		*gadget;
1315920cda627688c3229fd63157ff031f3f174175eAndrzej Pietrasiewicz
1325920cda627688c3229fd63157ff031f3f174175eAndrzej Pietrasiewicz	/*
1335920cda627688c3229fd63157ff031f3f174175eAndrzej Pietrasiewicz	 * Protect access read/write operations, only one read/write
1345920cda627688c3229fd63157ff031f3f174175eAndrzej Pietrasiewicz	 * at a time.  As a consequence protects ep0req and company.
1355920cda627688c3229fd63157ff031f3f174175eAndrzej Pietrasiewicz	 * While setup request is being processed (queued) this is
1365920cda627688c3229fd63157ff031f3f174175eAndrzej Pietrasiewicz	 * held.
1375920cda627688c3229fd63157ff031f3f174175eAndrzej Pietrasiewicz	 */
1385920cda627688c3229fd63157ff031f3f174175eAndrzej Pietrasiewicz	struct mutex			mutex;
1395920cda627688c3229fd63157ff031f3f174175eAndrzej Pietrasiewicz
1405920cda627688c3229fd63157ff031f3f174175eAndrzej Pietrasiewicz	/*
1415920cda627688c3229fd63157ff031f3f174175eAndrzej Pietrasiewicz	 * Protect access to endpoint related structures (basically
1425920cda627688c3229fd63157ff031f3f174175eAndrzej Pietrasiewicz	 * usb_ep_queue(), usb_ep_dequeue(), etc. calls) except for
1435920cda627688c3229fd63157ff031f3f174175eAndrzej Pietrasiewicz	 * endpoint zero.
1445920cda627688c3229fd63157ff031f3f174175eAndrzej Pietrasiewicz	 */
1455920cda627688c3229fd63157ff031f3f174175eAndrzej Pietrasiewicz	spinlock_t			eps_lock;
1465920cda627688c3229fd63157ff031f3f174175eAndrzej Pietrasiewicz
1475920cda627688c3229fd63157ff031f3f174175eAndrzej Pietrasiewicz	/*
1485920cda627688c3229fd63157ff031f3f174175eAndrzej Pietrasiewicz	 * XXX REVISIT do we need our own request? Since we are not
1495920cda627688c3229fd63157ff031f3f174175eAndrzej Pietrasiewicz	 * handling setup requests immediately user space may be so
1505920cda627688c3229fd63157ff031f3f174175eAndrzej Pietrasiewicz	 * slow that another setup will be sent to the gadget but this
1515920cda627688c3229fd63157ff031f3f174175eAndrzej Pietrasiewicz	 * time not to us but another function and then there could be
1525920cda627688c3229fd63157ff031f3f174175eAndrzej Pietrasiewicz	 * a race.  Is that the case? Or maybe we can use cdev->req
1535920cda627688c3229fd63157ff031f3f174175eAndrzej Pietrasiewicz	 * after all, maybe we just need some spinlock for that?
1545920cda627688c3229fd63157ff031f3f174175eAndrzej Pietrasiewicz	 */
1555920cda627688c3229fd63157ff031f3f174175eAndrzej Pietrasiewicz	struct usb_request		*ep0req;		/* P: mutex */
1565920cda627688c3229fd63157ff031f3f174175eAndrzej Pietrasiewicz	struct completion		ep0req_completion;	/* P: mutex */
1575920cda627688c3229fd63157ff031f3f174175eAndrzej Pietrasiewicz
1585920cda627688c3229fd63157ff031f3f174175eAndrzej Pietrasiewicz	/* reference counter */
1595920cda627688c3229fd63157ff031f3f174175eAndrzej Pietrasiewicz	atomic_t			ref;
1605920cda627688c3229fd63157ff031f3f174175eAndrzej Pietrasiewicz	/* how many files are opened (EP0 and others) */
1615920cda627688c3229fd63157ff031f3f174175eAndrzej Pietrasiewicz	atomic_t			opened;
1625920cda627688c3229fd63157ff031f3f174175eAndrzej Pietrasiewicz
1635920cda627688c3229fd63157ff031f3f174175eAndrzej Pietrasiewicz	/* EP0 state */
1645920cda627688c3229fd63157ff031f3f174175eAndrzej Pietrasiewicz	enum ffs_state			state;
1655920cda627688c3229fd63157ff031f3f174175eAndrzej Pietrasiewicz
1665920cda627688c3229fd63157ff031f3f174175eAndrzej Pietrasiewicz	/*
1675920cda627688c3229fd63157ff031f3f174175eAndrzej Pietrasiewicz	 * Possible transitions:
168e46318a00091e3e009363a516acc44a4a80e2ebbMichal Nazarewicz	 * + FFS_NO_SETUP        -> FFS_SETUP_PENDING  -- P: ev.waitq.lock
1695920cda627688c3229fd63157ff031f3f174175eAndrzej Pietrasiewicz	 *               happens only in ep0 read which is P: mutex
170e46318a00091e3e009363a516acc44a4a80e2ebbMichal Nazarewicz	 * + FFS_SETUP_PENDING   -> FFS_NO_SETUP       -- P: ev.waitq.lock
1715920cda627688c3229fd63157ff031f3f174175eAndrzej Pietrasiewicz	 *               happens only in ep0 i/o  which is P: mutex
172e46318a00091e3e009363a516acc44a4a80e2ebbMichal Nazarewicz	 * + FFS_SETUP_PENDING   -> FFS_SETUP_CANCELLED -- P: ev.waitq.lock
173e46318a00091e3e009363a516acc44a4a80e2ebbMichal Nazarewicz	 * + FFS_SETUP_CANCELLED -> FFS_NO_SETUP        -- cmpxchg
174a7ecf0544f0fc710ba6e2ff751d328a4190c4a1fMichal Nazarewicz	 *
175a7ecf0544f0fc710ba6e2ff751d328a4190c4a1fMichal Nazarewicz	 * This field should never be accessed directly and instead
176a7ecf0544f0fc710ba6e2ff751d328a4190c4a1fMichal Nazarewicz	 * ffs_setup_state_clear_cancelled function should be used.
1775920cda627688c3229fd63157ff031f3f174175eAndrzej Pietrasiewicz	 */
1785920cda627688c3229fd63157ff031f3f174175eAndrzej Pietrasiewicz	enum ffs_setup_state		setup_state;
1795920cda627688c3229fd63157ff031f3f174175eAndrzej Pietrasiewicz
1805920cda627688c3229fd63157ff031f3f174175eAndrzej Pietrasiewicz	/* Events & such. */
1815920cda627688c3229fd63157ff031f3f174175eAndrzej Pietrasiewicz	struct {
1825920cda627688c3229fd63157ff031f3f174175eAndrzej Pietrasiewicz		u8				types[4];
1835920cda627688c3229fd63157ff031f3f174175eAndrzej Pietrasiewicz		unsigned short			count;
1845920cda627688c3229fd63157ff031f3f174175eAndrzej Pietrasiewicz		/* XXX REVISIT need to update it in some places, or do we? */
1855920cda627688c3229fd63157ff031f3f174175eAndrzej Pietrasiewicz		unsigned short			can_stall;
1865920cda627688c3229fd63157ff031f3f174175eAndrzej Pietrasiewicz		struct usb_ctrlrequest		setup;
1875920cda627688c3229fd63157ff031f3f174175eAndrzej Pietrasiewicz
1885920cda627688c3229fd63157ff031f3f174175eAndrzej Pietrasiewicz		wait_queue_head_t		waitq;
1895920cda627688c3229fd63157ff031f3f174175eAndrzej Pietrasiewicz	} ev; /* the whole structure, P: ev.waitq.lock */
1905920cda627688c3229fd63157ff031f3f174175eAndrzej Pietrasiewicz
1915920cda627688c3229fd63157ff031f3f174175eAndrzej Pietrasiewicz	/* Flags */
1925920cda627688c3229fd63157ff031f3f174175eAndrzej Pietrasiewicz	unsigned long			flags;
1935920cda627688c3229fd63157ff031f3f174175eAndrzej Pietrasiewicz#define FFS_FL_CALL_CLOSED_CALLBACK 0
1945920cda627688c3229fd63157ff031f3f174175eAndrzej Pietrasiewicz#define FFS_FL_BOUND                1
1955920cda627688c3229fd63157ff031f3f174175eAndrzej Pietrasiewicz
1965920cda627688c3229fd63157ff031f3f174175eAndrzej Pietrasiewicz	/* Active function */
1975920cda627688c3229fd63157ff031f3f174175eAndrzej Pietrasiewicz	struct ffs_function		*func;
1985920cda627688c3229fd63157ff031f3f174175eAndrzej Pietrasiewicz
1995920cda627688c3229fd63157ff031f3f174175eAndrzej Pietrasiewicz	/*
2005920cda627688c3229fd63157ff031f3f174175eAndrzej Pietrasiewicz	 * Device name, write once when file system is mounted.
2015920cda627688c3229fd63157ff031f3f174175eAndrzej Pietrasiewicz	 * Intended for user to read if she wants.
2025920cda627688c3229fd63157ff031f3f174175eAndrzej Pietrasiewicz	 */
2035920cda627688c3229fd63157ff031f3f174175eAndrzej Pietrasiewicz	const char			*dev_name;
2045920cda627688c3229fd63157ff031f3f174175eAndrzej Pietrasiewicz	/* Private data for our user (ie. gadget).  Managed by user. */
2055920cda627688c3229fd63157ff031f3f174175eAndrzej Pietrasiewicz	void				*private_data;
2065920cda627688c3229fd63157ff031f3f174175eAndrzej Pietrasiewicz
2075920cda627688c3229fd63157ff031f3f174175eAndrzej Pietrasiewicz	/* filled by __ffs_data_got_descs() */
2085920cda627688c3229fd63157ff031f3f174175eAndrzej Pietrasiewicz	/*
209ac8dde11f2b397fe2282f585d5eb427a13675ea2Michal Nazarewicz	 * raw_descs is what you kfree, real_descs points inside of raw_descs,
210ac8dde11f2b397fe2282f585d5eb427a13675ea2Michal Nazarewicz	 * where full speed, high speed and super speed descriptors start.
211ac8dde11f2b397fe2282f585d5eb427a13675ea2Michal Nazarewicz	 * real_descs_length is the length of all those descriptors.
2125920cda627688c3229fd63157ff031f3f174175eAndrzej Pietrasiewicz	 */
213ac8dde11f2b397fe2282f585d5eb427a13675ea2Michal Nazarewicz	const void			*raw_descs_data;
2145920cda627688c3229fd63157ff031f3f174175eAndrzej Pietrasiewicz	const void			*raw_descs;
215ac8dde11f2b397fe2282f585d5eb427a13675ea2Michal Nazarewicz	unsigned			raw_descs_length;
2165920cda627688c3229fd63157ff031f3f174175eAndrzej Pietrasiewicz	unsigned			fs_descs_count;
2175920cda627688c3229fd63157ff031f3f174175eAndrzej Pietrasiewicz	unsigned			hs_descs_count;
2188d4e897bd0150fab594a871484e554472ee01452Manu Gautam	unsigned			ss_descs_count;
219f0175ab51993d2dc2728e7b22a16ffb0c8f4cfa0Andrzej Pietrasiewicz	unsigned			ms_os_descs_count;
220f0175ab51993d2dc2728e7b22a16ffb0c8f4cfa0Andrzej Pietrasiewicz	unsigned			ms_os_descs_ext_prop_count;
221f0175ab51993d2dc2728e7b22a16ffb0c8f4cfa0Andrzej Pietrasiewicz	unsigned			ms_os_descs_ext_prop_name_len;
222f0175ab51993d2dc2728e7b22a16ffb0c8f4cfa0Andrzej Pietrasiewicz	unsigned			ms_os_descs_ext_prop_data_len;
223f0175ab51993d2dc2728e7b22a16ffb0c8f4cfa0Andrzej Pietrasiewicz	void				*ms_os_descs_ext_prop_avail;
224f0175ab51993d2dc2728e7b22a16ffb0c8f4cfa0Andrzej Pietrasiewicz	void				*ms_os_descs_ext_prop_name_avail;
225f0175ab51993d2dc2728e7b22a16ffb0c8f4cfa0Andrzej Pietrasiewicz	void				*ms_os_descs_ext_prop_data_avail;
2265920cda627688c3229fd63157ff031f3f174175eAndrzej Pietrasiewicz
2271b0bf88fd8b845aef4300c7c0feca774265dd1c4Robert Baldyga	unsigned			user_flags;
2281b0bf88fd8b845aef4300c7c0feca774265dd1c4Robert Baldyga
2296d5c1c77bbf98b2cc5373af02bb7b3b27584ee4aRobert Baldyga	u8				eps_addrmap[15];
2306d5c1c77bbf98b2cc5373af02bb7b3b27584ee4aRobert Baldyga
2315920cda627688c3229fd63157ff031f3f174175eAndrzej Pietrasiewicz	unsigned short			strings_count;
2325920cda627688c3229fd63157ff031f3f174175eAndrzej Pietrasiewicz	unsigned short			interfaces_count;
2335920cda627688c3229fd63157ff031f3f174175eAndrzej Pietrasiewicz	unsigned short			eps_count;
2345920cda627688c3229fd63157ff031f3f174175eAndrzej Pietrasiewicz	unsigned short			_pad1;
2355920cda627688c3229fd63157ff031f3f174175eAndrzej Pietrasiewicz
2365920cda627688c3229fd63157ff031f3f174175eAndrzej Pietrasiewicz	/* filled by __ffs_data_got_strings() */
2375920cda627688c3229fd63157ff031f3f174175eAndrzej Pietrasiewicz	/* ids in stringtabs are set in functionfs_bind() */
2385920cda627688c3229fd63157ff031f3f174175eAndrzej Pietrasiewicz	const void			*raw_strings;
2395920cda627688c3229fd63157ff031f3f174175eAndrzej Pietrasiewicz	struct usb_gadget_strings	**stringtabs;
2405920cda627688c3229fd63157ff031f3f174175eAndrzej Pietrasiewicz
2415920cda627688c3229fd63157ff031f3f174175eAndrzej Pietrasiewicz	/*
2425920cda627688c3229fd63157ff031f3f174175eAndrzej Pietrasiewicz	 * File system's super block, write once when file system is
2435920cda627688c3229fd63157ff031f3f174175eAndrzej Pietrasiewicz	 * mounted.
2445920cda627688c3229fd63157ff031f3f174175eAndrzej Pietrasiewicz	 */
2455920cda627688c3229fd63157ff031f3f174175eAndrzej Pietrasiewicz	struct super_block		*sb;
2465920cda627688c3229fd63157ff031f3f174175eAndrzej Pietrasiewicz
2475920cda627688c3229fd63157ff031f3f174175eAndrzej Pietrasiewicz	/* File permissions, written once when fs is mounted */
2485920cda627688c3229fd63157ff031f3f174175eAndrzej Pietrasiewicz	struct ffs_file_perms {
2495920cda627688c3229fd63157ff031f3f174175eAndrzej Pietrasiewicz		umode_t				mode;
2505920cda627688c3229fd63157ff031f3f174175eAndrzej Pietrasiewicz		kuid_t				uid;
2515920cda627688c3229fd63157ff031f3f174175eAndrzej Pietrasiewicz		kgid_t				gid;
2525920cda627688c3229fd63157ff031f3f174175eAndrzej Pietrasiewicz	}				file_perms;
2535920cda627688c3229fd63157ff031f3f174175eAndrzej Pietrasiewicz
2545920cda627688c3229fd63157ff031f3f174175eAndrzej Pietrasiewicz	/*
2555920cda627688c3229fd63157ff031f3f174175eAndrzej Pietrasiewicz	 * The endpoint files, filled by ffs_epfiles_create(),
2565920cda627688c3229fd63157ff031f3f174175eAndrzej Pietrasiewicz	 * destroyed by ffs_epfiles_destroy().
2575920cda627688c3229fd63157ff031f3f174175eAndrzej Pietrasiewicz	 */
2585920cda627688c3229fd63157ff031f3f174175eAndrzej Pietrasiewicz	struct ffs_epfile		*epfiles;
2595920cda627688c3229fd63157ff031f3f174175eAndrzej Pietrasiewicz};
2605920cda627688c3229fd63157ff031f3f174175eAndrzej Pietrasiewicz
2615920cda627688c3229fd63157ff031f3f174175eAndrzej Pietrasiewicz
2625920cda627688c3229fd63157ff031f3f174175eAndrzej Pietrasiewiczstruct f_fs_opts {
2635920cda627688c3229fd63157ff031f3f174175eAndrzej Pietrasiewicz	struct usb_function_instance	func_inst;
2645920cda627688c3229fd63157ff031f3f174175eAndrzej Pietrasiewicz	struct ffs_dev			*dev;
2655920cda627688c3229fd63157ff031f3f174175eAndrzej Pietrasiewicz	unsigned			refcnt;
2665920cda627688c3229fd63157ff031f3f174175eAndrzej Pietrasiewicz	bool				no_configfs;
2675920cda627688c3229fd63157ff031f3f174175eAndrzej Pietrasiewicz};
2685920cda627688c3229fd63157ff031f3f174175eAndrzej Pietrasiewicz
2695920cda627688c3229fd63157ff031f3f174175eAndrzej Pietrasiewiczstatic inline struct f_fs_opts *to_f_fs_opts(struct usb_function_instance *fi)
2705920cda627688c3229fd63157ff031f3f174175eAndrzej Pietrasiewicz{
2715920cda627688c3229fd63157ff031f3f174175eAndrzej Pietrasiewicz	return container_of(fi, struct f_fs_opts, func_inst);
2725920cda627688c3229fd63157ff031f3f174175eAndrzej Pietrasiewicz}
2735920cda627688c3229fd63157ff031f3f174175eAndrzej Pietrasiewicz
274e72c39c0692d17da4c7f08e20d6c57f7409415f7Andrzej Pietrasiewicz#endif /* U_FFS_H */
275