aboutsummaryrefslogtreecommitdiffstats
path: root/gpxe/src/drivers/net
diff options
context:
space:
mode:
authorH. Peter Anvin <hpa@zytor.com>2008-06-04 18:52:18 -0700
committerH. Peter Anvin <hpa@zytor.com>2008-06-04 18:52:18 -0700
commite63132bf03140d91ec74eca663f7bc2f16429fb0 (patch)
treeea5af9895146e85d3912584e699799863e0f8a29 /gpxe/src/drivers/net
parentbce8e1595ab30c828254038523e1e25c9fd9445f (diff)
downloadsyslinux.git-e63132bf03140d91ec74eca663f7bc2f16429fb0.tar.gz
syslinux.git-e63132bf03140d91ec74eca663f7bc2f16429fb0.tar.xz
syslinux.git-e63132bf03140d91ec74eca663f7bc2f16429fb0.zip
Update gPXE from gPXE git
Diffstat (limited to 'gpxe/src/drivers/net')
-rw-r--r--gpxe/src/drivers/net/e1000/e1000.c3
-rw-r--r--gpxe/src/drivers/net/ipoib.c273
-rw-r--r--gpxe/src/drivers/net/legacy.c3
-rw-r--r--gpxe/src/drivers/net/mlx_ipoib/mt23108.c9
-rw-r--r--gpxe/src/drivers/net/mlx_ipoib/mt25218.c9
-rwxr-xr-xgpxe/src/drivers/net/mtnic.c160
-rwxr-xr-xgpxe/src/drivers/net/mtnic.h8
-rw-r--r--gpxe/src/drivers/net/natsemi.c3
-rw-r--r--gpxe/src/drivers/net/pnic.c3
-rw-r--r--gpxe/src/drivers/net/r8169.c581
-rw-r--r--gpxe/src/drivers/net/rtl8139.c3
-rw-r--r--gpxe/src/drivers/net/tg3.c4
-rw-r--r--gpxe/src/drivers/net/tg3.h1
13 files changed, 646 insertions, 414 deletions
diff --git a/gpxe/src/drivers/net/e1000/e1000.c b/gpxe/src/drivers/net/e1000/e1000.c
index 739217cf..a9aa508a 100644
--- a/gpxe/src/drivers/net/e1000/e1000.c
+++ b/gpxe/src/drivers/net/e1000/e1000.c
@@ -876,6 +876,9 @@ e1000_probe ( struct pci_device *pdev,
e1000_get_hw_control ( adapter );
+ /* Mark as link up; we don't yet handle link state */
+ netdev_link_up ( netdev );
+
if ( ( err = register_netdev ( netdev ) ) != 0)
goto err_register;
diff --git a/gpxe/src/drivers/net/ipoib.c b/gpxe/src/drivers/net/ipoib.c
index d457b258..e3baa14f 100644
--- a/gpxe/src/drivers/net/ipoib.c
+++ b/gpxe/src/drivers/net/ipoib.c
@@ -80,10 +80,14 @@ struct ipoib_device {
struct ib_gid broadcast_gid;
/** Broadcast LID */
unsigned int broadcast_lid;
- /** Joined to broadcast group */
- int broadcast_joined;
/** Data queue key */
unsigned long data_qkey;
+ /** Attached to multicast group
+ *
+ * This flag indicates whether or not we have attached our
+ * data queue pair to the broadcast multicast GID.
+ */
+ int broadcast_attached;
};
/**
@@ -272,6 +276,10 @@ static int ipoib_create_qset ( struct ipoib_device *ipoib,
struct ib_device *ibdev = ipoib->ibdev;
int rc;
+ /* Sanity check */
+ assert ( qset->cq == NULL );
+ assert ( qset->qp == NULL );
+
/* Store queue parameters */
qset->recv_max_fill = num_recv_wqes;
@@ -463,6 +471,12 @@ static int ipoib_transmit ( struct net_device *netdev,
}
iob_pull ( iobuf, ( sizeof ( *ipoib_pshdr ) ) );
+ /* Attempting transmission while link is down will put the
+ * queue pair into an error state, so don't try it.
+ */
+ if ( ! ibdev->link_up )
+ return -ENETUNREACH;
+
/* Construct address vector */
memset ( &av, 0, sizeof ( av ) );
av.qkey = IB_GLOBAL_QKEY;
@@ -617,14 +631,24 @@ static void ipoib_recv_path_record ( struct ipoib_device *ipoib __unused,
*/
static void ipoib_recv_mc_member_record ( struct ipoib_device *ipoib,
struct ib_mad_mc_member_record *mc_member_record ) {
+ int joined;
+ int rc;
+
/* Record parameters */
- ipoib->broadcast_joined =
- ( mc_member_record->scope__join_state & 0x0f );
+ joined = ( mc_member_record->scope__join_state & 0x0f );
ipoib->data_qkey = ntohl ( mc_member_record->qkey );
ipoib->broadcast_lid = ntohs ( mc_member_record->mlid );
DBGC ( ipoib, "IPoIB %p %s broadcast group: qkey %lx mlid %x\n",
- ipoib, ( ipoib->broadcast_joined ? "joined" : "left" ),
- ipoib->data_qkey, ipoib->broadcast_lid );
+ ipoib, ( joined ? "joined" : "left" ), ipoib->data_qkey,
+ ipoib->broadcast_lid );
+
+ /* Update data queue pair qkey */
+ if ( ( rc = ib_modify_qp ( ipoib->ibdev, ipoib->data.qp,
+ IB_MODIFY_QKEY, ipoib->data_qkey ) ) != 0 ){
+ DBGC ( ipoib, "IPoIB %p could not update data qkey: %s\n",
+ ipoib, strerror ( rc ) );
+ return;
+ }
}
/**
@@ -742,6 +766,60 @@ static void ipoib_irq ( struct net_device *netdev __unused,
}
/**
+ * Join IPv4 broadcast multicast group
+ *
+ * @v ipoib IPoIB device
+ * @ret rc Return status code
+ */
+static int ipoib_join_broadcast_group ( struct ipoib_device *ipoib ) {
+ int rc;
+
+ /* Sanity check */
+ if ( ! ipoib->data.qp )
+ return 0;
+
+ /* Attach data queue to broadcast multicast GID */
+ assert ( ipoib->broadcast_attached == 0 );
+ if ( ( rc = ib_mcast_attach ( ipoib->ibdev, ipoib->data.qp,
+ &ipoib->broadcast_gid ) ) != 0 ){
+ DBGC ( ipoib, "IPoIB %p could not attach to broadcast GID: "
+ "%s\n", ipoib, strerror ( rc ) );
+ return rc;
+ }
+ ipoib->broadcast_attached = 1;
+
+ /* Initiate broadcast group join */
+ if ( ( rc = ipoib_mc_member_record ( ipoib, &ipoib->broadcast_gid,
+ 1 ) ) != 0 ) {
+ DBGC ( ipoib, "IPoIB %p could not send broadcast join: %s\n",
+ ipoib, strerror ( rc ) );
+ return rc;
+ }
+
+ /* We will set link up on the network device when we receive
+ * the broadcast join response.
+ */
+
+ return 0;
+}
+
+/**
+ * Leave IPv4 broadcast multicast group
+ *
+ * @v ipoib IPoIB device
+ */
+static void ipoib_leave_broadcast_group ( struct ipoib_device *ipoib ) {
+
+ /* Detach data queue from broadcast multicast GID */
+ if ( ipoib->broadcast_attached ) {
+ assert ( ipoib->data.qp != NULL );
+ ib_mcast_detach ( ipoib->ibdev, ipoib->data.qp,
+ &ipoib->broadcast_gid );
+ ipoib->broadcast_attached = 0;
+ }
+}
+
+/**
* Open IPoIB network device
*
* @v netdev Network device
@@ -749,22 +827,53 @@ static void ipoib_irq ( struct net_device *netdev __unused,
*/
static int ipoib_open ( struct net_device *netdev ) {
struct ipoib_device *ipoib = netdev->priv;
- struct ib_device *ibdev = ipoib->ibdev;
+ struct ipoib_mac *mac = ( ( struct ipoib_mac * ) netdev->ll_addr );
int rc;
- /* Attach to broadcast multicast GID */
- if ( ( rc = ib_mcast_attach ( ibdev, ipoib->data.qp,
- &ipoib->broadcast_gid ) ) != 0 ) {
- DBG ( "Could not attach to broadcast GID: %s\n",
- strerror ( rc ) );
- return rc;
+ /* Allocate metadata queue set */
+ if ( ( rc = ipoib_create_qset ( ipoib, &ipoib->meta,
+ IPOIB_META_NUM_CQES,
+ IPOIB_META_NUM_SEND_WQES,
+ IPOIB_META_NUM_RECV_WQES,
+ IB_GLOBAL_QKEY ) ) != 0 ) {
+ DBGC ( ipoib, "IPoIB %p could not allocate metadata QP: %s\n",
+ ipoib, strerror ( rc ) );
+ goto err_create_meta_qset;
}
+ /* Allocate data queue set */
+ if ( ( rc = ipoib_create_qset ( ipoib, &ipoib->data,
+ IPOIB_DATA_NUM_CQES,
+ IPOIB_DATA_NUM_SEND_WQES,
+ IPOIB_DATA_NUM_RECV_WQES,
+ IB_GLOBAL_QKEY ) ) != 0 ) {
+ DBGC ( ipoib, "IPoIB %p could not allocate data QP: %s\n",
+ ipoib, strerror ( rc ) );
+ goto err_create_data_qset;
+ }
+
+ /* Update MAC address with data QPN */
+ mac->qpn = htonl ( ipoib->data.qp->qpn );
+
/* Fill receive rings */
ipoib_refill_recv ( ipoib, &ipoib->meta );
ipoib_refill_recv ( ipoib, &ipoib->data );
+ /* Join broadcast group */
+ if ( ( rc = ipoib_join_broadcast_group ( ipoib ) ) != 0 ) {
+ DBGC ( ipoib, "IPoIB %p could not join broadcast group: %s\n",
+ ipoib, strerror ( rc ) );
+ goto err_join_broadcast;
+ }
+
return 0;
+
+ err_join_broadcast:
+ ipoib_destroy_qset ( ipoib, &ipoib->data );
+ err_create_data_qset:
+ ipoib_destroy_qset ( ipoib, &ipoib->meta );
+ err_create_meta_qset:
+ return rc;
}
/**
@@ -774,12 +883,17 @@ static int ipoib_open ( struct net_device *netdev ) {
*/
static void ipoib_close ( struct net_device *netdev ) {
struct ipoib_device *ipoib = netdev->priv;
- struct ib_device *ibdev = ipoib->ibdev;
+ struct ipoib_mac *mac = ( ( struct ipoib_mac * ) netdev->ll_addr );
- /* Detach from broadcast multicast GID */
- ib_mcast_detach ( ibdev, ipoib->data.qp, &ipoib->broadcast_gid );
+ /* Leave broadcast group */
+ ipoib_leave_broadcast_group ( ipoib );
- /* FIXME: should probably flush the receive ring */
+ /* Remove data QPN from MAC address */
+ mac->qpn = 0;
+
+ /* Tear down the queues */
+ ipoib_destroy_qset ( ipoib, &ipoib->data );
+ ipoib_destroy_qset ( ipoib, &ipoib->meta );
}
/** IPoIB network device operations */
@@ -792,44 +906,61 @@ static struct net_device_operations ipoib_operations = {
};
/**
- * Join IPoIB broadcast group
+ * Update IPoIB dynamic Infiniband parameters
*
* @v ipoib IPoIB device
- * @ret rc Return status code
+ *
+ * The Infiniband port GID and partition key will change at runtime,
+ * when the link is established (or lost). The MAC address is based
+ * on the port GID, and the broadcast GID is based on the partition
+ * key. This function recalculates these IPoIB device parameters.
*/
-static int ipoib_join_broadcast_group ( struct ipoib_device *ipoib ) {
+static void ipoib_set_ib_params ( struct ipoib_device *ipoib ) {
struct ib_device *ibdev = ipoib->ibdev;
- unsigned int delay_ms;
- int rc;
+ struct net_device *netdev = ipoib->netdev;
+ struct ipoib_mac *mac;
- /* Make sure we have some receive descriptors */
- ipoib_refill_recv ( ipoib, &ipoib->meta );
+ /* Calculate GID portion of MAC address based on port GID */
+ mac = ( ( struct ipoib_mac * ) netdev->ll_addr );
+ memcpy ( &mac->gid, &ibdev->port_gid, sizeof ( mac->gid ) );
- /* Send join request */
- if ( ( rc = ipoib_mc_member_record ( ipoib, &ipoib->broadcast_gid,
- 1 ) ) != 0 ) {
- DBGC ( ipoib, "IPoIB %p could not send broadcast join: %s\n",
- ipoib, strerror ( rc ) );
- return rc;
+ /* Calculate broadcast GID based on partition key */
+ memcpy ( &ipoib->broadcast_gid, &ipv4_broadcast_gid,
+ sizeof ( ipoib->broadcast_gid ) );
+ ipoib->broadcast_gid.u.words[2] = htons ( ibdev->pkey );
+
+ /* Set net device link state to reflect Infiniband link state */
+ if ( ibdev->link_up ) {
+ netdev_link_up ( netdev );
+ } else {
+ netdev_link_down ( netdev );
}
+}
+
+/**
+ * Handle link status change
+ *
+ * @v ibdev Infiniband device
+ */
+void ipoib_link_state_changed ( struct ib_device *ibdev ) {
+ struct net_device *netdev = ib_get_ownerdata ( ibdev );
+ struct ipoib_device *ipoib = netdev->priv;
+ int rc;
- /* Wait for join to complete. Ideally we wouldn't delay for
- * this long, but we need the queue key before we can set up
- * the data queue pair, which we need before we can know the
- * MAC address.
+ /* Leave existing broadcast group */
+ ipoib_leave_broadcast_group ( ipoib );
+
+ /* Update MAC address and broadcast GID based on new port GID
+ * and partition key.
*/
- for ( delay_ms = IPOIB_JOIN_MAX_DELAY_MS ; delay_ms ; delay_ms-- ) {
- mdelay ( 1 );
- ib_poll_cq ( ibdev, ipoib->meta.cq, ipoib_meta_complete_send,
- ipoib_meta_complete_recv );
- ipoib_refill_recv ( ipoib, &ipoib->meta );
- if ( ipoib->broadcast_joined )
- return 0;
- }
- DBGC ( ipoib, "IPoIB %p timed out waiting for broadcast join\n",
- ipoib );
+ ipoib_set_ib_params ( ipoib );
- return -ETIMEDOUT;
+ /* Join new broadcast group */
+ if ( ( rc = ipoib_join_broadcast_group ( ipoib ) ) != 0 ) {
+ DBGC ( ipoib, "IPoIB %p could not rejoin broadcast group: "
+ "%s\n", ipoib, strerror ( rc ) );
+ return;
+ }
}
/**
@@ -841,7 +972,6 @@ static int ipoib_join_broadcast_group ( struct ipoib_device *ipoib ) {
int ipoib_probe ( struct ib_device *ibdev ) {
struct net_device *netdev;
struct ipoib_device *ipoib;
- struct ipoib_mac *mac;
int rc;
/* Allocate network device */
@@ -856,44 +986,11 @@ int ipoib_probe ( struct ib_device *ibdev ) {
ipoib->netdev = netdev;
ipoib->ibdev = ibdev;
- /* Calculate broadcast GID */
- memcpy ( &ipoib->broadcast_gid, &ipv4_broadcast_gid,
- sizeof ( ipoib->broadcast_gid ) );
- ipoib->broadcast_gid.u.words[2] = htons ( ibdev->pkey );
-
- /* Allocate metadata queue set */
- if ( ( rc = ipoib_create_qset ( ipoib, &ipoib->meta,
- IPOIB_META_NUM_CQES,
- IPOIB_META_NUM_SEND_WQES,
- IPOIB_META_NUM_RECV_WQES,
- IB_GLOBAL_QKEY ) ) != 0 ) {
- DBGC ( ipoib, "IPoIB %p could not allocate metadata QP: %s\n",
- ipoib, strerror ( rc ) );
- goto err_create_meta_qset;
- }
-
- /* Join broadcast group */
- if ( ( rc = ipoib_join_broadcast_group ( ipoib ) ) != 0 ) {
- DBGC ( ipoib, "IPoIB %p could not join broadcast group: %s\n",
- ipoib, strerror ( rc ) );
- goto err_join_broadcast_group;
- }
-
- /* Allocate data queue set */
- if ( ( rc = ipoib_create_qset ( ipoib, &ipoib->data,
- IPOIB_DATA_NUM_CQES,
- IPOIB_DATA_NUM_SEND_WQES,
- IPOIB_DATA_NUM_RECV_WQES,
- ipoib->data_qkey ) ) != 0 ) {
- DBGC ( ipoib, "IPoIB %p could not allocate data QP: %s\n",
- ipoib, strerror ( rc ) );
- goto err_create_data_qset;
- }
-
- /* Construct MAC address */
- mac = ( ( struct ipoib_mac * ) netdev->ll_addr );
- mac->qpn = htonl ( ipoib->data.qp->qpn );
- memcpy ( &mac->gid, &ibdev->port_gid, sizeof ( mac->gid ) );
+ /* Calculate as much of the broadcast GID and the MAC address
+ * as we can. We won't know either of these in full until we
+ * have link-up.
+ */
+ ipoib_set_ib_params ( ipoib );
/* Register network device */
if ( ( rc = register_netdev ( netdev ) ) != 0 )
@@ -902,11 +999,6 @@ int ipoib_probe ( struct ib_device *ibdev ) {
return 0;
err_register_netdev:
- ipoib_destroy_qset ( ipoib, &ipoib->data );
- err_join_broadcast_group:
- err_create_data_qset:
- ipoib_destroy_qset ( ipoib, &ipoib->meta );
- err_create_meta_qset:
netdev_nullify ( netdev );
netdev_put ( netdev );
return rc;
@@ -919,11 +1011,8 @@ int ipoib_probe ( struct ib_device *ibdev ) {
*/
void ipoib_remove ( struct ib_device *ibdev ) {
struct net_device *netdev = ib_get_ownerdata ( ibdev );
- struct ipoib_device *ipoib = netdev->priv;
unregister_netdev ( netdev );
- ipoib_destroy_qset ( ipoib, &ipoib->data );
- ipoib_destroy_qset ( ipoib, &ipoib->meta );
netdev_nullify ( netdev );
netdev_put ( netdev );
}
diff --git a/gpxe/src/drivers/net/legacy.c b/gpxe/src/drivers/net/legacy.c
index 32460adb..cbec3cf5 100644
--- a/gpxe/src/drivers/net/legacy.c
+++ b/gpxe/src/drivers/net/legacy.c
@@ -112,6 +112,9 @@ int legacy_probe ( void *hwdev,
*/
dev->desc.irq = nic.irqno;
+ /* Mark as link up; legacy devices don't handle link state */
+ netdev_link_up ( netdev );
+
if ( ( rc = register_netdev ( netdev ) ) != 0 )
goto err_register;
diff --git a/gpxe/src/drivers/net/mlx_ipoib/mt23108.c b/gpxe/src/drivers/net/mlx_ipoib/mt23108.c
index 492bc901..e1f61db6 100644
--- a/gpxe/src/drivers/net/mlx_ipoib/mt23108.c
+++ b/gpxe/src/drivers/net/mlx_ipoib/mt23108.c
@@ -10,6 +10,8 @@ Skeleton NIC driver for Etherboot
* your option) any later version.
*/
+/* to get toupper() */
+#include <ctype.h>
/* to get some global routines like printf */
#include "etherboot.h"
/* to get the interface to the body of the program */
@@ -31,12 +33,7 @@ int prompt_key(int secs, unsigned char *ch_p)
for (tmo = currticks() + secs * TICKS_PER_SEC; currticks() < tmo;) {
if (iskey()) {
- ch = getchar();
- /* toupper does not work ... */
- if (ch == 'v')
- ch = 'V';
- if (ch == 'i')
- ch = 'I';
+ ch = toupper(getchar());
if ((ch=='V') || (ch=='I')) {
*ch_p = ch;
return 1;
diff --git a/gpxe/src/drivers/net/mlx_ipoib/mt25218.c b/gpxe/src/drivers/net/mlx_ipoib/mt25218.c
index a603cdeb..8a252eae 100644
--- a/gpxe/src/drivers/net/mlx_ipoib/mt25218.c
+++ b/gpxe/src/drivers/net/mlx_ipoib/mt25218.c
@@ -10,6 +10,8 @@ Skeleton NIC driver for Etherboot
* your option) any later version.
*/
+/* to get toupper() */
+#include <ctype.h>
/* to get some global routines like printf */
#include "etherboot.h"
/* to get the interface to the body of the program */
@@ -31,12 +33,7 @@ int prompt_key(int secs, unsigned char *ch_p)
for (tmo = currticks() + secs * TICKS_PER_SEC; currticks() < tmo;) {
if (iskey()) {
- ch = getchar();
- /* toupper does not work ... */
- if (ch == 'v')
- ch = 'V';
- if (ch == 'i')
- ch = 'I';
+ ch = toupper(getchar());
if ((ch=='V') || (ch=='I')) {
*ch_p = ch;
return 1;
diff --git a/gpxe/src/drivers/net/mtnic.c b/gpxe/src/drivers/net/mtnic.c
index 536fcb8d..dd577f4a 100755
--- a/gpxe/src/drivers/net/mtnic.c
+++ b/gpxe/src/drivers/net/mtnic.c
@@ -35,8 +35,7 @@
#include <errno.h>
#include <gpxe/malloc.h>
#include <gpxe/umalloc.h>
-#include <bits/byteswap.h>
-#include <little_bswap.h>
+#include <byteswap.h>
#include <unistd.h>
#include <gpxe/pci.h>
#include <gpxe/ethernet.h>
@@ -54,6 +53,10 @@
*/
+/* (mcb30) - The Mellanox driver used "1" as a universal error code;
+ * this at least makes it a valid error number.
+ */
+#define MTNIC_ERROR -EIO
/** Set port number to use
@@ -108,12 +111,12 @@ mtnic_alloc_cmdif(struct mtnic_priv *priv)
priv->hcr = ioremap(bar + MTNIC_HCR_BASE, MTNIC_HCR_SIZE);
if (!priv->hcr) {
- eprintf("Couldn't map command register.");
+ DBG("Couldn't map command register.");
return MTNIC_ERROR;
}
mtnic_alloc_aligned(PAGE_SIZE, (void *)&priv->cmd.buf, &priv->cmd.mapping, PAGE_SIZE);
if (!priv->cmd.buf) {
- eprintf("Error in allocating buffer for command interface\n");
+ DBG("Error in allocating buffer for command interface\n");
return MTNIC_ERROR;
}
return 0;
@@ -153,8 +156,8 @@ mtnic_alloc_iobuf(struct mtnic_priv *priv, struct mtnic_ring *ring,
ring->iobuf[index] = alloc_iob(size);
if (!&ring->iobuf[index]) {
if (ring->prod <= (ring->cons + 1)) {
- eprintf("Error allocating Rx io "
- "buffer number %lx", index);
+ DBG("Error allocating Rx io "
+ "buffer number %lx", index);
/* In case of error freeing io buffer */
mtnic_free_io_buffers(ring);
return MTNIC_ERROR;
@@ -208,8 +211,8 @@ mtnic_alloc_ring(struct mtnic_priv *priv, struct mtnic_ring *ring,
err = mtnic_alloc_aligned(ring->buf_size, (void *)&ring->buf,
&ring->dma, PAGE_SIZE);
if (err) {
- eprintf("Failed allocating descriptor ring sizeof %lx\n",
- ring->buf_size);
+ DBG("Failed allocating descriptor ring sizeof %lx\n",
+ ring->buf_size);
return MTNIC_ERROR;
}
memset(ring->buf, 0, ring->buf_size);
@@ -225,7 +228,7 @@ mtnic_alloc_ring(struct mtnic_priv *priv, struct mtnic_ring *ring,
err = mtnic_alloc_aligned(sizeof(struct mtnic_cq_db_record),
(void *)&ring->db, &ring->db_dma, 32);
if (err) {
- eprintf("Failed allocating Rx ring doorbell record\n");
+ DBG("Failed allocating Rx ring doorbell record\n");
free(ring->buf);
return MTNIC_ERROR;
}
@@ -243,7 +246,7 @@ mtnic_alloc_ring(struct mtnic_priv *priv, struct mtnic_ring *ring,
/* Alloc IO_BUFFERS */
err = mtnic_alloc_iobuf(priv, ring, DEF_IOBUF_SIZE);
if (err) {
- eprintf("ERROR Allocating io buffer");
+ DBG("ERROR Allocating io buffer");
free(ring->buf);
return MTNIC_ERROR;
}
@@ -260,11 +263,11 @@ mtnic_alloc_ring(struct mtnic_priv *priv, struct mtnic_ring *ring,
/* Map Tx+CQ doorbells */
DBG("Mapping TxCQ doorbell at offset:0x%lx\n",
- priv->fw.txcq_db_offset);
+ priv->fw.txcq_db_offset);
ring->txcq_db = ioremap(mtnic_pci_dev.dev.bar[2] +
priv->fw.txcq_db_offset, PAGE_SIZE);
if (!ring->txcq_db) {
- eprintf("Couldn't map txcq doorbell, aborting...\n");
+ DBG("Couldn't map txcq doorbell, aborting...\n");
free(ring->buf);
return MTNIC_ERROR;
}
@@ -299,7 +302,7 @@ mtnic_alloc_cq(struct net_device *dev, int num, struct mtnic_cq *cq,
err = mtnic_alloc_aligned(sizeof(struct mtnic_cq_db_record),
(void *)&cq->db, &cq->db_dma, 32);
if (err) {
- eprintf("Failed allocating CQ doorbell record\n");
+ DBG("Failed allocating CQ doorbell record\n");
return MTNIC_ERROR;
}
memset(cq->db, 0, sizeof(struct mtnic_cq_db_record));
@@ -309,16 +312,16 @@ mtnic_alloc_cq(struct net_device *dev, int num, struct mtnic_cq *cq,
err = mtnic_alloc_aligned(cq->buf_size,
(void *)&cq->buf, &cq->dma, PAGE_SIZE);
if (err) {
- eprintf("Failed allocating CQ buffer\n");
+ DBG("Failed allocating CQ buffer\n");
free(cq->db);
return MTNIC_ERROR;
}
memset(cq->buf, 0, cq->buf_size);
DBG("Allocated CQ (addr:%p) - size:%lx buf:%p buf_size:%lx "
- "dma:%lx db:%p db_dma:%lx\n"
- "cqn offset:%lx \n", cq, cq->size, cq->buf,
- cq->buf_size, cq->dma, cq->db,
- cq->db_dma, offset_ind);
+ "dma:%lx db:%p db_dma:%lx\n"
+ "cqn offset:%lx \n", cq, cq->size, cq->buf,
+ cq->buf_size, cq->dma, cq->db,
+ cq->db_dma, offset_ind);
/* Set ownership of all CQEs to HW */
@@ -349,7 +352,7 @@ mtnic_alloc_resources(struct net_device *dev)
err = mtnic_alloc_cq(dev, cq_ind, &priv->cq[cq_ind], 1 /* RX */,
UNITS_BUFFER_SIZE, cq_offset + cq_ind);
if (err) {
- eprintf("Failed allocating Rx CQ\n");
+ DBG("Failed allocating Rx CQ\n");
return MTNIC_ERROR;
}
@@ -357,7 +360,7 @@ mtnic_alloc_resources(struct net_device *dev)
err = mtnic_alloc_ring(priv, &priv->rx_ring, UNITS_BUFFER_SIZE,
sizeof(struct mtnic_rx_desc), cq_ind, /* RX */1);
if (err) {
- eprintf("Failed allocating Rx Ring\n");
+ DBG("Failed allocating Rx Ring\n");
goto cq0_error;
}
@@ -367,7 +370,7 @@ mtnic_alloc_resources(struct net_device *dev)
err = mtnic_alloc_cq(dev, cq_ind, &priv->cq[cq_ind], 0 /* TX */,
UNITS_BUFFER_SIZE, cq_offset + cq_ind);
if (err) {
- eprintf("Failed allocating Tx CQ\n");
+ DBG("Failed allocating Tx CQ\n");
goto rx_error;
}
@@ -375,7 +378,7 @@ mtnic_alloc_resources(struct net_device *dev)
err = mtnic_alloc_ring(priv, &priv->tx_ring, UNITS_BUFFER_SIZE,
sizeof(struct mtnic_tx_desc), cq_ind, /* TX */ 0);
if (err) {
- eprintf("Failed allocating Tx ring\n");
+ DBG("Failed allocating Tx ring\n");
goto cq1_error;
}
@@ -412,7 +415,7 @@ mtnic_alloc_eq(struct mtnic_priv *priv)
priv->eq_db = ioremap(mtnic_pci_dev.dev.bar[2] +
priv->fw.eq_db_offset, sizeof(u32));
if (!priv->eq_db) {
- eprintf("Couldn't map EQ doorbell, aborting...\n");
+ DBG("Couldn't map EQ doorbell, aborting...\n");
return MTNIC_ERROR;
}
@@ -422,7 +425,7 @@ mtnic_alloc_eq(struct mtnic_priv *priv)
err = mtnic_alloc_aligned(priv->eq.buf_size, (void *)&priv->eq.buf,
&priv->eq.dma, PAGE_SIZE);
if (err) {
- eprintf("Failed allocating EQ buffer\n");
+ DBG("Failed allocating EQ buffer\n");
iounmap(priv->eq_db);
return MTNIC_ERROR;
}
@@ -470,7 +473,7 @@ cmdif_go_bit(struct mtnic_priv *priv)
}
}
- eprintf("Invalid tbit after %d retries!\n", TBIT_RETRIES);
+ DBG("Invalid tbit after %d retries!\n", TBIT_RETRIES);
return 1; /* Return busy... */
}
@@ -495,7 +498,7 @@ mtnic_cmd(struct mtnic_priv *priv, void *in_imm,
token++;
if (cmdif_go_bit(priv)) {
- eprintf("GO BIT BUSY:%p.\n", hcr + 6);
+ DBG("GO BIT BUSY:%p.\n", hcr + 6);
err = MTNIC_ERROR;
goto out;
}
@@ -529,7 +532,7 @@ mtnic_cmd(struct mtnic_priv *priv, void *in_imm,
}
if (cmdif_go_bit(priv)) {
- eprintf("Command opcode:0x%x token:0x%x TIMEOUT.\n", op, token);
+ DBG("Command opcode:0x%x token:0x%x TIMEOUT.\n", op, token);
err = MTNIC_ERROR;
goto out;
}
@@ -570,8 +573,8 @@ mtnic_map_cmd(struct mtnic_priv *priv, u16 op, struct mtnic_pages pages)
DBG("Mapping pages: size: %lx address: %p\n", pages.num, pages.buf);
if (addr & (PAGE_MASK)) {
- eprintf("Got FW area not aligned to %d (%llx/%x)\n",
- PAGE_SIZE, (u64) addr, len);
+ DBG("Got FW area not aligned to %d (%llx/%x)\n",
+ PAGE_SIZE, (u64) addr, len);
return MTNIC_ERROR;
}
@@ -687,7 +690,7 @@ mtnic_HEART_BEAT(struct mtnic_priv *priv, u32 *link_state)
if (!err) {
flags = be32_to_cpu(heart_beat.flags);
if (flags & MTNIC_BC_MASK(MTNIC_MASK_HEAR_BEAT_INT_ERROR)) {
- eprintf("Internal error detected\n");
+ DBG("Internal error detected\n");
return MTNIC_ERROR;
}
*link_state = flags &
@@ -746,9 +749,9 @@ mtnic_CONFIG_CQ(struct mtnic_priv *priv, int port,
config_cq->db_record_addr_l = cpu_to_be32(cq->db_dma);
config_cq->page_address[1] = cpu_to_be32(cq->dma);
DBG("config cq address: %lx dma_address: %lx"
- "offset: %d size %d index: %d "
- , config_cq->page_address[1],cq->dma,
- config_cq->offset, config_cq->size, config_cq->cq );
+ "offset: %d size %d index: %d "
+ , config_cq->page_address[1],cq->dma,
+ config_cq->offset, config_cq->size, config_cq->cq );
return mtnic_cmd(priv, NULL, NULL, port + 1,
MTNIC_IF_CMD_CONFIG_CQ);
@@ -798,8 +801,8 @@ mtnic_CONFIG_EQ(struct mtnic_priv *priv)
struct mtnic_if_config_eq_in_mbox *eq = priv->cmd.buf;
if (priv->eq.dma & (PAGE_MASK)) {
- eprintf("misalligned eq buffer:%lx\n",
- priv->eq.dma);
+ DBG("misalligned eq buffer:%lx\n",
+ priv->eq.dma);
return MTNIC_ERROR;
}
@@ -897,7 +900,7 @@ mtnic_QUERY_CAP(struct mtnic_priv *priv, u8 index, u8 mod, u64 *result)
*((u32*)result + 1) = be32_to_cpu(*out_imm);
DBG("Called Query cap with index:0x%x mod:%d result:0x%llx"
- " error:%d\n", index, mod, *result, err);
+ " error:%d\n", index, mod, *result, err);
return err;
}
@@ -1028,7 +1031,7 @@ mtnic_init_pci(struct pci_device *dev)
&mtnic_pci_dev.dev.
dev_config_space[i]);
if (err) {
- eprintf("Can not save configuration space");
+ DBG("Can not save configuration space");
return err;
}
}
@@ -1056,7 +1059,7 @@ int mtnic_init_card(struct net_device *dev)
/* Alloc command interface */
err = mtnic_alloc_cmdif(priv);
if (err) {
- eprintf("Failed to init command interface, aborting.\n");
+ DBG("Failed to init command interface, aborting.\n");
return MTNIC_ERROR;
}
@@ -1067,7 +1070,7 @@ int mtnic_init_card(struct net_device *dev)
*/
err = mtnic_QUERY_FW(priv);
if (err) {
- eprintf("QUERY_FW command failed, aborting.\n");
+ DBG("QUERY_FW command failed, aborting.\n");
goto cmd_error;
}
@@ -1076,7 +1079,7 @@ int mtnic_init_card(struct net_device *dev)
/* Allocate memory for FW and start it */
err = mtnic_map_cmd(priv, MTNIC_IF_CMD_MAP_FW, priv->fw.fw_pages);
if (err) {
- eprintf("Eror In MAP_FW\n");
+ DBG("Eror In MAP_FW\n");
if (priv->fw.fw_pages.buf)
free(priv->fw.fw_pages.buf);
goto cmd_error;
@@ -1085,12 +1088,12 @@ int mtnic_init_card(struct net_device *dev)
/* Run firmware */
err = mtnic_cmd(priv, NULL, NULL, 0, MTNIC_IF_CMD_RUN_FW);
if (err) {
- eprintf("Eror In RUN FW\n");
+ DBG("Eror In RUN FW\n");
goto map_fw_error;
}
DBG("FW version:%d.%d.%d\n",
- (u16) (priv->fw_ver >> 32),
+ (u16) (priv->fw_ver >> 32),
(u16) ((priv->fw_ver >> 16) & 0xffff),
(u16) (priv->fw_ver & 0xffff));
@@ -1098,22 +1101,22 @@ int mtnic_init_card(struct net_device *dev)
/* Get device information */
err = mtnic_query_cap(priv);
if (err) {
- eprintf("Insufficient resources, aborting.\n");
+ DBG("Insufficient resources, aborting.\n");
goto map_fw_error;
}
/* Open NIC */
err = mtnic_OPEN_NIC(priv);
if (err) {
- eprintf("Failed opening NIC, aborting.\n");
+ DBG("Failed opening NIC, aborting.\n");
goto map_fw_error;
}
/* Allocate and map pages worksace */
err = mtnic_map_cmd(priv, MTNIC_IF_CMD_MAP_PAGES, priv->fw.extra_pages);
if (err) {
- eprintf("Couldn't allocate %lx FW extra pages, aborting.\n",
- priv->fw.extra_pages.num);
+ DBG("Couldn't allocate %lx FW extra pages, aborting.\n",
+ priv->fw.extra_pages.num);
if (priv->fw.extra_pages.buf)
free(priv->fw.extra_pages.buf);
goto map_fw_error;
@@ -1122,7 +1125,7 @@ int mtnic_init_card(struct net_device *dev)
/* Get device offsets */
err = mtnic_query_offsets(priv);
if (err) {
- eprintf("Failed retrieving resource offests, aborting.\n");
+ DBG("Failed retrieving resource offests, aborting.\n");
free(priv->fw.extra_pages.buf);
goto map_extra_error;
}
@@ -1131,24 +1134,24 @@ int mtnic_init_card(struct net_device *dev)
/* Alloc EQ */
err = mtnic_alloc_eq(priv);
if (err) {
- eprintf("Failed init shared resources. error: %d\n", err);
+ DBG("Failed init shared resources. error: %d\n", err);
goto map_extra_error;
}
/* Configure HW */
err = mtnic_CONFIG_EQ(priv);
if (err) {
- eprintf("Failed configuring EQ\n");
+ DBG("Failed configuring EQ\n");
goto eq_error;
}
err = mtnic_CONFIG_RX(priv);
if (err) {
- eprintf("Failed Rx configuration\n");
+ DBG("Failed Rx configuration\n");
goto eq_error;
}
err = mtnic_CONFIG_TX(priv);
if (err) {
- eprintf("Failed Tx configuration\n");
+ DBG("Failed Tx configuration\n");
goto eq_error;
}
@@ -1270,7 +1273,7 @@ next:
if (ring->prod - ring->cons < (MAX_GAP_PROD_CONS)) {
err = mtnic_alloc_iobuf(priv, &priv->rx_ring, DEF_IOBUF_SIZE);
if (err) {
- eprintf("ERROR Allocating io buffer");
+ DBG("ERROR Allocating io buffer");
return MTNIC_ERROR;
}
}
@@ -1316,7 +1319,7 @@ mtnic_open(struct net_device *dev)
/* Alloc and configure CQs, TX, RX */
err = mtnic_alloc_resources(dev);
if (err) {
- eprintf("Error allocating resources\n");
+ DBG("Error allocating resources\n");
return MTNIC_ERROR;
}
@@ -1325,8 +1328,8 @@ mtnic_open(struct net_device *dev)
cq = &priv->cq[cq_ind];
err = mtnic_CONFIG_CQ(priv, priv->port, cq_ind, cq);
if (err) {
- eprintf("Failed configuring CQ:%d error %d\n",
- cq_ind, err);
+ DBG("Failed configuring CQ:%d error %d\n",
+ cq_ind, err);
if (cq_ind)
goto cq_error;
else
@@ -1341,7 +1344,7 @@ mtnic_open(struct net_device *dev)
ring = &priv->tx_ring;
err = mtnic_CONFIG_TX_RING(priv, priv->port, 0, ring);
if (err) {
- eprintf("Failed configuring Tx ring:0\n");
+ DBG("Failed configuring Tx ring:0\n");
goto cq_error;
}
@@ -1349,7 +1352,7 @@ mtnic_open(struct net_device *dev)
ring = &priv->rx_ring;
err = mtnic_CONFIG_RX_RING(priv, priv->port, 0, ring);
if (err) {
- eprintf("Failed configuring Rx ring:0\n");
+ DBG("Failed configuring Rx ring:0\n");
goto tx_error;
}
@@ -1358,42 +1361,42 @@ mtnic_open(struct net_device *dev)
if (!err)
err = mtnic_SET_PORT_RSS_INDIRECTION(priv, priv->port);
if (err) {
- eprintf("Failed configuring RSS steering\n");
+ DBG("Failed configuring RSS steering\n");
goto rx_error;
}
/* Set the port default ring to ring 0 */
err = mtnic_SET_PORT_DEFAULT_RING(priv, priv->port, 0);
if (err) {
- eprintf("Failed setting default ring\n");
+ DBG("Failed setting default ring\n");
goto rx_error;
}
/* Set Mac address */
err = mtnic_SET_RX_RING_ADDR(priv, priv->port, &priv->fw.mac[priv->port]);
if (err) {
- eprintf("Failed setting default MAC address\n");
+ DBG("Failed setting default MAC address\n");
goto rx_error;
}
/* Set MTU */
err = mtnic_SET_PORT_MTU(priv, priv->port, DEF_MTU);
if (err) {
- eprintf("Failed setting MTU\n");
+ DBG("Failed setting MTU\n");
goto rx_error;
}
/* Configure VLAN filter */
err = mtnic_CONFIG_PORT_VLAN_FILTER(priv, priv->port);
if (err) {
- eprintf("Failed configuring VLAN filter\n");
+ DBG("Failed configuring VLAN filter\n");
goto rx_error;
}
/* Bring up physical link */
err = mtnic_SET_PORT_STATE(priv, priv->port, 1);
if (err) {
- eprintf("Failed bringing up port\n");
+ DBG("Failed bringing up port\n");
goto rx_error;
}
mdelay(300); /* Let link state stabilize if cable was connected */
@@ -1402,11 +1405,11 @@ mtnic_open(struct net_device *dev)
err = mtnic_HEART_BEAT(priv, &dev_link_state);
if (err) {
- eprintf("Failed getting device link state\n");
+ DBG("Failed getting device link state\n");
return MTNIC_ERROR;
}
if (!(dev_link_state & 0x3)) {
- eprintf("Link down, check cables and restart\n");
+ DBG("Link down, check cables and restart\n");
return MTNIC_ERROR;
}
@@ -1453,12 +1456,12 @@ mtnic_poll(struct net_device *dev)
/* Check device */
err = mtnic_HEART_BEAT(priv, &dev_link_state);
if (err) {
- eprintf("Device has internal error\n");
+ DBG("Device has internal error\n");
priv->state = CARD_DOWN;
return;
}
if (!(dev_link_state & 0x3)) {
- eprintf("Link down, check cables and restart\n");
+ DBG("Link down, check cables and restart\n");
priv->state = CARD_DOWN;
return;
}
@@ -1472,7 +1475,7 @@ mtnic_poll(struct net_device *dev)
err = mtnic_process_rx_cq(priv, cq->dev, cq);
if (err) {
priv->state = CARD_DOWN;
- eprintf(" Error allocating RX buffers\n");
+ DBG(" Error allocating RX buffers\n");
return;
}
} else {
@@ -1664,17 +1667,11 @@ mtnic_probe(struct pci_device *pci,
void *dev_id;
int i;
- if (pci->vendor != MELLANOX_VENDOR_ID) {
- eprintf("");
- return 0;
- }
- printf("\nMellanox Technologies LTD - Boot over MTNIC implementaion\n");
-
adjust_pci_device(pci);
err = mtnic_init_pci(pci);
if (err) {
- eprintf("Error in pci_init\n");
+ DBG("Error in pci_init\n");
return MTNIC_ERROR;
}
@@ -1683,7 +1680,7 @@ mtnic_probe(struct pci_device *pci,
err = restore_config();
if (err) {
- eprintf("");
+ DBG("Error restoring config\n");
return err;
}
@@ -1693,14 +1690,14 @@ mtnic_probe(struct pci_device *pci,
result = ntohl(readl(dev_id));
iounmap(dev_id);
if (result != MTNIC_DEVICE_ID) {
- eprintf("Wrong Devie ID (0x%lx) !!!", result);
+ DBG("Wrong Devie ID (0x%lx) !!!", result);
return MTNIC_ERROR;
}
/* Initializing net device */
dev = alloc_etherdev(sizeof(struct mtnic_priv));
if (dev == NULL) {
- eprintf("Net device allocation failed\n");
+ DBG("Net device allocation failed\n");
return MTNIC_ERROR;
}
/*
@@ -1719,7 +1716,7 @@ mtnic_probe(struct pci_device *pci,
/* Initialize hardware */
err = mtnic_init_card(dev);
if (err) {
- eprintf("Error in init_card\n");
+ DBG("Error in init_card\n");
return MTNIC_ERROR;
}
@@ -1731,8 +1728,11 @@ mtnic_probe(struct pci_device *pci,
mac = mac >> 8;
}
+ /* Mark as link up; we don't yet handle link state */
+ netdev_link_up ( dev );
+
if (register_netdev(dev)) {
- eprintf("Netdev registration failed\n");
+ DBG("Netdev registration failed\n");
return MTNIC_ERROR;
}
diff --git a/gpxe/src/drivers/net/mtnic.h b/gpxe/src/drivers/net/mtnic.h
index f1d481ce..70a238e5 100755
--- a/gpxe/src/drivers/net/mtnic.h
+++ b/gpxe/src/drivers/net/mtnic.h
@@ -57,19 +57,11 @@
#define ROUND_TO_CHECK 0x400
-/*
-* Helper macros
-*/
-/* Print in case of an error */
-#define eprintf(fmt, a...) \
- printf("%s:%d: " fmt "\n", __func__, __LINE__, ##a)
-
#define XNOR(x,y) (!(x) == !(y))
#define dma_addr_t unsigned long
#define PAGE_SIZE 4096
#define PAGE_MASK (PAGE_SIZE - 1)
#define MTNIC_MAILBOX_SIZE PAGE_SIZE
-#define MTNIC_ERROR 1
diff --git a/gpxe/src/drivers/net/natsemi.c b/gpxe/src/drivers/net/natsemi.c
index 98a5ff84..028b905c 100644
--- a/gpxe/src/drivers/net/natsemi.c
+++ b/gpxe/src/drivers/net/natsemi.c
@@ -205,6 +205,9 @@ static int natsemi_probe (struct pci_device *pci,
last = last1;
}
+ /* Mark as link up; we don't yet handle link state */
+ netdev_link_up ( netdev );
+
if ((rc = register_netdev (netdev)) != 0)
goto err_register_netdev;
diff --git a/gpxe/src/drivers/net/pnic.c b/gpxe/src/drivers/net/pnic.c
index b431ec52..c7f08670 100644
--- a/gpxe/src/drivers/net/pnic.c
+++ b/gpxe/src/drivers/net/pnic.c
@@ -250,6 +250,9 @@ static int pnic_probe ( struct pci_device *pci,
status = pnic_command ( pnic, PNIC_CMD_READ_MAC, NULL, 0,
netdev->ll_addr, ETH_ALEN, NULL );
+ /* Mark as link up; PNIC has no concept of link state */
+ netdev_link_up ( netdev );
+
/* Register network device */
if ( ( rc = register_netdev ( netdev ) ) != 0 )
goto err;
diff --git a/gpxe/src/drivers/net/r8169.c b/gpxe/src/drivers/net/r8169.c
index ab9a30f8..885f054a 100644
--- a/gpxe/src/drivers/net/r8169.c
+++ b/gpxe/src/drivers/net/r8169.c
@@ -40,6 +40,9 @@
* v1.5 01-17-2004 timlegge Initial driver output cleanup
* v1.6 03-27-2004 timlegge Additional Cleanup
* v1.7 11-22-2005 timlegge Update to RealTek Driver Version 2.2
+*
+* 03-19-2008 Hilko Bengen Cleanups and fixes for newer cards
+* (successfully tested with 8110SC-d onboard NIC)
*
* Indent Options: indent -kr -i8
***************************************************************************/
@@ -50,8 +53,8 @@
#include <gpxe/ethernet.h>
#include <gpxe/malloc.h>
-#define drv_version "v1.6"
-#define drv_date "03-27-2004"
+#define drv_version "v1.7+"
+#define drv_date "03-19-2008"
#define HZ 1000
@@ -72,16 +75,6 @@ static u32 ioaddr;
#undef RTL8169_DYNAMIC_CONTROL
#define RTL8169_USE_IO
-
-/* media options
- _10_Half = 0x01,
- _10_Full = 0x02,
- _100_Half = 0x04,
- _100_Full = 0x08,
- _1000_Full = 0x10,
-*/
-static int media = -1;
-
#if 0
/* Maximum events (Rx packets, etc.) to handle at each interrupt. */
static int max_interrupt_work = 20;
@@ -148,29 +141,59 @@ static int multicast_filter_limit = 32;
#define RTL_R32(reg) ((unsigned long) readl (ioaddr + (reg)))
#endif
-#define MCFG_METHOD_1 0x01
-#define MCFG_METHOD_2 0x02
-#define MCFG_METHOD_3 0x03
-#define MCFG_METHOD_4 0x04
+enum mac_version {
+ RTL_GIGA_MAC_VER_01 = 0x01, // 8169
+ RTL_GIGA_MAC_VER_02 = 0x02, // 8169S
+ RTL_GIGA_MAC_VER_03 = 0x03, // 8110S
+ RTL_GIGA_MAC_VER_04 = 0x04, // 8169SB
+ RTL_GIGA_MAC_VER_05 = 0x05, // 8110SCd
+ RTL_GIGA_MAC_VER_06 = 0x06, // 8110SCe
+ RTL_GIGA_MAC_VER_11 = 0x0b, // 8168Bb
+ RTL_GIGA_MAC_VER_12 = 0x0c, // 8168Be
+ RTL_GIGA_MAC_VER_13 = 0x0d, // 8101Eb
+ RTL_GIGA_MAC_VER_14 = 0x0e, // 8101 ?
+ RTL_GIGA_MAC_VER_15 = 0x0f, // 8101 ?
+ RTL_GIGA_MAC_VER_16 = 0x11, // 8101Ec
+ RTL_GIGA_MAC_VER_17 = 0x10, // 8168Bf
+ RTL_GIGA_MAC_VER_18 = 0x12, // 8168CP
+ RTL_GIGA_MAC_VER_19 = 0x13, // 8168C
+ RTL_GIGA_MAC_VER_20 = 0x14 // 8168C
+};
-#define PCFG_METHOD_1 0x01 //PHY Reg 0x03 bit0-3 == 0x0000
-#define PCFG_METHOD_2 0x02 //PHY Reg 0x03 bit0-3 == 0x0001
-#define PCFG_METHOD_3 0x03 //PHY Reg 0x03 bit0-3 == 0x0002
+enum cfg_version {
+ RTL_CFG_0 = 0x00,
+ RTL_CFG_1,
+ RTL_CFG_2
+};
static struct {
const char *name;
- u8 mcfg; /* depend on RTL8169 docs */
+ u8 mac_version; /* depend on RTL8169 docs */
u32 RxConfigMask; /* should clear the bits supported by this chip */
} rtl_chip_info[] = {
- {
- "RTL-8169", MCFG_METHOD_1, 0xff7e1880,}, {
- "RTL8169s/8110s", MCFG_METHOD_2, 0xff7e1880}, {
-"RTL8169s/8110s", MCFG_METHOD_3, 0xff7e1880},};
+ {"RTL8169", RTL_GIGA_MAC_VER_01, 0xff7e1880}, // 8169
+ {"RTL8169s", RTL_GIGA_MAC_VER_02, 0xff7e1880}, // 8169S
+ {"RTL8110s", RTL_GIGA_MAC_VER_03, 0xff7e1880}, // 8110S
+ {"RTL8169sb/8110sb", RTL_GIGA_MAC_VER_04, 0xff7e1880}, // 8169SB
+ {"RTL8169sc/8110sc-d",RTL_GIGA_MAC_VER_05, 0xff7e1880}, // 8110SCd
+ {"RTL8169sc/8110sc-e",RTL_GIGA_MAC_VER_06, 0xff7e1880}, // 8110SCe
+ {"RTL8168b/8111b", RTL_GIGA_MAC_VER_11, 0xff7e1880}, // PCI-E
+ {"RTL8168b/8111b", RTL_GIGA_MAC_VER_12, 0xff7e1880}, // PCI-E
+ {"RTL8101e", RTL_GIGA_MAC_VER_13, 0xff7e1880}, // PCI-E 8139
+ {"RTL8100e", RTL_GIGA_MAC_VER_14, 0xff7e1880}, // PCI-E 8139
+ {"RTL8100e", RTL_GIGA_MAC_VER_15, 0xff7e1880}, // PCI-E 8139
+ {"RTL8168b/8111b", RTL_GIGA_MAC_VER_17, 0xff7e1880}, // PCI-E
+ {"RTL8101e", RTL_GIGA_MAC_VER_16, 0xff7e1880}, // PCI-E
+ {"RTL8168cp/8111cp", RTL_GIGA_MAC_VER_18, 0xff7e1880}, // PCI-E
+ {"RTL8168c/8111c", RTL_GIGA_MAC_VER_19, 0xff7e1880}, // PCI-E
+ {"RTL8168c/8111c", RTL_GIGA_MAC_VER_20, 0xff7e1880}, // PCI-E
+};
enum RTL8169_registers {
MAC0 = 0x0, /* Ethernet hardware address. */
MAR0 = 0x8, /* Multicast filter. */
- TxDescStartAddr = 0x20,
+ TxDescAddrLow = 0x20,
+ TxDescAddrHigh = 0x24,
TxHDescStartAddr = 0x28,
FLASH = 0x30,
ERSR = 0x36,
@@ -194,9 +217,11 @@ enum RTL8169_registers {
TBI_ANAR = 0x68,
TBI_LPAR = 0x6A,
PHYstatus = 0x6C,
- RxMaxSize = 0xDA,
- CPlusCmd = 0xE0,
- RxDescStartAddr = 0xE4,
+ RxMaxSize = 0xda,
+ CPlusCmd = 0xe0,
+ IntrMitigate = 0xe2,
+ RxDescAddrLow = 0xe4,
+ RxDescAddrHigh = 0xe8,
ETThReg = 0xEC,
FuncEvent = 0xF0,
FuncEventMask = 0xF4,
@@ -345,7 +370,7 @@ static struct rtl8169_private {
void *mmio_addr; /* memory map physical address */
int chipset;
int pcfg;
- int mcfg;
+ int mac_version;
unsigned long cur_rx; /* Index into the Rx descriptor buffer of next Rx pkt. */
unsigned long cur_tx; /* Index into the Tx descriptor buffer of next Rx pkt. */
struct TxDesc *TxDescArray; /* Index of 256-alignment Tx Descriptor buffer */
@@ -354,16 +379,14 @@ static struct rtl8169_private {
unsigned char *Tx_skbuff[NUM_TX_DESC];
} tpx;
-static struct rtl8169_private *tpc;
-
static const u16 rtl8169_intr_mask =
LinkChg | RxOverflow | RxFIFOOver | TxErr | TxOK | RxErr | RxOK;
static const unsigned int rtl8169_rx_config =
(RX_FIFO_THRESH << RxCfgFIFOShift) | (RX_DMA_BURST << RxCfgDMAShift) |
0x0000000E;
-static void rtl8169_hw_PHY_config(struct nic *nic __unused);
-//static void rtl8169_hw_PHY_reset(struct net_device *dev);
+static void rtl8169_hw_phy_config(struct nic *nic __unused);
+//static void rtl8169_hw_phy_reset(struct net_device *dev);
#define RTL8169_WRITE_GMII_REG_BIT( ioaddr, reg, bitnum, bitval )\
{ \
@@ -457,6 +480,65 @@ static int mdio_read(int RegAddr)
}
#endif
+static void rtl8169_get_mac_version( struct rtl8169_private *tp,
+ u32 ioaddr )
+{
+ /*
+ * The driver currently handles the 8168Bf and the 8168Be identically
+ * but they can be identified more specifically through the test below
+ * if needed:
+ *
+ * (RTL_R32(TxConfig) & 0x700000) == 0x500000 ? 8168Bf : 8168Be
+ *
+ * Same thing for the 8101Eb and the 8101Ec:
+ *
+ * (RTL_R32(TxConfig) & 0x700000) == 0x200000 ? 8101Eb : 8101Ec
+ */
+ const struct {
+ u32 mask;
+ u32 val;
+ int mac_version;
+ } mac_info[] = {
+ /* 8168B family. */
+ { 0x7c800000, 0x3c800000, RTL_GIGA_MAC_VER_18 },
+ { 0x7cf00000, 0x3c000000, RTL_GIGA_MAC_VER_19 },
+ { 0x7cf00000, 0x3c200000, RTL_GIGA_MAC_VER_20 },
+ { 0x7c800000, 0x3c000000, RTL_GIGA_MAC_VER_20 },
+ /* 8168B family. */
+ { 0x7cf00000, 0x38000000, RTL_GIGA_MAC_VER_12 },
+ { 0x7cf00000, 0x38500000, RTL_GIGA_MAC_VER_17 },
+ { 0x7c800000, 0x38000000, RTL_GIGA_MAC_VER_17 },
+ { 0x7c800000, 0x30000000, RTL_GIGA_MAC_VER_11 },
+ /* 8101 family. */
+ { 0x7cf00000, 0x34000000, RTL_GIGA_MAC_VER_13 },
+ { 0x7cf00000, 0x34200000, RTL_GIGA_MAC_VER_16 },
+ { 0x7c800000, 0x34000000, RTL_GIGA_MAC_VER_16 },
+ /* FIXME: where did these entries come from ? -- FR */
+ { 0xfc800000, 0x38800000, RTL_GIGA_MAC_VER_15 },
+ { 0xfc800000, 0x30800000, RTL_GIGA_MAC_VER_14 },
+ /* 8110 family. */
+ { 0xfc800000, 0x98000000, RTL_GIGA_MAC_VER_06 },
+ { 0xfc800000, 0x18000000, RTL_GIGA_MAC_VER_05 },
+ { 0xfc800000, 0x10000000, RTL_GIGA_MAC_VER_04 },
+ { 0xfc800000, 0x04000000, RTL_GIGA_MAC_VER_03 },
+ { 0xfc800000, 0x00800000, RTL_GIGA_MAC_VER_02 },
+ { 0xfc800000, 0x00000000, RTL_GIGA_MAC_VER_01 },
+ { 0x00000000, 0x00000000, RTL_GIGA_MAC_VER_01 } /* Catch-all */
+ }, *p = mac_info;
+
+ unsigned long rv;
+
+ rv = (RTL_R32(TxConfig));
+
+ while ((rv & p->mask) != p->val)
+ p++;
+ tp->mac_version = p->mac_version;
+
+ if (p->mask == 0x00000000) {
+ DBG("unknown MAC (%08lx)\n", rv);
+ }
+}
+
#define IORESOURCE_MEM 0x00000200
static int rtl8169_init_board(struct pci_device *pdev)
@@ -464,6 +546,7 @@ static int rtl8169_init_board(struct pci_device *pdev)
int i;
// unsigned long mmio_end, mmio_flags
unsigned long mmio_start, mmio_len;
+ struct rtl8169_private *tp = &tpx;
adjust_pci_device(pdev);
@@ -494,7 +577,7 @@ static int rtl8169_init_board(struct pci_device *pdev)
}
#endif
- tpc->mmio_addr = &ioaddr;
+ tp->mmio_addr = (void*)ioaddr;
/* Soft reset the chip. */
RTL_W8(ChipCmd, CmdReset);
@@ -504,48 +587,39 @@ static int rtl8169_init_board(struct pci_device *pdev)
break;
else
udelay(10);
- // identify config method
- {
- unsigned long val32 = (RTL_R32(TxConfig) & 0x7c800000);
- if (val32 == (0x1 << 28)) {
- tpc->mcfg = MCFG_METHOD_4;
- } else if (val32 == (0x1 << 26)) {
- tpc->mcfg = MCFG_METHOD_3;
- } else if (val32 == (0x1 << 23)) {
- tpc->mcfg = MCFG_METHOD_2;
- } else if (val32 == 0x00000000) {
- tpc->mcfg = MCFG_METHOD_1;
- } else {
- tpc->mcfg = MCFG_METHOD_1;
- }
- }
+
+ /* Identify chip attached to board */
+ rtl8169_get_mac_version( tp, ioaddr );
+
+ // rtl8169_print_mac_version(tp);
+
{
unsigned char val8 =
(unsigned char) (RTL8169_READ_GMII_REG(ioaddr, 3) &
0x000f);
if (val8 == 0x00) {
- tpc->pcfg = PCFG_METHOD_1;
+ tp->pcfg = RTL_CFG_0;
} else if (val8 == 0x01) {
- tpc->pcfg = PCFG_METHOD_2;
+ tp->pcfg = RTL_CFG_1;
} else if (val8 == 0x02) {
- tpc->pcfg = PCFG_METHOD_3;
+ tp->pcfg = RTL_CFG_2;
} else {
- tpc->pcfg = PCFG_METHOD_3;
+ tp->pcfg = RTL_CFG_2;
}
}
/* identify chip attached to board */
for (i = ARRAY_SIZE(rtl_chip_info) - 1; i >= 0; i--)
- if (tpc->mcfg == rtl_chip_info[i].mcfg) {
- tpc->chipset = i;
+ if (tp->mac_version == rtl_chip_info[i].mac_version) {
+ tp->chipset = i;
goto match;
}
/* if unknown chip, assume array element #0, original RTL-8169 in this case */
DBG ( "PCI device: unknown chip version, assuming RTL-8169\n" );
DBG ( "PCI device: TxConfig = %#lX\n", ( unsigned long ) RTL_R32 ( TxConfig ) );
- tpc->chipset = 0;
+ tp->chipset = 0;
return 1;
match:
@@ -584,51 +658,57 @@ static void r8169_irq(struct nic *nic __unused, irq_action_t action)
/**************************************************************************
POLL - Wait for a frame
***************************************************************************/
-static int r8169_poll(struct nic *nic, int retreive)
+static int r8169_poll(struct nic *nic, int retrieve)
{
/* return true if there's an ethernet packet ready to read */
/* nic->packet should contain data on return */
/* nic->packetlen should contain length of data */
int cur_rx;
unsigned int intr_status = 0;
- cur_rx = tpc->cur_rx;
- if ((tpc->RxDescArray[cur_rx].status & OWNbit) == 0) {
+ struct rtl8169_private *tp = &tpx;
+
+ cur_rx = tp->cur_rx;
+ if ((tp->RxDescArray[cur_rx].status & OWNbit) == 0) {
/* There is a packet ready */
- if (!retreive)
+ DBG("r8169_poll(): packet ready\n");
+ if (!retrieve)
return 1;
intr_status = RTL_R16(IntrStatus);
/* h/w no longer present (hotplug?) or major error,
bail */
- if (intr_status == 0xFFFF)
+ if (intr_status == 0xFFFF) {
+ DBG("r8169_poll(): unknown error\n");
return 0;
+ }
RTL_W16(IntrStatus, intr_status &
~(RxFIFOOver | RxOverflow | RxOK));
- if (!(tpc->RxDescArray[cur_rx].status & RxRES)) {
- nic->packetlen = (int) (tpc->RxDescArray[cur_rx].
+ if (!(tp->RxDescArray[cur_rx].status & RxRES)) {
+ nic->packetlen = (int) (tp->RxDescArray[cur_rx].
status & 0x00001FFF) - 4;
- memcpy(nic->packet, tpc->RxBufferRing[cur_rx],
+ memcpy(nic->packet, tp->RxBufferRing[cur_rx],
nic->packetlen);
if (cur_rx == NUM_RX_DESC - 1)
- tpc->RxDescArray[cur_rx].status =
+ tp->RxDescArray[cur_rx].status =
(OWNbit | EORbit) + RX_BUF_SIZE;
else
- tpc->RxDescArray[cur_rx].status =
+ tp->RxDescArray[cur_rx].status =
OWNbit + RX_BUF_SIZE;
- tpc->RxDescArray[cur_rx].buf_addr =
- virt_to_bus(tpc->RxBufferRing[cur_rx]);
+ tp->RxDescArray[cur_rx].buf_addr =
+ virt_to_bus(tp->RxBufferRing[cur_rx]);
+ tp->RxDescArray[cur_rx].buf_Haddr = 0;
} else
printf("Error Rx");
/* FIXME: shouldn't I reset the status on an error */
cur_rx = (cur_rx + 1) % NUM_RX_DESC;
- tpc->cur_rx = cur_rx;
+ tp->cur_rx = cur_rx;
RTL_W16(IntrStatus, intr_status &
(RxFIFOOver | RxOverflow | RxOK));
return 1;
}
- tpc->cur_rx = cur_rx;
+ tp->cur_rx = cur_rx;
/* FIXME: There is no reason to do this as cur_rx did not change */
return (0); /* initially as this is called to flush the input */
@@ -648,10 +728,11 @@ static void r8169_transmit(struct nic *nic, const char *d, /* Destination */
u16 nstype;
u32 to;
u8 *ptxb;
- int entry = tpc->cur_tx % NUM_TX_DESC;
+ struct rtl8169_private *tp = &tpx;
+ int entry = tp->cur_tx % NUM_TX_DESC;
/* point to the current txb incase multiple tx_rings are used */
- ptxb = tpc->Tx_skbuff[entry * MAX_ETH_FRAME_SIZE];
+ ptxb = tp->Tx_skbuff[entry * MAX_ETH_FRAME_SIZE];
memcpy(ptxb, d, ETH_ALEN);
memcpy(ptxb + ETH_ALEN, nic->node_addr, ETH_ALEN);
nstype = htons((u16) t);
@@ -662,20 +743,21 @@ static void r8169_transmit(struct nic *nic, const char *d, /* Destination */
while (s < ETH_ZLEN)
ptxb[s++] = '\0';
- tpc->TxDescArray[entry].buf_addr = virt_to_bus(ptxb);
+ tp->TxDescArray[entry].buf_addr = virt_to_bus(ptxb);
+ tp->TxDescArray[entry].buf_Haddr = 0;
if (entry != (NUM_TX_DESC - 1))
- tpc->TxDescArray[entry].status =
+ tp->TxDescArray[entry].status =
(OWNbit | FSbit | LSbit) | ((s > ETH_ZLEN) ? s :
ETH_ZLEN);
else
- tpc->TxDescArray[entry].status =
+ tp->TxDescArray[entry].status =
(OWNbit | EORbit | FSbit | LSbit) | ((s > ETH_ZLEN) ? s
: ETH_ZLEN);
RTL_W8(TxPoll, 0x40); /* set polling bit */
- tpc->cur_tx++;
+ tp->cur_tx++;
to = currticks() + TX_TIMEOUT;
- while ((tpc->TxDescArray[entry].status & OWNbit) && (currticks() < to)); /* wait */
+ while ((tp->TxDescArray[entry].status & OWNbit) && (currticks() < to)); /* wait */
if (currticks() >= to) {
printf("TX Time Out");
@@ -687,6 +769,7 @@ static void rtl8169_set_rx_mode(struct nic *nic __unused)
u32 mc_filter[2]; /* Multicast hash filter */
int rx_mode;
u32 tmp = 0;
+ struct rtl8169_private *tp = &tpx;
/* IFF_ALLMULTI */
/* Too many to filter perfectly -- accept all multicasts. */
@@ -695,7 +778,7 @@ static void rtl8169_set_rx_mode(struct nic *nic __unused)
tmp =
rtl8169_rx_config | rx_mode | (RTL_R32(RxConfig) &
- rtl_chip_info[tpc->chipset].
+ rtl_chip_info[tp->chipset].
RxConfigMask);
RTL_W32(RxConfig, tmp);
@@ -705,6 +788,7 @@ static void rtl8169_set_rx_mode(struct nic *nic __unused)
static void rtl8169_hw_start(struct nic *nic)
{
u32 i;
+ struct rtl8169_private *tp = &tpx;
/* Soft reset the chip. */
RTL_W8(ChipCmd, CmdReset);
@@ -726,7 +810,7 @@ static void rtl8169_hw_start(struct nic *nic)
/* Set Rx Config register */
i = rtl8169_rx_config | (RTL_R32(RxConfig) &
- rtl_chip_info[tpc->chipset].RxConfigMask);
+ rtl_chip_info[tp->chipset].RxConfigMask);
RTL_W32(RxConfig, i);
/* Set DMA burst size and Interframe Gap Time */
@@ -737,7 +821,7 @@ static void rtl8169_hw_start(struct nic *nic)
RTL_W16(CPlusCmd, RTL_R16(CPlusCmd));
- if (tpc->mcfg == MCFG_METHOD_2 || tpc->mcfg == MCFG_METHOD_3) {
+ if (tp->mac_version == RTL_GIGA_MAC_VER_02 || tp->mac_version == RTL_GIGA_MAC_VER_03) {
RTL_W16(CPlusCmd,
(RTL_R16(CPlusCmd) | (1 << 14) | (1 << 3)));
DBG
@@ -748,18 +832,18 @@ static void rtl8169_hw_start(struct nic *nic)
}
{
- //RTL_W16(0xE2, 0x1517);
- //RTL_W16(0xE2, 0x152a);
- //RTL_W16(0xE2, 0x282a);
- RTL_W16(0xE2, 0x0000);
+ //RTL_W16(IntrMitigate, 0x1517);
+ //RTL_W16(IntrMitigate, 0x152a);
+ //RTL_W16(IntrMitigate, 0x282a);
+ RTL_W16(IntrMitigate, 0x0000);
}
+ tp->cur_rx = 0;
-
- tpc->cur_rx = 0;
-
- RTL_W32(TxDescStartAddr, virt_to_le32desc(tpc->TxDescArray));
- RTL_W32(RxDescStartAddr, virt_to_le32desc(tpc->RxDescArray));
+ RTL_W32(TxDescAddrLow, virt_to_le32desc(tp->TxDescArray));
+ RTL_W32(TxDescAddrHigh, virt_to_le32desc(NULL));
+ RTL_W32(RxDescAddrLow, virt_to_le32desc(tp->RxDescArray));
+ RTL_W32(RxDescAddrHigh, virt_to_le32desc(NULL));
RTL_W8(Cfg9346, Cfg9346_Lock);
udelay(10);
@@ -777,26 +861,28 @@ static void rtl8169_hw_start(struct nic *nic)
static void rtl8169_init_ring(struct nic *nic __unused)
{
int i;
+ struct rtl8169_private *tp = &tpx;
- tpc->cur_rx = 0;
- tpc->cur_tx = 0;
- memset(tpc->TxDescArray, 0x0, NUM_TX_DESC * sizeof(struct TxDesc));
- memset(tpc->RxDescArray, 0x0, NUM_RX_DESC * sizeof(struct RxDesc));
+ tp->cur_rx = 0;
+ tp->cur_tx = 0;
+ memset(tp->TxDescArray, 0x0, NUM_TX_DESC * sizeof(struct TxDesc));
+ memset(tp->RxDescArray, 0x0, NUM_RX_DESC * sizeof(struct RxDesc));
for (i = 0; i < NUM_TX_DESC; i++) {
- tpc->Tx_skbuff[i] = &txb[i];
+ tp->Tx_skbuff[i] = &txb[i];
}
for (i = 0; i < NUM_RX_DESC; i++) {
if (i == (NUM_RX_DESC - 1))
- tpc->RxDescArray[i].status =
+ tp->RxDescArray[i].status =
(OWNbit | EORbit) | RX_BUF_SIZE;
else
- tpc->RxDescArray[i].status = OWNbit | RX_BUF_SIZE;
+ tp->RxDescArray[i].status = OWNbit | RX_BUF_SIZE;
- tpc->RxBufferRing[i] = &rxb[i * RX_BUF_SIZE];
- tpc->RxDescArray[i].buf_addr =
- virt_to_bus(tpc->RxBufferRing[i]);
+ tp->RxBufferRing[i] = &rxb[i * RX_BUF_SIZE];
+ tp->RxDescArray[i].buf_addr =
+ virt_to_bus(tp->RxBufferRing[i]);
+ tp->RxDescArray[i].buf_Haddr = 0;
}
}
@@ -806,9 +892,10 @@ RESET - Finish setting up the ethernet interface
static void r8169_reset(struct nic *nic)
{
int i;
+ struct rtl8169_private *tp = &tpx;
- tpc->TxDescArray = tx_ring;
- tpc->RxDescArray = rx_ring;
+ tp->TxDescArray = tx_ring;
+ tp->RxDescArray = rx_ring;
rtl8169_init_ring(nic);
rtl8169_hw_start(nic);
@@ -830,6 +917,8 @@ DISABLE - Turn off ethernet interface
***************************************************************************/
static void r8169_disable ( struct nic *nic __unused ) {
int i;
+ struct rtl8169_private *tp = &tpx;
+
/* Stop the chip's Tx and Rx DMA processes. */
RTL_W8(ChipCmd, 0x00);
@@ -838,10 +927,10 @@ static void r8169_disable ( struct nic *nic __unused ) {
RTL_W32(RxMissed, 0);
- tpc->TxDescArray = NULL;
- tpc->RxDescArray = NULL;
+ tp->TxDescArray = NULL;
+ tp->RxDescArray = NULL;
for (i = 0; i < NUM_RX_DESC; i++) {
- tpc->RxBufferRing[i] = NULL;
+ tp->RxBufferRing[i] = NULL;
}
}
@@ -858,6 +947,10 @@ static struct pci_device_id r8169_nics[] = {
PCI_ROM(0x16ec, 0x0116, "usr-r8169", "US Robotics RTL8169 Gigabit Ethernet"),
PCI_ROM(0x1186, 0x4300, "dlink-r8169", "D-Link RTL8169 Gigabit Ethernet"),
PCI_ROM(0x1737, 0x1032, "linksys-r8169", "Linksys RTL8169 Gigabit Ethernet"),
+ PCI_ROM(0x10ec, 0x8129, "r8169-8129", "RealTek RT8129 Fast Ethernet Adapter"),
+ PCI_ROM(0x10ec, 0x8136, "r8169-8101e", "RealTek RTL8101E PCI Express Fast Ethernet controller"),
+ PCI_ROM(0x10ec, 0x8167, "r8169-8110sc/8169sc", "RealTek RTL-8110SC/8169SC Gigabit Ethernet"),
+ PCI_ROM(0x10ec, 0x8168, "r8169-8168b", "RealTek RTL8111/8168B PCI Express Gigabit Ethernet controller"),
};
PCI_DRIVER ( r8169_driver, r8169_nics, PCI_NO_CLASS );
@@ -872,6 +965,7 @@ static int r8169_probe ( struct nic *nic, struct pci_device *pci ) {
static int board_idx = -1;
static int printed_version = 0;
+ struct rtl8169_private *tp = &tpx;
int i, rc;
int option = -1, Cap10_100 = 0, Cap1000 = 0;
@@ -891,9 +985,6 @@ static int r8169_probe ( struct nic *nic, struct pci_device *pci ) {
return 0;
memset ( r8169_bufs, 0, sizeof ( *r8169_bufs ) );
- /* point to private storage */
- tpc = &tpx;
-
rc = rtl8169_init_board(pci); /* Return code is meaningless */
/* Get MAC address. FIXME: read EEPROM */
@@ -901,30 +992,32 @@ static int r8169_probe ( struct nic *nic, struct pci_device *pci ) {
nic->node_addr[i] = RTL_R8(MAC0 + i);
DBG ( "%s: Identified chip type is '%s'.\n", pci->driver_name,
- rtl_chip_info[tpc->chipset].name );
+ rtl_chip_info[tp->chipset].name );
/* Print out some hardware info */
- DBG ( "%s: %s at IOAddr %#hX, ", pci->driver_name, eth_ntoa ( nic->node_addr ),
+ DBG ( "%s: %s at ioaddr %#hx, ", pci->driver_name, eth_ntoa ( nic->node_addr ),
(unsigned int) ioaddr );
/* Config PHY */
- rtl8169_hw_PHY_config(nic);
-
+ rtl8169_hw_phy_config(nic);
+
DBG("Set MAC Reg C+CR Offset 0x82h = 0x01h\n");
RTL_W8(0x82, 0x01);
- if (tpc->mcfg < MCFG_METHOD_3) {
- DBG("Set PCI Latency=0x40\n");
- pci_write_config_byte(pci, PCI_LATENCY_TIMER, 0x40);
- }
+ pci_write_config_byte(pci, PCI_LATENCY_TIMER, 0x40);
+
+ if (tp->mac_version <= RTL_GIGA_MAC_VER_06)
+ pci_write_config_byte(pci, PCI_CACHE_LINE_SIZE, 0x08);
- if (tpc->mcfg == MCFG_METHOD_2) {
+ if (tp->mac_version == RTL_GIGA_MAC_VER_02) {
DBG("Set MAC Reg C+CR Offset 0x82h = 0x01h\n");
RTL_W8(0x82, 0x01);
DBG("Set PHY Reg 0x0bh = 0x00h\n");
- RTL8169_WRITE_GMII_REG(ioaddr, 0x0b, 0x0000); //w 0x0b 15 0 0
+ RTL8169_WRITE_GMII_REG(ioaddr, 0x0b, 0x0000); //w 0x0b 15 0 0
}
+ r8169_reset(nic);
+
/* if TBI is not endbled */
if (!(RTL_R8(PHYstatus) & TBI_Enable)) {
int val = RTL8169_READ_GMII_REG(ioaddr, PHY_AUTO_NEGO_REG);
@@ -933,7 +1026,6 @@ static int r8169_probe ( struct nic *nic, struct pci_device *pci ) {
val |= PHY_Cap_PAUSE | PHY_Cap_ASYM_PAUSE;
#endif //end #define RTL8169_HW_FLOW_CONTROL_SUPPORT
- option = media;
/* Force RTL8169 in 10/100/1000 Full/Half mode. */
if (option > 0) {
printf(" Force-mode Enabled.\n");
@@ -1062,113 +1154,160 @@ static void rtl8169_hw_PHY_reset(struct nic *nic __unused)
*/
-//======================================================================================================
-static void rtl8169_hw_PHY_config(struct nic *nic __unused)
+struct phy_reg {
+ u16 reg;
+ u16 val;
+};
+
+static void rtl_phy_write(void *ioaddr, struct phy_reg *regs, int len)
{
+ while (len-- > 0) {
+ RTL8169_WRITE_GMII_REG((u32)ioaddr, regs->reg, regs->val);
+ regs++;
+ }
+}
- DBG("priv->mcfg=%d, priv->pcfg=%d\n", tpc->mcfg, tpc->pcfg);
+static void rtl8169s_hw_phy_config(void *ioaddr)
+{
+ struct {
+ u16 regs[5]; /* Beware of bit-sign propagation */
+ } phy_magic[5] = { {
+ { 0x0000, //w 4 15 12 0
+ 0x00a1, //w 3 15 0 00a1
+ 0x0008, //w 2 15 0 0008
+ 0x1020, //w 1 15 0 1020
+ 0x1000 } },{ //w 0 15 0 1000
+ { 0x7000, //w 4 15 12 7
+ 0xff41, //w 3 15 0 ff41
+ 0xde60, //w 2 15 0 de60
+ 0x0140, //w 1 15 0 0140
+ 0x0077 } },{ //w 0 15 0 0077
+ { 0xa000, //w 4 15 12 a
+ 0xdf01, //w 3 15 0 df01
+ 0xdf20, //w 2 15 0 df20
+ 0xff95, //w 1 15 0 ff95
+ 0xfa00 } },{ //w 0 15 0 fa00
+ { 0xb000, //w 4 15 12 b
+ 0xff41, //w 3 15 0 ff41
+ 0xde20, //w 2 15 0 de20
+ 0x0140, //w 1 15 0 0140
+ 0x00bb } },{ //w 0 15 0 00bb
+ { 0xf000, //w 4 15 12 f
+ 0xdf01, //w 3 15 0 df01
+ 0xdf20, //w 2 15 0 df20
+ 0xff95, //w 1 15 0 ff95
+ 0xbf00 } //w 0 15 0 bf00
+ }
+ }, *p = phy_magic;
+ unsigned int i;
+
+ RTL8169_WRITE_GMII_REG((u32)ioaddr, 0x1f, 0x0001); //w 31 2 0 1
+ RTL8169_WRITE_GMII_REG((u32)ioaddr, 0x15, 0x1000); //w 21 15 0 1000
+ RTL8169_WRITE_GMII_REG((u32)ioaddr, 0x18, 0x65c7); //w 24 15 0 65c7
+ RTL8169_WRITE_GMII_REG_BIT((u32)ioaddr, 4, 11, 0); //w 4 11 11 0
+
+ for (i = 0; i < ARRAY_SIZE(phy_magic); i++, p++) {
+ int val, pos = 4;
+
+ val = (RTL8169_READ_GMII_REG((u32)ioaddr, pos) & 0x0fff) | (p->regs[0] & 0xffff);
+ RTL8169_WRITE_GMII_REG((u32)ioaddr, pos, val);
+ while (--pos >= 0)
+ RTL8169_WRITE_GMII_REG((u32)ioaddr, pos, p->regs[4 - pos] & 0xffff);
+ RTL8169_WRITE_GMII_REG_BIT((u32)ioaddr, 4, 11, 1); //w 4 11 11 1
+ RTL8169_WRITE_GMII_REG_BIT((u32)ioaddr, 4, 11, 0); //w 4 11 11 0
+ }
+ RTL8169_WRITE_GMII_REG((u32)ioaddr, 0x1f, 0x0000); //w 31 2 0 0
+}
- if (tpc->mcfg == MCFG_METHOD_4) {
-/*
- RTL8169_WRITE_GMII_REG( (unsigned long)ioaddr, 0x1F, 0x0001 );
- RTL8169_WRITE_GMII_REG( (unsigned long)ioaddr, 0x1b, 0x841e );
- RTL8169_WRITE_GMII_REG( (unsigned long)ioaddr, 0x0e, 0x7bfb );
- RTL8169_WRITE_GMII_REG( (unsigned long)ioaddr, 0x09, 0x273a );
-*/
+static void rtl8169sb_hw_phy_config(void *ioaddr)
+{
+ struct phy_reg phy_reg_init[] = {
+ { 0x1f, 0x0002 },
+ { 0x01, 0x90d0 },
+ { 0x1f, 0x0000 }
+ };
- RTL8169_WRITE_GMII_REG((unsigned long) ioaddr, 0x1F,
- 0x0002);
- RTL8169_WRITE_GMII_REG((unsigned long) ioaddr, 0x01,
- 0x90D0);
- RTL8169_WRITE_GMII_REG((unsigned long) ioaddr, 0x1F,
- 0x0000);
- } else if ((tpc->mcfg == MCFG_METHOD_2)
- || (tpc->mcfg == MCFG_METHOD_3)) {
- RTL8169_WRITE_GMII_REG((unsigned long) ioaddr, 0x1F,
- 0x0001);
- RTL8169_WRITE_GMII_REG((unsigned long) ioaddr, 0x15,
- 0x1000);
- RTL8169_WRITE_GMII_REG((unsigned long) ioaddr, 0x18,
- 0x65C7);
- RTL8169_WRITE_GMII_REG((unsigned long) ioaddr, 0x04,
- 0x0000);
- RTL8169_WRITE_GMII_REG((unsigned long) ioaddr, 0x03,
- 0x00A1);
- RTL8169_WRITE_GMII_REG((unsigned long) ioaddr, 0x02,
- 0x0008);
- RTL8169_WRITE_GMII_REG((unsigned long) ioaddr, 0x01,
- 0x1020);
- RTL8169_WRITE_GMII_REG((unsigned long) ioaddr, 0x00,
- 0x1000);
- RTL8169_WRITE_GMII_REG((unsigned long) ioaddr, 0x04,
- 0x0800);
- RTL8169_WRITE_GMII_REG((unsigned long) ioaddr, 0x04,
- 0x0000);
- RTL8169_WRITE_GMII_REG((unsigned long) ioaddr, 0x04,
- 0x7000);
- RTL8169_WRITE_GMII_REG((unsigned long) ioaddr, 0x03,
- 0xFF41);
- RTL8169_WRITE_GMII_REG((unsigned long) ioaddr, 0x02,
- 0xDE60);
- RTL8169_WRITE_GMII_REG((unsigned long) ioaddr, 0x01,
- 0x0140);
- RTL8169_WRITE_GMII_REG((unsigned long) ioaddr, 0x00,
- 0x0077);
- RTL8169_WRITE_GMII_REG((unsigned long) ioaddr, 0x04,
- 0x7800);
- RTL8169_WRITE_GMII_REG((unsigned long) ioaddr, 0x04,
- 0x7000);
- RTL8169_WRITE_GMII_REG((unsigned long) ioaddr, 0x04,
- 0xA000);
- RTL8169_WRITE_GMII_REG((unsigned long) ioaddr, 0x03,
- 0xDF01);
- RTL8169_WRITE_GMII_REG((unsigned long) ioaddr, 0x02,
- 0xDF20);
- RTL8169_WRITE_GMII_REG((unsigned long) ioaddr, 0x01,
- 0xFF95);
- RTL8169_WRITE_GMII_REG((unsigned long) ioaddr, 0x00,
- 0xFA00);
- RTL8169_WRITE_GMII_REG((unsigned long) ioaddr, 0x04,
- 0xA800);
- RTL8169_WRITE_GMII_REG((unsigned long) ioaddr, 0x04,
- 0xA000);
- RTL8169_WRITE_GMII_REG((unsigned long) ioaddr, 0x04,
- 0xB000);
- RTL8169_WRITE_GMII_REG((unsigned long) ioaddr, 0x03,
- 0xFF41);
- RTL8169_WRITE_GMII_REG((unsigned long) ioaddr, 0x02,
- 0xDE20);
- RTL8169_WRITE_GMII_REG((unsigned long) ioaddr, 0x01,
- 0x0140);
- RTL8169_WRITE_GMII_REG((unsigned long) ioaddr, 0x00,
- 0x00BB);
- RTL8169_WRITE_GMII_REG((unsigned long) ioaddr, 0x04,
- 0xB800);
- RTL8169_WRITE_GMII_REG((unsigned long) ioaddr, 0x04,
- 0xB000);
- RTL8169_WRITE_GMII_REG((unsigned long) ioaddr, 0x04,
- 0xF000);
- RTL8169_WRITE_GMII_REG((unsigned long) ioaddr, 0x03,
- 0xDF01);
- RTL8169_WRITE_GMII_REG((unsigned long) ioaddr, 0x02,
- 0xDF20);
- RTL8169_WRITE_GMII_REG((unsigned long) ioaddr, 0x01,
- 0xFF95);
- RTL8169_WRITE_GMII_REG((unsigned long) ioaddr, 0x00,
- 0xBF00);
- RTL8169_WRITE_GMII_REG((unsigned long) ioaddr, 0x04,
- 0xF800);
- RTL8169_WRITE_GMII_REG((unsigned long) ioaddr, 0x04,
- 0xF000);
- RTL8169_WRITE_GMII_REG((unsigned long) ioaddr, 0x04,
- 0x0000);
- RTL8169_WRITE_GMII_REG((unsigned long) ioaddr, 0x1F,
- 0x0000);
- RTL8169_WRITE_GMII_REG((unsigned long) ioaddr, 0x0B,
- 0x0000);
- } else {
- DBG("tpc->mcfg=%d. Discard hw PHY config.\n",
- tpc->mcfg);
+ rtl_phy_write(ioaddr, phy_reg_init, ARRAY_SIZE(phy_reg_init));
+}
+
+static void rtl8168cp_hw_phy_config(void *ioaddr)
+{
+ struct phy_reg phy_reg_init[] = {
+ { 0x1f, 0x0000 },
+ { 0x1d, 0x0f00 },
+ { 0x1f, 0x0002 },
+ { 0x0c, 0x1ec8 },
+ { 0x1f, 0x0000 }
+ };
+
+ rtl_phy_write(ioaddr, phy_reg_init, ARRAY_SIZE(phy_reg_init));
+}
+
+static void rtl8168c_hw_phy_config(void *ioaddr)
+{
+ struct phy_reg phy_reg_init[] = {
+ { 0x1f, 0x0001 },
+ { 0x12, 0x2300 },
+ { 0x1f, 0x0002 },
+ { 0x00, 0x88d4 },
+ { 0x01, 0x82b1 },
+ { 0x03, 0x7002 },
+ { 0x08, 0x9e30 },
+ { 0x09, 0x01f0 },
+ { 0x0a, 0x5500 },
+ { 0x0c, 0x00c8 },
+ { 0x1f, 0x0003 },
+ { 0x12, 0xc096 },
+ { 0x16, 0x000a },
+ { 0x1f, 0x0000 }
+ };
+
+ rtl_phy_write(ioaddr, phy_reg_init, ARRAY_SIZE(phy_reg_init));
+}
+
+static void rtl8168cx_hw_phy_config(void *ioaddr)
+{
+ struct phy_reg phy_reg_init[] = {
+ { 0x1f, 0x0000 },
+ { 0x12, 0x2300 },
+ { 0x1f, 0x0003 },
+ { 0x16, 0x0f0a },
+ { 0x1f, 0x0000 },
+ { 0x1f, 0x0002 },
+ { 0x0c, 0x7eb8 },
+ { 0x1f, 0x0000 }
+ };
+
+ rtl_phy_write(ioaddr, phy_reg_init, ARRAY_SIZE(phy_reg_init));
+}
+
+static void rtl8169_hw_phy_config(struct nic *nic __unused)
+{
+ struct rtl8169_private *tp = &tpx;
+ void *ioaddr = tp->mmio_addr;
+ DBG("rtl8169_hw_phy_config(): card at addr=0x%lx: priv->mac_version=%d, priv->pcfg=%d\n", (unsigned long) ioaddr, tp->mac_version, tp->pcfg);
+
+ switch (tp->mac_version) {
+ case RTL_GIGA_MAC_VER_01:
+ break;
+ case RTL_GIGA_MAC_VER_02:
+ case RTL_GIGA_MAC_VER_03:
+ rtl8169s_hw_phy_config(ioaddr);
+ break;
+ case RTL_GIGA_MAC_VER_04:
+ rtl8169sb_hw_phy_config(ioaddr);
+ break;
+ case RTL_GIGA_MAC_VER_18:
+ rtl8168cp_hw_phy_config(ioaddr);
+ break;
+ case RTL_GIGA_MAC_VER_19:
+ rtl8168c_hw_phy_config(ioaddr);
+ break;
+ case RTL_GIGA_MAC_VER_20:
+ rtl8168cx_hw_phy_config(ioaddr);
+ break;
+ default:
+ break;
}
}
diff --git a/gpxe/src/drivers/net/rtl8139.c b/gpxe/src/drivers/net/rtl8139.c
index c432884c..509047a9 100644
--- a/gpxe/src/drivers/net/rtl8139.c
+++ b/gpxe/src/drivers/net/rtl8139.c
@@ -518,6 +518,9 @@ static int rtl_probe ( struct pci_device *pci,
rtl_reset ( netdev );
rtl_init_eeprom ( netdev );
nvs_read ( &rtl->eeprom.nvs, EE_MAC, netdev->ll_addr, ETH_ALEN );
+
+ /* Mark as link up; we don't yet handle link state */
+ netdev_link_up ( netdev );
/* Register network device */
if ( ( rc = register_netdev ( netdev ) ) != 0 )
diff --git a/gpxe/src/drivers/net/tg3.c b/gpxe/src/drivers/net/tg3.c
index 2aa072b6..ba228d72 100644
--- a/gpxe/src/drivers/net/tg3.c
+++ b/gpxe/src/drivers/net/tg3.c
@@ -1879,7 +1879,8 @@ static int tg3_setup_hw(struct tg3 *tp)
(65 << GRC_MISC_CFG_PRESCALAR_SHIFT));
/* Initialize MBUF/DESC pool. */
- if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5705) {
+ if ((GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5705) &&
+ (tp->pci_chip_rev_id != CHIPREV_ID_5721)) {
tw32(BUFMGR_MB_POOL_ADDR, NIC_SRAM_MBUF_POOL_BASE);
if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704)
tw32(BUFMGR_MB_POOL_SIZE, NIC_SRAM_MBUF_POOL_SIZE64);
@@ -3365,6 +3366,7 @@ PCI_ROM(0x14e4, 0x1648, "tg3-5704", "Broadcom Tigon 3 5704"),
PCI_ROM(0x14e4, 0x164d, "tg3-5702FE", "Broadcom Tigon 3 5702FE"),
PCI_ROM(0x14e4, 0x1653, "tg3-5705", "Broadcom Tigon 3 5705"),
PCI_ROM(0x14e4, 0x1654, "tg3-5705_2", "Broadcom Tigon 3 5705_2"),
+PCI_ROM(0x14e4, 0x1659, "tg3-5721", "Broadcom Tigon 3 5721"),
PCI_ROM(0x14e4, 0x165d, "tg3-5705M", "Broadcom Tigon 3 5705M"),
PCI_ROM(0x14e4, 0x165e, "tg3-5705M_2", "Broadcom Tigon 3 5705M_2"),
PCI_ROM(0x14e4, 0x1677, "tg3-5751", "Broadcom Tigon 3 5751"),
diff --git a/gpxe/src/drivers/net/tg3.h b/gpxe/src/drivers/net/tg3.h
index fd038f58..9077f80a 100644
--- a/gpxe/src/drivers/net/tg3.h
+++ b/gpxe/src/drivers/net/tg3.h
@@ -283,6 +283,7 @@ typedef unsigned long dma_addr_t;
#define CHIPREV_ID_5705_A1 0x3001
#define CHIPREV_ID_5705_A2 0x3002
#define CHIPREV_ID_5705_A3 0x3003
+#define CHIPREV_ID_5721 0x4101
#define CHIPREV_ID_5750_A0 0x4000
#define CHIPREV_ID_5750_A1 0x4001
#define CHIPREV_ID_5750_A3 0x4003