Skip to contentSkip to conversation

uas: HS-UAS mode implementation

PATCH New Tatyana Brokhman 1 participant 1 message Apr 14, 2011

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 5/5 uas: HS-UAS mode implementation

This patch adds implementation for UAS protocol over a HS USB bus connection.

drivers/usb/gadget/f_uasp.c +17 -8
index 7b1e2bd..1323207 100644
@@ -928,6 +928,8 @@ reset_uasp:
 
 	fcommon->fsg = new_fsg;
 	fsgd = fcommon->fsg;
+	uaspd->op_mode = (fcommon->gadget->speed == USB_SPEED_SUPER ?
+			  SS_UASP_MODE : HS_UASP_MODE);
 
 	/* Enable the endpoints */
 	config_ep_by_speed(fcommon->gadget, &fsgd->function, fsgd->bulk_in);
@@ -996,9 +998,9 @@ reset_uasp:
 		goto reset_uasp;
 	}
 
-	DBG(uaspd->ucommon->common, "%s() allocated command request = %p, "
-				    "udev=%p\n", __func__,
-				uaspd->cmd_buff.outreq, uaspd);
+	DBG(uaspd->ucommon->common, "%s() Enebled endpoints. "
+				    "Opperation mode = %d\n", __func__,
+				uaspd->op_mode);
 	uaspd->cmd_buff.outreq->buf = &(uaspd->cmd_buff.buf);
 	uaspd->cmd_buff.inreq = NULL;
 	uaspd->cmd_buff.state = BUF_STATE_EMPTY;
@@ -1202,6 +1204,7 @@ static int uasp_command_check(struct uasp_dev *udev, void **command)
 		list_for_each_entry(tmp_cmdiu, &curlun->cmd_queue, node) {
 			if (tmp_cmdiu->state != COMMAND_STATE_IDLE &&
 			    tmp_cmdiu->state != COMMAND_STATE_DATA &&
+			    tmp_cmdiu->state != COMMAND_STATE_RR_WR &&
 			    tmp_cmdiu->state != COMMAND_STATE_STATUS) {
 				continue;
 			}
@@ -1228,6 +1231,7 @@ static int uasp_command_check(struct uasp_dev *udev, void **command)
 	list_for_each_entry(tmp_cmdiu, &udev->cmd_queue, node) {
 		if (tmp_cmdiu->state != COMMAND_STATE_IDLE &&
 		    tmp_cmdiu->state != COMMAND_STATE_DATA &&
+		    tmp_cmdiu->state != COMMAND_STATE_RR_WR &&
 		    tmp_cmdiu->state != COMMAND_STATE_STATUS)
 			continue;
 
@@ -1306,7 +1310,8 @@ overlapped_tag:
 		fill_usb_request(tmiu->bh->inreq, tmiu->bh->buf,
 				 UASP_SIZEOF_RESPONSE_IU, 0,
 				 (void *)tmiu, 0,
-				 be16_to_cpup(&tmiu->tag), status_complete);
+				 be16_to_cpup(&tmiu->tag), status_complete,
+				 udev->op_mode);
 
 		tmiu->ep = udev->status;
 		tmiu->bh->inreq_busy = 1;
@@ -1335,7 +1340,8 @@ overlapped_tag:
 		fill_usb_request(cmdiu->bh->inreq, cmdiu->bh->buf,
 				 UASP_SIZEOF_SENSE_IU, 0,
 				 (void *)cmdiu, 0,
-				 be16_to_cpup(&cmdiu->tag), status_complete);
+				 be16_to_cpup(&cmdiu->tag), status_complete,
+				 udev->op_mode);
 		cmdiu->ep = udev->status;
 		cmdiu->bh->inreq_busy = 1;
 		if (usb_ep_queue(cmdiu->ep, cmdiu->bh->inreq, 0))
