Re: DMA mapping

From: Giuliano Procida (myxie@dev.madge.com)
Date: Tue Mar 07 2000 - 10:40:55 EST


Hi.

On Tue, Mar 07, 2000 at 05:59:15AM -0800, Matthew Jacob wrote:
> > I have a nice piece of hardware, that manages state (32-bit handle)
> > for me. It is just a shame that I will have to hack further state
> > tracking on top.
>
> I had the same problem for the Qlogic cards- they return, either in a
> response queue entry or in two 16 bit registers, a 32 bit handle that
> identifies a completing command. But this was always sorta busted for alpha &&
> ultrasparc to try and figure out from this what the real address of the
> original command block was,

Likewise, until I realised that virt_to_bus(skb) produced a nice
32-bit handle to give to the card.

> so I just began using the handle as an index into
> a an array of pointers- turns out this is much cleaner and safer because a lot
> of times the Qlogic f/w is confused and returns garbage instead of the correct
> handle- it's much easier to detect this when you have an index in the range of
> 0 to 1024 rather than assume what you get back from the card is a valid
> pointer.

It looks like I'll be doing something similar, but different:

struct queue {
  ...
  void * free_list;
  void * pointer_list[max_pending_buffers];
}

Start with: free_list -> pointer_list[0] -> ... -> pointer_list[m-1] -> 0

at pci_map:
tmp = free_list (null tmp means free_list exhausted)
free_list = *tmp
*tmp = skb
handle = tmp - pointer_list

at pci_unmap:
tmp = pointer_list + handle
skb = *tmp
*tmp = free_list
free_list = tmp

all with some juicy casts. This has the advantage of O(1) for both
insert and delete and uses only one more pointer (or perhaps index).

> Moral: it's a bad practice to take candy from strangers (i.e., trust
> CPU pointers as returned out of I/O cards).

Moral2: don't trust firmware assembler hackers. :-) :-)

Giuliano.

-- 
mail: gprocida@madge.com / myxie@debian.org | public PGP key ID: 93898735
home: +44 181 351 1172 / Flat 5, 135 Palmerston Road, London N22 8RW, UK
work: +44 1753 661 305 / Madge Networks, Wexham Springs, Slough SL3 6PJ, UK

- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.rutgers.edu Please read the FAQ at http://www.tux.org/lkml/



This archive was generated by hypermail 2b29 : Tue Mar 07 2000 - 21:00:22 EST