mirror of
https://github.com/edk2-porting/linux-next.git
synced 2024-12-25 21:54:06 +08:00
71e4634e00
Pull SCSI target updates from Nicholas Bellinger: "The highlights this round include: - Introduce configfs support for unlocked configfs_depend_item() (krzysztof + andrezej) - Conversion of usb-gadget target driver to new function registration interface (andrzej + sebastian) - Enable qla2xxx FC target mode support for Extended Logins (himansu + giridhar) - Enable qla2xxx FC target mode support for Exchange Offload (himansu + giridhar) - Add qla2xxx FC target mode irq affinity notification + selective command queuing. (quinn + himanshu) - Fix iscsi-target deadlock in se_node_acl configfs deletion (sagi + nab) - Convert se_node_acl configfs deletion + se_node_acl->queue_depth to proper se_session->sess_kref + target_get_session() usage. (hch + sagi + nab) - Fix long-standing race between se_node_acl->acl_kref get and get_initiator_node_acl() lookup. (hch + nab) - Fix target/user block-size handling, and make sure netlink reaches all network namespaces (sheng + andy) Note there is an outstanding bug-fix series for remote I_T nexus port TMR LUN_RESET has been posted and still being tested, and will likely become post -rc1 material at this point" * 'for-next' of git://git.kernel.org/pub/scm/linux/kernel/git/nab/target-pending: (56 commits) scsi: qla2xxxx: avoid type mismatch in comparison target/user: Make sure netlink would reach all network namespaces target: Obtain se_node_acl->acl_kref during get_initiator_node_acl target: Convert ACL change queue_depth se_session reference usage iscsi-target: Fix potential dead-lock during node acl delete ib_srpt: Convert acl lookup to modern get_initiator_node_acl usage tcm_fc: Convert acl lookup to modern get_initiator_node_acl usage tcm_fc: Wait for command completion before freeing a session target: Fix a memory leak in target_dev_lba_map_store() target: Support aborting tasks with a 64-bit tag usb/gadget: Remove set-but-not-used variables target: Remove an unused variable target: Fix indentation in target_core_configfs.c target/user: Allow user to set block size before enabling device iser-target: Fix non negative ERR_PTR isert_device_get usage target/fcoe: Add tag support to tcm_fc qla2xxx: Check for online flag instead of active reset when transmitting responses qla2xxx: Set all queues to 4k qla2xxx: Disable ZIO at start time. qla2xxx: Move atioq to a different lock to reduce lock contention ...
174 lines
4.3 KiB
C
174 lines
4.3 KiB
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;
|
|
}
|
|
|
|
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;
|
|
}
|
|
|
|
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;
|
|
}
|
|
|
|
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);
|
|
}
|
|
|
|
static void usbg_detach(struct usb_function_instance *f)
|
|
{
|
|
usb_composite_unregister(&usbg_driver);
|
|
}
|
|
|
|
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;
|
|
}
|
|
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);
|
|
|
|
}
|
|
module_exit(usb_target_gadget_exit);
|
|
|
|
MODULE_AUTHOR("Sebastian Andrzej Siewior <bigeasy@linutronix.de>");
|
|
MODULE_DESCRIPTION("usb-gadget fabric");
|
|
MODULE_LICENSE("GPL v2");
|