eth_v10.c 48 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746
  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. /* Renegotiate with link partner */
  617. if (autoneg_normal) {
  618. data = e100_get_mdio_reg(dev, np->mii_if.phy_id, MII_BMCR);
  619. data |= BMCR_ANENABLE | BMCR_ANRESTART;
  620. }
  621. e100_set_mdio_reg(dev, np->mii_if.phy_id, MII_BMCR, data);
  622. }
  623. static void
  624. e100_set_speed(struct net_device* dev, unsigned long speed)
  625. {
  626. struct net_local *np = netdev_priv(dev);
  627. spin_lock(&np->transceiver_lock);
  628. if (speed != current_speed_selection) {
  629. current_speed_selection = speed;
  630. e100_negotiate(dev);
  631. }
  632. spin_unlock(&np->transceiver_lock);
  633. }
  634. static void
  635. e100_check_duplex(unsigned long priv)
  636. {
  637. struct net_device *dev = (struct net_device *)priv;
  638. struct net_local *np = netdev_priv(dev);
  639. int old_duplex;
  640. spin_lock(&np->transceiver_lock);
  641. old_duplex = full_duplex;
  642. transceiver->check_duplex(dev);
  643. if (old_duplex != full_duplex) {
  644. /* Duplex changed */
  645. SETF(network_rec_config_shadow, R_NETWORK_REC_CONFIG, duplex, full_duplex);
  646. *R_NETWORK_REC_CONFIG = network_rec_config_shadow;
  647. }
  648. /* Reinitialize the timer. */
  649. duplex_timer.expires = jiffies + NET_DUPLEX_CHECK_INTERVAL;
  650. add_timer(&duplex_timer);
  651. np->mii_if.full_duplex = full_duplex;
  652. spin_unlock(&np->transceiver_lock);
  653. }
  654. #if defined(CONFIG_ETRAX_NO_PHY)
  655. static void
  656. dummy_check_duplex(struct net_device* dev)
  657. {
  658. full_duplex = 1;
  659. }
  660. #else
  661. static void
  662. generic_check_duplex(struct net_device* dev)
  663. {
  664. unsigned long data;
  665. struct net_local *np = netdev_priv(dev);
  666. data = e100_get_mdio_reg(dev, np->mii_if.phy_id, MII_ADVERTISE);
  667. if ((data & ADVERTISE_10FULL) ||
  668. (data & ADVERTISE_100FULL))
  669. full_duplex = 1;
  670. else
  671. full_duplex = 0;
  672. }
  673. static void
  674. tdk_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,
  679. MDIO_TDK_DIAGNOSTIC_REG);
  680. full_duplex = (data & MDIO_TDK_DIAGNOSTIC_DPLX) ? 1 : 0;
  681. }
  682. static void
  683. broadcom_check_duplex(struct net_device* dev)
  684. {
  685. unsigned long data;
  686. struct net_local *np = netdev_priv(dev);
  687. data = e100_get_mdio_reg(dev, np->mii_if.phy_id,
  688. MDIO_AUX_CTRL_STATUS_REG);
  689. full_duplex = (data & MDIO_BC_FULL_DUPLEX_IND) ? 1 : 0;
  690. }
  691. static void
  692. intel_check_duplex(struct net_device* dev)
  693. {
  694. unsigned long data;
  695. struct net_local *np = netdev_priv(dev);
  696. data = e100_get_mdio_reg(dev, np->mii_if.phy_id,
  697. MDIO_INT_STATUS_REG_2);
  698. full_duplex = (data & MDIO_INT_FULL_DUPLEX_IND) ? 1 : 0;
  699. }
  700. #endif
  701. static void
  702. e100_set_duplex(struct net_device* dev, enum duplex new_duplex)
  703. {
  704. struct net_local *np = netdev_priv(dev);
  705. spin_lock(&np->transceiver_lock);
  706. if (new_duplex != current_duplex) {
  707. current_duplex = new_duplex;
  708. e100_negotiate(dev);
  709. }
  710. spin_unlock(&np->transceiver_lock);
  711. }
  712. static int
  713. e100_probe_transceiver(struct net_device* dev)
  714. {
  715. int ret = 0;
  716. #if !defined(CONFIG_ETRAX_NO_PHY)
  717. unsigned int phyid_high;
  718. unsigned int phyid_low;
  719. unsigned int oui;
  720. struct transceiver_ops* ops = NULL;
  721. struct net_local *np = netdev_priv(dev);
  722. spin_lock(&np->transceiver_lock);
  723. /* Probe MDIO physical address */
  724. for (np->mii_if.phy_id = 0; np->mii_if.phy_id <= 31;
  725. np->mii_if.phy_id++) {
  726. if (e100_get_mdio_reg(dev,
  727. np->mii_if.phy_id, MII_BMSR) != 0xffff)
  728. break;
  729. }
  730. if (np->mii_if.phy_id == 32) {
  731. ret = -ENODEV;
  732. goto out;
  733. }
  734. /* Get manufacturer */
  735. phyid_high = e100_get_mdio_reg(dev, np->mii_if.phy_id, MII_PHYSID1);
  736. phyid_low = e100_get_mdio_reg(dev, np->mii_if.phy_id, MII_PHYSID2);
  737. oui = (phyid_high << 6) | (phyid_low >> 10);
  738. for (ops = &transceivers[0]; ops->oui; ops++) {
  739. if (ops->oui == oui)
  740. break;
  741. }
  742. transceiver = ops;
  743. out:
  744. spin_unlock(&np->transceiver_lock);
  745. #endif
  746. return ret;
  747. }
  748. static int
  749. e100_get_mdio_reg(struct net_device *dev, int phy_id, int location)
  750. {
  751. unsigned short cmd; /* Data to be sent on MDIO port */
  752. int data; /* Data read from MDIO */
  753. int bitCounter;
  754. /* Start of frame, OP Code, Physical Address, Register Address */
  755. cmd = (MDIO_START << 14) | (MDIO_READ << 12) | (phy_id << 7) |
  756. (location << 2);
  757. e100_send_mdio_cmd(cmd, 0);
  758. data = 0;
  759. /* Data... */
  760. for (bitCounter=15; bitCounter>=0 ; bitCounter--) {
  761. data |= (e100_receive_mdio_bit() << bitCounter);
  762. }
  763. return data;
  764. }
  765. static void
  766. e100_set_mdio_reg(struct net_device *dev, int phy_id, int location, int value)
  767. {
  768. int bitCounter;
  769. unsigned short cmd;
  770. cmd = (MDIO_START << 14) | (MDIO_WRITE << 12) | (phy_id << 7) |
  771. (location << 2);
  772. e100_send_mdio_cmd(cmd, 1);
  773. /* Data... */
  774. for (bitCounter=15; bitCounter>=0 ; bitCounter--) {
  775. e100_send_mdio_bit(GET_BIT(bitCounter, value));
  776. }
  777. }
  778. static void
  779. e100_send_mdio_cmd(unsigned short cmd, int write_cmd)
  780. {
  781. int bitCounter;
  782. unsigned char data = 0x2;
  783. /* Preamble */
  784. for (bitCounter = 31; bitCounter>= 0; bitCounter--)
  785. e100_send_mdio_bit(GET_BIT(bitCounter, MDIO_PREAMBLE));
  786. for (bitCounter = 15; bitCounter >= 2; bitCounter--)
  787. e100_send_mdio_bit(GET_BIT(bitCounter, cmd));
  788. /* Turnaround */
  789. for (bitCounter = 1; bitCounter >= 0 ; bitCounter--)
  790. if (write_cmd)
  791. e100_send_mdio_bit(GET_BIT(bitCounter, data));
  792. else
  793. e100_receive_mdio_bit();
  794. }
  795. static void
  796. e100_send_mdio_bit(unsigned char bit)
  797. {
  798. *R_NETWORK_MGM_CTRL =
  799. IO_STATE(R_NETWORK_MGM_CTRL, mdoe, enable) |
  800. IO_FIELD(R_NETWORK_MGM_CTRL, mdio, bit);
  801. udelay(1);
  802. *R_NETWORK_MGM_CTRL =
  803. IO_STATE(R_NETWORK_MGM_CTRL, mdoe, enable) |
  804. IO_MASK(R_NETWORK_MGM_CTRL, mdck) |
  805. IO_FIELD(R_NETWORK_MGM_CTRL, mdio, bit);
  806. udelay(1);
  807. }
  808. static unsigned char
  809. e100_receive_mdio_bit()
  810. {
  811. unsigned char bit;
  812. *R_NETWORK_MGM_CTRL = 0;
  813. bit = IO_EXTRACT(R_NETWORK_STAT, mdio, *R_NETWORK_STAT);
  814. udelay(1);
  815. *R_NETWORK_MGM_CTRL = IO_MASK(R_NETWORK_MGM_CTRL, mdck);
  816. udelay(1);
  817. return bit;
  818. }
  819. static void
  820. e100_reset_transceiver(struct net_device* dev)
  821. {
  822. struct net_local *np = netdev_priv(dev);
  823. unsigned short cmd;
  824. unsigned short data;
  825. int bitCounter;
  826. data = e100_get_mdio_reg(dev, np->mii_if.phy_id, MII_BMCR);
  827. cmd = (MDIO_START << 14) | (MDIO_WRITE << 12) | (np->mii_if.phy_id << 7) | (MII_BMCR << 2);
  828. e100_send_mdio_cmd(cmd, 1);
  829. data |= 0x8000;
  830. for (bitCounter = 15; bitCounter >= 0 ; bitCounter--) {
  831. e100_send_mdio_bit(GET_BIT(bitCounter, data));
  832. }
  833. }
  834. /* Called by upper layers if they decide it took too long to complete
  835. * sending a packet - we need to reset and stuff.
  836. */
  837. static void
  838. e100_tx_timeout(struct net_device *dev)
  839. {
  840. struct net_local *np = netdev_priv(dev);
  841. unsigned long flags;
  842. spin_lock_irqsave(&np->lock, flags);
  843. printk(KERN_WARNING "%s: transmit timed out, %s?\n", dev->name,
  844. tx_done(dev) ? "IRQ problem" : "network cable problem");
  845. /* remember we got an error */
  846. np->stats.tx_errors++;
  847. /* reset the TX DMA in case it has hung on something */
  848. RESET_DMA(NETWORK_TX_DMA_NBR);
  849. WAIT_DMA(NETWORK_TX_DMA_NBR);
  850. /* Reset the transceiver. */
  851. e100_reset_transceiver(dev);
  852. /* and get rid of the packets that never got an interrupt */
  853. while (myFirstTxDesc != myNextTxDesc) {
  854. dev_kfree_skb(myFirstTxDesc->skb);
  855. myFirstTxDesc->skb = 0;
  856. myFirstTxDesc = phys_to_virt(myFirstTxDesc->descr.next);
  857. }
  858. /* Set up transmit DMA channel so it can be restarted later */
  859. *R_DMA_CH0_FIRST = 0;
  860. *R_DMA_CH0_DESCR = virt_to_phys(myLastTxDesc);
  861. /* tell the upper layers we're ok again */
  862. netif_wake_queue(dev);
  863. spin_unlock_irqrestore(&np->lock, flags);
  864. }
  865. /* This will only be invoked if the driver is _not_ in XOFF state.
  866. * What this means is that we need not check it, and that this
  867. * invariant will hold if we make sure that the netif_*_queue()
  868. * calls are done at the proper times.
  869. */
  870. static int
  871. e100_send_packet(struct sk_buff *skb, struct net_device *dev)
  872. {
  873. struct net_local *np = netdev_priv(dev);
  874. unsigned char *buf = skb->data;
  875. unsigned long flags;
  876. #ifdef ETHDEBUG
  877. printk("send packet len %d\n", length);
  878. #endif
  879. spin_lock_irqsave(&np->lock, flags); /* protect from tx_interrupt and ourself */
  880. myNextTxDesc->skb = skb;
  881. dev->trans_start = jiffies;
  882. e100_hardware_send_packet(np, buf, skb->len);
  883. myNextTxDesc = phys_to_virt(myNextTxDesc->descr.next);
  884. /* Stop queue if full */
  885. if (myNextTxDesc == myFirstTxDesc) {
  886. netif_stop_queue(dev);
  887. }
  888. spin_unlock_irqrestore(&np->lock, flags);
  889. return 0;
  890. }
  891. /*
  892. * The typical workload of the driver:
  893. * Handle the network interface interrupts.
  894. */
  895. static irqreturn_t
  896. e100rxtx_interrupt(int irq, void *dev_id)
  897. {
  898. struct net_device *dev = (struct net_device *)dev_id;
  899. struct net_local *np = netdev_priv(dev);
  900. unsigned long irqbits;
  901. /*
  902. * Note that both rx and tx interrupts are blocked at this point,
  903. * regardless of which got us here.
  904. */
  905. irqbits = *R_IRQ_MASK2_RD;
  906. /* Handle received packets */
  907. if (irqbits & IO_STATE(R_IRQ_MASK2_RD, dma1_eop, active)) {
  908. /* acknowledge the eop interrupt */
  909. *R_DMA_CH1_CLR_INTR = IO_STATE(R_DMA_CH1_CLR_INTR, clr_eop, do);
  910. /* check if one or more complete packets were indeed received */
  911. while ((*R_DMA_CH1_FIRST != virt_to_phys(myNextRxDesc)) &&
  912. (myNextRxDesc != myLastRxDesc)) {
  913. /* Take out the buffer and give it to the OS, then
  914. * allocate a new buffer to put a packet in.
  915. */
  916. e100_rx(dev);
  917. np->stats.rx_packets++;
  918. /* restart/continue on the channel, for safety */
  919. *R_DMA_CH1_CMD = IO_STATE(R_DMA_CH1_CMD, cmd, restart);
  920. /* clear dma channel 1 eop/descr irq bits */
  921. *R_DMA_CH1_CLR_INTR =
  922. IO_STATE(R_DMA_CH1_CLR_INTR, clr_eop, do) |
  923. IO_STATE(R_DMA_CH1_CLR_INTR, clr_descr, do);
  924. /* now, we might have gotten another packet
  925. so we have to loop back and check if so */
  926. }
  927. }
  928. /* Report any packets that have been sent */
  929. while (virt_to_phys(myFirstTxDesc) != *R_DMA_CH0_FIRST &&
  930. (netif_queue_stopped(dev) || myFirstTxDesc != myNextTxDesc)) {
  931. np->stats.tx_bytes += myFirstTxDesc->skb->len;
  932. np->stats.tx_packets++;
  933. /* dma is ready with the transmission of the data in tx_skb, so now
  934. we can release the skb memory */
  935. dev_kfree_skb_irq(myFirstTxDesc->skb);
  936. myFirstTxDesc->skb = 0;
  937. myFirstTxDesc = phys_to_virt(myFirstTxDesc->descr.next);
  938. /* Wake up queue. */
  939. netif_wake_queue(dev);
  940. }
  941. if (irqbits & IO_STATE(R_IRQ_MASK2_RD, dma0_eop, active)) {
  942. /* acknowledge the eop interrupt. */
  943. *R_DMA_CH0_CLR_INTR = IO_STATE(R_DMA_CH0_CLR_INTR, clr_eop, do);
  944. }
  945. return IRQ_HANDLED;
  946. }
  947. static irqreturn_t
  948. e100nw_interrupt(int irq, void *dev_id)
  949. {
  950. struct net_device *dev = (struct net_device *)dev_id;
  951. struct net_local *np = netdev_priv(dev);
  952. unsigned long irqbits = *R_IRQ_MASK0_RD;
  953. /* check for underrun irq */
  954. if (irqbits & IO_STATE(R_IRQ_MASK0_RD, underrun, active)) {
  955. SETS(network_tr_ctrl_shadow, R_NETWORK_TR_CTRL, clr_error, clr);
  956. *R_NETWORK_TR_CTRL = network_tr_ctrl_shadow;
  957. SETS(network_tr_ctrl_shadow, R_NETWORK_TR_CTRL, clr_error, nop);
  958. np->stats.tx_errors++;
  959. D(printk("ethernet receiver underrun!\n"));
  960. }
  961. /* check for overrun irq */
  962. if (irqbits & IO_STATE(R_IRQ_MASK0_RD, overrun, active)) {
  963. update_rx_stats(&np->stats); /* this will ack the irq */
  964. D(printk("ethernet receiver overrun!\n"));
  965. }
  966. /* check for excessive collision irq */
  967. if (irqbits & IO_STATE(R_IRQ_MASK0_RD, excessive_col, active)) {
  968. SETS(network_tr_ctrl_shadow, R_NETWORK_TR_CTRL, clr_error, clr);
  969. *R_NETWORK_TR_CTRL = network_tr_ctrl_shadow;
  970. SETS(network_tr_ctrl_shadow, R_NETWORK_TR_CTRL, clr_error, nop);
  971. np->stats.tx_errors++;
  972. D(printk("ethernet excessive collisions!\n"));
  973. }
  974. return IRQ_HANDLED;
  975. }
  976. /* We have a good packet(s), get it/them out of the buffers. */
  977. static void
  978. e100_rx(struct net_device *dev)
  979. {
  980. struct sk_buff *skb;
  981. int length = 0;
  982. struct net_local *np = netdev_priv(dev);
  983. unsigned char *skb_data_ptr;
  984. #ifdef ETHDEBUG
  985. int i;
  986. #endif
  987. etrax_eth_descr *prevRxDesc; /* The descriptor right before myNextRxDesc */
  988. spin_lock(&np->led_lock);
  989. if (!led_active && time_after(jiffies, led_next_time)) {
  990. /* light the network leds depending on the current speed. */
  991. e100_set_network_leds(NETWORK_ACTIVITY);
  992. /* Set the earliest time we may clear the LED */
  993. led_next_time = jiffies + NET_FLASH_TIME;
  994. led_active = 1;
  995. mod_timer(&clear_led_timer, jiffies + HZ/10);
  996. }
  997. spin_unlock(&np->led_lock);
  998. length = myNextRxDesc->descr.hw_len - 4;
  999. np->stats.rx_bytes += length;
  1000. #ifdef ETHDEBUG
  1001. printk("Got a packet of length %d:\n", length);
  1002. /* dump the first bytes in the packet */
  1003. skb_data_ptr = (unsigned char *)phys_to_virt(myNextRxDesc->descr.buf);
  1004. for (i = 0; i < 8; i++) {
  1005. printk("%d: %.2x %.2x %.2x %.2x %.2x %.2x %.2x %.2x\n", i * 8,
  1006. skb_data_ptr[0],skb_data_ptr[1],skb_data_ptr[2],skb_data_ptr[3],
  1007. skb_data_ptr[4],skb_data_ptr[5],skb_data_ptr[6],skb_data_ptr[7]);
  1008. skb_data_ptr += 8;
  1009. }
  1010. #endif
  1011. if (length < RX_COPYBREAK) {
  1012. /* Small packet, copy data */
  1013. skb = dev_alloc_skb(length - ETHER_HEAD_LEN);
  1014. if (!skb) {
  1015. np->stats.rx_errors++;
  1016. printk(KERN_NOTICE "%s: Memory squeeze, dropping packet.\n", dev->name);
  1017. goto update_nextrxdesc;
  1018. }
  1019. skb_put(skb, length - ETHER_HEAD_LEN); /* allocate room for the packet body */
  1020. skb_data_ptr = skb_push(skb, ETHER_HEAD_LEN); /* allocate room for the header */
  1021. #ifdef ETHDEBUG
  1022. printk("head = 0x%x, data = 0x%x, tail = 0x%x, end = 0x%x\n",
  1023. skb->head, skb->data, skb_tail_pointer(skb),
  1024. skb_end_pointer(skb));
  1025. printk("copying packet to 0x%x.\n", skb_data_ptr);
  1026. #endif
  1027. memcpy(skb_data_ptr, phys_to_virt(myNextRxDesc->descr.buf), length);
  1028. }
  1029. else {
  1030. /* Large packet, send directly to upper layers and allocate new
  1031. * memory (aligned to cache line boundary to avoid bug).
  1032. * Before sending the skb to upper layers we must make sure
  1033. * that skb->data points to the aligned start of the packet.
  1034. */
  1035. int align;
  1036. struct sk_buff *new_skb = dev_alloc_skb(MAX_MEDIA_DATA_SIZE + 2 * L1_CACHE_BYTES);
  1037. if (!new_skb) {
  1038. np->stats.rx_errors++;
  1039. printk(KERN_NOTICE "%s: Memory squeeze, dropping packet.\n", dev->name);
  1040. goto update_nextrxdesc;
  1041. }
  1042. skb = myNextRxDesc->skb;
  1043. align = (int)phys_to_virt(myNextRxDesc->descr.buf) - (int)skb->data;
  1044. skb_put(skb, length + align);
  1045. skb_pull(skb, align); /* Remove alignment bytes */
  1046. myNextRxDesc->skb = new_skb;
  1047. myNextRxDesc->descr.buf = L1_CACHE_ALIGN(virt_to_phys(myNextRxDesc->skb->data));
  1048. }
  1049. skb->protocol = eth_type_trans(skb, dev);
  1050. /* Send the packet to the upper layers */
  1051. netif_rx(skb);
  1052. update_nextrxdesc:
  1053. /* Prepare for next packet */
  1054. myNextRxDesc->descr.status = 0;
  1055. prevRxDesc = myNextRxDesc;
  1056. myNextRxDesc = phys_to_virt(myNextRxDesc->descr.next);
  1057. rx_queue_len++;
  1058. /* Check if descriptors should be returned */
  1059. if (rx_queue_len == RX_QUEUE_THRESHOLD) {
  1060. flush_etrax_cache();
  1061. prevRxDesc->descr.ctrl |= d_eol;
  1062. myLastRxDesc->descr.ctrl &= ~d_eol;
  1063. myLastRxDesc = prevRxDesc;
  1064. rx_queue_len = 0;
  1065. }
  1066. }
  1067. /* The inverse routine to net_open(). */
  1068. static int
  1069. e100_close(struct net_device *dev)
  1070. {
  1071. struct net_local *np = netdev_priv(dev);
  1072. printk(KERN_INFO "Closing %s.\n", dev->name);
  1073. netif_stop_queue(dev);
  1074. *R_IRQ_MASK0_CLR =
  1075. IO_STATE(R_IRQ_MASK0_CLR, overrun, clr) |
  1076. IO_STATE(R_IRQ_MASK0_CLR, underrun, clr) |
  1077. IO_STATE(R_IRQ_MASK0_CLR, excessive_col, clr);
  1078. *R_IRQ_MASK2_CLR =
  1079. IO_STATE(R_IRQ_MASK2_CLR, dma0_descr, clr) |
  1080. IO_STATE(R_IRQ_MASK2_CLR, dma0_eop, clr) |
  1081. IO_STATE(R_IRQ_MASK2_CLR, dma1_descr, clr) |
  1082. IO_STATE(R_IRQ_MASK2_CLR, dma1_eop, clr);
  1083. /* Stop the receiver and the transmitter */
  1084. RESET_DMA(NETWORK_TX_DMA_NBR);
  1085. RESET_DMA(NETWORK_RX_DMA_NBR);
  1086. /* Flush the Tx and disable Rx here. */
  1087. free_irq(NETWORK_DMA_RX_IRQ_NBR, (void *)dev);
  1088. free_irq(NETWORK_DMA_TX_IRQ_NBR, (void *)dev);
  1089. free_irq(NETWORK_STATUS_IRQ_NBR, (void *)dev);
  1090. cris_free_dma(NETWORK_TX_DMA_NBR, cardname);
  1091. cris_free_dma(NETWORK_RX_DMA_NBR, cardname);
  1092. /* Update the statistics here. */
  1093. update_rx_stats(&np->stats);
  1094. update_tx_stats(&np->stats);
  1095. /* Stop speed/duplex timers */
  1096. del_timer(&speed_timer);
  1097. del_timer(&duplex_timer);
  1098. return 0;
  1099. }
  1100. static int
  1101. e100_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
  1102. {
  1103. struct mii_ioctl_data *data = if_mii(ifr);
  1104. struct net_local *np = netdev_priv(dev);
  1105. int rc = 0;
  1106. int old_autoneg;
  1107. spin_lock(&np->lock); /* Preempt protection */
  1108. switch (cmd) {
  1109. /* The ioctls below should be considered obsolete but are */
  1110. /* still present for compatability with old scripts/apps */
  1111. case SET_ETH_SPEED_10: /* 10 Mbps */
  1112. e100_set_speed(dev, 10);
  1113. break;
  1114. case SET_ETH_SPEED_100: /* 100 Mbps */
  1115. e100_set_speed(dev, 100);
  1116. break;
  1117. case SET_ETH_SPEED_AUTO: /* Auto-negotiate speed */
  1118. e100_set_speed(dev, 0);
  1119. break;
  1120. case SET_ETH_DUPLEX_HALF: /* Half duplex */
  1121. e100_set_duplex(dev, half);
  1122. break;
  1123. case SET_ETH_DUPLEX_FULL: /* Full duplex */
  1124. e100_set_duplex(dev, full);
  1125. break;
  1126. case SET_ETH_DUPLEX_AUTO: /* Auto-negotiate duplex */
  1127. e100_set_duplex(dev, autoneg);
  1128. break;
  1129. case SET_ETH_AUTONEG:
  1130. old_autoneg = autoneg_normal;
  1131. autoneg_normal = *(int*)data;
  1132. if (autoneg_normal != old_autoneg)
  1133. e100_negotiate(dev);
  1134. break;
  1135. default:
  1136. rc = generic_mii_ioctl(&np->mii_if, if_mii(ifr),
  1137. cmd, NULL);
  1138. break;
  1139. }
  1140. spin_unlock(&np->lock);
  1141. return rc;
  1142. }
  1143. static int e100_get_settings(struct net_device *dev,
  1144. struct ethtool_cmd *cmd)
  1145. {
  1146. struct net_local *np = netdev_priv(dev);
  1147. int err;
  1148. spin_lock_irq(&np->lock);
  1149. err = mii_ethtool_gset(&np->mii_if, cmd);
  1150. spin_unlock_irq(&np->lock);
  1151. /* The PHY may support 1000baseT, but the Etrax100 does not. */
  1152. cmd->supported &= ~(SUPPORTED_1000baseT_Half
  1153. | SUPPORTED_1000baseT_Full);
  1154. return err;
  1155. }
  1156. static int e100_set_settings(struct net_device *dev,
  1157. struct ethtool_cmd *ecmd)
  1158. {
  1159. if (ecmd->autoneg == AUTONEG_ENABLE) {
  1160. e100_set_duplex(dev, autoneg);
  1161. e100_set_speed(dev, 0);
  1162. } else {
  1163. e100_set_duplex(dev, ecmd->duplex == DUPLEX_HALF ? half : full);
  1164. e100_set_speed(dev, ecmd->speed == SPEED_10 ? 10: 100);
  1165. }
  1166. return 0;
  1167. }
  1168. static void e100_get_drvinfo(struct net_device *dev,
  1169. struct ethtool_drvinfo *info)
  1170. {
  1171. strncpy(info->driver, "ETRAX 100LX", sizeof(info->driver) - 1);
  1172. strncpy(info->version, "$Revision: 1.31 $", sizeof(info->version) - 1);
  1173. strncpy(info->fw_version, "N/A", sizeof(info->fw_version) - 1);
  1174. strncpy(info->bus_info, "N/A", sizeof(info->bus_info) - 1);
  1175. }
  1176. static int e100_nway_reset(struct net_device *dev)
  1177. {
  1178. if (current_duplex == autoneg && current_speed_selection == 0)
  1179. e100_negotiate(dev);
  1180. return 0;
  1181. }
  1182. static const struct ethtool_ops e100_ethtool_ops = {
  1183. .get_settings = e100_get_settings,
  1184. .set_settings = e100_set_settings,
  1185. .get_drvinfo = e100_get_drvinfo,
  1186. .nway_reset = e100_nway_reset,
  1187. .get_link = ethtool_op_get_link,
  1188. };
  1189. static int
  1190. e100_set_config(struct net_device *dev, struct ifmap *map)
  1191. {
  1192. struct net_local *np = netdev_priv(dev);
  1193. spin_lock(&np->lock); /* Preempt protection */
  1194. switch(map->port) {
  1195. case IF_PORT_UNKNOWN:
  1196. /* Use autoneg */
  1197. e100_set_speed(dev, 0);
  1198. e100_set_duplex(dev, autoneg);
  1199. break;
  1200. case IF_PORT_10BASET:
  1201. e100_set_speed(dev, 10);
  1202. e100_set_duplex(dev, autoneg);
  1203. break;
  1204. case IF_PORT_100BASET:
  1205. case IF_PORT_100BASETX:
  1206. e100_set_speed(dev, 100);
  1207. e100_set_duplex(dev, autoneg);
  1208. break;
  1209. case IF_PORT_100BASEFX:
  1210. case IF_PORT_10BASE2:
  1211. case IF_PORT_AUI:
  1212. spin_unlock(&np->lock);
  1213. return -EOPNOTSUPP;
  1214. break;
  1215. default:
  1216. printk(KERN_ERR "%s: Invalid media selected", dev->name);
  1217. spin_unlock(&np->lock);
  1218. return -EINVAL;
  1219. }
  1220. spin_unlock(&np->lock);
  1221. return 0;
  1222. }
  1223. static void
  1224. update_rx_stats(struct net_device_stats *es)
  1225. {
  1226. unsigned long r = *R_REC_COUNTERS;
  1227. /* update stats relevant to reception errors */
  1228. es->rx_fifo_errors += IO_EXTRACT(R_REC_COUNTERS, congestion, r);
  1229. es->rx_crc_errors += IO_EXTRACT(R_REC_COUNTERS, crc_error, r);
  1230. es->rx_frame_errors += IO_EXTRACT(R_REC_COUNTERS, alignment_error, r);
  1231. es->rx_length_errors += IO_EXTRACT(R_REC_COUNTERS, oversize, r);
  1232. }
  1233. static void
  1234. update_tx_stats(struct net_device_stats *es)
  1235. {
  1236. unsigned long r = *R_TR_COUNTERS;
  1237. /* update stats relevant to transmission errors */
  1238. es->collisions +=
  1239. IO_EXTRACT(R_TR_COUNTERS, single_col, r) +
  1240. IO_EXTRACT(R_TR_COUNTERS, multiple_col, r);
  1241. }
  1242. /*
  1243. * Get the current statistics.
  1244. * This may be called with the card open or closed.
  1245. */
  1246. static struct net_device_stats *
  1247. e100_get_stats(struct net_device *dev)
  1248. {
  1249. struct net_local *lp = netdev_priv(dev);
  1250. unsigned long flags;
  1251. spin_lock_irqsave(&lp->lock, flags);
  1252. update_rx_stats(&lp->stats);
  1253. update_tx_stats(&lp->stats);
  1254. spin_unlock_irqrestore(&lp->lock, flags);
  1255. return &lp->stats;
  1256. }
  1257. /*
  1258. * Set or clear the multicast filter for this adaptor.
  1259. * num_addrs == -1 Promiscuous mode, receive all packets
  1260. * num_addrs == 0 Normal mode, clear multicast list
  1261. * num_addrs > 0 Multicast mode, receive normal and MC packets,
  1262. * and do best-effort filtering.
  1263. */
  1264. static void
  1265. set_multicast_list(struct net_device *dev)
  1266. {
  1267. struct net_local *lp = netdev_priv(dev);
  1268. int num_addr = dev->mc_count;
  1269. unsigned long int lo_bits;
  1270. unsigned long int hi_bits;
  1271. spin_lock(&lp->lock);
  1272. if (dev->flags & IFF_PROMISC) {
  1273. /* promiscuous mode */
  1274. lo_bits = 0xfffffffful;
  1275. hi_bits = 0xfffffffful;
  1276. /* Enable individual receive */
  1277. SETS(network_rec_config_shadow, R_NETWORK_REC_CONFIG, individual, receive);
  1278. *R_NETWORK_REC_CONFIG = network_rec_config_shadow;
  1279. } else if (dev->flags & IFF_ALLMULTI) {
  1280. /* enable all multicasts */
  1281. lo_bits = 0xfffffffful;
  1282. hi_bits = 0xfffffffful;
  1283. /* Disable individual receive */
  1284. SETS(network_rec_config_shadow, R_NETWORK_REC_CONFIG, individual, discard);
  1285. *R_NETWORK_REC_CONFIG = network_rec_config_shadow;
  1286. } else if (num_addr == 0) {
  1287. /* Normal, clear the mc list */
  1288. lo_bits = 0x00000000ul;
  1289. hi_bits = 0x00000000ul;
  1290. /* Disable individual receive */
  1291. SETS(network_rec_config_shadow, R_NETWORK_REC_CONFIG, individual, discard);
  1292. *R_NETWORK_REC_CONFIG = network_rec_config_shadow;
  1293. } else {
  1294. /* MC mode, receive normal and MC packets */
  1295. char hash_ix;
  1296. struct dev_mc_list *dmi = dev->mc_list;
  1297. int i;
  1298. char *baddr;
  1299. lo_bits = 0x00000000ul;
  1300. hi_bits = 0x00000000ul;
  1301. for (i = 0; i < num_addr; i++) {
  1302. /* Calculate the hash index for the GA registers */
  1303. hash_ix = 0;
  1304. baddr = dmi->dmi_addr;
  1305. hash_ix ^= (*baddr) & 0x3f;
  1306. hash_ix ^= ((*baddr) >> 6) & 0x03;
  1307. ++baddr;
  1308. hash_ix ^= ((*baddr) << 2) & 0x03c;
  1309. hash_ix ^= ((*baddr) >> 4) & 0xf;
  1310. ++baddr;
  1311. hash_ix ^= ((*baddr) << 4) & 0x30;
  1312. hash_ix ^= ((*baddr) >> 2) & 0x3f;
  1313. ++baddr;
  1314. hash_ix ^= (*baddr) & 0x3f;
  1315. hash_ix ^= ((*baddr) >> 6) & 0x03;
  1316. ++baddr;
  1317. hash_ix ^= ((*baddr) << 2) & 0x03c;
  1318. hash_ix ^= ((*baddr) >> 4) & 0xf;
  1319. ++baddr;
  1320. hash_ix ^= ((*baddr) << 4) & 0x30;
  1321. hash_ix ^= ((*baddr) >> 2) & 0x3f;
  1322. hash_ix &= 0x3f;
  1323. if (hash_ix >= 32) {
  1324. hi_bits |= (1 << (hash_ix-32));
  1325. } else {
  1326. lo_bits |= (1 << hash_ix);
  1327. }
  1328. dmi = dmi->next;
  1329. }
  1330. /* Disable individual receive */
  1331. SETS(network_rec_config_shadow, R_NETWORK_REC_CONFIG, individual, discard);
  1332. *R_NETWORK_REC_CONFIG = network_rec_config_shadow;
  1333. }
  1334. *R_NETWORK_GA_0 = lo_bits;
  1335. *R_NETWORK_GA_1 = hi_bits;
  1336. spin_unlock(&lp->lock);
  1337. }
  1338. void
  1339. e100_hardware_send_packet(struct net_local *np, char *buf, int length)
  1340. {
  1341. D(printk("e100 send pack, buf 0x%x len %d\n", buf, length));
  1342. spin_lock(&np->led_lock);
  1343. if (!led_active && time_after(jiffies, led_next_time)) {
  1344. /* light the network leds depending on the current speed. */
  1345. e100_set_network_leds(NETWORK_ACTIVITY);
  1346. /* Set the earliest time we may clear the LED */
  1347. led_next_time = jiffies + NET_FLASH_TIME;
  1348. led_active = 1;
  1349. mod_timer(&clear_led_timer, jiffies + HZ/10);
  1350. }
  1351. spin_unlock(&np->led_lock);
  1352. /* configure the tx dma descriptor */
  1353. myNextTxDesc->descr.sw_len = length;
  1354. myNextTxDesc->descr.ctrl = d_eop | d_eol | d_wait;
  1355. myNextTxDesc->descr.buf = virt_to_phys(buf);
  1356. /* Move end of list */
  1357. myLastTxDesc->descr.ctrl &= ~d_eol;
  1358. myLastTxDesc = myNextTxDesc;
  1359. /* Restart DMA channel */
  1360. *R_DMA_CH0_CMD = IO_STATE(R_DMA_CH0_CMD, cmd, restart);
  1361. }
  1362. static void
  1363. e100_clear_network_leds(unsigned long dummy)
  1364. {
  1365. struct net_device *dev = (struct net_device *)dummy;
  1366. struct net_local *np = netdev_priv(dev);
  1367. spin_lock(&np->led_lock);
  1368. if (led_active && time_after(jiffies, led_next_time)) {
  1369. e100_set_network_leds(NO_NETWORK_ACTIVITY);
  1370. /* Set the earliest time we may set the LED */
  1371. led_next_time = jiffies + NET_FLASH_PAUSE;
  1372. led_active = 0;
  1373. }
  1374. spin_unlock(&np->led_lock);
  1375. }
  1376. static void
  1377. e100_set_network_leds(int active)
  1378. {
  1379. #if defined(CONFIG_ETRAX_NETWORK_LED_ON_WHEN_LINK)
  1380. int light_leds = (active == NO_NETWORK_ACTIVITY);
  1381. #elif defined(CONFIG_ETRAX_NETWORK_LED_ON_WHEN_ACTIVITY)
  1382. int light_leds = (active == NETWORK_ACTIVITY);
  1383. #else
  1384. #error "Define either CONFIG_ETRAX_NETWORK_LED_ON_WHEN_LINK or CONFIG_ETRAX_NETWORK_LED_ON_WHEN_ACTIVITY"
  1385. #endif
  1386. if (!current_speed) {
  1387. /* Make LED red, link is down */
  1388. #if defined(CONFIG_ETRAX_NETWORK_RED_ON_NO_CONNECTION)
  1389. CRIS_LED_NETWORK_SET(CRIS_LED_RED);
  1390. #else
  1391. CRIS_LED_NETWORK_SET(CRIS_LED_OFF);
  1392. #endif
  1393. } else if (light_leds) {
  1394. if (current_speed == 10) {
  1395. CRIS_LED_NETWORK_SET(CRIS_LED_ORANGE);
  1396. } else {
  1397. CRIS_LED_NETWORK_SET(CRIS_LED_GREEN);
  1398. }
  1399. } else {
  1400. CRIS_LED_NETWORK_SET(CRIS_LED_OFF);
  1401. }
  1402. }
  1403. #ifdef CONFIG_NET_POLL_CONTROLLER
  1404. static void
  1405. e100_netpoll(struct net_device* netdev)
  1406. {
  1407. e100rxtx_interrupt(NETWORK_DMA_TX_IRQ_NBR, netdev, NULL);
  1408. }
  1409. #endif
  1410. static int
  1411. etrax_init_module(void)
  1412. {
  1413. return etrax_ethernet_init();
  1414. }
  1415. static int __init
  1416. e100_boot_setup(char* str)
  1417. {
  1418. struct sockaddr sa = {0};
  1419. int i;
  1420. /* Parse the colon separated Ethernet station address */
  1421. for (i = 0; i < ETH_ALEN; i++) {
  1422. unsigned int tmp;
  1423. if (sscanf(str + 3*i, "%2x", &tmp) != 1) {
  1424. printk(KERN_WARNING "Malformed station address");
  1425. return 0;
  1426. }
  1427. sa.sa_data[i] = (char)tmp;
  1428. }
  1429. default_mac = sa;
  1430. return 1;
  1431. }
  1432. __setup("etrax100_eth=", e100_boot_setup);
  1433. module_init(etrax_init_module);