Ejemplo n.º 1
0
static int hsi_ch_write_timeout(int chno, void *buf)
{
	int err = 0, rc = 0;

	rc = wait_event_timeout(hsi_channels[chno].write_wait,
			hsi_channels[chno].write_happening == HSI_FALSE, HSI_WRITE_TIMEOUT);

	if( hsi_mcm_state == HSI_MCM_STATE_ERR_RECOVERY) {
#if MCM_DBG_LOG
		printk("\nmcm:locking 1st mutex end for ch: %d\n", chno);
#endif
		return -EREMOTEIO;
	}

	if (rc == 0) { 
		int ret = hsi_ll_check_channel(chno);

		if(ret == -EPERM) {
			err = -EREMOTEIO;
			
			hsi_channels[chno].write_happening = HSI_FALSE;
			hsi_ll_reset_write_channel(chno);
			hsi_mem_free(buf);
#if MCM_DBG_ERR_LOG
			printk("\nmcm: hsi_ll_check_channel - hsi_ch_write_timeout(...) failed\n");
#endif
		}
		else if(ret == -EACCES){
			hsi_channels[chno].write_happening = HSI_FALSE;
			err = -EREMOTEIO;
			
#if MCM_DBG_ERR_LOG
			printk("\nmcm:unlocking 1st mutex end for ch: %d\n", chno);
#endif
		}
		else if(ret == -EBUSY){
			wait_event(hsi_channels[chno].write_wait,
				hsi_channels[chno].write_happening == HSI_FALSE);

			err = 0;
			
#if MCM_DBG_LOG
			printk("\nmcm:unlocking 2st mutex end for ch: %d\n", chno);
#endif
		}
		else {
			err = 0;
#if MCM_DBG_LOG
			printk("\nmcm:unlocking 3st mutex end for ch: %d\n", chno);
#endif
		}
	}
	else {
#if MCM_DBG_LOG
		printk("\nmcm:unlocking 4st mutex end for ch: %d\n", chno);
#endif
	}

	return err;
}
Ejemplo n.º 2
0
static int hsi_ch_write_timeout(int chno, void *buf, long timeout)
{
	int err = 0, rc = 0, i =0;

#if 1
	while (1) {
		i++;
#else		
	for (i = 0; i < HSI_WRITE_TIMEOUT_TRY; i++) {
#endif
		
		rc = wait_event_timeout(hsi_channels[chno].write_wait,
				hsi_channels[chno].write_happening == HSI_FALSE, timeout);

		if( hsi_mcm_state == HSI_MCM_STATE_ERR_RECOVERY) {
#if MCM_DBG_LOG
			printk("\nmcm:locking 1st mutex end for ch: %d\n", chno);
#endif
			err= -EREMOTEIO;
			break;
		}

		if (rc == 0) {
			int ret = hsi_ll_check_channel(chno);

			
			if(ret == -EPERM) {
				err = -EREMOTEIO;
				
				hsi_channels[chno].write_happening = HSI_FALSE;
				hsi_ll_reset_write_channel(chno);
				hsi_mem_free(buf);
#if MCM_DBG_ERR_LOG
				printk("\nmcm: hsi_ll_check_channel - hsi_ch_write_timeout(...) failed\n");
#endif
				break;
			}
			
			else if(ret == -EACCES){
				hsi_channels[chno].write_happening = HSI_FALSE;
				err = -EREMOTEIO;
				
#if MCM_DBG_ERR_LOG
				printk("\nmcm:unlocking 1st mutex end for ch: %d\n", chno);
#endif
				break;				
			}
#if 0
			
			else if(ret == -EAGAIN){
				rc = wait_event_timeout(hsi_channels[chno].write_wait,
						hsi_channels[chno].write_happening == HSI_FALSE, timeout);

				if (rc == 0) {
					err = -EREMOTEIO;
					hsi_ll_reset_write_channel(chno);
					hsi_mem_free(buf);
#if MCM_DBG_ERR_LOG
					printk("\nmcm: hsi_ll_check_channel - 2st hsi_ch_write_timeout(...) failed\n");
#endif
				}
				else {
					err = 0;
#if MCM_DBG_LOG
					printk("\nmcm:unlocking 2st mutex end for ch: %d\n", chno);
#endif
				}
			}
#endif
			
			else if(ret == -EBUSY){
#if 1
			
#if MCM_DBG_ERR_LOG
				if(i % HSI_WRITE_TIMEOUT_TRY == 0)
					printk("\nmcm:hsi_ch_write_timeout - EBUSY for ch: %d\n", chno);
#endif
				err = -EBUSY;
#else
				wait_event(hsi_channels[chno].write_wait,
					hsi_channels[chno].write_happening == HSI_FALSE);
				err = 0;
#if MCM_DBG_LOG
				printk("\nmcm:unlocking 3st mutex end for ch: %d\n", chno);
#endif
#endif
			}
		
			else {
				err = 0;
#if MCM_DBG_LOG
				printk("\nmcm:unlocking 4st mutex end for ch: %d\n", chno);
#endif
				break;
			}
		}
	
		else { 
			err = 0;
#if MCM_DBG_LOG
			printk("\nmcm:unlocking 4st mutex end for ch: %d\n", chno);
#endif
			break;
		}
	}

#if 0
	if(err == -EBUSY) {
		err = 0;

		hsi_channels[chno].write_happening = HSI_FALSE;
		hsi_ll_reset_write_channel(chno);
		hsi_mem_free(buf);
#if MCM_DBG_ERR_LOG
		printk("\nmcm: hsi_ll_check_channel - EBUSY(...) failed\n");
#endif		
	}
#endif

	return err;
}
#endif

static int hsi_ch_tty_write(int chno, void *data, int len)
{
	void *buf = NULL;
	int err;

	buf = hsi_mem_alloc(len);

	if (!buf) {
		return -ENOMEM;
	}

	memcpy(buf, data, len);

	hsi_channels[chno].write_happening = HSI_TRUE;

	err = hsi_ll_write(chno, (unsigned char *)buf, len);
	
	if (err < 0) {
#if MCM_DBG_ERR_LOG
		printk("\nmcm: hsi_ll_write(...) failed. err=%d\n",err);
#endif

/* Should free in error case */
#if 1
		hsi_mem_free(buf);
#endif


		hsi_channels[chno].write_happening = HSI_FALSE;
	}
#if defined(MIPI_HSI_TTY_WRITE_TIMEOUT_FEATURE)	
	else {
#if MCM_DBG_LOG
		printk("\nmcm:locking mutex start for ch: %d\n", chno);
#endif

#if defined (TARGET_CARRIER_ATT) && !defined (MIPI_HSI_CHECK_CP_RX_INFO)
	
		if(chno == XMD_TTY_CIQ_CHANNEL) {
			wait_event(hsi_channels[chno].write_wait,
				hsi_channels[chno].write_happening == HSI_FALSE);
#if MCM_DBG_LOG
			printk("\nmcm:locking mutex end for ch: %d\n", chno);
#endif
		}
		else
#endif 
		{
			err = hsi_ch_write_timeout(chno, buf, HSI_WRITE_TTY_TIMEOUT);

#if MCM_DBG_LOG
			if (err < 0)
				printk("\nmcm:hsi_ch_write_timeout ret %d for ch: %d\n", err, chno);
#endif
		}

#if defined(HSI_MCM_NOTIFY_TO_CHARGER)
		hsi_ch_notify_to_charger(err);
#endif
	}
#else 
	else {