au1000_eth.c 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314
  1. /*
  2. *
  3. * Alchemy Au1x00 ethernet driver
  4. *
  5. * Copyright 2001-2003, 2006 MontaVista Software Inc.
  6. * Copyright 2002 TimeSys Corp.
  7. * Added ethtool/mii-tool support,
  8. * Copyright 2004 Matt Porter <mporter@kernel.crashing.org>
  9. * Update: 2004 Bjoern Riemer, riemer@fokus.fraunhofer.de
  10. * or riemer@riemer-nt.de: fixed the link beat detection with
  11. * ioctls (SIOCGMIIPHY)
  12. * Copyright 2006 Herbert Valerio Riedel <hvr@gnu.org>
  13. * converted to use linux-2.6.x's PHY framework
  14. *
  15. * Author: MontaVista Software, Inc.
  16. * ppopov@mvista.com or source@mvista.com
  17. *
  18. * ########################################################################
  19. *
  20. * This program is free software; you can distribute it and/or modify it
  21. * under the terms of the GNU General Public License (Version 2) as
  22. * published by the Free Software Foundation.
  23. *
  24. * This program is distributed in the hope it will be useful, but WITHOUT
  25. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  26. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  27. * for more details.
  28. *
  29. * You should have received a copy of the GNU General Public License along
  30. * with this program; if not, write to the Free Software Foundation, Inc.,
  31. * 59 Temple Place - Suite 330, Boston MA 02111-1307, USA.
  32. *
  33. * ########################################################################
  34. *
  35. *
  36. */
  37. #include <linux/dma-mapping.h>
  38. #include <linux/module.h>
  39. #include <linux/kernel.h>
  40. #include <linux/string.h>
  41. #include <linux/timer.h>
  42. #include <linux/errno.h>
  43. #include <linux/in.h>
  44. #include <linux/ioport.h>
  45. #include <linux/bitops.h>
  46. #include <linux/slab.h>
  47. #include <linux/interrupt.h>
  48. #include <linux/init.h>
  49. #include <linux/netdevice.h>
  50. #include <linux/etherdevice.h>
  51. #include <linux/ethtool.h>
  52. #include <linux/mii.h>
  53. #include <linux/skbuff.h>
  54. #include <linux/delay.h>
  55. #include <linux/crc32.h>
  56. #include <linux/phy.h>
  57. #include <asm/cpu.h>
  58. #include <asm/mipsregs.h>
  59. #include <asm/irq.h>
  60. #include <asm/io.h>
  61. #include <asm/processor.h>
  62. #include <au1000.h>
  63. #include <prom.h>
  64. #include "au1000_eth.h"
  65. #ifdef AU1000_ETH_DEBUG
  66. static int au1000_debug = 5;
  67. #else
  68. static int au1000_debug = 3;
  69. #endif
  70. #define DRV_NAME "au1000_eth"
  71. #define DRV_VERSION "1.6"
  72. #define DRV_AUTHOR "Pete Popov <ppopov@embeddedalley.com>"
  73. #define DRV_DESC "Au1xxx on-chip Ethernet driver"
  74. MODULE_AUTHOR(DRV_AUTHOR);
  75. MODULE_DESCRIPTION(DRV_DESC);
  76. MODULE_LICENSE("GPL");
  77. // prototypes
  78. static void hard_stop(struct net_device *);
  79. static void enable_rx_tx(struct net_device *dev);
  80. static struct net_device * au1000_probe(int port_num);
  81. static int au1000_init(struct net_device *);
  82. static int au1000_open(struct net_device *);
  83. static int au1000_close(struct net_device *);
  84. static int au1000_tx(struct sk_buff *, struct net_device *);
  85. static int au1000_rx(struct net_device *);
  86. static irqreturn_t au1000_interrupt(int, void *);
  87. static void au1000_tx_timeout(struct net_device *);
  88. static void set_rx_mode(struct net_device *);
  89. static int au1000_ioctl(struct net_device *, struct ifreq *, int);
  90. static int mdio_read(struct net_device *, int, int);
  91. static void mdio_write(struct net_device *, int, int, u16);
  92. static void au1000_adjust_link(struct net_device *);
  93. static void enable_mac(struct net_device *, int);
  94. /*
  95. * Theory of operation
  96. *
  97. * The Au1000 MACs use a simple rx and tx descriptor ring scheme.
  98. * There are four receive and four transmit descriptors. These
  99. * descriptors are not in memory; rather, they are just a set of
  100. * hardware registers.
  101. *
  102. * Since the Au1000 has a coherent data cache, the receive and
  103. * transmit buffers are allocated from the KSEG0 segment. The
  104. * hardware registers, however, are still mapped at KSEG1 to
  105. * make sure there's no out-of-order writes, and that all writes
  106. * complete immediately.
  107. */
  108. /* These addresses are only used if yamon doesn't tell us what
  109. * the mac address is, and the mac address is not passed on the
  110. * command line.
  111. */
  112. static unsigned char au1000_mac_addr[6] __devinitdata = {
  113. 0x00, 0x50, 0xc2, 0x0c, 0x30, 0x00
  114. };
  115. struct au1000_private *au_macs[NUM_ETH_INTERFACES];
  116. /*
  117. * board-specific configurations
  118. *
  119. * PHY detection algorithm
  120. *
  121. * If AU1XXX_PHY_STATIC_CONFIG is undefined, the PHY setup is
  122. * autodetected:
  123. *
  124. * mii_probe() first searches the current MAC's MII bus for a PHY,
  125. * selecting the first (or last, if AU1XXX_PHY_SEARCH_HIGHEST_ADDR is
  126. * defined) PHY address not already claimed by another netdev.
  127. *
  128. * If nothing was found that way when searching for the 2nd ethernet
  129. * controller's PHY and AU1XXX_PHY1_SEARCH_ON_MAC0 is defined, then
  130. * the first MII bus is searched as well for an unclaimed PHY; this is
  131. * needed in case of a dual-PHY accessible only through the MAC0's MII
  132. * bus.
  133. *
  134. * Finally, if no PHY is found, then the corresponding ethernet
  135. * controller is not registered to the network subsystem.
  136. */
  137. /* autodetection defaults */
  138. #undef AU1XXX_PHY_SEARCH_HIGHEST_ADDR
  139. #define AU1XXX_PHY1_SEARCH_ON_MAC0
  140. /* static PHY setup
  141. *
  142. * most boards PHY setup should be detectable properly with the
  143. * autodetection algorithm in mii_probe(), but in some cases (e.g. if
  144. * you have a switch attached, or want to use the PHY's interrupt
  145. * notification capabilities) you can provide a static PHY
  146. * configuration here
  147. *
  148. * IRQs may only be set, if a PHY address was configured
  149. * If a PHY address is given, also a bus id is required to be set
  150. *
  151. * ps: make sure the used irqs are configured properly in the board
  152. * specific irq-map
  153. */
  154. #if defined(CONFIG_MIPS_BOSPORUS)
  155. /*
  156. * Micrel/Kendin 5 port switch attached to MAC0,
  157. * MAC0 is associated with PHY address 5 (== WAN port)
  158. * MAC1 is not associated with any PHY, since it's connected directly
  159. * to the switch.
  160. * no interrupts are used
  161. */
  162. # define AU1XXX_PHY_STATIC_CONFIG
  163. # define AU1XXX_PHY0_ADDR 5
  164. # define AU1XXX_PHY0_BUSID 0
  165. # undef AU1XXX_PHY0_IRQ
  166. # undef AU1XXX_PHY1_ADDR
  167. # undef AU1XXX_PHY1_BUSID
  168. # undef AU1XXX_PHY1_IRQ
  169. #endif
  170. #if defined(AU1XXX_PHY0_BUSID) && (AU1XXX_PHY0_BUSID > 0)
  171. # error MAC0-associated PHY attached 2nd MACs MII bus not supported yet
  172. #endif
  173. /*
  174. * MII operations
  175. */
  176. static int mdio_read(struct net_device *dev, int phy_addr, int reg)
  177. {
  178. struct au1000_private *aup = (struct au1000_private *) dev->priv;
  179. volatile u32 *const mii_control_reg = &aup->mac->mii_control;
  180. volatile u32 *const mii_data_reg = &aup->mac->mii_data;
  181. u32 timedout = 20;
  182. u32 mii_control;
  183. while (*mii_control_reg & MAC_MII_BUSY) {
  184. mdelay(1);
  185. if (--timedout == 0) {
  186. printk(KERN_ERR "%s: read_MII busy timeout!!\n",
  187. dev->name);
  188. return -1;
  189. }
  190. }
  191. mii_control = MAC_SET_MII_SELECT_REG(reg) |
  192. MAC_SET_MII_SELECT_PHY(phy_addr) | MAC_MII_READ;
  193. *mii_control_reg = mii_control;
  194. timedout = 20;
  195. while (*mii_control_reg & MAC_MII_BUSY) {
  196. mdelay(1);
  197. if (--timedout == 0) {
  198. printk(KERN_ERR "%s: mdio_read busy timeout!!\n",
  199. dev->name);
  200. return -1;
  201. }
  202. }
  203. return (int)*mii_data_reg;
  204. }
  205. static void mdio_write(struct net_device *dev, int phy_addr, int reg, u16 value)
  206. {
  207. struct au1000_private *aup = (struct au1000_private *) dev->priv;
  208. volatile u32 *const mii_control_reg = &aup->mac->mii_control;
  209. volatile u32 *const mii_data_reg = &aup->mac->mii_data;
  210. u32 timedout = 20;
  211. u32 mii_control;
  212. while (*mii_control_reg & MAC_MII_BUSY) {
  213. mdelay(1);
  214. if (--timedout == 0) {
  215. printk(KERN_ERR "%s: mdio_write busy timeout!!\n",
  216. dev->name);
  217. return;
  218. }
  219. }
  220. mii_control = MAC_SET_MII_SELECT_REG(reg) |
  221. MAC_SET_MII_SELECT_PHY(phy_addr) | MAC_MII_WRITE;
  222. *mii_data_reg = value;
  223. *mii_control_reg = mii_control;
  224. }
  225. static int mdiobus_read(struct mii_bus *bus, int phy_addr, int regnum)
  226. {
  227. /* WARNING: bus->phy_map[phy_addr].attached_dev == dev does
  228. * _NOT_ hold (e.g. when PHY is accessed through other MAC's MII bus) */
  229. struct net_device *const dev = bus->priv;
  230. enable_mac(dev, 0); /* make sure the MAC associated with this
  231. * mii_bus is enabled */
  232. return mdio_read(dev, phy_addr, regnum);
  233. }
  234. static int mdiobus_write(struct mii_bus *bus, int phy_addr, int regnum,
  235. u16 value)
  236. {
  237. struct net_device *const dev = bus->priv;
  238. enable_mac(dev, 0); /* make sure the MAC associated with this
  239. * mii_bus is enabled */
  240. mdio_write(dev, phy_addr, regnum, value);
  241. return 0;
  242. }
  243. static int mdiobus_reset(struct mii_bus *bus)
  244. {
  245. struct net_device *const dev = bus->priv;
  246. enable_mac(dev, 0); /* make sure the MAC associated with this
  247. * mii_bus is enabled */
  248. return 0;
  249. }
  250. static int mii_probe (struct net_device *dev)
  251. {
  252. struct au1000_private *const aup = (struct au1000_private *) dev->priv;
  253. struct phy_device *phydev = NULL;
  254. #if defined(AU1XXX_PHY_STATIC_CONFIG)
  255. BUG_ON(aup->mac_id < 0 || aup->mac_id > 1);
  256. if(aup->mac_id == 0) { /* get PHY0 */
  257. # if defined(AU1XXX_PHY0_ADDR)
  258. phydev = au_macs[AU1XXX_PHY0_BUSID]->mii_bus.phy_map[AU1XXX_PHY0_ADDR];
  259. # else
  260. printk (KERN_INFO DRV_NAME ":%s: using PHY-less setup\n",
  261. dev->name);
  262. return 0;
  263. # endif /* defined(AU1XXX_PHY0_ADDR) */
  264. } else if (aup->mac_id == 1) { /* get PHY1 */
  265. # if defined(AU1XXX_PHY1_ADDR)
  266. phydev = au_macs[AU1XXX_PHY1_BUSID]->mii_bus.phy_map[AU1XXX_PHY1_ADDR];
  267. # else
  268. printk (KERN_INFO DRV_NAME ":%s: using PHY-less setup\n",
  269. dev->name);
  270. return 0;
  271. # endif /* defined(AU1XXX_PHY1_ADDR) */
  272. }
  273. #else /* defined(AU1XXX_PHY_STATIC_CONFIG) */
  274. int phy_addr;
  275. /* find the first (lowest address) PHY on the current MAC's MII bus */
  276. for (phy_addr = 0; phy_addr < PHY_MAX_ADDR; phy_addr++)
  277. if (aup->mii_bus.phy_map[phy_addr]) {
  278. phydev = aup->mii_bus.phy_map[phy_addr];
  279. # if !defined(AU1XXX_PHY_SEARCH_HIGHEST_ADDR)
  280. break; /* break out with first one found */
  281. # endif
  282. }
  283. # if defined(AU1XXX_PHY1_SEARCH_ON_MAC0)
  284. /* try harder to find a PHY */
  285. if (!phydev && (aup->mac_id == 1)) {
  286. /* no PHY found, maybe we have a dual PHY? */
  287. printk (KERN_INFO DRV_NAME ": no PHY found on MAC1, "
  288. "let's see if it's attached to MAC0...\n");
  289. BUG_ON(!au_macs[0]);
  290. /* find the first (lowest address) non-attached PHY on
  291. * the MAC0 MII bus */
  292. for (phy_addr = 0; phy_addr < PHY_MAX_ADDR; phy_addr++) {
  293. struct phy_device *const tmp_phydev =
  294. au_macs[0]->mii_bus.phy_map[phy_addr];
  295. if (!tmp_phydev)
  296. continue; /* no PHY here... */
  297. if (tmp_phydev->attached_dev)
  298. continue; /* already claimed by MAC0 */
  299. phydev = tmp_phydev;
  300. break; /* found it */
  301. }
  302. }
  303. # endif /* defined(AU1XXX_PHY1_SEARCH_OTHER_BUS) */
  304. #endif /* defined(AU1XXX_PHY_STATIC_CONFIG) */
  305. if (!phydev) {
  306. printk (KERN_ERR DRV_NAME ":%s: no PHY found\n", dev->name);
  307. return -1;
  308. }
  309. /* now we are supposed to have a proper phydev, to attach to... */
  310. BUG_ON(!phydev);
  311. BUG_ON(phydev->attached_dev);
  312. phydev = phy_connect(dev, phydev->dev.bus_id, &au1000_adjust_link, 0,
  313. PHY_INTERFACE_MODE_MII);
  314. if (IS_ERR(phydev)) {
  315. printk(KERN_ERR "%s: Could not attach to PHY\n", dev->name);
  316. return PTR_ERR(phydev);
  317. }
  318. /* mask with MAC supported features */
  319. phydev->supported &= (SUPPORTED_10baseT_Half
  320. | SUPPORTED_10baseT_Full
  321. | SUPPORTED_100baseT_Half
  322. | SUPPORTED_100baseT_Full
  323. | SUPPORTED_Autoneg
  324. /* | SUPPORTED_Pause | SUPPORTED_Asym_Pause */
  325. | SUPPORTED_MII
  326. | SUPPORTED_TP);
  327. phydev->advertising = phydev->supported;
  328. aup->old_link = 0;
  329. aup->old_speed = 0;
  330. aup->old_duplex = -1;
  331. aup->phy_dev = phydev;
  332. printk(KERN_INFO "%s: attached PHY driver [%s] "
  333. "(mii_bus:phy_addr=%s, irq=%d)\n",
  334. dev->name, phydev->drv->name, phydev->dev.bus_id, phydev->irq);
  335. return 0;
  336. }
  337. /*
  338. * Buffer allocation/deallocation routines. The buffer descriptor returned
  339. * has the virtual and dma address of a buffer suitable for
  340. * both, receive and transmit operations.
  341. */
  342. static db_dest_t *GetFreeDB(struct au1000_private *aup)
  343. {
  344. db_dest_t *pDB;
  345. pDB = aup->pDBfree;
  346. if (pDB) {
  347. aup->pDBfree = pDB->pnext;
  348. }
  349. return pDB;
  350. }
  351. void ReleaseDB(struct au1000_private *aup, db_dest_t *pDB)
  352. {
  353. db_dest_t *pDBfree = aup->pDBfree;
  354. if (pDBfree)
  355. pDBfree->pnext = pDB;
  356. aup->pDBfree = pDB;
  357. }
  358. static void enable_rx_tx(struct net_device *dev)
  359. {
  360. struct au1000_private *aup = (struct au1000_private *) dev->priv;
  361. if (au1000_debug > 4)
  362. printk(KERN_INFO "%s: enable_rx_tx\n", dev->name);
  363. aup->mac->control |= (MAC_RX_ENABLE | MAC_TX_ENABLE);
  364. au_sync_delay(10);
  365. }
  366. static void hard_stop(struct net_device *dev)
  367. {
  368. struct au1000_private *aup = (struct au1000_private *) dev->priv;
  369. if (au1000_debug > 4)
  370. printk(KERN_INFO "%s: hard stop\n", dev->name);
  371. aup->mac->control &= ~(MAC_RX_ENABLE | MAC_TX_ENABLE);
  372. au_sync_delay(10);
  373. }
  374. static void enable_mac(struct net_device *dev, int force_reset)
  375. {
  376. unsigned long flags;
  377. struct au1000_private *aup = (struct au1000_private *) dev->priv;
  378. spin_lock_irqsave(&aup->lock, flags);
  379. if(force_reset || (!aup->mac_enabled)) {
  380. *aup->enable = MAC_EN_CLOCK_ENABLE;
  381. au_sync_delay(2);
  382. *aup->enable = (MAC_EN_RESET0 | MAC_EN_RESET1 | MAC_EN_RESET2
  383. | MAC_EN_CLOCK_ENABLE);
  384. au_sync_delay(2);
  385. aup->mac_enabled = 1;
  386. }
  387. spin_unlock_irqrestore(&aup->lock, flags);
  388. }
  389. static void reset_mac_unlocked(struct net_device *dev)
  390. {
  391. struct au1000_private *const aup = (struct au1000_private *) dev->priv;
  392. int i;
  393. hard_stop(dev);
  394. *aup->enable = MAC_EN_CLOCK_ENABLE;
  395. au_sync_delay(2);
  396. *aup->enable = 0;
  397. au_sync_delay(2);
  398. aup->tx_full = 0;
  399. for (i = 0; i < NUM_RX_DMA; i++) {
  400. /* reset control bits */
  401. aup->rx_dma_ring[i]->buff_stat &= ~0xf;
  402. }
  403. for (i = 0; i < NUM_TX_DMA; i++) {
  404. /* reset control bits */
  405. aup->tx_dma_ring[i]->buff_stat &= ~0xf;
  406. }
  407. aup->mac_enabled = 0;
  408. }
  409. static void reset_mac(struct net_device *dev)
  410. {
  411. struct au1000_private *const aup = (struct au1000_private *) dev->priv;
  412. unsigned long flags;
  413. if (au1000_debug > 4)
  414. printk(KERN_INFO "%s: reset mac, aup %x\n",
  415. dev->name, (unsigned)aup);
  416. spin_lock_irqsave(&aup->lock, flags);
  417. reset_mac_unlocked (dev);
  418. spin_unlock_irqrestore(&aup->lock, flags);
  419. }
  420. /*
  421. * Setup the receive and transmit "rings". These pointers are the addresses
  422. * of the rx and tx MAC DMA registers so they are fixed by the hardware --
  423. * these are not descriptors sitting in memory.
  424. */
  425. static void
  426. setup_hw_rings(struct au1000_private *aup, u32 rx_base, u32 tx_base)
  427. {
  428. int i;
  429. for (i = 0; i < NUM_RX_DMA; i++) {
  430. aup->rx_dma_ring[i] =
  431. (volatile rx_dma_t *) (rx_base + sizeof(rx_dma_t)*i);
  432. }
  433. for (i = 0; i < NUM_TX_DMA; i++) {
  434. aup->tx_dma_ring[i] =
  435. (volatile tx_dma_t *) (tx_base + sizeof(tx_dma_t)*i);
  436. }
  437. }
  438. static struct {
  439. u32 base_addr;
  440. u32 macen_addr;
  441. int irq;
  442. struct net_device *dev;
  443. } iflist[2] = {
  444. #ifdef CONFIG_SOC_AU1000
  445. {AU1000_ETH0_BASE, AU1000_MAC0_ENABLE, AU1000_MAC0_DMA_INT},
  446. {AU1000_ETH1_BASE, AU1000_MAC1_ENABLE, AU1000_MAC1_DMA_INT}
  447. #endif
  448. #ifdef CONFIG_SOC_AU1100
  449. {AU1100_ETH0_BASE, AU1100_MAC0_ENABLE, AU1100_MAC0_DMA_INT}
  450. #endif
  451. #ifdef CONFIG_SOC_AU1500
  452. {AU1500_ETH0_BASE, AU1500_MAC0_ENABLE, AU1500_MAC0_DMA_INT},
  453. {AU1500_ETH1_BASE, AU1500_MAC1_ENABLE, AU1500_MAC1_DMA_INT}
  454. #endif
  455. #ifdef CONFIG_SOC_AU1550
  456. {AU1550_ETH0_BASE, AU1550_MAC0_ENABLE, AU1550_MAC0_DMA_INT},
  457. {AU1550_ETH1_BASE, AU1550_MAC1_ENABLE, AU1550_MAC1_DMA_INT}
  458. #endif
  459. };
  460. static int num_ifs;
  461. /*
  462. * Setup the base address and interrupt of the Au1xxx ethernet macs
  463. * based on cpu type and whether the interface is enabled in sys_pinfunc
  464. * register. The last interface is enabled if SYS_PF_NI2 (bit 4) is 0.
  465. */
  466. static int __init au1000_init_module(void)
  467. {
  468. int ni = (int)((au_readl(SYS_PINFUNC) & (u32)(SYS_PF_NI2)) >> 4);
  469. struct net_device *dev;
  470. int i, found_one = 0;
  471. num_ifs = NUM_ETH_INTERFACES - ni;
  472. for(i = 0; i < num_ifs; i++) {
  473. dev = au1000_probe(i);
  474. iflist[i].dev = dev;
  475. if (dev)
  476. found_one++;
  477. }
  478. if (!found_one)
  479. return -ENODEV;
  480. return 0;
  481. }
  482. /*
  483. * ethtool operations
  484. */
  485. static int au1000_get_settings(struct net_device *dev, struct ethtool_cmd *cmd)
  486. {
  487. struct au1000_private *aup = (struct au1000_private *)dev->priv;
  488. if (aup->phy_dev)
  489. return phy_ethtool_gset(aup->phy_dev, cmd);
  490. return -EINVAL;
  491. }
  492. static int au1000_set_settings(struct net_device *dev, struct ethtool_cmd *cmd)
  493. {
  494. struct au1000_private *aup = (struct au1000_private *)dev->priv;
  495. if (!capable(CAP_NET_ADMIN))
  496. return -EPERM;
  497. if (aup->phy_dev)
  498. return phy_ethtool_sset(aup->phy_dev, cmd);
  499. return -EINVAL;
  500. }
  501. static void
  502. au1000_get_drvinfo(struct net_device *dev, struct ethtool_drvinfo *info)
  503. {
  504. struct au1000_private *aup = (struct au1000_private *)dev->priv;
  505. strcpy(info->driver, DRV_NAME);
  506. strcpy(info->version, DRV_VERSION);
  507. info->fw_version[0] = '\0';
  508. sprintf(info->bus_info, "%s %d", DRV_NAME, aup->mac_id);
  509. info->regdump_len = 0;
  510. }
  511. static const struct ethtool_ops au1000_ethtool_ops = {
  512. .get_settings = au1000_get_settings,
  513. .set_settings = au1000_set_settings,
  514. .get_drvinfo = au1000_get_drvinfo,
  515. .get_link = ethtool_op_get_link,
  516. };
  517. static struct net_device * au1000_probe(int port_num)
  518. {
  519. static unsigned version_printed = 0;
  520. struct au1000_private *aup = NULL;
  521. struct net_device *dev = NULL;
  522. db_dest_t *pDB, *pDBfree;
  523. char ethaddr[6];
  524. int irq, i, err;
  525. u32 base, macen;
  526. if (port_num >= NUM_ETH_INTERFACES)
  527. return NULL;
  528. base = CPHYSADDR(iflist[port_num].base_addr );
  529. macen = CPHYSADDR(iflist[port_num].macen_addr);
  530. irq = iflist[port_num].irq;
  531. if (!request_mem_region( base, MAC_IOSIZE, "Au1x00 ENET") ||
  532. !request_mem_region(macen, 4, "Au1x00 ENET"))
  533. return NULL;
  534. if (version_printed++ == 0)
  535. printk("%s version %s %s\n", DRV_NAME, DRV_VERSION, DRV_AUTHOR);
  536. dev = alloc_etherdev(sizeof(struct au1000_private));
  537. if (!dev) {
  538. printk(KERN_ERR "%s: alloc_etherdev failed\n", DRV_NAME);
  539. return NULL;
  540. }
  541. if ((err = register_netdev(dev)) != 0) {
  542. printk(KERN_ERR "%s: Cannot register net device, error %d\n",
  543. DRV_NAME, err);
  544. free_netdev(dev);
  545. return NULL;
  546. }
  547. printk("%s: Au1xx0 Ethernet found at 0x%x, irq %d\n",
  548. dev->name, base, irq);
  549. aup = dev->priv;
  550. /* Allocate the data buffers */
  551. /* Snooping works fine with eth on all au1xxx */
  552. aup->vaddr = (u32)dma_alloc_noncoherent(NULL, MAX_BUF_SIZE *
  553. (NUM_TX_BUFFS + NUM_RX_BUFFS),
  554. &aup->dma_addr, 0);
  555. if (!aup->vaddr) {
  556. free_netdev(dev);
  557. release_mem_region( base, MAC_IOSIZE);
  558. release_mem_region(macen, 4);
  559. return NULL;
  560. }
  561. /* aup->mac is the base address of the MAC's registers */
  562. aup->mac = (volatile mac_reg_t *)iflist[port_num].base_addr;
  563. /* Setup some variables for quick register address access */
  564. aup->enable = (volatile u32 *)iflist[port_num].macen_addr;
  565. aup->mac_id = port_num;
  566. au_macs[port_num] = aup;
  567. if (port_num == 0) {
  568. if (prom_get_ethernet_addr(ethaddr) == 0)
  569. memcpy(au1000_mac_addr, ethaddr, sizeof(au1000_mac_addr));
  570. else {
  571. printk(KERN_INFO "%s: No MAC address found\n",
  572. dev->name);
  573. /* Use the hard coded MAC addresses */
  574. }
  575. setup_hw_rings(aup, MAC0_RX_DMA_ADDR, MAC0_TX_DMA_ADDR);
  576. } else if (port_num == 1)
  577. setup_hw_rings(aup, MAC1_RX_DMA_ADDR, MAC1_TX_DMA_ADDR);
  578. /*
  579. * Assign to the Ethernet ports two consecutive MAC addresses
  580. * to match those that are printed on their stickers
  581. */
  582. memcpy(dev->dev_addr, au1000_mac_addr, sizeof(au1000_mac_addr));
  583. dev->dev_addr[5] += port_num;
  584. *aup->enable = 0;
  585. aup->mac_enabled = 0;
  586. aup->mii_bus.priv = dev;
  587. aup->mii_bus.read = mdiobus_read;
  588. aup->mii_bus.write = mdiobus_write;
  589. aup->mii_bus.reset = mdiobus_reset;
  590. aup->mii_bus.name = "au1000_eth_mii";
  591. aup->mii_bus.id = aup->mac_id;
  592. aup->mii_bus.irq = kmalloc(sizeof(int)*PHY_MAX_ADDR, GFP_KERNEL);
  593. for(i = 0; i < PHY_MAX_ADDR; ++i)
  594. aup->mii_bus.irq[i] = PHY_POLL;
  595. /* if known, set corresponding PHY IRQs */
  596. #if defined(AU1XXX_PHY_STATIC_CONFIG)
  597. # if defined(AU1XXX_PHY0_IRQ)
  598. if (AU1XXX_PHY0_BUSID == aup->mii_bus.id)
  599. aup->mii_bus.irq[AU1XXX_PHY0_ADDR] = AU1XXX_PHY0_IRQ;
  600. # endif
  601. # if defined(AU1XXX_PHY1_IRQ)
  602. if (AU1XXX_PHY1_BUSID == aup->mii_bus.id)
  603. aup->mii_bus.irq[AU1XXX_PHY1_ADDR] = AU1XXX_PHY1_IRQ;
  604. # endif
  605. #endif
  606. mdiobus_register(&aup->mii_bus);
  607. if (mii_probe(dev) != 0) {
  608. goto err_out;
  609. }
  610. pDBfree = NULL;
  611. /* setup the data buffer descriptors and attach a buffer to each one */
  612. pDB = aup->db;
  613. for (i = 0; i < (NUM_TX_BUFFS+NUM_RX_BUFFS); i++) {
  614. pDB->pnext = pDBfree;
  615. pDBfree = pDB;
  616. pDB->vaddr = (u32 *)((unsigned)aup->vaddr + MAX_BUF_SIZE*i);
  617. pDB->dma_addr = (dma_addr_t)virt_to_bus(pDB->vaddr);
  618. pDB++;
  619. }
  620. aup->pDBfree = pDBfree;
  621. for (i = 0; i < NUM_RX_DMA; i++) {
  622. pDB = GetFreeDB(aup);
  623. if (!pDB) {
  624. goto err_out;
  625. }
  626. aup->rx_dma_ring[i]->buff_stat = (unsigned)pDB->dma_addr;
  627. aup->rx_db_inuse[i] = pDB;
  628. }
  629. for (i = 0; i < NUM_TX_DMA; i++) {
  630. pDB = GetFreeDB(aup);
  631. if (!pDB) {
  632. goto err_out;
  633. }
  634. aup->tx_dma_ring[i]->buff_stat = (unsigned)pDB->dma_addr;
  635. aup->tx_dma_ring[i]->len = 0;
  636. aup->tx_db_inuse[i] = pDB;
  637. }
  638. spin_lock_init(&aup->lock);
  639. dev->base_addr = base;
  640. dev->irq = irq;
  641. dev->open = au1000_open;
  642. dev->hard_start_xmit = au1000_tx;
  643. dev->stop = au1000_close;
  644. dev->set_multicast_list = &set_rx_mode;
  645. dev->do_ioctl = &au1000_ioctl;
  646. SET_ETHTOOL_OPS(dev, &au1000_ethtool_ops);
  647. dev->tx_timeout = au1000_tx_timeout;
  648. dev->watchdog_timeo = ETH_TX_TIMEOUT;
  649. /*
  650. * The boot code uses the ethernet controller, so reset it to start
  651. * fresh. au1000_init() expects that the device is in reset state.
  652. */
  653. reset_mac(dev);
  654. return dev;
  655. err_out:
  656. /* here we should have a valid dev plus aup-> register addresses
  657. * so we can reset the mac properly.*/
  658. reset_mac(dev);
  659. for (i = 0; i < NUM_RX_DMA; i++) {
  660. if (aup->rx_db_inuse[i])
  661. ReleaseDB(aup, aup->rx_db_inuse[i]);
  662. }
  663. for (i = 0; i < NUM_TX_DMA; i++) {
  664. if (aup->tx_db_inuse[i])
  665. ReleaseDB(aup, aup->tx_db_inuse[i]);
  666. }
  667. dma_free_noncoherent(NULL, MAX_BUF_SIZE * (NUM_TX_BUFFS + NUM_RX_BUFFS),
  668. (void *)aup->vaddr, aup->dma_addr);
  669. unregister_netdev(dev);
  670. free_netdev(dev);
  671. release_mem_region( base, MAC_IOSIZE);
  672. release_mem_region(macen, 4);
  673. return NULL;
  674. }
  675. /*
  676. * Initialize the interface.
  677. *
  678. * When the device powers up, the clocks are disabled and the
  679. * mac is in reset state. When the interface is closed, we
  680. * do the same -- reset the device and disable the clocks to
  681. * conserve power. Thus, whenever au1000_init() is called,
  682. * the device should already be in reset state.
  683. */
  684. static int au1000_init(struct net_device *dev)
  685. {
  686. struct au1000_private *aup = (struct au1000_private *) dev->priv;
  687. u32 flags;
  688. int i;
  689. u32 control;
  690. if (au1000_debug > 4)
  691. printk("%s: au1000_init\n", dev->name);
  692. /* bring the device out of reset */
  693. enable_mac(dev, 1);
  694. spin_lock_irqsave(&aup->lock, flags);
  695. aup->mac->control = 0;
  696. aup->tx_head = (aup->tx_dma_ring[0]->buff_stat & 0xC) >> 2;
  697. aup->tx_tail = aup->tx_head;
  698. aup->rx_head = (aup->rx_dma_ring[0]->buff_stat & 0xC) >> 2;
  699. aup->mac->mac_addr_high = dev->dev_addr[5]<<8 | dev->dev_addr[4];
  700. aup->mac->mac_addr_low = dev->dev_addr[3]<<24 | dev->dev_addr[2]<<16 |
  701. dev->dev_addr[1]<<8 | dev->dev_addr[0];
  702. for (i = 0; i < NUM_RX_DMA; i++) {
  703. aup->rx_dma_ring[i]->buff_stat |= RX_DMA_ENABLE;
  704. }
  705. au_sync();
  706. control = MAC_RX_ENABLE | MAC_TX_ENABLE;
  707. #ifndef CONFIG_CPU_LITTLE_ENDIAN
  708. control |= MAC_BIG_ENDIAN;
  709. #endif
  710. if (aup->phy_dev) {
  711. if (aup->phy_dev->link && (DUPLEX_FULL == aup->phy_dev->duplex))
  712. control |= MAC_FULL_DUPLEX;
  713. else
  714. control |= MAC_DISABLE_RX_OWN;
  715. } else { /* PHY-less op, assume full-duplex */
  716. control |= MAC_FULL_DUPLEX;
  717. }
  718. aup->mac->control = control;
  719. aup->mac->vlan1_tag = 0x8100; /* activate vlan support */
  720. au_sync();
  721. spin_unlock_irqrestore(&aup->lock, flags);
  722. return 0;
  723. }
  724. static void
  725. au1000_adjust_link(struct net_device *dev)
  726. {
  727. struct au1000_private *aup = (struct au1000_private *) dev->priv;
  728. struct phy_device *phydev = aup->phy_dev;
  729. unsigned long flags;
  730. int status_change = 0;
  731. BUG_ON(!aup->phy_dev);
  732. spin_lock_irqsave(&aup->lock, flags);
  733. if (phydev->link && (aup->old_speed != phydev->speed)) {
  734. // speed changed
  735. switch(phydev->speed) {
  736. case SPEED_10:
  737. case SPEED_100:
  738. break;
  739. default:
  740. printk(KERN_WARNING
  741. "%s: Speed (%d) is not 10/100 ???\n",
  742. dev->name, phydev->speed);
  743. break;
  744. }
  745. aup->old_speed = phydev->speed;
  746. status_change = 1;
  747. }
  748. if (phydev->link && (aup->old_duplex != phydev->duplex)) {
  749. // duplex mode changed
  750. /* switching duplex mode requires to disable rx and tx! */
  751. hard_stop(dev);
  752. if (DUPLEX_FULL == phydev->duplex)
  753. aup->mac->control = ((aup->mac->control
  754. | MAC_FULL_DUPLEX)
  755. & ~MAC_DISABLE_RX_OWN);
  756. else
  757. aup->mac->control = ((aup->mac->control
  758. & ~MAC_FULL_DUPLEX)
  759. | MAC_DISABLE_RX_OWN);
  760. au_sync_delay(1);
  761. enable_rx_tx(dev);
  762. aup->old_duplex = phydev->duplex;
  763. status_change = 1;
  764. }
  765. if(phydev->link != aup->old_link) {
  766. // link state changed
  767. if (phydev->link) // link went up
  768. netif_schedule(dev);
  769. else { // link went down
  770. aup->old_speed = 0;
  771. aup->old_duplex = -1;
  772. }
  773. aup->old_link = phydev->link;
  774. status_change = 1;
  775. }
  776. spin_unlock_irqrestore(&aup->lock, flags);
  777. if (status_change) {
  778. if (phydev->link)
  779. printk(KERN_INFO "%s: link up (%d/%s)\n",
  780. dev->name, phydev->speed,
  781. DUPLEX_FULL == phydev->duplex ? "Full" : "Half");
  782. else
  783. printk(KERN_INFO "%s: link down\n", dev->name);
  784. }
  785. }
  786. static int au1000_open(struct net_device *dev)
  787. {
  788. int retval;
  789. struct au1000_private *aup = (struct au1000_private *) dev->priv;
  790. if (au1000_debug > 4)
  791. printk("%s: open: dev=%p\n", dev->name, dev);
  792. if ((retval = request_irq(dev->irq, &au1000_interrupt, 0,
  793. dev->name, dev))) {
  794. printk(KERN_ERR "%s: unable to get IRQ %d\n",
  795. dev->name, dev->irq);
  796. return retval;
  797. }
  798. if ((retval = au1000_init(dev))) {
  799. printk(KERN_ERR "%s: error in au1000_init\n", dev->name);
  800. free_irq(dev->irq, dev);
  801. return retval;
  802. }
  803. if (aup->phy_dev) {
  804. /* cause the PHY state machine to schedule a link state check */
  805. aup->phy_dev->state = PHY_CHANGELINK;
  806. phy_start(aup->phy_dev);
  807. }
  808. netif_start_queue(dev);
  809. if (au1000_debug > 4)
  810. printk("%s: open: Initialization done.\n", dev->name);
  811. return 0;
  812. }
  813. static int au1000_close(struct net_device *dev)
  814. {
  815. unsigned long flags;
  816. struct au1000_private *const aup = (struct au1000_private *) dev->priv;
  817. if (au1000_debug > 4)
  818. printk("%s: close: dev=%p\n", dev->name, dev);
  819. if (aup->phy_dev)
  820. phy_stop(aup->phy_dev);
  821. spin_lock_irqsave(&aup->lock, flags);
  822. reset_mac_unlocked (dev);
  823. /* stop the device */
  824. netif_stop_queue(dev);
  825. /* disable the interrupt */
  826. free_irq(dev->irq, dev);
  827. spin_unlock_irqrestore(&aup->lock, flags);
  828. return 0;
  829. }
  830. static void __exit au1000_cleanup_module(void)
  831. {
  832. int i, j;
  833. struct net_device *dev;
  834. struct au1000_private *aup;
  835. for (i = 0; i < num_ifs; i++) {
  836. dev = iflist[i].dev;
  837. if (dev) {
  838. aup = (struct au1000_private *) dev->priv;
  839. unregister_netdev(dev);
  840. for (j = 0; j < NUM_RX_DMA; j++)
  841. if (aup->rx_db_inuse[j])
  842. ReleaseDB(aup, aup->rx_db_inuse[j]);
  843. for (j = 0; j < NUM_TX_DMA; j++)
  844. if (aup->tx_db_inuse[j])
  845. ReleaseDB(aup, aup->tx_db_inuse[j]);
  846. dma_free_noncoherent(NULL, MAX_BUF_SIZE *
  847. (NUM_TX_BUFFS + NUM_RX_BUFFS),
  848. (void *)aup->vaddr, aup->dma_addr);
  849. release_mem_region(dev->base_addr, MAC_IOSIZE);
  850. release_mem_region(CPHYSADDR(iflist[i].macen_addr), 4);
  851. free_netdev(dev);
  852. }
  853. }
  854. }
  855. static void update_tx_stats(struct net_device *dev, u32 status)
  856. {
  857. struct au1000_private *aup = (struct au1000_private *) dev->priv;
  858. struct net_device_stats *ps = &dev->stats;
  859. if (status & TX_FRAME_ABORTED) {
  860. if (!aup->phy_dev || (DUPLEX_FULL == aup->phy_dev->duplex)) {
  861. if (status & (TX_JAB_TIMEOUT | TX_UNDERRUN)) {
  862. /* any other tx errors are only valid
  863. * in half duplex mode */
  864. ps->tx_errors++;
  865. ps->tx_aborted_errors++;
  866. }
  867. }
  868. else {
  869. ps->tx_errors++;
  870. ps->tx_aborted_errors++;
  871. if (status & (TX_NO_CARRIER | TX_LOSS_CARRIER))
  872. ps->tx_carrier_errors++;
  873. }
  874. }
  875. }
  876. /*
  877. * Called from the interrupt service routine to acknowledge
  878. * the TX DONE bits. This is a must if the irq is setup as
  879. * edge triggered.
  880. */
  881. static void au1000_tx_ack(struct net_device *dev)
  882. {
  883. struct au1000_private *aup = (struct au1000_private *) dev->priv;
  884. volatile tx_dma_t *ptxd;
  885. ptxd = aup->tx_dma_ring[aup->tx_tail];
  886. while (ptxd->buff_stat & TX_T_DONE) {
  887. update_tx_stats(dev, ptxd->status);
  888. ptxd->buff_stat &= ~TX_T_DONE;
  889. ptxd->len = 0;
  890. au_sync();
  891. aup->tx_tail = (aup->tx_tail + 1) & (NUM_TX_DMA - 1);
  892. ptxd = aup->tx_dma_ring[aup->tx_tail];
  893. if (aup->tx_full) {
  894. aup->tx_full = 0;
  895. netif_wake_queue(dev);
  896. }
  897. }
  898. }
  899. /*
  900. * Au1000 transmit routine.
  901. */
  902. static int au1000_tx(struct sk_buff *skb, struct net_device *dev)
  903. {
  904. struct au1000_private *aup = (struct au1000_private *) dev->priv;
  905. struct net_device_stats *ps = &dev->stats;
  906. volatile tx_dma_t *ptxd;
  907. u32 buff_stat;
  908. db_dest_t *pDB;
  909. int i;
  910. if (au1000_debug > 5)
  911. printk("%s: tx: aup %x len=%d, data=%p, head %d\n",
  912. dev->name, (unsigned)aup, skb->len,
  913. skb->data, aup->tx_head);
  914. ptxd = aup->tx_dma_ring[aup->tx_head];
  915. buff_stat = ptxd->buff_stat;
  916. if (buff_stat & TX_DMA_ENABLE) {
  917. /* We've wrapped around and the transmitter is still busy */
  918. netif_stop_queue(dev);
  919. aup->tx_full = 1;
  920. return 1;
  921. }
  922. else if (buff_stat & TX_T_DONE) {
  923. update_tx_stats(dev, ptxd->status);
  924. ptxd->len = 0;
  925. }
  926. if (aup->tx_full) {
  927. aup->tx_full = 0;
  928. netif_wake_queue(dev);
  929. }
  930. pDB = aup->tx_db_inuse[aup->tx_head];
  931. skb_copy_from_linear_data(skb, pDB->vaddr, skb->len);
  932. if (skb->len < ETH_ZLEN) {
  933. for (i=skb->len; i<ETH_ZLEN; i++) {
  934. ((char *)pDB->vaddr)[i] = 0;
  935. }
  936. ptxd->len = ETH_ZLEN;
  937. }
  938. else
  939. ptxd->len = skb->len;
  940. ps->tx_packets++;
  941. ps->tx_bytes += ptxd->len;
  942. ptxd->buff_stat = pDB->dma_addr | TX_DMA_ENABLE;
  943. au_sync();
  944. dev_kfree_skb(skb);
  945. aup->tx_head = (aup->tx_head + 1) & (NUM_TX_DMA - 1);
  946. dev->trans_start = jiffies;
  947. return 0;
  948. }
  949. static inline void update_rx_stats(struct net_device *dev, u32 status)
  950. {
  951. struct au1000_private *aup = (struct au1000_private *) dev->priv;
  952. struct net_device_stats *ps = &dev->stats;
  953. ps->rx_packets++;
  954. if (status & RX_MCAST_FRAME)
  955. ps->multicast++;
  956. if (status & RX_ERROR) {
  957. ps->rx_errors++;
  958. if (status & RX_MISSED_FRAME)
  959. ps->rx_missed_errors++;
  960. if (status & (RX_OVERLEN | RX_OVERLEN | RX_LEN_ERROR))
  961. ps->rx_length_errors++;
  962. if (status & RX_CRC_ERROR)
  963. ps->rx_crc_errors++;
  964. if (status & RX_COLL)
  965. ps->collisions++;
  966. }
  967. else
  968. ps->rx_bytes += status & RX_FRAME_LEN_MASK;
  969. }
  970. /*
  971. * Au1000 receive routine.
  972. */
  973. static int au1000_rx(struct net_device *dev)
  974. {
  975. struct au1000_private *aup = (struct au1000_private *) dev->priv;
  976. struct sk_buff *skb;
  977. volatile rx_dma_t *prxd;
  978. u32 buff_stat, status;
  979. db_dest_t *pDB;
  980. u32 frmlen;
  981. if (au1000_debug > 5)
  982. printk("%s: au1000_rx head %d\n", dev->name, aup->rx_head);
  983. prxd = aup->rx_dma_ring[aup->rx_head];
  984. buff_stat = prxd->buff_stat;
  985. while (buff_stat & RX_T_DONE) {
  986. status = prxd->status;
  987. pDB = aup->rx_db_inuse[aup->rx_head];
  988. update_rx_stats(dev, status);
  989. if (!(status & RX_ERROR)) {
  990. /* good frame */
  991. frmlen = (status & RX_FRAME_LEN_MASK);
  992. frmlen -= 4; /* Remove FCS */
  993. skb = dev_alloc_skb(frmlen + 2);
  994. if (skb == NULL) {
  995. printk(KERN_ERR
  996. "%s: Memory squeeze, dropping packet.\n",
  997. dev->name);
  998. dev->stats.rx_dropped++;
  999. continue;
  1000. }
  1001. skb_reserve(skb, 2); /* 16 byte IP header align */
  1002. skb_copy_to_linear_data(skb,
  1003. (unsigned char *)pDB->vaddr, frmlen);
  1004. skb_put(skb, frmlen);
  1005. skb->protocol = eth_type_trans(skb, dev);
  1006. netif_rx(skb); /* pass the packet to upper layers */
  1007. }
  1008. else {
  1009. if (au1000_debug > 4) {
  1010. if (status & RX_MISSED_FRAME)
  1011. printk("rx miss\n");
  1012. if (status & RX_WDOG_TIMER)
  1013. printk("rx wdog\n");
  1014. if (status & RX_RUNT)
  1015. printk("rx runt\n");
  1016. if (status & RX_OVERLEN)
  1017. printk("rx overlen\n");
  1018. if (status & RX_COLL)
  1019. printk("rx coll\n");
  1020. if (status & RX_MII_ERROR)
  1021. printk("rx mii error\n");
  1022. if (status & RX_CRC_ERROR)
  1023. printk("rx crc error\n");
  1024. if (status & RX_LEN_ERROR)
  1025. printk("rx len error\n");
  1026. if (status & RX_U_CNTRL_FRAME)
  1027. printk("rx u control frame\n");
  1028. if (status & RX_MISSED_FRAME)
  1029. printk("rx miss\n");
  1030. }
  1031. }
  1032. prxd->buff_stat = (u32)(pDB->dma_addr | RX_DMA_ENABLE);
  1033. aup->rx_head = (aup->rx_head + 1) & (NUM_RX_DMA - 1);
  1034. au_sync();
  1035. /* next descriptor */
  1036. prxd = aup->rx_dma_ring[aup->rx_head];
  1037. buff_stat = prxd->buff_stat;
  1038. dev->last_rx = jiffies;
  1039. }
  1040. return 0;
  1041. }
  1042. /*
  1043. * Au1000 interrupt service routine.
  1044. */
  1045. static irqreturn_t au1000_interrupt(int irq, void *dev_id)
  1046. {
  1047. struct net_device *dev = (struct net_device *) dev_id;
  1048. if (dev == NULL) {
  1049. printk(KERN_ERR "%s: isr: null dev ptr\n", dev->name);
  1050. return IRQ_RETVAL(1);
  1051. }
  1052. /* Handle RX interrupts first to minimize chance of overrun */
  1053. au1000_rx(dev);
  1054. au1000_tx_ack(dev);
  1055. return IRQ_RETVAL(1);
  1056. }
  1057. /*
  1058. * The Tx ring has been full longer than the watchdog timeout
  1059. * value. The transmitter must be hung?
  1060. */
  1061. static void au1000_tx_timeout(struct net_device *dev)
  1062. {
  1063. printk(KERN_ERR "%s: au1000_tx_timeout: dev=%p\n", dev->name, dev);
  1064. reset_mac(dev);
  1065. au1000_init(dev);
  1066. dev->trans_start = jiffies;
  1067. netif_wake_queue(dev);
  1068. }
  1069. static void set_rx_mode(struct net_device *dev)
  1070. {
  1071. struct au1000_private *aup = (struct au1000_private *) dev->priv;
  1072. if (au1000_debug > 4)
  1073. printk("%s: set_rx_mode: flags=%x\n", dev->name, dev->flags);
  1074. if (dev->flags & IFF_PROMISC) { /* Set promiscuous. */
  1075. aup->mac->control |= MAC_PROMISCUOUS;
  1076. } else if ((dev->flags & IFF_ALLMULTI) ||
  1077. dev->mc_count > MULTICAST_FILTER_LIMIT) {
  1078. aup->mac->control |= MAC_PASS_ALL_MULTI;
  1079. aup->mac->control &= ~MAC_PROMISCUOUS;
  1080. printk(KERN_INFO "%s: Pass all multicast\n", dev->name);
  1081. } else {
  1082. int i;
  1083. struct dev_mc_list *mclist;
  1084. u32 mc_filter[2]; /* Multicast hash filter */
  1085. mc_filter[1] = mc_filter[0] = 0;
  1086. for (i = 0, mclist = dev->mc_list; mclist && i < dev->mc_count;
  1087. i++, mclist = mclist->next) {
  1088. set_bit(ether_crc(ETH_ALEN, mclist->dmi_addr)>>26,
  1089. (long *)mc_filter);
  1090. }
  1091. aup->mac->multi_hash_high = mc_filter[1];
  1092. aup->mac->multi_hash_low = mc_filter[0];
  1093. aup->mac->control &= ~MAC_PROMISCUOUS;
  1094. aup->mac->control |= MAC_HASH_MODE;
  1095. }
  1096. }
  1097. static int au1000_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
  1098. {
  1099. struct au1000_private *aup = (struct au1000_private *)dev->priv;
  1100. if (!netif_running(dev)) return -EINVAL;
  1101. if (!aup->phy_dev) return -EINVAL; // PHY not controllable
  1102. return phy_mii_ioctl(aup->phy_dev, if_mii(rq), cmd);
  1103. }
  1104. module_init(au1000_init_module);
  1105. module_exit(au1000_cleanup_module);