anchor.diff:  
   (in-package :mezzano.driver.rtl8168)
   
  +;;; "Realtek Gigabit Ethernet Media Access Controller With Power Management RTL8169"
   ;;; http://www.iitg.ernet.in/asahu/cs421/RealTek.pdf
   
   ;;; Registers.
  
positive.code:     (setf (values (rtl8168-rx-bounce-phys nic)
                    (rtl8168-rx-bounce-virt nic))
            (rtl8168-allocate-bounce "RX" +rtl8168-n-rx-descriptors+))
      ;; FIXME: Verify that all buffers were allocated.
      ;; Reset the TX ring.
      (dotimes (i +rtl8168-n-tx-descriptors+)
        (setf (rtl8168-tx-desc-flags nic i) 0
              (rtl8168-tx-desc-vlan nic i) 0
              (rtl8168-tx-desc-address nic i) (+ (rtl8168-tx-bounce-phys nic)
                                                 (* i (mezzano.supervisor::align-up +rtl8168-mtu+ 128)))))
      (setf (rtl8168-tx-used-count nic) 0
            (rtl8168-tx-current nic) 0
            (rtl8168-tx-tail nic) 0)
      ;; Reset the RX ring.
      (dotimes (i +rtl8168-n-rx-descriptors+)
        (setf (rtl8168-rx-desc-flags nic i) (logior (ash +rtl8168-mtu+ +rtl8168-descriptor-Frame_Length+)
                                                    (ash 1 +rtl8168-descriptor-OWN+)
                                                    (if (eql i (1- +rtl8168-n-rx-descriptors+))
                                                        (ash 1 +rtl8168-descriptor-EOR+)
                                                        0))
              (rtl8168-rx-desc-vlan nic i) 0
              (rtl8168-rx-desc-address nic i) (+ (rtl8168-rx-bounce-phys nic)
                                                 (* i (mezzano.supervisor::align-up +rtl8168-mtu+ 128)))))
      (setf (rtl8168-rx-current nic) 0)
      ;; Configure Rx.
      (setf (rtl8168-reg/32 nic +rtl8168-register-RCR+)
            (logior (ash #b111 +rtl8168-RCR-RXFTH+) ; No Rx FIFO threshold. This seems like the safest option to me.
                    (ash #b111 +rtl8168-RCR-MXDMA+) ; Unlimited maximum DMA burst size. PCI related, I don't know anything about this.
                    ;; Accept broadcast packets, packets addressed to us and all packets with a destination address (promiscious mode).
                    (ash 1 +rtl8168-RCR-AB+)
                    (ash 1 +rtl8168-RCR-APM+)
                    (ash 1 +rtl8168-RCR-AAP+)))
      (setf (rtl8168-reg/16 nic +rtl8168-register-RMS+) +rtl8168-mtu+) ; ### not clear if this includes the trailing CRC or not.
      (setf (rtl8168-reg/32 nic +rtl8168-register-RDSAR+) (ldb (byte 32 0) (rtl8168-rx-ring-phys nic))
            (rtl8168-reg/32 nic (+ +rtl8168-register-RDSAR+ 4)) (ldb (byte 32 32) (rtl8168-rx-ring-phys nic)))
      ;; Configure Tx.
      (setf (rtl8168-reg/32 nic +rtl8168-register-TCR+)
            (logior (ash #b11 +rtl8168-TCR-IFG+) ; Standard interframe gap time.
                    (ash #b0 +rtl8168-TCR-IFG2+)
                    (ash #b111 +rtl8168-TCR-MXDMA+))) ; Unlimited maximum DMA burst size. PCI related, I don't know anything about this.
      (setf (rtl8168-reg/8 nic +rtl8168-register-ETThR+) 48) ; I have no idea what this should be. (ceiling mtu 32)
      (setf (rtl8168-reg/32 nic +rtl8168-register-TNPDS+) (ldb (byte 32 0) (rtl8168-tx-ring-phys nic))
            (rtl8168-reg/32 nic (+ +rtl8168-register-TNPDS+ 4)) (ldb (byte 32 32) (rtl8168-tx-ring-phys nic)))
      ;; Enable TX & RX.
      (setf (rtl8168-reg/8 nic +rtl8168-register-CR+) (logior (ash 1 +rtl8168-CR-RE+)
                                                              (ash 1 +rtl8168-CR-TE+)))
      ;; Unmask IRQs.
      (setf (rtl8168-reg/16 nic +rtl8168-register-IMR+) #b1111) ; enable tx error, tx ok, rx error and rx ok.
      (simple-irq-unmask (rtl8168-irq-handler nic)))
    (nic:register-network-card nic)
    t)
  
negative.code: (defconstant +rtl8168-TPPoll-NPQ+ 6 "Normal Priority Queue polling")
  (defconstant +rtl8168-TPPoll-FSWInt+ 0 "Forced Software Interrupt")
  
  ;;; Bits in ISR/IMR.
  (defconstant +ISR-ROK+ 0 "Receive OK")
  (defconstant +ISR-RER+ 1 "Receive Error")
  (defconstant +ISR-TOK+ 2 "Transmit OK")
  (defconstant +ISR-TER+ 3 "Transmit Error")
  (defconstant +ISR-RDU+ 4 "Rx Descriptor Unavailable")
  (defconstant +ISR-PUN/LinkChg+ 5 "Packet Underrun/Link Changed")
  (defconstant +ISR-FOVW+ 6 "Rx FIFO Overflow")
  (defconstant +ISR-TDU+ 7 "Tx Descriptor Unavailable")
  (defconstant +ISR-SWInt+ 8 "Software Interrupt")
  (defconstant +ISR-TimeOut+ 14 "Time Out. TCTR reached TimerInt")
  (defconstant +ISR-SERR+ 15 "System Error")
  
  (defconstant +rtl8168-mtu+ 1536)
  (defconstant +rtl8168-descriptor-size+ 16)
  (defconstant +rtl8168-n-tx-descriptors+ 128)
  