blob: cd8fa39ec2708ac888f30320bb641e062184c5f1 [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 *
Eric Moore9f4203b2007-01-04 20:47:47 -07006 * Copyright (c) 1999-2007 LSI Logic Corporation
Moore, Eric Dean 2496af32005-04-22 18:02:41 -04007 * (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");
Eric Moore9f4203b2007-01-04 20:47:47 -070078MODULE_VERSION(my_VERSION);
Moore, Eric Dean 2496af32005-04-22 18:02:41 -040079
80/* Command line args */
Michael Reed05e8ec12006-01-13 14:31:54 -060081#define MPTFC_DEV_LOSS_TMO (60)
82static int mptfc_dev_loss_tmo = MPTFC_DEV_LOSS_TMO; /* reasonable default */
83module_param(mptfc_dev_loss_tmo, int, 0);
84MODULE_PARM_DESC(mptfc_dev_loss_tmo, " Initial time the driver programs the "
85 " transport to wait for an rport to "
86 " return following a device loss event."
87 " Default=60.");
88
Eric Moore793955f2007-01-29 09:42:20 -070089/* scsi-mid layer global parmeter is max_report_luns, which is 511 */
90#define MPTFC_MAX_LUN (16895)
91static int max_lun = MPTFC_MAX_LUN;
92module_param(max_lun, int, 0);
93MODULE_PARM_DESC(max_lun, " max lun, default=16895 ");
94
Moore, Eric Dean 2496af32005-04-22 18:02:41 -040095static int mptfcDoneCtx = -1;
96static int mptfcTaskCtx = -1;
97static int mptfcInternalCtx = -1; /* Used only for internal commands */
98
Michael Reed3bc7bf12006-01-25 18:05:18 -070099static int mptfc_target_alloc(struct scsi_target *starget);
100static int mptfc_slave_alloc(struct scsi_device *sdev);
Michael Reed05e8ec12006-01-13 14:31:54 -0600101static int mptfc_qcmd(struct scsi_cmnd *SCpnt,
Michael Reed3bc7bf12006-01-25 18:05:18 -0700102 void (*done)(struct scsi_cmnd *));
103static void mptfc_target_destroy(struct scsi_target *starget);
Michael Reed05e8ec12006-01-13 14:31:54 -0600104static void mptfc_set_rport_loss_tmo(struct fc_rport *rport, uint32_t timeout);
105static void __devexit mptfc_remove(struct pci_dev *pdev);
Michael Reed35508e42006-10-06 15:39:25 -0500106static int mptfc_abort(struct scsi_cmnd *SCpnt);
107static int mptfc_dev_reset(struct scsi_cmnd *SCpnt);
108static int mptfc_bus_reset(struct scsi_cmnd *SCpnt);
109static int mptfc_host_reset(struct scsi_cmnd *SCpnt);
Michael Reed05e8ec12006-01-13 14:31:54 -0600110
Moore, Eric Dean 2496af32005-04-22 18:02:41 -0400111static struct scsi_host_template mptfc_driver_template = {
Moore, Eric Deanf78496d2005-11-16 18:54:14 -0700112 .module = THIS_MODULE,
Moore, Eric Dean 2496af32005-04-22 18:02:41 -0400113 .proc_name = "mptfc",
114 .proc_info = mptscsih_proc_info,
115 .name = "MPT FC Host",
116 .info = mptscsih_info,
Michael Reed05e8ec12006-01-13 14:31:54 -0600117 .queuecommand = mptfc_qcmd,
Michael Reed3bc7bf12006-01-25 18:05:18 -0700118 .target_alloc = mptfc_target_alloc,
Michael Reed05e8ec12006-01-13 14:31:54 -0600119 .slave_alloc = mptfc_slave_alloc,
Moore, Eric Dean 2496af32005-04-22 18:02:41 -0400120 .slave_configure = mptscsih_slave_configure,
Michael Reed3bc7bf12006-01-25 18:05:18 -0700121 .target_destroy = mptfc_target_destroy,
Moore, Eric Dean 2496af32005-04-22 18:02:41 -0400122 .slave_destroy = mptscsih_slave_destroy,
Moore, Eric Dean6e3815b2005-06-24 12:18:57 -0600123 .change_queue_depth = mptscsih_change_queue_depth,
Michael Reed35508e42006-10-06 15:39:25 -0500124 .eh_abort_handler = mptfc_abort,
125 .eh_device_reset_handler = mptfc_dev_reset,
126 .eh_bus_reset_handler = mptfc_bus_reset,
127 .eh_host_reset_handler = mptfc_host_reset,
Moore, Eric Dean 2496af32005-04-22 18:02:41 -0400128 .bios_param = mptscsih_bios_param,
129 .can_queue = MPT_FC_CAN_QUEUE,
130 .this_id = -1,
131 .sg_tablesize = MPT_SCSI_SG_DEPTH,
132 .max_sectors = 8192,
133 .cmd_per_lun = 7,
134 .use_clustering = ENABLE_CLUSTERING,
Moore, Eric Dean 2496af32005-04-22 18:02:41 -0400135};
136
137/****************************************************************************
138 * Supported hardware
139 */
140
141static struct pci_device_id mptfc_pci_table[] = {
Eric Moore87cf8982006-06-27 16:09:26 -0600142 { PCI_VENDOR_ID_LSI_LOGIC, MPI_MANUFACTPAGE_DEVICEID_FC909,
Moore, Eric Dean 2496af32005-04-22 18:02:41 -0400143 PCI_ANY_ID, PCI_ANY_ID },
Eric Moore87cf8982006-06-27 16:09:26 -0600144 { PCI_VENDOR_ID_LSI_LOGIC, MPI_MANUFACTPAGE_DEVICEID_FC919,
Moore, Eric Dean 2496af32005-04-22 18:02:41 -0400145 PCI_ANY_ID, PCI_ANY_ID },
Eric Moore87cf8982006-06-27 16:09:26 -0600146 { PCI_VENDOR_ID_LSI_LOGIC, MPI_MANUFACTPAGE_DEVICEID_FC929,
Moore, Eric Dean 2496af32005-04-22 18:02:41 -0400147 PCI_ANY_ID, PCI_ANY_ID },
Eric Moore87cf8982006-06-27 16:09:26 -0600148 { PCI_VENDOR_ID_LSI_LOGIC, MPI_MANUFACTPAGE_DEVICEID_FC919X,
Moore, Eric Dean 2496af32005-04-22 18:02:41 -0400149 PCI_ANY_ID, PCI_ANY_ID },
Eric Moore87cf8982006-06-27 16:09:26 -0600150 { PCI_VENDOR_ID_LSI_LOGIC, MPI_MANUFACTPAGE_DEVICEID_FC929X,
Moore, Eric Dean 2496af32005-04-22 18:02:41 -0400151 PCI_ANY_ID, PCI_ANY_ID },
Eric Moore87cf8982006-06-27 16:09:26 -0600152 { PCI_VENDOR_ID_LSI_LOGIC, MPI_MANUFACTPAGE_DEVICEID_FC939X,
Moore, Eric Dean 3fadc592005-05-11 17:46:52 -0600153 PCI_ANY_ID, PCI_ANY_ID },
Eric Moore87cf8982006-06-27 16:09:26 -0600154 { PCI_VENDOR_ID_LSI_LOGIC, MPI_MANUFACTPAGE_DEVICEID_FC949X,
Moore, Eric Dean 3fadc592005-05-11 17:46:52 -0600155 PCI_ANY_ID, PCI_ANY_ID },
Eric Moore87cf8982006-06-27 16:09:26 -0600156 { PCI_VENDOR_ID_LSI_LOGIC, MPI_MANUFACTPAGE_DEVICEID_FC949E,
Moore, Eric6d5b0c32006-01-13 16:25:26 -0700157 PCI_ANY_ID, PCI_ANY_ID },
Moore, Eric Dean 2496af32005-04-22 18:02:41 -0400158 {0} /* Terminating entry */
159};
160MODULE_DEVICE_TABLE(pci, mptfc_pci_table);
161
Michael Reed05e8ec12006-01-13 14:31:54 -0600162static struct scsi_transport_template *mptfc_transport_template = NULL;
163
Adrian Bunk03fbcbc2006-01-25 02:00:52 +0100164static struct fc_function_template mptfc_transport_functions = {
Michael Reed05e8ec12006-01-13 14:31:54 -0600165 .dd_fcrport_size = 8,
166 .show_host_node_name = 1,
167 .show_host_port_name = 1,
168 .show_host_supported_classes = 1,
169 .show_host_port_id = 1,
170 .show_rport_supported_classes = 1,
171 .show_starget_node_name = 1,
172 .show_starget_port_name = 1,
173 .show_starget_port_id = 1,
174 .set_rport_dev_loss_tmo = mptfc_set_rport_loss_tmo,
175 .show_rport_dev_loss_tmo = 1,
Michael Reed5d947f22006-07-31 12:19:30 -0500176 .show_host_supported_speeds = 1,
177 .show_host_maxframe_size = 1,
178 .show_host_speed = 1,
179 .show_host_fabric_name = 1,
180 .show_host_port_type = 1,
181 .show_host_port_state = 1,
182 .show_host_symbolic_name = 1,
Michael Reed05e8ec12006-01-13 14:31:54 -0600183};
184
Michael Reed35508e42006-10-06 15:39:25 -0500185static int
186mptfc_block_error_handler(struct scsi_cmnd *SCpnt,
187 int (*func)(struct scsi_cmnd *SCpnt),
188 const char *caller)
189{
190 struct scsi_device *sdev = SCpnt->device;
191 struct Scsi_Host *shost = sdev->host;
192 struct fc_rport *rport = starget_to_rport(scsi_target(sdev));
193 unsigned long flags;
194 int ready;
195
196 spin_lock_irqsave(shost->host_lock, flags);
197 while ((ready = fc_remote_port_chkready(rport) >> 16) == DID_IMM_RETRY) {
198 spin_unlock_irqrestore(shost->host_lock, flags);
199 dfcprintk ((MYIOC_s_INFO_FMT
200 "mptfc_block_error_handler.%d: %d:%d, port status is "
201 "DID_IMM_RETRY, deferring %s recovery.\n",
202 ((MPT_SCSI_HOST *) shost->hostdata)->ioc->name,
203 ((MPT_SCSI_HOST *) shost->hostdata)->ioc->sh->host_no,
204 SCpnt->device->id,SCpnt->device->lun,caller));
205 msleep(1000);
206 spin_lock_irqsave(shost->host_lock, flags);
207 }
208 spin_unlock_irqrestore(shost->host_lock, flags);
209
210 if (ready == DID_NO_CONNECT || !SCpnt->device->hostdata) {
211 dfcprintk ((MYIOC_s_INFO_FMT
212 "%s.%d: %d:%d, failing recovery, "
213 "port state %d, vdev %p.\n", caller,
214 ((MPT_SCSI_HOST *) shost->hostdata)->ioc->name,
215 ((MPT_SCSI_HOST *) shost->hostdata)->ioc->sh->host_no,
216 SCpnt->device->id,SCpnt->device->lun,ready,
217 SCpnt->device->hostdata));
218 return FAILED;
219 }
220 dfcprintk ((MYIOC_s_INFO_FMT
221 "%s.%d: %d:%d, executing recovery.\n", caller,
222 ((MPT_SCSI_HOST *) shost->hostdata)->ioc->name,
223 ((MPT_SCSI_HOST *) shost->hostdata)->ioc->sh->host_no,
224 SCpnt->device->id,SCpnt->device->lun));
225 return (*func)(SCpnt);
226}
227
228static int
229mptfc_abort(struct scsi_cmnd *SCpnt)
230{
231 return
232 mptfc_block_error_handler(SCpnt, mptscsih_abort, __FUNCTION__);
233}
234
235static int
236mptfc_dev_reset(struct scsi_cmnd *SCpnt)
237{
238 return
239 mptfc_block_error_handler(SCpnt, mptscsih_dev_reset, __FUNCTION__);
240}
241
242static int
243mptfc_bus_reset(struct scsi_cmnd *SCpnt)
244{
245 return
246 mptfc_block_error_handler(SCpnt, mptscsih_bus_reset, __FUNCTION__);
247}
248
249static int
250mptfc_host_reset(struct scsi_cmnd *SCpnt)
251{
252 return
253 mptfc_block_error_handler(SCpnt, mptscsih_host_reset, __FUNCTION__);
254}
255
Michael Reed05e8ec12006-01-13 14:31:54 -0600256static void
257mptfc_set_rport_loss_tmo(struct fc_rport *rport, uint32_t timeout)
258{
259 if (timeout > 0)
260 rport->dev_loss_tmo = timeout;
261 else
262 rport->dev_loss_tmo = mptfc_dev_loss_tmo;
263}
264
265static int
266mptfc_FcDevPage0_cmp_func(const void *a, const void *b)
267{
268 FCDevicePage0_t **aa = (FCDevicePage0_t **)a;
269 FCDevicePage0_t **bb = (FCDevicePage0_t **)b;
270
271 if ((*aa)->CurrentBus == (*bb)->CurrentBus) {
272 if ((*aa)->CurrentTargetID == (*bb)->CurrentTargetID)
273 return 0;
274 if ((*aa)->CurrentTargetID < (*bb)->CurrentTargetID)
275 return -1;
276 return 1;
277 }
278 if ((*aa)->CurrentBus < (*bb)->CurrentBus)
279 return -1;
280 return 1;
281}
282
283static int
284mptfc_GetFcDevPage0(MPT_ADAPTER *ioc, int ioc_port,
285 void(*func)(MPT_ADAPTER *ioc,int channel, FCDevicePage0_t *arg))
286{
287 ConfigPageHeader_t hdr;
288 CONFIGPARMS cfg;
289 FCDevicePage0_t *ppage0_alloc, *fc;
290 dma_addr_t page0_dma;
291 int data_sz;
292 int ii;
293
294 FCDevicePage0_t *p0_array=NULL, *p_p0;
295 FCDevicePage0_t **pp0_array=NULL, **p_pp0;
296
297 int rc = -ENOMEM;
298 U32 port_id = 0xffffff;
299 int num_targ = 0;
300 int max_bus = ioc->facts.MaxBuses;
Eric Moore793955f2007-01-29 09:42:20 -0700301 int max_targ;
Michael Reed05e8ec12006-01-13 14:31:54 -0600302
Eric Moore793955f2007-01-29 09:42:20 -0700303 max_targ = (ioc->facts.MaxDevices == 0) ? 256 : ioc->facts.MaxDevices;
Michael Reed05e8ec12006-01-13 14:31:54 -0600304
305 data_sz = sizeof(FCDevicePage0_t) * max_bus * max_targ;
306 p_p0 = p0_array = kzalloc(data_sz, GFP_KERNEL);
307 if (!p0_array)
308 goto out;
309
310 data_sz = sizeof(FCDevicePage0_t *) * max_bus * max_targ;
311 p_pp0 = pp0_array = kzalloc(data_sz, GFP_KERNEL);
312 if (!pp0_array)
313 goto out;
314
315 do {
316 /* Get FC Device Page 0 header */
317 hdr.PageVersion = 0;
318 hdr.PageLength = 0;
319 hdr.PageNumber = 0;
320 hdr.PageType = MPI_CONFIG_PAGETYPE_FC_DEVICE;
321 cfg.cfghdr.hdr = &hdr;
322 cfg.physAddr = -1;
323 cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
324 cfg.dir = 0;
325 cfg.pageAddr = port_id;
326 cfg.timeout = 0;
327
328 if ((rc = mpt_config(ioc, &cfg)) != 0)
329 break;
330
331 if (hdr.PageLength <= 0)
332 break;
333
334 data_sz = hdr.PageLength * 4;
335 ppage0_alloc = pci_alloc_consistent(ioc->pcidev, data_sz,
336 &page0_dma);
337 rc = -ENOMEM;
338 if (!ppage0_alloc)
339 break;
340
341 cfg.physAddr = page0_dma;
342 cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
343
344 if ((rc = mpt_config(ioc, &cfg)) == 0) {
345 ppage0_alloc->PortIdentifier =
346 le32_to_cpu(ppage0_alloc->PortIdentifier);
347
348 ppage0_alloc->WWNN.Low =
349 le32_to_cpu(ppage0_alloc->WWNN.Low);
350
351 ppage0_alloc->WWNN.High =
352 le32_to_cpu(ppage0_alloc->WWNN.High);
353
354 ppage0_alloc->WWPN.Low =
355 le32_to_cpu(ppage0_alloc->WWPN.Low);
356
357 ppage0_alloc->WWPN.High =
358 le32_to_cpu(ppage0_alloc->WWPN.High);
359
360 ppage0_alloc->BBCredit =
361 le16_to_cpu(ppage0_alloc->BBCredit);
362
363 ppage0_alloc->MaxRxFrameSize =
364 le16_to_cpu(ppage0_alloc->MaxRxFrameSize);
365
366 port_id = ppage0_alloc->PortIdentifier;
367 num_targ++;
368 *p_p0 = *ppage0_alloc; /* save data */
369 *p_pp0++ = p_p0++; /* save addr */
370 }
371 pci_free_consistent(ioc->pcidev, data_sz,
372 (u8 *) ppage0_alloc, page0_dma);
373 if (rc != 0)
374 break;
375
376 } while (port_id <= 0xff0000);
377
378 if (num_targ) {
379 /* sort array */
380 if (num_targ > 1)
381 sort (pp0_array, num_targ, sizeof(FCDevicePage0_t *),
382 mptfc_FcDevPage0_cmp_func, NULL);
383 /* call caller's func for each targ */
384 for (ii = 0; ii < num_targ; ii++) {
385 fc = *(pp0_array+ii);
386 func(ioc, ioc_port, fc);
387 }
388 }
389
390 out:
Jesper Juhl8f760782006-06-27 02:55:06 -0700391 kfree(pp0_array);
392 kfree(p0_array);
Michael Reed05e8ec12006-01-13 14:31:54 -0600393 return rc;
394}
395
396static int
397mptfc_generate_rport_ids(FCDevicePage0_t *pg0, struct fc_rport_identifiers *rid)
398{
399 /* not currently usable */
400 if (pg0->Flags & (MPI_FC_DEVICE_PAGE0_FLAGS_PLOGI_INVALID |
401 MPI_FC_DEVICE_PAGE0_FLAGS_PRLI_INVALID))
402 return -1;
403
404 if (!(pg0->Flags & MPI_FC_DEVICE_PAGE0_FLAGS_TARGETID_BUS_VALID))
405 return -1;
406
407 if (!(pg0->Protocol & MPI_FC_DEVICE_PAGE0_PROT_FCP_TARGET))
408 return -1;
409
410 /*
411 * board data structure already normalized to platform endianness
412 * shifted to avoid unaligned access on 64 bit architecture
413 */
414 rid->node_name = ((u64)pg0->WWNN.High) << 32 | (u64)pg0->WWNN.Low;
415 rid->port_name = ((u64)pg0->WWPN.High) << 32 | (u64)pg0->WWPN.Low;
416 rid->port_id = pg0->PortIdentifier;
417 rid->roles = FC_RPORT_ROLE_UNKNOWN;
Michael Reed05e8ec12006-01-13 14:31:54 -0600418
419 return 0;
420}
421
422static void
423mptfc_register_dev(MPT_ADAPTER *ioc, int channel, FCDevicePage0_t *pg0)
424{
425 struct fc_rport_identifiers rport_ids;
426 struct fc_rport *rport;
427 struct mptfc_rport_info *ri;
Michael Reed3bc7bf12006-01-25 18:05:18 -0700428 int new_ri = 1;
Moore, Eric65207fe2006-04-21 16:14:35 -0600429 u64 pn, nn;
Michael Reed3bc7bf12006-01-25 18:05:18 -0700430 VirtTarget *vtarget;
mdr@sgi.com6dd727d2006-05-01 13:07:04 -0500431 u32 roles = FC_RPORT_ROLE_UNKNOWN;
Michael Reed05e8ec12006-01-13 14:31:54 -0600432
433 if (mptfc_generate_rport_ids(pg0, &rport_ids) < 0)
434 return;
435
mdr@sgi.com6dd727d2006-05-01 13:07:04 -0500436 roles |= FC_RPORT_ROLE_FCP_TARGET;
437 if (pg0->Protocol & MPI_FC_DEVICE_PAGE0_PROT_FCP_INITIATOR)
438 roles |= FC_RPORT_ROLE_FCP_INITIATOR;
439
Michael Reed05e8ec12006-01-13 14:31:54 -0600440 /* scan list looking for a match */
Michael Reed05e8ec12006-01-13 14:31:54 -0600441 list_for_each_entry(ri, &ioc->fc_rports, list) {
Michael Reed3bc7bf12006-01-25 18:05:18 -0700442 pn = (u64)ri->pg0.WWPN.High << 32 | (u64)ri->pg0.WWPN.Low;
443 if (pn == rport_ids.port_name) { /* match */
Michael Reed05e8ec12006-01-13 14:31:54 -0600444 list_move_tail(&ri->list, &ioc->fc_rports);
Michael Reed3bc7bf12006-01-25 18:05:18 -0700445 new_ri = 0;
Michael Reed05e8ec12006-01-13 14:31:54 -0600446 break;
447 }
448 }
Michael Reed3bc7bf12006-01-25 18:05:18 -0700449 if (new_ri) { /* allocate one */
Michael Reed05e8ec12006-01-13 14:31:54 -0600450 ri = kzalloc(sizeof(struct mptfc_rport_info), GFP_KERNEL);
451 if (!ri)
452 return;
Michael Reed05e8ec12006-01-13 14:31:54 -0600453 list_add_tail(&ri->list, &ioc->fc_rports);
454 }
455
456 ri->pg0 = *pg0; /* add/update pg0 data */
457 ri->flags &= ~MPT_RPORT_INFO_FLAGS_MISSING;
458
Michael Reed3bc7bf12006-01-25 18:05:18 -0700459 /* MPT_RPORT_INFO_FLAGS_REGISTERED - rport not previously deleted */
Michael Reed05e8ec12006-01-13 14:31:54 -0600460 if (!(ri->flags & MPT_RPORT_INFO_FLAGS_REGISTERED)) {
461 ri->flags |= MPT_RPORT_INFO_FLAGS_REGISTERED;
Michael Reed3bc7bf12006-01-25 18:05:18 -0700462 rport = fc_remote_port_add(ioc->sh, channel, &rport_ids);
Michael Reed05e8ec12006-01-13 14:31:54 -0600463 if (rport) {
Michael Reed3bc7bf12006-01-25 18:05:18 -0700464 ri->rport = rport;
465 if (new_ri) /* may have been reset by user */
466 rport->dev_loss_tmo = mptfc_dev_loss_tmo;
Michael Reed05e8ec12006-01-13 14:31:54 -0600467 /*
468 * if already mapped, remap here. If not mapped,
Michael Reed3bc7bf12006-01-25 18:05:18 -0700469 * target_alloc will allocate vtarget and map,
470 * slave_alloc will fill in vdev from vtarget.
Michael Reed05e8ec12006-01-13 14:31:54 -0600471 */
Michael Reed3bc7bf12006-01-25 18:05:18 -0700472 if (ri->starget) {
473 vtarget = ri->starget->hostdata;
474 if (vtarget) {
Eric Moore793955f2007-01-29 09:42:20 -0700475 vtarget->id = pg0->CurrentTargetID;
476 vtarget->channel = pg0->CurrentBus;
Michael Reed3bc7bf12006-01-25 18:05:18 -0700477 }
Michael Reed05e8ec12006-01-13 14:31:54 -0600478 }
Moore, Eric65207fe2006-04-21 16:14:35 -0600479 *((struct mptfc_rport_info **)rport->dd_data) = ri;
mdr@sgi.com6dd727d2006-05-01 13:07:04 -0500480 /* scan will be scheduled once rport becomes a target */
481 fc_remote_port_rolechg(rport,roles);
Moore, Eric65207fe2006-04-21 16:14:35 -0600482
483 pn = (u64)ri->pg0.WWPN.High << 32 | (u64)ri->pg0.WWPN.Low;
484 nn = (u64)ri->pg0.WWNN.High << 32 | (u64)ri->pg0.WWNN.Low;
Michael Reed3bc7bf12006-01-25 18:05:18 -0700485 dfcprintk ((MYIOC_s_INFO_FMT
486 "mptfc_reg_dev.%d: %x, %llx / %llx, tid %d, "
Michael Reed05e8ec12006-01-13 14:31:54 -0600487 "rport tid %d, tmo %d\n",
Michael Reed3bc7bf12006-01-25 18:05:18 -0700488 ioc->name,
Moore, Eric914c2d82006-03-14 09:19:36 -0700489 ioc->sh->host_no,
Michael Reed05e8ec12006-01-13 14:31:54 -0600490 pg0->PortIdentifier,
Moore, Eric65207fe2006-04-21 16:14:35 -0600491 (unsigned long long)nn,
492 (unsigned long long)pn,
Michael Reed05e8ec12006-01-13 14:31:54 -0600493 pg0->CurrentTargetID,
494 ri->rport->scsi_target_id,
Michael Reed3bc7bf12006-01-25 18:05:18 -0700495 ri->rport->dev_loss_tmo));
Michael Reed05e8ec12006-01-13 14:31:54 -0600496 } else {
497 list_del(&ri->list);
498 kfree(ri);
499 ri = NULL;
500 }
501 }
Michael Reed05e8ec12006-01-13 14:31:54 -0600502}
503
504/*
Michael Reed3bc7bf12006-01-25 18:05:18 -0700505 * OS entry point to allow for host driver to free allocated memory
506 * Called if no device present or device being unloaded
507 */
508static void
509mptfc_target_destroy(struct scsi_target *starget)
510{
511 struct fc_rport *rport;
512 struct mptfc_rport_info *ri;
513
514 rport = starget_to_rport(starget);
515 if (rport) {
516 ri = *((struct mptfc_rport_info **)rport->dd_data);
517 if (ri) /* better be! */
518 ri->starget = NULL;
519 }
520 if (starget->hostdata)
521 kfree(starget->hostdata);
522 starget->hostdata = NULL;
523}
524
525/*
526 * OS entry point to allow host driver to alloc memory
527 * for each scsi target. Called once per device the bus scan.
528 * Return non-zero if allocation fails.
529 */
530static int
531mptfc_target_alloc(struct scsi_target *starget)
532{
533 VirtTarget *vtarget;
534 struct fc_rport *rport;
535 struct mptfc_rport_info *ri;
536 int rc;
537
538 vtarget = kzalloc(sizeof(VirtTarget), GFP_KERNEL);
539 if (!vtarget)
540 return -ENOMEM;
541 starget->hostdata = vtarget;
542
543 rc = -ENODEV;
544 rport = starget_to_rport(starget);
545 if (rport) {
546 ri = *((struct mptfc_rport_info **)rport->dd_data);
547 if (ri) { /* better be! */
Eric Moore793955f2007-01-29 09:42:20 -0700548 vtarget->id = ri->pg0.CurrentTargetID;
549 vtarget->channel = ri->pg0.CurrentBus;
Michael Reed3bc7bf12006-01-25 18:05:18 -0700550 ri->starget = starget;
Michael Reed3bc7bf12006-01-25 18:05:18 -0700551 rc = 0;
552 }
553 }
554 if (rc != 0) {
555 kfree(vtarget);
556 starget->hostdata = NULL;
557 }
558
559 return rc;
560}
561
562/*
Michael Reed05e8ec12006-01-13 14:31:54 -0600563 * OS entry point to allow host driver to alloc memory
564 * for each scsi device. Called once per device the bus scan.
565 * Return non-zero if allocation fails.
566 * Init memory once per LUN.
567 */
Adrian Bunk03fbcbc2006-01-25 02:00:52 +0100568static int
Michael Reed05e8ec12006-01-13 14:31:54 -0600569mptfc_slave_alloc(struct scsi_device *sdev)
570{
571 MPT_SCSI_HOST *hd;
572 VirtTarget *vtarget;
573 VirtDevice *vdev;
574 struct scsi_target *starget;
575 struct fc_rport *rport;
Michael Reed05e8ec12006-01-13 14:31:54 -0600576
577
Moore, Eric65207fe2006-04-21 16:14:35 -0600578 starget = scsi_target(sdev);
579 rport = starget_to_rport(starget);
Michael Reed05e8ec12006-01-13 14:31:54 -0600580
581 if (!rport || fc_remote_port_chkready(rport))
582 return -ENXIO;
583
584 hd = (MPT_SCSI_HOST *)sdev->host->hostdata;
585
Michael Reed3bc7bf12006-01-25 18:05:18 -0700586 vdev = kzalloc(sizeof(VirtDevice), GFP_KERNEL);
Michael Reed05e8ec12006-01-13 14:31:54 -0600587 if (!vdev) {
588 printk(MYIOC_s_ERR_FMT "slave_alloc kmalloc(%zd) FAILED!\n",
589 hd->ioc->name, sizeof(VirtDevice));
590 return -ENOMEM;
591 }
Michael Reed05e8ec12006-01-13 14:31:54 -0600592
Michael Reed05e8ec12006-01-13 14:31:54 -0600593
Michael Reed05e8ec12006-01-13 14:31:54 -0600594 sdev->hostdata = vdev;
Michael Reed05e8ec12006-01-13 14:31:54 -0600595 vtarget = starget->hostdata;
Michael Reed3bc7bf12006-01-25 18:05:18 -0700596
Michael Reed05e8ec12006-01-13 14:31:54 -0600597 if (vtarget->num_luns == 0) {
Michael Reed3bc7bf12006-01-25 18:05:18 -0700598 vtarget->ioc_id = hd->ioc->id;
Eric Mooreba856d32006-07-11 17:34:01 -0600599 vtarget->tflags = MPT_TARGET_FLAGS_Q_YES;
Michael Reed05e8ec12006-01-13 14:31:54 -0600600 }
601
Michael Reed05e8ec12006-01-13 14:31:54 -0600602 vdev->vtarget = vtarget;
Michael Reed05e8ec12006-01-13 14:31:54 -0600603 vdev->lun = sdev->lun;
Michael Reed05e8ec12006-01-13 14:31:54 -0600604
Michael Reed05e8ec12006-01-13 14:31:54 -0600605 vtarget->num_luns++;
606
Moore, Eric65207fe2006-04-21 16:14:35 -0600607
Moore, Eric914c2d82006-03-14 09:19:36 -0700608#ifdef DMPT_DEBUG_FC
Moore, Eric65207fe2006-04-21 16:14:35 -0600609 {
610 u64 nn, pn;
Moore, Eric914c2d82006-03-14 09:19:36 -0700611 struct mptfc_rport_info *ri;
612 ri = *((struct mptfc_rport_info **)rport->dd_data);
Moore, Eric65207fe2006-04-21 16:14:35 -0600613 pn = (u64)ri->pg0.WWPN.High << 32 | (u64)ri->pg0.WWPN.Low;
614 nn = (u64)ri->pg0.WWNN.High << 32 | (u64)ri->pg0.WWNN.Low;
Michael Reed3bc7bf12006-01-25 18:05:18 -0700615 dfcprintk ((MYIOC_s_INFO_FMT
616 "mptfc_slv_alloc.%d: num_luns %d, sdev.id %d, "
Michael Reed05e8ec12006-01-13 14:31:54 -0600617 "CurrentTargetID %d, %x %llx %llx\n",
Moore, Eric914c2d82006-03-14 09:19:36 -0700618 hd->ioc->name,
Michael Reed3bc7bf12006-01-25 18:05:18 -0700619 sdev->host->host_no,
620 vtarget->num_luns,
621 sdev->id, ri->pg0.CurrentTargetID,
Moore, Eric65207fe2006-04-21 16:14:35 -0600622 ri->pg0.PortIdentifier,
623 (unsigned long long)pn,
624 (unsigned long long)nn));
Moore, Eric914c2d82006-03-14 09:19:36 -0700625 }
626#endif
Michael Reed05e8ec12006-01-13 14:31:54 -0600627
628 return 0;
629}
630
631static int
632mptfc_qcmd(struct scsi_cmnd *SCpnt, void (*done)(struct scsi_cmnd *))
633{
Michael Reed3bc7bf12006-01-25 18:05:18 -0700634 struct mptfc_rport_info *ri;
Michael Reed05e8ec12006-01-13 14:31:54 -0600635 struct fc_rport *rport = starget_to_rport(scsi_target(SCpnt->device));
636 int err;
Eric Moore793955f2007-01-29 09:42:20 -0700637 VirtDevice *vdev = SCpnt->device->hostdata;
Michael Reed05e8ec12006-01-13 14:31:54 -0600638
Eric Moore793955f2007-01-29 09:42:20 -0700639 if (!vdev || !vdev->vtarget) {
640 SCpnt->result = DID_NO_CONNECT << 16;
Michael Reed05e8ec12006-01-13 14:31:54 -0600641 done(SCpnt);
642 return 0;
643 }
Michael Reed3bc7bf12006-01-25 18:05:18 -0700644
Eric Moore793955f2007-01-29 09:42:20 -0700645 err = fc_remote_port_chkready(rport);
646 if (unlikely(err)) {
647 SCpnt->result = err;
Michael Reed35508e42006-10-06 15:39:25 -0500648 done(SCpnt);
649 return 0;
650 }
651
Moore, Eric65207fe2006-04-21 16:14:35 -0600652 /* dd_data is null until finished adding target */
653 ri = *((struct mptfc_rport_info **)rport->dd_data);
654 if (unlikely(!ri)) {
655 dfcprintk ((MYIOC_s_INFO_FMT
656 "mptfc_qcmd.%d: %d:%d, dd_data is null.\n",
657 ((MPT_SCSI_HOST *) SCpnt->device->host->hostdata)->ioc->name,
658 ((MPT_SCSI_HOST *) SCpnt->device->host->hostdata)->ioc->sh->host_no,
659 SCpnt->device->id,SCpnt->device->lun));
660 SCpnt->result = DID_IMM_RETRY << 16;
661 done(SCpnt);
662 return 0;
663 }
664
665 err = mptscsih_qcmd(SCpnt,done);
666#ifdef DMPT_DEBUG_FC
667 if (unlikely(err)) {
668 dfcprintk ((MYIOC_s_INFO_FMT
Michael Reed419835e2006-05-24 15:07:40 -0500669 "mptfc_qcmd.%d: %d:%d, mptscsih_qcmd returns non-zero, (%x).\n",
Moore, Eric65207fe2006-04-21 16:14:35 -0600670 ((MPT_SCSI_HOST *) SCpnt->device->host->hostdata)->ioc->name,
671 ((MPT_SCSI_HOST *) SCpnt->device->host->hostdata)->ioc->sh->host_no,
Michael Reed419835e2006-05-24 15:07:40 -0500672 SCpnt->device->id,SCpnt->device->lun,err));
Moore, Eric65207fe2006-04-21 16:14:35 -0600673 }
674#endif
675 return err;
Michael Reed05e8ec12006-01-13 14:31:54 -0600676}
677
Michael Reed80d3ac72006-05-24 15:07:09 -0500678/*
679 * mptfc_GetFcPortPage0 - Fetch FCPort config Page0.
680 * @ioc: Pointer to MPT_ADAPTER structure
681 * @portnum: IOC Port number
682 *
683 * Return: 0 for success
684 * -ENOMEM if no memory available
685 * -EPERM if not allowed due to ISR context
686 * -EAGAIN if no msg frames currently available
687 * -EFAULT for non-successful reply or no reply (timeout)
688 * -EINVAL portnum arg out of range (hardwired to two elements)
689 */
690static int
691mptfc_GetFcPortPage0(MPT_ADAPTER *ioc, int portnum)
692{
693 ConfigPageHeader_t hdr;
694 CONFIGPARMS cfg;
695 FCPortPage0_t *ppage0_alloc;
696 FCPortPage0_t *pp0dest;
697 dma_addr_t page0_dma;
698 int data_sz;
699 int copy_sz;
700 int rc;
701 int count = 400;
702
703 if (portnum > 1)
704 return -EINVAL;
705
706 /* Get FCPort Page 0 header */
707 hdr.PageVersion = 0;
708 hdr.PageLength = 0;
709 hdr.PageNumber = 0;
710 hdr.PageType = MPI_CONFIG_PAGETYPE_FC_PORT;
711 cfg.cfghdr.hdr = &hdr;
712 cfg.physAddr = -1;
713 cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
714 cfg.dir = 0;
715 cfg.pageAddr = portnum;
716 cfg.timeout = 0;
717
718 if ((rc = mpt_config(ioc, &cfg)) != 0)
719 return rc;
720
721 if (hdr.PageLength == 0)
722 return 0;
723
724 data_sz = hdr.PageLength * 4;
725 rc = -ENOMEM;
726 ppage0_alloc = (FCPortPage0_t *) pci_alloc_consistent(ioc->pcidev, data_sz, &page0_dma);
727 if (ppage0_alloc) {
728
729 try_again:
730 memset((u8 *)ppage0_alloc, 0, data_sz);
731 cfg.physAddr = page0_dma;
732 cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
733
734 if ((rc = mpt_config(ioc, &cfg)) == 0) {
735 /* save the data */
736 pp0dest = &ioc->fc_port_page0[portnum];
737 copy_sz = min_t(int, sizeof(FCPortPage0_t), data_sz);
738 memcpy(pp0dest, ppage0_alloc, copy_sz);
739
740 /*
741 * Normalize endianness of structure data,
742 * by byte-swapping all > 1 byte fields!
743 */
744 pp0dest->Flags = le32_to_cpu(pp0dest->Flags);
745 pp0dest->PortIdentifier = le32_to_cpu(pp0dest->PortIdentifier);
746 pp0dest->WWNN.Low = le32_to_cpu(pp0dest->WWNN.Low);
747 pp0dest->WWNN.High = le32_to_cpu(pp0dest->WWNN.High);
748 pp0dest->WWPN.Low = le32_to_cpu(pp0dest->WWPN.Low);
749 pp0dest->WWPN.High = le32_to_cpu(pp0dest->WWPN.High);
750 pp0dest->SupportedServiceClass = le32_to_cpu(pp0dest->SupportedServiceClass);
751 pp0dest->SupportedSpeeds = le32_to_cpu(pp0dest->SupportedSpeeds);
752 pp0dest->CurrentSpeed = le32_to_cpu(pp0dest->CurrentSpeed);
753 pp0dest->MaxFrameSize = le32_to_cpu(pp0dest->MaxFrameSize);
754 pp0dest->FabricWWNN.Low = le32_to_cpu(pp0dest->FabricWWNN.Low);
755 pp0dest->FabricWWNN.High = le32_to_cpu(pp0dest->FabricWWNN.High);
756 pp0dest->FabricWWPN.Low = le32_to_cpu(pp0dest->FabricWWPN.Low);
757 pp0dest->FabricWWPN.High = le32_to_cpu(pp0dest->FabricWWPN.High);
758 pp0dest->DiscoveredPortsCount = le32_to_cpu(pp0dest->DiscoveredPortsCount);
759 pp0dest->MaxInitiators = le32_to_cpu(pp0dest->MaxInitiators);
760
761 /*
762 * if still doing discovery,
763 * hang loose a while until finished
764 */
Michael Reed77d88ee2006-07-31 12:19:40 -0500765 if ((pp0dest->PortState == MPI_FCPORTPAGE0_PORTSTATE_UNKNOWN) ||
766 (pp0dest->PortState == MPI_FCPORTPAGE0_PORTSTATE_ONLINE &&
767 (pp0dest->Flags & MPI_FCPORTPAGE0_FLAGS_ATTACH_TYPE_MASK)
768 == MPI_FCPORTPAGE0_FLAGS_ATTACH_NO_INIT)) {
Michael Reed80d3ac72006-05-24 15:07:09 -0500769 if (count-- > 0) {
Michael Reedd6be06c2006-05-24 15:07:57 -0500770 msleep(100);
Michael Reed80d3ac72006-05-24 15:07:09 -0500771 goto try_again;
772 }
773 printk(MYIOC_s_INFO_FMT "Firmware discovery not"
774 " complete.\n",
775 ioc->name);
776 }
777 }
778
779 pci_free_consistent(ioc->pcidev, data_sz, (u8 *) ppage0_alloc, page0_dma);
780 }
781
782 return rc;
783}
784
Michael Reedca2f9382006-05-24 15:07:24 -0500785static int
786mptfc_WriteFcPortPage1(MPT_ADAPTER *ioc, int portnum)
787{
788 ConfigPageHeader_t hdr;
789 CONFIGPARMS cfg;
790 int rc;
791
792 if (portnum > 1)
793 return -EINVAL;
794
795 if (!(ioc->fc_data.fc_port_page1[portnum].data))
796 return -EINVAL;
797
798 /* get fcport page 1 header */
799 hdr.PageVersion = 0;
800 hdr.PageLength = 0;
801 hdr.PageNumber = 1;
802 hdr.PageType = MPI_CONFIG_PAGETYPE_FC_PORT;
803 cfg.cfghdr.hdr = &hdr;
804 cfg.physAddr = -1;
805 cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
806 cfg.dir = 0;
807 cfg.pageAddr = portnum;
808 cfg.timeout = 0;
809
810 if ((rc = mpt_config(ioc, &cfg)) != 0)
811 return rc;
812
813 if (hdr.PageLength == 0)
814 return -ENODEV;
815
816 if (hdr.PageLength*4 != ioc->fc_data.fc_port_page1[portnum].pg_sz)
817 return -EINVAL;
818
819 cfg.physAddr = ioc->fc_data.fc_port_page1[portnum].dma;
820 cfg.action = MPI_CONFIG_ACTION_PAGE_WRITE_CURRENT;
821 cfg.dir = 1;
822
823 rc = mpt_config(ioc, &cfg);
824
825 return rc;
826}
827
828static int
829mptfc_GetFcPortPage1(MPT_ADAPTER *ioc, int portnum)
830{
831 ConfigPageHeader_t hdr;
832 CONFIGPARMS cfg;
833 FCPortPage1_t *page1_alloc;
834 dma_addr_t page1_dma;
835 int data_sz;
836 int rc;
837
838 if (portnum > 1)
839 return -EINVAL;
840
841 /* get fcport page 1 header */
842 hdr.PageVersion = 0;
843 hdr.PageLength = 0;
844 hdr.PageNumber = 1;
845 hdr.PageType = MPI_CONFIG_PAGETYPE_FC_PORT;
846 cfg.cfghdr.hdr = &hdr;
847 cfg.physAddr = -1;
848 cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
849 cfg.dir = 0;
850 cfg.pageAddr = portnum;
851 cfg.timeout = 0;
852
853 if ((rc = mpt_config(ioc, &cfg)) != 0)
854 return rc;
855
856 if (hdr.PageLength == 0)
857 return -ENODEV;
858
859start_over:
860
861 if (ioc->fc_data.fc_port_page1[portnum].data == NULL) {
862 data_sz = hdr.PageLength * 4;
863 if (data_sz < sizeof(FCPortPage1_t))
864 data_sz = sizeof(FCPortPage1_t);
865
866 page1_alloc = (FCPortPage1_t *) pci_alloc_consistent(ioc->pcidev,
867 data_sz,
868 &page1_dma);
869 if (!page1_alloc)
870 return -ENOMEM;
871 }
872 else {
873 page1_alloc = ioc->fc_data.fc_port_page1[portnum].data;
874 page1_dma = ioc->fc_data.fc_port_page1[portnum].dma;
875 data_sz = ioc->fc_data.fc_port_page1[portnum].pg_sz;
876 if (hdr.PageLength * 4 > data_sz) {
877 ioc->fc_data.fc_port_page1[portnum].data = NULL;
878 pci_free_consistent(ioc->pcidev, data_sz, (u8 *)
879 page1_alloc, page1_dma);
880 goto start_over;
881 }
882 }
883
884 memset(page1_alloc,0,data_sz);
885
886 cfg.physAddr = page1_dma;
887 cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
888
889 if ((rc = mpt_config(ioc, &cfg)) == 0) {
890 ioc->fc_data.fc_port_page1[portnum].data = page1_alloc;
891 ioc->fc_data.fc_port_page1[portnum].pg_sz = data_sz;
892 ioc->fc_data.fc_port_page1[portnum].dma = page1_dma;
893 }
894 else {
895 ioc->fc_data.fc_port_page1[portnum].data = NULL;
896 pci_free_consistent(ioc->pcidev, data_sz, (u8 *)
897 page1_alloc, page1_dma);
898 }
899
900 return rc;
901}
902
903static void
904mptfc_SetFcPortPage1_defaults(MPT_ADAPTER *ioc)
905{
906 int ii;
907 FCPortPage1_t *pp1;
908
909 #define MPTFC_FW_DEVICE_TIMEOUT (1)
910 #define MPTFC_FW_IO_PEND_TIMEOUT (1)
911 #define ON_FLAGS (MPI_FCPORTPAGE1_FLAGS_IMMEDIATE_ERROR_REPLY)
912 #define OFF_FLAGS (MPI_FCPORTPAGE1_FLAGS_VERBOSE_RESCAN_EVENTS)
913
914 for (ii=0; ii<ioc->facts.NumberOfPorts; ii++) {
915 if (mptfc_GetFcPortPage1(ioc, ii) != 0)
916 continue;
917 pp1 = ioc->fc_data.fc_port_page1[ii].data;
918 if ((pp1->InitiatorDeviceTimeout == MPTFC_FW_DEVICE_TIMEOUT)
919 && (pp1->InitiatorIoPendTimeout == MPTFC_FW_IO_PEND_TIMEOUT)
920 && ((pp1->Flags & ON_FLAGS) == ON_FLAGS)
921 && ((pp1->Flags & OFF_FLAGS) == 0))
922 continue;
923 pp1->InitiatorDeviceTimeout = MPTFC_FW_DEVICE_TIMEOUT;
924 pp1->InitiatorIoPendTimeout = MPTFC_FW_IO_PEND_TIMEOUT;
925 pp1->Flags &= ~OFF_FLAGS;
926 pp1->Flags |= ON_FLAGS;
927 mptfc_WriteFcPortPage1(ioc, ii);
928 }
929}
930
931
Michael Reed05e8ec12006-01-13 14:31:54 -0600932static void
933mptfc_init_host_attr(MPT_ADAPTER *ioc,int portnum)
934{
Michael Reed5d947f22006-07-31 12:19:30 -0500935 unsigned class = 0;
936 unsigned cos = 0;
937 unsigned speed;
938 unsigned port_type;
939 unsigned port_state;
940 FCPortPage0_t *pp0;
941 struct Scsi_Host *sh;
942 char *sn;
Michael Reed05e8ec12006-01-13 14:31:54 -0600943
944 /* don't know what to do as only one scsi (fc) host was allocated */
945 if (portnum != 0)
946 return;
947
Michael Reed5d947f22006-07-31 12:19:30 -0500948 pp0 = &ioc->fc_port_page0[portnum];
949 sh = ioc->sh;
950
951 sn = fc_host_symbolic_name(sh);
952 snprintf(sn, FC_SYMBOLIC_NAME_SIZE, "%s %s%08xh",
953 ioc->prod_name,
954 MPT_FW_REV_MAGIC_ID_STRING,
955 ioc->facts.FWVersion.Word);
956
957 fc_host_tgtid_bind_type(sh) = FC_TGTID_BIND_BY_WWPN;
958
959 fc_host_maxframe_size(sh) = pp0->MaxFrameSize;
960
961 fc_host_node_name(sh) =
962 (u64)pp0->WWNN.High << 32 | (u64)pp0->WWNN.Low;
963
964 fc_host_port_name(sh) =
965 (u64)pp0->WWPN.High << 32 | (u64)pp0->WWPN.Low;
966
967 fc_host_port_id(sh) = pp0->PortIdentifier;
968
969 class = pp0->SupportedServiceClass;
Michael Reed05e8ec12006-01-13 14:31:54 -0600970 if (class & MPI_FCPORTPAGE0_SUPPORT_CLASS_1)
971 cos |= FC_COS_CLASS1;
972 if (class & MPI_FCPORTPAGE0_SUPPORT_CLASS_2)
973 cos |= FC_COS_CLASS2;
974 if (class & MPI_FCPORTPAGE0_SUPPORT_CLASS_3)
975 cos |= FC_COS_CLASS3;
Michael Reed5d947f22006-07-31 12:19:30 -0500976 fc_host_supported_classes(sh) = cos;
Michael Reed05e8ec12006-01-13 14:31:54 -0600977
Michael Reed5d947f22006-07-31 12:19:30 -0500978 if (pp0->CurrentSpeed == MPI_FCPORTPAGE0_CURRENT_SPEED_1GBIT)
979 speed = FC_PORTSPEED_1GBIT;
980 else if (pp0->CurrentSpeed == MPI_FCPORTPAGE0_CURRENT_SPEED_2GBIT)
981 speed = FC_PORTSPEED_2GBIT;
982 else if (pp0->CurrentSpeed == MPI_FCPORTPAGE0_CURRENT_SPEED_4GBIT)
983 speed = FC_PORTSPEED_4GBIT;
984 else if (pp0->CurrentSpeed == MPI_FCPORTPAGE0_CURRENT_SPEED_10GBIT)
985 speed = FC_PORTSPEED_10GBIT;
986 else
987 speed = FC_PORTSPEED_UNKNOWN;
988 fc_host_speed(sh) = speed;
Michael Reed05e8ec12006-01-13 14:31:54 -0600989
Michael Reed5d947f22006-07-31 12:19:30 -0500990 speed = 0;
991 if (pp0->SupportedSpeeds & MPI_FCPORTPAGE0_SUPPORT_1GBIT_SPEED)
992 speed |= FC_PORTSPEED_1GBIT;
993 if (pp0->SupportedSpeeds & MPI_FCPORTPAGE0_SUPPORT_2GBIT_SPEED)
994 speed |= FC_PORTSPEED_2GBIT;
995 if (pp0->SupportedSpeeds & MPI_FCPORTPAGE0_SUPPORT_4GBIT_SPEED)
996 speed |= FC_PORTSPEED_4GBIT;
997 if (pp0->SupportedSpeeds & MPI_FCPORTPAGE0_SUPPORT_10GBIT_SPEED)
998 speed |= FC_PORTSPEED_10GBIT;
999 fc_host_supported_speeds(sh) = speed;
Michael Reed05e8ec12006-01-13 14:31:54 -06001000
Michael Reed5d947f22006-07-31 12:19:30 -05001001 port_state = FC_PORTSTATE_UNKNOWN;
1002 if (pp0->PortState == MPI_FCPORTPAGE0_PORTSTATE_ONLINE)
1003 port_state = FC_PORTSTATE_ONLINE;
1004 else if (pp0->PortState == MPI_FCPORTPAGE0_PORTSTATE_OFFLINE)
1005 port_state = FC_PORTSTATE_LINKDOWN;
1006 fc_host_port_state(sh) = port_state;
Michael Reed05e8ec12006-01-13 14:31:54 -06001007
Michael Reed5d947f22006-07-31 12:19:30 -05001008 port_type = FC_PORTTYPE_UNKNOWN;
1009 if (pp0->Flags & MPI_FCPORTPAGE0_FLAGS_ATTACH_POINT_TO_POINT)
1010 port_type = FC_PORTTYPE_PTP;
1011 else if (pp0->Flags & MPI_FCPORTPAGE0_FLAGS_ATTACH_PRIVATE_LOOP)
1012 port_type = FC_PORTTYPE_LPORT;
1013 else if (pp0->Flags & MPI_FCPORTPAGE0_FLAGS_ATTACH_PUBLIC_LOOP)
1014 port_type = FC_PORTTYPE_NLPORT;
1015 else if (pp0->Flags & MPI_FCPORTPAGE0_FLAGS_ATTACH_FABRIC_DIRECT)
1016 port_type = FC_PORTTYPE_NPORT;
1017 fc_host_port_type(sh) = port_type;
Michael Reed05e8ec12006-01-13 14:31:54 -06001018
Michael Reed5d947f22006-07-31 12:19:30 -05001019 fc_host_fabric_name(sh) =
1020 (pp0->Flags & MPI_FCPORTPAGE0_FLAGS_FABRIC_WWN_VALID) ?
1021 (u64) pp0->FabricWWNN.High << 32 | (u64) pp0->FabricWWPN.Low :
1022 (u64)pp0->WWNN.High << 32 | (u64)pp0->WWNN.Low;
1023
Michael Reed05e8ec12006-01-13 14:31:54 -06001024}
1025
1026static void
David Howellsc4028952006-11-22 14:57:56 +00001027mptfc_setup_reset(struct work_struct *work)
Michael Reed419835e2006-05-24 15:07:40 -05001028{
David Howellsc4028952006-11-22 14:57:56 +00001029 MPT_ADAPTER *ioc =
1030 container_of(work, MPT_ADAPTER, fc_setup_reset_work);
Michael Reed419835e2006-05-24 15:07:40 -05001031 u64 pn;
1032 struct mptfc_rport_info *ri;
1033
1034 /* reset about to happen, delete (block) all rports */
1035 list_for_each_entry(ri, &ioc->fc_rports, list) {
1036 if (ri->flags & MPT_RPORT_INFO_FLAGS_REGISTERED) {
1037 ri->flags &= ~MPT_RPORT_INFO_FLAGS_REGISTERED;
1038 fc_remote_port_delete(ri->rport); /* won't sleep */
1039 ri->rport = NULL;
1040
1041 pn = (u64)ri->pg0.WWPN.High << 32 |
1042 (u64)ri->pg0.WWPN.Low;
1043 dfcprintk ((MYIOC_s_INFO_FMT
1044 "mptfc_setup_reset.%d: %llx deleted\n",
1045 ioc->name,
1046 ioc->sh->host_no,
1047 (unsigned long long)pn));
1048 }
1049 }
1050}
1051
1052static void
David Howellsc4028952006-11-22 14:57:56 +00001053mptfc_rescan_devices(struct work_struct *work)
Michael Reed05e8ec12006-01-13 14:31:54 -06001054{
David Howellsc4028952006-11-22 14:57:56 +00001055 MPT_ADAPTER *ioc =
1056 container_of(work, MPT_ADAPTER, fc_rescan_work);
Michael Reed05e8ec12006-01-13 14:31:54 -06001057 int ii;
Moore, Eric65207fe2006-04-21 16:14:35 -06001058 u64 pn;
Michael Reed05e8ec12006-01-13 14:31:54 -06001059 struct mptfc_rport_info *ri;
1060
Michael Reed3a0c56d2006-07-31 12:19:50 -05001061 /* start by tagging all ports as missing */
1062 list_for_each_entry(ri, &ioc->fc_rports, list) {
1063 if (ri->flags & MPT_RPORT_INFO_FLAGS_REGISTERED) {
1064 ri->flags |= MPT_RPORT_INFO_FLAGS_MISSING;
Michael Reed05e8ec12006-01-13 14:31:54 -06001065 }
Michael Reed3a0c56d2006-07-31 12:19:50 -05001066 }
Michael Reed05e8ec12006-01-13 14:31:54 -06001067
Michael Reed3a0c56d2006-07-31 12:19:50 -05001068 /*
1069 * now rescan devices known to adapter,
1070 * will reregister existing rports
1071 */
1072 for (ii=0; ii < ioc->facts.NumberOfPorts; ii++) {
1073 (void) mptfc_GetFcPortPage0(ioc, ii);
1074 mptfc_init_host_attr(ioc, ii); /* refresh */
1075 mptfc_GetFcDevPage0(ioc, ii, mptfc_register_dev);
1076 }
1077
1078 /* delete devices still missing */
1079 list_for_each_entry(ri, &ioc->fc_rports, list) {
1080 /* if newly missing, delete it */
1081 if (ri->flags & MPT_RPORT_INFO_FLAGS_MISSING) {
1082
1083 ri->flags &= ~(MPT_RPORT_INFO_FLAGS_REGISTERED|
1084 MPT_RPORT_INFO_FLAGS_MISSING);
1085 fc_remote_port_delete(ri->rport); /* won't sleep */
1086 ri->rport = NULL;
1087
1088 pn = (u64)ri->pg0.WWPN.High << 32 |
1089 (u64)ri->pg0.WWPN.Low;
1090 dfcprintk ((MYIOC_s_INFO_FMT
1091 "mptfc_rescan.%d: %llx deleted\n",
1092 ioc->name,
1093 ioc->sh->host_no,
1094 (unsigned long long)pn));
Michael Reed05e8ec12006-01-13 14:31:54 -06001095 }
Michael Reed3a0c56d2006-07-31 12:19:50 -05001096 }
Michael Reed05e8ec12006-01-13 14:31:54 -06001097}
1098
Moore, Eric Dean 2496af32005-04-22 18:02:41 -04001099static int
1100mptfc_probe(struct pci_dev *pdev, const struct pci_device_id *id)
1101{
1102 struct Scsi_Host *sh;
1103 MPT_SCSI_HOST *hd;
1104 MPT_ADAPTER *ioc;
1105 unsigned long flags;
Christoph Hellwig1ca00bb2006-01-13 18:27:50 +01001106 int ii;
Moore, Eric Dean 2496af32005-04-22 18:02:41 -04001107 int numSGE = 0;
1108 int scale;
1109 int ioc_cap;
Moore, Eric Dean 2496af32005-04-22 18:02:41 -04001110 int error=0;
1111 int r;
Michael Reed05e8ec12006-01-13 14:31:54 -06001112
Moore, Eric Dean 2496af32005-04-22 18:02:41 -04001113 if ((r = mpt_attach(pdev,id)) != 0)
1114 return r;
Michael Reed05e8ec12006-01-13 14:31:54 -06001115
Moore, Eric Dean 2496af32005-04-22 18:02:41 -04001116 ioc = pci_get_drvdata(pdev);
Moore, Eric Dean d335cc32005-04-30 17:09:38 -05001117 ioc->DoneCtx = mptfcDoneCtx;
1118 ioc->TaskCtx = mptfcTaskCtx;
1119 ioc->InternalCtx = mptfcInternalCtx;
Moore, Eric Dean 2496af32005-04-22 18:02:41 -04001120
1121 /* Added sanity check on readiness of the MPT adapter.
1122 */
1123 if (ioc->last_state != MPI_IOC_STATE_OPERATIONAL) {
1124 printk(MYIOC_s_WARN_FMT
1125 "Skipping because it's not operational!\n",
1126 ioc->name);
Moore, Eric Dean7acec1e2005-11-16 18:54:17 -07001127 error = -ENODEV;
1128 goto out_mptfc_probe;
Moore, Eric Dean 2496af32005-04-22 18:02:41 -04001129 }
1130
1131 if (!ioc->active) {
1132 printk(MYIOC_s_WARN_FMT "Skipping because it's disabled!\n",
1133 ioc->name);
Moore, Eric Dean7acec1e2005-11-16 18:54:17 -07001134 error = -ENODEV;
1135 goto out_mptfc_probe;
Moore, Eric Dean 2496af32005-04-22 18:02:41 -04001136 }
1137
1138 /* Sanity check - ensure at least 1 port is INITIATOR capable
1139 */
1140 ioc_cap = 0;
1141 for (ii=0; ii < ioc->facts.NumberOfPorts; ii++) {
1142 if (ioc->pfacts[ii].ProtocolFlags &
1143 MPI_PORTFACTS_PROTOCOL_INITIATOR)
1144 ioc_cap ++;
1145 }
1146
1147 if (!ioc_cap) {
1148 printk(MYIOC_s_WARN_FMT
1149 "Skipping ioc=%p because SCSI Initiator mode is NOT enabled!\n",
1150 ioc->name, ioc);
Eric Moore793955f2007-01-29 09:42:20 -07001151 return 0;
Moore, Eric Dean 2496af32005-04-22 18:02:41 -04001152 }
1153
1154 sh = scsi_host_alloc(&mptfc_driver_template, sizeof(MPT_SCSI_HOST));
1155
1156 if (!sh) {
1157 printk(MYIOC_s_WARN_FMT
1158 "Unable to register controller with SCSI subsystem\n",
1159 ioc->name);
Moore, Eric Dean7acec1e2005-11-16 18:54:17 -07001160 error = -1;
1161 goto out_mptfc_probe;
Moore, Eric Dean 2496af32005-04-22 18:02:41 -04001162 }
1163
Michael Reed80d3ac72006-05-24 15:07:09 -05001164 spin_lock_init(&ioc->fc_rescan_work_lock);
David Howellsc4028952006-11-22 14:57:56 +00001165 INIT_WORK(&ioc->fc_rescan_work, mptfc_rescan_devices);
1166 INIT_WORK(&ioc->fc_setup_reset_work, mptfc_setup_reset);
Michael Reed05e8ec12006-01-13 14:31:54 -06001167
Moore, Eric Dean 2496af32005-04-22 18:02:41 -04001168 spin_lock_irqsave(&ioc->FreeQlock, flags);
1169
1170 /* Attach the SCSI Host to the IOC structure
1171 */
1172 ioc->sh = sh;
1173
1174 sh->io_port = 0;
1175 sh->n_io_port = 0;
1176 sh->irq = 0;
1177
1178 /* set 16 byte cdb's */
1179 sh->max_cmd_len = 16;
1180
Eric Moore793955f2007-01-29 09:42:20 -07001181 sh->max_id = ioc->pfacts->MaxDevices;
1182 sh->max_lun = max_lun;
Moore, Eric Dean 2496af32005-04-22 18:02:41 -04001183
Moore, Eric Dean 2496af32005-04-22 18:02:41 -04001184 sh->this_id = ioc->pfacts[0].PortSCSIID;
1185
1186 /* Required entry.
1187 */
1188 sh->unique_id = ioc->id;
1189
1190 /* Verify that we won't exceed the maximum
1191 * number of chain buffers
1192 * We can optimize: ZZ = req_sz/sizeof(SGE)
1193 * For 32bit SGE's:
1194 * numSGE = 1 + (ZZ-1)*(maxChain -1) + ZZ
1195 * + (req_sz - 64)/sizeof(SGE)
1196 * A slightly different algorithm is required for
1197 * 64bit SGEs.
1198 */
1199 scale = ioc->req_sz/(sizeof(dma_addr_t) + sizeof(u32));
1200 if (sizeof(dma_addr_t) == sizeof(u64)) {
1201 numSGE = (scale - 1) *
1202 (ioc->facts.MaxChainDepth-1) + scale +
1203 (ioc->req_sz - 60) / (sizeof(dma_addr_t) +
1204 sizeof(u32));
1205 } else {
1206 numSGE = 1 + (scale - 1) *
1207 (ioc->facts.MaxChainDepth-1) + scale +
1208 (ioc->req_sz - 64) / (sizeof(dma_addr_t) +
1209 sizeof(u32));
1210 }
1211
1212 if (numSGE < sh->sg_tablesize) {
1213 /* Reset this value */
1214 dprintk((MYIOC_s_INFO_FMT
1215 "Resetting sg_tablesize to %d from %d\n",
1216 ioc->name, numSGE, sh->sg_tablesize));
1217 sh->sg_tablesize = numSGE;
1218 }
1219
Moore, Eric Dean 2496af32005-04-22 18:02:41 -04001220 spin_unlock_irqrestore(&ioc->FreeQlock, flags);
1221
1222 hd = (MPT_SCSI_HOST *) sh->hostdata;
1223 hd->ioc = ioc;
1224
1225 /* SCSI needs scsi_cmnd lookup table!
1226 * (with size equal to req_depth*PtrSz!)
1227 */
Christoph Hellwig1ca00bb2006-01-13 18:27:50 +01001228 hd->ScsiLookup = kcalloc(ioc->req_depth, sizeof(void *), GFP_ATOMIC);
1229 if (!hd->ScsiLookup) {
Moore, Eric Dean 2496af32005-04-22 18:02:41 -04001230 error = -ENOMEM;
Moore, Eric Dean7acec1e2005-11-16 18:54:17 -07001231 goto out_mptfc_probe;
Moore, Eric Dean 2496af32005-04-22 18:02:41 -04001232 }
1233
Christoph Hellwig1ca00bb2006-01-13 18:27:50 +01001234 dprintk((MYIOC_s_INFO_FMT "ScsiLookup @ %p\n",
1235 ioc->name, hd->ScsiLookup));
Moore, Eric Dean 2496af32005-04-22 18:02:41 -04001236
Moore, Eric Dean 2496af32005-04-22 18:02:41 -04001237 /* Clear the TM flags
1238 */
1239 hd->tmPending = 0;
1240 hd->tmState = TM_STATE_NONE;
1241 hd->resetPending = 0;
1242 hd->abortSCpnt = NULL;
1243
1244 /* Clear the pointer used to store
1245 * single-threaded commands, i.e., those
1246 * issued during a bus scan, dv and
1247 * configuration pages.
1248 */
1249 hd->cmdPtr = NULL;
1250
1251 /* Initialize this SCSI Hosts' timers
1252 * To use, set the timer expires field
1253 * and add_timer
1254 */
1255 init_timer(&hd->timer);
1256 hd->timer.data = (unsigned long) hd;
1257 hd->timer.function = mptscsih_timer_expired;
1258
Moore, Eric Dean 2496af32005-04-22 18:02:41 -04001259 init_waitqueue_head(&hd->scandv_waitq);
1260 hd->scandv_wait_done = 0;
1261 hd->last_queue_full = 0;
1262
Michael Reed05e8ec12006-01-13 14:31:54 -06001263 sh->transportt = mptfc_transport_template;
Moore, Eric Dean 2496af32005-04-22 18:02:41 -04001264 error = scsi_add_host (sh, &ioc->pcidev->dev);
1265 if(error) {
1266 dprintk((KERN_ERR MYNAM
1267 "scsi_add_host failed\n"));
Moore, Eric Dean7acec1e2005-11-16 18:54:17 -07001268 goto out_mptfc_probe;
Moore, Eric Dean 2496af32005-04-22 18:02:41 -04001269 }
1270
Moore, Eric65207fe2006-04-21 16:14:35 -06001271 /* initialize workqueue */
1272
1273 snprintf(ioc->fc_rescan_work_q_name, KOBJ_NAME_LEN, "mptfc_wq_%d",
1274 sh->host_no);
1275 ioc->fc_rescan_work_q =
1276 create_singlethread_workqueue(ioc->fc_rescan_work_q_name);
1277 if (!ioc->fc_rescan_work_q)
1278 goto out_mptfc_probe;
1279
1280 /*
Michael Reed80d3ac72006-05-24 15:07:09 -05001281 * Pre-fetch FC port WWN and stuff...
1282 * (FCPortPage0_t stuff)
1283 */
1284 for (ii=0; ii < ioc->facts.NumberOfPorts; ii++) {
1285 (void) mptfc_GetFcPortPage0(ioc, ii);
1286 }
Michael Reedca2f9382006-05-24 15:07:24 -05001287 mptfc_SetFcPortPage1_defaults(ioc);
Michael Reed80d3ac72006-05-24 15:07:09 -05001288
1289 /*
Moore, Eric65207fe2006-04-21 16:14:35 -06001290 * scan for rports -
1291 * by doing it via the workqueue, some locking is eliminated
1292 */
1293
Moore, Eric65207fe2006-04-21 16:14:35 -06001294 queue_work(ioc->fc_rescan_work_q, &ioc->fc_rescan_work);
1295 flush_workqueue(ioc->fc_rescan_work_q);
Michael Reed05e8ec12006-01-13 14:31:54 -06001296
Moore, Eric Dean 2496af32005-04-22 18:02:41 -04001297 return 0;
1298
Moore, Eric Dean7acec1e2005-11-16 18:54:17 -07001299out_mptfc_probe:
Moore, Eric Dean 2496af32005-04-22 18:02:41 -04001300
1301 mptscsih_remove(pdev);
1302 return error;
1303}
1304
1305static struct pci_driver mptfc_driver = {
1306 .name = "mptfc",
1307 .id_table = mptfc_pci_table,
1308 .probe = mptfc_probe,
Michael Reed05e8ec12006-01-13 14:31:54 -06001309 .remove = __devexit_p(mptfc_remove),
Greg Kroah-Hartmand18c3db2005-06-23 17:35:56 -07001310 .shutdown = mptscsih_shutdown,
Moore, Eric Dean 2496af32005-04-22 18:02:41 -04001311#ifdef CONFIG_PM
1312 .suspend = mptscsih_suspend,
1313 .resume = mptscsih_resume,
1314#endif
1315};
1316
Michael Reed80d3ac72006-05-24 15:07:09 -05001317static int
1318mptfc_event_process(MPT_ADAPTER *ioc, EventNotificationReply_t *pEvReply)
1319{
1320 MPT_SCSI_HOST *hd;
1321 u8 event = le32_to_cpu(pEvReply->Event) & 0xFF;
1322 unsigned long flags;
1323 int rc=1;
1324
1325 devtverboseprintk((MYIOC_s_INFO_FMT "MPT event (=%02Xh) routed to SCSI host driver!\n",
1326 ioc->name, event));
1327
1328 if (ioc->sh == NULL ||
1329 ((hd = (MPT_SCSI_HOST *)ioc->sh->hostdata) == NULL))
1330 return 1;
1331
1332 switch (event) {
1333 case MPI_EVENT_RESCAN:
1334 spin_lock_irqsave(&ioc->fc_rescan_work_lock, flags);
1335 if (ioc->fc_rescan_work_q) {
Michael Reed3a0c56d2006-07-31 12:19:50 -05001336 queue_work(ioc->fc_rescan_work_q,
1337 &ioc->fc_rescan_work);
Michael Reed80d3ac72006-05-24 15:07:09 -05001338 }
1339 spin_unlock_irqrestore(&ioc->fc_rescan_work_lock, flags);
1340 break;
1341 default:
1342 rc = mptscsih_event_process(ioc,pEvReply);
1343 break;
1344 }
1345 return rc;
1346}
1347
1348static int
1349mptfc_ioc_reset(MPT_ADAPTER *ioc, int reset_phase)
1350{
1351 int rc;
1352 unsigned long flags;
1353
1354 rc = mptscsih_ioc_reset(ioc,reset_phase);
1355 if (rc == 0)
1356 return rc;
1357
1358
1359 dtmprintk((KERN_WARNING MYNAM
1360 ": IOC %s_reset routed to FC host driver!\n",
1361 reset_phase==MPT_IOC_SETUP_RESET ? "setup" : (
1362 reset_phase==MPT_IOC_PRE_RESET ? "pre" : "post")));
1363
1364 if (reset_phase == MPT_IOC_SETUP_RESET) {
Michael Reed419835e2006-05-24 15:07:40 -05001365 spin_lock_irqsave(&ioc->fc_rescan_work_lock, flags);
1366 if (ioc->fc_rescan_work_q) {
1367 queue_work(ioc->fc_rescan_work_q,
1368 &ioc->fc_setup_reset_work);
1369 }
1370 spin_unlock_irqrestore(&ioc->fc_rescan_work_lock, flags);
Michael Reed80d3ac72006-05-24 15:07:09 -05001371 }
1372
1373 else if (reset_phase == MPT_IOC_PRE_RESET) {
1374 }
1375
1376 else { /* MPT_IOC_POST_RESET */
Michael Reedca2f9382006-05-24 15:07:24 -05001377 mptfc_SetFcPortPage1_defaults(ioc);
Michael Reed80d3ac72006-05-24 15:07:09 -05001378 spin_lock_irqsave(&ioc->fc_rescan_work_lock, flags);
1379 if (ioc->fc_rescan_work_q) {
Michael Reed3a0c56d2006-07-31 12:19:50 -05001380 queue_work(ioc->fc_rescan_work_q,
1381 &ioc->fc_rescan_work);
Michael Reed80d3ac72006-05-24 15:07:09 -05001382 }
1383 spin_unlock_irqrestore(&ioc->fc_rescan_work_lock, flags);
1384 }
1385 return 1;
1386}
1387
Moore, Eric Dean 2496af32005-04-22 18:02:41 -04001388/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
1389/**
Randy Dunlapd9489fb2006-12-06 20:38:43 -08001390 * mptfc_init - Register MPT adapter(s) as SCSI host(s) with SCSI mid-layer.
Moore, Eric Dean 2496af32005-04-22 18:02:41 -04001391 *
1392 * Returns 0 for success, non-zero for failure.
1393 */
1394static int __init
1395mptfc_init(void)
1396{
Michael Reed05e8ec12006-01-13 14:31:54 -06001397 int error;
Moore, Eric Dean 2496af32005-04-22 18:02:41 -04001398
1399 show_mptmod_ver(my_NAME, my_VERSION);
1400
Michael Reedca2f9382006-05-24 15:07:24 -05001401 /* sanity check module parameters */
1402 if (mptfc_dev_loss_tmo <= 0)
Michael Reed05e8ec12006-01-13 14:31:54 -06001403 mptfc_dev_loss_tmo = MPTFC_DEV_LOSS_TMO;
1404
1405 mptfc_transport_template =
1406 fc_attach_transport(&mptfc_transport_functions);
1407
1408 if (!mptfc_transport_template)
1409 return -ENODEV;
1410
Moore, Eric Dean 2496af32005-04-22 18:02:41 -04001411 mptfcDoneCtx = mpt_register(mptscsih_io_done, MPTFC_DRIVER);
1412 mptfcTaskCtx = mpt_register(mptscsih_taskmgmt_complete, MPTFC_DRIVER);
1413 mptfcInternalCtx = mpt_register(mptscsih_scandv_complete, MPTFC_DRIVER);
1414
Michael Reed80d3ac72006-05-24 15:07:09 -05001415 if (mpt_event_register(mptfcDoneCtx, mptfc_event_process) == 0) {
Moore, Eric3a892be2006-03-14 09:14:03 -07001416 devtverboseprintk((KERN_INFO MYNAM
Moore, Eric Dean 2496af32005-04-22 18:02:41 -04001417 ": Registered for IOC event notifications\n"));
1418 }
1419
Michael Reed80d3ac72006-05-24 15:07:09 -05001420 if (mpt_reset_register(mptfcDoneCtx, mptfc_ioc_reset) == 0) {
Moore, Eric Dean 2496af32005-04-22 18:02:41 -04001421 dprintk((KERN_INFO MYNAM
1422 ": Registered for IOC reset notifications\n"));
1423 }
1424
Michael Reed05e8ec12006-01-13 14:31:54 -06001425 error = pci_register_driver(&mptfc_driver);
Michael Reed3bc7bf12006-01-25 18:05:18 -07001426 if (error)
Michael Reed05e8ec12006-01-13 14:31:54 -06001427 fc_release_transport(mptfc_transport_template);
Michael Reed05e8ec12006-01-13 14:31:54 -06001428
1429 return error;
1430}
1431
1432/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
1433/**
Randy Dunlapd9489fb2006-12-06 20:38:43 -08001434 * mptfc_remove - Remove fc infrastructure for devices
Michael Reed05e8ec12006-01-13 14:31:54 -06001435 * @pdev: Pointer to pci_dev structure
1436 *
1437 */
Michael Reed3bc7bf12006-01-25 18:05:18 -07001438static void __devexit
1439mptfc_remove(struct pci_dev *pdev)
Michael Reed05e8ec12006-01-13 14:31:54 -06001440{
Moore, Eric65207fe2006-04-21 16:14:35 -06001441 MPT_ADAPTER *ioc = pci_get_drvdata(pdev);
1442 struct mptfc_rport_info *p, *n;
1443 struct workqueue_struct *work_q;
1444 unsigned long flags;
Michael Reedca2f9382006-05-24 15:07:24 -05001445 int ii;
Moore, Eric65207fe2006-04-21 16:14:35 -06001446
1447 /* destroy workqueue */
1448 if ((work_q=ioc->fc_rescan_work_q)) {
1449 spin_lock_irqsave(&ioc->fc_rescan_work_lock, flags);
1450 ioc->fc_rescan_work_q = NULL;
1451 spin_unlock_irqrestore(&ioc->fc_rescan_work_lock, flags);
1452 destroy_workqueue(work_q);
1453 }
Michael Reed05e8ec12006-01-13 14:31:54 -06001454
1455 fc_remove_host(ioc->sh);
1456
1457 list_for_each_entry_safe(p, n, &ioc->fc_rports, list) {
1458 list_del(&p->list);
1459 kfree(p);
1460 }
1461
Michael Reedca2f9382006-05-24 15:07:24 -05001462 for (ii=0; ii<ioc->facts.NumberOfPorts; ii++) {
1463 if (ioc->fc_data.fc_port_page1[ii].data) {
1464 pci_free_consistent(ioc->pcidev,
1465 ioc->fc_data.fc_port_page1[ii].pg_sz,
1466 (u8 *) ioc->fc_data.fc_port_page1[ii].data,
1467 ioc->fc_data.fc_port_page1[ii].dma);
1468 ioc->fc_data.fc_port_page1[ii].data = NULL;
1469 }
1470 }
1471
Michael Reed05e8ec12006-01-13 14:31:54 -06001472 mptscsih_remove(pdev);
Moore, Eric Dean 2496af32005-04-22 18:02:41 -04001473}
1474
1475/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
1476/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
1477/**
1478 * mptfc_exit - Unregisters MPT adapter(s)
1479 *
1480 */
1481static void __exit
1482mptfc_exit(void)
1483{
1484 pci_unregister_driver(&mptfc_driver);
Michael Reed05e8ec12006-01-13 14:31:54 -06001485 fc_release_transport(mptfc_transport_template);
1486
Moore, Eric Dean 2496af32005-04-22 18:02:41 -04001487 mpt_reset_deregister(mptfcDoneCtx);
1488 dprintk((KERN_INFO MYNAM
1489 ": Deregistered for IOC reset notifications\n"));
1490
1491 mpt_event_deregister(mptfcDoneCtx);
1492 dprintk((KERN_INFO MYNAM
1493 ": Deregistered for IOC event notifications\n"));
1494
1495 mpt_deregister(mptfcInternalCtx);
1496 mpt_deregister(mptfcTaskCtx);
1497 mpt_deregister(mptfcDoneCtx);
1498}
1499
1500module_init(mptfc_init);
1501module_exit(mptfc_exit);