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