aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEric Moore <eric.moore@lsil.com>2006-06-27 16:42:12 -0400
committerJames Bottomley <jejb@mulgrave.il.steeleye.com>2006-06-28 12:41:33 -0400
commit547f9a218436ea35baf9a52e981753e44d9cff1f (patch)
tree59a13af4b90e3f51bf2ca795765161062e44518a
parent65c92b09acf0218b64f1c7ba4fdabeb8b732c876 (diff)
[SCSI] mptsas: wide port support
* Wide port support added - using James Bottomley's new SAS wide port API. (There is a known problem in sas transport layer reported yesterday to James. The Kobject dev.bus_ids for end devices are not unique across expanders. I have added a work around in this patch, where I asigning an unique port identifier for every port within the host - this solves the problem, but I expect a fix from James in the sas transport). * Adding target_alloc and target_destroy entry points, and moving code over from the slave entry points. * The renaming of some mptscsih_xxx functions declared in mptsas.c, to mptsas_xxx. * Target Reset moved from slave_destroy to hotplug work thread handling (with regard to device removal). Also inhibit IO to end device while device is being broken down . Talked to James Smart about this at Linux Expo (with questions of how the fc transport handles this). * Cleaning up the kzalloc's, and kfree's Signed-off-by: Eric Moore <Eric.Moore@lsil.com> Signed-off-by: James Bottomley <James.Bottomley@SteelEye.com>
-rw-r--r--drivers/message/fusion/Makefile5
-rw-r--r--drivers/message/fusion/mptbase.h15
-rw-r--r--drivers/message/fusion/mptsas.c963
3 files changed, 709 insertions, 274 deletions
diff --git a/drivers/message/fusion/Makefile b/drivers/message/fusion/Makefile
index 51740b346224..b114236f4395 100644
--- a/drivers/message/fusion/Makefile
+++ b/drivers/message/fusion/Makefile
@@ -33,6 +33,11 @@
33# For mptfc: 33# For mptfc:
34#CFLAGS_mptfc.o += -DMPT_DEBUG_FC 34#CFLAGS_mptfc.o += -DMPT_DEBUG_FC
35 35
36# For mptsas:
37#CFLAGS_mptsas.o += -DMPT_DEBUG_SAS
38#CFLAGS_mptsas.o += -DMPT_DEBUG_SAS_WIDE
39
40
36#=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-} LSI_LOGIC 41#=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-} LSI_LOGIC
37 42
38obj-$(CONFIG_FUSION_SPI) += mptbase.o mptscsih.o mptspi.o 43obj-$(CONFIG_FUSION_SPI) += mptbase.o mptscsih.o mptspi.o
diff --git a/drivers/message/fusion/mptbase.h b/drivers/message/fusion/mptbase.h
index 4720f9ae86aa..ddef586e09e1 100644
--- a/drivers/message/fusion/mptbase.h
+++ b/drivers/message/fusion/mptbase.h
@@ -76,8 +76,8 @@
76#define COPYRIGHT "Copyright (c) 1999-2005 " MODULEAUTHOR 76#define COPYRIGHT "Copyright (c) 1999-2005 " MODULEAUTHOR
77#endif 77#endif
78 78
79#define MPT_LINUX_VERSION_COMMON "3.03.10" 79#define MPT_LINUX_VERSION_COMMON "3.04.00"
80#define MPT_LINUX_PACKAGE_NAME "@(#)mptlinux-3.03.10" 80#define MPT_LINUX_PACKAGE_NAME "@(#)mptlinux-3.04.00"
81#define WHAT_MAGIC_STRING "@" "(" "#" ")" 81#define WHAT_MAGIC_STRING "@" "(" "#" ")"
82 82
83#define show_mptmod_ver(s,ver) \ 83#define show_mptmod_ver(s,ver) \
@@ -342,6 +342,7 @@ typedef struct _VirtTarget {
342 u8 negoFlags; /* bit field, see above */ 342 u8 negoFlags; /* bit field, see above */
343 u8 raidVolume; /* set, if RAID Volume */ 343 u8 raidVolume; /* set, if RAID Volume */
344 u8 type; /* byte 0 of Inquiry data */ 344 u8 type; /* byte 0 of Inquiry data */
345 u8 deleted; /* target in process of being removed */
345 u32 num_luns; 346 u32 num_luns;
346 u32 luns[8]; /* Max LUNs is 256 */ 347 u32 luns[8]; /* Max LUNs is 256 */
347} VirtTarget; 348} VirtTarget;
@@ -633,7 +634,7 @@ typedef struct _MPT_ADAPTER
633 int sas_index; /* index refrencing */ 634 int sas_index; /* index refrencing */
634 MPT_SAS_MGMT sas_mgmt; 635 MPT_SAS_MGMT sas_mgmt;
635 int num_ports; 636 int num_ports;
636 struct work_struct mptscsih_persistTask; 637 struct work_struct sas_persist_task;
637 638
638 struct work_struct fc_setup_reset_work; 639 struct work_struct fc_setup_reset_work;
639 struct list_head fc_rports; 640 struct list_head fc_rports;
@@ -642,6 +643,7 @@ typedef struct _MPT_ADAPTER
642 struct work_struct fc_rescan_work; 643 struct work_struct fc_rescan_work;
643 char fc_rescan_work_q_name[KOBJ_NAME_LEN]; 644 char fc_rescan_work_q_name[KOBJ_NAME_LEN];
644 struct workqueue_struct *fc_rescan_work_q; 645 struct workqueue_struct *fc_rescan_work_q;
646 u8 port_serial_number;
645} MPT_ADAPTER; 647} MPT_ADAPTER;
646 648
647/* 649/*
@@ -893,6 +895,13 @@ typedef struct _mpt_sge {
893#define DBG_DUMP_REQUEST_FRAME_HDR(mfp) 895#define DBG_DUMP_REQUEST_FRAME_HDR(mfp)
894#endif 896#endif
895 897
898// debug sas wide ports
899#ifdef MPT_DEBUG_SAS_WIDE
900#define dsaswideprintk(x) printk x
901#else
902#define dsaswideprintk(x)
903#endif
904
896 905
897/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/ 906/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
898 907
diff --git a/drivers/message/fusion/mptsas.c b/drivers/message/fusion/mptsas.c
index af6ec553ff7c..0877023cc79b 100644
--- a/drivers/message/fusion/mptsas.c
+++ b/drivers/message/fusion/mptsas.c
@@ -50,11 +50,14 @@
50#include <linux/errno.h> 50#include <linux/errno.h>
51#include <linux/sched.h> 51#include <linux/sched.h>
52#include <linux/workqueue.h> 52#include <linux/workqueue.h>
53#include <linux/delay.h> /* for mdelay */
53 54
55#include <scsi/scsi.h>
54#include <scsi/scsi_cmnd.h> 56#include <scsi/scsi_cmnd.h>
55#include <scsi/scsi_device.h> 57#include <scsi/scsi_device.h>
56#include <scsi/scsi_host.h> 58#include <scsi/scsi_host.h>
57#include <scsi/scsi_transport_sas.h> 59#include <scsi/scsi_transport_sas.h>
60#include <scsi/scsi_dbg.h>
58 61
59#include "mptbase.h" 62#include "mptbase.h"
60#include "mptscsih.h" 63#include "mptscsih.h"
@@ -137,23 +140,37 @@ struct mptsas_devinfo {
137 u32 device_info; /* bitfield detailed info about this device */ 140 u32 device_info; /* bitfield detailed info about this device */
138}; 141};
139 142
143/*
144 * Specific details on ports, wide/narrow
145 */
146struct mptsas_portinfo_details{
147 u8 port_id; /* port number provided to transport */
148 u16 num_phys; /* number of phys belong to this port */
149 u64 phy_bitmask; /* TODO, extend support for 255 phys */
150 struct sas_rphy *rphy; /* transport layer rphy object */
151 struct sas_port *port; /* transport layer port object */
152 struct scsi_target *starget;
153 struct mptsas_portinfo *port_info;
154};
155
140struct mptsas_phyinfo { 156struct mptsas_phyinfo {
141 u8 phy_id; /* phy index */ 157 u8 phy_id; /* phy index */
142 u8 port_id; /* port number this phy is part of */ 158 u8 port_id; /* firmware port identifier */
143 u8 negotiated_link_rate; /* nego'd link rate for this phy */ 159 u8 negotiated_link_rate; /* nego'd link rate for this phy */
144 u8 hw_link_rate; /* hardware max/min phys link rate */ 160 u8 hw_link_rate; /* hardware max/min phys link rate */
145 u8 programmed_link_rate; /* programmed max/min phy link rate */ 161 u8 programmed_link_rate; /* programmed max/min phy link rate */
162 u8 sas_port_add_phy; /* flag to request sas_port_add_phy*/
146 struct mptsas_devinfo identify; /* point to phy device info */ 163 struct mptsas_devinfo identify; /* point to phy device info */
147 struct mptsas_devinfo attached; /* point to attached device info */ 164 struct mptsas_devinfo attached; /* point to attached device info */
148 struct sas_phy *phy; 165 struct sas_phy *phy; /* transport layer phy object */
149 struct sas_rphy *rphy; 166 struct mptsas_portinfo *portinfo;
150 struct scsi_target *starget; 167 struct mptsas_portinfo_details * port_details;
151}; 168};
152 169
153struct mptsas_portinfo { 170struct mptsas_portinfo {
154 struct list_head list; 171 struct list_head list;
155 u16 handle; /* unique id to address this */ 172 u16 handle; /* unique id to address this */
156 u8 num_phys; /* number of phys */ 173 u16 num_phys; /* number of phys */
157 struct mptsas_phyinfo *phy_info; 174 struct mptsas_phyinfo *phy_info;
158}; 175};
159 176
@@ -169,7 +186,7 @@ struct mptsas_enclosure {
169 u8 sep_channel; /* SEP channel logical channel id */ 186 u8 sep_channel; /* SEP channel logical channel id */
170}; 187};
171 188
172#ifdef SASDEBUG 189#ifdef MPT_DEBUG_SAS
173static void mptsas_print_phy_data(MPI_SAS_IO_UNIT0_PHY_DATA *phy_data) 190static void mptsas_print_phy_data(MPI_SAS_IO_UNIT0_PHY_DATA *phy_data)
174{ 191{
175 printk("---- IO UNIT PAGE 0 ------------\n"); 192 printk("---- IO UNIT PAGE 0 ------------\n");
@@ -305,7 +322,7 @@ mptsas_find_portinfo_by_handle(MPT_ADAPTER *ioc, u16 handle)
305static inline int 322static inline int
306mptsas_is_end_device(struct mptsas_devinfo * attached) 323mptsas_is_end_device(struct mptsas_devinfo * attached)
307{ 324{
308 if ((attached->handle) && 325 if ((attached->sas_address) &&
309 (attached->device_info & 326 (attached->device_info &
310 MPI_SAS_DEVICE_INFO_END_DEVICE) && 327 MPI_SAS_DEVICE_INFO_END_DEVICE) &&
311 ((attached->device_info & 328 ((attached->device_info &
@@ -319,6 +336,253 @@ mptsas_is_end_device(struct mptsas_devinfo * attached)
319 return 0; 336 return 0;
320} 337}
321 338
339/* no mutex */
340void
341mptsas_port_delete(struct mptsas_portinfo_details * port_details)
342{
343 struct mptsas_portinfo *port_info;
344 struct mptsas_phyinfo *phy_info;
345 u8 i;
346
347 if (!port_details)
348 return;
349
350 port_info = port_details->port_info;
351 phy_info = port_info->phy_info;
352
353 dsaswideprintk((KERN_DEBUG "%s: [%p]: port=%02d num_phys=%02d "
354 "bitmask=0x%016llX\n",
355 __FUNCTION__, port_details, port_details->port_id,
356 port_details->num_phys, port_details->phy_bitmask));
357
358 for (i = 0; i < port_info->num_phys; i++, phy_info++) {
359 if(phy_info->port_details != port_details)
360 continue;
361 memset(&phy_info->attached, 0, sizeof(struct mptsas_devinfo));
362 phy_info->port_details = NULL;
363 }
364 kfree(port_details);
365}
366
367static inline struct sas_rphy *
368mptsas_get_rphy(struct mptsas_phyinfo *phy_info)
369{
370 if (phy_info->port_details)
371 return phy_info->port_details->rphy;
372 else
373 return NULL;
374}
375
376static inline void
377mptsas_set_rphy(struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
378{
379 if (phy_info->port_details) {
380 phy_info->port_details->rphy = rphy;
381 dsaswideprintk((KERN_DEBUG "sas_rphy_add: rphy=%p\n", rphy));
382 }
383
384#ifdef MPT_DEBUG_SAS_WIDE
385 if (rphy) {
386 dev_printk(KERN_DEBUG, &rphy->dev, "add:");
387 printk("rphy=%p release=%p\n",
388 rphy, rphy->dev.release);
389 }
390#endif
391}
392
393static inline struct sas_port *
394mptsas_get_port(struct mptsas_phyinfo *phy_info)
395{
396 if (phy_info->port_details)
397 return phy_info->port_details->port;
398 else
399 return NULL;
400}
401
402static inline void
403mptsas_set_port(struct mptsas_phyinfo *phy_info, struct sas_port *port)
404{
405 if (phy_info->port_details)
406 phy_info->port_details->port = port;
407
408#ifdef MPT_DEBUG_SAS_WIDE
409 if (port) {
410 dev_printk(KERN_DEBUG, &port->dev, "add: ");
411 printk("port=%p release=%p\n",
412 port, port->dev.release);
413 }
414#endif
415}
416
417static inline struct scsi_target *
418mptsas_get_starget(struct mptsas_phyinfo *phy_info)
419{
420 if (phy_info->port_details)
421 return phy_info->port_details->starget;
422 else
423 return NULL;
424}
425
426static inline void
427mptsas_set_starget(struct mptsas_phyinfo *phy_info, struct scsi_target *
428starget)
429{
430 if (phy_info->port_details)
431 phy_info->port_details->starget = starget;
432}
433
434
435/*
436 * mptsas_setup_wide_ports
437 *
438 * Updates for new and existing narrow/wide port configuration
439 * in the sas_topology
440 */
441void
442mptsas_setup_wide_ports(MPT_ADAPTER *ioc, struct mptsas_portinfo *port_info)
443{
444 struct mptsas_portinfo_details * port_details;
445 struct mptsas_phyinfo *phy_info, *phy_info_cmp;
446 u64 sas_address;
447 int i, j;
448
449 mutex_lock(&ioc->sas_topology_mutex);
450
451 phy_info = port_info->phy_info;
452 for (i = 0 ; i < port_info->num_phys ; i++, phy_info++) {
453 if (phy_info->attached.handle)
454 continue;
455 port_details = phy_info->port_details;
456 if (!port_details)
457 continue;
458 if (port_details->num_phys < 2)
459 continue;
460 /*
461 * Removing a phy from a port, letting the last
462 * phy be removed by firmware events.
463 */
464 dsaswideprintk((KERN_DEBUG
465 "%s: [%p]: port=%d deleting phy = %d\n",
466 __FUNCTION__, port_details,
467 port_details->port_id, i));
468 port_details->num_phys--;
469 port_details->phy_bitmask &= ~ (1 << phy_info->phy_id);
470 memset(&phy_info->attached, 0, sizeof(struct mptsas_devinfo));
471 sas_port_delete_phy(port_details->port, phy_info->phy);
472 phy_info->port_details = NULL;
473 }
474
475 /*
476 * Populate and refresh the tree
477 */
478 phy_info = port_info->phy_info;
479 for (i = 0 ; i < port_info->num_phys ; i++, phy_info++) {
480 sas_address = phy_info->attached.sas_address;
481 dsaswideprintk((KERN_DEBUG "phy_id=%d sas_address=0x%018llX\n",
482 i, sas_address));
483 if (!sas_address)
484 continue;
485 port_details = phy_info->port_details;
486 /*
487 * Forming a port
488 */
489 if (!port_details) {
490 port_details = kzalloc(sizeof(*port_details),
491 GFP_KERNEL);
492 if (!port_details)
493 goto out;
494 port_details->num_phys = 1;
495 port_details->port_info = port_info;
496 port_details->port_id = ioc->port_serial_number++;
497 if (phy_info->phy_id < 64 )
498 port_details->phy_bitmask |=
499 (1 << phy_info->phy_id);
500 phy_info->sas_port_add_phy=1;
501 dsaswideprintk((KERN_DEBUG "\t\tForming port\n\t\t"
502 "phy_id=%d sas_address=0x%018llX\n",
503 i, sas_address));
504 phy_info->port_details = port_details;
505 }
506
507 if (i == port_info->num_phys - 1)
508 continue;
509 phy_info_cmp = &port_info->phy_info[i + 1];
510 for (j = i + 1 ; j < port_info->num_phys ; j++,
511 phy_info_cmp++) {
512 if (!phy_info_cmp->attached.sas_address)
513 continue;
514 if (sas_address != phy_info_cmp->attached.sas_address)
515 continue;
516 if (phy_info_cmp->port_details == port_details )
517 continue;
518 dsaswideprintk((KERN_DEBUG
519 "\t\tphy_id=%d sas_address=0x%018llX\n",
520 j, phy_info_cmp->attached.sas_address));
521 if (phy_info_cmp->port_details) {
522 port_details->rphy =
523 mptsas_get_rphy(phy_info_cmp);
524 port_details->port =
525 mptsas_get_port(phy_info_cmp);
526 port_details->starget =
527 mptsas_get_starget(phy_info_cmp);
528 port_details->port_id =
529 phy_info_cmp->port_details->port_id;
530 port_details->num_phys =
531 phy_info_cmp->port_details->num_phys;
532// port_info->port_serial_number--;
533 ioc->port_serial_number--;
534 if (!phy_info_cmp->port_details->num_phys)
535 kfree(phy_info_cmp->port_details);
536 } else
537 phy_info_cmp->sas_port_add_phy=1;
538 /*
539 * Adding a phy to a port
540 */
541 phy_info_cmp->port_details = port_details;
542 if (phy_info_cmp->phy_id < 64 )
543 port_details->phy_bitmask |=
544 (1 << phy_info_cmp->phy_id);
545 port_details->num_phys++;
546 }
547 }
548
549 out:
550
551#ifdef MPT_DEBUG_SAS_WIDE
552 for (i = 0; i < port_info->num_phys; i++) {
553 port_details = port_info->phy_info[i].port_details;
554 if (!port_details)
555 continue;
556 dsaswideprintk((KERN_DEBUG
557 "%s: [%p]: phy_id=%02d port_id=%02d num_phys=%02d "
558 "bitmask=0x%016llX\n",
559 __FUNCTION__,
560 port_details, i, port_details->port_id,
561 port_details->num_phys, port_details->phy_bitmask));
562 dsaswideprintk((KERN_DEBUG"\t\tport = %p rphy=%p\n",
563 port_details->port, port_details->rphy));
564 }
565 dsaswideprintk((KERN_DEBUG"\n"));
566#endif
567 mutex_unlock(&ioc->sas_topology_mutex);
568}
569
570static void
571mptsas_target_reset(MPT_ADAPTER *ioc, VirtTarget * vtarget)
572{
573 MPT_SCSI_HOST *hd = (MPT_SCSI_HOST *)ioc->sh->hostdata;
574
575 if (mptscsih_TMHandler(hd,
576 MPI_SCSITASKMGMT_TASKTYPE_TARGET_RESET,
577 vtarget->bus_id, vtarget->target_id, 0, 0, 5) < 0) {
578 hd->tmPending = 0;
579 hd->tmState = TM_STATE_NONE;
580 printk(MYIOC_s_WARN_FMT
581 "Error processing TaskMgmt id=%d TARGET_RESET\n",
582 ioc->name, vtarget->target_id);
583 }
584}
585
322static int 586static int
323mptsas_sas_enclosure_pg0(MPT_ADAPTER *ioc, struct mptsas_enclosure *enclosure, 587mptsas_sas_enclosure_pg0(MPT_ADAPTER *ioc, struct mptsas_enclosure *enclosure,
324 u32 form, u32 form_specific) 588 u32 form, u32 form_specific)
@@ -400,11 +664,105 @@ mptsas_slave_configure(struct scsi_device *sdev)
400 return mptscsih_slave_configure(sdev); 664 return mptscsih_slave_configure(sdev);
401} 665}
402 666
403/* 667static int
404 * This is pretty ugly. We will be able to seriously clean it up 668mptsas_target_alloc(struct scsi_target *starget)
405 * once the DV code in mptscsih goes away and we can properly 669{
406 * implement ->target_alloc. 670 struct Scsi_Host *host = dev_to_shost(&starget->dev);
407 */ 671 MPT_SCSI_HOST *hd = (MPT_SCSI_HOST *)host->hostdata;
672 VirtTarget *vtarget;
673 u32 target_id;
674 u32 channel;
675 struct sas_rphy *rphy;
676 struct mptsas_portinfo *p;
677 int i;
678
679 vtarget = kzalloc(sizeof(VirtTarget), GFP_KERNEL);
680 if (!vtarget)
681 return -ENOMEM;
682
683 vtarget->starget = starget;
684 vtarget->ioc_id = hd->ioc->id;
685 vtarget->tflags = MPT_TARGET_FLAGS_Q_YES|MPT_TARGET_FLAGS_VALID_INQUIRY;
686
687 target_id = starget->id;
688 channel = 0;
689
690 hd->Targets[target_id] = vtarget;
691
692 /*
693 * RAID volumes placed beyond the last expected port.
694 */
695 if (starget->channel == hd->ioc->num_ports)
696 goto out;
697
698 rphy = dev_to_rphy(starget->dev.parent);
699 mutex_lock(&hd->ioc->sas_topology_mutex);
700 list_for_each_entry(p, &hd->ioc->sas_topology, list) {
701 for (i = 0; i < p->num_phys; i++) {
702 if (p->phy_info[i].attached.sas_address !=
703 rphy->identify.sas_address)
704 continue;
705 target_id = p->phy_info[i].attached.id;
706 channel = p->phy_info[i].attached.channel;
707 mptsas_set_starget(&p->phy_info[i], starget);
708
709 /*
710 * Exposing hidden raid components
711 */
712 if (mptscsih_is_phys_disk(hd->ioc, target_id)) {
713 target_id = mptscsih_raid_id_to_num(hd,
714 target_id);
715 vtarget->tflags |=
716 MPT_TARGET_FLAGS_RAID_COMPONENT;
717 }
718 mutex_unlock(&hd->ioc->sas_topology_mutex);
719 goto out;
720 }
721 }
722 mutex_unlock(&hd->ioc->sas_topology_mutex);
723
724 kfree(vtarget);
725 return -ENXIO;
726
727 out:
728 vtarget->target_id = target_id;
729 vtarget->bus_id = channel;
730 starget->hostdata = vtarget;
731 return 0;
732}
733
734static void
735mptsas_target_destroy(struct scsi_target *starget)
736{
737 struct Scsi_Host *host = dev_to_shost(&starget->dev);
738 MPT_SCSI_HOST *hd = (MPT_SCSI_HOST *)host->hostdata;
739 struct sas_rphy *rphy;
740 struct mptsas_portinfo *p;
741 int i;
742
743 if (!starget->hostdata)
744 return;
745
746 if (starget->channel == hd->ioc->num_ports)
747 goto out;
748
749 rphy = dev_to_rphy(starget->dev.parent);
750 list_for_each_entry(p, &hd->ioc->sas_topology, list) {
751 for (i = 0; i < p->num_phys; i++) {
752 if (p->phy_info[i].attached.sas_address !=
753 rphy->identify.sas_address)
754 continue;
755 mptsas_set_starget(&p->phy_info[i], NULL);
756 goto out;
757 }
758 }
759
760 out:
761 kfree(starget->hostdata);
762 starget->hostdata = NULL;
763}
764
765
408static int 766static int
409mptsas_slave_alloc(struct scsi_device *sdev) 767mptsas_slave_alloc(struct scsi_device *sdev)
410{ 768{
@@ -412,61 +770,41 @@ mptsas_slave_alloc(struct scsi_device *sdev)
412 MPT_SCSI_HOST *hd = (MPT_SCSI_HOST *)host->hostdata; 770 MPT_SCSI_HOST *hd = (MPT_SCSI_HOST *)host->hostdata;
413 struct sas_rphy *rphy; 771 struct sas_rphy *rphy;
414 struct mptsas_portinfo *p; 772 struct mptsas_portinfo *p;
415 VirtTarget *vtarget;
416 VirtDevice *vdev; 773 VirtDevice *vdev;
417 struct scsi_target *starget; 774 struct scsi_target *starget;
418 u32 target_id; 775 int i;
419 int i;
420 776
421 vdev = kzalloc(sizeof(VirtDevice), GFP_KERNEL); 777 vdev = kzalloc(sizeof(VirtDevice), GFP_KERNEL);
422 if (!vdev) { 778 if (!vdev) {
423 printk(MYIOC_s_ERR_FMT "slave_alloc kmalloc(%zd) FAILED!\n", 779 printk(MYIOC_s_ERR_FMT "slave_alloc kzalloc(%zd) FAILED!\n",
424 hd->ioc->name, sizeof(VirtDevice)); 780 hd->ioc->name, sizeof(VirtDevice));
425 return -ENOMEM; 781 return -ENOMEM;
426 } 782 }
427 sdev->hostdata = vdev;
428 starget = scsi_target(sdev); 783 starget = scsi_target(sdev);
429 vtarget = starget->hostdata; 784 vdev->vtarget = starget->hostdata;
430 vtarget->ioc_id = hd->ioc->id;
431 vdev->vtarget = vtarget;
432 if (vtarget->num_luns == 0) {
433 vtarget->tflags = MPT_TARGET_FLAGS_Q_YES|MPT_TARGET_FLAGS_VALID_INQUIRY;
434 hd->Targets[sdev->id] = vtarget;
435 }
436 785
437 /* 786 /*
438 RAID volumes placed beyond the last expected port. 787 * RAID volumes placed beyond the last expected port.
439 */ 788 */
440 if (sdev->channel == hd->ioc->num_ports) { 789 if (sdev->channel == hd->ioc->num_ports)
441 target_id = sdev->id;
442 vtarget->bus_id = 0;
443 vdev->lun = 0;
444 goto out; 790 goto out;
445 }
446 791
447 rphy = dev_to_rphy(sdev->sdev_target->dev.parent); 792 rphy = dev_to_rphy(sdev->sdev_target->dev.parent);
448 mutex_lock(&hd->ioc->sas_topology_mutex); 793 mutex_lock(&hd->ioc->sas_topology_mutex);
449 list_for_each_entry(p, &hd->ioc->sas_topology, list) { 794 list_for_each_entry(p, &hd->ioc->sas_topology, list) {
450 for (i = 0; i < p->num_phys; i++) { 795 for (i = 0; i < p->num_phys; i++) {
451 if (p->phy_info[i].attached.sas_address == 796 if (p->phy_info[i].attached.sas_address !=
452 rphy->identify.sas_address) { 797 rphy->identify.sas_address)
453 target_id = p->phy_info[i].attached.id; 798 continue;
454 vtarget->bus_id = p->phy_info[i].attached.channel; 799 vdev->lun = sdev->lun;
455 vdev->lun = sdev->lun; 800 /*
456 p->phy_info[i].starget = sdev->sdev_target; 801 * Exposing hidden raid components
457 /* 802 */
458 * Exposing hidden disk (RAID) 803 if (mptscsih_is_phys_disk(hd->ioc,
459 */ 804 p->phy_info[i].attached.id))
460 if (mptscsih_is_phys_disk(hd->ioc, target_id)) { 805 sdev->no_uld_attach = 1;
461 target_id = mptscsih_raid_id_to_num(hd, 806 mutex_unlock(&hd->ioc->sas_topology_mutex);
462 target_id); 807 goto out;
463 vdev->vtarget->tflags |=
464 MPT_TARGET_FLAGS_RAID_COMPONENT;
465 sdev->no_uld_attach = 1;
466 }
467 mutex_unlock(&hd->ioc->sas_topology_mutex);
468 goto out;
469 }
470 } 808 }
471 } 809 }
472 mutex_unlock(&hd->ioc->sas_topology_mutex); 810 mutex_unlock(&hd->ioc->sas_topology_mutex);
@@ -475,57 +813,39 @@ mptsas_slave_alloc(struct scsi_device *sdev)
475 return -ENXIO; 813 return -ENXIO;
476 814
477 out: 815 out:
478 vtarget->target_id = target_id; 816 vdev->vtarget->num_luns++;
479 vtarget->num_luns++; 817 sdev->hostdata = vdev;
480 return 0; 818 return 0;
481} 819}
482 820
483static void 821static int
484mptsas_slave_destroy(struct scsi_device *sdev) 822mptsas_qcmd(struct scsi_cmnd *SCpnt, void (*done)(struct scsi_cmnd *))
485{ 823{
486 struct Scsi_Host *host = sdev->host; 824 VirtDevice *vdev = SCpnt->device->hostdata;
487 MPT_SCSI_HOST *hd = (MPT_SCSI_HOST *)host->hostdata;
488 VirtDevice *vdev;
489 825
490 /* 826// scsi_print_command(SCpnt);
491 * Issue target reset to flush firmware outstanding commands. 827 if (vdev->vtarget->deleted) {
492 */ 828 SCpnt->result = DID_NO_CONNECT << 16;
493 vdev = sdev->hostdata; 829 done(SCpnt);
494 if (vdev->configured_lun){ 830 return 0;
495 if (mptscsih_TMHandler(hd,
496 MPI_SCSITASKMGMT_TASKTYPE_TARGET_RESET,
497 vdev->vtarget->bus_id,
498 vdev->vtarget->target_id,
499 0, 0, 5 /* 5 second timeout */)
500 < 0){
501
502 /* The TM request failed!
503 * Fatal error case.
504 */
505 printk(MYIOC_s_WARN_FMT
506 "Error processing TaskMgmt id=%d TARGET_RESET\n",
507 hd->ioc->name,
508 vdev->vtarget->target_id);
509
510 hd->tmPending = 0;
511 hd->tmState = TM_STATE_NONE;
512 }
513 } 831 }
514 mptscsih_slave_destroy(sdev); 832
833 return mptscsih_qcmd(SCpnt,done);
515} 834}
516 835
836
517static struct scsi_host_template mptsas_driver_template = { 837static struct scsi_host_template mptsas_driver_template = {
518 .module = THIS_MODULE, 838 .module = THIS_MODULE,
519 .proc_name = "mptsas", 839 .proc_name = "mptsas",
520 .proc_info = mptscsih_proc_info, 840 .proc_info = mptscsih_proc_info,
521 .name = "MPT SPI Host", 841 .name = "MPT SPI Host",
522 .info = mptscsih_info, 842 .info = mptscsih_info,
523 .queuecommand = mptscsih_qcmd, 843 .queuecommand = mptsas_qcmd,
524 .target_alloc = mptscsih_target_alloc, 844 .target_alloc = mptsas_target_alloc,
525 .slave_alloc = mptsas_slave_alloc, 845 .slave_alloc = mptsas_slave_alloc,
526 .slave_configure = mptsas_slave_configure, 846 .slave_configure = mptsas_slave_configure,
527 .target_destroy = mptscsih_target_destroy, 847 .target_destroy = mptsas_target_destroy,
528 .slave_destroy = mptsas_slave_destroy, 848 .slave_destroy = mptscsih_slave_destroy,
529 .change_queue_depth = mptscsih_change_queue_depth, 849 .change_queue_depth = mptscsih_change_queue_depth,
530 .eh_abort_handler = mptscsih_abort, 850 .eh_abort_handler = mptscsih_abort,
531 .eh_device_reset_handler = mptscsih_dev_reset, 851 .eh_device_reset_handler = mptscsih_dev_reset,
@@ -795,7 +1115,7 @@ mptsas_sas_io_unit_pg0(MPT_ADAPTER *ioc, struct mptsas_portinfo *port_info)
795 1115
796 port_info->num_phys = buffer->NumPhys; 1116 port_info->num_phys = buffer->NumPhys;
797 port_info->phy_info = kcalloc(port_info->num_phys, 1117 port_info->phy_info = kcalloc(port_info->num_phys,
798 sizeof(struct mptsas_phyinfo),GFP_KERNEL); 1118 sizeof(*port_info->phy_info),GFP_KERNEL);
799 if (!port_info->phy_info) { 1119 if (!port_info->phy_info) {
800 error = -ENOMEM; 1120 error = -ENOMEM;
801 goto out_free_consistent; 1121 goto out_free_consistent;
@@ -811,6 +1131,7 @@ mptsas_sas_io_unit_pg0(MPT_ADAPTER *ioc, struct mptsas_portinfo *port_info)
811 buffer->PhyData[i].Port; 1131 buffer->PhyData[i].Port;
812 port_info->phy_info[i].negotiated_link_rate = 1132 port_info->phy_info[i].negotiated_link_rate =
813 buffer->PhyData[i].NegotiatedLinkRate; 1133 buffer->PhyData[i].NegotiatedLinkRate;
1134 port_info->phy_info[i].portinfo = port_info;
814 } 1135 }
815 1136
816 out_free_consistent: 1137 out_free_consistent:
@@ -968,7 +1289,7 @@ mptsas_sas_expander_pg0(MPT_ADAPTER *ioc, struct mptsas_portinfo *port_info,
968 CONFIGPARMS cfg; 1289 CONFIGPARMS cfg;
969 SasExpanderPage0_t *buffer; 1290 SasExpanderPage0_t *buffer;
970 dma_addr_t dma_handle; 1291 dma_addr_t dma_handle;
971 int error; 1292 int i, error;
972 1293
973 hdr.PageVersion = MPI_SASEXPANDER0_PAGEVERSION; 1294 hdr.PageVersion = MPI_SASEXPANDER0_PAGEVERSION;
974 hdr.ExtPageLength = 0; 1295 hdr.ExtPageLength = 0;
@@ -1013,12 +1334,15 @@ mptsas_sas_expander_pg0(MPT_ADAPTER *ioc, struct mptsas_portinfo *port_info,
1013 port_info->num_phys = buffer->NumPhys; 1334 port_info->num_phys = buffer->NumPhys;
1014 port_info->handle = le16_to_cpu(buffer->DevHandle); 1335 port_info->handle = le16_to_cpu(buffer->DevHandle);
1015 port_info->phy_info = kcalloc(port_info->num_phys, 1336 port_info->phy_info = kcalloc(port_info->num_phys,
1016 sizeof(struct mptsas_phyinfo),GFP_KERNEL); 1337 sizeof(*port_info->phy_info),GFP_KERNEL);
1017 if (!port_info->phy_info) { 1338 if (!port_info->phy_info) {
1018 error = -ENOMEM; 1339 error = -ENOMEM;
1019 goto out_free_consistent; 1340 goto out_free_consistent;
1020 } 1341 }
1021 1342
1343 for (i = 0; i < port_info->num_phys; i++)
1344 port_info->phy_info[i].portinfo = port_info;
1345
1022 out_free_consistent: 1346 out_free_consistent:
1023 pci_free_consistent(ioc->pcidev, hdr.ExtPageLength * 4, 1347 pci_free_consistent(ioc->pcidev, hdr.ExtPageLength * 4,
1024 buffer, dma_handle); 1348 buffer, dma_handle);
@@ -1161,19 +1485,23 @@ static int mptsas_probe_one_phy(struct device *dev,
1161{ 1485{
1162 MPT_ADAPTER *ioc; 1486 MPT_ADAPTER *ioc;
1163 struct sas_phy *phy; 1487 struct sas_phy *phy;
1164 int error; 1488 struct sas_port *port;
1489 int error = 0;
1165 1490
1166 if (!dev) 1491 if (!dev) {
1167 return -ENODEV; 1492 error = -ENODEV;
1493 goto out;
1494 }
1168 1495
1169 if (!phy_info->phy) { 1496 if (!phy_info->phy) {
1170 phy = sas_phy_alloc(dev, index); 1497 phy = sas_phy_alloc(dev, index);
1171 if (!phy) 1498 if (!phy) {
1172 return -ENOMEM; 1499 error = -ENOMEM;
1500 goto out;
1501 }
1173 } else 1502 } else
1174 phy = phy_info->phy; 1503 phy = phy_info->phy;
1175 1504
1176 phy->port_identifier = phy_info->port_id;
1177 mptsas_parse_device_info(&phy->identify, &phy_info->identify); 1505 mptsas_parse_device_info(&phy->identify, &phy_info->identify);
1178 1506
1179 /* 1507 /*
@@ -1265,19 +1593,50 @@ static int mptsas_probe_one_phy(struct device *dev,
1265 error = sas_phy_add(phy); 1593 error = sas_phy_add(phy);
1266 if (error) { 1594 if (error) {
1267 sas_phy_free(phy); 1595 sas_phy_free(phy);
1268 return error; 1596 goto out;
1269 } 1597 }
1270 phy_info->phy = phy; 1598 phy_info->phy = phy;
1271 } 1599 }
1272 1600
1273 if ((phy_info->attached.handle) && 1601 if (!phy_info->attached.handle ||
1274 (!phy_info->rphy)) { 1602 !phy_info->port_details)
1603 goto out;
1604
1605 port = mptsas_get_port(phy_info);
1606 ioc = phy_to_ioc(phy_info->phy);
1607
1608 if (phy_info->sas_port_add_phy) {
1609
1610 if (!port) {
1611 port = sas_port_alloc(dev,
1612 phy_info->port_details->port_id);
1613 dsaswideprintk((KERN_DEBUG
1614 "sas_port_alloc: port=%p dev=%p port_id=%d\n",
1615 port, dev, phy_info->port_details->port_id));
1616 if (!port) {
1617 error = -ENOMEM;
1618 goto out;
1619 }
1620 error = sas_port_add(port);
1621 if (error) {
1622 dfailprintk((MYIOC_s_ERR_FMT
1623 "%s: exit at line=%d\n", ioc->name,
1624 __FUNCTION__, __LINE__));
1625 goto out;
1626 }
1627 mptsas_set_port(phy_info, port);
1628 }
1629 dsaswideprintk((KERN_DEBUG "sas_port_add_phy: phy_id=%d\n",
1630 phy_info->phy_id));
1631 sas_port_add_phy(port, phy_info->phy);
1632 phy_info->sas_port_add_phy = 0;
1633 }
1634
1635 if (!mptsas_get_rphy(phy_info) && port && !port->rphy) {
1275 1636
1276 struct sas_rphy *rphy; 1637 struct sas_rphy *rphy;
1277 struct sas_identify identify; 1638 struct sas_identify identify;
1278 1639
1279 ioc = phy_to_ioc(phy_info->phy);
1280
1281 /* 1640 /*
1282 * Let the hotplug_work thread handle processing 1641 * Let the hotplug_work thread handle processing
1283 * the adding/removing of devices that occur 1642 * the adding/removing of devices that occur
@@ -1285,36 +1644,42 @@ static int mptsas_probe_one_phy(struct device *dev,
1285 */ 1644 */
1286 if (ioc->sas_discovery_runtime && 1645 if (ioc->sas_discovery_runtime &&
1287 mptsas_is_end_device(&phy_info->attached)) 1646 mptsas_is_end_device(&phy_info->attached))
1288 return 0; 1647 goto out;
1289 1648
1290 mptsas_parse_device_info(&identify, &phy_info->attached); 1649 mptsas_parse_device_info(&identify, &phy_info->attached);
1291 switch (identify.device_type) { 1650 switch (identify.device_type) {
1292 case SAS_END_DEVICE: 1651 case SAS_END_DEVICE:
1293 rphy = sas_end_device_alloc(phy); 1652 rphy = sas_end_device_alloc(port);
1294 break; 1653 break;
1295 case SAS_EDGE_EXPANDER_DEVICE: 1654 case SAS_EDGE_EXPANDER_DEVICE:
1296 case SAS_FANOUT_EXPANDER_DEVICE: 1655 case SAS_FANOUT_EXPANDER_DEVICE:
1297 rphy = sas_expander_alloc(phy, identify.device_type); 1656 rphy = sas_expander_alloc(port, identify.device_type);
1298 break; 1657 break;
1299 default: 1658 default:
1300 rphy = NULL; 1659 rphy = NULL;
1301 break; 1660 break;
1302 } 1661 }
1303 if (!rphy) 1662 if (!rphy) {
1304 return 0; /* non-fatal: an rphy can be added later */ 1663 dfailprintk((MYIOC_s_ERR_FMT
1664 "%s: exit at line=%d\n", ioc->name,
1665 __FUNCTION__, __LINE__));
1666 goto out;
1667 }
1305 1668
1306 rphy->identify = identify; 1669 rphy->identify = identify;
1307
1308 error = sas_rphy_add(rphy); 1670 error = sas_rphy_add(rphy);
1309 if (error) { 1671 if (error) {
1672 dfailprintk((MYIOC_s_ERR_FMT
1673 "%s: exit at line=%d\n", ioc->name,
1674 __FUNCTION__, __LINE__));
1310 sas_rphy_free(rphy); 1675 sas_rphy_free(rphy);
1311 return error; 1676 goto out;
1312 } 1677 }
1313 1678 mptsas_set_rphy(phy_info, rphy);
1314 phy_info->rphy = rphy;
1315 } 1679 }
1316 1680
1317 return 0; 1681 out:
1682 return error;
1318} 1683}
1319 1684
1320static int 1685static int
@@ -1342,8 +1707,7 @@ mptsas_probe_hba_phys(MPT_ADAPTER *ioc)
1342 for (i = 0; i < hba->num_phys; i++) 1707 for (i = 0; i < hba->num_phys; i++)
1343 port_info->phy_info[i].negotiated_link_rate = 1708 port_info->phy_info[i].negotiated_link_rate =
1344 hba->phy_info[i].negotiated_link_rate; 1709 hba->phy_info[i].negotiated_link_rate;
1345 if (hba->phy_info) 1710 kfree(hba->phy_info);
1346 kfree(hba->phy_info);
1347 kfree(hba); 1711 kfree(hba);
1348 hba = NULL; 1712 hba = NULL;
1349 } 1713 }
@@ -1362,24 +1726,24 @@ mptsas_probe_hba_phys(MPT_ADAPTER *ioc)
1362 port_info->phy_info[i].phy_id; 1726 port_info->phy_info[i].phy_id;
1363 handle = port_info->phy_info[i].identify.handle; 1727 handle = port_info->phy_info[i].identify.handle;
1364 1728
1365 if (port_info->phy_info[i].attached.handle) { 1729 if (port_info->phy_info[i].attached.handle)
1366 mptsas_sas_device_pg0(ioc, 1730 mptsas_sas_device_pg0(ioc,
1367 &port_info->phy_info[i].attached, 1731 &port_info->phy_info[i].attached,
1368 (MPI_SAS_DEVICE_PGAD_FORM_HANDLE << 1732 (MPI_SAS_DEVICE_PGAD_FORM_HANDLE <<
1369 MPI_SAS_DEVICE_PGAD_FORM_SHIFT), 1733 MPI_SAS_DEVICE_PGAD_FORM_SHIFT),
1370 port_info->phy_info[i].attached.handle); 1734 port_info->phy_info[i].attached.handle);
1371 } 1735 }
1372 1736
1737 mptsas_setup_wide_ports(ioc, port_info);
1738
1739 for (i = 0; i < port_info->num_phys; i++, ioc->sas_index++)
1373 mptsas_probe_one_phy(&ioc->sh->shost_gendev, 1740 mptsas_probe_one_phy(&ioc->sh->shost_gendev,
1374 &port_info->phy_info[i], ioc->sas_index, 1); 1741 &port_info->phy_info[i], ioc->sas_index, 1);
1375 ioc->sas_index++;
1376 }
1377 1742
1378 return 0; 1743 return 0;
1379 1744
1380 out_free_port_info: 1745 out_free_port_info:
1381 if (hba) 1746 kfree(hba);
1382 kfree(hba);
1383 out: 1747 out:
1384 return error; 1748 return error;
1385} 1749}
@@ -1388,6 +1752,8 @@ static int
1388mptsas_probe_expander_phys(MPT_ADAPTER *ioc, u32 *handle) 1752mptsas_probe_expander_phys(MPT_ADAPTER *ioc, u32 *handle)
1389{ 1753{
1390 struct mptsas_portinfo *port_info, *p, *ex; 1754 struct mptsas_portinfo *port_info, *p, *ex;
1755 struct device *parent;
1756 struct sas_rphy *rphy;
1391 int error = -ENOMEM, i, j; 1757 int error = -ENOMEM, i, j;
1392 1758
1393 ex = kzalloc(sizeof(*port_info), GFP_KERNEL); 1759 ex = kzalloc(sizeof(*port_info), GFP_KERNEL);
@@ -1409,16 +1775,13 @@ mptsas_probe_expander_phys(MPT_ADAPTER *ioc, u32 *handle)
1409 list_add_tail(&port_info->list, &ioc->sas_topology); 1775 list_add_tail(&port_info->list, &ioc->sas_topology);
1410 } else { 1776 } else {
1411 port_info->handle = ex->handle; 1777 port_info->handle = ex->handle;
1412 if (ex->phy_info) 1778 kfree(ex->phy_info);
1413 kfree(ex->phy_info);
1414 kfree(ex); 1779 kfree(ex);
1415 ex = NULL; 1780 ex = NULL;
1416 } 1781 }
1417 mutex_unlock(&ioc->sas_topology_mutex); 1782 mutex_unlock(&ioc->sas_topology_mutex);
1418 1783
1419 for (i = 0; i < port_info->num_phys; i++) { 1784 for (i = 0; i < port_info->num_phys; i++) {
1420 struct device *parent;
1421
1422 mptsas_sas_expander_pg1(ioc, &port_info->phy_info[i], 1785 mptsas_sas_expander_pg1(ioc, &port_info->phy_info[i],
1423 (MPI_SAS_EXPAND_PGAD_FORM_HANDLE_PHY_NUM << 1786 (MPI_SAS_EXPAND_PGAD_FORM_HANDLE_PHY_NUM <<
1424 MPI_SAS_EXPAND_PGAD_FORM_SHIFT), (i << 16) + *handle); 1787 MPI_SAS_EXPAND_PGAD_FORM_SHIFT), (i << 16) + *handle);
@@ -1442,34 +1805,34 @@ mptsas_probe_expander_phys(MPT_ADAPTER *ioc, u32 *handle)
1442 port_info->phy_info[i].attached.phy_id = 1805 port_info->phy_info[i].attached.phy_id =
1443 port_info->phy_info[i].phy_id; 1806 port_info->phy_info[i].phy_id;
1444 } 1807 }
1808 }
1445 1809
1446 /* 1810 parent = &ioc->sh->shost_gendev;
1447 * If we find a parent port handle this expander is 1811 for (i = 0; i < port_info->num_phys; i++) {
1448 * attached to another expander, else it hangs of the
1449 * HBA phys.
1450 */
1451 parent = &ioc->sh->shost_gendev;
1452 mutex_lock(&ioc->sas_topology_mutex); 1812 mutex_lock(&ioc->sas_topology_mutex);
1453 list_for_each_entry(p, &ioc->sas_topology, list) { 1813 list_for_each_entry(p, &ioc->sas_topology, list) {
1454 for (j = 0; j < p->num_phys; j++) { 1814 for (j = 0; j < p->num_phys; j++) {
1455 if (port_info->phy_info[i].identify.handle == 1815 if (port_info->phy_info[i].identify.handle !=
1456 p->phy_info[j].attached.handle) 1816 p->phy_info[j].attached.handle)
1457 parent = &p->phy_info[j].rphy->dev; 1817 continue;
1818 rphy = mptsas_get_rphy(&p->phy_info[j]);
1819 parent = &rphy->dev;
1458 } 1820 }
1459 } 1821 }
1460 mutex_unlock(&ioc->sas_topology_mutex); 1822 mutex_unlock(&ioc->sas_topology_mutex);
1823 }
1824
1825 mptsas_setup_wide_ports(ioc, port_info);
1461 1826
1827 for (i = 0; i < port_info->num_phys; i++, ioc->sas_index++)
1462 mptsas_probe_one_phy(parent, &port_info->phy_info[i], 1828 mptsas_probe_one_phy(parent, &port_info->phy_info[i],
1463 ioc->sas_index, 0); 1829 ioc->sas_index, 0);
1464 ioc->sas_index++;
1465 }
1466 1830
1467 return 0; 1831 return 0;
1468 1832
1469 out_free_port_info: 1833 out_free_port_info:
1470 if (ex) { 1834 if (ex) {
1471 if (ex->phy_info) 1835 kfree(ex->phy_info);
1472 kfree(ex->phy_info);
1473 kfree(ex); 1836 kfree(ex);
1474 } 1837 }
1475 out: 1838 out:
@@ -1488,7 +1851,12 @@ mptsas_delete_expander_phys(MPT_ADAPTER *ioc)
1488{ 1851{
1489 struct mptsas_portinfo buffer; 1852 struct mptsas_portinfo buffer;
1490 struct mptsas_portinfo *port_info, *n, *parent; 1853 struct mptsas_portinfo *port_info, *n, *parent;
1854 struct mptsas_phyinfo *phy_info;
1855 struct scsi_target * starget;
1856 VirtTarget * vtarget;
1857 struct sas_port * port;
1491 int i; 1858 int i;
1859 u64 expander_sas_address;
1492 1860
1493 mutex_lock(&ioc->sas_topology_mutex); 1861 mutex_lock(&ioc->sas_topology_mutex);
1494 list_for_each_entry_safe(port_info, n, &ioc->sas_topology, list) { 1862 list_for_each_entry_safe(port_info, n, &ioc->sas_topology, list) {
@@ -1503,6 +1871,25 @@ mptsas_delete_expander_phys(MPT_ADAPTER *ioc)
1503 MPI_SAS_EXPAND_PGAD_FORM_SHIFT), port_info->handle)) { 1871 MPI_SAS_EXPAND_PGAD_FORM_SHIFT), port_info->handle)) {
1504 1872
1505 /* 1873 /*
1874 * Issue target reset to all child end devices
1875 * then mark them deleted to prevent further
1876 * IO going to them.
1877 */
1878 phy_info = port_info->phy_info;
1879 for (i = 0; i < port_info->num_phys; i++, phy_info++) {
1880 starget = mptsas_get_starget(phy_info);
1881 if (!starget)
1882 continue;
1883 vtarget = starget->hostdata;
1884 if(vtarget->deleted)
1885 continue;
1886 vtarget->deleted = 1;
1887 mptsas_target_reset(ioc, vtarget);
1888 sas_port_delete(mptsas_get_port(phy_info));
1889 mptsas_port_delete(phy_info->port_details);
1890 }
1891
1892 /*
1506 * Obtain the port_info instance to the parent port 1893 * Obtain the port_info instance to the parent port
1507 */ 1894 */
1508 parent = mptsas_find_portinfo_by_handle(ioc, 1895 parent = mptsas_find_portinfo_by_handle(ioc,
@@ -1511,34 +1898,43 @@ mptsas_delete_expander_phys(MPT_ADAPTER *ioc)
1511 if (!parent) 1898 if (!parent)
1512 goto next_port; 1899 goto next_port;
1513 1900
1901 expander_sas_address =
1902 port_info->phy_info[0].identify.sas_address;
1903
1514 /* 1904 /*
1515 * Delete rphys in the parent that point 1905 * Delete rphys in the parent that point
1516 * to this expander. The transport layer will 1906 * to this expander. The transport layer will
1517 * cleanup all the children. 1907 * cleanup all the children.
1518 */ 1908 */
1519 for (i = 0; i < parent->num_phys; i++) { 1909 phy_info = parent->phy_info;
1520 if ((!parent->phy_info[i].rphy) || 1910 for (i = 0; i < parent->num_phys; i++, phy_info++) {
1521 (parent->phy_info[i].attached.sas_address != 1911 port = mptsas_get_port(phy_info);
1522 port_info->phy_info[i].identify.sas_address)) 1912 if (!port)
1913 continue;
1914 if (phy_info->attached.sas_address !=
1915 expander_sas_address)
1523 continue; 1916 continue;
1524 sas_rphy_delete(parent->phy_info[i].rphy); 1917#ifdef MPT_DEBUG_SAS_WIDE
1525 memset(&parent->phy_info[i].attached, 0, 1918 dev_printk(KERN_DEBUG, &port->dev, "delete\n");
1526 sizeof(struct mptsas_devinfo)); 1919#endif
1527 parent->phy_info[i].rphy = NULL; 1920 sas_port_delete(port);
1528 parent->phy_info[i].starget = NULL; 1921 mptsas_port_delete(phy_info->port_details);
1529 } 1922 }
1530 next_port: 1923 next_port:
1924
1925 phy_info = port_info->phy_info;
1926 for (i = 0; i < port_info->num_phys; i++, phy_info++)
1927 mptsas_port_delete(phy_info->port_details);
1928
1531 list_del(&port_info->list); 1929 list_del(&port_info->list);
1532 if (port_info->phy_info) 1930 kfree(port_info->phy_info);
1533 kfree(port_info->phy_info);
1534 kfree(port_info); 1931 kfree(port_info);
1535 } 1932 }
1536 /* 1933 /*
1537 * Free this memory allocated from inside 1934 * Free this memory allocated from inside
1538 * mptsas_sas_expander_pg0 1935 * mptsas_sas_expander_pg0
1539 */ 1936 */
1540 if (buffer.phy_info) 1937 kfree(buffer.phy_info);
1541 kfree(buffer.phy_info);
1542 } 1938 }
1543 mutex_unlock(&ioc->sas_topology_mutex); 1939 mutex_unlock(&ioc->sas_topology_mutex);
1544} 1940}
@@ -1574,60 +1970,59 @@ mptsas_scan_sas_topology(MPT_ADAPTER *ioc)
1574/* 1970/*
1575 * Work queue thread to handle Runtime discovery 1971 * Work queue thread to handle Runtime discovery
1576 * Mere purpose is the hot add/delete of expanders 1972 * Mere purpose is the hot add/delete of expanders
1973 *(Mutex UNLOCKED)
1577 */ 1974 */
1578static void 1975static void
1579mptscsih_discovery_work(void * arg) 1976__mptsas_discovery_work(MPT_ADAPTER *ioc)
1580{ 1977{
1581 struct mptsas_discovery_event *ev = arg;
1582 MPT_ADAPTER *ioc = ev->ioc;
1583 u32 handle = 0xFFFF; 1978 u32 handle = 0xFFFF;
1584 1979
1585 mutex_lock(&ioc->sas_discovery_mutex);
1586 ioc->sas_discovery_runtime=1; 1980 ioc->sas_discovery_runtime=1;
1587 mptsas_delete_expander_phys(ioc); 1981 mptsas_delete_expander_phys(ioc);
1588 mptsas_probe_hba_phys(ioc); 1982 mptsas_probe_hba_phys(ioc);
1589 while (!mptsas_probe_expander_phys(ioc, &handle)) 1983 while (!mptsas_probe_expander_phys(ioc, &handle))
1590 ; 1984 ;
1591 kfree(ev);
1592 ioc->sas_discovery_runtime=0; 1985 ioc->sas_discovery_runtime=0;
1986}
1987
1988/*
1989 * Work queue thread to handle Runtime discovery
1990 * Mere purpose is the hot add/delete of expanders
1991 *(Mutex LOCKED)
1992 */
1993static void
1994mptsas_discovery_work(void * arg)
1995{
1996 struct mptsas_discovery_event *ev = arg;
1997 MPT_ADAPTER *ioc = ev->ioc;
1998
1999 mutex_lock(&ioc->sas_discovery_mutex);
2000 __mptsas_discovery_work(ioc);
1593 mutex_unlock(&ioc->sas_discovery_mutex); 2001 mutex_unlock(&ioc->sas_discovery_mutex);
2002 kfree(ev);
1594} 2003}
1595 2004
1596static struct mptsas_phyinfo * 2005static struct mptsas_phyinfo *
1597mptsas_find_phyinfo_by_parent(MPT_ADAPTER *ioc, u16 parent_handle, u8 phy_id) 2006mptsas_find_phyinfo_by_sas_address(MPT_ADAPTER *ioc, u64 sas_address)
1598{ 2007{
1599 struct mptsas_portinfo *port_info; 2008 struct mptsas_portinfo *port_info;
1600 struct mptsas_devinfo device_info;
1601 struct mptsas_phyinfo *phy_info = NULL; 2009 struct mptsas_phyinfo *phy_info = NULL;
1602 int i, error; 2010 int i;
1603
1604 /*
1605 * Retrieve the parent sas_address
1606 */
1607 error = mptsas_sas_device_pg0(ioc, &device_info,
1608 (MPI_SAS_DEVICE_PGAD_FORM_HANDLE <<
1609 MPI_SAS_DEVICE_PGAD_FORM_SHIFT),
1610 parent_handle);
1611 if (error)
1612 return NULL;
1613 2011
1614 /*
1615 * The phy_info structures are never deallocated during lifetime of
1616 * a host, so the code below is safe without additional refcounting.
1617 */
1618 mutex_lock(&ioc->sas_topology_mutex); 2012 mutex_lock(&ioc->sas_topology_mutex);
1619 list_for_each_entry(port_info, &ioc->sas_topology, list) { 2013 list_for_each_entry(port_info, &ioc->sas_topology, list) {
1620 for (i = 0; i < port_info->num_phys; i++) { 2014 for (i = 0; i < port_info->num_phys; i++) {
1621 if (port_info->phy_info[i].identify.sas_address == 2015 if (port_info->phy_info[i].attached.sas_address
1622 device_info.sas_address && 2016 != sas_address)
1623 port_info->phy_info[i].phy_id == phy_id) { 2017 continue;
1624 phy_info = &port_info->phy_info[i]; 2018 if (!mptsas_is_end_device(
1625 break; 2019 &port_info->phy_info[i].attached))
1626 } 2020 continue;
2021 phy_info = &port_info->phy_info[i];
2022 break;
1627 } 2023 }
1628 } 2024 }
1629 mutex_unlock(&ioc->sas_topology_mutex); 2025 mutex_unlock(&ioc->sas_topology_mutex);
1630
1631 return phy_info; 2026 return phy_info;
1632} 2027}
1633 2028
@@ -1638,21 +2033,19 @@ mptsas_find_phyinfo_by_target(MPT_ADAPTER *ioc, u32 id)
1638 struct mptsas_phyinfo *phy_info = NULL; 2033 struct mptsas_phyinfo *phy_info = NULL;
1639 int i; 2034 int i;
1640 2035
1641 /*
1642 * The phy_info structures are never deallocated during lifetime of
1643 * a host, so the code below is safe without additional refcounting.
1644 */
1645 mutex_lock(&ioc->sas_topology_mutex); 2036 mutex_lock(&ioc->sas_topology_mutex);
1646 list_for_each_entry(port_info, &ioc->sas_topology, list) { 2037 list_for_each_entry(port_info, &ioc->sas_topology, list) {
1647 for (i = 0; i < port_info->num_phys; i++) 2038 for (i = 0; i < port_info->num_phys; i++) {
1648 if (mptsas_is_end_device(&port_info->phy_info[i].attached)) 2039 if (port_info->phy_info[i].attached.id != id)
1649 if (port_info->phy_info[i].attached.id == id) { 2040 continue;
1650 phy_info = &port_info->phy_info[i]; 2041 if (!mptsas_is_end_device(
1651 break; 2042 &port_info->phy_info[i].attached))
1652 } 2043 continue;
2044 phy_info = &port_info->phy_info[i];
2045 break;
2046 }
1653 } 2047 }
1654 mutex_unlock(&ioc->sas_topology_mutex); 2048 mutex_unlock(&ioc->sas_topology_mutex);
1655
1656 return phy_info; 2049 return phy_info;
1657} 2050}
1658 2051
@@ -1660,7 +2053,7 @@ mptsas_find_phyinfo_by_target(MPT_ADAPTER *ioc, u32 id)
1660 * Work queue thread to clear the persitency table 2053 * Work queue thread to clear the persitency table
1661 */ 2054 */
1662static void 2055static void
1663mptscsih_sas_persist_clear_table(void * arg) 2056mptsas_persist_clear_table(void * arg)
1664{ 2057{
1665 MPT_ADAPTER *ioc = (MPT_ADAPTER *)arg; 2058 MPT_ADAPTER *ioc = (MPT_ADAPTER *)arg;
1666 2059
@@ -1681,7 +2074,6 @@ mptsas_reprobe_target(struct scsi_target *starget, int uld_attach)
1681 mptsas_reprobe_lun); 2074 mptsas_reprobe_lun);
1682} 2075}
1683 2076
1684
1685/* 2077/*
1686 * Work queue thread to handle SAS hotplug events 2078 * Work queue thread to handle SAS hotplug events
1687 */ 2079 */
@@ -1692,14 +2084,17 @@ mptsas_hotplug_work(void *arg)
1692 MPT_ADAPTER *ioc = ev->ioc; 2084 MPT_ADAPTER *ioc = ev->ioc;
1693 struct mptsas_phyinfo *phy_info; 2085 struct mptsas_phyinfo *phy_info;
1694 struct sas_rphy *rphy; 2086 struct sas_rphy *rphy;
2087 struct sas_port *port;
1695 struct scsi_device *sdev; 2088 struct scsi_device *sdev;
2089 struct scsi_target * starget;
1696 struct sas_identify identify; 2090 struct sas_identify identify;
1697 char *ds = NULL; 2091 char *ds = NULL;
1698 struct mptsas_devinfo sas_device; 2092 struct mptsas_devinfo sas_device;
1699 VirtTarget *vtarget; 2093 VirtTarget *vtarget;
2094 VirtDevice *vdevice;
1700 2095
1701 mutex_lock(&ioc->sas_discovery_mutex);
1702 2096
2097 mutex_lock(&ioc->sas_discovery_mutex);
1703 switch (ev->event_type) { 2098 switch (ev->event_type) {
1704 case MPTSAS_DEL_DEVICE: 2099 case MPTSAS_DEL_DEVICE:
1705 2100
@@ -1708,24 +2103,50 @@ mptsas_hotplug_work(void *arg)
1708 /* 2103 /*
1709 * Sanity checks, for non-existing phys and remote rphys. 2104 * Sanity checks, for non-existing phys and remote rphys.
1710 */ 2105 */
1711 if (!phy_info) 2106 if (!phy_info || !phy_info->port_details) {
2107 dfailprintk((MYIOC_s_ERR_FMT
2108 "%s: exit at line=%d\n", ioc->name,
2109 __FUNCTION__, __LINE__));
1712 break; 2110 break;
1713 if (!phy_info->rphy) 2111 }
2112 rphy = mptsas_get_rphy(phy_info);
2113 if (!rphy) {
2114 dfailprintk((MYIOC_s_ERR_FMT
2115 "%s: exit at line=%d\n", ioc->name,
2116 __FUNCTION__, __LINE__));
2117 break;
2118 }
2119 port = mptsas_get_port(phy_info);
2120 if (!port) {
2121 dfailprintk((MYIOC_s_ERR_FMT
2122 "%s: exit at line=%d\n", ioc->name,
2123 __FUNCTION__, __LINE__));
1714 break; 2124 break;
1715 if (phy_info->starget) { 2125 }
1716 vtarget = phy_info->starget->hostdata; 2126
2127 starget = mptsas_get_starget(phy_info);
2128 if (starget) {
2129 vtarget = starget->hostdata;
1717 2130
1718 if (!vtarget) 2131 if (!vtarget) {
2132 dfailprintk((MYIOC_s_ERR_FMT
2133 "%s: exit at line=%d\n", ioc->name,
2134 __FUNCTION__, __LINE__));
1719 break; 2135 break;
2136 }
2137
1720 /* 2138 /*
1721 * Handling RAID components 2139 * Handling RAID components
1722 */ 2140 */
1723 if (ev->phys_disk_num_valid) { 2141 if (ev->phys_disk_num_valid) {
1724 vtarget->target_id = ev->phys_disk_num; 2142 vtarget->target_id = ev->phys_disk_num;
1725 vtarget->tflags |= MPT_TARGET_FLAGS_RAID_COMPONENT; 2143 vtarget->tflags |= MPT_TARGET_FLAGS_RAID_COMPONENT;
1726 mptsas_reprobe_target(vtarget->starget, 1); 2144 mptsas_reprobe_target(starget, 1);
1727 break; 2145 break;
1728 } 2146 }
2147
2148 vtarget->deleted = 1;
2149 mptsas_target_reset(ioc, vtarget);
1729 } 2150 }
1730 2151
1731 if (phy_info->attached.device_info & MPI_SAS_DEVICE_INFO_SSP_TARGET) 2152 if (phy_info->attached.device_info & MPI_SAS_DEVICE_INFO_SSP_TARGET)
@@ -1739,10 +2160,11 @@ mptsas_hotplug_work(void *arg)
1739 "removing %s device, channel %d, id %d, phy %d\n", 2160 "removing %s device, channel %d, id %d, phy %d\n",
1740 ioc->name, ds, ev->channel, ev->id, phy_info->phy_id); 2161 ioc->name, ds, ev->channel, ev->id, phy_info->phy_id);
1741 2162
1742 sas_rphy_delete(phy_info->rphy); 2163#ifdef MPT_DEBUG_SAS_WIDE
1743 memset(&phy_info->attached, 0, sizeof(struct mptsas_devinfo)); 2164 dev_printk(KERN_DEBUG, &port->dev, "delete\n");
1744 phy_info->rphy = NULL; 2165#endif
1745 phy_info->starget = NULL; 2166 sas_port_delete(port);
2167 mptsas_port_delete(phy_info->port_details);
1746 break; 2168 break;
1747 case MPTSAS_ADD_DEVICE: 2169 case MPTSAS_ADD_DEVICE:
1748 2170
@@ -1754,59 +2176,60 @@ mptsas_hotplug_work(void *arg)
1754 */ 2176 */
1755 if (mptsas_sas_device_pg0(ioc, &sas_device, 2177 if (mptsas_sas_device_pg0(ioc, &sas_device,
1756 (MPI_SAS_DEVICE_PGAD_FORM_BUS_TARGET_ID << 2178 (MPI_SAS_DEVICE_PGAD_FORM_BUS_TARGET_ID <<
1757 MPI_SAS_DEVICE_PGAD_FORM_SHIFT), ev->id)) 2179 MPI_SAS_DEVICE_PGAD_FORM_SHIFT), ev->id)) {
2180 dfailprintk((MYIOC_s_ERR_FMT
2181 "%s: exit at line=%d\n", ioc->name,
2182 __FUNCTION__, __LINE__));
1758 break; 2183 break;
2184 }
1759 2185
1760 phy_info = mptsas_find_phyinfo_by_parent(ioc, 2186 ssleep(2);
1761 sas_device.handle_parent, sas_device.phy_id); 2187 __mptsas_discovery_work(ioc);
1762 2188
1763 if (!phy_info) { 2189 phy_info = mptsas_find_phyinfo_by_sas_address(ioc,
1764 u32 handle = 0xFFFF; 2190 sas_device.sas_address);
1765 2191
1766 /* 2192 if (!phy_info || !phy_info->port_details) {
1767 * Its possible when an expander has been hot added 2193 dfailprintk((MYIOC_s_ERR_FMT
1768 * containing attached devices, the sas firmware 2194 "%s: exit at line=%d\n", ioc->name,
1769 * may send a RC_ADDED event prior to the 2195 __FUNCTION__, __LINE__));
1770 * DISCOVERY STOP event. If that occurs, our 2196 break;
1771 * view of the topology in the driver in respect to this
1772 * expander might of not been setup, and we hit this
1773 * condition.
1774 * Therefore, this code kicks off discovery to
1775 * refresh the data.
1776 * Then again, we check whether the parent phy has
1777 * been created.
1778 */
1779 ioc->sas_discovery_runtime=1;
1780 mptsas_delete_expander_phys(ioc);
1781 mptsas_probe_hba_phys(ioc);
1782 while (!mptsas_probe_expander_phys(ioc, &handle))
1783 ;
1784 ioc->sas_discovery_runtime=0;
1785
1786 phy_info = mptsas_find_phyinfo_by_parent(ioc,
1787 sas_device.handle_parent, sas_device.phy_id);
1788 if (!phy_info)
1789 break;
1790 } 2197 }
1791 2198
1792 if (phy_info->starget) { 2199 starget = mptsas_get_starget(phy_info);
1793 vtarget = phy_info->starget->hostdata; 2200 if (starget) {
2201 vtarget = starget->hostdata;
1794 2202
1795 if (!vtarget) 2203 if (!vtarget) {
2204 dfailprintk((MYIOC_s_ERR_FMT
2205 "%s: exit at line=%d\n", ioc->name,
2206 __FUNCTION__, __LINE__));
1796 break; 2207 break;
2208 }
1797 /* 2209 /*
1798 * Handling RAID components 2210 * Handling RAID components
1799 */ 2211 */
1800 if (vtarget->tflags & MPT_TARGET_FLAGS_RAID_COMPONENT) { 2212 if (vtarget->tflags & MPT_TARGET_FLAGS_RAID_COMPONENT) {
1801 vtarget->tflags &= ~MPT_TARGET_FLAGS_RAID_COMPONENT; 2213 vtarget->tflags &= ~MPT_TARGET_FLAGS_RAID_COMPONENT;
1802 vtarget->target_id = ev->id; 2214 vtarget->target_id = ev->id;
1803 mptsas_reprobe_target(phy_info->starget, 0); 2215 mptsas_reprobe_target(starget, 0);
1804 } 2216 }
1805 break; 2217 break;
1806 } 2218 }
1807 2219
1808 if (phy_info->rphy) 2220 if (mptsas_get_rphy(phy_info)) {
2221 dfailprintk((MYIOC_s_ERR_FMT
2222 "%s: exit at line=%d\n", ioc->name,
2223 __FUNCTION__, __LINE__));
1809 break; 2224 break;
2225 }
2226 port = mptsas_get_port(phy_info);
2227 if (!port) {
2228 dfailprintk((MYIOC_s_ERR_FMT
2229 "%s: exit at line=%d\n", ioc->name,
2230 __FUNCTION__, __LINE__));
2231 break;
2232 }
1810 2233
1811 memcpy(&phy_info->attached, &sas_device, 2234 memcpy(&phy_info->attached, &sas_device,
1812 sizeof(struct mptsas_devinfo)); 2235 sizeof(struct mptsas_devinfo));
@@ -1823,28 +2246,23 @@ mptsas_hotplug_work(void *arg)
1823 ioc->name, ds, ev->channel, ev->id, ev->phy_id); 2246 ioc->name, ds, ev->channel, ev->id, ev->phy_id);
1824 2247
1825 mptsas_parse_device_info(&identify, &phy_info->attached); 2248 mptsas_parse_device_info(&identify, &phy_info->attached);
1826 switch (identify.device_type) { 2249 rphy = sas_end_device_alloc(port);
1827 case SAS_END_DEVICE: 2250 if (!rphy) {
1828 rphy = sas_end_device_alloc(phy_info->phy); 2251 dfailprintk((MYIOC_s_ERR_FMT
1829 break; 2252 "%s: exit at line=%d\n", ioc->name,
1830 case SAS_EDGE_EXPANDER_DEVICE: 2253 __FUNCTION__, __LINE__));
1831 case SAS_FANOUT_EXPANDER_DEVICE:
1832 rphy = sas_expander_alloc(phy_info->phy, identify.device_type);
1833 break;
1834 default:
1835 rphy = NULL;
1836 break;
1837 }
1838 if (!rphy)
1839 break; /* non-fatal: an rphy can be added later */ 2254 break; /* non-fatal: an rphy can be added later */
2255 }
1840 2256
1841 rphy->identify = identify; 2257 rphy->identify = identify;
1842 if (sas_rphy_add(rphy)) { 2258 if (sas_rphy_add(rphy)) {
2259 dfailprintk((MYIOC_s_ERR_FMT
2260 "%s: exit at line=%d\n", ioc->name,
2261 __FUNCTION__, __LINE__));
1843 sas_rphy_free(rphy); 2262 sas_rphy_free(rphy);
1844 break; 2263 break;
1845 } 2264 }
1846 2265 mptsas_set_rphy(phy_info, rphy);
1847 phy_info->rphy = rphy;
1848 break; 2266 break;
1849 case MPTSAS_ADD_RAID: 2267 case MPTSAS_ADD_RAID:
1850 sdev = scsi_device_lookup( 2268 sdev = scsi_device_lookup(
@@ -1876,6 +2294,9 @@ mptsas_hotplug_work(void *arg)
1876 printk(MYIOC_s_INFO_FMT 2294 printk(MYIOC_s_INFO_FMT
1877 "removing raid volume, channel %d, id %d\n", 2295 "removing raid volume, channel %d, id %d\n",
1878 ioc->name, ioc->num_ports, ev->id); 2296 ioc->name, ioc->num_ports, ev->id);
2297 vdevice = sdev->hostdata;
2298 vdevice->vtarget->deleted = 1;
2299 mptsas_target_reset(ioc, vdevice->vtarget);
1879 scsi_remove_device(sdev); 2300 scsi_remove_device(sdev);
1880 scsi_device_put(sdev); 2301 scsi_device_put(sdev);
1881 mpt_findImVolumes(ioc); 2302 mpt_findImVolumes(ioc);
@@ -1885,12 +2306,13 @@ mptsas_hotplug_work(void *arg)
1885 break; 2306 break;
1886 } 2307 }
1887 2308
1888 kfree(ev);
1889 mutex_unlock(&ioc->sas_discovery_mutex); 2309 mutex_unlock(&ioc->sas_discovery_mutex);
2310 kfree(ev);
2311
1890} 2312}
1891 2313
1892static void 2314static void
1893mptscsih_send_sas_event(MPT_ADAPTER *ioc, 2315mptsas_send_sas_event(MPT_ADAPTER *ioc,
1894 EVENT_DATA_SAS_DEVICE_STATUS_CHANGE *sas_event_data) 2316 EVENT_DATA_SAS_DEVICE_STATUS_CHANGE *sas_event_data)
1895{ 2317{
1896 struct mptsas_hotplug_event *ev; 2318 struct mptsas_hotplug_event *ev;
@@ -1906,7 +2328,7 @@ mptscsih_send_sas_event(MPT_ADAPTER *ioc,
1906 switch (sas_event_data->ReasonCode) { 2328 switch (sas_event_data->ReasonCode) {
1907 case MPI_EVENT_SAS_DEV_STAT_RC_ADDED: 2329 case MPI_EVENT_SAS_DEV_STAT_RC_ADDED:
1908 case MPI_EVENT_SAS_DEV_STAT_RC_NOT_RESPONDING: 2330 case MPI_EVENT_SAS_DEV_STAT_RC_NOT_RESPONDING:
1909 ev = kmalloc(sizeof(*ev), GFP_ATOMIC); 2331 ev = kzalloc(sizeof(*ev), GFP_ATOMIC);
1910 if (!ev) { 2332 if (!ev) {
1911 printk(KERN_WARNING "mptsas: lost hotplug event\n"); 2333 printk(KERN_WARNING "mptsas: lost hotplug event\n");
1912 break; 2334 break;
@@ -1936,10 +2358,9 @@ mptscsih_send_sas_event(MPT_ADAPTER *ioc,
1936 /* 2358 /*
1937 * Persistent table is full. 2359 * Persistent table is full.
1938 */ 2360 */
1939 INIT_WORK(&ioc->mptscsih_persistTask, 2361 INIT_WORK(&ioc->sas_persist_task,
1940 mptscsih_sas_persist_clear_table, 2362 mptsas_persist_clear_table, (void *)ioc);
1941 (void *)ioc); 2363 schedule_work(&ioc->sas_persist_task);
1942 schedule_work(&ioc->mptscsih_persistTask);
1943 break; 2364 break;
1944 case MPI_EVENT_SAS_DEV_STAT_RC_SMART_DATA: 2365 case MPI_EVENT_SAS_DEV_STAT_RC_SMART_DATA:
1945 /* TODO */ 2366 /* TODO */
@@ -1951,7 +2372,7 @@ mptscsih_send_sas_event(MPT_ADAPTER *ioc,
1951} 2372}
1952 2373
1953static void 2374static void
1954mptscsih_send_raid_event(MPT_ADAPTER *ioc, 2375mptsas_send_raid_event(MPT_ADAPTER *ioc,
1955 EVENT_DATA_RAID *raid_event_data) 2376 EVENT_DATA_RAID *raid_event_data)
1956{ 2377{
1957 struct mptsas_hotplug_event *ev; 2378 struct mptsas_hotplug_event *ev;
@@ -1961,13 +2382,12 @@ mptscsih_send_raid_event(MPT_ADAPTER *ioc,
1961 if (ioc->bus_type != SAS) 2382 if (ioc->bus_type != SAS)
1962 return; 2383 return;
1963 2384
1964 ev = kmalloc(sizeof(*ev), GFP_ATOMIC); 2385 ev = kzalloc(sizeof(*ev), GFP_ATOMIC);
1965 if (!ev) { 2386 if (!ev) {
1966 printk(KERN_WARNING "mptsas: lost hotplug event\n"); 2387 printk(KERN_WARNING "mptsas: lost hotplug event\n");
1967 return; 2388 return;
1968 } 2389 }
1969 2390
1970 memset(ev,0,sizeof(struct mptsas_hotplug_event));
1971 INIT_WORK(&ev->work, mptsas_hotplug_work, ev); 2391 INIT_WORK(&ev->work, mptsas_hotplug_work, ev);
1972 ev->ioc = ioc; 2392 ev->ioc = ioc;
1973 ev->id = raid_event_data->VolumeID; 2393 ev->id = raid_event_data->VolumeID;
@@ -2029,7 +2449,7 @@ mptscsih_send_raid_event(MPT_ADAPTER *ioc,
2029} 2449}
2030 2450
2031static void 2451static void
2032mptscsih_send_discovery(MPT_ADAPTER *ioc, 2452mptsas_send_discovery_event(MPT_ADAPTER *ioc,
2033 EVENT_DATA_SAS_DISCOVERY *discovery_data) 2453 EVENT_DATA_SAS_DISCOVERY *discovery_data)
2034{ 2454{
2035 struct mptsas_discovery_event *ev; 2455 struct mptsas_discovery_event *ev;
@@ -2044,11 +2464,10 @@ mptscsih_send_discovery(MPT_ADAPTER *ioc,
2044 if (discovery_data->DiscoveryStatus) 2464 if (discovery_data->DiscoveryStatus)
2045 return; 2465 return;
2046 2466
2047 ev = kmalloc(sizeof(*ev), GFP_ATOMIC); 2467 ev = kzalloc(sizeof(*ev), GFP_ATOMIC);
2048 if (!ev) 2468 if (!ev)
2049 return; 2469 return;
2050 memset(ev,0,sizeof(struct mptsas_discovery_event)); 2470 INIT_WORK(&ev->work, mptsas_discovery_work, ev);
2051 INIT_WORK(&ev->work, mptscsih_discovery_work, ev);
2052 ev->ioc = ioc; 2471 ev->ioc = ioc;
2053 schedule_work(&ev->work); 2472 schedule_work(&ev->work);
2054}; 2473};
@@ -2076,21 +2495,21 @@ mptsas_event_process(MPT_ADAPTER *ioc, EventNotificationReply_t *reply)
2076 2495
2077 switch (event) { 2496 switch (event) {
2078 case MPI_EVENT_SAS_DEVICE_STATUS_CHANGE: 2497 case MPI_EVENT_SAS_DEVICE_STATUS_CHANGE:
2079 mptscsih_send_sas_event(ioc, 2498 mptsas_send_sas_event(ioc,
2080 (EVENT_DATA_SAS_DEVICE_STATUS_CHANGE *)reply->Data); 2499 (EVENT_DATA_SAS_DEVICE_STATUS_CHANGE *)reply->Data);
2081 break; 2500 break;
2082 case MPI_EVENT_INTEGRATED_RAID: 2501 case MPI_EVENT_INTEGRATED_RAID:
2083 mptscsih_send_raid_event(ioc, 2502 mptsas_send_raid_event(ioc,
2084 (EVENT_DATA_RAID *)reply->Data); 2503 (EVENT_DATA_RAID *)reply->Data);
2085 break; 2504 break;
2086 case MPI_EVENT_PERSISTENT_TABLE_FULL: 2505 case MPI_EVENT_PERSISTENT_TABLE_FULL:
2087 INIT_WORK(&ioc->mptscsih_persistTask, 2506 INIT_WORK(&ioc->sas_persist_task,
2088 mptscsih_sas_persist_clear_table, 2507 mptsas_persist_clear_table,
2089 (void *)ioc); 2508 (void *)ioc);
2090 schedule_work(&ioc->mptscsih_persistTask); 2509 schedule_work(&ioc->sas_persist_task);
2091 break; 2510 break;
2092 case MPI_EVENT_SAS_DISCOVERY: 2511 case MPI_EVENT_SAS_DISCOVERY:
2093 mptscsih_send_discovery(ioc, 2512 mptsas_send_discovery_event(ioc,
2094 (EVENT_DATA_SAS_DISCOVERY *)reply->Data); 2513 (EVENT_DATA_SAS_DISCOVERY *)reply->Data);
2095 break; 2514 break;
2096 default: 2515 default:
@@ -2309,7 +2728,7 @@ mptsas_probe(struct pci_dev *pdev, const struct pci_device_id *id)
2309 2728
2310 return 0; 2729 return 0;
2311 2730
2312out_mptsas_probe: 2731 out_mptsas_probe:
2313 2732
2314 mptscsih_remove(pdev); 2733 mptscsih_remove(pdev);
2315 return error; 2734 return error;
@@ -2319,6 +2738,7 @@ static void __devexit mptsas_remove(struct pci_dev *pdev)
2319{ 2738{
2320 MPT_ADAPTER *ioc = pci_get_drvdata(pdev); 2739 MPT_ADAPTER *ioc = pci_get_drvdata(pdev);
2321 struct mptsas_portinfo *p, *n; 2740 struct mptsas_portinfo *p, *n;
2741 int i;
2322 2742
2323 ioc->sas_discovery_ignore_events=1; 2743 ioc->sas_discovery_ignore_events=1;
2324 sas_remove_host(ioc->sh); 2744 sas_remove_host(ioc->sh);
@@ -2326,8 +2746,9 @@ static void __devexit mptsas_remove(struct pci_dev *pdev)
2326 mutex_lock(&ioc->sas_topology_mutex); 2746 mutex_lock(&ioc->sas_topology_mutex);
2327 list_for_each_entry_safe(p, n, &ioc->sas_topology, list) { 2747 list_for_each_entry_safe(p, n, &ioc->sas_topology, list) {
2328 list_del(&p->list); 2748 list_del(&p->list);
2329 if (p->phy_info) 2749 for (i = 0 ; i < p->num_phys ; i++)
2330 kfree(p->phy_info); 2750 mptsas_port_delete(p->phy_info[i].port_details);
2751 kfree(p->phy_info);
2331 kfree(p); 2752 kfree(p);
2332 } 2753 }
2333 mutex_unlock(&ioc->sas_topology_mutex); 2754 mutex_unlock(&ioc->sas_topology_mutex);