eth_v10.c 48 KB

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