Пример #1
0
static ssize_t cxacru_sysfs_store_adsl_config(struct device *dev,
	struct device_attribute *attr, const char *buf, size_t count)
{
	struct cxacru_data *instance = to_usbatm_driver_data(
			to_usb_interface(dev));
	int len = strlen(buf);
	int ret, pos, num;
	__le32 data[CMD_PACKET_SIZE / 4];

	if (!capable(CAP_NET_ADMIN))
		return -EACCES;

	if (instance == NULL)
		return -ENODEV;

	pos = 0;
	num = 0;
	while (pos < len) {
		int tmp;
		u32 index;
		u32 value;

		ret = sscanf(buf + pos, "%x=%x%n", &index, &value, &tmp);
		if (ret < 2)
			return -EINVAL;
		if (index < 0 || index > 0x7f)
			return -EINVAL;
		pos += tmp;

		
		if (buf[pos] == '\n' && pos == len-1)
			pos++;

		data[num * 2 + 1] = cpu_to_le32(index);
		data[num * 2 + 2] = cpu_to_le32(value);
		num++;

		if (pos >= len || num >= CMD_MAX_CONFIG) {
			char log[CMD_MAX_CONFIG * 12 + 1]; 

			data[0] = cpu_to_le32(num);
			ret = cxacru_cm(instance, CM_REQUEST_CARD_DATA_SET,
				(u8 *) data, 4 + num * 8, NULL, 0);
			if (ret < 0) {
				atm_err(instance->usbatm,
					"set card data returned %d\n", ret);
				return -EIO;
			}

			for (tmp = 0; tmp < num; tmp++)
				snprintf(log + tmp*12, 13, " %02x=%08x",
					le32_to_cpu(data[tmp * 2 + 1]),
					le32_to_cpu(data[tmp * 2 + 2]));
			atm_info(instance->usbatm, "config%s\n", log);
			num = 0;
		}
	}

