blob: ef2b55e199105458bb8351d3ccfd118423feed18 [file] [log] [blame]
Moore, Eric Dean 2496af32005-04-22 18:02:41 -04001/*
2 * linux/drivers/message/fusion/mptfc.c
3 * For use with LSI Logic PCI chip/adapter(s)
4 * running LSI Logic Fusion MPT (Message Passing Technology) firmware.
5 *
6 * Copyright (c) 1999-2005 LSI Logic Corporation
7 * (mailto:mpt_linux_developer@lsil.com)
8 *
9 */
10/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
11/*
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
14 the Free Software Foundation; version 2 of the License.
15
16 This program is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 GNU General Public License for more details.
20
21 NO WARRANTY
22 THE PROGRAM IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR
23 CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT
24 LIMITATION, ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT,
25 MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Each Recipient is
26 solely responsible for determining the appropriateness of using and
27 distributing the Program and assumes all risks associated with its
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,
30 programs or equipment, and unavailability or interruption of operations.
31
32 DISCLAIMER OF LIABILITY
33 NEITHER RECIPIENT NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY
34 DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
35 DAMAGES (INCLUDING WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND
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
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
40
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
43 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
44*/
45/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
46#include "linux_compat.h" /* linux-2.6 tweaks */
47#include <linux/module.h>
48#include <linux/kernel.h>
49#include <linux/init.h>
50#include <linux/errno.h>
51#include <linux/kdev_t.h>
52#include <linux/blkdev.h>
53#include <linux/delay.h> /* for mdelay */
54#include <linux/interrupt.h> /* needed for in_interrupt() proto */
55#include <linux/reboot.h> /* notifier code */
56#include <linux/sched.h>
57#include <linux/workqueue.h>
Michael Reed05e8ec12006-01-13 14:31:54 -060058#include <linux/sort.h>
Moore, Eric Dean 2496af32005-04-22 18:02:41 -040059
60#include <scsi/scsi.h>
61#include <scsi/scsi_cmnd.h>
62#include <scsi/scsi_device.h>
63#include <scsi/scsi_host.h>
64#include <scsi/scsi_tcq.h>
Michael Reed05e8ec12006-01-13 14:31:54 -060065#include <scsi/scsi_transport_fc.h>
Moore, Eric Dean 2496af32005-04-22 18:02:41 -040066
67#include "mptbase.h"
68#include "mptscsih.h"
69
70/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
71#define my_NAME "Fusion MPT FC Host driver"
72#define my_VERSION MPT_LINUX_VERSION_COMMON
73#define MYNAM "mptfc"
74
75MODULE_AUTHOR(MODULEAUTHOR);
76MODULE_DESCRIPTION(my_NAME);
77MODULE_LICENSE("GPL");
78
79/* Command line args */
Michael Reed05e8ec12006-01-13 14:31:54 -060080#define MPTFC_DEV_LOSS_TMO (60)
81static int mptfc_dev_loss_tmo = MPTFC_DEV_LOSS_TMO; /* reasonable default */
82module_param(mptfc_dev_loss_tmo, int, 0);
83MODULE_PARM_DESC(mptfc_dev_loss_tmo, " Initial time the driver programs the "
84 " transport to wait for an rport to "
85 " return following a device loss event."
86 " Default=60.");
87
Moore, Eric Dean 2496af32005-04-22 18:02:41 -040088static int mptfcDoneCtx = -1;
89static int mptfcTaskCtx = -1;
90static int mptfcInternalCtx = -1; /* Used only for internal commands */
91
Michael Reed3bc7bf12006-01-25 18:05:18 -070092static int mptfc_target_alloc(struct scsi_target *starget);
93static int mptfc_slave_alloc(struct scsi_device *sdev);
Michael Reed05e8ec12006-01-13 14:31:54 -060094static int mptfc_qcmd(struct scsi_cmnd *SCpnt,
Michael Reed3bc7bf12006-01-25 18:05:18 -070095 void (*done)(struct scsi_cmnd *));
96static void mptfc_target_destroy(struct scsi_target *starget);
Michael Reed05e8ec12006-01-13 14:31:54 -060097static void mptfc_set_rport_loss_tmo(struct fc_rport *rport, uint32_t timeout);
98static void __devexit mptfc_remove(struct pci_dev *pdev);
Michael Reed35508e42006-10-06 15:39:25 -050099static int mptfc_abort(struct scsi_cmnd *SCpnt);
100static int mptfc_dev_reset(struct scsi_cmnd *SCpnt);
101static int mptfc_bus_reset(struct scsi_cmnd *SCpnt);
102static int mptfc_host_reset(struct scsi_cmnd *SCpnt);
Michael Reed05e8ec12006-01-13 14:31:54 -0600103
Moore, Eric Dean 2496af32005-04-22 18:02:41 -0400104static struct scsi_host_template mptfc_driver_template = {
Moore, Eric Deanf78496d2005-11-16 18:54:14 -0700105 .module = THIS_MODULE,
Moore, Eric Dean 2496af32005-04-22 18:02:41 -0400106 .proc_name = "mptfc",
107 .proc_info = mptscsih_proc_info,
108 .name = "MPT FC Host",
109 .info = mptscsih_info,
Michael Reed05e8ec12006-01-13 14:31:54 -0600110 .queuecommand = mptfc_qcmd,
Michael Reed3bc7bf12006-01-25 18:05:18 -0700111 .target_alloc = mptfc_target_alloc,
Michael Reed05e8ec12006-01-13 14:31:54 -0600112 .slave_alloc = mptfc_slave_alloc,
Moore, Eric Dean 2496af32005-04-22 18:02:41 -0400113 .slave_configure = mptscsih_slave_configure,
Michael Reed3bc7bf12006-01-25 18:05:18 -0700114 .target_destroy = mptfc_target_destroy,
Moore, Eric Dean 2496af32005-04-22 18:02:41 -0400115 .slave_destroy = mptscsih_slave_destroy,
Moore, Eric Dean6e3815b2005-06-24 12:18:57 -0600116 .change_queue_depth = mptscsih_change_queue_depth,
Michael Reed35508e42006-10-06 15:39:25 -0500117 .eh_abort_handler = mptfc_abort,
118 .eh_device_reset_handler = mptfc_dev_reset,
119 .eh_bus_reset_handler = mptfc_bus_reset,
120 .eh_host_reset_handler = mptfc_host_reset,
Moore, Eric Dean 2496af32005-04-22 18:02:41 -0400121 .bios_param = mptscsih_bios_param,
122 .can_queue = MPT_FC_CAN_QUEUE,
123 .this_id = -1,
124 .sg_tablesize = MPT_SCSI_SG_DEPTH,
125 .max_sectors = 8192,
126 .cmd_per_lun = 7,
127 .use_clustering = ENABLE_CLUSTERING,
Moore, Eric Dean 2496af32005-04-22 18:02:41 -0400128};
129
130/****************************************************************************
131 * Supported hardware
132 */
133
134static struct pci_device_id mptfc_pci_table[] = {
Eric Moore87cf8982006-06-27 16:09:26 -0600135 { PCI_VENDOR_ID_LSI_LOGIC, MPI_MANUFACTPAGE_DEVICEID_FC909,
Moore, Eric Dean 2496af32005-04-22 18:02:41 -0400136 PCI_ANY_ID, PCI_ANY_ID },
Eric Moore87cf8982006-06-27 16:09:26 -0600137 { PCI_VENDOR_ID_LSI_LOGIC, MPI_MANUFACTPAGE_DEVICEID_FC919,
Moore, Eric Dean 2496af32005-04-22 18:02:41 -0400138 PCI_ANY_ID, PCI_ANY_ID },
Eric Moore87cf8982006-06-27 16:09:26 -0600139 { PCI_VENDOR_ID_LSI_LOGIC, MPI_MANUFACTPAGE_DEVICEID_FC929,
Moore, Eric Dean 2496af32005-04-22 18:02:41 -0400140 PCI_ANY_ID, PCI_ANY_ID },
Eric Moore87cf8982006-06-27 16:09:26 -0600141 { PCI_VENDOR_ID_LSI_LOGIC, MPI_MANUFACTPAGE_DEVICEID_FC919X,
Moore, Eric Dean 2496af32005-04-22 18:02:41 -0400142 PCI_ANY_ID, PCI_ANY_ID },
Eric Moore87cf8982006-06-27 16:09:26 -0600143 { PCI_VENDOR_ID_LSI_LOGIC, MPI_MANUFACTPAGE_DEVICEID_FC929X,
Moore, Eric Dean 2496af32005-04-22 18:02:41 -0400144 PCI_ANY_ID, PCI_ANY_ID },
Eric Moore87cf8982006-06-27 16:09:26 -0600145 { PCI_VENDOR_ID_LSI_LOGIC, MPI_MANUFACTPAGE_DEVICEID_FC939X,
Moore, Eric Dean 3fadc592005-05-11 17:46:52 -0600146 PCI_ANY_ID, PCI_ANY_ID },
Eric Moore87cf8982006-06-27 16:09:26 -0600147 { PCI_VENDOR_ID_LSI_LOGIC, MPI_MANUFACTPAGE_DEVICEID_FC949X,
Moore, Eric Dean 3fadc592005-05-11 17:46:52 -0600148 PCI_ANY_ID, PCI_ANY_ID },
Eric Moore87cf8982006-06-27 16:09:26 -0600149 { PCI_VENDOR_ID_LSI_LOGIC, MPI_MANUFACTPAGE_DEVICEID_FC949E,
Moore, Eric6d5b0c32006-01-13 16:25:26 -0700150 PCI_ANY_ID, PCI_ANY_ID },
Moore, Eric Dean 2496af32005-04-22 18:02:41 -0400151 {0} /* Terminating entry */
152};
153MODULE_DEVICE_TABLE(pci, mptfc_pci_table);
154
Michael Reed05e8ec12006-01-13 14:31:54 -0600155static struct scsi_transport_template *mptfc_transport_template = NULL;
156
Adrian Bunk03fbcbc2006-01-25 02:00:52 +0100157static struct fc_function_template mptfc_transport_functions = {
Michael Reed05e8ec12006-01-13 14:31:54 -0600158 .dd_fcrport_size = 8,
159 .show_host_node_name = 1,
160 .show_host_port_name = 1,
161 .show_host_supported_classes = 1,
162 .show_host_port_id = 1,
163 .show_rport_supported_classes = 1,
164 .show_starget_node_name = 1,
165 .show_starget_port_name = 1,
166 .show_starget_port_id = 1,
167 .set_rport_dev_loss_tmo = mptfc_set_rport_loss_tmo,
168 .show_rport_dev_loss_tmo = 1,
Michael Reed5d947f22006-07-31 12:19:30 -0500169 .show_host_supported_speeds = 1,
170 .show_host_maxframe_size = 1,
171 .show_host_speed = 1,
172 .show_host_fabric_name = 1,
173 .show_host_port_type = 1,
174 .show_host_port_state = 1,
175 .show_host_symbolic_name = 1,
Michael Reed05e8ec12006-01-13 14:31:54 -0600176};
177
Michael Reed35508e42006-10-06 15:39:25 -0500178static int
179mptfc_block_error_handler(struct scsi_cmnd *SCpnt,
180 int (*func)(struct scsi_cmnd *SCpnt),
181 const char *caller)
182{
183 struct scsi_device *sdev = SCpnt->device;
184 struct Scsi_Host *shost = sdev->host;
185 struct fc_rport *rport = starget_to_rport(scsi_target(sdev));
186 unsigned long flags;
187 int ready;
188
189 spin_lock_irqsave(shost->host_lock, flags);
190 while ((ready = fc_remote_port_chkready(rport) >> 16) == DID_IMM_RETRY) {
191 spin_unlock_irqrestore(shost->host_lock, flags);
192 dfcprintk ((MYIOC_s_INFO_FMT
193 "mptfc_block_error_handler.%d: %d:%d, port status is "
194 "DID_IMM_RETRY, deferring %s recovery.\n",
195 ((MPT_SCSI_HOST *) shost->hostdata)->ioc->name,
196 ((MPT_SCSI_HOST *) shost->hostdata)->ioc->sh->host_no,
197 SCpnt->device->id,SCpnt->device->lun,caller));
198 msleep(1000);
199 spin_lock_irqsave(shost->host_lock, flags);
200 }
201 spin_unlock_irqrestore(shost->host_lock, flags);
202
203 if (ready == DID_NO_CONNECT || !SCpnt->device->hostdata) {
204 dfcprintk ((MYIOC_s_INFO_FMT
205 "%s.%d: %d:%d, failing recovery, "
206 "port state %d, vdev %p.\n", caller,
207 ((MPT_SCSI_HOST *) shost->hostdata)->ioc->name,
208 ((MPT_SCSI_HOST *) shost->hostdata)->ioc->sh->host_no,
209 SCpnt->device->id,SCpnt->device->lun,ready,
210 SCpnt->device->hostdata));
211 return FAILED;
212 }
213 dfcprintk ((MYIOC_s_INFO_FMT
214 "%s.%d: %d:%d, executing recovery.\n", caller,
215 ((MPT_SCSI_HOST *) shost->hostdata)->ioc->name,
216 ((MPT_SCSI_HOST *) shost->hostdata)->ioc->sh->host_no,
217 SCpnt->device->id,SCpnt->device->lun));
218 return (*func)(SCpnt);
219}
220
221static int
222mptfc_abort(struct scsi_cmnd *SCpnt)
223{
224 return
225 mptfc_block_error_handler(SCpnt, mptscsih_abort, __FUNCTION__);
226}
227
228static int
229mptfc_dev_reset(struct scsi_cmnd *SCpnt)
230{
231 return
232 mptfc_block_error_handler(SCpnt, mptscsih_dev_reset, __FUNCTION__);
233}
234
235static int
236mptfc_bus_reset(struct scsi_cmnd *SCpnt)
237{
238 return
239 mptfc_block_error_handler(SCpnt, mptscsih_bus_reset, __FUNCTION__);
240}
241
242static int
243mptfc_host_reset(struct scsi_cmnd *SCpnt)
244{
245 return
246 mptfc_block_error_handler(SCpnt, mptscsih_host_reset, __FUNCTION__);
247}
248
Michael Reed05e8ec12006-01-13 14:31:54 -0600249static void
250mptfc_set_rport_loss_tmo(struct fc_rport *rport, uint32_t timeout)
251{
252 if (timeout > 0)
253 rport->dev_loss_tmo = timeout;
254 else
255 rport->dev_loss_tmo = mptfc_dev_loss_tmo;
256}
257
258static int
259mptfc_FcDevPage0_cmp_func(const void *a, const void *b)
260{
261 FCDevicePage0_t **aa = (FCDevicePage0_t **)a;
262 FCDevicePage0_t **bb = (FCDevicePage0_t **)b;
263
264 if ((*aa)->CurrentBus == (*bb)->CurrentBus) {
265 if ((*aa)->CurrentTargetID == (*bb)->CurrentTargetID)
266 return 0;
267 if ((*aa)->CurrentTargetID < (*bb)->CurrentTargetID)
268 return -1;
269 return 1;
270 }
271 if ((*aa)->CurrentBus < (*bb)->CurrentBus)
272 return -1;
273 return 1;
274}
275
276static int
277mptfc_GetFcDevPage0(MPT_ADAPTER *ioc, int ioc_port,
278 void(*func)(MPT_ADAPTER *ioc,int channel, FCDevicePage0_t *arg))
279{
280 ConfigPageHeader_t hdr;
281 CONFIGPARMS cfg;
282 FCDevicePage0_t *ppage0_alloc, *fc;
283 dma_addr_t page0_dma;
284 int data_sz;
285 int ii;
286
287 FCDevicePage0_t *p0_array=NULL, *p_p0;
288 FCDevicePage0_t **pp0_array=NULL, **p_pp0;
289
290 int rc = -ENOMEM;
291 U32 port_id = 0xffffff;
292 int num_targ = 0;
293 int max_bus = ioc->facts.MaxBuses;
294 int max_targ = ioc->facts.MaxDevices;
295
296 if (max_bus == 0 || max_targ == 0)
297 goto out;
298
299 data_sz = sizeof(FCDevicePage0_t) * max_bus * max_targ;
300 p_p0 = p0_array = kzalloc(data_sz, GFP_KERNEL);
301 if (!p0_array)
302 goto out;
303
304 data_sz = sizeof(FCDevicePage0_t *) * max_bus * max_targ;
305 p_pp0 = pp0_array = kzalloc(data_sz, GFP_KERNEL);
306 if (!pp0_array)
307 goto out;
308
309 do {
310 /* Get FC Device Page 0 header */
311 hdr.PageVersion = 0;
312 hdr.PageLength = 0;
313 hdr.PageNumber = 0;
314 hdr.PageType = MPI_CONFIG_PAGETYPE_FC_DEVICE;
315 cfg.cfghdr.hdr = &hdr;
316 cfg.physAddr = -1;
317 cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
318 cfg.dir = 0;
319 cfg.pageAddr = port_id;
320 cfg.timeout = 0;
321
322 if ((rc = mpt_config(ioc, &cfg)) != 0)
323 break;
324
325 if (hdr.PageLength <= 0)
326 break;
327
328 data_sz = hdr.PageLength * 4;
329 ppage0_alloc = pci_alloc_consistent(ioc->pcidev, data_sz,
330 &page0_dma);
331 rc = -ENOMEM;
332 if (!ppage0_alloc)
333 break;
334
335 cfg.physAddr = page0_dma;
336 cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
337
338 if ((rc = mpt_config(ioc, &cfg)) == 0) {
339 ppage0_alloc->PortIdentifier =
340 le32_to_cpu(ppage0_alloc->PortIdentifier);
341
342 ppage0_alloc->WWNN.Low =
343 le32_to_cpu(ppage0_alloc->WWNN.Low);
344
345 ppage0_alloc->WWNN.High =
346 le32_to_cpu(ppage0_alloc->WWNN.High);
347
348 ppage0_alloc->WWPN.Low =
349 le32_to_cpu(ppage0_alloc->WWPN.Low);
350
351 ppage0_alloc->WWPN.High =
352 le32_to_cpu(ppage0_alloc->WWPN.High);
353
354 ppage0_alloc->BBCredit =
355 le16_to_cpu(ppage0_alloc->BBCredit);
356
357 ppage0_alloc->MaxRxFrameSize =
358 le16_to_cpu(ppage0_alloc->MaxRxFrameSize);
359
360 port_id = ppage0_alloc->PortIdentifier;
361 num_targ++;
362 *p_p0 = *ppage0_alloc; /* save data */
363 *p_pp0++ = p_p0++; /* save addr */
364 }
365 pci_free_consistent(ioc->pcidev, data_sz,
366 (u8 *) ppage0_alloc, page0_dma);
367 if (rc != 0)
368 break;
369
370 } while (port_id <= 0xff0000);
371
372 if (num_targ) {
373 /* sort array */
374 if (num_targ > 1)
375 sort (pp0_array, num_targ, sizeof(FCDevicePage0_t *),
376 mptfc_FcDevPage0_cmp_func, NULL);
377 /* call caller's func for each targ */
378 for (ii = 0; ii < num_targ; ii++) {
379 fc = *(pp0_array+ii);
380 func(ioc, ioc_port, fc);
381 }
382 }
383
384 out:
Jesper Juhl8f760782006-06-27 02:55:06 -0700385 kfree(pp0_array);
386 kfree(p0_array);
Michael Reed05e8ec12006-01-13 14:31:54 -0600387 return rc;
388}
389
390static int
391mptfc_generate_rport_ids(FCDevicePage0_t *pg0, struct fc_rport_identifiers *rid)
392{
393 /* not currently usable */
394 if (pg0->Flags & (MPI_FC_DEVICE_PAGE0_FLAGS_PLOGI_INVALID |
395 MPI_FC_DEVICE_PAGE0_FLAGS_PRLI_INVALID))
396 return -1;
397
398 if (!(pg0->Flags & MPI_FC_DEVICE_PAGE0_FLAGS_TARGETID_BUS_VALID))
399 return -1;
400
401 if (!(pg0->Protocol & MPI_FC_DEVICE_PAGE0_PROT_FCP_TARGET))
402 return -1;
403
404 /*
405 * board data structure already normalized to platform endianness
406 * shifted to avoid unaligned access on 64 bit architecture
407 */
408 rid->node_name = ((u64)pg0->WWNN.High) << 32 | (u64)pg0->WWNN.Low;
409 rid->port_name = ((u64)pg0->WWPN.High) << 32 | (u64)pg0->WWPN.Low;
410 rid->port_id = pg0->PortIdentifier;
411 rid->roles = FC_RPORT_ROLE_UNKNOWN;
Michael Reed05e8ec12006-01-13 14:31:54 -0600412
413 return 0;
414}
415
416static void
417mptfc_register_dev(MPT_ADAPTER *ioc, int channel, FCDevicePage0_t *pg0)
418{
419 struct fc_rport_identifiers rport_ids;
420 struct fc_rport *rport;
421 struct mptfc_rport_info *ri;
Michael Reed3bc7bf12006-01-25 18:05:18 -0700422 int new_ri = 1;
Moore, Eric65207fe2006-04-21 16:14:35 -0600423 u64 pn, nn;
Michael Reed3bc7bf12006-01-25 18:05:18 -0700424 VirtTarget *vtarget;
mdr@sgi.com6dd727d2006-05-01 13:07:04 -0500425 u32 roles = FC_RPORT_ROLE_UNKNOWN;
Michael Reed05e8ec12006-01-13 14:31:54 -0600426
427 if (mptfc_generate_rport_ids(pg0, &rport_ids) < 0)
428 return;
429
mdr@sgi.com6dd727d2006-05-01 13:07:04 -0500430 roles |= FC_RPORT_ROLE_FCP_TARGET;
431 if (pg0->Protocol & MPI_FC_DEVICE_PAGE0_PROT_FCP_INITIATOR)
432 roles |= FC_RPORT_ROLE_FCP_INITIATOR;
433
Michael Reed05e8ec12006-01-13 14:31:54 -0600434 /* scan list looking for a match */
Michael Reed05e8ec12006-01-13 14:31:54 -0600435 list_for_each_entry(ri, &ioc->fc_rports, list) {
Michael Reed3bc7bf12006-01-25 18:05:18 -0700436 pn = (u64)ri->pg0.WWPN.High << 32 | (u64)ri->pg0.WWPN.Low;
437 if (pn == rport_ids.port_name) { /* match */
Michael Reed05e8ec12006-01-13 14:31:54 -0600438 list_move_tail(&ri->list, &ioc->fc_rports);
Michael Reed3bc7bf12006-01-25 18:05:18 -0700439 new_ri = 0;
Michael Reed05e8ec12006-01-13 14:31:54 -0600440 break;
441 }
442 }
Michael Reed3bc7bf12006-01-25 18:05:18 -0700443 if (new_ri) { /* allocate one */
Michael Reed05e8ec12006-01-13 14:31:54 -0600444 ri = kzalloc(sizeof(struct mptfc_rport_info), GFP_KERNEL);
445 if (!ri)
446 return;
Michael Reed05e8ec12006-01-13 14:31:54 -0600447 list_add_tail(&ri->list, &ioc->fc_rports);
448 }
449
450 ri->pg0 = *pg0; /* add/update pg0 data */
451 ri->flags &= ~MPT_RPORT_INFO_FLAGS_MISSING;
452
Michael Reed3bc7bf12006-01-25 18:05:18 -0700453 /* MPT_RPORT_INFO_FLAGS_REGISTERED - rport not previously deleted */
Michael Reed05e8ec12006-01-13 14:31:54 -0600454 if (!(ri->flags & MPT_RPORT_INFO_FLAGS_REGISTERED)) {
455 ri->flags |= MPT_RPORT_INFO_FLAGS_REGISTERED;
Michael Reed3bc7bf12006-01-25 18:05:18 -0700456 rport = fc_remote_port_add(ioc->sh, channel, &rport_ids);
Michael Reed05e8ec12006-01-13 14:31:54 -0600457 if (rport) {
Michael Reed3bc7bf12006-01-25 18:05:18 -0700458 ri->rport = rport;
459 if (new_ri) /* may have been reset by user */
460 rport->dev_loss_tmo = mptfc_dev_loss_tmo;
Michael Reed05e8ec12006-01-13 14:31:54 -0600461 /*
462 * if already mapped, remap here. If not mapped,
Michael Reed3bc7bf12006-01-25 18:05:18 -0700463 * target_alloc will allocate vtarget and map,
464 * slave_alloc will fill in vdev from vtarget.
Michael Reed05e8ec12006-01-13 14:31:54 -0600465 */
Michael Reed3bc7bf12006-01-25 18:05:18 -0700466 if (ri->starget) {
467 vtarget = ri->starget->hostdata;
468 if (vtarget) {
469 vtarget->target_id = pg0->CurrentTargetID;
470 vtarget->bus_id = pg0->CurrentBus;
Michael Reed3bc7bf12006-01-25 18:05:18 -0700471 }
Michael Reed05e8ec12006-01-13 14:31:54 -0600472 }
Moore, Eric65207fe2006-04-21 16:14:35 -0600473 *((struct mptfc_rport_info **)rport->dd_data) = ri;
mdr@sgi.com6dd727d2006-05-01 13:07:04 -0500474 /* scan will be scheduled once rport becomes a target */
475 fc_remote_port_rolechg(rport,roles);
Moore, Eric65207fe2006-04-21 16:14:35 -0600476
477 pn = (u64)ri->pg0.WWPN.High << 32 | (u64)ri->pg0.WWPN.Low;
478 nn = (u64)ri->pg0.WWNN.High << 32 | (u64)ri->pg0.WWNN.Low;
Michael Reed3bc7bf12006-01-25 18:05:18 -0700479 dfcprintk ((MYIOC_s_INFO_FMT
480 "mptfc_reg_dev.%d: %x, %llx / %llx, tid %d, "
Michael Reed05e8ec12006-01-13 14:31:54 -0600481 "rport tid %d, tmo %d\n",
Michael Reed3bc7bf12006-01-25 18:05:18 -0700482 ioc->name,
Moore, Eric914c2d82006-03-14 09:19:36 -0700483 ioc->sh->host_no,
Michael Reed05e8ec12006-01-13 14:31:54 -0600484 pg0->PortIdentifier,
Moore, Eric65207fe2006-04-21 16:14:35 -0600485 (unsigned long long)nn,
486 (unsigned long long)pn,
Michael Reed05e8ec12006-01-13 14:31:54 -0600487 pg0->CurrentTargetID,
488 ri->rport->scsi_target_id,
Michael Reed3bc7bf12006-01-25 18:05:18 -0700489 ri->rport->dev_loss_tmo));
Michael Reed05e8ec12006-01-13 14:31:54 -0600490 } else {
491 list_del(&ri->list);
492 kfree(ri);
493 ri = NULL;
494 }
495 }
Michael Reed05e8ec12006-01-13 14:31:54 -0600496}
497
498/*
Michael Reed3bc7bf12006-01-25 18:05:18 -0700499 * OS entry point to allow for host driver to free allocated memory
500 * Called if no device present or device being unloaded
501 */
502static void
503mptfc_target_destroy(struct scsi_target *starget)
504{
505 struct fc_rport *rport;
506 struct mptfc_rport_info *ri;
507
508 rport = starget_to_rport(starget);
509 if (rport) {
510 ri = *((struct mptfc_rport_info **)rport->dd_data);
511 if (ri) /* better be! */
512 ri->starget = NULL;
513 }
514 if (starget->hostdata)
515 kfree(starget->hostdata);
516 starget->hostdata = NULL;
517}
518
519/*
520 * OS entry point to allow host driver to alloc memory
521 * for each scsi target. Called once per device the bus scan.
522 * Return non-zero if allocation fails.
523 */
524static int
525mptfc_target_alloc(struct scsi_target *starget)
526{
527 VirtTarget *vtarget;
528 struct fc_rport *rport;
529 struct mptfc_rport_info *ri;
530 int rc;
531
532 vtarget = kzalloc(sizeof(VirtTarget), GFP_KERNEL);
533 if (!vtarget)
534 return -ENOMEM;
535 starget->hostdata = vtarget;
536
537 rc = -ENODEV;
538 rport = starget_to_rport(starget);
539 if (rport) {
540 ri = *((struct mptfc_rport_info **)rport->dd_data);
541 if (ri) { /* better be! */
542 vtarget->target_id = ri->pg0.CurrentTargetID;
543 vtarget->bus_id = ri->pg0.CurrentBus;
544 ri->starget = starget;
Michael Reed3bc7bf12006-01-25 18:05:18 -0700545 rc = 0;
546 }
547 }
548 if (rc != 0) {
549 kfree(vtarget);
550 starget->hostdata = NULL;
551 }
552
553 return rc;
554}
555
556/*
Michael Reed05e8ec12006-01-13 14:31:54 -0600557 * OS entry point to allow host driver to alloc memory
558 * for each scsi device. Called once per device the bus scan.
559 * Return non-zero if allocation fails.
560 * Init memory once per LUN.
561 */
Adrian Bunk03fbcbc2006-01-25 02:00:52 +0100562static int
Michael Reed05e8ec12006-01-13 14:31:54 -0600563mptfc_slave_alloc(struct scsi_device *sdev)
564{
565 MPT_SCSI_HOST *hd;
566 VirtTarget *vtarget;
567 VirtDevice *vdev;
568 struct scsi_target *starget;
569 struct fc_rport *rport;
Michael Reed05e8ec12006-01-13 14:31:54 -0600570
571
Moore, Eric65207fe2006-04-21 16:14:35 -0600572 starget = scsi_target(sdev);
573 rport = starget_to_rport(starget);
Michael Reed05e8ec12006-01-13 14:31:54 -0600574
575 if (!rport || fc_remote_port_chkready(rport))
576 return -ENXIO;
577
578 hd = (MPT_SCSI_HOST *)sdev->host->hostdata;
579
Michael Reed3bc7bf12006-01-25 18:05:18 -0700580 vdev = kzalloc(sizeof(VirtDevice), GFP_KERNEL);
Michael Reed05e8ec12006-01-13 14:31:54 -0600581 if (!vdev) {
582 printk(MYIOC_s_ERR_FMT "slave_alloc kmalloc(%zd) FAILED!\n",
583 hd->ioc->name, sizeof(VirtDevice));
584 return -ENOMEM;
585 }
Michael Reed05e8ec12006-01-13 14:31:54 -0600586
Michael Reed05e8ec12006-01-13 14:31:54 -0600587
Michael Reed05e8ec12006-01-13 14:31:54 -0600588 sdev->hostdata = vdev;
Michael Reed05e8ec12006-01-13 14:31:54 -0600589 vtarget = starget->hostdata;
Michael Reed3bc7bf12006-01-25 18:05:18 -0700590
Michael Reed05e8ec12006-01-13 14:31:54 -0600591 if (vtarget->num_luns == 0) {
Michael Reed3bc7bf12006-01-25 18:05:18 -0700592 vtarget->ioc_id = hd->ioc->id;
Eric Mooreba856d32006-07-11 17:34:01 -0600593 vtarget->tflags = MPT_TARGET_FLAGS_Q_YES;
Michael Reed05e8ec12006-01-13 14:31:54 -0600594 hd->Targets[sdev->id] = vtarget;
595 }
596
Michael Reed05e8ec12006-01-13 14:31:54 -0600597 vdev->vtarget = vtarget;
Michael Reed05e8ec12006-01-13 14:31:54 -0600598 vdev->lun = sdev->lun;
Michael Reed05e8ec12006-01-13 14:31:54 -0600599
Michael Reed05e8ec12006-01-13 14:31:54 -0600600 vtarget->num_luns++;
601
Moore, Eric65207fe2006-04-21 16:14:35 -0600602
Moore, Eric914c2d82006-03-14 09:19:36 -0700603#ifdef DMPT_DEBUG_FC
Moore, Eric65207fe2006-04-21 16:14:35 -0600604 {
605 u64 nn, pn;
Moore, Eric914c2d82006-03-14 09:19:36 -0700606 struct mptfc_rport_info *ri;
607 ri = *((struct mptfc_rport_info **)rport->dd_data);
Moore, Eric65207fe2006-04-21 16:14:35 -0600608 pn = (u64)ri->pg0.WWPN.High << 32 | (u64)ri->pg0.WWPN.Low;
609 nn = (u64)ri->pg0.WWNN.High << 32 | (u64)ri->pg0.WWNN.Low;
Michael Reed3bc7bf12006-01-25 18:05:18 -0700610 dfcprintk ((MYIOC_s_INFO_FMT
611 "mptfc_slv_alloc.%d: num_luns %d, sdev.id %d, "
Michael Reed05e8ec12006-01-13 14:31:54 -0600612 "CurrentTargetID %d, %x %llx %llx\n",
Moore, Eric914c2d82006-03-14 09:19:36 -0700613 hd->ioc->name,
Michael Reed3bc7bf12006-01-25 18:05:18 -0700614 sdev->host->host_no,
615 vtarget->num_luns,
616 sdev->id, ri->pg0.CurrentTargetID,
Moore, Eric65207fe2006-04-21 16:14:35 -0600617 ri->pg0.PortIdentifier,
618 (unsigned long long)pn,
619 (unsigned long long)nn));
Moore, Eric914c2d82006-03-14 09:19:36 -0700620 }
621#endif
Michael Reed05e8ec12006-01-13 14:31:54 -0600622
623 return 0;
624}
625
626static int
627mptfc_qcmd(struct scsi_cmnd *SCpnt, void (*done)(struct scsi_cmnd *))
628{
Michael Reed3bc7bf12006-01-25 18:05:18 -0700629 struct mptfc_rport_info *ri;
Michael Reed05e8ec12006-01-13 14:31:54 -0600630 struct fc_rport *rport = starget_to_rport(scsi_target(SCpnt->device));
631 int err;
632
633 err = fc_remote_port_chkready(rport);
634 if (unlikely(err)) {
635 SCpnt->result = err;
636 done(SCpnt);
637 return 0;
638 }
Michael Reed3bc7bf12006-01-25 18:05:18 -0700639
Michael Reed35508e42006-10-06 15:39:25 -0500640 if (!SCpnt->device->hostdata) { /* vdev */
641 SCpnt->result = DID_NO_CONNECT << 16;
642 done(SCpnt);
643 return 0;
644 }
645
Moore, Eric65207fe2006-04-21 16:14:35 -0600646 /* dd_data is null until finished adding target */
647 ri = *((struct mptfc_rport_info **)rport->dd_data);
648 if (unlikely(!ri)) {
649 dfcprintk ((MYIOC_s_INFO_FMT
650 "mptfc_qcmd.%d: %d:%d, dd_data is null.\n",
651 ((MPT_SCSI_HOST *) SCpnt->device->host->hostdata)->ioc->name,
652 ((MPT_SCSI_HOST *) SCpnt->device->host->hostdata)->ioc->sh->host_no,
653 SCpnt->device->id,SCpnt->device->lun));
654 SCpnt->result = DID_IMM_RETRY << 16;
655 done(SCpnt);
656 return 0;
657 }
658
659 err = mptscsih_qcmd(SCpnt,done);
660#ifdef DMPT_DEBUG_FC
661 if (unlikely(err)) {
662 dfcprintk ((MYIOC_s_INFO_FMT
Michael Reed419835e2006-05-24 15:07:40 -0500663 "mptfc_qcmd.%d: %d:%d, mptscsih_qcmd returns non-zero, (%x).\n",
Moore, Eric65207fe2006-04-21 16:14:35 -0600664 ((MPT_SCSI_HOST *) SCpnt->device->host->hostdata)->ioc->name,
665 ((MPT_SCSI_HOST *) SCpnt->device->host->hostdata)->ioc->sh->host_no,
Michael Reed419835e2006-05-24 15:07:40 -0500666 SCpnt->device->id,SCpnt->device->lun,err));
Moore, Eric65207fe2006-04-21 16:14:35 -0600667 }
668#endif
669 return err;
Michael Reed05e8ec12006-01-13 14:31:54 -0600670}
671
Michael Reed80d3ac72006-05-24 15:07:09 -0500672/*
673 * mptfc_GetFcPortPage0 - Fetch FCPort config Page0.
674 * @ioc: Pointer to MPT_ADAPTER structure
675 * @portnum: IOC Port number
676 *
677 * Return: 0 for success
678 * -ENOMEM if no memory available
679 * -EPERM if not allowed due to ISR context
680 * -EAGAIN if no msg frames currently available
681 * -EFAULT for non-successful reply or no reply (timeout)
682 * -EINVAL portnum arg out of range (hardwired to two elements)
683 */
684static int
685mptfc_GetFcPortPage0(MPT_ADAPTER *ioc, int portnum)
686{
687 ConfigPageHeader_t hdr;
688 CONFIGPARMS cfg;
689 FCPortPage0_t *ppage0_alloc;
690 FCPortPage0_t *pp0dest;
691 dma_addr_t page0_dma;
692 int data_sz;
693 int copy_sz;
694 int rc;
695 int count = 400;
696
697 if (portnum > 1)
698 return -EINVAL;
699
700 /* Get FCPort Page 0 header */
701 hdr.PageVersion = 0;
702 hdr.PageLength = 0;
703 hdr.PageNumber = 0;
704 hdr.PageType = MPI_CONFIG_PAGETYPE_FC_PORT;
705 cfg.cfghdr.hdr = &hdr;
706 cfg.physAddr = -1;
707 cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
708 cfg.dir = 0;
709 cfg.pageAddr = portnum;
710 cfg.timeout = 0;
711
712 if ((rc = mpt_config(ioc, &cfg)) != 0)
713 return rc;
714
715 if (hdr.PageLength == 0)
716 return 0;
717
718 data_sz = hdr.PageLength * 4;
719 rc = -ENOMEM;
720 ppage0_alloc = (FCPortPage0_t *) pci_alloc_consistent(ioc->pcidev, data_sz, &page0_dma);
721 if (ppage0_alloc) {
722
723 try_again:
724 memset((u8 *)ppage0_alloc, 0, data_sz);
725 cfg.physAddr = page0_dma;
726 cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
727
728 if ((rc = mpt_config(ioc, &cfg)) == 0) {
729 /* save the data */
730 pp0dest = &ioc->fc_port_page0[portnum];
731 copy_sz = min_t(int, sizeof(FCPortPage0_t), data_sz);
732 memcpy(pp0dest, ppage0_alloc, copy_sz);
733
734 /*
735 * Normalize endianness of structure data,
736 * by byte-swapping all > 1 byte fields!
737 */
738 pp0dest->Flags = le32_to_cpu(pp0dest->Flags);
739 pp0dest->PortIdentifier = le32_to_cpu(pp0dest->PortIdentifier);
740 pp0dest->WWNN.Low = le32_to_cpu(pp0dest->WWNN.Low);
741 pp0dest->WWNN.High = le32_to_cpu(pp0dest->WWNN.High);
742 pp0dest->WWPN.Low = le32_to_cpu(pp0dest->WWPN.Low);
743 pp0dest->WWPN.High = le32_to_cpu(pp0dest->WWPN.High);
744 pp0dest->SupportedServiceClass = le32_to_cpu(pp0dest->SupportedServiceClass);
745 pp0dest->SupportedSpeeds = le32_to_cpu(pp0dest->SupportedSpeeds);
746 pp0dest->CurrentSpeed = le32_to_cpu(pp0dest->CurrentSpeed);
747 pp0dest->MaxFrameSize = le32_to_cpu(pp0dest->MaxFrameSize);
748 pp0dest->FabricWWNN.Low = le32_to_cpu(pp0dest->FabricWWNN.Low);
749 pp0dest->FabricWWNN.High = le32_to_cpu(pp0dest->FabricWWNN.High);
750 pp0dest->FabricWWPN.Low = le32_to_cpu(pp0dest->FabricWWPN.Low);
751 pp0dest->FabricWWPN.High = le32_to_cpu(pp0dest->FabricWWPN.High);
752 pp0dest->DiscoveredPortsCount = le32_to_cpu(pp0dest->DiscoveredPortsCount);
753 pp0dest->MaxInitiators = le32_to_cpu(pp0dest->MaxInitiators);
754
755 /*
756 * if still doing discovery,
757 * hang loose a while until finished
758 */
Michael Reed77d88ee2006-07-31 12:19:40 -0500759 if ((pp0dest->PortState == MPI_FCPORTPAGE0_PORTSTATE_UNKNOWN) ||
760 (pp0dest->PortState == MPI_FCPORTPAGE0_PORTSTATE_ONLINE &&
761 (pp0dest->Flags & MPI_FCPORTPAGE0_FLAGS_ATTACH_TYPE_MASK)
762 == MPI_FCPORTPAGE0_FLAGS_ATTACH_NO_INIT)) {
Michael Reed80d3ac72006-05-24 15:07:09 -0500763 if (count-- > 0) {
Michael Reedd6be06c2006-05-24 15:07:57 -0500764 msleep(100);
Michael Reed80d3ac72006-05-24 15:07:09 -0500765 goto try_again;
766 }
767 printk(MYIOC_s_INFO_FMT "Firmware discovery not"
768 " complete.\n",
769 ioc->name);
770 }
771 }
772
773 pci_free_consistent(ioc->pcidev, data_sz, (u8 *) ppage0_alloc, page0_dma);
774 }
775
776 return rc;
777}
778
Michael Reedca2f9382006-05-24 15:07:24 -0500779static int
780mptfc_WriteFcPortPage1(MPT_ADAPTER *ioc, int portnum)
781{
782 ConfigPageHeader_t hdr;
783 CONFIGPARMS cfg;
784 int rc;
785
786 if (portnum > 1)
787 return -EINVAL;
788
789 if (!(ioc->fc_data.fc_port_page1[portnum].data))
790 return -EINVAL;
791
792 /* get fcport page 1 header */
793 hdr.PageVersion = 0;
794 hdr.PageLength = 0;
795 hdr.PageNumber = 1;
796 hdr.PageType = MPI_CONFIG_PAGETYPE_FC_PORT;
797 cfg.cfghdr.hdr = &hdr;
798 cfg.physAddr = -1;
799 cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
800 cfg.dir = 0;
801 cfg.pageAddr = portnum;
802 cfg.timeout = 0;
803
804 if ((rc = mpt_config(ioc, &cfg)) != 0)
805 return rc;
806
807 if (hdr.PageLength == 0)
808 return -ENODEV;
809
810 if (hdr.PageLength*4 != ioc->fc_data.fc_port_page1[portnum].pg_sz)
811 return -EINVAL;
812
813 cfg.physAddr = ioc->fc_data.fc_port_page1[portnum].dma;
814 cfg.action = MPI_CONFIG_ACTION_PAGE_WRITE_CURRENT;
815 cfg.dir = 1;
816
817 rc = mpt_config(ioc, &cfg);
818
819 return rc;
820}
821
822static int
823mptfc_GetFcPortPage1(MPT_ADAPTER *ioc, int portnum)
824{
825 ConfigPageHeader_t hdr;
826 CONFIGPARMS cfg;
827 FCPortPage1_t *page1_alloc;
828 dma_addr_t page1_dma;
829 int data_sz;
830 int rc;
831
832 if (portnum > 1)
833 return -EINVAL;
834
835 /* get fcport page 1 header */
836 hdr.PageVersion = 0;
837 hdr.PageLength = 0;
838 hdr.PageNumber = 1;
839 hdr.PageType = MPI_CONFIG_PAGETYPE_FC_PORT;
840 cfg.cfghdr.hdr = &hdr;
841 cfg.physAddr = -1;
842 cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
843 cfg.dir = 0;
844 cfg.pageAddr = portnum;
845 cfg.timeout = 0;
846
847 if ((rc = mpt_config(ioc, &cfg)) != 0)
848 return rc;
849
850 if (hdr.PageLength == 0)
851 return -ENODEV;
852
853start_over:
854
855 if (ioc->fc_data.fc_port_page1[portnum].data == NULL) {
856 data_sz = hdr.PageLength * 4;
857 if (data_sz < sizeof(FCPortPage1_t))
858 data_sz = sizeof(FCPortPage1_t);
859
860 page1_alloc = (FCPortPage1_t *) pci_alloc_consistent(ioc->pcidev,
861 data_sz,
862 &page1_dma);
863 if (!page1_alloc)
864 return -ENOMEM;
865 }
866 else {
867 page1_alloc = ioc->fc_data.fc_port_page1[portnum].data;
868 page1_dma = ioc->fc_data.fc_port_page1[portnum].dma;
869 data_sz = ioc->fc_data.fc_port_page1[portnum].pg_sz;
870 if (hdr.PageLength * 4 > data_sz) {
871 ioc->fc_data.fc_port_page1[portnum].data = NULL;
872 pci_free_consistent(ioc->pcidev, data_sz, (u8 *)
873 page1_alloc, page1_dma);
874 goto start_over;
875 }
876 }
877
878 memset(page1_alloc,0,data_sz);
879
880 cfg.physAddr = page1_dma;
881 cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
882
883 if ((rc = mpt_config(ioc, &cfg)) == 0) {
884 ioc->fc_data.fc_port_page1[portnum].data = page1_alloc;
885 ioc->fc_data.fc_port_page1[portnum].pg_sz = data_sz;
886 ioc->fc_data.fc_port_page1[portnum].dma = page1_dma;
887 }
888 else {
889 ioc->fc_data.fc_port_page1[portnum].data = NULL;
890 pci_free_consistent(ioc->pcidev, data_sz, (u8 *)
891 page1_alloc, page1_dma);
892 }
893
894 return rc;
895}
896
897static void
898mptfc_SetFcPortPage1_defaults(MPT_ADAPTER *ioc)
899{
900 int ii;
901 FCPortPage1_t *pp1;
902
903 #define MPTFC_FW_DEVICE_TIMEOUT (1)
904 #define MPTFC_FW_IO_PEND_TIMEOUT (1)
905 #define ON_FLAGS (MPI_FCPORTPAGE1_FLAGS_IMMEDIATE_ERROR_REPLY)
906 #define OFF_FLAGS (MPI_FCPORTPAGE1_FLAGS_VERBOSE_RESCAN_EVENTS)
907
908 for (ii=0; ii<ioc->facts.NumberOfPorts; ii++) {
909 if (mptfc_GetFcPortPage1(ioc, ii) != 0)
910 continue;
911 pp1 = ioc->fc_data.fc_port_page1[ii].data;
912 if ((pp1->InitiatorDeviceTimeout == MPTFC_FW_DEVICE_TIMEOUT)
913 && (pp1->InitiatorIoPendTimeout == MPTFC_FW_IO_PEND_TIMEOUT)
914 && ((pp1->Flags & ON_FLAGS) == ON_FLAGS)
915 && ((pp1->Flags & OFF_FLAGS) == 0))
916 continue;
917 pp1->InitiatorDeviceTimeout = MPTFC_FW_DEVICE_TIMEOUT;
918 pp1->InitiatorIoPendTimeout = MPTFC_FW_IO_PEND_TIMEOUT;
919 pp1->Flags &= ~OFF_FLAGS;
920 pp1->Flags |= ON_FLAGS;
921 mptfc_WriteFcPortPage1(ioc, ii);
922 }
923}
924
925
Michael Reed05e8ec12006-01-13 14:31:54 -0600926static void
927mptfc_init_host_attr(MPT_ADAPTER *ioc,int portnum)
928{
Michael Reed5d947f22006-07-31 12:19:30 -0500929 unsigned class = 0;
930 unsigned cos = 0;
931 unsigned speed;
932 unsigned port_type;
933 unsigned port_state;
934 FCPortPage0_t *pp0;
935 struct Scsi_Host *sh;
936 char *sn;
Michael Reed05e8ec12006-01-13 14:31:54 -0600937
938 /* don't know what to do as only one scsi (fc) host was allocated */
939 if (portnum != 0)
940 return;
941
Michael Reed5d947f22006-07-31 12:19:30 -0500942 pp0 = &ioc->fc_port_page0[portnum];
943 sh = ioc->sh;
944
945 sn = fc_host_symbolic_name(sh);
946 snprintf(sn, FC_SYMBOLIC_NAME_SIZE, "%s %s%08xh",
947 ioc->prod_name,
948 MPT_FW_REV_MAGIC_ID_STRING,
949 ioc->facts.FWVersion.Word);
950
951 fc_host_tgtid_bind_type(sh) = FC_TGTID_BIND_BY_WWPN;
952
953 fc_host_maxframe_size(sh) = pp0->MaxFrameSize;
954
955 fc_host_node_name(sh) =
956 (u64)pp0->WWNN.High << 32 | (u64)pp0->WWNN.Low;
957
958 fc_host_port_name(sh) =
959 (u64)pp0->WWPN.High << 32 | (u64)pp0->WWPN.Low;
960
961 fc_host_port_id(sh) = pp0->PortIdentifier;
962
963 class = pp0->SupportedServiceClass;
Michael Reed05e8ec12006-01-13 14:31:54 -0600964 if (class & MPI_FCPORTPAGE0_SUPPORT_CLASS_1)
965 cos |= FC_COS_CLASS1;
966 if (class & MPI_FCPORTPAGE0_SUPPORT_CLASS_2)
967 cos |= FC_COS_CLASS2;
968 if (class & MPI_FCPORTPAGE0_SUPPORT_CLASS_3)
969 cos |= FC_COS_CLASS3;
Michael Reed5d947f22006-07-31 12:19:30 -0500970 fc_host_supported_classes(sh) = cos;
Michael Reed05e8ec12006-01-13 14:31:54 -0600971
Michael Reed5d947f22006-07-31 12:19:30 -0500972 if (pp0->CurrentSpeed == MPI_FCPORTPAGE0_CURRENT_SPEED_1GBIT)
973 speed = FC_PORTSPEED_1GBIT;
974 else if (pp0->CurrentSpeed == MPI_FCPORTPAGE0_CURRENT_SPEED_2GBIT)
975 speed = FC_PORTSPEED_2GBIT;
976 else if (pp0->CurrentSpeed == MPI_FCPORTPAGE0_CURRENT_SPEED_4GBIT)
977 speed = FC_PORTSPEED_4GBIT;
978 else if (pp0->CurrentSpeed == MPI_FCPORTPAGE0_CURRENT_SPEED_10GBIT)
979 speed = FC_PORTSPEED_10GBIT;
980 else
981 speed = FC_PORTSPEED_UNKNOWN;
982 fc_host_speed(sh) = speed;
Michael Reed05e8ec12006-01-13 14:31:54 -0600983
Michael Reed5d947f22006-07-31 12:19:30 -0500984 speed = 0;
985 if (pp0->SupportedSpeeds & MPI_FCPORTPAGE0_SUPPORT_1GBIT_SPEED)
986 speed |= FC_PORTSPEED_1GBIT;
987 if (pp0->SupportedSpeeds & MPI_FCPORTPAGE0_SUPPORT_2GBIT_SPEED)
988 speed |= FC_PORTSPEED_2GBIT;
989 if (pp0->SupportedSpeeds & MPI_FCPORTPAGE0_SUPPORT_4GBIT_SPEED)
990 speed |= FC_PORTSPEED_4GBIT;
991 if (pp0->SupportedSpeeds & MPI_FCPORTPAGE0_SUPPORT_10GBIT_SPEED)
992 speed |= FC_PORTSPEED_10GBIT;
993 fc_host_supported_speeds(sh) = speed;
Michael Reed05e8ec12006-01-13 14:31:54 -0600994
Michael Reed5d947f22006-07-31 12:19:30 -0500995 port_state = FC_PORTSTATE_UNKNOWN;
996 if (pp0->PortState == MPI_FCPORTPAGE0_PORTSTATE_ONLINE)
997 port_state = FC_PORTSTATE_ONLINE;
998 else if (pp0->PortState == MPI_FCPORTPAGE0_PORTSTATE_OFFLINE)
999 port_state = FC_PORTSTATE_LINKDOWN;
1000 fc_host_port_state(sh) = port_state;
Michael Reed05e8ec12006-01-13 14:31:54 -06001001
Michael Reed5d947f22006-07-31 12:19:30 -05001002 port_type = FC_PORTTYPE_UNKNOWN;
1003 if (pp0->Flags & MPI_FCPORTPAGE0_FLAGS_ATTACH_POINT_TO_POINT)
1004 port_type = FC_PORTTYPE_PTP;
1005 else if (pp0->Flags & MPI_FCPORTPAGE0_FLAGS_ATTACH_PRIVATE_LOOP)
1006 port_type = FC_PORTTYPE_LPORT;
1007 else if (pp0->Flags & MPI_FCPORTPAGE0_FLAGS_ATTACH_PUBLIC_LOOP)
1008 port_type = FC_PORTTYPE_NLPORT;
1009 else if (pp0->Flags & MPI_FCPORTPAGE0_FLAGS_ATTACH_FABRIC_DIRECT)
1010 port_type = FC_PORTTYPE_NPORT;
1011 fc_host_port_type(sh) = port_type;
Michael Reed05e8ec12006-01-13 14:31:54 -06001012
Michael Reed5d947f22006-07-31 12:19:30 -05001013 fc_host_fabric_name(sh) =
1014 (pp0->Flags & MPI_FCPORTPAGE0_FLAGS_FABRIC_WWN_VALID) ?
1015 (u64) pp0->FabricWWNN.High << 32 | (u64) pp0->FabricWWPN.Low :
1016 (u64)pp0->WWNN.High << 32 | (u64)pp0->WWNN.Low;
1017
Michael Reed05e8ec12006-01-13 14:31:54 -06001018}
1019
1020static void
David Howellsc4028952006-11-22 14:57:56 +00001021mptfc_setup_reset(struct work_struct *work)
Michael Reed419835e2006-05-24 15:07:40 -05001022{
David Howellsc4028952006-11-22 14:57:56 +00001023 MPT_ADAPTER *ioc =
1024 container_of(work, MPT_ADAPTER, fc_setup_reset_work);
Michael Reed419835e2006-05-24 15:07:40 -05001025 u64 pn;
1026 struct mptfc_rport_info *ri;
1027
1028 /* reset about to happen, delete (block) all rports */
1029 list_for_each_entry(ri, &ioc->fc_rports, list) {
1030 if (ri->flags & MPT_RPORT_INFO_FLAGS_REGISTERED) {
1031 ri->flags &= ~MPT_RPORT_INFO_FLAGS_REGISTERED;
1032 fc_remote_port_delete(ri->rport); /* won't sleep */
1033 ri->rport = NULL;
1034
1035 pn = (u64)ri->pg0.WWPN.High << 32 |
1036 (u64)ri->pg0.WWPN.Low;
1037 dfcprintk ((MYIOC_s_INFO_FMT
1038 "mptfc_setup_reset.%d: %llx deleted\n",
1039 ioc->name,
1040 ioc->sh->host_no,
1041 (unsigned long long)pn));
1042 }
1043 }
1044}
1045
1046static void
David Howellsc4028952006-11-22 14:57:56 +00001047mptfc_rescan_devices(struct work_struct *work)
Michael Reed05e8ec12006-01-13 14:31:54 -06001048{
David Howellsc4028952006-11-22 14:57:56 +00001049 MPT_ADAPTER *ioc =
1050 container_of(work, MPT_ADAPTER, fc_rescan_work);
Michael Reed05e8ec12006-01-13 14:31:54 -06001051 int ii;
Moore, Eric65207fe2006-04-21 16:14:35 -06001052 u64 pn;
Michael Reed05e8ec12006-01-13 14:31:54 -06001053 struct mptfc_rport_info *ri;
1054
Michael Reed3a0c56d2006-07-31 12:19:50 -05001055 /* start by tagging all ports as missing */
1056 list_for_each_entry(ri, &ioc->fc_rports, list) {
1057 if (ri->flags & MPT_RPORT_INFO_FLAGS_REGISTERED) {
1058 ri->flags |= MPT_RPORT_INFO_FLAGS_MISSING;
Michael Reed05e8ec12006-01-13 14:31:54 -06001059 }
Michael Reed3a0c56d2006-07-31 12:19:50 -05001060 }
Michael Reed05e8ec12006-01-13 14:31:54 -06001061
Michael Reed3a0c56d2006-07-31 12:19:50 -05001062 /*
1063 * now rescan devices known to adapter,
1064 * will reregister existing rports
1065 */
1066 for (ii=0; ii < ioc->facts.NumberOfPorts; ii++) {
1067 (void) mptfc_GetFcPortPage0(ioc, ii);
1068 mptfc_init_host_attr(ioc, ii); /* refresh */
1069 mptfc_GetFcDevPage0(ioc, ii, mptfc_register_dev);
1070 }
1071
1072 /* delete devices still missing */
1073 list_for_each_entry(ri, &ioc->fc_rports, list) {
1074 /* if newly missing, delete it */
1075 if (ri->flags & MPT_RPORT_INFO_FLAGS_MISSING) {
1076
1077 ri->flags &= ~(MPT_RPORT_INFO_FLAGS_REGISTERED|
1078 MPT_RPORT_INFO_FLAGS_MISSING);
1079 fc_remote_port_delete(ri->rport); /* won't sleep */
1080 ri->rport = NULL;
1081
1082 pn = (u64)ri->pg0.WWPN.High << 32 |
1083 (u64)ri->pg0.WWPN.Low;
1084 dfcprintk ((MYIOC_s_INFO_FMT
1085 "mptfc_rescan.%d: %llx deleted\n",
1086 ioc->name,
1087 ioc->sh->host_no,
1088 (unsigned long long)pn));
Michael Reed05e8ec12006-01-13 14:31:54 -06001089 }
Michael Reed3a0c56d2006-07-31 12:19:50 -05001090 }
Michael Reed05e8ec12006-01-13 14:31:54 -06001091}
1092
Moore, Eric Dean 2496af32005-04-22 18:02:41 -04001093static int
1094mptfc_probe(struct pci_dev *pdev, const struct pci_device_id *id)
1095{
1096 struct Scsi_Host *sh;
1097 MPT_SCSI_HOST *hd;
1098 MPT_ADAPTER *ioc;
1099 unsigned long flags;
Christoph Hellwig1ca00bb2006-01-13 18:27:50 +01001100 int ii;
Moore, Eric Dean 2496af32005-04-22 18:02:41 -04001101 int numSGE = 0;
1102 int scale;
1103 int ioc_cap;
Moore, Eric Dean 2496af32005-04-22 18:02:41 -04001104 int error=0;
1105 int r;
Michael Reed05e8ec12006-01-13 14:31:54 -06001106
Moore, Eric Dean 2496af32005-04-22 18:02:41 -04001107 if ((r = mpt_attach(pdev,id)) != 0)
1108 return r;
Michael Reed05e8ec12006-01-13 14:31:54 -06001109
Moore, Eric Dean 2496af32005-04-22 18:02:41 -04001110 ioc = pci_get_drvdata(pdev);
Moore, Eric Dean d335cc32005-04-30 17:09:38 -05001111 ioc->DoneCtx = mptfcDoneCtx;
1112 ioc->TaskCtx = mptfcTaskCtx;
1113 ioc->InternalCtx = mptfcInternalCtx;
Moore, Eric Dean 2496af32005-04-22 18:02:41 -04001114
1115 /* Added sanity check on readiness of the MPT adapter.
1116 */
1117 if (ioc->last_state != MPI_IOC_STATE_OPERATIONAL) {
1118 printk(MYIOC_s_WARN_FMT
1119 "Skipping because it's not operational!\n",
1120 ioc->name);
Moore, Eric Dean7acec1e2005-11-16 18:54:17 -07001121 error = -ENODEV;
1122 goto out_mptfc_probe;
Moore, Eric Dean 2496af32005-04-22 18:02:41 -04001123 }
1124
1125 if (!ioc->active) {
1126 printk(MYIOC_s_WARN_FMT "Skipping because it's disabled!\n",
1127 ioc->name);
Moore, Eric Dean7acec1e2005-11-16 18:54:17 -07001128 error = -ENODEV;
1129 goto out_mptfc_probe;
Moore, Eric Dean 2496af32005-04-22 18:02:41 -04001130 }
1131
1132 /* Sanity check - ensure at least 1 port is INITIATOR capable
1133 */
1134 ioc_cap = 0;
1135 for (ii=0; ii < ioc->facts.NumberOfPorts; ii++) {
1136 if (ioc->pfacts[ii].ProtocolFlags &
1137 MPI_PORTFACTS_PROTOCOL_INITIATOR)
1138 ioc_cap ++;
1139 }
1140
1141 if (!ioc_cap) {
1142 printk(MYIOC_s_WARN_FMT
1143 "Skipping ioc=%p because SCSI Initiator mode is NOT enabled!\n",
1144 ioc->name, ioc);
Michael Reed05e8ec12006-01-13 14:31:54 -06001145 return -ENODEV;
Moore, Eric Dean 2496af32005-04-22 18:02:41 -04001146 }
1147
1148 sh = scsi_host_alloc(&mptfc_driver_template, sizeof(MPT_SCSI_HOST));
1149
1150 if (!sh) {
1151 printk(MYIOC_s_WARN_FMT
1152 "Unable to register controller with SCSI subsystem\n",
1153 ioc->name);
Moore, Eric Dean7acec1e2005-11-16 18:54:17 -07001154 error = -1;
1155 goto out_mptfc_probe;
Moore, Eric Dean 2496af32005-04-22 18:02:41 -04001156 }
1157
Michael Reed80d3ac72006-05-24 15:07:09 -05001158 spin_lock_init(&ioc->fc_rescan_work_lock);
David Howellsc4028952006-11-22 14:57:56 +00001159 INIT_WORK(&ioc->fc_rescan_work, mptfc_rescan_devices);
1160 INIT_WORK(&ioc->fc_setup_reset_work, mptfc_setup_reset);
Michael Reed05e8ec12006-01-13 14:31:54 -06001161
Moore, Eric Dean 2496af32005-04-22 18:02:41 -04001162 spin_lock_irqsave(&ioc->FreeQlock, flags);
1163
1164 /* Attach the SCSI Host to the IOC structure
1165 */
1166 ioc->sh = sh;
1167
1168 sh->io_port = 0;
1169 sh->n_io_port = 0;
1170 sh->irq = 0;
1171
1172 /* set 16 byte cdb's */
1173 sh->max_cmd_len = 16;
1174
1175 sh->max_id = MPT_MAX_FC_DEVICES<256 ? MPT_MAX_FC_DEVICES : 255;
1176
1177 sh->max_lun = MPT_LAST_LUN + 1;
1178 sh->max_channel = 0;
1179 sh->this_id = ioc->pfacts[0].PortSCSIID;
1180
1181 /* Required entry.
1182 */
1183 sh->unique_id = ioc->id;
1184
1185 /* Verify that we won't exceed the maximum
1186 * number of chain buffers
1187 * We can optimize: ZZ = req_sz/sizeof(SGE)
1188 * For 32bit SGE's:
1189 * numSGE = 1 + (ZZ-1)*(maxChain -1) + ZZ
1190 * + (req_sz - 64)/sizeof(SGE)
1191 * A slightly different algorithm is required for
1192 * 64bit SGEs.
1193 */
1194 scale = ioc->req_sz/(sizeof(dma_addr_t) + sizeof(u32));
1195 if (sizeof(dma_addr_t) == sizeof(u64)) {
1196 numSGE = (scale - 1) *
1197 (ioc->facts.MaxChainDepth-1) + scale +
1198 (ioc->req_sz - 60) / (sizeof(dma_addr_t) +
1199 sizeof(u32));
1200 } else {
1201 numSGE = 1 + (scale - 1) *
1202 (ioc->facts.MaxChainDepth-1) + scale +
1203 (ioc->req_sz - 64) / (sizeof(dma_addr_t) +
1204 sizeof(u32));
1205 }
1206
1207 if (numSGE < sh->sg_tablesize) {
1208 /* Reset this value */
1209 dprintk((MYIOC_s_INFO_FMT
1210 "Resetting sg_tablesize to %d from %d\n",
1211 ioc->name, numSGE, sh->sg_tablesize));
1212 sh->sg_tablesize = numSGE;
1213 }
1214
Moore, Eric Dean 2496af32005-04-22 18:02:41 -04001215 spin_unlock_irqrestore(&ioc->FreeQlock, flags);
1216
1217 hd = (MPT_SCSI_HOST *) sh->hostdata;
1218 hd->ioc = ioc;
1219
1220 /* SCSI needs scsi_cmnd lookup table!
1221 * (with size equal to req_depth*PtrSz!)
1222 */
Christoph Hellwig1ca00bb2006-01-13 18:27:50 +01001223 hd->ScsiLookup = kcalloc(ioc->req_depth, sizeof(void *), GFP_ATOMIC);
1224 if (!hd->ScsiLookup) {
Moore, Eric Dean 2496af32005-04-22 18:02:41 -04001225 error = -ENOMEM;
Moore, Eric Dean7acec1e2005-11-16 18:54:17 -07001226 goto out_mptfc_probe;
Moore, Eric Dean 2496af32005-04-22 18:02:41 -04001227 }
1228
Christoph Hellwig1ca00bb2006-01-13 18:27:50 +01001229 dprintk((MYIOC_s_INFO_FMT "ScsiLookup @ %p\n",
1230 ioc->name, hd->ScsiLookup));
Moore, Eric Dean 2496af32005-04-22 18:02:41 -04001231
1232 /* Allocate memory for the device structures.
1233 * A non-Null pointer at an offset
1234 * indicates a device exists.
1235 * max_id = 1 + maximum id (hosts.h)
1236 */
Christoph Hellwig1ca00bb2006-01-13 18:27:50 +01001237 hd->Targets = kcalloc(sh->max_id, sizeof(void *), GFP_ATOMIC);
1238 if (!hd->Targets) {
Moore, Eric Dean 2496af32005-04-22 18:02:41 -04001239 error = -ENOMEM;
Moore, Eric Dean7acec1e2005-11-16 18:54:17 -07001240 goto out_mptfc_probe;
Moore, Eric Dean 2496af32005-04-22 18:02:41 -04001241 }
1242
Christoph Hellwig1ca00bb2006-01-13 18:27:50 +01001243 dprintk((KERN_INFO " vdev @ %p\n", hd->Targets));
Moore, Eric Dean 2496af32005-04-22 18:02:41 -04001244
1245 /* Clear the TM flags
1246 */
1247 hd->tmPending = 0;
1248 hd->tmState = TM_STATE_NONE;
1249 hd->resetPending = 0;
1250 hd->abortSCpnt = NULL;
1251
1252 /* Clear the pointer used to store
1253 * single-threaded commands, i.e., those
1254 * issued during a bus scan, dv and
1255 * configuration pages.
1256 */
1257 hd->cmdPtr = NULL;
1258
1259 /* Initialize this SCSI Hosts' timers
1260 * To use, set the timer expires field
1261 * and add_timer
1262 */
1263 init_timer(&hd->timer);
1264 hd->timer.data = (unsigned long) hd;
1265 hd->timer.function = mptscsih_timer_expired;
1266
Moore, Eric Dean 2496af32005-04-22 18:02:41 -04001267 init_waitqueue_head(&hd->scandv_waitq);
1268 hd->scandv_wait_done = 0;
1269 hd->last_queue_full = 0;
1270
Michael Reed05e8ec12006-01-13 14:31:54 -06001271 sh->transportt = mptfc_transport_template;
Moore, Eric Dean 2496af32005-04-22 18:02:41 -04001272 error = scsi_add_host (sh, &ioc->pcidev->dev);
1273 if(error) {
1274 dprintk((KERN_ERR MYNAM
1275 "scsi_add_host failed\n"));
Moore, Eric Dean7acec1e2005-11-16 18:54:17 -07001276 goto out_mptfc_probe;
Moore, Eric Dean 2496af32005-04-22 18:02:41 -04001277 }
1278
Moore, Eric65207fe2006-04-21 16:14:35 -06001279 /* initialize workqueue */
1280
1281 snprintf(ioc->fc_rescan_work_q_name, KOBJ_NAME_LEN, "mptfc_wq_%d",
1282 sh->host_no);
1283 ioc->fc_rescan_work_q =
1284 create_singlethread_workqueue(ioc->fc_rescan_work_q_name);
1285 if (!ioc->fc_rescan_work_q)
1286 goto out_mptfc_probe;
1287
1288 /*
Michael Reed80d3ac72006-05-24 15:07:09 -05001289 * Pre-fetch FC port WWN and stuff...
1290 * (FCPortPage0_t stuff)
1291 */
1292 for (ii=0; ii < ioc->facts.NumberOfPorts; ii++) {
1293 (void) mptfc_GetFcPortPage0(ioc, ii);
1294 }
Michael Reedca2f9382006-05-24 15:07:24 -05001295 mptfc_SetFcPortPage1_defaults(ioc);
Michael Reed80d3ac72006-05-24 15:07:09 -05001296
1297 /*
Moore, Eric65207fe2006-04-21 16:14:35 -06001298 * scan for rports -
1299 * by doing it via the workqueue, some locking is eliminated
1300 */
1301
Moore, Eric65207fe2006-04-21 16:14:35 -06001302 queue_work(ioc->fc_rescan_work_q, &ioc->fc_rescan_work);
1303 flush_workqueue(ioc->fc_rescan_work_q);
Michael Reed05e8ec12006-01-13 14:31:54 -06001304
Moore, Eric Dean 2496af32005-04-22 18:02:41 -04001305 return 0;
1306
Moore, Eric Dean7acec1e2005-11-16 18:54:17 -07001307out_mptfc_probe:
Moore, Eric Dean 2496af32005-04-22 18:02:41 -04001308
1309 mptscsih_remove(pdev);
1310 return error;
1311}
1312
1313static struct pci_driver mptfc_driver = {
1314 .name = "mptfc",
1315 .id_table = mptfc_pci_table,
1316 .probe = mptfc_probe,
Michael Reed05e8ec12006-01-13 14:31:54 -06001317 .remove = __devexit_p(mptfc_remove),
Greg Kroah-Hartmand18c3db2005-06-23 17:35:56 -07001318 .shutdown = mptscsih_shutdown,
Moore, Eric Dean 2496af32005-04-22 18:02:41 -04001319#ifdef CONFIG_PM
1320 .suspend = mptscsih_suspend,
1321 .resume = mptscsih_resume,
1322#endif
1323};
1324
Michael Reed80d3ac72006-05-24 15:07:09 -05001325static int
1326mptfc_event_process(MPT_ADAPTER *ioc, EventNotificationReply_t *pEvReply)
1327{
1328 MPT_SCSI_HOST *hd;
1329 u8 event = le32_to_cpu(pEvReply->Event) & 0xFF;
1330 unsigned long flags;
1331 int rc=1;
1332
1333 devtverboseprintk((MYIOC_s_INFO_FMT "MPT event (=%02Xh) routed to SCSI host driver!\n",
1334 ioc->name, event));
1335
1336 if (ioc->sh == NULL ||
1337 ((hd = (MPT_SCSI_HOST *)ioc->sh->hostdata) == NULL))
1338 return 1;
1339
1340 switch (event) {
1341 case MPI_EVENT_RESCAN:
1342 spin_lock_irqsave(&ioc->fc_rescan_work_lock, flags);
1343 if (ioc->fc_rescan_work_q) {
Michael Reed3a0c56d2006-07-31 12:19:50 -05001344 queue_work(ioc->fc_rescan_work_q,
1345 &ioc->fc_rescan_work);
Michael Reed80d3ac72006-05-24 15:07:09 -05001346 }
1347 spin_unlock_irqrestore(&ioc->fc_rescan_work_lock, flags);
1348 break;
1349 default:
1350 rc = mptscsih_event_process(ioc,pEvReply);
1351 break;
1352 }
1353 return rc;
1354}
1355
1356static int
1357mptfc_ioc_reset(MPT_ADAPTER *ioc, int reset_phase)
1358{
1359 int rc;
1360 unsigned long flags;
1361
1362 rc = mptscsih_ioc_reset(ioc,reset_phase);
1363 if (rc == 0)
1364 return rc;
1365
1366
1367 dtmprintk((KERN_WARNING MYNAM
1368 ": IOC %s_reset routed to FC host driver!\n",
1369 reset_phase==MPT_IOC_SETUP_RESET ? "setup" : (
1370 reset_phase==MPT_IOC_PRE_RESET ? "pre" : "post")));
1371
1372 if (reset_phase == MPT_IOC_SETUP_RESET) {
Michael Reed419835e2006-05-24 15:07:40 -05001373 spin_lock_irqsave(&ioc->fc_rescan_work_lock, flags);
1374 if (ioc->fc_rescan_work_q) {
1375 queue_work(ioc->fc_rescan_work_q,
1376 &ioc->fc_setup_reset_work);
1377 }
1378 spin_unlock_irqrestore(&ioc->fc_rescan_work_lock, flags);
Michael Reed80d3ac72006-05-24 15:07:09 -05001379 }
1380
1381 else if (reset_phase == MPT_IOC_PRE_RESET) {
1382 }
1383
1384 else { /* MPT_IOC_POST_RESET */
Michael Reedca2f9382006-05-24 15:07:24 -05001385 mptfc_SetFcPortPage1_defaults(ioc);
Michael Reed80d3ac72006-05-24 15:07:09 -05001386 spin_lock_irqsave(&ioc->fc_rescan_work_lock, flags);
1387 if (ioc->fc_rescan_work_q) {
Michael Reed3a0c56d2006-07-31 12:19:50 -05001388 queue_work(ioc->fc_rescan_work_q,
1389 &ioc->fc_rescan_work);
Michael Reed80d3ac72006-05-24 15:07:09 -05001390 }
1391 spin_unlock_irqrestore(&ioc->fc_rescan_work_lock, flags);
1392 }
1393 return 1;
1394}
1395
Moore, Eric Dean 2496af32005-04-22 18:02:41 -04001396/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
1397/**
1398 * mptfc_init - Register MPT adapter(s) as SCSI host(s) with
1399 * linux scsi mid-layer.
1400 *
1401 * Returns 0 for success, non-zero for failure.
1402 */
1403static int __init
1404mptfc_init(void)
1405{
Michael Reed05e8ec12006-01-13 14:31:54 -06001406 int error;
Moore, Eric Dean 2496af32005-04-22 18:02:41 -04001407
1408 show_mptmod_ver(my_NAME, my_VERSION);
1409
Michael Reedca2f9382006-05-24 15:07:24 -05001410 /* sanity check module parameters */
1411 if (mptfc_dev_loss_tmo <= 0)
Michael Reed05e8ec12006-01-13 14:31:54 -06001412 mptfc_dev_loss_tmo = MPTFC_DEV_LOSS_TMO;
1413
1414 mptfc_transport_template =
1415 fc_attach_transport(&mptfc_transport_functions);
1416
1417 if (!mptfc_transport_template)
1418 return -ENODEV;
1419
Moore, Eric Dean 2496af32005-04-22 18:02:41 -04001420 mptfcDoneCtx = mpt_register(mptscsih_io_done, MPTFC_DRIVER);
1421 mptfcTaskCtx = mpt_register(mptscsih_taskmgmt_complete, MPTFC_DRIVER);
1422 mptfcInternalCtx = mpt_register(mptscsih_scandv_complete, MPTFC_DRIVER);
1423
Michael Reed80d3ac72006-05-24 15:07:09 -05001424 if (mpt_event_register(mptfcDoneCtx, mptfc_event_process) == 0) {
Moore, Eric3a892be2006-03-14 09:14:03 -07001425 devtverboseprintk((KERN_INFO MYNAM
Moore, Eric Dean 2496af32005-04-22 18:02:41 -04001426 ": Registered for IOC event notifications\n"));
1427 }
1428
Michael Reed80d3ac72006-05-24 15:07:09 -05001429 if (mpt_reset_register(mptfcDoneCtx, mptfc_ioc_reset) == 0) {
Moore, Eric Dean 2496af32005-04-22 18:02:41 -04001430 dprintk((KERN_INFO MYNAM
1431 ": Registered for IOC reset notifications\n"));
1432 }
1433
Michael Reed05e8ec12006-01-13 14:31:54 -06001434 error = pci_register_driver(&mptfc_driver);
Michael Reed3bc7bf12006-01-25 18:05:18 -07001435 if (error)
Michael Reed05e8ec12006-01-13 14:31:54 -06001436 fc_release_transport(mptfc_transport_template);
Michael Reed05e8ec12006-01-13 14:31:54 -06001437
1438 return error;
1439}
1440
1441/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
1442/**
1443 * mptfc_remove - Removed fc infrastructure for devices
1444 * @pdev: Pointer to pci_dev structure
1445 *
1446 */
Michael Reed3bc7bf12006-01-25 18:05:18 -07001447static void __devexit
1448mptfc_remove(struct pci_dev *pdev)
Michael Reed05e8ec12006-01-13 14:31:54 -06001449{
Moore, Eric65207fe2006-04-21 16:14:35 -06001450 MPT_ADAPTER *ioc = pci_get_drvdata(pdev);
1451 struct mptfc_rport_info *p, *n;
1452 struct workqueue_struct *work_q;
1453 unsigned long flags;
Michael Reedca2f9382006-05-24 15:07:24 -05001454 int ii;
Moore, Eric65207fe2006-04-21 16:14:35 -06001455
1456 /* destroy workqueue */
1457 if ((work_q=ioc->fc_rescan_work_q)) {
1458 spin_lock_irqsave(&ioc->fc_rescan_work_lock, flags);
1459 ioc->fc_rescan_work_q = NULL;
1460 spin_unlock_irqrestore(&ioc->fc_rescan_work_lock, flags);
1461 destroy_workqueue(work_q);
1462 }
Michael Reed05e8ec12006-01-13 14:31:54 -06001463
1464 fc_remove_host(ioc->sh);
1465
1466 list_for_each_entry_safe(p, n, &ioc->fc_rports, list) {
1467 list_del(&p->list);
1468 kfree(p);
1469 }
1470
Michael Reedca2f9382006-05-24 15:07:24 -05001471 for (ii=0; ii<ioc->facts.NumberOfPorts; ii++) {
1472 if (ioc->fc_data.fc_port_page1[ii].data) {
1473 pci_free_consistent(ioc->pcidev,
1474 ioc->fc_data.fc_port_page1[ii].pg_sz,
1475 (u8 *) ioc->fc_data.fc_port_page1[ii].data,
1476 ioc->fc_data.fc_port_page1[ii].dma);
1477 ioc->fc_data.fc_port_page1[ii].data = NULL;
1478 }
1479 }
1480
Michael Reed05e8ec12006-01-13 14:31:54 -06001481 mptscsih_remove(pdev);
Moore, Eric Dean 2496af32005-04-22 18:02:41 -04001482}
1483
1484/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
1485/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
1486/**
1487 * mptfc_exit - Unregisters MPT adapter(s)
1488 *
1489 */
1490static void __exit
1491mptfc_exit(void)
1492{
1493 pci_unregister_driver(&mptfc_driver);
Michael Reed05e8ec12006-01-13 14:31:54 -06001494 fc_release_transport(mptfc_transport_template);
1495
Moore, Eric Dean 2496af32005-04-22 18:02:41 -04001496 mpt_reset_deregister(mptfcDoneCtx);
1497 dprintk((KERN_INFO MYNAM
1498 ": Deregistered for IOC reset notifications\n"));
1499
1500 mpt_event_deregister(mptfcDoneCtx);
1501 dprintk((KERN_INFO MYNAM
1502 ": Deregistered for IOC event notifications\n"));
1503
1504 mpt_deregister(mptfcInternalCtx);
1505 mpt_deregister(mptfcTaskCtx);
1506 mpt_deregister(mptfcDoneCtx);
1507}
1508
1509module_init(mptfc_init);
1510module_exit(mptfc_exit);