Skip to contentSkip to conversation

sym53c8xx: alloc_cmnd

RFC In review Matthew Wilcox 1 participant 1 message Oct 19, 2007

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

RFC 2/2 sym53c8xx: alloc_cmnd

This demonstration patch converts the sym53c8xx driver to use alloc_cmnd / destroy_cmnd. It's on top of mainline, not the latest version posted a couple of weeks ago. I've tried to keep it simple, but a few cleanups were necessary to make it compile. Speaking of which, it's only compile-tested; I'm travelling and don't feel like possibly crashing my test machine at home that doesn't have remote power.

The observant will notice that there's one slab per driver, rather than one per host. A more thorough conversion would perhaps use a dma_pool specialised for each host, but that would require ripping out sym_malloc.c and isn't really suitable for a demonstration patch. I hope that the actively maintained drivers will receive that level of care and attention.

Vehement-opposition-to-merge-by Matthew Wilcox <[email protected]>
drivers/scsi/sym53c8xx_2/sym53c8xx.h +12 -0
index 7519728..773ada4 100644
@@ -213,4 +213,16 @@ extern unsigned int sym_debug_flags;
  */
 #define SYM_SETUP_RESIDUAL_SUPPORT 1
 
+struct sym_cmnd {
+	struct scsi_cmnd cmnd;
+	dma_addr_t	data_mapping;
+	unsigned char	data_mapped;
+	unsigned char	to_do;			/* For error handling */
+	void (*old_done)(struct scsi_cmnd *);	/* For error handling */
+	struct completion *eh_done;		/* For error handling */
+	struct sym_ccb *cp;
+};
+
+#define sym_cmd(cmd)	container_of(cmd, struct sym_cmnd, cmnd)
+
 #endif /* SYM53C8XX_H */
drivers/scsi/sym53c8xx_2/sym_glue.c +63 -30

186 lines not on this page · raw message

drivers/scsi/sym53c8xx_2/sym_glue.h +1 -1
index 0f097ba..69837a2 100644
@@ -261,7 +261,7 @@ static __inline void sym_set_cam_result_ok(struct sym_ccb *cp, struct scsi_cmnd
 void sym_set_cam_result_error(struct sym_hcb *np, struct sym_ccb *cp, int resid);
 
 void sym_xpt_done(struct sym_hcb *np, struct scsi_cmnd *ccb);
-#define sym_print_addr(cmd, arg...) dev_info(&cmd->device->sdev_gendev , ## arg)
+#define sym_print_addr(cmd, arg...) dev_info(&(cmd)->device->sdev_gendev , ## arg)
 void sym_xpt_async_bus_reset(struct sym_hcb *np);
 void sym_xpt_async_sent_bdr(struct sym_hcb *np, int target);
 int  sym_setup_data_and_start (struct sym_hcb *np, struct scsi_cmnd *csio, struct sym_ccb *cp);
drivers/scsi/sym53c8xx_2/sym_hipd.c +6 -19
index 21cd4c7..6ef7e0a 100644
@@ -53,7 +53,6 @@
  */
 static void sym_int_ma (struct sym_hcb *np);
 static void sym_int_sir (struct sym_hcb *np);
-static struct sym_ccb *sym_alloc_ccb(struct sym_hcb *np);
 static struct sym_ccb *sym_ccb_from_dsa(struct sym_hcb *np, u32 dsa);
 static void sym_alloc_lcb_tags (struct sym_hcb *np, u_char tn, u_char ln);
 static void sym_complete_error (struct sym_hcb *np, struct sym_ccb *cp);
@@ -4578,25 +4577,14 @@ out_stuck:
 /*
  *  Acquire a control block
  */
-struct sym_ccb *sym_get_ccb (struct sym_hcb *np, struct scsi_cmnd *cmd, u_char tag_order)
+struct sym_ccb *sym_get_ccb (struct sym_hcb *np, struct sym_cmnd *cmd, u_char tag_order)
 {
-	u_char tn = cmd->device->id;
-	u_char ln = cmd->device->lun;
+	u_char tn = cmd->cmnd.device->id;
+	u_char ln = cmd->cmnd.device->lun;
 	struct sym_tcb *tp = &np->target[tn];
 	struct sym_lcb *lp = sym_lp(tp, ln);
 	u_short tag = NO_TAG;
-	SYM_QUEHEAD *qp;
-	struct sym_ccb *cp = NULL;
-
-	/*
-	 *  Look for a free CCB
-	 */
-	if (sym_que_empty(&np->free_ccbq))
-		sym_alloc_ccb(np);
-	qp = sym_remque_head(&np->free_ccbq);
-	if (!qp)
-		goto out;
-	cp = sym_que_entry(qp, struct sym_ccb, link_ccbq);
+	struct sym_ccb *cp = cmd->cp;
 
 	{
 		/*
@@ -4692,10 +4680,9 @@ struct sym_ccb *sym_get_ccb (struct sym_hcb *np, struct scsi_cmnd *cmd, u_char t
 	cp->lun    = ln;
 
 	if (DEBUG_FLAGS & DEBUG_TAGS) {
-		sym_print_addr(cmd, "ccb @%p using tag %d.\n", cp, tag);
+		sym_print_addr(&cmd->cmnd, "ccb @%p using tag %d.\n", cp, tag);
 	}
 
-out:
 	return cp;
 out_free:
 	sym_insque_head(&cp->link_ccbq, &np->free_ccbq);
@@ -4797,7 +4784,7 @@ void sym_free_ccb (struct sym_hcb *np, struct sym_ccb *cp)
 /*
  *  Allocate a CCB from memory and initialize its fixed part.
  */
-static struct sym_ccb *sym_alloc_ccb(struct sym_hcb *np)
+struct sym_ccb *sym_alloc_ccb(struct sym_hcb *np)
 {
 	struct sym_ccb *cp = NULL;
 	int hcode;
drivers/scsi/sym53c8xx_2/sym_hipd.h +2 -1
index 79ab6a1..b9300b5 100644
@@ -1055,7 +1055,8 @@ void sym_put_start_queue(struct sym_hcb *np, struct sym_ccb *cp);
 void sym_start_up(struct sym_hcb *np, int reason);
 void sym_interrupt(struct sym_hcb *np);
 int sym_clear_tasks(struct sym_hcb *np, int cam_status, int target, int lun, int task);
-struct sym_ccb *sym_get_ccb(struct sym_hcb *np, struct scsi_cmnd *cmd, u_char tag_order);
+struct sym_ccb *sym_get_ccb(struct sym_hcb *np, struct sym_cmnd *cmd, u_char tag_order);
+struct sym_ccb *sym_alloc_ccb(struct sym_hcb *np);
 void sym_free_ccb(struct sym_hcb *np, struct sym_ccb *cp);
 struct sym_lcb *sym_alloc_lcb(struct sym_hcb *np, u_char tn, u_char ln);
 int sym_queue_scsiio(struct sym_hcb *np, struct scsi_cmnd *csio, struct sym_ccb *cp);
Signature · 4 lines
Intel are signing my paycheques ... these opinions are still mine
"Bill, look, we understand that you're interested in selling us this
operating system, but compare it to ours.  We can't possibly take such
a retrograde step."