Exemplo n.º 1
0
/*
 * Read data from the device (when in normal)
 *
 * Allocate an SKB of the right size, read the data in and then
 * deliver it to the generic layer.
 *
 * We also check for a reboot barker. That means the device died and
 * we have to reboot it.
 */
static
void i2400ms_rx(struct i2400ms *i2400ms)
{
	int ret;
	struct sdio_func *func = i2400ms->func;
	struct device *dev = &func->dev;
	struct i2400m *i2400m = &i2400ms->i2400m;
	struct sk_buff *skb;
	ssize_t rx_size;

	d_fnstart(7, dev, "(i2400ms %p)\n", i2400ms);
	rx_size = __i2400ms_rx_get_size(i2400ms);
	if (rx_size < 0) {
		ret = rx_size;
		goto error_get_size;
	}

	ret = -ENOMEM;
	skb = alloc_skb(rx_size, GFP_ATOMIC);
	if (NULL == skb) {
		dev_err(dev, "RX: unable to alloc skb\n");
		goto error_alloc_skb;
	}
	ret = sdio_memcpy_fromio(func, skb->data,
				 I2400MS_DATA_ADDR, rx_size);
	if (ret < 0) {
		dev_err(dev, "RX: SDIO data read failed: %d\n", ret);
		goto error_memcpy_fromio;
	}

	rmb();	/* make sure we get boot_mode from dev_reset_handle */
	if (i2400m->boot_mode == 1) {
		spin_lock(&i2400m->rx_lock);
		i2400ms->bm_ack_size = rx_size;
		spin_unlock(&i2400m->rx_lock);
		memcpy(i2400m->bm_ack_buf, skb->data, rx_size);
		wake_up(&i2400ms->bm_wfa_wq);
		dev_err(dev, "RX: SDIO boot mode message\n");
		kfree_skb(skb);
	} else if (unlikely(!memcmp(skb->data, i2400m_NBOOT_BARKER,
				    sizeof(i2400m_NBOOT_BARKER))
			    || !memcmp(skb->data, i2400m_SBOOT_BARKER,
				       sizeof(i2400m_SBOOT_BARKER)))) {
		ret = i2400m_dev_reset_handle(i2400m);
		dev_err(dev, "RX: SDIO reboot barker\n");
		kfree_skb(skb);
	} else {
		skb_put(skb, rx_size);
		i2400m_rx(i2400m, skb);
	}
	d_fnend(7, dev, "(i2400ms %p) = void\n", i2400ms);
	return;

error_memcpy_fromio:
	kfree_skb(skb);
error_alloc_skb:
error_get_size:
	d_fnend(7, dev, "(i2400ms %p) = %d\n", i2400ms, ret);
	return;
}
Exemplo n.º 2
0
/*
 * Process a received notification
 *
 * In normal operation mode, we can only receive two types of payloads
 * on the notification endpoint:
 *
 *   - a reboot barker, we do a bootstrap (the device has reseted).
 *
 *   - a block of zeroes: there is pending data in the IN endpoint
 */
static
int i2400mu_notification_grok(struct i2400mu *i2400mu, const void *buf,
				 size_t buf_len)
{
	int ret;
	struct device *dev = &i2400mu->usb_iface->dev;
	struct i2400m *i2400m = &i2400mu->i2400m;

	d_fnstart(4, dev, "(i2400m %p buf %p buf_len %zu)\n",
		  i2400mu, buf, buf_len);
	ret = -EIO;
	if (buf_len < sizeof(i2400m_ZERO_BARKER))
		/* Not a bug, just ignore */
		goto error_bad_size;
	ret = 0;
	if (!memcmp(i2400m_ZERO_BARKER, buf, sizeof(i2400m_ZERO_BARKER))) {
		i2400mu_rx_kick(i2400mu);
		goto out;
	}
	ret = i2400m_is_boot_barker(i2400m, buf, buf_len);
	if (unlikely(ret >= 0))
		ret = i2400m_dev_reset_handle(i2400m, "device rebooted");
	else	/* Unknown or unexpected data in the notif message */
		i2400m_unknown_barker(i2400m, buf, buf_len);
error_bad_size:
out:
	d_fnend(4, dev, "(i2400m %p buf %p buf_len %zu) = %d\n",
		i2400mu, buf, buf_len, ret);
	return ret;
}
Exemplo n.º 3
0
static
int i2400mu_reset_resume(struct usb_interface *iface)
{
	int result;
	struct device *dev = &iface->dev;
	struct i2400mu *i2400mu = usb_get_intfdata(iface);
	struct i2400m *i2400m = &i2400mu->i2400m;

	d_fnstart(3, dev, "(iface %p)\n", iface);
	result = i2400m_dev_reset_handle(i2400m, "device reset on resume");
	d_fnend(3, dev, "(iface %p) = %d\n", iface, result);
	return result < 0 ? result : 0;
}
Exemplo n.º 4
0
/*
 * Read data from the device (when in normal)
 *
 * Allocate an SKB of the right size, read the data in and then
 * deliver it to the generic layer.
 *
 * We also check for a reboot barker. That means the device died and
 * we have to reboot it.
 */
