aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/message/fusion/mptsas.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/message/fusion/mptsas.c')
-rw-r--r--drivers/message/fusion/mptsas.c1063
1 files changed, 741 insertions, 322 deletions
diff --git a/drivers/message/fusion/mptsas.c b/drivers/message/fusion/mptsas.c
index af6ec553ff7..b752a479f6d 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"
@@ -64,20 +67,19 @@
64#define my_VERSION MPT_LINUX_VERSION_COMMON 67#define my_VERSION MPT_LINUX_VERSION_COMMON
65#define MYNAM "mptsas" 68#define MYNAM "mptsas"
66 69
70/*
71 * Reserved channel for integrated raid
72 */
73#define MPTSAS_RAID_CHANNEL 1
74
67MODULE_AUTHOR(MODULEAUTHOR); 75MODULE_AUTHOR(MODULEAUTHOR);
68MODULE_DESCRIPTION(my_NAME); 76MODULE_DESCRIPTION(my_NAME);
69MODULE_LICENSE("GPL"); 77MODULE_LICENSE("GPL");
70 78
71static int mpt_pq_filter;
72module_param(mpt_pq_filter, int, 0);
73MODULE_PARM_DESC(mpt_pq_filter,
74 "Enable peripheral qualifier filter: enable=1 "
75 "(default=0)");
76
77static int mpt_pt_clear; 79static int mpt_pt_clear;
78module_param(mpt_pt_clear, int, 0); 80module_param(mpt_pt_clear, int, 0);
79MODULE_PARM_DESC(mpt_pt_clear, 81MODULE_PARM_DESC(mpt_pt_clear,
80 "Clear persistency table: enable=1 " 82 " Clear persistency table: enable=1 "
81 "(default=MPTSCSIH_PT_CLEAR=0)"); 83 "(default=MPTSCSIH_PT_CLEAR=0)");
82 84
83static int mptsasDoneCtx = -1; 85static int mptsasDoneCtx = -1;
@@ -137,23 +139,36 @@ struct mptsas_devinfo {
137 u32 device_info; /* bitfield detailed info about this device */ 139 u32 device_info; /* bitfield detailed info about this device */
138}; 140};
139 141
142/*
143 * Specific details on ports, wide/narrow
144 */
145struct mptsas_portinfo_details{
146 u16 num_phys; /* number of phys belong to this port */
147 u64 phy_bitmask; /* TODO, extend support for 255 phys */
148 struct sas_rphy *rphy; /* transport layer rphy object */
149 struct sas_port *port; /* transport layer port object */
150 struct scsi_target *starget;
151 struct mptsas_portinfo *port_info;
152};
153
140struct mptsas_phyinfo { 154struct mptsas_phyinfo {
141 u8 phy_id; /* phy index */ 155 u8 phy_id; /* phy index */
142 u8 port_id; /* port number this phy is part of */ 156 u8 port_id; /* firmware port identifier */
143 u8 negotiated_link_rate; /* nego'd link rate for this phy */ 157 u8 negotiated_link_rate; /* nego'd link rate for this phy */
144 u8 hw_link_rate; /* hardware max/min phys link rate */ 158 u8 hw_link_rate; /* hardware max/min phys link rate */
145 u8 programmed_link_rate; /* programmed max/min phy link rate */ 159 u8 programmed_link_rate; /* programmed max/min phy link rate */
160 u8 sas_port_add_phy; /* flag to request sas_port_add_phy*/
146 struct mptsas_devinfo identify; /* point to phy device info */ 161 struct mptsas_devinfo identify; /* point to phy device info */
147 struct mptsas_devinfo attached; /* point to attached device info */ 162 struct mptsas_devinfo attached; /* point to attached device info */
148 struct sas_phy *phy; 163 struct sas_phy *phy; /* transport layer phy object */
149 struct sas_rphy *rphy; 164 struct mptsas_portinfo *portinfo;
150 struct scsi_target *starget; 165 struct mptsas_portinfo_details * port_details;
151}; 166};
152 167
153struct mptsas_portinfo { 168struct mptsas_portinfo {
154 struct list_head list; 169 struct list_head list;
155 u16 handle; /* unique id to address this */ 170 u16 handle; /* unique id to address this */
156 u8 num_phys; /* number of phys */ 171 u16 num_phys; /* number of phys */
157 struct mptsas_phyinfo *phy_info; 172 struct mptsas_phyinfo *phy_info;
158}; 173};
159 174
@@ -169,7 +184,7 @@ struct mptsas_enclosure {
169 u8 sep_channel; /* SEP channel logical channel id */ 184 u8 sep_channel; /* SEP channel logical channel id */
170}; 185};
171 186
172#ifdef SASDEBUG 187#ifdef MPT_DEBUG_SAS
173static void mptsas_print_phy_data(MPI_SAS_IO_UNIT0_PHY_DATA *phy_data) 188static void mptsas_print_phy_data(MPI_SAS_IO_UNIT0_PHY_DATA *phy_data)
174{ 189{
175 printk("---- IO UNIT PAGE 0 ------------\n"); 190 printk("---- IO UNIT PAGE 0 ------------\n");
@@ -305,7 +320,7 @@ mptsas_find_portinfo_by_handle(MPT_ADAPTER *ioc, u16 handle)
305static inline int 320static inline int
306mptsas_is_end_device(struct mptsas_devinfo * attached) 321mptsas_is_end_device(struct mptsas_devinfo * attached)
307{ 322{
308 if ((attached->handle) && 323 if ((attached->sas_address) &&
309 (attached->device_info & 324 (attached->device_info &
310 MPI_SAS_DEVICE_INFO_END_DEVICE) && 325 MPI_SAS_DEVICE_INFO_END_DEVICE) &&
311 ((attached->device_info & 326 ((attached->device_info &
@@ -319,6 +334,247 @@ mptsas_is_end_device(struct mptsas_devinfo * attached)
319 return 0; 334 return 0;
320} 335}
321 336
337/* no mutex */
338static void
339mptsas_port_delete(struct mptsas_portinfo_details * port_details)
340{
341 struct mptsas_portinfo *port_info;
342 struct mptsas_phyinfo *phy_info;
343 u8 i;
344
345 if (!port_details)
346 return;
347
348 port_info = port_details->port_info;
349 phy_info = port_info->phy_info;
350
351 dsaswideprintk((KERN_DEBUG "%s: [%p]: num_phys=%02d "
352 "bitmask=0x%016llX\n",
353 __FUNCTION__, port_details, port_details->num_phys,
354 port_details->phy_bitmask));
355
356 for (i = 0; i < port_info->num_phys; i++, phy_info++) {
357 if(phy_info->port_details != port_details)
358 continue;
359 memset(&phy_info->attached, 0, sizeof(struct mptsas_devinfo));
360 phy_info->port_details = NULL;
361 }
362 kfree(port_details);
363}
364
365static inline struct sas_rphy *
366mptsas_get_rphy(struct mptsas_phyinfo *phy_info)
367{
368 if (phy_info->port_details)
369 return phy_info->port_details->rphy;
370 else
371 return NULL;
372}
373
374static inline void
375mptsas_set_rphy(struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
376{
377 if (phy_info->port_details) {
378 phy_info->port_details->rphy = rphy;
379 dsaswideprintk((KERN_DEBUG "sas_rphy_add: rphy=%p\n", rphy));
380 }
381
382#ifdef MPT_DEBUG_SAS_WIDE
383 if (rphy) {
384 dev_printk(KERN_DEBUG, &rphy->dev, "add:");
385 printk("rphy=%p release=%p\n",
386 rphy, rphy->dev.release);
387 }
388#endif
389}
390
391static inline struct sas_port *
392mptsas_get_port(struct mptsas_phyinfo *phy_info)
393{
394 if (phy_info->port_details)
395 return phy_info->port_details->port;
396 else
397 return NULL;
398}
399
400static inline void
401mptsas_set_port(struct mptsas_phyinfo *phy_info, struct sas_port *port)
402{
403 if (phy_info->port_details)
404 phy_info->port_details->port = port;
405
406#ifdef MPT_DEBUG_SAS_WIDE
407 if (port) {
408 dev_printk(KERN_DEBUG, &port->dev, "add: ");
409 printk("port=%p release=%p\n",
410 port, port->dev.release);
411 }
412#endif
413}
414
415static inline struct scsi_target *
416mptsas_get_starget(struct mptsas_phyinfo *phy_info)
417{
418 if (phy_info->port_details)
419 return phy_info->port_details->starget;
420 else
421 return NULL;
422}
423
424static inline void
425mptsas_set_starget(struct mptsas_phyinfo *phy_info, struct scsi_target *
426starget)
427{
428 if (phy_info->port_details)
429 phy_info->port_details->starget = starget;
430}
431
432
433/*
434 * mptsas_setup_wide_ports
435 *
436 * Updates for new and existing narrow/wide port configuration
437 * in the sas_topology
438 */
439static void
440mptsas_setup_wide_ports(MPT_ADAPTER *ioc, struct mptsas_portinfo *port_info)
441{
442 struct mptsas_portinfo_details * port_details;
443 struct mptsas_phyinfo *phy_info, *phy_info_cmp;
444 u64 sas_address;
445 int i, j;
446
447 mutex_lock(&ioc->sas_topology_mutex);
448
449 phy_info = port_info->phy_info;
450 for (i = 0 ; i < port_info->num_phys ; i++, phy_info++) {
451 if (phy_info->attached.handle)
452 continue;
453 port_details = phy_info->port_details;
454 if (!port_details)
455 continue;
456 if (port_details->num_phys < 2)
457 continue;
458 /*
459 * Removing a phy from a port, letting the last
460 * phy be removed by firmware events.
461 */
462 dsaswideprintk((KERN_DEBUG
463 "%s: [%p]: deleting phy = %d\n",
464 __FUNCTION__, port_details, i));
465 port_details->num_phys--;
466 port_details->phy_bitmask &= ~ (1 << phy_info->phy_id);
467 memset(&phy_info->attached, 0, sizeof(struct mptsas_devinfo));
468 sas_port_delete_phy(port_details->port, phy_info->phy);
469 phy_info->port_details = NULL;
470 }
471
472 /*
473 * Populate and refresh the tree
474 */
475 phy_info = port_info->phy_info;
476 for (i = 0 ; i < port_info->num_phys ; i++, phy_info++) {
477 sas_address = phy_info->attached.sas_address;
478 dsaswideprintk((KERN_DEBUG "phy_id=%d sas_address=0x%018llX\n",
479 i, sas_address));
480 if (!sas_address)
481 continue;
482 port_details = phy_info->port_details;
483 /*
484 * Forming a port
485 */
486 if (!port_details) {
487 port_details = kzalloc(sizeof(*port_details),
488 GFP_KERNEL);
489 if (!port_details)
490 goto out;
491 port_details->num_phys = 1;
492 port_details->port_info = port_info;
493 if (phy_info->phy_id < 64 )
494 port_details->phy_bitmask |=
495 (1 << phy_info->phy_id);
496 phy_info->sas_port_add_phy=1;
497 dsaswideprintk((KERN_DEBUG "\t\tForming port\n\t\t"
498 "phy_id=%d sas_address=0x%018llX\n",
499 i, sas_address));
500 phy_info->port_details = port_details;
501 }
502
503 if (i == port_info->num_phys - 1)
504 continue;
505 phy_info_cmp = &port_info->phy_info[i + 1];
506 for (j = i + 1 ; j < port_info->num_phys ; j++,
507 phy_info_cmp++) {
508 if (!phy_info_cmp->attached.sas_address)
509 continue;
510 if (sas_address != phy_info_cmp->attached.sas_address)
511 continue;
512 if (phy_info_cmp->port_details == port_details )
513 continue;
514 dsaswideprintk((KERN_DEBUG
515 "\t\tphy_id=%d sas_address=0x%018llX\n",
516 j, phy_info_cmp->attached.sas_address));
517 if (phy_info_cmp->port_details) {
518 port_details->rphy =
519 mptsas_get_rphy(phy_info_cmp);
520 port_details->port =
521 mptsas_get_port(phy_info_cmp);
522 port_details->starget =
523 mptsas_get_starget(phy_info_cmp);
524 port_details->num_phys =
525 phy_info_cmp->port_details->num_phys;
526 if (!phy_info_cmp->port_details->num_phys)
527 kfree(phy_info_cmp->port_details);
528 } else
529 phy_info_cmp->sas_port_add_phy=1;
530 /*
531 * Adding a phy to a port
532 */
533 phy_info_cmp->port_details = port_details;
534 if (phy_info_cmp->phy_id < 64 )
535 port_details->phy_bitmask |=
536 (1 << phy_info_cmp->phy_id);
537 port_details->num_phys++;
538 }
539 }
540
541 out:
542
543#ifdef MPT_DEBUG_SAS_WIDE
544 for (i = 0; i < port_info->num_phys; i++) {
545 port_details = port_info->phy_info[i].port_details;
546 if (!port_details)
547 continue;
548 dsaswideprintk((KERN_DEBUG
549 "%s: [%p]: phy_id=%02d num_phys=%02d "
550 "bitmask=0x%016llX\n",
551 __FUNCTION__,
552 port_details, i, port_details->num_phys,
553 port_details->phy_bitmask));
554 dsaswideprintk((KERN_DEBUG"\t\tport = %p rphy=%p\n",
555 port_details->port, port_details->rphy));
556 }
557 dsaswideprintk((KERN_DEBUG"\n"));
558#endif
559 mutex_unlock(&ioc->sas_topology_mutex);
560}
561
562static void
563mptsas_target_reset(MPT_ADAPTER *ioc, VirtTarget * vtarget)
564{
565 MPT_SCSI_HOST *hd = (MPT_SCSI_HOST *)ioc->sh->hostdata;
566
567 if (mptscsih_TMHandler(hd,
568 MPI_SCSITASKMGMT_TASKTYPE_TARGET_RESET,
569 vtarget->bus_id, vtarget->target_id, 0, 0, 5) < 0) {
570 hd->tmPending = 0;
571 hd->tmState = TM_STATE_NONE;
572 printk(MYIOC_s_WARN_FMT
573 "Error processing TaskMgmt id=%d TARGET_RESET\n",
574 ioc->name, vtarget->target_id);
575 }
576}
577
322static int 578static int
323mptsas_sas_enclosure_pg0(MPT_ADAPTER *ioc, struct mptsas_enclosure *enclosure, 579mptsas_sas_enclosure_pg0(MPT_ADAPTER *ioc, struct mptsas_enclosure *enclosure,
324 u32 form, u32 form_specific) 580 u32 form, u32 form_specific)
@@ -387,24 +643,112 @@ mptsas_sas_enclosure_pg0(MPT_ADAPTER *ioc, struct mptsas_enclosure *enclosure,
387static int 643static int
388mptsas_slave_configure(struct scsi_device *sdev) 644mptsas_slave_configure(struct scsi_device *sdev)
389{ 645{
390 struct Scsi_Host *host = sdev->host;
391 MPT_SCSI_HOST *hd = (MPT_SCSI_HOST *)host->hostdata;
392 646
393 /* 647 if (sdev->channel == MPTSAS_RAID_CHANNEL)
394 * RAID volumes placed beyond the last expected port. 648 goto out;
395 * Ignore sending sas mode pages in that case..
396 */
397 if (sdev->channel < hd->ioc->num_ports)
398 sas_read_port_mode_page(sdev);
399 649
650 sas_read_port_mode_page(sdev);
651
652 out:
400 return mptscsih_slave_configure(sdev); 653 return mptscsih_slave_configure(sdev);
401} 654}
402 655
403/* 656static int
404 * This is pretty ugly. We will be able to seriously clean it up 657mptsas_target_alloc(struct scsi_target *starget)
405 * once the DV code in mptscsih goes away and we can properly 658{
406 * implement ->target_alloc. 659 struct Scsi_Host *host = dev_to_shost(&starget->dev);
407 */ 660 MPT_SCSI_HOST *hd = (MPT_SCSI_HOST *)host->hostdata;
661 VirtTarget *vtarget;
662 u32 target_id;
663 u32 channel;
664 struct sas_rphy *rphy;
665 struct mptsas_portinfo *p;
666 int i;
667
668 vtarget = kzalloc(sizeof(VirtTarget), GFP_KERNEL);
669 if (!vtarget)
670 return -ENOMEM;
671
672 vtarget->starget = starget;
673 vtarget->ioc_id = hd->ioc->id;
674 vtarget->tflags = MPT_TARGET_FLAGS_Q_YES|MPT_TARGET_FLAGS_VALID_INQUIRY;
675
676 target_id = starget->id;
677 channel = 0;
678
679 hd->Targets[target_id] = vtarget;
680
681 if (starget->channel == MPTSAS_RAID_CHANNEL)
682 goto out;
683
684 rphy = dev_to_rphy(starget->dev.parent);
685 mutex_lock(&hd->ioc->sas_topology_mutex);
686 list_for_each_entry(p, &hd->ioc->sas_topology, list) {
687 for (i = 0; i < p->num_phys; i++) {
688 if (p->phy_info[i].attached.sas_address !=
689 rphy->identify.sas_address)
690 continue;
691 target_id = p->phy_info[i].attached.id;
692 channel = p->phy_info[i].attached.channel;
693 mptsas_set_starget(&p->phy_info[i], starget);
694
695 /*
696 * Exposing hidden raid components
697 */
698 if (mptscsih_is_phys_disk(hd->ioc, target_id)) {
699 target_id = mptscsih_raid_id_to_num(hd,
700 target_id);
701 vtarget->tflags |=
702 MPT_TARGET_FLAGS_RAID_COMPONENT;
703 }
704 mutex_unlock(&hd->ioc->sas_topology_mutex);
705 goto out;
706 }
707 }
708 mutex_unlock(&hd->ioc->sas_topology_mutex);
709
710 kfree(vtarget);
711 return -ENXIO;
712
713 out:
714 vtarget->target_id = target_id;
715 vtarget->bus_id = channel;
716 starget->hostdata = vtarget;
717 return 0;
718}
719
720static void
721mptsas_target_destroy(struct scsi_target *starget)
722{
723 struct Scsi_Host *host = dev_to_shost(&starget->dev);
724 MPT_SCSI_HOST *hd = (MPT_SCSI_HOST *)host->hostdata;
725 struct sas_rphy *rphy;
726 struct mptsas_portinfo *p;
727 int i;
728
729 if (!starget->hostdata)
730 return;
731
732 if (starget->channel == MPTSAS_RAID_CHANNEL)
733 goto out;
734
735 rphy = dev_to_rphy(starget->dev.parent);
736 list_for_each_entry(p, &hd->ioc->sas_topology, list) {
737 for (i = 0; i < p->num_phys; i++) {
738 if (p->phy_info[i].attached.sas_address !=
739 rphy->identify.sas_address)
740 continue;
741 mptsas_set_starget(&p->phy_info[i], NULL);
742 goto out;
743 }
744 }
745
746 out:
747 kfree(starget->hostdata);
748 starget->hostdata = NULL;
749}
750
751
408static int 752static int
409mptsas_slave_alloc(struct scsi_device *sdev) 753mptsas_slave_alloc(struct scsi_device *sdev)
410{ 754{
@@ -412,61 +756,38 @@ mptsas_slave_alloc(struct scsi_device *sdev)
412 MPT_SCSI_HOST *hd = (MPT_SCSI_HOST *)host->hostdata; 756 MPT_SCSI_HOST *hd = (MPT_SCSI_HOST *)host->hostdata;
413 struct sas_rphy *rphy; 757 struct sas_rphy *rphy;
414 struct mptsas_portinfo *p; 758 struct mptsas_portinfo *p;
415 VirtTarget *vtarget;
416 VirtDevice *vdev; 759 VirtDevice *vdev;
417 struct scsi_target *starget; 760 struct scsi_target *starget;
418 u32 target_id; 761 int i;
419 int i;
420 762
421 vdev = kzalloc(sizeof(VirtDevice), GFP_KERNEL); 763 vdev = kzalloc(sizeof(VirtDevice), GFP_KERNEL);
422 if (!vdev) { 764 if (!vdev) {
423 printk(MYIOC_s_ERR_FMT "slave_alloc kmalloc(%zd) FAILED!\n", 765 printk(MYIOC_s_ERR_FMT "slave_alloc kzalloc(%zd) FAILED!\n",
424 hd->ioc->name, sizeof(VirtDevice)); 766 hd->ioc->name, sizeof(VirtDevice));
425 return -ENOMEM; 767 return -ENOMEM;
426 } 768 }
427 sdev->hostdata = vdev;
428 starget = scsi_target(sdev); 769 starget = scsi_target(sdev);
429 vtarget = starget->hostdata; 770 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 771
437 /* 772 if (sdev->channel == MPTSAS_RAID_CHANNEL)
438 RAID volumes placed beyond the last expected port.
439 */
440 if (sdev->channel == hd->ioc->num_ports) {
441 target_id = sdev->id;
442 vtarget->bus_id = 0;
443 vdev->lun = 0;
444 goto out; 773 goto out;
445 }
446 774
447 rphy = dev_to_rphy(sdev->sdev_target->dev.parent); 775 rphy = dev_to_rphy(sdev->sdev_target->dev.parent);
448 mutex_lock(&hd->ioc->sas_topology_mutex); 776 mutex_lock(&hd->ioc->sas_topology_mutex);
449 list_for_each_entry(p, &hd->ioc->sas_topology, list) { 777 list_for_each_entry(p, &hd->ioc->sas_topology, list) {
450 for (i = 0; i < p->num_phys; i++) { 778 for (i = 0; i < p->num_phys; i++) {
451 if (p->phy_info[i].attached.sas_address == 779 if (p->phy_info[i].attached.sas_address !=
452 rphy->identify.sas_address) { 780 rphy->identify.sas_address)
453 target_id = p->phy_info[i].attached.id; 781 continue;
454 vtarget->bus_id = p->phy_info[i].attached.channel; 782 vdev->lun = sdev->lun;
455 vdev->lun = sdev->lun; 783 /*
456 p->phy_info[i].starget = sdev->sdev_target; 784 * Exposing hidden raid components
457 /* 785 */
458 * Exposing hidden disk (RAID) 786 if (mptscsih_is_phys_disk(hd->ioc,
459 */ 787 p->phy_info[i].attached.id))
460 if (mptscsih_is_phys_disk(hd->ioc, target_id)) { 788 sdev->no_uld_attach = 1;
461 target_id = mptscsih_raid_id_to_num(hd, 789 mutex_unlock(&hd->ioc->sas_topology_mutex);
462 target_id); 790 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 } 791 }
471 } 792 }
472 mutex_unlock(&hd->ioc->sas_topology_mutex); 793 mutex_unlock(&hd->ioc->sas_topology_mutex);
@@ -475,57 +796,39 @@ mptsas_slave_alloc(struct scsi_device *sdev)
475 return -ENXIO; 796 return -ENXIO;
476 797
477 out: 798 out:
478 vtarget->target_id = target_id; 799 vdev->vtarget->num_luns++;
479 vtarget->num_luns++; 800 sdev->hostdata = vdev;
480 return 0; 801 return 0;
481} 802}
482 803
483static void 804static int
484mptsas_slave_destroy(struct scsi_device *sdev) 805mptsas_qcmd(struct scsi_cmnd *SCpnt, void (*done)(struct scsi_cmnd *))
485{ 806{
486 struct Scsi_Host *host = sdev->host; 807 VirtDevice *vdev = SCpnt->device->hostdata;
487 MPT_SCSI_HOST *hd = (MPT_SCSI_HOST *)host->hostdata;
488 VirtDevice *vdev;
489 808
490 /* 809// scsi_print_command(SCpnt);
491 * Issue target reset to flush firmware outstanding commands. 810 if (vdev->vtarget->deleted) {
492 */ 811 SCpnt->result = DID_NO_CONNECT << 16;
493 vdev = sdev->hostdata; 812 done(SCpnt);
494 if (vdev->configured_lun){ 813 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 } 814 }
514 mptscsih_slave_destroy(sdev); 815
816 return mptscsih_qcmd(SCpnt,done);
515} 817}
516 818
819
517static struct scsi_host_template mptsas_driver_template = { 820static struct scsi_host_template mptsas_driver_template = {
518 .module = THIS_MODULE, 821 .module = THIS_MODULE,
519 .proc_name = "mptsas", 822 .proc_name = "mptsas",
520 .proc_info = mptscsih_proc_info, 823 .proc_info = mptscsih_proc_info,
521 .name = "MPT SPI Host", 824 .name = "MPT SPI Host",
522 .info = mptscsih_info, 825 .info = mptscsih_info,
523 .queuecommand = mptscsih_qcmd, 826 .queuecommand = mptsas_qcmd,
524 .target_alloc = mptscsih_target_alloc, 827 .target_alloc = mptsas_target_alloc,
525 .slave_alloc = mptsas_slave_alloc, 828 .slave_alloc = mptsas_slave_alloc,
526 .slave_configure = mptsas_slave_configure, 829 .slave_configure = mptsas_slave_configure,
527 .target_destroy = mptscsih_target_destroy, 830 .target_destroy = mptsas_target_destroy,
528 .slave_destroy = mptsas_slave_destroy, 831 .slave_destroy = mptscsih_slave_destroy,
529 .change_queue_depth = mptscsih_change_queue_depth, 832 .change_queue_depth = mptscsih_change_queue_depth,
530 .eh_abort_handler = mptscsih_abort, 833 .eh_abort_handler = mptscsih_abort,
531 .eh_device_reset_handler = mptscsih_dev_reset, 834 .eh_device_reset_handler = mptscsih_dev_reset,
@@ -549,6 +852,10 @@ static int mptsas_get_linkerrors(struct sas_phy *phy)
549 dma_addr_t dma_handle; 852 dma_addr_t dma_handle;
550 int error; 853 int error;
551 854
855 /* FIXME: only have link errors on local phys */
856 if (!scsi_is_sas_phy_local(phy))
857 return -EINVAL;
858
552 hdr.PageVersion = MPI_SASPHY1_PAGEVERSION; 859 hdr.PageVersion = MPI_SASPHY1_PAGEVERSION;
553 hdr.ExtPageLength = 0; 860 hdr.ExtPageLength = 0;
554 hdr.PageNumber = 1 /* page number 1*/; 861 hdr.PageNumber = 1 /* page number 1*/;
@@ -621,6 +928,10 @@ static int mptsas_phy_reset(struct sas_phy *phy, int hard_reset)
621 unsigned long timeleft; 928 unsigned long timeleft;
622 int error = -ERESTARTSYS; 929 int error = -ERESTARTSYS;
623 930
931 /* FIXME: fusion doesn't allow non-local phy reset */
932 if (!scsi_is_sas_phy_local(phy))
933 return -EINVAL;
934
624 /* not implemented for expanders */ 935 /* not implemented for expanders */
625 if (phy->identify.target_port_protocols & SAS_PROTOCOL_SMP) 936 if (phy->identify.target_port_protocols & SAS_PROTOCOL_SMP)
626 return -ENXIO; 937 return -ENXIO;
@@ -795,7 +1106,7 @@ mptsas_sas_io_unit_pg0(MPT_ADAPTER *ioc, struct mptsas_portinfo *port_info)
795 1106
796 port_info->num_phys = buffer->NumPhys; 1107 port_info->num_phys = buffer->NumPhys;
797 port_info->phy_info = kcalloc(port_info->num_phys, 1108 port_info->phy_info = kcalloc(port_info->num_phys,
798 sizeof(struct mptsas_phyinfo),GFP_KERNEL); 1109 sizeof(*port_info->phy_info),GFP_KERNEL);
799 if (!port_info->phy_info) { 1110 if (!port_info->phy_info) {
800 error = -ENOMEM; 1111 error = -ENOMEM;
801 goto out_free_consistent; 1112 goto out_free_consistent;
@@ -811,6 +1122,7 @@ mptsas_sas_io_unit_pg0(MPT_ADAPTER *ioc, struct mptsas_portinfo *port_info)
811 buffer->PhyData[i].Port; 1122 buffer->PhyData[i].Port;
812 port_info->phy_info[i].negotiated_link_rate = 1123 port_info->phy_info[i].negotiated_link_rate =
813 buffer->PhyData[i].NegotiatedLinkRate; 1124 buffer->PhyData[i].NegotiatedLinkRate;
1125 port_info->phy_info[i].portinfo = port_info;
814 } 1126 }
815 1127
816 out_free_consistent: 1128 out_free_consistent:
@@ -968,7 +1280,7 @@ mptsas_sas_expander_pg0(MPT_ADAPTER *ioc, struct mptsas_portinfo *port_info,
968 CONFIGPARMS cfg; 1280 CONFIGPARMS cfg;
969 SasExpanderPage0_t *buffer; 1281 SasExpanderPage0_t *buffer;
970 dma_addr_t dma_handle; 1282 dma_addr_t dma_handle;
971 int error; 1283 int i, error;
972 1284
973 hdr.PageVersion = MPI_SASEXPANDER0_PAGEVERSION; 1285 hdr.PageVersion = MPI_SASEXPANDER0_PAGEVERSION;
974 hdr.ExtPageLength = 0; 1286 hdr.ExtPageLength = 0;
@@ -1013,12 +1325,15 @@ mptsas_sas_expander_pg0(MPT_ADAPTER *ioc, struct mptsas_portinfo *port_info,
1013 port_info->num_phys = buffer->NumPhys; 1325 port_info->num_phys = buffer->NumPhys;
1014 port_info->handle = le16_to_cpu(buffer->DevHandle); 1326 port_info->handle = le16_to_cpu(buffer->DevHandle);
1015 port_info->phy_info = kcalloc(port_info->num_phys, 1327 port_info->phy_info = kcalloc(port_info->num_phys,
1016 sizeof(struct mptsas_phyinfo),GFP_KERNEL); 1328 sizeof(*port_info->phy_info),GFP_KERNEL);
1017 if (!port_info->phy_info) { 1329 if (!port_info->phy_info) {
1018 error = -ENOMEM; 1330 error = -ENOMEM;
1019 goto out_free_consistent; 1331 goto out_free_consistent;
1020 } 1332 }
1021 1333
1334 for (i = 0; i < port_info->num_phys; i++)
1335 port_info->phy_info[i].portinfo = port_info;
1336
1022 out_free_consistent: 1337 out_free_consistent:
1023 pci_free_consistent(ioc->pcidev, hdr.ExtPageLength * 4, 1338 pci_free_consistent(ioc->pcidev, hdr.ExtPageLength * 4,
1024 buffer, dma_handle); 1339 buffer, dma_handle);
@@ -1161,19 +1476,23 @@ static int mptsas_probe_one_phy(struct device *dev,
1161{ 1476{
1162 MPT_ADAPTER *ioc; 1477 MPT_ADAPTER *ioc;
1163 struct sas_phy *phy; 1478 struct sas_phy *phy;
1164 int error; 1479 struct sas_port *port;
1480 int error = 0;
1165 1481
1166 if (!dev) 1482 if (!dev) {
1167 return -ENODEV; 1483 error = -ENODEV;
1484 goto out;
1485 }
1168 1486
1169 if (!phy_info->phy) { 1487 if (!phy_info->phy) {
1170 phy = sas_phy_alloc(dev, index); 1488 phy = sas_phy_alloc(dev, index);
1171 if (!phy) 1489 if (!phy) {
1172 return -ENOMEM; 1490 error = -ENOMEM;
1491 goto out;
1492 }
1173 } else 1493 } else
1174 phy = phy_info->phy; 1494 phy = phy_info->phy;
1175 1495
1176 phy->port_identifier = phy_info->port_id;
1177 mptsas_parse_device_info(&phy->identify, &phy_info->identify); 1496 mptsas_parse_device_info(&phy->identify, &phy_info->identify);
1178 1497
1179 /* 1498 /*
@@ -1259,25 +1578,54 @@ static int mptsas_probe_one_phy(struct device *dev,
1259 1578
1260 if (!phy_info->phy) { 1579 if (!phy_info->phy) {
1261 1580
1262 if (local)
1263 phy->local_attached = 1;
1264
1265 error = sas_phy_add(phy); 1581 error = sas_phy_add(phy);
1266 if (error) { 1582 if (error) {
1267 sas_phy_free(phy); 1583 sas_phy_free(phy);
1268 return error; 1584 goto out;
1269 } 1585 }
1270 phy_info->phy = phy; 1586 phy_info->phy = phy;
1271 } 1587 }
1272 1588
1273 if ((phy_info->attached.handle) && 1589 if (!phy_info->attached.handle ||
1274 (!phy_info->rphy)) { 1590 !phy_info->port_details)
1591 goto out;
1592
1593 port = mptsas_get_port(phy_info);
1594 ioc = phy_to_ioc(phy_info->phy);
1595
1596 if (phy_info->sas_port_add_phy) {
1597
1598 if (!port) {
1599 port = sas_port_alloc_num(dev);
1600 if (!port) {
1601 error = -ENOMEM;
1602 goto out;
1603 }
1604 error = sas_port_add(port);
1605 if (error) {
1606 dfailprintk((MYIOC_s_ERR_FMT
1607 "%s: exit at line=%d\n", ioc->name,
1608 __FUNCTION__, __LINE__));
1609 goto out;
1610 }
1611 mptsas_set_port(phy_info, port);
1612 dsaswideprintk((KERN_DEBUG
1613 "sas_port_alloc: port=%p dev=%p port_id=%d\n",
1614 port, dev, port->port_identifier));
1615 }
1616 dsaswideprintk((KERN_DEBUG "sas_port_add_phy: phy_id=%d\n",
1617 phy_info->phy_id));
1618 sas_port_add_phy(port, phy_info->phy);
1619 phy_info->sas_port_add_phy = 0;
1620 }
1621
1622 if (!mptsas_get_rphy(phy_info) && port && !port->rphy) {
1275 1623
1276 struct sas_rphy *rphy; 1624 struct sas_rphy *rphy;
1625 struct device *parent;
1277 struct sas_identify identify; 1626 struct sas_identify identify;
1278 1627
1279 ioc = phy_to_ioc(phy_info->phy); 1628 parent = dev->parent->parent;
1280
1281 /* 1629 /*
1282 * Let the hotplug_work thread handle processing 1630 * Let the hotplug_work thread handle processing
1283 * the adding/removing of devices that occur 1631 * the adding/removing of devices that occur
@@ -1285,36 +1633,67 @@ static int mptsas_probe_one_phy(struct device *dev,
1285 */ 1633 */
1286 if (ioc->sas_discovery_runtime && 1634 if (ioc->sas_discovery_runtime &&
1287 mptsas_is_end_device(&phy_info->attached)) 1635 mptsas_is_end_device(&phy_info->attached))
1288 return 0; 1636 goto out;
1289 1637
1290 mptsas_parse_device_info(&identify, &phy_info->attached); 1638 mptsas_parse_device_info(&identify, &phy_info->attached);
1639 if (scsi_is_host_device(parent)) {
1640 struct mptsas_portinfo *port_info;
1641 int i;
1642
1643 mutex_lock(&ioc->sas_topology_mutex);
1644 port_info = mptsas_find_portinfo_by_handle(ioc,
1645 ioc->handle);
1646 mutex_unlock(&ioc->sas_topology_mutex);
1647
1648 for (i = 0; i < port_info->num_phys; i++)
1649 if (port_info->phy_info[i].identify.sas_address ==
1650 identify.sas_address) {
1651 sas_port_mark_backlink(port);
1652 goto out;
1653 }
1654
1655 } else if (scsi_is_sas_rphy(parent)) {
1656 struct sas_rphy *parent_rphy = dev_to_rphy(parent);
1657 if (identify.sas_address ==
1658 parent_rphy->identify.sas_address) {
1659 sas_port_mark_backlink(port);
1660 goto out;
1661 }
1662 }
1663
1291 switch (identify.device_type) { 1664 switch (identify.device_type) {
1292 case SAS_END_DEVICE: 1665 case SAS_END_DEVICE:
1293 rphy = sas_end_device_alloc(phy); 1666 rphy = sas_end_device_alloc(port);
1294 break; 1667 break;
1295 case SAS_EDGE_EXPANDER_DEVICE: 1668 case SAS_EDGE_EXPANDER_DEVICE:
1296 case SAS_FANOUT_EXPANDER_DEVICE: 1669 case SAS_FANOUT_EXPANDER_DEVICE:
1297 rphy = sas_expander_alloc(phy, identify.device_type); 1670 rphy = sas_expander_alloc(port, identify.device_type);
1298 break; 1671 break;
1299 default: 1672 default:
1300 rphy = NULL; 1673 rphy = NULL;
1301 break; 1674 break;
1302 } 1675 }
1303 if (!rphy) 1676 if (!rphy) {
1304 return 0; /* non-fatal: an rphy can be added later */ 1677 dfailprintk((MYIOC_s_ERR_FMT
1678 "%s: exit at line=%d\n", ioc->name,
1679 __FUNCTION__, __LINE__));
1680 goto out;
1681 }
1305 1682
1306 rphy->identify = identify; 1683 rphy->identify = identify;
1307
1308 error = sas_rphy_add(rphy); 1684 error = sas_rphy_add(rphy);
1309 if (error) { 1685 if (error) {
1686 dfailprintk((MYIOC_s_ERR_FMT
1687 "%s: exit at line=%d\n", ioc->name,
1688 __FUNCTION__, __LINE__));
1310 sas_rphy_free(rphy); 1689 sas_rphy_free(rphy);
1311 return error; 1690 goto out;
1312 } 1691 }
1313 1692 mptsas_set_rphy(phy_info, rphy);
1314 phy_info->rphy = rphy;
1315 } 1693 }
1316 1694
1317 return 0; 1695 out:
1696 return error;
1318} 1697}
1319 1698
1320static int 1699static int
@@ -1333,6 +1712,7 @@ mptsas_probe_hba_phys(MPT_ADAPTER *ioc)
1333 goto out_free_port_info; 1712 goto out_free_port_info;
1334 1713
1335 mutex_lock(&ioc->sas_topology_mutex); 1714 mutex_lock(&ioc->sas_topology_mutex);
1715 ioc->handle = hba->handle;
1336 port_info = mptsas_find_portinfo_by_handle(ioc, hba->handle); 1716 port_info = mptsas_find_portinfo_by_handle(ioc, hba->handle);
1337 if (!port_info) { 1717 if (!port_info) {
1338 port_info = hba; 1718 port_info = hba;
@@ -1342,13 +1722,11 @@ mptsas_probe_hba_phys(MPT_ADAPTER *ioc)
1342 for (i = 0; i < hba->num_phys; i++) 1722 for (i = 0; i < hba->num_phys; i++)
1343 port_info->phy_info[i].negotiated_link_rate = 1723 port_info->phy_info[i].negotiated_link_rate =
1344 hba->phy_info[i].negotiated_link_rate; 1724 hba->phy_info[i].negotiated_link_rate;
1345 if (hba->phy_info) 1725 kfree(hba->phy_info);
1346 kfree(hba->phy_info);
1347 kfree(hba); 1726 kfree(hba);
1348 hba = NULL; 1727 hba = NULL;
1349 } 1728 }
1350 mutex_unlock(&ioc->sas_topology_mutex); 1729 mutex_unlock(&ioc->sas_topology_mutex);
1351 ioc->num_ports = port_info->num_phys;
1352 1730
1353 for (i = 0; i < port_info->num_phys; i++) { 1731 for (i = 0; i < port_info->num_phys; i++) {
1354 mptsas_sas_phy_pg0(ioc, &port_info->phy_info[i], 1732 mptsas_sas_phy_pg0(ioc, &port_info->phy_info[i],
@@ -1362,24 +1740,24 @@ mptsas_probe_hba_phys(MPT_ADAPTER *ioc)
1362 port_info->phy_info[i].phy_id; 1740 port_info->phy_info[i].phy_id;
1363 handle = port_info->phy_info[i].identify.handle; 1741 handle = port_info->phy_info[i].identify.handle;
1364 1742
1365 if (port_info->phy_info[i].attached.handle) { 1743 if (port_info->phy_info[i].attached.handle)
1366 mptsas_sas_device_pg0(ioc, 1744 mptsas_sas_device_pg0(ioc,
1367 &port_info->phy_info[i].attached, 1745 &port_info->phy_info[i].attached,
1368 (MPI_SAS_DEVICE_PGAD_FORM_HANDLE << 1746 (MPI_SAS_DEVICE_PGAD_FORM_HANDLE <<
1369 MPI_SAS_DEVICE_PGAD_FORM_SHIFT), 1747 MPI_SAS_DEVICE_PGAD_FORM_SHIFT),
1370 port_info->phy_info[i].attached.handle); 1748 port_info->phy_info[i].attached.handle);
1371 } 1749 }
1372 1750
1751 mptsas_setup_wide_ports(ioc, port_info);
1752
1753 for (i = 0; i < port_info->num_phys; i++, ioc->sas_index++)
1373 mptsas_probe_one_phy(&ioc->sh->shost_gendev, 1754 mptsas_probe_one_phy(&ioc->sh->shost_gendev,
1374 &port_info->phy_info[i], ioc->sas_index, 1); 1755 &port_info->phy_info[i], ioc->sas_index, 1);
1375 ioc->sas_index++;
1376 }
1377 1756
1378 return 0; 1757 return 0;
1379 1758
1380 out_free_port_info: 1759 out_free_port_info:
1381 if (hba) 1760 kfree(hba);
1382 kfree(hba);
1383 out: 1761 out:
1384 return error; 1762 return error;
1385} 1763}
@@ -1388,6 +1766,8 @@ static int
1388mptsas_probe_expander_phys(MPT_ADAPTER *ioc, u32 *handle) 1766mptsas_probe_expander_phys(MPT_ADAPTER *ioc, u32 *handle)
1389{ 1767{
1390 struct mptsas_portinfo *port_info, *p, *ex; 1768 struct mptsas_portinfo *port_info, *p, *ex;
1769 struct device *parent;
1770 struct sas_rphy *rphy;
1391 int error = -ENOMEM, i, j; 1771 int error = -ENOMEM, i, j;
1392 1772
1393 ex = kzalloc(sizeof(*port_info), GFP_KERNEL); 1773 ex = kzalloc(sizeof(*port_info), GFP_KERNEL);
@@ -1409,16 +1789,13 @@ mptsas_probe_expander_phys(MPT_ADAPTER *ioc, u32 *handle)
1409 list_add_tail(&port_info->list, &ioc->sas_topology); 1789 list_add_tail(&port_info->list, &ioc->sas_topology);
1410 } else { 1790 } else {
1411 port_info->handle = ex->handle; 1791 port_info->handle = ex->handle;
1412 if (ex->phy_info) 1792 kfree(ex->phy_info);
1413 kfree(ex->phy_info);
1414 kfree(ex); 1793 kfree(ex);
1415 ex = NULL; 1794 ex = NULL;
1416 } 1795 }
1417 mutex_unlock(&ioc->sas_topology_mutex); 1796 mutex_unlock(&ioc->sas_topology_mutex);
1418 1797
1419 for (i = 0; i < port_info->num_phys; i++) { 1798 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], 1799 mptsas_sas_expander_pg1(ioc, &port_info->phy_info[i],
1423 (MPI_SAS_EXPAND_PGAD_FORM_HANDLE_PHY_NUM << 1800 (MPI_SAS_EXPAND_PGAD_FORM_HANDLE_PHY_NUM <<
1424 MPI_SAS_EXPAND_PGAD_FORM_SHIFT), (i << 16) + *handle); 1801 MPI_SAS_EXPAND_PGAD_FORM_SHIFT), (i << 16) + *handle);
@@ -1442,34 +1819,34 @@ mptsas_probe_expander_phys(MPT_ADAPTER *ioc, u32 *handle)
1442 port_info->phy_info[i].attached.phy_id = 1819 port_info->phy_info[i].attached.phy_id =
1443 port_info->phy_info[i].phy_id; 1820 port_info->phy_info[i].phy_id;
1444 } 1821 }
1822 }
1445 1823
1446 /* 1824 parent = &ioc->sh->shost_gendev;
1447 * If we find a parent port handle this expander is 1825 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); 1826 mutex_lock(&ioc->sas_topology_mutex);
1453 list_for_each_entry(p, &ioc->sas_topology, list) { 1827 list_for_each_entry(p, &ioc->sas_topology, list) {
1454 for (j = 0; j < p->num_phys; j++) { 1828 for (j = 0; j < p->num_phys; j++) {
1455 if (port_info->phy_info[i].identify.handle == 1829 if (port_info->phy_info[i].identify.handle !=
1456 p->phy_info[j].attached.handle) 1830 p->phy_info[j].attached.handle)
1457 parent = &p->phy_info[j].rphy->dev; 1831 continue;
1832 rphy = mptsas_get_rphy(&p->phy_info[j]);
1833 parent = &rphy->dev;
1458 } 1834 }
1459 } 1835 }
1460 mutex_unlock(&ioc->sas_topology_mutex); 1836 mutex_unlock(&ioc->sas_topology_mutex);
1837 }
1838
1839 mptsas_setup_wide_ports(ioc, port_info);
1461 1840
1841 for (i = 0; i < port_info->num_phys; i++, ioc->sas_index++)
1462 mptsas_probe_one_phy(parent, &port_info->phy_info[i], 1842 mptsas_probe_one_phy(parent, &port_info->phy_info[i],
1463 ioc->sas_index, 0); 1843 ioc->sas_index, 0);
1464 ioc->sas_index++;
1465 }
1466 1844
1467 return 0; 1845 return 0;
1468 1846
1469 out_free_port_info: 1847 out_free_port_info:
1470 if (ex) { 1848 if (ex) {
1471 if (ex->phy_info) 1849 kfree(ex->phy_info);
1472 kfree(ex->phy_info);
1473 kfree(ex); 1850 kfree(ex);
1474 } 1851 }
1475 out: 1852 out:
@@ -1488,7 +1865,12 @@ mptsas_delete_expander_phys(MPT_ADAPTER *ioc)
1488{ 1865{
1489 struct mptsas_portinfo buffer; 1866 struct mptsas_portinfo buffer;
1490 struct mptsas_portinfo *port_info, *n, *parent; 1867 struct mptsas_portinfo *port_info, *n, *parent;
1868 struct mptsas_phyinfo *phy_info;
1869 struct scsi_target * starget;
1870 VirtTarget * vtarget;
1871 struct sas_port * port;
1491 int i; 1872 int i;
1873 u64 expander_sas_address;
1492 1874
1493 mutex_lock(&ioc->sas_topology_mutex); 1875 mutex_lock(&ioc->sas_topology_mutex);
1494 list_for_each_entry_safe(port_info, n, &ioc->sas_topology, list) { 1876 list_for_each_entry_safe(port_info, n, &ioc->sas_topology, list) {
@@ -1503,6 +1885,25 @@ mptsas_delete_expander_phys(MPT_ADAPTER *ioc)
1503 MPI_SAS_EXPAND_PGAD_FORM_SHIFT), port_info->handle)) { 1885 MPI_SAS_EXPAND_PGAD_FORM_SHIFT), port_info->handle)) {
1504 1886
1505 /* 1887 /*
1888 * Issue target reset to all child end devices
1889 * then mark them deleted to prevent further
1890 * IO going to them.
1891 */
1892 phy_info = port_info->phy_info;
1893 for (i = 0; i < port_info->num_phys; i++, phy_info++) {
1894 starget = mptsas_get_starget(phy_info);
1895 if (!starget)
1896 continue;
1897 vtarget = starget->hostdata;
1898 if(vtarget->deleted)
1899 continue;
1900 vtarget->deleted = 1;
1901 mptsas_target_reset(ioc, vtarget);
1902 sas_port_delete(mptsas_get_port(phy_info));
1903 mptsas_port_delete(phy_info->port_details);
1904 }
1905
1906 /*
1506 * Obtain the port_info instance to the parent port 1907 * Obtain the port_info instance to the parent port
1507 */ 1908 */
1508 parent = mptsas_find_portinfo_by_handle(ioc, 1909 parent = mptsas_find_portinfo_by_handle(ioc,
@@ -1511,34 +1912,44 @@ mptsas_delete_expander_phys(MPT_ADAPTER *ioc)
1511 if (!parent) 1912 if (!parent)
1512 goto next_port; 1913 goto next_port;
1513 1914
1915 expander_sas_address =
1916 port_info->phy_info[0].identify.sas_address;
1917
1514 /* 1918 /*
1515 * Delete rphys in the parent that point 1919 * Delete rphys in the parent that point
1516 * to this expander. The transport layer will 1920 * to this expander. The transport layer will
1517 * cleanup all the children. 1921 * cleanup all the children.
1518 */ 1922 */
1519 for (i = 0; i < parent->num_phys; i++) { 1923 phy_info = parent->phy_info;
1520 if ((!parent->phy_info[i].rphy) || 1924 for (i = 0; i < parent->num_phys; i++, phy_info++) {
1521 (parent->phy_info[i].attached.sas_address != 1925 port = mptsas_get_port(phy_info);
1522 port_info->phy_info[i].identify.sas_address)) 1926 if (!port)
1927 continue;
1928 if (phy_info->attached.sas_address !=
1929 expander_sas_address)
1523 continue; 1930 continue;
1524 sas_rphy_delete(parent->phy_info[i].rphy); 1931#ifdef MPT_DEBUG_SAS_WIDE
1525 memset(&parent->phy_info[i].attached, 0, 1932 dev_printk(KERN_DEBUG, &port->dev,
1526 sizeof(struct mptsas_devinfo)); 1933 "delete port (%d)\n", port->port_identifier);
1527 parent->phy_info[i].rphy = NULL; 1934#endif
1528 parent->phy_info[i].starget = NULL; 1935 sas_port_delete(port);
1936 mptsas_port_delete(phy_info->port_details);
1529 } 1937 }
1530 next_port: 1938 next_port:
1939
1940 phy_info = port_info->phy_info;
1941 for (i = 0; i < port_info->num_phys; i++, phy_info++)
1942 mptsas_port_delete(phy_info->port_details);
1943
1531 list_del(&port_info->list); 1944 list_del(&port_info->list);
1532 if (port_info->phy_info) 1945 kfree(port_info->phy_info);
1533 kfree(port_info->phy_info);
1534 kfree(port_info); 1946 kfree(port_info);
1535 } 1947 }
1536 /* 1948 /*
1537 * Free this memory allocated from inside 1949 * Free this memory allocated from inside
1538 * mptsas_sas_expander_pg0 1950 * mptsas_sas_expander_pg0
1539 */ 1951 */
1540 if (buffer.phy_info) 1952 kfree(buffer.phy_info);
1541 kfree(buffer.phy_info);
1542 } 1953 }
1543 mutex_unlock(&ioc->sas_topology_mutex); 1954 mutex_unlock(&ioc->sas_topology_mutex);
1544} 1955}
@@ -1564,7 +1975,7 @@ mptsas_scan_sas_topology(MPT_ADAPTER *ioc)
1564 if (!ioc->raid_data.pIocPg2->NumActiveVolumes) 1975 if (!ioc->raid_data.pIocPg2->NumActiveVolumes)
1565 goto out; 1976 goto out;
1566 for (i=0; i<ioc->raid_data.pIocPg2->NumActiveVolumes; i++) { 1977 for (i=0; i<ioc->raid_data.pIocPg2->NumActiveVolumes; i++) {
1567 scsi_add_device(ioc->sh, ioc->num_ports, 1978 scsi_add_device(ioc->sh, MPTSAS_RAID_CHANNEL,
1568 ioc->raid_data.pIocPg2->RaidVolume[i].VolumeID, 0); 1979 ioc->raid_data.pIocPg2->RaidVolume[i].VolumeID, 0);
1569 } 1980 }
1570 out: 1981 out:
@@ -1574,60 +1985,59 @@ mptsas_scan_sas_topology(MPT_ADAPTER *ioc)
1574/* 1985/*
1575 * Work queue thread to handle Runtime discovery 1986 * Work queue thread to handle Runtime discovery
1576 * Mere purpose is the hot add/delete of expanders 1987 * Mere purpose is the hot add/delete of expanders
1988 *(Mutex UNLOCKED)
1577 */ 1989 */
1578static void 1990static void
1579mptscsih_discovery_work(void * arg) 1991__mptsas_discovery_work(MPT_ADAPTER *ioc)
1580{ 1992{
1581 struct mptsas_discovery_event *ev = arg;
1582 MPT_ADAPTER *ioc = ev->ioc;
1583 u32 handle = 0xFFFF; 1993 u32 handle = 0xFFFF;
1584 1994
1585 mutex_lock(&ioc->sas_discovery_mutex);
1586 ioc->sas_discovery_runtime=1; 1995 ioc->sas_discovery_runtime=1;
1587 mptsas_delete_expander_phys(ioc); 1996 mptsas_delete_expander_phys(ioc);
1588 mptsas_probe_hba_phys(ioc); 1997 mptsas_probe_hba_phys(ioc);
1589 while (!mptsas_probe_expander_phys(ioc, &handle)) 1998 while (!mptsas_probe_expander_phys(ioc, &handle))
1590 ; 1999 ;
1591 kfree(ev);
1592 ioc->sas_discovery_runtime=0; 2000 ioc->sas_discovery_runtime=0;
2001}
2002
2003/*
2004 * Work queue thread to handle Runtime discovery
2005 * Mere purpose is the hot add/delete of expanders
2006 *(Mutex LOCKED)
2007 */
2008static void
2009mptsas_discovery_work(void * arg)
2010{
2011 struct mptsas_discovery_event *ev = arg;
2012 MPT_ADAPTER *ioc = ev->ioc;
2013
2014 mutex_lock(&ioc->sas_discovery_mutex);
2015 __mptsas_discovery_work(ioc);
1593 mutex_unlock(&ioc->sas_discovery_mutex); 2016 mutex_unlock(&ioc->sas_discovery_mutex);
2017 kfree(ev);
1594} 2018}
1595 2019
1596static struct mptsas_phyinfo * 2020static struct mptsas_phyinfo *
1597mptsas_find_phyinfo_by_parent(MPT_ADAPTER *ioc, u16 parent_handle, u8 phy_id) 2021mptsas_find_phyinfo_by_sas_address(MPT_ADAPTER *ioc, u64 sas_address)
1598{ 2022{
1599 struct mptsas_portinfo *port_info; 2023 struct mptsas_portinfo *port_info;
1600 struct mptsas_devinfo device_info;
1601 struct mptsas_phyinfo *phy_info = NULL; 2024 struct mptsas_phyinfo *phy_info = NULL;
1602 int i, error; 2025 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 2026
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); 2027 mutex_lock(&ioc->sas_topology_mutex);
1619 list_for_each_entry(port_info, &ioc->sas_topology, list) { 2028 list_for_each_entry(port_info, &ioc->sas_topology, list) {
1620 for (i = 0; i < port_info->num_phys; i++) { 2029 for (i = 0; i < port_info->num_phys; i++) {
1621 if (port_info->phy_info[i].identify.sas_address == 2030 if (port_info->phy_info[i].attached.sas_address
1622 device_info.sas_address && 2031 != sas_address)
1623 port_info->phy_info[i].phy_id == phy_id) { 2032 continue;
1624 phy_info = &port_info->phy_info[i]; 2033 if (!mptsas_is_end_device(
1625 break; 2034 &port_info->phy_info[i].attached))
1626 } 2035 continue;
2036 phy_info = &port_info->phy_info[i];
2037 break;
1627 } 2038 }
1628 } 2039 }
1629 mutex_unlock(&ioc->sas_topology_mutex); 2040 mutex_unlock(&ioc->sas_topology_mutex);
1630
1631 return phy_info; 2041 return phy_info;
1632} 2042}
1633 2043
@@ -1638,21 +2048,19 @@ mptsas_find_phyinfo_by_target(MPT_ADAPTER *ioc, u32 id)
1638 struct mptsas_phyinfo *phy_info = NULL; 2048 struct mptsas_phyinfo *phy_info = NULL;
1639 int i; 2049 int i;
1640 2050
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); 2051 mutex_lock(&ioc->sas_topology_mutex);
1646 list_for_each_entry(port_info, &ioc->sas_topology, list) { 2052 list_for_each_entry(port_info, &ioc->sas_topology, list) {
1647 for (i = 0; i < port_info->num_phys; i++) 2053 for (i = 0; i < port_info->num_phys; i++) {
1648 if (mptsas_is_end_device(&port_info->phy_info[i].attached)) 2054 if (port_info->phy_info[i].attached.id != id)
1649 if (port_info->phy_info[i].attached.id == id) { 2055 continue;
1650 phy_info = &port_info->phy_info[i]; 2056 if (!mptsas_is_end_device(
1651 break; 2057 &port_info->phy_info[i].attached))
1652 } 2058 continue;
2059 phy_info = &port_info->phy_info[i];
2060 break;
2061 }
1653 } 2062 }
1654 mutex_unlock(&ioc->sas_topology_mutex); 2063 mutex_unlock(&ioc->sas_topology_mutex);
1655
1656 return phy_info; 2064 return phy_info;
1657} 2065}
1658 2066
@@ -1660,7 +2068,7 @@ mptsas_find_phyinfo_by_target(MPT_ADAPTER *ioc, u32 id)
1660 * Work queue thread to clear the persitency table 2068 * Work queue thread to clear the persitency table
1661 */ 2069 */
1662static void 2070static void
1663mptscsih_sas_persist_clear_table(void * arg) 2071mptsas_persist_clear_table(void * arg)
1664{ 2072{
1665 MPT_ADAPTER *ioc = (MPT_ADAPTER *)arg; 2073 MPT_ADAPTER *ioc = (MPT_ADAPTER *)arg;
1666 2074
@@ -1681,7 +2089,6 @@ mptsas_reprobe_target(struct scsi_target *starget, int uld_attach)
1681 mptsas_reprobe_lun); 2089 mptsas_reprobe_lun);
1682} 2090}
1683 2091
1684
1685/* 2092/*
1686 * Work queue thread to handle SAS hotplug events 2093 * Work queue thread to handle SAS hotplug events
1687 */ 2094 */
@@ -1692,14 +2099,17 @@ mptsas_hotplug_work(void *arg)
1692 MPT_ADAPTER *ioc = ev->ioc; 2099 MPT_ADAPTER *ioc = ev->ioc;
1693 struct mptsas_phyinfo *phy_info; 2100 struct mptsas_phyinfo *phy_info;
1694 struct sas_rphy *rphy; 2101 struct sas_rphy *rphy;
2102 struct sas_port *port;
1695 struct scsi_device *sdev; 2103 struct scsi_device *sdev;
2104 struct scsi_target * starget;
1696 struct sas_identify identify; 2105 struct sas_identify identify;
1697 char *ds = NULL; 2106 char *ds = NULL;
1698 struct mptsas_devinfo sas_device; 2107 struct mptsas_devinfo sas_device;
1699 VirtTarget *vtarget; 2108 VirtTarget *vtarget;
2109 VirtDevice *vdevice;
1700 2110
1701 mutex_lock(&ioc->sas_discovery_mutex);
1702 2111
2112 mutex_lock(&ioc->sas_discovery_mutex);
1703 switch (ev->event_type) { 2113 switch (ev->event_type) {
1704 case MPTSAS_DEL_DEVICE: 2114 case MPTSAS_DEL_DEVICE:
1705 2115
@@ -1708,24 +2118,50 @@ mptsas_hotplug_work(void *arg)
1708 /* 2118 /*
1709 * Sanity checks, for non-existing phys and remote rphys. 2119 * Sanity checks, for non-existing phys and remote rphys.
1710 */ 2120 */
1711 if (!phy_info) 2121 if (!phy_info || !phy_info->port_details) {
2122 dfailprintk((MYIOC_s_ERR_FMT
2123 "%s: exit at line=%d\n", ioc->name,
2124 __FUNCTION__, __LINE__));
1712 break; 2125 break;
1713 if (!phy_info->rphy) 2126 }
2127 rphy = mptsas_get_rphy(phy_info);
2128 if (!rphy) {
2129 dfailprintk((MYIOC_s_ERR_FMT
2130 "%s: exit at line=%d\n", ioc->name,
2131 __FUNCTION__, __LINE__));
2132 break;
2133 }
2134 port = mptsas_get_port(phy_info);
2135 if (!port) {
2136 dfailprintk((MYIOC_s_ERR_FMT
2137 "%s: exit at line=%d\n", ioc->name,
2138 __FUNCTION__, __LINE__));
1714 break; 2139 break;
1715 if (phy_info->starget) { 2140 }
1716 vtarget = phy_info->starget->hostdata; 2141
2142 starget = mptsas_get_starget(phy_info);
2143 if (starget) {
2144 vtarget = starget->hostdata;
1717 2145
1718 if (!vtarget) 2146 if (!vtarget) {
2147 dfailprintk((MYIOC_s_ERR_FMT
2148 "%s: exit at line=%d\n", ioc->name,
2149 __FUNCTION__, __LINE__));
1719 break; 2150 break;
2151 }
2152
1720 /* 2153 /*
1721 * Handling RAID components 2154 * Handling RAID components
1722 */ 2155 */
1723 if (ev->phys_disk_num_valid) { 2156 if (ev->phys_disk_num_valid) {
1724 vtarget->target_id = ev->phys_disk_num; 2157 vtarget->target_id = ev->phys_disk_num;
1725 vtarget->tflags |= MPT_TARGET_FLAGS_RAID_COMPONENT; 2158 vtarget->tflags |= MPT_TARGET_FLAGS_RAID_COMPONENT;
1726 mptsas_reprobe_target(vtarget->starget, 1); 2159 mptsas_reprobe_target(starget, 1);
1727 break; 2160 break;
1728 } 2161 }
2162
2163 vtarget->deleted = 1;
2164 mptsas_target_reset(ioc, vtarget);
1729 } 2165 }
1730 2166
1731 if (phy_info->attached.device_info & MPI_SAS_DEVICE_INFO_SSP_TARGET) 2167 if (phy_info->attached.device_info & MPI_SAS_DEVICE_INFO_SSP_TARGET)
@@ -1739,10 +2175,12 @@ mptsas_hotplug_work(void *arg)
1739 "removing %s device, channel %d, id %d, phy %d\n", 2175 "removing %s device, channel %d, id %d, phy %d\n",
1740 ioc->name, ds, ev->channel, ev->id, phy_info->phy_id); 2176 ioc->name, ds, ev->channel, ev->id, phy_info->phy_id);
1741 2177
1742 sas_rphy_delete(phy_info->rphy); 2178#ifdef MPT_DEBUG_SAS_WIDE
1743 memset(&phy_info->attached, 0, sizeof(struct mptsas_devinfo)); 2179 dev_printk(KERN_DEBUG, &port->dev,
1744 phy_info->rphy = NULL; 2180 "delete port (%d)\n", port->port_identifier);
1745 phy_info->starget = NULL; 2181#endif
2182 sas_port_delete(port);
2183 mptsas_port_delete(phy_info->port_details);
1746 break; 2184 break;
1747 case MPTSAS_ADD_DEVICE: 2185 case MPTSAS_ADD_DEVICE:
1748 2186
@@ -1754,59 +2192,60 @@ mptsas_hotplug_work(void *arg)
1754 */ 2192 */
1755 if (mptsas_sas_device_pg0(ioc, &sas_device, 2193 if (mptsas_sas_device_pg0(ioc, &sas_device,
1756 (MPI_SAS_DEVICE_PGAD_FORM_BUS_TARGET_ID << 2194 (MPI_SAS_DEVICE_PGAD_FORM_BUS_TARGET_ID <<
1757 MPI_SAS_DEVICE_PGAD_FORM_SHIFT), ev->id)) 2195 MPI_SAS_DEVICE_PGAD_FORM_SHIFT), ev->id)) {
2196 dfailprintk((MYIOC_s_ERR_FMT
2197 "%s: exit at line=%d\n", ioc->name,
2198 __FUNCTION__, __LINE__));
1758 break; 2199 break;
2200 }
1759 2201
1760 phy_info = mptsas_find_phyinfo_by_parent(ioc, 2202 ssleep(2);
1761 sas_device.handle_parent, sas_device.phy_id); 2203 __mptsas_discovery_work(ioc);
1762 2204
1763 if (!phy_info) { 2205 phy_info = mptsas_find_phyinfo_by_sas_address(ioc,
1764 u32 handle = 0xFFFF; 2206 sas_device.sas_address);
1765 2207
1766 /* 2208 if (!phy_info || !phy_info->port_details) {
1767 * Its possible when an expander has been hot added 2209 dfailprintk((MYIOC_s_ERR_FMT
1768 * containing attached devices, the sas firmware 2210 "%s: exit at line=%d\n", ioc->name,
1769 * may send a RC_ADDED event prior to the 2211 __FUNCTION__, __LINE__));
1770 * DISCOVERY STOP event. If that occurs, our 2212 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 } 2213 }
1791 2214
1792 if (phy_info->starget) { 2215 starget = mptsas_get_starget(phy_info);
1793 vtarget = phy_info->starget->hostdata; 2216 if (starget) {
2217 vtarget = starget->hostdata;
1794 2218
1795 if (!vtarget) 2219 if (!vtarget) {
2220 dfailprintk((MYIOC_s_ERR_FMT
2221 "%s: exit at line=%d\n", ioc->name,
2222 __FUNCTION__, __LINE__));
1796 break; 2223 break;
2224 }
1797 /* 2225 /*
1798 * Handling RAID components 2226 * Handling RAID components
1799 */ 2227 */
1800 if (vtarget->tflags & MPT_TARGET_FLAGS_RAID_COMPONENT) { 2228 if (vtarget->tflags & MPT_TARGET_FLAGS_RAID_COMPONENT) {
1801 vtarget->tflags &= ~MPT_TARGET_FLAGS_RAID_COMPONENT; 2229 vtarget->tflags &= ~MPT_TARGET_FLAGS_RAID_COMPONENT;
1802 vtarget->target_id = ev->id; 2230 vtarget->target_id = ev->id;
1803 mptsas_reprobe_target(phy_info->starget, 0); 2231 mptsas_reprobe_target(starget, 0);
1804 } 2232 }
1805 break; 2233 break;
1806 } 2234 }
1807 2235
1808 if (phy_info->rphy) 2236 if (mptsas_get_rphy(phy_info)) {
2237 dfailprintk((MYIOC_s_ERR_FMT
2238 "%s: exit at line=%d\n", ioc->name,
2239 __FUNCTION__, __LINE__));
1809 break; 2240 break;
2241 }
2242 port = mptsas_get_port(phy_info);
2243 if (!port) {
2244 dfailprintk((MYIOC_s_ERR_FMT
2245 "%s: exit at line=%d\n", ioc->name,
2246 __FUNCTION__, __LINE__));
2247 break;
2248 }
1810 2249
1811 memcpy(&phy_info->attached, &sas_device, 2250 memcpy(&phy_info->attached, &sas_device,
1812 sizeof(struct mptsas_devinfo)); 2251 sizeof(struct mptsas_devinfo));
@@ -1823,59 +2262,48 @@ mptsas_hotplug_work(void *arg)
1823 ioc->name, ds, ev->channel, ev->id, ev->phy_id); 2262 ioc->name, ds, ev->channel, ev->id, ev->phy_id);
1824 2263
1825 mptsas_parse_device_info(&identify, &phy_info->attached); 2264 mptsas_parse_device_info(&identify, &phy_info->attached);
1826 switch (identify.device_type) { 2265 rphy = sas_end_device_alloc(port);
1827 case SAS_END_DEVICE: 2266 if (!rphy) {
1828 rphy = sas_end_device_alloc(phy_info->phy); 2267 dfailprintk((MYIOC_s_ERR_FMT
1829 break; 2268 "%s: exit at line=%d\n", ioc->name,
1830 case SAS_EDGE_EXPANDER_DEVICE: 2269 __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 */ 2270 break; /* non-fatal: an rphy can be added later */
2271 }
1840 2272
1841 rphy->identify = identify; 2273 rphy->identify = identify;
1842 if (sas_rphy_add(rphy)) { 2274 if (sas_rphy_add(rphy)) {
2275 dfailprintk((MYIOC_s_ERR_FMT
2276 "%s: exit at line=%d\n", ioc->name,
2277 __FUNCTION__, __LINE__));
1843 sas_rphy_free(rphy); 2278 sas_rphy_free(rphy);
1844 break; 2279 break;
1845 } 2280 }
1846 2281 mptsas_set_rphy(phy_info, rphy);
1847 phy_info->rphy = rphy;
1848 break; 2282 break;
1849 case MPTSAS_ADD_RAID: 2283 case MPTSAS_ADD_RAID:
1850 sdev = scsi_device_lookup( 2284 sdev = scsi_device_lookup(ioc->sh, MPTSAS_RAID_CHANNEL,
1851 ioc->sh, 2285 ev->id, 0);
1852 ioc->num_ports,
1853 ev->id,
1854 0);
1855 if (sdev) { 2286 if (sdev) {
1856 scsi_device_put(sdev); 2287 scsi_device_put(sdev);
1857 break; 2288 break;
1858 } 2289 }
1859 printk(MYIOC_s_INFO_FMT 2290 printk(MYIOC_s_INFO_FMT
1860 "attaching raid volume, channel %d, id %d\n", 2291 "attaching raid volume, channel %d, id %d\n",
1861 ioc->name, ioc->num_ports, ev->id); 2292 ioc->name, MPTSAS_RAID_CHANNEL, ev->id);
1862 scsi_add_device(ioc->sh, 2293 scsi_add_device(ioc->sh, MPTSAS_RAID_CHANNEL, ev->id, 0);
1863 ioc->num_ports,
1864 ev->id,
1865 0);
1866 mpt_findImVolumes(ioc); 2294 mpt_findImVolumes(ioc);
1867 break; 2295 break;
1868 case MPTSAS_DEL_RAID: 2296 case MPTSAS_DEL_RAID:
1869 sdev = scsi_device_lookup( 2297 sdev = scsi_device_lookup(ioc->sh, MPTSAS_RAID_CHANNEL,
1870 ioc->sh, 2298 ev->id, 0);
1871 ioc->num_ports,
1872 ev->id,
1873 0);
1874 if (!sdev) 2299 if (!sdev)
1875 break; 2300 break;
1876 printk(MYIOC_s_INFO_FMT 2301 printk(MYIOC_s_INFO_FMT
1877 "removing raid volume, channel %d, id %d\n", 2302 "removing raid volume, channel %d, id %d\n",
1878 ioc->name, ioc->num_ports, ev->id); 2303 ioc->name, MPTSAS_RAID_CHANNEL, ev->id);
2304 vdevice = sdev->hostdata;
2305 vdevice->vtarget->deleted = 1;
2306 mptsas_target_reset(ioc, vdevice->vtarget);
1879 scsi_remove_device(sdev); 2307 scsi_remove_device(sdev);
1880 scsi_device_put(sdev); 2308 scsi_device_put(sdev);
1881 mpt_findImVolumes(ioc); 2309 mpt_findImVolumes(ioc);
@@ -1885,12 +2313,13 @@ mptsas_hotplug_work(void *arg)
1885 break; 2313 break;
1886 } 2314 }
1887 2315
1888 kfree(ev);
1889 mutex_unlock(&ioc->sas_discovery_mutex); 2316 mutex_unlock(&ioc->sas_discovery_mutex);
2317 kfree(ev);
2318
1890} 2319}
1891 2320
1892static void 2321static void
1893mptscsih_send_sas_event(MPT_ADAPTER *ioc, 2322mptsas_send_sas_event(MPT_ADAPTER *ioc,
1894 EVENT_DATA_SAS_DEVICE_STATUS_CHANGE *sas_event_data) 2323 EVENT_DATA_SAS_DEVICE_STATUS_CHANGE *sas_event_data)
1895{ 2324{
1896 struct mptsas_hotplug_event *ev; 2325 struct mptsas_hotplug_event *ev;
@@ -1906,7 +2335,7 @@ mptscsih_send_sas_event(MPT_ADAPTER *ioc,
1906 switch (sas_event_data->ReasonCode) { 2335 switch (sas_event_data->ReasonCode) {
1907 case MPI_EVENT_SAS_DEV_STAT_RC_ADDED: 2336 case MPI_EVENT_SAS_DEV_STAT_RC_ADDED:
1908 case MPI_EVENT_SAS_DEV_STAT_RC_NOT_RESPONDING: 2337 case MPI_EVENT_SAS_DEV_STAT_RC_NOT_RESPONDING:
1909 ev = kmalloc(sizeof(*ev), GFP_ATOMIC); 2338 ev = kzalloc(sizeof(*ev), GFP_ATOMIC);
1910 if (!ev) { 2339 if (!ev) {
1911 printk(KERN_WARNING "mptsas: lost hotplug event\n"); 2340 printk(KERN_WARNING "mptsas: lost hotplug event\n");
1912 break; 2341 break;
@@ -1936,10 +2365,9 @@ mptscsih_send_sas_event(MPT_ADAPTER *ioc,
1936 /* 2365 /*
1937 * Persistent table is full. 2366 * Persistent table is full.
1938 */ 2367 */
1939 INIT_WORK(&ioc->mptscsih_persistTask, 2368 INIT_WORK(&ioc->sas_persist_task,
1940 mptscsih_sas_persist_clear_table, 2369 mptsas_persist_clear_table, (void *)ioc);
1941 (void *)ioc); 2370 schedule_work(&ioc->sas_persist_task);
1942 schedule_work(&ioc->mptscsih_persistTask);
1943 break; 2371 break;
1944 case MPI_EVENT_SAS_DEV_STAT_RC_SMART_DATA: 2372 case MPI_EVENT_SAS_DEV_STAT_RC_SMART_DATA:
1945 /* TODO */ 2373 /* TODO */
@@ -1951,7 +2379,7 @@ mptscsih_send_sas_event(MPT_ADAPTER *ioc,
1951} 2379}
1952 2380
1953static void 2381static void
1954mptscsih_send_raid_event(MPT_ADAPTER *ioc, 2382mptsas_send_raid_event(MPT_ADAPTER *ioc,
1955 EVENT_DATA_RAID *raid_event_data) 2383 EVENT_DATA_RAID *raid_event_data)
1956{ 2384{
1957 struct mptsas_hotplug_event *ev; 2385 struct mptsas_hotplug_event *ev;
@@ -1961,13 +2389,12 @@ mptscsih_send_raid_event(MPT_ADAPTER *ioc,
1961 if (ioc->bus_type != SAS) 2389 if (ioc->bus_type != SAS)
1962 return; 2390 return;
1963 2391
1964 ev = kmalloc(sizeof(*ev), GFP_ATOMIC); 2392 ev = kzalloc(sizeof(*ev), GFP_ATOMIC);
1965 if (!ev) { 2393 if (!ev) {
1966 printk(KERN_WARNING "mptsas: lost hotplug event\n"); 2394 printk(KERN_WARNING "mptsas: lost hotplug event\n");
1967 return; 2395 return;
1968 } 2396 }
1969 2397
1970 memset(ev,0,sizeof(struct mptsas_hotplug_event));
1971 INIT_WORK(&ev->work, mptsas_hotplug_work, ev); 2398 INIT_WORK(&ev->work, mptsas_hotplug_work, ev);
1972 ev->ioc = ioc; 2399 ev->ioc = ioc;
1973 ev->id = raid_event_data->VolumeID; 2400 ev->id = raid_event_data->VolumeID;
@@ -2029,7 +2456,7 @@ mptscsih_send_raid_event(MPT_ADAPTER *ioc,
2029} 2456}
2030 2457
2031static void 2458static void
2032mptscsih_send_discovery(MPT_ADAPTER *ioc, 2459mptsas_send_discovery_event(MPT_ADAPTER *ioc,
2033 EVENT_DATA_SAS_DISCOVERY *discovery_data) 2460 EVENT_DATA_SAS_DISCOVERY *discovery_data)
2034{ 2461{
2035 struct mptsas_discovery_event *ev; 2462 struct mptsas_discovery_event *ev;
@@ -2044,11 +2471,10 @@ mptscsih_send_discovery(MPT_ADAPTER *ioc,
2044 if (discovery_data->DiscoveryStatus) 2471 if (discovery_data->DiscoveryStatus)
2045 return; 2472 return;
2046 2473
2047 ev = kmalloc(sizeof(*ev), GFP_ATOMIC); 2474 ev = kzalloc(sizeof(*ev), GFP_ATOMIC);
2048 if (!ev) 2475 if (!ev)
2049 return; 2476 return;
2050 memset(ev,0,sizeof(struct mptsas_discovery_event)); 2477 INIT_WORK(&ev->work, mptsas_discovery_work, ev);
2051 INIT_WORK(&ev->work, mptscsih_discovery_work, ev);
2052 ev->ioc = ioc; 2478 ev->ioc = ioc;
2053 schedule_work(&ev->work); 2479 schedule_work(&ev->work);
2054}; 2480};
@@ -2076,21 +2502,21 @@ mptsas_event_process(MPT_ADAPTER *ioc, EventNotificationReply_t *reply)
2076 2502
2077 switch (event) { 2503 switch (event) {
2078 case MPI_EVENT_SAS_DEVICE_STATUS_CHANGE: 2504 case MPI_EVENT_SAS_DEVICE_STATUS_CHANGE:
2079 mptscsih_send_sas_event(ioc, 2505 mptsas_send_sas_event(ioc,
2080 (EVENT_DATA_SAS_DEVICE_STATUS_CHANGE *)reply->Data); 2506 (EVENT_DATA_SAS_DEVICE_STATUS_CHANGE *)reply->Data);
2081 break; 2507 break;
2082 case MPI_EVENT_INTEGRATED_RAID: 2508 case MPI_EVENT_INTEGRATED_RAID:
2083 mptscsih_send_raid_event(ioc, 2509 mptsas_send_raid_event(ioc,
2084 (EVENT_DATA_RAID *)reply->Data); 2510 (EVENT_DATA_RAID *)reply->Data);
2085 break; 2511 break;
2086 case MPI_EVENT_PERSISTENT_TABLE_FULL: 2512 case MPI_EVENT_PERSISTENT_TABLE_FULL:
2087 INIT_WORK(&ioc->mptscsih_persistTask, 2513 INIT_WORK(&ioc->sas_persist_task,
2088 mptscsih_sas_persist_clear_table, 2514 mptsas_persist_clear_table,
2089 (void *)ioc); 2515 (void *)ioc);
2090 schedule_work(&ioc->mptscsih_persistTask); 2516 schedule_work(&ioc->sas_persist_task);
2091 break; 2517 break;
2092 case MPI_EVENT_SAS_DISCOVERY: 2518 case MPI_EVENT_SAS_DISCOVERY:
2093 mptscsih_send_discovery(ioc, 2519 mptsas_send_discovery_event(ioc,
2094 (EVENT_DATA_SAS_DISCOVERY *)reply->Data); 2520 (EVENT_DATA_SAS_DISCOVERY *)reply->Data);
2095 break; 2521 break;
2096 default: 2522 default:
@@ -2280,7 +2706,6 @@ mptsas_probe(struct pci_dev *pdev, const struct pci_device_id *id)
2280 hd->timer.data = (unsigned long) hd; 2706 hd->timer.data = (unsigned long) hd;
2281 hd->timer.function = mptscsih_timer_expired; 2707 hd->timer.function = mptscsih_timer_expired;
2282 2708
2283 hd->mpt_pq_filter = mpt_pq_filter;
2284 ioc->sas_data.ptClear = mpt_pt_clear; 2709 ioc->sas_data.ptClear = mpt_pt_clear;
2285 2710
2286 if (ioc->sas_data.ptClear==1) { 2711 if (ioc->sas_data.ptClear==1) {
@@ -2288,12 +2713,6 @@ mptsas_probe(struct pci_dev *pdev, const struct pci_device_id *id)
2288 ioc, MPI_SAS_OP_CLEAR_ALL_PERSISTENT); 2713 ioc, MPI_SAS_OP_CLEAR_ALL_PERSISTENT);
2289 } 2714 }
2290 2715
2291 ddvprintk((MYIOC_s_INFO_FMT
2292 "mpt_pq_filter %x mpt_pq_filter %x\n",
2293 ioc->name,
2294 mpt_pq_filter,
2295 mpt_pq_filter));
2296
2297 init_waitqueue_head(&hd->scandv_waitq); 2716 init_waitqueue_head(&hd->scandv_waitq);
2298 hd->scandv_wait_done = 0; 2717 hd->scandv_wait_done = 0;
2299 hd->last_queue_full = 0; 2718 hd->last_queue_full = 0;
@@ -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);
@@ -2336,17 +2757,15 @@ static void __devexit mptsas_remove(struct pci_dev *pdev)
2336} 2757}
2337 2758
2338static struct pci_device_id mptsas_pci_table[] = { 2759static struct pci_device_id mptsas_pci_table[] = {
2339 { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_SAS1064, 2760 { PCI_VENDOR_ID_LSI_LOGIC, MPI_MANUFACTPAGE_DEVID_SAS1064,
2340 PCI_ANY_ID, PCI_ANY_ID },
2341 { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_SAS1066,
2342 PCI_ANY_ID, PCI_ANY_ID }, 2761 PCI_ANY_ID, PCI_ANY_ID },
2343 { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_SAS1068, 2762 { PCI_VENDOR_ID_LSI_LOGIC, MPI_MANUFACTPAGE_DEVID_SAS1068,
2344 PCI_ANY_ID, PCI_ANY_ID }, 2763 PCI_ANY_ID, PCI_ANY_ID },
2345 { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_SAS1064E, 2764 { PCI_VENDOR_ID_LSI_LOGIC, MPI_MANUFACTPAGE_DEVID_SAS1064E,
2346 PCI_ANY_ID, PCI_ANY_ID }, 2765 PCI_ANY_ID, PCI_ANY_ID },
2347 { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_SAS1066E, 2766 { PCI_VENDOR_ID_LSI_LOGIC, MPI_MANUFACTPAGE_DEVID_SAS1068E,
2348 PCI_ANY_ID, PCI_ANY_ID }, 2767 PCI_ANY_ID, PCI_ANY_ID },
2349 { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_SAS1068E, 2768 { PCI_VENDOR_ID_LSI_LOGIC, MPI_MANUFACTPAGE_DEVID_SAS1078,
2350 PCI_ANY_ID, PCI_ANY_ID }, 2769 PCI_ANY_ID, PCI_ANY_ID },
2351 {0} /* Terminating entry */ 2770 {0} /* Terminating entry */
2352}; 2771};