Commit cac197031ce274efff8a5abea811b9d69ae3d740

Authored by Al Viro
1 parent 09dae7fc57

fusion: switch to ->show_info()

Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>

Showing 5 changed files with 11 additions and 95 deletions Inline Diff

drivers/message/fusion/mptfc.c
1 /* 1 /*
2 * linux/drivers/message/fusion/mptfc.c 2 * linux/drivers/message/fusion/mptfc.c
3 * For use with LSI PCI chip/adapter(s) 3 * For use with LSI PCI chip/adapter(s)
4 * running LSI Fusion MPT (Message Passing Technology) firmware. 4 * running LSI Fusion MPT (Message Passing Technology) firmware.
5 * 5 *
6 * Copyright (c) 1999-2008 LSI Corporation 6 * Copyright (c) 1999-2008 LSI Corporation
7 * (mailto:DL-MPTFusionLinux@lsi.com) 7 * (mailto:DL-MPTFusionLinux@lsi.com)
8 * 8 *
9 */ 9 */
10 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/ 10 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
11 /* 11 /*
12 This program is free software; you can redistribute it and/or modify 12 This program is free software; you can redistribute it and/or modify
13 it under the terms of the GNU General Public License as published by 13 it under the terms of the GNU General Public License as published by
14 the Free Software Foundation; version 2 of the License. 14 the Free Software Foundation; version 2 of the License.
15 15
16 This program is distributed in the hope that it will be useful, 16 This program is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of 17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 GNU General Public License for more details. 19 GNU General Public License for more details.
20 20
21 NO WARRANTY 21 NO WARRANTY
22 THE PROGRAM IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR 22 THE PROGRAM IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR
23 CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT 23 CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT
24 LIMITATION, ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT, 24 LIMITATION, ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT,
25 MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Each Recipient is 25 MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Each Recipient is
26 solely responsible for determining the appropriateness of using and 26 solely responsible for determining the appropriateness of using and
27 distributing the Program and assumes all risks associated with its 27 distributing the Program and assumes all risks associated with its
28 exercise of rights under this Agreement, including but not limited to 28 exercise of rights under this Agreement, including but not limited to
29 the risks and costs of program errors, damage to or loss of data, 29 the risks and costs of program errors, damage to or loss of data,
30 programs or equipment, and unavailability or interruption of operations. 30 programs or equipment, and unavailability or interruption of operations.
31 31
32 DISCLAIMER OF LIABILITY 32 DISCLAIMER OF LIABILITY
33 NEITHER RECIPIENT NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY 33 NEITHER RECIPIENT NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY
34 DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 34 DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
35 DAMAGES (INCLUDING WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND 35 DAMAGES (INCLUDING WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND
36 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR 36 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
37 TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE 37 TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
38 USE OR DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS GRANTED 38 USE OR DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS GRANTED
39 HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES 39 HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES
40 40
41 You should have received a copy of the GNU General Public License 41 You should have received a copy of the GNU General Public License
42 along with this program; if not, write to the Free Software 42 along with this program; if not, write to the Free Software
43 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 43 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
44 */ 44 */
45 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/ 45 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
46 #include <linux/module.h> 46 #include <linux/module.h>
47 #include <linux/kernel.h> 47 #include <linux/kernel.h>
48 #include <linux/init.h> 48 #include <linux/init.h>
49 #include <linux/errno.h> 49 #include <linux/errno.h>
50 #include <linux/kdev_t.h> 50 #include <linux/kdev_t.h>
51 #include <linux/blkdev.h> 51 #include <linux/blkdev.h>
52 #include <linux/delay.h> /* for mdelay */ 52 #include <linux/delay.h> /* for mdelay */
53 #include <linux/interrupt.h> /* needed for in_interrupt() proto */ 53 #include <linux/interrupt.h> /* needed for in_interrupt() proto */
54 #include <linux/reboot.h> /* notifier code */ 54 #include <linux/reboot.h> /* notifier code */
55 #include <linux/workqueue.h> 55 #include <linux/workqueue.h>
56 #include <linux/sort.h> 56 #include <linux/sort.h>
57 #include <linux/slab.h> 57 #include <linux/slab.h>
58 58
59 #include <scsi/scsi.h> 59 #include <scsi/scsi.h>
60 #include <scsi/scsi_cmnd.h> 60 #include <scsi/scsi_cmnd.h>
61 #include <scsi/scsi_device.h> 61 #include <scsi/scsi_device.h>
62 #include <scsi/scsi_host.h> 62 #include <scsi/scsi_host.h>
63 #include <scsi/scsi_tcq.h> 63 #include <scsi/scsi_tcq.h>
64 #include <scsi/scsi_transport_fc.h> 64 #include <scsi/scsi_transport_fc.h>
65 65
66 #include "mptbase.h" 66 #include "mptbase.h"
67 #include "mptscsih.h" 67 #include "mptscsih.h"
68 68
69 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/ 69 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
70 #define my_NAME "Fusion MPT FC Host driver" 70 #define my_NAME "Fusion MPT FC Host driver"
71 #define my_VERSION MPT_LINUX_VERSION_COMMON 71 #define my_VERSION MPT_LINUX_VERSION_COMMON
72 #define MYNAM "mptfc" 72 #define MYNAM "mptfc"
73 73
74 MODULE_AUTHOR(MODULEAUTHOR); 74 MODULE_AUTHOR(MODULEAUTHOR);
75 MODULE_DESCRIPTION(my_NAME); 75 MODULE_DESCRIPTION(my_NAME);
76 MODULE_LICENSE("GPL"); 76 MODULE_LICENSE("GPL");
77 MODULE_VERSION(my_VERSION); 77 MODULE_VERSION(my_VERSION);
78 78
79 /* Command line args */ 79 /* Command line args */
80 #define MPTFC_DEV_LOSS_TMO (60) 80 #define MPTFC_DEV_LOSS_TMO (60)
81 static int mptfc_dev_loss_tmo = MPTFC_DEV_LOSS_TMO; /* reasonable default */ 81 static int mptfc_dev_loss_tmo = MPTFC_DEV_LOSS_TMO; /* reasonable default */
82 module_param(mptfc_dev_loss_tmo, int, 0); 82 module_param(mptfc_dev_loss_tmo, int, 0);
83 MODULE_PARM_DESC(mptfc_dev_loss_tmo, " Initial time the driver programs the " 83 MODULE_PARM_DESC(mptfc_dev_loss_tmo, " Initial time the driver programs the "
84 " transport to wait for an rport to " 84 " transport to wait for an rport to "
85 " return following a device loss event." 85 " return following a device loss event."
86 " Default=60."); 86 " Default=60.");
87 87
88 /* scsi-mid layer global parmeter is max_report_luns, which is 511 */ 88 /* scsi-mid layer global parmeter is max_report_luns, which is 511 */
89 #define MPTFC_MAX_LUN (16895) 89 #define MPTFC_MAX_LUN (16895)
90 static int max_lun = MPTFC_MAX_LUN; 90 static int max_lun = MPTFC_MAX_LUN;
91 module_param(max_lun, int, 0); 91 module_param(max_lun, int, 0);
92 MODULE_PARM_DESC(max_lun, " max lun, default=16895 "); 92 MODULE_PARM_DESC(max_lun, " max lun, default=16895 ");
93 93
94 static u8 mptfcDoneCtx = MPT_MAX_PROTOCOL_DRIVERS; 94 static u8 mptfcDoneCtx = MPT_MAX_PROTOCOL_DRIVERS;
95 static u8 mptfcTaskCtx = MPT_MAX_PROTOCOL_DRIVERS; 95 static u8 mptfcTaskCtx = MPT_MAX_PROTOCOL_DRIVERS;
96 static u8 mptfcInternalCtx = MPT_MAX_PROTOCOL_DRIVERS; 96 static u8 mptfcInternalCtx = MPT_MAX_PROTOCOL_DRIVERS;
97 97
98 static int mptfc_target_alloc(struct scsi_target *starget); 98 static int mptfc_target_alloc(struct scsi_target *starget);
99 static int mptfc_slave_alloc(struct scsi_device *sdev); 99 static int mptfc_slave_alloc(struct scsi_device *sdev);
100 static int mptfc_qcmd(struct Scsi_Host *shost, struct scsi_cmnd *SCpnt); 100 static int mptfc_qcmd(struct Scsi_Host *shost, struct scsi_cmnd *SCpnt);
101 static void mptfc_target_destroy(struct scsi_target *starget); 101 static void mptfc_target_destroy(struct scsi_target *starget);
102 static void mptfc_set_rport_loss_tmo(struct fc_rport *rport, uint32_t timeout); 102 static void mptfc_set_rport_loss_tmo(struct fc_rport *rport, uint32_t timeout);
103 static void mptfc_remove(struct pci_dev *pdev); 103 static void mptfc_remove(struct pci_dev *pdev);
104 static int mptfc_abort(struct scsi_cmnd *SCpnt); 104 static int mptfc_abort(struct scsi_cmnd *SCpnt);
105 static int mptfc_dev_reset(struct scsi_cmnd *SCpnt); 105 static int mptfc_dev_reset(struct scsi_cmnd *SCpnt);
106 static int mptfc_bus_reset(struct scsi_cmnd *SCpnt); 106 static int mptfc_bus_reset(struct scsi_cmnd *SCpnt);
107 static int mptfc_host_reset(struct scsi_cmnd *SCpnt); 107 static int mptfc_host_reset(struct scsi_cmnd *SCpnt);
108 108
109 static struct scsi_host_template mptfc_driver_template = { 109 static struct scsi_host_template mptfc_driver_template = {
110 .module = THIS_MODULE, 110 .module = THIS_MODULE,
111 .proc_name = "mptfc", 111 .proc_name = "mptfc",
112 .proc_info = mptscsih_proc_info, 112 .show_info = mptscsih_show_info,
113 .name = "MPT FC Host", 113 .name = "MPT FC Host",
114 .info = mptscsih_info, 114 .info = mptscsih_info,
115 .queuecommand = mptfc_qcmd, 115 .queuecommand = mptfc_qcmd,
116 .target_alloc = mptfc_target_alloc, 116 .target_alloc = mptfc_target_alloc,
117 .slave_alloc = mptfc_slave_alloc, 117 .slave_alloc = mptfc_slave_alloc,
118 .slave_configure = mptscsih_slave_configure, 118 .slave_configure = mptscsih_slave_configure,
119 .target_destroy = mptfc_target_destroy, 119 .target_destroy = mptfc_target_destroy,
120 .slave_destroy = mptscsih_slave_destroy, 120 .slave_destroy = mptscsih_slave_destroy,
121 .change_queue_depth = mptscsih_change_queue_depth, 121 .change_queue_depth = mptscsih_change_queue_depth,
122 .eh_abort_handler = mptfc_abort, 122 .eh_abort_handler = mptfc_abort,
123 .eh_device_reset_handler = mptfc_dev_reset, 123 .eh_device_reset_handler = mptfc_dev_reset,
124 .eh_bus_reset_handler = mptfc_bus_reset, 124 .eh_bus_reset_handler = mptfc_bus_reset,
125 .eh_host_reset_handler = mptfc_host_reset, 125 .eh_host_reset_handler = mptfc_host_reset,
126 .bios_param = mptscsih_bios_param, 126 .bios_param = mptscsih_bios_param,
127 .can_queue = MPT_FC_CAN_QUEUE, 127 .can_queue = MPT_FC_CAN_QUEUE,
128 .this_id = -1, 128 .this_id = -1,
129 .sg_tablesize = MPT_SCSI_SG_DEPTH, 129 .sg_tablesize = MPT_SCSI_SG_DEPTH,
130 .max_sectors = 8192, 130 .max_sectors = 8192,
131 .cmd_per_lun = 7, 131 .cmd_per_lun = 7,
132 .use_clustering = ENABLE_CLUSTERING, 132 .use_clustering = ENABLE_CLUSTERING,
133 .shost_attrs = mptscsih_host_attrs, 133 .shost_attrs = mptscsih_host_attrs,
134 }; 134 };
135 135
136 /**************************************************************************** 136 /****************************************************************************
137 * Supported hardware 137 * Supported hardware
138 */ 138 */
139 139
140 static struct pci_device_id mptfc_pci_table[] = { 140 static struct pci_device_id mptfc_pci_table[] = {
141 { PCI_VENDOR_ID_LSI_LOGIC, MPI_MANUFACTPAGE_DEVICEID_FC909, 141 { PCI_VENDOR_ID_LSI_LOGIC, MPI_MANUFACTPAGE_DEVICEID_FC909,
142 PCI_ANY_ID, PCI_ANY_ID }, 142 PCI_ANY_ID, PCI_ANY_ID },
143 { PCI_VENDOR_ID_LSI_LOGIC, MPI_MANUFACTPAGE_DEVICEID_FC919, 143 { PCI_VENDOR_ID_LSI_LOGIC, MPI_MANUFACTPAGE_DEVICEID_FC919,
144 PCI_ANY_ID, PCI_ANY_ID }, 144 PCI_ANY_ID, PCI_ANY_ID },
145 { PCI_VENDOR_ID_LSI_LOGIC, MPI_MANUFACTPAGE_DEVICEID_FC929, 145 { PCI_VENDOR_ID_LSI_LOGIC, MPI_MANUFACTPAGE_DEVICEID_FC929,
146 PCI_ANY_ID, PCI_ANY_ID }, 146 PCI_ANY_ID, PCI_ANY_ID },
147 { PCI_VENDOR_ID_LSI_LOGIC, MPI_MANUFACTPAGE_DEVICEID_FC919X, 147 { PCI_VENDOR_ID_LSI_LOGIC, MPI_MANUFACTPAGE_DEVICEID_FC919X,
148 PCI_ANY_ID, PCI_ANY_ID }, 148 PCI_ANY_ID, PCI_ANY_ID },
149 { PCI_VENDOR_ID_LSI_LOGIC, MPI_MANUFACTPAGE_DEVICEID_FC929X, 149 { PCI_VENDOR_ID_LSI_LOGIC, MPI_MANUFACTPAGE_DEVICEID_FC929X,
150 PCI_ANY_ID, PCI_ANY_ID }, 150 PCI_ANY_ID, PCI_ANY_ID },
151 { PCI_VENDOR_ID_LSI_LOGIC, MPI_MANUFACTPAGE_DEVICEID_FC939X, 151 { PCI_VENDOR_ID_LSI_LOGIC, MPI_MANUFACTPAGE_DEVICEID_FC939X,
152 PCI_ANY_ID, PCI_ANY_ID }, 152 PCI_ANY_ID, PCI_ANY_ID },
153 { PCI_VENDOR_ID_LSI_LOGIC, MPI_MANUFACTPAGE_DEVICEID_FC949X, 153 { PCI_VENDOR_ID_LSI_LOGIC, MPI_MANUFACTPAGE_DEVICEID_FC949X,
154 PCI_ANY_ID, PCI_ANY_ID }, 154 PCI_ANY_ID, PCI_ANY_ID },
155 { PCI_VENDOR_ID_LSI_LOGIC, MPI_MANUFACTPAGE_DEVICEID_FC949E, 155 { PCI_VENDOR_ID_LSI_LOGIC, MPI_MANUFACTPAGE_DEVICEID_FC949E,
156 PCI_ANY_ID, PCI_ANY_ID }, 156 PCI_ANY_ID, PCI_ANY_ID },
157 { PCI_VENDOR_ID_BROCADE, MPI_MANUFACTPAGE_DEVICEID_FC949E, 157 { PCI_VENDOR_ID_BROCADE, MPI_MANUFACTPAGE_DEVICEID_FC949E,
158 PCI_ANY_ID, PCI_ANY_ID }, 158 PCI_ANY_ID, PCI_ANY_ID },
159 {0} /* Terminating entry */ 159 {0} /* Terminating entry */
160 }; 160 };
161 MODULE_DEVICE_TABLE(pci, mptfc_pci_table); 161 MODULE_DEVICE_TABLE(pci, mptfc_pci_table);
162 162
163 static struct scsi_transport_template *mptfc_transport_template = NULL; 163 static struct scsi_transport_template *mptfc_transport_template = NULL;
164 164
165 static struct fc_function_template mptfc_transport_functions = { 165 static struct fc_function_template mptfc_transport_functions = {
166 .dd_fcrport_size = 8, 166 .dd_fcrport_size = 8,
167 .show_host_node_name = 1, 167 .show_host_node_name = 1,
168 .show_host_port_name = 1, 168 .show_host_port_name = 1,
169 .show_host_supported_classes = 1, 169 .show_host_supported_classes = 1,
170 .show_host_port_id = 1, 170 .show_host_port_id = 1,
171 .show_rport_supported_classes = 1, 171 .show_rport_supported_classes = 1,
172 .show_starget_node_name = 1, 172 .show_starget_node_name = 1,
173 .show_starget_port_name = 1, 173 .show_starget_port_name = 1,
174 .show_starget_port_id = 1, 174 .show_starget_port_id = 1,
175 .set_rport_dev_loss_tmo = mptfc_set_rport_loss_tmo, 175 .set_rport_dev_loss_tmo = mptfc_set_rport_loss_tmo,
176 .show_rport_dev_loss_tmo = 1, 176 .show_rport_dev_loss_tmo = 1,
177 .show_host_supported_speeds = 1, 177 .show_host_supported_speeds = 1,
178 .show_host_maxframe_size = 1, 178 .show_host_maxframe_size = 1,
179 .show_host_speed = 1, 179 .show_host_speed = 1,
180 .show_host_fabric_name = 1, 180 .show_host_fabric_name = 1,
181 .show_host_port_type = 1, 181 .show_host_port_type = 1,
182 .show_host_port_state = 1, 182 .show_host_port_state = 1,
183 .show_host_symbolic_name = 1, 183 .show_host_symbolic_name = 1,
184 }; 184 };
185 185
186 static int 186 static int
187 mptfc_block_error_handler(struct scsi_cmnd *SCpnt, 187 mptfc_block_error_handler(struct scsi_cmnd *SCpnt,
188 int (*func)(struct scsi_cmnd *SCpnt), 188 int (*func)(struct scsi_cmnd *SCpnt),
189 const char *caller) 189 const char *caller)
190 { 190 {
191 MPT_SCSI_HOST *hd; 191 MPT_SCSI_HOST *hd;
192 struct scsi_device *sdev = SCpnt->device; 192 struct scsi_device *sdev = SCpnt->device;
193 struct Scsi_Host *shost = sdev->host; 193 struct Scsi_Host *shost = sdev->host;
194 struct fc_rport *rport = starget_to_rport(scsi_target(sdev)); 194 struct fc_rport *rport = starget_to_rport(scsi_target(sdev));
195 unsigned long flags; 195 unsigned long flags;
196 int ready; 196 int ready;
197 MPT_ADAPTER *ioc; 197 MPT_ADAPTER *ioc;
198 int loops = 40; /* seconds */ 198 int loops = 40; /* seconds */
199 199
200 hd = shost_priv(SCpnt->device->host); 200 hd = shost_priv(SCpnt->device->host);
201 ioc = hd->ioc; 201 ioc = hd->ioc;
202 spin_lock_irqsave(shost->host_lock, flags); 202 spin_lock_irqsave(shost->host_lock, flags);
203 while ((ready = fc_remote_port_chkready(rport) >> 16) == DID_IMM_RETRY 203 while ((ready = fc_remote_port_chkready(rport) >> 16) == DID_IMM_RETRY
204 || (loops > 0 && ioc->active == 0)) { 204 || (loops > 0 && ioc->active == 0)) {
205 spin_unlock_irqrestore(shost->host_lock, flags); 205 spin_unlock_irqrestore(shost->host_lock, flags);
206 dfcprintk (ioc, printk(MYIOC_s_DEBUG_FMT 206 dfcprintk (ioc, printk(MYIOC_s_DEBUG_FMT
207 "mptfc_block_error_handler.%d: %d:%d, port status is " 207 "mptfc_block_error_handler.%d: %d:%d, port status is "
208 "%x, active flag %d, deferring %s recovery.\n", 208 "%x, active flag %d, deferring %s recovery.\n",
209 ioc->name, ioc->sh->host_no, 209 ioc->name, ioc->sh->host_no,
210 SCpnt->device->id, SCpnt->device->lun, 210 SCpnt->device->id, SCpnt->device->lun,
211 ready, ioc->active, caller)); 211 ready, ioc->active, caller));
212 msleep(1000); 212 msleep(1000);
213 spin_lock_irqsave(shost->host_lock, flags); 213 spin_lock_irqsave(shost->host_lock, flags);
214 loops --; 214 loops --;
215 } 215 }
216 spin_unlock_irqrestore(shost->host_lock, flags); 216 spin_unlock_irqrestore(shost->host_lock, flags);
217 217
218 if (ready == DID_NO_CONNECT || !SCpnt->device->hostdata 218 if (ready == DID_NO_CONNECT || !SCpnt->device->hostdata
219 || ioc->active == 0) { 219 || ioc->active == 0) {
220 dfcprintk (ioc, printk(MYIOC_s_DEBUG_FMT 220 dfcprintk (ioc, printk(MYIOC_s_DEBUG_FMT
221 "%s.%d: %d:%d, failing recovery, " 221 "%s.%d: %d:%d, failing recovery, "
222 "port state %x, active %d, vdevice %p.\n", caller, 222 "port state %x, active %d, vdevice %p.\n", caller,
223 ioc->name, ioc->sh->host_no, 223 ioc->name, ioc->sh->host_no,
224 SCpnt->device->id, SCpnt->device->lun, ready, 224 SCpnt->device->id, SCpnt->device->lun, ready,
225 ioc->active, SCpnt->device->hostdata)); 225 ioc->active, SCpnt->device->hostdata));
226 return FAILED; 226 return FAILED;
227 } 227 }
228 dfcprintk (ioc, printk(MYIOC_s_DEBUG_FMT 228 dfcprintk (ioc, printk(MYIOC_s_DEBUG_FMT
229 "%s.%d: %d:%d, executing recovery.\n", caller, 229 "%s.%d: %d:%d, executing recovery.\n", caller,
230 ioc->name, ioc->sh->host_no, 230 ioc->name, ioc->sh->host_no,
231 SCpnt->device->id, SCpnt->device->lun)); 231 SCpnt->device->id, SCpnt->device->lun));
232 return (*func)(SCpnt); 232 return (*func)(SCpnt);
233 } 233 }
234 234
235 static int 235 static int
236 mptfc_abort(struct scsi_cmnd *SCpnt) 236 mptfc_abort(struct scsi_cmnd *SCpnt)
237 { 237 {
238 return 238 return
239 mptfc_block_error_handler(SCpnt, mptscsih_abort, __func__); 239 mptfc_block_error_handler(SCpnt, mptscsih_abort, __func__);
240 } 240 }
241 241
242 static int 242 static int
243 mptfc_dev_reset(struct scsi_cmnd *SCpnt) 243 mptfc_dev_reset(struct scsi_cmnd *SCpnt)
244 { 244 {
245 return 245 return
246 mptfc_block_error_handler(SCpnt, mptscsih_dev_reset, __func__); 246 mptfc_block_error_handler(SCpnt, mptscsih_dev_reset, __func__);
247 } 247 }
248 248
249 static int 249 static int
250 mptfc_bus_reset(struct scsi_cmnd *SCpnt) 250 mptfc_bus_reset(struct scsi_cmnd *SCpnt)
251 { 251 {
252 return 252 return
253 mptfc_block_error_handler(SCpnt, mptscsih_bus_reset, __func__); 253 mptfc_block_error_handler(SCpnt, mptscsih_bus_reset, __func__);
254 } 254 }
255 255
256 static int 256 static int
257 mptfc_host_reset(struct scsi_cmnd *SCpnt) 257 mptfc_host_reset(struct scsi_cmnd *SCpnt)
258 { 258 {
259 return 259 return
260 mptfc_block_error_handler(SCpnt, mptscsih_host_reset, __func__); 260 mptfc_block_error_handler(SCpnt, mptscsih_host_reset, __func__);
261 } 261 }
262 262
263 static void 263 static void
264 mptfc_set_rport_loss_tmo(struct fc_rport *rport, uint32_t timeout) 264 mptfc_set_rport_loss_tmo(struct fc_rport *rport, uint32_t timeout)
265 { 265 {
266 if (timeout > 0) 266 if (timeout > 0)
267 rport->dev_loss_tmo = timeout; 267 rport->dev_loss_tmo = timeout;
268 else 268 else
269 rport->dev_loss_tmo = mptfc_dev_loss_tmo; 269 rport->dev_loss_tmo = mptfc_dev_loss_tmo;
270 } 270 }
271 271
272 static int 272 static int
273 mptfc_FcDevPage0_cmp_func(const void *a, const void *b) 273 mptfc_FcDevPage0_cmp_func(const void *a, const void *b)
274 { 274 {
275 FCDevicePage0_t **aa = (FCDevicePage0_t **)a; 275 FCDevicePage0_t **aa = (FCDevicePage0_t **)a;
276 FCDevicePage0_t **bb = (FCDevicePage0_t **)b; 276 FCDevicePage0_t **bb = (FCDevicePage0_t **)b;
277 277
278 if ((*aa)->CurrentBus == (*bb)->CurrentBus) { 278 if ((*aa)->CurrentBus == (*bb)->CurrentBus) {
279 if ((*aa)->CurrentTargetID == (*bb)->CurrentTargetID) 279 if ((*aa)->CurrentTargetID == (*bb)->CurrentTargetID)
280 return 0; 280 return 0;
281 if ((*aa)->CurrentTargetID < (*bb)->CurrentTargetID) 281 if ((*aa)->CurrentTargetID < (*bb)->CurrentTargetID)
282 return -1; 282 return -1;
283 return 1; 283 return 1;
284 } 284 }
285 if ((*aa)->CurrentBus < (*bb)->CurrentBus) 285 if ((*aa)->CurrentBus < (*bb)->CurrentBus)
286 return -1; 286 return -1;
287 return 1; 287 return 1;
288 } 288 }
289 289
290 static int 290 static int
291 mptfc_GetFcDevPage0(MPT_ADAPTER *ioc, int ioc_port, 291 mptfc_GetFcDevPage0(MPT_ADAPTER *ioc, int ioc_port,
292 void(*func)(MPT_ADAPTER *ioc,int channel, FCDevicePage0_t *arg)) 292 void(*func)(MPT_ADAPTER *ioc,int channel, FCDevicePage0_t *arg))
293 { 293 {
294 ConfigPageHeader_t hdr; 294 ConfigPageHeader_t hdr;
295 CONFIGPARMS cfg; 295 CONFIGPARMS cfg;
296 FCDevicePage0_t *ppage0_alloc, *fc; 296 FCDevicePage0_t *ppage0_alloc, *fc;
297 dma_addr_t page0_dma; 297 dma_addr_t page0_dma;
298 int data_sz; 298 int data_sz;
299 int ii; 299 int ii;
300 300
301 FCDevicePage0_t *p0_array=NULL, *p_p0; 301 FCDevicePage0_t *p0_array=NULL, *p_p0;
302 FCDevicePage0_t **pp0_array=NULL, **p_pp0; 302 FCDevicePage0_t **pp0_array=NULL, **p_pp0;
303 303
304 int rc = -ENOMEM; 304 int rc = -ENOMEM;
305 U32 port_id = 0xffffff; 305 U32 port_id = 0xffffff;
306 int num_targ = 0; 306 int num_targ = 0;
307 int max_bus = ioc->facts.MaxBuses; 307 int max_bus = ioc->facts.MaxBuses;
308 int max_targ; 308 int max_targ;
309 309
310 max_targ = (ioc->facts.MaxDevices == 0) ? 256 : ioc->facts.MaxDevices; 310 max_targ = (ioc->facts.MaxDevices == 0) ? 256 : ioc->facts.MaxDevices;
311 311
312 data_sz = sizeof(FCDevicePage0_t) * max_bus * max_targ; 312 data_sz = sizeof(FCDevicePage0_t) * max_bus * max_targ;
313 p_p0 = p0_array = kzalloc(data_sz, GFP_KERNEL); 313 p_p0 = p0_array = kzalloc(data_sz, GFP_KERNEL);
314 if (!p0_array) 314 if (!p0_array)
315 goto out; 315 goto out;
316 316
317 data_sz = sizeof(FCDevicePage0_t *) * max_bus * max_targ; 317 data_sz = sizeof(FCDevicePage0_t *) * max_bus * max_targ;
318 p_pp0 = pp0_array = kzalloc(data_sz, GFP_KERNEL); 318 p_pp0 = pp0_array = kzalloc(data_sz, GFP_KERNEL);
319 if (!pp0_array) 319 if (!pp0_array)
320 goto out; 320 goto out;
321 321
322 do { 322 do {
323 /* Get FC Device Page 0 header */ 323 /* Get FC Device Page 0 header */
324 hdr.PageVersion = 0; 324 hdr.PageVersion = 0;
325 hdr.PageLength = 0; 325 hdr.PageLength = 0;
326 hdr.PageNumber = 0; 326 hdr.PageNumber = 0;
327 hdr.PageType = MPI_CONFIG_PAGETYPE_FC_DEVICE; 327 hdr.PageType = MPI_CONFIG_PAGETYPE_FC_DEVICE;
328 cfg.cfghdr.hdr = &hdr; 328 cfg.cfghdr.hdr = &hdr;
329 cfg.physAddr = -1; 329 cfg.physAddr = -1;
330 cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER; 330 cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
331 cfg.dir = 0; 331 cfg.dir = 0;
332 cfg.pageAddr = port_id; 332 cfg.pageAddr = port_id;
333 cfg.timeout = 0; 333 cfg.timeout = 0;
334 334
335 if ((rc = mpt_config(ioc, &cfg)) != 0) 335 if ((rc = mpt_config(ioc, &cfg)) != 0)
336 break; 336 break;
337 337
338 if (hdr.PageLength <= 0) 338 if (hdr.PageLength <= 0)
339 break; 339 break;
340 340
341 data_sz = hdr.PageLength * 4; 341 data_sz = hdr.PageLength * 4;
342 ppage0_alloc = pci_alloc_consistent(ioc->pcidev, data_sz, 342 ppage0_alloc = pci_alloc_consistent(ioc->pcidev, data_sz,
343 &page0_dma); 343 &page0_dma);
344 rc = -ENOMEM; 344 rc = -ENOMEM;
345 if (!ppage0_alloc) 345 if (!ppage0_alloc)
346 break; 346 break;
347 347
348 cfg.physAddr = page0_dma; 348 cfg.physAddr = page0_dma;
349 cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT; 349 cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
350 350
351 if ((rc = mpt_config(ioc, &cfg)) == 0) { 351 if ((rc = mpt_config(ioc, &cfg)) == 0) {
352 ppage0_alloc->PortIdentifier = 352 ppage0_alloc->PortIdentifier =
353 le32_to_cpu(ppage0_alloc->PortIdentifier); 353 le32_to_cpu(ppage0_alloc->PortIdentifier);
354 354
355 ppage0_alloc->WWNN.Low = 355 ppage0_alloc->WWNN.Low =
356 le32_to_cpu(ppage0_alloc->WWNN.Low); 356 le32_to_cpu(ppage0_alloc->WWNN.Low);
357 357
358 ppage0_alloc->WWNN.High = 358 ppage0_alloc->WWNN.High =
359 le32_to_cpu(ppage0_alloc->WWNN.High); 359 le32_to_cpu(ppage0_alloc->WWNN.High);
360 360
361 ppage0_alloc->WWPN.Low = 361 ppage0_alloc->WWPN.Low =
362 le32_to_cpu(ppage0_alloc->WWPN.Low); 362 le32_to_cpu(ppage0_alloc->WWPN.Low);
363 363
364 ppage0_alloc->WWPN.High = 364 ppage0_alloc->WWPN.High =
365 le32_to_cpu(ppage0_alloc->WWPN.High); 365 le32_to_cpu(ppage0_alloc->WWPN.High);
366 366
367 ppage0_alloc->BBCredit = 367 ppage0_alloc->BBCredit =
368 le16_to_cpu(ppage0_alloc->BBCredit); 368 le16_to_cpu(ppage0_alloc->BBCredit);
369 369
370 ppage0_alloc->MaxRxFrameSize = 370 ppage0_alloc->MaxRxFrameSize =
371 le16_to_cpu(ppage0_alloc->MaxRxFrameSize); 371 le16_to_cpu(ppage0_alloc->MaxRxFrameSize);
372 372
373 port_id = ppage0_alloc->PortIdentifier; 373 port_id = ppage0_alloc->PortIdentifier;
374 num_targ++; 374 num_targ++;
375 *p_p0 = *ppage0_alloc; /* save data */ 375 *p_p0 = *ppage0_alloc; /* save data */
376 *p_pp0++ = p_p0++; /* save addr */ 376 *p_pp0++ = p_p0++; /* save addr */
377 } 377 }
378 pci_free_consistent(ioc->pcidev, data_sz, 378 pci_free_consistent(ioc->pcidev, data_sz,
379 (u8 *) ppage0_alloc, page0_dma); 379 (u8 *) ppage0_alloc, page0_dma);
380 if (rc != 0) 380 if (rc != 0)
381 break; 381 break;
382 382
383 } while (port_id <= 0xff0000); 383 } while (port_id <= 0xff0000);
384 384
385 if (num_targ) { 385 if (num_targ) {
386 /* sort array */ 386 /* sort array */
387 if (num_targ > 1) 387 if (num_targ > 1)
388 sort (pp0_array, num_targ, sizeof(FCDevicePage0_t *), 388 sort (pp0_array, num_targ, sizeof(FCDevicePage0_t *),
389 mptfc_FcDevPage0_cmp_func, NULL); 389 mptfc_FcDevPage0_cmp_func, NULL);
390 /* call caller's func for each targ */ 390 /* call caller's func for each targ */
391 for (ii = 0; ii < num_targ; ii++) { 391 for (ii = 0; ii < num_targ; ii++) {
392 fc = *(pp0_array+ii); 392 fc = *(pp0_array+ii);
393 func(ioc, ioc_port, fc); 393 func(ioc, ioc_port, fc);
394 } 394 }
395 } 395 }
396 396
397 out: 397 out:
398 kfree(pp0_array); 398 kfree(pp0_array);
399 kfree(p0_array); 399 kfree(p0_array);
400 return rc; 400 return rc;
401 } 401 }
402 402
403 static int 403 static int
404 mptfc_generate_rport_ids(FCDevicePage0_t *pg0, struct fc_rport_identifiers *rid) 404 mptfc_generate_rport_ids(FCDevicePage0_t *pg0, struct fc_rport_identifiers *rid)
405 { 405 {
406 /* not currently usable */ 406 /* not currently usable */
407 if (pg0->Flags & (MPI_FC_DEVICE_PAGE0_FLAGS_PLOGI_INVALID | 407 if (pg0->Flags & (MPI_FC_DEVICE_PAGE0_FLAGS_PLOGI_INVALID |
408 MPI_FC_DEVICE_PAGE0_FLAGS_PRLI_INVALID)) 408 MPI_FC_DEVICE_PAGE0_FLAGS_PRLI_INVALID))
409 return -1; 409 return -1;
410 410
411 if (!(pg0->Flags & MPI_FC_DEVICE_PAGE0_FLAGS_TARGETID_BUS_VALID)) 411 if (!(pg0->Flags & MPI_FC_DEVICE_PAGE0_FLAGS_TARGETID_BUS_VALID))
412 return -1; 412 return -1;
413 413
414 if (!(pg0->Protocol & MPI_FC_DEVICE_PAGE0_PROT_FCP_TARGET)) 414 if (!(pg0->Protocol & MPI_FC_DEVICE_PAGE0_PROT_FCP_TARGET))
415 return -1; 415 return -1;
416 416
417 /* 417 /*
418 * board data structure already normalized to platform endianness 418 * board data structure already normalized to platform endianness
419 * shifted to avoid unaligned access on 64 bit architecture 419 * shifted to avoid unaligned access on 64 bit architecture
420 */ 420 */
421 rid->node_name = ((u64)pg0->WWNN.High) << 32 | (u64)pg0->WWNN.Low; 421 rid->node_name = ((u64)pg0->WWNN.High) << 32 | (u64)pg0->WWNN.Low;
422 rid->port_name = ((u64)pg0->WWPN.High) << 32 | (u64)pg0->WWPN.Low; 422 rid->port_name = ((u64)pg0->WWPN.High) << 32 | (u64)pg0->WWPN.Low;
423 rid->port_id = pg0->PortIdentifier; 423 rid->port_id = pg0->PortIdentifier;
424 rid->roles = FC_RPORT_ROLE_UNKNOWN; 424 rid->roles = FC_RPORT_ROLE_UNKNOWN;
425 425
426 return 0; 426 return 0;
427 } 427 }
428 428
429 static void 429 static void
430 mptfc_register_dev(MPT_ADAPTER *ioc, int channel, FCDevicePage0_t *pg0) 430 mptfc_register_dev(MPT_ADAPTER *ioc, int channel, FCDevicePage0_t *pg0)
431 { 431 {
432 struct fc_rport_identifiers rport_ids; 432 struct fc_rport_identifiers rport_ids;
433 struct fc_rport *rport; 433 struct fc_rport *rport;
434 struct mptfc_rport_info *ri; 434 struct mptfc_rport_info *ri;
435 int new_ri = 1; 435 int new_ri = 1;
436 u64 pn, nn; 436 u64 pn, nn;
437 VirtTarget *vtarget; 437 VirtTarget *vtarget;
438 u32 roles = FC_RPORT_ROLE_UNKNOWN; 438 u32 roles = FC_RPORT_ROLE_UNKNOWN;
439 439
440 if (mptfc_generate_rport_ids(pg0, &rport_ids) < 0) 440 if (mptfc_generate_rport_ids(pg0, &rport_ids) < 0)
441 return; 441 return;
442 442
443 roles |= FC_RPORT_ROLE_FCP_TARGET; 443 roles |= FC_RPORT_ROLE_FCP_TARGET;
444 if (pg0->Protocol & MPI_FC_DEVICE_PAGE0_PROT_FCP_INITIATOR) 444 if (pg0->Protocol & MPI_FC_DEVICE_PAGE0_PROT_FCP_INITIATOR)
445 roles |= FC_RPORT_ROLE_FCP_INITIATOR; 445 roles |= FC_RPORT_ROLE_FCP_INITIATOR;
446 446
447 /* scan list looking for a match */ 447 /* scan list looking for a match */
448 list_for_each_entry(ri, &ioc->fc_rports, list) { 448 list_for_each_entry(ri, &ioc->fc_rports, list) {
449 pn = (u64)ri->pg0.WWPN.High << 32 | (u64)ri->pg0.WWPN.Low; 449 pn = (u64)ri->pg0.WWPN.High << 32 | (u64)ri->pg0.WWPN.Low;
450 if (pn == rport_ids.port_name) { /* match */ 450 if (pn == rport_ids.port_name) { /* match */
451 list_move_tail(&ri->list, &ioc->fc_rports); 451 list_move_tail(&ri->list, &ioc->fc_rports);
452 new_ri = 0; 452 new_ri = 0;
453 break; 453 break;
454 } 454 }
455 } 455 }
456 if (new_ri) { /* allocate one */ 456 if (new_ri) { /* allocate one */
457 ri = kzalloc(sizeof(struct mptfc_rport_info), GFP_KERNEL); 457 ri = kzalloc(sizeof(struct mptfc_rport_info), GFP_KERNEL);
458 if (!ri) 458 if (!ri)
459 return; 459 return;
460 list_add_tail(&ri->list, &ioc->fc_rports); 460 list_add_tail(&ri->list, &ioc->fc_rports);
461 } 461 }
462 462
463 ri->pg0 = *pg0; /* add/update pg0 data */ 463 ri->pg0 = *pg0; /* add/update pg0 data */
464 ri->flags &= ~MPT_RPORT_INFO_FLAGS_MISSING; 464 ri->flags &= ~MPT_RPORT_INFO_FLAGS_MISSING;
465 465
466 /* MPT_RPORT_INFO_FLAGS_REGISTERED - rport not previously deleted */ 466 /* MPT_RPORT_INFO_FLAGS_REGISTERED - rport not previously deleted */
467 if (!(ri->flags & MPT_RPORT_INFO_FLAGS_REGISTERED)) { 467 if (!(ri->flags & MPT_RPORT_INFO_FLAGS_REGISTERED)) {
468 ri->flags |= MPT_RPORT_INFO_FLAGS_REGISTERED; 468 ri->flags |= MPT_RPORT_INFO_FLAGS_REGISTERED;
469 rport = fc_remote_port_add(ioc->sh, channel, &rport_ids); 469 rport = fc_remote_port_add(ioc->sh, channel, &rport_ids);
470 if (rport) { 470 if (rport) {
471 ri->rport = rport; 471 ri->rport = rport;
472 if (new_ri) /* may have been reset by user */ 472 if (new_ri) /* may have been reset by user */
473 rport->dev_loss_tmo = mptfc_dev_loss_tmo; 473 rport->dev_loss_tmo = mptfc_dev_loss_tmo;
474 /* 474 /*
475 * if already mapped, remap here. If not mapped, 475 * if already mapped, remap here. If not mapped,
476 * target_alloc will allocate vtarget and map, 476 * target_alloc will allocate vtarget and map,
477 * slave_alloc will fill in vdevice from vtarget. 477 * slave_alloc will fill in vdevice from vtarget.
478 */ 478 */
479 if (ri->starget) { 479 if (ri->starget) {
480 vtarget = ri->starget->hostdata; 480 vtarget = ri->starget->hostdata;
481 if (vtarget) { 481 if (vtarget) {
482 vtarget->id = pg0->CurrentTargetID; 482 vtarget->id = pg0->CurrentTargetID;
483 vtarget->channel = pg0->CurrentBus; 483 vtarget->channel = pg0->CurrentBus;
484 vtarget->deleted = 0; 484 vtarget->deleted = 0;
485 } 485 }
486 } 486 }
487 *((struct mptfc_rport_info **)rport->dd_data) = ri; 487 *((struct mptfc_rport_info **)rport->dd_data) = ri;
488 /* scan will be scheduled once rport becomes a target */ 488 /* scan will be scheduled once rport becomes a target */
489 fc_remote_port_rolechg(rport,roles); 489 fc_remote_port_rolechg(rport,roles);
490 490
491 pn = (u64)ri->pg0.WWPN.High << 32 | (u64)ri->pg0.WWPN.Low; 491 pn = (u64)ri->pg0.WWPN.High << 32 | (u64)ri->pg0.WWPN.Low;
492 nn = (u64)ri->pg0.WWNN.High << 32 | (u64)ri->pg0.WWNN.Low; 492 nn = (u64)ri->pg0.WWNN.High << 32 | (u64)ri->pg0.WWNN.Low;
493 dfcprintk (ioc, printk(MYIOC_s_DEBUG_FMT 493 dfcprintk (ioc, printk(MYIOC_s_DEBUG_FMT
494 "mptfc_reg_dev.%d: %x, %llx / %llx, tid %d, " 494 "mptfc_reg_dev.%d: %x, %llx / %llx, tid %d, "
495 "rport tid %d, tmo %d\n", 495 "rport tid %d, tmo %d\n",
496 ioc->name, 496 ioc->name,
497 ioc->sh->host_no, 497 ioc->sh->host_no,
498 pg0->PortIdentifier, 498 pg0->PortIdentifier,
499 (unsigned long long)nn, 499 (unsigned long long)nn,
500 (unsigned long long)pn, 500 (unsigned long long)pn,
501 pg0->CurrentTargetID, 501 pg0->CurrentTargetID,
502 ri->rport->scsi_target_id, 502 ri->rport->scsi_target_id,
503 ri->rport->dev_loss_tmo)); 503 ri->rport->dev_loss_tmo));
504 } else { 504 } else {
505 list_del(&ri->list); 505 list_del(&ri->list);
506 kfree(ri); 506 kfree(ri);
507 ri = NULL; 507 ri = NULL;
508 } 508 }
509 } 509 }
510 } 510 }
511 511
512 /* 512 /*
513 * OS entry point to allow for host driver to free allocated memory 513 * OS entry point to allow for host driver to free allocated memory
514 * Called if no device present or device being unloaded 514 * Called if no device present or device being unloaded
515 */ 515 */
516 static void 516 static void
517 mptfc_target_destroy(struct scsi_target *starget) 517 mptfc_target_destroy(struct scsi_target *starget)
518 { 518 {
519 struct fc_rport *rport; 519 struct fc_rport *rport;
520 struct mptfc_rport_info *ri; 520 struct mptfc_rport_info *ri;
521 521
522 rport = starget_to_rport(starget); 522 rport = starget_to_rport(starget);
523 if (rport) { 523 if (rport) {
524 ri = *((struct mptfc_rport_info **)rport->dd_data); 524 ri = *((struct mptfc_rport_info **)rport->dd_data);
525 if (ri) /* better be! */ 525 if (ri) /* better be! */
526 ri->starget = NULL; 526 ri->starget = NULL;
527 } 527 }
528 if (starget->hostdata) 528 if (starget->hostdata)
529 kfree(starget->hostdata); 529 kfree(starget->hostdata);
530 starget->hostdata = NULL; 530 starget->hostdata = NULL;
531 } 531 }
532 532
533 /* 533 /*
534 * OS entry point to allow host driver to alloc memory 534 * OS entry point to allow host driver to alloc memory
535 * for each scsi target. Called once per device the bus scan. 535 * for each scsi target. Called once per device the bus scan.
536 * Return non-zero if allocation fails. 536 * Return non-zero if allocation fails.
537 */ 537 */
538 static int 538 static int
539 mptfc_target_alloc(struct scsi_target *starget) 539 mptfc_target_alloc(struct scsi_target *starget)
540 { 540 {
541 VirtTarget *vtarget; 541 VirtTarget *vtarget;
542 struct fc_rport *rport; 542 struct fc_rport *rport;
543 struct mptfc_rport_info *ri; 543 struct mptfc_rport_info *ri;
544 int rc; 544 int rc;
545 545
546 vtarget = kzalloc(sizeof(VirtTarget), GFP_KERNEL); 546 vtarget = kzalloc(sizeof(VirtTarget), GFP_KERNEL);
547 if (!vtarget) 547 if (!vtarget)
548 return -ENOMEM; 548 return -ENOMEM;
549 starget->hostdata = vtarget; 549 starget->hostdata = vtarget;
550 550
551 rc = -ENODEV; 551 rc = -ENODEV;
552 rport = starget_to_rport(starget); 552 rport = starget_to_rport(starget);
553 if (rport) { 553 if (rport) {
554 ri = *((struct mptfc_rport_info **)rport->dd_data); 554 ri = *((struct mptfc_rport_info **)rport->dd_data);
555 if (ri) { /* better be! */ 555 if (ri) { /* better be! */
556 vtarget->id = ri->pg0.CurrentTargetID; 556 vtarget->id = ri->pg0.CurrentTargetID;
557 vtarget->channel = ri->pg0.CurrentBus; 557 vtarget->channel = ri->pg0.CurrentBus;
558 ri->starget = starget; 558 ri->starget = starget;
559 rc = 0; 559 rc = 0;
560 } 560 }
561 } 561 }
562 if (rc != 0) { 562 if (rc != 0) {
563 kfree(vtarget); 563 kfree(vtarget);
564 starget->hostdata = NULL; 564 starget->hostdata = NULL;
565 } 565 }
566 566
567 return rc; 567 return rc;
568 } 568 }
569 /* 569 /*
570 * mptfc_dump_lun_info 570 * mptfc_dump_lun_info
571 * @ioc 571 * @ioc
572 * @rport 572 * @rport
573 * @sdev 573 * @sdev
574 * 574 *
575 */ 575 */
576 static void 576 static void
577 mptfc_dump_lun_info(MPT_ADAPTER *ioc, struct fc_rport *rport, struct scsi_device *sdev, 577 mptfc_dump_lun_info(MPT_ADAPTER *ioc, struct fc_rport *rport, struct scsi_device *sdev,
578 VirtTarget *vtarget) 578 VirtTarget *vtarget)
579 { 579 {
580 u64 nn, pn; 580 u64 nn, pn;
581 struct mptfc_rport_info *ri; 581 struct mptfc_rport_info *ri;
582 582
583 ri = *((struct mptfc_rport_info **)rport->dd_data); 583 ri = *((struct mptfc_rport_info **)rport->dd_data);
584 pn = (u64)ri->pg0.WWPN.High << 32 | (u64)ri->pg0.WWPN.Low; 584 pn = (u64)ri->pg0.WWPN.High << 32 | (u64)ri->pg0.WWPN.Low;
585 nn = (u64)ri->pg0.WWNN.High << 32 | (u64)ri->pg0.WWNN.Low; 585 nn = (u64)ri->pg0.WWNN.High << 32 | (u64)ri->pg0.WWNN.Low;
586 dfcprintk (ioc, printk(MYIOC_s_DEBUG_FMT 586 dfcprintk (ioc, printk(MYIOC_s_DEBUG_FMT
587 "mptfc_slv_alloc.%d: num_luns %d, sdev.id %d, " 587 "mptfc_slv_alloc.%d: num_luns %d, sdev.id %d, "
588 "CurrentTargetID %d, %x %llx %llx\n", 588 "CurrentTargetID %d, %x %llx %llx\n",
589 ioc->name, 589 ioc->name,
590 sdev->host->host_no, 590 sdev->host->host_no,
591 vtarget->num_luns, 591 vtarget->num_luns,
592 sdev->id, ri->pg0.CurrentTargetID, 592 sdev->id, ri->pg0.CurrentTargetID,
593 ri->pg0.PortIdentifier, 593 ri->pg0.PortIdentifier,
594 (unsigned long long)pn, 594 (unsigned long long)pn,
595 (unsigned long long)nn)); 595 (unsigned long long)nn));
596 } 596 }
597 597
598 598
599 /* 599 /*
600 * OS entry point to allow host driver to alloc memory 600 * OS entry point to allow host driver to alloc memory
601 * for each scsi device. Called once per device the bus scan. 601 * for each scsi device. Called once per device the bus scan.
602 * Return non-zero if allocation fails. 602 * Return non-zero if allocation fails.
603 * Init memory once per LUN. 603 * Init memory once per LUN.
604 */ 604 */
605 static int 605 static int
606 mptfc_slave_alloc(struct scsi_device *sdev) 606 mptfc_slave_alloc(struct scsi_device *sdev)
607 { 607 {
608 MPT_SCSI_HOST *hd; 608 MPT_SCSI_HOST *hd;
609 VirtTarget *vtarget; 609 VirtTarget *vtarget;
610 VirtDevice *vdevice; 610 VirtDevice *vdevice;
611 struct scsi_target *starget; 611 struct scsi_target *starget;
612 struct fc_rport *rport; 612 struct fc_rport *rport;
613 MPT_ADAPTER *ioc; 613 MPT_ADAPTER *ioc;
614 614
615 starget = scsi_target(sdev); 615 starget = scsi_target(sdev);
616 rport = starget_to_rport(starget); 616 rport = starget_to_rport(starget);
617 617
618 if (!rport || fc_remote_port_chkready(rport)) 618 if (!rport || fc_remote_port_chkready(rport))
619 return -ENXIO; 619 return -ENXIO;
620 620
621 hd = shost_priv(sdev->host); 621 hd = shost_priv(sdev->host);
622 ioc = hd->ioc; 622 ioc = hd->ioc;
623 623
624 vdevice = kzalloc(sizeof(VirtDevice), GFP_KERNEL); 624 vdevice = kzalloc(sizeof(VirtDevice), GFP_KERNEL);
625 if (!vdevice) { 625 if (!vdevice) {
626 printk(MYIOC_s_ERR_FMT "slave_alloc kmalloc(%zd) FAILED!\n", 626 printk(MYIOC_s_ERR_FMT "slave_alloc kmalloc(%zd) FAILED!\n",
627 ioc->name, sizeof(VirtDevice)); 627 ioc->name, sizeof(VirtDevice));
628 return -ENOMEM; 628 return -ENOMEM;
629 } 629 }
630 630
631 631
632 sdev->hostdata = vdevice; 632 sdev->hostdata = vdevice;
633 vtarget = starget->hostdata; 633 vtarget = starget->hostdata;
634 634
635 if (vtarget->num_luns == 0) { 635 if (vtarget->num_luns == 0) {
636 vtarget->ioc_id = ioc->id; 636 vtarget->ioc_id = ioc->id;
637 vtarget->tflags = MPT_TARGET_FLAGS_Q_YES; 637 vtarget->tflags = MPT_TARGET_FLAGS_Q_YES;
638 } 638 }
639 639
640 vdevice->vtarget = vtarget; 640 vdevice->vtarget = vtarget;
641 vdevice->lun = sdev->lun; 641 vdevice->lun = sdev->lun;
642 642
643 vtarget->num_luns++; 643 vtarget->num_luns++;
644 644
645 645
646 mptfc_dump_lun_info(ioc, rport, sdev, vtarget); 646 mptfc_dump_lun_info(ioc, rport, sdev, vtarget);
647 647
648 return 0; 648 return 0;
649 } 649 }
650 650
651 static int 651 static int
652 mptfc_qcmd_lck(struct scsi_cmnd *SCpnt, void (*done)(struct scsi_cmnd *)) 652 mptfc_qcmd_lck(struct scsi_cmnd *SCpnt, void (*done)(struct scsi_cmnd *))
653 { 653 {
654 struct mptfc_rport_info *ri; 654 struct mptfc_rport_info *ri;
655 struct fc_rport *rport = starget_to_rport(scsi_target(SCpnt->device)); 655 struct fc_rport *rport = starget_to_rport(scsi_target(SCpnt->device));
656 int err; 656 int err;
657 VirtDevice *vdevice = SCpnt->device->hostdata; 657 VirtDevice *vdevice = SCpnt->device->hostdata;
658 658
659 if (!vdevice || !vdevice->vtarget) { 659 if (!vdevice || !vdevice->vtarget) {
660 SCpnt->result = DID_NO_CONNECT << 16; 660 SCpnt->result = DID_NO_CONNECT << 16;
661 done(SCpnt); 661 done(SCpnt);
662 return 0; 662 return 0;
663 } 663 }
664 664
665 err = fc_remote_port_chkready(rport); 665 err = fc_remote_port_chkready(rport);
666 if (unlikely(err)) { 666 if (unlikely(err)) {
667 SCpnt->result = err; 667 SCpnt->result = err;
668 done(SCpnt); 668 done(SCpnt);
669 return 0; 669 return 0;
670 } 670 }
671 671
672 /* dd_data is null until finished adding target */ 672 /* dd_data is null until finished adding target */
673 ri = *((struct mptfc_rport_info **)rport->dd_data); 673 ri = *((struct mptfc_rport_info **)rport->dd_data);
674 if (unlikely(!ri)) { 674 if (unlikely(!ri)) {
675 SCpnt->result = DID_IMM_RETRY << 16; 675 SCpnt->result = DID_IMM_RETRY << 16;
676 done(SCpnt); 676 done(SCpnt);
677 return 0; 677 return 0;
678 } 678 }
679 679
680 return mptscsih_qcmd(SCpnt,done); 680 return mptscsih_qcmd(SCpnt,done);
681 } 681 }
682 682
683 static DEF_SCSI_QCMD(mptfc_qcmd) 683 static DEF_SCSI_QCMD(mptfc_qcmd)
684 684
685 /* 685 /*
686 * mptfc_display_port_link_speed - displaying link speed 686 * mptfc_display_port_link_speed - displaying link speed
687 * @ioc: Pointer to MPT_ADAPTER structure 687 * @ioc: Pointer to MPT_ADAPTER structure
688 * @portnum: IOC Port number 688 * @portnum: IOC Port number
689 * @pp0dest: port page0 data payload 689 * @pp0dest: port page0 data payload
690 * 690 *
691 */ 691 */
692 static void 692 static void
693 mptfc_display_port_link_speed(MPT_ADAPTER *ioc, int portnum, FCPortPage0_t *pp0dest) 693 mptfc_display_port_link_speed(MPT_ADAPTER *ioc, int portnum, FCPortPage0_t *pp0dest)
694 { 694 {
695 u8 old_speed, new_speed, state; 695 u8 old_speed, new_speed, state;
696 char *old, *new; 696 char *old, *new;
697 697
698 if (portnum >= 2) 698 if (portnum >= 2)
699 return; 699 return;
700 700
701 old_speed = ioc->fc_link_speed[portnum]; 701 old_speed = ioc->fc_link_speed[portnum];
702 new_speed = pp0dest->CurrentSpeed; 702 new_speed = pp0dest->CurrentSpeed;
703 state = pp0dest->PortState; 703 state = pp0dest->PortState;
704 704
705 if (state != MPI_FCPORTPAGE0_PORTSTATE_OFFLINE && 705 if (state != MPI_FCPORTPAGE0_PORTSTATE_OFFLINE &&
706 new_speed != MPI_FCPORTPAGE0_CURRENT_SPEED_UKNOWN) { 706 new_speed != MPI_FCPORTPAGE0_CURRENT_SPEED_UKNOWN) {
707 707
708 old = old_speed == MPI_FCPORTPAGE0_CURRENT_SPEED_1GBIT ? "1 Gbps" : 708 old = old_speed == MPI_FCPORTPAGE0_CURRENT_SPEED_1GBIT ? "1 Gbps" :
709 old_speed == MPI_FCPORTPAGE0_CURRENT_SPEED_2GBIT ? "2 Gbps" : 709 old_speed == MPI_FCPORTPAGE0_CURRENT_SPEED_2GBIT ? "2 Gbps" :
710 old_speed == MPI_FCPORTPAGE0_CURRENT_SPEED_4GBIT ? "4 Gbps" : 710 old_speed == MPI_FCPORTPAGE0_CURRENT_SPEED_4GBIT ? "4 Gbps" :
711 "Unknown"; 711 "Unknown";
712 new = new_speed == MPI_FCPORTPAGE0_CURRENT_SPEED_1GBIT ? "1 Gbps" : 712 new = new_speed == MPI_FCPORTPAGE0_CURRENT_SPEED_1GBIT ? "1 Gbps" :
713 new_speed == MPI_FCPORTPAGE0_CURRENT_SPEED_2GBIT ? "2 Gbps" : 713 new_speed == MPI_FCPORTPAGE0_CURRENT_SPEED_2GBIT ? "2 Gbps" :
714 new_speed == MPI_FCPORTPAGE0_CURRENT_SPEED_4GBIT ? "4 Gbps" : 714 new_speed == MPI_FCPORTPAGE0_CURRENT_SPEED_4GBIT ? "4 Gbps" :
715 "Unknown"; 715 "Unknown";
716 if (old_speed == 0) 716 if (old_speed == 0)
717 printk(MYIOC_s_NOTE_FMT 717 printk(MYIOC_s_NOTE_FMT
718 "FC Link Established, Speed = %s\n", 718 "FC Link Established, Speed = %s\n",
719 ioc->name, new); 719 ioc->name, new);
720 else if (old_speed != new_speed) 720 else if (old_speed != new_speed)
721 printk(MYIOC_s_WARN_FMT 721 printk(MYIOC_s_WARN_FMT
722 "FC Link Speed Change, Old Speed = %s, New Speed = %s\n", 722 "FC Link Speed Change, Old Speed = %s, New Speed = %s\n",
723 ioc->name, old, new); 723 ioc->name, old, new);
724 724
725 ioc->fc_link_speed[portnum] = new_speed; 725 ioc->fc_link_speed[portnum] = new_speed;
726 } 726 }
727 } 727 }
728 728
729 /* 729 /*
730 * mptfc_GetFcPortPage0 - Fetch FCPort config Page0. 730 * mptfc_GetFcPortPage0 - Fetch FCPort config Page0.
731 * @ioc: Pointer to MPT_ADAPTER structure 731 * @ioc: Pointer to MPT_ADAPTER structure
732 * @portnum: IOC Port number 732 * @portnum: IOC Port number
733 * 733 *
734 * Return: 0 for success 734 * Return: 0 for success
735 * -ENOMEM if no memory available 735 * -ENOMEM if no memory available
736 * -EPERM if not allowed due to ISR context 736 * -EPERM if not allowed due to ISR context
737 * -EAGAIN if no msg frames currently available 737 * -EAGAIN if no msg frames currently available
738 * -EFAULT for non-successful reply or no reply (timeout) 738 * -EFAULT for non-successful reply or no reply (timeout)
739 * -EINVAL portnum arg out of range (hardwired to two elements) 739 * -EINVAL portnum arg out of range (hardwired to two elements)
740 */ 740 */
741 static int 741 static int
742 mptfc_GetFcPortPage0(MPT_ADAPTER *ioc, int portnum) 742 mptfc_GetFcPortPage0(MPT_ADAPTER *ioc, int portnum)
743 { 743 {
744 ConfigPageHeader_t hdr; 744 ConfigPageHeader_t hdr;
745 CONFIGPARMS cfg; 745 CONFIGPARMS cfg;
746 FCPortPage0_t *ppage0_alloc; 746 FCPortPage0_t *ppage0_alloc;
747 FCPortPage0_t *pp0dest; 747 FCPortPage0_t *pp0dest;
748 dma_addr_t page0_dma; 748 dma_addr_t page0_dma;
749 int data_sz; 749 int data_sz;
750 int copy_sz; 750 int copy_sz;
751 int rc; 751 int rc;
752 int count = 400; 752 int count = 400;
753 753
754 if (portnum > 1) 754 if (portnum > 1)
755 return -EINVAL; 755 return -EINVAL;
756 756
757 /* Get FCPort Page 0 header */ 757 /* Get FCPort Page 0 header */
758 hdr.PageVersion = 0; 758 hdr.PageVersion = 0;
759 hdr.PageLength = 0; 759 hdr.PageLength = 0;
760 hdr.PageNumber = 0; 760 hdr.PageNumber = 0;
761 hdr.PageType = MPI_CONFIG_PAGETYPE_FC_PORT; 761 hdr.PageType = MPI_CONFIG_PAGETYPE_FC_PORT;
762 cfg.cfghdr.hdr = &hdr; 762 cfg.cfghdr.hdr = &hdr;
763 cfg.physAddr = -1; 763 cfg.physAddr = -1;
764 cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER; 764 cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
765 cfg.dir = 0; 765 cfg.dir = 0;
766 cfg.pageAddr = portnum; 766 cfg.pageAddr = portnum;
767 cfg.timeout = 0; 767 cfg.timeout = 0;
768 768
769 if ((rc = mpt_config(ioc, &cfg)) != 0) 769 if ((rc = mpt_config(ioc, &cfg)) != 0)
770 return rc; 770 return rc;
771 771
772 if (hdr.PageLength == 0) 772 if (hdr.PageLength == 0)
773 return 0; 773 return 0;
774 774
775 data_sz = hdr.PageLength * 4; 775 data_sz = hdr.PageLength * 4;
776 rc = -ENOMEM; 776 rc = -ENOMEM;
777 ppage0_alloc = (FCPortPage0_t *) pci_alloc_consistent(ioc->pcidev, data_sz, &page0_dma); 777 ppage0_alloc = (FCPortPage0_t *) pci_alloc_consistent(ioc->pcidev, data_sz, &page0_dma);
778 if (ppage0_alloc) { 778 if (ppage0_alloc) {
779 779
780 try_again: 780 try_again:
781 memset((u8 *)ppage0_alloc, 0, data_sz); 781 memset((u8 *)ppage0_alloc, 0, data_sz);
782 cfg.physAddr = page0_dma; 782 cfg.physAddr = page0_dma;
783 cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT; 783 cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
784 784
785 if ((rc = mpt_config(ioc, &cfg)) == 0) { 785 if ((rc = mpt_config(ioc, &cfg)) == 0) {
786 /* save the data */ 786 /* save the data */
787 pp0dest = &ioc->fc_port_page0[portnum]; 787 pp0dest = &ioc->fc_port_page0[portnum];
788 copy_sz = min_t(int, sizeof(FCPortPage0_t), data_sz); 788 copy_sz = min_t(int, sizeof(FCPortPage0_t), data_sz);
789 memcpy(pp0dest, ppage0_alloc, copy_sz); 789 memcpy(pp0dest, ppage0_alloc, copy_sz);
790 790
791 /* 791 /*
792 * Normalize endianness of structure data, 792 * Normalize endianness of structure data,
793 * by byte-swapping all > 1 byte fields! 793 * by byte-swapping all > 1 byte fields!
794 */ 794 */
795 pp0dest->Flags = le32_to_cpu(pp0dest->Flags); 795 pp0dest->Flags = le32_to_cpu(pp0dest->Flags);
796 pp0dest->PortIdentifier = le32_to_cpu(pp0dest->PortIdentifier); 796 pp0dest->PortIdentifier = le32_to_cpu(pp0dest->PortIdentifier);
797 pp0dest->WWNN.Low = le32_to_cpu(pp0dest->WWNN.Low); 797 pp0dest->WWNN.Low = le32_to_cpu(pp0dest->WWNN.Low);
798 pp0dest->WWNN.High = le32_to_cpu(pp0dest->WWNN.High); 798 pp0dest->WWNN.High = le32_to_cpu(pp0dest->WWNN.High);
799 pp0dest->WWPN.Low = le32_to_cpu(pp0dest->WWPN.Low); 799 pp0dest->WWPN.Low = le32_to_cpu(pp0dest->WWPN.Low);
800 pp0dest->WWPN.High = le32_to_cpu(pp0dest->WWPN.High); 800 pp0dest->WWPN.High = le32_to_cpu(pp0dest->WWPN.High);
801 pp0dest->SupportedServiceClass = le32_to_cpu(pp0dest->SupportedServiceClass); 801 pp0dest->SupportedServiceClass = le32_to_cpu(pp0dest->SupportedServiceClass);
802 pp0dest->SupportedSpeeds = le32_to_cpu(pp0dest->SupportedSpeeds); 802 pp0dest->SupportedSpeeds = le32_to_cpu(pp0dest->SupportedSpeeds);
803 pp0dest->CurrentSpeed = le32_to_cpu(pp0dest->CurrentSpeed); 803 pp0dest->CurrentSpeed = le32_to_cpu(pp0dest->CurrentSpeed);
804 pp0dest->MaxFrameSize = le32_to_cpu(pp0dest->MaxFrameSize); 804 pp0dest->MaxFrameSize = le32_to_cpu(pp0dest->MaxFrameSize);
805 pp0dest->FabricWWNN.Low = le32_to_cpu(pp0dest->FabricWWNN.Low); 805 pp0dest->FabricWWNN.Low = le32_to_cpu(pp0dest->FabricWWNN.Low);
806 pp0dest->FabricWWNN.High = le32_to_cpu(pp0dest->FabricWWNN.High); 806 pp0dest->FabricWWNN.High = le32_to_cpu(pp0dest->FabricWWNN.High);
807 pp0dest->FabricWWPN.Low = le32_to_cpu(pp0dest->FabricWWPN.Low); 807 pp0dest->FabricWWPN.Low = le32_to_cpu(pp0dest->FabricWWPN.Low);
808 pp0dest->FabricWWPN.High = le32_to_cpu(pp0dest->FabricWWPN.High); 808 pp0dest->FabricWWPN.High = le32_to_cpu(pp0dest->FabricWWPN.High);
809 pp0dest->DiscoveredPortsCount = le32_to_cpu(pp0dest->DiscoveredPortsCount); 809 pp0dest->DiscoveredPortsCount = le32_to_cpu(pp0dest->DiscoveredPortsCount);
810 pp0dest->MaxInitiators = le32_to_cpu(pp0dest->MaxInitiators); 810 pp0dest->MaxInitiators = le32_to_cpu(pp0dest->MaxInitiators);
811 811
812 /* 812 /*
813 * if still doing discovery, 813 * if still doing discovery,
814 * hang loose a while until finished 814 * hang loose a while until finished
815 */ 815 */
816 if ((pp0dest->PortState == MPI_FCPORTPAGE0_PORTSTATE_UNKNOWN) || 816 if ((pp0dest->PortState == MPI_FCPORTPAGE0_PORTSTATE_UNKNOWN) ||
817 (pp0dest->PortState == MPI_FCPORTPAGE0_PORTSTATE_ONLINE && 817 (pp0dest->PortState == MPI_FCPORTPAGE0_PORTSTATE_ONLINE &&
818 (pp0dest->Flags & MPI_FCPORTPAGE0_FLAGS_ATTACH_TYPE_MASK) 818 (pp0dest->Flags & MPI_FCPORTPAGE0_FLAGS_ATTACH_TYPE_MASK)
819 == MPI_FCPORTPAGE0_FLAGS_ATTACH_NO_INIT)) { 819 == MPI_FCPORTPAGE0_FLAGS_ATTACH_NO_INIT)) {
820 if (count-- > 0) { 820 if (count-- > 0) {
821 msleep(100); 821 msleep(100);
822 goto try_again; 822 goto try_again;
823 } 823 }
824 printk(MYIOC_s_INFO_FMT "Firmware discovery not" 824 printk(MYIOC_s_INFO_FMT "Firmware discovery not"
825 " complete.\n", 825 " complete.\n",
826 ioc->name); 826 ioc->name);
827 } 827 }
828 mptfc_display_port_link_speed(ioc, portnum, pp0dest); 828 mptfc_display_port_link_speed(ioc, portnum, pp0dest);
829 } 829 }
830 830
831 pci_free_consistent(ioc->pcidev, data_sz, (u8 *) ppage0_alloc, page0_dma); 831 pci_free_consistent(ioc->pcidev, data_sz, (u8 *) ppage0_alloc, page0_dma);
832 } 832 }
833 833
834 return rc; 834 return rc;
835 } 835 }
836 836
837 static int 837 static int
838 mptfc_WriteFcPortPage1(MPT_ADAPTER *ioc, int portnum) 838 mptfc_WriteFcPortPage1(MPT_ADAPTER *ioc, int portnum)
839 { 839 {
840 ConfigPageHeader_t hdr; 840 ConfigPageHeader_t hdr;
841 CONFIGPARMS cfg; 841 CONFIGPARMS cfg;
842 int rc; 842 int rc;
843 843
844 if (portnum > 1) 844 if (portnum > 1)
845 return -EINVAL; 845 return -EINVAL;
846 846
847 if (!(ioc->fc_data.fc_port_page1[portnum].data)) 847 if (!(ioc->fc_data.fc_port_page1[portnum].data))
848 return -EINVAL; 848 return -EINVAL;
849 849
850 /* get fcport page 1 header */ 850 /* get fcport page 1 header */
851 hdr.PageVersion = 0; 851 hdr.PageVersion = 0;
852 hdr.PageLength = 0; 852 hdr.PageLength = 0;
853 hdr.PageNumber = 1; 853 hdr.PageNumber = 1;
854 hdr.PageType = MPI_CONFIG_PAGETYPE_FC_PORT; 854 hdr.PageType = MPI_CONFIG_PAGETYPE_FC_PORT;
855 cfg.cfghdr.hdr = &hdr; 855 cfg.cfghdr.hdr = &hdr;
856 cfg.physAddr = -1; 856 cfg.physAddr = -1;
857 cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER; 857 cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
858 cfg.dir = 0; 858 cfg.dir = 0;
859 cfg.pageAddr = portnum; 859 cfg.pageAddr = portnum;
860 cfg.timeout = 0; 860 cfg.timeout = 0;
861 861
862 if ((rc = mpt_config(ioc, &cfg)) != 0) 862 if ((rc = mpt_config(ioc, &cfg)) != 0)
863 return rc; 863 return rc;
864 864
865 if (hdr.PageLength == 0) 865 if (hdr.PageLength == 0)
866 return -ENODEV; 866 return -ENODEV;
867 867
868 if (hdr.PageLength*4 != ioc->fc_data.fc_port_page1[portnum].pg_sz) 868 if (hdr.PageLength*4 != ioc->fc_data.fc_port_page1[portnum].pg_sz)
869 return -EINVAL; 869 return -EINVAL;
870 870
871 cfg.physAddr = ioc->fc_data.fc_port_page1[portnum].dma; 871 cfg.physAddr = ioc->fc_data.fc_port_page1[portnum].dma;
872 cfg.action = MPI_CONFIG_ACTION_PAGE_WRITE_CURRENT; 872 cfg.action = MPI_CONFIG_ACTION_PAGE_WRITE_CURRENT;
873 cfg.dir = 1; 873 cfg.dir = 1;
874 874
875 rc = mpt_config(ioc, &cfg); 875 rc = mpt_config(ioc, &cfg);
876 876
877 return rc; 877 return rc;
878 } 878 }
879 879
880 static int 880 static int
881 mptfc_GetFcPortPage1(MPT_ADAPTER *ioc, int portnum) 881 mptfc_GetFcPortPage1(MPT_ADAPTER *ioc, int portnum)
882 { 882 {
883 ConfigPageHeader_t hdr; 883 ConfigPageHeader_t hdr;
884 CONFIGPARMS cfg; 884 CONFIGPARMS cfg;
885 FCPortPage1_t *page1_alloc; 885 FCPortPage1_t *page1_alloc;
886 dma_addr_t page1_dma; 886 dma_addr_t page1_dma;
887 int data_sz; 887 int data_sz;
888 int rc; 888 int rc;
889 889
890 if (portnum > 1) 890 if (portnum > 1)
891 return -EINVAL; 891 return -EINVAL;
892 892
893 /* get fcport page 1 header */ 893 /* get fcport page 1 header */
894 hdr.PageVersion = 0; 894 hdr.PageVersion = 0;
895 hdr.PageLength = 0; 895 hdr.PageLength = 0;
896 hdr.PageNumber = 1; 896 hdr.PageNumber = 1;
897 hdr.PageType = MPI_CONFIG_PAGETYPE_FC_PORT; 897 hdr.PageType = MPI_CONFIG_PAGETYPE_FC_PORT;
898 cfg.cfghdr.hdr = &hdr; 898 cfg.cfghdr.hdr = &hdr;
899 cfg.physAddr = -1; 899 cfg.physAddr = -1;
900 cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER; 900 cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
901 cfg.dir = 0; 901 cfg.dir = 0;
902 cfg.pageAddr = portnum; 902 cfg.pageAddr = portnum;
903 cfg.timeout = 0; 903 cfg.timeout = 0;
904 904
905 if ((rc = mpt_config(ioc, &cfg)) != 0) 905 if ((rc = mpt_config(ioc, &cfg)) != 0)
906 return rc; 906 return rc;
907 907
908 if (hdr.PageLength == 0) 908 if (hdr.PageLength == 0)
909 return -ENODEV; 909 return -ENODEV;
910 910
911 start_over: 911 start_over:
912 912
913 if (ioc->fc_data.fc_port_page1[portnum].data == NULL) { 913 if (ioc->fc_data.fc_port_page1[portnum].data == NULL) {
914 data_sz = hdr.PageLength * 4; 914 data_sz = hdr.PageLength * 4;
915 if (data_sz < sizeof(FCPortPage1_t)) 915 if (data_sz < sizeof(FCPortPage1_t))
916 data_sz = sizeof(FCPortPage1_t); 916 data_sz = sizeof(FCPortPage1_t);
917 917
918 page1_alloc = (FCPortPage1_t *) pci_alloc_consistent(ioc->pcidev, 918 page1_alloc = (FCPortPage1_t *) pci_alloc_consistent(ioc->pcidev,
919 data_sz, 919 data_sz,
920 &page1_dma); 920 &page1_dma);
921 if (!page1_alloc) 921 if (!page1_alloc)
922 return -ENOMEM; 922 return -ENOMEM;
923 } 923 }
924 else { 924 else {
925 page1_alloc = ioc->fc_data.fc_port_page1[portnum].data; 925 page1_alloc = ioc->fc_data.fc_port_page1[portnum].data;
926 page1_dma = ioc->fc_data.fc_port_page1[portnum].dma; 926 page1_dma = ioc->fc_data.fc_port_page1[portnum].dma;
927 data_sz = ioc->fc_data.fc_port_page1[portnum].pg_sz; 927 data_sz = ioc->fc_data.fc_port_page1[portnum].pg_sz;
928 if (hdr.PageLength * 4 > data_sz) { 928 if (hdr.PageLength * 4 > data_sz) {
929 ioc->fc_data.fc_port_page1[portnum].data = NULL; 929 ioc->fc_data.fc_port_page1[portnum].data = NULL;
930 pci_free_consistent(ioc->pcidev, data_sz, (u8 *) 930 pci_free_consistent(ioc->pcidev, data_sz, (u8 *)
931 page1_alloc, page1_dma); 931 page1_alloc, page1_dma);
932 goto start_over; 932 goto start_over;
933 } 933 }
934 } 934 }
935 935
936 memset(page1_alloc,0,data_sz); 936 memset(page1_alloc,0,data_sz);
937 937
938 cfg.physAddr = page1_dma; 938 cfg.physAddr = page1_dma;
939 cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT; 939 cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
940 940
941 if ((rc = mpt_config(ioc, &cfg)) == 0) { 941 if ((rc = mpt_config(ioc, &cfg)) == 0) {
942 ioc->fc_data.fc_port_page1[portnum].data = page1_alloc; 942 ioc->fc_data.fc_port_page1[portnum].data = page1_alloc;
943 ioc->fc_data.fc_port_page1[portnum].pg_sz = data_sz; 943 ioc->fc_data.fc_port_page1[portnum].pg_sz = data_sz;
944 ioc->fc_data.fc_port_page1[portnum].dma = page1_dma; 944 ioc->fc_data.fc_port_page1[portnum].dma = page1_dma;
945 } 945 }
946 else { 946 else {
947 ioc->fc_data.fc_port_page1[portnum].data = NULL; 947 ioc->fc_data.fc_port_page1[portnum].data = NULL;
948 pci_free_consistent(ioc->pcidev, data_sz, (u8 *) 948 pci_free_consistent(ioc->pcidev, data_sz, (u8 *)
949 page1_alloc, page1_dma); 949 page1_alloc, page1_dma);
950 } 950 }
951 951
952 return rc; 952 return rc;
953 } 953 }
954 954
955 static void 955 static void
956 mptfc_SetFcPortPage1_defaults(MPT_ADAPTER *ioc) 956 mptfc_SetFcPortPage1_defaults(MPT_ADAPTER *ioc)
957 { 957 {
958 int ii; 958 int ii;
959 FCPortPage1_t *pp1; 959 FCPortPage1_t *pp1;
960 960
961 #define MPTFC_FW_DEVICE_TIMEOUT (1) 961 #define MPTFC_FW_DEVICE_TIMEOUT (1)
962 #define MPTFC_FW_IO_PEND_TIMEOUT (1) 962 #define MPTFC_FW_IO_PEND_TIMEOUT (1)
963 #define ON_FLAGS (MPI_FCPORTPAGE1_FLAGS_IMMEDIATE_ERROR_REPLY) 963 #define ON_FLAGS (MPI_FCPORTPAGE1_FLAGS_IMMEDIATE_ERROR_REPLY)
964 #define OFF_FLAGS (MPI_FCPORTPAGE1_FLAGS_VERBOSE_RESCAN_EVENTS) 964 #define OFF_FLAGS (MPI_FCPORTPAGE1_FLAGS_VERBOSE_RESCAN_EVENTS)
965 965
966 for (ii=0; ii<ioc->facts.NumberOfPorts; ii++) { 966 for (ii=0; ii<ioc->facts.NumberOfPorts; ii++) {
967 if (mptfc_GetFcPortPage1(ioc, ii) != 0) 967 if (mptfc_GetFcPortPage1(ioc, ii) != 0)
968 continue; 968 continue;
969 pp1 = ioc->fc_data.fc_port_page1[ii].data; 969 pp1 = ioc->fc_data.fc_port_page1[ii].data;
970 if ((pp1->InitiatorDeviceTimeout == MPTFC_FW_DEVICE_TIMEOUT) 970 if ((pp1->InitiatorDeviceTimeout == MPTFC_FW_DEVICE_TIMEOUT)
971 && (pp1->InitiatorIoPendTimeout == MPTFC_FW_IO_PEND_TIMEOUT) 971 && (pp1->InitiatorIoPendTimeout == MPTFC_FW_IO_PEND_TIMEOUT)
972 && ((pp1->Flags & ON_FLAGS) == ON_FLAGS) 972 && ((pp1->Flags & ON_FLAGS) == ON_FLAGS)
973 && ((pp1->Flags & OFF_FLAGS) == 0)) 973 && ((pp1->Flags & OFF_FLAGS) == 0))
974 continue; 974 continue;
975 pp1->InitiatorDeviceTimeout = MPTFC_FW_DEVICE_TIMEOUT; 975 pp1->InitiatorDeviceTimeout = MPTFC_FW_DEVICE_TIMEOUT;
976 pp1->InitiatorIoPendTimeout = MPTFC_FW_IO_PEND_TIMEOUT; 976 pp1->InitiatorIoPendTimeout = MPTFC_FW_IO_PEND_TIMEOUT;
977 pp1->Flags &= ~OFF_FLAGS; 977 pp1->Flags &= ~OFF_FLAGS;
978 pp1->Flags |= ON_FLAGS; 978 pp1->Flags |= ON_FLAGS;
979 mptfc_WriteFcPortPage1(ioc, ii); 979 mptfc_WriteFcPortPage1(ioc, ii);
980 } 980 }
981 } 981 }
982 982
983 983
984 static void 984 static void
985 mptfc_init_host_attr(MPT_ADAPTER *ioc,int portnum) 985 mptfc_init_host_attr(MPT_ADAPTER *ioc,int portnum)
986 { 986 {
987 unsigned class = 0; 987 unsigned class = 0;
988 unsigned cos = 0; 988 unsigned cos = 0;
989 unsigned speed; 989 unsigned speed;
990 unsigned port_type; 990 unsigned port_type;
991 unsigned port_state; 991 unsigned port_state;
992 FCPortPage0_t *pp0; 992 FCPortPage0_t *pp0;
993 struct Scsi_Host *sh; 993 struct Scsi_Host *sh;
994 char *sn; 994 char *sn;
995 995
996 /* don't know what to do as only one scsi (fc) host was allocated */ 996 /* don't know what to do as only one scsi (fc) host was allocated */
997 if (portnum != 0) 997 if (portnum != 0)
998 return; 998 return;
999 999
1000 pp0 = &ioc->fc_port_page0[portnum]; 1000 pp0 = &ioc->fc_port_page0[portnum];
1001 sh = ioc->sh; 1001 sh = ioc->sh;
1002 1002
1003 sn = fc_host_symbolic_name(sh); 1003 sn = fc_host_symbolic_name(sh);
1004 snprintf(sn, FC_SYMBOLIC_NAME_SIZE, "%s %s%08xh", 1004 snprintf(sn, FC_SYMBOLIC_NAME_SIZE, "%s %s%08xh",
1005 ioc->prod_name, 1005 ioc->prod_name,
1006 MPT_FW_REV_MAGIC_ID_STRING, 1006 MPT_FW_REV_MAGIC_ID_STRING,
1007 ioc->facts.FWVersion.Word); 1007 ioc->facts.FWVersion.Word);
1008 1008
1009 fc_host_tgtid_bind_type(sh) = FC_TGTID_BIND_BY_WWPN; 1009 fc_host_tgtid_bind_type(sh) = FC_TGTID_BIND_BY_WWPN;
1010 1010
1011 fc_host_maxframe_size(sh) = pp0->MaxFrameSize; 1011 fc_host_maxframe_size(sh) = pp0->MaxFrameSize;
1012 1012
1013 fc_host_node_name(sh) = 1013 fc_host_node_name(sh) =
1014 (u64)pp0->WWNN.High << 32 | (u64)pp0->WWNN.Low; 1014 (u64)pp0->WWNN.High << 32 | (u64)pp0->WWNN.Low;
1015 1015
1016 fc_host_port_name(sh) = 1016 fc_host_port_name(sh) =
1017 (u64)pp0->WWPN.High << 32 | (u64)pp0->WWPN.Low; 1017 (u64)pp0->WWPN.High << 32 | (u64)pp0->WWPN.Low;
1018 1018
1019 fc_host_port_id(sh) = pp0->PortIdentifier; 1019 fc_host_port_id(sh) = pp0->PortIdentifier;
1020 1020
1021 class = pp0->SupportedServiceClass; 1021 class = pp0->SupportedServiceClass;
1022 if (class & MPI_FCPORTPAGE0_SUPPORT_CLASS_1) 1022 if (class & MPI_FCPORTPAGE0_SUPPORT_CLASS_1)
1023 cos |= FC_COS_CLASS1; 1023 cos |= FC_COS_CLASS1;
1024 if (class & MPI_FCPORTPAGE0_SUPPORT_CLASS_2) 1024 if (class & MPI_FCPORTPAGE0_SUPPORT_CLASS_2)
1025 cos |= FC_COS_CLASS2; 1025 cos |= FC_COS_CLASS2;
1026 if (class & MPI_FCPORTPAGE0_SUPPORT_CLASS_3) 1026 if (class & MPI_FCPORTPAGE0_SUPPORT_CLASS_3)
1027 cos |= FC_COS_CLASS3; 1027 cos |= FC_COS_CLASS3;
1028 fc_host_supported_classes(sh) = cos; 1028 fc_host_supported_classes(sh) = cos;
1029 1029
1030 if (pp0->CurrentSpeed == MPI_FCPORTPAGE0_CURRENT_SPEED_1GBIT) 1030 if (pp0->CurrentSpeed == MPI_FCPORTPAGE0_CURRENT_SPEED_1GBIT)
1031 speed = FC_PORTSPEED_1GBIT; 1031 speed = FC_PORTSPEED_1GBIT;
1032 else if (pp0->CurrentSpeed == MPI_FCPORTPAGE0_CURRENT_SPEED_2GBIT) 1032 else if (pp0->CurrentSpeed == MPI_FCPORTPAGE0_CURRENT_SPEED_2GBIT)
1033 speed = FC_PORTSPEED_2GBIT; 1033 speed = FC_PORTSPEED_2GBIT;
1034 else if (pp0->CurrentSpeed == MPI_FCPORTPAGE0_CURRENT_SPEED_4GBIT) 1034 else if (pp0->CurrentSpeed == MPI_FCPORTPAGE0_CURRENT_SPEED_4GBIT)
1035 speed = FC_PORTSPEED_4GBIT; 1035 speed = FC_PORTSPEED_4GBIT;
1036 else if (pp0->CurrentSpeed == MPI_FCPORTPAGE0_CURRENT_SPEED_10GBIT) 1036 else if (pp0->CurrentSpeed == MPI_FCPORTPAGE0_CURRENT_SPEED_10GBIT)
1037 speed = FC_PORTSPEED_10GBIT; 1037 speed = FC_PORTSPEED_10GBIT;
1038 else 1038 else
1039 speed = FC_PORTSPEED_UNKNOWN; 1039 speed = FC_PORTSPEED_UNKNOWN;
1040 fc_host_speed(sh) = speed; 1040 fc_host_speed(sh) = speed;
1041 1041
1042 speed = 0; 1042 speed = 0;
1043 if (pp0->SupportedSpeeds & MPI_FCPORTPAGE0_SUPPORT_1GBIT_SPEED) 1043 if (pp0->SupportedSpeeds & MPI_FCPORTPAGE0_SUPPORT_1GBIT_SPEED)
1044 speed |= FC_PORTSPEED_1GBIT; 1044 speed |= FC_PORTSPEED_1GBIT;
1045 if (pp0->SupportedSpeeds & MPI_FCPORTPAGE0_SUPPORT_2GBIT_SPEED) 1045 if (pp0->SupportedSpeeds & MPI_FCPORTPAGE0_SUPPORT_2GBIT_SPEED)
1046 speed |= FC_PORTSPEED_2GBIT; 1046 speed |= FC_PORTSPEED_2GBIT;
1047 if (pp0->SupportedSpeeds & MPI_FCPORTPAGE0_SUPPORT_4GBIT_SPEED) 1047 if (pp0->SupportedSpeeds & MPI_FCPORTPAGE0_SUPPORT_4GBIT_SPEED)
1048 speed |= FC_PORTSPEED_4GBIT; 1048 speed |= FC_PORTSPEED_4GBIT;
1049 if (pp0->SupportedSpeeds & MPI_FCPORTPAGE0_SUPPORT_10GBIT_SPEED) 1049 if (pp0->SupportedSpeeds & MPI_FCPORTPAGE0_SUPPORT_10GBIT_SPEED)
1050 speed |= FC_PORTSPEED_10GBIT; 1050 speed |= FC_PORTSPEED_10GBIT;
1051 fc_host_supported_speeds(sh) = speed; 1051 fc_host_supported_speeds(sh) = speed;
1052 1052
1053 port_state = FC_PORTSTATE_UNKNOWN; 1053 port_state = FC_PORTSTATE_UNKNOWN;
1054 if (pp0->PortState == MPI_FCPORTPAGE0_PORTSTATE_ONLINE) 1054 if (pp0->PortState == MPI_FCPORTPAGE0_PORTSTATE_ONLINE)
1055 port_state = FC_PORTSTATE_ONLINE; 1055 port_state = FC_PORTSTATE_ONLINE;
1056 else if (pp0->PortState == MPI_FCPORTPAGE0_PORTSTATE_OFFLINE) 1056 else if (pp0->PortState == MPI_FCPORTPAGE0_PORTSTATE_OFFLINE)
1057 port_state = FC_PORTSTATE_LINKDOWN; 1057 port_state = FC_PORTSTATE_LINKDOWN;
1058 fc_host_port_state(sh) = port_state; 1058 fc_host_port_state(sh) = port_state;
1059 1059
1060 port_type = FC_PORTTYPE_UNKNOWN; 1060 port_type = FC_PORTTYPE_UNKNOWN;
1061 if (pp0->Flags & MPI_FCPORTPAGE0_FLAGS_ATTACH_POINT_TO_POINT) 1061 if (pp0->Flags & MPI_FCPORTPAGE0_FLAGS_ATTACH_POINT_TO_POINT)
1062 port_type = FC_PORTTYPE_PTP; 1062 port_type = FC_PORTTYPE_PTP;
1063 else if (pp0->Flags & MPI_FCPORTPAGE0_FLAGS_ATTACH_PRIVATE_LOOP) 1063 else if (pp0->Flags & MPI_FCPORTPAGE0_FLAGS_ATTACH_PRIVATE_LOOP)
1064 port_type = FC_PORTTYPE_LPORT; 1064 port_type = FC_PORTTYPE_LPORT;
1065 else if (pp0->Flags & MPI_FCPORTPAGE0_FLAGS_ATTACH_PUBLIC_LOOP) 1065 else if (pp0->Flags & MPI_FCPORTPAGE0_FLAGS_ATTACH_PUBLIC_LOOP)
1066 port_type = FC_PORTTYPE_NLPORT; 1066 port_type = FC_PORTTYPE_NLPORT;
1067 else if (pp0->Flags & MPI_FCPORTPAGE0_FLAGS_ATTACH_FABRIC_DIRECT) 1067 else if (pp0->Flags & MPI_FCPORTPAGE0_FLAGS_ATTACH_FABRIC_DIRECT)
1068 port_type = FC_PORTTYPE_NPORT; 1068 port_type = FC_PORTTYPE_NPORT;
1069 fc_host_port_type(sh) = port_type; 1069 fc_host_port_type(sh) = port_type;
1070 1070
1071 fc_host_fabric_name(sh) = 1071 fc_host_fabric_name(sh) =
1072 (pp0->Flags & MPI_FCPORTPAGE0_FLAGS_FABRIC_WWN_VALID) ? 1072 (pp0->Flags & MPI_FCPORTPAGE0_FLAGS_FABRIC_WWN_VALID) ?
1073 (u64) pp0->FabricWWNN.High << 32 | (u64) pp0->FabricWWPN.Low : 1073 (u64) pp0->FabricWWNN.High << 32 | (u64) pp0->FabricWWPN.Low :
1074 (u64)pp0->WWNN.High << 32 | (u64)pp0->WWNN.Low; 1074 (u64)pp0->WWNN.High << 32 | (u64)pp0->WWNN.Low;
1075 1075
1076 } 1076 }
1077 1077
1078 static void 1078 static void
1079 mptfc_link_status_change(struct work_struct *work) 1079 mptfc_link_status_change(struct work_struct *work)
1080 { 1080 {
1081 MPT_ADAPTER *ioc = 1081 MPT_ADAPTER *ioc =
1082 container_of(work, MPT_ADAPTER, fc_rescan_work); 1082 container_of(work, MPT_ADAPTER, fc_rescan_work);
1083 int ii; 1083 int ii;
1084 1084
1085 for (ii=0; ii < ioc->facts.NumberOfPorts; ii++) 1085 for (ii=0; ii < ioc->facts.NumberOfPorts; ii++)
1086 (void) mptfc_GetFcPortPage0(ioc, ii); 1086 (void) mptfc_GetFcPortPage0(ioc, ii);
1087 1087
1088 } 1088 }
1089 1089
1090 static void 1090 static void
1091 mptfc_setup_reset(struct work_struct *work) 1091 mptfc_setup_reset(struct work_struct *work)
1092 { 1092 {
1093 MPT_ADAPTER *ioc = 1093 MPT_ADAPTER *ioc =
1094 container_of(work, MPT_ADAPTER, fc_setup_reset_work); 1094 container_of(work, MPT_ADAPTER, fc_setup_reset_work);
1095 u64 pn; 1095 u64 pn;
1096 struct mptfc_rport_info *ri; 1096 struct mptfc_rport_info *ri;
1097 struct scsi_target *starget; 1097 struct scsi_target *starget;
1098 VirtTarget *vtarget; 1098 VirtTarget *vtarget;
1099 1099
1100 /* reset about to happen, delete (block) all rports */ 1100 /* reset about to happen, delete (block) all rports */
1101 list_for_each_entry(ri, &ioc->fc_rports, list) { 1101 list_for_each_entry(ri, &ioc->fc_rports, list) {
1102 if (ri->flags & MPT_RPORT_INFO_FLAGS_REGISTERED) { 1102 if (ri->flags & MPT_RPORT_INFO_FLAGS_REGISTERED) {
1103 ri->flags &= ~MPT_RPORT_INFO_FLAGS_REGISTERED; 1103 ri->flags &= ~MPT_RPORT_INFO_FLAGS_REGISTERED;
1104 fc_remote_port_delete(ri->rport); /* won't sleep */ 1104 fc_remote_port_delete(ri->rport); /* won't sleep */
1105 ri->rport = NULL; 1105 ri->rport = NULL;
1106 starget = ri->starget; 1106 starget = ri->starget;
1107 if (starget) { 1107 if (starget) {
1108 vtarget = starget->hostdata; 1108 vtarget = starget->hostdata;
1109 if (vtarget) 1109 if (vtarget)
1110 vtarget->deleted = 1; 1110 vtarget->deleted = 1;
1111 } 1111 }
1112 1112
1113 pn = (u64)ri->pg0.WWPN.High << 32 | 1113 pn = (u64)ri->pg0.WWPN.High << 32 |
1114 (u64)ri->pg0.WWPN.Low; 1114 (u64)ri->pg0.WWPN.Low;
1115 dfcprintk (ioc, printk(MYIOC_s_DEBUG_FMT 1115 dfcprintk (ioc, printk(MYIOC_s_DEBUG_FMT
1116 "mptfc_setup_reset.%d: %llx deleted\n", 1116 "mptfc_setup_reset.%d: %llx deleted\n",
1117 ioc->name, 1117 ioc->name,
1118 ioc->sh->host_no, 1118 ioc->sh->host_no,
1119 (unsigned long long)pn)); 1119 (unsigned long long)pn));
1120 } 1120 }
1121 } 1121 }
1122 } 1122 }
1123 1123
1124 static void 1124 static void
1125 mptfc_rescan_devices(struct work_struct *work) 1125 mptfc_rescan_devices(struct work_struct *work)
1126 { 1126 {
1127 MPT_ADAPTER *ioc = 1127 MPT_ADAPTER *ioc =
1128 container_of(work, MPT_ADAPTER, fc_rescan_work); 1128 container_of(work, MPT_ADAPTER, fc_rescan_work);
1129 int ii; 1129 int ii;
1130 u64 pn; 1130 u64 pn;
1131 struct mptfc_rport_info *ri; 1131 struct mptfc_rport_info *ri;
1132 struct scsi_target *starget; 1132 struct scsi_target *starget;
1133 VirtTarget *vtarget; 1133 VirtTarget *vtarget;
1134 1134
1135 /* start by tagging all ports as missing */ 1135 /* start by tagging all ports as missing */
1136 list_for_each_entry(ri, &ioc->fc_rports, list) { 1136 list_for_each_entry(ri, &ioc->fc_rports, list) {
1137 if (ri->flags & MPT_RPORT_INFO_FLAGS_REGISTERED) { 1137 if (ri->flags & MPT_RPORT_INFO_FLAGS_REGISTERED) {
1138 ri->flags |= MPT_RPORT_INFO_FLAGS_MISSING; 1138 ri->flags |= MPT_RPORT_INFO_FLAGS_MISSING;
1139 } 1139 }
1140 } 1140 }
1141 1141
1142 /* 1142 /*
1143 * now rescan devices known to adapter, 1143 * now rescan devices known to adapter,
1144 * will reregister existing rports 1144 * will reregister existing rports
1145 */ 1145 */
1146 for (ii=0; ii < ioc->facts.NumberOfPorts; ii++) { 1146 for (ii=0; ii < ioc->facts.NumberOfPorts; ii++) {
1147 (void) mptfc_GetFcPortPage0(ioc, ii); 1147 (void) mptfc_GetFcPortPage0(ioc, ii);
1148 mptfc_init_host_attr(ioc, ii); /* refresh */ 1148 mptfc_init_host_attr(ioc, ii); /* refresh */
1149 mptfc_GetFcDevPage0(ioc, ii, mptfc_register_dev); 1149 mptfc_GetFcDevPage0(ioc, ii, mptfc_register_dev);
1150 } 1150 }
1151 1151
1152 /* delete devices still missing */ 1152 /* delete devices still missing */
1153 list_for_each_entry(ri, &ioc->fc_rports, list) { 1153 list_for_each_entry(ri, &ioc->fc_rports, list) {
1154 /* if newly missing, delete it */ 1154 /* if newly missing, delete it */
1155 if (ri->flags & MPT_RPORT_INFO_FLAGS_MISSING) { 1155 if (ri->flags & MPT_RPORT_INFO_FLAGS_MISSING) {
1156 1156
1157 ri->flags &= ~(MPT_RPORT_INFO_FLAGS_REGISTERED| 1157 ri->flags &= ~(MPT_RPORT_INFO_FLAGS_REGISTERED|
1158 MPT_RPORT_INFO_FLAGS_MISSING); 1158 MPT_RPORT_INFO_FLAGS_MISSING);
1159 fc_remote_port_delete(ri->rport); /* won't sleep */ 1159 fc_remote_port_delete(ri->rport); /* won't sleep */
1160 ri->rport = NULL; 1160 ri->rport = NULL;
1161 starget = ri->starget; 1161 starget = ri->starget;
1162 if (starget) { 1162 if (starget) {
1163 vtarget = starget->hostdata; 1163 vtarget = starget->hostdata;
1164 if (vtarget) 1164 if (vtarget)
1165 vtarget->deleted = 1; 1165 vtarget->deleted = 1;
1166 } 1166 }
1167 1167
1168 pn = (u64)ri->pg0.WWPN.High << 32 | 1168 pn = (u64)ri->pg0.WWPN.High << 32 |
1169 (u64)ri->pg0.WWPN.Low; 1169 (u64)ri->pg0.WWPN.Low;
1170 dfcprintk (ioc, printk(MYIOC_s_DEBUG_FMT 1170 dfcprintk (ioc, printk(MYIOC_s_DEBUG_FMT
1171 "mptfc_rescan.%d: %llx deleted\n", 1171 "mptfc_rescan.%d: %llx deleted\n",
1172 ioc->name, 1172 ioc->name,
1173 ioc->sh->host_no, 1173 ioc->sh->host_no,
1174 (unsigned long long)pn)); 1174 (unsigned long long)pn));
1175 } 1175 }
1176 } 1176 }
1177 } 1177 }
1178 1178
1179 static int 1179 static int
1180 mptfc_probe(struct pci_dev *pdev, const struct pci_device_id *id) 1180 mptfc_probe(struct pci_dev *pdev, const struct pci_device_id *id)
1181 { 1181 {
1182 struct Scsi_Host *sh; 1182 struct Scsi_Host *sh;
1183 MPT_SCSI_HOST *hd; 1183 MPT_SCSI_HOST *hd;
1184 MPT_ADAPTER *ioc; 1184 MPT_ADAPTER *ioc;
1185 unsigned long flags; 1185 unsigned long flags;
1186 int ii; 1186 int ii;
1187 int numSGE = 0; 1187 int numSGE = 0;
1188 int scale; 1188 int scale;
1189 int ioc_cap; 1189 int ioc_cap;
1190 int error=0; 1190 int error=0;
1191 int r; 1191 int r;
1192 1192
1193 if ((r = mpt_attach(pdev,id)) != 0) 1193 if ((r = mpt_attach(pdev,id)) != 0)
1194 return r; 1194 return r;
1195 1195
1196 ioc = pci_get_drvdata(pdev); 1196 ioc = pci_get_drvdata(pdev);
1197 ioc->DoneCtx = mptfcDoneCtx; 1197 ioc->DoneCtx = mptfcDoneCtx;
1198 ioc->TaskCtx = mptfcTaskCtx; 1198 ioc->TaskCtx = mptfcTaskCtx;
1199 ioc->InternalCtx = mptfcInternalCtx; 1199 ioc->InternalCtx = mptfcInternalCtx;
1200 1200
1201 /* Added sanity check on readiness of the MPT adapter. 1201 /* Added sanity check on readiness of the MPT adapter.
1202 */ 1202 */
1203 if (ioc->last_state != MPI_IOC_STATE_OPERATIONAL) { 1203 if (ioc->last_state != MPI_IOC_STATE_OPERATIONAL) {
1204 printk(MYIOC_s_WARN_FMT 1204 printk(MYIOC_s_WARN_FMT
1205 "Skipping because it's not operational!\n", 1205 "Skipping because it's not operational!\n",
1206 ioc->name); 1206 ioc->name);
1207 error = -ENODEV; 1207 error = -ENODEV;
1208 goto out_mptfc_probe; 1208 goto out_mptfc_probe;
1209 } 1209 }
1210 1210
1211 if (!ioc->active) { 1211 if (!ioc->active) {
1212 printk(MYIOC_s_WARN_FMT "Skipping because it's disabled!\n", 1212 printk(MYIOC_s_WARN_FMT "Skipping because it's disabled!\n",
1213 ioc->name); 1213 ioc->name);
1214 error = -ENODEV; 1214 error = -ENODEV;
1215 goto out_mptfc_probe; 1215 goto out_mptfc_probe;
1216 } 1216 }
1217 1217
1218 /* Sanity check - ensure at least 1 port is INITIATOR capable 1218 /* Sanity check - ensure at least 1 port is INITIATOR capable
1219 */ 1219 */
1220 ioc_cap = 0; 1220 ioc_cap = 0;
1221 for (ii=0; ii < ioc->facts.NumberOfPorts; ii++) { 1221 for (ii=0; ii < ioc->facts.NumberOfPorts; ii++) {
1222 if (ioc->pfacts[ii].ProtocolFlags & 1222 if (ioc->pfacts[ii].ProtocolFlags &
1223 MPI_PORTFACTS_PROTOCOL_INITIATOR) 1223 MPI_PORTFACTS_PROTOCOL_INITIATOR)
1224 ioc_cap ++; 1224 ioc_cap ++;
1225 } 1225 }
1226 1226
1227 if (!ioc_cap) { 1227 if (!ioc_cap) {
1228 printk(MYIOC_s_WARN_FMT 1228 printk(MYIOC_s_WARN_FMT
1229 "Skipping ioc=%p because SCSI Initiator mode is NOT enabled!\n", 1229 "Skipping ioc=%p because SCSI Initiator mode is NOT enabled!\n",
1230 ioc->name, ioc); 1230 ioc->name, ioc);
1231 return 0; 1231 return 0;
1232 } 1232 }
1233 1233
1234 sh = scsi_host_alloc(&mptfc_driver_template, sizeof(MPT_SCSI_HOST)); 1234 sh = scsi_host_alloc(&mptfc_driver_template, sizeof(MPT_SCSI_HOST));
1235 1235
1236 if (!sh) { 1236 if (!sh) {
1237 printk(MYIOC_s_WARN_FMT 1237 printk(MYIOC_s_WARN_FMT
1238 "Unable to register controller with SCSI subsystem\n", 1238 "Unable to register controller with SCSI subsystem\n",
1239 ioc->name); 1239 ioc->name);
1240 error = -1; 1240 error = -1;
1241 goto out_mptfc_probe; 1241 goto out_mptfc_probe;
1242 } 1242 }
1243 1243
1244 spin_lock_init(&ioc->fc_rescan_work_lock); 1244 spin_lock_init(&ioc->fc_rescan_work_lock);
1245 INIT_WORK(&ioc->fc_rescan_work, mptfc_rescan_devices); 1245 INIT_WORK(&ioc->fc_rescan_work, mptfc_rescan_devices);
1246 INIT_WORK(&ioc->fc_setup_reset_work, mptfc_setup_reset); 1246 INIT_WORK(&ioc->fc_setup_reset_work, mptfc_setup_reset);
1247 INIT_WORK(&ioc->fc_lsc_work, mptfc_link_status_change); 1247 INIT_WORK(&ioc->fc_lsc_work, mptfc_link_status_change);
1248 1248
1249 spin_lock_irqsave(&ioc->FreeQlock, flags); 1249 spin_lock_irqsave(&ioc->FreeQlock, flags);
1250 1250
1251 /* Attach the SCSI Host to the IOC structure 1251 /* Attach the SCSI Host to the IOC structure
1252 */ 1252 */
1253 ioc->sh = sh; 1253 ioc->sh = sh;
1254 1254
1255 sh->io_port = 0; 1255 sh->io_port = 0;
1256 sh->n_io_port = 0; 1256 sh->n_io_port = 0;
1257 sh->irq = 0; 1257 sh->irq = 0;
1258 1258
1259 /* set 16 byte cdb's */ 1259 /* set 16 byte cdb's */
1260 sh->max_cmd_len = 16; 1260 sh->max_cmd_len = 16;
1261 1261
1262 sh->max_id = ioc->pfacts->MaxDevices; 1262 sh->max_id = ioc->pfacts->MaxDevices;
1263 sh->max_lun = max_lun; 1263 sh->max_lun = max_lun;
1264 1264
1265 /* Required entry. 1265 /* Required entry.
1266 */ 1266 */
1267 sh->unique_id = ioc->id; 1267 sh->unique_id = ioc->id;
1268 1268
1269 /* Verify that we won't exceed the maximum 1269 /* Verify that we won't exceed the maximum
1270 * number of chain buffers 1270 * number of chain buffers
1271 * We can optimize: ZZ = req_sz/sizeof(SGE) 1271 * We can optimize: ZZ = req_sz/sizeof(SGE)
1272 * For 32bit SGE's: 1272 * For 32bit SGE's:
1273 * numSGE = 1 + (ZZ-1)*(maxChain -1) + ZZ 1273 * numSGE = 1 + (ZZ-1)*(maxChain -1) + ZZ
1274 * + (req_sz - 64)/sizeof(SGE) 1274 * + (req_sz - 64)/sizeof(SGE)
1275 * A slightly different algorithm is required for 1275 * A slightly different algorithm is required for
1276 * 64bit SGEs. 1276 * 64bit SGEs.
1277 */ 1277 */
1278 scale = ioc->req_sz/ioc->SGE_size; 1278 scale = ioc->req_sz/ioc->SGE_size;
1279 if (ioc->sg_addr_size == sizeof(u64)) { 1279 if (ioc->sg_addr_size == sizeof(u64)) {
1280 numSGE = (scale - 1) * 1280 numSGE = (scale - 1) *
1281 (ioc->facts.MaxChainDepth-1) + scale + 1281 (ioc->facts.MaxChainDepth-1) + scale +
1282 (ioc->req_sz - 60) / ioc->SGE_size; 1282 (ioc->req_sz - 60) / ioc->SGE_size;
1283 } else { 1283 } else {
1284 numSGE = 1 + (scale - 1) * 1284 numSGE = 1 + (scale - 1) *
1285 (ioc->facts.MaxChainDepth-1) + scale + 1285 (ioc->facts.MaxChainDepth-1) + scale +
1286 (ioc->req_sz - 64) / ioc->SGE_size; 1286 (ioc->req_sz - 64) / ioc->SGE_size;
1287 } 1287 }
1288 1288
1289 if (numSGE < sh->sg_tablesize) { 1289 if (numSGE < sh->sg_tablesize) {
1290 /* Reset this value */ 1290 /* Reset this value */
1291 dprintk(ioc, printk(MYIOC_s_DEBUG_FMT 1291 dprintk(ioc, printk(MYIOC_s_DEBUG_FMT
1292 "Resetting sg_tablesize to %d from %d\n", 1292 "Resetting sg_tablesize to %d from %d\n",
1293 ioc->name, numSGE, sh->sg_tablesize)); 1293 ioc->name, numSGE, sh->sg_tablesize));
1294 sh->sg_tablesize = numSGE; 1294 sh->sg_tablesize = numSGE;
1295 } 1295 }
1296 1296
1297 spin_unlock_irqrestore(&ioc->FreeQlock, flags); 1297 spin_unlock_irqrestore(&ioc->FreeQlock, flags);
1298 1298
1299 hd = shost_priv(sh); 1299 hd = shost_priv(sh);
1300 hd->ioc = ioc; 1300 hd->ioc = ioc;
1301 1301
1302 /* SCSI needs scsi_cmnd lookup table! 1302 /* SCSI needs scsi_cmnd lookup table!
1303 * (with size equal to req_depth*PtrSz!) 1303 * (with size equal to req_depth*PtrSz!)
1304 */ 1304 */
1305 ioc->ScsiLookup = kcalloc(ioc->req_depth, sizeof(void *), GFP_ATOMIC); 1305 ioc->ScsiLookup = kcalloc(ioc->req_depth, sizeof(void *), GFP_ATOMIC);
1306 if (!ioc->ScsiLookup) { 1306 if (!ioc->ScsiLookup) {
1307 error = -ENOMEM; 1307 error = -ENOMEM;
1308 goto out_mptfc_probe; 1308 goto out_mptfc_probe;
1309 } 1309 }
1310 spin_lock_init(&ioc->scsi_lookup_lock); 1310 spin_lock_init(&ioc->scsi_lookup_lock);
1311 1311
1312 dprintk(ioc, printk(MYIOC_s_DEBUG_FMT "ScsiLookup @ %p\n", 1312 dprintk(ioc, printk(MYIOC_s_DEBUG_FMT "ScsiLookup @ %p\n",
1313 ioc->name, ioc->ScsiLookup)); 1313 ioc->name, ioc->ScsiLookup));
1314 1314
1315 hd->last_queue_full = 0; 1315 hd->last_queue_full = 0;
1316 1316
1317 sh->transportt = mptfc_transport_template; 1317 sh->transportt = mptfc_transport_template;
1318 error = scsi_add_host (sh, &ioc->pcidev->dev); 1318 error = scsi_add_host (sh, &ioc->pcidev->dev);
1319 if(error) { 1319 if(error) {
1320 dprintk(ioc, printk(MYIOC_s_ERR_FMT 1320 dprintk(ioc, printk(MYIOC_s_ERR_FMT
1321 "scsi_add_host failed\n", ioc->name)); 1321 "scsi_add_host failed\n", ioc->name));
1322 goto out_mptfc_probe; 1322 goto out_mptfc_probe;
1323 } 1323 }
1324 1324
1325 /* initialize workqueue */ 1325 /* initialize workqueue */
1326 1326
1327 snprintf(ioc->fc_rescan_work_q_name, sizeof(ioc->fc_rescan_work_q_name), 1327 snprintf(ioc->fc_rescan_work_q_name, sizeof(ioc->fc_rescan_work_q_name),
1328 "mptfc_wq_%d", sh->host_no); 1328 "mptfc_wq_%d", sh->host_no);
1329 ioc->fc_rescan_work_q = 1329 ioc->fc_rescan_work_q =
1330 create_singlethread_workqueue(ioc->fc_rescan_work_q_name); 1330 create_singlethread_workqueue(ioc->fc_rescan_work_q_name);
1331 if (!ioc->fc_rescan_work_q) 1331 if (!ioc->fc_rescan_work_q)
1332 goto out_mptfc_probe; 1332 goto out_mptfc_probe;
1333 1333
1334 /* 1334 /*
1335 * Pre-fetch FC port WWN and stuff... 1335 * Pre-fetch FC port WWN and stuff...
1336 * (FCPortPage0_t stuff) 1336 * (FCPortPage0_t stuff)
1337 */ 1337 */
1338 for (ii=0; ii < ioc->facts.NumberOfPorts; ii++) { 1338 for (ii=0; ii < ioc->facts.NumberOfPorts; ii++) {
1339 (void) mptfc_GetFcPortPage0(ioc, ii); 1339 (void) mptfc_GetFcPortPage0(ioc, ii);
1340 } 1340 }
1341 mptfc_SetFcPortPage1_defaults(ioc); 1341 mptfc_SetFcPortPage1_defaults(ioc);
1342 1342
1343 /* 1343 /*
1344 * scan for rports - 1344 * scan for rports -
1345 * by doing it via the workqueue, some locking is eliminated 1345 * by doing it via the workqueue, some locking is eliminated
1346 */ 1346 */
1347 1347
1348 queue_work(ioc->fc_rescan_work_q, &ioc->fc_rescan_work); 1348 queue_work(ioc->fc_rescan_work_q, &ioc->fc_rescan_work);
1349 flush_workqueue(ioc->fc_rescan_work_q); 1349 flush_workqueue(ioc->fc_rescan_work_q);
1350 1350
1351 return 0; 1351 return 0;
1352 1352
1353 out_mptfc_probe: 1353 out_mptfc_probe:
1354 1354
1355 mptscsih_remove(pdev); 1355 mptscsih_remove(pdev);
1356 return error; 1356 return error;
1357 } 1357 }
1358 1358
1359 static struct pci_driver mptfc_driver = { 1359 static struct pci_driver mptfc_driver = {
1360 .name = "mptfc", 1360 .name = "mptfc",
1361 .id_table = mptfc_pci_table, 1361 .id_table = mptfc_pci_table,
1362 .probe = mptfc_probe, 1362 .probe = mptfc_probe,
1363 .remove = mptfc_remove, 1363 .remove = mptfc_remove,
1364 .shutdown = mptscsih_shutdown, 1364 .shutdown = mptscsih_shutdown,
1365 #ifdef CONFIG_PM 1365 #ifdef CONFIG_PM
1366 .suspend = mptscsih_suspend, 1366 .suspend = mptscsih_suspend,
1367 .resume = mptscsih_resume, 1367 .resume = mptscsih_resume,
1368 #endif 1368 #endif
1369 }; 1369 };
1370 1370
1371 static int 1371 static int
1372 mptfc_event_process(MPT_ADAPTER *ioc, EventNotificationReply_t *pEvReply) 1372 mptfc_event_process(MPT_ADAPTER *ioc, EventNotificationReply_t *pEvReply)
1373 { 1373 {
1374 MPT_SCSI_HOST *hd; 1374 MPT_SCSI_HOST *hd;
1375 u8 event = le32_to_cpu(pEvReply->Event) & 0xFF; 1375 u8 event = le32_to_cpu(pEvReply->Event) & 0xFF;
1376 unsigned long flags; 1376 unsigned long flags;
1377 int rc=1; 1377 int rc=1;
1378 1378
1379 if (ioc->bus_type != FC) 1379 if (ioc->bus_type != FC)
1380 return 0; 1380 return 0;
1381 1381
1382 devtverboseprintk(ioc, printk(MYIOC_s_DEBUG_FMT "MPT event (=%02Xh) routed to SCSI host driver!\n", 1382 devtverboseprintk(ioc, printk(MYIOC_s_DEBUG_FMT "MPT event (=%02Xh) routed to SCSI host driver!\n",
1383 ioc->name, event)); 1383 ioc->name, event));
1384 1384
1385 if (ioc->sh == NULL || 1385 if (ioc->sh == NULL ||
1386 ((hd = shost_priv(ioc->sh)) == NULL)) 1386 ((hd = shost_priv(ioc->sh)) == NULL))
1387 return 1; 1387 return 1;
1388 1388
1389 switch (event) { 1389 switch (event) {
1390 case MPI_EVENT_RESCAN: 1390 case MPI_EVENT_RESCAN:
1391 spin_lock_irqsave(&ioc->fc_rescan_work_lock, flags); 1391 spin_lock_irqsave(&ioc->fc_rescan_work_lock, flags);
1392 if (ioc->fc_rescan_work_q) { 1392 if (ioc->fc_rescan_work_q) {
1393 queue_work(ioc->fc_rescan_work_q, 1393 queue_work(ioc->fc_rescan_work_q,
1394 &ioc->fc_rescan_work); 1394 &ioc->fc_rescan_work);
1395 } 1395 }
1396 spin_unlock_irqrestore(&ioc->fc_rescan_work_lock, flags); 1396 spin_unlock_irqrestore(&ioc->fc_rescan_work_lock, flags);
1397 break; 1397 break;
1398 case MPI_EVENT_LINK_STATUS_CHANGE: 1398 case MPI_EVENT_LINK_STATUS_CHANGE:
1399 spin_lock_irqsave(&ioc->fc_rescan_work_lock, flags); 1399 spin_lock_irqsave(&ioc->fc_rescan_work_lock, flags);
1400 if (ioc->fc_rescan_work_q) { 1400 if (ioc->fc_rescan_work_q) {
1401 queue_work(ioc->fc_rescan_work_q, 1401 queue_work(ioc->fc_rescan_work_q,
1402 &ioc->fc_lsc_work); 1402 &ioc->fc_lsc_work);
1403 } 1403 }
1404 spin_unlock_irqrestore(&ioc->fc_rescan_work_lock, flags); 1404 spin_unlock_irqrestore(&ioc->fc_rescan_work_lock, flags);
1405 break; 1405 break;
1406 default: 1406 default:
1407 rc = mptscsih_event_process(ioc,pEvReply); 1407 rc = mptscsih_event_process(ioc,pEvReply);
1408 break; 1408 break;
1409 } 1409 }
1410 return rc; 1410 return rc;
1411 } 1411 }
1412 1412
1413 static int 1413 static int
1414 mptfc_ioc_reset(MPT_ADAPTER *ioc, int reset_phase) 1414 mptfc_ioc_reset(MPT_ADAPTER *ioc, int reset_phase)
1415 { 1415 {
1416 int rc; 1416 int rc;
1417 unsigned long flags; 1417 unsigned long flags;
1418 1418
1419 rc = mptscsih_ioc_reset(ioc,reset_phase); 1419 rc = mptscsih_ioc_reset(ioc,reset_phase);
1420 if ((ioc->bus_type != FC) || (!rc)) 1420 if ((ioc->bus_type != FC) || (!rc))
1421 return rc; 1421 return rc;
1422 1422
1423 1423
1424 dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT 1424 dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT
1425 ": IOC %s_reset routed to FC host driver!\n",ioc->name, 1425 ": IOC %s_reset routed to FC host driver!\n",ioc->name,
1426 reset_phase==MPT_IOC_SETUP_RESET ? "setup" : ( 1426 reset_phase==MPT_IOC_SETUP_RESET ? "setup" : (
1427 reset_phase==MPT_IOC_PRE_RESET ? "pre" : "post"))); 1427 reset_phase==MPT_IOC_PRE_RESET ? "pre" : "post")));
1428 1428
1429 if (reset_phase == MPT_IOC_SETUP_RESET) { 1429 if (reset_phase == MPT_IOC_SETUP_RESET) {
1430 spin_lock_irqsave(&ioc->fc_rescan_work_lock, flags); 1430 spin_lock_irqsave(&ioc->fc_rescan_work_lock, flags);
1431 if (ioc->fc_rescan_work_q) { 1431 if (ioc->fc_rescan_work_q) {
1432 queue_work(ioc->fc_rescan_work_q, 1432 queue_work(ioc->fc_rescan_work_q,
1433 &ioc->fc_setup_reset_work); 1433 &ioc->fc_setup_reset_work);
1434 } 1434 }
1435 spin_unlock_irqrestore(&ioc->fc_rescan_work_lock, flags); 1435 spin_unlock_irqrestore(&ioc->fc_rescan_work_lock, flags);
1436 } 1436 }
1437 1437
1438 else if (reset_phase == MPT_IOC_PRE_RESET) { 1438 else if (reset_phase == MPT_IOC_PRE_RESET) {
1439 } 1439 }
1440 1440
1441 else { /* MPT_IOC_POST_RESET */ 1441 else { /* MPT_IOC_POST_RESET */
1442 mptfc_SetFcPortPage1_defaults(ioc); 1442 mptfc_SetFcPortPage1_defaults(ioc);
1443 spin_lock_irqsave(&ioc->fc_rescan_work_lock, flags); 1443 spin_lock_irqsave(&ioc->fc_rescan_work_lock, flags);
1444 if (ioc->fc_rescan_work_q) { 1444 if (ioc->fc_rescan_work_q) {
1445 queue_work(ioc->fc_rescan_work_q, 1445 queue_work(ioc->fc_rescan_work_q,
1446 &ioc->fc_rescan_work); 1446 &ioc->fc_rescan_work);
1447 } 1447 }
1448 spin_unlock_irqrestore(&ioc->fc_rescan_work_lock, flags); 1448 spin_unlock_irqrestore(&ioc->fc_rescan_work_lock, flags);
1449 } 1449 }
1450 return 1; 1450 return 1;
1451 } 1451 }
1452 1452
1453 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/ 1453 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
1454 /** 1454 /**
1455 * mptfc_init - Register MPT adapter(s) as SCSI host(s) with SCSI mid-layer. 1455 * mptfc_init - Register MPT adapter(s) as SCSI host(s) with SCSI mid-layer.
1456 * 1456 *
1457 * Returns 0 for success, non-zero for failure. 1457 * Returns 0 for success, non-zero for failure.
1458 */ 1458 */
1459 static int __init 1459 static int __init
1460 mptfc_init(void) 1460 mptfc_init(void)
1461 { 1461 {
1462 int error; 1462 int error;
1463 1463
1464 show_mptmod_ver(my_NAME, my_VERSION); 1464 show_mptmod_ver(my_NAME, my_VERSION);
1465 1465
1466 /* sanity check module parameters */ 1466 /* sanity check module parameters */
1467 if (mptfc_dev_loss_tmo <= 0) 1467 if (mptfc_dev_loss_tmo <= 0)
1468 mptfc_dev_loss_tmo = MPTFC_DEV_LOSS_TMO; 1468 mptfc_dev_loss_tmo = MPTFC_DEV_LOSS_TMO;
1469 1469
1470 mptfc_transport_template = 1470 mptfc_transport_template =
1471 fc_attach_transport(&mptfc_transport_functions); 1471 fc_attach_transport(&mptfc_transport_functions);
1472 1472
1473 if (!mptfc_transport_template) 1473 if (!mptfc_transport_template)
1474 return -ENODEV; 1474 return -ENODEV;
1475 1475
1476 mptfcDoneCtx = mpt_register(mptscsih_io_done, MPTFC_DRIVER, 1476 mptfcDoneCtx = mpt_register(mptscsih_io_done, MPTFC_DRIVER,
1477 "mptscsih_scandv_complete"); 1477 "mptscsih_scandv_complete");
1478 mptfcTaskCtx = mpt_register(mptscsih_taskmgmt_complete, MPTFC_DRIVER, 1478 mptfcTaskCtx = mpt_register(mptscsih_taskmgmt_complete, MPTFC_DRIVER,
1479 "mptscsih_scandv_complete"); 1479 "mptscsih_scandv_complete");
1480 mptfcInternalCtx = mpt_register(mptscsih_scandv_complete, MPTFC_DRIVER, 1480 mptfcInternalCtx = mpt_register(mptscsih_scandv_complete, MPTFC_DRIVER,
1481 "mptscsih_scandv_complete"); 1481 "mptscsih_scandv_complete");
1482 1482
1483 mpt_event_register(mptfcDoneCtx, mptfc_event_process); 1483 mpt_event_register(mptfcDoneCtx, mptfc_event_process);
1484 mpt_reset_register(mptfcDoneCtx, mptfc_ioc_reset); 1484 mpt_reset_register(mptfcDoneCtx, mptfc_ioc_reset);
1485 1485
1486 error = pci_register_driver(&mptfc_driver); 1486 error = pci_register_driver(&mptfc_driver);
1487 if (error) 1487 if (error)
1488 fc_release_transport(mptfc_transport_template); 1488 fc_release_transport(mptfc_transport_template);
1489 1489
1490 return error; 1490 return error;
1491 } 1491 }
1492 1492
1493 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/ 1493 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
1494 /** 1494 /**
1495 * mptfc_remove - Remove fc infrastructure for devices 1495 * mptfc_remove - Remove fc infrastructure for devices
1496 * @pdev: Pointer to pci_dev structure 1496 * @pdev: Pointer to pci_dev structure
1497 * 1497 *
1498 */ 1498 */
1499 static void mptfc_remove(struct pci_dev *pdev) 1499 static void mptfc_remove(struct pci_dev *pdev)
1500 { 1500 {
1501 MPT_ADAPTER *ioc = pci_get_drvdata(pdev); 1501 MPT_ADAPTER *ioc = pci_get_drvdata(pdev);
1502 struct mptfc_rport_info *p, *n; 1502 struct mptfc_rport_info *p, *n;
1503 struct workqueue_struct *work_q; 1503 struct workqueue_struct *work_q;
1504 unsigned long flags; 1504 unsigned long flags;
1505 int ii; 1505 int ii;
1506 1506
1507 /* destroy workqueue */ 1507 /* destroy workqueue */
1508 if ((work_q=ioc->fc_rescan_work_q)) { 1508 if ((work_q=ioc->fc_rescan_work_q)) {
1509 spin_lock_irqsave(&ioc->fc_rescan_work_lock, flags); 1509 spin_lock_irqsave(&ioc->fc_rescan_work_lock, flags);
1510 ioc->fc_rescan_work_q = NULL; 1510 ioc->fc_rescan_work_q = NULL;
1511 spin_unlock_irqrestore(&ioc->fc_rescan_work_lock, flags); 1511 spin_unlock_irqrestore(&ioc->fc_rescan_work_lock, flags);
1512 destroy_workqueue(work_q); 1512 destroy_workqueue(work_q);
1513 } 1513 }
1514 1514
1515 fc_remove_host(ioc->sh); 1515 fc_remove_host(ioc->sh);
1516 1516
1517 list_for_each_entry_safe(p, n, &ioc->fc_rports, list) { 1517 list_for_each_entry_safe(p, n, &ioc->fc_rports, list) {
1518 list_del(&p->list); 1518 list_del(&p->list);
1519 kfree(p); 1519 kfree(p);
1520 } 1520 }
1521 1521
1522 for (ii=0; ii<ioc->facts.NumberOfPorts; ii++) { 1522 for (ii=0; ii<ioc->facts.NumberOfPorts; ii++) {
1523 if (ioc->fc_data.fc_port_page1[ii].data) { 1523 if (ioc->fc_data.fc_port_page1[ii].data) {
1524 pci_free_consistent(ioc->pcidev, 1524 pci_free_consistent(ioc->pcidev,
1525 ioc->fc_data.fc_port_page1[ii].pg_sz, 1525 ioc->fc_data.fc_port_page1[ii].pg_sz,
1526 (u8 *) ioc->fc_data.fc_port_page1[ii].data, 1526 (u8 *) ioc->fc_data.fc_port_page1[ii].data,
1527 ioc->fc_data.fc_port_page1[ii].dma); 1527 ioc->fc_data.fc_port_page1[ii].dma);
1528 ioc->fc_data.fc_port_page1[ii].data = NULL; 1528 ioc->fc_data.fc_port_page1[ii].data = NULL;
1529 } 1529 }
1530 } 1530 }
1531 1531
1532 mptscsih_remove(pdev); 1532 mptscsih_remove(pdev);
1533 } 1533 }
1534 1534
1535 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/ 1535 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
1536 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/ 1536 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
1537 /** 1537 /**
1538 * mptfc_exit - Unregisters MPT adapter(s) 1538 * mptfc_exit - Unregisters MPT adapter(s)
1539 * 1539 *
1540 */ 1540 */
1541 static void __exit 1541 static void __exit
1542 mptfc_exit(void) 1542 mptfc_exit(void)
1543 { 1543 {
1544 pci_unregister_driver(&mptfc_driver); 1544 pci_unregister_driver(&mptfc_driver);
1545 fc_release_transport(mptfc_transport_template); 1545 fc_release_transport(mptfc_transport_template);
1546 1546
1547 mpt_reset_deregister(mptfcDoneCtx); 1547 mpt_reset_deregister(mptfcDoneCtx);
1548 mpt_event_deregister(mptfcDoneCtx); 1548 mpt_event_deregister(mptfcDoneCtx);
1549 1549
1550 mpt_deregister(mptfcInternalCtx); 1550 mpt_deregister(mptfcInternalCtx);
1551 mpt_deregister(mptfcTaskCtx); 1551 mpt_deregister(mptfcTaskCtx);
1552 mpt_deregister(mptfcDoneCtx); 1552 mpt_deregister(mptfcDoneCtx);
1553 } 1553 }
1554 1554
1555 module_init(mptfc_init); 1555 module_init(mptfc_init);
1556 module_exit(mptfc_exit); 1556 module_exit(mptfc_exit);
1557 1557
drivers/message/fusion/mptsas.c
1 /* 1 /*
2 * linux/drivers/message/fusion/mptsas.c 2 * linux/drivers/message/fusion/mptsas.c
3 * For use with LSI PCI chip/adapter(s) 3 * For use with LSI PCI chip/adapter(s)
4 * running LSI Fusion MPT (Message Passing Technology) firmware. 4 * running LSI Fusion MPT (Message Passing Technology) firmware.
5 * 5 *
6 * Copyright (c) 1999-2008 LSI Corporation 6 * Copyright (c) 1999-2008 LSI Corporation
7 * (mailto:DL-MPTFusionLinux@lsi.com) 7 * (mailto:DL-MPTFusionLinux@lsi.com)
8 */ 8 */
9 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/ 9 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
10 /* 10 /*
11 This program is free software; you can redistribute it and/or modify 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 12 it under the terms of the GNU General Public License as published by
13 the Free Software Foundation; version 2 of the License. 13 the Free Software Foundation; version 2 of the License.
14 14
15 This program is distributed in the hope that it will be useful, 15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of 16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details. 18 GNU General Public License for more details.
19 19
20 NO WARRANTY 20 NO WARRANTY
21 THE PROGRAM IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR 21 THE PROGRAM IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR
22 CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT 22 CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT
23 LIMITATION, ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT, 23 LIMITATION, ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT,
24 MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Each Recipient is 24 MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Each Recipient is
25 solely responsible for determining the appropriateness of using and 25 solely responsible for determining the appropriateness of using and
26 distributing the Program and assumes all risks associated with its 26 distributing the Program and assumes all risks associated with its
27 exercise of rights under this Agreement, including but not limited to 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, 28 the risks and costs of program errors, damage to or loss of data,
29 programs or equipment, and unavailability or interruption of operations. 29 programs or equipment, and unavailability or interruption of operations.
30 30
31 DISCLAIMER OF LIABILITY 31 DISCLAIMER OF LIABILITY
32 NEITHER RECIPIENT NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY 32 NEITHER RECIPIENT NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY
33 DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 33 DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
34 DAMAGES (INCLUDING WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND 34 DAMAGES (INCLUDING WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND
35 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR 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 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 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 38 HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES
39 39
40 You should have received a copy of the GNU General Public License 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 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 42 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
43 */ 43 */
44 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/ 44 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
45 45
46 #include <linux/module.h> 46 #include <linux/module.h>
47 #include <linux/kernel.h> 47 #include <linux/kernel.h>
48 #include <linux/slab.h> 48 #include <linux/slab.h>
49 #include <linux/init.h> 49 #include <linux/init.h>
50 #include <linux/errno.h> 50 #include <linux/errno.h>
51 #include <linux/jiffies.h> 51 #include <linux/jiffies.h>
52 #include <linux/workqueue.h> 52 #include <linux/workqueue.h>
53 #include <linux/delay.h> /* for mdelay */ 53 #include <linux/delay.h> /* for mdelay */
54 54
55 #include <scsi/scsi.h> 55 #include <scsi/scsi.h>
56 #include <scsi/scsi_cmnd.h> 56 #include <scsi/scsi_cmnd.h>
57 #include <scsi/scsi_device.h> 57 #include <scsi/scsi_device.h>
58 #include <scsi/scsi_host.h> 58 #include <scsi/scsi_host.h>
59 #include <scsi/scsi_transport_sas.h> 59 #include <scsi/scsi_transport_sas.h>
60 #include <scsi/scsi_transport.h> 60 #include <scsi/scsi_transport.h>
61 #include <scsi/scsi_dbg.h> 61 #include <scsi/scsi_dbg.h>
62 62
63 #include "mptbase.h" 63 #include "mptbase.h"
64 #include "mptscsih.h" 64 #include "mptscsih.h"
65 #include "mptsas.h" 65 #include "mptsas.h"
66 66
67 67
68 #define my_NAME "Fusion MPT SAS Host driver" 68 #define my_NAME "Fusion MPT SAS Host driver"
69 #define my_VERSION MPT_LINUX_VERSION_COMMON 69 #define my_VERSION MPT_LINUX_VERSION_COMMON
70 #define MYNAM "mptsas" 70 #define MYNAM "mptsas"
71 71
72 /* 72 /*
73 * Reserved channel for integrated raid 73 * Reserved channel for integrated raid
74 */ 74 */
75 #define MPTSAS_RAID_CHANNEL 1 75 #define MPTSAS_RAID_CHANNEL 1
76 76
77 #define SAS_CONFIG_PAGE_TIMEOUT 30 77 #define SAS_CONFIG_PAGE_TIMEOUT 30
78 MODULE_AUTHOR(MODULEAUTHOR); 78 MODULE_AUTHOR(MODULEAUTHOR);
79 MODULE_DESCRIPTION(my_NAME); 79 MODULE_DESCRIPTION(my_NAME);
80 MODULE_LICENSE("GPL"); 80 MODULE_LICENSE("GPL");
81 MODULE_VERSION(my_VERSION); 81 MODULE_VERSION(my_VERSION);
82 82
83 static int mpt_pt_clear; 83 static int mpt_pt_clear;
84 module_param(mpt_pt_clear, int, 0); 84 module_param(mpt_pt_clear, int, 0);
85 MODULE_PARM_DESC(mpt_pt_clear, 85 MODULE_PARM_DESC(mpt_pt_clear,
86 " Clear persistency table: enable=1 " 86 " Clear persistency table: enable=1 "
87 "(default=MPTSCSIH_PT_CLEAR=0)"); 87 "(default=MPTSCSIH_PT_CLEAR=0)");
88 88
89 /* scsi-mid layer global parmeter is max_report_luns, which is 511 */ 89 /* scsi-mid layer global parmeter is max_report_luns, which is 511 */
90 #define MPTSAS_MAX_LUN (16895) 90 #define MPTSAS_MAX_LUN (16895)
91 static int max_lun = MPTSAS_MAX_LUN; 91 static int max_lun = MPTSAS_MAX_LUN;
92 module_param(max_lun, int, 0); 92 module_param(max_lun, int, 0);
93 MODULE_PARM_DESC(max_lun, " max lun, default=16895 "); 93 MODULE_PARM_DESC(max_lun, " max lun, default=16895 ");
94 94
95 static int mpt_loadtime_max_sectors = 8192; 95 static int mpt_loadtime_max_sectors = 8192;
96 module_param(mpt_loadtime_max_sectors, int, 0); 96 module_param(mpt_loadtime_max_sectors, int, 0);
97 MODULE_PARM_DESC(mpt_loadtime_max_sectors, 97 MODULE_PARM_DESC(mpt_loadtime_max_sectors,
98 " Maximum sector define for Host Bus Adaptor.Range 64 to 8192 default=8192"); 98 " Maximum sector define for Host Bus Adaptor.Range 64 to 8192 default=8192");
99 99
100 static u8 mptsasDoneCtx = MPT_MAX_PROTOCOL_DRIVERS; 100 static u8 mptsasDoneCtx = MPT_MAX_PROTOCOL_DRIVERS;
101 static u8 mptsasTaskCtx = MPT_MAX_PROTOCOL_DRIVERS; 101 static u8 mptsasTaskCtx = MPT_MAX_PROTOCOL_DRIVERS;
102 static u8 mptsasInternalCtx = MPT_MAX_PROTOCOL_DRIVERS; /* Used only for internal commands */ 102 static u8 mptsasInternalCtx = MPT_MAX_PROTOCOL_DRIVERS; /* Used only for internal commands */
103 static u8 mptsasMgmtCtx = MPT_MAX_PROTOCOL_DRIVERS; 103 static u8 mptsasMgmtCtx = MPT_MAX_PROTOCOL_DRIVERS;
104 static u8 mptsasDeviceResetCtx = MPT_MAX_PROTOCOL_DRIVERS; 104 static u8 mptsasDeviceResetCtx = MPT_MAX_PROTOCOL_DRIVERS;
105 105
106 static void mptsas_firmware_event_work(struct work_struct *work); 106 static void mptsas_firmware_event_work(struct work_struct *work);
107 static void mptsas_send_sas_event(struct fw_event_work *fw_event); 107 static void mptsas_send_sas_event(struct fw_event_work *fw_event);
108 static void mptsas_send_raid_event(struct fw_event_work *fw_event); 108 static void mptsas_send_raid_event(struct fw_event_work *fw_event);
109 static void mptsas_send_ir2_event(struct fw_event_work *fw_event); 109 static void mptsas_send_ir2_event(struct fw_event_work *fw_event);
110 static void mptsas_parse_device_info(struct sas_identify *identify, 110 static void mptsas_parse_device_info(struct sas_identify *identify,
111 struct mptsas_devinfo *device_info); 111 struct mptsas_devinfo *device_info);
112 static inline void mptsas_set_rphy(MPT_ADAPTER *ioc, 112 static inline void mptsas_set_rphy(MPT_ADAPTER *ioc,
113 struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy); 113 struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy);
114 static struct mptsas_phyinfo *mptsas_find_phyinfo_by_sas_address 114 static struct mptsas_phyinfo *mptsas_find_phyinfo_by_sas_address
115 (MPT_ADAPTER *ioc, u64 sas_address); 115 (MPT_ADAPTER *ioc, u64 sas_address);
116 static int mptsas_sas_device_pg0(MPT_ADAPTER *ioc, 116 static int mptsas_sas_device_pg0(MPT_ADAPTER *ioc,
117 struct mptsas_devinfo *device_info, u32 form, u32 form_specific); 117 struct mptsas_devinfo *device_info, u32 form, u32 form_specific);
118 static int mptsas_sas_enclosure_pg0(MPT_ADAPTER *ioc, 118 static int mptsas_sas_enclosure_pg0(MPT_ADAPTER *ioc,
119 struct mptsas_enclosure *enclosure, u32 form, u32 form_specific); 119 struct mptsas_enclosure *enclosure, u32 form, u32 form_specific);
120 static int mptsas_add_end_device(MPT_ADAPTER *ioc, 120 static int mptsas_add_end_device(MPT_ADAPTER *ioc,
121 struct mptsas_phyinfo *phy_info); 121 struct mptsas_phyinfo *phy_info);
122 static void mptsas_del_end_device(MPT_ADAPTER *ioc, 122 static void mptsas_del_end_device(MPT_ADAPTER *ioc,
123 struct mptsas_phyinfo *phy_info); 123 struct mptsas_phyinfo *phy_info);
124 static void mptsas_send_link_status_event(struct fw_event_work *fw_event); 124 static void mptsas_send_link_status_event(struct fw_event_work *fw_event);
125 static struct mptsas_portinfo *mptsas_find_portinfo_by_sas_address 125 static struct mptsas_portinfo *mptsas_find_portinfo_by_sas_address
126 (MPT_ADAPTER *ioc, u64 sas_address); 126 (MPT_ADAPTER *ioc, u64 sas_address);
127 static void mptsas_expander_delete(MPT_ADAPTER *ioc, 127 static void mptsas_expander_delete(MPT_ADAPTER *ioc,
128 struct mptsas_portinfo *port_info, u8 force); 128 struct mptsas_portinfo *port_info, u8 force);
129 static void mptsas_send_expander_event(struct fw_event_work *fw_event); 129 static void mptsas_send_expander_event(struct fw_event_work *fw_event);
130 static void mptsas_not_responding_devices(MPT_ADAPTER *ioc); 130 static void mptsas_not_responding_devices(MPT_ADAPTER *ioc);
131 static void mptsas_scan_sas_topology(MPT_ADAPTER *ioc); 131 static void mptsas_scan_sas_topology(MPT_ADAPTER *ioc);
132 static void mptsas_broadcast_primative_work(struct fw_event_work *fw_event); 132 static void mptsas_broadcast_primative_work(struct fw_event_work *fw_event);
133 static void mptsas_handle_queue_full_event(struct fw_event_work *fw_event); 133 static void mptsas_handle_queue_full_event(struct fw_event_work *fw_event);
134 static void mptsas_volume_delete(MPT_ADAPTER *ioc, u8 id); 134 static void mptsas_volume_delete(MPT_ADAPTER *ioc, u8 id);
135 void mptsas_schedule_target_reset(void *ioc); 135 void mptsas_schedule_target_reset(void *ioc);
136 136
137 static void mptsas_print_phy_data(MPT_ADAPTER *ioc, 137 static void mptsas_print_phy_data(MPT_ADAPTER *ioc,
138 MPI_SAS_IO_UNIT0_PHY_DATA *phy_data) 138 MPI_SAS_IO_UNIT0_PHY_DATA *phy_data)
139 { 139 {
140 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT 140 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT
141 "---- IO UNIT PAGE 0 ------------\n", ioc->name)); 141 "---- IO UNIT PAGE 0 ------------\n", ioc->name));
142 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Handle=0x%X\n", 142 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Handle=0x%X\n",
143 ioc->name, le16_to_cpu(phy_data->AttachedDeviceHandle))); 143 ioc->name, le16_to_cpu(phy_data->AttachedDeviceHandle)));
144 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Controller Handle=0x%X\n", 144 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Controller Handle=0x%X\n",
145 ioc->name, le16_to_cpu(phy_data->ControllerDevHandle))); 145 ioc->name, le16_to_cpu(phy_data->ControllerDevHandle)));
146 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Port=0x%X\n", 146 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Port=0x%X\n",
147 ioc->name, phy_data->Port)); 147 ioc->name, phy_data->Port));
148 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Port Flags=0x%X\n", 148 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Port Flags=0x%X\n",
149 ioc->name, phy_data->PortFlags)); 149 ioc->name, phy_data->PortFlags));
150 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "PHY Flags=0x%X\n", 150 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "PHY Flags=0x%X\n",
151 ioc->name, phy_data->PhyFlags)); 151 ioc->name, phy_data->PhyFlags));
152 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Negotiated Link Rate=0x%X\n", 152 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Negotiated Link Rate=0x%X\n",
153 ioc->name, phy_data->NegotiatedLinkRate)); 153 ioc->name, phy_data->NegotiatedLinkRate));
154 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT 154 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT
155 "Controller PHY Device Info=0x%X\n", ioc->name, 155 "Controller PHY Device Info=0x%X\n", ioc->name,
156 le32_to_cpu(phy_data->ControllerPhyDeviceInfo))); 156 le32_to_cpu(phy_data->ControllerPhyDeviceInfo)));
157 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "DiscoveryStatus=0x%X\n\n", 157 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "DiscoveryStatus=0x%X\n\n",
158 ioc->name, le32_to_cpu(phy_data->DiscoveryStatus))); 158 ioc->name, le32_to_cpu(phy_data->DiscoveryStatus)));
159 } 159 }
160 160
161 static void mptsas_print_phy_pg0(MPT_ADAPTER *ioc, SasPhyPage0_t *pg0) 161 static void mptsas_print_phy_pg0(MPT_ADAPTER *ioc, SasPhyPage0_t *pg0)
162 { 162 {
163 __le64 sas_address; 163 __le64 sas_address;
164 164
165 memcpy(&sas_address, &pg0->SASAddress, sizeof(__le64)); 165 memcpy(&sas_address, &pg0->SASAddress, sizeof(__le64));
166 166
167 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT 167 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT
168 "---- SAS PHY PAGE 0 ------------\n", ioc->name)); 168 "---- SAS PHY PAGE 0 ------------\n", ioc->name));
169 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT 169 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT
170 "Attached Device Handle=0x%X\n", ioc->name, 170 "Attached Device Handle=0x%X\n", ioc->name,
171 le16_to_cpu(pg0->AttachedDevHandle))); 171 le16_to_cpu(pg0->AttachedDevHandle)));
172 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "SAS Address=0x%llX\n", 172 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "SAS Address=0x%llX\n",
173 ioc->name, (unsigned long long)le64_to_cpu(sas_address))); 173 ioc->name, (unsigned long long)le64_to_cpu(sas_address)));
174 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT 174 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT
175 "Attached PHY Identifier=0x%X\n", ioc->name, 175 "Attached PHY Identifier=0x%X\n", ioc->name,
176 pg0->AttachedPhyIdentifier)); 176 pg0->AttachedPhyIdentifier));
177 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Attached Device Info=0x%X\n", 177 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Attached Device Info=0x%X\n",
178 ioc->name, le32_to_cpu(pg0->AttachedDeviceInfo))); 178 ioc->name, le32_to_cpu(pg0->AttachedDeviceInfo)));
179 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Programmed Link Rate=0x%X\n", 179 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Programmed Link Rate=0x%X\n",
180 ioc->name, pg0->ProgrammedLinkRate)); 180 ioc->name, pg0->ProgrammedLinkRate));
181 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Change Count=0x%X\n", 181 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Change Count=0x%X\n",
182 ioc->name, pg0->ChangeCount)); 182 ioc->name, pg0->ChangeCount));
183 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "PHY Info=0x%X\n\n", 183 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "PHY Info=0x%X\n\n",
184 ioc->name, le32_to_cpu(pg0->PhyInfo))); 184 ioc->name, le32_to_cpu(pg0->PhyInfo)));
185 } 185 }
186 186
187 static void mptsas_print_phy_pg1(MPT_ADAPTER *ioc, SasPhyPage1_t *pg1) 187 static void mptsas_print_phy_pg1(MPT_ADAPTER *ioc, SasPhyPage1_t *pg1)
188 { 188 {
189 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT 189 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT
190 "---- SAS PHY PAGE 1 ------------\n", ioc->name)); 190 "---- SAS PHY PAGE 1 ------------\n", ioc->name));
191 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Invalid Dword Count=0x%x\n", 191 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Invalid Dword Count=0x%x\n",
192 ioc->name, pg1->InvalidDwordCount)); 192 ioc->name, pg1->InvalidDwordCount));
193 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT 193 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT
194 "Running Disparity Error Count=0x%x\n", ioc->name, 194 "Running Disparity Error Count=0x%x\n", ioc->name,
195 pg1->RunningDisparityErrorCount)); 195 pg1->RunningDisparityErrorCount));
196 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT 196 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT
197 "Loss Dword Synch Count=0x%x\n", ioc->name, 197 "Loss Dword Synch Count=0x%x\n", ioc->name,
198 pg1->LossDwordSynchCount)); 198 pg1->LossDwordSynchCount));
199 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT 199 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT
200 "PHY Reset Problem Count=0x%x\n\n", ioc->name, 200 "PHY Reset Problem Count=0x%x\n\n", ioc->name,
201 pg1->PhyResetProblemCount)); 201 pg1->PhyResetProblemCount));
202 } 202 }
203 203
204 static void mptsas_print_device_pg0(MPT_ADAPTER *ioc, SasDevicePage0_t *pg0) 204 static void mptsas_print_device_pg0(MPT_ADAPTER *ioc, SasDevicePage0_t *pg0)
205 { 205 {
206 __le64 sas_address; 206 __le64 sas_address;
207 207
208 memcpy(&sas_address, &pg0->SASAddress, sizeof(__le64)); 208 memcpy(&sas_address, &pg0->SASAddress, sizeof(__le64));
209 209
210 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT 210 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT
211 "---- SAS DEVICE PAGE 0 ---------\n", ioc->name)); 211 "---- SAS DEVICE PAGE 0 ---------\n", ioc->name));
212 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Handle=0x%X\n", 212 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Handle=0x%X\n",
213 ioc->name, le16_to_cpu(pg0->DevHandle))); 213 ioc->name, le16_to_cpu(pg0->DevHandle)));
214 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Parent Handle=0x%X\n", 214 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Parent Handle=0x%X\n",
215 ioc->name, le16_to_cpu(pg0->ParentDevHandle))); 215 ioc->name, le16_to_cpu(pg0->ParentDevHandle)));
216 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Enclosure Handle=0x%X\n", 216 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Enclosure Handle=0x%X\n",
217 ioc->name, le16_to_cpu(pg0->EnclosureHandle))); 217 ioc->name, le16_to_cpu(pg0->EnclosureHandle)));
218 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Slot=0x%X\n", 218 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Slot=0x%X\n",
219 ioc->name, le16_to_cpu(pg0->Slot))); 219 ioc->name, le16_to_cpu(pg0->Slot)));
220 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "SAS Address=0x%llX\n", 220 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "SAS Address=0x%llX\n",
221 ioc->name, (unsigned long long)le64_to_cpu(sas_address))); 221 ioc->name, (unsigned long long)le64_to_cpu(sas_address)));
222 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Target ID=0x%X\n", 222 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Target ID=0x%X\n",
223 ioc->name, pg0->TargetID)); 223 ioc->name, pg0->TargetID));
224 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Bus=0x%X\n", 224 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Bus=0x%X\n",
225 ioc->name, pg0->Bus)); 225 ioc->name, pg0->Bus));
226 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Parent Phy Num=0x%X\n", 226 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Parent Phy Num=0x%X\n",
227 ioc->name, pg0->PhyNum)); 227 ioc->name, pg0->PhyNum));
228 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Access Status=0x%X\n", 228 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Access Status=0x%X\n",
229 ioc->name, le16_to_cpu(pg0->AccessStatus))); 229 ioc->name, le16_to_cpu(pg0->AccessStatus)));
230 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Device Info=0x%X\n", 230 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Device Info=0x%X\n",
231 ioc->name, le32_to_cpu(pg0->DeviceInfo))); 231 ioc->name, le32_to_cpu(pg0->DeviceInfo)));
232 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Flags=0x%X\n", 232 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Flags=0x%X\n",
233 ioc->name, le16_to_cpu(pg0->Flags))); 233 ioc->name, le16_to_cpu(pg0->Flags)));
234 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Physical Port=0x%X\n\n", 234 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Physical Port=0x%X\n\n",
235 ioc->name, pg0->PhysicalPort)); 235 ioc->name, pg0->PhysicalPort));
236 } 236 }
237 237
238 static void mptsas_print_expander_pg1(MPT_ADAPTER *ioc, SasExpanderPage1_t *pg1) 238 static void mptsas_print_expander_pg1(MPT_ADAPTER *ioc, SasExpanderPage1_t *pg1)
239 { 239 {
240 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT 240 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT
241 "---- SAS EXPANDER PAGE 1 ------------\n", ioc->name)); 241 "---- SAS EXPANDER PAGE 1 ------------\n", ioc->name));
242 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Physical Port=0x%X\n", 242 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Physical Port=0x%X\n",
243 ioc->name, pg1->PhysicalPort)); 243 ioc->name, pg1->PhysicalPort));
244 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "PHY Identifier=0x%X\n", 244 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "PHY Identifier=0x%X\n",
245 ioc->name, pg1->PhyIdentifier)); 245 ioc->name, pg1->PhyIdentifier));
246 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Negotiated Link Rate=0x%X\n", 246 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Negotiated Link Rate=0x%X\n",
247 ioc->name, pg1->NegotiatedLinkRate)); 247 ioc->name, pg1->NegotiatedLinkRate));
248 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Programmed Link Rate=0x%X\n", 248 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Programmed Link Rate=0x%X\n",
249 ioc->name, pg1->ProgrammedLinkRate)); 249 ioc->name, pg1->ProgrammedLinkRate));
250 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Hardware Link Rate=0x%X\n", 250 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Hardware Link Rate=0x%X\n",
251 ioc->name, pg1->HwLinkRate)); 251 ioc->name, pg1->HwLinkRate));
252 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Owner Device Handle=0x%X\n", 252 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Owner Device Handle=0x%X\n",
253 ioc->name, le16_to_cpu(pg1->OwnerDevHandle))); 253 ioc->name, le16_to_cpu(pg1->OwnerDevHandle)));
254 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT 254 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT
255 "Attached Device Handle=0x%X\n\n", ioc->name, 255 "Attached Device Handle=0x%X\n\n", ioc->name,
256 le16_to_cpu(pg1->AttachedDevHandle))); 256 le16_to_cpu(pg1->AttachedDevHandle)));
257 } 257 }
258 258
259 /* inhibit sas firmware event handling */ 259 /* inhibit sas firmware event handling */
260 static void 260 static void
261 mptsas_fw_event_off(MPT_ADAPTER *ioc) 261 mptsas_fw_event_off(MPT_ADAPTER *ioc)
262 { 262 {
263 unsigned long flags; 263 unsigned long flags;
264 264
265 spin_lock_irqsave(&ioc->fw_event_lock, flags); 265 spin_lock_irqsave(&ioc->fw_event_lock, flags);
266 ioc->fw_events_off = 1; 266 ioc->fw_events_off = 1;
267 ioc->sas_discovery_quiesce_io = 0; 267 ioc->sas_discovery_quiesce_io = 0;
268 spin_unlock_irqrestore(&ioc->fw_event_lock, flags); 268 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
269 269
270 } 270 }
271 271
272 /* enable sas firmware event handling */ 272 /* enable sas firmware event handling */
273 static void 273 static void
274 mptsas_fw_event_on(MPT_ADAPTER *ioc) 274 mptsas_fw_event_on(MPT_ADAPTER *ioc)
275 { 275 {
276 unsigned long flags; 276 unsigned long flags;
277 277
278 spin_lock_irqsave(&ioc->fw_event_lock, flags); 278 spin_lock_irqsave(&ioc->fw_event_lock, flags);
279 ioc->fw_events_off = 0; 279 ioc->fw_events_off = 0;
280 spin_unlock_irqrestore(&ioc->fw_event_lock, flags); 280 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
281 } 281 }
282 282
283 /* queue a sas firmware event */ 283 /* queue a sas firmware event */
284 static void 284 static void
285 mptsas_add_fw_event(MPT_ADAPTER *ioc, struct fw_event_work *fw_event, 285 mptsas_add_fw_event(MPT_ADAPTER *ioc, struct fw_event_work *fw_event,
286 unsigned long delay) 286 unsigned long delay)
287 { 287 {
288 unsigned long flags; 288 unsigned long flags;
289 289
290 spin_lock_irqsave(&ioc->fw_event_lock, flags); 290 spin_lock_irqsave(&ioc->fw_event_lock, flags);
291 list_add_tail(&fw_event->list, &ioc->fw_event_list); 291 list_add_tail(&fw_event->list, &ioc->fw_event_list);
292 INIT_DELAYED_WORK(&fw_event->work, mptsas_firmware_event_work); 292 INIT_DELAYED_WORK(&fw_event->work, mptsas_firmware_event_work);
293 devtprintk(ioc, printk(MYIOC_s_DEBUG_FMT "%s: add (fw_event=0x%p)" 293 devtprintk(ioc, printk(MYIOC_s_DEBUG_FMT "%s: add (fw_event=0x%p)"
294 "on cpuid %d\n", ioc->name, __func__, 294 "on cpuid %d\n", ioc->name, __func__,
295 fw_event, smp_processor_id())); 295 fw_event, smp_processor_id()));
296 queue_delayed_work_on(smp_processor_id(), ioc->fw_event_q, 296 queue_delayed_work_on(smp_processor_id(), ioc->fw_event_q,
297 &fw_event->work, delay); 297 &fw_event->work, delay);
298 spin_unlock_irqrestore(&ioc->fw_event_lock, flags); 298 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
299 } 299 }
300 300
301 /* requeue a sas firmware event */ 301 /* requeue a sas firmware event */
302 static void 302 static void
303 mptsas_requeue_fw_event(MPT_ADAPTER *ioc, struct fw_event_work *fw_event, 303 mptsas_requeue_fw_event(MPT_ADAPTER *ioc, struct fw_event_work *fw_event,
304 unsigned long delay) 304 unsigned long delay)
305 { 305 {
306 unsigned long flags; 306 unsigned long flags;
307 spin_lock_irqsave(&ioc->fw_event_lock, flags); 307 spin_lock_irqsave(&ioc->fw_event_lock, flags);
308 devtprintk(ioc, printk(MYIOC_s_DEBUG_FMT "%s: reschedule task " 308 devtprintk(ioc, printk(MYIOC_s_DEBUG_FMT "%s: reschedule task "
309 "(fw_event=0x%p)on cpuid %d\n", ioc->name, __func__, 309 "(fw_event=0x%p)on cpuid %d\n", ioc->name, __func__,
310 fw_event, smp_processor_id())); 310 fw_event, smp_processor_id()));
311 fw_event->retries++; 311 fw_event->retries++;
312 queue_delayed_work_on(smp_processor_id(), ioc->fw_event_q, 312 queue_delayed_work_on(smp_processor_id(), ioc->fw_event_q,
313 &fw_event->work, msecs_to_jiffies(delay)); 313 &fw_event->work, msecs_to_jiffies(delay));
314 spin_unlock_irqrestore(&ioc->fw_event_lock, flags); 314 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
315 } 315 }
316 316
317 /* free memory associated to a sas firmware event */ 317 /* free memory associated to a sas firmware event */
318 static void 318 static void
319 mptsas_free_fw_event(MPT_ADAPTER *ioc, struct fw_event_work *fw_event) 319 mptsas_free_fw_event(MPT_ADAPTER *ioc, struct fw_event_work *fw_event)
320 { 320 {
321 unsigned long flags; 321 unsigned long flags;
322 322
323 spin_lock_irqsave(&ioc->fw_event_lock, flags); 323 spin_lock_irqsave(&ioc->fw_event_lock, flags);
324 devtprintk(ioc, printk(MYIOC_s_DEBUG_FMT "%s: kfree (fw_event=0x%p)\n", 324 devtprintk(ioc, printk(MYIOC_s_DEBUG_FMT "%s: kfree (fw_event=0x%p)\n",
325 ioc->name, __func__, fw_event)); 325 ioc->name, __func__, fw_event));
326 list_del(&fw_event->list); 326 list_del(&fw_event->list);
327 kfree(fw_event); 327 kfree(fw_event);
328 spin_unlock_irqrestore(&ioc->fw_event_lock, flags); 328 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
329 } 329 }
330 330
331 /* walk the firmware event queue, and either stop or wait for 331 /* walk the firmware event queue, and either stop or wait for
332 * outstanding events to complete */ 332 * outstanding events to complete */
333 static void 333 static void
334 mptsas_cleanup_fw_event_q(MPT_ADAPTER *ioc) 334 mptsas_cleanup_fw_event_q(MPT_ADAPTER *ioc)
335 { 335 {
336 struct fw_event_work *fw_event, *next; 336 struct fw_event_work *fw_event, *next;
337 struct mptsas_target_reset_event *target_reset_list, *n; 337 struct mptsas_target_reset_event *target_reset_list, *n;
338 MPT_SCSI_HOST *hd = shost_priv(ioc->sh); 338 MPT_SCSI_HOST *hd = shost_priv(ioc->sh);
339 339
340 /* flush the target_reset_list */ 340 /* flush the target_reset_list */
341 if (!list_empty(&hd->target_reset_list)) { 341 if (!list_empty(&hd->target_reset_list)) {
342 list_for_each_entry_safe(target_reset_list, n, 342 list_for_each_entry_safe(target_reset_list, n,
343 &hd->target_reset_list, list) { 343 &hd->target_reset_list, list) {
344 dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT 344 dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT
345 "%s: removing target reset for id=%d\n", 345 "%s: removing target reset for id=%d\n",
346 ioc->name, __func__, 346 ioc->name, __func__,
347 target_reset_list->sas_event_data.TargetID)); 347 target_reset_list->sas_event_data.TargetID));
348 list_del(&target_reset_list->list); 348 list_del(&target_reset_list->list);
349 kfree(target_reset_list); 349 kfree(target_reset_list);
350 } 350 }
351 } 351 }
352 352
353 if (list_empty(&ioc->fw_event_list) || 353 if (list_empty(&ioc->fw_event_list) ||
354 !ioc->fw_event_q || in_interrupt()) 354 !ioc->fw_event_q || in_interrupt())
355 return; 355 return;
356 356
357 list_for_each_entry_safe(fw_event, next, &ioc->fw_event_list, list) { 357 list_for_each_entry_safe(fw_event, next, &ioc->fw_event_list, list) {
358 if (cancel_delayed_work(&fw_event->work)) 358 if (cancel_delayed_work(&fw_event->work))
359 mptsas_free_fw_event(ioc, fw_event); 359 mptsas_free_fw_event(ioc, fw_event);
360 } 360 }
361 } 361 }
362 362
363 363
364 static inline MPT_ADAPTER *phy_to_ioc(struct sas_phy *phy) 364 static inline MPT_ADAPTER *phy_to_ioc(struct sas_phy *phy)
365 { 365 {
366 struct Scsi_Host *shost = dev_to_shost(phy->dev.parent); 366 struct Scsi_Host *shost = dev_to_shost(phy->dev.parent);
367 return ((MPT_SCSI_HOST *)shost->hostdata)->ioc; 367 return ((MPT_SCSI_HOST *)shost->hostdata)->ioc;
368 } 368 }
369 369
370 static inline MPT_ADAPTER *rphy_to_ioc(struct sas_rphy *rphy) 370 static inline MPT_ADAPTER *rphy_to_ioc(struct sas_rphy *rphy)
371 { 371 {
372 struct Scsi_Host *shost = dev_to_shost(rphy->dev.parent->parent); 372 struct Scsi_Host *shost = dev_to_shost(rphy->dev.parent->parent);
373 return ((MPT_SCSI_HOST *)shost->hostdata)->ioc; 373 return ((MPT_SCSI_HOST *)shost->hostdata)->ioc;
374 } 374 }
375 375
376 /* 376 /*
377 * mptsas_find_portinfo_by_handle 377 * mptsas_find_portinfo_by_handle
378 * 378 *
379 * This function should be called with the sas_topology_mutex already held 379 * This function should be called with the sas_topology_mutex already held
380 */ 380 */
381 static struct mptsas_portinfo * 381 static struct mptsas_portinfo *
382 mptsas_find_portinfo_by_handle(MPT_ADAPTER *ioc, u16 handle) 382 mptsas_find_portinfo_by_handle(MPT_ADAPTER *ioc, u16 handle)
383 { 383 {
384 struct mptsas_portinfo *port_info, *rc=NULL; 384 struct mptsas_portinfo *port_info, *rc=NULL;
385 int i; 385 int i;
386 386
387 list_for_each_entry(port_info, &ioc->sas_topology, list) 387 list_for_each_entry(port_info, &ioc->sas_topology, list)
388 for (i = 0; i < port_info->num_phys; i++) 388 for (i = 0; i < port_info->num_phys; i++)
389 if (port_info->phy_info[i].identify.handle == handle) { 389 if (port_info->phy_info[i].identify.handle == handle) {
390 rc = port_info; 390 rc = port_info;
391 goto out; 391 goto out;
392 } 392 }
393 out: 393 out:
394 return rc; 394 return rc;
395 } 395 }
396 396
397 /** 397 /**
398 * mptsas_find_portinfo_by_sas_address - 398 * mptsas_find_portinfo_by_sas_address -
399 * @ioc: Pointer to MPT_ADAPTER structure 399 * @ioc: Pointer to MPT_ADAPTER structure
400 * @handle: 400 * @handle:
401 * 401 *
402 * This function should be called with the sas_topology_mutex already held 402 * This function should be called with the sas_topology_mutex already held
403 * 403 *
404 **/ 404 **/
405 static struct mptsas_portinfo * 405 static struct mptsas_portinfo *
406 mptsas_find_portinfo_by_sas_address(MPT_ADAPTER *ioc, u64 sas_address) 406 mptsas_find_portinfo_by_sas_address(MPT_ADAPTER *ioc, u64 sas_address)
407 { 407 {
408 struct mptsas_portinfo *port_info, *rc = NULL; 408 struct mptsas_portinfo *port_info, *rc = NULL;
409 int i; 409 int i;
410 410
411 if (sas_address >= ioc->hba_port_sas_addr && 411 if (sas_address >= ioc->hba_port_sas_addr &&
412 sas_address < (ioc->hba_port_sas_addr + 412 sas_address < (ioc->hba_port_sas_addr +
413 ioc->hba_port_num_phy)) 413 ioc->hba_port_num_phy))
414 return ioc->hba_port_info; 414 return ioc->hba_port_info;
415 415
416 mutex_lock(&ioc->sas_topology_mutex); 416 mutex_lock(&ioc->sas_topology_mutex);
417 list_for_each_entry(port_info, &ioc->sas_topology, list) 417 list_for_each_entry(port_info, &ioc->sas_topology, list)
418 for (i = 0; i < port_info->num_phys; i++) 418 for (i = 0; i < port_info->num_phys; i++)
419 if (port_info->phy_info[i].identify.sas_address == 419 if (port_info->phy_info[i].identify.sas_address ==
420 sas_address) { 420 sas_address) {
421 rc = port_info; 421 rc = port_info;
422 goto out; 422 goto out;
423 } 423 }
424 out: 424 out:
425 mutex_unlock(&ioc->sas_topology_mutex); 425 mutex_unlock(&ioc->sas_topology_mutex);
426 return rc; 426 return rc;
427 } 427 }
428 428
429 /* 429 /*
430 * Returns true if there is a scsi end device 430 * Returns true if there is a scsi end device
431 */ 431 */
432 static inline int 432 static inline int
433 mptsas_is_end_device(struct mptsas_devinfo * attached) 433 mptsas_is_end_device(struct mptsas_devinfo * attached)
434 { 434 {
435 if ((attached->sas_address) && 435 if ((attached->sas_address) &&
436 (attached->device_info & 436 (attached->device_info &
437 MPI_SAS_DEVICE_INFO_END_DEVICE) && 437 MPI_SAS_DEVICE_INFO_END_DEVICE) &&
438 ((attached->device_info & 438 ((attached->device_info &
439 MPI_SAS_DEVICE_INFO_SSP_TARGET) | 439 MPI_SAS_DEVICE_INFO_SSP_TARGET) |
440 (attached->device_info & 440 (attached->device_info &
441 MPI_SAS_DEVICE_INFO_STP_TARGET) | 441 MPI_SAS_DEVICE_INFO_STP_TARGET) |
442 (attached->device_info & 442 (attached->device_info &
443 MPI_SAS_DEVICE_INFO_SATA_DEVICE))) 443 MPI_SAS_DEVICE_INFO_SATA_DEVICE)))
444 return 1; 444 return 1;
445 else 445 else
446 return 0; 446 return 0;
447 } 447 }
448 448
449 /* no mutex */ 449 /* no mutex */
450 static void 450 static void
451 mptsas_port_delete(MPT_ADAPTER *ioc, struct mptsas_portinfo_details * port_details) 451 mptsas_port_delete(MPT_ADAPTER *ioc, struct mptsas_portinfo_details * port_details)
452 { 452 {
453 struct mptsas_portinfo *port_info; 453 struct mptsas_portinfo *port_info;
454 struct mptsas_phyinfo *phy_info; 454 struct mptsas_phyinfo *phy_info;
455 u8 i; 455 u8 i;
456 456
457 if (!port_details) 457 if (!port_details)
458 return; 458 return;
459 459
460 port_info = port_details->port_info; 460 port_info = port_details->port_info;
461 phy_info = port_info->phy_info; 461 phy_info = port_info->phy_info;
462 462
463 dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "%s: [%p]: num_phys=%02d " 463 dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "%s: [%p]: num_phys=%02d "
464 "bitmask=0x%016llX\n", ioc->name, __func__, port_details, 464 "bitmask=0x%016llX\n", ioc->name, __func__, port_details,
465 port_details->num_phys, (unsigned long long) 465 port_details->num_phys, (unsigned long long)
466 port_details->phy_bitmask)); 466 port_details->phy_bitmask));
467 467
468 for (i = 0; i < port_info->num_phys; i++, phy_info++) { 468 for (i = 0; i < port_info->num_phys; i++, phy_info++) {
469 if(phy_info->port_details != port_details) 469 if(phy_info->port_details != port_details)
470 continue; 470 continue;
471 memset(&phy_info->attached, 0, sizeof(struct mptsas_devinfo)); 471 memset(&phy_info->attached, 0, sizeof(struct mptsas_devinfo));
472 mptsas_set_rphy(ioc, phy_info, NULL); 472 mptsas_set_rphy(ioc, phy_info, NULL);
473 phy_info->port_details = NULL; 473 phy_info->port_details = NULL;
474 } 474 }
475 kfree(port_details); 475 kfree(port_details);
476 } 476 }
477 477
478 static inline struct sas_rphy * 478 static inline struct sas_rphy *
479 mptsas_get_rphy(struct mptsas_phyinfo *phy_info) 479 mptsas_get_rphy(struct mptsas_phyinfo *phy_info)
480 { 480 {
481 if (phy_info->port_details) 481 if (phy_info->port_details)
482 return phy_info->port_details->rphy; 482 return phy_info->port_details->rphy;
483 else 483 else
484 return NULL; 484 return NULL;
485 } 485 }
486 486
487 static inline void 487 static inline void
488 mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy) 488 mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
489 { 489 {
490 if (phy_info->port_details) { 490 if (phy_info->port_details) {
491 phy_info->port_details->rphy = rphy; 491 phy_info->port_details->rphy = rphy;
492 dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n", 492 dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
493 ioc->name, rphy)); 493 ioc->name, rphy));
494 } 494 }
495 495
496 if (rphy) { 496 if (rphy) {
497 dsaswideprintk(ioc, dev_printk(KERN_DEBUG, 497 dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
498 &rphy->dev, MYIOC_s_FMT "add:", ioc->name)); 498 &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
499 dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n", 499 dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
500 ioc->name, rphy, rphy->dev.release)); 500 ioc->name, rphy, rphy->dev.release));
501 } 501 }
502 } 502 }
503 503
504 static inline struct sas_port * 504 static inline struct sas_port *
505 mptsas_get_port(struct mptsas_phyinfo *phy_info) 505 mptsas_get_port(struct mptsas_phyinfo *phy_info)
506 { 506 {
507 if (phy_info->port_details) 507 if (phy_info->port_details)
508 return phy_info->port_details->port; 508 return phy_info->port_details->port;
509 else 509 else
510 return NULL; 510 return NULL;
511 } 511 }
512 512
513 static inline void 513 static inline void
514 mptsas_set_port(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_port *port) 514 mptsas_set_port(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_port *port)
515 { 515 {
516 if (phy_info->port_details) 516 if (phy_info->port_details)
517 phy_info->port_details->port = port; 517 phy_info->port_details->port = port;
518 518
519 if (port) { 519 if (port) {
520 dsaswideprintk(ioc, dev_printk(KERN_DEBUG, 520 dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
521 &port->dev, MYIOC_s_FMT "add:", ioc->name)); 521 &port->dev, MYIOC_s_FMT "add:", ioc->name));
522 dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "port=%p release=%p\n", 522 dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "port=%p release=%p\n",
523 ioc->name, port, port->dev.release)); 523 ioc->name, port, port->dev.release));
524 } 524 }
525 } 525 }
526 526
527 static inline struct scsi_target * 527 static inline struct scsi_target *
528 mptsas_get_starget(struct mptsas_phyinfo *phy_info) 528 mptsas_get_starget(struct mptsas_phyinfo *phy_info)
529 { 529 {
530 if (phy_info->port_details) 530 if (phy_info->port_details)
531 return phy_info->port_details->starget; 531 return phy_info->port_details->starget;
532 else 532 else
533 return NULL; 533 return NULL;
534 } 534 }
535 535
536 static inline void 536 static inline void
537 mptsas_set_starget(struct mptsas_phyinfo *phy_info, struct scsi_target * 537 mptsas_set_starget(struct mptsas_phyinfo *phy_info, struct scsi_target *
538 starget) 538 starget)
539 { 539 {
540 if (phy_info->port_details) 540 if (phy_info->port_details)
541 phy_info->port_details->starget = starget; 541 phy_info->port_details->starget = starget;
542 } 542 }
543 543
544 /** 544 /**
545 * mptsas_add_device_component - 545 * mptsas_add_device_component -
546 * @ioc: Pointer to MPT_ADAPTER structure 546 * @ioc: Pointer to MPT_ADAPTER structure
547 * @channel: fw mapped id's 547 * @channel: fw mapped id's
548 * @id: 548 * @id:
549 * @sas_address: 549 * @sas_address:
550 * @device_info: 550 * @device_info:
551 * 551 *
552 **/ 552 **/
553 static void 553 static void
554 mptsas_add_device_component(MPT_ADAPTER *ioc, u8 channel, u8 id, 554 mptsas_add_device_component(MPT_ADAPTER *ioc, u8 channel, u8 id,
555 u64 sas_address, u32 device_info, u16 slot, u64 enclosure_logical_id) 555 u64 sas_address, u32 device_info, u16 slot, u64 enclosure_logical_id)
556 { 556 {
557 struct mptsas_device_info *sas_info, *next; 557 struct mptsas_device_info *sas_info, *next;
558 struct scsi_device *sdev; 558 struct scsi_device *sdev;
559 struct scsi_target *starget; 559 struct scsi_target *starget;
560 struct sas_rphy *rphy; 560 struct sas_rphy *rphy;
561 561
562 /* 562 /*
563 * Delete all matching devices out of the list 563 * Delete all matching devices out of the list
564 */ 564 */
565 mutex_lock(&ioc->sas_device_info_mutex); 565 mutex_lock(&ioc->sas_device_info_mutex);
566 list_for_each_entry_safe(sas_info, next, &ioc->sas_device_info_list, 566 list_for_each_entry_safe(sas_info, next, &ioc->sas_device_info_list,
567 list) { 567 list) {
568 if (!sas_info->is_logical_volume && 568 if (!sas_info->is_logical_volume &&
569 (sas_info->sas_address == sas_address || 569 (sas_info->sas_address == sas_address ||
570 (sas_info->fw.channel == channel && 570 (sas_info->fw.channel == channel &&
571 sas_info->fw.id == id))) { 571 sas_info->fw.id == id))) {
572 list_del(&sas_info->list); 572 list_del(&sas_info->list);
573 kfree(sas_info); 573 kfree(sas_info);
574 } 574 }
575 } 575 }
576 576
577 sas_info = kzalloc(sizeof(struct mptsas_device_info), GFP_KERNEL); 577 sas_info = kzalloc(sizeof(struct mptsas_device_info), GFP_KERNEL);
578 if (!sas_info) 578 if (!sas_info)
579 goto out; 579 goto out;
580 580
581 /* 581 /*
582 * Set Firmware mapping 582 * Set Firmware mapping
583 */ 583 */
584 sas_info->fw.id = id; 584 sas_info->fw.id = id;
585 sas_info->fw.channel = channel; 585 sas_info->fw.channel = channel;
586 586
587 sas_info->sas_address = sas_address; 587 sas_info->sas_address = sas_address;
588 sas_info->device_info = device_info; 588 sas_info->device_info = device_info;
589 sas_info->slot = slot; 589 sas_info->slot = slot;
590 sas_info->enclosure_logical_id = enclosure_logical_id; 590 sas_info->enclosure_logical_id = enclosure_logical_id;
591 INIT_LIST_HEAD(&sas_info->list); 591 INIT_LIST_HEAD(&sas_info->list);
592 list_add_tail(&sas_info->list, &ioc->sas_device_info_list); 592 list_add_tail(&sas_info->list, &ioc->sas_device_info_list);
593 593
594 /* 594 /*
595 * Set OS mapping 595 * Set OS mapping
596 */ 596 */
597 shost_for_each_device(sdev, ioc->sh) { 597 shost_for_each_device(sdev, ioc->sh) {
598 starget = scsi_target(sdev); 598 starget = scsi_target(sdev);
599 rphy = dev_to_rphy(starget->dev.parent); 599 rphy = dev_to_rphy(starget->dev.parent);
600 if (rphy->identify.sas_address == sas_address) { 600 if (rphy->identify.sas_address == sas_address) {
601 sas_info->os.id = starget->id; 601 sas_info->os.id = starget->id;
602 sas_info->os.channel = starget->channel; 602 sas_info->os.channel = starget->channel;
603 } 603 }
604 } 604 }
605 605
606 out: 606 out:
607 mutex_unlock(&ioc->sas_device_info_mutex); 607 mutex_unlock(&ioc->sas_device_info_mutex);
608 return; 608 return;
609 } 609 }
610 610
611 /** 611 /**
612 * mptsas_add_device_component_by_fw - 612 * mptsas_add_device_component_by_fw -
613 * @ioc: Pointer to MPT_ADAPTER structure 613 * @ioc: Pointer to MPT_ADAPTER structure
614 * @channel: fw mapped id's 614 * @channel: fw mapped id's
615 * @id: 615 * @id:
616 * 616 *
617 **/ 617 **/
618 static void 618 static void
619 mptsas_add_device_component_by_fw(MPT_ADAPTER *ioc, u8 channel, u8 id) 619 mptsas_add_device_component_by_fw(MPT_ADAPTER *ioc, u8 channel, u8 id)
620 { 620 {
621 struct mptsas_devinfo sas_device; 621 struct mptsas_devinfo sas_device;
622 struct mptsas_enclosure enclosure_info; 622 struct mptsas_enclosure enclosure_info;
623 int rc; 623 int rc;
624 624
625 rc = mptsas_sas_device_pg0(ioc, &sas_device, 625 rc = mptsas_sas_device_pg0(ioc, &sas_device,
626 (MPI_SAS_DEVICE_PGAD_FORM_BUS_TARGET_ID << 626 (MPI_SAS_DEVICE_PGAD_FORM_BUS_TARGET_ID <<
627 MPI_SAS_DEVICE_PGAD_FORM_SHIFT), 627 MPI_SAS_DEVICE_PGAD_FORM_SHIFT),
628 (channel << 8) + id); 628 (channel << 8) + id);
629 if (rc) 629 if (rc)
630 return; 630 return;
631 631
632 memset(&enclosure_info, 0, sizeof(struct mptsas_enclosure)); 632 memset(&enclosure_info, 0, sizeof(struct mptsas_enclosure));
633 mptsas_sas_enclosure_pg0(ioc, &enclosure_info, 633 mptsas_sas_enclosure_pg0(ioc, &enclosure_info,
634 (MPI_SAS_ENCLOS_PGAD_FORM_HANDLE << 634 (MPI_SAS_ENCLOS_PGAD_FORM_HANDLE <<
635 MPI_SAS_ENCLOS_PGAD_FORM_SHIFT), 635 MPI_SAS_ENCLOS_PGAD_FORM_SHIFT),
636 sas_device.handle_enclosure); 636 sas_device.handle_enclosure);
637 637
638 mptsas_add_device_component(ioc, sas_device.channel, 638 mptsas_add_device_component(ioc, sas_device.channel,
639 sas_device.id, sas_device.sas_address, sas_device.device_info, 639 sas_device.id, sas_device.sas_address, sas_device.device_info,
640 sas_device.slot, enclosure_info.enclosure_logical_id); 640 sas_device.slot, enclosure_info.enclosure_logical_id);
641 } 641 }
642 642
643 /** 643 /**
644 * mptsas_add_device_component_starget_ir - Handle Integrated RAID, adding each individual device to list 644 * mptsas_add_device_component_starget_ir - Handle Integrated RAID, adding each individual device to list
645 * @ioc: Pointer to MPT_ADAPTER structure 645 * @ioc: Pointer to MPT_ADAPTER structure
646 * @channel: fw mapped id's 646 * @channel: fw mapped id's
647 * @id: 647 * @id:
648 * 648 *
649 **/ 649 **/
650 static void 650 static void
651 mptsas_add_device_component_starget_ir(MPT_ADAPTER *ioc, 651 mptsas_add_device_component_starget_ir(MPT_ADAPTER *ioc,
652 struct scsi_target *starget) 652 struct scsi_target *starget)
653 { 653 {
654 CONFIGPARMS cfg; 654 CONFIGPARMS cfg;
655 ConfigPageHeader_t hdr; 655 ConfigPageHeader_t hdr;
656 dma_addr_t dma_handle; 656 dma_addr_t dma_handle;
657 pRaidVolumePage0_t buffer = NULL; 657 pRaidVolumePage0_t buffer = NULL;
658 int i; 658 int i;
659 RaidPhysDiskPage0_t phys_disk; 659 RaidPhysDiskPage0_t phys_disk;
660 struct mptsas_device_info *sas_info, *next; 660 struct mptsas_device_info *sas_info, *next;
661 661
662 memset(&cfg, 0 , sizeof(CONFIGPARMS)); 662 memset(&cfg, 0 , sizeof(CONFIGPARMS));
663 memset(&hdr, 0 , sizeof(ConfigPageHeader_t)); 663 memset(&hdr, 0 , sizeof(ConfigPageHeader_t));
664 hdr.PageType = MPI_CONFIG_PAGETYPE_RAID_VOLUME; 664 hdr.PageType = MPI_CONFIG_PAGETYPE_RAID_VOLUME;
665 /* assumption that all volumes on channel = 0 */ 665 /* assumption that all volumes on channel = 0 */
666 cfg.pageAddr = starget->id; 666 cfg.pageAddr = starget->id;
667 cfg.cfghdr.hdr = &hdr; 667 cfg.cfghdr.hdr = &hdr;
668 cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER; 668 cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
669 cfg.timeout = SAS_CONFIG_PAGE_TIMEOUT; 669 cfg.timeout = SAS_CONFIG_PAGE_TIMEOUT;
670 670
671 if (mpt_config(ioc, &cfg) != 0) 671 if (mpt_config(ioc, &cfg) != 0)
672 goto out; 672 goto out;
673 673
674 if (!hdr.PageLength) 674 if (!hdr.PageLength)
675 goto out; 675 goto out;
676 676
677 buffer = pci_alloc_consistent(ioc->pcidev, hdr.PageLength * 4, 677 buffer = pci_alloc_consistent(ioc->pcidev, hdr.PageLength * 4,
678 &dma_handle); 678 &dma_handle);
679 679
680 if (!buffer) 680 if (!buffer)
681 goto out; 681 goto out;
682 682
683 cfg.physAddr = dma_handle; 683 cfg.physAddr = dma_handle;
684 cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT; 684 cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
685 685
686 if (mpt_config(ioc, &cfg) != 0) 686 if (mpt_config(ioc, &cfg) != 0)
687 goto out; 687 goto out;
688 688
689 if (!buffer->NumPhysDisks) 689 if (!buffer->NumPhysDisks)
690 goto out; 690 goto out;
691 691
692 /* 692 /*
693 * Adding entry for hidden components 693 * Adding entry for hidden components
694 */ 694 */
695 for (i = 0; i < buffer->NumPhysDisks; i++) { 695 for (i = 0; i < buffer->NumPhysDisks; i++) {
696 696
697 if (mpt_raid_phys_disk_pg0(ioc, 697 if (mpt_raid_phys_disk_pg0(ioc,
698 buffer->PhysDisk[i].PhysDiskNum, &phys_disk) != 0) 698 buffer->PhysDisk[i].PhysDiskNum, &phys_disk) != 0)
699 continue; 699 continue;
700 700
701 mptsas_add_device_component_by_fw(ioc, phys_disk.PhysDiskBus, 701 mptsas_add_device_component_by_fw(ioc, phys_disk.PhysDiskBus,
702 phys_disk.PhysDiskID); 702 phys_disk.PhysDiskID);
703 703
704 mutex_lock(&ioc->sas_device_info_mutex); 704 mutex_lock(&ioc->sas_device_info_mutex);
705 list_for_each_entry(sas_info, &ioc->sas_device_info_list, 705 list_for_each_entry(sas_info, &ioc->sas_device_info_list,
706 list) { 706 list) {
707 if (!sas_info->is_logical_volume && 707 if (!sas_info->is_logical_volume &&
708 (sas_info->fw.channel == phys_disk.PhysDiskBus && 708 (sas_info->fw.channel == phys_disk.PhysDiskBus &&
709 sas_info->fw.id == phys_disk.PhysDiskID)) { 709 sas_info->fw.id == phys_disk.PhysDiskID)) {
710 sas_info->is_hidden_raid_component = 1; 710 sas_info->is_hidden_raid_component = 1;
711 sas_info->volume_id = starget->id; 711 sas_info->volume_id = starget->id;
712 } 712 }
713 } 713 }
714 mutex_unlock(&ioc->sas_device_info_mutex); 714 mutex_unlock(&ioc->sas_device_info_mutex);
715 715
716 } 716 }
717 717
718 /* 718 /*
719 * Delete all matching devices out of the list 719 * Delete all matching devices out of the list
720 */ 720 */
721 mutex_lock(&ioc->sas_device_info_mutex); 721 mutex_lock(&ioc->sas_device_info_mutex);
722 list_for_each_entry_safe(sas_info, next, &ioc->sas_device_info_list, 722 list_for_each_entry_safe(sas_info, next, &ioc->sas_device_info_list,
723 list) { 723 list) {
724 if (sas_info->is_logical_volume && sas_info->fw.id == 724 if (sas_info->is_logical_volume && sas_info->fw.id ==
725 starget->id) { 725 starget->id) {
726 list_del(&sas_info->list); 726 list_del(&sas_info->list);
727 kfree(sas_info); 727 kfree(sas_info);
728 } 728 }
729 } 729 }
730 730
731 sas_info = kzalloc(sizeof(struct mptsas_device_info), GFP_KERNEL); 731 sas_info = kzalloc(sizeof(struct mptsas_device_info), GFP_KERNEL);
732 if (sas_info) { 732 if (sas_info) {
733 sas_info->fw.id = starget->id; 733 sas_info->fw.id = starget->id;
734 sas_info->os.id = starget->id; 734 sas_info->os.id = starget->id;
735 sas_info->os.channel = starget->channel; 735 sas_info->os.channel = starget->channel;
736 sas_info->is_logical_volume = 1; 736 sas_info->is_logical_volume = 1;
737 INIT_LIST_HEAD(&sas_info->list); 737 INIT_LIST_HEAD(&sas_info->list);
738 list_add_tail(&sas_info->list, &ioc->sas_device_info_list); 738 list_add_tail(&sas_info->list, &ioc->sas_device_info_list);
739 } 739 }
740 mutex_unlock(&ioc->sas_device_info_mutex); 740 mutex_unlock(&ioc->sas_device_info_mutex);
741 741
742 out: 742 out:
743 if (buffer) 743 if (buffer)
744 pci_free_consistent(ioc->pcidev, hdr.PageLength * 4, buffer, 744 pci_free_consistent(ioc->pcidev, hdr.PageLength * 4, buffer,
745 dma_handle); 745 dma_handle);
746 } 746 }
747 747
748 /** 748 /**
749 * mptsas_add_device_component_starget - 749 * mptsas_add_device_component_starget -
750 * @ioc: Pointer to MPT_ADAPTER structure 750 * @ioc: Pointer to MPT_ADAPTER structure
751 * @starget: 751 * @starget:
752 * 752 *
753 **/ 753 **/
754 static void 754 static void
755 mptsas_add_device_component_starget(MPT_ADAPTER *ioc, 755 mptsas_add_device_component_starget(MPT_ADAPTER *ioc,
756 struct scsi_target *starget) 756 struct scsi_target *starget)
757 { 757 {
758 VirtTarget *vtarget; 758 VirtTarget *vtarget;
759 struct sas_rphy *rphy; 759 struct sas_rphy *rphy;
760 struct mptsas_phyinfo *phy_info = NULL; 760 struct mptsas_phyinfo *phy_info = NULL;
761 struct mptsas_enclosure enclosure_info; 761 struct mptsas_enclosure enclosure_info;
762 762
763 rphy = dev_to_rphy(starget->dev.parent); 763 rphy = dev_to_rphy(starget->dev.parent);
764 vtarget = starget->hostdata; 764 vtarget = starget->hostdata;
765 phy_info = mptsas_find_phyinfo_by_sas_address(ioc, 765 phy_info = mptsas_find_phyinfo_by_sas_address(ioc,
766 rphy->identify.sas_address); 766 rphy->identify.sas_address);
767 if (!phy_info) 767 if (!phy_info)
768 return; 768 return;
769 769
770 memset(&enclosure_info, 0, sizeof(struct mptsas_enclosure)); 770 memset(&enclosure_info, 0, sizeof(struct mptsas_enclosure));
771 mptsas_sas_enclosure_pg0(ioc, &enclosure_info, 771 mptsas_sas_enclosure_pg0(ioc, &enclosure_info,
772 (MPI_SAS_ENCLOS_PGAD_FORM_HANDLE << 772 (MPI_SAS_ENCLOS_PGAD_FORM_HANDLE <<
773 MPI_SAS_ENCLOS_PGAD_FORM_SHIFT), 773 MPI_SAS_ENCLOS_PGAD_FORM_SHIFT),
774 phy_info->attached.handle_enclosure); 774 phy_info->attached.handle_enclosure);
775 775
776 mptsas_add_device_component(ioc, phy_info->attached.channel, 776 mptsas_add_device_component(ioc, phy_info->attached.channel,
777 phy_info->attached.id, phy_info->attached.sas_address, 777 phy_info->attached.id, phy_info->attached.sas_address,
778 phy_info->attached.device_info, 778 phy_info->attached.device_info,
779 phy_info->attached.slot, enclosure_info.enclosure_logical_id); 779 phy_info->attached.slot, enclosure_info.enclosure_logical_id);
780 } 780 }
781 781
782 /** 782 /**
783 * mptsas_del_device_component_by_os - Once a device has been removed, we mark the entry in the list as being cached 783 * mptsas_del_device_component_by_os - Once a device has been removed, we mark the entry in the list as being cached
784 * @ioc: Pointer to MPT_ADAPTER structure 784 * @ioc: Pointer to MPT_ADAPTER structure
785 * @channel: os mapped id's 785 * @channel: os mapped id's
786 * @id: 786 * @id:
787 * 787 *
788 **/ 788 **/
789 static void 789 static void
790 mptsas_del_device_component_by_os(MPT_ADAPTER *ioc, u8 channel, u8 id) 790 mptsas_del_device_component_by_os(MPT_ADAPTER *ioc, u8 channel, u8 id)
791 { 791 {
792 struct mptsas_device_info *sas_info, *next; 792 struct mptsas_device_info *sas_info, *next;
793 793
794 /* 794 /*
795 * Set is_cached flag 795 * Set is_cached flag
796 */ 796 */
797 list_for_each_entry_safe(sas_info, next, &ioc->sas_device_info_list, 797 list_for_each_entry_safe(sas_info, next, &ioc->sas_device_info_list,
798 list) { 798 list) {
799 if (sas_info->os.channel == channel && sas_info->os.id == id) 799 if (sas_info->os.channel == channel && sas_info->os.id == id)
800 sas_info->is_cached = 1; 800 sas_info->is_cached = 1;
801 } 801 }
802 } 802 }
803 803
804 /** 804 /**
805 * mptsas_del_device_components - Cleaning the list 805 * mptsas_del_device_components - Cleaning the list
806 * @ioc: Pointer to MPT_ADAPTER structure 806 * @ioc: Pointer to MPT_ADAPTER structure
807 * 807 *
808 **/ 808 **/
809 static void 809 static void
810 mptsas_del_device_components(MPT_ADAPTER *ioc) 810 mptsas_del_device_components(MPT_ADAPTER *ioc)
811 { 811 {
812 struct mptsas_device_info *sas_info, *next; 812 struct mptsas_device_info *sas_info, *next;
813 813
814 mutex_lock(&ioc->sas_device_info_mutex); 814 mutex_lock(&ioc->sas_device_info_mutex);
815 list_for_each_entry_safe(sas_info, next, &ioc->sas_device_info_list, 815 list_for_each_entry_safe(sas_info, next, &ioc->sas_device_info_list,
816 list) { 816 list) {
817 list_del(&sas_info->list); 817 list_del(&sas_info->list);
818 kfree(sas_info); 818 kfree(sas_info);
819 } 819 }
820 mutex_unlock(&ioc->sas_device_info_mutex); 820 mutex_unlock(&ioc->sas_device_info_mutex);
821 } 821 }
822 822
823 823
824 /* 824 /*
825 * mptsas_setup_wide_ports 825 * mptsas_setup_wide_ports
826 * 826 *
827 * Updates for new and existing narrow/wide port configuration 827 * Updates for new and existing narrow/wide port configuration
828 * in the sas_topology 828 * in the sas_topology
829 */ 829 */
830 static void 830 static void
831 mptsas_setup_wide_ports(MPT_ADAPTER *ioc, struct mptsas_portinfo *port_info) 831 mptsas_setup_wide_ports(MPT_ADAPTER *ioc, struct mptsas_portinfo *port_info)
832 { 832 {
833 struct mptsas_portinfo_details * port_details; 833 struct mptsas_portinfo_details * port_details;
834 struct mptsas_phyinfo *phy_info, *phy_info_cmp; 834 struct mptsas_phyinfo *phy_info, *phy_info_cmp;
835 u64 sas_address; 835 u64 sas_address;
836 int i, j; 836 int i, j;
837 837
838 mutex_lock(&ioc->sas_topology_mutex); 838 mutex_lock(&ioc->sas_topology_mutex);
839 839
840 phy_info = port_info->phy_info; 840 phy_info = port_info->phy_info;
841 for (i = 0 ; i < port_info->num_phys ; i++, phy_info++) { 841 for (i = 0 ; i < port_info->num_phys ; i++, phy_info++) {
842 if (phy_info->attached.handle) 842 if (phy_info->attached.handle)
843 continue; 843 continue;
844 port_details = phy_info->port_details; 844 port_details = phy_info->port_details;
845 if (!port_details) 845 if (!port_details)
846 continue; 846 continue;
847 if (port_details->num_phys < 2) 847 if (port_details->num_phys < 2)
848 continue; 848 continue;
849 /* 849 /*
850 * Removing a phy from a port, letting the last 850 * Removing a phy from a port, letting the last
851 * phy be removed by firmware events. 851 * phy be removed by firmware events.
852 */ 852 */
853 dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT 853 dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT
854 "%s: [%p]: deleting phy = %d\n", 854 "%s: [%p]: deleting phy = %d\n",
855 ioc->name, __func__, port_details, i)); 855 ioc->name, __func__, port_details, i));
856 port_details->num_phys--; 856 port_details->num_phys--;
857 port_details->phy_bitmask &= ~ (1 << phy_info->phy_id); 857 port_details->phy_bitmask &= ~ (1 << phy_info->phy_id);
858 memset(&phy_info->attached, 0, sizeof(struct mptsas_devinfo)); 858 memset(&phy_info->attached, 0, sizeof(struct mptsas_devinfo));
859 if (phy_info->phy) { 859 if (phy_info->phy) {
860 devtprintk(ioc, dev_printk(KERN_DEBUG, 860 devtprintk(ioc, dev_printk(KERN_DEBUG,
861 &phy_info->phy->dev, MYIOC_s_FMT 861 &phy_info->phy->dev, MYIOC_s_FMT
862 "delete phy %d, phy-obj (0x%p)\n", ioc->name, 862 "delete phy %d, phy-obj (0x%p)\n", ioc->name,
863 phy_info->phy_id, phy_info->phy)); 863 phy_info->phy_id, phy_info->phy));
864 sas_port_delete_phy(port_details->port, phy_info->phy); 864 sas_port_delete_phy(port_details->port, phy_info->phy);
865 } 865 }
866 phy_info->port_details = NULL; 866 phy_info->port_details = NULL;
867 } 867 }
868 868
869 /* 869 /*
870 * Populate and refresh the tree 870 * Populate and refresh the tree
871 */ 871 */
872 phy_info = port_info->phy_info; 872 phy_info = port_info->phy_info;
873 for (i = 0 ; i < port_info->num_phys ; i++, phy_info++) { 873 for (i = 0 ; i < port_info->num_phys ; i++, phy_info++) {
874 sas_address = phy_info->attached.sas_address; 874 sas_address = phy_info->attached.sas_address;
875 dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "phy_id=%d sas_address=0x%018llX\n", 875 dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "phy_id=%d sas_address=0x%018llX\n",
876 ioc->name, i, (unsigned long long)sas_address)); 876 ioc->name, i, (unsigned long long)sas_address));
877 if (!sas_address) 877 if (!sas_address)
878 continue; 878 continue;
879 port_details = phy_info->port_details; 879 port_details = phy_info->port_details;
880 /* 880 /*
881 * Forming a port 881 * Forming a port
882 */ 882 */
883 if (!port_details) { 883 if (!port_details) {
884 port_details = kzalloc(sizeof(struct 884 port_details = kzalloc(sizeof(struct
885 mptsas_portinfo_details), GFP_KERNEL); 885 mptsas_portinfo_details), GFP_KERNEL);
886 if (!port_details) 886 if (!port_details)
887 goto out; 887 goto out;
888 port_details->num_phys = 1; 888 port_details->num_phys = 1;
889 port_details->port_info = port_info; 889 port_details->port_info = port_info;
890 if (phy_info->phy_id < 64 ) 890 if (phy_info->phy_id < 64 )
891 port_details->phy_bitmask |= 891 port_details->phy_bitmask |=
892 (1 << phy_info->phy_id); 892 (1 << phy_info->phy_id);
893 phy_info->sas_port_add_phy=1; 893 phy_info->sas_port_add_phy=1;
894 dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "\t\tForming port\n\t\t" 894 dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "\t\tForming port\n\t\t"
895 "phy_id=%d sas_address=0x%018llX\n", 895 "phy_id=%d sas_address=0x%018llX\n",
896 ioc->name, i, (unsigned long long)sas_address)); 896 ioc->name, i, (unsigned long long)sas_address));
897 phy_info->port_details = port_details; 897 phy_info->port_details = port_details;
898 } 898 }
899 899
900 if (i == port_info->num_phys - 1) 900 if (i == port_info->num_phys - 1)
901 continue; 901 continue;
902 phy_info_cmp = &port_info->phy_info[i + 1]; 902 phy_info_cmp = &port_info->phy_info[i + 1];
903 for (j = i + 1 ; j < port_info->num_phys ; j++, 903 for (j = i + 1 ; j < port_info->num_phys ; j++,
904 phy_info_cmp++) { 904 phy_info_cmp++) {
905 if (!phy_info_cmp->attached.sas_address) 905 if (!phy_info_cmp->attached.sas_address)
906 continue; 906 continue;
907 if (sas_address != phy_info_cmp->attached.sas_address) 907 if (sas_address != phy_info_cmp->attached.sas_address)
908 continue; 908 continue;
909 if (phy_info_cmp->port_details == port_details ) 909 if (phy_info_cmp->port_details == port_details )
910 continue; 910 continue;
911 dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT 911 dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT
912 "\t\tphy_id=%d sas_address=0x%018llX\n", 912 "\t\tphy_id=%d sas_address=0x%018llX\n",
913 ioc->name, j, (unsigned long long) 913 ioc->name, j, (unsigned long long)
914 phy_info_cmp->attached.sas_address)); 914 phy_info_cmp->attached.sas_address));
915 if (phy_info_cmp->port_details) { 915 if (phy_info_cmp->port_details) {
916 port_details->rphy = 916 port_details->rphy =
917 mptsas_get_rphy(phy_info_cmp); 917 mptsas_get_rphy(phy_info_cmp);
918 port_details->port = 918 port_details->port =
919 mptsas_get_port(phy_info_cmp); 919 mptsas_get_port(phy_info_cmp);
920 port_details->starget = 920 port_details->starget =
921 mptsas_get_starget(phy_info_cmp); 921 mptsas_get_starget(phy_info_cmp);
922 port_details->num_phys = 922 port_details->num_phys =
923 phy_info_cmp->port_details->num_phys; 923 phy_info_cmp->port_details->num_phys;
924 if (!phy_info_cmp->port_details->num_phys) 924 if (!phy_info_cmp->port_details->num_phys)
925 kfree(phy_info_cmp->port_details); 925 kfree(phy_info_cmp->port_details);
926 } else 926 } else
927 phy_info_cmp->sas_port_add_phy=1; 927 phy_info_cmp->sas_port_add_phy=1;
928 /* 928 /*
929 * Adding a phy to a port 929 * Adding a phy to a port
930 */ 930 */
931 phy_info_cmp->port_details = port_details; 931 phy_info_cmp->port_details = port_details;
932 if (phy_info_cmp->phy_id < 64 ) 932 if (phy_info_cmp->phy_id < 64 )
933 port_details->phy_bitmask |= 933 port_details->phy_bitmask |=
934 (1 << phy_info_cmp->phy_id); 934 (1 << phy_info_cmp->phy_id);
935 port_details->num_phys++; 935 port_details->num_phys++;
936 } 936 }
937 } 937 }
938 938
939 out: 939 out:
940 940
941 for (i = 0; i < port_info->num_phys; i++) { 941 for (i = 0; i < port_info->num_phys; i++) {
942 port_details = port_info->phy_info[i].port_details; 942 port_details = port_info->phy_info[i].port_details;
943 if (!port_details) 943 if (!port_details)
944 continue; 944 continue;
945 dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT 945 dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT
946 "%s: [%p]: phy_id=%02d num_phys=%02d " 946 "%s: [%p]: phy_id=%02d num_phys=%02d "
947 "bitmask=0x%016llX\n", ioc->name, __func__, 947 "bitmask=0x%016llX\n", ioc->name, __func__,
948 port_details, i, port_details->num_phys, 948 port_details, i, port_details->num_phys,
949 (unsigned long long)port_details->phy_bitmask)); 949 (unsigned long long)port_details->phy_bitmask));
950 dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "\t\tport = %p rphy=%p\n", 950 dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "\t\tport = %p rphy=%p\n",
951 ioc->name, port_details->port, port_details->rphy)); 951 ioc->name, port_details->port, port_details->rphy));
952 } 952 }
953 dsaswideprintk(ioc, printk("\n")); 953 dsaswideprintk(ioc, printk("\n"));
954 mutex_unlock(&ioc->sas_topology_mutex); 954 mutex_unlock(&ioc->sas_topology_mutex);
955 } 955 }
956 956
957 /** 957 /**
958 * csmisas_find_vtarget 958 * csmisas_find_vtarget
959 * 959 *
960 * @ioc 960 * @ioc
961 * @volume_id 961 * @volume_id
962 * @volume_bus 962 * @volume_bus
963 * 963 *
964 **/ 964 **/
965 static VirtTarget * 965 static VirtTarget *
966 mptsas_find_vtarget(MPT_ADAPTER *ioc, u8 channel, u8 id) 966 mptsas_find_vtarget(MPT_ADAPTER *ioc, u8 channel, u8 id)
967 { 967 {
968 struct scsi_device *sdev; 968 struct scsi_device *sdev;
969 VirtDevice *vdevice; 969 VirtDevice *vdevice;
970 VirtTarget *vtarget = NULL; 970 VirtTarget *vtarget = NULL;
971 971
972 shost_for_each_device(sdev, ioc->sh) { 972 shost_for_each_device(sdev, ioc->sh) {
973 vdevice = sdev->hostdata; 973 vdevice = sdev->hostdata;
974 if ((vdevice == NULL) || 974 if ((vdevice == NULL) ||
975 (vdevice->vtarget == NULL)) 975 (vdevice->vtarget == NULL))
976 continue; 976 continue;
977 if ((vdevice->vtarget->tflags & 977 if ((vdevice->vtarget->tflags &
978 MPT_TARGET_FLAGS_RAID_COMPONENT || 978 MPT_TARGET_FLAGS_RAID_COMPONENT ||
979 vdevice->vtarget->raidVolume)) 979 vdevice->vtarget->raidVolume))
980 continue; 980 continue;
981 if (vdevice->vtarget->id == id && 981 if (vdevice->vtarget->id == id &&
982 vdevice->vtarget->channel == channel) 982 vdevice->vtarget->channel == channel)
983 vtarget = vdevice->vtarget; 983 vtarget = vdevice->vtarget;
984 } 984 }
985 return vtarget; 985 return vtarget;
986 } 986 }
987 987
988 static void 988 static void
989 mptsas_queue_device_delete(MPT_ADAPTER *ioc, 989 mptsas_queue_device_delete(MPT_ADAPTER *ioc,
990 MpiEventDataSasDeviceStatusChange_t *sas_event_data) 990 MpiEventDataSasDeviceStatusChange_t *sas_event_data)
991 { 991 {
992 struct fw_event_work *fw_event; 992 struct fw_event_work *fw_event;
993 int sz; 993 int sz;
994 994
995 sz = offsetof(struct fw_event_work, event_data) + 995 sz = offsetof(struct fw_event_work, event_data) +
996 sizeof(MpiEventDataSasDeviceStatusChange_t); 996 sizeof(MpiEventDataSasDeviceStatusChange_t);
997 fw_event = kzalloc(sz, GFP_ATOMIC); 997 fw_event = kzalloc(sz, GFP_ATOMIC);
998 if (!fw_event) { 998 if (!fw_event) {
999 printk(MYIOC_s_WARN_FMT "%s: failed at (line=%d)\n", 999 printk(MYIOC_s_WARN_FMT "%s: failed at (line=%d)\n",
1000 ioc->name, __func__, __LINE__); 1000 ioc->name, __func__, __LINE__);
1001 return; 1001 return;
1002 } 1002 }
1003 memcpy(fw_event->event_data, sas_event_data, 1003 memcpy(fw_event->event_data, sas_event_data,
1004 sizeof(MpiEventDataSasDeviceStatusChange_t)); 1004 sizeof(MpiEventDataSasDeviceStatusChange_t));
1005 fw_event->event = MPI_EVENT_SAS_DEVICE_STATUS_CHANGE; 1005 fw_event->event = MPI_EVENT_SAS_DEVICE_STATUS_CHANGE;
1006 fw_event->ioc = ioc; 1006 fw_event->ioc = ioc;
1007 mptsas_add_fw_event(ioc, fw_event, msecs_to_jiffies(1)); 1007 mptsas_add_fw_event(ioc, fw_event, msecs_to_jiffies(1));
1008 } 1008 }
1009 1009
1010 static void 1010 static void
1011 mptsas_queue_rescan(MPT_ADAPTER *ioc) 1011 mptsas_queue_rescan(MPT_ADAPTER *ioc)
1012 { 1012 {
1013 struct fw_event_work *fw_event; 1013 struct fw_event_work *fw_event;
1014 int sz; 1014 int sz;
1015 1015
1016 sz = offsetof(struct fw_event_work, event_data); 1016 sz = offsetof(struct fw_event_work, event_data);
1017 fw_event = kzalloc(sz, GFP_ATOMIC); 1017 fw_event = kzalloc(sz, GFP_ATOMIC);
1018 if (!fw_event) { 1018 if (!fw_event) {
1019 printk(MYIOC_s_WARN_FMT "%s: failed at (line=%d)\n", 1019 printk(MYIOC_s_WARN_FMT "%s: failed at (line=%d)\n",
1020 ioc->name, __func__, __LINE__); 1020 ioc->name, __func__, __LINE__);
1021 return; 1021 return;
1022 } 1022 }
1023 fw_event->event = -1; 1023 fw_event->event = -1;
1024 fw_event->ioc = ioc; 1024 fw_event->ioc = ioc;
1025 mptsas_add_fw_event(ioc, fw_event, msecs_to_jiffies(1)); 1025 mptsas_add_fw_event(ioc, fw_event, msecs_to_jiffies(1));
1026 } 1026 }
1027 1027
1028 1028
1029 /** 1029 /**
1030 * mptsas_target_reset 1030 * mptsas_target_reset
1031 * 1031 *
1032 * Issues TARGET_RESET to end device using handshaking method 1032 * Issues TARGET_RESET to end device using handshaking method
1033 * 1033 *
1034 * @ioc 1034 * @ioc
1035 * @channel 1035 * @channel
1036 * @id 1036 * @id
1037 * 1037 *
1038 * Returns (1) success 1038 * Returns (1) success
1039 * (0) failure 1039 * (0) failure
1040 * 1040 *
1041 **/ 1041 **/
1042 static int 1042 static int
1043 mptsas_target_reset(MPT_ADAPTER *ioc, u8 channel, u8 id) 1043 mptsas_target_reset(MPT_ADAPTER *ioc, u8 channel, u8 id)
1044 { 1044 {
1045 MPT_FRAME_HDR *mf; 1045 MPT_FRAME_HDR *mf;
1046 SCSITaskMgmt_t *pScsiTm; 1046 SCSITaskMgmt_t *pScsiTm;
1047 if (mpt_set_taskmgmt_in_progress_flag(ioc) != 0) 1047 if (mpt_set_taskmgmt_in_progress_flag(ioc) != 0)
1048 return 0; 1048 return 0;
1049 1049
1050 1050
1051 mf = mpt_get_msg_frame(mptsasDeviceResetCtx, ioc); 1051 mf = mpt_get_msg_frame(mptsasDeviceResetCtx, ioc);
1052 if (mf == NULL) { 1052 if (mf == NULL) {
1053 dfailprintk(ioc, printk(MYIOC_s_WARN_FMT 1053 dfailprintk(ioc, printk(MYIOC_s_WARN_FMT
1054 "%s, no msg frames @%d!!\n", ioc->name, 1054 "%s, no msg frames @%d!!\n", ioc->name,
1055 __func__, __LINE__)); 1055 __func__, __LINE__));
1056 goto out_fail; 1056 goto out_fail;
1057 } 1057 }
1058 1058
1059 dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT "TaskMgmt request (mf=%p)\n", 1059 dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT "TaskMgmt request (mf=%p)\n",
1060 ioc->name, mf)); 1060 ioc->name, mf));
1061 1061
1062 /* Format the Request 1062 /* Format the Request
1063 */ 1063 */
1064 pScsiTm = (SCSITaskMgmt_t *) mf; 1064 pScsiTm = (SCSITaskMgmt_t *) mf;
1065 memset (pScsiTm, 0, sizeof(SCSITaskMgmt_t)); 1065 memset (pScsiTm, 0, sizeof(SCSITaskMgmt_t));
1066 pScsiTm->TargetID = id; 1066 pScsiTm->TargetID = id;
1067 pScsiTm->Bus = channel; 1067 pScsiTm->Bus = channel;
1068 pScsiTm->Function = MPI_FUNCTION_SCSI_TASK_MGMT; 1068 pScsiTm->Function = MPI_FUNCTION_SCSI_TASK_MGMT;
1069 pScsiTm->TaskType = MPI_SCSITASKMGMT_TASKTYPE_TARGET_RESET; 1069 pScsiTm->TaskType = MPI_SCSITASKMGMT_TASKTYPE_TARGET_RESET;
1070 pScsiTm->MsgFlags = MPI_SCSITASKMGMT_MSGFLAGS_LIPRESET_RESET_OPTION; 1070 pScsiTm->MsgFlags = MPI_SCSITASKMGMT_MSGFLAGS_LIPRESET_RESET_OPTION;
1071 1071
1072 DBG_DUMP_TM_REQUEST_FRAME(ioc, (u32 *)mf); 1072 DBG_DUMP_TM_REQUEST_FRAME(ioc, (u32 *)mf);
1073 1073
1074 dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT 1074 dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT
1075 "TaskMgmt type=%d (sas device delete) fw_channel = %d fw_id = %d)\n", 1075 "TaskMgmt type=%d (sas device delete) fw_channel = %d fw_id = %d)\n",
1076 ioc->name, MPI_SCSITASKMGMT_TASKTYPE_TARGET_RESET, channel, id)); 1076 ioc->name, MPI_SCSITASKMGMT_TASKTYPE_TARGET_RESET, channel, id));
1077 1077
1078 mpt_put_msg_frame_hi_pri(mptsasDeviceResetCtx, ioc, mf); 1078 mpt_put_msg_frame_hi_pri(mptsasDeviceResetCtx, ioc, mf);
1079 1079
1080 return 1; 1080 return 1;
1081 1081
1082 out_fail: 1082 out_fail:
1083 1083
1084 mpt_clear_taskmgmt_in_progress_flag(ioc); 1084 mpt_clear_taskmgmt_in_progress_flag(ioc);
1085 return 0; 1085 return 0;
1086 } 1086 }
1087 1087
1088 static void 1088 static void
1089 mptsas_block_io_sdev(struct scsi_device *sdev, void *data) 1089 mptsas_block_io_sdev(struct scsi_device *sdev, void *data)
1090 { 1090 {
1091 scsi_device_set_state(sdev, SDEV_BLOCK); 1091 scsi_device_set_state(sdev, SDEV_BLOCK);
1092 } 1092 }
1093 1093
1094 static void 1094 static void
1095 mptsas_block_io_starget(struct scsi_target *starget) 1095 mptsas_block_io_starget(struct scsi_target *starget)
1096 { 1096 {
1097 if (starget) 1097 if (starget)
1098 starget_for_each_device(starget, NULL, mptsas_block_io_sdev); 1098 starget_for_each_device(starget, NULL, mptsas_block_io_sdev);
1099 } 1099 }
1100 1100
1101 /** 1101 /**
1102 * mptsas_target_reset_queue 1102 * mptsas_target_reset_queue
1103 * 1103 *
1104 * Receive request for TARGET_RESET after receiving an firmware 1104 * Receive request for TARGET_RESET after receiving an firmware
1105 * event NOT_RESPONDING_EVENT, then put command in link list 1105 * event NOT_RESPONDING_EVENT, then put command in link list
1106 * and queue if task_queue already in use. 1106 * and queue if task_queue already in use.
1107 * 1107 *
1108 * @ioc 1108 * @ioc
1109 * @sas_event_data 1109 * @sas_event_data
1110 * 1110 *
1111 **/ 1111 **/
1112 static void 1112 static void
1113 mptsas_target_reset_queue(MPT_ADAPTER *ioc, 1113 mptsas_target_reset_queue(MPT_ADAPTER *ioc,
1114 EVENT_DATA_SAS_DEVICE_STATUS_CHANGE *sas_event_data) 1114 EVENT_DATA_SAS_DEVICE_STATUS_CHANGE *sas_event_data)
1115 { 1115 {
1116 MPT_SCSI_HOST *hd = shost_priv(ioc->sh); 1116 MPT_SCSI_HOST *hd = shost_priv(ioc->sh);
1117 VirtTarget *vtarget = NULL; 1117 VirtTarget *vtarget = NULL;
1118 struct mptsas_target_reset_event *target_reset_list; 1118 struct mptsas_target_reset_event *target_reset_list;
1119 u8 id, channel; 1119 u8 id, channel;
1120 1120
1121 id = sas_event_data->TargetID; 1121 id = sas_event_data->TargetID;
1122 channel = sas_event_data->Bus; 1122 channel = sas_event_data->Bus;
1123 1123
1124 vtarget = mptsas_find_vtarget(ioc, channel, id); 1124 vtarget = mptsas_find_vtarget(ioc, channel, id);
1125 if (vtarget) { 1125 if (vtarget) {
1126 mptsas_block_io_starget(vtarget->starget); 1126 mptsas_block_io_starget(vtarget->starget);
1127 vtarget->deleted = 1; /* block IO */ 1127 vtarget->deleted = 1; /* block IO */
1128 } 1128 }
1129 1129
1130 target_reset_list = kzalloc(sizeof(struct mptsas_target_reset_event), 1130 target_reset_list = kzalloc(sizeof(struct mptsas_target_reset_event),
1131 GFP_ATOMIC); 1131 GFP_ATOMIC);
1132 if (!target_reset_list) { 1132 if (!target_reset_list) {
1133 dfailprintk(ioc, printk(MYIOC_s_WARN_FMT 1133 dfailprintk(ioc, printk(MYIOC_s_WARN_FMT
1134 "%s, failed to allocate mem @%d..!!\n", 1134 "%s, failed to allocate mem @%d..!!\n",
1135 ioc->name, __func__, __LINE__)); 1135 ioc->name, __func__, __LINE__));
1136 return; 1136 return;
1137 } 1137 }
1138 1138
1139 memcpy(&target_reset_list->sas_event_data, sas_event_data, 1139 memcpy(&target_reset_list->sas_event_data, sas_event_data,
1140 sizeof(*sas_event_data)); 1140 sizeof(*sas_event_data));
1141 list_add_tail(&target_reset_list->list, &hd->target_reset_list); 1141 list_add_tail(&target_reset_list->list, &hd->target_reset_list);
1142 1142
1143 target_reset_list->time_count = jiffies; 1143 target_reset_list->time_count = jiffies;
1144 1144
1145 if (mptsas_target_reset(ioc, channel, id)) { 1145 if (mptsas_target_reset(ioc, channel, id)) {
1146 target_reset_list->target_reset_issued = 1; 1146 target_reset_list->target_reset_issued = 1;
1147 } 1147 }
1148 } 1148 }
1149 1149
1150 /** 1150 /**
1151 * mptsas_schedule_target_reset- send pending target reset 1151 * mptsas_schedule_target_reset- send pending target reset
1152 * @iocp: per adapter object 1152 * @iocp: per adapter object
1153 * 1153 *
1154 * This function will delete scheduled target reset from the list and 1154 * This function will delete scheduled target reset from the list and
1155 * try to send next target reset. This will be called from completion 1155 * try to send next target reset. This will be called from completion
1156 * context of any Task management command. 1156 * context of any Task management command.
1157 */ 1157 */
1158 1158
1159 void 1159 void
1160 mptsas_schedule_target_reset(void *iocp) 1160 mptsas_schedule_target_reset(void *iocp)
1161 { 1161 {
1162 MPT_ADAPTER *ioc = (MPT_ADAPTER *)(iocp); 1162 MPT_ADAPTER *ioc = (MPT_ADAPTER *)(iocp);
1163 MPT_SCSI_HOST *hd = shost_priv(ioc->sh); 1163 MPT_SCSI_HOST *hd = shost_priv(ioc->sh);
1164 struct list_head *head = &hd->target_reset_list; 1164 struct list_head *head = &hd->target_reset_list;
1165 struct mptsas_target_reset_event *target_reset_list; 1165 struct mptsas_target_reset_event *target_reset_list;
1166 u8 id, channel; 1166 u8 id, channel;
1167 /* 1167 /*
1168 * issue target reset to next device in the queue 1168 * issue target reset to next device in the queue
1169 */ 1169 */
1170 1170
1171 head = &hd->target_reset_list; 1171 head = &hd->target_reset_list;
1172 if (list_empty(head)) 1172 if (list_empty(head))
1173 return; 1173 return;
1174 1174
1175 target_reset_list = list_entry(head->next, 1175 target_reset_list = list_entry(head->next,
1176 struct mptsas_target_reset_event, list); 1176 struct mptsas_target_reset_event, list);
1177 1177
1178 id = target_reset_list->sas_event_data.TargetID; 1178 id = target_reset_list->sas_event_data.TargetID;
1179 channel = target_reset_list->sas_event_data.Bus; 1179 channel = target_reset_list->sas_event_data.Bus;
1180 target_reset_list->time_count = jiffies; 1180 target_reset_list->time_count = jiffies;
1181 1181
1182 if (mptsas_target_reset(ioc, channel, id)) 1182 if (mptsas_target_reset(ioc, channel, id))
1183 target_reset_list->target_reset_issued = 1; 1183 target_reset_list->target_reset_issued = 1;
1184 return; 1184 return;
1185 } 1185 }
1186 1186
1187 1187
1188 /** 1188 /**
1189 * mptsas_taskmgmt_complete - complete SAS task management function 1189 * mptsas_taskmgmt_complete - complete SAS task management function
1190 * @ioc: Pointer to MPT_ADAPTER structure 1190 * @ioc: Pointer to MPT_ADAPTER structure
1191 * 1191 *
1192 * Completion for TARGET_RESET after NOT_RESPONDING_EVENT, enable work 1192 * Completion for TARGET_RESET after NOT_RESPONDING_EVENT, enable work
1193 * queue to finish off removing device from upper layers. then send next 1193 * queue to finish off removing device from upper layers. then send next
1194 * TARGET_RESET in the queue. 1194 * TARGET_RESET in the queue.
1195 **/ 1195 **/
1196 static int 1196 static int
1197 mptsas_taskmgmt_complete(MPT_ADAPTER *ioc, MPT_FRAME_HDR *mf, MPT_FRAME_HDR *mr) 1197 mptsas_taskmgmt_complete(MPT_ADAPTER *ioc, MPT_FRAME_HDR *mf, MPT_FRAME_HDR *mr)
1198 { 1198 {
1199 MPT_SCSI_HOST *hd = shost_priv(ioc->sh); 1199 MPT_SCSI_HOST *hd = shost_priv(ioc->sh);
1200 struct list_head *head = &hd->target_reset_list; 1200 struct list_head *head = &hd->target_reset_list;
1201 u8 id, channel; 1201 u8 id, channel;
1202 struct mptsas_target_reset_event *target_reset_list; 1202 struct mptsas_target_reset_event *target_reset_list;
1203 SCSITaskMgmtReply_t *pScsiTmReply; 1203 SCSITaskMgmtReply_t *pScsiTmReply;
1204 1204
1205 dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT "TaskMgmt completed: " 1205 dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT "TaskMgmt completed: "
1206 "(mf = %p, mr = %p)\n", ioc->name, mf, mr)); 1206 "(mf = %p, mr = %p)\n", ioc->name, mf, mr));
1207 1207
1208 pScsiTmReply = (SCSITaskMgmtReply_t *)mr; 1208 pScsiTmReply = (SCSITaskMgmtReply_t *)mr;
1209 if (pScsiTmReply) { 1209 if (pScsiTmReply) {
1210 dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT 1210 dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT
1211 "\tTaskMgmt completed: fw_channel = %d, fw_id = %d,\n" 1211 "\tTaskMgmt completed: fw_channel = %d, fw_id = %d,\n"
1212 "\ttask_type = 0x%02X, iocstatus = 0x%04X " 1212 "\ttask_type = 0x%02X, iocstatus = 0x%04X "
1213 "loginfo = 0x%08X,\n\tresponse_code = 0x%02X, " 1213 "loginfo = 0x%08X,\n\tresponse_code = 0x%02X, "
1214 "term_cmnds = %d\n", ioc->name, 1214 "term_cmnds = %d\n", ioc->name,
1215 pScsiTmReply->Bus, pScsiTmReply->TargetID, 1215 pScsiTmReply->Bus, pScsiTmReply->TargetID,
1216 pScsiTmReply->TaskType, 1216 pScsiTmReply->TaskType,
1217 le16_to_cpu(pScsiTmReply->IOCStatus), 1217 le16_to_cpu(pScsiTmReply->IOCStatus),
1218 le32_to_cpu(pScsiTmReply->IOCLogInfo), 1218 le32_to_cpu(pScsiTmReply->IOCLogInfo),
1219 pScsiTmReply->ResponseCode, 1219 pScsiTmReply->ResponseCode,
1220 le32_to_cpu(pScsiTmReply->TerminationCount))); 1220 le32_to_cpu(pScsiTmReply->TerminationCount)));
1221 1221
1222 if (pScsiTmReply->ResponseCode) 1222 if (pScsiTmReply->ResponseCode)
1223 mptscsih_taskmgmt_response_code(ioc, 1223 mptscsih_taskmgmt_response_code(ioc,
1224 pScsiTmReply->ResponseCode); 1224 pScsiTmReply->ResponseCode);
1225 } 1225 }
1226 1226
1227 if (pScsiTmReply && (pScsiTmReply->TaskType == 1227 if (pScsiTmReply && (pScsiTmReply->TaskType ==
1228 MPI_SCSITASKMGMT_TASKTYPE_QUERY_TASK || pScsiTmReply->TaskType == 1228 MPI_SCSITASKMGMT_TASKTYPE_QUERY_TASK || pScsiTmReply->TaskType ==
1229 MPI_SCSITASKMGMT_TASKTYPE_ABRT_TASK_SET)) { 1229 MPI_SCSITASKMGMT_TASKTYPE_ABRT_TASK_SET)) {
1230 ioc->taskmgmt_cmds.status |= MPT_MGMT_STATUS_COMMAND_GOOD; 1230 ioc->taskmgmt_cmds.status |= MPT_MGMT_STATUS_COMMAND_GOOD;
1231 ioc->taskmgmt_cmds.status |= MPT_MGMT_STATUS_RF_VALID; 1231 ioc->taskmgmt_cmds.status |= MPT_MGMT_STATUS_RF_VALID;
1232 memcpy(ioc->taskmgmt_cmds.reply, mr, 1232 memcpy(ioc->taskmgmt_cmds.reply, mr,
1233 min(MPT_DEFAULT_FRAME_SIZE, 4 * mr->u.reply.MsgLength)); 1233 min(MPT_DEFAULT_FRAME_SIZE, 4 * mr->u.reply.MsgLength));
1234 if (ioc->taskmgmt_cmds.status & MPT_MGMT_STATUS_PENDING) { 1234 if (ioc->taskmgmt_cmds.status & MPT_MGMT_STATUS_PENDING) {
1235 ioc->taskmgmt_cmds.status &= ~MPT_MGMT_STATUS_PENDING; 1235 ioc->taskmgmt_cmds.status &= ~MPT_MGMT_STATUS_PENDING;
1236 complete(&ioc->taskmgmt_cmds.done); 1236 complete(&ioc->taskmgmt_cmds.done);
1237 return 1; 1237 return 1;
1238 } 1238 }
1239 return 0; 1239 return 0;
1240 } 1240 }
1241 1241
1242 mpt_clear_taskmgmt_in_progress_flag(ioc); 1242 mpt_clear_taskmgmt_in_progress_flag(ioc);
1243 1243
1244 if (list_empty(head)) 1244 if (list_empty(head))
1245 return 1; 1245 return 1;
1246 1246
1247 target_reset_list = list_entry(head->next, 1247 target_reset_list = list_entry(head->next,
1248 struct mptsas_target_reset_event, list); 1248 struct mptsas_target_reset_event, list);
1249 1249
1250 dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT 1250 dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT
1251 "TaskMgmt: completed (%d seconds)\n", 1251 "TaskMgmt: completed (%d seconds)\n",
1252 ioc->name, jiffies_to_msecs(jiffies - 1252 ioc->name, jiffies_to_msecs(jiffies -
1253 target_reset_list->time_count)/1000)); 1253 target_reset_list->time_count)/1000));
1254 1254
1255 id = pScsiTmReply->TargetID; 1255 id = pScsiTmReply->TargetID;
1256 channel = pScsiTmReply->Bus; 1256 channel = pScsiTmReply->Bus;
1257 target_reset_list->time_count = jiffies; 1257 target_reset_list->time_count = jiffies;
1258 1258
1259 /* 1259 /*
1260 * retry target reset 1260 * retry target reset
1261 */ 1261 */
1262 if (!target_reset_list->target_reset_issued) { 1262 if (!target_reset_list->target_reset_issued) {
1263 if (mptsas_target_reset(ioc, channel, id)) 1263 if (mptsas_target_reset(ioc, channel, id))
1264 target_reset_list->target_reset_issued = 1; 1264 target_reset_list->target_reset_issued = 1;
1265 return 1; 1265 return 1;
1266 } 1266 }
1267 1267
1268 /* 1268 /*
1269 * enable work queue to remove device from upper layers 1269 * enable work queue to remove device from upper layers
1270 */ 1270 */
1271 list_del(&target_reset_list->list); 1271 list_del(&target_reset_list->list);
1272 if (!ioc->fw_events_off) 1272 if (!ioc->fw_events_off)
1273 mptsas_queue_device_delete(ioc, 1273 mptsas_queue_device_delete(ioc,
1274 &target_reset_list->sas_event_data); 1274 &target_reset_list->sas_event_data);
1275 1275
1276 1276
1277 ioc->schedule_target_reset(ioc); 1277 ioc->schedule_target_reset(ioc);
1278 1278
1279 return 1; 1279 return 1;
1280 } 1280 }
1281 1281
1282 /** 1282 /**
1283 * mptscsih_ioc_reset 1283 * mptscsih_ioc_reset
1284 * 1284 *
1285 * @ioc 1285 * @ioc
1286 * @reset_phase 1286 * @reset_phase
1287 * 1287 *
1288 **/ 1288 **/
1289 static int 1289 static int
1290 mptsas_ioc_reset(MPT_ADAPTER *ioc, int reset_phase) 1290 mptsas_ioc_reset(MPT_ADAPTER *ioc, int reset_phase)
1291 { 1291 {
1292 MPT_SCSI_HOST *hd; 1292 MPT_SCSI_HOST *hd;
1293 int rc; 1293 int rc;
1294 1294
1295 rc = mptscsih_ioc_reset(ioc, reset_phase); 1295 rc = mptscsih_ioc_reset(ioc, reset_phase);
1296 if ((ioc->bus_type != SAS) || (!rc)) 1296 if ((ioc->bus_type != SAS) || (!rc))
1297 return rc; 1297 return rc;
1298 1298
1299 hd = shost_priv(ioc->sh); 1299 hd = shost_priv(ioc->sh);
1300 if (!hd->ioc) 1300 if (!hd->ioc)
1301 goto out; 1301 goto out;
1302 1302
1303 switch (reset_phase) { 1303 switch (reset_phase) {
1304 case MPT_IOC_SETUP_RESET: 1304 case MPT_IOC_SETUP_RESET:
1305 dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT 1305 dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT
1306 "%s: MPT_IOC_SETUP_RESET\n", ioc->name, __func__)); 1306 "%s: MPT_IOC_SETUP_RESET\n", ioc->name, __func__));
1307 mptsas_fw_event_off(ioc); 1307 mptsas_fw_event_off(ioc);
1308 break; 1308 break;
1309 case MPT_IOC_PRE_RESET: 1309 case MPT_IOC_PRE_RESET:
1310 dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT 1310 dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT
1311 "%s: MPT_IOC_PRE_RESET\n", ioc->name, __func__)); 1311 "%s: MPT_IOC_PRE_RESET\n", ioc->name, __func__));
1312 break; 1312 break;
1313 case MPT_IOC_POST_RESET: 1313 case MPT_IOC_POST_RESET:
1314 dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT 1314 dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT
1315 "%s: MPT_IOC_POST_RESET\n", ioc->name, __func__)); 1315 "%s: MPT_IOC_POST_RESET\n", ioc->name, __func__));
1316 if (ioc->sas_mgmt.status & MPT_MGMT_STATUS_PENDING) { 1316 if (ioc->sas_mgmt.status & MPT_MGMT_STATUS_PENDING) {
1317 ioc->sas_mgmt.status |= MPT_MGMT_STATUS_DID_IOCRESET; 1317 ioc->sas_mgmt.status |= MPT_MGMT_STATUS_DID_IOCRESET;
1318 complete(&ioc->sas_mgmt.done); 1318 complete(&ioc->sas_mgmt.done);
1319 } 1319 }
1320 mptsas_cleanup_fw_event_q(ioc); 1320 mptsas_cleanup_fw_event_q(ioc);
1321 mptsas_queue_rescan(ioc); 1321 mptsas_queue_rescan(ioc);
1322 break; 1322 break;
1323 default: 1323 default:
1324 break; 1324 break;
1325 } 1325 }
1326 1326
1327 out: 1327 out:
1328 return rc; 1328 return rc;
1329 } 1329 }
1330 1330
1331 1331
1332 /** 1332 /**
1333 * enum device_state - 1333 * enum device_state -
1334 * @DEVICE_RETRY: need to retry the TUR 1334 * @DEVICE_RETRY: need to retry the TUR
1335 * @DEVICE_ERROR: TUR return error, don't add device 1335 * @DEVICE_ERROR: TUR return error, don't add device
1336 * @DEVICE_READY: device can be added 1336 * @DEVICE_READY: device can be added
1337 * 1337 *
1338 */ 1338 */
1339 enum device_state{ 1339 enum device_state{
1340 DEVICE_RETRY, 1340 DEVICE_RETRY,
1341 DEVICE_ERROR, 1341 DEVICE_ERROR,
1342 DEVICE_READY, 1342 DEVICE_READY,
1343 }; 1343 };
1344 1344
1345 static int 1345 static int
1346 mptsas_sas_enclosure_pg0(MPT_ADAPTER *ioc, struct mptsas_enclosure *enclosure, 1346 mptsas_sas_enclosure_pg0(MPT_ADAPTER *ioc, struct mptsas_enclosure *enclosure,
1347 u32 form, u32 form_specific) 1347 u32 form, u32 form_specific)
1348 { 1348 {
1349 ConfigExtendedPageHeader_t hdr; 1349 ConfigExtendedPageHeader_t hdr;
1350 CONFIGPARMS cfg; 1350 CONFIGPARMS cfg;
1351 SasEnclosurePage0_t *buffer; 1351 SasEnclosurePage0_t *buffer;
1352 dma_addr_t dma_handle; 1352 dma_addr_t dma_handle;
1353 int error; 1353 int error;
1354 __le64 le_identifier; 1354 __le64 le_identifier;
1355 1355
1356 memset(&hdr, 0, sizeof(hdr)); 1356 memset(&hdr, 0, sizeof(hdr));
1357 hdr.PageVersion = MPI_SASENCLOSURE0_PAGEVERSION; 1357 hdr.PageVersion = MPI_SASENCLOSURE0_PAGEVERSION;
1358 hdr.PageNumber = 0; 1358 hdr.PageNumber = 0;
1359 hdr.PageType = MPI_CONFIG_PAGETYPE_EXTENDED; 1359 hdr.PageType = MPI_CONFIG_PAGETYPE_EXTENDED;
1360 hdr.ExtPageType = MPI_CONFIG_EXTPAGETYPE_ENCLOSURE; 1360 hdr.ExtPageType = MPI_CONFIG_EXTPAGETYPE_ENCLOSURE;
1361 1361
1362 cfg.cfghdr.ehdr = &hdr; 1362 cfg.cfghdr.ehdr = &hdr;
1363 cfg.physAddr = -1; 1363 cfg.physAddr = -1;
1364 cfg.pageAddr = form + form_specific; 1364 cfg.pageAddr = form + form_specific;
1365 cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER; 1365 cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
1366 cfg.dir = 0; /* read */ 1366 cfg.dir = 0; /* read */
1367 cfg.timeout = SAS_CONFIG_PAGE_TIMEOUT; 1367 cfg.timeout = SAS_CONFIG_PAGE_TIMEOUT;
1368 1368
1369 error = mpt_config(ioc, &cfg); 1369 error = mpt_config(ioc, &cfg);
1370 if (error) 1370 if (error)
1371 goto out; 1371 goto out;
1372 if (!hdr.ExtPageLength) { 1372 if (!hdr.ExtPageLength) {
1373 error = -ENXIO; 1373 error = -ENXIO;
1374 goto out; 1374 goto out;
1375 } 1375 }
1376 1376
1377 buffer = pci_alloc_consistent(ioc->pcidev, hdr.ExtPageLength * 4, 1377 buffer = pci_alloc_consistent(ioc->pcidev, hdr.ExtPageLength * 4,
1378 &dma_handle); 1378 &dma_handle);
1379 if (!buffer) { 1379 if (!buffer) {
1380 error = -ENOMEM; 1380 error = -ENOMEM;
1381 goto out; 1381 goto out;
1382 } 1382 }
1383 1383
1384 cfg.physAddr = dma_handle; 1384 cfg.physAddr = dma_handle;
1385 cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT; 1385 cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
1386 1386
1387 error = mpt_config(ioc, &cfg); 1387 error = mpt_config(ioc, &cfg);
1388 if (error) 1388 if (error)
1389 goto out_free_consistent; 1389 goto out_free_consistent;
1390 1390
1391 /* save config data */ 1391 /* save config data */
1392 memcpy(&le_identifier, &buffer->EnclosureLogicalID, sizeof(__le64)); 1392 memcpy(&le_identifier, &buffer->EnclosureLogicalID, sizeof(__le64));
1393 enclosure->enclosure_logical_id = le64_to_cpu(le_identifier); 1393 enclosure->enclosure_logical_id = le64_to_cpu(le_identifier);
1394 enclosure->enclosure_handle = le16_to_cpu(buffer->EnclosureHandle); 1394 enclosure->enclosure_handle = le16_to_cpu(buffer->EnclosureHandle);
1395 enclosure->flags = le16_to_cpu(buffer->Flags); 1395 enclosure->flags = le16_to_cpu(buffer->Flags);
1396 enclosure->num_slot = le16_to_cpu(buffer->NumSlots); 1396 enclosure->num_slot = le16_to_cpu(buffer->NumSlots);
1397 enclosure->start_slot = le16_to_cpu(buffer->StartSlot); 1397 enclosure->start_slot = le16_to_cpu(buffer->StartSlot);
1398 enclosure->start_id = buffer->StartTargetID; 1398 enclosure->start_id = buffer->StartTargetID;
1399 enclosure->start_channel = buffer->StartBus; 1399 enclosure->start_channel = buffer->StartBus;
1400 enclosure->sep_id = buffer->SEPTargetID; 1400 enclosure->sep_id = buffer->SEPTargetID;
1401 enclosure->sep_channel = buffer->SEPBus; 1401 enclosure->sep_channel = buffer->SEPBus;
1402 1402
1403 out_free_consistent: 1403 out_free_consistent:
1404 pci_free_consistent(ioc->pcidev, hdr.ExtPageLength * 4, 1404 pci_free_consistent(ioc->pcidev, hdr.ExtPageLength * 4,
1405 buffer, dma_handle); 1405 buffer, dma_handle);
1406 out: 1406 out:
1407 return error; 1407 return error;
1408 } 1408 }
1409 1409
1410 /** 1410 /**
1411 * mptsas_add_end_device - report a new end device to sas transport layer 1411 * mptsas_add_end_device - report a new end device to sas transport layer
1412 * @ioc: Pointer to MPT_ADAPTER structure 1412 * @ioc: Pointer to MPT_ADAPTER structure
1413 * @phy_info: describes attached device 1413 * @phy_info: describes attached device
1414 * 1414 *
1415 * return (0) success (1) failure 1415 * return (0) success (1) failure
1416 * 1416 *
1417 **/ 1417 **/
1418 static int 1418 static int
1419 mptsas_add_end_device(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info) 1419 mptsas_add_end_device(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info)
1420 { 1420 {
1421 struct sas_rphy *rphy; 1421 struct sas_rphy *rphy;
1422 struct sas_port *port; 1422 struct sas_port *port;
1423 struct sas_identify identify; 1423 struct sas_identify identify;
1424 char *ds = NULL; 1424 char *ds = NULL;
1425 u8 fw_id; 1425 u8 fw_id;
1426 1426
1427 if (!phy_info) { 1427 if (!phy_info) {
1428 dfailprintk(ioc, printk(MYIOC_s_ERR_FMT 1428 dfailprintk(ioc, printk(MYIOC_s_ERR_FMT
1429 "%s: exit at line=%d\n", ioc->name, 1429 "%s: exit at line=%d\n", ioc->name,
1430 __func__, __LINE__)); 1430 __func__, __LINE__));
1431 return 1; 1431 return 1;
1432 } 1432 }
1433 1433
1434 fw_id = phy_info->attached.id; 1434 fw_id = phy_info->attached.id;
1435 1435
1436 if (mptsas_get_rphy(phy_info)) { 1436 if (mptsas_get_rphy(phy_info)) {
1437 dfailprintk(ioc, printk(MYIOC_s_ERR_FMT 1437 dfailprintk(ioc, printk(MYIOC_s_ERR_FMT
1438 "%s: fw_id=%d exit at line=%d\n", ioc->name, 1438 "%s: fw_id=%d exit at line=%d\n", ioc->name,
1439 __func__, fw_id, __LINE__)); 1439 __func__, fw_id, __LINE__));
1440 return 2; 1440 return 2;
1441 } 1441 }
1442 1442
1443 port = mptsas_get_port(phy_info); 1443 port = mptsas_get_port(phy_info);
1444 if (!port) { 1444 if (!port) {
1445 dfailprintk(ioc, printk(MYIOC_s_ERR_FMT 1445 dfailprintk(ioc, printk(MYIOC_s_ERR_FMT
1446 "%s: fw_id=%d exit at line=%d\n", ioc->name, 1446 "%s: fw_id=%d exit at line=%d\n", ioc->name,
1447 __func__, fw_id, __LINE__)); 1447 __func__, fw_id, __LINE__));
1448 return 3; 1448 return 3;
1449 } 1449 }
1450 1450
1451 if (phy_info->attached.device_info & 1451 if (phy_info->attached.device_info &
1452 MPI_SAS_DEVICE_INFO_SSP_TARGET) 1452 MPI_SAS_DEVICE_INFO_SSP_TARGET)
1453 ds = "ssp"; 1453 ds = "ssp";
1454 if (phy_info->attached.device_info & 1454 if (phy_info->attached.device_info &
1455 MPI_SAS_DEVICE_INFO_STP_TARGET) 1455 MPI_SAS_DEVICE_INFO_STP_TARGET)
1456 ds = "stp"; 1456 ds = "stp";
1457 if (phy_info->attached.device_info & 1457 if (phy_info->attached.device_info &
1458 MPI_SAS_DEVICE_INFO_SATA_DEVICE) 1458 MPI_SAS_DEVICE_INFO_SATA_DEVICE)
1459 ds = "sata"; 1459 ds = "sata";
1460 1460
1461 printk(MYIOC_s_INFO_FMT "attaching %s device: fw_channel %d, fw_id %d," 1461 printk(MYIOC_s_INFO_FMT "attaching %s device: fw_channel %d, fw_id %d,"
1462 " phy %d, sas_addr 0x%llx\n", ioc->name, ds, 1462 " phy %d, sas_addr 0x%llx\n", ioc->name, ds,
1463 phy_info->attached.channel, phy_info->attached.id, 1463 phy_info->attached.channel, phy_info->attached.id,
1464 phy_info->attached.phy_id, (unsigned long long) 1464 phy_info->attached.phy_id, (unsigned long long)
1465 phy_info->attached.sas_address); 1465 phy_info->attached.sas_address);
1466 1466
1467 mptsas_parse_device_info(&identify, &phy_info->attached); 1467 mptsas_parse_device_info(&identify, &phy_info->attached);
1468 rphy = sas_end_device_alloc(port); 1468 rphy = sas_end_device_alloc(port);
1469 if (!rphy) { 1469 if (!rphy) {
1470 dfailprintk(ioc, printk(MYIOC_s_ERR_FMT 1470 dfailprintk(ioc, printk(MYIOC_s_ERR_FMT
1471 "%s: fw_id=%d exit at line=%d\n", ioc->name, 1471 "%s: fw_id=%d exit at line=%d\n", ioc->name,
1472 __func__, fw_id, __LINE__)); 1472 __func__, fw_id, __LINE__));
1473 return 5; /* non-fatal: an rphy can be added later */ 1473 return 5; /* non-fatal: an rphy can be added later */
1474 } 1474 }
1475 1475
1476 rphy->identify = identify; 1476 rphy->identify = identify;
1477 if (sas_rphy_add(rphy)) { 1477 if (sas_rphy_add(rphy)) {
1478 dfailprintk(ioc, printk(MYIOC_s_ERR_FMT 1478 dfailprintk(ioc, printk(MYIOC_s_ERR_FMT
1479 "%s: fw_id=%d exit at line=%d\n", ioc->name, 1479 "%s: fw_id=%d exit at line=%d\n", ioc->name,
1480 __func__, fw_id, __LINE__)); 1480 __func__, fw_id, __LINE__));
1481 sas_rphy_free(rphy); 1481 sas_rphy_free(rphy);
1482 return 6; 1482 return 6;
1483 } 1483 }
1484 mptsas_set_rphy(ioc, phy_info, rphy); 1484 mptsas_set_rphy(ioc, phy_info, rphy);
1485 return 0; 1485 return 0;
1486 } 1486 }
1487 1487
1488 /** 1488 /**
1489 * mptsas_del_end_device - report a deleted end device to sas transport layer 1489 * mptsas_del_end_device - report a deleted end device to sas transport layer
1490 * @ioc: Pointer to MPT_ADAPTER structure 1490 * @ioc: Pointer to MPT_ADAPTER structure
1491 * @phy_info: describes attached device 1491 * @phy_info: describes attached device
1492 * 1492 *
1493 **/ 1493 **/
1494 static void 1494 static void
1495 mptsas_del_end_device(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info) 1495 mptsas_del_end_device(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info)
1496 { 1496 {
1497 struct sas_rphy *rphy; 1497 struct sas_rphy *rphy;
1498 struct sas_port *port; 1498 struct sas_port *port;
1499 struct mptsas_portinfo *port_info; 1499 struct mptsas_portinfo *port_info;
1500 struct mptsas_phyinfo *phy_info_parent; 1500 struct mptsas_phyinfo *phy_info_parent;
1501 int i; 1501 int i;
1502 char *ds = NULL; 1502 char *ds = NULL;
1503 u8 fw_id; 1503 u8 fw_id;
1504 u64 sas_address; 1504 u64 sas_address;
1505 1505
1506 if (!phy_info) 1506 if (!phy_info)
1507 return; 1507 return;
1508 1508
1509 fw_id = phy_info->attached.id; 1509 fw_id = phy_info->attached.id;
1510 sas_address = phy_info->attached.sas_address; 1510 sas_address = phy_info->attached.sas_address;
1511 1511
1512 if (!phy_info->port_details) { 1512 if (!phy_info->port_details) {
1513 dfailprintk(ioc, printk(MYIOC_s_ERR_FMT 1513 dfailprintk(ioc, printk(MYIOC_s_ERR_FMT
1514 "%s: fw_id=%d exit at line=%d\n", ioc->name, 1514 "%s: fw_id=%d exit at line=%d\n", ioc->name,
1515 __func__, fw_id, __LINE__)); 1515 __func__, fw_id, __LINE__));
1516 return; 1516 return;
1517 } 1517 }
1518 rphy = mptsas_get_rphy(phy_info); 1518 rphy = mptsas_get_rphy(phy_info);
1519 if (!rphy) { 1519 if (!rphy) {
1520 dfailprintk(ioc, printk(MYIOC_s_ERR_FMT 1520 dfailprintk(ioc, printk(MYIOC_s_ERR_FMT
1521 "%s: fw_id=%d exit at line=%d\n", ioc->name, 1521 "%s: fw_id=%d exit at line=%d\n", ioc->name,
1522 __func__, fw_id, __LINE__)); 1522 __func__, fw_id, __LINE__));
1523 return; 1523 return;
1524 } 1524 }
1525 1525
1526 if (phy_info->attached.device_info & MPI_SAS_DEVICE_INFO_SSP_INITIATOR 1526 if (phy_info->attached.device_info & MPI_SAS_DEVICE_INFO_SSP_INITIATOR
1527 || phy_info->attached.device_info 1527 || phy_info->attached.device_info
1528 & MPI_SAS_DEVICE_INFO_SMP_INITIATOR 1528 & MPI_SAS_DEVICE_INFO_SMP_INITIATOR
1529 || phy_info->attached.device_info 1529 || phy_info->attached.device_info
1530 & MPI_SAS_DEVICE_INFO_STP_INITIATOR) 1530 & MPI_SAS_DEVICE_INFO_STP_INITIATOR)
1531 ds = "initiator"; 1531 ds = "initiator";
1532 if (phy_info->attached.device_info & 1532 if (phy_info->attached.device_info &
1533 MPI_SAS_DEVICE_INFO_SSP_TARGET) 1533 MPI_SAS_DEVICE_INFO_SSP_TARGET)
1534 ds = "ssp"; 1534 ds = "ssp";
1535 if (phy_info->attached.device_info & 1535 if (phy_info->attached.device_info &
1536 MPI_SAS_DEVICE_INFO_STP_TARGET) 1536 MPI_SAS_DEVICE_INFO_STP_TARGET)
1537 ds = "stp"; 1537 ds = "stp";
1538 if (phy_info->attached.device_info & 1538 if (phy_info->attached.device_info &
1539 MPI_SAS_DEVICE_INFO_SATA_DEVICE) 1539 MPI_SAS_DEVICE_INFO_SATA_DEVICE)
1540 ds = "sata"; 1540 ds = "sata";
1541 1541
1542 dev_printk(KERN_DEBUG, &rphy->dev, MYIOC_s_FMT 1542 dev_printk(KERN_DEBUG, &rphy->dev, MYIOC_s_FMT
1543 "removing %s device: fw_channel %d, fw_id %d, phy %d," 1543 "removing %s device: fw_channel %d, fw_id %d, phy %d,"
1544 "sas_addr 0x%llx\n", ioc->name, ds, phy_info->attached.channel, 1544 "sas_addr 0x%llx\n", ioc->name, ds, phy_info->attached.channel,
1545 phy_info->attached.id, phy_info->attached.phy_id, 1545 phy_info->attached.id, phy_info->attached.phy_id,
1546 (unsigned long long) sas_address); 1546 (unsigned long long) sas_address);
1547 1547
1548 port = mptsas_get_port(phy_info); 1548 port = mptsas_get_port(phy_info);
1549 if (!port) { 1549 if (!port) {
1550 dfailprintk(ioc, printk(MYIOC_s_ERR_FMT 1550 dfailprintk(ioc, printk(MYIOC_s_ERR_FMT
1551 "%s: fw_id=%d exit at line=%d\n", ioc->name, 1551 "%s: fw_id=%d exit at line=%d\n", ioc->name,
1552 __func__, fw_id, __LINE__)); 1552 __func__, fw_id, __LINE__));
1553 return; 1553 return;
1554 } 1554 }
1555 port_info = phy_info->portinfo; 1555 port_info = phy_info->portinfo;
1556 phy_info_parent = port_info->phy_info; 1556 phy_info_parent = port_info->phy_info;
1557 for (i = 0; i < port_info->num_phys; i++, phy_info_parent++) { 1557 for (i = 0; i < port_info->num_phys; i++, phy_info_parent++) {
1558 if (!phy_info_parent->phy) 1558 if (!phy_info_parent->phy)
1559 continue; 1559 continue;
1560 if (phy_info_parent->attached.sas_address != 1560 if (phy_info_parent->attached.sas_address !=
1561 sas_address) 1561 sas_address)
1562 continue; 1562 continue;
1563 dev_printk(KERN_DEBUG, &phy_info_parent->phy->dev, 1563 dev_printk(KERN_DEBUG, &phy_info_parent->phy->dev,
1564 MYIOC_s_FMT "delete phy %d, phy-obj (0x%p)\n", 1564 MYIOC_s_FMT "delete phy %d, phy-obj (0x%p)\n",
1565 ioc->name, phy_info_parent->phy_id, 1565 ioc->name, phy_info_parent->phy_id,
1566 phy_info_parent->phy); 1566 phy_info_parent->phy);
1567 sas_port_delete_phy(port, phy_info_parent->phy); 1567 sas_port_delete_phy(port, phy_info_parent->phy);
1568 } 1568 }
1569 1569
1570 dev_printk(KERN_DEBUG, &port->dev, MYIOC_s_FMT 1570 dev_printk(KERN_DEBUG, &port->dev, MYIOC_s_FMT
1571 "delete port %d, sas_addr (0x%llx)\n", ioc->name, 1571 "delete port %d, sas_addr (0x%llx)\n", ioc->name,
1572 port->port_identifier, (unsigned long long)sas_address); 1572 port->port_identifier, (unsigned long long)sas_address);
1573 sas_port_delete(port); 1573 sas_port_delete(port);
1574 mptsas_set_port(ioc, phy_info, NULL); 1574 mptsas_set_port(ioc, phy_info, NULL);
1575 mptsas_port_delete(ioc, phy_info->port_details); 1575 mptsas_port_delete(ioc, phy_info->port_details);
1576 } 1576 }
1577 1577
1578 struct mptsas_phyinfo * 1578 struct mptsas_phyinfo *
1579 mptsas_refreshing_device_handles(MPT_ADAPTER *ioc, 1579 mptsas_refreshing_device_handles(MPT_ADAPTER *ioc,
1580 struct mptsas_devinfo *sas_device) 1580 struct mptsas_devinfo *sas_device)
1581 { 1581 {
1582 struct mptsas_phyinfo *phy_info; 1582 struct mptsas_phyinfo *phy_info;
1583 struct mptsas_portinfo *port_info; 1583 struct mptsas_portinfo *port_info;
1584 int i; 1584 int i;
1585 1585
1586 phy_info = mptsas_find_phyinfo_by_sas_address(ioc, 1586 phy_info = mptsas_find_phyinfo_by_sas_address(ioc,
1587 sas_device->sas_address); 1587 sas_device->sas_address);
1588 if (!phy_info) 1588 if (!phy_info)
1589 goto out; 1589 goto out;
1590 port_info = phy_info->portinfo; 1590 port_info = phy_info->portinfo;
1591 if (!port_info) 1591 if (!port_info)
1592 goto out; 1592 goto out;
1593 mutex_lock(&ioc->sas_topology_mutex); 1593 mutex_lock(&ioc->sas_topology_mutex);
1594 for (i = 0; i < port_info->num_phys; i++) { 1594 for (i = 0; i < port_info->num_phys; i++) {
1595 if (port_info->phy_info[i].attached.sas_address != 1595 if (port_info->phy_info[i].attached.sas_address !=
1596 sas_device->sas_address) 1596 sas_device->sas_address)
1597 continue; 1597 continue;
1598 port_info->phy_info[i].attached.channel = sas_device->channel; 1598 port_info->phy_info[i].attached.channel = sas_device->channel;
1599 port_info->phy_info[i].attached.id = sas_device->id; 1599 port_info->phy_info[i].attached.id = sas_device->id;
1600 port_info->phy_info[i].attached.sas_address = 1600 port_info->phy_info[i].attached.sas_address =
1601 sas_device->sas_address; 1601 sas_device->sas_address;
1602 port_info->phy_info[i].attached.handle = sas_device->handle; 1602 port_info->phy_info[i].attached.handle = sas_device->handle;
1603 port_info->phy_info[i].attached.handle_parent = 1603 port_info->phy_info[i].attached.handle_parent =
1604 sas_device->handle_parent; 1604 sas_device->handle_parent;
1605 port_info->phy_info[i].attached.handle_enclosure = 1605 port_info->phy_info[i].attached.handle_enclosure =
1606 sas_device->handle_enclosure; 1606 sas_device->handle_enclosure;
1607 } 1607 }
1608 mutex_unlock(&ioc->sas_topology_mutex); 1608 mutex_unlock(&ioc->sas_topology_mutex);
1609 out: 1609 out:
1610 return phy_info; 1610 return phy_info;
1611 } 1611 }
1612 1612
1613 /** 1613 /**
1614 * mptsas_firmware_event_work - work thread for processing fw events 1614 * mptsas_firmware_event_work - work thread for processing fw events
1615 * @work: work queue payload containing info describing the event 1615 * @work: work queue payload containing info describing the event
1616 * Context: user 1616 * Context: user
1617 * 1617 *
1618 */ 1618 */
1619 static void 1619 static void
1620 mptsas_firmware_event_work(struct work_struct *work) 1620 mptsas_firmware_event_work(struct work_struct *work)
1621 { 1621 {
1622 struct fw_event_work *fw_event = 1622 struct fw_event_work *fw_event =
1623 container_of(work, struct fw_event_work, work.work); 1623 container_of(work, struct fw_event_work, work.work);
1624 MPT_ADAPTER *ioc = fw_event->ioc; 1624 MPT_ADAPTER *ioc = fw_event->ioc;
1625 1625
1626 /* special rescan topology handling */ 1626 /* special rescan topology handling */
1627 if (fw_event->event == -1) { 1627 if (fw_event->event == -1) {
1628 if (ioc->in_rescan) { 1628 if (ioc->in_rescan) {
1629 devtprintk(ioc, printk(MYIOC_s_DEBUG_FMT 1629 devtprintk(ioc, printk(MYIOC_s_DEBUG_FMT
1630 "%s: rescan ignored as it is in progress\n", 1630 "%s: rescan ignored as it is in progress\n",
1631 ioc->name, __func__)); 1631 ioc->name, __func__));
1632 return; 1632 return;
1633 } 1633 }
1634 devtprintk(ioc, printk(MYIOC_s_DEBUG_FMT "%s: rescan after " 1634 devtprintk(ioc, printk(MYIOC_s_DEBUG_FMT "%s: rescan after "
1635 "reset\n", ioc->name, __func__)); 1635 "reset\n", ioc->name, __func__));
1636 ioc->in_rescan = 1; 1636 ioc->in_rescan = 1;
1637 mptsas_not_responding_devices(ioc); 1637 mptsas_not_responding_devices(ioc);
1638 mptsas_scan_sas_topology(ioc); 1638 mptsas_scan_sas_topology(ioc);
1639 ioc->in_rescan = 0; 1639 ioc->in_rescan = 0;
1640 mptsas_free_fw_event(ioc, fw_event); 1640 mptsas_free_fw_event(ioc, fw_event);
1641 mptsas_fw_event_on(ioc); 1641 mptsas_fw_event_on(ioc);
1642 return; 1642 return;
1643 } 1643 }
1644 1644
1645 /* events handling turned off during host reset */ 1645 /* events handling turned off during host reset */
1646 if (ioc->fw_events_off) { 1646 if (ioc->fw_events_off) {
1647 mptsas_free_fw_event(ioc, fw_event); 1647 mptsas_free_fw_event(ioc, fw_event);
1648 return; 1648 return;
1649 } 1649 }
1650 1650
1651 devtprintk(ioc, printk(MYIOC_s_DEBUG_FMT "%s: fw_event=(0x%p), " 1651 devtprintk(ioc, printk(MYIOC_s_DEBUG_FMT "%s: fw_event=(0x%p), "
1652 "event = (0x%02x)\n", ioc->name, __func__, fw_event, 1652 "event = (0x%02x)\n", ioc->name, __func__, fw_event,
1653 (fw_event->event & 0xFF))); 1653 (fw_event->event & 0xFF)));
1654 1654
1655 switch (fw_event->event) { 1655 switch (fw_event->event) {
1656 case MPI_EVENT_SAS_DEVICE_STATUS_CHANGE: 1656 case MPI_EVENT_SAS_DEVICE_STATUS_CHANGE:
1657 mptsas_send_sas_event(fw_event); 1657 mptsas_send_sas_event(fw_event);
1658 break; 1658 break;
1659 case MPI_EVENT_INTEGRATED_RAID: 1659 case MPI_EVENT_INTEGRATED_RAID:
1660 mptsas_send_raid_event(fw_event); 1660 mptsas_send_raid_event(fw_event);
1661 break; 1661 break;
1662 case MPI_EVENT_IR2: 1662 case MPI_EVENT_IR2:
1663 mptsas_send_ir2_event(fw_event); 1663 mptsas_send_ir2_event(fw_event);
1664 break; 1664 break;
1665 case MPI_EVENT_PERSISTENT_TABLE_FULL: 1665 case MPI_EVENT_PERSISTENT_TABLE_FULL:
1666 mptbase_sas_persist_operation(ioc, 1666 mptbase_sas_persist_operation(ioc,
1667 MPI_SAS_OP_CLEAR_NOT_PRESENT); 1667 MPI_SAS_OP_CLEAR_NOT_PRESENT);
1668 mptsas_free_fw_event(ioc, fw_event); 1668 mptsas_free_fw_event(ioc, fw_event);
1669 break; 1669 break;
1670 case MPI_EVENT_SAS_BROADCAST_PRIMITIVE: 1670 case MPI_EVENT_SAS_BROADCAST_PRIMITIVE:
1671 mptsas_broadcast_primative_work(fw_event); 1671 mptsas_broadcast_primative_work(fw_event);
1672 break; 1672 break;
1673 case MPI_EVENT_SAS_EXPANDER_STATUS_CHANGE: 1673 case MPI_EVENT_SAS_EXPANDER_STATUS_CHANGE:
1674 mptsas_send_expander_event(fw_event); 1674 mptsas_send_expander_event(fw_event);
1675 break; 1675 break;
1676 case MPI_EVENT_SAS_PHY_LINK_STATUS: 1676 case MPI_EVENT_SAS_PHY_LINK_STATUS:
1677 mptsas_send_link_status_event(fw_event); 1677 mptsas_send_link_status_event(fw_event);
1678 break; 1678 break;
1679 case MPI_EVENT_QUEUE_FULL: 1679 case MPI_EVENT_QUEUE_FULL:
1680 mptsas_handle_queue_full_event(fw_event); 1680 mptsas_handle_queue_full_event(fw_event);
1681 break; 1681 break;
1682 } 1682 }
1683 } 1683 }
1684 1684
1685 1685
1686 1686
1687 static int 1687 static int
1688 mptsas_slave_configure(struct scsi_device *sdev) 1688 mptsas_slave_configure(struct scsi_device *sdev)
1689 { 1689 {
1690 struct Scsi_Host *host = sdev->host; 1690 struct Scsi_Host *host = sdev->host;
1691 MPT_SCSI_HOST *hd = shost_priv(host); 1691 MPT_SCSI_HOST *hd = shost_priv(host);
1692 MPT_ADAPTER *ioc = hd->ioc; 1692 MPT_ADAPTER *ioc = hd->ioc;
1693 VirtDevice *vdevice = sdev->hostdata; 1693 VirtDevice *vdevice = sdev->hostdata;
1694 1694
1695 if (vdevice->vtarget->deleted) { 1695 if (vdevice->vtarget->deleted) {
1696 sdev_printk(KERN_INFO, sdev, "clearing deleted flag\n"); 1696 sdev_printk(KERN_INFO, sdev, "clearing deleted flag\n");
1697 vdevice->vtarget->deleted = 0; 1697 vdevice->vtarget->deleted = 0;
1698 } 1698 }
1699 1699
1700 /* 1700 /*
1701 * RAID volumes placed beyond the last expected port. 1701 * RAID volumes placed beyond the last expected port.
1702 * Ignore sending sas mode pages in that case.. 1702 * Ignore sending sas mode pages in that case..
1703 */ 1703 */
1704 if (sdev->channel == MPTSAS_RAID_CHANNEL) { 1704 if (sdev->channel == MPTSAS_RAID_CHANNEL) {
1705 mptsas_add_device_component_starget_ir(ioc, scsi_target(sdev)); 1705 mptsas_add_device_component_starget_ir(ioc, scsi_target(sdev));
1706 goto out; 1706 goto out;
1707 } 1707 }
1708 1708
1709 sas_read_port_mode_page(sdev); 1709 sas_read_port_mode_page(sdev);
1710 1710
1711 mptsas_add_device_component_starget(ioc, scsi_target(sdev)); 1711 mptsas_add_device_component_starget(ioc, scsi_target(sdev));
1712 1712
1713 out: 1713 out:
1714 return mptscsih_slave_configure(sdev); 1714 return mptscsih_slave_configure(sdev);
1715 } 1715 }
1716 1716
1717 static int 1717 static int
1718 mptsas_target_alloc(struct scsi_target *starget) 1718 mptsas_target_alloc(struct scsi_target *starget)
1719 { 1719 {
1720 struct Scsi_Host *host = dev_to_shost(&starget->dev); 1720 struct Scsi_Host *host = dev_to_shost(&starget->dev);
1721 MPT_SCSI_HOST *hd = shost_priv(host); 1721 MPT_SCSI_HOST *hd = shost_priv(host);
1722 VirtTarget *vtarget; 1722 VirtTarget *vtarget;
1723 u8 id, channel; 1723 u8 id, channel;
1724 struct sas_rphy *rphy; 1724 struct sas_rphy *rphy;
1725 struct mptsas_portinfo *p; 1725 struct mptsas_portinfo *p;
1726 int i; 1726 int i;
1727 MPT_ADAPTER *ioc = hd->ioc; 1727 MPT_ADAPTER *ioc = hd->ioc;
1728 1728
1729 vtarget = kzalloc(sizeof(VirtTarget), GFP_KERNEL); 1729 vtarget = kzalloc(sizeof(VirtTarget), GFP_KERNEL);
1730 if (!vtarget) 1730 if (!vtarget)
1731 return -ENOMEM; 1731 return -ENOMEM;
1732 1732
1733 vtarget->starget = starget; 1733 vtarget->starget = starget;
1734 vtarget->ioc_id = ioc->id; 1734 vtarget->ioc_id = ioc->id;
1735 vtarget->tflags = MPT_TARGET_FLAGS_Q_YES; 1735 vtarget->tflags = MPT_TARGET_FLAGS_Q_YES;
1736 id = starget->id; 1736 id = starget->id;
1737 channel = 0; 1737 channel = 0;
1738 1738
1739 /* 1739 /*
1740 * RAID volumes placed beyond the last expected port. 1740 * RAID volumes placed beyond the last expected port.
1741 */ 1741 */
1742 if (starget->channel == MPTSAS_RAID_CHANNEL) { 1742 if (starget->channel == MPTSAS_RAID_CHANNEL) {
1743 if (!ioc->raid_data.pIocPg2) { 1743 if (!ioc->raid_data.pIocPg2) {
1744 kfree(vtarget); 1744 kfree(vtarget);
1745 return -ENXIO; 1745 return -ENXIO;
1746 } 1746 }
1747 for (i = 0; i < ioc->raid_data.pIocPg2->NumActiveVolumes; i++) { 1747 for (i = 0; i < ioc->raid_data.pIocPg2->NumActiveVolumes; i++) {
1748 if (id == ioc->raid_data.pIocPg2-> 1748 if (id == ioc->raid_data.pIocPg2->
1749 RaidVolume[i].VolumeID) { 1749 RaidVolume[i].VolumeID) {
1750 channel = ioc->raid_data.pIocPg2-> 1750 channel = ioc->raid_data.pIocPg2->
1751 RaidVolume[i].VolumeBus; 1751 RaidVolume[i].VolumeBus;
1752 } 1752 }
1753 } 1753 }
1754 vtarget->raidVolume = 1; 1754 vtarget->raidVolume = 1;
1755 goto out; 1755 goto out;
1756 } 1756 }
1757 1757
1758 rphy = dev_to_rphy(starget->dev.parent); 1758 rphy = dev_to_rphy(starget->dev.parent);
1759 mutex_lock(&ioc->sas_topology_mutex); 1759 mutex_lock(&ioc->sas_topology_mutex);
1760 list_for_each_entry(p, &ioc->sas_topology, list) { 1760 list_for_each_entry(p, &ioc->sas_topology, list) {
1761 for (i = 0; i < p->num_phys; i++) { 1761 for (i = 0; i < p->num_phys; i++) {
1762 if (p->phy_info[i].attached.sas_address != 1762 if (p->phy_info[i].attached.sas_address !=
1763 rphy->identify.sas_address) 1763 rphy->identify.sas_address)
1764 continue; 1764 continue;
1765 id = p->phy_info[i].attached.id; 1765 id = p->phy_info[i].attached.id;
1766 channel = p->phy_info[i].attached.channel; 1766 channel = p->phy_info[i].attached.channel;
1767 mptsas_set_starget(&p->phy_info[i], starget); 1767 mptsas_set_starget(&p->phy_info[i], starget);
1768 1768
1769 /* 1769 /*
1770 * Exposing hidden raid components 1770 * Exposing hidden raid components
1771 */ 1771 */
1772 if (mptscsih_is_phys_disk(ioc, channel, id)) { 1772 if (mptscsih_is_phys_disk(ioc, channel, id)) {
1773 id = mptscsih_raid_id_to_num(ioc, 1773 id = mptscsih_raid_id_to_num(ioc,
1774 channel, id); 1774 channel, id);
1775 vtarget->tflags |= 1775 vtarget->tflags |=
1776 MPT_TARGET_FLAGS_RAID_COMPONENT; 1776 MPT_TARGET_FLAGS_RAID_COMPONENT;
1777 p->phy_info[i].attached.phys_disk_num = id; 1777 p->phy_info[i].attached.phys_disk_num = id;
1778 } 1778 }
1779 mutex_unlock(&ioc->sas_topology_mutex); 1779 mutex_unlock(&ioc->sas_topology_mutex);
1780 goto out; 1780 goto out;
1781 } 1781 }
1782 } 1782 }
1783 mutex_unlock(&ioc->sas_topology_mutex); 1783 mutex_unlock(&ioc->sas_topology_mutex);
1784 1784
1785 kfree(vtarget); 1785 kfree(vtarget);
1786 return -ENXIO; 1786 return -ENXIO;
1787 1787
1788 out: 1788 out:
1789 vtarget->id = id; 1789 vtarget->id = id;
1790 vtarget->channel = channel; 1790 vtarget->channel = channel;
1791 starget->hostdata = vtarget; 1791 starget->hostdata = vtarget;
1792 return 0; 1792 return 0;
1793 } 1793 }
1794 1794
1795 static void 1795 static void
1796 mptsas_target_destroy(struct scsi_target *starget) 1796 mptsas_target_destroy(struct scsi_target *starget)
1797 { 1797 {
1798 struct Scsi_Host *host = dev_to_shost(&starget->dev); 1798 struct Scsi_Host *host = dev_to_shost(&starget->dev);
1799 MPT_SCSI_HOST *hd = shost_priv(host); 1799 MPT_SCSI_HOST *hd = shost_priv(host);
1800 struct sas_rphy *rphy; 1800 struct sas_rphy *rphy;
1801 struct mptsas_portinfo *p; 1801 struct mptsas_portinfo *p;
1802 int i; 1802 int i;
1803 MPT_ADAPTER *ioc = hd->ioc; 1803 MPT_ADAPTER *ioc = hd->ioc;
1804 VirtTarget *vtarget; 1804 VirtTarget *vtarget;
1805 1805
1806 if (!starget->hostdata) 1806 if (!starget->hostdata)
1807 return; 1807 return;
1808 1808
1809 vtarget = starget->hostdata; 1809 vtarget = starget->hostdata;
1810 1810
1811 mptsas_del_device_component_by_os(ioc, starget->channel, 1811 mptsas_del_device_component_by_os(ioc, starget->channel,
1812 starget->id); 1812 starget->id);
1813 1813
1814 1814
1815 if (starget->channel == MPTSAS_RAID_CHANNEL) 1815 if (starget->channel == MPTSAS_RAID_CHANNEL)
1816 goto out; 1816 goto out;
1817 1817
1818 rphy = dev_to_rphy(starget->dev.parent); 1818 rphy = dev_to_rphy(starget->dev.parent);
1819 list_for_each_entry(p, &ioc->sas_topology, list) { 1819 list_for_each_entry(p, &ioc->sas_topology, list) {
1820 for (i = 0; i < p->num_phys; i++) { 1820 for (i = 0; i < p->num_phys; i++) {
1821 if (p->phy_info[i].attached.sas_address != 1821 if (p->phy_info[i].attached.sas_address !=
1822 rphy->identify.sas_address) 1822 rphy->identify.sas_address)
1823 continue; 1823 continue;
1824 1824
1825 starget_printk(KERN_INFO, starget, MYIOC_s_FMT 1825 starget_printk(KERN_INFO, starget, MYIOC_s_FMT
1826 "delete device: fw_channel %d, fw_id %d, phy %d, " 1826 "delete device: fw_channel %d, fw_id %d, phy %d, "
1827 "sas_addr 0x%llx\n", ioc->name, 1827 "sas_addr 0x%llx\n", ioc->name,
1828 p->phy_info[i].attached.channel, 1828 p->phy_info[i].attached.channel,
1829 p->phy_info[i].attached.id, 1829 p->phy_info[i].attached.id,
1830 p->phy_info[i].attached.phy_id, (unsigned long long) 1830 p->phy_info[i].attached.phy_id, (unsigned long long)
1831 p->phy_info[i].attached.sas_address); 1831 p->phy_info[i].attached.sas_address);
1832 1832
1833 mptsas_set_starget(&p->phy_info[i], NULL); 1833 mptsas_set_starget(&p->phy_info[i], NULL);
1834 } 1834 }
1835 } 1835 }
1836 1836
1837 out: 1837 out:
1838 vtarget->starget = NULL; 1838 vtarget->starget = NULL;
1839 kfree(starget->hostdata); 1839 kfree(starget->hostdata);
1840 starget->hostdata = NULL; 1840 starget->hostdata = NULL;
1841 } 1841 }
1842 1842
1843 1843
1844 static int 1844 static int
1845 mptsas_slave_alloc(struct scsi_device *sdev) 1845 mptsas_slave_alloc(struct scsi_device *sdev)
1846 { 1846 {
1847 struct Scsi_Host *host = sdev->host; 1847 struct Scsi_Host *host = sdev->host;
1848 MPT_SCSI_HOST *hd = shost_priv(host); 1848 MPT_SCSI_HOST *hd = shost_priv(host);
1849 struct sas_rphy *rphy; 1849 struct sas_rphy *rphy;
1850 struct mptsas_portinfo *p; 1850 struct mptsas_portinfo *p;
1851 VirtDevice *vdevice; 1851 VirtDevice *vdevice;
1852 struct scsi_target *starget; 1852 struct scsi_target *starget;
1853 int i; 1853 int i;
1854 MPT_ADAPTER *ioc = hd->ioc; 1854 MPT_ADAPTER *ioc = hd->ioc;
1855 1855
1856 vdevice = kzalloc(sizeof(VirtDevice), GFP_KERNEL); 1856 vdevice = kzalloc(sizeof(VirtDevice), GFP_KERNEL);
1857 if (!vdevice) { 1857 if (!vdevice) {
1858 printk(MYIOC_s_ERR_FMT "slave_alloc kzalloc(%zd) FAILED!\n", 1858 printk(MYIOC_s_ERR_FMT "slave_alloc kzalloc(%zd) FAILED!\n",
1859 ioc->name, sizeof(VirtDevice)); 1859 ioc->name, sizeof(VirtDevice));
1860 return -ENOMEM; 1860 return -ENOMEM;
1861 } 1861 }
1862 starget = scsi_target(sdev); 1862 starget = scsi_target(sdev);
1863 vdevice->vtarget = starget->hostdata; 1863 vdevice->vtarget = starget->hostdata;
1864 1864
1865 if (sdev->channel == MPTSAS_RAID_CHANNEL) 1865 if (sdev->channel == MPTSAS_RAID_CHANNEL)
1866 goto out; 1866 goto out;
1867 1867
1868 rphy = dev_to_rphy(sdev->sdev_target->dev.parent); 1868 rphy = dev_to_rphy(sdev->sdev_target->dev.parent);
1869 mutex_lock(&ioc->sas_topology_mutex); 1869 mutex_lock(&ioc->sas_topology_mutex);
1870 list_for_each_entry(p, &ioc->sas_topology, list) { 1870 list_for_each_entry(p, &ioc->sas_topology, list) {
1871 for (i = 0; i < p->num_phys; i++) { 1871 for (i = 0; i < p->num_phys; i++) {
1872 if (p->phy_info[i].attached.sas_address != 1872 if (p->phy_info[i].attached.sas_address !=
1873 rphy->identify.sas_address) 1873 rphy->identify.sas_address)
1874 continue; 1874 continue;
1875 vdevice->lun = sdev->lun; 1875 vdevice->lun = sdev->lun;
1876 /* 1876 /*
1877 * Exposing hidden raid components 1877 * Exposing hidden raid components
1878 */ 1878 */
1879 if (mptscsih_is_phys_disk(ioc, 1879 if (mptscsih_is_phys_disk(ioc,
1880 p->phy_info[i].attached.channel, 1880 p->phy_info[i].attached.channel,
1881 p->phy_info[i].attached.id)) 1881 p->phy_info[i].attached.id))
1882 sdev->no_uld_attach = 1; 1882 sdev->no_uld_attach = 1;
1883 mutex_unlock(&ioc->sas_topology_mutex); 1883 mutex_unlock(&ioc->sas_topology_mutex);
1884 goto out; 1884 goto out;
1885 } 1885 }
1886 } 1886 }
1887 mutex_unlock(&ioc->sas_topology_mutex); 1887 mutex_unlock(&ioc->sas_topology_mutex);
1888 1888
1889 kfree(vdevice); 1889 kfree(vdevice);
1890 return -ENXIO; 1890 return -ENXIO;
1891 1891
1892 out: 1892 out:
1893 vdevice->vtarget->num_luns++; 1893 vdevice->vtarget->num_luns++;
1894 sdev->hostdata = vdevice; 1894 sdev->hostdata = vdevice;
1895 return 0; 1895 return 0;
1896 } 1896 }
1897 1897
1898 static int 1898 static int
1899 mptsas_qcmd_lck(struct scsi_cmnd *SCpnt, void (*done)(struct scsi_cmnd *)) 1899 mptsas_qcmd_lck(struct scsi_cmnd *SCpnt, void (*done)(struct scsi_cmnd *))
1900 { 1900 {
1901 MPT_SCSI_HOST *hd; 1901 MPT_SCSI_HOST *hd;
1902 MPT_ADAPTER *ioc; 1902 MPT_ADAPTER *ioc;
1903 VirtDevice *vdevice = SCpnt->device->hostdata; 1903 VirtDevice *vdevice = SCpnt->device->hostdata;
1904 1904
1905 if (!vdevice || !vdevice->vtarget || vdevice->vtarget->deleted) { 1905 if (!vdevice || !vdevice->vtarget || vdevice->vtarget->deleted) {
1906 SCpnt->result = DID_NO_CONNECT << 16; 1906 SCpnt->result = DID_NO_CONNECT << 16;
1907 done(SCpnt); 1907 done(SCpnt);
1908 return 0; 1908 return 0;
1909 } 1909 }
1910 1910
1911 hd = shost_priv(SCpnt->device->host); 1911 hd = shost_priv(SCpnt->device->host);
1912 ioc = hd->ioc; 1912 ioc = hd->ioc;
1913 1913
1914 if (ioc->sas_discovery_quiesce_io) 1914 if (ioc->sas_discovery_quiesce_io)
1915 return SCSI_MLQUEUE_HOST_BUSY; 1915 return SCSI_MLQUEUE_HOST_BUSY;
1916 1916
1917 if (ioc->debug_level & MPT_DEBUG_SCSI) 1917 if (ioc->debug_level & MPT_DEBUG_SCSI)
1918 scsi_print_command(SCpnt); 1918 scsi_print_command(SCpnt);
1919 1919
1920 return mptscsih_qcmd(SCpnt,done); 1920 return mptscsih_qcmd(SCpnt,done);
1921 } 1921 }
1922 1922
1923 static DEF_SCSI_QCMD(mptsas_qcmd) 1923 static DEF_SCSI_QCMD(mptsas_qcmd)
1924 1924
1925 /** 1925 /**
1926 * mptsas_mptsas_eh_timed_out - resets the scsi_cmnd timeout 1926 * mptsas_mptsas_eh_timed_out - resets the scsi_cmnd timeout
1927 * if the device under question is currently in the 1927 * if the device under question is currently in the
1928 * device removal delay. 1928 * device removal delay.
1929 * @sc: scsi command that the midlayer is about to time out 1929 * @sc: scsi command that the midlayer is about to time out
1930 * 1930 *
1931 **/ 1931 **/
1932 static enum blk_eh_timer_return mptsas_eh_timed_out(struct scsi_cmnd *sc) 1932 static enum blk_eh_timer_return mptsas_eh_timed_out(struct scsi_cmnd *sc)
1933 { 1933 {
1934 MPT_SCSI_HOST *hd; 1934 MPT_SCSI_HOST *hd;
1935 MPT_ADAPTER *ioc; 1935 MPT_ADAPTER *ioc;
1936 VirtDevice *vdevice; 1936 VirtDevice *vdevice;
1937 enum blk_eh_timer_return rc = BLK_EH_NOT_HANDLED; 1937 enum blk_eh_timer_return rc = BLK_EH_NOT_HANDLED;
1938 1938
1939 hd = shost_priv(sc->device->host); 1939 hd = shost_priv(sc->device->host);
1940 if (hd == NULL) { 1940 if (hd == NULL) {
1941 printk(KERN_ERR MYNAM ": %s: Can't locate host! (sc=%p)\n", 1941 printk(KERN_ERR MYNAM ": %s: Can't locate host! (sc=%p)\n",
1942 __func__, sc); 1942 __func__, sc);
1943 goto done; 1943 goto done;
1944 } 1944 }
1945 1945
1946 ioc = hd->ioc; 1946 ioc = hd->ioc;
1947 if (ioc->bus_type != SAS) { 1947 if (ioc->bus_type != SAS) {
1948 printk(KERN_ERR MYNAM ": %s: Wrong bus type (sc=%p)\n", 1948 printk(KERN_ERR MYNAM ": %s: Wrong bus type (sc=%p)\n",
1949 __func__, sc); 1949 __func__, sc);
1950 goto done; 1950 goto done;
1951 } 1951 }
1952 1952
1953 /* In case if IOC is in reset from internal context. 1953 /* In case if IOC is in reset from internal context.
1954 * Do not execute EEH for the same IOC. SML should to reset timer. 1954 * Do not execute EEH for the same IOC. SML should to reset timer.
1955 */ 1955 */
1956 if (ioc->ioc_reset_in_progress) { 1956 if (ioc->ioc_reset_in_progress) {
1957 dtmprintk(ioc, printk(MYIOC_s_WARN_FMT ": %s: ioc is in reset," 1957 dtmprintk(ioc, printk(MYIOC_s_WARN_FMT ": %s: ioc is in reset,"
1958 "SML need to reset the timer (sc=%p)\n", 1958 "SML need to reset the timer (sc=%p)\n",
1959 ioc->name, __func__, sc)); 1959 ioc->name, __func__, sc));
1960 rc = BLK_EH_RESET_TIMER; 1960 rc = BLK_EH_RESET_TIMER;
1961 } 1961 }
1962 vdevice = sc->device->hostdata; 1962 vdevice = sc->device->hostdata;
1963 if (vdevice && vdevice->vtarget && (vdevice->vtarget->inDMD 1963 if (vdevice && vdevice->vtarget && (vdevice->vtarget->inDMD
1964 || vdevice->vtarget->deleted)) { 1964 || vdevice->vtarget->deleted)) {
1965 dtmprintk(ioc, printk(MYIOC_s_WARN_FMT ": %s: target removed " 1965 dtmprintk(ioc, printk(MYIOC_s_WARN_FMT ": %s: target removed "
1966 "or in device removal delay (sc=%p)\n", 1966 "or in device removal delay (sc=%p)\n",
1967 ioc->name, __func__, sc)); 1967 ioc->name, __func__, sc));
1968 rc = BLK_EH_RESET_TIMER; 1968 rc = BLK_EH_RESET_TIMER;
1969 goto done; 1969 goto done;
1970 } 1970 }
1971 1971
1972 done: 1972 done:
1973 return rc; 1973 return rc;
1974 } 1974 }
1975 1975
1976 1976
1977 static struct scsi_host_template mptsas_driver_template = { 1977 static struct scsi_host_template mptsas_driver_template = {
1978 .module = THIS_MODULE, 1978 .module = THIS_MODULE,
1979 .proc_name = "mptsas", 1979 .proc_name = "mptsas",
1980 .proc_info = mptscsih_proc_info, 1980 .show_info = mptscsih_show_info,
1981 .name = "MPT SAS Host", 1981 .name = "MPT SAS Host",
1982 .info = mptscsih_info, 1982 .info = mptscsih_info,
1983 .queuecommand = mptsas_qcmd, 1983 .queuecommand = mptsas_qcmd,
1984 .target_alloc = mptsas_target_alloc, 1984 .target_alloc = mptsas_target_alloc,
1985 .slave_alloc = mptsas_slave_alloc, 1985 .slave_alloc = mptsas_slave_alloc,
1986 .slave_configure = mptsas_slave_configure, 1986 .slave_configure = mptsas_slave_configure,
1987 .target_destroy = mptsas_target_destroy, 1987 .target_destroy = mptsas_target_destroy,
1988 .slave_destroy = mptscsih_slave_destroy, 1988 .slave_destroy = mptscsih_slave_destroy,
1989 .change_queue_depth = mptscsih_change_queue_depth, 1989 .change_queue_depth = mptscsih_change_queue_depth,
1990 .eh_abort_handler = mptscsih_abort, 1990 .eh_abort_handler = mptscsih_abort,
1991 .eh_device_reset_handler = mptscsih_dev_reset, 1991 .eh_device_reset_handler = mptscsih_dev_reset,
1992 .eh_host_reset_handler = mptscsih_host_reset, 1992 .eh_host_reset_handler = mptscsih_host_reset,
1993 .bios_param = mptscsih_bios_param, 1993 .bios_param = mptscsih_bios_param,
1994 .can_queue = MPT_SAS_CAN_QUEUE, 1994 .can_queue = MPT_SAS_CAN_QUEUE,
1995 .this_id = -1, 1995 .this_id = -1,
1996 .sg_tablesize = MPT_SCSI_SG_DEPTH, 1996 .sg_tablesize = MPT_SCSI_SG_DEPTH,
1997 .max_sectors = 8192, 1997 .max_sectors = 8192,
1998 .cmd_per_lun = 7, 1998 .cmd_per_lun = 7,
1999 .use_clustering = ENABLE_CLUSTERING, 1999 .use_clustering = ENABLE_CLUSTERING,
2000 .shost_attrs = mptscsih_host_attrs, 2000 .shost_attrs = mptscsih_host_attrs,
2001 }; 2001 };
2002 2002
2003 static int mptsas_get_linkerrors(struct sas_phy *phy) 2003 static int mptsas_get_linkerrors(struct sas_phy *phy)
2004 { 2004 {
2005 MPT_ADAPTER *ioc = phy_to_ioc(phy); 2005 MPT_ADAPTER *ioc = phy_to_ioc(phy);
2006 ConfigExtendedPageHeader_t hdr; 2006 ConfigExtendedPageHeader_t hdr;
2007 CONFIGPARMS cfg; 2007 CONFIGPARMS cfg;
2008 SasPhyPage1_t *buffer; 2008 SasPhyPage1_t *buffer;
2009 dma_addr_t dma_handle; 2009 dma_addr_t dma_handle;
2010 int error; 2010 int error;
2011 2011
2012 /* FIXME: only have link errors on local phys */ 2012 /* FIXME: only have link errors on local phys */
2013 if (!scsi_is_sas_phy_local(phy)) 2013 if (!scsi_is_sas_phy_local(phy))
2014 return -EINVAL; 2014 return -EINVAL;
2015 2015
2016 hdr.PageVersion = MPI_SASPHY1_PAGEVERSION; 2016 hdr.PageVersion = MPI_SASPHY1_PAGEVERSION;
2017 hdr.ExtPageLength = 0; 2017 hdr.ExtPageLength = 0;
2018 hdr.PageNumber = 1 /* page number 1*/; 2018 hdr.PageNumber = 1 /* page number 1*/;
2019 hdr.Reserved1 = 0; 2019 hdr.Reserved1 = 0;
2020 hdr.Reserved2 = 0; 2020 hdr.Reserved2 = 0;
2021 hdr.PageType = MPI_CONFIG_PAGETYPE_EXTENDED; 2021 hdr.PageType = MPI_CONFIG_PAGETYPE_EXTENDED;
2022 hdr.ExtPageType = MPI_CONFIG_EXTPAGETYPE_SAS_PHY; 2022 hdr.ExtPageType = MPI_CONFIG_EXTPAGETYPE_SAS_PHY;
2023 2023
2024 cfg.cfghdr.ehdr = &hdr; 2024 cfg.cfghdr.ehdr = &hdr;
2025 cfg.physAddr = -1; 2025 cfg.physAddr = -1;
2026 cfg.pageAddr = phy->identify.phy_identifier; 2026 cfg.pageAddr = phy->identify.phy_identifier;
2027 cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER; 2027 cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
2028 cfg.dir = 0; /* read */ 2028 cfg.dir = 0; /* read */
2029 cfg.timeout = SAS_CONFIG_PAGE_TIMEOUT; 2029 cfg.timeout = SAS_CONFIG_PAGE_TIMEOUT;
2030 2030
2031 error = mpt_config(ioc, &cfg); 2031 error = mpt_config(ioc, &cfg);
2032 if (error) 2032 if (error)
2033 return error; 2033 return error;
2034 if (!hdr.ExtPageLength) 2034 if (!hdr.ExtPageLength)
2035 return -ENXIO; 2035 return -ENXIO;
2036 2036
2037 buffer = pci_alloc_consistent(ioc->pcidev, hdr.ExtPageLength * 4, 2037 buffer = pci_alloc_consistent(ioc->pcidev, hdr.ExtPageLength * 4,
2038 &dma_handle); 2038 &dma_handle);
2039 if (!buffer) 2039 if (!buffer)
2040 return -ENOMEM; 2040 return -ENOMEM;
2041 2041
2042 cfg.physAddr = dma_handle; 2042 cfg.physAddr = dma_handle;
2043 cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT; 2043 cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
2044 2044
2045 error = mpt_config(ioc, &cfg); 2045 error = mpt_config(ioc, &cfg);
2046 if (error) 2046 if (error)
2047 goto out_free_consistent; 2047 goto out_free_consistent;
2048 2048
2049 mptsas_print_phy_pg1(ioc, buffer); 2049 mptsas_print_phy_pg1(ioc, buffer);
2050 2050
2051 phy->invalid_dword_count = le32_to_cpu(buffer->InvalidDwordCount); 2051 phy->invalid_dword_count = le32_to_cpu(buffer->InvalidDwordCount);
2052 phy->running_disparity_error_count = 2052 phy->running_disparity_error_count =
2053 le32_to_cpu(buffer->RunningDisparityErrorCount); 2053 le32_to_cpu(buffer->RunningDisparityErrorCount);
2054 phy->loss_of_dword_sync_count = 2054 phy->loss_of_dword_sync_count =
2055 le32_to_cpu(buffer->LossDwordSynchCount); 2055 le32_to_cpu(buffer->LossDwordSynchCount);
2056 phy->phy_reset_problem_count = 2056 phy->phy_reset_problem_count =
2057 le32_to_cpu(buffer->PhyResetProblemCount); 2057 le32_to_cpu(buffer->PhyResetProblemCount);
2058 2058
2059 out_free_consistent: 2059 out_free_consistent:
2060 pci_free_consistent(ioc->pcidev, hdr.ExtPageLength * 4, 2060 pci_free_consistent(ioc->pcidev, hdr.ExtPageLength * 4,
2061 buffer, dma_handle); 2061 buffer, dma_handle);
2062 return error; 2062 return error;
2063 } 2063 }
2064 2064
2065 static int mptsas_mgmt_done(MPT_ADAPTER *ioc, MPT_FRAME_HDR *req, 2065 static int mptsas_mgmt_done(MPT_ADAPTER *ioc, MPT_FRAME_HDR *req,
2066 MPT_FRAME_HDR *reply) 2066 MPT_FRAME_HDR *reply)
2067 { 2067 {
2068 ioc->sas_mgmt.status |= MPT_MGMT_STATUS_COMMAND_GOOD; 2068 ioc->sas_mgmt.status |= MPT_MGMT_STATUS_COMMAND_GOOD;
2069 if (reply != NULL) { 2069 if (reply != NULL) {
2070 ioc->sas_mgmt.status |= MPT_MGMT_STATUS_RF_VALID; 2070 ioc->sas_mgmt.status |= MPT_MGMT_STATUS_RF_VALID;
2071 memcpy(ioc->sas_mgmt.reply, reply, 2071 memcpy(ioc->sas_mgmt.reply, reply,
2072 min(ioc->reply_sz, 4 * reply->u.reply.MsgLength)); 2072 min(ioc->reply_sz, 4 * reply->u.reply.MsgLength));
2073 } 2073 }
2074 2074
2075 if (ioc->sas_mgmt.status & MPT_MGMT_STATUS_PENDING) { 2075 if (ioc->sas_mgmt.status & MPT_MGMT_STATUS_PENDING) {
2076 ioc->sas_mgmt.status &= ~MPT_MGMT_STATUS_PENDING; 2076 ioc->sas_mgmt.status &= ~MPT_MGMT_STATUS_PENDING;
2077 complete(&ioc->sas_mgmt.done); 2077 complete(&ioc->sas_mgmt.done);
2078 return 1; 2078 return 1;
2079 } 2079 }
2080 return 0; 2080 return 0;
2081 } 2081 }
2082 2082
2083 static int mptsas_phy_reset(struct sas_phy *phy, int hard_reset) 2083 static int mptsas_phy_reset(struct sas_phy *phy, int hard_reset)
2084 { 2084 {
2085 MPT_ADAPTER *ioc = phy_to_ioc(phy); 2085 MPT_ADAPTER *ioc = phy_to_ioc(phy);
2086 SasIoUnitControlRequest_t *req; 2086 SasIoUnitControlRequest_t *req;
2087 SasIoUnitControlReply_t *reply; 2087 SasIoUnitControlReply_t *reply;
2088 MPT_FRAME_HDR *mf; 2088 MPT_FRAME_HDR *mf;
2089 MPIHeader_t *hdr; 2089 MPIHeader_t *hdr;
2090 unsigned long timeleft; 2090 unsigned long timeleft;
2091 int error = -ERESTARTSYS; 2091 int error = -ERESTARTSYS;
2092 2092
2093 /* FIXME: fusion doesn't allow non-local phy reset */ 2093 /* FIXME: fusion doesn't allow non-local phy reset */
2094 if (!scsi_is_sas_phy_local(phy)) 2094 if (!scsi_is_sas_phy_local(phy))
2095 return -EINVAL; 2095 return -EINVAL;
2096 2096
2097 /* not implemented for expanders */ 2097 /* not implemented for expanders */
2098 if (phy->identify.target_port_protocols & SAS_PROTOCOL_SMP) 2098 if (phy->identify.target_port_protocols & SAS_PROTOCOL_SMP)
2099 return -ENXIO; 2099 return -ENXIO;
2100 2100
2101 if (mutex_lock_interruptible(&ioc->sas_mgmt.mutex)) 2101 if (mutex_lock_interruptible(&ioc->sas_mgmt.mutex))
2102 goto out; 2102 goto out;
2103 2103
2104 mf = mpt_get_msg_frame(mptsasMgmtCtx, ioc); 2104 mf = mpt_get_msg_frame(mptsasMgmtCtx, ioc);
2105 if (!mf) { 2105 if (!mf) {
2106 error = -ENOMEM; 2106 error = -ENOMEM;
2107 goto out_unlock; 2107 goto out_unlock;
2108 } 2108 }
2109 2109
2110 hdr = (MPIHeader_t *) mf; 2110 hdr = (MPIHeader_t *) mf;
2111 req = (SasIoUnitControlRequest_t *)mf; 2111 req = (SasIoUnitControlRequest_t *)mf;
2112 memset(req, 0, sizeof(SasIoUnitControlRequest_t)); 2112 memset(req, 0, sizeof(SasIoUnitControlRequest_t));
2113 req->Function = MPI_FUNCTION_SAS_IO_UNIT_CONTROL; 2113 req->Function = MPI_FUNCTION_SAS_IO_UNIT_CONTROL;
2114 req->MsgContext = hdr->MsgContext; 2114 req->MsgContext = hdr->MsgContext;
2115 req->Operation = hard_reset ? 2115 req->Operation = hard_reset ?
2116 MPI_SAS_OP_PHY_HARD_RESET : MPI_SAS_OP_PHY_LINK_RESET; 2116 MPI_SAS_OP_PHY_HARD_RESET : MPI_SAS_OP_PHY_LINK_RESET;
2117 req->PhyNum = phy->identify.phy_identifier; 2117 req->PhyNum = phy->identify.phy_identifier;
2118 2118
2119 INITIALIZE_MGMT_STATUS(ioc->sas_mgmt.status) 2119 INITIALIZE_MGMT_STATUS(ioc->sas_mgmt.status)
2120 mpt_put_msg_frame(mptsasMgmtCtx, ioc, mf); 2120 mpt_put_msg_frame(mptsasMgmtCtx, ioc, mf);
2121 2121
2122 timeleft = wait_for_completion_timeout(&ioc->sas_mgmt.done, 2122 timeleft = wait_for_completion_timeout(&ioc->sas_mgmt.done,
2123 10 * HZ); 2123 10 * HZ);
2124 if (!(ioc->sas_mgmt.status & MPT_MGMT_STATUS_COMMAND_GOOD)) { 2124 if (!(ioc->sas_mgmt.status & MPT_MGMT_STATUS_COMMAND_GOOD)) {
2125 error = -ETIME; 2125 error = -ETIME;
2126 mpt_free_msg_frame(ioc, mf); 2126 mpt_free_msg_frame(ioc, mf);
2127 if (ioc->sas_mgmt.status & MPT_MGMT_STATUS_DID_IOCRESET) 2127 if (ioc->sas_mgmt.status & MPT_MGMT_STATUS_DID_IOCRESET)
2128 goto out_unlock; 2128 goto out_unlock;
2129 if (!timeleft) 2129 if (!timeleft)
2130 mpt_Soft_Hard_ResetHandler(ioc, CAN_SLEEP); 2130 mpt_Soft_Hard_ResetHandler(ioc, CAN_SLEEP);
2131 goto out_unlock; 2131 goto out_unlock;
2132 } 2132 }
2133 2133
2134 /* a reply frame is expected */ 2134 /* a reply frame is expected */
2135 if ((ioc->sas_mgmt.status & 2135 if ((ioc->sas_mgmt.status &
2136 MPT_MGMT_STATUS_RF_VALID) == 0) { 2136 MPT_MGMT_STATUS_RF_VALID) == 0) {
2137 error = -ENXIO; 2137 error = -ENXIO;
2138 goto out_unlock; 2138 goto out_unlock;
2139 } 2139 }
2140 2140
2141 /* process the completed Reply Message Frame */ 2141 /* process the completed Reply Message Frame */
2142 reply = (SasIoUnitControlReply_t *)ioc->sas_mgmt.reply; 2142 reply = (SasIoUnitControlReply_t *)ioc->sas_mgmt.reply;
2143 if (reply->IOCStatus != MPI_IOCSTATUS_SUCCESS) { 2143 if (reply->IOCStatus != MPI_IOCSTATUS_SUCCESS) {
2144 printk(MYIOC_s_INFO_FMT "%s: IOCStatus=0x%X IOCLogInfo=0x%X\n", 2144 printk(MYIOC_s_INFO_FMT "%s: IOCStatus=0x%X IOCLogInfo=0x%X\n",
2145 ioc->name, __func__, reply->IOCStatus, reply->IOCLogInfo); 2145 ioc->name, __func__, reply->IOCStatus, reply->IOCLogInfo);
2146 error = -ENXIO; 2146 error = -ENXIO;
2147 goto out_unlock; 2147 goto out_unlock;
2148 } 2148 }
2149 2149
2150 error = 0; 2150 error = 0;
2151 2151
2152 out_unlock: 2152 out_unlock:
2153 CLEAR_MGMT_STATUS(ioc->sas_mgmt.status) 2153 CLEAR_MGMT_STATUS(ioc->sas_mgmt.status)
2154 mutex_unlock(&ioc->sas_mgmt.mutex); 2154 mutex_unlock(&ioc->sas_mgmt.mutex);
2155 out: 2155 out:
2156 return error; 2156 return error;
2157 } 2157 }
2158 2158
2159 static int 2159 static int
2160 mptsas_get_enclosure_identifier(struct sas_rphy *rphy, u64 *identifier) 2160 mptsas_get_enclosure_identifier(struct sas_rphy *rphy, u64 *identifier)
2161 { 2161 {
2162 MPT_ADAPTER *ioc = rphy_to_ioc(rphy); 2162 MPT_ADAPTER *ioc = rphy_to_ioc(rphy);
2163 int i, error; 2163 int i, error;
2164 struct mptsas_portinfo *p; 2164 struct mptsas_portinfo *p;
2165 struct mptsas_enclosure enclosure_info; 2165 struct mptsas_enclosure enclosure_info;
2166 u64 enclosure_handle; 2166 u64 enclosure_handle;
2167 2167
2168 mutex_lock(&ioc->sas_topology_mutex); 2168 mutex_lock(&ioc->sas_topology_mutex);
2169 list_for_each_entry(p, &ioc->sas_topology, list) { 2169 list_for_each_entry(p, &ioc->sas_topology, list) {
2170 for (i = 0; i < p->num_phys; i++) { 2170 for (i = 0; i < p->num_phys; i++) {
2171 if (p->phy_info[i].attached.sas_address == 2171 if (p->phy_info[i].attached.sas_address ==
2172 rphy->identify.sas_address) { 2172 rphy->identify.sas_address) {
2173 enclosure_handle = p->phy_info[i]. 2173 enclosure_handle = p->phy_info[i].
2174 attached.handle_enclosure; 2174 attached.handle_enclosure;
2175 goto found_info; 2175 goto found_info;
2176 } 2176 }
2177 } 2177 }
2178 } 2178 }
2179 mutex_unlock(&ioc->sas_topology_mutex); 2179 mutex_unlock(&ioc->sas_topology_mutex);
2180 return -ENXIO; 2180 return -ENXIO;
2181 2181
2182 found_info: 2182 found_info:
2183 mutex_unlock(&ioc->sas_topology_mutex); 2183 mutex_unlock(&ioc->sas_topology_mutex);
2184 memset(&enclosure_info, 0, sizeof(struct mptsas_enclosure)); 2184 memset(&enclosure_info, 0, sizeof(struct mptsas_enclosure));
2185 error = mptsas_sas_enclosure_pg0(ioc, &enclosure_info, 2185 error = mptsas_sas_enclosure_pg0(ioc, &enclosure_info,
2186 (MPI_SAS_ENCLOS_PGAD_FORM_HANDLE << 2186 (MPI_SAS_ENCLOS_PGAD_FORM_HANDLE <<
2187 MPI_SAS_ENCLOS_PGAD_FORM_SHIFT), enclosure_handle); 2187 MPI_SAS_ENCLOS_PGAD_FORM_SHIFT), enclosure_handle);
2188 if (!error) 2188 if (!error)
2189 *identifier = enclosure_info.enclosure_logical_id; 2189 *identifier = enclosure_info.enclosure_logical_id;
2190 return error; 2190 return error;
2191 } 2191 }
2192 2192
2193 static int 2193 static int
2194 mptsas_get_bay_identifier(struct sas_rphy *rphy) 2194 mptsas_get_bay_identifier(struct sas_rphy *rphy)
2195 { 2195 {
2196 MPT_ADAPTER *ioc = rphy_to_ioc(rphy); 2196 MPT_ADAPTER *ioc = rphy_to_ioc(rphy);
2197 struct mptsas_portinfo *p; 2197 struct mptsas_portinfo *p;
2198 int i, rc; 2198 int i, rc;
2199 2199
2200 mutex_lock(&ioc->sas_topology_mutex); 2200 mutex_lock(&ioc->sas_topology_mutex);
2201 list_for_each_entry(p, &ioc->sas_topology, list) { 2201 list_for_each_entry(p, &ioc->sas_topology, list) {
2202 for (i = 0; i < p->num_phys; i++) { 2202 for (i = 0; i < p->num_phys; i++) {
2203 if (p->phy_info[i].attached.sas_address == 2203 if (p->phy_info[i].attached.sas_address ==
2204 rphy->identify.sas_address) { 2204 rphy->identify.sas_address) {
2205 rc = p->phy_info[i].attached.slot; 2205 rc = p->phy_info[i].attached.slot;
2206 goto out; 2206 goto out;
2207 } 2207 }
2208 } 2208 }
2209 } 2209 }
2210 rc = -ENXIO; 2210 rc = -ENXIO;
2211 out: 2211 out:
2212 mutex_unlock(&ioc->sas_topology_mutex); 2212 mutex_unlock(&ioc->sas_topology_mutex);
2213 return rc; 2213 return rc;
2214 } 2214 }
2215 2215
2216 static int mptsas_smp_handler(struct Scsi_Host *shost, struct sas_rphy *rphy, 2216 static int mptsas_smp_handler(struct Scsi_Host *shost, struct sas_rphy *rphy,
2217 struct request *req) 2217 struct request *req)
2218 { 2218 {
2219 MPT_ADAPTER *ioc = ((MPT_SCSI_HOST *) shost->hostdata)->ioc; 2219 MPT_ADAPTER *ioc = ((MPT_SCSI_HOST *) shost->hostdata)->ioc;
2220 MPT_FRAME_HDR *mf; 2220 MPT_FRAME_HDR *mf;
2221 SmpPassthroughRequest_t *smpreq; 2221 SmpPassthroughRequest_t *smpreq;
2222 struct request *rsp = req->next_rq; 2222 struct request *rsp = req->next_rq;
2223 int ret; 2223 int ret;
2224 int flagsLength; 2224 int flagsLength;
2225 unsigned long timeleft; 2225 unsigned long timeleft;
2226 char *psge; 2226 char *psge;
2227 dma_addr_t dma_addr_in = 0; 2227 dma_addr_t dma_addr_in = 0;
2228 dma_addr_t dma_addr_out = 0; 2228 dma_addr_t dma_addr_out = 0;
2229 u64 sas_address = 0; 2229 u64 sas_address = 0;
2230 2230
2231 if (!rsp) { 2231 if (!rsp) {
2232 printk(MYIOC_s_ERR_FMT "%s: the smp response space is missing\n", 2232 printk(MYIOC_s_ERR_FMT "%s: the smp response space is missing\n",
2233 ioc->name, __func__); 2233 ioc->name, __func__);
2234 return -EINVAL; 2234 return -EINVAL;
2235 } 2235 }
2236 2236
2237 /* do we need to support multiple segments? */ 2237 /* do we need to support multiple segments? */
2238 if (req->bio->bi_vcnt > 1 || rsp->bio->bi_vcnt > 1) { 2238 if (req->bio->bi_vcnt > 1 || rsp->bio->bi_vcnt > 1) {
2239 printk(MYIOC_s_ERR_FMT "%s: multiple segments req %u %u, rsp %u %u\n", 2239 printk(MYIOC_s_ERR_FMT "%s: multiple segments req %u %u, rsp %u %u\n",
2240 ioc->name, __func__, req->bio->bi_vcnt, blk_rq_bytes(req), 2240 ioc->name, __func__, req->bio->bi_vcnt, blk_rq_bytes(req),
2241 rsp->bio->bi_vcnt, blk_rq_bytes(rsp)); 2241 rsp->bio->bi_vcnt, blk_rq_bytes(rsp));
2242 return -EINVAL; 2242 return -EINVAL;
2243 } 2243 }
2244 2244
2245 ret = mutex_lock_interruptible(&ioc->sas_mgmt.mutex); 2245 ret = mutex_lock_interruptible(&ioc->sas_mgmt.mutex);
2246 if (ret) 2246 if (ret)
2247 goto out; 2247 goto out;
2248 2248
2249 mf = mpt_get_msg_frame(mptsasMgmtCtx, ioc); 2249 mf = mpt_get_msg_frame(mptsasMgmtCtx, ioc);
2250 if (!mf) { 2250 if (!mf) {
2251 ret = -ENOMEM; 2251 ret = -ENOMEM;
2252 goto out_unlock; 2252 goto out_unlock;
2253 } 2253 }
2254 2254
2255 smpreq = (SmpPassthroughRequest_t *)mf; 2255 smpreq = (SmpPassthroughRequest_t *)mf;
2256 memset(smpreq, 0, sizeof(*smpreq)); 2256 memset(smpreq, 0, sizeof(*smpreq));
2257 2257
2258 smpreq->RequestDataLength = cpu_to_le16(blk_rq_bytes(req) - 4); 2258 smpreq->RequestDataLength = cpu_to_le16(blk_rq_bytes(req) - 4);
2259 smpreq->Function = MPI_FUNCTION_SMP_PASSTHROUGH; 2259 smpreq->Function = MPI_FUNCTION_SMP_PASSTHROUGH;
2260 2260
2261 if (rphy) 2261 if (rphy)
2262 sas_address = rphy->identify.sas_address; 2262 sas_address = rphy->identify.sas_address;
2263 else { 2263 else {
2264 struct mptsas_portinfo *port_info; 2264 struct mptsas_portinfo *port_info;
2265 2265
2266 mutex_lock(&ioc->sas_topology_mutex); 2266 mutex_lock(&ioc->sas_topology_mutex);
2267 port_info = ioc->hba_port_info; 2267 port_info = ioc->hba_port_info;
2268 if (port_info && port_info->phy_info) 2268 if (port_info && port_info->phy_info)
2269 sas_address = 2269 sas_address =
2270 port_info->phy_info[0].phy->identify.sas_address; 2270 port_info->phy_info[0].phy->identify.sas_address;
2271 mutex_unlock(&ioc->sas_topology_mutex); 2271 mutex_unlock(&ioc->sas_topology_mutex);
2272 } 2272 }
2273 2273
2274 *((u64 *)&smpreq->SASAddress) = cpu_to_le64(sas_address); 2274 *((u64 *)&smpreq->SASAddress) = cpu_to_le64(sas_address);
2275 2275
2276 psge = (char *) 2276 psge = (char *)
2277 (((int *) mf) + (offsetof(SmpPassthroughRequest_t, SGL) / 4)); 2277 (((int *) mf) + (offsetof(SmpPassthroughRequest_t, SGL) / 4));
2278 2278
2279 /* request */ 2279 /* request */
2280 flagsLength = (MPI_SGE_FLAGS_SIMPLE_ELEMENT | 2280 flagsLength = (MPI_SGE_FLAGS_SIMPLE_ELEMENT |
2281 MPI_SGE_FLAGS_END_OF_BUFFER | 2281 MPI_SGE_FLAGS_END_OF_BUFFER |
2282 MPI_SGE_FLAGS_DIRECTION) 2282 MPI_SGE_FLAGS_DIRECTION)
2283 << MPI_SGE_FLAGS_SHIFT; 2283 << MPI_SGE_FLAGS_SHIFT;
2284 flagsLength |= (blk_rq_bytes(req) - 4); 2284 flagsLength |= (blk_rq_bytes(req) - 4);
2285 2285
2286 dma_addr_out = pci_map_single(ioc->pcidev, bio_data(req->bio), 2286 dma_addr_out = pci_map_single(ioc->pcidev, bio_data(req->bio),
2287 blk_rq_bytes(req), PCI_DMA_BIDIRECTIONAL); 2287 blk_rq_bytes(req), PCI_DMA_BIDIRECTIONAL);
2288 if (!dma_addr_out) 2288 if (!dma_addr_out)
2289 goto put_mf; 2289 goto put_mf;
2290 ioc->add_sge(psge, flagsLength, dma_addr_out); 2290 ioc->add_sge(psge, flagsLength, dma_addr_out);
2291 psge += ioc->SGE_size; 2291 psge += ioc->SGE_size;
2292 2292
2293 /* response */ 2293 /* response */
2294 flagsLength = MPI_SGE_FLAGS_SIMPLE_ELEMENT | 2294 flagsLength = MPI_SGE_FLAGS_SIMPLE_ELEMENT |
2295 MPI_SGE_FLAGS_SYSTEM_ADDRESS | 2295 MPI_SGE_FLAGS_SYSTEM_ADDRESS |
2296 MPI_SGE_FLAGS_IOC_TO_HOST | 2296 MPI_SGE_FLAGS_IOC_TO_HOST |
2297 MPI_SGE_FLAGS_END_OF_BUFFER; 2297 MPI_SGE_FLAGS_END_OF_BUFFER;
2298 2298
2299 flagsLength = flagsLength << MPI_SGE_FLAGS_SHIFT; 2299 flagsLength = flagsLength << MPI_SGE_FLAGS_SHIFT;
2300 flagsLength |= blk_rq_bytes(rsp) + 4; 2300 flagsLength |= blk_rq_bytes(rsp) + 4;
2301 dma_addr_in = pci_map_single(ioc->pcidev, bio_data(rsp->bio), 2301 dma_addr_in = pci_map_single(ioc->pcidev, bio_data(rsp->bio),
2302 blk_rq_bytes(rsp), PCI_DMA_BIDIRECTIONAL); 2302 blk_rq_bytes(rsp), PCI_DMA_BIDIRECTIONAL);
2303 if (!dma_addr_in) 2303 if (!dma_addr_in)
2304 goto unmap; 2304 goto unmap;
2305 ioc->add_sge(psge, flagsLength, dma_addr_in); 2305 ioc->add_sge(psge, flagsLength, dma_addr_in);
2306 2306
2307 INITIALIZE_MGMT_STATUS(ioc->sas_mgmt.status) 2307 INITIALIZE_MGMT_STATUS(ioc->sas_mgmt.status)
2308 mpt_put_msg_frame(mptsasMgmtCtx, ioc, mf); 2308 mpt_put_msg_frame(mptsasMgmtCtx, ioc, mf);
2309 2309
2310 timeleft = wait_for_completion_timeout(&ioc->sas_mgmt.done, 10 * HZ); 2310 timeleft = wait_for_completion_timeout(&ioc->sas_mgmt.done, 10 * HZ);
2311 if (!(ioc->sas_mgmt.status & MPT_MGMT_STATUS_COMMAND_GOOD)) { 2311 if (!(ioc->sas_mgmt.status & MPT_MGMT_STATUS_COMMAND_GOOD)) {
2312 ret = -ETIME; 2312 ret = -ETIME;
2313 mpt_free_msg_frame(ioc, mf); 2313 mpt_free_msg_frame(ioc, mf);
2314 mf = NULL; 2314 mf = NULL;
2315 if (ioc->sas_mgmt.status & MPT_MGMT_STATUS_DID_IOCRESET) 2315 if (ioc->sas_mgmt.status & MPT_MGMT_STATUS_DID_IOCRESET)
2316 goto unmap; 2316 goto unmap;
2317 if (!timeleft) 2317 if (!timeleft)
2318 mpt_Soft_Hard_ResetHandler(ioc, CAN_SLEEP); 2318 mpt_Soft_Hard_ResetHandler(ioc, CAN_SLEEP);
2319 goto unmap; 2319 goto unmap;
2320 } 2320 }
2321 mf = NULL; 2321 mf = NULL;
2322 2322
2323 if (ioc->sas_mgmt.status & MPT_MGMT_STATUS_RF_VALID) { 2323 if (ioc->sas_mgmt.status & MPT_MGMT_STATUS_RF_VALID) {
2324 SmpPassthroughReply_t *smprep; 2324 SmpPassthroughReply_t *smprep;
2325 2325
2326 smprep = (SmpPassthroughReply_t *)ioc->sas_mgmt.reply; 2326 smprep = (SmpPassthroughReply_t *)ioc->sas_mgmt.reply;
2327 memcpy(req->sense, smprep, sizeof(*smprep)); 2327 memcpy(req->sense, smprep, sizeof(*smprep));
2328 req->sense_len = sizeof(*smprep); 2328 req->sense_len = sizeof(*smprep);
2329 req->resid_len = 0; 2329 req->resid_len = 0;
2330 rsp->resid_len -= smprep->ResponseDataLength; 2330 rsp->resid_len -= smprep->ResponseDataLength;
2331 } else { 2331 } else {
2332 printk(MYIOC_s_ERR_FMT 2332 printk(MYIOC_s_ERR_FMT
2333 "%s: smp passthru reply failed to be returned\n", 2333 "%s: smp passthru reply failed to be returned\n",
2334 ioc->name, __func__); 2334 ioc->name, __func__);
2335 ret = -ENXIO; 2335 ret = -ENXIO;
2336 } 2336 }
2337 unmap: 2337 unmap:
2338 if (dma_addr_out) 2338 if (dma_addr_out)
2339 pci_unmap_single(ioc->pcidev, dma_addr_out, blk_rq_bytes(req), 2339 pci_unmap_single(ioc->pcidev, dma_addr_out, blk_rq_bytes(req),
2340 PCI_DMA_BIDIRECTIONAL); 2340 PCI_DMA_BIDIRECTIONAL);
2341 if (dma_addr_in) 2341 if (dma_addr_in)
2342 pci_unmap_single(ioc->pcidev, dma_addr_in, blk_rq_bytes(rsp), 2342 pci_unmap_single(ioc->pcidev, dma_addr_in, blk_rq_bytes(rsp),
2343 PCI_DMA_BIDIRECTIONAL); 2343 PCI_DMA_BIDIRECTIONAL);
2344 put_mf: 2344 put_mf:
2345 if (mf) 2345 if (mf)
2346 mpt_free_msg_frame(ioc, mf); 2346 mpt_free_msg_frame(ioc, mf);
2347 out_unlock: 2347 out_unlock:
2348 CLEAR_MGMT_STATUS(ioc->sas_mgmt.status) 2348 CLEAR_MGMT_STATUS(ioc->sas_mgmt.status)
2349 mutex_unlock(&ioc->sas_mgmt.mutex); 2349 mutex_unlock(&ioc->sas_mgmt.mutex);
2350 out: 2350 out:
2351 return ret; 2351 return ret;
2352 } 2352 }
2353 2353
2354 static struct sas_function_template mptsas_transport_functions = { 2354 static struct sas_function_template mptsas_transport_functions = {
2355 .get_linkerrors = mptsas_get_linkerrors, 2355 .get_linkerrors = mptsas_get_linkerrors,
2356 .get_enclosure_identifier = mptsas_get_enclosure_identifier, 2356 .get_enclosure_identifier = mptsas_get_enclosure_identifier,
2357 .get_bay_identifier = mptsas_get_bay_identifier, 2357 .get_bay_identifier = mptsas_get_bay_identifier,
2358 .phy_reset = mptsas_phy_reset, 2358 .phy_reset = mptsas_phy_reset,
2359 .smp_handler = mptsas_smp_handler, 2359 .smp_handler = mptsas_smp_handler,
2360 }; 2360 };
2361 2361
2362 static struct scsi_transport_template *mptsas_transport_template; 2362 static struct scsi_transport_template *mptsas_transport_template;
2363 2363
2364 static int 2364 static int
2365 mptsas_sas_io_unit_pg0(MPT_ADAPTER *ioc, struct mptsas_portinfo *port_info) 2365 mptsas_sas_io_unit_pg0(MPT_ADAPTER *ioc, struct mptsas_portinfo *port_info)
2366 { 2366 {
2367 ConfigExtendedPageHeader_t hdr; 2367 ConfigExtendedPageHeader_t hdr;
2368 CONFIGPARMS cfg; 2368 CONFIGPARMS cfg;
2369 SasIOUnitPage0_t *buffer; 2369 SasIOUnitPage0_t *buffer;
2370 dma_addr_t dma_handle; 2370 dma_addr_t dma_handle;
2371 int error, i; 2371 int error, i;
2372 2372
2373 hdr.PageVersion = MPI_SASIOUNITPAGE0_PAGEVERSION; 2373 hdr.PageVersion = MPI_SASIOUNITPAGE0_PAGEVERSION;
2374 hdr.ExtPageLength = 0; 2374 hdr.ExtPageLength = 0;
2375 hdr.PageNumber = 0; 2375 hdr.PageNumber = 0;
2376 hdr.Reserved1 = 0; 2376 hdr.Reserved1 = 0;
2377 hdr.Reserved2 = 0; 2377 hdr.Reserved2 = 0;
2378 hdr.PageType = MPI_CONFIG_PAGETYPE_EXTENDED; 2378 hdr.PageType = MPI_CONFIG_PAGETYPE_EXTENDED;
2379 hdr.ExtPageType = MPI_CONFIG_EXTPAGETYPE_SAS_IO_UNIT; 2379 hdr.ExtPageType = MPI_CONFIG_EXTPAGETYPE_SAS_IO_UNIT;
2380 2380
2381 cfg.cfghdr.ehdr = &hdr; 2381 cfg.cfghdr.ehdr = &hdr;
2382 cfg.physAddr = -1; 2382 cfg.physAddr = -1;
2383 cfg.pageAddr = 0; 2383 cfg.pageAddr = 0;
2384 cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER; 2384 cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
2385 cfg.dir = 0; /* read */ 2385 cfg.dir = 0; /* read */
2386 cfg.timeout = SAS_CONFIG_PAGE_TIMEOUT; 2386 cfg.timeout = SAS_CONFIG_PAGE_TIMEOUT;
2387 2387
2388 error = mpt_config(ioc, &cfg); 2388 error = mpt_config(ioc, &cfg);
2389 if (error) 2389 if (error)
2390 goto out; 2390 goto out;
2391 if (!hdr.ExtPageLength) { 2391 if (!hdr.ExtPageLength) {
2392 error = -ENXIO; 2392 error = -ENXIO;
2393 goto out; 2393 goto out;
2394 } 2394 }
2395 2395
2396 buffer = pci_alloc_consistent(ioc->pcidev, hdr.ExtPageLength * 4, 2396 buffer = pci_alloc_consistent(ioc->pcidev, hdr.ExtPageLength * 4,
2397 &dma_handle); 2397 &dma_handle);
2398 if (!buffer) { 2398 if (!buffer) {
2399 error = -ENOMEM; 2399 error = -ENOMEM;
2400 goto out; 2400 goto out;
2401 } 2401 }
2402 2402
2403 cfg.physAddr = dma_handle; 2403 cfg.physAddr = dma_handle;
2404 cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT; 2404 cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
2405 2405
2406 error = mpt_config(ioc, &cfg); 2406 error = mpt_config(ioc, &cfg);
2407 if (error) 2407 if (error)
2408 goto out_free_consistent; 2408 goto out_free_consistent;
2409 2409
2410 port_info->num_phys = buffer->NumPhys; 2410 port_info->num_phys = buffer->NumPhys;
2411 port_info->phy_info = kcalloc(port_info->num_phys, 2411 port_info->phy_info = kcalloc(port_info->num_phys,
2412 sizeof(struct mptsas_phyinfo), GFP_KERNEL); 2412 sizeof(struct mptsas_phyinfo), GFP_KERNEL);
2413 if (!port_info->phy_info) { 2413 if (!port_info->phy_info) {
2414 error = -ENOMEM; 2414 error = -ENOMEM;
2415 goto out_free_consistent; 2415 goto out_free_consistent;
2416 } 2416 }
2417 2417
2418 ioc->nvdata_version_persistent = 2418 ioc->nvdata_version_persistent =
2419 le16_to_cpu(buffer->NvdataVersionPersistent); 2419 le16_to_cpu(buffer->NvdataVersionPersistent);
2420 ioc->nvdata_version_default = 2420 ioc->nvdata_version_default =
2421 le16_to_cpu(buffer->NvdataVersionDefault); 2421 le16_to_cpu(buffer->NvdataVersionDefault);
2422 2422
2423 for (i = 0; i < port_info->num_phys; i++) { 2423 for (i = 0; i < port_info->num_phys; i++) {
2424 mptsas_print_phy_data(ioc, &buffer->PhyData[i]); 2424 mptsas_print_phy_data(ioc, &buffer->PhyData[i]);
2425 port_info->phy_info[i].phy_id = i; 2425 port_info->phy_info[i].phy_id = i;
2426 port_info->phy_info[i].port_id = 2426 port_info->phy_info[i].port_id =
2427 buffer->PhyData[i].Port; 2427 buffer->PhyData[i].Port;
2428 port_info->phy_info[i].negotiated_link_rate = 2428 port_info->phy_info[i].negotiated_link_rate =
2429 buffer->PhyData[i].NegotiatedLinkRate; 2429 buffer->PhyData[i].NegotiatedLinkRate;
2430 port_info->phy_info[i].portinfo = port_info; 2430 port_info->phy_info[i].portinfo = port_info;
2431 port_info->phy_info[i].handle = 2431 port_info->phy_info[i].handle =
2432 le16_to_cpu(buffer->PhyData[i].ControllerDevHandle); 2432 le16_to_cpu(buffer->PhyData[i].ControllerDevHandle);
2433 } 2433 }
2434 2434
2435 out_free_consistent: 2435 out_free_consistent:
2436 pci_free_consistent(ioc->pcidev, hdr.ExtPageLength * 4, 2436 pci_free_consistent(ioc->pcidev, hdr.ExtPageLength * 4,
2437 buffer, dma_handle); 2437 buffer, dma_handle);
2438 out: 2438 out:
2439 return error; 2439 return error;
2440 } 2440 }
2441 2441
2442 static int 2442 static int
2443 mptsas_sas_io_unit_pg1(MPT_ADAPTER *ioc) 2443 mptsas_sas_io_unit_pg1(MPT_ADAPTER *ioc)
2444 { 2444 {
2445 ConfigExtendedPageHeader_t hdr; 2445 ConfigExtendedPageHeader_t hdr;
2446 CONFIGPARMS cfg; 2446 CONFIGPARMS cfg;
2447 SasIOUnitPage1_t *buffer; 2447 SasIOUnitPage1_t *buffer;
2448 dma_addr_t dma_handle; 2448 dma_addr_t dma_handle;
2449 int error; 2449 int error;
2450 u8 device_missing_delay; 2450 u8 device_missing_delay;
2451 2451
2452 memset(&hdr, 0, sizeof(ConfigExtendedPageHeader_t)); 2452 memset(&hdr, 0, sizeof(ConfigExtendedPageHeader_t));
2453 memset(&cfg, 0, sizeof(CONFIGPARMS)); 2453 memset(&cfg, 0, sizeof(CONFIGPARMS));
2454 2454
2455 cfg.cfghdr.ehdr = &hdr; 2455 cfg.cfghdr.ehdr = &hdr;
2456 cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER; 2456 cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
2457 cfg.timeout = SAS_CONFIG_PAGE_TIMEOUT; 2457 cfg.timeout = SAS_CONFIG_PAGE_TIMEOUT;
2458 cfg.cfghdr.ehdr->PageType = MPI_CONFIG_PAGETYPE_EXTENDED; 2458 cfg.cfghdr.ehdr->PageType = MPI_CONFIG_PAGETYPE_EXTENDED;
2459 cfg.cfghdr.ehdr->ExtPageType = MPI_CONFIG_EXTPAGETYPE_SAS_IO_UNIT; 2459 cfg.cfghdr.ehdr->ExtPageType = MPI_CONFIG_EXTPAGETYPE_SAS_IO_UNIT;
2460 cfg.cfghdr.ehdr->PageVersion = MPI_SASIOUNITPAGE1_PAGEVERSION; 2460 cfg.cfghdr.ehdr->PageVersion = MPI_SASIOUNITPAGE1_PAGEVERSION;
2461 cfg.cfghdr.ehdr->PageNumber = 1; 2461 cfg.cfghdr.ehdr->PageNumber = 1;
2462 2462
2463 error = mpt_config(ioc, &cfg); 2463 error = mpt_config(ioc, &cfg);
2464 if (error) 2464 if (error)
2465 goto out; 2465 goto out;
2466 if (!hdr.ExtPageLength) { 2466 if (!hdr.ExtPageLength) {
2467 error = -ENXIO; 2467 error = -ENXIO;
2468 goto out; 2468 goto out;
2469 } 2469 }
2470 2470
2471 buffer = pci_alloc_consistent(ioc->pcidev, hdr.ExtPageLength * 4, 2471 buffer = pci_alloc_consistent(ioc->pcidev, hdr.ExtPageLength * 4,
2472 &dma_handle); 2472 &dma_handle);
2473 if (!buffer) { 2473 if (!buffer) {
2474 error = -ENOMEM; 2474 error = -ENOMEM;
2475 goto out; 2475 goto out;
2476 } 2476 }
2477 2477
2478 cfg.physAddr = dma_handle; 2478 cfg.physAddr = dma_handle;
2479 cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT; 2479 cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
2480 2480
2481 error = mpt_config(ioc, &cfg); 2481 error = mpt_config(ioc, &cfg);
2482 if (error) 2482 if (error)
2483 goto out_free_consistent; 2483 goto out_free_consistent;
2484 2484
2485 ioc->io_missing_delay = 2485 ioc->io_missing_delay =
2486 le16_to_cpu(buffer->IODeviceMissingDelay); 2486 le16_to_cpu(buffer->IODeviceMissingDelay);
2487 device_missing_delay = buffer->ReportDeviceMissingDelay; 2487 device_missing_delay = buffer->ReportDeviceMissingDelay;
2488 ioc->device_missing_delay = (device_missing_delay & MPI_SAS_IOUNIT1_REPORT_MISSING_UNIT_16) ? 2488 ioc->device_missing_delay = (device_missing_delay & MPI_SAS_IOUNIT1_REPORT_MISSING_UNIT_16) ?
2489 (device_missing_delay & MPI_SAS_IOUNIT1_REPORT_MISSING_TIMEOUT_MASK) * 16 : 2489 (device_missing_delay & MPI_SAS_IOUNIT1_REPORT_MISSING_TIMEOUT_MASK) * 16 :
2490 device_missing_delay & MPI_SAS_IOUNIT1_REPORT_MISSING_TIMEOUT_MASK; 2490 device_missing_delay & MPI_SAS_IOUNIT1_REPORT_MISSING_TIMEOUT_MASK;
2491 2491
2492 out_free_consistent: 2492 out_free_consistent:
2493 pci_free_consistent(ioc->pcidev, hdr.ExtPageLength * 4, 2493 pci_free_consistent(ioc->pcidev, hdr.ExtPageLength * 4,
2494 buffer, dma_handle); 2494 buffer, dma_handle);
2495 out: 2495 out:
2496 return error; 2496 return error;
2497 } 2497 }
2498 2498
2499 static int 2499 static int
2500 mptsas_sas_phy_pg0(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, 2500 mptsas_sas_phy_pg0(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info,
2501 u32 form, u32 form_specific) 2501 u32 form, u32 form_specific)
2502 { 2502 {
2503 ConfigExtendedPageHeader_t hdr; 2503 ConfigExtendedPageHeader_t hdr;
2504 CONFIGPARMS cfg; 2504 CONFIGPARMS cfg;
2505 SasPhyPage0_t *buffer; 2505 SasPhyPage0_t *buffer;
2506 dma_addr_t dma_handle; 2506 dma_addr_t dma_handle;
2507 int error; 2507 int error;
2508 2508
2509 hdr.PageVersion = MPI_SASPHY0_PAGEVERSION; 2509 hdr.PageVersion = MPI_SASPHY0_PAGEVERSION;
2510 hdr.ExtPageLength = 0; 2510 hdr.ExtPageLength = 0;
2511 hdr.PageNumber = 0; 2511 hdr.PageNumber = 0;
2512 hdr.Reserved1 = 0; 2512 hdr.Reserved1 = 0;
2513 hdr.Reserved2 = 0; 2513 hdr.Reserved2 = 0;
2514 hdr.PageType = MPI_CONFIG_PAGETYPE_EXTENDED; 2514 hdr.PageType = MPI_CONFIG_PAGETYPE_EXTENDED;
2515 hdr.ExtPageType = MPI_CONFIG_EXTPAGETYPE_SAS_PHY; 2515 hdr.ExtPageType = MPI_CONFIG_EXTPAGETYPE_SAS_PHY;
2516 2516
2517 cfg.cfghdr.ehdr = &hdr; 2517 cfg.cfghdr.ehdr = &hdr;
2518 cfg.dir = 0; /* read */ 2518 cfg.dir = 0; /* read */
2519 cfg.timeout = SAS_CONFIG_PAGE_TIMEOUT; 2519 cfg.timeout = SAS_CONFIG_PAGE_TIMEOUT;
2520 2520
2521 /* Get Phy Pg 0 for each Phy. */ 2521 /* Get Phy Pg 0 for each Phy. */
2522 cfg.physAddr = -1; 2522 cfg.physAddr = -1;
2523 cfg.pageAddr = form + form_specific; 2523 cfg.pageAddr = form + form_specific;
2524 cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER; 2524 cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
2525 2525
2526 error = mpt_config(ioc, &cfg); 2526 error = mpt_config(ioc, &cfg);
2527 if (error) 2527 if (error)
2528 goto out; 2528 goto out;
2529 2529
2530 if (!hdr.ExtPageLength) { 2530 if (!hdr.ExtPageLength) {
2531 error = -ENXIO; 2531 error = -ENXIO;
2532 goto out; 2532 goto out;
2533 } 2533 }
2534 2534
2535 buffer = pci_alloc_consistent(ioc->pcidev, hdr.ExtPageLength * 4, 2535 buffer = pci_alloc_consistent(ioc->pcidev, hdr.ExtPageLength * 4,
2536 &dma_handle); 2536 &dma_handle);
2537 if (!buffer) { 2537 if (!buffer) {
2538 error = -ENOMEM; 2538 error = -ENOMEM;
2539 goto out; 2539 goto out;
2540 } 2540 }
2541 2541
2542 cfg.physAddr = dma_handle; 2542 cfg.physAddr = dma_handle;
2543 cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT; 2543 cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
2544 2544
2545 error = mpt_config(ioc, &cfg); 2545 error = mpt_config(ioc, &cfg);
2546 if (error) 2546 if (error)
2547 goto out_free_consistent; 2547 goto out_free_consistent;
2548 2548
2549 mptsas_print_phy_pg0(ioc, buffer); 2549 mptsas_print_phy_pg0(ioc, buffer);
2550 2550
2551 phy_info->hw_link_rate = buffer->HwLinkRate; 2551 phy_info->hw_link_rate = buffer->HwLinkRate;
2552 phy_info->programmed_link_rate = buffer->ProgrammedLinkRate; 2552 phy_info->programmed_link_rate = buffer->ProgrammedLinkRate;
2553 phy_info->identify.handle = le16_to_cpu(buffer->OwnerDevHandle); 2553 phy_info->identify.handle = le16_to_cpu(buffer->OwnerDevHandle);
2554 phy_info->attached.handle = le16_to_cpu(buffer->AttachedDevHandle); 2554 phy_info->attached.handle = le16_to_cpu(buffer->AttachedDevHandle);
2555 2555
2556 out_free_consistent: 2556 out_free_consistent:
2557 pci_free_consistent(ioc->pcidev, hdr.ExtPageLength * 4, 2557 pci_free_consistent(ioc->pcidev, hdr.ExtPageLength * 4,
2558 buffer, dma_handle); 2558 buffer, dma_handle);
2559 out: 2559 out:
2560 return error; 2560 return error;
2561 } 2561 }
2562 2562
2563 static int 2563 static int
2564 mptsas_sas_device_pg0(MPT_ADAPTER *ioc, struct mptsas_devinfo *device_info, 2564 mptsas_sas_device_pg0(MPT_ADAPTER *ioc, struct mptsas_devinfo *device_info,
2565 u32 form, u32 form_specific) 2565 u32 form, u32 form_specific)
2566 { 2566 {
2567 ConfigExtendedPageHeader_t hdr; 2567 ConfigExtendedPageHeader_t hdr;
2568 CONFIGPARMS cfg; 2568 CONFIGPARMS cfg;
2569 SasDevicePage0_t *buffer; 2569 SasDevicePage0_t *buffer;
2570 dma_addr_t dma_handle; 2570 dma_addr_t dma_handle;
2571 __le64 sas_address; 2571 __le64 sas_address;
2572 int error=0; 2572 int error=0;
2573 2573
2574 hdr.PageVersion = MPI_SASDEVICE0_PAGEVERSION; 2574 hdr.PageVersion = MPI_SASDEVICE0_PAGEVERSION;
2575 hdr.ExtPageLength = 0; 2575 hdr.ExtPageLength = 0;
2576 hdr.PageNumber = 0; 2576 hdr.PageNumber = 0;
2577 hdr.Reserved1 = 0; 2577 hdr.Reserved1 = 0;
2578 hdr.Reserved2 = 0; 2578 hdr.Reserved2 = 0;
2579 hdr.PageType = MPI_CONFIG_PAGETYPE_EXTENDED; 2579 hdr.PageType = MPI_CONFIG_PAGETYPE_EXTENDED;
2580 hdr.ExtPageType = MPI_CONFIG_EXTPAGETYPE_SAS_DEVICE; 2580 hdr.ExtPageType = MPI_CONFIG_EXTPAGETYPE_SAS_DEVICE;
2581 2581
2582 cfg.cfghdr.ehdr = &hdr; 2582 cfg.cfghdr.ehdr = &hdr;
2583 cfg.pageAddr = form + form_specific; 2583 cfg.pageAddr = form + form_specific;
2584 cfg.physAddr = -1; 2584 cfg.physAddr = -1;
2585 cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER; 2585 cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
2586 cfg.dir = 0; /* read */ 2586 cfg.dir = 0; /* read */
2587 cfg.timeout = SAS_CONFIG_PAGE_TIMEOUT; 2587 cfg.timeout = SAS_CONFIG_PAGE_TIMEOUT;
2588 2588
2589 memset(device_info, 0, sizeof(struct mptsas_devinfo)); 2589 memset(device_info, 0, sizeof(struct mptsas_devinfo));
2590 error = mpt_config(ioc, &cfg); 2590 error = mpt_config(ioc, &cfg);
2591 if (error) 2591 if (error)
2592 goto out; 2592 goto out;
2593 if (!hdr.ExtPageLength) { 2593 if (!hdr.ExtPageLength) {
2594 error = -ENXIO; 2594 error = -ENXIO;
2595 goto out; 2595 goto out;
2596 } 2596 }
2597 2597
2598 buffer = pci_alloc_consistent(ioc->pcidev, hdr.ExtPageLength * 4, 2598 buffer = pci_alloc_consistent(ioc->pcidev, hdr.ExtPageLength * 4,
2599 &dma_handle); 2599 &dma_handle);
2600 if (!buffer) { 2600 if (!buffer) {
2601 error = -ENOMEM; 2601 error = -ENOMEM;
2602 goto out; 2602 goto out;
2603 } 2603 }
2604 2604
2605 cfg.physAddr = dma_handle; 2605 cfg.physAddr = dma_handle;
2606 cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT; 2606 cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
2607 2607
2608 error = mpt_config(ioc, &cfg); 2608 error = mpt_config(ioc, &cfg);
2609 2609
2610 if (error == MPI_IOCSTATUS_CONFIG_INVALID_PAGE) { 2610 if (error == MPI_IOCSTATUS_CONFIG_INVALID_PAGE) {
2611 error = -ENODEV; 2611 error = -ENODEV;
2612 goto out_free_consistent; 2612 goto out_free_consistent;
2613 } 2613 }
2614 2614
2615 if (error) 2615 if (error)
2616 goto out_free_consistent; 2616 goto out_free_consistent;
2617 2617
2618 mptsas_print_device_pg0(ioc, buffer); 2618 mptsas_print_device_pg0(ioc, buffer);
2619 2619
2620 memset(device_info, 0, sizeof(struct mptsas_devinfo)); 2620 memset(device_info, 0, sizeof(struct mptsas_devinfo));
2621 device_info->handle = le16_to_cpu(buffer->DevHandle); 2621 device_info->handle = le16_to_cpu(buffer->DevHandle);
2622 device_info->handle_parent = le16_to_cpu(buffer->ParentDevHandle); 2622 device_info->handle_parent = le16_to_cpu(buffer->ParentDevHandle);
2623 device_info->handle_enclosure = 2623 device_info->handle_enclosure =
2624 le16_to_cpu(buffer->EnclosureHandle); 2624 le16_to_cpu(buffer->EnclosureHandle);
2625 device_info->slot = le16_to_cpu(buffer->Slot); 2625 device_info->slot = le16_to_cpu(buffer->Slot);
2626 device_info->phy_id = buffer->PhyNum; 2626 device_info->phy_id = buffer->PhyNum;
2627 device_info->port_id = buffer->PhysicalPort; 2627 device_info->port_id = buffer->PhysicalPort;
2628 device_info->id = buffer->TargetID; 2628 device_info->id = buffer->TargetID;
2629 device_info->phys_disk_num = ~0; 2629 device_info->phys_disk_num = ~0;
2630 device_info->channel = buffer->Bus; 2630 device_info->channel = buffer->Bus;
2631 memcpy(&sas_address, &buffer->SASAddress, sizeof(__le64)); 2631 memcpy(&sas_address, &buffer->SASAddress, sizeof(__le64));
2632 device_info->sas_address = le64_to_cpu(sas_address); 2632 device_info->sas_address = le64_to_cpu(sas_address);
2633 device_info->device_info = 2633 device_info->device_info =
2634 le32_to_cpu(buffer->DeviceInfo); 2634 le32_to_cpu(buffer->DeviceInfo);
2635 device_info->flags = le16_to_cpu(buffer->Flags); 2635 device_info->flags = le16_to_cpu(buffer->Flags);
2636 2636
2637 out_free_consistent: 2637 out_free_consistent:
2638 pci_free_consistent(ioc->pcidev, hdr.ExtPageLength * 4, 2638 pci_free_consistent(ioc->pcidev, hdr.ExtPageLength * 4,
2639 buffer, dma_handle); 2639 buffer, dma_handle);
2640 out: 2640 out:
2641 return error; 2641 return error;
2642 } 2642 }
2643 2643
2644 static int 2644 static int
2645 mptsas_sas_expander_pg0(MPT_ADAPTER *ioc, struct mptsas_portinfo *port_info, 2645 mptsas_sas_expander_pg0(MPT_ADAPTER *ioc, struct mptsas_portinfo *port_info,
2646 u32 form, u32 form_specific) 2646 u32 form, u32 form_specific)
2647 { 2647 {
2648 ConfigExtendedPageHeader_t hdr; 2648 ConfigExtendedPageHeader_t hdr;
2649 CONFIGPARMS cfg; 2649 CONFIGPARMS cfg;
2650 SasExpanderPage0_t *buffer; 2650 SasExpanderPage0_t *buffer;
2651 dma_addr_t dma_handle; 2651 dma_addr_t dma_handle;
2652 int i, error; 2652 int i, error;
2653 __le64 sas_address; 2653 __le64 sas_address;
2654 2654
2655 memset(port_info, 0, sizeof(struct mptsas_portinfo)); 2655 memset(port_info, 0, sizeof(struct mptsas_portinfo));
2656 hdr.PageVersion = MPI_SASEXPANDER0_PAGEVERSION; 2656 hdr.PageVersion = MPI_SASEXPANDER0_PAGEVERSION;
2657 hdr.ExtPageLength = 0; 2657 hdr.ExtPageLength = 0;
2658 hdr.PageNumber = 0; 2658 hdr.PageNumber = 0;
2659 hdr.Reserved1 = 0; 2659 hdr.Reserved1 = 0;
2660 hdr.Reserved2 = 0; 2660 hdr.Reserved2 = 0;
2661 hdr.PageType = MPI_CONFIG_PAGETYPE_EXTENDED; 2661 hdr.PageType = MPI_CONFIG_PAGETYPE_EXTENDED;
2662 hdr.ExtPageType = MPI_CONFIG_EXTPAGETYPE_SAS_EXPANDER; 2662 hdr.ExtPageType = MPI_CONFIG_EXTPAGETYPE_SAS_EXPANDER;
2663 2663
2664 cfg.cfghdr.ehdr = &hdr; 2664 cfg.cfghdr.ehdr = &hdr;
2665 cfg.physAddr = -1; 2665 cfg.physAddr = -1;
2666 cfg.pageAddr = form + form_specific; 2666 cfg.pageAddr = form + form_specific;
2667 cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER; 2667 cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
2668 cfg.dir = 0; /* read */ 2668 cfg.dir = 0; /* read */
2669 cfg.timeout = SAS_CONFIG_PAGE_TIMEOUT; 2669 cfg.timeout = SAS_CONFIG_PAGE_TIMEOUT;
2670 2670
2671 memset(port_info, 0, sizeof(struct mptsas_portinfo)); 2671 memset(port_info, 0, sizeof(struct mptsas_portinfo));
2672 error = mpt_config(ioc, &cfg); 2672 error = mpt_config(ioc, &cfg);
2673 if (error) 2673 if (error)
2674 goto out; 2674 goto out;
2675 2675
2676 if (!hdr.ExtPageLength) { 2676 if (!hdr.ExtPageLength) {
2677 error = -ENXIO; 2677 error = -ENXIO;
2678 goto out; 2678 goto out;
2679 } 2679 }
2680 2680
2681 buffer = pci_alloc_consistent(ioc->pcidev, hdr.ExtPageLength * 4, 2681 buffer = pci_alloc_consistent(ioc->pcidev, hdr.ExtPageLength * 4,
2682 &dma_handle); 2682 &dma_handle);
2683 if (!buffer) { 2683 if (!buffer) {
2684 error = -ENOMEM; 2684 error = -ENOMEM;
2685 goto out; 2685 goto out;
2686 } 2686 }
2687 2687
2688 cfg.physAddr = dma_handle; 2688 cfg.physAddr = dma_handle;
2689 cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT; 2689 cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
2690 2690
2691 error = mpt_config(ioc, &cfg); 2691 error = mpt_config(ioc, &cfg);
2692 if (error == MPI_IOCSTATUS_CONFIG_INVALID_PAGE) { 2692 if (error == MPI_IOCSTATUS_CONFIG_INVALID_PAGE) {
2693 error = -ENODEV; 2693 error = -ENODEV;
2694 goto out_free_consistent; 2694 goto out_free_consistent;
2695 } 2695 }
2696 2696
2697 if (error) 2697 if (error)
2698 goto out_free_consistent; 2698 goto out_free_consistent;
2699 2699
2700 /* save config data */ 2700 /* save config data */
2701 port_info->num_phys = (buffer->NumPhys) ? buffer->NumPhys : 1; 2701 port_info->num_phys = (buffer->NumPhys) ? buffer->NumPhys : 1;
2702 port_info->phy_info = kcalloc(port_info->num_phys, 2702 port_info->phy_info = kcalloc(port_info->num_phys,
2703 sizeof(struct mptsas_phyinfo), GFP_KERNEL); 2703 sizeof(struct mptsas_phyinfo), GFP_KERNEL);
2704 if (!port_info->phy_info) { 2704 if (!port_info->phy_info) {
2705 error = -ENOMEM; 2705 error = -ENOMEM;
2706 goto out_free_consistent; 2706 goto out_free_consistent;
2707 } 2707 }
2708 2708
2709 memcpy(&sas_address, &buffer->SASAddress, sizeof(__le64)); 2709 memcpy(&sas_address, &buffer->SASAddress, sizeof(__le64));
2710 for (i = 0; i < port_info->num_phys; i++) { 2710 for (i = 0; i < port_info->num_phys; i++) {
2711 port_info->phy_info[i].portinfo = port_info; 2711 port_info->phy_info[i].portinfo = port_info;
2712 port_info->phy_info[i].handle = 2712 port_info->phy_info[i].handle =
2713 le16_to_cpu(buffer->DevHandle); 2713 le16_to_cpu(buffer->DevHandle);
2714 port_info->phy_info[i].identify.sas_address = 2714 port_info->phy_info[i].identify.sas_address =
2715 le64_to_cpu(sas_address); 2715 le64_to_cpu(sas_address);
2716 port_info->phy_info[i].identify.handle_parent = 2716 port_info->phy_info[i].identify.handle_parent =
2717 le16_to_cpu(buffer->ParentDevHandle); 2717 le16_to_cpu(buffer->ParentDevHandle);
2718 } 2718 }
2719 2719
2720 out_free_consistent: 2720 out_free_consistent:
2721 pci_free_consistent(ioc->pcidev, hdr.ExtPageLength * 4, 2721 pci_free_consistent(ioc->pcidev, hdr.ExtPageLength * 4,
2722 buffer, dma_handle); 2722 buffer, dma_handle);
2723 out: 2723 out:
2724 return error; 2724 return error;
2725 } 2725 }
2726 2726
2727 static int 2727 static int
2728 mptsas_sas_expander_pg1(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, 2728 mptsas_sas_expander_pg1(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info,
2729 u32 form, u32 form_specific) 2729 u32 form, u32 form_specific)
2730 { 2730 {
2731 ConfigExtendedPageHeader_t hdr; 2731 ConfigExtendedPageHeader_t hdr;
2732 CONFIGPARMS cfg; 2732 CONFIGPARMS cfg;
2733 SasExpanderPage1_t *buffer; 2733 SasExpanderPage1_t *buffer;
2734 dma_addr_t dma_handle; 2734 dma_addr_t dma_handle;
2735 int error=0; 2735 int error=0;
2736 2736
2737 hdr.PageVersion = MPI_SASEXPANDER1_PAGEVERSION; 2737 hdr.PageVersion = MPI_SASEXPANDER1_PAGEVERSION;
2738 hdr.ExtPageLength = 0; 2738 hdr.ExtPageLength = 0;
2739 hdr.PageNumber = 1; 2739 hdr.PageNumber = 1;
2740 hdr.Reserved1 = 0; 2740 hdr.Reserved1 = 0;
2741 hdr.Reserved2 = 0; 2741 hdr.Reserved2 = 0;
2742 hdr.PageType = MPI_CONFIG_PAGETYPE_EXTENDED; 2742 hdr.PageType = MPI_CONFIG_PAGETYPE_EXTENDED;
2743 hdr.ExtPageType = MPI_CONFIG_EXTPAGETYPE_SAS_EXPANDER; 2743 hdr.ExtPageType = MPI_CONFIG_EXTPAGETYPE_SAS_EXPANDER;
2744 2744
2745 cfg.cfghdr.ehdr = &hdr; 2745 cfg.cfghdr.ehdr = &hdr;
2746 cfg.physAddr = -1; 2746 cfg.physAddr = -1;
2747 cfg.pageAddr = form + form_specific; 2747 cfg.pageAddr = form + form_specific;
2748 cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER; 2748 cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
2749 cfg.dir = 0; /* read */ 2749 cfg.dir = 0; /* read */
2750 cfg.timeout = SAS_CONFIG_PAGE_TIMEOUT; 2750 cfg.timeout = SAS_CONFIG_PAGE_TIMEOUT;
2751 2751
2752 error = mpt_config(ioc, &cfg); 2752 error = mpt_config(ioc, &cfg);
2753 if (error) 2753 if (error)
2754 goto out; 2754 goto out;
2755 2755
2756 if (!hdr.ExtPageLength) { 2756 if (!hdr.ExtPageLength) {
2757 error = -ENXIO; 2757 error = -ENXIO;
2758 goto out; 2758 goto out;
2759 } 2759 }
2760 2760
2761 buffer = pci_alloc_consistent(ioc->pcidev, hdr.ExtPageLength * 4, 2761 buffer = pci_alloc_consistent(ioc->pcidev, hdr.ExtPageLength * 4,
2762 &dma_handle); 2762 &dma_handle);
2763 if (!buffer) { 2763 if (!buffer) {
2764 error = -ENOMEM; 2764 error = -ENOMEM;
2765 goto out; 2765 goto out;
2766 } 2766 }
2767 2767
2768 cfg.physAddr = dma_handle; 2768 cfg.physAddr = dma_handle;
2769 cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT; 2769 cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
2770 2770
2771 error = mpt_config(ioc, &cfg); 2771 error = mpt_config(ioc, &cfg);
2772 2772
2773 if (error == MPI_IOCSTATUS_CONFIG_INVALID_PAGE) { 2773 if (error == MPI_IOCSTATUS_CONFIG_INVALID_PAGE) {
2774 error = -ENODEV; 2774 error = -ENODEV;
2775 goto out_free_consistent; 2775 goto out_free_consistent;
2776 } 2776 }
2777 2777
2778 if (error) 2778 if (error)
2779 goto out_free_consistent; 2779 goto out_free_consistent;
2780 2780
2781 2781
2782 mptsas_print_expander_pg1(ioc, buffer); 2782 mptsas_print_expander_pg1(ioc, buffer);
2783 2783
2784 /* save config data */ 2784 /* save config data */
2785 phy_info->phy_id = buffer->PhyIdentifier; 2785 phy_info->phy_id = buffer->PhyIdentifier;
2786 phy_info->port_id = buffer->PhysicalPort; 2786 phy_info->port_id = buffer->PhysicalPort;
2787 phy_info->negotiated_link_rate = buffer->NegotiatedLinkRate; 2787 phy_info->negotiated_link_rate = buffer->NegotiatedLinkRate;
2788 phy_info->programmed_link_rate = buffer->ProgrammedLinkRate; 2788 phy_info->programmed_link_rate = buffer->ProgrammedLinkRate;
2789 phy_info->hw_link_rate = buffer->HwLinkRate; 2789 phy_info->hw_link_rate = buffer->HwLinkRate;
2790 phy_info->identify.handle = le16_to_cpu(buffer->OwnerDevHandle); 2790 phy_info->identify.handle = le16_to_cpu(buffer->OwnerDevHandle);
2791 phy_info->attached.handle = le16_to_cpu(buffer->AttachedDevHandle); 2791 phy_info->attached.handle = le16_to_cpu(buffer->AttachedDevHandle);
2792 2792
2793 out_free_consistent: 2793 out_free_consistent:
2794 pci_free_consistent(ioc->pcidev, hdr.ExtPageLength * 4, 2794 pci_free_consistent(ioc->pcidev, hdr.ExtPageLength * 4,
2795 buffer, dma_handle); 2795 buffer, dma_handle);
2796 out: 2796 out:
2797 return error; 2797 return error;
2798 } 2798 }
2799 2799
2800 struct rep_manu_request{ 2800 struct rep_manu_request{
2801 u8 smp_frame_type; 2801 u8 smp_frame_type;
2802 u8 function; 2802 u8 function;
2803 u8 reserved; 2803 u8 reserved;
2804 u8 request_length; 2804 u8 request_length;
2805 }; 2805 };
2806 2806
2807 struct rep_manu_reply{ 2807 struct rep_manu_reply{
2808 u8 smp_frame_type; /* 0x41 */ 2808 u8 smp_frame_type; /* 0x41 */
2809 u8 function; /* 0x01 */ 2809 u8 function; /* 0x01 */
2810 u8 function_result; 2810 u8 function_result;
2811 u8 response_length; 2811 u8 response_length;
2812 u16 expander_change_count; 2812 u16 expander_change_count;
2813 u8 reserved0[2]; 2813 u8 reserved0[2];
2814 u8 sas_format:1; 2814 u8 sas_format:1;
2815 u8 reserved1:7; 2815 u8 reserved1:7;
2816 u8 reserved2[3]; 2816 u8 reserved2[3];
2817 u8 vendor_id[SAS_EXPANDER_VENDOR_ID_LEN]; 2817 u8 vendor_id[SAS_EXPANDER_VENDOR_ID_LEN];
2818 u8 product_id[SAS_EXPANDER_PRODUCT_ID_LEN]; 2818 u8 product_id[SAS_EXPANDER_PRODUCT_ID_LEN];
2819 u8 product_rev[SAS_EXPANDER_PRODUCT_REV_LEN]; 2819 u8 product_rev[SAS_EXPANDER_PRODUCT_REV_LEN];
2820 u8 component_vendor_id[SAS_EXPANDER_COMPONENT_VENDOR_ID_LEN]; 2820 u8 component_vendor_id[SAS_EXPANDER_COMPONENT_VENDOR_ID_LEN];
2821 u16 component_id; 2821 u16 component_id;
2822 u8 component_revision_id; 2822 u8 component_revision_id;
2823 u8 reserved3; 2823 u8 reserved3;
2824 u8 vendor_specific[8]; 2824 u8 vendor_specific[8];
2825 }; 2825 };
2826 2826
2827 /** 2827 /**
2828 * mptsas_exp_repmanufacture_info - 2828 * mptsas_exp_repmanufacture_info -
2829 * @ioc: per adapter object 2829 * @ioc: per adapter object
2830 * @sas_address: expander sas address 2830 * @sas_address: expander sas address
2831 * @edev: the sas_expander_device object 2831 * @edev: the sas_expander_device object
2832 * 2832 *
2833 * Fills in the sas_expander_device object when SMP port is created. 2833 * Fills in the sas_expander_device object when SMP port is created.
2834 * 2834 *
2835 * Returns 0 for success, non-zero for failure. 2835 * Returns 0 for success, non-zero for failure.
2836 */ 2836 */
2837 static int 2837 static int
2838 mptsas_exp_repmanufacture_info(MPT_ADAPTER *ioc, 2838 mptsas_exp_repmanufacture_info(MPT_ADAPTER *ioc,
2839 u64 sas_address, struct sas_expander_device *edev) 2839 u64 sas_address, struct sas_expander_device *edev)
2840 { 2840 {
2841 MPT_FRAME_HDR *mf; 2841 MPT_FRAME_HDR *mf;
2842 SmpPassthroughRequest_t *smpreq; 2842 SmpPassthroughRequest_t *smpreq;
2843 SmpPassthroughReply_t *smprep; 2843 SmpPassthroughReply_t *smprep;
2844 struct rep_manu_reply *manufacture_reply; 2844 struct rep_manu_reply *manufacture_reply;
2845 struct rep_manu_request *manufacture_request; 2845 struct rep_manu_request *manufacture_request;
2846 int ret; 2846 int ret;
2847 int flagsLength; 2847 int flagsLength;
2848 unsigned long timeleft; 2848 unsigned long timeleft;
2849 char *psge; 2849 char *psge;
2850 unsigned long flags; 2850 unsigned long flags;
2851 void *data_out = NULL; 2851 void *data_out = NULL;
2852 dma_addr_t data_out_dma = 0; 2852 dma_addr_t data_out_dma = 0;
2853 u32 sz; 2853 u32 sz;
2854 2854
2855 spin_lock_irqsave(&ioc->taskmgmt_lock, flags); 2855 spin_lock_irqsave(&ioc->taskmgmt_lock, flags);
2856 if (ioc->ioc_reset_in_progress) { 2856 if (ioc->ioc_reset_in_progress) {
2857 spin_unlock_irqrestore(&ioc->taskmgmt_lock, flags); 2857 spin_unlock_irqrestore(&ioc->taskmgmt_lock, flags);
2858 printk(MYIOC_s_INFO_FMT "%s: host reset in progress!\n", 2858 printk(MYIOC_s_INFO_FMT "%s: host reset in progress!\n",
2859 __func__, ioc->name); 2859 __func__, ioc->name);
2860 return -EFAULT; 2860 return -EFAULT;
2861 } 2861 }
2862 spin_unlock_irqrestore(&ioc->taskmgmt_lock, flags); 2862 spin_unlock_irqrestore(&ioc->taskmgmt_lock, flags);
2863 2863
2864 ret = mutex_lock_interruptible(&ioc->sas_mgmt.mutex); 2864 ret = mutex_lock_interruptible(&ioc->sas_mgmt.mutex);
2865 if (ret) 2865 if (ret)
2866 goto out; 2866 goto out;
2867 2867
2868 mf = mpt_get_msg_frame(mptsasMgmtCtx, ioc); 2868 mf = mpt_get_msg_frame(mptsasMgmtCtx, ioc);
2869 if (!mf) { 2869 if (!mf) {
2870 ret = -ENOMEM; 2870 ret = -ENOMEM;
2871 goto out_unlock; 2871 goto out_unlock;
2872 } 2872 }
2873 2873
2874 smpreq = (SmpPassthroughRequest_t *)mf; 2874 smpreq = (SmpPassthroughRequest_t *)mf;
2875 memset(smpreq, 0, sizeof(*smpreq)); 2875 memset(smpreq, 0, sizeof(*smpreq));
2876 2876
2877 sz = sizeof(struct rep_manu_request) + sizeof(struct rep_manu_reply); 2877 sz = sizeof(struct rep_manu_request) + sizeof(struct rep_manu_reply);
2878 2878
2879 data_out = pci_alloc_consistent(ioc->pcidev, sz, &data_out_dma); 2879 data_out = pci_alloc_consistent(ioc->pcidev, sz, &data_out_dma);
2880 if (!data_out) { 2880 if (!data_out) {
2881 printk(KERN_ERR "Memory allocation failure at %s:%d/%s()!\n", 2881 printk(KERN_ERR "Memory allocation failure at %s:%d/%s()!\n",
2882 __FILE__, __LINE__, __func__); 2882 __FILE__, __LINE__, __func__);
2883 ret = -ENOMEM; 2883 ret = -ENOMEM;
2884 goto put_mf; 2884 goto put_mf;
2885 } 2885 }
2886 2886
2887 manufacture_request = data_out; 2887 manufacture_request = data_out;
2888 manufacture_request->smp_frame_type = 0x40; 2888 manufacture_request->smp_frame_type = 0x40;
2889 manufacture_request->function = 1; 2889 manufacture_request->function = 1;
2890 manufacture_request->reserved = 0; 2890 manufacture_request->reserved = 0;
2891 manufacture_request->request_length = 0; 2891 manufacture_request->request_length = 0;
2892 2892
2893 smpreq->Function = MPI_FUNCTION_SMP_PASSTHROUGH; 2893 smpreq->Function = MPI_FUNCTION_SMP_PASSTHROUGH;
2894 smpreq->PhysicalPort = 0xFF; 2894 smpreq->PhysicalPort = 0xFF;
2895 *((u64 *)&smpreq->SASAddress) = cpu_to_le64(sas_address); 2895 *((u64 *)&smpreq->SASAddress) = cpu_to_le64(sas_address);
2896 smpreq->RequestDataLength = sizeof(struct rep_manu_request); 2896 smpreq->RequestDataLength = sizeof(struct rep_manu_request);
2897 2897
2898 psge = (char *) 2898 psge = (char *)
2899 (((int *) mf) + (offsetof(SmpPassthroughRequest_t, SGL) / 4)); 2899 (((int *) mf) + (offsetof(SmpPassthroughRequest_t, SGL) / 4));
2900 2900
2901 flagsLength = MPI_SGE_FLAGS_SIMPLE_ELEMENT | 2901 flagsLength = MPI_SGE_FLAGS_SIMPLE_ELEMENT |
2902 MPI_SGE_FLAGS_SYSTEM_ADDRESS | 2902 MPI_SGE_FLAGS_SYSTEM_ADDRESS |
2903 MPI_SGE_FLAGS_HOST_TO_IOC | 2903 MPI_SGE_FLAGS_HOST_TO_IOC |
2904 MPI_SGE_FLAGS_END_OF_BUFFER; 2904 MPI_SGE_FLAGS_END_OF_BUFFER;
2905 flagsLength = flagsLength << MPI_SGE_FLAGS_SHIFT; 2905 flagsLength = flagsLength << MPI_SGE_FLAGS_SHIFT;
2906 flagsLength |= sizeof(struct rep_manu_request); 2906 flagsLength |= sizeof(struct rep_manu_request);
2907 2907
2908 ioc->add_sge(psge, flagsLength, data_out_dma); 2908 ioc->add_sge(psge, flagsLength, data_out_dma);
2909 psge += ioc->SGE_size; 2909 psge += ioc->SGE_size;
2910 2910
2911 flagsLength = MPI_SGE_FLAGS_SIMPLE_ELEMENT | 2911 flagsLength = MPI_SGE_FLAGS_SIMPLE_ELEMENT |
2912 MPI_SGE_FLAGS_SYSTEM_ADDRESS | 2912 MPI_SGE_FLAGS_SYSTEM_ADDRESS |
2913 MPI_SGE_FLAGS_IOC_TO_HOST | 2913 MPI_SGE_FLAGS_IOC_TO_HOST |
2914 MPI_SGE_FLAGS_END_OF_BUFFER; 2914 MPI_SGE_FLAGS_END_OF_BUFFER;
2915 flagsLength = flagsLength << MPI_SGE_FLAGS_SHIFT; 2915 flagsLength = flagsLength << MPI_SGE_FLAGS_SHIFT;
2916 flagsLength |= sizeof(struct rep_manu_reply); 2916 flagsLength |= sizeof(struct rep_manu_reply);
2917 ioc->add_sge(psge, flagsLength, data_out_dma + 2917 ioc->add_sge(psge, flagsLength, data_out_dma +
2918 sizeof(struct rep_manu_request)); 2918 sizeof(struct rep_manu_request));
2919 2919
2920 INITIALIZE_MGMT_STATUS(ioc->sas_mgmt.status) 2920 INITIALIZE_MGMT_STATUS(ioc->sas_mgmt.status)
2921 mpt_put_msg_frame(mptsasMgmtCtx, ioc, mf); 2921 mpt_put_msg_frame(mptsasMgmtCtx, ioc, mf);
2922 2922
2923 timeleft = wait_for_completion_timeout(&ioc->sas_mgmt.done, 10 * HZ); 2923 timeleft = wait_for_completion_timeout(&ioc->sas_mgmt.done, 10 * HZ);
2924 if (!(ioc->sas_mgmt.status & MPT_MGMT_STATUS_COMMAND_GOOD)) { 2924 if (!(ioc->sas_mgmt.status & MPT_MGMT_STATUS_COMMAND_GOOD)) {
2925 ret = -ETIME; 2925 ret = -ETIME;
2926 mpt_free_msg_frame(ioc, mf); 2926 mpt_free_msg_frame(ioc, mf);
2927 mf = NULL; 2927 mf = NULL;
2928 if (ioc->sas_mgmt.status & MPT_MGMT_STATUS_DID_IOCRESET) 2928 if (ioc->sas_mgmt.status & MPT_MGMT_STATUS_DID_IOCRESET)
2929 goto out_free; 2929 goto out_free;
2930 if (!timeleft) 2930 if (!timeleft)
2931 mpt_Soft_Hard_ResetHandler(ioc, CAN_SLEEP); 2931 mpt_Soft_Hard_ResetHandler(ioc, CAN_SLEEP);
2932 goto out_free; 2932 goto out_free;
2933 } 2933 }
2934 2934
2935 mf = NULL; 2935 mf = NULL;
2936 2936
2937 if (ioc->sas_mgmt.status & MPT_MGMT_STATUS_RF_VALID) { 2937 if (ioc->sas_mgmt.status & MPT_MGMT_STATUS_RF_VALID) {
2938 u8 *tmp; 2938 u8 *tmp;
2939 2939
2940 smprep = (SmpPassthroughReply_t *)ioc->sas_mgmt.reply; 2940 smprep = (SmpPassthroughReply_t *)ioc->sas_mgmt.reply;
2941 if (le16_to_cpu(smprep->ResponseDataLength) != 2941 if (le16_to_cpu(smprep->ResponseDataLength) !=
2942 sizeof(struct rep_manu_reply)) 2942 sizeof(struct rep_manu_reply))
2943 goto out_free; 2943 goto out_free;
2944 2944
2945 manufacture_reply = data_out + sizeof(struct rep_manu_request); 2945 manufacture_reply = data_out + sizeof(struct rep_manu_request);
2946 strncpy(edev->vendor_id, manufacture_reply->vendor_id, 2946 strncpy(edev->vendor_id, manufacture_reply->vendor_id,
2947 SAS_EXPANDER_VENDOR_ID_LEN); 2947 SAS_EXPANDER_VENDOR_ID_LEN);
2948 strncpy(edev->product_id, manufacture_reply->product_id, 2948 strncpy(edev->product_id, manufacture_reply->product_id,
2949 SAS_EXPANDER_PRODUCT_ID_LEN); 2949 SAS_EXPANDER_PRODUCT_ID_LEN);
2950 strncpy(edev->product_rev, manufacture_reply->product_rev, 2950 strncpy(edev->product_rev, manufacture_reply->product_rev,
2951 SAS_EXPANDER_PRODUCT_REV_LEN); 2951 SAS_EXPANDER_PRODUCT_REV_LEN);
2952 edev->level = manufacture_reply->sas_format; 2952 edev->level = manufacture_reply->sas_format;
2953 if (manufacture_reply->sas_format) { 2953 if (manufacture_reply->sas_format) {
2954 strncpy(edev->component_vendor_id, 2954 strncpy(edev->component_vendor_id,
2955 manufacture_reply->component_vendor_id, 2955 manufacture_reply->component_vendor_id,
2956 SAS_EXPANDER_COMPONENT_VENDOR_ID_LEN); 2956 SAS_EXPANDER_COMPONENT_VENDOR_ID_LEN);
2957 tmp = (u8 *)&manufacture_reply->component_id; 2957 tmp = (u8 *)&manufacture_reply->component_id;
2958 edev->component_id = tmp[0] << 8 | tmp[1]; 2958 edev->component_id = tmp[0] << 8 | tmp[1];
2959 edev->component_revision_id = 2959 edev->component_revision_id =
2960 manufacture_reply->component_revision_id; 2960 manufacture_reply->component_revision_id;
2961 } 2961 }
2962 } else { 2962 } else {
2963 printk(MYIOC_s_ERR_FMT 2963 printk(MYIOC_s_ERR_FMT
2964 "%s: smp passthru reply failed to be returned\n", 2964 "%s: smp passthru reply failed to be returned\n",
2965 ioc->name, __func__); 2965 ioc->name, __func__);
2966 ret = -ENXIO; 2966 ret = -ENXIO;
2967 } 2967 }
2968 out_free: 2968 out_free:
2969 if (data_out_dma) 2969 if (data_out_dma)
2970 pci_free_consistent(ioc->pcidev, sz, data_out, data_out_dma); 2970 pci_free_consistent(ioc->pcidev, sz, data_out, data_out_dma);
2971 put_mf: 2971 put_mf:
2972 if (mf) 2972 if (mf)
2973 mpt_free_msg_frame(ioc, mf); 2973 mpt_free_msg_frame(ioc, mf);
2974 out_unlock: 2974 out_unlock:
2975 CLEAR_MGMT_STATUS(ioc->sas_mgmt.status) 2975 CLEAR_MGMT_STATUS(ioc->sas_mgmt.status)
2976 mutex_unlock(&ioc->sas_mgmt.mutex); 2976 mutex_unlock(&ioc->sas_mgmt.mutex);
2977 out: 2977 out:
2978 return ret; 2978 return ret;
2979 } 2979 }
2980 2980
2981 static void 2981 static void
2982 mptsas_parse_device_info(struct sas_identify *identify, 2982 mptsas_parse_device_info(struct sas_identify *identify,
2983 struct mptsas_devinfo *device_info) 2983 struct mptsas_devinfo *device_info)
2984 { 2984 {
2985 u16 protocols; 2985 u16 protocols;
2986 2986
2987 identify->sas_address = device_info->sas_address; 2987 identify->sas_address = device_info->sas_address;
2988 identify->phy_identifier = device_info->phy_id; 2988 identify->phy_identifier = device_info->phy_id;
2989 2989
2990 /* 2990 /*
2991 * Fill in Phy Initiator Port Protocol. 2991 * Fill in Phy Initiator Port Protocol.
2992 * Bits 6:3, more than one bit can be set, fall through cases. 2992 * Bits 6:3, more than one bit can be set, fall through cases.
2993 */ 2993 */
2994 protocols = device_info->device_info & 0x78; 2994 protocols = device_info->device_info & 0x78;
2995 identify->initiator_port_protocols = 0; 2995 identify->initiator_port_protocols = 0;
2996 if (protocols & MPI_SAS_DEVICE_INFO_SSP_INITIATOR) 2996 if (protocols & MPI_SAS_DEVICE_INFO_SSP_INITIATOR)
2997 identify->initiator_port_protocols |= SAS_PROTOCOL_SSP; 2997 identify->initiator_port_protocols |= SAS_PROTOCOL_SSP;
2998 if (protocols & MPI_SAS_DEVICE_INFO_STP_INITIATOR) 2998 if (protocols & MPI_SAS_DEVICE_INFO_STP_INITIATOR)
2999 identify->initiator_port_protocols |= SAS_PROTOCOL_STP; 2999 identify->initiator_port_protocols |= SAS_PROTOCOL_STP;
3000 if (protocols & MPI_SAS_DEVICE_INFO_SMP_INITIATOR) 3000 if (protocols & MPI_SAS_DEVICE_INFO_SMP_INITIATOR)
3001 identify->initiator_port_protocols |= SAS_PROTOCOL_SMP; 3001 identify->initiator_port_protocols |= SAS_PROTOCOL_SMP;
3002 if (protocols & MPI_SAS_DEVICE_INFO_SATA_HOST) 3002 if (protocols & MPI_SAS_DEVICE_INFO_SATA_HOST)
3003 identify->initiator_port_protocols |= SAS_PROTOCOL_SATA; 3003 identify->initiator_port_protocols |= SAS_PROTOCOL_SATA;
3004 3004
3005 /* 3005 /*
3006 * Fill in Phy Target Port Protocol. 3006 * Fill in Phy Target Port Protocol.
3007 * Bits 10:7, more than one bit can be set, fall through cases. 3007 * Bits 10:7, more than one bit can be set, fall through cases.
3008 */ 3008 */
3009 protocols = device_info->device_info & 0x780; 3009 protocols = device_info->device_info & 0x780;
3010 identify->target_port_protocols = 0; 3010 identify->target_port_protocols = 0;
3011 if (protocols & MPI_SAS_DEVICE_INFO_SSP_TARGET) 3011 if (protocols & MPI_SAS_DEVICE_INFO_SSP_TARGET)
3012 identify->target_port_protocols |= SAS_PROTOCOL_SSP; 3012 identify->target_port_protocols |= SAS_PROTOCOL_SSP;
3013 if (protocols & MPI_SAS_DEVICE_INFO_STP_TARGET) 3013 if (protocols & MPI_SAS_DEVICE_INFO_STP_TARGET)
3014 identify->target_port_protocols |= SAS_PROTOCOL_STP; 3014 identify->target_port_protocols |= SAS_PROTOCOL_STP;
3015 if (protocols & MPI_SAS_DEVICE_INFO_SMP_TARGET) 3015 if (protocols & MPI_SAS_DEVICE_INFO_SMP_TARGET)
3016 identify->target_port_protocols |= SAS_PROTOCOL_SMP; 3016 identify->target_port_protocols |= SAS_PROTOCOL_SMP;
3017 if (protocols & MPI_SAS_DEVICE_INFO_SATA_DEVICE) 3017 if (protocols & MPI_SAS_DEVICE_INFO_SATA_DEVICE)
3018 identify->target_port_protocols |= SAS_PROTOCOL_SATA; 3018 identify->target_port_protocols |= SAS_PROTOCOL_SATA;
3019 3019
3020 /* 3020 /*
3021 * Fill in Attached device type. 3021 * Fill in Attached device type.
3022 */ 3022 */
3023 switch (device_info->device_info & 3023 switch (device_info->device_info &
3024 MPI_SAS_DEVICE_INFO_MASK_DEVICE_TYPE) { 3024 MPI_SAS_DEVICE_INFO_MASK_DEVICE_TYPE) {
3025 case MPI_SAS_DEVICE_INFO_NO_DEVICE: 3025 case MPI_SAS_DEVICE_INFO_NO_DEVICE:
3026 identify->device_type = SAS_PHY_UNUSED; 3026 identify->device_type = SAS_PHY_UNUSED;
3027 break; 3027 break;
3028 case MPI_SAS_DEVICE_INFO_END_DEVICE: 3028 case MPI_SAS_DEVICE_INFO_END_DEVICE:
3029 identify->device_type = SAS_END_DEVICE; 3029 identify->device_type = SAS_END_DEVICE;
3030 break; 3030 break;
3031 case MPI_SAS_DEVICE_INFO_EDGE_EXPANDER: 3031 case MPI_SAS_DEVICE_INFO_EDGE_EXPANDER:
3032 identify->device_type = SAS_EDGE_EXPANDER_DEVICE; 3032 identify->device_type = SAS_EDGE_EXPANDER_DEVICE;
3033 break; 3033 break;
3034 case MPI_SAS_DEVICE_INFO_FANOUT_EXPANDER: 3034 case MPI_SAS_DEVICE_INFO_FANOUT_EXPANDER:
3035 identify->device_type = SAS_FANOUT_EXPANDER_DEVICE; 3035 identify->device_type = SAS_FANOUT_EXPANDER_DEVICE;
3036 break; 3036 break;
3037 } 3037 }
3038 } 3038 }
3039 3039
3040 static int mptsas_probe_one_phy(struct device *dev, 3040 static int mptsas_probe_one_phy(struct device *dev,
3041 struct mptsas_phyinfo *phy_info, int index, int local) 3041 struct mptsas_phyinfo *phy_info, int index, int local)
3042 { 3042 {
3043 MPT_ADAPTER *ioc; 3043 MPT_ADAPTER *ioc;
3044 struct sas_phy *phy; 3044 struct sas_phy *phy;
3045 struct sas_port *port; 3045 struct sas_port *port;
3046 int error = 0; 3046 int error = 0;
3047 VirtTarget *vtarget; 3047 VirtTarget *vtarget;
3048 3048
3049 if (!dev) { 3049 if (!dev) {
3050 error = -ENODEV; 3050 error = -ENODEV;
3051 goto out; 3051 goto out;
3052 } 3052 }
3053 3053
3054 if (!phy_info->phy) { 3054 if (!phy_info->phy) {
3055 phy = sas_phy_alloc(dev, index); 3055 phy = sas_phy_alloc(dev, index);
3056 if (!phy) { 3056 if (!phy) {
3057 error = -ENOMEM; 3057 error = -ENOMEM;
3058 goto out; 3058 goto out;
3059 } 3059 }
3060 } else 3060 } else
3061 phy = phy_info->phy; 3061 phy = phy_info->phy;
3062 3062
3063 mptsas_parse_device_info(&phy->identify, &phy_info->identify); 3063 mptsas_parse_device_info(&phy->identify, &phy_info->identify);
3064 3064
3065 /* 3065 /*
3066 * Set Negotiated link rate. 3066 * Set Negotiated link rate.
3067 */ 3067 */
3068 switch (phy_info->negotiated_link_rate) { 3068 switch (phy_info->negotiated_link_rate) {
3069 case MPI_SAS_IOUNIT0_RATE_PHY_DISABLED: 3069 case MPI_SAS_IOUNIT0_RATE_PHY_DISABLED:
3070 phy->negotiated_linkrate = SAS_PHY_DISABLED; 3070 phy->negotiated_linkrate = SAS_PHY_DISABLED;
3071 break; 3071 break;
3072 case MPI_SAS_IOUNIT0_RATE_FAILED_SPEED_NEGOTIATION: 3072 case MPI_SAS_IOUNIT0_RATE_FAILED_SPEED_NEGOTIATION:
3073 phy->negotiated_linkrate = SAS_LINK_RATE_FAILED; 3073 phy->negotiated_linkrate = SAS_LINK_RATE_FAILED;
3074 break; 3074 break;
3075 case MPI_SAS_IOUNIT0_RATE_1_5: 3075 case MPI_SAS_IOUNIT0_RATE_1_5:
3076 phy->negotiated_linkrate = SAS_LINK_RATE_1_5_GBPS; 3076 phy->negotiated_linkrate = SAS_LINK_RATE_1_5_GBPS;
3077 break; 3077 break;
3078 case MPI_SAS_IOUNIT0_RATE_3_0: 3078 case MPI_SAS_IOUNIT0_RATE_3_0:
3079 phy->negotiated_linkrate = SAS_LINK_RATE_3_0_GBPS; 3079 phy->negotiated_linkrate = SAS_LINK_RATE_3_0_GBPS;
3080 break; 3080 break;
3081 case MPI_SAS_IOUNIT0_RATE_6_0: 3081 case MPI_SAS_IOUNIT0_RATE_6_0:
3082 phy->negotiated_linkrate = SAS_LINK_RATE_6_0_GBPS; 3082 phy->negotiated_linkrate = SAS_LINK_RATE_6_0_GBPS;
3083 break; 3083 break;
3084 case MPI_SAS_IOUNIT0_RATE_SATA_OOB_COMPLETE: 3084 case MPI_SAS_IOUNIT0_RATE_SATA_OOB_COMPLETE:
3085 case MPI_SAS_IOUNIT0_RATE_UNKNOWN: 3085 case MPI_SAS_IOUNIT0_RATE_UNKNOWN:
3086 default: 3086 default:
3087 phy->negotiated_linkrate = SAS_LINK_RATE_UNKNOWN; 3087 phy->negotiated_linkrate = SAS_LINK_RATE_UNKNOWN;
3088 break; 3088 break;
3089 } 3089 }
3090 3090
3091 /* 3091 /*
3092 * Set Max hardware link rate. 3092 * Set Max hardware link rate.
3093 */ 3093 */
3094 switch (phy_info->hw_link_rate & MPI_SAS_PHY0_PRATE_MAX_RATE_MASK) { 3094 switch (phy_info->hw_link_rate & MPI_SAS_PHY0_PRATE_MAX_RATE_MASK) {
3095 case MPI_SAS_PHY0_HWRATE_MAX_RATE_1_5: 3095 case MPI_SAS_PHY0_HWRATE_MAX_RATE_1_5:
3096 phy->maximum_linkrate_hw = SAS_LINK_RATE_1_5_GBPS; 3096 phy->maximum_linkrate_hw = SAS_LINK_RATE_1_5_GBPS;
3097 break; 3097 break;
3098 case MPI_SAS_PHY0_PRATE_MAX_RATE_3_0: 3098 case MPI_SAS_PHY0_PRATE_MAX_RATE_3_0:
3099 phy->maximum_linkrate_hw = SAS_LINK_RATE_3_0_GBPS; 3099 phy->maximum_linkrate_hw = SAS_LINK_RATE_3_0_GBPS;
3100 break; 3100 break;
3101 default: 3101 default:
3102 break; 3102 break;
3103 } 3103 }
3104 3104
3105 /* 3105 /*
3106 * Set Max programmed link rate. 3106 * Set Max programmed link rate.
3107 */ 3107 */
3108 switch (phy_info->programmed_link_rate & 3108 switch (phy_info->programmed_link_rate &
3109 MPI_SAS_PHY0_PRATE_MAX_RATE_MASK) { 3109 MPI_SAS_PHY0_PRATE_MAX_RATE_MASK) {
3110 case MPI_SAS_PHY0_PRATE_MAX_RATE_1_5: 3110 case MPI_SAS_PHY0_PRATE_MAX_RATE_1_5:
3111 phy->maximum_linkrate = SAS_LINK_RATE_1_5_GBPS; 3111 phy->maximum_linkrate = SAS_LINK_RATE_1_5_GBPS;
3112 break; 3112 break;
3113 case MPI_SAS_PHY0_PRATE_MAX_RATE_3_0: 3113 case MPI_SAS_PHY0_PRATE_MAX_RATE_3_0:
3114 phy->maximum_linkrate = SAS_LINK_RATE_3_0_GBPS; 3114 phy->maximum_linkrate = SAS_LINK_RATE_3_0_GBPS;
3115 break; 3115 break;
3116 default: 3116 default:
3117 break; 3117 break;
3118 } 3118 }
3119 3119
3120 /* 3120 /*
3121 * Set Min hardware link rate. 3121 * Set Min hardware link rate.
3122 */ 3122 */
3123 switch (phy_info->hw_link_rate & MPI_SAS_PHY0_HWRATE_MIN_RATE_MASK) { 3123 switch (phy_info->hw_link_rate & MPI_SAS_PHY0_HWRATE_MIN_RATE_MASK) {
3124 case MPI_SAS_PHY0_HWRATE_MIN_RATE_1_5: 3124 case MPI_SAS_PHY0_HWRATE_MIN_RATE_1_5:
3125 phy->minimum_linkrate_hw = SAS_LINK_RATE_1_5_GBPS; 3125 phy->minimum_linkrate_hw = SAS_LINK_RATE_1_5_GBPS;
3126 break; 3126 break;
3127 case MPI_SAS_PHY0_PRATE_MIN_RATE_3_0: 3127 case MPI_SAS_PHY0_PRATE_MIN_RATE_3_0:
3128 phy->minimum_linkrate_hw = SAS_LINK_RATE_3_0_GBPS; 3128 phy->minimum_linkrate_hw = SAS_LINK_RATE_3_0_GBPS;
3129 break; 3129 break;
3130 default: 3130 default:
3131 break; 3131 break;
3132 } 3132 }
3133 3133
3134 /* 3134 /*
3135 * Set Min programmed link rate. 3135 * Set Min programmed link rate.
3136 */ 3136 */
3137 switch (phy_info->programmed_link_rate & 3137 switch (phy_info->programmed_link_rate &
3138 MPI_SAS_PHY0_PRATE_MIN_RATE_MASK) { 3138 MPI_SAS_PHY0_PRATE_MIN_RATE_MASK) {
3139 case MPI_SAS_PHY0_PRATE_MIN_RATE_1_5: 3139 case MPI_SAS_PHY0_PRATE_MIN_RATE_1_5:
3140 phy->minimum_linkrate = SAS_LINK_RATE_1_5_GBPS; 3140 phy->minimum_linkrate = SAS_LINK_RATE_1_5_GBPS;
3141 break; 3141 break;
3142 case MPI_SAS_PHY0_PRATE_MIN_RATE_3_0: 3142 case MPI_SAS_PHY0_PRATE_MIN_RATE_3_0:
3143 phy->minimum_linkrate = SAS_LINK_RATE_3_0_GBPS; 3143 phy->minimum_linkrate = SAS_LINK_RATE_3_0_GBPS;
3144 break; 3144 break;
3145 default: 3145 default:
3146 break; 3146 break;
3147 } 3147 }
3148 3148
3149 if (!phy_info->phy) { 3149 if (!phy_info->phy) {
3150 3150
3151 error = sas_phy_add(phy); 3151 error = sas_phy_add(phy);
3152 if (error) { 3152 if (error) {
3153 sas_phy_free(phy); 3153 sas_phy_free(phy);
3154 goto out; 3154 goto out;
3155 } 3155 }
3156 phy_info->phy = phy; 3156 phy_info->phy = phy;
3157 } 3157 }
3158 3158
3159 if (!phy_info->attached.handle || 3159 if (!phy_info->attached.handle ||
3160 !phy_info->port_details) 3160 !phy_info->port_details)
3161 goto out; 3161 goto out;
3162 3162
3163 port = mptsas_get_port(phy_info); 3163 port = mptsas_get_port(phy_info);
3164 ioc = phy_to_ioc(phy_info->phy); 3164 ioc = phy_to_ioc(phy_info->phy);
3165 3165
3166 if (phy_info->sas_port_add_phy) { 3166 if (phy_info->sas_port_add_phy) {
3167 3167
3168 if (!port) { 3168 if (!port) {
3169 port = sas_port_alloc_num(dev); 3169 port = sas_port_alloc_num(dev);
3170 if (!port) { 3170 if (!port) {
3171 error = -ENOMEM; 3171 error = -ENOMEM;
3172 goto out; 3172 goto out;
3173 } 3173 }
3174 error = sas_port_add(port); 3174 error = sas_port_add(port);
3175 if (error) { 3175 if (error) {
3176 dfailprintk(ioc, printk(MYIOC_s_ERR_FMT 3176 dfailprintk(ioc, printk(MYIOC_s_ERR_FMT
3177 "%s: exit at line=%d\n", ioc->name, 3177 "%s: exit at line=%d\n", ioc->name,
3178 __func__, __LINE__)); 3178 __func__, __LINE__));
3179 goto out; 3179 goto out;
3180 } 3180 }
3181 mptsas_set_port(ioc, phy_info, port); 3181 mptsas_set_port(ioc, phy_info, port);
3182 devtprintk(ioc, dev_printk(KERN_DEBUG, &port->dev, 3182 devtprintk(ioc, dev_printk(KERN_DEBUG, &port->dev,
3183 MYIOC_s_FMT "add port %d, sas_addr (0x%llx)\n", 3183 MYIOC_s_FMT "add port %d, sas_addr (0x%llx)\n",
3184 ioc->name, port->port_identifier, 3184 ioc->name, port->port_identifier,
3185 (unsigned long long)phy_info-> 3185 (unsigned long long)phy_info->
3186 attached.sas_address)); 3186 attached.sas_address));
3187 } 3187 }
3188 dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT 3188 dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT
3189 "sas_port_add_phy: phy_id=%d\n", 3189 "sas_port_add_phy: phy_id=%d\n",
3190 ioc->name, phy_info->phy_id)); 3190 ioc->name, phy_info->phy_id));
3191 sas_port_add_phy(port, phy_info->phy); 3191 sas_port_add_phy(port, phy_info->phy);
3192 phy_info->sas_port_add_phy = 0; 3192 phy_info->sas_port_add_phy = 0;
3193 devtprintk(ioc, dev_printk(KERN_DEBUG, &phy_info->phy->dev, 3193 devtprintk(ioc, dev_printk(KERN_DEBUG, &phy_info->phy->dev,
3194 MYIOC_s_FMT "add phy %d, phy-obj (0x%p)\n", ioc->name, 3194 MYIOC_s_FMT "add phy %d, phy-obj (0x%p)\n", ioc->name,
3195 phy_info->phy_id, phy_info->phy)); 3195 phy_info->phy_id, phy_info->phy));
3196 } 3196 }
3197 if (!mptsas_get_rphy(phy_info) && port && !port->rphy) { 3197 if (!mptsas_get_rphy(phy_info) && port && !port->rphy) {
3198 3198
3199 struct sas_rphy *rphy; 3199 struct sas_rphy *rphy;
3200 struct device *parent; 3200 struct device *parent;
3201 struct sas_identify identify; 3201 struct sas_identify identify;
3202 3202
3203 parent = dev->parent->parent; 3203 parent = dev->parent->parent;
3204 /* 3204 /*
3205 * Let the hotplug_work thread handle processing 3205 * Let the hotplug_work thread handle processing
3206 * the adding/removing of devices that occur 3206 * the adding/removing of devices that occur
3207 * after start of day. 3207 * after start of day.
3208 */ 3208 */
3209 if (mptsas_is_end_device(&phy_info->attached) && 3209 if (mptsas_is_end_device(&phy_info->attached) &&
3210 phy_info->attached.handle_parent) { 3210 phy_info->attached.handle_parent) {
3211 goto out; 3211 goto out;
3212 } 3212 }
3213 3213
3214 mptsas_parse_device_info(&identify, &phy_info->attached); 3214 mptsas_parse_device_info(&identify, &phy_info->attached);
3215 if (scsi_is_host_device(parent)) { 3215 if (scsi_is_host_device(parent)) {
3216 struct mptsas_portinfo *port_info; 3216 struct mptsas_portinfo *port_info;
3217 int i; 3217 int i;
3218 3218
3219 port_info = ioc->hba_port_info; 3219 port_info = ioc->hba_port_info;
3220 3220
3221 for (i = 0; i < port_info->num_phys; i++) 3221 for (i = 0; i < port_info->num_phys; i++)
3222 if (port_info->phy_info[i].identify.sas_address == 3222 if (port_info->phy_info[i].identify.sas_address ==
3223 identify.sas_address) { 3223 identify.sas_address) {
3224 sas_port_mark_backlink(port); 3224 sas_port_mark_backlink(port);
3225 goto out; 3225 goto out;
3226 } 3226 }
3227 3227
3228 } else if (scsi_is_sas_rphy(parent)) { 3228 } else if (scsi_is_sas_rphy(parent)) {
3229 struct sas_rphy *parent_rphy = dev_to_rphy(parent); 3229 struct sas_rphy *parent_rphy = dev_to_rphy(parent);
3230 if (identify.sas_address == 3230 if (identify.sas_address ==
3231 parent_rphy->identify.sas_address) { 3231 parent_rphy->identify.sas_address) {
3232 sas_port_mark_backlink(port); 3232 sas_port_mark_backlink(port);
3233 goto out; 3233 goto out;
3234 } 3234 }
3235 } 3235 }
3236 3236
3237 switch (identify.device_type) { 3237 switch (identify.device_type) {
3238 case SAS_END_DEVICE: 3238 case SAS_END_DEVICE:
3239 rphy = sas_end_device_alloc(port); 3239 rphy = sas_end_device_alloc(port);
3240 break; 3240 break;
3241 case SAS_EDGE_EXPANDER_DEVICE: 3241 case SAS_EDGE_EXPANDER_DEVICE:
3242 case SAS_FANOUT_EXPANDER_DEVICE: 3242 case SAS_FANOUT_EXPANDER_DEVICE:
3243 rphy = sas_expander_alloc(port, identify.device_type); 3243 rphy = sas_expander_alloc(port, identify.device_type);
3244 break; 3244 break;
3245 default: 3245 default:
3246 rphy = NULL; 3246 rphy = NULL;
3247 break; 3247 break;
3248 } 3248 }
3249 if (!rphy) { 3249 if (!rphy) {
3250 dfailprintk(ioc, printk(MYIOC_s_ERR_FMT 3250 dfailprintk(ioc, printk(MYIOC_s_ERR_FMT
3251 "%s: exit at line=%d\n", ioc->name, 3251 "%s: exit at line=%d\n", ioc->name,
3252 __func__, __LINE__)); 3252 __func__, __LINE__));
3253 goto out; 3253 goto out;
3254 } 3254 }
3255 3255
3256 rphy->identify = identify; 3256 rphy->identify = identify;
3257 error = sas_rphy_add(rphy); 3257 error = sas_rphy_add(rphy);
3258 if (error) { 3258 if (error) {
3259 dfailprintk(ioc, printk(MYIOC_s_ERR_FMT 3259 dfailprintk(ioc, printk(MYIOC_s_ERR_FMT
3260 "%s: exit at line=%d\n", ioc->name, 3260 "%s: exit at line=%d\n", ioc->name,
3261 __func__, __LINE__)); 3261 __func__, __LINE__));
3262 sas_rphy_free(rphy); 3262 sas_rphy_free(rphy);
3263 goto out; 3263 goto out;
3264 } 3264 }
3265 mptsas_set_rphy(ioc, phy_info, rphy); 3265 mptsas_set_rphy(ioc, phy_info, rphy);
3266 if (identify.device_type == SAS_EDGE_EXPANDER_DEVICE || 3266 if (identify.device_type == SAS_EDGE_EXPANDER_DEVICE ||
3267 identify.device_type == SAS_FANOUT_EXPANDER_DEVICE) 3267 identify.device_type == SAS_FANOUT_EXPANDER_DEVICE)
3268 mptsas_exp_repmanufacture_info(ioc, 3268 mptsas_exp_repmanufacture_info(ioc,
3269 identify.sas_address, 3269 identify.sas_address,
3270 rphy_to_expander_device(rphy)); 3270 rphy_to_expander_device(rphy));
3271 } 3271 }
3272 3272
3273 /* If the device exists,verify it wasn't previously flagged 3273 /* If the device exists,verify it wasn't previously flagged
3274 as a missing device. If so, clear it */ 3274 as a missing device. If so, clear it */
3275 vtarget = mptsas_find_vtarget(ioc, 3275 vtarget = mptsas_find_vtarget(ioc,
3276 phy_info->attached.channel, 3276 phy_info->attached.channel,
3277 phy_info->attached.id); 3277 phy_info->attached.id);
3278 if (vtarget && vtarget->inDMD) { 3278 if (vtarget && vtarget->inDMD) {
3279 printk(KERN_INFO "Device returned, unsetting inDMD\n"); 3279 printk(KERN_INFO "Device returned, unsetting inDMD\n");
3280 vtarget->inDMD = 0; 3280 vtarget->inDMD = 0;
3281 } 3281 }
3282 3282
3283 out: 3283 out:
3284 return error; 3284 return error;
3285 } 3285 }
3286 3286
3287 static int 3287 static int
3288 mptsas_probe_hba_phys(MPT_ADAPTER *ioc) 3288 mptsas_probe_hba_phys(MPT_ADAPTER *ioc)
3289 { 3289 {
3290 struct mptsas_portinfo *port_info, *hba; 3290 struct mptsas_portinfo *port_info, *hba;
3291 int error = -ENOMEM, i; 3291 int error = -ENOMEM, i;
3292 3292
3293 hba = kzalloc(sizeof(struct mptsas_portinfo), GFP_KERNEL); 3293 hba = kzalloc(sizeof(struct mptsas_portinfo), GFP_KERNEL);
3294 if (! hba) 3294 if (! hba)
3295 goto out; 3295 goto out;
3296 3296
3297 error = mptsas_sas_io_unit_pg0(ioc, hba); 3297 error = mptsas_sas_io_unit_pg0(ioc, hba);
3298 if (error) 3298 if (error)
3299 goto out_free_port_info; 3299 goto out_free_port_info;
3300 3300
3301 mptsas_sas_io_unit_pg1(ioc); 3301 mptsas_sas_io_unit_pg1(ioc);
3302 mutex_lock(&ioc->sas_topology_mutex); 3302 mutex_lock(&ioc->sas_topology_mutex);
3303 port_info = ioc->hba_port_info; 3303 port_info = ioc->hba_port_info;
3304 if (!port_info) { 3304 if (!port_info) {
3305 ioc->hba_port_info = port_info = hba; 3305 ioc->hba_port_info = port_info = hba;
3306 ioc->hba_port_num_phy = port_info->num_phys; 3306 ioc->hba_port_num_phy = port_info->num_phys;
3307 list_add_tail(&port_info->list, &ioc->sas_topology); 3307 list_add_tail(&port_info->list, &ioc->sas_topology);
3308 } else { 3308 } else {
3309 for (i = 0; i < hba->num_phys; i++) { 3309 for (i = 0; i < hba->num_phys; i++) {
3310 port_info->phy_info[i].negotiated_link_rate = 3310 port_info->phy_info[i].negotiated_link_rate =
3311 hba->phy_info[i].negotiated_link_rate; 3311 hba->phy_info[i].negotiated_link_rate;
3312 port_info->phy_info[i].handle = 3312 port_info->phy_info[i].handle =
3313 hba->phy_info[i].handle; 3313 hba->phy_info[i].handle;
3314 port_info->phy_info[i].port_id = 3314 port_info->phy_info[i].port_id =
3315 hba->phy_info[i].port_id; 3315 hba->phy_info[i].port_id;
3316 } 3316 }
3317 kfree(hba->phy_info); 3317 kfree(hba->phy_info);
3318 kfree(hba); 3318 kfree(hba);
3319 hba = NULL; 3319 hba = NULL;
3320 } 3320 }
3321 mutex_unlock(&ioc->sas_topology_mutex); 3321 mutex_unlock(&ioc->sas_topology_mutex);
3322 #if defined(CPQ_CIM) 3322 #if defined(CPQ_CIM)
3323 ioc->num_ports = port_info->num_phys; 3323 ioc->num_ports = port_info->num_phys;
3324 #endif 3324 #endif
3325 for (i = 0; i < port_info->num_phys; i++) { 3325 for (i = 0; i < port_info->num_phys; i++) {
3326 mptsas_sas_phy_pg0(ioc, &port_info->phy_info[i], 3326 mptsas_sas_phy_pg0(ioc, &port_info->phy_info[i],
3327 (MPI_SAS_PHY_PGAD_FORM_PHY_NUMBER << 3327 (MPI_SAS_PHY_PGAD_FORM_PHY_NUMBER <<
3328 MPI_SAS_PHY_PGAD_FORM_SHIFT), i); 3328 MPI_SAS_PHY_PGAD_FORM_SHIFT), i);
3329 port_info->phy_info[i].identify.handle = 3329 port_info->phy_info[i].identify.handle =
3330 port_info->phy_info[i].handle; 3330 port_info->phy_info[i].handle;
3331 mptsas_sas_device_pg0(ioc, &port_info->phy_info[i].identify, 3331 mptsas_sas_device_pg0(ioc, &port_info->phy_info[i].identify,
3332 (MPI_SAS_DEVICE_PGAD_FORM_HANDLE << 3332 (MPI_SAS_DEVICE_PGAD_FORM_HANDLE <<
3333 MPI_SAS_DEVICE_PGAD_FORM_SHIFT), 3333 MPI_SAS_DEVICE_PGAD_FORM_SHIFT),
3334 port_info->phy_info[i].identify.handle); 3334 port_info->phy_info[i].identify.handle);
3335 if (!ioc->hba_port_sas_addr) 3335 if (!ioc->hba_port_sas_addr)
3336 ioc->hba_port_sas_addr = 3336 ioc->hba_port_sas_addr =
3337 port_info->phy_info[i].identify.sas_address; 3337 port_info->phy_info[i].identify.sas_address;
3338 port_info->phy_info[i].identify.phy_id = 3338 port_info->phy_info[i].identify.phy_id =
3339 port_info->phy_info[i].phy_id = i; 3339 port_info->phy_info[i].phy_id = i;
3340 if (port_info->phy_info[i].attached.handle) 3340 if (port_info->phy_info[i].attached.handle)
3341 mptsas_sas_device_pg0(ioc, 3341 mptsas_sas_device_pg0(ioc,
3342 &port_info->phy_info[i].attached, 3342 &port_info->phy_info[i].attached,
3343 (MPI_SAS_DEVICE_PGAD_FORM_HANDLE << 3343 (MPI_SAS_DEVICE_PGAD_FORM_HANDLE <<
3344 MPI_SAS_DEVICE_PGAD_FORM_SHIFT), 3344 MPI_SAS_DEVICE_PGAD_FORM_SHIFT),
3345 port_info->phy_info[i].attached.handle); 3345 port_info->phy_info[i].attached.handle);
3346 } 3346 }
3347 3347
3348 mptsas_setup_wide_ports(ioc, port_info); 3348 mptsas_setup_wide_ports(ioc, port_info);
3349 3349
3350 for (i = 0; i < port_info->num_phys; i++, ioc->sas_index++) 3350 for (i = 0; i < port_info->num_phys; i++, ioc->sas_index++)
3351 mptsas_probe_one_phy(&ioc->sh->shost_gendev, 3351 mptsas_probe_one_phy(&ioc->sh->shost_gendev,
3352 &port_info->phy_info[i], ioc->sas_index, 1); 3352 &port_info->phy_info[i], ioc->sas_index, 1);
3353 3353
3354 return 0; 3354 return 0;
3355 3355
3356 out_free_port_info: 3356 out_free_port_info:
3357 kfree(hba); 3357 kfree(hba);
3358 out: 3358 out:
3359 return error; 3359 return error;
3360 } 3360 }
3361 3361
3362 static void 3362 static void
3363 mptsas_expander_refresh(MPT_ADAPTER *ioc, struct mptsas_portinfo *port_info) 3363 mptsas_expander_refresh(MPT_ADAPTER *ioc, struct mptsas_portinfo *port_info)
3364 { 3364 {
3365 struct mptsas_portinfo *parent; 3365 struct mptsas_portinfo *parent;
3366 struct device *parent_dev; 3366 struct device *parent_dev;
3367 struct sas_rphy *rphy; 3367 struct sas_rphy *rphy;
3368 int i; 3368 int i;
3369 u64 sas_address; /* expander sas address */ 3369 u64 sas_address; /* expander sas address */
3370 u32 handle; 3370 u32 handle;
3371 3371
3372 handle = port_info->phy_info[0].handle; 3372 handle = port_info->phy_info[0].handle;
3373 sas_address = port_info->phy_info[0].identify.sas_address; 3373 sas_address = port_info->phy_info[0].identify.sas_address;
3374 for (i = 0; i < port_info->num_phys; i++) { 3374 for (i = 0; i < port_info->num_phys; i++) {
3375 mptsas_sas_expander_pg1(ioc, &port_info->phy_info[i], 3375 mptsas_sas_expander_pg1(ioc, &port_info->phy_info[i],
3376 (MPI_SAS_EXPAND_PGAD_FORM_HANDLE_PHY_NUM << 3376 (MPI_SAS_EXPAND_PGAD_FORM_HANDLE_PHY_NUM <<
3377 MPI_SAS_EXPAND_PGAD_FORM_SHIFT), (i << 16) + handle); 3377 MPI_SAS_EXPAND_PGAD_FORM_SHIFT), (i << 16) + handle);
3378 3378
3379 mptsas_sas_device_pg0(ioc, 3379 mptsas_sas_device_pg0(ioc,
3380 &port_info->phy_info[i].identify, 3380 &port_info->phy_info[i].identify,
3381 (MPI_SAS_DEVICE_PGAD_FORM_HANDLE << 3381 (MPI_SAS_DEVICE_PGAD_FORM_HANDLE <<
3382 MPI_SAS_DEVICE_PGAD_FORM_SHIFT), 3382 MPI_SAS_DEVICE_PGAD_FORM_SHIFT),
3383 port_info->phy_info[i].identify.handle); 3383 port_info->phy_info[i].identify.handle);
3384 port_info->phy_info[i].identify.phy_id = 3384 port_info->phy_info[i].identify.phy_id =
3385 port_info->phy_info[i].phy_id; 3385 port_info->phy_info[i].phy_id;
3386 3386
3387 if (port_info->phy_info[i].attached.handle) { 3387 if (port_info->phy_info[i].attached.handle) {
3388 mptsas_sas_device_pg0(ioc, 3388 mptsas_sas_device_pg0(ioc,
3389 &port_info->phy_info[i].attached, 3389 &port_info->phy_info[i].attached,
3390 (MPI_SAS_DEVICE_PGAD_FORM_HANDLE << 3390 (MPI_SAS_DEVICE_PGAD_FORM_HANDLE <<
3391 MPI_SAS_DEVICE_PGAD_FORM_SHIFT), 3391 MPI_SAS_DEVICE_PGAD_FORM_SHIFT),
3392 port_info->phy_info[i].attached.handle); 3392 port_info->phy_info[i].attached.handle);
3393 port_info->phy_info[i].attached.phy_id = 3393 port_info->phy_info[i].attached.phy_id =
3394 port_info->phy_info[i].phy_id; 3394 port_info->phy_info[i].phy_id;
3395 } 3395 }
3396 } 3396 }
3397 3397
3398 mutex_lock(&ioc->sas_topology_mutex); 3398 mutex_lock(&ioc->sas_topology_mutex);
3399 parent = mptsas_find_portinfo_by_handle(ioc, 3399 parent = mptsas_find_portinfo_by_handle(ioc,
3400 port_info->phy_info[0].identify.handle_parent); 3400 port_info->phy_info[0].identify.handle_parent);
3401 if (!parent) { 3401 if (!parent) {
3402 mutex_unlock(&ioc->sas_topology_mutex); 3402 mutex_unlock(&ioc->sas_topology_mutex);
3403 return; 3403 return;
3404 } 3404 }
3405 for (i = 0, parent_dev = NULL; i < parent->num_phys && !parent_dev; 3405 for (i = 0, parent_dev = NULL; i < parent->num_phys && !parent_dev;
3406 i++) { 3406 i++) {
3407 if (parent->phy_info[i].attached.sas_address == sas_address) { 3407 if (parent->phy_info[i].attached.sas_address == sas_address) {
3408 rphy = mptsas_get_rphy(&parent->phy_info[i]); 3408 rphy = mptsas_get_rphy(&parent->phy_info[i]);
3409 parent_dev = &rphy->dev; 3409 parent_dev = &rphy->dev;
3410 } 3410 }
3411 } 3411 }
3412 mutex_unlock(&ioc->sas_topology_mutex); 3412 mutex_unlock(&ioc->sas_topology_mutex);
3413 3413
3414 mptsas_setup_wide_ports(ioc, port_info); 3414 mptsas_setup_wide_ports(ioc, port_info);
3415 for (i = 0; i < port_info->num_phys; i++, ioc->sas_index++) 3415 for (i = 0; i < port_info->num_phys; i++, ioc->sas_index++)
3416 mptsas_probe_one_phy(parent_dev, &port_info->phy_info[i], 3416 mptsas_probe_one_phy(parent_dev, &port_info->phy_info[i],
3417 ioc->sas_index, 0); 3417 ioc->sas_index, 0);
3418 } 3418 }
3419 3419
3420 static void 3420 static void
3421 mptsas_expander_event_add(MPT_ADAPTER *ioc, 3421 mptsas_expander_event_add(MPT_ADAPTER *ioc,
3422 MpiEventDataSasExpanderStatusChange_t *expander_data) 3422 MpiEventDataSasExpanderStatusChange_t *expander_data)
3423 { 3423 {
3424 struct mptsas_portinfo *port_info; 3424 struct mptsas_portinfo *port_info;
3425 int i; 3425 int i;
3426 __le64 sas_address; 3426 __le64 sas_address;
3427 3427
3428 port_info = kzalloc(sizeof(struct mptsas_portinfo), GFP_KERNEL); 3428 port_info = kzalloc(sizeof(struct mptsas_portinfo), GFP_KERNEL);
3429 if (!port_info) 3429 if (!port_info)
3430 BUG(); 3430 BUG();
3431 port_info->num_phys = (expander_data->NumPhys) ? 3431 port_info->num_phys = (expander_data->NumPhys) ?
3432 expander_data->NumPhys : 1; 3432 expander_data->NumPhys : 1;
3433 port_info->phy_info = kcalloc(port_info->num_phys, 3433 port_info->phy_info = kcalloc(port_info->num_phys,
3434 sizeof(struct mptsas_phyinfo), GFP_KERNEL); 3434 sizeof(struct mptsas_phyinfo), GFP_KERNEL);
3435 if (!port_info->phy_info) 3435 if (!port_info->phy_info)
3436 BUG(); 3436 BUG();
3437 memcpy(&sas_address, &expander_data->SASAddress, sizeof(__le64)); 3437 memcpy(&sas_address, &expander_data->SASAddress, sizeof(__le64));
3438 for (i = 0; i < port_info->num_phys; i++) { 3438 for (i = 0; i < port_info->num_phys; i++) {
3439 port_info->phy_info[i].portinfo = port_info; 3439 port_info->phy_info[i].portinfo = port_info;
3440 port_info->phy_info[i].handle = 3440 port_info->phy_info[i].handle =
3441 le16_to_cpu(expander_data->DevHandle); 3441 le16_to_cpu(expander_data->DevHandle);
3442 port_info->phy_info[i].identify.sas_address = 3442 port_info->phy_info[i].identify.sas_address =
3443 le64_to_cpu(sas_address); 3443 le64_to_cpu(sas_address);
3444 port_info->phy_info[i].identify.handle_parent = 3444 port_info->phy_info[i].identify.handle_parent =
3445 le16_to_cpu(expander_data->ParentDevHandle); 3445 le16_to_cpu(expander_data->ParentDevHandle);
3446 } 3446 }
3447 3447
3448 mutex_lock(&ioc->sas_topology_mutex); 3448 mutex_lock(&ioc->sas_topology_mutex);
3449 list_add_tail(&port_info->list, &ioc->sas_topology); 3449 list_add_tail(&port_info->list, &ioc->sas_topology);
3450 mutex_unlock(&ioc->sas_topology_mutex); 3450 mutex_unlock(&ioc->sas_topology_mutex);
3451 3451
3452 printk(MYIOC_s_INFO_FMT "add expander: num_phys %d, " 3452 printk(MYIOC_s_INFO_FMT "add expander: num_phys %d, "
3453 "sas_addr (0x%llx)\n", ioc->name, port_info->num_phys, 3453 "sas_addr (0x%llx)\n", ioc->name, port_info->num_phys,
3454 (unsigned long long)sas_address); 3454 (unsigned long long)sas_address);
3455 3455
3456 mptsas_expander_refresh(ioc, port_info); 3456 mptsas_expander_refresh(ioc, port_info);
3457 } 3457 }
3458 3458
3459 /** 3459 /**
3460 * mptsas_delete_expander_siblings - remove siblings attached to expander 3460 * mptsas_delete_expander_siblings - remove siblings attached to expander
3461 * @ioc: Pointer to MPT_ADAPTER structure 3461 * @ioc: Pointer to MPT_ADAPTER structure
3462 * @parent: the parent port_info object 3462 * @parent: the parent port_info object
3463 * @expander: the expander port_info object 3463 * @expander: the expander port_info object
3464 **/ 3464 **/
3465 static void 3465 static void
3466 mptsas_delete_expander_siblings(MPT_ADAPTER *ioc, struct mptsas_portinfo 3466 mptsas_delete_expander_siblings(MPT_ADAPTER *ioc, struct mptsas_portinfo
3467 *parent, struct mptsas_portinfo *expander) 3467 *parent, struct mptsas_portinfo *expander)
3468 { 3468 {
3469 struct mptsas_phyinfo *phy_info; 3469 struct mptsas_phyinfo *phy_info;
3470 struct mptsas_portinfo *port_info; 3470 struct mptsas_portinfo *port_info;
3471 struct sas_rphy *rphy; 3471 struct sas_rphy *rphy;
3472 int i; 3472 int i;
3473 3473
3474 phy_info = expander->phy_info; 3474 phy_info = expander->phy_info;
3475 for (i = 0; i < expander->num_phys; i++, phy_info++) { 3475 for (i = 0; i < expander->num_phys; i++, phy_info++) {
3476 rphy = mptsas_get_rphy(phy_info); 3476 rphy = mptsas_get_rphy(phy_info);
3477 if (!rphy) 3477 if (!rphy)
3478 continue; 3478 continue;
3479 if (rphy->identify.device_type == SAS_END_DEVICE) 3479 if (rphy->identify.device_type == SAS_END_DEVICE)
3480 mptsas_del_end_device(ioc, phy_info); 3480 mptsas_del_end_device(ioc, phy_info);
3481 } 3481 }
3482 3482
3483 phy_info = expander->phy_info; 3483 phy_info = expander->phy_info;
3484 for (i = 0; i < expander->num_phys; i++, phy_info++) { 3484 for (i = 0; i < expander->num_phys; i++, phy_info++) {
3485 rphy = mptsas_get_rphy(phy_info); 3485 rphy = mptsas_get_rphy(phy_info);
3486 if (!rphy) 3486 if (!rphy)
3487 continue; 3487 continue;
3488 if (rphy->identify.device_type == 3488 if (rphy->identify.device_type ==
3489 MPI_SAS_DEVICE_INFO_EDGE_EXPANDER || 3489 MPI_SAS_DEVICE_INFO_EDGE_EXPANDER ||
3490 rphy->identify.device_type == 3490 rphy->identify.device_type ==
3491 MPI_SAS_DEVICE_INFO_FANOUT_EXPANDER) { 3491 MPI_SAS_DEVICE_INFO_FANOUT_EXPANDER) {
3492 port_info = mptsas_find_portinfo_by_sas_address(ioc, 3492 port_info = mptsas_find_portinfo_by_sas_address(ioc,
3493 rphy->identify.sas_address); 3493 rphy->identify.sas_address);
3494 if (!port_info) 3494 if (!port_info)
3495 continue; 3495 continue;
3496 if (port_info == parent) /* backlink rphy */ 3496 if (port_info == parent) /* backlink rphy */
3497 continue; 3497 continue;
3498 /* 3498 /*
3499 Delete this expander even if the expdevpage is exists 3499 Delete this expander even if the expdevpage is exists
3500 because the parent expander is already deleted 3500 because the parent expander is already deleted
3501 */ 3501 */
3502 mptsas_expander_delete(ioc, port_info, 1); 3502 mptsas_expander_delete(ioc, port_info, 1);
3503 } 3503 }
3504 } 3504 }
3505 } 3505 }
3506 3506
3507 3507
3508 /** 3508 /**
3509 * mptsas_expander_delete - remove this expander 3509 * mptsas_expander_delete - remove this expander
3510 * @ioc: Pointer to MPT_ADAPTER structure 3510 * @ioc: Pointer to MPT_ADAPTER structure
3511 * @port_info: expander port_info struct 3511 * @port_info: expander port_info struct
3512 * @force: Flag to forcefully delete the expander 3512 * @force: Flag to forcefully delete the expander
3513 * 3513 *
3514 **/ 3514 **/
3515 3515
3516 static void mptsas_expander_delete(MPT_ADAPTER *ioc, 3516 static void mptsas_expander_delete(MPT_ADAPTER *ioc,
3517 struct mptsas_portinfo *port_info, u8 force) 3517 struct mptsas_portinfo *port_info, u8 force)
3518 { 3518 {
3519 3519
3520 struct mptsas_portinfo *parent; 3520 struct mptsas_portinfo *parent;
3521 int i; 3521 int i;
3522 u64 expander_sas_address; 3522 u64 expander_sas_address;
3523 struct mptsas_phyinfo *phy_info; 3523 struct mptsas_phyinfo *phy_info;
3524 struct mptsas_portinfo buffer; 3524 struct mptsas_portinfo buffer;
3525 struct mptsas_portinfo_details *port_details; 3525 struct mptsas_portinfo_details *port_details;
3526 struct sas_port *port; 3526 struct sas_port *port;
3527 3527
3528 if (!port_info) 3528 if (!port_info)
3529 return; 3529 return;
3530 3530
3531 /* see if expander is still there before deleting */ 3531 /* see if expander is still there before deleting */
3532 mptsas_sas_expander_pg0(ioc, &buffer, 3532 mptsas_sas_expander_pg0(ioc, &buffer,
3533 (MPI_SAS_EXPAND_PGAD_FORM_HANDLE << 3533 (MPI_SAS_EXPAND_PGAD_FORM_HANDLE <<
3534 MPI_SAS_EXPAND_PGAD_FORM_SHIFT), 3534 MPI_SAS_EXPAND_PGAD_FORM_SHIFT),
3535 port_info->phy_info[0].identify.handle); 3535 port_info->phy_info[0].identify.handle);
3536 3536
3537 if (buffer.num_phys) { 3537 if (buffer.num_phys) {
3538 kfree(buffer.phy_info); 3538 kfree(buffer.phy_info);
3539 if (!force) 3539 if (!force)
3540 return; 3540 return;
3541 } 3541 }
3542 3542
3543 3543
3544 /* 3544 /*
3545 * Obtain the port_info instance to the parent port 3545 * Obtain the port_info instance to the parent port
3546 */ 3546 */
3547 port_details = NULL; 3547 port_details = NULL;
3548 expander_sas_address = 3548 expander_sas_address =
3549 port_info->phy_info[0].identify.sas_address; 3549 port_info->phy_info[0].identify.sas_address;
3550 parent = mptsas_find_portinfo_by_handle(ioc, 3550 parent = mptsas_find_portinfo_by_handle(ioc,
3551 port_info->phy_info[0].identify.handle_parent); 3551 port_info->phy_info[0].identify.handle_parent);
3552 mptsas_delete_expander_siblings(ioc, parent, port_info); 3552 mptsas_delete_expander_siblings(ioc, parent, port_info);
3553 if (!parent) 3553 if (!parent)
3554 goto out; 3554 goto out;
3555 3555
3556 /* 3556 /*
3557 * Delete rphys in the parent that point 3557 * Delete rphys in the parent that point
3558 * to this expander. 3558 * to this expander.
3559 */ 3559 */
3560 phy_info = parent->phy_info; 3560 phy_info = parent->phy_info;
3561 port = NULL; 3561 port = NULL;
3562 for (i = 0; i < parent->num_phys; i++, phy_info++) { 3562 for (i = 0; i < parent->num_phys; i++, phy_info++) {
3563 if (!phy_info->phy) 3563 if (!phy_info->phy)
3564 continue; 3564 continue;
3565 if (phy_info->attached.sas_address != 3565 if (phy_info->attached.sas_address !=
3566 expander_sas_address) 3566 expander_sas_address)
3567 continue; 3567 continue;
3568 if (!port) { 3568 if (!port) {
3569 port = mptsas_get_port(phy_info); 3569 port = mptsas_get_port(phy_info);
3570 port_details = phy_info->port_details; 3570 port_details = phy_info->port_details;
3571 } 3571 }
3572 dev_printk(KERN_DEBUG, &phy_info->phy->dev, 3572 dev_printk(KERN_DEBUG, &phy_info->phy->dev,
3573 MYIOC_s_FMT "delete phy %d, phy-obj (0x%p)\n", ioc->name, 3573 MYIOC_s_FMT "delete phy %d, phy-obj (0x%p)\n", ioc->name,
3574 phy_info->phy_id, phy_info->phy); 3574 phy_info->phy_id, phy_info->phy);
3575 sas_port_delete_phy(port, phy_info->phy); 3575 sas_port_delete_phy(port, phy_info->phy);
3576 } 3576 }
3577 if (port) { 3577 if (port) {
3578 dev_printk(KERN_DEBUG, &port->dev, 3578 dev_printk(KERN_DEBUG, &port->dev,
3579 MYIOC_s_FMT "delete port %d, sas_addr (0x%llx)\n", 3579 MYIOC_s_FMT "delete port %d, sas_addr (0x%llx)\n",
3580 ioc->name, port->port_identifier, 3580 ioc->name, port->port_identifier,
3581 (unsigned long long)expander_sas_address); 3581 (unsigned long long)expander_sas_address);
3582 sas_port_delete(port); 3582 sas_port_delete(port);
3583 mptsas_port_delete(ioc, port_details); 3583 mptsas_port_delete(ioc, port_details);
3584 } 3584 }
3585 out: 3585 out:
3586 3586
3587 printk(MYIOC_s_INFO_FMT "delete expander: num_phys %d, " 3587 printk(MYIOC_s_INFO_FMT "delete expander: num_phys %d, "
3588 "sas_addr (0x%llx)\n", ioc->name, port_info->num_phys, 3588 "sas_addr (0x%llx)\n", ioc->name, port_info->num_phys,
3589 (unsigned long long)expander_sas_address); 3589 (unsigned long long)expander_sas_address);
3590 3590
3591 /* 3591 /*
3592 * free link 3592 * free link
3593 */ 3593 */
3594 list_del(&port_info->list); 3594 list_del(&port_info->list);
3595 kfree(port_info->phy_info); 3595 kfree(port_info->phy_info);
3596 kfree(port_info); 3596 kfree(port_info);
3597 } 3597 }
3598 3598
3599 3599
3600 /** 3600 /**
3601 * mptsas_send_expander_event - expanders events 3601 * mptsas_send_expander_event - expanders events
3602 * @ioc: Pointer to MPT_ADAPTER structure 3602 * @ioc: Pointer to MPT_ADAPTER structure
3603 * @expander_data: event data 3603 * @expander_data: event data
3604 * 3604 *
3605 * 3605 *
3606 * This function handles adding, removing, and refreshing 3606 * This function handles adding, removing, and refreshing
3607 * device handles within the expander objects. 3607 * device handles within the expander objects.
3608 */ 3608 */
3609 static void 3609 static void
3610 mptsas_send_expander_event(struct fw_event_work *fw_event) 3610 mptsas_send_expander_event(struct fw_event_work *fw_event)
3611 { 3611 {
3612 MPT_ADAPTER *ioc; 3612 MPT_ADAPTER *ioc;
3613 MpiEventDataSasExpanderStatusChange_t *expander_data; 3613 MpiEventDataSasExpanderStatusChange_t *expander_data;
3614 struct mptsas_portinfo *port_info; 3614 struct mptsas_portinfo *port_info;
3615 __le64 sas_address; 3615 __le64 sas_address;
3616 int i; 3616 int i;
3617 3617
3618 ioc = fw_event->ioc; 3618 ioc = fw_event->ioc;
3619 expander_data = (MpiEventDataSasExpanderStatusChange_t *) 3619 expander_data = (MpiEventDataSasExpanderStatusChange_t *)
3620 fw_event->event_data; 3620 fw_event->event_data;
3621 memcpy(&sas_address, &expander_data->SASAddress, sizeof(__le64)); 3621 memcpy(&sas_address, &expander_data->SASAddress, sizeof(__le64));
3622 sas_address = le64_to_cpu(sas_address); 3622 sas_address = le64_to_cpu(sas_address);
3623 port_info = mptsas_find_portinfo_by_sas_address(ioc, sas_address); 3623 port_info = mptsas_find_portinfo_by_sas_address(ioc, sas_address);
3624 3624
3625 if (expander_data->ReasonCode == MPI_EVENT_SAS_EXP_RC_ADDED) { 3625 if (expander_data->ReasonCode == MPI_EVENT_SAS_EXP_RC_ADDED) {
3626 if (port_info) { 3626 if (port_info) {
3627 for (i = 0; i < port_info->num_phys; i++) { 3627 for (i = 0; i < port_info->num_phys; i++) {
3628 port_info->phy_info[i].portinfo = port_info; 3628 port_info->phy_info[i].portinfo = port_info;
3629 port_info->phy_info[i].handle = 3629 port_info->phy_info[i].handle =
3630 le16_to_cpu(expander_data->DevHandle); 3630 le16_to_cpu(expander_data->DevHandle);
3631 port_info->phy_info[i].identify.sas_address = 3631 port_info->phy_info[i].identify.sas_address =
3632 le64_to_cpu(sas_address); 3632 le64_to_cpu(sas_address);
3633 port_info->phy_info[i].identify.handle_parent = 3633 port_info->phy_info[i].identify.handle_parent =
3634 le16_to_cpu(expander_data->ParentDevHandle); 3634 le16_to_cpu(expander_data->ParentDevHandle);
3635 } 3635 }
3636 mptsas_expander_refresh(ioc, port_info); 3636 mptsas_expander_refresh(ioc, port_info);
3637 } else if (!port_info && expander_data->NumPhys) 3637 } else if (!port_info && expander_data->NumPhys)
3638 mptsas_expander_event_add(ioc, expander_data); 3638 mptsas_expander_event_add(ioc, expander_data);
3639 } else if (expander_data->ReasonCode == 3639 } else if (expander_data->ReasonCode ==
3640 MPI_EVENT_SAS_EXP_RC_NOT_RESPONDING) 3640 MPI_EVENT_SAS_EXP_RC_NOT_RESPONDING)
3641 mptsas_expander_delete(ioc, port_info, 0); 3641 mptsas_expander_delete(ioc, port_info, 0);
3642 3642
3643 mptsas_free_fw_event(ioc, fw_event); 3643 mptsas_free_fw_event(ioc, fw_event);
3644 } 3644 }
3645 3645
3646 3646
3647 /** 3647 /**
3648 * mptsas_expander_add - 3648 * mptsas_expander_add -
3649 * @ioc: Pointer to MPT_ADAPTER structure 3649 * @ioc: Pointer to MPT_ADAPTER structure
3650 * @handle: 3650 * @handle:
3651 * 3651 *
3652 */ 3652 */
3653 struct mptsas_portinfo * 3653 struct mptsas_portinfo *
3654 mptsas_expander_add(MPT_ADAPTER *ioc, u16 handle) 3654 mptsas_expander_add(MPT_ADAPTER *ioc, u16 handle)
3655 { 3655 {
3656 struct mptsas_portinfo buffer, *port_info; 3656 struct mptsas_portinfo buffer, *port_info;
3657 int i; 3657 int i;
3658 3658
3659 if ((mptsas_sas_expander_pg0(ioc, &buffer, 3659 if ((mptsas_sas_expander_pg0(ioc, &buffer,
3660 (MPI_SAS_EXPAND_PGAD_FORM_HANDLE << 3660 (MPI_SAS_EXPAND_PGAD_FORM_HANDLE <<
3661 MPI_SAS_EXPAND_PGAD_FORM_SHIFT), handle))) 3661 MPI_SAS_EXPAND_PGAD_FORM_SHIFT), handle)))
3662 return NULL; 3662 return NULL;
3663 3663
3664 port_info = kzalloc(sizeof(struct mptsas_portinfo), GFP_ATOMIC); 3664 port_info = kzalloc(sizeof(struct mptsas_portinfo), GFP_ATOMIC);
3665 if (!port_info) { 3665 if (!port_info) {
3666 dfailprintk(ioc, printk(MYIOC_s_ERR_FMT 3666 dfailprintk(ioc, printk(MYIOC_s_ERR_FMT
3667 "%s: exit at line=%d\n", ioc->name, 3667 "%s: exit at line=%d\n", ioc->name,
3668 __func__, __LINE__)); 3668 __func__, __LINE__));
3669 return NULL; 3669 return NULL;
3670 } 3670 }
3671 port_info->num_phys = buffer.num_phys; 3671 port_info->num_phys = buffer.num_phys;
3672 port_info->phy_info = buffer.phy_info; 3672 port_info->phy_info = buffer.phy_info;
3673 for (i = 0; i < port_info->num_phys; i++) 3673 for (i = 0; i < port_info->num_phys; i++)
3674 port_info->phy_info[i].portinfo = port_info; 3674 port_info->phy_info[i].portinfo = port_info;
3675 mutex_lock(&ioc->sas_topology_mutex); 3675 mutex_lock(&ioc->sas_topology_mutex);
3676 list_add_tail(&port_info->list, &ioc->sas_topology); 3676 list_add_tail(&port_info->list, &ioc->sas_topology);
3677 mutex_unlock(&ioc->sas_topology_mutex); 3677 mutex_unlock(&ioc->sas_topology_mutex);
3678 printk(MYIOC_s_INFO_FMT "add expander: num_phys %d, " 3678 printk(MYIOC_s_INFO_FMT "add expander: num_phys %d, "
3679 "sas_addr (0x%llx)\n", ioc->name, port_info->num_phys, 3679 "sas_addr (0x%llx)\n", ioc->name, port_info->num_phys,
3680 (unsigned long long)buffer.phy_info[0].identify.sas_address); 3680 (unsigned long long)buffer.phy_info[0].identify.sas_address);
3681 mptsas_expander_refresh(ioc, port_info); 3681 mptsas_expander_refresh(ioc, port_info);
3682 return port_info; 3682 return port_info;
3683 } 3683 }
3684 3684
3685 static void 3685 static void
3686 mptsas_send_link_status_event(struct fw_event_work *fw_event) 3686 mptsas_send_link_status_event(struct fw_event_work *fw_event)
3687 { 3687 {
3688 MPT_ADAPTER *ioc; 3688 MPT_ADAPTER *ioc;
3689 MpiEventDataSasPhyLinkStatus_t *link_data; 3689 MpiEventDataSasPhyLinkStatus_t *link_data;
3690 struct mptsas_portinfo *port_info; 3690 struct mptsas_portinfo *port_info;
3691 struct mptsas_phyinfo *phy_info = NULL; 3691 struct mptsas_phyinfo *phy_info = NULL;
3692 __le64 sas_address; 3692 __le64 sas_address;
3693 u8 phy_num; 3693 u8 phy_num;
3694 u8 link_rate; 3694 u8 link_rate;
3695 3695
3696 ioc = fw_event->ioc; 3696 ioc = fw_event->ioc;
3697 link_data = (MpiEventDataSasPhyLinkStatus_t *)fw_event->event_data; 3697 link_data = (MpiEventDataSasPhyLinkStatus_t *)fw_event->event_data;
3698 3698
3699 memcpy(&sas_address, &link_data->SASAddress, sizeof(__le64)); 3699 memcpy(&sas_address, &link_data->SASAddress, sizeof(__le64));
3700 sas_address = le64_to_cpu(sas_address); 3700 sas_address = le64_to_cpu(sas_address);
3701 link_rate = link_data->LinkRates >> 4; 3701 link_rate = link_data->LinkRates >> 4;
3702 phy_num = link_data->PhyNum; 3702 phy_num = link_data->PhyNum;
3703 3703
3704 port_info = mptsas_find_portinfo_by_sas_address(ioc, sas_address); 3704 port_info = mptsas_find_portinfo_by_sas_address(ioc, sas_address);
3705 if (port_info) { 3705 if (port_info) {
3706 phy_info = &port_info->phy_info[phy_num]; 3706 phy_info = &port_info->phy_info[phy_num];
3707 if (phy_info) 3707 if (phy_info)
3708 phy_info->negotiated_link_rate = link_rate; 3708 phy_info->negotiated_link_rate = link_rate;
3709 } 3709 }
3710 3710
3711 if (link_rate == MPI_SAS_IOUNIT0_RATE_1_5 || 3711 if (link_rate == MPI_SAS_IOUNIT0_RATE_1_5 ||
3712 link_rate == MPI_SAS_IOUNIT0_RATE_3_0 || 3712 link_rate == MPI_SAS_IOUNIT0_RATE_3_0 ||
3713 link_rate == MPI_SAS_IOUNIT0_RATE_6_0) { 3713 link_rate == MPI_SAS_IOUNIT0_RATE_6_0) {
3714 3714
3715 if (!port_info) { 3715 if (!port_info) {
3716 if (ioc->old_sas_discovery_protocal) { 3716 if (ioc->old_sas_discovery_protocal) {
3717 port_info = mptsas_expander_add(ioc, 3717 port_info = mptsas_expander_add(ioc,
3718 le16_to_cpu(link_data->DevHandle)); 3718 le16_to_cpu(link_data->DevHandle));
3719 if (port_info) 3719 if (port_info)
3720 goto out; 3720 goto out;
3721 } 3721 }
3722 goto out; 3722 goto out;
3723 } 3723 }
3724 3724
3725 if (port_info == ioc->hba_port_info) 3725 if (port_info == ioc->hba_port_info)
3726 mptsas_probe_hba_phys(ioc); 3726 mptsas_probe_hba_phys(ioc);
3727 else 3727 else
3728 mptsas_expander_refresh(ioc, port_info); 3728 mptsas_expander_refresh(ioc, port_info);
3729 } else if (phy_info && phy_info->phy) { 3729 } else if (phy_info && phy_info->phy) {
3730 if (link_rate == MPI_SAS_IOUNIT0_RATE_PHY_DISABLED) 3730 if (link_rate == MPI_SAS_IOUNIT0_RATE_PHY_DISABLED)
3731 phy_info->phy->negotiated_linkrate = 3731 phy_info->phy->negotiated_linkrate =
3732 SAS_PHY_DISABLED; 3732 SAS_PHY_DISABLED;
3733 else if (link_rate == 3733 else if (link_rate ==
3734 MPI_SAS_IOUNIT0_RATE_FAILED_SPEED_NEGOTIATION) 3734 MPI_SAS_IOUNIT0_RATE_FAILED_SPEED_NEGOTIATION)
3735 phy_info->phy->negotiated_linkrate = 3735 phy_info->phy->negotiated_linkrate =
3736 SAS_LINK_RATE_FAILED; 3736 SAS_LINK_RATE_FAILED;
3737 else { 3737 else {
3738 phy_info->phy->negotiated_linkrate = 3738 phy_info->phy->negotiated_linkrate =
3739 SAS_LINK_RATE_UNKNOWN; 3739 SAS_LINK_RATE_UNKNOWN;
3740 if (ioc->device_missing_delay && 3740 if (ioc->device_missing_delay &&
3741 mptsas_is_end_device(&phy_info->attached)) { 3741 mptsas_is_end_device(&phy_info->attached)) {
3742 struct scsi_device *sdev; 3742 struct scsi_device *sdev;
3743 VirtDevice *vdevice; 3743 VirtDevice *vdevice;
3744 u8 channel, id; 3744 u8 channel, id;
3745 id = phy_info->attached.id; 3745 id = phy_info->attached.id;
3746 channel = phy_info->attached.channel; 3746 channel = phy_info->attached.channel;
3747 devtprintk(ioc, printk(MYIOC_s_DEBUG_FMT 3747 devtprintk(ioc, printk(MYIOC_s_DEBUG_FMT
3748 "Link down for fw_id %d:fw_channel %d\n", 3748 "Link down for fw_id %d:fw_channel %d\n",
3749 ioc->name, phy_info->attached.id, 3749 ioc->name, phy_info->attached.id,
3750 phy_info->attached.channel)); 3750 phy_info->attached.channel));
3751 3751
3752 shost_for_each_device(sdev, ioc->sh) { 3752 shost_for_each_device(sdev, ioc->sh) {
3753 vdevice = sdev->hostdata; 3753 vdevice = sdev->hostdata;
3754 if ((vdevice == NULL) || 3754 if ((vdevice == NULL) ||
3755 (vdevice->vtarget == NULL)) 3755 (vdevice->vtarget == NULL))
3756 continue; 3756 continue;
3757 if ((vdevice->vtarget->tflags & 3757 if ((vdevice->vtarget->tflags &
3758 MPT_TARGET_FLAGS_RAID_COMPONENT || 3758 MPT_TARGET_FLAGS_RAID_COMPONENT ||
3759 vdevice->vtarget->raidVolume)) 3759 vdevice->vtarget->raidVolume))
3760 continue; 3760 continue;
3761 if (vdevice->vtarget->id == id && 3761 if (vdevice->vtarget->id == id &&
3762 vdevice->vtarget->channel == 3762 vdevice->vtarget->channel ==
3763 channel) 3763 channel)
3764 devtprintk(ioc, 3764 devtprintk(ioc,
3765 printk(MYIOC_s_DEBUG_FMT 3765 printk(MYIOC_s_DEBUG_FMT
3766 "SDEV OUTSTANDING CMDS" 3766 "SDEV OUTSTANDING CMDS"
3767 "%d\n", ioc->name, 3767 "%d\n", ioc->name,
3768 sdev->device_busy)); 3768 sdev->device_busy));
3769 } 3769 }
3770 3770
3771 } 3771 }
3772 } 3772 }
3773 } 3773 }
3774 out: 3774 out:
3775 mptsas_free_fw_event(ioc, fw_event); 3775 mptsas_free_fw_event(ioc, fw_event);
3776 } 3776 }
3777 3777
3778 static void 3778 static void
3779 mptsas_not_responding_devices(MPT_ADAPTER *ioc) 3779 mptsas_not_responding_devices(MPT_ADAPTER *ioc)
3780 { 3780 {
3781 struct mptsas_portinfo buffer, *port_info; 3781 struct mptsas_portinfo buffer, *port_info;
3782 struct mptsas_device_info *sas_info; 3782 struct mptsas_device_info *sas_info;
3783 struct mptsas_devinfo sas_device; 3783 struct mptsas_devinfo sas_device;
3784 u32 handle; 3784 u32 handle;
3785 VirtTarget *vtarget = NULL; 3785 VirtTarget *vtarget = NULL;
3786 struct mptsas_phyinfo *phy_info; 3786 struct mptsas_phyinfo *phy_info;
3787 u8 found_expander; 3787 u8 found_expander;
3788 int retval, retry_count; 3788 int retval, retry_count;
3789 unsigned long flags; 3789 unsigned long flags;
3790 3790
3791 mpt_findImVolumes(ioc); 3791 mpt_findImVolumes(ioc);
3792 3792
3793 spin_lock_irqsave(&ioc->taskmgmt_lock, flags); 3793 spin_lock_irqsave(&ioc->taskmgmt_lock, flags);
3794 if (ioc->ioc_reset_in_progress) { 3794 if (ioc->ioc_reset_in_progress) {
3795 dfailprintk(ioc, printk(MYIOC_s_DEBUG_FMT 3795 dfailprintk(ioc, printk(MYIOC_s_DEBUG_FMT
3796 "%s: exiting due to a parallel reset \n", ioc->name, 3796 "%s: exiting due to a parallel reset \n", ioc->name,
3797 __func__)); 3797 __func__));
3798 spin_unlock_irqrestore(&ioc->taskmgmt_lock, flags); 3798 spin_unlock_irqrestore(&ioc->taskmgmt_lock, flags);
3799 return; 3799 return;
3800 } 3800 }
3801 spin_unlock_irqrestore(&ioc->taskmgmt_lock, flags); 3801 spin_unlock_irqrestore(&ioc->taskmgmt_lock, flags);
3802 3802
3803 /* devices, logical volumes */ 3803 /* devices, logical volumes */
3804 mutex_lock(&ioc->sas_device_info_mutex); 3804 mutex_lock(&ioc->sas_device_info_mutex);
3805 redo_device_scan: 3805 redo_device_scan:
3806 list_for_each_entry(sas_info, &ioc->sas_device_info_list, list) { 3806 list_for_each_entry(sas_info, &ioc->sas_device_info_list, list) {
3807 if (sas_info->is_cached) 3807 if (sas_info->is_cached)
3808 continue; 3808 continue;
3809 if (!sas_info->is_logical_volume) { 3809 if (!sas_info->is_logical_volume) {
3810 sas_device.handle = 0; 3810 sas_device.handle = 0;
3811 retry_count = 0; 3811 retry_count = 0;
3812 retry_page: 3812 retry_page:
3813 retval = mptsas_sas_device_pg0(ioc, &sas_device, 3813 retval = mptsas_sas_device_pg0(ioc, &sas_device,
3814 (MPI_SAS_DEVICE_PGAD_FORM_BUS_TARGET_ID 3814 (MPI_SAS_DEVICE_PGAD_FORM_BUS_TARGET_ID
3815 << MPI_SAS_DEVICE_PGAD_FORM_SHIFT), 3815 << MPI_SAS_DEVICE_PGAD_FORM_SHIFT),
3816 (sas_info->fw.channel << 8) + 3816 (sas_info->fw.channel << 8) +
3817 sas_info->fw.id); 3817 sas_info->fw.id);
3818 3818
3819 if (sas_device.handle) 3819 if (sas_device.handle)
3820 continue; 3820 continue;
3821 if (retval == -EBUSY) { 3821 if (retval == -EBUSY) {
3822 spin_lock_irqsave(&ioc->taskmgmt_lock, flags); 3822 spin_lock_irqsave(&ioc->taskmgmt_lock, flags);
3823 if (ioc->ioc_reset_in_progress) { 3823 if (ioc->ioc_reset_in_progress) {
3824 dfailprintk(ioc, 3824 dfailprintk(ioc,
3825 printk(MYIOC_s_DEBUG_FMT 3825 printk(MYIOC_s_DEBUG_FMT
3826 "%s: exiting due to reset\n", 3826 "%s: exiting due to reset\n",
3827 ioc->name, __func__)); 3827 ioc->name, __func__));
3828 spin_unlock_irqrestore 3828 spin_unlock_irqrestore
3829 (&ioc->taskmgmt_lock, flags); 3829 (&ioc->taskmgmt_lock, flags);
3830 mutex_unlock(&ioc-> 3830 mutex_unlock(&ioc->
3831 sas_device_info_mutex); 3831 sas_device_info_mutex);
3832 return; 3832 return;
3833 } 3833 }
3834 spin_unlock_irqrestore(&ioc->taskmgmt_lock, 3834 spin_unlock_irqrestore(&ioc->taskmgmt_lock,
3835 flags); 3835 flags);
3836 } 3836 }
3837 3837
3838 if (retval && (retval != -ENODEV)) { 3838 if (retval && (retval != -ENODEV)) {
3839 if (retry_count < 10) { 3839 if (retry_count < 10) {
3840 retry_count++; 3840 retry_count++;
3841 goto retry_page; 3841 goto retry_page;
3842 } else { 3842 } else {
3843 devtprintk(ioc, printk(MYIOC_s_DEBUG_FMT 3843 devtprintk(ioc, printk(MYIOC_s_DEBUG_FMT
3844 "%s: Config page retry exceeded retry " 3844 "%s: Config page retry exceeded retry "
3845 "count deleting device 0x%llx\n", 3845 "count deleting device 0x%llx\n",
3846 ioc->name, __func__, 3846 ioc->name, __func__,
3847 sas_info->sas_address)); 3847 sas_info->sas_address));
3848 } 3848 }
3849 } 3849 }
3850 3850
3851 /* delete device */ 3851 /* delete device */
3852 vtarget = mptsas_find_vtarget(ioc, 3852 vtarget = mptsas_find_vtarget(ioc,
3853 sas_info->fw.channel, sas_info->fw.id); 3853 sas_info->fw.channel, sas_info->fw.id);
3854 3854
3855 if (vtarget) 3855 if (vtarget)
3856 vtarget->deleted = 1; 3856 vtarget->deleted = 1;
3857 3857
3858 phy_info = mptsas_find_phyinfo_by_sas_address(ioc, 3858 phy_info = mptsas_find_phyinfo_by_sas_address(ioc,
3859 sas_info->sas_address); 3859 sas_info->sas_address);
3860 3860
3861 if (phy_info) { 3861 if (phy_info) {
3862 mptsas_del_end_device(ioc, phy_info); 3862 mptsas_del_end_device(ioc, phy_info);
3863 goto redo_device_scan; 3863 goto redo_device_scan;
3864 } 3864 }
3865 } else 3865 } else
3866 mptsas_volume_delete(ioc, sas_info->fw.id); 3866 mptsas_volume_delete(ioc, sas_info->fw.id);
3867 } 3867 }
3868 mutex_unlock(&ioc->sas_device_info_mutex); 3868 mutex_unlock(&ioc->sas_device_info_mutex);
3869 3869
3870 /* expanders */ 3870 /* expanders */
3871 mutex_lock(&ioc->sas_topology_mutex); 3871 mutex_lock(&ioc->sas_topology_mutex);
3872 redo_expander_scan: 3872 redo_expander_scan:
3873 list_for_each_entry(port_info, &ioc->sas_topology, list) { 3873 list_for_each_entry(port_info, &ioc->sas_topology, list) {
3874 3874
3875 if (port_info->phy_info && 3875 if (port_info->phy_info &&
3876 (!(port_info->phy_info[0].identify.device_info & 3876 (!(port_info->phy_info[0].identify.device_info &
3877 MPI_SAS_DEVICE_INFO_SMP_TARGET))) 3877 MPI_SAS_DEVICE_INFO_SMP_TARGET)))
3878 continue; 3878 continue;
3879 found_expander = 0; 3879 found_expander = 0;
3880 handle = 0xFFFF; 3880 handle = 0xFFFF;
3881 while (!mptsas_sas_expander_pg0(ioc, &buffer, 3881 while (!mptsas_sas_expander_pg0(ioc, &buffer,
3882 (MPI_SAS_EXPAND_PGAD_FORM_GET_NEXT_HANDLE << 3882 (MPI_SAS_EXPAND_PGAD_FORM_GET_NEXT_HANDLE <<
3883 MPI_SAS_EXPAND_PGAD_FORM_SHIFT), handle) && 3883 MPI_SAS_EXPAND_PGAD_FORM_SHIFT), handle) &&
3884 !found_expander) { 3884 !found_expander) {
3885 3885
3886 handle = buffer.phy_info[0].handle; 3886 handle = buffer.phy_info[0].handle;
3887 if (buffer.phy_info[0].identify.sas_address == 3887 if (buffer.phy_info[0].identify.sas_address ==
3888 port_info->phy_info[0].identify.sas_address) { 3888 port_info->phy_info[0].identify.sas_address) {
3889 found_expander = 1; 3889 found_expander = 1;
3890 } 3890 }
3891 kfree(buffer.phy_info); 3891 kfree(buffer.phy_info);
3892 } 3892 }
3893 3893
3894 if (!found_expander) { 3894 if (!found_expander) {
3895 mptsas_expander_delete(ioc, port_info, 0); 3895 mptsas_expander_delete(ioc, port_info, 0);
3896 goto redo_expander_scan; 3896 goto redo_expander_scan;
3897 } 3897 }
3898 } 3898 }
3899 mutex_unlock(&ioc->sas_topology_mutex); 3899 mutex_unlock(&ioc->sas_topology_mutex);
3900 } 3900 }
3901 3901
3902 /** 3902 /**
3903 * mptsas_probe_expanders - adding expanders 3903 * mptsas_probe_expanders - adding expanders
3904 * @ioc: Pointer to MPT_ADAPTER structure 3904 * @ioc: Pointer to MPT_ADAPTER structure
3905 * 3905 *
3906 **/ 3906 **/
3907 static void 3907 static void
3908 mptsas_probe_expanders(MPT_ADAPTER *ioc) 3908 mptsas_probe_expanders(MPT_ADAPTER *ioc)
3909 { 3909 {
3910 struct mptsas_portinfo buffer, *port_info; 3910 struct mptsas_portinfo buffer, *port_info;
3911 u32 handle; 3911 u32 handle;
3912 int i; 3912 int i;
3913 3913
3914 handle = 0xFFFF; 3914 handle = 0xFFFF;
3915 while (!mptsas_sas_expander_pg0(ioc, &buffer, 3915 while (!mptsas_sas_expander_pg0(ioc, &buffer,
3916 (MPI_SAS_EXPAND_PGAD_FORM_GET_NEXT_HANDLE << 3916 (MPI_SAS_EXPAND_PGAD_FORM_GET_NEXT_HANDLE <<
3917 MPI_SAS_EXPAND_PGAD_FORM_SHIFT), handle)) { 3917 MPI_SAS_EXPAND_PGAD_FORM_SHIFT), handle)) {
3918 3918
3919 handle = buffer.phy_info[0].handle; 3919 handle = buffer.phy_info[0].handle;
3920 port_info = mptsas_find_portinfo_by_sas_address(ioc, 3920 port_info = mptsas_find_portinfo_by_sas_address(ioc,
3921 buffer.phy_info[0].identify.sas_address); 3921 buffer.phy_info[0].identify.sas_address);
3922 3922
3923 if (port_info) { 3923 if (port_info) {
3924 /* refreshing handles */ 3924 /* refreshing handles */
3925 for (i = 0; i < buffer.num_phys; i++) { 3925 for (i = 0; i < buffer.num_phys; i++) {
3926 port_info->phy_info[i].handle = handle; 3926 port_info->phy_info[i].handle = handle;
3927 port_info->phy_info[i].identify.handle_parent = 3927 port_info->phy_info[i].identify.handle_parent =
3928 buffer.phy_info[0].identify.handle_parent; 3928 buffer.phy_info[0].identify.handle_parent;
3929 } 3929 }
3930 mptsas_expander_refresh(ioc, port_info); 3930 mptsas_expander_refresh(ioc, port_info);
3931 kfree(buffer.phy_info); 3931 kfree(buffer.phy_info);
3932 continue; 3932 continue;
3933 } 3933 }
3934 3934
3935 port_info = kzalloc(sizeof(struct mptsas_portinfo), GFP_KERNEL); 3935 port_info = kzalloc(sizeof(struct mptsas_portinfo), GFP_KERNEL);
3936 if (!port_info) { 3936 if (!port_info) {
3937 dfailprintk(ioc, printk(MYIOC_s_ERR_FMT 3937 dfailprintk(ioc, printk(MYIOC_s_ERR_FMT
3938 "%s: exit at line=%d\n", ioc->name, 3938 "%s: exit at line=%d\n", ioc->name,
3939 __func__, __LINE__)); 3939 __func__, __LINE__));
3940 return; 3940 return;
3941 } 3941 }
3942 port_info->num_phys = buffer.num_phys; 3942 port_info->num_phys = buffer.num_phys;
3943 port_info->phy_info = buffer.phy_info; 3943 port_info->phy_info = buffer.phy_info;
3944 for (i = 0; i < port_info->num_phys; i++) 3944 for (i = 0; i < port_info->num_phys; i++)
3945 port_info->phy_info[i].portinfo = port_info; 3945 port_info->phy_info[i].portinfo = port_info;
3946 mutex_lock(&ioc->sas_topology_mutex); 3946 mutex_lock(&ioc->sas_topology_mutex);
3947 list_add_tail(&port_info->list, &ioc->sas_topology); 3947 list_add_tail(&port_info->list, &ioc->sas_topology);
3948 mutex_unlock(&ioc->sas_topology_mutex); 3948 mutex_unlock(&ioc->sas_topology_mutex);
3949 printk(MYIOC_s_INFO_FMT "add expander: num_phys %d, " 3949 printk(MYIOC_s_INFO_FMT "add expander: num_phys %d, "
3950 "sas_addr (0x%llx)\n", ioc->name, port_info->num_phys, 3950 "sas_addr (0x%llx)\n", ioc->name, port_info->num_phys,
3951 (unsigned long long)buffer.phy_info[0].identify.sas_address); 3951 (unsigned long long)buffer.phy_info[0].identify.sas_address);
3952 mptsas_expander_refresh(ioc, port_info); 3952 mptsas_expander_refresh(ioc, port_info);
3953 } 3953 }
3954 } 3954 }
3955 3955
3956 static void 3956 static void
3957 mptsas_probe_devices(MPT_ADAPTER *ioc) 3957 mptsas_probe_devices(MPT_ADAPTER *ioc)
3958 { 3958 {
3959 u16 handle; 3959 u16 handle;
3960 struct mptsas_devinfo sas_device; 3960 struct mptsas_devinfo sas_device;
3961 struct mptsas_phyinfo *phy_info; 3961 struct mptsas_phyinfo *phy_info;
3962 3962
3963 handle = 0xFFFF; 3963 handle = 0xFFFF;
3964 while (!(mptsas_sas_device_pg0(ioc, &sas_device, 3964 while (!(mptsas_sas_device_pg0(ioc, &sas_device,
3965 MPI_SAS_DEVICE_PGAD_FORM_GET_NEXT_HANDLE, handle))) { 3965 MPI_SAS_DEVICE_PGAD_FORM_GET_NEXT_HANDLE, handle))) {
3966 3966
3967 handle = sas_device.handle; 3967 handle = sas_device.handle;
3968 3968
3969 if ((sas_device.device_info & 3969 if ((sas_device.device_info &
3970 (MPI_SAS_DEVICE_INFO_SSP_TARGET | 3970 (MPI_SAS_DEVICE_INFO_SSP_TARGET |
3971 MPI_SAS_DEVICE_INFO_STP_TARGET | 3971 MPI_SAS_DEVICE_INFO_STP_TARGET |
3972 MPI_SAS_DEVICE_INFO_SATA_DEVICE)) == 0) 3972 MPI_SAS_DEVICE_INFO_SATA_DEVICE)) == 0)
3973 continue; 3973 continue;
3974 3974
3975 /* If there is no FW B_T mapping for this device then continue 3975 /* If there is no FW B_T mapping for this device then continue
3976 * */ 3976 * */
3977 if (!(sas_device.flags & MPI_SAS_DEVICE0_FLAGS_DEVICE_PRESENT) 3977 if (!(sas_device.flags & MPI_SAS_DEVICE0_FLAGS_DEVICE_PRESENT)
3978 || !(sas_device.flags & 3978 || !(sas_device.flags &
3979 MPI_SAS_DEVICE0_FLAGS_DEVICE_MAPPED)) 3979 MPI_SAS_DEVICE0_FLAGS_DEVICE_MAPPED))
3980 continue; 3980 continue;
3981 3981
3982 phy_info = mptsas_refreshing_device_handles(ioc, &sas_device); 3982 phy_info = mptsas_refreshing_device_handles(ioc, &sas_device);
3983 if (!phy_info) 3983 if (!phy_info)
3984 continue; 3984 continue;
3985 3985
3986 if (mptsas_get_rphy(phy_info)) 3986 if (mptsas_get_rphy(phy_info))
3987 continue; 3987 continue;
3988 3988
3989 mptsas_add_end_device(ioc, phy_info); 3989 mptsas_add_end_device(ioc, phy_info);
3990 } 3990 }
3991 } 3991 }
3992 3992
3993 /** 3993 /**
3994 * mptsas_scan_sas_topology - 3994 * mptsas_scan_sas_topology -
3995 * @ioc: Pointer to MPT_ADAPTER structure 3995 * @ioc: Pointer to MPT_ADAPTER structure
3996 * @sas_address: 3996 * @sas_address:
3997 * 3997 *
3998 **/ 3998 **/
3999 static void 3999 static void
4000 mptsas_scan_sas_topology(MPT_ADAPTER *ioc) 4000 mptsas_scan_sas_topology(MPT_ADAPTER *ioc)
4001 { 4001 {
4002 struct scsi_device *sdev; 4002 struct scsi_device *sdev;
4003 int i; 4003 int i;
4004 4004
4005 mptsas_probe_hba_phys(ioc); 4005 mptsas_probe_hba_phys(ioc);
4006 mptsas_probe_expanders(ioc); 4006 mptsas_probe_expanders(ioc);
4007 mptsas_probe_devices(ioc); 4007 mptsas_probe_devices(ioc);
4008 4008
4009 /* 4009 /*
4010 Reporting RAID volumes. 4010 Reporting RAID volumes.
4011 */ 4011 */
4012 if (!ioc->ir_firmware || !ioc->raid_data.pIocPg2 || 4012 if (!ioc->ir_firmware || !ioc->raid_data.pIocPg2 ||
4013 !ioc->raid_data.pIocPg2->NumActiveVolumes) 4013 !ioc->raid_data.pIocPg2->NumActiveVolumes)
4014 return; 4014 return;
4015 for (i = 0; i < ioc->raid_data.pIocPg2->NumActiveVolumes; i++) { 4015 for (i = 0; i < ioc->raid_data.pIocPg2->NumActiveVolumes; i++) {
4016 sdev = scsi_device_lookup(ioc->sh, MPTSAS_RAID_CHANNEL, 4016 sdev = scsi_device_lookup(ioc->sh, MPTSAS_RAID_CHANNEL,
4017 ioc->raid_data.pIocPg2->RaidVolume[i].VolumeID, 0); 4017 ioc->raid_data.pIocPg2->RaidVolume[i].VolumeID, 0);
4018 if (sdev) { 4018 if (sdev) {
4019 scsi_device_put(sdev); 4019 scsi_device_put(sdev);
4020 continue; 4020 continue;
4021 } 4021 }
4022 printk(MYIOC_s_INFO_FMT "attaching raid volume, channel %d, " 4022 printk(MYIOC_s_INFO_FMT "attaching raid volume, channel %d, "
4023 "id %d\n", ioc->name, MPTSAS_RAID_CHANNEL, 4023 "id %d\n", ioc->name, MPTSAS_RAID_CHANNEL,
4024 ioc->raid_data.pIocPg2->RaidVolume[i].VolumeID); 4024 ioc->raid_data.pIocPg2->RaidVolume[i].VolumeID);
4025 scsi_add_device(ioc->sh, MPTSAS_RAID_CHANNEL, 4025 scsi_add_device(ioc->sh, MPTSAS_RAID_CHANNEL,
4026 ioc->raid_data.pIocPg2->RaidVolume[i].VolumeID, 0); 4026 ioc->raid_data.pIocPg2->RaidVolume[i].VolumeID, 0);
4027 } 4027 }
4028 } 4028 }
4029 4029
4030 4030
4031 static void 4031 static void
4032 mptsas_handle_queue_full_event(struct fw_event_work *fw_event) 4032 mptsas_handle_queue_full_event(struct fw_event_work *fw_event)
4033 { 4033 {
4034 MPT_ADAPTER *ioc; 4034 MPT_ADAPTER *ioc;
4035 EventDataQueueFull_t *qfull_data; 4035 EventDataQueueFull_t *qfull_data;
4036 struct mptsas_device_info *sas_info; 4036 struct mptsas_device_info *sas_info;
4037 struct scsi_device *sdev; 4037 struct scsi_device *sdev;
4038 int depth; 4038 int depth;
4039 int id = -1; 4039 int id = -1;
4040 int channel = -1; 4040 int channel = -1;
4041 int fw_id, fw_channel; 4041 int fw_id, fw_channel;
4042 u16 current_depth; 4042 u16 current_depth;
4043 4043
4044 4044
4045 ioc = fw_event->ioc; 4045 ioc = fw_event->ioc;
4046 qfull_data = (EventDataQueueFull_t *)fw_event->event_data; 4046 qfull_data = (EventDataQueueFull_t *)fw_event->event_data;
4047 fw_id = qfull_data->TargetID; 4047 fw_id = qfull_data->TargetID;
4048 fw_channel = qfull_data->Bus; 4048 fw_channel = qfull_data->Bus;
4049 current_depth = le16_to_cpu(qfull_data->CurrentDepth); 4049 current_depth = le16_to_cpu(qfull_data->CurrentDepth);
4050 4050
4051 /* if hidden raid component, look for the volume id */ 4051 /* if hidden raid component, look for the volume id */
4052 mutex_lock(&ioc->sas_device_info_mutex); 4052 mutex_lock(&ioc->sas_device_info_mutex);
4053 if (mptscsih_is_phys_disk(ioc, fw_channel, fw_id)) { 4053 if (mptscsih_is_phys_disk(ioc, fw_channel, fw_id)) {
4054 list_for_each_entry(sas_info, &ioc->sas_device_info_list, 4054 list_for_each_entry(sas_info, &ioc->sas_device_info_list,
4055 list) { 4055 list) {
4056 if (sas_info->is_cached || 4056 if (sas_info->is_cached ||
4057 sas_info->is_logical_volume) 4057 sas_info->is_logical_volume)
4058 continue; 4058 continue;
4059 if (sas_info->is_hidden_raid_component && 4059 if (sas_info->is_hidden_raid_component &&
4060 (sas_info->fw.channel == fw_channel && 4060 (sas_info->fw.channel == fw_channel &&
4061 sas_info->fw.id == fw_id)) { 4061 sas_info->fw.id == fw_id)) {
4062 id = sas_info->volume_id; 4062 id = sas_info->volume_id;
4063 channel = MPTSAS_RAID_CHANNEL; 4063 channel = MPTSAS_RAID_CHANNEL;
4064 goto out; 4064 goto out;
4065 } 4065 }
4066 } 4066 }
4067 } else { 4067 } else {
4068 list_for_each_entry(sas_info, &ioc->sas_device_info_list, 4068 list_for_each_entry(sas_info, &ioc->sas_device_info_list,
4069 list) { 4069 list) {
4070 if (sas_info->is_cached || 4070 if (sas_info->is_cached ||
4071 sas_info->is_hidden_raid_component || 4071 sas_info->is_hidden_raid_component ||
4072 sas_info->is_logical_volume) 4072 sas_info->is_logical_volume)
4073 continue; 4073 continue;
4074 if (sas_info->fw.channel == fw_channel && 4074 if (sas_info->fw.channel == fw_channel &&
4075 sas_info->fw.id == fw_id) { 4075 sas_info->fw.id == fw_id) {
4076 id = sas_info->os.id; 4076 id = sas_info->os.id;
4077 channel = sas_info->os.channel; 4077 channel = sas_info->os.channel;
4078 goto out; 4078 goto out;
4079 } 4079 }
4080 } 4080 }
4081 4081
4082 } 4082 }
4083 4083
4084 out: 4084 out:
4085 mutex_unlock(&ioc->sas_device_info_mutex); 4085 mutex_unlock(&ioc->sas_device_info_mutex);
4086 4086
4087 if (id != -1) { 4087 if (id != -1) {
4088 shost_for_each_device(sdev, ioc->sh) { 4088 shost_for_each_device(sdev, ioc->sh) {
4089 if (sdev->id == id && sdev->channel == channel) { 4089 if (sdev->id == id && sdev->channel == channel) {
4090 if (current_depth > sdev->queue_depth) { 4090 if (current_depth > sdev->queue_depth) {
4091 sdev_printk(KERN_INFO, sdev, 4091 sdev_printk(KERN_INFO, sdev,
4092 "strange observation, the queue " 4092 "strange observation, the queue "
4093 "depth is (%d) meanwhile fw queue " 4093 "depth is (%d) meanwhile fw queue "
4094 "depth (%d)\n", sdev->queue_depth, 4094 "depth (%d)\n", sdev->queue_depth,
4095 current_depth); 4095 current_depth);
4096 continue; 4096 continue;
4097 } 4097 }
4098 depth = scsi_track_queue_full(sdev, 4098 depth = scsi_track_queue_full(sdev,
4099 current_depth - 1); 4099 current_depth - 1);
4100 if (depth > 0) 4100 if (depth > 0)
4101 sdev_printk(KERN_INFO, sdev, 4101 sdev_printk(KERN_INFO, sdev,
4102 "Queue depth reduced to (%d)\n", 4102 "Queue depth reduced to (%d)\n",
4103 depth); 4103 depth);
4104 else if (depth < 0) 4104 else if (depth < 0)
4105 sdev_printk(KERN_INFO, sdev, 4105 sdev_printk(KERN_INFO, sdev,
4106 "Tagged Command Queueing is being " 4106 "Tagged Command Queueing is being "
4107 "disabled\n"); 4107 "disabled\n");
4108 else if (depth == 0) 4108 else if (depth == 0)
4109 sdev_printk(KERN_INFO, sdev, 4109 sdev_printk(KERN_INFO, sdev,
4110 "Queue depth not changed yet\n"); 4110 "Queue depth not changed yet\n");
4111 } 4111 }
4112 } 4112 }
4113 } 4113 }
4114 4114
4115 mptsas_free_fw_event(ioc, fw_event); 4115 mptsas_free_fw_event(ioc, fw_event);
4116 } 4116 }
4117 4117
4118 4118
4119 static struct mptsas_phyinfo * 4119 static struct mptsas_phyinfo *
4120 mptsas_find_phyinfo_by_sas_address(MPT_ADAPTER *ioc, u64 sas_address) 4120 mptsas_find_phyinfo_by_sas_address(MPT_ADAPTER *ioc, u64 sas_address)
4121 { 4121 {
4122 struct mptsas_portinfo *port_info; 4122 struct mptsas_portinfo *port_info;
4123 struct mptsas_phyinfo *phy_info = NULL; 4123 struct mptsas_phyinfo *phy_info = NULL;
4124 int i; 4124 int i;
4125 4125
4126 mutex_lock(&ioc->sas_topology_mutex); 4126 mutex_lock(&ioc->sas_topology_mutex);
4127 list_for_each_entry(port_info, &ioc->sas_topology, list) { 4127 list_for_each_entry(port_info, &ioc->sas_topology, list) {
4128 for (i = 0; i < port_info->num_phys; i++) { 4128 for (i = 0; i < port_info->num_phys; i++) {
4129 if (!mptsas_is_end_device( 4129 if (!mptsas_is_end_device(
4130 &port_info->phy_info[i].attached)) 4130 &port_info->phy_info[i].attached))
4131 continue; 4131 continue;
4132 if (port_info->phy_info[i].attached.sas_address 4132 if (port_info->phy_info[i].attached.sas_address
4133 != sas_address) 4133 != sas_address)
4134 continue; 4134 continue;
4135 phy_info = &port_info->phy_info[i]; 4135 phy_info = &port_info->phy_info[i];
4136 break; 4136 break;
4137 } 4137 }
4138 } 4138 }
4139 mutex_unlock(&ioc->sas_topology_mutex); 4139 mutex_unlock(&ioc->sas_topology_mutex);
4140 return phy_info; 4140 return phy_info;
4141 } 4141 }
4142 4142
4143 /** 4143 /**
4144 * mptsas_find_phyinfo_by_phys_disk_num - 4144 * mptsas_find_phyinfo_by_phys_disk_num -
4145 * @ioc: Pointer to MPT_ADAPTER structure 4145 * @ioc: Pointer to MPT_ADAPTER structure
4146 * @phys_disk_num: 4146 * @phys_disk_num:
4147 * @channel: 4147 * @channel:
4148 * @id: 4148 * @id:
4149 * 4149 *
4150 **/ 4150 **/
4151 static struct mptsas_phyinfo * 4151 static struct mptsas_phyinfo *
4152 mptsas_find_phyinfo_by_phys_disk_num(MPT_ADAPTER *ioc, u8 phys_disk_num, 4152 mptsas_find_phyinfo_by_phys_disk_num(MPT_ADAPTER *ioc, u8 phys_disk_num,
4153 u8 channel, u8 id) 4153 u8 channel, u8 id)
4154 { 4154 {
4155 struct mptsas_phyinfo *phy_info = NULL; 4155 struct mptsas_phyinfo *phy_info = NULL;
4156 struct mptsas_portinfo *port_info; 4156 struct mptsas_portinfo *port_info;
4157 RaidPhysDiskPage1_t *phys_disk = NULL; 4157 RaidPhysDiskPage1_t *phys_disk = NULL;
4158 int num_paths; 4158 int num_paths;
4159 u64 sas_address = 0; 4159 u64 sas_address = 0;
4160 int i; 4160 int i;
4161 4161
4162 phy_info = NULL; 4162 phy_info = NULL;
4163 if (!ioc->raid_data.pIocPg3) 4163 if (!ioc->raid_data.pIocPg3)
4164 return NULL; 4164 return NULL;
4165 /* dual port support */ 4165 /* dual port support */
4166 num_paths = mpt_raid_phys_disk_get_num_paths(ioc, phys_disk_num); 4166 num_paths = mpt_raid_phys_disk_get_num_paths(ioc, phys_disk_num);
4167 if (!num_paths) 4167 if (!num_paths)
4168 goto out; 4168 goto out;
4169 phys_disk = kzalloc(offsetof(RaidPhysDiskPage1_t, Path) + 4169 phys_disk = kzalloc(offsetof(RaidPhysDiskPage1_t, Path) +
4170 (num_paths * sizeof(RAID_PHYS_DISK1_PATH)), GFP_KERNEL); 4170 (num_paths * sizeof(RAID_PHYS_DISK1_PATH)), GFP_KERNEL);
4171 if (!phys_disk) 4171 if (!phys_disk)
4172 goto out; 4172 goto out;
4173 mpt_raid_phys_disk_pg1(ioc, phys_disk_num, phys_disk); 4173 mpt_raid_phys_disk_pg1(ioc, phys_disk_num, phys_disk);
4174 for (i = 0; i < num_paths; i++) { 4174 for (i = 0; i < num_paths; i++) {
4175 if ((phys_disk->Path[i].Flags & 1) != 0) 4175 if ((phys_disk->Path[i].Flags & 1) != 0)
4176 /* entry no longer valid */ 4176 /* entry no longer valid */
4177 continue; 4177 continue;
4178 if ((id == phys_disk->Path[i].PhysDiskID) && 4178 if ((id == phys_disk->Path[i].PhysDiskID) &&
4179 (channel == phys_disk->Path[i].PhysDiskBus)) { 4179 (channel == phys_disk->Path[i].PhysDiskBus)) {
4180 memcpy(&sas_address, &phys_disk->Path[i].WWID, 4180 memcpy(&sas_address, &phys_disk->Path[i].WWID,
4181 sizeof(u64)); 4181 sizeof(u64));
4182 phy_info = mptsas_find_phyinfo_by_sas_address(ioc, 4182 phy_info = mptsas_find_phyinfo_by_sas_address(ioc,
4183 sas_address); 4183 sas_address);
4184 goto out; 4184 goto out;
4185 } 4185 }
4186 } 4186 }
4187 4187
4188 out: 4188 out:
4189 kfree(phys_disk); 4189 kfree(phys_disk);
4190 if (phy_info) 4190 if (phy_info)
4191 return phy_info; 4191 return phy_info;
4192 4192
4193 /* 4193 /*
4194 * Extra code to handle RAID0 case, where the sas_address is not updated 4194 * Extra code to handle RAID0 case, where the sas_address is not updated
4195 * in phys_disk_page_1 when hotswapped 4195 * in phys_disk_page_1 when hotswapped
4196 */ 4196 */
4197 mutex_lock(&ioc->sas_topology_mutex); 4197 mutex_lock(&ioc->sas_topology_mutex);
4198 list_for_each_entry(port_info, &ioc->sas_topology, list) { 4198 list_for_each_entry(port_info, &ioc->sas_topology, list) {
4199 for (i = 0; i < port_info->num_phys && !phy_info; i++) { 4199 for (i = 0; i < port_info->num_phys && !phy_info; i++) {
4200 if (!mptsas_is_end_device( 4200 if (!mptsas_is_end_device(
4201 &port_info->phy_info[i].attached)) 4201 &port_info->phy_info[i].attached))
4202 continue; 4202 continue;
4203 if (port_info->phy_info[i].attached.phys_disk_num == ~0) 4203 if (port_info->phy_info[i].attached.phys_disk_num == ~0)
4204 continue; 4204 continue;
4205 if ((port_info->phy_info[i].attached.phys_disk_num == 4205 if ((port_info->phy_info[i].attached.phys_disk_num ==
4206 phys_disk_num) && 4206 phys_disk_num) &&
4207 (port_info->phy_info[i].attached.id == id) && 4207 (port_info->phy_info[i].attached.id == id) &&
4208 (port_info->phy_info[i].attached.channel == 4208 (port_info->phy_info[i].attached.channel ==
4209 channel)) 4209 channel))
4210 phy_info = &port_info->phy_info[i]; 4210 phy_info = &port_info->phy_info[i];
4211 } 4211 }
4212 } 4212 }
4213 mutex_unlock(&ioc->sas_topology_mutex); 4213 mutex_unlock(&ioc->sas_topology_mutex);
4214 return phy_info; 4214 return phy_info;
4215 } 4215 }
4216 4216
4217 static void 4217 static void
4218 mptsas_reprobe_lun(struct scsi_device *sdev, void *data) 4218 mptsas_reprobe_lun(struct scsi_device *sdev, void *data)
4219 { 4219 {
4220 int rc; 4220 int rc;
4221 4221
4222 sdev->no_uld_attach = data ? 1 : 0; 4222 sdev->no_uld_attach = data ? 1 : 0;
4223 rc = scsi_device_reprobe(sdev); 4223 rc = scsi_device_reprobe(sdev);
4224 } 4224 }
4225 4225
4226 static void 4226 static void
4227 mptsas_reprobe_target(struct scsi_target *starget, int uld_attach) 4227 mptsas_reprobe_target(struct scsi_target *starget, int uld_attach)
4228 { 4228 {
4229 starget_for_each_device(starget, uld_attach ? (void *)1 : NULL, 4229 starget_for_each_device(starget, uld_attach ? (void *)1 : NULL,
4230 mptsas_reprobe_lun); 4230 mptsas_reprobe_lun);
4231 } 4231 }
4232 4232
4233 static void 4233 static void
4234 mptsas_adding_inactive_raid_components(MPT_ADAPTER *ioc, u8 channel, u8 id) 4234 mptsas_adding_inactive_raid_components(MPT_ADAPTER *ioc, u8 channel, u8 id)
4235 { 4235 {
4236 CONFIGPARMS cfg; 4236 CONFIGPARMS cfg;
4237 ConfigPageHeader_t hdr; 4237 ConfigPageHeader_t hdr;
4238 dma_addr_t dma_handle; 4238 dma_addr_t dma_handle;
4239 pRaidVolumePage0_t buffer = NULL; 4239 pRaidVolumePage0_t buffer = NULL;
4240 RaidPhysDiskPage0_t phys_disk; 4240 RaidPhysDiskPage0_t phys_disk;
4241 int i; 4241 int i;
4242 struct mptsas_phyinfo *phy_info; 4242 struct mptsas_phyinfo *phy_info;
4243 struct mptsas_devinfo sas_device; 4243 struct mptsas_devinfo sas_device;
4244 4244
4245 memset(&cfg, 0 , sizeof(CONFIGPARMS)); 4245 memset(&cfg, 0 , sizeof(CONFIGPARMS));
4246 memset(&hdr, 0 , sizeof(ConfigPageHeader_t)); 4246 memset(&hdr, 0 , sizeof(ConfigPageHeader_t));
4247 hdr.PageType = MPI_CONFIG_PAGETYPE_RAID_VOLUME; 4247 hdr.PageType = MPI_CONFIG_PAGETYPE_RAID_VOLUME;
4248 cfg.pageAddr = (channel << 8) + id; 4248 cfg.pageAddr = (channel << 8) + id;
4249 cfg.cfghdr.hdr = &hdr; 4249 cfg.cfghdr.hdr = &hdr;
4250 cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER; 4250 cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
4251 cfg.timeout = SAS_CONFIG_PAGE_TIMEOUT; 4251 cfg.timeout = SAS_CONFIG_PAGE_TIMEOUT;
4252 4252
4253 if (mpt_config(ioc, &cfg) != 0) 4253 if (mpt_config(ioc, &cfg) != 0)
4254 goto out; 4254 goto out;
4255 4255
4256 if (!hdr.PageLength) 4256 if (!hdr.PageLength)
4257 goto out; 4257 goto out;
4258 4258
4259 buffer = pci_alloc_consistent(ioc->pcidev, hdr.PageLength * 4, 4259 buffer = pci_alloc_consistent(ioc->pcidev, hdr.PageLength * 4,
4260 &dma_handle); 4260 &dma_handle);
4261 4261
4262 if (!buffer) 4262 if (!buffer)
4263 goto out; 4263 goto out;
4264 4264
4265 cfg.physAddr = dma_handle; 4265 cfg.physAddr = dma_handle;
4266 cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT; 4266 cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
4267 4267
4268 if (mpt_config(ioc, &cfg) != 0) 4268 if (mpt_config(ioc, &cfg) != 0)
4269 goto out; 4269 goto out;
4270 4270
4271 if (!(buffer->VolumeStatus.Flags & 4271 if (!(buffer->VolumeStatus.Flags &
4272 MPI_RAIDVOL0_STATUS_FLAG_VOLUME_INACTIVE)) 4272 MPI_RAIDVOL0_STATUS_FLAG_VOLUME_INACTIVE))
4273 goto out; 4273 goto out;
4274 4274
4275 if (!buffer->NumPhysDisks) 4275 if (!buffer->NumPhysDisks)
4276 goto out; 4276 goto out;
4277 4277
4278 for (i = 0; i < buffer->NumPhysDisks; i++) { 4278 for (i = 0; i < buffer->NumPhysDisks; i++) {
4279 4279
4280 if (mpt_raid_phys_disk_pg0(ioc, 4280 if (mpt_raid_phys_disk_pg0(ioc,
4281 buffer->PhysDisk[i].PhysDiskNum, &phys_disk) != 0) 4281 buffer->PhysDisk[i].PhysDiskNum, &phys_disk) != 0)
4282 continue; 4282 continue;
4283 4283
4284 if (mptsas_sas_device_pg0(ioc, &sas_device, 4284 if (mptsas_sas_device_pg0(ioc, &sas_device,
4285 (MPI_SAS_DEVICE_PGAD_FORM_BUS_TARGET_ID << 4285 (MPI_SAS_DEVICE_PGAD_FORM_BUS_TARGET_ID <<
4286 MPI_SAS_DEVICE_PGAD_FORM_SHIFT), 4286 MPI_SAS_DEVICE_PGAD_FORM_SHIFT),
4287 (phys_disk.PhysDiskBus << 8) + 4287 (phys_disk.PhysDiskBus << 8) +
4288 phys_disk.PhysDiskID)) 4288 phys_disk.PhysDiskID))
4289 continue; 4289 continue;
4290 4290
4291 /* If there is no FW B_T mapping for this device then continue 4291 /* If there is no FW B_T mapping for this device then continue
4292 * */ 4292 * */
4293 if (!(sas_device.flags & MPI_SAS_DEVICE0_FLAGS_DEVICE_PRESENT) 4293 if (!(sas_device.flags & MPI_SAS_DEVICE0_FLAGS_DEVICE_PRESENT)
4294 || !(sas_device.flags & 4294 || !(sas_device.flags &
4295 MPI_SAS_DEVICE0_FLAGS_DEVICE_MAPPED)) 4295 MPI_SAS_DEVICE0_FLAGS_DEVICE_MAPPED))
4296 continue; 4296 continue;
4297 4297
4298 4298
4299 phy_info = mptsas_find_phyinfo_by_sas_address(ioc, 4299 phy_info = mptsas_find_phyinfo_by_sas_address(ioc,
4300 sas_device.sas_address); 4300 sas_device.sas_address);
4301 mptsas_add_end_device(ioc, phy_info); 4301 mptsas_add_end_device(ioc, phy_info);
4302 } 4302 }
4303 4303
4304 out: 4304 out:
4305 if (buffer) 4305 if (buffer)
4306 pci_free_consistent(ioc->pcidev, hdr.PageLength * 4, buffer, 4306 pci_free_consistent(ioc->pcidev, hdr.PageLength * 4, buffer,
4307 dma_handle); 4307 dma_handle);
4308 } 4308 }
4309 /* 4309 /*
4310 * Work queue thread to handle SAS hotplug events 4310 * Work queue thread to handle SAS hotplug events
4311 */ 4311 */
4312 static void 4312 static void
4313 mptsas_hotplug_work(MPT_ADAPTER *ioc, struct fw_event_work *fw_event, 4313 mptsas_hotplug_work(MPT_ADAPTER *ioc, struct fw_event_work *fw_event,
4314 struct mptsas_hotplug_event *hot_plug_info) 4314 struct mptsas_hotplug_event *hot_plug_info)
4315 { 4315 {
4316 struct mptsas_phyinfo *phy_info; 4316 struct mptsas_phyinfo *phy_info;
4317 struct scsi_target * starget; 4317 struct scsi_target * starget;
4318 struct mptsas_devinfo sas_device; 4318 struct mptsas_devinfo sas_device;
4319 VirtTarget *vtarget; 4319 VirtTarget *vtarget;
4320 int i; 4320 int i;
4321 struct mptsas_portinfo *port_info; 4321 struct mptsas_portinfo *port_info;
4322 4322
4323 switch (hot_plug_info->event_type) { 4323 switch (hot_plug_info->event_type) {
4324 4324
4325 case MPTSAS_ADD_PHYSDISK: 4325 case MPTSAS_ADD_PHYSDISK:
4326 4326
4327 if (!ioc->raid_data.pIocPg2) 4327 if (!ioc->raid_data.pIocPg2)
4328 break; 4328 break;
4329 4329
4330 for (i = 0; i < ioc->raid_data.pIocPg2->NumActiveVolumes; i++) { 4330 for (i = 0; i < ioc->raid_data.pIocPg2->NumActiveVolumes; i++) {
4331 if (ioc->raid_data.pIocPg2->RaidVolume[i].VolumeID == 4331 if (ioc->raid_data.pIocPg2->RaidVolume[i].VolumeID ==
4332 hot_plug_info->id) { 4332 hot_plug_info->id) {
4333 printk(MYIOC_s_WARN_FMT "firmware bug: unable " 4333 printk(MYIOC_s_WARN_FMT "firmware bug: unable "
4334 "to add hidden disk - target_id matchs " 4334 "to add hidden disk - target_id matchs "
4335 "volume_id\n", ioc->name); 4335 "volume_id\n", ioc->name);
4336 mptsas_free_fw_event(ioc, fw_event); 4336 mptsas_free_fw_event(ioc, fw_event);
4337 return; 4337 return;
4338 } 4338 }
4339 } 4339 }
4340 mpt_findImVolumes(ioc); 4340 mpt_findImVolumes(ioc);
4341 4341
4342 case MPTSAS_ADD_DEVICE: 4342 case MPTSAS_ADD_DEVICE:
4343 memset(&sas_device, 0, sizeof(struct mptsas_devinfo)); 4343 memset(&sas_device, 0, sizeof(struct mptsas_devinfo));
4344 mptsas_sas_device_pg0(ioc, &sas_device, 4344 mptsas_sas_device_pg0(ioc, &sas_device,
4345 (MPI_SAS_DEVICE_PGAD_FORM_BUS_TARGET_ID << 4345 (MPI_SAS_DEVICE_PGAD_FORM_BUS_TARGET_ID <<
4346 MPI_SAS_DEVICE_PGAD_FORM_SHIFT), 4346 MPI_SAS_DEVICE_PGAD_FORM_SHIFT),
4347 (hot_plug_info->channel << 8) + 4347 (hot_plug_info->channel << 8) +
4348 hot_plug_info->id); 4348 hot_plug_info->id);
4349 4349
4350 /* If there is no FW B_T mapping for this device then break 4350 /* If there is no FW B_T mapping for this device then break
4351 * */ 4351 * */
4352 if (!(sas_device.flags & MPI_SAS_DEVICE0_FLAGS_DEVICE_PRESENT) 4352 if (!(sas_device.flags & MPI_SAS_DEVICE0_FLAGS_DEVICE_PRESENT)
4353 || !(sas_device.flags & 4353 || !(sas_device.flags &
4354 MPI_SAS_DEVICE0_FLAGS_DEVICE_MAPPED)) 4354 MPI_SAS_DEVICE0_FLAGS_DEVICE_MAPPED))
4355 break; 4355 break;
4356 4356
4357 if (!sas_device.handle) 4357 if (!sas_device.handle)
4358 return; 4358 return;
4359 4359
4360 phy_info = mptsas_refreshing_device_handles(ioc, &sas_device); 4360 phy_info = mptsas_refreshing_device_handles(ioc, &sas_device);
4361 /* Only For SATA Device ADD */ 4361 /* Only For SATA Device ADD */
4362 if (!phy_info && (sas_device.device_info & 4362 if (!phy_info && (sas_device.device_info &
4363 MPI_SAS_DEVICE_INFO_SATA_DEVICE)) { 4363 MPI_SAS_DEVICE_INFO_SATA_DEVICE)) {
4364 devtprintk(ioc, printk(MYIOC_s_DEBUG_FMT 4364 devtprintk(ioc, printk(MYIOC_s_DEBUG_FMT
4365 "%s %d SATA HOT PLUG: " 4365 "%s %d SATA HOT PLUG: "
4366 "parent handle of device %x\n", ioc->name, 4366 "parent handle of device %x\n", ioc->name,
4367 __func__, __LINE__, sas_device.handle_parent)); 4367 __func__, __LINE__, sas_device.handle_parent));
4368 port_info = mptsas_find_portinfo_by_handle(ioc, 4368 port_info = mptsas_find_portinfo_by_handle(ioc,
4369 sas_device.handle_parent); 4369 sas_device.handle_parent);
4370 4370
4371 if (port_info == ioc->hba_port_info) 4371 if (port_info == ioc->hba_port_info)
4372 mptsas_probe_hba_phys(ioc); 4372 mptsas_probe_hba_phys(ioc);
4373 else if (port_info) 4373 else if (port_info)
4374 mptsas_expander_refresh(ioc, port_info); 4374 mptsas_expander_refresh(ioc, port_info);
4375 else { 4375 else {
4376 dfailprintk(ioc, printk(MYIOC_s_ERR_FMT 4376 dfailprintk(ioc, printk(MYIOC_s_ERR_FMT
4377 "%s %d port info is NULL\n", 4377 "%s %d port info is NULL\n",
4378 ioc->name, __func__, __LINE__)); 4378 ioc->name, __func__, __LINE__));
4379 break; 4379 break;
4380 } 4380 }
4381 phy_info = mptsas_refreshing_device_handles 4381 phy_info = mptsas_refreshing_device_handles
4382 (ioc, &sas_device); 4382 (ioc, &sas_device);
4383 } 4383 }
4384 4384
4385 if (!phy_info) { 4385 if (!phy_info) {
4386 dfailprintk(ioc, printk(MYIOC_s_ERR_FMT 4386 dfailprintk(ioc, printk(MYIOC_s_ERR_FMT
4387 "%s %d phy info is NULL\n", 4387 "%s %d phy info is NULL\n",
4388 ioc->name, __func__, __LINE__)); 4388 ioc->name, __func__, __LINE__));
4389 break; 4389 break;
4390 } 4390 }
4391 4391
4392 if (mptsas_get_rphy(phy_info)) 4392 if (mptsas_get_rphy(phy_info))
4393 break; 4393 break;
4394 4394
4395 mptsas_add_end_device(ioc, phy_info); 4395 mptsas_add_end_device(ioc, phy_info);
4396 break; 4396 break;
4397 4397
4398 case MPTSAS_DEL_DEVICE: 4398 case MPTSAS_DEL_DEVICE:
4399 phy_info = mptsas_find_phyinfo_by_sas_address(ioc, 4399 phy_info = mptsas_find_phyinfo_by_sas_address(ioc,
4400 hot_plug_info->sas_address); 4400 hot_plug_info->sas_address);
4401 mptsas_del_end_device(ioc, phy_info); 4401 mptsas_del_end_device(ioc, phy_info);
4402 break; 4402 break;
4403 4403
4404 case MPTSAS_DEL_PHYSDISK: 4404 case MPTSAS_DEL_PHYSDISK:
4405 4405
4406 mpt_findImVolumes(ioc); 4406 mpt_findImVolumes(ioc);
4407 4407
4408 phy_info = mptsas_find_phyinfo_by_phys_disk_num( 4408 phy_info = mptsas_find_phyinfo_by_phys_disk_num(
4409 ioc, hot_plug_info->phys_disk_num, 4409 ioc, hot_plug_info->phys_disk_num,
4410 hot_plug_info->channel, 4410 hot_plug_info->channel,
4411 hot_plug_info->id); 4411 hot_plug_info->id);
4412 mptsas_del_end_device(ioc, phy_info); 4412 mptsas_del_end_device(ioc, phy_info);
4413 break; 4413 break;
4414 4414
4415 case MPTSAS_ADD_PHYSDISK_REPROBE: 4415 case MPTSAS_ADD_PHYSDISK_REPROBE:
4416 4416
4417 if (mptsas_sas_device_pg0(ioc, &sas_device, 4417 if (mptsas_sas_device_pg0(ioc, &sas_device,
4418 (MPI_SAS_DEVICE_PGAD_FORM_BUS_TARGET_ID << 4418 (MPI_SAS_DEVICE_PGAD_FORM_BUS_TARGET_ID <<
4419 MPI_SAS_DEVICE_PGAD_FORM_SHIFT), 4419 MPI_SAS_DEVICE_PGAD_FORM_SHIFT),
4420 (hot_plug_info->channel << 8) + hot_plug_info->id)) { 4420 (hot_plug_info->channel << 8) + hot_plug_info->id)) {
4421 dfailprintk(ioc, printk(MYIOC_s_ERR_FMT 4421 dfailprintk(ioc, printk(MYIOC_s_ERR_FMT
4422 "%s: fw_id=%d exit at line=%d\n", ioc->name, 4422 "%s: fw_id=%d exit at line=%d\n", ioc->name,
4423 __func__, hot_plug_info->id, __LINE__)); 4423 __func__, hot_plug_info->id, __LINE__));
4424 break; 4424 break;
4425 } 4425 }
4426 4426
4427 /* If there is no FW B_T mapping for this device then break 4427 /* If there is no FW B_T mapping for this device then break
4428 * */ 4428 * */
4429 if (!(sas_device.flags & MPI_SAS_DEVICE0_FLAGS_DEVICE_PRESENT) 4429 if (!(sas_device.flags & MPI_SAS_DEVICE0_FLAGS_DEVICE_PRESENT)
4430 || !(sas_device.flags & 4430 || !(sas_device.flags &
4431 MPI_SAS_DEVICE0_FLAGS_DEVICE_MAPPED)) 4431 MPI_SAS_DEVICE0_FLAGS_DEVICE_MAPPED))
4432 break; 4432 break;
4433 4433
4434 phy_info = mptsas_find_phyinfo_by_sas_address( 4434 phy_info = mptsas_find_phyinfo_by_sas_address(
4435 ioc, sas_device.sas_address); 4435 ioc, sas_device.sas_address);
4436 4436
4437 if (!phy_info) { 4437 if (!phy_info) {
4438 dfailprintk(ioc, printk(MYIOC_s_ERR_FMT 4438 dfailprintk(ioc, printk(MYIOC_s_ERR_FMT
4439 "%s: fw_id=%d exit at line=%d\n", ioc->name, 4439 "%s: fw_id=%d exit at line=%d\n", ioc->name,
4440 __func__, hot_plug_info->id, __LINE__)); 4440 __func__, hot_plug_info->id, __LINE__));
4441 break; 4441 break;
4442 } 4442 }
4443 4443
4444 starget = mptsas_get_starget(phy_info); 4444 starget = mptsas_get_starget(phy_info);
4445 if (!starget) { 4445 if (!starget) {
4446 dfailprintk(ioc, printk(MYIOC_s_ERR_FMT 4446 dfailprintk(ioc, printk(MYIOC_s_ERR_FMT
4447 "%s: fw_id=%d exit at line=%d\n", ioc->name, 4447 "%s: fw_id=%d exit at line=%d\n", ioc->name,
4448 __func__, hot_plug_info->id, __LINE__)); 4448 __func__, hot_plug_info->id, __LINE__));
4449 break; 4449 break;
4450 } 4450 }
4451 4451
4452 vtarget = starget->hostdata; 4452 vtarget = starget->hostdata;
4453 if (!vtarget) { 4453 if (!vtarget) {
4454 dfailprintk(ioc, printk(MYIOC_s_ERR_FMT 4454 dfailprintk(ioc, printk(MYIOC_s_ERR_FMT
4455 "%s: fw_id=%d exit at line=%d\n", ioc->name, 4455 "%s: fw_id=%d exit at line=%d\n", ioc->name,
4456 __func__, hot_plug_info->id, __LINE__)); 4456 __func__, hot_plug_info->id, __LINE__));
4457 break; 4457 break;
4458 } 4458 }
4459 4459
4460 mpt_findImVolumes(ioc); 4460 mpt_findImVolumes(ioc);
4461 4461
4462 starget_printk(KERN_INFO, starget, MYIOC_s_FMT "RAID Hidding: " 4462 starget_printk(KERN_INFO, starget, MYIOC_s_FMT "RAID Hidding: "
4463 "fw_channel=%d, fw_id=%d, physdsk %d, sas_addr 0x%llx\n", 4463 "fw_channel=%d, fw_id=%d, physdsk %d, sas_addr 0x%llx\n",
4464 ioc->name, hot_plug_info->channel, hot_plug_info->id, 4464 ioc->name, hot_plug_info->channel, hot_plug_info->id,
4465 hot_plug_info->phys_disk_num, (unsigned long long) 4465 hot_plug_info->phys_disk_num, (unsigned long long)
4466 sas_device.sas_address); 4466 sas_device.sas_address);
4467 4467
4468 vtarget->id = hot_plug_info->phys_disk_num; 4468 vtarget->id = hot_plug_info->phys_disk_num;
4469 vtarget->tflags |= MPT_TARGET_FLAGS_RAID_COMPONENT; 4469 vtarget->tflags |= MPT_TARGET_FLAGS_RAID_COMPONENT;
4470 phy_info->attached.phys_disk_num = hot_plug_info->phys_disk_num; 4470 phy_info->attached.phys_disk_num = hot_plug_info->phys_disk_num;
4471 mptsas_reprobe_target(starget, 1); 4471 mptsas_reprobe_target(starget, 1);
4472 break; 4472 break;
4473 4473
4474 case MPTSAS_DEL_PHYSDISK_REPROBE: 4474 case MPTSAS_DEL_PHYSDISK_REPROBE:
4475 4475
4476 if (mptsas_sas_device_pg0(ioc, &sas_device, 4476 if (mptsas_sas_device_pg0(ioc, &sas_device,
4477 (MPI_SAS_DEVICE_PGAD_FORM_BUS_TARGET_ID << 4477 (MPI_SAS_DEVICE_PGAD_FORM_BUS_TARGET_ID <<
4478 MPI_SAS_DEVICE_PGAD_FORM_SHIFT), 4478 MPI_SAS_DEVICE_PGAD_FORM_SHIFT),
4479 (hot_plug_info->channel << 8) + hot_plug_info->id)) { 4479 (hot_plug_info->channel << 8) + hot_plug_info->id)) {
4480 dfailprintk(ioc, printk(MYIOC_s_ERR_FMT 4480 dfailprintk(ioc, printk(MYIOC_s_ERR_FMT
4481 "%s: fw_id=%d exit at line=%d\n", 4481 "%s: fw_id=%d exit at line=%d\n",
4482 ioc->name, __func__, 4482 ioc->name, __func__,
4483 hot_plug_info->id, __LINE__)); 4483 hot_plug_info->id, __LINE__));
4484 break; 4484 break;
4485 } 4485 }
4486 4486
4487 /* If there is no FW B_T mapping for this device then break 4487 /* If there is no FW B_T mapping for this device then break
4488 * */ 4488 * */
4489 if (!(sas_device.flags & MPI_SAS_DEVICE0_FLAGS_DEVICE_PRESENT) 4489 if (!(sas_device.flags & MPI_SAS_DEVICE0_FLAGS_DEVICE_PRESENT)
4490 || !(sas_device.flags & 4490 || !(sas_device.flags &
4491 MPI_SAS_DEVICE0_FLAGS_DEVICE_MAPPED)) 4491 MPI_SAS_DEVICE0_FLAGS_DEVICE_MAPPED))
4492 break; 4492 break;
4493 4493
4494 phy_info = mptsas_find_phyinfo_by_sas_address(ioc, 4494 phy_info = mptsas_find_phyinfo_by_sas_address(ioc,
4495 sas_device.sas_address); 4495 sas_device.sas_address);
4496 if (!phy_info) { 4496 if (!phy_info) {
4497 dfailprintk(ioc, printk(MYIOC_s_ERR_FMT 4497 dfailprintk(ioc, printk(MYIOC_s_ERR_FMT
4498 "%s: fw_id=%d exit at line=%d\n", ioc->name, 4498 "%s: fw_id=%d exit at line=%d\n", ioc->name,
4499 __func__, hot_plug_info->id, __LINE__)); 4499 __func__, hot_plug_info->id, __LINE__));
4500 break; 4500 break;
4501 } 4501 }
4502 4502
4503 starget = mptsas_get_starget(phy_info); 4503 starget = mptsas_get_starget(phy_info);
4504 if (!starget) { 4504 if (!starget) {
4505 dfailprintk(ioc, printk(MYIOC_s_ERR_FMT 4505 dfailprintk(ioc, printk(MYIOC_s_ERR_FMT
4506 "%s: fw_id=%d exit at line=%d\n", ioc->name, 4506 "%s: fw_id=%d exit at line=%d\n", ioc->name,
4507 __func__, hot_plug_info->id, __LINE__)); 4507 __func__, hot_plug_info->id, __LINE__));
4508 break; 4508 break;
4509 } 4509 }
4510 4510
4511 vtarget = starget->hostdata; 4511 vtarget = starget->hostdata;
4512 if (!vtarget) { 4512 if (!vtarget) {
4513 dfailprintk(ioc, printk(MYIOC_s_ERR_FMT 4513 dfailprintk(ioc, printk(MYIOC_s_ERR_FMT
4514 "%s: fw_id=%d exit at line=%d\n", ioc->name, 4514 "%s: fw_id=%d exit at line=%d\n", ioc->name,
4515 __func__, hot_plug_info->id, __LINE__)); 4515 __func__, hot_plug_info->id, __LINE__));
4516 break; 4516 break;
4517 } 4517 }
4518 4518
4519 if (!(vtarget->tflags & MPT_TARGET_FLAGS_RAID_COMPONENT)) { 4519 if (!(vtarget->tflags & MPT_TARGET_FLAGS_RAID_COMPONENT)) {
4520 dfailprintk(ioc, printk(MYIOC_s_ERR_FMT 4520 dfailprintk(ioc, printk(MYIOC_s_ERR_FMT
4521 "%s: fw_id=%d exit at line=%d\n", ioc->name, 4521 "%s: fw_id=%d exit at line=%d\n", ioc->name,
4522 __func__, hot_plug_info->id, __LINE__)); 4522 __func__, hot_plug_info->id, __LINE__));
4523 break; 4523 break;
4524 } 4524 }
4525 4525
4526 mpt_findImVolumes(ioc); 4526 mpt_findImVolumes(ioc);
4527 4527
4528 starget_printk(KERN_INFO, starget, MYIOC_s_FMT "RAID Exposing:" 4528 starget_printk(KERN_INFO, starget, MYIOC_s_FMT "RAID Exposing:"
4529 " fw_channel=%d, fw_id=%d, physdsk %d, sas_addr 0x%llx\n", 4529 " fw_channel=%d, fw_id=%d, physdsk %d, sas_addr 0x%llx\n",
4530 ioc->name, hot_plug_info->channel, hot_plug_info->id, 4530 ioc->name, hot_plug_info->channel, hot_plug_info->id,
4531 hot_plug_info->phys_disk_num, (unsigned long long) 4531 hot_plug_info->phys_disk_num, (unsigned long long)
4532 sas_device.sas_address); 4532 sas_device.sas_address);
4533 4533
4534 vtarget->tflags &= ~MPT_TARGET_FLAGS_RAID_COMPONENT; 4534 vtarget->tflags &= ~MPT_TARGET_FLAGS_RAID_COMPONENT;
4535 vtarget->id = hot_plug_info->id; 4535 vtarget->id = hot_plug_info->id;
4536 phy_info->attached.phys_disk_num = ~0; 4536 phy_info->attached.phys_disk_num = ~0;
4537 mptsas_reprobe_target(starget, 0); 4537 mptsas_reprobe_target(starget, 0);
4538 mptsas_add_device_component_by_fw(ioc, 4538 mptsas_add_device_component_by_fw(ioc,
4539 hot_plug_info->channel, hot_plug_info->id); 4539 hot_plug_info->channel, hot_plug_info->id);
4540 break; 4540 break;
4541 4541
4542 case MPTSAS_ADD_RAID: 4542 case MPTSAS_ADD_RAID:
4543 4543
4544 mpt_findImVolumes(ioc); 4544 mpt_findImVolumes(ioc);
4545 printk(MYIOC_s_INFO_FMT "attaching raid volume, channel %d, " 4545 printk(MYIOC_s_INFO_FMT "attaching raid volume, channel %d, "
4546 "id %d\n", ioc->name, MPTSAS_RAID_CHANNEL, 4546 "id %d\n", ioc->name, MPTSAS_RAID_CHANNEL,
4547 hot_plug_info->id); 4547 hot_plug_info->id);
4548 scsi_add_device(ioc->sh, MPTSAS_RAID_CHANNEL, 4548 scsi_add_device(ioc->sh, MPTSAS_RAID_CHANNEL,
4549 hot_plug_info->id, 0); 4549 hot_plug_info->id, 0);
4550 break; 4550 break;
4551 4551
4552 case MPTSAS_DEL_RAID: 4552 case MPTSAS_DEL_RAID:
4553 4553
4554 mpt_findImVolumes(ioc); 4554 mpt_findImVolumes(ioc);
4555 printk(MYIOC_s_INFO_FMT "removing raid volume, channel %d, " 4555 printk(MYIOC_s_INFO_FMT "removing raid volume, channel %d, "
4556 "id %d\n", ioc->name, MPTSAS_RAID_CHANNEL, 4556 "id %d\n", ioc->name, MPTSAS_RAID_CHANNEL,
4557 hot_plug_info->id); 4557 hot_plug_info->id);
4558 scsi_remove_device(hot_plug_info->sdev); 4558 scsi_remove_device(hot_plug_info->sdev);
4559 scsi_device_put(hot_plug_info->sdev); 4559 scsi_device_put(hot_plug_info->sdev);
4560 break; 4560 break;
4561 4561
4562 case MPTSAS_ADD_INACTIVE_VOLUME: 4562 case MPTSAS_ADD_INACTIVE_VOLUME:
4563 4563
4564 mpt_findImVolumes(ioc); 4564 mpt_findImVolumes(ioc);
4565 mptsas_adding_inactive_raid_components(ioc, 4565 mptsas_adding_inactive_raid_components(ioc,
4566 hot_plug_info->channel, hot_plug_info->id); 4566 hot_plug_info->channel, hot_plug_info->id);
4567 break; 4567 break;
4568 4568
4569 default: 4569 default:
4570 break; 4570 break;
4571 } 4571 }
4572 4572
4573 mptsas_free_fw_event(ioc, fw_event); 4573 mptsas_free_fw_event(ioc, fw_event);
4574 } 4574 }
4575 4575
4576 static void 4576 static void
4577 mptsas_send_sas_event(struct fw_event_work *fw_event) 4577 mptsas_send_sas_event(struct fw_event_work *fw_event)
4578 { 4578 {
4579 MPT_ADAPTER *ioc; 4579 MPT_ADAPTER *ioc;
4580 struct mptsas_hotplug_event hot_plug_info; 4580 struct mptsas_hotplug_event hot_plug_info;
4581 EVENT_DATA_SAS_DEVICE_STATUS_CHANGE *sas_event_data; 4581 EVENT_DATA_SAS_DEVICE_STATUS_CHANGE *sas_event_data;
4582 u32 device_info; 4582 u32 device_info;
4583 u64 sas_address; 4583 u64 sas_address;
4584 4584
4585 ioc = fw_event->ioc; 4585 ioc = fw_event->ioc;
4586 sas_event_data = (EVENT_DATA_SAS_DEVICE_STATUS_CHANGE *) 4586 sas_event_data = (EVENT_DATA_SAS_DEVICE_STATUS_CHANGE *)
4587 fw_event->event_data; 4587 fw_event->event_data;
4588 device_info = le32_to_cpu(sas_event_data->DeviceInfo); 4588 device_info = le32_to_cpu(sas_event_data->DeviceInfo);
4589 4589
4590 if ((device_info & 4590 if ((device_info &
4591 (MPI_SAS_DEVICE_INFO_SSP_TARGET | 4591 (MPI_SAS_DEVICE_INFO_SSP_TARGET |
4592 MPI_SAS_DEVICE_INFO_STP_TARGET | 4592 MPI_SAS_DEVICE_INFO_STP_TARGET |
4593 MPI_SAS_DEVICE_INFO_SATA_DEVICE)) == 0) { 4593 MPI_SAS_DEVICE_INFO_SATA_DEVICE)) == 0) {
4594 mptsas_free_fw_event(ioc, fw_event); 4594 mptsas_free_fw_event(ioc, fw_event);
4595 return; 4595 return;
4596 } 4596 }
4597 4597
4598 if (sas_event_data->ReasonCode == 4598 if (sas_event_data->ReasonCode ==
4599 MPI_EVENT_SAS_DEV_STAT_RC_NO_PERSIST_ADDED) { 4599 MPI_EVENT_SAS_DEV_STAT_RC_NO_PERSIST_ADDED) {
4600 mptbase_sas_persist_operation(ioc, 4600 mptbase_sas_persist_operation(ioc,
4601 MPI_SAS_OP_CLEAR_NOT_PRESENT); 4601 MPI_SAS_OP_CLEAR_NOT_PRESENT);
4602 mptsas_free_fw_event(ioc, fw_event); 4602 mptsas_free_fw_event(ioc, fw_event);
4603 return; 4603 return;
4604 } 4604 }
4605 4605
4606 switch (sas_event_data->ReasonCode) { 4606 switch (sas_event_data->ReasonCode) {
4607 case MPI_EVENT_SAS_DEV_STAT_RC_NOT_RESPONDING: 4607 case MPI_EVENT_SAS_DEV_STAT_RC_NOT_RESPONDING:
4608 case MPI_EVENT_SAS_DEV_STAT_RC_ADDED: 4608 case MPI_EVENT_SAS_DEV_STAT_RC_ADDED:
4609 memset(&hot_plug_info, 0, sizeof(struct mptsas_hotplug_event)); 4609 memset(&hot_plug_info, 0, sizeof(struct mptsas_hotplug_event));
4610 hot_plug_info.handle = le16_to_cpu(sas_event_data->DevHandle); 4610 hot_plug_info.handle = le16_to_cpu(sas_event_data->DevHandle);
4611 hot_plug_info.channel = sas_event_data->Bus; 4611 hot_plug_info.channel = sas_event_data->Bus;
4612 hot_plug_info.id = sas_event_data->TargetID; 4612 hot_plug_info.id = sas_event_data->TargetID;
4613 hot_plug_info.phy_id = sas_event_data->PhyNum; 4613 hot_plug_info.phy_id = sas_event_data->PhyNum;
4614 memcpy(&sas_address, &sas_event_data->SASAddress, 4614 memcpy(&sas_address, &sas_event_data->SASAddress,
4615 sizeof(u64)); 4615 sizeof(u64));
4616 hot_plug_info.sas_address = le64_to_cpu(sas_address); 4616 hot_plug_info.sas_address = le64_to_cpu(sas_address);
4617 hot_plug_info.device_info = device_info; 4617 hot_plug_info.device_info = device_info;
4618 if (sas_event_data->ReasonCode & 4618 if (sas_event_data->ReasonCode &
4619 MPI_EVENT_SAS_DEV_STAT_RC_ADDED) 4619 MPI_EVENT_SAS_DEV_STAT_RC_ADDED)
4620 hot_plug_info.event_type = MPTSAS_ADD_DEVICE; 4620 hot_plug_info.event_type = MPTSAS_ADD_DEVICE;
4621 else 4621 else
4622 hot_plug_info.event_type = MPTSAS_DEL_DEVICE; 4622 hot_plug_info.event_type = MPTSAS_DEL_DEVICE;
4623 mptsas_hotplug_work(ioc, fw_event, &hot_plug_info); 4623 mptsas_hotplug_work(ioc, fw_event, &hot_plug_info);
4624 break; 4624 break;
4625 4625
4626 case MPI_EVENT_SAS_DEV_STAT_RC_NO_PERSIST_ADDED: 4626 case MPI_EVENT_SAS_DEV_STAT_RC_NO_PERSIST_ADDED:
4627 mptbase_sas_persist_operation(ioc, 4627 mptbase_sas_persist_operation(ioc,
4628 MPI_SAS_OP_CLEAR_NOT_PRESENT); 4628 MPI_SAS_OP_CLEAR_NOT_PRESENT);
4629 mptsas_free_fw_event(ioc, fw_event); 4629 mptsas_free_fw_event(ioc, fw_event);
4630 break; 4630 break;
4631 4631
4632 case MPI_EVENT_SAS_DEV_STAT_RC_SMART_DATA: 4632 case MPI_EVENT_SAS_DEV_STAT_RC_SMART_DATA:
4633 /* TODO */ 4633 /* TODO */
4634 case MPI_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET: 4634 case MPI_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET:
4635 /* TODO */ 4635 /* TODO */
4636 default: 4636 default:
4637 mptsas_free_fw_event(ioc, fw_event); 4637 mptsas_free_fw_event(ioc, fw_event);
4638 break; 4638 break;
4639 } 4639 }
4640 } 4640 }
4641 4641
4642 static void 4642 static void
4643 mptsas_send_raid_event(struct fw_event_work *fw_event) 4643 mptsas_send_raid_event(struct fw_event_work *fw_event)
4644 { 4644 {
4645 MPT_ADAPTER *ioc; 4645 MPT_ADAPTER *ioc;
4646 EVENT_DATA_RAID *raid_event_data; 4646 EVENT_DATA_RAID *raid_event_data;
4647 struct mptsas_hotplug_event hot_plug_info; 4647 struct mptsas_hotplug_event hot_plug_info;
4648 int status; 4648 int status;
4649 int state; 4649 int state;
4650 struct scsi_device *sdev = NULL; 4650 struct scsi_device *sdev = NULL;
4651 VirtDevice *vdevice = NULL; 4651 VirtDevice *vdevice = NULL;
4652 RaidPhysDiskPage0_t phys_disk; 4652 RaidPhysDiskPage0_t phys_disk;
4653 4653
4654 ioc = fw_event->ioc; 4654 ioc = fw_event->ioc;
4655 raid_event_data = (EVENT_DATA_RAID *)fw_event->event_data; 4655 raid_event_data = (EVENT_DATA_RAID *)fw_event->event_data;
4656 status = le32_to_cpu(raid_event_data->SettingsStatus); 4656 status = le32_to_cpu(raid_event_data->SettingsStatus);
4657 state = (status >> 8) & 0xff; 4657 state = (status >> 8) & 0xff;
4658 4658
4659 memset(&hot_plug_info, 0, sizeof(struct mptsas_hotplug_event)); 4659 memset(&hot_plug_info, 0, sizeof(struct mptsas_hotplug_event));
4660 hot_plug_info.id = raid_event_data->VolumeID; 4660 hot_plug_info.id = raid_event_data->VolumeID;
4661 hot_plug_info.channel = raid_event_data->VolumeBus; 4661 hot_plug_info.channel = raid_event_data->VolumeBus;
4662 hot_plug_info.phys_disk_num = raid_event_data->PhysDiskNum; 4662 hot_plug_info.phys_disk_num = raid_event_data->PhysDiskNum;
4663 4663
4664 if (raid_event_data->ReasonCode == MPI_EVENT_RAID_RC_VOLUME_DELETED || 4664 if (raid_event_data->ReasonCode == MPI_EVENT_RAID_RC_VOLUME_DELETED ||
4665 raid_event_data->ReasonCode == MPI_EVENT_RAID_RC_VOLUME_CREATED || 4665 raid_event_data->ReasonCode == MPI_EVENT_RAID_RC_VOLUME_CREATED ||
4666 raid_event_data->ReasonCode == 4666 raid_event_data->ReasonCode ==
4667 MPI_EVENT_RAID_RC_VOLUME_STATUS_CHANGED) { 4667 MPI_EVENT_RAID_RC_VOLUME_STATUS_CHANGED) {
4668 sdev = scsi_device_lookup(ioc->sh, MPTSAS_RAID_CHANNEL, 4668 sdev = scsi_device_lookup(ioc->sh, MPTSAS_RAID_CHANNEL,
4669 hot_plug_info.id, 0); 4669 hot_plug_info.id, 0);
4670 hot_plug_info.sdev = sdev; 4670 hot_plug_info.sdev = sdev;
4671 if (sdev) 4671 if (sdev)
4672 vdevice = sdev->hostdata; 4672 vdevice = sdev->hostdata;
4673 } 4673 }
4674 4674
4675 devtprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Entering %s: " 4675 devtprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Entering %s: "
4676 "ReasonCode=%02x\n", ioc->name, __func__, 4676 "ReasonCode=%02x\n", ioc->name, __func__,
4677 raid_event_data->ReasonCode)); 4677 raid_event_data->ReasonCode));
4678 4678
4679 switch (raid_event_data->ReasonCode) { 4679 switch (raid_event_data->ReasonCode) {
4680 case MPI_EVENT_RAID_RC_PHYSDISK_DELETED: 4680 case MPI_EVENT_RAID_RC_PHYSDISK_DELETED:
4681 hot_plug_info.event_type = MPTSAS_DEL_PHYSDISK_REPROBE; 4681 hot_plug_info.event_type = MPTSAS_DEL_PHYSDISK_REPROBE;
4682 break; 4682 break;
4683 case MPI_EVENT_RAID_RC_PHYSDISK_CREATED: 4683 case MPI_EVENT_RAID_RC_PHYSDISK_CREATED:
4684 hot_plug_info.event_type = MPTSAS_ADD_PHYSDISK_REPROBE; 4684 hot_plug_info.event_type = MPTSAS_ADD_PHYSDISK_REPROBE;
4685 break; 4685 break;
4686 case MPI_EVENT_RAID_RC_PHYSDISK_STATUS_CHANGED: 4686 case MPI_EVENT_RAID_RC_PHYSDISK_STATUS_CHANGED:
4687 switch (state) { 4687 switch (state) {
4688 case MPI_PD_STATE_ONLINE: 4688 case MPI_PD_STATE_ONLINE:
4689 case MPI_PD_STATE_NOT_COMPATIBLE: 4689 case MPI_PD_STATE_NOT_COMPATIBLE:
4690 mpt_raid_phys_disk_pg0(ioc, 4690 mpt_raid_phys_disk_pg0(ioc,
4691 raid_event_data->PhysDiskNum, &phys_disk); 4691 raid_event_data->PhysDiskNum, &phys_disk);
4692 hot_plug_info.id = phys_disk.PhysDiskID; 4692 hot_plug_info.id = phys_disk.PhysDiskID;
4693 hot_plug_info.channel = phys_disk.PhysDiskBus; 4693 hot_plug_info.channel = phys_disk.PhysDiskBus;
4694 hot_plug_info.event_type = MPTSAS_ADD_PHYSDISK; 4694 hot_plug_info.event_type = MPTSAS_ADD_PHYSDISK;
4695 break; 4695 break;
4696 case MPI_PD_STATE_FAILED: 4696 case MPI_PD_STATE_FAILED:
4697 case MPI_PD_STATE_MISSING: 4697 case MPI_PD_STATE_MISSING:
4698 case MPI_PD_STATE_OFFLINE_AT_HOST_REQUEST: 4698 case MPI_PD_STATE_OFFLINE_AT_HOST_REQUEST:
4699 case MPI_PD_STATE_FAILED_AT_HOST_REQUEST: 4699 case MPI_PD_STATE_FAILED_AT_HOST_REQUEST:
4700 case MPI_PD_STATE_OFFLINE_FOR_ANOTHER_REASON: 4700 case MPI_PD_STATE_OFFLINE_FOR_ANOTHER_REASON:
4701 hot_plug_info.event_type = MPTSAS_DEL_PHYSDISK; 4701 hot_plug_info.event_type = MPTSAS_DEL_PHYSDISK;
4702 break; 4702 break;
4703 default: 4703 default:
4704 break; 4704 break;
4705 } 4705 }
4706 break; 4706 break;
4707 case MPI_EVENT_RAID_RC_VOLUME_DELETED: 4707 case MPI_EVENT_RAID_RC_VOLUME_DELETED:
4708 if (!sdev) 4708 if (!sdev)
4709 break; 4709 break;
4710 vdevice->vtarget->deleted = 1; /* block IO */ 4710 vdevice->vtarget->deleted = 1; /* block IO */
4711 hot_plug_info.event_type = MPTSAS_DEL_RAID; 4711 hot_plug_info.event_type = MPTSAS_DEL_RAID;
4712 break; 4712 break;
4713 case MPI_EVENT_RAID_RC_VOLUME_CREATED: 4713 case MPI_EVENT_RAID_RC_VOLUME_CREATED:
4714 if (sdev) { 4714 if (sdev) {
4715 scsi_device_put(sdev); 4715 scsi_device_put(sdev);
4716 break; 4716 break;
4717 } 4717 }
4718 hot_plug_info.event_type = MPTSAS_ADD_RAID; 4718 hot_plug_info.event_type = MPTSAS_ADD_RAID;
4719 break; 4719 break;
4720 case MPI_EVENT_RAID_RC_VOLUME_STATUS_CHANGED: 4720 case MPI_EVENT_RAID_RC_VOLUME_STATUS_CHANGED:
4721 if (!(status & MPI_RAIDVOL0_STATUS_FLAG_ENABLED)) { 4721 if (!(status & MPI_RAIDVOL0_STATUS_FLAG_ENABLED)) {
4722 if (!sdev) 4722 if (!sdev)
4723 break; 4723 break;
4724 vdevice->vtarget->deleted = 1; /* block IO */ 4724 vdevice->vtarget->deleted = 1; /* block IO */
4725 hot_plug_info.event_type = MPTSAS_DEL_RAID; 4725 hot_plug_info.event_type = MPTSAS_DEL_RAID;
4726 break; 4726 break;
4727 } 4727 }
4728 switch (state) { 4728 switch (state) {
4729 case MPI_RAIDVOL0_STATUS_STATE_FAILED: 4729 case MPI_RAIDVOL0_STATUS_STATE_FAILED:
4730 case MPI_RAIDVOL0_STATUS_STATE_MISSING: 4730 case MPI_RAIDVOL0_STATUS_STATE_MISSING:
4731 if (!sdev) 4731 if (!sdev)
4732 break; 4732 break;
4733 vdevice->vtarget->deleted = 1; /* block IO */ 4733 vdevice->vtarget->deleted = 1; /* block IO */
4734 hot_plug_info.event_type = MPTSAS_DEL_RAID; 4734 hot_plug_info.event_type = MPTSAS_DEL_RAID;
4735 break; 4735 break;
4736 case MPI_RAIDVOL0_STATUS_STATE_OPTIMAL: 4736 case MPI_RAIDVOL0_STATUS_STATE_OPTIMAL:
4737 case MPI_RAIDVOL0_STATUS_STATE_DEGRADED: 4737 case MPI_RAIDVOL0_STATUS_STATE_DEGRADED:
4738 if (sdev) { 4738 if (sdev) {
4739 scsi_device_put(sdev); 4739 scsi_device_put(sdev);
4740 break; 4740 break;
4741 } 4741 }
4742 hot_plug_info.event_type = MPTSAS_ADD_RAID; 4742 hot_plug_info.event_type = MPTSAS_ADD_RAID;
4743 break; 4743 break;
4744 default: 4744 default:
4745 break; 4745 break;
4746 } 4746 }
4747 break; 4747 break;
4748 default: 4748 default:
4749 break; 4749 break;
4750 } 4750 }
4751 4751
4752 if (hot_plug_info.event_type != MPTSAS_IGNORE_EVENT) 4752 if (hot_plug_info.event_type != MPTSAS_IGNORE_EVENT)
4753 mptsas_hotplug_work(ioc, fw_event, &hot_plug_info); 4753 mptsas_hotplug_work(ioc, fw_event, &hot_plug_info);
4754 else 4754 else
4755 mptsas_free_fw_event(ioc, fw_event); 4755 mptsas_free_fw_event(ioc, fw_event);
4756 } 4756 }
4757 4757
4758 /** 4758 /**
4759 * mptsas_issue_tm - send mptsas internal tm request 4759 * mptsas_issue_tm - send mptsas internal tm request
4760 * @ioc: Pointer to MPT_ADAPTER structure 4760 * @ioc: Pointer to MPT_ADAPTER structure
4761 * @type: Task Management type 4761 * @type: Task Management type
4762 * @channel: channel number for task management 4762 * @channel: channel number for task management
4763 * @id: Logical Target ID for reset (if appropriate) 4763 * @id: Logical Target ID for reset (if appropriate)
4764 * @lun: Logical unit for reset (if appropriate) 4764 * @lun: Logical unit for reset (if appropriate)
4765 * @task_context: Context for the task to be aborted 4765 * @task_context: Context for the task to be aborted
4766 * @timeout: timeout for task management control 4766 * @timeout: timeout for task management control
4767 * 4767 *
4768 * return 0 on success and -1 on failure: 4768 * return 0 on success and -1 on failure:
4769 * 4769 *
4770 */ 4770 */
4771 static int 4771 static int
4772 mptsas_issue_tm(MPT_ADAPTER *ioc, u8 type, u8 channel, u8 id, u64 lun, 4772 mptsas_issue_tm(MPT_ADAPTER *ioc, u8 type, u8 channel, u8 id, u64 lun,
4773 int task_context, ulong timeout, u8 *issue_reset) 4773 int task_context, ulong timeout, u8 *issue_reset)
4774 { 4774 {
4775 MPT_FRAME_HDR *mf; 4775 MPT_FRAME_HDR *mf;
4776 SCSITaskMgmt_t *pScsiTm; 4776 SCSITaskMgmt_t *pScsiTm;
4777 int retval; 4777 int retval;
4778 unsigned long timeleft; 4778 unsigned long timeleft;
4779 4779
4780 *issue_reset = 0; 4780 *issue_reset = 0;
4781 mf = mpt_get_msg_frame(mptsasDeviceResetCtx, ioc); 4781 mf = mpt_get_msg_frame(mptsasDeviceResetCtx, ioc);
4782 if (mf == NULL) { 4782 if (mf == NULL) {
4783 retval = -1; /* return failure */ 4783 retval = -1; /* return failure */
4784 dtmprintk(ioc, printk(MYIOC_s_WARN_FMT "TaskMgmt request: no " 4784 dtmprintk(ioc, printk(MYIOC_s_WARN_FMT "TaskMgmt request: no "
4785 "msg frames!!\n", ioc->name)); 4785 "msg frames!!\n", ioc->name));
4786 goto out; 4786 goto out;
4787 } 4787 }
4788 4788
4789 dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT "TaskMgmt request: mr = %p, " 4789 dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT "TaskMgmt request: mr = %p, "
4790 "task_type = 0x%02X,\n\t timeout = %ld, fw_channel = %d, " 4790 "task_type = 0x%02X,\n\t timeout = %ld, fw_channel = %d, "
4791 "fw_id = %d, lun = %lld,\n\t task_context = 0x%x\n", ioc->name, mf, 4791 "fw_id = %d, lun = %lld,\n\t task_context = 0x%x\n", ioc->name, mf,
4792 type, timeout, channel, id, (unsigned long long)lun, 4792 type, timeout, channel, id, (unsigned long long)lun,
4793 task_context)); 4793 task_context));
4794 4794
4795 pScsiTm = (SCSITaskMgmt_t *) mf; 4795 pScsiTm = (SCSITaskMgmt_t *) mf;
4796 memset(pScsiTm, 0, sizeof(SCSITaskMgmt_t)); 4796 memset(pScsiTm, 0, sizeof(SCSITaskMgmt_t));
4797 pScsiTm->Function = MPI_FUNCTION_SCSI_TASK_MGMT; 4797 pScsiTm->Function = MPI_FUNCTION_SCSI_TASK_MGMT;
4798 pScsiTm->TaskType = type; 4798 pScsiTm->TaskType = type;
4799 pScsiTm->MsgFlags = 0; 4799 pScsiTm->MsgFlags = 0;
4800 pScsiTm->TargetID = id; 4800 pScsiTm->TargetID = id;
4801 pScsiTm->Bus = channel; 4801 pScsiTm->Bus = channel;
4802 pScsiTm->ChainOffset = 0; 4802 pScsiTm->ChainOffset = 0;
4803 pScsiTm->Reserved = 0; 4803 pScsiTm->Reserved = 0;
4804 pScsiTm->Reserved1 = 0; 4804 pScsiTm->Reserved1 = 0;
4805 pScsiTm->TaskMsgContext = task_context; 4805 pScsiTm->TaskMsgContext = task_context;
4806 int_to_scsilun(lun, (struct scsi_lun *)pScsiTm->LUN); 4806 int_to_scsilun(lun, (struct scsi_lun *)pScsiTm->LUN);
4807 4807
4808 INITIALIZE_MGMT_STATUS(ioc->taskmgmt_cmds.status) 4808 INITIALIZE_MGMT_STATUS(ioc->taskmgmt_cmds.status)
4809 CLEAR_MGMT_STATUS(ioc->internal_cmds.status) 4809 CLEAR_MGMT_STATUS(ioc->internal_cmds.status)
4810 retval = 0; 4810 retval = 0;
4811 mpt_put_msg_frame_hi_pri(mptsasDeviceResetCtx, ioc, mf); 4811 mpt_put_msg_frame_hi_pri(mptsasDeviceResetCtx, ioc, mf);
4812 4812
4813 /* Now wait for the command to complete */ 4813 /* Now wait for the command to complete */
4814 timeleft = wait_for_completion_timeout(&ioc->taskmgmt_cmds.done, 4814 timeleft = wait_for_completion_timeout(&ioc->taskmgmt_cmds.done,
4815 timeout*HZ); 4815 timeout*HZ);
4816 if (!(ioc->taskmgmt_cmds.status & MPT_MGMT_STATUS_COMMAND_GOOD)) { 4816 if (!(ioc->taskmgmt_cmds.status & MPT_MGMT_STATUS_COMMAND_GOOD)) {
4817 retval = -1; /* return failure */ 4817 retval = -1; /* return failure */
4818 dtmprintk(ioc, printk(MYIOC_s_ERR_FMT 4818 dtmprintk(ioc, printk(MYIOC_s_ERR_FMT
4819 "TaskMgmt request: TIMED OUT!(mr=%p)\n", ioc->name, mf)); 4819 "TaskMgmt request: TIMED OUT!(mr=%p)\n", ioc->name, mf));
4820 mpt_free_msg_frame(ioc, mf); 4820 mpt_free_msg_frame(ioc, mf);
4821 if (ioc->taskmgmt_cmds.status & MPT_MGMT_STATUS_DID_IOCRESET) 4821 if (ioc->taskmgmt_cmds.status & MPT_MGMT_STATUS_DID_IOCRESET)
4822 goto out; 4822 goto out;
4823 *issue_reset = 1; 4823 *issue_reset = 1;
4824 goto out; 4824 goto out;
4825 } 4825 }
4826 4826
4827 if (!(ioc->taskmgmt_cmds.status & MPT_MGMT_STATUS_RF_VALID)) { 4827 if (!(ioc->taskmgmt_cmds.status & MPT_MGMT_STATUS_RF_VALID)) {
4828 retval = -1; /* return failure */ 4828 retval = -1; /* return failure */
4829 dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT 4829 dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT
4830 "TaskMgmt request: failed with no reply\n", ioc->name)); 4830 "TaskMgmt request: failed with no reply\n", ioc->name));
4831 goto out; 4831 goto out;
4832 } 4832 }
4833 4833
4834 out: 4834 out:
4835 CLEAR_MGMT_STATUS(ioc->taskmgmt_cmds.status) 4835 CLEAR_MGMT_STATUS(ioc->taskmgmt_cmds.status)
4836 return retval; 4836 return retval;
4837 } 4837 }
4838 4838
4839 /** 4839 /**
4840 * mptsas_broadcast_primative_work - Handle broadcast primitives 4840 * mptsas_broadcast_primative_work - Handle broadcast primitives
4841 * @work: work queue payload containing info describing the event 4841 * @work: work queue payload containing info describing the event
4842 * 4842 *
4843 * this will be handled in workqueue context. 4843 * this will be handled in workqueue context.
4844 */ 4844 */
4845 static void 4845 static void
4846 mptsas_broadcast_primative_work(struct fw_event_work *fw_event) 4846 mptsas_broadcast_primative_work(struct fw_event_work *fw_event)
4847 { 4847 {
4848 MPT_ADAPTER *ioc = fw_event->ioc; 4848 MPT_ADAPTER *ioc = fw_event->ioc;
4849 MPT_FRAME_HDR *mf; 4849 MPT_FRAME_HDR *mf;
4850 VirtDevice *vdevice; 4850 VirtDevice *vdevice;
4851 int ii; 4851 int ii;
4852 struct scsi_cmnd *sc; 4852 struct scsi_cmnd *sc;
4853 SCSITaskMgmtReply_t *pScsiTmReply; 4853 SCSITaskMgmtReply_t *pScsiTmReply;
4854 u8 issue_reset; 4854 u8 issue_reset;
4855 int task_context; 4855 int task_context;
4856 u8 channel, id; 4856 u8 channel, id;
4857 int lun; 4857 int lun;
4858 u32 termination_count; 4858 u32 termination_count;
4859 u32 query_count; 4859 u32 query_count;
4860 4860
4861 dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT 4861 dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT
4862 "%s - enter\n", ioc->name, __func__)); 4862 "%s - enter\n", ioc->name, __func__));
4863 4863
4864 mutex_lock(&ioc->taskmgmt_cmds.mutex); 4864 mutex_lock(&ioc->taskmgmt_cmds.mutex);
4865 if (mpt_set_taskmgmt_in_progress_flag(ioc) != 0) { 4865 if (mpt_set_taskmgmt_in_progress_flag(ioc) != 0) {
4866 mutex_unlock(&ioc->taskmgmt_cmds.mutex); 4866 mutex_unlock(&ioc->taskmgmt_cmds.mutex);
4867 mptsas_requeue_fw_event(ioc, fw_event, 1000); 4867 mptsas_requeue_fw_event(ioc, fw_event, 1000);
4868 return; 4868 return;
4869 } 4869 }
4870 4870
4871 issue_reset = 0; 4871 issue_reset = 0;
4872 termination_count = 0; 4872 termination_count = 0;
4873 query_count = 0; 4873 query_count = 0;
4874 mpt_findImVolumes(ioc); 4874 mpt_findImVolumes(ioc);
4875 pScsiTmReply = (SCSITaskMgmtReply_t *) ioc->taskmgmt_cmds.reply; 4875 pScsiTmReply = (SCSITaskMgmtReply_t *) ioc->taskmgmt_cmds.reply;
4876 4876
4877 for (ii = 0; ii < ioc->req_depth; ii++) { 4877 for (ii = 0; ii < ioc->req_depth; ii++) {
4878 if (ioc->fw_events_off) 4878 if (ioc->fw_events_off)
4879 goto out; 4879 goto out;
4880 sc = mptscsih_get_scsi_lookup(ioc, ii); 4880 sc = mptscsih_get_scsi_lookup(ioc, ii);
4881 if (!sc) 4881 if (!sc)
4882 continue; 4882 continue;
4883 mf = MPT_INDEX_2_MFPTR(ioc, ii); 4883 mf = MPT_INDEX_2_MFPTR(ioc, ii);
4884 if (!mf) 4884 if (!mf)
4885 continue; 4885 continue;
4886 task_context = mf->u.frame.hwhdr.msgctxu.MsgContext; 4886 task_context = mf->u.frame.hwhdr.msgctxu.MsgContext;
4887 vdevice = sc->device->hostdata; 4887 vdevice = sc->device->hostdata;
4888 if (!vdevice || !vdevice->vtarget) 4888 if (!vdevice || !vdevice->vtarget)
4889 continue; 4889 continue;
4890 if (vdevice->vtarget->tflags & MPT_TARGET_FLAGS_RAID_COMPONENT) 4890 if (vdevice->vtarget->tflags & MPT_TARGET_FLAGS_RAID_COMPONENT)
4891 continue; /* skip hidden raid components */ 4891 continue; /* skip hidden raid components */
4892 if (vdevice->vtarget->raidVolume) 4892 if (vdevice->vtarget->raidVolume)
4893 continue; /* skip hidden raid components */ 4893 continue; /* skip hidden raid components */
4894 channel = vdevice->vtarget->channel; 4894 channel = vdevice->vtarget->channel;
4895 id = vdevice->vtarget->id; 4895 id = vdevice->vtarget->id;
4896 lun = vdevice->lun; 4896 lun = vdevice->lun;
4897 if (mptsas_issue_tm(ioc, MPI_SCSITASKMGMT_TASKTYPE_QUERY_TASK, 4897 if (mptsas_issue_tm(ioc, MPI_SCSITASKMGMT_TASKTYPE_QUERY_TASK,
4898 channel, id, (u64)lun, task_context, 30, &issue_reset)) 4898 channel, id, (u64)lun, task_context, 30, &issue_reset))
4899 goto out; 4899 goto out;
4900 query_count++; 4900 query_count++;
4901 termination_count += 4901 termination_count +=
4902 le32_to_cpu(pScsiTmReply->TerminationCount); 4902 le32_to_cpu(pScsiTmReply->TerminationCount);
4903 if ((pScsiTmReply->IOCStatus == MPI_IOCSTATUS_SUCCESS) && 4903 if ((pScsiTmReply->IOCStatus == MPI_IOCSTATUS_SUCCESS) &&
4904 (pScsiTmReply->ResponseCode == 4904 (pScsiTmReply->ResponseCode ==
4905 MPI_SCSITASKMGMT_RSP_TM_SUCCEEDED || 4905 MPI_SCSITASKMGMT_RSP_TM_SUCCEEDED ||
4906 pScsiTmReply->ResponseCode == 4906 pScsiTmReply->ResponseCode ==
4907 MPI_SCSITASKMGMT_RSP_IO_QUEUED_ON_IOC)) 4907 MPI_SCSITASKMGMT_RSP_IO_QUEUED_ON_IOC))
4908 continue; 4908 continue;
4909 if (mptsas_issue_tm(ioc, 4909 if (mptsas_issue_tm(ioc,
4910 MPI_SCSITASKMGMT_TASKTYPE_ABRT_TASK_SET, 4910 MPI_SCSITASKMGMT_TASKTYPE_ABRT_TASK_SET,
4911 channel, id, (u64)lun, 0, 30, &issue_reset)) 4911 channel, id, (u64)lun, 0, 30, &issue_reset))
4912 goto out; 4912 goto out;
4913 termination_count += 4913 termination_count +=
4914 le32_to_cpu(pScsiTmReply->TerminationCount); 4914 le32_to_cpu(pScsiTmReply->TerminationCount);
4915 } 4915 }
4916 4916
4917 out: 4917 out:
4918 dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT 4918 dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT
4919 "%s - exit, query_count = %d termination_count = %d\n", 4919 "%s - exit, query_count = %d termination_count = %d\n",
4920 ioc->name, __func__, query_count, termination_count)); 4920 ioc->name, __func__, query_count, termination_count));
4921 4921
4922 ioc->broadcast_aen_busy = 0; 4922 ioc->broadcast_aen_busy = 0;
4923 mpt_clear_taskmgmt_in_progress_flag(ioc); 4923 mpt_clear_taskmgmt_in_progress_flag(ioc);
4924 mutex_unlock(&ioc->taskmgmt_cmds.mutex); 4924 mutex_unlock(&ioc->taskmgmt_cmds.mutex);
4925 4925
4926 if (issue_reset) { 4926 if (issue_reset) {
4927 printk(MYIOC_s_WARN_FMT 4927 printk(MYIOC_s_WARN_FMT
4928 "Issuing Reset from %s!! doorbell=0x%08x\n", 4928 "Issuing Reset from %s!! doorbell=0x%08x\n",
4929 ioc->name, __func__, mpt_GetIocState(ioc, 0)); 4929 ioc->name, __func__, mpt_GetIocState(ioc, 0));
4930 mpt_Soft_Hard_ResetHandler(ioc, CAN_SLEEP); 4930 mpt_Soft_Hard_ResetHandler(ioc, CAN_SLEEP);
4931 } 4931 }
4932 mptsas_free_fw_event(ioc, fw_event); 4932 mptsas_free_fw_event(ioc, fw_event);
4933 } 4933 }
4934 4934
4935 /* 4935 /*
4936 * mptsas_send_ir2_event - handle exposing hidden disk when 4936 * mptsas_send_ir2_event - handle exposing hidden disk when
4937 * an inactive raid volume is added 4937 * an inactive raid volume is added
4938 * 4938 *
4939 * @ioc: Pointer to MPT_ADAPTER structure 4939 * @ioc: Pointer to MPT_ADAPTER structure
4940 * @ir2_data 4940 * @ir2_data
4941 * 4941 *
4942 */ 4942 */
4943 static void 4943 static void
4944 mptsas_send_ir2_event(struct fw_event_work *fw_event) 4944 mptsas_send_ir2_event(struct fw_event_work *fw_event)
4945 { 4945 {
4946 MPT_ADAPTER *ioc; 4946 MPT_ADAPTER *ioc;
4947 struct mptsas_hotplug_event hot_plug_info; 4947 struct mptsas_hotplug_event hot_plug_info;
4948 MPI_EVENT_DATA_IR2 *ir2_data; 4948 MPI_EVENT_DATA_IR2 *ir2_data;
4949 u8 reasonCode; 4949 u8 reasonCode;
4950 RaidPhysDiskPage0_t phys_disk; 4950 RaidPhysDiskPage0_t phys_disk;
4951 4951
4952 ioc = fw_event->ioc; 4952 ioc = fw_event->ioc;
4953 ir2_data = (MPI_EVENT_DATA_IR2 *)fw_event->event_data; 4953 ir2_data = (MPI_EVENT_DATA_IR2 *)fw_event->event_data;
4954 reasonCode = ir2_data->ReasonCode; 4954 reasonCode = ir2_data->ReasonCode;
4955 4955
4956 devtprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Entering %s: " 4956 devtprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Entering %s: "
4957 "ReasonCode=%02x\n", ioc->name, __func__, reasonCode)); 4957 "ReasonCode=%02x\n", ioc->name, __func__, reasonCode));
4958 4958
4959 memset(&hot_plug_info, 0, sizeof(struct mptsas_hotplug_event)); 4959 memset(&hot_plug_info, 0, sizeof(struct mptsas_hotplug_event));
4960 hot_plug_info.id = ir2_data->TargetID; 4960 hot_plug_info.id = ir2_data->TargetID;
4961 hot_plug_info.channel = ir2_data->Bus; 4961 hot_plug_info.channel = ir2_data->Bus;
4962 switch (reasonCode) { 4962 switch (reasonCode) {
4963 case MPI_EVENT_IR2_RC_FOREIGN_CFG_DETECTED: 4963 case MPI_EVENT_IR2_RC_FOREIGN_CFG_DETECTED:
4964 hot_plug_info.event_type = MPTSAS_ADD_INACTIVE_VOLUME; 4964 hot_plug_info.event_type = MPTSAS_ADD_INACTIVE_VOLUME;
4965 break; 4965 break;
4966 case MPI_EVENT_IR2_RC_DUAL_PORT_REMOVED: 4966 case MPI_EVENT_IR2_RC_DUAL_PORT_REMOVED:
4967 hot_plug_info.phys_disk_num = ir2_data->PhysDiskNum; 4967 hot_plug_info.phys_disk_num = ir2_data->PhysDiskNum;
4968 hot_plug_info.event_type = MPTSAS_DEL_PHYSDISK; 4968 hot_plug_info.event_type = MPTSAS_DEL_PHYSDISK;
4969 break; 4969 break;
4970 case MPI_EVENT_IR2_RC_DUAL_PORT_ADDED: 4970 case MPI_EVENT_IR2_RC_DUAL_PORT_ADDED:
4971 hot_plug_info.phys_disk_num = ir2_data->PhysDiskNum; 4971 hot_plug_info.phys_disk_num = ir2_data->PhysDiskNum;
4972 mpt_raid_phys_disk_pg0(ioc, 4972 mpt_raid_phys_disk_pg0(ioc,
4973 ir2_data->PhysDiskNum, &phys_disk); 4973 ir2_data->PhysDiskNum, &phys_disk);
4974 hot_plug_info.id = phys_disk.PhysDiskID; 4974 hot_plug_info.id = phys_disk.PhysDiskID;
4975 hot_plug_info.event_type = MPTSAS_ADD_PHYSDISK; 4975 hot_plug_info.event_type = MPTSAS_ADD_PHYSDISK;
4976 break; 4976 break;
4977 default: 4977 default:
4978 mptsas_free_fw_event(ioc, fw_event); 4978 mptsas_free_fw_event(ioc, fw_event);
4979 return; 4979 return;
4980 } 4980 }
4981 mptsas_hotplug_work(ioc, fw_event, &hot_plug_info); 4981 mptsas_hotplug_work(ioc, fw_event, &hot_plug_info);
4982 } 4982 }
4983 4983
4984 static int 4984 static int
4985 mptsas_event_process(MPT_ADAPTER *ioc, EventNotificationReply_t *reply) 4985 mptsas_event_process(MPT_ADAPTER *ioc, EventNotificationReply_t *reply)
4986 { 4986 {
4987 u32 event = le32_to_cpu(reply->Event); 4987 u32 event = le32_to_cpu(reply->Event);
4988 int sz, event_data_sz; 4988 int sz, event_data_sz;
4989 struct fw_event_work *fw_event; 4989 struct fw_event_work *fw_event;
4990 unsigned long delay; 4990 unsigned long delay;
4991 4991
4992 if (ioc->bus_type != SAS) 4992 if (ioc->bus_type != SAS)
4993 return 0; 4993 return 0;
4994 4994
4995 /* events turned off due to host reset or driver unloading */ 4995 /* events turned off due to host reset or driver unloading */
4996 if (ioc->fw_events_off) 4996 if (ioc->fw_events_off)
4997 return 0; 4997 return 0;
4998 4998
4999 delay = msecs_to_jiffies(1); 4999 delay = msecs_to_jiffies(1);
5000 switch (event) { 5000 switch (event) {
5001 case MPI_EVENT_SAS_BROADCAST_PRIMITIVE: 5001 case MPI_EVENT_SAS_BROADCAST_PRIMITIVE:
5002 { 5002 {
5003 EVENT_DATA_SAS_BROADCAST_PRIMITIVE *broadcast_event_data = 5003 EVENT_DATA_SAS_BROADCAST_PRIMITIVE *broadcast_event_data =
5004 (EVENT_DATA_SAS_BROADCAST_PRIMITIVE *)reply->Data; 5004 (EVENT_DATA_SAS_BROADCAST_PRIMITIVE *)reply->Data;
5005 if (broadcast_event_data->Primitive != 5005 if (broadcast_event_data->Primitive !=
5006 MPI_EVENT_PRIMITIVE_ASYNCHRONOUS_EVENT) 5006 MPI_EVENT_PRIMITIVE_ASYNCHRONOUS_EVENT)
5007 return 0; 5007 return 0;
5008 if (ioc->broadcast_aen_busy) 5008 if (ioc->broadcast_aen_busy)
5009 return 0; 5009 return 0;
5010 ioc->broadcast_aen_busy = 1; 5010 ioc->broadcast_aen_busy = 1;
5011 break; 5011 break;
5012 } 5012 }
5013 case MPI_EVENT_SAS_DEVICE_STATUS_CHANGE: 5013 case MPI_EVENT_SAS_DEVICE_STATUS_CHANGE:
5014 { 5014 {
5015 EVENT_DATA_SAS_DEVICE_STATUS_CHANGE *sas_event_data = 5015 EVENT_DATA_SAS_DEVICE_STATUS_CHANGE *sas_event_data =
5016 (EVENT_DATA_SAS_DEVICE_STATUS_CHANGE *)reply->Data; 5016 (EVENT_DATA_SAS_DEVICE_STATUS_CHANGE *)reply->Data;
5017 u16 ioc_stat; 5017 u16 ioc_stat;
5018 ioc_stat = le16_to_cpu(reply->IOCStatus); 5018 ioc_stat = le16_to_cpu(reply->IOCStatus);
5019 5019
5020 if (sas_event_data->ReasonCode == 5020 if (sas_event_data->ReasonCode ==
5021 MPI_EVENT_SAS_DEV_STAT_RC_NOT_RESPONDING) { 5021 MPI_EVENT_SAS_DEV_STAT_RC_NOT_RESPONDING) {
5022 mptsas_target_reset_queue(ioc, sas_event_data); 5022 mptsas_target_reset_queue(ioc, sas_event_data);
5023 return 0; 5023 return 0;
5024 } 5024 }
5025 if (sas_event_data->ReasonCode == 5025 if (sas_event_data->ReasonCode ==
5026 MPI_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET && 5026 MPI_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET &&
5027 ioc->device_missing_delay && 5027 ioc->device_missing_delay &&
5028 (ioc_stat & MPI_IOCSTATUS_FLAG_LOG_INFO_AVAILABLE)) { 5028 (ioc_stat & MPI_IOCSTATUS_FLAG_LOG_INFO_AVAILABLE)) {
5029 VirtTarget *vtarget = NULL; 5029 VirtTarget *vtarget = NULL;
5030 u8 id, channel; 5030 u8 id, channel;
5031 5031
5032 id = sas_event_data->TargetID; 5032 id = sas_event_data->TargetID;
5033 channel = sas_event_data->Bus; 5033 channel = sas_event_data->Bus;
5034 5034
5035 vtarget = mptsas_find_vtarget(ioc, channel, id); 5035 vtarget = mptsas_find_vtarget(ioc, channel, id);
5036 if (vtarget) { 5036 if (vtarget) {
5037 devtprintk(ioc, printk(MYIOC_s_DEBUG_FMT 5037 devtprintk(ioc, printk(MYIOC_s_DEBUG_FMT
5038 "LogInfo (0x%x) available for " 5038 "LogInfo (0x%x) available for "
5039 "INTERNAL_DEVICE_RESET" 5039 "INTERNAL_DEVICE_RESET"
5040 "fw_id %d fw_channel %d\n", ioc->name, 5040 "fw_id %d fw_channel %d\n", ioc->name,
5041 le32_to_cpu(reply->IOCLogInfo), 5041 le32_to_cpu(reply->IOCLogInfo),
5042 id, channel)); 5042 id, channel));
5043 if (vtarget->raidVolume) { 5043 if (vtarget->raidVolume) {
5044 devtprintk(ioc, printk(MYIOC_s_DEBUG_FMT 5044 devtprintk(ioc, printk(MYIOC_s_DEBUG_FMT
5045 "Skipping Raid Volume for inDMD\n", 5045 "Skipping Raid Volume for inDMD\n",
5046 ioc->name)); 5046 ioc->name));
5047 } else { 5047 } else {
5048 devtprintk(ioc, printk(MYIOC_s_DEBUG_FMT 5048 devtprintk(ioc, printk(MYIOC_s_DEBUG_FMT
5049 "Setting device flag inDMD\n", 5049 "Setting device flag inDMD\n",
5050 ioc->name)); 5050 ioc->name));
5051 vtarget->inDMD = 1; 5051 vtarget->inDMD = 1;
5052 } 5052 }
5053 5053
5054 } 5054 }
5055 5055
5056 } 5056 }
5057 5057
5058 break; 5058 break;
5059 } 5059 }
5060 case MPI_EVENT_SAS_EXPANDER_STATUS_CHANGE: 5060 case MPI_EVENT_SAS_EXPANDER_STATUS_CHANGE:
5061 { 5061 {
5062 MpiEventDataSasExpanderStatusChange_t *expander_data = 5062 MpiEventDataSasExpanderStatusChange_t *expander_data =
5063 (MpiEventDataSasExpanderStatusChange_t *)reply->Data; 5063 (MpiEventDataSasExpanderStatusChange_t *)reply->Data;
5064 5064
5065 if (ioc->old_sas_discovery_protocal) 5065 if (ioc->old_sas_discovery_protocal)
5066 return 0; 5066 return 0;
5067 5067
5068 if (expander_data->ReasonCode == 5068 if (expander_data->ReasonCode ==
5069 MPI_EVENT_SAS_EXP_RC_NOT_RESPONDING && 5069 MPI_EVENT_SAS_EXP_RC_NOT_RESPONDING &&
5070 ioc->device_missing_delay) 5070 ioc->device_missing_delay)
5071 delay = HZ * ioc->device_missing_delay; 5071 delay = HZ * ioc->device_missing_delay;
5072 break; 5072 break;
5073 } 5073 }
5074 case MPI_EVENT_SAS_DISCOVERY: 5074 case MPI_EVENT_SAS_DISCOVERY:
5075 { 5075 {
5076 u32 discovery_status; 5076 u32 discovery_status;
5077 EventDataSasDiscovery_t *discovery_data = 5077 EventDataSasDiscovery_t *discovery_data =
5078 (EventDataSasDiscovery_t *)reply->Data; 5078 (EventDataSasDiscovery_t *)reply->Data;
5079 5079
5080 discovery_status = le32_to_cpu(discovery_data->DiscoveryStatus); 5080 discovery_status = le32_to_cpu(discovery_data->DiscoveryStatus);
5081 ioc->sas_discovery_quiesce_io = discovery_status ? 1 : 0; 5081 ioc->sas_discovery_quiesce_io = discovery_status ? 1 : 0;
5082 if (ioc->old_sas_discovery_protocal && !discovery_status) 5082 if (ioc->old_sas_discovery_protocal && !discovery_status)
5083 mptsas_queue_rescan(ioc); 5083 mptsas_queue_rescan(ioc);
5084 return 0; 5084 return 0;
5085 } 5085 }
5086 case MPI_EVENT_INTEGRATED_RAID: 5086 case MPI_EVENT_INTEGRATED_RAID:
5087 case MPI_EVENT_PERSISTENT_TABLE_FULL: 5087 case MPI_EVENT_PERSISTENT_TABLE_FULL:
5088 case MPI_EVENT_IR2: 5088 case MPI_EVENT_IR2:
5089 case MPI_EVENT_SAS_PHY_LINK_STATUS: 5089 case MPI_EVENT_SAS_PHY_LINK_STATUS:
5090 case MPI_EVENT_QUEUE_FULL: 5090 case MPI_EVENT_QUEUE_FULL:
5091 break; 5091 break;
5092 default: 5092 default:
5093 return 0; 5093 return 0;
5094 } 5094 }
5095 5095
5096 event_data_sz = ((reply->MsgLength * 4) - 5096 event_data_sz = ((reply->MsgLength * 4) -
5097 offsetof(EventNotificationReply_t, Data)); 5097 offsetof(EventNotificationReply_t, Data));
5098 sz = offsetof(struct fw_event_work, event_data) + event_data_sz; 5098 sz = offsetof(struct fw_event_work, event_data) + event_data_sz;
5099 fw_event = kzalloc(sz, GFP_ATOMIC); 5099 fw_event = kzalloc(sz, GFP_ATOMIC);
5100 if (!fw_event) { 5100 if (!fw_event) {
5101 printk(MYIOC_s_WARN_FMT "%s: failed at (line=%d)\n", ioc->name, 5101 printk(MYIOC_s_WARN_FMT "%s: failed at (line=%d)\n", ioc->name,
5102 __func__, __LINE__); 5102 __func__, __LINE__);
5103 return 0; 5103 return 0;
5104 } 5104 }
5105 memcpy(fw_event->event_data, reply->Data, event_data_sz); 5105 memcpy(fw_event->event_data, reply->Data, event_data_sz);
5106 fw_event->event = event; 5106 fw_event->event = event;
5107 fw_event->ioc = ioc; 5107 fw_event->ioc = ioc;
5108 mptsas_add_fw_event(ioc, fw_event, delay); 5108 mptsas_add_fw_event(ioc, fw_event, delay);
5109 return 0; 5109 return 0;
5110 } 5110 }
5111 5111
5112 /* Delete a volume when no longer listed in ioc pg2 5112 /* Delete a volume when no longer listed in ioc pg2
5113 */ 5113 */
5114 static void mptsas_volume_delete(MPT_ADAPTER *ioc, u8 id) 5114 static void mptsas_volume_delete(MPT_ADAPTER *ioc, u8 id)
5115 { 5115 {
5116 struct scsi_device *sdev; 5116 struct scsi_device *sdev;
5117 int i; 5117 int i;
5118 5118
5119 sdev = scsi_device_lookup(ioc->sh, MPTSAS_RAID_CHANNEL, id, 0); 5119 sdev = scsi_device_lookup(ioc->sh, MPTSAS_RAID_CHANNEL, id, 0);
5120 if (!sdev) 5120 if (!sdev)
5121 return; 5121 return;
5122 if (!ioc->raid_data.pIocPg2) 5122 if (!ioc->raid_data.pIocPg2)
5123 goto out; 5123 goto out;
5124 if (!ioc->raid_data.pIocPg2->NumActiveVolumes) 5124 if (!ioc->raid_data.pIocPg2->NumActiveVolumes)
5125 goto out; 5125 goto out;
5126 for (i = 0; i < ioc->raid_data.pIocPg2->NumActiveVolumes; i++) 5126 for (i = 0; i < ioc->raid_data.pIocPg2->NumActiveVolumes; i++)
5127 if (ioc->raid_data.pIocPg2->RaidVolume[i].VolumeID == id) 5127 if (ioc->raid_data.pIocPg2->RaidVolume[i].VolumeID == id)
5128 goto release_sdev; 5128 goto release_sdev;
5129 out: 5129 out:
5130 printk(MYIOC_s_INFO_FMT "removing raid volume, channel %d, " 5130 printk(MYIOC_s_INFO_FMT "removing raid volume, channel %d, "
5131 "id %d\n", ioc->name, MPTSAS_RAID_CHANNEL, id); 5131 "id %d\n", ioc->name, MPTSAS_RAID_CHANNEL, id);
5132 scsi_remove_device(sdev); 5132 scsi_remove_device(sdev);
5133 release_sdev: 5133 release_sdev:
5134 scsi_device_put(sdev); 5134 scsi_device_put(sdev);
5135 } 5135 }
5136 5136
5137 static int 5137 static int
5138 mptsas_probe(struct pci_dev *pdev, const struct pci_device_id *id) 5138 mptsas_probe(struct pci_dev *pdev, const struct pci_device_id *id)
5139 { 5139 {
5140 struct Scsi_Host *sh; 5140 struct Scsi_Host *sh;
5141 MPT_SCSI_HOST *hd; 5141 MPT_SCSI_HOST *hd;
5142 MPT_ADAPTER *ioc; 5142 MPT_ADAPTER *ioc;
5143 unsigned long flags; 5143 unsigned long flags;
5144 int ii; 5144 int ii;
5145 int numSGE = 0; 5145 int numSGE = 0;
5146 int scale; 5146 int scale;
5147 int ioc_cap; 5147 int ioc_cap;
5148 int error=0; 5148 int error=0;
5149 int r; 5149 int r;
5150 5150
5151 r = mpt_attach(pdev,id); 5151 r = mpt_attach(pdev,id);
5152 if (r) 5152 if (r)
5153 return r; 5153 return r;
5154 5154
5155 ioc = pci_get_drvdata(pdev); 5155 ioc = pci_get_drvdata(pdev);
5156 mptsas_fw_event_off(ioc); 5156 mptsas_fw_event_off(ioc);
5157 ioc->DoneCtx = mptsasDoneCtx; 5157 ioc->DoneCtx = mptsasDoneCtx;
5158 ioc->TaskCtx = mptsasTaskCtx; 5158 ioc->TaskCtx = mptsasTaskCtx;
5159 ioc->InternalCtx = mptsasInternalCtx; 5159 ioc->InternalCtx = mptsasInternalCtx;
5160 ioc->schedule_target_reset = &mptsas_schedule_target_reset; 5160 ioc->schedule_target_reset = &mptsas_schedule_target_reset;
5161 ioc->schedule_dead_ioc_flush_running_cmds = 5161 ioc->schedule_dead_ioc_flush_running_cmds =
5162 &mptscsih_flush_running_cmds; 5162 &mptscsih_flush_running_cmds;
5163 /* Added sanity check on readiness of the MPT adapter. 5163 /* Added sanity check on readiness of the MPT adapter.
5164 */ 5164 */
5165 if (ioc->last_state != MPI_IOC_STATE_OPERATIONAL) { 5165 if (ioc->last_state != MPI_IOC_STATE_OPERATIONAL) {
5166 printk(MYIOC_s_WARN_FMT 5166 printk(MYIOC_s_WARN_FMT
5167 "Skipping because it's not operational!\n", 5167 "Skipping because it's not operational!\n",
5168 ioc->name); 5168 ioc->name);
5169 error = -ENODEV; 5169 error = -ENODEV;
5170 goto out_mptsas_probe; 5170 goto out_mptsas_probe;
5171 } 5171 }
5172 5172
5173 if (!ioc->active) { 5173 if (!ioc->active) {
5174 printk(MYIOC_s_WARN_FMT "Skipping because it's disabled!\n", 5174 printk(MYIOC_s_WARN_FMT "Skipping because it's disabled!\n",
5175 ioc->name); 5175 ioc->name);
5176 error = -ENODEV; 5176 error = -ENODEV;
5177 goto out_mptsas_probe; 5177 goto out_mptsas_probe;
5178 } 5178 }
5179 5179
5180 /* Sanity check - ensure at least 1 port is INITIATOR capable 5180 /* Sanity check - ensure at least 1 port is INITIATOR capable
5181 */ 5181 */
5182 ioc_cap = 0; 5182 ioc_cap = 0;
5183 for (ii = 0; ii < ioc->facts.NumberOfPorts; ii++) { 5183 for (ii = 0; ii < ioc->facts.NumberOfPorts; ii++) {
5184 if (ioc->pfacts[ii].ProtocolFlags & 5184 if (ioc->pfacts[ii].ProtocolFlags &
5185 MPI_PORTFACTS_PROTOCOL_INITIATOR) 5185 MPI_PORTFACTS_PROTOCOL_INITIATOR)
5186 ioc_cap++; 5186 ioc_cap++;
5187 } 5187 }
5188 5188
5189 if (!ioc_cap) { 5189 if (!ioc_cap) {
5190 printk(MYIOC_s_WARN_FMT 5190 printk(MYIOC_s_WARN_FMT
5191 "Skipping ioc=%p because SCSI Initiator mode " 5191 "Skipping ioc=%p because SCSI Initiator mode "
5192 "is NOT enabled!\n", ioc->name, ioc); 5192 "is NOT enabled!\n", ioc->name, ioc);
5193 return 0; 5193 return 0;
5194 } 5194 }
5195 5195
5196 sh = scsi_host_alloc(&mptsas_driver_template, sizeof(MPT_SCSI_HOST)); 5196 sh = scsi_host_alloc(&mptsas_driver_template, sizeof(MPT_SCSI_HOST));
5197 if (!sh) { 5197 if (!sh) {
5198 printk(MYIOC_s_WARN_FMT 5198 printk(MYIOC_s_WARN_FMT
5199 "Unable to register controller with SCSI subsystem\n", 5199 "Unable to register controller with SCSI subsystem\n",
5200 ioc->name); 5200 ioc->name);
5201 error = -1; 5201 error = -1;
5202 goto out_mptsas_probe; 5202 goto out_mptsas_probe;
5203 } 5203 }
5204 5204
5205 spin_lock_irqsave(&ioc->FreeQlock, flags); 5205 spin_lock_irqsave(&ioc->FreeQlock, flags);
5206 5206
5207 /* Attach the SCSI Host to the IOC structure 5207 /* Attach the SCSI Host to the IOC structure
5208 */ 5208 */
5209 ioc->sh = sh; 5209 ioc->sh = sh;
5210 5210
5211 sh->io_port = 0; 5211 sh->io_port = 0;
5212 sh->n_io_port = 0; 5212 sh->n_io_port = 0;
5213 sh->irq = 0; 5213 sh->irq = 0;
5214 5214
5215 /* set 16 byte cdb's */ 5215 /* set 16 byte cdb's */
5216 sh->max_cmd_len = 16; 5216 sh->max_cmd_len = 16;
5217 sh->can_queue = min_t(int, ioc->req_depth - 10, sh->can_queue); 5217 sh->can_queue = min_t(int, ioc->req_depth - 10, sh->can_queue);
5218 sh->max_id = -1; 5218 sh->max_id = -1;
5219 sh->max_lun = max_lun; 5219 sh->max_lun = max_lun;
5220 sh->transportt = mptsas_transport_template; 5220 sh->transportt = mptsas_transport_template;
5221 5221
5222 /* Required entry. 5222 /* Required entry.
5223 */ 5223 */
5224 sh->unique_id = ioc->id; 5224 sh->unique_id = ioc->id;
5225 5225
5226 INIT_LIST_HEAD(&ioc->sas_topology); 5226 INIT_LIST_HEAD(&ioc->sas_topology);
5227 mutex_init(&ioc->sas_topology_mutex); 5227 mutex_init(&ioc->sas_topology_mutex);
5228 mutex_init(&ioc->sas_discovery_mutex); 5228 mutex_init(&ioc->sas_discovery_mutex);
5229 mutex_init(&ioc->sas_mgmt.mutex); 5229 mutex_init(&ioc->sas_mgmt.mutex);
5230 init_completion(&ioc->sas_mgmt.done); 5230 init_completion(&ioc->sas_mgmt.done);
5231 5231
5232 /* Verify that we won't exceed the maximum 5232 /* Verify that we won't exceed the maximum
5233 * number of chain buffers 5233 * number of chain buffers
5234 * We can optimize: ZZ = req_sz/sizeof(SGE) 5234 * We can optimize: ZZ = req_sz/sizeof(SGE)
5235 * For 32bit SGE's: 5235 * For 32bit SGE's:
5236 * numSGE = 1 + (ZZ-1)*(maxChain -1) + ZZ 5236 * numSGE = 1 + (ZZ-1)*(maxChain -1) + ZZ
5237 * + (req_sz - 64)/sizeof(SGE) 5237 * + (req_sz - 64)/sizeof(SGE)
5238 * A slightly different algorithm is required for 5238 * A slightly different algorithm is required for
5239 * 64bit SGEs. 5239 * 64bit SGEs.
5240 */ 5240 */
5241 scale = ioc->req_sz/ioc->SGE_size; 5241 scale = ioc->req_sz/ioc->SGE_size;
5242 if (ioc->sg_addr_size == sizeof(u64)) { 5242 if (ioc->sg_addr_size == sizeof(u64)) {
5243 numSGE = (scale - 1) * 5243 numSGE = (scale - 1) *
5244 (ioc->facts.MaxChainDepth-1) + scale + 5244 (ioc->facts.MaxChainDepth-1) + scale +
5245 (ioc->req_sz - 60) / ioc->SGE_size; 5245 (ioc->req_sz - 60) / ioc->SGE_size;
5246 } else { 5246 } else {
5247 numSGE = 1 + (scale - 1) * 5247 numSGE = 1 + (scale - 1) *
5248 (ioc->facts.MaxChainDepth-1) + scale + 5248 (ioc->facts.MaxChainDepth-1) + scale +
5249 (ioc->req_sz - 64) / ioc->SGE_size; 5249 (ioc->req_sz - 64) / ioc->SGE_size;
5250 } 5250 }
5251 5251
5252 if (numSGE < sh->sg_tablesize) { 5252 if (numSGE < sh->sg_tablesize) {
5253 /* Reset this value */ 5253 /* Reset this value */
5254 dprintk(ioc, printk(MYIOC_s_DEBUG_FMT 5254 dprintk(ioc, printk(MYIOC_s_DEBUG_FMT
5255 "Resetting sg_tablesize to %d from %d\n", 5255 "Resetting sg_tablesize to %d from %d\n",
5256 ioc->name, numSGE, sh->sg_tablesize)); 5256 ioc->name, numSGE, sh->sg_tablesize));
5257 sh->sg_tablesize = numSGE; 5257 sh->sg_tablesize = numSGE;
5258 } 5258 }
5259 5259
5260 if (mpt_loadtime_max_sectors) { 5260 if (mpt_loadtime_max_sectors) {
5261 if (mpt_loadtime_max_sectors < 64 || 5261 if (mpt_loadtime_max_sectors < 64 ||
5262 mpt_loadtime_max_sectors > 8192) { 5262 mpt_loadtime_max_sectors > 8192) {
5263 printk(MYIOC_s_INFO_FMT "Invalid value passed for" 5263 printk(MYIOC_s_INFO_FMT "Invalid value passed for"
5264 "mpt_loadtime_max_sectors %d." 5264 "mpt_loadtime_max_sectors %d."
5265 "Range from 64 to 8192\n", ioc->name, 5265 "Range from 64 to 8192\n", ioc->name,
5266 mpt_loadtime_max_sectors); 5266 mpt_loadtime_max_sectors);
5267 } 5267 }
5268 mpt_loadtime_max_sectors &= 0xFFFFFFFE; 5268 mpt_loadtime_max_sectors &= 0xFFFFFFFE;
5269 dprintk(ioc, printk(MYIOC_s_DEBUG_FMT 5269 dprintk(ioc, printk(MYIOC_s_DEBUG_FMT
5270 "Resetting max sector to %d from %d\n", 5270 "Resetting max sector to %d from %d\n",
5271 ioc->name, mpt_loadtime_max_sectors, sh->max_sectors)); 5271 ioc->name, mpt_loadtime_max_sectors, sh->max_sectors));
5272 sh->max_sectors = mpt_loadtime_max_sectors; 5272 sh->max_sectors = mpt_loadtime_max_sectors;
5273 } 5273 }
5274 5274
5275 hd = shost_priv(sh); 5275 hd = shost_priv(sh);
5276 hd->ioc = ioc; 5276 hd->ioc = ioc;
5277 5277
5278 /* SCSI needs scsi_cmnd lookup table! 5278 /* SCSI needs scsi_cmnd lookup table!
5279 * (with size equal to req_depth*PtrSz!) 5279 * (with size equal to req_depth*PtrSz!)
5280 */ 5280 */
5281 ioc->ScsiLookup = kcalloc(ioc->req_depth, sizeof(void *), GFP_ATOMIC); 5281 ioc->ScsiLookup = kcalloc(ioc->req_depth, sizeof(void *), GFP_ATOMIC);
5282 if (!ioc->ScsiLookup) { 5282 if (!ioc->ScsiLookup) {
5283 error = -ENOMEM; 5283 error = -ENOMEM;
5284 spin_unlock_irqrestore(&ioc->FreeQlock, flags); 5284 spin_unlock_irqrestore(&ioc->FreeQlock, flags);
5285 goto out_mptsas_probe; 5285 goto out_mptsas_probe;
5286 } 5286 }
5287 spin_lock_init(&ioc->scsi_lookup_lock); 5287 spin_lock_init(&ioc->scsi_lookup_lock);
5288 5288
5289 dprintk(ioc, printk(MYIOC_s_DEBUG_FMT "ScsiLookup @ %p\n", 5289 dprintk(ioc, printk(MYIOC_s_DEBUG_FMT "ScsiLookup @ %p\n",
5290 ioc->name, ioc->ScsiLookup)); 5290 ioc->name, ioc->ScsiLookup));
5291 5291
5292 ioc->sas_data.ptClear = mpt_pt_clear; 5292 ioc->sas_data.ptClear = mpt_pt_clear;
5293 5293
5294 hd->last_queue_full = 0; 5294 hd->last_queue_full = 0;
5295 INIT_LIST_HEAD(&hd->target_reset_list); 5295 INIT_LIST_HEAD(&hd->target_reset_list);
5296 INIT_LIST_HEAD(&ioc->sas_device_info_list); 5296 INIT_LIST_HEAD(&ioc->sas_device_info_list);
5297 mutex_init(&ioc->sas_device_info_mutex); 5297 mutex_init(&ioc->sas_device_info_mutex);
5298 5298
5299 spin_unlock_irqrestore(&ioc->FreeQlock, flags); 5299 spin_unlock_irqrestore(&ioc->FreeQlock, flags);
5300 5300
5301 if (ioc->sas_data.ptClear==1) { 5301 if (ioc->sas_data.ptClear==1) {
5302 mptbase_sas_persist_operation( 5302 mptbase_sas_persist_operation(
5303 ioc, MPI_SAS_OP_CLEAR_ALL_PERSISTENT); 5303 ioc, MPI_SAS_OP_CLEAR_ALL_PERSISTENT);
5304 } 5304 }
5305 5305
5306 error = scsi_add_host(sh, &ioc->pcidev->dev); 5306 error = scsi_add_host(sh, &ioc->pcidev->dev);
5307 if (error) { 5307 if (error) {
5308 dprintk(ioc, printk(MYIOC_s_ERR_FMT 5308 dprintk(ioc, printk(MYIOC_s_ERR_FMT
5309 "scsi_add_host failed\n", ioc->name)); 5309 "scsi_add_host failed\n", ioc->name));
5310 goto out_mptsas_probe; 5310 goto out_mptsas_probe;
5311 } 5311 }
5312 5312
5313 /* older firmware doesn't support expander events */ 5313 /* older firmware doesn't support expander events */
5314 if ((ioc->facts.HeaderVersion >> 8) < 0xE) 5314 if ((ioc->facts.HeaderVersion >> 8) < 0xE)
5315 ioc->old_sas_discovery_protocal = 1; 5315 ioc->old_sas_discovery_protocal = 1;
5316 mptsas_scan_sas_topology(ioc); 5316 mptsas_scan_sas_topology(ioc);
5317 mptsas_fw_event_on(ioc); 5317 mptsas_fw_event_on(ioc);
5318 return 0; 5318 return 0;
5319 5319
5320 out_mptsas_probe: 5320 out_mptsas_probe:
5321 5321
5322 mptscsih_remove(pdev); 5322 mptscsih_remove(pdev);
5323 return error; 5323 return error;
5324 } 5324 }
5325 5325
5326 void 5326 void
5327 mptsas_shutdown(struct pci_dev *pdev) 5327 mptsas_shutdown(struct pci_dev *pdev)
5328 { 5328 {
5329 MPT_ADAPTER *ioc = pci_get_drvdata(pdev); 5329 MPT_ADAPTER *ioc = pci_get_drvdata(pdev);
5330 5330
5331 mptsas_fw_event_off(ioc); 5331 mptsas_fw_event_off(ioc);
5332 mptsas_cleanup_fw_event_q(ioc); 5332 mptsas_cleanup_fw_event_q(ioc);
5333 } 5333 }
5334 5334
5335 static void mptsas_remove(struct pci_dev *pdev) 5335 static void mptsas_remove(struct pci_dev *pdev)
5336 { 5336 {
5337 MPT_ADAPTER *ioc = pci_get_drvdata(pdev); 5337 MPT_ADAPTER *ioc = pci_get_drvdata(pdev);
5338 struct mptsas_portinfo *p, *n; 5338 struct mptsas_portinfo *p, *n;
5339 int i; 5339 int i;
5340 5340
5341 if (!ioc->sh) { 5341 if (!ioc->sh) {
5342 printk(MYIOC_s_INFO_FMT "IOC is in Target mode\n", ioc->name); 5342 printk(MYIOC_s_INFO_FMT "IOC is in Target mode\n", ioc->name);
5343 mpt_detach(pdev); 5343 mpt_detach(pdev);
5344 return; 5344 return;
5345 } 5345 }
5346 5346
5347 mptsas_shutdown(pdev); 5347 mptsas_shutdown(pdev);
5348 5348
5349 mptsas_del_device_components(ioc); 5349 mptsas_del_device_components(ioc);
5350 5350
5351 ioc->sas_discovery_ignore_events = 1; 5351 ioc->sas_discovery_ignore_events = 1;
5352 sas_remove_host(ioc->sh); 5352 sas_remove_host(ioc->sh);
5353 5353
5354 mutex_lock(&ioc->sas_topology_mutex); 5354 mutex_lock(&ioc->sas_topology_mutex);
5355 list_for_each_entry_safe(p, n, &ioc->sas_topology, list) { 5355 list_for_each_entry_safe(p, n, &ioc->sas_topology, list) {
5356 list_del(&p->list); 5356 list_del(&p->list);
5357 for (i = 0 ; i < p->num_phys ; i++) 5357 for (i = 0 ; i < p->num_phys ; i++)
5358 mptsas_port_delete(ioc, p->phy_info[i].port_details); 5358 mptsas_port_delete(ioc, p->phy_info[i].port_details);
5359 5359
5360 kfree(p->phy_info); 5360 kfree(p->phy_info);
5361 kfree(p); 5361 kfree(p);
5362 } 5362 }
5363 mutex_unlock(&ioc->sas_topology_mutex); 5363 mutex_unlock(&ioc->sas_topology_mutex);
5364 ioc->hba_port_info = NULL; 5364 ioc->hba_port_info = NULL;
5365 mptscsih_remove(pdev); 5365 mptscsih_remove(pdev);
5366 } 5366 }
5367 5367
5368 static struct pci_device_id mptsas_pci_table[] = { 5368 static struct pci_device_id mptsas_pci_table[] = {
5369 { PCI_VENDOR_ID_LSI_LOGIC, MPI_MANUFACTPAGE_DEVID_SAS1064, 5369 { PCI_VENDOR_ID_LSI_LOGIC, MPI_MANUFACTPAGE_DEVID_SAS1064,
5370 PCI_ANY_ID, PCI_ANY_ID }, 5370 PCI_ANY_ID, PCI_ANY_ID },
5371 { PCI_VENDOR_ID_LSI_LOGIC, MPI_MANUFACTPAGE_DEVID_SAS1068, 5371 { PCI_VENDOR_ID_LSI_LOGIC, MPI_MANUFACTPAGE_DEVID_SAS1068,
5372 PCI_ANY_ID, PCI_ANY_ID }, 5372 PCI_ANY_ID, PCI_ANY_ID },
5373 { PCI_VENDOR_ID_LSI_LOGIC, MPI_MANUFACTPAGE_DEVID_SAS1064E, 5373 { PCI_VENDOR_ID_LSI_LOGIC, MPI_MANUFACTPAGE_DEVID_SAS1064E,
5374 PCI_ANY_ID, PCI_ANY_ID }, 5374 PCI_ANY_ID, PCI_ANY_ID },
5375 { PCI_VENDOR_ID_LSI_LOGIC, MPI_MANUFACTPAGE_DEVID_SAS1068E, 5375 { PCI_VENDOR_ID_LSI_LOGIC, MPI_MANUFACTPAGE_DEVID_SAS1068E,
5376 PCI_ANY_ID, PCI_ANY_ID }, 5376 PCI_ANY_ID, PCI_ANY_ID },
5377 { PCI_VENDOR_ID_LSI_LOGIC, MPI_MANUFACTPAGE_DEVID_SAS1078, 5377 { PCI_VENDOR_ID_LSI_LOGIC, MPI_MANUFACTPAGE_DEVID_SAS1078,
5378 PCI_ANY_ID, PCI_ANY_ID }, 5378 PCI_ANY_ID, PCI_ANY_ID },
5379 { PCI_VENDOR_ID_LSI_LOGIC, MPI_MANUFACTPAGE_DEVID_SAS1068_820XELP, 5379 { PCI_VENDOR_ID_LSI_LOGIC, MPI_MANUFACTPAGE_DEVID_SAS1068_820XELP,
5380 PCI_ANY_ID, PCI_ANY_ID }, 5380 PCI_ANY_ID, PCI_ANY_ID },
5381 {0} /* Terminating entry */ 5381 {0} /* Terminating entry */
5382 }; 5382 };
5383 MODULE_DEVICE_TABLE(pci, mptsas_pci_table); 5383 MODULE_DEVICE_TABLE(pci, mptsas_pci_table);
5384 5384
5385 5385
5386 static struct pci_driver mptsas_driver = { 5386 static struct pci_driver mptsas_driver = {
5387 .name = "mptsas", 5387 .name = "mptsas",
5388 .id_table = mptsas_pci_table, 5388 .id_table = mptsas_pci_table,
5389 .probe = mptsas_probe, 5389 .probe = mptsas_probe,
5390 .remove = mptsas_remove, 5390 .remove = mptsas_remove,
5391 .shutdown = mptsas_shutdown, 5391 .shutdown = mptsas_shutdown,
5392 #ifdef CONFIG_PM 5392 #ifdef CONFIG_PM
5393 .suspend = mptscsih_suspend, 5393 .suspend = mptscsih_suspend,
5394 .resume = mptscsih_resume, 5394 .resume = mptscsih_resume,
5395 #endif 5395 #endif
5396 }; 5396 };
5397 5397
5398 static int __init 5398 static int __init
5399 mptsas_init(void) 5399 mptsas_init(void)
5400 { 5400 {
5401 int error; 5401 int error;
5402 5402
5403 show_mptmod_ver(my_NAME, my_VERSION); 5403 show_mptmod_ver(my_NAME, my_VERSION);
5404 5404
5405 mptsas_transport_template = 5405 mptsas_transport_template =
5406 sas_attach_transport(&mptsas_transport_functions); 5406 sas_attach_transport(&mptsas_transport_functions);
5407 if (!mptsas_transport_template) 5407 if (!mptsas_transport_template)
5408 return -ENODEV; 5408 return -ENODEV;
5409 mptsas_transport_template->eh_timed_out = mptsas_eh_timed_out; 5409 mptsas_transport_template->eh_timed_out = mptsas_eh_timed_out;
5410 5410
5411 mptsasDoneCtx = mpt_register(mptscsih_io_done, MPTSAS_DRIVER, 5411 mptsasDoneCtx = mpt_register(mptscsih_io_done, MPTSAS_DRIVER,
5412 "mptscsih_io_done"); 5412 "mptscsih_io_done");
5413 mptsasTaskCtx = mpt_register(mptscsih_taskmgmt_complete, MPTSAS_DRIVER, 5413 mptsasTaskCtx = mpt_register(mptscsih_taskmgmt_complete, MPTSAS_DRIVER,
5414 "mptscsih_taskmgmt_complete"); 5414 "mptscsih_taskmgmt_complete");
5415 mptsasInternalCtx = 5415 mptsasInternalCtx =
5416 mpt_register(mptscsih_scandv_complete, MPTSAS_DRIVER, 5416 mpt_register(mptscsih_scandv_complete, MPTSAS_DRIVER,
5417 "mptscsih_scandv_complete"); 5417 "mptscsih_scandv_complete");
5418 mptsasMgmtCtx = mpt_register(mptsas_mgmt_done, MPTSAS_DRIVER, 5418 mptsasMgmtCtx = mpt_register(mptsas_mgmt_done, MPTSAS_DRIVER,
5419 "mptsas_mgmt_done"); 5419 "mptsas_mgmt_done");
5420 mptsasDeviceResetCtx = 5420 mptsasDeviceResetCtx =
5421 mpt_register(mptsas_taskmgmt_complete, MPTSAS_DRIVER, 5421 mpt_register(mptsas_taskmgmt_complete, MPTSAS_DRIVER,
5422 "mptsas_taskmgmt_complete"); 5422 "mptsas_taskmgmt_complete");
5423 5423
5424 mpt_event_register(mptsasDoneCtx, mptsas_event_process); 5424 mpt_event_register(mptsasDoneCtx, mptsas_event_process);
5425 mpt_reset_register(mptsasDoneCtx, mptsas_ioc_reset); 5425 mpt_reset_register(mptsasDoneCtx, mptsas_ioc_reset);
5426 5426
5427 error = pci_register_driver(&mptsas_driver); 5427 error = pci_register_driver(&mptsas_driver);
5428 if (error) 5428 if (error)
5429 sas_release_transport(mptsas_transport_template); 5429 sas_release_transport(mptsas_transport_template);
5430 5430
5431 return error; 5431 return error;
5432 } 5432 }
5433 5433
5434 static void __exit 5434 static void __exit
5435 mptsas_exit(void) 5435 mptsas_exit(void)
5436 { 5436 {
5437 pci_unregister_driver(&mptsas_driver); 5437 pci_unregister_driver(&mptsas_driver);
5438 sas_release_transport(mptsas_transport_template); 5438 sas_release_transport(mptsas_transport_template);
5439 5439
5440 mpt_reset_deregister(mptsasDoneCtx); 5440 mpt_reset_deregister(mptsasDoneCtx);
5441 mpt_event_deregister(mptsasDoneCtx); 5441 mpt_event_deregister(mptsasDoneCtx);
5442 5442
5443 mpt_deregister(mptsasMgmtCtx); 5443 mpt_deregister(mptsasMgmtCtx);
5444 mpt_deregister(mptsasInternalCtx); 5444 mpt_deregister(mptsasInternalCtx);
5445 mpt_deregister(mptsasTaskCtx); 5445 mpt_deregister(mptsasTaskCtx);
5446 mpt_deregister(mptsasDoneCtx); 5446 mpt_deregister(mptsasDoneCtx);
5447 mpt_deregister(mptsasDeviceResetCtx); 5447 mpt_deregister(mptsasDeviceResetCtx);
5448 } 5448 }
5449 5449
5450 module_init(mptsas_init); 5450 module_init(mptsas_init);
5451 module_exit(mptsas_exit); 5451 module_exit(mptsas_exit);
5452 5452
drivers/message/fusion/mptscsih.c
1 /* 1 /*
2 * linux/drivers/message/fusion/mptscsih.c 2 * linux/drivers/message/fusion/mptscsih.c
3 * For use with LSI PCI chip/adapter(s) 3 * For use with LSI PCI chip/adapter(s)
4 * running LSI Fusion MPT (Message Passing Technology) firmware. 4 * running LSI Fusion MPT (Message Passing Technology) firmware.
5 * 5 *
6 * Copyright (c) 1999-2008 LSI Corporation 6 * Copyright (c) 1999-2008 LSI Corporation
7 * (mailto:DL-MPTFusionLinux@lsi.com) 7 * (mailto:DL-MPTFusionLinux@lsi.com)
8 * 8 *
9 */ 9 */
10 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/ 10 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
11 /* 11 /*
12 This program is free software; you can redistribute it and/or modify 12 This program is free software; you can redistribute it and/or modify
13 it under the terms of the GNU General Public License as published by 13 it under the terms of the GNU General Public License as published by
14 the Free Software Foundation; version 2 of the License. 14 the Free Software Foundation; version 2 of the License.
15 15
16 This program is distributed in the hope that it will be useful, 16 This program is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of 17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 GNU General Public License for more details. 19 GNU General Public License for more details.
20 20
21 NO WARRANTY 21 NO WARRANTY
22 THE PROGRAM IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR 22 THE PROGRAM IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR
23 CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT 23 CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT
24 LIMITATION, ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT, 24 LIMITATION, ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT,
25 MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Each Recipient is 25 MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Each Recipient is
26 solely responsible for determining the appropriateness of using and 26 solely responsible for determining the appropriateness of using and
27 distributing the Program and assumes all risks associated with its 27 distributing the Program and assumes all risks associated with its
28 exercise of rights under this Agreement, including but not limited to 28 exercise of rights under this Agreement, including but not limited to
29 the risks and costs of program errors, damage to or loss of data, 29 the risks and costs of program errors, damage to or loss of data,
30 programs or equipment, and unavailability or interruption of operations. 30 programs or equipment, and unavailability or interruption of operations.
31 31
32 DISCLAIMER OF LIABILITY 32 DISCLAIMER OF LIABILITY
33 NEITHER RECIPIENT NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY 33 NEITHER RECIPIENT NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY
34 DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 34 DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
35 DAMAGES (INCLUDING WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND 35 DAMAGES (INCLUDING WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND
36 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR 36 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
37 TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE 37 TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
38 USE OR DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS GRANTED 38 USE OR DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS GRANTED
39 HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES 39 HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES
40 40
41 You should have received a copy of the GNU General Public License 41 You should have received a copy of the GNU General Public License
42 along with this program; if not, write to the Free Software 42 along with this program; if not, write to the Free Software
43 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 43 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
44 */ 44 */
45 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/ 45 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
46 46
47 #include <linux/module.h> 47 #include <linux/module.h>
48 #include <linux/kernel.h> 48 #include <linux/kernel.h>
49 #include <linux/slab.h> 49 #include <linux/slab.h>
50 #include <linux/init.h> 50 #include <linux/init.h>
51 #include <linux/errno.h> 51 #include <linux/errno.h>
52 #include <linux/kdev_t.h> 52 #include <linux/kdev_t.h>
53 #include <linux/blkdev.h> 53 #include <linux/blkdev.h>
54 #include <linux/delay.h> /* for mdelay */ 54 #include <linux/delay.h> /* for mdelay */
55 #include <linux/interrupt.h> /* needed for in_interrupt() proto */ 55 #include <linux/interrupt.h> /* needed for in_interrupt() proto */
56 #include <linux/reboot.h> /* notifier code */ 56 #include <linux/reboot.h> /* notifier code */
57 #include <linux/workqueue.h> 57 #include <linux/workqueue.h>
58 58
59 #include <scsi/scsi.h> 59 #include <scsi/scsi.h>
60 #include <scsi/scsi_cmnd.h> 60 #include <scsi/scsi_cmnd.h>
61 #include <scsi/scsi_device.h> 61 #include <scsi/scsi_device.h>
62 #include <scsi/scsi_host.h> 62 #include <scsi/scsi_host.h>
63 #include <scsi/scsi_tcq.h> 63 #include <scsi/scsi_tcq.h>
64 #include <scsi/scsi_dbg.h> 64 #include <scsi/scsi_dbg.h>
65 65
66 #include "mptbase.h" 66 #include "mptbase.h"
67 #include "mptscsih.h" 67 #include "mptscsih.h"
68 #include "lsi/mpi_log_sas.h" 68 #include "lsi/mpi_log_sas.h"
69 69
70 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/ 70 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
71 #define my_NAME "Fusion MPT SCSI Host driver" 71 #define my_NAME "Fusion MPT SCSI Host driver"
72 #define my_VERSION MPT_LINUX_VERSION_COMMON 72 #define my_VERSION MPT_LINUX_VERSION_COMMON
73 #define MYNAM "mptscsih" 73 #define MYNAM "mptscsih"
74 74
75 MODULE_AUTHOR(MODULEAUTHOR); 75 MODULE_AUTHOR(MODULEAUTHOR);
76 MODULE_DESCRIPTION(my_NAME); 76 MODULE_DESCRIPTION(my_NAME);
77 MODULE_LICENSE("GPL"); 77 MODULE_LICENSE("GPL");
78 MODULE_VERSION(my_VERSION); 78 MODULE_VERSION(my_VERSION);
79 79
80 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/ 80 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
81 /* 81 /*
82 * Other private/forward protos... 82 * Other private/forward protos...
83 */ 83 */
84 struct scsi_cmnd *mptscsih_get_scsi_lookup(MPT_ADAPTER *ioc, int i); 84 struct scsi_cmnd *mptscsih_get_scsi_lookup(MPT_ADAPTER *ioc, int i);
85 static struct scsi_cmnd * mptscsih_getclear_scsi_lookup(MPT_ADAPTER *ioc, int i); 85 static struct scsi_cmnd * mptscsih_getclear_scsi_lookup(MPT_ADAPTER *ioc, int i);
86 static void mptscsih_set_scsi_lookup(MPT_ADAPTER *ioc, int i, struct scsi_cmnd *scmd); 86 static void mptscsih_set_scsi_lookup(MPT_ADAPTER *ioc, int i, struct scsi_cmnd *scmd);
87 static int SCPNT_TO_LOOKUP_IDX(MPT_ADAPTER *ioc, struct scsi_cmnd *scmd); 87 static int SCPNT_TO_LOOKUP_IDX(MPT_ADAPTER *ioc, struct scsi_cmnd *scmd);
88 int mptscsih_io_done(MPT_ADAPTER *ioc, MPT_FRAME_HDR *mf, MPT_FRAME_HDR *r); 88 int mptscsih_io_done(MPT_ADAPTER *ioc, MPT_FRAME_HDR *mf, MPT_FRAME_HDR *r);
89 static void mptscsih_report_queue_full(struct scsi_cmnd *sc, SCSIIOReply_t *pScsiReply, SCSIIORequest_t *pScsiReq); 89 static void mptscsih_report_queue_full(struct scsi_cmnd *sc, SCSIIOReply_t *pScsiReply, SCSIIORequest_t *pScsiReq);
90 int mptscsih_taskmgmt_complete(MPT_ADAPTER *ioc, MPT_FRAME_HDR *mf, MPT_FRAME_HDR *r); 90 int mptscsih_taskmgmt_complete(MPT_ADAPTER *ioc, MPT_FRAME_HDR *mf, MPT_FRAME_HDR *r);
91 91
92 static int mptscsih_AddSGE(MPT_ADAPTER *ioc, struct scsi_cmnd *SCpnt, 92 static int mptscsih_AddSGE(MPT_ADAPTER *ioc, struct scsi_cmnd *SCpnt,
93 SCSIIORequest_t *pReq, int req_idx); 93 SCSIIORequest_t *pReq, int req_idx);
94 static void mptscsih_freeChainBuffers(MPT_ADAPTER *ioc, int req_idx); 94 static void mptscsih_freeChainBuffers(MPT_ADAPTER *ioc, int req_idx);
95 static void mptscsih_copy_sense_data(struct scsi_cmnd *sc, MPT_SCSI_HOST *hd, MPT_FRAME_HDR *mf, SCSIIOReply_t *pScsiReply); 95 static void mptscsih_copy_sense_data(struct scsi_cmnd *sc, MPT_SCSI_HOST *hd, MPT_FRAME_HDR *mf, SCSIIOReply_t *pScsiReply);
96 96
97 int mptscsih_IssueTaskMgmt(MPT_SCSI_HOST *hd, u8 type, u8 channel, u8 id, 97 int mptscsih_IssueTaskMgmt(MPT_SCSI_HOST *hd, u8 type, u8 channel, u8 id,
98 int lun, int ctx2abort, ulong timeout); 98 int lun, int ctx2abort, ulong timeout);
99 99
100 int mptscsih_ioc_reset(MPT_ADAPTER *ioc, int post_reset); 100 int mptscsih_ioc_reset(MPT_ADAPTER *ioc, int post_reset);
101 int mptscsih_event_process(MPT_ADAPTER *ioc, EventNotificationReply_t *pEvReply); 101 int mptscsih_event_process(MPT_ADAPTER *ioc, EventNotificationReply_t *pEvReply);
102 102
103 void 103 void
104 mptscsih_taskmgmt_response_code(MPT_ADAPTER *ioc, u8 response_code); 104 mptscsih_taskmgmt_response_code(MPT_ADAPTER *ioc, u8 response_code);
105 static int mptscsih_get_completion_code(MPT_ADAPTER *ioc, 105 static int mptscsih_get_completion_code(MPT_ADAPTER *ioc,
106 MPT_FRAME_HDR *req, MPT_FRAME_HDR *reply); 106 MPT_FRAME_HDR *req, MPT_FRAME_HDR *reply);
107 int mptscsih_scandv_complete(MPT_ADAPTER *ioc, MPT_FRAME_HDR *mf, MPT_FRAME_HDR *r); 107 int mptscsih_scandv_complete(MPT_ADAPTER *ioc, MPT_FRAME_HDR *mf, MPT_FRAME_HDR *r);
108 static int mptscsih_do_cmd(MPT_SCSI_HOST *hd, INTERNAL_CMD *iocmd); 108 static int mptscsih_do_cmd(MPT_SCSI_HOST *hd, INTERNAL_CMD *iocmd);
109 static void mptscsih_synchronize_cache(MPT_SCSI_HOST *hd, VirtDevice *vdevice); 109 static void mptscsih_synchronize_cache(MPT_SCSI_HOST *hd, VirtDevice *vdevice);
110 110
111 static int 111 static int
112 mptscsih_taskmgmt_reply(MPT_ADAPTER *ioc, u8 type, 112 mptscsih_taskmgmt_reply(MPT_ADAPTER *ioc, u8 type,
113 SCSITaskMgmtReply_t *pScsiTmReply); 113 SCSITaskMgmtReply_t *pScsiTmReply);
114 void mptscsih_remove(struct pci_dev *); 114 void mptscsih_remove(struct pci_dev *);
115 void mptscsih_shutdown(struct pci_dev *); 115 void mptscsih_shutdown(struct pci_dev *);
116 #ifdef CONFIG_PM 116 #ifdef CONFIG_PM
117 int mptscsih_suspend(struct pci_dev *pdev, pm_message_t state); 117 int mptscsih_suspend(struct pci_dev *pdev, pm_message_t state);
118 int mptscsih_resume(struct pci_dev *pdev); 118 int mptscsih_resume(struct pci_dev *pdev);
119 #endif 119 #endif
120 120
121 #define SNS_LEN(scp) SCSI_SENSE_BUFFERSIZE 121 #define SNS_LEN(scp) SCSI_SENSE_BUFFERSIZE
122 122
123 123
124 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/ 124 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
125 /* 125 /*
126 * mptscsih_getFreeChainBuffer - Function to get a free chain 126 * mptscsih_getFreeChainBuffer - Function to get a free chain
127 * from the MPT_SCSI_HOST FreeChainQ. 127 * from the MPT_SCSI_HOST FreeChainQ.
128 * @ioc: Pointer to MPT_ADAPTER structure 128 * @ioc: Pointer to MPT_ADAPTER structure
129 * @req_idx: Index of the SCSI IO request frame. (output) 129 * @req_idx: Index of the SCSI IO request frame. (output)
130 * 130 *
131 * return SUCCESS or FAILED 131 * return SUCCESS or FAILED
132 */ 132 */
133 static inline int 133 static inline int
134 mptscsih_getFreeChainBuffer(MPT_ADAPTER *ioc, int *retIndex) 134 mptscsih_getFreeChainBuffer(MPT_ADAPTER *ioc, int *retIndex)
135 { 135 {
136 MPT_FRAME_HDR *chainBuf; 136 MPT_FRAME_HDR *chainBuf;
137 unsigned long flags; 137 unsigned long flags;
138 int rc; 138 int rc;
139 int chain_idx; 139 int chain_idx;
140 140
141 dsgprintk(ioc, printk(MYIOC_s_DEBUG_FMT "getFreeChainBuffer called\n", 141 dsgprintk(ioc, printk(MYIOC_s_DEBUG_FMT "getFreeChainBuffer called\n",
142 ioc->name)); 142 ioc->name));
143 spin_lock_irqsave(&ioc->FreeQlock, flags); 143 spin_lock_irqsave(&ioc->FreeQlock, flags);
144 if (!list_empty(&ioc->FreeChainQ)) { 144 if (!list_empty(&ioc->FreeChainQ)) {
145 int offset; 145 int offset;
146 146
147 chainBuf = list_entry(ioc->FreeChainQ.next, MPT_FRAME_HDR, 147 chainBuf = list_entry(ioc->FreeChainQ.next, MPT_FRAME_HDR,
148 u.frame.linkage.list); 148 u.frame.linkage.list);
149 list_del(&chainBuf->u.frame.linkage.list); 149 list_del(&chainBuf->u.frame.linkage.list);
150 offset = (u8 *)chainBuf - (u8 *)ioc->ChainBuffer; 150 offset = (u8 *)chainBuf - (u8 *)ioc->ChainBuffer;
151 chain_idx = offset / ioc->req_sz; 151 chain_idx = offset / ioc->req_sz;
152 rc = SUCCESS; 152 rc = SUCCESS;
153 dsgprintk(ioc, printk(MYIOC_s_DEBUG_FMT 153 dsgprintk(ioc, printk(MYIOC_s_DEBUG_FMT
154 "getFreeChainBuffer chainBuf=%p ChainBuffer=%p offset=%d chain_idx=%d\n", 154 "getFreeChainBuffer chainBuf=%p ChainBuffer=%p offset=%d chain_idx=%d\n",
155 ioc->name, chainBuf, ioc->ChainBuffer, offset, chain_idx)); 155 ioc->name, chainBuf, ioc->ChainBuffer, offset, chain_idx));
156 } else { 156 } else {
157 rc = FAILED; 157 rc = FAILED;
158 chain_idx = MPT_HOST_NO_CHAIN; 158 chain_idx = MPT_HOST_NO_CHAIN;
159 dfailprintk(ioc, printk(MYIOC_s_ERR_FMT "getFreeChainBuffer failed\n", 159 dfailprintk(ioc, printk(MYIOC_s_ERR_FMT "getFreeChainBuffer failed\n",
160 ioc->name)); 160 ioc->name));
161 } 161 }
162 spin_unlock_irqrestore(&ioc->FreeQlock, flags); 162 spin_unlock_irqrestore(&ioc->FreeQlock, flags);
163 163
164 *retIndex = chain_idx; 164 *retIndex = chain_idx;
165 return rc; 165 return rc;
166 } /* mptscsih_getFreeChainBuffer() */ 166 } /* mptscsih_getFreeChainBuffer() */
167 167
168 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/ 168 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
169 /* 169 /*
170 * mptscsih_AddSGE - Add a SGE (plus chain buffers) to the 170 * mptscsih_AddSGE - Add a SGE (plus chain buffers) to the
171 * SCSIIORequest_t Message Frame. 171 * SCSIIORequest_t Message Frame.
172 * @ioc: Pointer to MPT_ADAPTER structure 172 * @ioc: Pointer to MPT_ADAPTER structure
173 * @SCpnt: Pointer to scsi_cmnd structure 173 * @SCpnt: Pointer to scsi_cmnd structure
174 * @pReq: Pointer to SCSIIORequest_t structure 174 * @pReq: Pointer to SCSIIORequest_t structure
175 * 175 *
176 * Returns ... 176 * Returns ...
177 */ 177 */
178 static int 178 static int
179 mptscsih_AddSGE(MPT_ADAPTER *ioc, struct scsi_cmnd *SCpnt, 179 mptscsih_AddSGE(MPT_ADAPTER *ioc, struct scsi_cmnd *SCpnt,
180 SCSIIORequest_t *pReq, int req_idx) 180 SCSIIORequest_t *pReq, int req_idx)
181 { 181 {
182 char *psge; 182 char *psge;
183 char *chainSge; 183 char *chainSge;
184 struct scatterlist *sg; 184 struct scatterlist *sg;
185 int frm_sz; 185 int frm_sz;
186 int sges_left, sg_done; 186 int sges_left, sg_done;
187 int chain_idx = MPT_HOST_NO_CHAIN; 187 int chain_idx = MPT_HOST_NO_CHAIN;
188 int sgeOffset; 188 int sgeOffset;
189 int numSgeSlots, numSgeThisFrame; 189 int numSgeSlots, numSgeThisFrame;
190 u32 sgflags, sgdir, thisxfer = 0; 190 u32 sgflags, sgdir, thisxfer = 0;
191 int chain_dma_off = 0; 191 int chain_dma_off = 0;
192 int newIndex; 192 int newIndex;
193 int ii; 193 int ii;
194 dma_addr_t v2; 194 dma_addr_t v2;
195 u32 RequestNB; 195 u32 RequestNB;
196 196
197 sgdir = le32_to_cpu(pReq->Control) & MPI_SCSIIO_CONTROL_DATADIRECTION_MASK; 197 sgdir = le32_to_cpu(pReq->Control) & MPI_SCSIIO_CONTROL_DATADIRECTION_MASK;
198 if (sgdir == MPI_SCSIIO_CONTROL_WRITE) { 198 if (sgdir == MPI_SCSIIO_CONTROL_WRITE) {
199 sgdir = MPT_TRANSFER_HOST_TO_IOC; 199 sgdir = MPT_TRANSFER_HOST_TO_IOC;
200 } else { 200 } else {
201 sgdir = MPT_TRANSFER_IOC_TO_HOST; 201 sgdir = MPT_TRANSFER_IOC_TO_HOST;
202 } 202 }
203 203
204 psge = (char *) &pReq->SGL; 204 psge = (char *) &pReq->SGL;
205 frm_sz = ioc->req_sz; 205 frm_sz = ioc->req_sz;
206 206
207 /* Map the data portion, if any. 207 /* Map the data portion, if any.
208 * sges_left = 0 if no data transfer. 208 * sges_left = 0 if no data transfer.
209 */ 209 */
210 sges_left = scsi_dma_map(SCpnt); 210 sges_left = scsi_dma_map(SCpnt);
211 if (sges_left < 0) 211 if (sges_left < 0)
212 return FAILED; 212 return FAILED;
213 213
214 /* Handle the SG case. 214 /* Handle the SG case.
215 */ 215 */
216 sg = scsi_sglist(SCpnt); 216 sg = scsi_sglist(SCpnt);
217 sg_done = 0; 217 sg_done = 0;
218 sgeOffset = sizeof(SCSIIORequest_t) - sizeof(SGE_IO_UNION); 218 sgeOffset = sizeof(SCSIIORequest_t) - sizeof(SGE_IO_UNION);
219 chainSge = NULL; 219 chainSge = NULL;
220 220
221 /* Prior to entering this loop - the following must be set 221 /* Prior to entering this loop - the following must be set
222 * current MF: sgeOffset (bytes) 222 * current MF: sgeOffset (bytes)
223 * chainSge (Null if original MF is not a chain buffer) 223 * chainSge (Null if original MF is not a chain buffer)
224 * sg_done (num SGE done for this MF) 224 * sg_done (num SGE done for this MF)
225 */ 225 */
226 226
227 nextSGEset: 227 nextSGEset:
228 numSgeSlots = ((frm_sz - sgeOffset) / ioc->SGE_size); 228 numSgeSlots = ((frm_sz - sgeOffset) / ioc->SGE_size);
229 numSgeThisFrame = (sges_left < numSgeSlots) ? sges_left : numSgeSlots; 229 numSgeThisFrame = (sges_left < numSgeSlots) ? sges_left : numSgeSlots;
230 230
231 sgflags = MPT_SGE_FLAGS_SIMPLE_ELEMENT | sgdir; 231 sgflags = MPT_SGE_FLAGS_SIMPLE_ELEMENT | sgdir;
232 232
233 /* Get first (num - 1) SG elements 233 /* Get first (num - 1) SG elements
234 * Skip any SG entries with a length of 0 234 * Skip any SG entries with a length of 0
235 * NOTE: at finish, sg and psge pointed to NEXT data/location positions 235 * NOTE: at finish, sg and psge pointed to NEXT data/location positions
236 */ 236 */
237 for (ii=0; ii < (numSgeThisFrame-1); ii++) { 237 for (ii=0; ii < (numSgeThisFrame-1); ii++) {
238 thisxfer = sg_dma_len(sg); 238 thisxfer = sg_dma_len(sg);
239 if (thisxfer == 0) { 239 if (thisxfer == 0) {
240 /* Get next SG element from the OS */ 240 /* Get next SG element from the OS */
241 sg = sg_next(sg); 241 sg = sg_next(sg);
242 sg_done++; 242 sg_done++;
243 continue; 243 continue;
244 } 244 }
245 245
246 v2 = sg_dma_address(sg); 246 v2 = sg_dma_address(sg);
247 ioc->add_sge(psge, sgflags | thisxfer, v2); 247 ioc->add_sge(psge, sgflags | thisxfer, v2);
248 248
249 /* Get next SG element from the OS */ 249 /* Get next SG element from the OS */
250 sg = sg_next(sg); 250 sg = sg_next(sg);
251 psge += ioc->SGE_size; 251 psge += ioc->SGE_size;
252 sgeOffset += ioc->SGE_size; 252 sgeOffset += ioc->SGE_size;
253 sg_done++; 253 sg_done++;
254 } 254 }
255 255
256 if (numSgeThisFrame == sges_left) { 256 if (numSgeThisFrame == sges_left) {
257 /* Add last element, end of buffer and end of list flags. 257 /* Add last element, end of buffer and end of list flags.
258 */ 258 */
259 sgflags |= MPT_SGE_FLAGS_LAST_ELEMENT | 259 sgflags |= MPT_SGE_FLAGS_LAST_ELEMENT |
260 MPT_SGE_FLAGS_END_OF_BUFFER | 260 MPT_SGE_FLAGS_END_OF_BUFFER |
261 MPT_SGE_FLAGS_END_OF_LIST; 261 MPT_SGE_FLAGS_END_OF_LIST;
262 262
263 /* Add last SGE and set termination flags. 263 /* Add last SGE and set termination flags.
264 * Note: Last SGE may have a length of 0 - which should be ok. 264 * Note: Last SGE may have a length of 0 - which should be ok.
265 */ 265 */
266 thisxfer = sg_dma_len(sg); 266 thisxfer = sg_dma_len(sg);
267 267
268 v2 = sg_dma_address(sg); 268 v2 = sg_dma_address(sg);
269 ioc->add_sge(psge, sgflags | thisxfer, v2); 269 ioc->add_sge(psge, sgflags | thisxfer, v2);
270 sgeOffset += ioc->SGE_size; 270 sgeOffset += ioc->SGE_size;
271 sg_done++; 271 sg_done++;
272 272
273 if (chainSge) { 273 if (chainSge) {
274 /* The current buffer is a chain buffer, 274 /* The current buffer is a chain buffer,
275 * but there is not another one. 275 * but there is not another one.
276 * Update the chain element 276 * Update the chain element
277 * Offset and Length fields. 277 * Offset and Length fields.
278 */ 278 */
279 ioc->add_chain((char *)chainSge, 0, sgeOffset, 279 ioc->add_chain((char *)chainSge, 0, sgeOffset,
280 ioc->ChainBufferDMA + chain_dma_off); 280 ioc->ChainBufferDMA + chain_dma_off);
281 } else { 281 } else {
282 /* The current buffer is the original MF 282 /* The current buffer is the original MF
283 * and there is no Chain buffer. 283 * and there is no Chain buffer.
284 */ 284 */
285 pReq->ChainOffset = 0; 285 pReq->ChainOffset = 0;
286 RequestNB = (((sgeOffset - 1) >> ioc->NBShiftFactor) + 1) & 0x03; 286 RequestNB = (((sgeOffset - 1) >> ioc->NBShiftFactor) + 1) & 0x03;
287 dsgprintk(ioc, printk(MYIOC_s_DEBUG_FMT 287 dsgprintk(ioc, printk(MYIOC_s_DEBUG_FMT
288 "Single Buffer RequestNB=%x, sgeOffset=%d\n", ioc->name, RequestNB, sgeOffset)); 288 "Single Buffer RequestNB=%x, sgeOffset=%d\n", ioc->name, RequestNB, sgeOffset));
289 ioc->RequestNB[req_idx] = RequestNB; 289 ioc->RequestNB[req_idx] = RequestNB;
290 } 290 }
291 } else { 291 } else {
292 /* At least one chain buffer is needed. 292 /* At least one chain buffer is needed.
293 * Complete the first MF 293 * Complete the first MF
294 * - last SGE element, set the LastElement bit 294 * - last SGE element, set the LastElement bit
295 * - set ChainOffset (words) for orig MF 295 * - set ChainOffset (words) for orig MF
296 * (OR finish previous MF chain buffer) 296 * (OR finish previous MF chain buffer)
297 * - update MFStructPtr ChainIndex 297 * - update MFStructPtr ChainIndex
298 * - Populate chain element 298 * - Populate chain element
299 * Also 299 * Also
300 * Loop until done. 300 * Loop until done.
301 */ 301 */
302 302
303 dsgprintk(ioc, printk(MYIOC_s_DEBUG_FMT "SG: Chain Required! sg done %d\n", 303 dsgprintk(ioc, printk(MYIOC_s_DEBUG_FMT "SG: Chain Required! sg done %d\n",
304 ioc->name, sg_done)); 304 ioc->name, sg_done));
305 305
306 /* Set LAST_ELEMENT flag for last non-chain element 306 /* Set LAST_ELEMENT flag for last non-chain element
307 * in the buffer. Since psge points at the NEXT 307 * in the buffer. Since psge points at the NEXT
308 * SGE element, go back one SGE element, update the flags 308 * SGE element, go back one SGE element, update the flags
309 * and reset the pointer. (Note: sgflags & thisxfer are already 309 * and reset the pointer. (Note: sgflags & thisxfer are already
310 * set properly). 310 * set properly).
311 */ 311 */
312 if (sg_done) { 312 if (sg_done) {
313 u32 *ptmp = (u32 *) (psge - ioc->SGE_size); 313 u32 *ptmp = (u32 *) (psge - ioc->SGE_size);
314 sgflags = le32_to_cpu(*ptmp); 314 sgflags = le32_to_cpu(*ptmp);
315 sgflags |= MPT_SGE_FLAGS_LAST_ELEMENT; 315 sgflags |= MPT_SGE_FLAGS_LAST_ELEMENT;
316 *ptmp = cpu_to_le32(sgflags); 316 *ptmp = cpu_to_le32(sgflags);
317 } 317 }
318 318
319 if (chainSge) { 319 if (chainSge) {
320 /* The current buffer is a chain buffer. 320 /* The current buffer is a chain buffer.
321 * chainSge points to the previous Chain Element. 321 * chainSge points to the previous Chain Element.
322 * Update its chain element Offset and Length (must 322 * Update its chain element Offset and Length (must
323 * include chain element size) fields. 323 * include chain element size) fields.
324 * Old chain element is now complete. 324 * Old chain element is now complete.
325 */ 325 */
326 u8 nextChain = (u8) (sgeOffset >> 2); 326 u8 nextChain = (u8) (sgeOffset >> 2);
327 sgeOffset += ioc->SGE_size; 327 sgeOffset += ioc->SGE_size;
328 ioc->add_chain((char *)chainSge, nextChain, sgeOffset, 328 ioc->add_chain((char *)chainSge, nextChain, sgeOffset,
329 ioc->ChainBufferDMA + chain_dma_off); 329 ioc->ChainBufferDMA + chain_dma_off);
330 } else { 330 } else {
331 /* The original MF buffer requires a chain buffer - 331 /* The original MF buffer requires a chain buffer -
332 * set the offset. 332 * set the offset.
333 * Last element in this MF is a chain element. 333 * Last element in this MF is a chain element.
334 */ 334 */
335 pReq->ChainOffset = (u8) (sgeOffset >> 2); 335 pReq->ChainOffset = (u8) (sgeOffset >> 2);
336 RequestNB = (((sgeOffset - 1) >> ioc->NBShiftFactor) + 1) & 0x03; 336 RequestNB = (((sgeOffset - 1) >> ioc->NBShiftFactor) + 1) & 0x03;
337 dsgprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Chain Buffer Needed, RequestNB=%x sgeOffset=%d\n", ioc->name, RequestNB, sgeOffset)); 337 dsgprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Chain Buffer Needed, RequestNB=%x sgeOffset=%d\n", ioc->name, RequestNB, sgeOffset));
338 ioc->RequestNB[req_idx] = RequestNB; 338 ioc->RequestNB[req_idx] = RequestNB;
339 } 339 }
340 340
341 sges_left -= sg_done; 341 sges_left -= sg_done;
342 342
343 343
344 /* NOTE: psge points to the beginning of the chain element 344 /* NOTE: psge points to the beginning of the chain element
345 * in current buffer. Get a chain buffer. 345 * in current buffer. Get a chain buffer.
346 */ 346 */
347 if ((mptscsih_getFreeChainBuffer(ioc, &newIndex)) == FAILED) { 347 if ((mptscsih_getFreeChainBuffer(ioc, &newIndex)) == FAILED) {
348 dfailprintk(ioc, printk(MYIOC_s_DEBUG_FMT 348 dfailprintk(ioc, printk(MYIOC_s_DEBUG_FMT
349 "getFreeChainBuffer FAILED SCSI cmd=%02x (%p)\n", 349 "getFreeChainBuffer FAILED SCSI cmd=%02x (%p)\n",
350 ioc->name, pReq->CDB[0], SCpnt)); 350 ioc->name, pReq->CDB[0], SCpnt));
351 return FAILED; 351 return FAILED;
352 } 352 }
353 353
354 /* Update the tracking arrays. 354 /* Update the tracking arrays.
355 * If chainSge == NULL, update ReqToChain, else ChainToChain 355 * If chainSge == NULL, update ReqToChain, else ChainToChain
356 */ 356 */
357 if (chainSge) { 357 if (chainSge) {
358 ioc->ChainToChain[chain_idx] = newIndex; 358 ioc->ChainToChain[chain_idx] = newIndex;
359 } else { 359 } else {
360 ioc->ReqToChain[req_idx] = newIndex; 360 ioc->ReqToChain[req_idx] = newIndex;
361 } 361 }
362 chain_idx = newIndex; 362 chain_idx = newIndex;
363 chain_dma_off = ioc->req_sz * chain_idx; 363 chain_dma_off = ioc->req_sz * chain_idx;
364 364
365 /* Populate the chainSGE for the current buffer. 365 /* Populate the chainSGE for the current buffer.
366 * - Set chain buffer pointer to psge and fill 366 * - Set chain buffer pointer to psge and fill
367 * out the Address and Flags fields. 367 * out the Address and Flags fields.
368 */ 368 */
369 chainSge = (char *) psge; 369 chainSge = (char *) psge;
370 dsgprintk(ioc, printk(MYIOC_s_DEBUG_FMT " Current buff @ %p (index 0x%x)", 370 dsgprintk(ioc, printk(MYIOC_s_DEBUG_FMT " Current buff @ %p (index 0x%x)",
371 ioc->name, psge, req_idx)); 371 ioc->name, psge, req_idx));
372 372
373 /* Start the SGE for the next buffer 373 /* Start the SGE for the next buffer
374 */ 374 */
375 psge = (char *) (ioc->ChainBuffer + chain_dma_off); 375 psge = (char *) (ioc->ChainBuffer + chain_dma_off);
376 sgeOffset = 0; 376 sgeOffset = 0;
377 sg_done = 0; 377 sg_done = 0;
378 378
379 dsgprintk(ioc, printk(MYIOC_s_DEBUG_FMT " Chain buff @ %p (index 0x%x)\n", 379 dsgprintk(ioc, printk(MYIOC_s_DEBUG_FMT " Chain buff @ %p (index 0x%x)\n",
380 ioc->name, psge, chain_idx)); 380 ioc->name, psge, chain_idx));
381 381
382 /* Start the SGE for the next buffer 382 /* Start the SGE for the next buffer
383 */ 383 */
384 384
385 goto nextSGEset; 385 goto nextSGEset;
386 } 386 }
387 387
388 return SUCCESS; 388 return SUCCESS;
389 } /* mptscsih_AddSGE() */ 389 } /* mptscsih_AddSGE() */
390 390
391 static void 391 static void
392 mptscsih_issue_sep_command(MPT_ADAPTER *ioc, VirtTarget *vtarget, 392 mptscsih_issue_sep_command(MPT_ADAPTER *ioc, VirtTarget *vtarget,
393 U32 SlotStatus) 393 U32 SlotStatus)
394 { 394 {
395 MPT_FRAME_HDR *mf; 395 MPT_FRAME_HDR *mf;
396 SEPRequest_t *SEPMsg; 396 SEPRequest_t *SEPMsg;
397 397
398 if (ioc->bus_type != SAS) 398 if (ioc->bus_type != SAS)
399 return; 399 return;
400 400
401 /* Not supported for hidden raid components 401 /* Not supported for hidden raid components
402 */ 402 */
403 if (vtarget->tflags & MPT_TARGET_FLAGS_RAID_COMPONENT) 403 if (vtarget->tflags & MPT_TARGET_FLAGS_RAID_COMPONENT)
404 return; 404 return;
405 405
406 if ((mf = mpt_get_msg_frame(ioc->InternalCtx, ioc)) == NULL) { 406 if ((mf = mpt_get_msg_frame(ioc->InternalCtx, ioc)) == NULL) {
407 dfailprintk(ioc, printk(MYIOC_s_WARN_FMT "%s: no msg frames!!\n", 407 dfailprintk(ioc, printk(MYIOC_s_WARN_FMT "%s: no msg frames!!\n",
408 ioc->name,__func__)); 408 ioc->name,__func__));
409 return; 409 return;
410 } 410 }
411 411
412 SEPMsg = (SEPRequest_t *)mf; 412 SEPMsg = (SEPRequest_t *)mf;
413 SEPMsg->Function = MPI_FUNCTION_SCSI_ENCLOSURE_PROCESSOR; 413 SEPMsg->Function = MPI_FUNCTION_SCSI_ENCLOSURE_PROCESSOR;
414 SEPMsg->Bus = vtarget->channel; 414 SEPMsg->Bus = vtarget->channel;
415 SEPMsg->TargetID = vtarget->id; 415 SEPMsg->TargetID = vtarget->id;
416 SEPMsg->Action = MPI_SEP_REQ_ACTION_WRITE_STATUS; 416 SEPMsg->Action = MPI_SEP_REQ_ACTION_WRITE_STATUS;
417 SEPMsg->SlotStatus = SlotStatus; 417 SEPMsg->SlotStatus = SlotStatus;
418 devtverboseprintk(ioc, printk(MYIOC_s_DEBUG_FMT 418 devtverboseprintk(ioc, printk(MYIOC_s_DEBUG_FMT
419 "Sending SEP cmd=%x channel=%d id=%d\n", 419 "Sending SEP cmd=%x channel=%d id=%d\n",
420 ioc->name, SlotStatus, SEPMsg->Bus, SEPMsg->TargetID)); 420 ioc->name, SlotStatus, SEPMsg->Bus, SEPMsg->TargetID));
421 mpt_put_msg_frame(ioc->DoneCtx, ioc, mf); 421 mpt_put_msg_frame(ioc->DoneCtx, ioc, mf);
422 } 422 }
423 423
424 #ifdef CONFIG_FUSION_LOGGING 424 #ifdef CONFIG_FUSION_LOGGING
425 /** 425 /**
426 * mptscsih_info_scsiio - debug print info on reply frame 426 * mptscsih_info_scsiio - debug print info on reply frame
427 * @ioc: Pointer to MPT_ADAPTER structure 427 * @ioc: Pointer to MPT_ADAPTER structure
428 * @sc: original scsi cmnd pointer 428 * @sc: original scsi cmnd pointer
429 * @pScsiReply: Pointer to MPT reply frame 429 * @pScsiReply: Pointer to MPT reply frame
430 * 430 *
431 * MPT_DEBUG_REPLY needs to be enabled to obtain this info 431 * MPT_DEBUG_REPLY needs to be enabled to obtain this info
432 * 432 *
433 * Refer to lsi/mpi.h. 433 * Refer to lsi/mpi.h.
434 **/ 434 **/
435 static void 435 static void
436 mptscsih_info_scsiio(MPT_ADAPTER *ioc, struct scsi_cmnd *sc, SCSIIOReply_t * pScsiReply) 436 mptscsih_info_scsiio(MPT_ADAPTER *ioc, struct scsi_cmnd *sc, SCSIIOReply_t * pScsiReply)
437 { 437 {
438 char *desc = NULL; 438 char *desc = NULL;
439 char *desc1 = NULL; 439 char *desc1 = NULL;
440 u16 ioc_status; 440 u16 ioc_status;
441 u8 skey, asc, ascq; 441 u8 skey, asc, ascq;
442 442
443 ioc_status = le16_to_cpu(pScsiReply->IOCStatus) & MPI_IOCSTATUS_MASK; 443 ioc_status = le16_to_cpu(pScsiReply->IOCStatus) & MPI_IOCSTATUS_MASK;
444 444
445 switch (ioc_status) { 445 switch (ioc_status) {
446 446
447 case MPI_IOCSTATUS_SUCCESS: 447 case MPI_IOCSTATUS_SUCCESS:
448 desc = "success"; 448 desc = "success";
449 break; 449 break;
450 case MPI_IOCSTATUS_SCSI_INVALID_BUS: 450 case MPI_IOCSTATUS_SCSI_INVALID_BUS:
451 desc = "invalid bus"; 451 desc = "invalid bus";
452 break; 452 break;
453 case MPI_IOCSTATUS_SCSI_INVALID_TARGETID: 453 case MPI_IOCSTATUS_SCSI_INVALID_TARGETID:
454 desc = "invalid target_id"; 454 desc = "invalid target_id";
455 break; 455 break;
456 case MPI_IOCSTATUS_SCSI_DEVICE_NOT_THERE: 456 case MPI_IOCSTATUS_SCSI_DEVICE_NOT_THERE:
457 desc = "device not there"; 457 desc = "device not there";
458 break; 458 break;
459 case MPI_IOCSTATUS_SCSI_DATA_OVERRUN: 459 case MPI_IOCSTATUS_SCSI_DATA_OVERRUN:
460 desc = "data overrun"; 460 desc = "data overrun";
461 break; 461 break;
462 case MPI_IOCSTATUS_SCSI_DATA_UNDERRUN: 462 case MPI_IOCSTATUS_SCSI_DATA_UNDERRUN:
463 desc = "data underrun"; 463 desc = "data underrun";
464 break; 464 break;
465 case MPI_IOCSTATUS_SCSI_IO_DATA_ERROR: 465 case MPI_IOCSTATUS_SCSI_IO_DATA_ERROR:
466 desc = "I/O data error"; 466 desc = "I/O data error";
467 break; 467 break;
468 case MPI_IOCSTATUS_SCSI_PROTOCOL_ERROR: 468 case MPI_IOCSTATUS_SCSI_PROTOCOL_ERROR:
469 desc = "protocol error"; 469 desc = "protocol error";
470 break; 470 break;
471 case MPI_IOCSTATUS_SCSI_TASK_TERMINATED: 471 case MPI_IOCSTATUS_SCSI_TASK_TERMINATED:
472 desc = "task terminated"; 472 desc = "task terminated";
473 break; 473 break;
474 case MPI_IOCSTATUS_SCSI_RESIDUAL_MISMATCH: 474 case MPI_IOCSTATUS_SCSI_RESIDUAL_MISMATCH:
475 desc = "residual mismatch"; 475 desc = "residual mismatch";
476 break; 476 break;
477 case MPI_IOCSTATUS_SCSI_TASK_MGMT_FAILED: 477 case MPI_IOCSTATUS_SCSI_TASK_MGMT_FAILED:
478 desc = "task management failed"; 478 desc = "task management failed";
479 break; 479 break;
480 case MPI_IOCSTATUS_SCSI_IOC_TERMINATED: 480 case MPI_IOCSTATUS_SCSI_IOC_TERMINATED:
481 desc = "IOC terminated"; 481 desc = "IOC terminated";
482 break; 482 break;
483 case MPI_IOCSTATUS_SCSI_EXT_TERMINATED: 483 case MPI_IOCSTATUS_SCSI_EXT_TERMINATED:
484 desc = "ext terminated"; 484 desc = "ext terminated";
485 break; 485 break;
486 default: 486 default:
487 desc = ""; 487 desc = "";
488 break; 488 break;
489 } 489 }
490 490
491 switch (pScsiReply->SCSIStatus) 491 switch (pScsiReply->SCSIStatus)
492 { 492 {
493 493
494 case MPI_SCSI_STATUS_SUCCESS: 494 case MPI_SCSI_STATUS_SUCCESS:
495 desc1 = "success"; 495 desc1 = "success";
496 break; 496 break;
497 case MPI_SCSI_STATUS_CHECK_CONDITION: 497 case MPI_SCSI_STATUS_CHECK_CONDITION:
498 desc1 = "check condition"; 498 desc1 = "check condition";
499 break; 499 break;
500 case MPI_SCSI_STATUS_CONDITION_MET: 500 case MPI_SCSI_STATUS_CONDITION_MET:
501 desc1 = "condition met"; 501 desc1 = "condition met";
502 break; 502 break;
503 case MPI_SCSI_STATUS_BUSY: 503 case MPI_SCSI_STATUS_BUSY:
504 desc1 = "busy"; 504 desc1 = "busy";
505 break; 505 break;
506 case MPI_SCSI_STATUS_INTERMEDIATE: 506 case MPI_SCSI_STATUS_INTERMEDIATE:
507 desc1 = "intermediate"; 507 desc1 = "intermediate";
508 break; 508 break;
509 case MPI_SCSI_STATUS_INTERMEDIATE_CONDMET: 509 case MPI_SCSI_STATUS_INTERMEDIATE_CONDMET:
510 desc1 = "intermediate condmet"; 510 desc1 = "intermediate condmet";
511 break; 511 break;
512 case MPI_SCSI_STATUS_RESERVATION_CONFLICT: 512 case MPI_SCSI_STATUS_RESERVATION_CONFLICT:
513 desc1 = "reservation conflict"; 513 desc1 = "reservation conflict";
514 break; 514 break;
515 case MPI_SCSI_STATUS_COMMAND_TERMINATED: 515 case MPI_SCSI_STATUS_COMMAND_TERMINATED:
516 desc1 = "command terminated"; 516 desc1 = "command terminated";
517 break; 517 break;
518 case MPI_SCSI_STATUS_TASK_SET_FULL: 518 case MPI_SCSI_STATUS_TASK_SET_FULL:
519 desc1 = "task set full"; 519 desc1 = "task set full";
520 break; 520 break;
521 case MPI_SCSI_STATUS_ACA_ACTIVE: 521 case MPI_SCSI_STATUS_ACA_ACTIVE:
522 desc1 = "aca active"; 522 desc1 = "aca active";
523 break; 523 break;
524 case MPI_SCSI_STATUS_FCPEXT_DEVICE_LOGGED_OUT: 524 case MPI_SCSI_STATUS_FCPEXT_DEVICE_LOGGED_OUT:
525 desc1 = "fcpext device logged out"; 525 desc1 = "fcpext device logged out";
526 break; 526 break;
527 case MPI_SCSI_STATUS_FCPEXT_NO_LINK: 527 case MPI_SCSI_STATUS_FCPEXT_NO_LINK:
528 desc1 = "fcpext no link"; 528 desc1 = "fcpext no link";
529 break; 529 break;
530 case MPI_SCSI_STATUS_FCPEXT_UNASSIGNED: 530 case MPI_SCSI_STATUS_FCPEXT_UNASSIGNED:
531 desc1 = "fcpext unassigned"; 531 desc1 = "fcpext unassigned";
532 break; 532 break;
533 default: 533 default:
534 desc1 = ""; 534 desc1 = "";
535 break; 535 break;
536 } 536 }
537 537
538 scsi_print_command(sc); 538 scsi_print_command(sc);
539 printk(MYIOC_s_DEBUG_FMT "\tfw_channel = %d, fw_id = %d, lun = %d\n", 539 printk(MYIOC_s_DEBUG_FMT "\tfw_channel = %d, fw_id = %d, lun = %d\n",
540 ioc->name, pScsiReply->Bus, pScsiReply->TargetID, sc->device->lun); 540 ioc->name, pScsiReply->Bus, pScsiReply->TargetID, sc->device->lun);
541 printk(MYIOC_s_DEBUG_FMT "\trequest_len = %d, underflow = %d, " 541 printk(MYIOC_s_DEBUG_FMT "\trequest_len = %d, underflow = %d, "
542 "resid = %d\n", ioc->name, scsi_bufflen(sc), sc->underflow, 542 "resid = %d\n", ioc->name, scsi_bufflen(sc), sc->underflow,
543 scsi_get_resid(sc)); 543 scsi_get_resid(sc));
544 printk(MYIOC_s_DEBUG_FMT "\ttag = %d, transfer_count = %d, " 544 printk(MYIOC_s_DEBUG_FMT "\ttag = %d, transfer_count = %d, "
545 "sc->result = %08X\n", ioc->name, le16_to_cpu(pScsiReply->TaskTag), 545 "sc->result = %08X\n", ioc->name, le16_to_cpu(pScsiReply->TaskTag),
546 le32_to_cpu(pScsiReply->TransferCount), sc->result); 546 le32_to_cpu(pScsiReply->TransferCount), sc->result);
547 547
548 printk(MYIOC_s_DEBUG_FMT "\tiocstatus = %s (0x%04x), " 548 printk(MYIOC_s_DEBUG_FMT "\tiocstatus = %s (0x%04x), "
549 "scsi_status = %s (0x%02x), scsi_state = (0x%02x)\n", 549 "scsi_status = %s (0x%02x), scsi_state = (0x%02x)\n",
550 ioc->name, desc, ioc_status, desc1, pScsiReply->SCSIStatus, 550 ioc->name, desc, ioc_status, desc1, pScsiReply->SCSIStatus,
551 pScsiReply->SCSIState); 551 pScsiReply->SCSIState);
552 552
553 if (pScsiReply->SCSIState & MPI_SCSI_STATE_AUTOSENSE_VALID) { 553 if (pScsiReply->SCSIState & MPI_SCSI_STATE_AUTOSENSE_VALID) {
554 skey = sc->sense_buffer[2] & 0x0F; 554 skey = sc->sense_buffer[2] & 0x0F;
555 asc = sc->sense_buffer[12]; 555 asc = sc->sense_buffer[12];
556 ascq = sc->sense_buffer[13]; 556 ascq = sc->sense_buffer[13];
557 557
558 printk(MYIOC_s_DEBUG_FMT "\t[sense_key,asc,ascq]: " 558 printk(MYIOC_s_DEBUG_FMT "\t[sense_key,asc,ascq]: "
559 "[0x%02x,0x%02x,0x%02x]\n", ioc->name, skey, asc, ascq); 559 "[0x%02x,0x%02x,0x%02x]\n", ioc->name, skey, asc, ascq);
560 } 560 }
561 561
562 /* 562 /*
563 * Look for + dump FCP ResponseInfo[]! 563 * Look for + dump FCP ResponseInfo[]!
564 */ 564 */
565 if (pScsiReply->SCSIState & MPI_SCSI_STATE_RESPONSE_INFO_VALID && 565 if (pScsiReply->SCSIState & MPI_SCSI_STATE_RESPONSE_INFO_VALID &&
566 pScsiReply->ResponseInfo) 566 pScsiReply->ResponseInfo)
567 printk(MYIOC_s_DEBUG_FMT "response_info = %08xh\n", 567 printk(MYIOC_s_DEBUG_FMT "response_info = %08xh\n",
568 ioc->name, le32_to_cpu(pScsiReply->ResponseInfo)); 568 ioc->name, le32_to_cpu(pScsiReply->ResponseInfo));
569 } 569 }
570 #endif 570 #endif
571 571
572 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/ 572 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
573 /* 573 /*
574 * mptscsih_io_done - Main SCSI IO callback routine registered to 574 * mptscsih_io_done - Main SCSI IO callback routine registered to
575 * Fusion MPT (base) driver 575 * Fusion MPT (base) driver
576 * @ioc: Pointer to MPT_ADAPTER structure 576 * @ioc: Pointer to MPT_ADAPTER structure
577 * @mf: Pointer to original MPT request frame 577 * @mf: Pointer to original MPT request frame
578 * @r: Pointer to MPT reply frame (NULL if TurboReply) 578 * @r: Pointer to MPT reply frame (NULL if TurboReply)
579 * 579 *
580 * This routine is called from mpt.c::mpt_interrupt() at the completion 580 * This routine is called from mpt.c::mpt_interrupt() at the completion
581 * of any SCSI IO request. 581 * of any SCSI IO request.
582 * This routine is registered with the Fusion MPT (base) driver at driver 582 * This routine is registered with the Fusion MPT (base) driver at driver
583 * load/init time via the mpt_register() API call. 583 * load/init time via the mpt_register() API call.
584 * 584 *
585 * Returns 1 indicating alloc'd request frame ptr should be freed. 585 * Returns 1 indicating alloc'd request frame ptr should be freed.
586 */ 586 */
587 int 587 int
588 mptscsih_io_done(MPT_ADAPTER *ioc, MPT_FRAME_HDR *mf, MPT_FRAME_HDR *mr) 588 mptscsih_io_done(MPT_ADAPTER *ioc, MPT_FRAME_HDR *mf, MPT_FRAME_HDR *mr)
589 { 589 {
590 struct scsi_cmnd *sc; 590 struct scsi_cmnd *sc;
591 MPT_SCSI_HOST *hd; 591 MPT_SCSI_HOST *hd;
592 SCSIIORequest_t *pScsiReq; 592 SCSIIORequest_t *pScsiReq;
593 SCSIIOReply_t *pScsiReply; 593 SCSIIOReply_t *pScsiReply;
594 u16 req_idx, req_idx_MR; 594 u16 req_idx, req_idx_MR;
595 VirtDevice *vdevice; 595 VirtDevice *vdevice;
596 VirtTarget *vtarget; 596 VirtTarget *vtarget;
597 597
598 hd = shost_priv(ioc->sh); 598 hd = shost_priv(ioc->sh);
599 req_idx = le16_to_cpu(mf->u.frame.hwhdr.msgctxu.fld.req_idx); 599 req_idx = le16_to_cpu(mf->u.frame.hwhdr.msgctxu.fld.req_idx);
600 req_idx_MR = (mr != NULL) ? 600 req_idx_MR = (mr != NULL) ?
601 le16_to_cpu(mr->u.frame.hwhdr.msgctxu.fld.req_idx) : req_idx; 601 le16_to_cpu(mr->u.frame.hwhdr.msgctxu.fld.req_idx) : req_idx;
602 602
603 /* Special case, where already freed message frame is received from 603 /* Special case, where already freed message frame is received from
604 * Firmware. It happens with Resetting IOC. 604 * Firmware. It happens with Resetting IOC.
605 * Return immediately. Do not care 605 * Return immediately. Do not care
606 */ 606 */
607 if ((req_idx != req_idx_MR) || 607 if ((req_idx != req_idx_MR) ||
608 (le32_to_cpu(mf->u.frame.linkage.arg1) == 0xdeadbeaf)) 608 (le32_to_cpu(mf->u.frame.linkage.arg1) == 0xdeadbeaf))
609 return 0; 609 return 0;
610 610
611 sc = mptscsih_getclear_scsi_lookup(ioc, req_idx); 611 sc = mptscsih_getclear_scsi_lookup(ioc, req_idx);
612 if (sc == NULL) { 612 if (sc == NULL) {
613 MPIHeader_t *hdr = (MPIHeader_t *)mf; 613 MPIHeader_t *hdr = (MPIHeader_t *)mf;
614 614
615 /* Remark: writeSDP1 will use the ScsiDoneCtx 615 /* Remark: writeSDP1 will use the ScsiDoneCtx
616 * If a SCSI I/O cmd, device disabled by OS and 616 * If a SCSI I/O cmd, device disabled by OS and
617 * completion done. Cannot touch sc struct. Just free mem. 617 * completion done. Cannot touch sc struct. Just free mem.
618 */ 618 */
619 if (hdr->Function == MPI_FUNCTION_SCSI_IO_REQUEST) 619 if (hdr->Function == MPI_FUNCTION_SCSI_IO_REQUEST)
620 printk(MYIOC_s_ERR_FMT "NULL ScsiCmd ptr!\n", 620 printk(MYIOC_s_ERR_FMT "NULL ScsiCmd ptr!\n",
621 ioc->name); 621 ioc->name);
622 622
623 mptscsih_freeChainBuffers(ioc, req_idx); 623 mptscsih_freeChainBuffers(ioc, req_idx);
624 return 1; 624 return 1;
625 } 625 }
626 626
627 if ((unsigned char *)mf != sc->host_scribble) { 627 if ((unsigned char *)mf != sc->host_scribble) {
628 mptscsih_freeChainBuffers(ioc, req_idx); 628 mptscsih_freeChainBuffers(ioc, req_idx);
629 return 1; 629 return 1;
630 } 630 }
631 631
632 if (ioc->bus_type == SAS) { 632 if (ioc->bus_type == SAS) {
633 VirtDevice *vdevice = sc->device->hostdata; 633 VirtDevice *vdevice = sc->device->hostdata;
634 634
635 if (!vdevice || !vdevice->vtarget || 635 if (!vdevice || !vdevice->vtarget ||
636 vdevice->vtarget->deleted) { 636 vdevice->vtarget->deleted) {
637 sc->result = DID_NO_CONNECT << 16; 637 sc->result = DID_NO_CONNECT << 16;
638 goto out; 638 goto out;
639 } 639 }
640 } 640 }
641 641
642 sc->host_scribble = NULL; 642 sc->host_scribble = NULL;
643 sc->result = DID_OK << 16; /* Set default reply as OK */ 643 sc->result = DID_OK << 16; /* Set default reply as OK */
644 pScsiReq = (SCSIIORequest_t *) mf; 644 pScsiReq = (SCSIIORequest_t *) mf;
645 pScsiReply = (SCSIIOReply_t *) mr; 645 pScsiReply = (SCSIIOReply_t *) mr;
646 646
647 if((ioc->facts.MsgVersion >= MPI_VERSION_01_05) && pScsiReply){ 647 if((ioc->facts.MsgVersion >= MPI_VERSION_01_05) && pScsiReply){
648 dmfprintk(ioc, printk(MYIOC_s_DEBUG_FMT 648 dmfprintk(ioc, printk(MYIOC_s_DEBUG_FMT
649 "ScsiDone (mf=%p,mr=%p,sc=%p,idx=%d,task-tag=%d)\n", 649 "ScsiDone (mf=%p,mr=%p,sc=%p,idx=%d,task-tag=%d)\n",
650 ioc->name, mf, mr, sc, req_idx, pScsiReply->TaskTag)); 650 ioc->name, mf, mr, sc, req_idx, pScsiReply->TaskTag));
651 }else{ 651 }else{
652 dmfprintk(ioc, printk(MYIOC_s_DEBUG_FMT 652 dmfprintk(ioc, printk(MYIOC_s_DEBUG_FMT
653 "ScsiDone (mf=%p,mr=%p,sc=%p,idx=%d)\n", 653 "ScsiDone (mf=%p,mr=%p,sc=%p,idx=%d)\n",
654 ioc->name, mf, mr, sc, req_idx)); 654 ioc->name, mf, mr, sc, req_idx));
655 } 655 }
656 656
657 if (pScsiReply == NULL) { 657 if (pScsiReply == NULL) {
658 /* special context reply handling */ 658 /* special context reply handling */
659 ; 659 ;
660 } else { 660 } else {
661 u32 xfer_cnt; 661 u32 xfer_cnt;
662 u16 status; 662 u16 status;
663 u8 scsi_state, scsi_status; 663 u8 scsi_state, scsi_status;
664 u32 log_info; 664 u32 log_info;
665 665
666 status = le16_to_cpu(pScsiReply->IOCStatus) & MPI_IOCSTATUS_MASK; 666 status = le16_to_cpu(pScsiReply->IOCStatus) & MPI_IOCSTATUS_MASK;
667 667
668 scsi_state = pScsiReply->SCSIState; 668 scsi_state = pScsiReply->SCSIState;
669 scsi_status = pScsiReply->SCSIStatus; 669 scsi_status = pScsiReply->SCSIStatus;
670 xfer_cnt = le32_to_cpu(pScsiReply->TransferCount); 670 xfer_cnt = le32_to_cpu(pScsiReply->TransferCount);
671 scsi_set_resid(sc, scsi_bufflen(sc) - xfer_cnt); 671 scsi_set_resid(sc, scsi_bufflen(sc) - xfer_cnt);
672 log_info = le32_to_cpu(pScsiReply->IOCLogInfo); 672 log_info = le32_to_cpu(pScsiReply->IOCLogInfo);
673 673
674 /* 674 /*
675 * if we get a data underrun indication, yet no data was 675 * if we get a data underrun indication, yet no data was
676 * transferred and the SCSI status indicates that the 676 * transferred and the SCSI status indicates that the
677 * command was never started, change the data underrun 677 * command was never started, change the data underrun
678 * to success 678 * to success
679 */ 679 */
680 if (status == MPI_IOCSTATUS_SCSI_DATA_UNDERRUN && xfer_cnt == 0 && 680 if (status == MPI_IOCSTATUS_SCSI_DATA_UNDERRUN && xfer_cnt == 0 &&
681 (scsi_status == MPI_SCSI_STATUS_BUSY || 681 (scsi_status == MPI_SCSI_STATUS_BUSY ||
682 scsi_status == MPI_SCSI_STATUS_RESERVATION_CONFLICT || 682 scsi_status == MPI_SCSI_STATUS_RESERVATION_CONFLICT ||
683 scsi_status == MPI_SCSI_STATUS_TASK_SET_FULL)) { 683 scsi_status == MPI_SCSI_STATUS_TASK_SET_FULL)) {
684 status = MPI_IOCSTATUS_SUCCESS; 684 status = MPI_IOCSTATUS_SUCCESS;
685 } 685 }
686 686
687 if (scsi_state & MPI_SCSI_STATE_AUTOSENSE_VALID) 687 if (scsi_state & MPI_SCSI_STATE_AUTOSENSE_VALID)
688 mptscsih_copy_sense_data(sc, hd, mf, pScsiReply); 688 mptscsih_copy_sense_data(sc, hd, mf, pScsiReply);
689 689
690 /* 690 /*
691 * Look for + dump FCP ResponseInfo[]! 691 * Look for + dump FCP ResponseInfo[]!
692 */ 692 */
693 if (scsi_state & MPI_SCSI_STATE_RESPONSE_INFO_VALID && 693 if (scsi_state & MPI_SCSI_STATE_RESPONSE_INFO_VALID &&
694 pScsiReply->ResponseInfo) { 694 pScsiReply->ResponseInfo) {
695 printk(MYIOC_s_NOTE_FMT "[%d:%d:%d:%d] " 695 printk(MYIOC_s_NOTE_FMT "[%d:%d:%d:%d] "
696 "FCP_ResponseInfo=%08xh\n", ioc->name, 696 "FCP_ResponseInfo=%08xh\n", ioc->name,
697 sc->device->host->host_no, sc->device->channel, 697 sc->device->host->host_no, sc->device->channel,
698 sc->device->id, sc->device->lun, 698 sc->device->id, sc->device->lun,
699 le32_to_cpu(pScsiReply->ResponseInfo)); 699 le32_to_cpu(pScsiReply->ResponseInfo));
700 } 700 }
701 701
702 switch(status) { 702 switch(status) {
703 case MPI_IOCSTATUS_BUSY: /* 0x0002 */ 703 case MPI_IOCSTATUS_BUSY: /* 0x0002 */
704 case MPI_IOCSTATUS_INSUFFICIENT_RESOURCES: /* 0x0006 */ 704 case MPI_IOCSTATUS_INSUFFICIENT_RESOURCES: /* 0x0006 */
705 /* CHECKME! 705 /* CHECKME!
706 * Maybe: DRIVER_BUSY | SUGGEST_RETRY | DID_SOFT_ERROR (retry) 706 * Maybe: DRIVER_BUSY | SUGGEST_RETRY | DID_SOFT_ERROR (retry)
707 * But not: DID_BUS_BUSY lest one risk 707 * But not: DID_BUS_BUSY lest one risk
708 * killing interrupt handler:-( 708 * killing interrupt handler:-(
709 */ 709 */
710 sc->result = SAM_STAT_BUSY; 710 sc->result = SAM_STAT_BUSY;
711 break; 711 break;
712 712
713 case MPI_IOCSTATUS_SCSI_INVALID_BUS: /* 0x0041 */ 713 case MPI_IOCSTATUS_SCSI_INVALID_BUS: /* 0x0041 */
714 case MPI_IOCSTATUS_SCSI_INVALID_TARGETID: /* 0x0042 */ 714 case MPI_IOCSTATUS_SCSI_INVALID_TARGETID: /* 0x0042 */
715 sc->result = DID_BAD_TARGET << 16; 715 sc->result = DID_BAD_TARGET << 16;
716 break; 716 break;
717 717
718 case MPI_IOCSTATUS_SCSI_DEVICE_NOT_THERE: /* 0x0043 */ 718 case MPI_IOCSTATUS_SCSI_DEVICE_NOT_THERE: /* 0x0043 */
719 /* Spoof to SCSI Selection Timeout! */ 719 /* Spoof to SCSI Selection Timeout! */
720 if (ioc->bus_type != FC) 720 if (ioc->bus_type != FC)
721 sc->result = DID_NO_CONNECT << 16; 721 sc->result = DID_NO_CONNECT << 16;
722 /* else fibre, just stall until rescan event */ 722 /* else fibre, just stall until rescan event */
723 else 723 else
724 sc->result = DID_REQUEUE << 16; 724 sc->result = DID_REQUEUE << 16;
725 725
726 if (hd->sel_timeout[pScsiReq->TargetID] < 0xFFFF) 726 if (hd->sel_timeout[pScsiReq->TargetID] < 0xFFFF)
727 hd->sel_timeout[pScsiReq->TargetID]++; 727 hd->sel_timeout[pScsiReq->TargetID]++;
728 728
729 vdevice = sc->device->hostdata; 729 vdevice = sc->device->hostdata;
730 if (!vdevice) 730 if (!vdevice)
731 break; 731 break;
732 vtarget = vdevice->vtarget; 732 vtarget = vdevice->vtarget;
733 if (vtarget->tflags & MPT_TARGET_FLAGS_LED_ON) { 733 if (vtarget->tflags & MPT_TARGET_FLAGS_LED_ON) {
734 mptscsih_issue_sep_command(ioc, vtarget, 734 mptscsih_issue_sep_command(ioc, vtarget,
735 MPI_SEP_REQ_SLOTSTATUS_UNCONFIGURED); 735 MPI_SEP_REQ_SLOTSTATUS_UNCONFIGURED);
736 vtarget->tflags &= ~MPT_TARGET_FLAGS_LED_ON; 736 vtarget->tflags &= ~MPT_TARGET_FLAGS_LED_ON;
737 } 737 }
738 break; 738 break;
739 739
740 case MPI_IOCSTATUS_SCSI_IOC_TERMINATED: /* 0x004B */ 740 case MPI_IOCSTATUS_SCSI_IOC_TERMINATED: /* 0x004B */
741 if ( ioc->bus_type == SAS ) { 741 if ( ioc->bus_type == SAS ) {
742 u16 ioc_status = 742 u16 ioc_status =
743 le16_to_cpu(pScsiReply->IOCStatus); 743 le16_to_cpu(pScsiReply->IOCStatus);
744 if ((ioc_status & 744 if ((ioc_status &
745 MPI_IOCSTATUS_FLAG_LOG_INFO_AVAILABLE) 745 MPI_IOCSTATUS_FLAG_LOG_INFO_AVAILABLE)
746 && 746 &&
747 ((log_info & SAS_LOGINFO_MASK) == 747 ((log_info & SAS_LOGINFO_MASK) ==
748 SAS_LOGINFO_NEXUS_LOSS)) { 748 SAS_LOGINFO_NEXUS_LOSS)) {
749 VirtDevice *vdevice = 749 VirtDevice *vdevice =
750 sc->device->hostdata; 750 sc->device->hostdata;
751 751
752 /* flag the device as being in 752 /* flag the device as being in
753 * device removal delay so we can 753 * device removal delay so we can
754 * notify the midlayer to hold off 754 * notify the midlayer to hold off
755 * on timeout eh */ 755 * on timeout eh */
756 if (vdevice && vdevice-> 756 if (vdevice && vdevice->
757 vtarget && 757 vtarget &&
758 vdevice->vtarget-> 758 vdevice->vtarget->
759 raidVolume) 759 raidVolume)
760 printk(KERN_INFO 760 printk(KERN_INFO
761 "Skipping Raid Volume" 761 "Skipping Raid Volume"
762 "for inDMD\n"); 762 "for inDMD\n");
763 else if (vdevice && 763 else if (vdevice &&
764 vdevice->vtarget) 764 vdevice->vtarget)
765 vdevice->vtarget-> 765 vdevice->vtarget->
766 inDMD = 1; 766 inDMD = 1;
767 767
768 sc->result = 768 sc->result =
769 (DID_TRANSPORT_DISRUPTED 769 (DID_TRANSPORT_DISRUPTED
770 << 16); 770 << 16);
771 break; 771 break;
772 } 772 }
773 } else if (ioc->bus_type == FC) { 773 } else if (ioc->bus_type == FC) {
774 /* 774 /*
775 * The FC IOC may kill a request for variety of 775 * The FC IOC may kill a request for variety of
776 * reasons, some of which may be recovered by a 776 * reasons, some of which may be recovered by a
777 * retry, some which are unlikely to be 777 * retry, some which are unlikely to be
778 * recovered. Return DID_ERROR instead of 778 * recovered. Return DID_ERROR instead of
779 * DID_RESET to permit retry of the command, 779 * DID_RESET to permit retry of the command,
780 * just not an infinite number of them 780 * just not an infinite number of them
781 */ 781 */
782 sc->result = DID_ERROR << 16; 782 sc->result = DID_ERROR << 16;
783 break; 783 break;
784 } 784 }
785 785
786 /* 786 /*
787 * Allow non-SAS & non-NEXUS_LOSS to drop into below code 787 * Allow non-SAS & non-NEXUS_LOSS to drop into below code
788 */ 788 */
789 789
790 case MPI_IOCSTATUS_SCSI_TASK_TERMINATED: /* 0x0048 */ 790 case MPI_IOCSTATUS_SCSI_TASK_TERMINATED: /* 0x0048 */
791 /* Linux handles an unsolicited DID_RESET better 791 /* Linux handles an unsolicited DID_RESET better
792 * than an unsolicited DID_ABORT. 792 * than an unsolicited DID_ABORT.
793 */ 793 */
794 sc->result = DID_RESET << 16; 794 sc->result = DID_RESET << 16;
795 break; 795 break;
796 796
797 case MPI_IOCSTATUS_SCSI_EXT_TERMINATED: /* 0x004C */ 797 case MPI_IOCSTATUS_SCSI_EXT_TERMINATED: /* 0x004C */
798 if (ioc->bus_type == FC) 798 if (ioc->bus_type == FC)
799 sc->result = DID_ERROR << 16; 799 sc->result = DID_ERROR << 16;
800 else 800 else
801 sc->result = DID_RESET << 16; 801 sc->result = DID_RESET << 16;
802 break; 802 break;
803 803
804 case MPI_IOCSTATUS_SCSI_RESIDUAL_MISMATCH: /* 0x0049 */ 804 case MPI_IOCSTATUS_SCSI_RESIDUAL_MISMATCH: /* 0x0049 */
805 scsi_set_resid(sc, scsi_bufflen(sc) - xfer_cnt); 805 scsi_set_resid(sc, scsi_bufflen(sc) - xfer_cnt);
806 if((xfer_cnt==0)||(sc->underflow > xfer_cnt)) 806 if((xfer_cnt==0)||(sc->underflow > xfer_cnt))
807 sc->result=DID_SOFT_ERROR << 16; 807 sc->result=DID_SOFT_ERROR << 16;
808 else /* Sufficient data transfer occurred */ 808 else /* Sufficient data transfer occurred */
809 sc->result = (DID_OK << 16) | scsi_status; 809 sc->result = (DID_OK << 16) | scsi_status;
810 dreplyprintk(ioc, printk(MYIOC_s_DEBUG_FMT 810 dreplyprintk(ioc, printk(MYIOC_s_DEBUG_FMT
811 "RESIDUAL_MISMATCH: result=%x on channel=%d id=%d\n", 811 "RESIDUAL_MISMATCH: result=%x on channel=%d id=%d\n",
812 ioc->name, sc->result, sc->device->channel, sc->device->id)); 812 ioc->name, sc->result, sc->device->channel, sc->device->id));
813 break; 813 break;
814 814
815 case MPI_IOCSTATUS_SCSI_DATA_UNDERRUN: /* 0x0045 */ 815 case MPI_IOCSTATUS_SCSI_DATA_UNDERRUN: /* 0x0045 */
816 /* 816 /*
817 * Do upfront check for valid SenseData and give it 817 * Do upfront check for valid SenseData and give it
818 * precedence! 818 * precedence!
819 */ 819 */
820 sc->result = (DID_OK << 16) | scsi_status; 820 sc->result = (DID_OK << 16) | scsi_status;
821 if (!(scsi_state & MPI_SCSI_STATE_AUTOSENSE_VALID)) { 821 if (!(scsi_state & MPI_SCSI_STATE_AUTOSENSE_VALID)) {
822 822
823 /* 823 /*
824 * For an Errata on LSI53C1030 824 * For an Errata on LSI53C1030
825 * When the length of request data 825 * When the length of request data
826 * and transfer data are different 826 * and transfer data are different
827 * with result of command (READ or VERIFY), 827 * with result of command (READ or VERIFY),
828 * DID_SOFT_ERROR is set. 828 * DID_SOFT_ERROR is set.
829 */ 829 */
830 if (ioc->bus_type == SPI) { 830 if (ioc->bus_type == SPI) {
831 if ((pScsiReq->CDB[0] == READ_6 && ((pScsiReq->CDB[1] & 0x02) == 0)) || 831 if ((pScsiReq->CDB[0] == READ_6 && ((pScsiReq->CDB[1] & 0x02) == 0)) ||
832 pScsiReq->CDB[0] == READ_10 || 832 pScsiReq->CDB[0] == READ_10 ||
833 pScsiReq->CDB[0] == READ_12 || 833 pScsiReq->CDB[0] == READ_12 ||
834 (pScsiReq->CDB[0] == READ_16 && 834 (pScsiReq->CDB[0] == READ_16 &&
835 ((pScsiReq->CDB[1] & 0x02) == 0)) || 835 ((pScsiReq->CDB[1] & 0x02) == 0)) ||
836 pScsiReq->CDB[0] == VERIFY || 836 pScsiReq->CDB[0] == VERIFY ||
837 pScsiReq->CDB[0] == VERIFY_16) { 837 pScsiReq->CDB[0] == VERIFY_16) {
838 if (scsi_bufflen(sc) != 838 if (scsi_bufflen(sc) !=
839 xfer_cnt) { 839 xfer_cnt) {
840 sc->result = 840 sc->result =
841 DID_SOFT_ERROR << 16; 841 DID_SOFT_ERROR << 16;
842 printk(KERN_WARNING "Errata" 842 printk(KERN_WARNING "Errata"
843 "on LSI53C1030 occurred." 843 "on LSI53C1030 occurred."
844 "sc->req_bufflen=0x%02x," 844 "sc->req_bufflen=0x%02x,"
845 "xfer_cnt=0x%02x\n", 845 "xfer_cnt=0x%02x\n",
846 scsi_bufflen(sc), 846 scsi_bufflen(sc),
847 xfer_cnt); 847 xfer_cnt);
848 } 848 }
849 } 849 }
850 } 850 }
851 851
852 if (xfer_cnt < sc->underflow) { 852 if (xfer_cnt < sc->underflow) {
853 if (scsi_status == SAM_STAT_BUSY) 853 if (scsi_status == SAM_STAT_BUSY)
854 sc->result = SAM_STAT_BUSY; 854 sc->result = SAM_STAT_BUSY;
855 else 855 else
856 sc->result = DID_SOFT_ERROR << 16; 856 sc->result = DID_SOFT_ERROR << 16;
857 } 857 }
858 if (scsi_state & (MPI_SCSI_STATE_AUTOSENSE_FAILED | MPI_SCSI_STATE_NO_SCSI_STATUS)) { 858 if (scsi_state & (MPI_SCSI_STATE_AUTOSENSE_FAILED | MPI_SCSI_STATE_NO_SCSI_STATUS)) {
859 /* What to do? 859 /* What to do?
860 */ 860 */
861 sc->result = DID_SOFT_ERROR << 16; 861 sc->result = DID_SOFT_ERROR << 16;
862 } 862 }
863 else if (scsi_state & MPI_SCSI_STATE_TERMINATED) { 863 else if (scsi_state & MPI_SCSI_STATE_TERMINATED) {
864 /* Not real sure here either... */ 864 /* Not real sure here either... */
865 sc->result = DID_RESET << 16; 865 sc->result = DID_RESET << 16;
866 } 866 }
867 } 867 }
868 868
869 869
870 dreplyprintk(ioc, printk(MYIOC_s_DEBUG_FMT 870 dreplyprintk(ioc, printk(MYIOC_s_DEBUG_FMT
871 " sc->underflow={report ERR if < %02xh bytes xfer'd}\n", 871 " sc->underflow={report ERR if < %02xh bytes xfer'd}\n",
872 ioc->name, sc->underflow)); 872 ioc->name, sc->underflow));
873 dreplyprintk(ioc, printk(MYIOC_s_DEBUG_FMT 873 dreplyprintk(ioc, printk(MYIOC_s_DEBUG_FMT
874 " ActBytesXferd=%02xh\n", ioc->name, xfer_cnt)); 874 " ActBytesXferd=%02xh\n", ioc->name, xfer_cnt));
875 875
876 /* Report Queue Full 876 /* Report Queue Full
877 */ 877 */
878 if (scsi_status == MPI_SCSI_STATUS_TASK_SET_FULL) 878 if (scsi_status == MPI_SCSI_STATUS_TASK_SET_FULL)
879 mptscsih_report_queue_full(sc, pScsiReply, pScsiReq); 879 mptscsih_report_queue_full(sc, pScsiReply, pScsiReq);
880 880
881 break; 881 break;
882 882
883 case MPI_IOCSTATUS_SCSI_DATA_OVERRUN: /* 0x0044 */ 883 case MPI_IOCSTATUS_SCSI_DATA_OVERRUN: /* 0x0044 */
884 scsi_set_resid(sc, 0); 884 scsi_set_resid(sc, 0);
885 case MPI_IOCSTATUS_SCSI_RECOVERED_ERROR: /* 0x0040 */ 885 case MPI_IOCSTATUS_SCSI_RECOVERED_ERROR: /* 0x0040 */
886 case MPI_IOCSTATUS_SUCCESS: /* 0x0000 */ 886 case MPI_IOCSTATUS_SUCCESS: /* 0x0000 */
887 sc->result = (DID_OK << 16) | scsi_status; 887 sc->result = (DID_OK << 16) | scsi_status;
888 if (scsi_state == 0) { 888 if (scsi_state == 0) {
889 ; 889 ;
890 } else if (scsi_state & 890 } else if (scsi_state &
891 MPI_SCSI_STATE_AUTOSENSE_VALID) { 891 MPI_SCSI_STATE_AUTOSENSE_VALID) {
892 892
893 /* 893 /*
894 * For potential trouble on LSI53C1030. 894 * For potential trouble on LSI53C1030.
895 * (date:2007.xx.) 895 * (date:2007.xx.)
896 * It is checked whether the length of 896 * It is checked whether the length of
897 * request data is equal to 897 * request data is equal to
898 * the length of transfer and residual. 898 * the length of transfer and residual.
899 * MEDIUM_ERROR is set by incorrect data. 899 * MEDIUM_ERROR is set by incorrect data.
900 */ 900 */
901 if ((ioc->bus_type == SPI) && 901 if ((ioc->bus_type == SPI) &&
902 (sc->sense_buffer[2] & 0x20)) { 902 (sc->sense_buffer[2] & 0x20)) {
903 u32 difftransfer; 903 u32 difftransfer;
904 difftransfer = 904 difftransfer =
905 sc->sense_buffer[3] << 24 | 905 sc->sense_buffer[3] << 24 |
906 sc->sense_buffer[4] << 16 | 906 sc->sense_buffer[4] << 16 |
907 sc->sense_buffer[5] << 8 | 907 sc->sense_buffer[5] << 8 |
908 sc->sense_buffer[6]; 908 sc->sense_buffer[6];
909 if (((sc->sense_buffer[3] & 0x80) == 909 if (((sc->sense_buffer[3] & 0x80) ==
910 0x80) && (scsi_bufflen(sc) 910 0x80) && (scsi_bufflen(sc)
911 != xfer_cnt)) { 911 != xfer_cnt)) {
912 sc->sense_buffer[2] = 912 sc->sense_buffer[2] =
913 MEDIUM_ERROR; 913 MEDIUM_ERROR;
914 sc->sense_buffer[12] = 0xff; 914 sc->sense_buffer[12] = 0xff;
915 sc->sense_buffer[13] = 0xff; 915 sc->sense_buffer[13] = 0xff;
916 printk(KERN_WARNING"Errata" 916 printk(KERN_WARNING"Errata"
917 "on LSI53C1030 occurred." 917 "on LSI53C1030 occurred."
918 "sc->req_bufflen=0x%02x," 918 "sc->req_bufflen=0x%02x,"
919 "xfer_cnt=0x%02x\n" , 919 "xfer_cnt=0x%02x\n" ,
920 scsi_bufflen(sc), 920 scsi_bufflen(sc),
921 xfer_cnt); 921 xfer_cnt);
922 } 922 }
923 if (((sc->sense_buffer[3] & 0x80) 923 if (((sc->sense_buffer[3] & 0x80)
924 != 0x80) && 924 != 0x80) &&
925 (scsi_bufflen(sc) != 925 (scsi_bufflen(sc) !=
926 xfer_cnt + difftransfer)) { 926 xfer_cnt + difftransfer)) {
927 sc->sense_buffer[2] = 927 sc->sense_buffer[2] =
928 MEDIUM_ERROR; 928 MEDIUM_ERROR;
929 sc->sense_buffer[12] = 0xff; 929 sc->sense_buffer[12] = 0xff;
930 sc->sense_buffer[13] = 0xff; 930 sc->sense_buffer[13] = 0xff;
931 printk(KERN_WARNING 931 printk(KERN_WARNING
932 "Errata on LSI53C1030 occurred" 932 "Errata on LSI53C1030 occurred"
933 "sc->req_bufflen=0x%02x," 933 "sc->req_bufflen=0x%02x,"
934 " xfer_cnt=0x%02x," 934 " xfer_cnt=0x%02x,"
935 "difftransfer=0x%02x\n", 935 "difftransfer=0x%02x\n",
936 scsi_bufflen(sc), 936 scsi_bufflen(sc),
937 xfer_cnt, 937 xfer_cnt,
938 difftransfer); 938 difftransfer);
939 } 939 }
940 } 940 }
941 941
942 /* 942 /*
943 * If running against circa 200003dd 909 MPT f/w, 943 * If running against circa 200003dd 909 MPT f/w,
944 * may get this (AUTOSENSE_VALID) for actual TASK_SET_FULL 944 * may get this (AUTOSENSE_VALID) for actual TASK_SET_FULL
945 * (QUEUE_FULL) returned from device! --> get 0x0000?128 945 * (QUEUE_FULL) returned from device! --> get 0x0000?128
946 * and with SenseBytes set to 0. 946 * and with SenseBytes set to 0.
947 */ 947 */
948 if (pScsiReply->SCSIStatus == MPI_SCSI_STATUS_TASK_SET_FULL) 948 if (pScsiReply->SCSIStatus == MPI_SCSI_STATUS_TASK_SET_FULL)
949 mptscsih_report_queue_full(sc, pScsiReply, pScsiReq); 949 mptscsih_report_queue_full(sc, pScsiReply, pScsiReq);
950 950
951 } 951 }
952 else if (scsi_state & 952 else if (scsi_state &
953 (MPI_SCSI_STATE_AUTOSENSE_FAILED | MPI_SCSI_STATE_NO_SCSI_STATUS) 953 (MPI_SCSI_STATE_AUTOSENSE_FAILED | MPI_SCSI_STATE_NO_SCSI_STATUS)
954 ) { 954 ) {
955 /* 955 /*
956 * What to do? 956 * What to do?
957 */ 957 */
958 sc->result = DID_SOFT_ERROR << 16; 958 sc->result = DID_SOFT_ERROR << 16;
959 } 959 }
960 else if (scsi_state & MPI_SCSI_STATE_TERMINATED) { 960 else if (scsi_state & MPI_SCSI_STATE_TERMINATED) {
961 /* Not real sure here either... */ 961 /* Not real sure here either... */
962 sc->result = DID_RESET << 16; 962 sc->result = DID_RESET << 16;
963 } 963 }
964 else if (scsi_state & MPI_SCSI_STATE_QUEUE_TAG_REJECTED) { 964 else if (scsi_state & MPI_SCSI_STATE_QUEUE_TAG_REJECTED) {
965 /* Device Inq. data indicates that it supports 965 /* Device Inq. data indicates that it supports
966 * QTags, but rejects QTag messages. 966 * QTags, but rejects QTag messages.
967 * This command completed OK. 967 * This command completed OK.
968 * 968 *
969 * Not real sure here either so do nothing... */ 969 * Not real sure here either so do nothing... */
970 } 970 }
971 971
972 if (sc->result == MPI_SCSI_STATUS_TASK_SET_FULL) 972 if (sc->result == MPI_SCSI_STATUS_TASK_SET_FULL)
973 mptscsih_report_queue_full(sc, pScsiReply, pScsiReq); 973 mptscsih_report_queue_full(sc, pScsiReply, pScsiReq);
974 974
975 /* Add handling of: 975 /* Add handling of:
976 * Reservation Conflict, Busy, 976 * Reservation Conflict, Busy,
977 * Command Terminated, CHECK 977 * Command Terminated, CHECK
978 */ 978 */
979 break; 979 break;
980 980
981 case MPI_IOCSTATUS_SCSI_PROTOCOL_ERROR: /* 0x0047 */ 981 case MPI_IOCSTATUS_SCSI_PROTOCOL_ERROR: /* 0x0047 */
982 sc->result = DID_SOFT_ERROR << 16; 982 sc->result = DID_SOFT_ERROR << 16;
983 break; 983 break;
984 984
985 case MPI_IOCSTATUS_INVALID_FUNCTION: /* 0x0001 */ 985 case MPI_IOCSTATUS_INVALID_FUNCTION: /* 0x0001 */
986 case MPI_IOCSTATUS_INVALID_SGL: /* 0x0003 */ 986 case MPI_IOCSTATUS_INVALID_SGL: /* 0x0003 */
987 case MPI_IOCSTATUS_INTERNAL_ERROR: /* 0x0004 */ 987 case MPI_IOCSTATUS_INTERNAL_ERROR: /* 0x0004 */
988 case MPI_IOCSTATUS_RESERVED: /* 0x0005 */ 988 case MPI_IOCSTATUS_RESERVED: /* 0x0005 */
989 case MPI_IOCSTATUS_INVALID_FIELD: /* 0x0007 */ 989 case MPI_IOCSTATUS_INVALID_FIELD: /* 0x0007 */
990 case MPI_IOCSTATUS_INVALID_STATE: /* 0x0008 */ 990 case MPI_IOCSTATUS_INVALID_STATE: /* 0x0008 */
991 case MPI_IOCSTATUS_SCSI_IO_DATA_ERROR: /* 0x0046 */ 991 case MPI_IOCSTATUS_SCSI_IO_DATA_ERROR: /* 0x0046 */
992 case MPI_IOCSTATUS_SCSI_TASK_MGMT_FAILED: /* 0x004A */ 992 case MPI_IOCSTATUS_SCSI_TASK_MGMT_FAILED: /* 0x004A */
993 default: 993 default:
994 /* 994 /*
995 * What to do? 995 * What to do?
996 */ 996 */
997 sc->result = DID_SOFT_ERROR << 16; 997 sc->result = DID_SOFT_ERROR << 16;
998 break; 998 break;
999 999
1000 } /* switch(status) */ 1000 } /* switch(status) */
1001 1001
1002 #ifdef CONFIG_FUSION_LOGGING 1002 #ifdef CONFIG_FUSION_LOGGING
1003 if (sc->result && (ioc->debug_level & MPT_DEBUG_REPLY)) 1003 if (sc->result && (ioc->debug_level & MPT_DEBUG_REPLY))
1004 mptscsih_info_scsiio(ioc, sc, pScsiReply); 1004 mptscsih_info_scsiio(ioc, sc, pScsiReply);
1005 #endif 1005 #endif
1006 1006
1007 } /* end of address reply case */ 1007 } /* end of address reply case */
1008 out: 1008 out:
1009 /* Unmap the DMA buffers, if any. */ 1009 /* Unmap the DMA buffers, if any. */
1010 scsi_dma_unmap(sc); 1010 scsi_dma_unmap(sc);
1011 1011
1012 sc->scsi_done(sc); /* Issue the command callback */ 1012 sc->scsi_done(sc); /* Issue the command callback */
1013 1013
1014 /* Free Chain buffers */ 1014 /* Free Chain buffers */
1015 mptscsih_freeChainBuffers(ioc, req_idx); 1015 mptscsih_freeChainBuffers(ioc, req_idx);
1016 return 1; 1016 return 1;
1017 } 1017 }
1018 1018
1019 /* 1019 /*
1020 * mptscsih_flush_running_cmds - For each command found, search 1020 * mptscsih_flush_running_cmds - For each command found, search
1021 * Scsi_Host instance taskQ and reply to OS. 1021 * Scsi_Host instance taskQ and reply to OS.
1022 * Called only if recovering from a FW reload. 1022 * Called only if recovering from a FW reload.
1023 * @hd: Pointer to a SCSI HOST structure 1023 * @hd: Pointer to a SCSI HOST structure
1024 * 1024 *
1025 * Returns: None. 1025 * Returns: None.
1026 * 1026 *
1027 * Must be called while new I/Os are being queued. 1027 * Must be called while new I/Os are being queued.
1028 */ 1028 */
1029 void 1029 void
1030 mptscsih_flush_running_cmds(MPT_SCSI_HOST *hd) 1030 mptscsih_flush_running_cmds(MPT_SCSI_HOST *hd)
1031 { 1031 {
1032 MPT_ADAPTER *ioc = hd->ioc; 1032 MPT_ADAPTER *ioc = hd->ioc;
1033 struct scsi_cmnd *sc; 1033 struct scsi_cmnd *sc;
1034 SCSIIORequest_t *mf = NULL; 1034 SCSIIORequest_t *mf = NULL;
1035 int ii; 1035 int ii;
1036 int channel, id; 1036 int channel, id;
1037 1037
1038 for (ii= 0; ii < ioc->req_depth; ii++) { 1038 for (ii= 0; ii < ioc->req_depth; ii++) {
1039 sc = mptscsih_getclear_scsi_lookup(ioc, ii); 1039 sc = mptscsih_getclear_scsi_lookup(ioc, ii);
1040 if (!sc) 1040 if (!sc)
1041 continue; 1041 continue;
1042 mf = (SCSIIORequest_t *)MPT_INDEX_2_MFPTR(ioc, ii); 1042 mf = (SCSIIORequest_t *)MPT_INDEX_2_MFPTR(ioc, ii);
1043 if (!mf) 1043 if (!mf)
1044 continue; 1044 continue;
1045 channel = mf->Bus; 1045 channel = mf->Bus;
1046 id = mf->TargetID; 1046 id = mf->TargetID;
1047 mptscsih_freeChainBuffers(ioc, ii); 1047 mptscsih_freeChainBuffers(ioc, ii);
1048 mpt_free_msg_frame(ioc, (MPT_FRAME_HDR *)mf); 1048 mpt_free_msg_frame(ioc, (MPT_FRAME_HDR *)mf);
1049 if ((unsigned char *)mf != sc->host_scribble) 1049 if ((unsigned char *)mf != sc->host_scribble)
1050 continue; 1050 continue;
1051 scsi_dma_unmap(sc); 1051 scsi_dma_unmap(sc);
1052 sc->result = DID_RESET << 16; 1052 sc->result = DID_RESET << 16;
1053 sc->host_scribble = NULL; 1053 sc->host_scribble = NULL;
1054 dtmprintk(ioc, sdev_printk(KERN_INFO, sc->device, MYIOC_s_FMT 1054 dtmprintk(ioc, sdev_printk(KERN_INFO, sc->device, MYIOC_s_FMT
1055 "completing cmds: fw_channel %d, fw_id %d, sc=%p, mf = %p, " 1055 "completing cmds: fw_channel %d, fw_id %d, sc=%p, mf = %p, "
1056 "idx=%x\n", ioc->name, channel, id, sc, mf, ii)); 1056 "idx=%x\n", ioc->name, channel, id, sc, mf, ii));
1057 sc->scsi_done(sc); 1057 sc->scsi_done(sc);
1058 } 1058 }
1059 } 1059 }
1060 EXPORT_SYMBOL(mptscsih_flush_running_cmds); 1060 EXPORT_SYMBOL(mptscsih_flush_running_cmds);
1061 1061
1062 /* 1062 /*
1063 * mptscsih_search_running_cmds - Delete any commands associated 1063 * mptscsih_search_running_cmds - Delete any commands associated
1064 * with the specified target and lun. Function called only 1064 * with the specified target and lun. Function called only
1065 * when a lun is disable by mid-layer. 1065 * when a lun is disable by mid-layer.
1066 * Do NOT access the referenced scsi_cmnd structure or 1066 * Do NOT access the referenced scsi_cmnd structure or
1067 * members. Will cause either a paging or NULL ptr error. 1067 * members. Will cause either a paging or NULL ptr error.
1068 * (BUT, BUT, BUT, the code does reference it! - mdr) 1068 * (BUT, BUT, BUT, the code does reference it! - mdr)
1069 * @hd: Pointer to a SCSI HOST structure 1069 * @hd: Pointer to a SCSI HOST structure
1070 * @vdevice: per device private data 1070 * @vdevice: per device private data
1071 * 1071 *
1072 * Returns: None. 1072 * Returns: None.
1073 * 1073 *
1074 * Called from slave_destroy. 1074 * Called from slave_destroy.
1075 */ 1075 */
1076 static void 1076 static void
1077 mptscsih_search_running_cmds(MPT_SCSI_HOST *hd, VirtDevice *vdevice) 1077 mptscsih_search_running_cmds(MPT_SCSI_HOST *hd, VirtDevice *vdevice)
1078 { 1078 {
1079 SCSIIORequest_t *mf = NULL; 1079 SCSIIORequest_t *mf = NULL;
1080 int ii; 1080 int ii;
1081 struct scsi_cmnd *sc; 1081 struct scsi_cmnd *sc;
1082 struct scsi_lun lun; 1082 struct scsi_lun lun;
1083 MPT_ADAPTER *ioc = hd->ioc; 1083 MPT_ADAPTER *ioc = hd->ioc;
1084 unsigned long flags; 1084 unsigned long flags;
1085 1085
1086 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags); 1086 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
1087 for (ii = 0; ii < ioc->req_depth; ii++) { 1087 for (ii = 0; ii < ioc->req_depth; ii++) {
1088 if ((sc = ioc->ScsiLookup[ii]) != NULL) { 1088 if ((sc = ioc->ScsiLookup[ii]) != NULL) {
1089 1089
1090 mf = (SCSIIORequest_t *)MPT_INDEX_2_MFPTR(ioc, ii); 1090 mf = (SCSIIORequest_t *)MPT_INDEX_2_MFPTR(ioc, ii);
1091 if (mf == NULL) 1091 if (mf == NULL)
1092 continue; 1092 continue;
1093 /* If the device is a hidden raid component, then its 1093 /* If the device is a hidden raid component, then its
1094 * expected that the mf->function will be RAID_SCSI_IO 1094 * expected that the mf->function will be RAID_SCSI_IO
1095 */ 1095 */
1096 if (vdevice->vtarget->tflags & 1096 if (vdevice->vtarget->tflags &
1097 MPT_TARGET_FLAGS_RAID_COMPONENT && mf->Function != 1097 MPT_TARGET_FLAGS_RAID_COMPONENT && mf->Function !=
1098 MPI_FUNCTION_RAID_SCSI_IO_PASSTHROUGH) 1098 MPI_FUNCTION_RAID_SCSI_IO_PASSTHROUGH)
1099 continue; 1099 continue;
1100 1100
1101 int_to_scsilun(vdevice->lun, &lun); 1101 int_to_scsilun(vdevice->lun, &lun);
1102 if ((mf->Bus != vdevice->vtarget->channel) || 1102 if ((mf->Bus != vdevice->vtarget->channel) ||
1103 (mf->TargetID != vdevice->vtarget->id) || 1103 (mf->TargetID != vdevice->vtarget->id) ||
1104 memcmp(lun.scsi_lun, mf->LUN, 8)) 1104 memcmp(lun.scsi_lun, mf->LUN, 8))
1105 continue; 1105 continue;
1106 1106
1107 if ((unsigned char *)mf != sc->host_scribble) 1107 if ((unsigned char *)mf != sc->host_scribble)
1108 continue; 1108 continue;
1109 ioc->ScsiLookup[ii] = NULL; 1109 ioc->ScsiLookup[ii] = NULL;
1110 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags); 1110 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
1111 mptscsih_freeChainBuffers(ioc, ii); 1111 mptscsih_freeChainBuffers(ioc, ii);
1112 mpt_free_msg_frame(ioc, (MPT_FRAME_HDR *)mf); 1112 mpt_free_msg_frame(ioc, (MPT_FRAME_HDR *)mf);
1113 scsi_dma_unmap(sc); 1113 scsi_dma_unmap(sc);
1114 sc->host_scribble = NULL; 1114 sc->host_scribble = NULL;
1115 sc->result = DID_NO_CONNECT << 16; 1115 sc->result = DID_NO_CONNECT << 16;
1116 dtmprintk(ioc, sdev_printk(KERN_INFO, sc->device, 1116 dtmprintk(ioc, sdev_printk(KERN_INFO, sc->device,
1117 MYIOC_s_FMT "completing cmds: fw_channel %d, " 1117 MYIOC_s_FMT "completing cmds: fw_channel %d, "
1118 "fw_id %d, sc=%p, mf = %p, idx=%x\n", ioc->name, 1118 "fw_id %d, sc=%p, mf = %p, idx=%x\n", ioc->name,
1119 vdevice->vtarget->channel, vdevice->vtarget->id, 1119 vdevice->vtarget->channel, vdevice->vtarget->id,
1120 sc, mf, ii)); 1120 sc, mf, ii));
1121 sc->scsi_done(sc); 1121 sc->scsi_done(sc);
1122 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags); 1122 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
1123 } 1123 }
1124 } 1124 }
1125 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags); 1125 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
1126 return; 1126 return;
1127 } 1127 }
1128 1128
1129 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/ 1129 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
1130 1130
1131 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/ 1131 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
1132 /* 1132 /*
1133 * mptscsih_report_queue_full - Report QUEUE_FULL status returned 1133 * mptscsih_report_queue_full - Report QUEUE_FULL status returned
1134 * from a SCSI target device. 1134 * from a SCSI target device.
1135 * @sc: Pointer to scsi_cmnd structure 1135 * @sc: Pointer to scsi_cmnd structure
1136 * @pScsiReply: Pointer to SCSIIOReply_t 1136 * @pScsiReply: Pointer to SCSIIOReply_t
1137 * @pScsiReq: Pointer to original SCSI request 1137 * @pScsiReq: Pointer to original SCSI request
1138 * 1138 *
1139 * This routine periodically reports QUEUE_FULL status returned from a 1139 * This routine periodically reports QUEUE_FULL status returned from a
1140 * SCSI target device. It reports this to the console via kernel 1140 * SCSI target device. It reports this to the console via kernel
1141 * printk() API call, not more than once every 10 seconds. 1141 * printk() API call, not more than once every 10 seconds.
1142 */ 1142 */
1143 static void 1143 static void
1144 mptscsih_report_queue_full(struct scsi_cmnd *sc, SCSIIOReply_t *pScsiReply, SCSIIORequest_t *pScsiReq) 1144 mptscsih_report_queue_full(struct scsi_cmnd *sc, SCSIIOReply_t *pScsiReply, SCSIIORequest_t *pScsiReq)
1145 { 1145 {
1146 long time = jiffies; 1146 long time = jiffies;
1147 MPT_SCSI_HOST *hd; 1147 MPT_SCSI_HOST *hd;
1148 MPT_ADAPTER *ioc; 1148 MPT_ADAPTER *ioc;
1149 1149
1150 if (sc->device == NULL) 1150 if (sc->device == NULL)
1151 return; 1151 return;
1152 if (sc->device->host == NULL) 1152 if (sc->device->host == NULL)
1153 return; 1153 return;
1154 if ((hd = shost_priv(sc->device->host)) == NULL) 1154 if ((hd = shost_priv(sc->device->host)) == NULL)
1155 return; 1155 return;
1156 ioc = hd->ioc; 1156 ioc = hd->ioc;
1157 if (time - hd->last_queue_full > 10 * HZ) { 1157 if (time - hd->last_queue_full > 10 * HZ) {
1158 dprintk(ioc, printk(MYIOC_s_WARN_FMT "Device (%d:%d:%d) reported QUEUE_FULL!\n", 1158 dprintk(ioc, printk(MYIOC_s_WARN_FMT "Device (%d:%d:%d) reported QUEUE_FULL!\n",
1159 ioc->name, 0, sc->device->id, sc->device->lun)); 1159 ioc->name, 0, sc->device->id, sc->device->lun));
1160 hd->last_queue_full = time; 1160 hd->last_queue_full = time;
1161 } 1161 }
1162 } 1162 }
1163 1163
1164 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/ 1164 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
1165 /* 1165 /*
1166 * mptscsih_remove - Removed scsi devices 1166 * mptscsih_remove - Removed scsi devices
1167 * @pdev: Pointer to pci_dev structure 1167 * @pdev: Pointer to pci_dev structure
1168 * 1168 *
1169 * 1169 *
1170 */ 1170 */
1171 void 1171 void
1172 mptscsih_remove(struct pci_dev *pdev) 1172 mptscsih_remove(struct pci_dev *pdev)
1173 { 1173 {
1174 MPT_ADAPTER *ioc = pci_get_drvdata(pdev); 1174 MPT_ADAPTER *ioc = pci_get_drvdata(pdev);
1175 struct Scsi_Host *host = ioc->sh; 1175 struct Scsi_Host *host = ioc->sh;
1176 MPT_SCSI_HOST *hd; 1176 MPT_SCSI_HOST *hd;
1177 int sz1; 1177 int sz1;
1178 1178
1179 scsi_remove_host(host); 1179 scsi_remove_host(host);
1180 1180
1181 if((hd = shost_priv(host)) == NULL) 1181 if((hd = shost_priv(host)) == NULL)
1182 return; 1182 return;
1183 1183
1184 mptscsih_shutdown(pdev); 1184 mptscsih_shutdown(pdev);
1185 1185
1186 sz1=0; 1186 sz1=0;
1187 1187
1188 if (ioc->ScsiLookup != NULL) { 1188 if (ioc->ScsiLookup != NULL) {
1189 sz1 = ioc->req_depth * sizeof(void *); 1189 sz1 = ioc->req_depth * sizeof(void *);
1190 kfree(ioc->ScsiLookup); 1190 kfree(ioc->ScsiLookup);
1191 ioc->ScsiLookup = NULL; 1191 ioc->ScsiLookup = NULL;
1192 } 1192 }
1193 1193
1194 dprintk(ioc, printk(MYIOC_s_DEBUG_FMT 1194 dprintk(ioc, printk(MYIOC_s_DEBUG_FMT
1195 "Free'd ScsiLookup (%d) memory\n", 1195 "Free'd ScsiLookup (%d) memory\n",
1196 ioc->name, sz1)); 1196 ioc->name, sz1));
1197 1197
1198 kfree(hd->info_kbuf); 1198 kfree(hd->info_kbuf);
1199 1199
1200 /* NULL the Scsi_Host pointer 1200 /* NULL the Scsi_Host pointer
1201 */ 1201 */
1202 ioc->sh = NULL; 1202 ioc->sh = NULL;
1203 1203
1204 scsi_host_put(host); 1204 scsi_host_put(host);
1205 1205
1206 mpt_detach(pdev); 1206 mpt_detach(pdev);
1207 1207
1208 } 1208 }
1209 1209
1210 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/ 1210 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
1211 /* 1211 /*
1212 * mptscsih_shutdown - reboot notifier 1212 * mptscsih_shutdown - reboot notifier
1213 * 1213 *
1214 */ 1214 */
1215 void 1215 void
1216 mptscsih_shutdown(struct pci_dev *pdev) 1216 mptscsih_shutdown(struct pci_dev *pdev)
1217 { 1217 {
1218 } 1218 }
1219 1219
1220 #ifdef CONFIG_PM 1220 #ifdef CONFIG_PM
1221 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/ 1221 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
1222 /* 1222 /*
1223 * mptscsih_suspend - Fusion MPT scsi driver suspend routine. 1223 * mptscsih_suspend - Fusion MPT scsi driver suspend routine.
1224 * 1224 *
1225 * 1225 *
1226 */ 1226 */
1227 int 1227 int
1228 mptscsih_suspend(struct pci_dev *pdev, pm_message_t state) 1228 mptscsih_suspend(struct pci_dev *pdev, pm_message_t state)
1229 { 1229 {
1230 MPT_ADAPTER *ioc = pci_get_drvdata(pdev); 1230 MPT_ADAPTER *ioc = pci_get_drvdata(pdev);
1231 1231
1232 scsi_block_requests(ioc->sh); 1232 scsi_block_requests(ioc->sh);
1233 flush_scheduled_work(); 1233 flush_scheduled_work();
1234 mptscsih_shutdown(pdev); 1234 mptscsih_shutdown(pdev);
1235 return mpt_suspend(pdev,state); 1235 return mpt_suspend(pdev,state);
1236 } 1236 }
1237 1237
1238 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/ 1238 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
1239 /* 1239 /*
1240 * mptscsih_resume - Fusion MPT scsi driver resume routine. 1240 * mptscsih_resume - Fusion MPT scsi driver resume routine.
1241 * 1241 *
1242 * 1242 *
1243 */ 1243 */
1244 int 1244 int
1245 mptscsih_resume(struct pci_dev *pdev) 1245 mptscsih_resume(struct pci_dev *pdev)
1246 { 1246 {
1247 MPT_ADAPTER *ioc = pci_get_drvdata(pdev); 1247 MPT_ADAPTER *ioc = pci_get_drvdata(pdev);
1248 int rc; 1248 int rc;
1249 1249
1250 rc = mpt_resume(pdev); 1250 rc = mpt_resume(pdev);
1251 scsi_unblock_requests(ioc->sh); 1251 scsi_unblock_requests(ioc->sh);
1252 return rc; 1252 return rc;
1253 } 1253 }
1254 1254
1255 #endif 1255 #endif
1256 1256
1257 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/ 1257 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
1258 /** 1258 /**
1259 * mptscsih_info - Return information about MPT adapter 1259 * mptscsih_info - Return information about MPT adapter
1260 * @SChost: Pointer to Scsi_Host structure 1260 * @SChost: Pointer to Scsi_Host structure
1261 * 1261 *
1262 * (linux scsi_host_template.info routine) 1262 * (linux scsi_host_template.info routine)
1263 * 1263 *
1264 * Returns pointer to buffer where information was written. 1264 * Returns pointer to buffer where information was written.
1265 */ 1265 */
1266 const char * 1266 const char *
1267 mptscsih_info(struct Scsi_Host *SChost) 1267 mptscsih_info(struct Scsi_Host *SChost)
1268 { 1268 {
1269 MPT_SCSI_HOST *h; 1269 MPT_SCSI_HOST *h;
1270 int size = 0; 1270 int size = 0;
1271 1271
1272 h = shost_priv(SChost); 1272 h = shost_priv(SChost);
1273 1273
1274 if (h) { 1274 if (h) {
1275 if (h->info_kbuf == NULL) 1275 if (h->info_kbuf == NULL)
1276 if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL) 1276 if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
1277 return h->info_kbuf; 1277 return h->info_kbuf;
1278 h->info_kbuf[0] = '\0'; 1278 h->info_kbuf[0] = '\0';
1279 1279
1280 mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0); 1280 mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
1281 h->info_kbuf[size-1] = '\0'; 1281 h->info_kbuf[size-1] = '\0';
1282 } 1282 }
1283 1283
1284 return h->info_kbuf; 1284 return h->info_kbuf;
1285 } 1285 }
1286 1286
1287 struct info_str { 1287 int mptscsih_show_info(struct seq_file *m, struct Scsi_Host *host)
1288 char *buffer;
1289 int length;
1290 int offset;
1291 int pos;
1292 };
1293
1294 static void
1295 mptscsih_copy_mem_info(struct info_str *info, char *data, int len)
1296 { 1288 {
1297 if (info->pos + len > info->length)
1298 len = info->length - info->pos;
1299
1300 if (info->pos + len < info->offset) {
1301 info->pos += len;
1302 return;
1303 }
1304
1305 if (info->pos < info->offset) {
1306 data += (info->offset - info->pos);
1307 len -= (info->offset - info->pos);
1308 }
1309
1310 if (len > 0) {
1311 memcpy(info->buffer + info->pos, data, len);
1312 info->pos += len;
1313 }
1314 }
1315
1316 static int
1317 mptscsih_copy_info(struct info_str *info, char *fmt, ...)
1318 {
1319 va_list args;
1320 char buf[81];
1321 int len;
1322
1323 va_start(args, fmt);
1324 len = vsprintf(buf, fmt, args);
1325 va_end(args);
1326
1327 mptscsih_copy_mem_info(info, buf, len);
1328 return len;
1329 }
1330
1331 static int
1332 mptscsih_host_info(MPT_ADAPTER *ioc, char *pbuf, off_t offset, int len)
1333 {
1334 struct info_str info;
1335
1336 info.buffer = pbuf;
1337 info.length = len;
1338 info.offset = offset;
1339 info.pos = 0;
1340
1341 mptscsih_copy_info(&info, "%s: %s, ", ioc->name, ioc->prod_name);
1342 mptscsih_copy_info(&info, "%s%08xh, ", MPT_FW_REV_MAGIC_ID_STRING, ioc->facts.FWVersion.Word);
1343 mptscsih_copy_info(&info, "Ports=%d, ", ioc->facts.NumberOfPorts);
1344 mptscsih_copy_info(&info, "MaxQ=%d\n", ioc->req_depth);
1345
1346 return ((info.pos > info.offset) ? info.pos - info.offset : 0);
1347 }
1348
1349 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
1350 /**
1351 * mptscsih_proc_info - Return information about MPT adapter
1352 * @host: scsi host struct
1353 * @buffer: if write, user data; if read, buffer for user
1354 * @start: returns the buffer address
1355 * @offset: if write, 0; if read, the current offset into the buffer from
1356 * the previous read.
1357 * @length: if write, return length;
1358 * @func: write = 1; read = 0
1359 *
1360 * (linux scsi_host_template.info routine)
1361 */
1362 int
1363 mptscsih_proc_info(struct Scsi_Host *host, char *buffer, char **start, off_t offset,
1364 int length, int func)
1365 {
1366 MPT_SCSI_HOST *hd = shost_priv(host); 1289 MPT_SCSI_HOST *hd = shost_priv(host);
1367 MPT_ADAPTER *ioc = hd->ioc; 1290 MPT_ADAPTER *ioc = hd->ioc;
1368 int size = 0;
1369 1291
1370 if (func) { 1292 seq_printf(m, "%s: %s, ", ioc->name, ioc->prod_name);
1371 /* 1293 seq_printf(m, "%s%08xh, ", MPT_FW_REV_MAGIC_ID_STRING, ioc->facts.FWVersion.Word);
1372 * write is not supported 1294 seq_printf(m, "Ports=%d, ", ioc->facts.NumberOfPorts);
1373 */ 1295 seq_printf(m, "MaxQ=%d\n", ioc->req_depth);
1374 } else {
1375 if (start)
1376 *start = buffer;
1377 1296
1378 size = mptscsih_host_info(ioc, buffer, offset, length); 1297 return 0;
1379 }
1380
1381 return size;
1382 } 1298 }
1383 1299
1384 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/ 1300 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
1385 #define ADD_INDEX_LOG(req_ent) do { } while(0) 1301 #define ADD_INDEX_LOG(req_ent) do { } while(0)
1386 1302
1387 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/ 1303 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
1388 /** 1304 /**
1389 * mptscsih_qcmd - Primary Fusion MPT SCSI initiator IO start routine. 1305 * mptscsih_qcmd - Primary Fusion MPT SCSI initiator IO start routine.
1390 * @SCpnt: Pointer to scsi_cmnd structure 1306 * @SCpnt: Pointer to scsi_cmnd structure
1391 * @done: Pointer SCSI mid-layer IO completion function 1307 * @done: Pointer SCSI mid-layer IO completion function
1392 * 1308 *
1393 * (linux scsi_host_template.queuecommand routine) 1309 * (linux scsi_host_template.queuecommand routine)
1394 * This is the primary SCSI IO start routine. Create a MPI SCSIIORequest 1310 * This is the primary SCSI IO start routine. Create a MPI SCSIIORequest
1395 * from a linux scsi_cmnd request and send it to the IOC. 1311 * from a linux scsi_cmnd request and send it to the IOC.
1396 * 1312 *
1397 * Returns 0. (rtn value discarded by linux scsi mid-layer) 1313 * Returns 0. (rtn value discarded by linux scsi mid-layer)
1398 */ 1314 */
1399 int 1315 int
1400 mptscsih_qcmd(struct scsi_cmnd *SCpnt, void (*done)(struct scsi_cmnd *)) 1316 mptscsih_qcmd(struct scsi_cmnd *SCpnt, void (*done)(struct scsi_cmnd *))
1401 { 1317 {
1402 MPT_SCSI_HOST *hd; 1318 MPT_SCSI_HOST *hd;
1403 MPT_FRAME_HDR *mf; 1319 MPT_FRAME_HDR *mf;
1404 SCSIIORequest_t *pScsiReq; 1320 SCSIIORequest_t *pScsiReq;
1405 VirtDevice *vdevice = SCpnt->device->hostdata; 1321 VirtDevice *vdevice = SCpnt->device->hostdata;
1406 u32 datalen; 1322 u32 datalen;
1407 u32 scsictl; 1323 u32 scsictl;
1408 u32 scsidir; 1324 u32 scsidir;
1409 u32 cmd_len; 1325 u32 cmd_len;
1410 int my_idx; 1326 int my_idx;
1411 int ii; 1327 int ii;
1412 MPT_ADAPTER *ioc; 1328 MPT_ADAPTER *ioc;
1413 1329
1414 hd = shost_priv(SCpnt->device->host); 1330 hd = shost_priv(SCpnt->device->host);
1415 ioc = hd->ioc; 1331 ioc = hd->ioc;
1416 SCpnt->scsi_done = done; 1332 SCpnt->scsi_done = done;
1417 1333
1418 dmfprintk(ioc, printk(MYIOC_s_DEBUG_FMT "qcmd: SCpnt=%p, done()=%p\n", 1334 dmfprintk(ioc, printk(MYIOC_s_DEBUG_FMT "qcmd: SCpnt=%p, done()=%p\n",
1419 ioc->name, SCpnt, done)); 1335 ioc->name, SCpnt, done));
1420 1336
1421 if (ioc->taskmgmt_quiesce_io) 1337 if (ioc->taskmgmt_quiesce_io)
1422 return SCSI_MLQUEUE_HOST_BUSY; 1338 return SCSI_MLQUEUE_HOST_BUSY;
1423 1339
1424 /* 1340 /*
1425 * Put together a MPT SCSI request... 1341 * Put together a MPT SCSI request...
1426 */ 1342 */
1427 if ((mf = mpt_get_msg_frame(ioc->DoneCtx, ioc)) == NULL) { 1343 if ((mf = mpt_get_msg_frame(ioc->DoneCtx, ioc)) == NULL) {
1428 dprintk(ioc, printk(MYIOC_s_WARN_FMT "QueueCmd, no msg frames!!\n", 1344 dprintk(ioc, printk(MYIOC_s_WARN_FMT "QueueCmd, no msg frames!!\n",
1429 ioc->name)); 1345 ioc->name));
1430 return SCSI_MLQUEUE_HOST_BUSY; 1346 return SCSI_MLQUEUE_HOST_BUSY;
1431 } 1347 }
1432 1348
1433 pScsiReq = (SCSIIORequest_t *) mf; 1349 pScsiReq = (SCSIIORequest_t *) mf;
1434 1350
1435 my_idx = le16_to_cpu(mf->u.frame.hwhdr.msgctxu.fld.req_idx); 1351 my_idx = le16_to_cpu(mf->u.frame.hwhdr.msgctxu.fld.req_idx);
1436 1352
1437 ADD_INDEX_LOG(my_idx); 1353 ADD_INDEX_LOG(my_idx);
1438 1354
1439 /* TUR's being issued with scsictl=0x02000000 (DATA_IN)! 1355 /* TUR's being issued with scsictl=0x02000000 (DATA_IN)!
1440 * Seems we may receive a buffer (datalen>0) even when there 1356 * Seems we may receive a buffer (datalen>0) even when there
1441 * will be no data transfer! GRRRRR... 1357 * will be no data transfer! GRRRRR...
1442 */ 1358 */
1443 if (SCpnt->sc_data_direction == DMA_FROM_DEVICE) { 1359 if (SCpnt->sc_data_direction == DMA_FROM_DEVICE) {
1444 datalen = scsi_bufflen(SCpnt); 1360 datalen = scsi_bufflen(SCpnt);
1445 scsidir = MPI_SCSIIO_CONTROL_READ; /* DATA IN (host<--ioc<--dev) */ 1361 scsidir = MPI_SCSIIO_CONTROL_READ; /* DATA IN (host<--ioc<--dev) */
1446 } else if (SCpnt->sc_data_direction == DMA_TO_DEVICE) { 1362 } else if (SCpnt->sc_data_direction == DMA_TO_DEVICE) {
1447 datalen = scsi_bufflen(SCpnt); 1363 datalen = scsi_bufflen(SCpnt);
1448 scsidir = MPI_SCSIIO_CONTROL_WRITE; /* DATA OUT (host-->ioc-->dev) */ 1364 scsidir = MPI_SCSIIO_CONTROL_WRITE; /* DATA OUT (host-->ioc-->dev) */
1449 } else { 1365 } else {
1450 datalen = 0; 1366 datalen = 0;
1451 scsidir = MPI_SCSIIO_CONTROL_NODATATRANSFER; 1367 scsidir = MPI_SCSIIO_CONTROL_NODATATRANSFER;
1452 } 1368 }
1453 1369
1454 /* Default to untagged. Once a target structure has been allocated, 1370 /* Default to untagged. Once a target structure has been allocated,
1455 * use the Inquiry data to determine if device supports tagged. 1371 * use the Inquiry data to determine if device supports tagged.
1456 */ 1372 */
1457 if (vdevice 1373 if (vdevice
1458 && (vdevice->vtarget->tflags & MPT_TARGET_FLAGS_Q_YES) 1374 && (vdevice->vtarget->tflags & MPT_TARGET_FLAGS_Q_YES)
1459 && (SCpnt->device->tagged_supported)) { 1375 && (SCpnt->device->tagged_supported)) {
1460 scsictl = scsidir | MPI_SCSIIO_CONTROL_SIMPLEQ; 1376 scsictl = scsidir | MPI_SCSIIO_CONTROL_SIMPLEQ;
1461 if (SCpnt->request && SCpnt->request->ioprio) { 1377 if (SCpnt->request && SCpnt->request->ioprio) {
1462 if (((SCpnt->request->ioprio & 0x7) == 1) || 1378 if (((SCpnt->request->ioprio & 0x7) == 1) ||
1463 !(SCpnt->request->ioprio & 0x7)) 1379 !(SCpnt->request->ioprio & 0x7))
1464 scsictl |= MPI_SCSIIO_CONTROL_HEADOFQ; 1380 scsictl |= MPI_SCSIIO_CONTROL_HEADOFQ;
1465 } 1381 }
1466 } else 1382 } else
1467 scsictl = scsidir | MPI_SCSIIO_CONTROL_UNTAGGED; 1383 scsictl = scsidir | MPI_SCSIIO_CONTROL_UNTAGGED;
1468 1384
1469 1385
1470 /* Use the above information to set up the message frame 1386 /* Use the above information to set up the message frame
1471 */ 1387 */
1472 pScsiReq->TargetID = (u8) vdevice->vtarget->id; 1388 pScsiReq->TargetID = (u8) vdevice->vtarget->id;
1473 pScsiReq->Bus = vdevice->vtarget->channel; 1389 pScsiReq->Bus = vdevice->vtarget->channel;
1474 pScsiReq->ChainOffset = 0; 1390 pScsiReq->ChainOffset = 0;
1475 if (vdevice->vtarget->tflags & MPT_TARGET_FLAGS_RAID_COMPONENT) 1391 if (vdevice->vtarget->tflags & MPT_TARGET_FLAGS_RAID_COMPONENT)
1476 pScsiReq->Function = MPI_FUNCTION_RAID_SCSI_IO_PASSTHROUGH; 1392 pScsiReq->Function = MPI_FUNCTION_RAID_SCSI_IO_PASSTHROUGH;
1477 else 1393 else
1478 pScsiReq->Function = MPI_FUNCTION_SCSI_IO_REQUEST; 1394 pScsiReq->Function = MPI_FUNCTION_SCSI_IO_REQUEST;
1479 pScsiReq->CDBLength = SCpnt->cmd_len; 1395 pScsiReq->CDBLength = SCpnt->cmd_len;
1480 pScsiReq->SenseBufferLength = MPT_SENSE_BUFFER_SIZE; 1396 pScsiReq->SenseBufferLength = MPT_SENSE_BUFFER_SIZE;
1481 pScsiReq->Reserved = 0; 1397 pScsiReq->Reserved = 0;
1482 pScsiReq->MsgFlags = mpt_msg_flags(ioc); 1398 pScsiReq->MsgFlags = mpt_msg_flags(ioc);
1483 int_to_scsilun(SCpnt->device->lun, (struct scsi_lun *)pScsiReq->LUN); 1399 int_to_scsilun(SCpnt->device->lun, (struct scsi_lun *)pScsiReq->LUN);
1484 pScsiReq->Control = cpu_to_le32(scsictl); 1400 pScsiReq->Control = cpu_to_le32(scsictl);
1485 1401
1486 /* 1402 /*
1487 * Write SCSI CDB into the message 1403 * Write SCSI CDB into the message
1488 */ 1404 */
1489 cmd_len = SCpnt->cmd_len; 1405 cmd_len = SCpnt->cmd_len;
1490 for (ii=0; ii < cmd_len; ii++) 1406 for (ii=0; ii < cmd_len; ii++)
1491 pScsiReq->CDB[ii] = SCpnt->cmnd[ii]; 1407 pScsiReq->CDB[ii] = SCpnt->cmnd[ii];
1492 1408
1493 for (ii=cmd_len; ii < 16; ii++) 1409 for (ii=cmd_len; ii < 16; ii++)
1494 pScsiReq->CDB[ii] = 0; 1410 pScsiReq->CDB[ii] = 0;
1495 1411
1496 /* DataLength */ 1412 /* DataLength */
1497 pScsiReq->DataLength = cpu_to_le32(datalen); 1413 pScsiReq->DataLength = cpu_to_le32(datalen);
1498 1414
1499 /* SenseBuffer low address */ 1415 /* SenseBuffer low address */
1500 pScsiReq->SenseBufferLowAddr = cpu_to_le32(ioc->sense_buf_low_dma 1416 pScsiReq->SenseBufferLowAddr = cpu_to_le32(ioc->sense_buf_low_dma
1501 + (my_idx * MPT_SENSE_BUFFER_ALLOC)); 1417 + (my_idx * MPT_SENSE_BUFFER_ALLOC));
1502 1418
1503 /* Now add the SG list 1419 /* Now add the SG list
1504 * Always have a SGE even if null length. 1420 * Always have a SGE even if null length.
1505 */ 1421 */
1506 if (datalen == 0) { 1422 if (datalen == 0) {
1507 /* Add a NULL SGE */ 1423 /* Add a NULL SGE */
1508 ioc->add_sge((char *)&pScsiReq->SGL, 1424 ioc->add_sge((char *)&pScsiReq->SGL,
1509 MPT_SGE_FLAGS_SSIMPLE_READ | 0, 1425 MPT_SGE_FLAGS_SSIMPLE_READ | 0,
1510 (dma_addr_t) -1); 1426 (dma_addr_t) -1);
1511 } else { 1427 } else {
1512 /* Add a 32 or 64 bit SGE */ 1428 /* Add a 32 or 64 bit SGE */
1513 if (mptscsih_AddSGE(ioc, SCpnt, pScsiReq, my_idx) != SUCCESS) 1429 if (mptscsih_AddSGE(ioc, SCpnt, pScsiReq, my_idx) != SUCCESS)
1514 goto fail; 1430 goto fail;
1515 } 1431 }
1516 1432
1517 SCpnt->host_scribble = (unsigned char *)mf; 1433 SCpnt->host_scribble = (unsigned char *)mf;
1518 mptscsih_set_scsi_lookup(ioc, my_idx, SCpnt); 1434 mptscsih_set_scsi_lookup(ioc, my_idx, SCpnt);
1519 1435
1520 mpt_put_msg_frame(ioc->DoneCtx, ioc, mf); 1436 mpt_put_msg_frame(ioc->DoneCtx, ioc, mf);
1521 dmfprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Issued SCSI cmd (%p) mf=%p idx=%d\n", 1437 dmfprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Issued SCSI cmd (%p) mf=%p idx=%d\n",
1522 ioc->name, SCpnt, mf, my_idx)); 1438 ioc->name, SCpnt, mf, my_idx));
1523 DBG_DUMP_REQUEST_FRAME(ioc, (u32 *)mf); 1439 DBG_DUMP_REQUEST_FRAME(ioc, (u32 *)mf);
1524 return 0; 1440 return 0;
1525 1441
1526 fail: 1442 fail:
1527 mptscsih_freeChainBuffers(ioc, my_idx); 1443 mptscsih_freeChainBuffers(ioc, my_idx);
1528 mpt_free_msg_frame(ioc, mf); 1444 mpt_free_msg_frame(ioc, mf);
1529 return SCSI_MLQUEUE_HOST_BUSY; 1445 return SCSI_MLQUEUE_HOST_BUSY;
1530 } 1446 }
1531 1447
1532 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/ 1448 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
1533 /* 1449 /*
1534 * mptscsih_freeChainBuffers - Function to free chain buffers associated 1450 * mptscsih_freeChainBuffers - Function to free chain buffers associated
1535 * with a SCSI IO request 1451 * with a SCSI IO request
1536 * @hd: Pointer to the MPT_SCSI_HOST instance 1452 * @hd: Pointer to the MPT_SCSI_HOST instance
1537 * @req_idx: Index of the SCSI IO request frame. 1453 * @req_idx: Index of the SCSI IO request frame.
1538 * 1454 *
1539 * Called if SG chain buffer allocation fails and mptscsih callbacks. 1455 * Called if SG chain buffer allocation fails and mptscsih callbacks.
1540 * No return. 1456 * No return.
1541 */ 1457 */
1542 static void 1458 static void
1543 mptscsih_freeChainBuffers(MPT_ADAPTER *ioc, int req_idx) 1459 mptscsih_freeChainBuffers(MPT_ADAPTER *ioc, int req_idx)
1544 { 1460 {
1545 MPT_FRAME_HDR *chain; 1461 MPT_FRAME_HDR *chain;
1546 unsigned long flags; 1462 unsigned long flags;
1547 int chain_idx; 1463 int chain_idx;
1548 int next; 1464 int next;
1549 1465
1550 /* Get the first chain index and reset 1466 /* Get the first chain index and reset
1551 * tracker state. 1467 * tracker state.
1552 */ 1468 */
1553 chain_idx = ioc->ReqToChain[req_idx]; 1469 chain_idx = ioc->ReqToChain[req_idx];
1554 ioc->ReqToChain[req_idx] = MPT_HOST_NO_CHAIN; 1470 ioc->ReqToChain[req_idx] = MPT_HOST_NO_CHAIN;
1555 1471
1556 while (chain_idx != MPT_HOST_NO_CHAIN) { 1472 while (chain_idx != MPT_HOST_NO_CHAIN) {
1557 1473
1558 /* Save the next chain buffer index */ 1474 /* Save the next chain buffer index */
1559 next = ioc->ChainToChain[chain_idx]; 1475 next = ioc->ChainToChain[chain_idx];
1560 1476
1561 /* Free this chain buffer and reset 1477 /* Free this chain buffer and reset
1562 * tracker 1478 * tracker
1563 */ 1479 */
1564 ioc->ChainToChain[chain_idx] = MPT_HOST_NO_CHAIN; 1480 ioc->ChainToChain[chain_idx] = MPT_HOST_NO_CHAIN;
1565 1481
1566 chain = (MPT_FRAME_HDR *) (ioc->ChainBuffer 1482 chain = (MPT_FRAME_HDR *) (ioc->ChainBuffer
1567 + (chain_idx * ioc->req_sz)); 1483 + (chain_idx * ioc->req_sz));
1568 1484
1569 spin_lock_irqsave(&ioc->FreeQlock, flags); 1485 spin_lock_irqsave(&ioc->FreeQlock, flags);
1570 list_add_tail(&chain->u.frame.linkage.list, &ioc->FreeChainQ); 1486 list_add_tail(&chain->u.frame.linkage.list, &ioc->FreeChainQ);
1571 spin_unlock_irqrestore(&ioc->FreeQlock, flags); 1487 spin_unlock_irqrestore(&ioc->FreeQlock, flags);
1572 1488
1573 dmfprintk(ioc, printk(MYIOC_s_DEBUG_FMT "FreeChainBuffers (index %d)\n", 1489 dmfprintk(ioc, printk(MYIOC_s_DEBUG_FMT "FreeChainBuffers (index %d)\n",
1574 ioc->name, chain_idx)); 1490 ioc->name, chain_idx));
1575 1491
1576 /* handle next */ 1492 /* handle next */
1577 chain_idx = next; 1493 chain_idx = next;
1578 } 1494 }
1579 return; 1495 return;
1580 } 1496 }
1581 1497
1582 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/ 1498 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
1583 /* 1499 /*
1584 * Reset Handling 1500 * Reset Handling
1585 */ 1501 */
1586 1502
1587 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/ 1503 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
1588 /** 1504 /**
1589 * mptscsih_IssueTaskMgmt - Generic send Task Management function. 1505 * mptscsih_IssueTaskMgmt - Generic send Task Management function.
1590 * @hd: Pointer to MPT_SCSI_HOST structure 1506 * @hd: Pointer to MPT_SCSI_HOST structure
1591 * @type: Task Management type 1507 * @type: Task Management type
1592 * @channel: channel number for task management 1508 * @channel: channel number for task management
1593 * @id: Logical Target ID for reset (if appropriate) 1509 * @id: Logical Target ID for reset (if appropriate)
1594 * @lun: Logical Unit for reset (if appropriate) 1510 * @lun: Logical Unit for reset (if appropriate)
1595 * @ctx2abort: Context for the task to be aborted (if appropriate) 1511 * @ctx2abort: Context for the task to be aborted (if appropriate)
1596 * @timeout: timeout for task management control 1512 * @timeout: timeout for task management control
1597 * 1513 *
1598 * Remark: _HardResetHandler can be invoked from an interrupt thread (timer) 1514 * Remark: _HardResetHandler can be invoked from an interrupt thread (timer)
1599 * or a non-interrupt thread. In the former, must not call schedule(). 1515 * or a non-interrupt thread. In the former, must not call schedule().
1600 * 1516 *
1601 * Not all fields are meaningfull for all task types. 1517 * Not all fields are meaningfull for all task types.
1602 * 1518 *
1603 * Returns 0 for SUCCESS, or FAILED. 1519 * Returns 0 for SUCCESS, or FAILED.
1604 * 1520 *
1605 **/ 1521 **/
1606 int 1522 int
1607 mptscsih_IssueTaskMgmt(MPT_SCSI_HOST *hd, u8 type, u8 channel, u8 id, int lun, 1523 mptscsih_IssueTaskMgmt(MPT_SCSI_HOST *hd, u8 type, u8 channel, u8 id, int lun,
1608 int ctx2abort, ulong timeout) 1524 int ctx2abort, ulong timeout)
1609 { 1525 {
1610 MPT_FRAME_HDR *mf; 1526 MPT_FRAME_HDR *mf;
1611 SCSITaskMgmt_t *pScsiTm; 1527 SCSITaskMgmt_t *pScsiTm;
1612 int ii; 1528 int ii;
1613 int retval; 1529 int retval;
1614 MPT_ADAPTER *ioc = hd->ioc; 1530 MPT_ADAPTER *ioc = hd->ioc;
1615 unsigned long timeleft; 1531 unsigned long timeleft;
1616 u8 issue_hard_reset; 1532 u8 issue_hard_reset;
1617 u32 ioc_raw_state; 1533 u32 ioc_raw_state;
1618 unsigned long time_count; 1534 unsigned long time_count;
1619 1535
1620 issue_hard_reset = 0; 1536 issue_hard_reset = 0;
1621 ioc_raw_state = mpt_GetIocState(ioc, 0); 1537 ioc_raw_state = mpt_GetIocState(ioc, 0);
1622 1538
1623 if ((ioc_raw_state & MPI_IOC_STATE_MASK) != MPI_IOC_STATE_OPERATIONAL) { 1539 if ((ioc_raw_state & MPI_IOC_STATE_MASK) != MPI_IOC_STATE_OPERATIONAL) {
1624 printk(MYIOC_s_WARN_FMT 1540 printk(MYIOC_s_WARN_FMT
1625 "TaskMgmt type=%x: IOC Not operational (0x%x)!\n", 1541 "TaskMgmt type=%x: IOC Not operational (0x%x)!\n",
1626 ioc->name, type, ioc_raw_state); 1542 ioc->name, type, ioc_raw_state);
1627 printk(MYIOC_s_WARN_FMT "Issuing HardReset from %s!!\n", 1543 printk(MYIOC_s_WARN_FMT "Issuing HardReset from %s!!\n",
1628 ioc->name, __func__); 1544 ioc->name, __func__);
1629 if (mpt_HardResetHandler(ioc, CAN_SLEEP) < 0) 1545 if (mpt_HardResetHandler(ioc, CAN_SLEEP) < 0)
1630 printk(MYIOC_s_WARN_FMT "TaskMgmt HardReset " 1546 printk(MYIOC_s_WARN_FMT "TaskMgmt HardReset "
1631 "FAILED!!\n", ioc->name); 1547 "FAILED!!\n", ioc->name);
1632 return 0; 1548 return 0;
1633 } 1549 }
1634 1550
1635 /* DOORBELL ACTIVE check is not required if 1551 /* DOORBELL ACTIVE check is not required if
1636 * MPI_IOCFACTS_CAPABILITY_HIGH_PRI_Q is supported. 1552 * MPI_IOCFACTS_CAPABILITY_HIGH_PRI_Q is supported.
1637 */ 1553 */
1638 1554
1639 if (!((ioc->facts.IOCCapabilities & MPI_IOCFACTS_CAPABILITY_HIGH_PRI_Q) 1555 if (!((ioc->facts.IOCCapabilities & MPI_IOCFACTS_CAPABILITY_HIGH_PRI_Q)
1640 && (ioc->facts.MsgVersion >= MPI_VERSION_01_05)) && 1556 && (ioc->facts.MsgVersion >= MPI_VERSION_01_05)) &&
1641 (ioc_raw_state & MPI_DOORBELL_ACTIVE)) { 1557 (ioc_raw_state & MPI_DOORBELL_ACTIVE)) {
1642 printk(MYIOC_s_WARN_FMT 1558 printk(MYIOC_s_WARN_FMT
1643 "TaskMgmt type=%x: ioc_state: " 1559 "TaskMgmt type=%x: ioc_state: "
1644 "DOORBELL_ACTIVE (0x%x)!\n", 1560 "DOORBELL_ACTIVE (0x%x)!\n",
1645 ioc->name, type, ioc_raw_state); 1561 ioc->name, type, ioc_raw_state);
1646 return FAILED; 1562 return FAILED;
1647 } 1563 }
1648 1564
1649 mutex_lock(&ioc->taskmgmt_cmds.mutex); 1565 mutex_lock(&ioc->taskmgmt_cmds.mutex);
1650 if (mpt_set_taskmgmt_in_progress_flag(ioc) != 0) { 1566 if (mpt_set_taskmgmt_in_progress_flag(ioc) != 0) {
1651 mf = NULL; 1567 mf = NULL;
1652 retval = FAILED; 1568 retval = FAILED;
1653 goto out; 1569 goto out;
1654 } 1570 }
1655 1571
1656 /* Return Fail to calling function if no message frames available. 1572 /* Return Fail to calling function if no message frames available.
1657 */ 1573 */
1658 if ((mf = mpt_get_msg_frame(ioc->TaskCtx, ioc)) == NULL) { 1574 if ((mf = mpt_get_msg_frame(ioc->TaskCtx, ioc)) == NULL) {
1659 dfailprintk(ioc, printk(MYIOC_s_ERR_FMT 1575 dfailprintk(ioc, printk(MYIOC_s_ERR_FMT
1660 "TaskMgmt no msg frames!!\n", ioc->name)); 1576 "TaskMgmt no msg frames!!\n", ioc->name));
1661 retval = FAILED; 1577 retval = FAILED;
1662 mpt_clear_taskmgmt_in_progress_flag(ioc); 1578 mpt_clear_taskmgmt_in_progress_flag(ioc);
1663 goto out; 1579 goto out;
1664 } 1580 }
1665 dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT "TaskMgmt request (mf=%p)\n", 1581 dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT "TaskMgmt request (mf=%p)\n",
1666 ioc->name, mf)); 1582 ioc->name, mf));
1667 1583
1668 /* Format the Request 1584 /* Format the Request
1669 */ 1585 */
1670 pScsiTm = (SCSITaskMgmt_t *) mf; 1586 pScsiTm = (SCSITaskMgmt_t *) mf;
1671 pScsiTm->TargetID = id; 1587 pScsiTm->TargetID = id;
1672 pScsiTm->Bus = channel; 1588 pScsiTm->Bus = channel;
1673 pScsiTm->ChainOffset = 0; 1589 pScsiTm->ChainOffset = 0;
1674 pScsiTm->Function = MPI_FUNCTION_SCSI_TASK_MGMT; 1590 pScsiTm->Function = MPI_FUNCTION_SCSI_TASK_MGMT;
1675 1591
1676 pScsiTm->Reserved = 0; 1592 pScsiTm->Reserved = 0;
1677 pScsiTm->TaskType = type; 1593 pScsiTm->TaskType = type;
1678 pScsiTm->Reserved1 = 0; 1594 pScsiTm->Reserved1 = 0;
1679 pScsiTm->MsgFlags = (type == MPI_SCSITASKMGMT_TASKTYPE_RESET_BUS) 1595 pScsiTm->MsgFlags = (type == MPI_SCSITASKMGMT_TASKTYPE_RESET_BUS)
1680 ? MPI_SCSITASKMGMT_MSGFLAGS_LIPRESET_RESET_OPTION : 0; 1596 ? MPI_SCSITASKMGMT_MSGFLAGS_LIPRESET_RESET_OPTION : 0;
1681 1597
1682 int_to_scsilun(lun, (struct scsi_lun *)pScsiTm->LUN); 1598 int_to_scsilun(lun, (struct scsi_lun *)pScsiTm->LUN);
1683 1599
1684 for (ii=0; ii < 7; ii++) 1600 for (ii=0; ii < 7; ii++)
1685 pScsiTm->Reserved2[ii] = 0; 1601 pScsiTm->Reserved2[ii] = 0;
1686 1602
1687 pScsiTm->TaskMsgContext = ctx2abort; 1603 pScsiTm->TaskMsgContext = ctx2abort;
1688 1604
1689 dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT "TaskMgmt: ctx2abort (0x%08x) " 1605 dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT "TaskMgmt: ctx2abort (0x%08x) "
1690 "task_type = 0x%02X, timeout = %ld\n", ioc->name, ctx2abort, 1606 "task_type = 0x%02X, timeout = %ld\n", ioc->name, ctx2abort,
1691 type, timeout)); 1607 type, timeout));
1692 1608
1693 DBG_DUMP_TM_REQUEST_FRAME(ioc, (u32 *)pScsiTm); 1609 DBG_DUMP_TM_REQUEST_FRAME(ioc, (u32 *)pScsiTm);
1694 1610
1695 INITIALIZE_MGMT_STATUS(ioc->taskmgmt_cmds.status) 1611 INITIALIZE_MGMT_STATUS(ioc->taskmgmt_cmds.status)
1696 time_count = jiffies; 1612 time_count = jiffies;
1697 if ((ioc->facts.IOCCapabilities & MPI_IOCFACTS_CAPABILITY_HIGH_PRI_Q) && 1613 if ((ioc->facts.IOCCapabilities & MPI_IOCFACTS_CAPABILITY_HIGH_PRI_Q) &&
1698 (ioc->facts.MsgVersion >= MPI_VERSION_01_05)) 1614 (ioc->facts.MsgVersion >= MPI_VERSION_01_05))
1699 mpt_put_msg_frame_hi_pri(ioc->TaskCtx, ioc, mf); 1615 mpt_put_msg_frame_hi_pri(ioc->TaskCtx, ioc, mf);
1700 else { 1616 else {
1701 retval = mpt_send_handshake_request(ioc->TaskCtx, ioc, 1617 retval = mpt_send_handshake_request(ioc->TaskCtx, ioc,
1702 sizeof(SCSITaskMgmt_t), (u32*)pScsiTm, CAN_SLEEP); 1618 sizeof(SCSITaskMgmt_t), (u32*)pScsiTm, CAN_SLEEP);
1703 if (retval) { 1619 if (retval) {
1704 dfailprintk(ioc, printk(MYIOC_s_ERR_FMT 1620 dfailprintk(ioc, printk(MYIOC_s_ERR_FMT
1705 "TaskMgmt handshake FAILED!(mf=%p, rc=%d) \n", 1621 "TaskMgmt handshake FAILED!(mf=%p, rc=%d) \n",
1706 ioc->name, mf, retval)); 1622 ioc->name, mf, retval));
1707 mpt_free_msg_frame(ioc, mf); 1623 mpt_free_msg_frame(ioc, mf);
1708 mpt_clear_taskmgmt_in_progress_flag(ioc); 1624 mpt_clear_taskmgmt_in_progress_flag(ioc);
1709 goto out; 1625 goto out;
1710 } 1626 }
1711 } 1627 }
1712 1628
1713 timeleft = wait_for_completion_timeout(&ioc->taskmgmt_cmds.done, 1629 timeleft = wait_for_completion_timeout(&ioc->taskmgmt_cmds.done,
1714 timeout*HZ); 1630 timeout*HZ);
1715 if (!(ioc->taskmgmt_cmds.status & MPT_MGMT_STATUS_COMMAND_GOOD)) { 1631 if (!(ioc->taskmgmt_cmds.status & MPT_MGMT_STATUS_COMMAND_GOOD)) {
1716 retval = FAILED; 1632 retval = FAILED;
1717 dtmprintk(ioc, printk(MYIOC_s_ERR_FMT 1633 dtmprintk(ioc, printk(MYIOC_s_ERR_FMT
1718 "TaskMgmt TIMED OUT!(mf=%p)\n", ioc->name, mf)); 1634 "TaskMgmt TIMED OUT!(mf=%p)\n", ioc->name, mf));
1719 mpt_clear_taskmgmt_in_progress_flag(ioc); 1635 mpt_clear_taskmgmt_in_progress_flag(ioc);
1720 if (ioc->taskmgmt_cmds.status & MPT_MGMT_STATUS_DID_IOCRESET) 1636 if (ioc->taskmgmt_cmds.status & MPT_MGMT_STATUS_DID_IOCRESET)
1721 goto out; 1637 goto out;
1722 issue_hard_reset = 1; 1638 issue_hard_reset = 1;
1723 goto out; 1639 goto out;
1724 } 1640 }
1725 1641
1726 retval = mptscsih_taskmgmt_reply(ioc, type, 1642 retval = mptscsih_taskmgmt_reply(ioc, type,
1727 (SCSITaskMgmtReply_t *) ioc->taskmgmt_cmds.reply); 1643 (SCSITaskMgmtReply_t *) ioc->taskmgmt_cmds.reply);
1728 1644
1729 dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT 1645 dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT
1730 "TaskMgmt completed (%d seconds)\n", 1646 "TaskMgmt completed (%d seconds)\n",
1731 ioc->name, jiffies_to_msecs(jiffies - time_count)/1000)); 1647 ioc->name, jiffies_to_msecs(jiffies - time_count)/1000));
1732 1648
1733 out: 1649 out:
1734 1650
1735 CLEAR_MGMT_STATUS(ioc->taskmgmt_cmds.status) 1651 CLEAR_MGMT_STATUS(ioc->taskmgmt_cmds.status)
1736 if (issue_hard_reset) { 1652 if (issue_hard_reset) {
1737 printk(MYIOC_s_WARN_FMT 1653 printk(MYIOC_s_WARN_FMT
1738 "Issuing Reset from %s!! doorbell=0x%08x\n", 1654 "Issuing Reset from %s!! doorbell=0x%08x\n",
1739 ioc->name, __func__, mpt_GetIocState(ioc, 0)); 1655 ioc->name, __func__, mpt_GetIocState(ioc, 0));
1740 retval = (ioc->bus_type == SAS) ? 1656 retval = (ioc->bus_type == SAS) ?
1741 mpt_HardResetHandler(ioc, CAN_SLEEP) : 1657 mpt_HardResetHandler(ioc, CAN_SLEEP) :
1742 mpt_Soft_Hard_ResetHandler(ioc, CAN_SLEEP); 1658 mpt_Soft_Hard_ResetHandler(ioc, CAN_SLEEP);
1743 mpt_free_msg_frame(ioc, mf); 1659 mpt_free_msg_frame(ioc, mf);
1744 } 1660 }
1745 1661
1746 retval = (retval == 0) ? 0 : FAILED; 1662 retval = (retval == 0) ? 0 : FAILED;
1747 mutex_unlock(&ioc->taskmgmt_cmds.mutex); 1663 mutex_unlock(&ioc->taskmgmt_cmds.mutex);
1748 return retval; 1664 return retval;
1749 } 1665 }
1750 EXPORT_SYMBOL(mptscsih_IssueTaskMgmt); 1666 EXPORT_SYMBOL(mptscsih_IssueTaskMgmt);
1751 1667
1752 static int 1668 static int
1753 mptscsih_get_tm_timeout(MPT_ADAPTER *ioc) 1669 mptscsih_get_tm_timeout(MPT_ADAPTER *ioc)
1754 { 1670 {
1755 switch (ioc->bus_type) { 1671 switch (ioc->bus_type) {
1756 case FC: 1672 case FC:
1757 return 40; 1673 return 40;
1758 case SAS: 1674 case SAS:
1759 return 30; 1675 return 30;
1760 case SPI: 1676 case SPI:
1761 default: 1677 default:
1762 return 10; 1678 return 10;
1763 } 1679 }
1764 } 1680 }
1765 1681
1766 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/ 1682 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
1767 /** 1683 /**
1768 * mptscsih_abort - Abort linux scsi_cmnd routine, new_eh variant 1684 * mptscsih_abort - Abort linux scsi_cmnd routine, new_eh variant
1769 * @SCpnt: Pointer to scsi_cmnd structure, IO to be aborted 1685 * @SCpnt: Pointer to scsi_cmnd structure, IO to be aborted
1770 * 1686 *
1771 * (linux scsi_host_template.eh_abort_handler routine) 1687 * (linux scsi_host_template.eh_abort_handler routine)
1772 * 1688 *
1773 * Returns SUCCESS or FAILED. 1689 * Returns SUCCESS or FAILED.
1774 **/ 1690 **/
1775 int 1691 int
1776 mptscsih_abort(struct scsi_cmnd * SCpnt) 1692 mptscsih_abort(struct scsi_cmnd * SCpnt)
1777 { 1693 {
1778 MPT_SCSI_HOST *hd; 1694 MPT_SCSI_HOST *hd;
1779 MPT_FRAME_HDR *mf; 1695 MPT_FRAME_HDR *mf;
1780 u32 ctx2abort; 1696 u32 ctx2abort;
1781 int scpnt_idx; 1697 int scpnt_idx;
1782 int retval; 1698 int retval;
1783 VirtDevice *vdevice; 1699 VirtDevice *vdevice;
1784 MPT_ADAPTER *ioc; 1700 MPT_ADAPTER *ioc;
1785 1701
1786 /* If we can't locate our host adapter structure, return FAILED status. 1702 /* If we can't locate our host adapter structure, return FAILED status.
1787 */ 1703 */
1788 if ((hd = shost_priv(SCpnt->device->host)) == NULL) { 1704 if ((hd = shost_priv(SCpnt->device->host)) == NULL) {
1789 SCpnt->result = DID_RESET << 16; 1705 SCpnt->result = DID_RESET << 16;
1790 SCpnt->scsi_done(SCpnt); 1706 SCpnt->scsi_done(SCpnt);
1791 printk(KERN_ERR MYNAM ": task abort: " 1707 printk(KERN_ERR MYNAM ": task abort: "
1792 "can't locate host! (sc=%p)\n", SCpnt); 1708 "can't locate host! (sc=%p)\n", SCpnt);
1793 return FAILED; 1709 return FAILED;
1794 } 1710 }
1795 1711
1796 ioc = hd->ioc; 1712 ioc = hd->ioc;
1797 printk(MYIOC_s_INFO_FMT "attempting task abort! (sc=%p)\n", 1713 printk(MYIOC_s_INFO_FMT "attempting task abort! (sc=%p)\n",
1798 ioc->name, SCpnt); 1714 ioc->name, SCpnt);
1799 scsi_print_command(SCpnt); 1715 scsi_print_command(SCpnt);
1800 1716
1801 vdevice = SCpnt->device->hostdata; 1717 vdevice = SCpnt->device->hostdata;
1802 if (!vdevice || !vdevice->vtarget) { 1718 if (!vdevice || !vdevice->vtarget) {
1803 dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT 1719 dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT
1804 "task abort: device has been deleted (sc=%p)\n", 1720 "task abort: device has been deleted (sc=%p)\n",
1805 ioc->name, SCpnt)); 1721 ioc->name, SCpnt));
1806 SCpnt->result = DID_NO_CONNECT << 16; 1722 SCpnt->result = DID_NO_CONNECT << 16;
1807 SCpnt->scsi_done(SCpnt); 1723 SCpnt->scsi_done(SCpnt);
1808 retval = SUCCESS; 1724 retval = SUCCESS;
1809 goto out; 1725 goto out;
1810 } 1726 }
1811 1727
1812 /* Task aborts are not supported for hidden raid components. 1728 /* Task aborts are not supported for hidden raid components.
1813 */ 1729 */
1814 if (vdevice->vtarget->tflags & MPT_TARGET_FLAGS_RAID_COMPONENT) { 1730 if (vdevice->vtarget->tflags & MPT_TARGET_FLAGS_RAID_COMPONENT) {
1815 dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT 1731 dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT
1816 "task abort: hidden raid component (sc=%p)\n", 1732 "task abort: hidden raid component (sc=%p)\n",
1817 ioc->name, SCpnt)); 1733 ioc->name, SCpnt));
1818 SCpnt->result = DID_RESET << 16; 1734 SCpnt->result = DID_RESET << 16;
1819 retval = FAILED; 1735 retval = FAILED;
1820 goto out; 1736 goto out;
1821 } 1737 }
1822 1738
1823 /* Task aborts are not supported for volumes. 1739 /* Task aborts are not supported for volumes.
1824 */ 1740 */
1825 if (vdevice->vtarget->raidVolume) { 1741 if (vdevice->vtarget->raidVolume) {
1826 dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT 1742 dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT
1827 "task abort: raid volume (sc=%p)\n", 1743 "task abort: raid volume (sc=%p)\n",
1828 ioc->name, SCpnt)); 1744 ioc->name, SCpnt));
1829 SCpnt->result = DID_RESET << 16; 1745 SCpnt->result = DID_RESET << 16;
1830 retval = FAILED; 1746 retval = FAILED;
1831 goto out; 1747 goto out;
1832 } 1748 }
1833 1749
1834 /* Find this command 1750 /* Find this command
1835 */ 1751 */
1836 if ((scpnt_idx = SCPNT_TO_LOOKUP_IDX(ioc, SCpnt)) < 0) { 1752 if ((scpnt_idx = SCPNT_TO_LOOKUP_IDX(ioc, SCpnt)) < 0) {
1837 /* Cmd not found in ScsiLookup. 1753 /* Cmd not found in ScsiLookup.
1838 * Do OS callback. 1754 * Do OS callback.
1839 */ 1755 */
1840 SCpnt->result = DID_RESET << 16; 1756 SCpnt->result = DID_RESET << 16;
1841 dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT "task abort: " 1757 dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT "task abort: "
1842 "Command not in the active list! (sc=%p)\n", ioc->name, 1758 "Command not in the active list! (sc=%p)\n", ioc->name,
1843 SCpnt)); 1759 SCpnt));
1844 retval = SUCCESS; 1760 retval = SUCCESS;
1845 goto out; 1761 goto out;
1846 } 1762 }
1847 1763
1848 if (ioc->timeouts < -1) 1764 if (ioc->timeouts < -1)
1849 ioc->timeouts++; 1765 ioc->timeouts++;
1850 1766
1851 if (mpt_fwfault_debug) 1767 if (mpt_fwfault_debug)
1852 mpt_halt_firmware(ioc); 1768 mpt_halt_firmware(ioc);
1853 1769
1854 /* Most important! Set TaskMsgContext to SCpnt's MsgContext! 1770 /* Most important! Set TaskMsgContext to SCpnt's MsgContext!
1855 * (the IO to be ABORT'd) 1771 * (the IO to be ABORT'd)
1856 * 1772 *
1857 * NOTE: Since we do not byteswap MsgContext, we do not 1773 * NOTE: Since we do not byteswap MsgContext, we do not
1858 * swap it here either. It is an opaque cookie to 1774 * swap it here either. It is an opaque cookie to
1859 * the controller, so it does not matter. -DaveM 1775 * the controller, so it does not matter. -DaveM
1860 */ 1776 */
1861 mf = MPT_INDEX_2_MFPTR(ioc, scpnt_idx); 1777 mf = MPT_INDEX_2_MFPTR(ioc, scpnt_idx);
1862 ctx2abort = mf->u.frame.hwhdr.msgctxu.MsgContext; 1778 ctx2abort = mf->u.frame.hwhdr.msgctxu.MsgContext;
1863 retval = mptscsih_IssueTaskMgmt(hd, 1779 retval = mptscsih_IssueTaskMgmt(hd,
1864 MPI_SCSITASKMGMT_TASKTYPE_ABORT_TASK, 1780 MPI_SCSITASKMGMT_TASKTYPE_ABORT_TASK,
1865 vdevice->vtarget->channel, 1781 vdevice->vtarget->channel,
1866 vdevice->vtarget->id, vdevice->lun, 1782 vdevice->vtarget->id, vdevice->lun,
1867 ctx2abort, mptscsih_get_tm_timeout(ioc)); 1783 ctx2abort, mptscsih_get_tm_timeout(ioc));
1868 1784
1869 if (SCPNT_TO_LOOKUP_IDX(ioc, SCpnt) == scpnt_idx) { 1785 if (SCPNT_TO_LOOKUP_IDX(ioc, SCpnt) == scpnt_idx) {
1870 dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT 1786 dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT
1871 "task abort: command still in active list! (sc=%p)\n", 1787 "task abort: command still in active list! (sc=%p)\n",
1872 ioc->name, SCpnt)); 1788 ioc->name, SCpnt));
1873 retval = FAILED; 1789 retval = FAILED;
1874 } else { 1790 } else {
1875 dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT 1791 dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT
1876 "task abort: command cleared from active list! (sc=%p)\n", 1792 "task abort: command cleared from active list! (sc=%p)\n",
1877 ioc->name, SCpnt)); 1793 ioc->name, SCpnt));
1878 retval = SUCCESS; 1794 retval = SUCCESS;
1879 } 1795 }
1880 1796
1881 out: 1797 out:
1882 printk(MYIOC_s_INFO_FMT "task abort: %s (rv=%04x) (sc=%p)\n", 1798 printk(MYIOC_s_INFO_FMT "task abort: %s (rv=%04x) (sc=%p)\n",
1883 ioc->name, ((retval == SUCCESS) ? "SUCCESS" : "FAILED"), retval, 1799 ioc->name, ((retval == SUCCESS) ? "SUCCESS" : "FAILED"), retval,
1884 SCpnt); 1800 SCpnt);
1885 1801
1886 return retval; 1802 return retval;
1887 } 1803 }
1888 1804
1889 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/ 1805 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
1890 /** 1806 /**
1891 * mptscsih_dev_reset - Perform a SCSI TARGET_RESET! new_eh variant 1807 * mptscsih_dev_reset - Perform a SCSI TARGET_RESET! new_eh variant
1892 * @SCpnt: Pointer to scsi_cmnd structure, IO which reset is due to 1808 * @SCpnt: Pointer to scsi_cmnd structure, IO which reset is due to
1893 * 1809 *
1894 * (linux scsi_host_template.eh_dev_reset_handler routine) 1810 * (linux scsi_host_template.eh_dev_reset_handler routine)
1895 * 1811 *
1896 * Returns SUCCESS or FAILED. 1812 * Returns SUCCESS or FAILED.
1897 **/ 1813 **/
1898 int 1814 int
1899 mptscsih_dev_reset(struct scsi_cmnd * SCpnt) 1815 mptscsih_dev_reset(struct scsi_cmnd * SCpnt)
1900 { 1816 {
1901 MPT_SCSI_HOST *hd; 1817 MPT_SCSI_HOST *hd;
1902 int retval; 1818 int retval;
1903 VirtDevice *vdevice; 1819 VirtDevice *vdevice;
1904 MPT_ADAPTER *ioc; 1820 MPT_ADAPTER *ioc;
1905 1821
1906 /* If we can't locate our host adapter structure, return FAILED status. 1822 /* If we can't locate our host adapter structure, return FAILED status.
1907 */ 1823 */
1908 if ((hd = shost_priv(SCpnt->device->host)) == NULL){ 1824 if ((hd = shost_priv(SCpnt->device->host)) == NULL){
1909 printk(KERN_ERR MYNAM ": target reset: " 1825 printk(KERN_ERR MYNAM ": target reset: "
1910 "Can't locate host! (sc=%p)\n", SCpnt); 1826 "Can't locate host! (sc=%p)\n", SCpnt);
1911 return FAILED; 1827 return FAILED;
1912 } 1828 }
1913 1829
1914 ioc = hd->ioc; 1830 ioc = hd->ioc;
1915 printk(MYIOC_s_INFO_FMT "attempting target reset! (sc=%p)\n", 1831 printk(MYIOC_s_INFO_FMT "attempting target reset! (sc=%p)\n",
1916 ioc->name, SCpnt); 1832 ioc->name, SCpnt);
1917 scsi_print_command(SCpnt); 1833 scsi_print_command(SCpnt);
1918 1834
1919 vdevice = SCpnt->device->hostdata; 1835 vdevice = SCpnt->device->hostdata;
1920 if (!vdevice || !vdevice->vtarget) { 1836 if (!vdevice || !vdevice->vtarget) {
1921 retval = 0; 1837 retval = 0;
1922 goto out; 1838 goto out;
1923 } 1839 }
1924 1840
1925 /* Target reset to hidden raid component is not supported 1841 /* Target reset to hidden raid component is not supported
1926 */ 1842 */
1927 if (vdevice->vtarget->tflags & MPT_TARGET_FLAGS_RAID_COMPONENT) { 1843 if (vdevice->vtarget->tflags & MPT_TARGET_FLAGS_RAID_COMPONENT) {
1928 retval = FAILED; 1844 retval = FAILED;
1929 goto out; 1845 goto out;
1930 } 1846 }
1931 1847
1932 retval = mptscsih_IssueTaskMgmt(hd, 1848 retval = mptscsih_IssueTaskMgmt(hd,
1933 MPI_SCSITASKMGMT_TASKTYPE_TARGET_RESET, 1849 MPI_SCSITASKMGMT_TASKTYPE_TARGET_RESET,
1934 vdevice->vtarget->channel, 1850 vdevice->vtarget->channel,
1935 vdevice->vtarget->id, 0, 0, 1851 vdevice->vtarget->id, 0, 0,
1936 mptscsih_get_tm_timeout(ioc)); 1852 mptscsih_get_tm_timeout(ioc));
1937 1853
1938 out: 1854 out:
1939 printk (MYIOC_s_INFO_FMT "target reset: %s (sc=%p)\n", 1855 printk (MYIOC_s_INFO_FMT "target reset: %s (sc=%p)\n",
1940 ioc->name, ((retval == 0) ? "SUCCESS" : "FAILED" ), SCpnt); 1856 ioc->name, ((retval == 0) ? "SUCCESS" : "FAILED" ), SCpnt);
1941 1857
1942 if (retval == 0) 1858 if (retval == 0)
1943 return SUCCESS; 1859 return SUCCESS;
1944 else 1860 else
1945 return FAILED; 1861 return FAILED;
1946 } 1862 }
1947 1863
1948 1864
1949 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/ 1865 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
1950 /** 1866 /**
1951 * mptscsih_bus_reset - Perform a SCSI BUS_RESET! new_eh variant 1867 * mptscsih_bus_reset - Perform a SCSI BUS_RESET! new_eh variant
1952 * @SCpnt: Pointer to scsi_cmnd structure, IO which reset is due to 1868 * @SCpnt: Pointer to scsi_cmnd structure, IO which reset is due to
1953 * 1869 *
1954 * (linux scsi_host_template.eh_bus_reset_handler routine) 1870 * (linux scsi_host_template.eh_bus_reset_handler routine)
1955 * 1871 *
1956 * Returns SUCCESS or FAILED. 1872 * Returns SUCCESS or FAILED.
1957 **/ 1873 **/
1958 int 1874 int
1959 mptscsih_bus_reset(struct scsi_cmnd * SCpnt) 1875 mptscsih_bus_reset(struct scsi_cmnd * SCpnt)
1960 { 1876 {
1961 MPT_SCSI_HOST *hd; 1877 MPT_SCSI_HOST *hd;
1962 int retval; 1878 int retval;
1963 VirtDevice *vdevice; 1879 VirtDevice *vdevice;
1964 MPT_ADAPTER *ioc; 1880 MPT_ADAPTER *ioc;
1965 1881
1966 /* If we can't locate our host adapter structure, return FAILED status. 1882 /* If we can't locate our host adapter structure, return FAILED status.
1967 */ 1883 */
1968 if ((hd = shost_priv(SCpnt->device->host)) == NULL){ 1884 if ((hd = shost_priv(SCpnt->device->host)) == NULL){
1969 printk(KERN_ERR MYNAM ": bus reset: " 1885 printk(KERN_ERR MYNAM ": bus reset: "
1970 "Can't locate host! (sc=%p)\n", SCpnt); 1886 "Can't locate host! (sc=%p)\n", SCpnt);
1971 return FAILED; 1887 return FAILED;
1972 } 1888 }
1973 1889
1974 ioc = hd->ioc; 1890 ioc = hd->ioc;
1975 printk(MYIOC_s_INFO_FMT "attempting bus reset! (sc=%p)\n", 1891 printk(MYIOC_s_INFO_FMT "attempting bus reset! (sc=%p)\n",
1976 ioc->name, SCpnt); 1892 ioc->name, SCpnt);
1977 scsi_print_command(SCpnt); 1893 scsi_print_command(SCpnt);
1978 1894
1979 if (ioc->timeouts < -1) 1895 if (ioc->timeouts < -1)
1980 ioc->timeouts++; 1896 ioc->timeouts++;
1981 1897
1982 vdevice = SCpnt->device->hostdata; 1898 vdevice = SCpnt->device->hostdata;
1983 if (!vdevice || !vdevice->vtarget) 1899 if (!vdevice || !vdevice->vtarget)
1984 return SUCCESS; 1900 return SUCCESS;
1985 retval = mptscsih_IssueTaskMgmt(hd, 1901 retval = mptscsih_IssueTaskMgmt(hd,
1986 MPI_SCSITASKMGMT_TASKTYPE_RESET_BUS, 1902 MPI_SCSITASKMGMT_TASKTYPE_RESET_BUS,
1987 vdevice->vtarget->channel, 0, 0, 0, 1903 vdevice->vtarget->channel, 0, 0, 0,
1988 mptscsih_get_tm_timeout(ioc)); 1904 mptscsih_get_tm_timeout(ioc));
1989 1905
1990 printk(MYIOC_s_INFO_FMT "bus reset: %s (sc=%p)\n", 1906 printk(MYIOC_s_INFO_FMT "bus reset: %s (sc=%p)\n",
1991 ioc->name, ((retval == 0) ? "SUCCESS" : "FAILED" ), SCpnt); 1907 ioc->name, ((retval == 0) ? "SUCCESS" : "FAILED" ), SCpnt);
1992 1908
1993 if (retval == 0) 1909 if (retval == 0)
1994 return SUCCESS; 1910 return SUCCESS;
1995 else 1911 else
1996 return FAILED; 1912 return FAILED;
1997 } 1913 }
1998 1914
1999 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/ 1915 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
2000 /** 1916 /**
2001 * mptscsih_host_reset - Perform a SCSI host adapter RESET (new_eh variant) 1917 * mptscsih_host_reset - Perform a SCSI host adapter RESET (new_eh variant)
2002 * @SCpnt: Pointer to scsi_cmnd structure, IO which reset is due to 1918 * @SCpnt: Pointer to scsi_cmnd structure, IO which reset is due to
2003 * 1919 *
2004 * (linux scsi_host_template.eh_host_reset_handler routine) 1920 * (linux scsi_host_template.eh_host_reset_handler routine)
2005 * 1921 *
2006 * Returns SUCCESS or FAILED. 1922 * Returns SUCCESS or FAILED.
2007 */ 1923 */
2008 int 1924 int
2009 mptscsih_host_reset(struct scsi_cmnd *SCpnt) 1925 mptscsih_host_reset(struct scsi_cmnd *SCpnt)
2010 { 1926 {
2011 MPT_SCSI_HOST * hd; 1927 MPT_SCSI_HOST * hd;
2012 int status = SUCCESS; 1928 int status = SUCCESS;
2013 MPT_ADAPTER *ioc; 1929 MPT_ADAPTER *ioc;
2014 int retval; 1930 int retval;
2015 1931
2016 /* If we can't locate the host to reset, then we failed. */ 1932 /* If we can't locate the host to reset, then we failed. */
2017 if ((hd = shost_priv(SCpnt->device->host)) == NULL){ 1933 if ((hd = shost_priv(SCpnt->device->host)) == NULL){
2018 printk(KERN_ERR MYNAM ": host reset: " 1934 printk(KERN_ERR MYNAM ": host reset: "
2019 "Can't locate host! (sc=%p)\n", SCpnt); 1935 "Can't locate host! (sc=%p)\n", SCpnt);
2020 return FAILED; 1936 return FAILED;
2021 } 1937 }
2022 1938
2023 /* make sure we have no outstanding commands at this stage */ 1939 /* make sure we have no outstanding commands at this stage */
2024 mptscsih_flush_running_cmds(hd); 1940 mptscsih_flush_running_cmds(hd);
2025 1941
2026 ioc = hd->ioc; 1942 ioc = hd->ioc;
2027 printk(MYIOC_s_INFO_FMT "attempting host reset! (sc=%p)\n", 1943 printk(MYIOC_s_INFO_FMT "attempting host reset! (sc=%p)\n",
2028 ioc->name, SCpnt); 1944 ioc->name, SCpnt);
2029 1945
2030 /* If our attempts to reset the host failed, then return a failed 1946 /* If our attempts to reset the host failed, then return a failed
2031 * status. The host will be taken off line by the SCSI mid-layer. 1947 * status. The host will be taken off line by the SCSI mid-layer.
2032 */ 1948 */
2033 retval = mpt_Soft_Hard_ResetHandler(ioc, CAN_SLEEP); 1949 retval = mpt_Soft_Hard_ResetHandler(ioc, CAN_SLEEP);
2034 if (retval < 0) 1950 if (retval < 0)
2035 status = FAILED; 1951 status = FAILED;
2036 else 1952 else
2037 status = SUCCESS; 1953 status = SUCCESS;
2038 1954
2039 printk(MYIOC_s_INFO_FMT "host reset: %s (sc=%p)\n", 1955 printk(MYIOC_s_INFO_FMT "host reset: %s (sc=%p)\n",
2040 ioc->name, ((retval == 0) ? "SUCCESS" : "FAILED" ), SCpnt); 1956 ioc->name, ((retval == 0) ? "SUCCESS" : "FAILED" ), SCpnt);
2041 1957
2042 return status; 1958 return status;
2043 } 1959 }
2044 1960
2045 static int 1961 static int
2046 mptscsih_taskmgmt_reply(MPT_ADAPTER *ioc, u8 type, 1962 mptscsih_taskmgmt_reply(MPT_ADAPTER *ioc, u8 type,
2047 SCSITaskMgmtReply_t *pScsiTmReply) 1963 SCSITaskMgmtReply_t *pScsiTmReply)
2048 { 1964 {
2049 u16 iocstatus; 1965 u16 iocstatus;
2050 u32 termination_count; 1966 u32 termination_count;
2051 int retval; 1967 int retval;
2052 1968
2053 if (!(ioc->taskmgmt_cmds.status & MPT_MGMT_STATUS_RF_VALID)) { 1969 if (!(ioc->taskmgmt_cmds.status & MPT_MGMT_STATUS_RF_VALID)) {
2054 retval = FAILED; 1970 retval = FAILED;
2055 goto out; 1971 goto out;
2056 } 1972 }
2057 1973
2058 DBG_DUMP_TM_REPLY_FRAME(ioc, (u32 *)pScsiTmReply); 1974 DBG_DUMP_TM_REPLY_FRAME(ioc, (u32 *)pScsiTmReply);
2059 1975
2060 iocstatus = le16_to_cpu(pScsiTmReply->IOCStatus) & MPI_IOCSTATUS_MASK; 1976 iocstatus = le16_to_cpu(pScsiTmReply->IOCStatus) & MPI_IOCSTATUS_MASK;
2061 termination_count = le32_to_cpu(pScsiTmReply->TerminationCount); 1977 termination_count = le32_to_cpu(pScsiTmReply->TerminationCount);
2062 1978
2063 dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT 1979 dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT
2064 "TaskMgmt fw_channel = %d, fw_id = %d, task_type = 0x%02X,\n" 1980 "TaskMgmt fw_channel = %d, fw_id = %d, task_type = 0x%02X,\n"
2065 "\tiocstatus = 0x%04X, loginfo = 0x%08X, response_code = 0x%02X,\n" 1981 "\tiocstatus = 0x%04X, loginfo = 0x%08X, response_code = 0x%02X,\n"
2066 "\tterm_cmnds = %d\n", ioc->name, pScsiTmReply->Bus, 1982 "\tterm_cmnds = %d\n", ioc->name, pScsiTmReply->Bus,
2067 pScsiTmReply->TargetID, type, le16_to_cpu(pScsiTmReply->IOCStatus), 1983 pScsiTmReply->TargetID, type, le16_to_cpu(pScsiTmReply->IOCStatus),
2068 le32_to_cpu(pScsiTmReply->IOCLogInfo), pScsiTmReply->ResponseCode, 1984 le32_to_cpu(pScsiTmReply->IOCLogInfo), pScsiTmReply->ResponseCode,
2069 termination_count)); 1985 termination_count));
2070 1986
2071 if (ioc->facts.MsgVersion >= MPI_VERSION_01_05 && 1987 if (ioc->facts.MsgVersion >= MPI_VERSION_01_05 &&
2072 pScsiTmReply->ResponseCode) 1988 pScsiTmReply->ResponseCode)
2073 mptscsih_taskmgmt_response_code(ioc, 1989 mptscsih_taskmgmt_response_code(ioc,
2074 pScsiTmReply->ResponseCode); 1990 pScsiTmReply->ResponseCode);
2075 1991
2076 if (iocstatus == MPI_IOCSTATUS_SUCCESS) { 1992 if (iocstatus == MPI_IOCSTATUS_SUCCESS) {
2077 retval = 0; 1993 retval = 0;
2078 goto out; 1994 goto out;
2079 } 1995 }
2080 1996
2081 retval = FAILED; 1997 retval = FAILED;
2082 if (type == MPI_SCSITASKMGMT_TASKTYPE_ABORT_TASK) { 1998 if (type == MPI_SCSITASKMGMT_TASKTYPE_ABORT_TASK) {
2083 if (termination_count == 1) 1999 if (termination_count == 1)
2084 retval = 0; 2000 retval = 0;
2085 goto out; 2001 goto out;
2086 } 2002 }
2087 2003
2088 if (iocstatus == MPI_IOCSTATUS_SCSI_TASK_TERMINATED || 2004 if (iocstatus == MPI_IOCSTATUS_SCSI_TASK_TERMINATED ||
2089 iocstatus == MPI_IOCSTATUS_SCSI_IOC_TERMINATED) 2005 iocstatus == MPI_IOCSTATUS_SCSI_IOC_TERMINATED)
2090 retval = 0; 2006 retval = 0;
2091 2007
2092 out: 2008 out:
2093 return retval; 2009 return retval;
2094 } 2010 }
2095 2011
2096 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/ 2012 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
2097 void 2013 void
2098 mptscsih_taskmgmt_response_code(MPT_ADAPTER *ioc, u8 response_code) 2014 mptscsih_taskmgmt_response_code(MPT_ADAPTER *ioc, u8 response_code)
2099 { 2015 {
2100 char *desc; 2016 char *desc;
2101 2017
2102 switch (response_code) { 2018 switch (response_code) {
2103 case MPI_SCSITASKMGMT_RSP_TM_COMPLETE: 2019 case MPI_SCSITASKMGMT_RSP_TM_COMPLETE:
2104 desc = "The task completed."; 2020 desc = "The task completed.";
2105 break; 2021 break;
2106 case MPI_SCSITASKMGMT_RSP_INVALID_FRAME: 2022 case MPI_SCSITASKMGMT_RSP_INVALID_FRAME:
2107 desc = "The IOC received an invalid frame status."; 2023 desc = "The IOC received an invalid frame status.";
2108 break; 2024 break;
2109 case MPI_SCSITASKMGMT_RSP_TM_NOT_SUPPORTED: 2025 case MPI_SCSITASKMGMT_RSP_TM_NOT_SUPPORTED:
2110 desc = "The task type is not supported."; 2026 desc = "The task type is not supported.";
2111 break; 2027 break;
2112 case MPI_SCSITASKMGMT_RSP_TM_FAILED: 2028 case MPI_SCSITASKMGMT_RSP_TM_FAILED:
2113 desc = "The requested task failed."; 2029 desc = "The requested task failed.";
2114 break; 2030 break;
2115 case MPI_SCSITASKMGMT_RSP_TM_SUCCEEDED: 2031 case MPI_SCSITASKMGMT_RSP_TM_SUCCEEDED:
2116 desc = "The task completed successfully."; 2032 desc = "The task completed successfully.";
2117 break; 2033 break;
2118 case MPI_SCSITASKMGMT_RSP_TM_INVALID_LUN: 2034 case MPI_SCSITASKMGMT_RSP_TM_INVALID_LUN:
2119 desc = "The LUN request is invalid."; 2035 desc = "The LUN request is invalid.";
2120 break; 2036 break;
2121 case MPI_SCSITASKMGMT_RSP_IO_QUEUED_ON_IOC: 2037 case MPI_SCSITASKMGMT_RSP_IO_QUEUED_ON_IOC:
2122 desc = "The task is in the IOC queue and has not been sent to target."; 2038 desc = "The task is in the IOC queue and has not been sent to target.";
2123 break; 2039 break;
2124 default: 2040 default:
2125 desc = "unknown"; 2041 desc = "unknown";
2126 break; 2042 break;
2127 } 2043 }
2128 printk(MYIOC_s_INFO_FMT "Response Code(0x%08x): F/W: %s\n", 2044 printk(MYIOC_s_INFO_FMT "Response Code(0x%08x): F/W: %s\n",
2129 ioc->name, response_code, desc); 2045 ioc->name, response_code, desc);
2130 } 2046 }
2131 EXPORT_SYMBOL(mptscsih_taskmgmt_response_code); 2047 EXPORT_SYMBOL(mptscsih_taskmgmt_response_code);
2132 2048
2133 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/ 2049 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
2134 /** 2050 /**
2135 * mptscsih_taskmgmt_complete - Registered with Fusion MPT base driver 2051 * mptscsih_taskmgmt_complete - Registered with Fusion MPT base driver
2136 * @ioc: Pointer to MPT_ADAPTER structure 2052 * @ioc: Pointer to MPT_ADAPTER structure
2137 * @mf: Pointer to SCSI task mgmt request frame 2053 * @mf: Pointer to SCSI task mgmt request frame
2138 * @mr: Pointer to SCSI task mgmt reply frame 2054 * @mr: Pointer to SCSI task mgmt reply frame
2139 * 2055 *
2140 * This routine is called from mptbase.c::mpt_interrupt() at the completion 2056 * This routine is called from mptbase.c::mpt_interrupt() at the completion
2141 * of any SCSI task management request. 2057 * of any SCSI task management request.
2142 * This routine is registered with the MPT (base) driver at driver 2058 * This routine is registered with the MPT (base) driver at driver
2143 * load/init time via the mpt_register() API call. 2059 * load/init time via the mpt_register() API call.
2144 * 2060 *
2145 * Returns 1 indicating alloc'd request frame ptr should be freed. 2061 * Returns 1 indicating alloc'd request frame ptr should be freed.
2146 **/ 2062 **/
2147 int 2063 int
2148 mptscsih_taskmgmt_complete(MPT_ADAPTER *ioc, MPT_FRAME_HDR *mf, 2064 mptscsih_taskmgmt_complete(MPT_ADAPTER *ioc, MPT_FRAME_HDR *mf,
2149 MPT_FRAME_HDR *mr) 2065 MPT_FRAME_HDR *mr)
2150 { 2066 {
2151 dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT 2067 dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT
2152 "TaskMgmt completed (mf=%p, mr=%p)\n", ioc->name, mf, mr)); 2068 "TaskMgmt completed (mf=%p, mr=%p)\n", ioc->name, mf, mr));
2153 2069
2154 ioc->taskmgmt_cmds.status |= MPT_MGMT_STATUS_COMMAND_GOOD; 2070 ioc->taskmgmt_cmds.status |= MPT_MGMT_STATUS_COMMAND_GOOD;
2155 2071
2156 if (!mr) 2072 if (!mr)
2157 goto out; 2073 goto out;
2158 2074
2159 ioc->taskmgmt_cmds.status |= MPT_MGMT_STATUS_RF_VALID; 2075 ioc->taskmgmt_cmds.status |= MPT_MGMT_STATUS_RF_VALID;
2160 memcpy(ioc->taskmgmt_cmds.reply, mr, 2076 memcpy(ioc->taskmgmt_cmds.reply, mr,
2161 min(MPT_DEFAULT_FRAME_SIZE, 4 * mr->u.reply.MsgLength)); 2077 min(MPT_DEFAULT_FRAME_SIZE, 4 * mr->u.reply.MsgLength));
2162 out: 2078 out:
2163 if (ioc->taskmgmt_cmds.status & MPT_MGMT_STATUS_PENDING) { 2079 if (ioc->taskmgmt_cmds.status & MPT_MGMT_STATUS_PENDING) {
2164 mpt_clear_taskmgmt_in_progress_flag(ioc); 2080 mpt_clear_taskmgmt_in_progress_flag(ioc);
2165 ioc->taskmgmt_cmds.status &= ~MPT_MGMT_STATUS_PENDING; 2081 ioc->taskmgmt_cmds.status &= ~MPT_MGMT_STATUS_PENDING;
2166 complete(&ioc->taskmgmt_cmds.done); 2082 complete(&ioc->taskmgmt_cmds.done);
2167 if (ioc->bus_type == SAS) 2083 if (ioc->bus_type == SAS)
2168 ioc->schedule_target_reset(ioc); 2084 ioc->schedule_target_reset(ioc);
2169 return 1; 2085 return 1;
2170 } 2086 }
2171 return 0; 2087 return 0;
2172 } 2088 }
2173 2089
2174 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/ 2090 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
2175 /* 2091 /*
2176 * This is anyones guess quite frankly. 2092 * This is anyones guess quite frankly.
2177 */ 2093 */
2178 int 2094 int
2179 mptscsih_bios_param(struct scsi_device * sdev, struct block_device *bdev, 2095 mptscsih_bios_param(struct scsi_device * sdev, struct block_device *bdev,
2180 sector_t capacity, int geom[]) 2096 sector_t capacity, int geom[])
2181 { 2097 {
2182 int heads; 2098 int heads;
2183 int sectors; 2099 int sectors;
2184 sector_t cylinders; 2100 sector_t cylinders;
2185 ulong dummy; 2101 ulong dummy;
2186 2102
2187 heads = 64; 2103 heads = 64;
2188 sectors = 32; 2104 sectors = 32;
2189 2105
2190 dummy = heads * sectors; 2106 dummy = heads * sectors;
2191 cylinders = capacity; 2107 cylinders = capacity;
2192 sector_div(cylinders,dummy); 2108 sector_div(cylinders,dummy);
2193 2109
2194 /* 2110 /*
2195 * Handle extended translation size for logical drives 2111 * Handle extended translation size for logical drives
2196 * > 1Gb 2112 * > 1Gb
2197 */ 2113 */
2198 if ((ulong)capacity >= 0x200000) { 2114 if ((ulong)capacity >= 0x200000) {
2199 heads = 255; 2115 heads = 255;
2200 sectors = 63; 2116 sectors = 63;
2201 dummy = heads * sectors; 2117 dummy = heads * sectors;
2202 cylinders = capacity; 2118 cylinders = capacity;
2203 sector_div(cylinders,dummy); 2119 sector_div(cylinders,dummy);
2204 } 2120 }
2205 2121
2206 /* return result */ 2122 /* return result */
2207 geom[0] = heads; 2123 geom[0] = heads;
2208 geom[1] = sectors; 2124 geom[1] = sectors;
2209 geom[2] = cylinders; 2125 geom[2] = cylinders;
2210 2126
2211 return 0; 2127 return 0;
2212 } 2128 }
2213 2129
2214 /* Search IOC page 3 to determine if this is hidden physical disk 2130 /* Search IOC page 3 to determine if this is hidden physical disk
2215 * 2131 *
2216 */ 2132 */
2217 int 2133 int
2218 mptscsih_is_phys_disk(MPT_ADAPTER *ioc, u8 channel, u8 id) 2134 mptscsih_is_phys_disk(MPT_ADAPTER *ioc, u8 channel, u8 id)
2219 { 2135 {
2220 struct inactive_raid_component_info *component_info; 2136 struct inactive_raid_component_info *component_info;
2221 int i, j; 2137 int i, j;
2222 RaidPhysDiskPage1_t *phys_disk; 2138 RaidPhysDiskPage1_t *phys_disk;
2223 int rc = 0; 2139 int rc = 0;
2224 int num_paths; 2140 int num_paths;
2225 2141
2226 if (!ioc->raid_data.pIocPg3) 2142 if (!ioc->raid_data.pIocPg3)
2227 goto out; 2143 goto out;
2228 for (i = 0; i < ioc->raid_data.pIocPg3->NumPhysDisks; i++) { 2144 for (i = 0; i < ioc->raid_data.pIocPg3->NumPhysDisks; i++) {
2229 if ((id == ioc->raid_data.pIocPg3->PhysDisk[i].PhysDiskID) && 2145 if ((id == ioc->raid_data.pIocPg3->PhysDisk[i].PhysDiskID) &&
2230 (channel == ioc->raid_data.pIocPg3->PhysDisk[i].PhysDiskBus)) { 2146 (channel == ioc->raid_data.pIocPg3->PhysDisk[i].PhysDiskBus)) {
2231 rc = 1; 2147 rc = 1;
2232 goto out; 2148 goto out;
2233 } 2149 }
2234 } 2150 }
2235 2151
2236 if (ioc->bus_type != SAS) 2152 if (ioc->bus_type != SAS)
2237 goto out; 2153 goto out;
2238 2154
2239 /* 2155 /*
2240 * Check if dual path 2156 * Check if dual path
2241 */ 2157 */
2242 for (i = 0; i < ioc->raid_data.pIocPg3->NumPhysDisks; i++) { 2158 for (i = 0; i < ioc->raid_data.pIocPg3->NumPhysDisks; i++) {
2243 num_paths = mpt_raid_phys_disk_get_num_paths(ioc, 2159 num_paths = mpt_raid_phys_disk_get_num_paths(ioc,
2244 ioc->raid_data.pIocPg3->PhysDisk[i].PhysDiskNum); 2160 ioc->raid_data.pIocPg3->PhysDisk[i].PhysDiskNum);
2245 if (num_paths < 2) 2161 if (num_paths < 2)
2246 continue; 2162 continue;
2247 phys_disk = kzalloc(offsetof(RaidPhysDiskPage1_t, Path) + 2163 phys_disk = kzalloc(offsetof(RaidPhysDiskPage1_t, Path) +
2248 (num_paths * sizeof(RAID_PHYS_DISK1_PATH)), GFP_KERNEL); 2164 (num_paths * sizeof(RAID_PHYS_DISK1_PATH)), GFP_KERNEL);
2249 if (!phys_disk) 2165 if (!phys_disk)
2250 continue; 2166 continue;
2251 if ((mpt_raid_phys_disk_pg1(ioc, 2167 if ((mpt_raid_phys_disk_pg1(ioc,
2252 ioc->raid_data.pIocPg3->PhysDisk[i].PhysDiskNum, 2168 ioc->raid_data.pIocPg3->PhysDisk[i].PhysDiskNum,
2253 phys_disk))) { 2169 phys_disk))) {
2254 kfree(phys_disk); 2170 kfree(phys_disk);
2255 continue; 2171 continue;
2256 } 2172 }
2257 for (j = 0; j < num_paths; j++) { 2173 for (j = 0; j < num_paths; j++) {
2258 if ((phys_disk->Path[j].Flags & 2174 if ((phys_disk->Path[j].Flags &
2259 MPI_RAID_PHYSDISK1_FLAG_INVALID)) 2175 MPI_RAID_PHYSDISK1_FLAG_INVALID))
2260 continue; 2176 continue;
2261 if ((phys_disk->Path[j].Flags & 2177 if ((phys_disk->Path[j].Flags &
2262 MPI_RAID_PHYSDISK1_FLAG_BROKEN)) 2178 MPI_RAID_PHYSDISK1_FLAG_BROKEN))
2263 continue; 2179 continue;
2264 if ((id == phys_disk->Path[j].PhysDiskID) && 2180 if ((id == phys_disk->Path[j].PhysDiskID) &&
2265 (channel == phys_disk->Path[j].PhysDiskBus)) { 2181 (channel == phys_disk->Path[j].PhysDiskBus)) {
2266 rc = 1; 2182 rc = 1;
2267 kfree(phys_disk); 2183 kfree(phys_disk);
2268 goto out; 2184 goto out;
2269 } 2185 }
2270 } 2186 }
2271 kfree(phys_disk); 2187 kfree(phys_disk);
2272 } 2188 }
2273 2189
2274 2190
2275 /* 2191 /*
2276 * Check inactive list for matching phys disks 2192 * Check inactive list for matching phys disks
2277 */ 2193 */
2278 if (list_empty(&ioc->raid_data.inactive_list)) 2194 if (list_empty(&ioc->raid_data.inactive_list))
2279 goto out; 2195 goto out;
2280 2196
2281 mutex_lock(&ioc->raid_data.inactive_list_mutex); 2197 mutex_lock(&ioc->raid_data.inactive_list_mutex);
2282 list_for_each_entry(component_info, &ioc->raid_data.inactive_list, 2198 list_for_each_entry(component_info, &ioc->raid_data.inactive_list,
2283 list) { 2199 list) {
2284 if ((component_info->d.PhysDiskID == id) && 2200 if ((component_info->d.PhysDiskID == id) &&
2285 (component_info->d.PhysDiskBus == channel)) 2201 (component_info->d.PhysDiskBus == channel))
2286 rc = 1; 2202 rc = 1;
2287 } 2203 }
2288 mutex_unlock(&ioc->raid_data.inactive_list_mutex); 2204 mutex_unlock(&ioc->raid_data.inactive_list_mutex);
2289 2205
2290 out: 2206 out:
2291 return rc; 2207 return rc;
2292 } 2208 }
2293 EXPORT_SYMBOL(mptscsih_is_phys_disk); 2209 EXPORT_SYMBOL(mptscsih_is_phys_disk);
2294 2210
2295 u8 2211 u8
2296 mptscsih_raid_id_to_num(MPT_ADAPTER *ioc, u8 channel, u8 id) 2212 mptscsih_raid_id_to_num(MPT_ADAPTER *ioc, u8 channel, u8 id)
2297 { 2213 {
2298 struct inactive_raid_component_info *component_info; 2214 struct inactive_raid_component_info *component_info;
2299 int i, j; 2215 int i, j;
2300 RaidPhysDiskPage1_t *phys_disk; 2216 RaidPhysDiskPage1_t *phys_disk;
2301 int rc = -ENXIO; 2217 int rc = -ENXIO;
2302 int num_paths; 2218 int num_paths;
2303 2219
2304 if (!ioc->raid_data.pIocPg3) 2220 if (!ioc->raid_data.pIocPg3)
2305 goto out; 2221 goto out;
2306 for (i = 0; i < ioc->raid_data.pIocPg3->NumPhysDisks; i++) { 2222 for (i = 0; i < ioc->raid_data.pIocPg3->NumPhysDisks; i++) {
2307 if ((id == ioc->raid_data.pIocPg3->PhysDisk[i].PhysDiskID) && 2223 if ((id == ioc->raid_data.pIocPg3->PhysDisk[i].PhysDiskID) &&
2308 (channel == ioc->raid_data.pIocPg3->PhysDisk[i].PhysDiskBus)) { 2224 (channel == ioc->raid_data.pIocPg3->PhysDisk[i].PhysDiskBus)) {
2309 rc = ioc->raid_data.pIocPg3->PhysDisk[i].PhysDiskNum; 2225 rc = ioc->raid_data.pIocPg3->PhysDisk[i].PhysDiskNum;
2310 goto out; 2226 goto out;
2311 } 2227 }
2312 } 2228 }
2313 2229
2314 if (ioc->bus_type != SAS) 2230 if (ioc->bus_type != SAS)
2315 goto out; 2231 goto out;
2316 2232
2317 /* 2233 /*
2318 * Check if dual path 2234 * Check if dual path
2319 */ 2235 */
2320 for (i = 0; i < ioc->raid_data.pIocPg3->NumPhysDisks; i++) { 2236 for (i = 0; i < ioc->raid_data.pIocPg3->NumPhysDisks; i++) {
2321 num_paths = mpt_raid_phys_disk_get_num_paths(ioc, 2237 num_paths = mpt_raid_phys_disk_get_num_paths(ioc,
2322 ioc->raid_data.pIocPg3->PhysDisk[i].PhysDiskNum); 2238 ioc->raid_data.pIocPg3->PhysDisk[i].PhysDiskNum);
2323 if (num_paths < 2) 2239 if (num_paths < 2)
2324 continue; 2240 continue;
2325 phys_disk = kzalloc(offsetof(RaidPhysDiskPage1_t, Path) + 2241 phys_disk = kzalloc(offsetof(RaidPhysDiskPage1_t, Path) +
2326 (num_paths * sizeof(RAID_PHYS_DISK1_PATH)), GFP_KERNEL); 2242 (num_paths * sizeof(RAID_PHYS_DISK1_PATH)), GFP_KERNEL);
2327 if (!phys_disk) 2243 if (!phys_disk)
2328 continue; 2244 continue;
2329 if ((mpt_raid_phys_disk_pg1(ioc, 2245 if ((mpt_raid_phys_disk_pg1(ioc,
2330 ioc->raid_data.pIocPg3->PhysDisk[i].PhysDiskNum, 2246 ioc->raid_data.pIocPg3->PhysDisk[i].PhysDiskNum,
2331 phys_disk))) { 2247 phys_disk))) {
2332 kfree(phys_disk); 2248 kfree(phys_disk);
2333 continue; 2249 continue;
2334 } 2250 }
2335 for (j = 0; j < num_paths; j++) { 2251 for (j = 0; j < num_paths; j++) {
2336 if ((phys_disk->Path[j].Flags & 2252 if ((phys_disk->Path[j].Flags &
2337 MPI_RAID_PHYSDISK1_FLAG_INVALID)) 2253 MPI_RAID_PHYSDISK1_FLAG_INVALID))
2338 continue; 2254 continue;
2339 if ((phys_disk->Path[j].Flags & 2255 if ((phys_disk->Path[j].Flags &
2340 MPI_RAID_PHYSDISK1_FLAG_BROKEN)) 2256 MPI_RAID_PHYSDISK1_FLAG_BROKEN))
2341 continue; 2257 continue;
2342 if ((id == phys_disk->Path[j].PhysDiskID) && 2258 if ((id == phys_disk->Path[j].PhysDiskID) &&
2343 (channel == phys_disk->Path[j].PhysDiskBus)) { 2259 (channel == phys_disk->Path[j].PhysDiskBus)) {
2344 rc = phys_disk->PhysDiskNum; 2260 rc = phys_disk->PhysDiskNum;
2345 kfree(phys_disk); 2261 kfree(phys_disk);
2346 goto out; 2262 goto out;
2347 } 2263 }
2348 } 2264 }
2349 kfree(phys_disk); 2265 kfree(phys_disk);
2350 } 2266 }
2351 2267
2352 /* 2268 /*
2353 * Check inactive list for matching phys disks 2269 * Check inactive list for matching phys disks
2354 */ 2270 */
2355 if (list_empty(&ioc->raid_data.inactive_list)) 2271 if (list_empty(&ioc->raid_data.inactive_list))
2356 goto out; 2272 goto out;
2357 2273
2358 mutex_lock(&ioc->raid_data.inactive_list_mutex); 2274 mutex_lock(&ioc->raid_data.inactive_list_mutex);
2359 list_for_each_entry(component_info, &ioc->raid_data.inactive_list, 2275 list_for_each_entry(component_info, &ioc->raid_data.inactive_list,
2360 list) { 2276 list) {
2361 if ((component_info->d.PhysDiskID == id) && 2277 if ((component_info->d.PhysDiskID == id) &&
2362 (component_info->d.PhysDiskBus == channel)) 2278 (component_info->d.PhysDiskBus == channel))
2363 rc = component_info->d.PhysDiskNum; 2279 rc = component_info->d.PhysDiskNum;
2364 } 2280 }
2365 mutex_unlock(&ioc->raid_data.inactive_list_mutex); 2281 mutex_unlock(&ioc->raid_data.inactive_list_mutex);
2366 2282
2367 out: 2283 out:
2368 return rc; 2284 return rc;
2369 } 2285 }
2370 EXPORT_SYMBOL(mptscsih_raid_id_to_num); 2286 EXPORT_SYMBOL(mptscsih_raid_id_to_num);
2371 2287
2372 /* 2288 /*
2373 * OS entry point to allow for host driver to free allocated memory 2289 * OS entry point to allow for host driver to free allocated memory
2374 * Called if no device present or device being unloaded 2290 * Called if no device present or device being unloaded
2375 */ 2291 */
2376 void 2292 void
2377 mptscsih_slave_destroy(struct scsi_device *sdev) 2293 mptscsih_slave_destroy(struct scsi_device *sdev)
2378 { 2294 {
2379 struct Scsi_Host *host = sdev->host; 2295 struct Scsi_Host *host = sdev->host;
2380 MPT_SCSI_HOST *hd = shost_priv(host); 2296 MPT_SCSI_HOST *hd = shost_priv(host);
2381 VirtTarget *vtarget; 2297 VirtTarget *vtarget;
2382 VirtDevice *vdevice; 2298 VirtDevice *vdevice;
2383 struct scsi_target *starget; 2299 struct scsi_target *starget;
2384 2300
2385 starget = scsi_target(sdev); 2301 starget = scsi_target(sdev);
2386 vtarget = starget->hostdata; 2302 vtarget = starget->hostdata;
2387 vdevice = sdev->hostdata; 2303 vdevice = sdev->hostdata;
2388 if (!vdevice) 2304 if (!vdevice)
2389 return; 2305 return;
2390 2306
2391 mptscsih_search_running_cmds(hd, vdevice); 2307 mptscsih_search_running_cmds(hd, vdevice);
2392 vtarget->num_luns--; 2308 vtarget->num_luns--;
2393 mptscsih_synchronize_cache(hd, vdevice); 2309 mptscsih_synchronize_cache(hd, vdevice);
2394 kfree(vdevice); 2310 kfree(vdevice);
2395 sdev->hostdata = NULL; 2311 sdev->hostdata = NULL;
2396 } 2312 }
2397 2313
2398 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/ 2314 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
2399 /* 2315 /*
2400 * mptscsih_change_queue_depth - This function will set a devices queue depth 2316 * mptscsih_change_queue_depth - This function will set a devices queue depth
2401 * @sdev: per scsi_device pointer 2317 * @sdev: per scsi_device pointer
2402 * @qdepth: requested queue depth 2318 * @qdepth: requested queue depth
2403 * @reason: calling context 2319 * @reason: calling context
2404 * 2320 *
2405 * Adding support for new 'change_queue_depth' api. 2321 * Adding support for new 'change_queue_depth' api.
2406 */ 2322 */
2407 int 2323 int
2408 mptscsih_change_queue_depth(struct scsi_device *sdev, int qdepth, int reason) 2324 mptscsih_change_queue_depth(struct scsi_device *sdev, int qdepth, int reason)
2409 { 2325 {
2410 MPT_SCSI_HOST *hd = shost_priv(sdev->host); 2326 MPT_SCSI_HOST *hd = shost_priv(sdev->host);
2411 VirtTarget *vtarget; 2327 VirtTarget *vtarget;
2412 struct scsi_target *starget; 2328 struct scsi_target *starget;
2413 int max_depth; 2329 int max_depth;
2414 int tagged; 2330 int tagged;
2415 MPT_ADAPTER *ioc = hd->ioc; 2331 MPT_ADAPTER *ioc = hd->ioc;
2416 2332
2417 starget = scsi_target(sdev); 2333 starget = scsi_target(sdev);
2418 vtarget = starget->hostdata; 2334 vtarget = starget->hostdata;
2419 2335
2420 if (reason != SCSI_QDEPTH_DEFAULT) 2336 if (reason != SCSI_QDEPTH_DEFAULT)
2421 return -EOPNOTSUPP; 2337 return -EOPNOTSUPP;
2422 2338
2423 if (ioc->bus_type == SPI) { 2339 if (ioc->bus_type == SPI) {
2424 if (!(vtarget->tflags & MPT_TARGET_FLAGS_Q_YES)) 2340 if (!(vtarget->tflags & MPT_TARGET_FLAGS_Q_YES))
2425 max_depth = 1; 2341 max_depth = 1;
2426 else if (sdev->type == TYPE_DISK && 2342 else if (sdev->type == TYPE_DISK &&
2427 vtarget->minSyncFactor <= MPT_ULTRA160) 2343 vtarget->minSyncFactor <= MPT_ULTRA160)
2428 max_depth = MPT_SCSI_CMD_PER_DEV_HIGH; 2344 max_depth = MPT_SCSI_CMD_PER_DEV_HIGH;
2429 else 2345 else
2430 max_depth = MPT_SCSI_CMD_PER_DEV_LOW; 2346 max_depth = MPT_SCSI_CMD_PER_DEV_LOW;
2431 } else 2347 } else
2432 max_depth = ioc->sh->can_queue; 2348 max_depth = ioc->sh->can_queue;
2433 2349
2434 if (!sdev->tagged_supported) 2350 if (!sdev->tagged_supported)
2435 max_depth = 1; 2351 max_depth = 1;
2436 2352
2437 if (qdepth > max_depth) 2353 if (qdepth > max_depth)
2438 qdepth = max_depth; 2354 qdepth = max_depth;
2439 if (qdepth == 1) 2355 if (qdepth == 1)
2440 tagged = 0; 2356 tagged = 0;
2441 else 2357 else
2442 tagged = MSG_SIMPLE_TAG; 2358 tagged = MSG_SIMPLE_TAG;
2443 2359
2444 scsi_adjust_queue_depth(sdev, tagged, qdepth); 2360 scsi_adjust_queue_depth(sdev, tagged, qdepth);
2445 return sdev->queue_depth; 2361 return sdev->queue_depth;
2446 } 2362 }
2447 2363
2448 /* 2364 /*
2449 * OS entry point to adjust the queue_depths on a per-device basis. 2365 * OS entry point to adjust the queue_depths on a per-device basis.
2450 * Called once per device the bus scan. Use it to force the queue_depth 2366 * Called once per device the bus scan. Use it to force the queue_depth
2451 * member to 1 if a device does not support Q tags. 2367 * member to 1 if a device does not support Q tags.
2452 * Return non-zero if fails. 2368 * Return non-zero if fails.
2453 */ 2369 */
2454 int 2370 int
2455 mptscsih_slave_configure(struct scsi_device *sdev) 2371 mptscsih_slave_configure(struct scsi_device *sdev)
2456 { 2372 {
2457 struct Scsi_Host *sh = sdev->host; 2373 struct Scsi_Host *sh = sdev->host;
2458 VirtTarget *vtarget; 2374 VirtTarget *vtarget;
2459 VirtDevice *vdevice; 2375 VirtDevice *vdevice;
2460 struct scsi_target *starget; 2376 struct scsi_target *starget;
2461 MPT_SCSI_HOST *hd = shost_priv(sh); 2377 MPT_SCSI_HOST *hd = shost_priv(sh);
2462 MPT_ADAPTER *ioc = hd->ioc; 2378 MPT_ADAPTER *ioc = hd->ioc;
2463 2379
2464 starget = scsi_target(sdev); 2380 starget = scsi_target(sdev);
2465 vtarget = starget->hostdata; 2381 vtarget = starget->hostdata;
2466 vdevice = sdev->hostdata; 2382 vdevice = sdev->hostdata;
2467 2383
2468 dsprintk(ioc, printk(MYIOC_s_DEBUG_FMT 2384 dsprintk(ioc, printk(MYIOC_s_DEBUG_FMT
2469 "device @ %p, channel=%d, id=%d, lun=%d\n", 2385 "device @ %p, channel=%d, id=%d, lun=%d\n",
2470 ioc->name, sdev, sdev->channel, sdev->id, sdev->lun)); 2386 ioc->name, sdev, sdev->channel, sdev->id, sdev->lun));
2471 if (ioc->bus_type == SPI) 2387 if (ioc->bus_type == SPI)
2472 dsprintk(ioc, printk(MYIOC_s_DEBUG_FMT 2388 dsprintk(ioc, printk(MYIOC_s_DEBUG_FMT
2473 "sdtr %d wdtr %d ppr %d inq length=%d\n", 2389 "sdtr %d wdtr %d ppr %d inq length=%d\n",
2474 ioc->name, sdev->sdtr, sdev->wdtr, 2390 ioc->name, sdev->sdtr, sdev->wdtr,
2475 sdev->ppr, sdev->inquiry_len)); 2391 sdev->ppr, sdev->inquiry_len));
2476 2392
2477 vdevice->configured_lun = 1; 2393 vdevice->configured_lun = 1;
2478 2394
2479 dsprintk(ioc, printk(MYIOC_s_DEBUG_FMT 2395 dsprintk(ioc, printk(MYIOC_s_DEBUG_FMT
2480 "Queue depth=%d, tflags=%x\n", 2396 "Queue depth=%d, tflags=%x\n",
2481 ioc->name, sdev->queue_depth, vtarget->tflags)); 2397 ioc->name, sdev->queue_depth, vtarget->tflags));
2482 2398
2483 if (ioc->bus_type == SPI) 2399 if (ioc->bus_type == SPI)
2484 dsprintk(ioc, printk(MYIOC_s_DEBUG_FMT 2400 dsprintk(ioc, printk(MYIOC_s_DEBUG_FMT
2485 "negoFlags=%x, maxOffset=%x, SyncFactor=%x\n", 2401 "negoFlags=%x, maxOffset=%x, SyncFactor=%x\n",
2486 ioc->name, vtarget->negoFlags, vtarget->maxOffset, 2402 ioc->name, vtarget->negoFlags, vtarget->maxOffset,
2487 vtarget->minSyncFactor)); 2403 vtarget->minSyncFactor));
2488 2404
2489 mptscsih_change_queue_depth(sdev, MPT_SCSI_CMD_PER_DEV_HIGH, 2405 mptscsih_change_queue_depth(sdev, MPT_SCSI_CMD_PER_DEV_HIGH,
2490 SCSI_QDEPTH_DEFAULT); 2406 SCSI_QDEPTH_DEFAULT);
2491 dsprintk(ioc, printk(MYIOC_s_DEBUG_FMT 2407 dsprintk(ioc, printk(MYIOC_s_DEBUG_FMT
2492 "tagged %d, simple %d, ordered %d\n", 2408 "tagged %d, simple %d, ordered %d\n",
2493 ioc->name,sdev->tagged_supported, sdev->simple_tags, 2409 ioc->name,sdev->tagged_supported, sdev->simple_tags,
2494 sdev->ordered_tags)); 2410 sdev->ordered_tags));
2495 2411
2496 blk_queue_dma_alignment (sdev->request_queue, 512 - 1); 2412 blk_queue_dma_alignment (sdev->request_queue, 512 - 1);
2497 2413
2498 return 0; 2414 return 0;
2499 } 2415 }
2500 2416
2501 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/ 2417 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
2502 /* 2418 /*
2503 * Private routines... 2419 * Private routines...
2504 */ 2420 */
2505 2421
2506 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/ 2422 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
2507 /* Utility function to copy sense data from the scsi_cmnd buffer 2423 /* Utility function to copy sense data from the scsi_cmnd buffer
2508 * to the FC and SCSI target structures. 2424 * to the FC and SCSI target structures.
2509 * 2425 *
2510 */ 2426 */
2511 static void 2427 static void
2512 mptscsih_copy_sense_data(struct scsi_cmnd *sc, MPT_SCSI_HOST *hd, MPT_FRAME_HDR *mf, SCSIIOReply_t *pScsiReply) 2428 mptscsih_copy_sense_data(struct scsi_cmnd *sc, MPT_SCSI_HOST *hd, MPT_FRAME_HDR *mf, SCSIIOReply_t *pScsiReply)
2513 { 2429 {
2514 VirtDevice *vdevice; 2430 VirtDevice *vdevice;
2515 SCSIIORequest_t *pReq; 2431 SCSIIORequest_t *pReq;
2516 u32 sense_count = le32_to_cpu(pScsiReply->SenseCount); 2432 u32 sense_count = le32_to_cpu(pScsiReply->SenseCount);
2517 MPT_ADAPTER *ioc = hd->ioc; 2433 MPT_ADAPTER *ioc = hd->ioc;
2518 2434
2519 /* Get target structure 2435 /* Get target structure
2520 */ 2436 */
2521 pReq = (SCSIIORequest_t *) mf; 2437 pReq = (SCSIIORequest_t *) mf;
2522 vdevice = sc->device->hostdata; 2438 vdevice = sc->device->hostdata;
2523 2439
2524 if (sense_count) { 2440 if (sense_count) {
2525 u8 *sense_data; 2441 u8 *sense_data;
2526 int req_index; 2442 int req_index;
2527 2443
2528 /* Copy the sense received into the scsi command block. */ 2444 /* Copy the sense received into the scsi command block. */
2529 req_index = le16_to_cpu(mf->u.frame.hwhdr.msgctxu.fld.req_idx); 2445 req_index = le16_to_cpu(mf->u.frame.hwhdr.msgctxu.fld.req_idx);
2530 sense_data = ((u8 *)ioc->sense_buf_pool + (req_index * MPT_SENSE_BUFFER_ALLOC)); 2446 sense_data = ((u8 *)ioc->sense_buf_pool + (req_index * MPT_SENSE_BUFFER_ALLOC));
2531 memcpy(sc->sense_buffer, sense_data, SNS_LEN(sc)); 2447 memcpy(sc->sense_buffer, sense_data, SNS_LEN(sc));
2532 2448
2533 /* Log SMART data (asc = 0x5D, non-IM case only) if required. 2449 /* Log SMART data (asc = 0x5D, non-IM case only) if required.
2534 */ 2450 */
2535 if ((ioc->events) && (ioc->eventTypes & (1 << MPI_EVENT_SCSI_DEVICE_STATUS_CHANGE))) { 2451 if ((ioc->events) && (ioc->eventTypes & (1 << MPI_EVENT_SCSI_DEVICE_STATUS_CHANGE))) {
2536 if ((sense_data[12] == 0x5D) && (vdevice->vtarget->raidVolume == 0)) { 2452 if ((sense_data[12] == 0x5D) && (vdevice->vtarget->raidVolume == 0)) {
2537 int idx; 2453 int idx;
2538 2454
2539 idx = ioc->eventContext % MPTCTL_EVENT_LOG_SIZE; 2455 idx = ioc->eventContext % MPTCTL_EVENT_LOG_SIZE;
2540 ioc->events[idx].event = MPI_EVENT_SCSI_DEVICE_STATUS_CHANGE; 2456 ioc->events[idx].event = MPI_EVENT_SCSI_DEVICE_STATUS_CHANGE;
2541 ioc->events[idx].eventContext = ioc->eventContext; 2457 ioc->events[idx].eventContext = ioc->eventContext;
2542 2458
2543 ioc->events[idx].data[0] = (pReq->LUN[1] << 24) | 2459 ioc->events[idx].data[0] = (pReq->LUN[1] << 24) |
2544 (MPI_EVENT_SCSI_DEV_STAT_RC_SMART_DATA << 16) | 2460 (MPI_EVENT_SCSI_DEV_STAT_RC_SMART_DATA << 16) |
2545 (sc->device->channel << 8) | sc->device->id; 2461 (sc->device->channel << 8) | sc->device->id;
2546 2462
2547 ioc->events[idx].data[1] = (sense_data[13] << 8) | sense_data[12]; 2463 ioc->events[idx].data[1] = (sense_data[13] << 8) | sense_data[12];
2548 2464
2549 ioc->eventContext++; 2465 ioc->eventContext++;
2550 if (ioc->pcidev->vendor == 2466 if (ioc->pcidev->vendor ==
2551 PCI_VENDOR_ID_IBM) { 2467 PCI_VENDOR_ID_IBM) {
2552 mptscsih_issue_sep_command(ioc, 2468 mptscsih_issue_sep_command(ioc,
2553 vdevice->vtarget, MPI_SEP_REQ_SLOTSTATUS_PREDICTED_FAULT); 2469 vdevice->vtarget, MPI_SEP_REQ_SLOTSTATUS_PREDICTED_FAULT);
2554 vdevice->vtarget->tflags |= 2470 vdevice->vtarget->tflags |=
2555 MPT_TARGET_FLAGS_LED_ON; 2471 MPT_TARGET_FLAGS_LED_ON;
2556 } 2472 }
2557 } 2473 }
2558 } 2474 }
2559 } else { 2475 } else {
2560 dprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Hmmm... SenseData len=0! (?)\n", 2476 dprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Hmmm... SenseData len=0! (?)\n",
2561 ioc->name)); 2477 ioc->name));
2562 } 2478 }
2563 } 2479 }
2564 2480
2565 /** 2481 /**
2566 * mptscsih_get_scsi_lookup - retrieves scmd entry 2482 * mptscsih_get_scsi_lookup - retrieves scmd entry
2567 * @ioc: Pointer to MPT_ADAPTER structure 2483 * @ioc: Pointer to MPT_ADAPTER structure
2568 * @i: index into the array 2484 * @i: index into the array
2569 * 2485 *
2570 * Returns the scsi_cmd pointer 2486 * Returns the scsi_cmd pointer
2571 */ 2487 */
2572 struct scsi_cmnd * 2488 struct scsi_cmnd *
2573 mptscsih_get_scsi_lookup(MPT_ADAPTER *ioc, int i) 2489 mptscsih_get_scsi_lookup(MPT_ADAPTER *ioc, int i)
2574 { 2490 {
2575 unsigned long flags; 2491 unsigned long flags;
2576 struct scsi_cmnd *scmd; 2492 struct scsi_cmnd *scmd;
2577 2493
2578 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags); 2494 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
2579 scmd = ioc->ScsiLookup[i]; 2495 scmd = ioc->ScsiLookup[i];
2580 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags); 2496 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
2581 2497
2582 return scmd; 2498 return scmd;
2583 } 2499 }
2584 EXPORT_SYMBOL(mptscsih_get_scsi_lookup); 2500 EXPORT_SYMBOL(mptscsih_get_scsi_lookup);
2585 2501
2586 /** 2502 /**
2587 * mptscsih_getclear_scsi_lookup - retrieves and clears scmd entry from ScsiLookup[] array list 2503 * mptscsih_getclear_scsi_lookup - retrieves and clears scmd entry from ScsiLookup[] array list
2588 * @ioc: Pointer to MPT_ADAPTER structure 2504 * @ioc: Pointer to MPT_ADAPTER structure
2589 * @i: index into the array 2505 * @i: index into the array
2590 * 2506 *
2591 * Returns the scsi_cmd pointer 2507 * Returns the scsi_cmd pointer
2592 * 2508 *
2593 **/ 2509 **/
2594 static struct scsi_cmnd * 2510 static struct scsi_cmnd *
2595 mptscsih_getclear_scsi_lookup(MPT_ADAPTER *ioc, int i) 2511 mptscsih_getclear_scsi_lookup(MPT_ADAPTER *ioc, int i)
2596 { 2512 {
2597 unsigned long flags; 2513 unsigned long flags;
2598 struct scsi_cmnd *scmd; 2514 struct scsi_cmnd *scmd;
2599 2515
2600 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags); 2516 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
2601 scmd = ioc->ScsiLookup[i]; 2517 scmd = ioc->ScsiLookup[i];
2602 ioc->ScsiLookup[i] = NULL; 2518 ioc->ScsiLookup[i] = NULL;
2603 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags); 2519 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
2604 2520
2605 return scmd; 2521 return scmd;
2606 } 2522 }
2607 2523
2608 /** 2524 /**
2609 * mptscsih_set_scsi_lookup - write a scmd entry into the ScsiLookup[] array list 2525 * mptscsih_set_scsi_lookup - write a scmd entry into the ScsiLookup[] array list
2610 * 2526 *
2611 * @ioc: Pointer to MPT_ADAPTER structure 2527 * @ioc: Pointer to MPT_ADAPTER structure
2612 * @i: index into the array 2528 * @i: index into the array
2613 * @scmd: scsi_cmnd pointer 2529 * @scmd: scsi_cmnd pointer
2614 * 2530 *
2615 **/ 2531 **/
2616 static void 2532 static void
2617 mptscsih_set_scsi_lookup(MPT_ADAPTER *ioc, int i, struct scsi_cmnd *scmd) 2533 mptscsih_set_scsi_lookup(MPT_ADAPTER *ioc, int i, struct scsi_cmnd *scmd)
2618 { 2534 {
2619 unsigned long flags; 2535 unsigned long flags;
2620 2536
2621 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags); 2537 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
2622 ioc->ScsiLookup[i] = scmd; 2538 ioc->ScsiLookup[i] = scmd;
2623 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags); 2539 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
2624 } 2540 }
2625 2541
2626 /** 2542 /**
2627 * SCPNT_TO_LOOKUP_IDX - searches for a given scmd in the ScsiLookup[] array list 2543 * SCPNT_TO_LOOKUP_IDX - searches for a given scmd in the ScsiLookup[] array list
2628 * @ioc: Pointer to MPT_ADAPTER structure 2544 * @ioc: Pointer to MPT_ADAPTER structure
2629 * @sc: scsi_cmnd pointer 2545 * @sc: scsi_cmnd pointer
2630 */ 2546 */
2631 static int 2547 static int
2632 SCPNT_TO_LOOKUP_IDX(MPT_ADAPTER *ioc, struct scsi_cmnd *sc) 2548 SCPNT_TO_LOOKUP_IDX(MPT_ADAPTER *ioc, struct scsi_cmnd *sc)
2633 { 2549 {
2634 unsigned long flags; 2550 unsigned long flags;
2635 int i, index=-1; 2551 int i, index=-1;
2636 2552
2637 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags); 2553 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
2638 for (i = 0; i < ioc->req_depth; i++) { 2554 for (i = 0; i < ioc->req_depth; i++) {
2639 if (ioc->ScsiLookup[i] == sc) { 2555 if (ioc->ScsiLookup[i] == sc) {
2640 index = i; 2556 index = i;
2641 goto out; 2557 goto out;
2642 } 2558 }
2643 } 2559 }
2644 2560
2645 out: 2561 out:
2646 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags); 2562 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
2647 return index; 2563 return index;
2648 } 2564 }
2649 2565
2650 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/ 2566 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
2651 int 2567 int
2652 mptscsih_ioc_reset(MPT_ADAPTER *ioc, int reset_phase) 2568 mptscsih_ioc_reset(MPT_ADAPTER *ioc, int reset_phase)
2653 { 2569 {
2654 MPT_SCSI_HOST *hd; 2570 MPT_SCSI_HOST *hd;
2655 2571
2656 if (ioc->sh == NULL || shost_priv(ioc->sh) == NULL) 2572 if (ioc->sh == NULL || shost_priv(ioc->sh) == NULL)
2657 return 0; 2573 return 0;
2658 2574
2659 hd = shost_priv(ioc->sh); 2575 hd = shost_priv(ioc->sh);
2660 switch (reset_phase) { 2576 switch (reset_phase) {
2661 case MPT_IOC_SETUP_RESET: 2577 case MPT_IOC_SETUP_RESET:
2662 dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT 2578 dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT
2663 "%s: MPT_IOC_SETUP_RESET\n", ioc->name, __func__)); 2579 "%s: MPT_IOC_SETUP_RESET\n", ioc->name, __func__));
2664 break; 2580 break;
2665 case MPT_IOC_PRE_RESET: 2581 case MPT_IOC_PRE_RESET:
2666 dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT 2582 dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT
2667 "%s: MPT_IOC_PRE_RESET\n", ioc->name, __func__)); 2583 "%s: MPT_IOC_PRE_RESET\n", ioc->name, __func__));
2668 mptscsih_flush_running_cmds(hd); 2584 mptscsih_flush_running_cmds(hd);
2669 break; 2585 break;
2670 case MPT_IOC_POST_RESET: 2586 case MPT_IOC_POST_RESET:
2671 dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT 2587 dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT
2672 "%s: MPT_IOC_POST_RESET\n", ioc->name, __func__)); 2588 "%s: MPT_IOC_POST_RESET\n", ioc->name, __func__));
2673 if (ioc->internal_cmds.status & MPT_MGMT_STATUS_PENDING) { 2589 if (ioc->internal_cmds.status & MPT_MGMT_STATUS_PENDING) {
2674 ioc->internal_cmds.status |= 2590 ioc->internal_cmds.status |=
2675 MPT_MGMT_STATUS_DID_IOCRESET; 2591 MPT_MGMT_STATUS_DID_IOCRESET;
2676 complete(&ioc->internal_cmds.done); 2592 complete(&ioc->internal_cmds.done);
2677 } 2593 }
2678 break; 2594 break;
2679 default: 2595 default:
2680 break; 2596 break;
2681 } 2597 }
2682 return 1; /* currently means nothing really */ 2598 return 1; /* currently means nothing really */
2683 } 2599 }
2684 2600
2685 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/ 2601 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
2686 int 2602 int
2687 mptscsih_event_process(MPT_ADAPTER *ioc, EventNotificationReply_t *pEvReply) 2603 mptscsih_event_process(MPT_ADAPTER *ioc, EventNotificationReply_t *pEvReply)
2688 { 2604 {
2689 u8 event = le32_to_cpu(pEvReply->Event) & 0xFF; 2605 u8 event = le32_to_cpu(pEvReply->Event) & 0xFF;
2690 2606
2691 devtverboseprintk(ioc, printk(MYIOC_s_DEBUG_FMT 2607 devtverboseprintk(ioc, printk(MYIOC_s_DEBUG_FMT
2692 "MPT event (=%02Xh) routed to SCSI host driver!\n", 2608 "MPT event (=%02Xh) routed to SCSI host driver!\n",
2693 ioc->name, event)); 2609 ioc->name, event));
2694 2610
2695 if ((event == MPI_EVENT_IOC_BUS_RESET || 2611 if ((event == MPI_EVENT_IOC_BUS_RESET ||
2696 event == MPI_EVENT_EXT_BUS_RESET) && 2612 event == MPI_EVENT_EXT_BUS_RESET) &&
2697 (ioc->bus_type == SPI) && (ioc->soft_resets < -1)) 2613 (ioc->bus_type == SPI) && (ioc->soft_resets < -1))
2698 ioc->soft_resets++; 2614 ioc->soft_resets++;
2699 2615
2700 return 1; /* currently means nothing really */ 2616 return 1; /* currently means nothing really */
2701 } 2617 }
2702 2618
2703 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/ 2619 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
2704 /* 2620 /*
2705 * Bus Scan and Domain Validation functionality ... 2621 * Bus Scan and Domain Validation functionality ...
2706 */ 2622 */
2707 2623
2708 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/ 2624 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
2709 /* 2625 /*
2710 * mptscsih_scandv_complete - Scan and DV callback routine registered 2626 * mptscsih_scandv_complete - Scan and DV callback routine registered
2711 * to Fustion MPT (base) driver. 2627 * to Fustion MPT (base) driver.
2712 * 2628 *
2713 * @ioc: Pointer to MPT_ADAPTER structure 2629 * @ioc: Pointer to MPT_ADAPTER structure
2714 * @mf: Pointer to original MPT request frame 2630 * @mf: Pointer to original MPT request frame
2715 * @mr: Pointer to MPT reply frame (NULL if TurboReply) 2631 * @mr: Pointer to MPT reply frame (NULL if TurboReply)
2716 * 2632 *
2717 * This routine is called from mpt.c::mpt_interrupt() at the completion 2633 * This routine is called from mpt.c::mpt_interrupt() at the completion
2718 * of any SCSI IO request. 2634 * of any SCSI IO request.
2719 * This routine is registered with the Fusion MPT (base) driver at driver 2635 * This routine is registered with the Fusion MPT (base) driver at driver
2720 * load/init time via the mpt_register() API call. 2636 * load/init time via the mpt_register() API call.
2721 * 2637 *
2722 * Returns 1 indicating alloc'd request frame ptr should be freed. 2638 * Returns 1 indicating alloc'd request frame ptr should be freed.
2723 * 2639 *
2724 * Remark: Sets a completion code and (possibly) saves sense data 2640 * Remark: Sets a completion code and (possibly) saves sense data
2725 * in the IOC member localReply structure. 2641 * in the IOC member localReply structure.
2726 * Used ONLY for DV and other internal commands. 2642 * Used ONLY for DV and other internal commands.
2727 */ 2643 */
2728 int 2644 int
2729 mptscsih_scandv_complete(MPT_ADAPTER *ioc, MPT_FRAME_HDR *req, 2645 mptscsih_scandv_complete(MPT_ADAPTER *ioc, MPT_FRAME_HDR *req,
2730 MPT_FRAME_HDR *reply) 2646 MPT_FRAME_HDR *reply)
2731 { 2647 {
2732 SCSIIORequest_t *pReq; 2648 SCSIIORequest_t *pReq;
2733 SCSIIOReply_t *pReply; 2649 SCSIIOReply_t *pReply;
2734 u8 cmd; 2650 u8 cmd;
2735 u16 req_idx; 2651 u16 req_idx;
2736 u8 *sense_data; 2652 u8 *sense_data;
2737 int sz; 2653 int sz;
2738 2654
2739 ioc->internal_cmds.status |= MPT_MGMT_STATUS_COMMAND_GOOD; 2655 ioc->internal_cmds.status |= MPT_MGMT_STATUS_COMMAND_GOOD;
2740 ioc->internal_cmds.completion_code = MPT_SCANDV_GOOD; 2656 ioc->internal_cmds.completion_code = MPT_SCANDV_GOOD;
2741 if (!reply) 2657 if (!reply)
2742 goto out; 2658 goto out;
2743 2659
2744 pReply = (SCSIIOReply_t *) reply; 2660 pReply = (SCSIIOReply_t *) reply;
2745 pReq = (SCSIIORequest_t *) req; 2661 pReq = (SCSIIORequest_t *) req;
2746 ioc->internal_cmds.completion_code = 2662 ioc->internal_cmds.completion_code =
2747 mptscsih_get_completion_code(ioc, req, reply); 2663 mptscsih_get_completion_code(ioc, req, reply);
2748 ioc->internal_cmds.status |= MPT_MGMT_STATUS_RF_VALID; 2664 ioc->internal_cmds.status |= MPT_MGMT_STATUS_RF_VALID;
2749 memcpy(ioc->internal_cmds.reply, reply, 2665 memcpy(ioc->internal_cmds.reply, reply,
2750 min(MPT_DEFAULT_FRAME_SIZE, 4 * reply->u.reply.MsgLength)); 2666 min(MPT_DEFAULT_FRAME_SIZE, 4 * reply->u.reply.MsgLength));
2751 cmd = reply->u.hdr.Function; 2667 cmd = reply->u.hdr.Function;
2752 if (((cmd == MPI_FUNCTION_SCSI_IO_REQUEST) || 2668 if (((cmd == MPI_FUNCTION_SCSI_IO_REQUEST) ||
2753 (cmd == MPI_FUNCTION_RAID_SCSI_IO_PASSTHROUGH)) && 2669 (cmd == MPI_FUNCTION_RAID_SCSI_IO_PASSTHROUGH)) &&
2754 (pReply->SCSIState & MPI_SCSI_STATE_AUTOSENSE_VALID)) { 2670 (pReply->SCSIState & MPI_SCSI_STATE_AUTOSENSE_VALID)) {
2755 req_idx = le16_to_cpu(req->u.frame.hwhdr.msgctxu.fld.req_idx); 2671 req_idx = le16_to_cpu(req->u.frame.hwhdr.msgctxu.fld.req_idx);
2756 sense_data = ((u8 *)ioc->sense_buf_pool + 2672 sense_data = ((u8 *)ioc->sense_buf_pool +
2757 (req_idx * MPT_SENSE_BUFFER_ALLOC)); 2673 (req_idx * MPT_SENSE_BUFFER_ALLOC));
2758 sz = min_t(int, pReq->SenseBufferLength, 2674 sz = min_t(int, pReq->SenseBufferLength,
2759 MPT_SENSE_BUFFER_ALLOC); 2675 MPT_SENSE_BUFFER_ALLOC);
2760 memcpy(ioc->internal_cmds.sense, sense_data, sz); 2676 memcpy(ioc->internal_cmds.sense, sense_data, sz);
2761 } 2677 }
2762 out: 2678 out:
2763 if (!(ioc->internal_cmds.status & MPT_MGMT_STATUS_PENDING)) 2679 if (!(ioc->internal_cmds.status & MPT_MGMT_STATUS_PENDING))
2764 return 0; 2680 return 0;
2765 ioc->internal_cmds.status &= ~MPT_MGMT_STATUS_PENDING; 2681 ioc->internal_cmds.status &= ~MPT_MGMT_STATUS_PENDING;
2766 complete(&ioc->internal_cmds.done); 2682 complete(&ioc->internal_cmds.done);
2767 return 1; 2683 return 1;
2768 } 2684 }
2769 2685
2770 2686
2771 /** 2687 /**
2772 * mptscsih_get_completion_code - get completion code from MPT request 2688 * mptscsih_get_completion_code - get completion code from MPT request
2773 * @ioc: Pointer to MPT_ADAPTER structure 2689 * @ioc: Pointer to MPT_ADAPTER structure
2774 * @req: Pointer to original MPT request frame 2690 * @req: Pointer to original MPT request frame
2775 * @reply: Pointer to MPT reply frame (NULL if TurboReply) 2691 * @reply: Pointer to MPT reply frame (NULL if TurboReply)
2776 * 2692 *
2777 **/ 2693 **/
2778 static int 2694 static int
2779 mptscsih_get_completion_code(MPT_ADAPTER *ioc, MPT_FRAME_HDR *req, 2695 mptscsih_get_completion_code(MPT_ADAPTER *ioc, MPT_FRAME_HDR *req,
2780 MPT_FRAME_HDR *reply) 2696 MPT_FRAME_HDR *reply)
2781 { 2697 {
2782 SCSIIOReply_t *pReply; 2698 SCSIIOReply_t *pReply;
2783 MpiRaidActionReply_t *pr; 2699 MpiRaidActionReply_t *pr;
2784 u8 scsi_status; 2700 u8 scsi_status;
2785 u16 status; 2701 u16 status;
2786 int completion_code; 2702 int completion_code;
2787 2703
2788 pReply = (SCSIIOReply_t *)reply; 2704 pReply = (SCSIIOReply_t *)reply;
2789 status = le16_to_cpu(pReply->IOCStatus) & MPI_IOCSTATUS_MASK; 2705 status = le16_to_cpu(pReply->IOCStatus) & MPI_IOCSTATUS_MASK;
2790 scsi_status = pReply->SCSIStatus; 2706 scsi_status = pReply->SCSIStatus;
2791 2707
2792 devtprintk(ioc, printk(MYIOC_s_DEBUG_FMT 2708 devtprintk(ioc, printk(MYIOC_s_DEBUG_FMT
2793 "IOCStatus=%04xh, SCSIState=%02xh, SCSIStatus=%02xh," 2709 "IOCStatus=%04xh, SCSIState=%02xh, SCSIStatus=%02xh,"
2794 "IOCLogInfo=%08xh\n", ioc->name, status, pReply->SCSIState, 2710 "IOCLogInfo=%08xh\n", ioc->name, status, pReply->SCSIState,
2795 scsi_status, le32_to_cpu(pReply->IOCLogInfo))); 2711 scsi_status, le32_to_cpu(pReply->IOCLogInfo)));
2796 2712
2797 switch (status) { 2713 switch (status) {
2798 2714
2799 case MPI_IOCSTATUS_SCSI_DEVICE_NOT_THERE: /* 0x0043 */ 2715 case MPI_IOCSTATUS_SCSI_DEVICE_NOT_THERE: /* 0x0043 */
2800 completion_code = MPT_SCANDV_SELECTION_TIMEOUT; 2716 completion_code = MPT_SCANDV_SELECTION_TIMEOUT;
2801 break; 2717 break;
2802 2718
2803 case MPI_IOCSTATUS_SCSI_IO_DATA_ERROR: /* 0x0046 */ 2719 case MPI_IOCSTATUS_SCSI_IO_DATA_ERROR: /* 0x0046 */
2804 case MPI_IOCSTATUS_SCSI_TASK_TERMINATED: /* 0x0048 */ 2720 case MPI_IOCSTATUS_SCSI_TASK_TERMINATED: /* 0x0048 */
2805 case MPI_IOCSTATUS_SCSI_IOC_TERMINATED: /* 0x004B */ 2721 case MPI_IOCSTATUS_SCSI_IOC_TERMINATED: /* 0x004B */
2806 case MPI_IOCSTATUS_SCSI_EXT_TERMINATED: /* 0x004C */ 2722 case MPI_IOCSTATUS_SCSI_EXT_TERMINATED: /* 0x004C */
2807 completion_code = MPT_SCANDV_DID_RESET; 2723 completion_code = MPT_SCANDV_DID_RESET;
2808 break; 2724 break;
2809 2725
2810 case MPI_IOCSTATUS_BUSY: 2726 case MPI_IOCSTATUS_BUSY:
2811 case MPI_IOCSTATUS_INSUFFICIENT_RESOURCES: 2727 case MPI_IOCSTATUS_INSUFFICIENT_RESOURCES:
2812 completion_code = MPT_SCANDV_BUSY; 2728 completion_code = MPT_SCANDV_BUSY;
2813 break; 2729 break;
2814 2730
2815 case MPI_IOCSTATUS_SCSI_DATA_UNDERRUN: /* 0x0045 */ 2731 case MPI_IOCSTATUS_SCSI_DATA_UNDERRUN: /* 0x0045 */
2816 case MPI_IOCSTATUS_SCSI_RECOVERED_ERROR: /* 0x0040 */ 2732 case MPI_IOCSTATUS_SCSI_RECOVERED_ERROR: /* 0x0040 */
2817 case MPI_IOCSTATUS_SUCCESS: /* 0x0000 */ 2733 case MPI_IOCSTATUS_SUCCESS: /* 0x0000 */
2818 if (pReply->Function == MPI_FUNCTION_CONFIG) { 2734 if (pReply->Function == MPI_FUNCTION_CONFIG) {
2819 completion_code = MPT_SCANDV_GOOD; 2735 completion_code = MPT_SCANDV_GOOD;
2820 } else if (pReply->Function == MPI_FUNCTION_RAID_ACTION) { 2736 } else if (pReply->Function == MPI_FUNCTION_RAID_ACTION) {
2821 pr = (MpiRaidActionReply_t *)reply; 2737 pr = (MpiRaidActionReply_t *)reply;
2822 if (le16_to_cpu(pr->ActionStatus) == 2738 if (le16_to_cpu(pr->ActionStatus) ==
2823 MPI_RAID_ACTION_ASTATUS_SUCCESS) 2739 MPI_RAID_ACTION_ASTATUS_SUCCESS)
2824 completion_code = MPT_SCANDV_GOOD; 2740 completion_code = MPT_SCANDV_GOOD;
2825 else 2741 else
2826 completion_code = MPT_SCANDV_SOME_ERROR; 2742 completion_code = MPT_SCANDV_SOME_ERROR;
2827 } else if (pReply->SCSIState & MPI_SCSI_STATE_AUTOSENSE_VALID) 2743 } else if (pReply->SCSIState & MPI_SCSI_STATE_AUTOSENSE_VALID)
2828 completion_code = MPT_SCANDV_SENSE; 2744 completion_code = MPT_SCANDV_SENSE;
2829 else if (pReply->SCSIState & MPI_SCSI_STATE_AUTOSENSE_FAILED) { 2745 else if (pReply->SCSIState & MPI_SCSI_STATE_AUTOSENSE_FAILED) {
2830 if (req->u.scsireq.CDB[0] == INQUIRY) 2746 if (req->u.scsireq.CDB[0] == INQUIRY)
2831 completion_code = MPT_SCANDV_ISSUE_SENSE; 2747 completion_code = MPT_SCANDV_ISSUE_SENSE;
2832 else 2748 else
2833 completion_code = MPT_SCANDV_DID_RESET; 2749 completion_code = MPT_SCANDV_DID_RESET;
2834 } else if (pReply->SCSIState & MPI_SCSI_STATE_NO_SCSI_STATUS) 2750 } else if (pReply->SCSIState & MPI_SCSI_STATE_NO_SCSI_STATUS)
2835 completion_code = MPT_SCANDV_DID_RESET; 2751 completion_code = MPT_SCANDV_DID_RESET;
2836 else if (pReply->SCSIState & MPI_SCSI_STATE_TERMINATED) 2752 else if (pReply->SCSIState & MPI_SCSI_STATE_TERMINATED)
2837 completion_code = MPT_SCANDV_DID_RESET; 2753 completion_code = MPT_SCANDV_DID_RESET;
2838 else if (scsi_status == MPI_SCSI_STATUS_BUSY) 2754 else if (scsi_status == MPI_SCSI_STATUS_BUSY)
2839 completion_code = MPT_SCANDV_BUSY; 2755 completion_code = MPT_SCANDV_BUSY;
2840 else 2756 else
2841 completion_code = MPT_SCANDV_GOOD; 2757 completion_code = MPT_SCANDV_GOOD;
2842 break; 2758 break;
2843 2759
2844 case MPI_IOCSTATUS_SCSI_PROTOCOL_ERROR: /* 0x0047 */ 2760 case MPI_IOCSTATUS_SCSI_PROTOCOL_ERROR: /* 0x0047 */
2845 if (pReply->SCSIState & MPI_SCSI_STATE_TERMINATED) 2761 if (pReply->SCSIState & MPI_SCSI_STATE_TERMINATED)
2846 completion_code = MPT_SCANDV_DID_RESET; 2762 completion_code = MPT_SCANDV_DID_RESET;
2847 else 2763 else
2848 completion_code = MPT_SCANDV_SOME_ERROR; 2764 completion_code = MPT_SCANDV_SOME_ERROR;
2849 break; 2765 break;
2850 default: 2766 default:
2851 completion_code = MPT_SCANDV_SOME_ERROR; 2767 completion_code = MPT_SCANDV_SOME_ERROR;
2852 break; 2768 break;
2853 2769
2854 } /* switch(status) */ 2770 } /* switch(status) */
2855 2771
2856 devtprintk(ioc, printk(MYIOC_s_DEBUG_FMT 2772 devtprintk(ioc, printk(MYIOC_s_DEBUG_FMT
2857 " completionCode set to %08xh\n", ioc->name, completion_code)); 2773 " completionCode set to %08xh\n", ioc->name, completion_code));
2858 return completion_code; 2774 return completion_code;
2859 } 2775 }
2860 2776
2861 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/ 2777 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
2862 /** 2778 /**
2863 * mptscsih_do_cmd - Do internal command. 2779 * mptscsih_do_cmd - Do internal command.
2864 * @hd: MPT_SCSI_HOST pointer 2780 * @hd: MPT_SCSI_HOST pointer
2865 * @io: INTERNAL_CMD pointer. 2781 * @io: INTERNAL_CMD pointer.
2866 * 2782 *
2867 * Issue the specified internally generated command and do command 2783 * Issue the specified internally generated command and do command
2868 * specific cleanup. For bus scan / DV only. 2784 * specific cleanup. For bus scan / DV only.
2869 * NOTES: If command is Inquiry and status is good, 2785 * NOTES: If command is Inquiry and status is good,
2870 * initialize a target structure, save the data 2786 * initialize a target structure, save the data
2871 * 2787 *
2872 * Remark: Single threaded access only. 2788 * Remark: Single threaded access only.
2873 * 2789 *
2874 * Return: 2790 * Return:
2875 * < 0 if an illegal command or no resources 2791 * < 0 if an illegal command or no resources
2876 * 2792 *
2877 * 0 if good 2793 * 0 if good
2878 * 2794 *
2879 * > 0 if command complete but some type of completion error. 2795 * > 0 if command complete but some type of completion error.
2880 */ 2796 */
2881 static int 2797 static int
2882 mptscsih_do_cmd(MPT_SCSI_HOST *hd, INTERNAL_CMD *io) 2798 mptscsih_do_cmd(MPT_SCSI_HOST *hd, INTERNAL_CMD *io)
2883 { 2799 {
2884 MPT_FRAME_HDR *mf; 2800 MPT_FRAME_HDR *mf;
2885 SCSIIORequest_t *pScsiReq; 2801 SCSIIORequest_t *pScsiReq;
2886 int my_idx, ii, dir; 2802 int my_idx, ii, dir;
2887 int timeout; 2803 int timeout;
2888 char cmdLen; 2804 char cmdLen;
2889 char CDB[]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}; 2805 char CDB[]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
2890 u8 cmd = io->cmd; 2806 u8 cmd = io->cmd;
2891 MPT_ADAPTER *ioc = hd->ioc; 2807 MPT_ADAPTER *ioc = hd->ioc;
2892 int ret = 0; 2808 int ret = 0;
2893 unsigned long timeleft; 2809 unsigned long timeleft;
2894 unsigned long flags; 2810 unsigned long flags;
2895 2811
2896 /* don't send internal command during diag reset */ 2812 /* don't send internal command during diag reset */
2897 spin_lock_irqsave(&ioc->taskmgmt_lock, flags); 2813 spin_lock_irqsave(&ioc->taskmgmt_lock, flags);
2898 if (ioc->ioc_reset_in_progress) { 2814 if (ioc->ioc_reset_in_progress) {
2899 spin_unlock_irqrestore(&ioc->taskmgmt_lock, flags); 2815 spin_unlock_irqrestore(&ioc->taskmgmt_lock, flags);
2900 dfailprintk(ioc, printk(MYIOC_s_DEBUG_FMT 2816 dfailprintk(ioc, printk(MYIOC_s_DEBUG_FMT
2901 "%s: busy with host reset\n", ioc->name, __func__)); 2817 "%s: busy with host reset\n", ioc->name, __func__));
2902 return MPT_SCANDV_BUSY; 2818 return MPT_SCANDV_BUSY;
2903 } 2819 }
2904 spin_unlock_irqrestore(&ioc->taskmgmt_lock, flags); 2820 spin_unlock_irqrestore(&ioc->taskmgmt_lock, flags);
2905 2821
2906 mutex_lock(&ioc->internal_cmds.mutex); 2822 mutex_lock(&ioc->internal_cmds.mutex);
2907 2823
2908 /* Set command specific information 2824 /* Set command specific information
2909 */ 2825 */
2910 switch (cmd) { 2826 switch (cmd) {
2911 case INQUIRY: 2827 case INQUIRY:
2912 cmdLen = 6; 2828 cmdLen = 6;
2913 dir = MPI_SCSIIO_CONTROL_READ; 2829 dir = MPI_SCSIIO_CONTROL_READ;
2914 CDB[0] = cmd; 2830 CDB[0] = cmd;
2915 CDB[4] = io->size; 2831 CDB[4] = io->size;
2916 timeout = 10; 2832 timeout = 10;
2917 break; 2833 break;
2918 2834
2919 case TEST_UNIT_READY: 2835 case TEST_UNIT_READY:
2920 cmdLen = 6; 2836 cmdLen = 6;
2921 dir = MPI_SCSIIO_CONTROL_READ; 2837 dir = MPI_SCSIIO_CONTROL_READ;
2922 timeout = 10; 2838 timeout = 10;
2923 break; 2839 break;
2924 2840
2925 case START_STOP: 2841 case START_STOP:
2926 cmdLen = 6; 2842 cmdLen = 6;
2927 dir = MPI_SCSIIO_CONTROL_READ; 2843 dir = MPI_SCSIIO_CONTROL_READ;
2928 CDB[0] = cmd; 2844 CDB[0] = cmd;
2929 CDB[4] = 1; /*Spin up the disk */ 2845 CDB[4] = 1; /*Spin up the disk */
2930 timeout = 15; 2846 timeout = 15;
2931 break; 2847 break;
2932 2848
2933 case REQUEST_SENSE: 2849 case REQUEST_SENSE:
2934 cmdLen = 6; 2850 cmdLen = 6;
2935 CDB[0] = cmd; 2851 CDB[0] = cmd;
2936 CDB[4] = io->size; 2852 CDB[4] = io->size;
2937 dir = MPI_SCSIIO_CONTROL_READ; 2853 dir = MPI_SCSIIO_CONTROL_READ;
2938 timeout = 10; 2854 timeout = 10;
2939 break; 2855 break;
2940 2856
2941 case READ_BUFFER: 2857 case READ_BUFFER:
2942 cmdLen = 10; 2858 cmdLen = 10;
2943 dir = MPI_SCSIIO_CONTROL_READ; 2859 dir = MPI_SCSIIO_CONTROL_READ;
2944 CDB[0] = cmd; 2860 CDB[0] = cmd;
2945 if (io->flags & MPT_ICFLAG_ECHO) { 2861 if (io->flags & MPT_ICFLAG_ECHO) {
2946 CDB[1] = 0x0A; 2862 CDB[1] = 0x0A;
2947 } else { 2863 } else {
2948 CDB[1] = 0x02; 2864 CDB[1] = 0x02;
2949 } 2865 }
2950 2866
2951 if (io->flags & MPT_ICFLAG_BUF_CAP) { 2867 if (io->flags & MPT_ICFLAG_BUF_CAP) {
2952 CDB[1] |= 0x01; 2868 CDB[1] |= 0x01;
2953 } 2869 }
2954 CDB[6] = (io->size >> 16) & 0xFF; 2870 CDB[6] = (io->size >> 16) & 0xFF;
2955 CDB[7] = (io->size >> 8) & 0xFF; 2871 CDB[7] = (io->size >> 8) & 0xFF;
2956 CDB[8] = io->size & 0xFF; 2872 CDB[8] = io->size & 0xFF;
2957 timeout = 10; 2873 timeout = 10;
2958 break; 2874 break;
2959 2875
2960 case WRITE_BUFFER: 2876 case WRITE_BUFFER:
2961 cmdLen = 10; 2877 cmdLen = 10;
2962 dir = MPI_SCSIIO_CONTROL_WRITE; 2878 dir = MPI_SCSIIO_CONTROL_WRITE;
2963 CDB[0] = cmd; 2879 CDB[0] = cmd;
2964 if (io->flags & MPT_ICFLAG_ECHO) { 2880 if (io->flags & MPT_ICFLAG_ECHO) {
2965 CDB[1] = 0x0A; 2881 CDB[1] = 0x0A;
2966 } else { 2882 } else {
2967 CDB[1] = 0x02; 2883 CDB[1] = 0x02;
2968 } 2884 }
2969 CDB[6] = (io->size >> 16) & 0xFF; 2885 CDB[6] = (io->size >> 16) & 0xFF;
2970 CDB[7] = (io->size >> 8) & 0xFF; 2886 CDB[7] = (io->size >> 8) & 0xFF;
2971 CDB[8] = io->size & 0xFF; 2887 CDB[8] = io->size & 0xFF;
2972 timeout = 10; 2888 timeout = 10;
2973 break; 2889 break;
2974 2890
2975 case RESERVE: 2891 case RESERVE:
2976 cmdLen = 6; 2892 cmdLen = 6;
2977 dir = MPI_SCSIIO_CONTROL_READ; 2893 dir = MPI_SCSIIO_CONTROL_READ;
2978 CDB[0] = cmd; 2894 CDB[0] = cmd;
2979 timeout = 10; 2895 timeout = 10;
2980 break; 2896 break;
2981 2897
2982 case RELEASE: 2898 case RELEASE:
2983 cmdLen = 6; 2899 cmdLen = 6;
2984 dir = MPI_SCSIIO_CONTROL_READ; 2900 dir = MPI_SCSIIO_CONTROL_READ;
2985 CDB[0] = cmd; 2901 CDB[0] = cmd;
2986 timeout = 10; 2902 timeout = 10;
2987 break; 2903 break;
2988 2904
2989 case SYNCHRONIZE_CACHE: 2905 case SYNCHRONIZE_CACHE:
2990 cmdLen = 10; 2906 cmdLen = 10;
2991 dir = MPI_SCSIIO_CONTROL_READ; 2907 dir = MPI_SCSIIO_CONTROL_READ;
2992 CDB[0] = cmd; 2908 CDB[0] = cmd;
2993 // CDB[1] = 0x02; /* set immediate bit */ 2909 // CDB[1] = 0x02; /* set immediate bit */
2994 timeout = 10; 2910 timeout = 10;
2995 break; 2911 break;
2996 2912
2997 default: 2913 default:
2998 /* Error Case */ 2914 /* Error Case */
2999 ret = -EFAULT; 2915 ret = -EFAULT;
3000 goto out; 2916 goto out;
3001 } 2917 }
3002 2918
3003 /* Get and Populate a free Frame 2919 /* Get and Populate a free Frame
3004 * MsgContext set in mpt_get_msg_frame call 2920 * MsgContext set in mpt_get_msg_frame call
3005 */ 2921 */
3006 if ((mf = mpt_get_msg_frame(ioc->InternalCtx, ioc)) == NULL) { 2922 if ((mf = mpt_get_msg_frame(ioc->InternalCtx, ioc)) == NULL) {
3007 dfailprintk(ioc, printk(MYIOC_s_WARN_FMT "%s: No msg frames!\n", 2923 dfailprintk(ioc, printk(MYIOC_s_WARN_FMT "%s: No msg frames!\n",
3008 ioc->name, __func__)); 2924 ioc->name, __func__));
3009 ret = MPT_SCANDV_BUSY; 2925 ret = MPT_SCANDV_BUSY;
3010 goto out; 2926 goto out;
3011 } 2927 }
3012 2928
3013 pScsiReq = (SCSIIORequest_t *) mf; 2929 pScsiReq = (SCSIIORequest_t *) mf;
3014 2930
3015 /* Get the request index */ 2931 /* Get the request index */
3016 my_idx = le16_to_cpu(mf->u.frame.hwhdr.msgctxu.fld.req_idx); 2932 my_idx = le16_to_cpu(mf->u.frame.hwhdr.msgctxu.fld.req_idx);
3017 ADD_INDEX_LOG(my_idx); /* for debug */ 2933 ADD_INDEX_LOG(my_idx); /* for debug */
3018 2934
3019 if (io->flags & MPT_ICFLAG_PHYS_DISK) { 2935 if (io->flags & MPT_ICFLAG_PHYS_DISK) {
3020 pScsiReq->TargetID = io->physDiskNum; 2936 pScsiReq->TargetID = io->physDiskNum;
3021 pScsiReq->Bus = 0; 2937 pScsiReq->Bus = 0;
3022 pScsiReq->ChainOffset = 0; 2938 pScsiReq->ChainOffset = 0;
3023 pScsiReq->Function = MPI_FUNCTION_RAID_SCSI_IO_PASSTHROUGH; 2939 pScsiReq->Function = MPI_FUNCTION_RAID_SCSI_IO_PASSTHROUGH;
3024 } else { 2940 } else {
3025 pScsiReq->TargetID = io->id; 2941 pScsiReq->TargetID = io->id;
3026 pScsiReq->Bus = io->channel; 2942 pScsiReq->Bus = io->channel;
3027 pScsiReq->ChainOffset = 0; 2943 pScsiReq->ChainOffset = 0;
3028 pScsiReq->Function = MPI_FUNCTION_SCSI_IO_REQUEST; 2944 pScsiReq->Function = MPI_FUNCTION_SCSI_IO_REQUEST;
3029 } 2945 }
3030 2946
3031 pScsiReq->CDBLength = cmdLen; 2947 pScsiReq->CDBLength = cmdLen;
3032 pScsiReq->SenseBufferLength = MPT_SENSE_BUFFER_SIZE; 2948 pScsiReq->SenseBufferLength = MPT_SENSE_BUFFER_SIZE;
3033 2949
3034 pScsiReq->Reserved = 0; 2950 pScsiReq->Reserved = 0;
3035 2951
3036 pScsiReq->MsgFlags = mpt_msg_flags(ioc); 2952 pScsiReq->MsgFlags = mpt_msg_flags(ioc);
3037 /* MsgContext set in mpt_get_msg_fram call */ 2953 /* MsgContext set in mpt_get_msg_fram call */
3038 2954
3039 int_to_scsilun(io->lun, (struct scsi_lun *)pScsiReq->LUN); 2955 int_to_scsilun(io->lun, (struct scsi_lun *)pScsiReq->LUN);
3040 2956
3041 if (io->flags & MPT_ICFLAG_TAGGED_CMD) 2957 if (io->flags & MPT_ICFLAG_TAGGED_CMD)
3042 pScsiReq->Control = cpu_to_le32(dir | MPI_SCSIIO_CONTROL_SIMPLEQ); 2958 pScsiReq->Control = cpu_to_le32(dir | MPI_SCSIIO_CONTROL_SIMPLEQ);
3043 else 2959 else
3044 pScsiReq->Control = cpu_to_le32(dir | MPI_SCSIIO_CONTROL_UNTAGGED); 2960 pScsiReq->Control = cpu_to_le32(dir | MPI_SCSIIO_CONTROL_UNTAGGED);
3045 2961
3046 if (cmd == REQUEST_SENSE) { 2962 if (cmd == REQUEST_SENSE) {
3047 pScsiReq->Control = cpu_to_le32(dir | MPI_SCSIIO_CONTROL_UNTAGGED); 2963 pScsiReq->Control = cpu_to_le32(dir | MPI_SCSIIO_CONTROL_UNTAGGED);
3048 devtprintk(ioc, printk(MYIOC_s_DEBUG_FMT 2964 devtprintk(ioc, printk(MYIOC_s_DEBUG_FMT
3049 "%s: Untagged! 0x%02x\n", ioc->name, __func__, cmd)); 2965 "%s: Untagged! 0x%02x\n", ioc->name, __func__, cmd));
3050 } 2966 }
3051 2967
3052 for (ii = 0; ii < 16; ii++) 2968 for (ii = 0; ii < 16; ii++)
3053 pScsiReq->CDB[ii] = CDB[ii]; 2969 pScsiReq->CDB[ii] = CDB[ii];
3054 2970
3055 pScsiReq->DataLength = cpu_to_le32(io->size); 2971 pScsiReq->DataLength = cpu_to_le32(io->size);
3056 pScsiReq->SenseBufferLowAddr = cpu_to_le32(ioc->sense_buf_low_dma 2972 pScsiReq->SenseBufferLowAddr = cpu_to_le32(ioc->sense_buf_low_dma
3057 + (my_idx * MPT_SENSE_BUFFER_ALLOC)); 2973 + (my_idx * MPT_SENSE_BUFFER_ALLOC));
3058 2974
3059 devtprintk(ioc, printk(MYIOC_s_DEBUG_FMT 2975 devtprintk(ioc, printk(MYIOC_s_DEBUG_FMT
3060 "%s: Sending Command 0x%02x for fw_channel=%d fw_id=%d lun=%d\n", 2976 "%s: Sending Command 0x%02x for fw_channel=%d fw_id=%d lun=%d\n",
3061 ioc->name, __func__, cmd, io->channel, io->id, io->lun)); 2977 ioc->name, __func__, cmd, io->channel, io->id, io->lun));
3062 2978
3063 if (dir == MPI_SCSIIO_CONTROL_READ) 2979 if (dir == MPI_SCSIIO_CONTROL_READ)
3064 ioc->add_sge((char *) &pScsiReq->SGL, 2980 ioc->add_sge((char *) &pScsiReq->SGL,
3065 MPT_SGE_FLAGS_SSIMPLE_READ | io->size, io->data_dma); 2981 MPT_SGE_FLAGS_SSIMPLE_READ | io->size, io->data_dma);
3066 else 2982 else
3067 ioc->add_sge((char *) &pScsiReq->SGL, 2983 ioc->add_sge((char *) &pScsiReq->SGL,
3068 MPT_SGE_FLAGS_SSIMPLE_WRITE | io->size, io->data_dma); 2984 MPT_SGE_FLAGS_SSIMPLE_WRITE | io->size, io->data_dma);
3069 2985
3070 INITIALIZE_MGMT_STATUS(ioc->internal_cmds.status) 2986 INITIALIZE_MGMT_STATUS(ioc->internal_cmds.status)
3071 mpt_put_msg_frame(ioc->InternalCtx, ioc, mf); 2987 mpt_put_msg_frame(ioc->InternalCtx, ioc, mf);
3072 timeleft = wait_for_completion_timeout(&ioc->internal_cmds.done, 2988 timeleft = wait_for_completion_timeout(&ioc->internal_cmds.done,
3073 timeout*HZ); 2989 timeout*HZ);
3074 if (!(ioc->internal_cmds.status & MPT_MGMT_STATUS_COMMAND_GOOD)) { 2990 if (!(ioc->internal_cmds.status & MPT_MGMT_STATUS_COMMAND_GOOD)) {
3075 ret = MPT_SCANDV_DID_RESET; 2991 ret = MPT_SCANDV_DID_RESET;
3076 dfailprintk(ioc, printk(MYIOC_s_DEBUG_FMT 2992 dfailprintk(ioc, printk(MYIOC_s_DEBUG_FMT
3077 "%s: TIMED OUT for cmd=0x%02x\n", ioc->name, __func__, 2993 "%s: TIMED OUT for cmd=0x%02x\n", ioc->name, __func__,
3078 cmd)); 2994 cmd));
3079 if (ioc->internal_cmds.status & MPT_MGMT_STATUS_DID_IOCRESET) { 2995 if (ioc->internal_cmds.status & MPT_MGMT_STATUS_DID_IOCRESET) {
3080 mpt_free_msg_frame(ioc, mf); 2996 mpt_free_msg_frame(ioc, mf);
3081 goto out; 2997 goto out;
3082 } 2998 }
3083 if (!timeleft) { 2999 if (!timeleft) {
3084 printk(MYIOC_s_WARN_FMT 3000 printk(MYIOC_s_WARN_FMT
3085 "Issuing Reset from %s!! doorbell=0x%08xh" 3001 "Issuing Reset from %s!! doorbell=0x%08xh"
3086 " cmd=0x%02x\n", 3002 " cmd=0x%02x\n",
3087 ioc->name, __func__, mpt_GetIocState(ioc, 0), 3003 ioc->name, __func__, mpt_GetIocState(ioc, 0),
3088 cmd); 3004 cmd);
3089 mpt_Soft_Hard_ResetHandler(ioc, CAN_SLEEP); 3005 mpt_Soft_Hard_ResetHandler(ioc, CAN_SLEEP);
3090 mpt_free_msg_frame(ioc, mf); 3006 mpt_free_msg_frame(ioc, mf);
3091 } 3007 }
3092 goto out; 3008 goto out;
3093 } 3009 }
3094 3010
3095 ret = ioc->internal_cmds.completion_code; 3011 ret = ioc->internal_cmds.completion_code;
3096 devtprintk(ioc, printk(MYIOC_s_DEBUG_FMT "%s: success, rc=0x%02x\n", 3012 devtprintk(ioc, printk(MYIOC_s_DEBUG_FMT "%s: success, rc=0x%02x\n",
3097 ioc->name, __func__, ret)); 3013 ioc->name, __func__, ret));
3098 3014
3099 out: 3015 out:
3100 CLEAR_MGMT_STATUS(ioc->internal_cmds.status) 3016 CLEAR_MGMT_STATUS(ioc->internal_cmds.status)
3101 mutex_unlock(&ioc->internal_cmds.mutex); 3017 mutex_unlock(&ioc->internal_cmds.mutex);
3102 return ret; 3018 return ret;
3103 } 3019 }
3104 3020
3105 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/ 3021 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
3106 /** 3022 /**
3107 * mptscsih_synchronize_cache - Send SYNCHRONIZE_CACHE to all disks. 3023 * mptscsih_synchronize_cache - Send SYNCHRONIZE_CACHE to all disks.
3108 * @hd: Pointer to a SCSI HOST structure 3024 * @hd: Pointer to a SCSI HOST structure
3109 * @vdevice: virtual target device 3025 * @vdevice: virtual target device
3110 * 3026 *
3111 * Uses the ISR, but with special processing. 3027 * Uses the ISR, but with special processing.
3112 * MUST be single-threaded. 3028 * MUST be single-threaded.
3113 * 3029 *
3114 */ 3030 */
3115 static void 3031 static void
3116 mptscsih_synchronize_cache(MPT_SCSI_HOST *hd, VirtDevice *vdevice) 3032 mptscsih_synchronize_cache(MPT_SCSI_HOST *hd, VirtDevice *vdevice)
3117 { 3033 {
3118 INTERNAL_CMD iocmd; 3034 INTERNAL_CMD iocmd;
3119 3035
3120 /* Ignore hidden raid components, this is handled when the command 3036 /* Ignore hidden raid components, this is handled when the command
3121 * is sent to the volume 3037 * is sent to the volume
3122 */ 3038 */
3123 if (vdevice->vtarget->tflags & MPT_TARGET_FLAGS_RAID_COMPONENT) 3039 if (vdevice->vtarget->tflags & MPT_TARGET_FLAGS_RAID_COMPONENT)
3124 return; 3040 return;
3125 3041
3126 if (vdevice->vtarget->type != TYPE_DISK || vdevice->vtarget->deleted || 3042 if (vdevice->vtarget->type != TYPE_DISK || vdevice->vtarget->deleted ||
3127 !vdevice->configured_lun) 3043 !vdevice->configured_lun)
3128 return; 3044 return;
3129 3045
3130 /* Following parameters will not change 3046 /* Following parameters will not change
3131 * in this routine. 3047 * in this routine.
3132 */ 3048 */
3133 iocmd.cmd = SYNCHRONIZE_CACHE; 3049 iocmd.cmd = SYNCHRONIZE_CACHE;
3134 iocmd.flags = 0; 3050 iocmd.flags = 0;
3135 iocmd.physDiskNum = -1; 3051 iocmd.physDiskNum = -1;
3136 iocmd.data = NULL; 3052 iocmd.data = NULL;
3137 iocmd.data_dma = -1; 3053 iocmd.data_dma = -1;
3138 iocmd.size = 0; 3054 iocmd.size = 0;
3139 iocmd.rsvd = iocmd.rsvd2 = 0; 3055 iocmd.rsvd = iocmd.rsvd2 = 0;
3140 iocmd.channel = vdevice->vtarget->channel; 3056 iocmd.channel = vdevice->vtarget->channel;
3141 iocmd.id = vdevice->vtarget->id; 3057 iocmd.id = vdevice->vtarget->id;
3142 iocmd.lun = vdevice->lun; 3058 iocmd.lun = vdevice->lun;
3143 3059
3144 mptscsih_do_cmd(hd, &iocmd); 3060 mptscsih_do_cmd(hd, &iocmd);
3145 } 3061 }
3146 3062
3147 static ssize_t 3063 static ssize_t
3148 mptscsih_version_fw_show(struct device *dev, struct device_attribute *attr, 3064 mptscsih_version_fw_show(struct device *dev, struct device_attribute *attr,
3149 char *buf) 3065 char *buf)
3150 { 3066 {
3151 struct Scsi_Host *host = class_to_shost(dev); 3067 struct Scsi_Host *host = class_to_shost(dev);
3152 MPT_SCSI_HOST *hd = shost_priv(host); 3068 MPT_SCSI_HOST *hd = shost_priv(host);
3153 MPT_ADAPTER *ioc = hd->ioc; 3069 MPT_ADAPTER *ioc = hd->ioc;
3154 3070
3155 return snprintf(buf, PAGE_SIZE, "%02d.%02d.%02d.%02d\n", 3071 return snprintf(buf, PAGE_SIZE, "%02d.%02d.%02d.%02d\n",
3156 (ioc->facts.FWVersion.Word & 0xFF000000) >> 24, 3072 (ioc->facts.FWVersion.Word & 0xFF000000) >> 24,
3157 (ioc->facts.FWVersion.Word & 0x00FF0000) >> 16, 3073 (ioc->facts.FWVersion.Word & 0x00FF0000) >> 16,
3158 (ioc->facts.FWVersion.Word & 0x0000FF00) >> 8, 3074 (ioc->facts.FWVersion.Word & 0x0000FF00) >> 8,
3159 ioc->facts.FWVersion.Word & 0x000000FF); 3075 ioc->facts.FWVersion.Word & 0x000000FF);
3160 } 3076 }
3161 static DEVICE_ATTR(version_fw, S_IRUGO, mptscsih_version_fw_show, NULL); 3077 static DEVICE_ATTR(version_fw, S_IRUGO, mptscsih_version_fw_show, NULL);
3162 3078
3163 static ssize_t 3079 static ssize_t
3164 mptscsih_version_bios_show(struct device *dev, struct device_attribute *attr, 3080 mptscsih_version_bios_show(struct device *dev, struct device_attribute *attr,
3165 char *buf) 3081 char *buf)
3166 { 3082 {
3167 struct Scsi_Host *host = class_to_shost(dev); 3083 struct Scsi_Host *host = class_to_shost(dev);
3168 MPT_SCSI_HOST *hd = shost_priv(host); 3084 MPT_SCSI_HOST *hd = shost_priv(host);
3169 MPT_ADAPTER *ioc = hd->ioc; 3085 MPT_ADAPTER *ioc = hd->ioc;
3170 3086
3171 return snprintf(buf, PAGE_SIZE, "%02x.%02x.%02x.%02x\n", 3087 return snprintf(buf, PAGE_SIZE, "%02x.%02x.%02x.%02x\n",
3172 (ioc->biosVersion & 0xFF000000) >> 24, 3088 (ioc->biosVersion & 0xFF000000) >> 24,
3173 (ioc->biosVersion & 0x00FF0000) >> 16, 3089 (ioc->biosVersion & 0x00FF0000) >> 16,
3174 (ioc->biosVersion & 0x0000FF00) >> 8, 3090 (ioc->biosVersion & 0x0000FF00) >> 8,
3175 ioc->biosVersion & 0x000000FF); 3091 ioc->biosVersion & 0x000000FF);
3176 } 3092 }
3177 static DEVICE_ATTR(version_bios, S_IRUGO, mptscsih_version_bios_show, NULL); 3093 static DEVICE_ATTR(version_bios, S_IRUGO, mptscsih_version_bios_show, NULL);
3178 3094
3179 static ssize_t 3095 static ssize_t
3180 mptscsih_version_mpi_show(struct device *dev, struct device_attribute *attr, 3096 mptscsih_version_mpi_show(struct device *dev, struct device_attribute *attr,
3181 char *buf) 3097 char *buf)
3182 { 3098 {
3183 struct Scsi_Host *host = class_to_shost(dev); 3099 struct Scsi_Host *host = class_to_shost(dev);
3184 MPT_SCSI_HOST *hd = shost_priv(host); 3100 MPT_SCSI_HOST *hd = shost_priv(host);
3185 MPT_ADAPTER *ioc = hd->ioc; 3101 MPT_ADAPTER *ioc = hd->ioc;
3186 3102
3187 return snprintf(buf, PAGE_SIZE, "%03x\n", ioc->facts.MsgVersion); 3103 return snprintf(buf, PAGE_SIZE, "%03x\n", ioc->facts.MsgVersion);
3188 } 3104 }
3189 static DEVICE_ATTR(version_mpi, S_IRUGO, mptscsih_version_mpi_show, NULL); 3105 static DEVICE_ATTR(version_mpi, S_IRUGO, mptscsih_version_mpi_show, NULL);
3190 3106
3191 static ssize_t 3107 static ssize_t
3192 mptscsih_version_product_show(struct device *dev, 3108 mptscsih_version_product_show(struct device *dev,
3193 struct device_attribute *attr, 3109 struct device_attribute *attr,
3194 char *buf) 3110 char *buf)
3195 { 3111 {
3196 struct Scsi_Host *host = class_to_shost(dev); 3112 struct Scsi_Host *host = class_to_shost(dev);
3197 MPT_SCSI_HOST *hd = shost_priv(host); 3113 MPT_SCSI_HOST *hd = shost_priv(host);
3198 MPT_ADAPTER *ioc = hd->ioc; 3114 MPT_ADAPTER *ioc = hd->ioc;
3199 3115
3200 return snprintf(buf, PAGE_SIZE, "%s\n", ioc->prod_name); 3116 return snprintf(buf, PAGE_SIZE, "%s\n", ioc->prod_name);
3201 } 3117 }
3202 static DEVICE_ATTR(version_product, S_IRUGO, 3118 static DEVICE_ATTR(version_product, S_IRUGO,
3203 mptscsih_version_product_show, NULL); 3119 mptscsih_version_product_show, NULL);
3204 3120
3205 static ssize_t 3121 static ssize_t
3206 mptscsih_version_nvdata_persistent_show(struct device *dev, 3122 mptscsih_version_nvdata_persistent_show(struct device *dev,
3207 struct device_attribute *attr, 3123 struct device_attribute *attr,
3208 char *buf) 3124 char *buf)
3209 { 3125 {
3210 struct Scsi_Host *host = class_to_shost(dev); 3126 struct Scsi_Host *host = class_to_shost(dev);
3211 MPT_SCSI_HOST *hd = shost_priv(host); 3127 MPT_SCSI_HOST *hd = shost_priv(host);
3212 MPT_ADAPTER *ioc = hd->ioc; 3128 MPT_ADAPTER *ioc = hd->ioc;
3213 3129
3214 return snprintf(buf, PAGE_SIZE, "%02xh\n", 3130 return snprintf(buf, PAGE_SIZE, "%02xh\n",
3215 ioc->nvdata_version_persistent); 3131 ioc->nvdata_version_persistent);
3216 } 3132 }
3217 static DEVICE_ATTR(version_nvdata_persistent, S_IRUGO, 3133 static DEVICE_ATTR(version_nvdata_persistent, S_IRUGO,
3218 mptscsih_version_nvdata_persistent_show, NULL); 3134 mptscsih_version_nvdata_persistent_show, NULL);
3219 3135
3220 static ssize_t 3136 static ssize_t
3221 mptscsih_version_nvdata_default_show(struct device *dev, 3137 mptscsih_version_nvdata_default_show(struct device *dev,
3222 struct device_attribute *attr, char *buf) 3138 struct device_attribute *attr, char *buf)
3223 { 3139 {
3224 struct Scsi_Host *host = class_to_shost(dev); 3140 struct Scsi_Host *host = class_to_shost(dev);
3225 MPT_SCSI_HOST *hd = shost_priv(host); 3141 MPT_SCSI_HOST *hd = shost_priv(host);
3226 MPT_ADAPTER *ioc = hd->ioc; 3142 MPT_ADAPTER *ioc = hd->ioc;
3227 3143
3228 return snprintf(buf, PAGE_SIZE, "%02xh\n",ioc->nvdata_version_default); 3144 return snprintf(buf, PAGE_SIZE, "%02xh\n",ioc->nvdata_version_default);
3229 } 3145 }
3230 static DEVICE_ATTR(version_nvdata_default, S_IRUGO, 3146 static DEVICE_ATTR(version_nvdata_default, S_IRUGO,
3231 mptscsih_version_nvdata_default_show, NULL); 3147 mptscsih_version_nvdata_default_show, NULL);
3232 3148
3233 static ssize_t 3149 static ssize_t
3234 mptscsih_board_name_show(struct device *dev, struct device_attribute *attr, 3150 mptscsih_board_name_show(struct device *dev, struct device_attribute *attr,
3235 char *buf) 3151 char *buf)
3236 { 3152 {
3237 struct Scsi_Host *host = class_to_shost(dev); 3153 struct Scsi_Host *host = class_to_shost(dev);
3238 MPT_SCSI_HOST *hd = shost_priv(host); 3154 MPT_SCSI_HOST *hd = shost_priv(host);
3239 MPT_ADAPTER *ioc = hd->ioc; 3155 MPT_ADAPTER *ioc = hd->ioc;
3240 3156
3241 return snprintf(buf, PAGE_SIZE, "%s\n", ioc->board_name); 3157 return snprintf(buf, PAGE_SIZE, "%s\n", ioc->board_name);
3242 } 3158 }
3243 static DEVICE_ATTR(board_name, S_IRUGO, mptscsih_board_name_show, NULL); 3159 static DEVICE_ATTR(board_name, S_IRUGO, mptscsih_board_name_show, NULL);
3244 3160
3245 static ssize_t 3161 static ssize_t
3246 mptscsih_board_assembly_show(struct device *dev, 3162 mptscsih_board_assembly_show(struct device *dev,
3247 struct device_attribute *attr, char *buf) 3163 struct device_attribute *attr, char *buf)
3248 { 3164 {
3249 struct Scsi_Host *host = class_to_shost(dev); 3165 struct Scsi_Host *host = class_to_shost(dev);
3250 MPT_SCSI_HOST *hd = shost_priv(host); 3166 MPT_SCSI_HOST *hd = shost_priv(host);
3251 MPT_ADAPTER *ioc = hd->ioc; 3167 MPT_ADAPTER *ioc = hd->ioc;
3252 3168
3253 return snprintf(buf, PAGE_SIZE, "%s\n", ioc->board_assembly); 3169 return snprintf(buf, PAGE_SIZE, "%s\n", ioc->board_assembly);
3254 } 3170 }
3255 static DEVICE_ATTR(board_assembly, S_IRUGO, 3171 static DEVICE_ATTR(board_assembly, S_IRUGO,
3256 mptscsih_board_assembly_show, NULL); 3172 mptscsih_board_assembly_show, NULL);
3257 3173
3258 static ssize_t 3174 static ssize_t
3259 mptscsih_board_tracer_show(struct device *dev, struct device_attribute *attr, 3175 mptscsih_board_tracer_show(struct device *dev, struct device_attribute *attr,
3260 char *buf) 3176 char *buf)
3261 { 3177 {
3262 struct Scsi_Host *host = class_to_shost(dev); 3178 struct Scsi_Host *host = class_to_shost(dev);
3263 MPT_SCSI_HOST *hd = shost_priv(host); 3179 MPT_SCSI_HOST *hd = shost_priv(host);
3264 MPT_ADAPTER *ioc = hd->ioc; 3180 MPT_ADAPTER *ioc = hd->ioc;
3265 3181
3266 return snprintf(buf, PAGE_SIZE, "%s\n", ioc->board_tracer); 3182 return snprintf(buf, PAGE_SIZE, "%s\n", ioc->board_tracer);
3267 } 3183 }
3268 static DEVICE_ATTR(board_tracer, S_IRUGO, 3184 static DEVICE_ATTR(board_tracer, S_IRUGO,
3269 mptscsih_board_tracer_show, NULL); 3185 mptscsih_board_tracer_show, NULL);
3270 3186
3271 static ssize_t 3187 static ssize_t
3272 mptscsih_io_delay_show(struct device *dev, struct device_attribute *attr, 3188 mptscsih_io_delay_show(struct device *dev, struct device_attribute *attr,
3273 char *buf) 3189 char *buf)
3274 { 3190 {
3275 struct Scsi_Host *host = class_to_shost(dev); 3191 struct Scsi_Host *host = class_to_shost(dev);
3276 MPT_SCSI_HOST *hd = shost_priv(host); 3192 MPT_SCSI_HOST *hd = shost_priv(host);
3277 MPT_ADAPTER *ioc = hd->ioc; 3193 MPT_ADAPTER *ioc = hd->ioc;
3278 3194
3279 return snprintf(buf, PAGE_SIZE, "%02d\n", ioc->io_missing_delay); 3195 return snprintf(buf, PAGE_SIZE, "%02d\n", ioc->io_missing_delay);
3280 } 3196 }
3281 static DEVICE_ATTR(io_delay, S_IRUGO, 3197 static DEVICE_ATTR(io_delay, S_IRUGO,
3282 mptscsih_io_delay_show, NULL); 3198 mptscsih_io_delay_show, NULL);
3283 3199
3284 static ssize_t 3200 static ssize_t
3285 mptscsih_device_delay_show(struct device *dev, struct device_attribute *attr, 3201 mptscsih_device_delay_show(struct device *dev, struct device_attribute *attr,
3286 char *buf) 3202 char *buf)
3287 { 3203 {
3288 struct Scsi_Host *host = class_to_shost(dev); 3204 struct Scsi_Host *host = class_to_shost(dev);
3289 MPT_SCSI_HOST *hd = shost_priv(host); 3205 MPT_SCSI_HOST *hd = shost_priv(host);
3290 MPT_ADAPTER *ioc = hd->ioc; 3206 MPT_ADAPTER *ioc = hd->ioc;
3291 3207
3292 return snprintf(buf, PAGE_SIZE, "%02d\n", ioc->device_missing_delay); 3208 return snprintf(buf, PAGE_SIZE, "%02d\n", ioc->device_missing_delay);
3293 } 3209 }
3294 static DEVICE_ATTR(device_delay, S_IRUGO, 3210 static DEVICE_ATTR(device_delay, S_IRUGO,
3295 mptscsih_device_delay_show, NULL); 3211 mptscsih_device_delay_show, NULL);
3296 3212
3297 static ssize_t 3213 static ssize_t
3298 mptscsih_debug_level_show(struct device *dev, struct device_attribute *attr, 3214 mptscsih_debug_level_show(struct device *dev, struct device_attribute *attr,
3299 char *buf) 3215 char *buf)
3300 { 3216 {
3301 struct Scsi_Host *host = class_to_shost(dev); 3217 struct Scsi_Host *host = class_to_shost(dev);
3302 MPT_SCSI_HOST *hd = shost_priv(host); 3218 MPT_SCSI_HOST *hd = shost_priv(host);
3303 MPT_ADAPTER *ioc = hd->ioc; 3219 MPT_ADAPTER *ioc = hd->ioc;
3304 3220
3305 return snprintf(buf, PAGE_SIZE, "%08xh\n", ioc->debug_level); 3221 return snprintf(buf, PAGE_SIZE, "%08xh\n", ioc->debug_level);
3306 } 3222 }
3307 static ssize_t 3223 static ssize_t
3308 mptscsih_debug_level_store(struct device *dev, struct device_attribute *attr, 3224 mptscsih_debug_level_store(struct device *dev, struct device_attribute *attr,
3309 const char *buf, size_t count) 3225 const char *buf, size_t count)
3310 { 3226 {
3311 struct Scsi_Host *host = class_to_shost(dev); 3227 struct Scsi_Host *host = class_to_shost(dev);
3312 MPT_SCSI_HOST *hd = shost_priv(host); 3228 MPT_SCSI_HOST *hd = shost_priv(host);
3313 MPT_ADAPTER *ioc = hd->ioc; 3229 MPT_ADAPTER *ioc = hd->ioc;
3314 int val = 0; 3230 int val = 0;
3315 3231
3316 if (sscanf(buf, "%x", &val) != 1) 3232 if (sscanf(buf, "%x", &val) != 1)
3317 return -EINVAL; 3233 return -EINVAL;
3318 3234
3319 ioc->debug_level = val; 3235 ioc->debug_level = val;
3320 printk(MYIOC_s_INFO_FMT "debug_level=%08xh\n", 3236 printk(MYIOC_s_INFO_FMT "debug_level=%08xh\n",
3321 ioc->name, ioc->debug_level); 3237 ioc->name, ioc->debug_level);
3322 return strlen(buf); 3238 return strlen(buf);
3323 } 3239 }
3324 static DEVICE_ATTR(debug_level, S_IRUGO | S_IWUSR, 3240 static DEVICE_ATTR(debug_level, S_IRUGO | S_IWUSR,
3325 mptscsih_debug_level_show, mptscsih_debug_level_store); 3241 mptscsih_debug_level_show, mptscsih_debug_level_store);
3326 3242
3327 struct device_attribute *mptscsih_host_attrs[] = { 3243 struct device_attribute *mptscsih_host_attrs[] = {
3328 &dev_attr_version_fw, 3244 &dev_attr_version_fw,
3329 &dev_attr_version_bios, 3245 &dev_attr_version_bios,
3330 &dev_attr_version_mpi, 3246 &dev_attr_version_mpi,
3331 &dev_attr_version_product, 3247 &dev_attr_version_product,
3332 &dev_attr_version_nvdata_persistent, 3248 &dev_attr_version_nvdata_persistent,
3333 &dev_attr_version_nvdata_default, 3249 &dev_attr_version_nvdata_default,
3334 &dev_attr_board_name, 3250 &dev_attr_board_name,
3335 &dev_attr_board_assembly, 3251 &dev_attr_board_assembly,
3336 &dev_attr_board_tracer, 3252 &dev_attr_board_tracer,
3337 &dev_attr_io_delay, 3253 &dev_attr_io_delay,
3338 &dev_attr_device_delay, 3254 &dev_attr_device_delay,
3339 &dev_attr_debug_level, 3255 &dev_attr_debug_level,
3340 NULL, 3256 NULL,
3341 }; 3257 };
3342 3258
3343 EXPORT_SYMBOL(mptscsih_host_attrs); 3259 EXPORT_SYMBOL(mptscsih_host_attrs);
3344 3260
3345 EXPORT_SYMBOL(mptscsih_remove); 3261 EXPORT_SYMBOL(mptscsih_remove);
3346 EXPORT_SYMBOL(mptscsih_shutdown); 3262 EXPORT_SYMBOL(mptscsih_shutdown);
3347 #ifdef CONFIG_PM 3263 #ifdef CONFIG_PM
3348 EXPORT_SYMBOL(mptscsih_suspend); 3264 EXPORT_SYMBOL(mptscsih_suspend);
3349 EXPORT_SYMBOL(mptscsih_resume); 3265 EXPORT_SYMBOL(mptscsih_resume);
3350 #endif 3266 #endif
3351 EXPORT_SYMBOL(mptscsih_proc_info); 3267 EXPORT_SYMBOL(mptscsih_show_info);
3352 EXPORT_SYMBOL(mptscsih_info); 3268 EXPORT_SYMBOL(mptscsih_info);
3353 EXPORT_SYMBOL(mptscsih_qcmd); 3269 EXPORT_SYMBOL(mptscsih_qcmd);
3354 EXPORT_SYMBOL(mptscsih_slave_destroy); 3270 EXPORT_SYMBOL(mptscsih_slave_destroy);
3355 EXPORT_SYMBOL(mptscsih_slave_configure); 3271 EXPORT_SYMBOL(mptscsih_slave_configure);
3356 EXPORT_SYMBOL(mptscsih_abort); 3272 EXPORT_SYMBOL(mptscsih_abort);
3357 EXPORT_SYMBOL(mptscsih_dev_reset); 3273 EXPORT_SYMBOL(mptscsih_dev_reset);
3358 EXPORT_SYMBOL(mptscsih_bus_reset); 3274 EXPORT_SYMBOL(mptscsih_bus_reset);
3359 EXPORT_SYMBOL(mptscsih_host_reset); 3275 EXPORT_SYMBOL(mptscsih_host_reset);
3360 EXPORT_SYMBOL(mptscsih_bios_param); 3276 EXPORT_SYMBOL(mptscsih_bios_param);
3361 EXPORT_SYMBOL(mptscsih_io_done); 3277 EXPORT_SYMBOL(mptscsih_io_done);
3362 EXPORT_SYMBOL(mptscsih_taskmgmt_complete); 3278 EXPORT_SYMBOL(mptscsih_taskmgmt_complete);
3363 EXPORT_SYMBOL(mptscsih_scandv_complete); 3279 EXPORT_SYMBOL(mptscsih_scandv_complete);
3364 EXPORT_SYMBOL(mptscsih_event_process); 3280 EXPORT_SYMBOL(mptscsih_event_process);
3365 EXPORT_SYMBOL(mptscsih_ioc_reset); 3281 EXPORT_SYMBOL(mptscsih_ioc_reset);
3366 EXPORT_SYMBOL(mptscsih_change_queue_depth); 3282 EXPORT_SYMBOL(mptscsih_change_queue_depth);
3367 3283
3368 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/ 3284 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
3369 3285
drivers/message/fusion/mptscsih.h
1 /* 1 /*
2 * linux/drivers/message/fusion/mptscsih.h 2 * linux/drivers/message/fusion/mptscsih.h
3 * High performance SCSI / Fibre Channel SCSI Host device driver. 3 * High performance SCSI / Fibre Channel SCSI Host device driver.
4 * For use with PCI chip/adapter(s): 4 * For use with PCI chip/adapter(s):
5 * LSIFC9xx/LSI409xx Fibre Channel 5 * LSIFC9xx/LSI409xx Fibre Channel
6 * running LSI Fusion MPT (Message Passing Technology) firmware. 6 * running LSI Fusion MPT (Message Passing Technology) firmware.
7 * 7 *
8 * Copyright (c) 1999-2008 LSI Corporation 8 * Copyright (c) 1999-2008 LSI Corporation
9 * (mailto:DL-MPTFusionLinux@lsi.com) 9 * (mailto:DL-MPTFusionLinux@lsi.com)
10 * 10 *
11 */ 11 */
12 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/ 12 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
13 /* 13 /*
14 This program is free software; you can redistribute it and/or modify 14 This program is free software; you can redistribute it and/or modify
15 it under the terms of the GNU General Public License as published by 15 it under the terms of the GNU General Public License as published by
16 the Free Software Foundation; version 2 of the License. 16 the Free Software Foundation; version 2 of the License.
17 17
18 This program is distributed in the hope that it will be useful, 18 This program is distributed in the hope that it will be useful,
19 but WITHOUT ANY WARRANTY; without even the implied warranty of 19 but WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 GNU General Public License for more details. 21 GNU General Public License for more details.
22 22
23 NO WARRANTY 23 NO WARRANTY
24 THE PROGRAM IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR 24 THE PROGRAM IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR
25 CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT 25 CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT
26 LIMITATION, ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT, 26 LIMITATION, ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT,
27 MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Each Recipient is 27 MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Each Recipient is
28 solely responsible for determining the appropriateness of using and 28 solely responsible for determining the appropriateness of using and
29 distributing the Program and assumes all risks associated with its 29 distributing the Program and assumes all risks associated with its
30 exercise of rights under this Agreement, including but not limited to 30 exercise of rights under this Agreement, including but not limited to
31 the risks and costs of program errors, damage to or loss of data, 31 the risks and costs of program errors, damage to or loss of data,
32 programs or equipment, and unavailability or interruption of operations. 32 programs or equipment, and unavailability or interruption of operations.
33 33
34 DISCLAIMER OF LIABILITY 34 DISCLAIMER OF LIABILITY
35 NEITHER RECIPIENT NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY 35 NEITHER RECIPIENT NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY
36 DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 36 DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
37 DAMAGES (INCLUDING WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND 37 DAMAGES (INCLUDING WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND
38 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR 38 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
39 TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE 39 TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
40 USE OR DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS GRANTED 40 USE OR DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS GRANTED
41 HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES 41 HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES
42 42
43 You should have received a copy of the GNU General Public License 43 You should have received a copy of the GNU General Public License
44 along with this program; if not, write to the Free Software 44 along with this program; if not, write to the Free Software
45 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 45 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
46 */ 46 */
47 47
48 #ifndef SCSIHOST_H_INCLUDED 48 #ifndef SCSIHOST_H_INCLUDED
49 #define SCSIHOST_H_INCLUDED 49 #define SCSIHOST_H_INCLUDED
50 50
51 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/ 51 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
52 /* 52 /*
53 * SCSI Public stuff... 53 * SCSI Public stuff...
54 */ 54 */
55 55
56 #define MPT_SCANDV_GOOD (0x00000000) /* must be 0 */ 56 #define MPT_SCANDV_GOOD (0x00000000) /* must be 0 */
57 #define MPT_SCANDV_DID_RESET (0x00000001) 57 #define MPT_SCANDV_DID_RESET (0x00000001)
58 #define MPT_SCANDV_SENSE (0x00000002) 58 #define MPT_SCANDV_SENSE (0x00000002)
59 #define MPT_SCANDV_SOME_ERROR (0x00000004) 59 #define MPT_SCANDV_SOME_ERROR (0x00000004)
60 #define MPT_SCANDV_SELECTION_TIMEOUT (0x00000008) 60 #define MPT_SCANDV_SELECTION_TIMEOUT (0x00000008)
61 #define MPT_SCANDV_ISSUE_SENSE (0x00000010) 61 #define MPT_SCANDV_ISSUE_SENSE (0x00000010)
62 #define MPT_SCANDV_FALLBACK (0x00000020) 62 #define MPT_SCANDV_FALLBACK (0x00000020)
63 #define MPT_SCANDV_BUSY (0x00000040) 63 #define MPT_SCANDV_BUSY (0x00000040)
64 64
65 #define MPT_SCANDV_MAX_RETRIES (10) 65 #define MPT_SCANDV_MAX_RETRIES (10)
66 66
67 #define MPT_ICFLAG_BUF_CAP 0x01 /* ReadBuffer Read Capacity format */ 67 #define MPT_ICFLAG_BUF_CAP 0x01 /* ReadBuffer Read Capacity format */
68 #define MPT_ICFLAG_ECHO 0x02 /* ReadBuffer Echo buffer format */ 68 #define MPT_ICFLAG_ECHO 0x02 /* ReadBuffer Echo buffer format */
69 #define MPT_ICFLAG_EBOS 0x04 /* ReadBuffer Echo buffer has EBOS */ 69 #define MPT_ICFLAG_EBOS 0x04 /* ReadBuffer Echo buffer has EBOS */
70 #define MPT_ICFLAG_PHYS_DISK 0x08 /* Any SCSI IO but do Phys Disk Format */ 70 #define MPT_ICFLAG_PHYS_DISK 0x08 /* Any SCSI IO but do Phys Disk Format */
71 #define MPT_ICFLAG_TAGGED_CMD 0x10 /* Do tagged IO */ 71 #define MPT_ICFLAG_TAGGED_CMD 0x10 /* Do tagged IO */
72 #define MPT_ICFLAG_DID_RESET 0x20 /* Bus Reset occurred with this command */ 72 #define MPT_ICFLAG_DID_RESET 0x20 /* Bus Reset occurred with this command */
73 #define MPT_ICFLAG_RESERVED 0x40 /* Reserved has been issued */ 73 #define MPT_ICFLAG_RESERVED 0x40 /* Reserved has been issued */
74 74
75 #define MPT_SCSI_CMD_PER_DEV_HIGH 64 75 #define MPT_SCSI_CMD_PER_DEV_HIGH 64
76 #define MPT_SCSI_CMD_PER_DEV_LOW 32 76 #define MPT_SCSI_CMD_PER_DEV_LOW 32
77 77
78 #define MPT_SCSI_CMD_PER_LUN 7 78 #define MPT_SCSI_CMD_PER_LUN 7
79 79
80 #define MPT_SCSI_MAX_SECTORS 8192 80 #define MPT_SCSI_MAX_SECTORS 8192
81 81
82 /* SCSI driver setup structure. Settings can be overridden 82 /* SCSI driver setup structure. Settings can be overridden
83 * by command line options. 83 * by command line options.
84 */ 84 */
85 #define MPTSCSIH_DOMAIN_VALIDATION 1 85 #define MPTSCSIH_DOMAIN_VALIDATION 1
86 #define MPTSCSIH_MAX_WIDTH 1 86 #define MPTSCSIH_MAX_WIDTH 1
87 #define MPTSCSIH_MIN_SYNC 0x08 87 #define MPTSCSIH_MIN_SYNC 0x08
88 #define MPTSCSIH_SAF_TE 0 88 #define MPTSCSIH_SAF_TE 0
89 #define MPTSCSIH_PT_CLEAR 0 89 #define MPTSCSIH_PT_CLEAR 0
90 90
91 #endif 91 #endif
92 92
93 93
94 typedef struct _internal_cmd { 94 typedef struct _internal_cmd {
95 char *data; /* data pointer */ 95 char *data; /* data pointer */
96 dma_addr_t data_dma; /* data dma address */ 96 dma_addr_t data_dma; /* data dma address */
97 int size; /* transfer size */ 97 int size; /* transfer size */
98 u8 cmd; /* SCSI Op Code */ 98 u8 cmd; /* SCSI Op Code */
99 u8 channel; /* bus number */ 99 u8 channel; /* bus number */
100 u8 id; /* SCSI ID (virtual) */ 100 u8 id; /* SCSI ID (virtual) */
101 int lun; 101 int lun;
102 u8 flags; /* Bit Field - See above */ 102 u8 flags; /* Bit Field - See above */
103 u8 physDiskNum; /* Phys disk number, -1 else */ 103 u8 physDiskNum; /* Phys disk number, -1 else */
104 u8 rsvd2; 104 u8 rsvd2;
105 u8 rsvd; 105 u8 rsvd;
106 } INTERNAL_CMD; 106 } INTERNAL_CMD;
107 107
108 extern void mptscsih_remove(struct pci_dev *); 108 extern void mptscsih_remove(struct pci_dev *);
109 extern void mptscsih_shutdown(struct pci_dev *); 109 extern void mptscsih_shutdown(struct pci_dev *);
110 #ifdef CONFIG_PM 110 #ifdef CONFIG_PM
111 extern int mptscsih_suspend(struct pci_dev *pdev, pm_message_t state); 111 extern int mptscsih_suspend(struct pci_dev *pdev, pm_message_t state);
112 extern int mptscsih_resume(struct pci_dev *pdev); 112 extern int mptscsih_resume(struct pci_dev *pdev);
113 #endif 113 #endif
114 extern int mptscsih_proc_info(struct Scsi_Host *host, char *buffer, char **start, off_t offset, int length, int func); 114 extern int mptscsih_show_info(struct seq_file *, struct Scsi_Host *);
115 extern const char * mptscsih_info(struct Scsi_Host *SChost); 115 extern const char * mptscsih_info(struct Scsi_Host *SChost);
116 extern int mptscsih_qcmd(struct scsi_cmnd *SCpnt, void (*done)(struct scsi_cmnd *)); 116 extern int mptscsih_qcmd(struct scsi_cmnd *SCpnt, void (*done)(struct scsi_cmnd *));
117 extern int mptscsih_IssueTaskMgmt(MPT_SCSI_HOST *hd, u8 type, u8 channel, 117 extern int mptscsih_IssueTaskMgmt(MPT_SCSI_HOST *hd, u8 type, u8 channel,
118 u8 id, int lun, int ctx2abort, ulong timeout); 118 u8 id, int lun, int ctx2abort, ulong timeout);
119 extern void mptscsih_slave_destroy(struct scsi_device *device); 119 extern void mptscsih_slave_destroy(struct scsi_device *device);
120 extern int mptscsih_slave_configure(struct scsi_device *device); 120 extern int mptscsih_slave_configure(struct scsi_device *device);
121 extern int mptscsih_abort(struct scsi_cmnd * SCpnt); 121 extern int mptscsih_abort(struct scsi_cmnd * SCpnt);
122 extern int mptscsih_dev_reset(struct scsi_cmnd * SCpnt); 122 extern int mptscsih_dev_reset(struct scsi_cmnd * SCpnt);
123 extern int mptscsih_bus_reset(struct scsi_cmnd * SCpnt); 123 extern int mptscsih_bus_reset(struct scsi_cmnd * SCpnt);
124 extern int mptscsih_host_reset(struct scsi_cmnd *SCpnt); 124 extern int mptscsih_host_reset(struct scsi_cmnd *SCpnt);
125 extern int mptscsih_bios_param(struct scsi_device * sdev, struct block_device *bdev, sector_t capacity, int geom[]); 125 extern int mptscsih_bios_param(struct scsi_device * sdev, struct block_device *bdev, sector_t capacity, int geom[]);
126 extern int mptscsih_io_done(MPT_ADAPTER *ioc, MPT_FRAME_HDR *mf, MPT_FRAME_HDR *r); 126 extern int mptscsih_io_done(MPT_ADAPTER *ioc, MPT_FRAME_HDR *mf, MPT_FRAME_HDR *r);
127 extern int mptscsih_taskmgmt_complete(MPT_ADAPTER *ioc, MPT_FRAME_HDR *mf, MPT_FRAME_HDR *r); 127 extern int mptscsih_taskmgmt_complete(MPT_ADAPTER *ioc, MPT_FRAME_HDR *mf, MPT_FRAME_HDR *r);
128 extern int mptscsih_scandv_complete(MPT_ADAPTER *ioc, MPT_FRAME_HDR *mf, MPT_FRAME_HDR *r); 128 extern int mptscsih_scandv_complete(MPT_ADAPTER *ioc, MPT_FRAME_HDR *mf, MPT_FRAME_HDR *r);
129 extern int mptscsih_event_process(MPT_ADAPTER *ioc, EventNotificationReply_t *pEvReply); 129 extern int mptscsih_event_process(MPT_ADAPTER *ioc, EventNotificationReply_t *pEvReply);
130 extern int mptscsih_ioc_reset(MPT_ADAPTER *ioc, int post_reset); 130 extern int mptscsih_ioc_reset(MPT_ADAPTER *ioc, int post_reset);
131 extern int mptscsih_change_queue_depth(struct scsi_device *sdev, int qdepth, 131 extern int mptscsih_change_queue_depth(struct scsi_device *sdev, int qdepth,
132 int reason); 132 int reason);
133 extern u8 mptscsih_raid_id_to_num(MPT_ADAPTER *ioc, u8 channel, u8 id); 133 extern u8 mptscsih_raid_id_to_num(MPT_ADAPTER *ioc, u8 channel, u8 id);
134 extern int mptscsih_is_phys_disk(MPT_ADAPTER *ioc, u8 channel, u8 id); 134 extern int mptscsih_is_phys_disk(MPT_ADAPTER *ioc, u8 channel, u8 id);
135 extern struct device_attribute *mptscsih_host_attrs[]; 135 extern struct device_attribute *mptscsih_host_attrs[];
136 extern struct scsi_cmnd *mptscsih_get_scsi_lookup(MPT_ADAPTER *ioc, int i); 136 extern struct scsi_cmnd *mptscsih_get_scsi_lookup(MPT_ADAPTER *ioc, int i);
137 extern void mptscsih_taskmgmt_response_code(MPT_ADAPTER *ioc, u8 response_code); 137 extern void mptscsih_taskmgmt_response_code(MPT_ADAPTER *ioc, u8 response_code);
138 extern void mptscsih_flush_running_cmds(MPT_SCSI_HOST *hd); 138 extern void mptscsih_flush_running_cmds(MPT_SCSI_HOST *hd);
139 139
drivers/message/fusion/mptspi.c
1 /* 1 /*
2 * linux/drivers/message/fusion/mptspi.c 2 * linux/drivers/message/fusion/mptspi.c
3 * For use with LSI PCI chip/adapter(s) 3 * For use with LSI PCI chip/adapter(s)
4 * running LSI Fusion MPT (Message Passing Technology) firmware. 4 * running LSI Fusion MPT (Message Passing Technology) firmware.
5 * 5 *
6 * Copyright (c) 1999-2008 LSI Corporation 6 * Copyright (c) 1999-2008 LSI Corporation
7 * (mailto:DL-MPTFusionLinux@lsi.com) 7 * (mailto:DL-MPTFusionLinux@lsi.com)
8 * 8 *
9 */ 9 */
10 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/ 10 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
11 /* 11 /*
12 This program is free software; you can redistribute it and/or modify 12 This program is free software; you can redistribute it and/or modify
13 it under the terms of the GNU General Public License as published by 13 it under the terms of the GNU General Public License as published by
14 the Free Software Foundation; version 2 of the License. 14 the Free Software Foundation; version 2 of the License.
15 15
16 This program is distributed in the hope that it will be useful, 16 This program is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of 17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 GNU General Public License for more details. 19 GNU General Public License for more details.
20 20
21 NO WARRANTY 21 NO WARRANTY
22 THE PROGRAM IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR 22 THE PROGRAM IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR
23 CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT 23 CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT
24 LIMITATION, ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT, 24 LIMITATION, ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT,
25 MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Each Recipient is 25 MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Each Recipient is
26 solely responsible for determining the appropriateness of using and 26 solely responsible for determining the appropriateness of using and
27 distributing the Program and assumes all risks associated with its 27 distributing the Program and assumes all risks associated with its
28 exercise of rights under this Agreement, including but not limited to 28 exercise of rights under this Agreement, including but not limited to
29 the risks and costs of program errors, damage to or loss of data, 29 the risks and costs of program errors, damage to or loss of data,
30 programs or equipment, and unavailability or interruption of operations. 30 programs or equipment, and unavailability or interruption of operations.
31 31
32 DISCLAIMER OF LIABILITY 32 DISCLAIMER OF LIABILITY
33 NEITHER RECIPIENT NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY 33 NEITHER RECIPIENT NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY
34 DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 34 DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
35 DAMAGES (INCLUDING WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND 35 DAMAGES (INCLUDING WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND
36 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR 36 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
37 TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE 37 TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
38 USE OR DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS GRANTED 38 USE OR DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS GRANTED
39 HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES 39 HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES
40 40
41 You should have received a copy of the GNU General Public License 41 You should have received a copy of the GNU General Public License
42 along with this program; if not, write to the Free Software 42 along with this program; if not, write to the Free Software
43 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 43 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
44 */ 44 */
45 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/ 45 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
46 46
47 #include <linux/module.h> 47 #include <linux/module.h>
48 #include <linux/kernel.h> 48 #include <linux/kernel.h>
49 #include <linux/slab.h> 49 #include <linux/slab.h>
50 #include <linux/init.h> 50 #include <linux/init.h>
51 #include <linux/errno.h> 51 #include <linux/errno.h>
52 #include <linux/kdev_t.h> 52 #include <linux/kdev_t.h>
53 #include <linux/blkdev.h> 53 #include <linux/blkdev.h>
54 #include <linux/delay.h> /* for mdelay */ 54 #include <linux/delay.h> /* for mdelay */
55 #include <linux/interrupt.h> /* needed for in_interrupt() proto */ 55 #include <linux/interrupt.h> /* needed for in_interrupt() proto */
56 #include <linux/reboot.h> /* notifier code */ 56 #include <linux/reboot.h> /* notifier code */
57 #include <linux/workqueue.h> 57 #include <linux/workqueue.h>
58 #include <linux/raid_class.h> 58 #include <linux/raid_class.h>
59 59
60 #include <scsi/scsi.h> 60 #include <scsi/scsi.h>
61 #include <scsi/scsi_cmnd.h> 61 #include <scsi/scsi_cmnd.h>
62 #include <scsi/scsi_device.h> 62 #include <scsi/scsi_device.h>
63 #include <scsi/scsi_host.h> 63 #include <scsi/scsi_host.h>
64 #include <scsi/scsi_tcq.h> 64 #include <scsi/scsi_tcq.h>
65 #include <scsi/scsi_transport.h> 65 #include <scsi/scsi_transport.h>
66 #include <scsi/scsi_transport_spi.h> 66 #include <scsi/scsi_transport_spi.h>
67 #include <scsi/scsi_dbg.h> 67 #include <scsi/scsi_dbg.h>
68 68
69 #include "mptbase.h" 69 #include "mptbase.h"
70 #include "mptscsih.h" 70 #include "mptscsih.h"
71 71
72 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/ 72 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
73 #define my_NAME "Fusion MPT SPI Host driver" 73 #define my_NAME "Fusion MPT SPI Host driver"
74 #define my_VERSION MPT_LINUX_VERSION_COMMON 74 #define my_VERSION MPT_LINUX_VERSION_COMMON
75 #define MYNAM "mptspi" 75 #define MYNAM "mptspi"
76 76
77 MODULE_AUTHOR(MODULEAUTHOR); 77 MODULE_AUTHOR(MODULEAUTHOR);
78 MODULE_DESCRIPTION(my_NAME); 78 MODULE_DESCRIPTION(my_NAME);
79 MODULE_LICENSE("GPL"); 79 MODULE_LICENSE("GPL");
80 MODULE_VERSION(my_VERSION); 80 MODULE_VERSION(my_VERSION);
81 81
82 /* Command line args */ 82 /* Command line args */
83 static int mpt_saf_te = MPTSCSIH_SAF_TE; 83 static int mpt_saf_te = MPTSCSIH_SAF_TE;
84 module_param(mpt_saf_te, int, 0); 84 module_param(mpt_saf_te, int, 0);
85 MODULE_PARM_DESC(mpt_saf_te, " Force enabling SEP Processor: enable=1 (default=MPTSCSIH_SAF_TE=0)"); 85 MODULE_PARM_DESC(mpt_saf_te, " Force enabling SEP Processor: enable=1 (default=MPTSCSIH_SAF_TE=0)");
86 86
87 static void mptspi_write_offset(struct scsi_target *, int); 87 static void mptspi_write_offset(struct scsi_target *, int);
88 static void mptspi_write_width(struct scsi_target *, int); 88 static void mptspi_write_width(struct scsi_target *, int);
89 static int mptspi_write_spi_device_pg1(struct scsi_target *, 89 static int mptspi_write_spi_device_pg1(struct scsi_target *,
90 struct _CONFIG_PAGE_SCSI_DEVICE_1 *); 90 struct _CONFIG_PAGE_SCSI_DEVICE_1 *);
91 91
92 static struct scsi_transport_template *mptspi_transport_template = NULL; 92 static struct scsi_transport_template *mptspi_transport_template = NULL;
93 93
94 static u8 mptspiDoneCtx = MPT_MAX_PROTOCOL_DRIVERS; 94 static u8 mptspiDoneCtx = MPT_MAX_PROTOCOL_DRIVERS;
95 static u8 mptspiTaskCtx = MPT_MAX_PROTOCOL_DRIVERS; 95 static u8 mptspiTaskCtx = MPT_MAX_PROTOCOL_DRIVERS;
96 static u8 mptspiInternalCtx = MPT_MAX_PROTOCOL_DRIVERS; /* Used only for internal commands */ 96 static u8 mptspiInternalCtx = MPT_MAX_PROTOCOL_DRIVERS; /* Used only for internal commands */
97 97
98 /** 98 /**
99 * mptspi_setTargetNegoParms - Update the target negotiation parameters 99 * mptspi_setTargetNegoParms - Update the target negotiation parameters
100 * @hd: Pointer to a SCSI Host Structure 100 * @hd: Pointer to a SCSI Host Structure
101 * @target: per target private data 101 * @target: per target private data
102 * @sdev: SCSI device 102 * @sdev: SCSI device
103 * 103 *
104 * Update the target negotiation parameters based on the the Inquiry 104 * Update the target negotiation parameters based on the the Inquiry
105 * data, adapter capabilities, and NVRAM settings. 105 * data, adapter capabilities, and NVRAM settings.
106 **/ 106 **/
107 static void 107 static void
108 mptspi_setTargetNegoParms(MPT_SCSI_HOST *hd, VirtTarget *target, 108 mptspi_setTargetNegoParms(MPT_SCSI_HOST *hd, VirtTarget *target,
109 struct scsi_device *sdev) 109 struct scsi_device *sdev)
110 { 110 {
111 MPT_ADAPTER *ioc = hd->ioc; 111 MPT_ADAPTER *ioc = hd->ioc;
112 SpiCfgData *pspi_data = &ioc->spi_data; 112 SpiCfgData *pspi_data = &ioc->spi_data;
113 int id = (int) target->id; 113 int id = (int) target->id;
114 int nvram; 114 int nvram;
115 u8 width = MPT_NARROW; 115 u8 width = MPT_NARROW;
116 u8 factor = MPT_ASYNC; 116 u8 factor = MPT_ASYNC;
117 u8 offset = 0; 117 u8 offset = 0;
118 u8 nfactor; 118 u8 nfactor;
119 u8 noQas = 1; 119 u8 noQas = 1;
120 120
121 target->negoFlags = pspi_data->noQas; 121 target->negoFlags = pspi_data->noQas;
122 122
123 if (sdev->scsi_level < SCSI_2) { 123 if (sdev->scsi_level < SCSI_2) {
124 width = 0; 124 width = 0;
125 factor = MPT_ULTRA2; 125 factor = MPT_ULTRA2;
126 offset = pspi_data->maxSyncOffset; 126 offset = pspi_data->maxSyncOffset;
127 target->tflags &= ~MPT_TARGET_FLAGS_Q_YES; 127 target->tflags &= ~MPT_TARGET_FLAGS_Q_YES;
128 } else { 128 } else {
129 if (scsi_device_wide(sdev)) 129 if (scsi_device_wide(sdev))
130 width = 1; 130 width = 1;
131 131
132 if (scsi_device_sync(sdev)) { 132 if (scsi_device_sync(sdev)) {
133 factor = pspi_data->minSyncFactor; 133 factor = pspi_data->minSyncFactor;
134 if (!scsi_device_dt(sdev)) 134 if (!scsi_device_dt(sdev))
135 factor = MPT_ULTRA2; 135 factor = MPT_ULTRA2;
136 else { 136 else {
137 if (!scsi_device_ius(sdev) && 137 if (!scsi_device_ius(sdev) &&
138 !scsi_device_qas(sdev)) 138 !scsi_device_qas(sdev))
139 factor = MPT_ULTRA160; 139 factor = MPT_ULTRA160;
140 else { 140 else {
141 factor = MPT_ULTRA320; 141 factor = MPT_ULTRA320;
142 if (scsi_device_qas(sdev)) { 142 if (scsi_device_qas(sdev)) {
143 ddvprintk(ioc, 143 ddvprintk(ioc,
144 printk(MYIOC_s_DEBUG_FMT "Enabling QAS due to " 144 printk(MYIOC_s_DEBUG_FMT "Enabling QAS due to "
145 "byte56=%02x on id=%d!\n", ioc->name, 145 "byte56=%02x on id=%d!\n", ioc->name,
146 scsi_device_qas(sdev), id)); 146 scsi_device_qas(sdev), id));
147 noQas = 0; 147 noQas = 0;
148 } 148 }
149 if (sdev->type == TYPE_TAPE && 149 if (sdev->type == TYPE_TAPE &&
150 scsi_device_ius(sdev)) 150 scsi_device_ius(sdev))
151 target->negoFlags |= MPT_TAPE_NEGO_IDP; 151 target->negoFlags |= MPT_TAPE_NEGO_IDP;
152 } 152 }
153 } 153 }
154 offset = pspi_data->maxSyncOffset; 154 offset = pspi_data->maxSyncOffset;
155 155
156 /* If RAID, never disable QAS 156 /* If RAID, never disable QAS
157 * else if non RAID, do not disable 157 * else if non RAID, do not disable
158 * QAS if bit 1 is set 158 * QAS if bit 1 is set
159 * bit 1 QAS support, non-raid only 159 * bit 1 QAS support, non-raid only
160 * bit 0 IU support 160 * bit 0 IU support
161 */ 161 */
162 if (target->raidVolume == 1) 162 if (target->raidVolume == 1)
163 noQas = 0; 163 noQas = 0;
164 } else { 164 } else {
165 factor = MPT_ASYNC; 165 factor = MPT_ASYNC;
166 offset = 0; 166 offset = 0;
167 } 167 }
168 } 168 }
169 169
170 if (!sdev->tagged_supported) 170 if (!sdev->tagged_supported)
171 target->tflags &= ~MPT_TARGET_FLAGS_Q_YES; 171 target->tflags &= ~MPT_TARGET_FLAGS_Q_YES;
172 172
173 /* Update tflags based on NVRAM settings. (SCSI only) 173 /* Update tflags based on NVRAM settings. (SCSI only)
174 */ 174 */
175 if (pspi_data->nvram && (pspi_data->nvram[id] != MPT_HOST_NVRAM_INVALID)) { 175 if (pspi_data->nvram && (pspi_data->nvram[id] != MPT_HOST_NVRAM_INVALID)) {
176 nvram = pspi_data->nvram[id]; 176 nvram = pspi_data->nvram[id];
177 nfactor = (nvram & MPT_NVRAM_SYNC_MASK) >> 8; 177 nfactor = (nvram & MPT_NVRAM_SYNC_MASK) >> 8;
178 178
179 if (width) 179 if (width)
180 width = nvram & MPT_NVRAM_WIDE_DISABLE ? 0 : 1; 180 width = nvram & MPT_NVRAM_WIDE_DISABLE ? 0 : 1;
181 181
182 if (offset > 0) { 182 if (offset > 0) {
183 /* Ensure factor is set to the 183 /* Ensure factor is set to the
184 * maximum of: adapter, nvram, inquiry 184 * maximum of: adapter, nvram, inquiry
185 */ 185 */
186 if (nfactor) { 186 if (nfactor) {
187 if (nfactor < pspi_data->minSyncFactor ) 187 if (nfactor < pspi_data->minSyncFactor )
188 nfactor = pspi_data->minSyncFactor; 188 nfactor = pspi_data->minSyncFactor;
189 189
190 factor = max(factor, nfactor); 190 factor = max(factor, nfactor);
191 if (factor == MPT_ASYNC) 191 if (factor == MPT_ASYNC)
192 offset = 0; 192 offset = 0;
193 } else { 193 } else {
194 offset = 0; 194 offset = 0;
195 factor = MPT_ASYNC; 195 factor = MPT_ASYNC;
196 } 196 }
197 } else { 197 } else {
198 factor = MPT_ASYNC; 198 factor = MPT_ASYNC;
199 } 199 }
200 } 200 }
201 201
202 /* Make sure data is consistent 202 /* Make sure data is consistent
203 */ 203 */
204 if ((!width) && (factor < MPT_ULTRA2)) 204 if ((!width) && (factor < MPT_ULTRA2))
205 factor = MPT_ULTRA2; 205 factor = MPT_ULTRA2;
206 206
207 /* Save the data to the target structure. 207 /* Save the data to the target structure.
208 */ 208 */
209 target->minSyncFactor = factor; 209 target->minSyncFactor = factor;
210 target->maxOffset = offset; 210 target->maxOffset = offset;
211 target->maxWidth = width; 211 target->maxWidth = width;
212 212
213 spi_min_period(scsi_target(sdev)) = factor; 213 spi_min_period(scsi_target(sdev)) = factor;
214 spi_max_offset(scsi_target(sdev)) = offset; 214 spi_max_offset(scsi_target(sdev)) = offset;
215 spi_max_width(scsi_target(sdev)) = width; 215 spi_max_width(scsi_target(sdev)) = width;
216 216
217 target->tflags |= MPT_TARGET_FLAGS_VALID_NEGO; 217 target->tflags |= MPT_TARGET_FLAGS_VALID_NEGO;
218 218
219 /* Disable unused features. 219 /* Disable unused features.
220 */ 220 */
221 if (!width) 221 if (!width)
222 target->negoFlags |= MPT_TARGET_NO_NEGO_WIDE; 222 target->negoFlags |= MPT_TARGET_NO_NEGO_WIDE;
223 223
224 if (!offset) 224 if (!offset)
225 target->negoFlags |= MPT_TARGET_NO_NEGO_SYNC; 225 target->negoFlags |= MPT_TARGET_NO_NEGO_SYNC;
226 226
227 if ( factor > MPT_ULTRA320 ) 227 if ( factor > MPT_ULTRA320 )
228 noQas = 0; 228 noQas = 0;
229 229
230 if (noQas && (pspi_data->noQas == 0)) { 230 if (noQas && (pspi_data->noQas == 0)) {
231 pspi_data->noQas |= MPT_TARGET_NO_NEGO_QAS; 231 pspi_data->noQas |= MPT_TARGET_NO_NEGO_QAS;
232 target->negoFlags |= MPT_TARGET_NO_NEGO_QAS; 232 target->negoFlags |= MPT_TARGET_NO_NEGO_QAS;
233 233
234 /* Disable QAS in a mixed configuration case 234 /* Disable QAS in a mixed configuration case
235 */ 235 */
236 236
237 ddvprintk(ioc, printk(MYIOC_s_DEBUG_FMT 237 ddvprintk(ioc, printk(MYIOC_s_DEBUG_FMT
238 "Disabling QAS due to noQas=%02x on id=%d!\n", ioc->name, noQas, id)); 238 "Disabling QAS due to noQas=%02x on id=%d!\n", ioc->name, noQas, id));
239 } 239 }
240 } 240 }
241 241
242 /** 242 /**
243 * mptspi_writeIOCPage4 - write IOC Page 4 243 * mptspi_writeIOCPage4 - write IOC Page 4
244 * @hd: Pointer to a SCSI Host Structure 244 * @hd: Pointer to a SCSI Host Structure
245 * @channel: channel number 245 * @channel: channel number
246 * @id: write IOC Page4 for this ID & Bus 246 * @id: write IOC Page4 for this ID & Bus
247 * 247 *
248 * Return: -EAGAIN if unable to obtain a Message Frame 248 * Return: -EAGAIN if unable to obtain a Message Frame
249 * or 0 if success. 249 * or 0 if success.
250 * 250 *
251 * Remark: We do not wait for a return, write pages sequentially. 251 * Remark: We do not wait for a return, write pages sequentially.
252 **/ 252 **/
253 static int 253 static int
254 mptspi_writeIOCPage4(MPT_SCSI_HOST *hd, u8 channel , u8 id) 254 mptspi_writeIOCPage4(MPT_SCSI_HOST *hd, u8 channel , u8 id)
255 { 255 {
256 MPT_ADAPTER *ioc = hd->ioc; 256 MPT_ADAPTER *ioc = hd->ioc;
257 Config_t *pReq; 257 Config_t *pReq;
258 IOCPage4_t *IOCPage4Ptr; 258 IOCPage4_t *IOCPage4Ptr;
259 MPT_FRAME_HDR *mf; 259 MPT_FRAME_HDR *mf;
260 dma_addr_t dataDma; 260 dma_addr_t dataDma;
261 u16 req_idx; 261 u16 req_idx;
262 u32 frameOffset; 262 u32 frameOffset;
263 u32 flagsLength; 263 u32 flagsLength;
264 int ii; 264 int ii;
265 265
266 /* Get a MF for this command. 266 /* Get a MF for this command.
267 */ 267 */
268 if ((mf = mpt_get_msg_frame(ioc->DoneCtx, ioc)) == NULL) { 268 if ((mf = mpt_get_msg_frame(ioc->DoneCtx, ioc)) == NULL) {
269 dfailprintk(ioc, printk(MYIOC_s_WARN_FMT 269 dfailprintk(ioc, printk(MYIOC_s_WARN_FMT
270 "writeIOCPage4 : no msg frames!\n",ioc->name)); 270 "writeIOCPage4 : no msg frames!\n",ioc->name));
271 return -EAGAIN; 271 return -EAGAIN;
272 } 272 }
273 273
274 /* Set the request and the data pointers. 274 /* Set the request and the data pointers.
275 * Place data at end of MF. 275 * Place data at end of MF.
276 */ 276 */
277 pReq = (Config_t *)mf; 277 pReq = (Config_t *)mf;
278 278
279 req_idx = le16_to_cpu(mf->u.frame.hwhdr.msgctxu.fld.req_idx); 279 req_idx = le16_to_cpu(mf->u.frame.hwhdr.msgctxu.fld.req_idx);
280 frameOffset = ioc->req_sz - sizeof(IOCPage4_t); 280 frameOffset = ioc->req_sz - sizeof(IOCPage4_t);
281 281
282 /* Complete the request frame (same for all requests). 282 /* Complete the request frame (same for all requests).
283 */ 283 */
284 pReq->Action = MPI_CONFIG_ACTION_PAGE_WRITE_CURRENT; 284 pReq->Action = MPI_CONFIG_ACTION_PAGE_WRITE_CURRENT;
285 pReq->Reserved = 0; 285 pReq->Reserved = 0;
286 pReq->ChainOffset = 0; 286 pReq->ChainOffset = 0;
287 pReq->Function = MPI_FUNCTION_CONFIG; 287 pReq->Function = MPI_FUNCTION_CONFIG;
288 pReq->ExtPageLength = 0; 288 pReq->ExtPageLength = 0;
289 pReq->ExtPageType = 0; 289 pReq->ExtPageType = 0;
290 pReq->MsgFlags = 0; 290 pReq->MsgFlags = 0;
291 for (ii=0; ii < 8; ii++) { 291 for (ii=0; ii < 8; ii++) {
292 pReq->Reserved2[ii] = 0; 292 pReq->Reserved2[ii] = 0;
293 } 293 }
294 294
295 IOCPage4Ptr = ioc->spi_data.pIocPg4; 295 IOCPage4Ptr = ioc->spi_data.pIocPg4;
296 dataDma = ioc->spi_data.IocPg4_dma; 296 dataDma = ioc->spi_data.IocPg4_dma;
297 ii = IOCPage4Ptr->ActiveSEP++; 297 ii = IOCPage4Ptr->ActiveSEP++;
298 IOCPage4Ptr->SEP[ii].SEPTargetID = id; 298 IOCPage4Ptr->SEP[ii].SEPTargetID = id;
299 IOCPage4Ptr->SEP[ii].SEPBus = channel; 299 IOCPage4Ptr->SEP[ii].SEPBus = channel;
300 pReq->Header = IOCPage4Ptr->Header; 300 pReq->Header = IOCPage4Ptr->Header;
301 pReq->PageAddress = cpu_to_le32(id | (channel << 8 )); 301 pReq->PageAddress = cpu_to_le32(id | (channel << 8 ));
302 302
303 /* Add a SGE to the config request. 303 /* Add a SGE to the config request.
304 */ 304 */
305 flagsLength = MPT_SGE_FLAGS_SSIMPLE_WRITE | 305 flagsLength = MPT_SGE_FLAGS_SSIMPLE_WRITE |
306 (IOCPage4Ptr->Header.PageLength + ii) * 4; 306 (IOCPage4Ptr->Header.PageLength + ii) * 4;
307 307
308 ioc->add_sge((char *)&pReq->PageBufferSGE, flagsLength, dataDma); 308 ioc->add_sge((char *)&pReq->PageBufferSGE, flagsLength, dataDma);
309 309
310 ddvprintk(ioc, printk(MYIOC_s_DEBUG_FMT 310 ddvprintk(ioc, printk(MYIOC_s_DEBUG_FMT
311 "writeIOCPage4: MaxSEP=%d ActiveSEP=%d id=%d bus=%d\n", 311 "writeIOCPage4: MaxSEP=%d ActiveSEP=%d id=%d bus=%d\n",
312 ioc->name, IOCPage4Ptr->MaxSEP, IOCPage4Ptr->ActiveSEP, id, channel)); 312 ioc->name, IOCPage4Ptr->MaxSEP, IOCPage4Ptr->ActiveSEP, id, channel));
313 313
314 mpt_put_msg_frame(ioc->DoneCtx, ioc, mf); 314 mpt_put_msg_frame(ioc->DoneCtx, ioc, mf);
315 315
316 return 0; 316 return 0;
317 } 317 }
318 318
319 /** 319 /**
320 * mptspi_initTarget - Target, LUN alloc/free functionality. 320 * mptspi_initTarget - Target, LUN alloc/free functionality.
321 * @hd: Pointer to MPT_SCSI_HOST structure 321 * @hd: Pointer to MPT_SCSI_HOST structure
322 * @vtarget: per target private data 322 * @vtarget: per target private data
323 * @sdev: SCSI device 323 * @sdev: SCSI device
324 * 324 *
325 * NOTE: It's only SAFE to call this routine if data points to 325 * NOTE: It's only SAFE to call this routine if data points to
326 * sane & valid STANDARD INQUIRY data! 326 * sane & valid STANDARD INQUIRY data!
327 * 327 *
328 * Allocate and initialize memory for this target. 328 * Allocate and initialize memory for this target.
329 * Save inquiry data. 329 * Save inquiry data.
330 * 330 *
331 **/ 331 **/
332 static void 332 static void
333 mptspi_initTarget(MPT_SCSI_HOST *hd, VirtTarget *vtarget, 333 mptspi_initTarget(MPT_SCSI_HOST *hd, VirtTarget *vtarget,
334 struct scsi_device *sdev) 334 struct scsi_device *sdev)
335 { 335 {
336 336
337 /* Is LUN supported? If so, upper 2 bits will be 0 337 /* Is LUN supported? If so, upper 2 bits will be 0
338 * in first byte of inquiry data. 338 * in first byte of inquiry data.
339 */ 339 */
340 if (sdev->inq_periph_qual != 0) 340 if (sdev->inq_periph_qual != 0)
341 return; 341 return;
342 342
343 if (vtarget == NULL) 343 if (vtarget == NULL)
344 return; 344 return;
345 345
346 vtarget->type = sdev->type; 346 vtarget->type = sdev->type;
347 347
348 if ((sdev->type == TYPE_PROCESSOR) && (hd->ioc->spi_data.Saf_Te)) { 348 if ((sdev->type == TYPE_PROCESSOR) && (hd->ioc->spi_data.Saf_Te)) {
349 /* Treat all Processors as SAF-TE if 349 /* Treat all Processors as SAF-TE if
350 * command line option is set */ 350 * command line option is set */
351 vtarget->tflags |= MPT_TARGET_FLAGS_SAF_TE_ISSUED; 351 vtarget->tflags |= MPT_TARGET_FLAGS_SAF_TE_ISSUED;
352 mptspi_writeIOCPage4(hd, vtarget->channel, vtarget->id); 352 mptspi_writeIOCPage4(hd, vtarget->channel, vtarget->id);
353 }else if ((sdev->type == TYPE_PROCESSOR) && 353 }else if ((sdev->type == TYPE_PROCESSOR) &&
354 !(vtarget->tflags & MPT_TARGET_FLAGS_SAF_TE_ISSUED )) { 354 !(vtarget->tflags & MPT_TARGET_FLAGS_SAF_TE_ISSUED )) {
355 if (sdev->inquiry_len > 49 ) { 355 if (sdev->inquiry_len > 49 ) {
356 if (sdev->inquiry[44] == 'S' && 356 if (sdev->inquiry[44] == 'S' &&
357 sdev->inquiry[45] == 'A' && 357 sdev->inquiry[45] == 'A' &&
358 sdev->inquiry[46] == 'F' && 358 sdev->inquiry[46] == 'F' &&
359 sdev->inquiry[47] == '-' && 359 sdev->inquiry[47] == '-' &&
360 sdev->inquiry[48] == 'T' && 360 sdev->inquiry[48] == 'T' &&
361 sdev->inquiry[49] == 'E' ) { 361 sdev->inquiry[49] == 'E' ) {
362 vtarget->tflags |= MPT_TARGET_FLAGS_SAF_TE_ISSUED; 362 vtarget->tflags |= MPT_TARGET_FLAGS_SAF_TE_ISSUED;
363 mptspi_writeIOCPage4(hd, vtarget->channel, vtarget->id); 363 mptspi_writeIOCPage4(hd, vtarget->channel, vtarget->id);
364 } 364 }
365 } 365 }
366 } 366 }
367 mptspi_setTargetNegoParms(hd, vtarget, sdev); 367 mptspi_setTargetNegoParms(hd, vtarget, sdev);
368 } 368 }
369 369
370 /** 370 /**
371 * mptspi_is_raid - Determines whether target is belonging to volume 371 * mptspi_is_raid - Determines whether target is belonging to volume
372 * @hd: Pointer to a SCSI HOST structure 372 * @hd: Pointer to a SCSI HOST structure
373 * @id: target device id 373 * @id: target device id
374 * 374 *
375 * Return: 375 * Return:
376 * non-zero = true 376 * non-zero = true
377 * zero = false 377 * zero = false
378 * 378 *
379 */ 379 */
380 static int 380 static int
381 mptspi_is_raid(struct _MPT_SCSI_HOST *hd, u32 id) 381 mptspi_is_raid(struct _MPT_SCSI_HOST *hd, u32 id)
382 { 382 {
383 int i, rc = 0; 383 int i, rc = 0;
384 MPT_ADAPTER *ioc = hd->ioc; 384 MPT_ADAPTER *ioc = hd->ioc;
385 385
386 if (!ioc->raid_data.pIocPg2) 386 if (!ioc->raid_data.pIocPg2)
387 goto out; 387 goto out;
388 388
389 if (!ioc->raid_data.pIocPg2->NumActiveVolumes) 389 if (!ioc->raid_data.pIocPg2->NumActiveVolumes)
390 goto out; 390 goto out;
391 for (i=0; i < ioc->raid_data.pIocPg2->NumActiveVolumes; i++) { 391 for (i=0; i < ioc->raid_data.pIocPg2->NumActiveVolumes; i++) {
392 if (ioc->raid_data.pIocPg2->RaidVolume[i].VolumeID == id) { 392 if (ioc->raid_data.pIocPg2->RaidVolume[i].VolumeID == id) {
393 rc = 1; 393 rc = 1;
394 goto out; 394 goto out;
395 } 395 }
396 } 396 }
397 397
398 out: 398 out:
399 return rc; 399 return rc;
400 } 400 }
401 401
402 static int mptspi_target_alloc(struct scsi_target *starget) 402 static int mptspi_target_alloc(struct scsi_target *starget)
403 { 403 {
404 struct Scsi_Host *shost = dev_to_shost(&starget->dev); 404 struct Scsi_Host *shost = dev_to_shost(&starget->dev);
405 struct _MPT_SCSI_HOST *hd = shost_priv(shost); 405 struct _MPT_SCSI_HOST *hd = shost_priv(shost);
406 VirtTarget *vtarget; 406 VirtTarget *vtarget;
407 MPT_ADAPTER *ioc; 407 MPT_ADAPTER *ioc;
408 408
409 if (hd == NULL) 409 if (hd == NULL)
410 return -ENODEV; 410 return -ENODEV;
411 411
412 ioc = hd->ioc; 412 ioc = hd->ioc;
413 vtarget = kzalloc(sizeof(VirtTarget), GFP_KERNEL); 413 vtarget = kzalloc(sizeof(VirtTarget), GFP_KERNEL);
414 if (!vtarget) 414 if (!vtarget)
415 return -ENOMEM; 415 return -ENOMEM;
416 416
417 vtarget->ioc_id = ioc->id; 417 vtarget->ioc_id = ioc->id;
418 vtarget->tflags = MPT_TARGET_FLAGS_Q_YES; 418 vtarget->tflags = MPT_TARGET_FLAGS_Q_YES;
419 vtarget->id = (u8)starget->id; 419 vtarget->id = (u8)starget->id;
420 vtarget->channel = (u8)starget->channel; 420 vtarget->channel = (u8)starget->channel;
421 vtarget->starget = starget; 421 vtarget->starget = starget;
422 starget->hostdata = vtarget; 422 starget->hostdata = vtarget;
423 423
424 if (starget->channel == 1) { 424 if (starget->channel == 1) {
425 if (mptscsih_is_phys_disk(ioc, 0, starget->id) == 0) 425 if (mptscsih_is_phys_disk(ioc, 0, starget->id) == 0)
426 return 0; 426 return 0;
427 vtarget->tflags |= MPT_TARGET_FLAGS_RAID_COMPONENT; 427 vtarget->tflags |= MPT_TARGET_FLAGS_RAID_COMPONENT;
428 /* The real channel for this device is zero */ 428 /* The real channel for this device is zero */
429 vtarget->channel = 0; 429 vtarget->channel = 0;
430 /* The actual physdisknum (for RAID passthrough) */ 430 /* The actual physdisknum (for RAID passthrough) */
431 vtarget->id = mptscsih_raid_id_to_num(ioc, 0, 431 vtarget->id = mptscsih_raid_id_to_num(ioc, 0,
432 starget->id); 432 starget->id);
433 } 433 }
434 434
435 if (starget->channel == 0 && 435 if (starget->channel == 0 &&
436 mptspi_is_raid(hd, starget->id)) { 436 mptspi_is_raid(hd, starget->id)) {
437 vtarget->raidVolume = 1; 437 vtarget->raidVolume = 1;
438 ddvprintk(ioc, printk(MYIOC_s_DEBUG_FMT 438 ddvprintk(ioc, printk(MYIOC_s_DEBUG_FMT
439 "RAID Volume @ channel=%d id=%d\n", ioc->name, starget->channel, 439 "RAID Volume @ channel=%d id=%d\n", ioc->name, starget->channel,
440 starget->id)); 440 starget->id));
441 } 441 }
442 442
443 if (ioc->spi_data.nvram && 443 if (ioc->spi_data.nvram &&
444 ioc->spi_data.nvram[starget->id] != MPT_HOST_NVRAM_INVALID) { 444 ioc->spi_data.nvram[starget->id] != MPT_HOST_NVRAM_INVALID) {
445 u32 nvram = ioc->spi_data.nvram[starget->id]; 445 u32 nvram = ioc->spi_data.nvram[starget->id];
446 spi_min_period(starget) = (nvram & MPT_NVRAM_SYNC_MASK) >> MPT_NVRAM_SYNC_SHIFT; 446 spi_min_period(starget) = (nvram & MPT_NVRAM_SYNC_MASK) >> MPT_NVRAM_SYNC_SHIFT;
447 spi_max_width(starget) = nvram & MPT_NVRAM_WIDE_DISABLE ? 0 : 1; 447 spi_max_width(starget) = nvram & MPT_NVRAM_WIDE_DISABLE ? 0 : 1;
448 } else { 448 } else {
449 spi_min_period(starget) = ioc->spi_data.minSyncFactor; 449 spi_min_period(starget) = ioc->spi_data.minSyncFactor;
450 spi_max_width(starget) = ioc->spi_data.maxBusWidth; 450 spi_max_width(starget) = ioc->spi_data.maxBusWidth;
451 } 451 }
452 spi_max_offset(starget) = ioc->spi_data.maxSyncOffset; 452 spi_max_offset(starget) = ioc->spi_data.maxSyncOffset;
453 453
454 spi_offset(starget) = 0; 454 spi_offset(starget) = 0;
455 spi_period(starget) = 0xFF; 455 spi_period(starget) = 0xFF;
456 mptspi_write_width(starget, 0); 456 mptspi_write_width(starget, 0);
457 457
458 return 0; 458 return 0;
459 } 459 }
460 460
461 static void 461 static void
462 mptspi_target_destroy(struct scsi_target *starget) 462 mptspi_target_destroy(struct scsi_target *starget)
463 { 463 {
464 if (starget->hostdata) 464 if (starget->hostdata)
465 kfree(starget->hostdata); 465 kfree(starget->hostdata);
466 starget->hostdata = NULL; 466 starget->hostdata = NULL;
467 } 467 }
468 468
469 /** 469 /**
470 * mptspi_print_write_nego - negotiation parameters debug info that is being sent 470 * mptspi_print_write_nego - negotiation parameters debug info that is being sent
471 * @hd: Pointer to a SCSI HOST structure 471 * @hd: Pointer to a SCSI HOST structure
472 * @starget: SCSI target 472 * @starget: SCSI target
473 * @ii: negotiation parameters 473 * @ii: negotiation parameters
474 * 474 *
475 */ 475 */
476 static void 476 static void
477 mptspi_print_write_nego(struct _MPT_SCSI_HOST *hd, struct scsi_target *starget, u32 ii) 477 mptspi_print_write_nego(struct _MPT_SCSI_HOST *hd, struct scsi_target *starget, u32 ii)
478 { 478 {
479 ddvprintk(hd->ioc, printk(MYIOC_s_DEBUG_FMT "id=%d Requested = 0x%08x" 479 ddvprintk(hd->ioc, printk(MYIOC_s_DEBUG_FMT "id=%d Requested = 0x%08x"
480 " ( %s factor = 0x%02x @ offset = 0x%02x %s%s%s%s%s%s%s%s)\n", 480 " ( %s factor = 0x%02x @ offset = 0x%02x %s%s%s%s%s%s%s%s)\n",
481 hd->ioc->name, starget->id, ii, 481 hd->ioc->name, starget->id, ii,
482 ii & MPI_SCSIDEVPAGE0_NP_WIDE ? "Wide ": "", 482 ii & MPI_SCSIDEVPAGE0_NP_WIDE ? "Wide ": "",
483 ((ii >> 8) & 0xFF), ((ii >> 16) & 0xFF), 483 ((ii >> 8) & 0xFF), ((ii >> 16) & 0xFF),
484 ii & MPI_SCSIDEVPAGE0_NP_IU ? "IU ": "", 484 ii & MPI_SCSIDEVPAGE0_NP_IU ? "IU ": "",
485 ii & MPI_SCSIDEVPAGE0_NP_DT ? "DT ": "", 485 ii & MPI_SCSIDEVPAGE0_NP_DT ? "DT ": "",
486 ii & MPI_SCSIDEVPAGE0_NP_QAS ? "QAS ": "", 486 ii & MPI_SCSIDEVPAGE0_NP_QAS ? "QAS ": "",
487 ii & MPI_SCSIDEVPAGE0_NP_HOLD_MCS ? "HOLDMCS ": "", 487 ii & MPI_SCSIDEVPAGE0_NP_HOLD_MCS ? "HOLDMCS ": "",
488 ii & MPI_SCSIDEVPAGE0_NP_WR_FLOW ? "WRFLOW ": "", 488 ii & MPI_SCSIDEVPAGE0_NP_WR_FLOW ? "WRFLOW ": "",
489 ii & MPI_SCSIDEVPAGE0_NP_RD_STRM ? "RDSTRM ": "", 489 ii & MPI_SCSIDEVPAGE0_NP_RD_STRM ? "RDSTRM ": "",
490 ii & MPI_SCSIDEVPAGE0_NP_RTI ? "RTI ": "", 490 ii & MPI_SCSIDEVPAGE0_NP_RTI ? "RTI ": "",
491 ii & MPI_SCSIDEVPAGE0_NP_PCOMP_EN ? "PCOMP ": "")); 491 ii & MPI_SCSIDEVPAGE0_NP_PCOMP_EN ? "PCOMP ": ""));
492 } 492 }
493 493
494 /** 494 /**
495 * mptspi_print_read_nego - negotiation parameters debug info that is being read 495 * mptspi_print_read_nego - negotiation parameters debug info that is being read
496 * @hd: Pointer to a SCSI HOST structure 496 * @hd: Pointer to a SCSI HOST structure
497 * @starget: SCSI target 497 * @starget: SCSI target
498 * @ii: negotiation parameters 498 * @ii: negotiation parameters
499 * 499 *
500 */ 500 */
501 static void 501 static void
502 mptspi_print_read_nego(struct _MPT_SCSI_HOST *hd, struct scsi_target *starget, u32 ii) 502 mptspi_print_read_nego(struct _MPT_SCSI_HOST *hd, struct scsi_target *starget, u32 ii)
503 { 503 {
504 ddvprintk(hd->ioc, printk(MYIOC_s_DEBUG_FMT "id=%d Read = 0x%08x" 504 ddvprintk(hd->ioc, printk(MYIOC_s_DEBUG_FMT "id=%d Read = 0x%08x"
505 " ( %s factor = 0x%02x @ offset = 0x%02x %s%s%s%s%s%s%s%s)\n", 505 " ( %s factor = 0x%02x @ offset = 0x%02x %s%s%s%s%s%s%s%s)\n",
506 hd->ioc->name, starget->id, ii, 506 hd->ioc->name, starget->id, ii,
507 ii & MPI_SCSIDEVPAGE0_NP_WIDE ? "Wide ": "", 507 ii & MPI_SCSIDEVPAGE0_NP_WIDE ? "Wide ": "",
508 ((ii >> 8) & 0xFF), ((ii >> 16) & 0xFF), 508 ((ii >> 8) & 0xFF), ((ii >> 16) & 0xFF),
509 ii & MPI_SCSIDEVPAGE0_NP_IU ? "IU ": "", 509 ii & MPI_SCSIDEVPAGE0_NP_IU ? "IU ": "",
510 ii & MPI_SCSIDEVPAGE0_NP_DT ? "DT ": "", 510 ii & MPI_SCSIDEVPAGE0_NP_DT ? "DT ": "",
511 ii & MPI_SCSIDEVPAGE0_NP_QAS ? "QAS ": "", 511 ii & MPI_SCSIDEVPAGE0_NP_QAS ? "QAS ": "",
512 ii & MPI_SCSIDEVPAGE0_NP_HOLD_MCS ? "HOLDMCS ": "", 512 ii & MPI_SCSIDEVPAGE0_NP_HOLD_MCS ? "HOLDMCS ": "",
513 ii & MPI_SCSIDEVPAGE0_NP_WR_FLOW ? "WRFLOW ": "", 513 ii & MPI_SCSIDEVPAGE0_NP_WR_FLOW ? "WRFLOW ": "",
514 ii & MPI_SCSIDEVPAGE0_NP_RD_STRM ? "RDSTRM ": "", 514 ii & MPI_SCSIDEVPAGE0_NP_RD_STRM ? "RDSTRM ": "",
515 ii & MPI_SCSIDEVPAGE0_NP_RTI ? "RTI ": "", 515 ii & MPI_SCSIDEVPAGE0_NP_RTI ? "RTI ": "",
516 ii & MPI_SCSIDEVPAGE0_NP_PCOMP_EN ? "PCOMP ": "")); 516 ii & MPI_SCSIDEVPAGE0_NP_PCOMP_EN ? "PCOMP ": ""));
517 } 517 }
518 518
519 static int mptspi_read_spi_device_pg0(struct scsi_target *starget, 519 static int mptspi_read_spi_device_pg0(struct scsi_target *starget,
520 struct _CONFIG_PAGE_SCSI_DEVICE_0 *pass_pg0) 520 struct _CONFIG_PAGE_SCSI_DEVICE_0 *pass_pg0)
521 { 521 {
522 struct Scsi_Host *shost = dev_to_shost(&starget->dev); 522 struct Scsi_Host *shost = dev_to_shost(&starget->dev);
523 struct _MPT_SCSI_HOST *hd = shost_priv(shost); 523 struct _MPT_SCSI_HOST *hd = shost_priv(shost);
524 struct _MPT_ADAPTER *ioc = hd->ioc; 524 struct _MPT_ADAPTER *ioc = hd->ioc;
525 struct _CONFIG_PAGE_SCSI_DEVICE_0 *spi_dev_pg0; 525 struct _CONFIG_PAGE_SCSI_DEVICE_0 *spi_dev_pg0;
526 dma_addr_t spi_dev_pg0_dma; 526 dma_addr_t spi_dev_pg0_dma;
527 int size; 527 int size;
528 struct _x_config_parms cfg; 528 struct _x_config_parms cfg;
529 struct _CONFIG_PAGE_HEADER hdr; 529 struct _CONFIG_PAGE_HEADER hdr;
530 int err = -EBUSY; 530 int err = -EBUSY;
531 531
532 /* No SPI parameters for RAID devices */ 532 /* No SPI parameters for RAID devices */
533 if (starget->channel == 0 && 533 if (starget->channel == 0 &&
534 mptspi_is_raid(hd, starget->id)) 534 mptspi_is_raid(hd, starget->id))
535 return -1; 535 return -1;
536 536
537 size = ioc->spi_data.sdp0length * 4; 537 size = ioc->spi_data.sdp0length * 4;
538 /* 538 /*
539 if (ioc->spi_data.sdp0length & 1) 539 if (ioc->spi_data.sdp0length & 1)
540 size += size + 4; 540 size += size + 4;
541 size += 2048; 541 size += 2048;
542 */ 542 */
543 543
544 spi_dev_pg0 = dma_alloc_coherent(&ioc->pcidev->dev, size, &spi_dev_pg0_dma, GFP_KERNEL); 544 spi_dev_pg0 = dma_alloc_coherent(&ioc->pcidev->dev, size, &spi_dev_pg0_dma, GFP_KERNEL);
545 if (spi_dev_pg0 == NULL) { 545 if (spi_dev_pg0 == NULL) {
546 starget_printk(KERN_ERR, starget, MYIOC_s_FMT 546 starget_printk(KERN_ERR, starget, MYIOC_s_FMT
547 "dma_alloc_coherent for parameters failed\n", ioc->name); 547 "dma_alloc_coherent for parameters failed\n", ioc->name);
548 return -EINVAL; 548 return -EINVAL;
549 } 549 }
550 550
551 memset(&hdr, 0, sizeof(hdr)); 551 memset(&hdr, 0, sizeof(hdr));
552 552
553 hdr.PageVersion = ioc->spi_data.sdp0version; 553 hdr.PageVersion = ioc->spi_data.sdp0version;
554 hdr.PageLength = ioc->spi_data.sdp0length; 554 hdr.PageLength = ioc->spi_data.sdp0length;
555 hdr.PageNumber = 0; 555 hdr.PageNumber = 0;
556 hdr.PageType = MPI_CONFIG_PAGETYPE_SCSI_DEVICE; 556 hdr.PageType = MPI_CONFIG_PAGETYPE_SCSI_DEVICE;
557 557
558 memset(&cfg, 0, sizeof(cfg)); 558 memset(&cfg, 0, sizeof(cfg));
559 559
560 cfg.cfghdr.hdr = &hdr; 560 cfg.cfghdr.hdr = &hdr;
561 cfg.physAddr = spi_dev_pg0_dma; 561 cfg.physAddr = spi_dev_pg0_dma;
562 cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT; 562 cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
563 cfg.dir = 0; 563 cfg.dir = 0;
564 cfg.pageAddr = starget->id; 564 cfg.pageAddr = starget->id;
565 cfg.timeout = 60; 565 cfg.timeout = 60;
566 566
567 if (mpt_config(ioc, &cfg)) { 567 if (mpt_config(ioc, &cfg)) {
568 starget_printk(KERN_ERR, starget, MYIOC_s_FMT "mpt_config failed\n", ioc->name); 568 starget_printk(KERN_ERR, starget, MYIOC_s_FMT "mpt_config failed\n", ioc->name);
569 goto out_free; 569 goto out_free;
570 } 570 }
571 err = 0; 571 err = 0;
572 memcpy(pass_pg0, spi_dev_pg0, size); 572 memcpy(pass_pg0, spi_dev_pg0, size);
573 573
574 mptspi_print_read_nego(hd, starget, le32_to_cpu(spi_dev_pg0->NegotiatedParameters)); 574 mptspi_print_read_nego(hd, starget, le32_to_cpu(spi_dev_pg0->NegotiatedParameters));
575 575
576 out_free: 576 out_free:
577 dma_free_coherent(&ioc->pcidev->dev, size, spi_dev_pg0, spi_dev_pg0_dma); 577 dma_free_coherent(&ioc->pcidev->dev, size, spi_dev_pg0, spi_dev_pg0_dma);
578 return err; 578 return err;
579 } 579 }
580 580
581 static u32 mptspi_getRP(struct scsi_target *starget) 581 static u32 mptspi_getRP(struct scsi_target *starget)
582 { 582 {
583 u32 nego = 0; 583 u32 nego = 0;
584 584
585 nego |= spi_iu(starget) ? MPI_SCSIDEVPAGE1_RP_IU : 0; 585 nego |= spi_iu(starget) ? MPI_SCSIDEVPAGE1_RP_IU : 0;
586 nego |= spi_dt(starget) ? MPI_SCSIDEVPAGE1_RP_DT : 0; 586 nego |= spi_dt(starget) ? MPI_SCSIDEVPAGE1_RP_DT : 0;
587 nego |= spi_qas(starget) ? MPI_SCSIDEVPAGE1_RP_QAS : 0; 587 nego |= spi_qas(starget) ? MPI_SCSIDEVPAGE1_RP_QAS : 0;
588 nego |= spi_hold_mcs(starget) ? MPI_SCSIDEVPAGE1_RP_HOLD_MCS : 0; 588 nego |= spi_hold_mcs(starget) ? MPI_SCSIDEVPAGE1_RP_HOLD_MCS : 0;
589 nego |= spi_wr_flow(starget) ? MPI_SCSIDEVPAGE1_RP_WR_FLOW : 0; 589 nego |= spi_wr_flow(starget) ? MPI_SCSIDEVPAGE1_RP_WR_FLOW : 0;
590 nego |= spi_rd_strm(starget) ? MPI_SCSIDEVPAGE1_RP_RD_STRM : 0; 590 nego |= spi_rd_strm(starget) ? MPI_SCSIDEVPAGE1_RP_RD_STRM : 0;
591 nego |= spi_rti(starget) ? MPI_SCSIDEVPAGE1_RP_RTI : 0; 591 nego |= spi_rti(starget) ? MPI_SCSIDEVPAGE1_RP_RTI : 0;
592 nego |= spi_pcomp_en(starget) ? MPI_SCSIDEVPAGE1_RP_PCOMP_EN : 0; 592 nego |= spi_pcomp_en(starget) ? MPI_SCSIDEVPAGE1_RP_PCOMP_EN : 0;
593 593
594 nego |= (spi_period(starget) << MPI_SCSIDEVPAGE1_RP_SHIFT_MIN_SYNC_PERIOD) & MPI_SCSIDEVPAGE1_RP_MIN_SYNC_PERIOD_MASK; 594 nego |= (spi_period(starget) << MPI_SCSIDEVPAGE1_RP_SHIFT_MIN_SYNC_PERIOD) & MPI_SCSIDEVPAGE1_RP_MIN_SYNC_PERIOD_MASK;
595 nego |= (spi_offset(starget) << MPI_SCSIDEVPAGE1_RP_SHIFT_MAX_SYNC_OFFSET) & MPI_SCSIDEVPAGE1_RP_MAX_SYNC_OFFSET_MASK; 595 nego |= (spi_offset(starget) << MPI_SCSIDEVPAGE1_RP_SHIFT_MAX_SYNC_OFFSET) & MPI_SCSIDEVPAGE1_RP_MAX_SYNC_OFFSET_MASK;
596 nego |= spi_width(starget) ? MPI_SCSIDEVPAGE1_RP_WIDE : 0; 596 nego |= spi_width(starget) ? MPI_SCSIDEVPAGE1_RP_WIDE : 0;
597 597
598 return nego; 598 return nego;
599 } 599 }
600 600
601 static void mptspi_read_parameters(struct scsi_target *starget) 601 static void mptspi_read_parameters(struct scsi_target *starget)
602 { 602 {
603 int nego; 603 int nego;
604 struct _CONFIG_PAGE_SCSI_DEVICE_0 spi_dev_pg0; 604 struct _CONFIG_PAGE_SCSI_DEVICE_0 spi_dev_pg0;
605 605
606 mptspi_read_spi_device_pg0(starget, &spi_dev_pg0); 606 mptspi_read_spi_device_pg0(starget, &spi_dev_pg0);
607 607
608 nego = le32_to_cpu(spi_dev_pg0.NegotiatedParameters); 608 nego = le32_to_cpu(spi_dev_pg0.NegotiatedParameters);
609 609
610 spi_iu(starget) = (nego & MPI_SCSIDEVPAGE0_NP_IU) ? 1 : 0; 610 spi_iu(starget) = (nego & MPI_SCSIDEVPAGE0_NP_IU) ? 1 : 0;
611 spi_dt(starget) = (nego & MPI_SCSIDEVPAGE0_NP_DT) ? 1 : 0; 611 spi_dt(starget) = (nego & MPI_SCSIDEVPAGE0_NP_DT) ? 1 : 0;
612 spi_qas(starget) = (nego & MPI_SCSIDEVPAGE0_NP_QAS) ? 1 : 0; 612 spi_qas(starget) = (nego & MPI_SCSIDEVPAGE0_NP_QAS) ? 1 : 0;
613 spi_wr_flow(starget) = (nego & MPI_SCSIDEVPAGE0_NP_WR_FLOW) ? 1 : 0; 613 spi_wr_flow(starget) = (nego & MPI_SCSIDEVPAGE0_NP_WR_FLOW) ? 1 : 0;
614 spi_rd_strm(starget) = (nego & MPI_SCSIDEVPAGE0_NP_RD_STRM) ? 1 : 0; 614 spi_rd_strm(starget) = (nego & MPI_SCSIDEVPAGE0_NP_RD_STRM) ? 1 : 0;
615 spi_rti(starget) = (nego & MPI_SCSIDEVPAGE0_NP_RTI) ? 1 : 0; 615 spi_rti(starget) = (nego & MPI_SCSIDEVPAGE0_NP_RTI) ? 1 : 0;
616 spi_pcomp_en(starget) = (nego & MPI_SCSIDEVPAGE0_NP_PCOMP_EN) ? 1 : 0; 616 spi_pcomp_en(starget) = (nego & MPI_SCSIDEVPAGE0_NP_PCOMP_EN) ? 1 : 0;
617 spi_hold_mcs(starget) = (nego & MPI_SCSIDEVPAGE0_NP_HOLD_MCS) ? 1 : 0; 617 spi_hold_mcs(starget) = (nego & MPI_SCSIDEVPAGE0_NP_HOLD_MCS) ? 1 : 0;
618 spi_period(starget) = (nego & MPI_SCSIDEVPAGE0_NP_NEG_SYNC_PERIOD_MASK) >> MPI_SCSIDEVPAGE0_NP_SHIFT_SYNC_PERIOD; 618 spi_period(starget) = (nego & MPI_SCSIDEVPAGE0_NP_NEG_SYNC_PERIOD_MASK) >> MPI_SCSIDEVPAGE0_NP_SHIFT_SYNC_PERIOD;
619 spi_offset(starget) = (nego & MPI_SCSIDEVPAGE0_NP_NEG_SYNC_OFFSET_MASK) >> MPI_SCSIDEVPAGE0_NP_SHIFT_SYNC_OFFSET; 619 spi_offset(starget) = (nego & MPI_SCSIDEVPAGE0_NP_NEG_SYNC_OFFSET_MASK) >> MPI_SCSIDEVPAGE0_NP_SHIFT_SYNC_OFFSET;
620 spi_width(starget) = (nego & MPI_SCSIDEVPAGE0_NP_WIDE) ? 1 : 0; 620 spi_width(starget) = (nego & MPI_SCSIDEVPAGE0_NP_WIDE) ? 1 : 0;
621 } 621 }
622 622
623 int 623 int
624 mptscsih_quiesce_raid(MPT_SCSI_HOST *hd, int quiesce, u8 channel, u8 id) 624 mptscsih_quiesce_raid(MPT_SCSI_HOST *hd, int quiesce, u8 channel, u8 id)
625 { 625 {
626 MPT_ADAPTER *ioc = hd->ioc; 626 MPT_ADAPTER *ioc = hd->ioc;
627 MpiRaidActionRequest_t *pReq; 627 MpiRaidActionRequest_t *pReq;
628 MPT_FRAME_HDR *mf; 628 MPT_FRAME_HDR *mf;
629 int ret; 629 int ret;
630 unsigned long timeleft; 630 unsigned long timeleft;
631 631
632 mutex_lock(&ioc->internal_cmds.mutex); 632 mutex_lock(&ioc->internal_cmds.mutex);
633 633
634 /* Get and Populate a free Frame 634 /* Get and Populate a free Frame
635 */ 635 */
636 if ((mf = mpt_get_msg_frame(ioc->InternalCtx, ioc)) == NULL) { 636 if ((mf = mpt_get_msg_frame(ioc->InternalCtx, ioc)) == NULL) {
637 dfailprintk(hd->ioc, printk(MYIOC_s_WARN_FMT 637 dfailprintk(hd->ioc, printk(MYIOC_s_WARN_FMT
638 "%s: no msg frames!\n", ioc->name, __func__)); 638 "%s: no msg frames!\n", ioc->name, __func__));
639 ret = -EAGAIN; 639 ret = -EAGAIN;
640 goto out; 640 goto out;
641 } 641 }
642 pReq = (MpiRaidActionRequest_t *)mf; 642 pReq = (MpiRaidActionRequest_t *)mf;
643 if (quiesce) 643 if (quiesce)
644 pReq->Action = MPI_RAID_ACTION_QUIESCE_PHYS_IO; 644 pReq->Action = MPI_RAID_ACTION_QUIESCE_PHYS_IO;
645 else 645 else
646 pReq->Action = MPI_RAID_ACTION_ENABLE_PHYS_IO; 646 pReq->Action = MPI_RAID_ACTION_ENABLE_PHYS_IO;
647 pReq->Reserved1 = 0; 647 pReq->Reserved1 = 0;
648 pReq->ChainOffset = 0; 648 pReq->ChainOffset = 0;
649 pReq->Function = MPI_FUNCTION_RAID_ACTION; 649 pReq->Function = MPI_FUNCTION_RAID_ACTION;
650 pReq->VolumeID = id; 650 pReq->VolumeID = id;
651 pReq->VolumeBus = channel; 651 pReq->VolumeBus = channel;
652 pReq->PhysDiskNum = 0; 652 pReq->PhysDiskNum = 0;
653 pReq->MsgFlags = 0; 653 pReq->MsgFlags = 0;
654 pReq->Reserved2 = 0; 654 pReq->Reserved2 = 0;
655 pReq->ActionDataWord = 0; /* Reserved for this action */ 655 pReq->ActionDataWord = 0; /* Reserved for this action */
656 656
657 ioc->add_sge((char *)&pReq->ActionDataSGE, 657 ioc->add_sge((char *)&pReq->ActionDataSGE,
658 MPT_SGE_FLAGS_SSIMPLE_READ | 0, (dma_addr_t) -1); 658 MPT_SGE_FLAGS_SSIMPLE_READ | 0, (dma_addr_t) -1);
659 659
660 ddvprintk(ioc, printk(MYIOC_s_DEBUG_FMT "RAID Volume action=%x channel=%d id=%d\n", 660 ddvprintk(ioc, printk(MYIOC_s_DEBUG_FMT "RAID Volume action=%x channel=%d id=%d\n",
661 ioc->name, pReq->Action, channel, id)); 661 ioc->name, pReq->Action, channel, id));
662 662
663 INITIALIZE_MGMT_STATUS(ioc->internal_cmds.status) 663 INITIALIZE_MGMT_STATUS(ioc->internal_cmds.status)
664 mpt_put_msg_frame(ioc->InternalCtx, ioc, mf); 664 mpt_put_msg_frame(ioc->InternalCtx, ioc, mf);
665 timeleft = wait_for_completion_timeout(&ioc->internal_cmds.done, 10*HZ); 665 timeleft = wait_for_completion_timeout(&ioc->internal_cmds.done, 10*HZ);
666 if (!(ioc->internal_cmds.status & MPT_MGMT_STATUS_COMMAND_GOOD)) { 666 if (!(ioc->internal_cmds.status & MPT_MGMT_STATUS_COMMAND_GOOD)) {
667 ret = -ETIME; 667 ret = -ETIME;
668 dfailprintk(ioc, printk(MYIOC_s_DEBUG_FMT "%s: TIMED OUT!\n", 668 dfailprintk(ioc, printk(MYIOC_s_DEBUG_FMT "%s: TIMED OUT!\n",
669 ioc->name, __func__)); 669 ioc->name, __func__));
670 if (ioc->internal_cmds.status & MPT_MGMT_STATUS_DID_IOCRESET) 670 if (ioc->internal_cmds.status & MPT_MGMT_STATUS_DID_IOCRESET)
671 goto out; 671 goto out;
672 if (!timeleft) { 672 if (!timeleft) {
673 printk(MYIOC_s_WARN_FMT "Issuing Reset from %s!!\n", 673 printk(MYIOC_s_WARN_FMT "Issuing Reset from %s!!\n",
674 ioc->name, __func__); 674 ioc->name, __func__);
675 mpt_HardResetHandler(ioc, CAN_SLEEP); 675 mpt_HardResetHandler(ioc, CAN_SLEEP);
676 mpt_free_msg_frame(ioc, mf); 676 mpt_free_msg_frame(ioc, mf);
677 } 677 }
678 goto out; 678 goto out;
679 } 679 }
680 680
681 ret = ioc->internal_cmds.completion_code; 681 ret = ioc->internal_cmds.completion_code;
682 682
683 out: 683 out:
684 CLEAR_MGMT_STATUS(ioc->internal_cmds.status) 684 CLEAR_MGMT_STATUS(ioc->internal_cmds.status)
685 mutex_unlock(&ioc->internal_cmds.mutex); 685 mutex_unlock(&ioc->internal_cmds.mutex);
686 return ret; 686 return ret;
687 } 687 }
688 688
689 static void mptspi_dv_device(struct _MPT_SCSI_HOST *hd, 689 static void mptspi_dv_device(struct _MPT_SCSI_HOST *hd,
690 struct scsi_device *sdev) 690 struct scsi_device *sdev)
691 { 691 {
692 VirtTarget *vtarget = scsi_target(sdev)->hostdata; 692 VirtTarget *vtarget = scsi_target(sdev)->hostdata;
693 MPT_ADAPTER *ioc = hd->ioc; 693 MPT_ADAPTER *ioc = hd->ioc;
694 694
695 /* no DV on RAID devices */ 695 /* no DV on RAID devices */
696 if (sdev->channel == 0 && 696 if (sdev->channel == 0 &&
697 mptspi_is_raid(hd, sdev->id)) 697 mptspi_is_raid(hd, sdev->id))
698 return; 698 return;
699 699
700 /* If this is a piece of a RAID, then quiesce first */ 700 /* If this is a piece of a RAID, then quiesce first */
701 if (sdev->channel == 1 && 701 if (sdev->channel == 1 &&
702 mptscsih_quiesce_raid(hd, 1, vtarget->channel, vtarget->id) < 0) { 702 mptscsih_quiesce_raid(hd, 1, vtarget->channel, vtarget->id) < 0) {
703 starget_printk(KERN_ERR, scsi_target(sdev), MYIOC_s_FMT 703 starget_printk(KERN_ERR, scsi_target(sdev), MYIOC_s_FMT
704 "Integrated RAID quiesce failed\n", ioc->name); 704 "Integrated RAID quiesce failed\n", ioc->name);
705 return; 705 return;
706 } 706 }
707 707
708 hd->spi_pending |= (1 << sdev->id); 708 hd->spi_pending |= (1 << sdev->id);
709 spi_dv_device(sdev); 709 spi_dv_device(sdev);
710 hd->spi_pending &= ~(1 << sdev->id); 710 hd->spi_pending &= ~(1 << sdev->id);
711 711
712 if (sdev->channel == 1 && 712 if (sdev->channel == 1 &&
713 mptscsih_quiesce_raid(hd, 0, vtarget->channel, vtarget->id) < 0) 713 mptscsih_quiesce_raid(hd, 0, vtarget->channel, vtarget->id) < 0)
714 starget_printk(KERN_ERR, scsi_target(sdev), MYIOC_s_FMT 714 starget_printk(KERN_ERR, scsi_target(sdev), MYIOC_s_FMT
715 "Integrated RAID resume failed\n", ioc->name); 715 "Integrated RAID resume failed\n", ioc->name);
716 716
717 mptspi_read_parameters(sdev->sdev_target); 717 mptspi_read_parameters(sdev->sdev_target);
718 spi_display_xfer_agreement(sdev->sdev_target); 718 spi_display_xfer_agreement(sdev->sdev_target);
719 mptspi_read_parameters(sdev->sdev_target); 719 mptspi_read_parameters(sdev->sdev_target);
720 } 720 }
721 721
722 static int mptspi_slave_alloc(struct scsi_device *sdev) 722 static int mptspi_slave_alloc(struct scsi_device *sdev)
723 { 723 {
724 MPT_SCSI_HOST *hd = shost_priv(sdev->host); 724 MPT_SCSI_HOST *hd = shost_priv(sdev->host);
725 VirtTarget *vtarget; 725 VirtTarget *vtarget;
726 VirtDevice *vdevice; 726 VirtDevice *vdevice;
727 struct scsi_target *starget; 727 struct scsi_target *starget;
728 MPT_ADAPTER *ioc = hd->ioc; 728 MPT_ADAPTER *ioc = hd->ioc;
729 729
730 if (sdev->channel == 1 && 730 if (sdev->channel == 1 &&
731 mptscsih_is_phys_disk(ioc, 0, sdev->id) == 0) 731 mptscsih_is_phys_disk(ioc, 0, sdev->id) == 0)
732 return -ENXIO; 732 return -ENXIO;
733 733
734 vdevice = kzalloc(sizeof(VirtDevice), GFP_KERNEL); 734 vdevice = kzalloc(sizeof(VirtDevice), GFP_KERNEL);
735 if (!vdevice) { 735 if (!vdevice) {
736 printk(MYIOC_s_ERR_FMT "slave_alloc kmalloc(%zd) FAILED!\n", 736 printk(MYIOC_s_ERR_FMT "slave_alloc kmalloc(%zd) FAILED!\n",
737 ioc->name, sizeof(VirtDevice)); 737 ioc->name, sizeof(VirtDevice));
738 return -ENOMEM; 738 return -ENOMEM;
739 } 739 }
740 740
741 vdevice->lun = sdev->lun; 741 vdevice->lun = sdev->lun;
742 sdev->hostdata = vdevice; 742 sdev->hostdata = vdevice;
743 743
744 starget = scsi_target(sdev); 744 starget = scsi_target(sdev);
745 vtarget = starget->hostdata; 745 vtarget = starget->hostdata;
746 vdevice->vtarget = vtarget; 746 vdevice->vtarget = vtarget;
747 vtarget->num_luns++; 747 vtarget->num_luns++;
748 748
749 if (sdev->channel == 1) 749 if (sdev->channel == 1)
750 sdev->no_uld_attach = 1; 750 sdev->no_uld_attach = 1;
751 751
752 return 0; 752 return 0;
753 } 753 }
754 754
755 static int mptspi_slave_configure(struct scsi_device *sdev) 755 static int mptspi_slave_configure(struct scsi_device *sdev)
756 { 756 {
757 struct _MPT_SCSI_HOST *hd = shost_priv(sdev->host); 757 struct _MPT_SCSI_HOST *hd = shost_priv(sdev->host);
758 VirtTarget *vtarget = scsi_target(sdev)->hostdata; 758 VirtTarget *vtarget = scsi_target(sdev)->hostdata;
759 int ret; 759 int ret;
760 760
761 mptspi_initTarget(hd, vtarget, sdev); 761 mptspi_initTarget(hd, vtarget, sdev);
762 762
763 ret = mptscsih_slave_configure(sdev); 763 ret = mptscsih_slave_configure(sdev);
764 764
765 if (ret) 765 if (ret)
766 return ret; 766 return ret;
767 767
768 ddvprintk(hd->ioc, printk(MYIOC_s_DEBUG_FMT "id=%d min_period=0x%02x" 768 ddvprintk(hd->ioc, printk(MYIOC_s_DEBUG_FMT "id=%d min_period=0x%02x"
769 " max_offset=0x%02x max_width=%d\n", hd->ioc->name, 769 " max_offset=0x%02x max_width=%d\n", hd->ioc->name,
770 sdev->id, spi_min_period(scsi_target(sdev)), 770 sdev->id, spi_min_period(scsi_target(sdev)),
771 spi_max_offset(scsi_target(sdev)), 771 spi_max_offset(scsi_target(sdev)),
772 spi_max_width(scsi_target(sdev)))); 772 spi_max_width(scsi_target(sdev))));
773 773
774 if ((sdev->channel == 1 || 774 if ((sdev->channel == 1 ||
775 !(mptspi_is_raid(hd, sdev->id))) && 775 !(mptspi_is_raid(hd, sdev->id))) &&
776 !spi_initial_dv(sdev->sdev_target)) 776 !spi_initial_dv(sdev->sdev_target))
777 mptspi_dv_device(hd, sdev); 777 mptspi_dv_device(hd, sdev);
778 778
779 return 0; 779 return 0;
780 } 780 }
781 781
782 static int 782 static int
783 mptspi_qcmd_lck(struct scsi_cmnd *SCpnt, void (*done)(struct scsi_cmnd *)) 783 mptspi_qcmd_lck(struct scsi_cmnd *SCpnt, void (*done)(struct scsi_cmnd *))
784 { 784 {
785 struct _MPT_SCSI_HOST *hd = shost_priv(SCpnt->device->host); 785 struct _MPT_SCSI_HOST *hd = shost_priv(SCpnt->device->host);
786 VirtDevice *vdevice = SCpnt->device->hostdata; 786 VirtDevice *vdevice = SCpnt->device->hostdata;
787 MPT_ADAPTER *ioc = hd->ioc; 787 MPT_ADAPTER *ioc = hd->ioc;
788 788
789 if (!vdevice || !vdevice->vtarget) { 789 if (!vdevice || !vdevice->vtarget) {
790 SCpnt->result = DID_NO_CONNECT << 16; 790 SCpnt->result = DID_NO_CONNECT << 16;
791 done(SCpnt); 791 done(SCpnt);
792 return 0; 792 return 0;
793 } 793 }
794 794
795 if (SCpnt->device->channel == 1 && 795 if (SCpnt->device->channel == 1 &&
796 mptscsih_is_phys_disk(ioc, 0, SCpnt->device->id) == 0) { 796 mptscsih_is_phys_disk(ioc, 0, SCpnt->device->id) == 0) {
797 SCpnt->result = DID_NO_CONNECT << 16; 797 SCpnt->result = DID_NO_CONNECT << 16;
798 done(SCpnt); 798 done(SCpnt);
799 return 0; 799 return 0;
800 } 800 }
801 801
802 if (spi_dv_pending(scsi_target(SCpnt->device))) 802 if (spi_dv_pending(scsi_target(SCpnt->device)))
803 ddvprintk(ioc, scsi_print_command(SCpnt)); 803 ddvprintk(ioc, scsi_print_command(SCpnt));
804 804
805 return mptscsih_qcmd(SCpnt,done); 805 return mptscsih_qcmd(SCpnt,done);
806 } 806 }
807 807
808 static DEF_SCSI_QCMD(mptspi_qcmd) 808 static DEF_SCSI_QCMD(mptspi_qcmd)
809 809
810 static void mptspi_slave_destroy(struct scsi_device *sdev) 810 static void mptspi_slave_destroy(struct scsi_device *sdev)
811 { 811 {
812 struct scsi_target *starget = scsi_target(sdev); 812 struct scsi_target *starget = scsi_target(sdev);
813 VirtTarget *vtarget = starget->hostdata; 813 VirtTarget *vtarget = starget->hostdata;
814 VirtDevice *vdevice = sdev->hostdata; 814 VirtDevice *vdevice = sdev->hostdata;
815 815
816 /* Will this be the last lun on a non-raid device? */ 816 /* Will this be the last lun on a non-raid device? */
817 if (vtarget->num_luns == 1 && vdevice->configured_lun) { 817 if (vtarget->num_luns == 1 && vdevice->configured_lun) {
818 struct _CONFIG_PAGE_SCSI_DEVICE_1 pg1; 818 struct _CONFIG_PAGE_SCSI_DEVICE_1 pg1;
819 819
820 /* Async Narrow */ 820 /* Async Narrow */
821 pg1.RequestedParameters = 0; 821 pg1.RequestedParameters = 0;
822 pg1.Reserved = 0; 822 pg1.Reserved = 0;
823 pg1.Configuration = 0; 823 pg1.Configuration = 0;
824 824
825 mptspi_write_spi_device_pg1(starget, &pg1); 825 mptspi_write_spi_device_pg1(starget, &pg1);
826 } 826 }
827 827
828 mptscsih_slave_destroy(sdev); 828 mptscsih_slave_destroy(sdev);
829 } 829 }
830 830
831 static struct scsi_host_template mptspi_driver_template = { 831 static struct scsi_host_template mptspi_driver_template = {
832 .module = THIS_MODULE, 832 .module = THIS_MODULE,
833 .proc_name = "mptspi", 833 .proc_name = "mptspi",
834 .proc_info = mptscsih_proc_info, 834 .show_info = mptscsih_show_info,
835 .name = "MPT SPI Host", 835 .name = "MPT SPI Host",
836 .info = mptscsih_info, 836 .info = mptscsih_info,
837 .queuecommand = mptspi_qcmd, 837 .queuecommand = mptspi_qcmd,
838 .target_alloc = mptspi_target_alloc, 838 .target_alloc = mptspi_target_alloc,
839 .slave_alloc = mptspi_slave_alloc, 839 .slave_alloc = mptspi_slave_alloc,
840 .slave_configure = mptspi_slave_configure, 840 .slave_configure = mptspi_slave_configure,
841 .target_destroy = mptspi_target_destroy, 841 .target_destroy = mptspi_target_destroy,
842 .slave_destroy = mptspi_slave_destroy, 842 .slave_destroy = mptspi_slave_destroy,
843 .change_queue_depth = mptscsih_change_queue_depth, 843 .change_queue_depth = mptscsih_change_queue_depth,
844 .eh_abort_handler = mptscsih_abort, 844 .eh_abort_handler = mptscsih_abort,
845 .eh_device_reset_handler = mptscsih_dev_reset, 845 .eh_device_reset_handler = mptscsih_dev_reset,
846 .eh_bus_reset_handler = mptscsih_bus_reset, 846 .eh_bus_reset_handler = mptscsih_bus_reset,
847 .eh_host_reset_handler = mptscsih_host_reset, 847 .eh_host_reset_handler = mptscsih_host_reset,
848 .bios_param = mptscsih_bios_param, 848 .bios_param = mptscsih_bios_param,
849 .can_queue = MPT_SCSI_CAN_QUEUE, 849 .can_queue = MPT_SCSI_CAN_QUEUE,
850 .this_id = -1, 850 .this_id = -1,
851 .sg_tablesize = MPT_SCSI_SG_DEPTH, 851 .sg_tablesize = MPT_SCSI_SG_DEPTH,
852 .max_sectors = 8192, 852 .max_sectors = 8192,
853 .cmd_per_lun = 7, 853 .cmd_per_lun = 7,
854 .use_clustering = ENABLE_CLUSTERING, 854 .use_clustering = ENABLE_CLUSTERING,
855 .shost_attrs = mptscsih_host_attrs, 855 .shost_attrs = mptscsih_host_attrs,
856 }; 856 };
857 857
858 static int mptspi_write_spi_device_pg1(struct scsi_target *starget, 858 static int mptspi_write_spi_device_pg1(struct scsi_target *starget,
859 struct _CONFIG_PAGE_SCSI_DEVICE_1 *pass_pg1) 859 struct _CONFIG_PAGE_SCSI_DEVICE_1 *pass_pg1)
860 { 860 {
861 struct Scsi_Host *shost = dev_to_shost(&starget->dev); 861 struct Scsi_Host *shost = dev_to_shost(&starget->dev);
862 struct _MPT_SCSI_HOST *hd = shost_priv(shost); 862 struct _MPT_SCSI_HOST *hd = shost_priv(shost);
863 struct _MPT_ADAPTER *ioc = hd->ioc; 863 struct _MPT_ADAPTER *ioc = hd->ioc;
864 struct _CONFIG_PAGE_SCSI_DEVICE_1 *pg1; 864 struct _CONFIG_PAGE_SCSI_DEVICE_1 *pg1;
865 dma_addr_t pg1_dma; 865 dma_addr_t pg1_dma;
866 int size; 866 int size;
867 struct _x_config_parms cfg; 867 struct _x_config_parms cfg;
868 struct _CONFIG_PAGE_HEADER hdr; 868 struct _CONFIG_PAGE_HEADER hdr;
869 int err = -EBUSY; 869 int err = -EBUSY;
870 u32 nego_parms; 870 u32 nego_parms;
871 u32 period; 871 u32 period;
872 struct scsi_device *sdev; 872 struct scsi_device *sdev;
873 int i; 873 int i;
874 874
875 /* don't allow updating nego parameters on RAID devices */ 875 /* don't allow updating nego parameters on RAID devices */
876 if (starget->channel == 0 && 876 if (starget->channel == 0 &&
877 mptspi_is_raid(hd, starget->id)) 877 mptspi_is_raid(hd, starget->id))
878 return -1; 878 return -1;
879 879
880 size = ioc->spi_data.sdp1length * 4; 880 size = ioc->spi_data.sdp1length * 4;
881 881
882 pg1 = dma_alloc_coherent(&ioc->pcidev->dev, size, &pg1_dma, GFP_KERNEL); 882 pg1 = dma_alloc_coherent(&ioc->pcidev->dev, size, &pg1_dma, GFP_KERNEL);
883 if (pg1 == NULL) { 883 if (pg1 == NULL) {
884 starget_printk(KERN_ERR, starget, MYIOC_s_FMT 884 starget_printk(KERN_ERR, starget, MYIOC_s_FMT
885 "dma_alloc_coherent for parameters failed\n", ioc->name); 885 "dma_alloc_coherent for parameters failed\n", ioc->name);
886 return -EINVAL; 886 return -EINVAL;
887 } 887 }
888 888
889 memset(&hdr, 0, sizeof(hdr)); 889 memset(&hdr, 0, sizeof(hdr));
890 890
891 hdr.PageVersion = ioc->spi_data.sdp1version; 891 hdr.PageVersion = ioc->spi_data.sdp1version;
892 hdr.PageLength = ioc->spi_data.sdp1length; 892 hdr.PageLength = ioc->spi_data.sdp1length;
893 hdr.PageNumber = 1; 893 hdr.PageNumber = 1;
894 hdr.PageType = MPI_CONFIG_PAGETYPE_SCSI_DEVICE; 894 hdr.PageType = MPI_CONFIG_PAGETYPE_SCSI_DEVICE;
895 895
896 memset(&cfg, 0, sizeof(cfg)); 896 memset(&cfg, 0, sizeof(cfg));
897 897
898 cfg.cfghdr.hdr = &hdr; 898 cfg.cfghdr.hdr = &hdr;
899 cfg.physAddr = pg1_dma; 899 cfg.physAddr = pg1_dma;
900 cfg.action = MPI_CONFIG_ACTION_PAGE_WRITE_CURRENT; 900 cfg.action = MPI_CONFIG_ACTION_PAGE_WRITE_CURRENT;
901 cfg.dir = 1; 901 cfg.dir = 1;
902 cfg.pageAddr = starget->id; 902 cfg.pageAddr = starget->id;
903 903
904 memcpy(pg1, pass_pg1, size); 904 memcpy(pg1, pass_pg1, size);
905 905
906 pg1->Header.PageVersion = hdr.PageVersion; 906 pg1->Header.PageVersion = hdr.PageVersion;
907 pg1->Header.PageLength = hdr.PageLength; 907 pg1->Header.PageLength = hdr.PageLength;
908 pg1->Header.PageNumber = hdr.PageNumber; 908 pg1->Header.PageNumber = hdr.PageNumber;
909 pg1->Header.PageType = hdr.PageType; 909 pg1->Header.PageType = hdr.PageType;
910 910
911 nego_parms = le32_to_cpu(pg1->RequestedParameters); 911 nego_parms = le32_to_cpu(pg1->RequestedParameters);
912 period = (nego_parms & MPI_SCSIDEVPAGE1_RP_MIN_SYNC_PERIOD_MASK) >> 912 period = (nego_parms & MPI_SCSIDEVPAGE1_RP_MIN_SYNC_PERIOD_MASK) >>
913 MPI_SCSIDEVPAGE1_RP_SHIFT_MIN_SYNC_PERIOD; 913 MPI_SCSIDEVPAGE1_RP_SHIFT_MIN_SYNC_PERIOD;
914 if (period == 8) { 914 if (period == 8) {
915 /* Turn on inline data padding for TAPE when running U320 */ 915 /* Turn on inline data padding for TAPE when running U320 */
916 for (i = 0 ; i < 16; i++) { 916 for (i = 0 ; i < 16; i++) {
917 sdev = scsi_device_lookup_by_target(starget, i); 917 sdev = scsi_device_lookup_by_target(starget, i);
918 if (sdev && sdev->type == TYPE_TAPE) { 918 if (sdev && sdev->type == TYPE_TAPE) {
919 sdev_printk(KERN_DEBUG, sdev, MYIOC_s_FMT 919 sdev_printk(KERN_DEBUG, sdev, MYIOC_s_FMT
920 "IDP:ON\n", ioc->name); 920 "IDP:ON\n", ioc->name);
921 nego_parms |= MPI_SCSIDEVPAGE1_RP_IDP; 921 nego_parms |= MPI_SCSIDEVPAGE1_RP_IDP;
922 pg1->RequestedParameters = 922 pg1->RequestedParameters =
923 cpu_to_le32(nego_parms); 923 cpu_to_le32(nego_parms);
924 break; 924 break;
925 } 925 }
926 } 926 }
927 } 927 }
928 928
929 mptspi_print_write_nego(hd, starget, le32_to_cpu(pg1->RequestedParameters)); 929 mptspi_print_write_nego(hd, starget, le32_to_cpu(pg1->RequestedParameters));
930 930
931 if (mpt_config(ioc, &cfg)) { 931 if (mpt_config(ioc, &cfg)) {
932 starget_printk(KERN_ERR, starget, MYIOC_s_FMT 932 starget_printk(KERN_ERR, starget, MYIOC_s_FMT
933 "mpt_config failed\n", ioc->name); 933 "mpt_config failed\n", ioc->name);
934 goto out_free; 934 goto out_free;
935 } 935 }
936 err = 0; 936 err = 0;
937 937
938 out_free: 938 out_free:
939 dma_free_coherent(&ioc->pcidev->dev, size, pg1, pg1_dma); 939 dma_free_coherent(&ioc->pcidev->dev, size, pg1, pg1_dma);
940 return err; 940 return err;
941 } 941 }
942 942
943 static void mptspi_write_offset(struct scsi_target *starget, int offset) 943 static void mptspi_write_offset(struct scsi_target *starget, int offset)
944 { 944 {
945 struct _CONFIG_PAGE_SCSI_DEVICE_1 pg1; 945 struct _CONFIG_PAGE_SCSI_DEVICE_1 pg1;
946 u32 nego; 946 u32 nego;
947 947
948 if (offset < 0) 948 if (offset < 0)
949 offset = 0; 949 offset = 0;
950 950
951 if (offset > 255) 951 if (offset > 255)
952 offset = 255; 952 offset = 255;
953 953
954 if (spi_offset(starget) == -1) 954 if (spi_offset(starget) == -1)
955 mptspi_read_parameters(starget); 955 mptspi_read_parameters(starget);
956 956
957 spi_offset(starget) = offset; 957 spi_offset(starget) = offset;
958 958
959 nego = mptspi_getRP(starget); 959 nego = mptspi_getRP(starget);
960 960
961 pg1.RequestedParameters = cpu_to_le32(nego); 961 pg1.RequestedParameters = cpu_to_le32(nego);
962 pg1.Reserved = 0; 962 pg1.Reserved = 0;
963 pg1.Configuration = 0; 963 pg1.Configuration = 0;
964 964
965 mptspi_write_spi_device_pg1(starget, &pg1); 965 mptspi_write_spi_device_pg1(starget, &pg1);
966 } 966 }
967 967
968 static void mptspi_write_period(struct scsi_target *starget, int period) 968 static void mptspi_write_period(struct scsi_target *starget, int period)
969 { 969 {
970 struct _CONFIG_PAGE_SCSI_DEVICE_1 pg1; 970 struct _CONFIG_PAGE_SCSI_DEVICE_1 pg1;
971 u32 nego; 971 u32 nego;
972 972
973 if (period < 8) 973 if (period < 8)
974 period = 8; 974 period = 8;
975 975
976 if (period > 255) 976 if (period > 255)
977 period = 255; 977 period = 255;
978 978
979 if (spi_period(starget) == -1) 979 if (spi_period(starget) == -1)
980 mptspi_read_parameters(starget); 980 mptspi_read_parameters(starget);
981 981
982 if (period == 8) { 982 if (period == 8) {
983 spi_iu(starget) = 1; 983 spi_iu(starget) = 1;
984 spi_dt(starget) = 1; 984 spi_dt(starget) = 1;
985 } else if (period == 9) { 985 } else if (period == 9) {
986 spi_dt(starget) = 1; 986 spi_dt(starget) = 1;
987 } 987 }
988 988
989 spi_period(starget) = period; 989 spi_period(starget) = period;
990 990
991 nego = mptspi_getRP(starget); 991 nego = mptspi_getRP(starget);
992 992
993 pg1.RequestedParameters = cpu_to_le32(nego); 993 pg1.RequestedParameters = cpu_to_le32(nego);
994 pg1.Reserved = 0; 994 pg1.Reserved = 0;
995 pg1.Configuration = 0; 995 pg1.Configuration = 0;
996 996
997 mptspi_write_spi_device_pg1(starget, &pg1); 997 mptspi_write_spi_device_pg1(starget, &pg1);
998 } 998 }
999 999
1000 static void mptspi_write_dt(struct scsi_target *starget, int dt) 1000 static void mptspi_write_dt(struct scsi_target *starget, int dt)
1001 { 1001 {
1002 struct _CONFIG_PAGE_SCSI_DEVICE_1 pg1; 1002 struct _CONFIG_PAGE_SCSI_DEVICE_1 pg1;
1003 u32 nego; 1003 u32 nego;
1004 1004
1005 if (spi_period(starget) == -1) 1005 if (spi_period(starget) == -1)
1006 mptspi_read_parameters(starget); 1006 mptspi_read_parameters(starget);
1007 1007
1008 if (!dt && spi_period(starget) < 10) 1008 if (!dt && spi_period(starget) < 10)
1009 spi_period(starget) = 10; 1009 spi_period(starget) = 10;
1010 1010
1011 spi_dt(starget) = dt; 1011 spi_dt(starget) = dt;
1012 1012
1013 nego = mptspi_getRP(starget); 1013 nego = mptspi_getRP(starget);
1014 1014
1015 1015
1016 pg1.RequestedParameters = cpu_to_le32(nego); 1016 pg1.RequestedParameters = cpu_to_le32(nego);
1017 pg1.Reserved = 0; 1017 pg1.Reserved = 0;
1018 pg1.Configuration = 0; 1018 pg1.Configuration = 0;
1019 1019
1020 mptspi_write_spi_device_pg1(starget, &pg1); 1020 mptspi_write_spi_device_pg1(starget, &pg1);
1021 } 1021 }
1022 1022
1023 static void mptspi_write_iu(struct scsi_target *starget, int iu) 1023 static void mptspi_write_iu(struct scsi_target *starget, int iu)
1024 { 1024 {
1025 struct _CONFIG_PAGE_SCSI_DEVICE_1 pg1; 1025 struct _CONFIG_PAGE_SCSI_DEVICE_1 pg1;
1026 u32 nego; 1026 u32 nego;
1027 1027
1028 if (spi_period(starget) == -1) 1028 if (spi_period(starget) == -1)
1029 mptspi_read_parameters(starget); 1029 mptspi_read_parameters(starget);
1030 1030
1031 if (!iu && spi_period(starget) < 9) 1031 if (!iu && spi_period(starget) < 9)
1032 spi_period(starget) = 9; 1032 spi_period(starget) = 9;
1033 1033
1034 spi_iu(starget) = iu; 1034 spi_iu(starget) = iu;
1035 1035
1036 nego = mptspi_getRP(starget); 1036 nego = mptspi_getRP(starget);
1037 1037
1038 pg1.RequestedParameters = cpu_to_le32(nego); 1038 pg1.RequestedParameters = cpu_to_le32(nego);
1039 pg1.Reserved = 0; 1039 pg1.Reserved = 0;
1040 pg1.Configuration = 0; 1040 pg1.Configuration = 0;
1041 1041
1042 mptspi_write_spi_device_pg1(starget, &pg1); 1042 mptspi_write_spi_device_pg1(starget, &pg1);
1043 } 1043 }
1044 1044
1045 #define MPTSPI_SIMPLE_TRANSPORT_PARM(parm) \ 1045 #define MPTSPI_SIMPLE_TRANSPORT_PARM(parm) \
1046 static void mptspi_write_##parm(struct scsi_target *starget, int parm)\ 1046 static void mptspi_write_##parm(struct scsi_target *starget, int parm)\
1047 { \ 1047 { \
1048 struct _CONFIG_PAGE_SCSI_DEVICE_1 pg1; \ 1048 struct _CONFIG_PAGE_SCSI_DEVICE_1 pg1; \
1049 u32 nego; \ 1049 u32 nego; \
1050 \ 1050 \
1051 spi_##parm(starget) = parm; \ 1051 spi_##parm(starget) = parm; \
1052 \ 1052 \
1053 nego = mptspi_getRP(starget); \ 1053 nego = mptspi_getRP(starget); \
1054 \ 1054 \
1055 pg1.RequestedParameters = cpu_to_le32(nego); \ 1055 pg1.RequestedParameters = cpu_to_le32(nego); \
1056 pg1.Reserved = 0; \ 1056 pg1.Reserved = 0; \
1057 pg1.Configuration = 0; \ 1057 pg1.Configuration = 0; \
1058 \ 1058 \
1059 mptspi_write_spi_device_pg1(starget, &pg1); \ 1059 mptspi_write_spi_device_pg1(starget, &pg1); \
1060 } 1060 }
1061 1061
1062 MPTSPI_SIMPLE_TRANSPORT_PARM(rd_strm) 1062 MPTSPI_SIMPLE_TRANSPORT_PARM(rd_strm)
1063 MPTSPI_SIMPLE_TRANSPORT_PARM(wr_flow) 1063 MPTSPI_SIMPLE_TRANSPORT_PARM(wr_flow)
1064 MPTSPI_SIMPLE_TRANSPORT_PARM(rti) 1064 MPTSPI_SIMPLE_TRANSPORT_PARM(rti)
1065 MPTSPI_SIMPLE_TRANSPORT_PARM(hold_mcs) 1065 MPTSPI_SIMPLE_TRANSPORT_PARM(hold_mcs)
1066 MPTSPI_SIMPLE_TRANSPORT_PARM(pcomp_en) 1066 MPTSPI_SIMPLE_TRANSPORT_PARM(pcomp_en)
1067 1067
1068 static void mptspi_write_qas(struct scsi_target *starget, int qas) 1068 static void mptspi_write_qas(struct scsi_target *starget, int qas)
1069 { 1069 {
1070 struct _CONFIG_PAGE_SCSI_DEVICE_1 pg1; 1070 struct _CONFIG_PAGE_SCSI_DEVICE_1 pg1;
1071 struct Scsi_Host *shost = dev_to_shost(&starget->dev); 1071 struct Scsi_Host *shost = dev_to_shost(&starget->dev);
1072 struct _MPT_SCSI_HOST *hd = shost_priv(shost); 1072 struct _MPT_SCSI_HOST *hd = shost_priv(shost);
1073 VirtTarget *vtarget = starget->hostdata; 1073 VirtTarget *vtarget = starget->hostdata;
1074 u32 nego; 1074 u32 nego;
1075 1075
1076 if ((vtarget->negoFlags & MPT_TARGET_NO_NEGO_QAS) || 1076 if ((vtarget->negoFlags & MPT_TARGET_NO_NEGO_QAS) ||
1077 hd->ioc->spi_data.noQas) 1077 hd->ioc->spi_data.noQas)
1078 spi_qas(starget) = 0; 1078 spi_qas(starget) = 0;
1079 else 1079 else
1080 spi_qas(starget) = qas; 1080 spi_qas(starget) = qas;
1081 1081
1082 nego = mptspi_getRP(starget); 1082 nego = mptspi_getRP(starget);
1083 1083
1084 pg1.RequestedParameters = cpu_to_le32(nego); 1084 pg1.RequestedParameters = cpu_to_le32(nego);
1085 pg1.Reserved = 0; 1085 pg1.Reserved = 0;
1086 pg1.Configuration = 0; 1086 pg1.Configuration = 0;
1087 1087
1088 mptspi_write_spi_device_pg1(starget, &pg1); 1088 mptspi_write_spi_device_pg1(starget, &pg1);
1089 } 1089 }
1090 1090
1091 static void mptspi_write_width(struct scsi_target *starget, int width) 1091 static void mptspi_write_width(struct scsi_target *starget, int width)
1092 { 1092 {
1093 struct _CONFIG_PAGE_SCSI_DEVICE_1 pg1; 1093 struct _CONFIG_PAGE_SCSI_DEVICE_1 pg1;
1094 u32 nego; 1094 u32 nego;
1095 1095
1096 if (!width) { 1096 if (!width) {
1097 spi_dt(starget) = 0; 1097 spi_dt(starget) = 0;
1098 if (spi_period(starget) < 10) 1098 if (spi_period(starget) < 10)
1099 spi_period(starget) = 10; 1099 spi_period(starget) = 10;
1100 } 1100 }
1101 1101
1102 spi_width(starget) = width; 1102 spi_width(starget) = width;
1103 1103
1104 nego = mptspi_getRP(starget); 1104 nego = mptspi_getRP(starget);
1105 1105
1106 pg1.RequestedParameters = cpu_to_le32(nego); 1106 pg1.RequestedParameters = cpu_to_le32(nego);
1107 pg1.Reserved = 0; 1107 pg1.Reserved = 0;
1108 pg1.Configuration = 0; 1108 pg1.Configuration = 0;
1109 1109
1110 mptspi_write_spi_device_pg1(starget, &pg1); 1110 mptspi_write_spi_device_pg1(starget, &pg1);
1111 } 1111 }
1112 1112
1113 struct work_queue_wrapper { 1113 struct work_queue_wrapper {
1114 struct work_struct work; 1114 struct work_struct work;
1115 struct _MPT_SCSI_HOST *hd; 1115 struct _MPT_SCSI_HOST *hd;
1116 int disk; 1116 int disk;
1117 }; 1117 };
1118 1118
1119 static void mpt_work_wrapper(struct work_struct *work) 1119 static void mpt_work_wrapper(struct work_struct *work)
1120 { 1120 {
1121 struct work_queue_wrapper *wqw = 1121 struct work_queue_wrapper *wqw =
1122 container_of(work, struct work_queue_wrapper, work); 1122 container_of(work, struct work_queue_wrapper, work);
1123 struct _MPT_SCSI_HOST *hd = wqw->hd; 1123 struct _MPT_SCSI_HOST *hd = wqw->hd;
1124 MPT_ADAPTER *ioc = hd->ioc; 1124 MPT_ADAPTER *ioc = hd->ioc;
1125 struct Scsi_Host *shost = ioc->sh; 1125 struct Scsi_Host *shost = ioc->sh;
1126 struct scsi_device *sdev; 1126 struct scsi_device *sdev;
1127 int disk = wqw->disk; 1127 int disk = wqw->disk;
1128 struct _CONFIG_PAGE_IOC_3 *pg3; 1128 struct _CONFIG_PAGE_IOC_3 *pg3;
1129 1129
1130 kfree(wqw); 1130 kfree(wqw);
1131 1131
1132 mpt_findImVolumes(ioc); 1132 mpt_findImVolumes(ioc);
1133 pg3 = ioc->raid_data.pIocPg3; 1133 pg3 = ioc->raid_data.pIocPg3;
1134 if (!pg3) 1134 if (!pg3)
1135 return; 1135 return;
1136 1136
1137 shost_for_each_device(sdev,shost) { 1137 shost_for_each_device(sdev,shost) {
1138 struct scsi_target *starget = scsi_target(sdev); 1138 struct scsi_target *starget = scsi_target(sdev);
1139 VirtTarget *vtarget = starget->hostdata; 1139 VirtTarget *vtarget = starget->hostdata;
1140 1140
1141 /* only want to search RAID components */ 1141 /* only want to search RAID components */
1142 if (sdev->channel != 1) 1142 if (sdev->channel != 1)
1143 continue; 1143 continue;
1144 1144
1145 /* The id is the raid PhysDiskNum, even if 1145 /* The id is the raid PhysDiskNum, even if
1146 * starget->id is the actual target address */ 1146 * starget->id is the actual target address */
1147 if(vtarget->id != disk) 1147 if(vtarget->id != disk)
1148 continue; 1148 continue;
1149 1149
1150 starget_printk(KERN_INFO, vtarget->starget, MYIOC_s_FMT 1150 starget_printk(KERN_INFO, vtarget->starget, MYIOC_s_FMT
1151 "Integrated RAID requests DV of new device\n", ioc->name); 1151 "Integrated RAID requests DV of new device\n", ioc->name);
1152 mptspi_dv_device(hd, sdev); 1152 mptspi_dv_device(hd, sdev);
1153 } 1153 }
1154 shost_printk(KERN_INFO, shost, MYIOC_s_FMT 1154 shost_printk(KERN_INFO, shost, MYIOC_s_FMT
1155 "Integrated RAID detects new device %d\n", ioc->name, disk); 1155 "Integrated RAID detects new device %d\n", ioc->name, disk);
1156 scsi_scan_target(&ioc->sh->shost_gendev, 1, disk, 0, 1); 1156 scsi_scan_target(&ioc->sh->shost_gendev, 1, disk, 0, 1);
1157 } 1157 }
1158 1158
1159 1159
1160 static void mpt_dv_raid(struct _MPT_SCSI_HOST *hd, int disk) 1160 static void mpt_dv_raid(struct _MPT_SCSI_HOST *hd, int disk)
1161 { 1161 {
1162 struct work_queue_wrapper *wqw = kmalloc(sizeof(*wqw), GFP_ATOMIC); 1162 struct work_queue_wrapper *wqw = kmalloc(sizeof(*wqw), GFP_ATOMIC);
1163 MPT_ADAPTER *ioc = hd->ioc; 1163 MPT_ADAPTER *ioc = hd->ioc;
1164 1164
1165 if (!wqw) { 1165 if (!wqw) {
1166 shost_printk(KERN_ERR, ioc->sh, MYIOC_s_FMT 1166 shost_printk(KERN_ERR, ioc->sh, MYIOC_s_FMT
1167 "Failed to act on RAID event for physical disk %d\n", 1167 "Failed to act on RAID event for physical disk %d\n",
1168 ioc->name, disk); 1168 ioc->name, disk);
1169 return; 1169 return;
1170 } 1170 }
1171 INIT_WORK(&wqw->work, mpt_work_wrapper); 1171 INIT_WORK(&wqw->work, mpt_work_wrapper);
1172 wqw->hd = hd; 1172 wqw->hd = hd;
1173 wqw->disk = disk; 1173 wqw->disk = disk;
1174 1174
1175 schedule_work(&wqw->work); 1175 schedule_work(&wqw->work);
1176 } 1176 }
1177 1177
1178 static int 1178 static int
1179 mptspi_event_process(MPT_ADAPTER *ioc, EventNotificationReply_t *pEvReply) 1179 mptspi_event_process(MPT_ADAPTER *ioc, EventNotificationReply_t *pEvReply)
1180 { 1180 {
1181 u8 event = le32_to_cpu(pEvReply->Event) & 0xFF; 1181 u8 event = le32_to_cpu(pEvReply->Event) & 0xFF;
1182 struct _MPT_SCSI_HOST *hd = shost_priv(ioc->sh); 1182 struct _MPT_SCSI_HOST *hd = shost_priv(ioc->sh);
1183 1183
1184 if (ioc->bus_type != SPI) 1184 if (ioc->bus_type != SPI)
1185 return 0; 1185 return 0;
1186 1186
1187 if (hd && event == MPI_EVENT_INTEGRATED_RAID) { 1187 if (hd && event == MPI_EVENT_INTEGRATED_RAID) {
1188 int reason 1188 int reason
1189 = (le32_to_cpu(pEvReply->Data[0]) & 0x00FF0000) >> 16; 1189 = (le32_to_cpu(pEvReply->Data[0]) & 0x00FF0000) >> 16;
1190 1190
1191 if (reason == MPI_EVENT_RAID_RC_DOMAIN_VAL_NEEDED) { 1191 if (reason == MPI_EVENT_RAID_RC_DOMAIN_VAL_NEEDED) {
1192 int disk = (le32_to_cpu(pEvReply->Data[0]) & 0xFF000000) >> 24; 1192 int disk = (le32_to_cpu(pEvReply->Data[0]) & 0xFF000000) >> 24;
1193 mpt_dv_raid(hd, disk); 1193 mpt_dv_raid(hd, disk);
1194 } 1194 }
1195 } 1195 }
1196 return mptscsih_event_process(ioc, pEvReply); 1196 return mptscsih_event_process(ioc, pEvReply);
1197 } 1197 }
1198 1198
1199 static int 1199 static int
1200 mptspi_deny_binding(struct scsi_target *starget) 1200 mptspi_deny_binding(struct scsi_target *starget)
1201 { 1201 {
1202 struct _MPT_SCSI_HOST *hd = 1202 struct _MPT_SCSI_HOST *hd =
1203 (struct _MPT_SCSI_HOST *)dev_to_shost(starget->dev.parent)->hostdata; 1203 (struct _MPT_SCSI_HOST *)dev_to_shost(starget->dev.parent)->hostdata;
1204 return ((mptspi_is_raid(hd, starget->id)) && 1204 return ((mptspi_is_raid(hd, starget->id)) &&
1205 starget->channel == 0) ? 1 : 0; 1205 starget->channel == 0) ? 1 : 0;
1206 } 1206 }
1207 1207
1208 static struct spi_function_template mptspi_transport_functions = { 1208 static struct spi_function_template mptspi_transport_functions = {
1209 .get_offset = mptspi_read_parameters, 1209 .get_offset = mptspi_read_parameters,
1210 .set_offset = mptspi_write_offset, 1210 .set_offset = mptspi_write_offset,
1211 .show_offset = 1, 1211 .show_offset = 1,
1212 .get_period = mptspi_read_parameters, 1212 .get_period = mptspi_read_parameters,
1213 .set_period = mptspi_write_period, 1213 .set_period = mptspi_write_period,
1214 .show_period = 1, 1214 .show_period = 1,
1215 .get_width = mptspi_read_parameters, 1215 .get_width = mptspi_read_parameters,
1216 .set_width = mptspi_write_width, 1216 .set_width = mptspi_write_width,
1217 .show_width = 1, 1217 .show_width = 1,
1218 .get_iu = mptspi_read_parameters, 1218 .get_iu = mptspi_read_parameters,
1219 .set_iu = mptspi_write_iu, 1219 .set_iu = mptspi_write_iu,
1220 .show_iu = 1, 1220 .show_iu = 1,
1221 .get_dt = mptspi_read_parameters, 1221 .get_dt = mptspi_read_parameters,
1222 .set_dt = mptspi_write_dt, 1222 .set_dt = mptspi_write_dt,
1223 .show_dt = 1, 1223 .show_dt = 1,
1224 .get_qas = mptspi_read_parameters, 1224 .get_qas = mptspi_read_parameters,
1225 .set_qas = mptspi_write_qas, 1225 .set_qas = mptspi_write_qas,
1226 .show_qas = 1, 1226 .show_qas = 1,
1227 .get_wr_flow = mptspi_read_parameters, 1227 .get_wr_flow = mptspi_read_parameters,
1228 .set_wr_flow = mptspi_write_wr_flow, 1228 .set_wr_flow = mptspi_write_wr_flow,
1229 .show_wr_flow = 1, 1229 .show_wr_flow = 1,
1230 .get_rd_strm = mptspi_read_parameters, 1230 .get_rd_strm = mptspi_read_parameters,
1231 .set_rd_strm = mptspi_write_rd_strm, 1231 .set_rd_strm = mptspi_write_rd_strm,
1232 .show_rd_strm = 1, 1232 .show_rd_strm = 1,
1233 .get_rti = mptspi_read_parameters, 1233 .get_rti = mptspi_read_parameters,
1234 .set_rti = mptspi_write_rti, 1234 .set_rti = mptspi_write_rti,
1235 .show_rti = 1, 1235 .show_rti = 1,
1236 .get_pcomp_en = mptspi_read_parameters, 1236 .get_pcomp_en = mptspi_read_parameters,
1237 .set_pcomp_en = mptspi_write_pcomp_en, 1237 .set_pcomp_en = mptspi_write_pcomp_en,
1238 .show_pcomp_en = 1, 1238 .show_pcomp_en = 1,
1239 .get_hold_mcs = mptspi_read_parameters, 1239 .get_hold_mcs = mptspi_read_parameters,
1240 .set_hold_mcs = mptspi_write_hold_mcs, 1240 .set_hold_mcs = mptspi_write_hold_mcs,
1241 .show_hold_mcs = 1, 1241 .show_hold_mcs = 1,
1242 .deny_binding = mptspi_deny_binding, 1242 .deny_binding = mptspi_deny_binding,
1243 }; 1243 };
1244 1244
1245 /**************************************************************************** 1245 /****************************************************************************
1246 * Supported hardware 1246 * Supported hardware
1247 */ 1247 */
1248 1248
1249 static struct pci_device_id mptspi_pci_table[] = { 1249 static struct pci_device_id mptspi_pci_table[] = {
1250 { PCI_VENDOR_ID_LSI_LOGIC, MPI_MANUFACTPAGE_DEVID_53C1030, 1250 { PCI_VENDOR_ID_LSI_LOGIC, MPI_MANUFACTPAGE_DEVID_53C1030,
1251 PCI_ANY_ID, PCI_ANY_ID }, 1251 PCI_ANY_ID, PCI_ANY_ID },
1252 { PCI_VENDOR_ID_ATTO, MPI_MANUFACTPAGE_DEVID_53C1030, 1252 { PCI_VENDOR_ID_ATTO, MPI_MANUFACTPAGE_DEVID_53C1030,
1253 PCI_ANY_ID, PCI_ANY_ID }, 1253 PCI_ANY_ID, PCI_ANY_ID },
1254 { PCI_VENDOR_ID_LSI_LOGIC, MPI_MANUFACTPAGE_DEVID_53C1035, 1254 { PCI_VENDOR_ID_LSI_LOGIC, MPI_MANUFACTPAGE_DEVID_53C1035,
1255 PCI_ANY_ID, PCI_ANY_ID }, 1255 PCI_ANY_ID, PCI_ANY_ID },
1256 {0} /* Terminating entry */ 1256 {0} /* Terminating entry */
1257 }; 1257 };
1258 MODULE_DEVICE_TABLE(pci, mptspi_pci_table); 1258 MODULE_DEVICE_TABLE(pci, mptspi_pci_table);
1259 1259
1260 1260
1261 /* 1261 /*
1262 * renegotiate for a given target 1262 * renegotiate for a given target
1263 */ 1263 */
1264 static void 1264 static void
1265 mptspi_dv_renegotiate_work(struct work_struct *work) 1265 mptspi_dv_renegotiate_work(struct work_struct *work)
1266 { 1266 {
1267 struct work_queue_wrapper *wqw = 1267 struct work_queue_wrapper *wqw =
1268 container_of(work, struct work_queue_wrapper, work); 1268 container_of(work, struct work_queue_wrapper, work);
1269 struct _MPT_SCSI_HOST *hd = wqw->hd; 1269 struct _MPT_SCSI_HOST *hd = wqw->hd;
1270 struct scsi_device *sdev; 1270 struct scsi_device *sdev;
1271 struct scsi_target *starget; 1271 struct scsi_target *starget;
1272 struct _CONFIG_PAGE_SCSI_DEVICE_1 pg1; 1272 struct _CONFIG_PAGE_SCSI_DEVICE_1 pg1;
1273 u32 nego; 1273 u32 nego;
1274 MPT_ADAPTER *ioc = hd->ioc; 1274 MPT_ADAPTER *ioc = hd->ioc;
1275 1275
1276 kfree(wqw); 1276 kfree(wqw);
1277 1277
1278 if (hd->spi_pending) { 1278 if (hd->spi_pending) {
1279 shost_for_each_device(sdev, ioc->sh) { 1279 shost_for_each_device(sdev, ioc->sh) {
1280 if (hd->spi_pending & (1 << sdev->id)) 1280 if (hd->spi_pending & (1 << sdev->id))
1281 continue; 1281 continue;
1282 starget = scsi_target(sdev); 1282 starget = scsi_target(sdev);
1283 nego = mptspi_getRP(starget); 1283 nego = mptspi_getRP(starget);
1284 pg1.RequestedParameters = cpu_to_le32(nego); 1284 pg1.RequestedParameters = cpu_to_le32(nego);
1285 pg1.Reserved = 0; 1285 pg1.Reserved = 0;
1286 pg1.Configuration = 0; 1286 pg1.Configuration = 0;
1287 mptspi_write_spi_device_pg1(starget, &pg1); 1287 mptspi_write_spi_device_pg1(starget, &pg1);
1288 } 1288 }
1289 } else { 1289 } else {
1290 shost_for_each_device(sdev, ioc->sh) 1290 shost_for_each_device(sdev, ioc->sh)
1291 mptspi_dv_device(hd, sdev); 1291 mptspi_dv_device(hd, sdev);
1292 } 1292 }
1293 } 1293 }
1294 1294
1295 static void 1295 static void
1296 mptspi_dv_renegotiate(struct _MPT_SCSI_HOST *hd) 1296 mptspi_dv_renegotiate(struct _MPT_SCSI_HOST *hd)
1297 { 1297 {
1298 struct work_queue_wrapper *wqw = kmalloc(sizeof(*wqw), GFP_ATOMIC); 1298 struct work_queue_wrapper *wqw = kmalloc(sizeof(*wqw), GFP_ATOMIC);
1299 1299
1300 if (!wqw) 1300 if (!wqw)
1301 return; 1301 return;
1302 1302
1303 INIT_WORK(&wqw->work, mptspi_dv_renegotiate_work); 1303 INIT_WORK(&wqw->work, mptspi_dv_renegotiate_work);
1304 wqw->hd = hd; 1304 wqw->hd = hd;
1305 1305
1306 schedule_work(&wqw->work); 1306 schedule_work(&wqw->work);
1307 } 1307 }
1308 1308
1309 /* 1309 /*
1310 * spi module reset handler 1310 * spi module reset handler
1311 */ 1311 */
1312 static int 1312 static int
1313 mptspi_ioc_reset(MPT_ADAPTER *ioc, int reset_phase) 1313 mptspi_ioc_reset(MPT_ADAPTER *ioc, int reset_phase)
1314 { 1314 {
1315 int rc; 1315 int rc;
1316 1316
1317 rc = mptscsih_ioc_reset(ioc, reset_phase); 1317 rc = mptscsih_ioc_reset(ioc, reset_phase);
1318 if ((ioc->bus_type != SPI) || (!rc)) 1318 if ((ioc->bus_type != SPI) || (!rc))
1319 return rc; 1319 return rc;
1320 1320
1321 /* only try to do a renegotiation if we're properly set up 1321 /* only try to do a renegotiation if we're properly set up
1322 * if we get an ioc fault on bringup, ioc->sh will be NULL */ 1322 * if we get an ioc fault on bringup, ioc->sh will be NULL */
1323 if (reset_phase == MPT_IOC_POST_RESET && 1323 if (reset_phase == MPT_IOC_POST_RESET &&
1324 ioc->sh) { 1324 ioc->sh) {
1325 struct _MPT_SCSI_HOST *hd = shost_priv(ioc->sh); 1325 struct _MPT_SCSI_HOST *hd = shost_priv(ioc->sh);
1326 1326
1327 mptspi_dv_renegotiate(hd); 1327 mptspi_dv_renegotiate(hd);
1328 } 1328 }
1329 1329
1330 return rc; 1330 return rc;
1331 } 1331 }
1332 1332
1333 #ifdef CONFIG_PM 1333 #ifdef CONFIG_PM
1334 /* 1334 /*
1335 * spi module resume handler 1335 * spi module resume handler
1336 */ 1336 */
1337 static int 1337 static int
1338 mptspi_resume(struct pci_dev *pdev) 1338 mptspi_resume(struct pci_dev *pdev)
1339 { 1339 {
1340 MPT_ADAPTER *ioc = pci_get_drvdata(pdev); 1340 MPT_ADAPTER *ioc = pci_get_drvdata(pdev);
1341 struct _MPT_SCSI_HOST *hd = shost_priv(ioc->sh); 1341 struct _MPT_SCSI_HOST *hd = shost_priv(ioc->sh);
1342 int rc; 1342 int rc;
1343 1343
1344 rc = mptscsih_resume(pdev); 1344 rc = mptscsih_resume(pdev);
1345 mptspi_dv_renegotiate(hd); 1345 mptspi_dv_renegotiate(hd);
1346 1346
1347 return rc; 1347 return rc;
1348 } 1348 }
1349 #endif 1349 #endif
1350 1350
1351 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/ 1351 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
1352 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/ 1352 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
1353 /* 1353 /*
1354 * mptspi_probe - Installs scsi devices per bus. 1354 * mptspi_probe - Installs scsi devices per bus.
1355 * @pdev: Pointer to pci_dev structure 1355 * @pdev: Pointer to pci_dev structure
1356 * 1356 *
1357 * Returns 0 for success, non-zero for failure. 1357 * Returns 0 for success, non-zero for failure.
1358 * 1358 *
1359 */ 1359 */
1360 static int 1360 static int
1361 mptspi_probe(struct pci_dev *pdev, const struct pci_device_id *id) 1361 mptspi_probe(struct pci_dev *pdev, const struct pci_device_id *id)
1362 { 1362 {
1363 struct Scsi_Host *sh; 1363 struct Scsi_Host *sh;
1364 MPT_SCSI_HOST *hd; 1364 MPT_SCSI_HOST *hd;
1365 MPT_ADAPTER *ioc; 1365 MPT_ADAPTER *ioc;
1366 unsigned long flags; 1366 unsigned long flags;
1367 int ii; 1367 int ii;
1368 int numSGE = 0; 1368 int numSGE = 0;
1369 int scale; 1369 int scale;
1370 int ioc_cap; 1370 int ioc_cap;
1371 int error=0; 1371 int error=0;
1372 int r; 1372 int r;
1373 1373
1374 if ((r = mpt_attach(pdev,id)) != 0) 1374 if ((r = mpt_attach(pdev,id)) != 0)
1375 return r; 1375 return r;
1376 1376
1377 ioc = pci_get_drvdata(pdev); 1377 ioc = pci_get_drvdata(pdev);
1378 ioc->DoneCtx = mptspiDoneCtx; 1378 ioc->DoneCtx = mptspiDoneCtx;
1379 ioc->TaskCtx = mptspiTaskCtx; 1379 ioc->TaskCtx = mptspiTaskCtx;
1380 ioc->InternalCtx = mptspiInternalCtx; 1380 ioc->InternalCtx = mptspiInternalCtx;
1381 1381
1382 /* Added sanity check on readiness of the MPT adapter. 1382 /* Added sanity check on readiness of the MPT adapter.
1383 */ 1383 */
1384 if (ioc->last_state != MPI_IOC_STATE_OPERATIONAL) { 1384 if (ioc->last_state != MPI_IOC_STATE_OPERATIONAL) {
1385 printk(MYIOC_s_WARN_FMT 1385 printk(MYIOC_s_WARN_FMT
1386 "Skipping because it's not operational!\n", 1386 "Skipping because it's not operational!\n",
1387 ioc->name); 1387 ioc->name);
1388 error = -ENODEV; 1388 error = -ENODEV;
1389 goto out_mptspi_probe; 1389 goto out_mptspi_probe;
1390 } 1390 }
1391 1391
1392 if (!ioc->active) { 1392 if (!ioc->active) {
1393 printk(MYIOC_s_WARN_FMT "Skipping because it's disabled!\n", 1393 printk(MYIOC_s_WARN_FMT "Skipping because it's disabled!\n",
1394 ioc->name); 1394 ioc->name);
1395 error = -ENODEV; 1395 error = -ENODEV;
1396 goto out_mptspi_probe; 1396 goto out_mptspi_probe;
1397 } 1397 }
1398 1398
1399 /* Sanity check - ensure at least 1 port is INITIATOR capable 1399 /* Sanity check - ensure at least 1 port is INITIATOR capable
1400 */ 1400 */
1401 ioc_cap = 0; 1401 ioc_cap = 0;
1402 for (ii=0; ii < ioc->facts.NumberOfPorts; ii++) { 1402 for (ii=0; ii < ioc->facts.NumberOfPorts; ii++) {
1403 if (ioc->pfacts[ii].ProtocolFlags & 1403 if (ioc->pfacts[ii].ProtocolFlags &
1404 MPI_PORTFACTS_PROTOCOL_INITIATOR) 1404 MPI_PORTFACTS_PROTOCOL_INITIATOR)
1405 ioc_cap ++; 1405 ioc_cap ++;
1406 } 1406 }
1407 1407
1408 if (!ioc_cap) { 1408 if (!ioc_cap) {
1409 printk(MYIOC_s_WARN_FMT 1409 printk(MYIOC_s_WARN_FMT
1410 "Skipping ioc=%p because SCSI Initiator mode is NOT enabled!\n", 1410 "Skipping ioc=%p because SCSI Initiator mode is NOT enabled!\n",
1411 ioc->name, ioc); 1411 ioc->name, ioc);
1412 return 0; 1412 return 0;
1413 } 1413 }
1414 1414
1415 sh = scsi_host_alloc(&mptspi_driver_template, sizeof(MPT_SCSI_HOST)); 1415 sh = scsi_host_alloc(&mptspi_driver_template, sizeof(MPT_SCSI_HOST));
1416 1416
1417 if (!sh) { 1417 if (!sh) {
1418 printk(MYIOC_s_WARN_FMT 1418 printk(MYIOC_s_WARN_FMT
1419 "Unable to register controller with SCSI subsystem\n", 1419 "Unable to register controller with SCSI subsystem\n",
1420 ioc->name); 1420 ioc->name);
1421 error = -1; 1421 error = -1;
1422 goto out_mptspi_probe; 1422 goto out_mptspi_probe;
1423 } 1423 }
1424 1424
1425 spin_lock_irqsave(&ioc->FreeQlock, flags); 1425 spin_lock_irqsave(&ioc->FreeQlock, flags);
1426 1426
1427 /* Attach the SCSI Host to the IOC structure 1427 /* Attach the SCSI Host to the IOC structure
1428 */ 1428 */
1429 ioc->sh = sh; 1429 ioc->sh = sh;
1430 1430
1431 sh->io_port = 0; 1431 sh->io_port = 0;
1432 sh->n_io_port = 0; 1432 sh->n_io_port = 0;
1433 sh->irq = 0; 1433 sh->irq = 0;
1434 1434
1435 /* set 16 byte cdb's */ 1435 /* set 16 byte cdb's */
1436 sh->max_cmd_len = 16; 1436 sh->max_cmd_len = 16;
1437 1437
1438 /* Yikes! This is important! 1438 /* Yikes! This is important!
1439 * Otherwise, by default, linux 1439 * Otherwise, by default, linux
1440 * only scans target IDs 0-7! 1440 * only scans target IDs 0-7!
1441 * pfactsN->MaxDevices unreliable 1441 * pfactsN->MaxDevices unreliable
1442 * (not supported in early 1442 * (not supported in early
1443 * versions of the FW). 1443 * versions of the FW).
1444 * max_id = 1 + actual max id, 1444 * max_id = 1 + actual max id,
1445 * max_lun = 1 + actual last lun, 1445 * max_lun = 1 + actual last lun,
1446 * see hosts.h :o( 1446 * see hosts.h :o(
1447 */ 1447 */
1448 sh->max_id = ioc->devices_per_bus; 1448 sh->max_id = ioc->devices_per_bus;
1449 1449
1450 sh->max_lun = MPT_LAST_LUN + 1; 1450 sh->max_lun = MPT_LAST_LUN + 1;
1451 /* 1451 /*
1452 * If RAID Firmware Detected, setup virtual channel 1452 * If RAID Firmware Detected, setup virtual channel
1453 */ 1453 */
1454 if (ioc->ir_firmware) 1454 if (ioc->ir_firmware)
1455 sh->max_channel = 1; 1455 sh->max_channel = 1;
1456 else 1456 else
1457 sh->max_channel = 0; 1457 sh->max_channel = 0;
1458 sh->this_id = ioc->pfacts[0].PortSCSIID; 1458 sh->this_id = ioc->pfacts[0].PortSCSIID;
1459 1459
1460 /* Required entry. 1460 /* Required entry.
1461 */ 1461 */
1462 sh->unique_id = ioc->id; 1462 sh->unique_id = ioc->id;
1463 1463
1464 /* Verify that we won't exceed the maximum 1464 /* Verify that we won't exceed the maximum
1465 * number of chain buffers 1465 * number of chain buffers
1466 * We can optimize: ZZ = req_sz/sizeof(SGE) 1466 * We can optimize: ZZ = req_sz/sizeof(SGE)
1467 * For 32bit SGE's: 1467 * For 32bit SGE's:
1468 * numSGE = 1 + (ZZ-1)*(maxChain -1) + ZZ 1468 * numSGE = 1 + (ZZ-1)*(maxChain -1) + ZZ
1469 * + (req_sz - 64)/sizeof(SGE) 1469 * + (req_sz - 64)/sizeof(SGE)
1470 * A slightly different algorithm is required for 1470 * A slightly different algorithm is required for
1471 * 64bit SGEs. 1471 * 64bit SGEs.
1472 */ 1472 */
1473 scale = ioc->req_sz/ioc->SGE_size; 1473 scale = ioc->req_sz/ioc->SGE_size;
1474 if (ioc->sg_addr_size == sizeof(u64)) { 1474 if (ioc->sg_addr_size == sizeof(u64)) {
1475 numSGE = (scale - 1) * 1475 numSGE = (scale - 1) *
1476 (ioc->facts.MaxChainDepth-1) + scale + 1476 (ioc->facts.MaxChainDepth-1) + scale +
1477 (ioc->req_sz - 60) / ioc->SGE_size; 1477 (ioc->req_sz - 60) / ioc->SGE_size;
1478 } else { 1478 } else {
1479 numSGE = 1 + (scale - 1) * 1479 numSGE = 1 + (scale - 1) *
1480 (ioc->facts.MaxChainDepth-1) + scale + 1480 (ioc->facts.MaxChainDepth-1) + scale +
1481 (ioc->req_sz - 64) / ioc->SGE_size; 1481 (ioc->req_sz - 64) / ioc->SGE_size;
1482 } 1482 }
1483 1483
1484 if (numSGE < sh->sg_tablesize) { 1484 if (numSGE < sh->sg_tablesize) {
1485 /* Reset this value */ 1485 /* Reset this value */
1486 dprintk(ioc, printk(MYIOC_s_DEBUG_FMT 1486 dprintk(ioc, printk(MYIOC_s_DEBUG_FMT
1487 "Resetting sg_tablesize to %d from %d\n", 1487 "Resetting sg_tablesize to %d from %d\n",
1488 ioc->name, numSGE, sh->sg_tablesize)); 1488 ioc->name, numSGE, sh->sg_tablesize));
1489 sh->sg_tablesize = numSGE; 1489 sh->sg_tablesize = numSGE;
1490 } 1490 }
1491 1491
1492 spin_unlock_irqrestore(&ioc->FreeQlock, flags); 1492 spin_unlock_irqrestore(&ioc->FreeQlock, flags);
1493 1493
1494 hd = shost_priv(sh); 1494 hd = shost_priv(sh);
1495 hd->ioc = ioc; 1495 hd->ioc = ioc;
1496 1496
1497 /* SCSI needs scsi_cmnd lookup table! 1497 /* SCSI needs scsi_cmnd lookup table!
1498 * (with size equal to req_depth*PtrSz!) 1498 * (with size equal to req_depth*PtrSz!)
1499 */ 1499 */
1500 ioc->ScsiLookup = kcalloc(ioc->req_depth, sizeof(void *), GFP_ATOMIC); 1500 ioc->ScsiLookup = kcalloc(ioc->req_depth, sizeof(void *), GFP_ATOMIC);
1501 if (!ioc->ScsiLookup) { 1501 if (!ioc->ScsiLookup) {
1502 error = -ENOMEM; 1502 error = -ENOMEM;
1503 goto out_mptspi_probe; 1503 goto out_mptspi_probe;
1504 } 1504 }
1505 spin_lock_init(&ioc->scsi_lookup_lock); 1505 spin_lock_init(&ioc->scsi_lookup_lock);
1506 1506
1507 dprintk(ioc, printk(MYIOC_s_DEBUG_FMT "ScsiLookup @ %p\n", 1507 dprintk(ioc, printk(MYIOC_s_DEBUG_FMT "ScsiLookup @ %p\n",
1508 ioc->name, ioc->ScsiLookup)); 1508 ioc->name, ioc->ScsiLookup));
1509 1509
1510 ioc->spi_data.Saf_Te = mpt_saf_te; 1510 ioc->spi_data.Saf_Te = mpt_saf_te;
1511 ddvprintk(ioc, printk(MYIOC_s_DEBUG_FMT 1511 ddvprintk(ioc, printk(MYIOC_s_DEBUG_FMT
1512 "saf_te %x\n", 1512 "saf_te %x\n",
1513 ioc->name, 1513 ioc->name,
1514 mpt_saf_te)); 1514 mpt_saf_te));
1515 ioc->spi_data.noQas = 0; 1515 ioc->spi_data.noQas = 0;
1516 1516
1517 hd->last_queue_full = 0; 1517 hd->last_queue_full = 0;
1518 hd->spi_pending = 0; 1518 hd->spi_pending = 0;
1519 1519
1520 /* Some versions of the firmware don't support page 0; without 1520 /* Some versions of the firmware don't support page 0; without
1521 * that we can't get the parameters */ 1521 * that we can't get the parameters */
1522 if (ioc->spi_data.sdp0length != 0) 1522 if (ioc->spi_data.sdp0length != 0)
1523 sh->transportt = mptspi_transport_template; 1523 sh->transportt = mptspi_transport_template;
1524 1524
1525 error = scsi_add_host (sh, &ioc->pcidev->dev); 1525 error = scsi_add_host (sh, &ioc->pcidev->dev);
1526 if(error) { 1526 if(error) {
1527 dprintk(ioc, printk(MYIOC_s_ERR_FMT 1527 dprintk(ioc, printk(MYIOC_s_ERR_FMT
1528 "scsi_add_host failed\n", ioc->name)); 1528 "scsi_add_host failed\n", ioc->name));
1529 goto out_mptspi_probe; 1529 goto out_mptspi_probe;
1530 } 1530 }
1531 1531
1532 /* 1532 /*
1533 * issue internal bus reset 1533 * issue internal bus reset
1534 */ 1534 */
1535 if (ioc->spi_data.bus_reset) 1535 if (ioc->spi_data.bus_reset)
1536 mptscsih_IssueTaskMgmt(hd, 1536 mptscsih_IssueTaskMgmt(hd,
1537 MPI_SCSITASKMGMT_TASKTYPE_RESET_BUS, 1537 MPI_SCSITASKMGMT_TASKTYPE_RESET_BUS,
1538 0, 0, 0, 0, 5); 1538 0, 0, 0, 0, 5);
1539 1539
1540 scsi_scan_host(sh); 1540 scsi_scan_host(sh);
1541 return 0; 1541 return 0;
1542 1542
1543 out_mptspi_probe: 1543 out_mptspi_probe:
1544 1544
1545 mptscsih_remove(pdev); 1545 mptscsih_remove(pdev);
1546 return error; 1546 return error;
1547 } 1547 }
1548 1548
1549 static struct pci_driver mptspi_driver = { 1549 static struct pci_driver mptspi_driver = {
1550 .name = "mptspi", 1550 .name = "mptspi",
1551 .id_table = mptspi_pci_table, 1551 .id_table = mptspi_pci_table,
1552 .probe = mptspi_probe, 1552 .probe = mptspi_probe,
1553 .remove = mptscsih_remove, 1553 .remove = mptscsih_remove,
1554 .shutdown = mptscsih_shutdown, 1554 .shutdown = mptscsih_shutdown,
1555 #ifdef CONFIG_PM 1555 #ifdef CONFIG_PM
1556 .suspend = mptscsih_suspend, 1556 .suspend = mptscsih_suspend,
1557 .resume = mptspi_resume, 1557 .resume = mptspi_resume,
1558 #endif 1558 #endif
1559 }; 1559 };
1560 1560
1561 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/ 1561 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
1562 /** 1562 /**
1563 * mptspi_init - Register MPT adapter(s) as SCSI host(s) with SCSI mid-layer. 1563 * mptspi_init - Register MPT adapter(s) as SCSI host(s) with SCSI mid-layer.
1564 * 1564 *
1565 * Returns 0 for success, non-zero for failure. 1565 * Returns 0 for success, non-zero for failure.
1566 */ 1566 */
1567 static int __init 1567 static int __init
1568 mptspi_init(void) 1568 mptspi_init(void)
1569 { 1569 {
1570 int error; 1570 int error;
1571 1571
1572 show_mptmod_ver(my_NAME, my_VERSION); 1572 show_mptmod_ver(my_NAME, my_VERSION);
1573 1573
1574 mptspi_transport_template = spi_attach_transport(&mptspi_transport_functions); 1574 mptspi_transport_template = spi_attach_transport(&mptspi_transport_functions);
1575 if (!mptspi_transport_template) 1575 if (!mptspi_transport_template)
1576 return -ENODEV; 1576 return -ENODEV;
1577 1577
1578 mptspiDoneCtx = mpt_register(mptscsih_io_done, MPTSPI_DRIVER, 1578 mptspiDoneCtx = mpt_register(mptscsih_io_done, MPTSPI_DRIVER,
1579 "mptscsih_io_done"); 1579 "mptscsih_io_done");
1580 mptspiTaskCtx = mpt_register(mptscsih_taskmgmt_complete, MPTSPI_DRIVER, 1580 mptspiTaskCtx = mpt_register(mptscsih_taskmgmt_complete, MPTSPI_DRIVER,
1581 "mptscsih_taskmgmt_complete"); 1581 "mptscsih_taskmgmt_complete");
1582 mptspiInternalCtx = mpt_register(mptscsih_scandv_complete, 1582 mptspiInternalCtx = mpt_register(mptscsih_scandv_complete,
1583 MPTSPI_DRIVER, "mptscsih_scandv_complete"); 1583 MPTSPI_DRIVER, "mptscsih_scandv_complete");
1584 1584
1585 mpt_event_register(mptspiDoneCtx, mptspi_event_process); 1585 mpt_event_register(mptspiDoneCtx, mptspi_event_process);
1586 mpt_reset_register(mptspiDoneCtx, mptspi_ioc_reset); 1586 mpt_reset_register(mptspiDoneCtx, mptspi_ioc_reset);
1587 1587
1588 error = pci_register_driver(&mptspi_driver); 1588 error = pci_register_driver(&mptspi_driver);
1589 if (error) 1589 if (error)
1590 spi_release_transport(mptspi_transport_template); 1590 spi_release_transport(mptspi_transport_template);
1591 1591
1592 return error; 1592 return error;
1593 } 1593 }
1594 1594
1595 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/ 1595 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
1596 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/ 1596 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
1597 /** 1597 /**
1598 * mptspi_exit - Unregisters MPT adapter(s) 1598 * mptspi_exit - Unregisters MPT adapter(s)
1599 */ 1599 */
1600 static void __exit 1600 static void __exit
1601 mptspi_exit(void) 1601 mptspi_exit(void)
1602 { 1602 {
1603 pci_unregister_driver(&mptspi_driver); 1603 pci_unregister_driver(&mptspi_driver);
1604 1604
1605 mpt_reset_deregister(mptspiDoneCtx); 1605 mpt_reset_deregister(mptspiDoneCtx);
1606 mpt_event_deregister(mptspiDoneCtx); 1606 mpt_event_deregister(mptspiDoneCtx);
1607 1607
1608 mpt_deregister(mptspiInternalCtx); 1608 mpt_deregister(mptspiInternalCtx);
1609 mpt_deregister(mptspiTaskCtx); 1609 mpt_deregister(mptspiTaskCtx);
1610 mpt_deregister(mptspiDoneCtx); 1610 mpt_deregister(mptspiDoneCtx);
1611 spi_release_transport(mptspi_transport_template); 1611 spi_release_transport(mptspi_transport_template);
1612 } 1612 }
1613 1613
1614 module_init(mptspi_init); 1614 module_init(mptspi_init);
1615 module_exit(mptspi_exit); 1615 module_exit(mptspi_exit);
1616 1616