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 | |
Eric Moore | b506ade | 2007-01-29 09:45:37 -0700 | [diff] [blame] | 98 | static void mptsas_hotplug_work(struct work_struct *work); |
Christoph Hellwig | 0c33b27 | 2005-09-09 16:27:19 +0200 | [diff] [blame] | 99 | |
Prakash, Sathya | d6ecdd6 | 2007-07-24 15:47:41 +0530 | [diff] [blame] | 100 | static void mptsas_print_phy_data(MPT_ADAPTER *ioc, |
| 101 | MPI_SAS_IO_UNIT0_PHY_DATA *phy_data) |
Christoph Hellwig | b514112 | 2005-10-28 22:07:41 +0200 | [diff] [blame] | 102 | { |
Eric Moore | 29dd360 | 2007-09-14 18:46:51 -0600 | [diff] [blame] | 103 | dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT |
| 104 | "---- IO UNIT PAGE 0 ------------\n", ioc->name)); |
| 105 | dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Handle=0x%X\n", |
| 106 | ioc->name, le16_to_cpu(phy_data->AttachedDeviceHandle))); |
| 107 | dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Controller Handle=0x%X\n", |
| 108 | ioc->name, le16_to_cpu(phy_data->ControllerDevHandle))); |
| 109 | dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Port=0x%X\n", |
| 110 | ioc->name, phy_data->Port)); |
| 111 | dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Port Flags=0x%X\n", |
| 112 | ioc->name, phy_data->PortFlags)); |
| 113 | dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "PHY Flags=0x%X\n", |
| 114 | ioc->name, phy_data->PhyFlags)); |
| 115 | dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Negotiated Link Rate=0x%X\n", |
| 116 | ioc->name, phy_data->NegotiatedLinkRate)); |
| 117 | dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT |
| 118 | "Controller PHY Device Info=0x%X\n", ioc->name, |
| 119 | le32_to_cpu(phy_data->ControllerPhyDeviceInfo))); |
| 120 | dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "DiscoveryStatus=0x%X\n\n", |
| 121 | ioc->name, le32_to_cpu(phy_data->DiscoveryStatus))); |
Christoph Hellwig | b514112 | 2005-10-28 22:07:41 +0200 | [diff] [blame] | 122 | } |
| 123 | |
Prakash, Sathya | d6ecdd6 | 2007-07-24 15:47:41 +0530 | [diff] [blame] | 124 | static void mptsas_print_phy_pg0(MPT_ADAPTER *ioc, SasPhyPage0_t *pg0) |
Christoph Hellwig | b514112 | 2005-10-28 22:07:41 +0200 | [diff] [blame] | 125 | { |
| 126 | __le64 sas_address; |
| 127 | |
| 128 | memcpy(&sas_address, &pg0->SASAddress, sizeof(__le64)); |
| 129 | |
Eric Moore | 29dd360 | 2007-09-14 18:46:51 -0600 | [diff] [blame] | 130 | dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT |
| 131 | "---- SAS PHY PAGE 0 ------------\n", ioc->name)); |
| 132 | dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT |
| 133 | "Attached Device Handle=0x%X\n", ioc->name, |
| 134 | le16_to_cpu(pg0->AttachedDevHandle))); |
| 135 | dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "SAS Address=0x%llX\n", |
| 136 | ioc->name, (unsigned long long)le64_to_cpu(sas_address))); |
| 137 | dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT |
| 138 | "Attached PHY Identifier=0x%X\n", ioc->name, |
| 139 | pg0->AttachedPhyIdentifier)); |
| 140 | dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Attached Device Info=0x%X\n", |
| 141 | ioc->name, le32_to_cpu(pg0->AttachedDeviceInfo))); |
| 142 | dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Programmed Link Rate=0x%X\n", |
| 143 | ioc->name, pg0->ProgrammedLinkRate)); |
| 144 | dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Change Count=0x%X\n", |
| 145 | ioc->name, pg0->ChangeCount)); |
| 146 | dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "PHY Info=0x%X\n\n", |
| 147 | ioc->name, le32_to_cpu(pg0->PhyInfo))); |
Christoph Hellwig | b514112 | 2005-10-28 22:07:41 +0200 | [diff] [blame] | 148 | } |
| 149 | |
Prakash, Sathya | d6ecdd6 | 2007-07-24 15:47:41 +0530 | [diff] [blame] | 150 | static void mptsas_print_phy_pg1(MPT_ADAPTER *ioc, SasPhyPage1_t *pg1) |
Christoph Hellwig | b514112 | 2005-10-28 22:07:41 +0200 | [diff] [blame] | 151 | { |
Eric Moore | 29dd360 | 2007-09-14 18:46:51 -0600 | [diff] [blame] | 152 | dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT |
| 153 | "---- SAS PHY PAGE 1 ------------\n", ioc->name)); |
| 154 | dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Invalid Dword Count=0x%x\n", |
| 155 | ioc->name, pg1->InvalidDwordCount)); |
| 156 | dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT |
| 157 | "Running Disparity Error Count=0x%x\n", ioc->name, |
| 158 | pg1->RunningDisparityErrorCount)); |
| 159 | dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT |
| 160 | "Loss Dword Synch Count=0x%x\n", ioc->name, |
| 161 | pg1->LossDwordSynchCount)); |
| 162 | dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT |
| 163 | "PHY Reset Problem Count=0x%x\n\n", ioc->name, |
| 164 | pg1->PhyResetProblemCount)); |
Christoph Hellwig | b514112 | 2005-10-28 22:07:41 +0200 | [diff] [blame] | 165 | } |
| 166 | |
Prakash, Sathya | d6ecdd6 | 2007-07-24 15:47:41 +0530 | [diff] [blame] | 167 | static void mptsas_print_device_pg0(MPT_ADAPTER *ioc, SasDevicePage0_t *pg0) |
Christoph Hellwig | b514112 | 2005-10-28 22:07:41 +0200 | [diff] [blame] | 168 | { |
| 169 | __le64 sas_address; |
| 170 | |
| 171 | memcpy(&sas_address, &pg0->SASAddress, sizeof(__le64)); |
| 172 | |
Eric Moore | 29dd360 | 2007-09-14 18:46:51 -0600 | [diff] [blame] | 173 | dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT |
| 174 | "---- SAS DEVICE PAGE 0 ---------\n", ioc->name)); |
| 175 | dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Handle=0x%X\n", |
| 176 | ioc->name, le16_to_cpu(pg0->DevHandle))); |
| 177 | dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Parent Handle=0x%X\n", |
| 178 | ioc->name, le16_to_cpu(pg0->ParentDevHandle))); |
| 179 | dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Enclosure Handle=0x%X\n", |
| 180 | ioc->name, le16_to_cpu(pg0->EnclosureHandle))); |
| 181 | dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Slot=0x%X\n", |
| 182 | ioc->name, le16_to_cpu(pg0->Slot))); |
| 183 | dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "SAS Address=0x%llX\n", |
| 184 | ioc->name, (unsigned long long)le64_to_cpu(sas_address))); |
| 185 | dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Target ID=0x%X\n", |
| 186 | ioc->name, pg0->TargetID)); |
| 187 | dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Bus=0x%X\n", |
| 188 | ioc->name, pg0->Bus)); |
| 189 | dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Parent Phy Num=0x%X\n", |
| 190 | ioc->name, pg0->PhyNum)); |
| 191 | dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Access Status=0x%X\n", |
| 192 | ioc->name, le16_to_cpu(pg0->AccessStatus))); |
| 193 | dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Device Info=0x%X\n", |
| 194 | ioc->name, le32_to_cpu(pg0->DeviceInfo))); |
| 195 | dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Flags=0x%X\n", |
| 196 | ioc->name, le16_to_cpu(pg0->Flags))); |
| 197 | dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Physical Port=0x%X\n\n", |
| 198 | ioc->name, pg0->PhysicalPort)); |
Christoph Hellwig | b514112 | 2005-10-28 22:07:41 +0200 | [diff] [blame] | 199 | } |
| 200 | |
Prakash, Sathya | d6ecdd6 | 2007-07-24 15:47:41 +0530 | [diff] [blame] | 201 | static void mptsas_print_expander_pg1(MPT_ADAPTER *ioc, SasExpanderPage1_t *pg1) |
Christoph Hellwig | b514112 | 2005-10-28 22:07:41 +0200 | [diff] [blame] | 202 | { |
Eric Moore | 29dd360 | 2007-09-14 18:46:51 -0600 | [diff] [blame] | 203 | dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT |
| 204 | "---- SAS EXPANDER PAGE 1 ------------\n", ioc->name)); |
| 205 | dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Physical Port=0x%X\n", |
| 206 | ioc->name, pg1->PhysicalPort)); |
| 207 | dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "PHY Identifier=0x%X\n", |
| 208 | ioc->name, pg1->PhyIdentifier)); |
| 209 | dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Negotiated Link Rate=0x%X\n", |
| 210 | ioc->name, pg1->NegotiatedLinkRate)); |
| 211 | dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Programmed Link Rate=0x%X\n", |
| 212 | ioc->name, pg1->ProgrammedLinkRate)); |
| 213 | dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Hardware Link Rate=0x%X\n", |
| 214 | ioc->name, pg1->HwLinkRate)); |
| 215 | dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Owner Device Handle=0x%X\n", |
| 216 | ioc->name, le16_to_cpu(pg1->OwnerDevHandle))); |
| 217 | dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT |
| 218 | "Attached Device Handle=0x%X\n\n", ioc->name, |
| 219 | le16_to_cpu(pg1->AttachedDevHandle))); |
Christoph Hellwig | b514112 | 2005-10-28 22:07:41 +0200 | [diff] [blame] | 220 | } |
Christoph Hellwig | b514112 | 2005-10-28 22:07:41 +0200 | [diff] [blame] | 221 | |
Christoph Hellwig | e309444 | 2006-02-16 13:25:36 +0100 | [diff] [blame] | 222 | static inline MPT_ADAPTER *phy_to_ioc(struct sas_phy *phy) |
| 223 | { |
| 224 | struct Scsi_Host *shost = dev_to_shost(phy->dev.parent); |
| 225 | return ((MPT_SCSI_HOST *)shost->hostdata)->ioc; |
| 226 | } |
| 227 | |
| 228 | static inline MPT_ADAPTER *rphy_to_ioc(struct sas_rphy *rphy) |
| 229 | { |
| 230 | struct Scsi_Host *shost = dev_to_shost(rphy->dev.parent->parent); |
| 231 | return ((MPT_SCSI_HOST *)shost->hostdata)->ioc; |
| 232 | } |
| 233 | |
Michael Reed | 7748369 | 2008-03-20 17:32:05 -0500 | [diff] [blame] | 234 | static struct mptsas_portinfo * |
| 235 | mptsas_get_hba_portinfo(MPT_ADAPTER *ioc) |
| 236 | { |
| 237 | struct list_head *head = &ioc->sas_topology; |
| 238 | struct mptsas_portinfo *pi = NULL; |
| 239 | |
| 240 | /* always the first entry on sas_topology list */ |
| 241 | |
| 242 | if (!list_empty(head)) |
| 243 | pi = list_entry(head->next, struct mptsas_portinfo, list); |
| 244 | |
| 245 | return pi; |
| 246 | } |
| 247 | |
Moore, Eric | e6b2d76 | 2006-03-14 09:14:24 -0700 | [diff] [blame] | 248 | /* |
| 249 | * mptsas_find_portinfo_by_handle |
| 250 | * |
| 251 | * This function should be called with the sas_topology_mutex already held |
| 252 | */ |
| 253 | static struct mptsas_portinfo * |
| 254 | mptsas_find_portinfo_by_handle(MPT_ADAPTER *ioc, u16 handle) |
| 255 | { |
| 256 | struct mptsas_portinfo *port_info, *rc=NULL; |
| 257 | int i; |
| 258 | |
| 259 | list_for_each_entry(port_info, &ioc->sas_topology, list) |
| 260 | for (i = 0; i < port_info->num_phys; i++) |
| 261 | if (port_info->phy_info[i].identify.handle == handle) { |
| 262 | rc = port_info; |
| 263 | goto out; |
| 264 | } |
| 265 | out: |
| 266 | return rc; |
| 267 | } |
| 268 | |
Moore, Eric | bd23e94 | 2006-04-17 12:43:04 -0600 | [diff] [blame] | 269 | /* |
| 270 | * Returns true if there is a scsi end device |
| 271 | */ |
| 272 | static inline int |
| 273 | mptsas_is_end_device(struct mptsas_devinfo * attached) |
| 274 | { |
Eric Moore | 547f9a2 | 2006-06-27 14:42:12 -0600 | [diff] [blame] | 275 | if ((attached->sas_address) && |
Moore, Eric | bd23e94 | 2006-04-17 12:43:04 -0600 | [diff] [blame] | 276 | (attached->device_info & |
| 277 | MPI_SAS_DEVICE_INFO_END_DEVICE) && |
| 278 | ((attached->device_info & |
| 279 | MPI_SAS_DEVICE_INFO_SSP_TARGET) | |
| 280 | (attached->device_info & |
| 281 | MPI_SAS_DEVICE_INFO_STP_TARGET) | |
| 282 | (attached->device_info & |
| 283 | MPI_SAS_DEVICE_INFO_SATA_DEVICE))) |
| 284 | return 1; |
| 285 | else |
| 286 | return 0; |
| 287 | } |
| 288 | |
Eric Moore | 547f9a2 | 2006-06-27 14:42:12 -0600 | [diff] [blame] | 289 | /* no mutex */ |
Eric Moore | 376ac83 | 2006-06-29 17:36:26 -0600 | [diff] [blame] | 290 | static void |
Prakash, Sathya | d6ecdd6 | 2007-07-24 15:47:41 +0530 | [diff] [blame] | 291 | mptsas_port_delete(MPT_ADAPTER *ioc, struct mptsas_portinfo_details * port_details) |
Eric Moore | 547f9a2 | 2006-06-27 14:42:12 -0600 | [diff] [blame] | 292 | { |
| 293 | struct mptsas_portinfo *port_info; |
| 294 | struct mptsas_phyinfo *phy_info; |
| 295 | u8 i; |
| 296 | |
| 297 | if (!port_details) |
| 298 | return; |
| 299 | |
| 300 | port_info = port_details->port_info; |
| 301 | phy_info = port_info->phy_info; |
| 302 | |
Eric Moore | 29dd360 | 2007-09-14 18:46:51 -0600 | [diff] [blame] | 303 | dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "%s: [%p]: num_phys=%02d " |
Harvey Harrison | cadbd4a | 2008-07-03 23:47:27 -0700 | [diff] [blame] | 304 | "bitmask=0x%016llX\n", ioc->name, __func__, port_details, |
Eric Moore | f99be43 | 2007-01-04 20:46:54 -0700 | [diff] [blame] | 305 | port_details->num_phys, (unsigned long long) |
| 306 | port_details->phy_bitmask)); |
Eric Moore | 547f9a2 | 2006-06-27 14:42:12 -0600 | [diff] [blame] | 307 | |
| 308 | for (i = 0; i < port_info->num_phys; i++, phy_info++) { |
| 309 | if(phy_info->port_details != port_details) |
| 310 | continue; |
| 311 | memset(&phy_info->attached, 0, sizeof(struct mptsas_devinfo)); |
| 312 | phy_info->port_details = NULL; |
| 313 | } |
| 314 | kfree(port_details); |
| 315 | } |
| 316 | |
| 317 | static inline struct sas_rphy * |
| 318 | mptsas_get_rphy(struct mptsas_phyinfo *phy_info) |
| 319 | { |
| 320 | if (phy_info->port_details) |
| 321 | return phy_info->port_details->rphy; |
| 322 | else |
| 323 | return NULL; |
| 324 | } |
| 325 | |
| 326 | static inline void |
Prakash, Sathya | d6ecdd6 | 2007-07-24 15:47:41 +0530 | [diff] [blame] | 327 | 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] | 328 | { |
| 329 | if (phy_info->port_details) { |
| 330 | phy_info->port_details->rphy = rphy; |
Eric Moore | 29dd360 | 2007-09-14 18:46:51 -0600 | [diff] [blame] | 331 | dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n", |
| 332 | ioc->name, rphy)); |
Eric Moore | 547f9a2 | 2006-06-27 14:42:12 -0600 | [diff] [blame] | 333 | } |
| 334 | |
Eric Moore | 547f9a2 | 2006-06-27 14:42:12 -0600 | [diff] [blame] | 335 | if (rphy) { |
Eric Moore | c51d0be | 2007-09-29 10:17:21 -0600 | [diff] [blame] | 336 | dsaswideprintk(ioc, dev_printk(KERN_DEBUG, |
| 337 | &rphy->dev, MYIOC_s_FMT "add:", ioc->name)); |
Eric Moore | 29dd360 | 2007-09-14 18:46:51 -0600 | [diff] [blame] | 338 | dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n", |
| 339 | ioc->name, rphy, rphy->dev.release)); |
Eric Moore | 547f9a2 | 2006-06-27 14:42:12 -0600 | [diff] [blame] | 340 | } |
Eric Moore | 547f9a2 | 2006-06-27 14:42:12 -0600 | [diff] [blame] | 341 | } |
| 342 | |
| 343 | static inline struct sas_port * |
| 344 | mptsas_get_port(struct mptsas_phyinfo *phy_info) |
| 345 | { |
| 346 | if (phy_info->port_details) |
| 347 | return phy_info->port_details->port; |
| 348 | else |
| 349 | return NULL; |
| 350 | } |
| 351 | |
| 352 | static inline void |
Prakash, Sathya | d6ecdd6 | 2007-07-24 15:47:41 +0530 | [diff] [blame] | 353 | 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] | 354 | { |
| 355 | if (phy_info->port_details) |
| 356 | phy_info->port_details->port = port; |
| 357 | |
Eric Moore | 547f9a2 | 2006-06-27 14:42:12 -0600 | [diff] [blame] | 358 | if (port) { |
Eric Moore | c51d0be | 2007-09-29 10:17:21 -0600 | [diff] [blame] | 359 | dsaswideprintk(ioc, dev_printk(KERN_DEBUG, |
| 360 | &port->dev, MYIOC_s_FMT "add:", ioc->name)); |
Eric Moore | 29dd360 | 2007-09-14 18:46:51 -0600 | [diff] [blame] | 361 | dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "port=%p release=%p\n", |
| 362 | ioc->name, port, port->dev.release)); |
Eric Moore | 547f9a2 | 2006-06-27 14:42:12 -0600 | [diff] [blame] | 363 | } |
Eric Moore | 547f9a2 | 2006-06-27 14:42:12 -0600 | [diff] [blame] | 364 | } |
| 365 | |
| 366 | static inline struct scsi_target * |
| 367 | mptsas_get_starget(struct mptsas_phyinfo *phy_info) |
| 368 | { |
| 369 | if (phy_info->port_details) |
| 370 | return phy_info->port_details->starget; |
| 371 | else |
| 372 | return NULL; |
| 373 | } |
| 374 | |
| 375 | static inline void |
| 376 | mptsas_set_starget(struct mptsas_phyinfo *phy_info, struct scsi_target * |
| 377 | starget) |
| 378 | { |
| 379 | if (phy_info->port_details) |
| 380 | phy_info->port_details->starget = starget; |
| 381 | } |
| 382 | |
| 383 | |
| 384 | /* |
| 385 | * mptsas_setup_wide_ports |
| 386 | * |
| 387 | * Updates for new and existing narrow/wide port configuration |
| 388 | * in the sas_topology |
| 389 | */ |
Eric Moore | 376ac83 | 2006-06-29 17:36:26 -0600 | [diff] [blame] | 390 | static void |
Eric Moore | 547f9a2 | 2006-06-27 14:42:12 -0600 | [diff] [blame] | 391 | mptsas_setup_wide_ports(MPT_ADAPTER *ioc, struct mptsas_portinfo *port_info) |
| 392 | { |
| 393 | struct mptsas_portinfo_details * port_details; |
| 394 | struct mptsas_phyinfo *phy_info, *phy_info_cmp; |
| 395 | u64 sas_address; |
| 396 | int i, j; |
| 397 | |
| 398 | mutex_lock(&ioc->sas_topology_mutex); |
| 399 | |
| 400 | phy_info = port_info->phy_info; |
| 401 | for (i = 0 ; i < port_info->num_phys ; i++, phy_info++) { |
| 402 | if (phy_info->attached.handle) |
| 403 | continue; |
| 404 | port_details = phy_info->port_details; |
| 405 | if (!port_details) |
| 406 | continue; |
| 407 | if (port_details->num_phys < 2) |
| 408 | continue; |
| 409 | /* |
| 410 | * Removing a phy from a port, letting the last |
| 411 | * phy be removed by firmware events. |
| 412 | */ |
Eric Moore | 29dd360 | 2007-09-14 18:46:51 -0600 | [diff] [blame] | 413 | dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT |
| 414 | "%s: [%p]: deleting phy = %d\n", |
Harvey Harrison | cadbd4a | 2008-07-03 23:47:27 -0700 | [diff] [blame] | 415 | ioc->name, __func__, port_details, i)); |
Eric Moore | 547f9a2 | 2006-06-27 14:42:12 -0600 | [diff] [blame] | 416 | port_details->num_phys--; |
| 417 | port_details->phy_bitmask &= ~ (1 << phy_info->phy_id); |
| 418 | memset(&phy_info->attached, 0, sizeof(struct mptsas_devinfo)); |
| 419 | sas_port_delete_phy(port_details->port, phy_info->phy); |
| 420 | phy_info->port_details = NULL; |
| 421 | } |
| 422 | |
| 423 | /* |
| 424 | * Populate and refresh the tree |
| 425 | */ |
| 426 | phy_info = port_info->phy_info; |
| 427 | for (i = 0 ; i < port_info->num_phys ; i++, phy_info++) { |
| 428 | sas_address = phy_info->attached.sas_address; |
Eric Moore | 29dd360 | 2007-09-14 18:46:51 -0600 | [diff] [blame] | 429 | dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "phy_id=%d sas_address=0x%018llX\n", |
| 430 | ioc->name, i, (unsigned long long)sas_address)); |
Eric Moore | 547f9a2 | 2006-06-27 14:42:12 -0600 | [diff] [blame] | 431 | if (!sas_address) |
| 432 | continue; |
| 433 | port_details = phy_info->port_details; |
| 434 | /* |
| 435 | * Forming a port |
| 436 | */ |
| 437 | if (!port_details) { |
| 438 | port_details = kzalloc(sizeof(*port_details), |
| 439 | GFP_KERNEL); |
| 440 | if (!port_details) |
| 441 | goto out; |
| 442 | port_details->num_phys = 1; |
| 443 | port_details->port_info = port_info; |
Eric Moore | 547f9a2 | 2006-06-27 14:42:12 -0600 | [diff] [blame] | 444 | if (phy_info->phy_id < 64 ) |
| 445 | port_details->phy_bitmask |= |
| 446 | (1 << phy_info->phy_id); |
| 447 | phy_info->sas_port_add_phy=1; |
Eric Moore | 29dd360 | 2007-09-14 18:46:51 -0600 | [diff] [blame] | 448 | 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] | 449 | "phy_id=%d sas_address=0x%018llX\n", |
Eric Moore | 29dd360 | 2007-09-14 18:46:51 -0600 | [diff] [blame] | 450 | ioc->name, i, (unsigned long long)sas_address)); |
Eric Moore | 547f9a2 | 2006-06-27 14:42:12 -0600 | [diff] [blame] | 451 | phy_info->port_details = port_details; |
| 452 | } |
| 453 | |
| 454 | if (i == port_info->num_phys - 1) |
| 455 | continue; |
| 456 | phy_info_cmp = &port_info->phy_info[i + 1]; |
| 457 | for (j = i + 1 ; j < port_info->num_phys ; j++, |
| 458 | phy_info_cmp++) { |
| 459 | if (!phy_info_cmp->attached.sas_address) |
| 460 | continue; |
| 461 | if (sas_address != phy_info_cmp->attached.sas_address) |
| 462 | continue; |
| 463 | if (phy_info_cmp->port_details == port_details ) |
| 464 | continue; |
Eric Moore | 29dd360 | 2007-09-14 18:46:51 -0600 | [diff] [blame] | 465 | dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT |
Eric Moore | f99be43 | 2007-01-04 20:46:54 -0700 | [diff] [blame] | 466 | "\t\tphy_id=%d sas_address=0x%018llX\n", |
Eric Moore | 29dd360 | 2007-09-14 18:46:51 -0600 | [diff] [blame] | 467 | ioc->name, j, (unsigned long long) |
Eric Moore | f99be43 | 2007-01-04 20:46:54 -0700 | [diff] [blame] | 468 | phy_info_cmp->attached.sas_address)); |
Eric Moore | 547f9a2 | 2006-06-27 14:42:12 -0600 | [diff] [blame] | 469 | if (phy_info_cmp->port_details) { |
| 470 | port_details->rphy = |
| 471 | mptsas_get_rphy(phy_info_cmp); |
| 472 | port_details->port = |
| 473 | mptsas_get_port(phy_info_cmp); |
| 474 | port_details->starget = |
| 475 | mptsas_get_starget(phy_info_cmp); |
Eric Moore | 547f9a2 | 2006-06-27 14:42:12 -0600 | [diff] [blame] | 476 | port_details->num_phys = |
| 477 | phy_info_cmp->port_details->num_phys; |
Eric Moore | 547f9a2 | 2006-06-27 14:42:12 -0600 | [diff] [blame] | 478 | if (!phy_info_cmp->port_details->num_phys) |
| 479 | kfree(phy_info_cmp->port_details); |
| 480 | } else |
| 481 | phy_info_cmp->sas_port_add_phy=1; |
| 482 | /* |
| 483 | * Adding a phy to a port |
| 484 | */ |
| 485 | phy_info_cmp->port_details = port_details; |
| 486 | if (phy_info_cmp->phy_id < 64 ) |
| 487 | port_details->phy_bitmask |= |
| 488 | (1 << phy_info_cmp->phy_id); |
| 489 | port_details->num_phys++; |
| 490 | } |
| 491 | } |
| 492 | |
| 493 | out: |
| 494 | |
Eric Moore | 547f9a2 | 2006-06-27 14:42:12 -0600 | [diff] [blame] | 495 | for (i = 0; i < port_info->num_phys; i++) { |
| 496 | port_details = port_info->phy_info[i].port_details; |
| 497 | if (!port_details) |
| 498 | continue; |
Eric Moore | 29dd360 | 2007-09-14 18:46:51 -0600 | [diff] [blame] | 499 | dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT |
Eric Moore | f99be43 | 2007-01-04 20:46:54 -0700 | [diff] [blame] | 500 | "%s: [%p]: phy_id=%02d num_phys=%02d " |
Harvey Harrison | cadbd4a | 2008-07-03 23:47:27 -0700 | [diff] [blame] | 501 | "bitmask=0x%016llX\n", ioc->name, __func__, |
Eric Moore | f99be43 | 2007-01-04 20:46:54 -0700 | [diff] [blame] | 502 | port_details, i, port_details->num_phys, |
| 503 | (unsigned long long)port_details->phy_bitmask)); |
Eric Moore | 29dd360 | 2007-09-14 18:46:51 -0600 | [diff] [blame] | 504 | dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "\t\tport = %p rphy=%p\n", |
| 505 | ioc->name, port_details->port, port_details->rphy)); |
Eric Moore | 547f9a2 | 2006-06-27 14:42:12 -0600 | [diff] [blame] | 506 | } |
Eric Moore | 29dd360 | 2007-09-14 18:46:51 -0600 | [diff] [blame] | 507 | dsaswideprintk(ioc, printk("\n")); |
Eric Moore | 547f9a2 | 2006-06-27 14:42:12 -0600 | [diff] [blame] | 508 | mutex_unlock(&ioc->sas_topology_mutex); |
| 509 | } |
| 510 | |
Eric Moore | df9e062 | 2007-01-29 09:46:21 -0700 | [diff] [blame] | 511 | /** |
| 512 | * csmisas_find_vtarget |
| 513 | * |
| 514 | * @ioc |
| 515 | * @volume_id |
| 516 | * @volume_bus |
| 517 | * |
| 518 | **/ |
| 519 | static VirtTarget * |
| 520 | mptsas_find_vtarget(MPT_ADAPTER *ioc, u8 channel, u8 id) |
Eric Moore | 547f9a2 | 2006-06-27 14:42:12 -0600 | [diff] [blame] | 521 | { |
Eric Moore | df9e062 | 2007-01-29 09:46:21 -0700 | [diff] [blame] | 522 | struct scsi_device *sdev; |
Eric Moore | a69de50 | 2007-09-14 18:48:19 -0600 | [diff] [blame] | 523 | VirtDevice *vdevice; |
Eric Moore | df9e062 | 2007-01-29 09:46:21 -0700 | [diff] [blame] | 524 | VirtTarget *vtarget = NULL; |
Eric Moore | 547f9a2 | 2006-06-27 14:42:12 -0600 | [diff] [blame] | 525 | |
Eric Moore | df9e062 | 2007-01-29 09:46:21 -0700 | [diff] [blame] | 526 | shost_for_each_device(sdev, ioc->sh) { |
Kashyap, Desai | e7deff3 | 2009-05-29 16:46:07 +0530 | [diff] [blame^] | 527 | vdevice = sdev->hostdata; |
| 528 | if ((vdevice == NULL) || |
| 529 | (vdevice->vtarget == NULL)) |
Eric Moore | df9e062 | 2007-01-29 09:46:21 -0700 | [diff] [blame] | 530 | continue; |
Eric Moore | a69de50 | 2007-09-14 18:48:19 -0600 | [diff] [blame] | 531 | if (vdevice->vtarget->id == id && |
Kashyap, Desai | e7deff3 | 2009-05-29 16:46:07 +0530 | [diff] [blame^] | 532 | vdevice->vtarget->channel == channel) |
Eric Moore | a69de50 | 2007-09-14 18:48:19 -0600 | [diff] [blame] | 533 | vtarget = vdevice->vtarget; |
Eric Moore | 547f9a2 | 2006-06-27 14:42:12 -0600 | [diff] [blame] | 534 | } |
Eric Moore | df9e062 | 2007-01-29 09:46:21 -0700 | [diff] [blame] | 535 | return vtarget; |
| 536 | } |
| 537 | |
| 538 | /** |
| 539 | * mptsas_target_reset |
| 540 | * |
| 541 | * Issues TARGET_RESET to end device using handshaking method |
| 542 | * |
| 543 | * @ioc |
| 544 | * @channel |
| 545 | * @id |
| 546 | * |
| 547 | * Returns (1) success |
| 548 | * (0) failure |
| 549 | * |
| 550 | **/ |
| 551 | static int |
| 552 | mptsas_target_reset(MPT_ADAPTER *ioc, u8 channel, u8 id) |
| 553 | { |
| 554 | MPT_FRAME_HDR *mf; |
| 555 | SCSITaskMgmt_t *pScsiTm; |
| 556 | |
Kashyap, Desai | e7deff3 | 2009-05-29 16:46:07 +0530 | [diff] [blame^] | 557 | mf = mpt_get_msg_frame(mptsasDeviceResetCtx, ioc); |
| 558 | if (mf == NULL) { |
| 559 | dfailprintk(ioc, printk(MYIOC_s_WARN_FMT |
| 560 | "%s, no msg frames @%d!!\n", |
| 561 | ioc->name, __func__, __LINE__)); |
Eric Moore | df9e062 | 2007-01-29 09:46:21 -0700 | [diff] [blame] | 562 | return 0; |
| 563 | } |
| 564 | |
| 565 | /* Format the Request |
| 566 | */ |
| 567 | pScsiTm = (SCSITaskMgmt_t *) mf; |
| 568 | memset (pScsiTm, 0, sizeof(SCSITaskMgmt_t)); |
| 569 | pScsiTm->TargetID = id; |
| 570 | pScsiTm->Bus = channel; |
| 571 | pScsiTm->Function = MPI_FUNCTION_SCSI_TASK_MGMT; |
| 572 | pScsiTm->TaskType = MPI_SCSITASKMGMT_TASKTYPE_TARGET_RESET; |
| 573 | pScsiTm->MsgFlags = MPI_SCSITASKMGMT_MSGFLAGS_LIPRESET_RESET_OPTION; |
| 574 | |
Prakash, Sathya | d6ecdd6 | 2007-07-24 15:47:41 +0530 | [diff] [blame] | 575 | DBG_DUMP_TM_REQUEST_FRAME(ioc, (u32 *)mf); |
Eric Moore | df9e062 | 2007-01-29 09:46:21 -0700 | [diff] [blame] | 576 | |
Kashyap, Desai | e7deff3 | 2009-05-29 16:46:07 +0530 | [diff] [blame^] | 577 | mpt_put_msg_frame_hi_pri(mptsasDeviceResetCtx, ioc, mf); |
Eric Moore | df9e062 | 2007-01-29 09:46:21 -0700 | [diff] [blame] | 578 | |
| 579 | return 1; |
| 580 | } |
| 581 | |
| 582 | /** |
| 583 | * mptsas_target_reset_queue |
| 584 | * |
| 585 | * Receive request for TARGET_RESET after recieving an firmware |
| 586 | * event NOT_RESPONDING_EVENT, then put command in link list |
| 587 | * and queue if task_queue already in use. |
| 588 | * |
| 589 | * @ioc |
| 590 | * @sas_event_data |
| 591 | * |
| 592 | **/ |
| 593 | static void |
| 594 | mptsas_target_reset_queue(MPT_ADAPTER *ioc, |
| 595 | EVENT_DATA_SAS_DEVICE_STATUS_CHANGE *sas_event_data) |
| 596 | { |
Eric Moore | e7eae9f | 2007-09-29 10:15:59 -0600 | [diff] [blame] | 597 | MPT_SCSI_HOST *hd = shost_priv(ioc->sh); |
Eric Moore | df9e062 | 2007-01-29 09:46:21 -0700 | [diff] [blame] | 598 | VirtTarget *vtarget = NULL; |
| 599 | struct mptsas_target_reset_event *target_reset_list; |
| 600 | u8 id, channel; |
| 601 | |
| 602 | id = sas_event_data->TargetID; |
| 603 | channel = sas_event_data->Bus; |
| 604 | |
| 605 | if (!(vtarget = mptsas_find_vtarget(ioc, channel, id))) |
| 606 | return; |
| 607 | |
| 608 | vtarget->deleted = 1; /* block IO */ |
| 609 | |
| 610 | target_reset_list = kzalloc(sizeof(*target_reset_list), |
| 611 | GFP_ATOMIC); |
| 612 | if (!target_reset_list) { |
Kashyap, Desai | e7deff3 | 2009-05-29 16:46:07 +0530 | [diff] [blame^] | 613 | dfailprintk(ioc, printk(MYIOC_s_WARN_FMT |
| 614 | "%s, failed to allocate mem @%d..!!\n", |
| 615 | ioc->name, __func__, __LINE__)); |
Eric Moore | df9e062 | 2007-01-29 09:46:21 -0700 | [diff] [blame] | 616 | return; |
| 617 | } |
| 618 | |
| 619 | memcpy(&target_reset_list->sas_event_data, sas_event_data, |
| 620 | sizeof(*sas_event_data)); |
| 621 | list_add_tail(&target_reset_list->list, &hd->target_reset_list); |
| 622 | |
Kashyap, Desai | e7deff3 | 2009-05-29 16:46:07 +0530 | [diff] [blame^] | 623 | target_reset_list->time_count = jiffies; |
Eric Moore | df9e062 | 2007-01-29 09:46:21 -0700 | [diff] [blame] | 624 | |
| 625 | if (mptsas_target_reset(ioc, channel, id)) { |
| 626 | target_reset_list->target_reset_issued = 1; |
Eric Moore | df9e062 | 2007-01-29 09:46:21 -0700 | [diff] [blame] | 627 | } |
| 628 | } |
| 629 | |
| 630 | /** |
Kashyap, Desai | e7deff3 | 2009-05-29 16:46:07 +0530 | [diff] [blame^] | 631 | * mptsas_taskmgmt_complete - Completion for TARGET_RESET after |
| 632 | * NOT_RESPONDING_EVENT, enable work queue to finish off removing device |
| 633 | * from upper layers. then send next TARGET_RESET in the queue. |
| 634 | * @ioc: Pointer to MPT_ADAPTER structure |
Eric Moore | df9e062 | 2007-01-29 09:46:21 -0700 | [diff] [blame] | 635 | * |
| 636 | **/ |
Kashyap, Desai | e7deff3 | 2009-05-29 16:46:07 +0530 | [diff] [blame^] | 637 | static int |
| 638 | 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] | 639 | { |
Eric Moore | e7eae9f | 2007-09-29 10:15:59 -0600 | [diff] [blame] | 640 | MPT_SCSI_HOST *hd = shost_priv(ioc->sh); |
Eric Moore | df9e062 | 2007-01-29 09:46:21 -0700 | [diff] [blame] | 641 | struct list_head *head = &hd->target_reset_list; |
Eric Moore | df9e062 | 2007-01-29 09:46:21 -0700 | [diff] [blame] | 642 | struct mptsas_hotplug_event *ev; |
| 643 | EVENT_DATA_SAS_DEVICE_STATUS_CHANGE *sas_event_data; |
| 644 | u8 id, channel; |
| 645 | __le64 sas_address; |
Kashyap, Desai | e7deff3 | 2009-05-29 16:46:07 +0530 | [diff] [blame^] | 646 | struct mptsas_target_reset_event *target_reset_list; |
| 647 | SCSITaskMgmtReply_t *pScsiTmReply; |
| 648 | |
| 649 | dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT "TaskMgmt completed: " |
| 650 | "(mf = %p, mr = %p)\n", ioc->name, mf, mr)); |
| 651 | |
| 652 | pScsiTmReply = (SCSITaskMgmtReply_t *)mr; |
| 653 | if (pScsiTmReply) { |
| 654 | dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT |
| 655 | "\tTaskMgmt completed: fw_channel = %d, fw_id = %d,\n" |
| 656 | "\ttask_type = 0x%02X, iocstatus = 0x%04X " |
| 657 | "loginfo = 0x%08X,\n\tresponse_code = 0x%02X, " |
| 658 | "term_cmnds = %d\n", ioc->name, |
| 659 | pScsiTmReply->Bus, pScsiTmReply->TargetID, |
| 660 | pScsiTmReply->TaskType, |
| 661 | le16_to_cpu(pScsiTmReply->IOCStatus), |
| 662 | le32_to_cpu(pScsiTmReply->IOCLogInfo), |
| 663 | pScsiTmReply->ResponseCode, |
| 664 | le32_to_cpu(pScsiTmReply->TerminationCount))); |
| 665 | |
| 666 | if (pScsiTmReply->ResponseCode) |
| 667 | mptscsih_taskmgmt_response_code(ioc, |
| 668 | pScsiTmReply->ResponseCode); |
| 669 | } |
| 670 | |
| 671 | if (pScsiTmReply && (pScsiTmReply->TaskType == |
| 672 | MPI_SCSITASKMGMT_TASKTYPE_QUERY_TASK || pScsiTmReply->TaskType == |
| 673 | MPI_SCSITASKMGMT_TASKTYPE_ABRT_TASK_SET)) { |
| 674 | ioc->taskmgmt_cmds.status |= MPT_MGMT_STATUS_COMMAND_GOOD; |
| 675 | ioc->taskmgmt_cmds.status |= MPT_MGMT_STATUS_RF_VALID; |
| 676 | memcpy(ioc->taskmgmt_cmds.reply, mr, |
| 677 | min(MPT_DEFAULT_FRAME_SIZE, 4 * mr->u.reply.MsgLength)); |
| 678 | if (ioc->taskmgmt_cmds.status & MPT_MGMT_STATUS_PENDING) { |
| 679 | ioc->taskmgmt_cmds.status &= ~MPT_MGMT_STATUS_PENDING; |
| 680 | complete(&ioc->taskmgmt_cmds.done); |
| 681 | return 1; |
| 682 | } |
| 683 | return 0; |
| 684 | } |
| 685 | |
| 686 | mpt_clear_taskmgmt_in_progress_flag(ioc); |
Eric Moore | df9e062 | 2007-01-29 09:46:21 -0700 | [diff] [blame] | 687 | |
| 688 | if (list_empty(head)) |
Kashyap, Desai | e7deff3 | 2009-05-29 16:46:07 +0530 | [diff] [blame^] | 689 | return 1; |
Eric Moore | df9e062 | 2007-01-29 09:46:21 -0700 | [diff] [blame] | 690 | |
Kashyap, Desai | e7deff3 | 2009-05-29 16:46:07 +0530 | [diff] [blame^] | 691 | target_reset_list = list_entry(head->next, |
| 692 | struct mptsas_target_reset_event, list); |
| 693 | |
| 694 | dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT |
| 695 | "TaskMgmt: completed (%d seconds)\n", |
| 696 | ioc->name, jiffies_to_msecs(jiffies - |
| 697 | target_reset_list->time_count)/1000)); |
Eric Moore | df9e062 | 2007-01-29 09:46:21 -0700 | [diff] [blame] | 698 | |
| 699 | sas_event_data = &target_reset_list->sas_event_data; |
Kashyap, Desai | e7deff3 | 2009-05-29 16:46:07 +0530 | [diff] [blame^] | 700 | id = pScsiTmReply->TargetID; |
| 701 | channel = pScsiTmReply->Bus; |
| 702 | target_reset_list->time_count = jiffies; |
Eric Moore | df9e062 | 2007-01-29 09:46:21 -0700 | [diff] [blame] | 703 | |
| 704 | /* |
| 705 | * retry target reset |
| 706 | */ |
| 707 | if (!target_reset_list->target_reset_issued) { |
Kashyap, Desai | e7deff3 | 2009-05-29 16:46:07 +0530 | [diff] [blame^] | 708 | if (mptsas_target_reset(ioc, channel, id)) |
Eric Moore | df9e062 | 2007-01-29 09:46:21 -0700 | [diff] [blame] | 709 | target_reset_list->target_reset_issued = 1; |
Kashyap, Desai | e7deff3 | 2009-05-29 16:46:07 +0530 | [diff] [blame^] | 710 | return 1; |
Eric Moore | df9e062 | 2007-01-29 09:46:21 -0700 | [diff] [blame] | 711 | } |
| 712 | |
| 713 | /* |
| 714 | * enable work queue to remove device from upper layers |
| 715 | */ |
| 716 | list_del(&target_reset_list->list); |
| 717 | |
| 718 | ev = kzalloc(sizeof(*ev), GFP_ATOMIC); |
| 719 | if (!ev) { |
Prakash, Sathya | d6ecdd6 | 2007-07-24 15:47:41 +0530 | [diff] [blame] | 720 | dfailprintk(ioc, printk(MYIOC_s_WARN_FMT "%s, failed to allocate mem @%d..!!\n", |
Harvey Harrison | cadbd4a | 2008-07-03 23:47:27 -0700 | [diff] [blame] | 721 | ioc->name,__func__, __LINE__)); |
Kashyap, Desai | e7deff3 | 2009-05-29 16:46:07 +0530 | [diff] [blame^] | 722 | return 0; |
Eric Moore | df9e062 | 2007-01-29 09:46:21 -0700 | [diff] [blame] | 723 | } |
| 724 | |
| 725 | INIT_WORK(&ev->work, mptsas_hotplug_work); |
| 726 | ev->ioc = ioc; |
| 727 | ev->handle = le16_to_cpu(sas_event_data->DevHandle); |
| 728 | ev->parent_handle = |
| 729 | le16_to_cpu(sas_event_data->ParentDevHandle); |
| 730 | ev->channel = channel; |
| 731 | ev->id =id; |
| 732 | ev->phy_id = sas_event_data->PhyNum; |
| 733 | memcpy(&sas_address, &sas_event_data->SASAddress, |
| 734 | sizeof(__le64)); |
| 735 | ev->sas_address = le64_to_cpu(sas_address); |
| 736 | ev->device_info = le32_to_cpu(sas_event_data->DeviceInfo); |
| 737 | ev->event_type = MPTSAS_DEL_DEVICE; |
| 738 | schedule_work(&ev->work); |
| 739 | kfree(target_reset_list); |
| 740 | |
Kashyap, Desai | e7deff3 | 2009-05-29 16:46:07 +0530 | [diff] [blame^] | 741 | |
Eric Moore | df9e062 | 2007-01-29 09:46:21 -0700 | [diff] [blame] | 742 | /* |
| 743 | * issue target reset to next device in the queue |
| 744 | */ |
| 745 | |
| 746 | head = &hd->target_reset_list; |
| 747 | if (list_empty(head)) |
Kashyap, Desai | e7deff3 | 2009-05-29 16:46:07 +0530 | [diff] [blame^] | 748 | return 1; |
Eric Moore | df9e062 | 2007-01-29 09:46:21 -0700 | [diff] [blame] | 749 | |
| 750 | target_reset_list = list_entry(head->next, struct mptsas_target_reset_event, |
| 751 | list); |
| 752 | |
Kashyap, Desai | e7deff3 | 2009-05-29 16:46:07 +0530 | [diff] [blame^] | 753 | id = target_reset_list->sas_event_data.TargetID; |
| 754 | channel = target_reset_list->sas_event_data.Bus; |
| 755 | target_reset_list->time_count = jiffies; |
Eric Moore | df9e062 | 2007-01-29 09:46:21 -0700 | [diff] [blame] | 756 | |
Kashyap, Desai | e7deff3 | 2009-05-29 16:46:07 +0530 | [diff] [blame^] | 757 | if (mptsas_target_reset(ioc, channel, id)) |
Eric Moore | df9e062 | 2007-01-29 09:46:21 -0700 | [diff] [blame] | 758 | target_reset_list->target_reset_issued = 1; |
Eric Moore | df9e062 | 2007-01-29 09:46:21 -0700 | [diff] [blame] | 759 | |
Kashyap, Desai | e7deff3 | 2009-05-29 16:46:07 +0530 | [diff] [blame^] | 760 | return 1; |
Eric Moore | df9e062 | 2007-01-29 09:46:21 -0700 | [diff] [blame] | 761 | } |
| 762 | |
| 763 | /** |
| 764 | * mptscsih_ioc_reset |
| 765 | * |
| 766 | * @ioc |
| 767 | * @reset_phase |
| 768 | * |
| 769 | **/ |
| 770 | static int |
| 771 | mptsas_ioc_reset(MPT_ADAPTER *ioc, int reset_phase) |
| 772 | { |
Judith Lebzelter | ba76ef2 | 2007-03-09 13:07:44 -0800 | [diff] [blame] | 773 | MPT_SCSI_HOST *hd; |
Eric Moore | df9e062 | 2007-01-29 09:46:21 -0700 | [diff] [blame] | 774 | struct mptsas_target_reset_event *target_reset_list, *n; |
| 775 | int rc; |
| 776 | |
| 777 | rc = mptscsih_ioc_reset(ioc, reset_phase); |
| 778 | |
| 779 | if (ioc->bus_type != SAS) |
| 780 | goto out; |
| 781 | |
| 782 | if (reset_phase != MPT_IOC_POST_RESET) |
| 783 | goto out; |
| 784 | |
Judith Lebzelter | ba76ef2 | 2007-03-09 13:07:44 -0800 | [diff] [blame] | 785 | if (!ioc->sh || !ioc->sh->hostdata) |
| 786 | goto out; |
Eric Moore | e7eae9f | 2007-09-29 10:15:59 -0600 | [diff] [blame] | 787 | hd = shost_priv(ioc->sh); |
Judith Lebzelter | ba76ef2 | 2007-03-09 13:07:44 -0800 | [diff] [blame] | 788 | if (!hd->ioc) |
Eric Moore | df9e062 | 2007-01-29 09:46:21 -0700 | [diff] [blame] | 789 | goto out; |
| 790 | |
| 791 | if (list_empty(&hd->target_reset_list)) |
| 792 | goto out; |
| 793 | |
| 794 | /* flush the target_reset_list */ |
| 795 | list_for_each_entry_safe(target_reset_list, n, |
| 796 | &hd->target_reset_list, list) { |
| 797 | list_del(&target_reset_list->list); |
| 798 | kfree(target_reset_list); |
| 799 | } |
| 800 | |
| 801 | out: |
| 802 | return rc; |
Eric Moore | 547f9a2 | 2006-06-27 14:42:12 -0600 | [diff] [blame] | 803 | } |
| 804 | |
Christoph Hellwig | e309444 | 2006-02-16 13:25:36 +0100 | [diff] [blame] | 805 | static int |
Moore, Eric | 5243543 | 2006-03-14 09:14:15 -0700 | [diff] [blame] | 806 | mptsas_sas_enclosure_pg0(MPT_ADAPTER *ioc, struct mptsas_enclosure *enclosure, |
Christoph Hellwig | e309444 | 2006-02-16 13:25:36 +0100 | [diff] [blame] | 807 | u32 form, u32 form_specific) |
| 808 | { |
| 809 | ConfigExtendedPageHeader_t hdr; |
| 810 | CONFIGPARMS cfg; |
| 811 | SasEnclosurePage0_t *buffer; |
| 812 | dma_addr_t dma_handle; |
| 813 | int error; |
| 814 | __le64 le_identifier; |
| 815 | |
| 816 | memset(&hdr, 0, sizeof(hdr)); |
| 817 | hdr.PageVersion = MPI_SASENCLOSURE0_PAGEVERSION; |
| 818 | hdr.PageNumber = 0; |
| 819 | hdr.PageType = MPI_CONFIG_PAGETYPE_EXTENDED; |
| 820 | hdr.ExtPageType = MPI_CONFIG_EXTPAGETYPE_ENCLOSURE; |
| 821 | |
| 822 | cfg.cfghdr.ehdr = &hdr; |
| 823 | cfg.physAddr = -1; |
| 824 | cfg.pageAddr = form + form_specific; |
| 825 | cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER; |
| 826 | cfg.dir = 0; /* read */ |
| 827 | cfg.timeout = 10; |
| 828 | |
| 829 | error = mpt_config(ioc, &cfg); |
| 830 | if (error) |
| 831 | goto out; |
| 832 | if (!hdr.ExtPageLength) { |
| 833 | error = -ENXIO; |
| 834 | goto out; |
| 835 | } |
| 836 | |
| 837 | buffer = pci_alloc_consistent(ioc->pcidev, hdr.ExtPageLength * 4, |
| 838 | &dma_handle); |
| 839 | if (!buffer) { |
| 840 | error = -ENOMEM; |
| 841 | goto out; |
| 842 | } |
| 843 | |
| 844 | cfg.physAddr = dma_handle; |
| 845 | cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT; |
| 846 | |
| 847 | error = mpt_config(ioc, &cfg); |
| 848 | if (error) |
| 849 | goto out_free_consistent; |
| 850 | |
| 851 | /* save config data */ |
| 852 | memcpy(&le_identifier, &buffer->EnclosureLogicalID, sizeof(__le64)); |
| 853 | enclosure->enclosure_logical_id = le64_to_cpu(le_identifier); |
| 854 | enclosure->enclosure_handle = le16_to_cpu(buffer->EnclosureHandle); |
| 855 | enclosure->flags = le16_to_cpu(buffer->Flags); |
| 856 | enclosure->num_slot = le16_to_cpu(buffer->NumSlots); |
| 857 | enclosure->start_slot = le16_to_cpu(buffer->StartSlot); |
| 858 | enclosure->start_id = buffer->StartTargetID; |
| 859 | enclosure->start_channel = buffer->StartBus; |
| 860 | enclosure->sep_id = buffer->SEPTargetID; |
| 861 | enclosure->sep_channel = buffer->SEPBus; |
| 862 | |
| 863 | out_free_consistent: |
| 864 | pci_free_consistent(ioc->pcidev, hdr.ExtPageLength * 4, |
| 865 | buffer, dma_handle); |
| 866 | out: |
| 867 | return error; |
| 868 | } |
Christoph Hellwig | b514112 | 2005-10-28 22:07:41 +0200 | [diff] [blame] | 869 | |
James Bottomley | f013db3 | 2006-03-18 14:54:36 -0600 | [diff] [blame] | 870 | static int |
| 871 | mptsas_slave_configure(struct scsi_device *sdev) |
| 872 | { |
Moore, Eric | 3c0c25b | 2006-04-13 16:08:17 -0600 | [diff] [blame] | 873 | |
James Bottomley | e8bf394 | 2006-07-11 17:49:34 -0400 | [diff] [blame] | 874 | if (sdev->channel == MPTSAS_RAID_CHANNEL) |
| 875 | goto out; |
James Bottomley | f013db3 | 2006-03-18 14:54:36 -0600 | [diff] [blame] | 876 | |
James Bottomley | e8bf394 | 2006-07-11 17:49:34 -0400 | [diff] [blame] | 877 | sas_read_port_mode_page(sdev); |
| 878 | |
| 879 | out: |
James Bottomley | f013db3 | 2006-03-18 14:54:36 -0600 | [diff] [blame] | 880 | return mptscsih_slave_configure(sdev); |
| 881 | } |
| 882 | |
Eric Moore | 547f9a2 | 2006-06-27 14:42:12 -0600 | [diff] [blame] | 883 | static int |
| 884 | mptsas_target_alloc(struct scsi_target *starget) |
| 885 | { |
| 886 | struct Scsi_Host *host = dev_to_shost(&starget->dev); |
Eric Moore | e7eae9f | 2007-09-29 10:15:59 -0600 | [diff] [blame] | 887 | MPT_SCSI_HOST *hd = shost_priv(host); |
Eric Moore | 547f9a2 | 2006-06-27 14:42:12 -0600 | [diff] [blame] | 888 | VirtTarget *vtarget; |
Eric Moore | 793955f | 2007-01-29 09:42:20 -0700 | [diff] [blame] | 889 | u8 id, channel; |
Eric Moore | 547f9a2 | 2006-06-27 14:42:12 -0600 | [diff] [blame] | 890 | struct sas_rphy *rphy; |
| 891 | struct mptsas_portinfo *p; |
| 892 | int i; |
Eric Moore | e80b002 | 2007-09-14 18:49:03 -0600 | [diff] [blame] | 893 | MPT_ADAPTER *ioc = hd->ioc; |
Eric Moore | 547f9a2 | 2006-06-27 14:42:12 -0600 | [diff] [blame] | 894 | |
| 895 | vtarget = kzalloc(sizeof(VirtTarget), GFP_KERNEL); |
| 896 | if (!vtarget) |
| 897 | return -ENOMEM; |
| 898 | |
| 899 | vtarget->starget = starget; |
Eric Moore | e80b002 | 2007-09-14 18:49:03 -0600 | [diff] [blame] | 900 | vtarget->ioc_id = ioc->id; |
Eric Moore | 793955f | 2007-01-29 09:42:20 -0700 | [diff] [blame] | 901 | vtarget->tflags = MPT_TARGET_FLAGS_Q_YES; |
| 902 | id = starget->id; |
Eric Moore | 547f9a2 | 2006-06-27 14:42:12 -0600 | [diff] [blame] | 903 | channel = 0; |
| 904 | |
Eric Moore | 793955f | 2007-01-29 09:42:20 -0700 | [diff] [blame] | 905 | /* |
| 906 | * RAID volumes placed beyond the last expected port. |
| 907 | */ |
| 908 | if (starget->channel == MPTSAS_RAID_CHANNEL) { |
Eric Moore | e80b002 | 2007-09-14 18:49:03 -0600 | [diff] [blame] | 909 | for (i=0; i < ioc->raid_data.pIocPg2->NumActiveVolumes; i++) |
| 910 | if (id == ioc->raid_data.pIocPg2->RaidVolume[i].VolumeID) |
| 911 | channel = ioc->raid_data.pIocPg2->RaidVolume[i].VolumeBus; |
Eric Moore | 547f9a2 | 2006-06-27 14:42:12 -0600 | [diff] [blame] | 912 | goto out; |
Eric Moore | 793955f | 2007-01-29 09:42:20 -0700 | [diff] [blame] | 913 | } |
Eric Moore | 547f9a2 | 2006-06-27 14:42:12 -0600 | [diff] [blame] | 914 | |
| 915 | rphy = dev_to_rphy(starget->dev.parent); |
Eric Moore | e80b002 | 2007-09-14 18:49:03 -0600 | [diff] [blame] | 916 | mutex_lock(&ioc->sas_topology_mutex); |
| 917 | list_for_each_entry(p, &ioc->sas_topology, list) { |
Eric Moore | 547f9a2 | 2006-06-27 14:42:12 -0600 | [diff] [blame] | 918 | for (i = 0; i < p->num_phys; i++) { |
| 919 | if (p->phy_info[i].attached.sas_address != |
| 920 | rphy->identify.sas_address) |
| 921 | continue; |
Eric Moore | 793955f | 2007-01-29 09:42:20 -0700 | [diff] [blame] | 922 | id = p->phy_info[i].attached.id; |
Eric Moore | 547f9a2 | 2006-06-27 14:42:12 -0600 | [diff] [blame] | 923 | channel = p->phy_info[i].attached.channel; |
| 924 | mptsas_set_starget(&p->phy_info[i], starget); |
| 925 | |
| 926 | /* |
| 927 | * Exposing hidden raid components |
| 928 | */ |
Eric Moore | e80b002 | 2007-09-14 18:49:03 -0600 | [diff] [blame] | 929 | if (mptscsih_is_phys_disk(ioc, channel, id)) { |
| 930 | id = mptscsih_raid_id_to_num(ioc, |
Eric Moore | 793955f | 2007-01-29 09:42:20 -0700 | [diff] [blame] | 931 | channel, id); |
Eric Moore | 547f9a2 | 2006-06-27 14:42:12 -0600 | [diff] [blame] | 932 | vtarget->tflags |= |
| 933 | MPT_TARGET_FLAGS_RAID_COMPONENT; |
Eric Moore | b506ade | 2007-01-29 09:45:37 -0700 | [diff] [blame] | 934 | p->phy_info[i].attached.phys_disk_num = id; |
Eric Moore | 547f9a2 | 2006-06-27 14:42:12 -0600 | [diff] [blame] | 935 | } |
Eric Moore | e80b002 | 2007-09-14 18:49:03 -0600 | [diff] [blame] | 936 | mutex_unlock(&ioc->sas_topology_mutex); |
Eric Moore | 547f9a2 | 2006-06-27 14:42:12 -0600 | [diff] [blame] | 937 | goto out; |
| 938 | } |
| 939 | } |
Eric Moore | e80b002 | 2007-09-14 18:49:03 -0600 | [diff] [blame] | 940 | mutex_unlock(&ioc->sas_topology_mutex); |
Eric Moore | 547f9a2 | 2006-06-27 14:42:12 -0600 | [diff] [blame] | 941 | |
| 942 | kfree(vtarget); |
| 943 | return -ENXIO; |
| 944 | |
| 945 | out: |
Eric Moore | 793955f | 2007-01-29 09:42:20 -0700 | [diff] [blame] | 946 | vtarget->id = id; |
| 947 | vtarget->channel = channel; |
Eric Moore | 547f9a2 | 2006-06-27 14:42:12 -0600 | [diff] [blame] | 948 | starget->hostdata = vtarget; |
| 949 | return 0; |
| 950 | } |
| 951 | |
| 952 | static void |
| 953 | mptsas_target_destroy(struct scsi_target *starget) |
| 954 | { |
| 955 | struct Scsi_Host *host = dev_to_shost(&starget->dev); |
Eric Moore | e7eae9f | 2007-09-29 10:15:59 -0600 | [diff] [blame] | 956 | MPT_SCSI_HOST *hd = shost_priv(host); |
Eric Moore | 547f9a2 | 2006-06-27 14:42:12 -0600 | [diff] [blame] | 957 | struct sas_rphy *rphy; |
| 958 | struct mptsas_portinfo *p; |
| 959 | int i; |
Eric Moore | e80b002 | 2007-09-14 18:49:03 -0600 | [diff] [blame] | 960 | MPT_ADAPTER *ioc = hd->ioc; |
Eric Moore | 547f9a2 | 2006-06-27 14:42:12 -0600 | [diff] [blame] | 961 | |
| 962 | if (!starget->hostdata) |
| 963 | return; |
| 964 | |
James Bottomley | e8bf394 | 2006-07-11 17:49:34 -0400 | [diff] [blame] | 965 | if (starget->channel == MPTSAS_RAID_CHANNEL) |
Eric Moore | 547f9a2 | 2006-06-27 14:42:12 -0600 | [diff] [blame] | 966 | goto out; |
| 967 | |
| 968 | rphy = dev_to_rphy(starget->dev.parent); |
Eric Moore | e80b002 | 2007-09-14 18:49:03 -0600 | [diff] [blame] | 969 | list_for_each_entry(p, &ioc->sas_topology, list) { |
Eric Moore | 547f9a2 | 2006-06-27 14:42:12 -0600 | [diff] [blame] | 970 | for (i = 0; i < p->num_phys; i++) { |
| 971 | if (p->phy_info[i].attached.sas_address != |
| 972 | rphy->identify.sas_address) |
| 973 | continue; |
| 974 | mptsas_set_starget(&p->phy_info[i], NULL); |
| 975 | goto out; |
| 976 | } |
| 977 | } |
| 978 | |
| 979 | out: |
| 980 | kfree(starget->hostdata); |
| 981 | starget->hostdata = NULL; |
| 982 | } |
| 983 | |
| 984 | |
Christoph Hellwig | 0c33b27 | 2005-09-09 16:27:19 +0200 | [diff] [blame] | 985 | static int |
Moore, Eric Dean | c7c8298 | 2005-11-16 18:54:25 -0700 | [diff] [blame] | 986 | mptsas_slave_alloc(struct scsi_device *sdev) |
Christoph Hellwig | 0c33b27 | 2005-09-09 16:27:19 +0200 | [diff] [blame] | 987 | { |
Moore, Eric Dean | c7c8298 | 2005-11-16 18:54:25 -0700 | [diff] [blame] | 988 | struct Scsi_Host *host = sdev->host; |
Eric Moore | e7eae9f | 2007-09-29 10:15:59 -0600 | [diff] [blame] | 989 | MPT_SCSI_HOST *hd = shost_priv(host); |
Christoph Hellwig | 0c33b27 | 2005-09-09 16:27:19 +0200 | [diff] [blame] | 990 | struct sas_rphy *rphy; |
| 991 | struct mptsas_portinfo *p; |
Eric Moore | a69de50 | 2007-09-14 18:48:19 -0600 | [diff] [blame] | 992 | VirtDevice *vdevice; |
Moore, Eric Dean | c7c8298 | 2005-11-16 18:54:25 -0700 | [diff] [blame] | 993 | struct scsi_target *starget; |
Eric Moore | 547f9a2 | 2006-06-27 14:42:12 -0600 | [diff] [blame] | 994 | int i; |
Eric Moore | e80b002 | 2007-09-14 18:49:03 -0600 | [diff] [blame] | 995 | MPT_ADAPTER *ioc = hd->ioc; |
Christoph Hellwig | 0c33b27 | 2005-09-09 16:27:19 +0200 | [diff] [blame] | 996 | |
Eric Moore | a69de50 | 2007-09-14 18:48:19 -0600 | [diff] [blame] | 997 | vdevice = kzalloc(sizeof(VirtDevice), GFP_KERNEL); |
| 998 | if (!vdevice) { |
Eric Moore | 547f9a2 | 2006-06-27 14:42:12 -0600 | [diff] [blame] | 999 | printk(MYIOC_s_ERR_FMT "slave_alloc kzalloc(%zd) FAILED!\n", |
Eric Moore | e80b002 | 2007-09-14 18:49:03 -0600 | [diff] [blame] | 1000 | ioc->name, sizeof(VirtDevice)); |
Christoph Hellwig | 0c33b27 | 2005-09-09 16:27:19 +0200 | [diff] [blame] | 1001 | return -ENOMEM; |
| 1002 | } |
Moore, Eric Dean | c7c8298 | 2005-11-16 18:54:25 -0700 | [diff] [blame] | 1003 | starget = scsi_target(sdev); |
Eric Moore | a69de50 | 2007-09-14 18:48:19 -0600 | [diff] [blame] | 1004 | vdevice->vtarget = starget->hostdata; |
Christoph Hellwig | 0c33b27 | 2005-09-09 16:27:19 +0200 | [diff] [blame] | 1005 | |
James Bottomley | e8bf394 | 2006-07-11 17:49:34 -0400 | [diff] [blame] | 1006 | if (sdev->channel == MPTSAS_RAID_CHANNEL) |
Moore, Eric | 816aa90 | 2006-01-13 16:25:20 -0700 | [diff] [blame] | 1007 | goto out; |
Moore, Eric | 816aa90 | 2006-01-13 16:25:20 -0700 | [diff] [blame] | 1008 | |
Moore, Eric Dean | c7c8298 | 2005-11-16 18:54:25 -0700 | [diff] [blame] | 1009 | rphy = dev_to_rphy(sdev->sdev_target->dev.parent); |
Eric Moore | e80b002 | 2007-09-14 18:49:03 -0600 | [diff] [blame] | 1010 | mutex_lock(&ioc->sas_topology_mutex); |
| 1011 | list_for_each_entry(p, &ioc->sas_topology, list) { |
Christoph Hellwig | 0c33b27 | 2005-09-09 16:27:19 +0200 | [diff] [blame] | 1012 | for (i = 0; i < p->num_phys; i++) { |
Eric Moore | 547f9a2 | 2006-06-27 14:42:12 -0600 | [diff] [blame] | 1013 | if (p->phy_info[i].attached.sas_address != |
| 1014 | rphy->identify.sas_address) |
| 1015 | continue; |
Eric Moore | a69de50 | 2007-09-14 18:48:19 -0600 | [diff] [blame] | 1016 | vdevice->lun = sdev->lun; |
Eric Moore | 547f9a2 | 2006-06-27 14:42:12 -0600 | [diff] [blame] | 1017 | /* |
| 1018 | * Exposing hidden raid components |
| 1019 | */ |
Eric Moore | e80b002 | 2007-09-14 18:49:03 -0600 | [diff] [blame] | 1020 | if (mptscsih_is_phys_disk(ioc, |
Eric Moore | 793955f | 2007-01-29 09:42:20 -0700 | [diff] [blame] | 1021 | p->phy_info[i].attached.channel, |
| 1022 | p->phy_info[i].attached.id)) |
Eric Moore | 547f9a2 | 2006-06-27 14:42:12 -0600 | [diff] [blame] | 1023 | sdev->no_uld_attach = 1; |
Eric Moore | e80b002 | 2007-09-14 18:49:03 -0600 | [diff] [blame] | 1024 | mutex_unlock(&ioc->sas_topology_mutex); |
Eric Moore | 547f9a2 | 2006-06-27 14:42:12 -0600 | [diff] [blame] | 1025 | goto out; |
Christoph Hellwig | 0c33b27 | 2005-09-09 16:27:19 +0200 | [diff] [blame] | 1026 | } |
| 1027 | } |
Eric Moore | e80b002 | 2007-09-14 18:49:03 -0600 | [diff] [blame] | 1028 | mutex_unlock(&ioc->sas_topology_mutex); |
Christoph Hellwig | 0c33b27 | 2005-09-09 16:27:19 +0200 | [diff] [blame] | 1029 | |
Eric Moore | a69de50 | 2007-09-14 18:48:19 -0600 | [diff] [blame] | 1030 | kfree(vdevice); |
Christoph Hellwig | 23f236e | 2006-01-30 19:00:43 +0100 | [diff] [blame] | 1031 | return -ENXIO; |
Christoph Hellwig | 0c33b27 | 2005-09-09 16:27:19 +0200 | [diff] [blame] | 1032 | |
| 1033 | out: |
Eric Moore | a69de50 | 2007-09-14 18:48:19 -0600 | [diff] [blame] | 1034 | vdevice->vtarget->num_luns++; |
| 1035 | sdev->hostdata = vdevice; |
Christoph Hellwig | 0c33b27 | 2005-09-09 16:27:19 +0200 | [diff] [blame] | 1036 | return 0; |
| 1037 | } |
| 1038 | |
Eric Moore | 547f9a2 | 2006-06-27 14:42:12 -0600 | [diff] [blame] | 1039 | static int |
| 1040 | mptsas_qcmd(struct scsi_cmnd *SCpnt, void (*done)(struct scsi_cmnd *)) |
Christoph Hellwig | 9a28f49a | 2006-01-13 18:04:41 +0100 | [diff] [blame] | 1041 | { |
Kashyap, Desai | 7b5a65b | 2009-05-29 16:38:14 +0530 | [diff] [blame] | 1042 | MPT_SCSI_HOST *hd; |
| 1043 | MPT_ADAPTER *ioc; |
Eric Moore | a69de50 | 2007-09-14 18:48:19 -0600 | [diff] [blame] | 1044 | VirtDevice *vdevice = SCpnt->device->hostdata; |
Christoph Hellwig | 9a28f49a | 2006-01-13 18:04:41 +0100 | [diff] [blame] | 1045 | |
Eric Moore | a69de50 | 2007-09-14 18:48:19 -0600 | [diff] [blame] | 1046 | if (!vdevice || !vdevice->vtarget || vdevice->vtarget->deleted) { |
Eric Moore | 547f9a2 | 2006-06-27 14:42:12 -0600 | [diff] [blame] | 1047 | SCpnt->result = DID_NO_CONNECT << 16; |
| 1048 | done(SCpnt); |
| 1049 | return 0; |
Moore, Eric | 7d3eecf | 2006-01-25 18:05:12 -0700 | [diff] [blame] | 1050 | } |
Eric Moore | 547f9a2 | 2006-06-27 14:42:12 -0600 | [diff] [blame] | 1051 | |
Kashyap, Desai | 7b5a65b | 2009-05-29 16:38:14 +0530 | [diff] [blame] | 1052 | hd = shost_priv(SCpnt->device->host); |
| 1053 | ioc = hd->ioc; |
| 1054 | |
| 1055 | if (ioc->sas_discovery_quiesce_io) |
| 1056 | return SCSI_MLQUEUE_HOST_BUSY; |
| 1057 | |
Eric Moore | 793955f | 2007-01-29 09:42:20 -0700 | [diff] [blame] | 1058 | // scsi_print_command(SCpnt); |
| 1059 | |
Eric Moore | 547f9a2 | 2006-06-27 14:42:12 -0600 | [diff] [blame] | 1060 | return mptscsih_qcmd(SCpnt,done); |
Christoph Hellwig | 9a28f49a | 2006-01-13 18:04:41 +0100 | [diff] [blame] | 1061 | } |
| 1062 | |
Eric Moore | 547f9a2 | 2006-06-27 14:42:12 -0600 | [diff] [blame] | 1063 | |
Christoph Hellwig | 0c33b27 | 2005-09-09 16:27:19 +0200 | [diff] [blame] | 1064 | static struct scsi_host_template mptsas_driver_template = { |
Moore, Eric Dean | f78496d | 2005-11-16 18:54:14 -0700 | [diff] [blame] | 1065 | .module = THIS_MODULE, |
Christoph Hellwig | 0c33b27 | 2005-09-09 16:27:19 +0200 | [diff] [blame] | 1066 | .proc_name = "mptsas", |
| 1067 | .proc_info = mptscsih_proc_info, |
| 1068 | .name = "MPT SPI Host", |
| 1069 | .info = mptscsih_info, |
Eric Moore | 547f9a2 | 2006-06-27 14:42:12 -0600 | [diff] [blame] | 1070 | .queuecommand = mptsas_qcmd, |
| 1071 | .target_alloc = mptsas_target_alloc, |
Christoph Hellwig | 0c33b27 | 2005-09-09 16:27:19 +0200 | [diff] [blame] | 1072 | .slave_alloc = mptsas_slave_alloc, |
James Bottomley | f013db3 | 2006-03-18 14:54:36 -0600 | [diff] [blame] | 1073 | .slave_configure = mptsas_slave_configure, |
Eric Moore | 547f9a2 | 2006-06-27 14:42:12 -0600 | [diff] [blame] | 1074 | .target_destroy = mptsas_target_destroy, |
| 1075 | .slave_destroy = mptscsih_slave_destroy, |
Christoph Hellwig | 0c33b27 | 2005-09-09 16:27:19 +0200 | [diff] [blame] | 1076 | .change_queue_depth = mptscsih_change_queue_depth, |
| 1077 | .eh_abort_handler = mptscsih_abort, |
| 1078 | .eh_device_reset_handler = mptscsih_dev_reset, |
| 1079 | .eh_bus_reset_handler = mptscsih_bus_reset, |
| 1080 | .eh_host_reset_handler = mptscsih_host_reset, |
| 1081 | .bios_param = mptscsih_bios_param, |
| 1082 | .can_queue = MPT_FC_CAN_QUEUE, |
| 1083 | .this_id = -1, |
| 1084 | .sg_tablesize = MPT_SCSI_SG_DEPTH, |
| 1085 | .max_sectors = 8192, |
| 1086 | .cmd_per_lun = 7, |
| 1087 | .use_clustering = ENABLE_CLUSTERING, |
Prakash, Sathya | edb9068 | 2007-07-17 14:39:14 +0530 | [diff] [blame] | 1088 | .shost_attrs = mptscsih_host_attrs, |
Christoph Hellwig | 0c33b27 | 2005-09-09 16:27:19 +0200 | [diff] [blame] | 1089 | }; |
| 1090 | |
Christoph Hellwig | b514112 | 2005-10-28 22:07:41 +0200 | [diff] [blame] | 1091 | static int mptsas_get_linkerrors(struct sas_phy *phy) |
| 1092 | { |
| 1093 | MPT_ADAPTER *ioc = phy_to_ioc(phy); |
| 1094 | ConfigExtendedPageHeader_t hdr; |
| 1095 | CONFIGPARMS cfg; |
| 1096 | SasPhyPage1_t *buffer; |
| 1097 | dma_addr_t dma_handle; |
| 1098 | int error; |
| 1099 | |
James Bottomley | f4ad7b5 | 2006-08-25 13:48:18 -0500 | [diff] [blame] | 1100 | /* FIXME: only have link errors on local phys */ |
| 1101 | if (!scsi_is_sas_phy_local(phy)) |
| 1102 | return -EINVAL; |
| 1103 | |
Christoph Hellwig | b514112 | 2005-10-28 22:07:41 +0200 | [diff] [blame] | 1104 | hdr.PageVersion = MPI_SASPHY1_PAGEVERSION; |
| 1105 | hdr.ExtPageLength = 0; |
| 1106 | hdr.PageNumber = 1 /* page number 1*/; |
| 1107 | hdr.Reserved1 = 0; |
| 1108 | hdr.Reserved2 = 0; |
| 1109 | hdr.PageType = MPI_CONFIG_PAGETYPE_EXTENDED; |
| 1110 | hdr.ExtPageType = MPI_CONFIG_EXTPAGETYPE_SAS_PHY; |
| 1111 | |
| 1112 | cfg.cfghdr.ehdr = &hdr; |
| 1113 | cfg.physAddr = -1; |
| 1114 | cfg.pageAddr = phy->identify.phy_identifier; |
| 1115 | cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER; |
| 1116 | cfg.dir = 0; /* read */ |
| 1117 | cfg.timeout = 10; |
| 1118 | |
| 1119 | error = mpt_config(ioc, &cfg); |
| 1120 | if (error) |
| 1121 | return error; |
| 1122 | if (!hdr.ExtPageLength) |
| 1123 | return -ENXIO; |
| 1124 | |
| 1125 | buffer = pci_alloc_consistent(ioc->pcidev, hdr.ExtPageLength * 4, |
| 1126 | &dma_handle); |
| 1127 | if (!buffer) |
| 1128 | return -ENOMEM; |
| 1129 | |
| 1130 | cfg.physAddr = dma_handle; |
| 1131 | cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT; |
| 1132 | |
| 1133 | error = mpt_config(ioc, &cfg); |
| 1134 | if (error) |
| 1135 | goto out_free_consistent; |
| 1136 | |
Prakash, Sathya | d6ecdd6 | 2007-07-24 15:47:41 +0530 | [diff] [blame] | 1137 | mptsas_print_phy_pg1(ioc, buffer); |
Christoph Hellwig | b514112 | 2005-10-28 22:07:41 +0200 | [diff] [blame] | 1138 | |
| 1139 | phy->invalid_dword_count = le32_to_cpu(buffer->InvalidDwordCount); |
| 1140 | phy->running_disparity_error_count = |
| 1141 | le32_to_cpu(buffer->RunningDisparityErrorCount); |
| 1142 | phy->loss_of_dword_sync_count = |
| 1143 | le32_to_cpu(buffer->LossDwordSynchCount); |
| 1144 | phy->phy_reset_problem_count = |
| 1145 | le32_to_cpu(buffer->PhyResetProblemCount); |
| 1146 | |
| 1147 | out_free_consistent: |
| 1148 | pci_free_consistent(ioc->pcidev, hdr.ExtPageLength * 4, |
| 1149 | buffer, dma_handle); |
| 1150 | return error; |
| 1151 | } |
| 1152 | |
Christoph Hellwig | da4fa65 | 2005-10-19 20:01:42 +0200 | [diff] [blame] | 1153 | static int mptsas_mgmt_done(MPT_ADAPTER *ioc, MPT_FRAME_HDR *req, |
| 1154 | MPT_FRAME_HDR *reply) |
| 1155 | { |
Kashyap, Desai | f0f09d3 | 2009-05-29 16:40:57 +0530 | [diff] [blame] | 1156 | ioc->sas_mgmt.status |= MPT_MGMT_STATUS_COMMAND_GOOD; |
Christoph Hellwig | da4fa65 | 2005-10-19 20:01:42 +0200 | [diff] [blame] | 1157 | if (reply != NULL) { |
Kashyap, Desai | f0f09d3 | 2009-05-29 16:40:57 +0530 | [diff] [blame] | 1158 | ioc->sas_mgmt.status |= MPT_MGMT_STATUS_RF_VALID; |
Christoph Hellwig | da4fa65 | 2005-10-19 20:01:42 +0200 | [diff] [blame] | 1159 | memcpy(ioc->sas_mgmt.reply, reply, |
| 1160 | min(ioc->reply_sz, 4 * reply->u.reply.MsgLength)); |
| 1161 | } |
| 1162 | complete(&ioc->sas_mgmt.done); |
| 1163 | return 1; |
| 1164 | } |
| 1165 | |
| 1166 | static int mptsas_phy_reset(struct sas_phy *phy, int hard_reset) |
| 1167 | { |
| 1168 | MPT_ADAPTER *ioc = phy_to_ioc(phy); |
| 1169 | SasIoUnitControlRequest_t *req; |
| 1170 | SasIoUnitControlReply_t *reply; |
| 1171 | MPT_FRAME_HDR *mf; |
| 1172 | MPIHeader_t *hdr; |
| 1173 | unsigned long timeleft; |
| 1174 | int error = -ERESTARTSYS; |
| 1175 | |
James Bottomley | f4ad7b5 | 2006-08-25 13:48:18 -0500 | [diff] [blame] | 1176 | /* FIXME: fusion doesn't allow non-local phy reset */ |
| 1177 | if (!scsi_is_sas_phy_local(phy)) |
| 1178 | return -EINVAL; |
| 1179 | |
Christoph Hellwig | da4fa65 | 2005-10-19 20:01:42 +0200 | [diff] [blame] | 1180 | /* not implemented for expanders */ |
| 1181 | if (phy->identify.target_port_protocols & SAS_PROTOCOL_SMP) |
| 1182 | return -ENXIO; |
| 1183 | |
Christoph Hellwig | eeb846c | 2006-01-13 18:27:11 +0100 | [diff] [blame] | 1184 | if (mutex_lock_interruptible(&ioc->sas_mgmt.mutex)) |
Christoph Hellwig | da4fa65 | 2005-10-19 20:01:42 +0200 | [diff] [blame] | 1185 | goto out; |
| 1186 | |
| 1187 | mf = mpt_get_msg_frame(mptsasMgmtCtx, ioc); |
| 1188 | if (!mf) { |
| 1189 | error = -ENOMEM; |
| 1190 | goto out_unlock; |
| 1191 | } |
| 1192 | |
| 1193 | hdr = (MPIHeader_t *) mf; |
| 1194 | req = (SasIoUnitControlRequest_t *)mf; |
| 1195 | memset(req, 0, sizeof(SasIoUnitControlRequest_t)); |
| 1196 | req->Function = MPI_FUNCTION_SAS_IO_UNIT_CONTROL; |
| 1197 | req->MsgContext = hdr->MsgContext; |
| 1198 | req->Operation = hard_reset ? |
| 1199 | MPI_SAS_OP_PHY_HARD_RESET : MPI_SAS_OP_PHY_LINK_RESET; |
| 1200 | req->PhyNum = phy->identify.phy_identifier; |
| 1201 | |
| 1202 | mpt_put_msg_frame(mptsasMgmtCtx, ioc, mf); |
| 1203 | |
| 1204 | timeleft = wait_for_completion_timeout(&ioc->sas_mgmt.done, |
| 1205 | 10 * HZ); |
| 1206 | if (!timeleft) { |
| 1207 | /* On timeout reset the board */ |
| 1208 | mpt_free_msg_frame(ioc, mf); |
| 1209 | mpt_HardResetHandler(ioc, CAN_SLEEP); |
| 1210 | error = -ETIMEDOUT; |
| 1211 | goto out_unlock; |
| 1212 | } |
| 1213 | |
| 1214 | /* a reply frame is expected */ |
| 1215 | if ((ioc->sas_mgmt.status & |
Kashyap, Desai | f0f09d3 | 2009-05-29 16:40:57 +0530 | [diff] [blame] | 1216 | MPT_MGMT_STATUS_RF_VALID) == 0) { |
Christoph Hellwig | da4fa65 | 2005-10-19 20:01:42 +0200 | [diff] [blame] | 1217 | error = -ENXIO; |
| 1218 | goto out_unlock; |
| 1219 | } |
| 1220 | |
| 1221 | /* process the completed Reply Message Frame */ |
| 1222 | reply = (SasIoUnitControlReply_t *)ioc->sas_mgmt.reply; |
| 1223 | if (reply->IOCStatus != MPI_IOCSTATUS_SUCCESS) { |
Eric Moore | 29dd360 | 2007-09-14 18:46:51 -0600 | [diff] [blame] | 1224 | 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] | 1225 | ioc->name, __func__, reply->IOCStatus, reply->IOCLogInfo); |
Christoph Hellwig | da4fa65 | 2005-10-19 20:01:42 +0200 | [diff] [blame] | 1226 | error = -ENXIO; |
| 1227 | goto out_unlock; |
| 1228 | } |
| 1229 | |
| 1230 | error = 0; |
| 1231 | |
| 1232 | out_unlock: |
Christoph Hellwig | eeb846c | 2006-01-13 18:27:11 +0100 | [diff] [blame] | 1233 | mutex_unlock(&ioc->sas_mgmt.mutex); |
Christoph Hellwig | da4fa65 | 2005-10-19 20:01:42 +0200 | [diff] [blame] | 1234 | out: |
| 1235 | return error; |
| 1236 | } |
Christoph Hellwig | b514112 | 2005-10-28 22:07:41 +0200 | [diff] [blame] | 1237 | |
Christoph Hellwig | e309444 | 2006-02-16 13:25:36 +0100 | [diff] [blame] | 1238 | static int |
| 1239 | mptsas_get_enclosure_identifier(struct sas_rphy *rphy, u64 *identifier) |
| 1240 | { |
| 1241 | MPT_ADAPTER *ioc = rphy_to_ioc(rphy); |
| 1242 | int i, error; |
| 1243 | struct mptsas_portinfo *p; |
| 1244 | struct mptsas_enclosure enclosure_info; |
| 1245 | u64 enclosure_handle; |
| 1246 | |
| 1247 | mutex_lock(&ioc->sas_topology_mutex); |
| 1248 | list_for_each_entry(p, &ioc->sas_topology, list) { |
| 1249 | for (i = 0; i < p->num_phys; i++) { |
| 1250 | if (p->phy_info[i].attached.sas_address == |
| 1251 | rphy->identify.sas_address) { |
| 1252 | enclosure_handle = p->phy_info[i]. |
| 1253 | attached.handle_enclosure; |
| 1254 | goto found_info; |
| 1255 | } |
| 1256 | } |
| 1257 | } |
| 1258 | mutex_unlock(&ioc->sas_topology_mutex); |
| 1259 | return -ENXIO; |
| 1260 | |
| 1261 | found_info: |
| 1262 | mutex_unlock(&ioc->sas_topology_mutex); |
| 1263 | memset(&enclosure_info, 0, sizeof(struct mptsas_enclosure)); |
Moore, Eric | 5243543 | 2006-03-14 09:14:15 -0700 | [diff] [blame] | 1264 | error = mptsas_sas_enclosure_pg0(ioc, &enclosure_info, |
Christoph Hellwig | e309444 | 2006-02-16 13:25:36 +0100 | [diff] [blame] | 1265 | (MPI_SAS_ENCLOS_PGAD_FORM_HANDLE << |
| 1266 | MPI_SAS_ENCLOS_PGAD_FORM_SHIFT), enclosure_handle); |
| 1267 | if (!error) |
| 1268 | *identifier = enclosure_info.enclosure_logical_id; |
| 1269 | return error; |
| 1270 | } |
| 1271 | |
| 1272 | static int |
| 1273 | mptsas_get_bay_identifier(struct sas_rphy *rphy) |
| 1274 | { |
| 1275 | MPT_ADAPTER *ioc = rphy_to_ioc(rphy); |
| 1276 | struct mptsas_portinfo *p; |
| 1277 | int i, rc; |
| 1278 | |
| 1279 | mutex_lock(&ioc->sas_topology_mutex); |
| 1280 | list_for_each_entry(p, &ioc->sas_topology, list) { |
| 1281 | for (i = 0; i < p->num_phys; i++) { |
| 1282 | if (p->phy_info[i].attached.sas_address == |
| 1283 | rphy->identify.sas_address) { |
| 1284 | rc = p->phy_info[i].attached.slot; |
| 1285 | goto out; |
| 1286 | } |
| 1287 | } |
| 1288 | } |
| 1289 | rc = -ENXIO; |
| 1290 | out: |
| 1291 | mutex_unlock(&ioc->sas_topology_mutex); |
| 1292 | return rc; |
| 1293 | } |
| 1294 | |
FUJITA Tomonori | 159e36f | 2007-07-30 11:10:07 -0600 | [diff] [blame] | 1295 | static int mptsas_smp_handler(struct Scsi_Host *shost, struct sas_rphy *rphy, |
| 1296 | struct request *req) |
| 1297 | { |
| 1298 | MPT_ADAPTER *ioc = ((MPT_SCSI_HOST *) shost->hostdata)->ioc; |
| 1299 | MPT_FRAME_HDR *mf; |
| 1300 | SmpPassthroughRequest_t *smpreq; |
| 1301 | struct request *rsp = req->next_rq; |
| 1302 | int ret; |
| 1303 | int flagsLength; |
| 1304 | unsigned long timeleft; |
| 1305 | char *psge; |
| 1306 | dma_addr_t dma_addr_in = 0; |
| 1307 | dma_addr_t dma_addr_out = 0; |
| 1308 | u64 sas_address = 0; |
| 1309 | |
| 1310 | if (!rsp) { |
Eric Moore | 29dd360 | 2007-09-14 18:46:51 -0600 | [diff] [blame] | 1311 | 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] | 1312 | ioc->name, __func__); |
FUJITA Tomonori | 159e36f | 2007-07-30 11:10:07 -0600 | [diff] [blame] | 1313 | return -EINVAL; |
| 1314 | } |
| 1315 | |
| 1316 | /* do we need to support multiple segments? */ |
| 1317 | if (req->bio->bi_vcnt > 1 || rsp->bio->bi_vcnt > 1) { |
Eric Moore | 29dd360 | 2007-09-14 18:46:51 -0600 | [diff] [blame] | 1318 | 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] | 1319 | ioc->name, __func__, req->bio->bi_vcnt, req->data_len, |
Eric Moore | 29dd360 | 2007-09-14 18:46:51 -0600 | [diff] [blame] | 1320 | rsp->bio->bi_vcnt, rsp->data_len); |
FUJITA Tomonori | 159e36f | 2007-07-30 11:10:07 -0600 | [diff] [blame] | 1321 | return -EINVAL; |
| 1322 | } |
| 1323 | |
| 1324 | ret = mutex_lock_interruptible(&ioc->sas_mgmt.mutex); |
| 1325 | if (ret) |
| 1326 | goto out; |
| 1327 | |
| 1328 | mf = mpt_get_msg_frame(mptsasMgmtCtx, ioc); |
| 1329 | if (!mf) { |
| 1330 | ret = -ENOMEM; |
| 1331 | goto out_unlock; |
| 1332 | } |
| 1333 | |
| 1334 | smpreq = (SmpPassthroughRequest_t *)mf; |
| 1335 | memset(smpreq, 0, sizeof(*smpreq)); |
| 1336 | |
| 1337 | smpreq->RequestDataLength = cpu_to_le16(req->data_len - 4); |
| 1338 | smpreq->Function = MPI_FUNCTION_SMP_PASSTHROUGH; |
| 1339 | |
| 1340 | if (rphy) |
| 1341 | sas_address = rphy->identify.sas_address; |
| 1342 | else { |
| 1343 | struct mptsas_portinfo *port_info; |
| 1344 | |
| 1345 | mutex_lock(&ioc->sas_topology_mutex); |
Michael Reed | 7748369 | 2008-03-20 17:32:05 -0500 | [diff] [blame] | 1346 | port_info = mptsas_get_hba_portinfo(ioc); |
FUJITA Tomonori | 159e36f | 2007-07-30 11:10:07 -0600 | [diff] [blame] | 1347 | if (port_info && port_info->phy_info) |
| 1348 | sas_address = |
| 1349 | port_info->phy_info[0].phy->identify.sas_address; |
| 1350 | mutex_unlock(&ioc->sas_topology_mutex); |
| 1351 | } |
| 1352 | |
| 1353 | *((u64 *)&smpreq->SASAddress) = cpu_to_le64(sas_address); |
| 1354 | |
| 1355 | psge = (char *) |
| 1356 | (((int *) mf) + (offsetof(SmpPassthroughRequest_t, SGL) / 4)); |
| 1357 | |
| 1358 | /* request */ |
| 1359 | flagsLength = (MPI_SGE_FLAGS_SIMPLE_ELEMENT | |
| 1360 | MPI_SGE_FLAGS_END_OF_BUFFER | |
Kashyap, Desai | 14d0f0b | 2009-05-29 16:37:04 +0530 | [diff] [blame] | 1361 | MPI_SGE_FLAGS_DIRECTION) |
| 1362 | << MPI_SGE_FLAGS_SHIFT; |
FUJITA Tomonori | 159e36f | 2007-07-30 11:10:07 -0600 | [diff] [blame] | 1363 | flagsLength |= (req->data_len - 4); |
| 1364 | |
| 1365 | dma_addr_out = pci_map_single(ioc->pcidev, bio_data(req->bio), |
| 1366 | req->data_len, PCI_DMA_BIDIRECTIONAL); |
| 1367 | if (!dma_addr_out) |
| 1368 | goto put_mf; |
Kashyap, Desai | 14d0f0b | 2009-05-29 16:37:04 +0530 | [diff] [blame] | 1369 | ioc->add_sge(psge, flagsLength, dma_addr_out); |
FUJITA Tomonori | 159e36f | 2007-07-30 11:10:07 -0600 | [diff] [blame] | 1370 | psge += (sizeof(u32) + sizeof(dma_addr_t)); |
| 1371 | |
| 1372 | /* response */ |
| 1373 | flagsLength = MPT_SGE_FLAGS_SSIMPLE_READ; |
| 1374 | flagsLength |= rsp->data_len + 4; |
| 1375 | dma_addr_in = pci_map_single(ioc->pcidev, bio_data(rsp->bio), |
| 1376 | rsp->data_len, PCI_DMA_BIDIRECTIONAL); |
| 1377 | if (!dma_addr_in) |
| 1378 | goto unmap; |
Kashyap, Desai | 14d0f0b | 2009-05-29 16:37:04 +0530 | [diff] [blame] | 1379 | ioc->add_sge(psge, flagsLength, dma_addr_in); |
FUJITA Tomonori | 159e36f | 2007-07-30 11:10:07 -0600 | [diff] [blame] | 1380 | |
| 1381 | mpt_put_msg_frame(mptsasMgmtCtx, ioc, mf); |
| 1382 | |
| 1383 | timeleft = wait_for_completion_timeout(&ioc->sas_mgmt.done, 10 * HZ); |
| 1384 | if (!timeleft) { |
Harvey Harrison | cadbd4a | 2008-07-03 23:47:27 -0700 | [diff] [blame] | 1385 | printk(MYIOC_s_ERR_FMT "%s: smp timeout!\n", ioc->name, __func__); |
FUJITA Tomonori | 159e36f | 2007-07-30 11:10:07 -0600 | [diff] [blame] | 1386 | /* On timeout reset the board */ |
| 1387 | mpt_HardResetHandler(ioc, CAN_SLEEP); |
| 1388 | ret = -ETIMEDOUT; |
| 1389 | goto unmap; |
| 1390 | } |
| 1391 | mf = NULL; |
| 1392 | |
Kashyap, Desai | f0f09d3 | 2009-05-29 16:40:57 +0530 | [diff] [blame] | 1393 | if (ioc->sas_mgmt.status & MPT_MGMT_STATUS_RF_VALID) { |
FUJITA Tomonori | 159e36f | 2007-07-30 11:10:07 -0600 | [diff] [blame] | 1394 | SmpPassthroughReply_t *smprep; |
| 1395 | |
| 1396 | smprep = (SmpPassthroughReply_t *)ioc->sas_mgmt.reply; |
| 1397 | memcpy(req->sense, smprep, sizeof(*smprep)); |
| 1398 | req->sense_len = sizeof(*smprep); |
FUJITA Tomonori | 38b3167 | 2007-12-30 19:34:52 +0900 | [diff] [blame] | 1399 | req->data_len = 0; |
| 1400 | rsp->data_len -= smprep->ResponseDataLength; |
FUJITA Tomonori | 159e36f | 2007-07-30 11:10:07 -0600 | [diff] [blame] | 1401 | } else { |
Eric Moore | 29dd360 | 2007-09-14 18:46:51 -0600 | [diff] [blame] | 1402 | printk(MYIOC_s_ERR_FMT "%s: smp passthru reply failed to be returned\n", |
Harvey Harrison | cadbd4a | 2008-07-03 23:47:27 -0700 | [diff] [blame] | 1403 | ioc->name, __func__); |
FUJITA Tomonori | 159e36f | 2007-07-30 11:10:07 -0600 | [diff] [blame] | 1404 | ret = -ENXIO; |
| 1405 | } |
| 1406 | unmap: |
| 1407 | if (dma_addr_out) |
| 1408 | pci_unmap_single(ioc->pcidev, dma_addr_out, req->data_len, |
| 1409 | PCI_DMA_BIDIRECTIONAL); |
| 1410 | if (dma_addr_in) |
| 1411 | pci_unmap_single(ioc->pcidev, dma_addr_in, rsp->data_len, |
| 1412 | PCI_DMA_BIDIRECTIONAL); |
| 1413 | put_mf: |
| 1414 | if (mf) |
| 1415 | mpt_free_msg_frame(ioc, mf); |
| 1416 | out_unlock: |
| 1417 | mutex_unlock(&ioc->sas_mgmt.mutex); |
| 1418 | out: |
| 1419 | return ret; |
| 1420 | } |
| 1421 | |
Christoph Hellwig | 0c33b27 | 2005-09-09 16:27:19 +0200 | [diff] [blame] | 1422 | static struct sas_function_template mptsas_transport_functions = { |
Christoph Hellwig | b514112 | 2005-10-28 22:07:41 +0200 | [diff] [blame] | 1423 | .get_linkerrors = mptsas_get_linkerrors, |
Christoph Hellwig | e309444 | 2006-02-16 13:25:36 +0100 | [diff] [blame] | 1424 | .get_enclosure_identifier = mptsas_get_enclosure_identifier, |
| 1425 | .get_bay_identifier = mptsas_get_bay_identifier, |
Christoph Hellwig | da4fa65 | 2005-10-19 20:01:42 +0200 | [diff] [blame] | 1426 | .phy_reset = mptsas_phy_reset, |
FUJITA Tomonori | 159e36f | 2007-07-30 11:10:07 -0600 | [diff] [blame] | 1427 | .smp_handler = mptsas_smp_handler, |
Christoph Hellwig | 0c33b27 | 2005-09-09 16:27:19 +0200 | [diff] [blame] | 1428 | }; |
| 1429 | |
| 1430 | static struct scsi_transport_template *mptsas_transport_template; |
| 1431 | |
Christoph Hellwig | 0c33b27 | 2005-09-09 16:27:19 +0200 | [diff] [blame] | 1432 | static int |
| 1433 | mptsas_sas_io_unit_pg0(MPT_ADAPTER *ioc, struct mptsas_portinfo *port_info) |
| 1434 | { |
| 1435 | ConfigExtendedPageHeader_t hdr; |
| 1436 | CONFIGPARMS cfg; |
| 1437 | SasIOUnitPage0_t *buffer; |
| 1438 | dma_addr_t dma_handle; |
| 1439 | int error, i; |
| 1440 | |
| 1441 | hdr.PageVersion = MPI_SASIOUNITPAGE0_PAGEVERSION; |
| 1442 | hdr.ExtPageLength = 0; |
| 1443 | hdr.PageNumber = 0; |
| 1444 | hdr.Reserved1 = 0; |
| 1445 | hdr.Reserved2 = 0; |
| 1446 | hdr.PageType = MPI_CONFIG_PAGETYPE_EXTENDED; |
| 1447 | hdr.ExtPageType = MPI_CONFIG_EXTPAGETYPE_SAS_IO_UNIT; |
| 1448 | |
| 1449 | cfg.cfghdr.ehdr = &hdr; |
| 1450 | cfg.physAddr = -1; |
| 1451 | cfg.pageAddr = 0; |
| 1452 | cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER; |
| 1453 | cfg.dir = 0; /* read */ |
| 1454 | cfg.timeout = 10; |
| 1455 | |
| 1456 | error = mpt_config(ioc, &cfg); |
| 1457 | if (error) |
| 1458 | goto out; |
| 1459 | if (!hdr.ExtPageLength) { |
| 1460 | error = -ENXIO; |
| 1461 | goto out; |
| 1462 | } |
| 1463 | |
| 1464 | buffer = pci_alloc_consistent(ioc->pcidev, hdr.ExtPageLength * 4, |
| 1465 | &dma_handle); |
| 1466 | if (!buffer) { |
| 1467 | error = -ENOMEM; |
| 1468 | goto out; |
| 1469 | } |
| 1470 | |
| 1471 | cfg.physAddr = dma_handle; |
| 1472 | cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT; |
| 1473 | |
| 1474 | error = mpt_config(ioc, &cfg); |
| 1475 | if (error) |
| 1476 | goto out_free_consistent; |
| 1477 | |
| 1478 | port_info->num_phys = buffer->NumPhys; |
| 1479 | port_info->phy_info = kcalloc(port_info->num_phys, |
Eric Moore | 547f9a2 | 2006-06-27 14:42:12 -0600 | [diff] [blame] | 1480 | sizeof(*port_info->phy_info),GFP_KERNEL); |
Christoph Hellwig | 0c33b27 | 2005-09-09 16:27:19 +0200 | [diff] [blame] | 1481 | if (!port_info->phy_info) { |
| 1482 | error = -ENOMEM; |
| 1483 | goto out_free_consistent; |
| 1484 | } |
| 1485 | |
Prakash, Sathya | edb9068 | 2007-07-17 14:39:14 +0530 | [diff] [blame] | 1486 | ioc->nvdata_version_persistent = |
| 1487 | le16_to_cpu(buffer->NvdataVersionPersistent); |
| 1488 | ioc->nvdata_version_default = |
| 1489 | le16_to_cpu(buffer->NvdataVersionDefault); |
| 1490 | |
Christoph Hellwig | 0c33b27 | 2005-09-09 16:27:19 +0200 | [diff] [blame] | 1491 | for (i = 0; i < port_info->num_phys; i++) { |
Prakash, Sathya | d6ecdd6 | 2007-07-24 15:47:41 +0530 | [diff] [blame] | 1492 | mptsas_print_phy_data(ioc, &buffer->PhyData[i]); |
Christoph Hellwig | 0c33b27 | 2005-09-09 16:27:19 +0200 | [diff] [blame] | 1493 | port_info->phy_info[i].phy_id = i; |
| 1494 | port_info->phy_info[i].port_id = |
| 1495 | buffer->PhyData[i].Port; |
| 1496 | port_info->phy_info[i].negotiated_link_rate = |
| 1497 | buffer->PhyData[i].NegotiatedLinkRate; |
Eric Moore | 547f9a2 | 2006-06-27 14:42:12 -0600 | [diff] [blame] | 1498 | port_info->phy_info[i].portinfo = port_info; |
Eric Moore | 2ecce49 | 2007-01-29 09:47:08 -0700 | [diff] [blame] | 1499 | port_info->phy_info[i].handle = |
| 1500 | le16_to_cpu(buffer->PhyData[i].ControllerDevHandle); |
Christoph Hellwig | 0c33b27 | 2005-09-09 16:27:19 +0200 | [diff] [blame] | 1501 | } |
| 1502 | |
| 1503 | out_free_consistent: |
| 1504 | pci_free_consistent(ioc->pcidev, hdr.ExtPageLength * 4, |
| 1505 | buffer, dma_handle); |
| 1506 | out: |
| 1507 | return error; |
| 1508 | } |
| 1509 | |
| 1510 | static int |
Prakash, Sathya | edb9068 | 2007-07-17 14:39:14 +0530 | [diff] [blame] | 1511 | mptsas_sas_io_unit_pg1(MPT_ADAPTER *ioc) |
| 1512 | { |
| 1513 | ConfigExtendedPageHeader_t hdr; |
| 1514 | CONFIGPARMS cfg; |
| 1515 | SasIOUnitPage1_t *buffer; |
| 1516 | dma_addr_t dma_handle; |
| 1517 | int error; |
| 1518 | u16 device_missing_delay; |
| 1519 | |
| 1520 | memset(&hdr, 0, sizeof(ConfigExtendedPageHeader_t)); |
| 1521 | memset(&cfg, 0, sizeof(CONFIGPARMS)); |
| 1522 | |
| 1523 | cfg.cfghdr.ehdr = &hdr; |
| 1524 | cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER; |
| 1525 | cfg.timeout = 10; |
| 1526 | cfg.cfghdr.ehdr->PageType = MPI_CONFIG_PAGETYPE_EXTENDED; |
| 1527 | cfg.cfghdr.ehdr->ExtPageType = MPI_CONFIG_EXTPAGETYPE_SAS_IO_UNIT; |
| 1528 | cfg.cfghdr.ehdr->PageVersion = MPI_SASIOUNITPAGE1_PAGEVERSION; |
| 1529 | cfg.cfghdr.ehdr->PageNumber = 1; |
| 1530 | |
| 1531 | error = mpt_config(ioc, &cfg); |
| 1532 | if (error) |
| 1533 | goto out; |
| 1534 | if (!hdr.ExtPageLength) { |
| 1535 | error = -ENXIO; |
| 1536 | goto out; |
| 1537 | } |
| 1538 | |
| 1539 | buffer = pci_alloc_consistent(ioc->pcidev, hdr.ExtPageLength * 4, |
| 1540 | &dma_handle); |
| 1541 | if (!buffer) { |
| 1542 | error = -ENOMEM; |
| 1543 | goto out; |
| 1544 | } |
| 1545 | |
| 1546 | cfg.physAddr = dma_handle; |
| 1547 | cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT; |
| 1548 | |
| 1549 | error = mpt_config(ioc, &cfg); |
| 1550 | if (error) |
| 1551 | goto out_free_consistent; |
| 1552 | |
| 1553 | ioc->io_missing_delay = |
| 1554 | le16_to_cpu(buffer->IODeviceMissingDelay); |
| 1555 | device_missing_delay = le16_to_cpu(buffer->ReportDeviceMissingDelay); |
| 1556 | ioc->device_missing_delay = (device_missing_delay & MPI_SAS_IOUNIT1_REPORT_MISSING_UNIT_16) ? |
| 1557 | (device_missing_delay & MPI_SAS_IOUNIT1_REPORT_MISSING_TIMEOUT_MASK) * 16 : |
| 1558 | device_missing_delay & MPI_SAS_IOUNIT1_REPORT_MISSING_TIMEOUT_MASK; |
| 1559 | |
| 1560 | out_free_consistent: |
| 1561 | pci_free_consistent(ioc->pcidev, hdr.ExtPageLength * 4, |
| 1562 | buffer, dma_handle); |
| 1563 | out: |
| 1564 | return error; |
| 1565 | } |
| 1566 | |
| 1567 | static int |
Christoph Hellwig | 0c33b27 | 2005-09-09 16:27:19 +0200 | [diff] [blame] | 1568 | mptsas_sas_phy_pg0(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, |
| 1569 | u32 form, u32 form_specific) |
| 1570 | { |
| 1571 | ConfigExtendedPageHeader_t hdr; |
| 1572 | CONFIGPARMS cfg; |
| 1573 | SasPhyPage0_t *buffer; |
| 1574 | dma_addr_t dma_handle; |
| 1575 | int error; |
| 1576 | |
| 1577 | hdr.PageVersion = MPI_SASPHY0_PAGEVERSION; |
| 1578 | hdr.ExtPageLength = 0; |
| 1579 | hdr.PageNumber = 0; |
| 1580 | hdr.Reserved1 = 0; |
| 1581 | hdr.Reserved2 = 0; |
| 1582 | hdr.PageType = MPI_CONFIG_PAGETYPE_EXTENDED; |
| 1583 | hdr.ExtPageType = MPI_CONFIG_EXTPAGETYPE_SAS_PHY; |
| 1584 | |
| 1585 | cfg.cfghdr.ehdr = &hdr; |
| 1586 | cfg.dir = 0; /* read */ |
| 1587 | cfg.timeout = 10; |
| 1588 | |
| 1589 | /* Get Phy Pg 0 for each Phy. */ |
| 1590 | cfg.physAddr = -1; |
| 1591 | cfg.pageAddr = form + form_specific; |
| 1592 | cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER; |
| 1593 | |
| 1594 | error = mpt_config(ioc, &cfg); |
| 1595 | if (error) |
| 1596 | goto out; |
| 1597 | |
| 1598 | if (!hdr.ExtPageLength) { |
| 1599 | error = -ENXIO; |
| 1600 | goto out; |
| 1601 | } |
| 1602 | |
| 1603 | buffer = pci_alloc_consistent(ioc->pcidev, hdr.ExtPageLength * 4, |
| 1604 | &dma_handle); |
| 1605 | if (!buffer) { |
| 1606 | error = -ENOMEM; |
| 1607 | goto out; |
| 1608 | } |
| 1609 | |
| 1610 | cfg.physAddr = dma_handle; |
| 1611 | cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT; |
| 1612 | |
| 1613 | error = mpt_config(ioc, &cfg); |
| 1614 | if (error) |
| 1615 | goto out_free_consistent; |
| 1616 | |
Prakash, Sathya | d6ecdd6 | 2007-07-24 15:47:41 +0530 | [diff] [blame] | 1617 | mptsas_print_phy_pg0(ioc, buffer); |
Christoph Hellwig | 0c33b27 | 2005-09-09 16:27:19 +0200 | [diff] [blame] | 1618 | |
| 1619 | phy_info->hw_link_rate = buffer->HwLinkRate; |
| 1620 | phy_info->programmed_link_rate = buffer->ProgrammedLinkRate; |
| 1621 | phy_info->identify.handle = le16_to_cpu(buffer->OwnerDevHandle); |
| 1622 | phy_info->attached.handle = le16_to_cpu(buffer->AttachedDevHandle); |
| 1623 | |
| 1624 | out_free_consistent: |
| 1625 | pci_free_consistent(ioc->pcidev, hdr.ExtPageLength * 4, |
| 1626 | buffer, dma_handle); |
| 1627 | out: |
| 1628 | return error; |
| 1629 | } |
| 1630 | |
| 1631 | static int |
| 1632 | mptsas_sas_device_pg0(MPT_ADAPTER *ioc, struct mptsas_devinfo *device_info, |
| 1633 | u32 form, u32 form_specific) |
| 1634 | { |
| 1635 | ConfigExtendedPageHeader_t hdr; |
| 1636 | CONFIGPARMS cfg; |
| 1637 | SasDevicePage0_t *buffer; |
| 1638 | dma_addr_t dma_handle; |
| 1639 | __le64 sas_address; |
Moore, Eric | bd23e94 | 2006-04-17 12:43:04 -0600 | [diff] [blame] | 1640 | int error=0; |
| 1641 | |
| 1642 | if (ioc->sas_discovery_runtime && |
| 1643 | mptsas_is_end_device(device_info)) |
| 1644 | goto out; |
Christoph Hellwig | 0c33b27 | 2005-09-09 16:27:19 +0200 | [diff] [blame] | 1645 | |
| 1646 | hdr.PageVersion = MPI_SASDEVICE0_PAGEVERSION; |
| 1647 | hdr.ExtPageLength = 0; |
| 1648 | hdr.PageNumber = 0; |
| 1649 | hdr.Reserved1 = 0; |
| 1650 | hdr.Reserved2 = 0; |
| 1651 | hdr.PageType = MPI_CONFIG_PAGETYPE_EXTENDED; |
| 1652 | hdr.ExtPageType = MPI_CONFIG_EXTPAGETYPE_SAS_DEVICE; |
| 1653 | |
| 1654 | cfg.cfghdr.ehdr = &hdr; |
| 1655 | cfg.pageAddr = form + form_specific; |
| 1656 | cfg.physAddr = -1; |
| 1657 | cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER; |
| 1658 | cfg.dir = 0; /* read */ |
| 1659 | cfg.timeout = 10; |
| 1660 | |
Moore, Eric | db9c917 | 2006-03-14 09:14:18 -0700 | [diff] [blame] | 1661 | memset(device_info, 0, sizeof(struct mptsas_devinfo)); |
Christoph Hellwig | 0c33b27 | 2005-09-09 16:27:19 +0200 | [diff] [blame] | 1662 | error = mpt_config(ioc, &cfg); |
| 1663 | if (error) |
| 1664 | goto out; |
| 1665 | if (!hdr.ExtPageLength) { |
| 1666 | error = -ENXIO; |
| 1667 | goto out; |
| 1668 | } |
| 1669 | |
| 1670 | buffer = pci_alloc_consistent(ioc->pcidev, hdr.ExtPageLength * 4, |
| 1671 | &dma_handle); |
| 1672 | if (!buffer) { |
| 1673 | error = -ENOMEM; |
| 1674 | goto out; |
| 1675 | } |
| 1676 | |
| 1677 | cfg.physAddr = dma_handle; |
| 1678 | cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT; |
| 1679 | |
| 1680 | error = mpt_config(ioc, &cfg); |
| 1681 | if (error) |
| 1682 | goto out_free_consistent; |
| 1683 | |
Prakash, Sathya | d6ecdd6 | 2007-07-24 15:47:41 +0530 | [diff] [blame] | 1684 | mptsas_print_device_pg0(ioc, buffer); |
Christoph Hellwig | 0c33b27 | 2005-09-09 16:27:19 +0200 | [diff] [blame] | 1685 | |
| 1686 | device_info->handle = le16_to_cpu(buffer->DevHandle); |
Moore, Eric | c73787ee | 2006-01-26 16:20:06 -0700 | [diff] [blame] | 1687 | device_info->handle_parent = le16_to_cpu(buffer->ParentDevHandle); |
Christoph Hellwig | e309444 | 2006-02-16 13:25:36 +0100 | [diff] [blame] | 1688 | device_info->handle_enclosure = |
| 1689 | le16_to_cpu(buffer->EnclosureHandle); |
| 1690 | device_info->slot = le16_to_cpu(buffer->Slot); |
Christoph Hellwig | 0c33b27 | 2005-09-09 16:27:19 +0200 | [diff] [blame] | 1691 | device_info->phy_id = buffer->PhyNum; |
| 1692 | device_info->port_id = buffer->PhysicalPort; |
Christoph Hellwig | 9a28f49a | 2006-01-13 18:04:41 +0100 | [diff] [blame] | 1693 | device_info->id = buffer->TargetID; |
Eric Moore | b506ade | 2007-01-29 09:45:37 -0700 | [diff] [blame] | 1694 | device_info->phys_disk_num = ~0; |
Christoph Hellwig | 9a28f49a | 2006-01-13 18:04:41 +0100 | [diff] [blame] | 1695 | device_info->channel = buffer->Bus; |
Christoph Hellwig | 0c33b27 | 2005-09-09 16:27:19 +0200 | [diff] [blame] | 1696 | memcpy(&sas_address, &buffer->SASAddress, sizeof(__le64)); |
| 1697 | device_info->sas_address = le64_to_cpu(sas_address); |
| 1698 | device_info->device_info = |
| 1699 | le32_to_cpu(buffer->DeviceInfo); |
| 1700 | |
| 1701 | out_free_consistent: |
| 1702 | pci_free_consistent(ioc->pcidev, hdr.ExtPageLength * 4, |
| 1703 | buffer, dma_handle); |
| 1704 | out: |
| 1705 | return error; |
| 1706 | } |
| 1707 | |
| 1708 | static int |
| 1709 | mptsas_sas_expander_pg0(MPT_ADAPTER *ioc, struct mptsas_portinfo *port_info, |
| 1710 | u32 form, u32 form_specific) |
| 1711 | { |
| 1712 | ConfigExtendedPageHeader_t hdr; |
| 1713 | CONFIGPARMS cfg; |
| 1714 | SasExpanderPage0_t *buffer; |
| 1715 | dma_addr_t dma_handle; |
Eric Moore | 547f9a2 | 2006-06-27 14:42:12 -0600 | [diff] [blame] | 1716 | int i, error; |
Christoph Hellwig | 0c33b27 | 2005-09-09 16:27:19 +0200 | [diff] [blame] | 1717 | |
| 1718 | hdr.PageVersion = MPI_SASEXPANDER0_PAGEVERSION; |
| 1719 | hdr.ExtPageLength = 0; |
| 1720 | hdr.PageNumber = 0; |
| 1721 | hdr.Reserved1 = 0; |
| 1722 | hdr.Reserved2 = 0; |
| 1723 | hdr.PageType = MPI_CONFIG_PAGETYPE_EXTENDED; |
| 1724 | hdr.ExtPageType = MPI_CONFIG_EXTPAGETYPE_SAS_EXPANDER; |
| 1725 | |
| 1726 | cfg.cfghdr.ehdr = &hdr; |
| 1727 | cfg.physAddr = -1; |
| 1728 | cfg.pageAddr = form + form_specific; |
| 1729 | cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER; |
| 1730 | cfg.dir = 0; /* read */ |
| 1731 | cfg.timeout = 10; |
| 1732 | |
Moore, Eric | db9c917 | 2006-03-14 09:14:18 -0700 | [diff] [blame] | 1733 | memset(port_info, 0, sizeof(struct mptsas_portinfo)); |
Christoph Hellwig | 0c33b27 | 2005-09-09 16:27:19 +0200 | [diff] [blame] | 1734 | error = mpt_config(ioc, &cfg); |
| 1735 | if (error) |
| 1736 | goto out; |
| 1737 | |
| 1738 | if (!hdr.ExtPageLength) { |
| 1739 | error = -ENXIO; |
| 1740 | goto out; |
| 1741 | } |
| 1742 | |
| 1743 | buffer = pci_alloc_consistent(ioc->pcidev, hdr.ExtPageLength * 4, |
| 1744 | &dma_handle); |
| 1745 | if (!buffer) { |
| 1746 | error = -ENOMEM; |
| 1747 | goto out; |
| 1748 | } |
| 1749 | |
| 1750 | cfg.physAddr = dma_handle; |
| 1751 | cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT; |
| 1752 | |
| 1753 | error = mpt_config(ioc, &cfg); |
| 1754 | if (error) |
| 1755 | goto out_free_consistent; |
| 1756 | |
Krzysztof Oledzki | 51f39ea | 2008-03-04 14:56:23 -0800 | [diff] [blame] | 1757 | if (!buffer->NumPhys) { |
| 1758 | error = -ENODEV; |
| 1759 | goto out_free_consistent; |
| 1760 | } |
| 1761 | |
Christoph Hellwig | 0c33b27 | 2005-09-09 16:27:19 +0200 | [diff] [blame] | 1762 | /* save config data */ |
| 1763 | port_info->num_phys = buffer->NumPhys; |
Christoph Hellwig | 0c33b27 | 2005-09-09 16:27:19 +0200 | [diff] [blame] | 1764 | port_info->phy_info = kcalloc(port_info->num_phys, |
Eric Moore | 547f9a2 | 2006-06-27 14:42:12 -0600 | [diff] [blame] | 1765 | sizeof(*port_info->phy_info),GFP_KERNEL); |
Christoph Hellwig | 0c33b27 | 2005-09-09 16:27:19 +0200 | [diff] [blame] | 1766 | if (!port_info->phy_info) { |
| 1767 | error = -ENOMEM; |
| 1768 | goto out_free_consistent; |
| 1769 | } |
| 1770 | |
Eric Moore | 2ecce49 | 2007-01-29 09:47:08 -0700 | [diff] [blame] | 1771 | for (i = 0; i < port_info->num_phys; i++) { |
Eric Moore | 547f9a2 | 2006-06-27 14:42:12 -0600 | [diff] [blame] | 1772 | port_info->phy_info[i].portinfo = port_info; |
Eric Moore | 2ecce49 | 2007-01-29 09:47:08 -0700 | [diff] [blame] | 1773 | port_info->phy_info[i].handle = |
| 1774 | le16_to_cpu(buffer->DevHandle); |
| 1775 | } |
Eric Moore | 547f9a2 | 2006-06-27 14:42:12 -0600 | [diff] [blame] | 1776 | |
Christoph Hellwig | 0c33b27 | 2005-09-09 16:27:19 +0200 | [diff] [blame] | 1777 | out_free_consistent: |
| 1778 | pci_free_consistent(ioc->pcidev, hdr.ExtPageLength * 4, |
| 1779 | buffer, dma_handle); |
| 1780 | out: |
| 1781 | return error; |
| 1782 | } |
| 1783 | |
| 1784 | static int |
| 1785 | mptsas_sas_expander_pg1(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, |
| 1786 | u32 form, u32 form_specific) |
| 1787 | { |
| 1788 | ConfigExtendedPageHeader_t hdr; |
| 1789 | CONFIGPARMS cfg; |
| 1790 | SasExpanderPage1_t *buffer; |
| 1791 | dma_addr_t dma_handle; |
Moore, Eric | bd23e94 | 2006-04-17 12:43:04 -0600 | [diff] [blame] | 1792 | int error=0; |
| 1793 | |
| 1794 | if (ioc->sas_discovery_runtime && |
| 1795 | mptsas_is_end_device(&phy_info->attached)) |
| 1796 | goto out; |
Christoph Hellwig | 0c33b27 | 2005-09-09 16:27:19 +0200 | [diff] [blame] | 1797 | |
| 1798 | hdr.PageVersion = MPI_SASEXPANDER0_PAGEVERSION; |
| 1799 | hdr.ExtPageLength = 0; |
| 1800 | hdr.PageNumber = 1; |
| 1801 | hdr.Reserved1 = 0; |
| 1802 | hdr.Reserved2 = 0; |
| 1803 | hdr.PageType = MPI_CONFIG_PAGETYPE_EXTENDED; |
| 1804 | hdr.ExtPageType = MPI_CONFIG_EXTPAGETYPE_SAS_EXPANDER; |
| 1805 | |
| 1806 | cfg.cfghdr.ehdr = &hdr; |
| 1807 | cfg.physAddr = -1; |
| 1808 | cfg.pageAddr = form + form_specific; |
| 1809 | cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER; |
| 1810 | cfg.dir = 0; /* read */ |
| 1811 | cfg.timeout = 10; |
| 1812 | |
| 1813 | error = mpt_config(ioc, &cfg); |
| 1814 | if (error) |
| 1815 | goto out; |
| 1816 | |
| 1817 | if (!hdr.ExtPageLength) { |
| 1818 | error = -ENXIO; |
| 1819 | goto out; |
| 1820 | } |
| 1821 | |
| 1822 | buffer = pci_alloc_consistent(ioc->pcidev, hdr.ExtPageLength * 4, |
| 1823 | &dma_handle); |
| 1824 | if (!buffer) { |
| 1825 | error = -ENOMEM; |
| 1826 | goto out; |
| 1827 | } |
| 1828 | |
| 1829 | cfg.physAddr = dma_handle; |
| 1830 | cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT; |
| 1831 | |
| 1832 | error = mpt_config(ioc, &cfg); |
| 1833 | if (error) |
| 1834 | goto out_free_consistent; |
| 1835 | |
| 1836 | |
Prakash, Sathya | d6ecdd6 | 2007-07-24 15:47:41 +0530 | [diff] [blame] | 1837 | mptsas_print_expander_pg1(ioc, buffer); |
Christoph Hellwig | 0c33b27 | 2005-09-09 16:27:19 +0200 | [diff] [blame] | 1838 | |
| 1839 | /* save config data */ |
Eric Moore | 024358e | 2005-10-21 20:56:36 +0200 | [diff] [blame] | 1840 | phy_info->phy_id = buffer->PhyIdentifier; |
Christoph Hellwig | 0c33b27 | 2005-09-09 16:27:19 +0200 | [diff] [blame] | 1841 | phy_info->port_id = buffer->PhysicalPort; |
| 1842 | phy_info->negotiated_link_rate = buffer->NegotiatedLinkRate; |
| 1843 | phy_info->programmed_link_rate = buffer->ProgrammedLinkRate; |
| 1844 | phy_info->hw_link_rate = buffer->HwLinkRate; |
| 1845 | phy_info->identify.handle = le16_to_cpu(buffer->OwnerDevHandle); |
| 1846 | phy_info->attached.handle = le16_to_cpu(buffer->AttachedDevHandle); |
| 1847 | |
Christoph Hellwig | 0c33b27 | 2005-09-09 16:27:19 +0200 | [diff] [blame] | 1848 | out_free_consistent: |
| 1849 | pci_free_consistent(ioc->pcidev, hdr.ExtPageLength * 4, |
| 1850 | buffer, dma_handle); |
| 1851 | out: |
| 1852 | return error; |
| 1853 | } |
| 1854 | |
| 1855 | static void |
| 1856 | mptsas_parse_device_info(struct sas_identify *identify, |
| 1857 | struct mptsas_devinfo *device_info) |
| 1858 | { |
| 1859 | u16 protocols; |
| 1860 | |
| 1861 | identify->sas_address = device_info->sas_address; |
| 1862 | identify->phy_identifier = device_info->phy_id; |
| 1863 | |
| 1864 | /* |
| 1865 | * Fill in Phy Initiator Port Protocol. |
| 1866 | * Bits 6:3, more than one bit can be set, fall through cases. |
| 1867 | */ |
| 1868 | protocols = device_info->device_info & 0x78; |
| 1869 | identify->initiator_port_protocols = 0; |
| 1870 | if (protocols & MPI_SAS_DEVICE_INFO_SSP_INITIATOR) |
| 1871 | identify->initiator_port_protocols |= SAS_PROTOCOL_SSP; |
| 1872 | if (protocols & MPI_SAS_DEVICE_INFO_STP_INITIATOR) |
| 1873 | identify->initiator_port_protocols |= SAS_PROTOCOL_STP; |
| 1874 | if (protocols & MPI_SAS_DEVICE_INFO_SMP_INITIATOR) |
| 1875 | identify->initiator_port_protocols |= SAS_PROTOCOL_SMP; |
| 1876 | if (protocols & MPI_SAS_DEVICE_INFO_SATA_HOST) |
| 1877 | identify->initiator_port_protocols |= SAS_PROTOCOL_SATA; |
| 1878 | |
| 1879 | /* |
| 1880 | * Fill in Phy Target Port Protocol. |
| 1881 | * Bits 10:7, more than one bit can be set, fall through cases. |
| 1882 | */ |
| 1883 | protocols = device_info->device_info & 0x780; |
| 1884 | identify->target_port_protocols = 0; |
| 1885 | if (protocols & MPI_SAS_DEVICE_INFO_SSP_TARGET) |
| 1886 | identify->target_port_protocols |= SAS_PROTOCOL_SSP; |
| 1887 | if (protocols & MPI_SAS_DEVICE_INFO_STP_TARGET) |
| 1888 | identify->target_port_protocols |= SAS_PROTOCOL_STP; |
| 1889 | if (protocols & MPI_SAS_DEVICE_INFO_SMP_TARGET) |
| 1890 | identify->target_port_protocols |= SAS_PROTOCOL_SMP; |
| 1891 | if (protocols & MPI_SAS_DEVICE_INFO_SATA_DEVICE) |
| 1892 | identify->target_port_protocols |= SAS_PROTOCOL_SATA; |
| 1893 | |
| 1894 | /* |
| 1895 | * Fill in Attached device type. |
| 1896 | */ |
| 1897 | switch (device_info->device_info & |
| 1898 | MPI_SAS_DEVICE_INFO_MASK_DEVICE_TYPE) { |
| 1899 | case MPI_SAS_DEVICE_INFO_NO_DEVICE: |
| 1900 | identify->device_type = SAS_PHY_UNUSED; |
| 1901 | break; |
| 1902 | case MPI_SAS_DEVICE_INFO_END_DEVICE: |
| 1903 | identify->device_type = SAS_END_DEVICE; |
| 1904 | break; |
| 1905 | case MPI_SAS_DEVICE_INFO_EDGE_EXPANDER: |
| 1906 | identify->device_type = SAS_EDGE_EXPANDER_DEVICE; |
| 1907 | break; |
| 1908 | case MPI_SAS_DEVICE_INFO_FANOUT_EXPANDER: |
| 1909 | identify->device_type = SAS_FANOUT_EXPANDER_DEVICE; |
| 1910 | break; |
| 1911 | } |
| 1912 | } |
| 1913 | |
| 1914 | static int mptsas_probe_one_phy(struct device *dev, |
Christoph Hellwig | ac01bbb | 2005-10-19 20:01:17 +0200 | [diff] [blame] | 1915 | struct mptsas_phyinfo *phy_info, int index, int local) |
Christoph Hellwig | 0c33b27 | 2005-09-09 16:27:19 +0200 | [diff] [blame] | 1916 | { |
Moore, Eric | e6b2d76 | 2006-03-14 09:14:24 -0700 | [diff] [blame] | 1917 | MPT_ADAPTER *ioc; |
Christoph Hellwig | 9a28f49a | 2006-01-13 18:04:41 +0100 | [diff] [blame] | 1918 | struct sas_phy *phy; |
Eric Moore | 547f9a2 | 2006-06-27 14:42:12 -0600 | [diff] [blame] | 1919 | struct sas_port *port; |
| 1920 | int error = 0; |
Christoph Hellwig | 0c33b27 | 2005-09-09 16:27:19 +0200 | [diff] [blame] | 1921 | |
Eric Moore | 547f9a2 | 2006-06-27 14:42:12 -0600 | [diff] [blame] | 1922 | if (!dev) { |
| 1923 | error = -ENODEV; |
| 1924 | goto out; |
| 1925 | } |
Moore, Eric | e6b2d76 | 2006-03-14 09:14:24 -0700 | [diff] [blame] | 1926 | |
| 1927 | if (!phy_info->phy) { |
| 1928 | phy = sas_phy_alloc(dev, index); |
Eric Moore | 547f9a2 | 2006-06-27 14:42:12 -0600 | [diff] [blame] | 1929 | if (!phy) { |
| 1930 | error = -ENOMEM; |
| 1931 | goto out; |
| 1932 | } |
Moore, Eric | e6b2d76 | 2006-03-14 09:14:24 -0700 | [diff] [blame] | 1933 | } else |
| 1934 | phy = phy_info->phy; |
Christoph Hellwig | 0c33b27 | 2005-09-09 16:27:19 +0200 | [diff] [blame] | 1935 | |
Christoph Hellwig | 9a28f49a | 2006-01-13 18:04:41 +0100 | [diff] [blame] | 1936 | mptsas_parse_device_info(&phy->identify, &phy_info->identify); |
Christoph Hellwig | 0c33b27 | 2005-09-09 16:27:19 +0200 | [diff] [blame] | 1937 | |
| 1938 | /* |
| 1939 | * Set Negotiated link rate. |
| 1940 | */ |
| 1941 | switch (phy_info->negotiated_link_rate) { |
| 1942 | case MPI_SAS_IOUNIT0_RATE_PHY_DISABLED: |
Christoph Hellwig | 9a28f49a | 2006-01-13 18:04:41 +0100 | [diff] [blame] | 1943 | phy->negotiated_linkrate = SAS_PHY_DISABLED; |
Christoph Hellwig | 0c33b27 | 2005-09-09 16:27:19 +0200 | [diff] [blame] | 1944 | break; |
| 1945 | case MPI_SAS_IOUNIT0_RATE_FAILED_SPEED_NEGOTIATION: |
Christoph Hellwig | 9a28f49a | 2006-01-13 18:04:41 +0100 | [diff] [blame] | 1946 | phy->negotiated_linkrate = SAS_LINK_RATE_FAILED; |
Christoph Hellwig | 0c33b27 | 2005-09-09 16:27:19 +0200 | [diff] [blame] | 1947 | break; |
| 1948 | case MPI_SAS_IOUNIT0_RATE_1_5: |
Christoph Hellwig | 9a28f49a | 2006-01-13 18:04:41 +0100 | [diff] [blame] | 1949 | phy->negotiated_linkrate = SAS_LINK_RATE_1_5_GBPS; |
Christoph Hellwig | 0c33b27 | 2005-09-09 16:27:19 +0200 | [diff] [blame] | 1950 | break; |
| 1951 | case MPI_SAS_IOUNIT0_RATE_3_0: |
Christoph Hellwig | 9a28f49a | 2006-01-13 18:04:41 +0100 | [diff] [blame] | 1952 | phy->negotiated_linkrate = SAS_LINK_RATE_3_0_GBPS; |
Christoph Hellwig | 0c33b27 | 2005-09-09 16:27:19 +0200 | [diff] [blame] | 1953 | break; |
| 1954 | case MPI_SAS_IOUNIT0_RATE_SATA_OOB_COMPLETE: |
| 1955 | case MPI_SAS_IOUNIT0_RATE_UNKNOWN: |
| 1956 | default: |
Christoph Hellwig | 9a28f49a | 2006-01-13 18:04:41 +0100 | [diff] [blame] | 1957 | phy->negotiated_linkrate = SAS_LINK_RATE_UNKNOWN; |
Christoph Hellwig | 0c33b27 | 2005-09-09 16:27:19 +0200 | [diff] [blame] | 1958 | break; |
| 1959 | } |
| 1960 | |
| 1961 | /* |
| 1962 | * Set Max hardware link rate. |
| 1963 | */ |
| 1964 | switch (phy_info->hw_link_rate & MPI_SAS_PHY0_PRATE_MAX_RATE_MASK) { |
| 1965 | case MPI_SAS_PHY0_HWRATE_MAX_RATE_1_5: |
Christoph Hellwig | 9a28f49a | 2006-01-13 18:04:41 +0100 | [diff] [blame] | 1966 | phy->maximum_linkrate_hw = SAS_LINK_RATE_1_5_GBPS; |
Christoph Hellwig | 0c33b27 | 2005-09-09 16:27:19 +0200 | [diff] [blame] | 1967 | break; |
| 1968 | case MPI_SAS_PHY0_PRATE_MAX_RATE_3_0: |
Christoph Hellwig | 9a28f49a | 2006-01-13 18:04:41 +0100 | [diff] [blame] | 1969 | phy->maximum_linkrate_hw = SAS_LINK_RATE_3_0_GBPS; |
Christoph Hellwig | 0c33b27 | 2005-09-09 16:27:19 +0200 | [diff] [blame] | 1970 | break; |
| 1971 | default: |
| 1972 | break; |
| 1973 | } |
| 1974 | |
| 1975 | /* |
| 1976 | * Set Max programmed link rate. |
| 1977 | */ |
| 1978 | switch (phy_info->programmed_link_rate & |
| 1979 | MPI_SAS_PHY0_PRATE_MAX_RATE_MASK) { |
| 1980 | case MPI_SAS_PHY0_PRATE_MAX_RATE_1_5: |
Christoph Hellwig | 9a28f49a | 2006-01-13 18:04:41 +0100 | [diff] [blame] | 1981 | phy->maximum_linkrate = SAS_LINK_RATE_1_5_GBPS; |
Christoph Hellwig | 0c33b27 | 2005-09-09 16:27:19 +0200 | [diff] [blame] | 1982 | break; |
| 1983 | case MPI_SAS_PHY0_PRATE_MAX_RATE_3_0: |
Christoph Hellwig | 9a28f49a | 2006-01-13 18:04:41 +0100 | [diff] [blame] | 1984 | phy->maximum_linkrate = SAS_LINK_RATE_3_0_GBPS; |
Christoph Hellwig | 0c33b27 | 2005-09-09 16:27:19 +0200 | [diff] [blame] | 1985 | break; |
| 1986 | default: |
| 1987 | break; |
| 1988 | } |
| 1989 | |
| 1990 | /* |
| 1991 | * Set Min hardware link rate. |
| 1992 | */ |
| 1993 | switch (phy_info->hw_link_rate & MPI_SAS_PHY0_HWRATE_MIN_RATE_MASK) { |
| 1994 | case MPI_SAS_PHY0_HWRATE_MIN_RATE_1_5: |
Christoph Hellwig | 9a28f49a | 2006-01-13 18:04:41 +0100 | [diff] [blame] | 1995 | phy->minimum_linkrate_hw = SAS_LINK_RATE_1_5_GBPS; |
Christoph Hellwig | 0c33b27 | 2005-09-09 16:27:19 +0200 | [diff] [blame] | 1996 | break; |
| 1997 | case MPI_SAS_PHY0_PRATE_MIN_RATE_3_0: |
Christoph Hellwig | 9a28f49a | 2006-01-13 18:04:41 +0100 | [diff] [blame] | 1998 | phy->minimum_linkrate_hw = SAS_LINK_RATE_3_0_GBPS; |
Christoph Hellwig | 0c33b27 | 2005-09-09 16:27:19 +0200 | [diff] [blame] | 1999 | break; |
| 2000 | default: |
| 2001 | break; |
| 2002 | } |
| 2003 | |
| 2004 | /* |
| 2005 | * Set Min programmed link rate. |
| 2006 | */ |
| 2007 | switch (phy_info->programmed_link_rate & |
| 2008 | MPI_SAS_PHY0_PRATE_MIN_RATE_MASK) { |
| 2009 | case MPI_SAS_PHY0_PRATE_MIN_RATE_1_5: |
Christoph Hellwig | 9a28f49a | 2006-01-13 18:04:41 +0100 | [diff] [blame] | 2010 | phy->minimum_linkrate = SAS_LINK_RATE_1_5_GBPS; |
Christoph Hellwig | 0c33b27 | 2005-09-09 16:27:19 +0200 | [diff] [blame] | 2011 | break; |
| 2012 | case MPI_SAS_PHY0_PRATE_MIN_RATE_3_0: |
Christoph Hellwig | 9a28f49a | 2006-01-13 18:04:41 +0100 | [diff] [blame] | 2013 | phy->minimum_linkrate = SAS_LINK_RATE_3_0_GBPS; |
Christoph Hellwig | 0c33b27 | 2005-09-09 16:27:19 +0200 | [diff] [blame] | 2014 | break; |
| 2015 | default: |
| 2016 | break; |
| 2017 | } |
| 2018 | |
Moore, Eric | e6b2d76 | 2006-03-14 09:14:24 -0700 | [diff] [blame] | 2019 | if (!phy_info->phy) { |
Christoph Hellwig | ac01bbb | 2005-10-19 20:01:17 +0200 | [diff] [blame] | 2020 | |
Moore, Eric | e6b2d76 | 2006-03-14 09:14:24 -0700 | [diff] [blame] | 2021 | error = sas_phy_add(phy); |
| 2022 | if (error) { |
| 2023 | sas_phy_free(phy); |
Eric Moore | 547f9a2 | 2006-06-27 14:42:12 -0600 | [diff] [blame] | 2024 | goto out; |
Moore, Eric | e6b2d76 | 2006-03-14 09:14:24 -0700 | [diff] [blame] | 2025 | } |
| 2026 | phy_info->phy = phy; |
Christoph Hellwig | 0c33b27 | 2005-09-09 16:27:19 +0200 | [diff] [blame] | 2027 | } |
| 2028 | |
Eric Moore | 547f9a2 | 2006-06-27 14:42:12 -0600 | [diff] [blame] | 2029 | if (!phy_info->attached.handle || |
| 2030 | !phy_info->port_details) |
| 2031 | goto out; |
| 2032 | |
| 2033 | port = mptsas_get_port(phy_info); |
| 2034 | ioc = phy_to_ioc(phy_info->phy); |
| 2035 | |
| 2036 | if (phy_info->sas_port_add_phy) { |
| 2037 | |
| 2038 | if (!port) { |
Eric Moore | dc22f16 | 2006-07-06 11:23:14 -0600 | [diff] [blame] | 2039 | port = sas_port_alloc_num(dev); |
Eric Moore | 547f9a2 | 2006-06-27 14:42:12 -0600 | [diff] [blame] | 2040 | if (!port) { |
| 2041 | error = -ENOMEM; |
| 2042 | goto out; |
| 2043 | } |
| 2044 | error = sas_port_add(port); |
| 2045 | if (error) { |
Prakash, Sathya | d6ecdd6 | 2007-07-24 15:47:41 +0530 | [diff] [blame] | 2046 | dfailprintk(ioc, printk(MYIOC_s_ERR_FMT |
Eric Moore | 547f9a2 | 2006-06-27 14:42:12 -0600 | [diff] [blame] | 2047 | "%s: exit at line=%d\n", ioc->name, |
Harvey Harrison | cadbd4a | 2008-07-03 23:47:27 -0700 | [diff] [blame] | 2048 | __func__, __LINE__)); |
Eric Moore | 547f9a2 | 2006-06-27 14:42:12 -0600 | [diff] [blame] | 2049 | goto out; |
| 2050 | } |
Prakash, Sathya | d6ecdd6 | 2007-07-24 15:47:41 +0530 | [diff] [blame] | 2051 | mptsas_set_port(ioc, phy_info, port); |
Eric Moore | 29dd360 | 2007-09-14 18:46:51 -0600 | [diff] [blame] | 2052 | dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT |
Eric Moore | dc22f16 | 2006-07-06 11:23:14 -0600 | [diff] [blame] | 2053 | "sas_port_alloc: port=%p dev=%p port_id=%d\n", |
Eric Moore | 29dd360 | 2007-09-14 18:46:51 -0600 | [diff] [blame] | 2054 | ioc->name, port, dev, port->port_identifier)); |
Eric Moore | 547f9a2 | 2006-06-27 14:42:12 -0600 | [diff] [blame] | 2055 | } |
Eric Moore | 29dd360 | 2007-09-14 18:46:51 -0600 | [diff] [blame] | 2056 | dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_port_add_phy: phy_id=%d\n", |
| 2057 | ioc->name, phy_info->phy_id)); |
Eric Moore | 547f9a2 | 2006-06-27 14:42:12 -0600 | [diff] [blame] | 2058 | sas_port_add_phy(port, phy_info->phy); |
| 2059 | phy_info->sas_port_add_phy = 0; |
| 2060 | } |
| 2061 | |
| 2062 | if (!mptsas_get_rphy(phy_info) && port && !port->rphy) { |
Moore, Eric | e6b2d76 | 2006-03-14 09:14:24 -0700 | [diff] [blame] | 2063 | |
Christoph Hellwig | 0c33b27 | 2005-09-09 16:27:19 +0200 | [diff] [blame] | 2064 | struct sas_rphy *rphy; |
James Bottomley | 2686de2 | 2006-06-30 12:54:02 -0500 | [diff] [blame] | 2065 | struct device *parent; |
James Bottomley | f013db3 | 2006-03-18 14:54:36 -0600 | [diff] [blame] | 2066 | struct sas_identify identify; |
Christoph Hellwig | 0c33b27 | 2005-09-09 16:27:19 +0200 | [diff] [blame] | 2067 | |
James Bottomley | 2686de2 | 2006-06-30 12:54:02 -0500 | [diff] [blame] | 2068 | parent = dev->parent->parent; |
Moore, Eric | e6b2d76 | 2006-03-14 09:14:24 -0700 | [diff] [blame] | 2069 | /* |
| 2070 | * Let the hotplug_work thread handle processing |
| 2071 | * the adding/removing of devices that occur |
| 2072 | * after start of day. |
| 2073 | */ |
| 2074 | if (ioc->sas_discovery_runtime && |
| 2075 | mptsas_is_end_device(&phy_info->attached)) |
Eric Moore | 547f9a2 | 2006-06-27 14:42:12 -0600 | [diff] [blame] | 2076 | goto out; |
Moore, Eric | e6b2d76 | 2006-03-14 09:14:24 -0700 | [diff] [blame] | 2077 | |
James Bottomley | f013db3 | 2006-03-18 14:54:36 -0600 | [diff] [blame] | 2078 | mptsas_parse_device_info(&identify, &phy_info->attached); |
James Bottomley | 2686de2 | 2006-06-30 12:54:02 -0500 | [diff] [blame] | 2079 | if (scsi_is_host_device(parent)) { |
| 2080 | struct mptsas_portinfo *port_info; |
| 2081 | int i; |
| 2082 | |
| 2083 | mutex_lock(&ioc->sas_topology_mutex); |
Michael Reed | 7748369 | 2008-03-20 17:32:05 -0500 | [diff] [blame] | 2084 | port_info = mptsas_get_hba_portinfo(ioc); |
James Bottomley | 2686de2 | 2006-06-30 12:54:02 -0500 | [diff] [blame] | 2085 | mutex_unlock(&ioc->sas_topology_mutex); |
| 2086 | |
| 2087 | for (i = 0; i < port_info->num_phys; i++) |
| 2088 | if (port_info->phy_info[i].identify.sas_address == |
James Bottomley | 0c269e6 | 2006-07-12 09:51:04 -0400 | [diff] [blame] | 2089 | identify.sas_address) { |
| 2090 | sas_port_mark_backlink(port); |
James Bottomley | 2686de2 | 2006-06-30 12:54:02 -0500 | [diff] [blame] | 2091 | goto out; |
James Bottomley | 0c269e6 | 2006-07-12 09:51:04 -0400 | [diff] [blame] | 2092 | } |
James Bottomley | 2686de2 | 2006-06-30 12:54:02 -0500 | [diff] [blame] | 2093 | |
| 2094 | } else if (scsi_is_sas_rphy(parent)) { |
| 2095 | struct sas_rphy *parent_rphy = dev_to_rphy(parent); |
| 2096 | if (identify.sas_address == |
James Bottomley | 0c269e6 | 2006-07-12 09:51:04 -0400 | [diff] [blame] | 2097 | parent_rphy->identify.sas_address) { |
| 2098 | sas_port_mark_backlink(port); |
James Bottomley | 2686de2 | 2006-06-30 12:54:02 -0500 | [diff] [blame] | 2099 | goto out; |
James Bottomley | 0c269e6 | 2006-07-12 09:51:04 -0400 | [diff] [blame] | 2100 | } |
James Bottomley | 2686de2 | 2006-06-30 12:54:02 -0500 | [diff] [blame] | 2101 | } |
| 2102 | |
James Bottomley | f013db3 | 2006-03-18 14:54:36 -0600 | [diff] [blame] | 2103 | switch (identify.device_type) { |
| 2104 | case SAS_END_DEVICE: |
Eric Moore | 547f9a2 | 2006-06-27 14:42:12 -0600 | [diff] [blame] | 2105 | rphy = sas_end_device_alloc(port); |
James Bottomley | f013db3 | 2006-03-18 14:54:36 -0600 | [diff] [blame] | 2106 | break; |
| 2107 | case SAS_EDGE_EXPANDER_DEVICE: |
| 2108 | case SAS_FANOUT_EXPANDER_DEVICE: |
Eric Moore | 547f9a2 | 2006-06-27 14:42:12 -0600 | [diff] [blame] | 2109 | rphy = sas_expander_alloc(port, identify.device_type); |
James Bottomley | f013db3 | 2006-03-18 14:54:36 -0600 | [diff] [blame] | 2110 | break; |
| 2111 | default: |
| 2112 | rphy = NULL; |
| 2113 | break; |
| 2114 | } |
Eric Moore | 547f9a2 | 2006-06-27 14:42:12 -0600 | [diff] [blame] | 2115 | if (!rphy) { |
Prakash, Sathya | d6ecdd6 | 2007-07-24 15:47:41 +0530 | [diff] [blame] | 2116 | dfailprintk(ioc, printk(MYIOC_s_ERR_FMT |
Eric Moore | 547f9a2 | 2006-06-27 14:42:12 -0600 | [diff] [blame] | 2117 | "%s: exit at line=%d\n", ioc->name, |
Harvey Harrison | cadbd4a | 2008-07-03 23:47:27 -0700 | [diff] [blame] | 2118 | __func__, __LINE__)); |
Eric Moore | 547f9a2 | 2006-06-27 14:42:12 -0600 | [diff] [blame] | 2119 | goto out; |
Christoph Hellwig | 0c33b27 | 2005-09-09 16:27:19 +0200 | [diff] [blame] | 2120 | } |
| 2121 | |
Eric Moore | 547f9a2 | 2006-06-27 14:42:12 -0600 | [diff] [blame] | 2122 | rphy->identify = identify; |
| 2123 | error = sas_rphy_add(rphy); |
| 2124 | if (error) { |
Prakash, Sathya | d6ecdd6 | 2007-07-24 15:47:41 +0530 | [diff] [blame] | 2125 | dfailprintk(ioc, printk(MYIOC_s_ERR_FMT |
Eric Moore | 547f9a2 | 2006-06-27 14:42:12 -0600 | [diff] [blame] | 2126 | "%s: exit at line=%d\n", ioc->name, |
Harvey Harrison | cadbd4a | 2008-07-03 23:47:27 -0700 | [diff] [blame] | 2127 | __func__, __LINE__)); |
Eric Moore | 547f9a2 | 2006-06-27 14:42:12 -0600 | [diff] [blame] | 2128 | sas_rphy_free(rphy); |
| 2129 | goto out; |
| 2130 | } |
Prakash, Sathya | d6ecdd6 | 2007-07-24 15:47:41 +0530 | [diff] [blame] | 2131 | mptsas_set_rphy(ioc, phy_info, rphy); |
Christoph Hellwig | 0c33b27 | 2005-09-09 16:27:19 +0200 | [diff] [blame] | 2132 | } |
| 2133 | |
Eric Moore | 547f9a2 | 2006-06-27 14:42:12 -0600 | [diff] [blame] | 2134 | out: |
| 2135 | return error; |
Christoph Hellwig | 0c33b27 | 2005-09-09 16:27:19 +0200 | [diff] [blame] | 2136 | } |
| 2137 | |
| 2138 | static int |
Moore, Eric | e6b2d76 | 2006-03-14 09:14:24 -0700 | [diff] [blame] | 2139 | mptsas_probe_hba_phys(MPT_ADAPTER *ioc) |
Christoph Hellwig | 0c33b27 | 2005-09-09 16:27:19 +0200 | [diff] [blame] | 2140 | { |
Moore, Eric | e6b2d76 | 2006-03-14 09:14:24 -0700 | [diff] [blame] | 2141 | struct mptsas_portinfo *port_info, *hba; |
Christoph Hellwig | 0c33b27 | 2005-09-09 16:27:19 +0200 | [diff] [blame] | 2142 | int error = -ENOMEM, i; |
| 2143 | |
Moore, Eric | e6b2d76 | 2006-03-14 09:14:24 -0700 | [diff] [blame] | 2144 | hba = kzalloc(sizeof(*port_info), GFP_KERNEL); |
| 2145 | if (! hba) |
Christoph Hellwig | 0c33b27 | 2005-09-09 16:27:19 +0200 | [diff] [blame] | 2146 | goto out; |
Christoph Hellwig | 0c33b27 | 2005-09-09 16:27:19 +0200 | [diff] [blame] | 2147 | |
Moore, Eric | e6b2d76 | 2006-03-14 09:14:24 -0700 | [diff] [blame] | 2148 | error = mptsas_sas_io_unit_pg0(ioc, hba); |
Christoph Hellwig | 0c33b27 | 2005-09-09 16:27:19 +0200 | [diff] [blame] | 2149 | if (error) |
| 2150 | goto out_free_port_info; |
| 2151 | |
Prakash, Sathya | edb9068 | 2007-07-17 14:39:14 +0530 | [diff] [blame] | 2152 | mptsas_sas_io_unit_pg1(ioc); |
Christoph Hellwig | 9a28f49a | 2006-01-13 18:04:41 +0100 | [diff] [blame] | 2153 | mutex_lock(&ioc->sas_topology_mutex); |
Michael Reed | 7748369 | 2008-03-20 17:32:05 -0500 | [diff] [blame] | 2154 | port_info = mptsas_get_hba_portinfo(ioc); |
Moore, Eric | e6b2d76 | 2006-03-14 09:14:24 -0700 | [diff] [blame] | 2155 | if (!port_info) { |
| 2156 | port_info = hba; |
| 2157 | list_add_tail(&port_info->list, &ioc->sas_topology); |
| 2158 | } else { |
Eric Moore | 2ecce49 | 2007-01-29 09:47:08 -0700 | [diff] [blame] | 2159 | for (i = 0; i < hba->num_phys; i++) { |
Moore, Eric | e6b2d76 | 2006-03-14 09:14:24 -0700 | [diff] [blame] | 2160 | port_info->phy_info[i].negotiated_link_rate = |
| 2161 | hba->phy_info[i].negotiated_link_rate; |
Eric Moore | 2ecce49 | 2007-01-29 09:47:08 -0700 | [diff] [blame] | 2162 | port_info->phy_info[i].handle = |
| 2163 | hba->phy_info[i].handle; |
| 2164 | port_info->phy_info[i].port_id = |
| 2165 | hba->phy_info[i].port_id; |
| 2166 | } |
Eric Moore | 547f9a2 | 2006-06-27 14:42:12 -0600 | [diff] [blame] | 2167 | kfree(hba->phy_info); |
Moore, Eric | e6b2d76 | 2006-03-14 09:14:24 -0700 | [diff] [blame] | 2168 | kfree(hba); |
| 2169 | hba = NULL; |
| 2170 | } |
Christoph Hellwig | 9a28f49a | 2006-01-13 18:04:41 +0100 | [diff] [blame] | 2171 | mutex_unlock(&ioc->sas_topology_mutex); |
Christoph Hellwig | 0c33b27 | 2005-09-09 16:27:19 +0200 | [diff] [blame] | 2172 | for (i = 0; i < port_info->num_phys; i++) { |
| 2173 | mptsas_sas_phy_pg0(ioc, &port_info->phy_info[i], |
| 2174 | (MPI_SAS_PHY_PGAD_FORM_PHY_NUMBER << |
| 2175 | MPI_SAS_PHY_PGAD_FORM_SHIFT), i); |
| 2176 | |
| 2177 | mptsas_sas_device_pg0(ioc, &port_info->phy_info[i].identify, |
Eric Moore | 2ecce49 | 2007-01-29 09:47:08 -0700 | [diff] [blame] | 2178 | (MPI_SAS_DEVICE_PGAD_FORM_HANDLE << |
| 2179 | MPI_SAS_DEVICE_PGAD_FORM_SHIFT), |
| 2180 | port_info->phy_info[i].handle); |
Eric Moore | 024358e | 2005-10-21 20:56:36 +0200 | [diff] [blame] | 2181 | port_info->phy_info[i].identify.phy_id = |
Eric Moore | 2ecce49 | 2007-01-29 09:47:08 -0700 | [diff] [blame] | 2182 | port_info->phy_info[i].phy_id = i; |
Eric Moore | 547f9a2 | 2006-06-27 14:42:12 -0600 | [diff] [blame] | 2183 | if (port_info->phy_info[i].attached.handle) |
Christoph Hellwig | 0c33b27 | 2005-09-09 16:27:19 +0200 | [diff] [blame] | 2184 | mptsas_sas_device_pg0(ioc, |
| 2185 | &port_info->phy_info[i].attached, |
| 2186 | (MPI_SAS_DEVICE_PGAD_FORM_HANDLE << |
| 2187 | MPI_SAS_DEVICE_PGAD_FORM_SHIFT), |
| 2188 | port_info->phy_info[i].attached.handle); |
Eric Moore | 547f9a2 | 2006-06-27 14:42:12 -0600 | [diff] [blame] | 2189 | } |
Christoph Hellwig | 0c33b27 | 2005-09-09 16:27:19 +0200 | [diff] [blame] | 2190 | |
Eric Moore | 547f9a2 | 2006-06-27 14:42:12 -0600 | [diff] [blame] | 2191 | mptsas_setup_wide_ports(ioc, port_info); |
| 2192 | |
| 2193 | for (i = 0; i < port_info->num_phys; i++, ioc->sas_index++) |
Christoph Hellwig | 0c33b27 | 2005-09-09 16:27:19 +0200 | [diff] [blame] | 2194 | mptsas_probe_one_phy(&ioc->sh->shost_gendev, |
Moore, Eric | e6b2d76 | 2006-03-14 09:14:24 -0700 | [diff] [blame] | 2195 | &port_info->phy_info[i], ioc->sas_index, 1); |
Christoph Hellwig | 0c33b27 | 2005-09-09 16:27:19 +0200 | [diff] [blame] | 2196 | |
| 2197 | return 0; |
| 2198 | |
| 2199 | out_free_port_info: |
Eric Moore | 547f9a2 | 2006-06-27 14:42:12 -0600 | [diff] [blame] | 2200 | kfree(hba); |
Christoph Hellwig | 0c33b27 | 2005-09-09 16:27:19 +0200 | [diff] [blame] | 2201 | out: |
| 2202 | return error; |
| 2203 | } |
| 2204 | |
| 2205 | static int |
Moore, Eric | e6b2d76 | 2006-03-14 09:14:24 -0700 | [diff] [blame] | 2206 | mptsas_probe_expander_phys(MPT_ADAPTER *ioc, u32 *handle) |
Christoph Hellwig | 0c33b27 | 2005-09-09 16:27:19 +0200 | [diff] [blame] | 2207 | { |
Moore, Eric | e6b2d76 | 2006-03-14 09:14:24 -0700 | [diff] [blame] | 2208 | struct mptsas_portinfo *port_info, *p, *ex; |
Eric Moore | 547f9a2 | 2006-06-27 14:42:12 -0600 | [diff] [blame] | 2209 | struct device *parent; |
| 2210 | struct sas_rphy *rphy; |
Christoph Hellwig | 0c33b27 | 2005-09-09 16:27:19 +0200 | [diff] [blame] | 2211 | int error = -ENOMEM, i, j; |
| 2212 | |
Moore, Eric | e6b2d76 | 2006-03-14 09:14:24 -0700 | [diff] [blame] | 2213 | ex = kzalloc(sizeof(*port_info), GFP_KERNEL); |
| 2214 | if (!ex) |
Christoph Hellwig | 0c33b27 | 2005-09-09 16:27:19 +0200 | [diff] [blame] | 2215 | goto out; |
Christoph Hellwig | 0c33b27 | 2005-09-09 16:27:19 +0200 | [diff] [blame] | 2216 | |
Moore, Eric | e6b2d76 | 2006-03-14 09:14:24 -0700 | [diff] [blame] | 2217 | error = mptsas_sas_expander_pg0(ioc, ex, |
Eric Moore | 2ecce49 | 2007-01-29 09:47:08 -0700 | [diff] [blame] | 2218 | (MPI_SAS_EXPAND_PGAD_FORM_GET_NEXT_HANDLE << |
| 2219 | MPI_SAS_EXPAND_PGAD_FORM_SHIFT), *handle); |
Christoph Hellwig | 0c33b27 | 2005-09-09 16:27:19 +0200 | [diff] [blame] | 2220 | if (error) |
| 2221 | goto out_free_port_info; |
| 2222 | |
Eric Moore | 2ecce49 | 2007-01-29 09:47:08 -0700 | [diff] [blame] | 2223 | *handle = ex->phy_info[0].handle; |
Christoph Hellwig | 0c33b27 | 2005-09-09 16:27:19 +0200 | [diff] [blame] | 2224 | |
Christoph Hellwig | 9a28f49a | 2006-01-13 18:04:41 +0100 | [diff] [blame] | 2225 | mutex_lock(&ioc->sas_topology_mutex); |
Moore, Eric | e6b2d76 | 2006-03-14 09:14:24 -0700 | [diff] [blame] | 2226 | port_info = mptsas_find_portinfo_by_handle(ioc, *handle); |
| 2227 | if (!port_info) { |
| 2228 | port_info = ex; |
| 2229 | list_add_tail(&port_info->list, &ioc->sas_topology); |
| 2230 | } else { |
Eric Moore | 2ecce49 | 2007-01-29 09:47:08 -0700 | [diff] [blame] | 2231 | for (i = 0; i < ex->num_phys; i++) { |
| 2232 | port_info->phy_info[i].handle = |
| 2233 | ex->phy_info[i].handle; |
| 2234 | port_info->phy_info[i].port_id = |
| 2235 | ex->phy_info[i].port_id; |
| 2236 | } |
Eric Moore | 547f9a2 | 2006-06-27 14:42:12 -0600 | [diff] [blame] | 2237 | kfree(ex->phy_info); |
Moore, Eric | e6b2d76 | 2006-03-14 09:14:24 -0700 | [diff] [blame] | 2238 | kfree(ex); |
| 2239 | ex = NULL; |
| 2240 | } |
Christoph Hellwig | 9a28f49a | 2006-01-13 18:04:41 +0100 | [diff] [blame] | 2241 | mutex_unlock(&ioc->sas_topology_mutex); |
| 2242 | |
Christoph Hellwig | 0c33b27 | 2005-09-09 16:27:19 +0200 | [diff] [blame] | 2243 | for (i = 0; i < port_info->num_phys; i++) { |
Christoph Hellwig | 0c33b27 | 2005-09-09 16:27:19 +0200 | [diff] [blame] | 2244 | mptsas_sas_expander_pg1(ioc, &port_info->phy_info[i], |
| 2245 | (MPI_SAS_EXPAND_PGAD_FORM_HANDLE_PHY_NUM << |
| 2246 | MPI_SAS_EXPAND_PGAD_FORM_SHIFT), (i << 16) + *handle); |
| 2247 | |
| 2248 | if (port_info->phy_info[i].identify.handle) { |
| 2249 | mptsas_sas_device_pg0(ioc, |
| 2250 | &port_info->phy_info[i].identify, |
| 2251 | (MPI_SAS_DEVICE_PGAD_FORM_HANDLE << |
| 2252 | MPI_SAS_DEVICE_PGAD_FORM_SHIFT), |
| 2253 | port_info->phy_info[i].identify.handle); |
Eric Moore | 024358e | 2005-10-21 20:56:36 +0200 | [diff] [blame] | 2254 | port_info->phy_info[i].identify.phy_id = |
| 2255 | port_info->phy_info[i].phy_id; |
Christoph Hellwig | 0c33b27 | 2005-09-09 16:27:19 +0200 | [diff] [blame] | 2256 | } |
| 2257 | |
| 2258 | if (port_info->phy_info[i].attached.handle) { |
| 2259 | mptsas_sas_device_pg0(ioc, |
| 2260 | &port_info->phy_info[i].attached, |
| 2261 | (MPI_SAS_DEVICE_PGAD_FORM_HANDLE << |
| 2262 | MPI_SAS_DEVICE_PGAD_FORM_SHIFT), |
| 2263 | port_info->phy_info[i].attached.handle); |
Moore, Eric | db9c917 | 2006-03-14 09:14:18 -0700 | [diff] [blame] | 2264 | port_info->phy_info[i].attached.phy_id = |
| 2265 | port_info->phy_info[i].phy_id; |
Christoph Hellwig | 0c33b27 | 2005-09-09 16:27:19 +0200 | [diff] [blame] | 2266 | } |
Eric Moore | 547f9a2 | 2006-06-27 14:42:12 -0600 | [diff] [blame] | 2267 | } |
Christoph Hellwig | 0c33b27 | 2005-09-09 16:27:19 +0200 | [diff] [blame] | 2268 | |
Eric Moore | 547f9a2 | 2006-06-27 14:42:12 -0600 | [diff] [blame] | 2269 | parent = &ioc->sh->shost_gendev; |
| 2270 | for (i = 0; i < port_info->num_phys; i++) { |
Christoph Hellwig | 9a28f49a | 2006-01-13 18:04:41 +0100 | [diff] [blame] | 2271 | mutex_lock(&ioc->sas_topology_mutex); |
Christoph Hellwig | 0c33b27 | 2005-09-09 16:27:19 +0200 | [diff] [blame] | 2272 | list_for_each_entry(p, &ioc->sas_topology, list) { |
| 2273 | for (j = 0; j < p->num_phys; j++) { |
Eric Moore | 547f9a2 | 2006-06-27 14:42:12 -0600 | [diff] [blame] | 2274 | if (port_info->phy_info[i].identify.handle != |
Christoph Hellwig | 0c33b27 | 2005-09-09 16:27:19 +0200 | [diff] [blame] | 2275 | p->phy_info[j].attached.handle) |
Eric Moore | 547f9a2 | 2006-06-27 14:42:12 -0600 | [diff] [blame] | 2276 | continue; |
| 2277 | rphy = mptsas_get_rphy(&p->phy_info[j]); |
| 2278 | parent = &rphy->dev; |
Christoph Hellwig | 0c33b27 | 2005-09-09 16:27:19 +0200 | [diff] [blame] | 2279 | } |
| 2280 | } |
Christoph Hellwig | 9a28f49a | 2006-01-13 18:04:41 +0100 | [diff] [blame] | 2281 | mutex_unlock(&ioc->sas_topology_mutex); |
Eric Moore | 547f9a2 | 2006-06-27 14:42:12 -0600 | [diff] [blame] | 2282 | } |
Christoph Hellwig | 0c33b27 | 2005-09-09 16:27:19 +0200 | [diff] [blame] | 2283 | |
Eric Moore | 547f9a2 | 2006-06-27 14:42:12 -0600 | [diff] [blame] | 2284 | mptsas_setup_wide_ports(ioc, port_info); |
| 2285 | |
| 2286 | for (i = 0; i < port_info->num_phys; i++, ioc->sas_index++) |
Christoph Hellwig | ac01bbb | 2005-10-19 20:01:17 +0200 | [diff] [blame] | 2287 | mptsas_probe_one_phy(parent, &port_info->phy_info[i], |
Moore, Eric | e6b2d76 | 2006-03-14 09:14:24 -0700 | [diff] [blame] | 2288 | ioc->sas_index, 0); |
Christoph Hellwig | 0c33b27 | 2005-09-09 16:27:19 +0200 | [diff] [blame] | 2289 | |
| 2290 | return 0; |
| 2291 | |
| 2292 | out_free_port_info: |
Moore, Eric | e6b2d76 | 2006-03-14 09:14:24 -0700 | [diff] [blame] | 2293 | if (ex) { |
Eric Moore | 547f9a2 | 2006-06-27 14:42:12 -0600 | [diff] [blame] | 2294 | kfree(ex->phy_info); |
Moore, Eric | e6b2d76 | 2006-03-14 09:14:24 -0700 | [diff] [blame] | 2295 | kfree(ex); |
| 2296 | } |
Christoph Hellwig | 0c33b27 | 2005-09-09 16:27:19 +0200 | [diff] [blame] | 2297 | out: |
| 2298 | return error; |
| 2299 | } |
| 2300 | |
Moore, Eric | e6b2d76 | 2006-03-14 09:14:24 -0700 | [diff] [blame] | 2301 | /* |
| 2302 | * mptsas_delete_expander_phys |
| 2303 | * |
| 2304 | * |
| 2305 | * This will traverse topology, and remove expanders |
| 2306 | * that are no longer present |
| 2307 | */ |
| 2308 | static void |
| 2309 | mptsas_delete_expander_phys(MPT_ADAPTER *ioc) |
| 2310 | { |
| 2311 | struct mptsas_portinfo buffer; |
| 2312 | struct mptsas_portinfo *port_info, *n, *parent; |
Eric Moore | 547f9a2 | 2006-06-27 14:42:12 -0600 | [diff] [blame] | 2313 | struct mptsas_phyinfo *phy_info; |
Eric Moore | 547f9a2 | 2006-06-27 14:42:12 -0600 | [diff] [blame] | 2314 | struct sas_port * port; |
Moore, Eric | e6b2d76 | 2006-03-14 09:14:24 -0700 | [diff] [blame] | 2315 | int i; |
Eric Moore | 547f9a2 | 2006-06-27 14:42:12 -0600 | [diff] [blame] | 2316 | u64 expander_sas_address; |
Moore, Eric | e6b2d76 | 2006-03-14 09:14:24 -0700 | [diff] [blame] | 2317 | |
| 2318 | mutex_lock(&ioc->sas_topology_mutex); |
| 2319 | list_for_each_entry_safe(port_info, n, &ioc->sas_topology, list) { |
| 2320 | |
Alan Cox | d58069a | 2009-04-01 15:00:29 +0100 | [diff] [blame] | 2321 | if (!(port_info->phy_info[0].identify.device_info & |
| 2322 | MPI_SAS_DEVICE_INFO_SMP_TARGET)) |
Moore, Eric | e6b2d76 | 2006-03-14 09:14:24 -0700 | [diff] [blame] | 2323 | continue; |
| 2324 | |
| 2325 | if (mptsas_sas_expander_pg0(ioc, &buffer, |
| 2326 | (MPI_SAS_EXPAND_PGAD_FORM_HANDLE << |
Eric Moore | 2ecce49 | 2007-01-29 09:47:08 -0700 | [diff] [blame] | 2327 | MPI_SAS_EXPAND_PGAD_FORM_SHIFT), |
| 2328 | port_info->phy_info[0].handle)) { |
Moore, Eric | e6b2d76 | 2006-03-14 09:14:24 -0700 | [diff] [blame] | 2329 | |
| 2330 | /* |
| 2331 | * Obtain the port_info instance to the parent port |
| 2332 | */ |
| 2333 | parent = mptsas_find_portinfo_by_handle(ioc, |
| 2334 | port_info->phy_info[0].identify.handle_parent); |
| 2335 | |
| 2336 | if (!parent) |
| 2337 | goto next_port; |
| 2338 | |
Eric Moore | 547f9a2 | 2006-06-27 14:42:12 -0600 | [diff] [blame] | 2339 | expander_sas_address = |
| 2340 | port_info->phy_info[0].identify.sas_address; |
| 2341 | |
Moore, Eric | e6b2d76 | 2006-03-14 09:14:24 -0700 | [diff] [blame] | 2342 | /* |
| 2343 | * Delete rphys in the parent that point |
| 2344 | * to this expander. The transport layer will |
| 2345 | * cleanup all the children. |
| 2346 | */ |
Eric Moore | 547f9a2 | 2006-06-27 14:42:12 -0600 | [diff] [blame] | 2347 | phy_info = parent->phy_info; |
| 2348 | for (i = 0; i < parent->num_phys; i++, phy_info++) { |
| 2349 | port = mptsas_get_port(phy_info); |
| 2350 | if (!port) |
Moore, Eric | e6b2d76 | 2006-03-14 09:14:24 -0700 | [diff] [blame] | 2351 | continue; |
Eric Moore | 547f9a2 | 2006-06-27 14:42:12 -0600 | [diff] [blame] | 2352 | if (phy_info->attached.sas_address != |
| 2353 | expander_sas_address) |
| 2354 | continue; |
Prakash, Sathya | d6ecdd6 | 2007-07-24 15:47:41 +0530 | [diff] [blame] | 2355 | dsaswideprintk(ioc, |
Eric Moore | c51d0be | 2007-09-29 10:17:21 -0600 | [diff] [blame] | 2356 | dev_printk(KERN_DEBUG, &port->dev, |
| 2357 | MYIOC_s_FMT "delete port (%d)\n", ioc->name, |
| 2358 | port->port_identifier)); |
Eric Moore | 547f9a2 | 2006-06-27 14:42:12 -0600 | [diff] [blame] | 2359 | sas_port_delete(port); |
Prakash, Sathya | d6ecdd6 | 2007-07-24 15:47:41 +0530 | [diff] [blame] | 2360 | mptsas_port_delete(ioc, phy_info->port_details); |
Moore, Eric | e6b2d76 | 2006-03-14 09:14:24 -0700 | [diff] [blame] | 2361 | } |
| 2362 | next_port: |
Eric Moore | 547f9a2 | 2006-06-27 14:42:12 -0600 | [diff] [blame] | 2363 | |
| 2364 | phy_info = port_info->phy_info; |
| 2365 | for (i = 0; i < port_info->num_phys; i++, phy_info++) |
Prakash, Sathya | d6ecdd6 | 2007-07-24 15:47:41 +0530 | [diff] [blame] | 2366 | mptsas_port_delete(ioc, phy_info->port_details); |
Eric Moore | 547f9a2 | 2006-06-27 14:42:12 -0600 | [diff] [blame] | 2367 | |
Moore, Eric | e6b2d76 | 2006-03-14 09:14:24 -0700 | [diff] [blame] | 2368 | list_del(&port_info->list); |
Eric Moore | 547f9a2 | 2006-06-27 14:42:12 -0600 | [diff] [blame] | 2369 | kfree(port_info->phy_info); |
Moore, Eric | e6b2d76 | 2006-03-14 09:14:24 -0700 | [diff] [blame] | 2370 | kfree(port_info); |
| 2371 | } |
| 2372 | /* |
| 2373 | * Free this memory allocated from inside |
| 2374 | * mptsas_sas_expander_pg0 |
| 2375 | */ |
Eric Moore | 547f9a2 | 2006-06-27 14:42:12 -0600 | [diff] [blame] | 2376 | kfree(buffer.phy_info); |
Moore, Eric | e6b2d76 | 2006-03-14 09:14:24 -0700 | [diff] [blame] | 2377 | } |
| 2378 | mutex_unlock(&ioc->sas_topology_mutex); |
| 2379 | } |
| 2380 | |
| 2381 | /* |
| 2382 | * Start of day discovery |
| 2383 | */ |
Christoph Hellwig | 0c33b27 | 2005-09-09 16:27:19 +0200 | [diff] [blame] | 2384 | static void |
| 2385 | mptsas_scan_sas_topology(MPT_ADAPTER *ioc) |
| 2386 | { |
| 2387 | u32 handle = 0xFFFF; |
Moore, Eric | f44e546 | 2006-03-14 09:14:21 -0700 | [diff] [blame] | 2388 | int i; |
Christoph Hellwig | 0c33b27 | 2005-09-09 16:27:19 +0200 | [diff] [blame] | 2389 | |
Moore, Eric | e6b2d76 | 2006-03-14 09:14:24 -0700 | [diff] [blame] | 2390 | mutex_lock(&ioc->sas_discovery_mutex); |
| 2391 | mptsas_probe_hba_phys(ioc); |
| 2392 | while (!mptsas_probe_expander_phys(ioc, &handle)) |
Christoph Hellwig | 0c33b27 | 2005-09-09 16:27:19 +0200 | [diff] [blame] | 2393 | ; |
Moore, Eric | f44e546 | 2006-03-14 09:14:21 -0700 | [diff] [blame] | 2394 | /* |
| 2395 | Reporting RAID volumes. |
| 2396 | */ |
Eric Moore | b506ade | 2007-01-29 09:45:37 -0700 | [diff] [blame] | 2397 | if (!ioc->ir_firmware) |
| 2398 | goto out; |
Moore, Eric | f44e546 | 2006-03-14 09:14:21 -0700 | [diff] [blame] | 2399 | if (!ioc->raid_data.pIocPg2) |
| 2400 | goto out; |
| 2401 | if (!ioc->raid_data.pIocPg2->NumActiveVolumes) |
| 2402 | goto out; |
Eric Moore | 793955f | 2007-01-29 09:42:20 -0700 | [diff] [blame] | 2403 | for (i = 0; i < ioc->raid_data.pIocPg2->NumActiveVolumes; i++) { |
James Bottomley | e8bf394 | 2006-07-11 17:49:34 -0400 | [diff] [blame] | 2404 | scsi_add_device(ioc->sh, MPTSAS_RAID_CHANNEL, |
Moore, Eric | f44e546 | 2006-03-14 09:14:21 -0700 | [diff] [blame] | 2405 | ioc->raid_data.pIocPg2->RaidVolume[i].VolumeID, 0); |
| 2406 | } |
| 2407 | out: |
Moore, Eric | e6b2d76 | 2006-03-14 09:14:24 -0700 | [diff] [blame] | 2408 | mutex_unlock(&ioc->sas_discovery_mutex); |
| 2409 | } |
| 2410 | |
| 2411 | /* |
| 2412 | * Work queue thread to handle Runtime discovery |
| 2413 | * Mere purpose is the hot add/delete of expanders |
Eric Moore | 547f9a2 | 2006-06-27 14:42:12 -0600 | [diff] [blame] | 2414 | *(Mutex UNLOCKED) |
Moore, Eric | e6b2d76 | 2006-03-14 09:14:24 -0700 | [diff] [blame] | 2415 | */ |
| 2416 | static void |
Eric Moore | 547f9a2 | 2006-06-27 14:42:12 -0600 | [diff] [blame] | 2417 | __mptsas_discovery_work(MPT_ADAPTER *ioc) |
Moore, Eric | e6b2d76 | 2006-03-14 09:14:24 -0700 | [diff] [blame] | 2418 | { |
Moore, Eric | e6b2d76 | 2006-03-14 09:14:24 -0700 | [diff] [blame] | 2419 | u32 handle = 0xFFFF; |
| 2420 | |
Moore, Eric | e6b2d76 | 2006-03-14 09:14:24 -0700 | [diff] [blame] | 2421 | ioc->sas_discovery_runtime=1; |
| 2422 | mptsas_delete_expander_phys(ioc); |
| 2423 | mptsas_probe_hba_phys(ioc); |
| 2424 | while (!mptsas_probe_expander_phys(ioc, &handle)) |
| 2425 | ; |
Moore, Eric | e6b2d76 | 2006-03-14 09:14:24 -0700 | [diff] [blame] | 2426 | ioc->sas_discovery_runtime=0; |
Eric Moore | 547f9a2 | 2006-06-27 14:42:12 -0600 | [diff] [blame] | 2427 | } |
| 2428 | |
| 2429 | /* |
| 2430 | * Work queue thread to handle Runtime discovery |
| 2431 | * Mere purpose is the hot add/delete of expanders |
| 2432 | *(Mutex LOCKED) |
| 2433 | */ |
| 2434 | static void |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 2435 | mptsas_discovery_work(struct work_struct *work) |
Eric Moore | 547f9a2 | 2006-06-27 14:42:12 -0600 | [diff] [blame] | 2436 | { |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 2437 | struct mptsas_discovery_event *ev = |
| 2438 | container_of(work, struct mptsas_discovery_event, work); |
Eric Moore | 547f9a2 | 2006-06-27 14:42:12 -0600 | [diff] [blame] | 2439 | MPT_ADAPTER *ioc = ev->ioc; |
| 2440 | |
| 2441 | mutex_lock(&ioc->sas_discovery_mutex); |
| 2442 | __mptsas_discovery_work(ioc); |
Moore, Eric | e6b2d76 | 2006-03-14 09:14:24 -0700 | [diff] [blame] | 2443 | mutex_unlock(&ioc->sas_discovery_mutex); |
Eric Moore | 547f9a2 | 2006-06-27 14:42:12 -0600 | [diff] [blame] | 2444 | kfree(ev); |
Christoph Hellwig | 0c33b27 | 2005-09-09 16:27:19 +0200 | [diff] [blame] | 2445 | } |
| 2446 | |
Christoph Hellwig | 9a28f49a | 2006-01-13 18:04:41 +0100 | [diff] [blame] | 2447 | static struct mptsas_phyinfo * |
Eric Moore | 547f9a2 | 2006-06-27 14:42:12 -0600 | [diff] [blame] | 2448 | mptsas_find_phyinfo_by_sas_address(MPT_ADAPTER *ioc, u64 sas_address) |
Christoph Hellwig | 9a28f49a | 2006-01-13 18:04:41 +0100 | [diff] [blame] | 2449 | { |
| 2450 | struct mptsas_portinfo *port_info; |
Christoph Hellwig | 9a28f49a | 2006-01-13 18:04:41 +0100 | [diff] [blame] | 2451 | struct mptsas_phyinfo *phy_info = NULL; |
Eric Moore | 547f9a2 | 2006-06-27 14:42:12 -0600 | [diff] [blame] | 2452 | int i; |
Christoph Hellwig | 9a28f49a | 2006-01-13 18:04:41 +0100 | [diff] [blame] | 2453 | |
Christoph Hellwig | 9a28f49a | 2006-01-13 18:04:41 +0100 | [diff] [blame] | 2454 | mutex_lock(&ioc->sas_topology_mutex); |
| 2455 | list_for_each_entry(port_info, &ioc->sas_topology, list) { |
| 2456 | for (i = 0; i < port_info->num_phys; i++) { |
Eric Moore | 547f9a2 | 2006-06-27 14:42:12 -0600 | [diff] [blame] | 2457 | if (!mptsas_is_end_device( |
| 2458 | &port_info->phy_info[i].attached)) |
| 2459 | continue; |
Eric Moore | b506ade | 2007-01-29 09:45:37 -0700 | [diff] [blame] | 2460 | if (port_info->phy_info[i].attached.sas_address |
| 2461 | != sas_address) |
| 2462 | continue; |
Eric Moore | 547f9a2 | 2006-06-27 14:42:12 -0600 | [diff] [blame] | 2463 | phy_info = &port_info->phy_info[i]; |
| 2464 | break; |
Christoph Hellwig | 9a28f49a | 2006-01-13 18:04:41 +0100 | [diff] [blame] | 2465 | } |
| 2466 | } |
| 2467 | mutex_unlock(&ioc->sas_topology_mutex); |
Christoph Hellwig | 9a28f49a | 2006-01-13 18:04:41 +0100 | [diff] [blame] | 2468 | return phy_info; |
| 2469 | } |
| 2470 | |
| 2471 | static struct mptsas_phyinfo * |
Eric Moore | b506ade | 2007-01-29 09:45:37 -0700 | [diff] [blame] | 2472 | mptsas_find_phyinfo_by_target(MPT_ADAPTER *ioc, u8 channel, u8 id) |
Christoph Hellwig | 9a28f49a | 2006-01-13 18:04:41 +0100 | [diff] [blame] | 2473 | { |
| 2474 | struct mptsas_portinfo *port_info; |
| 2475 | struct mptsas_phyinfo *phy_info = NULL; |
| 2476 | int i; |
| 2477 | |
Christoph Hellwig | 9a28f49a | 2006-01-13 18:04:41 +0100 | [diff] [blame] | 2478 | mutex_lock(&ioc->sas_topology_mutex); |
| 2479 | list_for_each_entry(port_info, &ioc->sas_topology, list) { |
Eric Moore | 547f9a2 | 2006-06-27 14:42:12 -0600 | [diff] [blame] | 2480 | for (i = 0; i < port_info->num_phys; i++) { |
Eric Moore | 547f9a2 | 2006-06-27 14:42:12 -0600 | [diff] [blame] | 2481 | if (!mptsas_is_end_device( |
| 2482 | &port_info->phy_info[i].attached)) |
| 2483 | continue; |
Eric Moore | b506ade | 2007-01-29 09:45:37 -0700 | [diff] [blame] | 2484 | if (port_info->phy_info[i].attached.id != id) |
| 2485 | continue; |
| 2486 | if (port_info->phy_info[i].attached.channel != channel) |
| 2487 | continue; |
| 2488 | phy_info = &port_info->phy_info[i]; |
| 2489 | break; |
| 2490 | } |
| 2491 | } |
| 2492 | mutex_unlock(&ioc->sas_topology_mutex); |
| 2493 | return phy_info; |
| 2494 | } |
| 2495 | |
| 2496 | static struct mptsas_phyinfo * |
| 2497 | mptsas_find_phyinfo_by_phys_disk_num(MPT_ADAPTER *ioc, u8 channel, u8 id) |
| 2498 | { |
| 2499 | struct mptsas_portinfo *port_info; |
| 2500 | struct mptsas_phyinfo *phy_info = NULL; |
| 2501 | int i; |
| 2502 | |
| 2503 | mutex_lock(&ioc->sas_topology_mutex); |
| 2504 | list_for_each_entry(port_info, &ioc->sas_topology, list) { |
| 2505 | for (i = 0; i < port_info->num_phys; i++) { |
| 2506 | if (!mptsas_is_end_device( |
| 2507 | &port_info->phy_info[i].attached)) |
| 2508 | continue; |
| 2509 | if (port_info->phy_info[i].attached.phys_disk_num == ~0) |
| 2510 | continue; |
| 2511 | if (port_info->phy_info[i].attached.phys_disk_num != id) |
| 2512 | continue; |
| 2513 | if (port_info->phy_info[i].attached.channel != channel) |
| 2514 | continue; |
Eric Moore | 547f9a2 | 2006-06-27 14:42:12 -0600 | [diff] [blame] | 2515 | phy_info = &port_info->phy_info[i]; |
| 2516 | break; |
| 2517 | } |
Christoph Hellwig | 9a28f49a | 2006-01-13 18:04:41 +0100 | [diff] [blame] | 2518 | } |
| 2519 | mutex_unlock(&ioc->sas_topology_mutex); |
Christoph Hellwig | 9a28f49a | 2006-01-13 18:04:41 +0100 | [diff] [blame] | 2520 | return phy_info; |
| 2521 | } |
| 2522 | |
Moore, Eric | 4b76647 | 2006-03-14 09:14:12 -0700 | [diff] [blame] | 2523 | /* |
| 2524 | * Work queue thread to clear the persitency table |
| 2525 | */ |
| 2526 | static void |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 2527 | mptsas_persist_clear_table(struct work_struct *work) |
Moore, Eric | 4b76647 | 2006-03-14 09:14:12 -0700 | [diff] [blame] | 2528 | { |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 2529 | MPT_ADAPTER *ioc = container_of(work, MPT_ADAPTER, sas_persist_task); |
Moore, Eric | 4b76647 | 2006-03-14 09:14:12 -0700 | [diff] [blame] | 2530 | |
| 2531 | mptbase_sas_persist_operation(ioc, MPI_SAS_OP_CLEAR_NOT_PRESENT); |
| 2532 | } |
| 2533 | |
Christoph Hellwig | 9a28f49a | 2006-01-13 18:04:41 +0100 | [diff] [blame] | 2534 | static void |
Moore, Eric | f44e546 | 2006-03-14 09:14:21 -0700 | [diff] [blame] | 2535 | mptsas_reprobe_lun(struct scsi_device *sdev, void *data) |
| 2536 | { |
Eric Moore | f99be43 | 2007-01-04 20:46:54 -0700 | [diff] [blame] | 2537 | int rc; |
| 2538 | |
Moore, Eric | f44e546 | 2006-03-14 09:14:21 -0700 | [diff] [blame] | 2539 | sdev->no_uld_attach = data ? 1 : 0; |
Eric Moore | f99be43 | 2007-01-04 20:46:54 -0700 | [diff] [blame] | 2540 | rc = scsi_device_reprobe(sdev); |
Moore, Eric | f44e546 | 2006-03-14 09:14:21 -0700 | [diff] [blame] | 2541 | } |
| 2542 | |
| 2543 | static void |
| 2544 | mptsas_reprobe_target(struct scsi_target *starget, int uld_attach) |
| 2545 | { |
| 2546 | starget_for_each_device(starget, uld_attach ? (void *)1 : NULL, |
| 2547 | mptsas_reprobe_lun); |
| 2548 | } |
| 2549 | |
Eric Moore | b506ade | 2007-01-29 09:45:37 -0700 | [diff] [blame] | 2550 | static void |
| 2551 | mptsas_adding_inactive_raid_components(MPT_ADAPTER *ioc, u8 channel, u8 id) |
| 2552 | { |
| 2553 | CONFIGPARMS cfg; |
| 2554 | ConfigPageHeader_t hdr; |
| 2555 | dma_addr_t dma_handle; |
| 2556 | pRaidVolumePage0_t buffer = NULL; |
| 2557 | RaidPhysDiskPage0_t phys_disk; |
| 2558 | int i; |
| 2559 | struct mptsas_hotplug_event *ev; |
| 2560 | |
| 2561 | memset(&cfg, 0 , sizeof(CONFIGPARMS)); |
| 2562 | memset(&hdr, 0 , sizeof(ConfigPageHeader_t)); |
| 2563 | hdr.PageType = MPI_CONFIG_PAGETYPE_RAID_VOLUME; |
| 2564 | cfg.pageAddr = (channel << 8) + id; |
| 2565 | cfg.cfghdr.hdr = &hdr; |
| 2566 | cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER; |
| 2567 | |
| 2568 | if (mpt_config(ioc, &cfg) != 0) |
| 2569 | goto out; |
| 2570 | |
| 2571 | if (!hdr.PageLength) |
| 2572 | goto out; |
| 2573 | |
| 2574 | buffer = pci_alloc_consistent(ioc->pcidev, hdr.PageLength * 4, |
| 2575 | &dma_handle); |
| 2576 | |
| 2577 | if (!buffer) |
| 2578 | goto out; |
| 2579 | |
| 2580 | cfg.physAddr = dma_handle; |
| 2581 | cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT; |
| 2582 | |
| 2583 | if (mpt_config(ioc, &cfg) != 0) |
| 2584 | goto out; |
| 2585 | |
| 2586 | if (!(buffer->VolumeStatus.Flags & |
| 2587 | MPI_RAIDVOL0_STATUS_FLAG_VOLUME_INACTIVE)) |
| 2588 | goto out; |
| 2589 | |
| 2590 | if (!buffer->NumPhysDisks) |
| 2591 | goto out; |
| 2592 | |
| 2593 | for (i = 0; i < buffer->NumPhysDisks; i++) { |
| 2594 | |
| 2595 | if (mpt_raid_phys_disk_pg0(ioc, |
| 2596 | buffer->PhysDisk[i].PhysDiskNum, &phys_disk) != 0) |
| 2597 | continue; |
| 2598 | |
| 2599 | ev = kzalloc(sizeof(*ev), GFP_ATOMIC); |
| 2600 | if (!ev) { |
Eric Moore | 29dd360 | 2007-09-14 18:46:51 -0600 | [diff] [blame] | 2601 | printk(MYIOC_s_WARN_FMT "mptsas: lost hotplug event\n", ioc->name); |
Eric Moore | b506ade | 2007-01-29 09:45:37 -0700 | [diff] [blame] | 2602 | goto out; |
| 2603 | } |
| 2604 | |
| 2605 | INIT_WORK(&ev->work, mptsas_hotplug_work); |
| 2606 | ev->ioc = ioc; |
| 2607 | ev->id = phys_disk.PhysDiskID; |
| 2608 | ev->channel = phys_disk.PhysDiskBus; |
| 2609 | ev->phys_disk_num_valid = 1; |
| 2610 | ev->phys_disk_num = phys_disk.PhysDiskNum; |
| 2611 | ev->event_type = MPTSAS_ADD_DEVICE; |
| 2612 | schedule_work(&ev->work); |
| 2613 | } |
| 2614 | |
| 2615 | out: |
| 2616 | if (buffer) |
| 2617 | pci_free_consistent(ioc->pcidev, hdr.PageLength * 4, buffer, |
| 2618 | dma_handle); |
| 2619 | } |
Moore, Eric | e6b2d76 | 2006-03-14 09:14:24 -0700 | [diff] [blame] | 2620 | /* |
| 2621 | * Work queue thread to handle SAS hotplug events |
| 2622 | */ |
Moore, Eric | f44e546 | 2006-03-14 09:14:21 -0700 | [diff] [blame] | 2623 | static void |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 2624 | mptsas_hotplug_work(struct work_struct *work) |
Christoph Hellwig | 9a28f49a | 2006-01-13 18:04:41 +0100 | [diff] [blame] | 2625 | { |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 2626 | struct mptsas_hotplug_event *ev = |
| 2627 | container_of(work, struct mptsas_hotplug_event, work); |
Eric Moore | b506ade | 2007-01-29 09:45:37 -0700 | [diff] [blame] | 2628 | |
Christoph Hellwig | 9a28f49a | 2006-01-13 18:04:41 +0100 | [diff] [blame] | 2629 | MPT_ADAPTER *ioc = ev->ioc; |
| 2630 | struct mptsas_phyinfo *phy_info; |
| 2631 | struct sas_rphy *rphy; |
Eric Moore | 547f9a2 | 2006-06-27 14:42:12 -0600 | [diff] [blame] | 2632 | struct sas_port *port; |
Moore, Eric | c73787ee | 2006-01-26 16:20:06 -0700 | [diff] [blame] | 2633 | struct scsi_device *sdev; |
Eric Moore | 547f9a2 | 2006-06-27 14:42:12 -0600 | [diff] [blame] | 2634 | struct scsi_target * starget; |
James Bottomley | f013db3 | 2006-03-18 14:54:36 -0600 | [diff] [blame] | 2635 | struct sas_identify identify; |
Christoph Hellwig | 9a28f49a | 2006-01-13 18:04:41 +0100 | [diff] [blame] | 2636 | char *ds = NULL; |
Moore, Eric | c73787ee | 2006-01-26 16:20:06 -0700 | [diff] [blame] | 2637 | struct mptsas_devinfo sas_device; |
Moore, Eric | f44e546 | 2006-03-14 09:14:21 -0700 | [diff] [blame] | 2638 | VirtTarget *vtarget; |
Eric Moore | 547f9a2 | 2006-06-27 14:42:12 -0600 | [diff] [blame] | 2639 | VirtDevice *vdevice; |
| 2640 | |
Moore, Eric | e6b2d76 | 2006-03-14 09:14:24 -0700 | [diff] [blame] | 2641 | mutex_lock(&ioc->sas_discovery_mutex); |
Christoph Hellwig | 9a28f49a | 2006-01-13 18:04:41 +0100 | [diff] [blame] | 2642 | switch (ev->event_type) { |
| 2643 | case MPTSAS_DEL_DEVICE: |
Christoph Hellwig | 9a28f49a | 2006-01-13 18:04:41 +0100 | [diff] [blame] | 2644 | |
Eric Moore | b506ade | 2007-01-29 09:45:37 -0700 | [diff] [blame] | 2645 | phy_info = NULL; |
| 2646 | if (ev->phys_disk_num_valid) { |
| 2647 | if (ev->hidden_raid_component){ |
| 2648 | if (mptsas_sas_device_pg0(ioc, &sas_device, |
| 2649 | (MPI_SAS_DEVICE_PGAD_FORM_BUS_TARGET_ID << |
| 2650 | MPI_SAS_DEVICE_PGAD_FORM_SHIFT), |
| 2651 | (ev->channel << 8) + ev->id)) { |
Prakash, Sathya | d6ecdd6 | 2007-07-24 15:47:41 +0530 | [diff] [blame] | 2652 | dfailprintk(ioc, printk(MYIOC_s_ERR_FMT |
Eric Moore | b506ade | 2007-01-29 09:45:37 -0700 | [diff] [blame] | 2653 | "%s: exit at line=%d\n", ioc->name, |
Harvey Harrison | cadbd4a | 2008-07-03 23:47:27 -0700 | [diff] [blame] | 2654 | __func__, __LINE__)); |
Eric Moore | b506ade | 2007-01-29 09:45:37 -0700 | [diff] [blame] | 2655 | break; |
| 2656 | } |
| 2657 | phy_info = mptsas_find_phyinfo_by_sas_address( |
| 2658 | ioc, sas_device.sas_address); |
| 2659 | }else |
| 2660 | phy_info = mptsas_find_phyinfo_by_phys_disk_num( |
| 2661 | ioc, ev->channel, ev->phys_disk_num); |
| 2662 | } |
| 2663 | |
| 2664 | if (!phy_info) |
| 2665 | phy_info = mptsas_find_phyinfo_by_target(ioc, |
| 2666 | ev->channel, ev->id); |
Moore, Eric | e6b2d76 | 2006-03-14 09:14:24 -0700 | [diff] [blame] | 2667 | |
Moore, Eric | f44e546 | 2006-03-14 09:14:21 -0700 | [diff] [blame] | 2668 | /* |
| 2669 | * Sanity checks, for non-existing phys and remote rphys. |
| 2670 | */ |
Eric Moore | b506ade | 2007-01-29 09:45:37 -0700 | [diff] [blame] | 2671 | if (!phy_info){ |
Prakash, Sathya | d6ecdd6 | 2007-07-24 15:47:41 +0530 | [diff] [blame] | 2672 | dfailprintk(ioc, printk(MYIOC_s_ERR_FMT |
Eric Moore | b506ade | 2007-01-29 09:45:37 -0700 | [diff] [blame] | 2673 | "%s: exit at line=%d\n", ioc->name, |
Harvey Harrison | cadbd4a | 2008-07-03 23:47:27 -0700 | [diff] [blame] | 2674 | __func__, __LINE__)); |
Eric Moore | b506ade | 2007-01-29 09:45:37 -0700 | [diff] [blame] | 2675 | break; |
| 2676 | } |
| 2677 | if (!phy_info->port_details) { |
Prakash, Sathya | d6ecdd6 | 2007-07-24 15:47:41 +0530 | [diff] [blame] | 2678 | dfailprintk(ioc, printk(MYIOC_s_ERR_FMT |
Eric Moore | 547f9a2 | 2006-06-27 14:42:12 -0600 | [diff] [blame] | 2679 | "%s: exit at line=%d\n", ioc->name, |
Harvey Harrison | cadbd4a | 2008-07-03 23:47:27 -0700 | [diff] [blame] | 2680 | __func__, __LINE__)); |
Christoph Hellwig | 9a28f49a | 2006-01-13 18:04:41 +0100 | [diff] [blame] | 2681 | break; |
Eric Moore | 547f9a2 | 2006-06-27 14:42:12 -0600 | [diff] [blame] | 2682 | } |
| 2683 | rphy = mptsas_get_rphy(phy_info); |
| 2684 | if (!rphy) { |
Prakash, Sathya | d6ecdd6 | 2007-07-24 15:47:41 +0530 | [diff] [blame] | 2685 | dfailprintk(ioc, printk(MYIOC_s_ERR_FMT |
Eric Moore | 547f9a2 | 2006-06-27 14:42:12 -0600 | [diff] [blame] | 2686 | "%s: exit at line=%d\n", ioc->name, |
Harvey Harrison | cadbd4a | 2008-07-03 23:47:27 -0700 | [diff] [blame] | 2687 | __func__, __LINE__)); |
Moore, Eric | f44e546 | 2006-03-14 09:14:21 -0700 | [diff] [blame] | 2688 | break; |
Eric Moore | 547f9a2 | 2006-06-27 14:42:12 -0600 | [diff] [blame] | 2689 | } |
Eric Moore | b506ade | 2007-01-29 09:45:37 -0700 | [diff] [blame] | 2690 | |
Eric Moore | 547f9a2 | 2006-06-27 14:42:12 -0600 | [diff] [blame] | 2691 | port = mptsas_get_port(phy_info); |
| 2692 | if (!port) { |
Prakash, Sathya | d6ecdd6 | 2007-07-24 15:47:41 +0530 | [diff] [blame] | 2693 | dfailprintk(ioc, printk(MYIOC_s_ERR_FMT |
Eric Moore | 547f9a2 | 2006-06-27 14:42:12 -0600 | [diff] [blame] | 2694 | "%s: exit at line=%d\n", ioc->name, |
Harvey Harrison | cadbd4a | 2008-07-03 23:47:27 -0700 | [diff] [blame] | 2695 | __func__, __LINE__)); |
Eric Moore | 547f9a2 | 2006-06-27 14:42:12 -0600 | [diff] [blame] | 2696 | break; |
| 2697 | } |
Moore, Eric | f44e546 | 2006-03-14 09:14:21 -0700 | [diff] [blame] | 2698 | |
Eric Moore | 547f9a2 | 2006-06-27 14:42:12 -0600 | [diff] [blame] | 2699 | starget = mptsas_get_starget(phy_info); |
| 2700 | if (starget) { |
| 2701 | vtarget = starget->hostdata; |
| 2702 | |
| 2703 | if (!vtarget) { |
Prakash, Sathya | d6ecdd6 | 2007-07-24 15:47:41 +0530 | [diff] [blame] | 2704 | dfailprintk(ioc, printk(MYIOC_s_ERR_FMT |
Eric Moore | 547f9a2 | 2006-06-27 14:42:12 -0600 | [diff] [blame] | 2705 | "%s: exit at line=%d\n", ioc->name, |
Harvey Harrison | cadbd4a | 2008-07-03 23:47:27 -0700 | [diff] [blame] | 2706 | __func__, __LINE__)); |
Moore, Eric | f44e546 | 2006-03-14 09:14:21 -0700 | [diff] [blame] | 2707 | break; |
Eric Moore | 547f9a2 | 2006-06-27 14:42:12 -0600 | [diff] [blame] | 2708 | } |
| 2709 | |
Moore, Eric | f44e546 | 2006-03-14 09:14:21 -0700 | [diff] [blame] | 2710 | /* |
| 2711 | * Handling RAID components |
| 2712 | */ |
Eric Moore | b506ade | 2007-01-29 09:45:37 -0700 | [diff] [blame] | 2713 | if (ev->phys_disk_num_valid && |
| 2714 | ev->hidden_raid_component) { |
| 2715 | printk(MYIOC_s_INFO_FMT |
| 2716 | "RAID Hidding: channel=%d, id=%d, " |
| 2717 | "physdsk %d \n", ioc->name, ev->channel, |
| 2718 | ev->id, ev->phys_disk_num); |
Eric Moore | 793955f | 2007-01-29 09:42:20 -0700 | [diff] [blame] | 2719 | vtarget->id = ev->phys_disk_num; |
Eric Moore | b506ade | 2007-01-29 09:45:37 -0700 | [diff] [blame] | 2720 | vtarget->tflags |= |
| 2721 | MPT_TARGET_FLAGS_RAID_COMPONENT; |
Eric Moore | 547f9a2 | 2006-06-27 14:42:12 -0600 | [diff] [blame] | 2722 | mptsas_reprobe_target(starget, 1); |
Eric Moore | b506ade | 2007-01-29 09:45:37 -0700 | [diff] [blame] | 2723 | phy_info->attached.phys_disk_num = |
| 2724 | ev->phys_disk_num; |
| 2725 | break; |
Moore, Eric | f44e546 | 2006-03-14 09:14:21 -0700 | [diff] [blame] | 2726 | } |
Christoph Hellwig | 9a28f49a | 2006-01-13 18:04:41 +0100 | [diff] [blame] | 2727 | } |
| 2728 | |
Eric Moore | b506ade | 2007-01-29 09:45:37 -0700 | [diff] [blame] | 2729 | if (phy_info->attached.device_info & |
| 2730 | MPI_SAS_DEVICE_INFO_SSP_TARGET) |
Moore, Eric | c73787ee | 2006-01-26 16:20:06 -0700 | [diff] [blame] | 2731 | ds = "ssp"; |
Eric Moore | b506ade | 2007-01-29 09:45:37 -0700 | [diff] [blame] | 2732 | if (phy_info->attached.device_info & |
| 2733 | MPI_SAS_DEVICE_INFO_STP_TARGET) |
Moore, Eric | c73787ee | 2006-01-26 16:20:06 -0700 | [diff] [blame] | 2734 | ds = "stp"; |
Eric Moore | b506ade | 2007-01-29 09:45:37 -0700 | [diff] [blame] | 2735 | if (phy_info->attached.device_info & |
| 2736 | MPI_SAS_DEVICE_INFO_SATA_DEVICE) |
Moore, Eric | c73787ee | 2006-01-26 16:20:06 -0700 | [diff] [blame] | 2737 | ds = "sata"; |
| 2738 | |
| 2739 | printk(MYIOC_s_INFO_FMT |
| 2740 | "removing %s device, channel %d, id %d, phy %d\n", |
| 2741 | ioc->name, ds, ev->channel, ev->id, phy_info->phy_id); |
Eric Moore | c51d0be | 2007-09-29 10:17:21 -0600 | [diff] [blame] | 2742 | dev_printk(KERN_DEBUG, &port->dev, MYIOC_s_FMT |
Eric Moore | 29dd360 | 2007-09-14 18:46:51 -0600 | [diff] [blame] | 2743 | "delete port (%d)\n", ioc->name, port->port_identifier); |
Eric Moore | 547f9a2 | 2006-06-27 14:42:12 -0600 | [diff] [blame] | 2744 | sas_port_delete(port); |
Prakash, Sathya | d6ecdd6 | 2007-07-24 15:47:41 +0530 | [diff] [blame] | 2745 | mptsas_port_delete(ioc, phy_info->port_details); |
Christoph Hellwig | 9a28f49a | 2006-01-13 18:04:41 +0100 | [diff] [blame] | 2746 | break; |
| 2747 | case MPTSAS_ADD_DEVICE: |
Moore, Eric | c73787ee | 2006-01-26 16:20:06 -0700 | [diff] [blame] | 2748 | |
Moore, Eric | bd23e94 | 2006-04-17 12:43:04 -0600 | [diff] [blame] | 2749 | if (ev->phys_disk_num_valid) |
| 2750 | mpt_findImVolumes(ioc); |
| 2751 | |
Moore, Eric | c73787ee | 2006-01-26 16:20:06 -0700 | [diff] [blame] | 2752 | /* |
Christoph Hellwig | e309444 | 2006-02-16 13:25:36 +0100 | [diff] [blame] | 2753 | * Refresh sas device pg0 data |
Moore, Eric | c73787ee | 2006-01-26 16:20:06 -0700 | [diff] [blame] | 2754 | */ |
Christoph Hellwig | e309444 | 2006-02-16 13:25:36 +0100 | [diff] [blame] | 2755 | if (mptsas_sas_device_pg0(ioc, &sas_device, |
| 2756 | (MPI_SAS_DEVICE_PGAD_FORM_BUS_TARGET_ID << |
Eric Moore | b506ade | 2007-01-29 09:45:37 -0700 | [diff] [blame] | 2757 | MPI_SAS_DEVICE_PGAD_FORM_SHIFT), |
| 2758 | (ev->channel << 8) + ev->id)) { |
Prakash, Sathya | d6ecdd6 | 2007-07-24 15:47:41 +0530 | [diff] [blame] | 2759 | dfailprintk(ioc, printk(MYIOC_s_ERR_FMT |
Eric Moore | 547f9a2 | 2006-06-27 14:42:12 -0600 | [diff] [blame] | 2760 | "%s: exit at line=%d\n", ioc->name, |
Harvey Harrison | cadbd4a | 2008-07-03 23:47:27 -0700 | [diff] [blame] | 2761 | __func__, __LINE__)); |
Christoph Hellwig | e309444 | 2006-02-16 13:25:36 +0100 | [diff] [blame] | 2762 | break; |
Moore, Eric | e6b2d76 | 2006-03-14 09:14:24 -0700 | [diff] [blame] | 2763 | } |
| 2764 | |
Eric Moore | 547f9a2 | 2006-06-27 14:42:12 -0600 | [diff] [blame] | 2765 | __mptsas_discovery_work(ioc); |
Moore, Eric | f44e546 | 2006-03-14 09:14:21 -0700 | [diff] [blame] | 2766 | |
Eric Moore | 547f9a2 | 2006-06-27 14:42:12 -0600 | [diff] [blame] | 2767 | phy_info = mptsas_find_phyinfo_by_sas_address(ioc, |
| 2768 | sas_device.sas_address); |
| 2769 | |
| 2770 | if (!phy_info || !phy_info->port_details) { |
Prakash, Sathya | d6ecdd6 | 2007-07-24 15:47:41 +0530 | [diff] [blame] | 2771 | dfailprintk(ioc, printk(MYIOC_s_ERR_FMT |
Eric Moore | 547f9a2 | 2006-06-27 14:42:12 -0600 | [diff] [blame] | 2772 | "%s: exit at line=%d\n", ioc->name, |
Harvey Harrison | cadbd4a | 2008-07-03 23:47:27 -0700 | [diff] [blame] | 2773 | __func__, __LINE__)); |
Eric Moore | 547f9a2 | 2006-06-27 14:42:12 -0600 | [diff] [blame] | 2774 | break; |
| 2775 | } |
| 2776 | |
| 2777 | starget = mptsas_get_starget(phy_info); |
Eric Moore | b506ade | 2007-01-29 09:45:37 -0700 | [diff] [blame] | 2778 | if (starget && (!ev->hidden_raid_component)){ |
| 2779 | |
Eric Moore | 547f9a2 | 2006-06-27 14:42:12 -0600 | [diff] [blame] | 2780 | vtarget = starget->hostdata; |
| 2781 | |
| 2782 | if (!vtarget) { |
Prakash, Sathya | d6ecdd6 | 2007-07-24 15:47:41 +0530 | [diff] [blame] | 2783 | dfailprintk(ioc, printk(MYIOC_s_ERR_FMT |
Eric Moore | 29dd360 | 2007-09-14 18:46:51 -0600 | [diff] [blame] | 2784 | "%s: exit at line=%d\n", ioc->name, |
Harvey Harrison | cadbd4a | 2008-07-03 23:47:27 -0700 | [diff] [blame] | 2785 | __func__, __LINE__)); |
Moore, Eric | f44e546 | 2006-03-14 09:14:21 -0700 | [diff] [blame] | 2786 | break; |
Eric Moore | 547f9a2 | 2006-06-27 14:42:12 -0600 | [diff] [blame] | 2787 | } |
Moore, Eric | f44e546 | 2006-03-14 09:14:21 -0700 | [diff] [blame] | 2788 | /* |
| 2789 | * Handling RAID components |
| 2790 | */ |
| 2791 | if (vtarget->tflags & MPT_TARGET_FLAGS_RAID_COMPONENT) { |
Eric Moore | b506ade | 2007-01-29 09:45:37 -0700 | [diff] [blame] | 2792 | printk(MYIOC_s_INFO_FMT |
| 2793 | "RAID Exposing: channel=%d, id=%d, " |
| 2794 | "physdsk %d \n", ioc->name, ev->channel, |
| 2795 | ev->id, ev->phys_disk_num); |
| 2796 | vtarget->tflags &= |
| 2797 | ~MPT_TARGET_FLAGS_RAID_COMPONENT; |
Eric Moore | 793955f | 2007-01-29 09:42:20 -0700 | [diff] [blame] | 2798 | vtarget->id = ev->id; |
Eric Moore | 547f9a2 | 2006-06-27 14:42:12 -0600 | [diff] [blame] | 2799 | mptsas_reprobe_target(starget, 0); |
Eric Moore | b506ade | 2007-01-29 09:45:37 -0700 | [diff] [blame] | 2800 | phy_info->attached.phys_disk_num = ~0; |
Moore, Eric | f44e546 | 2006-03-14 09:14:21 -0700 | [diff] [blame] | 2801 | } |
Christoph Hellwig | 9a28f49a | 2006-01-13 18:04:41 +0100 | [diff] [blame] | 2802 | break; |
| 2803 | } |
| 2804 | |
Eric Moore | 547f9a2 | 2006-06-27 14:42:12 -0600 | [diff] [blame] | 2805 | if (mptsas_get_rphy(phy_info)) { |
Prakash, Sathya | d6ecdd6 | 2007-07-24 15:47:41 +0530 | [diff] [blame] | 2806 | dfailprintk(ioc, printk(MYIOC_s_ERR_FMT |
Eric Moore | 547f9a2 | 2006-06-27 14:42:12 -0600 | [diff] [blame] | 2807 | "%s: exit at line=%d\n", ioc->name, |
Harvey Harrison | cadbd4a | 2008-07-03 23:47:27 -0700 | [diff] [blame] | 2808 | __func__, __LINE__)); |
Eric Moore | b506ade | 2007-01-29 09:45:37 -0700 | [diff] [blame] | 2809 | if (ev->channel) printk("%d\n", __LINE__); |
Christoph Hellwig | 9a28f49a | 2006-01-13 18:04:41 +0100 | [diff] [blame] | 2810 | break; |
Eric Moore | 547f9a2 | 2006-06-27 14:42:12 -0600 | [diff] [blame] | 2811 | } |
Eric Moore | b506ade | 2007-01-29 09:45:37 -0700 | [diff] [blame] | 2812 | |
Eric Moore | 547f9a2 | 2006-06-27 14:42:12 -0600 | [diff] [blame] | 2813 | port = mptsas_get_port(phy_info); |
| 2814 | if (!port) { |
Prakash, Sathya | d6ecdd6 | 2007-07-24 15:47:41 +0530 | [diff] [blame] | 2815 | dfailprintk(ioc, printk(MYIOC_s_ERR_FMT |
Eric Moore | 547f9a2 | 2006-06-27 14:42:12 -0600 | [diff] [blame] | 2816 | "%s: exit at line=%d\n", ioc->name, |
Harvey Harrison | cadbd4a | 2008-07-03 23:47:27 -0700 | [diff] [blame] | 2817 | __func__, __LINE__)); |
Eric Moore | 547f9a2 | 2006-06-27 14:42:12 -0600 | [diff] [blame] | 2818 | break; |
| 2819 | } |
Christoph Hellwig | e309444 | 2006-02-16 13:25:36 +0100 | [diff] [blame] | 2820 | memcpy(&phy_info->attached, &sas_device, |
| 2821 | sizeof(struct mptsas_devinfo)); |
Christoph Hellwig | 9a28f49a | 2006-01-13 18:04:41 +0100 | [diff] [blame] | 2822 | |
Eric Moore | b506ade | 2007-01-29 09:45:37 -0700 | [diff] [blame] | 2823 | if (phy_info->attached.device_info & |
| 2824 | MPI_SAS_DEVICE_INFO_SSP_TARGET) |
Moore, Eric | c73787ee | 2006-01-26 16:20:06 -0700 | [diff] [blame] | 2825 | ds = "ssp"; |
Eric Moore | b506ade | 2007-01-29 09:45:37 -0700 | [diff] [blame] | 2826 | if (phy_info->attached.device_info & |
| 2827 | MPI_SAS_DEVICE_INFO_STP_TARGET) |
Moore, Eric | c73787ee | 2006-01-26 16:20:06 -0700 | [diff] [blame] | 2828 | ds = "stp"; |
Eric Moore | b506ade | 2007-01-29 09:45:37 -0700 | [diff] [blame] | 2829 | if (phy_info->attached.device_info & |
| 2830 | MPI_SAS_DEVICE_INFO_SATA_DEVICE) |
Moore, Eric | c73787ee | 2006-01-26 16:20:06 -0700 | [diff] [blame] | 2831 | ds = "sata"; |
| 2832 | |
| 2833 | printk(MYIOC_s_INFO_FMT |
| 2834 | "attaching %s device, channel %d, id %d, phy %d\n", |
| 2835 | ioc->name, ds, ev->channel, ev->id, ev->phy_id); |
| 2836 | |
James Bottomley | f013db3 | 2006-03-18 14:54:36 -0600 | [diff] [blame] | 2837 | mptsas_parse_device_info(&identify, &phy_info->attached); |
Eric Moore | 547f9a2 | 2006-06-27 14:42:12 -0600 | [diff] [blame] | 2838 | rphy = sas_end_device_alloc(port); |
| 2839 | if (!rphy) { |
Prakash, Sathya | d6ecdd6 | 2007-07-24 15:47:41 +0530 | [diff] [blame] | 2840 | dfailprintk(ioc, printk(MYIOC_s_ERR_FMT |
Eric Moore | 547f9a2 | 2006-06-27 14:42:12 -0600 | [diff] [blame] | 2841 | "%s: exit at line=%d\n", ioc->name, |
Harvey Harrison | cadbd4a | 2008-07-03 23:47:27 -0700 | [diff] [blame] | 2842 | __func__, __LINE__)); |
Christoph Hellwig | 9a28f49a | 2006-01-13 18:04:41 +0100 | [diff] [blame] | 2843 | break; /* non-fatal: an rphy can be added later */ |
Eric Moore | 547f9a2 | 2006-06-27 14:42:12 -0600 | [diff] [blame] | 2844 | } |
Christoph Hellwig | 9a28f49a | 2006-01-13 18:04:41 +0100 | [diff] [blame] | 2845 | |
James Bottomley | f013db3 | 2006-03-18 14:54:36 -0600 | [diff] [blame] | 2846 | rphy->identify = identify; |
Christoph Hellwig | 9a28f49a | 2006-01-13 18:04:41 +0100 | [diff] [blame] | 2847 | if (sas_rphy_add(rphy)) { |
Prakash, Sathya | d6ecdd6 | 2007-07-24 15:47:41 +0530 | [diff] [blame] | 2848 | dfailprintk(ioc, printk(MYIOC_s_ERR_FMT |
Eric Moore | 547f9a2 | 2006-06-27 14:42:12 -0600 | [diff] [blame] | 2849 | "%s: exit at line=%d\n", ioc->name, |
Harvey Harrison | cadbd4a | 2008-07-03 23:47:27 -0700 | [diff] [blame] | 2850 | __func__, __LINE__)); |
Christoph Hellwig | 9a28f49a | 2006-01-13 18:04:41 +0100 | [diff] [blame] | 2851 | sas_rphy_free(rphy); |
| 2852 | break; |
| 2853 | } |
Prakash, Sathya | d6ecdd6 | 2007-07-24 15:47:41 +0530 | [diff] [blame] | 2854 | mptsas_set_rphy(ioc, phy_info, rphy); |
Christoph Hellwig | 9a28f49a | 2006-01-13 18:04:41 +0100 | [diff] [blame] | 2855 | break; |
Moore, Eric | c73787ee | 2006-01-26 16:20:06 -0700 | [diff] [blame] | 2856 | case MPTSAS_ADD_RAID: |
James Bottomley | e8bf394 | 2006-07-11 17:49:34 -0400 | [diff] [blame] | 2857 | sdev = scsi_device_lookup(ioc->sh, MPTSAS_RAID_CHANNEL, |
| 2858 | ev->id, 0); |
Moore, Eric | c73787ee | 2006-01-26 16:20:06 -0700 | [diff] [blame] | 2859 | if (sdev) { |
| 2860 | scsi_device_put(sdev); |
| 2861 | break; |
| 2862 | } |
| 2863 | printk(MYIOC_s_INFO_FMT |
Moore, Eric | 4b76647 | 2006-03-14 09:14:12 -0700 | [diff] [blame] | 2864 | "attaching raid volume, channel %d, id %d\n", |
James Bottomley | e8bf394 | 2006-07-11 17:49:34 -0400 | [diff] [blame] | 2865 | ioc->name, MPTSAS_RAID_CHANNEL, ev->id); |
| 2866 | scsi_add_device(ioc->sh, MPTSAS_RAID_CHANNEL, ev->id, 0); |
Moore, Eric | c73787ee | 2006-01-26 16:20:06 -0700 | [diff] [blame] | 2867 | mpt_findImVolumes(ioc); |
| 2868 | break; |
| 2869 | case MPTSAS_DEL_RAID: |
James Bottomley | e8bf394 | 2006-07-11 17:49:34 -0400 | [diff] [blame] | 2870 | sdev = scsi_device_lookup(ioc->sh, MPTSAS_RAID_CHANNEL, |
Eric Moore | b506ade | 2007-01-29 09:45:37 -0700 | [diff] [blame] | 2871 | ev->id, 0); |
Moore, Eric | c73787ee | 2006-01-26 16:20:06 -0700 | [diff] [blame] | 2872 | if (!sdev) |
| 2873 | break; |
| 2874 | printk(MYIOC_s_INFO_FMT |
Moore, Eric | 4b76647 | 2006-03-14 09:14:12 -0700 | [diff] [blame] | 2875 | "removing raid volume, channel %d, id %d\n", |
James Bottomley | e8bf394 | 2006-07-11 17:49:34 -0400 | [diff] [blame] | 2876 | ioc->name, MPTSAS_RAID_CHANNEL, ev->id); |
Eric Moore | b506ade | 2007-01-29 09:45:37 -0700 | [diff] [blame] | 2877 | vdevice = sdev->hostdata; |
Moore, Eric | c73787ee | 2006-01-26 16:20:06 -0700 | [diff] [blame] | 2878 | scsi_remove_device(sdev); |
| 2879 | scsi_device_put(sdev); |
| 2880 | mpt_findImVolumes(ioc); |
| 2881 | break; |
Eric Moore | b506ade | 2007-01-29 09:45:37 -0700 | [diff] [blame] | 2882 | case MPTSAS_ADD_INACTIVE_VOLUME: |
| 2883 | mptsas_adding_inactive_raid_components(ioc, |
| 2884 | ev->channel, ev->id); |
| 2885 | break; |
Moore, Eric | bd23e94 | 2006-04-17 12:43:04 -0600 | [diff] [blame] | 2886 | case MPTSAS_IGNORE_EVENT: |
| 2887 | default: |
| 2888 | break; |
Christoph Hellwig | 9a28f49a | 2006-01-13 18:04:41 +0100 | [diff] [blame] | 2889 | } |
| 2890 | |
Moore, Eric | e6b2d76 | 2006-03-14 09:14:24 -0700 | [diff] [blame] | 2891 | mutex_unlock(&ioc->sas_discovery_mutex); |
Eric Moore | 547f9a2 | 2006-06-27 14:42:12 -0600 | [diff] [blame] | 2892 | kfree(ev); |
Christoph Hellwig | 9a28f49a | 2006-01-13 18:04:41 +0100 | [diff] [blame] | 2893 | } |
| 2894 | |
| 2895 | static void |
Eric Moore | 547f9a2 | 2006-06-27 14:42:12 -0600 | [diff] [blame] | 2896 | mptsas_send_sas_event(MPT_ADAPTER *ioc, |
Christoph Hellwig | 9a28f49a | 2006-01-13 18:04:41 +0100 | [diff] [blame] | 2897 | EVENT_DATA_SAS_DEVICE_STATUS_CHANGE *sas_event_data) |
| 2898 | { |
| 2899 | struct mptsas_hotplug_event *ev; |
| 2900 | u32 device_info = le32_to_cpu(sas_event_data->DeviceInfo); |
| 2901 | __le64 sas_address; |
| 2902 | |
| 2903 | if ((device_info & |
| 2904 | (MPI_SAS_DEVICE_INFO_SSP_TARGET | |
| 2905 | MPI_SAS_DEVICE_INFO_STP_TARGET | |
| 2906 | MPI_SAS_DEVICE_INFO_SATA_DEVICE )) == 0) |
| 2907 | return; |
| 2908 | |
Moore, Eric | 4b76647 | 2006-03-14 09:14:12 -0700 | [diff] [blame] | 2909 | switch (sas_event_data->ReasonCode) { |
Moore, Eric | 4b76647 | 2006-03-14 09:14:12 -0700 | [diff] [blame] | 2910 | case MPI_EVENT_SAS_DEV_STAT_RC_NOT_RESPONDING: |
Eric Moore | df9e062 | 2007-01-29 09:46:21 -0700 | [diff] [blame] | 2911 | |
| 2912 | mptsas_target_reset_queue(ioc, sas_event_data); |
| 2913 | break; |
| 2914 | |
| 2915 | case MPI_EVENT_SAS_DEV_STAT_RC_ADDED: |
Eric Moore | 547f9a2 | 2006-06-27 14:42:12 -0600 | [diff] [blame] | 2916 | ev = kzalloc(sizeof(*ev), GFP_ATOMIC); |
Moore, Eric | 4b76647 | 2006-03-14 09:14:12 -0700 | [diff] [blame] | 2917 | if (!ev) { |
Eric Moore | 29dd360 | 2007-09-14 18:46:51 -0600 | [diff] [blame] | 2918 | printk(MYIOC_s_WARN_FMT "lost hotplug event\n", ioc->name); |
Moore, Eric | 4b76647 | 2006-03-14 09:14:12 -0700 | [diff] [blame] | 2919 | break; |
| 2920 | } |
Christoph Hellwig | 9a28f49a | 2006-01-13 18:04:41 +0100 | [diff] [blame] | 2921 | |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 2922 | INIT_WORK(&ev->work, mptsas_hotplug_work); |
Moore, Eric | 4b76647 | 2006-03-14 09:14:12 -0700 | [diff] [blame] | 2923 | ev->ioc = ioc; |
| 2924 | ev->handle = le16_to_cpu(sas_event_data->DevHandle); |
| 2925 | ev->parent_handle = |
| 2926 | le16_to_cpu(sas_event_data->ParentDevHandle); |
| 2927 | ev->channel = sas_event_data->Bus; |
| 2928 | ev->id = sas_event_data->TargetID; |
| 2929 | ev->phy_id = sas_event_data->PhyNum; |
| 2930 | memcpy(&sas_address, &sas_event_data->SASAddress, |
| 2931 | sizeof(__le64)); |
| 2932 | ev->sas_address = le64_to_cpu(sas_address); |
| 2933 | ev->device_info = device_info; |
| 2934 | |
| 2935 | if (sas_event_data->ReasonCode & |
| 2936 | MPI_EVENT_SAS_DEV_STAT_RC_ADDED) |
| 2937 | ev->event_type = MPTSAS_ADD_DEVICE; |
| 2938 | else |
| 2939 | ev->event_type = MPTSAS_DEL_DEVICE; |
| 2940 | schedule_work(&ev->work); |
| 2941 | break; |
| 2942 | case MPI_EVENT_SAS_DEV_STAT_RC_NO_PERSIST_ADDED: |
| 2943 | /* |
| 2944 | * Persistent table is full. |
| 2945 | */ |
Eric Moore | 547f9a2 | 2006-06-27 14:42:12 -0600 | [diff] [blame] | 2946 | INIT_WORK(&ioc->sas_persist_task, |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 2947 | mptsas_persist_clear_table); |
Eric Moore | 547f9a2 | 2006-06-27 14:42:12 -0600 | [diff] [blame] | 2948 | schedule_work(&ioc->sas_persist_task); |
Moore, Eric | 4b76647 | 2006-03-14 09:14:12 -0700 | [diff] [blame] | 2949 | break; |
Eric Moore | b506ade | 2007-01-29 09:45:37 -0700 | [diff] [blame] | 2950 | /* |
| 2951 | * TODO, handle other events |
| 2952 | */ |
Moore, Eric | 4b76647 | 2006-03-14 09:14:12 -0700 | [diff] [blame] | 2953 | case MPI_EVENT_SAS_DEV_STAT_RC_SMART_DATA: |
Eric Moore | b506ade | 2007-01-29 09:45:37 -0700 | [diff] [blame] | 2954 | case MPI_EVENT_SAS_DEV_STAT_RC_UNSUPPORTED: |
Moore, Eric | 4b76647 | 2006-03-14 09:14:12 -0700 | [diff] [blame] | 2955 | case MPI_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET: |
Eric Moore | b506ade | 2007-01-29 09:45:37 -0700 | [diff] [blame] | 2956 | case MPI_EVENT_SAS_DEV_STAT_RC_TASK_ABORT_INTERNAL: |
| 2957 | case MPI_EVENT_SAS_DEV_STAT_RC_ABORT_TASK_SET_INTERNAL: |
| 2958 | case MPI_EVENT_SAS_DEV_STAT_RC_CLEAR_TASK_SET_INTERNAL: |
| 2959 | case MPI_EVENT_SAS_DEV_STAT_RC_QUERY_TASK_INTERNAL: |
Moore, Eric | 4b76647 | 2006-03-14 09:14:12 -0700 | [diff] [blame] | 2960 | default: |
| 2961 | break; |
Christoph Hellwig | 9a28f49a | 2006-01-13 18:04:41 +0100 | [diff] [blame] | 2962 | } |
Christoph Hellwig | 9a28f49a | 2006-01-13 18:04:41 +0100 | [diff] [blame] | 2963 | } |
Moore, Eric | c73787ee | 2006-01-26 16:20:06 -0700 | [diff] [blame] | 2964 | static void |
Eric Moore | 547f9a2 | 2006-06-27 14:42:12 -0600 | [diff] [blame] | 2965 | mptsas_send_raid_event(MPT_ADAPTER *ioc, |
Moore, Eric | c73787ee | 2006-01-26 16:20:06 -0700 | [diff] [blame] | 2966 | EVENT_DATA_RAID *raid_event_data) |
| 2967 | { |
| 2968 | struct mptsas_hotplug_event *ev; |
Moore, Eric | bd23e94 | 2006-04-17 12:43:04 -0600 | [diff] [blame] | 2969 | int status = le32_to_cpu(raid_event_data->SettingsStatus); |
| 2970 | int state = (status >> 8) & 0xff; |
Moore, Eric | c73787ee | 2006-01-26 16:20:06 -0700 | [diff] [blame] | 2971 | |
| 2972 | if (ioc->bus_type != SAS) |
| 2973 | return; |
| 2974 | |
Eric Moore | 547f9a2 | 2006-06-27 14:42:12 -0600 | [diff] [blame] | 2975 | ev = kzalloc(sizeof(*ev), GFP_ATOMIC); |
Moore, Eric | c73787ee | 2006-01-26 16:20:06 -0700 | [diff] [blame] | 2976 | if (!ev) { |
Eric Moore | 29dd360 | 2007-09-14 18:46:51 -0600 | [diff] [blame] | 2977 | printk(MYIOC_s_WARN_FMT "lost hotplug event\n", ioc->name); |
Moore, Eric | c73787ee | 2006-01-26 16:20:06 -0700 | [diff] [blame] | 2978 | return; |
| 2979 | } |
| 2980 | |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 2981 | INIT_WORK(&ev->work, mptsas_hotplug_work); |
Moore, Eric | c73787ee | 2006-01-26 16:20:06 -0700 | [diff] [blame] | 2982 | ev->ioc = ioc; |
| 2983 | ev->id = raid_event_data->VolumeID; |
Eric Moore | b506ade | 2007-01-29 09:45:37 -0700 | [diff] [blame] | 2984 | ev->channel = raid_event_data->VolumeBus; |
Moore, Eric | bd23e94 | 2006-04-17 12:43:04 -0600 | [diff] [blame] | 2985 | ev->event_type = MPTSAS_IGNORE_EVENT; |
Moore, Eric | c73787ee | 2006-01-26 16:20:06 -0700 | [diff] [blame] | 2986 | |
| 2987 | switch (raid_event_data->ReasonCode) { |
| 2988 | case MPI_EVENT_RAID_RC_PHYSDISK_DELETED: |
Eric Moore | b506ade | 2007-01-29 09:45:37 -0700 | [diff] [blame] | 2989 | ev->phys_disk_num_valid = 1; |
| 2990 | ev->phys_disk_num = raid_event_data->PhysDiskNum; |
Moore, Eric | c73787ee | 2006-01-26 16:20:06 -0700 | [diff] [blame] | 2991 | ev->event_type = MPTSAS_ADD_DEVICE; |
| 2992 | break; |
| 2993 | case MPI_EVENT_RAID_RC_PHYSDISK_CREATED: |
Moore, Eric | f44e546 | 2006-03-14 09:14:21 -0700 | [diff] [blame] | 2994 | ev->phys_disk_num_valid = 1; |
| 2995 | ev->phys_disk_num = raid_event_data->PhysDiskNum; |
Eric Moore | b506ade | 2007-01-29 09:45:37 -0700 | [diff] [blame] | 2996 | ev->hidden_raid_component = 1; |
Moore, Eric | c73787ee | 2006-01-26 16:20:06 -0700 | [diff] [blame] | 2997 | ev->event_type = MPTSAS_DEL_DEVICE; |
| 2998 | break; |
Moore, Eric | bd23e94 | 2006-04-17 12:43:04 -0600 | [diff] [blame] | 2999 | case MPI_EVENT_RAID_RC_PHYSDISK_STATUS_CHANGED: |
| 3000 | switch (state) { |
| 3001 | case MPI_PD_STATE_ONLINE: |
Eric Moore | b506ade | 2007-01-29 09:45:37 -0700 | [diff] [blame] | 3002 | case MPI_PD_STATE_NOT_COMPATIBLE: |
Moore, Eric | bd23e94 | 2006-04-17 12:43:04 -0600 | [diff] [blame] | 3003 | ev->phys_disk_num_valid = 1; |
| 3004 | ev->phys_disk_num = raid_event_data->PhysDiskNum; |
Eric Moore | b506ade | 2007-01-29 09:45:37 -0700 | [diff] [blame] | 3005 | ev->hidden_raid_component = 1; |
Moore, Eric | bd23e94 | 2006-04-17 12:43:04 -0600 | [diff] [blame] | 3006 | ev->event_type = MPTSAS_ADD_DEVICE; |
| 3007 | break; |
| 3008 | case MPI_PD_STATE_MISSING: |
Moore, Eric | bd23e94 | 2006-04-17 12:43:04 -0600 | [diff] [blame] | 3009 | case MPI_PD_STATE_OFFLINE_AT_HOST_REQUEST: |
| 3010 | case MPI_PD_STATE_FAILED_AT_HOST_REQUEST: |
| 3011 | case MPI_PD_STATE_OFFLINE_FOR_ANOTHER_REASON: |
Eric Moore | b506ade | 2007-01-29 09:45:37 -0700 | [diff] [blame] | 3012 | ev->phys_disk_num_valid = 1; |
| 3013 | ev->phys_disk_num = raid_event_data->PhysDiskNum; |
Moore, Eric | bd23e94 | 2006-04-17 12:43:04 -0600 | [diff] [blame] | 3014 | ev->event_type = MPTSAS_DEL_DEVICE; |
| 3015 | break; |
| 3016 | default: |
| 3017 | break; |
| 3018 | } |
| 3019 | break; |
Moore, Eric | c73787ee | 2006-01-26 16:20:06 -0700 | [diff] [blame] | 3020 | case MPI_EVENT_RAID_RC_VOLUME_DELETED: |
| 3021 | ev->event_type = MPTSAS_DEL_RAID; |
| 3022 | break; |
| 3023 | case MPI_EVENT_RAID_RC_VOLUME_CREATED: |
| 3024 | ev->event_type = MPTSAS_ADD_RAID; |
| 3025 | break; |
| 3026 | case MPI_EVENT_RAID_RC_VOLUME_STATUS_CHANGED: |
Moore, Eric | bd23e94 | 2006-04-17 12:43:04 -0600 | [diff] [blame] | 3027 | switch (state) { |
| 3028 | case MPI_RAIDVOL0_STATUS_STATE_FAILED: |
| 3029 | case MPI_RAIDVOL0_STATUS_STATE_MISSING: |
| 3030 | ev->event_type = MPTSAS_DEL_RAID; |
| 3031 | break; |
| 3032 | case MPI_RAIDVOL0_STATUS_STATE_OPTIMAL: |
| 3033 | case MPI_RAIDVOL0_STATUS_STATE_DEGRADED: |
| 3034 | ev->event_type = MPTSAS_ADD_RAID; |
| 3035 | break; |
| 3036 | default: |
| 3037 | break; |
| 3038 | } |
Moore, Eric | c73787ee | 2006-01-26 16:20:06 -0700 | [diff] [blame] | 3039 | break; |
| 3040 | default: |
| 3041 | break; |
| 3042 | } |
| 3043 | schedule_work(&ev->work); |
| 3044 | } |
| 3045 | |
Moore, Eric | e6b2d76 | 2006-03-14 09:14:24 -0700 | [diff] [blame] | 3046 | static void |
Eric Moore | 547f9a2 | 2006-06-27 14:42:12 -0600 | [diff] [blame] | 3047 | mptsas_send_discovery_event(MPT_ADAPTER *ioc, |
Moore, Eric | e6b2d76 | 2006-03-14 09:14:24 -0700 | [diff] [blame] | 3048 | EVENT_DATA_SAS_DISCOVERY *discovery_data) |
| 3049 | { |
| 3050 | struct mptsas_discovery_event *ev; |
Kashyap, Desai | 7b5a65b | 2009-05-29 16:38:14 +0530 | [diff] [blame] | 3051 | u32 discovery_status; |
Moore, Eric | e6b2d76 | 2006-03-14 09:14:24 -0700 | [diff] [blame] | 3052 | |
| 3053 | /* |
| 3054 | * DiscoveryStatus |
| 3055 | * |
| 3056 | * This flag will be non-zero when firmware |
| 3057 | * kicks off discovery, and return to zero |
| 3058 | * once its completed. |
| 3059 | */ |
Kashyap, Desai | 7b5a65b | 2009-05-29 16:38:14 +0530 | [diff] [blame] | 3060 | discovery_status = le32_to_cpu(discovery_data->DiscoveryStatus); |
| 3061 | ioc->sas_discovery_quiesce_io = discovery_status ? 1 : 0; |
| 3062 | if (discovery_status) |
Moore, Eric | e6b2d76 | 2006-03-14 09:14:24 -0700 | [diff] [blame] | 3063 | return; |
| 3064 | |
Eric Moore | 547f9a2 | 2006-06-27 14:42:12 -0600 | [diff] [blame] | 3065 | ev = kzalloc(sizeof(*ev), GFP_ATOMIC); |
Moore, Eric | e6b2d76 | 2006-03-14 09:14:24 -0700 | [diff] [blame] | 3066 | if (!ev) |
| 3067 | return; |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 3068 | INIT_WORK(&ev->work, mptsas_discovery_work); |
Moore, Eric | e6b2d76 | 2006-03-14 09:14:24 -0700 | [diff] [blame] | 3069 | ev->ioc = ioc; |
| 3070 | schedule_work(&ev->work); |
| 3071 | }; |
| 3072 | |
Eric Moore | b506ade | 2007-01-29 09:45:37 -0700 | [diff] [blame] | 3073 | /* |
| 3074 | * mptsas_send_ir2_event - handle exposing hidden disk when |
| 3075 | * an inactive raid volume is added |
| 3076 | * |
| 3077 | * @ioc: Pointer to MPT_ADAPTER structure |
| 3078 | * @ir2_data |
| 3079 | * |
| 3080 | */ |
| 3081 | static void |
| 3082 | mptsas_send_ir2_event(MPT_ADAPTER *ioc, PTR_MPI_EVENT_DATA_IR2 ir2_data) |
| 3083 | { |
| 3084 | struct mptsas_hotplug_event *ev; |
| 3085 | |
| 3086 | if (ir2_data->ReasonCode != |
| 3087 | MPI_EVENT_IR2_RC_FOREIGN_CFG_DETECTED) |
| 3088 | return; |
| 3089 | |
| 3090 | ev = kzalloc(sizeof(*ev), GFP_ATOMIC); |
| 3091 | if (!ev) |
| 3092 | return; |
| 3093 | |
| 3094 | INIT_WORK(&ev->work, mptsas_hotplug_work); |
| 3095 | ev->ioc = ioc; |
| 3096 | ev->id = ir2_data->TargetID; |
| 3097 | ev->channel = ir2_data->Bus; |
| 3098 | ev->event_type = MPTSAS_ADD_INACTIVE_VOLUME; |
| 3099 | |
| 3100 | schedule_work(&ev->work); |
| 3101 | }; |
Moore, Eric | e6b2d76 | 2006-03-14 09:14:24 -0700 | [diff] [blame] | 3102 | |
Christoph Hellwig | 9a28f49a | 2006-01-13 18:04:41 +0100 | [diff] [blame] | 3103 | static int |
| 3104 | mptsas_event_process(MPT_ADAPTER *ioc, EventNotificationReply_t *reply) |
| 3105 | { |
Moore, Eric | c73787ee | 2006-01-26 16:20:06 -0700 | [diff] [blame] | 3106 | int rc=1; |
Christoph Hellwig | 9a28f49a | 2006-01-13 18:04:41 +0100 | [diff] [blame] | 3107 | u8 event = le32_to_cpu(reply->Event) & 0xFF; |
| 3108 | |
| 3109 | if (!ioc->sh) |
Moore, Eric | c73787ee | 2006-01-26 16:20:06 -0700 | [diff] [blame] | 3110 | goto out; |
Christoph Hellwig | 9a28f49a | 2006-01-13 18:04:41 +0100 | [diff] [blame] | 3111 | |
Moore, Eric | e6b2d76 | 2006-03-14 09:14:24 -0700 | [diff] [blame] | 3112 | /* |
| 3113 | * sas_discovery_ignore_events |
| 3114 | * |
| 3115 | * This flag is to prevent anymore processing of |
| 3116 | * sas events once mptsas_remove function is called. |
| 3117 | */ |
| 3118 | if (ioc->sas_discovery_ignore_events) { |
| 3119 | rc = mptscsih_event_process(ioc, reply); |
| 3120 | goto out; |
| 3121 | } |
| 3122 | |
Christoph Hellwig | 9a28f49a | 2006-01-13 18:04:41 +0100 | [diff] [blame] | 3123 | switch (event) { |
| 3124 | case MPI_EVENT_SAS_DEVICE_STATUS_CHANGE: |
Eric Moore | 547f9a2 | 2006-06-27 14:42:12 -0600 | [diff] [blame] | 3125 | mptsas_send_sas_event(ioc, |
Christoph Hellwig | 9a28f49a | 2006-01-13 18:04:41 +0100 | [diff] [blame] | 3126 | (EVENT_DATA_SAS_DEVICE_STATUS_CHANGE *)reply->Data); |
Moore, Eric | c73787ee | 2006-01-26 16:20:06 -0700 | [diff] [blame] | 3127 | break; |
| 3128 | case MPI_EVENT_INTEGRATED_RAID: |
Eric Moore | 547f9a2 | 2006-06-27 14:42:12 -0600 | [diff] [blame] | 3129 | mptsas_send_raid_event(ioc, |
Moore, Eric | c73787ee | 2006-01-26 16:20:06 -0700 | [diff] [blame] | 3130 | (EVENT_DATA_RAID *)reply->Data); |
| 3131 | break; |
Moore, Eric | 79de278 | 2006-01-25 18:05:15 -0700 | [diff] [blame] | 3132 | case MPI_EVENT_PERSISTENT_TABLE_FULL: |
Eric Moore | 547f9a2 | 2006-06-27 14:42:12 -0600 | [diff] [blame] | 3133 | INIT_WORK(&ioc->sas_persist_task, |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 3134 | mptsas_persist_clear_table); |
Eric Moore | 547f9a2 | 2006-06-27 14:42:12 -0600 | [diff] [blame] | 3135 | schedule_work(&ioc->sas_persist_task); |
Moore, Eric | 79de278 | 2006-01-25 18:05:15 -0700 | [diff] [blame] | 3136 | break; |
Moore, Eric | 4b76647 | 2006-03-14 09:14:12 -0700 | [diff] [blame] | 3137 | case MPI_EVENT_SAS_DISCOVERY: |
Eric Moore | 547f9a2 | 2006-06-27 14:42:12 -0600 | [diff] [blame] | 3138 | mptsas_send_discovery_event(ioc, |
Moore, Eric | e6b2d76 | 2006-03-14 09:14:24 -0700 | [diff] [blame] | 3139 | (EVENT_DATA_SAS_DISCOVERY *)reply->Data); |
| 3140 | break; |
Eric Moore | b506ade | 2007-01-29 09:45:37 -0700 | [diff] [blame] | 3141 | case MPI_EVENT_IR2: |
| 3142 | mptsas_send_ir2_event(ioc, |
| 3143 | (PTR_MPI_EVENT_DATA_IR2)reply->Data); |
| 3144 | break; |
Christoph Hellwig | 9a28f49a | 2006-01-13 18:04:41 +0100 | [diff] [blame] | 3145 | default: |
Moore, Eric | c73787ee | 2006-01-26 16:20:06 -0700 | [diff] [blame] | 3146 | rc = mptscsih_event_process(ioc, reply); |
| 3147 | break; |
Christoph Hellwig | 9a28f49a | 2006-01-13 18:04:41 +0100 | [diff] [blame] | 3148 | } |
Moore, Eric | c73787ee | 2006-01-26 16:20:06 -0700 | [diff] [blame] | 3149 | out: |
| 3150 | |
| 3151 | return rc; |
Christoph Hellwig | 9a28f49a | 2006-01-13 18:04:41 +0100 | [diff] [blame] | 3152 | } |
| 3153 | |
Christoph Hellwig | 0c33b27 | 2005-09-09 16:27:19 +0200 | [diff] [blame] | 3154 | static int |
| 3155 | mptsas_probe(struct pci_dev *pdev, const struct pci_device_id *id) |
| 3156 | { |
| 3157 | struct Scsi_Host *sh; |
| 3158 | MPT_SCSI_HOST *hd; |
| 3159 | MPT_ADAPTER *ioc; |
| 3160 | unsigned long flags; |
Christoph Hellwig | 1ca00bb | 2006-01-13 18:27:50 +0100 | [diff] [blame] | 3161 | int ii; |
Christoph Hellwig | 0c33b27 | 2005-09-09 16:27:19 +0200 | [diff] [blame] | 3162 | int numSGE = 0; |
| 3163 | int scale; |
| 3164 | int ioc_cap; |
Christoph Hellwig | 0c33b27 | 2005-09-09 16:27:19 +0200 | [diff] [blame] | 3165 | int error=0; |
| 3166 | int r; |
| 3167 | |
| 3168 | r = mpt_attach(pdev,id); |
| 3169 | if (r) |
| 3170 | return r; |
| 3171 | |
| 3172 | ioc = pci_get_drvdata(pdev); |
| 3173 | ioc->DoneCtx = mptsasDoneCtx; |
| 3174 | ioc->TaskCtx = mptsasTaskCtx; |
| 3175 | ioc->InternalCtx = mptsasInternalCtx; |
| 3176 | |
| 3177 | /* Added sanity check on readiness of the MPT adapter. |
| 3178 | */ |
| 3179 | if (ioc->last_state != MPI_IOC_STATE_OPERATIONAL) { |
| 3180 | printk(MYIOC_s_WARN_FMT |
| 3181 | "Skipping because it's not operational!\n", |
| 3182 | ioc->name); |
Moore, Eric Dean | 7acec1e | 2005-11-16 18:54:17 -0700 | [diff] [blame] | 3183 | error = -ENODEV; |
| 3184 | goto out_mptsas_probe; |
Christoph Hellwig | 0c33b27 | 2005-09-09 16:27:19 +0200 | [diff] [blame] | 3185 | } |
| 3186 | |
| 3187 | if (!ioc->active) { |
| 3188 | printk(MYIOC_s_WARN_FMT "Skipping because it's disabled!\n", |
| 3189 | ioc->name); |
Moore, Eric Dean | 7acec1e | 2005-11-16 18:54:17 -0700 | [diff] [blame] | 3190 | error = -ENODEV; |
| 3191 | goto out_mptsas_probe; |
Christoph Hellwig | 0c33b27 | 2005-09-09 16:27:19 +0200 | [diff] [blame] | 3192 | } |
| 3193 | |
| 3194 | /* Sanity check - ensure at least 1 port is INITIATOR capable |
| 3195 | */ |
| 3196 | ioc_cap = 0; |
| 3197 | for (ii = 0; ii < ioc->facts.NumberOfPorts; ii++) { |
| 3198 | if (ioc->pfacts[ii].ProtocolFlags & |
| 3199 | MPI_PORTFACTS_PROTOCOL_INITIATOR) |
| 3200 | ioc_cap++; |
| 3201 | } |
| 3202 | |
| 3203 | if (!ioc_cap) { |
| 3204 | printk(MYIOC_s_WARN_FMT |
| 3205 | "Skipping ioc=%p because SCSI Initiator mode " |
| 3206 | "is NOT enabled!\n", ioc->name, ioc); |
Moore, Eric Dean | 466544d | 2005-09-14 18:09:10 -0600 | [diff] [blame] | 3207 | return 0; |
Christoph Hellwig | 0c33b27 | 2005-09-09 16:27:19 +0200 | [diff] [blame] | 3208 | } |
| 3209 | |
| 3210 | sh = scsi_host_alloc(&mptsas_driver_template, sizeof(MPT_SCSI_HOST)); |
| 3211 | if (!sh) { |
| 3212 | printk(MYIOC_s_WARN_FMT |
| 3213 | "Unable to register controller with SCSI subsystem\n", |
| 3214 | ioc->name); |
Moore, Eric Dean | 7acec1e | 2005-11-16 18:54:17 -0700 | [diff] [blame] | 3215 | error = -1; |
| 3216 | goto out_mptsas_probe; |
Christoph Hellwig | 0c33b27 | 2005-09-09 16:27:19 +0200 | [diff] [blame] | 3217 | } |
| 3218 | |
| 3219 | spin_lock_irqsave(&ioc->FreeQlock, flags); |
| 3220 | |
| 3221 | /* Attach the SCSI Host to the IOC structure |
| 3222 | */ |
| 3223 | ioc->sh = sh; |
| 3224 | |
| 3225 | sh->io_port = 0; |
| 3226 | sh->n_io_port = 0; |
| 3227 | sh->irq = 0; |
| 3228 | |
| 3229 | /* set 16 byte cdb's */ |
| 3230 | sh->max_cmd_len = 16; |
| 3231 | |
Eric Moore | 793955f | 2007-01-29 09:42:20 -0700 | [diff] [blame] | 3232 | sh->max_id = ioc->pfacts[0].PortSCSIID; |
| 3233 | sh->max_lun = max_lun; |
Christoph Hellwig | 0c33b27 | 2005-09-09 16:27:19 +0200 | [diff] [blame] | 3234 | |
| 3235 | sh->transportt = mptsas_transport_template; |
| 3236 | |
Christoph Hellwig | 0c33b27 | 2005-09-09 16:27:19 +0200 | [diff] [blame] | 3237 | /* Required entry. |
| 3238 | */ |
| 3239 | sh->unique_id = ioc->id; |
| 3240 | |
| 3241 | INIT_LIST_HEAD(&ioc->sas_topology); |
Christoph Hellwig | 9a28f49a | 2006-01-13 18:04:41 +0100 | [diff] [blame] | 3242 | mutex_init(&ioc->sas_topology_mutex); |
Moore, Eric | e6b2d76 | 2006-03-14 09:14:24 -0700 | [diff] [blame] | 3243 | mutex_init(&ioc->sas_discovery_mutex); |
Christoph Hellwig | eeb846c | 2006-01-13 18:27:11 +0100 | [diff] [blame] | 3244 | mutex_init(&ioc->sas_mgmt.mutex); |
Christoph Hellwig | da4fa65 | 2005-10-19 20:01:42 +0200 | [diff] [blame] | 3245 | init_completion(&ioc->sas_mgmt.done); |
Christoph Hellwig | 0c33b27 | 2005-09-09 16:27:19 +0200 | [diff] [blame] | 3246 | |
| 3247 | /* Verify that we won't exceed the maximum |
| 3248 | * number of chain buffers |
| 3249 | * We can optimize: ZZ = req_sz/sizeof(SGE) |
| 3250 | * For 32bit SGE's: |
| 3251 | * numSGE = 1 + (ZZ-1)*(maxChain -1) + ZZ |
| 3252 | * + (req_sz - 64)/sizeof(SGE) |
| 3253 | * A slightly different algorithm is required for |
| 3254 | * 64bit SGEs. |
| 3255 | */ |
Kashyap, Desai | 14d0f0b | 2009-05-29 16:37:04 +0530 | [diff] [blame] | 3256 | scale = ioc->req_sz/ioc->SGE_size; |
| 3257 | if (ioc->sg_addr_size == sizeof(u64)) { |
Christoph Hellwig | 0c33b27 | 2005-09-09 16:27:19 +0200 | [diff] [blame] | 3258 | numSGE = (scale - 1) * |
| 3259 | (ioc->facts.MaxChainDepth-1) + scale + |
Kashyap, Desai | 14d0f0b | 2009-05-29 16:37:04 +0530 | [diff] [blame] | 3260 | (ioc->req_sz - 60) / ioc->SGE_size; |
Christoph Hellwig | 0c33b27 | 2005-09-09 16:27:19 +0200 | [diff] [blame] | 3261 | } else { |
| 3262 | numSGE = 1 + (scale - 1) * |
| 3263 | (ioc->facts.MaxChainDepth-1) + scale + |
Kashyap, Desai | 14d0f0b | 2009-05-29 16:37:04 +0530 | [diff] [blame] | 3264 | (ioc->req_sz - 64) / ioc->SGE_size; |
Christoph Hellwig | 0c33b27 | 2005-09-09 16:27:19 +0200 | [diff] [blame] | 3265 | } |
| 3266 | |
| 3267 | if (numSGE < sh->sg_tablesize) { |
| 3268 | /* Reset this value */ |
Prakash, Sathya | d6ecdd6 | 2007-07-24 15:47:41 +0530 | [diff] [blame] | 3269 | dprintk(ioc, printk(MYIOC_s_DEBUG_FMT |
Christoph Hellwig | 0c33b27 | 2005-09-09 16:27:19 +0200 | [diff] [blame] | 3270 | "Resetting sg_tablesize to %d from %d\n", |
| 3271 | ioc->name, numSGE, sh->sg_tablesize)); |
| 3272 | sh->sg_tablesize = numSGE; |
| 3273 | } |
| 3274 | |
Eric Moore | e7eae9f | 2007-09-29 10:15:59 -0600 | [diff] [blame] | 3275 | hd = shost_priv(sh); |
Christoph Hellwig | 0c33b27 | 2005-09-09 16:27:19 +0200 | [diff] [blame] | 3276 | hd->ioc = ioc; |
| 3277 | |
| 3278 | /* SCSI needs scsi_cmnd lookup table! |
| 3279 | * (with size equal to req_depth*PtrSz!) |
| 3280 | */ |
Eric Moore | e820638 | 2007-09-29 10:16:53 -0600 | [diff] [blame] | 3281 | ioc->ScsiLookup = kcalloc(ioc->req_depth, sizeof(void *), GFP_ATOMIC); |
| 3282 | if (!ioc->ScsiLookup) { |
Christoph Hellwig | 0c33b27 | 2005-09-09 16:27:19 +0200 | [diff] [blame] | 3283 | error = -ENOMEM; |
Eric Moore | bc6e089 | 2007-09-29 10:16:28 -0600 | [diff] [blame] | 3284 | spin_unlock_irqrestore(&ioc->FreeQlock, flags); |
Moore, Eric Dean | 7acec1e | 2005-11-16 18:54:17 -0700 | [diff] [blame] | 3285 | goto out_mptsas_probe; |
Christoph Hellwig | 0c33b27 | 2005-09-09 16:27:19 +0200 | [diff] [blame] | 3286 | } |
Eric Moore | e820638 | 2007-09-29 10:16:53 -0600 | [diff] [blame] | 3287 | spin_lock_init(&ioc->scsi_lookup_lock); |
Christoph Hellwig | 0c33b27 | 2005-09-09 16:27:19 +0200 | [diff] [blame] | 3288 | |
Prakash, Sathya | d6ecdd6 | 2007-07-24 15:47:41 +0530 | [diff] [blame] | 3289 | dprintk(ioc, printk(MYIOC_s_DEBUG_FMT "ScsiLookup @ %p\n", |
Eric Moore | e820638 | 2007-09-29 10:16:53 -0600 | [diff] [blame] | 3290 | ioc->name, ioc->ScsiLookup)); |
Christoph Hellwig | 0c33b27 | 2005-09-09 16:27:19 +0200 | [diff] [blame] | 3291 | |
Christoph Hellwig | 0c33b27 | 2005-09-09 16:27:19 +0200 | [diff] [blame] | 3292 | /* Clear the TM flags |
| 3293 | */ |
| 3294 | hd->tmPending = 0; |
| 3295 | hd->tmState = TM_STATE_NONE; |
Christoph Hellwig | 0c33b27 | 2005-09-09 16:27:19 +0200 | [diff] [blame] | 3296 | hd->abortSCpnt = NULL; |
| 3297 | |
| 3298 | /* Clear the pointer used to store |
| 3299 | * single-threaded commands, i.e., those |
| 3300 | * issued during a bus scan, dv and |
| 3301 | * configuration pages. |
| 3302 | */ |
| 3303 | hd->cmdPtr = NULL; |
| 3304 | |
| 3305 | /* Initialize this SCSI Hosts' timers |
| 3306 | * To use, set the timer expires field |
| 3307 | * and add_timer |
| 3308 | */ |
| 3309 | init_timer(&hd->timer); |
| 3310 | hd->timer.data = (unsigned long) hd; |
| 3311 | hd->timer.function = mptscsih_timer_expired; |
| 3312 | |
Christoph Hellwig | 0c33b27 | 2005-09-09 16:27:19 +0200 | [diff] [blame] | 3313 | ioc->sas_data.ptClear = mpt_pt_clear; |
| 3314 | |
Eric Moore | df9e062 | 2007-01-29 09:46:21 -0700 | [diff] [blame] | 3315 | hd->last_queue_full = 0; |
| 3316 | INIT_LIST_HEAD(&hd->target_reset_list); |
| 3317 | spin_unlock_irqrestore(&ioc->FreeQlock, flags); |
| 3318 | |
Christoph Hellwig | 0c33b27 | 2005-09-09 16:27:19 +0200 | [diff] [blame] | 3319 | if (ioc->sas_data.ptClear==1) { |
| 3320 | mptbase_sas_persist_operation( |
| 3321 | ioc, MPI_SAS_OP_CLEAR_ALL_PERSISTENT); |
| 3322 | } |
| 3323 | |
Christoph Hellwig | 0c33b27 | 2005-09-09 16:27:19 +0200 | [diff] [blame] | 3324 | error = scsi_add_host(sh, &ioc->pcidev->dev); |
| 3325 | if (error) { |
Eric Moore | 29dd360 | 2007-09-14 18:46:51 -0600 | [diff] [blame] | 3326 | dprintk(ioc, printk(MYIOC_s_ERR_FMT |
| 3327 | "scsi_add_host failed\n", ioc->name)); |
Moore, Eric Dean | 7acec1e | 2005-11-16 18:54:17 -0700 | [diff] [blame] | 3328 | goto out_mptsas_probe; |
Christoph Hellwig | 0c33b27 | 2005-09-09 16:27:19 +0200 | [diff] [blame] | 3329 | } |
| 3330 | |
| 3331 | mptsas_scan_sas_topology(ioc); |
| 3332 | |
| 3333 | return 0; |
| 3334 | |
Eric Moore | 547f9a2 | 2006-06-27 14:42:12 -0600 | [diff] [blame] | 3335 | out_mptsas_probe: |
Christoph Hellwig | 0c33b27 | 2005-09-09 16:27:19 +0200 | [diff] [blame] | 3336 | |
| 3337 | mptscsih_remove(pdev); |
| 3338 | return error; |
| 3339 | } |
| 3340 | |
Kashyap, Desai | 7b5a65b | 2009-05-29 16:38:14 +0530 | [diff] [blame] | 3341 | void |
| 3342 | mptsas_shutdown(struct pci_dev *pdev) |
| 3343 | { |
| 3344 | MPT_ADAPTER *ioc = pci_get_drvdata(pdev); |
| 3345 | |
| 3346 | ioc->sas_discovery_quiesce_io = 0; |
| 3347 | } |
| 3348 | |
Christoph Hellwig | 0c33b27 | 2005-09-09 16:27:19 +0200 | [diff] [blame] | 3349 | static void __devexit mptsas_remove(struct pci_dev *pdev) |
| 3350 | { |
| 3351 | MPT_ADAPTER *ioc = pci_get_drvdata(pdev); |
| 3352 | struct mptsas_portinfo *p, *n; |
Eric Moore | 547f9a2 | 2006-06-27 14:42:12 -0600 | [diff] [blame] | 3353 | int i; |
Christoph Hellwig | 0c33b27 | 2005-09-09 16:27:19 +0200 | [diff] [blame] | 3354 | |
Kashyap, Desai | 7b5a65b | 2009-05-29 16:38:14 +0530 | [diff] [blame] | 3355 | mptsas_shutdown(pdev); |
| 3356 | |
Eric Moore | b506ade | 2007-01-29 09:45:37 -0700 | [diff] [blame] | 3357 | ioc->sas_discovery_ignore_events = 1; |
Christoph Hellwig | 0c33b27 | 2005-09-09 16:27:19 +0200 | [diff] [blame] | 3358 | sas_remove_host(ioc->sh); |
| 3359 | |
Christoph Hellwig | 9a28f49a | 2006-01-13 18:04:41 +0100 | [diff] [blame] | 3360 | mutex_lock(&ioc->sas_topology_mutex); |
Christoph Hellwig | 0c33b27 | 2005-09-09 16:27:19 +0200 | [diff] [blame] | 3361 | list_for_each_entry_safe(p, n, &ioc->sas_topology, list) { |
| 3362 | list_del(&p->list); |
Eric Moore | 547f9a2 | 2006-06-27 14:42:12 -0600 | [diff] [blame] | 3363 | for (i = 0 ; i < p->num_phys ; i++) |
Prakash, Sathya | d6ecdd6 | 2007-07-24 15:47:41 +0530 | [diff] [blame] | 3364 | mptsas_port_delete(ioc, p->phy_info[i].port_details); |
Eric Moore | 547f9a2 | 2006-06-27 14:42:12 -0600 | [diff] [blame] | 3365 | kfree(p->phy_info); |
Christoph Hellwig | 0c33b27 | 2005-09-09 16:27:19 +0200 | [diff] [blame] | 3366 | kfree(p); |
| 3367 | } |
Christoph Hellwig | 9a28f49a | 2006-01-13 18:04:41 +0100 | [diff] [blame] | 3368 | mutex_unlock(&ioc->sas_topology_mutex); |
Christoph Hellwig | 0c33b27 | 2005-09-09 16:27:19 +0200 | [diff] [blame] | 3369 | |
| 3370 | mptscsih_remove(pdev); |
| 3371 | } |
| 3372 | |
| 3373 | static struct pci_device_id mptsas_pci_table[] = { |
Eric Moore | 87cf898 | 2006-06-27 16:09:26 -0600 | [diff] [blame] | 3374 | { PCI_VENDOR_ID_LSI_LOGIC, MPI_MANUFACTPAGE_DEVID_SAS1064, |
Christoph Hellwig | 0c33b27 | 2005-09-09 16:27:19 +0200 | [diff] [blame] | 3375 | PCI_ANY_ID, PCI_ANY_ID }, |
Eric Moore | 87cf898 | 2006-06-27 16:09:26 -0600 | [diff] [blame] | 3376 | { PCI_VENDOR_ID_LSI_LOGIC, MPI_MANUFACTPAGE_DEVID_SAS1068, |
Christoph Hellwig | 0c33b27 | 2005-09-09 16:27:19 +0200 | [diff] [blame] | 3377 | PCI_ANY_ID, PCI_ANY_ID }, |
Eric Moore | 87cf898 | 2006-06-27 16:09:26 -0600 | [diff] [blame] | 3378 | { PCI_VENDOR_ID_LSI_LOGIC, MPI_MANUFACTPAGE_DEVID_SAS1064E, |
Christoph Hellwig | 0c33b27 | 2005-09-09 16:27:19 +0200 | [diff] [blame] | 3379 | PCI_ANY_ID, PCI_ANY_ID }, |
Eric Moore | 87cf898 | 2006-06-27 16:09:26 -0600 | [diff] [blame] | 3380 | { PCI_VENDOR_ID_LSI_LOGIC, MPI_MANUFACTPAGE_DEVID_SAS1068E, |
Christoph Hellwig | 0c33b27 | 2005-09-09 16:27:19 +0200 | [diff] [blame] | 3381 | PCI_ANY_ID, PCI_ANY_ID }, |
Eric Moore | 87cf898 | 2006-06-27 16:09:26 -0600 | [diff] [blame] | 3382 | { PCI_VENDOR_ID_LSI_LOGIC, MPI_MANUFACTPAGE_DEVID_SAS1078, |
Christoph Hellwig | 0c33b27 | 2005-09-09 16:27:19 +0200 | [diff] [blame] | 3383 | PCI_ANY_ID, PCI_ANY_ID }, |
| 3384 | {0} /* Terminating entry */ |
| 3385 | }; |
| 3386 | MODULE_DEVICE_TABLE(pci, mptsas_pci_table); |
| 3387 | |
| 3388 | |
| 3389 | static struct pci_driver mptsas_driver = { |
| 3390 | .name = "mptsas", |
| 3391 | .id_table = mptsas_pci_table, |
| 3392 | .probe = mptsas_probe, |
| 3393 | .remove = __devexit_p(mptsas_remove), |
Kashyap, Desai | 7b5a65b | 2009-05-29 16:38:14 +0530 | [diff] [blame] | 3394 | .shutdown = mptsas_shutdown, |
Christoph Hellwig | 0c33b27 | 2005-09-09 16:27:19 +0200 | [diff] [blame] | 3395 | #ifdef CONFIG_PM |
| 3396 | .suspend = mptscsih_suspend, |
| 3397 | .resume = mptscsih_resume, |
| 3398 | #endif |
| 3399 | }; |
| 3400 | |
| 3401 | static int __init |
| 3402 | mptsas_init(void) |
| 3403 | { |
Prakash, Sathya | 57ce21b | 2007-07-02 17:04:10 +0530 | [diff] [blame] | 3404 | int error; |
| 3405 | |
Christoph Hellwig | 0c33b27 | 2005-09-09 16:27:19 +0200 | [diff] [blame] | 3406 | show_mptmod_ver(my_NAME, my_VERSION); |
| 3407 | |
| 3408 | mptsas_transport_template = |
| 3409 | sas_attach_transport(&mptsas_transport_functions); |
| 3410 | if (!mptsas_transport_template) |
| 3411 | return -ENODEV; |
| 3412 | |
| 3413 | mptsasDoneCtx = mpt_register(mptscsih_io_done, MPTSAS_DRIVER); |
Kashyap, Desai | e7deff3 | 2009-05-29 16:46:07 +0530 | [diff] [blame^] | 3414 | mptsasTaskCtx = mpt_register(mptscsih_taskmgmt_complete, MPTSAS_DRIVER); |
Christoph Hellwig | 0c33b27 | 2005-09-09 16:27:19 +0200 | [diff] [blame] | 3415 | mptsasInternalCtx = |
| 3416 | mpt_register(mptscsih_scandv_complete, MPTSAS_DRIVER); |
Christoph Hellwig | da4fa65 | 2005-10-19 20:01:42 +0200 | [diff] [blame] | 3417 | mptsasMgmtCtx = mpt_register(mptsas_mgmt_done, MPTSAS_DRIVER); |
Kashyap, Desai | e7deff3 | 2009-05-29 16:46:07 +0530 | [diff] [blame^] | 3418 | mptsasDeviceResetCtx = |
| 3419 | mpt_register(mptsas_taskmgmt_complete, MPTSAS_DRIVER); |
Christoph Hellwig | 0c33b27 | 2005-09-09 16:27:19 +0200 | [diff] [blame] | 3420 | |
Prakash, Sathya | d6ecdd6 | 2007-07-24 15:47:41 +0530 | [diff] [blame] | 3421 | mpt_event_register(mptsasDoneCtx, mptsas_event_process); |
| 3422 | mpt_reset_register(mptsasDoneCtx, mptsas_ioc_reset); |
Christoph Hellwig | 0c33b27 | 2005-09-09 16:27:19 +0200 | [diff] [blame] | 3423 | |
Prakash, Sathya | 57ce21b | 2007-07-02 17:04:10 +0530 | [diff] [blame] | 3424 | error = pci_register_driver(&mptsas_driver); |
| 3425 | if (error) |
| 3426 | sas_release_transport(mptsas_transport_template); |
| 3427 | |
| 3428 | return error; |
Christoph Hellwig | 0c33b27 | 2005-09-09 16:27:19 +0200 | [diff] [blame] | 3429 | } |
| 3430 | |
| 3431 | static void __exit |
| 3432 | mptsas_exit(void) |
| 3433 | { |
| 3434 | pci_unregister_driver(&mptsas_driver); |
| 3435 | sas_release_transport(mptsas_transport_template); |
| 3436 | |
| 3437 | mpt_reset_deregister(mptsasDoneCtx); |
| 3438 | mpt_event_deregister(mptsasDoneCtx); |
| 3439 | |
Christoph Hellwig | da4fa65 | 2005-10-19 20:01:42 +0200 | [diff] [blame] | 3440 | mpt_deregister(mptsasMgmtCtx); |
Christoph Hellwig | 0c33b27 | 2005-09-09 16:27:19 +0200 | [diff] [blame] | 3441 | mpt_deregister(mptsasInternalCtx); |
| 3442 | mpt_deregister(mptsasTaskCtx); |
| 3443 | mpt_deregister(mptsasDoneCtx); |
Kashyap, Desai | e7deff3 | 2009-05-29 16:46:07 +0530 | [diff] [blame^] | 3444 | mpt_deregister(mptsasDeviceResetCtx); |
Christoph Hellwig | 0c33b27 | 2005-09-09 16:27:19 +0200 | [diff] [blame] | 3445 | } |
| 3446 | |
| 3447 | module_init(mptsas_init); |
| 3448 | module_exit(mptsas_exit); |