A method and apparatus for enqueuing and dequeuing packets to and from a
shared packet memory, while avoiding collisions. An enqueue process or
state machine enqueues packets for a communication connection (e.g.,
channel, queue pair, flow). A dequeue process or state machine operating
in parallel dequeues packets and forwards them (e.g., to an InfiniBand
node). Packets are stored in the shared packet memory, and status/control
information is stored in a control memory that is updated for each packet
enqueue and packet dequeue. Prior to updating the packet and/or control
memory, each process interfaces with the other to determine if the other
process is active and/or to identify the other process' current
communication connection. If the enqueue process detects a collision, it
pauses (e.g., for a predetermined number of clock cycles). If the dequeue
process detects a collision, it selects a different communication
connection to dequeue.