RE: How to add/drop SCSI drives from within the driver?

From: Bagalkote, Sreenivas
Date: Thu Dec 09 2004 - 18:48:51 EST


All,

I am submitting the final patch that incorporates Matt's suggestions.

Thank you,
Sreenivas


diff -Naur old-rc2/Documentation/scsi/ChangeLog.megaraid
new-rc2/Documentation/scsi/ChangeLog.megaraid
--- old-rc2/Documentation/scsi/ChangeLog.megaraid 2004-12-07
16:40:23.000000000 -0500
+++ new-rc2/Documentation/scsi/ChangeLog.megaraid 2004-12-09
17:38:58.000000000 -0500
@@ -1,3 +1,22 @@
+Release Date : Thu Dec 9 17:25:27 EST 2004 - Sreenivas Bagalkote
<sreenib@xxxxxxxx>
+
+Current Version : 2.20.4.2 (scsi module), 2.20.2.3 (cmm module)
+Older Version : 2.20.4.1 (scsi module), 2.20.2.2 (cmm module)
+
+i. Fixed a bug in deallocating kioc's dma buffer in megaraid_mm module
+ii. Introduced driver ioctl that returns scsi address for a given ld.
+
+ "Why can't the existing sysfs interfaces be used to do this?"
+ - Brian King (brking@xxxxxxxxxx)
+
+ "I've looked into solving this another way, but I cannot see how
+ to get this driver-private mapping of logical drive number-> HCTL
+ without putting code something like this into the driver."
+
+ "...and by providing a mapping a function to userspace, the driver
+ is free to change its mapping algorithm in the future if necessary
.."
+ - Matt Domsch (Matt_Domsch@xxxxxxxx)
+
Release Date : Thu Nov 4 18:24:56 EST 2004 - Sreenivas Bagalkote
<sreenib@xxxxxxxx>

Current Version : 2.20.4.1 (scsi module), 2.20.2.2 (cmm module)
diff -Naur old-rc2/drivers/scsi/megaraid/megaraid_ioctl.h
new-rc2/drivers/scsi/megaraid/megaraid_ioctl.h
--- old-rc2/drivers/scsi/megaraid/megaraid_ioctl.h 2004-12-07
16:40:16.000000000 -0500
+++ new-rc2/drivers/scsi/megaraid/megaraid_ioctl.h 2004-12-09
17:05:18.000000000 -0500
@@ -51,6 +51,7 @@
#define MEGAIOC_QNADAP 'm' /* Query # of adapters */
#define MEGAIOC_QDRVRVER 'e' /* Query driver version */
#define MEGAIOC_QADAPINFO 'g' /* Query adapter information */
+#define MEGAIOC_GET_SADDR 'a' /* Get SCSI address of an LD */

#define USCSICMD 0x80
#define UIOC_RD 0x00001
@@ -62,6 +63,7 @@
#define GET_ADAP_INFO 0x30000
#define GET_CAP 0x40000
#define GET_STATS 0x50000
+#define GET_LD_SADDR 0x60000
#define GET_IOCTL_VERSION 0x01

#define EXT_IOCTL_SIGN_SZ 16
@@ -142,7 +144,7 @@

caddr_t buf_vaddr;
dma_addr_t buf_paddr;
- uint8_t pool_index;
+ int8_t pool_index;
uint8_t free_buf;

uint8_t timedout;
@@ -217,6 +219,27 @@

} __attribute__ ((packed)) mcontroller_t;

+/**
+ * ld_device_address : SCSI device address for the logical drives
+ *
+ * @host_no : host# to which LD belogs; as understood by
mid-layer
+ * @channel : channel on which LD is exported
+ * @target : target on which the LD is exported
+ * @lun : lun on which the LD is exported
+ * @ld : the LD for which this information is sought
+ * @reserved : reserved fields; must be set to zero
+ *
+ * NOTE : Applications set the LD number and expect
the
+ * SCSI address to be returned in the first four
fields
+ */
+struct ld_device_address {
+ uint32_t host_no;
+ uint32_t channel;
+ uint32_t scsi_id;
+ uint32_t lun;
+ uint32_t ld;
+ uint32_t reserved[3];
+} __attribute__ ((packed));

