eth_v10.c 48 KB

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