eth_v10.c 48 KB

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