Lines Matching refs:port
52 static int32_t UsbEcmStartTx(struct UsbEcm *port) in UsbEcmStartTx() argument
54 struct DListHead *pool = &port->writePool; in UsbEcmStartTx()
55 if (port->ecm == NULL) { in UsbEcmStartTx()
59 while (!port->writeBusy && !DListIsEmpty(pool)) { in UsbEcmStartTx()
62 if (port->writeStarted >= QUEUE_SIZE) { in UsbEcmStartTx()
66 OsalMutexLock(&port->lockWriteFifo); in UsbEcmStartTx()
67 len = DataFifoRead(&port->writeFifo, req->buf, port->ecm->dataInPipe.maxPacketSize); in UsbEcmStartTx()
68 OsalMutexUnlock(&port->lockWriteFifo); in UsbEcmStartTx()
74 port->writeBusy = true; in UsbEcmStartTx()
76 port->writeBusy = false; in UsbEcmStartTx()
82 port->writeStarted++; in UsbEcmStartTx()
84 if (port->ecm == NULL) { in UsbEcmStartTx()
91 static uint32_t UsbEcmStartRx(struct UsbEcm *port) in UsbEcmStartRx() argument
93 struct DListHead *pool = &port->readPool; in UsbEcmStartRx()
94 struct UsbEcmPipe *out = &port->ecm->dataOutPipe; in UsbEcmStartRx()
100 if (port->readStarted >= QUEUE_SIZE) { in UsbEcmStartRx()
113 port->readStarted++; in UsbEcmStartRx()
115 if (port->ecm == NULL) { in UsbEcmStartRx()
119 return port->readStarted; in UsbEcmStartRx()
122 static void UsbEcmRxPush(struct UsbEcm *port) in UsbEcmRxPush() argument
124 struct DListHead *queue = &port->readQueue; in UsbEcmRxPush()
145 OsalMutexLock(&port->lockReadFifo); in UsbEcmRxPush()
146 if (DataFifoIsFull(&port->readFifo)) { in UsbEcmRxPush()
147 DataFifoSkip(&port->readFifo, size); in UsbEcmRxPush()
149 uint32_t count = DataFifoWrite(&port->readFifo, data, size); in UsbEcmRxPush()
153 OsalMutexUnlock(&port->lockReadFifo); in UsbEcmRxPush()
156 DListInsertTail(&req->list, &port->readPool); in UsbEcmRxPush()
157 port->readStarted--; in UsbEcmRxPush()
160 if (!disconnect && port->ecm) { in UsbEcmRxPush()
161 UsbEcmStartRx(port); in UsbEcmRxPush()
180 struct UsbEcm *port = (struct UsbEcm *)req->context; in UsbEcmReadComplete() local
181 OsalMutexLock(&port->lock); in UsbEcmReadComplete()
182 DListInsertTail(&req->list, &port->readQueue); in UsbEcmReadComplete()
183 UsbEcmRxPush(port); in UsbEcmReadComplete()
184 OsalMutexUnlock(&port->lock); in UsbEcmReadComplete()
189 struct UsbEcm *port = (struct UsbEcm *)req->context; in UsbEcmWriteComplete() local
190 OsalMutexLock(&port->lock); in UsbEcmWriteComplete()
191 DListInsertTail(&req->list, &port->writePool); in UsbEcmWriteComplete()
192 port->writeStarted--; in UsbEcmWriteComplete()
196 UsbEcmStartTx(port); in UsbEcmWriteComplete()
205 OsalMutexUnlock(&port->lock); in UsbEcmWriteComplete()
208 static int32_t UsbEcmAllocReadRequests(struct UsbEcm *port, int32_t num) in UsbEcmAllocReadRequests() argument
210 struct UsbEcmDevice *ecm = port->ecm; in UsbEcmAllocReadRequests()
211 struct DListHead *head = &port->readPool; in UsbEcmAllocReadRequests()
222 req->context = port; in UsbEcmAllocReadRequests()
224 port->readAllocated++; in UsbEcmAllocReadRequests()
229 static int32_t UsbEcmAllocWriteRequests(struct UsbEcm *port, int32_t num) in UsbEcmAllocWriteRequests() argument
231 struct UsbEcmDevice *ecm = port->ecm; in UsbEcmAllocWriteRequests()
232 struct DListHead *head = &port->writePool; in UsbEcmAllocWriteRequests()
243 req->context = port; in UsbEcmAllocWriteRequests()
245 port->writeAllocated++; in UsbEcmAllocWriteRequests()
250 static int32_t UsbEcmStartIo(struct UsbEcm *port) in UsbEcmStartIo() argument
252 struct DListHead *head = &port->readPool; in UsbEcmStartIo()
257 if (port->readAllocated == 0) { in UsbEcmStartIo()
258 ret = UsbEcmAllocReadRequests(port, QUEUE_SIZE); in UsbEcmStartIo()
263 if (port->writeAllocated == 0) { in UsbEcmStartIo()
264 ret = UsbEcmAllocWriteRequests(port, QUEUE_SIZE); in UsbEcmStartIo()
266 UsbEcmFreeRequests(head, &port->readAllocated); in UsbEcmStartIo()
271 started = UsbEcmStartRx(port); in UsbEcmStartIo()
273 UsbEcmStartTx(port); in UsbEcmStartIo()
275 UsbEcmFreeRequests(head, &port->readAllocated); in UsbEcmStartIo()
276 UsbEcmFreeRequests(&port->writePool, &port->writeAllocated); in UsbEcmStartIo()
297 static int32_t UsbEcmOpen(struct UsbEcm *port) in UsbEcmOpen() argument
301 if (port == NULL) { in UsbEcmOpen()
305 OsalMutexLock(&port->lock); in UsbEcmOpen()
306 ret = UsbEcmAllocFifo(&port->writeFifo, WRITE_BUF_SIZE); in UsbEcmOpen()
311 ret = UsbEcmAllocFifo(&port->readFifo, READ_BUF_SIZE); in UsbEcmOpen()
316 DataFifoReset(&port->writeFifo); in UsbEcmOpen()
317 DataFifoReset(&port->readFifo); in UsbEcmOpen()
319 if (port->refCount++) { in UsbEcmOpen()
325 if (port->ecm) { in UsbEcmOpen()
327 ret = UsbEcmStartIo(port); in UsbEcmOpen()
334 OsalMutexUnlock(&port->lock); in UsbEcmOpen()
338 static int32_t UsbEcmClose(struct UsbEcm *port) in UsbEcmClose() argument
340 if (port == NULL) { in UsbEcmClose()
344 OsalMutexLock(&port->lock); in UsbEcmClose()
345 if (port->refCount != 1) { in UsbEcmClose()
346 --port->refCount; in UsbEcmClose()
352 DataFifoReset(&port->writeFifo); in UsbEcmClose()
353 DataFifoReset(&port->readFifo); in UsbEcmClose()
354 port->refCount = 0; in UsbEcmClose()
357 OsalMutexUnlock(&port->lock); in UsbEcmClose()
361 static int32_t UsbEcmRead(struct UsbEcm *port, struct HdfSBuf *reply) in UsbEcmRead() argument
366 OsalMutexLock(&port->lock); in UsbEcmRead()
367 OsalMutexLock(&port->lockReadFifo); in UsbEcmRead()
368 if (DataFifoIsEmpty(&port->readFifo)) { in UsbEcmRead()
369 OsalMutexUnlock(&port->lockReadFifo); in UsbEcmRead()
370 OsalMutexUnlock(&port->lock); in UsbEcmRead()
374 buf = (uint8_t *)OsalMemCalloc(DataFifoLen(&port->readFifo) + sizeof(uint32_t)); in UsbEcmRead()
377 OsalMutexUnlock(&port->lockReadFifo); in UsbEcmRead()
378 OsalMutexUnlock(&port->lock); in UsbEcmRead()
382 len = DataFifoRead(&port->readFifo, buf, DataFifoLen(&port->readFifo)); in UsbEcmRead()
386 OsalMutexUnlock(&port->lockReadFifo); in UsbEcmRead()
389 OsalMutexUnlock(&port->lockReadFifo); in UsbEcmRead()
399 if (port->ecm) { in UsbEcmRead()
400 UsbEcmStartRx(port); in UsbEcmRead()
403 OsalMutexUnlock(&port->lock); in UsbEcmRead()
407 static int32_t UsbEcmWrite(struct UsbEcm *port, struct HdfSBuf *data) in UsbEcmWrite() argument
417 OsalMutexLock(&port->lock); in UsbEcmWrite()
419 OsalMutexLock(&port->lockWriteFifo); in UsbEcmWrite()
420 size = DataFifoWrite(&port->writeFifo, buf, size); in UsbEcmWrite()
421 OsalMutexUnlock(&port->lockWriteFifo); in UsbEcmWrite()
423 if (port->ecm) { in UsbEcmWrite()
424 UsbEcmStartTx(port); in UsbEcmWrite()
426 OsalMutexUnlock(&port->lock); in UsbEcmWrite()
549 struct UsbEcm *port = NULL; in EcmDeviceDispatch() local
574 port = ecm->port; in EcmDeviceDispatch()
575 if (port == NULL) { in EcmDeviceDispatch()
578 OsalMutexLock(&port->lockRW); in EcmDeviceDispatch()
581 ret = UsbEcmOpen(port); in EcmDeviceDispatch()
584 ret = UsbEcmClose(port); in EcmDeviceDispatch()
587 ret = UsbEcmRead(port, reply); in EcmDeviceDispatch()
590 ret = UsbEcmWrite(port, data); in EcmDeviceDispatch()
596 OsalMutexUnlock(&port->lockRW); in EcmDeviceDispatch()
828 struct UsbEcm *port = NULL; in UsbEcmAlloc() local
830 port = (struct UsbEcm *)OsalMemCalloc(sizeof(*port)); in UsbEcmAlloc()
831 if (port == NULL) { in UsbEcmAlloc()
836 if (OsalMutexInit(&port->lock) != HDF_SUCCESS) { in UsbEcmAlloc()
838 OsalMemFree(port); in UsbEcmAlloc()
842 if (OsalMutexInit(&port->lockRW) != HDF_SUCCESS) { in UsbEcmAlloc()
844 OsalMutexDestroy(&port->lock); in UsbEcmAlloc()
845 OsalMemFree(port); in UsbEcmAlloc()
849 if (OsalMutexInit(&port->lockReadFifo) != HDF_SUCCESS) { in UsbEcmAlloc()
851 OsalMutexDestroy(&port->lock); in UsbEcmAlloc()
852 OsalMutexDestroy(&port->lockRW); in UsbEcmAlloc()
853 OsalMemFree(port); in UsbEcmAlloc()
857 if (OsalMutexInit(&port->lockWriteFifo) != HDF_SUCCESS) { in UsbEcmAlloc()
859 OsalMutexDestroy(&port->lock); in UsbEcmAlloc()
860 OsalMutexDestroy(&port->lockRW); in UsbEcmAlloc()
861 OsalMutexDestroy(&port->lockReadFifo); in UsbEcmAlloc()
862 OsalMemFree(port); in UsbEcmAlloc()
865 DListHeadInit(&port->readPool); in UsbEcmAlloc()
866 DListHeadInit(&port->readQueue); in UsbEcmAlloc()
867 DListHeadInit(&port->writePool); in UsbEcmAlloc()
869 ecm->port = port; in UsbEcmAlloc()
875 if (ecm != NULL && ecm->port != NULL) { in UsbEcmFree()
876 OsalMutexDestroy(&ecm->port->lock); in UsbEcmFree()
877 OsalMutexDestroy(&ecm->port->lockRW); in UsbEcmFree()
878 OsalMutexDestroy(&ecm->port->lockReadFifo); in UsbEcmFree()
879 OsalMutexDestroy(&ecm->port->lockWriteFifo); in UsbEcmFree()
880 OsalMemFree(ecm->port); in UsbEcmFree()
881 ecm->port = NULL; in UsbEcmFree()
1000 if (ecm->port) { in EcmRelease()
1001 OsalMemFree(ecm->port); in EcmRelease()
1002 ecm->port = NULL; in EcmRelease()