static
void i2400ms_rx(struct i2400ms *i2400ms)
{
	int ret;
	struct sdio_func *func = i2400ms->func;
	struct device *dev = &func->dev;
	struct i2400m *i2400m = &i2400ms->i2400m;
	struct sk_buff *skb;
	ssize_t rx_size;

	d_fnstart(7, dev, "(i2400ms %p)\n", i2400ms);
	rx_size = __i2400ms_rx_get_size(i2400ms);
	if (rx_size < 0) {
		ret = rx_size;
		goto error_get_size;
	}
	ret = -ENOMEM;
	skb = alloc_skb(rx_size, GFP_ATOMIC);
	if (NULL == skb) {
		dev_err(dev, "RX: unable to alloc skb\n");
		goto error_alloc_skb;
	}

	ret = sdio_memcpy_fromio(func, skb->data,
				 I2400MS_DATA_ADDR, rx_size);
	if (ret < 0) {
		dev_err(dev, "RX: SDIO data read failed: %d\n", ret);
		goto error_memcpy_fromio;
	}
	/* Check if device has reset */
	if (!memcmp(skb->data, i2400m_NBOOT_BARKER,
		    sizeof(i2400m_NBOOT_BARKER))
	    || !memcmp(skb->data, i2400m_SBOOT_BARKER,
		       sizeof(i2400m_SBOOT_BARKER))) {
		ret = i2400m_dev_reset_handle(i2400m);
		kfree_skb(skb);
	} else {
		skb_put(skb, rx_size);
		i2400m_rx(i2400m, skb);
	}
	d_fnend(7, dev, "(i2400ms %p) = void\n", i2400ms);
	return;

error_memcpy_fromio:
	kfree_skb(skb);
error_alloc_skb:
error_get_size:
	d_fnend(7, dev, "(i2400ms %p) = %d\n", i2400ms, ret);
	return;
}
Exemplo n.º 5
0
static
void i2400ms_rx(struct i2400ms *i2400ms)
{
	int ret;
	struct sdio_func *func = i2400ms->func;
	struct device *dev = &func->dev;
	struct i2400m *i2400m = &i2400ms->i2400m;
	struct sk_buff *skb;
	ssize_t rx_size;

	d_fnstart(7, dev, "(i2400ms %p)\n", i2400ms);
	rx_size = __i2400ms_rx_get_size(i2400ms);
	if (rx_size < 0) {
		ret = rx_size;
		goto error_get_size;
	}
	sdio_writeb(func, 1, I2400MS_INTR_CLEAR_ADDR, &ret);

	ret = -ENOMEM;
	skb = alloc_skb(rx_size, GFP_ATOMIC);
	if (NULL == skb) {
		dev_err(dev, "RX: unable to alloc skb\n");
		goto error_alloc_skb;
	}
	ret = sdio_memcpy_fromio(func, skb->data,
				 I2400MS_DATA_ADDR, rx_size);
	if (ret < 0) {
		dev_err(dev, "RX: SDIO data read failed: %d\n", ret);
		goto error_memcpy_fromio;
	}

	rmb();	
	if (unlikely(i2400m->boot_mode == 1)) {
		spin_lock(&i2400m->rx_lock);
		i2400ms->bm_ack_size = rx_size;
		spin_unlock(&i2400m->rx_lock);
		memcpy(i2400m->bm_ack_buf, skb->data, rx_size);
		wake_up(&i2400ms->bm_wfa_wq);
		d_printf(5, dev, "RX: SDIO boot mode message\n");
		kfree_skb(skb);
		goto out;
	}
	ret = -EIO;
	if (unlikely(rx_size < sizeof(__le32))) {
		dev_err(dev, "HW BUG? only %zu bytes received\n", rx_size);
		goto error_bad_size;
	}
	if (likely(i2400m_is_d2h_barker(skb->data))) {
		skb_put(skb, rx_size);
		i2400m_rx(i2400m, skb);
	} else if (unlikely(i2400m_is_boot_barker(i2400m,
						  skb->data, rx_size))) {
		ret = i2400m_dev_reset_handle(i2400m, "device rebooted");
		dev_err(dev, "RX: SDIO reboot barker\n");
		kfree_skb(skb);
	} else {
		i2400m_unknown_barker(i2400m, skb->data, rx_size);
		kfree_skb(skb);
	}
out:
	d_fnend(7, dev, "(i2400ms %p) = void\n", i2400ms);
	return;

error_memcpy_fromio:
	kfree_skb(skb);
error_alloc_skb:
error_get_size:
error_bad_size:
	d_fnend(7, dev, "(i2400ms %p) = %d\n", i2400ms, ret);
}