	return len;
}
Пример #2
0
static void speedtch_check_status(struct speedtch_instance_data *instance)
{
	struct usbatm_data *usbatm = instance->usbatm;
	struct atm_dev *atm_dev = usbatm->atm_dev;
	unsigned char *buf = instance->scratch_buffer;
	int down_speed, up_speed, ret;
	unsigned char status;

#ifdef VERBOSE_DEBUG
	atm_dbg(usbatm, "%s entered\n", __func__);
#endif

	ret = speedtch_read_status(instance);
	if (ret < 0) {
		atm_warn(usbatm, "error %d fetching device status\n", ret);
		instance->poll_delay = min(2 * instance->poll_delay, MAX_POLL_DELAY);
		return;
	}

	instance->poll_delay = max(instance->poll_delay / 2, MIN_POLL_DELAY);

	status = buf[OFFSET_7];

	if ((status != instance->last_status) || !status) {
		atm_dbg(usbatm, "%s: line state 0x%02x\n", __func__, status);

		switch (status) {
		case 0:
			atm_dev->signal = ATM_PHY_SIG_LOST;
			if (instance->last_status)
				atm_info(usbatm, "ADSL line is down\n");
			/* It may never resync again unless we ask it to... */
			ret = speedtch_start_synchro(instance);
			break;

		case 0x08:
			atm_dev->signal = ATM_PHY_SIG_UNKNOWN;
			atm_info(usbatm, "ADSL line is blocked?\n");
			break;

		case 0x10:
			atm_dev->signal = ATM_PHY_SIG_LOST;
			atm_info(usbatm, "ADSL line is synchronising\n");
			break;

		case 0x20:
			down_speed = buf[OFFSET_b] | (buf[OFFSET_b + 1] << 8)
				| (buf[OFFSET_b + 2] << 16) | (buf[OFFSET_b + 3] << 24);
			up_speed = buf[OFFSET_b + 4] | (buf[OFFSET_b + 5] << 8)
				| (buf[OFFSET_b + 6] << 16) | (buf[OFFSET_b + 7] << 24);

			if (!(down_speed & 0x0000ffff) && !(up_speed & 0x0000ffff)) {
				down_speed >>= 16;
				up_speed >>= 16;
			}

			atm_dev->link_rate = down_speed * 1000 / 424;
			atm_dev->signal = ATM_PHY_SIG_FOUND;

			atm_info(usbatm,
				 "ADSL line is up (%d kb/s down | %d kb/s up)\n",
				 down_speed, up_speed);
			break;

		default:
			atm_dev->signal = ATM_PHY_SIG_UNKNOWN;
			atm_info(usbatm, "unknown line state %02x\n", status);
			break;
		}
Пример #3
0
static void cxacru_poll_status(struct work_struct *work)
{
	struct cxacru_data *instance =
		container_of(work, struct cxacru_data, poll_work.work);
	u32 buf[CXINF_MAX] = {};
	struct usbatm_data *usbatm = instance->usbatm;
	struct atm_dev *atm_dev = usbatm->atm_dev;
	int keep_polling = 1;
	int ret;

	ret = cxacru_cm_get_array(instance, CM_REQUEST_CARD_INFO_GET, buf, CXINF_MAX);
	if (ret < 0) {
		if (ret != -ESHUTDOWN)
			atm_warn(usbatm, "poll status: error %d\n", ret);

		mutex_lock(&instance->poll_state_serialize);
		if (instance->poll_state != CXPOLL_SHUTDOWN) {
			instance->poll_state = CXPOLL_STOPPED;

			if (ret != -ESHUTDOWN)
				atm_warn(usbatm, "polling disabled, set adsl_state"
						" to 'start' or 'poll' to resume\n");
		}
		mutex_unlock(&instance->poll_state_serialize);
		goto reschedule;
	}

	memcpy(instance->card_info, buf, sizeof(instance->card_info));

	if (instance->adsl_status != buf[CXINF_LINE_STARTABLE]) {
		instance->adsl_status = buf[CXINF_LINE_STARTABLE];

		switch (instance->adsl_status) {
		case 0:
			atm_printk(KERN_INFO, usbatm, "ADSL state: running\n");
			break;

		case 1:
			atm_printk(KERN_INFO, usbatm, "ADSL state: stopped\n");
			break;

		default:
			atm_printk(KERN_INFO, usbatm, "Unknown adsl status %02x\n", instance->adsl_status);
			break;
		}
	}

	if (instance->line_status == buf[CXINF_LINE_STATUS])
		goto reschedule;

	instance->line_status = buf[CXINF_LINE_STATUS];
	switch (instance->line_status) {
	case 0:
		atm_dev->signal = ATM_PHY_SIG_LOST;
		atm_info(usbatm, "ADSL line: down\n");
		break;

	case 1:
		atm_dev->signal = ATM_PHY_SIG_LOST;
		atm_info(usbatm, "ADSL line: attempting to activate\n");
		break;

	case 2:
		atm_dev->signal = ATM_PHY_SIG_LOST;
		atm_info(usbatm, "ADSL line: training\n");
		break;

	case 3:
		atm_dev->signal = ATM_PHY_SIG_LOST;
		atm_info(usbatm, "ADSL line: channel analysis\n");
		break;

	case 4:
		atm_dev->signal = ATM_PHY_SIG_LOST;
		atm_info(usbatm, "ADSL line: exchange\n");
		break;

	case 5:
		atm_dev->link_rate = buf[CXINF_DOWNSTREAM_RATE] * 1000 / 424;
		atm_dev->signal = ATM_PHY_SIG_FOUND;

		atm_info(usbatm, "ADSL line: up (%d kb/s down | %d kb/s up)\n",
		     buf[CXINF_DOWNSTREAM_RATE], buf[CXINF_UPSTREAM_RATE]);
		break;

	case 6:
		atm_dev->signal = ATM_PHY_SIG_LOST;
		atm_info(usbatm, "ADSL line: waiting\n");
		break;

	case 7:
		atm_dev->signal = ATM_PHY_SIG_LOST;
		atm_info(usbatm, "ADSL line: initializing\n");
		break;

	default:
		atm_dev->signal = ATM_PHY_SIG_UNKNOWN;
		atm_info(usbatm, "Unknown line state %02x\n", instance->line_status);
		break;
	}
reschedule:

	mutex_lock(&instance->poll_state_serialize);
	if (instance->poll_state == CXPOLL_STOPPING &&
				instance->adsl_status == 1 && /* stopped */
				instance->line_status == 0) /* down */
		instance->poll_state = CXPOLL_STOPPED;

	if (instance->poll_state == CXPOLL_STOPPED)
		keep_polling = 0;
	mutex_unlock(&instance->poll_state_serialize);

	if (keep_polling)
		schedule_delayed_work(&instance->poll_work,
				round_jiffies_relative(POLL_INTERVAL*HZ));
}