drivers/usb/cdns3/gadget.c:1188:29: sparse: sparse: incorrect type in assignment (different base types)

From: kbuild test robot
Date: Fri May 29 2020 - 18:09:23 EST


tree: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master
head: 75caf310d16cc5e2f851c048cd597f5437013368
commit: 70d8b9e5e63d212019ba3f6823c8ec3d2df87645 usb: cdns3: make signed 1 bit bitfields unsigned
date: 9 weeks ago
config: i386-randconfig-s031-20200529 (attached as .config)
compiler: gcc-9 (Debian 9.3.0-13) 9.3.0
reproduce:
# apt-get install sparse
# sparse version: v0.6.1-243-gc100a7ab-dirty
git checkout 70d8b9e5e63d212019ba3f6823c8ec3d2df87645
# save the attached .config to linux build tree
make W=1 C=1 ARCH=i386 CF='-fdiagnostic-prefix -D__CHECK_ENDIAN__'

If you fix the issue, kindly add following tag as appropriate
Reported-by: kbuild test robot <lkp@xxxxxxxxx>


sparse warnings: (new ones prefixed by >>)

drivers/usb/cdns3/gadget.c:1157:35: sparse: sparse: incorrect type in assignment (different base types) @@ expected restricted __le32 [usertype] control @@ got unsigned long @@
drivers/usb/cdns3/gadget.c:1157:35: sparse: expected restricted __le32 [usertype] control
drivers/usb/cdns3/gadget.c:1157:35: sparse: got unsigned long
drivers/usb/cdns3/gadget.c:1173:29: sparse: sparse: incorrect type in assignment (different base types) @@ expected restricted __le32 [usertype] buffer @@ got unsigned long @@
drivers/usb/cdns3/gadget.c:1173:29: sparse: expected restricted __le32 [usertype] buffer
drivers/usb/cdns3/gadget.c:1173:29: sparse: got unsigned long
>> drivers/usb/cdns3/gadget.c:1188:29: sparse: sparse: incorrect type in assignment (different base types) @@ expected restricted __le32 [usertype] length @@ got unsigned long @@
drivers/usb/cdns3/gadget.c:1188:29: sparse: expected restricted __le32 [usertype] length
drivers/usb/cdns3/gadget.c:1188:29: sparse: got unsigned long
drivers/usb/cdns3/gadget.c:1191:37: sparse: sparse: invalid assignment: |=
drivers/usb/cdns3/gadget.c:1191:37: sparse: left side has type restricted __le32
drivers/usb/cdns3/gadget.c:1191:37: sparse: right side has type unsigned long
drivers/usb/cdns3/gadget.c:1213:38: sparse: sparse: incorrect type in assignment (different base types) @@ expected restricted __le32 [usertype] control @@ got unsigned int [assigned] [usertype] control @@
drivers/usb/cdns3/gadget.c:1213:38: sparse: expected restricted __le32 [usertype] control
drivers/usb/cdns3/gadget.c:1213:38: sparse: got unsigned int [assigned] [usertype] control
drivers/usb/cdns3/gadget.c:1215:48: sparse: sparse: incorrect type in assignment (different base types) @@ expected restricted __le32 [usertype] control @@ got unsigned int [assigned] [usertype] control @@
drivers/usb/cdns3/gadget.c:1215:48: sparse: expected restricted __le32 [usertype] control
drivers/usb/cdns3/gadget.c:1215:48: sparse: got unsigned int [assigned] [usertype] control
drivers/usb/cdns3/gadget.c:1229:30: sparse: sparse: invalid assignment: |=
drivers/usb/cdns3/gadget.c:1229:30: sparse: left side has type restricted __le32
drivers/usb/cdns3/gadget.c:1229:30: sparse: right side has type unsigned long
drivers/usb/cdns3/gadget.c:1255:36: sparse: sparse: restricted __le32 degrades to integer
drivers/usb/cdns3/gadget.c:1255:30: sparse: sparse: incorrect type in assignment (different base types) @@ expected restricted __le32 [usertype] control @@ got unsigned int @@
drivers/usb/cdns3/gadget.c:1255:30: sparse: expected restricted __le32 [usertype] control
drivers/usb/cdns3/gadget.c:1255:30: sparse: got unsigned int
drivers/usb/cdns3/gadget.c:1010:29: sparse: sparse: incorrect type in assignment (different base types) @@ expected restricted __le32 [usertype] buffer @@ got unsigned long @@
drivers/usb/cdns3/gadget.c:1010:29: sparse: expected restricted __le32 [usertype] buffer
drivers/usb/cdns3/gadget.c:1010:29: sparse: got unsigned long
drivers/usb/cdns3/gadget.c:1013:29: sparse: sparse: incorrect type in assignment (different base types) @@ expected restricted __le32 [usertype] buffer @@ got unsigned long @@
drivers/usb/cdns3/gadget.c:1013:29: sparse: expected restricted __le32 [usertype] buffer
drivers/usb/cdns3/gadget.c:1013:29: sparse: got unsigned long
drivers/usb/cdns3/gadget.c:1019:21: sparse: sparse: incorrect type in assignment (different base types) @@ expected restricted __le32 [usertype] length @@ got unsigned long @@
drivers/usb/cdns3/gadget.c:1019:21: sparse: expected restricted __le32 [usertype] length
drivers/usb/cdns3/gadget.c:1019:21: sparse: got unsigned long
drivers/usb/cdns3/gadget.c:1029:37: sparse: sparse: invalid assignment: |=
drivers/usb/cdns3/gadget.c:1029:37: sparse: left side has type restricted __le32
drivers/usb/cdns3/gadget.c:1029:37: sparse: right side has type unsigned long
drivers/usb/cdns3/gadget.c:1033:22: sparse: sparse: incorrect type in assignment (different base types) @@ expected restricted __le32 [usertype] control @@ got unsigned int [assigned] [usertype] control @@
drivers/usb/cdns3/gadget.c:1033:22: sparse: expected restricted __le32 [usertype] control
drivers/usb/cdns3/gadget.c:1033:22: sparse: got unsigned int [assigned] [usertype] control
drivers/usb/cdns3/gadget.c:85:6: sparse: sparse: symbol 'cdns3_clear_register_bit' was not declared. Should it be static?
drivers/usb/cdns3/gadget.c:140:26: sparse: sparse: symbol 'cdns3_next_align_buf' was not declared. Should it be static?
drivers/usb/cdns3/gadget.c:151:22: sparse: sparse: symbol 'cdns3_next_priv_request' was not declared. Should it be static?
drivers/usb/cdns3/gadget.c:193:5: sparse: sparse: symbol 'cdns3_ring_size' was not declared. Should it be static?
drivers/usb/cdns3/gadget.c:263:34: sparse: sparse: incorrect type in assignment (different base types) @@ expected restricted __le32 [usertype] buffer @@ got unsigned long @@
drivers/usb/cdns3/gadget.c:263:34: sparse: expected restricted __le32 [usertype] buffer
drivers/usb/cdns3/gadget.c:263:34: sparse: got unsigned long
drivers/usb/cdns3/gadget.c:264:35: sparse: sparse: incorrect type in assignment (different base types) @@ expected restricted __le32 [usertype] control @@ got unsigned long @@
drivers/usb/cdns3/gadget.c:264:35: sparse: expected restricted __le32 [usertype] control
drivers/usb/cdns3/gadget.c:264:35: sparse: got unsigned long
drivers/usb/cdns3/gadget.c:348:6: sparse: sparse: symbol 'cdns3_move_deq_to_next_trb' was not declared. Should it be static?
drivers/usb/cdns3/gadget.c:514:20: sparse: sparse: symbol 'cdns3_wa2_gadget_giveback' was not declared. Should it be static?
drivers/usb/cdns3/gadget.c:554:5: sparse: sparse: symbol 'cdns3_wa2_gadget_ep_queue' was not declared. Should it be static?
drivers/usb/cdns3/gadget.c:849:49: sparse: sparse: restricted __le32 degrades to integer
drivers/usb/cdns3/gadget.c:848:51: sparse: sparse: incorrect type in assignment (different base types) @@ expected restricted __le32 [usertype] control @@ got unsigned int @@
drivers/usb/cdns3/gadget.c:848:51: sparse: expected restricted __le32 [usertype] control
drivers/usb/cdns3/gadget.c:848:51: sparse: got unsigned int
drivers/usb/cdns3/gadget.c:852:49: sparse: sparse: restricted __le32 degrades to integer
drivers/usb/cdns3/gadget.c:851:51: sparse: sparse: incorrect type in assignment (different base types) @@ expected restricted __le32 [usertype] control @@ got unsigned int @@
drivers/usb/cdns3/gadget.c:851:51: sparse: expected restricted __le32 [usertype] control
drivers/usb/cdns3/gadget.c:851:51: sparse: got unsigned int
drivers/usb/cdns3/gadget.c:839:6: sparse: sparse: symbol 'cdns3_wa1_restore_cycle_bit' was not declared. Should it be static?
drivers/usb/cdns3/gadget.c:1393:17: sparse: sparse: restricted __le32 degrades to integer
drivers/usb/cdns3/gadget.c:1442:21: sparse: sparse: restricted __le32 degrades to integer
drivers/usb/cdns3/gadget.c:1574:35: sparse: sparse: dubious: x | !y
drivers/usb/cdns3/gadget.c:1907:6: sparse: sparse: symbol 'cdns3_stream_ep_reconfig' was not declared. Should it be static?
drivers/usb/cdns3/gadget.c:1928:6: sparse: sparse: symbol 'cdns3_configure_dmult' was not declared. Should it be static?
drivers/usb/cdns3/gadget.c:2552:34: sparse: sparse: incorrect type in assignment (different base types) @@ expected restricted __le32 [usertype] buffer @@ got unsigned long @@
drivers/usb/cdns3/gadget.c:2552:34: sparse: expected restricted __le32 [usertype] buffer
drivers/usb/cdns3/gadget.c:2552:34: sparse: got unsigned long
drivers/usb/cdns3/gadget.c:2554:46: sparse: sparse: restricted __le32 degrades to integer
drivers/usb/cdns3/gadget.c:2554:35: sparse: sparse: incorrect type in assignment (different base types) @@ expected restricted __le32 [usertype] control @@ got unsigned long @@
drivers/usb/cdns3/gadget.c:2554:35: sparse: expected restricted __le32 [usertype] control
drivers/usb/cdns3/gadget.c:2554:35: sparse: got unsigned long
drivers/usb/cdns3/gadget.c:2610:43: sparse: sparse: restricted __le32 degrades to integer
drivers/usb/cdns3/gadget.c:2610:38: sparse: sparse: incorrect type in assignment (different base types) @@ expected restricted __le32 [usertype] control @@ got unsigned long @@
drivers/usb/cdns3/gadget.c:2610:38: sparse: expected restricted __le32 [usertype] control
drivers/usb/cdns3/gadget.c:2610:38: sparse: got unsigned long
drivers/usb/cdns3/gadget.c:2625:43: sparse: sparse: restricted __le32 degrades to integer
drivers/usb/cdns3/gadget.c:2625:38: sparse: sparse: incorrect type in assignment (different base types) @@ expected restricted __le32 [usertype] control @@ got unsigned long @@
drivers/usb/cdns3/gadget.c:2625:38: sparse: expected restricted __le32 [usertype] control
drivers/usb/cdns3/gadget.c:2625:38: sparse: got unsigned long
--
drivers/usb/cdns3/ep0.c:40:37: sparse: sparse: incorrect type in assignment (different base types) @@ expected restricted __le32 [usertype] buffer @@ got unsigned long @@
drivers/usb/cdns3/ep0.c:40:37: sparse: expected restricted __le32 [usertype] buffer
drivers/usb/cdns3/ep0.c:40:37: sparse: got unsigned long
drivers/usb/cdns3/ep0.c:41:37: sparse: sparse: incorrect type in assignment (different base types) @@ expected restricted __le32 [usertype] length @@ got unsigned long @@
drivers/usb/cdns3/ep0.c:41:37: sparse: expected restricted __le32 [usertype] length
drivers/usb/cdns3/ep0.c:41:37: sparse: got unsigned long
drivers/usb/cdns3/ep0.c:44:46: sparse: sparse: incorrect type in assignment (different base types) @@ expected restricted __le32 [usertype] control @@ got unsigned long @@
drivers/usb/cdns3/ep0.c:44:46: sparse: expected restricted __le32 [usertype] control
drivers/usb/cdns3/ep0.c:44:46: sparse: got unsigned long
drivers/usb/cdns3/ep0.c:45:45: sparse: sparse: incorrect type in assignment (different base types) @@ expected restricted __le32 [usertype] buffer @@ got unsigned long @@
drivers/usb/cdns3/ep0.c:45:45: sparse: expected restricted __le32 [usertype] buffer
drivers/usb/cdns3/ep0.c:45:45: sparse: got unsigned long
drivers/usb/cdns3/ep0.c:46:45: sparse: sparse: incorrect type in assignment (different base types) @@ expected restricted __le32 [usertype] length @@ got unsigned long @@
drivers/usb/cdns3/ep0.c:46:45: sparse: expected restricted __le32 [usertype] length
drivers/usb/cdns3/ep0.c:46:45: sparse: got unsigned long
drivers/usb/cdns3/ep0.c:47:46: sparse: sparse: incorrect type in assignment (different base types) @@ expected restricted __le32 [usertype] control @@ got unsigned long @@
drivers/usb/cdns3/ep0.c:47:46: sparse: expected restricted __le32 [usertype] control
drivers/usb/cdns3/ep0.c:47:46: sparse: got unsigned long
drivers/usb/cdns3/ep0.c:50:46: sparse: sparse: incorrect type in assignment (different base types) @@ expected restricted __le32 [usertype] control @@ got unsigned long @@
drivers/usb/cdns3/ep0.c:50:46: sparse: expected restricted __le32 [usertype] control
drivers/usb/cdns3/ep0.c:50:46: sparse: got unsigned long
drivers/usb/cdns3/ep0.c:267:52: sparse: sparse: incorrect type in argument 1 (different base types) @@ expected unsigned char [usertype] ep_addr @@ got restricted __le16 [usertype] wIndex @@
drivers/usb/cdns3/ep0.c:267:52: sparse: expected unsigned char [usertype] ep_addr
drivers/usb/cdns3/ep0.c:267:52: sparse: got restricted __le16 [usertype] wIndex
>> drivers/usb/cdns3/ep0.c:271:47: sparse: sparse: incorrect type in argument 2 (different base types) @@ expected unsigned int [usertype] ep @@ got restricted __le16 [usertype] wIndex @@
drivers/usb/cdns3/ep0.c:271:47: sparse: expected unsigned int [usertype] ep
drivers/usb/cdns3/ep0.c:271:47: sparse: got restricted __le16 [usertype] wIndex
drivers/usb/cdns3/ep0.c:387:19: sparse: sparse: restricted __le16 degrades to integer
drivers/usb/cdns3/ep0.c:390:44: sparse: sparse: incorrect type in argument 1 (different base types) @@ expected unsigned char [usertype] ep_addr @@ got restricted __le16 [usertype] wIndex @@
drivers/usb/cdns3/ep0.c:390:44: sparse: expected unsigned char [usertype] ep_addr
drivers/usb/cdns3/ep0.c:390:44: sparse: got restricted __le16 [usertype] wIndex
drivers/usb/cdns3/ep0.c:393:39: sparse: sparse: incorrect type in argument 2 (different base types) @@ expected unsigned int [usertype] ep @@ got restricted __le16 [usertype] wIndex @@
drivers/usb/cdns3/ep0.c:393:39: sparse: expected unsigned int [usertype] ep
drivers/usb/cdns3/ep0.c:393:39: sparse: got restricted __le16 [usertype] wIndex
drivers/usb/cdns3/ep0.c:454:21: sparse: sparse: restricted __le16 degrades to integer
drivers/usb/cdns3/ep0.c:478:31: sparse: sparse: incorrect type in assignment (different base types) @@ expected unsigned short [usertype] isoch_delay @@ got restricted __le16 [usertype] wValue @@
drivers/usb/cdns3/ep0.c:478:31: sparse: expected unsigned short [usertype] isoch_delay
drivers/usb/cdns3/ep0.c:478:31: sparse: got restricted __le16 [usertype] wValue

