Skip to contentSkip to conversation

blk API update (and bug fix) to CDU535 cdrom driver

PATCH In review Felipe W Damasio 2 participants 3 messages Sep 9, 2003 4 messages not in the archive

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

A message that is not in the archive (sent off-list or not yet received): [email protected]

A message that is not in the archive (sent off-list or not yet received): [email protected]

A message that is not in the archive (sent off-list or not yet received): [email protected]

#4 lore raw

PATCH 1/1 blk API update (and bug fix) to CDU535 cdrom driver

Hi Jens,

Quoted 17 lines · Jens Axboe

held! Ugh, and the request function do_cdu535_request calls schedule_timeout with the queue lock held (that is held when that function is entered), that is very buggy as well. Should also use set_current_state() right above that call, not open code it (that also misses a memory barrier). Same function also has problems with request handling. You should kill:

	if (!(req->flags & REQ_CMD))
		continue;       /* FIXME */

that is very broken, make that:

	if (!blk_fs_request(req)) {
		end_request(req, 0);
		continue;
	}
Quoted 8 lines

and kill these two lines:

	if (rq_data_dir(req) != READ)
		panic("Unknown SONY CD cmd");

they are screwy too.

Care to fix the things I outlined above?

This patch I think fixes all these, doesn't it?

It applies on top of my latest cli-sti-removal patch that I sent you.

The only place I'm not sure is on releasing the queue lock before
calling schedule_timeout.

Please apply if it looks good to you.

Thanks for all your help!

Felipe

drivers/cdrom/sonycd535.c +8 -6
@@ -812,14 +812,14 @@
 
 		block = req->sector;
 		nsect = req->nr_sectors;
-		if (!(req->flags & REQ_CMD))
-			continue;	/* FIXME */
+		if (!blk_fs_request(req)) {
+			end_request(req, 0);
+			continue;
+		}
 		if (rq_data_dir(req) == WRITE) {
 			end_request(req, 0);
 			continue;
 		}
-		if (rq_data_dir(req) != READ)
-			panic("Unknown SONY CD cmd");
 		/*
 		 * If the block address is invalid or the request goes beyond
 		 * the end of the media, return an error.
@@ -896,8 +896,10 @@
 					}
 					if (readStatus == BAD_STATUS) {
 						/* Sleep for a while, then retry */
-						current->state = TASK_INTERRUPTIBLE;
+						set_current_state(TASK_INTERRUPTIBLE);
+						spin_unlock_irq(&sonycd535_lock);
 						schedule_timeout(RETRY_FOR_BAD_STATUS*HZ/10);
+						spin_lock_irq(&sonycd535_lock);
 					}
 #if DEBUG > 0
 					printk(CDU535_MESSAGE_NAME
@@ -1481,7 +1483,7 @@
 	/* look for the CD-ROM, follows the procedure in the DOS driver */
 	inb(select_unit_reg);
 	/* wait for 40 18 Hz ticks (reverse-engineered from DOS driver) */
-	current->state = TASK_INTERRUPTIBLE;
+	set_current_state(TASK_INTERRUPTIBLE);
 	schedule_timeout((HZ+17)*40/18);
 	inb(result_reg);
 
#5 lore raw
Quoted 25 lines · Felipe W Damasio

Hi Jens,

Quoted 22 lines · Jens Axboe

held! Ugh, and the request function do_cdu535_request calls schedule_timeout with the queue lock held (that is held when that function is entered), that is very buggy as well. Should also use set_current_state() right above that call, not open code it (that also misses a memory barrier). Same function also has problems with request handling. You should kill:

	if (!(req->flags & REQ_CMD))
		continue;       /* FIXME */

that is very broken, make that:

	if (!blk_fs_request(req)) {
		end_request(req, 0);
		continue;
	}

and kill these two lines:

	if (rq_data_dir(req) != READ)
		panic("Unknown SONY CD cmd");
Quoted 7 lines
Quoted 3 lines

they are screwy too.

Care to fix the things I outlined above?

This patch I think fixes all these, doesn't it?

It applies on top of my latest cli-sti-removal patch that I sent you.

That needed changes too, as per my last mail. Please send one complete patch with all the fixes in, thanks.

Signature · 1 line
Jens Axboe
#6 lore raw
	Hi,
Quoted 2 lines · Jens Axboe

That needed changes too, as per my last mail. Please send one complete patch with all the fixes in, thanks.

Sure thing, patch attached:

- cli-sti removal
- blk API update
- set_current_state
- Remove 'panic' line.

Please don't forget to remove BROKEN_ON_SMP from
drivers/cdrom/Kconfig on then cdu535 dependecies (I sent you a patch for that as well).

Thanks for your help Jens,

Felipe

drivers/cdrom/sonycd535.c +19 -9
@@ -36,6 +36,10 @@
  *	            module_init & module_exit.
  *                  Torben Mathiasen <[email protected]>
  *
+ * September 2003 - Fix SMP support by removing cli/sti calls.
+ *                  Using spinlocks with a wait_queue instead.
+ *                  Felipe Damasio <[email protected]>
+ *
  * Things to do:
  *  - handle errors and status better, put everything into a single word
  *  - use interrupts (code mostly there, but a big hole still missing)
@@ -340,10 +344,14 @@
 	if (sony535_irq_used <= 0) {	/* poll */
 		yield();
 	} else {	/* Interrupt driven */
-		cli();
+		DEFINE_WAIT(wait);
+		
+		spin_lock_irq(&sonycd535_lock);
 		enable_interrupts();
-		interruptible_sleep_on(&cdu535_irq_wait);
-		sti();
+		prepare_to_wait(&cdu535_irq_wait, &wait, TASK_INTERRUPTIBLE);
+		spin_unlock_irq(&sonycd535_lock);
+		schedule();
+		finish_wait(&cdu535_irq_wait, &wait);
 	}
 }
 
@@ -804,14 +812,14 @@
 
 		block = req->sector;
 		nsect = req->nr_sectors;
-		if (!(req->flags & REQ_CMD))
-			continue;	/* FIXME */
+		if (!blk_fs_request(req)) {
+			end_request(req, 0);
+			continue;
+		}
 		if (rq_data_dir(req) == WRITE) {
 			end_request(req, 0);
 			continue;
 		}
-		if (rq_data_dir(req) != READ)
-			panic("Unknown SONY CD cmd");
 		/*
 		 * If the block address is invalid or the request goes beyond
 		 * the end of the media, return an error.
@@ -888,8 +896,10 @@
 					}
 					if (readStatus == BAD_STATUS) {
 						/* Sleep for a while, then retry */
-						current->state = TASK_INTERRUPTIBLE;
+						set_current_state(TASK_INTERRUPTIBLE);
+						spin_unlock_irq(&sonycd535_lock);
 						schedule_timeout(RETRY_FOR_BAD_STATUS*HZ/10);
+						spin_lock_irq(&sonycd535_lock);
 					}
 #if DEBUG > 0
 					printk(CDU535_MESSAGE_NAME
@@ -1473,7 +1483,7 @@
 	/* look for the CD-ROM, follows the procedure in the DOS driver */
 	inb(select_unit_reg);
 	/* wait for 40 18 Hz ticks (reverse-engineered from DOS driver) */
-	current->state = TASK_INTERRUPTIBLE;
+	set_current_state(TASK_INTERRUPTIBLE);
 	schedule_timeout((HZ+17)*40/18);
 	inb(result_reg);