korina.c 32 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237
  1. /*
  2. * Driver for the IDT RC32434 (Korina) on-chip ethernet controller.
  3. *
  4. * Copyright 2004 IDT Inc. (rischelp@idt.com)
  5. * Copyright 2006 Felix Fietkau <nbd@openwrt.org>
  6. * Copyright 2008 Florian Fainelli <florian@openwrt.org>
  7. *
  8. * This program is free software; you can redistribute it and/or modify it
  9. * under the terms of the GNU General Public License as published by the
  10. * Free Software Foundation; either version 2 of the License, or (at your
  11. * option) any later version.
  12. *
  13. * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
  14. * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  15. * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
  16. * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
  17. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  18. * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
  19. * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
  20. * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  21. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  22. * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  23. *
  24. * You should have received a copy of the GNU General Public License along
  25. * with this program; if not, write to the Free Software Foundation, Inc.,
  26. * 675 Mass Ave, Cambridge, MA 02139, USA.
  27. *
  28. * Writing to a DMA status register:
  29. *
  30. * When writing to the status register, you should mask the bit you have
  31. * been testing the status register with. Both Tx and Rx DMA registers
  32. * should stick to this procedure.
  33. */
  34. #include <linux/module.h>
  35. #include <linux/kernel.h>
  36. #include <linux/moduleparam.h>
  37. #include <linux/sched.h>
  38. #include <linux/ctype.h>
  39. #include <linux/types.h>
  40. #include <linux/interrupt.h>
  41. #include <linux/init.h>
  42. #include <linux/ioport.h>
  43. #include <linux/in.h>
  44. #include <linux/slab.h>
  45. #include <linux/string.h>
  46. #include <linux/delay.h>
  47. #include <linux/netdevice.h>
  48. #include <linux/etherdevice.h>
  49. #include <linux/skbuff.h>
  50. #include <linux/errno.h>
  51. #include <linux/platform_device.h>
  52. #include <linux/mii.h>
  53. #include <linux/ethtool.h>
  54. #include <linux/crc32.h>
  55. #include <asm/bootinfo.h>
  56. #include <asm/bitops.h>
  57. #include <asm/pgtable.h>
  58. #include <asm/io.h>
  59. #include <asm/dma.h>
  60. #include <asm/mach-rc32434/rb.h>
  61. #include <asm/mach-rc32434/rc32434.h>
  62. #include <asm/mach-rc32434/eth.h>
  63. #include <asm/mach-rc32434/dma_v.h>
  64. #define DRV_NAME "korina"
  65. #define DRV_VERSION "0.10"
  66. #define DRV_RELDATE "04Mar2008"
  67. #define STATION_ADDRESS_HIGH(dev) (((dev)->dev_addr[0] << 8) | \
  68. ((dev)->dev_addr[1]))
  69. #define STATION_ADDRESS_LOW(dev) (((dev)->dev_addr[2] << 24) | \
  70. ((dev)->dev_addr[3] << 16) | \
  71. ((dev)->dev_addr[4] << 8) | \
  72. ((dev)->dev_addr[5]))
  73. #define MII_CLOCK 1250000 /* no more than 2.5MHz */
  74. /* the following must be powers of two */
  75. #define KORINA_NUM_RDS 64 /* number of receive descriptors */
  76. #define KORINA_NUM_TDS 64 /* number of transmit descriptors */
  77. /* KORINA_RBSIZE is the hardware's default maximum receive
  78. * frame size in bytes. Having this hardcoded means that there
  79. * is no support for MTU sizes greater than 1500. */
  80. #define KORINA_RBSIZE 1536 /* size of one resource buffer = Ether MTU */
  81. #define KORINA_RDS_MASK (KORINA_NUM_RDS - 1)
  82. #define KORINA_TDS_MASK (KORINA_NUM_TDS - 1)
  83. #define RD_RING_SIZE (KORINA_NUM_RDS * sizeof(struct dma_desc))
  84. #define TD_RING_SIZE (KORINA_NUM_TDS * sizeof(struct dma_desc))
  85. #define TX_TIMEOUT (6000 * HZ / 1000)
  86. enum chain_status { desc_filled, desc_empty };
  87. #define IS_DMA_FINISHED(X) (((X) & (DMA_DESC_FINI)) != 0)
  88. #define IS_DMA_DONE(X) (((X) & (DMA_DESC_DONE)) != 0)
  89. #define RCVPKT_LENGTH(X) (((X) & ETH_RX_LEN) >> ETH_RX_LEN_BIT)
  90. /* Information that need to be kept for each board. */
  91. struct korina_private {
  92. struct eth_regs *eth_regs;
  93. struct dma_reg *rx_dma_regs;
  94. struct dma_reg *tx_dma_regs;
  95. struct dma_desc *td_ring; /* transmit descriptor ring */
  96. struct dma_desc *rd_ring; /* receive descriptor ring */
  97. struct sk_buff *tx_skb[KORINA_NUM_TDS];
  98. struct sk_buff *rx_skb[KORINA_NUM_RDS];
  99. int rx_next_done;
  100. int rx_chain_head;
  101. int rx_chain_tail;
  102. enum chain_status rx_chain_status;
  103. int tx_next_done;
  104. int tx_chain_head;
  105. int tx_chain_tail;
  106. enum chain_status tx_chain_status;
  107. int tx_count;
  108. int tx_full;
  109. int rx_irq;
  110. int tx_irq;
  111. int ovr_irq;
  112. int und_irq;
  113. spinlock_t lock; /* NIC xmit lock */
  114. int dma_halt_cnt;
  115. int dma_run_cnt;
  116. struct napi_struct napi;
  117. struct timer_list media_check_timer;
  118. struct mii_if_info mii_if;
  119. struct work_struct restart_task;
  120. struct net_device *dev;
  121. int phy_addr;
  122. };
  123. extern unsigned int idt_cpu_freq;
  124. static inline void korina_start_dma(struct dma_reg *ch, u32 dma_addr)
  125. {
  126. writel(0, &ch->dmandptr);
  127. writel(dma_addr, &ch->dmadptr);
  128. }
  129. static inline void korina_abort_dma(struct net_device *dev,
  130. struct dma_reg *ch)
  131. {
  132. if (readl(&ch->dmac) & DMA_CHAN_RUN_BIT) {
  133. writel(0x10, &ch->dmac);
  134. while (!(readl(&ch->dmas) & DMA_STAT_HALT))
  135. dev->trans_start = jiffies;
  136. writel(0, &ch->dmas);
  137. }
  138. writel(0, &ch->dmadptr);
  139. writel(0, &ch->dmandptr);
  140. }
  141. static inline void korina_chain_dma(struct dma_reg *ch, u32 dma_addr)
  142. {
  143. writel(dma_addr, &ch->dmandptr);
  144. }
  145. static void korina_abort_tx(struct net_device *dev)
  146. {
  147. struct korina_private *lp = netdev_priv(dev);
  148. korina_abort_dma(dev, lp->tx_dma_regs);
  149. }
  150. static void korina_abort_rx(struct net_device *dev)
  151. {
  152. struct korina_private *lp = netdev_priv(dev);
  153. korina_abort_dma(dev, lp->rx_dma_regs);
  154. }
  155. static void korina_start_rx(struct korina_private *lp,
  156. struct dma_desc *rd)
  157. {
  158. korina_start_dma(lp->rx_dma_regs, CPHYSADDR(rd));
  159. }
  160. static void korina_chain_rx(struct korina_private *lp,
  161. struct dma_desc *rd)
  162. {
  163. korina_chain_dma(lp->rx_dma_regs, CPHYSADDR(rd));
  164. }
  165. /* transmit packet */
  166. static int korina_send_packet(struct sk_buff *skb, struct net_device *dev)
  167. {
  168. struct korina_private *lp = netdev_priv(dev);
  169. unsigned long flags;
  170. u32 length;
  171. u32 chain_prev, chain_next;
  172. struct dma_desc *td;
  173. spin_lock_irqsave(&lp->lock, flags);
  174. td = &lp->td_ring[lp->tx_chain_tail];
  175. /* stop queue when full, drop pkts if queue already full */
  176. if (lp->tx_count >= (KORINA_NUM_TDS - 2)) {
  177. lp->tx_full = 1;
  178. if (lp->tx_count == (KORINA_NUM_TDS - 2))
  179. netif_stop_queue(dev);
  180. else {
  181. dev->stats.tx_dropped++;
  182. dev_kfree_skb_any(skb);
  183. spin_unlock_irqrestore(&lp->lock, flags);
  184. return NETDEV_TX_BUSY;
  185. }
  186. }
  187. lp->tx_count++;
  188. lp->tx_skb[lp->tx_chain_tail] = skb;
  189. length = skb->len;
  190. dma_cache_wback((u32)skb->data, skb->len);
  191. /* Setup the transmit descriptor. */
  192. dma_cache_inv((u32) td, sizeof(*td));
  193. td->ca = CPHYSADDR(skb->data);
  194. chain_prev = (lp->tx_chain_tail - 1) & KORINA_TDS_MASK;
  195. chain_next = (lp->tx_chain_tail + 1) & KORINA_TDS_MASK;
  196. if (readl(&(lp->tx_dma_regs->dmandptr)) == 0) {
  197. if (lp->tx_chain_status == desc_empty) {
  198. /* Update tail */
  199. td->control = DMA_COUNT(length) |
  200. DMA_DESC_COF | DMA_DESC_IOF;
  201. /* Move tail */
  202. lp->tx_chain_tail = chain_next;
  203. /* Write to NDPTR */
  204. writel(CPHYSADDR(&lp->td_ring[lp->tx_chain_head]),
  205. &lp->tx_dma_regs->dmandptr);
  206. /* Move head to tail */
  207. lp->tx_chain_head = lp->tx_chain_tail;
  208. } else {
  209. /* Update tail */
  210. td->control = DMA_COUNT(length) |
  211. DMA_DESC_COF | DMA_DESC_IOF;
  212. /* Link to prev */
  213. lp->td_ring[chain_prev].control &=
  214. ~DMA_DESC_COF;
  215. /* Link to prev */
  216. lp->td_ring[chain_prev].link = CPHYSADDR(td);
  217. /* Move tail */
  218. lp->tx_chain_tail = chain_next;
  219. /* Write to NDPTR */
  220. writel(CPHYSADDR(&lp->td_ring[lp->tx_chain_head]),
  221. &(lp->tx_dma_regs->dmandptr));
  222. /* Move head to tail */
  223. lp->tx_chain_head = lp->tx_chain_tail;
  224. lp->tx_chain_status = desc_empty;
  225. }
  226. } else {
  227. if (lp->tx_chain_status == desc_empty) {
  228. /* Update tail */
  229. td->control = DMA_COUNT(length) |
  230. DMA_DESC_COF | DMA_DESC_IOF;
  231. /* Move tail */
  232. lp->tx_chain_tail = chain_next;
  233. lp->tx_chain_status = desc_filled;
  234. } else {
  235. /* Update tail */
  236. td->control = DMA_COUNT(length) |
  237. DMA_DESC_COF | DMA_DESC_IOF;
  238. lp->td_ring[chain_prev].control &=
  239. ~DMA_DESC_COF;
  240. lp->td_ring[chain_prev].link = CPHYSADDR(td);
  241. lp->tx_chain_tail = chain_next;
  242. }
  243. }
  244. dma_cache_wback((u32) td, sizeof(*td));
  245. dev->trans_start = jiffies;
  246. spin_unlock_irqrestore(&lp->lock, flags);
  247. return NETDEV_TX_OK;
  248. }
  249. static int mdio_read(struct net_device *dev, int mii_id, int reg)
  250. {
  251. struct korina_private *lp = netdev_priv(dev);
  252. int ret;
  253. mii_id = ((lp->rx_irq == 0x2c ? 1 : 0) << 8);
  254. writel(0, &lp->eth_regs->miimcfg);
  255. writel(0, &lp->eth_regs->miimcmd);
  256. writel(mii_id | reg, &lp->eth_regs->miimaddr);
  257. writel(ETH_MII_CMD_SCN, &lp->eth_regs->miimcmd);
  258. ret = (int)(readl(&lp->eth_regs->miimrdd));
  259. return ret;
  260. }
  261. static void mdio_write(struct net_device *dev, int mii_id, int reg, int val)
  262. {
  263. struct korina_private *lp = netdev_priv(dev);
  264. mii_id = ((lp->rx_irq == 0x2c ? 1 : 0) << 8);
  265. writel(0, &lp->eth_regs->miimcfg);
  266. writel(1, &lp->eth_regs->miimcmd);
  267. writel(mii_id | reg, &lp->eth_regs->miimaddr);
  268. writel(ETH_MII_CMD_SCN, &lp->eth_regs->miimcmd);
  269. writel(val, &lp->eth_regs->miimwtd);
  270. }
  271. /* Ethernet Rx DMA interrupt */
  272. static irqreturn_t korina_rx_dma_interrupt(int irq, void *dev_id)
  273. {
  274. struct net_device *dev = dev_id;
  275. struct korina_private *lp = netdev_priv(dev);
  276. u32 dmas, dmasm;
  277. irqreturn_t retval;
  278. dmas = readl(&lp->rx_dma_regs->dmas);
  279. if (dmas & (DMA_STAT_DONE | DMA_STAT_HALT | DMA_STAT_ERR)) {
  280. dmasm = readl(&lp->rx_dma_regs->dmasm);
  281. writel(dmasm | (DMA_STAT_DONE |
  282. DMA_STAT_HALT | DMA_STAT_ERR),
  283. &lp->rx_dma_regs->dmasm);
  284. napi_schedule(&lp->napi);
  285. if (dmas & DMA_STAT_ERR)
  286. printk(KERN_ERR "%s: DMA error\n", dev->name);
  287. retval = IRQ_HANDLED;
  288. } else
  289. retval = IRQ_NONE;
  290. return retval;
  291. }
  292. static int korina_rx(struct net_device *dev, int limit)
  293. {
  294. struct korina_private *lp = netdev_priv(dev);
  295. struct dma_desc *rd = &lp->rd_ring[lp->rx_next_done];
  296. struct sk_buff *skb, *skb_new;
  297. u8 *pkt_buf;
  298. u32 devcs, pkt_len, dmas;
  299. int count;
  300. dma_cache_inv((u32)rd, sizeof(*rd));
  301. for (count = 0; count < limit; count++) {
  302. skb = lp->rx_skb[lp->rx_next_done];
  303. skb_new = NULL;
  304. devcs = rd->devcs;
  305. if ((KORINA_RBSIZE - (u32)DMA_COUNT(rd->control)) == 0)
  306. break;
  307. /* Update statistics counters */
  308. if (devcs & ETH_RX_CRC)
  309. dev->stats.rx_crc_errors++;
  310. if (devcs & ETH_RX_LOR)
  311. dev->stats.rx_length_errors++;
  312. if (devcs & ETH_RX_LE)
  313. dev->stats.rx_length_errors++;
  314. if (devcs & ETH_RX_OVR)
  315. dev->stats.rx_fifo_errors++;
  316. if (devcs & ETH_RX_CV)
  317. dev->stats.rx_frame_errors++;
  318. if (devcs & ETH_RX_CES)
  319. dev->stats.rx_length_errors++;
  320. if (devcs & ETH_RX_MP)
  321. dev->stats.multicast++;
  322. if ((devcs & ETH_RX_LD) != ETH_RX_LD) {
  323. /* check that this is a whole packet
  324. * WARNING: DMA_FD bit incorrectly set
  325. * in Rc32434 (errata ref #077) */
  326. dev->stats.rx_errors++;
  327. dev->stats.rx_dropped++;
  328. } else if ((devcs & ETH_RX_ROK)) {
  329. pkt_len = RCVPKT_LENGTH(devcs);
  330. /* must be the (first and) last
  331. * descriptor then */
  332. pkt_buf = (u8 *)lp->rx_skb[lp->rx_next_done]->data;
  333. /* invalidate the cache */
  334. dma_cache_inv((unsigned long)pkt_buf, pkt_len - 4);
  335. /* Malloc up new buffer. */
  336. skb_new = netdev_alloc_skb_ip_align(dev, KORINA_RBSIZE);
  337. if (!skb_new)
  338. break;
  339. /* Do not count the CRC */
  340. skb_put(skb, pkt_len - 4);
  341. skb->protocol = eth_type_trans(skb, dev);
  342. /* Pass the packet to upper layers */
  343. netif_receive_skb(skb);
  344. dev->stats.rx_packets++;
  345. dev->stats.rx_bytes += pkt_len;
  346. /* Update the mcast stats */
  347. if (devcs & ETH_RX_MP)
  348. dev->stats.multicast++;
  349. lp->rx_skb[lp->rx_next_done] = skb_new;
  350. }
  351. rd->devcs = 0;
  352. /* Restore descriptor's curr_addr */
  353. if (skb_new)
  354. rd->ca = CPHYSADDR(skb_new->data);
  355. else
  356. rd->ca = CPHYSADDR(skb->data);
  357. rd->control = DMA_COUNT(KORINA_RBSIZE) |
  358. DMA_DESC_COD | DMA_DESC_IOD;
  359. lp->rd_ring[(lp->rx_next_done - 1) &
  360. KORINA_RDS_MASK].control &=
  361. ~DMA_DESC_COD;
  362. lp->rx_next_done = (lp->rx_next_done + 1) & KORINA_RDS_MASK;
  363. dma_cache_wback((u32)rd, sizeof(*rd));
  364. rd = &lp->rd_ring[lp->rx_next_done];
  365. writel(~DMA_STAT_DONE, &lp->rx_dma_regs->dmas);
  366. }
  367. dmas = readl(&lp->rx_dma_regs->dmas);
  368. if (dmas & DMA_STAT_HALT) {
  369. writel(~(DMA_STAT_HALT | DMA_STAT_ERR),
  370. &lp->rx_dma_regs->dmas);
  371. lp->dma_halt_cnt++;
  372. rd->devcs = 0;
  373. skb = lp->rx_skb[lp->rx_next_done];
  374. rd->ca = CPHYSADDR(skb->data);
  375. dma_cache_wback((u32)rd, sizeof(*rd));
  376. korina_chain_rx(lp, rd);
  377. }
  378. return count;
  379. }
  380. static int korina_poll(struct napi_struct *napi, int budget)
  381. {
  382. struct korina_private *lp =
  383. container_of(napi, struct korina_private, napi);
  384. struct net_device *dev = lp->dev;
  385. int work_done;
  386. work_done = korina_rx(dev, budget);
  387. if (work_done < budget) {
  388. napi_complete(napi);
  389. writel(readl(&lp->rx_dma_regs->dmasm) &
  390. ~(DMA_STAT_DONE | DMA_STAT_HALT | DMA_STAT_ERR),
  391. &lp->rx_dma_regs->dmasm);
  392. }
  393. return work_done;
  394. }
  395. /*
  396. * Set or clear the multicast filter for this adaptor.
  397. */
  398. static void korina_multicast_list(struct net_device *dev)
  399. {
  400. struct korina_private *lp = netdev_priv(dev);
  401. unsigned long flags;
  402. struct netdev_hw_addr *ha;
  403. u32 recognise = ETH_ARC_AB; /* always accept broadcasts */
  404. int i;
  405. /* Set promiscuous mode */
  406. if (dev->flags & IFF_PROMISC)
  407. recognise |= ETH_ARC_PRO;
  408. else if ((dev->flags & IFF_ALLMULTI) || (netdev_mc_count(dev) > 4))
  409. /* All multicast and broadcast */
  410. recognise |= ETH_ARC_AM;
  411. /* Build the hash table */
  412. if (netdev_mc_count(dev) > 4) {
  413. u16 hash_table[4];
  414. u32 crc;
  415. for (i = 0; i < 4; i++)
  416. hash_table[i] = 0;
  417. netdev_for_each_mc_addr(ha, dev) {
  418. crc = ether_crc_le(6, ha->addr);
  419. crc >>= 26;
  420. hash_table[crc >> 4] |= 1 << (15 - (crc & 0xf));
  421. }
  422. /* Accept filtered multicast */
  423. recognise |= ETH_ARC_AFM;
  424. /* Fill the MAC hash tables with their values */
  425. writel((u32)(hash_table[1] << 16 | hash_table[0]),
  426. &lp->eth_regs->ethhash0);
  427. writel((u32)(hash_table[3] << 16 | hash_table[2]),
  428. &lp->eth_regs->ethhash1);
  429. }
  430. spin_lock_irqsave(&lp->lock, flags);
  431. writel(recognise, &lp->eth_regs->etharc);
  432. spin_unlock_irqrestore(&lp->lock, flags);
  433. }
  434. static void korina_tx(struct net_device *dev)
  435. {
  436. struct korina_private *lp = netdev_priv(dev);
  437. struct dma_desc *td = &lp->td_ring[lp->tx_next_done];
  438. u32 devcs;
  439. u32 dmas;
  440. spin_lock(&lp->lock);
  441. /* Process all desc that are done */
  442. while (IS_DMA_FINISHED(td->control)) {
  443. if (lp->tx_full == 1) {
  444. netif_wake_queue(dev);
  445. lp->tx_full = 0;
  446. }
  447. devcs = lp->td_ring[lp->tx_next_done].devcs;
  448. if ((devcs & (ETH_TX_FD | ETH_TX_LD)) !=
  449. (ETH_TX_FD | ETH_TX_LD)) {
  450. dev->stats.tx_errors++;
  451. dev->stats.tx_dropped++;
  452. /* Should never happen */
  453. printk(KERN_ERR "%s: split tx ignored\n",
  454. dev->name);
  455. } else if (devcs & ETH_TX_TOK) {
  456. dev->stats.tx_packets++;
  457. dev->stats.tx_bytes +=
  458. lp->tx_skb[lp->tx_next_done]->len;
  459. } else {
  460. dev->stats.tx_errors++;
  461. dev->stats.tx_dropped++;
  462. /* Underflow */
  463. if (devcs & ETH_TX_UND)
  464. dev->stats.tx_fifo_errors++;
  465. /* Oversized frame */
  466. if (devcs & ETH_TX_OF)
  467. dev->stats.tx_aborted_errors++;
  468. /* Excessive deferrals */
  469. if (devcs & ETH_TX_ED)
  470. dev->stats.tx_carrier_errors++;
  471. /* Collisions: medium busy */
  472. if (devcs & ETH_TX_EC)
  473. dev->stats.collisions++;
  474. /* Late collision */
  475. if (devcs & ETH_TX_LC)
  476. dev->stats.tx_window_errors++;
  477. }
  478. /* We must always free the original skb */
  479. if (lp->tx_skb[lp->tx_next_done]) {
  480. dev_kfree_skb_any(lp->tx_skb[lp->tx_next_done]);
  481. lp->tx_skb[lp->tx_next_done] = NULL;
  482. }
  483. lp->td_ring[lp->tx_next_done].control = DMA_DESC_IOF;
  484. lp->td_ring[lp->tx_next_done].devcs = ETH_TX_FD | ETH_TX_LD;
  485. lp->td_ring[lp->tx_next_done].link = 0;
  486. lp->td_ring[lp->tx_next_done].ca = 0;
  487. lp->tx_count--;
  488. /* Go on to next transmission */
  489. lp->tx_next_done = (lp->tx_next_done + 1) & KORINA_TDS_MASK;
  490. td = &lp->td_ring[lp->tx_next_done];
  491. }
  492. /* Clear the DMA status register */
  493. dmas = readl(&lp->tx_dma_regs->dmas);
  494. writel(~dmas, &lp->tx_dma_regs->dmas);
  495. writel(readl(&lp->tx_dma_regs->dmasm) &
  496. ~(DMA_STAT_FINI | DMA_STAT_ERR),
  497. &lp->tx_dma_regs->dmasm);
  498. spin_unlock(&lp->lock);
  499. }
  500. static irqreturn_t
  501. korina_tx_dma_interrupt(int irq, void *dev_id)
  502. {
  503. struct net_device *dev = dev_id;
  504. struct korina_private *lp = netdev_priv(dev);
  505. u32 dmas, dmasm;
  506. irqreturn_t retval;
  507. dmas = readl(&lp->tx_dma_regs->dmas);
  508. if (dmas & (DMA_STAT_FINI | DMA_STAT_ERR)) {
  509. dmasm = readl(&lp->tx_dma_regs->dmasm);
  510. writel(dmasm | (DMA_STAT_FINI | DMA_STAT_ERR),
  511. &lp->tx_dma_regs->dmasm);
  512. korina_tx(dev);
  513. if (lp->tx_chain_status == desc_filled &&
  514. (readl(&(lp->tx_dma_regs->dmandptr)) == 0)) {
  515. writel(CPHYSADDR(&lp->td_ring[lp->tx_chain_head]),
  516. &(lp->tx_dma_regs->dmandptr));
  517. lp->tx_chain_status = desc_empty;
  518. lp->tx_chain_head = lp->tx_chain_tail;
  519. dev->trans_start = jiffies;
  520. }
  521. if (dmas & DMA_STAT_ERR)
  522. printk(KERN_ERR "%s: DMA error\n", dev->name);
  523. retval = IRQ_HANDLED;
  524. } else
  525. retval = IRQ_NONE;
  526. return retval;
  527. }
  528. static void korina_check_media(struct net_device *dev, unsigned int init_media)
  529. {
  530. struct korina_private *lp = netdev_priv(dev);
  531. mii_check_media(&lp->mii_if, 0, init_media);
  532. if (lp->mii_if.full_duplex)
  533. writel(readl(&lp->eth_regs->ethmac2) | ETH_MAC2_FD,
  534. &lp->eth_regs->ethmac2);
  535. else
  536. writel(readl(&lp->eth_regs->ethmac2) & ~ETH_MAC2_FD,
  537. &lp->eth_regs->ethmac2);
  538. }
  539. static void korina_poll_media(unsigned long data)
  540. {
  541. struct net_device *dev = (struct net_device *) data;
  542. struct korina_private *lp = netdev_priv(dev);
  543. korina_check_media(dev, 0);
  544. mod_timer(&lp->media_check_timer, jiffies + HZ);
  545. }
  546. static void korina_set_carrier(struct mii_if_info *mii)
  547. {
  548. if (mii->force_media) {
  549. /* autoneg is off: Link is always assumed to be up */
  550. if (!netif_carrier_ok(mii->dev))
  551. netif_carrier_on(mii->dev);
  552. } else /* Let MMI library update carrier status */
  553. korina_check_media(mii->dev, 0);
  554. }
  555. static int korina_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
  556. {
  557. struct korina_private *lp = netdev_priv(dev);
  558. struct mii_ioctl_data *data = if_mii(rq);
  559. int rc;
  560. if (!netif_running(dev))
  561. return -EINVAL;
  562. spin_lock_irq(&lp->lock);
  563. rc = generic_mii_ioctl(&lp->mii_if, data, cmd, NULL);
  564. spin_unlock_irq(&lp->lock);
  565. korina_set_carrier(&lp->mii_if);
  566. return rc;
  567. }
  568. /* ethtool helpers */
  569. static void netdev_get_drvinfo(struct net_device *dev,
  570. struct ethtool_drvinfo *info)
  571. {
  572. struct korina_private *lp = netdev_priv(dev);
  573. strcpy(info->driver, DRV_NAME);
  574. strcpy(info->version, DRV_VERSION);
  575. strcpy(info->bus_info, lp->dev->name);
  576. }
  577. static int netdev_get_settings(struct net_device *dev, struct ethtool_cmd *cmd)
  578. {
  579. struct korina_private *lp = netdev_priv(dev);
  580. int rc;
  581. spin_lock_irq(&lp->lock);
  582. rc = mii_ethtool_gset(&lp->mii_if, cmd);
  583. spin_unlock_irq(&lp->lock);
  584. return rc;
  585. }
  586. static int netdev_set_settings(struct net_device *dev, struct ethtool_cmd *cmd)
  587. {
  588. struct korina_private *lp = netdev_priv(dev);
  589. int rc;
  590. spin_lock_irq(&lp->lock);
  591. rc = mii_ethtool_sset(&lp->mii_if, cmd);
  592. spin_unlock_irq(&lp->lock);
  593. korina_set_carrier(&lp->mii_if);
  594. return rc;
  595. }
  596. static u32 netdev_get_link(struct net_device *dev)
  597. {
  598. struct korina_private *lp = netdev_priv(dev);
  599. return mii_link_ok(&lp->mii_if);
  600. }
  601. static const struct ethtool_ops netdev_ethtool_ops = {
  602. .get_drvinfo = netdev_get_drvinfo,
  603. .get_settings = netdev_get_settings,
  604. .set_settings = netdev_set_settings,
  605. .get_link = netdev_get_link,
  606. };
  607. static int korina_alloc_ring(struct net_device *dev)
  608. {
  609. struct korina_private *lp = netdev_priv(dev);
  610. struct sk_buff *skb;
  611. int i;
  612. /* Initialize the transmit descriptors */
  613. for (i = 0; i < KORINA_NUM_TDS; i++) {
  614. lp->td_ring[i].control = DMA_DESC_IOF;
  615. lp->td_ring[i].devcs = ETH_TX_FD | ETH_TX_LD;
  616. lp->td_ring[i].ca = 0;
  617. lp->td_ring[i].link = 0;
  618. }
  619. lp->tx_next_done = lp->tx_chain_head = lp->tx_chain_tail =
  620. lp->tx_full = lp->tx_count = 0;
  621. lp->tx_chain_status = desc_empty;
  622. /* Initialize the receive descriptors */
  623. for (i = 0; i < KORINA_NUM_RDS; i++) {
  624. skb = netdev_alloc_skb_ip_align(dev, KORINA_RBSIZE);
  625. if (!skb)
  626. return -ENOMEM;
  627. lp->rx_skb[i] = skb;
  628. lp->rd_ring[i].control = DMA_DESC_IOD |
  629. DMA_COUNT(KORINA_RBSIZE);
  630. lp->rd_ring[i].devcs = 0;
  631. lp->rd_ring[i].ca = CPHYSADDR(skb->data);
  632. lp->rd_ring[i].link = CPHYSADDR(&lp->rd_ring[i+1]);
  633. }
  634. /* loop back receive descriptors, so the last
  635. * descriptor points to the first one */
  636. lp->rd_ring[i - 1].link = CPHYSADDR(&lp->rd_ring[0]);
  637. lp->rd_ring[i - 1].control |= DMA_DESC_COD;
  638. lp->rx_next_done = 0;
  639. lp->rx_chain_head = 0;
  640. lp->rx_chain_tail = 0;
  641. lp->rx_chain_status = desc_empty;
  642. return 0;
  643. }
  644. static void korina_free_ring(struct net_device *dev)
  645. {
  646. struct korina_private *lp = netdev_priv(dev);
  647. int i;
  648. for (i = 0; i < KORINA_NUM_RDS; i++) {
  649. lp->rd_ring[i].control = 0;
  650. if (lp->rx_skb[i])
  651. dev_kfree_skb_any(lp->rx_skb[i]);
  652. lp->rx_skb[i] = NULL;
  653. }
  654. for (i = 0; i < KORINA_NUM_TDS; i++) {
  655. lp->td_ring[i].control = 0;
  656. if (lp->tx_skb[i])
  657. dev_kfree_skb_any(lp->tx_skb[i]);
  658. lp->tx_skb[i] = NULL;
  659. }
  660. }
  661. /*
  662. * Initialize the RC32434 ethernet controller.
  663. */
  664. static int korina_init(struct net_device *dev)
  665. {
  666. struct korina_private *lp = netdev_priv(dev);
  667. /* Disable DMA */
  668. korina_abort_tx(dev);
  669. korina_abort_rx(dev);
  670. /* reset ethernet logic */
  671. writel(0, &lp->eth_regs->ethintfc);
  672. while ((readl(&lp->eth_regs->ethintfc) & ETH_INT_FC_RIP))
  673. dev->trans_start = jiffies;
  674. /* Enable Ethernet Interface */
  675. writel(ETH_INT_FC_EN, &lp->eth_regs->ethintfc);
  676. /* Allocate rings */
  677. if (korina_alloc_ring(dev)) {
  678. printk(KERN_ERR "%s: descriptor allocation failed\n", dev->name);
  679. korina_free_ring(dev);
  680. return -ENOMEM;
  681. }
  682. writel(0, &lp->rx_dma_regs->dmas);
  683. /* Start Rx DMA */
  684. korina_start_rx(lp, &lp->rd_ring[0]);
  685. writel(readl(&lp->tx_dma_regs->dmasm) &
  686. ~(DMA_STAT_FINI | DMA_STAT_ERR),
  687. &lp->tx_dma_regs->dmasm);
  688. writel(readl(&lp->rx_dma_regs->dmasm) &
  689. ~(DMA_STAT_DONE | DMA_STAT_HALT | DMA_STAT_ERR),
  690. &lp->rx_dma_regs->dmasm);
  691. /* Accept only packets destined for this Ethernet device address */
  692. writel(ETH_ARC_AB, &lp->eth_regs->etharc);
  693. /* Set all Ether station address registers to their initial values */
  694. writel(STATION_ADDRESS_LOW(dev), &lp->eth_regs->ethsal0);
  695. writel(STATION_ADDRESS_HIGH(dev), &lp->eth_regs->ethsah0);
  696. writel(STATION_ADDRESS_LOW(dev), &lp->eth_regs->ethsal1);
  697. writel(STATION_ADDRESS_HIGH(dev), &lp->eth_regs->ethsah1);
  698. writel(STATION_ADDRESS_LOW(dev), &lp->eth_regs->ethsal2);
  699. writel(STATION_ADDRESS_HIGH(dev), &lp->eth_regs->ethsah2);
  700. writel(STATION_ADDRESS_LOW(dev), &lp->eth_regs->ethsal3);
  701. writel(STATION_ADDRESS_HIGH(dev), &lp->eth_regs->ethsah3);
  702. /* Frame Length Checking, Pad Enable, CRC Enable, Full Duplex set */
  703. writel(ETH_MAC2_PE | ETH_MAC2_CEN | ETH_MAC2_FD,
  704. &lp->eth_regs->ethmac2);
  705. /* Back to back inter-packet-gap */
  706. writel(0x15, &lp->eth_regs->ethipgt);
  707. /* Non - Back to back inter-packet-gap */
  708. writel(0x12, &lp->eth_regs->ethipgr);
  709. /* Management Clock Prescaler Divisor
  710. * Clock independent setting */
  711. writel(((idt_cpu_freq) / MII_CLOCK + 1) & ~1,
  712. &lp->eth_regs->ethmcp);
  713. /* don't transmit until fifo contains 48b */
  714. writel(48, &lp->eth_regs->ethfifott);
  715. writel(ETH_MAC1_RE, &lp->eth_regs->ethmac1);
  716. napi_enable(&lp->napi);
  717. netif_start_queue(dev);
  718. return 0;
  719. }
  720. /*
  721. * Restart the RC32434 ethernet controller.
  722. */
  723. static void korina_restart_task(struct work_struct *work)
  724. {
  725. struct korina_private *lp = container_of(work,
  726. struct korina_private, restart_task);
  727. struct net_device *dev = lp->dev;
  728. /*
  729. * Disable interrupts
  730. */
  731. disable_irq(lp->rx_irq);
  732. disable_irq(lp->tx_irq);
  733. disable_irq(lp->ovr_irq);
  734. disable_irq(lp->und_irq);
  735. writel(readl(&lp->tx_dma_regs->dmasm) |
  736. DMA_STAT_FINI | DMA_STAT_ERR,
  737. &lp->tx_dma_regs->dmasm);
  738. writel(readl(&lp->rx_dma_regs->dmasm) |
  739. DMA_STAT_DONE | DMA_STAT_HALT | DMA_STAT_ERR,
  740. &lp->rx_dma_regs->dmasm);
  741. korina_free_ring(dev);
  742. napi_disable(&lp->napi);
  743. if (korina_init(dev) < 0) {
  744. printk(KERN_ERR "%s: cannot restart device\n", dev->name);
  745. return;
  746. }
  747. korina_multicast_list(dev);
  748. enable_irq(lp->und_irq);
  749. enable_irq(lp->ovr_irq);
  750. enable_irq(lp->tx_irq);
  751. enable_irq(lp->rx_irq);
  752. }
  753. static void korina_clear_and_restart(struct net_device *dev, u32 value)
  754. {
  755. struct korina_private *lp = netdev_priv(dev);
  756. netif_stop_queue(dev);
  757. writel(value, &lp->eth_regs->ethintfc);
  758. schedule_work(&lp->restart_task);
  759. }
  760. /* Ethernet Tx Underflow interrupt */
  761. static irqreturn_t korina_und_interrupt(int irq, void *dev_id)
  762. {
  763. struct net_device *dev = dev_id;
  764. struct korina_private *lp = netdev_priv(dev);
  765. unsigned int und;
  766. spin_lock(&lp->lock);
  767. und = readl(&lp->eth_regs->ethintfc);
  768. if (und & ETH_INT_FC_UND)
  769. korina_clear_and_restart(dev, und & ~ETH_INT_FC_UND);
  770. spin_unlock(&lp->lock);
  771. return IRQ_HANDLED;
  772. }
  773. static void korina_tx_timeout(struct net_device *dev)
  774. {
  775. struct korina_private *lp = netdev_priv(dev);
  776. schedule_work(&lp->restart_task);
  777. }
  778. /* Ethernet Rx Overflow interrupt */
  779. static irqreturn_t
  780. korina_ovr_interrupt(int irq, void *dev_id)
  781. {
  782. struct net_device *dev = dev_id;
  783. struct korina_private *lp = netdev_priv(dev);
  784. unsigned int ovr;
  785. spin_lock(&lp->lock);
  786. ovr = readl(&lp->eth_regs->ethintfc);
  787. if (ovr & ETH_INT_FC_OVR)
  788. korina_clear_and_restart(dev, ovr & ~ETH_INT_FC_OVR);
  789. spin_unlock(&lp->lock);
  790. return IRQ_HANDLED;
  791. }
  792. #ifdef CONFIG_NET_POLL_CONTROLLER
  793. static void korina_poll_controller(struct net_device *dev)
  794. {
  795. disable_irq(dev->irq);
  796. korina_tx_dma_interrupt(dev->irq, dev);
  797. enable_irq(dev->irq);
  798. }
  799. #endif
  800. static int korina_open(struct net_device *dev)
  801. {
  802. struct korina_private *lp = netdev_priv(dev);
  803. int ret;
  804. /* Initialize */
  805. ret = korina_init(dev);
  806. if (ret < 0) {
  807. printk(KERN_ERR "%s: cannot open device\n", dev->name);
  808. goto out;
  809. }
  810. /* Install the interrupt handler
  811. * that handles the Done Finished
  812. * Ovr and Und Events */
  813. ret = request_irq(lp->rx_irq, korina_rx_dma_interrupt,
  814. IRQF_DISABLED, "Korina ethernet Rx", dev);
  815. if (ret < 0) {
  816. printk(KERN_ERR "%s: unable to get Rx DMA IRQ %d\n",
  817. dev->name, lp->rx_irq);
  818. goto err_release;
  819. }
  820. ret = request_irq(lp->tx_irq, korina_tx_dma_interrupt,
  821. IRQF_DISABLED, "Korina ethernet Tx", dev);
  822. if (ret < 0) {
  823. printk(KERN_ERR "%s: unable to get Tx DMA IRQ %d\n",
  824. dev->name, lp->tx_irq);
  825. goto err_free_rx_irq;
  826. }
  827. /* Install handler for overrun error. */
  828. ret = request_irq(lp->ovr_irq, korina_ovr_interrupt,
  829. IRQF_DISABLED, "Ethernet Overflow", dev);
  830. if (ret < 0) {
  831. printk(KERN_ERR "%s: unable to get OVR IRQ %d\n",
  832. dev->name, lp->ovr_irq);
  833. goto err_free_tx_irq;
  834. }
  835. /* Install handler for underflow error. */
  836. ret = request_irq(lp->und_irq, korina_und_interrupt,
  837. IRQF_DISABLED, "Ethernet Underflow", dev);
  838. if (ret < 0) {
  839. printk(KERN_ERR "%s: unable to get UND IRQ %d\n",
  840. dev->name, lp->und_irq);
  841. goto err_free_ovr_irq;
  842. }
  843. mod_timer(&lp->media_check_timer, jiffies + 1);
  844. out:
  845. return ret;
  846. err_free_ovr_irq:
  847. free_irq(lp->ovr_irq, dev);
  848. err_free_tx_irq:
  849. free_irq(lp->tx_irq, dev);
  850. err_free_rx_irq:
  851. free_irq(lp->rx_irq, dev);
  852. err_release:
  853. korina_free_ring(dev);
  854. goto out;
  855. }
  856. static int korina_close(struct net_device *dev)
  857. {
  858. struct korina_private *lp = netdev_priv(dev);
  859. u32 tmp;
  860. del_timer(&lp->media_check_timer);
  861. /* Disable interrupts */
  862. disable_irq(lp->rx_irq);
  863. disable_irq(lp->tx_irq);
  864. disable_irq(lp->ovr_irq);
  865. disable_irq(lp->und_irq);
  866. korina_abort_tx(dev);
  867. tmp = readl(&lp->tx_dma_regs->dmasm);
  868. tmp = tmp | DMA_STAT_FINI | DMA_STAT_ERR;
  869. writel(tmp, &lp->tx_dma_regs->dmasm);
  870. korina_abort_rx(dev);
  871. tmp = readl(&lp->rx_dma_regs->dmasm);
  872. tmp = tmp | DMA_STAT_DONE | DMA_STAT_HALT | DMA_STAT_ERR;
  873. writel(tmp, &lp->rx_dma_regs->dmasm);
  874. korina_free_ring(dev);
  875. napi_disable(&lp->napi);
  876. cancel_work_sync(&lp->restart_task);
  877. free_irq(lp->rx_irq, dev);
  878. free_irq(lp->tx_irq, dev);
  879. free_irq(lp->ovr_irq, dev);
  880. free_irq(lp->und_irq, dev);
  881. return 0;
  882. }
  883. static const struct net_device_ops korina_netdev_ops = {
  884. .ndo_open = korina_open,
  885. .ndo_stop = korina_close,
  886. .ndo_start_xmit = korina_send_packet,
  887. .ndo_set_rx_mode = korina_multicast_list,
  888. .ndo_tx_timeout = korina_tx_timeout,
  889. .ndo_do_ioctl = korina_ioctl,
  890. .ndo_change_mtu = eth_change_mtu,
  891. .ndo_validate_addr = eth_validate_addr,
  892. .ndo_set_mac_address = eth_mac_addr,
  893. #ifdef CONFIG_NET_POLL_CONTROLLER
  894. .ndo_poll_controller = korina_poll_controller,
  895. #endif
  896. };
  897. static int korina_probe(struct platform_device *pdev)
  898. {
  899. struct korina_device *bif = platform_get_drvdata(pdev);
  900. struct korina_private *lp;
  901. struct net_device *dev;
  902. struct resource *r;
  903. int rc;
  904. dev = alloc_etherdev(sizeof(struct korina_private));
  905. if (!dev)
  906. return -ENOMEM;
  907. SET_NETDEV_DEV(dev, &pdev->dev);
  908. lp = netdev_priv(dev);
  909. bif->dev = dev;
  910. memcpy(dev->dev_addr, bif->mac, 6);
  911. lp->rx_irq = platform_get_irq_byname(pdev, "korina_rx");
  912. lp->tx_irq = platform_get_irq_byname(pdev, "korina_tx");
  913. lp->ovr_irq = platform_get_irq_byname(pdev, "korina_ovr");
  914. lp->und_irq = platform_get_irq_byname(pdev, "korina_und");
  915. r = platform_get_resource_byname(pdev, IORESOURCE_MEM, "korina_regs");
  916. dev->base_addr = r->start;
  917. lp->eth_regs = ioremap_nocache(r->start, resource_size(r));
  918. if (!lp->eth_regs) {
  919. printk(KERN_ERR DRV_NAME ": cannot remap registers\n");
  920. rc = -ENXIO;
  921. goto probe_err_out;
  922. }
  923. r = platform_get_resource_byname(pdev, IORESOURCE_MEM, "korina_dma_rx");
  924. lp->rx_dma_regs = ioremap_nocache(r->start, resource_size(r));
  925. if (!lp->rx_dma_regs) {
  926. printk(KERN_ERR DRV_NAME ": cannot remap Rx DMA registers\n");
  927. rc = -ENXIO;
  928. goto probe_err_dma_rx;
  929. }
  930. r = platform_get_resource_byname(pdev, IORESOURCE_MEM, "korina_dma_tx");
  931. lp->tx_dma_regs = ioremap_nocache(r->start, resource_size(r));
  932. if (!lp->tx_dma_regs) {
  933. printk(KERN_ERR DRV_NAME ": cannot remap Tx DMA registers\n");
  934. rc = -ENXIO;
  935. goto probe_err_dma_tx;
  936. }
  937. lp->td_ring = kmalloc(TD_RING_SIZE + RD_RING_SIZE, GFP_KERNEL);
  938. if (!lp->td_ring) {
  939. rc = -ENXIO;
  940. goto probe_err_td_ring;
  941. }
  942. dma_cache_inv((unsigned long)(lp->td_ring),
  943. TD_RING_SIZE + RD_RING_SIZE);
  944. /* now convert TD_RING pointer to KSEG1 */
  945. lp->td_ring = (struct dma_desc *)KSEG1ADDR(lp->td_ring);
  946. lp->rd_ring = &lp->td_ring[KORINA_NUM_TDS];
  947. spin_lock_init(&lp->lock);
  948. /* just use the rx dma irq */
  949. dev->irq = lp->rx_irq;
  950. lp->dev = dev;
  951. dev->netdev_ops = &korina_netdev_ops;
  952. dev->ethtool_ops = &netdev_ethtool_ops;
  953. dev->watchdog_timeo = TX_TIMEOUT;
  954. netif_napi_add(dev, &lp->napi, korina_poll, 64);
  955. lp->phy_addr = (((lp->rx_irq == 0x2c? 1:0) << 8) | 0x05);
  956. lp->mii_if.dev = dev;
  957. lp->mii_if.mdio_read = mdio_read;
  958. lp->mii_if.mdio_write = mdio_write;
  959. lp->mii_if.phy_id = lp->phy_addr;
  960. lp->mii_if.phy_id_mask = 0x1f;
  961. lp->mii_if.reg_num_mask = 0x1f;
  962. rc = register_netdev(dev);
  963. if (rc < 0) {
  964. printk(KERN_ERR DRV_NAME
  965. ": cannot register net device: %d\n", rc);
  966. goto probe_err_register;
  967. }
  968. setup_timer(&lp->media_check_timer, korina_poll_media, (unsigned long) dev);
  969. INIT_WORK(&lp->restart_task, korina_restart_task);
  970. printk(KERN_INFO "%s: " DRV_NAME "-" DRV_VERSION " " DRV_RELDATE "\n",
  971. dev->name);
  972. out:
  973. return rc;
  974. probe_err_register:
  975. kfree(lp->td_ring);
  976. probe_err_td_ring:
  977. iounmap(lp->tx_dma_regs);
  978. probe_err_dma_tx:
  979. iounmap(lp->rx_dma_regs);
  980. probe_err_dma_rx:
  981. iounmap(lp->eth_regs);
  982. probe_err_out:
  983. free_netdev(dev);
  984. goto out;
  985. }
  986. static int korina_remove(struct platform_device *pdev)
  987. {
  988. struct korina_device *bif = platform_get_drvdata(pdev);
  989. struct korina_private *lp = netdev_priv(bif->dev);
  990. iounmap(lp->eth_regs);
  991. iounmap(lp->rx_dma_regs);
  992. iounmap(lp->tx_dma_regs);
  993. platform_set_drvdata(pdev, NULL);
  994. unregister_netdev(bif->dev);
  995. free_netdev(bif->dev);
  996. return 0;
  997. }
  998. static struct platform_driver korina_driver = {
  999. .driver.name = "korina",
  1000. .probe = korina_probe,
  1001. .remove = korina_remove,
  1002. };
  1003. module_platform_driver(korina_driver);
  1004. MODULE_AUTHOR("Philip Rischel <rischelp@idt.com>");
  1005. MODULE_AUTHOR("Felix Fietkau <nbd@openwrt.org>");
  1006. MODULE_AUTHOR("Florian Fainelli <florian@openwrt.org>");
  1007. MODULE_DESCRIPTION("IDT RC32434 (Korina) Ethernet driver");
  1008. MODULE_LICENSE("GPL");