fec.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635
  1. /*
  2. * fec.c
  3. *
  4. * Created on: 2019-8-30
  5. * Author: sunxi
  6. */
  7. //sunxi 20220411: 暂时屏蔽
  8. //#ifndef __LIGHT_DIFF_ACT_PRO__
  9. //#define __LIGHT_DIFF_ACT_PRO__
  10. //#endif
  11. #ifndef __SAVE_TO_BUFF_FOR_READ__
  12. #define __SAVE_TO_BUFF_FOR_READ__
  13. #endif
  14. #ifdef __LIGHT_DIFF_ACT_PRO__ // sunxi 20190904 光差保护
  15. #include <linux/kernel.h>
  16. #include <linux/interrupt.h>
  17. #include <linux/netdevice.h>
  18. #include <linux/etherdevice.h>
  19. #include <asm/cacheflush.h>
  20. #include <my_include/fec.h>
  21. #include <my_include/fec_ring.h>
  22. #include "rt.h"
  23. #include "bsp.h"
  24. #include "fec.h"
  25. #ifdef __SAVE_TO_BUFF_FOR_READ__ // 由采样中断读取读取临时缓冲区的数据,因为使用了 memcpy 拷贝了两次数据,效率会低一些
  26. #define FEC_LP_TXBUF_CNT 256 // 发送缓冲区数量最大值
  27. static unsigned char fec2_lp_txbuf[FEC_LP_TXBUF_CNT][FEC_LP_BUF_MAX];
  28. #if 0 // sunxi 20191015
  29. unsigned char fec2_lp_rx_head = 0;
  30. unsigned char fec2_lp_rx_tail = 0;
  31. struct fec_lp_rx_buf fec2_lp_rxbuf[FEC_LP_BUF_CNT_MAX];
  32. #else // sunxi 20191015
  33. struct fec_lp_rx_buf fec2_lp_rxbuf;
  34. unsigned int fec2_lp_rx_cnt = 0;
  35. #endif
  36. #endif // __SAVE_TO_BUFF_FOR_READ__
  37. #define POLL_FRAME 0x50 //巡检报文
  38. #define SAMP_FRAME 0xA0 //采样报文
  39. #define POLL_FRAME_WORD (12+4*9) //轮巡帧6个字,12字节
  40. #define SAMP_FRAME_WORD 32 //采样帧16个字,32字节
  41. /* Interrupt events/masks.
  42. */
  43. #define FEC_ENET_HBERR ((uint)0x80000000) /* Heartbeat error */
  44. #define FEC_ENET_BABR ((uint)0x40000000) /* Babbling receiver */
  45. #define FEC_ENET_BABT ((uint)0x20000000) /* Babbling transmitter */
  46. #define FEC_ENET_GRA ((uint)0x10000000) /* Graceful stop complete */
  47. #define FEC_ENET_TXF ((uint)0x08000000) /* Full frame transmitted */
  48. #define FEC_ENET_TXB ((uint)0x04000000) /* A buffer was transmitted */
  49. #define FEC_ENET_RXF ((uint)0x02000000) /* Full frame received */
  50. #define FEC_ENET_RXB ((uint)0x01000000) /* A buffer was received */
  51. #define FEC_ENET_MII ((uint)0x00800000) /* MII interrupt */
  52. #define FEC_ENET_EBERR ((uint)0x00400000) /* SDMA bus error */
  53. #define FEC_ENET_TS_AVAIL ((uint)0x00010000)
  54. #define FEC_ENET_TS_TIMER ((uint)0x00008000)
  55. static struct net_device *g_fec2_netdev = NULL;
  56. struct sk_buff g_fec2_skb[FEC_LP_TXBUF_CNT];
  57. #ifdef __FEC2_LDAP_TEST__
  58. #define TEST_BUF_MAX 64
  59. static unsigned char g_test_buf[TEST_BUF_MAX] = {0x00};
  60. static unsigned long g_fec2_us1, g_fec2_us2, g_fec2_us3;
  61. #endif // __FEC2_LDAP_TEST__
  62. static int fec2_lp_enet_start_xmit(struct sk_buff *skb, struct net_device *dev)
  63. {
  64. struct fec_enet_private *fep;
  65. volatile fec_t *fecp;
  66. volatile cbd_t *bdp, *bdp_tmp;
  67. unsigned short status;
  68. fep = netdev_priv(dev);
  69. fecp = (volatile fec_t *)dev->base_addr;
  70. if (!fep->link) {
  71. /* Link is down or autonegotiation is in progress. */
  72. return 1;
  73. }
  74. /* Fill in a Tx ring entry */
  75. bdp = fep->cur_tx;
  76. status = bdp->cbd_sc;
  77. #ifndef final_version
  78. if (status & BD_ENET_TX_READY) {
  79. /* Ooops. All transmit buffers are full. Bail out.
  80. * This should not happen, since dev->tbusy should be set.
  81. */
  82. // sunxi 20190814 printk(KERN_ERR "%s: tx queue full!.\n", dev->name);
  83. return 1;
  84. }
  85. #endif
  86. /* Clear all of the status flags.
  87. */
  88. status &= ~BD_ENET_TX_STATS;
  89. /* Set buffer length and buffer pointer.
  90. */
  91. bdp->cbd_bufaddr = __pa(skb->data);
  92. bdp->cbd_datlen = skb->len;
  93. /*
  94. * On some FEC implementations data must be aligned on
  95. * 4-byte boundaries. Use bounce buffers to copy data
  96. * and get it aligned. Ugh.
  97. */
  98. /*if (bdp->cbd_bufaddr & 0x3) {
  99. unsigned int index1;
  100. index1 = bdp - fep->tx_bd_base;
  101. memcpy(fep->tx_bounce[index1],
  102. (void *)skb->data, bdp->cbd_datlen);
  103. bdp->cbd_bufaddr = __pa(fep->tx_bounce[index1]);
  104. } */
  105. dev->stats.tx_bytes += skb->len;
  106. /* Push the data cache so the CPM does not get stale memory
  107. * data.
  108. */
  109. flush_dcache_range((unsigned long)skb->data,
  110. (unsigned long)skb->data + skb->len);
  111. /* Send it on its way. Tell FEC it's ready, interrupt when done,
  112. * it's the last BD of the frame, and to put the CRC on the end.
  113. */
  114. status |= (BD_ENET_TX_READY | BD_ENET_TX_INTR
  115. | BD_ENET_TX_LAST | BD_ENET_TX_TC);
  116. bdp->cbd_sc = status;
  117. dev->trans_start = jiffies;
  118. /* Trigger transmission start */
  119. fecp->fec_x_des_active = 0;
  120. /* If this was the last BD in the ring, start at the beginning again.
  121. */
  122. if (status & BD_ENET_TX_WRAP)
  123. bdp = fep->tx_bd_base;
  124. else
  125. bdp++;
  126. if (bdp == fep->dirty_tx) {
  127. fep->tx_full = 1;
  128. // sunxi 20200812 由于缓冲区满了后会调用该函数,导致后面调用 netif_wake_queue函数时导致内核出错,因此进行屏蔽,满了的缓冲区丢弃掉最前面一帧数据 netif_stop_queue(dev);
  129. // sunxi 20200812 added
  130. bdp_tmp = bdp;
  131. bdp_tmp ++;
  132. fep->dirty_tx = (cbd_t *)bdp_tmp;
  133. }
  134. fep->cur_tx = (cbd_t *)bdp;
  135. #ifdef __FEC2_LDAP_TEST__
  136. g_fec2_us2 = ustimer_get_origin();
  137. #endif // __FEC2_LDAP_TEST__
  138. return 0;
  139. }
  140. int fec2_lp_start_xmit(unsigned char *data, int len)
  141. {
  142. struct sk_buff *skb;
  143. static unsigned char skb_index = 0;
  144. unsigned long flags;
  145. if((g_fec2_netdev == NULL) || (data == NULL) || (len <= 0) || (len > FEC_LP_BUF_MAX))
  146. return 0;
  147. rt_irq_save(flags);
  148. skb = &g_fec2_skb[skb_index];
  149. skb->data = fec2_lp_txbuf[skb_index];
  150. //拷贝用户数据到skb->data
  151. memcpy(skb->data, data, len);
  152. //指定长度
  153. skb->len = len;
  154. skb_index ++;
  155. if(fec2_lp_enet_start_xmit(skb, g_fec2_netdev))
  156. len = 0;
  157. rt_irq_restore(flags);
  158. return len;
  159. }
  160. static void fec2_enet_tx(struct net_device *dev)
  161. {
  162. struct fec_enet_private *fep;
  163. volatile cbd_t *bdp;
  164. unsigned short status;
  165. unsigned long flags;
  166. fep = netdev_priv(dev);
  167. // sunxi 20191015 spin_lock_irqsave(&fep->hw_lock, flags);
  168. rt_irq_save(flags);
  169. bdp = fep->dirty_tx;
  170. #ifdef __FEC2_LDAP_TEST__
  171. g_fec2_us3 = ustimer_get_origin();
  172. #endif // __FEC2_LDAP_TEST__
  173. while (((status = bdp->cbd_sc) & BD_ENET_TX_READY) == 0) {
  174. if (bdp == fep->cur_tx && fep->tx_full == 0)
  175. break;
  176. /* Check for errors. */
  177. if (status & (BD_ENET_TX_HB | BD_ENET_TX_LC |
  178. BD_ENET_TX_RL | BD_ENET_TX_UN |
  179. BD_ENET_TX_CSL)) {
  180. dev->stats.tx_errors++;
  181. if (status & BD_ENET_TX_HB) /* No heartbeat */
  182. dev->stats.tx_heartbeat_errors++;
  183. if (status & BD_ENET_TX_LC) /* Late collision */
  184. dev->stats.tx_window_errors++;
  185. if (status & BD_ENET_TX_RL) /* Retrans limit */
  186. dev->stats.tx_aborted_errors++;
  187. if (status & BD_ENET_TX_UN) /* Underrun */
  188. dev->stats.tx_fifo_errors++;
  189. if (status & BD_ENET_TX_CSL) /* Carrier lost */
  190. dev->stats.tx_carrier_errors++;
  191. } else {
  192. dev->stats.tx_packets++;
  193. }
  194. #ifndef final_version
  195. if (status & BD_ENET_TX_READY)
  196. printk(KERN_ERR "HEY! "
  197. "Enet xmit interrupt and TX_READY.\n");
  198. #endif
  199. /* Deferred means some collisions occurred during transmit,
  200. * but we eventually sent the packet OK.
  201. */
  202. if (status & BD_ENET_TX_DEF)
  203. dev->stats.collisions++;
  204. /* Update pointer to next buffer descriptor to be transmitted.
  205. */
  206. if (status & BD_ENET_TX_WRAP)
  207. bdp = fep->tx_bd_base;
  208. else
  209. bdp++;
  210. /* Since we have freed up a buffer, the ring is no longer
  211. * full.
  212. * sunxi 20200812 前面发送接口判断如果缓冲区满了,进行数据丢弃,因此不会出现以下情况,不会导致调用以下函数导致内核出错
  213. */
  214. if (fep->tx_full) {
  215. fep->tx_full = 0;
  216. // sunxi 20200812 if (netif_queue_stopped(dev))
  217. // sunxi 20200812 netif_wake_queue(dev);
  218. }
  219. }
  220. fep->dirty_tx = (cbd_t *)bdp;
  221. #ifdef __FEC2_LDAP_TEST__
  222. rt_printf("us1 = %lu, us2 = %lu, us3 = %lu\n", g_fec2_us1, g_fec2_us2, g_fec2_us3);
  223. g_fec2_us1 = 0;
  224. g_fec2_us2 = 0;
  225. g_fec2_us3 = 0;
  226. #endif // __FEC2_LDAP_TEST__
  227. // sunxi 20191015 spin_unlock_irqrestore(&fep->hw_lock, flags);
  228. rt_irq_restore(flags);
  229. }
  230. extern void fec2_lp_frame_handle(unsigned char *data, bool bGoodPacket,int errtype);
  231. static void fec2_enet_rx(struct net_device *dev)
  232. {
  233. struct fec_enet_private *fep;
  234. volatile fec_t *fecp;
  235. volatile cbd_t *bdp;
  236. unsigned short status;
  237. int errtype=0;
  238. #if 0
  239. struct sk_buff *skb;
  240. #endif
  241. ushort pkt_len;
  242. __u8 *data;
  243. unsigned long flags;
  244. int frame_count;
  245. ushort i, wRecvCnt;
  246. ushort wCRC=0;
  247. ushort ucrc;
  248. u8 *rdptr = 0;
  249. bool bGoodPacket = false;
  250. fep = netdev_priv(dev);
  251. fecp = (volatile fec_t *)dev->base_addr;
  252. // sunxi 20190920 spin_lock_irqsave(&fep->hw_lock, flags);
  253. rt_irq_save(flags);
  254. /* First, grab all of the stats for the incoming packet.
  255. * These get messed up if we get called due to a busy condition.
  256. */
  257. bdp = fep->cur_rx;
  258. frame_count = 0;
  259. while (!((status = bdp->cbd_sc) & BD_ENET_RX_EMPTY)) {
  260. #if 1 //xbtong 目前流量控制好像不起作用,但在MCF54452上经测试是可以起作用的。
  261. //流控制,防止广播风暴
  262. frame_count++;
  263. if(frame_count > 2)
  264. {
  265. // opd寄存器存放发送给对方的PAUSE时间,以slot time(512 bit times ,5.12us) 为单位
  266. // printk("rx(%d):%d\n", fep->index, frame_count);
  267. // fecp->fec_r_fifo_section_empty = 0;
  268. // fecp->fec_opd = 0xfff0;
  269. // sunxi 20190731 fecp->fec_opd = 0x400;
  270. fecp->fec_opd = 0x80;
  271. fecp->fec_x_cntrl |= 0x0008;
  272. }
  273. #endif
  274. #ifndef final_version
  275. /* Since we have allocated space to hold a complete frame,
  276. * the last indicator should be set.
  277. */
  278. if ((status & BD_ENET_RX_LAST) == 0){
  279. printk(KERN_INFO "FEC ENET: rcv is not +last\n");
  280. //非法数据长度处理
  281. if(bdp->cbd_datlen > FEC_ENET_RX_FRSIZE )
  282. goto rx_processing_done;
  283. }
  284. #endif
  285. if (!fep->opened)
  286. goto rx_processing_done;
  287. /* Check for errors. */
  288. if (status & (BD_ENET_RX_LG | BD_ENET_RX_SH | BD_ENET_RX_NO |
  289. BD_ENET_RX_CR | BD_ENET_RX_OV)) {
  290. dev->stats.rx_errors++;
  291. if (status & (BD_ENET_RX_LG | BD_ENET_RX_SH)) {
  292. /* Frame too long or too short. */
  293. dev->stats.rx_length_errors++;
  294. }
  295. if (status & BD_ENET_RX_NO) /* Frame alignment */
  296. dev->stats.rx_frame_errors++;
  297. if (status & BD_ENET_RX_CR) /* CRC Error */
  298. dev->stats.rx_crc_errors++;
  299. if (status & BD_ENET_RX_OV) /* FIFO overrun */
  300. dev->stats.rx_fifo_errors++;
  301. }
  302. /* Report late collisions as a frame error.
  303. * On this error, the BD is closed, but we don't know what we
  304. * have in the buffer. So, just drop this frame on the floor.
  305. */
  306. if (status & BD_ENET_RX_CL) {
  307. dev->stats.rx_errors++;
  308. dev->stats.rx_frame_errors++;
  309. goto rx_processing_done;
  310. }
  311. /* Process the incoming frame.
  312. */
  313. dev->stats.rx_packets++;
  314. pkt_len = bdp->cbd_datlen;
  315. dev->stats.rx_bytes += pkt_len;
  316. data = (__u8 *)__va(bdp->cbd_bufaddr);
  317. data+=12;
  318. // 以下为光差保护数据接收处理
  319. /* 1. 光纤保护的数据帧,根据ut的协议帧,不是以太网数据帧格式(6字节目标mac地址,接着6字节源mac地址,再两字节帧类型,然后就是帧数据)
  320. * 2. 光纤保护的数据帧:两字节帧类型,0x5000是轮询帧,中间8字节的帧数据,最后加上两字节wCRC,一共10字节,
  321. * 3. 0xA000是采样帧,中间26字节的帧数据,最后加上两字节wCRC,一共是28字节。
  322. * 4. wCRC 是包括两个字节的帧类型和帧数据的异或
  323. */
  324. rdptr = (u8 *)data;
  325. switch( data[0] & 0xF0 )
  326. {
  327. case POLL_FRAME: //轮巡帧
  328. wRecvCnt = POLL_FRAME_WORD;
  329. break;
  330. case SAMP_FRAME: //采样帧
  331. wRecvCnt = SAMP_FRAME_WORD;
  332. break;
  333. default:
  334. wRecvCnt = 0;
  335. break;
  336. }
  337. if( wRecvCnt )
  338. {
  339. rdptr = (u8 *)data;
  340. for( i = 0; i < wRecvCnt-2; i++ )
  341. {
  342. wCRC += *rdptr++;
  343. }
  344. ucrc=(ushort )rdptr[0]|(rdptr[1]<<8);
  345. if( wCRC == ucrc ) //效验成功
  346. {
  347. bGoodPacket = true;
  348. }
  349. else
  350. {
  351. errtype=1;
  352. }
  353. }
  354. else
  355. {
  356. memset(data, 0x00, (SAMP_FRAME_WORD ));
  357. wRecvCnt = 0;
  358. errtype=2;
  359. }
  360. #ifdef __SAVE_TO_BUFF_FOR_READ__ // 保存在临时缓冲区,由采样中断读取,因为使用了 memcpy 拷贝了两次数据,效率会低一些
  361. // 把正确的数据保存到缓冲区
  362. #if 0 // sunxi 20191015
  363. fec2_lp_rx_head=0; //为保证采样数据的实效性,只处理一帧数据,不做缓存
  364. fec2_lp_rxbuf[fec2_lp_rx_head].bvalid = bGoodPacket;
  365. fec2_lp_rxbuf[fec2_lp_rx_head].len = wRecvCnt;
  366. if(wRecvCnt > 0)
  367. memcpy(fec2_lp_rxbuf[fec2_lp_rx_head].buf, data, wRecvCnt);
  368. fec2_lp_rx_head ++;
  369. if(fec2_lp_rx_head == fec2_lp_rx_tail)
  370. fec2_lp_rx_tail ++;
  371. #else // sunxi 20191015
  372. fec2_lp_rx_cnt = 0;
  373. fec2_lp_rxbuf.bvalid = bGoodPacket;
  374. fec2_lp_rxbuf.len = wRecvCnt;
  375. if(wRecvCnt > 0)
  376. memcpy(fec2_lp_rxbuf.buf, data, wRecvCnt);
  377. fec2_lp_rx_cnt = 1;
  378. #endif // sunxi 20191015
  379. // 数据直接网口2接收中断里面进行处理,调用app那边的接口,效率比较高
  380. fec2_lp_frame_handle(data, bGoodPacket,errtype); //接收报文处理
  381. #ifdef __FEC2_LDAP_TEST__
  382. for(i = 0; i < 256; i ++)
  383. data[i] = i;
  384. g_fec2_us1 = ustimer_get_origin();
  385. fec2_lp_start_xmit(g_test_buf, TEST_BUF_MAX);
  386. #endif // __FEC2_LDAP_TEST__
  387. #endif // __SAVE_TO_BUFF_FOR_READ__
  388. rx_processing_done:
  389. /* Clear the status flags for this buffer.
  390. */
  391. status &= ~BD_ENET_RX_STATS;
  392. /* Mark the buffer empty.
  393. */
  394. status |= BD_ENET_RX_EMPTY;
  395. bdp->cbd_sc = status;
  396. /* Update BD pointer to next entry.
  397. */
  398. if (status & BD_ENET_RX_WRAP)
  399. bdp = fep->rx_bd_base;
  400. else
  401. bdp++;
  402. /* Doing this here will keep the FEC running while we process
  403. * incoming frames. On a heavily loaded network, we should be
  404. * able to keep up at the expense of system resources.
  405. */
  406. fecp->fec_r_des_active = 0;
  407. } /* while (!((status = bdp->cbd_sc) & BD_ENET_RX_EMPTY)) */
  408. fep->cur_rx = (cbd_t *)bdp;
  409. // sunxi 20190920 spin_unlock_irqrestore(&fep->hw_lock, flags);
  410. rt_irq_restore(flags);
  411. }
  412. /* The interrupt handler.
  413. * This is called from the MPC core interrupt.
  414. */
  415. static void fec2_enet_interrupt(void)
  416. {
  417. struct net_device *dev = g_fec2_netdev;
  418. volatile fec_t *fecp;
  419. uint int_events;
  420. if(dev == NULL) // sunxi 20200811 added
  421. return;
  422. fecp = (volatile fec_t *)dev->base_addr;
  423. /* Get the interrupt events that caused us to be here.
  424. */
  425. do {
  426. int_events = fecp->fec_ievent;
  427. fecp->fec_ievent = int_events; // & (FEC_ENET_GRA | FEC_ENET_TXF | FEC_ENET_RXF | FEC_ENET_TXB | FEC_ENET_RXB);
  428. /* Handle receive event in its own function.
  429. */
  430. if (int_events & FEC_ENET_RXF) {
  431. fec2_enet_rx(dev);
  432. }
  433. /* Transmit OK, or non-fatal error. Update the buffer
  434. descriptors. FEC handles all errors, we just discover
  435. them as part of the transmit process.
  436. */
  437. if (int_events & FEC_ENET_TXF) {
  438. fec2_enet_tx(dev);
  439. }
  440. } while (int_events);
  441. }
  442. // sunxi 20191217 增加以下4个接口,当模块在手动卸载后,不会出现网口看门狗动作出现的网口2重启的内核出错信息,也不会在手动关闭和打开网口2时出现内核出错信息。
  443. static int fec2_enet_start_xmit(struct sk_buff *skb, struct net_device *dev)
  444. {
  445. return 0;
  446. }
  447. static void fec2_timeout(struct net_device *dev)
  448. {
  449. }
  450. static int fec2_enet_open(struct net_device *dev)
  451. {
  452. return 0;
  453. }
  454. static int fec2_enet_close(struct net_device *dev)
  455. {
  456. return 0;
  457. }
  458. extern struct net_device *fec_get_net_device(int idx);
  459. static const int fec_idx = 1; // sunxi 20200722 增加该变量,使用光纤通信可以不止是网口2,也可以是网口1,但是应用那边也需要对应改动。最好在调用fec2_reinit接口时可以把索引号传进来。
  460. int fec2_reinit(void)
  461. {
  462. #ifdef __FEC2_LDAP_TEST__
  463. int i;
  464. #endif // __FEC2_LDAP_TEST__
  465. g_fec2_netdev = fec_get_net_device(fec_idx);
  466. if(g_fec2_netdev == NULL)
  467. {
  468. return 0;
  469. }
  470. #ifdef __FEC2_LDAP_TEST__
  471. for(i = 0; i < TEST_BUF_MAX; i ++ )
  472. g_test_buf[i] = i;
  473. #endif // __FEC2_LDAP_TEST__
  474. if(g_fec2_netdev->stop != fec2_enet_close)
  475. {
  476. g_fec2_netdev->stop(g_fec2_netdev);
  477. g_fec2_netdev->stop = fec2_enet_close;
  478. // 重新定位新的网口2中断处理函数
  479. if(fec_idx == 1)
  480. {
  481. //free_irq(113, (void *)g_fec2_netdev);
  482. //free_irq(117, (void *)g_fec2_netdev);
  483. }
  484. else if(!fec_idx)
  485. {
  486. //free_irq(100, (void *)g_fec2_netdev);
  487. //free_irq(104, (void *)g_fec2_netdev);
  488. }
  489. }
  490. // 防止网口2的网络数据在其它地方来发送
  491. if(g_fec2_netdev->hard_start_xmit != fec2_enet_start_xmit)
  492. {
  493. g_fec2_netdev->hard_start_xmit = fec2_enet_start_xmit;
  494. g_fec2_netdev->tx_timeout = fec2_timeout;
  495. }
  496. if(fec_idx == 1)
  497. {
  498. rt_request_irq(113, 6, fec2_enet_interrupt, "fec2(TXF)");
  499. rt_request_irq(117, 6, fec2_enet_interrupt, "fec2(RXF)");
  500. }
  501. else if(!fec_idx)
  502. {
  503. rt_request_irq(100, 6, fec2_enet_interrupt, "fec1(TXF)");
  504. rt_request_irq(104, 6, fec2_enet_interrupt, "fec1(RXF)");
  505. }
  506. if(g_fec2_netdev->open != fec2_enet_open)
  507. {
  508. g_fec2_netdev->open(g_fec2_netdev);
  509. g_fec2_netdev->open = fec2_enet_open;
  510. }
  511. return 0;
  512. }
  513. int fec2_exit(void)
  514. {
  515. if(g_fec2_netdev == NULL)
  516. {
  517. return 0;
  518. }
  519. msleep(10); // 让有足够时间把数据都发送出去了再释放实时中断,不然会触发数据发送的看门狗动作。
  520. if(fec_idx == 1)
  521. {
  522. rt_free_irq(117);
  523. rt_free_irq(113);
  524. }
  525. else if(!fec_idx)
  526. {
  527. rt_free_irq(104);
  528. rt_free_irq(100);
  529. }
  530. return 0;
  531. }
  532. #endif // __LIGHT_DIFF_ACT_PRO__