Lines Matching defs:nic
119 struct VirtNetif *nic;
146 struct VirtNetif *nic = netif->state;
147 struct VirtnetConfig *conf = (struct VirtnetConfig *)(nic->dev.base + VIRTMMIO_REG_CONFIG);
183 static err_t InitTxFreelist(struct VirtNetif *nic)
187 nic->tbufRec = malloc(sizeof(struct TbufRecord) * nic->dev.vq[1].qsz);
188 if (nic->tbufRec == NULL) {
189 PRINT_ERR("alloc nic->tbufRec memory failed\n");
193 for (i = 0; i < nic->dev.vq[1].qsz - 1; i++) {
194 nic->dev.vq[1].desc[i].flag = VIRTQ_DESC_F_NEXT;
195 nic->dev.vq[1].desc[i].next = i + 1;
197 nic->tFreeHdr = 0;
198 nic->tFreeNum = nic->dev.vq[1].qsz;
203 static void FreeTxEntry(struct VirtNetif *nic, uint16_t head)
207 struct Virtq *q = &nic->dev.vq[1];
210 phead = nic->tbufRec[idx].head;
211 count = nic->tbufRec[idx].count;
212 tail = nic->tbufRec[idx].tail;
214 LOS_SpinLock(&nic->transLock);
215 if (nic->tFreeNum > 0) {
216 q->desc[tail].next = nic->tFreeHdr;
219 nic->tFreeNum += count;
220 nic->tFreeHdr = head;
221 LOS_SpinUnlock(&nic->transLock);
229 struct VirtNetif *nic = pc->nic;
232 LOS_SpinLockSave(&nic->recvLock, &intSave);
233 nic->dev.vq[0].avail->ring[nic->dev.vq[0].avail->index % nic->dev.vq[0].qsz] = pc->id;
235 nic->dev.vq[0].avail->index++;
236 LOS_SpinUnlockRestore(&nic->recvLock, intSave);
238 if (nic->dev.vq[0].used->flag != VIRTQ_USED_F_NO_NOTIFY) {
239 FENCE_WRITE_UINT32(0, nic->dev.base + VIRTMMIO_REG_QUEUENOTIFY);
243 static err_t ConfigRxBuffer(struct VirtNetif *nic, VADDR_T buf)
247 struct Virtq *q = &nic->dev.vq[0];
249 nic->rbufRec = calloc(q->qsz, sizeof(struct RbufRecord));
250 if (nic->rbufRec == NULL) {
251 PRINT_ERR("alloc nic->rbufRec memory failed\n");
265 nic->rbufRec[i].cbuf.custom_free_function = ReleaseRxEntry;
266 nic->rbufRec[i].nic = nic;
267 nic->rbufRec[i].id = i;
273 static err_t ConfigQueue(struct VirtNetif *nic)
297 buf = VirtmmioConfigQueue(&nic->dev, (VADDR_T)base, qsz, VIRTQ_NUM_NET);
307 if ((ret = ConfigRxBuffer(nic, buf)) != ERR_OK) {
311 if ((ret = InitTxFreelist(nic)) != ERR_OK) {
318 static uint16_t GetTxFreeEntry(struct VirtNetif *nic, uint16_t count)
324 LOS_SpinLockSave(&nic->transLock, &intSave);
325 if (count > nic->tFreeNum) {
326 LOS_SpinUnlockRestore(&nic->transLock, intSave);
331 nic->tFreeNum -= count;
332 head = nic->tFreeHdr;
336 idx = nic->dev.vq[1].desc[idx].next;
338 nic->tFreeHdr = idx; /* may be invalid if empty, but tFreeNum must be valid: 0 */
339 LOS_SpinUnlockRestore(&nic->transLock, intSave);
340 nic->dev.vq[1].desc[tail].flag &= ~VIRTQ_DESC_F_NEXT;
349 struct VirtNetif *nic = netif->state;
350 struct Virtq *trans = &nic->dev.vq[1];
363 head = GetTxFreeEntry(nic, add);
364 trans->desc[head].pAddr = u32_to_u64(VMM_TO_DMA_ADDR((PADDR_T)&nic->vnHdr));
376 nic->tbufRec[idx].head = p;
377 nic->tbufRec[idx].count = add;
378 nic->tbufRec[idx].tail = tmp;
384 FENCE_WRITE_UINT32(1, nic->dev.base + VIRTMMIO_REG_QUEUENOTIFY);
395 struct VirtNetif *nic = netif->state;
400 payload = DMA_TO_VMM_ADDR(nic->dev.vq[0].desc[e->id].pAddr) + sizeof(struct VirtnetHdr);
405 &nic->rbufRec[e->id].cbuf, (void *)payload, ETH_FRAME_LEN);
413 p = &nic->rbufRec[e->id].cbuf.pbuf;
421 struct VirtNetif *nic = netif->state;
422 struct Virtq *q = &nic->dev.vq[0];
450 static void VirtnetTxHandle(struct VirtNetif *nic)
452 struct Virtq *q = &nic->dev.vq[1];
460 FreeTxEntry(nic, e->id);
469 struct VirtNetif *nic = netif->state;
471 if (!(GET_UINT32(nic->dev.base + VIRTMMIO_REG_INTERRUPTSTATUS) & VIRTMMIO_IRQ_NOTIFY_USED)) {
477 VirtnetTxHandle(nic);
479 FENCE_WRITE_UINT32(VIRTMMIO_IRQ_NOTIFY_USED, nic->dev.base + VIRTMMIO_REG_INTERRUPTACK);
484 struct VirtNetif *nic = netif->state;
487 if (!VirtmmioDiscover(VIRTMMIO_DEVICE_ID_NET, &nic->dev)) {
491 VirtmmioInitBegin(&nic->dev);
493 if (!VirtmmioNegotiate(&nic->dev, Feature0, Feature1, netif)) {
498 if ((ret = ConfigQueue(nic)) != ERR_OK) {
502 if (!VirtmmioRegisterIRQ(&nic->dev, (HWI_PROC_FUNC)VirtnetIRQhandle, netif, VIRTMMIO_NETIF_NAME)) {
507 VritmmioInitEnd(&nic->dev);
510 nic->dev.vq[0].avail->index += nic->dev.vq[0].qsz;
511 FENCE_WRITE_UINT32(0, nic->dev.base + VIRTMMIO_REG_QUEUENOTIFY);
515 VirtmmioInitFailed(&nic->dev);
521 struct VirtNetif *nic = NULL;
525 nic = mem_calloc(1, sizeof(struct VirtNetif));
526 if (nic == NULL) {
527 PRINT_ERR("alloc nic memory failed\n");
530 netif->state = nic;
549 struct VirtNetif *nic = netif->state;
551 if (nic && (nic->dev.irq & ~_IRQ_MASK)) {
552 LOS_HwiDelete(nic->dev.irq, NULL);
554 if (nic && nic->rbufRec) {
555 free(nic->rbufRec);
557 if (nic && nic->tbufRec) {
558 free(nic->tbufRec);
560 if (nic && nic->dev.vq[0].desc) {
561 free(nic->dev.vq[0].desc);
563 if (nic) {
564 mem_free(nic);