eth_v10.c 48 KB

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