eth_v10.c 48 KB

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