These changes are the raw update to linux-4.4.6-rt14. Kernel sources
[kvmfornfv.git] / kernel / drivers / usb / gadget / legacy / tcm_usb_gadget.c
index f9b4882..22e5615 100644 (file)
 #include <linux/usb/composite.h>
 #include <linux/usb/gadget.h>
 #include <linux/usb/storage.h>
-#include <scsi/scsi.h>
 #include <scsi/scsi_tcq.h>
 #include <target/target_core_base.h>
 #include <target/target_core_fabric.h>
-#include <target/target_core_fabric_configfs.h>
-#include <target/target_core_configfs.h>
-#include <target/configfs_macros.h>
 #include <asm/unaligned.h>
 
 #include "tcm_usb_gadget.h"
 
 USB_GADGET_COMPOSITE_OPTIONS();
 
-static const struct target_core_fabric_ops usbg_ops;
-
 static inline struct f_uas *to_f_uas(struct usb_function *f)
 {
        return container_of(f, struct f_uas, function);
@@ -1112,6 +1106,7 @@ static int usbg_submit_command(struct f_uas *fu,
        memcpy(cmd->cmd_buf, cmd_iu->cdb, cmd_len);
 
        cmd->tag = be16_to_cpup(&cmd_iu->tag);
+       cmd->se_cmd.tag = cmd->tag;
        if (fu->flags & USBG_USE_STREAMS) {
                if (cmd->tag > UASP_SS_EP_COMP_NUM_STREAMS)
                        goto err;
@@ -1245,6 +1240,7 @@ static int bot_submit_command(struct f_uas *fu,
        cmd->unpacked_lun = cbw->Lun;
        cmd->is_read = cbw->Flags & US_BULK_FLAG_IN ? 1 : 0;
        cmd->data_len = le32_to_cpu(cbw->DataTransferLength);
+       cmd->se_cmd.tag = le32_to_cpu(cmd->bot_tag);
 
        INIT_WORK(&cmd->work, bot_cmd_work);
        ret = queue_work(tpg->workqueue, &cmd->work);
@@ -1274,23 +1270,6 @@ static char *usbg_get_fabric_name(void)
        return "usb_gadget";
 }
 
-static u8 usbg_get_fabric_proto_ident(struct se_portal_group *se_tpg)
-{
-       struct usbg_tpg *tpg = container_of(se_tpg,
-                               struct usbg_tpg, se_tpg);
-       struct usbg_tport *tport = tpg->tport;
-       u8 proto_id;
-
-       switch (tport->tport_proto_id) {
-       case SCSI_PROTOCOL_SAS:
-       default:
-               proto_id = sas_get_fabric_proto_ident(se_tpg);
-               break;
-       }
-
-       return proto_id;
-}
-
 static char *usbg_get_fabric_wwn(struct se_portal_group *se_tpg)
 {
        struct usbg_tpg *tpg = container_of(se_tpg,
@@ -1307,97 +1286,6 @@ static u16 usbg_get_tag(struct se_portal_group *se_tpg)
        return tpg->tport_tpgt;
 }
 
-static u32 usbg_get_default_depth(struct se_portal_group *se_tpg)
-{
-       return 1;
-}
-
-static u32 usbg_get_pr_transport_id(
-       struct se_portal_group *se_tpg,
-       struct se_node_acl *se_nacl,
-       struct t10_pr_registration *pr_reg,
-       int *format_code,
-       unsigned char *buf)
-{
-       struct usbg_tpg *tpg = container_of(se_tpg,
-                               struct usbg_tpg, se_tpg);
-       struct usbg_tport *tport = tpg->tport;
-       int ret = 0;
-
-       switch (tport->tport_proto_id) {
-       case SCSI_PROTOCOL_SAS:
-       default:
-               ret = sas_get_pr_transport_id(se_tpg, se_nacl, pr_reg,
-                                       format_code, buf);
-               break;
-       }
-
-       return ret;
-}
-
-static u32 usbg_get_pr_transport_id_len(
-       struct se_portal_group *se_tpg,
-       struct se_node_acl *se_nacl,
-       struct t10_pr_registration *pr_reg,
-       int *format_code)
-{
-       struct usbg_tpg *tpg = container_of(se_tpg,
-                               struct usbg_tpg, se_tpg);
-       struct usbg_tport *tport = tpg->tport;
-       int ret = 0;
-
-       switch (tport->tport_proto_id) {
-       case SCSI_PROTOCOL_SAS:
-       default:
-               ret = sas_get_pr_transport_id_len(se_tpg, se_nacl, pr_reg,
-                                       format_code);
-               break;
-       }
-
-       return ret;
-}
-
-static char *usbg_parse_pr_out_transport_id(
-       struct se_portal_group *se_tpg,
-       const char *buf,
-       u32 *out_tid_len,
-       char **port_nexus_ptr)
-{
-       struct usbg_tpg *tpg = container_of(se_tpg,
-                               struct usbg_tpg, se_tpg);
-       struct usbg_tport *tport = tpg->tport;
-       char *tid = NULL;
-
-       switch (tport->tport_proto_id) {
-       case SCSI_PROTOCOL_SAS:
-       default:
-               tid = sas_parse_pr_out_transport_id(se_tpg, buf, out_tid_len,
-                                       port_nexus_ptr);
-       }
-
-       return tid;
-}
-
-static struct se_node_acl *usbg_alloc_fabric_acl(struct se_portal_group *se_tpg)
-{
-       struct usbg_nacl *nacl;
-
-       nacl = kzalloc(sizeof(struct usbg_nacl), GFP_KERNEL);
-       if (!nacl)
-               return NULL;
-
-       return &nacl->se_node_acl;
-}
-
-static void usbg_release_fabric_acl(
-       struct se_portal_group *se_tpg,
-       struct se_node_acl *se_nacl)
-{
-       struct usbg_nacl *nacl = container_of(se_nacl,
-                       struct usbg_nacl, se_node_acl);
-       kfree(nacl);
-}
-
 static u32 usbg_tpg_get_inst_index(struct se_portal_group *se_tpg)
 {
        return 1;
@@ -1448,18 +1336,6 @@ static void usbg_set_default_node_attrs(struct se_node_acl *nacl)
        return;
 }
 
-static u32 usbg_get_task_tag(struct se_cmd *se_cmd)
-{
-       struct usbg_cmd *cmd = container_of(se_cmd, struct usbg_cmd,
-                       se_cmd);
-       struct f_uas *fu = cmd->fu;
-
-       if (fu->flags & USBG_IS_BOT)
-               return le32_to_cpu(cmd->bot_tag);
-       else
-               return cmd->tag;
-}
-
 static int usbg_get_cmd_state(struct se_cmd *se_cmd)
 {
        return 0;
@@ -1489,50 +1365,11 @@ static const char *usbg_check_wwn(const char *name)
        return n;
 }
 
-static struct se_node_acl *usbg_make_nodeacl(
-       struct se_portal_group *se_tpg,
-       struct config_group *group,
-       const char *name)
-{
-       struct se_node_acl *se_nacl, *se_nacl_new;
-       struct usbg_nacl *nacl;
-       u64 wwpn = 0;
-       u32 nexus_depth;
-       const char *wnn_name;
-
-       wnn_name = usbg_check_wwn(name);
-       if (!wnn_name)
-               return ERR_PTR(-EINVAL);
-       se_nacl_new = usbg_alloc_fabric_acl(se_tpg);
-       if (!(se_nacl_new))
-               return ERR_PTR(-ENOMEM);
-
-       nexus_depth = 1;
-       /*
-        * se_nacl_new may be released by core_tpg_add_initiator_node_acl()
-        * when converting a NodeACL from demo mode -> explict
-        */
-       se_nacl = core_tpg_add_initiator_node_acl(se_tpg, se_nacl_new,
-                               name, nexus_depth);
-       if (IS_ERR(se_nacl)) {
-               usbg_release_fabric_acl(se_tpg, se_nacl_new);
-               return se_nacl;
-       }
-       /*
-        * Locate our struct usbg_nacl and set the FC Nport WWPN
-        */
-       nacl = container_of(se_nacl, struct usbg_nacl, se_node_acl);
-       nacl->iport_wwpn = wwpn;
-       snprintf(nacl->iport_name, sizeof(nacl->iport_name), "%s", name);
-       return se_nacl;
-}
-
-static void usbg_drop_nodeacl(struct se_node_acl *se_acl)
+static int usbg_init_nodeacl(struct se_node_acl *se_nacl, const char *name)
 {
-       struct usbg_nacl *nacl = container_of(se_acl,
-                               struct usbg_nacl, se_node_acl);
-       core_tpg_del_initiator_node_acl(se_acl->se_tpg, se_acl, 1);
-       kfree(nacl);
+       if (!usbg_check_wwn(name))
+               return -EINVAL;
+       return 0;
 }
 
 struct usbg_tpg *the_only_tpg_I_currently_have;
@@ -1572,8 +1409,11 @@ static struct se_portal_group *usbg_make_tpg(
        tpg->tport = tport;
        tpg->tport_tpgt = tpgt;
 
-       ret = core_tpg_register(&usbg_ops, wwn, &tpg->se_tpg, tpg,
-                               TRANSPORT_TPG_TYPE_NORMAL);
+       /*
+        * SPC doesn't assign a protocol identifier for USB-SCSI, so we
+        * pretend to be SAS..
+        */
+       ret = core_tpg_register(wwn, &tpg->se_tpg, SCSI_PROTOCOL_SAS);
        if (ret < 0) {
                destroy_workqueue(tpg->workqueue);
                kfree(tpg);
@@ -1625,23 +1465,21 @@ static void usbg_drop_tport(struct se_wwn *wwn)
 /*
  * If somebody feels like dropping the version property, go ahead.
  */
-static ssize_t usbg_wwn_show_attr_version(
-       struct target_fabric_configfs *tf,
-       char *page)
+static ssize_t usbg_wwn_version_show(struct config_item *item, char *page)
 {
        return sprintf(page, "usb-gadget fabric module\n");
 }
-TF_WWN_ATTR_RO(usbg, version);
+
+CONFIGFS_ATTR_RO(usbg_wwn_, version);
 
 static struct configfs_attribute *usbg_wwn_attrs[] = {
-       &usbg_wwn_version.attr,
+       &usbg_wwn_attr_version,
        NULL,
 };
 
-static ssize_t tcm_usbg_tpg_show_enable(
-               struct se_portal_group *se_tpg,
-               char *page)
+static ssize_t tcm_usbg_tpg_enable_show(struct config_item *item, char *page)
 {
+       struct se_portal_group *se_tpg = to_tpg(item);
        struct usbg_tpg  *tpg = container_of(se_tpg, struct usbg_tpg, se_tpg);
 
        return snprintf(page, PAGE_SIZE, "%u\n", tpg->gadget_connect);
@@ -1650,11 +1488,10 @@ static ssize_t tcm_usbg_tpg_show_enable(
 static int usbg_attach(struct usbg_tpg *);
 static void usbg_detach(struct usbg_tpg *);
 
-static ssize_t tcm_usbg_tpg_store_enable(
-               struct se_portal_group *se_tpg,
-               const char *page,
-               size_t count)
+static ssize_t tcm_usbg_tpg_enable_store(struct config_item *item,
+               const char *page, size_t count)
 {
+       struct se_portal_group *se_tpg = to_tpg(item);
        struct usbg_tpg  *tpg = container_of(se_tpg, struct usbg_tpg, se_tpg);
        unsigned long op;
        ssize_t ret;
@@ -1681,12 +1518,10 @@ static ssize_t tcm_usbg_tpg_store_enable(
 out:
        return count;
 }
-TF_TPG_BASE_ATTR(tcm_usbg, enable, S_IRUGO | S_IWUSR);
 
-static ssize_t tcm_usbg_tpg_show_nexus(
-               struct se_portal_group *se_tpg,
-               char *page)
+static ssize_t tcm_usbg_tpg_nexus_show(struct config_item *item, char *page)
 {
+       struct se_portal_group *se_tpg = to_tpg(item);
        struct usbg_tpg *tpg = container_of(se_tpg, struct usbg_tpg, se_tpg);
        struct tcm_usbg_nexus *tv_nexus;
        ssize_t ret;
@@ -1794,11 +1629,10 @@ out:
        return ret;
 }
 
-static ssize_t tcm_usbg_tpg_store_nexus(
-               struct se_portal_group *se_tpg,
-               const char *page,
-               size_t count)
+static ssize_t tcm_usbg_tpg_nexus_store(struct config_item *item,
+               const char *page, size_t count)
 {
+       struct se_portal_group *se_tpg = to_tpg(item);
        struct usbg_tpg *tpg = container_of(se_tpg, struct usbg_tpg, se_tpg);
        unsigned char i_port[USBG_NAMELEN], *ptr;
        int ret;
@@ -1828,11 +1662,13 @@ static ssize_t tcm_usbg_tpg_store_nexus(
                return ret;
        return count;
 }
-TF_TPG_BASE_ATTR(tcm_usbg, nexus, S_IRUGO | S_IWUSR);
+
+CONFIGFS_ATTR(tcm_usbg_tpg_, enable);
+CONFIGFS_ATTR(tcm_usbg_tpg_, nexus);
 
 static struct configfs_attribute *usbg_base_attrs[] = {
-       &tcm_usbg_tpg_enable.attr,
-       &tcm_usbg_tpg_nexus.attr,
+       &tcm_usbg_tpg_attr_enable,
+       &tcm_usbg_tpg_attr_nexus,
        NULL,
 };
 
@@ -1867,19 +1703,12 @@ static const struct target_core_fabric_ops usbg_ops = {
        .module                         = THIS_MODULE,
        .name                           = "usb_gadget",
        .get_fabric_name                = usbg_get_fabric_name,
-       .get_fabric_proto_ident         = usbg_get_fabric_proto_ident,
        .tpg_get_wwn                    = usbg_get_fabric_wwn,
        .tpg_get_tag                    = usbg_get_tag,
-       .tpg_get_default_depth          = usbg_get_default_depth,
-       .tpg_get_pr_transport_id        = usbg_get_pr_transport_id,
-       .tpg_get_pr_transport_id_len    = usbg_get_pr_transport_id_len,
-       .tpg_parse_pr_out_transport_id  = usbg_parse_pr_out_transport_id,
        .tpg_check_demo_mode            = usbg_check_true,
        .tpg_check_demo_mode_cache      = usbg_check_false,
        .tpg_check_demo_mode_write_protect = usbg_check_false,
        .tpg_check_prod_mode_write_protect = usbg_check_false,
-       .tpg_alloc_fabric_acl           = usbg_alloc_fabric_acl,
-       .tpg_release_fabric_acl         = usbg_release_fabric_acl,
        .tpg_get_inst_index             = usbg_tpg_get_inst_index,
        .release_cmd                    = usbg_release_cmd,
        .shutdown_session               = usbg_shutdown_session,
@@ -1889,7 +1718,6 @@ static const struct target_core_fabric_ops usbg_ops = {
        .write_pending                  = usbg_send_write_request,
        .write_pending_status           = usbg_write_pending_status,
        .set_default_node_attributes    = usbg_set_default_node_attrs,
-       .get_task_tag                   = usbg_get_task_tag,
        .get_cmd_state                  = usbg_get_cmd_state,
        .queue_data_in                  = usbg_send_read_response,
        .queue_status                   = usbg_send_status_response,
@@ -1903,10 +1731,7 @@ static const struct target_core_fabric_ops usbg_ops = {
        .fabric_drop_tpg                = usbg_drop_tpg,
        .fabric_post_link               = usbg_port_link,
        .fabric_pre_unlink              = usbg_port_unlink,
-       .fabric_make_np                 = NULL,
-       .fabric_drop_np                 = NULL,
-       .fabric_make_nodeacl            = usbg_make_nodeacl,
-       .fabric_drop_nodeacl            = usbg_drop_nodeacl,
+       .fabric_init_nodeacl            = usbg_init_nodeacl,
 
        .tfc_wwn_attrs                  = usbg_wwn_attrs,
        .tfc_tpg_base_attrs             = usbg_base_attrs,
@@ -2187,14 +2012,6 @@ static struct usb_configuration usbg_config_driver = {
        .bmAttributes           = USB_CONFIG_ATT_SELFPOWER,
 };
 
-static void give_back_ep(struct usb_ep **pep)
-{
-       struct usb_ep *ep = *pep;
-       if (!ep)
-               return;
-       ep->driver_data = NULL;
-}
-
 static int usbg_bind(struct usb_configuration *c, struct usb_function *f)
 {
        struct f_uas            *fu = to_f_uas(f);
@@ -2214,29 +2031,24 @@ static int usbg_bind(struct usb_configuration *c, struct usb_function *f)
                        &uasp_bi_ep_comp_desc);
        if (!ep)
                goto ep_fail;
-
-       ep->driver_data = fu;
        fu->ep_in = ep;
 
        ep = usb_ep_autoconfig_ss(gadget, &uasp_ss_bo_desc,
                        &uasp_bo_ep_comp_desc);
        if (!ep)
                goto ep_fail;
-       ep->driver_data = fu;
        fu->ep_out = ep;
 
        ep = usb_ep_autoconfig_ss(gadget, &uasp_ss_status_desc,
                        &uasp_status_in_ep_comp_desc);
        if (!ep)
                goto ep_fail;
-       ep->driver_data = fu;
        fu->ep_status = ep;
 
        ep = usb_ep_autoconfig_ss(gadget, &uasp_ss_cmd_desc,
                        &uasp_cmd_comp_desc);
        if (!ep)
                goto ep_fail;
-       ep->driver_data = fu;
        fu->ep_cmd = ep;
 
        /* Assume endpoint addresses are the same for both speeds */
@@ -2260,11 +2072,6 @@ static int usbg_bind(struct usb_configuration *c, struct usb_function *f)
        return 0;
 ep_fail:
        pr_err("Can't claim all required eps\n");
-
-       give_back_ep(&fu->ep_in);
-       give_back_ep(&fu->ep_out);
-       give_back_ep(&fu->ep_status);
-       give_back_ep(&fu->ep_cmd);
        return -ENOTSUPP;
 }