/**
* mm_dmapool_t : Represents one dma pool with just one buffer
diff -Naur old-rc2/drivers/scsi/megaraid/megaraid_mbox.c
new-rc2/drivers/scsi/megaraid/megaraid_mbox.c
--- old-rc2/drivers/scsi/megaraid/megaraid_mbox.c 2004-12-07
16:40:16.000000000 -0500
+++ new-rc2/drivers/scsi/megaraid/megaraid_mbox.c 2004-12-09
17:42:33.538473752 -0500
@@ -10,7 +10,7 @@
* 2 of the License, or (at your option) any later version.
*
* FILE : megaraid_mbox.c
- * Version : v2.20.4.1 (Nov 04 2004)
+ * Version : v2.20.4.2 (Dec 9 2004)
*
* Authors:
* Atul Mukker <Atul.Mukker@xxxxxxxx>
@@ -3642,6 +3642,7 @@
megaraid_mbox_mm_handler(unsigned long drvr_data, uioc_t *kioc, uint32_t
action)
{
adapter_t *adapter;
+ struct ld_device_address* lda;

if (action != IOCTL_ISSUE) {
con_log(CL_ANN, (KERN_WARNING
@@ -3670,6 +3671,30 @@

return kioc->status;

+ case GET_LD_SADDR:
+
+ lda = (struct ld_device_address*)(unsigned
long)kioc->buf_vaddr;
+
+ if (lda->ld > MAX_LOGICAL_DRIVES_40LD) {
+ lda->host_no = 0xffffffff;
+ lda->channel = 0xffffffff;
+ lda->scsi_id = 0xffffffff;
+ lda->lun = 0xffffffff;
+ kioc->status = -ENODEV;
+ kioc->done(kioc);
+ return kioc->status;
+ }
+
+ lda->host_no = adapter->host->host_no;
+ lda->channel = adapter->max_channel;
+ lda->scsi_id = (lda->ld < adapter->init_id) ?
+ lda->ld : lda->ld + 1;
+ lda->lun = 0;
+ kioc->status = 0;
+ kioc->done(kioc);
+
+ return kioc->status;
+
case MBOX_CMD:

return megaraid_mbox_mm_command(adapter, kioc);
diff -Naur old-rc2/drivers/scsi/megaraid/megaraid_mbox.h
new-rc2/drivers/scsi/megaraid/megaraid_mbox.h
--- old-rc2/drivers/scsi/megaraid/megaraid_mbox.h 2004-12-07
16:40:16.000000000 -0500
+++ new-rc2/drivers/scsi/megaraid/megaraid_mbox.h 2004-12-09
17:41:34.706417584 -0500
@@ -21,8 +21,8 @@
#include "megaraid_ioctl.h"


-#define MEGARAID_VERSION "2.20.4.1"
-#define MEGARAID_EXT_VERSION "(Release Date: Thu Nov 4 17:44:59 EST
2004)"
+#define MEGARAID_VERSION "2.20.4.2"
+#define MEGARAID_EXT_VERSION "(Release Date: Thu Dec 9 17:25:27 EST
2004)"


/*
diff -Naur old-rc2/drivers/scsi/megaraid/megaraid_mm.c
new-rc2/drivers/scsi/megaraid/megaraid_mm.c
--- old-rc2/drivers/scsi/megaraid/megaraid_mm.c 2004-12-07
16:40:16.000000000 -0500
+++ new-rc2/drivers/scsi/megaraid/megaraid_mm.c 2004-12-09
18:12:16.485424616 -0500
@@ -10,7 +10,7 @@
* 2 of the License, or (at your option) any later version.
*
* FILE : megaraid_mm.c
- * Version : v2.20.2.2 (Nov 04 2004)
+ * Version : v2.20.2.3 (Dec 9 2004)
*
* Common management module
*/
@@ -373,6 +373,20 @@
if (mraid_mm_attach_buf(adp, kioc, kioc->xferlen))
return (-ENOMEM);
}
+ else if (subopcode == MEGAIOC_GET_SADDR) {
+
+ kioc->opcode = GET_LD_SADDR;
+ kioc->data_dir = UIOC_RD;
+ kioc->xferlen = sizeof(struct ld_device_address);
+
+ if (mraid_mm_attach_buf(adp, kioc, kioc->xferlen))
+ return (-ENOMEM);
+
+ if (copy_from_user(kioc->buf_vaddr, mimd.data,
+ kioc->xferlen )) {
+ return (-EFAULT);
+ }
+ }
else {
con_log(CL_ANN, (KERN_WARNING
"megaraid cmm: Invalid subop\n"));
@@ -614,23 +628,27 @@
mm_dmapool_t *pool;
unsigned long flags;

- pool = &adp->dma_pool_list[kioc->pool_index];
+ if (kioc->pool_index != -1) {
+ pool = &adp->dma_pool_list[kioc->pool_index];

- /* This routine may be called in non-isr context also */
- spin_lock_irqsave(&pool->lock, flags);
+ /* This routine may be called in non-isr context also */
+ spin_lock_irqsave(&pool->lock, flags);

- /*
- * While attaching the dma buffer, if we didn't get the required
- * buffer from the pool, we would have allocated it at the run time
- * and set the free_buf flag. We must free that buffer. Otherwise,
- * just mark that the buffer is not in use
- */
- if (kioc->free_buf == 1)
- pci_pool_free(pool->handle, kioc->buf_vaddr,
kioc->buf_paddr);
- else
- pool->in_use = 0;
+ /*
+ * While attaching the dma buffer, if we didn't get the
+ * required buffer from the pool, we would have allocated
+ * it at the run time and set the free_buf flag. We must
+ * free that buffer. Otherwise, just mark that the buffer is

+ * not in use
+ */
+ if (kioc->free_buf == 1)
+ pci_pool_free(pool->handle, kioc->buf_vaddr,
+ kioc->buf_paddr);
+ else
+ pool->in_use = 0;

- spin_unlock_irqrestore(&pool->lock, flags);
+ spin_unlock_irqrestore(&pool->lock, flags);
+ }

/* Return the kioc to the free pool */
spin_lock_irqsave(&adp->kioc_pool_lock, flags);
@@ -809,6 +827,15 @@

return 0;

+ case MEGAIOC_GET_SADDR:
+
+ if (copy_to_user(kmimd.data, kioc->buf_vaddr,
+ sizeof(struct ld_device_address))) {
+ return (-EFAULT);
+ }
+
+ return kioc->status;
+
default:
return (-EINVAL);
}
diff -Naur old-rc2/drivers/scsi/megaraid/megaraid_mm.h
new-rc2/drivers/scsi/megaraid/megaraid_mm.h
--- old-rc2/drivers/scsi/megaraid/megaraid_mm.h 2004-12-07
16:40:15.000000000 -0500
+++ new-rc2/drivers/scsi/megaraid/megaraid_mm.h 2004-12-09
18:12:10.336359416 -0500
@@ -29,9 +29,9 @@
#include "megaraid_ioctl.h"


-#define LSI_COMMON_MOD_VERSION "2.20.2.2"
+#define LSI_COMMON_MOD_VERSION "2.20.2.3"
#define LSI_COMMON_MOD_EXT_VERSION \
- "(Release Date: Thu Nov 4 17:46:29 EST 2004)"
+ "(Release Date: Thu Dec 9 17:25:27 EST 2004)"


#define LSI_DBGLVL dbglevel


Attachment: megaraid-hctl.patch
Description: Binary data