AMD PCNET: Difference between revisions

Jump to navigation Jump to search
[unchecked revision][unchecked revision]
Content added Content deleted
(Rewrote article to include proper initialization and transmit/receive packet examples)
m (typos)
Line 81: Line 81:
and similar functions for BCRs.
and similar functions for BCRs.


Unfortunately it is difficult to determine the current state of DWIO (and therefore know which state the card is in when the driver initializes) as the only way of reporting it is to read BCR18 bit 7, which in turn requires knowledge of the BDP, which requires knowledge of DWIO etc. Fortunately, following a reset (either hard or soft), the card is in a known state with DWIO=0 (16-bit access). Normally, therefore, when your driver takes control of the card, it can assume it is in 16-bit mode. However, it may be the case that firmware or a bootloader has already initialized the card into 32-bit mode, which you didn't know about. You should, therefore, reset the card when your driver takes control. This is accomplished by a read of the reset register:<source lang="c">ind(io_base + 0x18);
Unfortunately it is difficult to determine the current state of DWIO (and therefore know which state the card is in when the driver initializes) as the only way of reporting it is to read BCR18 bit 7, which in turn requires knowledge of the BDP, which requires knowledge of DWIO etc. Fortunately, following a reset (either hard or soft), the card is in a known state with DWIO=0 (16-bit access). Normally, therefore, when your driver takes control of the card, it would expect to assume it is in 16-bit mode. However, it may be the case that firmware or a bootloader has already initialized the card into 32-bit mode, which you didn't know about. You should, therefore, reset the card when your driver takes control. This is accomplished by a read of the reset register:<source lang="c">ind(io_base + 0x18);
inw(io_base + 0x14);</source>Note this snippet reads first from the 32-bit reset register: if the card is in 32-bit mode this will trigger a reset, if in 16-bit mode it will simply read garbage without affecting the card. It then reads from the 16-bit reset register: if the card was initially in 32-bit mode, it has since been reset and will now be reset again, otherwise it will reset for the first time.
inw(io_base + 0x14);</source>Note this snippet reads first from the 32-bit reset register: if the card is in 32-bit mode this will trigger a reset, if in 16-bit mode it will simply read garbage without affecting the card. It then reads from the 16-bit reset register: if the card was initially in 32-bit mode, it has since been reset and will now be reset again, otherwise it will reset for the first time.


Line 141: Line 141:
{
{
int ret = cur_tx_idx + 1;
int ret = cur_tx_idx + 1;
if(cur_tx_idx == tx_buffer_count)
if(ret == tx_buffer_count)
ret = 0;
ret = 0;
return ret;
return ret;
Line 150: Line 150:
{
{
int ret = cur_rx_idx + 1;
int ret = cur_rx_idx + 1;
if(cur_rx_idx == rx_buffer_count)
if(ret == rx_buffer_count)
ret = 0;
ret = 0;
return ret;
return ret;