vim +1188 drivers/usb/cdns3/gadget.c

54c4c69f0baa43 Jayshri Pawar 2019-12-13 1079
7733f6c32e36ff Pawel Laszczak 2019-08-26 1080 /**
7733f6c32e36ff Pawel Laszczak 2019-08-26 1081 * cdns3_ep_run_transfer - start transfer on no-default endpoint hardware
7733f6c32e36ff Pawel Laszczak 2019-08-26 1082 * @priv_ep: endpoint object
7733f6c32e36ff Pawel Laszczak 2019-08-26 1083 *
7733f6c32e36ff Pawel Laszczak 2019-08-26 1084 * Returns zero on success or negative value on failure
7733f6c32e36ff Pawel Laszczak 2019-08-26 1085 */
54c4c69f0baa43 Jayshri Pawar 2019-12-13 1086 static int cdns3_ep_run_transfer(struct cdns3_endpoint *priv_ep,
7733f6c32e36ff Pawel Laszczak 2019-08-26 1087 struct usb_request *request)
7733f6c32e36ff Pawel Laszczak 2019-08-26 1088 {
7733f6c32e36ff Pawel Laszczak 2019-08-26 1089 struct cdns3_device *priv_dev = priv_ep->cdns3_dev;
7733f6c32e36ff Pawel Laszczak 2019-08-26 1090 struct cdns3_request *priv_req;
7733f6c32e36ff Pawel Laszczak 2019-08-26 1091 struct cdns3_trb *trb;
7733f6c32e36ff Pawel Laszczak 2019-08-26 1092 dma_addr_t trb_dma;
7733f6c32e36ff Pawel Laszczak 2019-08-26 1093 u32 togle_pcs = 1;
7733f6c32e36ff Pawel Laszczak 2019-08-26 1094 int sg_iter = 0;
7733f6c32e36ff Pawel Laszczak 2019-08-26 1095 int num_trb;
7733f6c32e36ff Pawel Laszczak 2019-08-26 1096 int address;
7733f6c32e36ff Pawel Laszczak 2019-08-26 1097 u32 control;
7733f6c32e36ff Pawel Laszczak 2019-08-26 1098 int pcs;
54c4c69f0baa43 Jayshri Pawar 2019-12-13 1099 u16 total_tdl = 0;
7733f6c32e36ff Pawel Laszczak 2019-08-26 1100
7733f6c32e36ff Pawel Laszczak 2019-08-26 1101 if (priv_ep->type == USB_ENDPOINT_XFER_ISOC)
7733f6c32e36ff Pawel Laszczak 2019-08-26 1102 num_trb = priv_ep->interval;
7733f6c32e36ff Pawel Laszczak 2019-08-26 1103 else
7733f6c32e36ff Pawel Laszczak 2019-08-26 1104 num_trb = request->num_sgs ? request->num_sgs : 1;
7733f6c32e36ff Pawel Laszczak 2019-08-26 1105
7733f6c32e36ff Pawel Laszczak 2019-08-26 1106 if (num_trb > priv_ep->free_trbs) {
7733f6c32e36ff Pawel Laszczak 2019-08-26 1107 priv_ep->flags |= EP_RING_FULL;
7733f6c32e36ff Pawel Laszczak 2019-08-26 1108 return -ENOBUFS;
7733f6c32e36ff Pawel Laszczak 2019-08-26 1109 }
7733f6c32e36ff Pawel Laszczak 2019-08-26 1110
7733f6c32e36ff Pawel Laszczak 2019-08-26 1111 priv_req = to_cdns3_request(request);
7733f6c32e36ff Pawel Laszczak 2019-08-26 1112 address = priv_ep->endpoint.desc->bEndpointAddress;
7733f6c32e36ff Pawel Laszczak 2019-08-26 1113
7733f6c32e36ff Pawel Laszczak 2019-08-26 1114 priv_ep->flags |= EP_PENDING_REQUEST;
7733f6c32e36ff Pawel Laszczak 2019-08-26 1115
7733f6c32e36ff Pawel Laszczak 2019-08-26 1116 /* must allocate buffer aligned to 8 */
7733f6c32e36ff Pawel Laszczak 2019-08-26 1117 if (priv_req->flags & REQUEST_UNALIGNED)
7733f6c32e36ff Pawel Laszczak 2019-08-26 1118 trb_dma = priv_req->aligned_buf->dma;
7733f6c32e36ff Pawel Laszczak 2019-08-26 1119 else
7733f6c32e36ff Pawel Laszczak 2019-08-26 1120 trb_dma = request->dma;
7733f6c32e36ff Pawel Laszczak 2019-08-26 1121
7733f6c32e36ff Pawel Laszczak 2019-08-26 1122 trb = priv_ep->trb_pool + priv_ep->enqueue;
7733f6c32e36ff Pawel Laszczak 2019-08-26 1123 priv_req->start_trb = priv_ep->enqueue;
7733f6c32e36ff Pawel Laszczak 2019-08-26 1124 priv_req->trb = trb;
7733f6c32e36ff Pawel Laszczak 2019-08-26 1125
7733f6c32e36ff Pawel Laszczak 2019-08-26 1126 cdns3_select_ep(priv_ep->cdns3_dev, address);
7733f6c32e36ff Pawel Laszczak 2019-08-26 1127
7733f6c32e36ff Pawel Laszczak 2019-08-26 1128 /* prepare ring */
7733f6c32e36ff Pawel Laszczak 2019-08-26 1129 if ((priv_ep->enqueue + num_trb) >= (priv_ep->num_trbs - 1)) {
7733f6c32e36ff Pawel Laszczak 2019-08-26 1130 struct cdns3_trb *link_trb;
7733f6c32e36ff Pawel Laszczak 2019-08-26 1131 int doorbell, dma_index;
7733f6c32e36ff Pawel Laszczak 2019-08-26 1132 u32 ch_bit = 0;
7733f6c32e36ff Pawel Laszczak 2019-08-26 1133
7733f6c32e36ff Pawel Laszczak 2019-08-26 1134 doorbell = !!(readl(&priv_dev->regs->ep_cmd) & EP_CMD_DRDY);
7733f6c32e36ff Pawel Laszczak 2019-08-26 1135 dma_index = cdns3_get_dma_pos(priv_dev, priv_ep);
7733f6c32e36ff Pawel Laszczak 2019-08-26 1136
7733f6c32e36ff Pawel Laszczak 2019-08-26 1137 /* Driver can't update LINK TRB if it is current processed. */
7733f6c32e36ff Pawel Laszczak 2019-08-26 1138 if (doorbell && dma_index == priv_ep->num_trbs - 1) {
7733f6c32e36ff Pawel Laszczak 2019-08-26 1139 priv_ep->flags |= EP_DEFERRED_DRDY;
7733f6c32e36ff Pawel Laszczak 2019-08-26 1140 return -ENOBUFS;
7733f6c32e36ff Pawel Laszczak 2019-08-26 1141 }
7733f6c32e36ff Pawel Laszczak 2019-08-26 1142
7733f6c32e36ff Pawel Laszczak 2019-08-26 1143 /*updating C bt in Link TRB before starting DMA*/
7733f6c32e36ff Pawel Laszczak 2019-08-26 1144 link_trb = priv_ep->trb_pool + (priv_ep->num_trbs - 1);
7733f6c32e36ff Pawel Laszczak 2019-08-26 1145 /*
7733f6c32e36ff Pawel Laszczak 2019-08-26 1146 * For TRs size equal 2 enabling TRB_CHAIN for epXin causes
7733f6c32e36ff Pawel Laszczak 2019-08-26 1147 * that DMA stuck at the LINK TRB.
7733f6c32e36ff Pawel Laszczak 2019-08-26 1148 * On the other hand, removing TRB_CHAIN for longer TRs for
7733f6c32e36ff Pawel Laszczak 2019-08-26 1149 * epXout cause that DMA stuck after handling LINK TRB.
7733f6c32e36ff Pawel Laszczak 2019-08-26 1150 * To eliminate this strange behavioral driver set TRB_CHAIN
7733f6c32e36ff Pawel Laszczak 2019-08-26 1151 * bit only for TR size > 2.
7733f6c32e36ff Pawel Laszczak 2019-08-26 1152 */
7733f6c32e36ff Pawel Laszczak 2019-08-26 1153 if (priv_ep->type == USB_ENDPOINT_XFER_ISOC ||
7733f6c32e36ff Pawel Laszczak 2019-08-26 1154 TRBS_PER_SEGMENT > 2)
7733f6c32e36ff Pawel Laszczak 2019-08-26 1155 ch_bit = TRB_CHAIN;
7733f6c32e36ff Pawel Laszczak 2019-08-26 1156
7733f6c32e36ff Pawel Laszczak 2019-08-26 1157 link_trb->control = ((priv_ep->pcs) ? TRB_CYCLE : 0) |
7733f6c32e36ff Pawel Laszczak 2019-08-26 1158 TRB_TYPE(TRB_LINK) | TRB_TOGGLE | ch_bit;
7733f6c32e36ff Pawel Laszczak 2019-08-26 1159 }
7733f6c32e36ff Pawel Laszczak 2019-08-26 1160
7733f6c32e36ff Pawel Laszczak 2019-08-26 1161 if (priv_dev->dev_ver <= DEV_VER_V2)
7733f6c32e36ff Pawel Laszczak 2019-08-26 1162 togle_pcs = cdns3_wa1_update_guard(priv_ep, trb);
7733f6c32e36ff Pawel Laszczak 2019-08-26 1163
7733f6c32e36ff Pawel Laszczak 2019-08-26 1164 /* set incorrect Cycle Bit for first trb*/
7733f6c32e36ff Pawel Laszczak 2019-08-26 1165 control = priv_ep->pcs ? 0 : TRB_CYCLE;
7733f6c32e36ff Pawel Laszczak 2019-08-26 1166
7733f6c32e36ff Pawel Laszczak 2019-08-26 1167 do {
7733f6c32e36ff Pawel Laszczak 2019-08-26 1168 u32 length;
7733f6c32e36ff Pawel Laszczak 2019-08-26 1169 u16 td_size = 0;
7733f6c32e36ff Pawel Laszczak 2019-08-26 1170
7733f6c32e36ff Pawel Laszczak 2019-08-26 1171 /* fill TRB */
7733f6c32e36ff Pawel Laszczak 2019-08-26 1172 control |= TRB_TYPE(TRB_NORMAL);
7733f6c32e36ff Pawel Laszczak 2019-08-26 1173 trb->buffer = TRB_BUFFER(request->num_sgs == 0
7733f6c32e36ff Pawel Laszczak 2019-08-26 1174 ? trb_dma : request->sg[sg_iter].dma_address);
7733f6c32e36ff Pawel Laszczak 2019-08-26 1175
7733f6c32e36ff Pawel Laszczak 2019-08-26 1176 if (likely(!request->num_sgs))
7733f6c32e36ff Pawel Laszczak 2019-08-26 1177 length = request->length;
7733f6c32e36ff Pawel Laszczak 2019-08-26 1178 else
7733f6c32e36ff Pawel Laszczak 2019-08-26 1179 length = request->sg[sg_iter].length;
7733f6c32e36ff Pawel Laszczak 2019-08-26 1180
7733f6c32e36ff Pawel Laszczak 2019-08-26 1181 if (likely(priv_dev->dev_ver >= DEV_VER_V2))
7733f6c32e36ff Pawel Laszczak 2019-08-26 1182 td_size = DIV_ROUND_UP(length,
7733f6c32e36ff Pawel Laszczak 2019-08-26 1183 priv_ep->endpoint.maxpacket);
54c4c69f0baa43 Jayshri Pawar 2019-12-13 1184 else if (priv_ep->flags & EP_TDLCHK_EN)
54c4c69f0baa43 Jayshri Pawar 2019-12-13 1185 total_tdl += DIV_ROUND_UP(length,
54c4c69f0baa43 Jayshri Pawar 2019-12-13 1186 priv_ep->endpoint.maxpacket);
7733f6c32e36ff Pawel Laszczak 2019-08-26 1187
7733f6c32e36ff Pawel Laszczak 2019-08-26 @1188 trb->length = TRB_BURST_LEN(priv_ep->trb_burst_size) |
7733f6c32e36ff Pawel Laszczak 2019-08-26 1189 TRB_LEN(length);
7733f6c32e36ff Pawel Laszczak 2019-08-26 1190 if (priv_dev->gadget.speed == USB_SPEED_SUPER)
7733f6c32e36ff Pawel Laszczak 2019-08-26 1191 trb->length |= TRB_TDL_SS_SIZE(td_size);
7733f6c32e36ff Pawel Laszczak 2019-08-26 1192 else
7733f6c32e36ff Pawel Laszczak 2019-08-26 1193 control |= TRB_TDL_HS_SIZE(td_size);
7733f6c32e36ff Pawel Laszczak 2019-08-26 1194
7733f6c32e36ff Pawel Laszczak 2019-08-26 1195 pcs = priv_ep->pcs ? TRB_CYCLE : 0;
7733f6c32e36ff Pawel Laszczak 2019-08-26 1196
7733f6c32e36ff Pawel Laszczak 2019-08-26 1197 /*
7733f6c32e36ff Pawel Laszczak 2019-08-26 1198 * first trb should be prepared as last to avoid processing
7733f6c32e36ff Pawel Laszczak 2019-08-26 1199 * transfer to early
7733f6c32e36ff Pawel Laszczak 2019-08-26 1200 */
7733f6c32e36ff Pawel Laszczak 2019-08-26 1201 if (sg_iter != 0)
7733f6c32e36ff Pawel Laszczak 2019-08-26 1202 control |= pcs;
7733f6c32e36ff Pawel Laszczak 2019-08-26 1203
7733f6c32e36ff Pawel Laszczak 2019-08-26 1204 if (priv_ep->type == USB_ENDPOINT_XFER_ISOC && !priv_ep->dir) {
7733f6c32e36ff Pawel Laszczak 2019-08-26 1205 control |= TRB_IOC | TRB_ISP;
7733f6c32e36ff Pawel Laszczak 2019-08-26 1206 } else {
7733f6c32e36ff Pawel Laszczak 2019-08-26 1207 /* for last element in TD or in SG list */
7733f6c32e36ff Pawel Laszczak 2019-08-26 1208 if (sg_iter == (num_trb - 1) && sg_iter != 0)
7733f6c32e36ff Pawel Laszczak 2019-08-26 1209 control |= pcs | TRB_IOC | TRB_ISP;
7733f6c32e36ff Pawel Laszczak 2019-08-26 1210 }
7733f6c32e36ff Pawel Laszczak 2019-08-26 1211
7733f6c32e36ff Pawel Laszczak 2019-08-26 1212 if (sg_iter)
7733f6c32e36ff Pawel Laszczak 2019-08-26 1213 trb->control = control;
7733f6c32e36ff Pawel Laszczak 2019-08-26 1214 else
7733f6c32e36ff Pawel Laszczak 2019-08-26 1215 priv_req->trb->control = control;
7733f6c32e36ff Pawel Laszczak 2019-08-26 1216
7733f6c32e36ff Pawel Laszczak 2019-08-26 1217 control = 0;
7733f6c32e36ff Pawel Laszczak 2019-08-26 1218 ++sg_iter;
7733f6c32e36ff Pawel Laszczak 2019-08-26 1219 priv_req->end_trb = priv_ep->enqueue;
7733f6c32e36ff Pawel Laszczak 2019-08-26 1220 cdns3_ep_inc_enq(priv_ep);
7733f6c32e36ff Pawel Laszczak 2019-08-26 1221 trb = priv_ep->trb_pool + priv_ep->enqueue;
7733f6c32e36ff Pawel Laszczak 2019-08-26 1222 } while (sg_iter < num_trb);
7733f6c32e36ff Pawel Laszczak 2019-08-26 1223
7733f6c32e36ff Pawel Laszczak 2019-08-26 1224 trb = priv_req->trb;
7733f6c32e36ff Pawel Laszczak 2019-08-26 1225
7733f6c32e36ff Pawel Laszczak 2019-08-26 1226 priv_req->flags |= REQUEST_PENDING;
7733f6c32e36ff Pawel Laszczak 2019-08-26 1227
7733f6c32e36ff Pawel Laszczak 2019-08-26 1228 if (sg_iter == 1)
7733f6c32e36ff Pawel Laszczak 2019-08-26 1229 trb->control |= TRB_IOC | TRB_ISP;
7733f6c32e36ff Pawel Laszczak 2019-08-26 1230
54c4c69f0baa43 Jayshri Pawar 2019-12-13 1231 if (priv_dev->dev_ver < DEV_VER_V2 &&
54c4c69f0baa43 Jayshri Pawar 2019-12-13 1232 (priv_ep->flags & EP_TDLCHK_EN)) {
54c4c69f0baa43 Jayshri Pawar 2019-12-13 1233 u16 tdl = total_tdl;
54c4c69f0baa43 Jayshri Pawar 2019-12-13 1234 u16 old_tdl = EP_CMD_TDL_GET(readl(&priv_dev->regs->ep_cmd));
54c4c69f0baa43 Jayshri Pawar 2019-12-13 1235
54c4c69f0baa43 Jayshri Pawar 2019-12-13 1236 if (tdl > EP_CMD_TDL_MAX) {
54c4c69f0baa43 Jayshri Pawar 2019-12-13 1237 tdl = EP_CMD_TDL_MAX;
54c4c69f0baa43 Jayshri Pawar 2019-12-13 1238 priv_ep->pending_tdl = total_tdl - EP_CMD_TDL_MAX;
54c4c69f0baa43 Jayshri Pawar 2019-12-13 1239 }
54c4c69f0baa43 Jayshri Pawar 2019-12-13 1240
54c4c69f0baa43 Jayshri Pawar 2019-12-13 1241 if (old_tdl < tdl) {
54c4c69f0baa43 Jayshri Pawar 2019-12-13 1242 tdl -= old_tdl;
54c4c69f0baa43 Jayshri Pawar 2019-12-13 1243 writel(EP_CMD_TDL_SET(tdl) | EP_CMD_STDL,
54c4c69f0baa43 Jayshri Pawar 2019-12-13 1244 &priv_dev->regs->ep_cmd);
54c4c69f0baa43 Jayshri Pawar 2019-12-13 1245 }
54c4c69f0baa43 Jayshri Pawar 2019-12-13 1246 }
54c4c69f0baa43 Jayshri Pawar 2019-12-13 1247
7733f6c32e36ff Pawel Laszczak 2019-08-26 1248 /*
7733f6c32e36ff Pawel Laszczak 2019-08-26 1249 * Memory barrier - cycle bit must be set before other filds in trb.
7733f6c32e36ff Pawel Laszczak 2019-08-26 1250 */
7733f6c32e36ff Pawel Laszczak 2019-08-26 1251 wmb();
7733f6c32e36ff Pawel Laszczak 2019-08-26 1252
7733f6c32e36ff Pawel Laszczak 2019-08-26 1253 /* give the TD to the consumer*/
7733f6c32e36ff Pawel Laszczak 2019-08-26 1254 if (togle_pcs)
7733f6c32e36ff Pawel Laszczak 2019-08-26 1255 trb->control = trb->control ^ 1;
7733f6c32e36ff Pawel Laszczak 2019-08-26 1256
7733f6c32e36ff Pawel Laszczak 2019-08-26 1257 if (priv_dev->dev_ver <= DEV_VER_V2)
7733f6c32e36ff Pawel Laszczak 2019-08-26 1258 cdns3_wa1_tray_restore_cycle_bit(priv_dev, priv_ep);
7733f6c32e36ff Pawel Laszczak 2019-08-26 1259
7733f6c32e36ff Pawel Laszczak 2019-08-26 1260 trace_cdns3_prepare_trb(priv_ep, priv_req->trb);
7733f6c32e36ff Pawel Laszczak 2019-08-26 1261
7733f6c32e36ff Pawel Laszczak 2019-08-26 1262 /*
7733f6c32e36ff Pawel Laszczak 2019-08-26 1263 * Memory barrier - Cycle Bit must be set before trb->length and
7733f6c32e36ff Pawel Laszczak 2019-08-26 1264 * trb->buffer fields.
7733f6c32e36ff Pawel Laszczak 2019-08-26 1265 */
7733f6c32e36ff Pawel Laszczak 2019-08-26 1266 wmb();
7733f6c32e36ff Pawel Laszczak 2019-08-26 1267
7733f6c32e36ff Pawel Laszczak 2019-08-26 1268 /*
7733f6c32e36ff Pawel Laszczak 2019-08-26 1269 * For DMULT mode we can set address to transfer ring only once after
7733f6c32e36ff Pawel Laszczak 2019-08-26 1270 * enabling endpoint.
7733f6c32e36ff Pawel Laszczak 2019-08-26 1271 */
7733f6c32e36ff Pawel Laszczak 2019-08-26 1272 if (priv_ep->flags & EP_UPDATE_EP_TRBADDR) {
7733f6c32e36ff Pawel Laszczak 2019-08-26 1273 /*
7733f6c32e36ff Pawel Laszczak 2019-08-26 1274 * Until SW is not ready to handle the OUT transfer the ISO OUT
7733f6c32e36ff Pawel Laszczak 2019-08-26 1275 * Endpoint should be disabled (EP_CFG.ENABLE = 0).
7733f6c32e36ff Pawel Laszczak 2019-08-26 1276 * EP_CFG_ENABLE must be set before updating ep_traddr.
7733f6c32e36ff Pawel Laszczak 2019-08-26 1277 */
7733f6c32e36ff Pawel Laszczak 2019-08-26 1278 if (priv_ep->type == USB_ENDPOINT_XFER_ISOC && !priv_ep->dir &&
7733f6c32e36ff Pawel Laszczak 2019-08-26 1279 !(priv_ep->flags & EP_QUIRK_ISO_OUT_EN)) {
7733f6c32e36ff Pawel Laszczak 2019-08-26 1280 priv_ep->flags |= EP_QUIRK_ISO_OUT_EN;
7733f6c32e36ff Pawel Laszczak 2019-08-26 1281 cdns3_set_register_bit(&priv_dev->regs->ep_cfg,
7733f6c32e36ff Pawel Laszczak 2019-08-26 1282 EP_CFG_ENABLE);
7733f6c32e36ff Pawel Laszczak 2019-08-26 1283 }
7733f6c32e36ff Pawel Laszczak 2019-08-26 1284
7733f6c32e36ff Pawel Laszczak 2019-08-26 1285 writel(EP_TRADDR_TRADDR(priv_ep->trb_pool_dma +
7733f6c32e36ff Pawel Laszczak 2019-08-26 1286 priv_req->start_trb * TRB_SIZE),
7733f6c32e36ff Pawel Laszczak 2019-08-26 1287 &priv_dev->regs->ep_traddr);
7733f6c32e36ff Pawel Laszczak 2019-08-26 1288
7733f6c32e36ff Pawel Laszczak 2019-08-26 1289 priv_ep->flags &= ~EP_UPDATE_EP_TRBADDR;
7733f6c32e36ff Pawel Laszczak 2019-08-26 1290 }
7733f6c32e36ff Pawel Laszczak 2019-08-26 1291
7733f6c32e36ff Pawel Laszczak 2019-08-26 1292 if (!priv_ep->wa1_set && !(priv_ep->flags & EP_STALLED)) {
7733f6c32e36ff Pawel Laszczak 2019-08-26 1293 trace_cdns3_ring(priv_ep);
7733f6c32e36ff Pawel Laszczak 2019-08-26 1294 /*clearing TRBERR and EP_STS_DESCMIS before seting DRDY*/
7733f6c32e36ff Pawel Laszczak 2019-08-26 1295 writel(EP_STS_TRBERR | EP_STS_DESCMIS, &priv_dev->regs->ep_sts);
7733f6c32e36ff Pawel Laszczak 2019-08-26 1296 writel(EP_CMD_DRDY, &priv_dev->regs->ep_cmd);
7733f6c32e36ff Pawel Laszczak 2019-08-26 1297 trace_cdns3_doorbell_epx(priv_ep->name,
7733f6c32e36ff Pawel Laszczak 2019-08-26 1298 readl(&priv_dev->regs->ep_traddr));
7733f6c32e36ff Pawel Laszczak 2019-08-26 1299 }
7733f6c32e36ff Pawel Laszczak 2019-08-26 1300
7733f6c32e36ff Pawel Laszczak 2019-08-26 1301 /* WORKAROUND for transition to L0 */
7733f6c32e36ff Pawel Laszczak 2019-08-26 1302 __cdns3_gadget_wakeup(priv_dev);
7733f6c32e36ff Pawel Laszczak 2019-08-26 1303
7733f6c32e36ff Pawel Laszczak 2019-08-26 1304 return 0;
7733f6c32e36ff Pawel Laszczak 2019-08-26 1305 }
7733f6c32e36ff Pawel Laszczak 2019-08-26 1306

:::::: The code at line 1188 was first introduced by commit
:::::: 7733f6c32e36ff9d7adadf40001039bf219b1cbe usb: cdns3: Add Cadence USB3 DRD Driver

:::::: TO: Pawel Laszczak <pawell@xxxxxxxxxxx>
:::::: CC: Felipe Balbi <felipe.balbi@xxxxxxxxxxxxxxx>

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all@xxxxxxxxxxxx

Attachment: .config.gz
Description: application/gzip