[PATCH] target: uasp: gadget: pass SGs for gadget driver

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Gadget framework now has support for Scatter-Gather,
let's use it to avoid the unnecessary memcpy().

Signed-off-by: Felipe Balbi <balbi@xxxxxx>
---

This is the patch i applied on top of Sebastian's UASP
Gadget.

 drivers/target/uasp/gadget.c |   24 ++++++++++++++++++------
 1 files changed, 18 insertions(+), 6 deletions(-)

diff --git a/drivers/target/uasp/gadget.c b/drivers/target/uasp/gadget.c
index 5b7ccaf..212445a 100644
--- a/drivers/target/uasp/gadget.c
+++ b/drivers/target/uasp/gadget.c
@@ -43,6 +43,8 @@ struct f_uas {
 #define UASP_SS_MODE		(1 << 1)
 };
 
+#define fuas_to_gadget(f)	(f->function.config->cdev->gadget)
+
 static struct usb_interface_descriptor uasp_intf_desc = {
 	.bLength =		sizeof(uasp_intf_desc),
 	.bDescriptorType =	USB_DT_INTERFACE,
@@ -370,9 +372,10 @@ static void guas_status_data_cmpl(struct usb_ep *ep, struct usb_request *req);
 static int guas_prepare_r_request(struct uasp_cmd *cmd)
 {
 	struct f_uas *fu = cmd->fu;
+	struct usb_gadget *gadget = fuas_to_gadget(fu);
 	struct se_cmd *se_cmd = &cmd->tvc_se_cmd;
 
-	if (1) {
+	if (gadget->sg_tablesize == 0) {
 		/* XXX no SG support */
 		cmd->data_buf = kmalloc(se_cmd->data_length, GFP_ATOMIC);
 		if (!cmd->data_buf)
@@ -386,6 +389,9 @@ static int guas_prepare_r_request(struct uasp_cmd *cmd)
 		fu->req_in->buf = cmd->data_buf;
 	} else {
 		/* XXX setup sgl */
+		fu->req_in->buf = NULL;
+		fu->req_in->num_sgs = se_cmd->t_data_nents;
+		fu->req_in->sg = se_cmd->t_data_sg;
 	}
 
 	fu->req_in->complete = guas_status_data_cmpl;
@@ -407,10 +413,12 @@ static void guas_data_write_cmpl(struct usb_ep *ep, struct usb_request *req)
 		goto cleanup;
 	}
 
-	sg_copy_from_buffer(se_cmd->t_data_sg,
-			se_cmd->t_data_nents,
-			cmd->data_buf,
-			se_cmd->data_length);
+	if (req->num_sgs == 0) {
+		sg_copy_from_buffer(se_cmd->t_data_sg,
+				se_cmd->t_data_nents,
+				cmd->data_buf,
+				se_cmd->data_length);
+	}
 
 	complete(&cmd->write_complete);
 	return;
@@ -424,9 +432,10 @@ cleanup:
 static int guas_prepare_w_request(struct uasp_cmd *cmd)
 {
 	struct f_uas *fu = cmd->fu;
+	struct usb_gadget *gadget = fuas_to_gadget(fu);
 	struct se_cmd *se_cmd = &cmd->tvc_se_cmd;
 
-	if (1) {
+	if (gadget->sg_tablesize == 0) {
 		/* XXX no SG support */
 		cmd->data_buf = kmalloc(se_cmd->data_length, GFP_ATOMIC);
 		if (!cmd->data_buf)
@@ -435,6 +444,9 @@ static int guas_prepare_w_request(struct uasp_cmd *cmd)
 		fu->req_out->buf = cmd->data_buf;
 	} else {
 		/* XXX setup sgl */
+		fu->req_out->buf = NULL;
+		fu->req_out->num_sgs = se_cmd->t_data_nents;
+		fu->req_out->sg = se_cmd->t_data_sg;
 	}
 
 	fu->req_out->complete = guas_data_write_cmpl;
-- 
1.7.8.rc3

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Linux Media]     [Linux Input]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [Old Linux USB Devel Archive]

  Powered by Linux