📄 ga.c
字号:
#ifdef NSCDEBUG printk("The value of the tail %p 's CMDSTS : %x\n" , pNsc->PriQue[0].pRcbListTail->pRxDp, pNsc->PriQue[0].pRcbListTail->pRxDp->CmdSts);#endif#ifdef NSCDEBUG printk("The number of RX priorities : %d\n",pNsc->RxNumPrio);#endif /* Now set the Mac address in the device structure */ NsmCopy((char *)pNsc->PermMacAddr, (char *)dev->dev_addr, MAC_ADDR_LEN); /* Install interrupt vector and register the interrupt service routine */ if(request_irq (dev->irq, DrvIsr, SA_SHIRQ, dev->name, dev) != OK) {#ifdef FAILURE_MESSAGES printk (KERN_ERR "%s: request_irq Failed \n", DRV_NAME);#endif HsmUnInitialize(pNsc); return -EAGAIN; } /* Reset the adapter */ if( ( stat =HsmReset(pNsc, 0) ) == FAILURE) {#ifdef FAILURE_MESSAGES printk (KERN_ERR "%s: Resetting the adapter, failed \n", DRV_NAME);#endif free_irq (dev->irq, dev); HsmUnInitialize(pNsc); return -EAGAIN; } /* Call HsmOpen call to open the adapter */ if( ( stat =HsmOpen(pNsc) ) == FAILURE) {#ifdef FAILURE_MESSAGES printk (KERN_ERR "%s: Opening the adapter, failed \n", DRV_NAME);#endif free_irq (dev->irq, dev); HsmUnInitialize(pNsc); return -EAGAIN; } HsmRxFilter(pNsc, (ACCEPT_PERFECT_MATCH_ON | ACCEPT_ALL_BROADCAST_ON));#if 0 /* Mark the start flag in the device structure */ dev->start = DEV_STARTED; dev->tbusy = 0; dev->interrupt = 0;#endif /* Set the transmit queue length in the device structure */ dev->tx_queue_len = (MaxTxDesc*MaxPrio); NsmRegRead32(pNsm, (pNsc->RegAddr + RXDP), &dp_val);#ifdef NSCDEBUG NsmDbgMsg1("RXDP's initial Val : %x\n", dp_val);#endif return OK;}/*******************************************************************************f** Name: DrvClose** Description: This closes the device and reclaims the resources** Parameters: dev: Pointer to the device structure ** Return Value: OK or ERROR **f*******************************************************************************/STATIC intDrvClose (struct device *dev){#if 0 NsmContext *pNsm; AdapterContext *pNsc; dev->start = 0; dev->tbusy = 1; /* Get the pointer to the NsmContext and thereby to the AdapterContext, from the device structure */ pNsm = (NsmContext *)dev->priv; pNsc = &(pNsm->AdpCtxt); /* Stop Tx & Rx by calling HsmClose */ HsmClose(pNsc); /* Uninstall the interrupt vector, and deregister the interrupt service routine */ free_irq (dev->irq, dev); /* Free the Tx and Rx lists by calling HsmUnInitialize */ HsmUnInitialize(pNsc); pNsm->status &= ~NSM_OPEN;#endif /* Decrement module reference count using MOD_DEC_USE_COUNT */ MOD_DEC_USE_COUNT; return OK;}void AdapterClose (struct device *dev){ NsmContext *pNsm; AdapterContext *pNsc;#ifdef FT_DBG static UINT CallCount=0; printk("The DrvClose call No : %d",CallCount++);#endif#if 0 dev->start = 0; dev->tbusy = 1;#endif /* Get the pointer to the NsmContext and thereby to the AdapterContext, from the device structure */ pNsm = (NsmContext *)dev->priv; pNsc = &(pNsm->AdpCtxt);#ifdef NSCDEBUG printk(KERN_INFO "DrvClose called\n");#endif /* Stop Tx & Rx by calling HsmClose */ HsmClose(pNsc); /* Uninstall the interrupt vector, and deregister the interrupt service routine */ free_irq (dev->irq, dev); /* Free the Tx and Rx lists by calling HsmUnInitialize */ HsmUnInitialize(pNsc); }/*******************************************************************************f** Name: DrvSend** Description: This sends a packet down to the HSM, to be sent on wire** Parameters: dev: Pointer to the device structure* skb: Pointer to the sk_buff which contains the data to be * sent down** Return Value: OK or ERROR**f*******************************************************************************/STATIC intDrvSend (struct sk_buff *skb, struct device *dev){ NsmContext *pNsm; AdapterContext *pNsc; UINT retval=OK;#ifdef SINGLE_PACKET PktInfo Pkt; UCHAR status;#elif MULTIPLE_PACKETS static PktStruct Pkts; UCHAR stat;#endif /* Get the pointer to the NsmContext and thereby to the AdapterContext, from the device structure */ pNsm = (NsmContext *)dev->priv; pNsc = &(pNsm->AdpCtxt); /* Test the tbusy flag in the device structure before sending packet down */ if (test_and_set_bit(0, &dev->tbusy)) {#ifdef FAILURE_MESSAGES printk("The device is busy \n");#endif return 1; } /* Set the transmit start time in the device structure */ dev->trans_start = jiffies; /* Encapsulate the data which needs to be sent on the wire in a Packet struct */#ifdef SINGLE_PACKET CreatePacketInfo( skb, &Pkt);#elif MULTIPLE_PACKETS CreatePacketStruct( skb, &Pkts);#endif /* Get the priority of the packet, which is going to be sent down from the priority field in the skbuff. */ /* Call the HSM routine to send the packet on the wire with the priority obtained from the priority field of the skbuff. */ #ifdef SINGLE_PACKET#ifdef PRIORITY_QUEUES status = HsmSendPacket(pNsc, &Pkt, skb->priority);#else status = HsmSendPacket(pNsc, &Pkt, 0);#endif if(status == FAILURE) { retval = ERROR; }#elif MULTIPLE_PACKETS#ifdef PRIORITY_QUEUES stat = HsmSendPkts(pNsc, &Pkts, skb->priority);#else stat = HsmSendPkts(pNsc, &Pkts, 0);#endif if(stat == 0) { retval = ERROR; }#endif clear_bit(0, &dev->tbusy); return retval;}/*******************************************************************************f** Name: DrvSetMulticastList ** Description: NsmSetMulticastList sets multicast filters & promiscuous * mode ** Parameters: dev: Pointer to the device structure** Return Value: None **f*******************************************************************************/STATIC voidDrvSetMulticastList (struct device *dev){ struct dev_mc_list *mc_list; MultiList *pMultiList; MultiList *pMulti; MultiList *pMultiNext; NsmContext *pNsm = ((NsmContext *)dev->priv); UINT FilterFlags; /* Get the pointer to the NsmContext and thereby to the AdapterContext, from the device structure */ AdapterContext *pNsc = &(pNsm->AdpCtxt); FilterFlags = (pNsm->FilterFlags | ACCEPT_PERFECT_MATCH_ON | ACCEPT_ALL_BROADCAST_ON); /* Setup promiscuous mode */ if (dev->flags & IFF_PROMISC) { if(pNsm->FilterFlags & PROMISCUOUS_ON) { FilterFlags |= PROMISCUOUS_OFF; FilterFlags &= ~PROMISCUOUS_ON; } else if (pNsm->FilterFlags & PROMISCUOUS_OFF) { FilterFlags |= PROMISCUOUS_ON; FilterFlags &= ~PROMISCUOUS_OFF; } else /* The first time */ { FilterFlags |= PROMISCUOUS_ON; } } /* Receiving all multicast packets */ if (dev->flags & IFF_ALLMULTI) { if(pNsm->FilterFlags & ACCEPT_ALL_MULTICAST_OFF) { FilterFlags |= ACCEPT_ALL_MULTICAST_ON; FilterFlags &= ~ACCEPT_ALL_MULTICAST_OFF; } else if (pNsm->FilterFlags & ACCEPT_ALL_MULTICAST_ON) { FilterFlags |= ACCEPT_ALL_MULTICAST_OFF; FilterFlags &= ~ACCEPT_ALL_MULTICAST_ON; } else /* First time */ { FilterFlags |= ACCEPT_ALL_MULTICAST_ON; } } /* Call the HSM function to set the receive filters */ if(FilterFlags) { HsmRxFilter(pNsc, FilterFlags); pNsm->FilterFlags = FilterFlags; } /* Set the list of multicast addresses in the mc_list */ mc_list = dev->mc_list; pMultiList = NULL; /* Get the multicast address list from the mc_list and allocate a MultiList structure and put the multicast addresses into the MultiList structure */ while(mc_list) { pMulti = (MultiList *)kmalloc(sizeof(MultiList), GFP_KERNEL); if(pMulti == NULL) { if(pMultiList) { pMulti = pMultiList; while(pMulti) { pMultiNext = pMulti->Next; kfree(pMulti); pMulti = pMultiNext; } } return; } NsmCopy(mc_list->dmi_addr, pMulti->MulticastAddr,MAX_ADDR_LEN); pMulti->Next = pMultiList; pMultiList = pMulti; mc_list = mc_list->next; } /* Call the HSM function to add the list of multicast addresses to the filter */ HsmMulticastAdd(pNsc, pMultiList, TRUE); /* Free up the list of MultiList structures */ pMulti = pMultiList; while(pMulti) { pMultiNext = pMulti->Next; kfree(pMulti); pMulti = pMultiNext; }}/*******************************************************************************f** Name: DrvSetMacAddress** Description: This sets a new MAC address** Parameters: dev: Pointer to the device structure** addr: The new MAC address that needs to be set ** Return Value: OK or ERROR **f*******************************************************************************/int DrvSetMacAddress(struct device *dev, void *addr){ AdapterContext *pNsc = &((NsmContext *)dev->priv)->AdpCtxt; void *MacAddr = (void *) (((struct sockaddr *)addr)->sa_data); NsmCopy(MacAddr, (void *)dev->dev_addr, MAC_ADDR_LEN); NsmCopy(MacAddr, (void *)pNsc->CurrMacAddr, MAC_ADDR_LEN); HsmSetMacAddress(pNsc, pNsc->CurrMacAddr); return OK;}/*******************************************************************************f** Name: DrvIsr ** Description: This is the interrupt handler of the driver** Parameters: irq: This represents the IRQ value for which this handler * was registered** dev_id: This is a pointer to the device structure** regs: This is a pointer to a snapshot of the processor's * context, before the processor entered the interrupt code* * Return Value: None**f****************************************************************************/STATIC voidDrvIsr (int irq, void *dev_id, struct pt_regs *regs){ /* Get the pointer to the device structure from the dev_id */ struct device *dev = ( struct device *) dev_id; /* Get the pointer to the AdapterContext */ AdapterContext *pNsc = &(((struct NsmInfo *)dev->priv)->AdpCtxt); /* Set the interrupt flag in the device structure */ dev->interrupt = DEV_INTERRUPTED; /* Call the HSMs interrupt service routine */ HsmIsr (pNsc); /* Clear the interrupt flag in the device structure */ dev->interrupt = DEV_SERVICED_INTERRUPT; }/*******************************************************************************f** Name: DrvIoctl ** Description: This is the ioctl handler of the driver ** Parameters: dev: This is a pointer to the device structure** rq: pointer to a copy of the structure passed by the user * for this command** cmd: This indicates the ioctl command*
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -