none
NDIS Scatter Gather DMA or Common Buffer DMA on NDIS 6.20 ? RRS feed

  • Question

  • Currently, I have an FPGA based PCI NIC. I have mapped the registers and can read and write to them. According to the H/W engineers the NIC is capable of doing scatter gather DMA. But they have provided registers for pointing to the TX Buffers and the length/size (address length-pairs ?). 

    I am bit confused on whether I should use the common buffer DMA or the S/G DMA. If I create a scatter gather list, how can I access the SG list element ?  Is this the right way to access the SG list on Ndis 6.20 ? 

    Also if I am going to allocate Tx and Rx ring buffers of 256 bytes, do I need to provide that info by add Reg in the INF file ?



    With regards,
    Jenson Alex Pais


    Monday, July 4, 2016 10:01 AM

Answers

  • Yes, you must transform the system-provided SG list into a format that is understood by your device; I was just pointing out a common optimization. Yes, NdisMAllocateNetBuggerSGList will allocate memory guaranteed to be visible to your DMA controller (the MS developers aren't stupid).

    As far as using NdisMAllocateNetBuggerSGList goes, there are several ways you can use it, depending upon how you want to optimize your driver. You can let NDIS allocate the SG buffer for you by passing NULL for the SGLB, or you can manage it yourself, in which case you would pass the virtual address of a buffer you allocated. To keep things simple, I would recommend that you let NDIS allocate it for you, and then worry about performance once you're got it functioning. The more you let NDIS do the work for you, the easier - and faster - it will be to get a working driver.

    No, you don't need anything special in the INF for line-based interrupts

     -Brian


    Azius Developer Training www.azius.com Windows device driver, internals, security, & forensics training and consulting. Blog at www.azius.com/blog

    Tuesday, July 5, 2016 6:26 PM
    Moderator

All replies

  • To ensure that your DMA buffer is visible to your controller, you should use NdisMAllocateSharedMemory to allocate your buffers. You might want to read up on NDIS DMA here

    Since yours is a "soft" device (FPGA), you should ask the HW engineers to make the scatter-gather list format be the same as what NDIS creates, so you don't need to transform it.

    No, you don't need to put anything in your INF file about your DMA, but you will need to specify if your hardware uses MSI interrupts

     -Brian


    Azius Developer Training www.azius.com Windows device driver, internals, security, & forensics training and consulting. Blog at www.azius.com/blog

    Monday, July 4, 2016 10:30 PM
    Moderator
  • Hi Brian,

    Thank you for providing the info about NdisMAllocateSharedMemory. 

    Since the H/W is already deployed while using Linux drivers, I am kind of stuck with the current H/W. I highly doubt the H/W engineers  will make any changes to their design now.  Shouldn't I be able to get the SGList element and then buffer pointer and the length of the buffer ? So that I can copy those two into the mapped registers of the NIC for every NB.

    Will NdisMAllocateNetBufferSGList make use of the allocated shared memory ? Do I pass the virtual address obtained from the NdisMAllocateSharedMemory to the optional ScatterGatherListBuffer ?

    No changes to the INF file for the DMA part, wonderful. The hardware makes use of a line based interrupt. So I don't need to provide that info in the INF file ? 


    With regards, Jenson Alex Pais


    • Edited by JENSON PAIS Tuesday, July 5, 2016 7:11 AM Added query about allocation of SGlist
    Tuesday, July 5, 2016 6:06 AM
  • Yes, you must transform the system-provided SG list into a format that is understood by your device; I was just pointing out a common optimization. Yes, NdisMAllocateNetBuggerSGList will allocate memory guaranteed to be visible to your DMA controller (the MS developers aren't stupid).

    As far as using NdisMAllocateNetBuggerSGList goes, there are several ways you can use it, depending upon how you want to optimize your driver. You can let NDIS allocate the SG buffer for you by passing NULL for the SGLB, or you can manage it yourself, in which case you would pass the virtual address of a buffer you allocated. To keep things simple, I would recommend that you let NDIS allocate it for you, and then worry about performance once you're got it functioning. The more you let NDIS do the work for you, the easier - and faster - it will be to get a working driver.

    No, you don't need anything special in the INF for line-based interrupts

     -Brian


    Azius Developer Training www.azius.com Windows device driver, internals, security, & forensics training and consulting. Blog at www.azius.com/blog

    Tuesday, July 5, 2016 6:26 PM
    Moderator
  • Cheers for all the help, Brian. Your Azius blog about the INF file was also very helpful when I was modifying the INF file. 

    I am going to follow your advice and let NDIS allocate the SG buffer by keeping that value to null. Will get back to this thread if I face any issues. 


    With regards,
    Jenson Alex Pais


    Wednesday, July 6, 2016 9:44 AM
  • Hi Brian,

    Only one silly doubt, since NDIS 6 onwards requires deserialized miniports. Do I need to maintain another queue (I'm doing that already as I am using the NetVmini sample) or the SGList generated requires. I'm a bit confused about how to do the net buffer management then. 

    Also can I add the Ethernet header before SGList or after ?


    With regards, Jenson Alex Pais


    • Edited by JENSON PAIS Monday, July 18, 2016 11:26 AM Added Ethernet header part.
    Monday, July 18, 2016 10:22 AM
  • One way or another, you will have to manage the resources used by your driver. As I mentioned, fully managing your SG resources will give you better performance at the cost of more complexity. Letting the system do it initially is an easy way to get your driver up and running with the least amount of work.

    The SG list is based upon the contents of the NET_BUFFER, so any modifications should be done before the SG list is built.

     -Brian


    Azius Developer Training www.azius.com Windows device driver, internals, security, & forensics training and consulting. Blog at www.azius.com/blog

    Monday, July 18, 2016 5:55 PM
    Moderator
  • Thanks once again Brian. Cleared both my doubts. For now will let NDIS generate the SGL, will make necessary changes to the net buffer before building the SG List. 

    With regards, Jenson Alex Pais

    Tuesday, July 19, 2016 6:08 AM