aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/message/fusion/mptsas.c
diff options
context:
space:
mode:
authorJames Bottomley <jejb@mulgrave.il.steeleye.com>2006-07-03 10:41:12 -0400
committerJames Bottomley <jejb@mulgrave.il.steeleye.com>2006-07-03 10:41:12 -0400
commitc4e00fac42f268ed0a547cdd1d12bb8399864040 (patch)
tree1a54d87be2066c49b71a03764fcb4fc7f9c68c41 /drivers/message/fusion/mptsas.c
parent29454dde27d8e340bb1987bad9aa504af7081eba (diff)
parentd6b0c53723753fc0cfda63f56735b225c43e1e9a (diff)
Merge ../scsi-misc-2.6
Conflicts: drivers/scsi/nsp32.c drivers/scsi/pcmcia/nsp_cs.c Removal of randomness flag conflicts with SA_ -> IRQF_ global replacement. Signed-off-by: James Bottomley <James.Bottomley@SteelEye.com>
Diffstat (limited to 'drivers/message/fusion/mptsas.c')
-rw-r--r--drivers/message/fusion/mptsas.c996
1 files changed, 720 insertions, 276 deletions
diff --git a/drivers/message/fusion/mptsas.c b/drivers/message/fusion/mptsas.c
index 85689ab46cbc..f7bd8b11ed3b 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 */
340static void
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 */
441static void
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,52 @@ 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;
1638 struct device *parent;
1277 struct sas_identify identify; 1639 struct sas_identify identify;
1278 1640
1279 ioc = phy_to_ioc(phy_info->phy); 1641 parent = dev->parent->parent;
1280
1281 /* 1642 /*
1282 * Let the hotplug_work thread handle processing 1643 * Let the hotplug_work thread handle processing
1283 * the adding/removing of devices that occur 1644 * the adding/removing of devices that occur
@@ -1285,36 +1646,63 @@ static int mptsas_probe_one_phy(struct device *dev,
1285 */ 1646 */
1286 if (ioc->sas_discovery_runtime && 1647 if (ioc->sas_discovery_runtime &&
1287 mptsas_is_end_device(&phy_info->attached)) 1648 mptsas_is_end_device(&phy_info->attached))
1288 return 0; 1649 goto out;
1289 1650
1290 mptsas_parse_device_info(&identify, &phy_info->attached); 1651 mptsas_parse_device_info(&identify, &phy_info->attached);
1652 if (scsi_is_host_device(parent)) {
1653 struct mptsas_portinfo *port_info;
1654 int i;
1655
1656 mutex_lock(&ioc->sas_topology_mutex);
1657 port_info = mptsas_find_portinfo_by_handle(ioc,
1658 ioc->handle);
1659 mutex_unlock(&ioc->sas_topology_mutex);
1660
1661 for (i = 0; i < port_info->num_phys; i++)
1662 if (port_info->phy_info[i].identify.sas_address ==
1663 identify.sas_address)
1664 goto out;
1665
1666 } else if (scsi_is_sas_rphy(parent)) {
1667 struct sas_rphy *parent_rphy = dev_to_rphy(parent);
1668 if (identify.sas_address ==
1669 parent_rphy->identify.sas_address)
1670 goto out;
1671 }
1672
1291 switch (identify.device_type) { 1673 switch (identify.device_type) {
1292 case SAS_END_DEVICE: 1674 case SAS_END_DEVICE:
1293 rphy = sas_end_device_alloc(phy); 1675 rphy = sas_end_device_alloc(port);
1294 break; 1676 break;
1295 case SAS_EDGE_EXPANDER_DEVICE: 1677 case SAS_EDGE_EXPANDER_DEVICE:
1296 case SAS_FANOUT_EXPANDER_DEVICE: 1678 case SAS_FANOUT_EXPANDER_DEVICE:
1297 rphy = sas_expander_alloc(phy, identify.device_type); 1679 rphy = sas_expander_alloc(port, identify.device_type);
1298 break; 1680 break;
1299 default: 1681 default:
1300 rphy = NULL; 1682 rphy = NULL;
1301 break; 1683 break;
1302 } 1684 }
1303 if (!rphy) 1685 if (!rphy) {
1304 return 0; /* non-fatal: an rphy can be added later */ 1686 dfailprintk((MYIOC_s_ERR_FMT
1687 "%s: exit at line=%d\n", ioc->name,
1688 __FUNCTION__, __LINE__));
1689 goto out;
1690 }
1305 1691
1306 rphy->identify = identify; 1692 rphy->identify = identify;
1307
1308 error = sas_rphy_add(rphy); 1693 error = sas_rphy_add(rphy);
1309 if (error) { 1694 if (error) {
1695 dfailprintk((MYIOC_s_ERR_FMT
1696 "%s: exit at line=%d\n", ioc->name,
1697 __FUNCTION__, __LINE__));
1310 sas_rphy_free(rphy); 1698 sas_rphy_free(rphy);
1311 return error; 1699 goto out;
1312 } 1700 }
1313 1701 mptsas_set_rphy(phy_info, rphy);
1314 phy_info->rphy = rphy;
1315 } 1702 }
1316 1703
1317 return 0; 1704 out:
1705 return error;
1318} 1706}
1319 1707
1320static int 1708static int
@@ -1333,6 +1721,7 @@ mptsas_probe_hba_phys(MPT_ADAPTER *ioc)
1333 goto out_free_port_info; 1721 goto out_free_port_info;
1334 1722
1335 mutex_lock(&ioc->sas_topology_mutex); 1723 mutex_lock(&ioc->sas_topology_mutex);
1724 ioc->handle = hba->handle;
1336 port_info = mptsas_find_portinfo_by_handle(ioc, hba->handle); 1725 port_info = mptsas_find_portinfo_by_handle(ioc, hba->handle);
1337 if (!port_info) { 1726 if (!port_info) {
1338 port_info = hba; 1727 port_info = hba;
@@ -1342,8 +1731,7 @@ mptsas_probe_hba_phys(MPT_ADAPTER *ioc)
1342 for (i = 0; i < hba->num_phys; i++) 1731 for (i = 0; i < hba->num_phys; i++)
1343 port_info->phy_info[i].negotiated_link_rate = 1732 port_info->phy_info[i].negotiated_link_rate =
1344 hba->phy_info[i].negotiated_link_rate; 1733 hba->phy_info[i].negotiated_link_rate;
1345 if (hba->phy_info) 1734 kfree(hba->phy_info);
1346 kfree(hba->phy_info);
1347 kfree(hba); 1735 kfree(hba);
1348 hba = NULL; 1736 hba = NULL;
1349 } 1737 }
@@ -1362,18 +1750,19 @@ mptsas_probe_hba_phys(MPT_ADAPTER *ioc)
1362 port_info->phy_info[i].phy_id; 1750 port_info->phy_info[i].phy_id;
1363 handle = port_info->phy_info[i].identify.handle; 1751 handle = port_info->phy_info[i].identify.handle;
1364 1752
1365 if (port_info->phy_info[i].attached.handle) { 1753 if (port_info->phy_info[i].attached.handle)
1366 mptsas_sas_device_pg0(ioc, 1754 mptsas_sas_device_pg0(ioc,
1367 &port_info->phy_info[i].attached, 1755 &port_info->phy_info[i].attached,
1368 (MPI_SAS_DEVICE_PGAD_FORM_HANDLE << 1756 (MPI_SAS_DEVICE_PGAD_FORM_HANDLE <<
1369 MPI_SAS_DEVICE_PGAD_FORM_SHIFT), 1757 MPI_SAS_DEVICE_PGAD_FORM_SHIFT),
1370 port_info->phy_info[i].attached.handle); 1758 port_info->phy_info[i].attached.handle);
1371 } 1759 }
1760
1761 mptsas_setup_wide_ports(ioc, port_info);
1372 1762
1763 for (i = 0; i < port_info->num_phys; i++, ioc->sas_index++)
1373 mptsas_probe_one_phy(&ioc->sh->shost_gendev, 1764 mptsas_probe_one_phy(&ioc->sh->shost_gendev,
1374 &port_info->phy_info[i], ioc->sas_index, 1); 1765 &port_info->phy_info[i], ioc->sas_index, 1);
1375 ioc->sas_index++;
1376 }
1377 1766
1378 return 0; 1767 return 0;
1379 1768
@@ -1387,6 +1776,8 @@ static int
1387mptsas_probe_expander_phys(MPT_ADAPTER *ioc, u32 *handle) 1776mptsas_probe_expander_phys(MPT_ADAPTER *ioc, u32 *handle)
1388{ 1777{
1389 struct mptsas_portinfo *port_info, *p, *ex; 1778 struct mptsas_portinfo *port_info, *p, *ex;
1779 struct device *parent;
1780 struct sas_rphy *rphy;
1390 int error = -ENOMEM, i, j; 1781 int error = -ENOMEM, i, j;
1391 1782
1392 ex = kzalloc(sizeof(*port_info), GFP_KERNEL); 1783 ex = kzalloc(sizeof(*port_info), GFP_KERNEL);
@@ -1408,16 +1799,13 @@ mptsas_probe_expander_phys(MPT_ADAPTER *ioc, u32 *handle)
1408 list_add_tail(&port_info->list, &ioc->sas_topology); 1799 list_add_tail(&port_info->list, &ioc->sas_topology);
1409 } else { 1800 } else {
1410 port_info->handle = ex->handle; 1801 port_info->handle = ex->handle;
1411 if (ex->phy_info) 1802 kfree(ex->phy_info);
1412 kfree(ex->phy_info);
1413 kfree(ex); 1803 kfree(ex);
1414 ex = NULL; 1804 ex = NULL;
1415 } 1805 }
1416 mutex_unlock(&ioc->sas_topology_mutex); 1806 mutex_unlock(&ioc->sas_topology_mutex);
1417 1807
1418 for (i = 0; i < port_info->num_phys; i++) { 1808 for (i = 0; i < port_info->num_phys; i++) {
1419 struct device *parent;
1420
1421 mptsas_sas_expander_pg1(ioc, &port_info->phy_info[i], 1809 mptsas_sas_expander_pg1(ioc, &port_info->phy_info[i],
1422 (MPI_SAS_EXPAND_PGAD_FORM_HANDLE_PHY_NUM << 1810 (MPI_SAS_EXPAND_PGAD_FORM_HANDLE_PHY_NUM <<
1423 MPI_SAS_EXPAND_PGAD_FORM_SHIFT), (i << 16) + *handle); 1811 MPI_SAS_EXPAND_PGAD_FORM_SHIFT), (i << 16) + *handle);
@@ -1441,34 +1829,34 @@ mptsas_probe_expander_phys(MPT_ADAPTER *ioc, u32 *handle)
1441 port_info->phy_info[i].attached.phy_id = 1829 port_info->phy_info[i].attached.phy_id =
1442 port_info->phy_info[i].phy_id; 1830 port_info->phy_info[i].phy_id;
1443 } 1831 }
1832 }
1444 1833
1445 /* 1834 parent = &ioc->sh->shost_gendev;
1446 * If we find a parent port handle this expander is 1835 for (i = 0; i < port_info->num_phys; i++) {
1447 * attached to another expander, else it hangs of the
1448 * HBA phys.
1449 */
1450 parent = &ioc->sh->shost_gendev;
1451 mutex_lock(&ioc->sas_topology_mutex); 1836 mutex_lock(&ioc->sas_topology_mutex);
1452 list_for_each_entry(p, &ioc->sas_topology, list) { 1837 list_for_each_entry(p, &ioc->sas_topology, list) {
1453 for (j = 0; j < p->num_phys; j++) { 1838 for (j = 0; j < p->num_phys; j++) {
1454 if (port_info->phy_info[i].identify.handle == 1839 if (port_info->phy_info[i].identify.handle !=
1455 p->phy_info[j].attached.handle) 1840 p->phy_info[j].attached.handle)
1456 parent = &p->phy_info[j].rphy->dev; 1841 continue;
1842 rphy = mptsas_get_rphy(&p->phy_info[j]);
1843 parent = &rphy->dev;
1457 } 1844 }
1458 } 1845 }
1459 mutex_unlock(&ioc->sas_topology_mutex); 1846 mutex_unlock(&ioc->sas_topology_mutex);
1847 }
1848
1849 mptsas_setup_wide_ports(ioc, port_info);
1460 1850
1851 for (i = 0; i < port_info->num_phys; i++, ioc->sas_index++)
1461 mptsas_probe_one_phy(parent, &port_info->phy_info[i], 1852 mptsas_probe_one_phy(parent, &port_info->phy_info[i],
1462 ioc->sas_index, 0); 1853 ioc->sas_index, 0);
1463 ioc->sas_index++;
1464 }
1465 1854
1466 return 0; 1855 return 0;
1467 1856
1468 out_free_port_info: 1857 out_free_port_info:
1469 if (ex) { 1858 if (ex) {
1470 if (ex->phy_info) 1859 kfree(ex->phy_info);
1471 kfree(ex->phy_info);
1472 kfree(ex); 1860 kfree(ex);
1473 } 1861 }
1474 out: 1862 out:
@@ -1487,7 +1875,12 @@ mptsas_delete_expander_phys(MPT_ADAPTER *ioc)
1487{ 1875{
1488 struct mptsas_portinfo buffer; 1876 struct mptsas_portinfo buffer;
1489 struct mptsas_portinfo *port_info, *n, *parent; 1877 struct mptsas_portinfo *port_info, *n, *parent;
1878 struct mptsas_phyinfo *phy_info;
1879 struct scsi_target * starget;
1880 VirtTarget * vtarget;
1881 struct sas_port * port;
1490 int i; 1882 int i;
1883 u64 expander_sas_address;
1491 1884
1492 mutex_lock(&ioc->sas_topology_mutex); 1885 mutex_lock(&ioc->sas_topology_mutex);
1493 list_for_each_entry_safe(port_info, n, &ioc->sas_topology, list) { 1886 list_for_each_entry_safe(port_info, n, &ioc->sas_topology, list) {
@@ -1502,6 +1895,25 @@ mptsas_delete_expander_phys(MPT_ADAPTER *ioc)
1502 MPI_SAS_EXPAND_PGAD_FORM_SHIFT), port_info->handle)) { 1895 MPI_SAS_EXPAND_PGAD_FORM_SHIFT), port_info->handle)) {
1503 1896
1504 /* 1897 /*
1898 * Issue target reset to all child end devices
1899 * then mark them deleted to prevent further
1900 * IO going to them.
1901 */
1902 phy_info = port_info->phy_info;
1903 for (i = 0; i < port_info->num_phys; i++, phy_info++) {
1904 starget = mptsas_get_starget(phy_info);
1905 if (!starget)
1906 continue;
1907 vtarget = starget->hostdata;
1908 if(vtarget->deleted)
1909 continue;
1910 vtarget->deleted = 1;
1911 mptsas_target_reset(ioc, vtarget);
1912 sas_port_delete(mptsas_get_port(phy_info));
1913 mptsas_port_delete(phy_info->port_details);
1914 }
1915
1916 /*
1505 * Obtain the port_info instance to the parent port 1917 * Obtain the port_info instance to the parent port
1506 */ 1918 */
1507 parent = mptsas_find_portinfo_by_handle(ioc, 1919 parent = mptsas_find_portinfo_by_handle(ioc,
@@ -1510,34 +1922,43 @@ mptsas_delete_expander_phys(MPT_ADAPTER *ioc)
1510 if (!parent) 1922 if (!parent)
1511 goto next_port; 1923 goto next_port;
1512 1924
1925 expander_sas_address =
1926 port_info->phy_info[0].identify.sas_address;
1927
1513 /* 1928 /*
1514 * Delete rphys in the parent that point 1929 * Delete rphys in the parent that point
1515 * to this expander. The transport layer will 1930 * to this expander. The transport layer will
1516 * cleanup all the children. 1931 * cleanup all the children.
1517 */ 1932 */
1518 for (i = 0; i < parent->num_phys; i++) { 1933 phy_info = parent->phy_info;
1519 if ((!parent->phy_info[i].rphy) || 1934 for (i = 0; i < parent->num_phys; i++, phy_info++) {
1520 (parent->phy_info[i].attached.sas_address != 1935 port = mptsas_get_port(phy_info);
1521 port_info->phy_info[i].identify.sas_address)) 1936 if (!port)
1937 continue;
1938 if (phy_info->attached.sas_address !=
1939 expander_sas_address)
1522 continue; 1940 continue;
1523 sas_rphy_delete(parent->phy_info[i].rphy); 1941#ifdef MPT_DEBUG_SAS_WIDE
1524 memset(&parent->phy_info[i].attached, 0, 1942 dev_printk(KERN_DEBUG, &port->dev, "delete\n");
1525 sizeof(struct mptsas_devinfo)); 1943#endif
1526 parent->phy_info[i].rphy = NULL; 1944 sas_port_delete(port);
1527 parent->phy_info[i].starget = NULL; 1945 mptsas_port_delete(phy_info->port_details);
1528 } 1946 }
1529 next_port: 1947 next_port:
1948
1949 phy_info = port_info->phy_info;
1950 for (i = 0; i < port_info->num_phys; i++, phy_info++)
1951 mptsas_port_delete(phy_info->port_details);
1952
1530 list_del(&port_info->list); 1953 list_del(&port_info->list);
1531 if (port_info->phy_info) 1954 kfree(port_info->phy_info);
1532 kfree(port_info->phy_info);
1533 kfree(port_info); 1955 kfree(port_info);
1534 } 1956 }
1535 /* 1957 /*
1536 * Free this memory allocated from inside 1958 * Free this memory allocated from inside
1537 * mptsas_sas_expander_pg0 1959 * mptsas_sas_expander_pg0
1538 */ 1960 */
1539 if (buffer.phy_info) 1961 kfree(buffer.phy_info);
1540 kfree(buffer.phy_info);
1541 } 1962 }
1542 mutex_unlock(&ioc->sas_topology_mutex); 1963 mutex_unlock(&ioc->sas_topology_mutex);
1543} 1964}
@@ -1573,60 +1994,59 @@ mptsas_scan_sas_topology(MPT_ADAPTER *ioc)
1573/* 1994/*
1574 * Work queue thread to handle Runtime discovery 1995 * Work queue thread to handle Runtime discovery
1575 * Mere purpose is the hot add/delete of expanders 1996 * Mere purpose is the hot add/delete of expanders
1997 *(Mutex UNLOCKED)
1576 */ 1998 */
1577static void 1999static void
1578mptscsih_discovery_work(void * arg) 2000__mptsas_discovery_work(MPT_ADAPTER *ioc)
1579{ 2001{
1580 struct mptsas_discovery_event *ev = arg;
1581 MPT_ADAPTER *ioc = ev->ioc;
1582 u32 handle = 0xFFFF; 2002 u32 handle = 0xFFFF;
1583 2003
1584 mutex_lock(&ioc->sas_discovery_mutex);
1585 ioc->sas_discovery_runtime=1; 2004 ioc->sas_discovery_runtime=1;
1586 mptsas_delete_expander_phys(ioc); 2005 mptsas_delete_expander_phys(ioc);
1587 mptsas_probe_hba_phys(ioc); 2006 mptsas_probe_hba_phys(ioc);
1588 while (!mptsas_probe_expander_phys(ioc, &handle)) 2007 while (!mptsas_probe_expander_phys(ioc, &handle))
1589 ; 2008 ;
1590 kfree(ev);
1591 ioc->sas_discovery_runtime=0; 2009 ioc->sas_discovery_runtime=0;
2010}
2011
2012/*
2013 * Work queue thread to handle Runtime discovery
2014 * Mere purpose is the hot add/delete of expanders
2015 *(Mutex LOCKED)
2016 */
2017static void
2018mptsas_discovery_work(void * arg)
2019{
2020 struct mptsas_discovery_event *ev = arg;
2021 MPT_ADAPTER *ioc = ev->ioc;
2022
2023 mutex_lock(&ioc->sas_discovery_mutex);
2024 __mptsas_discovery_work(ioc);
1592 mutex_unlock(&ioc->sas_discovery_mutex); 2025 mutex_unlock(&ioc->sas_discovery_mutex);
2026 kfree(ev);
1593} 2027}
1594 2028
1595static struct mptsas_phyinfo * 2029static struct mptsas_phyinfo *
1596mptsas_find_phyinfo_by_parent(MPT_ADAPTER *ioc, u16 parent_handle, u8 phy_id) 2030mptsas_find_phyinfo_by_sas_address(MPT_ADAPTER *ioc, u64 sas_address)
1597{ 2031{
1598 struct mptsas_portinfo *port_info; 2032 struct mptsas_portinfo *port_info;
1599 struct mptsas_devinfo device_info;
1600 struct mptsas_phyinfo *phy_info = NULL; 2033 struct mptsas_phyinfo *phy_info = NULL;
1601 int i, error; 2034 int i;
1602
1603 /*
1604 * Retrieve the parent sas_address
1605 */
1606 error = mptsas_sas_device_pg0(ioc, &device_info,
1607 (MPI_SAS_DEVICE_PGAD_FORM_HANDLE <<
1608 MPI_SAS_DEVICE_PGAD_FORM_SHIFT),
1609 parent_handle);
1610 if (error)
1611 return NULL;
1612 2035
1613 /*
1614 * The phy_info structures are never deallocated during lifetime of
1615 * a host, so the code below is safe without additional refcounting.
1616 */
1617 mutex_lock(&ioc->sas_topology_mutex); 2036 mutex_lock(&ioc->sas_topology_mutex);
1618 list_for_each_entry(port_info, &ioc->sas_topology, list) { 2037 list_for_each_entry(port_info, &ioc->sas_topology, list) {
1619 for (i = 0; i < port_info->num_phys; i++) { 2038 for (i = 0; i < port_info->num_phys; i++) {
1620 if (port_info->phy_info[i].identify.sas_address == 2039 if (port_info->phy_info[i].attached.sas_address
1621 device_info.sas_address && 2040 != sas_address)
1622 port_info->phy_info[i].phy_id == phy_id) { 2041 continue;
1623 phy_info = &port_info->phy_info[i]; 2042 if (!mptsas_is_end_device(
1624 break; 2043 &port_info->phy_info[i].attached))
1625 } 2044 continue;
2045 phy_info = &port_info->phy_info[i];
2046 break;
1626 } 2047 }
1627 } 2048 }
1628 mutex_unlock(&ioc->sas_topology_mutex); 2049 mutex_unlock(&ioc->sas_topology_mutex);
1629
1630 return phy_info; 2050 return phy_info;
1631} 2051}
1632 2052
@@ -1637,21 +2057,19 @@ mptsas_find_phyinfo_by_target(MPT_ADAPTER *ioc, u32 id)
1637 struct mptsas_phyinfo *phy_info = NULL; 2057 struct mptsas_phyinfo *phy_info = NULL;
1638 int i; 2058 int i;
1639 2059
1640 /*
1641 * The phy_info structures are never deallocated during lifetime of
1642 * a host, so the code below is safe without additional refcounting.
1643 */
1644 mutex_lock(&ioc->sas_topology_mutex); 2060 mutex_lock(&ioc->sas_topology_mutex);
1645 list_for_each_entry(port_info, &ioc->sas_topology, list) { 2061 list_for_each_entry(port_info, &ioc->sas_topology, list) {
1646 for (i = 0; i < port_info->num_phys; i++) 2062 for (i = 0; i < port_info->num_phys; i++) {
1647 if (mptsas_is_end_device(&port_info->phy_info[i].attached)) 2063 if (port_info->phy_info[i].attached.id != id)
1648 if (port_info->phy_info[i].attached.id == id) { 2064 continue;
1649 phy_info = &port_info->phy_info[i]; 2065 if (!mptsas_is_end_device(
1650 break; 2066 &port_info->phy_info[i].attached))
1651 } 2067 continue;
2068 phy_info = &port_info->phy_info[i];
2069 break;
2070 }
1652 } 2071 }
1653 mutex_unlock(&ioc->sas_topology_mutex); 2072 mutex_unlock(&ioc->sas_topology_mutex);
1654
1655 return phy_info; 2073 return phy_info;
1656} 2074}
1657 2075
@@ -1659,7 +2077,7 @@ mptsas_find_phyinfo_by_target(MPT_ADAPTER *ioc, u32 id)
1659 * Work queue thread to clear the persitency table 2077 * Work queue thread to clear the persitency table
1660 */ 2078 */
1661static void 2079static void
1662mptscsih_sas_persist_clear_table(void * arg) 2080mptsas_persist_clear_table(void * arg)
1663{ 2081{
1664 MPT_ADAPTER *ioc = (MPT_ADAPTER *)arg; 2082 MPT_ADAPTER *ioc = (MPT_ADAPTER *)arg;
1665 2083
@@ -1680,7 +2098,6 @@ mptsas_reprobe_target(struct scsi_target *starget, int uld_attach)
1680 mptsas_reprobe_lun); 2098 mptsas_reprobe_lun);
1681} 2099}
1682 2100
1683
1684/* 2101/*
1685 * Work queue thread to handle SAS hotplug events 2102 * Work queue thread to handle SAS hotplug events
1686 */ 2103 */
@@ -1691,14 +2108,17 @@ mptsas_hotplug_work(void *arg)
1691 MPT_ADAPTER *ioc = ev->ioc; 2108 MPT_ADAPTER *ioc = ev->ioc;
1692 struct mptsas_phyinfo *phy_info; 2109 struct mptsas_phyinfo *phy_info;
1693 struct sas_rphy *rphy; 2110 struct sas_rphy *rphy;
2111 struct sas_port *port;
1694 struct scsi_device *sdev; 2112 struct scsi_device *sdev;
2113 struct scsi_target * starget;
1695 struct sas_identify identify; 2114 struct sas_identify identify;
1696 char *ds = NULL; 2115 char *ds = NULL;
1697 struct mptsas_devinfo sas_device; 2116 struct mptsas_devinfo sas_device;
1698 VirtTarget *vtarget; 2117 VirtTarget *vtarget;
2118 VirtDevice *vdevice;
1699 2119
1700 mutex_lock(&ioc->sas_discovery_mutex);
1701 2120
2121 mutex_lock(&ioc->sas_discovery_mutex);
1702 switch (ev->event_type) { 2122 switch (ev->event_type) {
1703 case MPTSAS_DEL_DEVICE: 2123 case MPTSAS_DEL_DEVICE:
1704 2124
@@ -1707,24 +2127,50 @@ mptsas_hotplug_work(void *arg)
1707 /* 2127 /*
1708 * Sanity checks, for non-existing phys and remote rphys. 2128 * Sanity checks, for non-existing phys and remote rphys.
1709 */ 2129 */
1710 if (!phy_info) 2130 if (!phy_info || !phy_info->port_details) {
2131 dfailprintk((MYIOC_s_ERR_FMT
2132 "%s: exit at line=%d\n", ioc->name,
2133 __FUNCTION__, __LINE__));
1711 break; 2134 break;
1712 if (!phy_info->rphy) 2135 }
2136 rphy = mptsas_get_rphy(phy_info);
2137 if (!rphy) {
2138 dfailprintk((MYIOC_s_ERR_FMT
2139 "%s: exit at line=%d\n", ioc->name,
2140 __FUNCTION__, __LINE__));
1713 break; 2141 break;
1714 if (phy_info->starget) { 2142 }
1715 vtarget = phy_info->starget->hostdata; 2143 port = mptsas_get_port(phy_info);
2144 if (!port) {
2145 dfailprintk((MYIOC_s_ERR_FMT
2146 "%s: exit at line=%d\n", ioc->name,
2147 __FUNCTION__, __LINE__));
2148 break;
2149 }
1716 2150
1717 if (!vtarget) 2151 starget = mptsas_get_starget(phy_info);
2152 if (starget) {
2153 vtarget = starget->hostdata;
2154
2155 if (!vtarget) {
2156 dfailprintk((MYIOC_s_ERR_FMT
2157 "%s: exit at line=%d\n", ioc->name,
2158 __FUNCTION__, __LINE__));
1718 break; 2159 break;
2160 }
2161
1719 /* 2162 /*
1720 * Handling RAID components 2163 * Handling RAID components
1721 */ 2164 */
1722 if (ev->phys_disk_num_valid) { 2165 if (ev->phys_disk_num_valid) {
1723 vtarget->target_id = ev->phys_disk_num; 2166 vtarget->target_id = ev->phys_disk_num;
1724 vtarget->tflags |= MPT_TARGET_FLAGS_RAID_COMPONENT; 2167 vtarget->tflags |= MPT_TARGET_FLAGS_RAID_COMPONENT;
1725 mptsas_reprobe_target(vtarget->starget, 1); 2168 mptsas_reprobe_target(starget, 1);
1726 break; 2169 break;
1727 } 2170 }
2171
2172 vtarget->deleted = 1;
2173 mptsas_target_reset(ioc, vtarget);
1728 } 2174 }
1729 2175
1730 if (phy_info->attached.device_info & MPI_SAS_DEVICE_INFO_SSP_TARGET) 2176 if (phy_info->attached.device_info & MPI_SAS_DEVICE_INFO_SSP_TARGET)
@@ -1738,10 +2184,11 @@ mptsas_hotplug_work(void *arg)
1738 "removing %s device, channel %d, id %d, phy %d\n", 2184 "removing %s device, channel %d, id %d, phy %d\n",
1739 ioc->name, ds, ev->channel, ev->id, phy_info->phy_id); 2185 ioc->name, ds, ev->channel, ev->id, phy_info->phy_id);
1740 2186
1741 sas_rphy_delete(phy_info->rphy); 2187#ifdef MPT_DEBUG_SAS_WIDE
1742 memset(&phy_info->attached, 0, sizeof(struct mptsas_devinfo)); 2188 dev_printk(KERN_DEBUG, &port->dev, "delete\n");
1743 phy_info->rphy = NULL; 2189#endif
1744 phy_info->starget = NULL; 2190 sas_port_delete(port);
2191 mptsas_port_delete(phy_info->port_details);
1745 break; 2192 break;
1746 case MPTSAS_ADD_DEVICE: 2193 case MPTSAS_ADD_DEVICE:
1747 2194
@@ -1753,59 +2200,60 @@ mptsas_hotplug_work(void *arg)
1753 */ 2200 */
1754 if (mptsas_sas_device_pg0(ioc, &sas_device, 2201 if (mptsas_sas_device_pg0(ioc, &sas_device,
1755 (MPI_SAS_DEVICE_PGAD_FORM_BUS_TARGET_ID << 2202 (MPI_SAS_DEVICE_PGAD_FORM_BUS_TARGET_ID <<
1756 MPI_SAS_DEVICE_PGAD_FORM_SHIFT), ev->id)) 2203 MPI_SAS_DEVICE_PGAD_FORM_SHIFT), ev->id)) {
2204 dfailprintk((MYIOC_s_ERR_FMT
2205 "%s: exit at line=%d\n", ioc->name,
2206 __FUNCTION__, __LINE__));
1757 break; 2207 break;
2208 }
1758 2209
1759 phy_info = mptsas_find_phyinfo_by_parent(ioc, 2210 ssleep(2);
1760 sas_device.handle_parent, sas_device.phy_id); 2211 __mptsas_discovery_work(ioc);
1761 2212
1762 if (!phy_info) { 2213 phy_info = mptsas_find_phyinfo_by_sas_address(ioc,
1763 u32 handle = 0xFFFF; 2214 sas_device.sas_address);
1764 2215
1765 /* 2216 if (!phy_info || !phy_info->port_details) {
1766 * Its possible when an expander has been hot added 2217 dfailprintk((MYIOC_s_ERR_FMT
1767 * containing attached devices, the sas firmware 2218 "%s: exit at line=%d\n", ioc->name,
1768 * may send a RC_ADDED event prior to the 2219 __FUNCTION__, __LINE__));
1769 * DISCOVERY STOP event. If that occurs, our 2220 break;
1770 * view of the topology in the driver in respect to this
1771 * expander might of not been setup, and we hit this
1772 * condition.
1773 * Therefore, this code kicks off discovery to
1774 * refresh the data.
1775 * Then again, we check whether the parent phy has
1776 * been created.
1777 */
1778 ioc->sas_discovery_runtime=1;
1779 mptsas_delete_expander_phys(ioc);
1780 mptsas_probe_hba_phys(ioc);
1781 while (!mptsas_probe_expander_phys(ioc, &handle))
1782 ;
1783 ioc->sas_discovery_runtime=0;
1784
1785 phy_info = mptsas_find_phyinfo_by_parent(ioc,
1786 sas_device.handle_parent, sas_device.phy_id);
1787 if (!phy_info)
1788 break;
1789 } 2221 }
1790 2222
1791 if (phy_info->starget) { 2223 starget = mptsas_get_starget(phy_info);
1792 vtarget = phy_info->starget->hostdata; 2224 if (starget) {
2225 vtarget = starget->hostdata;
1793 2226
1794 if (!vtarget) 2227 if (!vtarget) {
2228 dfailprintk((MYIOC_s_ERR_FMT
2229 "%s: exit at line=%d\n", ioc->name,
2230 __FUNCTION__, __LINE__));
1795 break; 2231 break;
2232 }
1796 /* 2233 /*
1797 * Handling RAID components 2234 * Handling RAID components
1798 */ 2235 */
1799 if (vtarget->tflags & MPT_TARGET_FLAGS_RAID_COMPONENT) { 2236 if (vtarget->tflags & MPT_TARGET_FLAGS_RAID_COMPONENT) {
1800 vtarget->tflags &= ~MPT_TARGET_FLAGS_RAID_COMPONENT; 2237 vtarget->tflags &= ~MPT_TARGET_FLAGS_RAID_COMPONENT;
1801 vtarget->target_id = ev->id; 2238 vtarget->target_id = ev->id;
1802 mptsas_reprobe_target(phy_info->starget, 0); 2239 mptsas_reprobe_target(starget, 0);
1803 } 2240 }
1804 break; 2241 break;
1805 } 2242 }
1806 2243
1807 if (phy_info->rphy) 2244 if (mptsas_get_rphy(phy_info)) {
2245 dfailprintk((MYIOC_s_ERR_FMT
2246 "%s: exit at line=%d\n", ioc->name,
2247 __FUNCTION__, __LINE__));
1808 break; 2248 break;
2249 }
2250 port = mptsas_get_port(phy_info);
2251 if (!port) {
2252 dfailprintk((MYIOC_s_ERR_FMT
2253 "%s: exit at line=%d\n", ioc->name,
2254 __FUNCTION__, __LINE__));
2255 break;
2256 }
1809 2257
1810 memcpy(&phy_info->attached, &sas_device, 2258 memcpy(&phy_info->attached, &sas_device,
1811 sizeof(struct mptsas_devinfo)); 2259 sizeof(struct mptsas_devinfo));
@@ -1822,28 +2270,23 @@ mptsas_hotplug_work(void *arg)
1822 ioc->name, ds, ev->channel, ev->id, ev->phy_id); 2270 ioc->name, ds, ev->channel, ev->id, ev->phy_id);
1823 2271
1824 mptsas_parse_device_info(&identify, &phy_info->attached); 2272 mptsas_parse_device_info(&identify, &phy_info->attached);
1825 switch (identify.device_type) { 2273 rphy = sas_end_device_alloc(port);
1826 case SAS_END_DEVICE: 2274 if (!rphy) {
1827 rphy = sas_end_device_alloc(phy_info->phy); 2275 dfailprintk((MYIOC_s_ERR_FMT
1828 break; 2276 "%s: exit at line=%d\n", ioc->name,
1829 case SAS_EDGE_EXPANDER_DEVICE: 2277 __FUNCTION__, __LINE__));
1830 case SAS_FANOUT_EXPANDER_DEVICE:
1831 rphy = sas_expander_alloc(phy_info->phy, identify.device_type);
1832 break;
1833 default:
1834 rphy = NULL;
1835 break;
1836 }
1837 if (!rphy)
1838 break; /* non-fatal: an rphy can be added later */ 2278 break; /* non-fatal: an rphy can be added later */
2279 }
1839 2280
1840 rphy->identify = identify; 2281 rphy->identify = identify;
1841 if (sas_rphy_add(rphy)) { 2282 if (sas_rphy_add(rphy)) {
2283 dfailprintk((MYIOC_s_ERR_FMT
2284 "%s: exit at line=%d\n", ioc->name,
2285 __FUNCTION__, __LINE__));
1842 sas_rphy_free(rphy); 2286 sas_rphy_free(rphy);
1843 break; 2287 break;
1844 } 2288 }
1845 2289 mptsas_set_rphy(phy_info, rphy);
1846 phy_info->rphy = rphy;
1847 break; 2290 break;
1848 case MPTSAS_ADD_RAID: 2291 case MPTSAS_ADD_RAID:
1849 sdev = scsi_device_lookup( 2292 sdev = scsi_device_lookup(
@@ -1875,6 +2318,9 @@ mptsas_hotplug_work(void *arg)
1875 printk(MYIOC_s_INFO_FMT 2318 printk(MYIOC_s_INFO_FMT
1876 "removing raid volume, channel %d, id %d\n", 2319 "removing raid volume, channel %d, id %d\n",
1877 ioc->name, ioc->num_ports, ev->id); 2320 ioc->name, ioc->num_ports, ev->id);
2321 vdevice = sdev->hostdata;
2322 vdevice->vtarget->deleted = 1;
2323 mptsas_target_reset(ioc, vdevice->vtarget);
1878 scsi_remove_device(sdev); 2324 scsi_remove_device(sdev);
1879 scsi_device_put(sdev); 2325 scsi_device_put(sdev);
1880 mpt_findImVolumes(ioc); 2326 mpt_findImVolumes(ioc);
@@ -1884,12 +2330,13 @@ mptsas_hotplug_work(void *arg)
1884 break; 2330 break;
1885 } 2331 }
1886 2332
1887 kfree(ev);
1888 mutex_unlock(&ioc->sas_discovery_mutex); 2333 mutex_unlock(&ioc->sas_discovery_mutex);
2334 kfree(ev);
2335
1889} 2336}
1890 2337
1891static void 2338static void
1892mptscsih_send_sas_event(MPT_ADAPTER *ioc, 2339mptsas_send_sas_event(MPT_ADAPTER *ioc,
1893 EVENT_DATA_SAS_DEVICE_STATUS_CHANGE *sas_event_data) 2340 EVENT_DATA_SAS_DEVICE_STATUS_CHANGE *sas_event_data)
1894{ 2341{
1895 struct mptsas_hotplug_event *ev; 2342 struct mptsas_hotplug_event *ev;
@@ -1905,7 +2352,7 @@ mptscsih_send_sas_event(MPT_ADAPTER *ioc,
1905 switch (sas_event_data->ReasonCode) { 2352 switch (sas_event_data->ReasonCode) {
1906 case MPI_EVENT_SAS_DEV_STAT_RC_ADDED: 2353 case MPI_EVENT_SAS_DEV_STAT_RC_ADDED:
1907 case MPI_EVENT_SAS_DEV_STAT_RC_NOT_RESPONDING: 2354 case MPI_EVENT_SAS_DEV_STAT_RC_NOT_RESPONDING:
1908 ev = kmalloc(sizeof(*ev), GFP_ATOMIC); 2355 ev = kzalloc(sizeof(*ev), GFP_ATOMIC);
1909 if (!ev) { 2356 if (!ev) {
1910 printk(KERN_WARNING "mptsas: lost hotplug event\n"); 2357 printk(KERN_WARNING "mptsas: lost hotplug event\n");
1911 break; 2358 break;
@@ -1935,10 +2382,9 @@ mptscsih_send_sas_event(MPT_ADAPTER *ioc,
1935 /* 2382 /*
1936 * Persistent table is full. 2383 * Persistent table is full.
1937 */ 2384 */
1938 INIT_WORK(&ioc->mptscsih_persistTask, 2385 INIT_WORK(&ioc->sas_persist_task,
1939 mptscsih_sas_persist_clear_table, 2386 mptsas_persist_clear_table, (void *)ioc);
1940 (void *)ioc); 2387 schedule_work(&ioc->sas_persist_task);
1941 schedule_work(&ioc->mptscsih_persistTask);
1942 break; 2388 break;
1943 case MPI_EVENT_SAS_DEV_STAT_RC_SMART_DATA: 2389 case MPI_EVENT_SAS_DEV_STAT_RC_SMART_DATA:
1944 /* TODO */ 2390 /* TODO */
@@ -1950,7 +2396,7 @@ mptscsih_send_sas_event(MPT_ADAPTER *ioc,
1950} 2396}
1951 2397
1952static void 2398static void
1953mptscsih_send_raid_event(MPT_ADAPTER *ioc, 2399mptsas_send_raid_event(MPT_ADAPTER *ioc,
1954 EVENT_DATA_RAID *raid_event_data) 2400 EVENT_DATA_RAID *raid_event_data)
1955{ 2401{
1956 struct mptsas_hotplug_event *ev; 2402 struct mptsas_hotplug_event *ev;
@@ -1960,13 +2406,12 @@ mptscsih_send_raid_event(MPT_ADAPTER *ioc,
1960 if (ioc->bus_type != SAS) 2406 if (ioc->bus_type != SAS)
1961 return; 2407 return;
1962 2408
1963 ev = kmalloc(sizeof(*ev), GFP_ATOMIC); 2409 ev = kzalloc(sizeof(*ev), GFP_ATOMIC);
1964 if (!ev) { 2410 if (!ev) {
1965 printk(KERN_WARNING "mptsas: lost hotplug event\n"); 2411 printk(KERN_WARNING "mptsas: lost hotplug event\n");
1966 return; 2412 return;
1967 } 2413 }
1968 2414
1969 memset(ev,0,sizeof(struct mptsas_hotplug_event));
1970 INIT_WORK(&ev->work, mptsas_hotplug_work, ev); 2415 INIT_WORK(&ev->work, mptsas_hotplug_work, ev);
1971 ev->ioc = ioc; 2416 ev->ioc = ioc;
1972 ev->id = raid_event_data->VolumeID; 2417 ev->id = raid_event_data->VolumeID;
@@ -2028,7 +2473,7 @@ mptscsih_send_raid_event(MPT_ADAPTER *ioc,
2028} 2473}
2029 2474
2030static void 2475static void
2031mptscsih_send_discovery(MPT_ADAPTER *ioc, 2476mptsas_send_discovery_event(MPT_ADAPTER *ioc,
2032 EVENT_DATA_SAS_DISCOVERY *discovery_data) 2477 EVENT_DATA_SAS_DISCOVERY *discovery_data)
2033{ 2478{
2034 struct mptsas_discovery_event *ev; 2479 struct mptsas_discovery_event *ev;
@@ -2043,11 +2488,10 @@ mptscsih_send_discovery(MPT_ADAPTER *ioc,
2043 if (discovery_data->DiscoveryStatus) 2488 if (discovery_data->DiscoveryStatus)
2044 return; 2489 return;
2045 2490
2046 ev = kmalloc(sizeof(*ev), GFP_ATOMIC); 2491 ev = kzalloc(sizeof(*ev), GFP_ATOMIC);
2047 if (!ev) 2492 if (!ev)
2048 return; 2493 return;
2049 memset(ev,0,sizeof(struct mptsas_discovery_event)); 2494 INIT_WORK(&ev->work, mptsas_discovery_work, ev);
2050 INIT_WORK(&ev->work, mptscsih_discovery_work, ev);
2051 ev->ioc = ioc; 2495 ev->ioc = ioc;
2052 schedule_work(&ev->work); 2496 schedule_work(&ev->work);
2053}; 2497};
@@ -2075,21 +2519,21 @@ mptsas_event_process(MPT_ADAPTER *ioc, EventNotificationReply_t *reply)
2075 2519
2076 switch (event) { 2520 switch (event) {
2077 case MPI_EVENT_SAS_DEVICE_STATUS_CHANGE: 2521 case MPI_EVENT_SAS_DEVICE_STATUS_CHANGE:
2078 mptscsih_send_sas_event(ioc, 2522 mptsas_send_sas_event(ioc,
2079 (EVENT_DATA_SAS_DEVICE_STATUS_CHANGE *)reply->Data); 2523 (EVENT_DATA_SAS_DEVICE_STATUS_CHANGE *)reply->Data);
2080 break; 2524 break;
2081 case MPI_EVENT_INTEGRATED_RAID: 2525 case MPI_EVENT_INTEGRATED_RAID:
2082 mptscsih_send_raid_event(ioc, 2526 mptsas_send_raid_event(ioc,
2083 (EVENT_DATA_RAID *)reply->Data); 2527 (EVENT_DATA_RAID *)reply->Data);
2084 break; 2528 break;
2085 case MPI_EVENT_PERSISTENT_TABLE_FULL: 2529 case MPI_EVENT_PERSISTENT_TABLE_FULL:
2086 INIT_WORK(&ioc->mptscsih_persistTask, 2530 INIT_WORK(&ioc->sas_persist_task,
2087 mptscsih_sas_persist_clear_table, 2531 mptsas_persist_clear_table,
2088 (void *)ioc); 2532 (void *)ioc);
2089 schedule_work(&ioc->mptscsih_persistTask); 2533 schedule_work(&ioc->sas_persist_task);
2090 break; 2534 break;
2091 case MPI_EVENT_SAS_DISCOVERY: 2535 case MPI_EVENT_SAS_DISCOVERY:
2092 mptscsih_send_discovery(ioc, 2536 mptsas_send_discovery_event(ioc,
2093 (EVENT_DATA_SAS_DISCOVERY *)reply->Data); 2537 (EVENT_DATA_SAS_DISCOVERY *)reply->Data);
2094 break; 2538 break;
2095 default: 2539 default:
@@ -2308,7 +2752,7 @@ mptsas_probe(struct pci_dev *pdev, const struct pci_device_id *id)
2308 2752
2309 return 0; 2753 return 0;
2310 2754
2311out_mptsas_probe: 2755 out_mptsas_probe:
2312 2756
2313 mptscsih_remove(pdev); 2757 mptscsih_remove(pdev);
2314 return error; 2758 return error;
@@ -2318,6 +2762,7 @@ static void __devexit mptsas_remove(struct pci_dev *pdev)
2318{ 2762{
2319 MPT_ADAPTER *ioc = pci_get_drvdata(pdev); 2763 MPT_ADAPTER *ioc = pci_get_drvdata(pdev);
2320 struct mptsas_portinfo *p, *n; 2764 struct mptsas_portinfo *p, *n;
2765 int i;
2321 2766
2322 ioc->sas_discovery_ignore_events=1; 2767 ioc->sas_discovery_ignore_events=1;
2323 sas_remove_host(ioc->sh); 2768 sas_remove_host(ioc->sh);
@@ -2325,8 +2770,9 @@ static void __devexit mptsas_remove(struct pci_dev *pdev)
2325 mutex_lock(&ioc->sas_topology_mutex); 2770 mutex_lock(&ioc->sas_topology_mutex);
2326 list_for_each_entry_safe(p, n, &ioc->sas_topology, list) { 2771 list_for_each_entry_safe(p, n, &ioc->sas_topology, list) {
2327 list_del(&p->list); 2772 list_del(&p->list);
2328 if (p->phy_info) 2773 for (i = 0 ; i < p->num_phys ; i++)
2329 kfree(p->phy_info); 2774 mptsas_port_delete(p->phy_info[i].port_details);
2775 kfree(p->phy_info);
2330 kfree(p); 2776 kfree(p);
2331 } 2777 }
2332 mutex_unlock(&ioc->sas_topology_mutex); 2778 mutex_unlock(&ioc->sas_topology_mutex);
@@ -2335,17 +2781,15 @@ static void __devexit mptsas_remove(struct pci_dev *pdev)
2335} 2781}
2336 2782
2337static struct pci_device_id mptsas_pci_table[] = { 2783static struct pci_device_id mptsas_pci_table[] = {
2338 { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_SAS1064, 2784 { PCI_VENDOR_ID_LSI_LOGIC, MPI_MANUFACTPAGE_DEVID_SAS1064,
2339 PCI_ANY_ID, PCI_ANY_ID },
2340 { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_SAS1066,
2341 PCI_ANY_ID, PCI_ANY_ID }, 2785 PCI_ANY_ID, PCI_ANY_ID },
2342 { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_SAS1068, 2786 { PCI_VENDOR_ID_LSI_LOGIC, MPI_MANUFACTPAGE_DEVID_SAS1068,
2343 PCI_ANY_ID, PCI_ANY_ID }, 2787 PCI_ANY_ID, PCI_ANY_ID },
2344 { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_SAS1064E, 2788 { PCI_VENDOR_ID_LSI_LOGIC, MPI_MANUFACTPAGE_DEVID_SAS1064E,
2345 PCI_ANY_ID, PCI_ANY_ID }, 2789 PCI_ANY_ID, PCI_ANY_ID },
2346 { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_SAS1066E, 2790 { PCI_VENDOR_ID_LSI_LOGIC, MPI_MANUFACTPAGE_DEVID_SAS1068E,
2347 PCI_ANY_ID, PCI_ANY_ID }, 2791 PCI_ANY_ID, PCI_ANY_ID },
2348 { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_SAS1068E, 2792 { PCI_VENDOR_ID_LSI_LOGIC, MPI_MANUFACTPAGE_DEVID_SAS1078,
2349 PCI_ANY_ID, PCI_ANY_ID }, 2793 PCI_ANY_ID, PCI_ANY_ID },
2350 {0} /* Terminating entry */ 2794 {0} /* Terminating entry */
2351}; 2795};