static int csvt_ctrl_attach(struct usb_serial *serial)
{
	struct csvt_ctrl_dev	*dev;

	dev = kzalloc(sizeof(*dev), GFP_KERNEL);
	if (!dev)
		return -ENOMEM;

	mutex_init(&dev->dev_lock);
	usb_set_serial_port_data(serial->port[0], dev);

	return 0;
}
Exemple #2
0
static void ark3116_release(struct usb_serial *serial)
{
	struct usb_serial_port *port = serial->port[0];
	struct ark3116_private *priv = usb_get_serial_port_data(port);

	/* device is closed, so URBs and DMA should be down */

	usb_set_serial_port_data(port, NULL);

	mutex_destroy(&priv->hw_lock);

	kfree(priv);
}
Exemple #3
0
static int f81232_startup(struct usb_serial *serial)
{
	struct f81232_private *priv;
	int i;

	for (i = 0; i < serial->num_ports; ++i) {
		priv = kzalloc(sizeof(struct f81232_private), GFP_KERNEL);
		if (!priv)
			goto cleanup;
		spin_lock_init(&priv->lock);
		init_waitqueue_head(&priv->delta_msr_wait);
		usb_set_serial_port_data(serial->port[i], priv);
	}
	return 0;

cleanup:
	for (--i; i >= 0; --i) {
		priv = usb_get_serial_port_data(serial->port[i]);
		kfree(priv);
		usb_set_serial_port_data(serial->port[i], NULL);
	}
	return -ENOMEM;
}
static int omninet_attach(struct usb_serial *serial)
{
	struct omninet_data *od;
	struct usb_serial_port *port = serial->port[0];

	od = kmalloc(sizeof(struct omninet_data), GFP_KERNEL);
	if (!od) {
		dev_err(&port->dev, "%s- kmalloc(%Zd) failed.\n",
			__func__, sizeof(struct omninet_data));
		return -ENOMEM;
	}
	usb_set_serial_port_data(port, od);
	return 0;
}
Exemple #5
0
static int ssu100_port_probe(struct usb_serial_port *port)
{
	struct ssu100_port_private *priv;

	priv = kzalloc(sizeof(*priv), GFP_KERNEL);
	if (!priv)
		return -ENOMEM;

	spin_lock_init(&priv->status_lock);

	usb_set_serial_port_data(port, priv);

	return 0;
}
Exemple #6
0
static int metrousb_port_probe(struct usb_serial_port *port)
{
	struct metrousb_private *metro_priv;

	metro_priv = kzalloc(sizeof(*metro_priv), GFP_KERNEL);
	if (!metro_priv)
		return -ENOMEM;

	spin_lock_init(&metro_priv->lock);

	usb_set_serial_port_data(port, metro_priv);

	return 0;
}
Exemple #7
0
/* call when the device plug out. free all the memory alloced by probe */
static void spcp8x5_shutdown(struct usb_serial *serial)
{
	int i;
	struct spcp8x5_private *priv;

	for (i = 0; i < serial->num_ports; i++) {
		priv = usb_get_serial_port_data(serial->port[i]);
		if (priv) {
			free_ringbuf(priv->buf);
			kfree(priv);
			usb_set_serial_port_data(serial->port[i] , NULL);
		}
	}
}
Exemple #8
0
static int f81232_port_probe(struct usb_serial_port *port)
{
	struct f81232_private *priv;

	priv = kzalloc(sizeof(*priv), GFP_KERNEL);
	if (!priv)
		return -ENOMEM;

	spin_lock_init(&priv->lock);
	init_waitqueue_head(&priv->delta_msr_wait);

	usb_set_serial_port_data(port, priv);

	return 0;
}
Exemple #9
0
static int mxu1_port_probe(struct usb_serial_port *port)
{
	struct mxu1_port *mxport;
	struct mxu1_device *mxdev;
	struct urb *urb;

	mxport = kzalloc(sizeof(struct mxu1_port), GFP_KERNEL);
	if (!mxport)
		return -ENOMEM;

	spin_lock_init(&mxport->mxp_lock);
	mutex_init(&mxport->mxp_mutex);

	mxport->mxp_port = port;
	mxdev = usb_get_serial_data(port->serial);

	urb = port->interrupt_in_urb;
	if (!urb) {
		dev_err(&port->dev, "%s - no interrupt urb\n", __func__);
		return -EINVAL;
	}

	switch (mxdev->mxd_model) {
	case MXU1_1110_PRODUCT_ID:
		mxport->mxp_uart_types = MXU1_TYPE_RS232;
		mxport->mxp_uart_mode = MXU1_UART_232;
		break;
	case MXU1_1130_PRODUCT_ID:
	case MXU1_1131_PRODUCT_ID:
		mxport->mxp_uart_types = MXU1_TYPE_RS422 | MXU1_TYPE_RS485;
		mxport->mxp_uart_mode = MXU1_UART_485_RECEIVER_DISABLED;
		break;
	case MXU1_1150_PRODUCT_ID:
	case MXU1_1151_PRODUCT_ID:
		mxport->mxp_uart_types =
			MXU1_TYPE_RS232 | MXU1_TYPE_RS422 | MXU1_TYPE_RS485;
		mxport->mxp_uart_mode = MXU1_UART_232;
		break;
	}

	usb_set_serial_port_data(port, mxport);

	port->port.closing_wait =
			msecs_to_jiffies(MXU1_DEFAULT_CLOSING_WAIT * 10);
	port->port.drain_delay = 1;

	return 0;
}
Exemple #10
0
static int pl2303_port_probe(struct usb_serial_port *port)
{
	struct pl2303_private *priv;

	priv = kzalloc(sizeof(*priv), GFP_KERNEL);
	if (!priv)
		return -ENOMEM;

	spin_lock_init(&priv->lock);

	usb_set_serial_port_data(port, priv);

	port->port.drain_delay = 256;

	return 0;
}
Exemple #11
0
static void mct_u232_shutdown (struct usb_serial *serial)
{
	struct mct_u232_private *priv;
	int i;
	
	dbg("%s", __FUNCTION__);

	for (i=0; i < serial->num_ports; ++i) {
		/* My special items, the standard routines free my urbs */
		priv = usb_get_serial_port_data(serial->port[i]);
		if (priv) {
			usb_set_serial_port_data(serial->port[i], NULL);
			kfree(priv);
		}
	}
} /* mct_u232_shutdown */
Exemple #12
0
static void qt_release(struct usb_serial *serial)
{
	struct usb_serial_port *port;
	struct quatech_port *qt_port;
	int i;

	for (i = 0; i < serial->num_ports; i++) {
		port = serial->port[i];
		if (!port)
			continue;

		qt_port = usb_get_serial_port_data(port);
		kfree(qt_port);
		usb_set_serial_port_data(port, NULL);
	}

}
Exemple #13
0
static int sierra_startup(struct usb_serial *serial)
{
	struct usb_serial_port *port;
	struct sierra_port_private *portdata;
	struct urb *urb;
	int i;
	int j;

	dbg("%s", __FUNCTION__);

	/*Set Device mode to D0 */
	sierra_set_power_state(serial->dev, 0x0000);

	/* Now setup per port private data */
	for (i = 0; i < serial->num_ports; i++) {
		port = serial->port[i];
		portdata = kzalloc(sizeof(*portdata), GFP_KERNEL);
		if (!portdata) {
			dbg("%s: kmalloc for sierra_port_private (%d) failed!.",
					__FUNCTION__, i);
			return -ENOMEM;
		}
		spin_lock_init(&portdata->lock);

		usb_set_serial_port_data(port, portdata);

		/* initialize the in urbs */
		for (j = 0; j < N_IN_URB; ++j) {
			urb = usb_alloc_urb(0, GFP_KERNEL);
			if (urb == NULL) {
				dbg("%s: alloc for in port failed.",
				    __FUNCTION__);
				continue;
			}
			/* Fill URB using supplied data. */
			usb_fill_bulk_urb(urb, serial->dev,
					  usb_rcvbulkpipe(serial->dev,
						port->bulk_in_endpointAddress),
					  portdata->in_buffer[j], IN_BUFLEN,
					  sierra_indat_callback, port);
			portdata->in_urbs[j] = urb;
		}
	}

	return 0;
}
Exemple #14
0
static int sierra_port_probe(struct usb_serial_port *port)
{
	struct usb_serial *serial = port->serial;
	struct sierra_port_private *portdata;
	const struct sierra_iface_info *himemoryp;
	u8 ifnum;

	portdata = kzalloc(sizeof(*portdata), GFP_KERNEL);
	if (!portdata)
		return -ENOMEM;

	spin_lock_init(&portdata->lock);
	init_usb_anchor(&portdata->active);
	init_usb_anchor(&portdata->delayed);

	/* Assume low memory requirements */
	portdata->num_out_urbs = N_OUT_URB;
	portdata->num_in_urbs  = N_IN_URB;

	/* Determine actual memory requirements */
	if (serial->num_ports == 1) {
		/* Get interface number for composite device */
		ifnum = sierra_interface_num(serial);
		himemoryp = &typeB_interface_list;
	} else {
		/* This is really the usb-serial port number of the interface
		 * rather than the interface number.
		 */
		ifnum = port->port_number;
		himemoryp = &typeA_interface_list;
	}

	if (is_himemory(ifnum, himemoryp)) {
		portdata->num_out_urbs = N_OUT_URB_HM;
		portdata->num_in_urbs  = N_IN_URB_HM;
	}

	dev_dbg(&port->dev,
			"Memory usage (urbs) interface #%d, in=%d, out=%d\n",
			ifnum, portdata->num_in_urbs, portdata->num_out_urbs);

	usb_set_serial_port_data(port, portdata);

	return 0;
}
static void ipaq_close(struct usb_serial_port *port, struct file *filp)
{
	struct ipaq_private	*priv = usb_get_serial_port_data(port);

	dbg("%s - port %d", __FUNCTION__, port->number);
			 
	/*
	 * shut down bulk read and write
	 */
	usb_unlink_urb(port->write_urb);
	usb_unlink_urb(port->read_urb);
	ipaq_destroy_lists(port);
	kfree(priv);
	usb_set_serial_port_data(port, NULL);

	/* Uncomment the following line if you want to see some statistics in your syslog */
	/* info ("Bytes In = %d  Bytes Out = %d", bytes_in, bytes_out); */
}
Exemple #16
0
static int spcp8x5_port_probe(struct usb_serial_port *port)
{
	const struct usb_device_id *id = usb_get_serial_data(port->serial);
	struct spcp8x5_private *priv;

	priv = kzalloc(sizeof(*priv), GFP_KERNEL);
	if (!priv)
		return -ENOMEM;

	spin_lock_init(&priv->lock);
	priv->quirks = id->driver_info;

	usb_set_serial_port_data(port, priv);

	port->port.drain_delay = 256;

	return 0;
}
Exemple #17
0
static int ssu100_attach(struct usb_serial *serial)
{
	struct ssu100_port_private *priv;
	struct usb_serial_port *port = *serial->port;

	priv = kzalloc(sizeof(*priv), GFP_KERNEL);
	if (!priv) {
		dev_err(&port->dev, "%s- kmalloc(%Zd) failed.\n", __func__,
			sizeof(*priv));
		return -ENOMEM;
	}

	spin_lock_init(&priv->status_lock);
	init_waitqueue_head(&priv->delta_msr_wait);
	usb_set_serial_port_data(port, priv);

	return ssu100_initdevice(serial->dev);
}
static void metrousb_shutdown(struct usb_serial *serial)
{
	int i = 0;

	dev_dbg(&serial->dev->dev, "%s\n", __func__);

	/*                                        */
	for (i = 0; i < serial->num_ports; ++i) {
		/*                      */
		metrousb_cleanup(serial->port[i]);

		/*              */
		kfree(usb_get_serial_port_data(serial->port[i]));
		usb_set_serial_port_data(serial->port[i], NULL);

		dev_dbg(&serial->dev->dev, "%s - freed port number=%d\n",
			__func__, serial->port[i]->number);
	}
}
static void metrousb_shutdown(struct usb_serial *serial)
{
	int i = 0;

	dev_dbg(&serial->dev->dev, "%s\n", __func__);

	/* Stop reading and writing on all ports. */
	for (i = 0; i < serial->num_ports; ++i) {
		/* Close any open urbs. */
		metrousb_cleanup(serial->port[i]);

		/* Free memory. */
		kfree(usb_get_serial_port_data(serial->port[i]));
		usb_set_serial_port_data(serial->port[i], NULL);

		dev_dbg(&serial->dev->dev, "%s - freed port number=%d\n",
			__func__, serial->port[i]->number);
	}
}
Exemple #20
0
static int cyberjack_port_probe(struct usb_serial_port *port)
{
	struct cyberjack_private *priv;
	int result;

	priv = kmalloc(sizeof(struct cyberjack_private), GFP_KERNEL);
	if (!priv)
		return -ENOMEM;

	spin_lock_init(&priv->lock);
	priv->rdtodo = 0;
	priv->wrfilled = 0;
	priv->wrsent = 0;

	usb_set_serial_port_data(port, priv);

	result = usb_submit_urb(port->interrupt_in_urb, GFP_KERNEL);
	if (result)
		dev_err(&port->dev, "usb_submit_urb(read int) failed\n");

	return 0;
}
Exemple #21
0
static void airprime_close(struct usb_serial_port *port, struct file * filp)
{
	struct airprime_private *priv = usb_get_serial_port_data(port);
	int i;

	dbg("%s - port %d", __FUNCTION__, port->number);

	priv->rts_state = 0;
	priv->dtr_state = 0;

	airprime_send_setup(port);

	for (i = 0; i < NUM_READ_URBS; ++i) {
		usb_kill_urb (priv->read_urbp[i]);
		kfree (priv->read_urbp[i]->transfer_buffer);
		usb_free_urb (priv->read_urbp[i]);
	}

	/* free up private structure */
	kfree (priv);
	usb_set_serial_port_data(port, NULL);
}
Exemple #22
0
static int qt2_port_probe(struct usb_serial_port *port)
{
	struct usb_serial *serial = port->serial;
	struct qt2_port_private *port_priv;
	u8 bEndpointAddress;

	port_priv = kzalloc(sizeof(*port_priv), GFP_KERNEL);
	if (!port_priv)
		return -ENOMEM;

	spin_lock_init(&port_priv->lock);
	spin_lock_init(&port_priv->urb_lock);
	port_priv->port = port;

	port_priv->write_buffer = kmalloc(QT2_WRITE_BUFFER_SIZE, GFP_KERNEL);
	if (!port_priv->write_buffer)
		goto err_buf;

	port_priv->write_urb = usb_alloc_urb(0, GFP_KERNEL);
	if (!port_priv->write_urb)
		goto err_urb;

	bEndpointAddress = serial->port[0]->bulk_out_endpointAddress;
	usb_fill_bulk_urb(port_priv->write_urb, serial->dev,
				usb_sndbulkpipe(serial->dev, bEndpointAddress),
				port_priv->write_buffer,
				QT2_WRITE_BUFFER_SIZE,
				qt2_write_bulk_callback, port);

	usb_set_serial_port_data(port, port_priv);

	return 0;
err_urb:
	kfree(port_priv->write_buffer);
err_buf:
	kfree(port_priv);
	return -ENOMEM;
}
Exemple #23
0
/* do some startup allocations not currently performed by usb_serial_probe() */
static int belkin_sa_startup (struct usb_serial *serial)
{
	struct usb_device *dev = serial->dev;
	struct belkin_sa_private *priv;

	/* allocate the private data structure */
	priv = kmalloc(sizeof(struct belkin_sa_private), GFP_KERNEL);
	if (!priv)
		return (-1); /* error */
	/* set initial values for control structures */
	spin_lock_init(&priv->lock);
	priv->control_state = 0;
	priv->last_lsr = 0;
	priv->last_msr = 0;
	/* see comments at top of file */
	priv->bad_flow_control = (le16_to_cpu(dev->descriptor.bcdDevice) <= 0x0206) ? 1 : 0;
	info("bcdDevice: %04x, bfc: %d", le16_to_cpu(dev->descriptor.bcdDevice), priv->bad_flow_control);

	init_waitqueue_head(&serial->port[0]->write_wait);
	usb_set_serial_port_data(serial->port[0], priv);
	
	return (0);
}
Exemple #24
0
static int ch341_port_probe(struct usb_serial_port *port)
{
	struct ch341_private *priv;
	int r;

	priv = kzalloc(sizeof(struct ch341_private), GFP_KERNEL);
	if (!priv)
		return -ENOMEM;

	spin_lock_init(&priv->lock);
	priv->baud_rate = DEFAULT_BAUD_RATE;
	priv->line_control = CH341_BIT_RTS | CH341_BIT_DTR;

	r = ch341_configure(port->serial->dev, priv);
	if (r < 0)
		goto error;

	usb_set_serial_port_data(port, priv);
	return 0;

error:	kfree(priv);
	return r;
}
Exemple #25
0
static void ipw_disconnect(struct usb_serial *serial)
{
	struct usb_serial_port *port;
	struct ipw_private *priv;

	if (serial) {
		port = &serial->port[0];
		if (port->tty)
			tty_hangup(port->tty);
		priv = usb_get_serial_port_data(port);
		kfree(priv);
		usb_set_serial_port_data(port, NULL);
		if (serial->dev) {
                /* shutdown any bulk reads that might be going on */
			if (serial->num_bulk_out)
				usb_unlink_urb (port->write_urb);
			if (serial->num_bulk_in)
				usb_unlink_urb (port->read_urb);
		}
//2.6		usb_serial_generic_shutdown(serial);
		kfree(serial);
	}
}
Exemple #26
0
static int mct_u232_startup(struct usb_serial *serial)
{
	struct mct_u232_private *priv;
	struct usb_serial_port *port, *rport;

	priv = kzalloc(sizeof(struct mct_u232_private), GFP_KERNEL);
	if (!priv)
		return -ENOMEM;
	spin_lock_init(&priv->lock);
	usb_set_serial_port_data(serial->port[0], priv);

	init_waitqueue_head(&serial->port[0]->write_wait);

	/* Puh, that's dirty */
	port = serial->port[0];
	rport = serial->port[1];
	/* No unlinking, it wasn't submitted yet. */
	usb_free_urb(port->read_urb);
	port->read_urb = rport->interrupt_in_urb;
	rport->interrupt_in_urb = NULL;
	port->read_urb->context = port;

	return 0;
} /* mct_u232_startup */
static int ipaq_open(struct usb_serial_port *port, struct file *filp)
{
	struct usb_serial	*serial = port->serial;
	struct ipaq_private	*priv;
	struct ipaq_packet	*pkt;
	int			i, result = 0;
	int			retries = KP_RETRIES;

	dbg("%s - port %d", __FUNCTION__, port->number);

	bytes_in = 0;
	bytes_out = 0;
	priv = (struct ipaq_private *)kmalloc(sizeof(struct ipaq_private), GFP_KERNEL);
	if (priv == NULL) {
		err("%s - Out of memory", __FUNCTION__);
		return -ENOMEM;
	}
	usb_set_serial_port_data(port, priv);
	priv->active = 0;
	priv->queue_len = 0;
	INIT_LIST_HEAD(&priv->queue);
	INIT_LIST_HEAD(&priv->freelist);

	for (i = 0; i < URBDATA_QUEUE_MAX / PACKET_SIZE; i++) {
		pkt = kmalloc(sizeof(struct ipaq_packet), GFP_KERNEL);
		if (pkt == NULL) {
			goto enomem;
		}
		pkt->data = kmalloc(PACKET_SIZE, GFP_KERNEL);
		if (pkt->data == NULL) {
			kfree(pkt);
			goto enomem;
		}
		pkt->len = 0;
		pkt->written = 0;
		INIT_LIST_HEAD(&pkt->list);
		list_add(&pkt->list, &priv->freelist);
		priv->free_len += PACKET_SIZE;
	}

	/*
	 * Force low latency on. This will immediately push data to the line
	 * discipline instead of queueing.
	 */

	port->tty->low_latency = 1;
	port->tty->raw = 1;
	port->tty->real_raw = 1;

	/*
	 * Lose the small buffers usbserial provides. Make larger ones.
	 */

	kfree(port->bulk_in_buffer);
	kfree(port->bulk_out_buffer);
	port->bulk_in_buffer = kmalloc(URBDATA_SIZE, GFP_KERNEL);
	if (port->bulk_in_buffer == NULL) {
		goto enomem;
	}
	port->bulk_out_buffer = kmalloc(URBDATA_SIZE, GFP_KERNEL);
	if (port->bulk_out_buffer == NULL) {
		kfree(port->bulk_in_buffer);
		goto enomem;
	}
	port->read_urb->transfer_buffer = port->bulk_in_buffer;
	port->write_urb->transfer_buffer = port->bulk_out_buffer;
	port->read_urb->transfer_buffer_length = URBDATA_SIZE;
	port->bulk_out_size = port->write_urb->transfer_buffer_length = URBDATA_SIZE;
	
	/* Start reading from the device */
	usb_fill_bulk_urb(port->read_urb, serial->dev, 
		      usb_rcvbulkpipe(serial->dev, port->bulk_in_endpointAddress),
		      port->read_urb->transfer_buffer, port->read_urb->transfer_buffer_length,
		      ipaq_read_bulk_callback, port);
	result = usb_submit_urb(port->read_urb, GFP_KERNEL);
	if (result) {
		err("%s - failed submitting read urb, error %d", __FUNCTION__, result);
		goto error;
	}

	/*
	 * Send out control message observed in win98 sniffs. Not sure what
	 * it does, but from empirical observations, it seems that the device
	 * will start the chat sequence once one of these messages gets
	 * through. Since this has a reasonably high failure rate, we retry
	 * several times.
	 */

	while (retries--) {
		result = usb_control_msg(serial->dev,
				usb_sndctrlpipe(serial->dev, 0), 0x22, 0x21,
				0x1, 0, NULL, 0, HZ / 10 + 1);
		if (result == 0) {
			return 0;
		}
	}
	err("%s - failed doing control urb, error %d", __FUNCTION__, result);
	goto error;

enomem:
	result = -ENOMEM;
	err("%s - Out of memory", __FUNCTION__);
error:
	ipaq_destroy_lists(port);
	kfree(priv);
	return result;
}
Exemple #28
0
static int hsictty_port_probe(struct usb_serial_port *port)
{
	int i;
	struct urb *urb;
	struct hsictty_port_private *portdata;
	struct usb_serial *serial = port->serial;
#ifndef USE_READ_WORK
	char task_name[50] = { 0 };
#endif

	portdata = kzalloc(sizeof(*portdata), GFP_KERNEL);
	if (!portdata) {
		hsictty_error("%s: alloc mem failed\n", __func__);
		return -ENOMEM;
	}
	portdata->opened = 0;
	portdata->lch_opened = 0;
	portdata->channel = port->number;

	INIT_LIST_HEAD(&portdata->pool);
	spin_lock_init(&portdata->pool_lock);
	sema_init(&portdata->ch_sem_w, 1);
	sema_init(&portdata->ch_sem_r, 1);
	init_completion(&portdata->tx_notifier);
	init_completion(&portdata->rx_push_notifier);
	init_usb_anchor(&portdata->delayed_urb);
#ifdef USE_READ_WORK
	INIT_WORK(&portdata->hsictty_read_work, hsictty_read_work);
#else
	sprintf(task_name, "hsictty_rx_task%d", portdata->channel);
	portdata->thread_exit = 0;
	portdata->rx_task = kthread_create(rx_threadfn, portdata, task_name);
	init_completion(&portdata->rx_notifier);
	if (portdata->rx_task)
		wake_up_process(portdata->rx_task);
#endif

	for (i = 0; i < ARRAY_SIZE(portdata->in_urbs); ++i) {
		urb = usb_alloc_urb(0, GFP_KERNEL);
		if (urb == NULL) {
			hsictty_dbg("%s: in urb alloc failed.\n", __func__);
			goto error;
		}
		portdata->in_urbs[i] = urb;

		portdata->in_buffer[i] =
		    usb_alloc_coherent(serial->dev, IN_BUFLEN, GFP_KERNEL,
				       &urb->transfer_dma);
		if (!portdata->in_buffer[i]) {
			hsictty_dbg
			    ("%s: in urb dma buffer alloc failed.\n", __func__);
			goto error;
		}

		/* Fill URB using supplied data. */
		usb_fill_bulk_urb(urb, serial->dev,
				  usb_sndbulkpipe(serial->dev,
						  port->bulk_in_endpointAddress)
				  | USB_DIR_IN, portdata->in_buffer[i],
				  IN_BUFLEN, hsictty_read_callback, port);
		urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
	}

	for (i = 0; i < ARRAY_SIZE(portdata->out_urbs); ++i) {
		urb = usb_alloc_urb(0, GFP_KERNEL);
		if (urb == NULL) {
			hsictty_dbg("%s: in urb alloc failed.\n", __func__);
			goto error;
		}
		portdata->out_urbs[i] = urb;

		portdata->out_buffer[i] =
		    usb_alloc_coherent(serial->dev, OUT_BUFLEN, GFP_KERNEL,
				       &urb->transfer_dma);
		if (!portdata->out_buffer[i]) {
			hsictty_dbg
			    ("%s: in urb dma buffer alloc failed.\n", __func__);
			goto error;
		}
		/* Fill URB using supplied data. */
		usb_fill_bulk_urb(urb, serial->dev,
				  usb_sndbulkpipe(serial->dev,
						  port->
						  bulk_out_endpointAddress)
				  | USB_DIR_OUT, portdata->out_buffer[i],
				  OUT_BUFLEN, hsictty_write_callback, port);
		urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
	}

	usb_set_serial_port_data(port, portdata);

	return 0;

error:
	for (i = 0; i < ARRAY_SIZE(portdata->out_urbs); ++i) {
		urb = portdata->out_urbs[i];
		if (!urb)
			continue;
		if (portdata->out_buffer[i])
			usb_free_coherent(serial->dev, OUT_BUFLEN,
					  portdata->out_buffer[i],
					  urb->transfer_dma);
		usb_free_urb(urb);
	}

	for (i = 0; i < ARRAY_SIZE(portdata->in_urbs); ++i) {
		urb = portdata->in_urbs[i];
		if (!urb)
			continue;
		if (portdata->in_buffer[i])
			usb_free_coherent(serial->dev, IN_BUFLEN,
					  portdata->in_buffer[i],
					  urb->transfer_dma);
		usb_free_urb(urb);
	}
#ifndef USE_READ_WORK
	if (portdata->rx_task) {
		portdata->thread_exit = 1;
		complete_all(&portdata->rx_notifier);
		kthread_stop(portdata->rx_task);
		portdata->rx_task = NULL;
	}
#endif


	kfree(portdata);

	return -EINVAL;
}
Exemple #29
0
static int airprime_open(struct usb_serial_port *port, struct file *filp)
{
	struct airprime_private *priv = usb_get_serial_port_data(port);
	struct usb_serial *serial = port->serial;
	struct urb *urb;
	char *buffer = NULL;
	int i;
	int result = 0;

	dbg("%s - port %d", __FUNCTION__, port->number);

	/* initialize our private data structure if it isn't already created */
	if (!priv) {
		priv = kzalloc(sizeof(*priv), GFP_KERNEL);
		if (!priv) {
			result = -ENOMEM;
			goto out;
		}
		spin_lock_init(&priv->lock);
		usb_set_serial_port_data(port, priv);
	}

	/* Set some sane defaults */
	priv->rts_state = 1;
	priv->dtr_state = 1;

	for (i = 0; i < NUM_READ_URBS; ++i) {
		buffer = kmalloc(buffer_size, GFP_KERNEL);
		if (!buffer) {
			dev_err(&port->dev, "%s - out of memory.\n",
				__FUNCTION__);
			result = -ENOMEM;
			goto errout;
		}
		urb = usb_alloc_urb(0, GFP_KERNEL);
		if (!urb) {
			kfree(buffer);
			dev_err(&port->dev, "%s - no more urbs?\n",
				__FUNCTION__);
			result = -ENOMEM;
			goto errout;
		}
		usb_fill_bulk_urb(urb, serial->dev,
				  usb_rcvbulkpipe(serial->dev,
						  port->bulk_out_endpointAddress),
				  buffer, buffer_size,
				  airprime_read_bulk_callback, port);
		result = usb_submit_urb(urb, GFP_KERNEL);
		if (result) {
			usb_free_urb(urb);
			kfree(buffer);
			dev_err(&port->dev,
				"%s - failed submitting read urb %d for port %d, error %d\n",
				__FUNCTION__, i, port->number, result);
			goto errout;
		}
		/* remember this urb so we can kill it when the port is closed */
		priv->read_urbp[i] = urb;
	}

	airprime_send_setup(port);

	goto out;

 errout:
	/* some error happened, cancel any submitted urbs and clean up anything that
	   got allocated successfully */

	while (i-- != 0) {
		urb = priv->read_urbp[i];
		buffer = urb->transfer_buffer;
		usb_kill_urb (urb);
		usb_free_urb (urb);
		kfree (buffer);
	}

 out:
	return result;
}
Exemple #30
0
/*****************************************************************************
 * Connect Tech's White Heat serial driver functions
 *****************************************************************************/
