[linuxkernelnewbies] LKML: [EMAIL PROTECTED] ...: USB serial driver - data loss issue.

2008-09-10 Thread Peter Teoh





http://lkml.org/lkml/2005/7/9/6

Hello,

I am facing this issue when i am testing my USB serial driver on Redhat
Linux 2.6.9 , EL version 4  with my application. The driver is written
for OXUSB950 and OXUSB954 devices.
 This application executes a set of transfer for one usb -serial port to
another . I have various combinations of transfers - unidirectional ,
bidirectional . The applications also tries to compare the data that was
sent is actually received on the other port . For bidirectional , a
window of data(1000 bytes)is written and read one byte at a time.
Basically read is slow as compared to writes.  This application gets
incorrect byte . The transfer where the application gets a mismatch is
most of the times the bidirectional test. Application is attached.

My observations - 
With this application , even when I do tty_flip_buffer_push() in the
bottom half  of the usb serial driver the flip count does not become
zero . I find the TTY_DONT_FLIP bit is also remaining set. The point
when the flip count crosses 512  I get an erroneous byte at the
application . This erroneous byte is the byte that is inserted by the
driver when the flip buffer is flipped some time later. Not sure
who/when/why this flip happens. This should be because later the
TTY_DONT_FLIP bit is reset when the line disc is no longer processing
data from the flip buffer.

The bottom half is meant to process the data recieved from the device
and push it to the tty and ldisc above . I have verified that i get
corect data in the bottom half of the driver. However the time when
tty_flip_buffer_push() does not flip the buffer and i do
tty_insert_flip_char() which causes the flip buffer to drop the data.
Note : the driver has the low_latency flag set .

Is this issue related to high baud rate , nature of the application (
read slower than writes) that causes the layer above the driver to go in
this scenario.

Is there any bug/race condition happening in the tty /ldisc layer for
the mentioned kernel version.

I am looking for some pointers to debug this issue. i am novice with the
intricacies of the tty and ldisc layer. I have taken help of Greg's
documents on the linux journal to understand the basics required when
writing usb-serial driver.

How should the usb-serial driver handle this - if for unknown reason the
flip buffer cannot be flipped and the data being that has been pushed
can overrun the buffer. Any inputs ?  

Thanks and Regards,
Monali

relevant Driver code - bottom half 

