korina.c 32 KB

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