aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Documentation/networking/bonding.txt52
-rw-r--r--MAINTAINERS6
-rw-r--r--drivers/net/Kconfig15
-rw-r--r--drivers/net/Makefile1
-rw-r--r--drivers/net/bonding/Makefile3
-rw-r--r--drivers/net/bonding/bond_3ad.c326
-rw-r--r--drivers/net/bonding/bond_3ad.h10
-rw-r--r--drivers/net/bonding/bond_alb.c13
-rw-r--r--drivers/net/bonding/bond_ipv6.c218
-rw-r--r--drivers/net/bonding/bond_main.c63
-rw-r--r--drivers/net/bonding/bond_sysfs.c91
-rw-r--r--drivers/net/bonding/bonding.h35
-rw-r--r--drivers/net/ehea/ehea.h2
-rw-r--r--drivers/net/ehea/ehea_qmr.c10
-rw-r--r--drivers/net/pcmcia/fmvj18x_cs.c73
-rw-r--r--drivers/net/phy/smsc.c28
-rw-r--r--drivers/net/sfc/Kconfig8
-rw-r--r--drivers/net/sfc/Makefile1
-rw-r--r--drivers/net/sfc/boards.c136
-rw-r--r--drivers/net/sfc/efx.c32
-rw-r--r--drivers/net/sfc/efx.h10
-rw-r--r--drivers/net/sfc/enum.h4
-rw-r--r--drivers/net/sfc/ethtool.c15
-rw-r--r--drivers/net/sfc/falcon.c23
-rw-r--r--drivers/net/sfc/falcon_hwdefs.h1
-rw-r--r--drivers/net/sfc/mdio_10g.c35
-rw-r--r--drivers/net/sfc/mdio_10g.h7
-rw-r--r--drivers/net/sfc/mtd.c268
-rw-r--r--drivers/net/sfc/net_driver.h8
-rw-r--r--drivers/net/sfc/sfe4001.c116
-rw-r--r--drivers/net/sfc/spi.h34
-rw-r--r--drivers/net/sfc/tenxpress.c18
-rw-r--r--drivers/net/sfc/workarounds.h2
-rw-r--r--drivers/net/sfc/xfp_phy.c9
-rw-r--r--drivers/net/smsc911x.c2091
-rw-r--r--drivers/net/smsc911x.h394
-rw-r--r--include/linux/smsc911x.h42
-rw-r--r--include/net/ndisc.h14
-rw-r--r--net/ipv6/ndisc.c92
39 files changed, 4015 insertions, 291 deletions
diff --git a/Documentation/networking/bonding.txt b/Documentation/networking/bonding.txt
index d733a428eff6..5ede7473b425 100644
--- a/Documentation/networking/bonding.txt
+++ b/Documentation/networking/bonding.txt
@@ -194,6 +194,48 @@ or, for backwards compatibility, the option value. E.g.,
194 194
195 The parameters are as follows: 195 The parameters are as follows:
196 196
197ad_select
198
199 Specifies the 802.3ad aggregation selection logic to use. The
200 possible values and their effects are:
201
202 stable or 0
203
204 The active aggregator is chosen by largest aggregate
205 bandwidth.
206
207 Reselection of the active aggregator occurs only when all
208 slaves of the active aggregator are down or the active
209 aggregator has no slaves.
210
211 This is the default value.
212
213 bandwidth or 1
214
215 The active aggregator is chosen by largest aggregate
216 bandwidth. Reselection occurs if:
217
218 - A slave is added to or removed from the bond
219
220 - Any slave's link state changes
221
222 - Any slave's 802.3ad association state changes
223
224 - The bond's adminstrative state changes to up
225
226 count or 2
227
228 The active aggregator is chosen by the largest number of
229 ports (slaves). Reselection occurs as described under the
230 "bandwidth" setting, above.
231
232 The bandwidth and count selection policies permit failover of
233 802.3ad aggregations when partial failure of the active aggregator
234 occurs. This keeps the aggregator with the highest availability
235 (either in bandwidth or in number of ports) active at all times.
236
237 This option was added in bonding version 3.4.0.
238
197arp_interval 239arp_interval
198 240
199 Specifies the ARP link monitoring frequency in milliseconds. 241 Specifies the ARP link monitoring frequency in milliseconds.
@@ -551,6 +593,16 @@ num_grat_arp
551 affects only the active-backup mode. This option was added for 593 affects only the active-backup mode. This option was added for
552 bonding version 3.3.0. 594 bonding version 3.3.0.
553 595
596num_unsol_na
597
598 Specifies the number of unsolicited IPv6 Neighbor Advertisements
599 to be issued after a failover event. One unsolicited NA is issued
600 immediately after the failover.
601
602 The valid range is 0 - 255; the default value is 1. This option
603 affects only the active-backup mode. This option was added for
604 bonding version 3.4.0.
605
554primary 606primary
555 607
556 A string (eth0, eth2, etc) specifying which slave is the 608 A string (eth0, eth2, etc) specifying which slave is the
diff --git a/MAINTAINERS b/MAINTAINERS
index ca96939b7969..425e50e6b4c5 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -3853,6 +3853,12 @@ M: mhoffman@lightlink.com
3853L: lm-sensors@lm-sensors.org 3853L: lm-sensors@lm-sensors.org
3854S: Maintained 3854S: Maintained
3855 3855
3856SMSC911x ETHERNET DRIVER
3857P: Steve Glendinning
3858M: steve.glendinning@smsc.com
3859L: netdev@vger.kernel.org
3860S: Supported
3861
3856SMX UIO Interface 3862SMX UIO Interface
3857P: Ben Nizette 3863P: Ben Nizette
3858M: bn@niasdigital.com 3864M: bn@niasdigital.com
diff --git a/drivers/net/Kconfig b/drivers/net/Kconfig
index 1757bb3f6e08..732ea834d50d 100644
--- a/drivers/net/Kconfig
+++ b/drivers/net/Kconfig
@@ -61,6 +61,7 @@ config DUMMY
61config BONDING 61config BONDING
62 tristate "Bonding driver support" 62 tristate "Bonding driver support"
63 depends on INET 63 depends on INET
64 depends on IPV6 || IPV6=n
64 ---help--- 65 ---help---
65 Say 'Y' or 'M' if you wish to be able to 'bond' multiple Ethernet 66 Say 'Y' or 'M' if you wish to be able to 'bond' multiple Ethernet
66 Channels together. This is called 'Etherchannel' by Cisco, 67 Channels together. This is called 'Etherchannel' by Cisco,
@@ -978,6 +979,20 @@ config SMC911X
978 called smc911x. If you want to compile it as a module, say M 979 called smc911x. If you want to compile it as a module, say M
979 here and read <file:Documentation/kbuild/modules.txt> 980 here and read <file:Documentation/kbuild/modules.txt>
980 981
982config SMSC911X
983 tristate "SMSC LAN911x/LAN921x families embedded ethernet support"
984 depends on ARM || SUPERH
985 select CRC32
986 select MII
987 select PHYLIB
988 ---help---
989 Say Y here if you want support for SMSC LAN911x and LAN921x families
990 of ethernet controllers.
991
992 To compile this driver as a module, choose M here and read
993 <file:Documentation/networking/net-modules.txt>. The module
994 will be called smsc911x.
995
981config NET_VENDOR_RACAL 996config NET_VENDOR_RACAL
982 bool "Racal-Interlan (Micom) NI cards" 997 bool "Racal-Interlan (Micom) NI cards"
983 depends on ISA 998 depends on ISA
diff --git a/drivers/net/Makefile b/drivers/net/Makefile
index 657c47b1a6b6..e06829aa75b0 100644
--- a/drivers/net/Makefile
+++ b/drivers/net/Makefile
@@ -219,6 +219,7 @@ obj-$(CONFIG_S2IO) += s2io.o
219obj-$(CONFIG_MYRI10GE) += myri10ge/ 219obj-$(CONFIG_MYRI10GE) += myri10ge/
220obj-$(CONFIG_SMC91X) += smc91x.o 220obj-$(CONFIG_SMC91X) += smc91x.o
221obj-$(CONFIG_SMC911X) += smc911x.o 221obj-$(CONFIG_SMC911X) += smc911x.o
222obj-$(CONFIG_SMSC911X) += smsc911x.o
222obj-$(CONFIG_BFIN_MAC) += bfin_mac.o 223obj-$(CONFIG_BFIN_MAC) += bfin_mac.o
223obj-$(CONFIG_DM9000) += dm9000.o 224obj-$(CONFIG_DM9000) += dm9000.o
224obj-$(CONFIG_PASEMI_MAC) += pasemi_mac_driver.o 225obj-$(CONFIG_PASEMI_MAC) += pasemi_mac_driver.o
diff --git a/drivers/net/bonding/Makefile b/drivers/net/bonding/Makefile
index 5cdae2bc055a..6f9c6faef24c 100644
--- a/drivers/net/bonding/Makefile
+++ b/drivers/net/bonding/Makefile
@@ -6,3 +6,6 @@ obj-$(CONFIG_BONDING) += bonding.o
6 6
7bonding-objs := bond_main.o bond_3ad.o bond_alb.o bond_sysfs.o 7bonding-objs := bond_main.o bond_3ad.o bond_alb.o bond_sysfs.o
8 8
9ipv6-$(subst m,y,$(CONFIG_IPV6)) += bond_ipv6.o
10bonding-objs += $(ipv6-y)
11
diff --git a/drivers/net/bonding/bond_3ad.c b/drivers/net/bonding/bond_3ad.c
index 6106660a4a44..ba1372f2f144 100644
--- a/drivers/net/bonding/bond_3ad.c
+++ b/drivers/net/bonding/bond_3ad.c
@@ -27,6 +27,7 @@
27#include <linux/netdevice.h> 27#include <linux/netdevice.h>
28#include <linux/spinlock.h> 28#include <linux/spinlock.h>
29#include <linux/ethtool.h> 29#include <linux/ethtool.h>
30#include <linux/etherdevice.h>
30#include <linux/if_bonding.h> 31#include <linux/if_bonding.h>
31#include <linux/pkt_sched.h> 32#include <linux/pkt_sched.h>
32#include <net/net_namespace.h> 33#include <net/net_namespace.h>
@@ -236,6 +237,17 @@ static inline struct aggregator *__get_next_agg(struct aggregator *aggregator)
236 return &(SLAVE_AD_INFO(slave->next).aggregator); 237 return &(SLAVE_AD_INFO(slave->next).aggregator);
237} 238}
238 239
240/*
241 * __agg_has_partner
242 *
243 * Return nonzero if aggregator has a partner (denoted by a non-zero ether
244 * address for the partner). Return 0 if not.
245 */
246static inline int __agg_has_partner(struct aggregator *agg)
247{
248 return !is_zero_ether_addr(agg->partner_system.mac_addr_value);
249}
250
239/** 251/**
240 * __disable_port - disable the port's slave 252 * __disable_port - disable the port's slave
241 * @port: the port we're looking at 253 * @port: the port we're looking at
@@ -274,14 +286,14 @@ static inline int __port_is_enabled(struct port *port)
274 * __get_agg_selection_mode - get the aggregator selection mode 286 * __get_agg_selection_mode - get the aggregator selection mode
275 * @port: the port we're looking at 287 * @port: the port we're looking at
276 * 288 *
277 * Get the aggregator selection mode. Can be %BANDWIDTH or %COUNT. 289 * Get the aggregator selection mode. Can be %STABLE, %BANDWIDTH or %COUNT.
278 */ 290 */
279static inline u32 __get_agg_selection_mode(struct port *port) 291static inline u32 __get_agg_selection_mode(struct port *port)
280{ 292{
281 struct bonding *bond = __get_bond_by_port(port); 293 struct bonding *bond = __get_bond_by_port(port);
282 294
283 if (bond == NULL) { 295 if (bond == NULL) {
284 return AD_BANDWIDTH; 296 return BOND_AD_STABLE;
285 } 297 }
286 298
287 return BOND_AD_INFO(bond).agg_select_mode; 299 return BOND_AD_INFO(bond).agg_select_mode;
@@ -1414,9 +1426,82 @@ static void ad_port_selection_logic(struct port *port)
1414 // else set ready=FALSE in all aggregator's ports 1426 // else set ready=FALSE in all aggregator's ports
1415 __set_agg_ports_ready(port->aggregator, __agg_ports_are_ready(port->aggregator)); 1427 __set_agg_ports_ready(port->aggregator, __agg_ports_are_ready(port->aggregator));
1416 1428
1417 if (!__check_agg_selection_timer(port) && (aggregator = __get_first_agg(port))) { 1429 aggregator = __get_first_agg(port);
1418 ad_agg_selection_logic(aggregator); 1430 ad_agg_selection_logic(aggregator);
1431}
1432
1433/*
1434 * Decide if "agg" is a better choice for the new active aggregator that
1435 * the current best, according to the ad_select policy.
1436 */
1437static struct aggregator *ad_agg_selection_test(struct aggregator *best,
1438 struct aggregator *curr)
1439{
1440 /*
1441 * 0. If no best, select current.
1442 *
1443 * 1. If the current agg is not individual, and the best is
1444 * individual, select current.
1445 *
1446 * 2. If current agg is individual and the best is not, keep best.
1447 *
1448 * 3. Therefore, current and best are both individual or both not
1449 * individual, so:
1450 *
1451 * 3a. If current agg partner replied, and best agg partner did not,
1452 * select current.
1453 *
1454 * 3b. If current agg partner did not reply and best agg partner
1455 * did reply, keep best.
1456 *
1457 * 4. Therefore, current and best both have partner replies or
1458 * both do not, so perform selection policy:
1459 *
1460 * BOND_AD_COUNT: Select by count of ports. If count is equal,
1461 * select by bandwidth.
1462 *
1463 * BOND_AD_STABLE, BOND_AD_BANDWIDTH: Select by bandwidth.
1464 */
1465 if (!best)
1466 return curr;
1467
1468 if (!curr->is_individual && best->is_individual)
1469 return curr;
1470
1471 if (curr->is_individual && !best->is_individual)
1472 return best;
1473
1474 if (__agg_has_partner(curr) && !__agg_has_partner(best))
1475 return curr;
1476
1477 if (!__agg_has_partner(curr) && __agg_has_partner(best))
1478 return best;
1479
1480 switch (__get_agg_selection_mode(curr->lag_ports)) {
1481 case BOND_AD_COUNT:
1482 if (curr->num_of_ports > best->num_of_ports)
1483 return curr;
1484
1485 if (curr->num_of_ports < best->num_of_ports)
1486 return best;
1487
1488 /*FALLTHROUGH*/
1489 case BOND_AD_STABLE:
1490 case BOND_AD_BANDWIDTH:
1491 if (__get_agg_bandwidth(curr) > __get_agg_bandwidth(best))
1492 return curr;
1493
1494 break;
1495
1496 default:
1497 printk(KERN_WARNING DRV_NAME
1498 ": %s: Impossible agg select mode %d\n",
1499 curr->slave->dev->master->name,
1500 __get_agg_selection_mode(curr->lag_ports));
1501 break;
1419 } 1502 }
1503
1504 return best;
1420} 1505}
1421 1506
1422/** 1507/**
@@ -1424,156 +1509,138 @@ static void ad_port_selection_logic(struct port *port)
1424 * @aggregator: the aggregator we're looking at 1509 * @aggregator: the aggregator we're looking at
1425 * 1510 *
1426 * It is assumed that only one aggregator may be selected for a team. 1511 * It is assumed that only one aggregator may be selected for a team.
1427 * The logic of this function is to select (at first time) the aggregator with 1512 *
1428 * the most ports attached to it, and to reselect the active aggregator only if 1513 * The logic of this function is to select the aggregator according to
1429 * the previous aggregator has no more ports related to it. 1514 * the ad_select policy:
1515 *
1516 * BOND_AD_STABLE: select the aggregator with the most ports attached to
1517 * it, and to reselect the active aggregator only if the previous
1518 * aggregator has no more ports related to it.
1519 *
1520 * BOND_AD_BANDWIDTH: select the aggregator with the highest total
1521 * bandwidth, and reselect whenever a link state change takes place or the
1522 * set of slaves in the bond changes.
1523 *
1524 * BOND_AD_COUNT: select the aggregator with largest number of ports
1525 * (slaves), and reselect whenever a link state change takes place or the
1526 * set of slaves in the bond changes.
1430 * 1527 *
1431 * FIXME: this function MUST be called with the first agg in the bond, or 1528 * FIXME: this function MUST be called with the first agg in the bond, or
1432 * __get_active_agg() won't work correctly. This function should be better 1529 * __get_active_agg() won't work correctly. This function should be better
1433 * called with the bond itself, and retrieve the first agg from it. 1530 * called with the bond itself, and retrieve the first agg from it.
1434 */ 1531 */
1435static void ad_agg_selection_logic(struct aggregator *aggregator) 1532static void ad_agg_selection_logic(struct aggregator *agg)
1436{ 1533{
1437 struct aggregator *best_aggregator = NULL, *active_aggregator = NULL; 1534 struct aggregator *best, *active, *origin;
1438 struct aggregator *last_active_aggregator = NULL, *origin_aggregator;
1439 struct port *port; 1535 struct port *port;
1440 u16 num_of_aggs=0;
1441 1536
1442 origin_aggregator = aggregator; 1537 origin = agg;
1443 1538
1444 //get current active aggregator 1539 active = __get_active_agg(agg);
1445 last_active_aggregator = __get_active_agg(aggregator); 1540 best = active;
1446 1541
1447 // search for the aggregator with the most ports attached to it.
1448 do { 1542 do {
1449 // count how many candidate lag's we have 1543 agg->is_active = 0;
1450 if (aggregator->lag_ports) { 1544
1451 num_of_aggs++; 1545 if (agg->num_of_ports)
1452 } 1546 best = ad_agg_selection_test(best, agg);
1453 if (aggregator->is_active && !aggregator->is_individual && // if current aggregator is the active aggregator 1547
1454 MAC_ADDRESS_COMPARE(&(aggregator->partner_system), &(null_mac_addr))) { // and partner answers to 802.3ad PDUs 1548 } while ((agg = __get_next_agg(agg)));
1455 if (aggregator->num_of_ports) { // if any ports attached to the current aggregator 1549
1456 best_aggregator=NULL; // disregard the best aggregator that was chosen by now 1550 if (best &&
1457 break; // stop the selection of other aggregator if there are any ports attached to this active aggregator 1551 __get_agg_selection_mode(best->lag_ports) == BOND_AD_STABLE) {
1458 } else { // no ports attached to this active aggregator 1552 /*
1459 aggregator->is_active = 0; // mark this aggregator as not active anymore 1553 * For the STABLE policy, don't replace the old active
1554 * aggregator if it's still active (it has an answering
1555 * partner) or if both the best and active don't have an
1556 * answering partner.
1557 */
1558 if (active && active->lag_ports &&
1559 active->lag_ports->is_enabled &&
1560 (__agg_has_partner(active) ||
1561 (!__agg_has_partner(active) && !__agg_has_partner(best)))) {
1562 if (!(!active->actor_oper_aggregator_key &&
1563 best->actor_oper_aggregator_key)) {
1564 best = NULL;
1565 active->is_active = 1;
1460 } 1566 }
1461 } 1567 }
1462 if (aggregator->num_of_ports) { // if any ports attached 1568 }
1463 if (best_aggregator) { // if there is a candidte aggregator
1464 //The reasons for choosing new best aggregator:
1465 // 1. if current agg is NOT individual and the best agg chosen so far is individual OR
1466 // current and best aggs are both individual or both not individual, AND
1467 // 2a. current agg partner reply but best agg partner do not reply OR
1468 // 2b. current agg partner reply OR current agg partner do not reply AND best agg partner also do not reply AND
1469 // current has more ports/bandwidth, or same amount of ports but current has faster ports, THEN
1470 // current agg become best agg so far
1471
1472 //if current agg is NOT individual and the best agg chosen so far is individual change best_aggregator
1473 if (!aggregator->is_individual && best_aggregator->is_individual) {
1474 best_aggregator=aggregator;
1475 }
1476 // current and best aggs are both individual or both not individual
1477 else if ((aggregator->is_individual && best_aggregator->is_individual) ||
1478 (!aggregator->is_individual && !best_aggregator->is_individual)) {
1479 // current and best aggs are both individual or both not individual AND
1480 // current agg partner reply but best agg partner do not reply
1481 if ((MAC_ADDRESS_COMPARE(&(aggregator->partner_system), &(null_mac_addr)) &&
1482 !MAC_ADDRESS_COMPARE(&(best_aggregator->partner_system), &(null_mac_addr)))) {
1483 best_aggregator=aggregator;
1484 }
1485 // current agg partner reply OR current agg partner do not reply AND best agg partner also do not reply
1486 else if (! (!MAC_ADDRESS_COMPARE(&(aggregator->partner_system), &(null_mac_addr)) &&
1487 MAC_ADDRESS_COMPARE(&(best_aggregator->partner_system), &(null_mac_addr)))) {
1488 if ((__get_agg_selection_mode(aggregator->lag_ports) == AD_BANDWIDTH)&&
1489 (__get_agg_bandwidth(aggregator) > __get_agg_bandwidth(best_aggregator))) {
1490 best_aggregator=aggregator;
1491 } else if (__get_agg_selection_mode(aggregator->lag_ports) == AD_COUNT) {
1492 if (((aggregator->num_of_ports > best_aggregator->num_of_ports) &&
1493 (aggregator->actor_oper_aggregator_key & AD_SPEED_KEY_BITS))||
1494 ((aggregator->num_of_ports == best_aggregator->num_of_ports) &&
1495 ((u16)(aggregator->actor_oper_aggregator_key & AD_SPEED_KEY_BITS) >
1496 (u16)(best_aggregator->actor_oper_aggregator_key & AD_SPEED_KEY_BITS)))) {
1497 best_aggregator=aggregator;
1498 }
1499 }
1500 }
1501 }
1502 } else {
1503 best_aggregator=aggregator;
1504 }
1505 }
1506 aggregator->is_active = 0; // mark all aggregators as not active anymore
1507 } while ((aggregator = __get_next_agg(aggregator)));
1508
1509 // if we have new aggregator selected, don't replace the old aggregator if it has an answering partner,
1510 // or if both old aggregator and new aggregator don't have answering partner
1511 if (best_aggregator) {
1512 if (last_active_aggregator && last_active_aggregator->lag_ports && last_active_aggregator->lag_ports->is_enabled &&
1513 (MAC_ADDRESS_COMPARE(&(last_active_aggregator->partner_system), &(null_mac_addr)) || // partner answers OR
1514 (!MAC_ADDRESS_COMPARE(&(last_active_aggregator->partner_system), &(null_mac_addr)) && // both old and new
1515 !MAC_ADDRESS_COMPARE(&(best_aggregator->partner_system), &(null_mac_addr)))) // partner do not answer
1516 ) {
1517 // if new aggregator has link, and old aggregator does not, replace old aggregator.(do nothing)
1518 // -> don't replace otherwise.
1519 if (!(!last_active_aggregator->actor_oper_aggregator_key && best_aggregator->actor_oper_aggregator_key)) {
1520 best_aggregator=NULL;
1521 last_active_aggregator->is_active = 1; // don't replace good old aggregator
1522 1569
1523 } 1570 if (best && (best == active)) {
1524 } 1571 best = NULL;
1572 active->is_active = 1;
1525 } 1573 }
1526 1574
1527 // if there is new best aggregator, activate it 1575 // if there is new best aggregator, activate it
1528 if (best_aggregator) { 1576 if (best) {
1529 for (aggregator = __get_first_agg(best_aggregator->lag_ports); 1577 dprintk("best Agg=%d; P=%d; a k=%d; p k=%d; Ind=%d; Act=%d\n",
1530 aggregator; 1578 best->aggregator_identifier, best->num_of_ports,
1531 aggregator = __get_next_agg(aggregator)) { 1579 best->actor_oper_aggregator_key,
1532 1580 best->partner_oper_aggregator_key,
1533 dprintk("Agg=%d; Ports=%d; a key=%d; p key=%d; Indiv=%d; Active=%d\n", 1581 best->is_individual, best->is_active);
1534 aggregator->aggregator_identifier, aggregator->num_of_ports, 1582 dprintk("best ports %p slave %p %s\n",
1535 aggregator->actor_oper_aggregator_key, aggregator->partner_oper_aggregator_key, 1583 best->lag_ports, best->slave,
1536 aggregator->is_individual, aggregator->is_active); 1584 best->slave ? best->slave->dev->name : "NULL");
1585
1586 for (agg = __get_first_agg(best->lag_ports); agg;
1587 agg = __get_next_agg(agg)) {
1588
1589 dprintk("Agg=%d; P=%d; a k=%d; p k=%d; Ind=%d; Act=%d\n",
1590 agg->aggregator_identifier, agg->num_of_ports,
1591 agg->actor_oper_aggregator_key,
1592 agg->partner_oper_aggregator_key,
1593 agg->is_individual, agg->is_active);
1537 } 1594 }
1538 1595
1539 // check if any partner replys 1596 // check if any partner replys
1540 if (best_aggregator->is_individual) { 1597 if (best->is_individual) {
1541 printk(KERN_WARNING DRV_NAME ": %s: Warning: No 802.3ad response from " 1598 printk(KERN_WARNING DRV_NAME ": %s: Warning: No 802.3ad"
1542 "the link partner for any adapters in the bond\n", 1599 " response from the link partner for any"
1543 best_aggregator->slave->dev->master->name); 1600 " adapters in the bond\n",
1544 } 1601 best->slave->dev->master->name);
1545
1546 // check if there are more than one aggregator
1547 if (num_of_aggs > 1) {
1548 dprintk("Warning: More than one Link Aggregation Group was "
1549 "found in the bond. Only one group will function in the bond\n");
1550 } 1602 }
1551 1603
1552 best_aggregator->is_active = 1; 1604 best->is_active = 1;
1553 dprintk("LAG %d choosed as the active LAG\n", best_aggregator->aggregator_identifier); 1605 dprintk("LAG %d chosen as the active LAG\n",
1554 dprintk("Agg=%d; Ports=%d; a key=%d; p key=%d; Indiv=%d; Active=%d\n", 1606 best->aggregator_identifier);
1555 best_aggregator->aggregator_identifier, best_aggregator->num_of_ports, 1607 dprintk("Agg=%d; P=%d; a k=%d; p k=%d; Ind=%d; Act=%d\n",
1556 best_aggregator->actor_oper_aggregator_key, best_aggregator->partner_oper_aggregator_key, 1608 best->aggregator_identifier, best->num_of_ports,
1557 best_aggregator->is_individual, best_aggregator->is_active); 1609 best->actor_oper_aggregator_key,
1610 best->partner_oper_aggregator_key,
1611 best->is_individual, best->is_active);
1558 1612
1559 // disable the ports that were related to the former active_aggregator 1613 // disable the ports that were related to the former active_aggregator
1560 if (last_active_aggregator) { 1614 if (active) {
1561 for (port=last_active_aggregator->lag_ports; port; port=port->next_port_in_aggregator) { 1615 for (port = active->lag_ports; port;
1616 port = port->next_port_in_aggregator) {
1562 __disable_port(port); 1617 __disable_port(port);
1563 } 1618 }
1564 } 1619 }
1565 } 1620 }
1566 1621
1567 // if the selected aggregator is of join individuals(partner_system is NULL), enable their ports 1622 /*
1568 active_aggregator = __get_active_agg(origin_aggregator); 1623 * if the selected aggregator is of join individuals
1624 * (partner_system is NULL), enable their ports
1625 */
1626 active = __get_active_agg(origin);
1569 1627
1570 if (active_aggregator) { 1628 if (active) {
1571 if (!MAC_ADDRESS_COMPARE(&(active_aggregator->partner_system), &(null_mac_addr))) { 1629 if (!__agg_has_partner(active)) {
1572 for (port=active_aggregator->lag_ports; port; port=port->next_port_in_aggregator) { 1630 for (port = active->lag_ports; port;
1631 port = port->next_port_in_aggregator) {
1573 __enable_port(port); 1632 __enable_port(port);
1574 } 1633 }
1575 } 1634 }
1576 } 1635 }
1636
1637 if (origin->slave) {
1638 struct bonding *bond;
1639
1640 bond = bond_get_bond_by_slave(origin->slave);
1641 if (bond)
1642 bond_3ad_set_carrier(bond);
1643 }
1577} 1644}
1578 1645
1579/** 1646/**
@@ -1830,6 +1897,19 @@ static void ad_initialize_lacpdu(struct lacpdu *lacpdu)
1830// Check aggregators status in team every T seconds 1897// Check aggregators status in team every T seconds
1831#define AD_AGGREGATOR_SELECTION_TIMER 8 1898#define AD_AGGREGATOR_SELECTION_TIMER 8
1832 1899
1900/*
1901 * bond_3ad_initiate_agg_selection(struct bonding *bond)
1902 *
1903 * Set the aggregation selection timer, to initiate an agg selection in
1904 * the very near future. Called during first initialization, and during
1905 * any down to up transitions of the bond.
1906 */
1907void bond_3ad_initiate_agg_selection(struct bonding *bond, int timeout)
1908{
1909 BOND_AD_INFO(bond).agg_select_timer = timeout;
1910 BOND_AD_INFO(bond).agg_select_mode = bond->params.ad_select;
1911}
1912
1833static u16 aggregator_identifier; 1913static u16 aggregator_identifier;
1834 1914
1835/** 1915/**
@@ -1854,9 +1934,9 @@ void bond_3ad_initialize(struct bonding *bond, u16 tick_resolution, int lacp_fas
1854 // initialize how many times this module is called in one second(should be about every 100ms) 1934 // initialize how many times this module is called in one second(should be about every 100ms)
1855 ad_ticks_per_sec = tick_resolution; 1935 ad_ticks_per_sec = tick_resolution;
1856 1936
1857 // initialize the aggregator selection timer(to activate an aggregation selection after initialize) 1937 bond_3ad_initiate_agg_selection(bond,
1858 BOND_AD_INFO(bond).agg_select_timer = (AD_AGGREGATOR_SELECTION_TIMER * ad_ticks_per_sec); 1938 AD_AGGREGATOR_SELECTION_TIMER *
1859 BOND_AD_INFO(bond).agg_select_mode = AD_BANDWIDTH; 1939 ad_ticks_per_sec);
1860 } 1940 }
1861} 1941}
1862 1942
diff --git a/drivers/net/bonding/bond_3ad.h b/drivers/net/bonding/bond_3ad.h
index b5ee45f6d55a..a803fe05f63e 100644
--- a/drivers/net/bonding/bond_3ad.h
+++ b/drivers/net/bonding/bond_3ad.h
@@ -42,10 +42,11 @@ typedef struct mac_addr {
42 u8 mac_addr_value[ETH_ALEN]; 42 u8 mac_addr_value[ETH_ALEN];
43} mac_addr_t; 43} mac_addr_t;
44 44
45typedef enum { 45enum {
46 AD_BANDWIDTH = 0, 46 BOND_AD_STABLE = 0,
47 AD_COUNT 47 BOND_AD_BANDWIDTH = 1,
48} agg_selection_t; 48 BOND_AD_COUNT = 2,
49};
49 50
50// rx machine states(43.4.11 in the 802.3ad standard) 51// rx machine states(43.4.11 in the 802.3ad standard)
51typedef enum { 52typedef enum {
@@ -277,6 +278,7 @@ void bond_3ad_initialize(struct bonding *bond, u16 tick_resolution, int lacp_fas
277int bond_3ad_bind_slave(struct slave *slave); 278int bond_3ad_bind_slave(struct slave *slave);
278void bond_3ad_unbind_slave(struct slave *slave); 279void bond_3ad_unbind_slave(struct slave *slave);
279void bond_3ad_state_machine_handler(struct work_struct *); 280void bond_3ad_state_machine_handler(struct work_struct *);
281void bond_3ad_initiate_agg_selection(struct bonding *bond, int timeout);
280void bond_3ad_adapter_speed_changed(struct slave *slave); 282void bond_3ad_adapter_speed_changed(struct slave *slave);
281void bond_3ad_adapter_duplex_changed(struct slave *slave); 283void bond_3ad_adapter_duplex_changed(struct slave *slave);
282void bond_3ad_handle_link_change(struct slave *slave, char link); 284void bond_3ad_handle_link_change(struct slave *slave, char link);
diff --git a/drivers/net/bonding/bond_alb.c b/drivers/net/bonding/bond_alb.c
index 87437c788476..e170fa2fa1a1 100644
--- a/drivers/net/bonding/bond_alb.c
+++ b/drivers/net/bonding/bond_alb.c
@@ -346,14 +346,18 @@ static void rlb_update_entry_from_arp(struct bonding *bond, struct arp_pkt *arp)
346 346
347static int rlb_arp_recv(struct sk_buff *skb, struct net_device *bond_dev, struct packet_type *ptype, struct net_device *orig_dev) 347static int rlb_arp_recv(struct sk_buff *skb, struct net_device *bond_dev, struct packet_type *ptype, struct net_device *orig_dev)
348{ 348{
349 struct bonding *bond = bond_dev->priv; 349 struct bonding *bond;
350 struct arp_pkt *arp = (struct arp_pkt *)skb->data; 350 struct arp_pkt *arp = (struct arp_pkt *)skb->data;
351 int res = NET_RX_DROP; 351 int res = NET_RX_DROP;
352 352
353 if (dev_net(bond_dev) != &init_net) 353 if (dev_net(bond_dev) != &init_net)
354 goto out; 354 goto out;
355 355
356 if (!(bond_dev->flags & IFF_MASTER)) 356 while (bond_dev->priv_flags & IFF_802_1Q_VLAN)
357 bond_dev = vlan_dev_real_dev(bond_dev);
358
359 if (!(bond_dev->priv_flags & IFF_BONDING) ||
360 !(bond_dev->flags & IFF_MASTER))
357 goto out; 361 goto out;
358 362
359 if (!arp) { 363 if (!arp) {
@@ -368,6 +372,9 @@ static int rlb_arp_recv(struct sk_buff *skb, struct net_device *bond_dev, struct
368 372
369 if (arp->op_code == htons(ARPOP_REPLY)) { 373 if (arp->op_code == htons(ARPOP_REPLY)) {
370 /* update rx hash table for this ARP */ 374 /* update rx hash table for this ARP */
375 printk("rar: update orig %s bond_dev %s\n", orig_dev->name,
376 bond_dev->name);
377 bond = bond_dev->priv;
371 rlb_update_entry_from_arp(bond, arp); 378 rlb_update_entry_from_arp(bond, arp);
372 dprintk("Server received an ARP Reply from client\n"); 379 dprintk("Server received an ARP Reply from client\n");
373 } 380 }
@@ -818,7 +825,7 @@ static int rlb_initialize(struct bonding *bond)
818 825
819 /*initialize packet type*/ 826 /*initialize packet type*/
820 pk_type->type = __constant_htons(ETH_P_ARP); 827 pk_type->type = __constant_htons(ETH_P_ARP);
821 pk_type->dev = bond->dev; 828 pk_type->dev = NULL;
822 pk_type->func = rlb_arp_recv; 829 pk_type->func = rlb_arp_recv;
823 830
824 /* register to receive ARPs */ 831 /* register to receive ARPs */
diff --git a/drivers/net/bonding/bond_ipv6.c b/drivers/net/bonding/bond_ipv6.c
new file mode 100644
index 000000000000..7c78b7bf671c
--- /dev/null
+++ b/drivers/net/bonding/bond_ipv6.c
@@ -0,0 +1,218 @@
1/*
2 * Copyright(c) 2008 Hewlett-Packard Development Company, L.P.
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License as published by the
6 * Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
11 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * for more details.
13 *
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17 *
18 * The full GNU General Public License is included in this distribution in the
19 * file called LICENSE.
20 *
21 */
22
23//#define BONDING_DEBUG 1
24
25#include <linux/types.h>
26#include <linux/if_vlan.h>
27#include <net/ipv6.h>
28#include <net/ndisc.h>
29#include <net/addrconf.h>
30#include "bonding.h"
31
32/*
33 * Assign bond->master_ipv6 to the next IPv6 address in the list, or
34 * zero it out if there are none.
35 */
36static void bond_glean_dev_ipv6(struct net_device *dev, struct in6_addr *addr)
37{
38 struct inet6_dev *idev;
39 struct inet6_ifaddr *ifa;
40
41 if (!dev)
42 return;
43
44 idev = in6_dev_get(dev);
45 if (!idev)
46 return;
47
48 read_lock_bh(&idev->lock);
49 ifa = idev->addr_list;
50 if (ifa)
51 ipv6_addr_copy(addr, &ifa->addr);
52 else
53 ipv6_addr_set(addr, 0, 0, 0, 0);
54
55 read_unlock_bh(&idev->lock);
56
57 in6_dev_put(idev);
58}
59
60static void bond_na_send(struct net_device *slave_dev,
61 struct in6_addr *daddr,
62 int router,
63 unsigned short vlan_id)
64{
65 struct in6_addr mcaddr;
66 struct icmp6hdr icmp6h = {
67 .icmp6_type = NDISC_NEIGHBOUR_ADVERTISEMENT,
68 };
69 struct sk_buff *skb;
70
71 icmp6h.icmp6_router = router;
72 icmp6h.icmp6_solicited = 0;
73 icmp6h.icmp6_override = 1;
74
75 addrconf_addr_solict_mult(daddr, &mcaddr);
76
77 dprintk("ipv6 na on slave %s: dest %pI6, src %pI6\n",
78 slave->name, &mcaddr, daddr);
79
80 skb = ndisc_build_skb(slave_dev, &mcaddr, daddr, &icmp6h, daddr,
81 ND_OPT_TARGET_LL_ADDR);
82
83 if (!skb) {
84 printk(KERN_ERR DRV_NAME ": NA packet allocation failed\n");
85 return;
86 }
87
88 if (vlan_id) {
89 skb = vlan_put_tag(skb, vlan_id);
90 if (!skb) {
91 printk(KERN_ERR DRV_NAME ": failed to insert VLAN tag\n");
92 return;
93 }
94 }
95
96 ndisc_send_skb(skb, slave_dev, NULL, &mcaddr, daddr, &icmp6h);
97}
98
99/*
100 * Kick out an unsolicited Neighbor Advertisement for an IPv6 address on
101 * the bonding master. This will help the switch learn our address
102 * if in active-backup mode.
103 *
104 * Caller must hold curr_slave_lock for read or better
105 */
106void bond_send_unsolicited_na(struct bonding *bond)
107{
108 struct slave *slave = bond->curr_active_slave;
109 struct vlan_entry *vlan;
110 struct inet6_dev *idev;
111 int is_router;
112
113 dprintk("bond_send_unsol_na: bond %s slave %s\n", bond->dev->name,
114 slave ? slave->dev->name : "NULL");
115
116 if (!slave || !bond->send_unsol_na ||
117 test_bit(__LINK_STATE_LINKWATCH_PENDING, &slave->dev->state))
118 return;
119
120 bond->send_unsol_na--;
121
122 idev = in6_dev_get(bond->dev);
123 if (!idev)
124 return;
125
126 is_router = !!idev->cnf.forwarding;
127
128 in6_dev_put(idev);
129
130 if (!ipv6_addr_any(&bond->master_ipv6))
131 bond_na_send(slave->dev, &bond->master_ipv6, is_router, 0);
132
133 list_for_each_entry(vlan, &bond->vlan_list, vlan_list) {
134 if (!ipv6_addr_any(&vlan->vlan_ipv6)) {
135 bond_na_send(slave->dev, &vlan->vlan_ipv6, is_router,
136 vlan->vlan_id);
137 }
138 }
139}
140
141/*
142 * bond_inet6addr_event: handle inet6addr notifier chain events.
143 *
144 * We keep track of device IPv6 addresses primarily to use as source
145 * addresses in NS probes.
146 *
147 * We track one IPv6 for the main device (if it has one).
148 */
149static int bond_inet6addr_event(struct notifier_block *this,
150 unsigned long event,
151 void *ptr)
152{
153 struct inet6_ifaddr *ifa = ptr;
154 struct net_device *vlan_dev, *event_dev = ifa->idev->dev;
155 struct bonding *bond;
156 struct vlan_entry *vlan;
157
158 if (dev_net(event_dev) != &init_net)
159 return NOTIFY_DONE;
160
161 list_for_each_entry(bond, &bond_dev_list, bond_list) {
162 if (bond->dev == event_dev) {
163 switch (event) {
164 case NETDEV_UP:
165 if (ipv6_addr_any(&bond->master_ipv6))
166 ipv6_addr_copy(&bond->master_ipv6,
167 &ifa->addr);
168 return NOTIFY_OK;
169 case NETDEV_DOWN:
170 if (ipv6_addr_equal(&bond->master_ipv6,
171 &ifa->addr))
172 bond_glean_dev_ipv6(bond->dev,
173 &bond->master_ipv6);
174 return NOTIFY_OK;
175 default:
176 return NOTIFY_DONE;
177 }
178 }
179
180 list_for_each_entry(vlan, &bond->vlan_list, vlan_list) {
181 vlan_dev = vlan_group_get_device(bond->vlgrp,
182 vlan->vlan_id);
183 if (vlan_dev == event_dev) {
184 switch (event) {
185 case NETDEV_UP:
186 if (ipv6_addr_any(&vlan->vlan_ipv6))
187 ipv6_addr_copy(&vlan->vlan_ipv6,
188 &ifa->addr);
189 return NOTIFY_OK;
190 case NETDEV_DOWN:
191 if (ipv6_addr_equal(&vlan->vlan_ipv6,
192 &ifa->addr))
193 bond_glean_dev_ipv6(vlan_dev,
194 &vlan->vlan_ipv6);
195 return NOTIFY_OK;
196 default:
197 return NOTIFY_DONE;
198 }
199 }
200 }
201 }
202 return NOTIFY_DONE;
203}
204
205static struct notifier_block bond_inet6addr_notifier = {
206 .notifier_call = bond_inet6addr_event,
207};
208
209void bond_register_ipv6_notifier(void)
210{
211 register_inet6addr_notifier(&bond_inet6addr_notifier);
212}
213
214void bond_unregister_ipv6_notifier(void)
215{
216 unregister_inet6addr_notifier(&bond_inet6addr_notifier);
217}
218
diff --git a/drivers/net/bonding/bond_main.c b/drivers/net/bonding/bond_main.c
index 39575d764974..02de3e031237 100644
--- a/drivers/net/bonding/bond_main.c
+++ b/drivers/net/bonding/bond_main.c
@@ -89,6 +89,7 @@
89 89
90static int max_bonds = BOND_DEFAULT_MAX_BONDS; 90static int max_bonds = BOND_DEFAULT_MAX_BONDS;
91static int num_grat_arp = 1; 91static int num_grat_arp = 1;
92static int num_unsol_na = 1;
92static int miimon = BOND_LINK_MON_INTERV; 93static int miimon = BOND_LINK_MON_INTERV;
93static int updelay = 0; 94static int updelay = 0;
94static int downdelay = 0; 95static int downdelay = 0;
@@ -96,6 +97,7 @@ static int use_carrier = 1;
96static char *mode = NULL; 97static char *mode = NULL;
97static char *primary = NULL; 98static char *primary = NULL;
98static char *lacp_rate = NULL; 99static char *lacp_rate = NULL;
100static char *ad_select = NULL;
99static char *xmit_hash_policy = NULL; 101static char *xmit_hash_policy = NULL;
100static int arp_interval = BOND_LINK_ARP_INTERV; 102static int arp_interval = BOND_LINK_ARP_INTERV;
101static char *arp_ip_target[BOND_MAX_ARP_TARGETS] = { NULL, }; 103static char *arp_ip_target[BOND_MAX_ARP_TARGETS] = { NULL, };
@@ -107,6 +109,8 @@ module_param(max_bonds, int, 0);
107MODULE_PARM_DESC(max_bonds, "Max number of bonded devices"); 109MODULE_PARM_DESC(max_bonds, "Max number of bonded devices");
108module_param(num_grat_arp, int, 0644); 110module_param(num_grat_arp, int, 0644);
109MODULE_PARM_DESC(num_grat_arp, "Number of gratuitous ARP packets to send on failover event"); 111MODULE_PARM_DESC(num_grat_arp, "Number of gratuitous ARP packets to send on failover event");
112module_param(num_unsol_na, int, 0644);
113MODULE_PARM_DESC(num_unsol_na, "Number of unsolicited IPv6 Neighbor Advertisements packets to send on failover event");
110module_param(miimon, int, 0); 114module_param(miimon, int, 0);
111MODULE_PARM_DESC(miimon, "Link check interval in milliseconds"); 115MODULE_PARM_DESC(miimon, "Link check interval in milliseconds");
112module_param(updelay, int, 0); 116module_param(updelay, int, 0);
@@ -127,6 +131,8 @@ MODULE_PARM_DESC(primary, "Primary network device to use");
127module_param(lacp_rate, charp, 0); 131module_param(lacp_rate, charp, 0);
128MODULE_PARM_DESC(lacp_rate, "LACPDU tx rate to request from 802.3ad partner " 132MODULE_PARM_DESC(lacp_rate, "LACPDU tx rate to request from 802.3ad partner "
129 "(slow/fast)"); 133 "(slow/fast)");
134module_param(ad_select, charp, 0);
135MODULE_PARM_DESC(ad_select, "803.ad aggregation selection logic: stable (0, default), bandwidth (1), count (2)");
130module_param(xmit_hash_policy, charp, 0); 136module_param(xmit_hash_policy, charp, 0);
131MODULE_PARM_DESC(xmit_hash_policy, "XOR hashing method: 0 for layer 2 (default)" 137MODULE_PARM_DESC(xmit_hash_policy, "XOR hashing method: 0 for layer 2 (default)"
132 ", 1 for layer 3+4"); 138 ", 1 for layer 3+4");
@@ -197,6 +203,13 @@ struct bond_parm_tbl fail_over_mac_tbl[] = {
197{ NULL, -1}, 203{ NULL, -1},
198}; 204};
199 205
206struct bond_parm_tbl ad_select_tbl[] = {
207{ "stable", BOND_AD_STABLE},
208{ "bandwidth", BOND_AD_BANDWIDTH},
209{ "count", BOND_AD_COUNT},
210{ NULL, -1},
211};
212
200/*-------------------------- Forward declarations ---------------------------*/ 213/*-------------------------- Forward declarations ---------------------------*/
201 214
202static void bond_send_gratuitous_arp(struct bonding *bond); 215static void bond_send_gratuitous_arp(struct bonding *bond);
@@ -242,14 +255,13 @@ static int bond_add_vlan(struct bonding *bond, unsigned short vlan_id)
242 dprintk("bond: %s, vlan id %d\n", 255 dprintk("bond: %s, vlan id %d\n",
243 (bond ? bond->dev->name: "None"), vlan_id); 256 (bond ? bond->dev->name: "None"), vlan_id);
244 257
245 vlan = kmalloc(sizeof(struct vlan_entry), GFP_KERNEL); 258 vlan = kzalloc(sizeof(struct vlan_entry), GFP_KERNEL);
246 if (!vlan) { 259 if (!vlan) {
247 return -ENOMEM; 260 return -ENOMEM;
248 } 261 }
249 262
250 INIT_LIST_HEAD(&vlan->vlan_list); 263 INIT_LIST_HEAD(&vlan->vlan_list);
251 vlan->vlan_id = vlan_id; 264 vlan->vlan_id = vlan_id;
252 vlan->vlan_ip = 0;
253 265
254 write_lock_bh(&bond->lock); 266 write_lock_bh(&bond->lock);
255 267
@@ -1208,6 +1220,9 @@ void bond_change_active_slave(struct bonding *bond, struct slave *new_active)
1208 bond->send_grat_arp = bond->params.num_grat_arp; 1220 bond->send_grat_arp = bond->params.num_grat_arp;
1209 bond_send_gratuitous_arp(bond); 1221 bond_send_gratuitous_arp(bond);
1210 1222
1223 bond->send_unsol_na = bond->params.num_unsol_na;
1224 bond_send_unsolicited_na(bond);
1225
1211 write_unlock_bh(&bond->curr_slave_lock); 1226 write_unlock_bh(&bond->curr_slave_lock);
1212 read_unlock(&bond->lock); 1227 read_unlock(&bond->lock);
1213 1228
@@ -2463,6 +2478,12 @@ void bond_mii_monitor(struct work_struct *work)
2463 read_unlock(&bond->curr_slave_lock); 2478 read_unlock(&bond->curr_slave_lock);
2464 } 2479 }
2465 2480
2481 if (bond->send_unsol_na) {
2482 read_lock(&bond->curr_slave_lock);
2483 bond_send_unsolicited_na(bond);
2484 read_unlock(&bond->curr_slave_lock);
2485 }
2486
2466 if (bond_miimon_inspect(bond)) { 2487 if (bond_miimon_inspect(bond)) {
2467 read_unlock(&bond->lock); 2488 read_unlock(&bond->lock);
2468 rtnl_lock(); 2489 rtnl_lock();
@@ -3158,6 +3179,12 @@ void bond_activebackup_arp_mon(struct work_struct *work)
3158 read_unlock(&bond->curr_slave_lock); 3179 read_unlock(&bond->curr_slave_lock);
3159 } 3180 }
3160 3181
3182 if (bond->send_unsol_na) {
3183 read_lock(&bond->curr_slave_lock);
3184 bond_send_unsolicited_na(bond);
3185 read_unlock(&bond->curr_slave_lock);
3186 }
3187
3161 if (bond_ab_arp_inspect(bond, delta_in_ticks)) { 3188 if (bond_ab_arp_inspect(bond, delta_in_ticks)) {
3162 read_unlock(&bond->lock); 3189 read_unlock(&bond->lock);
3163 rtnl_lock(); 3190 rtnl_lock();
@@ -3301,6 +3328,8 @@ static void bond_info_show_master(struct seq_file *seq)
3301 seq_puts(seq, "\n802.3ad info\n"); 3328 seq_puts(seq, "\n802.3ad info\n");
3302 seq_printf(seq, "LACP rate: %s\n", 3329 seq_printf(seq, "LACP rate: %s\n",
3303 (bond->params.lacp_fast) ? "fast" : "slow"); 3330 (bond->params.lacp_fast) ? "fast" : "slow");
3331 seq_printf(seq, "Aggregator selection policy (ad_select): %s\n",
3332 ad_select_tbl[bond->params.ad_select].modename);
3304 3333
3305 if (bond_3ad_get_active_agg_info(bond, &ad_info)) { 3334 if (bond_3ad_get_active_agg_info(bond, &ad_info)) {
3306 seq_printf(seq, "bond %s has no active aggregator\n", 3335 seq_printf(seq, "bond %s has no active aggregator\n",
@@ -3807,6 +3836,7 @@ static int bond_open(struct net_device *bond_dev)
3807 queue_delayed_work(bond->wq, &bond->ad_work, 0); 3836 queue_delayed_work(bond->wq, &bond->ad_work, 0);
3808 /* register to receive LACPDUs */ 3837 /* register to receive LACPDUs */
3809 bond_register_lacpdu(bond); 3838 bond_register_lacpdu(bond);
3839 bond_3ad_initiate_agg_selection(bond, 1);
3810 } 3840 }
3811 3841
3812 return 0; 3842 return 0;
@@ -3827,6 +3857,7 @@ static int bond_close(struct net_device *bond_dev)
3827 write_lock_bh(&bond->lock); 3857 write_lock_bh(&bond->lock);
3828 3858
3829 bond->send_grat_arp = 0; 3859 bond->send_grat_arp = 0;
3860 bond->send_unsol_na = 0;
3830 3861
3831 /* signal timers not to re-arm */ 3862 /* signal timers not to re-arm */
3832 bond->kill_timers = 1; 3863 bond->kill_timers = 1;
@@ -4542,6 +4573,7 @@ static int bond_init(struct net_device *bond_dev, struct bond_params *params)
4542 bond->primary_slave = NULL; 4573 bond->primary_slave = NULL;
4543 bond->dev = bond_dev; 4574 bond->dev = bond_dev;
4544 bond->send_grat_arp = 0; 4575 bond->send_grat_arp = 0;
4576 bond->send_unsol_na = 0;
4545 bond->setup_by_slave = 0; 4577 bond->setup_by_slave = 0;
4546 INIT_LIST_HEAD(&bond->vlan_list); 4578 INIT_LIST_HEAD(&bond->vlan_list);
4547 4579
@@ -4744,6 +4776,23 @@ static int bond_check_params(struct bond_params *params)
4744 } 4776 }
4745 } 4777 }
4746 4778
4779 if (ad_select) {
4780 params->ad_select = bond_parse_parm(ad_select, ad_select_tbl);
4781 if (params->ad_select == -1) {
4782 printk(KERN_ERR DRV_NAME
4783 ": Error: Invalid ad_select \"%s\"\n",
4784 ad_select == NULL ? "NULL" : ad_select);
4785 return -EINVAL;
4786 }
4787
4788 if (bond_mode != BOND_MODE_8023AD) {
4789 printk(KERN_WARNING DRV_NAME
4790 ": ad_select param only affects 802.3ad mode\n");
4791 }
4792 } else {
4793 params->ad_select = BOND_AD_STABLE;
4794 }
4795
4747 if (max_bonds < 0 || max_bonds > INT_MAX) { 4796 if (max_bonds < 0 || max_bonds > INT_MAX) {
4748 printk(KERN_WARNING DRV_NAME 4797 printk(KERN_WARNING DRV_NAME
4749 ": Warning: max_bonds (%d) not in range %d-%d, so it " 4798 ": Warning: max_bonds (%d) not in range %d-%d, so it "
@@ -4791,6 +4840,13 @@ static int bond_check_params(struct bond_params *params)
4791 num_grat_arp = 1; 4840 num_grat_arp = 1;
4792 } 4841 }
4793 4842
4843 if (num_unsol_na < 0 || num_unsol_na > 255) {
4844 printk(KERN_WARNING DRV_NAME
4845 ": Warning: num_unsol_na (%d) not in range 0-255 so it "
4846 "was reset to 1 \n", num_unsol_na);
4847 num_unsol_na = 1;
4848 }
4849
4794 /* reset values for 802.3ad */ 4850 /* reset values for 802.3ad */
4795 if (bond_mode == BOND_MODE_8023AD) { 4851 if (bond_mode == BOND_MODE_8023AD) {
4796 if (!miimon) { 4852 if (!miimon) {
@@ -4992,6 +5048,7 @@ static int bond_check_params(struct bond_params *params)
4992 params->xmit_policy = xmit_hashtype; 5048 params->xmit_policy = xmit_hashtype;
4993 params->miimon = miimon; 5049 params->miimon = miimon;
4994 params->num_grat_arp = num_grat_arp; 5050 params->num_grat_arp = num_grat_arp;
5051 params->num_unsol_na = num_unsol_na;
4995 params->arp_interval = arp_interval; 5052 params->arp_interval = arp_interval;
4996 params->arp_validate = arp_validate_value; 5053 params->arp_validate = arp_validate_value;
4997 params->updelay = updelay; 5054 params->updelay = updelay;
@@ -5144,6 +5201,7 @@ static int __init bonding_init(void)
5144 5201
5145 register_netdevice_notifier(&bond_netdev_notifier); 5202 register_netdevice_notifier(&bond_netdev_notifier);
5146 register_inetaddr_notifier(&bond_inetaddr_notifier); 5203 register_inetaddr_notifier(&bond_inetaddr_notifier);
5204 bond_register_ipv6_notifier();
5147 5205
5148 goto out; 5206 goto out;
5149err: 5207err:
@@ -5166,6 +5224,7 @@ static void __exit bonding_exit(void)
5166{ 5224{
5167 unregister_netdevice_notifier(&bond_netdev_notifier); 5225 unregister_netdevice_notifier(&bond_netdev_notifier);
5168 unregister_inetaddr_notifier(&bond_inetaddr_notifier); 5226 unregister_inetaddr_notifier(&bond_inetaddr_notifier);
5227 bond_unregister_ipv6_notifier();
5169 5228
5170 bond_destroy_sysfs(); 5229 bond_destroy_sysfs();
5171 5230
diff --git a/drivers/net/bonding/bond_sysfs.c b/drivers/net/bonding/bond_sysfs.c
index e400d7dfdfc8..aaf2927b5c38 100644
--- a/drivers/net/bonding/bond_sysfs.c
+++ b/drivers/net/bonding/bond_sysfs.c
@@ -48,6 +48,7 @@ extern struct list_head bond_dev_list;
48extern struct bond_params bonding_defaults; 48extern struct bond_params bonding_defaults;
49extern struct bond_parm_tbl bond_mode_tbl[]; 49extern struct bond_parm_tbl bond_mode_tbl[];
50extern struct bond_parm_tbl bond_lacp_tbl[]; 50extern struct bond_parm_tbl bond_lacp_tbl[];
51extern struct bond_parm_tbl ad_select_tbl[];
51extern struct bond_parm_tbl xmit_hashtype_tbl[]; 52extern struct bond_parm_tbl xmit_hashtype_tbl[];
52extern struct bond_parm_tbl arp_validate_tbl[]; 53extern struct bond_parm_tbl arp_validate_tbl[];
53extern struct bond_parm_tbl fail_over_mac_tbl[]; 54extern struct bond_parm_tbl fail_over_mac_tbl[];
@@ -944,6 +945,53 @@ out:
944} 945}
945static DEVICE_ATTR(lacp_rate, S_IRUGO | S_IWUSR, bonding_show_lacp, bonding_store_lacp); 946static DEVICE_ATTR(lacp_rate, S_IRUGO | S_IWUSR, bonding_show_lacp, bonding_store_lacp);
946 947
948static ssize_t bonding_show_ad_select(struct device *d,
949 struct device_attribute *attr,
950 char *buf)
951{
952 struct bonding *bond = to_bond(d);
953
954 return sprintf(buf, "%s %d\n",
955 ad_select_tbl[bond->params.ad_select].modename,
956 bond->params.ad_select);
957}
958
959
960static ssize_t bonding_store_ad_select(struct device *d,
961 struct device_attribute *attr,
962 const char *buf, size_t count)
963{
964 int new_value, ret = count;
965 struct bonding *bond = to_bond(d);
966
967 if (bond->dev->flags & IFF_UP) {
968 printk(KERN_ERR DRV_NAME
969 ": %s: Unable to update ad_select because interface "
970 "is up.\n", bond->dev->name);
971 ret = -EPERM;
972 goto out;
973 }
974
975 new_value = bond_parse_parm(buf, ad_select_tbl);
976
977 if (new_value != -1) {
978 bond->params.ad_select = new_value;
979 printk(KERN_INFO DRV_NAME
980 ": %s: Setting ad_select to %s (%d).\n",
981 bond->dev->name, ad_select_tbl[new_value].modename,
982 new_value);
983 } else {
984 printk(KERN_ERR DRV_NAME
985 ": %s: Ignoring invalid ad_select value %.*s.\n",
986 bond->dev->name, (int)strlen(buf) - 1, buf);
987 ret = -EINVAL;
988 }
989out:
990 return ret;
991}
992
993static DEVICE_ATTR(ad_select, S_IRUGO | S_IWUSR, bonding_show_ad_select, bonding_store_ad_select);
994
947/* 995/*
948 * Show and set the number of grat ARP to send after a failover event. 996 * Show and set the number of grat ARP to send after a failover event.
949 */ 997 */
@@ -983,6 +1031,47 @@ out:
983 return ret; 1031 return ret;
984} 1032}
985static DEVICE_ATTR(num_grat_arp, S_IRUGO | S_IWUSR, bonding_show_n_grat_arp, bonding_store_n_grat_arp); 1033static DEVICE_ATTR(num_grat_arp, S_IRUGO | S_IWUSR, bonding_show_n_grat_arp, bonding_store_n_grat_arp);
1034
1035/*
1036 * Show and set the number of unsolicted NA's to send after a failover event.
1037 */
1038static ssize_t bonding_show_n_unsol_na(struct device *d,
1039 struct device_attribute *attr,
1040 char *buf)
1041{
1042 struct bonding *bond = to_bond(d);
1043
1044 return sprintf(buf, "%d\n", bond->params.num_unsol_na);
1045}
1046
1047static ssize_t bonding_store_n_unsol_na(struct device *d,
1048 struct device_attribute *attr,
1049 const char *buf, size_t count)
1050{
1051 int new_value, ret = count;
1052 struct bonding *bond = to_bond(d);
1053
1054 if (sscanf(buf, "%d", &new_value) != 1) {
1055 printk(KERN_ERR DRV_NAME
1056 ": %s: no num_unsol_na value specified.\n",
1057 bond->dev->name);
1058 ret = -EINVAL;
1059 goto out;
1060 }
1061 if (new_value < 0 || new_value > 255) {
1062 printk(KERN_ERR DRV_NAME
1063 ": %s: Invalid num_unsol_na value %d not in range 0-255; rejected.\n",
1064 bond->dev->name, new_value);
1065 ret = -EINVAL;
1066 goto out;
1067 } else {
1068 bond->params.num_unsol_na = new_value;
1069 }
1070out:
1071 return ret;
1072}
1073static DEVICE_ATTR(num_unsol_na, S_IRUGO | S_IWUSR, bonding_show_n_unsol_na, bonding_store_n_unsol_na);
1074
986/* 1075/*
987 * Show and set the MII monitor interval. There are two tricky bits 1076 * Show and set the MII monitor interval. There are two tricky bits
988 * here. First, if MII monitoring is activated, then we must disable 1077 * here. First, if MII monitoring is activated, then we must disable
@@ -1418,8 +1507,10 @@ static struct attribute *per_bond_attrs[] = {
1418 &dev_attr_downdelay.attr, 1507 &dev_attr_downdelay.attr,
1419 &dev_attr_updelay.attr, 1508 &dev_attr_updelay.attr,
1420 &dev_attr_lacp_rate.attr, 1509 &dev_attr_lacp_rate.attr,
1510 &dev_attr_ad_select.attr,
1421 &dev_attr_xmit_hash_policy.attr, 1511 &dev_attr_xmit_hash_policy.attr,
1422 &dev_attr_num_grat_arp.attr, 1512 &dev_attr_num_grat_arp.attr,
1513 &dev_attr_num_unsol_na.attr,
1423 &dev_attr_miimon.attr, 1514 &dev_attr_miimon.attr,
1424 &dev_attr_primary.attr, 1515 &dev_attr_primary.attr,
1425 &dev_attr_use_carrier.attr, 1516 &dev_attr_use_carrier.attr,
diff --git a/drivers/net/bonding/bonding.h b/drivers/net/bonding/bonding.h
index ffb668dd6d3b..b5eb8e65b309 100644
--- a/drivers/net/bonding/bonding.h
+++ b/drivers/net/bonding/bonding.h
@@ -19,16 +19,19 @@
19#include <linux/proc_fs.h> 19#include <linux/proc_fs.h>
20#include <linux/if_bonding.h> 20#include <linux/if_bonding.h>
21#include <linux/kobject.h> 21#include <linux/kobject.h>
22#include <linux/in6.h>
22#include "bond_3ad.h" 23#include "bond_3ad.h"
23#include "bond_alb.h" 24#include "bond_alb.h"
24 25
25#define DRV_VERSION "3.3.0" 26#define DRV_VERSION "3.5.0"
26#define DRV_RELDATE "June 10, 2008" 27#define DRV_RELDATE "November 4, 2008"
27#define DRV_NAME "bonding" 28#define DRV_NAME "bonding"
28#define DRV_DESCRIPTION "Ethernet Channel Bonding Driver" 29#define DRV_DESCRIPTION "Ethernet Channel Bonding Driver"
29 30
30#define BOND_MAX_ARP_TARGETS 16 31#define BOND_MAX_ARP_TARGETS 16
31 32
33extern struct list_head bond_dev_list;
34
32#ifdef BONDING_DEBUG 35#ifdef BONDING_DEBUG
33#define dprintk(fmt, args...) \ 36#define dprintk(fmt, args...) \
34 printk(KERN_DEBUG \ 37 printk(KERN_DEBUG \
@@ -126,6 +129,7 @@ struct bond_params {
126 int xmit_policy; 129 int xmit_policy;
127 int miimon; 130 int miimon;
128 int num_grat_arp; 131 int num_grat_arp;
132 int num_unsol_na;
129 int arp_interval; 133 int arp_interval;
130 int arp_validate; 134 int arp_validate;
131 int use_carrier; 135 int use_carrier;
@@ -133,6 +137,7 @@ struct bond_params {
133 int updelay; 137 int updelay;
134 int downdelay; 138 int downdelay;
135 int lacp_fast; 139 int lacp_fast;
140 int ad_select;
136 char primary[IFNAMSIZ]; 141 char primary[IFNAMSIZ];
137 __be32 arp_targets[BOND_MAX_ARP_TARGETS]; 142 __be32 arp_targets[BOND_MAX_ARP_TARGETS];
138}; 143};
@@ -148,6 +153,9 @@ struct vlan_entry {
148 struct list_head vlan_list; 153 struct list_head vlan_list;
149 __be32 vlan_ip; 154 __be32 vlan_ip;
150 unsigned short vlan_id; 155 unsigned short vlan_id;
156#if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
157 struct in6_addr vlan_ipv6;
158#endif
151}; 159};
152 160
153struct slave { 161struct slave {
@@ -195,6 +203,7 @@ struct bonding {
195 rwlock_t curr_slave_lock; 203 rwlock_t curr_slave_lock;
196 s8 kill_timers; 204 s8 kill_timers;
197 s8 send_grat_arp; 205 s8 send_grat_arp;
206 s8 send_unsol_na;
198 s8 setup_by_slave; 207 s8 setup_by_slave;
199 struct net_device_stats stats; 208 struct net_device_stats stats;
200#ifdef CONFIG_PROC_FS 209#ifdef CONFIG_PROC_FS
@@ -218,6 +227,9 @@ struct bonding {
218 struct delayed_work arp_work; 227 struct delayed_work arp_work;
219 struct delayed_work alb_work; 228 struct delayed_work alb_work;
220 struct delayed_work ad_work; 229 struct delayed_work ad_work;
230#if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
231 struct in6_addr master_ipv6;
232#endif
221}; 233};
222 234
223/** 235/**
@@ -341,5 +353,24 @@ extern struct bond_parm_tbl xmit_hashtype_tbl[];
341extern struct bond_parm_tbl arp_validate_tbl[]; 353extern struct bond_parm_tbl arp_validate_tbl[];
342extern struct bond_parm_tbl fail_over_mac_tbl[]; 354extern struct bond_parm_tbl fail_over_mac_tbl[];
343 355
356#if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
357void bond_send_unsolicited_na(struct bonding *bond);
358void bond_register_ipv6_notifier(void);
359void bond_unregister_ipv6_notifier(void);
360#else
361static inline void bond_send_unsolicited_na(struct bonding *bond)
362{
363 return;
364}
365static inline void bond_register_ipv6_notifier(void)
366{
367 return;
368}
369static inline void bond_unregister_ipv6_notifier(void)
370{
371 return;
372}
373#endif
374
344#endif /* _LINUX_BONDING_H */ 375#endif /* _LINUX_BONDING_H */
345 376
diff --git a/drivers/net/ehea/ehea.h b/drivers/net/ehea/ehea.h
index 002d918fb4c7..9930d5f8b9e1 100644
--- a/drivers/net/ehea/ehea.h
+++ b/drivers/net/ehea/ehea.h
@@ -40,7 +40,7 @@
40#include <asm/io.h> 40#include <asm/io.h>
41 41
42#define DRV_NAME "ehea" 42#define DRV_NAME "ehea"
43#define DRV_VERSION "EHEA_0095" 43#define DRV_VERSION "EHEA_0096"
44 44
45/* eHEA capability flags */ 45/* eHEA capability flags */
46#define DLPAR_PORT_ADD_REM 1 46#define DLPAR_PORT_ADD_REM 1
diff --git a/drivers/net/ehea/ehea_qmr.c b/drivers/net/ehea/ehea_qmr.c
index 9d006878f045..3c0ec82f36fb 100644
--- a/drivers/net/ehea/ehea_qmr.c
+++ b/drivers/net/ehea/ehea_qmr.c
@@ -653,7 +653,7 @@ static int ehea_update_busmap(unsigned long pfn, unsigned long nr_pages, int add
653 int top = ehea_calc_index(i, EHEA_TOP_INDEX_SHIFT); 653 int top = ehea_calc_index(i, EHEA_TOP_INDEX_SHIFT);
654 int dir = ehea_calc_index(i, EHEA_DIR_INDEX_SHIFT); 654 int dir = ehea_calc_index(i, EHEA_DIR_INDEX_SHIFT);
655 int idx = i & EHEA_INDEX_MASK; 655 int idx = i & EHEA_INDEX_MASK;
656 656
657 if (add) { 657 if (add) {
658 int ret = ehea_init_bmap(ehea_bmap, top, dir); 658 int ret = ehea_init_bmap(ehea_bmap, top, dir);
659 if (ret) 659 if (ret)
@@ -780,7 +780,7 @@ void ehea_destroy_busmap(void)
780 780
781 kfree(ehea_bmap); 781 kfree(ehea_bmap);
782 ehea_bmap = NULL; 782 ehea_bmap = NULL;
783out_destroy: 783out_destroy:
784 mutex_unlock(&ehea_busmap_mutex); 784 mutex_unlock(&ehea_busmap_mutex);
785} 785}
786 786
@@ -858,10 +858,10 @@ static u64 ehea_reg_mr_sections(int top, int dir, u64 *pt,
858 for (idx = 0; idx < EHEA_MAP_ENTRIES; idx++) { 858 for (idx = 0; idx < EHEA_MAP_ENTRIES; idx++) {
859 if (!ehea_bmap->top[top]->dir[dir]->ent[idx]) 859 if (!ehea_bmap->top[top]->dir[dir]->ent[idx])
860 continue; 860 continue;
861 861
862 hret = ehea_reg_mr_section(top, dir, idx, pt, adapter, mr); 862 hret = ehea_reg_mr_section(top, dir, idx, pt, adapter, mr);
863 if ((hret != H_SUCCESS) && (hret != H_PAGE_REGISTERED)) 863 if ((hret != H_SUCCESS) && (hret != H_PAGE_REGISTERED))
864 return hret; 864 return hret;
865 } 865 }
866 return hret; 866 return hret;
867} 867}
@@ -879,7 +879,7 @@ static u64 ehea_reg_mr_dir_sections(int top, u64 *pt,
879 879
880 hret = ehea_reg_mr_sections(top, dir, pt, adapter, mr); 880 hret = ehea_reg_mr_sections(top, dir, pt, adapter, mr);
881 if ((hret != H_SUCCESS) && (hret != H_PAGE_REGISTERED)) 881 if ((hret != H_SUCCESS) && (hret != H_PAGE_REGISTERED))
882 return hret; 882 return hret;
883 } 883 }
884 return hret; 884 return hret;
885} 885}
diff --git a/drivers/net/pcmcia/fmvj18x_cs.c b/drivers/net/pcmcia/fmvj18x_cs.c
index e4f8fe3c5dae..69dcfbbabe82 100644
--- a/drivers/net/pcmcia/fmvj18x_cs.c
+++ b/drivers/net/pcmcia/fmvj18x_cs.c
@@ -125,6 +125,7 @@ typedef struct local_info_t {
125 u_short tx_queue_len; 125 u_short tx_queue_len;
126 cardtype_t cardtype; 126 cardtype_t cardtype;
127 u_short sent; 127 u_short sent;
128 u_char __iomem *base;
128} local_info_t; 129} local_info_t;
129 130
130#define MC_FILTERBREAK 64 131#define MC_FILTERBREAK 64
@@ -242,6 +243,7 @@ static int fmvj18x_probe(struct pcmcia_device *link)
242 lp = netdev_priv(dev); 243 lp = netdev_priv(dev);
243 link->priv = dev; 244 link->priv = dev;
244 lp->p_dev = link; 245 lp->p_dev = link;
246 lp->base = NULL;
245 247
246 /* The io structure describes IO port mapping */ 248 /* The io structure describes IO port mapping */
247 link->io.NumPorts1 = 32; 249 link->io.NumPorts1 = 32;
@@ -442,8 +444,10 @@ static int fmvj18x_config(struct pcmcia_device *link)
442 dev->irq = link->irq.AssignedIRQ; 444 dev->irq = link->irq.AssignedIRQ;
443 dev->base_addr = link->io.BasePort1; 445 dev->base_addr = link->io.BasePort1;
444 446
445 if (link->io.BasePort2 != 0) 447 if (link->io.BasePort2 != 0) {
446 fmvj18x_setup_mfc(link); 448 ret = fmvj18x_setup_mfc(link);
449 if (ret != 0) goto failed;
450 }
447 451
448 ioaddr = dev->base_addr; 452 ioaddr = dev->base_addr;
449 453
@@ -610,10 +614,10 @@ static int fmvj18x_setup_mfc(struct pcmcia_device *link)
610{ 614{
611 win_req_t req; 615 win_req_t req;
612 memreq_t mem; 616 memreq_t mem;
613 u_char __iomem *base; 617 int i;
614 int i, j;
615 struct net_device *dev = link->priv; 618 struct net_device *dev = link->priv;
616 unsigned int ioaddr; 619 unsigned int ioaddr;
620 local_info_t *lp = netdev_priv(dev);
617 621
618 /* Allocate a small memory window */ 622 /* Allocate a small memory window */
619 req.Attributes = WIN_DATA_WIDTH_8|WIN_MEMORY_TYPE_AM|WIN_ENABLE; 623 req.Attributes = WIN_DATA_WIDTH_8|WIN_MEMORY_TYPE_AM|WIN_ENABLE;
@@ -625,25 +629,32 @@ static int fmvj18x_setup_mfc(struct pcmcia_device *link)
625 return -1; 629 return -1;
626 } 630 }
627 631
628 base = ioremap(req.Base, req.Size); 632 lp->base = ioremap(req.Base, req.Size);
633 if (lp->base == NULL) {
634 printk(KERN_NOTICE "fmvj18x_cs: ioremap failed\n");
635 return -1;
636 }
637
629 mem.Page = 0; 638 mem.Page = 0;
630 mem.CardOffset = 0; 639 mem.CardOffset = 0;
631 pcmcia_map_mem_page(link->win, &mem); 640 i = pcmcia_map_mem_page(link->win, &mem);
632 641 if (i != 0) {
642 iounmap(lp->base);
643 lp->base = NULL;
644 cs_error(link, MapMemPage, i);
645 return -1;
646 }
647
633 ioaddr = dev->base_addr; 648 ioaddr = dev->base_addr;
634 writeb(0x47, base+0x800); /* Config Option Register of LAN */ 649 writeb(0x47, lp->base+0x800); /* Config Option Register of LAN */
635 writeb(0x0, base+0x802); /* Config and Status Register */ 650 writeb(0x0, lp->base+0x802); /* Config and Status Register */
636 651
637 writeb(ioaddr & 0xff, base+0x80a); /* I/O Base(Low) of LAN */ 652 writeb(ioaddr & 0xff, lp->base+0x80a); /* I/O Base(Low) of LAN */
638 writeb((ioaddr >> 8) & 0xff, base+0x80c); /* I/O Base(High) of LAN */ 653 writeb((ioaddr >> 8) & 0xff, lp->base+0x80c); /* I/O Base(High) of LAN */
639 654
640 writeb(0x45, base+0x820); /* Config Option Register of Modem */ 655 writeb(0x45, lp->base+0x820); /* Config Option Register of Modem */
641 writeb(0x8, base+0x822); /* Config and Status Register */ 656 writeb(0x8, lp->base+0x822); /* Config and Status Register */
642 657
643 iounmap(base);
644 j = pcmcia_release_window(link->win);
645 if (j != 0)
646 cs_error(link, ReleaseWindow, j);
647 return 0; 658 return 0;
648 659
649} 660}
@@ -651,8 +662,25 @@ static int fmvj18x_setup_mfc(struct pcmcia_device *link)
651 662
652static void fmvj18x_release(struct pcmcia_device *link) 663static void fmvj18x_release(struct pcmcia_device *link)
653{ 664{
654 DEBUG(0, "fmvj18x_release(0x%p)\n", link); 665
655 pcmcia_disable_device(link); 666 struct net_device *dev = link->priv;
667 local_info_t *lp = netdev_priv(dev);
668 u_char __iomem *tmp;
669 int j;
670
671 DEBUG(0, "fmvj18x_release(0x%p)\n", link);
672
673 if (lp->base != NULL) {
674 tmp = lp->base;
675 lp->base = NULL; /* set NULL before iounmap */
676 iounmap(tmp);
677 j = pcmcia_release_window(link->win);
678 if (j != 0)
679 cs_error(link, ReleaseWindow, j);
680 }
681
682 pcmcia_disable_device(link);
683
656} 684}
657 685
658static int fmvj18x_suspend(struct pcmcia_device *link) 686static int fmvj18x_suspend(struct pcmcia_device *link)
@@ -783,6 +811,13 @@ static irqreturn_t fjn_interrupt(int dummy, void *dev_id)
783 811
784 outb(D_TX_INTR, ioaddr + TX_INTR); 812 outb(D_TX_INTR, ioaddr + TX_INTR);
785 outb(D_RX_INTR, ioaddr + RX_INTR); 813 outb(D_RX_INTR, ioaddr + RX_INTR);
814
815 if (lp->base != NULL) {
816 /* Ack interrupt for multifunction card */
817 writeb(0x01, lp->base+0x802);
818 writeb(0x09, lp->base+0x822);
819 }
820
786 return IRQ_HANDLED; 821 return IRQ_HANDLED;
787 822
788} /* fjn_interrupt */ 823} /* fjn_interrupt */
diff --git a/drivers/net/phy/smsc.c b/drivers/net/phy/smsc.c
index 73baa7a3bb0e..c05d38d46350 100644
--- a/drivers/net/phy/smsc.c
+++ b/drivers/net/phy/smsc.c
@@ -126,6 +126,27 @@ static struct phy_driver lan8700_driver = {
126 .driver = { .owner = THIS_MODULE, } 126 .driver = { .owner = THIS_MODULE, }
127}; 127};
128 128
129static struct phy_driver lan911x_int_driver = {
130 .phy_id = 0x0007c0d0, /* OUI=0x00800f, Model#=0x0d */
131 .phy_id_mask = 0xfffffff0,
132 .name = "SMSC LAN911x Internal PHY",
133
134 .features = (PHY_BASIC_FEATURES | SUPPORTED_Pause
135 | SUPPORTED_Asym_Pause),
136 .flags = PHY_HAS_INTERRUPT | PHY_HAS_MAGICANEG,
137
138 /* basic functions */
139 .config_aneg = genphy_config_aneg,
140 .read_status = genphy_read_status,
141 .config_init = smsc_phy_config_init,
142
143 /* IRQ related */
144 .ack_interrupt = smsc_phy_ack_interrupt,
145 .config_intr = smsc_phy_config_intr,
146
147 .driver = { .owner = THIS_MODULE, }
148};
149
129static int __init smsc_init(void) 150static int __init smsc_init(void)
130{ 151{
131 int ret; 152 int ret;
@@ -142,8 +163,14 @@ static int __init smsc_init(void)
142 if (ret) 163 if (ret)
143 goto err3; 164 goto err3;
144 165
166 ret = phy_driver_register (&lan911x_int_driver);
167 if (ret)
168 goto err4;
169
145 return 0; 170 return 0;
146 171
172err4:
173 phy_driver_unregister (&lan8700_driver);
147err3: 174err3:
148 phy_driver_unregister (&lan8187_driver); 175 phy_driver_unregister (&lan8187_driver);
149err2: 176err2:
@@ -154,6 +181,7 @@ err1:
154 181
155static void __exit smsc_exit(void) 182static void __exit smsc_exit(void)
156{ 183{
184 phy_driver_unregister (&lan911x_int_driver);
157 phy_driver_unregister (&lan8700_driver); 185 phy_driver_unregister (&lan8700_driver);
158 phy_driver_unregister (&lan8187_driver); 186 phy_driver_unregister (&lan8187_driver);
159 phy_driver_unregister (&lan83c185_driver); 187 phy_driver_unregister (&lan83c185_driver);
diff --git a/drivers/net/sfc/Kconfig b/drivers/net/sfc/Kconfig
index 3be13b592b4d..3e25fb38f739 100644
--- a/drivers/net/sfc/Kconfig
+++ b/drivers/net/sfc/Kconfig
@@ -12,3 +12,11 @@ config SFC
12 12
13 To compile this driver as a module, choose M here. The module 13 To compile this driver as a module, choose M here. The module
14 will be called sfc. 14 will be called sfc.
15config SFC_MTD
16 bool "Solarflare Solarstorm SFC4000 flash MTD support"
17 depends on SFC && MTD
18 default y
19 help
20 This exposes the on-board flash memory as an MTD device (e.g.
21 /dev/mtd1). This makes it possible to upload new boot code
22 to the NIC.
diff --git a/drivers/net/sfc/Makefile b/drivers/net/sfc/Makefile
index c8f5704c8fb1..e507daa4f0e8 100644
--- a/drivers/net/sfc/Makefile
+++ b/drivers/net/sfc/Makefile
@@ -1,5 +1,6 @@
1sfc-y += efx.o falcon.o tx.o rx.o falcon_xmac.o \ 1sfc-y += efx.o falcon.o tx.o rx.o falcon_xmac.o \
2 selftest.o ethtool.o xfp_phy.o \ 2 selftest.o ethtool.o xfp_phy.o \
3 mdio_10g.o tenxpress.o boards.o sfe4001.o 3 mdio_10g.o tenxpress.o boards.o sfe4001.o
4sfc-$(CONFIG_SFC_MTD) += mtd.o
4 5
5obj-$(CONFIG_SFC) += sfc.o 6obj-$(CONFIG_SFC) += sfc.o
diff --git a/drivers/net/sfc/boards.c b/drivers/net/sfc/boards.c
index 99e602373269..edf026280bec 100644
--- a/drivers/net/sfc/boards.c
+++ b/drivers/net/sfc/boards.c
@@ -11,6 +11,7 @@
11#include "phy.h" 11#include "phy.h"
12#include "boards.h" 12#include "boards.h"
13#include "efx.h" 13#include "efx.h"
14#include "workarounds.h"
14 15
15/* Macros for unpacking the board revision */ 16/* Macros for unpacking the board revision */
16/* The revision info is in host byte order. */ 17/* The revision info is in host byte order. */
@@ -52,9 +53,128 @@ static void board_blink(struct efx_nic *efx, bool blink)
52} 53}
53 54
54/***************************************************************************** 55/*****************************************************************************
56 * Support for LM87 sensor chip used on several boards
57 */
58#define LM87_REG_ALARMS1 0x41
59#define LM87_REG_ALARMS2 0x42
60#define LM87_IN_LIMITS(nr, _min, _max) \
61 0x2B + (nr) * 2, _max, 0x2C + (nr) * 2, _min
62#define LM87_AIN_LIMITS(nr, _min, _max) \
63 0x3B + (nr), _max, 0x1A + (nr), _min
64#define LM87_TEMP_INT_LIMITS(_min, _max) \
65 0x39, _max, 0x3A, _min
66#define LM87_TEMP_EXT1_LIMITS(_min, _max) \
67 0x37, _max, 0x38, _min
68
69#define LM87_ALARM_TEMP_INT 0x10
70#define LM87_ALARM_TEMP_EXT1 0x20
71
72#if defined(CONFIG_SENSORS_LM87) || defined(CONFIG_SENSORS_LM87_MODULE)
73
74static int efx_init_lm87(struct efx_nic *efx, struct i2c_board_info *info,
75 const u8 *reg_values)
76{
77 struct i2c_client *client = i2c_new_device(&efx->i2c_adap, info);
78 int rc;
79
80 if (!client)
81 return -EIO;
82
83 while (*reg_values) {
84 u8 reg = *reg_values++;
85 u8 value = *reg_values++;
86 rc = i2c_smbus_write_byte_data(client, reg, value);
87 if (rc)
88 goto err;
89 }
90
91 efx->board_info.hwmon_client = client;
92 return 0;
93
94err:
95 i2c_unregister_device(client);
96 return rc;
97}
98
99static void efx_fini_lm87(struct efx_nic *efx)
100{
101 i2c_unregister_device(efx->board_info.hwmon_client);
102}
103
104static int efx_check_lm87(struct efx_nic *efx, unsigned mask)
105{
106 struct i2c_client *client = efx->board_info.hwmon_client;
107 s32 alarms1, alarms2;
108
109 /* If link is up then do not monitor temperature */
110 if (EFX_WORKAROUND_7884(efx) && efx->link_up)
111 return 0;
112
113 alarms1 = i2c_smbus_read_byte_data(client, LM87_REG_ALARMS1);
114 alarms2 = i2c_smbus_read_byte_data(client, LM87_REG_ALARMS2);
115 if (alarms1 < 0)
116 return alarms1;
117 if (alarms2 < 0)
118 return alarms2;
119 alarms1 &= mask;
120 alarms2 &= mask >> 8;
121 if (alarms1 || alarms2) {
122 EFX_ERR(efx,
123 "LM87 detected a hardware failure (status %02x:%02x)"
124 "%s%s\n",
125 alarms1, alarms2,
126 (alarms1 & LM87_ALARM_TEMP_INT) ? " INTERNAL" : "",
127 (alarms1 & LM87_ALARM_TEMP_EXT1) ? " EXTERNAL" : "");
128 return -ERANGE;
129 }
130
131 return 0;
132}
133
134#else /* !CONFIG_SENSORS_LM87 */
135
136static inline int
137efx_init_lm87(struct efx_nic *efx, struct i2c_board_info *info,
138 const u8 *reg_values)
139{
140 return 0;
141}
142static inline void efx_fini_lm87(struct efx_nic *efx)
143{
144}
145static inline int efx_check_lm87(struct efx_nic *efx, unsigned mask)
146{
147 return 0;
148}
149
150#endif /* CONFIG_SENSORS_LM87 */
151
152/*****************************************************************************
55 * Support for the SFE4002 153 * Support for the SFE4002
56 * 154 *
57 */ 155 */
156static u8 sfe4002_lm87_channel = 0x03; /* use AIN not FAN inputs */
157
158static const u8 sfe4002_lm87_regs[] = {
159 LM87_IN_LIMITS(0, 0x83, 0x91), /* 2.5V: 1.8V +/- 5% */
160 LM87_IN_LIMITS(1, 0x51, 0x5a), /* Vccp1: 1.2V +/- 5% */
161 LM87_IN_LIMITS(2, 0xb6, 0xca), /* 3.3V: 3.3V +/- 5% */
162 LM87_IN_LIMITS(3, 0xb0, 0xc9), /* 5V: 4.6-5.2V */
163 LM87_IN_LIMITS(4, 0xb0, 0xe0), /* 12V: 11-14V */
164 LM87_IN_LIMITS(5, 0x44, 0x4b), /* Vccp2: 1.0V +/- 5% */
165 LM87_AIN_LIMITS(0, 0xa0, 0xb2), /* AIN1: 1.66V +/- 5% */
166 LM87_AIN_LIMITS(1, 0x91, 0xa1), /* AIN2: 1.5V +/- 5% */
167 LM87_TEMP_INT_LIMITS(10, 60), /* board */
168 LM87_TEMP_EXT1_LIMITS(10, 70), /* Falcon */
169 0
170};
171
172static struct i2c_board_info sfe4002_hwmon_info = {
173 I2C_BOARD_INFO("lm87", 0x2e),
174 .platform_data = &sfe4002_lm87_channel,
175 .irq = -1,
176};
177
58/****************************************************************************/ 178/****************************************************************************/
59/* LED allocations. Note that on rev A0 boards the schematic and the reality 179/* LED allocations. Note that on rev A0 boards the schematic and the reality
60 * differ: red and green are swapped. Below is the fixed (A1) layout (there 180 * differ: red and green are swapped. Below is the fixed (A1) layout (there
@@ -84,11 +204,27 @@ static void sfe4002_fault_led(struct efx_nic *efx, bool state)
84 QUAKE_LED_OFF); 204 QUAKE_LED_OFF);
85} 205}
86 206
207static int sfe4002_check_hw(struct efx_nic *efx)
208{
209 /* A0 board rev. 4002s report a temperature fault the whole time
210 * (bad sensor) so we mask it out. */
211 unsigned alarm_mask =
212 (efx->board_info.major == 0 && efx->board_info.minor == 0) ?
213 ~LM87_ALARM_TEMP_EXT1 : ~0;
214
215 return efx_check_lm87(efx, alarm_mask);
216}
217
87static int sfe4002_init(struct efx_nic *efx) 218static int sfe4002_init(struct efx_nic *efx)
88{ 219{
220 int rc = efx_init_lm87(efx, &sfe4002_hwmon_info, sfe4002_lm87_regs);
221 if (rc)
222 return rc;
223 efx->board_info.monitor = sfe4002_check_hw;
89 efx->board_info.init_leds = sfe4002_init_leds; 224 efx->board_info.init_leds = sfe4002_init_leds;
90 efx->board_info.set_fault_led = sfe4002_fault_led; 225 efx->board_info.set_fault_led = sfe4002_fault_led;
91 efx->board_info.blink = board_blink; 226 efx->board_info.blink = board_blink;
227 efx->board_info.fini = efx_fini_lm87;
92 return 0; 228 return 0;
93} 229}
94 230
diff --git a/drivers/net/sfc/efx.c b/drivers/net/sfc/efx.c
index 5b05789f0b79..ac7bdbf3fd4a 100644
--- a/drivers/net/sfc/efx.c
+++ b/drivers/net/sfc/efx.c
@@ -77,11 +77,6 @@ static int napi_weight = 64;
77 */ 77 */
78unsigned int efx_monitor_interval = 1 * HZ; 78unsigned int efx_monitor_interval = 1 * HZ;
79 79
80/* This controls whether or not the hardware monitor will trigger a
81 * reset when it detects an error condition.
82 */
83static unsigned int monitor_reset = true;
84
85/* This controls whether or not the driver will initialise devices 80/* This controls whether or not the driver will initialise devices
86 * with invalid MAC addresses stored in the EEPROM or flash. If true, 81 * with invalid MAC addresses stored in the EEPROM or flash. If true,
87 * such devices will be initialised with a random locally-generated 82 * such devices will be initialised with a random locally-generated
@@ -1176,17 +1171,6 @@ static void efx_monitor(struct work_struct *data)
1176 rc = falcon_check_xmac(efx); 1171 rc = falcon_check_xmac(efx);
1177 mutex_unlock(&efx->mac_lock); 1172 mutex_unlock(&efx->mac_lock);
1178 1173
1179 if (rc) {
1180 if (monitor_reset) {
1181 EFX_ERR(efx, "hardware monitor detected a fault: "
1182 "triggering reset\n");
1183 efx_schedule_reset(efx, RESET_TYPE_MONITOR);
1184 } else {
1185 EFX_ERR(efx, "hardware monitor detected a fault, "
1186 "skipping reset\n");
1187 }
1188 }
1189
1190 queue_delayed_work(efx->workqueue, &efx->monitor_work, 1174 queue_delayed_work(efx->workqueue, &efx->monitor_work,
1191 efx_monitor_interval); 1175 efx_monitor_interval);
1192} 1176}
@@ -1358,12 +1342,11 @@ static void efx_watchdog(struct net_device *net_dev)
1358{ 1342{
1359 struct efx_nic *efx = netdev_priv(net_dev); 1343 struct efx_nic *efx = netdev_priv(net_dev);
1360 1344
1361 EFX_ERR(efx, "TX stuck with stop_count=%d port_enabled=%d: %s\n", 1345 EFX_ERR(efx, "TX stuck with stop_count=%d port_enabled=%d:"
1362 atomic_read(&efx->netif_stop_count), efx->port_enabled, 1346 " resetting channels\n",
1363 monitor_reset ? "resetting channels" : "skipping reset"); 1347 atomic_read(&efx->netif_stop_count), efx->port_enabled);
1364 1348
1365 if (monitor_reset) 1349 efx_schedule_reset(efx, RESET_TYPE_TX_WATCHDOG);
1366 efx_schedule_reset(efx, RESET_TYPE_MONITOR);
1367} 1350}
1368 1351
1369 1352
@@ -1459,6 +1442,7 @@ static int efx_netdev_event(struct notifier_block *this,
1459 struct efx_nic *efx = netdev_priv(net_dev); 1442 struct efx_nic *efx = netdev_priv(net_dev);
1460 1443
1461 strcpy(efx->name, net_dev->name); 1444 strcpy(efx->name, net_dev->name);
1445 efx_mtd_rename(efx);
1462 } 1446 }
1463 1447
1464 return NOTIFY_DONE; 1448 return NOTIFY_DONE;
@@ -1550,6 +1534,7 @@ void efx_reset_down(struct efx_nic *efx, struct ethtool_cmd *ecmd)
1550 1534
1551 efx_stop_all(efx); 1535 efx_stop_all(efx);
1552 mutex_lock(&efx->mac_lock); 1536 mutex_lock(&efx->mac_lock);
1537 mutex_lock(&efx->spi_lock);
1553 1538
1554 rc = falcon_xmac_get_settings(efx, ecmd); 1539 rc = falcon_xmac_get_settings(efx, ecmd);
1555 if (rc) 1540 if (rc)
@@ -1582,6 +1567,7 @@ int efx_reset_up(struct efx_nic *efx, struct ethtool_cmd *ecmd, bool ok)
1582 EFX_ERR(efx, "could not restore PHY settings\n"); 1567 EFX_ERR(efx, "could not restore PHY settings\n");
1583 } 1568 }
1584 1569
1570 mutex_unlock(&efx->spi_lock);
1585 mutex_unlock(&efx->mac_lock); 1571 mutex_unlock(&efx->mac_lock);
1586 1572
1587 if (ok) { 1573 if (ok) {
@@ -1777,6 +1763,7 @@ static int efx_init_struct(struct efx_nic *efx, struct efx_nic_type *type,
1777 memset(efx, 0, sizeof(*efx)); 1763 memset(efx, 0, sizeof(*efx));
1778 spin_lock_init(&efx->biu_lock); 1764 spin_lock_init(&efx->biu_lock);
1779 spin_lock_init(&efx->phy_lock); 1765 spin_lock_init(&efx->phy_lock);
1766 mutex_init(&efx->spi_lock);
1780 INIT_WORK(&efx->reset_work, efx_reset_work); 1767 INIT_WORK(&efx->reset_work, efx_reset_work);
1781 INIT_DELAYED_WORK(&efx->monitor_work, efx_monitor); 1768 INIT_DELAYED_WORK(&efx->monitor_work, efx_monitor);
1782 efx->pci_dev = pci_dev; 1769 efx->pci_dev = pci_dev;
@@ -1911,6 +1898,8 @@ static void efx_pci_remove(struct pci_dev *pci_dev)
1911 if (!efx) 1898 if (!efx)
1912 return; 1899 return;
1913 1900
1901 efx_mtd_remove(efx);
1902
1914 /* Mark the NIC as fini, then stop the interface */ 1903 /* Mark the NIC as fini, then stop the interface */
1915 rtnl_lock(); 1904 rtnl_lock();
1916 efx->state = STATE_FINI; 1905 efx->state = STATE_FINI;
@@ -2077,6 +2066,7 @@ static int __devinit efx_pci_probe(struct pci_dev *pci_dev,
2077 2066
2078 EFX_LOG(efx, "initialisation successful\n"); 2067 EFX_LOG(efx, "initialisation successful\n");
2079 2068
2069 efx_mtd_probe(efx); /* allowed to fail */
2080 return 0; 2070 return 0;
2081 2071
2082 fail5: 2072 fail5:
diff --git a/drivers/net/sfc/efx.h b/drivers/net/sfc/efx.h
index d02937b70eee..dd0d45b9e71f 100644
--- a/drivers/net/sfc/efx.h
+++ b/drivers/net/sfc/efx.h
@@ -58,6 +58,16 @@ extern int efx_port_dummy_op_int(struct efx_nic *efx);
58extern void efx_port_dummy_op_void(struct efx_nic *efx); 58extern void efx_port_dummy_op_void(struct efx_nic *efx);
59extern void efx_port_dummy_op_blink(struct efx_nic *efx, bool blink); 59extern void efx_port_dummy_op_blink(struct efx_nic *efx, bool blink);
60 60
61/* MTD */
62#ifdef CONFIG_SFC_MTD
63extern int efx_mtd_probe(struct efx_nic *efx);
64extern void efx_mtd_rename(struct efx_nic *efx);
65extern void efx_mtd_remove(struct efx_nic *efx);
66#else
67static inline int efx_mtd_probe(struct efx_nic *efx) { return 0; }
68static inline void efx_mtd_rename(struct efx_nic *efx) {}
69static inline void efx_mtd_remove(struct efx_nic *efx) {}
70#endif
61 71
62extern unsigned int efx_monitor_interval; 72extern unsigned int efx_monitor_interval;
63 73
diff --git a/drivers/net/sfc/enum.h b/drivers/net/sfc/enum.h
index cec15dbb88e4..41e758e8fdb1 100644
--- a/drivers/net/sfc/enum.h
+++ b/drivers/net/sfc/enum.h
@@ -72,7 +72,7 @@ extern const char *efx_loopback_mode_names[];
72 * @RESET_TYPE_ALL: reset everything but PCI core blocks 72 * @RESET_TYPE_ALL: reset everything but PCI core blocks
73 * @RESET_TYPE_WORLD: reset everything, save & restore PCI config 73 * @RESET_TYPE_WORLD: reset everything, save & restore PCI config
74 * @RESET_TYPE_DISABLE: disable NIC 74 * @RESET_TYPE_DISABLE: disable NIC
75 * @RESET_TYPE_MONITOR: reset due to hardware monitor 75 * @RESET_TYPE_TX_WATCHDOG: reset due to TX watchdog
76 * @RESET_TYPE_INT_ERROR: reset due to internal error 76 * @RESET_TYPE_INT_ERROR: reset due to internal error
77 * @RESET_TYPE_RX_RECOVERY: reset to recover from RX datapath errors 77 * @RESET_TYPE_RX_RECOVERY: reset to recover from RX datapath errors
78 * @RESET_TYPE_RX_DESC_FETCH: pcie error during rx descriptor fetch 78 * @RESET_TYPE_RX_DESC_FETCH: pcie error during rx descriptor fetch
@@ -86,7 +86,7 @@ enum reset_type {
86 RESET_TYPE_WORLD = 2, 86 RESET_TYPE_WORLD = 2,
87 RESET_TYPE_DISABLE = 3, 87 RESET_TYPE_DISABLE = 3,
88 RESET_TYPE_MAX_METHOD, 88 RESET_TYPE_MAX_METHOD,
89 RESET_TYPE_MONITOR, 89 RESET_TYPE_TX_WATCHDOG,
90 RESET_TYPE_INT_ERROR, 90 RESET_TYPE_INT_ERROR,
91 RESET_TYPE_RX_RECOVERY, 91 RESET_TYPE_RX_RECOVERY,
92 RESET_TYPE_RX_DESC_FETCH, 92 RESET_TYPE_RX_DESC_FETCH,
diff --git a/drivers/net/sfc/ethtool.c b/drivers/net/sfc/ethtool.c
index fa98af58223e..abd8fcd6e62d 100644
--- a/drivers/net/sfc/ethtool.c
+++ b/drivers/net/sfc/ethtool.c
@@ -172,10 +172,7 @@ static struct efx_ethtool_stat efx_ethtool_stats[] = {
172/* Number of ethtool statistics */ 172/* Number of ethtool statistics */
173#define EFX_ETHTOOL_NUM_STATS ARRAY_SIZE(efx_ethtool_stats) 173#define EFX_ETHTOOL_NUM_STATS ARRAY_SIZE(efx_ethtool_stats)
174 174
175/* EEPROM range with gPXE configuration */
176#define EFX_ETHTOOL_EEPROM_MAGIC 0xEFAB 175#define EFX_ETHTOOL_EEPROM_MAGIC 0xEFAB
177#define EFX_ETHTOOL_EEPROM_MIN 0x100U
178#define EFX_ETHTOOL_EEPROM_MAX 0x400U
179 176
180/************************************************************************** 177/**************************************************************************
181 * 178 *
@@ -545,8 +542,8 @@ static int efx_ethtool_get_eeprom_len(struct net_device *net_dev)
545 542
546 if (!spi) 543 if (!spi)
547 return 0; 544 return 0;
548 return min(spi->size, EFX_ETHTOOL_EEPROM_MAX) - 545 return min(spi->size, EFX_EEPROM_BOOTCONFIG_END) -
549 min(spi->size, EFX_ETHTOOL_EEPROM_MIN); 546 min(spi->size, EFX_EEPROM_BOOTCONFIG_START);
550} 547}
551 548
552static int efx_ethtool_get_eeprom(struct net_device *net_dev, 549static int efx_ethtool_get_eeprom(struct net_device *net_dev,
@@ -557,8 +554,10 @@ static int efx_ethtool_get_eeprom(struct net_device *net_dev,
557 size_t len; 554 size_t len;
558 int rc; 555 int rc;
559 556
560 rc = falcon_spi_read(spi, eeprom->offset + EFX_ETHTOOL_EEPROM_MIN, 557 mutex_lock(&efx->spi_lock);
558 rc = falcon_spi_read(spi, eeprom->offset + EFX_EEPROM_BOOTCONFIG_START,
561 eeprom->len, &len, buf); 559 eeprom->len, &len, buf);
560 mutex_unlock(&efx->spi_lock);
562 eeprom->magic = EFX_ETHTOOL_EEPROM_MAGIC; 561 eeprom->magic = EFX_ETHTOOL_EEPROM_MAGIC;
563 eeprom->len = len; 562 eeprom->len = len;
564 return rc; 563 return rc;
@@ -575,8 +574,10 @@ static int efx_ethtool_set_eeprom(struct net_device *net_dev,
575 if (eeprom->magic != EFX_ETHTOOL_EEPROM_MAGIC) 574 if (eeprom->magic != EFX_ETHTOOL_EEPROM_MAGIC)
576 return -EINVAL; 575 return -EINVAL;
577 576
578 rc = falcon_spi_write(spi, eeprom->offset + EFX_ETHTOOL_EEPROM_MIN, 577 mutex_lock(&efx->spi_lock);
578 rc = falcon_spi_write(spi, eeprom->offset + EFX_EEPROM_BOOTCONFIG_START,
579 eeprom->len, &len, buf); 579 eeprom->len, &len, buf);
580 mutex_unlock(&efx->spi_lock);
580 eeprom->len = len; 581 eeprom->len = len;
581 return rc; 582 return rc;
582} 583}
diff --git a/drivers/net/sfc/falcon.c b/drivers/net/sfc/falcon.c
index 31ed1f49de00..71e0bed60616 100644
--- a/drivers/net/sfc/falcon.c
+++ b/drivers/net/sfc/falcon.c
@@ -1628,9 +1628,9 @@ static int falcon_spi_wait(struct efx_nic *efx)
1628 } 1628 }
1629} 1629}
1630 1630
1631static int falcon_spi_cmd(const struct efx_spi_device *spi, 1631int falcon_spi_cmd(const struct efx_spi_device *spi,
1632 unsigned int command, int address, 1632 unsigned int command, int address,
1633 const void *in, void *out, unsigned int len) 1633 const void *in, void *out, unsigned int len)
1634{ 1634{
1635 struct efx_nic *efx = spi->efx; 1635 struct efx_nic *efx = spi->efx;
1636 bool addressed = (address >= 0); 1636 bool addressed = (address >= 0);
@@ -1641,6 +1641,7 @@ static int falcon_spi_cmd(const struct efx_spi_device *spi,
1641 /* Input validation */ 1641 /* Input validation */
1642 if (len > FALCON_SPI_MAX_LEN) 1642 if (len > FALCON_SPI_MAX_LEN)
1643 return -EINVAL; 1643 return -EINVAL;
1644 BUG_ON(!mutex_is_locked(&efx->spi_lock));
1644 1645
1645 /* Check SPI not currently being accessed */ 1646 /* Check SPI not currently being accessed */
1646 rc = falcon_spi_wait(efx); 1647 rc = falcon_spi_wait(efx);
@@ -1699,8 +1700,7 @@ efx_spi_munge_command(const struct efx_spi_device *spi,
1699 return command | (((address >> 8) & spi->munge_address) << 3); 1700 return command | (((address >> 8) & spi->munge_address) << 3);
1700} 1701}
1701 1702
1702 1703int falcon_spi_fast_wait(const struct efx_spi_device *spi)
1703static int falcon_spi_fast_wait(const struct efx_spi_device *spi)
1704{ 1704{
1705 u8 status; 1705 u8 status;
1706 int i, rc; 1706 int i, rc;
@@ -2253,13 +2253,15 @@ int falcon_read_nvram(struct efx_nic *efx, struct falcon_nvconfig *nvconfig_out)
2253 __le16 *word, *limit; 2253 __le16 *word, *limit;
2254 u32 csum; 2254 u32 csum;
2255 2255
2256 region = kmalloc(NVCONFIG_END, GFP_KERNEL); 2256 region = kmalloc(FALCON_NVCONFIG_END, GFP_KERNEL);
2257 if (!region) 2257 if (!region)
2258 return -ENOMEM; 2258 return -ENOMEM;
2259 nvconfig = region + NVCONFIG_OFFSET; 2259 nvconfig = region + NVCONFIG_OFFSET;
2260 2260
2261 spi = efx->spi_flash ? efx->spi_flash : efx->spi_eeprom; 2261 spi = efx->spi_flash ? efx->spi_flash : efx->spi_eeprom;
2262 rc = falcon_spi_read(spi, 0, NVCONFIG_END, NULL, region); 2262 mutex_lock(&efx->spi_lock);
2263 rc = falcon_spi_read(spi, 0, FALCON_NVCONFIG_END, NULL, region);
2264 mutex_unlock(&efx->spi_lock);
2263 if (rc) { 2265 if (rc) {
2264 EFX_ERR(efx, "Failed to read %s\n", 2266 EFX_ERR(efx, "Failed to read %s\n",
2265 efx->spi_flash ? "flash" : "EEPROM"); 2267 efx->spi_flash ? "flash" : "EEPROM");
@@ -2283,7 +2285,7 @@ int falcon_read_nvram(struct efx_nic *efx, struct falcon_nvconfig *nvconfig_out)
2283 limit = (__le16 *) (nvconfig + 1); 2285 limit = (__le16 *) (nvconfig + 1);
2284 } else { 2286 } else {
2285 word = region; 2287 word = region;
2286 limit = region + NVCONFIG_END; 2288 limit = region + FALCON_NVCONFIG_END;
2287 } 2289 }
2288 for (csum = 0; word < limit; ++word) 2290 for (csum = 0; word < limit; ++word)
2289 csum += le16_to_cpu(*word); 2291 csum += le16_to_cpu(*word);
@@ -2555,6 +2557,11 @@ static int falcon_spi_device_init(struct efx_nic *efx,
2555 SPI_DEV_TYPE_FIELD(device_type, SPI_DEV_TYPE_ADDR_LEN); 2557 SPI_DEV_TYPE_FIELD(device_type, SPI_DEV_TYPE_ADDR_LEN);
2556 spi_device->munge_address = (spi_device->size == 1 << 9 && 2558 spi_device->munge_address = (spi_device->size == 1 << 9 &&
2557 spi_device->addr_len == 1); 2559 spi_device->addr_len == 1);
2560 spi_device->erase_command =
2561 SPI_DEV_TYPE_FIELD(device_type, SPI_DEV_TYPE_ERASE_CMD);
2562 spi_device->erase_size =
2563 1 << SPI_DEV_TYPE_FIELD(device_type,
2564 SPI_DEV_TYPE_ERASE_SIZE);
2558 spi_device->block_size = 2565 spi_device->block_size =
2559 1 << SPI_DEV_TYPE_FIELD(device_type, 2566 1 << SPI_DEV_TYPE_FIELD(device_type,
2560 SPI_DEV_TYPE_BLOCK_SIZE); 2567 SPI_DEV_TYPE_BLOCK_SIZE);
diff --git a/drivers/net/sfc/falcon_hwdefs.h b/drivers/net/sfc/falcon_hwdefs.h
index 5d584b0dbb51..040e70ed4ec7 100644
--- a/drivers/net/sfc/falcon_hwdefs.h
+++ b/drivers/net/sfc/falcon_hwdefs.h
@@ -1150,7 +1150,6 @@ struct falcon_nvconfig_board_v3 {
1150 (((type) >> EFX_LOW_BIT(field)) & EFX_MASK32(EFX_WIDTH(field))) 1150 (((type) >> EFX_LOW_BIT(field)) & EFX_MASK32(EFX_WIDTH(field)))
1151 1151
1152#define NVCONFIG_OFFSET 0x300 1152#define NVCONFIG_OFFSET 0x300
1153#define NVCONFIG_END 0x400
1154 1153
1155#define NVCONFIG_BOARD_MAGIC_NUM 0xFA1C 1154#define NVCONFIG_BOARD_MAGIC_NUM 0xFA1C
1156struct falcon_nvconfig { 1155struct falcon_nvconfig {
diff --git a/drivers/net/sfc/mdio_10g.c b/drivers/net/sfc/mdio_10g.c
index 003e48dcb2f3..19e25210b687 100644
--- a/drivers/net/sfc/mdio_10g.c
+++ b/drivers/net/sfc/mdio_10g.c
@@ -260,6 +260,41 @@ void mdio_clause45_phy_reconfigure(struct efx_nic *efx)
260 MDIO_MMDREG_CTRL1, ctrl2); 260 MDIO_MMDREG_CTRL1, ctrl2);
261} 261}
262 262
263static void mdio_clause45_set_mmd_lpower(struct efx_nic *efx,
264 int lpower, int mmd)
265{
266 int phy = efx->mii.phy_id;
267 int stat = mdio_clause45_read(efx, phy, mmd, MDIO_MMDREG_STAT1);
268 int ctrl1, ctrl2;
269
270 EFX_TRACE(efx, "Setting low power mode for MMD %d to %d\n",
271 mmd, lpower);
272
273 if (stat & (1 << MDIO_MMDREG_STAT1_LPABLE_LBN)) {
274 ctrl1 = ctrl2 = mdio_clause45_read(efx, phy,
275 mmd, MDIO_MMDREG_CTRL1);
276 if (lpower)
277 ctrl2 |= (1 << MDIO_MMDREG_CTRL1_LPOWER_LBN);
278 else
279 ctrl2 &= ~(1 << MDIO_MMDREG_CTRL1_LPOWER_LBN);
280 if (ctrl1 != ctrl2)
281 mdio_clause45_write(efx, phy, mmd,
282 MDIO_MMDREG_CTRL1, ctrl2);
283 }
284}
285
286void mdio_clause45_set_mmds_lpower(struct efx_nic *efx,
287 int low_power, unsigned int mmd_mask)
288{
289 int mmd = 0;
290 while (mmd_mask) {
291 if (mmd_mask & 1)
292 mdio_clause45_set_mmd_lpower(efx, low_power, mmd);
293 mmd_mask = (mmd_mask >> 1);
294 mmd++;
295 }
296}
297
263/** 298/**
264 * mdio_clause45_get_settings - Read (some of) the PHY settings over MDIO. 299 * mdio_clause45_get_settings - Read (some of) the PHY settings over MDIO.
265 * @efx: Efx NIC 300 * @efx: Efx NIC
diff --git a/drivers/net/sfc/mdio_10g.h b/drivers/net/sfc/mdio_10g.h
index 19c42eaf7fb4..db9f358349c6 100644
--- a/drivers/net/sfc/mdio_10g.h
+++ b/drivers/net/sfc/mdio_10g.h
@@ -54,6 +54,9 @@
54/* Loopback bit for WIS, PCS, PHYSX and DTEXS */ 54/* Loopback bit for WIS, PCS, PHYSX and DTEXS */
55#define MDIO_MMDREG_CTRL1_LBACK_LBN (14) 55#define MDIO_MMDREG_CTRL1_LBACK_LBN (14)
56#define MDIO_MMDREG_CTRL1_LBACK_WIDTH (1) 56#define MDIO_MMDREG_CTRL1_LBACK_WIDTH (1)
57/* Low power */
58#define MDIO_MMDREG_CTRL1_LPOWER_LBN (11)
59#define MDIO_MMDREG_CTRL1_LPOWER_WIDTH (1)
57 60
58/* Bits in MMDREG_STAT1 */ 61/* Bits in MMDREG_STAT1 */
59#define MDIO_MMDREG_STAT1_FAULT_LBN (7) 62#define MDIO_MMDREG_STAT1_FAULT_LBN (7)
@@ -240,6 +243,10 @@ extern void mdio_clause45_transmit_disable(struct efx_nic *efx);
240/* Generic part of reconfigure: set/clear loopback bits */ 243/* Generic part of reconfigure: set/clear loopback bits */
241extern void mdio_clause45_phy_reconfigure(struct efx_nic *efx); 244extern void mdio_clause45_phy_reconfigure(struct efx_nic *efx);
242 245
246/* Set the power state of the specified MMDs */
247extern void mdio_clause45_set_mmds_lpower(struct efx_nic *efx,
248 int low_power, unsigned int mmd_mask);
249
243/* Read (some of) the PHY settings over MDIO */ 250/* Read (some of) the PHY settings over MDIO */
244extern void mdio_clause45_get_settings(struct efx_nic *efx, 251extern void mdio_clause45_get_settings(struct efx_nic *efx,
245 struct ethtool_cmd *ecmd); 252 struct ethtool_cmd *ecmd);
diff --git a/drivers/net/sfc/mtd.c b/drivers/net/sfc/mtd.c
new file mode 100644
index 000000000000..a1e6c2875fc0
--- /dev/null
+++ b/drivers/net/sfc/mtd.c
@@ -0,0 +1,268 @@
1/****************************************************************************
2 * Driver for Solarflare Solarstorm network controllers and boards
3 * Copyright 2005-2006 Fen Systems Ltd.
4 * Copyright 2006-2008 Solarflare Communications Inc.
5 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License version 2 as published
8 * by the Free Software Foundation, incorporated herein by reference.
9 */
10
11#include <linux/module.h>
12#include <linux/mtd/mtd.h>
13#include <linux/delay.h>
14
15#define EFX_DRIVER_NAME "sfc_mtd"
16#include "net_driver.h"
17#include "spi.h"
18
19#define EFX_SPI_VERIFY_BUF_LEN 16
20
21struct efx_mtd {
22 const struct efx_spi_device *spi;
23 struct mtd_info mtd;
24 char name[IFNAMSIZ + 20];
25};
26
27/* SPI utilities */
28
29static int efx_spi_slow_wait(struct efx_mtd *efx_mtd, bool uninterruptible)
30{
31 const struct efx_spi_device *spi = efx_mtd->spi;
32 struct efx_nic *efx = spi->efx;
33 u8 status;
34 int rc, i;
35
36 /* Wait up to 4s for flash/EEPROM to finish a slow operation. */
37 for (i = 0; i < 40; i++) {
38 __set_current_state(uninterruptible ?
39 TASK_UNINTERRUPTIBLE : TASK_INTERRUPTIBLE);
40 schedule_timeout(HZ / 10);
41 rc = falcon_spi_cmd(spi, SPI_RDSR, -1, NULL,
42 &status, sizeof(status));
43 if (rc)
44 return rc;
45 if (!(status & SPI_STATUS_NRDY))
46 return 0;
47 if (signal_pending(current))
48 return -EINTR;
49 }
50 EFX_ERR(efx, "timed out waiting for %s\n", efx_mtd->name);
51 return -ETIMEDOUT;
52}
53
54static int efx_spi_unlock(const struct efx_spi_device *spi)
55{
56 const u8 unlock_mask = (SPI_STATUS_BP2 | SPI_STATUS_BP1 |
57 SPI_STATUS_BP0);
58 u8 status;
59 int rc;
60
61 rc = falcon_spi_cmd(spi, SPI_RDSR, -1, NULL, &status, sizeof(status));
62 if (rc)
63 return rc;
64
65 if (!(status & unlock_mask))
66 return 0; /* already unlocked */
67
68 rc = falcon_spi_cmd(spi, SPI_WREN, -1, NULL, NULL, 0);
69 if (rc)
70 return rc;
71 rc = falcon_spi_cmd(spi, SPI_SST_EWSR, -1, NULL, NULL, 0);
72 if (rc)
73 return rc;
74
75 status &= ~unlock_mask;
76 rc = falcon_spi_cmd(spi, SPI_WRSR, -1, &status, NULL, sizeof(status));
77 if (rc)
78 return rc;
79 rc = falcon_spi_fast_wait(spi);
80 if (rc)
81 return rc;
82
83 return 0;
84}
85
86static int efx_spi_erase(struct efx_mtd *efx_mtd, loff_t start, size_t len)
87{
88 const struct efx_spi_device *spi = efx_mtd->spi;
89 unsigned pos, block_len;
90 u8 empty[EFX_SPI_VERIFY_BUF_LEN];
91 u8 buffer[EFX_SPI_VERIFY_BUF_LEN];
92 int rc;
93
94 if (len != spi->erase_size)
95 return -EINVAL;
96
97 if (spi->erase_command == 0)
98 return -EOPNOTSUPP;
99
100 rc = efx_spi_unlock(spi);
101 if (rc)
102 return rc;
103 rc = falcon_spi_cmd(spi, SPI_WREN, -1, NULL, NULL, 0);
104 if (rc)
105 return rc;
106 rc = falcon_spi_cmd(spi, spi->erase_command, start, NULL, NULL, 0);
107 if (rc)
108 return rc;
109 rc = efx_spi_slow_wait(efx_mtd, false);
110
111 /* Verify the entire region has been wiped */
112 memset(empty, 0xff, sizeof(empty));
113 for (pos = 0; pos < len; pos += block_len) {
114 block_len = min(len - pos, sizeof(buffer));
115 rc = falcon_spi_read(spi, start + pos, block_len, NULL, buffer);
116 if (rc)
117 return rc;
118 if (memcmp(empty, buffer, block_len))
119 return -EIO;
120
121 /* Avoid locking up the system */
122 cond_resched();
123 if (signal_pending(current))
124 return -EINTR;
125 }
126
127 return rc;
128}
129
130/* MTD interface */
131
132static int efx_mtd_read(struct mtd_info *mtd, loff_t start, size_t len,
133 size_t *retlen, u8 *buffer)
134{
135 struct efx_mtd *efx_mtd = mtd->priv;
136 const struct efx_spi_device *spi = efx_mtd->spi;
137 struct efx_nic *efx = spi->efx;
138 int rc;
139
140 rc = mutex_lock_interruptible(&efx->spi_lock);
141 if (rc)
142 return rc;
143 rc = falcon_spi_read(spi, FALCON_FLASH_BOOTCODE_START + start,
144 len, retlen, buffer);
145 mutex_unlock(&efx->spi_lock);
146 return rc;
147}
148
149static int efx_mtd_erase(struct mtd_info *mtd, struct erase_info *erase)
150{
151 struct efx_mtd *efx_mtd = mtd->priv;
152 struct efx_nic *efx = efx_mtd->spi->efx;
153 int rc;
154
155 rc = mutex_lock_interruptible(&efx->spi_lock);
156 if (rc)
157 return rc;
158 rc = efx_spi_erase(efx_mtd, FALCON_FLASH_BOOTCODE_START + erase->addr,
159 erase->len);
160 mutex_unlock(&efx->spi_lock);
161
162 if (rc == 0) {
163 erase->state = MTD_ERASE_DONE;
164 } else {
165 erase->state = MTD_ERASE_FAILED;
166 erase->fail_addr = 0xffffffff;
167 }
168 mtd_erase_callback(erase);
169 return rc;
170}
171
172static int efx_mtd_write(struct mtd_info *mtd, loff_t start,
173 size_t len, size_t *retlen, const u8 *buffer)
174{
175 struct efx_mtd *efx_mtd = mtd->priv;
176 const struct efx_spi_device *spi = efx_mtd->spi;
177 struct efx_nic *efx = spi->efx;
178 int rc;
179
180 rc = mutex_lock_interruptible(&efx->spi_lock);
181 if (rc)
182 return rc;
183 rc = falcon_spi_write(spi, FALCON_FLASH_BOOTCODE_START + start,
184 len, retlen, buffer);
185 mutex_unlock(&efx->spi_lock);
186 return rc;
187}
188
189static void efx_mtd_sync(struct mtd_info *mtd)
190{
191 struct efx_mtd *efx_mtd = mtd->priv;
192 struct efx_nic *efx = efx_mtd->spi->efx;
193 int rc;
194
195 mutex_lock(&efx->spi_lock);
196 rc = efx_spi_slow_wait(efx_mtd, true);
197 mutex_unlock(&efx->spi_lock);
198
199 if (rc)
200 EFX_ERR(efx, "%s sync failed (%d)\n", efx_mtd->name, rc);
201 return;
202}
203
204void efx_mtd_remove(struct efx_nic *efx)
205{
206 if (efx->spi_flash && efx->spi_flash->mtd) {
207 struct efx_mtd *efx_mtd = efx->spi_flash->mtd;
208 int rc;
209
210 for (;;) {
211 rc = del_mtd_device(&efx_mtd->mtd);
212 if (rc != -EBUSY)
213 break;
214 ssleep(1);
215 }
216 WARN_ON(rc);
217 kfree(efx_mtd);
218 }
219}
220
221void efx_mtd_rename(struct efx_nic *efx)
222{
223 if (efx->spi_flash && efx->spi_flash->mtd) {
224 struct efx_mtd *efx_mtd = efx->spi_flash->mtd;
225 snprintf(efx_mtd->name, sizeof(efx_mtd->name),
226 "%s sfc_flash_bootrom", efx->name);
227 }
228}
229
230int efx_mtd_probe(struct efx_nic *efx)
231{
232 struct efx_spi_device *spi = efx->spi_flash;
233 struct efx_mtd *efx_mtd;
234
235 if (!spi || spi->size <= FALCON_FLASH_BOOTCODE_START)
236 return -ENODEV;
237
238 efx_mtd = kzalloc(sizeof(*efx_mtd), GFP_KERNEL);
239 if (!efx_mtd)
240 return -ENOMEM;
241
242 efx_mtd->spi = spi;
243 spi->mtd = efx_mtd;
244
245 efx_mtd->mtd.type = MTD_NORFLASH;
246 efx_mtd->mtd.flags = MTD_CAP_NORFLASH;
247 efx_mtd->mtd.size = spi->size - FALCON_FLASH_BOOTCODE_START;
248 efx_mtd->mtd.erasesize = spi->erase_size;
249 efx_mtd->mtd.writesize = 1;
250 efx_mtd_rename(efx);
251
252 efx_mtd->mtd.owner = THIS_MODULE;
253 efx_mtd->mtd.priv = efx_mtd;
254 efx_mtd->mtd.name = efx_mtd->name;
255 efx_mtd->mtd.erase = efx_mtd_erase;
256 efx_mtd->mtd.read = efx_mtd_read;
257 efx_mtd->mtd.write = efx_mtd_write;
258 efx_mtd->mtd.sync = efx_mtd_sync;
259
260 if (add_mtd_device(&efx_mtd->mtd)) {
261 kfree(efx_mtd);
262 spi->mtd = NULL;
263 /* add_mtd_device() returns 1 if the MTD table is full */
264 return -ENOMEM;
265 }
266
267 return 0;
268}
diff --git a/drivers/net/sfc/net_driver.h b/drivers/net/sfc/net_driver.h
index cdb11fad6050..e596c9a6a4c4 100644
--- a/drivers/net/sfc/net_driver.h
+++ b/drivers/net/sfc/net_driver.h
@@ -414,6 +414,7 @@ struct efx_blinker {
414 * @init_leds: Sets up board LEDs 414 * @init_leds: Sets up board LEDs
415 * @set_fault_led: Turns the fault LED on or off 415 * @set_fault_led: Turns the fault LED on or off
416 * @blink: Starts/stops blinking 416 * @blink: Starts/stops blinking
417 * @monitor: Board-specific health check function
417 * @fini: Cleanup function 418 * @fini: Cleanup function
418 * @blinker: used to blink LEDs in software 419 * @blinker: used to blink LEDs in software
419 * @hwmon_client: I2C client for hardware monitor 420 * @hwmon_client: I2C client for hardware monitor
@@ -428,6 +429,7 @@ struct efx_board {
428 * have a separate init callback that happens later than 429 * have a separate init callback that happens later than
429 * board init. */ 430 * board init. */
430 int (*init_leds)(struct efx_nic *efx); 431 int (*init_leds)(struct efx_nic *efx);
432 int (*monitor) (struct efx_nic *nic);
431 void (*set_fault_led) (struct efx_nic *efx, bool state); 433 void (*set_fault_led) (struct efx_nic *efx, bool state);
432 void (*blink) (struct efx_nic *efx, bool start); 434 void (*blink) (struct efx_nic *efx, bool start);
433 void (*fini) (struct efx_nic *nic); 435 void (*fini) (struct efx_nic *nic);
@@ -525,11 +527,15 @@ struct efx_phy_operations {
525 * @enum efx_phy_mode - PHY operating mode flags 527 * @enum efx_phy_mode - PHY operating mode flags
526 * @PHY_MODE_NORMAL: on and should pass traffic 528 * @PHY_MODE_NORMAL: on and should pass traffic
527 * @PHY_MODE_TX_DISABLED: on with TX disabled 529 * @PHY_MODE_TX_DISABLED: on with TX disabled
530 * @PHY_MODE_LOW_POWER: set to low power through MDIO
531 * @PHY_MODE_OFF: switched off through external control
528 * @PHY_MODE_SPECIAL: on but will not pass traffic 532 * @PHY_MODE_SPECIAL: on but will not pass traffic
529 */ 533 */
530enum efx_phy_mode { 534enum efx_phy_mode {
531 PHY_MODE_NORMAL = 0, 535 PHY_MODE_NORMAL = 0,
532 PHY_MODE_TX_DISABLED = 1, 536 PHY_MODE_TX_DISABLED = 1,
537 PHY_MODE_LOW_POWER = 2,
538 PHY_MODE_OFF = 4,
533 PHY_MODE_SPECIAL = 8, 539 PHY_MODE_SPECIAL = 8,
534}; 540};
535 541
@@ -655,6 +661,7 @@ union efx_multicast_hash {
655 * This field will be %NULL if no flash device is present. 661 * This field will be %NULL if no flash device is present.
656 * @spi_eeprom: SPI EEPROM device 662 * @spi_eeprom: SPI EEPROM device
657 * This field will be %NULL if no EEPROM device is present. 663 * This field will be %NULL if no EEPROM device is present.
664 * @spi_lock: SPI bus lock
658 * @n_rx_nodesc_drop_cnt: RX no descriptor drop count 665 * @n_rx_nodesc_drop_cnt: RX no descriptor drop count
659 * @nic_data: Hardware dependant state 666 * @nic_data: Hardware dependant state
660 * @mac_lock: MAC access lock. Protects @port_enabled, @phy_mode, 667 * @mac_lock: MAC access lock. Protects @port_enabled, @phy_mode,
@@ -731,6 +738,7 @@ struct efx_nic {
731 738
732 struct efx_spi_device *spi_flash; 739 struct efx_spi_device *spi_flash;
733 struct efx_spi_device *spi_eeprom; 740 struct efx_spi_device *spi_eeprom;
741 struct mutex spi_lock;
734 742
735 unsigned n_rx_nodesc_drop_cnt; 743 unsigned n_rx_nodesc_drop_cnt;
736 744
diff --git a/drivers/net/sfc/sfe4001.c b/drivers/net/sfc/sfe4001.c
index fe4e3fd22330..aa576c559ec8 100644
--- a/drivers/net/sfc/sfe4001.c
+++ b/drivers/net/sfc/sfe4001.c
@@ -21,6 +21,7 @@
21#include "falcon_hwdefs.h" 21#include "falcon_hwdefs.h"
22#include "falcon_io.h" 22#include "falcon_io.h"
23#include "mac.h" 23#include "mac.h"
24#include "workarounds.h"
24 25
25/************************************************************************** 26/**************************************************************************
26 * 27 *
@@ -65,48 +66,9 @@
65#define P1_SPARE_LBN 4 66#define P1_SPARE_LBN 4
66#define P1_SPARE_WIDTH 4 67#define P1_SPARE_WIDTH 4
67 68
68 69/* Temperature Sensor */
69/************************************************************************** 70#define MAX664X_REG_RSL 0x02
70 * 71#define MAX664X_REG_WLHO 0x0B
71 * Temperature Sensor
72 *
73 **************************************************************************/
74#define MAX6647 0x4e
75
76#define RLTS 0x00
77#define RLTE 0x01
78#define RSL 0x02
79#define RCL 0x03
80#define RCRA 0x04
81#define RLHN 0x05
82#define RLLI 0x06
83#define RRHI 0x07
84#define RRLS 0x08
85#define WCRW 0x0a
86#define WLHO 0x0b
87#define WRHA 0x0c
88#define WRLN 0x0e
89#define OSHT 0x0f
90#define REET 0x10
91#define RIET 0x11
92#define RWOE 0x19
93#define RWOI 0x20
94#define HYS 0x21
95#define QUEUE 0x22
96#define MFID 0xfe
97#define REVID 0xff
98
99/* Status bits */
100#define MAX6647_BUSY (1 << 7) /* ADC is converting */
101#define MAX6647_LHIGH (1 << 6) /* Local high temp. alarm */
102#define MAX6647_LLOW (1 << 5) /* Local low temp. alarm */
103#define MAX6647_RHIGH (1 << 4) /* Remote high temp. alarm */
104#define MAX6647_RLOW (1 << 3) /* Remote low temp. alarm */
105#define MAX6647_FAULT (1 << 2) /* DXN/DXP short/open circuit */
106#define MAX6647_EOT (1 << 1) /* Remote junction overtemp. */
107#define MAX6647_IOT (1 << 0) /* Local junction overtemp. */
108
109static const u8 xgphy_max_temperature = 90;
110 72
111static void sfe4001_poweroff(struct efx_nic *efx) 73static void sfe4001_poweroff(struct efx_nic *efx)
112{ 74{
@@ -119,7 +81,7 @@ static void sfe4001_poweroff(struct efx_nic *efx)
119 i2c_smbus_write_byte_data(ioexp_client, P0_CONFIG, 0xff); 81 i2c_smbus_write_byte_data(ioexp_client, P0_CONFIG, 0xff);
120 82
121 /* Clear any over-temperature alert */ 83 /* Clear any over-temperature alert */
122 i2c_smbus_read_byte_data(hwmon_client, RSL); 84 i2c_smbus_read_byte_data(hwmon_client, MAX664X_REG_RSL);
123} 85}
124 86
125static int sfe4001_poweron(struct efx_nic *efx) 87static int sfe4001_poweron(struct efx_nic *efx)
@@ -131,7 +93,7 @@ static int sfe4001_poweron(struct efx_nic *efx)
131 u8 out; 93 u8 out;
132 94
133 /* Clear any previous over-temperature alert */ 95 /* Clear any previous over-temperature alert */
134 rc = i2c_smbus_read_byte_data(hwmon_client, RSL); 96 rc = i2c_smbus_read_byte_data(hwmon_client, MAX664X_REG_RSL);
135 if (rc < 0) 97 if (rc < 0)
136 return rc; 98 return rc;
137 99
@@ -209,6 +171,34 @@ fail_on:
209 return rc; 171 return rc;
210} 172}
211 173
174static int sfe4001_check_hw(struct efx_nic *efx)
175{
176 s32 status;
177
178 /* If XAUI link is up then do not monitor */
179 if (EFX_WORKAROUND_7884(efx) && falcon_xaui_link_ok(efx))
180 return 0;
181
182 /* Check the powered status of the PHY. Lack of power implies that
183 * the MAX6647 has shut down power to it, probably due to a temp.
184 * alarm. Reading the power status rather than the MAX6647 status
185 * directly because the later is read-to-clear and would thus
186 * start to power up the PHY again when polled, causing us to blip
187 * the power undesirably.
188 * We know we can read from the IO expander because we did
189 * it during power-on. Assume failure now is bad news. */
190 status = i2c_smbus_read_byte_data(efx->board_info.ioexp_client, P1_IN);
191 if (status >= 0 &&
192 (status & ((1 << P1_AFE_PWD_LBN) | (1 << P1_DSP_PWD25_LBN))) != 0)
193 return 0;
194
195 /* Use board power control, not PHY power control */
196 sfe4001_poweroff(efx);
197 efx->phy_mode = PHY_MODE_OFF;
198
199 return (status < 0) ? -EIO : -ERANGE;
200}
201
212/* On SFE4001 rev A2 and later, we can control the FLASH_CFG_1 pin 202/* On SFE4001 rev A2 and later, we can control the FLASH_CFG_1 pin
213 * using the 3V3X output of the IO-expander. Allow the user to set 203 * using the 3V3X output of the IO-expander. Allow the user to set
214 * this when the device is stopped, and keep it stopped then. 204 * this when the device is stopped, and keep it stopped then.
@@ -261,35 +251,34 @@ static void sfe4001_fini(struct efx_nic *efx)
261 i2c_unregister_device(efx->board_info.hwmon_client); 251 i2c_unregister_device(efx->board_info.hwmon_client);
262} 252}
263 253
254static struct i2c_board_info sfe4001_hwmon_info = {
255 I2C_BOARD_INFO("max6647", 0x4e),
256 .irq = -1,
257};
258
264/* This board uses an I2C expander to provider power to the PHY, which needs to 259/* This board uses an I2C expander to provider power to the PHY, which needs to
265 * be turned on before the PHY can be used. 260 * be turned on before the PHY can be used.
266 * Context: Process context, rtnl lock held 261 * Context: Process context, rtnl lock held
267 */ 262 */
268int sfe4001_init(struct efx_nic *efx) 263int sfe4001_init(struct efx_nic *efx)
269{ 264{
270 struct i2c_client *hwmon_client;
271 int rc; 265 int rc;
272 266
273 hwmon_client = i2c_new_dummy(&efx->i2c_adap, MAX6647); 267#if defined(CONFIG_SENSORS_LM90) || defined(CONFIG_SENSORS_LM90_MODULE)
274 if (!hwmon_client) 268 efx->board_info.hwmon_client =
269 i2c_new_device(&efx->i2c_adap, &sfe4001_hwmon_info);
270#else
271 efx->board_info.hwmon_client =
272 i2c_new_dummy(&efx->i2c_adap, sfe4001_hwmon_info.addr);
273#endif
274 if (!efx->board_info.hwmon_client)
275 return -EIO; 275 return -EIO;
276 efx->board_info.hwmon_client = hwmon_client;
277 276
278 /* Set DSP over-temperature alert threshold */ 277 /* Raise board/PHY high limit from 85 to 90 degrees Celsius */
279 EFX_INFO(efx, "DSP cut-out at %dC\n", xgphy_max_temperature); 278 rc = i2c_smbus_write_byte_data(efx->board_info.hwmon_client,
280 rc = i2c_smbus_write_byte_data(hwmon_client, WLHO, 279 MAX664X_REG_WLHO, 90);
281 xgphy_max_temperature);
282 if (rc) 280 if (rc)
283 goto fail_ioexp; 281 goto fail_hwmon;
284
285 /* Read it back and verify */
286 rc = i2c_smbus_read_byte_data(hwmon_client, RLHN);
287 if (rc < 0)
288 goto fail_ioexp;
289 if (rc != xgphy_max_temperature) {
290 rc = -EFAULT;
291 goto fail_ioexp;
292 }
293 282
294 efx->board_info.ioexp_client = i2c_new_dummy(&efx->i2c_adap, PCA9539); 283 efx->board_info.ioexp_client = i2c_new_dummy(&efx->i2c_adap, PCA9539);
295 if (!efx->board_info.ioexp_client) { 284 if (!efx->board_info.ioexp_client) {
@@ -301,6 +290,7 @@ int sfe4001_init(struct efx_nic *efx)
301 * blink code. */ 290 * blink code. */
302 efx->board_info.blink = tenxpress_phy_blink; 291 efx->board_info.blink = tenxpress_phy_blink;
303 292
293 efx->board_info.monitor = sfe4001_check_hw;
304 efx->board_info.fini = sfe4001_fini; 294 efx->board_info.fini = sfe4001_fini;
305 295
306 rc = sfe4001_poweron(efx); 296 rc = sfe4001_poweron(efx);
@@ -319,6 +309,6 @@ fail_on:
319fail_ioexp: 309fail_ioexp:
320 i2c_unregister_device(efx->board_info.ioexp_client); 310 i2c_unregister_device(efx->board_info.ioexp_client);
321fail_hwmon: 311fail_hwmon:
322 i2c_unregister_device(hwmon_client); 312 i2c_unregister_device(efx->board_info.hwmon_client);
323 return rc; 313 return rc;
324} 314}
diff --git a/drivers/net/sfc/spi.h b/drivers/net/sfc/spi.h
index feef61942377..c4aca132348a 100644
--- a/drivers/net/sfc/spi.h
+++ b/drivers/net/sfc/spi.h
@@ -25,6 +25,7 @@
25#define SPI_WRDI 0x04 /* Reset write enable latch */ 25#define SPI_WRDI 0x04 /* Reset write enable latch */
26#define SPI_RDSR 0x05 /* Read status register */ 26#define SPI_RDSR 0x05 /* Read status register */
27#define SPI_WREN 0x06 /* Set write enable latch */ 27#define SPI_WREN 0x06 /* Set write enable latch */
28#define SPI_SST_EWSR 0x50 /* SST: Enable write to status register */
28 29
29#define SPI_STATUS_WPEN 0x80 /* Write-protect pin enabled */ 30#define SPI_STATUS_WPEN 0x80 /* Write-protect pin enabled */
30#define SPI_STATUS_BP2 0x10 /* Block protection bit 2 */ 31#define SPI_STATUS_BP2 0x10 /* Block protection bit 2 */
@@ -36,6 +37,7 @@
36/** 37/**
37 * struct efx_spi_device - an Efx SPI (Serial Peripheral Interface) device 38 * struct efx_spi_device - an Efx SPI (Serial Peripheral Interface) device
38 * @efx: The Efx controller that owns this device 39 * @efx: The Efx controller that owns this device
40 * @mtd: MTD state
39 * @device_id: Controller's id for the device 41 * @device_id: Controller's id for the device
40 * @size: Size (in bytes) 42 * @size: Size (in bytes)
41 * @addr_len: Number of address bytes in read/write commands 43 * @addr_len: Number of address bytes in read/write commands
@@ -44,23 +46,51 @@
44 * use bit 3 of the command byte as address bit A8, rather 46 * use bit 3 of the command byte as address bit A8, rather
45 * than having a two-byte address. If this flag is set, then 47 * than having a two-byte address. If this flag is set, then
46 * commands should be munged in this way. 48 * commands should be munged in this way.
49 * @erase_command: Erase command (or 0 if sector erase not needed).
50 * @erase_size: Erase sector size (in bytes)
51 * Erase commands affect sectors with this size and alignment.
52 * This must be a power of two.
47 * @block_size: Write block size (in bytes). 53 * @block_size: Write block size (in bytes).
48 * Write commands are limited to blocks with this size and alignment. 54 * Write commands are limited to blocks with this size and alignment.
49 * @read: Read function for the device
50 * @write: Write function for the device
51 */ 55 */
52struct efx_spi_device { 56struct efx_spi_device {
53 struct efx_nic *efx; 57 struct efx_nic *efx;
58#ifdef CONFIG_SFC_MTD
59 void *mtd;
60#endif
54 int device_id; 61 int device_id;
55 unsigned int size; 62 unsigned int size;
56 unsigned int addr_len; 63 unsigned int addr_len;
57 unsigned int munge_address:1; 64 unsigned int munge_address:1;
65 u8 erase_command;
66 unsigned int erase_size;
58 unsigned int block_size; 67 unsigned int block_size;
59}; 68};
60 69
70int falcon_spi_cmd(const struct efx_spi_device *spi, unsigned int command,
71 int address, const void* in, void *out, unsigned int len);
72int falcon_spi_fast_wait(const struct efx_spi_device *spi);
61int falcon_spi_read(const struct efx_spi_device *spi, loff_t start, 73int falcon_spi_read(const struct efx_spi_device *spi, loff_t start,
62 size_t len, size_t *retlen, u8 *buffer); 74 size_t len, size_t *retlen, u8 *buffer);
63int falcon_spi_write(const struct efx_spi_device *spi, loff_t start, 75int falcon_spi_write(const struct efx_spi_device *spi, loff_t start,
64 size_t len, size_t *retlen, const u8 *buffer); 76 size_t len, size_t *retlen, const u8 *buffer);
65 77
78/*
79 * SFC4000 flash is partitioned into:
80 * 0-0x400 chip and board config (see falcon_hwdefs.h)
81 * 0x400-0x8000 unused (or may contain VPD if EEPROM not present)
82 * 0x8000-end boot code (mapped to PCI expansion ROM)
83 * SFC4000 small EEPROM (size < 0x400) is used for VPD only.
84 * SFC4000 large EEPROM (size >= 0x400) is partitioned into:
85 * 0-0x400 chip and board config
86 * configurable VPD
87 * 0x800-0x1800 boot config
88 * Aside from the chip and board config, all of these are optional and may
89 * be absent or truncated depending on the devices used.
90 */
91#define FALCON_NVCONFIG_END 0x400U
92#define FALCON_FLASH_BOOTCODE_START 0x8000U
93#define EFX_EEPROM_BOOTCONFIG_START 0x800U
94#define EFX_EEPROM_BOOTCONFIG_END 0x1800U
95
66#endif /* EFX_SPI_H */ 96#endif /* EFX_SPI_H */
diff --git a/drivers/net/sfc/tenxpress.c b/drivers/net/sfc/tenxpress.c
index d507c93d666e..8d41c29b9d7b 100644
--- a/drivers/net/sfc/tenxpress.c
+++ b/drivers/net/sfc/tenxpress.c
@@ -376,6 +376,7 @@ static int tenxpress_phy_check_hw(struct efx_nic *efx)
376{ 376{
377 struct tenxpress_phy_data *phy_data = efx->phy_data; 377 struct tenxpress_phy_data *phy_data = efx->phy_data;
378 bool link_ok; 378 bool link_ok;
379 int rc = 0;
379 380
380 link_ok = tenxpress_link_ok(efx, true); 381 link_ok = tenxpress_link_ok(efx, true);
381 382
@@ -391,7 +392,22 @@ static int tenxpress_phy_check_hw(struct efx_nic *efx)
391 atomic_set(&phy_data->bad_crc_count, 0); 392 atomic_set(&phy_data->bad_crc_count, 0);
392 } 393 }
393 394
394 return 0; 395 rc = efx->board_info.monitor(efx);
396 if (rc) {
397 EFX_ERR(efx, "Board sensor %s; shutting down PHY\n",
398 (rc == -ERANGE) ? "reported fault" : "failed");
399 if (efx->phy_mode & PHY_MODE_OFF) {
400 /* Assume that board has shut PHY off */
401 phy_data->phy_mode = PHY_MODE_OFF;
402 } else {
403 efx->phy_mode |= PHY_MODE_LOW_POWER;
404 mdio_clause45_set_mmds_lpower(efx, true,
405 efx->phy_op->mmds);
406 phy_data->phy_mode |= PHY_MODE_LOW_POWER;
407 }
408 }
409
410 return rc;
395} 411}
396 412
397static void tenxpress_phy_fini(struct efx_nic *efx) 413static void tenxpress_phy_fini(struct efx_nic *efx)
diff --git a/drivers/net/sfc/workarounds.h b/drivers/net/sfc/workarounds.h
index fa7b49d69288..ec50b90f4285 100644
--- a/drivers/net/sfc/workarounds.h
+++ b/drivers/net/sfc/workarounds.h
@@ -22,6 +22,8 @@
22#define EFX_WORKAROUND_5147 EFX_WORKAROUND_ALWAYS 22#define EFX_WORKAROUND_5147 EFX_WORKAROUND_ALWAYS
23/* RX PCIe double split performance issue */ 23/* RX PCIe double split performance issue */
24#define EFX_WORKAROUND_7575 EFX_WORKAROUND_ALWAYS 24#define EFX_WORKAROUND_7575 EFX_WORKAROUND_ALWAYS
25/* Bit-bashed I2C reads cause performance drop */
26#define EFX_WORKAROUND_7884 EFX_WORKAROUND_ALWAYS
25/* TX pkt parser problem with <= 16 byte TXes */ 27/* TX pkt parser problem with <= 16 byte TXes */
26#define EFX_WORKAROUND_9141 EFX_WORKAROUND_ALWAYS 28#define EFX_WORKAROUND_9141 EFX_WORKAROUND_ALWAYS
27/* Low rate CRC errors require XAUI reset */ 29/* Low rate CRC errors require XAUI reset */
diff --git a/drivers/net/sfc/xfp_phy.c b/drivers/net/sfc/xfp_phy.c
index 276151df3a70..91f024662101 100644
--- a/drivers/net/sfc/xfp_phy.c
+++ b/drivers/net/sfc/xfp_phy.c
@@ -128,6 +128,15 @@ static int xfp_phy_check_hw(struct efx_nic *efx)
128 if (link_up != efx->link_up) 128 if (link_up != efx->link_up)
129 falcon_xmac_sim_phy_event(efx); 129 falcon_xmac_sim_phy_event(efx);
130 130
131 rc = efx->board_info.monitor(efx);
132 if (rc) {
133 struct xfp_phy_data *phy_data = efx->phy_data;
134 EFX_ERR(efx, "XFP sensor alert; putting PHY into low power\n");
135 efx->phy_mode |= PHY_MODE_LOW_POWER;
136 mdio_clause45_set_mmds_lpower(efx, 1, XFP_REQUIRED_DEVS);
137 phy_data->phy_mode |= PHY_MODE_LOW_POWER;
138 }
139
131 return rc; 140 return rc;
132} 141}
133 142
diff --git a/drivers/net/smsc911x.c b/drivers/net/smsc911x.c
new file mode 100644
index 000000000000..fe517880fc97
--- /dev/null
+++ b/drivers/net/smsc911x.c
@@ -0,0 +1,2091 @@
1/***************************************************************************
2 *
3 * Copyright (C) 2004-2008 SMSC
4 * Copyright (C) 2005-2008 ARM
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19 *
20 ***************************************************************************
21 * Rewritten, heavily based on smsc911x simple driver by SMSC.
22 * Partly uses io macros from smc91x.c by Nicolas Pitre
23 *
24 * Supported devices:
25 * LAN9115, LAN9116, LAN9117, LAN9118
26 * LAN9215, LAN9216, LAN9217, LAN9218
27 * LAN9210, LAN9211
28 * LAN9220, LAN9221
29 *
30 */
31
32#include <linux/crc32.h>
33#include <linux/delay.h>
34#include <linux/errno.h>
35#include <linux/etherdevice.h>
36#include <linux/ethtool.h>
37#include <linux/init.h>
38#include <linux/ioport.h>
39#include <linux/kernel.h>
40#include <linux/module.h>
41#include <linux/netdevice.h>
42#include <linux/platform_device.h>
43#include <linux/sched.h>
44#include <linux/slab.h>
45#include <linux/timer.h>
46#include <linux/version.h>
47#include <linux/bug.h>
48#include <linux/bitops.h>
49#include <linux/irq.h>
50#include <linux/io.h>
51#include <linux/phy.h>
52#include <linux/smsc911x.h>
53#include "smsc911x.h"
54
55#define SMSC_CHIPNAME "smsc911x"
56#define SMSC_MDIONAME "smsc911x-mdio"
57#define SMSC_DRV_VERSION "2008-10-21"
58
59MODULE_LICENSE("GPL");
60MODULE_VERSION(SMSC_DRV_VERSION);
61
62#if USE_DEBUG > 0
63static int debug = 16;
64#else
65static int debug = 3;
66#endif
67
68module_param(debug, int, 0);
69MODULE_PARM_DESC(debug, "Debug level (0=none,...,16=all)");
70
71struct smsc911x_data {
72 void __iomem *ioaddr;
73
74 unsigned int idrev;
75
76 /* used to decide which workarounds apply */
77 unsigned int generation;
78
79 /* device configuration (copied from platform_data during probe) */
80 unsigned int irq_polarity;
81 unsigned int irq_type;
82 phy_interface_t phy_interface;
83
84 /* This needs to be acquired before calling any of below:
85 * smsc911x_mac_read(), smsc911x_mac_write()
86 */
87 spinlock_t mac_lock;
88
89#if (!SMSC_CAN_USE_32BIT)
90 /* spinlock to ensure 16-bit accesses are serialised */
91 spinlock_t dev_lock;
92#endif
93
94 struct phy_device *phy_dev;
95 struct mii_bus *mii_bus;
96 int phy_irq[PHY_MAX_ADDR];
97 unsigned int using_extphy;
98 int last_duplex;
99 int last_carrier;
100
101 u32 msg_enable;
102 unsigned int gpio_setting;
103 unsigned int gpio_orig_setting;
104 struct net_device *dev;
105 struct napi_struct napi;
106
107 unsigned int software_irq_signal;
108
109#ifdef USE_PHY_WORK_AROUND
110#define MIN_PACKET_SIZE (64)
111 char loopback_tx_pkt[MIN_PACKET_SIZE];
112 char loopback_rx_pkt[MIN_PACKET_SIZE];
113 unsigned int resetcount;
114#endif
115
116 /* Members for Multicast filter workaround */
117 unsigned int multicast_update_pending;
118 unsigned int set_bits_mask;
119 unsigned int clear_bits_mask;
120 unsigned int hashhi;
121 unsigned int hashlo;
122};
123
124#if SMSC_CAN_USE_32BIT
125
126static inline u32 smsc911x_reg_read(struct smsc911x_data *pdata, u32 reg)
127{
128 return readl(pdata->ioaddr + reg);
129}
130
131static inline void smsc911x_reg_write(struct smsc911x_data *pdata, u32 reg,
132 u32 val)
133{
134 writel(val, pdata->ioaddr + reg);
135}
136
137/* Writes a packet to the TX_DATA_FIFO */
138static inline void
139smsc911x_tx_writefifo(struct smsc911x_data *pdata, unsigned int *buf,
140 unsigned int wordcount)
141{
142 writesl(pdata->ioaddr + TX_DATA_FIFO, buf, wordcount);
143}
144
145/* Reads a packet out of the RX_DATA_FIFO */
146static inline void
147smsc911x_rx_readfifo(struct smsc911x_data *pdata, unsigned int *buf,
148 unsigned int wordcount)
149{
150 readsl(pdata->ioaddr + RX_DATA_FIFO, buf, wordcount);
151}
152
153#else /* SMSC_CAN_USE_32BIT */
154
155/* These 16-bit access functions are significantly slower, due to the locking
156 * necessary. If your bus hardware can be configured to do this for you
157 * (in response to a single 32-bit operation from software), you should use
158 * the 32-bit access functions instead. */
159
160static inline u32 smsc911x_reg_read(struct smsc911x_data *pdata, u32 reg)
161{
162 unsigned long flags;
163 u32 data;
164
165 /* these two 16-bit reads must be performed consecutively, so must
166 * not be interrupted by our own ISR (which would start another
167 * read operation) */
168 spin_lock_irqsave(&pdata->dev_lock, flags);
169 data = ((readw(pdata->ioaddr + reg) & 0xFFFF) |
170 ((readw(pdata->ioaddr + reg + 2) & 0xFFFF) << 16));
171 spin_unlock_irqrestore(&pdata->dev_lock, flags);
172
173 return data;
174}
175
176static inline void smsc911x_reg_write(struct smsc911x_data *pdata, u32 reg,
177 u32 val)
178{
179 unsigned long flags;
180
181 /* these two 16-bit writes must be performed consecutively, so must
182 * not be interrupted by our own ISR (which would start another
183 * read operation) */
184 spin_lock_irqsave(&pdata->dev_lock, flags);
185 writew(val & 0xFFFF, pdata->ioaddr + reg);
186 writew((val >> 16) & 0xFFFF, pdata->ioaddr + reg + 2);
187 spin_unlock_irqrestore(&pdata->dev_lock, flags);
188}
189
190/* Writes a packet to the TX_DATA_FIFO */
191static inline void
192smsc911x_tx_writefifo(struct smsc911x_data *pdata, unsigned int *buf,
193 unsigned int wordcount)
194{
195 while (wordcount--)
196 smsc911x_reg_write(pdata, TX_DATA_FIFO, *buf++);
197}
198
199/* Reads a packet out of the RX_DATA_FIFO */
200static inline void
201smsc911x_rx_readfifo(struct smsc911x_data *pdata, unsigned int *buf,
202 unsigned int wordcount)
203{
204 while (wordcount--)
205 *buf++ = smsc911x_reg_read(pdata, RX_DATA_FIFO);
206}
207
208#endif /* SMSC_CAN_USE_32BIT */
209
210/* waits for MAC not busy, with timeout. Only called by smsc911x_mac_read
211 * and smsc911x_mac_write, so assumes mac_lock is held */
212static int smsc911x_mac_complete(struct smsc911x_data *pdata)
213{
214 int i;
215 u32 val;
216
217 SMSC_ASSERT_MAC_LOCK(pdata);
218
219 for (i = 0; i < 40; i++) {
220 val = smsc911x_reg_read(pdata, MAC_CSR_CMD);
221 if (!(val & MAC_CSR_CMD_CSR_BUSY_))
222 return 0;
223 }
224 SMSC_WARNING(HW, "Timed out waiting for MAC not BUSY. "
225 "MAC_CSR_CMD: 0x%08X", val);
226 return -EIO;
227}
228
229/* Fetches a MAC register value. Assumes mac_lock is acquired */
230static u32 smsc911x_mac_read(struct smsc911x_data *pdata, unsigned int offset)
231{
232 unsigned int temp;
233
234 SMSC_ASSERT_MAC_LOCK(pdata);
235
236 temp = smsc911x_reg_read(pdata, MAC_CSR_CMD);
237 if (unlikely(temp & MAC_CSR_CMD_CSR_BUSY_)) {
238 SMSC_WARNING(HW, "MAC busy at entry");
239 return 0xFFFFFFFF;
240 }
241
242 /* Send the MAC cmd */
243 smsc911x_reg_write(pdata, MAC_CSR_CMD, ((offset & 0xFF) |
244 MAC_CSR_CMD_CSR_BUSY_ | MAC_CSR_CMD_R_NOT_W_));
245
246 /* Workaround for hardware read-after-write restriction */
247 temp = smsc911x_reg_read(pdata, BYTE_TEST);
248
249 /* Wait for the read to complete */
250 if (likely(smsc911x_mac_complete(pdata) == 0))
251 return smsc911x_reg_read(pdata, MAC_CSR_DATA);
252
253 SMSC_WARNING(HW, "MAC busy after read");
254 return 0xFFFFFFFF;
255}
256
257/* Set a mac register, mac_lock must be acquired before calling */
258static void smsc911x_mac_write(struct smsc911x_data *pdata,
259 unsigned int offset, u32 val)
260{
261 unsigned int temp;
262
263 SMSC_ASSERT_MAC_LOCK(pdata);
264
265 temp = smsc911x_reg_read(pdata, MAC_CSR_CMD);
266 if (unlikely(temp & MAC_CSR_CMD_CSR_BUSY_)) {
267 SMSC_WARNING(HW,
268 "smsc911x_mac_write failed, MAC busy at entry");
269 return;
270 }
271
272 /* Send data to write */
273 smsc911x_reg_write(pdata, MAC_CSR_DATA, val);
274
275 /* Write the actual data */
276 smsc911x_reg_write(pdata, MAC_CSR_CMD, ((offset & 0xFF) |
277 MAC_CSR_CMD_CSR_BUSY_));
278
279 /* Workaround for hardware read-after-write restriction */
280 temp = smsc911x_reg_read(pdata, BYTE_TEST);
281
282 /* Wait for the write to complete */
283 if (likely(smsc911x_mac_complete(pdata) == 0))
284 return;
285
286 SMSC_WARNING(HW,
287 "smsc911x_mac_write failed, MAC busy after write");
288}
289
290/* Get a phy register */
291static int smsc911x_mii_read(struct mii_bus *bus, int phyaddr, int regidx)
292{
293 struct smsc911x_data *pdata = (struct smsc911x_data *)bus->priv;
294 unsigned long flags;
295 unsigned int addr;
296 int i, reg;
297
298 spin_lock_irqsave(&pdata->mac_lock, flags);
299
300 /* Confirm MII not busy */
301 if (unlikely(smsc911x_mac_read(pdata, MII_ACC) & MII_ACC_MII_BUSY_)) {
302 SMSC_WARNING(HW,
303 "MII is busy in smsc911x_mii_read???");
304 reg = -EIO;
305 goto out;
306 }
307
308 /* Set the address, index & direction (read from PHY) */
309 addr = ((phyaddr & 0x1F) << 11) | ((regidx & 0x1F) << 6);
310 smsc911x_mac_write(pdata, MII_ACC, addr);
311
312 /* Wait for read to complete w/ timeout */
313 for (i = 0; i < 100; i++)
314 if (!(smsc911x_mac_read(pdata, MII_ACC) & MII_ACC_MII_BUSY_)) {
315 reg = smsc911x_mac_read(pdata, MII_DATA);
316 goto out;
317 }
318
319 SMSC_WARNING(HW, "Timed out waiting for MII write to finish");
320 reg = -EIO;
321
322out:
323 spin_unlock_irqrestore(&pdata->mac_lock, flags);
324 return reg;
325}
326
327/* Set a phy register */
328static int smsc911x_mii_write(struct mii_bus *bus, int phyaddr, int regidx,
329 u16 val)
330{
331 struct smsc911x_data *pdata = (struct smsc911x_data *)bus->priv;
332 unsigned long flags;
333 unsigned int addr;
334 int i, reg;
335
336 spin_lock_irqsave(&pdata->mac_lock, flags);
337
338 /* Confirm MII not busy */
339 if (unlikely(smsc911x_mac_read(pdata, MII_ACC) & MII_ACC_MII_BUSY_)) {
340 SMSC_WARNING(HW,
341 "MII is busy in smsc911x_mii_write???");
342 reg = -EIO;
343 goto out;
344 }
345
346 /* Put the data to write in the MAC */
347 smsc911x_mac_write(pdata, MII_DATA, val);
348
349 /* Set the address, index & direction (write to PHY) */
350 addr = ((phyaddr & 0x1F) << 11) | ((regidx & 0x1F) << 6) |
351 MII_ACC_MII_WRITE_;
352 smsc911x_mac_write(pdata, MII_ACC, addr);
353
354 /* Wait for write to complete w/ timeout */
355 for (i = 0; i < 100; i++)
356 if (!(smsc911x_mac_read(pdata, MII_ACC) & MII_ACC_MII_BUSY_)) {
357 reg = 0;
358 goto out;
359 }
360
361 SMSC_WARNING(HW, "Timed out waiting for MII write to finish");
362 reg = -EIO;
363
364out:
365 spin_unlock_irqrestore(&pdata->mac_lock, flags);
366 return reg;
367}
368
369/* Autodetects and initialises external phy for SMSC9115 and SMSC9117 flavors.
370 * If something goes wrong, returns -ENODEV to revert back to internal phy.
371 * Performed at initialisation only, so interrupts are enabled */
372static int smsc911x_phy_initialise_external(struct smsc911x_data *pdata)
373{
374 unsigned int hwcfg = smsc911x_reg_read(pdata, HW_CFG);
375
376 /* External phy is requested, supported, and detected */
377 if (hwcfg & HW_CFG_EXT_PHY_DET_) {
378
379 /* Switch to external phy. Assuming tx and rx are stopped
380 * because smsc911x_phy_initialise is called before
381 * smsc911x_rx_initialise and tx_initialise. */
382
383 /* Disable phy clocks to the MAC */
384 hwcfg &= (~HW_CFG_PHY_CLK_SEL_);
385 hwcfg |= HW_CFG_PHY_CLK_SEL_CLK_DIS_;
386 smsc911x_reg_write(pdata, HW_CFG, hwcfg);
387 udelay(10); /* Enough time for clocks to stop */
388
389 /* Switch to external phy */
390 hwcfg |= HW_CFG_EXT_PHY_EN_;
391 smsc911x_reg_write(pdata, HW_CFG, hwcfg);
392
393 /* Enable phy clocks to the MAC */
394 hwcfg &= (~HW_CFG_PHY_CLK_SEL_);
395 hwcfg |= HW_CFG_PHY_CLK_SEL_EXT_PHY_;
396 smsc911x_reg_write(pdata, HW_CFG, hwcfg);
397 udelay(10); /* Enough time for clocks to restart */
398
399 hwcfg |= HW_CFG_SMI_SEL_;
400 smsc911x_reg_write(pdata, HW_CFG, hwcfg);
401
402 SMSC_TRACE(HW, "Successfully switched to external PHY");
403 pdata->using_extphy = 1;
404 } else {
405 SMSC_WARNING(HW, "No external PHY detected, "
406 "Using internal PHY instead.");
407 /* Use internal phy */
408 return -ENODEV;
409 }
410 return 0;
411}
412
413/* Fetches a tx status out of the status fifo */
414static unsigned int smsc911x_tx_get_txstatus(struct smsc911x_data *pdata)
415{
416 unsigned int result =
417 smsc911x_reg_read(pdata, TX_FIFO_INF) & TX_FIFO_INF_TSUSED_;
418
419 if (result != 0)
420 result = smsc911x_reg_read(pdata, TX_STATUS_FIFO);
421
422 return result;
423}
424
425/* Fetches the next rx status */
426static unsigned int smsc911x_rx_get_rxstatus(struct smsc911x_data *pdata)
427{
428 unsigned int result =
429 smsc911x_reg_read(pdata, RX_FIFO_INF) & RX_FIFO_INF_RXSUSED_;
430
431 if (result != 0)
432 result = smsc911x_reg_read(pdata, RX_STATUS_FIFO);
433
434 return result;
435}
436
437#ifdef USE_PHY_WORK_AROUND
438static int smsc911x_phy_check_loopbackpkt(struct smsc911x_data *pdata)
439{
440 unsigned int tries;
441 u32 wrsz;
442 u32 rdsz;
443 ulong bufp;
444
445 for (tries = 0; tries < 10; tries++) {
446 unsigned int txcmd_a;
447 unsigned int txcmd_b;
448 unsigned int status;
449 unsigned int pktlength;
450 unsigned int i;
451
452 /* Zero-out rx packet memory */
453 memset(pdata->loopback_rx_pkt, 0, MIN_PACKET_SIZE);
454
455 /* Write tx packet to 118 */
456 txcmd_a = (u32)((ulong)pdata->loopback_tx_pkt & 0x03) << 16;
457 txcmd_a |= TX_CMD_A_FIRST_SEG_ | TX_CMD_A_LAST_SEG_;
458 txcmd_a |= MIN_PACKET_SIZE;
459
460 txcmd_b = MIN_PACKET_SIZE << 16 | MIN_PACKET_SIZE;
461
462 smsc911x_reg_write(pdata, TX_DATA_FIFO, txcmd_a);
463 smsc911x_reg_write(pdata, TX_DATA_FIFO, txcmd_b);
464
465 bufp = (ulong)pdata->loopback_tx_pkt & (~0x3);
466 wrsz = MIN_PACKET_SIZE + 3;
467 wrsz += (u32)((ulong)pdata->loopback_tx_pkt & 0x3);
468 wrsz >>= 2;
469
470 smsc911x_tx_writefifo(pdata, (unsigned int *)bufp, wrsz);
471
472 /* Wait till transmit is done */
473 i = 60;
474 do {
475 udelay(5);
476 status = smsc911x_tx_get_txstatus(pdata);
477 } while ((i--) && (!status));
478
479 if (!status) {
480 SMSC_WARNING(HW, "Failed to transmit "
481 "during loopback test");
482 continue;
483 }
484 if (status & TX_STS_ES_) {
485 SMSC_WARNING(HW, "Transmit encountered "
486 "errors during loopback test");
487 continue;
488 }
489
490 /* Wait till receive is done */
491 i = 60;
492 do {
493 udelay(5);
494 status = smsc911x_rx_get_rxstatus(pdata);
495 } while ((i--) && (!status));
496
497 if (!status) {
498 SMSC_WARNING(HW,
499 "Failed to receive during loopback test");
500 continue;
501 }
502 if (status & RX_STS_ES_) {
503 SMSC_WARNING(HW, "Receive encountered "
504 "errors during loopback test");
505 continue;
506 }
507
508 pktlength = ((status & 0x3FFF0000UL) >> 16);
509 bufp = (ulong)pdata->loopback_rx_pkt;
510 rdsz = pktlength + 3;
511 rdsz += (u32)((ulong)pdata->loopback_rx_pkt & 0x3);
512 rdsz >>= 2;
513
514 smsc911x_rx_readfifo(pdata, (unsigned int *)bufp, rdsz);
515
516 if (pktlength != (MIN_PACKET_SIZE + 4)) {
517 SMSC_WARNING(HW, "Unexpected packet size "
518 "during loop back test, size=%d, will retry",
519 pktlength);
520 } else {
521 unsigned int j;
522 int mismatch = 0;
523 for (j = 0; j < MIN_PACKET_SIZE; j++) {
524 if (pdata->loopback_tx_pkt[j]
525 != pdata->loopback_rx_pkt[j]) {
526 mismatch = 1;
527 break;
528 }
529 }
530 if (!mismatch) {
531 SMSC_TRACE(HW, "Successfully verified "
532 "loopback packet");
533 return 0;
534 } else {
535 SMSC_WARNING(HW, "Data mismatch "
536 "during loop back test, will retry");
537 }
538 }
539 }
540
541 return -EIO;
542}
543
544static int smsc911x_phy_reset(struct smsc911x_data *pdata)
545{
546 struct phy_device *phy_dev = pdata->phy_dev;
547 unsigned int temp;
548 unsigned int i = 100000;
549
550 BUG_ON(!phy_dev);
551 BUG_ON(!phy_dev->bus);
552
553 SMSC_TRACE(HW, "Performing PHY BCR Reset");
554 smsc911x_mii_write(phy_dev->bus, phy_dev->addr, MII_BMCR, BMCR_RESET);
555 do {
556 msleep(1);
557 temp = smsc911x_mii_read(phy_dev->bus, phy_dev->addr,
558 MII_BMCR);
559 } while ((i--) && (temp & BMCR_RESET));
560
561 if (temp & BMCR_RESET) {
562 SMSC_WARNING(HW, "PHY reset failed to complete.");
563 return -EIO;
564 }
565 /* Extra delay required because the phy may not be completed with
566 * its reset when BMCR_RESET is cleared. Specs say 256 uS is
567 * enough delay but using 1ms here to be safe */
568 msleep(1);
569
570 return 0;
571}
572
573static int smsc911x_phy_loopbacktest(struct net_device *dev)
574{
575 struct smsc911x_data *pdata = netdev_priv(dev);
576 struct phy_device *phy_dev = pdata->phy_dev;
577 int result = -EIO;
578 unsigned int i, val;
579 unsigned long flags;
580
581 /* Initialise tx packet using broadcast destination address */
582 memset(pdata->loopback_tx_pkt, 0xff, ETH_ALEN);
583
584 /* Use incrementing source address */
585 for (i = 6; i < 12; i++)
586 pdata->loopback_tx_pkt[i] = (char)i;
587
588 /* Set length type field */
589 pdata->loopback_tx_pkt[12] = 0x00;
590 pdata->loopback_tx_pkt[13] = 0x00;
591
592 for (i = 14; i < MIN_PACKET_SIZE; i++)
593 pdata->loopback_tx_pkt[i] = (char)i;
594
595 val = smsc911x_reg_read(pdata, HW_CFG);
596 val &= HW_CFG_TX_FIF_SZ_;
597 val |= HW_CFG_SF_;
598 smsc911x_reg_write(pdata, HW_CFG, val);
599
600 smsc911x_reg_write(pdata, TX_CFG, TX_CFG_TX_ON_);
601 smsc911x_reg_write(pdata, RX_CFG,
602 (u32)((ulong)pdata->loopback_rx_pkt & 0x03) << 8);
603
604 for (i = 0; i < 10; i++) {
605 /* Set PHY to 10/FD, no ANEG, and loopback mode */
606 smsc911x_mii_write(phy_dev->bus, phy_dev->addr, MII_BMCR,
607 BMCR_LOOPBACK | BMCR_FULLDPLX);
608
609 /* Enable MAC tx/rx, FD */
610 spin_lock_irqsave(&pdata->mac_lock, flags);
611 smsc911x_mac_write(pdata, MAC_CR, MAC_CR_FDPX_
612 | MAC_CR_TXEN_ | MAC_CR_RXEN_);
613 spin_unlock_irqrestore(&pdata->mac_lock, flags);
614
615 if (smsc911x_phy_check_loopbackpkt(pdata) == 0) {
616 result = 0;
617 break;
618 }
619 pdata->resetcount++;
620
621 /* Disable MAC rx */
622 spin_lock_irqsave(&pdata->mac_lock, flags);
623 smsc911x_mac_write(pdata, MAC_CR, 0);
624 spin_unlock_irqrestore(&pdata->mac_lock, flags);
625
626 smsc911x_phy_reset(pdata);
627 }
628
629 /* Disable MAC */
630 spin_lock_irqsave(&pdata->mac_lock, flags);
631 smsc911x_mac_write(pdata, MAC_CR, 0);
632 spin_unlock_irqrestore(&pdata->mac_lock, flags);
633
634 /* Cancel PHY loopback mode */
635 smsc911x_mii_write(phy_dev->bus, phy_dev->addr, MII_BMCR, 0);
636
637 smsc911x_reg_write(pdata, TX_CFG, 0);
638 smsc911x_reg_write(pdata, RX_CFG, 0);
639
640 return result;
641}
642#endif /* USE_PHY_WORK_AROUND */
643
644static u8 smsc95xx_resolve_flowctrl_fulldplx(u16 lcladv, u16 rmtadv)
645{
646 u8 cap = 0;
647
648 if (lcladv & ADVERTISE_PAUSE_CAP) {
649 if (lcladv & ADVERTISE_PAUSE_ASYM) {
650 if (rmtadv & LPA_PAUSE_CAP)
651 cap = FLOW_CTRL_TX | FLOW_CTRL_RX;
652 else if (rmtadv & LPA_PAUSE_ASYM)
653 cap = FLOW_CTRL_RX;
654 } else {
655 if (rmtadv & LPA_PAUSE_CAP)
656 cap = FLOW_CTRL_TX | FLOW_CTRL_RX;
657 }
658 } else if (lcladv & ADVERTISE_PAUSE_ASYM) {
659 if ((rmtadv & LPA_PAUSE_CAP) && (rmtadv & LPA_PAUSE_ASYM))
660 cap = FLOW_CTRL_TX;
661 }
662
663 return cap;
664}
665
666static void smsc911x_phy_update_flowcontrol(struct smsc911x_data *pdata)
667{
668 struct phy_device *phy_dev = pdata->phy_dev;
669 u32 afc = smsc911x_reg_read(pdata, AFC_CFG);
670 u32 flow;
671 unsigned long flags;
672
673 if (phy_dev->duplex == DUPLEX_FULL) {
674 u16 lcladv = phy_read(phy_dev, MII_ADVERTISE);
675 u16 rmtadv = phy_read(phy_dev, MII_LPA);
676 u8 cap = smsc95xx_resolve_flowctrl_fulldplx(lcladv, rmtadv);
677
678 if (cap & FLOW_CTRL_RX)
679 flow = 0xFFFF0002;
680 else
681 flow = 0;
682
683 if (cap & FLOW_CTRL_TX)
684 afc |= 0xF;
685 else
686 afc &= ~0xF;
687
688 SMSC_TRACE(HW, "rx pause %s, tx pause %s",
689 (cap & FLOW_CTRL_RX ? "enabled" : "disabled"),
690 (cap & FLOW_CTRL_TX ? "enabled" : "disabled"));
691 } else {
692 SMSC_TRACE(HW, "half duplex");
693 flow = 0;
694 afc |= 0xF;
695 }
696
697 spin_lock_irqsave(&pdata->mac_lock, flags);
698 smsc911x_mac_write(pdata, FLOW, flow);
699 spin_unlock_irqrestore(&pdata->mac_lock, flags);
700
701 smsc911x_reg_write(pdata, AFC_CFG, afc);
702}
703
704/* Update link mode if anything has changed. Called periodically when the
705 * PHY is in polling mode, even if nothing has changed. */
706static void smsc911x_phy_adjust_link(struct net_device *dev)
707{
708 struct smsc911x_data *pdata = netdev_priv(dev);
709 struct phy_device *phy_dev = pdata->phy_dev;
710 unsigned long flags;
711 int carrier;
712
713 if (phy_dev->duplex != pdata->last_duplex) {
714 unsigned int mac_cr;
715 SMSC_TRACE(HW, "duplex state has changed");
716
717 spin_lock_irqsave(&pdata->mac_lock, flags);
718 mac_cr = smsc911x_mac_read(pdata, MAC_CR);
719 if (phy_dev->duplex) {
720 SMSC_TRACE(HW,
721 "configuring for full duplex mode");
722 mac_cr |= MAC_CR_FDPX_;
723 } else {
724 SMSC_TRACE(HW,
725 "configuring for half duplex mode");
726 mac_cr &= ~MAC_CR_FDPX_;
727 }
728 smsc911x_mac_write(pdata, MAC_CR, mac_cr);
729 spin_unlock_irqrestore(&pdata->mac_lock, flags);
730
731 smsc911x_phy_update_flowcontrol(pdata);
732 pdata->last_duplex = phy_dev->duplex;
733 }
734
735 carrier = netif_carrier_ok(dev);
736 if (carrier != pdata->last_carrier) {
737 SMSC_TRACE(HW, "carrier state has changed");
738 if (carrier) {
739 SMSC_TRACE(HW, "configuring for carrier OK");
740 if ((pdata->gpio_orig_setting & GPIO_CFG_LED1_EN_) &&
741 (!pdata->using_extphy)) {
742 /* Restore orginal GPIO configuration */
743 pdata->gpio_setting = pdata->gpio_orig_setting;
744 smsc911x_reg_write(pdata, GPIO_CFG,
745 pdata->gpio_setting);
746 }
747 } else {
748 SMSC_TRACE(HW, "configuring for no carrier");
749 /* Check global setting that LED1
750 * usage is 10/100 indicator */
751 pdata->gpio_setting = smsc911x_reg_read(pdata,
752 GPIO_CFG);
753 if ((pdata->gpio_setting & GPIO_CFG_LED1_EN_)
754 && (!pdata->using_extphy)) {
755 /* Force 10/100 LED off, after saving
756 * orginal GPIO configuration */
757 pdata->gpio_orig_setting = pdata->gpio_setting;
758
759 pdata->gpio_setting &= ~GPIO_CFG_LED1_EN_;
760 pdata->gpio_setting |= (GPIO_CFG_GPIOBUF0_
761 | GPIO_CFG_GPIODIR0_
762 | GPIO_CFG_GPIOD0_);
763 smsc911x_reg_write(pdata, GPIO_CFG,
764 pdata->gpio_setting);
765 }
766 }
767 pdata->last_carrier = carrier;
768 }
769}
770
771static int smsc911x_mii_probe(struct net_device *dev)
772{
773 struct smsc911x_data *pdata = netdev_priv(dev);
774 struct phy_device *phydev = NULL;
775 int phy_addr;
776
777 /* find the first phy */
778 for (phy_addr = 0; phy_addr < PHY_MAX_ADDR; phy_addr++) {
779 if (pdata->mii_bus->phy_map[phy_addr]) {
780 phydev = pdata->mii_bus->phy_map[phy_addr];
781 SMSC_TRACE(PROBE, "PHY %d: addr %d, phy_id 0x%08X",
782 phy_addr, phydev->addr, phydev->phy_id);
783 break;
784 }
785 }
786
787 if (!phydev) {
788 pr_err("%s: no PHY found\n", dev->name);
789 return -ENODEV;
790 }
791
792 phydev = phy_connect(dev, phydev->dev.bus_id,
793 &smsc911x_phy_adjust_link, 0, pdata->phy_interface);
794
795 if (IS_ERR(phydev)) {
796 pr_err("%s: Could not attach to PHY\n", dev->name);
797 return PTR_ERR(phydev);
798 }
799
800 pr_info("%s: attached PHY driver [%s] (mii_bus:phy_addr=%s, irq=%d)\n",
801 dev->name, phydev->drv->name, phydev->dev.bus_id, phydev->irq);
802
803 /* mask with MAC supported features */
804 phydev->supported &= (PHY_BASIC_FEATURES | SUPPORTED_Pause |
805 SUPPORTED_Asym_Pause);
806 phydev->advertising = phydev->supported;
807
808 pdata->phy_dev = phydev;
809 pdata->last_duplex = -1;
810 pdata->last_carrier = -1;
811
812#ifdef USE_PHY_WORK_AROUND
813 if (smsc911x_phy_loopbacktest(dev) < 0) {
814 SMSC_WARNING(HW, "Failed Loop Back Test");
815 return -ENODEV;
816 }
817 SMSC_TRACE(HW, "Passed Loop Back Test");
818#endif /* USE_PHY_WORK_AROUND */
819
820 SMSC_TRACE(HW, "phy initialised succesfully");
821 return 0;
822}
823
824static int __devinit smsc911x_mii_init(struct platform_device *pdev,
825 struct net_device *dev)
826{
827 struct smsc911x_data *pdata = netdev_priv(dev);
828 int err = -ENXIO, i;
829
830 pdata->mii_bus = mdiobus_alloc();
831 if (!pdata->mii_bus) {
832 err = -ENOMEM;
833 goto err_out_1;
834 }
835
836 pdata->mii_bus->name = SMSC_MDIONAME;
837 snprintf(pdata->mii_bus->id, MII_BUS_ID_SIZE, "%x", pdev->id);
838 pdata->mii_bus->priv = pdata;
839 pdata->mii_bus->read = smsc911x_mii_read;
840 pdata->mii_bus->write = smsc911x_mii_write;
841 pdata->mii_bus->irq = pdata->phy_irq;
842 for (i = 0; i < PHY_MAX_ADDR; ++i)
843 pdata->mii_bus->irq[i] = PHY_POLL;
844
845 pdata->mii_bus->parent = &pdev->dev;
846 dev_set_drvdata(&pdev->dev, &pdata->mii_bus);
847
848 pdata->using_extphy = 0;
849
850 switch (pdata->idrev & 0xFFFF0000) {
851 case 0x01170000:
852 case 0x01150000:
853 case 0x117A0000:
854 case 0x115A0000:
855 /* External PHY supported, try to autodetect */
856 if (smsc911x_phy_initialise_external(pdata) < 0) {
857 SMSC_TRACE(HW, "No external PHY detected, "
858 "using internal PHY");
859 }
860 break;
861 default:
862 SMSC_TRACE(HW, "External PHY is not supported, "
863 "using internal PHY");
864 break;
865 }
866
867 if (!pdata->using_extphy) {
868 /* Mask all PHYs except ID 1 (internal) */
869 pdata->mii_bus->phy_mask = ~(1 << 1);
870 }
871
872 if (mdiobus_register(pdata->mii_bus)) {
873 SMSC_WARNING(PROBE, "Error registering mii bus");
874 goto err_out_free_bus_2;
875 }
876
877 if (smsc911x_mii_probe(dev) < 0) {
878 SMSC_WARNING(PROBE, "Error registering mii bus");
879 goto err_out_unregister_bus_3;
880 }
881
882 return 0;
883
884err_out_unregister_bus_3:
885 mdiobus_unregister(pdata->mii_bus);
886err_out_free_bus_2:
887 mdiobus_free(pdata->mii_bus);
888err_out_1:
889 return err;
890}
891
892/* Gets the number of tx statuses in the fifo */
893static unsigned int smsc911x_tx_get_txstatcount(struct smsc911x_data *pdata)
894{
895 return (smsc911x_reg_read(pdata, TX_FIFO_INF)
896 & TX_FIFO_INF_TSUSED_) >> 16;
897}
898
899/* Reads tx statuses and increments counters where necessary */
900static void smsc911x_tx_update_txcounters(struct net_device *dev)
901{
902 struct smsc911x_data *pdata = netdev_priv(dev);
903 unsigned int tx_stat;
904
905 while ((tx_stat = smsc911x_tx_get_txstatus(pdata)) != 0) {
906 if (unlikely(tx_stat & 0x80000000)) {
907 /* In this driver the packet tag is used as the packet
908 * length. Since a packet length can never reach the
909 * size of 0x8000, this bit is reserved. It is worth
910 * noting that the "reserved bit" in the warning above
911 * does not reference a hardware defined reserved bit
912 * but rather a driver defined one.
913 */
914 SMSC_WARNING(HW,
915 "Packet tag reserved bit is high");
916 } else {
917 if (unlikely(tx_stat & 0x00008000)) {
918 dev->stats.tx_errors++;
919 } else {
920 dev->stats.tx_packets++;
921 dev->stats.tx_bytes += (tx_stat >> 16);
922 }
923 if (unlikely(tx_stat & 0x00000100)) {
924 dev->stats.collisions += 16;
925 dev->stats.tx_aborted_errors += 1;
926 } else {
927 dev->stats.collisions +=
928 ((tx_stat >> 3) & 0xF);
929 }
930 if (unlikely(tx_stat & 0x00000800))
931 dev->stats.tx_carrier_errors += 1;
932 if (unlikely(tx_stat & 0x00000200)) {
933 dev->stats.collisions++;
934 dev->stats.tx_aborted_errors++;
935 }
936 }
937 }
938}
939
940/* Increments the Rx error counters */
941static void
942smsc911x_rx_counterrors(struct net_device *dev, unsigned int rxstat)
943{
944 int crc_err = 0;
945
946 if (unlikely(rxstat & 0x00008000)) {
947 dev->stats.rx_errors++;
948 if (unlikely(rxstat & 0x00000002)) {
949 dev->stats.rx_crc_errors++;
950 crc_err = 1;
951 }
952 }
953 if (likely(!crc_err)) {
954 if (unlikely((rxstat & 0x00001020) == 0x00001020)) {
955 /* Frame type indicates length,
956 * and length error is set */
957 dev->stats.rx_length_errors++;
958 }
959 if (rxstat & RX_STS_MCAST_)
960 dev->stats.multicast++;
961 }
962}
963
964/* Quickly dumps bad packets */
965static void
966smsc911x_rx_fastforward(struct smsc911x_data *pdata, unsigned int pktbytes)
967{
968 unsigned int pktwords = (pktbytes + NET_IP_ALIGN + 3) >> 2;
969
970 if (likely(pktwords >= 4)) {
971 unsigned int timeout = 500;
972 unsigned int val;
973 smsc911x_reg_write(pdata, RX_DP_CTRL, RX_DP_CTRL_RX_FFWD_);
974 do {
975 udelay(1);
976 val = smsc911x_reg_read(pdata, RX_DP_CTRL);
977 } while (timeout-- && (val & RX_DP_CTRL_RX_FFWD_));
978
979 if (unlikely(timeout == 0))
980 SMSC_WARNING(HW, "Timed out waiting for "
981 "RX FFWD to finish, RX_DP_CTRL: 0x%08X", val);
982 } else {
983 unsigned int temp;
984 while (pktwords--)
985 temp = smsc911x_reg_read(pdata, RX_DATA_FIFO);
986 }
987}
988
989/* NAPI poll function */
990static int smsc911x_poll(struct napi_struct *napi, int budget)
991{
992 struct smsc911x_data *pdata =
993 container_of(napi, struct smsc911x_data, napi);
994 struct net_device *dev = pdata->dev;
995 int npackets = 0;
996
997 while (likely(netif_running(dev)) && (npackets < budget)) {
998 unsigned int pktlength;
999 unsigned int pktwords;
1000 struct sk_buff *skb;
1001 unsigned int rxstat = smsc911x_rx_get_rxstatus(pdata);
1002
1003 if (!rxstat) {
1004 unsigned int temp;
1005 /* We processed all packets available. Tell NAPI it can
1006 * stop polling then re-enable rx interrupts */
1007 smsc911x_reg_write(pdata, INT_STS, INT_STS_RSFL_);
1008 netif_rx_complete(dev, napi);
1009 temp = smsc911x_reg_read(pdata, INT_EN);
1010 temp |= INT_EN_RSFL_EN_;
1011 smsc911x_reg_write(pdata, INT_EN, temp);
1012 break;
1013 }
1014
1015 /* Count packet for NAPI scheduling, even if it has an error.
1016 * Error packets still require cycles to discard */
1017 npackets++;
1018
1019 pktlength = ((rxstat & 0x3FFF0000) >> 16);
1020 pktwords = (pktlength + NET_IP_ALIGN + 3) >> 2;
1021 smsc911x_rx_counterrors(dev, rxstat);
1022
1023 if (unlikely(rxstat & RX_STS_ES_)) {
1024 SMSC_WARNING(RX_ERR,
1025 "Discarding packet with error bit set");
1026 /* Packet has an error, discard it and continue with
1027 * the next */
1028 smsc911x_rx_fastforward(pdata, pktwords);
1029 dev->stats.rx_dropped++;
1030 continue;
1031 }
1032
1033 skb = netdev_alloc_skb(dev, pktlength + NET_IP_ALIGN);
1034 if (unlikely(!skb)) {
1035 SMSC_WARNING(RX_ERR,
1036 "Unable to allocate skb for rx packet");
1037 /* Drop the packet and stop this polling iteration */
1038 smsc911x_rx_fastforward(pdata, pktwords);
1039 dev->stats.rx_dropped++;
1040 break;
1041 }
1042
1043 skb->data = skb->head;
1044 skb_reset_tail_pointer(skb);
1045
1046 /* Align IP on 16B boundary */
1047 skb_reserve(skb, NET_IP_ALIGN);
1048 skb_put(skb, pktlength - 4);
1049 smsc911x_rx_readfifo(pdata, (unsigned int *)skb->head,
1050 pktwords);
1051 skb->protocol = eth_type_trans(skb, dev);
1052 skb->ip_summed = CHECKSUM_NONE;
1053 netif_receive_skb(skb);
1054
1055 /* Update counters */
1056 dev->stats.rx_packets++;
1057 dev->stats.rx_bytes += (pktlength - 4);
1058 dev->last_rx = jiffies;
1059 }
1060
1061 /* Return total received packets */
1062 return npackets;
1063}
1064
1065/* Returns hash bit number for given MAC address
1066 * Example:
1067 * 01 00 5E 00 00 01 -> returns bit number 31 */
1068static unsigned int smsc911x_hash(char addr[ETH_ALEN])
1069{
1070 return (ether_crc(ETH_ALEN, addr) >> 26) & 0x3f;
1071}
1072
1073static void smsc911x_rx_multicast_update(struct smsc911x_data *pdata)
1074{
1075 /* Performs the multicast & mac_cr update. This is called when
1076 * safe on the current hardware, and with the mac_lock held */
1077 unsigned int mac_cr;
1078
1079 SMSC_ASSERT_MAC_LOCK(pdata);
1080
1081 mac_cr = smsc911x_mac_read(pdata, MAC_CR);
1082 mac_cr |= pdata->set_bits_mask;
1083 mac_cr &= ~(pdata->clear_bits_mask);
1084 smsc911x_mac_write(pdata, MAC_CR, mac_cr);
1085 smsc911x_mac_write(pdata, HASHH, pdata->hashhi);
1086 smsc911x_mac_write(pdata, HASHL, pdata->hashlo);
1087 SMSC_TRACE(HW, "maccr 0x%08X, HASHH 0x%08X, HASHL 0x%08X",
1088 mac_cr, pdata->hashhi, pdata->hashlo);
1089}
1090
1091static void smsc911x_rx_multicast_update_workaround(struct smsc911x_data *pdata)
1092{
1093 unsigned int mac_cr;
1094
1095 /* This function is only called for older LAN911x devices
1096 * (revA or revB), where MAC_CR, HASHH and HASHL should not
1097 * be modified during Rx - newer devices immediately update the
1098 * registers.
1099 *
1100 * This is called from interrupt context */
1101
1102 spin_lock(&pdata->mac_lock);
1103
1104 /* Check Rx has stopped */
1105 if (smsc911x_mac_read(pdata, MAC_CR) & MAC_CR_RXEN_)
1106 SMSC_WARNING(DRV, "Rx not stopped");
1107
1108 /* Perform the update - safe to do now Rx has stopped */
1109 smsc911x_rx_multicast_update(pdata);
1110
1111 /* Re-enable Rx */
1112 mac_cr = smsc911x_mac_read(pdata, MAC_CR);
1113 mac_cr |= MAC_CR_RXEN_;
1114 smsc911x_mac_write(pdata, MAC_CR, mac_cr);
1115
1116 pdata->multicast_update_pending = 0;
1117
1118 spin_unlock(&pdata->mac_lock);
1119}
1120
1121static int smsc911x_soft_reset(struct smsc911x_data *pdata)
1122{
1123 unsigned int timeout;
1124 unsigned int temp;
1125
1126 /* Reset the LAN911x */
1127 smsc911x_reg_write(pdata, HW_CFG, HW_CFG_SRST_);
1128 timeout = 10;
1129 do {
1130 udelay(10);
1131 temp = smsc911x_reg_read(pdata, HW_CFG);
1132 } while ((--timeout) && (temp & HW_CFG_SRST_));
1133
1134 if (unlikely(temp & HW_CFG_SRST_)) {
1135 SMSC_WARNING(DRV, "Failed to complete reset");
1136 return -EIO;
1137 }
1138 return 0;
1139}
1140
1141/* Sets the device MAC address to dev_addr, called with mac_lock held */
1142static void
1143smsc911x_set_mac_address(struct smsc911x_data *pdata, u8 dev_addr[6])
1144{
1145 u32 mac_high16 = (dev_addr[5] << 8) | dev_addr[4];
1146 u32 mac_low32 = (dev_addr[3] << 24) | (dev_addr[2] << 16) |
1147 (dev_addr[1] << 8) | dev_addr[0];
1148
1149 SMSC_ASSERT_MAC_LOCK(pdata);
1150
1151 smsc911x_mac_write(pdata, ADDRH, mac_high16);
1152 smsc911x_mac_write(pdata, ADDRL, mac_low32);
1153}
1154
1155static int smsc911x_open(struct net_device *dev)
1156{
1157 struct smsc911x_data *pdata = netdev_priv(dev);
1158 unsigned int timeout;
1159 unsigned int temp;
1160 unsigned int intcfg;
1161
1162 /* if the phy is not yet registered, retry later*/
1163 if (!pdata->phy_dev) {
1164 SMSC_WARNING(HW, "phy_dev is NULL");
1165 return -EAGAIN;
1166 }
1167
1168 if (!is_valid_ether_addr(dev->dev_addr)) {
1169 SMSC_WARNING(HW, "dev_addr is not a valid MAC address");
1170 return -EADDRNOTAVAIL;
1171 }
1172
1173 /* Reset the LAN911x */
1174 if (smsc911x_soft_reset(pdata)) {
1175 SMSC_WARNING(HW, "soft reset failed");
1176 return -EIO;
1177 }
1178
1179 smsc911x_reg_write(pdata, HW_CFG, 0x00050000);
1180 smsc911x_reg_write(pdata, AFC_CFG, 0x006E3740);
1181
1182 /* Make sure EEPROM has finished loading before setting GPIO_CFG */
1183 timeout = 50;
1184 while ((timeout--) &&
1185 (smsc911x_reg_read(pdata, E2P_CMD) & E2P_CMD_EPC_BUSY_)) {
1186 udelay(10);
1187 }
1188
1189 if (unlikely(timeout == 0))
1190 SMSC_WARNING(IFUP,
1191 "Timed out waiting for EEPROM busy bit to clear");
1192
1193 smsc911x_reg_write(pdata, GPIO_CFG, 0x70070000);
1194
1195 /* The soft reset above cleared the device's MAC address,
1196 * restore it from local copy (set in probe) */
1197 spin_lock_irq(&pdata->mac_lock);
1198 smsc911x_set_mac_address(pdata, dev->dev_addr);
1199 spin_unlock_irq(&pdata->mac_lock);
1200
1201 /* Initialise irqs, but leave all sources disabled */
1202 smsc911x_reg_write(pdata, INT_EN, 0);
1203 smsc911x_reg_write(pdata, INT_STS, 0xFFFFFFFF);
1204
1205 /* Set interrupt deassertion to 100uS */
1206 intcfg = ((10 << 24) | INT_CFG_IRQ_EN_);
1207
1208 if (pdata->irq_polarity) {
1209 SMSC_TRACE(IFUP, "irq polarity: active high");
1210 intcfg |= INT_CFG_IRQ_POL_;
1211 } else {
1212 SMSC_TRACE(IFUP, "irq polarity: active low");
1213 }
1214
1215 if (pdata->irq_type) {
1216 SMSC_TRACE(IFUP, "irq type: push-pull");
1217 intcfg |= INT_CFG_IRQ_TYPE_;
1218 } else {
1219 SMSC_TRACE(IFUP, "irq type: open drain");
1220 }
1221
1222 smsc911x_reg_write(pdata, INT_CFG, intcfg);
1223
1224 SMSC_TRACE(IFUP, "Testing irq handler using IRQ %d", dev->irq);
1225 pdata->software_irq_signal = 0;
1226 smp_wmb();
1227
1228 temp = smsc911x_reg_read(pdata, INT_EN);
1229 temp |= INT_EN_SW_INT_EN_;
1230 smsc911x_reg_write(pdata, INT_EN, temp);
1231
1232 timeout = 1000;
1233 while (timeout--) {
1234 if (pdata->software_irq_signal)
1235 break;
1236 msleep(1);
1237 }
1238
1239 if (!pdata->software_irq_signal) {
1240 dev_warn(&dev->dev, "ISR failed signaling test (IRQ %d)\n",
1241 dev->irq);
1242 return -ENODEV;
1243 }
1244 SMSC_TRACE(IFUP, "IRQ handler passed test using IRQ %d", dev->irq);
1245
1246 dev_info(&dev->dev, "SMSC911x/921x identified at %#08lx, IRQ: %d\n",
1247 (unsigned long)pdata->ioaddr, dev->irq);
1248
1249 /* Bring the PHY up */
1250 phy_start(pdata->phy_dev);
1251
1252 temp = smsc911x_reg_read(pdata, HW_CFG);
1253 /* Preserve TX FIFO size and external PHY configuration */
1254 temp &= (HW_CFG_TX_FIF_SZ_|0x00000FFF);
1255 temp |= HW_CFG_SF_;
1256 smsc911x_reg_write(pdata, HW_CFG, temp);
1257
1258 temp = smsc911x_reg_read(pdata, FIFO_INT);
1259 temp |= FIFO_INT_TX_AVAIL_LEVEL_;
1260 temp &= ~(FIFO_INT_RX_STS_LEVEL_);
1261 smsc911x_reg_write(pdata, FIFO_INT, temp);
1262
1263 /* set RX Data offset to 2 bytes for alignment */
1264 smsc911x_reg_write(pdata, RX_CFG, (2 << 8));
1265
1266 /* enable NAPI polling before enabling RX interrupts */
1267 napi_enable(&pdata->napi);
1268
1269 temp = smsc911x_reg_read(pdata, INT_EN);
1270 temp |= (INT_EN_TDFA_EN_ | INT_EN_RSFL_EN_);
1271 smsc911x_reg_write(pdata, INT_EN, temp);
1272
1273 spin_lock_irq(&pdata->mac_lock);
1274 temp = smsc911x_mac_read(pdata, MAC_CR);
1275 temp |= (MAC_CR_TXEN_ | MAC_CR_RXEN_ | MAC_CR_HBDIS_);
1276 smsc911x_mac_write(pdata, MAC_CR, temp);
1277 spin_unlock_irq(&pdata->mac_lock);
1278
1279 smsc911x_reg_write(pdata, TX_CFG, TX_CFG_TX_ON_);
1280
1281 netif_start_queue(dev);
1282 return 0;
1283}
1284
1285/* Entry point for stopping the interface */
1286static int smsc911x_stop(struct net_device *dev)
1287{
1288 struct smsc911x_data *pdata = netdev_priv(dev);
1289 unsigned int temp;
1290
1291 BUG_ON(!pdata->phy_dev);
1292
1293 /* Disable all device interrupts */
1294 temp = smsc911x_reg_read(pdata, INT_CFG);
1295 temp &= ~INT_CFG_IRQ_EN_;
1296 smsc911x_reg_write(pdata, INT_CFG, temp);
1297
1298 /* Stop Tx and Rx polling */
1299 netif_stop_queue(dev);
1300 napi_disable(&pdata->napi);
1301
1302 /* At this point all Rx and Tx activity is stopped */
1303 dev->stats.rx_dropped += smsc911x_reg_read(pdata, RX_DROP);
1304 smsc911x_tx_update_txcounters(dev);
1305
1306 /* Bring the PHY down */
1307 phy_stop(pdata->phy_dev);
1308
1309 SMSC_TRACE(IFDOWN, "Interface stopped");
1310 return 0;
1311}
1312
1313/* Entry point for transmitting a packet */
1314static int smsc911x_hard_start_xmit(struct sk_buff *skb, struct net_device *dev)
1315{
1316 struct smsc911x_data *pdata = netdev_priv(dev);
1317 unsigned int freespace;
1318 unsigned int tx_cmd_a;
1319 unsigned int tx_cmd_b;
1320 unsigned int temp;
1321 u32 wrsz;
1322 ulong bufp;
1323
1324 freespace = smsc911x_reg_read(pdata, TX_FIFO_INF) & TX_FIFO_INF_TDFREE_;
1325
1326 if (unlikely(freespace < TX_FIFO_LOW_THRESHOLD))
1327 SMSC_WARNING(TX_ERR,
1328 "Tx data fifo low, space available: %d", freespace);
1329
1330 /* Word alignment adjustment */
1331 tx_cmd_a = (u32)((ulong)skb->data & 0x03) << 16;
1332 tx_cmd_a |= TX_CMD_A_FIRST_SEG_ | TX_CMD_A_LAST_SEG_;
1333 tx_cmd_a |= (unsigned int)skb->len;
1334
1335 tx_cmd_b = ((unsigned int)skb->len) << 16;
1336 tx_cmd_b |= (unsigned int)skb->len;
1337
1338 smsc911x_reg_write(pdata, TX_DATA_FIFO, tx_cmd_a);
1339 smsc911x_reg_write(pdata, TX_DATA_FIFO, tx_cmd_b);
1340
1341 bufp = (ulong)skb->data & (~0x3);
1342 wrsz = (u32)skb->len + 3;
1343 wrsz += (u32)((ulong)skb->data & 0x3);
1344 wrsz >>= 2;
1345
1346 smsc911x_tx_writefifo(pdata, (unsigned int *)bufp, wrsz);
1347 freespace -= (skb->len + 32);
1348 dev_kfree_skb(skb);
1349 dev->trans_start = jiffies;
1350
1351 if (unlikely(smsc911x_tx_get_txstatcount(pdata) >= 30))
1352 smsc911x_tx_update_txcounters(dev);
1353
1354 if (freespace < TX_FIFO_LOW_THRESHOLD) {
1355 netif_stop_queue(dev);
1356 temp = smsc911x_reg_read(pdata, FIFO_INT);
1357 temp &= 0x00FFFFFF;
1358 temp |= 0x32000000;
1359 smsc911x_reg_write(pdata, FIFO_INT, temp);
1360 }
1361
1362 return NETDEV_TX_OK;
1363}
1364
1365/* Entry point for getting status counters */
1366static struct net_device_stats *smsc911x_get_stats(struct net_device *dev)
1367{
1368 struct smsc911x_data *pdata = netdev_priv(dev);
1369 smsc911x_tx_update_txcounters(dev);
1370 dev->stats.rx_dropped += smsc911x_reg_read(pdata, RX_DROP);
1371 return &dev->stats;
1372}
1373
1374/* Entry point for setting addressing modes */
1375static void smsc911x_set_multicast_list(struct net_device *dev)
1376{
1377 struct smsc911x_data *pdata = netdev_priv(dev);
1378 unsigned long flags;
1379
1380 if (dev->flags & IFF_PROMISC) {
1381 /* Enabling promiscuous mode */
1382 pdata->set_bits_mask = MAC_CR_PRMS_;
1383 pdata->clear_bits_mask = (MAC_CR_MCPAS_ | MAC_CR_HPFILT_);
1384 pdata->hashhi = 0;
1385 pdata->hashlo = 0;
1386 } else if (dev->flags & IFF_ALLMULTI) {
1387 /* Enabling all multicast mode */
1388 pdata->set_bits_mask = MAC_CR_MCPAS_;
1389 pdata->clear_bits_mask = (MAC_CR_PRMS_ | MAC_CR_HPFILT_);
1390 pdata->hashhi = 0;
1391 pdata->hashlo = 0;
1392 } else if (dev->mc_count > 0) {
1393 /* Enabling specific multicast addresses */
1394 unsigned int hash_high = 0;
1395 unsigned int hash_low = 0;
1396 unsigned int count = 0;
1397 struct dev_mc_list *mc_list = dev->mc_list;
1398
1399 pdata->set_bits_mask = MAC_CR_HPFILT_;
1400 pdata->clear_bits_mask = (MAC_CR_PRMS_ | MAC_CR_MCPAS_);
1401
1402 while (mc_list) {
1403 count++;
1404 if ((mc_list->dmi_addrlen) == ETH_ALEN) {
1405 unsigned int bitnum =
1406 smsc911x_hash(mc_list->dmi_addr);
1407 unsigned int mask = 0x01 << (bitnum & 0x1F);
1408 if (bitnum & 0x20)
1409 hash_high |= mask;
1410 else
1411 hash_low |= mask;
1412 } else {
1413 SMSC_WARNING(DRV, "dmi_addrlen != 6");
1414 }
1415 mc_list = mc_list->next;
1416 }
1417 if (count != (unsigned int)dev->mc_count)
1418 SMSC_WARNING(DRV, "mc_count != dev->mc_count");
1419
1420 pdata->hashhi = hash_high;
1421 pdata->hashlo = hash_low;
1422 } else {
1423 /* Enabling local MAC address only */
1424 pdata->set_bits_mask = 0;
1425 pdata->clear_bits_mask =
1426 (MAC_CR_PRMS_ | MAC_CR_MCPAS_ | MAC_CR_HPFILT_);
1427 pdata->hashhi = 0;
1428 pdata->hashlo = 0;
1429 }
1430
1431 spin_lock_irqsave(&pdata->mac_lock, flags);
1432
1433 if (pdata->generation <= 1) {
1434 /* Older hardware revision - cannot change these flags while
1435 * receiving data */
1436 if (!pdata->multicast_update_pending) {
1437 unsigned int temp;
1438 SMSC_TRACE(HW, "scheduling mcast update");
1439 pdata->multicast_update_pending = 1;
1440
1441 /* Request the hardware to stop, then perform the
1442 * update when we get an RX_STOP interrupt */
1443 smsc911x_reg_write(pdata, INT_STS, INT_STS_RXSTOP_INT_);
1444 temp = smsc911x_reg_read(pdata, INT_EN);
1445 temp |= INT_EN_RXSTOP_INT_EN_;
1446 smsc911x_reg_write(pdata, INT_EN, temp);
1447
1448 temp = smsc911x_mac_read(pdata, MAC_CR);
1449 temp &= ~(MAC_CR_RXEN_);
1450 smsc911x_mac_write(pdata, MAC_CR, temp);
1451 } else {
1452 /* There is another update pending, this should now
1453 * use the newer values */
1454 }
1455 } else {
1456 /* Newer hardware revision - can write immediately */
1457 smsc911x_rx_multicast_update(pdata);
1458 }
1459
1460 spin_unlock_irqrestore(&pdata->mac_lock, flags);
1461}
1462
1463static irqreturn_t smsc911x_irqhandler(int irq, void *dev_id)
1464{
1465 struct net_device *dev = dev_id;
1466 struct smsc911x_data *pdata = netdev_priv(dev);
1467 u32 intsts = smsc911x_reg_read(pdata, INT_STS);
1468 u32 inten = smsc911x_reg_read(pdata, INT_EN);
1469 int serviced = IRQ_NONE;
1470 u32 temp;
1471
1472 if (unlikely(intsts & inten & INT_STS_SW_INT_)) {
1473 temp = smsc911x_reg_read(pdata, INT_EN);
1474 temp &= (~INT_EN_SW_INT_EN_);
1475 smsc911x_reg_write(pdata, INT_EN, temp);
1476 smsc911x_reg_write(pdata, INT_STS, INT_STS_SW_INT_);
1477 pdata->software_irq_signal = 1;
1478 smp_wmb();
1479 serviced = IRQ_HANDLED;
1480 }
1481
1482 if (unlikely(intsts & inten & INT_STS_RXSTOP_INT_)) {
1483 /* Called when there is a multicast update scheduled and
1484 * it is now safe to complete the update */
1485 SMSC_TRACE(INTR, "RX Stop interrupt");
1486 temp = smsc911x_reg_read(pdata, INT_EN);
1487 temp &= (~INT_EN_RXSTOP_INT_EN_);
1488 smsc911x_reg_write(pdata, INT_EN, temp);
1489 smsc911x_reg_write(pdata, INT_STS, INT_STS_RXSTOP_INT_);
1490 smsc911x_rx_multicast_update_workaround(pdata);
1491 serviced = IRQ_HANDLED;
1492 }
1493
1494 if (intsts & inten & INT_STS_TDFA_) {
1495 temp = smsc911x_reg_read(pdata, FIFO_INT);
1496 temp |= FIFO_INT_TX_AVAIL_LEVEL_;
1497 smsc911x_reg_write(pdata, FIFO_INT, temp);
1498 smsc911x_reg_write(pdata, INT_STS, INT_STS_TDFA_);
1499 netif_wake_queue(dev);
1500 serviced = IRQ_HANDLED;
1501 }
1502
1503 if (unlikely(intsts & inten & INT_STS_RXE_)) {
1504 SMSC_TRACE(INTR, "RX Error interrupt");
1505 smsc911x_reg_write(pdata, INT_STS, INT_STS_RXE_);
1506 serviced = IRQ_HANDLED;
1507 }
1508
1509 if (likely(intsts & inten & INT_STS_RSFL_)) {
1510 if (likely(netif_rx_schedule_prep(dev, &pdata->napi))) {
1511 /* Disable Rx interrupts */
1512 temp = smsc911x_reg_read(pdata, INT_EN);
1513 temp &= (~INT_EN_RSFL_EN_);
1514 smsc911x_reg_write(pdata, INT_EN, temp);
1515 /* Schedule a NAPI poll */
1516 __netif_rx_schedule(dev, &pdata->napi);
1517 } else {
1518 SMSC_WARNING(RX_ERR,
1519 "netif_rx_schedule_prep failed");
1520 }
1521 serviced = IRQ_HANDLED;
1522 }
1523
1524 return serviced;
1525}
1526
1527#ifdef CONFIG_NET_POLL_CONTROLLER
1528void smsc911x_poll_controller(struct net_device *dev)
1529{
1530 disable_irq(dev->irq);
1531 smsc911x_irqhandler(0, dev);
1532 enable_irq(dev->irq);
1533}
1534#endif /* CONFIG_NET_POLL_CONTROLLER */
1535
1536/* Standard ioctls for mii-tool */
1537static int smsc911x_do_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
1538{
1539 struct smsc911x_data *pdata = netdev_priv(dev);
1540
1541 if (!netif_running(dev) || !pdata->phy_dev)
1542 return -EINVAL;
1543
1544 return phy_mii_ioctl(pdata->phy_dev, if_mii(ifr), cmd);
1545}
1546
1547static int
1548smsc911x_ethtool_getsettings(struct net_device *dev, struct ethtool_cmd *cmd)
1549{
1550 struct smsc911x_data *pdata = netdev_priv(dev);
1551
1552 cmd->maxtxpkt = 1;
1553 cmd->maxrxpkt = 1;
1554 return phy_ethtool_gset(pdata->phy_dev, cmd);
1555}
1556
1557static int
1558smsc911x_ethtool_setsettings(struct net_device *dev, struct ethtool_cmd *cmd)
1559{
1560 struct smsc911x_data *pdata = netdev_priv(dev);
1561
1562 return phy_ethtool_sset(pdata->phy_dev, cmd);
1563}
1564
1565static void smsc911x_ethtool_getdrvinfo(struct net_device *dev,
1566 struct ethtool_drvinfo *info)
1567{
1568 strlcpy(info->driver, SMSC_CHIPNAME, sizeof(info->driver));
1569 strlcpy(info->version, SMSC_DRV_VERSION, sizeof(info->version));
1570 strlcpy(info->bus_info, dev->dev.parent->bus_id,
1571 sizeof(info->bus_info));
1572}
1573
1574static int smsc911x_ethtool_nwayreset(struct net_device *dev)
1575{
1576 struct smsc911x_data *pdata = netdev_priv(dev);
1577
1578 return phy_start_aneg(pdata->phy_dev);
1579}
1580
1581static u32 smsc911x_ethtool_getmsglevel(struct net_device *dev)
1582{
1583 struct smsc911x_data *pdata = netdev_priv(dev);
1584 return pdata->msg_enable;
1585}
1586
1587static void smsc911x_ethtool_setmsglevel(struct net_device *dev, u32 level)
1588{
1589 struct smsc911x_data *pdata = netdev_priv(dev);
1590 pdata->msg_enable = level;
1591}
1592
1593static int smsc911x_ethtool_getregslen(struct net_device *dev)
1594{
1595 return (((E2P_DATA - ID_REV) / 4 + 1) + (WUCSR - MAC_CR) + 1 + 32) *
1596 sizeof(u32);
1597}
1598
1599static void
1600smsc911x_ethtool_getregs(struct net_device *dev, struct ethtool_regs *regs,
1601 void *buf)
1602{
1603 struct smsc911x_data *pdata = netdev_priv(dev);
1604 struct phy_device *phy_dev = pdata->phy_dev;
1605 unsigned long flags;
1606 unsigned int i;
1607 unsigned int j = 0;
1608 u32 *data = buf;
1609
1610 regs->version = pdata->idrev;
1611 for (i = ID_REV; i <= E2P_DATA; i += (sizeof(u32)))
1612 data[j++] = smsc911x_reg_read(pdata, i);
1613
1614 for (i = MAC_CR; i <= WUCSR; i++) {
1615 spin_lock_irqsave(&pdata->mac_lock, flags);
1616 data[j++] = smsc911x_mac_read(pdata, i);
1617 spin_unlock_irqrestore(&pdata->mac_lock, flags);
1618 }
1619
1620 for (i = 0; i <= 31; i++)
1621 data[j++] = smsc911x_mii_read(phy_dev->bus, phy_dev->addr, i);
1622}
1623
1624static void smsc911x_eeprom_enable_access(struct smsc911x_data *pdata)
1625{
1626 unsigned int temp = smsc911x_reg_read(pdata, GPIO_CFG);
1627 temp &= ~GPIO_CFG_EEPR_EN_;
1628 smsc911x_reg_write(pdata, GPIO_CFG, temp);
1629 msleep(1);
1630}
1631
1632static int smsc911x_eeprom_send_cmd(struct smsc911x_data *pdata, u32 op)
1633{
1634 int timeout = 100;
1635 u32 e2cmd;
1636
1637 SMSC_TRACE(DRV, "op 0x%08x", op);
1638 if (smsc911x_reg_read(pdata, E2P_CMD) & E2P_CMD_EPC_BUSY_) {
1639 SMSC_WARNING(DRV, "Busy at start");
1640 return -EBUSY;
1641 }
1642
1643 e2cmd = op | E2P_CMD_EPC_BUSY_;
1644 smsc911x_reg_write(pdata, E2P_CMD, e2cmd);
1645
1646 do {
1647 msleep(1);
1648 e2cmd = smsc911x_reg_read(pdata, E2P_CMD);
1649 } while ((e2cmd & E2P_CMD_EPC_BUSY_) && (timeout--));
1650
1651 if (!timeout) {
1652 SMSC_TRACE(DRV, "TIMED OUT");
1653 return -EAGAIN;
1654 }
1655
1656 if (e2cmd & E2P_CMD_EPC_TIMEOUT_) {
1657 SMSC_TRACE(DRV, "Error occured during eeprom operation");
1658 return -EINVAL;
1659 }
1660
1661 return 0;
1662}
1663
1664static int smsc911x_eeprom_read_location(struct smsc911x_data *pdata,
1665 u8 address, u8 *data)
1666{
1667 u32 op = E2P_CMD_EPC_CMD_READ_ | address;
1668 int ret;
1669
1670 SMSC_TRACE(DRV, "address 0x%x", address);
1671 ret = smsc911x_eeprom_send_cmd(pdata, op);
1672
1673 if (!ret)
1674 data[address] = smsc911x_reg_read(pdata, E2P_DATA);
1675
1676 return ret;
1677}
1678
1679static int smsc911x_eeprom_write_location(struct smsc911x_data *pdata,
1680 u8 address, u8 data)
1681{
1682 u32 op = E2P_CMD_EPC_CMD_ERASE_ | address;
1683 int ret;
1684
1685 SMSC_TRACE(DRV, "address 0x%x, data 0x%x", address, data);
1686 ret = smsc911x_eeprom_send_cmd(pdata, op);
1687
1688 if (!ret) {
1689 op = E2P_CMD_EPC_CMD_WRITE_ | address;
1690 smsc911x_reg_write(pdata, E2P_DATA, (u32)data);
1691 ret = smsc911x_eeprom_send_cmd(pdata, op);
1692 }
1693
1694 return ret;
1695}
1696
1697static int smsc911x_ethtool_get_eeprom_len(struct net_device *dev)
1698{
1699 return SMSC911X_EEPROM_SIZE;
1700}
1701
1702static int smsc911x_ethtool_get_eeprom(struct net_device *dev,
1703 struct ethtool_eeprom *eeprom, u8 *data)
1704{
1705 struct smsc911x_data *pdata = netdev_priv(dev);
1706 u8 eeprom_data[SMSC911X_EEPROM_SIZE];
1707 int len;
1708 int i;
1709
1710 smsc911x_eeprom_enable_access(pdata);
1711
1712 len = min(eeprom->len, SMSC911X_EEPROM_SIZE);
1713 for (i = 0; i < len; i++) {
1714 int ret = smsc911x_eeprom_read_location(pdata, i, eeprom_data);
1715 if (ret < 0) {
1716 eeprom->len = 0;
1717 return ret;
1718 }
1719 }
1720
1721 memcpy(data, &eeprom_data[eeprom->offset], len);
1722 eeprom->len = len;
1723 return 0;
1724}
1725
1726static int smsc911x_ethtool_set_eeprom(struct net_device *dev,
1727 struct ethtool_eeprom *eeprom, u8 *data)
1728{
1729 int ret;
1730 struct smsc911x_data *pdata = netdev_priv(dev);
1731
1732 smsc911x_eeprom_enable_access(pdata);
1733 smsc911x_eeprom_send_cmd(pdata, E2P_CMD_EPC_CMD_EWEN_);
1734 ret = smsc911x_eeprom_write_location(pdata, eeprom->offset, *data);
1735 smsc911x_eeprom_send_cmd(pdata, E2P_CMD_EPC_CMD_EWDS_);
1736
1737 /* Single byte write, according to man page */
1738 eeprom->len = 1;
1739
1740 return ret;
1741}
1742
1743static struct ethtool_ops smsc911x_ethtool_ops = {
1744 .get_settings = smsc911x_ethtool_getsettings,
1745 .set_settings = smsc911x_ethtool_setsettings,
1746 .get_link = ethtool_op_get_link,
1747 .get_drvinfo = smsc911x_ethtool_getdrvinfo,
1748 .nway_reset = smsc911x_ethtool_nwayreset,
1749 .get_msglevel = smsc911x_ethtool_getmsglevel,
1750 .set_msglevel = smsc911x_ethtool_setmsglevel,
1751 .get_regs_len = smsc911x_ethtool_getregslen,
1752 .get_regs = smsc911x_ethtool_getregs,
1753 .get_eeprom_len = smsc911x_ethtool_get_eeprom_len,
1754 .get_eeprom = smsc911x_ethtool_get_eeprom,
1755 .set_eeprom = smsc911x_ethtool_set_eeprom,
1756};
1757
1758/* Initializing private device structures, only called from probe */
1759static int __devinit smsc911x_init(struct net_device *dev)
1760{
1761 struct smsc911x_data *pdata = netdev_priv(dev);
1762 unsigned int byte_test;
1763
1764 SMSC_TRACE(PROBE, "Driver Parameters:");
1765 SMSC_TRACE(PROBE, "LAN base: 0x%08lX",
1766 (unsigned long)pdata->ioaddr);
1767 SMSC_TRACE(PROBE, "IRQ: %d", dev->irq);
1768 SMSC_TRACE(PROBE, "PHY will be autodetected.");
1769
1770#if (!SMSC_CAN_USE_32BIT)
1771 spin_lock_init(&pdata->dev_lock);
1772#endif
1773
1774 if (pdata->ioaddr == 0) {
1775 SMSC_WARNING(PROBE, "pdata->ioaddr: 0x00000000");
1776 return -ENODEV;
1777 }
1778
1779 /* Check byte ordering */
1780 byte_test = smsc911x_reg_read(pdata, BYTE_TEST);
1781 SMSC_TRACE(PROBE, "BYTE_TEST: 0x%08X", byte_test);
1782 if (byte_test == 0x43218765) {
1783 SMSC_TRACE(PROBE, "BYTE_TEST looks swapped, "
1784 "applying WORD_SWAP");
1785 smsc911x_reg_write(pdata, WORD_SWAP, 0xffffffff);
1786
1787 /* 1 dummy read of BYTE_TEST is needed after a write to
1788 * WORD_SWAP before its contents are valid */
1789 byte_test = smsc911x_reg_read(pdata, BYTE_TEST);
1790
1791 byte_test = smsc911x_reg_read(pdata, BYTE_TEST);
1792 }
1793
1794 if (byte_test != 0x87654321) {
1795 SMSC_WARNING(DRV, "BYTE_TEST: 0x%08X", byte_test);
1796 if (((byte_test >> 16) & 0xFFFF) == (byte_test & 0xFFFF)) {
1797 SMSC_WARNING(PROBE,
1798 "top 16 bits equal to bottom 16 bits");
1799 SMSC_TRACE(PROBE, "This may mean the chip is set "
1800 "for 32 bit while the bus is reading 16 bit");
1801 }
1802 return -ENODEV;
1803 }
1804
1805 /* Default generation to zero (all workarounds apply) */
1806 pdata->generation = 0;
1807
1808 pdata->idrev = smsc911x_reg_read(pdata, ID_REV);
1809 switch (pdata->idrev & 0xFFFF0000) {
1810 case 0x01180000:
1811 case 0x01170000:
1812 case 0x01160000:
1813 case 0x01150000:
1814 /* LAN911[5678] family */
1815 pdata->generation = pdata->idrev & 0x0000FFFF;
1816 break;
1817
1818 case 0x118A0000:
1819 case 0x117A0000:
1820 case 0x116A0000:
1821 case 0x115A0000:
1822 /* LAN921[5678] family */
1823 pdata->generation = 3;
1824 break;
1825
1826 case 0x92100000:
1827 case 0x92110000:
1828 case 0x92200000:
1829 case 0x92210000:
1830 /* LAN9210/LAN9211/LAN9220/LAN9221 */
1831 pdata->generation = 4;
1832 break;
1833
1834 default:
1835 SMSC_WARNING(PROBE, "LAN911x not identified, idrev: 0x%08X",
1836 pdata->idrev);
1837 return -ENODEV;
1838 }
1839
1840 SMSC_TRACE(PROBE, "LAN911x identified, idrev: 0x%08X, generation: %d",
1841 pdata->idrev, pdata->generation);
1842
1843 if (pdata->generation == 0)
1844 SMSC_WARNING(PROBE,
1845 "This driver is not intended for this chip revision");
1846
1847 /* Reset the LAN911x */
1848 if (smsc911x_soft_reset(pdata))
1849 return -ENODEV;
1850
1851 /* Disable all interrupt sources until we bring the device up */
1852 smsc911x_reg_write(pdata, INT_EN, 0);
1853
1854 ether_setup(dev);
1855 dev->open = smsc911x_open;
1856 dev->stop = smsc911x_stop;
1857 dev->hard_start_xmit = smsc911x_hard_start_xmit;
1858 dev->get_stats = smsc911x_get_stats;
1859 dev->set_multicast_list = smsc911x_set_multicast_list;
1860 dev->flags |= IFF_MULTICAST;
1861 dev->do_ioctl = smsc911x_do_ioctl;
1862 netif_napi_add(dev, &pdata->napi, smsc911x_poll, SMSC_NAPI_WEIGHT);
1863 dev->ethtool_ops = &smsc911x_ethtool_ops;
1864
1865#ifdef CONFIG_NET_POLL_CONTROLLER
1866 dev->poll_controller = smsc911x_poll_controller;
1867#endif /* CONFIG_NET_POLL_CONTROLLER */
1868
1869 return 0;
1870}
1871
1872static int __devexit smsc911x_drv_remove(struct platform_device *pdev)
1873{
1874 struct net_device *dev;
1875 struct smsc911x_data *pdata;
1876 struct resource *res;
1877
1878 dev = platform_get_drvdata(pdev);
1879 BUG_ON(!dev);
1880 pdata = netdev_priv(dev);
1881 BUG_ON(!pdata);
1882 BUG_ON(!pdata->ioaddr);
1883 BUG_ON(!pdata->phy_dev);
1884
1885 SMSC_TRACE(IFDOWN, "Stopping driver.");
1886
1887 phy_disconnect(pdata->phy_dev);
1888 pdata->phy_dev = NULL;
1889 mdiobus_unregister(pdata->mii_bus);
1890 mdiobus_free(pdata->mii_bus);
1891
1892 platform_set_drvdata(pdev, NULL);
1893 unregister_netdev(dev);
1894 free_irq(dev->irq, dev);
1895 res = platform_get_resource_byname(pdev, IORESOURCE_MEM,
1896 "smsc911x-memory");
1897 if (!res)
1898 platform_get_resource(pdev, IORESOURCE_MEM, 0);
1899
1900 release_mem_region(res->start, res->end - res->start);
1901
1902 iounmap(pdata->ioaddr);
1903
1904 free_netdev(dev);
1905
1906 return 0;
1907}
1908
1909static int __devinit smsc911x_drv_probe(struct platform_device *pdev)
1910{
1911 struct net_device *dev;
1912 struct smsc911x_data *pdata;
1913 struct resource *res;
1914 unsigned int intcfg = 0;
1915 int res_size;
1916 int retval;
1917 DECLARE_MAC_BUF(mac);
1918
1919 pr_info("%s: Driver version %s.\n", SMSC_CHIPNAME, SMSC_DRV_VERSION);
1920
1921 res = platform_get_resource_byname(pdev, IORESOURCE_MEM,
1922 "smsc911x-memory");
1923 if (!res)
1924 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
1925 if (!res) {
1926 pr_warning("%s: Could not allocate resource.\n",
1927 SMSC_CHIPNAME);
1928 retval = -ENODEV;
1929 goto out_0;
1930 }
1931 res_size = res->end - res->start;
1932
1933 if (!request_mem_region(res->start, res_size, SMSC_CHIPNAME)) {
1934 retval = -EBUSY;
1935 goto out_0;
1936 }
1937
1938 dev = alloc_etherdev(sizeof(struct smsc911x_data));
1939 if (!dev) {
1940 pr_warning("%s: Could not allocate device.\n", SMSC_CHIPNAME);
1941 retval = -ENOMEM;
1942 goto out_release_io_1;
1943 }
1944
1945 SET_NETDEV_DEV(dev, &pdev->dev);
1946
1947 pdata = netdev_priv(dev);
1948
1949 dev->irq = platform_get_irq(pdev, 0);
1950 pdata->ioaddr = ioremap_nocache(res->start, res_size);
1951
1952 /* copy config parameters across if present, otherwise pdata
1953 * defaults to zeros */
1954 if (pdev->dev.platform_data) {
1955 struct smsc911x_platform_config *config =
1956 pdev->dev.platform_data;
1957 pdata->irq_polarity = config->irq_polarity;
1958 pdata->irq_type = config->irq_type;
1959 pdata->phy_interface = config->phy_interface;
1960 }
1961
1962 pdata->dev = dev;
1963 pdata->msg_enable = ((1 << debug) - 1);
1964
1965 if (pdata->ioaddr == NULL) {
1966 SMSC_WARNING(PROBE,
1967 "Error smsc911x base address invalid");
1968 retval = -ENOMEM;
1969 goto out_free_netdev_2;
1970 }
1971
1972 retval = smsc911x_init(dev);
1973 if (retval < 0)
1974 goto out_unmap_io_3;
1975
1976 /* configure irq polarity and type before connecting isr */
1977 if (pdata->irq_polarity == SMSC911X_IRQ_POLARITY_ACTIVE_HIGH)
1978 intcfg |= INT_CFG_IRQ_POL_;
1979
1980 if (pdata->irq_type == SMSC911X_IRQ_TYPE_PUSH_PULL)
1981 intcfg |= INT_CFG_IRQ_TYPE_;
1982
1983 smsc911x_reg_write(pdata, INT_CFG, intcfg);
1984
1985 /* Ensure interrupts are globally disabled before connecting ISR */
1986 smsc911x_reg_write(pdata, INT_EN, 0);
1987 smsc911x_reg_write(pdata, INT_STS, 0xFFFFFFFF);
1988
1989 retval = request_irq(dev->irq, smsc911x_irqhandler, IRQF_DISABLED,
1990 SMSC_CHIPNAME, dev);
1991 if (retval) {
1992 SMSC_WARNING(PROBE,
1993 "Unable to claim requested irq: %d", dev->irq);
1994 goto out_unmap_io_3;
1995 }
1996
1997 platform_set_drvdata(pdev, dev);
1998
1999 retval = register_netdev(dev);
2000 if (retval) {
2001 SMSC_WARNING(PROBE,
2002 "Error %i registering device", retval);
2003 goto out_unset_drvdata_4;
2004 } else {
2005 SMSC_TRACE(PROBE, "Network interface: \"%s\"", dev->name);
2006 }
2007
2008 spin_lock_init(&pdata->mac_lock);
2009
2010 retval = smsc911x_mii_init(pdev, dev);
2011 if (retval) {
2012 SMSC_WARNING(PROBE,
2013 "Error %i initialising mii", retval);
2014 goto out_unregister_netdev_5;
2015 }
2016
2017 spin_lock_irq(&pdata->mac_lock);
2018
2019 /* Check if mac address has been specified when bringing interface up */
2020 if (is_valid_ether_addr(dev->dev_addr)) {
2021 smsc911x_set_mac_address(pdata, dev->dev_addr);
2022 SMSC_TRACE(PROBE, "MAC Address is specified by configuration");
2023 } else {
2024 /* Try reading mac address from device. if EEPROM is present
2025 * it will already have been set */
2026 u32 mac_high16 = smsc911x_mac_read(pdata, ADDRH);
2027 u32 mac_low32 = smsc911x_mac_read(pdata, ADDRL);
2028 dev->dev_addr[0] = (u8)(mac_low32);
2029 dev->dev_addr[1] = (u8)(mac_low32 >> 8);
2030 dev->dev_addr[2] = (u8)(mac_low32 >> 16);
2031 dev->dev_addr[3] = (u8)(mac_low32 >> 24);
2032 dev->dev_addr[4] = (u8)(mac_high16);
2033 dev->dev_addr[5] = (u8)(mac_high16 >> 8);
2034
2035 if (is_valid_ether_addr(dev->dev_addr)) {
2036 /* eeprom values are valid so use them */
2037 SMSC_TRACE(PROBE,
2038 "Mac Address is read from LAN911x EEPROM");
2039 } else {
2040 /* eeprom values are invalid, generate random MAC */
2041 random_ether_addr(dev->dev_addr);
2042 smsc911x_set_mac_address(pdata, dev->dev_addr);
2043 SMSC_TRACE(PROBE,
2044 "MAC Address is set to random_ether_addr");
2045 }
2046 }
2047
2048 spin_unlock_irq(&pdata->mac_lock);
2049
2050 dev_info(&dev->dev, "MAC Address: %s\n",
2051 print_mac(mac, dev->dev_addr));
2052
2053 return 0;
2054
2055out_unregister_netdev_5:
2056 unregister_netdev(dev);
2057out_unset_drvdata_4:
2058 platform_set_drvdata(pdev, NULL);
2059 free_irq(dev->irq, dev);
2060out_unmap_io_3:
2061 iounmap(pdata->ioaddr);
2062out_free_netdev_2:
2063 free_netdev(dev);
2064out_release_io_1:
2065 release_mem_region(res->start, res->end - res->start);
2066out_0:
2067 return retval;
2068}
2069
2070static struct platform_driver smsc911x_driver = {
2071 .probe = smsc911x_drv_probe,
2072 .remove = smsc911x_drv_remove,
2073 .driver = {
2074 .name = SMSC_CHIPNAME,
2075 },
2076};
2077
2078/* Entry point for loading the module */
2079static int __init smsc911x_init_module(void)
2080{
2081 return platform_driver_register(&smsc911x_driver);
2082}
2083
2084/* entry point for unloading the module */
2085static void __exit smsc911x_cleanup_module(void)
2086{
2087 platform_driver_unregister(&smsc911x_driver);
2088}
2089
2090module_init(smsc911x_init_module);
2091module_exit(smsc911x_cleanup_module);
diff --git a/drivers/net/smsc911x.h b/drivers/net/smsc911x.h
new file mode 100644
index 000000000000..feb36de274ca
--- /dev/null
+++ b/drivers/net/smsc911x.h
@@ -0,0 +1,394 @@
1/***************************************************************************
2 *
3 * Copyright (C) 2004-2008 SMSC
4 * Copyright (C) 2005-2008 ARM
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19 *
20 ***************************************************************************/
21#ifndef __SMSC911X_H__
22#define __SMSC911X_H__
23
24#define SMSC_CAN_USE_32BIT 1
25#define TX_FIFO_LOW_THRESHOLD ((u32)1600)
26#define SMSC911X_EEPROM_SIZE ((u32)7)
27#define USE_DEBUG 0
28
29/* This is the maximum number of packets to be received every
30 * NAPI poll */
31#define SMSC_NAPI_WEIGHT 16
32
33/* implements a PHY loopback test at initialisation time, to ensure a packet
34 * can be succesfully looped back */
35#define USE_PHY_WORK_AROUND
36
37#define DPRINTK(nlevel, klevel, fmt, args...) \
38 ((void)((NETIF_MSG_##nlevel & pdata->msg_enable) && \
39 printk(KERN_##klevel "%s: %s: " fmt "\n", \
40 pdata->dev->name, __func__, ## args)))
41
42#if USE_DEBUG >= 1
43#define SMSC_WARNING(nlevel, fmt, args...) \
44 DPRINTK(nlevel, WARNING, fmt, ## args)
45#else
46#define SMSC_WARNING(nlevel, fmt, args...) \
47 ({ do {} while (0); 0; })
48#endif
49
50#if USE_DEBUG >= 2
51#define SMSC_TRACE(nlevel, fmt, args...) \
52 DPRINTK(nlevel, INFO, fmt, ## args)
53#else
54#define SMSC_TRACE(nlevel, fmt, args...) \
55 ({ do {} while (0); 0; })
56#endif
57
58#ifdef CONFIG_DEBUG_SPINLOCK
59#define SMSC_ASSERT_MAC_LOCK(pdata) \
60 WARN_ON(!spin_is_locked(&pdata->mac_lock))
61#else
62#define SMSC_ASSERT_MAC_LOCK(pdata) do {} while (0)
63#endif /* CONFIG_DEBUG_SPINLOCK */
64
65#define FLOW_CTRL_TX (1)
66#define FLOW_CTRL_RX (2)
67
68/* SMSC911x registers and bitfields */
69#define RX_DATA_FIFO 0x00
70
71#define TX_DATA_FIFO 0x20
72#define TX_CMD_A_ON_COMP_ 0x80000000
73#define TX_CMD_A_BUF_END_ALGN_ 0x03000000
74#define TX_CMD_A_4_BYTE_ALGN_ 0x00000000
75#define TX_CMD_A_16_BYTE_ALGN_ 0x01000000
76#define TX_CMD_A_32_BYTE_ALGN_ 0x02000000
77#define TX_CMD_A_DATA_OFFSET_ 0x001F0000
78#define TX_CMD_A_FIRST_SEG_ 0x00002000
79#define TX_CMD_A_LAST_SEG_ 0x00001000
80#define TX_CMD_A_BUF_SIZE_ 0x000007FF
81#define TX_CMD_B_PKT_TAG_ 0xFFFF0000
82#define TX_CMD_B_ADD_CRC_DISABLE_ 0x00002000
83#define TX_CMD_B_DISABLE_PADDING_ 0x00001000
84#define TX_CMD_B_PKT_BYTE_LENGTH_ 0x000007FF
85
86#define RX_STATUS_FIFO 0x40
87#define RX_STS_ES_ 0x00008000
88#define RX_STS_MCAST_ 0x00000400
89
90#define RX_STATUS_FIFO_PEEK 0x44
91
92#define TX_STATUS_FIFO 0x48
93#define TX_STS_ES_ 0x00008000
94
95#define TX_STATUS_FIFO_PEEK 0x4C
96
97#define ID_REV 0x50
98#define ID_REV_CHIP_ID_ 0xFFFF0000
99#define ID_REV_REV_ID_ 0x0000FFFF
100
101#define INT_CFG 0x54
102#define INT_CFG_INT_DEAS_ 0xFF000000
103#define INT_CFG_INT_DEAS_CLR_ 0x00004000
104#define INT_CFG_INT_DEAS_STS_ 0x00002000
105#define INT_CFG_IRQ_INT_ 0x00001000
106#define INT_CFG_IRQ_EN_ 0x00000100
107#define INT_CFG_IRQ_POL_ 0x00000010
108#define INT_CFG_IRQ_TYPE_ 0x00000001
109
110#define INT_STS 0x58
111#define INT_STS_SW_INT_ 0x80000000
112#define INT_STS_TXSTOP_INT_ 0x02000000
113#define INT_STS_RXSTOP_INT_ 0x01000000
114#define INT_STS_RXDFH_INT_ 0x00800000
115#define INT_STS_RXDF_INT_ 0x00400000
116#define INT_STS_TX_IOC_ 0x00200000
117#define INT_STS_RXD_INT_ 0x00100000
118#define INT_STS_GPT_INT_ 0x00080000
119#define INT_STS_PHY_INT_ 0x00040000
120#define INT_STS_PME_INT_ 0x00020000
121#define INT_STS_TXSO_ 0x00010000
122#define INT_STS_RWT_ 0x00008000
123#define INT_STS_RXE_ 0x00004000
124#define INT_STS_TXE_ 0x00002000
125#define INT_STS_TDFU_ 0x00000800
126#define INT_STS_TDFO_ 0x00000400
127#define INT_STS_TDFA_ 0x00000200
128#define INT_STS_TSFF_ 0x00000100
129#define INT_STS_TSFL_ 0x00000080
130#define INT_STS_RXDF_ 0x00000040
131#define INT_STS_RDFL_ 0x00000020
132#define INT_STS_RSFF_ 0x00000010
133#define INT_STS_RSFL_ 0x00000008
134#define INT_STS_GPIO2_INT_ 0x00000004
135#define INT_STS_GPIO1_INT_ 0x00000002
136#define INT_STS_GPIO0_INT_ 0x00000001
137
138#define INT_EN 0x5C
139#define INT_EN_SW_INT_EN_ 0x80000000
140#define INT_EN_TXSTOP_INT_EN_ 0x02000000
141#define INT_EN_RXSTOP_INT_EN_ 0x01000000
142#define INT_EN_RXDFH_INT_EN_ 0x00800000
143#define INT_EN_TIOC_INT_EN_ 0x00200000
144#define INT_EN_RXD_INT_EN_ 0x00100000
145#define INT_EN_GPT_INT_EN_ 0x00080000
146#define INT_EN_PHY_INT_EN_ 0x00040000
147#define INT_EN_PME_INT_EN_ 0x00020000
148#define INT_EN_TXSO_EN_ 0x00010000
149#define INT_EN_RWT_EN_ 0x00008000
150#define INT_EN_RXE_EN_ 0x00004000
151#define INT_EN_TXE_EN_ 0x00002000
152#define INT_EN_TDFU_EN_ 0x00000800
153#define INT_EN_TDFO_EN_ 0x00000400
154#define INT_EN_TDFA_EN_ 0x00000200
155#define INT_EN_TSFF_EN_ 0x00000100
156#define INT_EN_TSFL_EN_ 0x00000080
157#define INT_EN_RXDF_EN_ 0x00000040
158#define INT_EN_RDFL_EN_ 0x00000020
159#define INT_EN_RSFF_EN_ 0x00000010
160#define INT_EN_RSFL_EN_ 0x00000008
161#define INT_EN_GPIO2_INT_ 0x00000004
162#define INT_EN_GPIO1_INT_ 0x00000002
163#define INT_EN_GPIO0_INT_ 0x00000001
164
165#define BYTE_TEST 0x64
166
167#define FIFO_INT 0x68
168#define FIFO_INT_TX_AVAIL_LEVEL_ 0xFF000000
169#define FIFO_INT_TX_STS_LEVEL_ 0x00FF0000
170#define FIFO_INT_RX_AVAIL_LEVEL_ 0x0000FF00
171#define FIFO_INT_RX_STS_LEVEL_ 0x000000FF
172
173#define RX_CFG 0x6C
174#define RX_CFG_RX_END_ALGN_ 0xC0000000
175#define RX_CFG_RX_END_ALGN4_ 0x00000000
176#define RX_CFG_RX_END_ALGN16_ 0x40000000
177#define RX_CFG_RX_END_ALGN32_ 0x80000000
178#define RX_CFG_RX_DMA_CNT_ 0x0FFF0000
179#define RX_CFG_RX_DUMP_ 0x00008000
180#define RX_CFG_RXDOFF_ 0x00001F00
181
182#define TX_CFG 0x70
183#define TX_CFG_TXS_DUMP_ 0x00008000
184#define TX_CFG_TXD_DUMP_ 0x00004000
185#define TX_CFG_TXSAO_ 0x00000004
186#define TX_CFG_TX_ON_ 0x00000002
187#define TX_CFG_STOP_TX_ 0x00000001
188
189#define HW_CFG 0x74
190#define HW_CFG_TTM_ 0x00200000
191#define HW_CFG_SF_ 0x00100000
192#define HW_CFG_TX_FIF_SZ_ 0x000F0000
193#define HW_CFG_TR_ 0x00003000
194#define HW_CFG_SRST_ 0x00000001
195
196/* only available on 115/117 */
197#define HW_CFG_PHY_CLK_SEL_ 0x00000060
198#define HW_CFG_PHY_CLK_SEL_INT_PHY_ 0x00000000
199#define HW_CFG_PHY_CLK_SEL_EXT_PHY_ 0x00000020
200#define HW_CFG_PHY_CLK_SEL_CLK_DIS_ 0x00000040
201#define HW_CFG_SMI_SEL_ 0x00000010
202#define HW_CFG_EXT_PHY_DET_ 0x00000008
203#define HW_CFG_EXT_PHY_EN_ 0x00000004
204#define HW_CFG_SRST_TO_ 0x00000002
205
206/* only available on 116/118 */
207#define HW_CFG_32_16_BIT_MODE_ 0x00000004
208
209#define RX_DP_CTRL 0x78
210#define RX_DP_CTRL_RX_FFWD_ 0x80000000
211
212#define RX_FIFO_INF 0x7C
213#define RX_FIFO_INF_RXSUSED_ 0x00FF0000
214#define RX_FIFO_INF_RXDUSED_ 0x0000FFFF
215
216#define TX_FIFO_INF 0x80
217#define TX_FIFO_INF_TSUSED_ 0x00FF0000
218#define TX_FIFO_INF_TDFREE_ 0x0000FFFF
219
220#define PMT_CTRL 0x84
221#define PMT_CTRL_PM_MODE_ 0x00003000
222#define PMT_CTRL_PM_MODE_D0_ 0x00000000
223#define PMT_CTRL_PM_MODE_D1_ 0x00001000
224#define PMT_CTRL_PM_MODE_D2_ 0x00002000
225#define PMT_CTRL_PM_MODE_D3_ 0x00003000
226#define PMT_CTRL_PHY_RST_ 0x00000400
227#define PMT_CTRL_WOL_EN_ 0x00000200
228#define PMT_CTRL_ED_EN_ 0x00000100
229#define PMT_CTRL_PME_TYPE_ 0x00000040
230#define PMT_CTRL_WUPS_ 0x00000030
231#define PMT_CTRL_WUPS_NOWAKE_ 0x00000000
232#define PMT_CTRL_WUPS_ED_ 0x00000010
233#define PMT_CTRL_WUPS_WOL_ 0x00000020
234#define PMT_CTRL_WUPS_MULTI_ 0x00000030
235#define PMT_CTRL_PME_IND_ 0x00000008
236#define PMT_CTRL_PME_POL_ 0x00000004
237#define PMT_CTRL_PME_EN_ 0x00000002
238#define PMT_CTRL_READY_ 0x00000001
239
240#define GPIO_CFG 0x88
241#define GPIO_CFG_LED3_EN_ 0x40000000
242#define GPIO_CFG_LED2_EN_ 0x20000000
243#define GPIO_CFG_LED1_EN_ 0x10000000
244#define GPIO_CFG_GPIO2_INT_POL_ 0x04000000
245#define GPIO_CFG_GPIO1_INT_POL_ 0x02000000
246#define GPIO_CFG_GPIO0_INT_POL_ 0x01000000
247#define GPIO_CFG_EEPR_EN_ 0x00700000
248#define GPIO_CFG_GPIOBUF2_ 0x00040000
249#define GPIO_CFG_GPIOBUF1_ 0x00020000
250#define GPIO_CFG_GPIOBUF0_ 0x00010000
251#define GPIO_CFG_GPIODIR2_ 0x00000400
252#define GPIO_CFG_GPIODIR1_ 0x00000200
253#define GPIO_CFG_GPIODIR0_ 0x00000100
254#define GPIO_CFG_GPIOD4_ 0x00000020
255#define GPIO_CFG_GPIOD3_ 0x00000010
256#define GPIO_CFG_GPIOD2_ 0x00000004
257#define GPIO_CFG_GPIOD1_ 0x00000002
258#define GPIO_CFG_GPIOD0_ 0x00000001
259
260#define GPT_CFG 0x8C
261#define GPT_CFG_TIMER_EN_ 0x20000000
262#define GPT_CFG_GPT_LOAD_ 0x0000FFFF
263
264#define GPT_CNT 0x90
265#define GPT_CNT_GPT_CNT_ 0x0000FFFF
266
267#define WORD_SWAP 0x98
268
269#define FREE_RUN 0x9C
270
271#define RX_DROP 0xA0
272
273#define MAC_CSR_CMD 0xA4
274#define MAC_CSR_CMD_CSR_BUSY_ 0x80000000
275#define MAC_CSR_CMD_R_NOT_W_ 0x40000000
276#define MAC_CSR_CMD_CSR_ADDR_ 0x000000FF
277
278#define MAC_CSR_DATA 0xA8
279
280#define AFC_CFG 0xAC
281#define AFC_CFG_AFC_HI_ 0x00FF0000
282#define AFC_CFG_AFC_LO_ 0x0000FF00
283#define AFC_CFG_BACK_DUR_ 0x000000F0
284#define AFC_CFG_FCMULT_ 0x00000008
285#define AFC_CFG_FCBRD_ 0x00000004
286#define AFC_CFG_FCADD_ 0x00000002
287#define AFC_CFG_FCANY_ 0x00000001
288
289#define E2P_CMD 0xB0
290#define E2P_CMD_EPC_BUSY_ 0x80000000
291#define E2P_CMD_EPC_CMD_ 0x70000000
292#define E2P_CMD_EPC_CMD_READ_ 0x00000000
293#define E2P_CMD_EPC_CMD_EWDS_ 0x10000000
294#define E2P_CMD_EPC_CMD_EWEN_ 0x20000000
295#define E2P_CMD_EPC_CMD_WRITE_ 0x30000000
296#define E2P_CMD_EPC_CMD_WRAL_ 0x40000000
297#define E2P_CMD_EPC_CMD_ERASE_ 0x50000000
298#define E2P_CMD_EPC_CMD_ERAL_ 0x60000000
299#define E2P_CMD_EPC_CMD_RELOAD_ 0x70000000
300#define E2P_CMD_EPC_TIMEOUT_ 0x00000200
301#define E2P_CMD_MAC_ADDR_LOADED_ 0x00000100
302#define E2P_CMD_EPC_ADDR_ 0x000000FF
303
304#define E2P_DATA 0xB4
305#define E2P_DATA_EEPROM_DATA_ 0x000000FF
306#define LAN_REGISTER_EXTENT 0x00000100
307
308/*
309 * MAC Control and Status Register (Indirect Address)
310 * Offset (through the MAC_CSR CMD and DATA port)
311 */
312#define MAC_CR 0x01
313#define MAC_CR_RXALL_ 0x80000000
314#define MAC_CR_HBDIS_ 0x10000000
315#define MAC_CR_RCVOWN_ 0x00800000
316#define MAC_CR_LOOPBK_ 0x00200000
317#define MAC_CR_FDPX_ 0x00100000
318#define MAC_CR_MCPAS_ 0x00080000
319#define MAC_CR_PRMS_ 0x00040000
320#define MAC_CR_INVFILT_ 0x00020000
321#define MAC_CR_PASSBAD_ 0x00010000
322#define MAC_CR_HFILT_ 0x00008000
323#define MAC_CR_HPFILT_ 0x00002000
324#define MAC_CR_LCOLL_ 0x00001000
325#define MAC_CR_BCAST_ 0x00000800
326#define MAC_CR_DISRTY_ 0x00000400
327#define MAC_CR_PADSTR_ 0x00000100
328#define MAC_CR_BOLMT_MASK_ 0x000000C0
329#define MAC_CR_DFCHK_ 0x00000020
330#define MAC_CR_TXEN_ 0x00000008
331#define MAC_CR_RXEN_ 0x00000004
332
333#define ADDRH 0x02
334
335#define ADDRL 0x03
336
337#define HASHH 0x04
338
339#define HASHL 0x05
340
341#define MII_ACC 0x06
342#define MII_ACC_PHY_ADDR_ 0x0000F800
343#define MII_ACC_MIIRINDA_ 0x000007C0
344#define MII_ACC_MII_WRITE_ 0x00000002
345#define MII_ACC_MII_BUSY_ 0x00000001
346
347#define MII_DATA 0x07
348
349#define FLOW 0x08
350#define FLOW_FCPT_ 0xFFFF0000
351#define FLOW_FCPASS_ 0x00000004
352#define FLOW_FCEN_ 0x00000002
353#define FLOW_FCBSY_ 0x00000001
354
355#define VLAN1 0x09
356
357#define VLAN2 0x0A
358
359#define WUFF 0x0B
360
361#define WUCSR 0x0C
362#define WUCSR_GUE_ 0x00000200
363#define WUCSR_WUFR_ 0x00000040
364#define WUCSR_MPR_ 0x00000020
365#define WUCSR_WAKE_EN_ 0x00000004
366#define WUCSR_MPEN_ 0x00000002
367
368/*
369 * Phy definitions (vendor-specific)
370 */
371#define LAN9118_PHY_ID 0x00C0001C
372
373#define MII_INTSTS 0x1D
374
375#define MII_INTMSK 0x1E
376#define PHY_INTMSK_AN_RCV_ (1 << 1)
377#define PHY_INTMSK_PDFAULT_ (1 << 2)
378#define PHY_INTMSK_AN_ACK_ (1 << 3)
379#define PHY_INTMSK_LNKDOWN_ (1 << 4)
380#define PHY_INTMSK_RFAULT_ (1 << 5)
381#define PHY_INTMSK_AN_COMP_ (1 << 6)
382#define PHY_INTMSK_ENERGYON_ (1 << 7)
383#define PHY_INTMSK_DEFAULT_ (PHY_INTMSK_ENERGYON_ | \
384 PHY_INTMSK_AN_COMP_ | \
385 PHY_INTMSK_RFAULT_ | \
386 PHY_INTMSK_LNKDOWN_)
387
388#define ADVERTISE_PAUSE_ALL (ADVERTISE_PAUSE_CAP | \
389 ADVERTISE_PAUSE_ASYM)
390
391#define LPA_PAUSE_ALL (LPA_PAUSE_CAP | \
392 LPA_PAUSE_ASYM)
393
394#endif /* __SMSC911X_H__ */
diff --git a/include/linux/smsc911x.h b/include/linux/smsc911x.h
new file mode 100644
index 000000000000..47c4ffd10dbb
--- /dev/null
+++ b/include/linux/smsc911x.h
@@ -0,0 +1,42 @@
1/***************************************************************************
2 *
3 * Copyright (C) 2004-2008 SMSC
4 * Copyright (C) 2005-2008 ARM
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19 *
20 ***************************************************************************/
21#ifndef __LINUX_SMSC911X_H__
22#define __LINUX_SMSC911X_H__
23
24#include <linux/phy.h>
25
26/* platform_device configuration data, should be assigned to
27 * the platform_device's dev.platform_data */
28struct smsc911x_platform_config {
29 unsigned int irq_polarity;
30 unsigned int irq_type;
31 phy_interface_t phy_interface;
32};
33
34/* Constants for platform_device irq polarity configuration */
35#define SMSC911X_IRQ_POLARITY_ACTIVE_LOW 0
36#define SMSC911X_IRQ_POLARITY_ACTIVE_HIGH 1
37
38/* Constants for platform_device irq type configuration */
39#define SMSC911X_IRQ_TYPE_OPEN_DRAIN 0
40#define SMSC911X_IRQ_TYPE_PUSH_PULL 1
41
42#endif /* __LINUX_SMSC911X_H__ */
diff --git a/include/net/ndisc.h b/include/net/ndisc.h
index 11dd0137c6a5..ce532f2222ce 100644
--- a/include/net/ndisc.h
+++ b/include/net/ndisc.h
@@ -108,6 +108,20 @@ extern void ndisc_send_redirect(struct sk_buff *skb,
108 108
109extern int ndisc_mc_map(struct in6_addr *addr, char *buf, struct net_device *dev, int dir); 109extern int ndisc_mc_map(struct in6_addr *addr, char *buf, struct net_device *dev, int dir);
110 110
111extern struct sk_buff *ndisc_build_skb(struct net_device *dev,
112 const struct in6_addr *daddr,
113 const struct in6_addr *saddr,
114 struct icmp6hdr *icmp6h,
115 const struct in6_addr *target,
116 int llinfo);
117
118extern void ndisc_send_skb(struct sk_buff *skb,
119 struct net_device *dev,
120 struct neighbour *neigh,
121 const struct in6_addr *daddr,
122 const struct in6_addr *saddr,
123 struct icmp6hdr *icmp6h);
124
111 125
112 126
113/* 127/*
diff --git a/net/ipv6/ndisc.c b/net/ipv6/ndisc.c
index 2a6752dae09d..fbf451c0d77a 100644
--- a/net/ipv6/ndisc.c
+++ b/net/ipv6/ndisc.c
@@ -437,38 +437,20 @@ static void pndisc_destructor(struct pneigh_entry *n)
437 ipv6_dev_mc_dec(dev, &maddr); 437 ipv6_dev_mc_dec(dev, &maddr);
438} 438}
439 439
440/* 440struct sk_buff *ndisc_build_skb(struct net_device *dev,
441 * Send a Neighbour Advertisement 441 const struct in6_addr *daddr,
442 */ 442 const struct in6_addr *saddr,
443static void __ndisc_send(struct net_device *dev, 443 struct icmp6hdr *icmp6h,
444 struct neighbour *neigh, 444 const struct in6_addr *target,
445 const struct in6_addr *daddr, 445 int llinfo)
446 const struct in6_addr *saddr,
447 struct icmp6hdr *icmp6h, const struct in6_addr *target,
448 int llinfo)
449{ 446{
450 struct flowi fl;
451 struct dst_entry *dst;
452 struct net *net = dev_net(dev); 447 struct net *net = dev_net(dev);
453 struct sock *sk = net->ipv6.ndisc_sk; 448 struct sock *sk = net->ipv6.ndisc_sk;
454 struct sk_buff *skb; 449 struct sk_buff *skb;
455 struct icmp6hdr *hdr; 450 struct icmp6hdr *hdr;
456 struct inet6_dev *idev;
457 int len; 451 int len;
458 int err; 452 int err;
459 u8 *opt, type; 453 u8 *opt;
460
461 type = icmp6h->icmp6_type;
462
463 icmpv6_flow_init(sk, &fl, type, saddr, daddr, dev->ifindex);
464
465 dst = icmp6_dst_alloc(dev, neigh, daddr);
466 if (!dst)
467 return;
468
469 err = xfrm_lookup(&dst, &fl, NULL, 0);
470 if (err < 0)
471 return;
472 454
473 if (!dev->addr_len) 455 if (!dev->addr_len)
474 llinfo = 0; 456 llinfo = 0;
@@ -485,8 +467,7 @@ static void __ndisc_send(struct net_device *dev,
485 ND_PRINTK0(KERN_ERR 467 ND_PRINTK0(KERN_ERR
486 "ICMPv6 ND: %s() failed to allocate an skb.\n", 468 "ICMPv6 ND: %s() failed to allocate an skb.\n",
487 __func__); 469 __func__);
488 dst_release(dst); 470 return NULL;
489 return;
490 } 471 }
491 472
492 skb_reserve(skb, LL_RESERVED_SPACE(dev)); 473 skb_reserve(skb, LL_RESERVED_SPACE(dev));
@@ -513,6 +494,42 @@ static void __ndisc_send(struct net_device *dev,
513 csum_partial((__u8 *) hdr, 494 csum_partial((__u8 *) hdr,
514 len, 0)); 495 len, 0));
515 496
497 return skb;
498}
499
500EXPORT_SYMBOL(ndisc_build_skb);
501
502void ndisc_send_skb(struct sk_buff *skb,
503 struct net_device *dev,
504 struct neighbour *neigh,
505 const struct in6_addr *daddr,
506 const struct in6_addr *saddr,
507 struct icmp6hdr *icmp6h)
508{
509 struct flowi fl;
510 struct dst_entry *dst;
511 struct net *net = dev_net(dev);
512 struct sock *sk = net->ipv6.ndisc_sk;
513 struct inet6_dev *idev;
514 int err;
515 u8 type;
516
517 type = icmp6h->icmp6_type;
518
519 icmpv6_flow_init(sk, &fl, type, saddr, daddr, dev->ifindex);
520
521 dst = icmp6_dst_alloc(dev, neigh, daddr);
522 if (!dst) {
523 kfree_skb(skb);
524 return;
525 }
526
527 err = xfrm_lookup(&dst, &fl, NULL, 0);
528 if (err < 0) {
529 kfree_skb(skb);
530 return;
531 }
532
516 skb->dst = dst; 533 skb->dst = dst;
517 534
518 idev = in6_dev_get(dst->dev); 535 idev = in6_dev_get(dst->dev);
@@ -529,6 +546,27 @@ static void __ndisc_send(struct net_device *dev,
529 in6_dev_put(idev); 546 in6_dev_put(idev);
530} 547}
531 548
549EXPORT_SYMBOL(ndisc_send_skb);
550
551/*
552 * Send a Neighbour Discover packet
553 */
554static void __ndisc_send(struct net_device *dev,
555 struct neighbour *neigh,
556 const struct in6_addr *daddr,
557 const struct in6_addr *saddr,
558 struct icmp6hdr *icmp6h, const struct in6_addr *target,
559 int llinfo)
560{
561 struct sk_buff *skb;
562
563 skb = ndisc_build_skb(dev, daddr, saddr, icmp6h, target, llinfo);
564 if (!skb)
565 return;
566
567 ndisc_send_skb(skb, dev, neigh, daddr, saddr, icmp6h);
568}
569
532static void ndisc_send_na(struct net_device *dev, struct neighbour *neigh, 570static void ndisc_send_na(struct net_device *dev, struct neighbour *neigh,
533 const struct in6_addr *daddr, 571 const struct in6_addr *daddr,
534 const struct in6_addr *solicited_addr, 572 const struct in6_addr *solicited_addr,