fec.c 18 KB

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