void rx_work_softint(void *private)
{
	struct usb_serial_port *port;
	struct oxsemi_port *port_info;
	struct usb_serial *serial;
	unsigned char *data;
	struct urb *urb = NULL;
	unsigned long flags;
	unsigned char notification_mask;
	int length;
	int i = 0;
	int throttled;
	struct tty_struct *tty;
	int status = 0;
	int port_number = 0;
	struct oxsemi_serial *device_info;

	oxsemi_dbg("[ENTRY]", TRACE);

	port = (struct usb_serial_port *)private;

	urb  = port-interrupt_in_urb;
	data = ""
	tty = port-tty;
	port_info = usb_get_serial_port_data(port);
	serial = port-serial;
	device_info = usb_get_serial_data(serial);
	port_number = port_info-port-number %
device_info-num_interfaces;


	oxsemi_dbg("Port Number = %d ", TRACE, port_number );
	oxsemi_dbg("Length of URB on INTERRUPT IN : %d", TRACE,
			urb-actual_length);
	oxsemi_debug_data(port-dev, __FUNCTION__, urb-actual_length,
data);

	if (port-open_count == 0) {
		oxsemi_dbg("No ports are opened ", CRITICAL);
		goto continue_read;
	}
	spin_lock_irqsave(port_info-port_lock, flags);
	throttled = port_info-throttled;
	notification_mask = data[NOTIFICATION_BYTE_OFFSET]; 
	oxsemi_dbg("Notification byte = 0x%x",
CRITICAL,notification_mask);
	/* Check if Transmit busy bit is set. */
	/* If set,stop_tx is marked as 1 so that we pause sending to the
port
	 * since the firmware is busy transmitting data to the device
	 */
	if (notification_mask  TRANSMIT_BUSY_MASK) {
		port_info-stop_tx = 1;
	}
	else {
		port_info-stop_tx = 0;
	}
	oxsemi_dbg("port_info-stop_tx = %d ", TRACE,
port_info-stop_tx);
	spin_unlock_irqrestore(port_info-port_lock, flags);
	/* Process the notification byte received */
	oxsemi_process_notifications(notification_mask,port);

	/* If there is data along with the notification byte 
	 * ( i.e urb-actual length  1) the read data needs to be
pushed 
	 * into the tty layer's receive buffer ( flip buffer)
	 */
	if (urb-actual_length  1)  
	{
		/* Check if close is pending.
		 * If close is pending on the port on which data is
received 
		 * then drop data else	send the data to the tty flip
buffer 
		 */
		if (port_info-close_pending) {
			oxsemi_dbg("Close is pending, dropping data on
the floor.",
CRITICAL);
		} 
		else 
		{
			if( throttled ) {
/* We are buffering data in our receive
buffer 
 * as much as possible during the
throttle time
 */
length = urb-actual_length - 1;

length = min((int)length,
(int)(OXSEMI_RX_BUFFER_SIZE -
port_info-rx_buffer_length));

[linuxkernelnewbies] IDE APIs

2008-09-10 Thread Peter Teoh





ide-atapi.c:EXPORT_SYMBOL_GPL(ide_pc_intr);
ide-atapi.c:EXPORT_SYMBOL_GPL(ide_transfer_pc);
ide-atapi.c:EXPORT_SYMBOL_GPL(ide_issue_pc);
ide.c:EXPORT_SYMBOL(ide_lock);
ide.c:EXPORT_SYMBOL_GPL(ide_port_unregister_devices);
ide.c:EXPORT_SYMBOL_GPL(ide_setting_mtx);
ide.c:EXPORT_SYMBOL(ide_spin_wait_hwgroup);
ide.c:EXPORT_SYMBOL(generic_ide_ioctl);
ide.c:EXPORT_SYMBOL_GPL(ide_device_get);
ide.c:EXPORT_SYMBOL_GPL(ide_device_put);
ide.c:EXPORT_SYMBOL_GPL(ide_bus_type);
ide.c:EXPORT_SYMBOL_GPL(ide_vlb_clk);
ide.c:EXPORT_SYMBOL_GPL(ide_pci_clk);
ide-dma.c:EXPORT_SYMBOL_GPL(ide_dma_intr);
ide-dma.c:EXPORT_SYMBOL_GPL(ide_build_sglist);
ide-dma.c:EXPORT_SYMBOL_GPL(ide_build_dmatable);
ide-dma.c:EXPORT_SYMBOL_GPL(ide_destroy_dmatable);
ide-dma.c:EXPORT_SYMBOL_GPL(ide_dma_host_set);
ide-dma.c:EXPORT_SYMBOL(ide_dma_off_quietly);
ide-dma.c:EXPORT_SYMBOL(ide_dma_off);
ide-dma.c:EXPORT_SYMBOL_GPL(ide_dma_setup);
ide-dma.c:EXPORT_SYMBOL_GPL(ide_dma_exec_cmd);
ide-dma.c:EXPORT_SYMBOL_GPL(ide_dma_start);
ide-dma.c:EXPORT_SYMBOL(__ide_dma_end);
ide-dma.c:EXPORT_SYMBOL_GPL(ide_dma_test_irq);
ide-dma.c:EXPORT_SYMBOL(__ide_dma_bad_drive);
ide-dma.c:EXPORT_SYMBOL_GPL(ide_find_dma_mode);
ide-dma.c:EXPORT_SYMBOL(ide_dma_lost_irq);
ide-dma.c:EXPORT_SYMBOL(ide_dma_timeout);
ide-dma.c:EXPORT_SYMBOL_GPL(ide_allocate_dma_engine);
ide-dma.c:EXPORT_SYMBOL_GPL(sff_dma_ops);
ide-io.c:EXPORT_SYMBOL(ide_end_request);
ide-io.c:EXPORT_SYMBOL_GPL(ide_end_dequeued_request);
ide-io.c:EXPORT_SYMBOL(ide_end_drive_cmd);
ide-io.c:EXPORT_SYMBOL_GPL(__ide_error);
ide-io.c:EXPORT_SYMBOL_GPL(ide_error);
ide-io.c:EXPORT_SYMBOL_GPL(ide_map_sg);
ide-io.c:EXPORT_SYMBOL_GPL(ide_init_sg_cmd);
ide-io.c:EXPORT_SYMBOL(ide_stall_queue);
ide-io.c:EXPORT_SYMBOL(ide_do_drive_cmd);
ide-io.c:EXPORT_SYMBOL_GPL(ide_pktcmd_tf_load);
ide-io.c:EXPORT_SYMBOL_GPL(ide_pad_transfer);
ide-iops.c:EXPORT_SYMBOL_GPL(ide_exec_command);
ide-iops.c:EXPORT_SYMBOL_GPL(ide_read_status);
ide-iops.c:EXPORT_SYMBOL_GPL(ide_read_altstatus);
ide-iops.c:EXPORT_SYMBOL_GPL(ide_read_sff_dma_status);
ide-iops.c:EXPORT_SYMBOL_GPL(ide_set_irq);
ide-iops.c:EXPORT_SYMBOL_GPL(ide_tf_load);
ide-iops.c:EXPORT_SYMBOL_GPL(ide_tf_read);
ide-iops.c:EXPORT_SYMBOL_GPL(ide_input_data);
ide-iops.c:EXPORT_SYMBOL_GPL(ide_output_data);
ide-iops.c:EXPORT_SYMBOL_GPL(ide_read_error);
ide-iops.c:EXPORT_SYMBOL_GPL(ide_read_bcount_and_ireason);
ide-iops.c:EXPORT_SYMBOL(ide_fixstring);
ide-iops.c:EXPORT_SYMBOL(drive_is_ready);
ide-iops.c:EXPORT_SYMBOL(ide_wait_stat);
ide-iops.c:EXPORT_SYMBOL_GPL(ide_in_drive_list);
ide-iops.c:EXPORT_SYMBOL(ide_set_handler);
ide-iops.c:EXPORT_SYMBOL(ide_execute_command);
ide-iops.c:EXPORT_SYMBOL_GPL(ide_execute_pkt_cmd);
ide-iops.c:EXPORT_SYMBOL(ide_do_reset);
ide-iops.c:EXPORT_SYMBOL_GPL(ide_wait_not_busy);
ide-lib.c:EXPORT_SYMBOL(ide_xfer_verbose);
ide-lib.c:EXPORT_SYMBOL_GPL(ide_get_best_pio_mode);
ide-lib.c:EXPORT_SYMBOL_GPL(ide_set_pio);
ide-lib.c:EXPORT_SYMBOL_GPL(ide_set_dma_mode);
ide-lib.c:EXPORT_SYMBOL_GPL(ide_get_lba_addr);
ide-lib.c:EXPORT_SYMBOL(ide_dump_status);
ide_new.c:EXPORT_SYMBOL(ide_hwifs);
ide_new.c:EXPORT_SYMBOL_GPL(ide_init_port_data);
ide_new.c:EXPORT_SYMBOL_GPL(ide_find_port);
ide_new.c:EXPORT_SYMBOL(ide_unregister);
ide_new.c:EXPORT_SYMBOL_GPL(ide_init_port_hw);
ide_new.c:EXPORT_SYMBOL_GPL(ide_deprecated_find_port);
ide_new.c:EXPORT_SYMBOL(ide_register_hw);
ide_new.c:EXPORT_SYMBOL_GPL(ide_setting_mtx);
ide_new.c:EXPORT_SYMBOL(ide_spin_wait_hwgroup);
ide_new.c:EXPORT_SYMBOL(system_bus_clock);
ide_new.c:EXPORT_SYMBOL(generic_ide_ioctl);
ide_new.c:EXPORT_SYMBOL(ide_lock);
ide_new.c:EXPORT_SYMBOL_GPL(ide_bus_type);
ide-probe.c:EXPORT_SYMBOL_GPL(ide_undecoded_slave);
ide-probe.c:EXPORT_SYMBOL_GPL(ide_register_region);
ide-probe.c:EXPORT_SYMBOL_GPL(ide_unregister_region);
ide-probe.c:EXPORT_SYMBOL_GPL(ide_init_disk);
ide-probe.c:EXPORT_SYMBOL_GPL(ide_host_alloc_all);
ide-probe.c:EXPORT_SYMBOL_GPL(ide_host_alloc);
ide-probe.c:EXPORT_SYMBOL_GPL(ide_host_register);
ide-probe.c:EXPORT_SYMBOL_GPL(ide_host_add);
ide-probe.c:EXPORT_SYMBOL_GPL(ide_host_free);
ide-probe.c:EXPORT_SYMBOL_GPL(ide_host_remove);
ide-probe.c:EXPORT_SYMBOL_GPL(ide_port_scan);
ide-probe.c:EXPORT_SYMBOL_GPL(ide_legacy_device_add);
ide-proc.c:EXPORT_SYMBOL(ide_add_setting);
ide-proc.c:EXPORT_SYMBOL_GPL(proc_ide_read_capacity);
ide-proc.c:EXPORT_SYMBOL(proc_ide_read_geometry);
ide-proc.c:EXPORT_SYMBOL(ide_proc_register_driver);
ide-proc.c:EXPORT_SYMBOL(ide_proc_unregister_driver);
ide-scan-pci.c:EXPORT_SYMBOL_GPL(__ide_pci_register_driver);
ide-taskfile.c:EXPORT_SYMBOL_GPL(do_rw_taskfile);
ide-taskfile.c:EXPORT_SYMBOL(ide_raw_taskfile);
ide-taskfile.c:EXPORT_SYMBOL_GPL(ide_no_data_taskfile);
ide-timings.c:EXPORT_SYMBOL_GPL(ide_timing_find_mode);
ide-timings.c:EXPORT_SYMBOL_GPL(ide_pio_cycle_time);
ide-timings.c:EXPORT_SYMBOL_GPL(ide_timing_merge);
ide-timings.c:EXPORT_SYMBOL_GPL(ide_timing_compute);
setup-pci.c:EXPORT_SYMBOL_GPL(ide_pci_dma_base);
setup-pci.c:EXPORT_SYMBOL_GPL(ide_pci_check_simplex);

[linuxkernelnewbies] LKML: Rene Herman: Driver model ISA bus

2008-09-10 Thread Peter Teoh





http://lkml.org/lkml/2006/6/6/239


  

  
  
  
  

  
Enter your
search termsSubmit
search formWeblkml.org
  



  Date
  Tue, 06 Jun 2006 23:54:02 +0200


  From
  Rene Herman 


  Subject
  Driver model ISA bus


  
  
  
  

  

Hi Greg.

The below was sent a month ago and I haven't heard anything back. Saw 
you saying "it's getting there" about this thing on the kernelnewbies 
list but where's there?

Signed-off-by: Rene Herman [EMAIL PROTECTED]

===
During the recent "isa drivers using platform devices" discussion it was
pointed out that (ALSA) ISA drivers ran into the problem of not having
the option to fail driver load (device registration rather) upon not
finding their hardware due to a probe() error not being passed up
through the driver model. In the course of that, I suggested a seperate
ISA bus might be best; Russell King agreed and suggested this bus could
use the .match() method for the actual device discovery.

The attached does this. For this old non (generically) discoverable ISA
hardware only the driver itself can do discovery so as a difference with
the platform_bus, this isa_bus also distributes match() up to the driver.

As another difference: these devices only exist in the driver model due
to the driver creating them because it might want to drive them, meaning
that all device creation has been made internal as well.

The usage model this provides is nice, and has been acked from the ALSA
side by Takashi Iwai and Jaroslav Kysela. The ALSA driver module_init's
now (for oldisa-only drivers) become:

static int __init alsa_card_foo_init(void)
{
	return isa_register_driver(snd_foo_isa_driver, SNDRV_CARDS);
}
static void __exit alsa_card_foo_exit(void)
{
	isa_unregister_driver(snd_foo_isa_driver);
}
Quite like the other bus models therefore. This removes a lot of
duplicated init code from the ALSA ISA drivers.

The passed in isa_driver struct is the regular driver struct embedding a
struct device_driver, the normal probe/remove/shutdown/suspend/resume
callbacks, and as indicated that .match callback.

The "SNDRV_CARDS" you see being passed in is a "unsigned int ndev"
parameter, indicating how many devices to create and call our methods with.

The platform_driver callbacks are called with a platform_device param;
the isa_driver callbacks are being called with a "struct device *dev,
unsigned int id" pair directly -- with the device creation completely
internal to the bus it's much cleaner to not leak isa_dev's by passing
them in at all. The id is the only thing we ever want other then the
struct device * anyways, and it makes for nicer code in the callbacks as
well.

With this additional .match() callback ISA drivers have all options. If
ALSA would want to keep the old non-load behaviour, it could stick all
of the old .probe in .match, which would only keep them registered after
everything was found to be present and accounted for. If it wanted the
behaviour of always loading as it inadvertently did for a bit after the
changeover to platform devices, it could just not provide a .match() and
do everything in .probe() as before.

If it, as Takashi Iwai already suggested earlier as a way of following
the model from saner buses more closely, wants to load when a later bind
could conceivably succeed, it could use .match() for the prerequisites
(such as checking the user wants the card enabled and that port/irq/dma
values have been passed in) and .probe() for everything else. This is
the nicest model.

To the code...

This exports only two functions; isa_{,un}register_driver().
isa_register_driver() register's the struct device_driver, and then
loops over the passed in ndev creating devices and registering them.
This causes the bus match method to be called for them, which is:

int isa_bus_match(struct device *dev, struct device_driver *driver)
{
  struct isa_driver *isa_driver = to_isa_driver(driver);
  if (dev-platform_data == isa_driver) {
  if (!isa_driver-match ||
  isa_driver-match(dev, to_isa_dev(dev)-id))
  return 1;
  dev-platform_data = NULL;
  }
  return 0;
}
The first thing this does is check if this device is in fact one of this
driver's devices by seeing if the device's platform_data pointer is set
to this driver. Platform devices compare strings, but we don't need to
do that with everything being internal, so isa_register_driver() abuses
dev-platform_data as a isa_driver pointer which we can then check here.
I believe platform_data is available for this, but if rather not, moving
the isa_driver pointer to the private struct isa_dev is ofcourse fine as
well.

Then, if the the driver did not provide a .match, it matches. If it did,
the driver match() method is called to determine a match.

If it did _not_ match, dev-platform_data is reset to indicate this 

[linuxkernelnewbies] LKML: Evgeniy Polyakov: [1/1] Block device throttling [Re: Distributed storage.]

2008-09-10 Thread Peter Teoh





http://lkml.org/lkml/2007/8/8/147


  

  From
  Evgeniy Polyakov 
  
  
  
  


  Subject
  [1/1] Block device throttling [Re: Distributed
storage.]

  

This throttling mechanism allows to limit maximum amount of queued bios 
per physical device. By default it is turned off and old block layer 
behaviour with unlimited number of bios is used. When turned on (queue
limit is set to something different than -1U via blk_set_queue_limit()),
generic_make_request() will sleep until there is room in the queue.
number of bios is increased in generic_make_request() and reduced either
in bio_endio(), when bio is completely processed (bi_size is zero), and
recharged from original queue when new device is assigned to bio via
blk_set_bdev(). All oerations are not atomic, since we do not care about
precise number of bios, but a fact, that we are close or close enough to
the limit.

Tested on distributed storage device - with limit of 2 bios it works
slow :)

Signed-off-by: Evgeniy Polyakov [EMAIL PROTECTED]

diff --git a/block/ll_rw_blk.c b/block/ll_rw_blk.c
index c99b463..1882c9b 100644
--- a/block/ll_rw_blk.c
+++ b/block/ll_rw_blk.c
@@ -1851,6 +1851,10 @@ request_queue_t *blk_alloc_queue_node(gfp_t gfp_mask, int node_id)
 	q-backing_dev_info.unplug_io_fn = blk_backing_dev_unplug;
 	q-backing_dev_info.unplug_io_data = q;
 
+	q-bio_limit = -1U;
+	q-bio_queued = 0;
+	init_waitqueue_head(q-wait);
+
 	mutex_init(q-sysfs_lock);
 
 	return q;
@@ -3237,6 +3241,16 @@ end_io:
  */
 void generic_make_request(struct bio *bio)
 {
+	request_queue_t *q;
+
+	BUG_ON(!bio-bi_bdev)
+
+	q = bdev_get_queue(bio-bi_bdev);
+	if (q  q-bio_limit != -1U) {
+		wait_event_interruptible(q-wait, q-bio_queued + 1 = q-bio_limit);
+		q-bio_queued++;
+	}
+
 	if (current-bio_tail) {
 		/* make_request is active */
 		*(current-bio_tail) = bio;
diff --git a/fs/bio.c b/fs/bio.c
index 093345f..0a33958 100644
--- a/fs/bio.c
+++ b/fs/bio.c
@@ -1028,6 +1028,16 @@ void bio_endio(struct bio *bio, unsigned int bytes_done, int error)
 	bio-bi_size -= bytes_done;
 	bio-bi_sector += (bytes_done  9);
 
+	if (!bio-bi_size  bio-bi_bdev) {
+		request_queue_t *q;
+
+		q = bdev_get_queue(bio-bi_bdev);
+		if (q) {
+			q-bio_queued--;
+			wake_up(q-wait);
+		}
+	}
+
 	if (bio-bi_end_io)
 		bio-bi_end_io(bio, bytes_done, error);
 }
diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
index db5b00a..7ce0cd7 100644
--- a/include/linux/blkdev.h
+++ b/include/linux/blkdev.h
@@ -467,6 +467,9 @@ struct request_queue
 	struct request		*orig_bar_rq;
 	unsigned int		bi_size;
 
+	wait_queue_head_t	wait;
+	unsigned int		bio_limit, bio_queued;
+
 	struct mutex		sysfs_lock;
 };
 
@@ -764,6 +767,30 @@ extern long nr_blockdev_pages(void);
 int blk_get_queue(request_queue_t *);
 request_queue_t *blk_alloc_queue(gfp_t);
 request_queue_t *blk_alloc_queue_node(gfp_t, int);
+
+static inline void blk_queue_set_limit(request_queue_t *q, unsigned int limit)
+{
+	q-bio_limit = limit;
+}
+
+static inline void blk_set_bdev(struct bio *bio, struct block_device *bdev)
+{
+	request_queue_t *q;
+
+	if (!bio-bi_bdev) {
+		bio-bi_bdev = bdev;
+		return;
+	}
+	
+	q = bdev_get_queue(bio-bi_bdev);
+	if (q) {
+		q-bio_queued--;
+		wake_up(q-wait);
+	}
+
+	bio-bi_bdev = bdev;
+}
+
 extern void blk_put_queue(request_queue_t *);
 
 /*
--