Christoph Hellwig | 0c33b27 | 2005-09-09 16:27:19 +0200 | [diff] [blame] | 1 | /* |
| 2 | * linux/drivers/message/fusion/mptsas.c |
Prakash, Sathya | f36789e | 2007-08-14 16:22:54 +0530 | [diff] [blame] | 3 | * For use with LSI PCI chip/adapter(s) |
| 4 | * running LSI Fusion MPT (Message Passing Technology) firmware. |
Christoph Hellwig | 0c33b27 | 2005-09-09 16:27:19 +0200 | [diff] [blame] | 5 | * |
Prakash, Sathya | cddc0ab | 2008-05-21 00:56:41 +0530 | [diff] [blame] | 6 | * Copyright (c) 1999-2008 LSI Corporation |
Eric Moore | 16d2010 | 2007-06-13 16:31:07 -0600 | [diff] [blame] | 7 | * (mailto:DL-MPTFusionLinux@lsi.com) |
Christoph Hellwig | 0c33b27 | 2005-09-09 16:27:19 +0200 | [diff] [blame] | 8 | */ |
| 9 | /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/ |
| 10 | /* |
| 11 | This program is free software; you can redistribute it and/or modify |
| 12 | it under the terms of the GNU General Public License as published by |
| 13 | the Free Software Foundation; version 2 of the License. |
| 14 | |
| 15 | This program is distributed in the hope that it will be useful, |
| 16 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 18 | GNU General Public License for more details. |
| 19 | |
| 20 | NO WARRANTY |
| 21 | THE PROGRAM IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR |
| 22 | CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT |
| 23 | LIMITATION, ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT, |
| 24 | MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Each Recipient is |
| 25 | solely responsible for determining the appropriateness of using and |
| 26 | distributing the Program and assumes all risks associated with its |
| 27 | exercise of rights under this Agreement, including but not limited to |
| 28 | the risks and costs of program errors, damage to or loss of data, |
| 29 | programs or equipment, and unavailability or interruption of operations. |
| 30 | |
| 31 | DISCLAIMER OF LIABILITY |
| 32 | NEITHER RECIPIENT NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY |
| 33 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
| 34 | DAMAGES (INCLUDING WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND |
| 35 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR |
| 36 | TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE |
| 37 | USE OR DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS GRANTED |
| 38 | HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES |
| 39 | |
| 40 | You should have received a copy of the GNU General Public License |
| 41 | along with this program; if not, write to the Free Software |
| 42 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 43 | */ |
| 44 | /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/ |
| 45 | |
| 46 | #include <linux/module.h> |
| 47 | #include <linux/kernel.h> |
| 48 | #include <linux/init.h> |
| 49 | #include <linux/errno.h> |
Tim Schmielau | cd354f1 | 2007-02-14 00:33:14 -0800 | [diff] [blame] | 50 | #include <linux/jiffies.h> |
Christoph Hellwig | 0c33b27 | 2005-09-09 16:27:19 +0200 | [diff] [blame] | 51 | #include <linux/workqueue.h> |
Eric Moore | 547f9a2 | 2006-06-27 14:42:12 -0600 | [diff] [blame] | 52 | #include <linux/delay.h> /* for mdelay */ |
Christoph Hellwig | 0c33b27 | 2005-09-09 16:27:19 +0200 | [diff] [blame] | 53 | |
Eric Moore | 547f9a2 | 2006-06-27 14:42:12 -0600 | [diff] [blame] | 54 | #include <scsi/scsi.h> |
Christoph Hellwig | 0c33b27 | 2005-09-09 16:27:19 +0200 | [diff] [blame] | 55 | #include <scsi/scsi_cmnd.h> |
| 56 | #include <scsi/scsi_device.h> |
| 57 | #include <scsi/scsi_host.h> |
| 58 | #include <scsi/scsi_transport_sas.h> |
Eric Moore | 547f9a2 | 2006-06-27 14:42:12 -0600 | [diff] [blame] | 59 | #include <scsi/scsi_dbg.h> |
Christoph Hellwig | 0c33b27 | 2005-09-09 16:27:19 +0200 | [diff] [blame] | 60 | |
| 61 | #include "mptbase.h" |
| 62 | #include "mptscsih.h" |
Prakash, Sathya | 56af97a | 2007-08-14 16:15:38 +0530 | [diff] [blame] | 63 | #include "mptsas.h" |
Christoph Hellwig | 0c33b27 | 2005-09-09 16:27:19 +0200 | [diff] [blame] | 64 | |
| 65 | |
| 66 | #define my_NAME "Fusion MPT SAS Host driver" |
| 67 | #define my_VERSION MPT_LINUX_VERSION_COMMON |
| 68 | #define MYNAM "mptsas" |
| 69 | |
James Bottomley | e8bf394 | 2006-07-11 17:49:34 -0400 | [diff] [blame] | 70 | /* |
| 71 | * Reserved channel for integrated raid |
| 72 | */ |
| 73 | #define MPTSAS_RAID_CHANNEL 1 |
| 74 | |
Christoph Hellwig | 0c33b27 | 2005-09-09 16:27:19 +0200 | [diff] [blame] | 75 | MODULE_AUTHOR(MODULEAUTHOR); |
| 76 | MODULE_DESCRIPTION(my_NAME); |
| 77 | MODULE_LICENSE("GPL"); |
Eric Moore | 9f4203b | 2007-01-04 20:47:47 -0700 | [diff] [blame] | 78 | MODULE_VERSION(my_VERSION); |
Christoph Hellwig | 0c33b27 | 2005-09-09 16:27:19 +0200 | [diff] [blame] | 79 | |
Christoph Hellwig | 0c33b27 | 2005-09-09 16:27:19 +0200 | [diff] [blame] | 80 | static int mpt_pt_clear; |
| 81 | module_param(mpt_pt_clear, int, 0); |
| 82 | MODULE_PARM_DESC(mpt_pt_clear, |
Eric Moore | ba856d3 | 2006-07-11 17:34:01 -0600 | [diff] [blame] | 83 | " Clear persistency table: enable=1 " |
Christoph Hellwig | 0c33b27 | 2005-09-09 16:27:19 +0200 | [diff] [blame] | 84 | "(default=MPTSCSIH_PT_CLEAR=0)"); |
| 85 | |
Eric Moore | 793955f | 2007-01-29 09:42:20 -0700 | [diff] [blame] | 86 | /* scsi-mid layer global parmeter is max_report_luns, which is 511 */ |
| 87 | #define MPTSAS_MAX_LUN (16895) |
| 88 | static int max_lun = MPTSAS_MAX_LUN; |
| 89 | module_param(max_lun, int, 0); |
| 90 | MODULE_PARM_DESC(max_lun, " max lun, default=16895 "); |
| 91 | |
Prakash, Sathya | f606f57 | 2007-08-14 16:12:53 +0530 | [diff] [blame] | 92 | static u8 mptsasDoneCtx = MPT_MAX_PROTOCOL_DRIVERS; |
| 93 | static u8 mptsasTaskCtx = MPT_MAX_PROTOCOL_DRIVERS; |
| 94 | static u8 mptsasInternalCtx = MPT_MAX_PROTOCOL_DRIVERS; /* Used only for internal commands */ |
| 95 | static u8 mptsasMgmtCtx = MPT_MAX_PROTOCOL_DRIVERS; |
Kashyap, Desai | e7deff3 | 2009-05-29 16:46:07 +0530 | [diff] [blame] | 96 | static u8 mptsasDeviceResetCtx = MPT_MAX_PROTOCOL_DRIVERS; |
Christoph Hellwig | 0c33b27 | 2005-09-09 16:27:19 +0200 | [diff] [blame] | 97 | |
Kashyap, Desai | 3eb0822c | 2009-05-29 16:47:26 +0530 | [diff] [blame] | 98 | static void mptsas_firmware_event_work(struct work_struct *work); |
| 99 | static void mptsas_send_sas_event(struct fw_event_work *fw_event); |
| 100 | static void mptsas_send_raid_event(struct fw_event_work *fw_event); |
| 101 | static void mptsas_send_ir2_event(struct fw_event_work *fw_event); |
| 102 | static void mptsas_parse_device_info(struct sas_identify *identify, |
| 103 | struct mptsas_devinfo *device_info); |
| 104 | static inline void mptsas_set_rphy(MPT_ADAPTER *ioc, |
| 105 | struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy); |
| 106 | static struct mptsas_phyinfo *mptsas_find_phyinfo_by_sas_address |
| 107 | (MPT_ADAPTER *ioc, u64 sas_address); |
| 108 | static int mptsas_sas_device_pg0(MPT_ADAPTER *ioc, |
| 109 | struct mptsas_devinfo *device_info, u32 form, u32 form_specific); |
| 110 | static int mptsas_sas_enclosure_pg0(MPT_ADAPTER *ioc, |
| 111 | struct mptsas_enclosure *enclosure, u32 form, u32 form_specific); |
| 112 | static int mptsas_add_end_device(MPT_ADAPTER *ioc, |
| 113 | struct mptsas_phyinfo *phy_info); |
| 114 | static void mptsas_del_end_device(MPT_ADAPTER *ioc, |
| 115 | struct mptsas_phyinfo *phy_info); |
Kashyap, Desai | f9c3402 | 2009-05-29 16:49:36 +0530 | [diff] [blame] | 116 | static void mptsas_send_link_status_event(struct fw_event_work *fw_event); |
| 117 | static struct mptsas_portinfo *mptsas_find_portinfo_by_sas_address |
| 118 | (MPT_ADAPTER *ioc, u64 sas_address); |
| 119 | static void mptsas_expander_delete(MPT_ADAPTER *ioc, |
| 120 | struct mptsas_portinfo *port_info, u8 force); |
| 121 | static void mptsas_send_expander_event(struct fw_event_work *fw_event); |
Kashyap, Desai | eedf92b | 2009-05-29 16:51:32 +0530 | [diff] [blame] | 122 | static void mptsas_not_responding_devices(MPT_ADAPTER *ioc); |
| 123 | static void mptsas_scan_sas_topology(MPT_ADAPTER *ioc); |
Kashyap, Desai | db7051b | 2009-05-29 16:56:59 +0530 | [diff] [blame^] | 124 | static void mptsas_broadcast_primative_work(struct fw_event_work *fw_event); |
Kashyap, Desai | 57e9851 | 2009-05-29 16:55:09 +0530 | [diff] [blame] | 125 | static void mptsas_handle_queue_full_event(struct fw_event_work *fw_event); |
Kashyap, Desai | a7938b0 | 2009-05-29 16:53:56 +0530 | [diff] [blame] | 126 | static void mptsas_volume_delete(MPT_ADAPTER *ioc, u8 id); |
Christoph Hellwig | 0c33b27 | 2005-09-09 16:27:19 +0200 | [diff] [blame] | 127 | |
Prakash, Sathya | d6ecdd6 | 2007-07-24 15:47:41 +0530 | [diff] [blame] | 128 | static void mptsas_print_phy_data(MPT_ADAPTER *ioc, |
| 129 | MPI_SAS_IO_UNIT0_PHY_DATA *phy_data) |
Christoph Hellwig | b514112 | 2005-10-28 22:07:41 +0200 | [diff] [blame] | 130 | { |
Eric Moore | 29dd360 | 2007-09-14 18:46:51 -0600 | [diff] [blame] | 131 | dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT |
| 132 | "---- IO UNIT PAGE 0 ------------\n", ioc->name)); |
| 133 | dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Handle=0x%X\n", |
| 134 | ioc->name, le16_to_cpu(phy_data->AttachedDeviceHandle))); |
| 135 | dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Controller Handle=0x%X\n", |
| 136 | ioc->name, le16_to_cpu(phy_data->ControllerDevHandle))); |
| 137 | dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Port=0x%X\n", |
| 138 | ioc->name, phy_data->Port)); |
| 139 | dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Port Flags=0x%X\n", |
| 140 | ioc->name, phy_data->PortFlags)); |
| 141 | dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "PHY Flags=0x%X\n", |
| 142 | ioc->name, phy_data->PhyFlags)); |
| 143 | dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Negotiated Link Rate=0x%X\n", |
| 144 | ioc->name, phy_data->NegotiatedLinkRate)); |
| 145 | dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT |
| 146 | "Controller PHY Device Info=0x%X\n", ioc->name, |
| 147 | le32_to_cpu(phy_data->ControllerPhyDeviceInfo))); |
| 148 | dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "DiscoveryStatus=0x%X\n\n", |
| 149 | ioc->name, le32_to_cpu(phy_data->DiscoveryStatus))); |
Christoph Hellwig | b514112 | 2005-10-28 22:07:41 +0200 | [diff] [blame] | 150 | } |
| 151 | |
Prakash, Sathya | d6ecdd6 | 2007-07-24 15:47:41 +0530 | [diff] [blame] | 152 | static void mptsas_print_phy_pg0(MPT_ADAPTER *ioc, SasPhyPage0_t *pg0) |
Christoph Hellwig | b514112 | 2005-10-28 22:07:41 +0200 | [diff] [blame] | 153 | { |
| 154 | __le64 sas_address; |
| 155 | |
| 156 | memcpy(&sas_address, &pg0->SASAddress, sizeof(__le64)); |
| 157 | |
Eric Moore | 29dd360 | 2007-09-14 18:46:51 -0600 | [diff] [blame] | 158 | dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT |
| 159 | "---- SAS PHY PAGE 0 ------------\n", ioc->name)); |
| 160 | dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT |
| 161 | "Attached Device Handle=0x%X\n", ioc->name, |
| 162 | le16_to_cpu(pg0->AttachedDevHandle))); |
| 163 | dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "SAS Address=0x%llX\n", |
| 164 | ioc->name, (unsigned long long)le64_to_cpu(sas_address))); |
| 165 | dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT |
| 166 | "Attached PHY Identifier=0x%X\n", ioc->name, |
| 167 | pg0->AttachedPhyIdentifier)); |
| 168 | dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Attached Device Info=0x%X\n", |
| 169 | ioc->name, le32_to_cpu(pg0->AttachedDeviceInfo))); |
| 170 | dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Programmed Link Rate=0x%X\n", |
| 171 | ioc->name, pg0->ProgrammedLinkRate)); |
| 172 | dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Change Count=0x%X\n", |
| 173 | ioc->name, pg0->ChangeCount)); |
| 174 | dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "PHY Info=0x%X\n\n", |
| 175 | ioc->name, le32_to_cpu(pg0->PhyInfo))); |
Christoph Hellwig | b514112 | 2005-10-28 22:07:41 +0200 | [diff] [blame] | 176 | } |
| 177 | |
Prakash, Sathya | d6ecdd6 | 2007-07-24 15:47:41 +0530 | [diff] [blame] | 178 | static void mptsas_print_phy_pg1(MPT_ADAPTER *ioc, SasPhyPage1_t *pg1) |
Christoph Hellwig | b514112 | 2005-10-28 22:07:41 +0200 | [diff] [blame] | 179 | { |
Eric Moore | 29dd360 | 2007-09-14 18:46:51 -0600 | [diff] [blame] | 180 | dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT |
| 181 | "---- SAS PHY PAGE 1 ------------\n", ioc->name)); |
| 182 | dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Invalid Dword Count=0x%x\n", |
| 183 | ioc->name, pg1->InvalidDwordCount)); |
| 184 | dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT |
| 185 | "Running Disparity Error Count=0x%x\n", ioc->name, |
| 186 | pg1->RunningDisparityErrorCount)); |
| 187 | dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT |
| 188 | "Loss Dword Synch Count=0x%x\n", ioc->name, |
| 189 | pg1->LossDwordSynchCount)); |
| 190 | dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT |
| 191 | "PHY Reset Problem Count=0x%x\n\n", ioc->name, |
| 192 | pg1->PhyResetProblemCount)); |
Christoph Hellwig | b514112 | 2005-10-28 22:07:41 +0200 | [diff] [blame] | 193 | } |
| 194 | |
Prakash, Sathya | d6ecdd6 | 2007-07-24 15:47:41 +0530 | [diff] [blame] | 195 | static void mptsas_print_device_pg0(MPT_ADAPTER *ioc, SasDevicePage0_t *pg0) |
Christoph Hellwig | b514112 | 2005-10-28 22:07:41 +0200 | [diff] [blame] | 196 | { |
| 197 | __le64 sas_address; |
| 198 | |
| 199 | memcpy(&sas_address, &pg0->SASAddress, sizeof(__le64)); |
| 200 | |
Eric Moore | 29dd360 | 2007-09-14 18:46:51 -0600 | [diff] [blame] | 201 | dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT |
| 202 | "---- SAS DEVICE PAGE 0 ---------\n", ioc->name)); |
| 203 | dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Handle=0x%X\n", |
| 204 | ioc->name, le16_to_cpu(pg0->DevHandle))); |
| 205 | dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Parent Handle=0x%X\n", |
| 206 | ioc->name, le16_to_cpu(pg0->ParentDevHandle))); |
| 207 | dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Enclosure Handle=0x%X\n", |
| 208 | ioc->name, le16_to_cpu(pg0->EnclosureHandle))); |
| 209 | dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Slot=0x%X\n", |
| 210 | ioc->name, le16_to_cpu(pg0->Slot))); |
| 211 | dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "SAS Address=0x%llX\n", |
| 212 | ioc->name, (unsigned long long)le64_to_cpu(sas_address))); |
| 213 | dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Target ID=0x%X\n", |
| 214 | ioc->name, pg0->TargetID)); |
| 215 | dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Bus=0x%X\n", |
| 216 | ioc->name, pg0->Bus)); |
| 217 | dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Parent Phy Num=0x%X\n", |
| 218 | ioc->name, pg0->PhyNum)); |
| 219 | dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Access Status=0x%X\n", |
| 220 | ioc->name, le16_to_cpu(pg0->AccessStatus))); |
| 221 | dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Device Info=0x%X\n", |
| 222 | ioc->name, le32_to_cpu(pg0->DeviceInfo))); |
| 223 | dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Flags=0x%X\n", |
| 224 | ioc->name, le16_to_cpu(pg0->Flags))); |
| 225 | dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Physical Port=0x%X\n\n", |
| 226 | ioc->name, pg0->PhysicalPort)); |
Christoph Hellwig | b514112 | 2005-10-28 22:07:41 +0200 | [diff] [blame] | 227 | } |
| 228 | |
Prakash, Sathya | d6ecdd6 | 2007-07-24 15:47:41 +0530 | [diff] [blame] | 229 | static void mptsas_print_expander_pg1(MPT_ADAPTER *ioc, SasExpanderPage1_t *pg1) |
Christoph Hellwig | b514112 | 2005-10-28 22:07:41 +0200 | [diff] [blame] | 230 | { |
Eric Moore | 29dd360 | 2007-09-14 18:46:51 -0600 | [diff] [blame] | 231 | dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT |
| 232 | "---- SAS EXPANDER PAGE 1 ------------\n", ioc->name)); |
| 233 | dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Physical Port=0x%X\n", |
| 234 | ioc->name, pg1->PhysicalPort)); |
| 235 | dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "PHY Identifier=0x%X\n", |
| 236 | ioc->name, pg1->PhyIdentifier)); |
| 237 | dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Negotiated Link Rate=0x%X\n", |
| 238 | ioc->name, pg1->NegotiatedLinkRate)); |
| 239 | dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Programmed Link Rate=0x%X\n", |
| 240 | ioc->name, pg1->ProgrammedLinkRate)); |
| 241 | dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Hardware Link Rate=0x%X\n", |
| 242 | ioc->name, pg1->HwLinkRate)); |
| 243 | dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Owner Device Handle=0x%X\n", |
| 244 | ioc->name, le16_to_cpu(pg1->OwnerDevHandle))); |
| 245 | dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT |
| 246 | "Attached Device Handle=0x%X\n\n", ioc->name, |
| 247 | le16_to_cpu(pg1->AttachedDevHandle))); |
Christoph Hellwig | b514112 | 2005-10-28 22:07:41 +0200 | [diff] [blame] | 248 | } |
Christoph Hellwig | b514112 | 2005-10-28 22:07:41 +0200 | [diff] [blame] | 249 | |
Kashyap, Desai | 3eb0822c | 2009-05-29 16:47:26 +0530 | [diff] [blame] | 250 | /* inhibit sas firmware event handling */ |
| 251 | static void |
| 252 | mptsas_fw_event_off(MPT_ADAPTER *ioc) |
| 253 | { |
| 254 | unsigned long flags; |
| 255 | |
| 256 | spin_lock_irqsave(&ioc->fw_event_lock, flags); |
| 257 | ioc->fw_events_off = 1; |
| 258 | ioc->sas_discovery_quiesce_io = 0; |
| 259 | spin_unlock_irqrestore(&ioc->fw_event_lock, flags); |
| 260 | |
| 261 | } |
| 262 | |
| 263 | /* enable sas firmware event handling */ |
| 264 | static void |
| 265 | mptsas_fw_event_on(MPT_ADAPTER *ioc) |
| 266 | { |
| 267 | unsigned long flags; |
| 268 | |
| 269 | spin_lock_irqsave(&ioc->fw_event_lock, flags); |
| 270 | ioc->fw_events_off = 0; |
| 271 | spin_unlock_irqrestore(&ioc->fw_event_lock, flags); |
| 272 | } |
| 273 | |
| 274 | /* queue a sas firmware event */ |
| 275 | static void |
| 276 | mptsas_add_fw_event(MPT_ADAPTER *ioc, struct fw_event_work *fw_event, |
| 277 | unsigned long delay) |
| 278 | { |
| 279 | unsigned long flags; |
| 280 | |
| 281 | spin_lock_irqsave(&ioc->fw_event_lock, flags); |
| 282 | list_add_tail(&fw_event->list, &ioc->fw_event_list); |
| 283 | INIT_DELAYED_WORK(&fw_event->work, mptsas_firmware_event_work); |
| 284 | devtprintk(ioc, printk(MYIOC_s_DEBUG_FMT "%s: add (fw_event=0x%p)\n", |
| 285 | ioc->name, __func__, fw_event)); |
| 286 | queue_delayed_work(ioc->fw_event_q, &fw_event->work, |
| 287 | delay); |
| 288 | spin_unlock_irqrestore(&ioc->fw_event_lock, flags); |
| 289 | } |
| 290 | |
Kashyap, Desai | db7051b | 2009-05-29 16:56:59 +0530 | [diff] [blame^] | 291 | /* requeue a sas firmware event */ |
| 292 | static void |
| 293 | mptsas_requeue_fw_event(MPT_ADAPTER *ioc, struct fw_event_work *fw_event, |
| 294 | unsigned long delay) |
| 295 | { |
| 296 | unsigned long flags; |
| 297 | spin_lock_irqsave(&ioc->fw_event_lock, flags); |
| 298 | devtprintk(ioc, printk(MYIOC_s_DEBUG_FMT "%s: reschedule task " |
| 299 | "(fw_event=0x%p)\n", ioc->name, __func__, fw_event)); |
| 300 | fw_event->retries++; |
| 301 | queue_delayed_work(ioc->fw_event_q, &fw_event->work, |
| 302 | msecs_to_jiffies(delay)); |
| 303 | spin_unlock_irqrestore(&ioc->fw_event_lock, flags); |
| 304 | } |
| 305 | |
Kashyap, Desai | 3eb0822c | 2009-05-29 16:47:26 +0530 | [diff] [blame] | 306 | /* free memory assoicated to a sas firmware event */ |
| 307 | static void |
| 308 | mptsas_free_fw_event(MPT_ADAPTER *ioc, struct fw_event_work *fw_event) |
| 309 | { |
| 310 | unsigned long flags; |
| 311 | |
| 312 | spin_lock_irqsave(&ioc->fw_event_lock, flags); |
| 313 | devtprintk(ioc, printk(MYIOC_s_DEBUG_FMT "%s: kfree (fw_event=0x%p)\n", |
| 314 | ioc->name, __func__, fw_event)); |
| 315 | list_del(&fw_event->list); |
| 316 | kfree(fw_event); |
| 317 | spin_unlock_irqrestore(&ioc->fw_event_lock, flags); |
| 318 | } |
| 319 | |
| 320 | /* walk the firmware event queue, and either stop or wait for |
| 321 | * outstanding events to complete */ |
| 322 | static void |
| 323 | mptsas_cleanup_fw_event_q(MPT_ADAPTER *ioc) |
| 324 | { |
| 325 | struct fw_event_work *fw_event, *next; |
| 326 | struct mptsas_target_reset_event *target_reset_list, *n; |
| 327 | u8 flush_q; |
| 328 | MPT_SCSI_HOST *hd = shost_priv(ioc->sh); |
| 329 | |
| 330 | /* flush the target_reset_list */ |
| 331 | if (!list_empty(&hd->target_reset_list)) { |
| 332 | list_for_each_entry_safe(target_reset_list, n, |
| 333 | &hd->target_reset_list, list) { |
| 334 | dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT |
| 335 | "%s: removing target reset for id=%d\n", |
| 336 | ioc->name, __func__, |
| 337 | target_reset_list->sas_event_data.TargetID)); |
| 338 | list_del(&target_reset_list->list); |
| 339 | kfree(target_reset_list); |
| 340 | } |
| 341 | } |
| 342 | |
| 343 | if (list_empty(&ioc->fw_event_list) || |
| 344 | !ioc->fw_event_q || in_interrupt()) |
| 345 | return; |
| 346 | |
| 347 | flush_q = 0; |
| 348 | list_for_each_entry_safe(fw_event, next, &ioc->fw_event_list, list) { |
| 349 | if (cancel_delayed_work(&fw_event->work)) |
| 350 | mptsas_free_fw_event(ioc, fw_event); |
| 351 | else |
| 352 | flush_q = 1; |
| 353 | } |
| 354 | if (flush_q) |
| 355 | flush_workqueue(ioc->fw_event_q); |
| 356 | } |
| 357 | |
| 358 | |
Christoph Hellwig | e309444 | 2006-02-16 13:25:36 +0100 | [diff] [blame] | 359 | static inline MPT_ADAPTER *phy_to_ioc(struct sas_phy *phy) |
| 360 | { |
| 361 | struct Scsi_Host *shost = dev_to_shost(phy->dev.parent); |
| 362 | return ((MPT_SCSI_HOST *)shost->hostdata)->ioc; |
| 363 | } |
| 364 | |
| 365 | static inline MPT_ADAPTER *rphy_to_ioc(struct sas_rphy *rphy) |
| 366 | { |
| 367 | struct Scsi_Host *shost = dev_to_shost(rphy->dev.parent->parent); |
| 368 | return ((MPT_SCSI_HOST *)shost->hostdata)->ioc; |
| 369 | } |
| 370 | |
Moore, Eric | e6b2d76 | 2006-03-14 09:14:24 -0700 | [diff] [blame] | 371 | /* |
| 372 | * mptsas_find_portinfo_by_handle |
| 373 | * |
| 374 | * This function should be called with the sas_topology_mutex already held |
| 375 | */ |
| 376 | static struct mptsas_portinfo * |
| 377 | mptsas_find_portinfo_by_handle(MPT_ADAPTER *ioc, u16 handle) |
| 378 | { |
| 379 | struct mptsas_portinfo *port_info, *rc=NULL; |
| 380 | int i; |
| 381 | |
| 382 | list_for_each_entry(port_info, &ioc->sas_topology, list) |
| 383 | for (i = 0; i < port_info->num_phys; i++) |
| 384 | if (port_info->phy_info[i].identify.handle == handle) { |
| 385 | rc = port_info; |
| 386 | goto out; |
| 387 | } |
| 388 | out: |
| 389 | return rc; |
| 390 | } |
| 391 | |
Kashyap, Desai | f9c3402 | 2009-05-29 16:49:36 +0530 | [diff] [blame] | 392 | /** |
| 393 | * mptsas_find_portinfo_by_sas_address - |
| 394 | * @ioc: Pointer to MPT_ADAPTER structure |
| 395 | * @handle: |
| 396 | * |
| 397 | * This function should be called with the sas_topology_mutex already held |
| 398 | * |
| 399 | **/ |
| 400 | static struct mptsas_portinfo * |
| 401 | mptsas_find_portinfo_by_sas_address(MPT_ADAPTER *ioc, u64 sas_address) |
| 402 | { |
| 403 | struct mptsas_portinfo *port_info, *rc = NULL; |
| 404 | int i; |
| 405 | |
| 406 | if (sas_address >= ioc->hba_port_sas_addr && |
| 407 | sas_address < (ioc->hba_port_sas_addr + |
| 408 | ioc->hba_port_num_phy)) |
| 409 | return ioc->hba_port_info; |
| 410 | |
| 411 | mutex_lock(&ioc->sas_topology_mutex); |
| 412 | list_for_each_entry(port_info, &ioc->sas_topology, list) |
| 413 | for (i = 0; i < port_info->num_phys; i++) |
| 414 | if (port_info->phy_info[i].identify.sas_address == |
| 415 | sas_address) { |
| 416 | rc = port_info; |
| 417 | goto out; |
| 418 | } |
| 419 | out: |
| 420 | mutex_unlock(&ioc->sas_topology_mutex); |
| 421 | return rc; |
| 422 | } |
| 423 | |
Moore, Eric | bd23e94 | 2006-04-17 12:43:04 -0600 | [diff] [blame] | 424 | /* |
| 425 | * Returns true if there is a scsi end device |
| 426 | */ |
| 427 | static inline int |
| 428 | mptsas_is_end_device(struct mptsas_devinfo * attached) |
| 429 | { |
Eric Moore | 547f9a2 | 2006-06-27 14:42:12 -0600 | [diff] [blame] | 430 | if ((attached->sas_address) && |
Moore, Eric | bd23e94 | 2006-04-17 12:43:04 -0600 | [diff] [blame] | 431 | (attached->device_info & |
| 432 | MPI_SAS_DEVICE_INFO_END_DEVICE) && |
| 433 | ((attached->device_info & |
| 434 | MPI_SAS_DEVICE_INFO_SSP_TARGET) | |
| 435 | (attached->device_info & |
| 436 | MPI_SAS_DEVICE_INFO_STP_TARGET) | |
| 437 | (attached->device_info & |
| 438 | MPI_SAS_DEVICE_INFO_SATA_DEVICE))) |
| 439 | return 1; |
| 440 | else |
| 441 | return 0; |
| 442 | } |
| 443 | |
Eric Moore | 547f9a2 | 2006-06-27 14:42:12 -0600 | [diff] [blame] | 444 | /* no mutex */ |
Eric Moore | 376ac83 | 2006-06-29 17:36:26 -0600 | [diff] [blame] | 445 | static void |
Prakash, Sathya | d6ecdd6 | 2007-07-24 15:47:41 +0530 | [diff] [blame] | 446 | mptsas_port_delete(MPT_ADAPTER *ioc, struct mptsas_portinfo_details * port_details) |
Eric Moore | 547f9a2 | 2006-06-27 14:42:12 -0600 | [diff] [blame] | 447 | { |
| 448 | struct mptsas_portinfo *port_info; |
| 449 | struct mptsas_phyinfo *phy_info; |
| 450 | u8 i; |
| 451 | |
| 452 | if (!port_details) |
| 453 | return; |
| 454 | |
| 455 | port_info = port_details->port_info; |
| 456 | phy_info = port_info->phy_info; |
| 457 | |
Eric Moore | 29dd360 | 2007-09-14 18:46:51 -0600 | [diff] [blame] | 458 | dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "%s: [%p]: num_phys=%02d " |
Harvey Harrison | cadbd4a | 2008-07-03 23:47:27 -0700 | [diff] [blame] | 459 | "bitmask=0x%016llX\n", ioc->name, __func__, port_details, |
Eric Moore | f99be43 | 2007-01-04 20:46:54 -0700 | [diff] [blame] | 460 | port_details->num_phys, (unsigned long long) |
| 461 | port_details->phy_bitmask)); |
Eric Moore | 547f9a2 | 2006-06-27 14:42:12 -0600 | [diff] [blame] | 462 | |
| 463 | for (i = 0; i < port_info->num_phys; i++, phy_info++) { |
| 464 | if(phy_info->port_details != port_details) |
| 465 | continue; |
| 466 | memset(&phy_info->attached, 0, sizeof(struct mptsas_devinfo)); |
Kashyap, Desai | 3eb0822c | 2009-05-29 16:47:26 +0530 | [diff] [blame] | 467 | mptsas_set_rphy(ioc, phy_info, NULL); |
Eric Moore | 547f9a2 | 2006-06-27 14:42:12 -0600 | [diff] [blame] | 468 | phy_info->port_details = NULL; |
| 469 | } |
| 470 | kfree(port_details); |
| 471 | } |
| 472 | |
| 473 | static inline struct sas_rphy * |
| 474 | mptsas_get_rphy(struct mptsas_phyinfo *phy_info) |
| 475 | { |
| 476 | if (phy_info->port_details) |
| 477 | return phy_info->port_details->rphy; |
| 478 | else |
| 479 | return NULL; |
| 480 | } |
| 481 | |
| 482 | static inline void |
Prakash, Sathya | d6ecdd6 | 2007-07-24 15:47:41 +0530 | [diff] [blame] | 483 | mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy) |
Eric Moore | 547f9a2 | 2006-06-27 14:42:12 -0600 | [diff] [blame] | 484 | { |
| 485 | if (phy_info->port_details) { |
| 486 | phy_info->port_details->rphy = rphy; |
Eric Moore | 29dd360 | 2007-09-14 18:46:51 -0600 | [diff] [blame] | 487 | dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n", |
| 488 | ioc->name, rphy)); |
Eric Moore | 547f9a2 | 2006-06-27 14:42:12 -0600 | [diff] [blame] | 489 | } |
| 490 | |
Eric Moore | 547f9a2 | 2006-06-27 14:42:12 -0600 | [diff] [blame] | 491 | if (rphy) { |
Eric Moore | c51d0be | 2007-09-29 10:17:21 -0600 | [diff] [blame] | 492 | dsaswideprintk(ioc, dev_printk(KERN_DEBUG, |
| 493 | &rphy->dev, MYIOC_s_FMT "add:", ioc->name)); |
Eric Moore | 29dd360 | 2007-09-14 18:46:51 -0600 | [diff] [blame] | 494 | dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n", |
| 495 | ioc->name, rphy, rphy->dev.release)); |
Eric Moore | 547f9a2 | 2006-06-27 14:42:12 -0600 | [diff] [blame] | 496 | } |
Eric Moore | 547f9a2 | 2006-06-27 14:42:12 -0600 | [diff] [blame] | 497 | } |
| 498 | |
| 499 | static inline struct sas_port * |
| 500 | mptsas_get_port(struct mptsas_phyinfo *phy_info) |
| 501 | { |
| 502 | if (phy_info->port_details) |
| 503 | return phy_info->port_details->port; |
| 504 | else |
| 505 | return NULL; |
| 506 | } |
| 507 | |
| 508 | static inline void |
Prakash, Sathya | d6ecdd6 | 2007-07-24 15:47:41 +0530 | [diff] [blame] | 509 | mptsas_set_port(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_port *port) |
Eric Moore | 547f9a2 | 2006-06-27 14:42:12 -0600 | [diff] [blame] | 510 | { |
| 511 | if (phy_info->port_details) |
| 512 | phy_info->port_details->port = port; |
| 513 | |
Eric Moore | 547f9a2 | 2006-06-27 14:42:12 -0600 | [diff] [blame] | 514 | if (port) { |
Eric Moore | c51d0be | 2007-09-29 10:17:21 -0600 | [diff] [blame] | 515 | dsaswideprintk(ioc, dev_printk(KERN_DEBUG, |
| 516 | &port->dev, MYIOC_s_FMT "add:", ioc->name)); |
Eric Moore | 29dd360 | 2007-09-14 18:46:51 -0600 | [diff] [blame] | 517 | dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "port=%p release=%p\n", |
| 518 | ioc->name, port, port->dev.release)); |
Eric Moore | 547f9a2 | 2006-06-27 14:42:12 -0600 | [diff] [blame] | 519 | } |
Eric Moore | 547f9a2 | 2006-06-27 14:42:12 -0600 | [diff] [blame] | 520 | } |
| 521 | |
| 522 | static inline struct scsi_target * |
| 523 | mptsas_get_starget(struct mptsas_phyinfo *phy_info) |
| 524 | { |
| 525 | if (phy_info->port_details) |
| 526 | return phy_info->port_details->starget; |
| 527 | else |
| 528 | return NULL; |
| 529 | } |
| 530 | |
| 531 | static inline void |
| 532 | mptsas_set_starget(struct mptsas_phyinfo *phy_info, struct scsi_target * |
| 533 | starget) |
| 534 | { |
| 535 | if (phy_info->port_details) |
| 536 | phy_info->port_details->starget = starget; |
| 537 | } |
| 538 | |
Kashyap, Desai | 3eb0822c | 2009-05-29 16:47:26 +0530 | [diff] [blame] | 539 | /** |
| 540 | * mptsas_add_device_component - |
| 541 | * @ioc: Pointer to MPT_ADAPTER structure |
| 542 | * @channel: fw mapped id's |
| 543 | * @id: |
| 544 | * @sas_address: |
| 545 | * @device_info: |
| 546 | * |
| 547 | **/ |
| 548 | static void |
| 549 | mptsas_add_device_component(MPT_ADAPTER *ioc, u8 channel, u8 id, |
| 550 | u64 sas_address, u32 device_info, u16 slot, u64 enclosure_logical_id) |
| 551 | { |
| 552 | struct mptsas_device_info *sas_info, *next; |
| 553 | struct scsi_device *sdev; |
| 554 | struct scsi_target *starget; |
| 555 | struct sas_rphy *rphy; |
| 556 | |
| 557 | /* |
| 558 | * Delete all matching devices out of the list |
| 559 | */ |
| 560 | mutex_lock(&ioc->sas_device_info_mutex); |
| 561 | list_for_each_entry_safe(sas_info, next, &ioc->sas_device_info_list, |
| 562 | list) { |
Kashyap, Desai | a7938b0 | 2009-05-29 16:53:56 +0530 | [diff] [blame] | 563 | if (!sas_info->is_logical_volume && |
| 564 | (sas_info->sas_address == sas_address || |
| 565 | (sas_info->fw.channel == channel && |
| 566 | sas_info->fw.id == id))) { |
Kashyap, Desai | 3eb0822c | 2009-05-29 16:47:26 +0530 | [diff] [blame] | 567 | list_del(&sas_info->list); |
| 568 | kfree(sas_info); |
| 569 | } |
| 570 | } |
| 571 | |
| 572 | sas_info = kzalloc(sizeof(struct mptsas_device_info), GFP_KERNEL); |
| 573 | if (!sas_info) |
| 574 | goto out; |
| 575 | |
| 576 | /* |
| 577 | * Set Firmware mapping |
| 578 | */ |
| 579 | sas_info->fw.id = id; |
| 580 | sas_info->fw.channel = channel; |
| 581 | |
| 582 | sas_info->sas_address = sas_address; |
| 583 | sas_info->device_info = device_info; |
| 584 | sas_info->slot = slot; |
| 585 | sas_info->enclosure_logical_id = enclosure_logical_id; |
| 586 | INIT_LIST_HEAD(&sas_info->list); |
| 587 | list_add_tail(&sas_info->list, &ioc->sas_device_info_list); |
| 588 | |
| 589 | /* |
| 590 | * Set OS mapping |
| 591 | */ |
| 592 | shost_for_each_device(sdev, ioc->sh) { |
| 593 | starget = scsi_target(sdev); |
| 594 | rphy = dev_to_rphy(starget->dev.parent); |
| 595 | if (rphy->identify.sas_address == sas_address) { |
| 596 | sas_info->os.id = starget->id; |
| 597 | sas_info->os.channel = starget->channel; |
| 598 | } |
| 599 | } |
| 600 | |
| 601 | out: |
| 602 | mutex_unlock(&ioc->sas_device_info_mutex); |
| 603 | return; |
| 604 | } |
| 605 | |
| 606 | /** |
| 607 | * mptsas_add_device_component_by_fw - |
| 608 | * @ioc: Pointer to MPT_ADAPTER structure |
| 609 | * @channel: fw mapped id's |
| 610 | * @id: |
| 611 | * |
| 612 | **/ |
| 613 | static void |
| 614 | mptsas_add_device_component_by_fw(MPT_ADAPTER *ioc, u8 channel, u8 id) |
| 615 | { |
| 616 | struct mptsas_devinfo sas_device; |
| 617 | struct mptsas_enclosure enclosure_info; |
| 618 | int rc; |
| 619 | |
| 620 | rc = mptsas_sas_device_pg0(ioc, &sas_device, |
| 621 | (MPI_SAS_DEVICE_PGAD_FORM_BUS_TARGET_ID << |
| 622 | MPI_SAS_DEVICE_PGAD_FORM_SHIFT), |
| 623 | (channel << 8) + id); |
| 624 | if (rc) |
| 625 | return; |
| 626 | |
| 627 | memset(&enclosure_info, 0, sizeof(struct mptsas_enclosure)); |
| 628 | mptsas_sas_enclosure_pg0(ioc, &enclosure_info, |
| 629 | (MPI_SAS_ENCLOS_PGAD_FORM_HANDLE << |
| 630 | MPI_SAS_ENCLOS_PGAD_FORM_SHIFT), |
| 631 | sas_device.handle_enclosure); |
| 632 | |
| 633 | mptsas_add_device_component(ioc, sas_device.channel, |
| 634 | sas_device.id, sas_device.sas_address, sas_device.device_info, |
| 635 | sas_device.slot, enclosure_info.enclosure_logical_id); |
| 636 | } |
| 637 | |
| 638 | /** |
Kashyap, Desai | a7938b0 | 2009-05-29 16:53:56 +0530 | [diff] [blame] | 639 | * mptsas_add_device_component_starget_ir - Handle Integrated RAID, adding |
| 640 | * each individual device to list |
| 641 | * @ioc: Pointer to MPT_ADAPTER structure |
| 642 | * @channel: fw mapped id's |
| 643 | * @id: |
| 644 | * |
| 645 | **/ |
| 646 | static void |
| 647 | mptsas_add_device_component_starget_ir(MPT_ADAPTER *ioc, |
| 648 | struct scsi_target *starget) |
| 649 | { |
| 650 | CONFIGPARMS cfg; |
| 651 | ConfigPageHeader_t hdr; |
| 652 | dma_addr_t dma_handle; |
| 653 | pRaidVolumePage0_t buffer = NULL; |
| 654 | int i; |
| 655 | RaidPhysDiskPage0_t phys_disk; |
| 656 | struct mptsas_device_info *sas_info, *next; |
| 657 | |
| 658 | memset(&cfg, 0 , sizeof(CONFIGPARMS)); |
| 659 | memset(&hdr, 0 , sizeof(ConfigPageHeader_t)); |
| 660 | hdr.PageType = MPI_CONFIG_PAGETYPE_RAID_VOLUME; |
| 661 | /* assumption that all volumes on channel = 0 */ |
| 662 | cfg.pageAddr = starget->id; |
| 663 | cfg.cfghdr.hdr = &hdr; |
| 664 | cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER; |
| 665 | cfg.timeout = 10; |
| 666 | |
| 667 | if (mpt_config(ioc, &cfg) != 0) |
| 668 | goto out; |
| 669 | |
| 670 | if (!hdr.PageLength) |
| 671 | goto out; |
| 672 | |
| 673 | buffer = pci_alloc_consistent(ioc->pcidev, hdr.PageLength * 4, |
| 674 | &dma_handle); |
| 675 | |
| 676 | if (!buffer) |
| 677 | goto out; |
| 678 | |
| 679 | cfg.physAddr = dma_handle; |
| 680 | cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT; |
| 681 | |
| 682 | if (mpt_config(ioc, &cfg) != 0) |
| 683 | goto out; |
| 684 | |
| 685 | if (!buffer->NumPhysDisks) |
| 686 | goto out; |
| 687 | |
| 688 | /* |
| 689 | * Adding entry for hidden components |
| 690 | */ |
| 691 | for (i = 0; i < buffer->NumPhysDisks; i++) { |
| 692 | |
| 693 | if (mpt_raid_phys_disk_pg0(ioc, |
| 694 | buffer->PhysDisk[i].PhysDiskNum, &phys_disk) != 0) |
| 695 | continue; |
| 696 | |
| 697 | mptsas_add_device_component_by_fw(ioc, phys_disk.PhysDiskBus, |
| 698 | phys_disk.PhysDiskID); |
| 699 | |
Kashyap, Desai | 57e9851 | 2009-05-29 16:55:09 +0530 | [diff] [blame] | 700 | mutex_lock(&ioc->sas_device_info_mutex); |
| 701 | list_for_each_entry(sas_info, &ioc->sas_device_info_list, |
| 702 | list) { |
| 703 | if (!sas_info->is_logical_volume && |
| 704 | (sas_info->fw.channel == phys_disk.PhysDiskBus && |
| 705 | sas_info->fw.id == phys_disk.PhysDiskID)) { |
| 706 | sas_info->is_hidden_raid_component = 1; |
| 707 | sas_info->volume_id = starget->id; |
| 708 | } |
| 709 | } |
| 710 | mutex_unlock(&ioc->sas_device_info_mutex); |
| 711 | |
Kashyap, Desai | a7938b0 | 2009-05-29 16:53:56 +0530 | [diff] [blame] | 712 | } |
| 713 | |
| 714 | /* |
| 715 | * Delete all matching devices out of the list |
| 716 | */ |
| 717 | mutex_lock(&ioc->sas_device_info_mutex); |
| 718 | list_for_each_entry_safe(sas_info, next, &ioc->sas_device_info_list, |
| 719 | list) { |
| 720 | if (sas_info->is_logical_volume && sas_info->fw.id == |
| 721 | starget->id) { |
| 722 | list_del(&sas_info->list); |
| 723 | kfree(sas_info); |
| 724 | } |
| 725 | } |
| 726 | |
| 727 | sas_info = kzalloc(sizeof(struct mptsas_device_info), GFP_KERNEL); |
| 728 | if (sas_info) { |
| 729 | sas_info->fw.id = starget->id; |
| 730 | sas_info->os.id = starget->id; |
| 731 | sas_info->os.channel = starget->channel; |
| 732 | sas_info->is_logical_volume = 1; |
| 733 | INIT_LIST_HEAD(&sas_info->list); |
| 734 | list_add_tail(&sas_info->list, &ioc->sas_device_info_list); |
| 735 | } |
| 736 | mutex_unlock(&ioc->sas_device_info_mutex); |
| 737 | |
| 738 | out: |
| 739 | if (buffer) |
| 740 | pci_free_consistent(ioc->pcidev, hdr.PageLength * 4, buffer, |
| 741 | dma_handle); |
| 742 | } |
| 743 | |
| 744 | /** |
Kashyap, Desai | 3eb0822c | 2009-05-29 16:47:26 +0530 | [diff] [blame] | 745 | * mptsas_add_device_component_starget - |
| 746 | * @ioc: Pointer to MPT_ADAPTER structure |
| 747 | * @starget: |
| 748 | * |
| 749 | **/ |
| 750 | static void |
| 751 | mptsas_add_device_component_starget(MPT_ADAPTER *ioc, |
| 752 | struct scsi_target *starget) |
| 753 | { |
| 754 | VirtTarget *vtarget; |
| 755 | struct sas_rphy *rphy; |
| 756 | struct mptsas_phyinfo *phy_info = NULL; |
| 757 | struct mptsas_enclosure enclosure_info; |
| 758 | |
| 759 | rphy = dev_to_rphy(starget->dev.parent); |
| 760 | vtarget = starget->hostdata; |
| 761 | phy_info = mptsas_find_phyinfo_by_sas_address(ioc, |
| 762 | rphy->identify.sas_address); |
| 763 | if (!phy_info) |
| 764 | return; |
| 765 | |
| 766 | memset(&enclosure_info, 0, sizeof(struct mptsas_enclosure)); |
| 767 | mptsas_sas_enclosure_pg0(ioc, &enclosure_info, |
| 768 | (MPI_SAS_ENCLOS_PGAD_FORM_HANDLE << |
| 769 | MPI_SAS_ENCLOS_PGAD_FORM_SHIFT), |
| 770 | phy_info->attached.handle_enclosure); |
| 771 | |
| 772 | mptsas_add_device_component(ioc, phy_info->attached.channel, |
| 773 | phy_info->attached.id, phy_info->attached.sas_address, |
| 774 | phy_info->attached.device_info, |
| 775 | phy_info->attached.slot, enclosure_info.enclosure_logical_id); |
| 776 | } |
| 777 | |
| 778 | /** |
Kashyap, Desai | 57e9851 | 2009-05-29 16:55:09 +0530 | [diff] [blame] | 779 | * mptsas_del_device_component_by_os - Once a device has been removed, we |
| 780 | * mark the entry in the list as being cached |
| 781 | * @ioc: Pointer to MPT_ADAPTER structure |
| 782 | * @channel: os mapped id's |
| 783 | * @id: |
| 784 | * |
| 785 | **/ |
| 786 | static void |
| 787 | mptsas_del_device_component_by_os(MPT_ADAPTER *ioc, u8 channel, u8 id) |
| 788 | { |
| 789 | struct mptsas_device_info *sas_info, *next; |
| 790 | |
| 791 | /* |
| 792 | * Set is_cached flag |
| 793 | */ |
| 794 | list_for_each_entry_safe(sas_info, next, &ioc->sas_device_info_list, |
| 795 | list) { |
| 796 | if (sas_info->os.channel == channel && sas_info->os.id == id) |
| 797 | sas_info->is_cached = 1; |
| 798 | } |
| 799 | } |
| 800 | |
| 801 | /** |
Kashyap, Desai | 3eb0822c | 2009-05-29 16:47:26 +0530 | [diff] [blame] | 802 | * mptsas_del_device_components - Cleaning the list |
| 803 | * @ioc: Pointer to MPT_ADAPTER structure |
| 804 | * |
| 805 | **/ |
| 806 | static void |
| 807 | mptsas_del_device_components(MPT_ADAPTER *ioc) |
| 808 | { |
| 809 | struct mptsas_device_info *sas_info, *next; |
| 810 | |
| 811 | mutex_lock(&ioc->sas_device_info_mutex); |
| 812 | list_for_each_entry_safe(sas_info, next, &ioc->sas_device_info_list, |
| 813 | list) { |
| 814 | list_del(&sas_info->list); |
| 815 | kfree(sas_info); |
| 816 | } |
| 817 | mutex_unlock(&ioc->sas_device_info_mutex); |
| 818 | } |
| 819 | |
Eric Moore | 547f9a2 | 2006-06-27 14:42:12 -0600 | [diff] [blame] | 820 | |
| 821 | /* |
| 822 | * mptsas_setup_wide_ports |
| 823 | * |
| 824 | * Updates for new and existing narrow/wide port configuration |
| 825 | * in the sas_topology |
| 826 | */ |
Eric Moore | 376ac83 | 2006-06-29 17:36:26 -0600 | [diff] [blame] | 827 | static void |
Eric Moore | 547f9a2 | 2006-06-27 14:42:12 -0600 | [diff] [blame] | 828 | mptsas_setup_wide_ports(MPT_ADAPTER *ioc, struct mptsas_portinfo *port_info) |
| 829 | { |
| 830 | struct mptsas_portinfo_details * port_details; |
| 831 | struct mptsas_phyinfo *phy_info, *phy_info_cmp; |
| 832 | u64 sas_address; |
| 833 | int i, j; |
| 834 | |
| 835 | mutex_lock(&ioc->sas_topology_mutex); |
| 836 | |
| 837 | phy_info = port_info->phy_info; |
| 838 | for (i = 0 ; i < port_info->num_phys ; i++, phy_info++) { |
| 839 | if (phy_info->attached.handle) |
| 840 | continue; |
| 841 | port_details = phy_info->port_details; |
| 842 | if (!port_details) |
| 843 | continue; |
| 844 | if (port_details->num_phys < 2) |
| 845 | continue; |
| 846 | /* |
| 847 | * Removing a phy from a port, letting the last |
| 848 | * phy be removed by firmware events. |
| 849 | */ |
Eric Moore | 29dd360 | 2007-09-14 18:46:51 -0600 | [diff] [blame] | 850 | dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT |
| 851 | "%s: [%p]: deleting phy = %d\n", |
Harvey Harrison | cadbd4a | 2008-07-03 23:47:27 -0700 | [diff] [blame] | 852 | ioc->name, __func__, port_details, i)); |
Eric Moore | 547f9a2 | 2006-06-27 14:42:12 -0600 | [diff] [blame] | 853 | port_details->num_phys--; |
| 854 | port_details->phy_bitmask &= ~ (1 << phy_info->phy_id); |
| 855 | memset(&phy_info->attached, 0, sizeof(struct mptsas_devinfo)); |
| 856 | sas_port_delete_phy(port_details->port, phy_info->phy); |
| 857 | phy_info->port_details = NULL; |
| 858 | } |
| 859 | |
| 860 | /* |
| 861 | * Populate and refresh the tree |
| 862 | */ |
| 863 | phy_info = port_info->phy_info; |
| 864 | for (i = 0 ; i < port_info->num_phys ; i++, phy_info++) { |
| 865 | sas_address = phy_info->attached.sas_address; |
Eric Moore | 29dd360 | 2007-09-14 18:46:51 -0600 | [diff] [blame] | 866 | dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "phy_id=%d sas_address=0x%018llX\n", |
| 867 | ioc->name, i, (unsigned long long)sas_address)); |
Eric Moore | 547f9a2 | 2006-06-27 14:42:12 -0600 | [diff] [blame] | 868 | if (!sas_address) |
| 869 | continue; |
| 870 | port_details = phy_info->port_details; |
| 871 | /* |
| 872 | * Forming a port |
| 873 | */ |
| 874 | if (!port_details) { |
Kashyap, Desai | 2f18786 | 2009-05-29 16:52:37 +0530 | [diff] [blame] | 875 | port_details = kzalloc(sizeof(struct |
| 876 | mptsas_portinfo_details), GFP_KERNEL); |
Eric Moore | 547f9a2 | 2006-06-27 14:42:12 -0600 | [diff] [blame] | 877 | if (!port_details) |
| 878 | goto out; |
| 879 | port_details->num_phys = 1; |
| 880 | port_details->port_info = port_info; |
Eric Moore | 547f9a2 | 2006-06-27 14:42:12 -0600 | [diff] [blame] | 881 | if (phy_info->phy_id < 64 ) |
| 882 | port_details->phy_bitmask |= |
| 883 | (1 << phy_info->phy_id); |
| 884 | phy_info->sas_port_add_phy=1; |
Eric Moore | 29dd360 | 2007-09-14 18:46:51 -0600 | [diff] [blame] | 885 | dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "\t\tForming port\n\t\t" |
Eric Moore | f99be43 | 2007-01-04 20:46:54 -0700 | [diff] [blame] | 886 | "phy_id=%d sas_address=0x%018llX\n", |
Eric Moore | 29dd360 | 2007-09-14 18:46:51 -0600 | [diff] [blame] | 887 | ioc->name, i, (unsigned long long)sas_address)); |
Eric Moore | 547f9a2 | 2006-06-27 14:42:12 -0600 | [diff] [blame] | 888 | phy_info->port_details = port_details; |
| 889 | } |
| 890 | |
| 891 | if (i == port_info->num_phys - 1) |
| 892 | continue; |
| 893 | phy_info_cmp = &port_info->phy_info[i + 1]; |
| 894 | for (j = i + 1 ; j < port_info->num_phys ; j++, |
| 895 | phy_info_cmp++) { |
| 896 | if (!phy_info_cmp->attached.sas_address) |
| 897 | continue; |
| 898 | if (sas_address != phy_info_cmp->attached.sas_address) |
| 899 | continue; |
| 900 | if (phy_info_cmp->port_details == port_details ) |
| 901 | continue; |
Eric Moore | 29dd360 | 2007-09-14 18:46:51 -0600 | [diff] [blame] | 902 | dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT |
Eric Moore | f99be43 | 2007-01-04 20:46:54 -0700 | [diff] [blame] | 903 | "\t\tphy_id=%d sas_address=0x%018llX\n", |
Eric Moore | 29dd360 | 2007-09-14 18:46:51 -0600 | [diff] [blame] | 904 | ioc->name, j, (unsigned long long) |
Eric Moore | f99be43 | 2007-01-04 20:46:54 -0700 | [diff] [blame] | 905 | phy_info_cmp->attached.sas_address)); |
Eric Moore | 547f9a2 | 2006-06-27 14:42:12 -0600 | [diff] [blame] | 906 | if (phy_info_cmp->port_details) { |
| 907 | port_details->rphy = |
| 908 | mptsas_get_rphy(phy_info_cmp); |
| 909 | port_details->port = |
| 910 | mptsas_get_port(phy_info_cmp); |
| 911 | port_details->starget = |
| 912 | mptsas_get_starget(phy_info_cmp); |
Eric Moore | 547f9a2 | 2006-06-27 14:42:12 -0600 | [diff] [blame] | 913 | port_details->num_phys = |
| 914 | phy_info_cmp->port_details->num_phys; |
Eric Moore | 547f9a2 | 2006-06-27 14:42:12 -0600 | [diff] [blame] | 915 | if (!phy_info_cmp->port_details->num_phys) |
| 916 | kfree(phy_info_cmp->port_details); |
| 917 | } else |
| 918 | phy_info_cmp->sas_port_add_phy=1; |
| 919 | /* |
| 920 | * Adding a phy to a port |
| 921 | */ |
| 922 | phy_info_cmp->port_details = port_details; |
| 923 | if (phy_info_cmp->phy_id < 64 ) |
| 924 | port_details->phy_bitmask |= |
| 925 | (1 << phy_info_cmp->phy_id); |
| 926 | port_details->num_phys++; |
| 927 | } |
| 928 | } |
| 929 | |
| 930 | out: |
| 931 | |
Eric Moore | 547f9a2 | 2006-06-27 14:42:12 -0600 | [diff] [blame] | 932 | for (i = 0; i < port_info->num_phys; i++) { |
| 933 | port_details = port_info->phy_info[i].port_details; |
| 934 | if (!port_details) |
| 935 | continue; |
Eric Moore | 29dd360 | 2007-09-14 18:46:51 -0600 | [diff] [blame] | 936 | dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT |
Eric Moore | f99be43 | 2007-01-04 20:46:54 -0700 | [diff] [blame] | 937 | "%s: [%p]: phy_id=%02d num_phys=%02d " |
Harvey Harrison | cadbd4a | 2008-07-03 23:47:27 -0700 | [diff] [blame] | 938 | "bitmask=0x%016llX\n", ioc->name, __func__, |
Eric Moore | f99be43 | 2007-01-04 20:46:54 -0700 | [diff] [blame] | 939 | port_details, i, port_details->num_phys, |
| 940 | (unsigned long long)port_details->phy_bitmask)); |
Eric Moore | 29dd360 | 2007-09-14 18:46:51 -0600 | [diff] [blame] | 941 | dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "\t\tport = %p rphy=%p\n", |
| 942 | ioc->name, port_details->port, port_details->rphy)); |
Eric Moore | 547f9a2 | 2006-06-27 14:42:12 -0600 | [diff] [blame] | 943 | } |
Eric Moore | 29dd360 | 2007-09-14 18:46:51 -0600 | [diff] [blame] | 944 | dsaswideprintk(ioc, printk("\n")); |
Eric Moore | 547f9a2 | 2006-06-27 14:42:12 -0600 | [diff] [blame] | 945 | mutex_unlock(&ioc->sas_topology_mutex); |
| 946 | } |
| 947 | |
Eric Moore | df9e062 | 2007-01-29 09:46:21 -0700 | [diff] [blame] | 948 | /** |
| 949 | * csmisas_find_vtarget |
| 950 | * |
| 951 | * @ioc |
| 952 | * @volume_id |
| 953 | * @volume_bus |
| 954 | * |
| 955 | **/ |
| 956 | static VirtTarget * |
| 957 | mptsas_find_vtarget(MPT_ADAPTER *ioc, u8 channel, u8 id) |
Eric Moore | 547f9a2 | 2006-06-27 14:42:12 -0600 | [diff] [blame] | 958 | { |
Eric Moore | df9e062 | 2007-01-29 09:46:21 -0700 | [diff] [blame] | 959 | struct scsi_device *sdev; |
Eric Moore | a69de50 | 2007-09-14 18:48:19 -0600 | [diff] [blame] | 960 | VirtDevice *vdevice; |
Eric Moore | df9e062 | 2007-01-29 09:46:21 -0700 | [diff] [blame] | 961 | VirtTarget *vtarget = NULL; |
Eric Moore | 547f9a2 | 2006-06-27 14:42:12 -0600 | [diff] [blame] | 962 | |
Eric Moore | df9e062 | 2007-01-29 09:46:21 -0700 | [diff] [blame] | 963 | shost_for_each_device(sdev, ioc->sh) { |
Kashyap, Desai | e7deff3 | 2009-05-29 16:46:07 +0530 | [diff] [blame] | 964 | vdevice = sdev->hostdata; |
| 965 | if ((vdevice == NULL) || |
| 966 | (vdevice->vtarget == NULL)) |
Eric Moore | df9e062 | 2007-01-29 09:46:21 -0700 | [diff] [blame] | 967 | continue; |
Kashyap, Desai | a7938b0 | 2009-05-29 16:53:56 +0530 | [diff] [blame] | 968 | if ((vdevice->vtarget->tflags & |
| 969 | MPT_TARGET_FLAGS_RAID_COMPONENT || |
| 970 | vdevice->vtarget->raidVolume)) |
| 971 | continue; |
Eric Moore | a69de50 | 2007-09-14 18:48:19 -0600 | [diff] [blame] | 972 | if (vdevice->vtarget->id == id && |
Kashyap, Desai | e7deff3 | 2009-05-29 16:46:07 +0530 | [diff] [blame] | 973 | vdevice->vtarget->channel == channel) |
Eric Moore | a69de50 | 2007-09-14 18:48:19 -0600 | [diff] [blame] | 974 | vtarget = vdevice->vtarget; |
Eric Moore | 547f9a2 | 2006-06-27 14:42:12 -0600 | [diff] [blame] | 975 | } |
Eric Moore | df9e062 | 2007-01-29 09:46:21 -0700 | [diff] [blame] | 976 | return vtarget; |
| 977 | } |
| 978 | |
Kashyap, Desai | 3eb0822c | 2009-05-29 16:47:26 +0530 | [diff] [blame] | 979 | static void |
| 980 | mptsas_queue_device_delete(MPT_ADAPTER *ioc, |
| 981 | MpiEventDataSasDeviceStatusChange_t *sas_event_data) |
| 982 | { |
| 983 | struct fw_event_work *fw_event; |
| 984 | int sz; |
| 985 | |
| 986 | sz = offsetof(struct fw_event_work, event_data) + |
| 987 | sizeof(MpiEventDataSasDeviceStatusChange_t); |
| 988 | fw_event = kzalloc(sz, GFP_ATOMIC); |
| 989 | if (!fw_event) { |
| 990 | printk(MYIOC_s_WARN_FMT "%s: failed at (line=%d)\n", |
| 991 | ioc->name, __func__, __LINE__); |
| 992 | return; |
| 993 | } |
| 994 | memcpy(fw_event->event_data, sas_event_data, |
| 995 | sizeof(MpiEventDataSasDeviceStatusChange_t)); |
| 996 | fw_event->event = MPI_EVENT_SAS_DEVICE_STATUS_CHANGE; |
| 997 | fw_event->ioc = ioc; |
| 998 | mptsas_add_fw_event(ioc, fw_event, msecs_to_jiffies(1)); |
| 999 | } |
| 1000 | |
Kashyap, Desai | eedf92b | 2009-05-29 16:51:32 +0530 | [diff] [blame] | 1001 | static void |
| 1002 | mptsas_queue_rescan(MPT_ADAPTER *ioc) |
| 1003 | { |
| 1004 | struct fw_event_work *fw_event; |
| 1005 | int sz; |
| 1006 | |
| 1007 | sz = offsetof(struct fw_event_work, event_data); |
| 1008 | fw_event = kzalloc(sz, GFP_ATOMIC); |
| 1009 | if (!fw_event) { |
| 1010 | printk(MYIOC_s_WARN_FMT "%s: failed at (line=%d)\n", |
| 1011 | ioc->name, __func__, __LINE__); |
| 1012 | return; |
| 1013 | } |
| 1014 | fw_event->event = -1; |
| 1015 | fw_event->ioc = ioc; |
| 1016 | mptsas_add_fw_event(ioc, fw_event, msecs_to_jiffies(1)); |
| 1017 | } |
| 1018 | |
Kashyap, Desai | 3eb0822c | 2009-05-29 16:47:26 +0530 | [diff] [blame] | 1019 | |
Eric Moore | df9e062 | 2007-01-29 09:46:21 -0700 | [diff] [blame] | 1020 | /** |
| 1021 | * mptsas_target_reset |
| 1022 | * |
| 1023 | * Issues TARGET_RESET to end device using handshaking method |
| 1024 | * |
| 1025 | * @ioc |
| 1026 | * @channel |
| 1027 | * @id |
| 1028 | * |
| 1029 | * Returns (1) success |
| 1030 | * (0) failure |
| 1031 | * |
| 1032 | **/ |
| 1033 | static int |
| 1034 | mptsas_target_reset(MPT_ADAPTER *ioc, u8 channel, u8 id) |
| 1035 | { |
| 1036 | MPT_FRAME_HDR *mf; |
| 1037 | SCSITaskMgmt_t *pScsiTm; |
Kashyap, Desai | ea2a788 | 2009-05-29 16:46:50 +0530 | [diff] [blame] | 1038 | if (mpt_set_taskmgmt_in_progress_flag(ioc) != 0) |
| 1039 | return 0; |
| 1040 | |
Eric Moore | df9e062 | 2007-01-29 09:46:21 -0700 | [diff] [blame] | 1041 | |
Kashyap, Desai | e7deff3 | 2009-05-29 16:46:07 +0530 | [diff] [blame] | 1042 | mf = mpt_get_msg_frame(mptsasDeviceResetCtx, ioc); |
| 1043 | if (mf == NULL) { |
| 1044 | dfailprintk(ioc, printk(MYIOC_s_WARN_FMT |
Kashyap, Desai | ea2a788 | 2009-05-29 16:46:50 +0530 | [diff] [blame] | 1045 | "%s, no msg frames @%d!!\n", ioc->name, |
| 1046 | __func__, __LINE__)); |
| 1047 | goto out_fail; |
Eric Moore | df9e062 | 2007-01-29 09:46:21 -0700 | [diff] [blame] | 1048 | } |
| 1049 | |
Kashyap, Desai | ea2a788 | 2009-05-29 16:46:50 +0530 | [diff] [blame] | 1050 | dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT "TaskMgmt request (mf=%p)\n", |
| 1051 | ioc->name, mf)); |
| 1052 | |
Eric Moore | df9e062 | 2007-01-29 09:46:21 -0700 | [diff] [blame] | 1053 | /* Format the Request |
| 1054 | */ |
| 1055 | pScsiTm = (SCSITaskMgmt_t *) mf; |
| 1056 | memset (pScsiTm, 0, sizeof(SCSITaskMgmt_t)); |
| 1057 | pScsiTm->TargetID = id; |
| 1058 | pScsiTm->Bus = channel; |
| 1059 | pScsiTm->Function = MPI_FUNCTION_SCSI_TASK_MGMT; |
| 1060 | pScsiTm->TaskType = MPI_SCSITASKMGMT_TASKTYPE_TARGET_RESET; |
| 1061 | pScsiTm->MsgFlags = MPI_SCSITASKMGMT_MSGFLAGS_LIPRESET_RESET_OPTION; |
| 1062 | |
Prakash, Sathya | d6ecdd6 | 2007-07-24 15:47:41 +0530 | [diff] [blame] | 1063 | DBG_DUMP_TM_REQUEST_FRAME(ioc, (u32 *)mf); |
Eric Moore | df9e062 | 2007-01-29 09:46:21 -0700 | [diff] [blame] | 1064 | |
Kashyap, Desai | ea2a788 | 2009-05-29 16:46:50 +0530 | [diff] [blame] | 1065 | dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT |
| 1066 | "TaskMgmt type=%d (sas device delete) fw_channel = %d fw_id = %d)\n", |
| 1067 | ioc->name, MPI_SCSITASKMGMT_TASKTYPE_TARGET_RESET, channel, id)); |
| 1068 | |
Kashyap, Desai | e7deff3 | 2009-05-29 16:46:07 +0530 | [diff] [blame] | 1069 | mpt_put_msg_frame_hi_pri(mptsasDeviceResetCtx, ioc, mf); |
Eric Moore | df9e062 | 2007-01-29 09:46:21 -0700 | [diff] [blame] | 1070 | |
| 1071 | return 1; |
Kashyap, Desai | ea2a788 | 2009-05-29 16:46:50 +0530 | [diff] [blame] | 1072 | |
| 1073 | out_fail: |
| 1074 | |
| 1075 | mpt_clear_taskmgmt_in_progress_flag(ioc); |
| 1076 | return 0; |
Eric Moore | df9e062 | 2007-01-29 09:46:21 -0700 | [diff] [blame] | 1077 | } |
| 1078 | |
| 1079 | /** |
| 1080 | * mptsas_target_reset_queue |
| 1081 | * |
| 1082 | * Receive request for TARGET_RESET after recieving an firmware |
| 1083 | * event NOT_RESPONDING_EVENT, then put command in link list |
| 1084 | * and queue if task_queue already in use. |
| 1085 | * |
| 1086 | * @ioc |
| 1087 | * @sas_event_data |
| 1088 | * |
| 1089 | **/ |
| 1090 | static void |
| 1091 | mptsas_target_reset_queue(MPT_ADAPTER *ioc, |
| 1092 | EVENT_DATA_SAS_DEVICE_STATUS_CHANGE *sas_event_data) |
| 1093 | { |
Eric Moore | e7eae9f | 2007-09-29 10:15:59 -0600 | [diff] [blame] | 1094 | MPT_SCSI_HOST *hd = shost_priv(ioc->sh); |
Eric Moore | df9e062 | 2007-01-29 09:46:21 -0700 | [diff] [blame] | 1095 | VirtTarget *vtarget = NULL; |
| 1096 | struct mptsas_target_reset_event *target_reset_list; |
| 1097 | u8 id, channel; |
| 1098 | |
| 1099 | id = sas_event_data->TargetID; |
| 1100 | channel = sas_event_data->Bus; |
| 1101 | |
| 1102 | if (!(vtarget = mptsas_find_vtarget(ioc, channel, id))) |
| 1103 | return; |
| 1104 | |
| 1105 | vtarget->deleted = 1; /* block IO */ |
| 1106 | |
Kashyap, Desai | 2f18786 | 2009-05-29 16:52:37 +0530 | [diff] [blame] | 1107 | target_reset_list = kzalloc(sizeof(struct mptsas_target_reset_event), |
Eric Moore | df9e062 | 2007-01-29 09:46:21 -0700 | [diff] [blame] | 1108 | GFP_ATOMIC); |
| 1109 | if (!target_reset_list) { |
Kashyap, Desai | e7deff3 | 2009-05-29 16:46:07 +0530 | [diff] [blame] | 1110 | dfailprintk(ioc, printk(MYIOC_s_WARN_FMT |
| 1111 | "%s, failed to allocate mem @%d..!!\n", |
| 1112 | ioc->name, __func__, __LINE__)); |
Eric Moore | df9e062 | 2007-01-29 09:46:21 -0700 | [diff] [blame] | 1113 | return; |
| 1114 | } |
| 1115 | |
| 1116 | memcpy(&target_reset_list->sas_event_data, sas_event_data, |
| 1117 | sizeof(*sas_event_data)); |
| 1118 | list_add_tail(&target_reset_list->list, &hd->target_reset_list); |
| 1119 | |
Kashyap, Desai | e7deff3 | 2009-05-29 16:46:07 +0530 | [diff] [blame] | 1120 | target_reset_list->time_count = jiffies; |
Eric Moore | df9e062 | 2007-01-29 09:46:21 -0700 | [diff] [blame] | 1121 | |
| 1122 | if (mptsas_target_reset(ioc, channel, id)) { |
| 1123 | target_reset_list->target_reset_issued = 1; |
Eric Moore | df9e062 | 2007-01-29 09:46:21 -0700 | [diff] [blame] | 1124 | } |
| 1125 | } |
| 1126 | |
| 1127 | /** |
Kashyap, Desai | e7deff3 | 2009-05-29 16:46:07 +0530 | [diff] [blame] | 1128 | * mptsas_taskmgmt_complete - Completion for TARGET_RESET after |
| 1129 | * NOT_RESPONDING_EVENT, enable work queue to finish off removing device |
| 1130 | * from upper layers. then send next TARGET_RESET in the queue. |
| 1131 | * @ioc: Pointer to MPT_ADAPTER structure |
Eric Moore | df9e062 | 2007-01-29 09:46:21 -0700 | [diff] [blame] | 1132 | * |
| 1133 | **/ |
Kashyap, Desai | e7deff3 | 2009-05-29 16:46:07 +0530 | [diff] [blame] | 1134 | static int |
| 1135 | mptsas_taskmgmt_complete(MPT_ADAPTER *ioc, MPT_FRAME_HDR *mf, MPT_FRAME_HDR *mr) |
Eric Moore | df9e062 | 2007-01-29 09:46:21 -0700 | [diff] [blame] | 1136 | { |
Eric Moore | e7eae9f | 2007-09-29 10:15:59 -0600 | [diff] [blame] | 1137 | MPT_SCSI_HOST *hd = shost_priv(ioc->sh); |
Eric Moore | df9e062 | 2007-01-29 09:46:21 -0700 | [diff] [blame] | 1138 | struct list_head *head = &hd->target_reset_list; |
Eric Moore | df9e062 | 2007-01-29 09:46:21 -0700 | [diff] [blame] | 1139 | u8 id, channel; |
Kashyap, Desai | e7deff3 | 2009-05-29 16:46:07 +0530 | [diff] [blame] | 1140 | struct mptsas_target_reset_event *target_reset_list; |
| 1141 | SCSITaskMgmtReply_t *pScsiTmReply; |
| 1142 | |
| 1143 | dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT "TaskMgmt completed: " |
| 1144 | "(mf = %p, mr = %p)\n", ioc->name, mf, mr)); |
| 1145 | |
| 1146 | pScsiTmReply = (SCSITaskMgmtReply_t *)mr; |
| 1147 | if (pScsiTmReply) { |
| 1148 | dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT |
| 1149 | "\tTaskMgmt completed: fw_channel = %d, fw_id = %d,\n" |
| 1150 | "\ttask_type = 0x%02X, iocstatus = 0x%04X " |
| 1151 | "loginfo = 0x%08X,\n\tresponse_code = 0x%02X, " |
| 1152 | "term_cmnds = %d\n", ioc->name, |
| 1153 | pScsiTmReply->Bus, pScsiTmReply->TargetID, |
| 1154 | pScsiTmReply->TaskType, |
| 1155 | le16_to_cpu(pScsiTmReply->IOCStatus), |
| 1156 | le32_to_cpu(pScsiTmReply->IOCLogInfo), |
| 1157 | pScsiTmReply->ResponseCode, |
| 1158 | le32_to_cpu(pScsiTmReply->TerminationCount))); |
| 1159 | |
| 1160 | if (pScsiTmReply->ResponseCode) |
| 1161 | mptscsih_taskmgmt_response_code(ioc, |
| 1162 | pScsiTmReply->ResponseCode); |
| 1163 | } |
| 1164 | |
| 1165 | if (pScsiTmReply && (pScsiTmReply->TaskType == |
| 1166 | MPI_SCSITASKMGMT_TASKTYPE_QUERY_TASK || pScsiTmReply->TaskType == |
| 1167 | MPI_SCSITASKMGMT_TASKTYPE_ABRT_TASK_SET)) { |
| 1168 | ioc->taskmgmt_cmds.status |= MPT_MGMT_STATUS_COMMAND_GOOD; |
| 1169 | ioc->taskmgmt_cmds.status |= MPT_MGMT_STATUS_RF_VALID; |
| 1170 | memcpy(ioc->taskmgmt_cmds.reply, mr, |
| 1171 | min(MPT_DEFAULT_FRAME_SIZE, 4 * mr->u.reply.MsgLength)); |
| 1172 | if (ioc->taskmgmt_cmds.status & MPT_MGMT_STATUS_PENDING) { |
| 1173 | ioc->taskmgmt_cmds.status &= ~MPT_MGMT_STATUS_PENDING; |
| 1174 | complete(&ioc->taskmgmt_cmds.done); |
| 1175 | return 1; |
| 1176 | } |
| 1177 | return 0; |
| 1178 | } |
| 1179 | |
| 1180 | mpt_clear_taskmgmt_in_progress_flag(ioc); |
Eric Moore | df9e062 | 2007-01-29 09:46:21 -0700 | [diff] [blame] | 1181 | |
| 1182 | if (list_empty(head)) |
Kashyap, Desai | e7deff3 | 2009-05-29 16:46:07 +0530 | [diff] [blame] | 1183 | return 1; |
Eric Moore | df9e062 | 2007-01-29 09:46:21 -0700 | [diff] [blame] | 1184 | |
Kashyap, Desai | e7deff3 | 2009-05-29 16:46:07 +0530 | [diff] [blame] | 1185 | target_reset_list = list_entry(head->next, |
| 1186 | struct mptsas_target_reset_event, list); |
| 1187 | |
| 1188 | dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT |
| 1189 | "TaskMgmt: completed (%d seconds)\n", |
| 1190 | ioc->name, jiffies_to_msecs(jiffies - |
| 1191 | target_reset_list->time_count)/1000)); |
Eric Moore | df9e062 | 2007-01-29 09:46:21 -0700 | [diff] [blame] | 1192 | |
Kashyap, Desai | e7deff3 | 2009-05-29 16:46:07 +0530 | [diff] [blame] | 1193 | id = pScsiTmReply->TargetID; |
| 1194 | channel = pScsiTmReply->Bus; |
| 1195 | target_reset_list->time_count = jiffies; |
Eric Moore | df9e062 | 2007-01-29 09:46:21 -0700 | [diff] [blame] | 1196 | |
| 1197 | /* |
| 1198 | * retry target reset |
| 1199 | */ |
| 1200 | if (!target_reset_list->target_reset_issued) { |
Kashyap, Desai | e7deff3 | 2009-05-29 16:46:07 +0530 | [diff] [blame] | 1201 | if (mptsas_target_reset(ioc, channel, id)) |
Eric Moore | df9e062 | 2007-01-29 09:46:21 -0700 | [diff] [blame] | 1202 | target_reset_list->target_reset_issued = 1; |
Kashyap, Desai | e7deff3 | 2009-05-29 16:46:07 +0530 | [diff] [blame] | 1203 | return 1; |
Eric Moore | df9e062 | 2007-01-29 09:46:21 -0700 | [diff] [blame] | 1204 | } |
| 1205 | |
| 1206 | /* |
| 1207 | * enable work queue to remove device from upper layers |
| 1208 | */ |
| 1209 | list_del(&target_reset_list->list); |
Kashyap, Desai | 3eb0822c | 2009-05-29 16:47:26 +0530 | [diff] [blame] | 1210 | if ((mptsas_find_vtarget(ioc, channel, id)) && !ioc->fw_events_off) |
| 1211 | mptsas_queue_device_delete(ioc, |
| 1212 | &target_reset_list->sas_event_data); |
Kashyap, Desai | ea2a788 | 2009-05-29 16:46:50 +0530 | [diff] [blame] | 1213 | |
Kashyap, Desai | e7deff3 | 2009-05-29 16:46:07 +0530 | [diff] [blame] | 1214 | |
Eric Moore | df9e062 | 2007-01-29 09:46:21 -0700 | [diff] [blame] | 1215 | /* |
| 1216 | * issue target reset to next device in the queue |
| 1217 | */ |
| 1218 | |
| 1219 | head = &hd->target_reset_list; |
| 1220 | if (list_empty(head)) |
Kashyap, Desai | e7deff3 | 2009-05-29 16:46:07 +0530 | [diff] [blame] | 1221 | return 1; |
Eric Moore | df9e062 | 2007-01-29 09:46:21 -0700 | [diff] [blame] | 1222 | |
| 1223 | target_reset_list = list_entry(head->next, struct mptsas_target_reset_event, |
| 1224 | list); |
| 1225 | |
Kashyap, Desai | e7deff3 | 2009-05-29 16:46:07 +0530 | [diff] [blame] | 1226 | id = target_reset_list->sas_event_data.TargetID; |
| 1227 | channel = target_reset_list->sas_event_data.Bus; |
| 1228 | target_reset_list->time_count = jiffies; |
Eric Moore | df9e062 | 2007-01-29 09:46:21 -0700 | [diff] [blame] | 1229 | |
Kashyap, Desai | e7deff3 | 2009-05-29 16:46:07 +0530 | [diff] [blame] | 1230 | if (mptsas_target_reset(ioc, channel, id)) |
Eric Moore | df9e062 | 2007-01-29 09:46:21 -0700 | [diff] [blame] | 1231 | target_reset_list->target_reset_issued = 1; |
Eric Moore | df9e062 | 2007-01-29 09:46:21 -0700 | [diff] [blame] | 1232 | |
Kashyap, Desai | e7deff3 | 2009-05-29 16:46:07 +0530 | [diff] [blame] | 1233 | return 1; |
Eric Moore | df9e062 | 2007-01-29 09:46:21 -0700 | [diff] [blame] | 1234 | } |
| 1235 | |
| 1236 | /** |
| 1237 | * mptscsih_ioc_reset |
| 1238 | * |
| 1239 | * @ioc |
| 1240 | * @reset_phase |
| 1241 | * |
| 1242 | **/ |
| 1243 | static int |
| 1244 | mptsas_ioc_reset(MPT_ADAPTER *ioc, int reset_phase) |
| 1245 | { |
Judith Lebzelter | ba76ef2 | 2007-03-09 13:07:44 -0800 | [diff] [blame] | 1246 | MPT_SCSI_HOST *hd; |
Eric Moore | df9e062 | 2007-01-29 09:46:21 -0700 | [diff] [blame] | 1247 | int rc; |
| 1248 | |
| 1249 | rc = mptscsih_ioc_reset(ioc, reset_phase); |
Kashyap, Desai | 3eb0822c | 2009-05-29 16:47:26 +0530 | [diff] [blame] | 1250 | if ((ioc->bus_type != SAS) || (!rc)) |
| 1251 | return rc; |
Eric Moore | df9e062 | 2007-01-29 09:46:21 -0700 | [diff] [blame] | 1252 | |
Eric Moore | e7eae9f | 2007-09-29 10:15:59 -0600 | [diff] [blame] | 1253 | hd = shost_priv(ioc->sh); |
Judith Lebzelter | ba76ef2 | 2007-03-09 13:07:44 -0800 | [diff] [blame] | 1254 | if (!hd->ioc) |
Eric Moore | df9e062 | 2007-01-29 09:46:21 -0700 | [diff] [blame] | 1255 | goto out; |
| 1256 | |
Kashyap, Desai | 3eb0822c | 2009-05-29 16:47:26 +0530 | [diff] [blame] | 1257 | switch (reset_phase) { |
| 1258 | case MPT_IOC_SETUP_RESET: |
| 1259 | dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT |
| 1260 | "%s: MPT_IOC_SETUP_RESET\n", ioc->name, __func__)); |
| 1261 | mptsas_fw_event_off(ioc); |
| 1262 | break; |
| 1263 | case MPT_IOC_PRE_RESET: |
| 1264 | dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT |
| 1265 | "%s: MPT_IOC_PRE_RESET\n", ioc->name, __func__)); |
| 1266 | break; |
| 1267 | case MPT_IOC_POST_RESET: |
| 1268 | dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT |
| 1269 | "%s: MPT_IOC_POST_RESET\n", ioc->name, __func__)); |
| 1270 | if (ioc->sas_mgmt.status & MPT_MGMT_STATUS_PENDING) { |
| 1271 | ioc->sas_mgmt.status |= MPT_MGMT_STATUS_DID_IOCRESET; |
| 1272 | complete(&ioc->sas_mgmt.done); |
| 1273 | } |
| 1274 | mptsas_cleanup_fw_event_q(ioc); |
Kashyap, Desai | eedf92b | 2009-05-29 16:51:32 +0530 | [diff] [blame] | 1275 | mptsas_queue_rescan(ioc); |
Kashyap, Desai | 3eb0822c | 2009-05-29 16:47:26 +0530 | [diff] [blame] | 1276 | mptsas_fw_event_on(ioc); |
| 1277 | break; |
| 1278 | default: |
| 1279 | break; |
Eric Moore | df9e062 | 2007-01-29 09:46:21 -0700 | [diff] [blame] | 1280 | } |
| 1281 | |
| 1282 | out: |
| 1283 | return rc; |
Eric Moore | 547f9a2 | 2006-06-27 14:42:12 -0600 | [diff] [blame] | 1284 | } |
| 1285 | |
Kashyap, Desai | 3eb0822c | 2009-05-29 16:47:26 +0530 | [diff] [blame] | 1286 | |
| 1287 | /** |
| 1288 | * enum device_state - |
| 1289 | * @DEVICE_RETRY: need to retry the TUR |
| 1290 | * @DEVICE_ERROR: TUR return error, don't add device |
| 1291 | * @DEVICE_READY: device can be added |
| 1292 | * |
| 1293 | */ |
| 1294 | enum device_state{ |
| 1295 | DEVICE_RETRY, |
| 1296 | DEVICE_ERROR, |
| 1297 | DEVICE_READY, |
| 1298 | }; |
| 1299 | |
Christoph Hellwig | e309444 | 2006-02-16 13:25:36 +0100 | [diff] [blame] | 1300 | static int |
Moore, Eric | 5243543 | 2006-03-14 09:14:15 -0700 | [diff] [blame] | 1301 | mptsas_sas_enclosure_pg0(MPT_ADAPTER *ioc, struct mptsas_enclosure *enclosure, |
Christoph Hellwig | e309444 | 2006-02-16 13:25:36 +0100 | [diff] [blame] | 1302 | u32 form, u32 form_specific) |
| 1303 | { |
| 1304 | ConfigExtendedPageHeader_t hdr; |
| 1305 | CONFIGPARMS cfg; |
| 1306 | SasEnclosurePage0_t *buffer; |
| 1307 | dma_addr_t dma_handle; |
| 1308 | int error; |
| 1309 | __le64 le_identifier; |
| 1310 | |
| 1311 | memset(&hdr, 0, sizeof(hdr)); |
| 1312 | hdr.PageVersion = MPI_SASENCLOSURE0_PAGEVERSION; |
| 1313 | hdr.PageNumber = 0; |
| 1314 | hdr.PageType = MPI_CONFIG_PAGETYPE_EXTENDED; |
| 1315 | hdr.ExtPageType = MPI_CONFIG_EXTPAGETYPE_ENCLOSURE; |
| 1316 | |
| 1317 | cfg.cfghdr.ehdr = &hdr; |
| 1318 | cfg.physAddr = -1; |
| 1319 | cfg.pageAddr = form + form_specific; |
| 1320 | cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER; |
| 1321 | cfg.dir = 0; /* read */ |
| 1322 | cfg.timeout = 10; |
| 1323 | |
| 1324 | error = mpt_config(ioc, &cfg); |
| 1325 | if (error) |
| 1326 | goto out; |
| 1327 | if (!hdr.ExtPageLength) { |
| 1328 | error = -ENXIO; |
| 1329 | goto out; |
| 1330 | } |
| 1331 | |
| 1332 | buffer = pci_alloc_consistent(ioc->pcidev, hdr.ExtPageLength * 4, |
| 1333 | &dma_handle); |
| 1334 | if (!buffer) { |
| 1335 | error = -ENOMEM; |
| 1336 | goto out; |
| 1337 | } |
| 1338 | |
| 1339 | cfg.physAddr = dma_handle; |
| 1340 | cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT; |
| 1341 | |
| 1342 | error = mpt_config(ioc, &cfg); |
| 1343 | if (error) |
| 1344 | goto out_free_consistent; |
| 1345 | |
| 1346 | /* save config data */ |
| 1347 | memcpy(&le_identifier, &buffer->EnclosureLogicalID, sizeof(__le64)); |
| 1348 | enclosure->enclosure_logical_id = le64_to_cpu(le_identifier); |
| 1349 | enclosure->enclosure_handle = le16_to_cpu(buffer->EnclosureHandle); |
| 1350 | enclosure->flags = le16_to_cpu(buffer->Flags); |
| 1351 | enclosure->num_slot = le16_to_cpu(buffer->NumSlots); |
| 1352 | enclosure->start_slot = le16_to_cpu(buffer->StartSlot); |
| 1353 | enclosure->start_id = buffer->StartTargetID; |
| 1354 | enclosure->start_channel = buffer->StartBus; |
| 1355 | enclosure->sep_id = buffer->SEPTargetID; |
| 1356 | enclosure->sep_channel = buffer->SEPBus; |
| 1357 | |
| 1358 | out_free_consistent: |
| 1359 | pci_free_consistent(ioc->pcidev, hdr.ExtPageLength * 4, |
| 1360 | buffer, dma_handle); |
| 1361 | out: |
| 1362 | return error; |
| 1363 | } |
Christoph Hellwig | b514112 | 2005-10-28 22:07:41 +0200 | [diff] [blame] | 1364 | |
Kashyap, Desai | 3eb0822c | 2009-05-29 16:47:26 +0530 | [diff] [blame] | 1365 | /** |
| 1366 | * mptsas_add_end_device - report a new end device to sas transport layer |
| 1367 | * @ioc: Pointer to MPT_ADAPTER structure |
| 1368 | * @phy_info: decribes attached device |
| 1369 | * |
| 1370 | * return (0) success (1) failure |
| 1371 | * |
| 1372 | **/ |
| 1373 | static int |
| 1374 | mptsas_add_end_device(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info) |
| 1375 | { |
| 1376 | struct sas_rphy *rphy; |
| 1377 | struct sas_port *port; |
| 1378 | struct sas_identify identify; |
| 1379 | char *ds = NULL; |
| 1380 | u8 fw_id; |
| 1381 | |
| 1382 | if (!phy_info) { |
| 1383 | dfailprintk(ioc, printk(MYIOC_s_ERR_FMT |
| 1384 | "%s: exit at line=%d\n", ioc->name, |
| 1385 | __func__, __LINE__)); |
| 1386 | return 1; |
| 1387 | } |
| 1388 | |
| 1389 | fw_id = phy_info->attached.id; |
| 1390 | |
| 1391 | if (mptsas_get_rphy(phy_info)) { |
| 1392 | dfailprintk(ioc, printk(MYIOC_s_ERR_FMT |
| 1393 | "%s: fw_id=%d exit at line=%d\n", ioc->name, |
| 1394 | __func__, fw_id, __LINE__)); |
| 1395 | return 2; |
| 1396 | } |
| 1397 | |
| 1398 | port = mptsas_get_port(phy_info); |
| 1399 | if (!port) { |
| 1400 | dfailprintk(ioc, printk(MYIOC_s_ERR_FMT |
| 1401 | "%s: fw_id=%d exit at line=%d\n", ioc->name, |
| 1402 | __func__, fw_id, __LINE__)); |
| 1403 | return 3; |
| 1404 | } |
| 1405 | |
| 1406 | if (phy_info->attached.device_info & |
| 1407 | MPI_SAS_DEVICE_INFO_SSP_TARGET) |
| 1408 | ds = "ssp"; |
| 1409 | if (phy_info->attached.device_info & |
| 1410 | MPI_SAS_DEVICE_INFO_STP_TARGET) |
| 1411 | ds = "stp"; |
| 1412 | if (phy_info->attached.device_info & |
| 1413 | MPI_SAS_DEVICE_INFO_SATA_DEVICE) |
| 1414 | ds = "sata"; |
| 1415 | |
| 1416 | printk(MYIOC_s_INFO_FMT "attaching %s device: fw_channel %d, fw_id %d," |
| 1417 | " phy %d, sas_addr 0x%llx\n", ioc->name, ds, |
| 1418 | phy_info->attached.channel, phy_info->attached.id, |
| 1419 | phy_info->attached.phy_id, (unsigned long long) |
| 1420 | phy_info->attached.sas_address); |
| 1421 | |
| 1422 | mptsas_parse_device_info(&identify, &phy_info->attached); |
| 1423 | rphy = sas_end_device_alloc(port); |
| 1424 | if (!rphy) { |
| 1425 | dfailprintk(ioc, printk(MYIOC_s_ERR_FMT |
| 1426 | "%s: fw_id=%d exit at line=%d\n", ioc->name, |
| 1427 | __func__, fw_id, __LINE__)); |
| 1428 | return 5; /* non-fatal: an rphy can be added later */ |
| 1429 | } |
| 1430 | |
| 1431 | rphy->identify = identify; |
| 1432 | if (sas_rphy_add(rphy)) { |
| 1433 | dfailprintk(ioc, printk(MYIOC_s_ERR_FMT |
| 1434 | "%s: fw_id=%d exit at line=%d\n", ioc->name, |
| 1435 | __func__, fw_id, __LINE__)); |
| 1436 | sas_rphy_free(rphy); |
| 1437 | return 6; |
| 1438 | } |
| 1439 | mptsas_set_rphy(ioc, phy_info, rphy); |
| 1440 | return 0; |
| 1441 | } |
| 1442 | |
| 1443 | /** |
| 1444 | * mptsas_del_end_device - report a deleted end device to sas transport |
| 1445 | * layer |
| 1446 | * @ioc: Pointer to MPT_ADAPTER structure |
| 1447 | * @phy_info: decribes attached device |
| 1448 | * |
| 1449 | **/ |
| 1450 | static void |
| 1451 | mptsas_del_end_device(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info) |
| 1452 | { |
| 1453 | struct sas_rphy *rphy; |
| 1454 | struct sas_port *port; |
| 1455 | struct mptsas_portinfo *port_info; |
| 1456 | struct mptsas_phyinfo *phy_info_parent; |
| 1457 | int i; |
| 1458 | char *ds = NULL; |
| 1459 | u8 fw_id; |
| 1460 | u64 sas_address; |
| 1461 | |
| 1462 | if (!phy_info) |
| 1463 | return; |
| 1464 | |
| 1465 | fw_id = phy_info->attached.id; |
| 1466 | sas_address = phy_info->attached.sas_address; |
| 1467 | |
| 1468 | if (!phy_info->port_details) { |
| 1469 | dfailprintk(ioc, printk(MYIOC_s_ERR_FMT |
| 1470 | "%s: fw_id=%d exit at line=%d\n", ioc->name, |
| 1471 | __func__, fw_id, __LINE__)); |
| 1472 | return; |
| 1473 | } |
| 1474 | rphy = mptsas_get_rphy(phy_info); |
| 1475 | if (!rphy) { |
| 1476 | dfailprintk(ioc, printk(MYIOC_s_ERR_FMT |
| 1477 | "%s: fw_id=%d exit at line=%d\n", ioc->name, |
| 1478 | __func__, fw_id, __LINE__)); |
| 1479 | return; |
| 1480 | } |
| 1481 | |
| 1482 | if (phy_info->attached.device_info & MPI_SAS_DEVICE_INFO_SSP_INITIATOR |
| 1483 | || phy_info->attached.device_info |
| 1484 | & MPI_SAS_DEVICE_INFO_SMP_INITIATOR |
| 1485 | || phy_info->attached.device_info |
| 1486 | & MPI_SAS_DEVICE_INFO_STP_INITIATOR) |
| 1487 | ds = "initiator"; |
| 1488 | if (phy_info->attached.device_info & |
| 1489 | MPI_SAS_DEVICE_INFO_SSP_TARGET) |
| 1490 | ds = "ssp"; |
| 1491 | if (phy_info->attached.device_info & |
| 1492 | MPI_SAS_DEVICE_INFO_STP_TARGET) |
| 1493 | ds = "stp"; |
| 1494 | if (phy_info->attached.device_info & |
| 1495 | MPI_SAS_DEVICE_INFO_SATA_DEVICE) |
| 1496 | ds = "sata"; |
| 1497 | |
| 1498 | dev_printk(KERN_DEBUG, &rphy->dev, MYIOC_s_FMT |
| 1499 | "removing %s device: fw_channel %d, fw_id %d, phy %d," |
| 1500 | "sas_addr 0x%llx\n", ioc->name, ds, phy_info->attached.channel, |
| 1501 | phy_info->attached.id, phy_info->attached.phy_id, |
| 1502 | (unsigned long long) sas_address); |
| 1503 | |
| 1504 | port = mptsas_get_port(phy_info); |
| 1505 | if (!port) { |
| 1506 | dfailprintk(ioc, printk(MYIOC_s_ERR_FMT |
| 1507 | "%s: fw_id=%d exit at line=%d\n", ioc->name, |
| 1508 | __func__, fw_id, __LINE__)); |
| 1509 | return; |
| 1510 | } |
| 1511 | port_info = phy_info->portinfo; |
| 1512 | phy_info_parent = port_info->phy_info; |
| 1513 | for (i = 0; i < port_info->num_phys; i++, phy_info_parent++) { |
| 1514 | if (!phy_info_parent->phy) |
| 1515 | continue; |
| 1516 | if (phy_info_parent->attached.sas_address != |
| 1517 | sas_address) |
| 1518 | continue; |
| 1519 | dev_printk(KERN_DEBUG, &phy_info_parent->phy->dev, |
| 1520 | MYIOC_s_FMT "delete phy %d, phy-obj (0x%p)\n", |
| 1521 | ioc->name, phy_info_parent->phy_id, |
| 1522 | phy_info_parent->phy); |
| 1523 | sas_port_delete_phy(port, phy_info_parent->phy); |
| 1524 | } |
| 1525 | |
| 1526 | dev_printk(KERN_DEBUG, &port->dev, MYIOC_s_FMT |
| 1527 | "delete port %d, sas_addr (0x%llx)\n", ioc->name, |
| 1528 | port->port_identifier, (unsigned long long)sas_address); |
| 1529 | sas_port_delete(port); |
| 1530 | mptsas_set_port(ioc, phy_info, NULL); |
| 1531 | mptsas_port_delete(ioc, phy_info->port_details); |
| 1532 | } |
| 1533 | |
| 1534 | struct mptsas_phyinfo * |
| 1535 | mptsas_refreshing_device_handles(MPT_ADAPTER *ioc, |
| 1536 | struct mptsas_devinfo *sas_device) |
| 1537 | { |
| 1538 | struct mptsas_phyinfo *phy_info; |
| 1539 | struct mptsas_portinfo *port_info; |
| 1540 | int i; |
| 1541 | |
| 1542 | phy_info = mptsas_find_phyinfo_by_sas_address(ioc, |
| 1543 | sas_device->sas_address); |
| 1544 | if (!phy_info) |
| 1545 | goto out; |
| 1546 | port_info = phy_info->portinfo; |
| 1547 | if (!port_info) |
| 1548 | goto out; |
| 1549 | mutex_lock(&ioc->sas_topology_mutex); |
| 1550 | for (i = 0; i < port_info->num_phys; i++) { |
| 1551 | if (port_info->phy_info[i].attached.sas_address != |
| 1552 | sas_device->sas_address) |
| 1553 | continue; |
| 1554 | port_info->phy_info[i].attached.channel = sas_device->channel; |
| 1555 | port_info->phy_info[i].attached.id = sas_device->id; |
| 1556 | port_info->phy_info[i].attached.sas_address = |
| 1557 | sas_device->sas_address; |
| 1558 | port_info->phy_info[i].attached.handle = sas_device->handle; |
| 1559 | port_info->phy_info[i].attached.handle_parent = |
| 1560 | sas_device->handle_parent; |
| 1561 | port_info->phy_info[i].attached.handle_enclosure = |
| 1562 | sas_device->handle_enclosure; |
| 1563 | } |
| 1564 | mutex_unlock(&ioc->sas_topology_mutex); |
| 1565 | out: |
| 1566 | return phy_info; |
| 1567 | } |
| 1568 | |
| 1569 | /** |
| 1570 | * mptsas_firmware_event_work - work thread for processing fw events |
| 1571 | * @work: work queue payload containing info describing the event |
| 1572 | * Context: user |
| 1573 | * |
| 1574 | */ |
| 1575 | static void |
| 1576 | mptsas_firmware_event_work(struct work_struct *work) |
| 1577 | { |
| 1578 | struct fw_event_work *fw_event = |
| 1579 | container_of(work, struct fw_event_work, work.work); |
| 1580 | MPT_ADAPTER *ioc = fw_event->ioc; |
| 1581 | |
Kashyap, Desai | eedf92b | 2009-05-29 16:51:32 +0530 | [diff] [blame] | 1582 | /* special rescan topology handling */ |
| 1583 | if (fw_event->event == -1) { |
| 1584 | if (ioc->in_rescan) { |
| 1585 | devtprintk(ioc, printk(MYIOC_s_DEBUG_FMT |
| 1586 | "%s: rescan ignored as it is in progress\n", |
| 1587 | ioc->name, __func__)); |
| 1588 | return; |
| 1589 | } |
| 1590 | devtprintk(ioc, printk(MYIOC_s_DEBUG_FMT "%s: rescan after " |
| 1591 | "reset\n", ioc->name, __func__)); |
| 1592 | ioc->in_rescan = 1; |
| 1593 | mptsas_not_responding_devices(ioc); |
| 1594 | mptsas_scan_sas_topology(ioc); |
| 1595 | ioc->in_rescan = 0; |
| 1596 | mptsas_free_fw_event(ioc, fw_event); |
| 1597 | return; |
| 1598 | } |
Kashyap, Desai | 3eb0822c | 2009-05-29 16:47:26 +0530 | [diff] [blame] | 1599 | |
| 1600 | /* events handling turned off during host reset */ |
| 1601 | if (ioc->fw_events_off) { |
| 1602 | mptsas_free_fw_event(ioc, fw_event); |
| 1603 | return; |
| 1604 | } |
| 1605 | |
| 1606 | devtprintk(ioc, printk(MYIOC_s_DEBUG_FMT "%s: fw_event=(0x%p), " |
| 1607 | "event = (0x%02x)\n", ioc->name, __func__, fw_event, |
| 1608 | (fw_event->event & 0xFF))); |
| 1609 | |
| 1610 | switch (fw_event->event) { |
| 1611 | case MPI_EVENT_SAS_DEVICE_STATUS_CHANGE: |
| 1612 | mptsas_send_sas_event(fw_event); |
| 1613 | break; |
| 1614 | case MPI_EVENT_INTEGRATED_RAID: |
| 1615 | mptsas_send_raid_event(fw_event); |
| 1616 | break; |
| 1617 | case MPI_EVENT_IR2: |
| 1618 | mptsas_send_ir2_event(fw_event); |
| 1619 | break; |
| 1620 | case MPI_EVENT_PERSISTENT_TABLE_FULL: |
| 1621 | mptbase_sas_persist_operation(ioc, |
| 1622 | MPI_SAS_OP_CLEAR_NOT_PRESENT); |
| 1623 | mptsas_free_fw_event(ioc, fw_event); |
| 1624 | break; |
Kashyap, Desai | db7051b | 2009-05-29 16:56:59 +0530 | [diff] [blame^] | 1625 | case MPI_EVENT_SAS_BROADCAST_PRIMITIVE: |
| 1626 | mptsas_broadcast_primative_work(fw_event); |
| 1627 | break; |
Kashyap, Desai | f9c3402 | 2009-05-29 16:49:36 +0530 | [diff] [blame] | 1628 | case MPI_EVENT_SAS_EXPANDER_STATUS_CHANGE: |
| 1629 | mptsas_send_expander_event(fw_event); |
| 1630 | break; |
| 1631 | case MPI_EVENT_SAS_PHY_LINK_STATUS: |
| 1632 | mptsas_send_link_status_event(fw_event); |
| 1633 | break; |
Kashyap, Desai | 57e9851 | 2009-05-29 16:55:09 +0530 | [diff] [blame] | 1634 | case MPI_EVENT_QUEUE_FULL: |
| 1635 | mptsas_handle_queue_full_event(fw_event); |
| 1636 | break; |
Kashyap, Desai | 3eb0822c | 2009-05-29 16:47:26 +0530 | [diff] [blame] | 1637 | } |
| 1638 | } |
| 1639 | |
| 1640 | |
| 1641 | |
James Bottomley | f013db3 | 2006-03-18 14:54:36 -0600 | [diff] [blame] | 1642 | static int |
| 1643 | mptsas_slave_configure(struct scsi_device *sdev) |
| 1644 | { |
Kashyap, Desai | 3eb0822c | 2009-05-29 16:47:26 +0530 | [diff] [blame] | 1645 | struct Scsi_Host *host = sdev->host; |
| 1646 | MPT_SCSI_HOST *hd = shost_priv(host); |
| 1647 | MPT_ADAPTER *ioc = hd->ioc; |
Kashyap, Desai | a7938b0 | 2009-05-29 16:53:56 +0530 | [diff] [blame] | 1648 | VirtDevice *vdevice = sdev->hostdata; |
Moore, Eric | 3c0c25b | 2006-04-13 16:08:17 -0600 | [diff] [blame] | 1649 | |
Kashyap, Desai | a7938b0 | 2009-05-29 16:53:56 +0530 | [diff] [blame] | 1650 | if (vdevice->vtarget->deleted) { |
| 1651 | sdev_printk(KERN_INFO, sdev, "clearing deleted flag\n"); |
| 1652 | vdevice->vtarget->deleted = 0; |
| 1653 | } |
| 1654 | |
| 1655 | /* |
| 1656 | * RAID volumes placed beyond the last expected port. |
| 1657 | * Ignore sending sas mode pages in that case.. |
| 1658 | */ |
| 1659 | if (sdev->channel == MPTSAS_RAID_CHANNEL) { |
| 1660 | mptsas_add_device_component_starget_ir(ioc, scsi_target(sdev)); |
James Bottomley | e8bf394 | 2006-07-11 17:49:34 -0400 | [diff] [blame] | 1661 | goto out; |
Kashyap, Desai | a7938b0 | 2009-05-29 16:53:56 +0530 | [diff] [blame] | 1662 | } |
James Bottomley | f013db3 | 2006-03-18 14:54:36 -0600 | [diff] [blame] | 1663 | |
James Bottomley | e8bf394 | 2006-07-11 17:49:34 -0400 | [diff] [blame] | 1664 | sas_read_port_mode_page(sdev); |
| 1665 | |
Kashyap, Desai | 3eb0822c | 2009-05-29 16:47:26 +0530 | [diff] [blame] | 1666 | mptsas_add_device_component_starget(ioc, scsi_target(sdev)); |
| 1667 | |
James Bottomley | e8bf394 | 2006-07-11 17:49:34 -0400 | [diff] [blame] | 1668 | out: |
James Bottomley | f013db3 | 2006-03-18 14:54:36 -0600 | [diff] [blame] | 1669 | return mptscsih_slave_configure(sdev); |
| 1670 | } |
| 1671 | |
Eric Moore | 547f9a2 | 2006-06-27 14:42:12 -0600 | [diff] [blame] | 1672 | static int |
| 1673 | mptsas_target_alloc(struct scsi_target *starget) |
| 1674 | { |
| 1675 | struct Scsi_Host *host = dev_to_shost(&starget->dev); |
Eric Moore | e7eae9f | 2007-09-29 10:15:59 -0600 | [diff] [blame] | 1676 | MPT_SCSI_HOST *hd = shost_priv(host); |
Eric Moore | 547f9a2 | 2006-06-27 14:42:12 -0600 | [diff] [blame] | 1677 | VirtTarget *vtarget; |
Eric Moore | 793955f | 2007-01-29 09:42:20 -0700 | [diff] [blame] | 1678 | u8 id, channel; |
Eric Moore | 547f9a2 | 2006-06-27 14:42:12 -0600 | [diff] [blame] | 1679 | struct sas_rphy *rphy; |
| 1680 | struct mptsas_portinfo *p; |
| 1681 | int i; |
Eric Moore | e80b002 | 2007-09-14 18:49:03 -0600 | [diff] [blame] | 1682 | MPT_ADAPTER *ioc = hd->ioc; |
Eric Moore | 547f9a2 | 2006-06-27 14:42:12 -0600 | [diff] [blame] | 1683 | |
| 1684 | vtarget = kzalloc(sizeof(VirtTarget), GFP_KERNEL); |
| 1685 | if (!vtarget) |
| 1686 | return -ENOMEM; |
| 1687 | |
| 1688 | vtarget->starget = starget; |
Eric Moore | e80b002 | 2007-09-14 18:49:03 -0600 | [diff] [blame] | 1689 | vtarget->ioc_id = ioc->id; |
Eric Moore | 793955f | 2007-01-29 09:42:20 -0700 | [diff] [blame] | 1690 | vtarget->tflags = MPT_TARGET_FLAGS_Q_YES; |
| 1691 | id = starget->id; |
Eric Moore | 547f9a2 | 2006-06-27 14:42:12 -0600 | [diff] [blame] | 1692 | channel = 0; |
| 1693 | |
Eric Moore | 793955f | 2007-01-29 09:42:20 -0700 | [diff] [blame] | 1694 | /* |
| 1695 | * RAID volumes placed beyond the last expected port. |
| 1696 | */ |
| 1697 | if (starget->channel == MPTSAS_RAID_CHANNEL) { |
Kashyap, Desai | a7938b0 | 2009-05-29 16:53:56 +0530 | [diff] [blame] | 1698 | if (!ioc->raid_data.pIocPg2) { |
| 1699 | kfree(vtarget); |
| 1700 | return -ENXIO; |
| 1701 | } |
| 1702 | for (i = 0; i < ioc->raid_data.pIocPg2->NumActiveVolumes; i++) { |
| 1703 | if (id == ioc->raid_data.pIocPg2-> |
| 1704 | RaidVolume[i].VolumeID) { |
| 1705 | channel = ioc->raid_data.pIocPg2-> |
| 1706 | RaidVolume[i].VolumeBus; |
| 1707 | } |
| 1708 | } |
| 1709 | vtarget->raidVolume = 1; |
Eric Moore | 547f9a2 | 2006-06-27 14:42:12 -0600 | [diff] [blame] | 1710 | goto out; |
Eric Moore | 793955f | 2007-01-29 09:42:20 -0700 | [diff] [blame] | 1711 | } |
Eric Moore | 547f9a2 | 2006-06-27 14:42:12 -0600 | [diff] [blame] | 1712 | |
| 1713 | rphy = dev_to_rphy(starget->dev.parent); |
Eric Moore | e80b002 | 2007-09-14 18:49:03 -0600 | [diff] [blame] | 1714 | mutex_lock(&ioc->sas_topology_mutex); |
| 1715 | list_for_each_entry(p, &ioc->sas_topology, list) { |
Eric Moore | 547f9a2 | 2006-06-27 14:42:12 -0600 | [diff] [blame] | 1716 | for (i = 0; i < p->num_phys; i++) { |
| 1717 | if (p->phy_info[i].attached.sas_address != |
| 1718 | rphy->identify.sas_address) |
| 1719 | continue; |
Eric Moore | 793955f | 2007-01-29 09:42:20 -0700 | [diff] [blame] | 1720 | id = p->phy_info[i].attached.id; |
Eric Moore | 547f9a2 | 2006-06-27 14:42:12 -0600 | [diff] [blame] | 1721 | channel = p->phy_info[i].attached.channel; |
| 1722 | mptsas_set_starget(&p->phy_info[i], starget); |
| 1723 | |
| 1724 | /* |
| 1725 | * Exposing hidden raid components |
| 1726 | */ |
Eric Moore | e80b002 | 2007-09-14 18:49:03 -0600 | [diff] [blame] | 1727 | if (mptscsih_is_phys_disk(ioc, channel, id)) { |
| 1728 | id = mptscsih_raid_id_to_num(ioc, |
Eric Moore | 793955f | 2007-01-29 09:42:20 -0700 | [diff] [blame] | 1729 | channel, id); |
Eric Moore | 547f9a2 | 2006-06-27 14:42:12 -0600 | [diff] [blame] | 1730 | vtarget->tflags |= |
| 1731 | MPT_TARGET_FLAGS_RAID_COMPONENT; |
Eric Moore | b506ade | 2007-01-29 09:45:37 -0700 | [diff] [blame] | 1732 | p->phy_info[i].attached.phys_disk_num = id; |
Eric Moore | 547f9a2 | 2006-06-27 14:42:12 -0600 | [diff] [blame] | 1733 | } |
Eric Moore | e80b002 | 2007-09-14 18:49:03 -0600 | [diff] [blame] | 1734 | mutex_unlock(&ioc->sas_topology_mutex); |
Eric Moore | 547f9a2 | 2006-06-27 14:42:12 -0600 | [diff] [blame] | 1735 | goto out; |
| 1736 | } |
| 1737 | } |
Eric Moore | e80b002 | 2007-09-14 18:49:03 -0600 | [diff] [blame] | 1738 | mutex_unlock(&ioc->sas_topology_mutex); |
Eric Moore | 547f9a2 | 2006-06-27 14:42:12 -0600 | [diff] [blame] | 1739 | |
| 1740 | kfree(vtarget); |
| 1741 | return -ENXIO; |
| 1742 | |
| 1743 | out: |
Eric Moore | 793955f | 2007-01-29 09:42:20 -0700 | [diff] [blame] | 1744 | vtarget->id = id; |
| 1745 | vtarget->channel = channel; |
Eric Moore | 547f9a2 | 2006-06-27 14:42:12 -0600 | [diff] [blame] | 1746 | starget->hostdata = vtarget; |
| 1747 | return 0; |
| 1748 | } |
| 1749 | |
| 1750 | static void |
| 1751 | mptsas_target_destroy(struct scsi_target *starget) |
| 1752 | { |
| 1753 | struct Scsi_Host *host = dev_to_shost(&starget->dev); |
Eric Moore | e7eae9f | 2007-09-29 10:15:59 -0600 | [diff] [blame] | 1754 | MPT_SCSI_HOST *hd = shost_priv(host); |
Eric Moore | 547f9a2 | 2006-06-27 14:42:12 -0600 | [diff] [blame] | 1755 | struct sas_rphy *rphy; |
| 1756 | struct mptsas_portinfo *p; |
| 1757 | int i; |
Kashyap, Desai | 3eb0822c | 2009-05-29 16:47:26 +0530 | [diff] [blame] | 1758 | MPT_ADAPTER *ioc = hd->ioc; |
| 1759 | VirtTarget *vtarget; |
Eric Moore | 547f9a2 | 2006-06-27 14:42:12 -0600 | [diff] [blame] | 1760 | |
| 1761 | if (!starget->hostdata) |
| 1762 | return; |
| 1763 | |
Kashyap, Desai | 3eb0822c | 2009-05-29 16:47:26 +0530 | [diff] [blame] | 1764 | vtarget = starget->hostdata; |
| 1765 | |
Kashyap, Desai | 57e9851 | 2009-05-29 16:55:09 +0530 | [diff] [blame] | 1766 | mptsas_del_device_component_by_os(ioc, starget->channel, |
| 1767 | starget->id); |
| 1768 | |
Kashyap, Desai | 3eb0822c | 2009-05-29 16:47:26 +0530 | [diff] [blame] | 1769 | |
James Bottomley | e8bf394 | 2006-07-11 17:49:34 -0400 | [diff] [blame] | 1770 | if (starget->channel == MPTSAS_RAID_CHANNEL) |
Eric Moore | 547f9a2 | 2006-06-27 14:42:12 -0600 | [diff] [blame] | 1771 | goto out; |
| 1772 | |
| 1773 | rphy = dev_to_rphy(starget->dev.parent); |
Eric Moore | e80b002 | 2007-09-14 18:49:03 -0600 | [diff] [blame] | 1774 | list_for_each_entry(p, &ioc->sas_topology, list) { |
Eric Moore | 547f9a2 | 2006-06-27 14:42:12 -0600 | [diff] [blame] | 1775 | for (i = 0; i < p->num_phys; i++) { |
| 1776 | if (p->phy_info[i].attached.sas_address != |
| 1777 | rphy->identify.sas_address) |
| 1778 | continue; |
Kashyap, Desai | 3eb0822c | 2009-05-29 16:47:26 +0530 | [diff] [blame] | 1779 | |
| 1780 | starget_printk(KERN_INFO, starget, MYIOC_s_FMT |
| 1781 | "delete device: fw_channel %d, fw_id %d, phy %d, " |
| 1782 | "sas_addr 0x%llx\n", ioc->name, |
| 1783 | p->phy_info[i].attached.channel, |
| 1784 | p->phy_info[i].attached.id, |
| 1785 | p->phy_info[i].attached.phy_id, (unsigned long long) |
| 1786 | p->phy_info[i].attached.sas_address); |
| 1787 | |
Eric Moore | 547f9a2 | 2006-06-27 14:42:12 -0600 | [diff] [blame] | 1788 | mptsas_set_starget(&p->phy_info[i], NULL); |
Eric Moore | 547f9a2 | 2006-06-27 14:42:12 -0600 | [diff] [blame] | 1789 | } |
| 1790 | } |
| 1791 | |
| 1792 | out: |
Kashyap, Desai | 3eb0822c | 2009-05-29 16:47:26 +0530 | [diff] [blame] | 1793 | vtarget->starget = NULL; |
Eric Moore | 547f9a2 | 2006-06-27 14:42:12 -0600 | [diff] [blame] | 1794 | kfree(starget->hostdata); |
| 1795 | starget->hostdata = NULL; |
| 1796 | } |
| 1797 | |
| 1798 | |
Christoph Hellwig | 0c33b27 | 2005-09-09 16:27:19 +0200 | [diff] [blame] | 1799 | static int |
Moore, Eric Dean | c7c8298 | 2005-11-16 18:54:25 -0700 | [diff] [blame] | 1800 | mptsas_slave_alloc(struct scsi_device *sdev) |
Christoph Hellwig | 0c33b27 | 2005-09-09 16:27:19 +0200 | [diff] [blame] | 1801 | { |
Moore, Eric Dean | c7c8298 | 2005-11-16 18:54:25 -0700 | [diff] [blame] | 1802 | struct Scsi_Host *host = sdev->host; |
Eric Moore | e7eae9f | 2007-09-29 10:15:59 -0600 | [diff] [blame] | 1803 | MPT_SCSI_HOST *hd = shost_priv(host); |
Christoph Hellwig | 0c33b27 | 2005-09-09 16:27:19 +0200 | [diff] [blame] | 1804 | struct sas_rphy *rphy; |
| 1805 | struct mptsas_portinfo *p; |
Eric Moore | a69de50 | 2007-09-14 18:48:19 -0600 | [diff] [blame] | 1806 | VirtDevice *vdevice; |
Moore, Eric Dean | c7c8298 | 2005-11-16 18:54:25 -0700 | [diff] [blame] | 1807 | struct scsi_target *starget; |
Eric Moore | 547f9a2 | 2006-06-27 14:42:12 -0600 | [diff] [blame] | 1808 | int i; |
Eric Moore | e80b002 | 2007-09-14 18:49:03 -0600 | [diff] [blame] | 1809 | MPT_ADAPTER *ioc = hd->ioc; |
Christoph Hellwig | 0c33b27 | 2005-09-09 16:27:19 +0200 | [diff] [blame] | 1810 | |
Eric Moore | a69de50 | 2007-09-14 18:48:19 -0600 | [diff] [blame] | 1811 | vdevice = kzalloc(sizeof(VirtDevice), GFP_KERNEL); |
| 1812 | if (!vdevice) { |
Eric Moore | 547f9a2 | 2006-06-27 14:42:12 -0600 | [diff] [blame] | 1813 | printk(MYIOC_s_ERR_FMT "slave_alloc kzalloc(%zd) FAILED!\n", |
Eric Moore | e80b002 | 2007-09-14 18:49:03 -0600 | [diff] [blame] | 1814 | ioc->name, sizeof(VirtDevice)); |
Christoph Hellwig | 0c33b27 | 2005-09-09 16:27:19 +0200 | [diff] [blame] | 1815 | return -ENOMEM; |
| 1816 | } |
Moore, Eric Dean | c7c8298 | 2005-11-16 18:54:25 -0700 | [diff] [blame] | 1817 | starget = scsi_target(sdev); |
Eric Moore | a69de50 | 2007-09-14 18:48:19 -0600 | [diff] [blame] | 1818 | vdevice->vtarget = starget->hostdata; |
Christoph Hellwig | 0c33b27 | 2005-09-09 16:27:19 +0200 | [diff] [blame] | 1819 | |
James Bottomley | e8bf394 | 2006-07-11 17:49:34 -0400 | [diff] [blame] | 1820 | if (sdev->channel == MPTSAS_RAID_CHANNEL) |
Moore, Eric | 816aa90 | 2006-01-13 16:25:20 -0700 | [diff] [blame] | 1821 | goto out; |
Moore, Eric | 816aa90 | 2006-01-13 16:25:20 -0700 | [diff] [blame] | 1822 | |
Moore, Eric Dean | c7c8298 | 2005-11-16 18:54:25 -0700 | [diff] [blame] | 1823 | rphy = dev_to_rphy(sdev->sdev_target->dev.parent); |
Eric Moore | e80b002 | 2007-09-14 18:49:03 -0600 | [diff] [blame] | 1824 | mutex_lock(&ioc->sas_topology_mutex); |
| 1825 | list_for_each_entry(p, &ioc->sas_topology, list) { |
Christoph Hellwig | 0c33b27 | 2005-09-09 16:27:19 +0200 | [diff] [blame] | 1826 | for (i = 0; i < p->num_phys; i++) { |
Eric Moore | 547f9a2 | 2006-06-27 14:42:12 -0600 | [diff] [blame] | 1827 | if (p->phy_info[i].attached.sas_address != |
| 1828 | rphy->identify.sas_address) |
| 1829 | continue; |
Eric Moore | a69de50 | 2007-09-14 18:48:19 -0600 | [diff] [blame] | 1830 | vdevice->lun = sdev->lun; |
Eric Moore | 547f9a2 | 2006-06-27 14:42:12 -0600 | [diff] [blame] | 1831 | /* |
| 1832 | * Exposing hidden raid components |
| 1833 | */ |
Eric Moore | e80b002 | 2007-09-14 18:49:03 -0600 | [diff] [blame] | 1834 | if (mptscsih_is_phys_disk(ioc, |
Eric Moore | 793955f | 2007-01-29 09:42:20 -0700 | [diff] [blame] | 1835 | p->phy_info[i].attached.channel, |
| 1836 | p->phy_info[i].attached.id)) |
Eric Moore | 547f9a2 | 2006-06-27 14:42:12 -0600 | [diff] [blame] | 1837 | sdev->no_uld_attach = 1; |
Eric Moore | e80b002 | 2007-09-14 18:49:03 -0600 | [diff] [blame] | 1838 | mutex_unlock(&ioc->sas_topology_mutex); |
Eric Moore | 547f9a2 | 2006-06-27 14:42:12 -0600 | [diff] [blame] | 1839 | goto out; |
Christoph Hellwig | 0c33b27 | 2005-09-09 16:27:19 +0200 | [diff] [blame] | 1840 | } |
| 1841 | } |
Eric Moore | e80b002 | 2007-09-14 18:49:03 -0600 | [diff] [blame] | 1842 | mutex_unlock(&ioc->sas_topology_mutex); |
Christoph Hellwig | 0c33b27 | 2005-09-09 16:27:19 +0200 | [diff] [blame] | 1843 | |
Eric Moore | a69de50 | 2007-09-14 18:48:19 -0600 | [diff] [blame] | 1844 | kfree(vdevice); |
Christoph Hellwig | 23f236e | 2006-01-30 19:00:43 +0100 | [diff] [blame] | 1845 | return -ENXIO; |
Christoph Hellwig | 0c33b27 | 2005-09-09 16:27:19 +0200 | [diff] [blame] | 1846 | |
| 1847 | out: |
Eric Moore | a69de50 | 2007-09-14 18:48:19 -0600 | [diff] [blame] | 1848 | vdevice->vtarget->num_luns++; |
| 1849 | sdev->hostdata = vdevice; |
Christoph Hellwig | 0c33b27 | 2005-09-09 16:27:19 +0200 | [diff] [blame] | 1850 | return 0; |
| 1851 | } |
| 1852 | |
Eric Moore | 547f9a2 | 2006-06-27 14:42:12 -0600 | [diff] [blame] | 1853 | static int |
| 1854 | mptsas_qcmd(struct scsi_cmnd *SCpnt, void (*done)(struct scsi_cmnd *)) |
Christoph Hellwig | 9a28f49 | 2006-01-13 18:04:41 +0100 | [diff] [blame] | 1855 | { |
Kashyap, Desai | 7b5a65b | 2009-05-29 16:38:14 +0530 | [diff] [blame] | 1856 | MPT_SCSI_HOST *hd; |
| 1857 | MPT_ADAPTER *ioc; |
Eric Moore | a69de50 | 2007-09-14 18:48:19 -0600 | [diff] [blame] | 1858 | VirtDevice *vdevice = SCpnt->device->hostdata; |
Christoph Hellwig | 9a28f49 | 2006-01-13 18:04:41 +0100 | [diff] [blame] | 1859 | |
Eric Moore | a69de50 | 2007-09-14 18:48:19 -0600 | [diff] [blame] | 1860 | if (!vdevice || !vdevice->vtarget || vdevice->vtarget->deleted) { |
Eric Moore | 547f9a2 | 2006-06-27 14:42:12 -0600 | [diff] [blame] | 1861 | SCpnt->result = DID_NO_CONNECT << 16; |
| 1862 | done(SCpnt); |
| 1863 | return 0; |
Moore, Eric | 7d3eecf | 2006-01-25 18:05:12 -0700 | [diff] [blame] | 1864 | } |
Eric Moore | 547f9a2 | 2006-06-27 14:42:12 -0600 | [diff] [blame] | 1865 | |
Kashyap, Desai | 7b5a65b | 2009-05-29 16:38:14 +0530 | [diff] [blame] | 1866 | hd = shost_priv(SCpnt->device->host); |
| 1867 | ioc = hd->ioc; |
| 1868 | |
| 1869 | if (ioc->sas_discovery_quiesce_io) |
| 1870 | return SCSI_MLQUEUE_HOST_BUSY; |
| 1871 | |
Eric Moore | 793955f | 2007-01-29 09:42:20 -0700 | [diff] [blame] | 1872 | // scsi_print_command(SCpnt); |
| 1873 | |
Eric Moore | 547f9a2 | 2006-06-27 14:42:12 -0600 | [diff] [blame] | 1874 | return mptscsih_qcmd(SCpnt,done); |
Christoph Hellwig | 9a28f49 | 2006-01-13 18:04:41 +0100 | [diff] [blame] | 1875 | } |
| 1876 | |
Eric Moore | 547f9a2 | 2006-06-27 14:42:12 -0600 | [diff] [blame] | 1877 | |
Christoph Hellwig | 0c33b27 | 2005-09-09 16:27:19 +0200 | [diff] [blame] | 1878 | static struct scsi_host_template mptsas_driver_template = { |
Moore, Eric Dean | f78496d | 2005-11-16 18:54:14 -0700 | [diff] [blame] | 1879 | .module = THIS_MODULE, |
Christoph Hellwig | 0c33b27 | 2005-09-09 16:27:19 +0200 | [diff] [blame] | 1880 | .proc_name = "mptsas", |
| 1881 | .proc_info = mptscsih_proc_info, |
| 1882 | .name = "MPT SPI Host", |
| 1883 | .info = mptscsih_info, |
Eric Moore | 547f9a2 | 2006-06-27 14:42:12 -0600 | [diff] [blame] | 1884 | .queuecommand = mptsas_qcmd, |
| 1885 | .target_alloc = mptsas_target_alloc, |
Christoph Hellwig | 0c33b27 | 2005-09-09 16:27:19 +0200 | [diff] [blame] | 1886 | .slave_alloc = mptsas_slave_alloc, |
James Bottomley | f013db3 | 2006-03-18 14:54:36 -0600 | [diff] [blame] | 1887 | .slave_configure = mptsas_slave_configure, |
Eric Moore | 547f9a2 | 2006-06-27 14:42:12 -0600 | [diff] [blame] | 1888 | .target_destroy = mptsas_target_destroy, |
| 1889 | .slave_destroy = mptscsih_slave_destroy, |
Christoph Hellwig | 0c33b27 | 2005-09-09 16:27:19 +0200 | [diff] [blame] | 1890 | .change_queue_depth = mptscsih_change_queue_depth, |
| 1891 | .eh_abort_handler = mptscsih_abort, |
| 1892 | .eh_device_reset_handler = mptscsih_dev_reset, |
| 1893 | .eh_bus_reset_handler = mptscsih_bus_reset, |
| 1894 | .eh_host_reset_handler = mptscsih_host_reset, |
| 1895 | .bios_param = mptscsih_bios_param, |
| 1896 | .can_queue = MPT_FC_CAN_QUEUE, |
| 1897 | .this_id = -1, |
| 1898 | .sg_tablesize = MPT_SCSI_SG_DEPTH, |
| 1899 | .max_sectors = 8192, |
| 1900 | .cmd_per_lun = 7, |
| 1901 | .use_clustering = ENABLE_CLUSTERING, |
Prakash, Sathya | edb9068 | 2007-07-17 14:39:14 +0530 | [diff] [blame] | 1902 | .shost_attrs = mptscsih_host_attrs, |
Christoph Hellwig | 0c33b27 | 2005-09-09 16:27:19 +0200 | [diff] [blame] | 1903 | }; |
| 1904 | |
Christoph Hellwig | b514112 | 2005-10-28 22:07:41 +0200 | [diff] [blame] | 1905 | static int mptsas_get_linkerrors(struct sas_phy *phy) |
| 1906 | { |
| 1907 | MPT_ADAPTER *ioc = phy_to_ioc(phy); |
| 1908 | ConfigExtendedPageHeader_t hdr; |
| 1909 | CONFIGPARMS cfg; |
| 1910 | SasPhyPage1_t *buffer; |
| 1911 | dma_addr_t dma_handle; |
| 1912 | int error; |
| 1913 | |
James Bottomley | f4ad7b5 | 2006-08-25 13:48:18 -0500 | [diff] [blame] | 1914 | /* FIXME: only have link errors on local phys */ |
| 1915 | if (!scsi_is_sas_phy_local(phy)) |
| 1916 | return -EINVAL; |
| 1917 | |
Christoph Hellwig | b514112 | 2005-10-28 22:07:41 +0200 | [diff] [blame] | 1918 | hdr.PageVersion = MPI_SASPHY1_PAGEVERSION; |
| 1919 | hdr.ExtPageLength = 0; |
| 1920 | hdr.PageNumber = 1 /* page number 1*/; |
| 1921 | hdr.Reserved1 = 0; |
| 1922 | hdr.Reserved2 = 0; |
| 1923 | hdr.PageType = MPI_CONFIG_PAGETYPE_EXTENDED; |
| 1924 | hdr.ExtPageType = MPI_CONFIG_EXTPAGETYPE_SAS_PHY; |
| 1925 | |
| 1926 | cfg.cfghdr.ehdr = &hdr; |
| 1927 | cfg.physAddr = -1; |
| 1928 | cfg.pageAddr = phy->identify.phy_identifier; |
| 1929 | cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER; |
| 1930 | cfg.dir = 0; /* read */ |
| 1931 | cfg.timeout = 10; |
| 1932 | |
| 1933 | error = mpt_config(ioc, &cfg); |
| 1934 | if (error) |
| 1935 | return error; |
| 1936 | if (!hdr.ExtPageLength) |
| 1937 | return -ENXIO; |
| 1938 | |
| 1939 | buffer = pci_alloc_consistent(ioc->pcidev, hdr.ExtPageLength * 4, |
| 1940 | &dma_handle); |
| 1941 | if (!buffer) |
| 1942 | return -ENOMEM; |
| 1943 | |
| 1944 | cfg.physAddr = dma_handle; |
| 1945 | cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT; |
| 1946 | |
| 1947 | error = mpt_config(ioc, &cfg); |
| 1948 | if (error) |
| 1949 | goto out_free_consistent; |
| 1950 | |
Prakash, Sathya | d6ecdd6 | 2007-07-24 15:47:41 +0530 | [diff] [blame] | 1951 | mptsas_print_phy_pg1(ioc, buffer); |
Christoph Hellwig | b514112 | 2005-10-28 22:07:41 +0200 | [diff] [blame] | 1952 | |
| 1953 | phy->invalid_dword_count = le32_to_cpu(buffer->InvalidDwordCount); |
| 1954 | phy->running_disparity_error_count = |
| 1955 | le32_to_cpu(buffer->RunningDisparityErrorCount); |
| 1956 | phy->loss_of_dword_sync_count = |
| 1957 | le32_to_cpu(buffer->LossDwordSynchCount); |
| 1958 | phy->phy_reset_problem_count = |
| 1959 | le32_to_cpu(buffer->PhyResetProblemCount); |
| 1960 | |
| 1961 | out_free_consistent: |
| 1962 | pci_free_consistent(ioc->pcidev, hdr.ExtPageLength * 4, |
| 1963 | buffer, dma_handle); |
| 1964 | return error; |
| 1965 | } |
| 1966 | |
Christoph Hellwig | da4fa65 | 2005-10-19 20:01:42 +0200 | [diff] [blame] | 1967 | static int mptsas_mgmt_done(MPT_ADAPTER *ioc, MPT_FRAME_HDR *req, |
| 1968 | MPT_FRAME_HDR *reply) |
| 1969 | { |
Kashyap, Desai | f0f09d3 | 2009-05-29 16:40:57 +0530 | [diff] [blame] | 1970 | ioc->sas_mgmt.status |= MPT_MGMT_STATUS_COMMAND_GOOD; |
Christoph Hellwig | da4fa65 | 2005-10-19 20:01:42 +0200 | [diff] [blame] | 1971 | if (reply != NULL) { |
Kashyap, Desai | f0f09d3 | 2009-05-29 16:40:57 +0530 | [diff] [blame] | 1972 | ioc->sas_mgmt.status |= MPT_MGMT_STATUS_RF_VALID; |
Christoph Hellwig | da4fa65 | 2005-10-19 20:01:42 +0200 | [diff] [blame] | 1973 | memcpy(ioc->sas_mgmt.reply, reply, |
| 1974 | min(ioc->reply_sz, 4 * reply->u.reply.MsgLength)); |
| 1975 | } |
Kashyap, Desai | 2f18786 | 2009-05-29 16:52:37 +0530 | [diff] [blame] | 1976 | |
| 1977 | if (ioc->sas_mgmt.status & MPT_MGMT_STATUS_PENDING) { |
| 1978 | ioc->sas_mgmt.status &= ~MPT_MGMT_STATUS_PENDING; |
| 1979 | complete(&ioc->sas_mgmt.done); |
| 1980 | return 1; |
| 1981 | } |
| 1982 | return 0; |
Christoph Hellwig | da4fa65 | 2005-10-19 20:01:42 +0200 | [diff] [blame] | 1983 | } |
| 1984 | |
| 1985 | static int mptsas_phy_reset(struct sas_phy *phy, int hard_reset) |
| 1986 | { |
| 1987 | MPT_ADAPTER *ioc = phy_to_ioc(phy); |
| 1988 | SasIoUnitControlRequest_t *req; |
| 1989 | SasIoUnitControlReply_t *reply; |
| 1990 | MPT_FRAME_HDR *mf; |
| 1991 | MPIHeader_t *hdr; |
| 1992 | unsigned long timeleft; |
| 1993 | int error = -ERESTARTSYS; |
| 1994 | |
James Bottomley | f4ad7b5 | 2006-08-25 13:48:18 -0500 | [diff] [blame] | 1995 | /* FIXME: fusion doesn't allow non-local phy reset */ |
| 1996 | if (!scsi_is_sas_phy_local(phy)) |
| 1997 | return -EINVAL; |
| 1998 | |
Christoph Hellwig | da4fa65 | 2005-10-19 20:01:42 +0200 | [diff] [blame] | 1999 | /* not implemented for expanders */ |
| 2000 | if (phy->identify.target_port_protocols & SAS_PROTOCOL_SMP) |
| 2001 | return -ENXIO; |
| 2002 | |
Christoph Hellwig | eeb846c | 2006-01-13 18:27:11 +0100 | [diff] [blame] | 2003 | if (mutex_lock_interruptible(&ioc->sas_mgmt.mutex)) |
Christoph Hellwig | da4fa65 | 2005-10-19 20:01:42 +0200 | [diff] [blame] | 2004 | goto out; |
| 2005 | |
| 2006 | mf = mpt_get_msg_frame(mptsasMgmtCtx, ioc); |
| 2007 | if (!mf) { |
| 2008 | error = -ENOMEM; |
| 2009 | goto out_unlock; |
| 2010 | } |
| 2011 | |
| 2012 | hdr = (MPIHeader_t *) mf; |
| 2013 | req = (SasIoUnitControlRequest_t *)mf; |
| 2014 | memset(req, 0, sizeof(SasIoUnitControlRequest_t)); |
| 2015 | req->Function = MPI_FUNCTION_SAS_IO_UNIT_CONTROL; |
| 2016 | req->MsgContext = hdr->MsgContext; |
| 2017 | req->Operation = hard_reset ? |
| 2018 | MPI_SAS_OP_PHY_HARD_RESET : MPI_SAS_OP_PHY_LINK_RESET; |
| 2019 | req->PhyNum = phy->identify.phy_identifier; |
| 2020 | |
Kashyap, Desai | 2f18786 | 2009-05-29 16:52:37 +0530 | [diff] [blame] | 2021 | INITIALIZE_MGMT_STATUS(ioc->sas_mgmt.status) |
Christoph Hellwig | da4fa65 | 2005-10-19 20:01:42 +0200 | [diff] [blame] | 2022 | mpt_put_msg_frame(mptsasMgmtCtx, ioc, mf); |
| 2023 | |
| 2024 | timeleft = wait_for_completion_timeout(&ioc->sas_mgmt.done, |
| 2025 | 10 * HZ); |
| 2026 | if (!timeleft) { |
| 2027 | /* On timeout reset the board */ |
| 2028 | mpt_free_msg_frame(ioc, mf); |
| 2029 | mpt_HardResetHandler(ioc, CAN_SLEEP); |
| 2030 | error = -ETIMEDOUT; |
| 2031 | goto out_unlock; |
| 2032 | } |
| 2033 | |
| 2034 | /* a reply frame is expected */ |
| 2035 | if ((ioc->sas_mgmt.status & |
Kashyap, Desai | f0f09d3 | 2009-05-29 16:40:57 +0530 | [diff] [blame] | 2036 | MPT_MGMT_STATUS_RF_VALID) == 0) { |
Christoph Hellwig | da4fa65 | 2005-10-19 20:01:42 +0200 | [diff] [blame] | 2037 | error = -ENXIO; |
| 2038 | goto out_unlock; |
| 2039 | } |
| 2040 | |
| 2041 | /* process the completed Reply Message Frame */ |
| 2042 | reply = (SasIoUnitControlReply_t *)ioc->sas_mgmt.reply; |
| 2043 | if (reply->IOCStatus != MPI_IOCSTATUS_SUCCESS) { |
Eric Moore | 29dd360 | 2007-09-14 18:46:51 -0600 | [diff] [blame] | 2044 | printk(MYIOC_s_INFO_FMT "%s: IOCStatus=0x%X IOCLogInfo=0x%X\n", |
Harvey Harrison | cadbd4a | 2008-07-03 23:47:27 -0700 | [diff] [blame] | 2045 | ioc->name, __func__, reply->IOCStatus, reply->IOCLogInfo); |
Christoph Hellwig | da4fa65 | 2005-10-19 20:01:42 +0200 | [diff] [blame] | 2046 | error = -ENXIO; |
| 2047 | goto out_unlock; |
| 2048 | } |
| 2049 | |
| 2050 | error = 0; |
| 2051 | |
| 2052 | out_unlock: |
Kashyap, Desai | 2f18786 | 2009-05-29 16:52:37 +0530 | [diff] [blame] | 2053 | CLEAR_MGMT_STATUS(ioc->sas_mgmt.status) |
Christoph Hellwig | eeb846c | 2006-01-13 18:27:11 +0100 | [diff] [blame] | 2054 | mutex_unlock(&ioc->sas_mgmt.mutex); |
Christoph Hellwig | da4fa65 | 2005-10-19 20:01:42 +0200 | [diff] [blame] | 2055 | out: |
| 2056 | return error; |
| 2057 | } |
Christoph Hellwig | b514112 | 2005-10-28 22:07:41 +0200 | [diff] [blame] | 2058 | |
Christoph Hellwig | e309444 | 2006-02-16 13:25:36 +0100 | [diff] [blame] | 2059 | static int |
| 2060 | mptsas_get_enclosure_identifier(struct sas_rphy *rphy, u64 *identifier) |
| 2061 | { |
| 2062 | MPT_ADAPTER *ioc = rphy_to_ioc(rphy); |
| 2063 | int i, error; |
| 2064 | struct mptsas_portinfo *p; |
| 2065 | struct mptsas_enclosure enclosure_info; |
| 2066 | u64 enclosure_handle; |
| 2067 | |
| 2068 | mutex_lock(&ioc->sas_topology_mutex); |
| 2069 | list_for_each_entry(p, &ioc->sas_topology, list) { |
| 2070 | for (i = 0; i < p->num_phys; i++) { |
| 2071 | if (p->phy_info[i].attached.sas_address == |
| 2072 | rphy->identify.sas_address) { |
| 2073 | enclosure_handle = p->phy_info[i]. |
| 2074 | attached.handle_enclosure; |
| 2075 | goto found_info; |
| 2076 | } |
| 2077 | } |
| 2078 | } |
| 2079 | mutex_unlock(&ioc->sas_topology_mutex); |
| 2080 | return -ENXIO; |
| 2081 | |
| 2082 | found_info: |
| 2083 | mutex_unlock(&ioc->sas_topology_mutex); |
| 2084 | memset(&enclosure_info, 0, sizeof(struct mptsas_enclosure)); |
Moore, Eric | 5243543 | 2006-03-14 09:14:15 -0700 | [diff] [blame] | 2085 | error = mptsas_sas_enclosure_pg0(ioc, &enclosure_info, |
Christoph Hellwig | e309444 | 2006-02-16 13:25:36 +0100 | [diff] [blame] | 2086 | (MPI_SAS_ENCLOS_PGAD_FORM_HANDLE << |
| 2087 | MPI_SAS_ENCLOS_PGAD_FORM_SHIFT), enclosure_handle); |
| 2088 | if (!error) |
| 2089 | *identifier = enclosure_info.enclosure_logical_id; |
| 2090 | return error; |
| 2091 | } |
| 2092 | |
| 2093 | static int |
| 2094 | mptsas_get_bay_identifier(struct sas_rphy *rphy) |
| 2095 | { |
| 2096 | MPT_ADAPTER *ioc = rphy_to_ioc(rphy); |
| 2097 | struct mptsas_portinfo *p; |
| 2098 | int i, rc; |
| 2099 | |
| 2100 | mutex_lock(&ioc->sas_topology_mutex); |
| 2101 | list_for_each_entry(p, &ioc->sas_topology, list) { |
| 2102 | for (i = 0; i < p->num_phys; i++) { |
| 2103 | if (p->phy_info[i].attached.sas_address == |
| 2104 | rphy->identify.sas_address) { |
| 2105 | rc = p->phy_info[i].attached.slot; |
| 2106 | goto out; |
| 2107 | } |
| 2108 | } |
| 2109 | } |
| 2110 | rc = -ENXIO; |
| 2111 | out: |
| 2112 | mutex_unlock(&ioc->sas_topology_mutex); |
| 2113 | return rc; |
| 2114 | } |
| 2115 | |
FUJITA Tomonori | 159e36f | 2007-07-30 11:10:07 -0600 | [diff] [blame] | 2116 | static int mptsas_smp_handler(struct Scsi_Host *shost, struct sas_rphy *rphy, |
| 2117 | struct request *req) |
| 2118 | { |
| 2119 | MPT_ADAPTER *ioc = ((MPT_SCSI_HOST *) shost->hostdata)->ioc; |
| 2120 | MPT_FRAME_HDR *mf; |
| 2121 | SmpPassthroughRequest_t *smpreq; |
| 2122 | struct request *rsp = req->next_rq; |
| 2123 | int ret; |
| 2124 | int flagsLength; |
| 2125 | unsigned long timeleft; |
| 2126 | char *psge; |
| 2127 | dma_addr_t dma_addr_in = 0; |
| 2128 | dma_addr_t dma_addr_out = 0; |
| 2129 | u64 sas_address = 0; |
| 2130 | |
| 2131 | if (!rsp) { |
Eric Moore | 29dd360 | 2007-09-14 18:46:51 -0600 | [diff] [blame] | 2132 | printk(MYIOC_s_ERR_FMT "%s: the smp response space is missing\n", |
Harvey Harrison | cadbd4a | 2008-07-03 23:47:27 -0700 | [diff] [blame] | 2133 | ioc->name, __func__); |
FUJITA Tomonori | 159e36f | 2007-07-30 11:10:07 -0600 | [diff] [blame] | 2134 | return -EINVAL; |
| 2135 | } |
| 2136 | |
| 2137 | /* do we need to support multiple segments? */ |
| 2138 | if (req->bio->bi_vcnt > 1 || rsp->bio->bi_vcnt > 1) { |
Eric Moore | 29dd360 | 2007-09-14 18:46:51 -0600 | [diff] [blame] | 2139 | printk(MYIOC_s_ERR_FMT "%s: multiple segments req %u %u, rsp %u %u\n", |
Harvey Harrison | cadbd4a | 2008-07-03 23:47:27 -0700 | [diff] [blame] | 2140 | ioc->name, __func__, req->bio->bi_vcnt, req->data_len, |
Eric Moore | 29dd360 | 2007-09-14 18:46:51 -0600 | [diff] [blame] | 2141 | rsp->bio->bi_vcnt, rsp->data_len); |
FUJITA Tomonori | 159e36f | 2007-07-30 11:10:07 -0600 | [diff] [blame] | 2142 | return -EINVAL; |
| 2143 | } |
| 2144 | |
| 2145 | ret = mutex_lock_interruptible(&ioc->sas_mgmt.mutex); |
| 2146 | if (ret) |
| 2147 | goto out; |
| 2148 | |
| 2149 | mf = mpt_get_msg_frame(mptsasMgmtCtx, ioc); |
| 2150 | if (!mf) { |
| 2151 | ret = -ENOMEM; |
| 2152 | goto out_unlock; |
| 2153 | } |
| 2154 | |
| 2155 | smpreq = (SmpPassthroughRequest_t *)mf; |
| 2156 | memset(smpreq, 0, sizeof(*smpreq)); |
| 2157 | |
| 2158 | smpreq->RequestDataLength = cpu_to_le16(req->data_len - 4); |
| 2159 | smpreq->Function = MPI_FUNCTION_SMP_PASSTHROUGH; |
| 2160 | |
| 2161 | if (rphy) |
| 2162 | sas_address = rphy->identify.sas_address; |
| 2163 | else { |
| 2164 | struct mptsas_portinfo *port_info; |
| 2165 | |
| 2166 | mutex_lock(&ioc->sas_topology_mutex); |
Kashyap, Desai | f9c3402 | 2009-05-29 16:49:36 +0530 | [diff] [blame] | 2167 | port_info = ioc->hba_port_info; |
FUJITA Tomonori | 159e36f | 2007-07-30 11:10:07 -0600 | [diff] [blame] | 2168 | if (port_info && port_info->phy_info) |
| 2169 | sas_address = |
| 2170 | port_info->phy_info[0].phy->identify.sas_address; |
| 2171 | mutex_unlock(&ioc->sas_topology_mutex); |
| 2172 | } |
| 2173 | |
| 2174 | *((u64 *)&smpreq->SASAddress) = cpu_to_le64(sas_address); |
| 2175 | |
| 2176 | psge = (char *) |
| 2177 | (((int *) mf) + (offsetof(SmpPassthroughRequest_t, SGL) / 4)); |
| 2178 | |
| 2179 | /* request */ |
| 2180 | flagsLength = (MPI_SGE_FLAGS_SIMPLE_ELEMENT | |
| 2181 | MPI_SGE_FLAGS_END_OF_BUFFER | |
Kashyap, Desai | 14d0f0b | 2009-05-29 16:37:04 +0530 | [diff] [blame] | 2182 | MPI_SGE_FLAGS_DIRECTION) |
| 2183 | << MPI_SGE_FLAGS_SHIFT; |
FUJITA Tomonori | 159e36f | 2007-07-30 11:10:07 -0600 | [diff] [blame] | 2184 | flagsLength |= (req->data_len - 4); |
| 2185 | |
| 2186 | dma_addr_out = pci_map_single(ioc->pcidev, bio_data(req->bio), |
| 2187 | req->data_len, PCI_DMA_BIDIRECTIONAL); |
| 2188 | if (!dma_addr_out) |
| 2189 | goto put_mf; |
Kashyap, Desai | 14d0f0b | 2009-05-29 16:37:04 +0530 | [diff] [blame] | 2190 | ioc->add_sge(psge, flagsLength, dma_addr_out); |
Kashyap, Desai | 2f18786 | 2009-05-29 16:52:37 +0530 | [diff] [blame] | 2191 | psge += ioc->SGE_size; |
FUJITA Tomonori | 159e36f | 2007-07-30 11:10:07 -0600 | [diff] [blame] | 2192 | |
| 2193 | /* response */ |
Kashyap, Desai | 2f18786 | 2009-05-29 16:52:37 +0530 | [diff] [blame] | 2194 | flagsLength = MPI_SGE_FLAGS_SIMPLE_ELEMENT | |
| 2195 | MPI_SGE_FLAGS_SYSTEM_ADDRESS | |
| 2196 | MPI_SGE_FLAGS_IOC_TO_HOST | |
| 2197 | MPI_SGE_FLAGS_END_OF_BUFFER; |
| 2198 | |
| 2199 | flagsLength = flagsLength << MPI_SGE_FLAGS_SHIFT; |
FUJITA Tomonori | 159e36f | 2007-07-30 11:10:07 -0600 | [diff] [blame] | 2200 | flagsLength |= rsp->data_len + 4; |
| 2201 | dma_addr_in = pci_map_single(ioc->pcidev, bio_data(rsp->bio), |
| 2202 | rsp->data_len, PCI_DMA_BIDIRECTIONAL); |
| 2203 | if (!dma_addr_in) |
| 2204 | goto unmap; |
Kashyap, Desai | 14d0f0b | 2009-05-29 16:37:04 +0530 | [diff] [blame] | 2205 | ioc->add_sge(psge, flagsLength, dma_addr_in); |
FUJITA Tomonori | 159e36f | 2007-07-30 11:10:07 -0600 | [diff] [blame] | 2206 | |
Kashyap, Desai | 2f18786 | 2009-05-29 16:52:37 +0530 | [diff] [blame] | 2207 | INITIALIZE_MGMT_STATUS(ioc->sas_mgmt.status) |
FUJITA Tomonori | 159e36f | 2007-07-30 11:10:07 -0600 | [diff] [blame] | 2208 | mpt_put_msg_frame(mptsasMgmtCtx, ioc, mf); |
| 2209 | |
| 2210 | timeleft = wait_for_completion_timeout(&ioc->sas_mgmt.done, 10 * HZ); |
| 2211 | if (!timeleft) { |
Harvey Harrison | cadbd4a | 2008-07-03 23:47:27 -0700 | [diff] [blame] | 2212 | printk(MYIOC_s_ERR_FMT "%s: smp timeout!\n", ioc->name, __func__); |
FUJITA Tomonori | 159e36f | 2007-07-30 11:10:07 -0600 | [diff] [blame] | 2213 | /* On timeout reset the board */ |
| 2214 | mpt_HardResetHandler(ioc, CAN_SLEEP); |
| 2215 | ret = -ETIMEDOUT; |
| 2216 | goto unmap; |
| 2217 | } |
| 2218 | mf = NULL; |
| 2219 | |
Kashyap, Desai | f0f09d3 | 2009-05-29 16:40:57 +0530 | [diff] [blame] | 2220 | if (ioc->sas_mgmt.status & MPT_MGMT_STATUS_RF_VALID) { |
FUJITA Tomonori | 159e36f | 2007-07-30 11:10:07 -0600 | [diff] [blame] | 2221 | SmpPassthroughReply_t *smprep; |
| 2222 | |
| 2223 | smprep = (SmpPassthroughReply_t *)ioc->sas_mgmt.reply; |
| 2224 | memcpy(req->sense, smprep, sizeof(*smprep)); |
| 2225 | req->sense_len = sizeof(*smprep); |
FUJITA Tomonori | 38b3167 | 2007-12-30 19:34:52 +0900 | [diff] [blame] | 2226 | req->data_len = 0; |
| 2227 | rsp->data_len -= smprep->ResponseDataLength; |
FUJITA Tomonori | 159e36f | 2007-07-30 11:10:07 -0600 | [diff] [blame] | 2228 | } else { |
Kashyap, Desai | 2f18786 | 2009-05-29 16:52:37 +0530 | [diff] [blame] | 2229 | printk(MYIOC_s_ERR_FMT |
| 2230 | "%s: smp passthru reply failed to be returned\n", |
Harvey Harrison | cadbd4a | 2008-07-03 23:47:27 -0700 | [diff] [blame] | 2231 | ioc->name, __func__); |
FUJITA Tomonori | 159e36f | 2007-07-30 11:10:07 -0600 | [diff] [blame] | 2232 | ret = -ENXIO; |
| 2233 | } |
| 2234 | unmap: |
| 2235 | if (dma_addr_out) |
| 2236 | pci_unmap_single(ioc->pcidev, dma_addr_out, req->data_len, |
| 2237 | PCI_DMA_BIDIRECTIONAL); |
| 2238 | if (dma_addr_in) |
| 2239 | pci_unmap_single(ioc->pcidev, dma_addr_in, rsp->data_len, |
| 2240 | PCI_DMA_BIDIRECTIONAL); |
| 2241 | put_mf: |
| 2242 | if (mf) |
| 2243 | mpt_free_msg_frame(ioc, mf); |
| 2244 | out_unlock: |
Kashyap, Desai | 2f18786 | 2009-05-29 16:52:37 +0530 | [diff] [blame] | 2245 | CLEAR_MGMT_STATUS(ioc->sas_mgmt.status) |
FUJITA Tomonori | 159e36f | 2007-07-30 11:10:07 -0600 | [diff] [blame] | 2246 | mutex_unlock(&ioc->sas_mgmt.mutex); |
| 2247 | out: |
| 2248 | return ret; |
| 2249 | } |
| 2250 | |
Christoph Hellwig | 0c33b27 | 2005-09-09 16:27:19 +0200 | [diff] [blame] | 2251 | static struct sas_function_template mptsas_transport_functions = { |
Christoph Hellwig | b514112 | 2005-10-28 22:07:41 +0200 | [diff] [blame] | 2252 | .get_linkerrors = mptsas_get_linkerrors, |
Christoph Hellwig | e309444 | 2006-02-16 13:25:36 +0100 | [diff] [blame] | 2253 | .get_enclosure_identifier = mptsas_get_enclosure_identifier, |
| 2254 | .get_bay_identifier = mptsas_get_bay_identifier, |
Christoph Hellwig | da4fa65 | 2005-10-19 20:01:42 +0200 | [diff] [blame] | 2255 | .phy_reset = mptsas_phy_reset, |
FUJITA Tomonori | 159e36f | 2007-07-30 11:10:07 -0600 | [diff] [blame] | 2256 | .smp_handler = mptsas_smp_handler, |
Christoph Hellwig | 0c33b27 | 2005-09-09 16:27:19 +0200 | [diff] [blame] | 2257 | }; |
| 2258 | |
| 2259 | static struct scsi_transport_template *mptsas_transport_template; |
| 2260 | |
Christoph Hellwig | 0c33b27 | 2005-09-09 16:27:19 +0200 | [diff] [blame] | 2261 | static int |
| 2262 | mptsas_sas_io_unit_pg0(MPT_ADAPTER *ioc, struct mptsas_portinfo *port_info) |
| 2263 | { |
| 2264 | ConfigExtendedPageHeader_t hdr; |
| 2265 | CONFIGPARMS cfg; |
| 2266 | SasIOUnitPage0_t *buffer; |
| 2267 | dma_addr_t dma_handle; |
| 2268 | int error, i; |
| 2269 | |
| 2270 | hdr.PageVersion = MPI_SASIOUNITPAGE0_PAGEVERSION; |
| 2271 | hdr.ExtPageLength = 0; |
| 2272 | hdr.PageNumber = 0; |
| 2273 | hdr.Reserved1 = 0; |
| 2274 | hdr.Reserved2 = 0; |
| 2275 | hdr.PageType = MPI_CONFIG_PAGETYPE_EXTENDED; |
| 2276 | hdr.ExtPageType = MPI_CONFIG_EXTPAGETYPE_SAS_IO_UNIT; |
| 2277 | |
| 2278 | cfg.cfghdr.ehdr = &hdr; |
| 2279 | cfg.physAddr = -1; |
| 2280 | cfg.pageAddr = 0; |
| 2281 | cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER; |
| 2282 | cfg.dir = 0; /* read */ |
| 2283 | cfg.timeout = 10; |
| 2284 | |
| 2285 | error = mpt_config(ioc, &cfg); |
| 2286 | if (error) |
| 2287 | goto out; |
| 2288 | if (!hdr.ExtPageLength) { |
| 2289 | error = -ENXIO; |
| 2290 | goto out; |
| 2291 | } |
| 2292 | |
| 2293 | buffer = pci_alloc_consistent(ioc->pcidev, hdr.ExtPageLength * 4, |
| 2294 | &dma_handle); |
| 2295 | if (!buffer) { |
| 2296 | error = -ENOMEM; |
| 2297 | goto out; |
| 2298 | } |
| 2299 | |
| 2300 | cfg.physAddr = dma_handle; |
| 2301 | cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT; |
| 2302 | |
| 2303 | error = mpt_config(ioc, &cfg); |
| 2304 | if (error) |
| 2305 | goto out_free_consistent; |
| 2306 | |
| 2307 | port_info->num_phys = buffer->NumPhys; |
| 2308 | port_info->phy_info = kcalloc(port_info->num_phys, |
Kashyap, Desai | 2f18786 | 2009-05-29 16:52:37 +0530 | [diff] [blame] | 2309 | sizeof(struct mptsas_phyinfo), GFP_KERNEL); |
Christoph Hellwig | 0c33b27 | 2005-09-09 16:27:19 +0200 | [diff] [blame] | 2310 | if (!port_info->phy_info) { |
| 2311 | error = -ENOMEM; |
| 2312 | goto out_free_consistent; |
| 2313 | } |
| 2314 | |
Prakash, Sathya | edb9068 | 2007-07-17 14:39:14 +0530 | [diff] [blame] | 2315 | ioc->nvdata_version_persistent = |
| 2316 | le16_to_cpu(buffer->NvdataVersionPersistent); |
| 2317 | ioc->nvdata_version_default = |
| 2318 | le16_to_cpu(buffer->NvdataVersionDefault); |
| 2319 | |
Christoph Hellwig | 0c33b27 | 2005-09-09 16:27:19 +0200 | [diff] [blame] | 2320 | for (i = 0; i < port_info->num_phys; i++) { |
Prakash, Sathya | d6ecdd6 | 2007-07-24 15:47:41 +0530 | [diff] [blame] | 2321 | mptsas_print_phy_data(ioc, &buffer->PhyData[i]); |
Christoph Hellwig | 0c33b27 | 2005-09-09 16:27:19 +0200 | [diff] [blame] | 2322 | port_info->phy_info[i].phy_id = i; |
| 2323 | port_info->phy_info[i].port_id = |
| 2324 | buffer->PhyData[i].Port; |
| 2325 | port_info->phy_info[i].negotiated_link_rate = |
| 2326 | buffer->PhyData[i].NegotiatedLinkRate; |
Eric Moore | 547f9a2 | 2006-06-27 14:42:12 -0600 | [diff] [blame] | 2327 | port_info->phy_info[i].portinfo = port_info; |
Eric Moore | 2ecce49 | 2007-01-29 09:47:08 -0700 | [diff] [blame] | 2328 | port_info->phy_info[i].handle = |
| 2329 | le16_to_cpu(buffer->PhyData[i].ControllerDevHandle); |
Christoph Hellwig | 0c33b27 | 2005-09-09 16:27:19 +0200 | [diff] [blame] | 2330 | } |
| 2331 | |
| 2332 | out_free_consistent: |
| 2333 | pci_free_consistent(ioc->pcidev, hdr.ExtPageLength * 4, |
| 2334 | buffer, dma_handle); |
| 2335 | out: |
| 2336 | return error; |
| 2337 | } |
| 2338 | |
| 2339 | static int |
Prakash, Sathya | edb9068 | 2007-07-17 14:39:14 +0530 | [diff] [blame] | 2340 | mptsas_sas_io_unit_pg1(MPT_ADAPTER *ioc) |
| 2341 | { |
| 2342 | ConfigExtendedPageHeader_t hdr; |
| 2343 | CONFIGPARMS cfg; |
| 2344 | SasIOUnitPage1_t *buffer; |
| 2345 | dma_addr_t dma_handle; |
| 2346 | int error; |
| 2347 | u16 device_missing_delay; |
| 2348 | |
| 2349 | memset(&hdr, 0, sizeof(ConfigExtendedPageHeader_t)); |
| 2350 | memset(&cfg, 0, sizeof(CONFIGPARMS)); |
| 2351 | |
| 2352 | cfg.cfghdr.ehdr = &hdr; |
| 2353 | cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER; |
| 2354 | cfg.timeout = 10; |
| 2355 | cfg.cfghdr.ehdr->PageType = MPI_CONFIG_PAGETYPE_EXTENDED; |
| 2356 | cfg.cfghdr.ehdr->ExtPageType = MPI_CONFIG_EXTPAGETYPE_SAS_IO_UNIT; |
| 2357 | cfg.cfghdr.ehdr->PageVersion = MPI_SASIOUNITPAGE1_PAGEVERSION; |
| 2358 | cfg.cfghdr.ehdr->PageNumber = 1; |
| 2359 | |
| 2360 | error = mpt_config(ioc, &cfg); |
| 2361 | if (error) |
| 2362 | goto out; |
| 2363 | if (!hdr.ExtPageLength) { |
| 2364 | error = -ENXIO; |
| 2365 | goto out; |
| 2366 | } |
| 2367 | |
| 2368 | buffer = pci_alloc_consistent(ioc->pcidev, hdr.ExtPageLength * 4, |
| 2369 | &dma_handle); |
| 2370 | if (!buffer) { |
| 2371 | error = -ENOMEM; |
| 2372 | goto out; |
| 2373 | } |
| 2374 | |
| 2375 | cfg.physAddr = dma_handle; |
| 2376 | cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT; |
| 2377 | |
| 2378 | error = mpt_config(ioc, &cfg); |
| 2379 | if (error) |
| 2380 | goto out_free_consistent; |
| 2381 | |
| 2382 | ioc->io_missing_delay = |
| 2383 | le16_to_cpu(buffer->IODeviceMissingDelay); |
| 2384 | device_missing_delay = le16_to_cpu(buffer->ReportDeviceMissingDelay); |
| 2385 | ioc->device_missing_delay = (device_missing_delay & MPI_SAS_IOUNIT1_REPORT_MISSING_UNIT_16) ? |
| 2386 | (device_missing_delay & MPI_SAS_IOUNIT1_REPORT_MISSING_TIMEOUT_MASK) * 16 : |
| 2387 | device_missing_delay & MPI_SAS_IOUNIT1_REPORT_MISSING_TIMEOUT_MASK; |
| 2388 | |
| 2389 | out_free_consistent: |
| 2390 | pci_free_consistent(ioc->pcidev, hdr.ExtPageLength * 4, |
| 2391 | buffer, dma_handle); |
| 2392 | out: |
| 2393 | return error; |
| 2394 | } |
| 2395 | |
| 2396 | static int |
Christoph Hellwig | 0c33b27 | 2005-09-09 16:27:19 +0200 | [diff] [blame] | 2397 | mptsas_sas_phy_pg0(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, |
| 2398 | u32 form, u32 form_specific) |
| 2399 | { |
| 2400 | ConfigExtendedPageHeader_t hdr; |
| 2401 | CONFIGPARMS cfg; |
| 2402 | SasPhyPage0_t *buffer; |
| 2403 | dma_addr_t dma_handle; |
| 2404 | int error; |
| 2405 | |
| 2406 | hdr.PageVersion = MPI_SASPHY0_PAGEVERSION; |
| 2407 | hdr.ExtPageLength = 0; |
| 2408 | hdr.PageNumber = 0; |
| 2409 | hdr.Reserved1 = 0; |
| 2410 | hdr.Reserved2 = 0; |
| 2411 | hdr.PageType = MPI_CONFIG_PAGETYPE_EXTENDED; |
| 2412 | hdr.ExtPageType = MPI_CONFIG_EXTPAGETYPE_SAS_PHY; |
| 2413 | |
| 2414 | cfg.cfghdr.ehdr = &hdr; |
| 2415 | cfg.dir = 0; /* read */ |
| 2416 | cfg.timeout = 10; |
| 2417 | |
| 2418 | /* Get Phy Pg 0 for each Phy. */ |
| 2419 | cfg.physAddr = -1; |
| 2420 | cfg.pageAddr = form + form_specific; |
| 2421 | cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER; |
| 2422 | |
| 2423 | error = mpt_config(ioc, &cfg); |
| 2424 | if (error) |
| 2425 | goto out; |
| 2426 | |
| 2427 | if (!hdr.ExtPageLength) { |
| 2428 | error = -ENXIO; |
| 2429 | goto out; |
| 2430 | } |
| 2431 | |
| 2432 | buffer = pci_alloc_consistent(ioc->pcidev, hdr.ExtPageLength * 4, |
| 2433 | &dma_handle); |
| 2434 | if (!buffer) { |
| 2435 | error = -ENOMEM; |
| 2436 | goto out; |
| 2437 | } |
| 2438 | |
| 2439 | cfg.physAddr = dma_handle; |
| 2440 | cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT; |
| 2441 | |
| 2442 | error = mpt_config(ioc, &cfg); |
| 2443 | if (error) |
| 2444 | goto out_free_consistent; |
| 2445 | |
Prakash, Sathya | d6ecdd6 | 2007-07-24 15:47:41 +0530 | [diff] [blame] | 2446 | mptsas_print_phy_pg0(ioc, buffer); |
Christoph Hellwig | 0c33b27 | 2005-09-09 16:27:19 +0200 | [diff] [blame] | 2447 | |
| 2448 | phy_info->hw_link_rate = buffer->HwLinkRate; |
| 2449 | phy_info->programmed_link_rate = buffer->ProgrammedLinkRate; |
| 2450 | phy_info->identify.handle = le16_to_cpu(buffer->OwnerDevHandle); |
| 2451 | phy_info->attached.handle = le16_to_cpu(buffer->AttachedDevHandle); |
| 2452 | |
| 2453 | out_free_consistent: |
| 2454 | pci_free_consistent(ioc->pcidev, hdr.ExtPageLength * 4, |
| 2455 | buffer, dma_handle); |
| 2456 | out: |
| 2457 | return error; |
| 2458 | } |
| 2459 | |
| 2460 | static int |
| 2461 | mptsas_sas_device_pg0(MPT_ADAPTER *ioc, struct mptsas_devinfo *device_info, |
| 2462 | u32 form, u32 form_specific) |
| 2463 | { |
| 2464 | ConfigExtendedPageHeader_t hdr; |
| 2465 | CONFIGPARMS cfg; |
| 2466 | SasDevicePage0_t *buffer; |
| 2467 | dma_addr_t dma_handle; |
| 2468 | __le64 sas_address; |
Moore, Eric | bd23e94 | 2006-04-17 12:43:04 -0600 | [diff] [blame] | 2469 | int error=0; |
| 2470 | |
Christoph Hellwig | 0c33b27 | 2005-09-09 16:27:19 +0200 | [diff] [blame] | 2471 | hdr.PageVersion = MPI_SASDEVICE0_PAGEVERSION; |
| 2472 | hdr.ExtPageLength = 0; |
| 2473 | hdr.PageNumber = 0; |
| 2474 | hdr.Reserved1 = 0; |
| 2475 | hdr.Reserved2 = 0; |
| 2476 | hdr.PageType = MPI_CONFIG_PAGETYPE_EXTENDED; |
| 2477 | hdr.ExtPageType = MPI_CONFIG_EXTPAGETYPE_SAS_DEVICE; |
| 2478 | |
| 2479 | cfg.cfghdr.ehdr = &hdr; |
| 2480 | cfg.pageAddr = form + form_specific; |
| 2481 | cfg.physAddr = -1; |
| 2482 | cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER; |
| 2483 | cfg.dir = 0; /* read */ |
| 2484 | cfg.timeout = 10; |
| 2485 | |
Moore, Eric | db9c917 | 2006-03-14 09:14:18 -0700 | [diff] [blame] | 2486 | memset(device_info, 0, sizeof(struct mptsas_devinfo)); |
Christoph Hellwig | 0c33b27 | 2005-09-09 16:27:19 +0200 | [diff] [blame] | 2487 | error = mpt_config(ioc, &cfg); |
| 2488 | if (error) |
| 2489 | goto out; |
| 2490 | if (!hdr.ExtPageLength) { |
| 2491 | error = -ENXIO; |
| 2492 | goto out; |
| 2493 | } |
| 2494 | |
| 2495 | buffer = pci_alloc_consistent(ioc->pcidev, hdr.ExtPageLength * 4, |
| 2496 | &dma_handle); |
| 2497 | if (!buffer) { |
| 2498 | error = -ENOMEM; |
| 2499 | goto out; |
| 2500 | } |
| 2501 | |
| 2502 | cfg.physAddr = dma_handle; |
| 2503 | cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT; |
| 2504 | |
| 2505 | error = mpt_config(ioc, &cfg); |
| 2506 | if (error) |
| 2507 | goto out_free_consistent; |
| 2508 | |
Prakash, Sathya | d6ecdd6 | 2007-07-24 15:47:41 +0530 | [diff] [blame] | 2509 | mptsas_print_device_pg0(ioc, buffer); |
Christoph Hellwig | 0c33b27 | 2005-09-09 16:27:19 +0200 | [diff] [blame] | 2510 | |
Kashyap, Desai | 2f18786 | 2009-05-29 16:52:37 +0530 | [diff] [blame] | 2511 | memset(device_info, 0, sizeof(struct mptsas_devinfo)); |
Christoph Hellwig | 0c33b27 | 2005-09-09 16:27:19 +0200 | [diff] [blame] | 2512 | device_info->handle = le16_to_cpu(buffer->DevHandle); |
Moore, Eric | c73787ee | 2006-01-26 16:20:06 -0700 | [diff] [blame] | 2513 | device_info->handle_parent = le16_to_cpu(buffer->ParentDevHandle); |
Christoph Hellwig | e309444 | 2006-02-16 13:25:36 +0100 | [diff] [blame] | 2514 | device_info->handle_enclosure = |
| 2515 | le16_to_cpu(buffer->EnclosureHandle); |
| 2516 | device_info->slot = le16_to_cpu(buffer->Slot); |
Christoph Hellwig | 0c33b27 | 2005-09-09 16:27:19 +0200 | [diff] [blame] | 2517 | device_info->phy_id = buffer->PhyNum; |
| 2518 | device_info->port_id = buffer->PhysicalPort; |
Christoph Hellwig | 9a28f49 | 2006-01-13 18:04:41 +0100 | [diff] [blame] | 2519 | device_info->id = buffer->TargetID; |
Eric Moore | b506ade | 2007-01-29 09:45:37 -0700 | [diff] [blame] | 2520 | device_info->phys_disk_num = ~0; |
Christoph Hellwig | 9a28f49 | 2006-01-13 18:04:41 +0100 | [diff] [blame] | 2521 | device_info->channel = buffer->Bus; |
Christoph Hellwig | 0c33b27 | 2005-09-09 16:27:19 +0200 | [diff] [blame] | 2522 | memcpy(&sas_address, &buffer->SASAddress, sizeof(__le64)); |
| 2523 | device_info->sas_address = le64_to_cpu(sas_address); |
| 2524 | device_info->device_info = |
| 2525 | le32_to_cpu(buffer->DeviceInfo); |
| 2526 | |
| 2527 | out_free_consistent: |
| 2528 | pci_free_consistent(ioc->pcidev, hdr.ExtPageLength * 4, |
| 2529 | buffer, dma_handle); |
| 2530 | out: |
| 2531 | return error; |
| 2532 | } |
| 2533 | |
| 2534 | static int |
| 2535 | mptsas_sas_expander_pg0(MPT_ADAPTER *ioc, struct mptsas_portinfo *port_info, |
| 2536 | u32 form, u32 form_specific) |
| 2537 | { |
| 2538 | ConfigExtendedPageHeader_t hdr; |
| 2539 | CONFIGPARMS cfg; |
| 2540 | SasExpanderPage0_t *buffer; |
| 2541 | dma_addr_t dma_handle; |
Eric Moore | 547f9a2 | 2006-06-27 14:42:12 -0600 | [diff] [blame] | 2542 | int i, error; |
Kashyap, Desai | 2f18786 | 2009-05-29 16:52:37 +0530 | [diff] [blame] | 2543 | __le64 sas_address; |
Christoph Hellwig | 0c33b27 | 2005-09-09 16:27:19 +0200 | [diff] [blame] | 2544 | |
Kashyap, Desai | 2f18786 | 2009-05-29 16:52:37 +0530 | [diff] [blame] | 2545 | memset(port_info, 0, sizeof(struct mptsas_portinfo)); |
Christoph Hellwig | 0c33b27 | 2005-09-09 16:27:19 +0200 | [diff] [blame] | 2546 | hdr.PageVersion = MPI_SASEXPANDER0_PAGEVERSION; |
| 2547 | hdr.ExtPageLength = 0; |
| 2548 | hdr.PageNumber = 0; |
| 2549 | hdr.Reserved1 = 0; |
| 2550 | hdr.Reserved2 = 0; |
| 2551 | hdr.PageType = MPI_CONFIG_PAGETYPE_EXTENDED; |
| 2552 | hdr.ExtPageType = MPI_CONFIG_EXTPAGETYPE_SAS_EXPANDER; |
| 2553 | |
| 2554 | cfg.cfghdr.ehdr = &hdr; |
| 2555 | cfg.physAddr = -1; |
| 2556 | cfg.pageAddr = form + form_specific; |
| 2557 | cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER; |
| 2558 | cfg.dir = 0; /* read */ |
| 2559 | cfg.timeout = 10; |
| 2560 | |
Moore, Eric | db9c917 | 2006-03-14 09:14:18 -0700 | [diff] [blame] | 2561 | memset(port_info, 0, sizeof(struct mptsas_portinfo)); |
Christoph Hellwig | 0c33b27 | 2005-09-09 16:27:19 +0200 | [diff] [blame] | 2562 | error = mpt_config(ioc, &cfg); |
| 2563 | if (error) |
| 2564 | goto out; |
| 2565 | |
| 2566 | if (!hdr.ExtPageLength) { |
| 2567 | error = -ENXIO; |
| 2568 | goto out; |
| 2569 | } |
| 2570 | |
| 2571 | buffer = pci_alloc_consistent(ioc->pcidev, hdr.ExtPageLength * 4, |
| 2572 | &dma_handle); |
| 2573 | if (!buffer) { |
| 2574 | error = -ENOMEM; |
| 2575 | goto out; |
| 2576 | } |
| 2577 | |
| 2578 | cfg.physAddr = dma_handle; |
| 2579 | cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT; |
| 2580 | |
| 2581 | error = mpt_config(ioc, &cfg); |
| 2582 | if (error) |
| 2583 | goto out_free_consistent; |
| 2584 | |
Krzysztof Oledzki | 51f39ea | 2008-03-04 14:56:23 -0800 | [diff] [blame] | 2585 | if (!buffer->NumPhys) { |
| 2586 | error = -ENODEV; |
| 2587 | goto out_free_consistent; |
| 2588 | } |
| 2589 | |
Christoph Hellwig | 0c33b27 | 2005-09-09 16:27:19 +0200 | [diff] [blame] | 2590 | /* save config data */ |
Kashyap, Desai | 2f18786 | 2009-05-29 16:52:37 +0530 | [diff] [blame] | 2591 | port_info->num_phys = (buffer->NumPhys) ? buffer->NumPhys : 1; |
Christoph Hellwig | 0c33b27 | 2005-09-09 16:27:19 +0200 | [diff] [blame] | 2592 | port_info->phy_info = kcalloc(port_info->num_phys, |
Kashyap, Desai | 2f18786 | 2009-05-29 16:52:37 +0530 | [diff] [blame] | 2593 | sizeof(struct mptsas_phyinfo), GFP_KERNEL); |
Christoph Hellwig | 0c33b27 | 2005-09-09 16:27:19 +0200 | [diff] [blame] | 2594 | if (!port_info->phy_info) { |
| 2595 | error = -ENOMEM; |
| 2596 | goto out_free_consistent; |
| 2597 | } |
| 2598 | |
Kashyap, Desai | 2f18786 | 2009-05-29 16:52:37 +0530 | [diff] [blame] | 2599 | memcpy(&sas_address, &buffer->SASAddress, sizeof(__le64)); |
Eric Moore | 2ecce49 | 2007-01-29 09:47:08 -0700 | [diff] [blame] | 2600 | for (i = 0; i < port_info->num_phys; i++) { |
Eric Moore | 547f9a2 | 2006-06-27 14:42:12 -0600 | [diff] [blame] | 2601 | port_info->phy_info[i].portinfo = port_info; |
Eric Moore | 2ecce49 | 2007-01-29 09:47:08 -0700 | [diff] [blame] | 2602 | port_info->phy_info[i].handle = |
| 2603 | le16_to_cpu(buffer->DevHandle); |
Kashyap, Desai | 2f18786 | 2009-05-29 16:52:37 +0530 | [diff] [blame] | 2604 | port_info->phy_info[i].identify.sas_address = |
| 2605 | le64_to_cpu(sas_address); |
| 2606 | port_info->phy_info[i].identify.handle_parent = |
| 2607 | le16_to_cpu(buffer->ParentDevHandle); |
Eric Moore | 2ecce49 | 2007-01-29 09:47:08 -0700 | [diff] [blame] | 2608 | } |
Eric Moore | 547f9a2 | 2006-06-27 14:42:12 -0600 | [diff] [blame] | 2609 | |
Christoph Hellwig | 0c33b27 | 2005-09-09 16:27:19 +0200 | [diff] [blame] | 2610 | out_free_consistent: |
| 2611 | pci_free_consistent(ioc->pcidev, hdr.ExtPageLength * 4, |
| 2612 | buffer, dma_handle); |
| 2613 | out: |
| 2614 | return error; |
| 2615 | } |
| 2616 | |
| 2617 | static int |
| 2618 | mptsas_sas_expander_pg1(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, |
| 2619 | u32 form, u32 form_specific) |
| 2620 | { |
| 2621 | ConfigExtendedPageHeader_t hdr; |
| 2622 | CONFIGPARMS cfg; |
| 2623 | SasExpanderPage1_t *buffer; |
| 2624 | dma_addr_t dma_handle; |
Moore, Eric | bd23e94 | 2006-04-17 12:43:04 -0600 | [diff] [blame] | 2625 | int error=0; |
| 2626 | |
Kashyap, Desai | 2f18786 | 2009-05-29 16:52:37 +0530 | [diff] [blame] | 2627 | hdr.PageVersion = MPI_SASEXPANDER1_PAGEVERSION; |
Christoph Hellwig | 0c33b27 | 2005-09-09 16:27:19 +0200 | [diff] [blame] | 2628 | hdr.ExtPageLength = 0; |
| 2629 | hdr.PageNumber = 1; |
| 2630 | hdr.Reserved1 = 0; |
| 2631 | hdr.Reserved2 = 0; |
| 2632 | hdr.PageType = MPI_CONFIG_PAGETYPE_EXTENDED; |
| 2633 | hdr.ExtPageType = MPI_CONFIG_EXTPAGETYPE_SAS_EXPANDER; |
| 2634 | |
| 2635 | cfg.cfghdr.ehdr = &hdr; |
| 2636 | cfg.physAddr = -1; |
| 2637 | cfg.pageAddr = form + form_specific; |
| 2638 | cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER; |
| 2639 | cfg.dir = 0; /* read */ |
| 2640 | cfg.timeout = 10; |
| 2641 | |
| 2642 | error = mpt_config(ioc, &cfg); |
| 2643 | if (error) |
| 2644 | goto out; |
| 2645 | |
| 2646 | if (!hdr.ExtPageLength) { |
| 2647 | error = -ENXIO; |
| 2648 | goto out; |
| 2649 | } |
| 2650 | |
| 2651 | buffer = pci_alloc_consistent(ioc->pcidev, hdr.ExtPageLength * 4, |
| 2652 | &dma_handle); |
| 2653 | if (!buffer) { |
| 2654 | error = -ENOMEM; |
| 2655 | goto out; |
| 2656 | } |
| 2657 | |
| 2658 | cfg.physAddr = dma_handle; |
| 2659 | cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT; |
| 2660 | |
| 2661 | error = mpt_config(ioc, &cfg); |
Kashyap, Desai | 2f18786 | 2009-05-29 16:52:37 +0530 | [diff] [blame] | 2662 | |
| 2663 | if (error == MPI_IOCSTATUS_CONFIG_INVALID_PAGE) { |
| 2664 | error = -ENODEV; |
| 2665 | goto out; |
| 2666 | } |
| 2667 | |
Christoph Hellwig | 0c33b27 | 2005-09-09 16:27:19 +0200 | [diff] [blame] | 2668 | if (error) |
| 2669 | goto out_free_consistent; |
| 2670 | |
| 2671 | |
Prakash, Sathya | d6ecdd6 | 2007-07-24 15:47:41 +0530 | [diff] [blame] | 2672 | mptsas_print_expander_pg1(ioc, buffer); |
Christoph Hellwig | 0c33b27 | 2005-09-09 16:27:19 +0200 | [diff] [blame] | 2673 | |
| 2674 | /* save config data */ |
Eric Moore | 024358e | 2005-10-21 20:56:36 +0200 | [diff] [blame] | 2675 | phy_info->phy_id = buffer->PhyIdentifier; |
Christoph Hellwig | 0c33b27 | 2005-09-09 16:27:19 +0200 | [diff] [blame] | 2676 | phy_info->port_id = buffer->PhysicalPort; |
| 2677 | phy_info->negotiated_link_rate = buffer->NegotiatedLinkRate; |
| 2678 | phy_info->programmed_link_rate = buffer->ProgrammedLinkRate; |
| 2679 | phy_info->hw_link_rate = buffer->HwLinkRate; |
| 2680 | phy_info->identify.handle = le16_to_cpu(buffer->OwnerDevHandle); |
| 2681 | phy_info->attached.handle = le16_to_cpu(buffer->AttachedDevHandle); |
| 2682 | |
Christoph Hellwig | 0c33b27 | 2005-09-09 16:27:19 +0200 | [diff] [blame] | 2683 | out_free_consistent: |
| 2684 | pci_free_consistent(ioc->pcidev, hdr.ExtPageLength * 4, |
| 2685 | buffer, dma_handle); |
| 2686 | out: |
| 2687 | return error; |
| 2688 | } |
| 2689 | |
| 2690 | static void |
| 2691 | mptsas_parse_device_info(struct sas_identify *identify, |
| 2692 | struct mptsas_devinfo *device_info) |
| 2693 | { |
| 2694 | u16 protocols; |
| 2695 | |
| 2696 | identify->sas_address = device_info->sas_address; |
| 2697 | identify->phy_identifier = device_info->phy_id; |
| 2698 | |
| 2699 | /* |
| 2700 | * Fill in Phy Initiator Port Protocol. |
| 2701 | * Bits 6:3, more than one bit can be set, fall through cases. |
| 2702 | */ |
| 2703 | protocols = device_info->device_info & 0x78; |
| 2704 | identify->initiator_port_protocols = 0; |
| 2705 | if (protocols & MPI_SAS_DEVICE_INFO_SSP_INITIATOR) |
| 2706 | identify->initiator_port_protocols |= SAS_PROTOCOL_SSP; |
| 2707 | if (protocols & MPI_SAS_DEVICE_INFO_STP_INITIATOR) |
| 2708 | identify->initiator_port_protocols |= SAS_PROTOCOL_STP; |
| 2709 | if (protocols & MPI_SAS_DEVICE_INFO_SMP_INITIATOR) |
| 2710 | identify->initiator_port_protocols |= SAS_PROTOCOL_SMP; |
| 2711 | if (protocols & MPI_SAS_DEVICE_INFO_SATA_HOST) |
| 2712 | identify->initiator_port_protocols |= SAS_PROTOCOL_SATA; |
| 2713 | |
| 2714 | /* |
| 2715 | * Fill in Phy Target Port Protocol. |
| 2716 | * Bits 10:7, more than one bit can be set, fall through cases. |
| 2717 | */ |
| 2718 | protocols = device_info->device_info & 0x780; |
| 2719 | identify->target_port_protocols = 0; |
| 2720 | if (protocols & MPI_SAS_DEVICE_INFO_SSP_TARGET) |
| 2721 | identify->target_port_protocols |= SAS_PROTOCOL_SSP; |
| 2722 | if (protocols & MPI_SAS_DEVICE_INFO_STP_TARGET) |
| 2723 | identify->target_port_protocols |= SAS_PROTOCOL_STP; |
| 2724 | if (protocols & MPI_SAS_DEVICE_INFO_SMP_TARGET) |
| 2725 | identify->target_port_protocols |= SAS_PROTOCOL_SMP; |
| 2726 | if (protocols & MPI_SAS_DEVICE_INFO_SATA_DEVICE) |
| 2727 | identify->target_port_protocols |= SAS_PROTOCOL_SATA; |
| 2728 | |
| 2729 | /* |
| 2730 | * Fill in Attached device type. |
| 2731 | */ |
| 2732 | switch (device_info->device_info & |
| 2733 | MPI_SAS_DEVICE_INFO_MASK_DEVICE_TYPE) { |
| 2734 | case MPI_SAS_DEVICE_INFO_NO_DEVICE: |
| 2735 | identify->device_type = SAS_PHY_UNUSED; |
| 2736 | break; |
| 2737 | case MPI_SAS_DEVICE_INFO_END_DEVICE: |
| 2738 | identify->device_type = SAS_END_DEVICE; |
| 2739 | break; |
| 2740 | case MPI_SAS_DEVICE_INFO_EDGE_EXPANDER: |
| 2741 | identify->device_type = SAS_EDGE_EXPANDER_DEVICE; |
| 2742 | break; |
| 2743 | case MPI_SAS_DEVICE_INFO_FANOUT_EXPANDER: |
| 2744 | identify->device_type = SAS_FANOUT_EXPANDER_DEVICE; |
| 2745 | break; |
| 2746 | } |
| 2747 | } |
| 2748 | |
| 2749 | static int mptsas_probe_one_phy(struct device *dev, |
Christoph Hellwig | ac01bbb | 2005-10-19 20:01:17 +0200 | [diff] [blame] | 2750 | struct mptsas_phyinfo *phy_info, int index, int local) |
Christoph Hellwig | 0c33b27 | 2005-09-09 16:27:19 +0200 | [diff] [blame] | 2751 | { |
Moore, Eric | e6b2d76 | 2006-03-14 09:14:24 -0700 | [diff] [blame] | 2752 | MPT_ADAPTER *ioc; |
Christoph Hellwig | 9a28f49 | 2006-01-13 18:04:41 +0100 | [diff] [blame] | 2753 | struct sas_phy *phy; |
Eric Moore | 547f9a2 | 2006-06-27 14:42:12 -0600 | [diff] [blame] | 2754 | struct sas_port *port; |
| 2755 | int error = 0; |
Christoph Hellwig | 0c33b27 | 2005-09-09 16:27:19 +0200 | [diff] [blame] | 2756 | |
Eric Moore | 547f9a2 | 2006-06-27 14:42:12 -0600 | [diff] [blame] | 2757 | if (!dev) { |
| 2758 | error = -ENODEV; |
| 2759 | goto out; |
| 2760 | } |
Moore, Eric | e6b2d76 | 2006-03-14 09:14:24 -0700 | [diff] [blame] | 2761 | |
| 2762 | if (!phy_info->phy) { |
| 2763 | phy = sas_phy_alloc(dev, index); |
Eric Moore | 547f9a2 | 2006-06-27 14:42:12 -0600 | [diff] [blame] | 2764 | if (!phy) { |
| 2765 | error = -ENOMEM; |
| 2766 | goto out; |
| 2767 | } |
Moore, Eric | e6b2d76 | 2006-03-14 09:14:24 -0700 | [diff] [blame] | 2768 | } else |
| 2769 | phy = phy_info->phy; |
Christoph Hellwig | 0c33b27 | 2005-09-09 16:27:19 +0200 | [diff] [blame] | 2770 | |
Christoph Hellwig | 9a28f49 | 2006-01-13 18:04:41 +0100 | [diff] [blame] | 2771 | mptsas_parse_device_info(&phy->identify, &phy_info->identify); |
Christoph Hellwig | 0c33b27 | 2005-09-09 16:27:19 +0200 | [diff] [blame] | 2772 | |
| 2773 | /* |
| 2774 | * Set Negotiated link rate. |
| 2775 | */ |
| 2776 | switch (phy_info->negotiated_link_rate) { |
| 2777 | case MPI_SAS_IOUNIT0_RATE_PHY_DISABLED: |
Christoph Hellwig | 9a28f49 | 2006-01-13 18:04:41 +0100 | [diff] [blame] | 2778 | phy->negotiated_linkrate = SAS_PHY_DISABLED; |
Christoph Hellwig | 0c33b27 | 2005-09-09 16:27:19 +0200 | [diff] [blame] | 2779 | break; |
| 2780 | case MPI_SAS_IOUNIT0_RATE_FAILED_SPEED_NEGOTIATION: |
Christoph Hellwig | 9a28f49 | 2006-01-13 18:04:41 +0100 | [diff] [blame] | 2781 | phy->negotiated_linkrate = SAS_LINK_RATE_FAILED; |
Christoph Hellwig | 0c33b27 | 2005-09-09 16:27:19 +0200 | [diff] [blame] | 2782 | break; |
| 2783 | case MPI_SAS_IOUNIT0_RATE_1_5: |
Christoph Hellwig | 9a28f49 | 2006-01-13 18:04:41 +0100 | [diff] [blame] | 2784 | phy->negotiated_linkrate = SAS_LINK_RATE_1_5_GBPS; |
Christoph Hellwig | 0c33b27 | 2005-09-09 16:27:19 +0200 | [diff] [blame] | 2785 | break; |
| 2786 | case MPI_SAS_IOUNIT0_RATE_3_0: |
Christoph Hellwig | 9a28f49 | 2006-01-13 18:04:41 +0100 | [diff] [blame] | 2787 | phy->negotiated_linkrate = SAS_LINK_RATE_3_0_GBPS; |
Christoph Hellwig | 0c33b27 | 2005-09-09 16:27:19 +0200 | [diff] [blame] | 2788 | break; |
| 2789 | case MPI_SAS_IOUNIT0_RATE_SATA_OOB_COMPLETE: |
| 2790 | case MPI_SAS_IOUNIT0_RATE_UNKNOWN: |
| 2791 | default: |
Christoph Hellwig | 9a28f49 | 2006-01-13 18:04:41 +0100 | [diff] [blame] | 2792 | phy->negotiated_linkrate = SAS_LINK_RATE_UNKNOWN; |
Christoph Hellwig | 0c33b27 | 2005-09-09 16:27:19 +0200 | [diff] [blame] | 2793 | break; |
| 2794 | } |
| 2795 | |
| 2796 | /* |
| 2797 | * Set Max hardware link rate. |
| 2798 | */ |
| 2799 | switch (phy_info->hw_link_rate & MPI_SAS_PHY0_PRATE_MAX_RATE_MASK) { |
| 2800 | case MPI_SAS_PHY0_HWRATE_MAX_RATE_1_5: |
Christoph Hellwig | 9a28f49 | 2006-01-13 18:04:41 +0100 | [diff] [blame] | 2801 | phy->maximum_linkrate_hw = SAS_LINK_RATE_1_5_GBPS; |
Christoph Hellwig | 0c33b27 | 2005-09-09 16:27:19 +0200 | [diff] [blame] | 2802 | break; |
| 2803 | case MPI_SAS_PHY0_PRATE_MAX_RATE_3_0: |
Christoph Hellwig | 9a28f49 | 2006-01-13 18:04:41 +0100 | [diff] [blame] | 2804 | phy->maximum_linkrate_hw = SAS_LINK_RATE_3_0_GBPS; |
Christoph Hellwig | 0c33b27 | 2005-09-09 16:27:19 +0200 | [diff] [blame] | 2805 | break; |
| 2806 | default: |
| 2807 | break; |
| 2808 | } |
| 2809 | |
| 2810 | /* |
| 2811 | * Set Max programmed link rate. |
| 2812 | */ |
| 2813 | switch (phy_info->programmed_link_rate & |
| 2814 | MPI_SAS_PHY0_PRATE_MAX_RATE_MASK) { |
| 2815 | case MPI_SAS_PHY0_PRATE_MAX_RATE_1_5: |
Christoph Hellwig | 9a28f49 | 2006-01-13 18:04:41 +0100 | [diff] [blame] | 2816 | phy->maximum_linkrate = SAS_LINK_RATE_1_5_GBPS; |
Christoph Hellwig | 0c33b27 | 2005-09-09 16:27:19 +0200 | [diff] [blame] | 2817 | break; |
| 2818 | case MPI_SAS_PHY0_PRATE_MAX_RATE_3_0: |
Christoph Hellwig | 9a28f49 | 2006-01-13 18:04:41 +0100 | [diff] [blame] | 2819 | phy->maximum_linkrate = SAS_LINK_RATE_3_0_GBPS; |
Christoph Hellwig | 0c33b27 | 2005-09-09 16:27:19 +0200 | [diff] [blame] | 2820 | break; |
| 2821 | default: |
| 2822 | break; |
| 2823 | } |
| 2824 | |
| 2825 | /* |
| 2826 | * Set Min hardware link rate. |
| 2827 | */ |
| 2828 | switch (phy_info->hw_link_rate & MPI_SAS_PHY0_HWRATE_MIN_RATE_MASK) { |
| 2829 | case MPI_SAS_PHY0_HWRATE_MIN_RATE_1_5: |
Christoph Hellwig | 9a28f49 | 2006-01-13 18:04:41 +0100 | [diff] [blame] | 2830 | phy->minimum_linkrate_hw = SAS_LINK_RATE_1_5_GBPS; |
Christoph Hellwig | 0c33b27 | 2005-09-09 16:27:19 +0200 | [diff] [blame] | 2831 | break; |
| 2832 | case MPI_SAS_PHY0_PRATE_MIN_RATE_3_0: |
Christoph Hellwig | 9a28f49 | 2006-01-13 18:04:41 +0100 | [diff] [blame] | 2833 | phy->minimum_linkrate_hw = SAS_LINK_RATE_3_0_GBPS; |
Christoph Hellwig | 0c33b27 | 2005-09-09 16:27:19 +0200 | [diff] [blame] | 2834 | break; |
| 2835 | default: |
| 2836 | break; |
| 2837 | } |
| 2838 | |
| 2839 | /* |
| 2840 | * Set Min programmed link rate. |
| 2841 | */ |
| 2842 | switch (phy_info->programmed_link_rate & |
| 2843 | MPI_SAS_PHY0_PRATE_MIN_RATE_MASK) { |
| 2844 | case MPI_SAS_PHY0_PRATE_MIN_RATE_1_5: |
Christoph Hellwig | 9a28f49 | 2006-01-13 18:04:41 +0100 | [diff] [blame] | 2845 | phy->minimum_linkrate = SAS_LINK_RATE_1_5_GBPS; |
Christoph Hellwig | 0c33b27 | 2005-09-09 16:27:19 +0200 | [diff] [blame] | 2846 | break; |
| 2847 | case MPI_SAS_PHY0_PRATE_MIN_RATE_3_0: |
Christoph Hellwig | 9a28f49 | 2006-01-13 18:04:41 +0100 | [diff] [blame] | 2848 | phy->minimum_linkrate = SAS_LINK_RATE_3_0_GBPS; |
Christoph Hellwig | 0c33b27 | 2005-09-09 16:27:19 +0200 | [diff] [blame] | 2849 | break; |
| 2850 | default: |
| 2851 | break; |
| 2852 | } |
| 2853 | |
Moore, Eric | e6b2d76 | 2006-03-14 09:14:24 -0700 | [diff] [blame] | 2854 | if (!phy_info->phy) { |
Christoph Hellwig | ac01bbb | 2005-10-19 20:01:17 +0200 | [diff] [blame] | 2855 | |
Moore, Eric | e6b2d76 | 2006-03-14 09:14:24 -0700 | [diff] [blame] | 2856 | error = sas_phy_add(phy); |
| 2857 | if (error) { |
| 2858 | sas_phy_free(phy); |
Eric Moore | 547f9a2 | 2006-06-27 14:42:12 -0600 | [diff] [blame] | 2859 | goto out; |
Moore, Eric | e6b2d76 | 2006-03-14 09:14:24 -0700 | [diff] [blame] | 2860 | } |
| 2861 | phy_info->phy = phy; |
Christoph Hellwig | 0c33b27 | 2005-09-09 16:27:19 +0200 | [diff] [blame] | 2862 | } |
| 2863 | |
Eric Moore | 547f9a2 | 2006-06-27 14:42:12 -0600 | [diff] [blame] | 2864 | if (!phy_info->attached.handle || |
| 2865 | !phy_info->port_details) |
| 2866 | goto out; |
| 2867 | |
| 2868 | port = mptsas_get_port(phy_info); |
| 2869 | ioc = phy_to_ioc(phy_info->phy); |
| 2870 | |
| 2871 | if (phy_info->sas_port_add_phy) { |
| 2872 | |
| 2873 | if (!port) { |
Eric Moore | dc22f16 | 2006-07-06 11:23:14 -0600 | [diff] [blame] | 2874 | port = sas_port_alloc_num(dev); |
Eric Moore | 547f9a2 | 2006-06-27 14:42:12 -0600 | [diff] [blame] | 2875 | if (!port) { |
| 2876 | error = -ENOMEM; |
| 2877 | goto out; |
| 2878 | } |
| 2879 | error = sas_port_add(port); |
| 2880 | if (error) { |
Prakash, Sathya | d6ecdd6 | 2007-07-24 15:47:41 +0530 | [diff] [blame] | 2881 | dfailprintk(ioc, printk(MYIOC_s_ERR_FMT |
Eric Moore | 547f9a2 | 2006-06-27 14:42:12 -0600 | [diff] [blame] | 2882 | "%s: exit at line=%d\n", ioc->name, |
Harvey Harrison | cadbd4a | 2008-07-03 23:47:27 -0700 | [diff] [blame] | 2883 | __func__, __LINE__)); |
Eric Moore | 547f9a2 | 2006-06-27 14:42:12 -0600 | [diff] [blame] | 2884 | goto out; |
| 2885 | } |
Prakash, Sathya | d6ecdd6 | 2007-07-24 15:47:41 +0530 | [diff] [blame] | 2886 | mptsas_set_port(ioc, phy_info, port); |
Kashyap, Desai | 2f18786 | 2009-05-29 16:52:37 +0530 | [diff] [blame] | 2887 | devtprintk(ioc, dev_printk(KERN_DEBUG, &port->dev, |
| 2888 | MYIOC_s_FMT "add port %d, sas_addr (0x%llx)\n", |
| 2889 | ioc->name, port->port_identifier, |
| 2890 | (unsigned long long)phy_info-> |
| 2891 | attached.sas_address)); |
Eric Moore | 547f9a2 | 2006-06-27 14:42:12 -0600 | [diff] [blame] | 2892 | } |
Kashyap, Desai | 2f18786 | 2009-05-29 16:52:37 +0530 | [diff] [blame] | 2893 | dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT |
| 2894 | "sas_port_add_phy: phy_id=%d\n", |
| 2895 | ioc->name, phy_info->phy_id)); |
Eric Moore | 547f9a2 | 2006-06-27 14:42:12 -0600 | [diff] [blame] | 2896 | sas_port_add_phy(port, phy_info->phy); |
| 2897 | phy_info->sas_port_add_phy = 0; |
Kashyap, Desai | 2f18786 | 2009-05-29 16:52:37 +0530 | [diff] [blame] | 2898 | devtprintk(ioc, dev_printk(KERN_DEBUG, &phy_info->phy->dev, |
| 2899 | MYIOC_s_FMT "add phy %d, phy-obj (0x%p)\n", ioc->name, |
| 2900 | phy_info->phy_id, phy_info->phy)); |
Eric Moore | 547f9a2 | 2006-06-27 14:42:12 -0600 | [diff] [blame] | 2901 | } |
Eric Moore | 547f9a2 | 2006-06-27 14:42:12 -0600 | [diff] [blame] | 2902 | if (!mptsas_get_rphy(phy_info) && port && !port->rphy) { |
Moore, Eric | e6b2d76 | 2006-03-14 09:14:24 -0700 | [diff] [blame] | 2903 | |
Christoph Hellwig | 0c33b27 | 2005-09-09 16:27:19 +0200 | [diff] [blame] | 2904 | struct sas_rphy *rphy; |
James Bottomley | 2686de2 | 2006-06-30 12:54:02 -0500 | [diff] [blame] | 2905 | struct device *parent; |
James Bottomley | f013db3 | 2006-03-18 14:54:36 -0600 | [diff] [blame] | 2906 | struct sas_identify identify; |
Christoph Hellwig | 0c33b27 | 2005-09-09 16:27:19 +0200 | [diff] [blame] | 2907 | |
James Bottomley | 2686de2 | 2006-06-30 12:54:02 -0500 | [diff] [blame] | 2908 | parent = dev->parent->parent; |
Moore, Eric | e6b2d76 | 2006-03-14 09:14:24 -0700 | [diff] [blame] | 2909 | /* |
| 2910 | * Let the hotplug_work thread handle processing |
| 2911 | * the adding/removing of devices that occur |
| 2912 | * after start of day. |
| 2913 | */ |
Kashyap, Desai | 2f18786 | 2009-05-29 16:52:37 +0530 | [diff] [blame] | 2914 | if (mptsas_is_end_device(&phy_info->attached) && |
| 2915 | phy_info->attached.handle_parent) { |
| 2916 | goto out; |
| 2917 | } |
Moore, Eric | e6b2d76 | 2006-03-14 09:14:24 -0700 | [diff] [blame] | 2918 | |
James Bottomley | f013db3 | 2006-03-18 14:54:36 -0600 | [diff] [blame] | 2919 | mptsas_parse_device_info(&identify, &phy_info->attached); |
James Bottomley | 2686de2 | 2006-06-30 12:54:02 -0500 | [diff] [blame] | 2920 | if (scsi_is_host_device(parent)) { |
| 2921 | struct mptsas_portinfo *port_info; |
| 2922 | int i; |
| 2923 | |
Kashyap, Desai | f9c3402 | 2009-05-29 16:49:36 +0530 | [diff] [blame] | 2924 | port_info = ioc->hba_port_info; |
James Bottomley | 2686de2 | 2006-06-30 12:54:02 -0500 | [diff] [blame] | 2925 | |
| 2926 | for (i = 0; i < port_info->num_phys; i++) |
| 2927 | if (port_info->phy_info[i].identify.sas_address == |
James Bottomley | 0c269e6 | 2006-07-12 09:51:04 -0400 | [diff] [blame] | 2928 | identify.sas_address) { |
| 2929 | sas_port_mark_backlink(port); |
James Bottomley | 2686de2 | 2006-06-30 12:54:02 -0500 | [diff] [blame] | 2930 | goto out; |
James Bottomley | 0c269e6 | 2006-07-12 09:51:04 -0400 | [diff] [blame] | 2931 | } |
James Bottomley | 2686de2 | 2006-06-30 12:54:02 -0500 | [diff] [blame] | 2932 | |
| 2933 | } else if (scsi_is_sas_rphy(parent)) { |
| 2934 | struct sas_rphy *parent_rphy = dev_to_rphy(parent); |
| 2935 | if (identify.sas_address == |
James Bottomley | 0c269e6 | 2006-07-12 09:51:04 -0400 | [diff] [blame] | 2936 | parent_rphy->identify.sas_address) { |
| 2937 | sas_port_mark_backlink(port); |
James Bottomley | 2686de2 | 2006-06-30 12:54:02 -0500 | [diff] [blame] | 2938 | goto out; |
James Bottomley | 0c269e6 | 2006-07-12 09:51:04 -0400 | [diff] [blame] | 2939 | } |
James Bottomley | 2686de2 | 2006-06-30 12:54:02 -0500 | [diff] [blame] | 2940 | } |
| 2941 | |
James Bottomley | f013db3 | 2006-03-18 14:54:36 -0600 | [diff] [blame] | 2942 | switch (identify.device_type) { |
| 2943 | case SAS_END_DEVICE: |
Eric Moore | 547f9a2 | 2006-06-27 14:42:12 -0600 | [diff] [blame] | 2944 | rphy = sas_end_device_alloc(port); |
James Bottomley | f013db3 | 2006-03-18 14:54:36 -0600 | [diff] [blame] | 2945 | break; |
| 2946 | case SAS_EDGE_EXPANDER_DEVICE: |
| 2947 | case SAS_FANOUT_EXPANDER_DEVICE: |
Eric Moore | 547f9a2 | 2006-06-27 14:42:12 -0600 | [diff] [blame] | 2948 | rphy = sas_expander_alloc(port, identify.device_type); |
James Bottomley | f013db3 | 2006-03-18 14:54:36 -0600 | [diff] [blame] | 2949 | break; |
| 2950 | default: |
| 2951 | rphy = NULL; |
| 2952 | break; |
| 2953 | } |
Eric Moore | 547f9a2 | 2006-06-27 14:42:12 -0600 | [diff] [blame] | 2954 | if (!rphy) { |
Prakash, Sathya | d6ecdd6 | 2007-07-24 15:47:41 +0530 | [diff] [blame] | 2955 | dfailprintk(ioc, printk(MYIOC_s_ERR_FMT |
Eric Moore | 547f9a2 | 2006-06-27 14:42:12 -0600 | [diff] [blame] | 2956 | "%s: exit at line=%d\n", ioc->name, |
Harvey Harrison | cadbd4a | 2008-07-03 23:47:27 -0700 | [diff] [blame] | 2957 | __func__, __LINE__)); |
Eric Moore | 547f9a2 | 2006-06-27 14:42:12 -0600 | [diff] [blame] | 2958 | goto out; |
Christoph Hellwig | 0c33b27 | 2005-09-09 16:27:19 +0200 | [diff] [blame] | 2959 | } |
| 2960 | |
Eric Moore | 547f9a2 | 2006-06-27 14:42:12 -0600 | [diff] [blame] | 2961 | rphy->identify = identify; |
| 2962 | error = sas_rphy_add(rphy); |
| 2963 | if (error) { |
Prakash, Sathya | d6ecdd6 | 2007-07-24 15:47:41 +0530 | [diff] [blame] | 2964 | dfailprintk(ioc, printk(MYIOC_s_ERR_FMT |
Eric Moore | 547f9a2 | 2006-06-27 14:42:12 -0600 | [diff] [blame] | 2965 | "%s: exit at line=%d\n", ioc->name, |
Harvey Harrison | cadbd4a | 2008-07-03 23:47:27 -0700 | [diff] [blame] | 2966 | __func__, __LINE__)); |
Eric Moore | 547f9a2 | 2006-06-27 14:42:12 -0600 | [diff] [blame] | 2967 | sas_rphy_free(rphy); |
| 2968 | goto out; |
| 2969 | } |
Prakash, Sathya | d6ecdd6 | 2007-07-24 15:47:41 +0530 | [diff] [blame] | 2970 | mptsas_set_rphy(ioc, phy_info, rphy); |
Christoph Hellwig | 0c33b27 | 2005-09-09 16:27:19 +0200 | [diff] [blame] | 2971 | } |
| 2972 | |
Eric Moore | 547f9a2 | 2006-06-27 14:42:12 -0600 | [diff] [blame] | 2973 | out: |
| 2974 | return error; |
Christoph Hellwig | 0c33b27 | 2005-09-09 16:27:19 +0200 | [diff] [blame] | 2975 | } |
| 2976 | |
| 2977 | static int |
Moore, Eric | e6b2d76 | 2006-03-14 09:14:24 -0700 | [diff] [blame] | 2978 | mptsas_probe_hba_phys(MPT_ADAPTER *ioc) |
Christoph Hellwig | 0c33b27 | 2005-09-09 16:27:19 +0200 | [diff] [blame] | 2979 | { |
Moore, Eric | e6b2d76 | 2006-03-14 09:14:24 -0700 | [diff] [blame] | 2980 | struct mptsas_portinfo *port_info, *hba; |
Christoph Hellwig | 0c33b27 | 2005-09-09 16:27:19 +0200 | [diff] [blame] | 2981 | int error = -ENOMEM, i; |
| 2982 | |
Kashyap, Desai | f9c3402 | 2009-05-29 16:49:36 +0530 | [diff] [blame] | 2983 | hba = kzalloc(sizeof(struct mptsas_portinfo), GFP_KERNEL); |
Moore, Eric | e6b2d76 | 2006-03-14 09:14:24 -0700 | [diff] [blame] | 2984 | if (! hba) |
Christoph Hellwig | 0c33b27 | 2005-09-09 16:27:19 +0200 | [diff] [blame] | 2985 | goto out; |
Christoph Hellwig | 0c33b27 | 2005-09-09 16:27:19 +0200 | [diff] [blame] | 2986 | |
Moore, Eric | e6b2d76 | 2006-03-14 09:14:24 -0700 | [diff] [blame] | 2987 | error = mptsas_sas_io_unit_pg0(ioc, hba); |
Christoph Hellwig | 0c33b27 | 2005-09-09 16:27:19 +0200 | [diff] [blame] | 2988 | if (error) |
| 2989 | goto out_free_port_info; |
| 2990 | |
Prakash, Sathya | edb9068 | 2007-07-17 14:39:14 +0530 | [diff] [blame] | 2991 | mptsas_sas_io_unit_pg1(ioc); |
Christoph Hellwig | 9a28f49 | 2006-01-13 18:04:41 +0100 | [diff] [blame] | 2992 | mutex_lock(&ioc->sas_topology_mutex); |
Kashyap, Desai | f9c3402 | 2009-05-29 16:49:36 +0530 | [diff] [blame] | 2993 | port_info = ioc->hba_port_info; |
Moore, Eric | e6b2d76 | 2006-03-14 09:14:24 -0700 | [diff] [blame] | 2994 | if (!port_info) { |
Kashyap, Desai | f9c3402 | 2009-05-29 16:49:36 +0530 | [diff] [blame] | 2995 | ioc->hba_port_info = port_info = hba; |
| 2996 | ioc->hba_port_num_phy = port_info->num_phys; |
Moore, Eric | e6b2d76 | 2006-03-14 09:14:24 -0700 | [diff] [blame] | 2997 | list_add_tail(&port_info->list, &ioc->sas_topology); |
| 2998 | } else { |
Eric Moore | 2ecce49 | 2007-01-29 09:47:08 -0700 | [diff] [blame] | 2999 | for (i = 0; i < hba->num_phys; i++) { |
Moore, Eric | e6b2d76 | 2006-03-14 09:14:24 -0700 | [diff] [blame] | 3000 | port_info->phy_info[i].negotiated_link_rate = |
| 3001 | hba->phy_info[i].negotiated_link_rate; |
Eric Moore | 2ecce49 | 2007-01-29 09:47:08 -0700 | [diff] [blame] | 3002 | port_info->phy_info[i].handle = |
| 3003 | hba->phy_info[i].handle; |
| 3004 | port_info->phy_info[i].port_id = |
| 3005 | hba->phy_info[i].port_id; |
| 3006 | } |
Eric Moore | 547f9a2 | 2006-06-27 14:42:12 -0600 | [diff] [blame] | 3007 | kfree(hba->phy_info); |
Moore, Eric | e6b2d76 | 2006-03-14 09:14:24 -0700 | [diff] [blame] | 3008 | kfree(hba); |
| 3009 | hba = NULL; |
| 3010 | } |
Christoph Hellwig | 9a28f49 | 2006-01-13 18:04:41 +0100 | [diff] [blame] | 3011 | mutex_unlock(&ioc->sas_topology_mutex); |
Kashyap, Desai | f9c3402 | 2009-05-29 16:49:36 +0530 | [diff] [blame] | 3012 | #if defined(CPQ_CIM) |
| 3013 | ioc->num_ports = port_info->num_phys; |
| 3014 | #endif |
Christoph Hellwig | 0c33b27 | 2005-09-09 16:27:19 +0200 | [diff] [blame] | 3015 | for (i = 0; i < port_info->num_phys; i++) { |
| 3016 | mptsas_sas_phy_pg0(ioc, &port_info->phy_info[i], |
| 3017 | (MPI_SAS_PHY_PGAD_FORM_PHY_NUMBER << |
| 3018 | MPI_SAS_PHY_PGAD_FORM_SHIFT), i); |
Kashyap, Desai | f9c3402 | 2009-05-29 16:49:36 +0530 | [diff] [blame] | 3019 | port_info->phy_info[i].identify.handle = |
| 3020 | port_info->phy_info[i].handle; |
Christoph Hellwig | 0c33b27 | 2005-09-09 16:27:19 +0200 | [diff] [blame] | 3021 | mptsas_sas_device_pg0(ioc, &port_info->phy_info[i].identify, |
Eric Moore | 2ecce49 | 2007-01-29 09:47:08 -0700 | [diff] [blame] | 3022 | (MPI_SAS_DEVICE_PGAD_FORM_HANDLE << |
| 3023 | MPI_SAS_DEVICE_PGAD_FORM_SHIFT), |
Kashyap, Desai | f9c3402 | 2009-05-29 16:49:36 +0530 | [diff] [blame] | 3024 | port_info->phy_info[i].identify.handle); |
| 3025 | if (!ioc->hba_port_sas_addr) |
| 3026 | ioc->hba_port_sas_addr = |
| 3027 | port_info->phy_info[i].identify.sas_address; |
Eric Moore | 024358e | 2005-10-21 20:56:36 +0200 | [diff] [blame] | 3028 | port_info->phy_info[i].identify.phy_id = |
Eric Moore | 2ecce49 | 2007-01-29 09:47:08 -0700 | [diff] [blame] | 3029 | port_info->phy_info[i].phy_id = i; |
Eric Moore | 547f9a2 | 2006-06-27 14:42:12 -0600 | [diff] [blame] | 3030 | if (port_info->phy_info[i].attached.handle) |
Christoph Hellwig | 0c33b27 | 2005-09-09 16:27:19 +0200 | [diff] [blame] | 3031 | mptsas_sas_device_pg0(ioc, |
| 3032 | &port_info->phy_info[i].attached, |
| 3033 | (MPI_SAS_DEVICE_PGAD_FORM_HANDLE << |
| 3034 | MPI_SAS_DEVICE_PGAD_FORM_SHIFT), |
| 3035 | port_info->phy_info[i].attached.handle); |
Eric Moore | 547f9a2 | 2006-06-27 14:42:12 -0600 | [diff] [blame] | 3036 | } |
Christoph Hellwig | 0c33b27 | 2005-09-09 16:27:19 +0200 | [diff] [blame] | 3037 | |
Eric Moore | 547f9a2 | 2006-06-27 14:42:12 -0600 | [diff] [blame] | 3038 | mptsas_setup_wide_ports(ioc, port_info); |
| 3039 | |
| 3040 | for (i = 0; i < port_info->num_phys; i++, ioc->sas_index++) |
Christoph Hellwig | 0c33b27 | 2005-09-09 16:27:19 +0200 | [diff] [blame] | 3041 | mptsas_probe_one_phy(&ioc->sh->shost_gendev, |
Moore, Eric | e6b2d76 | 2006-03-14 09:14:24 -0700 | [diff] [blame] | 3042 | &port_info->phy_info[i], ioc->sas_index, 1); |
Christoph Hellwig | 0c33b27 | 2005-09-09 16:27:19 +0200 | [diff] [blame] | 3043 | |
| 3044 | return 0; |
| 3045 | |
| 3046 | out_free_port_info: |
Eric Moore | 547f9a2 | 2006-06-27 14:42:12 -0600 | [diff] [blame] | 3047 | kfree(hba); |
Christoph Hellwig | 0c33b27 | 2005-09-09 16:27:19 +0200 | [diff] [blame] | 3048 | out: |
| 3049 | return error; |
| 3050 | } |
| 3051 | |
Kashyap, Desai | f9c3402 | 2009-05-29 16:49:36 +0530 | [diff] [blame] | 3052 | static void |
| 3053 | mptsas_expander_refresh(MPT_ADAPTER *ioc, struct mptsas_portinfo *port_info) |
Christoph Hellwig | 0c33b27 | 2005-09-09 16:27:19 +0200 | [diff] [blame] | 3054 | { |
Kashyap, Desai | f9c3402 | 2009-05-29 16:49:36 +0530 | [diff] [blame] | 3055 | struct mptsas_portinfo *parent; |
| 3056 | struct device *parent_dev; |
| 3057 | struct sas_rphy *rphy; |
| 3058 | int i; |
| 3059 | u64 sas_address; /* expander sas address */ |
| 3060 | u32 handle; |
Christoph Hellwig | 0c33b27 | 2005-09-09 16:27:19 +0200 | [diff] [blame] | 3061 | |
Kashyap, Desai | f9c3402 | 2009-05-29 16:49:36 +0530 | [diff] [blame] | 3062 | handle = port_info->phy_info[0].handle; |
| 3063 | sas_address = port_info->phy_info[0].identify.sas_address; |
Christoph Hellwig | 0c33b27 | 2005-09-09 16:27:19 +0200 | [diff] [blame] | 3064 | for (i = 0; i < port_info->num_phys; i++) { |
Christoph Hellwig | 0c33b27 | 2005-09-09 16:27:19 +0200 | [diff] [blame] | 3065 | mptsas_sas_expander_pg1(ioc, &port_info->phy_info[i], |
Kashyap, Desai | f9c3402 | 2009-05-29 16:49:36 +0530 | [diff] [blame] | 3066 | (MPI_SAS_EXPAND_PGAD_FORM_HANDLE_PHY_NUM << |
| 3067 | MPI_SAS_EXPAND_PGAD_FORM_SHIFT), (i << 16) + handle); |
Christoph Hellwig | 0c33b27 | 2005-09-09 16:27:19 +0200 | [diff] [blame] | 3068 | |
Kashyap, Desai | f9c3402 | 2009-05-29 16:49:36 +0530 | [diff] [blame] | 3069 | mptsas_sas_device_pg0(ioc, |
| 3070 | &port_info->phy_info[i].identify, |
| 3071 | (MPI_SAS_DEVICE_PGAD_FORM_HANDLE << |
| 3072 | MPI_SAS_DEVICE_PGAD_FORM_SHIFT), |
| 3073 | port_info->phy_info[i].identify.handle); |
| 3074 | port_info->phy_info[i].identify.phy_id = |
| 3075 | port_info->phy_info[i].phy_id; |
Christoph Hellwig | 0c33b27 | 2005-09-09 16:27:19 +0200 | [diff] [blame] | 3076 | |
| 3077 | if (port_info->phy_info[i].attached.handle) { |
| 3078 | mptsas_sas_device_pg0(ioc, |
Kashyap, Desai | f9c3402 | 2009-05-29 16:49:36 +0530 | [diff] [blame] | 3079 | &port_info->phy_info[i].attached, |
| 3080 | (MPI_SAS_DEVICE_PGAD_FORM_HANDLE << |
| 3081 | MPI_SAS_DEVICE_PGAD_FORM_SHIFT), |
| 3082 | port_info->phy_info[i].attached.handle); |
Moore, Eric | db9c917 | 2006-03-14 09:14:18 -0700 | [diff] [blame] | 3083 | port_info->phy_info[i].attached.phy_id = |
| 3084 | port_info->phy_info[i].phy_id; |
Christoph Hellwig | 0c33b27 | 2005-09-09 16:27:19 +0200 | [diff] [blame] | 3085 | } |
Eric Moore | 547f9a2 | 2006-06-27 14:42:12 -0600 | [diff] [blame] | 3086 | } |
Christoph Hellwig | 0c33b27 | 2005-09-09 16:27:19 +0200 | [diff] [blame] | 3087 | |
Moore, Eric | e6b2d76 | 2006-03-14 09:14:24 -0700 | [diff] [blame] | 3088 | mutex_lock(&ioc->sas_topology_mutex); |
Kashyap, Desai | f9c3402 | 2009-05-29 16:49:36 +0530 | [diff] [blame] | 3089 | parent = mptsas_find_portinfo_by_handle(ioc, |
| 3090 | port_info->phy_info[0].identify.handle_parent); |
| 3091 | if (!parent) { |
| 3092 | mutex_unlock(&ioc->sas_topology_mutex); |
| 3093 | return; |
| 3094 | } |
| 3095 | for (i = 0, parent_dev = NULL; i < parent->num_phys && !parent_dev; |
| 3096 | i++) { |
| 3097 | if (parent->phy_info[i].attached.sas_address == sas_address) { |
| 3098 | rphy = mptsas_get_rphy(&parent->phy_info[i]); |
| 3099 | parent_dev = &rphy->dev; |
Moore, Eric | e6b2d76 | 2006-03-14 09:14:24 -0700 | [diff] [blame] | 3100 | } |
Moore, Eric | e6b2d76 | 2006-03-14 09:14:24 -0700 | [diff] [blame] | 3101 | } |
| 3102 | mutex_unlock(&ioc->sas_topology_mutex); |
Kashyap, Desai | f9c3402 | 2009-05-29 16:49:36 +0530 | [diff] [blame] | 3103 | |
| 3104 | mptsas_setup_wide_ports(ioc, port_info); |
| 3105 | for (i = 0; i < port_info->num_phys; i++, ioc->sas_index++) |
| 3106 | mptsas_probe_one_phy(parent_dev, &port_info->phy_info[i], |
| 3107 | ioc->sas_index, 0); |
| 3108 | } |
| 3109 | |
| 3110 | static void |
| 3111 | mptsas_expander_event_add(MPT_ADAPTER *ioc, |
| 3112 | MpiEventDataSasExpanderStatusChange_t *expander_data) |
| 3113 | { |
| 3114 | struct mptsas_portinfo *port_info; |
| 3115 | int i; |
| 3116 | __le64 sas_address; |
| 3117 | |
| 3118 | port_info = kzalloc(sizeof(struct mptsas_portinfo), GFP_KERNEL); |
| 3119 | if (!port_info) |
| 3120 | BUG(); |
| 3121 | port_info->num_phys = (expander_data->NumPhys) ? |
| 3122 | expander_data->NumPhys : 1; |
| 3123 | port_info->phy_info = kcalloc(port_info->num_phys, |
| 3124 | sizeof(struct mptsas_phyinfo), GFP_KERNEL); |
| 3125 | if (!port_info->phy_info) |
| 3126 | BUG(); |
| 3127 | memcpy(&sas_address, &expander_data->SASAddress, sizeof(__le64)); |
| 3128 | for (i = 0; i < port_info->num_phys; i++) { |
| 3129 | port_info->phy_info[i].portinfo = port_info; |
| 3130 | port_info->phy_info[i].handle = |
| 3131 | le16_to_cpu(expander_data->DevHandle); |
| 3132 | port_info->phy_info[i].identify.sas_address = |
| 3133 | le64_to_cpu(sas_address); |
| 3134 | port_info->phy_info[i].identify.handle_parent = |
| 3135 | le16_to_cpu(expander_data->ParentDevHandle); |
| 3136 | } |
| 3137 | |
| 3138 | mutex_lock(&ioc->sas_topology_mutex); |
| 3139 | list_add_tail(&port_info->list, &ioc->sas_topology); |
| 3140 | mutex_unlock(&ioc->sas_topology_mutex); |
| 3141 | |
| 3142 | printk(MYIOC_s_INFO_FMT "add expander: num_phys %d, " |
| 3143 | "sas_addr (0x%llx)\n", ioc->name, port_info->num_phys, |
| 3144 | (unsigned long long)sas_address); |
| 3145 | |
| 3146 | mptsas_expander_refresh(ioc, port_info); |
| 3147 | } |
| 3148 | |
| 3149 | /** |
| 3150 | * mptsas_delete_expander_siblings - remove siblings attached to expander |
| 3151 | * @ioc: Pointer to MPT_ADAPTER structure |
| 3152 | * @parent: the parent port_info object |
| 3153 | * @expander: the expander port_info object |
| 3154 | **/ |
| 3155 | static void |
| 3156 | mptsas_delete_expander_siblings(MPT_ADAPTER *ioc, struct mptsas_portinfo |
| 3157 | *parent, struct mptsas_portinfo *expander) |
| 3158 | { |
| 3159 | struct mptsas_phyinfo *phy_info; |
| 3160 | struct mptsas_portinfo *port_info; |
| 3161 | struct sas_rphy *rphy; |
| 3162 | int i; |
| 3163 | |
| 3164 | phy_info = expander->phy_info; |
| 3165 | for (i = 0; i < expander->num_phys; i++, phy_info++) { |
| 3166 | rphy = mptsas_get_rphy(phy_info); |
| 3167 | if (!rphy) |
| 3168 | continue; |
| 3169 | if (rphy->identify.device_type == SAS_END_DEVICE) |
| 3170 | mptsas_del_end_device(ioc, phy_info); |
| 3171 | } |
| 3172 | |
| 3173 | phy_info = expander->phy_info; |
| 3174 | for (i = 0; i < expander->num_phys; i++, phy_info++) { |
| 3175 | rphy = mptsas_get_rphy(phy_info); |
| 3176 | if (!rphy) |
| 3177 | continue; |
| 3178 | if (rphy->identify.device_type == |
| 3179 | MPI_SAS_DEVICE_INFO_EDGE_EXPANDER || |
| 3180 | rphy->identify.device_type == |
| 3181 | MPI_SAS_DEVICE_INFO_FANOUT_EXPANDER) { |
| 3182 | port_info = mptsas_find_portinfo_by_sas_address(ioc, |
| 3183 | rphy->identify.sas_address); |
| 3184 | if (!port_info) |
| 3185 | continue; |
| 3186 | if (port_info == parent) /* backlink rphy */ |
| 3187 | continue; |
| 3188 | /* |
| 3189 | Delete this expander even if the expdevpage is exists |
| 3190 | because the parent expander is already deleted |
| 3191 | */ |
| 3192 | mptsas_expander_delete(ioc, port_info, 1); |
| 3193 | } |
| 3194 | } |
| 3195 | } |
| 3196 | |
| 3197 | |
| 3198 | /** |
| 3199 | * mptsas_expander_delete - remove this expander |
| 3200 | * @ioc: Pointer to MPT_ADAPTER structure |
| 3201 | * @port_info: expander port_info struct |
| 3202 | * @force: Flag to forcefully delete the expander |
| 3203 | * |
| 3204 | **/ |
| 3205 | |
| 3206 | static void mptsas_expander_delete(MPT_ADAPTER *ioc, |
| 3207 | struct mptsas_portinfo *port_info, u8 force) |
| 3208 | { |
| 3209 | |
| 3210 | struct mptsas_portinfo *parent; |
| 3211 | int i; |
| 3212 | u64 expander_sas_address; |
| 3213 | struct mptsas_phyinfo *phy_info; |
| 3214 | struct mptsas_portinfo buffer; |
| 3215 | struct mptsas_portinfo_details *port_details; |
| 3216 | struct sas_port *port; |
| 3217 | |
| 3218 | if (!port_info) |
| 3219 | return; |
| 3220 | |
| 3221 | /* see if expander is still there before deleting */ |
| 3222 | mptsas_sas_expander_pg0(ioc, &buffer, |
| 3223 | (MPI_SAS_EXPAND_PGAD_FORM_HANDLE << |
| 3224 | MPI_SAS_EXPAND_PGAD_FORM_SHIFT), |
| 3225 | port_info->phy_info[0].identify.handle); |
| 3226 | |
| 3227 | if (buffer.num_phys) { |
| 3228 | kfree(buffer.phy_info); |
| 3229 | if (!force) |
| 3230 | return; |
| 3231 | } |
| 3232 | |
| 3233 | |
| 3234 | /* |
| 3235 | * Obtain the port_info instance to the parent port |
| 3236 | */ |
| 3237 | port_details = NULL; |
| 3238 | expander_sas_address = |
| 3239 | port_info->phy_info[0].identify.sas_address; |
| 3240 | parent = mptsas_find_portinfo_by_handle(ioc, |
| 3241 | port_info->phy_info[0].identify.handle_parent); |
| 3242 | mptsas_delete_expander_siblings(ioc, parent, port_info); |
| 3243 | if (!parent) |
| 3244 | goto out; |
| 3245 | |
| 3246 | /* |
| 3247 | * Delete rphys in the parent that point |
| 3248 | * to this expander. |
| 3249 | */ |
| 3250 | phy_info = parent->phy_info; |
| 3251 | port = NULL; |
| 3252 | for (i = 0; i < parent->num_phys; i++, phy_info++) { |
| 3253 | if (!phy_info->phy) |
| 3254 | continue; |
| 3255 | if (phy_info->attached.sas_address != |
| 3256 | expander_sas_address) |
| 3257 | continue; |
| 3258 | if (!port) { |
| 3259 | port = mptsas_get_port(phy_info); |
| 3260 | port_details = phy_info->port_details; |
| 3261 | } |
| 3262 | dev_printk(KERN_DEBUG, &phy_info->phy->dev, |
| 3263 | MYIOC_s_FMT "delete phy %d, phy-obj (0x%p)\n", ioc->name, |
| 3264 | phy_info->phy_id, phy_info->phy); |
| 3265 | sas_port_delete_phy(port, phy_info->phy); |
| 3266 | } |
| 3267 | if (port) { |
| 3268 | dev_printk(KERN_DEBUG, &port->dev, |
| 3269 | MYIOC_s_FMT "delete port %d, sas_addr (0x%llx)\n", |
| 3270 | ioc->name, port->port_identifier, |
| 3271 | (unsigned long long)expander_sas_address); |
| 3272 | sas_port_delete(port); |
| 3273 | mptsas_port_delete(ioc, port_details); |
| 3274 | } |
| 3275 | out: |
| 3276 | |
| 3277 | printk(MYIOC_s_INFO_FMT "delete expander: num_phys %d, " |
| 3278 | "sas_addr (0x%llx)\n", ioc->name, port_info->num_phys, |
| 3279 | (unsigned long long)expander_sas_address); |
| 3280 | |
| 3281 | /* |
| 3282 | * free link |
| 3283 | */ |
| 3284 | list_del(&port_info->list); |
| 3285 | kfree(port_info->phy_info); |
| 3286 | kfree(port_info); |
| 3287 | } |
| 3288 | |
| 3289 | |
| 3290 | /** |
| 3291 | * mptsas_send_expander_event - expanders events |
| 3292 | * @ioc: Pointer to MPT_ADAPTER structure |
| 3293 | * @expander_data: event data |
| 3294 | * |
| 3295 | * |
| 3296 | * This function handles adding, removing, and refreshing |
| 3297 | * device handles within the expander objects. |
| 3298 | */ |
| 3299 | static void |
| 3300 | mptsas_send_expander_event(struct fw_event_work *fw_event) |
| 3301 | { |
| 3302 | MPT_ADAPTER *ioc; |
| 3303 | MpiEventDataSasExpanderStatusChange_t *expander_data; |
| 3304 | struct mptsas_portinfo *port_info; |
| 3305 | __le64 sas_address; |
| 3306 | int i; |
| 3307 | |
| 3308 | ioc = fw_event->ioc; |
| 3309 | expander_data = (MpiEventDataSasExpanderStatusChange_t *) |
| 3310 | fw_event->event_data; |
| 3311 | memcpy(&sas_address, &expander_data->SASAddress, sizeof(__le64)); |
| 3312 | port_info = mptsas_find_portinfo_by_sas_address(ioc, sas_address); |
| 3313 | |
| 3314 | if (expander_data->ReasonCode == MPI_EVENT_SAS_EXP_RC_ADDED) { |
| 3315 | if (port_info) { |
| 3316 | for (i = 0; i < port_info->num_phys; i++) { |
| 3317 | port_info->phy_info[i].portinfo = port_info; |
| 3318 | port_info->phy_info[i].handle = |
| 3319 | le16_to_cpu(expander_data->DevHandle); |
| 3320 | port_info->phy_info[i].identify.sas_address = |
| 3321 | le64_to_cpu(sas_address); |
| 3322 | port_info->phy_info[i].identify.handle_parent = |
| 3323 | le16_to_cpu(expander_data->ParentDevHandle); |
| 3324 | } |
| 3325 | mptsas_expander_refresh(ioc, port_info); |
| 3326 | } else if (!port_info && expander_data->NumPhys) |
| 3327 | mptsas_expander_event_add(ioc, expander_data); |
| 3328 | } else if (expander_data->ReasonCode == |
| 3329 | MPI_EVENT_SAS_EXP_RC_NOT_RESPONDING) |
| 3330 | mptsas_expander_delete(ioc, port_info, 0); |
| 3331 | |
| 3332 | mptsas_free_fw_event(ioc, fw_event); |
| 3333 | } |
| 3334 | |
| 3335 | |
| 3336 | /** |
| 3337 | * mptsas_expander_add - |
| 3338 | * @ioc: Pointer to MPT_ADAPTER structure |
| 3339 | * @handle: |
| 3340 | * |
| 3341 | */ |
| 3342 | struct mptsas_portinfo * |
| 3343 | mptsas_expander_add(MPT_ADAPTER *ioc, u16 handle) |
| 3344 | { |
| 3345 | struct mptsas_portinfo buffer, *port_info; |
| 3346 | int i; |
| 3347 | |
| 3348 | if ((mptsas_sas_expander_pg0(ioc, &buffer, |
| 3349 | (MPI_SAS_EXPAND_PGAD_FORM_HANDLE << |
| 3350 | MPI_SAS_EXPAND_PGAD_FORM_SHIFT), handle))) |
| 3351 | return NULL; |
| 3352 | |
| 3353 | port_info = kzalloc(sizeof(struct mptsas_portinfo), GFP_ATOMIC); |
| 3354 | if (!port_info) { |
| 3355 | dfailprintk(ioc, printk(MYIOC_s_ERR_FMT |
| 3356 | "%s: exit at line=%d\n", ioc->name, |
| 3357 | __func__, __LINE__)); |
| 3358 | return NULL; |
| 3359 | } |
| 3360 | port_info->num_phys = buffer.num_phys; |
| 3361 | port_info->phy_info = buffer.phy_info; |
| 3362 | for (i = 0; i < port_info->num_phys; i++) |
| 3363 | port_info->phy_info[i].portinfo = port_info; |
| 3364 | mutex_lock(&ioc->sas_topology_mutex); |
| 3365 | list_add_tail(&port_info->list, &ioc->sas_topology); |
| 3366 | mutex_unlock(&ioc->sas_topology_mutex); |
| 3367 | printk(MYIOC_s_INFO_FMT "add expander: num_phys %d, " |
| 3368 | "sas_addr (0x%llx)\n", ioc->name, port_info->num_phys, |
| 3369 | (unsigned long long)buffer.phy_info[0].identify.sas_address); |
| 3370 | mptsas_expander_refresh(ioc, port_info); |
| 3371 | return port_info; |
| 3372 | } |
| 3373 | |
| 3374 | static void |
| 3375 | mptsas_send_link_status_event(struct fw_event_work *fw_event) |
| 3376 | { |
| 3377 | MPT_ADAPTER *ioc; |
| 3378 | MpiEventDataSasPhyLinkStatus_t *link_data; |
| 3379 | struct mptsas_portinfo *port_info; |
| 3380 | struct mptsas_phyinfo *phy_info = NULL; |
| 3381 | __le64 sas_address; |
| 3382 | u8 phy_num; |
| 3383 | u8 link_rate; |
| 3384 | |
| 3385 | ioc = fw_event->ioc; |
| 3386 | link_data = (MpiEventDataSasPhyLinkStatus_t *)fw_event->event_data; |
| 3387 | |
| 3388 | memcpy(&sas_address, &link_data->SASAddress, sizeof(__le64)); |
| 3389 | sas_address = le64_to_cpu(sas_address); |
| 3390 | link_rate = link_data->LinkRates >> 4; |
| 3391 | phy_num = link_data->PhyNum; |
| 3392 | |
| 3393 | port_info = mptsas_find_portinfo_by_sas_address(ioc, sas_address); |
| 3394 | if (port_info) { |
| 3395 | phy_info = &port_info->phy_info[phy_num]; |
| 3396 | if (phy_info) |
| 3397 | phy_info->negotiated_link_rate = link_rate; |
| 3398 | } |
| 3399 | |
| 3400 | if (link_rate == MPI_SAS_IOUNIT0_RATE_1_5 || |
| 3401 | link_rate == MPI_SAS_IOUNIT0_RATE_3_0) { |
| 3402 | |
Kashyap, Desai | eedf92b | 2009-05-29 16:51:32 +0530 | [diff] [blame] | 3403 | if (!port_info) { |
| 3404 | if (ioc->old_sas_discovery_protocal) { |
| 3405 | port_info = mptsas_expander_add(ioc, |
| 3406 | le16_to_cpu(link_data->DevHandle)); |
| 3407 | if (port_info) |
| 3408 | goto out; |
| 3409 | } |
Kashyap, Desai | f9c3402 | 2009-05-29 16:49:36 +0530 | [diff] [blame] | 3410 | goto out; |
Kashyap, Desai | eedf92b | 2009-05-29 16:51:32 +0530 | [diff] [blame] | 3411 | } |
Kashyap, Desai | f9c3402 | 2009-05-29 16:49:36 +0530 | [diff] [blame] | 3412 | |
| 3413 | if (port_info == ioc->hba_port_info) |
| 3414 | mptsas_probe_hba_phys(ioc); |
| 3415 | else |
| 3416 | mptsas_expander_refresh(ioc, port_info); |
| 3417 | } else if (phy_info && phy_info->phy) { |
| 3418 | if (link_rate == MPI_SAS_IOUNIT0_RATE_PHY_DISABLED) |
| 3419 | phy_info->phy->negotiated_linkrate = |
| 3420 | SAS_PHY_DISABLED; |
| 3421 | else if (link_rate == |
| 3422 | MPI_SAS_IOUNIT0_RATE_FAILED_SPEED_NEGOTIATION) |
| 3423 | phy_info->phy->negotiated_linkrate = |
| 3424 | SAS_LINK_RATE_FAILED; |
| 3425 | else |
| 3426 | phy_info->phy->negotiated_linkrate = |
| 3427 | SAS_LINK_RATE_UNKNOWN; |
| 3428 | } |
| 3429 | out: |
| 3430 | mptsas_free_fw_event(ioc, fw_event); |
| 3431 | } |
| 3432 | |
Kashyap, Desai | eedf92b | 2009-05-29 16:51:32 +0530 | [diff] [blame] | 3433 | static void |
| 3434 | mptsas_not_responding_devices(MPT_ADAPTER *ioc) |
| 3435 | { |
| 3436 | struct mptsas_portinfo buffer, *port_info; |
| 3437 | struct mptsas_device_info *sas_info; |
| 3438 | struct mptsas_devinfo sas_device; |
| 3439 | u32 handle; |
| 3440 | VirtTarget *vtarget = NULL; |
| 3441 | struct mptsas_phyinfo *phy_info; |
| 3442 | u8 found_expander; |
| 3443 | int retval, retry_count; |
| 3444 | unsigned long flags; |
| 3445 | |
| 3446 | mpt_findImVolumes(ioc); |
| 3447 | |
| 3448 | spin_lock_irqsave(&ioc->taskmgmt_lock, flags); |
| 3449 | if (ioc->ioc_reset_in_progress) { |
| 3450 | dfailprintk(ioc, printk(MYIOC_s_DEBUG_FMT |
| 3451 | "%s: exiting due to a parallel reset \n", ioc->name, |
| 3452 | __func__)); |
| 3453 | spin_unlock_irqrestore(&ioc->taskmgmt_lock, flags); |
| 3454 | return; |
| 3455 | } |
| 3456 | spin_unlock_irqrestore(&ioc->taskmgmt_lock, flags); |
| 3457 | |
| 3458 | /* devices, logical volumes */ |
| 3459 | mutex_lock(&ioc->sas_device_info_mutex); |
| 3460 | redo_device_scan: |
| 3461 | list_for_each_entry(sas_info, &ioc->sas_device_info_list, list) { |
Kashyap, Desai | 57e9851 | 2009-05-29 16:55:09 +0530 | [diff] [blame] | 3462 | if (sas_info->is_cached) |
| 3463 | continue; |
Kashyap, Desai | a7938b0 | 2009-05-29 16:53:56 +0530 | [diff] [blame] | 3464 | if (!sas_info->is_logical_volume) { |
| 3465 | sas_device.handle = 0; |
| 3466 | retry_count = 0; |
Kashyap, Desai | eedf92b | 2009-05-29 16:51:32 +0530 | [diff] [blame] | 3467 | retry_page: |
Kashyap, Desai | a7938b0 | 2009-05-29 16:53:56 +0530 | [diff] [blame] | 3468 | retval = mptsas_sas_device_pg0(ioc, &sas_device, |
Kashyap, Desai | eedf92b | 2009-05-29 16:51:32 +0530 | [diff] [blame] | 3469 | (MPI_SAS_DEVICE_PGAD_FORM_BUS_TARGET_ID |
| 3470 | << MPI_SAS_DEVICE_PGAD_FORM_SHIFT), |
| 3471 | (sas_info->fw.channel << 8) + |
| 3472 | sas_info->fw.id); |
| 3473 | |
Kashyap, Desai | a7938b0 | 2009-05-29 16:53:56 +0530 | [diff] [blame] | 3474 | if (sas_device.handle) |
| 3475 | continue; |
| 3476 | if (retval == -EBUSY) { |
| 3477 | spin_lock_irqsave(&ioc->taskmgmt_lock, flags); |
| 3478 | if (ioc->ioc_reset_in_progress) { |
| 3479 | dfailprintk(ioc, |
| 3480 | printk(MYIOC_s_DEBUG_FMT |
| 3481 | "%s: exiting due to reset\n", |
| 3482 | ioc->name, __func__)); |
| 3483 | spin_unlock_irqrestore |
| 3484 | (&ioc->taskmgmt_lock, flags); |
| 3485 | mutex_unlock(&ioc-> |
| 3486 | sas_device_info_mutex); |
| 3487 | return; |
| 3488 | } |
| 3489 | spin_unlock_irqrestore(&ioc->taskmgmt_lock, |
| 3490 | flags); |
Kashyap, Desai | eedf92b | 2009-05-29 16:51:32 +0530 | [diff] [blame] | 3491 | } |
Kashyap, Desai | eedf92b | 2009-05-29 16:51:32 +0530 | [diff] [blame] | 3492 | |
Kashyap, Desai | a7938b0 | 2009-05-29 16:53:56 +0530 | [diff] [blame] | 3493 | if (retval && (retval != -ENODEV)) { |
| 3494 | if (retry_count < 10) { |
| 3495 | retry_count++; |
| 3496 | goto retry_page; |
| 3497 | } else { |
| 3498 | devtprintk(ioc, printk(MYIOC_s_DEBUG_FMT |
| 3499 | "%s: Config page retry exceeded retry " |
| 3500 | "count deleting device 0x%llx\n", |
| 3501 | ioc->name, __func__, |
| 3502 | sas_info->sas_address)); |
| 3503 | } |
Kashyap, Desai | eedf92b | 2009-05-29 16:51:32 +0530 | [diff] [blame] | 3504 | } |
Kashyap, Desai | eedf92b | 2009-05-29 16:51:32 +0530 | [diff] [blame] | 3505 | |
Kashyap, Desai | a7938b0 | 2009-05-29 16:53:56 +0530 | [diff] [blame] | 3506 | /* delete device */ |
| 3507 | vtarget = mptsas_find_vtarget(ioc, |
Kashyap, Desai | eedf92b | 2009-05-29 16:51:32 +0530 | [diff] [blame] | 3508 | sas_info->fw.channel, sas_info->fw.id); |
Kashyap, Desai | a7938b0 | 2009-05-29 16:53:56 +0530 | [diff] [blame] | 3509 | |
| 3510 | if (vtarget) |
| 3511 | vtarget->deleted = 1; |
| 3512 | |
| 3513 | phy_info = mptsas_find_phyinfo_by_sas_address(ioc, |
| 3514 | sas_info->sas_address); |
| 3515 | |
| 3516 | if (phy_info) { |
| 3517 | mptsas_del_end_device(ioc, phy_info); |
| 3518 | goto redo_device_scan; |
| 3519 | } |
| 3520 | } else |
| 3521 | mptsas_volume_delete(ioc, sas_info->fw.id); |
Kashyap, Desai | eedf92b | 2009-05-29 16:51:32 +0530 | [diff] [blame] | 3522 | } |
Kashyap, Desai | a7938b0 | 2009-05-29 16:53:56 +0530 | [diff] [blame] | 3523 | mutex_lock(&ioc->sas_device_info_mutex); |
Kashyap, Desai | eedf92b | 2009-05-29 16:51:32 +0530 | [diff] [blame] | 3524 | |
| 3525 | /* expanders */ |
| 3526 | mutex_lock(&ioc->sas_topology_mutex); |
| 3527 | redo_expander_scan: |
| 3528 | list_for_each_entry(port_info, &ioc->sas_topology, list) { |
| 3529 | |
| 3530 | if (port_info->phy_info && |
| 3531 | (!(port_info->phy_info[0].identify.device_info & |
| 3532 | MPI_SAS_DEVICE_INFO_SMP_TARGET))) |
| 3533 | continue; |
| 3534 | found_expander = 0; |
| 3535 | handle = 0xFFFF; |
| 3536 | while (!mptsas_sas_expander_pg0(ioc, &buffer, |
| 3537 | (MPI_SAS_EXPAND_PGAD_FORM_GET_NEXT_HANDLE << |
| 3538 | MPI_SAS_EXPAND_PGAD_FORM_SHIFT), handle) && |
| 3539 | !found_expander) { |
| 3540 | |
| 3541 | handle = buffer.phy_info[0].handle; |
| 3542 | if (buffer.phy_info[0].identify.sas_address == |
| 3543 | port_info->phy_info[0].identify.sas_address) { |
| 3544 | found_expander = 1; |
| 3545 | } |
| 3546 | kfree(buffer.phy_info); |
| 3547 | } |
| 3548 | |
| 3549 | if (!found_expander) { |
| 3550 | mptsas_expander_delete(ioc, port_info, 0); |
| 3551 | goto redo_expander_scan; |
| 3552 | } |
| 3553 | } |
| 3554 | mutex_lock(&ioc->sas_topology_mutex); |
| 3555 | } |
| 3556 | |
Kashyap, Desai | f9c3402 | 2009-05-29 16:49:36 +0530 | [diff] [blame] | 3557 | /** |
| 3558 | * mptsas_probe_expanders - adding expanders |
| 3559 | * @ioc: Pointer to MPT_ADAPTER structure |
| 3560 | * |
| 3561 | **/ |
| 3562 | static void |
| 3563 | mptsas_probe_expanders(MPT_ADAPTER *ioc) |
| 3564 | { |
| 3565 | struct mptsas_portinfo buffer, *port_info; |
| 3566 | u32 handle; |
| 3567 | int i; |
| 3568 | |
| 3569 | handle = 0xFFFF; |
| 3570 | while (!mptsas_sas_expander_pg0(ioc, &buffer, |
| 3571 | (MPI_SAS_EXPAND_PGAD_FORM_GET_NEXT_HANDLE << |
| 3572 | MPI_SAS_EXPAND_PGAD_FORM_SHIFT), handle)) { |
| 3573 | |
| 3574 | handle = buffer.phy_info[0].handle; |
| 3575 | port_info = mptsas_find_portinfo_by_sas_address(ioc, |
| 3576 | buffer.phy_info[0].identify.sas_address); |
| 3577 | |
| 3578 | if (port_info) { |
| 3579 | /* refreshing handles */ |
| 3580 | for (i = 0; i < buffer.num_phys; i++) { |
| 3581 | port_info->phy_info[i].handle = handle; |
| 3582 | port_info->phy_info[i].identify.handle_parent = |
| 3583 | buffer.phy_info[0].identify.handle_parent; |
| 3584 | } |
| 3585 | mptsas_expander_refresh(ioc, port_info); |
| 3586 | kfree(buffer.phy_info); |
| 3587 | continue; |
| 3588 | } |
| 3589 | |
| 3590 | port_info = kzalloc(sizeof(struct mptsas_portinfo), GFP_KERNEL); |
| 3591 | if (!port_info) { |
| 3592 | dfailprintk(ioc, printk(MYIOC_s_ERR_FMT |
| 3593 | "%s: exit at line=%d\n", ioc->name, |
| 3594 | __func__, __LINE__)); |
| 3595 | return; |
| 3596 | } |
| 3597 | port_info->num_phys = buffer.num_phys; |
| 3598 | port_info->phy_info = buffer.phy_info; |
| 3599 | for (i = 0; i < port_info->num_phys; i++) |
| 3600 | port_info->phy_info[i].portinfo = port_info; |
| 3601 | mutex_lock(&ioc->sas_topology_mutex); |
| 3602 | list_add_tail(&port_info->list, &ioc->sas_topology); |
| 3603 | mutex_unlock(&ioc->sas_topology_mutex); |
| 3604 | printk(MYIOC_s_INFO_FMT "add expander: num_phys %d, " |
| 3605 | "sas_addr (0x%llx)\n", ioc->name, port_info->num_phys, |
| 3606 | (unsigned long long)buffer.phy_info[0].identify.sas_address); |
| 3607 | mptsas_expander_refresh(ioc, port_info); |
| 3608 | } |
| 3609 | } |
| 3610 | |
| 3611 | static void |
| 3612 | mptsas_probe_devices(MPT_ADAPTER *ioc) |
| 3613 | { |
| 3614 | u16 handle; |
| 3615 | struct mptsas_devinfo sas_device; |
| 3616 | struct mptsas_phyinfo *phy_info; |
| 3617 | |
| 3618 | handle = 0xFFFF; |
| 3619 | while (!(mptsas_sas_device_pg0(ioc, &sas_device, |
| 3620 | MPI_SAS_DEVICE_PGAD_FORM_GET_NEXT_HANDLE, handle))) { |
| 3621 | |
| 3622 | handle = sas_device.handle; |
| 3623 | |
| 3624 | if ((sas_device.device_info & |
| 3625 | (MPI_SAS_DEVICE_INFO_SSP_TARGET | |
| 3626 | MPI_SAS_DEVICE_INFO_STP_TARGET | |
| 3627 | MPI_SAS_DEVICE_INFO_SATA_DEVICE)) == 0) |
| 3628 | continue; |
| 3629 | |
| 3630 | phy_info = mptsas_refreshing_device_handles(ioc, &sas_device); |
| 3631 | if (!phy_info) |
| 3632 | continue; |
| 3633 | |
| 3634 | if (mptsas_get_rphy(phy_info)) |
| 3635 | continue; |
| 3636 | |
| 3637 | mptsas_add_end_device(ioc, phy_info); |
| 3638 | } |
Moore, Eric | e6b2d76 | 2006-03-14 09:14:24 -0700 | [diff] [blame] | 3639 | } |
| 3640 | |
Kashyap, Desai | 2f18786 | 2009-05-29 16:52:37 +0530 | [diff] [blame] | 3641 | /** |
| 3642 | * mptsas_scan_sas_topology - |
| 3643 | * @ioc: Pointer to MPT_ADAPTER structure |
| 3644 | * @sas_address: |
| 3645 | * |
| 3646 | **/ |
Christoph Hellwig | 0c33b27 | 2005-09-09 16:27:19 +0200 | [diff] [blame] | 3647 | static void |
| 3648 | mptsas_scan_sas_topology(MPT_ADAPTER *ioc) |
| 3649 | { |
Kashyap, Desai | f9c3402 | 2009-05-29 16:49:36 +0530 | [diff] [blame] | 3650 | struct scsi_device *sdev; |
Moore, Eric | f44e546 | 2006-03-14 09:14:21 -0700 | [diff] [blame] | 3651 | int i; |
Christoph Hellwig | 0c33b27 | 2005-09-09 16:27:19 +0200 | [diff] [blame] | 3652 | |
Moore, Eric | e6b2d76 | 2006-03-14 09:14:24 -0700 | [diff] [blame] | 3653 | mptsas_probe_hba_phys(ioc); |
Kashyap, Desai | f9c3402 | 2009-05-29 16:49:36 +0530 | [diff] [blame] | 3654 | mptsas_probe_expanders(ioc); |
| 3655 | mptsas_probe_devices(ioc); |
| 3656 | |
Moore, Eric | f44e546 | 2006-03-14 09:14:21 -0700 | [diff] [blame] | 3657 | /* |
| 3658 | Reporting RAID volumes. |
| 3659 | */ |
Kashyap, Desai | f9c3402 | 2009-05-29 16:49:36 +0530 | [diff] [blame] | 3660 | if (!ioc->ir_firmware || !ioc->raid_data.pIocPg2 || |
| 3661 | !ioc->raid_data.pIocPg2->NumActiveVolumes) |
| 3662 | return; |
Eric Moore | 793955f | 2007-01-29 09:42:20 -0700 | [diff] [blame] | 3663 | for (i = 0; i < ioc->raid_data.pIocPg2->NumActiveVolumes; i++) { |
Kashyap, Desai | f9c3402 | 2009-05-29 16:49:36 +0530 | [diff] [blame] | 3664 | sdev = scsi_device_lookup(ioc->sh, MPTSAS_RAID_CHANNEL, |
| 3665 | ioc->raid_data.pIocPg2->RaidVolume[i].VolumeID, 0); |
| 3666 | if (sdev) { |
| 3667 | scsi_device_put(sdev); |
| 3668 | continue; |
| 3669 | } |
| 3670 | printk(MYIOC_s_INFO_FMT "attaching raid volume, channel %d, " |
| 3671 | "id %d\n", ioc->name, MPTSAS_RAID_CHANNEL, |
| 3672 | ioc->raid_data.pIocPg2->RaidVolume[i].VolumeID); |
James Bottomley | e8bf394 | 2006-07-11 17:49:34 -0400 | [diff] [blame] | 3673 | scsi_add_device(ioc->sh, MPTSAS_RAID_CHANNEL, |
Moore, Eric | f44e546 | 2006-03-14 09:14:21 -0700 | [diff] [blame] | 3674 | ioc->raid_data.pIocPg2->RaidVolume[i].VolumeID, 0); |
| 3675 | } |
Moore, Eric | e6b2d76 | 2006-03-14 09:14:24 -0700 | [diff] [blame] | 3676 | } |
| 3677 | |
Kashyap, Desai | 57e9851 | 2009-05-29 16:55:09 +0530 | [diff] [blame] | 3678 | |
| 3679 | static void |
| 3680 | mptsas_handle_queue_full_event(struct fw_event_work *fw_event) |
| 3681 | { |
| 3682 | MPT_ADAPTER *ioc; |
| 3683 | EventDataQueueFull_t *qfull_data; |
| 3684 | struct mptsas_device_info *sas_info; |
| 3685 | struct scsi_device *sdev; |
| 3686 | int depth; |
| 3687 | int id = -1; |
| 3688 | int channel = -1; |
| 3689 | int fw_id, fw_channel; |
| 3690 | u16 current_depth; |
| 3691 | |
| 3692 | |
| 3693 | ioc = fw_event->ioc; |
| 3694 | qfull_data = (EventDataQueueFull_t *)fw_event->event_data; |
| 3695 | fw_id = qfull_data->TargetID; |
| 3696 | fw_channel = qfull_data->Bus; |
| 3697 | current_depth = le16_to_cpu(qfull_data->CurrentDepth); |
| 3698 | |
| 3699 | /* if hidden raid component, look for the volume id */ |
| 3700 | mutex_lock(&ioc->sas_device_info_mutex); |
| 3701 | if (mptscsih_is_phys_disk(ioc, fw_channel, fw_id)) { |
| 3702 | list_for_each_entry(sas_info, &ioc->sas_device_info_list, |
| 3703 | list) { |
| 3704 | if (sas_info->is_cached || |
| 3705 | sas_info->is_logical_volume) |
| 3706 | continue; |
| 3707 | if (sas_info->is_hidden_raid_component && |
| 3708 | (sas_info->fw.channel == fw_channel && |
| 3709 | sas_info->fw.id == fw_id)) { |
| 3710 | id = sas_info->volume_id; |
| 3711 | channel = MPTSAS_RAID_CHANNEL; |
| 3712 | goto out; |
| 3713 | } |
| 3714 | } |
| 3715 | } else { |
| 3716 | list_for_each_entry(sas_info, &ioc->sas_device_info_list, |
| 3717 | list) { |
| 3718 | if (sas_info->is_cached || |
| 3719 | sas_info->is_hidden_raid_component || |
| 3720 | sas_info->is_logical_volume) |
| 3721 | continue; |
| 3722 | if (sas_info->fw.channel == fw_channel && |
| 3723 | sas_info->fw.id == fw_id) { |
| 3724 | id = sas_info->os.id; |
| 3725 | channel = sas_info->os.channel; |
| 3726 | goto out; |
| 3727 | } |
| 3728 | } |
| 3729 | |
| 3730 | } |
| 3731 | |
| 3732 | out: |
| 3733 | mutex_unlock(&ioc->sas_device_info_mutex); |
| 3734 | |
| 3735 | if (id != -1) { |
| 3736 | shost_for_each_device(sdev, ioc->sh) { |
| 3737 | if (sdev->id == id && sdev->channel == channel) { |
| 3738 | if (current_depth > sdev->queue_depth) { |
| 3739 | sdev_printk(KERN_INFO, sdev, |
| 3740 | "strange observation, the queue " |
| 3741 | "depth is (%d) meanwhile fw queue " |
| 3742 | "depth (%d)\n", sdev->queue_depth, |
| 3743 | current_depth); |
| 3744 | continue; |
| 3745 | } |
| 3746 | depth = scsi_track_queue_full(sdev, |
| 3747 | current_depth - 1); |
| 3748 | if (depth > 0) |
| 3749 | sdev_printk(KERN_INFO, sdev, |
| 3750 | "Queue depth reduced to (%d)\n", |
| 3751 | depth); |
| 3752 | else if (depth < 0) |
| 3753 | sdev_printk(KERN_INFO, sdev, |
| 3754 | "Tagged Command Queueing is being " |
| 3755 | "disabled\n"); |
| 3756 | else if (depth == 0) |
| 3757 | sdev_printk(KERN_INFO, sdev, |
| 3758 | "Queue depth not changed yet\n"); |
| 3759 | } |
| 3760 | } |
| 3761 | } |
| 3762 | |
| 3763 | mptsas_free_fw_event(ioc, fw_event); |
| 3764 | } |
| 3765 | |
| 3766 | |
Christoph Hellwig | 9a28f49 | 2006-01-13 18:04:41 +0100 | [diff] [blame] | 3767 | static struct mptsas_phyinfo * |
Eric Moore | 547f9a2 | 2006-06-27 14:42:12 -0600 | [diff] [blame] | 3768 | mptsas_find_phyinfo_by_sas_address(MPT_ADAPTER *ioc, u64 sas_address) |
Christoph Hellwig | 9a28f49 | 2006-01-13 18:04:41 +0100 | [diff] [blame] | 3769 | { |
| 3770 | struct mptsas_portinfo *port_info; |
Christoph Hellwig | 9a28f49 | 2006-01-13 18:04:41 +0100 | [diff] [blame] | 3771 | struct mptsas_phyinfo *phy_info = NULL; |
Eric Moore | 547f9a2 | 2006-06-27 14:42:12 -0600 | [diff] [blame] | 3772 | int i; |
Christoph Hellwig | 9a28f49 | 2006-01-13 18:04:41 +0100 | [diff] [blame] | 3773 | |
Christoph Hellwig | 9a28f49 | 2006-01-13 18:04:41 +0100 | [diff] [blame] | 3774 | mutex_lock(&ioc->sas_topology_mutex); |
| 3775 | list_for_each_entry(port_info, &ioc->sas_topology, list) { |
| 3776 | for (i = 0; i < port_info->num_phys; i++) { |
Eric Moore | 547f9a2 | 2006-06-27 14:42:12 -0600 | [diff] [blame] | 3777 | if (!mptsas_is_end_device( |
| 3778 | &port_info->phy_info[i].attached)) |
| 3779 | continue; |
Eric Moore | b506ade | 2007-01-29 09:45:37 -0700 | [diff] [blame] | 3780 | if (port_info->phy_info[i].attached.sas_address |
| 3781 | != sas_address) |
| 3782 | continue; |
Eric Moore | 547f9a2 | 2006-06-27 14:42:12 -0600 | [diff] [blame] | 3783 | phy_info = &port_info->phy_info[i]; |
| 3784 | break; |
Christoph Hellwig | 9a28f49 | 2006-01-13 18:04:41 +0100 | [diff] [blame] | 3785 | } |
| 3786 | } |
| 3787 | mutex_unlock(&ioc->sas_topology_mutex); |
Christoph Hellwig | 9a28f49 | 2006-01-13 18:04:41 +0100 | [diff] [blame] | 3788 | return phy_info; |
| 3789 | } |
| 3790 | |
Kashyap, Desai | a7938b0 | 2009-05-29 16:53:56 +0530 | [diff] [blame] | 3791 | /** |
| 3792 | * mptsas_find_phyinfo_by_phys_disk_num - |
| 3793 | * @ioc: Pointer to MPT_ADAPTER structure |
| 3794 | * @phys_disk_num: |
| 3795 | * @channel: |
| 3796 | * @id: |
| 3797 | * |
| 3798 | **/ |
Eric Moore | b506ade | 2007-01-29 09:45:37 -0700 | [diff] [blame] | 3799 | static struct mptsas_phyinfo * |
Kashyap, Desai | a7938b0 | 2009-05-29 16:53:56 +0530 | [diff] [blame] | 3800 | mptsas_find_phyinfo_by_phys_disk_num(MPT_ADAPTER *ioc, u8 phys_disk_num, |
| 3801 | u8 channel, u8 id) |
Eric Moore | b506ade | 2007-01-29 09:45:37 -0700 | [diff] [blame] | 3802 | { |
Eric Moore | b506ade | 2007-01-29 09:45:37 -0700 | [diff] [blame] | 3803 | struct mptsas_phyinfo *phy_info = NULL; |
Kashyap, Desai | a7938b0 | 2009-05-29 16:53:56 +0530 | [diff] [blame] | 3804 | struct mptsas_portinfo *port_info; |
| 3805 | RaidPhysDiskPage1_t *phys_disk = NULL; |
| 3806 | int num_paths; |
| 3807 | u64 sas_address = 0; |
Eric Moore | b506ade | 2007-01-29 09:45:37 -0700 | [diff] [blame] | 3808 | int i; |
| 3809 | |
Kashyap, Desai | a7938b0 | 2009-05-29 16:53:56 +0530 | [diff] [blame] | 3810 | phy_info = NULL; |
| 3811 | if (!ioc->raid_data.pIocPg3) |
| 3812 | return NULL; |
| 3813 | /* dual port support */ |
| 3814 | num_paths = mpt_raid_phys_disk_get_num_paths(ioc, phys_disk_num); |
| 3815 | if (!num_paths) |
| 3816 | goto out; |
| 3817 | phys_disk = kzalloc(offsetof(RaidPhysDiskPage1_t, Path) + |
| 3818 | (num_paths * sizeof(RAID_PHYS_DISK1_PATH)), GFP_KERNEL); |
| 3819 | if (!phys_disk) |
| 3820 | goto out; |
| 3821 | mpt_raid_phys_disk_pg1(ioc, phys_disk_num, phys_disk); |
| 3822 | for (i = 0; i < num_paths; i++) { |
| 3823 | if ((phys_disk->Path[i].Flags & 1) != 0) |
| 3824 | /* entry no longer valid */ |
| 3825 | continue; |
| 3826 | if ((id == phys_disk->Path[i].PhysDiskID) && |
| 3827 | (channel == phys_disk->Path[i].PhysDiskBus)) { |
| 3828 | memcpy(&sas_address, &phys_disk->Path[i].WWID, |
| 3829 | sizeof(u64)); |
| 3830 | phy_info = mptsas_find_phyinfo_by_sas_address(ioc, |
| 3831 | sas_address); |
| 3832 | goto out; |
| 3833 | } |
| 3834 | } |
| 3835 | |
| 3836 | out: |
| 3837 | kfree(phys_disk); |
| 3838 | if (phy_info) |
| 3839 | return phy_info; |
| 3840 | |
| 3841 | /* |
| 3842 | * Extra code to handle RAID0 case, where the sas_address is not updated |
| 3843 | * in phys_disk_page_1 when hotswapped |
| 3844 | */ |
Eric Moore | b506ade | 2007-01-29 09:45:37 -0700 | [diff] [blame] | 3845 | mutex_lock(&ioc->sas_topology_mutex); |
| 3846 | list_for_each_entry(port_info, &ioc->sas_topology, list) { |
Kashyap, Desai | a7938b0 | 2009-05-29 16:53:56 +0530 | [diff] [blame] | 3847 | for (i = 0; i < port_info->num_phys && !phy_info; i++) { |
Eric Moore | b506ade | 2007-01-29 09:45:37 -0700 | [diff] [blame] | 3848 | if (!mptsas_is_end_device( |
| 3849 | &port_info->phy_info[i].attached)) |
| 3850 | continue; |
| 3851 | if (port_info->phy_info[i].attached.phys_disk_num == ~0) |
| 3852 | continue; |
Kashyap, Desai | a7938b0 | 2009-05-29 16:53:56 +0530 | [diff] [blame] | 3853 | if ((port_info->phy_info[i].attached.phys_disk_num == |
| 3854 | phys_disk_num) && |
| 3855 | (port_info->phy_info[i].attached.id == id) && |
| 3856 | (port_info->phy_info[i].attached.channel == |
| 3857 | channel)) |
| 3858 | phy_info = &port_info->phy_info[i]; |
Eric Moore | 547f9a2 | 2006-06-27 14:42:12 -0600 | [diff] [blame] | 3859 | } |
Christoph Hellwig | 9a28f49 | 2006-01-13 18:04:41 +0100 | [diff] [blame] | 3860 | } |
| 3861 | mutex_unlock(&ioc->sas_topology_mutex); |
Christoph Hellwig | 9a28f49 | 2006-01-13 18:04:41 +0100 | [diff] [blame] | 3862 | return phy_info; |
| 3863 | } |
| 3864 | |
| 3865 | static void |
Moore, Eric | f44e546 | 2006-03-14 09:14:21 -0700 | [diff] [blame] | 3866 | mptsas_reprobe_lun(struct scsi_device *sdev, void *data) |
| 3867 | { |
Eric Moore | f99be43 | 2007-01-04 20:46:54 -0700 | [diff] [blame] | 3868 | int rc; |
| 3869 | |
Moore, Eric | f44e546 | 2006-03-14 09:14:21 -0700 | [diff] [blame] | 3870 | sdev->no_uld_attach = data ? 1 : 0; |
Eric Moore | f99be43 | 2007-01-04 20:46:54 -0700 | [diff] [blame] | 3871 | rc = scsi_device_reprobe(sdev); |
Moore, Eric | f44e546 | 2006-03-14 09:14:21 -0700 | [diff] [blame] | 3872 | } |
| 3873 | |
| 3874 | static void |
| 3875 | mptsas_reprobe_target(struct scsi_target *starget, int uld_attach) |
| 3876 | { |
| 3877 | starget_for_each_device(starget, uld_attach ? (void *)1 : NULL, |
| 3878 | mptsas_reprobe_lun); |
| 3879 | } |
| 3880 | |
Eric Moore | b506ade | 2007-01-29 09:45:37 -0700 | [diff] [blame] | 3881 | static void |
| 3882 | mptsas_adding_inactive_raid_components(MPT_ADAPTER *ioc, u8 channel, u8 id) |
| 3883 | { |
| 3884 | CONFIGPARMS cfg; |
| 3885 | ConfigPageHeader_t hdr; |
| 3886 | dma_addr_t dma_handle; |
| 3887 | pRaidVolumePage0_t buffer = NULL; |
| 3888 | RaidPhysDiskPage0_t phys_disk; |
| 3889 | int i; |
Kashyap, Desai | 3eb0822c | 2009-05-29 16:47:26 +0530 | [diff] [blame] | 3890 | struct mptsas_phyinfo *phy_info; |
| 3891 | struct mptsas_devinfo sas_device; |
Eric Moore | b506ade | 2007-01-29 09:45:37 -0700 | [diff] [blame] | 3892 | |
| 3893 | memset(&cfg, 0 , sizeof(CONFIGPARMS)); |
| 3894 | memset(&hdr, 0 , sizeof(ConfigPageHeader_t)); |
| 3895 | hdr.PageType = MPI_CONFIG_PAGETYPE_RAID_VOLUME; |
| 3896 | cfg.pageAddr = (channel << 8) + id; |
| 3897 | cfg.cfghdr.hdr = &hdr; |
| 3898 | cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER; |
| 3899 | |
| 3900 | if (mpt_config(ioc, &cfg) != 0) |
| 3901 | goto out; |
| 3902 | |
| 3903 | if (!hdr.PageLength) |
| 3904 | goto out; |
| 3905 | |
| 3906 | buffer = pci_alloc_consistent(ioc->pcidev, hdr.PageLength * 4, |
| 3907 | &dma_handle); |
| 3908 | |
| 3909 | if (!buffer) |
| 3910 | goto out; |
| 3911 | |
| 3912 | cfg.physAddr = dma_handle; |
| 3913 | cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT; |
| 3914 | |
| 3915 | if (mpt_config(ioc, &cfg) != 0) |
| 3916 | goto out; |
| 3917 | |
| 3918 | if (!(buffer->VolumeStatus.Flags & |
| 3919 | MPI_RAIDVOL0_STATUS_FLAG_VOLUME_INACTIVE)) |
| 3920 | goto out; |
| 3921 | |
| 3922 | if (!buffer->NumPhysDisks) |
| 3923 | goto out; |
| 3924 | |
| 3925 | for (i = 0; i < buffer->NumPhysDisks; i++) { |
| 3926 | |
| 3927 | if (mpt_raid_phys_disk_pg0(ioc, |
| 3928 | buffer->PhysDisk[i].PhysDiskNum, &phys_disk) != 0) |
| 3929 | continue; |
| 3930 | |
Kashyap, Desai | 3eb0822c | 2009-05-29 16:47:26 +0530 | [diff] [blame] | 3931 | if (mptsas_sas_device_pg0(ioc, &sas_device, |
| 3932 | (MPI_SAS_DEVICE_PGAD_FORM_BUS_TARGET_ID << |
| 3933 | MPI_SAS_DEVICE_PGAD_FORM_SHIFT), |
| 3934 | (phys_disk.PhysDiskBus << 8) + |
| 3935 | phys_disk.PhysDiskID)) |
| 3936 | continue; |
Eric Moore | b506ade | 2007-01-29 09:45:37 -0700 | [diff] [blame] | 3937 | |
Kashyap, Desai | 3eb0822c | 2009-05-29 16:47:26 +0530 | [diff] [blame] | 3938 | phy_info = mptsas_find_phyinfo_by_sas_address(ioc, |
| 3939 | sas_device.sas_address); |
| 3940 | mptsas_add_end_device(ioc, phy_info); |
Eric Moore | b506ade | 2007-01-29 09:45:37 -0700 | [diff] [blame] | 3941 | } |
| 3942 | |
| 3943 | out: |
| 3944 | if (buffer) |
| 3945 | pci_free_consistent(ioc->pcidev, hdr.PageLength * 4, buffer, |
| 3946 | dma_handle); |
| 3947 | } |
Moore, Eric | e6b2d76 | 2006-03-14 09:14:24 -0700 | [diff] [blame] | 3948 | /* |
| 3949 | * Work queue thread to handle SAS hotplug events |
| 3950 | */ |
Moore, Eric | f44e546 | 2006-03-14 09:14:21 -0700 | [diff] [blame] | 3951 | static void |
Kashyap, Desai | 3eb0822c | 2009-05-29 16:47:26 +0530 | [diff] [blame] | 3952 | mptsas_hotplug_work(MPT_ADAPTER *ioc, struct fw_event_work *fw_event, |
| 3953 | struct mptsas_hotplug_event *hot_plug_info) |
Christoph Hellwig | 9a28f49 | 2006-01-13 18:04:41 +0100 | [diff] [blame] | 3954 | { |
Christoph Hellwig | 9a28f49 | 2006-01-13 18:04:41 +0100 | [diff] [blame] | 3955 | struct mptsas_phyinfo *phy_info; |
Eric Moore | 547f9a2 | 2006-06-27 14:42:12 -0600 | [diff] [blame] | 3956 | struct scsi_target * starget; |
Moore, Eric | c73787ee | 2006-01-26 16:20:06 -0700 | [diff] [blame] | 3957 | struct mptsas_devinfo sas_device; |
Moore, Eric | f44e546 | 2006-03-14 09:14:21 -0700 | [diff] [blame] | 3958 | VirtTarget *vtarget; |
Kashyap, Desai | 3eb0822c | 2009-05-29 16:47:26 +0530 | [diff] [blame] | 3959 | int i; |
Eric Moore | 547f9a2 | 2006-06-27 14:42:12 -0600 | [diff] [blame] | 3960 | |
Kashyap, Desai | 3eb0822c | 2009-05-29 16:47:26 +0530 | [diff] [blame] | 3961 | switch (hot_plug_info->event_type) { |
Christoph Hellwig | 9a28f49 | 2006-01-13 18:04:41 +0100 | [diff] [blame] | 3962 | |
Kashyap, Desai | 3eb0822c | 2009-05-29 16:47:26 +0530 | [diff] [blame] | 3963 | case MPTSAS_ADD_PHYSDISK: |
Eric Moore | b506ade | 2007-01-29 09:45:37 -0700 | [diff] [blame] | 3964 | |
Kashyap, Desai | 3eb0822c | 2009-05-29 16:47:26 +0530 | [diff] [blame] | 3965 | if (!ioc->raid_data.pIocPg2) |
Eric Moore | b506ade | 2007-01-29 09:45:37 -0700 | [diff] [blame] | 3966 | break; |
Eric Moore | b506ade | 2007-01-29 09:45:37 -0700 | [diff] [blame] | 3967 | |
Kashyap, Desai | 3eb0822c | 2009-05-29 16:47:26 +0530 | [diff] [blame] | 3968 | for (i = 0; i < ioc->raid_data.pIocPg2->NumActiveVolumes; i++) { |
| 3969 | if (ioc->raid_data.pIocPg2->RaidVolume[i].VolumeID == |
| 3970 | hot_plug_info->id) { |
| 3971 | printk(MYIOC_s_WARN_FMT "firmware bug: unable " |
| 3972 | "to add hidden disk - target_id matchs " |
| 3973 | "volume_id\n", ioc->name); |
| 3974 | mptsas_free_fw_event(ioc, fw_event); |
| 3975 | return; |
Moore, Eric | f44e546 | 2006-03-14 09:14:21 -0700 | [diff] [blame] | 3976 | } |
Christoph Hellwig | 9a28f49 | 2006-01-13 18:04:41 +0100 | [diff] [blame] | 3977 | } |
Kashyap, Desai | 3eb0822c | 2009-05-29 16:47:26 +0530 | [diff] [blame] | 3978 | mpt_findImVolumes(ioc); |
Christoph Hellwig | 9a28f49 | 2006-01-13 18:04:41 +0100 | [diff] [blame] | 3979 | |
Christoph Hellwig | 9a28f49 | 2006-01-13 18:04:41 +0100 | [diff] [blame] | 3980 | case MPTSAS_ADD_DEVICE: |
Kashyap, Desai | 3eb0822c | 2009-05-29 16:47:26 +0530 | [diff] [blame] | 3981 | memset(&sas_device, 0, sizeof(struct mptsas_devinfo)); |
| 3982 | mptsas_sas_device_pg0(ioc, &sas_device, |
| 3983 | (MPI_SAS_DEVICE_PGAD_FORM_BUS_TARGET_ID << |
| 3984 | MPI_SAS_DEVICE_PGAD_FORM_SHIFT), |
| 3985 | (hot_plug_info->channel << 8) + |
| 3986 | hot_plug_info->id); |
Moore, Eric | c73787ee | 2006-01-26 16:20:06 -0700 | [diff] [blame] | 3987 | |
Kashyap, Desai | 3eb0822c | 2009-05-29 16:47:26 +0530 | [diff] [blame] | 3988 | if (!sas_device.handle) |
| 3989 | return; |
Moore, Eric | bd23e94 | 2006-04-17 12:43:04 -0600 | [diff] [blame] | 3990 | |
Kashyap, Desai | 3eb0822c | 2009-05-29 16:47:26 +0530 | [diff] [blame] | 3991 | phy_info = mptsas_refreshing_device_handles(ioc, &sas_device); |
| 3992 | if (!phy_info) |
| 3993 | break; |
| 3994 | |
| 3995 | if (mptsas_get_rphy(phy_info)) |
| 3996 | break; |
| 3997 | |
| 3998 | mptsas_add_end_device(ioc, phy_info); |
| 3999 | break; |
| 4000 | |
| 4001 | case MPTSAS_DEL_DEVICE: |
| 4002 | phy_info = mptsas_find_phyinfo_by_sas_address(ioc, |
| 4003 | hot_plug_info->sas_address); |
| 4004 | mptsas_del_end_device(ioc, phy_info); |
| 4005 | break; |
| 4006 | |
| 4007 | case MPTSAS_DEL_PHYSDISK: |
| 4008 | |
| 4009 | mpt_findImVolumes(ioc); |
| 4010 | |
| 4011 | phy_info = mptsas_find_phyinfo_by_phys_disk_num( |
Kashyap, Desai | a7938b0 | 2009-05-29 16:53:56 +0530 | [diff] [blame] | 4012 | ioc, hot_plug_info->phys_disk_num, |
| 4013 | hot_plug_info->channel, |
| 4014 | hot_plug_info->id); |
Kashyap, Desai | 3eb0822c | 2009-05-29 16:47:26 +0530 | [diff] [blame] | 4015 | mptsas_del_end_device(ioc, phy_info); |
| 4016 | break; |
| 4017 | |
| 4018 | case MPTSAS_ADD_PHYSDISK_REPROBE: |
| 4019 | |
Christoph Hellwig | e309444 | 2006-02-16 13:25:36 +0100 | [diff] [blame] | 4020 | if (mptsas_sas_device_pg0(ioc, &sas_device, |
| 4021 | (MPI_SAS_DEVICE_PGAD_FORM_BUS_TARGET_ID << |
Eric Moore | b506ade | 2007-01-29 09:45:37 -0700 | [diff] [blame] | 4022 | MPI_SAS_DEVICE_PGAD_FORM_SHIFT), |
Kashyap, Desai | 3eb0822c | 2009-05-29 16:47:26 +0530 | [diff] [blame] | 4023 | (hot_plug_info->channel << 8) + hot_plug_info->id)) { |
| 4024 | dfailprintk(ioc, printk(MYIOC_s_ERR_FMT |
| 4025 | "%s: fw_id=%d exit at line=%d\n", ioc->name, |
| 4026 | __func__, hot_plug_info->id, __LINE__)); |
Christoph Hellwig | e309444 | 2006-02-16 13:25:36 +0100 | [diff] [blame] | 4027 | break; |
Moore, Eric | e6b2d76 | 2006-03-14 09:14:24 -0700 | [diff] [blame] | 4028 | } |
| 4029 | |
Kashyap, Desai | 3eb0822c | 2009-05-29 16:47:26 +0530 | [diff] [blame] | 4030 | phy_info = mptsas_find_phyinfo_by_sas_address( |
| 4031 | ioc, sas_device.sas_address); |
Moore, Eric | f44e546 | 2006-03-14 09:14:21 -0700 | [diff] [blame] | 4032 | |
Kashyap, Desai | 3eb0822c | 2009-05-29 16:47:26 +0530 | [diff] [blame] | 4033 | if (!phy_info) { |
Prakash, Sathya | d6ecdd6 | 2007-07-24 15:47:41 +0530 | [diff] [blame] | 4034 | dfailprintk(ioc, printk(MYIOC_s_ERR_FMT |
Kashyap, Desai | 3eb0822c | 2009-05-29 16:47:26 +0530 | [diff] [blame] | 4035 | "%s: fw_id=%d exit at line=%d\n", ioc->name, |
| 4036 | __func__, hot_plug_info->id, __LINE__)); |
Eric Moore | 547f9a2 | 2006-06-27 14:42:12 -0600 | [diff] [blame] | 4037 | break; |
| 4038 | } |
| 4039 | |
| 4040 | starget = mptsas_get_starget(phy_info); |
Kashyap, Desai | 3eb0822c | 2009-05-29 16:47:26 +0530 | [diff] [blame] | 4041 | if (!starget) { |
| 4042 | dfailprintk(ioc, printk(MYIOC_s_ERR_FMT |
| 4043 | "%s: fw_id=%d exit at line=%d\n", ioc->name, |
| 4044 | __func__, hot_plug_info->id, __LINE__)); |
| 4045 | break; |
| 4046 | } |
Eric Moore | b506ade | 2007-01-29 09:45:37 -0700 | [diff] [blame] | 4047 | |
Kashyap, Desai | 3eb0822c | 2009-05-29 16:47:26 +0530 | [diff] [blame] | 4048 | vtarget = starget->hostdata; |
| 4049 | if (!vtarget) { |
| 4050 | dfailprintk(ioc, printk(MYIOC_s_ERR_FMT |
| 4051 | "%s: fw_id=%d exit at line=%d\n", ioc->name, |
| 4052 | __func__, hot_plug_info->id, __LINE__)); |
| 4053 | break; |
| 4054 | } |
Eric Moore | 547f9a2 | 2006-06-27 14:42:12 -0600 | [diff] [blame] | 4055 | |
Kashyap, Desai | 3eb0822c | 2009-05-29 16:47:26 +0530 | [diff] [blame] | 4056 | mpt_findImVolumes(ioc); |
| 4057 | |
| 4058 | starget_printk(KERN_INFO, starget, MYIOC_s_FMT "RAID Hidding: " |
| 4059 | "fw_channel=%d, fw_id=%d, physdsk %d, sas_addr 0x%llx\n", |
| 4060 | ioc->name, hot_plug_info->channel, hot_plug_info->id, |
| 4061 | hot_plug_info->phys_disk_num, (unsigned long long) |
| 4062 | sas_device.sas_address); |
| 4063 | |
| 4064 | vtarget->id = hot_plug_info->phys_disk_num; |
| 4065 | vtarget->tflags |= MPT_TARGET_FLAGS_RAID_COMPONENT; |
| 4066 | phy_info->attached.phys_disk_num = hot_plug_info->phys_disk_num; |
| 4067 | mptsas_reprobe_target(starget, 1); |
| 4068 | break; |
| 4069 | |
| 4070 | case MPTSAS_DEL_PHYSDISK_REPROBE: |
| 4071 | |
| 4072 | if (mptsas_sas_device_pg0(ioc, &sas_device, |
| 4073 | (MPI_SAS_DEVICE_PGAD_FORM_BUS_TARGET_ID << |
| 4074 | MPI_SAS_DEVICE_PGAD_FORM_SHIFT), |
| 4075 | (hot_plug_info->channel << 8) + hot_plug_info->id)) { |
Prakash, Sathya | d6ecdd6 | 2007-07-24 15:47:41 +0530 | [diff] [blame] | 4076 | dfailprintk(ioc, printk(MYIOC_s_ERR_FMT |
Kashyap, Desai | 3eb0822c | 2009-05-29 16:47:26 +0530 | [diff] [blame] | 4077 | "%s: fw_id=%d exit at line=%d\n", |
| 4078 | ioc->name, __func__, |
| 4079 | hot_plug_info->id, __LINE__)); |
Christoph Hellwig | 9a28f49 | 2006-01-13 18:04:41 +0100 | [diff] [blame] | 4080 | break; |
| 4081 | } |
| 4082 | |
Kashyap, Desai | 3eb0822c | 2009-05-29 16:47:26 +0530 | [diff] [blame] | 4083 | phy_info = mptsas_find_phyinfo_by_sas_address(ioc, |
| 4084 | sas_device.sas_address); |
| 4085 | if (!phy_info) { |
Prakash, Sathya | d6ecdd6 | 2007-07-24 15:47:41 +0530 | [diff] [blame] | 4086 | dfailprintk(ioc, printk(MYIOC_s_ERR_FMT |
Kashyap, Desai | 3eb0822c | 2009-05-29 16:47:26 +0530 | [diff] [blame] | 4087 | "%s: fw_id=%d exit at line=%d\n", ioc->name, |
| 4088 | __func__, hot_plug_info->id, __LINE__)); |
Christoph Hellwig | 9a28f49 | 2006-01-13 18:04:41 +0100 | [diff] [blame] | 4089 | break; |
Eric Moore | 547f9a2 | 2006-06-27 14:42:12 -0600 | [diff] [blame] | 4090 | } |
Eric Moore | b506ade | 2007-01-29 09:45:37 -0700 | [diff] [blame] | 4091 | |
Kashyap, Desai | 3eb0822c | 2009-05-29 16:47:26 +0530 | [diff] [blame] | 4092 | starget = mptsas_get_starget(phy_info); |
| 4093 | if (!starget) { |
Prakash, Sathya | d6ecdd6 | 2007-07-24 15:47:41 +0530 | [diff] [blame] | 4094 | dfailprintk(ioc, printk(MYIOC_s_ERR_FMT |
Kashyap, Desai | 3eb0822c | 2009-05-29 16:47:26 +0530 | [diff] [blame] | 4095 | "%s: fw_id=%d exit at line=%d\n", ioc->name, |
| 4096 | __func__, hot_plug_info->id, __LINE__)); |
Eric Moore | 547f9a2 | 2006-06-27 14:42:12 -0600 | [diff] [blame] | 4097 | break; |
| 4098 | } |
Christoph Hellwig | 9a28f49 | 2006-01-13 18:04:41 +0100 | [diff] [blame] | 4099 | |
Kashyap, Desai | 3eb0822c | 2009-05-29 16:47:26 +0530 | [diff] [blame] | 4100 | vtarget = starget->hostdata; |
| 4101 | if (!vtarget) { |
Prakash, Sathya | d6ecdd6 | 2007-07-24 15:47:41 +0530 | [diff] [blame] | 4102 | dfailprintk(ioc, printk(MYIOC_s_ERR_FMT |
Kashyap, Desai | 3eb0822c | 2009-05-29 16:47:26 +0530 | [diff] [blame] | 4103 | "%s: fw_id=%d exit at line=%d\n", ioc->name, |
| 4104 | __func__, hot_plug_info->id, __LINE__)); |
Christoph Hellwig | 9a28f49 | 2006-01-13 18:04:41 +0100 | [diff] [blame] | 4105 | break; |
| 4106 | } |
Kashyap, Desai | 3eb0822c | 2009-05-29 16:47:26 +0530 | [diff] [blame] | 4107 | |
| 4108 | if (!(vtarget->tflags & MPT_TARGET_FLAGS_RAID_COMPONENT)) { |
| 4109 | dfailprintk(ioc, printk(MYIOC_s_ERR_FMT |
| 4110 | "%s: fw_id=%d exit at line=%d\n", ioc->name, |
| 4111 | __func__, hot_plug_info->id, __LINE__)); |
| 4112 | break; |
| 4113 | } |
| 4114 | |
| 4115 | mpt_findImVolumes(ioc); |
| 4116 | |
| 4117 | starget_printk(KERN_INFO, starget, MYIOC_s_FMT "RAID Exposing:" |
| 4118 | " fw_channel=%d, fw_id=%d, physdsk %d, sas_addr 0x%llx\n", |
| 4119 | ioc->name, hot_plug_info->channel, hot_plug_info->id, |
| 4120 | hot_plug_info->phys_disk_num, (unsigned long long) |
| 4121 | sas_device.sas_address); |
| 4122 | |
| 4123 | vtarget->tflags &= ~MPT_TARGET_FLAGS_RAID_COMPONENT; |
| 4124 | vtarget->id = hot_plug_info->id; |
| 4125 | phy_info->attached.phys_disk_num = ~0; |
| 4126 | mptsas_reprobe_target(starget, 0); |
| 4127 | mptsas_add_device_component_by_fw(ioc, |
| 4128 | hot_plug_info->channel, hot_plug_info->id); |
Christoph Hellwig | 9a28f49 | 2006-01-13 18:04:41 +0100 | [diff] [blame] | 4129 | break; |
Kashyap, Desai | 3eb0822c | 2009-05-29 16:47:26 +0530 | [diff] [blame] | 4130 | |
Moore, Eric | c73787ee | 2006-01-26 16:20:06 -0700 | [diff] [blame] | 4131 | case MPTSAS_ADD_RAID: |
Kashyap, Desai | 3eb0822c | 2009-05-29 16:47:26 +0530 | [diff] [blame] | 4132 | |
Moore, Eric | c73787ee | 2006-01-26 16:20:06 -0700 | [diff] [blame] | 4133 | mpt_findImVolumes(ioc); |
Kashyap, Desai | 3eb0822c | 2009-05-29 16:47:26 +0530 | [diff] [blame] | 4134 | printk(MYIOC_s_INFO_FMT "attaching raid volume, channel %d, " |
| 4135 | "id %d\n", ioc->name, MPTSAS_RAID_CHANNEL, |
| 4136 | hot_plug_info->id); |
| 4137 | scsi_add_device(ioc->sh, MPTSAS_RAID_CHANNEL, |
| 4138 | hot_plug_info->id, 0); |
Moore, Eric | c73787ee | 2006-01-26 16:20:06 -0700 | [diff] [blame] | 4139 | break; |
Kashyap, Desai | 3eb0822c | 2009-05-29 16:47:26 +0530 | [diff] [blame] | 4140 | |
Moore, Eric | c73787ee | 2006-01-26 16:20:06 -0700 | [diff] [blame] | 4141 | case MPTSAS_DEL_RAID: |
Kashyap, Desai | 3eb0822c | 2009-05-29 16:47:26 +0530 | [diff] [blame] | 4142 | |
Moore, Eric | c73787ee | 2006-01-26 16:20:06 -0700 | [diff] [blame] | 4143 | mpt_findImVolumes(ioc); |
Kashyap, Desai | 3eb0822c | 2009-05-29 16:47:26 +0530 | [diff] [blame] | 4144 | printk(MYIOC_s_INFO_FMT "removing raid volume, channel %d, " |
| 4145 | "id %d\n", ioc->name, MPTSAS_RAID_CHANNEL, |
| 4146 | hot_plug_info->id); |
| 4147 | scsi_remove_device(hot_plug_info->sdev); |
| 4148 | scsi_device_put(hot_plug_info->sdev); |
Moore, Eric | c73787ee | 2006-01-26 16:20:06 -0700 | [diff] [blame] | 4149 | break; |
Kashyap, Desai | 3eb0822c | 2009-05-29 16:47:26 +0530 | [diff] [blame] | 4150 | |
Eric Moore | b506ade | 2007-01-29 09:45:37 -0700 | [diff] [blame] | 4151 | case MPTSAS_ADD_INACTIVE_VOLUME: |
Kashyap, Desai | 3eb0822c | 2009-05-29 16:47:26 +0530 | [diff] [blame] | 4152 | |
| 4153 | mpt_findImVolumes(ioc); |
Eric Moore | b506ade | 2007-01-29 09:45:37 -0700 | [diff] [blame] | 4154 | mptsas_adding_inactive_raid_components(ioc, |
Kashyap, Desai | 3eb0822c | 2009-05-29 16:47:26 +0530 | [diff] [blame] | 4155 | hot_plug_info->channel, hot_plug_info->id); |
Eric Moore | b506ade | 2007-01-29 09:45:37 -0700 | [diff] [blame] | 4156 | break; |
Kashyap, Desai | 3eb0822c | 2009-05-29 16:47:26 +0530 | [diff] [blame] | 4157 | |
Moore, Eric | bd23e94 | 2006-04-17 12:43:04 -0600 | [diff] [blame] | 4158 | default: |
| 4159 | break; |
Christoph Hellwig | 9a28f49 | 2006-01-13 18:04:41 +0100 | [diff] [blame] | 4160 | } |
| 4161 | |
Kashyap, Desai | 3eb0822c | 2009-05-29 16:47:26 +0530 | [diff] [blame] | 4162 | mptsas_free_fw_event(ioc, fw_event); |
Christoph Hellwig | 9a28f49 | 2006-01-13 18:04:41 +0100 | [diff] [blame] | 4163 | } |
| 4164 | |
| 4165 | static void |
Kashyap, Desai | 3eb0822c | 2009-05-29 16:47:26 +0530 | [diff] [blame] | 4166 | mptsas_send_sas_event(struct fw_event_work *fw_event) |
Christoph Hellwig | 9a28f49 | 2006-01-13 18:04:41 +0100 | [diff] [blame] | 4167 | { |
Kashyap, Desai | 3eb0822c | 2009-05-29 16:47:26 +0530 | [diff] [blame] | 4168 | MPT_ADAPTER *ioc; |
| 4169 | struct mptsas_hotplug_event hot_plug_info; |
| 4170 | EVENT_DATA_SAS_DEVICE_STATUS_CHANGE *sas_event_data; |
| 4171 | u32 device_info; |
| 4172 | u64 sas_address; |
| 4173 | |
| 4174 | ioc = fw_event->ioc; |
| 4175 | sas_event_data = (EVENT_DATA_SAS_DEVICE_STATUS_CHANGE *) |
| 4176 | fw_event->event_data; |
| 4177 | device_info = le32_to_cpu(sas_event_data->DeviceInfo); |
Christoph Hellwig | 9a28f49 | 2006-01-13 18:04:41 +0100 | [diff] [blame] | 4178 | |
| 4179 | if ((device_info & |
Kashyap, Desai | 3eb0822c | 2009-05-29 16:47:26 +0530 | [diff] [blame] | 4180 | (MPI_SAS_DEVICE_INFO_SSP_TARGET | |
| 4181 | MPI_SAS_DEVICE_INFO_STP_TARGET | |
| 4182 | MPI_SAS_DEVICE_INFO_SATA_DEVICE)) == 0) { |
| 4183 | mptsas_free_fw_event(ioc, fw_event); |
Christoph Hellwig | 9a28f49 | 2006-01-13 18:04:41 +0100 | [diff] [blame] | 4184 | return; |
Kashyap, Desai | 3eb0822c | 2009-05-29 16:47:26 +0530 | [diff] [blame] | 4185 | } |
| 4186 | |
| 4187 | if (sas_event_data->ReasonCode == |
| 4188 | MPI_EVENT_SAS_DEV_STAT_RC_NO_PERSIST_ADDED) { |
| 4189 | mptbase_sas_persist_operation(ioc, |
| 4190 | MPI_SAS_OP_CLEAR_NOT_PRESENT); |
| 4191 | mptsas_free_fw_event(ioc, fw_event); |
| 4192 | return; |
| 4193 | } |
Christoph Hellwig | 9a28f49 | 2006-01-13 18:04:41 +0100 | [diff] [blame] | 4194 | |
Moore, Eric | 4b76647 | 2006-03-14 09:14:12 -0700 | [diff] [blame] | 4195 | switch (sas_event_data->ReasonCode) { |
Moore, Eric | 4b76647 | 2006-03-14 09:14:12 -0700 | [diff] [blame] | 4196 | case MPI_EVENT_SAS_DEV_STAT_RC_NOT_RESPONDING: |
Eric Moore | df9e062 | 2007-01-29 09:46:21 -0700 | [diff] [blame] | 4197 | case MPI_EVENT_SAS_DEV_STAT_RC_ADDED: |
Kashyap, Desai | 3eb0822c | 2009-05-29 16:47:26 +0530 | [diff] [blame] | 4198 | memset(&hot_plug_info, 0, sizeof(struct mptsas_hotplug_event)); |
| 4199 | hot_plug_info.handle = le16_to_cpu(sas_event_data->DevHandle); |
| 4200 | hot_plug_info.channel = sas_event_data->Bus; |
| 4201 | hot_plug_info.id = sas_event_data->TargetID; |
| 4202 | hot_plug_info.phy_id = sas_event_data->PhyNum; |
Moore, Eric | 4b76647 | 2006-03-14 09:14:12 -0700 | [diff] [blame] | 4203 | memcpy(&sas_address, &sas_event_data->SASAddress, |
Kashyap, Desai | 3eb0822c | 2009-05-29 16:47:26 +0530 | [diff] [blame] | 4204 | sizeof(u64)); |
| 4205 | hot_plug_info.sas_address = le64_to_cpu(sas_address); |
| 4206 | hot_plug_info.device_info = device_info; |
Moore, Eric | 4b76647 | 2006-03-14 09:14:12 -0700 | [diff] [blame] | 4207 | if (sas_event_data->ReasonCode & |
| 4208 | MPI_EVENT_SAS_DEV_STAT_RC_ADDED) |
Kashyap, Desai | 3eb0822c | 2009-05-29 16:47:26 +0530 | [diff] [blame] | 4209 | hot_plug_info.event_type = MPTSAS_ADD_DEVICE; |
Moore, Eric | 4b76647 | 2006-03-14 09:14:12 -0700 | [diff] [blame] | 4210 | else |
Kashyap, Desai | 3eb0822c | 2009-05-29 16:47:26 +0530 | [diff] [blame] | 4211 | hot_plug_info.event_type = MPTSAS_DEL_DEVICE; |
| 4212 | mptsas_hotplug_work(ioc, fw_event, &hot_plug_info); |
Moore, Eric | 4b76647 | 2006-03-14 09:14:12 -0700 | [diff] [blame] | 4213 | break; |
Kashyap, Desai | 3eb0822c | 2009-05-29 16:47:26 +0530 | [diff] [blame] | 4214 | |
Moore, Eric | 4b76647 | 2006-03-14 09:14:12 -0700 | [diff] [blame] | 4215 | case MPI_EVENT_SAS_DEV_STAT_RC_NO_PERSIST_ADDED: |
Kashyap, Desai | 3eb0822c | 2009-05-29 16:47:26 +0530 | [diff] [blame] | 4216 | mptbase_sas_persist_operation(ioc, |
| 4217 | MPI_SAS_OP_CLEAR_NOT_PRESENT); |
| 4218 | mptsas_free_fw_event(ioc, fw_event); |
Moore, Eric | 4b76647 | 2006-03-14 09:14:12 -0700 | [diff] [blame] | 4219 | break; |
Kashyap, Desai | 3eb0822c | 2009-05-29 16:47:26 +0530 | [diff] [blame] | 4220 | |
Moore, Eric | 4b76647 | 2006-03-14 09:14:12 -0700 | [diff] [blame] | 4221 | case MPI_EVENT_SAS_DEV_STAT_RC_SMART_DATA: |
Kashyap, Desai | 3eb0822c | 2009-05-29 16:47:26 +0530 | [diff] [blame] | 4222 | /* TODO */ |
Moore, Eric | 4b76647 | 2006-03-14 09:14:12 -0700 | [diff] [blame] | 4223 | case MPI_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET: |
Kashyap, Desai | 3eb0822c | 2009-05-29 16:47:26 +0530 | [diff] [blame] | 4224 | /* TODO */ |
Moore, Eric | 4b76647 | 2006-03-14 09:14:12 -0700 | [diff] [blame] | 4225 | default: |
Kashyap, Desai | 3eb0822c | 2009-05-29 16:47:26 +0530 | [diff] [blame] | 4226 | mptsas_free_fw_event(ioc, fw_event); |
Moore, Eric | 4b76647 | 2006-03-14 09:14:12 -0700 | [diff] [blame] | 4227 | break; |
Christoph Hellwig | 9a28f49 | 2006-01-13 18:04:41 +0100 | [diff] [blame] | 4228 | } |
Christoph Hellwig | 9a28f49 | 2006-01-13 18:04:41 +0100 | [diff] [blame] | 4229 | } |
Kashyap, Desai | 3eb0822c | 2009-05-29 16:47:26 +0530 | [diff] [blame] | 4230 | |
Moore, Eric | c73787ee | 2006-01-26 16:20:06 -0700 | [diff] [blame] | 4231 | static void |
Kashyap, Desai | 3eb0822c | 2009-05-29 16:47:26 +0530 | [diff] [blame] | 4232 | mptsas_send_raid_event(struct fw_event_work *fw_event) |
Moore, Eric | c73787ee | 2006-01-26 16:20:06 -0700 | [diff] [blame] | 4233 | { |
Kashyap, Desai | 3eb0822c | 2009-05-29 16:47:26 +0530 | [diff] [blame] | 4234 | MPT_ADAPTER *ioc; |
| 4235 | EVENT_DATA_RAID *raid_event_data; |
| 4236 | struct mptsas_hotplug_event hot_plug_info; |
| 4237 | int status; |
| 4238 | int state; |
| 4239 | struct scsi_device *sdev = NULL; |
| 4240 | VirtDevice *vdevice = NULL; |
| 4241 | RaidPhysDiskPage0_t phys_disk; |
Moore, Eric | c73787ee | 2006-01-26 16:20:06 -0700 | [diff] [blame] | 4242 | |
Kashyap, Desai | 3eb0822c | 2009-05-29 16:47:26 +0530 | [diff] [blame] | 4243 | ioc = fw_event->ioc; |
| 4244 | raid_event_data = (EVENT_DATA_RAID *)fw_event->event_data; |
| 4245 | status = le32_to_cpu(raid_event_data->SettingsStatus); |
| 4246 | state = (status >> 8) & 0xff; |
Moore, Eric | c73787ee | 2006-01-26 16:20:06 -0700 | [diff] [blame] | 4247 | |
Kashyap, Desai | 3eb0822c | 2009-05-29 16:47:26 +0530 | [diff] [blame] | 4248 | memset(&hot_plug_info, 0, sizeof(struct mptsas_hotplug_event)); |
| 4249 | hot_plug_info.id = raid_event_data->VolumeID; |
| 4250 | hot_plug_info.channel = raid_event_data->VolumeBus; |
| 4251 | hot_plug_info.phys_disk_num = raid_event_data->PhysDiskNum; |
| 4252 | |
| 4253 | if (raid_event_data->ReasonCode == MPI_EVENT_RAID_RC_VOLUME_DELETED || |
| 4254 | raid_event_data->ReasonCode == MPI_EVENT_RAID_RC_VOLUME_CREATED || |
| 4255 | raid_event_data->ReasonCode == |
| 4256 | MPI_EVENT_RAID_RC_VOLUME_STATUS_CHANGED) { |
| 4257 | sdev = scsi_device_lookup(ioc->sh, MPTSAS_RAID_CHANNEL, |
| 4258 | hot_plug_info.id, 0); |
| 4259 | hot_plug_info.sdev = sdev; |
| 4260 | if (sdev) |
| 4261 | vdevice = sdev->hostdata; |
Moore, Eric | c73787ee | 2006-01-26 16:20:06 -0700 | [diff] [blame] | 4262 | } |
| 4263 | |
Kashyap, Desai | 3eb0822c | 2009-05-29 16:47:26 +0530 | [diff] [blame] | 4264 | devtprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Entering %s: " |
| 4265 | "ReasonCode=%02x\n", ioc->name, __func__, |
| 4266 | raid_event_data->ReasonCode)); |
Moore, Eric | c73787ee | 2006-01-26 16:20:06 -0700 | [diff] [blame] | 4267 | |
| 4268 | switch (raid_event_data->ReasonCode) { |
| 4269 | case MPI_EVENT_RAID_RC_PHYSDISK_DELETED: |
Kashyap, Desai | 3eb0822c | 2009-05-29 16:47:26 +0530 | [diff] [blame] | 4270 | hot_plug_info.event_type = MPTSAS_DEL_PHYSDISK_REPROBE; |
Moore, Eric | c73787ee | 2006-01-26 16:20:06 -0700 | [diff] [blame] | 4271 | break; |
| 4272 | case MPI_EVENT_RAID_RC_PHYSDISK_CREATED: |
Kashyap, Desai | 3eb0822c | 2009-05-29 16:47:26 +0530 | [diff] [blame] | 4273 | hot_plug_info.event_type = MPTSAS_ADD_PHYSDISK_REPROBE; |
Moore, Eric | c73787ee | 2006-01-26 16:20:06 -0700 | [diff] [blame] | 4274 | break; |
Moore, Eric | bd23e94 | 2006-04-17 12:43:04 -0600 | [diff] [blame] | 4275 | case MPI_EVENT_RAID_RC_PHYSDISK_STATUS_CHANGED: |
| 4276 | switch (state) { |
| 4277 | case MPI_PD_STATE_ONLINE: |
Eric Moore | b506ade | 2007-01-29 09:45:37 -0700 | [diff] [blame] | 4278 | case MPI_PD_STATE_NOT_COMPATIBLE: |
Kashyap, Desai | 3eb0822c | 2009-05-29 16:47:26 +0530 | [diff] [blame] | 4279 | mpt_raid_phys_disk_pg0(ioc, |
| 4280 | raid_event_data->PhysDiskNum, &phys_disk); |
| 4281 | hot_plug_info.id = phys_disk.PhysDiskID; |
| 4282 | hot_plug_info.channel = phys_disk.PhysDiskBus; |
| 4283 | hot_plug_info.event_type = MPTSAS_ADD_PHYSDISK; |
Moore, Eric | bd23e94 | 2006-04-17 12:43:04 -0600 | [diff] [blame] | 4284 | break; |
Kashyap, Desai | 3eb0822c | 2009-05-29 16:47:26 +0530 | [diff] [blame] | 4285 | case MPI_PD_STATE_FAILED: |
Moore, Eric | bd23e94 | 2006-04-17 12:43:04 -0600 | [diff] [blame] | 4286 | case MPI_PD_STATE_MISSING: |
Moore, Eric | bd23e94 | 2006-04-17 12:43:04 -0600 | [diff] [blame] | 4287 | case MPI_PD_STATE_OFFLINE_AT_HOST_REQUEST: |
| 4288 | case MPI_PD_STATE_FAILED_AT_HOST_REQUEST: |
| 4289 | case MPI_PD_STATE_OFFLINE_FOR_ANOTHER_REASON: |
Kashyap, Desai | 3eb0822c | 2009-05-29 16:47:26 +0530 | [diff] [blame] | 4290 | hot_plug_info.event_type = MPTSAS_DEL_PHYSDISK; |
Moore, Eric | bd23e94 | 2006-04-17 12:43:04 -0600 | [diff] [blame] | 4291 | break; |
| 4292 | default: |
| 4293 | break; |
| 4294 | } |
| 4295 | break; |
Moore, Eric | c73787ee | 2006-01-26 16:20:06 -0700 | [diff] [blame] | 4296 | case MPI_EVENT_RAID_RC_VOLUME_DELETED: |
Kashyap, Desai | 3eb0822c | 2009-05-29 16:47:26 +0530 | [diff] [blame] | 4297 | if (!sdev) |
| 4298 | break; |
| 4299 | vdevice->vtarget->deleted = 1; /* block IO */ |
| 4300 | hot_plug_info.event_type = MPTSAS_DEL_RAID; |
Moore, Eric | c73787ee | 2006-01-26 16:20:06 -0700 | [diff] [blame] | 4301 | break; |
| 4302 | case MPI_EVENT_RAID_RC_VOLUME_CREATED: |
Kashyap, Desai | 3eb0822c | 2009-05-29 16:47:26 +0530 | [diff] [blame] | 4303 | if (sdev) { |
| 4304 | scsi_device_put(sdev); |
| 4305 | break; |
| 4306 | } |
| 4307 | hot_plug_info.event_type = MPTSAS_ADD_RAID; |
Moore, Eric | c73787ee | 2006-01-26 16:20:06 -0700 | [diff] [blame] | 4308 | break; |
| 4309 | case MPI_EVENT_RAID_RC_VOLUME_STATUS_CHANGED: |
Kashyap, Desai | 3eb0822c | 2009-05-29 16:47:26 +0530 | [diff] [blame] | 4310 | if (!(status & MPI_RAIDVOL0_STATUS_FLAG_ENABLED)) { |
| 4311 | if (!sdev) |
| 4312 | break; |
| 4313 | vdevice->vtarget->deleted = 1; /* block IO */ |
| 4314 | hot_plug_info.event_type = MPTSAS_DEL_RAID; |
| 4315 | break; |
| 4316 | } |
Moore, Eric | bd23e94 | 2006-04-17 12:43:04 -0600 | [diff] [blame] | 4317 | switch (state) { |
| 4318 | case MPI_RAIDVOL0_STATUS_STATE_FAILED: |
| 4319 | case MPI_RAIDVOL0_STATUS_STATE_MISSING: |
Kashyap, Desai | 3eb0822c | 2009-05-29 16:47:26 +0530 | [diff] [blame] | 4320 | if (!sdev) |
| 4321 | break; |
| 4322 | vdevice->vtarget->deleted = 1; /* block IO */ |
| 4323 | hot_plug_info.event_type = MPTSAS_DEL_RAID; |
Moore, Eric | bd23e94 | 2006-04-17 12:43:04 -0600 | [diff] [blame] | 4324 | break; |
| 4325 | case MPI_RAIDVOL0_STATUS_STATE_OPTIMAL: |
| 4326 | case MPI_RAIDVOL0_STATUS_STATE_DEGRADED: |
Kashyap, Desai | 3eb0822c | 2009-05-29 16:47:26 +0530 | [diff] [blame] | 4327 | if (sdev) { |
| 4328 | scsi_device_put(sdev); |
| 4329 | break; |
| 4330 | } |
| 4331 | hot_plug_info.event_type = MPTSAS_ADD_RAID; |
Moore, Eric | bd23e94 | 2006-04-17 12:43:04 -0600 | [diff] [blame] | 4332 | break; |
| 4333 | default: |
| 4334 | break; |
| 4335 | } |
Moore, Eric | c73787ee | 2006-01-26 16:20:06 -0700 | [diff] [blame] | 4336 | break; |
| 4337 | default: |
| 4338 | break; |
| 4339 | } |
Kashyap, Desai | 3eb0822c | 2009-05-29 16:47:26 +0530 | [diff] [blame] | 4340 | |
| 4341 | if (hot_plug_info.event_type != MPTSAS_IGNORE_EVENT) |
| 4342 | mptsas_hotplug_work(ioc, fw_event, &hot_plug_info); |
| 4343 | else |
| 4344 | mptsas_free_fw_event(ioc, fw_event); |
Moore, Eric | c73787ee | 2006-01-26 16:20:06 -0700 | [diff] [blame] | 4345 | } |
| 4346 | |
Kashyap, Desai | db7051b | 2009-05-29 16:56:59 +0530 | [diff] [blame^] | 4347 | /** |
| 4348 | * mptsas_issue_tm - send mptsas internal tm request |
| 4349 | * @ioc: Pointer to MPT_ADAPTER structure |
| 4350 | * @type: Task Management type |
| 4351 | * @channel: channel number for task management |
| 4352 | * @id: Logical Target ID for reset (if appropriate) |
| 4353 | * @lun: Logical unit for reset (if appropriate) |
| 4354 | * @task_context: Context for the task to be aborted |
| 4355 | * @timeout: timeout for task management control |
| 4356 | * |
| 4357 | * return 0 on success and -1 on failure: |
| 4358 | * |
| 4359 | */ |
| 4360 | static int |
| 4361 | mptsas_issue_tm(MPT_ADAPTER *ioc, u8 type, u8 channel, u8 id, u64 lun, |
| 4362 | int task_context, ulong timeout, u8 *issue_reset) |
| 4363 | { |
| 4364 | MPT_FRAME_HDR *mf; |
| 4365 | SCSITaskMgmt_t *pScsiTm; |
| 4366 | int retval; |
| 4367 | unsigned long timeleft; |
| 4368 | |
| 4369 | *issue_reset = 0; |
| 4370 | mf = mpt_get_msg_frame(mptsasDeviceResetCtx, ioc); |
| 4371 | if (mf == NULL) { |
| 4372 | retval = -1; /* return failure */ |
| 4373 | dtmprintk(ioc, printk(MYIOC_s_WARN_FMT "TaskMgmt request: no " |
| 4374 | "msg frames!!\n", ioc->name)); |
| 4375 | goto out; |
| 4376 | } |
| 4377 | |
| 4378 | dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT "TaskMgmt request: mr = %p, " |
| 4379 | "task_type = 0x%02X,\n\t timeout = %ld, fw_channel = %d, " |
| 4380 | "fw_id = %d, lun = %lld,\n\t task_context = 0x%x\n", ioc->name, mf, |
| 4381 | type, timeout, channel, id, (unsigned long long)lun, |
| 4382 | task_context)); |
| 4383 | |
| 4384 | pScsiTm = (SCSITaskMgmt_t *) mf; |
| 4385 | memset(pScsiTm, 0, sizeof(SCSITaskMgmt_t)); |
| 4386 | pScsiTm->Function = MPI_FUNCTION_SCSI_TASK_MGMT; |
| 4387 | pScsiTm->TaskType = type; |
| 4388 | pScsiTm->MsgFlags = 0; |
| 4389 | pScsiTm->TargetID = id; |
| 4390 | pScsiTm->Bus = channel; |
| 4391 | pScsiTm->ChainOffset = 0; |
| 4392 | pScsiTm->Reserved = 0; |
| 4393 | pScsiTm->Reserved1 = 0; |
| 4394 | pScsiTm->TaskMsgContext = task_context; |
| 4395 | int_to_scsilun(lun, (struct scsi_lun *)pScsiTm->LUN); |
| 4396 | |
| 4397 | INITIALIZE_MGMT_STATUS(ioc->taskmgmt_cmds.status) |
| 4398 | CLEAR_MGMT_STATUS(ioc->internal_cmds.status) |
| 4399 | retval = 0; |
| 4400 | mpt_put_msg_frame_hi_pri(mptsasDeviceResetCtx, ioc, mf); |
| 4401 | |
| 4402 | /* Now wait for the command to complete */ |
| 4403 | timeleft = wait_for_completion_timeout(&ioc->taskmgmt_cmds.done, |
| 4404 | timeout*HZ); |
| 4405 | if (!(ioc->taskmgmt_cmds.status & MPT_MGMT_STATUS_COMMAND_GOOD)) { |
| 4406 | retval = -1; /* return failure */ |
| 4407 | dtmprintk(ioc, printk(MYIOC_s_ERR_FMT |
| 4408 | "TaskMgmt request: TIMED OUT!(mr=%p)\n", ioc->name, mf)); |
| 4409 | mpt_free_msg_frame(ioc, mf); |
| 4410 | if (ioc->taskmgmt_cmds.status & MPT_MGMT_STATUS_DID_IOCRESET) |
| 4411 | goto out; |
| 4412 | *issue_reset = 1; |
| 4413 | goto out; |
| 4414 | } |
| 4415 | |
| 4416 | if (!(ioc->taskmgmt_cmds.status & MPT_MGMT_STATUS_RF_VALID)) { |
| 4417 | retval = -1; /* return failure */ |
| 4418 | dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT |
| 4419 | "TaskMgmt request: failed with no reply\n", ioc->name)); |
| 4420 | goto out; |
| 4421 | } |
| 4422 | |
| 4423 | out: |
| 4424 | CLEAR_MGMT_STATUS(ioc->taskmgmt_cmds.status) |
| 4425 | return retval; |
| 4426 | } |
| 4427 | |
| 4428 | /** |
| 4429 | * mptsas_broadcast_primative_work - Handle broadcast primitives |
| 4430 | * @work: work queue payload containing info describing the event |
| 4431 | * |
| 4432 | * this will be handled in workqueue context. |
| 4433 | */ |
| 4434 | static void |
| 4435 | mptsas_broadcast_primative_work(struct fw_event_work *fw_event) |
| 4436 | { |
| 4437 | MPT_ADAPTER *ioc = fw_event->ioc; |
| 4438 | MPT_FRAME_HDR *mf; |
| 4439 | VirtDevice *vdevice; |
| 4440 | int ii; |
| 4441 | struct scsi_cmnd *sc; |
| 4442 | SCSITaskMgmtReply_t *pScsiTmReply; |
| 4443 | u8 issue_reset; |
| 4444 | int task_context; |
| 4445 | u8 channel, id; |
| 4446 | int lun; |
| 4447 | u32 termination_count; |
| 4448 | u32 query_count; |
| 4449 | |
| 4450 | dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT |
| 4451 | "%s - enter\n", ioc->name, __func__)); |
| 4452 | |
| 4453 | mutex_lock(&ioc->taskmgmt_cmds.mutex); |
| 4454 | if (mpt_set_taskmgmt_in_progress_flag(ioc) != 0) { |
| 4455 | mutex_unlock(&ioc->taskmgmt_cmds.mutex); |
| 4456 | mptsas_requeue_fw_event(ioc, fw_event, 1000); |
| 4457 | return; |
| 4458 | } |
| 4459 | |
| 4460 | issue_reset = 0; |
| 4461 | termination_count = 0; |
| 4462 | query_count = 0; |
| 4463 | mpt_findImVolumes(ioc); |
| 4464 | pScsiTmReply = (SCSITaskMgmtReply_t *) ioc->taskmgmt_cmds.reply; |
| 4465 | |
| 4466 | for (ii = 0; ii < ioc->req_depth; ii++) { |
| 4467 | if (ioc->fw_events_off) |
| 4468 | goto out; |
| 4469 | sc = mptscsih_get_scsi_lookup(ioc, ii); |
| 4470 | if (!sc) |
| 4471 | continue; |
| 4472 | mf = MPT_INDEX_2_MFPTR(ioc, ii); |
| 4473 | if (!mf) |
| 4474 | continue; |
| 4475 | task_context = mf->u.frame.hwhdr.msgctxu.MsgContext; |
| 4476 | vdevice = sc->device->hostdata; |
| 4477 | if (!vdevice || !vdevice->vtarget) |
| 4478 | continue; |
| 4479 | if (vdevice->vtarget->tflags & MPT_TARGET_FLAGS_RAID_COMPONENT) |
| 4480 | continue; /* skip hidden raid components */ |
| 4481 | if (vdevice->vtarget->raidVolume) |
| 4482 | continue; /* skip hidden raid components */ |
| 4483 | channel = vdevice->vtarget->channel; |
| 4484 | id = vdevice->vtarget->id; |
| 4485 | lun = vdevice->lun; |
| 4486 | if (mptsas_issue_tm(ioc, MPI_SCSITASKMGMT_TASKTYPE_QUERY_TASK, |
| 4487 | channel, id, (u64)lun, task_context, 30, &issue_reset)) |
| 4488 | goto out; |
| 4489 | query_count++; |
| 4490 | termination_count += |
| 4491 | le32_to_cpu(pScsiTmReply->TerminationCount); |
| 4492 | if ((pScsiTmReply->IOCStatus == MPI_IOCSTATUS_SUCCESS) && |
| 4493 | (pScsiTmReply->ResponseCode == |
| 4494 | MPI_SCSITASKMGMT_RSP_TM_SUCCEEDED || |
| 4495 | pScsiTmReply->ResponseCode == |
| 4496 | MPI_SCSITASKMGMT_RSP_IO_QUEUED_ON_IOC)) |
| 4497 | continue; |
| 4498 | if (mptsas_issue_tm(ioc, |
| 4499 | MPI_SCSITASKMGMT_TASKTYPE_ABRT_TASK_SET, |
| 4500 | channel, id, (u64)lun, 0, 30, &issue_reset)) |
| 4501 | goto out; |
| 4502 | termination_count += |
| 4503 | le32_to_cpu(pScsiTmReply->TerminationCount); |
| 4504 | } |
| 4505 | |
| 4506 | out: |
| 4507 | dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT |
| 4508 | "%s - exit, query_count = %d termination_count = %d\n", |
| 4509 | ioc->name, __func__, query_count, termination_count)); |
| 4510 | |
| 4511 | ioc->broadcast_aen_busy = 0; |
| 4512 | mpt_clear_taskmgmt_in_progress_flag(ioc); |
| 4513 | mutex_unlock(&ioc->taskmgmt_cmds.mutex); |
| 4514 | |
| 4515 | if (issue_reset) { |
| 4516 | printk(MYIOC_s_WARN_FMT "Issuing Reset from %s!!\n", |
| 4517 | ioc->name, __func__); |
| 4518 | mpt_HardResetHandler(ioc, CAN_SLEEP); |
| 4519 | } |
| 4520 | mptsas_free_fw_event(ioc, fw_event); |
| 4521 | } |
| 4522 | |
Eric Moore | b506ade | 2007-01-29 09:45:37 -0700 | [diff] [blame] | 4523 | /* |
| 4524 | * mptsas_send_ir2_event - handle exposing hidden disk when |
| 4525 | * an inactive raid volume is added |
| 4526 | * |
| 4527 | * @ioc: Pointer to MPT_ADAPTER structure |
| 4528 | * @ir2_data |
| 4529 | * |
| 4530 | */ |
| 4531 | static void |
Kashyap, Desai | 3eb0822c | 2009-05-29 16:47:26 +0530 | [diff] [blame] | 4532 | mptsas_send_ir2_event(struct fw_event_work *fw_event) |
Eric Moore | b506ade | 2007-01-29 09:45:37 -0700 | [diff] [blame] | 4533 | { |
Kashyap, Desai | 3eb0822c | 2009-05-29 16:47:26 +0530 | [diff] [blame] | 4534 | MPT_ADAPTER *ioc; |
| 4535 | struct mptsas_hotplug_event hot_plug_info; |
| 4536 | MPI_EVENT_DATA_IR2 *ir2_data; |
| 4537 | u8 reasonCode; |
Kashyap, Desai | a7938b0 | 2009-05-29 16:53:56 +0530 | [diff] [blame] | 4538 | RaidPhysDiskPage0_t phys_disk; |
Eric Moore | b506ade | 2007-01-29 09:45:37 -0700 | [diff] [blame] | 4539 | |
Kashyap, Desai | 3eb0822c | 2009-05-29 16:47:26 +0530 | [diff] [blame] | 4540 | ioc = fw_event->ioc; |
| 4541 | ir2_data = (MPI_EVENT_DATA_IR2 *)fw_event->event_data; |
| 4542 | reasonCode = ir2_data->ReasonCode; |
| 4543 | |
| 4544 | devtprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Entering %s: " |
| 4545 | "ReasonCode=%02x\n", ioc->name, __func__, reasonCode)); |
| 4546 | |
| 4547 | memset(&hot_plug_info, 0, sizeof(struct mptsas_hotplug_event)); |
| 4548 | hot_plug_info.id = ir2_data->TargetID; |
| 4549 | hot_plug_info.channel = ir2_data->Bus; |
| 4550 | switch (reasonCode) { |
| 4551 | case MPI_EVENT_IR2_RC_FOREIGN_CFG_DETECTED: |
| 4552 | hot_plug_info.event_type = MPTSAS_ADD_INACTIVE_VOLUME; |
| 4553 | break; |
Kashyap, Desai | a7938b0 | 2009-05-29 16:53:56 +0530 | [diff] [blame] | 4554 | case MPI_EVENT_IR2_RC_DUAL_PORT_REMOVED: |
| 4555 | hot_plug_info.phys_disk_num = ir2_data->PhysDiskNum; |
| 4556 | hot_plug_info.event_type = MPTSAS_DEL_PHYSDISK; |
| 4557 | break; |
| 4558 | case MPI_EVENT_IR2_RC_DUAL_PORT_ADDED: |
| 4559 | hot_plug_info.phys_disk_num = ir2_data->PhysDiskNum; |
| 4560 | mpt_raid_phys_disk_pg0(ioc, |
| 4561 | ir2_data->PhysDiskNum, &phys_disk); |
| 4562 | hot_plug_info.id = phys_disk.PhysDiskID; |
| 4563 | hot_plug_info.event_type = MPTSAS_ADD_PHYSDISK; |
| 4564 | break; |
Kashyap, Desai | 3eb0822c | 2009-05-29 16:47:26 +0530 | [diff] [blame] | 4565 | default: |
| 4566 | mptsas_free_fw_event(ioc, fw_event); |
Eric Moore | b506ade | 2007-01-29 09:45:37 -0700 | [diff] [blame] | 4567 | return; |
Kashyap, Desai | 3eb0822c | 2009-05-29 16:47:26 +0530 | [diff] [blame] | 4568 | } |
| 4569 | mptsas_hotplug_work(ioc, fw_event, &hot_plug_info); |
| 4570 | } |
Moore, Eric | e6b2d76 | 2006-03-14 09:14:24 -0700 | [diff] [blame] | 4571 | |
Christoph Hellwig | 9a28f49 | 2006-01-13 18:04:41 +0100 | [diff] [blame] | 4572 | static int |
| 4573 | mptsas_event_process(MPT_ADAPTER *ioc, EventNotificationReply_t *reply) |
| 4574 | { |
Kashyap, Desai | 3eb0822c | 2009-05-29 16:47:26 +0530 | [diff] [blame] | 4575 | u32 event = le32_to_cpu(reply->Event); |
| 4576 | int sz, event_data_sz; |
| 4577 | struct fw_event_work *fw_event; |
| 4578 | unsigned long delay; |
Christoph Hellwig | 9a28f49 | 2006-01-13 18:04:41 +0100 | [diff] [blame] | 4579 | |
Kashyap, Desai | 3eb0822c | 2009-05-29 16:47:26 +0530 | [diff] [blame] | 4580 | /* events turned off due to host reset or driver unloading */ |
| 4581 | if (ioc->fw_events_off) |
| 4582 | return 0; |
Christoph Hellwig | 9a28f49 | 2006-01-13 18:04:41 +0100 | [diff] [blame] | 4583 | |
Kashyap, Desai | 3eb0822c | 2009-05-29 16:47:26 +0530 | [diff] [blame] | 4584 | delay = msecs_to_jiffies(1); |
Christoph Hellwig | 9a28f49 | 2006-01-13 18:04:41 +0100 | [diff] [blame] | 4585 | switch (event) { |
Kashyap, Desai | db7051b | 2009-05-29 16:56:59 +0530 | [diff] [blame^] | 4586 | case MPI_EVENT_SAS_BROADCAST_PRIMITIVE: |
| 4587 | { |
| 4588 | EVENT_DATA_SAS_BROADCAST_PRIMITIVE *broadcast_event_data = |
| 4589 | (EVENT_DATA_SAS_BROADCAST_PRIMITIVE *)reply->Data; |
| 4590 | if (broadcast_event_data->Primitive != |
| 4591 | MPI_EVENT_PRIMITIVE_ASYNCHRONOUS_EVENT) |
| 4592 | return 0; |
| 4593 | if (ioc->broadcast_aen_busy) |
| 4594 | return 0; |
| 4595 | ioc->broadcast_aen_busy = 1; |
| 4596 | break; |
| 4597 | } |
Christoph Hellwig | 9a28f49 | 2006-01-13 18:04:41 +0100 | [diff] [blame] | 4598 | case MPI_EVENT_SAS_DEVICE_STATUS_CHANGE: |
Kashyap, Desai | 3eb0822c | 2009-05-29 16:47:26 +0530 | [diff] [blame] | 4599 | { |
| 4600 | EVENT_DATA_SAS_DEVICE_STATUS_CHANGE *sas_event_data = |
| 4601 | (EVENT_DATA_SAS_DEVICE_STATUS_CHANGE *)reply->Data; |
| 4602 | |
| 4603 | if (sas_event_data->ReasonCode == |
| 4604 | MPI_EVENT_SAS_DEV_STAT_RC_NOT_RESPONDING) { |
| 4605 | mptsas_target_reset_queue(ioc, sas_event_data); |
| 4606 | return 0; |
| 4607 | } |
Moore, Eric | c73787ee | 2006-01-26 16:20:06 -0700 | [diff] [blame] | 4608 | break; |
Kashyap, Desai | 3eb0822c | 2009-05-29 16:47:26 +0530 | [diff] [blame] | 4609 | } |
Kashyap, Desai | f9c3402 | 2009-05-29 16:49:36 +0530 | [diff] [blame] | 4610 | case MPI_EVENT_SAS_EXPANDER_STATUS_CHANGE: |
| 4611 | { |
| 4612 | MpiEventDataSasExpanderStatusChange_t *expander_data = |
| 4613 | (MpiEventDataSasExpanderStatusChange_t *)reply->Data; |
| 4614 | |
Kashyap, Desai | eedf92b | 2009-05-29 16:51:32 +0530 | [diff] [blame] | 4615 | if (ioc->old_sas_discovery_protocal) |
| 4616 | return 0; |
Kashyap, Desai | f9c3402 | 2009-05-29 16:49:36 +0530 | [diff] [blame] | 4617 | |
| 4618 | if (expander_data->ReasonCode == |
| 4619 | MPI_EVENT_SAS_EXP_RC_NOT_RESPONDING && |
| 4620 | ioc->device_missing_delay) |
| 4621 | delay = HZ * ioc->device_missing_delay; |
Moore, Eric | e6b2d76 | 2006-03-14 09:14:24 -0700 | [diff] [blame] | 4622 | break; |
Kashyap, Desai | f9c3402 | 2009-05-29 16:49:36 +0530 | [diff] [blame] | 4623 | } |
| 4624 | case MPI_EVENT_SAS_DISCOVERY: |
| 4625 | { |
| 4626 | u32 discovery_status; |
| 4627 | EventDataSasDiscovery_t *discovery_data = |
| 4628 | (EventDataSasDiscovery_t *)reply->Data; |
| 4629 | |
| 4630 | discovery_status = le32_to_cpu(discovery_data->DiscoveryStatus); |
| 4631 | ioc->sas_discovery_quiesce_io = discovery_status ? 1 : 0; |
Kashyap, Desai | eedf92b | 2009-05-29 16:51:32 +0530 | [diff] [blame] | 4632 | if (ioc->old_sas_discovery_protocal && !discovery_status) |
| 4633 | mptsas_queue_rescan(ioc); |
Kashyap, Desai | f9c3402 | 2009-05-29 16:49:36 +0530 | [diff] [blame] | 4634 | return 0; |
| 4635 | } |
Kashyap, Desai | 3eb0822c | 2009-05-29 16:47:26 +0530 | [diff] [blame] | 4636 | case MPI_EVENT_INTEGRATED_RAID: |
| 4637 | case MPI_EVENT_PERSISTENT_TABLE_FULL: |
Eric Moore | b506ade | 2007-01-29 09:45:37 -0700 | [diff] [blame] | 4638 | case MPI_EVENT_IR2: |
Kashyap, Desai | 3eb0822c | 2009-05-29 16:47:26 +0530 | [diff] [blame] | 4639 | case MPI_EVENT_SAS_PHY_LINK_STATUS: |
| 4640 | case MPI_EVENT_QUEUE_FULL: |
Eric Moore | b506ade | 2007-01-29 09:45:37 -0700 | [diff] [blame] | 4641 | break; |
Christoph Hellwig | 9a28f49 | 2006-01-13 18:04:41 +0100 | [diff] [blame] | 4642 | default: |
Kashyap, Desai | 3eb0822c | 2009-05-29 16:47:26 +0530 | [diff] [blame] | 4643 | return 0; |
Christoph Hellwig | 9a28f49 | 2006-01-13 18:04:41 +0100 | [diff] [blame] | 4644 | } |
Moore, Eric | c73787ee | 2006-01-26 16:20:06 -0700 | [diff] [blame] | 4645 | |
Kashyap, Desai | 3eb0822c | 2009-05-29 16:47:26 +0530 | [diff] [blame] | 4646 | event_data_sz = ((reply->MsgLength * 4) - |
| 4647 | offsetof(EventNotificationReply_t, Data)); |
| 4648 | sz = offsetof(struct fw_event_work, event_data) + event_data_sz; |
| 4649 | fw_event = kzalloc(sz, GFP_ATOMIC); |
| 4650 | if (!fw_event) { |
| 4651 | printk(MYIOC_s_WARN_FMT "%s: failed at (line=%d)\n", ioc->name, |
| 4652 | __func__, __LINE__); |
| 4653 | return 0; |
| 4654 | } |
| 4655 | memcpy(fw_event->event_data, reply->Data, event_data_sz); |
| 4656 | fw_event->event = event; |
| 4657 | fw_event->ioc = ioc; |
| 4658 | mptsas_add_fw_event(ioc, fw_event, delay); |
| 4659 | return 0; |
Christoph Hellwig | 9a28f49 | 2006-01-13 18:04:41 +0100 | [diff] [blame] | 4660 | } |
| 4661 | |
Kashyap, Desai | a7938b0 | 2009-05-29 16:53:56 +0530 | [diff] [blame] | 4662 | /* Delete a volume when no longer listed in ioc pg2 |
| 4663 | */ |
| 4664 | static void mptsas_volume_delete(MPT_ADAPTER *ioc, u8 id) |
| 4665 | { |
| 4666 | struct scsi_device *sdev; |
| 4667 | int i; |
| 4668 | |
| 4669 | sdev = scsi_device_lookup(ioc->sh, MPTSAS_RAID_CHANNEL, id, 0); |
| 4670 | if (!sdev) |
| 4671 | return; |
| 4672 | if (!ioc->raid_data.pIocPg2) |
| 4673 | goto out; |
| 4674 | if (!ioc->raid_data.pIocPg2->NumActiveVolumes) |
| 4675 | goto out; |
| 4676 | for (i = 0; i < ioc->raid_data.pIocPg2->NumActiveVolumes; i++) |
| 4677 | if (ioc->raid_data.pIocPg2->RaidVolume[i].VolumeID == id) |
| 4678 | goto release_sdev; |
| 4679 | out: |
| 4680 | printk(MYIOC_s_INFO_FMT "removing raid volume, channel %d, " |
| 4681 | "id %d\n", ioc->name, MPTSAS_RAID_CHANNEL, id); |
| 4682 | scsi_remove_device(sdev); |
| 4683 | release_sdev: |
| 4684 | scsi_device_put(sdev); |
| 4685 | } |
| 4686 | |
Christoph Hellwig | 0c33b27 | 2005-09-09 16:27:19 +0200 | [diff] [blame] | 4687 | static int |
| 4688 | mptsas_probe(struct pci_dev *pdev, const struct pci_device_id *id) |
| 4689 | { |
| 4690 | struct Scsi_Host *sh; |
| 4691 | MPT_SCSI_HOST *hd; |
| 4692 | MPT_ADAPTER *ioc; |
| 4693 | unsigned long flags; |
Christoph Hellwig | 1ca00bb | 2006-01-13 18:27:50 +0100 | [diff] [blame] | 4694 | int ii; |
Christoph Hellwig | 0c33b27 | 2005-09-09 16:27:19 +0200 | [diff] [blame] | 4695 | int numSGE = 0; |
| 4696 | int scale; |
| 4697 | int ioc_cap; |
Christoph Hellwig | 0c33b27 | 2005-09-09 16:27:19 +0200 | [diff] [blame] | 4698 | int error=0; |
| 4699 | int r; |
| 4700 | |
| 4701 | r = mpt_attach(pdev,id); |
| 4702 | if (r) |
| 4703 | return r; |
| 4704 | |
| 4705 | ioc = pci_get_drvdata(pdev); |
Kashyap, Desai | 3eb0822c | 2009-05-29 16:47:26 +0530 | [diff] [blame] | 4706 | mptsas_fw_event_off(ioc); |
Christoph Hellwig | 0c33b27 | 2005-09-09 16:27:19 +0200 | [diff] [blame] | 4707 | ioc->DoneCtx = mptsasDoneCtx; |
| 4708 | ioc->TaskCtx = mptsasTaskCtx; |
| 4709 | ioc->InternalCtx = mptsasInternalCtx; |
| 4710 | |
| 4711 | /* Added sanity check on readiness of the MPT adapter. |
| 4712 | */ |
| 4713 | if (ioc->last_state != MPI_IOC_STATE_OPERATIONAL) { |
| 4714 | printk(MYIOC_s_WARN_FMT |
| 4715 | "Skipping because it's not operational!\n", |
| 4716 | ioc->name); |
Moore, Eric Dean | 7acec1e | 2005-11-16 18:54:17 -0700 | [diff] [blame] | 4717 | error = -ENODEV; |
| 4718 | goto out_mptsas_probe; |
Christoph Hellwig | 0c33b27 | 2005-09-09 16:27:19 +0200 | [diff] [blame] | 4719 | } |
| 4720 | |
| 4721 | if (!ioc->active) { |
| 4722 | printk(MYIOC_s_WARN_FMT "Skipping because it's disabled!\n", |
| 4723 | ioc->name); |
Moore, Eric Dean | 7acec1e | 2005-11-16 18:54:17 -0700 | [diff] [blame] | 4724 | error = -ENODEV; |
| 4725 | goto out_mptsas_probe; |
Christoph Hellwig | 0c33b27 | 2005-09-09 16:27:19 +0200 | [diff] [blame] | 4726 | } |
| 4727 | |
| 4728 | /* Sanity check - ensure at least 1 port is INITIATOR capable |
| 4729 | */ |
| 4730 | ioc_cap = 0; |
| 4731 | for (ii = 0; ii < ioc->facts.NumberOfPorts; ii++) { |
| 4732 | if (ioc->pfacts[ii].ProtocolFlags & |
| 4733 | MPI_PORTFACTS_PROTOCOL_INITIATOR) |
| 4734 | ioc_cap++; |
| 4735 | } |
| 4736 | |
| 4737 | if (!ioc_cap) { |
| 4738 | printk(MYIOC_s_WARN_FMT |
| 4739 | "Skipping ioc=%p because SCSI Initiator mode " |
| 4740 | "is NOT enabled!\n", ioc->name, ioc); |
Moore, Eric Dean | 466544d | 2005-09-14 18:09:10 -0600 | [diff] [blame] | 4741 | return 0; |
Christoph Hellwig | 0c33b27 | 2005-09-09 16:27:19 +0200 | [diff] [blame] | 4742 | } |
| 4743 | |
| 4744 | sh = scsi_host_alloc(&mptsas_driver_template, sizeof(MPT_SCSI_HOST)); |
| 4745 | if (!sh) { |
| 4746 | printk(MYIOC_s_WARN_FMT |
| 4747 | "Unable to register controller with SCSI subsystem\n", |
| 4748 | ioc->name); |
Moore, Eric Dean | 7acec1e | 2005-11-16 18:54:17 -0700 | [diff] [blame] | 4749 | error = -1; |
| 4750 | goto out_mptsas_probe; |
Christoph Hellwig | 0c33b27 | 2005-09-09 16:27:19 +0200 | [diff] [blame] | 4751 | } |
| 4752 | |
| 4753 | spin_lock_irqsave(&ioc->FreeQlock, flags); |
| 4754 | |
| 4755 | /* Attach the SCSI Host to the IOC structure |
| 4756 | */ |
| 4757 | ioc->sh = sh; |
| 4758 | |
| 4759 | sh->io_port = 0; |
| 4760 | sh->n_io_port = 0; |
| 4761 | sh->irq = 0; |
| 4762 | |
| 4763 | /* set 16 byte cdb's */ |
| 4764 | sh->max_cmd_len = 16; |
| 4765 | |
Eric Moore | 793955f | 2007-01-29 09:42:20 -0700 | [diff] [blame] | 4766 | sh->max_id = ioc->pfacts[0].PortSCSIID; |
| 4767 | sh->max_lun = max_lun; |
Christoph Hellwig | 0c33b27 | 2005-09-09 16:27:19 +0200 | [diff] [blame] | 4768 | |
| 4769 | sh->transportt = mptsas_transport_template; |
| 4770 | |
Christoph Hellwig | 0c33b27 | 2005-09-09 16:27:19 +0200 | [diff] [blame] | 4771 | /* Required entry. |
| 4772 | */ |
| 4773 | sh->unique_id = ioc->id; |
| 4774 | |
| 4775 | INIT_LIST_HEAD(&ioc->sas_topology); |
Christoph Hellwig | 9a28f49 | 2006-01-13 18:04:41 +0100 | [diff] [blame] | 4776 | mutex_init(&ioc->sas_topology_mutex); |
Moore, Eric | e6b2d76 | 2006-03-14 09:14:24 -0700 | [diff] [blame] | 4777 | mutex_init(&ioc->sas_discovery_mutex); |
Christoph Hellwig | eeb846c | 2006-01-13 18:27:11 +0100 | [diff] [blame] | 4778 | mutex_init(&ioc->sas_mgmt.mutex); |
Christoph Hellwig | da4fa65 | 2005-10-19 20:01:42 +0200 | [diff] [blame] | 4779 | init_completion(&ioc->sas_mgmt.done); |
Christoph Hellwig | 0c33b27 | 2005-09-09 16:27:19 +0200 | [diff] [blame] | 4780 | |
| 4781 | /* Verify that we won't exceed the maximum |
| 4782 | * number of chain buffers |
| 4783 | * We can optimize: ZZ = req_sz/sizeof(SGE) |
| 4784 | * For 32bit SGE's: |
| 4785 | * numSGE = 1 + (ZZ-1)*(maxChain -1) + ZZ |
| 4786 | * + (req_sz - 64)/sizeof(SGE) |
| 4787 | * A slightly different algorithm is required for |
| 4788 | * 64bit SGEs. |
| 4789 | */ |
Kashyap, Desai | 14d0f0b | 2009-05-29 16:37:04 +0530 | [diff] [blame] | 4790 | scale = ioc->req_sz/ioc->SGE_size; |
| 4791 | if (ioc->sg_addr_size == sizeof(u64)) { |
Christoph Hellwig | 0c33b27 | 2005-09-09 16:27:19 +0200 | [diff] [blame] | 4792 | numSGE = (scale - 1) * |
| 4793 | (ioc->facts.MaxChainDepth-1) + scale + |
Kashyap, Desai | 14d0f0b | 2009-05-29 16:37:04 +0530 | [diff] [blame] | 4794 | (ioc->req_sz - 60) / ioc->SGE_size; |
Christoph Hellwig | 0c33b27 | 2005-09-09 16:27:19 +0200 | [diff] [blame] | 4795 | } else { |
| 4796 | numSGE = 1 + (scale - 1) * |
| 4797 | (ioc->facts.MaxChainDepth-1) + scale + |
Kashyap, Desai | 14d0f0b | 2009-05-29 16:37:04 +0530 | [diff] [blame] | 4798 | (ioc->req_sz - 64) / ioc->SGE_size; |
Christoph Hellwig | 0c33b27 | 2005-09-09 16:27:19 +0200 | [diff] [blame] | 4799 | } |
| 4800 | |
| 4801 | if (numSGE < sh->sg_tablesize) { |
| 4802 | /* Reset this value */ |
Prakash, Sathya | d6ecdd6 | 2007-07-24 15:47:41 +0530 | [diff] [blame] | 4803 | dprintk(ioc, printk(MYIOC_s_DEBUG_FMT |
Christoph Hellwig | 0c33b27 | 2005-09-09 16:27:19 +0200 | [diff] [blame] | 4804 | "Resetting sg_tablesize to %d from %d\n", |
| 4805 | ioc->name, numSGE, sh->sg_tablesize)); |
| 4806 | sh->sg_tablesize = numSGE; |
| 4807 | } |
| 4808 | |
Eric Moore | e7eae9f | 2007-09-29 10:15:59 -0600 | [diff] [blame] | 4809 | hd = shost_priv(sh); |
Christoph Hellwig | 0c33b27 | 2005-09-09 16:27:19 +0200 | [diff] [blame] | 4810 | hd->ioc = ioc; |
| 4811 | |
| 4812 | /* SCSI needs scsi_cmnd lookup table! |
| 4813 | * (with size equal to req_depth*PtrSz!) |
| 4814 | */ |
Eric Moore | e820638 | 2007-09-29 10:16:53 -0600 | [diff] [blame] | 4815 | ioc->ScsiLookup = kcalloc(ioc->req_depth, sizeof(void *), GFP_ATOMIC); |
| 4816 | if (!ioc->ScsiLookup) { |
Christoph Hellwig | 0c33b27 | 2005-09-09 16:27:19 +0200 | [diff] [blame] | 4817 | error = -ENOMEM; |
Eric Moore | bc6e089 | 2007-09-29 10:16:28 -0600 | [diff] [blame] | 4818 | spin_unlock_irqrestore(&ioc->FreeQlock, flags); |
Moore, Eric Dean | 7acec1e | 2005-11-16 18:54:17 -0700 | [diff] [blame] | 4819 | goto out_mptsas_probe; |
Christoph Hellwig | 0c33b27 | 2005-09-09 16:27:19 +0200 | [diff] [blame] | 4820 | } |
Eric Moore | e820638 | 2007-09-29 10:16:53 -0600 | [diff] [blame] | 4821 | spin_lock_init(&ioc->scsi_lookup_lock); |
Christoph Hellwig | 0c33b27 | 2005-09-09 16:27:19 +0200 | [diff] [blame] | 4822 | |
Prakash, Sathya | d6ecdd6 | 2007-07-24 15:47:41 +0530 | [diff] [blame] | 4823 | dprintk(ioc, printk(MYIOC_s_DEBUG_FMT "ScsiLookup @ %p\n", |
Eric Moore | e820638 | 2007-09-29 10:16:53 -0600 | [diff] [blame] | 4824 | ioc->name, ioc->ScsiLookup)); |
Christoph Hellwig | 0c33b27 | 2005-09-09 16:27:19 +0200 | [diff] [blame] | 4825 | |
Christoph Hellwig | 0c33b27 | 2005-09-09 16:27:19 +0200 | [diff] [blame] | 4826 | /* Clear the TM flags |
| 4827 | */ |
Christoph Hellwig | 0c33b27 | 2005-09-09 16:27:19 +0200 | [diff] [blame] | 4828 | hd->abortSCpnt = NULL; |
| 4829 | |
| 4830 | /* Clear the pointer used to store |
| 4831 | * single-threaded commands, i.e., those |
| 4832 | * issued during a bus scan, dv and |
| 4833 | * configuration pages. |
| 4834 | */ |
| 4835 | hd->cmdPtr = NULL; |
| 4836 | |
| 4837 | /* Initialize this SCSI Hosts' timers |
| 4838 | * To use, set the timer expires field |
| 4839 | * and add_timer |
| 4840 | */ |
| 4841 | init_timer(&hd->timer); |
| 4842 | hd->timer.data = (unsigned long) hd; |
| 4843 | hd->timer.function = mptscsih_timer_expired; |
| 4844 | |
Christoph Hellwig | 0c33b27 | 2005-09-09 16:27:19 +0200 | [diff] [blame] | 4845 | ioc->sas_data.ptClear = mpt_pt_clear; |
| 4846 | |
Eric Moore | df9e062 | 2007-01-29 09:46:21 -0700 | [diff] [blame] | 4847 | hd->last_queue_full = 0; |
| 4848 | INIT_LIST_HEAD(&hd->target_reset_list); |
Kashyap, Desai | 3eb0822c | 2009-05-29 16:47:26 +0530 | [diff] [blame] | 4849 | INIT_LIST_HEAD(&ioc->sas_device_info_list); |
| 4850 | mutex_init(&ioc->sas_device_info_mutex); |
| 4851 | |
Eric Moore | df9e062 | 2007-01-29 09:46:21 -0700 | [diff] [blame] | 4852 | spin_unlock_irqrestore(&ioc->FreeQlock, flags); |
| 4853 | |
Christoph Hellwig | 0c33b27 | 2005-09-09 16:27:19 +0200 | [diff] [blame] | 4854 | if (ioc->sas_data.ptClear==1) { |
| 4855 | mptbase_sas_persist_operation( |
| 4856 | ioc, MPI_SAS_OP_CLEAR_ALL_PERSISTENT); |
| 4857 | } |
| 4858 | |
Christoph Hellwig | 0c33b27 | 2005-09-09 16:27:19 +0200 | [diff] [blame] | 4859 | error = scsi_add_host(sh, &ioc->pcidev->dev); |
| 4860 | if (error) { |
Eric Moore | 29dd360 | 2007-09-14 18:46:51 -0600 | [diff] [blame] | 4861 | dprintk(ioc, printk(MYIOC_s_ERR_FMT |
| 4862 | "scsi_add_host failed\n", ioc->name)); |
Moore, Eric Dean | 7acec1e | 2005-11-16 18:54:17 -0700 | [diff] [blame] | 4863 | goto out_mptsas_probe; |
Christoph Hellwig | 0c33b27 | 2005-09-09 16:27:19 +0200 | [diff] [blame] | 4864 | } |
| 4865 | |
Kashyap, Desai | eedf92b | 2009-05-29 16:51:32 +0530 | [diff] [blame] | 4866 | /* older firmware doesn't support expander events */ |
| 4867 | if ((ioc->facts.HeaderVersion >> 8) < 0xE) |
| 4868 | ioc->old_sas_discovery_protocal = 1; |
Christoph Hellwig | 0c33b27 | 2005-09-09 16:27:19 +0200 | [diff] [blame] | 4869 | mptsas_scan_sas_topology(ioc); |
Kashyap, Desai | 3eb0822c | 2009-05-29 16:47:26 +0530 | [diff] [blame] | 4870 | mptsas_fw_event_on(ioc); |
Christoph Hellwig | 0c33b27 | 2005-09-09 16:27:19 +0200 | [diff] [blame] | 4871 | return 0; |
| 4872 | |
Eric Moore | 547f9a2 | 2006-06-27 14:42:12 -0600 | [diff] [blame] | 4873 | out_mptsas_probe: |
Christoph Hellwig | 0c33b27 | 2005-09-09 16:27:19 +0200 | [diff] [blame] | 4874 | |
| 4875 | mptscsih_remove(pdev); |
| 4876 | return error; |
| 4877 | } |
| 4878 | |
Kashyap, Desai | 7b5a65b | 2009-05-29 16:38:14 +0530 | [diff] [blame] | 4879 | void |
| 4880 | mptsas_shutdown(struct pci_dev *pdev) |
| 4881 | { |
| 4882 | MPT_ADAPTER *ioc = pci_get_drvdata(pdev); |
| 4883 | |
Kashyap, Desai | 3eb0822c | 2009-05-29 16:47:26 +0530 | [diff] [blame] | 4884 | mptsas_fw_event_off(ioc); |
| 4885 | mptsas_cleanup_fw_event_q(ioc); |
Kashyap, Desai | 7b5a65b | 2009-05-29 16:38:14 +0530 | [diff] [blame] | 4886 | } |
| 4887 | |
Christoph Hellwig | 0c33b27 | 2005-09-09 16:27:19 +0200 | [diff] [blame] | 4888 | static void __devexit mptsas_remove(struct pci_dev *pdev) |
| 4889 | { |
| 4890 | MPT_ADAPTER *ioc = pci_get_drvdata(pdev); |
| 4891 | struct mptsas_portinfo *p, *n; |
Eric Moore | 547f9a2 | 2006-06-27 14:42:12 -0600 | [diff] [blame] | 4892 | int i; |
Christoph Hellwig | 0c33b27 | 2005-09-09 16:27:19 +0200 | [diff] [blame] | 4893 | |
Kashyap, Desai | 7b5a65b | 2009-05-29 16:38:14 +0530 | [diff] [blame] | 4894 | mptsas_shutdown(pdev); |
| 4895 | |
Kashyap, Desai | 3eb0822c | 2009-05-29 16:47:26 +0530 | [diff] [blame] | 4896 | mptsas_del_device_components(ioc); |
| 4897 | |
Eric Moore | b506ade | 2007-01-29 09:45:37 -0700 | [diff] [blame] | 4898 | ioc->sas_discovery_ignore_events = 1; |
Christoph Hellwig | 0c33b27 | 2005-09-09 16:27:19 +0200 | [diff] [blame] | 4899 | sas_remove_host(ioc->sh); |
| 4900 | |
Christoph Hellwig | 9a28f49 | 2006-01-13 18:04:41 +0100 | [diff] [blame] | 4901 | mutex_lock(&ioc->sas_topology_mutex); |
Christoph Hellwig | 0c33b27 | 2005-09-09 16:27:19 +0200 | [diff] [blame] | 4902 | list_for_each_entry_safe(p, n, &ioc->sas_topology, list) { |
| 4903 | list_del(&p->list); |
Eric Moore | 547f9a2 | 2006-06-27 14:42:12 -0600 | [diff] [blame] | 4904 | for (i = 0 ; i < p->num_phys ; i++) |
Prakash, Sathya | d6ecdd6 | 2007-07-24 15:47:41 +0530 | [diff] [blame] | 4905 | mptsas_port_delete(ioc, p->phy_info[i].port_details); |
Kashyap, Desai | 3eb0822c | 2009-05-29 16:47:26 +0530 | [diff] [blame] | 4906 | |
Eric Moore | 547f9a2 | 2006-06-27 14:42:12 -0600 | [diff] [blame] | 4907 | kfree(p->phy_info); |
Christoph Hellwig | 0c33b27 | 2005-09-09 16:27:19 +0200 | [diff] [blame] | 4908 | kfree(p); |
| 4909 | } |
Christoph Hellwig | 9a28f49 | 2006-01-13 18:04:41 +0100 | [diff] [blame] | 4910 | mutex_unlock(&ioc->sas_topology_mutex); |
Kashyap, Desai | f9c3402 | 2009-05-29 16:49:36 +0530 | [diff] [blame] | 4911 | ioc->hba_port_info = NULL; |
Christoph Hellwig | 0c33b27 | 2005-09-09 16:27:19 +0200 | [diff] [blame] | 4912 | mptscsih_remove(pdev); |
| 4913 | } |
| 4914 | |
| 4915 | static struct pci_device_id mptsas_pci_table[] = { |
Eric Moore | 87cf898 | 2006-06-27 16:09:26 -0600 | [diff] [blame] | 4916 | { PCI_VENDOR_ID_LSI_LOGIC, MPI_MANUFACTPAGE_DEVID_SAS1064, |
Christoph Hellwig | 0c33b27 | 2005-09-09 16:27:19 +0200 | [diff] [blame] | 4917 | PCI_ANY_ID, PCI_ANY_ID }, |
Eric Moore | 87cf898 | 2006-06-27 16:09:26 -0600 | [diff] [blame] | 4918 | { PCI_VENDOR_ID_LSI_LOGIC, MPI_MANUFACTPAGE_DEVID_SAS1068, |
Christoph Hellwig | 0c33b27 | 2005-09-09 16:27:19 +0200 | [diff] [blame] | 4919 | PCI_ANY_ID, PCI_ANY_ID }, |
Eric Moore | 87cf898 | 2006-06-27 16:09:26 -0600 | [diff] [blame] | 4920 | { PCI_VENDOR_ID_LSI_LOGIC, MPI_MANUFACTPAGE_DEVID_SAS1064E, |
Christoph Hellwig | 0c33b27 | 2005-09-09 16:27:19 +0200 | [diff] [blame] | 4921 | PCI_ANY_ID, PCI_ANY_ID }, |
Eric Moore | 87cf898 | 2006-06-27 16:09:26 -0600 | [diff] [blame] | 4922 | { PCI_VENDOR_ID_LSI_LOGIC, MPI_MANUFACTPAGE_DEVID_SAS1068E, |
Christoph Hellwig | 0c33b27 | 2005-09-09 16:27:19 +0200 | [diff] [blame] | 4923 | PCI_ANY_ID, PCI_ANY_ID }, |
Eric Moore | 87cf898 | 2006-06-27 16:09:26 -0600 | [diff] [blame] | 4924 | { PCI_VENDOR_ID_LSI_LOGIC, MPI_MANUFACTPAGE_DEVID_SAS1078, |
Christoph Hellwig | 0c33b27 | 2005-09-09 16:27:19 +0200 | [diff] [blame] | 4925 | PCI_ANY_ID, PCI_ANY_ID }, |
| 4926 | {0} /* Terminating entry */ |
| 4927 | }; |
| 4928 | MODULE_DEVICE_TABLE(pci, mptsas_pci_table); |
| 4929 | |
| 4930 | |
| 4931 | static struct pci_driver mptsas_driver = { |
| 4932 | .name = "mptsas", |
| 4933 | .id_table = mptsas_pci_table, |
| 4934 | .probe = mptsas_probe, |
| 4935 | .remove = __devexit_p(mptsas_remove), |
Kashyap, Desai | 7b5a65b | 2009-05-29 16:38:14 +0530 | [diff] [blame] | 4936 | .shutdown = mptsas_shutdown, |
Christoph Hellwig | 0c33b27 | 2005-09-09 16:27:19 +0200 | [diff] [blame] | 4937 | #ifdef CONFIG_PM |
| 4938 | .suspend = mptscsih_suspend, |
| 4939 | .resume = mptscsih_resume, |
| 4940 | #endif |
| 4941 | }; |
| 4942 | |
| 4943 | static int __init |
| 4944 | mptsas_init(void) |
| 4945 | { |
Prakash, Sathya | 57ce21b | 2007-07-02 17:04:10 +0530 | [diff] [blame] | 4946 | int error; |
| 4947 | |
Christoph Hellwig | 0c33b27 | 2005-09-09 16:27:19 +0200 | [diff] [blame] | 4948 | show_mptmod_ver(my_NAME, my_VERSION); |
| 4949 | |
| 4950 | mptsas_transport_template = |
| 4951 | sas_attach_transport(&mptsas_transport_functions); |
| 4952 | if (!mptsas_transport_template) |
| 4953 | return -ENODEV; |
| 4954 | |
| 4955 | mptsasDoneCtx = mpt_register(mptscsih_io_done, MPTSAS_DRIVER); |
Kashyap, Desai | e7deff3 | 2009-05-29 16:46:07 +0530 | [diff] [blame] | 4956 | mptsasTaskCtx = mpt_register(mptscsih_taskmgmt_complete, MPTSAS_DRIVER); |
Christoph Hellwig | 0c33b27 | 2005-09-09 16:27:19 +0200 | [diff] [blame] | 4957 | mptsasInternalCtx = |
| 4958 | mpt_register(mptscsih_scandv_complete, MPTSAS_DRIVER); |
Christoph Hellwig | da4fa65 | 2005-10-19 20:01:42 +0200 | [diff] [blame] | 4959 | mptsasMgmtCtx = mpt_register(mptsas_mgmt_done, MPTSAS_DRIVER); |
Kashyap, Desai | e7deff3 | 2009-05-29 16:46:07 +0530 | [diff] [blame] | 4960 | mptsasDeviceResetCtx = |
| 4961 | mpt_register(mptsas_taskmgmt_complete, MPTSAS_DRIVER); |
Christoph Hellwig | 0c33b27 | 2005-09-09 16:27:19 +0200 | [diff] [blame] | 4962 | |
Prakash, Sathya | d6ecdd6 | 2007-07-24 15:47:41 +0530 | [diff] [blame] | 4963 | mpt_event_register(mptsasDoneCtx, mptsas_event_process); |
| 4964 | mpt_reset_register(mptsasDoneCtx, mptsas_ioc_reset); |
Christoph Hellwig | 0c33b27 | 2005-09-09 16:27:19 +0200 | [diff] [blame] | 4965 | |
Prakash, Sathya | 57ce21b | 2007-07-02 17:04:10 +0530 | [diff] [blame] | 4966 | error = pci_register_driver(&mptsas_driver); |
| 4967 | if (error) |
| 4968 | sas_release_transport(mptsas_transport_template); |
| 4969 | |
| 4970 | return error; |
Christoph Hellwig | 0c33b27 | 2005-09-09 16:27:19 +0200 | [diff] [blame] | 4971 | } |
| 4972 | |
| 4973 | static void __exit |
| 4974 | mptsas_exit(void) |
| 4975 | { |
| 4976 | pci_unregister_driver(&mptsas_driver); |
| 4977 | sas_release_transport(mptsas_transport_template); |
| 4978 | |
| 4979 | mpt_reset_deregister(mptsasDoneCtx); |
| 4980 | mpt_event_deregister(mptsasDoneCtx); |
| 4981 | |
Christoph Hellwig | da4fa65 | 2005-10-19 20:01:42 +0200 | [diff] [blame] | 4982 | mpt_deregister(mptsasMgmtCtx); |
Christoph Hellwig | 0c33b27 | 2005-09-09 16:27:19 +0200 | [diff] [blame] | 4983 | mpt_deregister(mptsasInternalCtx); |
| 4984 | mpt_deregister(mptsasTaskCtx); |
| 4985 | mpt_deregister(mptsasDoneCtx); |
Kashyap, Desai | e7deff3 | 2009-05-29 16:46:07 +0530 | [diff] [blame] | 4986 | mpt_deregister(mptsasDeviceResetCtx); |
Christoph Hellwig | 0c33b27 | 2005-09-09 16:27:19 +0200 | [diff] [blame] | 4987 | } |
| 4988 | |
| 4989 | module_init(mptsas_init); |
| 4990 | module_exit(mptsas_exit); |