blob: 244a32c66f06cc9687217c7f0ad514842d50b962 [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);
99
Moore, Eric Dean 2496af32005-04-22 18:02:41 -0400100static struct scsi_host_template mptfc_driver_template = {
Moore, Eric Deanf78496d2005-11-16 18:54:14 -0700101 .module = THIS_MODULE,
Moore, Eric Dean 2496af32005-04-22 18:02:41 -0400102 .proc_name = "mptfc",
103 .proc_info = mptscsih_proc_info,
104 .name = "MPT FC Host",
105 .info = mptscsih_info,
Michael Reed05e8ec12006-01-13 14:31:54 -0600106 .queuecommand = mptfc_qcmd,
Michael Reed3bc7bf12006-01-25 18:05:18 -0700107 .target_alloc = mptfc_target_alloc,
Michael Reed05e8ec12006-01-13 14:31:54 -0600108 .slave_alloc = mptfc_slave_alloc,
Moore, Eric Dean 2496af32005-04-22 18:02:41 -0400109 .slave_configure = mptscsih_slave_configure,
Michael Reed3bc7bf12006-01-25 18:05:18 -0700110 .target_destroy = mptfc_target_destroy,
Moore, Eric Dean 2496af32005-04-22 18:02:41 -0400111 .slave_destroy = mptscsih_slave_destroy,
Moore, Eric Dean6e3815b2005-06-24 12:18:57 -0600112 .change_queue_depth = mptscsih_change_queue_depth,
Moore, Eric Dean 2496af32005-04-22 18:02:41 -0400113 .eh_abort_handler = mptscsih_abort,
114 .eh_device_reset_handler = mptscsih_dev_reset,
115 .eh_bus_reset_handler = mptscsih_bus_reset,
116 .eh_host_reset_handler = mptscsih_host_reset,
117 .bios_param = mptscsih_bios_param,
118 .can_queue = MPT_FC_CAN_QUEUE,
119 .this_id = -1,
120 .sg_tablesize = MPT_SCSI_SG_DEPTH,
121 .max_sectors = 8192,
122 .cmd_per_lun = 7,
123 .use_clustering = ENABLE_CLUSTERING,
Moore, Eric Dean 2496af32005-04-22 18:02:41 -0400124};
125
126/****************************************************************************
127 * Supported hardware
128 */
129
130static struct pci_device_id mptfc_pci_table[] = {
Eric Moore87cf8982006-06-27 16:09:26 -0600131 { PCI_VENDOR_ID_LSI_LOGIC, MPI_MANUFACTPAGE_DEVICEID_FC909,
Moore, Eric Dean 2496af32005-04-22 18:02:41 -0400132 PCI_ANY_ID, PCI_ANY_ID },
Eric Moore87cf8982006-06-27 16:09:26 -0600133 { PCI_VENDOR_ID_LSI_LOGIC, MPI_MANUFACTPAGE_DEVICEID_FC919,
Moore, Eric Dean 2496af32005-04-22 18:02:41 -0400134 PCI_ANY_ID, PCI_ANY_ID },
Eric Moore87cf8982006-06-27 16:09:26 -0600135 { PCI_VENDOR_ID_LSI_LOGIC, MPI_MANUFACTPAGE_DEVICEID_FC929,
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_FC919X,
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_FC929X,
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_FC939X,
Moore, Eric Dean 3fadc592005-05-11 17:46:52 -0600142 PCI_ANY_ID, PCI_ANY_ID },
Eric Moore87cf8982006-06-27 16:09:26 -0600143 { PCI_VENDOR_ID_LSI_LOGIC, MPI_MANUFACTPAGE_DEVICEID_FC949X,
Moore, Eric Dean 3fadc592005-05-11 17:46:52 -0600144 PCI_ANY_ID, PCI_ANY_ID },
Eric Moore87cf8982006-06-27 16:09:26 -0600145 { PCI_VENDOR_ID_LSI_LOGIC, MPI_MANUFACTPAGE_DEVICEID_FC949E,
Moore, Eric6d5b0c32006-01-13 16:25:26 -0700146 PCI_ANY_ID, PCI_ANY_ID },
Moore, Eric Dean 2496af32005-04-22 18:02:41 -0400147 {0} /* Terminating entry */
148};
149MODULE_DEVICE_TABLE(pci, mptfc_pci_table);
150
Michael Reed05e8ec12006-01-13 14:31:54 -0600151static struct scsi_transport_template *mptfc_transport_template = NULL;
152
Adrian Bunk03fbcbc2006-01-25 02:00:52 +0100153static struct fc_function_template mptfc_transport_functions = {
Michael Reed05e8ec12006-01-13 14:31:54 -0600154 .dd_fcrport_size = 8,
155 .show_host_node_name = 1,
156 .show_host_port_name = 1,
157 .show_host_supported_classes = 1,
158 .show_host_port_id = 1,
159 .show_rport_supported_classes = 1,
160 .show_starget_node_name = 1,
161 .show_starget_port_name = 1,
162 .show_starget_port_id = 1,
163 .set_rport_dev_loss_tmo = mptfc_set_rport_loss_tmo,
164 .show_rport_dev_loss_tmo = 1,
Michael Reed5d947f22006-07-31 12:19:30 -0500165 .show_host_supported_speeds = 1,
166 .show_host_maxframe_size = 1,
167 .show_host_speed = 1,
168 .show_host_fabric_name = 1,
169 .show_host_port_type = 1,
170 .show_host_port_state = 1,
171 .show_host_symbolic_name = 1,
Michael Reed05e8ec12006-01-13 14:31:54 -0600172};
173
Michael Reed05e8ec12006-01-13 14:31:54 -0600174static void
175mptfc_set_rport_loss_tmo(struct fc_rport *rport, uint32_t timeout)
176{
177 if (timeout > 0)
178 rport->dev_loss_tmo = timeout;
179 else
180 rport->dev_loss_tmo = mptfc_dev_loss_tmo;
181}
182
183static int
184mptfc_FcDevPage0_cmp_func(const void *a, const void *b)
185{
186 FCDevicePage0_t **aa = (FCDevicePage0_t **)a;
187 FCDevicePage0_t **bb = (FCDevicePage0_t **)b;
188
189 if ((*aa)->CurrentBus == (*bb)->CurrentBus) {
190 if ((*aa)->CurrentTargetID == (*bb)->CurrentTargetID)
191 return 0;
192 if ((*aa)->CurrentTargetID < (*bb)->CurrentTargetID)
193 return -1;
194 return 1;
195 }
196 if ((*aa)->CurrentBus < (*bb)->CurrentBus)
197 return -1;
198 return 1;
199}
200
201static int
202mptfc_GetFcDevPage0(MPT_ADAPTER *ioc, int ioc_port,
203 void(*func)(MPT_ADAPTER *ioc,int channel, FCDevicePage0_t *arg))
204{
205 ConfigPageHeader_t hdr;
206 CONFIGPARMS cfg;
207 FCDevicePage0_t *ppage0_alloc, *fc;
208 dma_addr_t page0_dma;
209 int data_sz;
210 int ii;
211
212 FCDevicePage0_t *p0_array=NULL, *p_p0;
213 FCDevicePage0_t **pp0_array=NULL, **p_pp0;
214
215 int rc = -ENOMEM;
216 U32 port_id = 0xffffff;
217 int num_targ = 0;
218 int max_bus = ioc->facts.MaxBuses;
219 int max_targ = ioc->facts.MaxDevices;
220
221 if (max_bus == 0 || max_targ == 0)
222 goto out;
223
224 data_sz = sizeof(FCDevicePage0_t) * max_bus * max_targ;
225 p_p0 = p0_array = kzalloc(data_sz, GFP_KERNEL);
226 if (!p0_array)
227 goto out;
228
229 data_sz = sizeof(FCDevicePage0_t *) * max_bus * max_targ;
230 p_pp0 = pp0_array = kzalloc(data_sz, GFP_KERNEL);
231 if (!pp0_array)
232 goto out;
233
234 do {
235 /* Get FC Device Page 0 header */
236 hdr.PageVersion = 0;
237 hdr.PageLength = 0;
238 hdr.PageNumber = 0;
239 hdr.PageType = MPI_CONFIG_PAGETYPE_FC_DEVICE;
240 cfg.cfghdr.hdr = &hdr;
241 cfg.physAddr = -1;
242 cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
243 cfg.dir = 0;
244 cfg.pageAddr = port_id;
245 cfg.timeout = 0;
246
247 if ((rc = mpt_config(ioc, &cfg)) != 0)
248 break;
249
250 if (hdr.PageLength <= 0)
251 break;
252
253 data_sz = hdr.PageLength * 4;
254 ppage0_alloc = pci_alloc_consistent(ioc->pcidev, data_sz,
255 &page0_dma);
256 rc = -ENOMEM;
257 if (!ppage0_alloc)
258 break;
259
260 cfg.physAddr = page0_dma;
261 cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
262
263 if ((rc = mpt_config(ioc, &cfg)) == 0) {
264 ppage0_alloc->PortIdentifier =
265 le32_to_cpu(ppage0_alloc->PortIdentifier);
266
267 ppage0_alloc->WWNN.Low =
268 le32_to_cpu(ppage0_alloc->WWNN.Low);
269
270 ppage0_alloc->WWNN.High =
271 le32_to_cpu(ppage0_alloc->WWNN.High);
272
273 ppage0_alloc->WWPN.Low =
274 le32_to_cpu(ppage0_alloc->WWPN.Low);
275
276 ppage0_alloc->WWPN.High =
277 le32_to_cpu(ppage0_alloc->WWPN.High);
278
279 ppage0_alloc->BBCredit =
280 le16_to_cpu(ppage0_alloc->BBCredit);
281
282 ppage0_alloc->MaxRxFrameSize =
283 le16_to_cpu(ppage0_alloc->MaxRxFrameSize);
284
285 port_id = ppage0_alloc->PortIdentifier;
286 num_targ++;
287 *p_p0 = *ppage0_alloc; /* save data */
288 *p_pp0++ = p_p0++; /* save addr */
289 }
290 pci_free_consistent(ioc->pcidev, data_sz,
291 (u8 *) ppage0_alloc, page0_dma);
292 if (rc != 0)
293 break;
294
295 } while (port_id <= 0xff0000);
296
297 if (num_targ) {
298 /* sort array */
299 if (num_targ > 1)
300 sort (pp0_array, num_targ, sizeof(FCDevicePage0_t *),
301 mptfc_FcDevPage0_cmp_func, NULL);
302 /* call caller's func for each targ */
303 for (ii = 0; ii < num_targ; ii++) {
304 fc = *(pp0_array+ii);
305 func(ioc, ioc_port, fc);
306 }
307 }
308
309 out:
Jesper Juhl8f760782006-06-27 02:55:06 -0700310 kfree(pp0_array);
311 kfree(p0_array);
Michael Reed05e8ec12006-01-13 14:31:54 -0600312 return rc;
313}
314
315static int
316mptfc_generate_rport_ids(FCDevicePage0_t *pg0, struct fc_rport_identifiers *rid)
317{
318 /* not currently usable */
319 if (pg0->Flags & (MPI_FC_DEVICE_PAGE0_FLAGS_PLOGI_INVALID |
320 MPI_FC_DEVICE_PAGE0_FLAGS_PRLI_INVALID))
321 return -1;
322
323 if (!(pg0->Flags & MPI_FC_DEVICE_PAGE0_FLAGS_TARGETID_BUS_VALID))
324 return -1;
325
326 if (!(pg0->Protocol & MPI_FC_DEVICE_PAGE0_PROT_FCP_TARGET))
327 return -1;
328
329 /*
330 * board data structure already normalized to platform endianness
331 * shifted to avoid unaligned access on 64 bit architecture
332 */
333 rid->node_name = ((u64)pg0->WWNN.High) << 32 | (u64)pg0->WWNN.Low;
334 rid->port_name = ((u64)pg0->WWPN.High) << 32 | (u64)pg0->WWPN.Low;
335 rid->port_id = pg0->PortIdentifier;
336 rid->roles = FC_RPORT_ROLE_UNKNOWN;
Michael Reed05e8ec12006-01-13 14:31:54 -0600337
338 return 0;
339}
340
341static void
342mptfc_register_dev(MPT_ADAPTER *ioc, int channel, FCDevicePage0_t *pg0)
343{
344 struct fc_rport_identifiers rport_ids;
345 struct fc_rport *rport;
346 struct mptfc_rport_info *ri;
Michael Reed3bc7bf12006-01-25 18:05:18 -0700347 int new_ri = 1;
Moore, Eric65207fe2006-04-21 16:14:35 -0600348 u64 pn, nn;
Michael Reed3bc7bf12006-01-25 18:05:18 -0700349 VirtTarget *vtarget;
mdr@sgi.com6dd727d2006-05-01 13:07:04 -0500350 u32 roles = FC_RPORT_ROLE_UNKNOWN;
Michael Reed05e8ec12006-01-13 14:31:54 -0600351
352 if (mptfc_generate_rport_ids(pg0, &rport_ids) < 0)
353 return;
354
mdr@sgi.com6dd727d2006-05-01 13:07:04 -0500355 roles |= FC_RPORT_ROLE_FCP_TARGET;
356 if (pg0->Protocol & MPI_FC_DEVICE_PAGE0_PROT_FCP_INITIATOR)
357 roles |= FC_RPORT_ROLE_FCP_INITIATOR;
358
Michael Reed05e8ec12006-01-13 14:31:54 -0600359 /* scan list looking for a match */
Michael Reed05e8ec12006-01-13 14:31:54 -0600360 list_for_each_entry(ri, &ioc->fc_rports, list) {
Michael Reed3bc7bf12006-01-25 18:05:18 -0700361 pn = (u64)ri->pg0.WWPN.High << 32 | (u64)ri->pg0.WWPN.Low;
362 if (pn == rport_ids.port_name) { /* match */
Michael Reed05e8ec12006-01-13 14:31:54 -0600363 list_move_tail(&ri->list, &ioc->fc_rports);
Michael Reed3bc7bf12006-01-25 18:05:18 -0700364 new_ri = 0;
Michael Reed05e8ec12006-01-13 14:31:54 -0600365 break;
366 }
367 }
Michael Reed3bc7bf12006-01-25 18:05:18 -0700368 if (new_ri) { /* allocate one */
Michael Reed05e8ec12006-01-13 14:31:54 -0600369 ri = kzalloc(sizeof(struct mptfc_rport_info), GFP_KERNEL);
370 if (!ri)
371 return;
Michael Reed05e8ec12006-01-13 14:31:54 -0600372 list_add_tail(&ri->list, &ioc->fc_rports);
373 }
374
375 ri->pg0 = *pg0; /* add/update pg0 data */
376 ri->flags &= ~MPT_RPORT_INFO_FLAGS_MISSING;
377
Michael Reed3bc7bf12006-01-25 18:05:18 -0700378 /* MPT_RPORT_INFO_FLAGS_REGISTERED - rport not previously deleted */
Michael Reed05e8ec12006-01-13 14:31:54 -0600379 if (!(ri->flags & MPT_RPORT_INFO_FLAGS_REGISTERED)) {
380 ri->flags |= MPT_RPORT_INFO_FLAGS_REGISTERED;
Michael Reed3bc7bf12006-01-25 18:05:18 -0700381 rport = fc_remote_port_add(ioc->sh, channel, &rport_ids);
Michael Reed05e8ec12006-01-13 14:31:54 -0600382 if (rport) {
Michael Reed3bc7bf12006-01-25 18:05:18 -0700383 ri->rport = rport;
384 if (new_ri) /* may have been reset by user */
385 rport->dev_loss_tmo = mptfc_dev_loss_tmo;
Michael Reed05e8ec12006-01-13 14:31:54 -0600386 /*
387 * if already mapped, remap here. If not mapped,
Michael Reed3bc7bf12006-01-25 18:05:18 -0700388 * target_alloc will allocate vtarget and map,
389 * slave_alloc will fill in vdev from vtarget.
Michael Reed05e8ec12006-01-13 14:31:54 -0600390 */
Michael Reed3bc7bf12006-01-25 18:05:18 -0700391 if (ri->starget) {
392 vtarget = ri->starget->hostdata;
393 if (vtarget) {
394 vtarget->target_id = pg0->CurrentTargetID;
395 vtarget->bus_id = pg0->CurrentBus;
Michael Reed3bc7bf12006-01-25 18:05:18 -0700396 }
Michael Reed05e8ec12006-01-13 14:31:54 -0600397 }
Moore, Eric65207fe2006-04-21 16:14:35 -0600398 *((struct mptfc_rport_info **)rport->dd_data) = ri;
mdr@sgi.com6dd727d2006-05-01 13:07:04 -0500399 /* scan will be scheduled once rport becomes a target */
400 fc_remote_port_rolechg(rport,roles);
Moore, Eric65207fe2006-04-21 16:14:35 -0600401
402 pn = (u64)ri->pg0.WWPN.High << 32 | (u64)ri->pg0.WWPN.Low;
403 nn = (u64)ri->pg0.WWNN.High << 32 | (u64)ri->pg0.WWNN.Low;
Michael Reed3bc7bf12006-01-25 18:05:18 -0700404 dfcprintk ((MYIOC_s_INFO_FMT
405 "mptfc_reg_dev.%d: %x, %llx / %llx, tid %d, "
Michael Reed05e8ec12006-01-13 14:31:54 -0600406 "rport tid %d, tmo %d\n",
Michael Reed3bc7bf12006-01-25 18:05:18 -0700407 ioc->name,
Moore, Eric914c2d82006-03-14 09:19:36 -0700408 ioc->sh->host_no,
Michael Reed05e8ec12006-01-13 14:31:54 -0600409 pg0->PortIdentifier,
Moore, Eric65207fe2006-04-21 16:14:35 -0600410 (unsigned long long)nn,
411 (unsigned long long)pn,
Michael Reed05e8ec12006-01-13 14:31:54 -0600412 pg0->CurrentTargetID,
413 ri->rport->scsi_target_id,
Michael Reed3bc7bf12006-01-25 18:05:18 -0700414 ri->rport->dev_loss_tmo));
Michael Reed05e8ec12006-01-13 14:31:54 -0600415 } else {
416 list_del(&ri->list);
417 kfree(ri);
418 ri = NULL;
419 }
420 }
Michael Reed05e8ec12006-01-13 14:31:54 -0600421}
422
423/*
Michael Reed3bc7bf12006-01-25 18:05:18 -0700424 * OS entry point to allow for host driver to free allocated memory
425 * Called if no device present or device being unloaded
426 */
427static void
428mptfc_target_destroy(struct scsi_target *starget)
429{
430 struct fc_rport *rport;
431 struct mptfc_rport_info *ri;
432
433 rport = starget_to_rport(starget);
434 if (rport) {
435 ri = *((struct mptfc_rport_info **)rport->dd_data);
436 if (ri) /* better be! */
437 ri->starget = NULL;
438 }
439 if (starget->hostdata)
440 kfree(starget->hostdata);
441 starget->hostdata = NULL;
442}
443
444/*
445 * OS entry point to allow host driver to alloc memory
446 * for each scsi target. Called once per device the bus scan.
447 * Return non-zero if allocation fails.
448 */
449static int
450mptfc_target_alloc(struct scsi_target *starget)
451{
452 VirtTarget *vtarget;
453 struct fc_rport *rport;
454 struct mptfc_rport_info *ri;
455 int rc;
456
457 vtarget = kzalloc(sizeof(VirtTarget), GFP_KERNEL);
458 if (!vtarget)
459 return -ENOMEM;
460 starget->hostdata = vtarget;
461
462 rc = -ENODEV;
463 rport = starget_to_rport(starget);
464 if (rport) {
465 ri = *((struct mptfc_rport_info **)rport->dd_data);
466 if (ri) { /* better be! */
467 vtarget->target_id = ri->pg0.CurrentTargetID;
468 vtarget->bus_id = ri->pg0.CurrentBus;
469 ri->starget = starget;
Michael Reed3bc7bf12006-01-25 18:05:18 -0700470 rc = 0;
471 }
472 }
473 if (rc != 0) {
474 kfree(vtarget);
475 starget->hostdata = NULL;
476 }
477
478 return rc;
479}
480
481/*
Michael Reed05e8ec12006-01-13 14:31:54 -0600482 * OS entry point to allow host driver to alloc memory
483 * for each scsi device. Called once per device the bus scan.
484 * Return non-zero if allocation fails.
485 * Init memory once per LUN.
486 */
Adrian Bunk03fbcbc2006-01-25 02:00:52 +0100487static int
Michael Reed05e8ec12006-01-13 14:31:54 -0600488mptfc_slave_alloc(struct scsi_device *sdev)
489{
490 MPT_SCSI_HOST *hd;
491 VirtTarget *vtarget;
492 VirtDevice *vdev;
493 struct scsi_target *starget;
494 struct fc_rport *rport;
Michael Reed05e8ec12006-01-13 14:31:54 -0600495
496
Moore, Eric65207fe2006-04-21 16:14:35 -0600497 starget = scsi_target(sdev);
498 rport = starget_to_rport(starget);
Michael Reed05e8ec12006-01-13 14:31:54 -0600499
500 if (!rport || fc_remote_port_chkready(rport))
501 return -ENXIO;
502
503 hd = (MPT_SCSI_HOST *)sdev->host->hostdata;
504
Michael Reed3bc7bf12006-01-25 18:05:18 -0700505 vdev = kzalloc(sizeof(VirtDevice), GFP_KERNEL);
Michael Reed05e8ec12006-01-13 14:31:54 -0600506 if (!vdev) {
507 printk(MYIOC_s_ERR_FMT "slave_alloc kmalloc(%zd) FAILED!\n",
508 hd->ioc->name, sizeof(VirtDevice));
509 return -ENOMEM;
510 }
Michael Reed05e8ec12006-01-13 14:31:54 -0600511
Michael Reed05e8ec12006-01-13 14:31:54 -0600512
Michael Reed05e8ec12006-01-13 14:31:54 -0600513 sdev->hostdata = vdev;
Michael Reed05e8ec12006-01-13 14:31:54 -0600514 vtarget = starget->hostdata;
Michael Reed3bc7bf12006-01-25 18:05:18 -0700515
Michael Reed05e8ec12006-01-13 14:31:54 -0600516 if (vtarget->num_luns == 0) {
Michael Reed3bc7bf12006-01-25 18:05:18 -0700517 vtarget->ioc_id = hd->ioc->id;
Eric Mooreba856d32006-07-11 17:34:01 -0600518 vtarget->tflags = MPT_TARGET_FLAGS_Q_YES;
Michael Reed05e8ec12006-01-13 14:31:54 -0600519 hd->Targets[sdev->id] = vtarget;
520 }
521
Michael Reed05e8ec12006-01-13 14:31:54 -0600522 vdev->vtarget = vtarget;
Michael Reed05e8ec12006-01-13 14:31:54 -0600523 vdev->lun = sdev->lun;
Michael Reed05e8ec12006-01-13 14:31:54 -0600524
Michael Reed05e8ec12006-01-13 14:31:54 -0600525 vtarget->num_luns++;
526
Moore, Eric65207fe2006-04-21 16:14:35 -0600527
Moore, Eric914c2d82006-03-14 09:19:36 -0700528#ifdef DMPT_DEBUG_FC
Moore, Eric65207fe2006-04-21 16:14:35 -0600529 {
530 u64 nn, pn;
Moore, Eric914c2d82006-03-14 09:19:36 -0700531 struct mptfc_rport_info *ri;
532 ri = *((struct mptfc_rport_info **)rport->dd_data);
Moore, Eric65207fe2006-04-21 16:14:35 -0600533 pn = (u64)ri->pg0.WWPN.High << 32 | (u64)ri->pg0.WWPN.Low;
534 nn = (u64)ri->pg0.WWNN.High << 32 | (u64)ri->pg0.WWNN.Low;
Michael Reed3bc7bf12006-01-25 18:05:18 -0700535 dfcprintk ((MYIOC_s_INFO_FMT
536 "mptfc_slv_alloc.%d: num_luns %d, sdev.id %d, "
Michael Reed05e8ec12006-01-13 14:31:54 -0600537 "CurrentTargetID %d, %x %llx %llx\n",
Moore, Eric914c2d82006-03-14 09:19:36 -0700538 hd->ioc->name,
Michael Reed3bc7bf12006-01-25 18:05:18 -0700539 sdev->host->host_no,
540 vtarget->num_luns,
541 sdev->id, ri->pg0.CurrentTargetID,
Moore, Eric65207fe2006-04-21 16:14:35 -0600542 ri->pg0.PortIdentifier,
543 (unsigned long long)pn,
544 (unsigned long long)nn));
Moore, Eric914c2d82006-03-14 09:19:36 -0700545 }
546#endif
Michael Reed05e8ec12006-01-13 14:31:54 -0600547
548 return 0;
549}
550
551static int
552mptfc_qcmd(struct scsi_cmnd *SCpnt, void (*done)(struct scsi_cmnd *))
553{
Michael Reed3bc7bf12006-01-25 18:05:18 -0700554 struct mptfc_rport_info *ri;
Michael Reed05e8ec12006-01-13 14:31:54 -0600555 struct fc_rport *rport = starget_to_rport(scsi_target(SCpnt->device));
556 int err;
557
558 err = fc_remote_port_chkready(rport);
559 if (unlikely(err)) {
560 SCpnt->result = err;
561 done(SCpnt);
562 return 0;
563 }
Michael Reed3bc7bf12006-01-25 18:05:18 -0700564
Moore, Eric65207fe2006-04-21 16:14:35 -0600565 /* dd_data is null until finished adding target */
566 ri = *((struct mptfc_rport_info **)rport->dd_data);
567 if (unlikely(!ri)) {
568 dfcprintk ((MYIOC_s_INFO_FMT
569 "mptfc_qcmd.%d: %d:%d, dd_data is null.\n",
570 ((MPT_SCSI_HOST *) SCpnt->device->host->hostdata)->ioc->name,
571 ((MPT_SCSI_HOST *) SCpnt->device->host->hostdata)->ioc->sh->host_no,
572 SCpnt->device->id,SCpnt->device->lun));
573 SCpnt->result = DID_IMM_RETRY << 16;
574 done(SCpnt);
575 return 0;
576 }
577
578 err = mptscsih_qcmd(SCpnt,done);
579#ifdef DMPT_DEBUG_FC
580 if (unlikely(err)) {
581 dfcprintk ((MYIOC_s_INFO_FMT
Michael Reed419835e2006-05-24 15:07:40 -0500582 "mptfc_qcmd.%d: %d:%d, mptscsih_qcmd returns non-zero, (%x).\n",
Moore, Eric65207fe2006-04-21 16:14:35 -0600583 ((MPT_SCSI_HOST *) SCpnt->device->host->hostdata)->ioc->name,
584 ((MPT_SCSI_HOST *) SCpnt->device->host->hostdata)->ioc->sh->host_no,
Michael Reed419835e2006-05-24 15:07:40 -0500585 SCpnt->device->id,SCpnt->device->lun,err));
Moore, Eric65207fe2006-04-21 16:14:35 -0600586 }
587#endif
588 return err;
Michael Reed05e8ec12006-01-13 14:31:54 -0600589}
590
Michael Reed80d3ac72006-05-24 15:07:09 -0500591/*
592 * mptfc_GetFcPortPage0 - Fetch FCPort config Page0.
593 * @ioc: Pointer to MPT_ADAPTER structure
594 * @portnum: IOC Port number
595 *
596 * Return: 0 for success
597 * -ENOMEM if no memory available
598 * -EPERM if not allowed due to ISR context
599 * -EAGAIN if no msg frames currently available
600 * -EFAULT for non-successful reply or no reply (timeout)
601 * -EINVAL portnum arg out of range (hardwired to two elements)
602 */
603static int
604mptfc_GetFcPortPage0(MPT_ADAPTER *ioc, int portnum)
605{
606 ConfigPageHeader_t hdr;
607 CONFIGPARMS cfg;
608 FCPortPage0_t *ppage0_alloc;
609 FCPortPage0_t *pp0dest;
610 dma_addr_t page0_dma;
611 int data_sz;
612 int copy_sz;
613 int rc;
614 int count = 400;
615
616 if (portnum > 1)
617 return -EINVAL;
618
619 /* Get FCPort Page 0 header */
620 hdr.PageVersion = 0;
621 hdr.PageLength = 0;
622 hdr.PageNumber = 0;
623 hdr.PageType = MPI_CONFIG_PAGETYPE_FC_PORT;
624 cfg.cfghdr.hdr = &hdr;
625 cfg.physAddr = -1;
626 cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
627 cfg.dir = 0;
628 cfg.pageAddr = portnum;
629 cfg.timeout = 0;
630
631 if ((rc = mpt_config(ioc, &cfg)) != 0)
632 return rc;
633
634 if (hdr.PageLength == 0)
635 return 0;
636
637 data_sz = hdr.PageLength * 4;
638 rc = -ENOMEM;
639 ppage0_alloc = (FCPortPage0_t *) pci_alloc_consistent(ioc->pcidev, data_sz, &page0_dma);
640 if (ppage0_alloc) {
641
642 try_again:
643 memset((u8 *)ppage0_alloc, 0, data_sz);
644 cfg.physAddr = page0_dma;
645 cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
646
647 if ((rc = mpt_config(ioc, &cfg)) == 0) {
648 /* save the data */
649 pp0dest = &ioc->fc_port_page0[portnum];
650 copy_sz = min_t(int, sizeof(FCPortPage0_t), data_sz);
651 memcpy(pp0dest, ppage0_alloc, copy_sz);
652
653 /*
654 * Normalize endianness of structure data,
655 * by byte-swapping all > 1 byte fields!
656 */
657 pp0dest->Flags = le32_to_cpu(pp0dest->Flags);
658 pp0dest->PortIdentifier = le32_to_cpu(pp0dest->PortIdentifier);
659 pp0dest->WWNN.Low = le32_to_cpu(pp0dest->WWNN.Low);
660 pp0dest->WWNN.High = le32_to_cpu(pp0dest->WWNN.High);
661 pp0dest->WWPN.Low = le32_to_cpu(pp0dest->WWPN.Low);
662 pp0dest->WWPN.High = le32_to_cpu(pp0dest->WWPN.High);
663 pp0dest->SupportedServiceClass = le32_to_cpu(pp0dest->SupportedServiceClass);
664 pp0dest->SupportedSpeeds = le32_to_cpu(pp0dest->SupportedSpeeds);
665 pp0dest->CurrentSpeed = le32_to_cpu(pp0dest->CurrentSpeed);
666 pp0dest->MaxFrameSize = le32_to_cpu(pp0dest->MaxFrameSize);
667 pp0dest->FabricWWNN.Low = le32_to_cpu(pp0dest->FabricWWNN.Low);
668 pp0dest->FabricWWNN.High = le32_to_cpu(pp0dest->FabricWWNN.High);
669 pp0dest->FabricWWPN.Low = le32_to_cpu(pp0dest->FabricWWPN.Low);
670 pp0dest->FabricWWPN.High = le32_to_cpu(pp0dest->FabricWWPN.High);
671 pp0dest->DiscoveredPortsCount = le32_to_cpu(pp0dest->DiscoveredPortsCount);
672 pp0dest->MaxInitiators = le32_to_cpu(pp0dest->MaxInitiators);
673
674 /*
675 * if still doing discovery,
676 * hang loose a while until finished
677 */
678 if (pp0dest->PortState == MPI_FCPORTPAGE0_PORTSTATE_UNKNOWN) {
679 if (count-- > 0) {
Michael Reedd6be06c2006-05-24 15:07:57 -0500680 msleep(100);
Michael Reed80d3ac72006-05-24 15:07:09 -0500681 goto try_again;
682 }
683 printk(MYIOC_s_INFO_FMT "Firmware discovery not"
684 " complete.\n",
685 ioc->name);
686 }
687 }
688
689 pci_free_consistent(ioc->pcidev, data_sz, (u8 *) ppage0_alloc, page0_dma);
690 }
691
692 return rc;
693}
694
Michael Reedca2f9382006-05-24 15:07:24 -0500695static int
696mptfc_WriteFcPortPage1(MPT_ADAPTER *ioc, int portnum)
697{
698 ConfigPageHeader_t hdr;
699 CONFIGPARMS cfg;
700 int rc;
701
702 if (portnum > 1)
703 return -EINVAL;
704
705 if (!(ioc->fc_data.fc_port_page1[portnum].data))
706 return -EINVAL;
707
708 /* get fcport page 1 header */
709 hdr.PageVersion = 0;
710 hdr.PageLength = 0;
711 hdr.PageNumber = 1;
712 hdr.PageType = MPI_CONFIG_PAGETYPE_FC_PORT;
713 cfg.cfghdr.hdr = &hdr;
714 cfg.physAddr = -1;
715 cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
716 cfg.dir = 0;
717 cfg.pageAddr = portnum;
718 cfg.timeout = 0;
719
720 if ((rc = mpt_config(ioc, &cfg)) != 0)
721 return rc;
722
723 if (hdr.PageLength == 0)
724 return -ENODEV;
725
726 if (hdr.PageLength*4 != ioc->fc_data.fc_port_page1[portnum].pg_sz)
727 return -EINVAL;
728
729 cfg.physAddr = ioc->fc_data.fc_port_page1[portnum].dma;
730 cfg.action = MPI_CONFIG_ACTION_PAGE_WRITE_CURRENT;
731 cfg.dir = 1;
732
733 rc = mpt_config(ioc, &cfg);
734
735 return rc;
736}
737
738static int
739mptfc_GetFcPortPage1(MPT_ADAPTER *ioc, int portnum)
740{
741 ConfigPageHeader_t hdr;
742 CONFIGPARMS cfg;
743 FCPortPage1_t *page1_alloc;
744 dma_addr_t page1_dma;
745 int data_sz;
746 int rc;
747
748 if (portnum > 1)
749 return -EINVAL;
750
751 /* get fcport page 1 header */
752 hdr.PageVersion = 0;
753 hdr.PageLength = 0;
754 hdr.PageNumber = 1;
755 hdr.PageType = MPI_CONFIG_PAGETYPE_FC_PORT;
756 cfg.cfghdr.hdr = &hdr;
757 cfg.physAddr = -1;
758 cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
759 cfg.dir = 0;
760 cfg.pageAddr = portnum;
761 cfg.timeout = 0;
762
763 if ((rc = mpt_config(ioc, &cfg)) != 0)
764 return rc;
765
766 if (hdr.PageLength == 0)
767 return -ENODEV;
768
769start_over:
770
771 if (ioc->fc_data.fc_port_page1[portnum].data == NULL) {
772 data_sz = hdr.PageLength * 4;
773 if (data_sz < sizeof(FCPortPage1_t))
774 data_sz = sizeof(FCPortPage1_t);
775
776 page1_alloc = (FCPortPage1_t *) pci_alloc_consistent(ioc->pcidev,
777 data_sz,
778 &page1_dma);
779 if (!page1_alloc)
780 return -ENOMEM;
781 }
782 else {
783 page1_alloc = ioc->fc_data.fc_port_page1[portnum].data;
784 page1_dma = ioc->fc_data.fc_port_page1[portnum].dma;
785 data_sz = ioc->fc_data.fc_port_page1[portnum].pg_sz;
786 if (hdr.PageLength * 4 > data_sz) {
787 ioc->fc_data.fc_port_page1[portnum].data = NULL;
788 pci_free_consistent(ioc->pcidev, data_sz, (u8 *)
789 page1_alloc, page1_dma);
790 goto start_over;
791 }
792 }
793
794 memset(page1_alloc,0,data_sz);
795
796 cfg.physAddr = page1_dma;
797 cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
798
799 if ((rc = mpt_config(ioc, &cfg)) == 0) {
800 ioc->fc_data.fc_port_page1[portnum].data = page1_alloc;
801 ioc->fc_data.fc_port_page1[portnum].pg_sz = data_sz;
802 ioc->fc_data.fc_port_page1[portnum].dma = page1_dma;
803 }
804 else {
805 ioc->fc_data.fc_port_page1[portnum].data = NULL;
806 pci_free_consistent(ioc->pcidev, data_sz, (u8 *)
807 page1_alloc, page1_dma);
808 }
809
810 return rc;
811}
812
813static void
814mptfc_SetFcPortPage1_defaults(MPT_ADAPTER *ioc)
815{
816 int ii;
817 FCPortPage1_t *pp1;
818
819 #define MPTFC_FW_DEVICE_TIMEOUT (1)
820 #define MPTFC_FW_IO_PEND_TIMEOUT (1)
821 #define ON_FLAGS (MPI_FCPORTPAGE1_FLAGS_IMMEDIATE_ERROR_REPLY)
822 #define OFF_FLAGS (MPI_FCPORTPAGE1_FLAGS_VERBOSE_RESCAN_EVENTS)
823
824 for (ii=0; ii<ioc->facts.NumberOfPorts; ii++) {
825 if (mptfc_GetFcPortPage1(ioc, ii) != 0)
826 continue;
827 pp1 = ioc->fc_data.fc_port_page1[ii].data;
828 if ((pp1->InitiatorDeviceTimeout == MPTFC_FW_DEVICE_TIMEOUT)
829 && (pp1->InitiatorIoPendTimeout == MPTFC_FW_IO_PEND_TIMEOUT)
830 && ((pp1->Flags & ON_FLAGS) == ON_FLAGS)
831 && ((pp1->Flags & OFF_FLAGS) == 0))
832 continue;
833 pp1->InitiatorDeviceTimeout = MPTFC_FW_DEVICE_TIMEOUT;
834 pp1->InitiatorIoPendTimeout = MPTFC_FW_IO_PEND_TIMEOUT;
835 pp1->Flags &= ~OFF_FLAGS;
836 pp1->Flags |= ON_FLAGS;
837 mptfc_WriteFcPortPage1(ioc, ii);
838 }
839}
840
841
Michael Reed05e8ec12006-01-13 14:31:54 -0600842static void
843mptfc_init_host_attr(MPT_ADAPTER *ioc,int portnum)
844{
Michael Reed5d947f22006-07-31 12:19:30 -0500845 unsigned class = 0;
846 unsigned cos = 0;
847 unsigned speed;
848 unsigned port_type;
849 unsigned port_state;
850 FCPortPage0_t *pp0;
851 struct Scsi_Host *sh;
852 char *sn;
Michael Reed05e8ec12006-01-13 14:31:54 -0600853
854 /* don't know what to do as only one scsi (fc) host was allocated */
855 if (portnum != 0)
856 return;
857
Michael Reed5d947f22006-07-31 12:19:30 -0500858 pp0 = &ioc->fc_port_page0[portnum];
859 sh = ioc->sh;
860
861 sn = fc_host_symbolic_name(sh);
862 snprintf(sn, FC_SYMBOLIC_NAME_SIZE, "%s %s%08xh",
863 ioc->prod_name,
864 MPT_FW_REV_MAGIC_ID_STRING,
865 ioc->facts.FWVersion.Word);
866
867 fc_host_tgtid_bind_type(sh) = FC_TGTID_BIND_BY_WWPN;
868
869 fc_host_maxframe_size(sh) = pp0->MaxFrameSize;
870
871 fc_host_node_name(sh) =
872 (u64)pp0->WWNN.High << 32 | (u64)pp0->WWNN.Low;
873
874 fc_host_port_name(sh) =
875 (u64)pp0->WWPN.High << 32 | (u64)pp0->WWPN.Low;
876
877 fc_host_port_id(sh) = pp0->PortIdentifier;
878
879 class = pp0->SupportedServiceClass;
Michael Reed05e8ec12006-01-13 14:31:54 -0600880 if (class & MPI_FCPORTPAGE0_SUPPORT_CLASS_1)
881 cos |= FC_COS_CLASS1;
882 if (class & MPI_FCPORTPAGE0_SUPPORT_CLASS_2)
883 cos |= FC_COS_CLASS2;
884 if (class & MPI_FCPORTPAGE0_SUPPORT_CLASS_3)
885 cos |= FC_COS_CLASS3;
Michael Reed5d947f22006-07-31 12:19:30 -0500886 fc_host_supported_classes(sh) = cos;
Michael Reed05e8ec12006-01-13 14:31:54 -0600887
Michael Reed5d947f22006-07-31 12:19:30 -0500888 if (pp0->CurrentSpeed == MPI_FCPORTPAGE0_CURRENT_SPEED_1GBIT)
889 speed = FC_PORTSPEED_1GBIT;
890 else if (pp0->CurrentSpeed == MPI_FCPORTPAGE0_CURRENT_SPEED_2GBIT)
891 speed = FC_PORTSPEED_2GBIT;
892 else if (pp0->CurrentSpeed == MPI_FCPORTPAGE0_CURRENT_SPEED_4GBIT)
893 speed = FC_PORTSPEED_4GBIT;
894 else if (pp0->CurrentSpeed == MPI_FCPORTPAGE0_CURRENT_SPEED_10GBIT)
895 speed = FC_PORTSPEED_10GBIT;
896 else
897 speed = FC_PORTSPEED_UNKNOWN;
898 fc_host_speed(sh) = speed;
Michael Reed05e8ec12006-01-13 14:31:54 -0600899
Michael Reed5d947f22006-07-31 12:19:30 -0500900 speed = 0;
901 if (pp0->SupportedSpeeds & MPI_FCPORTPAGE0_SUPPORT_1GBIT_SPEED)
902 speed |= FC_PORTSPEED_1GBIT;
903 if (pp0->SupportedSpeeds & MPI_FCPORTPAGE0_SUPPORT_2GBIT_SPEED)
904 speed |= FC_PORTSPEED_2GBIT;
905 if (pp0->SupportedSpeeds & MPI_FCPORTPAGE0_SUPPORT_4GBIT_SPEED)
906 speed |= FC_PORTSPEED_4GBIT;
907 if (pp0->SupportedSpeeds & MPI_FCPORTPAGE0_SUPPORT_10GBIT_SPEED)
908 speed |= FC_PORTSPEED_10GBIT;
909 fc_host_supported_speeds(sh) = speed;
Michael Reed05e8ec12006-01-13 14:31:54 -0600910
Michael Reed5d947f22006-07-31 12:19:30 -0500911 port_state = FC_PORTSTATE_UNKNOWN;
912 if (pp0->PortState == MPI_FCPORTPAGE0_PORTSTATE_ONLINE)
913 port_state = FC_PORTSTATE_ONLINE;
914 else if (pp0->PortState == MPI_FCPORTPAGE0_PORTSTATE_OFFLINE)
915 port_state = FC_PORTSTATE_LINKDOWN;
916 fc_host_port_state(sh) = port_state;
Michael Reed05e8ec12006-01-13 14:31:54 -0600917
Michael Reed5d947f22006-07-31 12:19:30 -0500918 port_type = FC_PORTTYPE_UNKNOWN;
919 if (pp0->Flags & MPI_FCPORTPAGE0_FLAGS_ATTACH_POINT_TO_POINT)
920 port_type = FC_PORTTYPE_PTP;
921 else if (pp0->Flags & MPI_FCPORTPAGE0_FLAGS_ATTACH_PRIVATE_LOOP)
922 port_type = FC_PORTTYPE_LPORT;
923 else if (pp0->Flags & MPI_FCPORTPAGE0_FLAGS_ATTACH_PUBLIC_LOOP)
924 port_type = FC_PORTTYPE_NLPORT;
925 else if (pp0->Flags & MPI_FCPORTPAGE0_FLAGS_ATTACH_FABRIC_DIRECT)
926 port_type = FC_PORTTYPE_NPORT;
927 fc_host_port_type(sh) = port_type;
Michael Reed05e8ec12006-01-13 14:31:54 -0600928
Michael Reed5d947f22006-07-31 12:19:30 -0500929 fc_host_fabric_name(sh) =
930 (pp0->Flags & MPI_FCPORTPAGE0_FLAGS_FABRIC_WWN_VALID) ?
931 (u64) pp0->FabricWWNN.High << 32 | (u64) pp0->FabricWWPN.Low :
932 (u64)pp0->WWNN.High << 32 | (u64)pp0->WWNN.Low;
933
Michael Reed05e8ec12006-01-13 14:31:54 -0600934}
935
936static void
Michael Reed419835e2006-05-24 15:07:40 -0500937mptfc_setup_reset(void *arg)
938{
939 MPT_ADAPTER *ioc = (MPT_ADAPTER *)arg;
940 u64 pn;
941 struct mptfc_rport_info *ri;
942
943 /* reset about to happen, delete (block) all rports */
944 list_for_each_entry(ri, &ioc->fc_rports, list) {
945 if (ri->flags & MPT_RPORT_INFO_FLAGS_REGISTERED) {
946 ri->flags &= ~MPT_RPORT_INFO_FLAGS_REGISTERED;
947 fc_remote_port_delete(ri->rport); /* won't sleep */
948 ri->rport = NULL;
949
950 pn = (u64)ri->pg0.WWPN.High << 32 |
951 (u64)ri->pg0.WWPN.Low;
952 dfcprintk ((MYIOC_s_INFO_FMT
953 "mptfc_setup_reset.%d: %llx deleted\n",
954 ioc->name,
955 ioc->sh->host_no,
956 (unsigned long long)pn));
957 }
958 }
959}
960
961static void
Michael Reed05e8ec12006-01-13 14:31:54 -0600962mptfc_rescan_devices(void *arg)
963{
964 MPT_ADAPTER *ioc = (MPT_ADAPTER *)arg;
965 int ii;
966 int work_to_do;
Moore, Eric65207fe2006-04-21 16:14:35 -0600967 u64 pn;
Michael Reed05e8ec12006-01-13 14:31:54 -0600968 unsigned long flags;
969 struct mptfc_rport_info *ri;
970
971 do {
972 /* start by tagging all ports as missing */
Michael Reed05e8ec12006-01-13 14:31:54 -0600973 list_for_each_entry(ri, &ioc->fc_rports, list) {
974 if (ri->flags & MPT_RPORT_INFO_FLAGS_REGISTERED) {
975 ri->flags |= MPT_RPORT_INFO_FLAGS_MISSING;
976 }
977 }
Michael Reed05e8ec12006-01-13 14:31:54 -0600978
979 /*
980 * now rescan devices known to adapter,
981 * will reregister existing rports
982 */
983 for (ii=0; ii < ioc->facts.NumberOfPorts; ii++) {
Michael Reed80d3ac72006-05-24 15:07:09 -0500984 (void) mptfc_GetFcPortPage0(ioc, ii);
Michael Reed05e8ec12006-01-13 14:31:54 -0600985 mptfc_init_host_attr(ioc,ii); /* refresh */
986 mptfc_GetFcDevPage0(ioc,ii,mptfc_register_dev);
987 }
988
989 /* delete devices still missing */
Michael Reed05e8ec12006-01-13 14:31:54 -0600990 list_for_each_entry(ri, &ioc->fc_rports, list) {
991 /* if newly missing, delete it */
Moore, Eric65207fe2006-04-21 16:14:35 -0600992 if (ri->flags & MPT_RPORT_INFO_FLAGS_MISSING) {
Michael Reed05e8ec12006-01-13 14:31:54 -0600993
994 ri->flags &= ~(MPT_RPORT_INFO_FLAGS_REGISTERED|
995 MPT_RPORT_INFO_FLAGS_MISSING);
Moore, Eric65207fe2006-04-21 16:14:35 -0600996 fc_remote_port_delete(ri->rport); /* won't sleep */
Michael Reed3bc7bf12006-01-25 18:05:18 -0700997 ri->rport = NULL;
Moore, Eric65207fe2006-04-21 16:14:35 -0600998
999 pn = (u64)ri->pg0.WWPN.High << 32 |
1000 (u64)ri->pg0.WWPN.Low;
Michael Reed3bc7bf12006-01-25 18:05:18 -07001001 dfcprintk ((MYIOC_s_INFO_FMT
1002 "mptfc_rescan.%d: %llx deleted\n",
1003 ioc->name,
1004 ioc->sh->host_no,
Moore, Eric65207fe2006-04-21 16:14:35 -06001005 (unsigned long long)pn));
Michael Reed05e8ec12006-01-13 14:31:54 -06001006 }
1007 }
Michael Reed05e8ec12006-01-13 14:31:54 -06001008
1009 /*
1010 * allow multiple passes as target state
1011 * might have changed during scan
1012 */
1013 spin_lock_irqsave(&ioc->fc_rescan_work_lock, flags);
1014 if (ioc->fc_rescan_work_count > 2) /* only need one more */
1015 ioc->fc_rescan_work_count = 2;
1016 work_to_do = --ioc->fc_rescan_work_count;
1017 spin_unlock_irqrestore(&ioc->fc_rescan_work_lock, flags);
1018 } while (work_to_do);
1019}
1020
Moore, Eric Dean 2496af32005-04-22 18:02:41 -04001021static int
1022mptfc_probe(struct pci_dev *pdev, const struct pci_device_id *id)
1023{
1024 struct Scsi_Host *sh;
1025 MPT_SCSI_HOST *hd;
1026 MPT_ADAPTER *ioc;
1027 unsigned long flags;
Christoph Hellwig1ca00bb2006-01-13 18:27:50 +01001028 int ii;
Moore, Eric Dean 2496af32005-04-22 18:02:41 -04001029 int numSGE = 0;
1030 int scale;
1031 int ioc_cap;
Moore, Eric Dean 2496af32005-04-22 18:02:41 -04001032 int error=0;
1033 int r;
Michael Reed05e8ec12006-01-13 14:31:54 -06001034
Moore, Eric Dean 2496af32005-04-22 18:02:41 -04001035 if ((r = mpt_attach(pdev,id)) != 0)
1036 return r;
Michael Reed05e8ec12006-01-13 14:31:54 -06001037
Moore, Eric Dean 2496af32005-04-22 18:02:41 -04001038 ioc = pci_get_drvdata(pdev);
Moore, Eric Dean d335cc32005-04-30 17:09:38 -05001039 ioc->DoneCtx = mptfcDoneCtx;
1040 ioc->TaskCtx = mptfcTaskCtx;
1041 ioc->InternalCtx = mptfcInternalCtx;
Moore, Eric Dean 2496af32005-04-22 18:02:41 -04001042
1043 /* Added sanity check on readiness of the MPT adapter.
1044 */
1045 if (ioc->last_state != MPI_IOC_STATE_OPERATIONAL) {
1046 printk(MYIOC_s_WARN_FMT
1047 "Skipping because it's not operational!\n",
1048 ioc->name);
Moore, Eric Dean7acec1e2005-11-16 18:54:17 -07001049 error = -ENODEV;
1050 goto out_mptfc_probe;
Moore, Eric Dean 2496af32005-04-22 18:02:41 -04001051 }
1052
1053 if (!ioc->active) {
1054 printk(MYIOC_s_WARN_FMT "Skipping because it's disabled!\n",
1055 ioc->name);
Moore, Eric Dean7acec1e2005-11-16 18:54:17 -07001056 error = -ENODEV;
1057 goto out_mptfc_probe;
Moore, Eric Dean 2496af32005-04-22 18:02:41 -04001058 }
1059
1060 /* Sanity check - ensure at least 1 port is INITIATOR capable
1061 */
1062 ioc_cap = 0;
1063 for (ii=0; ii < ioc->facts.NumberOfPorts; ii++) {
1064 if (ioc->pfacts[ii].ProtocolFlags &
1065 MPI_PORTFACTS_PROTOCOL_INITIATOR)
1066 ioc_cap ++;
1067 }
1068
1069 if (!ioc_cap) {
1070 printk(MYIOC_s_WARN_FMT
1071 "Skipping ioc=%p because SCSI Initiator mode is NOT enabled!\n",
1072 ioc->name, ioc);
Michael Reed05e8ec12006-01-13 14:31:54 -06001073 return -ENODEV;
Moore, Eric Dean 2496af32005-04-22 18:02:41 -04001074 }
1075
1076 sh = scsi_host_alloc(&mptfc_driver_template, sizeof(MPT_SCSI_HOST));
1077
1078 if (!sh) {
1079 printk(MYIOC_s_WARN_FMT
1080 "Unable to register controller with SCSI subsystem\n",
1081 ioc->name);
Moore, Eric Dean7acec1e2005-11-16 18:54:17 -07001082 error = -1;
1083 goto out_mptfc_probe;
Moore, Eric Dean 2496af32005-04-22 18:02:41 -04001084 }
1085
Michael Reed80d3ac72006-05-24 15:07:09 -05001086 spin_lock_init(&ioc->fc_rescan_work_lock);
Michael Reed05e8ec12006-01-13 14:31:54 -06001087 INIT_WORK(&ioc->fc_rescan_work, mptfc_rescan_devices,(void *)ioc);
Michael Reed419835e2006-05-24 15:07:40 -05001088 INIT_WORK(&ioc->fc_setup_reset_work, mptfc_setup_reset, (void *)ioc);
Michael Reed05e8ec12006-01-13 14:31:54 -06001089
Moore, Eric Dean 2496af32005-04-22 18:02:41 -04001090 spin_lock_irqsave(&ioc->FreeQlock, flags);
1091
1092 /* Attach the SCSI Host to the IOC structure
1093 */
1094 ioc->sh = sh;
1095
1096 sh->io_port = 0;
1097 sh->n_io_port = 0;
1098 sh->irq = 0;
1099
1100 /* set 16 byte cdb's */
1101 sh->max_cmd_len = 16;
1102
1103 sh->max_id = MPT_MAX_FC_DEVICES<256 ? MPT_MAX_FC_DEVICES : 255;
1104
1105 sh->max_lun = MPT_LAST_LUN + 1;
1106 sh->max_channel = 0;
1107 sh->this_id = ioc->pfacts[0].PortSCSIID;
1108
1109 /* Required entry.
1110 */
1111 sh->unique_id = ioc->id;
1112
1113 /* Verify that we won't exceed the maximum
1114 * number of chain buffers
1115 * We can optimize: ZZ = req_sz/sizeof(SGE)
1116 * For 32bit SGE's:
1117 * numSGE = 1 + (ZZ-1)*(maxChain -1) + ZZ
1118 * + (req_sz - 64)/sizeof(SGE)
1119 * A slightly different algorithm is required for
1120 * 64bit SGEs.
1121 */
1122 scale = ioc->req_sz/(sizeof(dma_addr_t) + sizeof(u32));
1123 if (sizeof(dma_addr_t) == sizeof(u64)) {
1124 numSGE = (scale - 1) *
1125 (ioc->facts.MaxChainDepth-1) + scale +
1126 (ioc->req_sz - 60) / (sizeof(dma_addr_t) +
1127 sizeof(u32));
1128 } else {
1129 numSGE = 1 + (scale - 1) *
1130 (ioc->facts.MaxChainDepth-1) + scale +
1131 (ioc->req_sz - 64) / (sizeof(dma_addr_t) +
1132 sizeof(u32));
1133 }
1134
1135 if (numSGE < sh->sg_tablesize) {
1136 /* Reset this value */
1137 dprintk((MYIOC_s_INFO_FMT
1138 "Resetting sg_tablesize to %d from %d\n",
1139 ioc->name, numSGE, sh->sg_tablesize));
1140 sh->sg_tablesize = numSGE;
1141 }
1142
Moore, Eric Dean 2496af32005-04-22 18:02:41 -04001143 spin_unlock_irqrestore(&ioc->FreeQlock, flags);
1144
1145 hd = (MPT_SCSI_HOST *) sh->hostdata;
1146 hd->ioc = ioc;
1147
1148 /* SCSI needs scsi_cmnd lookup table!
1149 * (with size equal to req_depth*PtrSz!)
1150 */
Christoph Hellwig1ca00bb2006-01-13 18:27:50 +01001151 hd->ScsiLookup = kcalloc(ioc->req_depth, sizeof(void *), GFP_ATOMIC);
1152 if (!hd->ScsiLookup) {
Moore, Eric Dean 2496af32005-04-22 18:02:41 -04001153 error = -ENOMEM;
Moore, Eric Dean7acec1e2005-11-16 18:54:17 -07001154 goto out_mptfc_probe;
Moore, Eric Dean 2496af32005-04-22 18:02:41 -04001155 }
1156
Christoph Hellwig1ca00bb2006-01-13 18:27:50 +01001157 dprintk((MYIOC_s_INFO_FMT "ScsiLookup @ %p\n",
1158 ioc->name, hd->ScsiLookup));
Moore, Eric Dean 2496af32005-04-22 18:02:41 -04001159
1160 /* Allocate memory for the device structures.
1161 * A non-Null pointer at an offset
1162 * indicates a device exists.
1163 * max_id = 1 + maximum id (hosts.h)
1164 */
Christoph Hellwig1ca00bb2006-01-13 18:27:50 +01001165 hd->Targets = kcalloc(sh->max_id, sizeof(void *), GFP_ATOMIC);
1166 if (!hd->Targets) {
Moore, Eric Dean 2496af32005-04-22 18:02:41 -04001167 error = -ENOMEM;
Moore, Eric Dean7acec1e2005-11-16 18:54:17 -07001168 goto out_mptfc_probe;
Moore, Eric Dean 2496af32005-04-22 18:02:41 -04001169 }
1170
Christoph Hellwig1ca00bb2006-01-13 18:27:50 +01001171 dprintk((KERN_INFO " vdev @ %p\n", hd->Targets));
Moore, Eric Dean 2496af32005-04-22 18:02:41 -04001172
1173 /* Clear the TM flags
1174 */
1175 hd->tmPending = 0;
1176 hd->tmState = TM_STATE_NONE;
1177 hd->resetPending = 0;
1178 hd->abortSCpnt = NULL;
1179
1180 /* Clear the pointer used to store
1181 * single-threaded commands, i.e., those
1182 * issued during a bus scan, dv and
1183 * configuration pages.
1184 */
1185 hd->cmdPtr = NULL;
1186
1187 /* Initialize this SCSI Hosts' timers
1188 * To use, set the timer expires field
1189 * and add_timer
1190 */
1191 init_timer(&hd->timer);
1192 hd->timer.data = (unsigned long) hd;
1193 hd->timer.function = mptscsih_timer_expired;
1194
Moore, Eric Dean 2496af32005-04-22 18:02:41 -04001195 init_waitqueue_head(&hd->scandv_waitq);
1196 hd->scandv_wait_done = 0;
1197 hd->last_queue_full = 0;
1198
Michael Reed05e8ec12006-01-13 14:31:54 -06001199 sh->transportt = mptfc_transport_template;
Moore, Eric Dean 2496af32005-04-22 18:02:41 -04001200 error = scsi_add_host (sh, &ioc->pcidev->dev);
1201 if(error) {
1202 dprintk((KERN_ERR MYNAM
1203 "scsi_add_host failed\n"));
Moore, Eric Dean7acec1e2005-11-16 18:54:17 -07001204 goto out_mptfc_probe;
Moore, Eric Dean 2496af32005-04-22 18:02:41 -04001205 }
1206
Moore, Eric65207fe2006-04-21 16:14:35 -06001207 /* initialize workqueue */
1208
1209 snprintf(ioc->fc_rescan_work_q_name, KOBJ_NAME_LEN, "mptfc_wq_%d",
1210 sh->host_no);
1211 ioc->fc_rescan_work_q =
1212 create_singlethread_workqueue(ioc->fc_rescan_work_q_name);
1213 if (!ioc->fc_rescan_work_q)
1214 goto out_mptfc_probe;
1215
1216 /*
Michael Reed80d3ac72006-05-24 15:07:09 -05001217 * Pre-fetch FC port WWN and stuff...
1218 * (FCPortPage0_t stuff)
1219 */
1220 for (ii=0; ii < ioc->facts.NumberOfPorts; ii++) {
1221 (void) mptfc_GetFcPortPage0(ioc, ii);
1222 }
Michael Reedca2f9382006-05-24 15:07:24 -05001223 mptfc_SetFcPortPage1_defaults(ioc);
Michael Reed80d3ac72006-05-24 15:07:09 -05001224
1225 /*
Moore, Eric65207fe2006-04-21 16:14:35 -06001226 * scan for rports -
1227 * by doing it via the workqueue, some locking is eliminated
1228 */
1229
1230 ioc->fc_rescan_work_count = 1;
1231 queue_work(ioc->fc_rescan_work_q, &ioc->fc_rescan_work);
1232 flush_workqueue(ioc->fc_rescan_work_q);
Michael Reed05e8ec12006-01-13 14:31:54 -06001233
Moore, Eric Dean 2496af32005-04-22 18:02:41 -04001234 return 0;
1235
Moore, Eric Dean7acec1e2005-11-16 18:54:17 -07001236out_mptfc_probe:
Moore, Eric Dean 2496af32005-04-22 18:02:41 -04001237
1238 mptscsih_remove(pdev);
1239 return error;
1240}
1241
1242static struct pci_driver mptfc_driver = {
1243 .name = "mptfc",
1244 .id_table = mptfc_pci_table,
1245 .probe = mptfc_probe,
Michael Reed05e8ec12006-01-13 14:31:54 -06001246 .remove = __devexit_p(mptfc_remove),
Greg Kroah-Hartmand18c3db2005-06-23 17:35:56 -07001247 .shutdown = mptscsih_shutdown,
Moore, Eric Dean 2496af32005-04-22 18:02:41 -04001248#ifdef CONFIG_PM
1249 .suspend = mptscsih_suspend,
1250 .resume = mptscsih_resume,
1251#endif
1252};
1253
Michael Reed80d3ac72006-05-24 15:07:09 -05001254static int
1255mptfc_event_process(MPT_ADAPTER *ioc, EventNotificationReply_t *pEvReply)
1256{
1257 MPT_SCSI_HOST *hd;
1258 u8 event = le32_to_cpu(pEvReply->Event) & 0xFF;
1259 unsigned long flags;
1260 int rc=1;
1261
1262 devtverboseprintk((MYIOC_s_INFO_FMT "MPT event (=%02Xh) routed to SCSI host driver!\n",
1263 ioc->name, event));
1264
1265 if (ioc->sh == NULL ||
1266 ((hd = (MPT_SCSI_HOST *)ioc->sh->hostdata) == NULL))
1267 return 1;
1268
1269 switch (event) {
1270 case MPI_EVENT_RESCAN:
1271 spin_lock_irqsave(&ioc->fc_rescan_work_lock, flags);
1272 if (ioc->fc_rescan_work_q) {
1273 if (ioc->fc_rescan_work_count++ == 0) {
1274 queue_work(ioc->fc_rescan_work_q,
1275 &ioc->fc_rescan_work);
1276 }
1277 }
1278 spin_unlock_irqrestore(&ioc->fc_rescan_work_lock, flags);
1279 break;
1280 default:
1281 rc = mptscsih_event_process(ioc,pEvReply);
1282 break;
1283 }
1284 return rc;
1285}
1286
1287static int
1288mptfc_ioc_reset(MPT_ADAPTER *ioc, int reset_phase)
1289{
1290 int rc;
1291 unsigned long flags;
1292
1293 rc = mptscsih_ioc_reset(ioc,reset_phase);
1294 if (rc == 0)
1295 return rc;
1296
1297
1298 dtmprintk((KERN_WARNING MYNAM
1299 ": IOC %s_reset routed to FC host driver!\n",
1300 reset_phase==MPT_IOC_SETUP_RESET ? "setup" : (
1301 reset_phase==MPT_IOC_PRE_RESET ? "pre" : "post")));
1302
1303 if (reset_phase == MPT_IOC_SETUP_RESET) {
Michael Reed419835e2006-05-24 15:07:40 -05001304 spin_lock_irqsave(&ioc->fc_rescan_work_lock, flags);
1305 if (ioc->fc_rescan_work_q) {
1306 queue_work(ioc->fc_rescan_work_q,
1307 &ioc->fc_setup_reset_work);
1308 }
1309 spin_unlock_irqrestore(&ioc->fc_rescan_work_lock, flags);
Michael Reed80d3ac72006-05-24 15:07:09 -05001310 }
1311
1312 else if (reset_phase == MPT_IOC_PRE_RESET) {
1313 }
1314
1315 else { /* MPT_IOC_POST_RESET */
Michael Reedca2f9382006-05-24 15:07:24 -05001316 mptfc_SetFcPortPage1_defaults(ioc);
Michael Reed80d3ac72006-05-24 15:07:09 -05001317 spin_lock_irqsave(&ioc->fc_rescan_work_lock, flags);
1318 if (ioc->fc_rescan_work_q) {
1319 if (ioc->fc_rescan_work_count++ == 0) {
1320 queue_work(ioc->fc_rescan_work_q,
1321 &ioc->fc_rescan_work);
1322 }
1323 }
1324 spin_unlock_irqrestore(&ioc->fc_rescan_work_lock, flags);
1325 }
1326 return 1;
1327}
1328
Moore, Eric Dean 2496af32005-04-22 18:02:41 -04001329/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
1330/**
1331 * mptfc_init - Register MPT adapter(s) as SCSI host(s) with
1332 * linux scsi mid-layer.
1333 *
1334 * Returns 0 for success, non-zero for failure.
1335 */
1336static int __init
1337mptfc_init(void)
1338{
Michael Reed05e8ec12006-01-13 14:31:54 -06001339 int error;
Moore, Eric Dean 2496af32005-04-22 18:02:41 -04001340
1341 show_mptmod_ver(my_NAME, my_VERSION);
1342
Michael Reedca2f9382006-05-24 15:07:24 -05001343 /* sanity check module parameters */
1344 if (mptfc_dev_loss_tmo <= 0)
Michael Reed05e8ec12006-01-13 14:31:54 -06001345 mptfc_dev_loss_tmo = MPTFC_DEV_LOSS_TMO;
1346
1347 mptfc_transport_template =
1348 fc_attach_transport(&mptfc_transport_functions);
1349
1350 if (!mptfc_transport_template)
1351 return -ENODEV;
1352
Moore, Eric Dean 2496af32005-04-22 18:02:41 -04001353 mptfcDoneCtx = mpt_register(mptscsih_io_done, MPTFC_DRIVER);
1354 mptfcTaskCtx = mpt_register(mptscsih_taskmgmt_complete, MPTFC_DRIVER);
1355 mptfcInternalCtx = mpt_register(mptscsih_scandv_complete, MPTFC_DRIVER);
1356
Michael Reed80d3ac72006-05-24 15:07:09 -05001357 if (mpt_event_register(mptfcDoneCtx, mptfc_event_process) == 0) {
Moore, Eric3a892be2006-03-14 09:14:03 -07001358 devtverboseprintk((KERN_INFO MYNAM
Moore, Eric Dean 2496af32005-04-22 18:02:41 -04001359 ": Registered for IOC event notifications\n"));
1360 }
1361
Michael Reed80d3ac72006-05-24 15:07:09 -05001362 if (mpt_reset_register(mptfcDoneCtx, mptfc_ioc_reset) == 0) {
Moore, Eric Dean 2496af32005-04-22 18:02:41 -04001363 dprintk((KERN_INFO MYNAM
1364 ": Registered for IOC reset notifications\n"));
1365 }
1366
Michael Reed05e8ec12006-01-13 14:31:54 -06001367 error = pci_register_driver(&mptfc_driver);
Michael Reed3bc7bf12006-01-25 18:05:18 -07001368 if (error)
Michael Reed05e8ec12006-01-13 14:31:54 -06001369 fc_release_transport(mptfc_transport_template);
Michael Reed05e8ec12006-01-13 14:31:54 -06001370
1371 return error;
1372}
1373
1374/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
1375/**
1376 * mptfc_remove - Removed fc infrastructure for devices
1377 * @pdev: Pointer to pci_dev structure
1378 *
1379 */
Michael Reed3bc7bf12006-01-25 18:05:18 -07001380static void __devexit
1381mptfc_remove(struct pci_dev *pdev)
Michael Reed05e8ec12006-01-13 14:31:54 -06001382{
Moore, Eric65207fe2006-04-21 16:14:35 -06001383 MPT_ADAPTER *ioc = pci_get_drvdata(pdev);
1384 struct mptfc_rport_info *p, *n;
1385 struct workqueue_struct *work_q;
1386 unsigned long flags;
Michael Reedca2f9382006-05-24 15:07:24 -05001387 int ii;
Moore, Eric65207fe2006-04-21 16:14:35 -06001388
1389 /* destroy workqueue */
1390 if ((work_q=ioc->fc_rescan_work_q)) {
1391 spin_lock_irqsave(&ioc->fc_rescan_work_lock, flags);
1392 ioc->fc_rescan_work_q = NULL;
1393 spin_unlock_irqrestore(&ioc->fc_rescan_work_lock, flags);
1394 destroy_workqueue(work_q);
1395 }
Michael Reed05e8ec12006-01-13 14:31:54 -06001396
1397 fc_remove_host(ioc->sh);
1398
1399 list_for_each_entry_safe(p, n, &ioc->fc_rports, list) {
1400 list_del(&p->list);
1401 kfree(p);
1402 }
1403
Michael Reedca2f9382006-05-24 15:07:24 -05001404 for (ii=0; ii<ioc->facts.NumberOfPorts; ii++) {
1405 if (ioc->fc_data.fc_port_page1[ii].data) {
1406 pci_free_consistent(ioc->pcidev,
1407 ioc->fc_data.fc_port_page1[ii].pg_sz,
1408 (u8 *) ioc->fc_data.fc_port_page1[ii].data,
1409 ioc->fc_data.fc_port_page1[ii].dma);
1410 ioc->fc_data.fc_port_page1[ii].data = NULL;
1411 }
1412 }
1413
Michael Reed05e8ec12006-01-13 14:31:54 -06001414 mptscsih_remove(pdev);
Moore, Eric Dean 2496af32005-04-22 18:02:41 -04001415}
1416
1417/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
1418/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
1419/**
1420 * mptfc_exit - Unregisters MPT adapter(s)
1421 *
1422 */
1423static void __exit
1424mptfc_exit(void)
1425{
1426 pci_unregister_driver(&mptfc_driver);
Michael Reed05e8ec12006-01-13 14:31:54 -06001427 fc_release_transport(mptfc_transport_template);
1428
Moore, Eric Dean 2496af32005-04-22 18:02:41 -04001429 mpt_reset_deregister(mptfcDoneCtx);
1430 dprintk((KERN_INFO MYNAM
1431 ": Deregistered for IOC reset notifications\n"));
1432
1433 mpt_event_deregister(mptfcDoneCtx);
1434 dprintk((KERN_INFO MYNAM
1435 ": Deregistered for IOC event notifications\n"));
1436
1437 mpt_deregister(mptfcInternalCtx);
1438 mpt_deregister(mptfcTaskCtx);
1439 mpt_deregister(mptfcDoneCtx);
1440}
1441
1442module_init(mptfc_init);
1443module_exit(mptfc_exit);