Jesper Nilsson | 5efa1d1 | 2008-02-06 13:35:07 +0100 | [diff] [blame] | 1 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | * e100net.c: A network driver for the ETRAX 100LX network controller. |
| 3 | * |
| 4 | * Copyright (c) 1998-2002 Axis Communications AB. |
| 5 | * |
| 6 | * The outline of this driver comes from skeleton.c. |
| 7 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8 | */ |
| 9 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10 | #include <linux/kernel.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11 | #include <linux/delay.h> |
| 12 | #include <linux/types.h> |
| 13 | #include <linux/fcntl.h> |
| 14 | #include <linux/interrupt.h> |
| 15 | #include <linux/ptrace.h> |
| 16 | #include <linux/ioport.h> |
| 17 | #include <linux/in.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 18 | #include <linux/string.h> |
| 19 | #include <linux/spinlock.h> |
| 20 | #include <linux/errno.h> |
| 21 | #include <linux/init.h> |
Jiri Slaby | 1977f03 | 2007-10-18 23:40:25 -0700 | [diff] [blame] | 22 | #include <linux/bitops.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 23 | |
| 24 | #include <linux/if.h> |
| 25 | #include <linux/mii.h> |
| 26 | #include <linux/netdevice.h> |
| 27 | #include <linux/etherdevice.h> |
| 28 | #include <linux/skbuff.h> |
| 29 | #include <linux/ethtool.h> |
| 30 | |
Jesper Nilsson | 556dcee | 2008-10-21 17:45:58 +0200 | [diff] [blame] | 31 | #include <arch/svinto.h>/* DMA and register descriptions */ |
Jesper Nilsson | 5efa1d1 | 2008-02-06 13:35:07 +0100 | [diff] [blame] | 32 | #include <asm/io.h> /* CRIS_LED_* I/O functions */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 33 | #include <asm/irq.h> |
| 34 | #include <asm/dma.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 35 | #include <asm/ethernet.h> |
| 36 | #include <asm/cache.h> |
Jesper Nilsson | 556dcee | 2008-10-21 17:45:58 +0200 | [diff] [blame] | 37 | #include <arch/io_interface_mux.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 38 | |
| 39 | //#define ETHDEBUG |
| 40 | #define D(x) |
| 41 | |
| 42 | /* |
| 43 | * The name of the card. Is used for messages and in the requests for |
| 44 | * io regions, irqs and dma channels |
| 45 | */ |
| 46 | |
| 47 | static const char* cardname = "ETRAX 100LX built-in ethernet controller"; |
| 48 | |
| 49 | /* A default ethernet address. Highlevel SW will set the real one later */ |
| 50 | |
| 51 | static struct sockaddr default_mac = { |
| 52 | 0, |
| 53 | { 0x00, 0x40, 0x8C, 0xCD, 0x00, 0x00 } |
| 54 | }; |
| 55 | |
| 56 | /* Information that need to be kept for each board. */ |
| 57 | struct net_local { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 58 | struct mii_if_info mii_if; |
| 59 | |
| 60 | /* Tx control lock. This protects the transmit buffer ring |
| 61 | * state along with the "tx full" state of the driver. This |
| 62 | * means all netif_queue flow control actions are protected |
| 63 | * by this lock as well. |
| 64 | */ |
| 65 | spinlock_t lock; |
Jesper Nilsson | bafef0a | 2007-11-14 17:00:55 -0800 | [diff] [blame] | 66 | |
| 67 | spinlock_t led_lock; /* Protect LED state */ |
| 68 | spinlock_t transceiver_lock; /* Protect transceiver state. */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 69 | }; |
| 70 | |
| 71 | typedef struct etrax_eth_descr |
| 72 | { |
| 73 | etrax_dma_descr descr; |
| 74 | struct sk_buff* skb; |
| 75 | } etrax_eth_descr; |
| 76 | |
| 77 | /* Some transceivers requires special handling */ |
| 78 | struct transceiver_ops |
| 79 | { |
| 80 | unsigned int oui; |
| 81 | void (*check_speed)(struct net_device* dev); |
| 82 | void (*check_duplex)(struct net_device* dev); |
| 83 | }; |
| 84 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 85 | /* Duplex settings */ |
| 86 | enum duplex |
| 87 | { |
| 88 | half, |
| 89 | full, |
| 90 | autoneg |
| 91 | }; |
| 92 | |
| 93 | /* Dma descriptors etc. */ |
| 94 | |
Jesper Nilsson | bafef0a | 2007-11-14 17:00:55 -0800 | [diff] [blame] | 95 | #define MAX_MEDIA_DATA_SIZE 1522 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 96 | |
| 97 | #define MIN_PACKET_LEN 46 |
| 98 | #define ETHER_HEAD_LEN 14 |
| 99 | |
| 100 | /* |
| 101 | ** MDIO constants. |
| 102 | */ |
| 103 | #define MDIO_START 0x1 |
| 104 | #define MDIO_READ 0x2 |
| 105 | #define MDIO_WRITE 0x1 |
| 106 | #define MDIO_PREAMBLE 0xfffffffful |
| 107 | |
| 108 | /* Broadcom specific */ |
| 109 | #define MDIO_AUX_CTRL_STATUS_REG 0x18 |
| 110 | #define MDIO_BC_FULL_DUPLEX_IND 0x1 |
| 111 | #define MDIO_BC_SPEED 0x2 |
| 112 | |
| 113 | /* TDK specific */ |
| 114 | #define MDIO_TDK_DIAGNOSTIC_REG 18 |
| 115 | #define MDIO_TDK_DIAGNOSTIC_RATE 0x400 |
| 116 | #define MDIO_TDK_DIAGNOSTIC_DPLX 0x800 |
| 117 | |
| 118 | /*Intel LXT972A specific*/ |
| 119 | #define MDIO_INT_STATUS_REG_2 0x0011 |
Jesper Nilsson | bafef0a | 2007-11-14 17:00:55 -0800 | [diff] [blame] | 120 | #define MDIO_INT_FULL_DUPLEX_IND (1 << 9) |
| 121 | #define MDIO_INT_SPEED (1 << 14) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 122 | |
| 123 | /* Network flash constants */ |
| 124 | #define NET_FLASH_TIME (HZ/50) /* 20 ms */ |
| 125 | #define NET_FLASH_PAUSE (HZ/100) /* 10 ms */ |
| 126 | #define NET_LINK_UP_CHECK_INTERVAL (2*HZ) /* 2 s */ |
| 127 | #define NET_DUPLEX_CHECK_INTERVAL (2*HZ) /* 2 s */ |
| 128 | |
| 129 | #define NO_NETWORK_ACTIVITY 0 |
| 130 | #define NETWORK_ACTIVITY 1 |
| 131 | |
Jesper Nilsson | bafef0a | 2007-11-14 17:00:55 -0800 | [diff] [blame] | 132 | #define NBR_OF_RX_DESC 32 |
| 133 | #define NBR_OF_TX_DESC 16 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 134 | |
| 135 | /* Large packets are sent directly to upper layers while small packets are */ |
| 136 | /* copied (to reduce memory waste). The following constant decides the breakpoint */ |
| 137 | #define RX_COPYBREAK 256 |
| 138 | |
| 139 | /* Due to a chip bug we need to flush the cache when descriptors are returned */ |
| 140 | /* to the DMA. To decrease performance impact we return descriptors in chunks. */ |
| 141 | /* The following constant determines the number of descriptors to return. */ |
| 142 | #define RX_QUEUE_THRESHOLD NBR_OF_RX_DESC/2 |
| 143 | |
| 144 | #define GET_BIT(bit,val) (((val) >> (bit)) & 0x01) |
| 145 | |
| 146 | /* Define some macros to access ETRAX 100 registers */ |
| 147 | #define SETF(var, reg, field, val) var = (var & ~IO_MASK_(reg##_, field##_)) | \ |
| 148 | IO_FIELD_(reg##_, field##_, val) |
| 149 | #define SETS(var, reg, field, val) var = (var & ~IO_MASK_(reg##_, field##_)) | \ |
| 150 | IO_STATE_(reg##_, field##_, _##val) |
| 151 | |
| 152 | static etrax_eth_descr *myNextRxDesc; /* Points to the next descriptor to |
| 153 | to be processed */ |
| 154 | static etrax_eth_descr *myLastRxDesc; /* The last processed descriptor */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 155 | |
| 156 | static etrax_eth_descr RxDescList[NBR_OF_RX_DESC] __attribute__ ((aligned(32))); |
| 157 | |
| 158 | static etrax_eth_descr* myFirstTxDesc; /* First packet not yet sent */ |
| 159 | static etrax_eth_descr* myLastTxDesc; /* End of send queue */ |
| 160 | static etrax_eth_descr* myNextTxDesc; /* Next descriptor to use */ |
| 161 | static etrax_eth_descr TxDescList[NBR_OF_TX_DESC] __attribute__ ((aligned(32))); |
| 162 | |
| 163 | static unsigned int network_rec_config_shadow = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 164 | |
| 165 | static unsigned int network_tr_ctrl_shadow = 0; |
| 166 | |
| 167 | /* Network speed indication. */ |
Ingo Molnar | 8d06afa | 2005-09-09 13:10:40 -0700 | [diff] [blame] | 168 | static DEFINE_TIMER(speed_timer, NULL, 0, 0); |
| 169 | static DEFINE_TIMER(clear_led_timer, NULL, 0, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 170 | static int current_speed; /* Speed read from transceiver */ |
| 171 | static int current_speed_selection; /* Speed selected by user */ |
| 172 | static unsigned long led_next_time; |
| 173 | static int led_active; |
| 174 | static int rx_queue_len; |
| 175 | |
| 176 | /* Duplex */ |
Ingo Molnar | 8d06afa | 2005-09-09 13:10:40 -0700 | [diff] [blame] | 177 | static DEFINE_TIMER(duplex_timer, NULL, 0, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 178 | static int full_duplex; |
| 179 | static enum duplex current_duplex; |
| 180 | |
| 181 | /* Index to functions, as function prototypes. */ |
| 182 | |
| 183 | static int etrax_ethernet_init(void); |
| 184 | |
| 185 | static int e100_open(struct net_device *dev); |
| 186 | static int e100_set_mac_address(struct net_device *dev, void *addr); |
| 187 | static int e100_send_packet(struct sk_buff *skb, struct net_device *dev); |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 188 | static irqreturn_t e100rxtx_interrupt(int irq, void *dev_id); |
| 189 | static irqreturn_t e100nw_interrupt(int irq, void *dev_id); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 190 | static void e100_rx(struct net_device *dev); |
| 191 | static int e100_close(struct net_device *dev); |
| 192 | static int e100_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 193 | static int e100_set_config(struct net_device* dev, struct ifmap* map); |
| 194 | static void e100_tx_timeout(struct net_device *dev); |
| 195 | static struct net_device_stats *e100_get_stats(struct net_device *dev); |
| 196 | static void set_multicast_list(struct net_device *dev); |
Jesper Nilsson | bafef0a | 2007-11-14 17:00:55 -0800 | [diff] [blame] | 197 | static void e100_hardware_send_packet(struct net_local* np, char *buf, int length); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 198 | static void update_rx_stats(struct net_device_stats *); |
| 199 | static void update_tx_stats(struct net_device_stats *); |
| 200 | static int e100_probe_transceiver(struct net_device* dev); |
| 201 | |
| 202 | static void e100_check_speed(unsigned long priv); |
| 203 | static void e100_set_speed(struct net_device* dev, unsigned long speed); |
| 204 | static void e100_check_duplex(unsigned long priv); |
| 205 | static void e100_set_duplex(struct net_device* dev, enum duplex); |
| 206 | static void e100_negotiate(struct net_device* dev); |
| 207 | |
| 208 | static int e100_get_mdio_reg(struct net_device *dev, int phy_id, int location); |
| 209 | static void e100_set_mdio_reg(struct net_device *dev, int phy_id, int location, int value); |
| 210 | |
| 211 | static void e100_send_mdio_cmd(unsigned short cmd, int write_cmd); |
| 212 | static void e100_send_mdio_bit(unsigned char bit); |
| 213 | static unsigned char e100_receive_mdio_bit(void); |
| 214 | static void e100_reset_transceiver(struct net_device* net); |
| 215 | |
| 216 | static void e100_clear_network_leds(unsigned long dummy); |
| 217 | static void e100_set_network_leds(int active); |
| 218 | |
Jeff Garzik | 7282d49 | 2006-09-13 14:30:00 -0400 | [diff] [blame] | 219 | static const struct ethtool_ops e100_ethtool_ops; |
Jesper Nilsson | bafef0a | 2007-11-14 17:00:55 -0800 | [diff] [blame] | 220 | #if defined(CONFIG_ETRAX_NO_PHY) |
| 221 | static void dummy_check_speed(struct net_device* dev); |
| 222 | static void dummy_check_duplex(struct net_device* dev); |
| 223 | #else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 224 | static void broadcom_check_speed(struct net_device* dev); |
| 225 | static void broadcom_check_duplex(struct net_device* dev); |
| 226 | static void tdk_check_speed(struct net_device* dev); |
| 227 | static void tdk_check_duplex(struct net_device* dev); |
| 228 | static void intel_check_speed(struct net_device* dev); |
| 229 | static void intel_check_duplex(struct net_device* dev); |
| 230 | static void generic_check_speed(struct net_device* dev); |
| 231 | static void generic_check_duplex(struct net_device* dev); |
Jesper Nilsson | bafef0a | 2007-11-14 17:00:55 -0800 | [diff] [blame] | 232 | #endif |
| 233 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 234 | static void e100_netpoll(struct net_device* dev); |
| 235 | #endif |
| 236 | |
| 237 | static int autoneg_normal = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 238 | |
| 239 | struct transceiver_ops transceivers[] = |
| 240 | { |
Jesper Nilsson | bafef0a | 2007-11-14 17:00:55 -0800 | [diff] [blame] | 241 | #if defined(CONFIG_ETRAX_NO_PHY) |
| 242 | {0x0000, dummy_check_speed, dummy_check_duplex} /* Dummy */ |
| 243 | #else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 244 | {0x1018, broadcom_check_speed, broadcom_check_duplex}, /* Broadcom */ |
| 245 | {0xC039, tdk_check_speed, tdk_check_duplex}, /* TDK 2120 */ |
| 246 | {0x039C, tdk_check_speed, tdk_check_duplex}, /* TDK 2120C */ |
| 247 | {0x04de, intel_check_speed, intel_check_duplex}, /* Intel LXT972A*/ |
| 248 | {0x0000, generic_check_speed, generic_check_duplex} /* Generic, must be last */ |
Jesper Nilsson | bafef0a | 2007-11-14 17:00:55 -0800 | [diff] [blame] | 249 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 250 | }; |
| 251 | |
Jesper Nilsson | bafef0a | 2007-11-14 17:00:55 -0800 | [diff] [blame] | 252 | struct transceiver_ops* transceiver = &transceivers[0]; |
| 253 | |
Alexander Beregalov | a95c2a3 | 2009-04-11 07:45:55 +0000 | [diff] [blame] | 254 | static const struct net_device_ops e100_netdev_ops = { |
| 255 | .ndo_open = e100_open, |
| 256 | .ndo_stop = e100_close, |
| 257 | .ndo_start_xmit = e100_send_packet, |
| 258 | .ndo_tx_timeout = e100_tx_timeout, |
| 259 | .ndo_get_stats = e100_get_stats, |
Jiri Pirko | afc4b13 | 2011-08-16 06:29:01 +0000 | [diff] [blame] | 260 | .ndo_set_rx_mode = set_multicast_list, |
Alexander Beregalov | a95c2a3 | 2009-04-11 07:45:55 +0000 | [diff] [blame] | 261 | .ndo_do_ioctl = e100_ioctl, |
| 262 | .ndo_set_mac_address = e100_set_mac_address, |
| 263 | .ndo_validate_addr = eth_validate_addr, |
Alexander Beregalov | a95c2a3 | 2009-04-11 07:45:55 +0000 | [diff] [blame] | 264 | .ndo_set_config = e100_set_config, |
| 265 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 266 | .ndo_poll_controller = e100_netpoll, |
| 267 | #endif |
| 268 | }; |
| 269 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 270 | #define tx_done(dev) (*R_DMA_CH0_CMD == 0) |
| 271 | |
| 272 | /* |
| 273 | * Check for a network adaptor of this type, and return '0' if one exists. |
| 274 | * If dev->base_addr == 0, probe all likely locations. |
| 275 | * If dev->base_addr == 1, always return failure. |
| 276 | * If dev->base_addr == 2, allocate space for the device and return success |
| 277 | * (detachable devices only). |
| 278 | */ |
| 279 | |
| 280 | static int __init |
| 281 | etrax_ethernet_init(void) |
| 282 | { |
| 283 | struct net_device *dev; |
| 284 | struct net_local* np; |
| 285 | int i, err; |
| 286 | |
| 287 | printk(KERN_INFO |
Jesper Nilsson | bafef0a | 2007-11-14 17:00:55 -0800 | [diff] [blame] | 288 | "ETRAX 100LX 10/100MBit ethernet v2.0 (c) 1998-2007 Axis Communications AB\n"); |
| 289 | |
| 290 | if (cris_request_io_interface(if_eth, cardname)) { |
| 291 | printk(KERN_CRIT "etrax_ethernet_init failed to get IO interface\n"); |
| 292 | return -EBUSY; |
| 293 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 294 | |
| 295 | dev = alloc_etherdev(sizeof(struct net_local)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 296 | if (!dev) |
| 297 | return -ENOMEM; |
| 298 | |
Jesper Nilsson | bafef0a | 2007-11-14 17:00:55 -0800 | [diff] [blame] | 299 | np = netdev_priv(dev); |
| 300 | |
| 301 | /* we do our own locking */ |
| 302 | dev->features |= NETIF_F_LLTX; |
| 303 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 304 | dev->base_addr = (unsigned int)R_NETWORK_SA_0; /* just to have something to show */ |
| 305 | |
| 306 | /* now setup our etrax specific stuff */ |
| 307 | |
| 308 | dev->irq = NETWORK_DMA_RX_IRQ_NBR; /* we really use DMATX as well... */ |
| 309 | dev->dma = NETWORK_RX_DMA_NBR; |
| 310 | |
| 311 | /* fill in our handlers so the network layer can talk to us in the future */ |
| 312 | |
Christoph Hellwig | 76f2b4d | 2005-11-07 06:18:57 +0100 | [diff] [blame] | 313 | dev->ethtool_ops = &e100_ethtool_ops; |
Alexander Beregalov | a95c2a3 | 2009-04-11 07:45:55 +0000 | [diff] [blame] | 314 | dev->netdev_ops = &e100_netdev_ops; |
Jesper Nilsson | bafef0a | 2007-11-14 17:00:55 -0800 | [diff] [blame] | 315 | |
| 316 | spin_lock_init(&np->lock); |
| 317 | spin_lock_init(&np->led_lock); |
| 318 | spin_lock_init(&np->transceiver_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 319 | |
| 320 | /* Initialise the list of Etrax DMA-descriptors */ |
| 321 | |
| 322 | /* Initialise receive descriptors */ |
| 323 | |
| 324 | for (i = 0; i < NBR_OF_RX_DESC; i++) { |
Jesper Nilsson | bafef0a | 2007-11-14 17:00:55 -0800 | [diff] [blame] | 325 | /* Allocate two extra cachelines to make sure that buffer used |
| 326 | * by DMA does not share cacheline with any other data (to |
| 327 | * avoid cache bug) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 328 | */ |
| 329 | RxDescList[i].skb = dev_alloc_skb(MAX_MEDIA_DATA_SIZE + 2 * L1_CACHE_BYTES); |
David Rientjes | 92b1f90 | 2006-11-08 19:49:15 -0800 | [diff] [blame] | 330 | if (!RxDescList[i].skb) |
| 331 | return -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 332 | RxDescList[i].descr.ctrl = 0; |
| 333 | RxDescList[i].descr.sw_len = MAX_MEDIA_DATA_SIZE; |
| 334 | RxDescList[i].descr.next = virt_to_phys(&RxDescList[i + 1]); |
| 335 | RxDescList[i].descr.buf = L1_CACHE_ALIGN(virt_to_phys(RxDescList[i].skb->data)); |
| 336 | RxDescList[i].descr.status = 0; |
| 337 | RxDescList[i].descr.hw_len = 0; |
| 338 | prepare_rx_descriptor(&RxDescList[i].descr); |
| 339 | } |
| 340 | |
| 341 | RxDescList[NBR_OF_RX_DESC - 1].descr.ctrl = d_eol; |
| 342 | RxDescList[NBR_OF_RX_DESC - 1].descr.next = virt_to_phys(&RxDescList[0]); |
| 343 | rx_queue_len = 0; |
| 344 | |
| 345 | /* Initialize transmit descriptors */ |
| 346 | for (i = 0; i < NBR_OF_TX_DESC; i++) { |
| 347 | TxDescList[i].descr.ctrl = 0; |
| 348 | TxDescList[i].descr.sw_len = 0; |
| 349 | TxDescList[i].descr.next = virt_to_phys(&TxDescList[i + 1].descr); |
| 350 | TxDescList[i].descr.buf = 0; |
| 351 | TxDescList[i].descr.status = 0; |
| 352 | TxDescList[i].descr.hw_len = 0; |
| 353 | TxDescList[i].skb = 0; |
| 354 | } |
| 355 | |
| 356 | TxDescList[NBR_OF_TX_DESC - 1].descr.ctrl = d_eol; |
| 357 | TxDescList[NBR_OF_TX_DESC - 1].descr.next = virt_to_phys(&TxDescList[0].descr); |
| 358 | |
| 359 | /* Initialise initial pointers */ |
| 360 | |
| 361 | myNextRxDesc = &RxDescList[0]; |
| 362 | myLastRxDesc = &RxDescList[NBR_OF_RX_DESC - 1]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 363 | myFirstTxDesc = &TxDescList[0]; |
| 364 | myNextTxDesc = &TxDescList[0]; |
| 365 | myLastTxDesc = &TxDescList[NBR_OF_TX_DESC - 1]; |
| 366 | |
| 367 | /* Register device */ |
| 368 | err = register_netdev(dev); |
| 369 | if (err) { |
| 370 | free_netdev(dev); |
| 371 | return err; |
| 372 | } |
| 373 | |
| 374 | /* set the default MAC address */ |
| 375 | |
| 376 | e100_set_mac_address(dev, &default_mac); |
| 377 | |
| 378 | /* Initialize speed indicator stuff. */ |
| 379 | |
| 380 | current_speed = 10; |
| 381 | current_speed_selection = 0; /* Auto */ |
| 382 | speed_timer.expires = jiffies + NET_LINK_UP_CHECK_INTERVAL; |
Jesper Nilsson | bafef0a | 2007-11-14 17:00:55 -0800 | [diff] [blame] | 383 | speed_timer.data = (unsigned long)dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 384 | speed_timer.function = e100_check_speed; |
| 385 | |
| 386 | clear_led_timer.function = e100_clear_network_leds; |
Jesper Nilsson | bafef0a | 2007-11-14 17:00:55 -0800 | [diff] [blame] | 387 | clear_led_timer.data = (unsigned long)dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 388 | |
| 389 | full_duplex = 0; |
| 390 | current_duplex = autoneg; |
| 391 | duplex_timer.expires = jiffies + NET_DUPLEX_CHECK_INTERVAL; |
| 392 | duplex_timer.data = (unsigned long)dev; |
| 393 | duplex_timer.function = e100_check_duplex; |
| 394 | |
| 395 | /* Initialize mii interface */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 396 | np->mii_if.phy_id_mask = 0x1f; |
| 397 | np->mii_if.reg_num_mask = 0x1f; |
| 398 | np->mii_if.dev = dev; |
| 399 | np->mii_if.mdio_read = e100_get_mdio_reg; |
| 400 | np->mii_if.mdio_write = e100_set_mdio_reg; |
| 401 | |
| 402 | /* Initialize group address registers to make sure that no */ |
| 403 | /* unwanted addresses are matched */ |
| 404 | *R_NETWORK_GA_0 = 0x00000000; |
| 405 | *R_NETWORK_GA_1 = 0x00000000; |
Jesper Nilsson | bafef0a | 2007-11-14 17:00:55 -0800 | [diff] [blame] | 406 | |
| 407 | /* Initialize next time the led can flash */ |
| 408 | led_next_time = jiffies; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 409 | return 0; |
| 410 | } |
Paul Gortmaker | a13925a | 2016-10-31 15:32:16 -0400 | [diff] [blame] | 411 | device_initcall(etrax_ethernet_init) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 412 | |
| 413 | /* set MAC address of the interface. called from the core after a |
| 414 | * SIOCSIFADDR ioctl, and from the bootup above. |
| 415 | */ |
| 416 | |
| 417 | static int |
| 418 | e100_set_mac_address(struct net_device *dev, void *p) |
| 419 | { |
Jesper Nilsson | bafef0a | 2007-11-14 17:00:55 -0800 | [diff] [blame] | 420 | struct net_local *np = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 421 | struct sockaddr *addr = p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 422 | |
| 423 | spin_lock(&np->lock); /* preemption protection */ |
| 424 | |
| 425 | /* remember it */ |
| 426 | |
| 427 | memcpy(dev->dev_addr, addr->sa_data, dev->addr_len); |
| 428 | |
| 429 | /* Write it to the hardware. |
| 430 | * Note the way the address is wrapped: |
| 431 | * *R_NETWORK_SA_0 = a0_0 | (a0_1 << 8) | (a0_2 << 16) | (a0_3 << 24); |
| 432 | * *R_NETWORK_SA_1 = a0_4 | (a0_5 << 8); |
| 433 | */ |
| 434 | |
| 435 | *R_NETWORK_SA_0 = dev->dev_addr[0] | (dev->dev_addr[1] << 8) | |
| 436 | (dev->dev_addr[2] << 16) | (dev->dev_addr[3] << 24); |
| 437 | *R_NETWORK_SA_1 = dev->dev_addr[4] | (dev->dev_addr[5] << 8); |
| 438 | *R_NETWORK_SA_2 = 0; |
| 439 | |
| 440 | /* show it in the log as well */ |
| 441 | |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 442 | printk(KERN_INFO "%s: changed MAC to %pM\n", dev->name, dev->dev_addr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 443 | |
| 444 | spin_unlock(&np->lock); |
| 445 | |
| 446 | return 0; |
| 447 | } |
| 448 | |
| 449 | /* |
| 450 | * Open/initialize the board. This is called (in the current kernel) |
| 451 | * sometime after booting when the 'ifconfig' program is run. |
| 452 | * |
| 453 | * This routine should set everything up anew at each open, even |
| 454 | * registers that "should" only need to be set once at boot, so that |
| 455 | * there is non-reboot way to recover if something goes wrong. |
| 456 | */ |
| 457 | |
| 458 | static int |
| 459 | e100_open(struct net_device *dev) |
| 460 | { |
| 461 | unsigned long flags; |
| 462 | |
| 463 | /* enable the MDIO output pin */ |
| 464 | |
| 465 | *R_NETWORK_MGM_CTRL = IO_STATE(R_NETWORK_MGM_CTRL, mdoe, enable); |
| 466 | |
| 467 | *R_IRQ_MASK0_CLR = |
| 468 | IO_STATE(R_IRQ_MASK0_CLR, overrun, clr) | |
| 469 | IO_STATE(R_IRQ_MASK0_CLR, underrun, clr) | |
| 470 | IO_STATE(R_IRQ_MASK0_CLR, excessive_col, clr); |
| 471 | |
| 472 | /* clear dma0 and 1 eop and descr irq masks */ |
| 473 | *R_IRQ_MASK2_CLR = |
| 474 | IO_STATE(R_IRQ_MASK2_CLR, dma0_descr, clr) | |
| 475 | IO_STATE(R_IRQ_MASK2_CLR, dma0_eop, clr) | |
| 476 | IO_STATE(R_IRQ_MASK2_CLR, dma1_descr, clr) | |
| 477 | IO_STATE(R_IRQ_MASK2_CLR, dma1_eop, clr); |
| 478 | |
| 479 | /* Reset and wait for the DMA channels */ |
| 480 | |
| 481 | RESET_DMA(NETWORK_TX_DMA_NBR); |
| 482 | RESET_DMA(NETWORK_RX_DMA_NBR); |
| 483 | WAIT_DMA(NETWORK_TX_DMA_NBR); |
| 484 | WAIT_DMA(NETWORK_RX_DMA_NBR); |
| 485 | |
| 486 | /* Initialise the etrax network controller */ |
| 487 | |
| 488 | /* allocate the irq corresponding to the receiving DMA */ |
| 489 | |
Javier Martinez Canillas | ab392d2 | 2011-03-28 16:27:31 +0000 | [diff] [blame] | 490 | if (request_irq(NETWORK_DMA_RX_IRQ_NBR, e100rxtx_interrupt, 0, cardname, |
| 491 | (void *)dev)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 492 | goto grace_exit0; |
| 493 | } |
| 494 | |
| 495 | /* allocate the irq corresponding to the transmitting DMA */ |
| 496 | |
| 497 | if (request_irq(NETWORK_DMA_TX_IRQ_NBR, e100rxtx_interrupt, 0, |
| 498 | cardname, (void *)dev)) { |
| 499 | goto grace_exit1; |
| 500 | } |
| 501 | |
| 502 | /* allocate the irq corresponding to the network errors etc */ |
| 503 | |
| 504 | if (request_irq(NETWORK_STATUS_IRQ_NBR, e100nw_interrupt, 0, |
| 505 | cardname, (void *)dev)) { |
| 506 | goto grace_exit2; |
| 507 | } |
| 508 | |
Jesper Nilsson | bafef0a | 2007-11-14 17:00:55 -0800 | [diff] [blame] | 509 | /* |
| 510 | * Always allocate the DMA channels after the IRQ, |
| 511 | * and clean up on failure. |
| 512 | */ |
| 513 | |
| 514 | if (cris_request_dma(NETWORK_TX_DMA_NBR, |
| 515 | cardname, |
| 516 | DMA_VERBOSE_ON_ERROR, |
| 517 | dma_eth)) { |
| 518 | goto grace_exit3; |
| 519 | } |
| 520 | |
| 521 | if (cris_request_dma(NETWORK_RX_DMA_NBR, |
| 522 | cardname, |
| 523 | DMA_VERBOSE_ON_ERROR, |
| 524 | dma_eth)) { |
| 525 | goto grace_exit4; |
| 526 | } |
| 527 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 528 | /* give the HW an idea of what MAC address we want */ |
| 529 | |
| 530 | *R_NETWORK_SA_0 = dev->dev_addr[0] | (dev->dev_addr[1] << 8) | |
| 531 | (dev->dev_addr[2] << 16) | (dev->dev_addr[3] << 24); |
| 532 | *R_NETWORK_SA_1 = dev->dev_addr[4] | (dev->dev_addr[5] << 8); |
| 533 | *R_NETWORK_SA_2 = 0; |
| 534 | |
| 535 | #if 0 |
| 536 | /* use promiscuous mode for testing */ |
| 537 | *R_NETWORK_GA_0 = 0xffffffff; |
| 538 | *R_NETWORK_GA_1 = 0xffffffff; |
| 539 | |
| 540 | *R_NETWORK_REC_CONFIG = 0xd; /* broadcast rec, individ. rec, ma0 enabled */ |
| 541 | #else |
Jesper Nilsson | bafef0a | 2007-11-14 17:00:55 -0800 | [diff] [blame] | 542 | SETS(network_rec_config_shadow, R_NETWORK_REC_CONFIG, max_size, size1522); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 543 | SETS(network_rec_config_shadow, R_NETWORK_REC_CONFIG, broadcast, receive); |
| 544 | SETS(network_rec_config_shadow, R_NETWORK_REC_CONFIG, ma0, enable); |
| 545 | SETF(network_rec_config_shadow, R_NETWORK_REC_CONFIG, duplex, full_duplex); |
| 546 | *R_NETWORK_REC_CONFIG = network_rec_config_shadow; |
| 547 | #endif |
| 548 | |
| 549 | *R_NETWORK_GEN_CONFIG = |
| 550 | IO_STATE(R_NETWORK_GEN_CONFIG, phy, mii_clk) | |
| 551 | IO_STATE(R_NETWORK_GEN_CONFIG, enable, on); |
| 552 | |
| 553 | SETS(network_tr_ctrl_shadow, R_NETWORK_TR_CTRL, clr_error, clr); |
| 554 | SETS(network_tr_ctrl_shadow, R_NETWORK_TR_CTRL, delay, none); |
| 555 | SETS(network_tr_ctrl_shadow, R_NETWORK_TR_CTRL, cancel, dont); |
| 556 | SETS(network_tr_ctrl_shadow, R_NETWORK_TR_CTRL, cd, enable); |
| 557 | SETS(network_tr_ctrl_shadow, R_NETWORK_TR_CTRL, retry, enable); |
| 558 | SETS(network_tr_ctrl_shadow, R_NETWORK_TR_CTRL, pad, enable); |
| 559 | SETS(network_tr_ctrl_shadow, R_NETWORK_TR_CTRL, crc, enable); |
| 560 | *R_NETWORK_TR_CTRL = network_tr_ctrl_shadow; |
| 561 | |
Jesper Nilsson | bafef0a | 2007-11-14 17:00:55 -0800 | [diff] [blame] | 562 | local_irq_save(flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 563 | |
| 564 | /* enable the irq's for ethernet DMA */ |
| 565 | |
| 566 | *R_IRQ_MASK2_SET = |
| 567 | IO_STATE(R_IRQ_MASK2_SET, dma0_eop, set) | |
| 568 | IO_STATE(R_IRQ_MASK2_SET, dma1_eop, set); |
| 569 | |
| 570 | *R_IRQ_MASK0_SET = |
| 571 | IO_STATE(R_IRQ_MASK0_SET, overrun, set) | |
| 572 | IO_STATE(R_IRQ_MASK0_SET, underrun, set) | |
| 573 | IO_STATE(R_IRQ_MASK0_SET, excessive_col, set); |
| 574 | |
| 575 | /* make sure the irqs are cleared */ |
| 576 | |
| 577 | *R_DMA_CH0_CLR_INTR = IO_STATE(R_DMA_CH0_CLR_INTR, clr_eop, do); |
| 578 | *R_DMA_CH1_CLR_INTR = IO_STATE(R_DMA_CH1_CLR_INTR, clr_eop, do); |
| 579 | |
| 580 | /* make sure the rec and transmit error counters are cleared */ |
| 581 | |
| 582 | (void)*R_REC_COUNTERS; /* dummy read */ |
| 583 | (void)*R_TR_COUNTERS; /* dummy read */ |
| 584 | |
| 585 | /* start the receiving DMA channel so we can receive packets from now on */ |
| 586 | |
| 587 | *R_DMA_CH1_FIRST = virt_to_phys(myNextRxDesc); |
| 588 | *R_DMA_CH1_CMD = IO_STATE(R_DMA_CH1_CMD, cmd, start); |
| 589 | |
| 590 | /* Set up transmit DMA channel so it can be restarted later */ |
| 591 | |
| 592 | *R_DMA_CH0_FIRST = 0; |
| 593 | *R_DMA_CH0_DESCR = virt_to_phys(myLastTxDesc); |
Jesper Nilsson | bafef0a | 2007-11-14 17:00:55 -0800 | [diff] [blame] | 594 | netif_start_queue(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 595 | |
Jesper Nilsson | bafef0a | 2007-11-14 17:00:55 -0800 | [diff] [blame] | 596 | local_irq_restore(flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 597 | |
| 598 | /* Probe for transceiver */ |
| 599 | if (e100_probe_transceiver(dev)) |
Jesper Nilsson | bafef0a | 2007-11-14 17:00:55 -0800 | [diff] [blame] | 600 | goto grace_exit5; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 601 | |
| 602 | /* Start duplex/speed timers */ |
| 603 | add_timer(&speed_timer); |
| 604 | add_timer(&duplex_timer); |
| 605 | |
| 606 | /* We are now ready to accept transmit requeusts from |
| 607 | * the queueing layer of the networking. |
| 608 | */ |
Jesper Nilsson | bafef0a | 2007-11-14 17:00:55 -0800 | [diff] [blame] | 609 | netif_carrier_on(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 610 | |
| 611 | return 0; |
| 612 | |
Jesper Nilsson | bafef0a | 2007-11-14 17:00:55 -0800 | [diff] [blame] | 613 | grace_exit5: |
| 614 | cris_free_dma(NETWORK_RX_DMA_NBR, cardname); |
| 615 | grace_exit4: |
| 616 | cris_free_dma(NETWORK_TX_DMA_NBR, cardname); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 617 | grace_exit3: |
| 618 | free_irq(NETWORK_STATUS_IRQ_NBR, (void *)dev); |
| 619 | grace_exit2: |
| 620 | free_irq(NETWORK_DMA_TX_IRQ_NBR, (void *)dev); |
| 621 | grace_exit1: |
| 622 | free_irq(NETWORK_DMA_RX_IRQ_NBR, (void *)dev); |
| 623 | grace_exit0: |
| 624 | return -EAGAIN; |
| 625 | } |
| 626 | |
Jesper Nilsson | bafef0a | 2007-11-14 17:00:55 -0800 | [diff] [blame] | 627 | #if defined(CONFIG_ETRAX_NO_PHY) |
| 628 | static void |
| 629 | dummy_check_speed(struct net_device* dev) |
| 630 | { |
| 631 | current_speed = 100; |
| 632 | } |
| 633 | #else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 634 | static void |
| 635 | generic_check_speed(struct net_device* dev) |
| 636 | { |
| 637 | unsigned long data; |
Jesper Nilsson | bafef0a | 2007-11-14 17:00:55 -0800 | [diff] [blame] | 638 | struct net_local *np = netdev_priv(dev); |
| 639 | |
| 640 | data = e100_get_mdio_reg(dev, np->mii_if.phy_id, MII_ADVERTISE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 641 | if ((data & ADVERTISE_100FULL) || |
| 642 | (data & ADVERTISE_100HALF)) |
| 643 | current_speed = 100; |
| 644 | else |
| 645 | current_speed = 10; |
| 646 | } |
| 647 | |
| 648 | static void |
| 649 | tdk_check_speed(struct net_device* dev) |
| 650 | { |
| 651 | unsigned long data; |
Jesper Nilsson | bafef0a | 2007-11-14 17:00:55 -0800 | [diff] [blame] | 652 | struct net_local *np = netdev_priv(dev); |
| 653 | |
| 654 | data = e100_get_mdio_reg(dev, np->mii_if.phy_id, |
| 655 | MDIO_TDK_DIAGNOSTIC_REG); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 656 | current_speed = (data & MDIO_TDK_DIAGNOSTIC_RATE ? 100 : 10); |
| 657 | } |
| 658 | |
| 659 | static void |
| 660 | broadcom_check_speed(struct net_device* dev) |
| 661 | { |
| 662 | unsigned long data; |
Jesper Nilsson | bafef0a | 2007-11-14 17:00:55 -0800 | [diff] [blame] | 663 | struct net_local *np = netdev_priv(dev); |
| 664 | |
| 665 | data = e100_get_mdio_reg(dev, np->mii_if.phy_id, |
| 666 | MDIO_AUX_CTRL_STATUS_REG); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 667 | current_speed = (data & MDIO_BC_SPEED ? 100 : 10); |
| 668 | } |
| 669 | |
| 670 | static void |
| 671 | intel_check_speed(struct net_device* dev) |
| 672 | { |
| 673 | unsigned long data; |
Jesper Nilsson | bafef0a | 2007-11-14 17:00:55 -0800 | [diff] [blame] | 674 | struct net_local *np = netdev_priv(dev); |
| 675 | |
| 676 | data = e100_get_mdio_reg(dev, np->mii_if.phy_id, |
| 677 | MDIO_INT_STATUS_REG_2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 678 | current_speed = (data & MDIO_INT_SPEED ? 100 : 10); |
| 679 | } |
Jesper Nilsson | bafef0a | 2007-11-14 17:00:55 -0800 | [diff] [blame] | 680 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 681 | static void |
| 682 | e100_check_speed(unsigned long priv) |
| 683 | { |
| 684 | struct net_device* dev = (struct net_device*)priv; |
Jesper Nilsson | bafef0a | 2007-11-14 17:00:55 -0800 | [diff] [blame] | 685 | struct net_local *np = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 686 | static int led_initiated = 0; |
| 687 | unsigned long data; |
| 688 | int old_speed = current_speed; |
| 689 | |
Jesper Nilsson | bafef0a | 2007-11-14 17:00:55 -0800 | [diff] [blame] | 690 | spin_lock(&np->transceiver_lock); |
| 691 | |
| 692 | data = e100_get_mdio_reg(dev, np->mii_if.phy_id, MII_BMSR); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 693 | if (!(data & BMSR_LSTATUS)) { |
| 694 | current_speed = 0; |
| 695 | } else { |
| 696 | transceiver->check_speed(dev); |
| 697 | } |
| 698 | |
Jesper Nilsson | bafef0a | 2007-11-14 17:00:55 -0800 | [diff] [blame] | 699 | spin_lock(&np->led_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 700 | if ((old_speed != current_speed) || !led_initiated) { |
| 701 | led_initiated = 1; |
| 702 | e100_set_network_leds(NO_NETWORK_ACTIVITY); |
Jesper Nilsson | bafef0a | 2007-11-14 17:00:55 -0800 | [diff] [blame] | 703 | if (current_speed) |
| 704 | netif_carrier_on(dev); |
| 705 | else |
| 706 | netif_carrier_off(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 707 | } |
Jesper Nilsson | bafef0a | 2007-11-14 17:00:55 -0800 | [diff] [blame] | 708 | spin_unlock(&np->led_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 709 | |
| 710 | /* Reinitialize the timer. */ |
| 711 | speed_timer.expires = jiffies + NET_LINK_UP_CHECK_INTERVAL; |
| 712 | add_timer(&speed_timer); |
Jesper Nilsson | bafef0a | 2007-11-14 17:00:55 -0800 | [diff] [blame] | 713 | |
| 714 | spin_unlock(&np->transceiver_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 715 | } |
| 716 | |
| 717 | static void |
| 718 | e100_negotiate(struct net_device* dev) |
| 719 | { |
Jesper Nilsson | bafef0a | 2007-11-14 17:00:55 -0800 | [diff] [blame] | 720 | struct net_local *np = netdev_priv(dev); |
| 721 | unsigned short data = e100_get_mdio_reg(dev, np->mii_if.phy_id, |
| 722 | MII_ADVERTISE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 723 | |
| 724 | /* Discard old speed and duplex settings */ |
| 725 | data &= ~(ADVERTISE_100HALF | ADVERTISE_100FULL | |
| 726 | ADVERTISE_10HALF | ADVERTISE_10FULL); |
| 727 | |
| 728 | switch (current_speed_selection) { |
Jesper Nilsson | bafef0a | 2007-11-14 17:00:55 -0800 | [diff] [blame] | 729 | case 10: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 730 | if (current_duplex == full) |
| 731 | data |= ADVERTISE_10FULL; |
| 732 | else if (current_duplex == half) |
| 733 | data |= ADVERTISE_10HALF; |
| 734 | else |
| 735 | data |= ADVERTISE_10HALF | ADVERTISE_10FULL; |
| 736 | break; |
| 737 | |
Jesper Nilsson | bafef0a | 2007-11-14 17:00:55 -0800 | [diff] [blame] | 738 | case 100: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 739 | if (current_duplex == full) |
| 740 | data |= ADVERTISE_100FULL; |
| 741 | else if (current_duplex == half) |
| 742 | data |= ADVERTISE_100HALF; |
| 743 | else |
| 744 | data |= ADVERTISE_100HALF | ADVERTISE_100FULL; |
| 745 | break; |
| 746 | |
Jesper Nilsson | bafef0a | 2007-11-14 17:00:55 -0800 | [diff] [blame] | 747 | case 0: /* Auto */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 748 | if (current_duplex == full) |
| 749 | data |= ADVERTISE_100FULL | ADVERTISE_10FULL; |
| 750 | else if (current_duplex == half) |
| 751 | data |= ADVERTISE_100HALF | ADVERTISE_10HALF; |
| 752 | else |
| 753 | data |= ADVERTISE_10HALF | ADVERTISE_10FULL | |
| 754 | ADVERTISE_100HALF | ADVERTISE_100FULL; |
| 755 | break; |
| 756 | |
Jesper Nilsson | bafef0a | 2007-11-14 17:00:55 -0800 | [diff] [blame] | 757 | default: /* assume autoneg speed and duplex */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 758 | data |= ADVERTISE_10HALF | ADVERTISE_10FULL | |
| 759 | ADVERTISE_100HALF | ADVERTISE_100FULL; |
Jesper Nilsson | bafef0a | 2007-11-14 17:00:55 -0800 | [diff] [blame] | 760 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 761 | } |
| 762 | |
Jesper Nilsson | bafef0a | 2007-11-14 17:00:55 -0800 | [diff] [blame] | 763 | e100_set_mdio_reg(dev, np->mii_if.phy_id, MII_ADVERTISE, data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 764 | |
Jesper Nilsson | e6cd197 | 2009-08-31 18:28:26 +0200 | [diff] [blame] | 765 | data = e100_get_mdio_reg(dev, np->mii_if.phy_id, MII_BMCR); |
Jesper Nilsson | bafef0a | 2007-11-14 17:00:55 -0800 | [diff] [blame] | 766 | if (autoneg_normal) { |
Jesper Nilsson | e6cd197 | 2009-08-31 18:28:26 +0200 | [diff] [blame] | 767 | /* Renegotiate with link partner */ |
| 768 | data |= BMCR_ANENABLE | BMCR_ANRESTART; |
| 769 | } else { |
| 770 | /* Don't negotiate speed or duplex */ |
| 771 | data &= ~(BMCR_ANENABLE | BMCR_ANRESTART); |
| 772 | |
| 773 | /* Set speed and duplex static */ |
| 774 | if (current_speed_selection == 10) |
| 775 | data &= ~BMCR_SPEED100; |
| 776 | else |
| 777 | data |= BMCR_SPEED100; |
| 778 | |
| 779 | if (current_duplex != full) |
| 780 | data &= ~BMCR_FULLDPLX; |
| 781 | else |
| 782 | data |= BMCR_FULLDPLX; |
Jesper Nilsson | bafef0a | 2007-11-14 17:00:55 -0800 | [diff] [blame] | 783 | } |
| 784 | e100_set_mdio_reg(dev, np->mii_if.phy_id, MII_BMCR, data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 785 | } |
| 786 | |
| 787 | static void |
| 788 | e100_set_speed(struct net_device* dev, unsigned long speed) |
| 789 | { |
Jesper Nilsson | bafef0a | 2007-11-14 17:00:55 -0800 | [diff] [blame] | 790 | struct net_local *np = netdev_priv(dev); |
| 791 | |
| 792 | spin_lock(&np->transceiver_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 793 | if (speed != current_speed_selection) { |
| 794 | current_speed_selection = speed; |
| 795 | e100_negotiate(dev); |
| 796 | } |
Jesper Nilsson | bafef0a | 2007-11-14 17:00:55 -0800 | [diff] [blame] | 797 | spin_unlock(&np->transceiver_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 798 | } |
| 799 | |
| 800 | static void |
| 801 | e100_check_duplex(unsigned long priv) |
| 802 | { |
| 803 | struct net_device *dev = (struct net_device *)priv; |
Jesper Nilsson | bafef0a | 2007-11-14 17:00:55 -0800 | [diff] [blame] | 804 | struct net_local *np = netdev_priv(dev); |
| 805 | int old_duplex; |
| 806 | |
| 807 | spin_lock(&np->transceiver_lock); |
| 808 | old_duplex = full_duplex; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 809 | transceiver->check_duplex(dev); |
| 810 | if (old_duplex != full_duplex) { |
| 811 | /* Duplex changed */ |
| 812 | SETF(network_rec_config_shadow, R_NETWORK_REC_CONFIG, duplex, full_duplex); |
| 813 | *R_NETWORK_REC_CONFIG = network_rec_config_shadow; |
| 814 | } |
| 815 | |
| 816 | /* Reinitialize the timer. */ |
| 817 | duplex_timer.expires = jiffies + NET_DUPLEX_CHECK_INTERVAL; |
| 818 | add_timer(&duplex_timer); |
| 819 | np->mii_if.full_duplex = full_duplex; |
Jesper Nilsson | bafef0a | 2007-11-14 17:00:55 -0800 | [diff] [blame] | 820 | spin_unlock(&np->transceiver_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 821 | } |
Jesper Nilsson | bafef0a | 2007-11-14 17:00:55 -0800 | [diff] [blame] | 822 | #if defined(CONFIG_ETRAX_NO_PHY) |
| 823 | static void |
| 824 | dummy_check_duplex(struct net_device* dev) |
| 825 | { |
| 826 | full_duplex = 1; |
| 827 | } |
| 828 | #else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 829 | static void |
| 830 | generic_check_duplex(struct net_device* dev) |
| 831 | { |
| 832 | unsigned long data; |
Jesper Nilsson | bafef0a | 2007-11-14 17:00:55 -0800 | [diff] [blame] | 833 | struct net_local *np = netdev_priv(dev); |
| 834 | |
| 835 | data = e100_get_mdio_reg(dev, np->mii_if.phy_id, MII_ADVERTISE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 836 | if ((data & ADVERTISE_10FULL) || |
| 837 | (data & ADVERTISE_100FULL)) |
| 838 | full_duplex = 1; |
| 839 | else |
| 840 | full_duplex = 0; |
| 841 | } |
| 842 | |
| 843 | static void |
| 844 | tdk_check_duplex(struct net_device* dev) |
| 845 | { |
| 846 | unsigned long data; |
Jesper Nilsson | bafef0a | 2007-11-14 17:00:55 -0800 | [diff] [blame] | 847 | struct net_local *np = netdev_priv(dev); |
| 848 | |
| 849 | data = e100_get_mdio_reg(dev, np->mii_if.phy_id, |
| 850 | MDIO_TDK_DIAGNOSTIC_REG); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 851 | full_duplex = (data & MDIO_TDK_DIAGNOSTIC_DPLX) ? 1 : 0; |
| 852 | } |
| 853 | |
| 854 | static void |
| 855 | broadcom_check_duplex(struct net_device* dev) |
| 856 | { |
| 857 | unsigned long data; |
Jesper Nilsson | bafef0a | 2007-11-14 17:00:55 -0800 | [diff] [blame] | 858 | struct net_local *np = netdev_priv(dev); |
| 859 | |
| 860 | data = e100_get_mdio_reg(dev, np->mii_if.phy_id, |
| 861 | MDIO_AUX_CTRL_STATUS_REG); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 862 | full_duplex = (data & MDIO_BC_FULL_DUPLEX_IND) ? 1 : 0; |
| 863 | } |
| 864 | |
| 865 | static void |
| 866 | intel_check_duplex(struct net_device* dev) |
| 867 | { |
| 868 | unsigned long data; |
Jesper Nilsson | bafef0a | 2007-11-14 17:00:55 -0800 | [diff] [blame] | 869 | struct net_local *np = netdev_priv(dev); |
| 870 | |
| 871 | data = e100_get_mdio_reg(dev, np->mii_if.phy_id, |
| 872 | MDIO_INT_STATUS_REG_2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 873 | full_duplex = (data & MDIO_INT_FULL_DUPLEX_IND) ? 1 : 0; |
| 874 | } |
Jesper Nilsson | bafef0a | 2007-11-14 17:00:55 -0800 | [diff] [blame] | 875 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 876 | static void |
| 877 | e100_set_duplex(struct net_device* dev, enum duplex new_duplex) |
| 878 | { |
Jesper Nilsson | bafef0a | 2007-11-14 17:00:55 -0800 | [diff] [blame] | 879 | struct net_local *np = netdev_priv(dev); |
| 880 | |
| 881 | spin_lock(&np->transceiver_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 882 | if (new_duplex != current_duplex) { |
| 883 | current_duplex = new_duplex; |
| 884 | e100_negotiate(dev); |
| 885 | } |
Jesper Nilsson | bafef0a | 2007-11-14 17:00:55 -0800 | [diff] [blame] | 886 | spin_unlock(&np->transceiver_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 887 | } |
| 888 | |
| 889 | static int |
| 890 | e100_probe_transceiver(struct net_device* dev) |
| 891 | { |
Andrew Morton | 633edf5 | 2007-11-14 17:00:58 -0800 | [diff] [blame] | 892 | int ret = 0; |
| 893 | |
Jesper Nilsson | bafef0a | 2007-11-14 17:00:55 -0800 | [diff] [blame] | 894 | #if !defined(CONFIG_ETRAX_NO_PHY) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 895 | unsigned int phyid_high; |
| 896 | unsigned int phyid_low; |
| 897 | unsigned int oui; |
| 898 | struct transceiver_ops* ops = NULL; |
Jesper Nilsson | bafef0a | 2007-11-14 17:00:55 -0800 | [diff] [blame] | 899 | struct net_local *np = netdev_priv(dev); |
| 900 | |
| 901 | spin_lock(&np->transceiver_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 902 | |
| 903 | /* Probe MDIO physical address */ |
Jesper Nilsson | bafef0a | 2007-11-14 17:00:55 -0800 | [diff] [blame] | 904 | for (np->mii_if.phy_id = 0; np->mii_if.phy_id <= 31; |
| 905 | np->mii_if.phy_id++) { |
| 906 | if (e100_get_mdio_reg(dev, |
| 907 | np->mii_if.phy_id, MII_BMSR) != 0xffff) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 908 | break; |
| 909 | } |
Andrew Morton | 633edf5 | 2007-11-14 17:00:58 -0800 | [diff] [blame] | 910 | if (np->mii_if.phy_id == 32) { |
| 911 | ret = -ENODEV; |
| 912 | goto out; |
| 913 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 914 | |
| 915 | /* Get manufacturer */ |
Jesper Nilsson | bafef0a | 2007-11-14 17:00:55 -0800 | [diff] [blame] | 916 | phyid_high = e100_get_mdio_reg(dev, np->mii_if.phy_id, MII_PHYSID1); |
| 917 | phyid_low = e100_get_mdio_reg(dev, np->mii_if.phy_id, MII_PHYSID2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 918 | oui = (phyid_high << 6) | (phyid_low >> 10); |
| 919 | |
| 920 | for (ops = &transceivers[0]; ops->oui; ops++) { |
| 921 | if (ops->oui == oui) |
| 922 | break; |
| 923 | } |
| 924 | transceiver = ops; |
Andrew Morton | 633edf5 | 2007-11-14 17:00:58 -0800 | [diff] [blame] | 925 | out: |
Jesper Nilsson | bafef0a | 2007-11-14 17:00:55 -0800 | [diff] [blame] | 926 | spin_unlock(&np->transceiver_lock); |
| 927 | #endif |
Andrew Morton | 633edf5 | 2007-11-14 17:00:58 -0800 | [diff] [blame] | 928 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 929 | } |
| 930 | |
| 931 | static int |
| 932 | e100_get_mdio_reg(struct net_device *dev, int phy_id, int location) |
| 933 | { |
| 934 | unsigned short cmd; /* Data to be sent on MDIO port */ |
| 935 | int data; /* Data read from MDIO */ |
| 936 | int bitCounter; |
| 937 | |
| 938 | /* Start of frame, OP Code, Physical Address, Register Address */ |
| 939 | cmd = (MDIO_START << 14) | (MDIO_READ << 12) | (phy_id << 7) | |
| 940 | (location << 2); |
| 941 | |
| 942 | e100_send_mdio_cmd(cmd, 0); |
| 943 | |
| 944 | data = 0; |
| 945 | |
| 946 | /* Data... */ |
| 947 | for (bitCounter=15; bitCounter>=0 ; bitCounter--) { |
| 948 | data |= (e100_receive_mdio_bit() << bitCounter); |
| 949 | } |
| 950 | |
| 951 | return data; |
| 952 | } |
| 953 | |
| 954 | static void |
| 955 | e100_set_mdio_reg(struct net_device *dev, int phy_id, int location, int value) |
| 956 | { |
| 957 | int bitCounter; |
| 958 | unsigned short cmd; |
| 959 | |
| 960 | cmd = (MDIO_START << 14) | (MDIO_WRITE << 12) | (phy_id << 7) | |
| 961 | (location << 2); |
| 962 | |
| 963 | e100_send_mdio_cmd(cmd, 1); |
| 964 | |
| 965 | /* Data... */ |
| 966 | for (bitCounter=15; bitCounter>=0 ; bitCounter--) { |
| 967 | e100_send_mdio_bit(GET_BIT(bitCounter, value)); |
| 968 | } |
| 969 | |
| 970 | } |
| 971 | |
| 972 | static void |
| 973 | e100_send_mdio_cmd(unsigned short cmd, int write_cmd) |
| 974 | { |
| 975 | int bitCounter; |
| 976 | unsigned char data = 0x2; |
| 977 | |
| 978 | /* Preamble */ |
| 979 | for (bitCounter = 31; bitCounter>= 0; bitCounter--) |
| 980 | e100_send_mdio_bit(GET_BIT(bitCounter, MDIO_PREAMBLE)); |
| 981 | |
| 982 | for (bitCounter = 15; bitCounter >= 2; bitCounter--) |
| 983 | e100_send_mdio_bit(GET_BIT(bitCounter, cmd)); |
| 984 | |
| 985 | /* Turnaround */ |
| 986 | for (bitCounter = 1; bitCounter >= 0 ; bitCounter--) |
| 987 | if (write_cmd) |
| 988 | e100_send_mdio_bit(GET_BIT(bitCounter, data)); |
| 989 | else |
| 990 | e100_receive_mdio_bit(); |
| 991 | } |
| 992 | |
| 993 | static void |
| 994 | e100_send_mdio_bit(unsigned char bit) |
| 995 | { |
| 996 | *R_NETWORK_MGM_CTRL = |
| 997 | IO_STATE(R_NETWORK_MGM_CTRL, mdoe, enable) | |
| 998 | IO_FIELD(R_NETWORK_MGM_CTRL, mdio, bit); |
| 999 | udelay(1); |
| 1000 | *R_NETWORK_MGM_CTRL = |
| 1001 | IO_STATE(R_NETWORK_MGM_CTRL, mdoe, enable) | |
| 1002 | IO_MASK(R_NETWORK_MGM_CTRL, mdck) | |
| 1003 | IO_FIELD(R_NETWORK_MGM_CTRL, mdio, bit); |
| 1004 | udelay(1); |
| 1005 | } |
| 1006 | |
| 1007 | static unsigned char |
Ben Hutchings | a55b138 | 2012-07-10 10:54:38 +0000 | [diff] [blame] | 1008 | e100_receive_mdio_bit(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1009 | { |
| 1010 | unsigned char bit; |
| 1011 | *R_NETWORK_MGM_CTRL = 0; |
| 1012 | bit = IO_EXTRACT(R_NETWORK_STAT, mdio, *R_NETWORK_STAT); |
| 1013 | udelay(1); |
| 1014 | *R_NETWORK_MGM_CTRL = IO_MASK(R_NETWORK_MGM_CTRL, mdck); |
| 1015 | udelay(1); |
| 1016 | return bit; |
| 1017 | } |
| 1018 | |
| 1019 | static void |
| 1020 | e100_reset_transceiver(struct net_device* dev) |
| 1021 | { |
Jesper Nilsson | bafef0a | 2007-11-14 17:00:55 -0800 | [diff] [blame] | 1022 | struct net_local *np = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1023 | unsigned short cmd; |
| 1024 | unsigned short data; |
| 1025 | int bitCounter; |
| 1026 | |
Jesper Nilsson | bafef0a | 2007-11-14 17:00:55 -0800 | [diff] [blame] | 1027 | data = e100_get_mdio_reg(dev, np->mii_if.phy_id, MII_BMCR); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1028 | |
Jesper Nilsson | bafef0a | 2007-11-14 17:00:55 -0800 | [diff] [blame] | 1029 | cmd = (MDIO_START << 14) | (MDIO_WRITE << 12) | (np->mii_if.phy_id << 7) | (MII_BMCR << 2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1030 | |
| 1031 | e100_send_mdio_cmd(cmd, 1); |
| 1032 | |
| 1033 | data |= 0x8000; |
| 1034 | |
| 1035 | for (bitCounter = 15; bitCounter >= 0 ; bitCounter--) { |
| 1036 | e100_send_mdio_bit(GET_BIT(bitCounter, data)); |
| 1037 | } |
| 1038 | } |
| 1039 | |
| 1040 | /* Called by upper layers if they decide it took too long to complete |
| 1041 | * sending a packet - we need to reset and stuff. |
| 1042 | */ |
| 1043 | |
| 1044 | static void |
| 1045 | e100_tx_timeout(struct net_device *dev) |
| 1046 | { |
Jesper Nilsson | bafef0a | 2007-11-14 17:00:55 -0800 | [diff] [blame] | 1047 | struct net_local *np = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1048 | unsigned long flags; |
| 1049 | |
| 1050 | spin_lock_irqsave(&np->lock, flags); |
| 1051 | |
| 1052 | printk(KERN_WARNING "%s: transmit timed out, %s?\n", dev->name, |
| 1053 | tx_done(dev) ? "IRQ problem" : "network cable problem"); |
| 1054 | |
| 1055 | /* remember we got an error */ |
| 1056 | |
Tobias Klauser | 40fe7d8 | 2010-12-02 07:22:05 +0000 | [diff] [blame] | 1057 | dev->stats.tx_errors++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1058 | |
| 1059 | /* reset the TX DMA in case it has hung on something */ |
| 1060 | |
| 1061 | RESET_DMA(NETWORK_TX_DMA_NBR); |
| 1062 | WAIT_DMA(NETWORK_TX_DMA_NBR); |
| 1063 | |
| 1064 | /* Reset the transceiver. */ |
| 1065 | |
| 1066 | e100_reset_transceiver(dev); |
| 1067 | |
| 1068 | /* and get rid of the packets that never got an interrupt */ |
Jesper Nilsson | bafef0a | 2007-11-14 17:00:55 -0800 | [diff] [blame] | 1069 | while (myFirstTxDesc != myNextTxDesc) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1070 | dev_kfree_skb(myFirstTxDesc->skb); |
| 1071 | myFirstTxDesc->skb = 0; |
| 1072 | myFirstTxDesc = phys_to_virt(myFirstTxDesc->descr.next); |
| 1073 | } |
| 1074 | |
| 1075 | /* Set up transmit DMA channel so it can be restarted later */ |
| 1076 | *R_DMA_CH0_FIRST = 0; |
| 1077 | *R_DMA_CH0_DESCR = virt_to_phys(myLastTxDesc); |
| 1078 | |
| 1079 | /* tell the upper layers we're ok again */ |
| 1080 | |
| 1081 | netif_wake_queue(dev); |
| 1082 | spin_unlock_irqrestore(&np->lock, flags); |
| 1083 | } |
| 1084 | |
| 1085 | |
| 1086 | /* This will only be invoked if the driver is _not_ in XOFF state. |
| 1087 | * What this means is that we need not check it, and that this |
| 1088 | * invariant will hold if we make sure that the netif_*_queue() |
| 1089 | * calls are done at the proper times. |
| 1090 | */ |
| 1091 | |
| 1092 | static int |
| 1093 | e100_send_packet(struct sk_buff *skb, struct net_device *dev) |
| 1094 | { |
Jesper Nilsson | bafef0a | 2007-11-14 17:00:55 -0800 | [diff] [blame] | 1095 | struct net_local *np = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1096 | unsigned char *buf = skb->data; |
| 1097 | unsigned long flags; |
| 1098 | |
| 1099 | #ifdef ETHDEBUG |
| 1100 | printk("send packet len %d\n", length); |
| 1101 | #endif |
| 1102 | spin_lock_irqsave(&np->lock, flags); /* protect from tx_interrupt and ourself */ |
| 1103 | |
| 1104 | myNextTxDesc->skb = skb; |
| 1105 | |
Florian Westphal | 860e953 | 2016-05-03 16:33:13 +0200 | [diff] [blame] | 1106 | netif_trans_update(dev); /* NETIF_F_LLTX driver :( */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1107 | |
Jesper Nilsson | bafef0a | 2007-11-14 17:00:55 -0800 | [diff] [blame] | 1108 | e100_hardware_send_packet(np, buf, skb->len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1109 | |
| 1110 | myNextTxDesc = phys_to_virt(myNextTxDesc->descr.next); |
| 1111 | |
| 1112 | /* Stop queue if full */ |
| 1113 | if (myNextTxDesc == myFirstTxDesc) { |
| 1114 | netif_stop_queue(dev); |
| 1115 | } |
| 1116 | |
| 1117 | spin_unlock_irqrestore(&np->lock, flags); |
| 1118 | |
Patrick McHardy | 6ed1065 | 2009-06-23 06:03:08 +0000 | [diff] [blame] | 1119 | return NETDEV_TX_OK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1120 | } |
| 1121 | |
| 1122 | /* |
| 1123 | * The typical workload of the driver: |
| 1124 | * Handle the network interface interrupts. |
| 1125 | */ |
| 1126 | |
| 1127 | static irqreturn_t |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 1128 | e100rxtx_interrupt(int irq, void *dev_id) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1129 | { |
| 1130 | struct net_device *dev = (struct net_device *)dev_id; |
Jesper Nilsson | bafef0a | 2007-11-14 17:00:55 -0800 | [diff] [blame] | 1131 | unsigned long irqbits; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1132 | |
Jesper Nilsson | bafef0a | 2007-11-14 17:00:55 -0800 | [diff] [blame] | 1133 | /* |
| 1134 | * Note that both rx and tx interrupts are blocked at this point, |
| 1135 | * regardless of which got us here. |
| 1136 | */ |
| 1137 | |
| 1138 | irqbits = *R_IRQ_MASK2_RD; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1139 | |
| 1140 | /* Handle received packets */ |
| 1141 | if (irqbits & IO_STATE(R_IRQ_MASK2_RD, dma1_eop, active)) { |
| 1142 | /* acknowledge the eop interrupt */ |
| 1143 | |
| 1144 | *R_DMA_CH1_CLR_INTR = IO_STATE(R_DMA_CH1_CLR_INTR, clr_eop, do); |
| 1145 | |
| 1146 | /* check if one or more complete packets were indeed received */ |
| 1147 | |
| 1148 | while ((*R_DMA_CH1_FIRST != virt_to_phys(myNextRxDesc)) && |
| 1149 | (myNextRxDesc != myLastRxDesc)) { |
| 1150 | /* Take out the buffer and give it to the OS, then |
| 1151 | * allocate a new buffer to put a packet in. |
| 1152 | */ |
| 1153 | e100_rx(dev); |
Tobias Klauser | 40fe7d8 | 2010-12-02 07:22:05 +0000 | [diff] [blame] | 1154 | dev->stats.rx_packets++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1155 | /* restart/continue on the channel, for safety */ |
| 1156 | *R_DMA_CH1_CMD = IO_STATE(R_DMA_CH1_CMD, cmd, restart); |
| 1157 | /* clear dma channel 1 eop/descr irq bits */ |
| 1158 | *R_DMA_CH1_CLR_INTR = |
| 1159 | IO_STATE(R_DMA_CH1_CLR_INTR, clr_eop, do) | |
| 1160 | IO_STATE(R_DMA_CH1_CLR_INTR, clr_descr, do); |
| 1161 | |
| 1162 | /* now, we might have gotten another packet |
| 1163 | so we have to loop back and check if so */ |
| 1164 | } |
| 1165 | } |
| 1166 | |
| 1167 | /* Report any packets that have been sent */ |
Jesper Nilsson | bafef0a | 2007-11-14 17:00:55 -0800 | [diff] [blame] | 1168 | while (virt_to_phys(myFirstTxDesc) != *R_DMA_CH0_FIRST && |
| 1169 | (netif_queue_stopped(dev) || myFirstTxDesc != myNextTxDesc)) { |
Tobias Klauser | 40fe7d8 | 2010-12-02 07:22:05 +0000 | [diff] [blame] | 1170 | dev->stats.tx_bytes += myFirstTxDesc->skb->len; |
| 1171 | dev->stats.tx_packets++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1172 | |
| 1173 | /* dma is ready with the transmission of the data in tx_skb, so now |
| 1174 | we can release the skb memory */ |
| 1175 | dev_kfree_skb_irq(myFirstTxDesc->skb); |
| 1176 | myFirstTxDesc->skb = 0; |
| 1177 | myFirstTxDesc = phys_to_virt(myFirstTxDesc->descr.next); |
Jesper Nilsson | bafef0a | 2007-11-14 17:00:55 -0800 | [diff] [blame] | 1178 | /* Wake up queue. */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1179 | netif_wake_queue(dev); |
| 1180 | } |
| 1181 | |
Jesper Nilsson | bafef0a | 2007-11-14 17:00:55 -0800 | [diff] [blame] | 1182 | if (irqbits & IO_STATE(R_IRQ_MASK2_RD, dma0_eop, active)) { |
| 1183 | /* acknowledge the eop interrupt. */ |
| 1184 | *R_DMA_CH0_CLR_INTR = IO_STATE(R_DMA_CH0_CLR_INTR, clr_eop, do); |
| 1185 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1186 | |
| 1187 | return IRQ_HANDLED; |
| 1188 | } |
| 1189 | |
| 1190 | static irqreturn_t |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 1191 | e100nw_interrupt(int irq, void *dev_id) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1192 | { |
| 1193 | struct net_device *dev = (struct net_device *)dev_id; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1194 | unsigned long irqbits = *R_IRQ_MASK0_RD; |
| 1195 | |
| 1196 | /* check for underrun irq */ |
| 1197 | if (irqbits & IO_STATE(R_IRQ_MASK0_RD, underrun, active)) { |
| 1198 | SETS(network_tr_ctrl_shadow, R_NETWORK_TR_CTRL, clr_error, clr); |
| 1199 | *R_NETWORK_TR_CTRL = network_tr_ctrl_shadow; |
| 1200 | SETS(network_tr_ctrl_shadow, R_NETWORK_TR_CTRL, clr_error, nop); |
Tobias Klauser | 40fe7d8 | 2010-12-02 07:22:05 +0000 | [diff] [blame] | 1201 | dev->stats.tx_errors++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1202 | D(printk("ethernet receiver underrun!\n")); |
| 1203 | } |
| 1204 | |
| 1205 | /* check for overrun irq */ |
| 1206 | if (irqbits & IO_STATE(R_IRQ_MASK0_RD, overrun, active)) { |
Tobias Klauser | 40fe7d8 | 2010-12-02 07:22:05 +0000 | [diff] [blame] | 1207 | update_rx_stats(&dev->stats); /* this will ack the irq */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1208 | D(printk("ethernet receiver overrun!\n")); |
| 1209 | } |
| 1210 | /* check for excessive collision irq */ |
| 1211 | if (irqbits & IO_STATE(R_IRQ_MASK0_RD, excessive_col, active)) { |
| 1212 | SETS(network_tr_ctrl_shadow, R_NETWORK_TR_CTRL, clr_error, clr); |
| 1213 | *R_NETWORK_TR_CTRL = network_tr_ctrl_shadow; |
| 1214 | SETS(network_tr_ctrl_shadow, R_NETWORK_TR_CTRL, clr_error, nop); |
Tobias Klauser | 40fe7d8 | 2010-12-02 07:22:05 +0000 | [diff] [blame] | 1215 | dev->stats.tx_errors++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1216 | D(printk("ethernet excessive collisions!\n")); |
| 1217 | } |
| 1218 | return IRQ_HANDLED; |
| 1219 | } |
| 1220 | |
| 1221 | /* We have a good packet(s), get it/them out of the buffers. */ |
| 1222 | static void |
| 1223 | e100_rx(struct net_device *dev) |
| 1224 | { |
| 1225 | struct sk_buff *skb; |
| 1226 | int length = 0; |
Jesper Nilsson | bafef0a | 2007-11-14 17:00:55 -0800 | [diff] [blame] | 1227 | struct net_local *np = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1228 | unsigned char *skb_data_ptr; |
| 1229 | #ifdef ETHDEBUG |
| 1230 | int i; |
| 1231 | #endif |
Jesper Nilsson | bafef0a | 2007-11-14 17:00:55 -0800 | [diff] [blame] | 1232 | etrax_eth_descr *prevRxDesc; /* The descriptor right before myNextRxDesc */ |
| 1233 | spin_lock(&np->led_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1234 | if (!led_active && time_after(jiffies, led_next_time)) { |
| 1235 | /* light the network leds depending on the current speed. */ |
| 1236 | e100_set_network_leds(NETWORK_ACTIVITY); |
| 1237 | |
| 1238 | /* Set the earliest time we may clear the LED */ |
| 1239 | led_next_time = jiffies + NET_FLASH_TIME; |
| 1240 | led_active = 1; |
| 1241 | mod_timer(&clear_led_timer, jiffies + HZ/10); |
| 1242 | } |
Jesper Nilsson | bafef0a | 2007-11-14 17:00:55 -0800 | [diff] [blame] | 1243 | spin_unlock(&np->led_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1244 | |
| 1245 | length = myNextRxDesc->descr.hw_len - 4; |
Tobias Klauser | 40fe7d8 | 2010-12-02 07:22:05 +0000 | [diff] [blame] | 1246 | dev->stats.rx_bytes += length; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1247 | |
| 1248 | #ifdef ETHDEBUG |
| 1249 | printk("Got a packet of length %d:\n", length); |
| 1250 | /* dump the first bytes in the packet */ |
| 1251 | skb_data_ptr = (unsigned char *)phys_to_virt(myNextRxDesc->descr.buf); |
| 1252 | for (i = 0; i < 8; i++) { |
| 1253 | printk("%d: %.2x %.2x %.2x %.2x %.2x %.2x %.2x %.2x\n", i * 8, |
| 1254 | skb_data_ptr[0],skb_data_ptr[1],skb_data_ptr[2],skb_data_ptr[3], |
| 1255 | skb_data_ptr[4],skb_data_ptr[5],skb_data_ptr[6],skb_data_ptr[7]); |
| 1256 | skb_data_ptr += 8; |
| 1257 | } |
| 1258 | #endif |
| 1259 | |
| 1260 | if (length < RX_COPYBREAK) { |
| 1261 | /* Small packet, copy data */ |
| 1262 | skb = dev_alloc_skb(length - ETHER_HEAD_LEN); |
| 1263 | if (!skb) { |
Tobias Klauser | 40fe7d8 | 2010-12-02 07:22:05 +0000 | [diff] [blame] | 1264 | dev->stats.rx_errors++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1265 | printk(KERN_NOTICE "%s: Memory squeeze, dropping packet.\n", dev->name); |
Jesper Nilsson | bafef0a | 2007-11-14 17:00:55 -0800 | [diff] [blame] | 1266 | goto update_nextrxdesc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1267 | } |
| 1268 | |
| 1269 | skb_put(skb, length - ETHER_HEAD_LEN); /* allocate room for the packet body */ |
| 1270 | skb_data_ptr = skb_push(skb, ETHER_HEAD_LEN); /* allocate room for the header */ |
| 1271 | |
| 1272 | #ifdef ETHDEBUG |
| 1273 | printk("head = 0x%x, data = 0x%x, tail = 0x%x, end = 0x%x\n", |
Arnaldo Carvalho de Melo | 4305b54 | 2007-04-19 20:43:29 -0700 | [diff] [blame] | 1274 | skb->head, skb->data, skb_tail_pointer(skb), |
| 1275 | skb_end_pointer(skb)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1276 | printk("copying packet to 0x%x.\n", skb_data_ptr); |
| 1277 | #endif |
| 1278 | |
| 1279 | memcpy(skb_data_ptr, phys_to_virt(myNextRxDesc->descr.buf), length); |
| 1280 | } |
| 1281 | else { |
| 1282 | /* Large packet, send directly to upper layers and allocate new |
| 1283 | * memory (aligned to cache line boundary to avoid bug). |
Jesper Nilsson | bafef0a | 2007-11-14 17:00:55 -0800 | [diff] [blame] | 1284 | * Before sending the skb to upper layers we must make sure |
| 1285 | * that skb->data points to the aligned start of the packet. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1286 | */ |
| 1287 | int align; |
| 1288 | struct sk_buff *new_skb = dev_alloc_skb(MAX_MEDIA_DATA_SIZE + 2 * L1_CACHE_BYTES); |
| 1289 | if (!new_skb) { |
Tobias Klauser | 40fe7d8 | 2010-12-02 07:22:05 +0000 | [diff] [blame] | 1290 | dev->stats.rx_errors++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1291 | printk(KERN_NOTICE "%s: Memory squeeze, dropping packet.\n", dev->name); |
Jesper Nilsson | bafef0a | 2007-11-14 17:00:55 -0800 | [diff] [blame] | 1292 | goto update_nextrxdesc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1293 | } |
| 1294 | skb = myNextRxDesc->skb; |
| 1295 | align = (int)phys_to_virt(myNextRxDesc->descr.buf) - (int)skb->data; |
| 1296 | skb_put(skb, length + align); |
| 1297 | skb_pull(skb, align); /* Remove alignment bytes */ |
| 1298 | myNextRxDesc->skb = new_skb; |
| 1299 | myNextRxDesc->descr.buf = L1_CACHE_ALIGN(virt_to_phys(myNextRxDesc->skb->data)); |
| 1300 | } |
| 1301 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1302 | skb->protocol = eth_type_trans(skb, dev); |
| 1303 | |
| 1304 | /* Send the packet to the upper layers */ |
| 1305 | netif_rx(skb); |
| 1306 | |
Jesper Nilsson | bafef0a | 2007-11-14 17:00:55 -0800 | [diff] [blame] | 1307 | update_nextrxdesc: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1308 | /* Prepare for next packet */ |
| 1309 | myNextRxDesc->descr.status = 0; |
Jesper Nilsson | bafef0a | 2007-11-14 17:00:55 -0800 | [diff] [blame] | 1310 | prevRxDesc = myNextRxDesc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1311 | myNextRxDesc = phys_to_virt(myNextRxDesc->descr.next); |
| 1312 | |
| 1313 | rx_queue_len++; |
| 1314 | |
| 1315 | /* Check if descriptors should be returned */ |
| 1316 | if (rx_queue_len == RX_QUEUE_THRESHOLD) { |
| 1317 | flush_etrax_cache(); |
Jesper Nilsson | bafef0a | 2007-11-14 17:00:55 -0800 | [diff] [blame] | 1318 | prevRxDesc->descr.ctrl |= d_eol; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1319 | myLastRxDesc->descr.ctrl &= ~d_eol; |
Jesper Nilsson | bafef0a | 2007-11-14 17:00:55 -0800 | [diff] [blame] | 1320 | myLastRxDesc = prevRxDesc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1321 | rx_queue_len = 0; |
| 1322 | } |
| 1323 | } |
| 1324 | |
| 1325 | /* The inverse routine to net_open(). */ |
| 1326 | static int |
| 1327 | e100_close(struct net_device *dev) |
| 1328 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1329 | printk(KERN_INFO "Closing %s.\n", dev->name); |
| 1330 | |
| 1331 | netif_stop_queue(dev); |
| 1332 | |
| 1333 | *R_IRQ_MASK0_CLR = |
| 1334 | IO_STATE(R_IRQ_MASK0_CLR, overrun, clr) | |
| 1335 | IO_STATE(R_IRQ_MASK0_CLR, underrun, clr) | |
| 1336 | IO_STATE(R_IRQ_MASK0_CLR, excessive_col, clr); |
| 1337 | |
| 1338 | *R_IRQ_MASK2_CLR = |
| 1339 | IO_STATE(R_IRQ_MASK2_CLR, dma0_descr, clr) | |
| 1340 | IO_STATE(R_IRQ_MASK2_CLR, dma0_eop, clr) | |
| 1341 | IO_STATE(R_IRQ_MASK2_CLR, dma1_descr, clr) | |
| 1342 | IO_STATE(R_IRQ_MASK2_CLR, dma1_eop, clr); |
| 1343 | |
| 1344 | /* Stop the receiver and the transmitter */ |
| 1345 | |
| 1346 | RESET_DMA(NETWORK_TX_DMA_NBR); |
| 1347 | RESET_DMA(NETWORK_RX_DMA_NBR); |
| 1348 | |
| 1349 | /* Flush the Tx and disable Rx here. */ |
| 1350 | |
| 1351 | free_irq(NETWORK_DMA_RX_IRQ_NBR, (void *)dev); |
| 1352 | free_irq(NETWORK_DMA_TX_IRQ_NBR, (void *)dev); |
| 1353 | free_irq(NETWORK_STATUS_IRQ_NBR, (void *)dev); |
| 1354 | |
Jesper Nilsson | bafef0a | 2007-11-14 17:00:55 -0800 | [diff] [blame] | 1355 | cris_free_dma(NETWORK_TX_DMA_NBR, cardname); |
| 1356 | cris_free_dma(NETWORK_RX_DMA_NBR, cardname); |
| 1357 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1358 | /* Update the statistics here. */ |
| 1359 | |
Tobias Klauser | 40fe7d8 | 2010-12-02 07:22:05 +0000 | [diff] [blame] | 1360 | update_rx_stats(&dev->stats); |
| 1361 | update_tx_stats(&dev->stats); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1362 | |
| 1363 | /* Stop speed/duplex timers */ |
| 1364 | del_timer(&speed_timer); |
| 1365 | del_timer(&duplex_timer); |
| 1366 | |
| 1367 | return 0; |
| 1368 | } |
| 1369 | |
| 1370 | static int |
| 1371 | e100_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd) |
| 1372 | { |
| 1373 | struct mii_ioctl_data *data = if_mii(ifr); |
| 1374 | struct net_local *np = netdev_priv(dev); |
Jesper Nilsson | bafef0a | 2007-11-14 17:00:55 -0800 | [diff] [blame] | 1375 | int rc = 0; |
| 1376 | int old_autoneg; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1377 | |
| 1378 | spin_lock(&np->lock); /* Preempt protection */ |
| 1379 | switch (cmd) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1380 | /* The ioctls below should be considered obsolete but are */ |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 1381 | /* still present for compatibility with old scripts/apps */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1382 | case SET_ETH_SPEED_10: /* 10 Mbps */ |
| 1383 | e100_set_speed(dev, 10); |
| 1384 | break; |
| 1385 | case SET_ETH_SPEED_100: /* 100 Mbps */ |
| 1386 | e100_set_speed(dev, 100); |
| 1387 | break; |
Jesper Nilsson | bafef0a | 2007-11-14 17:00:55 -0800 | [diff] [blame] | 1388 | case SET_ETH_SPEED_AUTO: /* Auto-negotiate speed */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1389 | e100_set_speed(dev, 0); |
| 1390 | break; |
Jesper Nilsson | bafef0a | 2007-11-14 17:00:55 -0800 | [diff] [blame] | 1391 | case SET_ETH_DUPLEX_HALF: /* Half duplex */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1392 | e100_set_duplex(dev, half); |
| 1393 | break; |
Jesper Nilsson | bafef0a | 2007-11-14 17:00:55 -0800 | [diff] [blame] | 1394 | case SET_ETH_DUPLEX_FULL: /* Full duplex */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1395 | e100_set_duplex(dev, full); |
| 1396 | break; |
Jesper Nilsson | bafef0a | 2007-11-14 17:00:55 -0800 | [diff] [blame] | 1397 | case SET_ETH_DUPLEX_AUTO: /* Auto-negotiate duplex */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1398 | e100_set_duplex(dev, autoneg); |
| 1399 | break; |
Jesper Nilsson | bafef0a | 2007-11-14 17:00:55 -0800 | [diff] [blame] | 1400 | case SET_ETH_AUTONEG: |
| 1401 | old_autoneg = autoneg_normal; |
| 1402 | autoneg_normal = *(int*)data; |
| 1403 | if (autoneg_normal != old_autoneg) |
| 1404 | e100_negotiate(dev); |
| 1405 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1406 | default: |
Jesper Nilsson | bafef0a | 2007-11-14 17:00:55 -0800 | [diff] [blame] | 1407 | rc = generic_mii_ioctl(&np->mii_if, if_mii(ifr), |
| 1408 | cmd, NULL); |
| 1409 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1410 | } |
| 1411 | spin_unlock(&np->lock); |
Jesper Nilsson | bafef0a | 2007-11-14 17:00:55 -0800 | [diff] [blame] | 1412 | return rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1413 | } |
| 1414 | |
Philippe Reynes | bb37056 | 2017-03-25 19:39:05 +0100 | [diff] [blame] | 1415 | static int e100_get_link_ksettings(struct net_device *dev, |
| 1416 | struct ethtool_link_ksettings *cmd) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1417 | { |
Jesper Nilsson | bafef0a | 2007-11-14 17:00:55 -0800 | [diff] [blame] | 1418 | struct net_local *np = netdev_priv(dev); |
Philippe Reynes | bb37056 | 2017-03-25 19:39:05 +0100 | [diff] [blame] | 1419 | u32 supported; |
Christoph Hellwig | 76f2b4d | 2005-11-07 06:18:57 +0100 | [diff] [blame] | 1420 | |
Jesper Nilsson | bafef0a | 2007-11-14 17:00:55 -0800 | [diff] [blame] | 1421 | spin_lock_irq(&np->lock); |
yuval.shaia@oracle.com | 82c01a8 | 2017-06-04 20:22:00 +0300 | [diff] [blame] | 1422 | mii_ethtool_get_link_ksettings(&np->mii_if, cmd); |
Jesper Nilsson | bafef0a | 2007-11-14 17:00:55 -0800 | [diff] [blame] | 1423 | spin_unlock_irq(&np->lock); |
Christoph Hellwig | 76f2b4d | 2005-11-07 06:18:57 +0100 | [diff] [blame] | 1424 | |
Jesper Nilsson | bafef0a | 2007-11-14 17:00:55 -0800 | [diff] [blame] | 1425 | /* The PHY may support 1000baseT, but the Etrax100 does not. */ |
Philippe Reynes | bb37056 | 2017-03-25 19:39:05 +0100 | [diff] [blame] | 1426 | ethtool_convert_link_mode_to_legacy_u32(&supported, |
| 1427 | cmd->link_modes.supported); |
| 1428 | |
| 1429 | supported &= ~(SUPPORTED_1000baseT_Half | SUPPORTED_1000baseT_Full); |
| 1430 | |
| 1431 | ethtool_convert_legacy_u32_to_link_mode(cmd->link_modes.supported, |
| 1432 | supported); |
| 1433 | |
yuval.shaia@oracle.com | 82c01a8 | 2017-06-04 20:22:00 +0300 | [diff] [blame] | 1434 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1435 | } |
| 1436 | |
Philippe Reynes | bb37056 | 2017-03-25 19:39:05 +0100 | [diff] [blame] | 1437 | static int e100_set_link_ksettings(struct net_device *dev, |
| 1438 | const struct ethtool_link_ksettings *ecmd) |
Christoph Hellwig | 76f2b4d | 2005-11-07 06:18:57 +0100 | [diff] [blame] | 1439 | { |
Philippe Reynes | bb37056 | 2017-03-25 19:39:05 +0100 | [diff] [blame] | 1440 | if (ecmd->base.autoneg == AUTONEG_ENABLE) { |
Christoph Hellwig | 76f2b4d | 2005-11-07 06:18:57 +0100 | [diff] [blame] | 1441 | e100_set_duplex(dev, autoneg); |
| 1442 | e100_set_speed(dev, 0); |
| 1443 | } else { |
Philippe Reynes | bb37056 | 2017-03-25 19:39:05 +0100 | [diff] [blame] | 1444 | e100_set_duplex(dev, ecmd->base.duplex == DUPLEX_HALF ? |
| 1445 | half : full); |
| 1446 | e100_set_speed(dev, ecmd->base.speed == SPEED_10 ? 10 : 100); |
Christoph Hellwig | 76f2b4d | 2005-11-07 06:18:57 +0100 | [diff] [blame] | 1447 | } |
| 1448 | |
| 1449 | return 0; |
| 1450 | } |
| 1451 | |
| 1452 | static void e100_get_drvinfo(struct net_device *dev, |
| 1453 | struct ethtool_drvinfo *info) |
| 1454 | { |
Jiri Pirko | 7826d43 | 2013-01-06 00:44:26 +0000 | [diff] [blame] | 1455 | strlcpy(info->driver, "ETRAX 100LX", sizeof(info->driver)); |
| 1456 | strlcpy(info->version, "$Revision: 1.31 $", sizeof(info->version)); |
| 1457 | strlcpy(info->fw_version, "N/A", sizeof(info->fw_version)); |
| 1458 | strlcpy(info->bus_info, "N/A", sizeof(info->bus_info)); |
Christoph Hellwig | 76f2b4d | 2005-11-07 06:18:57 +0100 | [diff] [blame] | 1459 | } |
| 1460 | |
| 1461 | static int e100_nway_reset(struct net_device *dev) |
| 1462 | { |
| 1463 | if (current_duplex == autoneg && current_speed_selection == 0) |
| 1464 | e100_negotiate(dev); |
| 1465 | return 0; |
| 1466 | } |
| 1467 | |
Jeff Garzik | 7282d49 | 2006-09-13 14:30:00 -0400 | [diff] [blame] | 1468 | static const struct ethtool_ops e100_ethtool_ops = { |
Christoph Hellwig | 76f2b4d | 2005-11-07 06:18:57 +0100 | [diff] [blame] | 1469 | .get_drvinfo = e100_get_drvinfo, |
| 1470 | .nway_reset = e100_nway_reset, |
| 1471 | .get_link = ethtool_op_get_link, |
Philippe Reynes | bb37056 | 2017-03-25 19:39:05 +0100 | [diff] [blame] | 1472 | .get_link_ksettings = e100_get_link_ksettings, |
| 1473 | .set_link_ksettings = e100_set_link_ksettings, |
Christoph Hellwig | 76f2b4d | 2005-11-07 06:18:57 +0100 | [diff] [blame] | 1474 | }; |
| 1475 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1476 | static int |
| 1477 | e100_set_config(struct net_device *dev, struct ifmap *map) |
| 1478 | { |
Jesper Nilsson | bafef0a | 2007-11-14 17:00:55 -0800 | [diff] [blame] | 1479 | struct net_local *np = netdev_priv(dev); |
| 1480 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1481 | spin_lock(&np->lock); /* Preempt protection */ |
| 1482 | |
| 1483 | switch(map->port) { |
| 1484 | case IF_PORT_UNKNOWN: |
| 1485 | /* Use autoneg */ |
| 1486 | e100_set_speed(dev, 0); |
| 1487 | e100_set_duplex(dev, autoneg); |
| 1488 | break; |
| 1489 | case IF_PORT_10BASET: |
| 1490 | e100_set_speed(dev, 10); |
| 1491 | e100_set_duplex(dev, autoneg); |
| 1492 | break; |
| 1493 | case IF_PORT_100BASET: |
| 1494 | case IF_PORT_100BASETX: |
| 1495 | e100_set_speed(dev, 100); |
| 1496 | e100_set_duplex(dev, autoneg); |
| 1497 | break; |
| 1498 | case IF_PORT_100BASEFX: |
| 1499 | case IF_PORT_10BASE2: |
| 1500 | case IF_PORT_AUI: |
| 1501 | spin_unlock(&np->lock); |
| 1502 | return -EOPNOTSUPP; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1503 | default: |
| 1504 | printk(KERN_ERR "%s: Invalid media selected", dev->name); |
| 1505 | spin_unlock(&np->lock); |
| 1506 | return -EINVAL; |
| 1507 | } |
| 1508 | spin_unlock(&np->lock); |
| 1509 | return 0; |
| 1510 | } |
| 1511 | |
| 1512 | static void |
| 1513 | update_rx_stats(struct net_device_stats *es) |
| 1514 | { |
| 1515 | unsigned long r = *R_REC_COUNTERS; |
| 1516 | /* update stats relevant to reception errors */ |
| 1517 | es->rx_fifo_errors += IO_EXTRACT(R_REC_COUNTERS, congestion, r); |
| 1518 | es->rx_crc_errors += IO_EXTRACT(R_REC_COUNTERS, crc_error, r); |
| 1519 | es->rx_frame_errors += IO_EXTRACT(R_REC_COUNTERS, alignment_error, r); |
| 1520 | es->rx_length_errors += IO_EXTRACT(R_REC_COUNTERS, oversize, r); |
| 1521 | } |
| 1522 | |
| 1523 | static void |
| 1524 | update_tx_stats(struct net_device_stats *es) |
| 1525 | { |
| 1526 | unsigned long r = *R_TR_COUNTERS; |
| 1527 | /* update stats relevant to transmission errors */ |
| 1528 | es->collisions += |
| 1529 | IO_EXTRACT(R_TR_COUNTERS, single_col, r) + |
| 1530 | IO_EXTRACT(R_TR_COUNTERS, multiple_col, r); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1531 | } |
| 1532 | |
| 1533 | /* |
| 1534 | * Get the current statistics. |
| 1535 | * This may be called with the card open or closed. |
| 1536 | */ |
| 1537 | static struct net_device_stats * |
| 1538 | e100_get_stats(struct net_device *dev) |
| 1539 | { |
Jesper Nilsson | bafef0a | 2007-11-14 17:00:55 -0800 | [diff] [blame] | 1540 | struct net_local *lp = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1541 | unsigned long flags; |
Jesper Nilsson | bafef0a | 2007-11-14 17:00:55 -0800 | [diff] [blame] | 1542 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1543 | spin_lock_irqsave(&lp->lock, flags); |
| 1544 | |
Tobias Klauser | 40fe7d8 | 2010-12-02 07:22:05 +0000 | [diff] [blame] | 1545 | update_rx_stats(&dev->stats); |
| 1546 | update_tx_stats(&dev->stats); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1547 | |
| 1548 | spin_unlock_irqrestore(&lp->lock, flags); |
Tobias Klauser | 40fe7d8 | 2010-12-02 07:22:05 +0000 | [diff] [blame] | 1549 | return &dev->stats; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1550 | } |
| 1551 | |
| 1552 | /* |
| 1553 | * Set or clear the multicast filter for this adaptor. |
| 1554 | * num_addrs == -1 Promiscuous mode, receive all packets |
| 1555 | * num_addrs == 0 Normal mode, clear multicast list |
| 1556 | * num_addrs > 0 Multicast mode, receive normal and MC packets, |
| 1557 | * and do best-effort filtering. |
| 1558 | */ |
| 1559 | static void |
| 1560 | set_multicast_list(struct net_device *dev) |
| 1561 | { |
Jesper Nilsson | bafef0a | 2007-11-14 17:00:55 -0800 | [diff] [blame] | 1562 | struct net_local *lp = netdev_priv(dev); |
Jiri Pirko | 4cd24ea | 2010-02-08 04:30:35 +0000 | [diff] [blame] | 1563 | int num_addr = netdev_mc_count(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1564 | unsigned long int lo_bits; |
| 1565 | unsigned long int hi_bits; |
Jesper Nilsson | bafef0a | 2007-11-14 17:00:55 -0800 | [diff] [blame] | 1566 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1567 | spin_lock(&lp->lock); |
Jesper Nilsson | bafef0a | 2007-11-14 17:00:55 -0800 | [diff] [blame] | 1568 | if (dev->flags & IFF_PROMISC) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1569 | /* promiscuous mode */ |
| 1570 | lo_bits = 0xfffffffful; |
| 1571 | hi_bits = 0xfffffffful; |
| 1572 | |
| 1573 | /* Enable individual receive */ |
| 1574 | SETS(network_rec_config_shadow, R_NETWORK_REC_CONFIG, individual, receive); |
| 1575 | *R_NETWORK_REC_CONFIG = network_rec_config_shadow; |
| 1576 | } else if (dev->flags & IFF_ALLMULTI) { |
| 1577 | /* enable all multicasts */ |
| 1578 | lo_bits = 0xfffffffful; |
| 1579 | hi_bits = 0xfffffffful; |
| 1580 | |
| 1581 | /* Disable individual receive */ |
| 1582 | SETS(network_rec_config_shadow, R_NETWORK_REC_CONFIG, individual, discard); |
| 1583 | *R_NETWORK_REC_CONFIG = network_rec_config_shadow; |
| 1584 | } else if (num_addr == 0) { |
| 1585 | /* Normal, clear the mc list */ |
| 1586 | lo_bits = 0x00000000ul; |
| 1587 | hi_bits = 0x00000000ul; |
| 1588 | |
| 1589 | /* Disable individual receive */ |
| 1590 | SETS(network_rec_config_shadow, R_NETWORK_REC_CONFIG, individual, discard); |
| 1591 | *R_NETWORK_REC_CONFIG = network_rec_config_shadow; |
| 1592 | } else { |
| 1593 | /* MC mode, receive normal and MC packets */ |
| 1594 | char hash_ix; |
Jiri Pirko | 22bedad3 | 2010-04-01 21:22:57 +0000 | [diff] [blame] | 1595 | struct netdev_hw_addr *ha; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1596 | char *baddr; |
Jesper Nilsson | bafef0a | 2007-11-14 17:00:55 -0800 | [diff] [blame] | 1597 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1598 | lo_bits = 0x00000000ul; |
| 1599 | hi_bits = 0x00000000ul; |
Jiri Pirko | 22bedad3 | 2010-04-01 21:22:57 +0000 | [diff] [blame] | 1600 | netdev_for_each_mc_addr(ha, dev) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1601 | /* Calculate the hash index for the GA registers */ |
| 1602 | |
| 1603 | hash_ix = 0; |
Jiri Pirko | 22bedad3 | 2010-04-01 21:22:57 +0000 | [diff] [blame] | 1604 | baddr = ha->addr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1605 | hash_ix ^= (*baddr) & 0x3f; |
| 1606 | hash_ix ^= ((*baddr) >> 6) & 0x03; |
| 1607 | ++baddr; |
| 1608 | hash_ix ^= ((*baddr) << 2) & 0x03c; |
| 1609 | hash_ix ^= ((*baddr) >> 4) & 0xf; |
| 1610 | ++baddr; |
| 1611 | hash_ix ^= ((*baddr) << 4) & 0x30; |
| 1612 | hash_ix ^= ((*baddr) >> 2) & 0x3f; |
| 1613 | ++baddr; |
| 1614 | hash_ix ^= (*baddr) & 0x3f; |
| 1615 | hash_ix ^= ((*baddr) >> 6) & 0x03; |
| 1616 | ++baddr; |
| 1617 | hash_ix ^= ((*baddr) << 2) & 0x03c; |
| 1618 | hash_ix ^= ((*baddr) >> 4) & 0xf; |
| 1619 | ++baddr; |
| 1620 | hash_ix ^= ((*baddr) << 4) & 0x30; |
| 1621 | hash_ix ^= ((*baddr) >> 2) & 0x3f; |
| 1622 | |
| 1623 | hash_ix &= 0x3f; |
| 1624 | |
| 1625 | if (hash_ix >= 32) { |
| 1626 | hi_bits |= (1 << (hash_ix-32)); |
Jesper Nilsson | bafef0a | 2007-11-14 17:00:55 -0800 | [diff] [blame] | 1627 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1628 | lo_bits |= (1 << hash_ix); |
| 1629 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1630 | } |
| 1631 | /* Disable individual receive */ |
| 1632 | SETS(network_rec_config_shadow, R_NETWORK_REC_CONFIG, individual, discard); |
| 1633 | *R_NETWORK_REC_CONFIG = network_rec_config_shadow; |
| 1634 | } |
| 1635 | *R_NETWORK_GA_0 = lo_bits; |
| 1636 | *R_NETWORK_GA_1 = hi_bits; |
| 1637 | spin_unlock(&lp->lock); |
| 1638 | } |
| 1639 | |
| 1640 | void |
Jesper Nilsson | bafef0a | 2007-11-14 17:00:55 -0800 | [diff] [blame] | 1641 | e100_hardware_send_packet(struct net_local *np, char *buf, int length) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1642 | { |
| 1643 | D(printk("e100 send pack, buf 0x%x len %d\n", buf, length)); |
| 1644 | |
Jesper Nilsson | bafef0a | 2007-11-14 17:00:55 -0800 | [diff] [blame] | 1645 | spin_lock(&np->led_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1646 | if (!led_active && time_after(jiffies, led_next_time)) { |
| 1647 | /* light the network leds depending on the current speed. */ |
| 1648 | e100_set_network_leds(NETWORK_ACTIVITY); |
| 1649 | |
| 1650 | /* Set the earliest time we may clear the LED */ |
| 1651 | led_next_time = jiffies + NET_FLASH_TIME; |
| 1652 | led_active = 1; |
| 1653 | mod_timer(&clear_led_timer, jiffies + HZ/10); |
| 1654 | } |
Jesper Nilsson | bafef0a | 2007-11-14 17:00:55 -0800 | [diff] [blame] | 1655 | spin_unlock(&np->led_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1656 | |
| 1657 | /* configure the tx dma descriptor */ |
| 1658 | myNextTxDesc->descr.sw_len = length; |
| 1659 | myNextTxDesc->descr.ctrl = d_eop | d_eol | d_wait; |
| 1660 | myNextTxDesc->descr.buf = virt_to_phys(buf); |
| 1661 | |
| 1662 | /* Move end of list */ |
| 1663 | myLastTxDesc->descr.ctrl &= ~d_eol; |
| 1664 | myLastTxDesc = myNextTxDesc; |
| 1665 | |
| 1666 | /* Restart DMA channel */ |
| 1667 | *R_DMA_CH0_CMD = IO_STATE(R_DMA_CH0_CMD, cmd, restart); |
| 1668 | } |
| 1669 | |
| 1670 | static void |
| 1671 | e100_clear_network_leds(unsigned long dummy) |
| 1672 | { |
Jesper Nilsson | bafef0a | 2007-11-14 17:00:55 -0800 | [diff] [blame] | 1673 | struct net_device *dev = (struct net_device *)dummy; |
| 1674 | struct net_local *np = netdev_priv(dev); |
| 1675 | |
| 1676 | spin_lock(&np->led_lock); |
| 1677 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1678 | if (led_active && time_after(jiffies, led_next_time)) { |
| 1679 | e100_set_network_leds(NO_NETWORK_ACTIVITY); |
| 1680 | |
| 1681 | /* Set the earliest time we may set the LED */ |
| 1682 | led_next_time = jiffies + NET_FLASH_PAUSE; |
| 1683 | led_active = 0; |
| 1684 | } |
Jesper Nilsson | bafef0a | 2007-11-14 17:00:55 -0800 | [diff] [blame] | 1685 | |
| 1686 | spin_unlock(&np->led_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1687 | } |
| 1688 | |
| 1689 | static void |
| 1690 | e100_set_network_leds(int active) |
| 1691 | { |
| 1692 | #if defined(CONFIG_ETRAX_NETWORK_LED_ON_WHEN_LINK) |
| 1693 | int light_leds = (active == NO_NETWORK_ACTIVITY); |
| 1694 | #elif defined(CONFIG_ETRAX_NETWORK_LED_ON_WHEN_ACTIVITY) |
| 1695 | int light_leds = (active == NETWORK_ACTIVITY); |
| 1696 | #else |
| 1697 | #error "Define either CONFIG_ETRAX_NETWORK_LED_ON_WHEN_LINK or CONFIG_ETRAX_NETWORK_LED_ON_WHEN_ACTIVITY" |
| 1698 | #endif |
| 1699 | |
| 1700 | if (!current_speed) { |
| 1701 | /* Make LED red, link is down */ |
Jesper Nilsson | 5efa1d1 | 2008-02-06 13:35:07 +0100 | [diff] [blame] | 1702 | CRIS_LED_NETWORK_SET(CRIS_LED_OFF); |
Jesper Nilsson | bafef0a | 2007-11-14 17:00:55 -0800 | [diff] [blame] | 1703 | } else if (light_leds) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1704 | if (current_speed == 10) { |
Jesper Nilsson | 5efa1d1 | 2008-02-06 13:35:07 +0100 | [diff] [blame] | 1705 | CRIS_LED_NETWORK_SET(CRIS_LED_ORANGE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1706 | } else { |
Jesper Nilsson | 5efa1d1 | 2008-02-06 13:35:07 +0100 | [diff] [blame] | 1707 | CRIS_LED_NETWORK_SET(CRIS_LED_GREEN); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1708 | } |
Jesper Nilsson | bafef0a | 2007-11-14 17:00:55 -0800 | [diff] [blame] | 1709 | } else { |
Jesper Nilsson | 5efa1d1 | 2008-02-06 13:35:07 +0100 | [diff] [blame] | 1710 | CRIS_LED_NETWORK_SET(CRIS_LED_OFF); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1711 | } |
| 1712 | } |
| 1713 | |
Jesper Nilsson | bafef0a | 2007-11-14 17:00:55 -0800 | [diff] [blame] | 1714 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 1715 | static void |
| 1716 | e100_netpoll(struct net_device* netdev) |
| 1717 | { |
Randy Dunlap | ff6e122 | 2012-08-03 14:38:07 +0000 | [diff] [blame] | 1718 | e100rxtx_interrupt(NETWORK_DMA_TX_IRQ_NBR, netdev); |
Jesper Nilsson | bafef0a | 2007-11-14 17:00:55 -0800 | [diff] [blame] | 1719 | } |
| 1720 | #endif |
| 1721 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1722 | |
| 1723 | static int __init |
| 1724 | e100_boot_setup(char* str) |
| 1725 | { |
| 1726 | struct sockaddr sa = {0}; |
| 1727 | int i; |
| 1728 | |
| 1729 | /* Parse the colon separated Ethernet station address */ |
| 1730 | for (i = 0; i < ETH_ALEN; i++) { |
| 1731 | unsigned int tmp; |
| 1732 | if (sscanf(str + 3*i, "%2x", &tmp) != 1) { |
| 1733 | printk(KERN_WARNING "Malformed station address"); |
| 1734 | return 0; |
| 1735 | } |
| 1736 | sa.sa_data[i] = (char)tmp; |
| 1737 | } |
| 1738 | |
| 1739 | default_mac = sa; |
| 1740 | return 1; |
| 1741 | } |
| 1742 | |
| 1743 | __setup("etrax100_eth=", e100_boot_setup); |