1 /******************************************************************************
3 ** FILE NAME : ifxmips_mei_core.c
9 ** DESCRIPTION : MEI Driver
10 ** COPYRIGHT : Copyright (c) 2006
11 ** Infineon Technologies AG
12 ** Am Campeon 1-12, 85579 Neubiberg, Germany
14 ** This program is free software; you can redistribute it and/or modify
15 ** it under the terms of the GNU General Public License as published by
16 ** the Free Software Foundation; either version 2 of the License, or
17 ** (at your option) any later version.
20 ** $Version $Date $Author $Comment
21 1.00.01 TC Chen Fixed cell rate calculation issue
22 Fixed pvovider_id of adsl mib swapping issue
23 1.00.02 TC Chen Added L3 Low Poewr Mode support.
24 1.00.03 TC Chen Fixed Clear Eoc transmit issue.
25 1.00.04 31/08/2006 TC Chen Add ADSL Link/Data Led
27 Add AUTOBOOT_ENABLE_SET ioctl for autoboot
29 Fix fast path cell rate calculation
30 1.00.05 25/09/2006 TC Chen Fix ATM QoS fail on interface 0(fast path).
31 1.00.06 02/10/2006 TC Chen Change ifxmips_ppe_set_cell_rate to
33 Add ATM Led callback function
34 1.00.07 13/11/2006 TC Chen Invert ADSL Link LED Signal
35 1.00.08 08/12/2006 TC Chen Fix loop diagnostic warning message issue
36 1.00.09 20/12/2006 TC Chen Workaround for USB OC interrupt which is trigegred once DSL reset
37 ******************************************************************************/
40 * ===========================================================================
42 * ===========================================================================
45 #include <asm/ifxmips/ifxmips_mei_linux.h>
47 char IFXMIPS_MEI_VERSION[] = "1.00.09";
49 #define IFXMIPS_MEI_CMV_EXTRA //WINHOST debug
50 #define IFX_ADSL_L3_MODE_SUPPORT //L3 Low Power Mode Support
51 #define IFX_ADSL_DUAL_LATENCY_SUPPORT
52 #undef IFXMIPS_CLEAR_EOC //clear eoc support
54 // for ARC memory access
55 #define WHILE_DELAY 20000
56 #if defined(IFXMIPS_PORT_RTEMS)
57 #undef IFXMIPS_DMA_DEBUG_MUTEX
59 #define IFXMIPS_DMA_DEBUG_MUTEX
67 #undef DFE_LOOPBACK // testing code //undefined by Henry , start to real link test.
71 //#define DFE_MEM_TEST
72 //#define DFE_PING_TEST
73 #define DFE_ATM_LOOPBACK
76 #undef DATA_LED_ON_MODE
77 #define DATA_LED_SUPPORT // support adsl data led
78 //#define DATA_LED_ADSL_FW_HANDLE // adsl data led handle by firmware
79 #define CONFIG_IFXMIPS_MEI_LED // adsl led support
82 #define SDRAM_SEGMENT_SIZE (64*1024)
83 // Number of Bar registers
84 #define MAX_BAR_REGISTERS (17)
86 #define XDATA_REGISTER (15)
88 #define IFXMIPS_MEI_DEVNAME "mei"
92 #define UINT32 unsigned long
95 #include "dsp_xmem_arb_rand_em.h"
98 #include "aai_mem_test.h"
100 #ifdef DFE_ATM_LOOPBACK
101 #include "aai_lpbk_dyn_rate.h"
105 /************************************************************************
106 * Function declaration
107 ************************************************************************/
108 static MEI_ERROR meiDMAWrite (u32 destaddr, u32 * databuff, u32 databuffsize);
109 static MEI_ERROR meiDMARead (u32 srcaddr, u32 * databuff, u32 databuffsize);
110 static void meiControlModeSwitch (int mode);
111 static void meiPollForDbgDone (void);
112 static MEI_ERROR _meiDebugLongWordRead (u32 DEC_mode, u32 address,
114 static MEI_ERROR _meiDebugLongWordWrite (u32 DEC_mode, u32 address, u32 data);
115 MEI_ERROR meiDebugWrite (u32 destaddr, u32 * databuff, u32 databuffsize);
116 static MEI_ERROR meiDebugRead (u32 srcaddr, u32 * databuff, u32 databuffsize);
117 static MEI_ERROR meiMailboxWrite (u16 * msgsrcbuffer, u16 msgsize);
118 static MEI_ERROR meiDownloadBootCode (void);
119 static MEI_ERROR meiHaltArc (void);
120 static MEI_ERROR meiRunArc (void);
121 static MEI_ERROR meiRunAdslModem (void);
122 static int meiGetPage (u32 Page, u32 data, u32 MaxSize, u32 * Buffer,
124 void makeCMV (u8 opcode, u8 group, u16 address, u16 index, int size,
125 u16 * data, u16 * CMVMSG);
126 MEI_ERROR meiCMV (u16 * request, int reply, u16 * response);
127 static void meiMailboxInterruptsDisable (void);
128 static void meiMailboxInterruptsEnable (void);
129 static int update_bar_register (int nTotalBar);
130 static int free_image_buffer (int type);
131 static int alloc_processor_memory (unsigned long size,
132 smmu_mem_info_t * adsl_mem_info);
133 ssize_t mei_write (MEI_file_t * filp, char *buf, size_t size, loff_t * loff);
134 int mei_ioctl (MEI_inode_t * ino, MEI_file_t * fil, unsigned int command,
137 #ifdef CONFIG_PROC_FS
138 static int proc_read (struct file *file, char *buf, size_t nbytes,
140 static ssize_t proc_write (struct file *file, const char *buffer,
141 size_t count, loff_t * ppos);
144 #ifdef CONFIG_IFXMIPS_MEI_MIB
145 int mei_mib_ioctl (MEI_inode_t * ino, MEI_file_t * fil, unsigned int command,
147 int mei_mib_adsl_link_up (void);
148 int mei_mib_adsl_link_down (void);
149 int ifxmips_mei_mib_init (void);
150 int ifxmips_mei_mib_cleanup (void);
152 #if defined(CONFIG_IFXMIPS_MEI_LED) && defined(DATA_LED_SUPPORT)
153 static int ifxmips_mei_led_init (void);
154 static int ifxmips_mei_led_cleanup (void);
155 static int adsl_led_flash_task (void);
158 #ifdef IFXMIPS_CLEAR_EOC
159 extern void ifx_push_eoc (struct sk_buff *pkt);
162 /************************************************************************
163 * variable declaration
164 ************************************************************************/
165 static smmu_mem_info_t adsl_mem_info[MAX_BAR_REGISTERS];
166 static unsigned long image_size = 0;
167 static struct timeval time_disconnect, time_showtime;
168 static u16 unavailable_seconds = 0;
169 #ifdef IFXMIPS_CLEAR_EOC
170 static wait_queue_head_t wait_queue_hdlc_poll; ///clear eoc
173 static int showtime_lock_flag = 0;
174 static int quiet_mode_flag = 0;
177 static int major = IFXMIPS_MEI_MAJOR;
178 MEI_mutex_t mei_sema;
180 // Mei to ARC CMV count, reply count, ARC Indicator count
181 static int indicator_count = 0;
182 static int cmv_count = 0;
183 static int reply_count = 0;
184 static u16 Recent_indicator[MSG_LENGTH];
185 static int reset_arc_flag = 0;
187 // Used in interrupt handler as flags
188 static int arcmsgav = 0;
189 static int cmv_reply = 0;
190 static int cmv_waiting = 0;
191 static int modem_ready = 0;
192 // to wait for arc cmv reply, sleep on wait_queue_arcmsgav;
193 static wait_queue_head_t wait_queue_arcmsgav;
195 // CMV mailbox messages
196 // ARC to MEI message
197 static u16 CMV_RxMsg[MSG_LENGTH] __attribute__ ((aligned (4)));
198 // MEI to ARC message
199 static u16 CMV_TxMsg[MSG_LENGTH] __attribute__ ((aligned (4)));
201 static u32 *mei_arc_swap_buff = NULL; // holding swap pages
202 static ARC_IMG_HDR *img_hdr;
203 static int arc_halt_flag = 0;
204 static int nBar = 0; // total bars to be used.
206 static u32 loop_diagnostics_mode = 0;
207 wait_queue_head_t wait_queue_loop_diagnostic;
208 int loop_diagnostics_completed = 0;
209 u32 adsl_mode, adsl_mode_extend; // adsl mode : adsl/ 2/ 2+
210 static int autoboot_enable_flag = 0;
212 #ifdef IFX_ADSL_DUAL_LATENCY_SUPPORT
213 static u8 bDualLatency = 0;
216 #ifdef IFXMIPS_CLEAR_EOC
217 static u16 ceoc_read_idx = 0;
220 #ifdef IFX_ADSL_L3_MODE_SUPPORT
221 static wait_queue_head_t wait_queue_l3; // l3 power mode
222 static int l3_shutdown = 0;
223 int get_l3_power_status (void);
226 #if defined(CONFIG_IFXMIPS_MEI_LED) && defined(DATA_LED_SUPPORT)
227 int led_status_on = 0, led_need_to_flash = 0;
228 static int stop_led_module = 0; //wakeup and clean led module
229 static wait_queue_head_t wait_queue_led_polling; // adsl led
232 static struct file_operations mei_operations = {
237 #ifdef CONFIG_PROC_FS
238 static struct proc_dir_entry *meidir;
239 static struct file_operations proc_operations = {
243 static reg_entry_t regs[PROC_ITEMS]; //total items to be monitored by /proc/mei
244 #define NUM_OF_REG_ENTRY (sizeof(regs)/sizeof(reg_entry_t))
245 #endif //#ifdef CONFIG_PROC_FS
248 unsigned char got_int = 0;
251 ///////////////// mei access Rd/Wr methods ///////////////
253 * Write a value to register
254 * This function writes a value to ifxmips register
256 * \param ul_address The address to write
257 * \param ul_data The value to write
261 meiLongwordWrite (u32* ul_address, u32 ul_data)
263 ifxmips_w32(ul_data, ul_address);
266 } // end of "meiLongwordWrite(..."
269 * Read the ifxmips register
270 * This function read the value from ifxmips register
272 * \param ul_address The address to write
273 * \param pul_data Pointer to the data
277 meiLongwordRead (u32* ul_address, u32 * pul_data)
279 //*pul_data = *((volatile u32 *)ul_address);
280 *pul_data = ifxmips_r32(ul_address);
283 } // end of "meiLongwordRead(..."
286 * Write several DWORD datas to ARC memory via ARC DMA interface
287 * This function writes several DWORD datas to ARC memory via DMA interface.
289 * \param destaddr The address to write
290 * \param databuff Pointer to the data buffer
291 * \param databuffsize Number of DWORDs to write
292 * \return MEI_SUCCESS or MEI_FAILURE
296 meiDMAWrite (u32 destaddr, u32 * databuff, u32 databuffsize)
305 #ifdef IFXMIPS_DMA_DEBUG_MUTEX
309 //printk("destaddr=%X,size=%d\n",destaddr,databuffsize);
310 // Set the write transfer address
311 meiLongwordWrite (MEI_XFR_ADDR, destaddr);
313 // Write the data pushed across DMA
314 while (databuffsize--) {
316 if (databuff == (u32 *) CMV_TxMsg)
317 MEI_HALF_WORD_SWAP (temp);
318 meiLongwordWrite (MEI_DATA_XFR, temp);
320 } // end of "while(..."
322 #ifdef IFXMIPS_DMA_DEBUG_MUTEX
323 MEI_UNLOCKINT (flags);
328 } // end of "meiDMAWrite(..."
331 * Read several DWORD datas from ARC memory via ARC DMA interface
332 * This function reads several DWORD datas from ARC memory via DMA interface.
334 * \param srcaddr The address to read
335 * \param databuff Pointer to the data buffer
336 * \param databuffsize Number of DWORDs to read
337 * \return MEI_SUCCESS or MEI_FAILURE
341 meiDMARead (u32 srcaddr, u32 * databuff, u32 databuffsize)
345 #ifdef IFXMIPS_DMA_DEBUG_MUTEX
348 //printk("destaddr=%X,size=%X\n",srcaddr,databuffsize);
352 #ifdef IFXMIPS_DMA_DEBUG_MUTEX
356 // Set the read transfer address
357 meiLongwordWrite (MEI_XFR_ADDR, srcaddr);
359 // Read the data popped across DMA
360 while (databuffsize--) {
361 meiLongwordRead (MEI_DATA_XFR, &temp);
362 if (databuff == (u32 *) CMV_RxMsg) // swap half word
363 MEI_HALF_WORD_SWAP (temp);
366 } // end of "while(..."
368 #ifdef IFXMIPS_DMA_DEBUG_MUTEX
369 MEI_UNLOCKINT (flags);
374 } // end of "meiDMARead(..."
377 * Switch the ARC control mode
378 * This function switchs the ARC control mode to JTAG mode or MEI mode
380 * \param mode The mode want to switch: JTAG_MASTER_MODE or MEI_MASTER_MODE.
384 meiControlModeSwitch (int mode)
387 meiLongwordRead ( MEI_DBG_MASTER, &temp);
389 case JTAG_MASTER_MODE:
390 temp &= ~(HOST_MSTR);
392 case MEI_MASTER_MODE:
396 printk ("meiControlModeSwitch: unkonwn mode [%d]\n",
400 meiLongwordWrite (MEI_DBG_MASTER, temp);
404 * Poll for transaction complete signal
405 * This function polls and waits for transaction complete signal.
410 meiPollForDbgDone (void)
414 while (i < WHILE_DELAY) {
415 meiLongwordRead (ARC_TO_MEI_INT, &query);
416 query &= (ARC_TO_MEI_DBG_DONE);
420 if (i == WHILE_DELAY) {
421 printk ("\n\n PollforDbg fail");
424 meiLongwordWrite ( ARC_TO_MEI_INT, ARC_TO_MEI_DBG_DONE); // to clear this interrupt
425 } // end of "meiPollForDbgDone(..."
428 * ARC Debug Memory Access for a single DWORD reading.
429 * This function used for direct, address-based access to ARC memory.
431 * \param DEC_mode ARC memory space to used
432 * \param address Address to read
433 * \param data Pointer to data
434 * \return MEI_SUCCESS or MEI_FAILURE
438 _meiDebugLongWordRead (u32 DEC_mode, u32 address, u32 * data)
440 meiLongwordWrite ( MEI_DEBUG_DEC, DEC_mode);
441 meiLongwordWrite ( MEI_DEBUG_RAD, address);
442 meiPollForDbgDone ();
443 meiLongwordRead (MEI_DEBUG_DATA, data);
448 * ARC Debug Memory Access for a single DWORD writing.
449 * This function used for direct, address-based access to ARC memory.
451 * \param DEC_mode ARC memory space to used
452 * \param address The address to write
453 * \param data The data to write
454 * \return MEI_SUCCESS or MEI_FAILURE
458 _meiDebugLongWordWrite (u32 DEC_mode, u32 address, u32 data)
460 meiLongwordWrite (MEI_DEBUG_DEC, DEC_mode);
461 meiLongwordWrite (MEI_DEBUG_WAD, address);
462 meiLongwordWrite (MEI_DEBUG_DATA, data);
463 meiPollForDbgDone ();
468 * ARC Debug Memory Access for writing.
469 * This function used for direct, address-based access to ARC memory.
471 * \param destaddr The address to ead
472 * \param databuffer Pointer to data
473 * \param databuffsize The number of DWORDs to read
474 * \return MEI_SUCCESS or MEI_FAILURE
479 meiDebugWrite (u32 destaddr, u32 * databuff, u32 databuffsize)
485 #ifdef IFXMIPS_DMA_DEBUG_MUTEX
489 #ifdef IFXMIPS_DMA_DEBUG_MUTEX
493 // Open the debug port before DMP memory write
494 meiControlModeSwitch (MEI_MASTER_MODE);
496 meiLongwordWrite (MEI_DEBUG_DEC, MEI_DEBUG_DEC_DMP1_MASK);
498 // For the requested length, write the address and write the data
501 for (i = 0; i < databuffsize; i++) {
503 _meiDebugLongWordWrite (MEI_DEBUG_DEC_DMP1_MASK, address,
507 } // end of "for(..."
509 // Close the debug port after DMP memory write
510 meiControlModeSwitch (JTAG_MASTER_MODE);
512 #ifdef IFXMIPS_DMA_DEBUG_MUTEX
513 MEI_UNLOCKINT (flags);
519 } // end of "meiDebugWrite(..."
522 * ARC Debug Memory Access for reading.
523 * This function used for direct, address-based access to ARC memory.
525 * \param srcaddr The address to read
526 * \param databuffer Pointer to data
527 * \param databuffsize The number of DWORDs to read
528 * \return MEI_SUCCESS or MEI_FAILURE
532 meiDebugRead (u32 srcaddr, u32 * databuff, u32 databuffsize)
538 #ifdef IFXMIPS_DMA_DEBUG_MUTEX
542 #ifdef IFXMIPS_DMA_DEBUG_MUTEX
546 // Open the debug port before DMP memory read
547 meiControlModeSwitch (MEI_MASTER_MODE);
549 meiLongwordWrite (MEI_DEBUG_DEC, MEI_DEBUG_DEC_DMP1_MASK);
551 // For the requested length, write the address and read the data
554 for (i = 0; i < databuffsize; i++) {
555 _meiDebugLongWordRead (MEI_DEBUG_DEC_DMP1_MASK, address,
560 } // end of "for(..."
562 // Close the debug port after DMP memory read
563 meiControlModeSwitch (JTAG_MASTER_MODE);
565 #ifdef IFXMIPS_DMA_DEBUG_MUTEX
566 MEI_UNLOCKINT (flags);
572 } // end of "meiDebugRead(..."
575 * Send a message to ARC MailBox.
576 * This function sends a message to ARC Mailbox via ARC DMA interface.
578 * \param msgsrcbuffer Pointer to message.
579 * \param msgsize The number of words to write.
580 * \return MEI_SUCCESS or MEI_FAILURE
584 meiMailboxWrite (u16 * msgsrcbuffer, u16 msgsize)
587 u32 arc_mailbox_status = 0x0;
589 MEI_ERROR meiMailboxError = MEI_SUCCESS;
593 meiDMAWrite (MEI_TO_ARC_MAILBOX, (u32 *) msgsrcbuffer,
596 meiDMAWrite (MEI_TO_ARC_MAILBOXR, (u32 *) (&temp), 1);
598 // Notify arc that mailbox write completed
600 meiLongwordWrite (MEI_TO_ARC_INT, MEI_TO_ARC_MSGAV);
603 while (i < WHILE_DELAY) { // wait for ARC to clear the bit
604 meiLongwordRead ( MEI_TO_ARC_INT, &arc_mailbox_status);
605 if ((arc_mailbox_status & MEI_TO_ARC_MSGAV) !=
609 if (i == WHILE_DELAY) {
611 ("\n\n MEI_TO_ARC_MSGAV not cleared by ARC");
612 meiMailboxError = MEI_FAILURE;
617 return meiMailboxError;
619 } // end of "meiMailboxWrite(..."
622 * Read a message from ARC MailBox.
623 * This function reads a message from ARC Mailbox via ARC DMA interface.
625 * \param msgsrcbuffer Pointer to message.
626 * \param msgsize The number of words to read
627 * \return MEI_SUCCESS or MEI_FAILURE
631 meiMailboxRead (u16 * msgdestbuffer, u16 msgsize)
633 MEI_ERROR meiMailboxError = MEI_SUCCESS;
636 meiDMARead (ARC_TO_MEI_MAILBOX, (u32 *) msgdestbuffer,
639 // Notify arc that mailbox read completed
640 meiLongwordWrite (ARC_TO_MEI_INT, ARC_TO_MEI_MSGAV);
643 return meiMailboxError;
645 } // end of "meiMailboxRead(..."
648 * Download boot pages to ARC.
649 * This function downloads boot pages to ARC.
651 * \return MEI_SUCCESS or MEI_FAILURE
655 meiDownloadBootPages (void)
662 ** DMA the boot code page(s)
665 for (boot_loop = 1; boot_loop < le32_to_cpu (img_hdr->count);
668 for (boot_loop = 1; boot_loop < (img_hdr->count); boot_loop++)
672 if (le32_to_cpu (img_hdr->page[boot_loop].p_size) & BOOT_FLAG)
674 if ((img_hdr->page[boot_loop].p_size) & BOOT_FLAG)
678 meiGetPage (boot_loop, GET_PROG, MAXSWAPSIZE,
679 mei_arc_swap_buff, &dest_addr);
681 meiDMAWrite (dest_addr, mei_arc_swap_buff,
686 if (le32_to_cpu (img_hdr->page[boot_loop].d_size) & BOOT_FLAG)
688 if ((img_hdr->page[boot_loop].d_size) & BOOT_FLAG)
692 meiGetPage (boot_loop, GET_DATA, MAXSWAPSIZE,
693 mei_arc_swap_buff, &dest_addr);
695 meiDMAWrite (dest_addr, mei_arc_swap_buff,
707 mei_fuse_rar_init (void)
710 meiDMAWrite (IRAM0_BASE, &data, 1);
711 meiDMAWrite (IRAM0_BASE + 4, &data, 1);
712 meiDMAWrite (IRAM1_BASE, &data, 1);
713 meiDMAWrite (IRAM1_BASE + 4, &data, 1);
714 meiDMAWrite (BRAM_BASE, &data, 1);
715 meiDMAWrite (BRAM_BASE + 4, &data, 1);
716 meiDMAWrite (ADSL_DILV_BASE, &data, 1);
717 meiDMAWrite (ADSL_DILV_BASE + 4, &data, 1);
726 u32 reg_data, fuse_value;
728 meiLongwordRead ( IFXMIPS_RCU_RST, ®_data);
729 while ((reg_data & 0x10000000) == 0) {
730 meiLongwordRead ( IFXMIPS_RCU_RST, ®_data);
733 /* 0x4000 translate to about 16 ms@111M, so should be enough */
737 // STEP a: Prepare memory for external accesses
738 // Write fuse_en bit24
739 meiLongwordRead (IFXMIPS_RCU_RST, ®_data);
740 meiLongwordWrite (IFXMIPS_RCU_RST, reg_data | (1 << 24));
742 mei_fuse_rar_init ();
743 for (i = 0; i < 4; i++) {
744 meiLongwordRead((u32*)(IFXMIPS_FUSE_BASE_ADDR + (i * 4)), &fuse_value);
745 switch (fuse_value & 0xF0000) {
748 ((fuse_value & RX_DILV_ADDR_BIT_MASK) |
749 (RX_DILV_ADDR_BIT_MASK + 0x1));
750 meiDMAWrite (ADSL_DILV_BASE, ®_data, 1);
754 ((fuse_value & RX_DILV_ADDR_BIT_MASK) |
755 (RX_DILV_ADDR_BIT_MASK + 0x1));
756 meiDMAWrite (ADSL_DILV_BASE + 4, ®_data, 1);
760 ((fuse_value & IRAM0_ADDR_BIT_MASK) |
761 (IRAM0_ADDR_BIT_MASK + 0x1));
762 meiDMAWrite (IRAM0_BASE, ®_data, 1);
766 ((fuse_value & IRAM0_ADDR_BIT_MASK) |
767 (IRAM0_ADDR_BIT_MASK + 0x1));
768 meiDMAWrite (IRAM0_BASE + 4, ®_data, 1);
772 ((fuse_value & IRAM1_ADDR_BIT_MASK) |
773 (IRAM1_ADDR_BIT_MASK + 0x1));
774 meiDMAWrite (IRAM1_BASE, ®_data, 1);
778 ((fuse_value & IRAM1_ADDR_BIT_MASK) |
779 (IRAM1_ADDR_BIT_MASK + 0x1));
780 meiDMAWrite (IRAM1_BASE + 4, ®_data, 1);
784 ((fuse_value & BRAM_ADDR_BIT_MASK) |
785 (BRAM_ADDR_BIT_MASK + 0x1));
786 meiDMAWrite (BRAM_BASE, ®_data, 1);
790 ((fuse_value & BRAM_ADDR_BIT_MASK) |
791 (BRAM_ADDR_BIT_MASK + 0x1));
792 meiDMAWrite (BRAM_BASE + 4, ®_data, 1);
794 default: // PPE efuse
798 meiLongwordRead (IFXMIPS_RCU_RST, ®_data);
799 meiLongwordWrite (IFXMIPS_RCU_RST, reg_data & 0xF7FFFFFF);
803 * Download boot code to ARC.
804 * This function downloads boot code to ARC.
806 * \return MEI_SUCCESS or MEI_FAILURE
810 meiDownloadBootCode (void)
812 u32 arc_debug_data = ACL_CLK_MODE_ENABLE; //0x10
814 meiMailboxInterruptsDisable ();
816 // Switch arc control from JTAG mode to MEI mode
817 meiControlModeSwitch (MEI_MASTER_MODE);
818 //enable ac_clk signal
819 _meiDebugLongWordRead (MEI_DEBUG_DEC_DMP1_MASK, CRI_CCR0,
821 arc_debug_data |= ACL_CLK_MODE_ENABLE;
822 _meiDebugLongWordWrite (MEI_DEBUG_DEC_DMP1_MASK, CRI_CCR0,
824 //Switch arc control from MEI mode to JTAG mode
825 meiControlModeSwitch (JTAG_MASTER_MODE);
827 mei_fuse_prg (); //program fuse rar
829 meiDownloadBootPages ();
833 } // end of "meiDownloadBootCode(..."
839 * This function halts the ARC.
841 * \return MEI_SUCCESS or MEI_FAILURE
847 u32 arc_debug_data = 0x0;
849 // Switch arc control from JTAG mode to MEI mode
850 meiControlModeSwitch (MEI_MASTER_MODE);
851 _meiDebugLongWordRead (MEI_DEBUG_DEC_AUX_MASK, ARC_DEBUG,
853 arc_debug_data |= (BIT1);
854 _meiDebugLongWordWrite (MEI_DEBUG_DEC_AUX_MASK, ARC_DEBUG,
856 // Switch arc control from MEI mode to JTAG mode
857 meiControlModeSwitch (JTAG_MASTER_MODE);
864 } // end of "meiHalt(..."
868 * This function runs the ARC.
870 * \return MEI_SUCCESS or MEI_FAILURE
876 u32 arc_debug_data = 0x0;
878 // Switch arc control from JTAG mode to MEI mode- write '1' to bit0
879 meiControlModeSwitch (MEI_MASTER_MODE);
880 _meiDebugLongWordRead (MEI_DEBUG_DEC_AUX_MASK, AUX_STATUS,
883 // Write debug data reg with content ANDd with 0xFDFFFFFF (halt bit cleared)
884 arc_debug_data &= ~(BIT25);
885 _meiDebugLongWordWrite (MEI_DEBUG_DEC_AUX_MASK, AUX_STATUS,
888 // Switch arc control from MEI mode to JTAG mode- write '0' to bit0
889 meiControlModeSwitch (JTAG_MASTER_MODE);
890 // Enable mask for arc codeswap interrupts
891 meiMailboxInterruptsEnable ();
897 } // end of "meiActivate(..."
901 * This function resets the ARC.
903 * \return MEI_SUCCESS or MEI_FAILURE
910 u32 arc_debug_data = 0;
915 meiLongwordRead (IFXMIPS_RCU_RST, &arc_debug_data);
916 meiLongwordWrite (IFXMIPS_RCU_RST,
917 arc_debug_data | IFXMIPS_RCU_RST_REQ_DFE |
918 IFXMIPS_RCU_RST_REQ_AFE);
919 meiLongwordWrite (IFXMIPS_RCU_RST, arc_debug_data);
921 meiLongwordWrite(MEI_RST_CONTROL, MEI_SOFT_RESET);
922 meiLongwordWrite(MEI_RST_CONTROL, 0);
924 meiMailboxInterruptsDisable ();
925 MEI_MUTEX_INIT (mei_sema, 1);
932 * Reset the ARC, download boot codes, and run the ARC.
933 * This function resets the ARC, downloads boot codes to ARC, and runs the ARC.
935 * \return MEI_SUCCESS or MEI_FAILURE
939 meiRunAdslModem (void)
941 int nSize = 0, idx = 0;
943 img_hdr = (ARC_IMG_HDR *) adsl_mem_info[0].address;
944 #if defined(HEADER_SWAP)
945 if ((img_hdr->count) * sizeof (ARC_SWP_PAGE_HDR) > SDRAM_SEGMENT_SIZE)
946 #else //define(HEADER_SWAP)
947 if (le32_to_cpu (img_hdr->count) * sizeof (ARC_SWP_PAGE_HDR) >
949 #endif //define(HEADER_SWAP)
952 ("segment_size is smaller than firmware header size\n");
956 for (idx = 0; idx < MAX_BAR_REGISTERS; idx++) {
957 nSize += adsl_mem_info[idx].nCopy;
959 if (nSize != image_size) {
961 ("Firmware download is not completed. \nPlease download firmware again!\n");
966 if (reset_arc_flag == 0) {
970 meiControlModeSwitch (MEI_MASTER_MODE);
971 //enable ac_clk signal
972 _meiDebugLongWordRead (MEI_DEBUG_DEC_DMP1_MASK, CRI_CCR0,
974 arc_debug_data |= ACL_CLK_MODE_ENABLE;
975 _meiDebugLongWordWrite (MEI_DEBUG_DEC_DMP1_MASK, CRI_CCR0,
977 meiControlModeSwitch (JTAG_MASTER_MODE);
979 update_bar_register (nBar);
982 if (arc_halt_flag == 0) {
985 printk ("Starting to meiDownloadBootCode\n");
987 meiDownloadBootCode();
989 // 1.00.09 20/12/2006 TC Chen
990 // disable USB OC interrupt, reset DSL chip will triger OC interrupt
991 disable_irq(IFXMIPS_USB_OC_INT);
995 MEI_WAIT (100); //wait 100ms
997 //1.00.09 20/12/2006 TC Chen
998 // restore USB OC interrupt
999 MEI_MASK_AND_ACK_IRQ(IFXMIPS_USB_OC_INT);
1000 enable_irq(IFXMIPS_USB_OC_INT);
1002 if (modem_ready != 1) {
1003 printk ("Running ADSL modem firmware fail!\n");
1012 * Get the page's data pointer
1013 * This function caculats the data address from the firmware header.
1015 * \param Page The page number.
1016 * \param data Data page or program page.
1017 * \param MaxSize The maximum size to read.
1018 * \param Buffer Pointer to data.
1019 * \param Dest Pointer to the destination address.
1020 * \return The number of bytes to read.
1024 meiGetPage (u32 Page, u32 data, u32 MaxSize, u32 * Buffer, u32 * Dest)
1029 u32 idx, offset, nBar = 0;
1031 if (Page > img_hdr->count)
1034 ** Get program or data size, depending on "data" flag
1038 GET_DATA) ? le32_to_cpu (img_hdr->page[Page].
1039 d_size) : le32_to_cpu (img_hdr->
1044 GET_DATA) ? (img_hdr->page[Page].d_size) : (img_hdr->
1048 size &= BOOT_FLAG_MASK; // Clear boot bit!
1055 ** Get program or data offset, depending on "data" flag
1058 i = data ? le32_to_cpu (img_hdr->page[Page].
1059 d_offset) : le32_to_cpu (img_hdr->page[Page].
1062 i = data ? (img_hdr->page[Page].d_offset) : (img_hdr->page[Page].
1067 ** Copy data/program to buffer
1070 idx = i / SDRAM_SEGMENT_SIZE;
1071 offset = i % SDRAM_SEGMENT_SIZE;
1072 p = (u32 *) ((u8 *) adsl_mem_info[idx].address + offset);
1074 for (i = 0; i < size; i++) {
1075 if (offset + i * 4 - (nBar * SDRAM_SEGMENT_SIZE) >=
1076 SDRAM_SEGMENT_SIZE) {
1080 KSEG1ADDR ((u32) adsl_mem_info[idx].
1086 Buffer[i] = le32_to_cpu (Buffer[i]);
1092 ** Pass back data/program destination address
1095 *Dest = data ? le32_to_cpu (img_hdr->page[Page].
1096 d_dest) : le32_to_cpu (img_hdr->
1099 *Dest = data ? (img_hdr->page[Page].d_dest) : (img_hdr->page[Page].
1106 ////////////////makeCMV(Opcode, Group, Address, Index, Size, Data), CMV in u16 TxMessage[MSG_LENGTH]///////////////////////////
1109 * Compose a message.
1110 * This function compose a message from opcode, group, address, index, size, and data
1112 * \param opcode The message opcode
1113 * \param group The message group number
1114 * \param address The message address.
1115 * \param index The message index.
1116 * \param size The number of words to read/write.
1117 * \param data The pointer to data.
1118 * \param CMVMSG The pointer to message buffer.
1122 makeCMV (u8 opcode, u8 group, u16 address, u16 index, int size, u16 * data,
1125 memset (CMVMSG, 0, MSG_LENGTH * 2);
1126 CMVMSG[0] = (opcode << 4) + (size & 0xf);
1127 CMVMSG[1] = (((index == 0) ? 0 : 1) << 7) + (group & 0x7f);
1128 CMVMSG[2] = address;
1130 if (opcode == H2D_CMV_WRITE)
1131 memcpy (CMVMSG + 4, data, size * 2);
1136 * Send a message to ARC and read the response
1137 * This function sends a message to arc, waits the response, and reads the responses.
1139 * \param request Pointer to the request
1140 * \param reply Wait reply or not.
1141 * \param response Pointer to the response
1142 * \return MEI_SUCCESS or MEI_FAILURE
1146 meiCMV (u16 * request, int reply, u16 * response) // write cmv to arc, if reply needed, wait for reply
1149 #if defined(IFXMIPS_PORT_RTEMS)
1150 int delay_counter = 0;
1154 memcpy (CMV_TxMsg, request, MSG_LENGTH * 2);
1157 meierror = meiMailboxWrite (CMV_TxMsg, MSG_LENGTH);
1159 if (meierror != MEI_SUCCESS) {
1162 printk ("\n\n MailboxWrite Fail.");
1169 if (cmv_reply == NO_REPLY)
1172 #if !defined(IFXMIPS_PORT_RTEMS)
1174 MEI_WAIT_EVENT_TIMEOUT (wait_queue_arcmsgav, CMV_TIMEOUT);
1176 while (arcmsgav == 0 && delay_counter < CMV_TIMEOUT / 5) {
1183 if (arcmsgav == 0) { //CMV_timeout
1185 printk ("\nmeiCMV: MEI_MAILBOX_TIMEOUT\n");
1186 return MEI_MAILBOX_TIMEOUT;
1191 memcpy (response, CMV_RxMsg, MSG_LENGTH * 2);
1197 ///////////////////// Interrupt handler /////////////////////////
1199 * Disable ARC to MEI interrupt
1204 meiMailboxInterruptsDisable (void)
1206 meiLongwordWrite (ARC_TO_MEI_INT_MASK, 0x0);
1207 } // end of "meiMailboxInterruptsDisable(..."
1210 * Eable ARC to MEI interrupt
1215 meiMailboxInterruptsEnable (void)
1217 meiLongwordWrite (ARC_TO_MEI_INT_MASK, MSGAV_EN);
1218 } // end of "meiMailboxInterruptsEnable(..."
1221 * MEI interrupt handler
1225 * \param regs Pointer to the structure of ifxmips mips registers
1229 mei_interrupt_arcmsgav (int int1, void *void0)
1233 #if defined(DFE_LOOPBACK) && defined(DFE_PING_TEST)
1234 dfe_loopback_irq_handler ();
1236 #endif //DFE_LOOPBACK
1238 meiDebugRead (ARC_MEI_MAILBOXR, &scratch, 1);
1239 if (scratch & OMB_CODESWAP_MESSAGE_MSG_TYPE_MASK) {
1240 printk("\n\n Receive Code Swap Request interrupt!!!");
1243 else if (scratch & OMB_CLEAREOC_INTERRUPT_CODE) // clear eoc message interrupt
1245 meiLongwordWrite (ARC_TO_MEI_INT, ARC_TO_MEI_MSGAV);
1246 #if defined (IFXMIPS_CLEAR_EOC)
1247 MEI_WAKEUP_EVENT (wait_queue_hdlc_poll);
1249 MEI_MASK_AND_ACK_IRQ (IFXMIPS_MEI_INT);
1252 else { // normal message
1253 meiMailboxRead (CMV_RxMsg, MSG_LENGTH);
1257 printk ("got interrupt\n");
1258 for (msg_idx = 0; msg_idx < MSG_LENGTH; msg_idx++) {
1259 printk ("%04X ", CMV_RxMsg[msg_idx]);
1260 if (msg_idx % 8 == 7)
1266 if (cmv_waiting == 1) {
1269 #if !defined(IFXMIPS_PORT_RTEMS)
1270 MEI_WAKEUP_EVENT (wait_queue_arcmsgav);
1275 memcpy ((char *) Recent_indicator, (char *) CMV_RxMsg,
1277 if (((CMV_RxMsg[0] & 0xff0) >> 4) == D2H_AUTONOMOUS_MODEM_READY_MSG) // arc ready
1278 { //check ARC ready message
1279 printk ("Got MODEM_READY_MSG\n");
1281 MEI_MUTEX_UNLOCK (mei_sema); // allow cmv access
1286 MEI_MASK_AND_ACK_IRQ (IFXMIPS_MEI_INT);
1288 return IRQ_HANDLED;;
1291 ////////////////////////hdlc ////////////////
1294 * Get the hdlc status
1296 * \return HDLC status
1300 ifx_me_hdlc_status (void)
1302 u16 CMVMSG[MSG_LENGTH];
1308 makeCMV (H2D_CMV_READ, STAT, 14, 0, 1, NULL, CMVMSG); //Get HDLC status
1309 ret = mei_ioctl ((struct inode *) 0, NULL, IFXMIPS_MEI_CMV_WINHOST,
1310 (unsigned long) CMVMSG);
1314 return CMVMSG[4] & 0x0F;
1318 * Check if the me is reslved.
1320 * \param status the me status
1321 * \return ME_HDLC_UNRESOLVED or ME_HDLC_RESOLVED
1325 ifx_me_is_resloved (int status)
1327 u16 CMVMSG[MSG_LENGTH];
1329 if (adsl_mode <= 8 && adsl_mode_extend == 0) // adsl mode
1331 makeCMV (H2D_CMV_READ, CNTL, 2, 0, 1, NULL, CMVMSG); //Get ME-HDLC Control
1332 ret = mei_ioctl ((struct inode *) 0, NULL,
1333 IFXMIPS_MEI_CMV_WINHOST,
1334 (unsigned long) CMVMSG);
1336 return ME_HDLC_UNRESOLVED;
1338 if (CMVMSG[4] & (1 << 0)) {
1339 return ME_HDLC_UNRESOLVED;
1343 if (status == ME_HDLC_MSG_QUEUED
1344 || status == ME_HDLC_MSG_SENT)
1345 return ME_HDLC_UNRESOLVED;
1346 if (status == ME_HDLC_IDLE) {
1347 makeCMV (H2D_CMV_READ, CNTL, 2, 0, 1, NULL, CMVMSG); //Get ME-HDLC Control
1348 ret = mei_ioctl ((struct inode *) 0, NULL,
1349 IFXMIPS_MEI_CMV_WINHOST,
1350 (unsigned long) CMVMSG);
1352 return IFX_POP_EOC_FAIL;
1354 if (CMVMSG[4] & (1 << 0)) {
1355 return ME_HDLC_UNRESOLVED;
1359 return ME_HDLC_RESOLVED;
1363 _ifx_me_hdlc_send (unsigned char *hdlc_pkt, int pkt_len, int max_length)
1366 u16 CMVMSG[MSG_LENGTH];
1372 if (pkt_len > max_length) {
1373 makeCMV (H2D_CMV_READ, INFO, 85, 2, 1, NULL, CMVMSG); //Get ME-HDLC Control
1374 ret = mei_ioctl ((struct inode *) 0, NULL,
1375 IFXMIPS_MEI_CMV_WINHOST,
1376 (unsigned long) CMVMSG);
1380 rx_length = CMVMSG[4];
1381 if (rx_length + max_length < pkt_len) {
1382 printk ("Exceed maximum eoc rx(%d)+tx(%d) message length\n", rx_length, max_length);
1386 makeCMV (H2D_CMV_WRITE, INFO, 85, 6, 1, &data, CMVMSG); //disable RX Eoc
1387 ret = mei_ioctl ((struct inode *) 0, NULL,
1388 IFXMIPS_MEI_CMV_WINHOST,
1389 (unsigned long) CMVMSG);
1394 while (len < pkt_len) {
1395 write_size = pkt_len - len;
1396 if (write_size > 24)
1398 //printk("len=%d,write_size=%d,pkt_len=%d\n",len,write_size,pkt_len);
1399 memset (CMVMSG, 0, sizeof (CMVMSG));
1400 makeCMV (H2D_CMV_WRITE, INFO, 81, len / 2, (write_size + 1) / 2, (u16 *) (hdlc_pkt + len), CMVMSG); //Write clear eoc message to ARC
1401 ret = mei_ioctl ((struct inode *) 0, NULL,
1402 IFXMIPS_MEI_CMV_WINHOST,
1403 (unsigned long) CMVMSG);
1409 makeCMV (H2D_CMV_WRITE, INFO, 83, 2, 1, &len, CMVMSG); //Update tx message length
1410 ret = mei_ioctl ((struct inode *) 0, NULL, IFXMIPS_MEI_CMV_WINHOST,
1411 (unsigned long) CMVMSG);
1417 makeCMV (H2D_CMV_WRITE, CNTL, 2, 0, 1, &data, CMVMSG); //Start to send
1418 ret = mei_ioctl ((struct inode *) 0, NULL, IFXMIPS_MEI_CMV_WINHOST,
1419 (unsigned long) CMVMSG);
1429 * \param hdlc_pkt Pointer to hdlc packet
1430 * \param hdlc_pkt_len The number of bytes to send
1431 * \return success or failure.
1435 ifx_me_hdlc_send (unsigned char *hdlc_pkt, int hdlc_pkt_len)
1437 int hdlc_status = 0;
1438 u16 CMVMSG[MSG_LENGTH];
1439 int max_hdlc_tx_length = 0, ret = 0, retry = 0;
1441 int send_busy_counter = 0;
1445 // retry 1000 times (10 seconds)
1446 while (retry < 1000) {
1447 /* In L2 power mode, do not read the OHC related parameters,
1448 instead give the indication to the calling IOCTL,
1449 that the readout fails (just return -EBUSY). */
1450 power_mode = get_l3_power_status();
1451 if (power_mode == L2_POWER_MODE) {
1455 hdlc_status = ifx_me_hdlc_status ();
1456 if (ifx_me_is_resloved (hdlc_status) == ME_HDLC_RESOLVED) // arc ready to send HDLC message
1458 makeCMV (H2D_CMV_READ, INFO, 83, 0, 1, NULL, CMVMSG); //Get Maximum Allowed HDLC Tx Message Length
1459 ret = mei_ioctl ((struct inode *) 0, NULL,
1460 IFXMIPS_MEI_CMV_WINHOST,
1461 (unsigned long) CMVMSG);
1464 ("ifx_me_hdlc_send failed. Return -EIO");
1467 max_hdlc_tx_length = CMVMSG[4];
1468 ret = _ifx_me_hdlc_send (hdlc_pkt, hdlc_pkt_len,
1469 max_hdlc_tx_length);
1473 if (hdlc_status == ME_HDLC_MSG_SENT)
1474 send_busy_counter++;
1479 // wait 10 seconds and FW still report busy -> reset FW HDLC status
1480 if (send_busy_counter > 950 && send_retry == 0) {
1484 printk ("Reset FW HDLC status!!\n");
1485 send_busy_counter = 0;
1487 makeCMV (H2D_CMV_WRITE, CNTL, 2, 0, 1, NULL, CMVMSG); //Force reset to idle
1488 ret = mei_ioctl ((struct inode *) 0, NULL,
1489 IFXMIPS_MEI_CMV_WINHOST,
1490 (unsigned long) CMVMSG);
1496 printk ("ifx_me_hdlc_send failed. Return -EBUSY");
1501 * Read the hdlc packets
1503 * \param hdlc_pkt Pointer to hdlc packet
1504 * \param hdlc_pkt_len The maximum number of bytes to read
1505 * \return The number of bytes which reads.
1509 ifx_mei_hdlc_read (char *hdlc_pkt, int max_hdlc_pkt_len)
1511 u16 CMVMSG[MSG_LENGTH];
1512 int msg_read_len, ret = 0, pkt_len = 0, retry = 0;
1514 while (retry < 10) {
1515 ret = ifx_me_hdlc_status ();
1516 if (ret == ME_HDLC_RESP_RCVD) {
1517 int current_size = 0;
1518 makeCMV (H2D_CMV_READ, INFO, 83, 3, 1, NULL, CMVMSG); //Get EoC packet length
1519 ret = mei_ioctl ((MEI_inode_t *) 0, NULL,
1520 IFXMIPS_MEI_CMV_WINHOST,
1521 (unsigned long) CMVMSG);
1526 pkt_len = CMVMSG[4];
1527 if (pkt_len > max_hdlc_pkt_len) {
1531 while (current_size < pkt_len) {
1532 if (pkt_len - current_size >
1533 (MSG_LENGTH * 2 - 8))
1534 msg_read_len = (MSG_LENGTH * 2 - 8);
1537 pkt_len - (current_size);
1538 makeCMV (H2D_CMV_READ, INFO, 82, 0 + (current_size / 2), (msg_read_len + 1) / 2, NULL, CMVMSG); //Get hdlc packet
1539 ret = mei_ioctl ((MEI_inode_t *) 0, NULL,
1540 IFXMIPS_MEI_CMV_WINHOST,
1541 (unsigned long) CMVMSG);
1545 memcpy (hdlc_pkt + current_size, &CMVMSG[4],
1547 current_size += msg_read_len;
1564 #if defined(IFXMIPS_CLEAR_EOC)
1566 ifx_me_ceoc_send (struct sk_buff *eoc_pkt)
1568 int ret, pkt_len = 0;
1569 unsigned char *pkt_data_ptr;
1573 if (adsl_mode <= 8 && adsl_mode_extend == 0) // adsl mode
1575 pkt_len = eoc_pkt->len;
1577 pkt_data_ptr = kmalloc (pkt_len + 3, GFP_KERNEL);
1580 pkt_data_ptr[0] = 0x4c;
1581 pkt_data_ptr[1] = 0x81;
1584 pkt_len = eoc_pkt->len + 4;
1585 pkt_data_ptr = kmalloc (pkt_len + 1 + 2, GFP_KERNEL);
1586 memset (pkt_data_ptr, 0, pkt_len + 1 + 2);
1587 //fill clear eoc header
1588 pkt_data_ptr[0] = 0x1;
1589 pkt_data_ptr[1] = 0x8;
1590 pkt_data_ptr[2] = 0x4c;
1591 pkt_data_ptr[3] = 0x81;
1594 for (swap_idx = 0; swap_idx < (eoc_pkt->len / 2) * 2; swap_idx += 2)
1596 //printk("%02X %02X ",eoc_pkt->data[swap_idx],eoc_pkt->data[swap_idx+1]);
1597 pkt_data_ptr[swap_idx + offset] = eoc_pkt->data[swap_idx + 1];
1598 pkt_data_ptr[swap_idx + 1 + offset] = eoc_pkt->data[swap_idx];
1600 if (eoc_pkt->len % 2)
1602 //printk("%02X ",eoc_pkt->data[eoc_pkt->len-1]);
1603 pkt_data_ptr[eoc_pkt->len - 1 + offset] =
1604 eoc_pkt->data[eoc_pkt->len - 1];
1605 pkt_data_ptr[eoc_pkt->len + offset] =
1606 eoc_pkt->data[eoc_pkt->len - 1];
1608 ret = ifx_me_hdlc_send (pkt_data_ptr, pkt_len);
1610 if (pkt_data_ptr != eoc_pkt->data)
1612 kfree (pkt_data_ptr);
1614 dev_kfree_skb (eoc_pkt);
1619 get_me_ceoc_data (int pkt_len, int rx_buffer_addr, int rx_buffer_len,
1624 u16 CMVMSG[MSG_LENGTH];
1625 int read_size, aread_size;
1627 u8 *data = NULL, *data_ptr = NULL;
1633 read_size = (pkt_len / 4) + 4;
1634 offset = ceoc_read_idx % 4;
1635 over_read = read_size * 4 - pkt_len - offset;
1637 ceoc_read_idx = (ceoc_read_idx & 0xFFFFFFFC);
1639 data = kmalloc (read_size * 4, GFP_KERNEL);
1642 data_ptr = kmalloc (read_size * 4, GFP_KERNEL);
1643 if (data_ptr == NULL)
1645 if (ceoc_read_idx + read_size * 4 >= rx_buffer_len) {
1646 aread_size = (rx_buffer_len - ceoc_read_idx) / 4;
1649 aread_size = read_size;
1652 //printk("aread_size = %d,ceoc_read_idx=%d,read_size=%d,offset=%d\n",aread_size,ceoc_read_idx,read_size,offset);
1654 meiDebugRead (rx_buffer_addr + ceoc_read_idx, (u32 *) (data),
1656 ceoc_read_idx += aread_size * 4;
1657 if (aread_size != read_size) {
1659 meiDebugRead (rx_buffer_addr,
1660 (u32 *) (data) + aread_size,
1661 read_size - aread_size);
1662 ceoc_read_idx = (read_size - aread_size) * 4;
1664 if (ceoc_read_idx < over_read)
1665 ceoc_read_idx = rx_buffer_len + ceoc_read_idx - over_read;
1667 ceoc_read_idx -= over_read;
1669 if (offset == 0 || offset == 2) {
1670 for (i = 0; i < read_size; i++) {
1673 for (j = 0; j < 4; j++) {
1674 if (i * 4 + j - offset >= 0)
1675 data_ptr[i * 4 + j - offset] =
1676 data[i * 4 + (3 - j)];
1681 else if (offset == 1) {
1682 for (i = 0; i < pkt_len; i = i + 4) {
1684 data_ptr[i + 1] = data[i + 1];
1685 data_ptr[i] = data[i + 2];
1686 data_ptr[i + 3] = data[i + 7];
1687 data_ptr[i + 2] = data[i];
1690 else if (offset == 3) {
1691 for (i = 0; i < pkt_len; i = i + 4) {
1692 data_ptr[i + 1] = data[i + 7];
1693 data_ptr[i + 0] = data[i];
1694 data_ptr[i + 3] = data[i + 5];
1695 data_ptr[i + 2] = data[i + 6];
1698 if (pkt_len % 2 == 1)
1699 data_ptr[pkt_len - 1] = data_ptr[pkt_len];
1702 memcpy (data_ptr1, data_ptr, pkt_len);
1705 makeCMV (H2D_CMV_WRITE, INFO, 85, 3, 1, &ceoc_read_idx, CMVMSG);
1706 ret = mei_ioctl ((struct inode *) 0, NULL, IFXMIPS_MEI_CMV_WINHOST,
1707 (unsigned long) CMVMSG);
1720 ifx_me_ceoc_receive (int ceoc_write_idx, int rx_buffer_len,
1721 struct sk_buff **eoc_pkt)
1723 u16 CMVMSG[MSG_LENGTH];
1725 u16 lsw_addr, msw_addr;
1726 u32 rx_buffer_addr = 0;
1729 //printk("rx_buffer_len=%d,ceoc_read_idx=%d,ceoc_write_idx=%d\n",rx_buffer_len,ceoc_read_idx,ceoc_write_idx);
1730 if (ceoc_write_idx > ceoc_read_idx) {
1731 pkt_len = ceoc_write_idx - ceoc_read_idx;
1734 pkt_len = rx_buffer_len - ceoc_read_idx + ceoc_write_idx;
1736 *eoc_pkt = dev_alloc_skb (pkt_len);
1737 if (*eoc_pkt == NULL) {
1738 printk ("Out of memory!\n");
1743 makeCMV (H2D_CMV_READ, INFO, 85, 0, 1, NULL, CMVMSG); //Get HDLC packet
1744 ret = mei_ioctl ((struct inode *) 0, NULL, IFXMIPS_MEI_CMV_WINHOST,
1745 (unsigned long) CMVMSG);
1749 lsw_addr = CMVMSG[4];
1751 makeCMV (H2D_CMV_READ, INFO, 85, 1, 1, NULL, CMVMSG); //Get HDLC packet
1752 ret = mei_ioctl ((struct inode *) 0, NULL, IFXMIPS_MEI_CMV_WINHOST,
1753 (unsigned long) CMVMSG);
1757 msw_addr = CMVMSG[4];
1758 rx_buffer_addr = msw_addr << 16 | lsw_addr;
1760 get_me_ceoc_data (pkt_len, rx_buffer_addr, rx_buffer_len,
1761 (u16 *) skb_put (*eoc_pkt, pkt_len));
1762 if (dma_ret != MEI_SUCCESS) {
1769 if (*eoc_pkt != NULL)
1770 dev_kfree_skb (*eoc_pkt);
1775 ifx_mei_ceoc_rx (void)
1777 u16 CMVMSG[MSG_LENGTH];
1778 int rx_buffer_len, ret, pkt_len = 0;
1779 struct sk_buff *eoc_pkt;
1780 u16 ceoc_write_idx = 0;
1782 makeCMV (H2D_CMV_READ, INFO, 85, 2, 1, NULL, CMVMSG); //Get EoC packet length
1783 ret = mei_ioctl ((struct inode *) 0, NULL, IFXMIPS_MEI_CMV_WINHOST,
1784 (unsigned long) CMVMSG);
1786 printk ("ioctl fail!!\n");
1788 rx_buffer_len = CMVMSG[4];
1790 makeCMV (H2D_CMV_READ, INFO, 85, 4, 1, NULL, CMVMSG); //Get write index
1791 ret = mei_ioctl ((struct inode *) 0, NULL, IFXMIPS_MEI_CMV_WINHOST,
1792 (unsigned long) CMVMSG);
1797 ceoc_write_idx = CMVMSG[4];
1798 ret = ifx_me_ceoc_receive (ceoc_write_idx, rx_buffer_len, &eoc_pkt);
1799 #if defined (CONFIG_ATM_IFXMIPS)
1801 skb_pull (eoc_pkt, 2); // skip 4c 81 header
1802 ifx_push_ceoc (eoc_pkt); //pass data to higher layer
1810 adsl_clear_eoc_poll (void *unused)
1812 struct task_struct *tsk = current;
1814 daemonize("mei_eoc_poll");
1815 strcpy(tsk->comm, "mei_ceoc_poll");
1816 sigfillset(&tsk->blocked);
1820 MEI_WAIT_EVENT (wait_queue_hdlc_poll);
1826 #endif //#if defined(IFXMIPS_CLEAR_EOC)
1828 #ifdef IFXMIPS_CLEAR_EOC
1830 ifxmips_mei_ceoc_init (void)
1832 kernel_thread (adsl_clear_eoc_poll, NULL,
1833 CLONE_FS | CLONE_FILES | CLONE_SIGNAL);
1838 ////////////////////// Driver Structure ///////////////////////
1841 * Free the memory for ARC firmware
1843 * \param type Free all memory or free the unused memory after showtime
1847 free_image_buffer (int type)
1850 for (idx = 0; idx < MAX_BAR_REGISTERS; idx++) {
1851 printk ("meminfo[%d].type=%d,size=%ld,addr=%X\n", idx,
1852 adsl_mem_info[idx].type, adsl_mem_info[idx].size,
1853 (unsigned int)adsl_mem_info[idx].address);
1854 if (type == FREE_ALL || adsl_mem_info[idx].type == type) {
1855 if (adsl_mem_info[idx].size > 0) {
1856 kfree (adsl_mem_info[idx].org_address);
1857 adsl_mem_info[idx].address = 0;
1858 adsl_mem_info[idx].size = 0;
1859 adsl_mem_info[idx].type = 0;
1860 adsl_mem_info[idx].nCopy = 0;
1868 * Allocate memory for ARC firmware
1870 * \param size The number of bytes to allocate.
1871 * \param adsl_mem_info Pointer to firmware information.
1875 alloc_processor_memory (unsigned long size, smmu_mem_info_t * adsl_mem_info)
1877 char *mem_ptr = NULL;
1878 char *org_mem_ptr = NULL;
1880 long total_size = 0;
1881 long img_size = size;
1885 while (img_size > 0 && idx < MAX_BAR_REGISTERS) {
1886 // skip bar15 for XDATA usage.
1887 #ifndef DFE_LOOPBACK
1888 if (idx == XDATA_REGISTER)
1891 if (idx == MAX_BAR_REGISTERS - 1)
1893 //allocate 1MB memory for bar16
1894 org_mem_ptr = kmalloc (1024 * 1024, GFP_ATOMIC);
1895 mem_ptr = (char*)((unsigned long) (org_mem_ptr + 1023) & 0xFFFFFC00);
1896 adsl_mem_info[idx].size = 1024 * 1024;
1898 org_mem_ptr = kmalloc (SDRAM_SEGMENT_SIZE, GFP_ATOMIC);
1899 mem_ptr = (char*)((unsigned long) (org_mem_ptr + 1023) & 0xFFFFFC00);
1900 adsl_mem_info[idx].size = SDRAM_SEGMENT_SIZE;
1902 if (org_mem_ptr == NULL)
1904 printk ("kmalloc memory fail!\n");
1906 goto allocate_error;
1908 adsl_mem_info[idx].address = mem_ptr;
1909 adsl_mem_info[idx].org_address = org_mem_ptr;
1911 img_size -= SDRAM_SEGMENT_SIZE;
1912 total_size += SDRAM_SEGMENT_SIZE;
1913 printk("alloc memory idx=%d,img_size=%ld,addr=%X\n",
1914 idx, img_size, (unsigned int)adsl_mem_info[idx].address);
1919 printk ("Image size is too large!\n");
1921 goto allocate_error;
1927 free_image_buffer (FREE_ALL);
1932 * Program the BAR registers
1934 * \param nTotalBar The number of bar to program.
1938 update_bar_register (int nTotalBar)
1942 for (idx = 0; idx < nTotalBar; idx++) {
1943 //skip XDATA register
1944 if (idx == XDATA_REGISTER)
1946 meiLongwordWrite ( MEI_XMEM_BAR_BASE + idx * 4,
1947 (((uint32_t) adsl_mem_info[idx].
1948 address) & 0x0FFFFFFF));
1949 printk ("BAR%d=%08X, addr=%08X\n", idx,
1950 (((uint32_t) adsl_mem_info[idx].
1951 address) & 0x0FFFFFFF),
1952 (((uint32_t) adsl_mem_info[idx].address)));
1954 for (idx = nTotalBar; idx < MAX_BAR_REGISTERS; idx++) {
1955 if (idx == XDATA_REGISTER)
1957 meiLongwordWrite ( MEI_XMEM_BAR_BASE + idx * 4,
1958 (((uint32_t) adsl_mem_info[nTotalBar - 1].
1959 address) & 0x0FFFFFFF));
1962 meiLongwordWrite (MEI_XMEM_BAR_BASE + XDATA_REGISTER * 4,
1963 (((uint32_t) adsl_mem_info[XDATA_REGISTER].
1964 address) & 0x0FFFFFFF));
1965 // update MEI_XDATA_BASE_SH
1966 printk ("update bar15 register with %08lX\n",
1967 ((unsigned long) adsl_mem_info[XDATA_REGISTER].
1968 address) & 0x0FFFFFFF);
1969 meiLongwordWrite (MEI_XDATA_BASE_SH,
1970 ((unsigned long) adsl_mem_info[XDATA_REGISTER].
1971 address) & 0x0FFFFFFF);
1976 * Copy the firmware to BARs memory.
1978 * \param filp Pointer to the file structure.
1979 * \param buf Pointer to the data.
1980 * \param size The number of bytes to copy.
1981 * \param loff The file offset.
1982 * \return The current file position.
1986 mei_write (MEI_file_t * filp, char *buf, size_t size, loff_t * loff)
1988 ARC_IMG_HDR img_hdr_tmp, *img_hdr;
1990 size_t nRead = 0, nCopy = 0;
1992 ssize_t retval = -ENOMEM;
1996 if (size < sizeof (img_hdr)) {
1997 printk ("Firmware size is too small!\n");
2000 copy_from_user ((char *) &img_hdr_tmp, buf,
2001 sizeof (img_hdr_tmp));
2002 image_size = le32_to_cpu (img_hdr_tmp.size) + 8; // header of image_size and crc are not included.
2003 if (image_size > 1024 * 1024) {
2004 printk ("Firmware size is too large!\n");
2007 // check if arc is halt
2008 if (arc_halt_flag != 1) {
2013 // reset part of PPE
2014 *(unsigned long *) (IFXMIPS_PPE32_SRST) = 0xC30;
2015 *(unsigned long *) (IFXMIPS_PPE32_SRST) = 0xFFF;
2017 free_image_buffer (FREE_ALL); //free all
2019 retval = alloc_processor_memory (image_size, adsl_mem_info);
2021 printk ("Error: No memory space left.\n");
2025 for (idx = 0; idx < retval; idx++) {
2026 //skip XDATA register
2027 if (idx == XDATA_REGISTER)
2029 if (idx * SDRAM_SEGMENT_SIZE <
2030 le32_to_cpu (img_hdr_tmp.page[0].p_offset)) {
2031 adsl_mem_info[idx].type = FREE_RELOAD;
2034 adsl_mem_info[idx].type = FREE_SHOWTIME;
2040 img_hdr = (ARC_IMG_HDR *) adsl_mem_info[0].address;
2042 #if !defined(__LINUX__)
2043 adsl_mem_info[XDATA_REGISTER].org_address =
2044 kmalloc (SDRAM_SEGMENT_SIZE + 1023, GFP_ATOMIC);
2046 adsl_mem_info[XDATA_REGISTER].org_address =
2047 kmalloc (SDRAM_SEGMENT_SIZE, GFP_ATOMIC);
2049 adsl_mem_info[XDATA_REGISTER].address =
2051 *) ((unsigned long) (adsl_mem_info[XDATA_REGISTER].
2053 1023) & 0xFFFFFC00);
2054 adsl_mem_info[XDATA_REGISTER].size = SDRAM_SEGMENT_SIZE;
2055 if (adsl_mem_info[XDATA_REGISTER].address == NULL) {
2056 printk ("kmalloc memory fail!\n");
2060 adsl_mem_info[XDATA_REGISTER].type = FREE_RELOAD;
2061 update_bar_register (nBar);
2064 else if (image_size == 0) {
2065 printk ("Error: Firmware size=0! \n");
2069 if (arc_halt_flag == 0) {
2071 ("Please download the firmware from the beginning of the firmware!\n");
2077 while (nRead < size) {
2078 long offset = ((long) (*loff) + nRead) % SDRAM_SEGMENT_SIZE;
2079 idx = (((long) (*loff)) + nRead) / SDRAM_SEGMENT_SIZE;
2081 KSEG1ADDR ((unsigned long) (adsl_mem_info[idx].
2083 if ((size - nRead + offset) > SDRAM_SEGMENT_SIZE)
2084 nCopy = SDRAM_SEGMENT_SIZE - offset;
2086 nCopy = size - nRead;
2087 copy_from_user (mem_ptr, buf + nRead, nCopy);
2089 for (offset = 0; offset < (nCopy / 4); offset++) {
2090 ((unsigned long *) mem_ptr)[offset] =
2091 le32_to_cpu (((unsigned long *)
2096 adsl_mem_info[idx].nCopy += nCopy;
2099 #if ( defined(HEADER_SWAP) && !defined(IMAGE_SWAP)) || (defined(IMAGE_SWAP) && !defined(HEADER_SWAP))
2104 (sizeof (ARC_IMG_HDR) +
2105 (le32_to_cpu (img_hdr_tmp.count) -
2106 1) * sizeof (ARC_SWP_PAGE_HDR)) / 4; idx++) {
2107 ((unsigned long *) img_hdr)[idx] =
2108 le32_to_cpu (((unsigned long *)
2112 #endif //( defined(HEADER_SWAP) && !defined(IMAGE_SWAP)) || (defined(IMAGE_SWAP) && !defined(HEADER_SWAP))
2113 printk ("size=%X,loff=%08X\n", size, (unsigned int) *loff);
2118 free_image_buffer (FREE_ALL);
2123 /********************************************************
2125 ********************************************************/
2127 * Send a CMV message.
2128 * This function sends a CMV message to ARC
2130 * \param opcode The message opcode
2131 * \param group The message group number
2132 * \param address The message address.
2133 * \param index The message index.
2134 * \param size The number of words to read/write.
2135 * \param data The pointer to data.
2136 * \param CMVMSG The pointer to message buffer.
2137 * \return 0: success
2141 send_cmv (u8 opcode, u8 group, u16 address, u16 index, int size, u16 * data, u16 * CMVMSG)
2145 makeCMV(opcode, group, address, index, size, data, CMVMSG);
2146 ret = mei_ioctl((struct inode *) 0, NULL, IFXMIPS_MEI_CMV_WINHOST, (unsigned long)CMVMSG);
2150 #ifdef IFX_ADSL_L3_MODE_SUPPORT
2153 * Check the L3 request from CO
2154 * This function Check if CPE received the L3 request from CO
2155 * \return 1: got L3 request.
2159 check_co_l3_shutdown_request (void)
2161 u16 CMVMSG[MSG_LENGTH];
2162 if (modem_ready == 1) {
2163 if (send_cmv (H2D_CMV_READ, STAT, 4, 0, 1, NULL, CMVMSG) != 0) {
2166 if (CMVMSG[4] & BIT14) {
2174 * Check the L3 status
2175 * This function get the CPE Power Management Mode status
2176 * \return 0: L0 Mode
2182 get_l3_power_status (void)
2184 u16 CMVMSG[MSG_LENGTH];
2185 if (modem_ready == 0) {
2186 return L3_POWER_MODE;
2189 if (send_cmv (H2D_CMV_READ, STAT, 18, 0, 1, NULL, CMVMSG) !=
2193 return ((int) CMVMSG[4]);
2200 * Send a L3 request to CO
2201 * This function send a L3 request to CO and check the CO response.
2202 * \return 0: Success. Others: Fail.
2206 send_l3_shutdown_cmd (void)
2210 u16 CMVMSG[MSG_LENGTH];
2212 if (modem_ready == 0) {
2215 // send l3 request to CO
2216 if (send_cmv (H2D_CMV_WRITE, CNTL, 3, 0, 1, &cmd, CMVMSG) != 0) {
2222 // check CO response
2223 if (send_cmv (H2D_CMV_READ, STAT, 20, 0, 1, NULL, CMVMSG) != 0) {
2226 if (CMVMSG[4] == 0) {
2236 else if (CMVMSG[4] == 1) // reject
2240 else if (CMVMSG[4] == 2) // ok
2244 else if (CMVMSG[4] == 3) // failure
2252 * Enable L3 Power Mode
2253 * This function send a L3 request to CO and check the CO response. Then reboot the CPE to enter L3 Mode.
2254 * \return 0: Success. Others: Fail.
2258 set_l3_shutdown (void)
2261 if (l3_shutdown == 0) {
2262 // send l3 request to CO
2263 ret = send_l3_shutdown_cmd ();
2264 if (ret == 0) //got CO ACK
2266 //reboot adsl and block autoboot daemon
2267 ret = mei_ioctl ((struct inode *) 0, NULL, IFXMIPS_MEI_REBOOT, (unsigned long)NULL);
2275 * Disable L3 Power Mode
2276 * This function disable L3 Mode and wake up the autoboot daemon.
2277 * \return 0: Success.
2280 //l3 power mode disable
2282 set_l3_power_on (void)
2284 if (l3_shutdown == 1) {
2286 // wakeup autoboot daemon
2287 MEI_WAKEUP_EVENT (wait_queue_l3);
2293 /********************************************************
2294 * End of L3 Power Mode *
2295 ********************************************************/
2296 #endif //IFX_ADSL_L3_MODE_SUPPORT
2298 #ifdef CONFIG_IFXMIPS_MEI_LED
2300 * LED Initialization function
2303 meiADSLLedInit (void)
2306 u16 CMVMSG[MSG_LENGTH];
2309 #if defined(DATA_LED_SUPPORT) && defined (DATA_LED_ADSL_FW_HANDLE)
2312 // Setup ADSL Link/Data LED
2313 if (send_cmv (H2D_CMV_WRITE, INFO, 91, 0, 1, &data, CMVMSG) != 0) {
2317 if (send_cmv (H2D_CMV_WRITE, INFO, 91, 2, 1, &data, CMVMSG) != 0) {
2321 // Let FW to handle ADSL Link LED
2322 data = 0x0a03; //invert the LED signal as per input from Stefan on 13/11/2006
2323 if (send_cmv (H2D_CMV_WRITE, INFO, 91, 4, 1, &data, CMVMSG) != 0) {
2327 #ifdef DATA_LED_SUPPORT
2328 #ifdef DATA_LED_ADSL_FW_HANDLE
2330 // Turn ADSL Data LED on
2332 if (send_cmv (H2D_CMV_WRITE, INFO, 91, 5, 1, &data, CMVMSG) != 0) {
2336 ifxmips_led_set(0x1);
2343 #ifdef IFX_ADSL_DUAL_LATENCY_SUPPORT
2345 * Dual Latency Path Initialization function
2348 meiDualLatencyInit (void)
2351 u16 CMVMSG[MSG_LENGTH];
2353 // setup up stream path
2354 if (bDualLatency & DUAL_LATENCY_US_ENABLE) {
2361 if (send_cmv (H2D_CMV_WRITE, CNFG, 10, 0, 1, &nDual, CMVMSG) != 0) {
2365 if (send_cmv (H2D_CMV_WRITE, CNFG, 11, 0, 1, &nDual, CMVMSG) != 0) {
2369 // setup down stream path
2370 if (bDualLatency & DUAL_LATENCY_DS_ENABLE) {
2377 if (send_cmv (H2D_CMV_WRITE, CNFG, 21, 0, 1, &nDual, CMVMSG) != 0) {
2380 if (send_cmv (H2D_CMV_WRITE, CNFG, 22, 0, 1, &nDual, CMVMSG) != 0) {
2387 mei_is_dual_latency_enabled (void)
2389 return bDualLatency;
2394 meiAdslStartupInit (void)
2396 #ifdef CONFIG_IFXMIPS_MEI_LED
2399 #ifdef IFX_ADSL_DUAL_LATENCY_SUPPORT
2400 meiDualLatencyInit ();
2406 * MEI IO controls for user space accessing
2408 * \param ino Pointer to the stucture of inode.
2409 * \param fil Pointer to the stucture of file.
2410 * \param command The ioctl command.
2411 * \param lon The address of data.
2412 * \return Success or failure.
2416 mei_ioctl (MEI_inode_t * ino, MEI_file_t * fil, unsigned int command,
2421 int meierr = MEI_SUCCESS;
2424 u32 arc_debug_data, reg_data;
2425 #ifdef IFXMIPS_CLEAR_EOC
2427 struct sk_buff *eoc_skb;
2428 #endif //IFXMIPS_CLEAR_EOC
2429 u16 RxMessage[MSG_LENGTH] __attribute__ ((aligned (4)));
2430 u16 TxMessage[MSG_LENGTH] __attribute__ ((aligned (4)));
2432 int from_kernel = 0; //joelin
2433 if (ino == (MEI_inode_t *) 0)
2434 from_kernel = 1; //joelin
2435 if (command < IFXMIPS_MEI_START) {
2436 #ifdef CONFIG_IFXMIPS_MEI_MIB
2437 return mei_mib_ioctl (ino, fil, command, lon);
2438 #endif //CONFIG_IFXMIPS_MEI_MIB
2440 if (command == IFXMIPS_MIB_LO_ATUR
2441 || command == IFXMIPS_MIB_LO_ATUC)
2444 ("No such ioctl command (0x%X)! MEI ADSL MIB is not supported!\n",
2446 return -ENOIOCTLCMD;
2450 case IFXMIPS_MEI_START:
2453 loop_diagnostics_completed = 0;
2454 if (time_disconnect.tv_sec == 0)
2455 do_gettimeofday (&time_disconnect);
2457 if (MEI_MUTEX_LOCK (mei_sema)) //disable CMV access until ARC ready
2459 printk ("-ERESTARTSYS\n");
2460 return -ERESTARTSYS;
2463 meiMailboxInterruptsDisable (); //disable all MEI interrupts
2464 if (mei_arc_swap_buff == NULL) {
2466 (u32 *) kmalloc (MAXSWAPSIZE * 4,
2468 if (mei_arc_swap_buff == NULL) {
2470 ("\n\n malloc fail for codeswap buff");
2471 meierr = MEI_FAILURE;
2474 if (meiRunAdslModem () != MEI_SUCCESS) {
2476 ("meiRunAdslModem() error...");
2477 meierr = MEI_FAILURE;
2479 #ifdef IFX_ADSL_L3_MODE_SUPPORT
2480 /* L3 Power Mode Start */
2481 if (l3_shutdown == 1) {
2482 // block autoboot daemon until l3 power mode disable
2483 MEI_WAIT_EVENT (wait_queue_l3);
2485 /* L3 Power Mode End */
2486 #endif //IFX_ADSL_L3_MODE_SUPPORT
2487 if (autoboot_enable_flag)
2488 meiAdslStartupInit ();
2491 case IFXMIPS_MEI_SHOWTIME:
2492 if (MEI_MUTEX_LOCK (mei_sema))
2493 return -ERESTARTSYS;
2495 do_gettimeofday (&time_showtime);
2496 unavailable_seconds +=
2497 time_showtime.tv_sec - time_disconnect.tv_sec;
2498 time_disconnect.tv_sec = 0;
2499 makeCMV (H2D_CMV_READ, RATE, 0, 0, 4, NULL, TxMessage); //maximum allowed tx message length, in bytes
2500 if (meiCMV (TxMessage, YES_REPLY, RxMessage) !=
2503 ("\n\nCMV fail, Group RAGE Address 0 Index 0");
2508 rate_intl = RxMessage[4] | RxMessage[5] << 16;
2509 rate_fast = RxMessage[6] | RxMessage[7] << 16;
2510 // 609251:tc.chen Fix ATM QoS issue start
2511 if (rate_intl && rate_fast) // apply cell rate to each path
2513 #ifdef CONFIG_ATM_IFXMIPS
2514 ifx_atm_set_cell_rate (1,
2517 ifx_atm_set_cell_rate (0,
2522 else if (rate_fast) // apply fast path cell rate to atm interface 0
2524 #ifdef CONFIG_ATM_IFXMIPS
2525 ifx_atm_set_cell_rate (0,
2530 else if (rate_intl) // apply interleave path cell rate to atm interface 0
2532 #ifdef CONFIG_ATM_IFXMIPS
2533 ifx_atm_set_cell_rate (0,
2539 printk ("Got rate fail.\n");
2541 // 609251:tc.chen end
2544 #ifdef IFXMIPS_CLEAR_EOC
2546 makeCMV (H2D_CMV_WRITE, OPTN, 24, 0, 1, &data,
2548 if (meiCMV (TxMessage, YES_REPLY, RxMessage) !=
2550 printk ("Enable clear eoc fail!\n");
2554 makeCMV (H2D_CMV_READ, STAT, 1, 0, 1, NULL,
2556 if (meiCMV (TxMessage, YES_REPLY, RxMessage) !=
2558 #ifdef IFXMIPS_MEI_DEBUG_ON
2559 printk ("\n\nCMV fail, Group STAT Address 1 Index 0");
2562 adsl_mode = RxMessage[4];
2563 makeCMV (H2D_CMV_READ, STAT, 17, 0, 1, NULL,
2565 if (meiCMV (TxMessage, YES_REPLY, RxMessage) !=
2567 #ifdef IFXMIPS_MEI_DEBUG_ON
2568 printk ("\n\nCMV fail, Group STAT Address 1 Index 0");
2571 adsl_mode_extend = RxMessage[4];
2572 #ifdef CONFIG_IFXMIPS_MEI_MIB
2573 mei_mib_adsl_link_up ();
2576 //joelin 04/16/2005-start
2577 makeCMV (H2D_CMV_WRITE, PLAM, 10, 0, 1,
2578 &unavailable_seconds, TxMessage);
2579 if (meiCMV (TxMessage, YES_REPLY, RxMessage) !=
2582 ("\n\nCMV fail, Group 7 Address 10 Index 0");
2585 //joelin 04/16/2005-end
2587 free_image_buffer (FREE_SHOWTIME);
2588 MEI_MUTEX_UNLOCK (mei_sema);
2591 case IFXMIPS_MEI_HALT:
2592 if (arc_halt_flag == 0) {
2597 case IFXMIPS_MEI_RUN:
2598 if (arc_halt_flag == 1) {
2602 case IFXMIPS_MEI_CMV_WINHOST:
2603 if (MEI_MUTEX_LOCK (mei_sema))
2604 return -ERESTARTSYS;
2607 copy_from_user ((char *) TxMessage, (char *) lon, MSG_LENGTH * 2); //joelin
2609 memcpy (TxMessage, (char *) lon,
2612 if (meiCMV (TxMessage, YES_REPLY, RxMessage) !=
2615 ("\n\nWINHOST CMV fail :TxMessage:%X %X %X %X, RxMessage:%X %X %X %X %X\n",
2616 TxMessage[0], TxMessage[1],
2617 TxMessage[2], TxMessage[3],
2618 RxMessage[0], RxMessage[1],
2619 RxMessage[2], RxMessage[3],
2621 meierr = MEI_FAILURE;
2624 if (!from_kernel) //joelin
2625 copy_to_user ((char *) lon,
2629 memcpy ((char *) lon,
2634 MEI_MUTEX_UNLOCK (mei_sema);
2636 #ifdef IFXMIPS_MEI_CMV_EXTRA
2637 case IFXMIPS_MEI_CMV_READ:
2638 copy_from_user ((char *) (®rdwr), (char *) lon,
2640 meiLongwordRead ((u32*)regrdwr.iAddress, &(regrdwr.iData));
2642 copy_to_user((char *) lon, (char *) (®rdwr), sizeof (meireg));
2645 case IFXMIPS_MEI_CMV_WRITE:
2646 copy_from_user ((char *) (®rdwr), (char *) lon, sizeof (meireg));
2647 meiLongwordWrite ((u32*)regrdwr.iAddress, regrdwr.iData);
2650 case IFXMIPS_MEI_REMOTE:
2651 copy_from_user ((char *) (&i), (char *) lon,
2654 meiMailboxInterruptsEnable ();
2656 MEI_MUTEX_UNLOCK (mei_sema);
2659 meiMailboxInterruptsDisable ();
2660 if (MEI_MUTEX_LOCK (mei_sema))
2661 return -ERESTARTSYS;
2665 ("\n\n IFXMIPS_MEI_REMOTE argument error");
2666 meierr = MEI_FAILURE;
2670 case IFXMIPS_MEI_READDEBUG:
2671 case IFXMIPS_MEI_WRITEDEBUG:
2672 #if 0 //tc.chen:It is no necessary to acquire lock to read debug memory!!
2673 if (MEI_MUTEX_LOCK (mei_sema))
2674 return -ERESTARTSYS;
2677 copy_from_user ((char *) (&debugrdwr),
2679 sizeof (debugrdwr));
2681 memcpy ((char *) (&debugrdwr), (char *) lon,
2682 sizeof (debugrdwr));
2684 if (command == IFXMIPS_MEI_READDEBUG)
2685 meiDebugRead (debugrdwr.iAddress,
2689 meiDebugWrite (debugrdwr.iAddress,
2694 copy_to_user ((char *) lon, (char *) (&debugrdwr), sizeof (debugrdwr)); //dying gasp
2695 #if 0 //tc.chen:It is no necessary to acquire lock to read debug memory!!
2696 MEI_MUTEX_UNLOCK (mei_sema);
2699 case IFXMIPS_MEI_RESET:
2700 case IFXMIPS_MEI_REBOOT:
2702 #ifdef CONFIG_IFXMIPS_MEI_MIB
2703 mei_mib_adsl_link_down ();
2706 #ifdef IFX_ADSL_L3_MODE_SUPPORT
2707 /* L3 Power Mode start */
2708 if (check_co_l3_shutdown_request () == 1) //co request
2710 // cpe received co L3 request
2713 /* L3 Power Mode end */
2714 #endif //IFX_ADSL_L3_MODE_SUPPORT
2717 meiControlModeSwitch (MEI_MASTER_MODE);
2718 //enable ac_clk signal
2719 _meiDebugLongWordRead (MEI_DEBUG_DEC_DMP1_MASK,
2720 CRI_CCR0, &arc_debug_data);
2721 arc_debug_data |= ACL_CLK_MODE_ENABLE;
2722 _meiDebugLongWordWrite (MEI_DEBUG_DEC_DMP1_MASK,
2723 CRI_CCR0, arc_debug_data);
2724 meiControlModeSwitch (JTAG_MASTER_MODE);
2726 update_bar_register (nBar);
2728 case IFXMIPS_MEI_DOWNLOAD:
2729 // DMA the boot code page(s)
2730 printk ("Start download pages");
2731 meiDownloadBootPages ();
2733 #endif //IFXMIPS_MEI_CMV_EXTRA
2735 #ifdef IFXMIPS_CLEAR_EOC
2736 case IFXMIPS_MEI_EOC_SEND:
2741 copy_from_user ((char *) (&debugrdwr),
2743 sizeof (debugrdwr));
2745 dev_alloc_skb (debugrdwr.iCount * 4);
2746 if (eoc_skb == NULL) {
2748 ("\n\nskb alloc fail");
2752 eoc_skb->len = debugrdwr.iCount * 4;
2754 (eoc_skb, debugrdwr.iCount * 4),
2755 (char *) debugrdwr.buffer,
2756 debugrdwr.iCount * 4);
2759 eoc_skb = (struct sk_buff *) lon;
2761 ifx_me_ceoc_send (eoc_skb); //pass data to higher layer
2763 #endif // IFXMIPS_CLEAR_EOC
2764 case IFXMIPS_MEI_JTAG_ENABLE:
2765 printk ("ARC JTAG Enable.\n");
2766 *(IFXMIPS_GPIO_P0_DIR) = (*IFXMIPS_GPIO_P0_DIR) & (~0x800); // set gpio11 to input
2767 *(IFXMIPS_GPIO_P0_ALTSEL0) = ((*IFXMIPS_GPIO_P0_ALTSEL0) & (~0x800));
2768 *(IFXMIPS_GPIO_P0_ALTSEL1) = ((*IFXMIPS_GPIO_P0_ALTSEL1) & (~0x800));
2769 *IFXMIPS_GPIO_P0_OD = (*IFXMIPS_GPIO_P0_OD) | 0x800;
2772 meiLongwordRead(IFXMIPS_RCU_RST, ®_data);
2773 meiLongwordWrite(IFXMIPS_RCU_RST, reg_data | IFXMIPS_RCU_RST_REQ_ARC_JTAG);
2776 case GET_ADSL_LOOP_DIAGNOSTICS_MODE:
2777 copy_to_user ((char *) lon, (char *) &loop_diagnostics_mode, sizeof(int));
2779 case LOOP_DIAGNOSTIC_MODE_COMPLETE:
2780 loop_diagnostics_completed = 1;
2781 #ifdef CONFIG_IFXMIPS_MEI_MIB
2783 makeCMV (H2D_CMV_READ, STAT, 1, 0, 1, NULL, TxMessage);
2784 if (meiCMV (TxMessage, YES_REPLY, RxMessage) != MEI_SUCCESS) {
2785 #ifdef IFXMIPS_MEI_DEBUG_ON
2786 printk ("\n\nCMV fail, Group STAT Address 1 Index 0");
2789 adsl_mode = RxMessage[4];
2791 makeCMV (H2D_CMV_READ, STAT, 17, 0, 1, NULL, TxMessage);
2792 if (meiCMV (TxMessage, YES_REPLY, RxMessage) != MEI_SUCCESS) {
2793 #ifdef IFXMIPS_MEI_DEBUG_ON
2794 printk ("\n\nCMV fail, Group STAT Address 1 Index 0");
2797 adsl_mode_extend = RxMessage[4];
2799 MEI_WAKEUP_EVENT (wait_queue_loop_diagnostic);
2801 case SET_ADSL_LOOP_DIAGNOSTICS_MODE:
2802 if (lon != loop_diagnostics_mode) {
2803 loop_diagnostics_completed = 0;
2804 loop_diagnostics_mode = lon;
2805 #if 0 //08/12/2006 tc.chen : autoboot daemon should reset dsl
2806 mei_ioctl ((MEI_inode_t *) 0, NULL,
2808 (unsigned long) NULL);
2812 case IS_ADSL_LOOP_DIAGNOSTICS_MODE_COMPLETE:
2813 copy_to_user ((char *) lon,
2814 (char *) &loop_diagnostics_completed,
2817 #ifdef IFX_ADSL_L3_MODE_SUPPORT
2818 /* L3 Power Mode Start */
2819 case GET_POWER_MANAGEMENT_MODE:
2820 i = get_l3_power_status ();
2821 copy_to_user ((char *) lon, (char *) &i,
2824 case SET_L3_POWER_MODE:
2826 copy_from_user ((char *) &i, (char *) lon,
2829 return set_l3_shutdown ();
2832 return set_l3_power_on ();
2835 /* L3 Power Mode End */
2836 #endif //IFX_ADSL_L3_MODE_SUPPORT
2837 #ifdef IFX_ADSL_DUAL_LATENCY_SUPPORT
2838 case GET_ADSL_DUAL_LATENCY:
2839 i = mei_is_dual_latency_enabled ();
2842 copy_to_user ((char *) lon, (char *) &i,
2845 case SET_ADSL_DUAL_LATENCY:
2847 copy_from_user ((char *) &i, (char *) lon,
2849 if (i > DUAL_LATENCY_US_DS_ENABLE) {
2852 if (i != bDualLatency) {
2854 i = 1; // DualLatency update,need to reboot arc
2857 i = 0; // DualLatency is the same
2859 if (modem_ready && i) // modem is already start, reboot arc to apply Dual Latency changed
2861 mei_ioctl ((MEI_inode_t *) 0, NULL,
2863 (unsigned long) NULL);
2868 case QUIET_MODE_GET:
2869 copy_to_user ((char *) lon, (char *) &quiet_mode_flag,
2872 case QUIET_MODE_SET:
2873 copy_from_user ((char *) &i, (char *) lon,
2878 u16 CMVMSG[MSG_LENGTH];
2880 makeCMV (H2D_CMV_WRITE, INFO, 94, 0, 1, &data, CMVMSG); // set tx power to 0
2881 meierr = mei_ioctl ((struct inode *) 0, NULL,
2882 IFXMIPS_MEI_CMV_WINHOST,
2883 (unsigned long) CMVMSG);
2885 quiet_mode_flag = i;
2887 case SHOWTIME_LOCK_GET:
2888 copy_to_user ((char *) lon,
2889 (char *) &showtime_lock_flag,
2892 case SHOWTIME_LOCK_SET:
2893 copy_from_user ((char *) &i, (char *) lon,
2897 showtime_lock_flag = i;
2899 case AUTOBOOT_ENABLE_SET:
2900 copy_from_user ((char *) &i, (char *) lon,
2904 autoboot_enable_flag = i;
2908 ("The ioctl command(0x%X is not supported!\n",
2910 meierr = -ENOIOCTLCMD;
2916 //////////////////// procfs debug ///////////////////////////
2918 #ifdef CONFIG_PROC_FS
2920 proc_read (struct file *file, char *buf, size_t nbytes, loff_t * ppos)
2922 int i_ino = (file->f_dentry->d_inode)->i_ino;
2927 reg_entry_t *current_reg = NULL;
2928 u16 RxMessage[MSG_LENGTH] __attribute__ ((aligned (4)));
2929 u16 TxMessage[MSG_LENGTH] __attribute__ ((aligned (4)));
2931 for (i = 0; i < NUM_OF_REG_ENTRY; i++) {
2932 if (regs[i].low_ino == i_ino) {
2933 current_reg = ®s[i];
2937 if (current_reg == NULL)
2940 if (current_reg->flag == (int *) 8) {
2943 //Firmware version: major.minor.sub_version.int_version.rel_state.spl_appl
2944 ///Firmware Date Time Code: date/month min:hour
2945 if (*ppos > 0) /* Assume reading completed in previous read */
2946 return 0; // indicates end of file
2947 if (MEI_MUTEX_LOCK (mei_sema))
2948 return -ERESTARTSYS;
2950 if (indicator_count < 1) {
2951 MEI_MUTEX_UNLOCK (mei_sema);
2956 makeCMV (H2D_CMV_READ, INFO, 54, 0, 1, NULL, TxMessage);
2957 if (meiCMV (TxMessage, YES_REPLY, RxMessage) != MEI_SUCCESS) {
2958 MEI_MUTEX_UNLOCK (mei_sema);
2961 version = RxMessage[4];
2962 count = sprintf (outputbuf, "%d.%d.", (version) & 0xff,
2963 (version >> 8) & 0xff);
2965 //sub_version:bits 4-7
2966 //int_version:bits 0-3
2967 //spl_appl:bits 8-13
2968 //rel_state:bits 14-15
2969 makeCMV (H2D_CMV_READ, INFO, 54, 1, 1, NULL, TxMessage);
2970 if (meiCMV (TxMessage, YES_REPLY, RxMessage) != MEI_SUCCESS) {
2971 MEI_MUTEX_UNLOCK (mei_sema);
2974 version = RxMessage[4];
2975 count += sprintf (outputbuf + count, "%d.%d.%d.%d",
2976 (version >> 4) & 0xf,
2978 (version >> 14) & 0x3,
2979 (version >> 8) & 0x3f);
2982 makeCMV (H2D_CMV_READ, INFO, 55, 0, 1, NULL, TxMessage);
2983 if (meiCMV (TxMessage, YES_REPLY, RxMessage) != MEI_SUCCESS) {
2984 MEI_MUTEX_UNLOCK (mei_sema);
2987 version = RxMessage[4];
2991 makeCMV (H2D_CMV_READ, INFO, 55, 1, 1, NULL, TxMessage);
2992 if (meiCMV (TxMessage, YES_REPLY, RxMessage) != MEI_SUCCESS) {
2993 MEI_MUTEX_UNLOCK (mei_sema);
2996 version += (RxMessage[4] << 16);
2997 count += sprintf (outputbuf + count, " %d/%d %d:%d\n",
2998 version & 0xff, (version >> 8) & 0xff,
2999 (version >> 25) & 0xff,
3000 (version >> 16) & 0xff);
3001 MEI_MUTEX_UNLOCK (mei_sema);
3005 else if (current_reg->flag != (int *) Recent_indicator) {
3006 if (*ppos > 0) /* Assume reading completed in previous read */
3007 return 0; // indicates end of file
3008 count = sprintf (outputbuf, "0x%08X\n\n",
3009 *(current_reg->flag));
3011 if (count > nbytes) /* Assume output can be read at one time */
3015 if ((int) (*ppos) / ((int) 7) == 16)
3016 return 0; // indicate end of the message
3017 count = sprintf (outputbuf, "0x%04X\n\n",
3018 *(((u16 *) (current_reg->flag)) +
3019 (int) (*ppos) / ((int) 7)));
3022 if (copy_to_user (buf, outputbuf, count))
3028 proc_write (struct file *file, const char *buffer, size_t count,
3031 int i_ino = (file->f_dentry->d_inode)->i_ino;
3032 reg_entry_t *current_reg = NULL;
3034 unsigned long newRegValue;
3037 for (i = 0; i < NUM_OF_REG_ENTRY; i++) {
3038 if (regs[i].low_ino == i_ino) {
3039 current_reg = ®s[i];
3043 if ((current_reg == NULL)
3044 || (current_reg->flag == (int *) Recent_indicator))
3047 newRegValue = simple_strtoul (buffer, &endp, 0);
3048 *(current_reg->flag) = (int) newRegValue;
3049 return (count + endp - buffer);
3051 #endif //CONFIG_PROC_FS
3053 //TODO, for loopback test
3055 #define mte_reg_base (0x4800*4+0x20000)
3057 /* Iridia Registers Address Constants */
3058 #define MTE_Reg(r) (int)(mte_reg_base + (r*4))
3060 #define IT_AMODE MTE_Reg(0x0004)
3062 #define OMBOX_BASE 0xDF80
3063 #define OMBOX1 (OMBOX_BASE+0x4)
3064 #define IMBOX_BASE 0xDFC0
3066 #define TIMER_DELAY (1024)
3067 #define BC0_BYTES (32)
3068 #define BC1_BYTES (30)
3070 #define TIMEOUT_VALUE 2000
3076 for (i = 0; i < cycle; i++);
3080 WriteRegLong (u32 addr, u32 data)
3082 //*((volatile u32 *)(addr)) = data;
3083 IFXMIPS_WRITE_REGISTER_L (data, addr);
3087 ReadRegLong (u32 addr)
3090 //rd_val = *((volatile u32 *)(addr));
3092 return IFXMIPS_READ_REGISTER_L (addr);
3095 /* This routine writes the mailbox with the data in an input array */
3097 WriteMbox (u32 * mboxarray, u32 size)
3099 meiDebugWrite (IMBOX_BASE, mboxarray, size);
3100 printk ("write to %X\n", IMBOX_BASE);
3101 meiLongwordWrite ( MEI_TO_ARC_INT, MEI_TO_ARC_MSGAV);
3104 /* This routine reads the output mailbox and places the results into an array */
3106 ReadMbox (u32 * mboxarray, u32 size)
3108 meiDebugRead (OMBOX_BASE, mboxarray, size);
3109 printk ("read from %X\n", OMBOX_BASE);
3113 MEIWriteARCValue (u32 address, u32 value)
3117 /* Write address register */
3118 IFXMIPS_WRITE_REGISTER_L (address, MEI_DEBUG_WAD);
3120 /* Write data register */
3121 IFXMIPS_WRITE_REGISTER_L (value, MEI_DEBUG_DATA);
3123 /* wait until complete - timeout at 40 */
3124 for (i = 0; i < 40; i++) {
3125 check = IFXMIPS_READ_REGISTER_L (ARC_TO_MEI_INT);
3127 if ((check & ARC_TO_MEI_DBG_DONE))
3130 /* clear the flag */
3131 IFXMIPS_WRITE_REGISTER_L (ARC_TO_MEI_DBG_DONE, ARC_TO_MEI_INT);
3135 arc_code_page_download (uint32_t arc_code_length, uint32_t * start_address)
3138 printk ("try to download pages,size=%d\n", arc_code_length);
3139 meiControlModeSwitch (MEI_MASTER_MODE);
3140 if (arc_halt_flag == 0) {
3143 meiLongwordWrite ( MEI_XFR_ADDR, 0);
3144 for (count = 0; count < arc_code_length; count++) {
3145 meiLongwordWrite ( MEI_DATA_XFR,
3146 *(start_address + count));
3148 meiControlModeSwitch (JTAG_MASTER_MODE);
3151 load_jump_table (unsigned long addr)
3154 uint32_t addr_le, addr_be;
3155 uint32_t jump_table[32];
3156 for (i = 0; i < 16; i++) {
3157 addr_le = i * 8 + addr;
3158 addr_be = ((addr_le >> 16) & 0xffff);
3159 addr_be |= ((addr_le & 0xffff) << 16);
3160 jump_table[i * 2 + 0] = 0x0f802020;
3161 jump_table[i * 2 + 1] = addr_be;
3162 //printk("jt %X %08X %08X\n",i,jump_table[i*2+0],jump_table[i*2+1]);
3164 arc_code_page_download (32, &jump_table[0]);
3169 dfe_loopback_irq_handler (void)
3171 uint32_t rd_mbox[10];
3173 memset (&rd_mbox[0], 0, 10 * 4);
3174 ReadMbox (&rd_mbox[0], 6);
3175 if (rd_mbox[0] == 0x0) {
3176 printk ("Get ARC_ACK\n");
3179 else if (rd_mbox[0] == 0x5) {
3180 printk ("Get ARC_BUSY\n");
3183 else if (rd_mbox[0] == 0x3) {
3184 printk ("Get ARC_EDONE\n");
3185 if (rd_mbox[1] == 0x0) {
3187 printk ("Get E_MEMTEST\n");
3188 if (rd_mbox[2] != 0x1) {
3190 printk ("Get Result %X\n",
3195 meiLongwordWrite ( ARC_TO_MEI_INT, ARC_TO_MEI_DBG_DONE);
3196 MEI_MASK_AND_ACK_IRQ (IFXMIPS_MEI_INT);
3197 disable_irq (IFXMIPS_MEI_INT);
3203 wait_mem_test_result (void)
3207 printk ("Waiting Starting\n");
3208 while (mbox[0] == 0) {
3209 ReadMbox (&mbox[0], 5);
3211 printk ("Try to get mem test result.\n");
3212 ReadMbox (&mbox[0], 5);
3213 if (mbox[0] == 0xA) {
3214 printk ("Success.\n");
3216 else if (mbox[0] == 0xA) {
3218 ("Fail,address %X,except data %X,receive data %X\n",
3219 mbox[1], mbox[2], mbox[3]);
3227 arc_ping_testing (void)
3229 #define MEI_PING 0x00000001
3230 uint32_t wr_mbox[10], rd_mbox[10];
3232 for (i = 0; i < 10; i++) {
3237 printk ("send ping msg\n");
3238 wr_mbox[0] = MEI_PING;
3239 WriteMbox (&wr_mbox[0], 10);
3241 while (got_int == 0) {
3245 printk ("send start event\n");
3251 wr_mbox[3] = (uint32_t) 0xf5acc307e;
3254 wr_mbox[6] = 0x1c000;
3258 WriteMbox (&wr_mbox[0], 10);
3259 enable_irq (IFXMIPS_MEI_INT);
3260 //printk("meiMailboxWrite ret=%d\n",i);
3261 meiLongwordWrite ( MEI_TO_ARC_INT, MEI_TO_ARC_MSGAV);
3262 printk ("sleeping\n");
3267 printk ("got_int >>>> 3\n");
3269 printk ("got int = %d\n", got_int);
3272 enable_irq (IFXMIPS_MEI_INT);
3274 //mbox_read(&rd_mbox[0],6);
3280 DFE_Loopback_Test (void)
3283 u32 arc_debug_data = 0, temp;
3287 arc_debug_data = ACL_CLK_MODE_ENABLE;
3288 meiDebugWrite (CRI_CCR0, &arc_debug_data, 1);
3290 #if defined( DFE_PING_TEST )|| defined( DFE_ATM_LOOPBACK)
3291 // WriteARCreg(AUX_XMEM_LTEST,0);
3292 meiControlModeSwitch (MEI_MASTER_MODE);
3293 #define AUX_XMEM_LTEST 0x128
3294 _meiDebugLongWordWrite (MEI_DEBUG_DEC_AUX_MASK, AUX_XMEM_LTEST, 0);
3295 meiControlModeSwitch (JTAG_MASTER_MODE);
3297 // WriteARCreg(AUX_XDMA_GAP,0);
3298 meiControlModeSwitch (MEI_MASTER_MODE);
3299 #define AUX_XDMA_GAP 0x114
3300 _meiDebugLongWordWrite (MEI_DEBUG_DEC_AUX_MASK, AUX_XDMA_GAP, 0);
3301 meiControlModeSwitch (JTAG_MASTER_MODE);
3303 meiControlModeSwitch (MEI_MASTER_MODE);
3305 _meiDebugLongWordWrite (MEI_DEBUG_DEC_AUX_MASK,
3306 (u32) MEI_XDATA_BASE_SH, temp);
3307 meiControlModeSwitch (JTAG_MASTER_MODE);
3309 i = alloc_processor_memory (SDRAM_SEGMENT_SIZE * 16, adsl_mem_info);
3313 for (idx = 0; idx < i; idx++) {
3314 adsl_mem_info[idx].type = FREE_RELOAD;
3315 IFXMIPS_WRITE_REGISTER_L ((((uint32_t)
3317 address) & 0x0fffffff),
3318 MEI_XMEM_BAR_BASE + idx * 4);
3319 printk ("bar%d(%X)=%X\n", idx,
3320 MEI_XMEM_BAR_BASE + idx * 4,
3321 (((uint32_t) adsl_mem_info[idx].
3322 address) & 0x0fffffff));
3323 memset ((u8 *) adsl_mem_info[idx].address, 0,
3324 SDRAM_SEGMENT_SIZE);
3327 meiLongwordWrite ( MEI_XDATA_BASE_SH, ((unsigned long)
3335 printk ("cannot load image: no memory\n\n");
3338 //WriteARCreg(AUX_IC_CTRL,2);
3339 meiControlModeSwitch (MEI_MASTER_MODE);
3340 #define AUX_IC_CTRL 0x11
3341 _meiDebugLongWordWrite (MEI_DEBUG_DEC_AUX_MASK, AUX_IC_CTRL, 2);
3342 meiControlModeSwitch (JTAG_MASTER_MODE);
3346 #ifdef DFE_PING_TEST
3348 printk ("ping test image size=%d\n", sizeof (code_array));
3349 memcpy ((u8 *) (adsl_mem_info[0].address + 0x1004), &code_array[0],
3350 sizeof (code_array));
3351 load_jump_table (0x80000 + 0x1004);
3353 #endif //DFE_PING_TEST
3355 printk ("ARC ping test code download complete\n");
3356 #endif //defined( DFE_PING_TEST )|| defined( DFE_ATM_LOOPBACK)
3358 meiLongwordWrite (ARC_TO_MEI_INT_MASK, MSGAV_EN);
3360 arc_code_page_download (1537, &mem_test_code_array[0]);
3361 printk ("ARC mem test code download complete\n");
3362 #endif //DFE_MEM_TEST
3363 #ifdef DFE_ATM_LOOPBACK
3364 arc_debug_data = 0xf;
3365 arc_code_page_download (1077, &code_array[0]);
3366 // Start Iridia IT_AMODE (in dmp access) why is it required?
3367 meiDebugWrite (0x32010, &arc_debug_data, 1);
3368 #endif //DFE_ATM_LOOPBACK
3369 meiMailboxInterruptsEnable ();
3372 #ifdef DFE_PING_TEST
3373 arc_ping_testing ();
3374 #endif //DFE_PING_TEST
3376 wait_mem_test_result ();
3377 #endif //DFE_MEM_TEST
3379 free_image_buffer (FREE_ALL);
3383 #endif //DFE_LOOPBACK
3384 //end of TODO, for loopback test
3386 #if defined(CONFIG_IFXMIPS_MEI_LED) && defined(DATA_LED_SUPPORT)
3389 * Led Thread Main function
3392 led_poll (void *unused)
3394 struct task_struct *tsk = current;
3396 daemonize("mei_led_poll");
3397 strcpy (tsk->comm, "atm_led");
3398 sigfillset (&tsk->blocked);
3400 stop_led_module = 0; //begin polling ...
3402 while (!stop_led_module) {
3403 if (led_status_on || led_need_to_flash) {
3404 adsl_led_flash_task ();
3406 if (led_status_on) //sleep 200 ms to check if need to turn led off
3408 interruptible_sleep_on_timeout
3409 (&wait_queue_led_polling, 25);
3412 interruptible_sleep_on (&wait_queue_led_polling);
3419 * API for atm driver to notify led thread a data coming/sending
3421 #if defined (CONFIG_ATM_IFXMIPS)
3423 adsl_led_flash (void)
3428 if (led_status_on == 0 && led_need_to_flash == 0)
3430 wake_up_interruptible (&wait_queue_led_polling); //wake up and clean led module
3432 led_need_to_flash = 1; //asking to flash led
3438 * Main task for led controlling.
3441 adsl_led_flash_task (void)
3443 #ifdef DATA_LED_ADSL_FW_HANDLE
3447 u16 CMVMSG[MSG_LENGTH];
3450 // printk("Task Running...\n"); //joelin test
3453 led_need_to_flash = 0;
3458 if (led_status_on == 0 && led_need_to_flash == 1) {
3460 #ifdef DATA_LED_ADSL_FW_HANDLE
3461 data = 0x0901; //flash
3462 send_cmv (H2D_CMV_WRITE, INFO, 91, 5, 1, &data, CMVMSG); //use GPIO9 for TR68 data led .flash.
3464 ifxmips_led_blink_set(0x0); // data
3465 ifxmips_led_blink_set(0x1); // link
3470 else if (led_status_on == 1 && led_need_to_flash == 0) {
3471 #ifdef DATA_LED_ADSL_FW_HANDLE
3472 #ifdef DATA_LED_ON_MODE
3473 data = 0x0903; //use GPIO9 for TR68 data led .turn on.
3475 data = 0x0900; //off
3477 printk ("off %04X\n", data);
3478 send_cmv (H2D_CMV_WRITE, INFO, 91, 5, 1, &data, CMVMSG); //use GPIO9 for TR68 data led .off.
3483 led_need_to_flash = 0;
3488 * Led initialization function
3489 * This function create a thread to polling atm traffic and do led blanking
3492 ifxmips_mei_led_init (void)
3494 init_waitqueue_head (&wait_queue_led_polling); // adsl led for led function
3495 kernel_thread (led_poll, NULL, CLONE_FS | CLONE_FILES | CLONE_SIGHAND | CLONE_THREAD);
3500 * Led destory function
3503 ifxmips_mei_led_cleanup (void)
3505 stop_led_module = 1; //wake up and clean led module
3506 wake_up_interruptible (&wait_queue_led_polling); //wake up and clean led module
3509 #endif //#ifdef CONFIG_IFXMIPS_MEI_LED
3511 ////////////////////////////////////////////////////////////////////////////
3513 ifxmips_mei_init_module (void)
3515 struct proc_dir_entry *entry;
3518 #ifdef CONFIG_DEVFS_FS
3521 reg_entry_t regs_temp[PROC_ITEMS] = // Items being debugged
3523 /* { flag, name, description } */
3524 {&arcmsgav, "arcmsgav", "arc to mei message ", 0},
3525 {&cmv_reply, "cmv_reply", "cmv needs reply", 0},
3526 {&cmv_waiting, "cmv_waiting",
3527 "waiting for cmv reply from arc", 0},
3528 {&indicator_count, "indicator_count",
3529 "ARC to MEI indicator count", 0},
3530 {&cmv_count, "cmv_count", "MEI to ARC CMVs", 0},
3531 {&reply_count, "reply_count", "ARC to MEI Reply", 0},
3532 {(int *) Recent_indicator, "Recent_indicator",
3533 "most recent indicator", 0},
3534 {(int *) 8, "version", "version of firmware", 0},
3536 do_gettimeofday (&time_disconnect);
3538 printk ("Danube MEI version:%s\n", IFXMIPS_MEI_VERSION);
3540 memcpy ((char *) regs, (char *) regs_temp, sizeof (regs_temp));
3541 MEI_MUTEX_INIT (mei_sema, 1); // semaphore initialization, mutex
3542 MEI_INIT_WAKELIST ("arcq", wait_queue_arcmsgav); // for ARCMSGAV
3543 MEI_INIT_WAKELIST ("arcldq", wait_queue_loop_diagnostic); // for loop diagnostic function
3544 #ifdef IFX_ADSL_L3_MODE_SUPPORT
3545 MEI_INIT_WAKELIST ("arcl3q", wait_queue_l3); // for l3 power mode
3546 #endif //IFX_ADSL_L3_MODE_SUPPORT
3549 memset (&adsl_mem_info[0], 0, sizeof (smmu_mem_info_t) * MAX_BAR_REGISTERS);
3550 #if defined(CONFIG_IFXMIPS_MEI_LED) && defined(DATA_LED_SUPPORT)
3551 printk("not enabling mei leds due to bug that makes the board hang\n");
3552 // ifxmips_mei_led_init ();
3555 #ifdef CONFIG_IFXMIPS_MEI_MIB
3556 ifxmips_mei_mib_init ();
3559 #ifdef IFXMIPS_CLEAR_EOC
3560 MEI_INIT_WAKELIST ("arceoc", wait_queue_hdlc_poll);
3561 ifxmips_mei_ceoc_init ();
3564 temp = ifxmips_r32(IFXMIPS_PMU_PWDCR);
3566 ifxmips_w32(temp, IFXMIPS_PMU_PWDCR);
3568 #if defined (CONFIG_ATM_IFXMIPS)
3569 IFX_ATM_LED_Callback_Register (adsl_led_flash);
3571 if (register_chrdev (major, IFXMIPS_MEI_DEVNAME, &mei_operations) != 0) {
3572 printk("\n\n unable to register major for ifxmips_mei!!!");
3575 printk("registered ifxmips_mei on #%d\n", major);
3578 disable_irq(IFXMIPS_MEI_INT);
3580 if (request_irq(IFXMIPS_MEI_INT, mei_interrupt_arcmsgav, 0, "ifxmips_mei_arcmsgav", NULL) != 0) {
3581 printk("\n\n unable to register irq(%d) for ifxmips_mei!!!",
3586 // enable_irq(IFXMIPS_MEI_INT);
3588 meidir = proc_mkdir(MEI_DIRNAME, &proc_root);
3591 printk(": can't create /proc/" MEI_DIRNAME "\n\n");
3595 for (i = 0; i < NUM_OF_REG_ENTRY; i++) {
3596 entry = create_proc_entry (regs[i].name,
3597 S_IWUSR | S_IRUSR | S_IRGRP | S_IROTH, meidir);
3600 regs[i].low_ino = entry->low_ino;
3601 entry->proc_fops = &proc_operations;
3603 printk (": can't create /proc/" MEI_DIRNAME "/%s\n\n", regs[i].name);
3608 ///////////////////////////////// register net device ////////////////////////////
3610 DFE_Loopback_Test ();
3611 #endif //DFE_LOOPBACK
3616 ifxmips_mei_cleanup_module (void)
3620 #if defined(CONFIG_IFXMIPS_MEI_LED) && defined(DATA_LED_SUPPORT)
3621 ifxmips_mei_led_cleanup ();
3623 showtime = 0; //joelin,clear task
3625 #ifdef CONFIG_PROC_FS
3626 for (i = 0; i < NUM_OF_REG_ENTRY; i++)
3627 remove_proc_entry (regs[i].name, meidir);
3629 remove_proc_entry (MEI_DIRNAME, &proc_root);
3630 #endif //CONFIG_PROC_FS
3632 #if defined (CONFIG_ATM_IFXMIPS)
3633 IFX_ATM_LED_Callback_Unregister (adsl_led_flash);
3635 disable_irq (IFXMIPS_MEI_INT);
3636 free_irq(IFXMIPS_MEI_INT, NULL);
3638 #ifdef CONFIG_DEVFS_FS
3639 devfs_unregister (mei_devfs_handle);
3641 unregister_chrdev (major, "ifxmips_mei");
3643 #ifdef CONFIG_IFXMIPS_MEI_MIB
3644 ifxmips_mei_mib_cleanup ();
3647 free_image_buffer (FREE_ALL);
3651 EXPORT_SYMBOL (meiDebugRead);
3652 EXPORT_SYMBOL (meiDebugWrite);
3653 EXPORT_SYMBOL (ifx_me_hdlc_send);
3654 EXPORT_SYMBOL (ifx_mei_hdlc_read);
3655 MODULE_LICENSE ("GPL");
3657 module_init (ifxmips_mei_init_module);
3658 module_exit (ifxmips_mei_cleanup_module);