eth_v10.c 48 KB

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