@@ -1674,7 +1680,8 @@ void abort_commands(struct uasp_dev *udev,
 
 	spin_lock_irqsave(lock, flags);
 	list_for_each_entry_safe(cmdiu, tmp_cmdiu, cmd_queue, node) {
-		if (cmdiu->state == COMMAND_STATE_DATA) {
+		if (cmdiu->state == COMMAND_STATE_DATA ||
+		    cmdiu->state == COMMAND_STATE_RR_WR) {
 			if (cmdiu->req_sts == CMD_REQ_IN_PROGRESS) {
 				spin_unlock_irqrestore(lock, flags);
 				if (cmdiu->bh->inreq_busy)
@@ -2377,6 +2384,7 @@ uasp_add_err:
  * @short_not_ok: short_not_ok field of the request.
  * @stream_id: stream_id field of the request.
  * @complete: complete function to be called on request completion
+ * @op_mode: operation mode (HS_UASP_MODE/SS_UASP_MODE)
  *
  */
 void fill_usb_request(struct usb_request *req,
@@ -2386,14 +2394,15 @@ void fill_usb_request(struct usb_request *req,
 		      void *context,
 		      unsigned short_not_ok,
 		      unsigned stream_id,
-		      usb_request_complete_t complete)
+		      usb_request_complete_t complete,
+		      uint8_t op_mode)
 {
 	req->buf = buf;
 	req->length = length;
 	req->zero = zero;
 	req->context = context;
 	req->short_not_ok = short_not_ok;
-	req->stream_id = stream_id;
+	req->stream_id = (op_mode == SS_UASP_MODE ? stream_id : 0);
 	req->complete = complete;
 }
 
drivers/usb/gadget/f_uasp.h +28 -1
index 42e0d0fa..651d030 100644
@@ -130,6 +130,10 @@ struct uasp_dev {
 	struct usb_ep		*command;
 	struct fsg_buffhd	cmd_buff;
 
+#define HS_UASP_MODE		0
+#define SS_UASP_MODE		1
+	uint8_t			op_mode;
+
 	unsigned int		cmd_enabled;
 	unsigned int		status_enabled;
 
@@ -343,6 +347,28 @@ struct response_iu {
 } __attribute__((__packed__));
 #define UASP_SIZEOF_RESPONSE_IU		8
 
+
+/* READ/WRITE READY IU - see table 14/15 of the UAS Spec */
+struct rw_ready_iu {
+	__u8 iu_id;
+	__u8 reserved;
+	__be16 tag;	/* section 4.2 of the UAS spec */
+} __attribute__((__packed__));
+#define UASP_SIZEOF_RW_READY_IU	4
+
+/**
+ * fill_usb_request() - fills the usb_request structure with the given values.
+ * @req: pointer to usb_request structure to be filled.
+ * @buf: the buffer to send/receive
+ * @length: length field of the request.
+ * @zero: zero field of the request.
+ * @context: context field of the request.
+ * @short_not_ok: short_not_ok field of the request.
+ * @stream_id: stream_id field of the request.
+ * @complete: complete function to be called on request completion
+ * @op_mode: operation mode (HS_UASP_MODE/SS_UASP_MODE)
+ *
+ */
 void fill_usb_request(struct usb_request *req,
 		      void *buf,
 		      unsigned length,
@@ -350,7 +376,8 @@ void fill_usb_request(struct usb_request *req,
 		      void *context,
 		      unsigned short_not_ok,
 		      unsigned stream_id,
-		      usb_request_complete_t complete);
+		      usb_request_complete_t complete,
+		      uint8_t op_mode);
 
 /**
  * uasp_bulk_in_complete() - Callback function for the bulk IN endpoint
drivers/usb/gadget/uasp_cmdiu.c +235 -29

472 lines not on this page · raw message

drivers/usb/gadget/uasp_tmiu.c +11 -9
index 0b4b417..37d8d39 100644
@@ -90,7 +90,7 @@ res_lun_fill_response:
 
 	fill_usb_request(tmiu->bh->inreq, (void *)riu, UASP_SIZEOF_RESPONSE_IU,
 			 0, (void *)tmiu, 0, be16_to_cpup(&tmiu->tag),
-			 status_complete);
+			 status_complete, udev->op_mode);
 	tmiu->ep = udev->status;
 }
 
@@ -134,7 +134,8 @@ static void abort_task(struct uasp_dev *udev,
 found:
 	if (cmdiu) {
 		spin_lock_irqsave(&(curlun->lock), flags);
-		if (cmdiu->state == COMMAND_STATE_DATA) {
+		if (cmdiu->state == COMMAND_STATE_DATA ||
+		    cmdiu->state == COMMAND_STATE_RR_WR) {
 			if (cmdiu->req_sts == CMD_REQ_IN_PROGRESS) {
 				spin_unlock_irqrestore(&(curlun->lock), flags);
 				if (cmdiu->bh->inreq_busy)
@@ -161,7 +162,7 @@ abrt_task_fill_response:
 
 	fill_usb_request(tmiu->bh->inreq, (void *)riu, UASP_SIZEOF_RESPONSE_IU,
 			 0, (void *)tmiu, 0, be16_to_cpup(&tmiu->tag),
-			 status_complete);
+			 status_complete, udev->op_mode);
 	tmiu->ep = udev->status;
 }
 
@@ -203,7 +204,7 @@ abrt_ts_fill_response:
 
 	fill_usb_request(tmiu->bh->inreq, (void *)riu, UASP_SIZEOF_RESPONSE_IU,
 			 0, (void *)tmiu, 0, be16_to_cpup(&tmiu->tag),
-			 status_complete);
+			 status_complete, udev->op_mode);
 	tmiu->ep = udev->status;
 }
 
@@ -258,7 +259,7 @@ reset_nexus_fill_response:
 		RESPONSE_TM_FUNCTION_COMPLETE);
 	fill_usb_request(tmiu->bh->inreq, (void *)riu, UASP_SIZEOF_RESPONSE_IU,
 			 0, (void *)tmiu, 0, be16_to_cpup(&tmiu->tag),
-			 status_complete);
+			 status_complete, udev->op_mode);
 	tmiu->ep = udev->status;
 	DBG(udev->ucommon->common, "%s() - Exit\n", __func__);
 }
@@ -306,7 +307,7 @@ qut_fill_response:
 
 	fill_usb_request(tmiu->bh->inreq, (void *)riu, UASP_SIZEOF_RESPONSE_IU,
 			 0, (void *)tmiu, 0, be16_to_cpup(&tmiu->tag),
-			 status_complete);
+			 status_complete, udev->op_mode);
 
 	tmiu->ep = udev->status;
 }
@@ -342,6 +343,7 @@ static void query_task(struct uasp_dev *udev,
 		if (cmdiu->tag == tmiu->task_tag) {
 			if (cmdiu->state == COMMAND_STATE_IDLE  ||
 			    cmdiu->state == COMMAND_STATE_DATA  ||
+			    cmdiu->state == COMMAND_STATE_RR_WR ||
 			    cmdiu->state == COMMAND_STATE_STATUS)
 				status = RESPONSE_TM_FUNCTION_SUCCEEDED;
 			spin_unlock_irqrestore(&(curlun->lock), flags);
@@ -354,7 +356,7 @@ q_task_fill_response:
 	fill_response_iu(udev, riu, tmiu->tag, 0, status);
 	fill_usb_request(tmiu->bh->inreq, (void *)riu, UASP_SIZEOF_RESPONSE_IU,
 			 0, (void *)tmiu, 0, be16_to_cpup(&tmiu->tag),
-			 status_complete);
+			 status_complete, udev->op_mode);
 	tmiu->ep = udev->status;
 }
 
@@ -402,7 +404,7 @@ q_task_set_fill_response:
 	fill_response_iu(udev, riu, tmiu->tag, 0, status);
 	fill_usb_request(tmiu->bh->inreq, (void *)riu, UASP_SIZEOF_RESPONSE_IU,
 			 0, (void *)tmiu, 0, be16_to_cpup(&tmiu->tag),
-			 status_complete);
+			 status_complete, udev->op_mode);
 	tmiu->ep = udev->status;
 	DBG(udev->ucommon->common, "%s() - Exit\n", __func__);
 }
@@ -461,7 +463,7 @@ static void process_tmiu(struct uasp_dev *udev,
 		fill_usb_request(tmiu->bh->inreq, (void *)riu,
 				 UASP_SIZEOF_RESPONSE_IU, 0,
 				 (void *)tmiu, 0, be16_to_cpup(&tmiu->tag),
-				 status_complete);
+				 status_complete, udev->op_mode);
 		tmiu->ep = udev->status;
 		break;
 	}
Signature · 5 lines
1.7.3.3

--
Sent by a Consultant for Qualcomm Innovation Center, Inc.
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum