ifxmips_ptm_adsl.c 50 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569
  1. /******************************************************************************
  2. **
  3. ** FILE NAME : ifxmips_ptm_adsl.c
  4. ** PROJECT : UEIP
  5. ** MODULES : PTM
  6. **
  7. ** DATE : 7 Jul 2009
  8. ** AUTHOR : Xu Liang
  9. ** DESCRIPTION : PTM driver common source file (core functions for Danube/
  10. ** Amazon-SE/AR9)
  11. ** COPYRIGHT : Copyright (c) 2006
  12. ** Infineon Technologies AG
  13. ** Am Campeon 1-12, 85579 Neubiberg, Germany
  14. **
  15. ** This program is free software; you can redistribute it and/or modify
  16. ** it under the terms of the GNU General Public License as published by
  17. ** the Free Software Foundation; either version 2 of the License, or
  18. ** (at your option) any later version.
  19. **
  20. ** HISTORY
  21. ** $Date $Author $Comment
  22. ** 07 JUL 2009 Xu Liang Init Version
  23. *******************************************************************************/
  24. /*
  25. * ####################################
  26. * Head File
  27. * ####################################
  28. */
  29. /*
  30. * Common Head File
  31. */
  32. #include <linux/version.h>
  33. #include <linux/kernel.h>
  34. #include <linux/module.h>
  35. #include <linux/types.h>
  36. #include <linux/errno.h>
  37. #include <linux/proc_fs.h>
  38. #include <linux/init.h>
  39. #include <linux/ioctl.h>
  40. #include <linux/etherdevice.h>
  41. #include <linux/interrupt.h>
  42. #include <linux/netdevice.h>
  43. #include <asm/io.h>
  44. /*
  45. * Chip Specific Head File
  46. */
  47. #include "ifxmips_ptm_adsl.h"
  48. #include <lantiq_soc.h>
  49. /*
  50. * ####################################
  51. * Kernel Version Adaption
  52. * ####################################
  53. */
  54. #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,11)
  55. #define MODULE_PARM_ARRAY(a, b) module_param_array(a, int, NULL, 0)
  56. #define MODULE_PARM(a, b) module_param(a, int, 0)
  57. #else
  58. #define MODULE_PARM_ARRAY(a, b) MODULE_PARM(a, b)
  59. #endif
  60. /*
  61. * ####################################
  62. * Parameters to Configure PPE
  63. * ####################################
  64. */
  65. static int write_desc_delay = 0x20; /* Write descriptor delay */
  66. static int rx_max_packet_size = ETH_MAX_FRAME_LENGTH;
  67. /* Max packet size for RX */
  68. static int dma_rx_descriptor_length = 24; /* Number of descriptors per DMA RX channel */
  69. static int dma_tx_descriptor_length = 24; /* Number of descriptors per DMA TX channel */
  70. static int eth_efmtc_crc_cfg = 0x03100710; /* default: tx_eth_crc_check: 1, tx_tc_crc_check: 1, tx_tc_crc_len = 16 */
  71. /* rx_eth_crc_present: 1, rx_eth_crc_check: 1, rx_tc_crc_check: 1, rx_tc_crc_len = 16 */
  72. MODULE_PARM(write_desc_delay, "i");
  73. MODULE_PARM_DESC(write_desc_delay, "PPE core clock cycles between descriptor write and effectiveness in external RAM");
  74. MODULE_PARM(rx_max_packet_size, "i");
  75. MODULE_PARM_DESC(rx_max_packet_size, "Max packet size in byte for downstream ethernet frames");
  76. MODULE_PARM(dma_rx_descriptor_length, "i");
  77. MODULE_PARM_DESC(dma_rx_descriptor_length, "Number of descriptor assigned to DMA RX channel (>16)");
  78. MODULE_PARM(dma_tx_descriptor_length, "i");
  79. MODULE_PARM_DESC(dma_tx_descriptor_length, "Number of descriptor assigned to DMA TX channel (>16)");
  80. MODULE_PARM(eth_efmtc_crc_cfg, "i");
  81. MODULE_PARM_DESC(eth_efmtc_crc_cfg, "Configuration for PTM TX/RX ethernet/efm-tc CRC");
  82. /*
  83. * ####################################
  84. * Definition
  85. * ####################################
  86. */
  87. #define DUMP_SKB_LEN ~0
  88. /*
  89. * ####################################
  90. * Declaration
  91. * ####################################
  92. */
  93. /*
  94. * Network Operations
  95. */
  96. static void ptm_setup(struct net_device *, int);
  97. static struct net_device_stats *ptm_get_stats(struct net_device *);
  98. static int ptm_open(struct net_device *);
  99. static int ptm_stop(struct net_device *);
  100. static unsigned int ptm_poll(int, unsigned int);
  101. static int ptm_napi_poll(struct napi_struct *, int);
  102. static int ptm_hard_start_xmit(struct sk_buff *, struct net_device *);
  103. static int ptm_ioctl(struct net_device *, struct ifreq *, int);
  104. static void ptm_tx_timeout(struct net_device *);
  105. /*
  106. * DSL Data LED
  107. */
  108. static INLINE void adsl_led_flash(void);
  109. /*
  110. * buffer manage functions
  111. */
  112. static INLINE struct sk_buff* alloc_skb_rx(void);
  113. //static INLINE struct sk_buff* alloc_skb_tx(unsigned int);
  114. static INLINE struct sk_buff *get_skb_rx_pointer(unsigned int);
  115. static INLINE int get_tx_desc(unsigned int, unsigned int *);
  116. /*
  117. * Mailbox handler and signal function
  118. */
  119. static INLINE int mailbox_rx_irq_handler(unsigned int);
  120. static irqreturn_t mailbox_irq_handler(int, void *);
  121. static INLINE void mailbox_signal(unsigned int, int);
  122. #ifdef CONFIG_IFX_PTM_RX_TASKLET
  123. static void do_ptm_tasklet(unsigned long);
  124. #endif
  125. /*
  126. * Debug Functions
  127. */
  128. #if defined(DEBUG_DUMP_SKB) && DEBUG_DUMP_SKB
  129. static void dump_skb(struct sk_buff *, u32, char *, int, int, int);
  130. #else
  131. #define dump_skb(skb, len, title, port, ch, is_tx) do {} while (0)
  132. #endif
  133. #if defined(ENABLE_DBG_PROC) && ENABLE_DBG_PROC
  134. static void skb_swap(struct sk_buff *);
  135. #else
  136. #define skb_swap(skb) do {} while (0)
  137. #endif
  138. /*
  139. * Proc File Functions
  140. */
  141. static INLINE void proc_file_create(void);
  142. static INLINE void proc_file_delete(void);
  143. static int proc_read_version(char *, char **, off_t, int, int *, void *);
  144. static int proc_read_wanmib(char *, char **, off_t, int, int *, void *);
  145. static int proc_write_wanmib(struct file *, const char *, unsigned long, void *);
  146. #if defined(ENABLE_FW_PROC) && ENABLE_FW_PROC
  147. static int proc_read_genconf(char *, char **, off_t, int, int *, void *);
  148. #endif
  149. #if defined(ENABLE_DBG_PROC) && ENABLE_DBG_PROC
  150. static int proc_read_dbg(char *, char **, off_t, int, int *, void *);
  151. static int proc_write_dbg(struct file *, const char *, unsigned long, void *);
  152. #endif
  153. /*
  154. * Proc Help Functions
  155. */
  156. static INLINE int stricmp(const char *, const char *);
  157. #if defined(ENABLE_DBG_PROC) && ENABLE_DBG_PROC
  158. static INLINE int strincmp(const char *, const char *, int);
  159. #endif
  160. static INLINE int ifx_ptm_version(char *);
  161. /*
  162. * Init & clean-up functions
  163. */
  164. static INLINE void check_parameters(void);
  165. static INLINE int init_priv_data(void);
  166. static INLINE void clear_priv_data(void);
  167. static INLINE void init_tables(void);
  168. /*
  169. * Exteranl Function
  170. */
  171. #if defined(CONFIG_IFXMIPS_DSL_CPE_MEI) || defined(CONFIG_IFXMIPS_DSL_CPE_MEI_MODULE)
  172. extern int ifx_mei_atm_showtime_check(int *is_showtime, struct port_cell_info *port_cell, void **xdata_addr);
  173. #else
  174. static inline int ifx_mei_atm_showtime_check(int *is_showtime, struct port_cell_info *port_cell, void **xdata_addr)
  175. {
  176. if ( is_showtime != NULL )
  177. *is_showtime = 0;
  178. return 0;
  179. }
  180. #endif
  181. /*
  182. * External variable
  183. */
  184. #if defined(CONFIG_IFXMIPS_DSL_CPE_MEI) || defined(CONFIG_IFXMIPS_DSL_CPE_MEI_MODULE)
  185. extern int (*ifx_mei_atm_showtime_enter)(struct port_cell_info *, void *);
  186. extern int (*ifx_mei_atm_showtime_exit)(void);
  187. #else
  188. int (*ifx_mei_atm_showtime_enter)(struct port_cell_info *, void *) = NULL;
  189. EXPORT_SYMBOL(ifx_mei_atm_showtime_enter);
  190. int (*ifx_mei_atm_showtime_exit)(void) = NULL;
  191. EXPORT_SYMBOL(ifx_mei_atm_showtime_exit);
  192. #endif
  193. /*
  194. * ####################################
  195. * Local Variable
  196. * ####################################
  197. */
  198. static struct ptm_priv_data g_ptm_priv_data;
  199. #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,32)
  200. static struct net_device_ops g_ptm_netdev_ops = {
  201. .ndo_get_stats = ptm_get_stats,
  202. .ndo_open = ptm_open,
  203. .ndo_stop = ptm_stop,
  204. .ndo_start_xmit = ptm_hard_start_xmit,
  205. .ndo_validate_addr = eth_validate_addr,
  206. .ndo_set_mac_address = eth_mac_addr,
  207. .ndo_change_mtu = eth_change_mtu,
  208. .ndo_do_ioctl = ptm_ioctl,
  209. .ndo_tx_timeout = ptm_tx_timeout,
  210. };
  211. #endif
  212. static struct net_device *g_net_dev[2] = {0};
  213. static char *g_net_dev_name[2] = {"ptm0", "ptmfast0"};
  214. #ifdef CONFIG_IFX_PTM_RX_TASKLET
  215. static struct tasklet_struct g_ptm_tasklet[] = {
  216. {NULL, 0, ATOMIC_INIT(0), do_ptm_tasklet, 0},
  217. {NULL, 0, ATOMIC_INIT(0), do_ptm_tasklet, 1},
  218. };
  219. #endif
  220. unsigned int ifx_ptm_dbg_enable = DBG_ENABLE_MASK_ERR;
  221. static struct proc_dir_entry* g_ptm_dir = NULL;
  222. static int g_showtime = 0;
  223. /*
  224. * ####################################
  225. * Local Function
  226. * ####################################
  227. */
  228. static void ptm_setup(struct net_device *dev, int ndev)
  229. {
  230. #if defined(CONFIG_IFXMIPS_DSL_CPE_MEI) || defined(CONFIG_IFXMIPS_DSL_CPE_MEI_MODULE)
  231. netif_carrier_off(dev);
  232. #endif
  233. /* hook network operations */
  234. dev->netdev_ops = &g_ptm_netdev_ops;
  235. netif_napi_add(dev, &g_ptm_priv_data.itf[ndev].napi, ptm_napi_poll, 25);
  236. dev->watchdog_timeo = ETH_WATCHDOG_TIMEOUT;
  237. dev->dev_addr[0] = 0x00;
  238. dev->dev_addr[1] = 0x20;
  239. dev->dev_addr[2] = 0xda;
  240. dev->dev_addr[3] = 0x86;
  241. dev->dev_addr[4] = 0x23;
  242. dev->dev_addr[5] = 0x75 + ndev;
  243. }
  244. static struct net_device_stats *ptm_get_stats(struct net_device *dev)
  245. {
  246. int ndev;
  247. for ( ndev = 0; ndev < ARRAY_SIZE(g_net_dev) && g_net_dev[ndev] != dev; ndev++ );
  248. ASSERT(ndev >= 0 && ndev < ARRAY_SIZE(g_net_dev), "ndev = %d (wrong value)", ndev);
  249. g_ptm_priv_data.itf[ndev].stats.rx_errors = WAN_MIB_TABLE[ndev].wrx_tccrc_err_pdu + WAN_MIB_TABLE[ndev].wrx_ethcrc_err_pdu;
  250. g_ptm_priv_data.itf[ndev].stats.rx_dropped = WAN_MIB_TABLE[ndev].wrx_nodesc_drop_pdu + WAN_MIB_TABLE[ndev].wrx_len_violation_drop_pdu + (WAN_MIB_TABLE[ndev].wrx_correct_pdu - g_ptm_priv_data.itf[ndev].stats.rx_packets);
  251. return &g_ptm_priv_data.itf[ndev].stats;
  252. }
  253. static int ptm_open(struct net_device *dev)
  254. {
  255. int ndev;
  256. for ( ndev = 0; ndev < ARRAY_SIZE(g_net_dev) && g_net_dev[ndev] != dev; ndev++ );
  257. ASSERT(ndev >= 0 && ndev < ARRAY_SIZE(g_net_dev), "ndev = %d (wrong value)", ndev);
  258. napi_enable(&g_ptm_priv_data.itf[ndev].napi);
  259. IFX_REG_W32_MASK(0, 1 << ndev, MBOX_IGU1_IER);
  260. netif_start_queue(dev);
  261. return 0;
  262. }
  263. static int ptm_stop(struct net_device *dev)
  264. {
  265. int ndev;
  266. for ( ndev = 0; ndev < ARRAY_SIZE(g_net_dev) && g_net_dev[ndev] != dev; ndev++ );
  267. ASSERT(ndev >= 0 && ndev < ARRAY_SIZE(g_net_dev), "ndev = %d (wrong value)", ndev);
  268. IFX_REG_W32_MASK((1 << ndev) | (1 << (ndev + 16)), 0, MBOX_IGU1_IER);
  269. napi_disable(&g_ptm_priv_data.itf[ndev].napi);
  270. netif_stop_queue(dev);
  271. return 0;
  272. }
  273. static unsigned int ptm_poll(int ndev, unsigned int work_to_do)
  274. {
  275. unsigned int work_done = 0;
  276. ASSERT(ndev >= 0 && ndev < ARRAY_SIZE(g_net_dev), "ndev = %d (wrong value)", ndev);
  277. while ( work_done < work_to_do && WRX_DMA_CHANNEL_CONFIG(ndev)->vlddes > 0 ) {
  278. if ( mailbox_rx_irq_handler(ndev) < 0 )
  279. break;
  280. work_done++;
  281. }
  282. return work_done;
  283. }
  284. static int ptm_napi_poll(struct napi_struct *napi, int budget)
  285. {
  286. int ndev;
  287. unsigned int work_done;
  288. for ( ndev = 0; ndev < ARRAY_SIZE(g_net_dev) && g_net_dev[ndev] != napi->dev; ndev++ );
  289. work_done = ptm_poll(ndev, budget);
  290. // interface down
  291. if ( !netif_running(napi->dev) ) {
  292. napi_complete(napi);
  293. return work_done;
  294. }
  295. // no more traffic
  296. if ( WRX_DMA_CHANNEL_CONFIG(ndev)->vlddes == 0 ) {
  297. // clear interrupt
  298. IFX_REG_W32_MASK(0, 1 << ndev, MBOX_IGU1_ISRC);
  299. // double check
  300. if ( WRX_DMA_CHANNEL_CONFIG(ndev)->vlddes == 0 ) {
  301. napi_complete(napi);
  302. IFX_REG_W32_MASK(0, 1 << ndev, MBOX_IGU1_IER);
  303. return work_done;
  304. }
  305. }
  306. // next round
  307. return work_done;
  308. }
  309. static int ptm_hard_start_xmit(struct sk_buff *skb, struct net_device *dev)
  310. {
  311. int ndev;
  312. unsigned int f_full;
  313. int desc_base;
  314. register struct tx_descriptor reg_desc = {0};
  315. for ( ndev = 0; ndev < ARRAY_SIZE(g_net_dev) && g_net_dev[ndev] != dev; ndev++ );
  316. ASSERT(ndev >= 0 && ndev < ARRAY_SIZE(g_net_dev), "ndev = %d (wrong value)", ndev);
  317. if ( !g_showtime ) {
  318. err("not in showtime");
  319. goto PTM_HARD_START_XMIT_FAIL;
  320. }
  321. /* allocate descriptor */
  322. desc_base = get_tx_desc(ndev, &f_full);
  323. if ( f_full ) {
  324. dev->trans_start = jiffies;
  325. netif_stop_queue(dev);
  326. IFX_REG_W32_MASK(0, 1 << (ndev + 16), MBOX_IGU1_ISRC);
  327. IFX_REG_W32_MASK(0, 1 << (ndev + 16), MBOX_IGU1_IER);
  328. }
  329. if ( desc_base < 0 )
  330. goto PTM_HARD_START_XMIT_FAIL;
  331. if ( g_ptm_priv_data.itf[ndev].tx_skb[desc_base] != NULL )
  332. dev_kfree_skb_any(g_ptm_priv_data.itf[ndev].tx_skb[desc_base]);
  333. g_ptm_priv_data.itf[ndev].tx_skb[desc_base] = skb;
  334. reg_desc.dataptr = (unsigned int)skb->data >> 2;
  335. reg_desc.datalen = skb->len < ETH_ZLEN ? ETH_ZLEN : skb->len;
  336. reg_desc.byteoff = (unsigned int)skb->data & (DATA_BUFFER_ALIGNMENT - 1);
  337. reg_desc.own = 1;
  338. reg_desc.c = 1;
  339. reg_desc.sop = reg_desc.eop = 1;
  340. /* write discriptor to memory and write back cache */
  341. g_ptm_priv_data.itf[ndev].tx_desc[desc_base] = reg_desc;
  342. dma_cache_wback((unsigned long)skb->data, skb->len);
  343. wmb();
  344. dump_skb(skb, DUMP_SKB_LEN, (char *)__func__, ndev, ndev, 1);
  345. if ( (ifx_ptm_dbg_enable & DBG_ENABLE_MASK_MAC_SWAP) ) {
  346. skb_swap(skb);
  347. }
  348. g_ptm_priv_data.itf[ndev].stats.tx_packets++;
  349. g_ptm_priv_data.itf[ndev].stats.tx_bytes += reg_desc.datalen;
  350. dev->trans_start = jiffies;
  351. mailbox_signal(ndev, 1);
  352. adsl_led_flash();
  353. return NETDEV_TX_OK;
  354. PTM_HARD_START_XMIT_FAIL:
  355. dev_kfree_skb_any(skb);
  356. g_ptm_priv_data.itf[ndev].stats.tx_dropped++;
  357. return NETDEV_TX_OK;
  358. }
  359. static int ptm_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
  360. {
  361. int ndev;
  362. for ( ndev = 0; ndev < ARRAY_SIZE(g_net_dev) && g_net_dev[ndev] != dev; ndev++ );
  363. ASSERT(ndev >= 0 && ndev < ARRAY_SIZE(g_net_dev), "ndev = %d (wrong value)", ndev);
  364. switch ( cmd )
  365. {
  366. case IFX_PTM_MIB_CW_GET:
  367. ((PTM_CW_IF_ENTRY_T *)ifr->ifr_data)->ifRxNoIdleCodewords = WAN_MIB_TABLE[ndev].wrx_nonidle_cw;
  368. ((PTM_CW_IF_ENTRY_T *)ifr->ifr_data)->ifRxIdleCodewords = WAN_MIB_TABLE[ndev].wrx_idle_cw;
  369. ((PTM_CW_IF_ENTRY_T *)ifr->ifr_data)->ifRxCodingViolation = WAN_MIB_TABLE[ndev].wrx_err_cw;
  370. ((PTM_CW_IF_ENTRY_T *)ifr->ifr_data)->ifTxNoIdleCodewords = 0;
  371. ((PTM_CW_IF_ENTRY_T *)ifr->ifr_data)->ifTxIdleCodewords = 0;
  372. break;
  373. case IFX_PTM_MIB_FRAME_GET:
  374. ((PTM_FRAME_MIB_T *)ifr->ifr_data)->RxCorrect = WAN_MIB_TABLE[ndev].wrx_correct_pdu;
  375. ((PTM_FRAME_MIB_T *)ifr->ifr_data)->TC_CrcError = WAN_MIB_TABLE[ndev].wrx_tccrc_err_pdu;
  376. ((PTM_FRAME_MIB_T *)ifr->ifr_data)->RxDropped = WAN_MIB_TABLE[ndev].wrx_nodesc_drop_pdu + WAN_MIB_TABLE[ndev].wrx_len_violation_drop_pdu;
  377. ((PTM_FRAME_MIB_T *)ifr->ifr_data)->TxSend = WAN_MIB_TABLE[ndev].wtx_total_pdu;
  378. break;
  379. case IFX_PTM_CFG_GET:
  380. ((IFX_PTM_CFG_T *)ifr->ifr_data)->RxEthCrcPresent = CFG_ETH_EFMTC_CRC->rx_eth_crc_present;
  381. ((IFX_PTM_CFG_T *)ifr->ifr_data)->RxEthCrcCheck = CFG_ETH_EFMTC_CRC->rx_eth_crc_check;
  382. ((IFX_PTM_CFG_T *)ifr->ifr_data)->RxTcCrcCheck = CFG_ETH_EFMTC_CRC->rx_tc_crc_check;
  383. ((IFX_PTM_CFG_T *)ifr->ifr_data)->RxTcCrcLen = CFG_ETH_EFMTC_CRC->rx_tc_crc_len;
  384. ((IFX_PTM_CFG_T *)ifr->ifr_data)->TxEthCrcGen = CFG_ETH_EFMTC_CRC->tx_eth_crc_gen;
  385. ((IFX_PTM_CFG_T *)ifr->ifr_data)->TxTcCrcGen = CFG_ETH_EFMTC_CRC->tx_tc_crc_gen;
  386. ((IFX_PTM_CFG_T *)ifr->ifr_data)->TxTcCrcLen = CFG_ETH_EFMTC_CRC->tx_tc_crc_len;
  387. break;
  388. case IFX_PTM_CFG_SET:
  389. CFG_ETH_EFMTC_CRC->rx_eth_crc_present = ((IFX_PTM_CFG_T *)ifr->ifr_data)->RxEthCrcPresent ? 1 : 0;
  390. CFG_ETH_EFMTC_CRC->rx_eth_crc_check = ((IFX_PTM_CFG_T *)ifr->ifr_data)->RxEthCrcCheck ? 1 : 0;
  391. if ( ((IFX_PTM_CFG_T *)ifr->ifr_data)->RxTcCrcCheck && (((IFX_PTM_CFG_T *)ifr->ifr_data)->RxTcCrcLen == 16 || ((IFX_PTM_CFG_T *)ifr->ifr_data)->RxTcCrcLen == 32) )
  392. {
  393. CFG_ETH_EFMTC_CRC->rx_tc_crc_check = 1;
  394. CFG_ETH_EFMTC_CRC->rx_tc_crc_len = ((IFX_PTM_CFG_T *)ifr->ifr_data)->RxTcCrcLen;
  395. }
  396. else
  397. {
  398. CFG_ETH_EFMTC_CRC->rx_tc_crc_check = 0;
  399. CFG_ETH_EFMTC_CRC->rx_tc_crc_len = 0;
  400. }
  401. CFG_ETH_EFMTC_CRC->tx_eth_crc_gen = ((IFX_PTM_CFG_T *)ifr->ifr_data)->TxEthCrcGen ? 1 : 0;
  402. if ( ((IFX_PTM_CFG_T *)ifr->ifr_data)->TxTcCrcGen && (((IFX_PTM_CFG_T *)ifr->ifr_data)->TxTcCrcLen == 16 || ((IFX_PTM_CFG_T *)ifr->ifr_data)->TxTcCrcLen == 32) )
  403. {
  404. CFG_ETH_EFMTC_CRC->tx_tc_crc_gen = 1;
  405. CFG_ETH_EFMTC_CRC->tx_tc_crc_len = ((IFX_PTM_CFG_T *)ifr->ifr_data)->TxTcCrcLen;
  406. }
  407. else
  408. {
  409. CFG_ETH_EFMTC_CRC->tx_tc_crc_gen = 0;
  410. CFG_ETH_EFMTC_CRC->tx_tc_crc_len = 0;
  411. }
  412. break;
  413. default:
  414. return -EOPNOTSUPP;
  415. }
  416. return 0;
  417. }
  418. static void ptm_tx_timeout(struct net_device *dev)
  419. {
  420. int ndev;
  421. for ( ndev = 0; ndev < ARRAY_SIZE(g_net_dev) && g_net_dev[ndev] != dev; ndev++ );
  422. ASSERT(ndev >= 0 && ndev < ARRAY_SIZE(g_net_dev), "ndev = %d (wrong value)", ndev);
  423. /* disable TX irq, release skb when sending new packet */
  424. IFX_REG_W32_MASK(1 << (ndev + 16), 0, MBOX_IGU1_IER);
  425. /* wake up TX queue */
  426. netif_wake_queue(dev);
  427. return;
  428. }
  429. static INLINE void adsl_led_flash(void)
  430. {
  431. }
  432. static INLINE struct sk_buff* alloc_skb_rx(void)
  433. {
  434. struct sk_buff *skb;
  435. /* allocate memroy including trailer and padding */
  436. skb = dev_alloc_skb(rx_max_packet_size + RX_HEAD_MAC_ADDR_ALIGNMENT + DATA_BUFFER_ALIGNMENT);
  437. if ( skb != NULL ) {
  438. /* must be burst length alignment and reserve two more bytes for MAC address alignment */
  439. if ( ((unsigned int)skb->data & (DATA_BUFFER_ALIGNMENT - 1)) != 0 )
  440. skb_reserve(skb, ~((unsigned int)skb->data + (DATA_BUFFER_ALIGNMENT - 1)) & (DATA_BUFFER_ALIGNMENT - 1));
  441. /* pub skb in reserved area "skb->data - 4" */
  442. *((struct sk_buff **)skb->data - 1) = skb;
  443. wmb();
  444. /* write back and invalidate cache */
  445. dma_cache_wback_inv((unsigned long)skb->data - sizeof(skb), sizeof(skb));
  446. /* invalidate cache */
  447. dma_cache_inv((unsigned long)skb->data, (unsigned int)skb->end - (unsigned int)skb->data);
  448. }
  449. return skb;
  450. }
  451. #if 0
  452. static INLINE struct sk_buff* alloc_skb_tx(unsigned int size)
  453. {
  454. struct sk_buff *skb;
  455. /* allocate memory including padding */
  456. size = (size + DATA_BUFFER_ALIGNMENT - 1) & ~(DATA_BUFFER_ALIGNMENT - 1);
  457. skb = dev_alloc_skb(size + DATA_BUFFER_ALIGNMENT);
  458. /* must be burst length alignment */
  459. if ( skb != NULL )
  460. skb_reserve(skb, ~((unsigned int)skb->data + (DATA_BUFFER_ALIGNMENT - 1)) & (DATA_BUFFER_ALIGNMENT - 1));
  461. return skb;
  462. }
  463. #endif
  464. static INLINE struct sk_buff *get_skb_rx_pointer(unsigned int dataptr)
  465. {
  466. unsigned int skb_dataptr;
  467. struct sk_buff *skb;
  468. skb_dataptr = ((dataptr - 1) << 2) | KSEG1;
  469. skb = *(struct sk_buff **)skb_dataptr;
  470. ASSERT((unsigned int)skb >= KSEG0, "invalid skb - skb = %#08x, dataptr = %#08x", (unsigned int)skb, dataptr);
  471. ASSERT(((unsigned int)skb->data | KSEG1) == ((dataptr << 2) | KSEG1), "invalid skb - skb = %#08x, skb->data = %#08x, dataptr = %#08x", (unsigned int)skb, (unsigned int)skb->data, dataptr);
  472. return skb;
  473. }
  474. static INLINE int get_tx_desc(unsigned int itf, unsigned int *f_full)
  475. {
  476. int desc_base = -1;
  477. struct ptm_itf *p_itf = &g_ptm_priv_data.itf[itf];
  478. // assume TX is serial operation
  479. // no protection provided
  480. *f_full = 1;
  481. if ( p_itf->tx_desc[p_itf->tx_desc_pos].own == 0 ) {
  482. desc_base = p_itf->tx_desc_pos;
  483. if ( ++(p_itf->tx_desc_pos) == dma_tx_descriptor_length )
  484. p_itf->tx_desc_pos = 0;
  485. if ( p_itf->tx_desc[p_itf->tx_desc_pos].own == 0 )
  486. *f_full = 0;
  487. }
  488. return desc_base;
  489. }
  490. static INLINE int mailbox_rx_irq_handler(unsigned int ch) // return: < 0 - descriptor not available, 0 - received one packet
  491. {
  492. unsigned int ndev = ch;
  493. struct sk_buff *skb;
  494. struct sk_buff *new_skb;
  495. volatile struct rx_descriptor *desc;
  496. struct rx_descriptor reg_desc;
  497. int netif_rx_ret;
  498. desc = &g_ptm_priv_data.itf[ndev].rx_desc[g_ptm_priv_data.itf[ndev].rx_desc_pos];
  499. if ( desc->own || !desc->c ) // if PP32 hold descriptor or descriptor not completed
  500. return -EAGAIN;
  501. if ( ++g_ptm_priv_data.itf[ndev].rx_desc_pos == dma_rx_descriptor_length )
  502. g_ptm_priv_data.itf[ndev].rx_desc_pos = 0;
  503. reg_desc = *desc;
  504. skb = get_skb_rx_pointer(reg_desc.dataptr);
  505. if ( !reg_desc.err ) {
  506. new_skb = alloc_skb_rx();
  507. if ( new_skb != NULL ) {
  508. skb_reserve(skb, reg_desc.byteoff);
  509. skb_put(skb, reg_desc.datalen);
  510. dump_skb(skb, DUMP_SKB_LEN, (char *)__func__, ndev, ndev, 0);
  511. // parse protocol header
  512. skb->dev = g_net_dev[ndev];
  513. skb->protocol = eth_type_trans(skb, skb->dev);
  514. g_net_dev[ndev]->last_rx = jiffies;
  515. netif_rx_ret = netif_receive_skb(skb);
  516. if ( netif_rx_ret != NET_RX_DROP ) {
  517. g_ptm_priv_data.itf[ndev].stats.rx_packets++;
  518. g_ptm_priv_data.itf[ndev].stats.rx_bytes += reg_desc.datalen;
  519. }
  520. reg_desc.dataptr = ((unsigned int)new_skb->data >> 2) & 0x0FFFFFFF;
  521. reg_desc.byteoff = RX_HEAD_MAC_ADDR_ALIGNMENT;
  522. }
  523. }
  524. else
  525. reg_desc.err = 0;
  526. reg_desc.datalen = rx_max_packet_size;
  527. reg_desc.own = 1;
  528. reg_desc.c = 0;
  529. // update descriptor
  530. *desc = reg_desc;
  531. wmb();
  532. mailbox_signal(ndev, 0);
  533. adsl_led_flash();
  534. return 0;
  535. }
  536. static irqreturn_t mailbox_irq_handler(int irq, void *dev_id)
  537. {
  538. unsigned int isr;
  539. int i;
  540. isr = IFX_REG_R32(MBOX_IGU1_ISR);
  541. IFX_REG_W32(isr, MBOX_IGU1_ISRC);
  542. isr &= IFX_REG_R32(MBOX_IGU1_IER);
  543. while ( (i = __fls(isr)) >= 0 ) {
  544. isr ^= 1 << i;
  545. if ( i >= 16 ) {
  546. // TX
  547. IFX_REG_W32_MASK(1 << i, 0, MBOX_IGU1_IER);
  548. i -= 16;
  549. if ( i < MAX_ITF_NUMBER )
  550. netif_wake_queue(g_net_dev[i]);
  551. }
  552. else {
  553. // RX
  554. #ifdef CONFIG_IFX_PTM_RX_INTERRUPT
  555. while ( WRX_DMA_CHANNEL_CONFIG(i)->vlddes > 0 )
  556. mailbox_rx_irq_handler(i);
  557. #else
  558. IFX_REG_W32_MASK(1 << i, 0, MBOX_IGU1_IER);
  559. napi_schedule(&g_ptm_priv_data.itf[i].napi);
  560. #endif
  561. }
  562. }
  563. return IRQ_HANDLED;
  564. }
  565. static INLINE void mailbox_signal(unsigned int itf, int is_tx)
  566. {
  567. int count = 1000;
  568. if ( is_tx ) {
  569. while ( MBOX_IGU3_ISR_ISR(itf + 16) && count > 0 )
  570. count--;
  571. IFX_REG_W32(MBOX_IGU3_ISRS_SET(itf + 16), MBOX_IGU3_ISRS);
  572. }
  573. else {
  574. while ( MBOX_IGU3_ISR_ISR(itf) && count > 0 )
  575. count--;
  576. IFX_REG_W32(MBOX_IGU3_ISRS_SET(itf), MBOX_IGU3_ISRS);
  577. }
  578. ASSERT(count != 0, "MBOX_IGU3_ISR = 0x%08x", IFX_REG_R32(MBOX_IGU3_ISR));
  579. }
  580. #ifdef CONFIG_IFX_PTM_RX_TASKLET
  581. static void do_ptm_tasklet(unsigned long arg)
  582. {
  583. unsigned int work_to_do = 25;
  584. unsigned int work_done = 0;
  585. ASSERT(arg >= 0 && arg < ARRAY_SIZE(g_net_dev), "arg = %lu (wrong value)", arg);
  586. while ( work_done < work_to_do && WRX_DMA_CHANNEL_CONFIG(arg)->vlddes > 0 ) {
  587. if ( mailbox_rx_irq_handler(arg) < 0 )
  588. break;
  589. work_done++;
  590. }
  591. // interface down
  592. if ( !netif_running(g_net_dev[arg]) )
  593. return;
  594. // no more traffic
  595. if ( WRX_DMA_CHANNEL_CONFIG(arg)->vlddes == 0 ) {
  596. // clear interrupt
  597. IFX_REG_W32_MASK(0, 1 << arg, MBOX_IGU1_ISRC);
  598. // double check
  599. if ( WRX_DMA_CHANNEL_CONFIG(arg)->vlddes == 0 ) {
  600. IFX_REG_W32_MASK(0, 1 << arg, MBOX_IGU1_IER);
  601. return;
  602. }
  603. }
  604. // next round
  605. tasklet_schedule(&g_ptm_tasklet[arg]);
  606. }
  607. #endif
  608. #if defined(DEBUG_DUMP_SKB) && DEBUG_DUMP_SKB
  609. static void dump_skb(struct sk_buff *skb, u32 len, char *title, int port, int ch, int is_tx)
  610. {
  611. int i;
  612. if ( !(ifx_ptm_dbg_enable & (is_tx ? DBG_ENABLE_MASK_DUMP_SKB_TX : DBG_ENABLE_MASK_DUMP_SKB_RX)) )
  613. return;
  614. if ( skb->len < len )
  615. len = skb->len;
  616. if ( len > rx_max_packet_size ) {
  617. printk("too big data length: skb = %08x, skb->data = %08x, skb->len = %d\n", (u32)skb, (u32)skb->data, skb->len);
  618. return;
  619. }
  620. if ( ch >= 0 )
  621. printk("%s (port %d, ch %d)\n", title, port, ch);
  622. else
  623. printk("%s\n", title);
  624. printk(" skb->data = %08X, skb->tail = %08X, skb->len = %d\n", (u32)skb->data, (u32)skb->tail, (int)skb->len);
  625. for ( i = 1; i <= len; i++ ) {
  626. if ( i % 16 == 1 )
  627. printk(" %4d:", i - 1);
  628. printk(" %02X", (int)(*((char*)skb->data + i - 1) & 0xFF));
  629. if ( i % 16 == 0 )
  630. printk("\n");
  631. }
  632. if ( (i - 1) % 16 != 0 )
  633. printk("\n");
  634. }
  635. #endif
  636. #if defined(ENABLE_DBG_PROC) && ENABLE_DBG_PROC
  637. static void skb_swap(struct sk_buff *skb)
  638. {
  639. unsigned char tmp[8];
  640. unsigned char *p = skb->data;
  641. if ( !(p[0] & 0x01) ) { // bypass broadcast/multicast
  642. // swap MAC
  643. memcpy(tmp, p, 6);
  644. memcpy(p, p + 6, 6);
  645. memcpy(p + 6, tmp, 6);
  646. p += 12;
  647. // bypass VLAN
  648. while ( p[0] == 0x81 && p[1] == 0x00 )
  649. p += 4;
  650. // IP
  651. if ( p[0] == 0x08 && p[1] == 0x00 ) {
  652. p += 14;
  653. memcpy(tmp, p, 4);
  654. memcpy(p, p + 4, 4);
  655. memcpy(p + 4, tmp, 4);
  656. p += 8;
  657. }
  658. dma_cache_wback((unsigned long)skb->data, (unsigned long)p - (unsigned long)skb->data);
  659. }
  660. }
  661. #endif
  662. static INLINE void proc_file_create(void)
  663. {
  664. #if defined(ENABLE_DBG_PROC) && ENABLE_DBG_PROC
  665. struct proc_dir_entry *res;
  666. g_ptm_dir = proc_mkdir("driver/ifx_ptm", NULL);
  667. create_proc_read_entry("version",
  668. 0,
  669. g_ptm_dir,
  670. proc_read_version,
  671. NULL);
  672. res = create_proc_entry("wanmib",
  673. 0,
  674. g_ptm_dir);
  675. if ( res != NULL ) {
  676. res->read_proc = proc_read_wanmib;
  677. res->write_proc = proc_write_wanmib;
  678. }
  679. #if defined(ENABLE_FW_PROC) && ENABLE_FW_PROC
  680. create_proc_read_entry("genconf",
  681. 0,
  682. g_ptm_dir,
  683. proc_read_genconf,
  684. NULL);
  685. #ifdef CONFIG_AR9
  686. create_proc_read_entry("regs",
  687. 0,
  688. g_ptm_dir,
  689. ifx_ptm_proc_read_regs,
  690. NULL);
  691. #endif
  692. #endif
  693. res = create_proc_entry("dbg",
  694. 0,
  695. g_ptm_dir);
  696. if ( res != NULL ) {
  697. res->read_proc = proc_read_dbg;
  698. res->write_proc = proc_write_dbg;
  699. }
  700. #endif
  701. }
  702. static INLINE void proc_file_delete(void)
  703. {
  704. #if defined(ENABLE_DBG_PROC) && ENABLE_DBG_PROC
  705. remove_proc_entry("dbg", g_ptm_dir);
  706. #endif
  707. #if defined(ENABLE_FW_PROC) && ENABLE_FW_PROC
  708. #ifdef CONFIG_AR9
  709. remove_proc_entry("regs", g_ptm_dir);
  710. #endif
  711. remove_proc_entry("genconf", g_ptm_dir);
  712. #endif
  713. remove_proc_entry("wanmib", g_ptm_dir);
  714. remove_proc_entry("version", g_ptm_dir);
  715. remove_proc_entry("driver/ifx_ptm", NULL);
  716. }
  717. static int proc_read_version(char *buf, char **start, off_t offset, int count, int *eof, void *data)
  718. {
  719. int len = 0;
  720. len += ifx_ptm_version(buf + len);
  721. if ( offset >= len ) {
  722. *start = buf;
  723. *eof = 1;
  724. return 0;
  725. }
  726. *start = buf + offset;
  727. if ( (len -= offset) > count )
  728. return count;
  729. *eof = 1;
  730. return len;
  731. }
  732. static int proc_read_wanmib(char *page, char **start, off_t off, int count, int *eof, void *data)
  733. {
  734. int len = 0;
  735. int i;
  736. char *title[] = {
  737. "ptm0\n",
  738. "ptmfast0\n"
  739. };
  740. for ( i = 0; i < ARRAY_SIZE(title); i++ ) {
  741. len += sprintf(page + off + len, title[i]);
  742. len += sprintf(page + off + len, " wrx_correct_pdu = %d\n", WAN_MIB_TABLE[i].wrx_correct_pdu);
  743. len += sprintf(page + off + len, " wrx_correct_pdu_bytes = %d\n", WAN_MIB_TABLE[i].wrx_correct_pdu_bytes);
  744. len += sprintf(page + off + len, " wrx_tccrc_err_pdu = %d\n", WAN_MIB_TABLE[i].wrx_tccrc_err_pdu);
  745. len += sprintf(page + off + len, " wrx_tccrc_err_pdu_bytes = %d\n", WAN_MIB_TABLE[i].wrx_tccrc_err_pdu_bytes);
  746. len += sprintf(page + off + len, " wrx_ethcrc_err_pdu = %d\n", WAN_MIB_TABLE[i].wrx_ethcrc_err_pdu);
  747. len += sprintf(page + off + len, " wrx_ethcrc_err_pdu_bytes = %d\n", WAN_MIB_TABLE[i].wrx_ethcrc_err_pdu_bytes);
  748. len += sprintf(page + off + len, " wrx_nodesc_drop_pdu = %d\n", WAN_MIB_TABLE[i].wrx_nodesc_drop_pdu);
  749. len += sprintf(page + off + len, " wrx_len_violation_drop_pdu = %d\n", WAN_MIB_TABLE[i].wrx_len_violation_drop_pdu);
  750. len += sprintf(page + off + len, " wrx_idle_bytes = %d\n", WAN_MIB_TABLE[i].wrx_idle_bytes);
  751. len += sprintf(page + off + len, " wrx_nonidle_cw = %d\n", WAN_MIB_TABLE[i].wrx_nonidle_cw);
  752. len += sprintf(page + off + len, " wrx_idle_cw = %d\n", WAN_MIB_TABLE[i].wrx_idle_cw);
  753. len += sprintf(page + off + len, " wrx_err_cw = %d\n", WAN_MIB_TABLE[i].wrx_err_cw);
  754. len += sprintf(page + off + len, " wtx_total_pdu = %d\n", WAN_MIB_TABLE[i].wtx_total_pdu);
  755. len += sprintf(page + off + len, " wtx_total_bytes = %d\n", WAN_MIB_TABLE[i].wtx_total_bytes);
  756. }
  757. *eof = 1;
  758. return len;
  759. }
  760. static int proc_write_wanmib(struct file *file, const char *buf, unsigned long count, void *data)
  761. {
  762. char str[2048];
  763. char *p;
  764. int len, rlen;
  765. int i;
  766. len = count < sizeof(str) ? count : sizeof(str) - 1;
  767. rlen = len - copy_from_user(str, buf, len);
  768. while ( rlen && str[rlen - 1] <= ' ' )
  769. rlen--;
  770. str[rlen] = 0;
  771. for ( p = str; *p && *p <= ' '; p++, rlen-- );
  772. if ( !*p )
  773. return count;
  774. if ( stricmp(p, "clear") == 0 || stricmp(p, "clean") == 0 ) {
  775. for ( i = 0; i < 2; i++ )
  776. memset((void*)&WAN_MIB_TABLE[i], 0, sizeof(WAN_MIB_TABLE[i]));
  777. }
  778. return count;
  779. }
  780. #if defined(ENABLE_FW_PROC) && ENABLE_FW_PROC
  781. static int proc_read_genconf(char *page, char **start, off_t off, int count, int *eof, void *data)
  782. {
  783. int len = 0;
  784. int len_max = off + count;
  785. char *pstr;
  786. char str[2048];
  787. int llen = 0;
  788. int i;
  789. unsigned long bit;
  790. pstr = *start = page;
  791. __sync();
  792. llen += sprintf(str + llen, "CFG_WAN_WRDES_DELAY (0x%08X): %d\n", (unsigned int)CFG_WAN_WRDES_DELAY, IFX_REG_R32(CFG_WAN_WRDES_DELAY));
  793. llen += sprintf(str + llen, "CFG_WRX_DMACH_ON (0x%08X):", (unsigned int)CFG_WRX_DMACH_ON);
  794. for ( i = 0, bit = 1; i < MAX_RX_DMA_CHANNEL_NUMBER; i++, bit <<= 1 )
  795. llen += sprintf(str + llen, " %d - %s", i, (IFX_REG_R32(CFG_WRX_DMACH_ON) & bit) ? "on " : "off");
  796. llen += sprintf(str + llen, "\n");
  797. llen += sprintf(str + llen, "CFG_WTX_DMACH_ON (0x%08X):", (unsigned int)CFG_WTX_DMACH_ON);
  798. for ( i = 0, bit = 1; i < MAX_TX_DMA_CHANNEL_NUMBER; i++, bit <<= 1 )
  799. llen += sprintf(str + llen, " %d - %s", i, (IFX_REG_R32(CFG_WTX_DMACH_ON) & bit) ? "on " : "off");
  800. llen += sprintf(str + llen, "\n");
  801. llen += sprintf(str + llen, "CFG_WRX_LOOK_BITTH (0x%08X): %d\n", (unsigned int)CFG_WRX_LOOK_BITTH, IFX_REG_R32(CFG_WRX_LOOK_BITTH));
  802. llen += sprintf(str + llen, "CFG_ETH_EFMTC_CRC (0x%08X): rx_tc_crc_len - %2d, rx_tc_crc_check - %s\n", (unsigned int)CFG_ETH_EFMTC_CRC, CFG_ETH_EFMTC_CRC->rx_tc_crc_len, CFG_ETH_EFMTC_CRC->rx_tc_crc_check ? " on" : "off");
  803. llen += sprintf(str + llen, " rx_eth_crc_check - %s, rx_eth_crc_present - %s\n", CFG_ETH_EFMTC_CRC->rx_eth_crc_check ? " on" : "off", CFG_ETH_EFMTC_CRC->rx_eth_crc_present ? " on" : "off");
  804. llen += sprintf(str + llen, " tx_tc_crc_len - %2d, tx_tc_crc_gen - %s\n", CFG_ETH_EFMTC_CRC->tx_tc_crc_len, CFG_ETH_EFMTC_CRC->tx_tc_crc_gen ? " on" : "off");
  805. llen += sprintf(str + llen, " tx_eth_crc_gen - %s\n", CFG_ETH_EFMTC_CRC->tx_eth_crc_gen ? " on" : "off");
  806. llen += sprintf(str + llen, "RX Port:\n");
  807. for ( i = 0; i < MAX_RX_DMA_CHANNEL_NUMBER; i++ )
  808. llen += sprintf(str + llen, " %d (0x%08X). mfs - %5d, dmach - %d, local_state - %d, partner_state - %d\n", i, (unsigned int)WRX_PORT_CONFIG(i), WRX_PORT_CONFIG(i)->mfs, WRX_PORT_CONFIG(i)->dmach, WRX_PORT_CONFIG(i)->local_state, WRX_PORT_CONFIG(i)->partner_state);
  809. llen += sprintf(str + llen, "RX DMA Channel:\n");
  810. for ( i = 0; i < MAX_RX_DMA_CHANNEL_NUMBER; i++ )
  811. llen += sprintf(str + llen, " %d (0x%08X). desba - 0x%08X (0x%08X), deslen - %d, vlddes - %d\n", i, (unsigned int)WRX_DMA_CHANNEL_CONFIG(i), WRX_DMA_CHANNEL_CONFIG(i)->desba, ((unsigned int)WRX_DMA_CHANNEL_CONFIG(i)->desba << 2) | KSEG1, WRX_DMA_CHANNEL_CONFIG(i)->deslen, WRX_DMA_CHANNEL_CONFIG(i)->vlddes);
  812. llen += sprintf(str + llen, "TX Port:\n");
  813. for ( i = 0; i < MAX_TX_DMA_CHANNEL_NUMBER; i++ )
  814. llen += sprintf(str + llen, " %d (0x%08X). tx_cwth2 - %d, tx_cwth1 - %d\n", i, (unsigned int)WTX_PORT_CONFIG(i), WTX_PORT_CONFIG(i)->tx_cwth2, WTX_PORT_CONFIG(i)->tx_cwth1);
  815. llen += sprintf(str + llen, "TX DMA Channel:\n");
  816. for ( i = 0; i < MAX_TX_DMA_CHANNEL_NUMBER; i++ )
  817. llen += sprintf(str + llen, " %d (0x%08X). desba - 0x%08X (0x%08X), deslen - %d, vlddes - %d\n", i, (unsigned int)WTX_DMA_CHANNEL_CONFIG(i), WTX_DMA_CHANNEL_CONFIG(i)->desba, ((unsigned int)WTX_DMA_CHANNEL_CONFIG(i)->desba << 2) | KSEG1, WTX_DMA_CHANNEL_CONFIG(i)->deslen, WTX_DMA_CHANNEL_CONFIG(i)->vlddes);
  818. if ( len <= off && len + llen > off )
  819. {
  820. memcpy(pstr, str + off - len, len + llen - off);
  821. pstr += len + llen - off;
  822. }
  823. else if ( len > off )
  824. {
  825. memcpy(pstr, str, llen);
  826. pstr += llen;
  827. }
  828. len += llen;
  829. if ( len >= len_max )
  830. goto PROC_READ_GENCONF_OVERRUN_END;
  831. *eof = 1;
  832. return len - off;
  833. PROC_READ_GENCONF_OVERRUN_END:
  834. return len - llen - off;
  835. }
  836. #endif // defined(ENABLE_FW_PROC) && ENABLE_FW_PROC
  837. #if defined(ENABLE_DBG_PROC) && ENABLE_DBG_PROC
  838. static int proc_read_dbg(char *page, char **start, off_t off, int count, int *eof, void *data)
  839. {
  840. int len = 0;
  841. len += sprintf(page + off + len, "error print - %s\n", (ifx_ptm_dbg_enable & DBG_ENABLE_MASK_ERR) ? "enabled" : "disabled");
  842. len += sprintf(page + off + len, "debug print - %s\n", (ifx_ptm_dbg_enable & DBG_ENABLE_MASK_DEBUG_PRINT) ? "enabled" : "disabled");
  843. len += sprintf(page + off + len, "assert - %s\n", (ifx_ptm_dbg_enable & DBG_ENABLE_MASK_ASSERT) ? "enabled" : "disabled");
  844. len += sprintf(page + off + len, "dump rx skb - %s\n", (ifx_ptm_dbg_enable & DBG_ENABLE_MASK_DUMP_SKB_RX) ? "enabled" : "disabled");
  845. len += sprintf(page + off + len, "dump tx skb - %s\n", (ifx_ptm_dbg_enable & DBG_ENABLE_MASK_DUMP_SKB_TX) ? "enabled" : "disabled");
  846. len += sprintf(page + off + len, "mac swap - %s\n", (ifx_ptm_dbg_enable & DBG_ENABLE_MASK_MAC_SWAP) ? "enabled" : "disabled");
  847. *eof = 1;
  848. return len;
  849. }
  850. static int proc_write_dbg(struct file *file, const char *buf, unsigned long count, void *data)
  851. {
  852. static const char *dbg_enable_mask_str[] = {
  853. " error print",
  854. " err",
  855. " debug print",
  856. " dbg",
  857. " assert",
  858. " assert",
  859. " dump rx skb",
  860. " rx",
  861. " dump tx skb",
  862. " tx",
  863. " dump init",
  864. " init",
  865. " dump qos",
  866. " qos",
  867. " mac swap",
  868. " swap",
  869. " all"
  870. };
  871. static const int dbg_enable_mask_str_len[] = {
  872. 12, 4,
  873. 12, 4,
  874. 7, 7,
  875. 12, 3,
  876. 12, 3,
  877. 10, 5,
  878. 9, 4,
  879. 9, 5,
  880. 4
  881. };
  882. unsigned int dbg_enable_mask[] = {
  883. DBG_ENABLE_MASK_ERR,
  884. DBG_ENABLE_MASK_DEBUG_PRINT,
  885. DBG_ENABLE_MASK_ASSERT,
  886. DBG_ENABLE_MASK_DUMP_SKB_RX,
  887. DBG_ENABLE_MASK_DUMP_SKB_TX,
  888. DBG_ENABLE_MASK_DUMP_INIT,
  889. DBG_ENABLE_MASK_DUMP_QOS,
  890. DBG_ENABLE_MASK_MAC_SWAP,
  891. DBG_ENABLE_MASK_ALL
  892. };
  893. char str[2048];
  894. char *p;
  895. int len, rlen;
  896. int f_enable = 0;
  897. int i;
  898. len = count < sizeof(str) ? count : sizeof(str) - 1;
  899. rlen = len - copy_from_user(str, buf, len);
  900. while ( rlen && str[rlen - 1] <= ' ' )
  901. rlen--;
  902. str[rlen] = 0;
  903. for ( p = str; *p && *p <= ' '; p++, rlen-- );
  904. if ( !*p )
  905. return 0;
  906. // debugging feature for enter/leave showtime
  907. if ( strincmp(p, "enter", 5) == 0 && ifx_mei_atm_showtime_enter != NULL )
  908. ifx_mei_atm_showtime_enter(NULL, NULL);
  909. else if ( strincmp(p, "leave", 5) == 0 && ifx_mei_atm_showtime_exit != NULL )
  910. ifx_mei_atm_showtime_exit();
  911. if ( strincmp(p, "enable", 6) == 0 ) {
  912. p += 6;
  913. f_enable = 1;
  914. }
  915. else if ( strincmp(p, "disable", 7) == 0 ) {
  916. p += 7;
  917. f_enable = -1;
  918. }
  919. else if ( strincmp(p, "help", 4) == 0 || *p == '?' ) {
  920. printk("echo <enable/disable> [err/dbg/assert/rx/tx/init/qos/swap/all] > /proc/driver/ifx_ptm/dbg\n");
  921. }
  922. if ( f_enable ) {
  923. if ( *p == 0 ) {
  924. if ( f_enable > 0 )
  925. ifx_ptm_dbg_enable |= DBG_ENABLE_MASK_ALL & ~DBG_ENABLE_MASK_MAC_SWAP;
  926. else
  927. ifx_ptm_dbg_enable &= ~DBG_ENABLE_MASK_ALL | DBG_ENABLE_MASK_MAC_SWAP;
  928. }
  929. else {
  930. do {
  931. for ( i = 0; i < ARRAY_SIZE(dbg_enable_mask_str); i++ )
  932. if ( strincmp(p, dbg_enable_mask_str[i], dbg_enable_mask_str_len[i]) == 0 ) {
  933. if ( f_enable > 0 )
  934. ifx_ptm_dbg_enable |= dbg_enable_mask[i >> 1];
  935. else
  936. ifx_ptm_dbg_enable &= ~dbg_enable_mask[i >> 1];
  937. p += dbg_enable_mask_str_len[i];
  938. break;
  939. }
  940. } while ( i < ARRAY_SIZE(dbg_enable_mask_str) );
  941. }
  942. }
  943. return count;
  944. }
  945. #endif // defined(ENABLE_DBG_PROC) && ENABLE_DBG_PROC
  946. static INLINE int stricmp(const char *p1, const char *p2)
  947. {
  948. int c1, c2;
  949. while ( *p1 && *p2 )
  950. {
  951. c1 = *p1 >= 'A' && *p1 <= 'Z' ? *p1 + 'a' - 'A' : *p1;
  952. c2 = *p2 >= 'A' && *p2 <= 'Z' ? *p2 + 'a' - 'A' : *p2;
  953. if ( (c1 -= c2) )
  954. return c1;
  955. p1++;
  956. p2++;
  957. }
  958. return *p1 - *p2;
  959. }
  960. #if defined(ENABLE_DBG_PROC) && ENABLE_DBG_PROC
  961. static INLINE int strincmp(const char *p1, const char *p2, int n)
  962. {
  963. int c1 = 0, c2;
  964. while ( n && *p1 && *p2 )
  965. {
  966. c1 = *p1 >= 'A' && *p1 <= 'Z' ? *p1 + 'a' - 'A' : *p1;
  967. c2 = *p2 >= 'A' && *p2 <= 'Z' ? *p2 + 'a' - 'A' : *p2;
  968. if ( (c1 -= c2) )
  969. return c1;
  970. p1++;
  971. p2++;
  972. n--;
  973. }
  974. return n ? *p1 - *p2 : c1;
  975. }
  976. #endif
  977. static INLINE int ifx_ptm_version(char *buf)
  978. {
  979. int len = 0;
  980. unsigned int major, minor;
  981. ifx_ptm_get_fw_ver(&major, &minor);
  982. len += sprintf(buf + len, "PTM %d.%d.%d", IFX_PTM_VER_MAJOR, IFX_PTM_VER_MID, IFX_PTM_VER_MINOR);
  983. len += sprintf(buf + len, " PTM (E1) firmware version %d.%d\n", major, minor);
  984. return len;
  985. }
  986. static INLINE void check_parameters(void)
  987. {
  988. /* There is a delay between PPE write descriptor and descriptor is */
  989. /* really stored in memory. Host also has this delay when writing */
  990. /* descriptor. So PPE will use this value to determine if the write */
  991. /* operation makes effect. */
  992. if ( write_desc_delay < 0 )
  993. write_desc_delay = 0;
  994. /* Because of the limitation of length field in descriptors, the packet */
  995. /* size could not be larger than 64K minus overhead size. */
  996. if ( rx_max_packet_size < ETH_MIN_FRAME_LENGTH )
  997. rx_max_packet_size = ETH_MIN_FRAME_LENGTH;
  998. else if ( rx_max_packet_size > 65536 - 1 )
  999. rx_max_packet_size = 65536 - 1;
  1000. if ( dma_rx_descriptor_length < 2 )
  1001. dma_rx_descriptor_length = 2;
  1002. if ( dma_tx_descriptor_length < 2 )
  1003. dma_tx_descriptor_length = 2;
  1004. }
  1005. static INLINE int init_priv_data(void)
  1006. {
  1007. void *p;
  1008. int i;
  1009. struct rx_descriptor rx_desc = {0};
  1010. struct sk_buff *skb;
  1011. volatile struct rx_descriptor *p_rx_desc;
  1012. volatile struct tx_descriptor *p_tx_desc;
  1013. struct sk_buff **ppskb;
  1014. // clear ptm private data structure
  1015. memset(&g_ptm_priv_data, 0, sizeof(g_ptm_priv_data));
  1016. // allocate memory for RX descriptors
  1017. p = kzalloc(MAX_ITF_NUMBER * dma_rx_descriptor_length * sizeof(struct rx_descriptor) + DESC_ALIGNMENT, GFP_KERNEL);
  1018. if ( p == NULL )
  1019. return -1;
  1020. dma_cache_inv((unsigned long)p, MAX_ITF_NUMBER * dma_rx_descriptor_length * sizeof(struct rx_descriptor) + DESC_ALIGNMENT);
  1021. g_ptm_priv_data.rx_desc_base = p;
  1022. //p = (void *)((((unsigned int)p + DESC_ALIGNMENT - 1) & ~(DESC_ALIGNMENT - 1)) | KSEG1);
  1023. // allocate memory for TX descriptors
  1024. p = kzalloc(MAX_ITF_NUMBER * dma_tx_descriptor_length * sizeof(struct tx_descriptor) + DESC_ALIGNMENT, GFP_KERNEL);
  1025. if ( p == NULL )
  1026. return -1;
  1027. dma_cache_inv((unsigned long)p, MAX_ITF_NUMBER * dma_tx_descriptor_length * sizeof(struct tx_descriptor) + DESC_ALIGNMENT);
  1028. g_ptm_priv_data.tx_desc_base = p;
  1029. // allocate memroy for TX skb pointers
  1030. p = kzalloc(MAX_ITF_NUMBER * dma_tx_descriptor_length * sizeof(struct sk_buff *) + 4, GFP_KERNEL);
  1031. if ( p == NULL )
  1032. return -1;
  1033. dma_cache_wback_inv((unsigned long)p, MAX_ITF_NUMBER * dma_tx_descriptor_length * sizeof(struct sk_buff *) + 4);
  1034. g_ptm_priv_data.tx_skb_base = p;
  1035. p_rx_desc = (volatile struct rx_descriptor *)((((unsigned int)g_ptm_priv_data.rx_desc_base + DESC_ALIGNMENT - 1) & ~(DESC_ALIGNMENT - 1)) | KSEG1);
  1036. p_tx_desc = (volatile struct tx_descriptor *)((((unsigned int)g_ptm_priv_data.tx_desc_base + DESC_ALIGNMENT - 1) & ~(DESC_ALIGNMENT - 1)) | KSEG1);
  1037. ppskb = (struct sk_buff **)(((unsigned int)g_ptm_priv_data.tx_skb_base + 3) & ~3);
  1038. for ( i = 0; i < MAX_ITF_NUMBER; i++ ) {
  1039. g_ptm_priv_data.itf[i].rx_desc = &p_rx_desc[i * dma_rx_descriptor_length];
  1040. g_ptm_priv_data.itf[i].tx_desc = &p_tx_desc[i * dma_tx_descriptor_length];
  1041. g_ptm_priv_data.itf[i].tx_skb = &ppskb[i * dma_tx_descriptor_length];
  1042. }
  1043. rx_desc.own = 1;
  1044. rx_desc.c = 0;
  1045. rx_desc.sop = 1;
  1046. rx_desc.eop = 1;
  1047. rx_desc.byteoff = RX_HEAD_MAC_ADDR_ALIGNMENT;
  1048. rx_desc.id = 0;
  1049. rx_desc.err = 0;
  1050. rx_desc.datalen = rx_max_packet_size;
  1051. for ( i = 0; i < MAX_ITF_NUMBER * dma_rx_descriptor_length; i++ ) {
  1052. skb = alloc_skb_rx();
  1053. if ( skb == NULL )
  1054. return -1;
  1055. rx_desc.dataptr = ((unsigned int)skb->data >> 2) & 0x0FFFFFFF;
  1056. p_rx_desc[i] = rx_desc;
  1057. }
  1058. return 0;
  1059. }
  1060. static INLINE void clear_priv_data(void)
  1061. {
  1062. int i, j;
  1063. struct sk_buff *skb;
  1064. for ( i = 0; i < MAX_ITF_NUMBER; i++ ) {
  1065. if ( g_ptm_priv_data.itf[i].tx_skb != NULL ) {
  1066. for ( j = 0; j < dma_tx_descriptor_length; j++ )
  1067. if ( g_ptm_priv_data.itf[i].tx_skb[j] != NULL )
  1068. dev_kfree_skb_any(g_ptm_priv_data.itf[i].tx_skb[j]);
  1069. }
  1070. if ( g_ptm_priv_data.itf[i].rx_desc != NULL ) {
  1071. for ( j = 0; j < dma_rx_descriptor_length; j++ ) {
  1072. if ( g_ptm_priv_data.itf[i].rx_desc[j].sop || g_ptm_priv_data.itf[i].rx_desc[j].eop ) { // descriptor initialized
  1073. skb = get_skb_rx_pointer(g_ptm_priv_data.itf[i].rx_desc[j].dataptr);
  1074. dev_kfree_skb_any(skb);
  1075. }
  1076. }
  1077. }
  1078. }
  1079. if ( g_ptm_priv_data.rx_desc_base != NULL )
  1080. kfree(g_ptm_priv_data.rx_desc_base);
  1081. if ( g_ptm_priv_data.tx_desc_base != NULL )
  1082. kfree(g_ptm_priv_data.tx_desc_base);
  1083. if ( g_ptm_priv_data.tx_skb_base != NULL )
  1084. kfree(g_ptm_priv_data.tx_skb_base);
  1085. }
  1086. static INLINE void init_tables(void)
  1087. {
  1088. int i;
  1089. volatile unsigned int *p;
  1090. struct wrx_dma_channel_config rx_config = {0};
  1091. struct wtx_dma_channel_config tx_config = {0};
  1092. struct wrx_port_cfg_status rx_port_cfg = { 0 };
  1093. struct wtx_port_cfg tx_port_cfg = { 0 };
  1094. /*
  1095. * CDM Block 1
  1096. */
  1097. IFX_REG_W32(CDM_CFG_RAM1_SET(0x00) | CDM_CFG_RAM0_SET(0x00), CDM_CFG); // CDM block 1 must be data memory and mapped to 0x5000 (dword addr)
  1098. p = CDM_DATA_MEMORY(0, 0); // Clear CDM block 1
  1099. for ( i = 0; i < CDM_DATA_MEMORY_DWLEN; i++, p++ )
  1100. IFX_REG_W32(0, p);
  1101. /*
  1102. * General Registers
  1103. */
  1104. IFX_REG_W32(write_desc_delay, CFG_WAN_WRDES_DELAY);
  1105. IFX_REG_W32((1 << MAX_RX_DMA_CHANNEL_NUMBER) - 1, CFG_WRX_DMACH_ON);
  1106. IFX_REG_W32((1 << MAX_TX_DMA_CHANNEL_NUMBER) - 1, CFG_WTX_DMACH_ON);
  1107. IFX_REG_W32(8, CFG_WRX_LOOK_BITTH); // WAN RX EFM-TC Looking Threshold
  1108. IFX_REG_W32(eth_efmtc_crc_cfg, CFG_ETH_EFMTC_CRC);
  1109. /*
  1110. * WRX DMA Channel Configuration Table
  1111. */
  1112. rx_config.deslen = dma_rx_descriptor_length;
  1113. rx_port_cfg.mfs = ETH_MAX_FRAME_LENGTH;
  1114. rx_port_cfg.local_state = 0; // looking for sync
  1115. rx_port_cfg.partner_state = 0; // parter receiver is out of sync
  1116. for ( i = 0; i < MAX_RX_DMA_CHANNEL_NUMBER; i++ ) {
  1117. rx_config.desba = ((unsigned int)g_ptm_priv_data.itf[i].rx_desc >> 2) & 0x0FFFFFFF;
  1118. *WRX_DMA_CHANNEL_CONFIG(i) = rx_config;
  1119. rx_port_cfg.dmach = i;
  1120. *WRX_PORT_CONFIG(i) = rx_port_cfg;
  1121. }
  1122. /*
  1123. * WTX DMA Channel Configuration Table
  1124. */
  1125. tx_config.deslen = dma_tx_descriptor_length;
  1126. tx_port_cfg.tx_cwth1 = 5;
  1127. tx_port_cfg.tx_cwth2 = 4;
  1128. for ( i = 0; i < MAX_TX_DMA_CHANNEL_NUMBER; i++ ) {
  1129. tx_config.desba = ((unsigned int)g_ptm_priv_data.itf[i].tx_desc >> 2) & 0x0FFFFFFF;
  1130. *WTX_DMA_CHANNEL_CONFIG(i) = tx_config;
  1131. *WTX_PORT_CONFIG(i) = tx_port_cfg;
  1132. }
  1133. }
  1134. /*
  1135. * ####################################
  1136. * Global Function
  1137. * ####################################
  1138. */
  1139. static int ptm_showtime_enter(struct port_cell_info *port_cell, void *xdata_addr)
  1140. {
  1141. int i;
  1142. g_showtime = 1;
  1143. for ( i = 0; i < ARRAY_SIZE(g_net_dev); i++ )
  1144. netif_carrier_on(g_net_dev[i]);
  1145. printk("enter showtime\n");
  1146. return 0;
  1147. }
  1148. static int ptm_showtime_exit(void)
  1149. {
  1150. int i;
  1151. if ( !g_showtime )
  1152. return -1;
  1153. for ( i = 0; i < ARRAY_SIZE(g_net_dev); i++ )
  1154. netif_carrier_off(g_net_dev[i]);
  1155. g_showtime = 0;
  1156. printk("leave showtime\n");
  1157. return 0;
  1158. }
  1159. /*
  1160. * ####################################
  1161. * Init/Cleanup API
  1162. * ####################################
  1163. */
  1164. /*
  1165. * Description:
  1166. * Initialize global variables, PP32, comunication structures, register IRQ
  1167. * and register device.
  1168. * Input:
  1169. * none
  1170. * Output:
  1171. * 0 --- successful
  1172. * else --- failure, usually it is negative value of error code
  1173. */
  1174. static int ifx_ptm_init(void)
  1175. {
  1176. int ret;
  1177. struct port_cell_info port_cell = {0};
  1178. void *xdata_addr = NULL;
  1179. int i;
  1180. char ver_str[256];
  1181. check_parameters();
  1182. ret = init_priv_data();
  1183. if ( ret != 0 ) {
  1184. err("INIT_PRIV_DATA_FAIL");
  1185. goto INIT_PRIV_DATA_FAIL;
  1186. }
  1187. ifx_ptm_init_chip();
  1188. init_tables();
  1189. for ( i = 0; i < ARRAY_SIZE(g_net_dev); i++ ) {
  1190. g_net_dev[i] = alloc_netdev(0, g_net_dev_name[i], NET_NAME_UNKNOWN, ether_setup);
  1191. if ( g_net_dev[i] == NULL )
  1192. goto ALLOC_NETDEV_FAIL;
  1193. ptm_setup(g_net_dev[i], i);
  1194. }
  1195. for ( i = 0; i < ARRAY_SIZE(g_net_dev); i++ ) {
  1196. ret = register_netdev(g_net_dev[i]);
  1197. if ( ret != 0 )
  1198. goto REGISTER_NETDEV_FAIL;
  1199. }
  1200. /* register interrupt handler */
  1201. #if LINUX_VERSION_CODE >= KERNEL_VERSION(4,1,0)
  1202. ret = request_irq(PPE_MAILBOX_IGU1_INT, mailbox_irq_handler, 0, "ptm_mailbox_isr", &g_ptm_priv_data);
  1203. #else
  1204. ret = request_irq(PPE_MAILBOX_IGU1_INT, mailbox_irq_handler, IRQF_DISABLED, "ptm_mailbox_isr", &g_ptm_priv_data);
  1205. #endif
  1206. if ( ret ) {
  1207. if ( ret == -EBUSY ) {
  1208. err("IRQ may be occupied by other driver, please reconfig to disable it.");
  1209. }
  1210. else {
  1211. err("request_irq fail");
  1212. }
  1213. goto REQUEST_IRQ_PPE_MAILBOX_IGU1_INT_FAIL;
  1214. }
  1215. disable_irq(PPE_MAILBOX_IGU1_INT);
  1216. ret = ifx_pp32_start(0);
  1217. if ( ret ) {
  1218. err("ifx_pp32_start fail!");
  1219. goto PP32_START_FAIL;
  1220. }
  1221. IFX_REG_W32(0, MBOX_IGU1_IER);
  1222. IFX_REG_W32(~0, MBOX_IGU1_ISRC);
  1223. enable_irq(PPE_MAILBOX_IGU1_INT);
  1224. proc_file_create();
  1225. port_cell.port_num = 1;
  1226. ifx_mei_atm_showtime_check(&g_showtime, &port_cell, &xdata_addr);
  1227. ifx_mei_atm_showtime_enter = ptm_showtime_enter;
  1228. ifx_mei_atm_showtime_exit = ptm_showtime_exit;
  1229. ifx_ptm_version(ver_str);
  1230. printk(KERN_INFO "%s", ver_str);
  1231. printk("ifxmips_ptm: PTM init succeed\n");
  1232. return 0;
  1233. PP32_START_FAIL:
  1234. free_irq(PPE_MAILBOX_IGU1_INT, &g_ptm_priv_data);
  1235. REQUEST_IRQ_PPE_MAILBOX_IGU1_INT_FAIL:
  1236. i = ARRAY_SIZE(g_net_dev);
  1237. REGISTER_NETDEV_FAIL:
  1238. while ( i-- )
  1239. unregister_netdev(g_net_dev[i]);
  1240. i = ARRAY_SIZE(g_net_dev);
  1241. ALLOC_NETDEV_FAIL:
  1242. while ( i-- ) {
  1243. free_netdev(g_net_dev[i]);
  1244. g_net_dev[i] = NULL;
  1245. }
  1246. INIT_PRIV_DATA_FAIL:
  1247. clear_priv_data();
  1248. printk("ifxmips_ptm: PTM init failed\n");
  1249. return ret;
  1250. }
  1251. /*
  1252. * Description:
  1253. * Release memory, free IRQ, and deregister device.
  1254. * Input:
  1255. * none
  1256. * Output:
  1257. * none
  1258. */
  1259. static void __exit ifx_ptm_exit(void)
  1260. {
  1261. int i;
  1262. ifx_mei_atm_showtime_enter = NULL;
  1263. ifx_mei_atm_showtime_exit = NULL;
  1264. proc_file_delete();
  1265. ifx_pp32_stop(0);
  1266. free_irq(PPE_MAILBOX_IGU1_INT, &g_ptm_priv_data);
  1267. for ( i = 0; i < ARRAY_SIZE(g_net_dev); i++ )
  1268. unregister_netdev(g_net_dev[i]);
  1269. for ( i = 0; i < ARRAY_SIZE(g_net_dev); i++ ) {
  1270. free_netdev(g_net_dev[i]);
  1271. g_net_dev[i] = NULL;
  1272. }
  1273. ifx_ptm_uninit_chip();
  1274. clear_priv_data();
  1275. }
  1276. module_init(ifx_ptm_init);
  1277. module_exit(ifx_ptm_exit);