hpsa: fix per device memory leak on driver unload
Subsystems (3)
PATCH 1/10 hpsa: fix per device memory leak on driver unload
From: Stephen M. Cameron <[email protected]>
--- drivers/scsi/hpsa.c | 9 +++++++++ 1 files changed, 9 insertions(+), 0 deletions(-)
drivers/scsi/hpsa.c +9 -0
@@ -4480,6 +4480,14 @@ static void hpsa_shutdown(struct pci_dev *pdev)#endif /* CONFIG_PCI_MSI */ } +static void __devexit hpsa_free_device_info(struct ctlr_info *h) +{ +int i; + +for (i =0 ; i < h->ndevices; i++) +kfree (h->dev[i]); +} + static void __devexit hpsa_remove_one(struct pci_dev *pdev) {struct ctlr_info *h;
@@ -4495,6 +4503,7 @@ static void __devexit hpsa_remove_one(struct pci_dev *pdev)iounmap (h->vaddr);iounmap (h->transtable);iounmap (h->cfgtable); +hpsa_free_device_info (h);hpsa_free_sg_chain_blocks (h); pci_free_consistent(h->pdev, h->nr_cmds * sizeof(struct CommandList),
PATCH 2/10 hpsa: removed unneeded structure member max_sg_entries and fix badly named constant MAXSGENTRIES
From: Stephen M. Cameron <[email protected]>
We had both h->max_sg_entries and h->maxsgentries in the per controller structure which is terribly confusing. max_sg_entries was really just a constant, 32, which defines how big the "block fetch table" is, which is as large as the max number of SG elements embedded within a command (excluding SG elements in chain blocks).
MAXSGENTRIES was the constant used to denote the max number of SG elements embedded within a command, also a poor name.
So renamed MAXSGENTREIS to SG_ENTRIES_IN_CMD, and removed h->max_sg_entries and replaced it with SG_ENTRIES_IN_CMD.
h->maxsgentries is unchanged, and is the maximum number of sg elements the controller will support in a command, including those in chain blocks, minus 1 for the chain block pointer..
--- drivers/scsi/hpsa.c | 20 ++++++++++---------- drivers/scsi/hpsa.h | 1 - drivers/scsi/hpsa_cmd.h | 4 ++-- 3 files changed, 12 insertions(+), 13 deletions(-)
drivers/scsi/hpsa.c +10 -10
@@ -2698,16 +2698,16 @@ static int hpsa_big_passthru_ioctl(struct ctlr_info *h, void __user *argp) status = -EINVAL ; goto cleanup1; } -if (ioc->buf_size > ioc->malloc_size *MAXSGENTRIES ) { +if (ioc->buf_size > ioc->malloc_size *SG_ENTRIES_IN_CMD ) { status = -EINVAL ; goto cleanup1; } - buff =kzalloc (MAXSGENTRIES *sizeof (char *),GFP_KERNEL ); + buff =kzalloc (SG_ENTRIES_IN_CMD *sizeof (char *),GFP_KERNEL );if (!buff) { status = -ENOMEM ; goto cleanup1; } - buff_size =kmalloc (MAXSGENTRIES *sizeof (int ),GFP_KERNEL ); + buff_size =kmalloc (SG_ENTRIES_IN_CMD *sizeof (int ),GFP_KERNEL );if (!buff_size) { status = -ENOMEM ; goto cleanup1;
@@ -4599,15 +4599,15 @@ static __devinit void hpsa_enter_performant_mode(struct ctlr_info *h,* Each SG entry requires 16 bytes. The eight registers are programmed * with the number of 16-byte blocks a command of that size requires. * The smallest command possible requires 5 such 16 byte blocks. -* the largest command possible requires MAXSGENTRIES + 4 16-byte +* the largest command possible requires SG_ENTRIES_IN_CMD + 4 16-byte * blocks. Note, this only extends to the SG entries contained * within the command block, and does not extend to chained blocks * of SG elements. bft[] contains the eight values we write to * the registers. They are not evenly distributed, but have more * sizes for small commands, and fewer sizes for larger commands. */ -int bft[8 ] = {5 ,6 ,8 ,10 ,12 ,20 ,28 ,MAXSGENTRIES +4 }; -BUILD_BUG_ON (28 >MAXSGENTRIES +4 ); +int bft[8 ] = {5 ,6 ,8 ,10 ,12 ,20 ,28 ,SG_ENTRIES_IN_CMD +4 }; +BUILD_BUG_ON (28 >SG_ENTRIES_IN_CMD +4 );/* 5 = 1 s/g entry or 4k * 6 = 2 s/g entry or 8k * 8 = 4 s/g entry or 16k
@@ -4620,8 +4620,9 @@ static __devinit void hpsa_enter_performant_mode(struct ctlr_info *h,memset (h->reply_pool,0 , h->reply_pool_size); h->reply_pool_head = h->reply_pool; - bft[7 ] = h->max_sg_entries +4 ; -calc_bucket_map (bft,ARRAY_SIZE (bft),32 , h->blockFetchTable); + bft[7 ] =SG_ENTRIES_IN_CMD +4 ; +calc_bucket_map (bft,ARRAY_SIZE (bft), +SG_ENTRIES_IN_CMD , h->blockFetchTable);for (i =0 ; i <8 ; i++)writel (bft[i], &h->transtable->BlockFetch[i]);
@@ -4659,14 +4660,13 @@ static __devinit void hpsa_put_ctlr_into_performant_mode(struct ctlr_info *h)return ;hpsa_get_max_perf_mode_cmds (h); - h->max_sg_entries =32 ;/* Performant mode ring buffer and supporting data structures */ h->reply_pool_size = h->max_commands *sizeof (u64); h->reply_pool =pci_alloc_consistent (h->pdev, h->reply_pool_size, &(h->reply_pool_dhandle));/* Need a block fetch table for performant mode */ - h->blockFetchTable =kmalloc (((h->max_sg_entries+1 ) * + h->blockFetchTable =kmalloc (((SG_ENTRIES_IN_CMD +1 ) *sizeof (u32)),GFP_KERNEL ); if ((h->reply_pool == NULL)
drivers/scsi/hpsa.h +0 -1
@@ -58,7 +58,6 @@ struct ctlr_info {unsigned long paddr;int nr_cmds;/* Number of commands allowed on this controller */ struct CfgTable __iomem *cfgtable; -int max_sg_entries;int interrupts_enabled;int major;int max_commands;
drivers/scsi/hpsa_cmd.h +2 -2
@@ -23,7 +23,7 @@/* general boundary defintions */ #define SENSEINFOBYTES 32/* may vary between hbas */ -#define MAXSGENTRIES 32 +#define SG_ENTRIES_IN_CMD 32/* Max SG entries excluding chain blocks */ #define HPSA_SG_CHAIN 0x80000000#define MAXREPLYQS 256
@@ -282,7 +282,7 @@ struct CommandList {struct CommandListHeader Header;struct RequestBlock Request;struct ErrDescriptor ErrDesc; -struct SGDescriptor SG [MAXSGENTRIES ]; +struct SGDescriptor SG [SG_ENTRIES_IN_CMD ];/* information associated with the command */ u32 busaddr;/* physical addr of this record */ struct ErrorInfo *err_info;/* pointer to the allocated mem */
PATCH 3/10 hpsa: combine hpsa_scsi_detect and hpsa_register_scsi
In reply to Stephen M. CameronFrom: Stephen M. Cameron <[email protected]>
hpsa_register_scsi just calls hpsa_scsi_detect. Move the guts of hpsa_scsi_detect into hpsa_register_scsi and get rid of hpsa_scsi_detect.
--- drivers/scsi/hpsa.c | 81 ++++++++++++++++++++++----------------------------- 1 files changed, 35 insertions(+), 46 deletions(-)
drivers/scsi/hpsa.c +35 -46
@@ -1255,46 +1255,6 @@ static void complete_scsi_command(struct CommandList *cp)cmd_free (h, cp); } -static int hpsa_scsi_detect (struct ctlr_info *h) -{ -struct Scsi_Host *sh; -int error; - - sh =scsi_host_alloc (&hpsa_driver_template,sizeof (h)); -if (sh ==NULL ) - goto fail; - - sh->io_port =0 ; - sh->n_io_port =0 ; - sh->this_id =-1 ; - sh->max_channel =3 ; - sh->max_cmd_len =MAX_COMMAND_SIZE ; - sh->max_lun =HPSA_MAX_LUN ; - sh->max_id =HPSA_MAX_LUN ; - sh->can_queue = h->nr_cmds; - sh->cmd_per_lun = h->nr_cmds; - sh->sg_tablesize = h->maxsgentries; - h->scsi_host = sh; - sh->hostdata[0 ] = (unsigned long ) h; - sh->irq = h->intr[h->intr_mode]; - sh->unique_id = sh->irq; - error =scsi_add_host (sh, &h->pdev->dev); -if (error) - goto fail_host_put; -scsi_scan_host (sh); -return 0 ; - - fail_host_put: -dev_err (&h->pdev->dev,"hpsa_scsi_detect: scsi_add_host" -" failed for controller %d\n" , h->ctlr); -scsi_host_put (sh); -return error; - fail: -dev_err (&h->pdev->dev,"hpsa_scsi_detect: scsi_host_alloc" -" failed for controller %d\n" , h->ctlr); -return -ENOMEM ; -} -static void hpsa_pci_unmap (struct pci_dev *pdev,struct CommandList *c,int sg_used,int data_direction) {
@@ -2226,13 +2186,42 @@ static void hpsa_unregister_scsi(struct ctlr_info *h)static int hpsa_register_scsi (struct ctlr_info *h) { -int rc; +struct Scsi_Host *sh; +int error; - rc =hpsa_scsi_detect (h); -if (rc !=0 ) -dev_err (&h->pdev->dev,"hpsa_register_scsi: failed" -" hpsa_scsi_detect(), rc is %d\n" , rc); -return rc; + sh =scsi_host_alloc (&hpsa_driver_template,sizeof (h)); +if (sh ==NULL ) + goto fail; + + sh->io_port =0 ; + sh->n_io_port =0 ; + sh->this_id =-1 ; + sh->max_channel =3 ; + sh->max_cmd_len =MAX_COMMAND_SIZE ; + sh->max_lun =HPSA_MAX_LUN ; + sh->max_id =HPSA_MAX_LUN ; + sh->can_queue = h->nr_cmds; + sh->cmd_per_lun = h->nr_cmds; + sh->sg_tablesize = h->maxsgentries; + h->scsi_host = sh; + sh->hostdata[0 ] = (unsigned long ) h; + sh->irq = h->intr[h->intr_mode]; + sh->unique_id = sh->irq; + error =scsi_add_host (sh, &h->pdev->dev); +if (error) + goto fail_host_put; +scsi_scan_host (sh); +return 0 ; + + fail_host_put: +dev_err (&h->pdev->dev,"%s: scsi_add_host" +" failed for controller %d\n" , __func__, h->ctlr); +scsi_host_put (sh); +return error; + fail: +dev_err (&h->pdev->dev,"%s: scsi_host_alloc" +" failed for controller %d\n" , __func__, h->ctlr); +return -ENOMEM ; } static int wait_for_device_to_become_ready(struct ctlr_info *h,
PATCH 4/10 hpsa: factor out driver name
In reply to Stephen M. CameronFrom: Stephen M. Cameron <[email protected]>
Sometimes, for testing purposes (e.g. testing rmmod on a system that normally boots using hpsa) it's nice to rename the driver and split it into two drivers and restrict it to certain controllers. This makes that easier.
--- drivers/scsi/hpsa.c | 27 ++++++++++++++------------- drivers/scsi/hpsa.h | 2 +- 2 files changed, 15 insertions(+), 14 deletions(-)
drivers/scsi/hpsa.c +14 -13
@@ -56,6 +56,7 @@/* HPSA_DRIVER_VERSION must be 3 byte values (0-255) separated by '.' */ #define HPSA_DRIVER_VERSION "2.0.2-1"#define DRIVER_NAME "HP HPSA Driver (v " HPSA_DRIVER_VERSION ")" +#define HPSA "hpsa"/* How long to wait (in milliseconds) for board to go into simple mode */ #define MAX_CONFIG_WAIT 30000
@@ -202,30 +203,30 @@ static int check_for_unit_attention(struct ctlr_info *h,switch (c->err_info->SenseInfo[12 ]) {case STATE_CHANGED : -dev_warn (&h->pdev->dev,"hpsa%d: a state change " +dev_warn (&h->pdev->dev,HPSA "%d: a state change " "detected, command retried\n" , h->ctlr);break ;case LUN_FAILED : -dev_warn (&h->pdev->dev,"hpsa%d: LUN failure " +dev_warn (&h->pdev->dev,HPSA "%d: LUN failure " "detected, action required\n" , h->ctlr);break ;case REPORT_LUNS_CHANGED : -dev_warn (&h->pdev->dev,"hpsa%d: report LUN data " +dev_warn (&h->pdev->dev,HPSA "%d: report LUN data " "changed, action required\n" , h->ctlr);/* * Note: this REPORT_LUNS_CHANGED condition only occurs on the MSA2012. */ break ;case POWER_OR_RESET : -dev_warn (&h->pdev->dev,"hpsa%d: a power on " +dev_warn (&h->pdev->dev,HPSA "%d: a power on " "or device reset detected\n" , h->ctlr);break ;case UNIT_ATTENTION_CLEARED : -dev_warn (&h->pdev->dev,"hpsa%d: unit attention " +dev_warn (&h->pdev->dev,HPSA "%d: unit attention " "cleared by another initiator\n" , h->ctlr);break ;default : -dev_warn (&h->pdev->dev,"hpsa%d: unknown " +dev_warn (&h->pdev->dev,HPSA "%d: unknown " "unit attention detected\n" , h->ctlr);break ; }
@@ -473,8 +474,8 @@ static struct device_attribute *hpsa_shost_attrs[] = {static struct scsi_host_template hpsa_driver_template = { .module =THIS_MODULE , - .name ="hpsa" , - .proc_name ="hpsa" , + .name =HPSA , + .proc_name =HPSA , .queuecommand = hpsa_scsi_queue_command, .scan_start = hpsa_scan_start, .scan_finished = hpsa_scan_finished,
@@ -3341,7 +3342,7 @@ static int hpsa_controller_hard_reset(struct pci_dev *pdev,static __devinit void init_driver_version (char *driver_version,int len) {memset (driver_version,0 , len); -strncpy (driver_version,"hpsa " HPSA_DRIVER_VERSION , len -1 ); +strncpy (driver_version,HPSA " " HPSA_DRIVER_VERSION , len -1 ); } static __devinit int write_driver_ver_to_cfgtable(
@@ -3922,7 +3923,7 @@ static int __devinit hpsa_pci_init(struct ctlr_info *h)return err; } - err =pci_request_regions (h->pdev,"hpsa" ); + err =pci_request_regions (h->pdev,HPSA );if (err) {dev_err (&h->pdev->dev,"cannot obtain PCI resources, aborting\n" );
@@ -4240,7 +4241,7 @@ static void start_controller_lockup_detector(struct ctlr_info *h)spin_lock_init (&lockup_detector_lock); hpsa_lockup_detector =kthread_run (detect_controller_lockup_thread, -NULL ,"hpsa" ); +NULL ,HPSA ); }if (!hpsa_lockup_detector) { dev_warn(&h->pdev->dev,
@@ -4312,7 +4313,7 @@ reinit_after_soft_reset:if (rc !=0 ) goto clean1; -sprintf (h->devname,"hpsa%d" , number_of_controllers); +sprintf (h->devname,HPSA "%d" , number_of_controllers); h->ctlr = number_of_controllers; number_of_controllers++;
@@ -4526,7 +4527,7 @@ static int hpsa_resume(__attribute__((unused)) struct pci_dev *pdev) }static struct pci_driver hpsa_pci_driver = { - .name ="hpsa" , + .name =HPSA , .probe = hpsa_init_one, .remove =__devexit_p (hpsa_remove_one), .id_table = hpsa_pci_device_id,/* id_table */
drivers/scsi/hpsa.h +1 -1
@@ -316,7 +316,7 @@ static unsigned long SA5_completed(struct ctlr_info *h)dev_dbg (&h->pdev->dev,"Read %lx back from board\n" , register_value); else - dev_dbg(&h->pdev->dev, "hpsa: FIFO Empty read\n"); + dev_dbg(&h->pdev->dev, "FIFO Empty read\n");#endif return register_value;
PATCH 5/10 hpsa: Fix problem with MSA2xxx devices
In reply to Stephen M. CameronFrom: Stephen M. Cameron <[email protected]>
Upgraded firmware on Smart Array P7xx (and some others) made them show up as SCSI revision 5 devices and this caused the driver to fail to map MSA2xxx logical drives to the correct bus/target/lun. A symptom of this would be that the target ID of the logical drives as presented by the external storage array is ignored, and all such logical drives are assigned to target zero, differentiated only by LUN. Some multipath software reportedly does not deal well with this behavior, failing to recognize different paths to the same device as such.
--- drivers/scsi/hpsa.c | 34 +++++++++++++++------------------- 1 files changed, 15 insertions(+), 19 deletions(-)
drivers/scsi/hpsa.c +15 -19
@@ -1635,30 +1635,26 @@ static void figure_bus_target_lun(struct ctlr_info *h,if (is_logical_dev_addr_mode (lunaddrbytes)) {/* logical device */ -if (unlikely (is_scsi_rev_5 (h))) { -/* p1210m, logical drives lun assignments -* match SCSI REPORT LUNS data. + lunid =le32_to_cpu (*((__le32 *) lunaddrbytes)); +if (is_msa2xxx (h, device)) { +/* msa2xxx way, put logicals on bus 1 +* and match target/lun numbers box +* reports. */ - lunid =le32_to_cpu (*((__le32 *) lunaddrbytes)); - *bus =0 ; - *target =0 ; - *lun = (lunid &0x3fff ) +1 ; + *bus =1 ; + *target = (lunid >>16 ) &0x3fff ; + *lun = lunid &0x00ff ; }else { -/* not p1210m... */ - lunid =le32_to_cpu (*((__le32 *) lunaddrbytes)); -if (is_msa2xxx (h, device)) { -/* msa2xxx way, put logicals on bus 1 -* and match target/lun numbers box -* reports. -*/ - *bus =1 ; - *target = (lunid >>16 ) &0x3fff ; - *lun = lunid &0x00ff ; +if (likely (is_scsi_rev_5 (h))) { +/* All current smart arrays (circa 2011) */ + *bus =0 ; + *target =0 ; + *lun = (lunid &0x3fff ) +1 ; }else { -/* Traditional smart array way. */ +/* Traditional old smart array way. */ *bus =0 ; - *lun =0 ; *target = lunid &0x3fff ; + *lun =0 ; } } }else {
[3.0.y, 3.2.y, 3.3.y] Re: [PATCH 05/10] hpsa: Fix problem with MSA2xxx devices
Hi Greg and Ben,
Please consider
9bc3711cbb67 [SCSI] hpsa: Fix problem with MSA2xxx devices
for application to next week's 3.0.y, 3.2.y, and 3.3.y trees.
As Steven Williamson noticed[1], without this patch:
Quoted 6 lines
The hpsa driver fails to correctly assign devices when there are multiple paths on at least the Smart Array 712m with the latest firmware.
The end result is only one device node is created in /dev and multipath tools then only detect one path.
He tested this patch + fda38518f236 "[SCSI] hpsa: add P2000 to list of shared SAS devices" (which is already in v3.0) on top of a 2.6.32.y-based kernel and found:
Quoted 6 lines
Applying the patch here:
http://www.spinics.net/lists/linux-scsi/msg56690.html
to the current stable version of the squeeze kernel fixes the issue.This was tested on a Smart Array 712m, connected via 2 SAS switches to a HP P2000 G3 SAS Array.
Stephen, are any other patches from the series at [2] or elsewhere candidates for inclusion in stable trees?
Thanks and hope that helps,
Jonathan
[1] http://bugs.debian.org/661057
[2] http://thread.gmane.org/gmane.linux.kernel/1241509
Re: [3.0.y, 3.2.y, 3.3.y] Re: [PATCH 05/10] hpsa: Fix problem with MSA2xxx devices
Quoted 7 lines · Jonathan Nieder
Hi Greg and Ben,
Please consider
9bc3711cbb67[SCSI] hpsa: Fix problem with MSA2xxx devicesfor application to next week's 3.0.y, 3.2.y, and 3.3.y trees.
[...]
Added to the queue for 3.2.y, thanks.
Ben.
Signature · 2 lines
Ben Hutchings You can't have everything. Where would you put it?
Re: [3.0.y, 3.2.y, 3.3.y] Re: [PATCH 05/10] hpsa: Fix problem with MSA2xxx devices
In reply to Jonathan NiederQuoted 7 lines · Jonathan Nieder
Hi Greg and Ben,
Please consider
9bc3711cbb67[SCSI] hpsa: Fix problem with MSA2xxx devicesfor application to next week's 3.0.y, 3.2.y, and 3.3.y trees.
Now applied to the 3.0.y and 3.3.y trees, thanks.
greg k-h
Re: [3.0.y, 3.2.y, 3.3.y] Re: [PATCH 05/10] hpsa: Fix problem with MSA2xxx devices
Quoted 1 line · Greg KH
Now applied
Thanks, both.
PATCH 6/10 hpsa: make target and lun match what SCSI REPORT LUNs returns
In reply to Stephen M. CameronFrom: Stephen M. Cameron <[email protected]>
Some distros have a "rescan-scsi-bus.sh" script which depends on SCSI REPORT LUNs not reporting something different than what the driver tells the kernel, even if the driver uses scan_start and scan_finished methods of the SCSI host template to override the usual SCSI midlayer discovery code. Previously, 1 was added to the LUN to make room to insert the RAID controller device at LUN 0. Now, the RAID controller is moved to bus 3, and 1 is no longer added to the LUN. However, SCSI REPORT LUNS on Smart Array doesn't report physical devices like tape drives or auto-loaders as it turns out, so those particular device types still won't match. Generally the logical drives are reported first however, so at least those should match.
--- drivers/scsi/hpsa.c | 25 +++++-------------------- 1 files changed, 5 insertions(+), 20 deletions(-)
drivers/scsi/hpsa.c +5 -20
@@ -1645,30 +1645,15 @@ static void figure_bus_target_lun(struct ctlr_info *h, *target = (lunid >>16 ) &0x3fff ; *lun = lunid &0x00ff ; }else { -if (likely (is_scsi_rev_5 (h))) { -/* All current smart arrays (circa 2011) */ - *bus =0 ; - *target =0 ; - *lun = (lunid &0x3fff ) +1 ; - }else { -/* Traditional old smart array way. */ - *bus =0 ; - *target = lunid &0x3fff ; - *lun =0 ; - } + *bus =0 ; + *target =0 ; + *lun = (lunid &0x3fff ); } }else { -/* physical device */ if (is_hba_lunid (lunaddrbytes)) -if (unlikely (is_scsi_rev_5 (h))) { - *bus =0 ;/* put p1210m ctlr at 0,0,0 */ - *target =0 ; - *lun =0 ; -return ; - }else - *bus =3 ;/* traditional smartarray */ + *bus =3 ;/* controller */ else - *bus =2 ;/* physical disk */ + *bus =2 ;/* physical device */ *target =-1 ; *lun =-1 ;/* we will fill these in later. */ }
PATCH 7/10 hpsa: refactor hpsa_figure_bus_target_lun
In reply to Stephen M. CameronFrom: Stephen M. Cameron <[email protected]>
It should call hpsa_set_bus_target_lun rather
than individually setting bus, target and lun.
--- drivers/scsi/hpsa.c | 68 +++++++++++++++++++++++---------------------------- 1 files changed, 30 insertions(+), 38 deletions(-)
drivers/scsi/hpsa.c +30 -38
@@ -1628,35 +1628,30 @@ static int is_msa2xxx(struct ctlr_info *h, struct hpsa_scsi_dev_t *device)* in hpsa_find_target_lun, called by hpsa_scsi_add_entry.) */ static void figure_bus_target_lun (struct ctlr_info *h, -u8 *lunaddrbytes,int *bus,int *target,int *lun, -struct hpsa_scsi_dev_t *device) -{ -u32 lunid; - -if (is_logical_dev_addr_mode (lunaddrbytes)) { -/* logical device */ - lunid =le32_to_cpu (*((__le32 *) lunaddrbytes)); -if (is_msa2xxx (h, device)) { -/* msa2xxx way, put logicals on bus 1 -* and match target/lun numbers box -* reports. -*/ - *bus =1 ; - *target = (lunid >>16 ) &0x3fff ; - *lun = lunid &0x00ff ; - }else { - *bus =0 ; - *target =0 ; - *lun = (lunid &0x3fff ); - } - }else { +u8 *lunaddrbytes,struct hpsa_scsi_dev_t *device) +{ +u32 lunid =le32_to_cpu (*((__le32 *) lunaddrbytes)); + +if (!is_logical_dev_addr_mode (lunaddrbytes)) { +/* physical device, target and lun filled in later */ if (is_hba_lunid (lunaddrbytes)) - *bus =3 ;/* controller */ +hpsa_set_bus_target_lun (device,3 ,0 , lunid &0x3fff );else - *bus =2 ;/* physical device */ - *target =-1 ; - *lun =-1 ;/* we will fill these in later. */ +/* defer target, lun assignment for physical devices */ +hpsa_set_bus_target_lun (device,2 ,-1 ,-1 ); +return ; + } +/* It's a logical device */ +if (is_msa2xxx (h, device)) { +/* msa2xxx way, put logicals on bus 1 +* and match target/lun numbers box +* reports, other smart array, bus 0, target 0, match lunid +*/ +hpsa_set_bus_target_lun (device, +1 , (lunid >>16 ) &0x3fff , lunid &0x00ff ); +return ; } +hpsa_set_bus_target_lun (device,0 ,0 , lunid &0x3fff ); }/*
@@ -1673,12 +1668,11 @@ static void figure_bus_target_lun(struct ctlr_info *h,static int add_msa2xxx_enclosure_device (struct ctlr_info *h,struct hpsa_scsi_dev_t *tmpdevice,struct hpsa_scsi_dev_t *this_device,u8 *lunaddrbytes, -int bus,int target,int lun,unsigned long lunzerobits[], -int *nmsa2xxx_enclosures) +unsigned long lunzerobits[],int *nmsa2xxx_enclosures) {unsigned char scsi3addr[8 ]; -if (test_bit (target, lunzerobits)) +if (test_bit (tmpdevice->target, lunzerobits))return 0 ;/* There is already a lun 0 on this target. */ if (!is_logical_dev_addr_mode (lunaddrbytes))
@@ -1687,11 +1681,11 @@ static int add_msa2xxx_enclosure_device(struct ctlr_info *h,if (!is_msa2xxx (h, tmpdevice))return 0 ;/* It's only the MSA2xxx that have this problem. */ -if (lun ==0 )/* if lun is 0, then obviously we have a lun 0. */ +if (tmpdevice->lun ==0 )/* if lun is 0, then we have a lun 0. */ return 0 ;memset (scsi3addr,0 ,8 ); - scsi3addr[3 ] = target; + scsi3addr[3 ] = tmpdevice->target;if (is_hba_lunid (scsi3addr))return 0 ;/* Don't add the RAID controller here. */
@@ -1708,8 +1702,9 @@ static int add_msa2xxx_enclosure_device(struct ctlr_info *h,if (hpsa_update_device_info (h, scsi3addr, this_device,NULL ))return 0 ; (*nmsa2xxx_enclosures)++; -hpsa_set_bus_target_lun (this_device, bus, target,0 ); -set_bit (target, lunzerobits); +hpsa_set_bus_target_lun (this_device, + tmpdevice->bus, tmpdevice->target,0 ); +set_bit (tmpdevice->target, lunzerobits);return 1 ; }
@@ -1804,7 +1799,6 @@ static void hpsa_update_scsi_devices(struct ctlr_info *h, int hostno)int ncurrent =0 ;int reportlunsize =sizeof (*physdev_list) +HPSA_MAX_PHYS_LUN *8 ;int i, nmsa2xxx_enclosures, ndevs_to_allocate; -int bus, target, lun;int raid_ctlr_position;DECLARE_BITMAP (lunzerobits,HPSA_MAX_TARGETS_PER_CTLR );
@@ -1869,8 +1863,7 @@ static void hpsa_update_scsi_devices(struct ctlr_info *h, int hostno)if (hpsa_update_device_info (h, lunaddrbytes, tmpdevice, &is_OBDR))continue ;/* skip it if we can't talk to it. */ -figure_bus_target_lun (h, lunaddrbytes, &bus, &target, &lun, - tmpdevice); +figure_bus_target_lun (h, lunaddrbytes, tmpdevice); this_device = currentsd[ncurrent];/*
@@ -1881,14 +1874,13 @@ static void hpsa_update_scsi_devices(struct ctlr_info *h, int hostno)* there is no lun 0. */ if (add_msa2xxx_enclosure_device (h, tmpdevice, this_device, - lunaddrbytes, bus, target, lun, lunzerobits, + lunaddrbytes, lunzerobits, &nmsa2xxx_enclosures)) { ncurrent++; this_device = currentsd[ncurrent]; } *this_device = *tmpdevice; -hpsa_set_bus_target_lun (this_device, bus, target, lun);switch (this_device->devtype) {case TYPE_ROM :
PATCH 8/10 hpsa: eliminate 8 external target limitation
In reply to Stephen M. CameronFrom: Scott Teel <[email protected]>
Driver limits SAS external target IDs to range 1-8.
Need to increase limit and clean up overlapping concepts of targets and paths in the code.
There are several defined constants that control this:
HPSA_MAX_TARGETS_PER_CTLR 16 MAX_MSA2XXX_ENCLOSURES 32 HPSA_MAX_PATHS 8
We can condense this to one constant:MAX_EXT_TARGETS 32
SAS switches allow for 8 connections, and there is capacity for 4 switches per enclosure in largest blade enclosure type.
--- drivers/scsi/hpsa.c | 16 ++++++++-------- drivers/scsi/hpsa_cmd.h | 5 ++--- 2 files changed, 10 insertions(+), 11 deletions(-)
drivers/scsi/hpsa.c +8 -8
@@ -1692,9 +1692,9 @@ static int add_msa2xxx_enclosure_device(struct ctlr_info *h,if (is_scsi_rev_5 (h))return 0 ;/* p1210m doesn't need to do this. */ -if (*nmsa2xxx_enclosures >=MAX_MSA2XXX_ENCLOSURES ) { -dev_warn (&h->pdev->dev,"Maximum number of MSA2XXX " -"enclosures exceeded. Check your hardware " +if (*nmsa2xxx_enclosures >=MAX_EXT_TARGETS ) { +dev_warn (&h->pdev->dev,"Maximum number of external " +"target devices exceeded. Check your hardware " "configuration." );return 0 ; }
@@ -1800,7 +1800,7 @@ static void hpsa_update_scsi_devices(struct ctlr_info *h, int hostno)int reportlunsize =sizeof (*physdev_list) +HPSA_MAX_PHYS_LUN *8 ;int i, nmsa2xxx_enclosures, ndevs_to_allocate;int raid_ctlr_position; -DECLARE_BITMAP (lunzerobits,HPSA_MAX_TARGETS_PER_CTLR ); +DECLARE_BITMAP (lunzerobits,MAX_EXT_TARGETS ); currentsd =kzalloc (sizeof (*currentsd) *HPSA_MAX_DEVICES ,GFP_KERNEL ); physdev_list =kzalloc (reportlunsize,GFP_KERNEL );
@@ -1817,11 +1817,11 @@ static void hpsa_update_scsi_devices(struct ctlr_info *h, int hostno) logdev_list, &nlogicals)) goto out; -/* We might see up to 32 MSA2xxx enclosures, actually 8 of them -* but each of them 4 times through different paths. The plus 1 -* is for the RAID controller. +/* We might see up to the maximum number of logical and physical disks +* plus external target devices, and a device for the local RAID +* controller. */ - ndevs_to_allocate = nphysicals + nlogicals +MAX_MSA2XXX_ENCLOSURES +1 ; + ndevs_to_allocate = nphysicals + nlogicals +MAX_EXT_TARGETS +1 ;/* Allocate the per device structures */ for (i =0 ; i < ndevs_to_allocate; i++) {
drivers/scsi/hpsa_cmd.h +2 -3
@@ -122,12 +122,11 @@ union u64bit { };/* FIXME this is a per controller value (barf!) */ -#define HPSA_MAX_TARGETS_PER_CTLR 16#define HPSA_MAX_LUN 1024#define HPSA_MAX_PHYS_LUN 1024 -#define MAX_MSA2XXX_ENCLOSURES 32 +#define MAX_EXT_TARGETS 32#define HPSA_MAX_DEVICES (HPSA_MAX_PHYS_LUN + HPSA_MAX_LUN + \ - MAX_MSA2XXX_ENCLOSURES + 1)/* + 1 is for the controller itself */ + MAX_EXT_TARGETS + 1)/* + 1 is for the controller itself */ /* SCSI-3 Commands */ #pragma pack(1)
PATCH 9/10 hpsa: improve naming on external target device functions
In reply to Stephen M. CameronFrom: Scott Teel <[email protected]>
Reduce confusion and inaccuracy caused by dated naming of vars and functions referring to external target devices.
CURRENT NAMING: PROPOSED NAMING:
"MSA2xxx devices" "external target devices" msa2xxx_model ext_target_model is_msa2xxx is_ext_target add_msa2xxx_enclosure add_ext_target_dev nmsa2xxx_enclosures n_ext_target_devs
--- drivers/scsi/hpsa.c | 43 ++++++++++++++++++++++--------------------- 1 files changed, 22 insertions(+), 21 deletions(-)
drivers/scsi/hpsa.c +22 -21
@@ -214,7 +214,8 @@ static int check_for_unit_attention(struct ctlr_info *h,dev_warn (&h->pdev->dev,HPSA "%d: report LUN data " "changed, action required\n" , h->ctlr);/* -* Note: this REPORT_LUNS_CHANGED condition only occurs on the MSA2012. +* Note: this REPORT_LUNS_CHANGED condition only occurs on the external +* target (array) devices. */ break ;case POWER_OR_RESET :
@@ -1600,7 +1601,7 @@ bail_out:return 1 ; } -static unsigned char *msa2xxx_model[] = { +static unsigned char *ext_target_model[] = {"MSA2012" ,"MSA2024" ,"MSA2312" ,
@@ -1609,19 +1610,19 @@ static unsigned char *msa2xxx_model[] = { NULL, }; -static int is_msa2xxx (struct ctlr_info *h,struct hpsa_scsi_dev_t *device) +static int is_ext_target (struct ctlr_info *h,struct hpsa_scsi_dev_t *device) {int i; -for (i =0 ; msa2xxx_model[i]; i++) -if (strncmp (device->model, msa2xxx_model[i], -strlen (msa2xxx_model[i])) ==0 ) +for (i =0 ; ext_target_model[i]; i++) +if (strncmp (device->model, ext_target_model[i], +strlen (ext_target_model[i])) ==0 )return 1 ;return 0 ; }/* Helper function to assign bus, target, lun mapping of devices. -* Puts non-msa2xxx logical volumes on bus 0, msa2xxx logical +* Puts non-external target logical volumes on bus 0, external target logical * volumes on bus 1, physical devices on bus 2. and the hba on bus 3. * Logical drive target and lun are assigned at this time, but * physical device lun and target assignment are deferred (assigned
@@ -1642,8 +1643,8 @@ static void figure_bus_target_lun(struct ctlr_info *h,return ; }/* It's a logical device */ -if (is_msa2xxx (h, device)) { -/* msa2xxx way, put logicals on bus 1 +if (is_ext_target (h, device)) { +/* external target way, put logicals on bus 1 * and match target/lun numbers box * reports, other smart array, bus 0, target 0, match lunid */
@@ -1656,7 +1657,7 @@ static void figure_bus_target_lun(struct ctlr_info *h,/* * If there is no lun 0 on a target, linux won't find any devices. -* For the MSA2xxx boxes, we have to manually detect the enclosure +* For the external targets (arrays), we have to manually detect the enclosure * which is at lun zero, as CCISS_REPORT_PHYSICAL_LUNS doesn't report * it for some reason. *tmpdevice is the target we're adding, * this_device is a pointer into the current element of currentsd[]
@@ -1665,10 +1666,10 @@ static void figure_bus_target_lun(struct ctlr_info *h,* lun 0 assigned. * Returns 1 if an enclosure was added, 0 if not. */ -static int add_msa2xxx_enclosure_device (struct ctlr_info *h, +static int add_ext_target_dev (struct ctlr_info *h,struct hpsa_scsi_dev_t *tmpdevice,struct hpsa_scsi_dev_t *this_device,u8 *lunaddrbytes, -unsigned long lunzerobits[],int *nmsa2xxx_enclosures) +unsigned long lunzerobits[],int *n_ext_target_devs) {unsigned char scsi3addr[8 ];
@@ -1678,8 +1679,8 @@ static int add_msa2xxx_enclosure_device(struct ctlr_info *h,if (!is_logical_dev_addr_mode (lunaddrbytes))return 0 ;/* It's the logical targets that may lack lun 0. */ -if (!is_msa2xxx (h, tmpdevice)) -return 0 ;/* It's only the MSA2xxx that have this problem. */ +if (!is_ext_target (h, tmpdevice)) +return 0 ;/* Only external target devices have this problem. */ if (tmpdevice->lun ==0 )/* if lun is 0, then we have a lun 0. */ return 0 ;
@@ -1692,7 +1693,7 @@ static int add_msa2xxx_enclosure_device(struct ctlr_info *h,if (is_scsi_rev_5 (h))return 0 ;/* p1210m doesn't need to do this. */ -if (*nmsa2xxx_enclosures >=MAX_EXT_TARGETS ) { +if (*n_ext_target_devs >=MAX_EXT_TARGETS ) {dev_warn (&h->pdev->dev,"Maximum number of external " "target devices exceeded. Check your hardware " "configuration." );
@@ -1701,7 +1702,7 @@ static int add_msa2xxx_enclosure_device(struct ctlr_info *h,if (hpsa_update_device_info (h, scsi3addr, this_device,NULL ))return 0 ; - (*nmsa2xxx_enclosures)++; + (*n_ext_target_devs)++;hpsa_set_bus_target_lun (this_device, tmpdevice->bus, tmpdevice->target,0 );set_bit (tmpdevice->target, lunzerobits);
@@ -1798,7 +1799,7 @@ static void hpsa_update_scsi_devices(struct ctlr_info *h, int hostno)struct hpsa_scsi_dev_t **currentsd, *this_device, *tmpdevice;int ncurrent =0 ;int reportlunsize =sizeof (*physdev_list) +HPSA_MAX_PHYS_LUN *8 ; -int i, nmsa2xxx_enclosures, ndevs_to_allocate; +int i, n_ext_target_devs, ndevs_to_allocate;int raid_ctlr_position;DECLARE_BITMAP (lunzerobits,MAX_EXT_TARGETS );
@@ -1847,7 +1848,7 @@ static void hpsa_update_scsi_devices(struct ctlr_info *h, int hostno) raid_ctlr_position = nphysicals + nlogicals;/* adjust our table of devices */ - nmsa2xxx_enclosures =0 ; + n_ext_target_devs =0 ;for (i =0 ; i < nphysicals + nlogicals +1 ; i++) {u8 *lunaddrbytes, is_OBDR =0 ;
@@ -1867,15 +1868,15 @@ static void hpsa_update_scsi_devices(struct ctlr_info *h, int hostno) this_device = currentsd[ncurrent];/* -* For the msa2xxx boxes, we have to insert a LUN 0 which +* For external target devices, we have to insert a LUN 0 which * doesn't show up in CCISS_REPORT_PHYSICAL data, but there * is nonetheless an enclosure device there. We have to * present that otherwise linux won't find anything if * there is no lun 0. */ -if (add_msa2xxx_enclosure_device (h, tmpdevice, this_device, +if (add_ext_target_dev (h, tmpdevice, this_device, lunaddrbytes, lunzerobits, - &nmsa2xxx_enclosures)) { + &n_ext_target_devs)) { ncurrent++; this_device = currentsd[ncurrent]; }
PATCH 10/10 hpsa: update device attributes when they change
In reply to Stephen M. CameronFrom: Scott Teel <[email protected]>
Certain types of changes to devices should not be interpreted as a device change that would cause the device to be removed and re-added. These include RAID level and Firmware revision changes. However, these attribute changes DO need to be reflected in the controller info structure's dev structure list, so that sysfs and /proc info files for the devices will reflect the new values.
--- drivers/scsi/hpsa.c | 43 ++++++++++++++++++++++++++++++++++++++++--- 1 files changed, 40 insertions(+), 3 deletions(-)
drivers/scsi/hpsa.c +40 -3
@@ -675,6 +675,20 @@ lun_assigned:return 0 ; } +/* Update an entry in h->dev[] array. */ +static void hpsa_scsi_update_entry (struct ctlr_info *h,int hostno, +int entry,struct hpsa_scsi_dev_t *new_entry) +{ +/* assumes h->devlock is held */ +BUG_ON (entry <0 || entry >=HPSA_MAX_DEVICES ); + +/* Raid level changed. */ + h->dev[entry]->raid_level = new_entry->raid_level; +dev_info (&h->pdev->dev,"%s device c%db%dt%dl%d updated.\n" , +scsi_device_type (new_entry->devtype), hostno, new_entry->bus, + new_entry->target, new_entry->lun); +} +/* Replace an entry from h->dev[] array. */ static void hpsa_scsi_replace_entry(struct ctlr_info *h, int hostno, int entry, struct hpsa_scsi_dev_t *new_entry,
@@ -781,10 +795,25 @@ static inline int device_is_the_same(struct hpsa_scsi_dev_t *dev1,return 1 ; } +static inline int device_updated (struct hpsa_scsi_dev_t *dev1, +struct hpsa_scsi_dev_t *dev2) +{ +/* Device attributes that can change, but don't mean +* that the device is a different device, nor that the OS +* needs to be told anything about the change. +*/ +if (dev1->raid_level != dev2->raid_level) +return 1 ; +return 0 ; +} +/* Find needle in haystack. If exact match found, return DEVICE_SAME, * and return needle location in *index. If scsi3addr matches, but not * vendor, model, serial num, etc. return DEVICE_CHANGED, and return needle -* location in *index. If needle not found, return DEVICE_NOT_FOUND. +* location in *index. +* In the case of a minor device attribute change, such as RAID level, just +* return DEVICE_UPDATED, along with the updated device's location in index. +* If needle not found, return DEVICE_NOT_FOUND. */ static int hpsa_scsi_find_entry(struct hpsa_scsi_dev_t *needle, struct hpsa_scsi_dev_t *haystack[], int haystack_size,
@@ -794,15 +823,19 @@ static int hpsa_scsi_find_entry(struct hpsa_scsi_dev_t *needle,#define DEVICE_NOT_FOUND 0#define DEVICE_CHANGED 1#define DEVICE_SAME 2 +#define DEVICE_UPDATED 3for (i =0 ; i < haystack_size; i++) {if (haystack[i] ==NULL )/* previously removed. */ continue ;if (SCSI3ADDR_EQ (needle->scsi3addr, haystack[i]->scsi3addr)) { *index = i; -if (device_is_the_same (needle, haystack[i])) +if (device_is_the_same (needle, haystack[i])) { +if (device_updated (needle, haystack[i])) +return DEVICE_UPDATED ;return DEVICE_SAME ; -else + }else {return DEVICE_CHANGED ; + } } } *index =-1 ;
@@ -838,6 +871,8 @@ static void adjust_hpsa_scsi_table(struct ctlr_info *h, int hostno,* sd[] and remove them from h->dev[], and for any * devices which have changed, remove the old device * info and add the new device info. +* If minor device attributes change, just update +* the existing device structure. */ i =0 ; nremoved =0 ;
@@ -858,6 +893,8 @@ static void adjust_hpsa_scsi_table(struct ctlr_info *h, int hostno,* at the bottom of hpsa_update_scsi_devices() */ sd[entry] =NULL ; + }else if (device_change ==DEVICE_UPDATED ) { +hpsa_scsi_update_entry (h, hostno, i, sd[entry]); } i++; }