summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJeff Darcy <jdarcy@redhat.com>2011-09-08 11:07:10 -0400
committerVijay Bellur <vijay@gluster.com>2011-09-29 11:52:30 -0700
commitabb4cbeea35c40d69f18aba599f58d7e2dc5fdaf (patch)
tree847cee5ae0b35354ce6544a401242a0c432806ae
parentb43596fb4cdb84ae8b5665537914fe72517b8722 (diff)
Second round of warning suppression.
Used a #pragma to kill ~170 in rpcgen code. Added GF_UNUSED to deal with a few more from macros elsewhere. The remainder are function return values (mostly context and dict calls) that really should be checked. Those would be harder to fix without real understanding of the code where they occur, so they remain as reminders. (Patchset 2: deal with older gcc that doesn't handle #pragma GCC diagnostic) (Patchset 3: fix include paths in generated files) (Patchset 4: keep up with trunk, squash 9 new warnings) (Patchset 5: six more, all in AFR) Change-Id: I29760c8c81be4d7e6489312c5d0e92cc24814b7b BUG: 2550 Reviewed-on: http://review.gluster.com/378 Tested-by: Gluster Build System <jenkins@build.gluster.com> Reviewed-by: Vijay Bellur <vijay@gluster.com>
-rwxr-xr-xextras/generate-xdr-files.sh6
-rw-r--r--libglusterfs/src/glusterfs.h7
-rw-r--r--rpc/xdr/src/cli1-xdr.c6
-rw-r--r--rpc/xdr/src/cli1-xdr.h6
-rw-r--r--rpc/xdr/src/glusterd1-xdr.c6
-rw-r--r--rpc/xdr/src/glusterd1-xdr.h6
-rw-r--r--rpc/xdr/src/glusterfs3-xdr.c6
-rw-r--r--rpc/xdr/src/glusterfs3-xdr.h6
-rw-r--r--rpc/xdr/src/portmap-xdr.c6
-rw-r--r--rpc/xdr/src/portmap-xdr.h6
-rw-r--r--xlators/cluster/afr/src/afr-lk-common.c2
-rw-r--r--xlators/cluster/afr/src/afr-open.c16
-rw-r--r--xlators/cluster/afr/src/afr-self-heal-common.c2
-rw-r--r--xlators/cluster/afr/src/afr-self-heal-entry.c8
-rw-r--r--xlators/cluster/afr/src/afr-self-heald.c4
-rw-r--r--xlators/cluster/afr/src/afr-transaction.c3
-rw-r--r--xlators/cluster/afr/src/afr.c2
-rw-r--r--xlators/cluster/afr/src/pump.c12
-rw-r--r--xlators/cluster/dht/src/dht-common.c2
-rw-r--r--xlators/cluster/dht/src/nufa.c2
-rw-r--r--xlators/features/quota/src/quota.c8
21 files changed, 75 insertions, 47 deletions
diff --git a/extras/generate-xdr-files.sh b/extras/generate-xdr-files.sh
index 004e098778..d1c2f13685 100755
--- a/extras/generate-xdr-files.sh
+++ b/extras/generate-xdr-files.sh
@@ -43,6 +43,12 @@ append_licence_header ()
#include "xdr-common.h"
#include "compat.h"
+#if defined(__GNUC__)
+#if __GNUC__ >= 4
+#pragma GCC diagnostic ignored "-Wunused-but-set-variable"
+#endif
+#endif
+
EOF
cat $src_file >> $dst_file;
diff --git a/libglusterfs/src/glusterfs.h b/libglusterfs/src/glusterfs.h
index 57a542bb35..c5c0a6261d 100644
--- a/libglusterfs/src/glusterfs.h
+++ b/libglusterfs/src/glusterfs.h
@@ -381,6 +381,13 @@ typedef enum {
extern char *glusterfs_strevent (glusterfs_event_t ev);
#define GF_MUST_CHECK __attribute__((warn_unused_result))
+/*
+ * Some macros (e.g. ALLOC_OR_GOTO) set variables in function scope, but the
+ * calling function might not only declare the variable to keep the macro happy
+ * and not use it otherwise. In such cases, the following can be used to
+ * suppress the "set but not used" warning that would otherwise occur.
+ */
+#define GF_UNUSED __attribute__((unused))
int glusterfs_graph_prepare (glusterfs_graph_t *graph, glusterfs_ctx_t *ctx);
int glusterfs_graph_destroy (glusterfs_graph_t *graph);
diff --git a/rpc/xdr/src/cli1-xdr.c b/rpc/xdr/src/cli1-xdr.c
index 8e2adc51c8..5885000cd8 100644
--- a/rpc/xdr/src/cli1-xdr.c
+++ b/rpc/xdr/src/cli1-xdr.c
@@ -20,6 +20,12 @@
#include "xdr-common.h"
#include "compat.h"
+#if defined(__GNUC__)
+#if __GNUC__ >= 4
+#pragma GCC diagnostic ignored "-Wunused-but-set-variable"
+#endif
+#endif
+
/*
* Please do not edit this file.
* It was generated using rpcgen.
diff --git a/rpc/xdr/src/cli1-xdr.h b/rpc/xdr/src/cli1-xdr.h
index 56a5f4802f..32f624faf6 100644
--- a/rpc/xdr/src/cli1-xdr.h
+++ b/rpc/xdr/src/cli1-xdr.h
@@ -20,6 +20,12 @@
#include "xdr-common.h"
#include "compat.h"
+#if defined(__GNUC__)
+#if __GNUC__ >= 4
+#pragma GCC diagnostic ignored "-Wunused-but-set-variable"
+#endif
+#endif
+
/*
* Please do not edit this file.
* It was generated using rpcgen.
diff --git a/rpc/xdr/src/glusterd1-xdr.c b/rpc/xdr/src/glusterd1-xdr.c
index 0602d08a93..a5438d23e3 100644
--- a/rpc/xdr/src/glusterd1-xdr.c
+++ b/rpc/xdr/src/glusterd1-xdr.c
@@ -20,6 +20,12 @@
#include "xdr-common.h"
#include "compat.h"
+#if defined(__GNUC__)
+#if __GNUC__ >= 4
+#pragma GCC diagnostic ignored "-Wunused-but-set-variable"
+#endif
+#endif
+
/*
* Please do not edit this file.
* It was generated using rpcgen.
diff --git a/rpc/xdr/src/glusterd1-xdr.h b/rpc/xdr/src/glusterd1-xdr.h
index eecdd3e042..14c41baffb 100644
--- a/rpc/xdr/src/glusterd1-xdr.h
+++ b/rpc/xdr/src/glusterd1-xdr.h
@@ -20,6 +20,12 @@
#include "xdr-common.h"
#include "compat.h"
+#if defined(__GNUC__)
+#if __GNUC__ >= 4
+#pragma GCC diagnostic ignored "-Wunused-but-set-variable"
+#endif
+#endif
+
/*
* Please do not edit this file.
* It was generated using rpcgen.
diff --git a/rpc/xdr/src/glusterfs3-xdr.c b/rpc/xdr/src/glusterfs3-xdr.c
index ced80de624..64e504f46f 100644
--- a/rpc/xdr/src/glusterfs3-xdr.c
+++ b/rpc/xdr/src/glusterfs3-xdr.c
@@ -20,6 +20,12 @@
#include "xdr-common.h"
#include "compat.h"
+#if defined(__GNUC__)
+#if __GNUC__ >= 4
+#pragma GCC diagnostic ignored "-Wunused-but-set-variable"
+#endif
+#endif
+
/*
* Please do not edit this file.
* It was generated using rpcgen.
diff --git a/rpc/xdr/src/glusterfs3-xdr.h b/rpc/xdr/src/glusterfs3-xdr.h
index e1a62821a4..0c8af17d2c 100644
--- a/rpc/xdr/src/glusterfs3-xdr.h
+++ b/rpc/xdr/src/glusterfs3-xdr.h
@@ -20,6 +20,12 @@
#include "xdr-common.h"
#include "compat.h"
+#if defined(__GNUC__)
+#if __GNUC__ >= 4
+#pragma GCC diagnostic ignored "-Wunused-but-set-variable"
+#endif
+#endif
+
/*
* Please do not edit this file.
* It was generated using rpcgen.
diff --git a/rpc/xdr/src/portmap-xdr.c b/rpc/xdr/src/portmap-xdr.c
index 0ef580d809..7033213c0b 100644
--- a/rpc/xdr/src/portmap-xdr.c
+++ b/rpc/xdr/src/portmap-xdr.c
@@ -20,6 +20,12 @@
#include "xdr-common.h"
#include "compat.h"
+#if defined(__GNUC__)
+#if __GNUC__ >= 4
+#pragma GCC diagnostic ignored "-Wunused-but-set-variable"
+#endif
+#endif
+
/*
* Please do not edit this file.
* It was generated using rpcgen.
diff --git a/rpc/xdr/src/portmap-xdr.h b/rpc/xdr/src/portmap-xdr.h
index 2096ef5d80..2686da287b 100644
--- a/rpc/xdr/src/portmap-xdr.h
+++ b/rpc/xdr/src/portmap-xdr.h
@@ -20,6 +20,12 @@
#include "xdr-common.h"
#include "compat.h"
+#if defined(__GNUC__)
+#if __GNUC__ >= 4
+#pragma GCC diagnostic ignored "-Wunused-but-set-variable"
+#endif
+#endif
+
/*
* Please do not edit this file.
* It was generated using rpcgen.
diff --git a/xlators/cluster/afr/src/afr-lk-common.c b/xlators/cluster/afr/src/afr-lk-common.c
index ba468dcdcb..1828ddde78 100644
--- a/xlators/cluster/afr/src/afr-lk-common.c
+++ b/xlators/cluster/afr/src/afr-lk-common.c
@@ -588,7 +588,6 @@ afr_unlock_inodelk (call_frame_t *frame, xlator_t *this)
afr_private_t *priv = NULL;
struct gf_flock flock = {0,};
struct gf_flock full_flock = {0,};
- struct gf_flock *flock_use = &flock;
int call_count = 0;
int i = 0;
int piggyback = 0;
@@ -636,7 +635,6 @@ afr_unlock_inodelk (call_frame_t *frame, xlator_t *this)
}
piggyback = 0;
- flock_use = &full_flock;
LOCK (&local->fd->lock);
{
diff --git a/xlators/cluster/afr/src/afr-open.c b/xlators/cluster/afr/src/afr-open.c
index 4b328e1845..4075c27240 100644
--- a/xlators/cluster/afr/src/afr-open.c
+++ b/xlators/cluster/afr/src/afr-open.c
@@ -92,14 +92,12 @@ afr_perform_data_self_heal (call_frame_t *frame, xlator_t *this)
{
afr_local_t *local = NULL;
afr_self_heal_t *sh = NULL;
- afr_private_t *priv = NULL;
inode_t *inode = NULL;
int st_child = -1;
char reason[64] = {0};
local = frame->local;
sh = &local->self_heal;
- priv = this->private;
inode = local->fd->inode;
if (!IA_ISREG (inode->ia_type))
@@ -392,13 +390,13 @@ int
afr_fix_open (call_frame_t *frame, xlator_t *this, afr_fd_ctx_t *fd_ctx,
int need_open_count, int *need_open)
{
- afr_local_t *local = NULL;
- afr_private_t *priv = NULL;
- int i = 0;
- call_frame_t *open_frame = NULL;
- afr_local_t *open_local = NULL;
- int ret = -1;
- int32_t op_errno = 0;
+ afr_local_t *local = NULL;
+ afr_private_t *priv = NULL;
+ int i = 0;
+ call_frame_t *open_frame = NULL;
+ afr_local_t *open_local = NULL;
+ int ret = -1;
+ GF_UNUSED int32_t op_errno = 0;
GF_ASSERT (fd_ctx);
GF_ASSERT (need_open_count > 0);
diff --git a/xlators/cluster/afr/src/afr-self-heal-common.c b/xlators/cluster/afr/src/afr-self-heal-common.c
index d1456d936b..6dd17c1b8b 100644
--- a/xlators/cluster/afr/src/afr-self-heal-common.c
+++ b/xlators/cluster/afr/src/afr-self-heal-common.c
@@ -1087,7 +1087,6 @@ afr_impunge_frame_create (call_frame_t *frame, xlator_t *this,
{
afr_local_t *local = NULL;
afr_local_t *impunge_local = NULL;
- afr_self_heal_t *sh = NULL;
afr_self_heal_t *impunge_sh = NULL;
int32_t op_errno = 0;
afr_private_t *priv = NULL;
@@ -1104,7 +1103,6 @@ afr_impunge_frame_create (call_frame_t *frame, xlator_t *this,
ALLOC_OR_GOTO (impunge_local, afr_local_t, out);
local = frame->local;
- sh = &local->self_heal;
new_frame->local = impunge_local;
impunge_sh = &impunge_local->self_heal;
impunge_sh->sh_frame = frame;
diff --git a/xlators/cluster/afr/src/afr-self-heal-entry.c b/xlators/cluster/afr/src/afr-self-heal-entry.c
index af41c480e8..0481d915d2 100644
--- a/xlators/cluster/afr/src/afr-self-heal-entry.c
+++ b/xlators/cluster/afr/src/afr-self-heal-entry.c
@@ -897,9 +897,7 @@ afr_sh_entry_call_impunge_done (call_frame_t *impunge_frame, xlator_t *this,
afr_self_heal_t *impunge_sh = NULL;
call_frame_t *frame = NULL;
int32_t impunge_ret_child = 0;
- afr_private_t *priv = NULL;
- priv = this->private;
AFR_INIT_SH_FRAME_VALS (impunge_frame, impunge_local, impunge_sh,
frame, local, sh);
@@ -918,12 +916,10 @@ afr_sh_entry_impunge_setattr_cbk (call_frame_t *impunge_frame, void *cookie,
int call_count = 0;
afr_private_t *priv = NULL;
afr_local_t *impunge_local = NULL;
- afr_self_heal_t *impunge_sh = NULL;
int child_index = 0;
priv = this->private;
impunge_local = impunge_frame->local;
- impunge_sh = &impunge_local->self_heal;
child_index = (long) cookie;
if (op_ret == 0) {
@@ -1247,11 +1243,9 @@ afr_sh_entry_impunge_symlink (call_frame_t *impunge_frame, xlator_t *this,
dict_t *dict = NULL;
struct iatt *buf = NULL;
int ret = 0;
- afr_self_heal_t *impunge_sh = NULL;
priv = this->private;
impunge_local = impunge_frame->local;
- impunge_sh = &impunge_local->self_heal;
buf = &impunge_local->cont.symlink.buf;
@@ -1734,7 +1728,6 @@ int
afr_sh_entry_impunge_entry (call_frame_t *frame, xlator_t *this,
gf_dirent_t *entry)
{
- afr_private_t *priv = NULL;
afr_local_t *local = NULL;
afr_self_heal_t *sh = NULL;
int ret = -1;
@@ -1745,7 +1738,6 @@ afr_sh_entry_impunge_entry (call_frame_t *frame, xlator_t *this,
int op_ret = -1;
mode_t entry_mode = 0;
- priv = this->private;
local = frame->local;
sh = &local->self_heal;
diff --git a/xlators/cluster/afr/src/afr-self-heald.c b/xlators/cluster/afr/src/afr-self-heald.c
index 30450d97c8..dd0dd86da0 100644
--- a/xlators/cluster/afr/src/afr-self-heald.c
+++ b/xlators/cluster/afr/src/afr-self-heald.c
@@ -115,11 +115,8 @@ _perform_self_heal (xlator_t *this, loc_t *parentloc, gf_dirent_t *entries,
struct iatt parent = {0};;
int ret = 0;
loc_t entry_loc = {0};
- afr_private_t *priv = NULL;
dict_t *xattr_req = NULL;
- priv = this->private;
-
xattr_req = dict_new ();
if (!xattr_req) {
ret = -1;
@@ -525,3 +522,4 @@ afr_set_root_gfid (dict_t *dict)
return ret;
}
+
diff --git a/xlators/cluster/afr/src/afr-transaction.c b/xlators/cluster/afr/src/afr-transaction.c
index 8ec634fd4b..d3960dcff4 100644
--- a/xlators/cluster/afr/src/afr-transaction.c
+++ b/xlators/cluster/afr/src/afr-transaction.c
@@ -336,15 +336,12 @@ afr_changelog_post_op_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
afr_internal_lock_t *int_lock = NULL;
afr_private_t *priv = NULL;
afr_local_t *local = NULL;
- int child_index = 0;
int call_count = -1;
priv = this->private;
local = frame->local;
int_lock = &local->internal_lock;
- child_index = (long) cookie;
-
LOCK (&frame->lock);
{
call_count = --local->call_count;
diff --git a/xlators/cluster/afr/src/afr.c b/xlators/cluster/afr/src/afr.c
index 8bb94e2053..30da3fc729 100644
--- a/xlators/cluster/afr/src/afr.c
+++ b/xlators/cluster/afr/src/afr.c
@@ -178,7 +178,7 @@ init (xlator_t *this)
xlator_list_t * trav = NULL;
int i = 0;
int ret = -1;
- int op_errno = 0;
+ GF_UNUSED int op_errno = 0;
xlator_t * read_subvol = NULL;
xlator_t * fav_child = NULL;
diff --git a/xlators/cluster/afr/src/pump.c b/xlators/cluster/afr/src/pump.c
index 63c89b3c7b..dbf86b0a2a 100644
--- a/xlators/cluster/afr/src/pump.c
+++ b/xlators/cluster/afr/src/pump.c
@@ -249,13 +249,11 @@ static int
pump_update_resume_state (xlator_t *this, const char *path)
{
afr_private_t *priv = NULL;
- pump_private_t *pump_priv = NULL;
pump_state_t state;
const char *resume_path = NULL;
priv = this->private;
- pump_priv = priv->pump_private;
state = pump_get_state ();
@@ -284,14 +282,10 @@ pump_update_resume_state (xlator_t *this, const char *path)
static gf_boolean_t
is_pump_traversal_allowed (xlator_t *this, const char *path)
{
- afr_private_t *priv = NULL;
-
pump_state_t state;
const char *resume_path = NULL;
gf_boolean_t ret = _gf_true;
- priv = this->private;
-
state = pump_get_state ();
if (state == PUMP_STATE_RESUME) {
@@ -472,12 +466,8 @@ out:
static int
pump_update_resume_path (xlator_t *this)
{
- afr_private_t *priv = NULL;
-
const char *resume_path = NULL;
- priv = this->private;
-
resume_path = pump_get_resume_path (this);
if (resume_path) {
@@ -2386,7 +2376,7 @@ init (xlator_t *this)
xlator_list_t * trav = NULL;
int i = 0;
int ret = -1;
- int op_errno = 0;
+ GF_UNUSED int op_errno = 0;
int source_child = 0;
diff --git a/xlators/cluster/dht/src/dht-common.c b/xlators/cluster/dht/src/dht-common.c
index 671a9b2094..6cf1d0c85a 100644
--- a/xlators/cluster/dht/src/dht-common.c
+++ b/xlators/cluster/dht/src/dht-common.c
@@ -1031,7 +1031,6 @@ dht_lookup (call_frame_t *frame, xlator_t *this,
{
xlator_t *subvol = NULL;
xlator_t *hashed_subvol = NULL;
- xlator_t *cached_subvol = NULL;
dht_local_t *local = NULL;
dht_conf_t *conf = NULL;
int ret = -1;
@@ -1083,7 +1082,6 @@ dht_lookup (call_frame_t *frame, xlator_t *this,
}
- cached_subvol = local->cached_subvol;
if (!hashed_subvol)
hashed_subvol = dht_subvol_get_hashed (this, loc);
local->hashed_subvol = hashed_subvol;
diff --git a/xlators/cluster/dht/src/nufa.c b/xlators/cluster/dht/src/nufa.c
index 9dcf224d17..2f196951a5 100644
--- a/xlators/cluster/dht/src/nufa.c
+++ b/xlators/cluster/dht/src/nufa.c
@@ -150,7 +150,6 @@ nufa_lookup (call_frame_t *frame, xlator_t *this,
loc_t *loc, dict_t *xattr_req)
{
xlator_t *hashed_subvol = NULL;
- xlator_t *cached_subvol = NULL;
xlator_t *subvol = NULL;
dht_local_t *local = NULL;
dht_conf_t *conf = NULL;
@@ -182,7 +181,6 @@ nufa_lookup (call_frame_t *frame, xlator_t *this,
}
hashed_subvol = dht_subvol_get_hashed (this, &local->loc);
- cached_subvol = local->cached_subvol;
local->hashed_subvol = hashed_subvol;
diff --git a/xlators/features/quota/src/quota.c b/xlators/features/quota/src/quota.c
index ba691e3895..c15d59f545 100644
--- a/xlators/features/quota/src/quota.c
+++ b/xlators/features/quota/src/quota.c
@@ -144,8 +144,8 @@ out:
quota_local_t *
quota_local_new ()
{
- quota_local_t *local = NULL;
- int32_t ret = 0;
+ quota_local_t *local = NULL;
+ GF_UNUSED int32_t ret = 0;
QUOTA_LOCAL_ALLOC_OR_GOTO (local, quota_local_t, err);
err:
@@ -156,8 +156,8 @@ err:
quota_dentry_t *
__quota_dentry_new (quota_inode_ctx_t *ctx, char *name, ino_t par)
{
- quota_dentry_t *dentry = NULL;
- int32_t ret = 0;
+ quota_dentry_t *dentry = NULL;
+ GF_UNUSED int32_t ret = 0;
QUOTA_ALLOC_OR_GOTO (dentry, quota_dentry_t, err);
='#n1332'>1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709
/*
 * Broadcom BCM570x Ethernet Driver for U-Boot.
 * Support 5701, 5702, 5703, and 5704. Single instance driver.
 * Copyright (C) 2002 James F. Dougherty (jfd@broadcom.com)
 */

#include <common.h>

#if (CONFIG_COMMANDS & CFG_CMD_NET) && (!defined(CONFIG_NET_MULTI)) && \
	defined(CONFIG_BCM570x)

#ifdef CONFIG_BMW
#include <mpc824x.h>
#endif
#include <net.h>
#include "bcm570x_mm.h"
#include "bcm570x_autoneg.h"
#include <pci.h>
#include <malloc.h>



/*
 * PCI Registers and definitions.
 */
#define PCI_CMD_MASK	0xffff0000	/* mask to save status bits */
#define PCI_ANY_ID (~0)

/*
 * PCI memory base for Ethernet device as well as device Interrupt.
 */
#define BCM570X_MBAR 	0x80100000
#define BCM570X_ILINE   1



#define SECOND_USEC	1000000
#define MAX_PACKET_SIZE 1600
#define MAX_UNITS       4

/* Globals to this module */
int initialized = 0;
unsigned int ioBase = 0;
volatile PLM_DEVICE_BLOCK    pDevice = NULL;        /* 570x softc */
volatile PUM_DEVICE_BLOCK    pUmDevice = NULL;

/* Used to pass the full-duplex flag, etc. */
int line_speed[MAX_UNITS] = {0,0,0,0};
static int full_duplex[MAX_UNITS] = {1,1,1,1};
static int rx_flow_control[MAX_UNITS] = {0,0,0,0};
static int tx_flow_control[MAX_UNITS] = {0,0,0,0};
static int auto_flow_control[MAX_UNITS] = {0,0,0,0};
static int tx_checksum[MAX_UNITS] = {1,1,1,1};
static int rx_checksum[MAX_UNITS] = {1,1,1,1};
static int auto_speed[MAX_UNITS] = {1,1,1,1};

#if JUMBO_FRAMES
/* Jumbo MTU for interfaces. */
static int mtu[MAX_UNITS] = {0,0,0,0};
#endif

/* Turn on Wake-on lan for a device unit */
static int enable_wol[MAX_UNITS] = {0,0,0,0};

#define TX_DESC_CNT DEFAULT_TX_PACKET_DESC_COUNT
static unsigned int tx_pkt_desc_cnt[MAX_UNITS] =
	{TX_DESC_CNT,TX_DESC_CNT,TX_DESC_CNT, TX_DESC_CNT};

#define RX_DESC_CNT DEFAULT_STD_RCV_DESC_COUNT
static unsigned int rx_std_desc_cnt[MAX_UNITS] =
	{RX_DESC_CNT,RX_DESC_CNT,RX_DESC_CNT,RX_DESC_CNT};

static unsigned int rx_adaptive_coalesce[MAX_UNITS] = {1,1,1,1};

#if T3_JUMBO_RCV_RCB_ENTRY_COUNT
#define JBO_DESC_CNT DEFAULT_JUMBO_RCV_DESC_COUNT
static unsigned int rx_jumbo_desc_cnt[MAX_UNITS] =
	{JBO_DESC_CNT, JBO_DESC_CNT, JBO_DESC_CNT, JBO_DESC_CNT};
#endif
#define RX_COAL_TK DEFAULT_RX_COALESCING_TICKS
static unsigned int rx_coalesce_ticks[MAX_UNITS] =
	{RX_COAL_TK, RX_COAL_TK, RX_COAL_TK, RX_COAL_TK};

#define RX_COAL_FM DEFAULT_RX_MAX_COALESCED_FRAMES
static unsigned int rx_max_coalesce_frames[MAX_UNITS] =
	{RX_COAL_FM, RX_COAL_FM, RX_COAL_FM, RX_COAL_FM};

#define TX_COAL_TK DEFAULT_TX_COALESCING_TICKS
static unsigned int tx_coalesce_ticks[MAX_UNITS] =
	{TX_COAL_TK, TX_COAL_TK, TX_COAL_TK, TX_COAL_TK};

#define TX_COAL_FM DEFAULT_TX_MAX_COALESCED_FRAMES
static unsigned int tx_max_coalesce_frames[MAX_UNITS] =
	{TX_COAL_FM, TX_COAL_FM, TX_COAL_FM, TX_COAL_FM};

#define ST_COAL_TK DEFAULT_STATS_COALESCING_TICKS
static unsigned int stats_coalesce_ticks[MAX_UNITS] =
	{ST_COAL_TK, ST_COAL_TK, ST_COAL_TK, ST_COAL_TK};



/*
 * Legitimate values for BCM570x device types
 */
typedef enum {
	BCM5700VIGIL = 0,
	BCM5700A6,
	BCM5700T6,
	BCM5700A9,
	BCM5700T9,
	BCM5700,
	BCM5701A5,
	BCM5701T1,
	BCM5701T8,
	BCM5701A7,
	BCM5701A10,
	BCM5701A12,
	BCM5701,
	BCM5702,
	BCM5703,
	BCM5703A31,
	TC996T,
	TC996ST,
	TC996SSX,
	TC996SX,
	TC996BT,
	TC997T,
	TC997SX,
	TC1000T,
	TC940BR01,
	TC942BR01,
	NC6770,
	NC7760,
	NC7770,
	NC7780
} board_t;

/* Chip-Rev names for each device-type */
static struct {
    char* name;
} chip_rev[] = {
       {"BCM5700VIGIL"},
       {"BCM5700A6"},
       {"BCM5700T6"},
       {"BCM5700A9"},
       {"BCM5700T9"},
       {"BCM5700"},
       {"BCM5701A5"},
       {"BCM5701T1"},
       {"BCM5701T8"},
       {"BCM5701A7"},
       {"BCM5701A10"},
       {"BCM5701A12"},
       {"BCM5701"},
       {"BCM5702"},
       {"BCM5703"},
       {"BCM5703A31"},
       {"TC996T"},
       {"TC996ST"},
       {"TC996SSX"},
       {"TC996SX"},
       {"TC996BT"},
       {"TC997T"},
       {"TC997SX"},
       {"TC1000T"},
       {"TC940BR01"},
       {"TC942BR01"},
       {"NC6770"},
       {"NC7760"},
       {"NC7770"},
       {"NC7780"},
       {0}
};


/* indexed by board_t, above */
static struct {
    char *name;
} board_info[] = {
	{ "Broadcom Vigil B5700 1000Base-T" },
	{ "Broadcom BCM5700 1000Base-T" },
	{ "Broadcom BCM5700 1000Base-SX" },
	{ "Broadcom BCM5700 1000Base-SX" },
	{ "Broadcom BCM5700 1000Base-T" },
	{ "Broadcom BCM5700" },
	{ "Broadcom BCM5701 1000Base-T" },
	{ "Broadcom BCM5701 1000Base-T" },
	{ "Broadcom BCM5701 1000Base-T" },
	{ "Broadcom BCM5701 1000Base-SX" },
	{ "Broadcom BCM5701 1000Base-T" },
	{ "Broadcom BCM5701 1000Base-T" },
	{ "Broadcom BCM5701" },
	{ "Broadcom BCM5702 1000Base-T" },
	{ "Broadcom BCM5703 1000Base-T" },
	{ "Broadcom BCM5703 1000Base-SX" },
	{ "3Com 3C996 10/100/1000 Server NIC" },
	{ "3Com 3C996 10/100/1000 Server NIC" },
	{ "3Com 3C996 Gigabit Fiber-SX Server NIC" },
	{ "3Com 3C996 Gigabit Fiber-SX Server NIC" },
	{ "3Com 3C996B Gigabit Server NIC" },
	{ "3Com 3C997 Gigabit Server NIC" },
	{ "3Com 3C997 Gigabit Fiber-SX Server NIC" },
	{ "3Com 3C1000 Gigabit NIC" },
	{ "3Com 3C940 Gigabit LOM (21X21)" },
	{ "3Com 3C942 Gigabit LOM (31X31)" },
	{ "Compaq NC6770 Gigabit Server Adapter" },
	{ "Compaq NC7760 Gigabit Server Adapter" },
	{ "Compaq NC7770 Gigabit Server Adapter" },
	{ "Compaq NC7780 Gigabit Server Adapter" },
	{ 0 },
};

/* PCI Devices which use the 570x chipset */
struct pci_device_table {
    unsigned short vendor_id, device_id; /* Vendor/DeviceID */
    unsigned short subvendor, subdevice; /* Subsystem ID's or PCI_ANY_ID */
    unsigned int class, class_mask; /* (class,subclass,prog-if) triplet */
    unsigned long board_id;	    /* Data private to the driver */
    int io_size, min_latency;
} bcm570xDevices[] = {
	{0x14e4, 0x1644, 0x1014, 0x0277, 0, 0, BCM5700VIGIL ,128,32},
	{0x14e4, 0x1644, 0x14e4, 0x1644, 0, 0, BCM5700A6 ,128,32},
	{0x14e4, 0x1644, 0x14e4, 0x2, 0, 0, BCM5700T6 ,128,32},
	{0x14e4, 0x1644, 0x14e4, 0x3, 0, 0, BCM5700A9 ,128,32},
	{0x14e4, 0x1644, 0x14e4, 0x4, 0, 0, BCM5700T9 ,128,32},
	{0x14e4, 0x1644, 0x1028, 0xd1, 0, 0, BCM5700 ,128,32},
	{0x14e4, 0x1644, 0x1028, 0x0106, 0, 0, BCM5700 ,128,32},
	{0x14e4, 0x1644, 0x1028, 0x0109, 0, 0, BCM5700 ,128,32},
	{0x14e4, 0x1644, 0x1028, 0x010a, 0, 0, BCM5700 ,128,32},
	{0x14e4, 0x1644, 0x10b7, 0x1000, 0, 0, TC996T ,128,32},
	{0x14e4, 0x1644, 0x10b7, 0x1001, 0, 0, TC996ST ,128,32},
	{0x14e4, 0x1644, 0x10b7, 0x1002, 0, 0, TC996SSX ,128,32},
	{0x14e4, 0x1644, 0x10b7, 0x1003, 0, 0, TC997T ,128,32},
	{0x14e4, 0x1644, 0x10b7, 0x1005, 0, 0, TC997SX ,128,32},
	{0x14e4, 0x1644, 0x10b7, 0x1008, 0, 0, TC942BR01 ,128,32},
	{0x14e4, 0x1644, PCI_ANY_ID, PCI_ANY_ID, 0, 0, BCM5700 ,128,32},
	{0x14e4, 0x1645, 0x14e4, 1, 0, 0, BCM5701A5 ,128,32},
	{0x14e4, 0x1645, 0x14e4, 5, 0, 0, BCM5701T1 ,128,32},
	{0x14e4, 0x1645, 0x14e4, 6, 0, 0, BCM5701T8 ,128,32},
	{0x14e4, 0x1645, 0x14e4, 7, 0, 0, BCM5701A7 ,128,32},
	{0x14e4, 0x1645, 0x14e4, 8, 0, 0, BCM5701A10 ,128,32},
	{0x14e4, 0x1645, 0x14e4, 0x8008, 0, 0, BCM5701A12 ,128,32},
	{0x14e4, 0x1645, 0x0e11, 0xc1, 0, 0, NC6770 ,128,32},
	{0x14e4, 0x1645, 0x0e11, 0x7c, 0, 0, NC7770 ,128,32},
	{0x14e4, 0x1645, 0x0e11, 0x85, 0, 0, NC7780 ,128,32},
	{0x14e4, 0x1645, 0x1028, 0x0121, 0, 0, BCM5701 ,128,32},
	{0x14e4, 0x1645, 0x10b7, 0x1004, 0, 0, TC996SX ,128,32},
	{0x14e4, 0x1645, 0x10b7, 0x1006, 0, 0, TC996BT ,128,32},
	{0x14e4, 0x1645, 0x10b7, 0x1007, 0, 0, TC1000T ,128,32},
	{0x14e4, 0x1645, 0x10b7, 0x1008, 0, 0, TC940BR01 ,128,32},
	{0x14e4, 0x1645, PCI_ANY_ID, PCI_ANY_ID, 0, 0, BCM5701 ,128,32},
	{0x14e4, 0x1646, 0x14e4, 0x8009, 0, 0, BCM5702 ,128,32},
	{0x14e4, 0x1646, 0x0e11, 0xbb, 0, 0, NC7760 ,128,32},
	{0x14e4, 0x1646, PCI_ANY_ID, PCI_ANY_ID, 0, 0, BCM5702 ,128,32},
	{0x14e4, 0x16a6, 0x14e4, 0x8009, 0, 0, BCM5702 ,128,32},
	{0x14e4, 0x16a6, 0x0e11, 0xbb, 0, 0, NC7760 ,128,32},
	{0x14e4, 0x16a6, PCI_ANY_ID, PCI_ANY_ID, 0, 0, BCM5702 ,128,32},
	{0x14e4, 0x1647, 0x14e4, 0x0009, 0, 0, BCM5703 ,128,32},
	{0x14e4, 0x1647, 0x14e4, 0x000a, 0, 0, BCM5703A31 ,128,32},
	{0x14e4, 0x1647, 0x14e4, 0x000b, 0, 0, BCM5703 ,128,32},
	{0x14e4, 0x1647, 0x14e4, 0x800a, 0, 0, BCM5703 ,128,32},
	{0x14e4, 0x1647, 0x0e11, 0x9a, 0, 0, NC7770 ,128,32},
	{0x14e4, 0x1647, 0x0e11, 0x99, 0, 0, NC7780 ,128,32},
	{0x14e4, 0x1647, PCI_ANY_ID, PCI_ANY_ID, 0, 0, BCM5703 ,128,32},
	{0x14e4, 0x16a7, 0x14e4, 0x0009, 0, 0, BCM5703 ,128,32},
	{0x14e4, 0x16a7, 0x14e4, 0x000a, 0, 0, BCM5703A31 ,128,32},
	{0x14e4, 0x16a7, 0x14e4, 0x000b, 0, 0, BCM5703 ,128,32},
	{0x14e4, 0x16a7, 0x14e4, 0x800a, 0, 0, BCM5703 ,128,32},
	{0x14e4, 0x16a7, 0x0e11, 0x9a, 0, 0, NC7770 ,128,32},
	{0x14e4, 0x16a7, 0x0e11, 0x99, 0, 0, NC7780 ,128,32},
	{0x14e4, 0x16a7, PCI_ANY_ID, PCI_ANY_ID, 0, 0, BCM5703 ,128,32}
};

#define n570xDevices   (sizeof(bcm570xDevices)/sizeof(bcm570xDevices[0]))



/*
 * Allocate a packet buffer from the bcm570x packet pool.
 */
void *
bcm570xPktAlloc(int u, int pksize)
{
    return malloc(pksize);
}

/*
 * Free a packet previously allocated from the bcm570x packet
 * buffer pool.
 */
void
bcm570xPktFree(int u, void *p)
{
    free(p);
}

int
bcm570xReplenishRxBuffers(PUM_DEVICE_BLOCK pUmDevice)
{
    PLM_PACKET pPacket;
    PUM_PACKET pUmPacket;
    void *skb;
    int queue_rx = 0;
    int ret = 0;

    while ((pUmPacket = (PUM_PACKET)
	    QQ_PopHead(&pUmDevice->rx_out_of_buf_q.Container)) != 0) {

	pPacket = (PLM_PACKET) pUmPacket;

	/* reuse an old skb */
	if (pUmPacket->skbuff) {
	    QQ_PushTail(&pDevice->RxPacketFreeQ.Container, pPacket);
	    queue_rx = 1;
	    continue;
	}
	if ( ( skb = bcm570xPktAlloc(pUmDevice->index,
				     pPacket->u.Rx.RxBufferSize + 2)) == 0) {
	    QQ_PushHead(&pUmDevice->rx_out_of_buf_q.Container,pPacket);
	    printf("NOTICE: Out of RX memory.\n");
	    ret = 1;
	    break;
	}

	pUmPacket->skbuff = skb;
	QQ_PushTail(&pDevice->RxPacketFreeQ.Container, pPacket);
	queue_rx = 1;
    }

    if (queue_rx) {
	LM_QueueRxPackets(pDevice);
    }

    return ret;
}

/*
 * Probe, Map, and Init 570x device.
 */
int eth_init(bd_t *bis)
{
    int i, rv, devFound = FALSE;
    pci_dev_t  devbusfn;
    unsigned short status;

    /* Find PCI device, if it exists, configure ...  */
    for( i = 0; i < n570xDevices; i++){
	devbusfn = pci_find_device(bcm570xDevices[i].vendor_id,
				   bcm570xDevices[i].device_id, 0);
	if(devbusfn == -1) {
	    continue; /* No device of that vendor/device ID */
	} else {

	    /* Set ILINE */
	    pci_write_config_byte(devbusfn,
				  PCI_INTERRUPT_LINE, BCM570X_ILINE);

	    /*
	     * 0x10 - 0x14 define one 64-bit MBAR.
	     * 0x14 is the higher-order address bits of the BAR.
	     */
	    pci_write_config_dword(devbusfn,
				   PCI_BASE_ADDRESS_1, 0);

	    ioBase = BCM570X_MBAR;

	    pci_write_config_dword(devbusfn,
				   PCI_BASE_ADDRESS_0, ioBase);

	    /*
	     * Enable PCI memory, IO, and Master -- don't
	     * reset any status bits in doing so.
	     */
	    pci_read_config_word(devbusfn,
				 PCI_COMMAND, &status);

	    status |= PCI_COMMAND_MEMORY|PCI_COMMAND_MASTER;

	    pci_write_config_word(devbusfn,
				  PCI_COMMAND, status);

	    printf("\n%s: bus %d, device %d, function %d: MBAR=0x%x\n",
		   board_info[bcm570xDevices[i].board_id].name,
		   PCI_BUS(devbusfn),
		   PCI_DEV(devbusfn),
		   PCI_FUNC(devbusfn),
		   ioBase);

	    /* Allocate once, but always clear on init */
	    if (!pDevice) {
		pDevice = malloc(sizeof(UM_DEVICE_BLOCK));
		pUmDevice = (PUM_DEVICE_BLOCK)pDevice;
		memset(pDevice, 0x0, sizeof(UM_DEVICE_BLOCK));
	    }

	    /* Configure pci dev structure */
	    pUmDevice->pdev = devbusfn;
	    pUmDevice->index = 0;
	    pUmDevice->tx_pkt = 0;
	    pUmDevice->rx_pkt = 0;
	    devFound = TRUE;
	    break;
	}
    }

    if(!devFound){
	printf("eth_init: FAILURE: no BCM570x Ethernet devices found.\n");
	return -1;
    }

    /* Setup defaults for chip */
    pDevice->TaskToOffload = LM_TASK_OFFLOAD_NONE;

    if (pDevice->ChipRevId == T3_CHIP_ID_5700_B0) {
	pDevice->TaskToOffload = LM_TASK_OFFLOAD_NONE;
    } else {

	if (rx_checksum[i]) {
	    pDevice->TaskToOffload |=
		LM_TASK_OFFLOAD_RX_TCP_CHECKSUM |
		LM_TASK_OFFLOAD_RX_UDP_CHECKSUM;
	}

	if (tx_checksum[i]) {
	    pDevice->TaskToOffload |=
		LM_TASK_OFFLOAD_TX_TCP_CHECKSUM |
		LM_TASK_OFFLOAD_TX_UDP_CHECKSUM;
	    pDevice->NoTxPseudoHdrChksum = TRUE;
	}
    }

    /* Set Device PCI Memory base address */
    pDevice->pMappedMemBase = (PLM_UINT8) ioBase;

    /* Pull down adapter info */
    if ((rv = LM_GetAdapterInfo(pDevice)) != LM_STATUS_SUCCESS) {
	printf("bcm570xEnd: LM_GetAdapterInfo failed: rv=%d!\n", rv );
	return -2;
    }

    /* Lock not needed */
    pUmDevice->do_global_lock = 0;

    if (T3_ASIC_REV(pUmDevice->lm_dev.ChipRevId) == T3_ASIC_REV_5700) {
	/* The 5700 chip works best without interleaved register */
	/* accesses on certain machines. */
	pUmDevice->do_global_lock = 1;
    }

    /* Setup timer delays */
    if (T3_ASIC_REV(pDevice->ChipRevId) == T3_ASIC_REV_5701) {
	pDevice->UseTaggedStatus = TRUE;
	pUmDevice->timer_interval = CFG_HZ;
    }
    else {
	pUmDevice->timer_interval = CFG_HZ / 50;
    }

    /* Grab name .... */
    pUmDevice->name =
	(char*)malloc(strlen(board_info[bcm570xDevices[i].board_id].name)+1);
    strcpy(pUmDevice->name,board_info[bcm570xDevices[i].board_id].name);

    memcpy(pDevice->NodeAddress, bis->bi_enetaddr, 6);
    LM_SetMacAddress(pDevice, bis->bi_enetaddr);
    /* Init queues  .. */
    QQ_InitQueue(&pUmDevice->rx_out_of_buf_q.Container,
		 MAX_RX_PACKET_DESC_COUNT);
    pUmDevice->rx_last_cnt = pUmDevice->tx_last_cnt = 0;

    /* delay for 4 seconds */
    pUmDevice->delayed_link_ind =
	(4 * CFG_HZ) / pUmDevice->timer_interval;

    pUmDevice->adaptive_expiry =
	CFG_HZ / pUmDevice->timer_interval;

    /* Sometimes we get spurious ints. after reset when link is down. */
    /* This field tells the isr to service the int. even if there is */
    /* no status block update. */
    pUmDevice->adapter_just_inited =
	(3 * CFG_HZ) / pUmDevice->timer_interval;

    /* Initialize 570x */
    if (LM_InitializeAdapter(pDevice) != LM_STATUS_SUCCESS) {
	printf("ERROR: Adapter initialization failed.\n");
	return ERROR;
    }

    /* Enable chip ISR */
    LM_EnableInterrupt(pDevice);

    /* Clear MC table */
    LM_MulticastClear(pDevice);

    /* Enable Multicast */
    LM_SetReceiveMask(pDevice,
		      pDevice->ReceiveMask | LM_ACCEPT_ALL_MULTICAST);

    pUmDevice->opened = 1;
    pUmDevice->tx_full = 0;
    pUmDevice->tx_pkt = 0;
    pUmDevice->rx_pkt = 0;
    printf("eth%d: %s @0x%lx,",
	   pDevice->index, pUmDevice->name, (unsigned long)ioBase);
    printf(	"node addr ");
    for (i = 0; i < 6; i++) {
	printf("%2.2x", pDevice->NodeAddress[i]);
    }
    printf("\n");

    printf("eth%d: ", pDevice->index);
    printf("%s with ",
	   chip_rev[bcm570xDevices[i].board_id].name);

    if ((pDevice->PhyId & PHY_ID_MASK) == PHY_BCM5400_PHY_ID)
	printf("Broadcom BCM5400 Copper ");
    else if ((pDevice->PhyId & PHY_ID_MASK) == PHY_BCM5401_PHY_ID)
	printf("Broadcom BCM5401 Copper ");
    else if ((pDevice->PhyId & PHY_ID_MASK) == PHY_BCM5411_PHY_ID)
	printf("Broadcom BCM5411 Copper ");
    else if ((pDevice->PhyId & PHY_ID_MASK) == PHY_BCM5701_PHY_ID)
	printf("Broadcom BCM5701 Integrated Copper ");
    else if ((pDevice->PhyId & PHY_ID_MASK) == PHY_BCM5703_PHY_ID)
        printf("Broadcom BCM5703 Integrated Copper ");
    else if ((pDevice->PhyId & PHY_ID_MASK) == PHY_BCM8002_PHY_ID)
	printf("Broadcom BCM8002 SerDes ");
    else if (pDevice->EnableTbi)
	printf("Agilent HDMP-1636 SerDes ");
    else
	printf("Unknown ");
    printf("transceiver found\n");

    printf("eth%d: %s, MTU: %d,",
	   pDevice->index, pDevice->BusSpeedStr, 1500);

    if ((pDevice->ChipRevId != T3_CHIP_ID_5700_B0) &&
	rx_checksum[i])
	printf("Rx Checksum ON\n");
    else
	printf("Rx Checksum OFF\n");
    initialized++;

    return 0;
}

/* Ethernet Interrupt service routine */
void
eth_isr(void)
{
    LM_UINT32 oldtag, newtag;
    int i;

    pUmDevice->interrupt = 1;

    if (pDevice->UseTaggedStatus) {
	if ((pDevice->pStatusBlkVirt->Status & STATUS_BLOCK_UPDATED) ||
	    pUmDevice->adapter_just_inited) {
            MB_REG_WR(pDevice, Mailbox.Interrupt[0].Low, 1);
            oldtag = pDevice->pStatusBlkVirt->StatusTag;

            for (i = 0; ; i++) {
                pDevice->pStatusBlkVirt->Status &= ~STATUS_BLOCK_UPDATED;
                LM_ServiceInterrupts(pDevice);
                newtag = pDevice->pStatusBlkVirt->StatusTag;
                if ((newtag == oldtag) || (i > 50)) {
                    MB_REG_WR(pDevice, Mailbox.Interrupt[0].Low, newtag << 24);
                    if (pDevice->UndiFix) {
                        REG_WR(pDevice, Grc.LocalCtrl,
			       pDevice->GrcLocalCtrl | 0x2);
                    }
                    break;
                 }
		oldtag = newtag;
	    }
	}
    }
    else {
	while (pDevice->pStatusBlkVirt->Status & STATUS_BLOCK_UPDATED) {
	    unsigned int dummy;

	    pDevice->pMemView->Mailbox.Interrupt[0].Low = 1;
	    pDevice->pStatusBlkVirt->Status &= ~STATUS_BLOCK_UPDATED;
	    LM_ServiceInterrupts(pDevice);
	    pDevice->pMemView->Mailbox.Interrupt[0].Low = 0;
	    dummy = pDevice->pMemView->Mailbox.Interrupt[0].Low;
	}
    }

    /* Allocate new RX buffers */
    if (QQ_GetEntryCnt(&pUmDevice->rx_out_of_buf_q.Container)) {
	bcm570xReplenishRxBuffers(pUmDevice);
    }

    /* Queue packets */
    if (QQ_GetEntryCnt(&pDevice->RxPacketFreeQ.Container)) {
	LM_QueueRxPackets(pDevice);
    }

    if (pUmDevice->tx_queued) {
	pUmDevice->tx_queued = 0;
    }

    if(pUmDevice->tx_full){
	if(pDevice->LinkStatus != LM_STATUS_LINK_DOWN){
	    printf("NOTICE: tx was previously blocked, restarting MUX\n");
	    pUmDevice->tx_full = 0;
	}
    }

    pUmDevice->interrupt = 0;

}

int
eth_send(volatile void *packet, int length)
{
    int status = 0;
#if ET_DEBUG
    unsigned char* ptr = (unsigned char*)packet;
#endif
    PLM_PACKET pPacket;
    PUM_PACKET pUmPacket;

    /* Link down, return */
    while(pDevice->LinkStatus == LM_STATUS_LINK_DOWN) {
#if 0
        printf("eth%d: link down - check cable or link partner.\n",
               pUmDevice->index);
#endif
	eth_isr();

	/* Wait to see link for one-half a second before sending ... */
	udelay(1500000);

    }

    /* Clear sent flag */
    pUmDevice->tx_pkt = 0;

    /* Previously blocked */
    if(pUmDevice->tx_full){
	printf("eth%d: tx blocked.\n", pUmDevice->index);
	return 0;
    }

    pPacket = (PLM_PACKET)
	QQ_PopHead(&pDevice->TxPacketFreeQ.Container);

    if (pPacket == 0) {
	pUmDevice->tx_full = 1;
	printf("bcm570xEndSend: TX full!\n");
	return 0;
    }

    if (pDevice->SendBdLeft.counter == 0) {
	pUmDevice->tx_full = 1;
	printf("bcm570xEndSend: no more TX descriptors!\n");
	QQ_PushHead(&pDevice->TxPacketFreeQ.Container, pPacket);
	return 0;
    }

    if (length <= 0){
	printf("eth: bad packet size: %d\n", length);
	goto out;
    }

    /* Get packet buffers and fragment list */
    pUmPacket = (PUM_PACKET) pPacket;
    /* Single DMA Descriptor transmit.
     * Fragments may be provided, but one DMA descriptor max is
     * used to send the packet.
     */
    if (MM_CoalesceTxBuffer (pDevice, pPacket) != LM_STATUS_SUCCESS) {
        if (pUmPacket->skbuff == NULL){
	    /* Packet was discarded */
	    printf("TX: failed (1)\n");
	    status = 1;
	} else{
	    printf("TX: failed (2)\n");
	    status = 2;
	}
        QQ_PushHead (&pDevice->TxPacketFreeQ.Container, pPacket);
        return status;
    }

    /* Copy packet to DMA buffer */
    memset(pUmPacket->skbuff, 0x0, MAX_PACKET_SIZE);
    memcpy((void*)pUmPacket->skbuff, (void*)packet, length);
    pPacket->PacketSize = length;
    pPacket->Flags |= SND_BD_FLAG_END|SND_BD_FLAG_COAL_NOW;
    pPacket->u.Tx.FragCount = 1;
    /* We've already provided a frame ready for transmission */
    pPacket->Flags &= ~SND_BD_FLAG_TCP_UDP_CKSUM;

    if ( LM_SendPacket(pDevice, pPacket) == LM_STATUS_FAILURE){
        /*
         *  A lower level send failure will push the packet descriptor back
         *  in the free queue, so just deal with the VxWorks clusters.
         */
        if (pUmPacket->skbuff == NULL){
	    printf("TX failed (1)!\n");
	    /* Packet was discarded */
	    status = 3;
	} else {
	    /* A resource problem ... */
	    printf("TX failed (2)!\n");
	    status = 4;
	}

	if (QQ_GetEntryCnt(&pDevice->TxPacketFreeQ.Container) == 0) {
	    printf("TX: emptyQ!\n");
	    pUmDevice->tx_full = 1;
	}
    }

    while(pUmDevice->tx_pkt == 0){
	/* Service TX */
	eth_isr();
    }
#if ET_DEBUG
    printf("eth_send: 0x%x, %d bytes\n"
	   "[%x %x %x %x %x %x %x %x %x %x %x %x %x %x %x %x] ...\n",
	   (int)pPacket, length,
	   ptr[0],ptr[1],ptr[2],ptr[3],ptr[4],ptr[5],
	   ptr[6],ptr[7],ptr[8],ptr[9],ptr[10],ptr[11],ptr[12],
	   ptr[13],ptr[14],ptr[15]);
#endif
    pUmDevice->tx_pkt = 0;
    QQ_PushHead(&pDevice->TxPacketFreeQ.Container, pPacket);

    /* Done with send */
 out:
    return status;
}


/* Ethernet receive */
int
eth_rx(void)
{
    PLM_PACKET          pPacket = NULL;
    PUM_PACKET          pUmPacket = NULL;
    void *skb;
    int size=0;

    while(TRUE) {

    bcm570x_service_isr:
	/* Pull down packet if it is there */
	eth_isr();

	/* Indicate RX packets called */
	if(pUmDevice->rx_pkt){
	    /* printf("eth_rx: got a packet...\n"); */
	    pUmDevice->rx_pkt = 0;
	} else {
	    /* printf("eth_rx: waiting for packet...\n"); */
	    goto bcm570x_service_isr;
	}

	pPacket = (PLM_PACKET)
	    QQ_PopHead(&pDevice->RxPacketReceivedQ.Container);

	if (pPacket == 0){
	    printf("eth_rx: empty packet!\n");
	    goto bcm570x_service_isr;
	}

	pUmPacket = (PUM_PACKET) pPacket;
#if ET_DEBUG
	printf("eth_rx: packet @0x%x\n",
	       (int)pPacket);
#endif
	/* If the packet generated an error, reuse buffer */
	if ((pPacket->PacketStatus != LM_STATUS_SUCCESS) ||
	    ((size = pPacket->PacketSize) > pDevice->RxMtu)) {

	    /* reuse skb */
	    QQ_PushTail(&pDevice->RxPacketFreeQ.Container, pPacket);
	    printf("eth_rx: error in packet dma!\n");
	    goto bcm570x_service_isr;
	}

	/* Set size and address */
	skb = pUmPacket->skbuff;
	size = pPacket->PacketSize;

	/* Pass the packet up to the protocol
	 * layers.
	 */
	NetReceive(skb, size);

	/* Free packet buffer */
	bcm570xPktFree (pUmDevice->index, skb);
	pUmPacket->skbuff = NULL;

	/* Reuse SKB */
	QQ_PushTail(&pDevice->RxPacketFreeQ.Container, pPacket);

	return 0; /* Got a packet, bail ... */
    }
    return size;
}



/* Shut down device */
void
eth_halt(void)
{
    int i;
    if ( initialized)
    if (pDevice && pUmDevice && pUmDevice->opened){
	printf("\neth%d:%s,", pUmDevice->index, pUmDevice->name);
	printf("HALT,");
        /* stop device */
        LM_Halt(pDevice);
	printf("POWER DOWN,");
        LM_SetPowerState(pDevice, LM_POWER_STATE_D3);

        /* Free the memory allocated by the device in tigon3 */
        for (i = 0; i < pUmDevice->mem_list_num; i++)  {
            if (pUmDevice->mem_list[i])  {
		/* sanity check */
                if (pUmDevice->dma_list[i]) {  /* cache-safe memory */
                    free(pUmDevice->mem_list[i]);
		} else {
                    free(pUmDevice->mem_list[i]);  /* normal memory   */
		}
	    }
	}
	pUmDevice->opened = 0;
	free(pDevice);
	pDevice = NULL;
	pUmDevice = NULL;
	initialized = 0;
	printf("done - offline.\n");
    }
}




/*
 *
 * Middle Module: Interface between the HW driver (tigon3 modules) and
 * the native (SENS) driver.  These routines implement the system
 * interface for tigon3 on VxWorks.
 */

/* Middle module dependency - size of a packet descriptor */
int MM_Packet_Desc_Size = sizeof(UM_PACKET);


LM_STATUS
MM_ReadConfig32(PLM_DEVICE_BLOCK pDevice,
		LM_UINT32 Offset,
		LM_UINT32 *pValue32)
{
    UM_DEVICE_BLOCK *pUmDevice;
    pUmDevice = (UM_DEVICE_BLOCK *) pDevice;
    pci_read_config_dword(pUmDevice->pdev,
			  Offset, (u32 *) pValue32);
    return LM_STATUS_SUCCESS;
}


LM_STATUS
MM_WriteConfig32(PLM_DEVICE_BLOCK pDevice,
		 LM_UINT32 Offset,
		 LM_UINT32 Value32)
{
    UM_DEVICE_BLOCK *pUmDevice;
    pUmDevice = (UM_DEVICE_BLOCK *) pDevice;
    pci_write_config_dword(pUmDevice->pdev,
			   Offset, Value32);
    return LM_STATUS_SUCCESS;
}


LM_STATUS
MM_ReadConfig16(PLM_DEVICE_BLOCK pDevice,
		LM_UINT32 Offset,
		LM_UINT16 *pValue16)
{
    UM_DEVICE_BLOCK *pUmDevice;
    pUmDevice = (UM_DEVICE_BLOCK *) pDevice;
    pci_read_config_word(pUmDevice->pdev,
			 Offset, (u16*) pValue16);
    return LM_STATUS_SUCCESS;
}

LM_STATUS
MM_WriteConfig16(PLM_DEVICE_BLOCK pDevice,
		 LM_UINT32 Offset,
		 LM_UINT16 Value16)
{
    UM_DEVICE_BLOCK *pUmDevice;
    pUmDevice = (UM_DEVICE_BLOCK *) pDevice;
    pci_write_config_word(pUmDevice->pdev,
			  Offset, Value16);
    return LM_STATUS_SUCCESS;
}


LM_STATUS
MM_AllocateSharedMemory(PLM_DEVICE_BLOCK pDevice, LM_UINT32 BlockSize,
			PLM_VOID *pMemoryBlockVirt,
			PLM_PHYSICAL_ADDRESS pMemoryBlockPhy,
			LM_BOOL Cached)
{
    PLM_VOID pvirt;
    PUM_DEVICE_BLOCK pUmDevice = (PUM_DEVICE_BLOCK) pDevice;
    dma_addr_t mapping;

    pvirt = malloc(BlockSize);
    mapping = (dma_addr_t)(pvirt);
    if (!pvirt)
	return LM_STATUS_FAILURE;

    pUmDevice->mem_list[pUmDevice->mem_list_num] = pvirt;
    pUmDevice->dma_list[pUmDevice->mem_list_num] = mapping;
    pUmDevice->mem_size_list[pUmDevice->mem_list_num++] = BlockSize;
    memset(pvirt, 0, BlockSize);

    *pMemoryBlockVirt = (PLM_VOID) pvirt;
    MM_SetAddr (pMemoryBlockPhy, (dma_addr_t) mapping);

    return LM_STATUS_SUCCESS;
}



LM_STATUS
MM_AllocateMemory(PLM_DEVICE_BLOCK pDevice, LM_UINT32 BlockSize,
	PLM_VOID *pMemoryBlockVirt)
{
    PLM_VOID pvirt;
    PUM_DEVICE_BLOCK pUmDevice = (PUM_DEVICE_BLOCK) pDevice;

    pvirt = malloc(BlockSize);

    if (!pvirt)
	return LM_STATUS_FAILURE;

    pUmDevice->mem_list[pUmDevice->mem_list_num] = pvirt;
    pUmDevice->dma_list[pUmDevice->mem_list_num] = 0;
    pUmDevice->mem_size_list[pUmDevice->mem_list_num++] = BlockSize;
    memset(pvirt, 0, BlockSize);
    *pMemoryBlockVirt = pvirt;

    return LM_STATUS_SUCCESS;
}

LM_STATUS
MM_MapMemBase(PLM_DEVICE_BLOCK pDevice)
{
    printf("BCM570x PCI Memory base address @0x%x\n",
	   (unsigned int)pDevice->pMappedMemBase);
    return LM_STATUS_SUCCESS;
}

LM_STATUS
MM_InitializeUmPackets(PLM_DEVICE_BLOCK pDevice)
{
    int i;
    void* skb;
    PUM_DEVICE_BLOCK pUmDevice = (PUM_DEVICE_BLOCK) pDevice;
    PUM_PACKET pUmPacket = NULL;
    PLM_PACKET pPacket = NULL;

    for (i = 0; i < pDevice->RxPacketDescCnt; i++) {
	pPacket = QQ_PopHead(&pDevice->RxPacketFreeQ.Container);
	pUmPacket = (PUM_PACKET) pPacket;

	if (pPacket == 0) {
	    printf("MM_InitializeUmPackets: Bad RxPacketFreeQ\n");
	}

	skb = bcm570xPktAlloc(pUmDevice->index,
			      pPacket->u.Rx.RxBufferSize + 2);

	if (skb == 0) {
	    pUmPacket->skbuff = 0;
	    QQ_PushTail(&pUmDevice->rx_out_of_buf_q.Container, pPacket);
	    printf("MM_InitializeUmPackets: out of buffer.\n");
	    continue;
	}

	pUmPacket->skbuff = skb;
	QQ_PushTail(&pDevice->RxPacketFreeQ.Container, pPacket);
    }

    pUmDevice->rx_low_buf_thresh = pDevice->RxPacketDescCnt / 8;

    return LM_STATUS_SUCCESS;
}

LM_STATUS
MM_GetConfig(PLM_DEVICE_BLOCK pDevice)
{
    PUM_DEVICE_BLOCK pUmDevice = (PUM_DEVICE_BLOCK) pDevice;
    int index = pDevice->index;

    if (auto_speed[index] == 0)
	pDevice->DisableAutoNeg = TRUE;
    else
	pDevice->DisableAutoNeg = FALSE;

    if (line_speed[index] == 0) {
	pDevice->RequestedMediaType =
	    LM_REQUESTED_MEDIA_TYPE_AUTO;
	pDevice->DisableAutoNeg = FALSE;
    }
    else {
	if (line_speed[index] == 1000) {
	    if (pDevice->EnableTbi) {
		pDevice->RequestedMediaType =
		    LM_REQUESTED_MEDIA_TYPE_FIBER_1000MBPS_FULL_DUPLEX;
	    }
	    else if (full_duplex[index]) {
		pDevice->RequestedMediaType =
		    LM_REQUESTED_MEDIA_TYPE_UTP_1000MBPS_FULL_DUPLEX;
	    }
	    else {
		pDevice->RequestedMediaType =
		    LM_REQUESTED_MEDIA_TYPE_UTP_1000MBPS;
	    }
	    if (!pDevice->EnableTbi)
		pDevice->DisableAutoNeg = FALSE;
	}
	else if (line_speed[index] == 100) {
	    if (full_duplex[index]) {
		pDevice->RequestedMediaType =
		    LM_REQUESTED_MEDIA_TYPE_UTP_100MBPS_FULL_DUPLEX;
	    }
	    else {
		pDevice->RequestedMediaType =
		    LM_REQUESTED_MEDIA_TYPE_UTP_100MBPS;
	    }
	}
	else if (line_speed[index] == 10) {
	    if (full_duplex[index]) {
		pDevice->RequestedMediaType =
		    LM_REQUESTED_MEDIA_TYPE_UTP_10MBPS_FULL_DUPLEX;
	    }
	    else {
		pDevice->RequestedMediaType =
		    LM_REQUESTED_MEDIA_TYPE_UTP_10MBPS;
	    }
	}
	else {
	    pDevice->RequestedMediaType =
		LM_REQUESTED_MEDIA_TYPE_AUTO;
	    pDevice->DisableAutoNeg = FALSE;
	}

    }
    pDevice->FlowControlCap = 0;
    if (rx_flow_control[index] != 0) {
	pDevice->FlowControlCap |= LM_FLOW_CONTROL_RECEIVE_PAUSE;
    }
    if (tx_flow_control[index] != 0) {
	pDevice->FlowControlCap |= LM_FLOW_CONTROL_TRANSMIT_PAUSE;
    }
    if ((auto_flow_control[index] != 0) &&
	(pDevice->DisableAutoNeg == FALSE)) {

	pDevice->FlowControlCap |= LM_FLOW_CONTROL_AUTO_PAUSE;
	if ((tx_flow_control[index] == 0) &&
	    (rx_flow_control[index] == 0)) {
	    pDevice->FlowControlCap |=
		LM_FLOW_CONTROL_TRANSMIT_PAUSE |
		LM_FLOW_CONTROL_RECEIVE_PAUSE;
	}
    }

    /* Default MTU for now */
    pUmDevice->mtu = 1500;

#if T3_JUMBO_RCV_RCB_ENTRY_COUNT
    if (pUmDevice->mtu > 1500) {
	pDevice->RxMtu = pUmDevice->mtu;
	pDevice->RxJumboDescCnt = DEFAULT_JUMBO_RCV_DESC_COUNT;
    }
    else {
	pDevice->RxJumboDescCnt = 0;
    }
    pDevice->RxJumboDescCnt = rx_jumbo_desc_cnt[index];
#else
    pDevice->RxMtu = pUmDevice->mtu;
#endif

    if (T3_ASIC_REV(pDevice->ChipRevId) == T3_ASIC_REV_5701) {
	pDevice->UseTaggedStatus = TRUE;
	pUmDevice->timer_interval = CFG_HZ;
    }
    else {
	pUmDevice->timer_interval = CFG_HZ/50;
    }

    pDevice->TxPacketDescCnt = tx_pkt_desc_cnt[index];
    pDevice->RxStdDescCnt = rx_std_desc_cnt[index];
    /* Note:  adaptive coalescence really isn't adaptive in this driver */
    pUmDevice->rx_adaptive_coalesce = rx_adaptive_coalesce[index];
    if (!pUmDevice->rx_adaptive_coalesce) {
	pDevice->RxCoalescingTicks = rx_coalesce_ticks[index];
	if (pDevice->RxCoalescingTicks > MAX_RX_COALESCING_TICKS)
	    pDevice->RxCoalescingTicks = MAX_RX_COALESCING_TICKS;
	pUmDevice->rx_curr_coalesce_ticks =pDevice->RxCoalescingTicks;

	pDevice->RxMaxCoalescedFrames = rx_max_coalesce_frames[index];
	if (pDevice->RxMaxCoalescedFrames>MAX_RX_MAX_COALESCED_FRAMES)
	    pDevice->RxMaxCoalescedFrames =
				MAX_RX_MAX_COALESCED_FRAMES;
	pUmDevice->rx_curr_coalesce_frames =
	    pDevice->RxMaxCoalescedFrames;
	pDevice->StatsCoalescingTicks = stats_coalesce_ticks[index];
	if (pDevice->StatsCoalescingTicks>MAX_STATS_COALESCING_TICKS)
	    pDevice->StatsCoalescingTicks=
		MAX_STATS_COALESCING_TICKS;
	}
	else {
	    pUmDevice->rx_curr_coalesce_frames =
		DEFAULT_RX_MAX_COALESCED_FRAMES;
	    pUmDevice->rx_curr_coalesce_ticks =
		DEFAULT_RX_COALESCING_TICKS;
	}
    pDevice->TxCoalescingTicks = tx_coalesce_ticks[index];
    if (pDevice->TxCoalescingTicks > MAX_TX_COALESCING_TICKS)
	pDevice->TxCoalescingTicks = MAX_TX_COALESCING_TICKS;
    pDevice->TxMaxCoalescedFrames = tx_max_coalesce_frames[index];
    if (pDevice->TxMaxCoalescedFrames > MAX_TX_MAX_COALESCED_FRAMES)
	pDevice->TxMaxCoalescedFrames = MAX_TX_MAX_COALESCED_FRAMES;

    if (enable_wol[index]) {
	pDevice->WakeUpModeCap = LM_WAKE_UP_MODE_MAGIC_PACKET;
	pDevice->WakeUpMode = LM_WAKE_UP_MODE_MAGIC_PACKET;
    }
    pDevice->NicSendBd = TRUE;

    /* Don't update status blocks during interrupt */
    pDevice->RxCoalescingTicksDuringInt = 0;
    pDevice->TxCoalescingTicksDuringInt = 0;

    return LM_STATUS_SUCCESS;

}


LM_STATUS
MM_StartTxDma(PLM_DEVICE_BLOCK pDevice, PLM_PACKET pPacket)
{
    PUM_DEVICE_BLOCK pUmDevice = (PUM_DEVICE_BLOCK) pDevice;
    printf("Start TX DMA: dev=%d packet @0x%x\n",
	   (int)pUmDevice->index, (unsigned int)pPacket);

    return LM_STATUS_SUCCESS;
}

LM_STATUS
MM_CompleteTxDma(PLM_DEVICE_BLOCK pDevice, PLM_PACKET pPacket)
{
    PUM_DEVICE_BLOCK pUmDevice = (PUM_DEVICE_BLOCK) pDevice;
    printf("Complete TX DMA: dev=%d packet @0x%x\n",
	   (int)pUmDevice->index, (unsigned int)pPacket);
    return LM_STATUS_SUCCESS;
}


LM_STATUS
MM_IndicateStatus(PLM_DEVICE_BLOCK pDevice, LM_STATUS Status)
{
    char buf[128];
    char lcd[4];
    PUM_DEVICE_BLOCK pUmDevice = (PUM_DEVICE_BLOCK) pDevice;
    LM_FLOW_CONTROL flow_control;

    pUmDevice->delayed_link_ind = 0;
    memset(lcd, 0x0, 4);

    if (Status == LM_STATUS_LINK_DOWN) {
	sprintf(buf,"eth%d: %s: NIC Link is down\n",
		pUmDevice->index,pUmDevice->name);
        lcd[0] = 'L';lcd[1]='N';lcd[2]='K';lcd[3] = '?';
    } else if (Status == LM_STATUS_LINK_ACTIVE) {
	sprintf(buf,"eth%d:%s: ", pUmDevice->index, pUmDevice->name);

	if (pDevice->LineSpeed == LM_LINE_SPEED_1000MBPS){
	    strcat(buf,"1000 Mbps ");
            lcd[0] = '1';lcd[1]='G';lcd[2]='B';
	} else if (pDevice->LineSpeed == LM_LINE_SPEED_100MBPS){
	    strcat(buf,"100 Mbps ");
            lcd[0] = '1';lcd[1]='0';lcd[2]='0';
	} else if (pDevice->LineSpeed == LM_LINE_SPEED_10MBPS){
	    strcat(buf,"10 Mbps ");
            lcd[0] = '1';lcd[1]='0';lcd[2]=' ';
	}
	if (pDevice->DuplexMode == LM_DUPLEX_MODE_FULL){
	    strcat(buf, "full duplex");
            lcd[3] = 'F';
	} else {
	    strcat(buf, "half duplex");
            lcd[3] = 'H';
	}
	strcat(buf, " link up");

	flow_control = pDevice->FlowControl &
	    (LM_FLOW_CONTROL_RECEIVE_PAUSE |
	     LM_FLOW_CONTROL_TRANSMIT_PAUSE);

	if (flow_control) {
	    if (flow_control & LM_FLOW_CONTROL_RECEIVE_PAUSE) {
		strcat(buf,", receive ");
		if (flow_control & LM_FLOW_CONTROL_TRANSMIT_PAUSE)
		    strcat(buf," & transmit ");
	    }
	    else {
		strcat(buf,", transmit ");
	    }
	    strcat(buf,"flow control ON");
	} else {
	    strcat(buf, ", flow control OFF");
	}
        strcat(buf,"\n");
	printf("%s",buf);
    }
#if 0
    sysLedDsply(lcd[0],lcd[1],lcd[2],lcd[3]);
#endif
    return LM_STATUS_SUCCESS;
}

LM_STATUS
MM_FreeRxBuffer(PLM_DEVICE_BLOCK pDevice, PLM_PACKET pPacket)
{

    PUM_DEVICE_BLOCK pUmDevice = (PUM_DEVICE_BLOCK) pDevice;
    PUM_PACKET pUmPacket;
    void *skb;

    pUmPacket = (PUM_PACKET) pPacket;

    if ((skb = pUmPacket->skbuff))
	bcm570xPktFree(pUmDevice->index, skb);

    pUmPacket->skbuff = 0;

    return LM_STATUS_SUCCESS;
}

unsigned long
MM_AnGetCurrentTime_us(PAN_STATE_INFO pAnInfo)
{
    return get_timer(0);
}

/*
 *   Transform an MBUF chain into a single MBUF.
 *   This routine will fail if the amount of data in the
 *   chain overflows a transmit buffer.  In that case,
 *   the incoming MBUF chain will be freed.  This routine can
 *   also fail by not being able to allocate a new MBUF (including
 *   cluster and mbuf headers).  In that case the failure is
 *   non-fatal.  The incoming cluster chain is not freed, giving
 *   the caller the choice of whether to try a retransmit later.
 */
LM_STATUS
MM_CoalesceTxBuffer(PLM_DEVICE_BLOCK pDevice, PLM_PACKET pPacket)
{
    PUM_PACKET pUmPacket = (PUM_PACKET) pPacket;
    PUM_DEVICE_BLOCK pUmDevice = (PUM_DEVICE_BLOCK) pDevice;
    void *skbnew;
    int len = 0;

    if (len == 0)
        return (LM_STATUS_SUCCESS);

    if (len > MAX_PACKET_SIZE){
        printf ("eth%d: xmit frame discarded, too big!, size = %d\n",
		pUmDevice->index, len);
        return (LM_STATUS_FAILURE);
    }

    skbnew = bcm570xPktAlloc(pUmDevice->index, MAX_PACKET_SIZE);

    if (skbnew == NULL) {
        pUmDevice->tx_full = 1;
        printf ("eth%d: out of transmit buffers", pUmDevice->index);
        return (LM_STATUS_FAILURE);
    }

    /* New packet values */
    pUmPacket->skbuff = skbnew;
    pUmPacket->lm_packet.u.Tx.FragCount = 1;

    return (LM_STATUS_SUCCESS);
}


LM_STATUS
MM_IndicateRxPackets(PLM_DEVICE_BLOCK pDevice)
{
    PUM_DEVICE_BLOCK pUmDevice = (PUM_DEVICE_BLOCK) pDevice;
    pUmDevice->rx_pkt = 1;
    return LM_STATUS_SUCCESS;
}

LM_STATUS
MM_IndicateTxPackets(PLM_DEVICE_BLOCK pDevice)
{
    PUM_DEVICE_BLOCK pUmDevice = (PUM_DEVICE_BLOCK) pDevice;
    PLM_PACKET pPacket;
    PUM_PACKET pUmPacket;
    void *skb;
    while ( TRUE ) {

	pPacket = (PLM_PACKET)
	    QQ_PopHead(&pDevice->TxPacketXmittedQ.Container);

	if (pPacket == 0)
	    break;

	pUmPacket = (PUM_PACKET) pPacket;
	skb = (void*)pUmPacket->skbuff;

        /*
        * Free MBLK if we transmitted a fragmented packet or a
        * non-fragmented packet straight from the VxWorks
        * buffer pool. If packet was copied to a local transmit
        * buffer, then there's no MBUF to free, just free
        * the transmit buffer back to the cluster pool.
        */

	if (skb)
	    bcm570xPktFree (pUmDevice->index, skb);

	pUmPacket->skbuff = 0;
	QQ_PushTail(&pDevice->TxPacketFreeQ.Container, pPacket);
	pUmDevice->tx_pkt = 1;
    }
    if (pUmDevice->tx_full) {
	if (QQ_GetEntryCnt(&pDevice->TxPacketFreeQ.Container) >=
	    (QQ_GetSize(&pDevice->TxPacketFreeQ.Container) >> 1))
	    pUmDevice->tx_full = 0;
    }
    return LM_STATUS_SUCCESS;
}

/*