static int whiteheat_attach(struct usb_serial *serial)
{
	struct usb_serial_port *command_port;
	struct whiteheat_command_private *command_info;
	struct whiteheat_hw_info *hw_info;
	int pipe;
	int ret;
	int alen;
	__u8 *command;
	__u8 *result;

	command_port = serial->port[COMMAND_PORT];

	pipe = usb_sndbulkpipe(serial->dev,
			command_port->bulk_out_endpointAddress);
	command = kmalloc(2, GFP_KERNEL);
	if (!command)
		goto no_command_buffer;
	command[0] = WHITEHEAT_GET_HW_INFO;
	command[1] = 0;

	result = kmalloc(sizeof(*hw_info) + 1, GFP_KERNEL);
	if (!result)
		goto no_result_buffer;
	/*
	 * When the module is reloaded the firmware is still there and
	 * the endpoints are still in the usb core unchanged. This is the
	 * unlinking bug in disguise. Same for the call below.
	 */
	usb_clear_halt(serial->dev, pipe);
	ret = usb_bulk_msg(serial->dev, pipe, command, 2,
						&alen, COMMAND_TIMEOUT_MS);
	if (ret) {
		dev_err(&serial->dev->dev, "%s: Couldn't send command [%d]\n",
			serial->type->description, ret);
		goto no_firmware;
	} else if (alen != 2) {
		dev_err(&serial->dev->dev, "%s: Send command incomplete [%d]\n",
			serial->type->description, alen);
		goto no_firmware;
	}

	pipe = usb_rcvbulkpipe(serial->dev,
				command_port->bulk_in_endpointAddress);
	/* See the comment on the usb_clear_halt() above */
	usb_clear_halt(serial->dev, pipe);
	ret = usb_bulk_msg(serial->dev, pipe, result,
			sizeof(*hw_info) + 1, &alen, COMMAND_TIMEOUT_MS);
	if (ret) {
		dev_err(&serial->dev->dev, "%s: Couldn't get results [%d]\n",
			serial->type->description, ret);
		goto no_firmware;
	} else if (alen != sizeof(*hw_info) + 1) {
		dev_err(&serial->dev->dev, "%s: Get results incomplete [%d]\n",
			serial->type->description, alen);
		goto no_firmware;
	} else if (result[0] != command[0]) {
		dev_err(&serial->dev->dev, "%s: Command failed [%d]\n",
			serial->type->description, result[0]);
		goto no_firmware;
	}

	hw_info = (struct whiteheat_hw_info *)&result[1];

	dev_info(&serial->dev->dev, "%s: Firmware v%d.%02d\n",
		 serial->type->description,
		 hw_info->sw_major_rev, hw_info->sw_minor_rev);

	command_info = kmalloc(sizeof(struct whiteheat_command_private),
								GFP_KERNEL);
	if (command_info == NULL) {
		dev_err(&serial->dev->dev,
			"%s: Out of memory for port structures\n",
			serial->type->description);
		goto no_command_private;
	}

	mutex_init(&command_info->mutex);
	command_info->port_running = 0;
	init_waitqueue_head(&command_info->wait_command);
	usb_set_serial_port_data(command_port, command_info);
	command_port->write_urb->complete = command_port_write_callback;
	command_port->read_urb->complete = command_port_read_callback;
	kfree(result);
	kfree(command);

	return 0;

no_firmware:
	/* Firmware likely not running */
	dev_err(&serial->dev->dev,
		"%s: Unable to retrieve firmware version, try replugging\n",
		serial->type->description);
	dev_err(&serial->dev->dev,
		"%s: If the firmware is not running (status led not blinking)\n",
		serial->type->description);
	dev_err(&serial->dev->dev,
		"%s: please contact [email protected]\n",
		serial->type->description);
	kfree(result);
	kfree(command);
	return -ENODEV;

no_command_private:
	kfree(result);
no_result_buffer:
	kfree(command);
no_command_buffer:
	return -ENOMEM;
}