Release 4.7 drivers/usb/gadget/legacy/tcm_usb_gadget.c
/* Target based USB-Gadget
*
* UAS protocol handling, target callbacks, configfs handling,
* BBB (USB Mass Storage Class Bulk-Only (BBB) and Transport protocol handling.
*
* Author: Sebastian Andrzej Siewior <bigeasy at linutronix dot de>
* License: GPLv2 as published by FSF.
*/
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/types.h>
#include <linux/string.h>
#include <linux/configfs.h>
#include <linux/ctype.h>
#include <linux/usb/ch9.h>
#include <linux/usb/composite.h>
#include <linux/usb/gadget.h>
#include <linux/usb/storage.h>
#include <scsi/scsi_tcq.h>
#include <target/target_core_base.h>
#include <target/target_core_fabric.h>
#include <asm/unaligned.h>
#include "u_tcm.h"
USB_GADGET_COMPOSITE_OPTIONS();
#define UAS_VENDOR_ID 0x0525
/* NetChip */
#define UAS_PRODUCT_ID 0xa4a5
/* Linux-USB File-backed Storage Gadget */
static struct usb_device_descriptor usbg_device_desc = {
.bLength = sizeof(usbg_device_desc),
.bDescriptorType = USB_DT_DEVICE,
/* .bcdUSB = DYNAMIC */
.bDeviceClass = USB_CLASS_PER_INTERFACE,
.idVendor = cpu_to_le16(UAS_VENDOR_ID),
.idProduct = cpu_to_le16(UAS_PRODUCT_ID),
.bNumConfigurations = 1,
};
#define USB_G_STR_CONFIG USB_GADGET_FIRST_AVAIL_IDX
static struct usb_string usbg_us_strings[] = {
[USB_GADGET_MANUFACTURER_IDX].s = "Target Manufactor",
[USB_GADGET_PRODUCT_IDX].s = "Target Product",
[USB_GADGET_SERIAL_IDX].s = "000000000001",
[USB_G_STR_CONFIG].s = "default config",
{ },
};
static struct usb_gadget_strings usbg_stringtab = {
.language = 0x0409,
.strings = usbg_us_strings,
};
static struct usb_gadget_strings *usbg_strings[] = {
&usbg_stringtab,
NULL,
};
static struct usb_function_instance *fi_tcm;
static struct usb_function *f_tcm;
static int guas_unbind(struct usb_composite_dev *cdev)
{
if (!IS_ERR_OR_NULL(f_tcm))
usb_put_function(f_tcm);
return 0;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
sebastian andrzej siewior | sebastian andrzej siewior | 15 | 55.56% | 1 | 33.33% |
andrzej pietrasiewicz | andrzej pietrasiewicz | 12 | 44.44% | 2 | 66.67% |
| Total | 27 | 100.00% | 3 | 100.00% |
static int tcm_do_config(struct usb_configuration *c)
{
int status;
f_tcm = usb_get_function(fi_tcm);
if (IS_ERR(f_tcm))
return PTR_ERR(f_tcm);
status = usb_add_function(c, f_tcm);
if (status < 0) {
usb_put_function(f_tcm);
return status;
}
return 0;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
sebastian andrzej siewior | sebastian andrzej siewior | 38 | 61.29% | 1 | 50.00% |
andrzej pietrasiewicz | andrzej pietrasiewicz | 24 | 38.71% | 1 | 50.00% |
| Total | 62 | 100.00% | 2 | 100.00% |
static struct usb_configuration usbg_config_driver = {
.label = "Linux Target",
.bConfigurationValue = 1,
.bmAttributes = USB_CONFIG_ATT_SELFPOWER,
};
static int usbg_attach(struct usb_function_instance *f);
static void usbg_detach(struct usb_function_instance *f);
static int usb_target_bind(struct usb_composite_dev *cdev)
{
int ret;
ret = usb_string_ids_tab(cdev, usbg_us_strings);
if (ret)
return ret;
usbg_device_desc.iManufacturer =
usbg_us_strings[USB_GADGET_MANUFACTURER_IDX].id;
usbg_device_desc.iProduct = usbg_us_strings[USB_GADGET_PRODUCT_IDX].id;
usbg_device_desc.iSerialNumber =
usbg_us_strings[USB_GADGET_SERIAL_IDX].id;
usbg_config_driver.iConfiguration =
usbg_us_strings[USB_G_STR_CONFIG].id;
ret = usb_add_config(cdev, &usbg_config_driver, tcm_do_config);
if (ret)
return ret;
usb_composite_overwrite_options(cdev, &coverwrite);
return 0;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
sebastian andrzej siewior | sebastian andrzej siewior | 103 | 99.04% | 4 | 80.00% |
andrzej pietrasiewicz | andrzej pietrasiewicz | 1 | 0.96% | 1 | 20.00% |
| Total | 104 | 100.00% | 5 | 100.00% |
static struct usb_composite_driver usbg_driver = {
.name = "g_target",
.dev = &usbg_device_desc,
.strings = usbg_strings,
.max_speed = USB_SPEED_SUPER,
.bind = usb_target_bind,
.unbind = guas_unbind,
};
static int usbg_attach(struct usb_function_instance *f)
{
return usb_composite_probe(&usbg_driver);
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
sebastian andrzej siewior | sebastian andrzej siewior | 16 | 88.89% | 1 | 50.00% |
andrzej pietrasiewicz | andrzej pietrasiewicz | 2 | 11.11% | 1 | 50.00% |
| Total | 18 | 100.00% | 2 | 100.00% |
static void usbg_detach(struct usb_function_instance *f)
{
usb_composite_unregister(&usbg_driver);
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
sebastian andrzej siewior | sebastian andrzej siewior | 15 | 88.24% | 1 | 50.00% |
andrzej pietrasiewicz | andrzej pietrasiewicz | 2 | 11.76% | 1 | 50.00% |
| Total | 17 | 100.00% | 2 | 100.00% |
static int __init usb_target_gadget_init(void)
{
struct f_tcm_opts *tcm_opts;
fi_tcm = usb_get_function_instance("tcm");
if (IS_ERR(fi_tcm))
return PTR_ERR(fi_tcm);
tcm_opts = container_of(fi_tcm, struct f_tcm_opts, func_inst);
mutex_lock(&tcm_opts->dep_lock);
tcm_opts->tcm_register_callback = usbg_attach;
tcm_opts->tcm_unregister_callback = usbg_detach;
tcm_opts->dependent = THIS_MODULE;
tcm_opts->can_attach = true;
tcm_opts->has_dep = true;
mutex_unlock(&tcm_opts->dep_lock);
fi_tcm->set_inst_name(fi_tcm, "tcm-legacy");
return 0;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
andrzej pietrasiewicz | andrzej pietrasiewicz | 87 | 83.65% | 1 | 33.33% |
sebastian andrzej siewior | sebastian andrzej siewior | 11 | 10.58% | 1 | 33.33% |
christoph hellwig | christoph hellwig | 6 | 5.77% | 1 | 33.33% |
| Total | 104 | 100.00% | 3 | 100.00% |
module_init(usb_target_gadget_init);
static void __exit usb_target_gadget_exit(void)
{
if (!IS_ERR_OR_NULL(fi_tcm))
usb_put_function_instance(fi_tcm);
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
sebastian andrzej siewior | sebastian andrzej siewior | 10 | 45.45% | 1 | 33.33% |
andrzej pietrasiewicz | andrzej pietrasiewicz | 10 | 45.45% | 1 | 33.33% |
christoph hellwig | christoph hellwig | 2 | 9.09% | 1 | 33.33% |
| Total | 22 | 100.00% | 3 | 100.00% |
module_exit(usb_target_gadget_exit);
MODULE_AUTHOR("Sebastian Andrzej Siewior <bigeasy@linutronix.de>");
MODULE_DESCRIPTION("usb-gadget fabric");
MODULE_LICENSE("GPL v2");
Overall Contributors
| Person | Tokens | Prop | Commits | CommitProp |
sebastian andrzej siewior | sebastian andrzej siewior | 371 | 56.73% | 6 | 50.00% |
andrzej pietrasiewicz | andrzej pietrasiewicz | 271 | 41.44% | 3 | 25.00% |
christoph hellwig | christoph hellwig | 8 | 1.22% | 1 | 8.33% |
arnd bergmann | arnd bergmann | 3 | 0.46% | 1 | 8.33% |
linus torvalds | linus torvalds | 1 | 0.15% | 1 | 8.33% |
| Total | 654 | 100.00% | 12 | 100.00% |
Information contained on this website is for historical information purposes only and does not indicate or represent copyright ownership.