Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

[SCSI] megaraid: simplify internal command handling

We don't use the passed in scsi command for anything, so just add a adapter-
wide internal status to go along with the internal scb that is used unter
int_mtx to pass back the return value and get rid of all the complexities
and abuse of the scsi_cmnd structure.

This gets rid of the only user of scsi_allocate_command/scsi_free_command,
which can now be removed.

[jejb: checkpatch fixes]
Signed-off-by: Christoph Hellwig <hch@lst.de>
Acked-by: Adam Radford <aradford@gmail.com>
Signed-off-by: James Bottomley <JBottomley@Parallels.com>

authored by

Christoph Hellwig and committed by
James Bottomley
0f2bb84d c38c007a

+32 -150
+31 -89
drivers/scsi/megaraid.c
··· 531 531 int target = 0; 532 532 int ldrv_num = 0; /* logical drive number */ 533 533 534 - 535 - /* 536 - * filter the internal and ioctl commands 537 - */ 538 - if((cmd->cmnd[0] == MEGA_INTERNAL_CMD)) 539 - return (scb_t *)cmd->host_scribble; 540 - 541 534 /* 542 535 * We know what channels our logical drives are on - mega_find_card() 543 536 */ ··· 1432 1439 1433 1440 cmdid = completed[i]; 1434 1441 1435 - if( cmdid == CMDID_INT_CMDS ) { /* internal command */ 1442 + /* 1443 + * Only free SCBs for the commands coming down from the 1444 + * mid-layer, not for which were issued internally 1445 + * 1446 + * For internal command, restore the status returned by the 1447 + * firmware so that user can interpret it. 1448 + */ 1449 + if (cmdid == CMDID_INT_CMDS) { 1436 1450 scb = &adapter->int_scb; 1437 - cmd = scb->cmd; 1438 - mbox = (mbox_t *)scb->raw_mbox; 1439 1451 1440 - /* 1441 - * Internal command interface do not fire the extended 1442 - * passthru or 64-bit passthru 1443 - */ 1444 - pthru = scb->pthru; 1452 + list_del_init(&scb->list); 1453 + scb->state = SCB_FREE; 1445 1454 1446 - } 1447 - else { 1455 + adapter->int_status = status; 1456 + complete(&adapter->int_waitq); 1457 + } else { 1448 1458 scb = &adapter->scb_list[cmdid]; 1449 1459 1450 1460 /* ··· 1636 1640 cmd->result |= (DID_BAD_TARGET << 16)|status; 1637 1641 } 1638 1642 1639 - /* 1640 - * Only free SCBs for the commands coming down from the 1641 - * mid-layer, not for which were issued internally 1642 - * 1643 - * For internal command, restore the status returned by the 1644 - * firmware so that user can interpret it. 1645 - */ 1646 - if( cmdid == CMDID_INT_CMDS ) { /* internal command */ 1647 - cmd->result = status; 1648 - 1649 - /* 1650 - * Remove the internal command from the pending list 1651 - */ 1652 - list_del_init(&scb->list); 1653 - scb->state = SCB_FREE; 1654 - } 1655 - else { 1656 - mega_free_scb(adapter, scb); 1657 - } 1643 + mega_free_scb(adapter, scb); 1658 1644 1659 1645 /* Add Scsi_Command to end of completed queue */ 1660 1646 list_add_tail(SCSI_LIST(cmd), &adapter->completed_list); ··· 4111 4133 * The last argument is the address of the passthru structure if the command 4112 4134 * to be fired is a passthru command 4113 4135 * 4114 - * lockscope specifies whether the caller has already acquired the lock. Of 4115 - * course, the caller must know which lock we are talking about. 4116 - * 4117 4136 * Note: parameter 'pthru' is null for non-passthru commands. 4118 4137 */ 4119 4138 static int 4120 4139 mega_internal_command(adapter_t *adapter, megacmd_t *mc, mega_passthru *pthru) 4121 4140 { 4122 - Scsi_Cmnd *scmd; 4123 - struct scsi_device *sdev; 4141 + unsigned long flags; 4124 4142 scb_t *scb; 4125 4143 int rval; 4126 - 4127 - scmd = scsi_allocate_command(GFP_KERNEL); 4128 - if (!scmd) 4129 - return -ENOMEM; 4130 4144 4131 4145 /* 4132 4146 * The internal commands share one command id and hence are ··· 4130 4160 scb = &adapter->int_scb; 4131 4161 memset(scb, 0, sizeof(scb_t)); 4132 4162 4133 - sdev = kzalloc(sizeof(struct scsi_device), GFP_KERNEL); 4134 - scmd->device = sdev; 4135 - 4136 - memset(adapter->int_cdb, 0, sizeof(adapter->int_cdb)); 4137 - scmd->cmnd = adapter->int_cdb; 4138 - scmd->device->host = adapter->host; 4139 - scmd->host_scribble = (void *)scb; 4140 - scmd->cmnd[0] = MEGA_INTERNAL_CMD; 4141 - 4142 - scb->state |= SCB_ACTIVE; 4143 - scb->cmd = scmd; 4163 + scb->idx = CMDID_INT_CMDS; 4164 + scb->state |= SCB_ACTIVE | SCB_PENDQ; 4144 4165 4145 4166 memcpy(scb->raw_mbox, mc, sizeof(megacmd_t)); 4146 4167 4147 4168 /* 4148 4169 * Is it a passthru command 4149 4170 */ 4150 - if( mc->cmd == MEGA_MBOXCMD_PASSTHRU ) { 4151 - 4171 + if (mc->cmd == MEGA_MBOXCMD_PASSTHRU) 4152 4172 scb->pthru = pthru; 4153 - } 4154 4173 4155 - scb->idx = CMDID_INT_CMDS; 4156 - 4157 - megaraid_queue_lck(scmd, mega_internal_done); 4174 + spin_lock_irqsave(&adapter->lock, flags); 4175 + list_add_tail(&scb->list, &adapter->pending_list); 4176 + /* 4177 + * Check if the HBA is in quiescent state, e.g., during a 4178 + * delete logical drive opertion. If it is, don't run 4179 + * the pending_list. 4180 + */ 4181 + if (atomic_read(&adapter->quiescent) == 0) 4182 + mega_runpendq(adapter); 4183 + spin_unlock_irqrestore(&adapter->lock, flags); 4158 4184 4159 4185 wait_for_completion(&adapter->int_waitq); 4160 4186 4161 - rval = scmd->result; 4162 - mc->status = scmd->result; 4163 - kfree(sdev); 4187 + mc->status = rval = adapter->int_status; 4164 4188 4165 4189 /* 4166 4190 * Print a debug message for all failed commands. Applications can use 4167 4191 * this information. 4168 4192 */ 4169 - if( scmd->result && trace_level ) { 4193 + if (rval && trace_level) { 4170 4194 printk("megaraid: cmd [%x, %x, %x] status:[%x]\n", 4171 - mc->cmd, mc->opcode, mc->subopcode, scmd->result); 4195 + mc->cmd, mc->opcode, mc->subopcode, rval); 4172 4196 } 4173 4197 4174 4198 mutex_unlock(&adapter->int_mtx); 4175 - 4176 - scsi_free_command(GFP_KERNEL, scmd); 4177 - 4178 4199 return rval; 4179 4200 } 4180 - 4181 - 4182 - /** 4183 - * mega_internal_done() 4184 - * @scmd - internal scsi command 4185 - * 4186 - * Callback routine for internal commands. 4187 - */ 4188 - static void 4189 - mega_internal_done(Scsi_Cmnd *scmd) 4190 - { 4191 - adapter_t *adapter; 4192 - 4193 - adapter = (adapter_t *)scmd->device->host->hostdata; 4194 - 4195 - complete(&adapter->int_waitq); 4196 - 4197 - } 4198 - 4199 4201 4200 4202 static struct scsi_host_template megaraid_template = { 4201 4203 .module = THIS_MODULE,
+1 -2
drivers/scsi/megaraid.h
··· 853 853 854 854 u8 sglen; /* f/w supported scatter-gather list length */ 855 855 856 - unsigned char int_cdb[MAX_COMMAND_SIZE]; 857 856 scb_t int_scb; 858 857 struct mutex int_mtx; /* To synchronize the internal 859 858 commands */ 859 + int int_status; /* status of internal cmd */ 860 860 struct completion int_waitq; /* wait queue for internal 861 861 cmds */ 862 862 ··· 1004 1004 static int mega_do_del_logdrv(adapter_t *, int); 1005 1005 static void mega_get_max_sgl(adapter_t *); 1006 1006 static int mega_internal_command(adapter_t *, megacmd_t *, mega_passthru *); 1007 - static void mega_internal_done(Scsi_Cmnd *); 1008 1007 static int mega_support_cluster(adapter_t *); 1009 1008 #endif 1010 1009
-56
drivers/scsi/scsi.c
··· 403 403 } 404 404 405 405 /** 406 - * scsi_allocate_command - get a fully allocated SCSI command 407 - * @gfp_mask: allocation mask 408 - * 409 - * This function is for use outside of the normal host based pools. 410 - * It allocates the relevant command and takes an additional reference 411 - * on the pool it used. This function *must* be paired with 412 - * scsi_free_command which also has the identical mask, otherwise the 413 - * free pool counts will eventually go wrong and you'll trigger a bug. 414 - * 415 - * This function should *only* be used by drivers that need a static 416 - * command allocation at start of day for internal functions. 417 - */ 418 - struct scsi_cmnd *scsi_allocate_command(gfp_t gfp_mask) 419 - { 420 - struct scsi_host_cmd_pool *pool = scsi_get_host_cmd_pool(gfp_mask); 421 - 422 - if (!pool) 423 - return NULL; 424 - 425 - return scsi_pool_alloc_command(pool, gfp_mask); 426 - } 427 - EXPORT_SYMBOL(scsi_allocate_command); 428 - 429 - /** 430 - * scsi_free_command - free a command allocated by scsi_allocate_command 431 - * @gfp_mask: mask used in the original allocation 432 - * @cmd: command to free 433 - * 434 - * Note: using the original allocation mask is vital because that's 435 - * what determines which command pool we use to free the command. Any 436 - * mismatch will cause the system to BUG eventually. 437 - */ 438 - void scsi_free_command(gfp_t gfp_mask, struct scsi_cmnd *cmd) 439 - { 440 - struct scsi_host_cmd_pool *pool = scsi_get_host_cmd_pool(gfp_mask); 441 - 442 - /* 443 - * this could trigger if the mask to scsi_allocate_command 444 - * doesn't match this mask. Otherwise we're guaranteed that this 445 - * succeeds because scsi_allocate_command must have taken a reference 446 - * on the pool 447 - */ 448 - BUG_ON(!pool); 449 - 450 - scsi_pool_free_command(pool, cmd); 451 - /* 452 - * scsi_put_host_cmd_pool is called twice; once to release the 453 - * reference we took above, and once to release the reference 454 - * originally taken by scsi_allocate_command 455 - */ 456 - scsi_put_host_cmd_pool(gfp_mask); 457 - scsi_put_host_cmd_pool(gfp_mask); 458 - } 459 - EXPORT_SYMBOL(scsi_free_command); 460 - 461 - /** 462 406 * scsi_setup_command_freelist - Setup the command freelist for a scsi host. 463 407 * @shost: host to allocate the freelist for. 464 408 *
-3
include/scsi/scsi_cmnd.h
··· 155 155 extern int scsi_dma_map(struct scsi_cmnd *cmd); 156 156 extern void scsi_dma_unmap(struct scsi_cmnd *cmd); 157 157 158 - struct scsi_cmnd *scsi_allocate_command(gfp_t gfp_mask); 159 - void scsi_free_command(gfp_t gfp_mask, struct scsi_cmnd *cmd); 160 - 161 158 static inline unsigned scsi_sg_count(struct scsi_cmnd *cmd) 162 159 { 163 160 return cmd->sdb.table.nents;