3 * Linux MegaRAID device driver
5 * Copyright (c) 2003-2004 LSI Logic Corporation.
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version
10 * 2 of the License, or (at your option) any later version.
12 * FILE : megaraid_mbox.c
13 * Version : v2.20.5.1 (Nov 16 2006)
16 * Atul Mukker <Atul.Mukker@lsi.com>
17 * Sreenivas Bagalkote <Sreenivas.Bagalkote@lsi.com>
18 * Manoj Jose <Manoj.Jose@lsi.com>
21 * List of supported controllers
23 * OEM Product Name VID DID SSVID SSID
24 * --- ------------ --- --- ---- ----
25 * Dell PERC3/QC 101E 1960 1028 0471
26 * Dell PERC3/DC 101E 1960 1028 0493
27 * Dell PERC3/SC 101E 1960 1028 0475
28 * Dell PERC3/Di 1028 1960 1028 0123
29 * Dell PERC4/SC 1000 1960 1028 0520
30 * Dell PERC4/DC 1000 1960 1028 0518
31 * Dell PERC4/QC 1000 0407 1028 0531
32 * Dell PERC4/Di 1028 000F 1028 014A
33 * Dell PERC 4e/Si 1028 0013 1028 016c
34 * Dell PERC 4e/Di 1028 0013 1028 016d
35 * Dell PERC 4e/Di 1028 0013 1028 016e
36 * Dell PERC 4e/Di 1028 0013 1028 016f
37 * Dell PERC 4e/Di 1028 0013 1028 0170
38 * Dell PERC 4e/DC 1000 0408 1028 0002
39 * Dell PERC 4e/SC 1000 0408 1028 0001
42 * LSI MegaRAID SCSI 320-0 1000 1960 1000 A520
43 * LSI MegaRAID SCSI 320-1 1000 1960 1000 0520
44 * LSI MegaRAID SCSI 320-2 1000 1960 1000 0518
45 * LSI MegaRAID SCSI 320-0X 1000 0407 1000 0530
46 * LSI MegaRAID SCSI 320-2X 1000 0407 1000 0532
47 * LSI MegaRAID SCSI 320-4X 1000 0407 1000 0531
48 * LSI MegaRAID SCSI 320-1E 1000 0408 1000 0001
49 * LSI MegaRAID SCSI 320-2E 1000 0408 1000 0002
50 * LSI MegaRAID SATA 150-4 1000 1960 1000 4523
51 * LSI MegaRAID SATA 150-6 1000 1960 1000 0523
52 * LSI MegaRAID SATA 300-4X 1000 0409 1000 3004
53 * LSI MegaRAID SATA 300-8X 1000 0409 1000 3008
55 * INTEL RAID Controller SRCU42X 1000 0407 8086 0532
56 * INTEL RAID Controller SRCS16 1000 1960 8086 0523
57 * INTEL RAID Controller SRCU42E 1000 0408 8086 0002
58 * INTEL RAID Controller SRCZCRX 1000 0407 8086 0530
59 * INTEL RAID Controller SRCS28X 1000 0409 8086 3008
60 * INTEL RAID Controller SROMBU42E 1000 0408 8086 3431
61 * INTEL RAID Controller SROMBU42E 1000 0408 8086 3499
62 * INTEL RAID Controller SRCU51L 1000 1960 8086 0520
64 * FSC MegaRAID PCI Express ROMB 1000 0408 1734 1065
66 * ACER MegaRAID ROMB-2E 1000 0408 1025 004D
68 * NEC MegaRAID PCI Express ROMB 1000 0408 1033 8287
70 * For history of changes, see Documentation/ChangeLog.megaraid
73 #include "megaraid_mbox.h"
75 static int megaraid_init(void);
76 static void megaraid_exit(void);
78 static int megaraid_probe_one(struct pci_dev
*, const struct pci_device_id
*);
79 static void megaraid_detach_one(struct pci_dev
*);
80 static void megaraid_mbox_shutdown(struct pci_dev
*);
82 static int megaraid_io_attach(adapter_t
*);
83 static void megaraid_io_detach(adapter_t
*);
85 static int megaraid_init_mbox(adapter_t
*);
86 static void megaraid_fini_mbox(adapter_t
*);
88 static int megaraid_alloc_cmd_packets(adapter_t
*);
89 static void megaraid_free_cmd_packets(adapter_t
*);
91 static int megaraid_mbox_setup_dma_pools(adapter_t
*);
92 static void megaraid_mbox_teardown_dma_pools(adapter_t
*);
94 static int megaraid_sysfs_alloc_resources(adapter_t
*);
95 static void megaraid_sysfs_free_resources(adapter_t
*);
97 static int megaraid_abort_handler(struct scsi_cmnd
*);
98 static int megaraid_reset_handler(struct scsi_cmnd
*);
100 static int mbox_post_sync_cmd(adapter_t
*, uint8_t []);
101 static int mbox_post_sync_cmd_fast(adapter_t
*, uint8_t []);
102 static int megaraid_busywait_mbox(mraid_device_t
*);
103 static int megaraid_mbox_product_info(adapter_t
*);
104 static int megaraid_mbox_extended_cdb(adapter_t
*);
105 static int megaraid_mbox_support_ha(adapter_t
*, uint16_t *);
106 static int megaraid_mbox_support_random_del(adapter_t
*);
107 static int megaraid_mbox_get_max_sg(adapter_t
*);
108 static void megaraid_mbox_enum_raid_scsi(adapter_t
*);
109 static void megaraid_mbox_flush_cache(adapter_t
*);
110 static int megaraid_mbox_fire_sync_cmd(adapter_t
*);
112 static void megaraid_mbox_display_scb(adapter_t
*, scb_t
*);
113 static void megaraid_mbox_setup_device_map(adapter_t
*);
115 static int megaraid_queue_command(struct scsi_cmnd
*,
116 void (*)(struct scsi_cmnd
*));
117 static scb_t
*megaraid_mbox_build_cmd(adapter_t
*, struct scsi_cmnd
*, int *);
118 static void megaraid_mbox_runpendq(adapter_t
*, scb_t
*);
119 static void megaraid_mbox_prepare_pthru(adapter_t
*, scb_t
*,
121 static void megaraid_mbox_prepare_epthru(adapter_t
*, scb_t
*,
124 static irqreturn_t
megaraid_isr(int, void *);
126 static void megaraid_mbox_dpc(unsigned long);
128 static ssize_t
megaraid_sysfs_show_app_hndl(struct class_device
*, char *);
129 static ssize_t
megaraid_sysfs_show_ldnum(struct device
*, struct device_attribute
*attr
, char *);
131 static int megaraid_cmm_register(adapter_t
*);
132 static int megaraid_cmm_unregister(adapter_t
*);
133 static int megaraid_mbox_mm_handler(unsigned long, uioc_t
*, uint32_t);
134 static int megaraid_mbox_mm_command(adapter_t
*, uioc_t
*);
135 static void megaraid_mbox_mm_done(adapter_t
*, scb_t
*);
136 static int gather_hbainfo(adapter_t
*, mraid_hba_info_t
*);
137 static int wait_till_fw_empty(adapter_t
*);
141 MODULE_AUTHOR("megaraidlinux@lsi.com");
142 MODULE_DESCRIPTION("LSI Logic MegaRAID Mailbox Driver");
143 MODULE_LICENSE("GPL");
144 MODULE_VERSION(MEGARAID_VERSION
);
147 * ### modules parameters for driver ###
151 * Set to enable driver to expose unconfigured disk to kernel
153 static int megaraid_expose_unconf_disks
= 0;
154 module_param_named(unconf_disks
, megaraid_expose_unconf_disks
, int, 0);
155 MODULE_PARM_DESC(unconf_disks
,
156 "Set to expose unconfigured disks to kernel (default=0)");
159 * driver wait time if the adapter's mailbox is busy
161 static unsigned int max_mbox_busy_wait
= MBOX_BUSY_WAIT
;
162 module_param_named(busy_wait
, max_mbox_busy_wait
, int, 0);
163 MODULE_PARM_DESC(busy_wait
,
164 "Max wait for mailbox in microseconds if busy (default=10)");
167 * number of sectors per IO command
169 static unsigned int megaraid_max_sectors
= MBOX_MAX_SECTORS
;
170 module_param_named(max_sectors
, megaraid_max_sectors
, int, 0);
171 MODULE_PARM_DESC(max_sectors
,
172 "Maximum number of sectors per IO command (default=128)");
175 * number of commands per logical unit
177 static unsigned int megaraid_cmd_per_lun
= MBOX_DEF_CMD_PER_LUN
;
178 module_param_named(cmd_per_lun
, megaraid_cmd_per_lun
, int, 0);
179 MODULE_PARM_DESC(cmd_per_lun
,
180 "Maximum number of commands per logical unit (default=64)");
184 * Fast driver load option, skip scanning for physical devices during load.
185 * This would result in non-disk devices being skipped during driver load
186 * time. These can be later added though, using /proc/scsi/scsi
188 static unsigned int megaraid_fast_load
= 0;
189 module_param_named(fast_load
, megaraid_fast_load
, int, 0);
190 MODULE_PARM_DESC(fast_load
,
191 "Faster loading of the driver, skips physical devices! (default=0)");
195 * mraid_debug level - threshold for amount of information to be displayed by
196 * the driver. This level can be changed through modules parameters, ioctl or
197 * sysfs/proc interface. By default, print the announcement messages only.
199 int mraid_debug_level
= CL_ANN
;
200 module_param_named(debug_level
, mraid_debug_level
, int, 0);
201 MODULE_PARM_DESC(debug_level
, "Debug level for driver (default=0)");
204 * ### global data ###
206 static uint8_t megaraid_mbox_version
[8] =
207 { 0x02, 0x20, 0x04, 0x06, 3, 7, 20, 5 };
211 * PCI table for all supported controllers.
213 static struct pci_device_id pci_id_table_g
[] = {
216 PCI_DEVICE_ID_PERC4_DI_DISCOVERY
,
218 PCI_SUBSYS_ID_PERC4_DI_DISCOVERY
,
221 PCI_VENDOR_ID_LSI_LOGIC
,
222 PCI_DEVICE_ID_PERC4_SC
,
224 PCI_SUBSYS_ID_PERC4_SC
,
227 PCI_VENDOR_ID_LSI_LOGIC
,
228 PCI_DEVICE_ID_PERC4_DC
,
230 PCI_SUBSYS_ID_PERC4_DC
,
233 PCI_VENDOR_ID_LSI_LOGIC
,
240 PCI_DEVICE_ID_PERC4_DI_EVERGLADES
,
242 PCI_SUBSYS_ID_PERC4_DI_EVERGLADES
,
246 PCI_DEVICE_ID_PERC4E_SI_BIGBEND
,
248 PCI_SUBSYS_ID_PERC4E_SI_BIGBEND
,
252 PCI_DEVICE_ID_PERC4E_DI_KOBUK
,
254 PCI_SUBSYS_ID_PERC4E_DI_KOBUK
,
258 PCI_DEVICE_ID_PERC4E_DI_CORVETTE
,
260 PCI_SUBSYS_ID_PERC4E_DI_CORVETTE
,
264 PCI_DEVICE_ID_PERC4E_DI_EXPEDITION
,
266 PCI_SUBSYS_ID_PERC4E_DI_EXPEDITION
,
270 PCI_DEVICE_ID_PERC4E_DI_GUADALUPE
,
272 PCI_SUBSYS_ID_PERC4E_DI_GUADALUPE
,
275 PCI_VENDOR_ID_LSI_LOGIC
,
276 PCI_DEVICE_ID_DOBSON
,
282 PCI_DEVICE_ID_AMI_MEGARAID3
,
287 PCI_VENDOR_ID_LSI_LOGIC
,
288 PCI_DEVICE_ID_AMI_MEGARAID3
,
293 PCI_VENDOR_ID_LSI_LOGIC
,
294 PCI_DEVICE_ID_LINDSAY
,
298 {0} /* Terminating entry */
300 MODULE_DEVICE_TABLE(pci
, pci_id_table_g
);
303 static struct pci_driver megaraid_pci_driver_g
= {
305 .id_table
= pci_id_table_g
,
306 .probe
= megaraid_probe_one
,
307 .remove
= __devexit_p(megaraid_detach_one
),
308 .shutdown
= megaraid_mbox_shutdown
,
313 // definitions for the device attributes for exporting logical drive number
314 // for a scsi address (Host, Channel, Id, Lun)
316 CLASS_DEVICE_ATTR(megaraid_mbox_app_hndl
, S_IRUSR
, megaraid_sysfs_show_app_hndl
,
319 // Host template initializer for megaraid mbox sysfs device attributes
320 static struct class_device_attribute
*megaraid_shost_attrs
[] = {
321 &class_device_attr_megaraid_mbox_app_hndl
,
326 DEVICE_ATTR(megaraid_mbox_ld
, S_IRUSR
, megaraid_sysfs_show_ldnum
, NULL
);
328 // Host template initializer for megaraid mbox sysfs device attributes
329 static struct device_attribute
*megaraid_sdev_attrs
[] = {
330 &dev_attr_megaraid_mbox_ld
,
335 * megaraid_change_queue_depth - Change the device's queue depth
336 * @sdev: scsi device struct
337 * @qdepth: depth to set
342 static int megaraid_change_queue_depth(struct scsi_device
*sdev
, int qdepth
)
344 if (qdepth
> MBOX_MAX_SCSI_CMDS
)
345 qdepth
= MBOX_MAX_SCSI_CMDS
;
346 scsi_adjust_queue_depth(sdev
, 0, qdepth
);
347 return sdev
->queue_depth
;
351 * Scsi host template for megaraid unified driver
353 static struct scsi_host_template megaraid_template_g
= {
354 .module
= THIS_MODULE
,
355 .name
= "LSI Logic MegaRAID driver",
356 .proc_name
= "megaraid",
357 .queuecommand
= megaraid_queue_command
,
358 .eh_abort_handler
= megaraid_abort_handler
,
359 .eh_device_reset_handler
= megaraid_reset_handler
,
360 .eh_bus_reset_handler
= megaraid_reset_handler
,
361 .eh_host_reset_handler
= megaraid_reset_handler
,
362 .change_queue_depth
= megaraid_change_queue_depth
,
363 .use_clustering
= ENABLE_CLUSTERING
,
364 .use_sg_chaining
= ENABLE_SG_CHAINING
,
365 .sdev_attrs
= megaraid_sdev_attrs
,
366 .shost_attrs
= megaraid_shost_attrs
,
371 * megaraid_init - module load hook
373 * We register ourselves as hotplug enabled module and let PCI subsystem
374 * discover our adapters.
381 // Announce the driver version
382 con_log(CL_ANN
, (KERN_INFO
"megaraid: %s %s\n", MEGARAID_VERSION
,
383 MEGARAID_EXT_VERSION
));
385 // check validity of module parameters
386 if (megaraid_cmd_per_lun
> MBOX_MAX_SCSI_CMDS
) {
388 con_log(CL_ANN
, (KERN_WARNING
389 "megaraid mailbox: max commands per lun reset to %d\n",
390 MBOX_MAX_SCSI_CMDS
));
392 megaraid_cmd_per_lun
= MBOX_MAX_SCSI_CMDS
;
396 // register as a PCI hot-plug driver module
397 rval
= pci_register_driver(&megaraid_pci_driver_g
);
399 con_log(CL_ANN
, (KERN_WARNING
400 "megaraid: could not register hotplug support.\n"));
408 * megaraid_exit - driver unload entry point
410 * We simply unwrap the megaraid_init routine here.
415 con_log(CL_DLEVEL1
, (KERN_NOTICE
"megaraid: unloading framework\n"));
417 // unregister as PCI hotplug driver
418 pci_unregister_driver(&megaraid_pci_driver_g
);
425 * megaraid_probe_one - PCI hotplug entry point
426 * @pdev : handle to this controller's PCI configuration space
427 * @id : pci device id of the class of controllers
429 * This routine should be called whenever a new adapter is detected by the
430 * PCI hotplug susbsytem.
433 megaraid_probe_one(struct pci_dev
*pdev
, const struct pci_device_id
*id
)
438 // detected a new controller
439 con_log(CL_ANN
, (KERN_INFO
440 "megaraid: probe new device %#4.04x:%#4.04x:%#4.04x:%#4.04x: ",
441 pdev
->vendor
, pdev
->device
, pdev
->subsystem_vendor
,
442 pdev
->subsystem_device
));
444 con_log(CL_ANN
, ("bus %d:slot %d:func %d\n", pdev
->bus
->number
,
445 PCI_SLOT(pdev
->devfn
), PCI_FUNC(pdev
->devfn
)));
447 if (pci_enable_device(pdev
)) {
448 con_log(CL_ANN
, (KERN_WARNING
449 "megaraid: pci_enable_device failed\n"));
454 // Enable bus-mastering on this controller
455 pci_set_master(pdev
);
457 // Allocate the per driver initialization structure
458 adapter
= kzalloc(sizeof(adapter_t
), GFP_KERNEL
);
460 if (adapter
== NULL
) {
461 con_log(CL_ANN
, (KERN_WARNING
462 "megaraid: out of memory, %s %d.\n", __FUNCTION__
, __LINE__
));
468 // set up PCI related soft state and other pre-known parameters
469 adapter
->unique_id
= pdev
->bus
->number
<< 8 | pdev
->devfn
;
470 adapter
->irq
= pdev
->irq
;
471 adapter
->pdev
= pdev
;
473 atomic_set(&adapter
->being_detached
, 0);
475 // Setup the default DMA mask. This would be changed later on
476 // depending on hardware capabilities
477 if (pci_set_dma_mask(adapter
->pdev
, DMA_32BIT_MASK
) != 0) {
479 con_log(CL_ANN
, (KERN_WARNING
480 "megaraid: pci_set_dma_mask failed:%d\n", __LINE__
));
482 goto out_free_adapter
;
486 // Initialize the synchronization lock for kernel and LLD
487 spin_lock_init(&adapter
->lock
);
489 // Initialize the command queues: the list of free SCBs and the list
491 INIT_LIST_HEAD(&adapter
->kscb_pool
);
492 spin_lock_init(SCSI_FREE_LIST_LOCK(adapter
));
494 INIT_LIST_HEAD(&adapter
->pend_list
);
495 spin_lock_init(PENDING_LIST_LOCK(adapter
));
497 INIT_LIST_HEAD(&adapter
->completed_list
);
498 spin_lock_init(COMPLETED_LIST_LOCK(adapter
));
501 // Start the mailbox based controller
502 if (megaraid_init_mbox(adapter
) != 0) {
503 con_log(CL_ANN
, (KERN_WARNING
504 "megaraid: maibox adapter did not initialize\n"));
506 goto out_free_adapter
;
509 // Register with LSI Common Management Module
510 if (megaraid_cmm_register(adapter
) != 0) {
512 con_log(CL_ANN
, (KERN_WARNING
513 "megaraid: could not register with management module\n"));
518 // setup adapter handle in PCI soft state
519 pci_set_drvdata(pdev
, adapter
);
521 // attach with scsi mid-layer
522 if (megaraid_io_attach(adapter
) != 0) {
524 con_log(CL_ANN
, (KERN_WARNING
"megaraid: io attach failed\n"));
532 pci_set_drvdata(pdev
, NULL
);
533 megaraid_cmm_unregister(adapter
);
535 megaraid_fini_mbox(adapter
);
539 pci_disable_device(pdev
);
546 * megaraid_detach_one - release framework resources and call LLD release routine
547 * @pdev : handle for our PCI cofiguration space
549 * This routine is called during driver unload. We free all the allocated
550 * resources and call the corresponding LLD so that it can also release all
553 * This routine is also called from the PCI hotplug system.
556 megaraid_detach_one(struct pci_dev
*pdev
)
559 struct Scsi_Host
*host
;
562 // Start a rollback on this adapter
563 adapter
= pci_get_drvdata(pdev
);
566 con_log(CL_ANN
, (KERN_CRIT
567 "megaraid: Invalid detach on %#4.04x:%#4.04x:%#4.04x:%#4.04x\n",
568 pdev
->vendor
, pdev
->device
, pdev
->subsystem_vendor
,
569 pdev
->subsystem_device
));
574 con_log(CL_ANN
, (KERN_NOTICE
575 "megaraid: detaching device %#4.04x:%#4.04x:%#4.04x:%#4.04x\n",
576 pdev
->vendor
, pdev
->device
, pdev
->subsystem_vendor
,
577 pdev
->subsystem_device
));
581 host
= adapter
->host
;
583 // do not allow any more requests from the management module for this
585 // FIXME: How do we account for the request which might still be
587 atomic_set(&adapter
->being_detached
, 1);
589 // detach from the IO sub-system
590 megaraid_io_detach(adapter
);
592 // reset the device state in the PCI structure. We check this
593 // condition when we enter here. If the device state is NULL,
594 // that would mean the device has already been removed
595 pci_set_drvdata(pdev
, NULL
);
597 // Unregister from common management module
599 // FIXME: this must return success or failure for conditions if there
600 // is a command pending with LLD or not.
601 megaraid_cmm_unregister(adapter
);
603 // finalize the mailbox based controller and release all resources
604 megaraid_fini_mbox(adapter
);
610 pci_disable_device(pdev
);
617 * megaraid_mbox_shutdown - PCI shutdown for megaraid HBA
618 * @pdev : generic driver model device
620 * Shutdown notification, perform flush cache.
623 megaraid_mbox_shutdown(struct pci_dev
*pdev
)
625 adapter_t
*adapter
= pci_get_drvdata(pdev
);
629 con_log(CL_ANN
, (KERN_WARNING
630 "megaraid: null device in shutdown\n"));
635 con_log(CL_ANN
, (KERN_INFO
"megaraid: flushing adapter %d...",
638 megaraid_mbox_flush_cache(adapter
);
640 con_log(CL_ANN
, ("done\n"));
645 * megaraid_io_attach - attach a device with the IO subsystem
646 * @adapter : controller's soft state
648 * Attach this device with the IO subsystem.
651 megaraid_io_attach(adapter_t
*adapter
)
653 struct Scsi_Host
*host
;
655 // Initialize SCSI Host structure
656 host
= scsi_host_alloc(&megaraid_template_g
, 8);
658 con_log(CL_ANN
, (KERN_WARNING
659 "megaraid mbox: scsi_register failed\n"));
664 SCSIHOST2ADAP(host
) = (caddr_t
)adapter
;
665 adapter
->host
= host
;
667 host
->irq
= adapter
->irq
;
668 host
->unique_id
= adapter
->unique_id
;
669 host
->can_queue
= adapter
->max_cmds
;
670 host
->this_id
= adapter
->init_id
;
671 host
->sg_tablesize
= adapter
->sglen
;
672 host
->max_sectors
= adapter
->max_sectors
;
673 host
->cmd_per_lun
= adapter
->cmd_per_lun
;
674 host
->max_channel
= adapter
->max_channel
;
675 host
->max_id
= adapter
->max_target
;
676 host
->max_lun
= adapter
->max_lun
;
679 // notify mid-layer about the new controller
680 if (scsi_add_host(host
, &adapter
->pdev
->dev
)) {
682 con_log(CL_ANN
, (KERN_WARNING
683 "megaraid mbox: scsi_add_host failed\n"));
690 scsi_scan_host(host
);
697 * megaraid_io_detach - detach a device from the IO subsystem
698 * @adapter : controller's soft state
700 * Detach this device from the IO subsystem.
703 megaraid_io_detach(adapter_t
*adapter
)
705 struct Scsi_Host
*host
;
707 con_log(CL_DLEVEL1
, (KERN_INFO
"megaraid: io detach\n"));
709 host
= adapter
->host
;
711 scsi_remove_host(host
);
718 * START: Mailbox Low Level Driver
720 * This is section specific to the single mailbox based controllers
724 * megaraid_init_mbox - initialize controller
725 * @adapter : our soft state
727 * - Allocate 16-byte aligned mailbox memory for firmware handshake
728 * - Allocate controller's memory resources
729 * - Find out all initialization data
730 * - Allocate memory required for all the commands
731 * - Use internal library of FW routines, build up complete soft state
734 megaraid_init_mbox(adapter_t
*adapter
)
736 struct pci_dev
*pdev
;
737 mraid_device_t
*raid_dev
;
742 adapter
->ito
= MBOX_TIMEOUT
;
743 pdev
= adapter
->pdev
;
746 * Allocate and initialize the init data structure for mailbox
749 raid_dev
= kzalloc(sizeof(mraid_device_t
), GFP_KERNEL
);
750 if (raid_dev
== NULL
) return -1;
754 * Attach the adapter soft state to raid device soft state
756 adapter
->raid_device
= (caddr_t
)raid_dev
;
757 raid_dev
->fast_load
= megaraid_fast_load
;
761 raid_dev
->baseport
= pci_resource_start(pdev
, 0);
763 if (pci_request_regions(pdev
, "MegaRAID: LSI Logic Corporation") != 0) {
765 con_log(CL_ANN
, (KERN_WARNING
766 "megaraid: mem region busy\n"));
768 goto out_free_raid_dev
;
771 raid_dev
->baseaddr
= ioremap_nocache(raid_dev
->baseport
, 128);
773 if (!raid_dev
->baseaddr
) {
775 con_log(CL_ANN
, (KERN_WARNING
776 "megaraid: could not map hba memory\n") );
778 goto out_release_regions
;
781 /* initialize the mutual exclusion lock for the mailbox */
782 spin_lock_init(&raid_dev
->mailbox_lock
);
784 /* allocate memory required for commands */
785 if (megaraid_alloc_cmd_packets(adapter
) != 0)
789 * Issue SYNC cmd to flush the pending cmds in the adapter
790 * and initialize its internal state
793 if (megaraid_mbox_fire_sync_cmd(adapter
))
794 con_log(CL_ANN
, ("megaraid: sync cmd failed\n"));
797 * Setup the rest of the soft state using the library of
801 /* request IRQ and register the interrupt service routine */
802 if (request_irq(adapter
->irq
, megaraid_isr
, IRQF_SHARED
, "megaraid",
805 con_log(CL_ANN
, (KERN_WARNING
806 "megaraid: Couldn't register IRQ %d!\n", adapter
->irq
));
812 if (megaraid_mbox_product_info(adapter
) != 0)
815 // Do we support extended CDBs
816 adapter
->max_cdb_sz
= 10;
817 if (megaraid_mbox_extended_cdb(adapter
) == 0) {
818 adapter
->max_cdb_sz
= 16;
822 * Do we support cluster environment, if we do, what is the initiator
824 * NOTE: In a non-cluster aware firmware environment, the LLD should
825 * return 7 as initiator id.
828 adapter
->init_id
= -1;
829 if (megaraid_mbox_support_ha(adapter
, &adapter
->init_id
) == 0) {
834 * Prepare the device ids array to have the mapping between the kernel
835 * device address and megaraid device address.
836 * We export the physical devices on their actual addresses. The
837 * logical drives are exported on a virtual SCSI channel
839 megaraid_mbox_setup_device_map(adapter
);
841 // If the firmware supports random deletion, update the device id map
842 if (megaraid_mbox_support_random_del(adapter
)) {
844 // Change the logical drives numbers in device_ids array one
845 // slot in device_ids is reserved for target id, that's why
847 for (i
= 0; i
<= MAX_LOGICAL_DRIVES_40LD
; i
++) {
848 adapter
->device_ids
[adapter
->max_channel
][i
] += 0x80;
850 adapter
->device_ids
[adapter
->max_channel
][adapter
->init_id
] =
853 raid_dev
->random_del_supported
= 1;
857 * find out the maximum number of scatter-gather elements supported by
860 adapter
->sglen
= megaraid_mbox_get_max_sg(adapter
);
862 // enumerate RAID and SCSI channels so that all devices on SCSI
863 // channels can later be exported, including disk devices
864 megaraid_mbox_enum_raid_scsi(adapter
);
867 * Other parameters required by upper layer
869 * maximum number of sectors per IO command
871 adapter
->max_sectors
= megaraid_max_sectors
;
874 * number of queued commands per LUN.
876 adapter
->cmd_per_lun
= megaraid_cmd_per_lun
;
879 * Allocate resources required to issue FW calls, when sysfs is
882 if (megaraid_sysfs_alloc_resources(adapter
) != 0)
885 // Set the DMA mask to 64-bit. All supported controllers as capable of
887 pci_read_config_dword(adapter
->pdev
, PCI_CONF_AMISIG64
, &magic64
);
889 if (((magic64
== HBA_SIGNATURE_64_BIT
) &&
890 ((adapter
->pdev
->subsystem_device
!=
891 PCI_SUBSYS_ID_MEGARAID_SATA_150_6
) &&
892 (adapter
->pdev
->subsystem_device
!=
893 PCI_SUBSYS_ID_MEGARAID_SATA_150_4
))) ||
894 (adapter
->pdev
->vendor
== PCI_VENDOR_ID_LSI_LOGIC
&&
895 adapter
->pdev
->device
== PCI_DEVICE_ID_VERDE
) ||
896 (adapter
->pdev
->vendor
== PCI_VENDOR_ID_LSI_LOGIC
&&
897 adapter
->pdev
->device
== PCI_DEVICE_ID_DOBSON
) ||
898 (adapter
->pdev
->vendor
== PCI_VENDOR_ID_LSI_LOGIC
&&
899 adapter
->pdev
->device
== PCI_DEVICE_ID_LINDSAY
) ||
900 (adapter
->pdev
->vendor
== PCI_VENDOR_ID_DELL
&&
901 adapter
->pdev
->device
== PCI_DEVICE_ID_PERC4_DI_EVERGLADES
) ||
902 (adapter
->pdev
->vendor
== PCI_VENDOR_ID_DELL
&&
903 adapter
->pdev
->device
== PCI_DEVICE_ID_PERC4E_DI_KOBUK
)) {
904 if (pci_set_dma_mask(adapter
->pdev
, DMA_64BIT_MASK
)) {
905 con_log(CL_ANN
, (KERN_WARNING
906 "megaraid: DMA mask for 64-bit failed\n"));
908 if (pci_set_dma_mask (adapter
->pdev
, DMA_32BIT_MASK
)) {
909 con_log(CL_ANN
, (KERN_WARNING
910 "megaraid: 32-bit DMA mask failed\n"));
911 goto out_free_sysfs_res
;
916 // setup tasklet for DPC
917 tasklet_init(&adapter
->dpc_h
, megaraid_mbox_dpc
,
918 (unsigned long)adapter
);
920 con_log(CL_DLEVEL1
, (KERN_INFO
921 "megaraid mbox hba successfully initialized\n"));
926 megaraid_sysfs_free_resources(adapter
);
928 free_irq(adapter
->irq
, adapter
);
930 megaraid_free_cmd_packets(adapter
);
932 iounmap(raid_dev
->baseaddr
);
934 pci_release_regions(pdev
);
943 * megaraid_fini_mbox - undo controller initialization
944 * @adapter : our soft state
947 megaraid_fini_mbox(adapter_t
*adapter
)
949 mraid_device_t
*raid_dev
= ADAP2RAIDDEV(adapter
);
952 megaraid_mbox_flush_cache(adapter
);
954 tasklet_kill(&adapter
->dpc_h
);
956 megaraid_sysfs_free_resources(adapter
);
958 megaraid_free_cmd_packets(adapter
);
960 free_irq(adapter
->irq
, adapter
);
962 iounmap(raid_dev
->baseaddr
);
964 pci_release_regions(adapter
->pdev
);
973 * megaraid_alloc_cmd_packets - allocate shared mailbox
974 * @adapter : soft state of the raid controller
976 * Allocate and align the shared mailbox. This maibox is used to issue
977 * all the commands. For IO based controllers, the mailbox is also regsitered
978 * with the FW. Allocate memory for all commands as well.
979 * This is our big allocator.
982 megaraid_alloc_cmd_packets(adapter_t
*adapter
)
984 mraid_device_t
*raid_dev
= ADAP2RAIDDEV(adapter
);
985 struct pci_dev
*pdev
;
989 struct mraid_pci_blk
*epthru_pci_blk
;
990 struct mraid_pci_blk
*sg_pci_blk
;
991 struct mraid_pci_blk
*mbox_pci_blk
;
994 pdev
= adapter
->pdev
;
998 * Allocate the common 16-byte aligned memory for the handshake
1001 raid_dev
->una_mbox64
= pci_alloc_consistent(adapter
->pdev
,
1002 sizeof(mbox64_t
), &raid_dev
->una_mbox64_dma
);
1004 if (!raid_dev
->una_mbox64
) {
1005 con_log(CL_ANN
, (KERN_WARNING
1006 "megaraid: out of memory, %s %d\n", __FUNCTION__
,
1010 memset(raid_dev
->una_mbox64
, 0, sizeof(mbox64_t
));
1013 * Align the mailbox at 16-byte boundary
1015 raid_dev
->mbox
= &raid_dev
->una_mbox64
->mbox32
;
1017 raid_dev
->mbox
= (mbox_t
*)((((unsigned long)raid_dev
->mbox
) + 15) &
1020 raid_dev
->mbox64
= (mbox64_t
*)(((unsigned long)raid_dev
->mbox
) - 8);
1022 align
= ((void *)raid_dev
->mbox
-
1023 ((void *)&raid_dev
->una_mbox64
->mbox32
));
1025 raid_dev
->mbox_dma
= (unsigned long)raid_dev
->una_mbox64_dma
+ 8 +
1028 // Allocate memory for commands issued internally
1029 adapter
->ibuf
= pci_alloc_consistent(pdev
, MBOX_IBUF_SIZE
,
1030 &adapter
->ibuf_dma_h
);
1031 if (!adapter
->ibuf
) {
1033 con_log(CL_ANN
, (KERN_WARNING
1034 "megaraid: out of memory, %s %d\n", __FUNCTION__
,
1037 goto out_free_common_mbox
;
1039 memset(adapter
->ibuf
, 0, MBOX_IBUF_SIZE
);
1041 // Allocate memory for our SCSI Command Blocks and their associated
1045 * Allocate memory for the base list of scb. Later allocate memory for
1046 * CCBs and embedded components of each CCB and point the pointers in
1047 * scb to the allocated components
1048 * NOTE: The code to allocate SCB will be duplicated in all the LLD
1049 * since the calling routine does not yet know the number of available
1052 adapter
->kscb_list
= kcalloc(MBOX_MAX_SCSI_CMDS
, sizeof(scb_t
), GFP_KERNEL
);
1054 if (adapter
->kscb_list
== NULL
) {
1055 con_log(CL_ANN
, (KERN_WARNING
1056 "megaraid: out of memory, %s %d\n", __FUNCTION__
,
1061 // memory allocation for our command packets
1062 if (megaraid_mbox_setup_dma_pools(adapter
) != 0) {
1063 con_log(CL_ANN
, (KERN_WARNING
1064 "megaraid: out of memory, %s %d\n", __FUNCTION__
,
1066 goto out_free_scb_list
;
1069 // Adjust the scb pointers and link in the free pool
1070 epthru_pci_blk
= raid_dev
->epthru_pool
;
1071 sg_pci_blk
= raid_dev
->sg_pool
;
1072 mbox_pci_blk
= raid_dev
->mbox_pool
;
1074 for (i
= 0; i
< MBOX_MAX_SCSI_CMDS
; i
++) {
1075 scb
= adapter
->kscb_list
+ i
;
1076 ccb
= raid_dev
->ccb_list
+ i
;
1078 ccb
->mbox
= (mbox_t
*)(mbox_pci_blk
[i
].vaddr
+ 16);
1079 ccb
->raw_mbox
= (uint8_t *)ccb
->mbox
;
1080 ccb
->mbox64
= (mbox64_t
*)(mbox_pci_blk
[i
].vaddr
+ 8);
1081 ccb
->mbox_dma_h
= (unsigned long)mbox_pci_blk
[i
].dma_addr
+ 16;
1083 // make sure the mailbox is aligned properly
1084 if (ccb
->mbox_dma_h
& 0x0F) {
1085 con_log(CL_ANN
, (KERN_CRIT
1086 "megaraid mbox: not aligned on 16-bytes\n"));
1088 goto out_teardown_dma_pools
;
1091 ccb
->epthru
= (mraid_epassthru_t
*)
1092 epthru_pci_blk
[i
].vaddr
;
1093 ccb
->epthru_dma_h
= epthru_pci_blk
[i
].dma_addr
;
1094 ccb
->pthru
= (mraid_passthru_t
*)ccb
->epthru
;
1095 ccb
->pthru_dma_h
= ccb
->epthru_dma_h
;
1098 ccb
->sgl64
= (mbox_sgl64
*)sg_pci_blk
[i
].vaddr
;
1099 ccb
->sgl_dma_h
= sg_pci_blk
[i
].dma_addr
;
1100 ccb
->sgl32
= (mbox_sgl32
*)ccb
->sgl64
;
1102 scb
->ccb
= (caddr_t
)ccb
;
1105 scb
->sno
= i
; // command index
1108 scb
->state
= SCB_FREE
;
1109 scb
->dma_direction
= PCI_DMA_NONE
;
1110 scb
->dma_type
= MRAID_DMA_NONE
;
1111 scb
->dev_channel
= -1;
1112 scb
->dev_target
= -1;
1114 // put scb in the free pool
1115 list_add_tail(&scb
->list
, &adapter
->kscb_pool
);
1120 out_teardown_dma_pools
:
1121 megaraid_mbox_teardown_dma_pools(adapter
);
1123 kfree(adapter
->kscb_list
);
1125 pci_free_consistent(pdev
, MBOX_IBUF_SIZE
, (void *)adapter
->ibuf
,
1126 adapter
->ibuf_dma_h
);
1127 out_free_common_mbox
:
1128 pci_free_consistent(adapter
->pdev
, sizeof(mbox64_t
),
1129 (caddr_t
)raid_dev
->una_mbox64
, raid_dev
->una_mbox64_dma
);
1136 * megaraid_free_cmd_packets - free memory
1137 * @adapter : soft state of the raid controller
1139 * Release memory resources allocated for commands.
1142 megaraid_free_cmd_packets(adapter_t
*adapter
)
1144 mraid_device_t
*raid_dev
= ADAP2RAIDDEV(adapter
);
1146 megaraid_mbox_teardown_dma_pools(adapter
);
1148 kfree(adapter
->kscb_list
);
1150 pci_free_consistent(adapter
->pdev
, MBOX_IBUF_SIZE
,
1151 (void *)adapter
->ibuf
, adapter
->ibuf_dma_h
);
1153 pci_free_consistent(adapter
->pdev
, sizeof(mbox64_t
),
1154 (caddr_t
)raid_dev
->una_mbox64
, raid_dev
->una_mbox64_dma
);
1160 * megaraid_mbox_setup_dma_pools - setup dma pool for command packets
1161 * @adapter : HBA soft state
1163 * Setup the dma pools for mailbox, passthru and extended passthru structures,
1164 * and scatter-gather lists.
1167 megaraid_mbox_setup_dma_pools(adapter_t
*adapter
)
1169 mraid_device_t
*raid_dev
= ADAP2RAIDDEV(adapter
);
1170 struct mraid_pci_blk
*epthru_pci_blk
;
1171 struct mraid_pci_blk
*sg_pci_blk
;
1172 struct mraid_pci_blk
*mbox_pci_blk
;
1177 // Allocate memory for 16-bytes aligned mailboxes
1178 raid_dev
->mbox_pool_handle
= pci_pool_create("megaraid mbox pool",
1180 sizeof(mbox64_t
) + 16,
1183 if (raid_dev
->mbox_pool_handle
== NULL
) {
1184 goto fail_setup_dma_pool
;
1187 mbox_pci_blk
= raid_dev
->mbox_pool
;
1188 for (i
= 0; i
< MBOX_MAX_SCSI_CMDS
; i
++) {
1189 mbox_pci_blk
[i
].vaddr
= pci_pool_alloc(
1190 raid_dev
->mbox_pool_handle
,
1192 &mbox_pci_blk
[i
].dma_addr
);
1193 if (!mbox_pci_blk
[i
].vaddr
) {
1194 goto fail_setup_dma_pool
;
1199 * Allocate memory for each embedded passthru strucuture pointer
1200 * Request for a 128 bytes aligned structure for each passthru command
1202 * Since passthru and extended passthru commands are exclusive, they
1203 * share common memory pool. Passthru structures piggyback on memory
1204 * allocted to extended passthru since passthru is smaller of the two
1206 raid_dev
->epthru_pool_handle
= pci_pool_create("megaraid mbox pthru",
1207 adapter
->pdev
, sizeof(mraid_epassthru_t
), 128, 0);
1209 if (raid_dev
->epthru_pool_handle
== NULL
) {
1210 goto fail_setup_dma_pool
;
1213 epthru_pci_blk
= raid_dev
->epthru_pool
;
1214 for (i
= 0; i
< MBOX_MAX_SCSI_CMDS
; i
++) {
1215 epthru_pci_blk
[i
].vaddr
= pci_pool_alloc(
1216 raid_dev
->epthru_pool_handle
,
1218 &epthru_pci_blk
[i
].dma_addr
);
1219 if (!epthru_pci_blk
[i
].vaddr
) {
1220 goto fail_setup_dma_pool
;
1225 // Allocate memory for each scatter-gather list. Request for 512 bytes
1226 // alignment for each sg list
1227 raid_dev
->sg_pool_handle
= pci_pool_create("megaraid mbox sg",
1229 sizeof(mbox_sgl64
) * MBOX_MAX_SG_SIZE
,
1232 if (raid_dev
->sg_pool_handle
== NULL
) {
1233 goto fail_setup_dma_pool
;
1236 sg_pci_blk
= raid_dev
->sg_pool
;
1237 for (i
= 0; i
< MBOX_MAX_SCSI_CMDS
; i
++) {
1238 sg_pci_blk
[i
].vaddr
= pci_pool_alloc(
1239 raid_dev
->sg_pool_handle
,
1241 &sg_pci_blk
[i
].dma_addr
);
1242 if (!sg_pci_blk
[i
].vaddr
) {
1243 goto fail_setup_dma_pool
;
1249 fail_setup_dma_pool
:
1250 megaraid_mbox_teardown_dma_pools(adapter
);
1256 * megaraid_mbox_teardown_dma_pools - teardown dma pools for command packets
1257 * @adapter : HBA soft state
1259 * Teardown the dma pool for mailbox, passthru and extended passthru
1260 * structures, and scatter-gather lists.
1263 megaraid_mbox_teardown_dma_pools(adapter_t
*adapter
)
1265 mraid_device_t
*raid_dev
= ADAP2RAIDDEV(adapter
);
1266 struct mraid_pci_blk
*epthru_pci_blk
;
1267 struct mraid_pci_blk
*sg_pci_blk
;
1268 struct mraid_pci_blk
*mbox_pci_blk
;
1272 sg_pci_blk
= raid_dev
->sg_pool
;
1273 for (i
= 0; i
< MBOX_MAX_SCSI_CMDS
&& sg_pci_blk
[i
].vaddr
; i
++) {
1274 pci_pool_free(raid_dev
->sg_pool_handle
, sg_pci_blk
[i
].vaddr
,
1275 sg_pci_blk
[i
].dma_addr
);
1277 if (raid_dev
->sg_pool_handle
)
1278 pci_pool_destroy(raid_dev
->sg_pool_handle
);
1281 epthru_pci_blk
= raid_dev
->epthru_pool
;
1282 for (i
= 0; i
< MBOX_MAX_SCSI_CMDS
&& epthru_pci_blk
[i
].vaddr
; i
++) {
1283 pci_pool_free(raid_dev
->epthru_pool_handle
,
1284 epthru_pci_blk
[i
].vaddr
, epthru_pci_blk
[i
].dma_addr
);
1286 if (raid_dev
->epthru_pool_handle
)
1287 pci_pool_destroy(raid_dev
->epthru_pool_handle
);
1290 mbox_pci_blk
= raid_dev
->mbox_pool
;
1291 for (i
= 0; i
< MBOX_MAX_SCSI_CMDS
&& mbox_pci_blk
[i
].vaddr
; i
++) {
1292 pci_pool_free(raid_dev
->mbox_pool_handle
,
1293 mbox_pci_blk
[i
].vaddr
, mbox_pci_blk
[i
].dma_addr
);
1295 if (raid_dev
->mbox_pool_handle
)
1296 pci_pool_destroy(raid_dev
->mbox_pool_handle
);
1303 * megaraid_alloc_scb - detach and return a scb from the free list
1304 * @adapter : controller's soft state
1305 * @scp : pointer to the scsi command to be executed
1307 * Return the scb from the head of the free list. %NULL if there are none
1311 megaraid_alloc_scb(adapter_t
*adapter
, struct scsi_cmnd
*scp
)
1313 struct list_head
*head
= &adapter
->kscb_pool
;
1315 unsigned long flags
;
1317 // detach scb from free pool
1318 spin_lock_irqsave(SCSI_FREE_LIST_LOCK(adapter
), flags
);
1320 if (list_empty(head
)) {
1321 spin_unlock_irqrestore(SCSI_FREE_LIST_LOCK(adapter
), flags
);
1325 scb
= list_entry(head
->next
, scb_t
, list
);
1326 list_del_init(&scb
->list
);
1328 spin_unlock_irqrestore(SCSI_FREE_LIST_LOCK(adapter
), flags
);
1330 scb
->state
= SCB_ACTIVE
;
1332 scb
->dma_type
= MRAID_DMA_NONE
;
1339 * megaraid_dealloc_scb - return the scb to the free pool
1340 * @adapter : controller's soft state
1341 * @scb : scb to be freed
1343 * Return the scb back to the free list of scbs. The caller must 'flush' the
1344 * SCB before calling us. E.g., performing pci_unamp and/or pci_sync etc.
1345 * NOTE NOTE: Make sure the scb is not on any list before calling this
1349 megaraid_dealloc_scb(adapter_t
*adapter
, scb_t
*scb
)
1351 unsigned long flags
;
1353 // put scb in the free pool
1354 scb
->state
= SCB_FREE
;
1356 spin_lock_irqsave(SCSI_FREE_LIST_LOCK(adapter
), flags
);
1358 list_add(&scb
->list
, &adapter
->kscb_pool
);
1360 spin_unlock_irqrestore(SCSI_FREE_LIST_LOCK(adapter
), flags
);
1367 * megaraid_mbox_mksgl - make the scatter-gather list
1368 * @adapter : controller's soft state
1369 * @scb : scsi control block
1371 * Prepare the scatter-gather list.
1374 megaraid_mbox_mksgl(adapter_t
*adapter
, scb_t
*scb
)
1376 struct scatterlist
*sgl
;
1378 struct scsi_cmnd
*scp
;
1384 ccb
= (mbox_ccb_t
*)scb
->ccb
;
1386 sgcnt
= scsi_dma_map(scp
);
1387 BUG_ON(sgcnt
< 0 || sgcnt
> adapter
->sglen
);
1389 // no mapping required if no data to be transferred
1393 scb
->dma_type
= MRAID_DMA_WSG
;
1395 scsi_for_each_sg(scp
, sgl
, sgcnt
, i
) {
1396 ccb
->sgl64
[i
].address
= sg_dma_address(sgl
);
1397 ccb
->sgl64
[i
].length
= sg_dma_len(sgl
);
1400 // Return count of SG nodes
1406 * mbox_post_cmd - issue a mailbox command
1407 * @adapter : controller's soft state
1408 * @scb : command to be issued
1410 * Post the command to the controller if mailbox is available.
1413 mbox_post_cmd(adapter_t
*adapter
, scb_t
*scb
)
1415 mraid_device_t
*raid_dev
= ADAP2RAIDDEV(adapter
);
1419 unsigned long flags
;
1423 ccb
= (mbox_ccb_t
*)scb
->ccb
;
1424 mbox
= raid_dev
->mbox
;
1425 mbox64
= raid_dev
->mbox64
;
1428 * Check for busy mailbox. If it is, return failure - the caller
1429 * should retry later.
1431 spin_lock_irqsave(MAILBOX_LOCK(raid_dev
), flags
);
1433 if (unlikely(mbox
->busy
)) {
1438 } while(mbox
->busy
&& (i
< max_mbox_busy_wait
));
1442 spin_unlock_irqrestore(MAILBOX_LOCK(raid_dev
), flags
);
1449 // Copy this command's mailbox data into "adapter's" mailbox
1450 memcpy((caddr_t
)mbox64
, (caddr_t
)ccb
->mbox64
, 22);
1451 mbox
->cmdid
= scb
->sno
;
1453 adapter
->outstanding_cmds
++;
1455 if (scb
->dma_direction
== PCI_DMA_TODEVICE
)
1456 pci_dma_sync_sg_for_device(adapter
->pdev
,
1457 scsi_sglist(scb
->scp
),
1458 scsi_sg_count(scb
->scp
),
1461 mbox
->busy
= 1; // Set busy
1466 WRINDOOR(raid_dev
, raid_dev
->mbox_dma
| 0x1);
1468 spin_unlock_irqrestore(MAILBOX_LOCK(raid_dev
), flags
);
1475 * megaraid_queue_command - generic queue entry point for all LLDs
1476 * @scp : pointer to the scsi command to be executed
1477 * @done : callback routine to be called after the cmd has be completed
1479 * Queue entry point for mailbox based controllers.
1482 megaraid_queue_command(struct scsi_cmnd
*scp
, void (*done
)(struct scsi_cmnd
*))
1488 adapter
= SCP2ADAPTER(scp
);
1489 scp
->scsi_done
= done
;
1493 * Allocate and build a SCB request
1494 * if_busy flag will be set if megaraid_mbox_build_cmd() command could
1495 * not allocate scb. We will return non-zero status in that case.
1496 * NOTE: scb can be null even though certain commands completed
1497 * successfully, e.g., MODE_SENSE and TEST_UNIT_READY, it would
1498 * return 0 in that case, and we would do the callback right away.
1501 scb
= megaraid_mbox_build_cmd(adapter
, scp
, &if_busy
);
1502 if (!scb
) { // command already completed
1507 megaraid_mbox_runpendq(adapter
, scb
);
1512 * megaraid_mbox_build_cmd - transform the mid-layer scsi commands
1513 * @adapter : controller's soft state
1514 * @scp : mid-layer scsi command pointer
1515 * @busy : set if request could not be completed because of lack of
1518 * Transform the mid-layer scsi command to megaraid firmware lingua.
1519 * Convert the command issued by mid-layer to format understood by megaraid
1520 * firmware. We also complete certain commands without sending them to firmware.
1523 megaraid_mbox_build_cmd(adapter_t
*adapter
, struct scsi_cmnd
*scp
, int *busy
)
1525 mraid_device_t
*rdev
= ADAP2RAIDDEV(adapter
);
1530 mraid_passthru_t
*pthru
;
1534 char skip
[] = "skipping";
1535 char scan
[] = "scanning";
1540 * Get the appropriate device map for the device this command is
1543 MRAID_GET_DEVICE_MAP(adapter
, scp
, channel
, target
, islogical
);
1546 * Logical drive commands
1549 switch (scp
->cmnd
[0]) {
1550 case TEST_UNIT_READY
:
1552 * Do we support clustering and is the support enabled
1553 * If no, return success always
1556 scp
->result
= (DID_OK
<< 16);
1560 if (!(scb
= megaraid_alloc_scb(adapter
, scp
))) {
1561 scp
->result
= (DID_ERROR
<< 16);
1566 scb
->dma_direction
= scp
->sc_data_direction
;
1567 scb
->dev_channel
= 0xFF;
1568 scb
->dev_target
= target
;
1569 ccb
= (mbox_ccb_t
*)scb
->ccb
;
1572 * The command id will be provided by the command
1575 ccb
->raw_mbox
[0] = CLUSTER_CMD
;
1576 ccb
->raw_mbox
[2] = RESERVATION_STATUS
;
1577 ccb
->raw_mbox
[3] = target
;
1583 struct scatterlist
*sgl
;
1586 sgl
= scsi_sglist(scp
);
1589 (page_address((&sgl
[0])->page
)
1590 + (&sgl
[0])->offset
);
1592 memset(vaddr
, 0, scp
->cmnd
[4]);
1595 con_log(CL_ANN
, (KERN_WARNING
1596 "megaraid mailbox: invalid sg:%d\n",
1600 scp
->result
= (DID_OK
<< 16);
1605 * Display the channel scan for logical drives
1606 * Do not display scan for a channel if already done.
1608 if (!(rdev
->last_disp
& (1L << SCP2CHANNEL(scp
)))) {
1610 con_log(CL_ANN
, (KERN_INFO
1611 "scsi[%d]: scanning scsi channel %d",
1612 adapter
->host
->host_no
,
1616 " [virtual] for logical drives\n"));
1618 rdev
->last_disp
|= (1L << SCP2CHANNEL(scp
));
1621 if (scp
->cmnd
[1] & MEGA_SCSI_INQ_EVPD
) {
1622 scp
->sense_buffer
[0] = 0x70;
1623 scp
->sense_buffer
[2] = ILLEGAL_REQUEST
;
1624 scp
->sense_buffer
[12] = MEGA_INVALID_FIELD_IN_CDB
;
1625 scp
->result
= CHECK_CONDITION
<< 1;
1633 * Do not allow LUN > 0 for logical drives and
1634 * requests for more than 40 logical drives
1637 scp
->result
= (DID_BAD_TARGET
<< 16);
1640 if ((target
% 0x80) >= MAX_LOGICAL_DRIVES_40LD
) {
1641 scp
->result
= (DID_BAD_TARGET
<< 16);
1646 /* Allocate a SCB and initialize passthru */
1647 if (!(scb
= megaraid_alloc_scb(adapter
, scp
))) {
1648 scp
->result
= (DID_ERROR
<< 16);
1653 ccb
= (mbox_ccb_t
*)scb
->ccb
;
1654 scb
->dev_channel
= 0xFF;
1655 scb
->dev_target
= target
;
1658 mbox64
= ccb
->mbox64
;
1662 pthru
->reqsenselen
= 14;
1663 pthru
->islogical
= 1;
1664 pthru
->logdrv
= target
;
1665 pthru
->cdblen
= scp
->cmd_len
;
1666 memcpy(pthru
->cdb
, scp
->cmnd
, scp
->cmd_len
);
1668 mbox
->cmd
= MBOXCMD_PASSTHRU64
;
1669 scb
->dma_direction
= scp
->sc_data_direction
;
1671 pthru
->dataxferlen
= scsi_bufflen(scp
);
1672 pthru
->dataxferaddr
= ccb
->sgl_dma_h
;
1673 pthru
->numsge
= megaraid_mbox_mksgl(adapter
,
1676 mbox
->xferaddr
= 0xFFFFFFFF;
1677 mbox64
->xferaddr_lo
= (uint32_t )ccb
->pthru_dma_h
;
1678 mbox64
->xferaddr_hi
= 0;
1690 * Allocate a SCB and initialize mailbox
1692 if (!(scb
= megaraid_alloc_scb(adapter
, scp
))) {
1693 scp
->result
= (DID_ERROR
<< 16);
1697 ccb
= (mbox_ccb_t
*)scb
->ccb
;
1698 scb
->dev_channel
= 0xFF;
1699 scb
->dev_target
= target
;
1701 mbox64
= ccb
->mbox64
;
1702 mbox
->logdrv
= target
;
1705 * A little HACK: 2nd bit is zero for all scsi read
1706 * commands and is set for all scsi write commands
1708 mbox
->cmd
= (scp
->cmnd
[0] & 0x02) ? MBOXCMD_LWRITE64
:
1712 * 6-byte READ(0x08) or WRITE(0x0A) cdb
1714 if (scp
->cmd_len
== 6) {
1715 mbox
->numsectors
= (uint32_t)scp
->cmnd
[4];
1717 ((uint32_t)scp
->cmnd
[1] << 16) |
1718 ((uint32_t)scp
->cmnd
[2] << 8) |
1719 (uint32_t)scp
->cmnd
[3];
1721 mbox
->lba
&= 0x1FFFFF;
1725 * 10-byte READ(0x28) or WRITE(0x2A) cdb
1727 else if (scp
->cmd_len
== 10) {
1729 (uint32_t)scp
->cmnd
[8] |
1730 ((uint32_t)scp
->cmnd
[7] << 8);
1732 ((uint32_t)scp
->cmnd
[2] << 24) |
1733 ((uint32_t)scp
->cmnd
[3] << 16) |
1734 ((uint32_t)scp
->cmnd
[4] << 8) |
1735 (uint32_t)scp
->cmnd
[5];
1739 * 12-byte READ(0xA8) or WRITE(0xAA) cdb
1741 else if (scp
->cmd_len
== 12) {
1743 ((uint32_t)scp
->cmnd
[2] << 24) |
1744 ((uint32_t)scp
->cmnd
[3] << 16) |
1745 ((uint32_t)scp
->cmnd
[4] << 8) |
1746 (uint32_t)scp
->cmnd
[5];
1749 ((uint32_t)scp
->cmnd
[6] << 24) |
1750 ((uint32_t)scp
->cmnd
[7] << 16) |
1751 ((uint32_t)scp
->cmnd
[8] << 8) |
1752 (uint32_t)scp
->cmnd
[9];
1755 con_log(CL_ANN
, (KERN_WARNING
1756 "megaraid: unsupported CDB length\n"));
1758 megaraid_dealloc_scb(adapter
, scb
);
1760 scp
->result
= (DID_ERROR
<< 16);
1764 scb
->dma_direction
= scp
->sc_data_direction
;
1766 // Calculate Scatter-Gather info
1767 mbox64
->xferaddr_lo
= (uint32_t )ccb
->sgl_dma_h
;
1768 mbox
->numsge
= megaraid_mbox_mksgl(adapter
,
1770 mbox
->xferaddr
= 0xFFFFFFFF;
1771 mbox64
->xferaddr_hi
= 0;
1778 * Do we support clustering and is the support enabled
1781 scp
->result
= (DID_BAD_TARGET
<< 16);
1786 * Allocate a SCB and initialize mailbox
1788 if (!(scb
= megaraid_alloc_scb(adapter
, scp
))) {
1789 scp
->result
= (DID_ERROR
<< 16);
1794 ccb
= (mbox_ccb_t
*)scb
->ccb
;
1795 scb
->dev_channel
= 0xFF;
1796 scb
->dev_target
= target
;
1797 ccb
->raw_mbox
[0] = CLUSTER_CMD
;
1798 ccb
->raw_mbox
[2] = (scp
->cmnd
[0] == RESERVE
) ?
1799 RESERVE_LD
: RELEASE_LD
;
1801 ccb
->raw_mbox
[3] = target
;
1802 scb
->dma_direction
= scp
->sc_data_direction
;
1807 scp
->result
= (DID_BAD_TARGET
<< 16);
1811 else { // Passthru device commands
1813 // Do not allow access to target id > 15 or LUN > 7
1814 if (target
> 15 || SCP2LUN(scp
) > 7) {
1815 scp
->result
= (DID_BAD_TARGET
<< 16);
1819 // if fast load option was set and scan for last device is
1820 // over, reset the fast_load flag so that during a possible
1821 // next scan, devices can be made available
1822 if (rdev
->fast_load
&& (target
== 15) &&
1823 (SCP2CHANNEL(scp
) == adapter
->max_channel
-1)) {
1825 con_log(CL_ANN
, (KERN_INFO
1826 "megaraid[%d]: physical device scan re-enabled\n",
1827 adapter
->host
->host_no
));
1828 rdev
->fast_load
= 0;
1832 * Display the channel scan for physical devices
1834 if (!(rdev
->last_disp
& (1L << SCP2CHANNEL(scp
)))) {
1836 ss
= rdev
->fast_load
? skip
: scan
;
1838 con_log(CL_ANN
, (KERN_INFO
1839 "scsi[%d]: %s scsi channel %d [Phy %d]",
1840 adapter
->host
->host_no
, ss
, SCP2CHANNEL(scp
),
1844 " for non-raid devices\n"));
1846 rdev
->last_disp
|= (1L << SCP2CHANNEL(scp
));
1849 // disable channel sweep if fast load option given
1850 if (rdev
->fast_load
) {
1851 scp
->result
= (DID_BAD_TARGET
<< 16);
1855 // Allocate a SCB and initialize passthru
1856 if (!(scb
= megaraid_alloc_scb(adapter
, scp
))) {
1857 scp
->result
= (DID_ERROR
<< 16);
1862 ccb
= (mbox_ccb_t
*)scb
->ccb
;
1863 scb
->dev_channel
= channel
;
1864 scb
->dev_target
= target
;
1865 scb
->dma_direction
= scp
->sc_data_direction
;
1867 mbox64
= ccb
->mbox64
;
1869 // Does this firmware support extended CDBs
1870 if (adapter
->max_cdb_sz
== 16) {
1871 mbox
->cmd
= MBOXCMD_EXTPTHRU
;
1873 megaraid_mbox_prepare_epthru(adapter
, scb
, scp
);
1875 mbox64
->xferaddr_lo
= (uint32_t)ccb
->epthru_dma_h
;
1876 mbox64
->xferaddr_hi
= 0;
1877 mbox
->xferaddr
= 0xFFFFFFFF;
1880 mbox
->cmd
= MBOXCMD_PASSTHRU64
;
1882 megaraid_mbox_prepare_pthru(adapter
, scb
, scp
);
1884 mbox64
->xferaddr_lo
= (uint32_t)ccb
->pthru_dma_h
;
1885 mbox64
->xferaddr_hi
= 0;
1886 mbox
->xferaddr
= 0xFFFFFFFF;
1896 * megaraid_mbox_runpendq - execute commands queued in the pending queue
1897 * @adapter : controller's soft state
1898 * @scb_q : SCB to be queued in the pending list
1900 * Scan the pending list for commands which are not yet issued and try to
1901 * post to the controller. The SCB can be a null pointer, which would indicate
1902 * no SCB to be queue, just try to execute the ones in the pending list.
1904 * NOTE: We do not actually traverse the pending list. The SCBs are plucked
1905 * out from the head of the pending list. If it is successfully issued, the
1906 * next SCB is at the head now.
1909 megaraid_mbox_runpendq(adapter_t
*adapter
, scb_t
*scb_q
)
1912 unsigned long flags
;
1914 spin_lock_irqsave(PENDING_LIST_LOCK(adapter
), flags
);
1917 scb_q
->state
= SCB_PENDQ
;
1918 list_add_tail(&scb_q
->list
, &adapter
->pend_list
);
1921 // if the adapter in not in quiescent mode, post the commands to FW
1922 if (adapter
->quiescent
) {
1923 spin_unlock_irqrestore(PENDING_LIST_LOCK(adapter
), flags
);
1927 while (!list_empty(&adapter
->pend_list
)) {
1929 assert_spin_locked(PENDING_LIST_LOCK(adapter
));
1931 scb
= list_entry(adapter
->pend_list
.next
, scb_t
, list
);
1933 // remove the scb from the pending list and try to
1934 // issue. If we are unable to issue it, put back in
1935 // the pending list and return
1937 list_del_init(&scb
->list
);
1939 spin_unlock_irqrestore(PENDING_LIST_LOCK(adapter
), flags
);
1941 // if mailbox was busy, return SCB back to pending
1942 // list. Make sure to add at the head, since that's
1943 // where it would have been removed from
1945 scb
->state
= SCB_ISSUED
;
1947 if (mbox_post_cmd(adapter
, scb
) != 0) {
1949 spin_lock_irqsave(PENDING_LIST_LOCK(adapter
), flags
);
1951 scb
->state
= SCB_PENDQ
;
1953 list_add(&scb
->list
, &adapter
->pend_list
);
1955 spin_unlock_irqrestore(PENDING_LIST_LOCK(adapter
),
1961 spin_lock_irqsave(PENDING_LIST_LOCK(adapter
), flags
);
1964 spin_unlock_irqrestore(PENDING_LIST_LOCK(adapter
), flags
);
1972 * megaraid_mbox_prepare_pthru - prepare a command for physical devices
1973 * @adapter : pointer to controller's soft state
1974 * @scb : scsi control block
1975 * @scp : scsi command from the mid-layer
1977 * Prepare a command for the scsi physical devices.
1980 megaraid_mbox_prepare_pthru(adapter_t
*adapter
, scb_t
*scb
,
1981 struct scsi_cmnd
*scp
)
1984 mraid_passthru_t
*pthru
;
1988 ccb
= (mbox_ccb_t
*)scb
->ccb
;
1990 channel
= scb
->dev_channel
;
1991 target
= scb
->dev_target
;
1993 // 0=6sec, 1=60sec, 2=10min, 3=3hrs, 4=NO timeout
1996 pthru
->islogical
= 0;
1998 pthru
->target
= (channel
<< 4) | target
;
1999 pthru
->logdrv
= SCP2LUN(scp
);
2000 pthru
->reqsenselen
= 14;
2001 pthru
->cdblen
= scp
->cmd_len
;
2003 memcpy(pthru
->cdb
, scp
->cmnd
, scp
->cmd_len
);
2005 if (scsi_bufflen(scp
)) {
2006 pthru
->dataxferlen
= scsi_bufflen(scp
);
2007 pthru
->dataxferaddr
= ccb
->sgl_dma_h
;
2008 pthru
->numsge
= megaraid_mbox_mksgl(adapter
, scb
);
2011 pthru
->dataxferaddr
= 0;
2012 pthru
->dataxferlen
= 0;
2020 * megaraid_mbox_prepare_epthru - prepare a command for physical devices
2021 * @adapter : pointer to controller's soft state
2022 * @scb : scsi control block
2023 * @scp : scsi command from the mid-layer
2025 * Prepare a command for the scsi physical devices. This rountine prepares
2026 * commands for devices which can take extended CDBs (>10 bytes).
2029 megaraid_mbox_prepare_epthru(adapter_t
*adapter
, scb_t
*scb
,
2030 struct scsi_cmnd
*scp
)
2033 mraid_epassthru_t
*epthru
;
2037 ccb
= (mbox_ccb_t
*)scb
->ccb
;
2038 epthru
= ccb
->epthru
;
2039 channel
= scb
->dev_channel
;
2040 target
= scb
->dev_target
;
2042 // 0=6sec, 1=60sec, 2=10min, 3=3hrs, 4=NO timeout
2043 epthru
->timeout
= 4;
2045 epthru
->islogical
= 0;
2046 epthru
->channel
= 0;
2047 epthru
->target
= (channel
<< 4) | target
;
2048 epthru
->logdrv
= SCP2LUN(scp
);
2049 epthru
->reqsenselen
= 14;
2050 epthru
->cdblen
= scp
->cmd_len
;
2052 memcpy(epthru
->cdb
, scp
->cmnd
, scp
->cmd_len
);
2054 if (scsi_bufflen(scp
)) {
2055 epthru
->dataxferlen
= scsi_bufflen(scp
);
2056 epthru
->dataxferaddr
= ccb
->sgl_dma_h
;
2057 epthru
->numsge
= megaraid_mbox_mksgl(adapter
, scb
);
2060 epthru
->dataxferaddr
= 0;
2061 epthru
->dataxferlen
= 0;
2069 * megaraid_ack_sequence - interrupt ack sequence for memory mapped HBAs
2070 * @adapter : controller's soft state
2072 * Interrupt acknowledgement sequence for memory mapped HBAs. Find out the
2073 * completed command and put them on the completed list for later processing.
2075 * Returns: 1 if the interrupt is valid, 0 otherwise
2078 megaraid_ack_sequence(adapter_t
*adapter
)
2080 mraid_device_t
*raid_dev
= ADAP2RAIDDEV(adapter
);
2084 uint8_t completed
[MBOX_MAX_FIRMWARE_STATUS
];
2085 struct list_head clist
;
2088 unsigned long flags
;
2092 mbox
= raid_dev
->mbox
;
2094 // move the SCBs from the firmware completed array to our local list
2095 INIT_LIST_HEAD(&clist
);
2097 // loop till F/W has more commands for us to complete
2099 spin_lock_irqsave(MAILBOX_LOCK(raid_dev
), flags
);
2102 * Check if a valid interrupt is pending. If found, force the
2103 * interrupt line low.
2105 dword
= RDOUTDOOR(raid_dev
);
2106 if (dword
!= 0x10001234) break;
2110 WROUTDOOR(raid_dev
, 0x10001234);
2113 // wait for valid numstatus to post
2114 for (i
= 0; i
< 0xFFFFF; i
++) {
2115 if (mbox
->numstatus
!= 0xFF) {
2116 nstatus
= mbox
->numstatus
;
2121 mbox
->numstatus
= 0xFF;
2123 adapter
->outstanding_cmds
-= nstatus
;
2125 for (i
= 0; i
< nstatus
; i
++) {
2127 // wait for valid command index to post
2128 for (j
= 0; j
< 0xFFFFF; j
++) {
2129 if (mbox
->completed
[i
] != 0xFF) break;
2132 completed
[i
] = mbox
->completed
[i
];
2133 mbox
->completed
[i
] = 0xFF;
2135 if (completed
[i
] == 0xFF) {
2136 con_log(CL_ANN
, (KERN_CRIT
2137 "megaraid: command posting timed out\n"));
2143 // Get SCB associated with this command id
2144 if (completed
[i
] >= MBOX_MAX_SCSI_CMDS
) {
2146 scb
= adapter
->uscb_list
+ (completed
[i
] -
2147 MBOX_MAX_SCSI_CMDS
);
2151 scb
= adapter
->kscb_list
+ completed
[i
];
2154 scb
->status
= mbox
->status
;
2155 list_add_tail(&scb
->list
, &clist
);
2158 // Acknowledge interrupt
2159 WRINDOOR(raid_dev
, 0x02);
2163 spin_unlock_irqrestore(MAILBOX_LOCK(raid_dev
), flags
);
2166 // put the completed commands in the completed list. DPC would
2167 // complete these commands later
2168 spin_lock_irqsave(COMPLETED_LIST_LOCK(adapter
), flags
);
2170 list_splice(&clist
, &adapter
->completed_list
);
2172 spin_unlock_irqrestore(COMPLETED_LIST_LOCK(adapter
), flags
);
2175 // schedule the DPC if there is some work for it
2177 tasklet_schedule(&adapter
->dpc_h
);
2184 * megaraid_isr - isr for memory based mailbox based controllers
2186 * @devp : pointer to our soft state
2188 * Interrupt service routine for memory-mapped mailbox controllers.
2191 megaraid_isr(int irq
, void *devp
)
2193 adapter_t
*adapter
= devp
;
2196 handled
= megaraid_ack_sequence(adapter
);
2198 /* Loop through any pending requests */
2199 if (!adapter
->quiescent
) {
2200 megaraid_mbox_runpendq(adapter
, NULL
);
2203 return IRQ_RETVAL(handled
);
2208 * megaraid_mbox_sync_scb - sync kernel buffers
2209 * @adapter : controller's soft state
2210 * @scb : pointer to the resource packet
2212 * DMA sync if required.
2215 megaraid_mbox_sync_scb(adapter_t
*adapter
, scb_t
*scb
)
2219 ccb
= (mbox_ccb_t
*)scb
->ccb
;
2221 if (scb
->dma_direction
== PCI_DMA_FROMDEVICE
)
2222 pci_dma_sync_sg_for_cpu(adapter
->pdev
,
2223 scsi_sglist(scb
->scp
),
2224 scsi_sg_count(scb
->scp
),
2225 PCI_DMA_FROMDEVICE
);
2227 scsi_dma_unmap(scb
->scp
);
2233 * megaraid_mbox_dpc - the tasklet to complete the commands from completed list
2234 * @devp : pointer to HBA soft state
2236 * Pick up the commands from the completed list and send back to the owners.
2237 * This is a reentrant function and does not assume any locks are held while
2238 * it is being called.
2241 megaraid_mbox_dpc(unsigned long devp
)
2243 adapter_t
*adapter
= (adapter_t
*)devp
;
2244 mraid_device_t
*raid_dev
;
2245 struct list_head clist
;
2246 struct scatterlist
*sgl
;
2249 struct scsi_cmnd
*scp
;
2250 mraid_passthru_t
*pthru
;
2251 mraid_epassthru_t
*epthru
;
2257 unsigned long flags
;
2263 if (!adapter
) return;
2265 raid_dev
= ADAP2RAIDDEV(adapter
);
2267 // move the SCBs from the completed list to our local list
2268 INIT_LIST_HEAD(&clist
);
2270 spin_lock_irqsave(COMPLETED_LIST_LOCK(adapter
), flags
);
2272 list_splice_init(&adapter
->completed_list
, &clist
);
2274 spin_unlock_irqrestore(COMPLETED_LIST_LOCK(adapter
), flags
);
2277 list_for_each_entry_safe(scb
, tmp
, &clist
, list
) {
2279 status
= scb
->status
;
2281 ccb
= (mbox_ccb_t
*)scb
->ccb
;
2283 epthru
= ccb
->epthru
;
2286 // Make sure f/w has completed a valid command
2287 if (scb
->state
!= SCB_ISSUED
) {
2288 con_log(CL_ANN
, (KERN_CRIT
2289 "megaraid critical err: invalid command %d:%d:%p\n",
2290 scb
->sno
, scb
->state
, scp
));
2292 continue; // Must never happen!
2295 // check for the management command and complete it right away
2296 if (scb
->sno
>= MBOX_MAX_SCSI_CMDS
) {
2297 scb
->state
= SCB_FREE
;
2298 scb
->status
= status
;
2300 // remove from local clist
2301 list_del_init(&scb
->list
);
2303 kioc
= (uioc_t
*)scb
->gp
;
2306 megaraid_mbox_mm_done(adapter
, scb
);
2311 // Was an abort issued for this command earlier
2312 if (scb
->state
& SCB_ABORT
) {
2313 con_log(CL_ANN
, (KERN_NOTICE
2314 "megaraid: aborted cmd %lx[%x] completed\n",
2315 scp
->serial_number
, scb
->sno
));
2319 * If the inquiry came of a disk drive which is not part of
2320 * any RAID array, expose it to the kernel. For this to be
2321 * enabled, user must set the "megaraid_expose_unconf_disks"
2322 * flag to 1 by specifying it on module parameter list.
2323 * This would enable data migration off drives from other
2326 islogical
= MRAID_IS_LOGICAL(adapter
, scp
);
2327 if (scp
->cmnd
[0] == INQUIRY
&& status
== 0 && islogical
== 0
2328 && IS_RAID_CH(raid_dev
, scb
->dev_channel
)) {
2330 sgl
= scsi_sglist(scp
);
2332 c
= *(unsigned char *)
2333 (page_address((&sgl
[0])->page
) +
2336 con_log(CL_ANN
, (KERN_WARNING
2337 "megaraid mailbox: invalid sg:%d\n",
2342 if ((c
& 0x1F ) == TYPE_DISK
) {
2343 pdev_index
= (scb
->dev_channel
* 16) +
2346 raid_dev
->pdrv_state
[pdev_index
] & 0x0F;
2348 if (pdev_state
== PDRV_ONLINE
||
2349 pdev_state
== PDRV_FAILED
||
2350 pdev_state
== PDRV_RBLD
||
2351 pdev_state
== PDRV_HOTSPARE
||
2352 megaraid_expose_unconf_disks
== 0) {
2359 // Convert MegaRAID status to Linux error code
2364 scp
->result
= (DID_OK
<< 16);
2369 /* set sense_buffer and result fields */
2370 if (mbox
->cmd
== MBOXCMD_PASSTHRU
||
2371 mbox
->cmd
== MBOXCMD_PASSTHRU64
) {
2373 memcpy(scp
->sense_buffer
, pthru
->reqsensearea
,
2376 scp
->result
= DRIVER_SENSE
<< 24 |
2377 DID_OK
<< 16 | CHECK_CONDITION
<< 1;
2380 if (mbox
->cmd
== MBOXCMD_EXTPTHRU
) {
2382 memcpy(scp
->sense_buffer
,
2383 epthru
->reqsensearea
, 14);
2385 scp
->result
= DRIVER_SENSE
<< 24 |
2387 CHECK_CONDITION
<< 1;
2389 scp
->sense_buffer
[0] = 0x70;
2390 scp
->sense_buffer
[2] = ABORTED_COMMAND
;
2391 scp
->result
= CHECK_CONDITION
<< 1;
2398 scp
->result
= DID_BUS_BUSY
<< 16 | status
;
2404 * If TEST_UNIT_READY fails, we know RESERVATION_STATUS
2407 if (scp
->cmnd
[0] == TEST_UNIT_READY
) {
2408 scp
->result
= DID_ERROR
<< 16 |
2409 RESERVATION_CONFLICT
<< 1;
2413 * Error code returned is 1 if Reserve or Release
2414 * failed or the input parameter is invalid
2416 if (status
== 1 && (scp
->cmnd
[0] == RESERVE
||
2417 scp
->cmnd
[0] == RELEASE
)) {
2419 scp
->result
= DID_ERROR
<< 16 |
2420 RESERVATION_CONFLICT
<< 1;
2423 scp
->result
= DID_BAD_TARGET
<< 16 | status
;
2427 // print a debug message for all failed commands
2429 megaraid_mbox_display_scb(adapter
, scb
);
2432 // Free our internal resources and call the mid-layer callback
2434 megaraid_mbox_sync_scb(adapter
, scb
);
2436 // remove from local clist
2437 list_del_init(&scb
->list
);
2439 // put back in free list
2440 megaraid_dealloc_scb(adapter
, scb
);
2442 // send the scsi packet back to kernel
2443 scp
->scsi_done(scp
);
2451 * megaraid_abort_handler - abort the scsi command
2452 * @scp : command to be aborted
2454 * Abort a previous SCSI request. Only commands on the pending list can be
2455 * aborted. All the commands issued to the F/W must complete.
2458 megaraid_abort_handler(struct scsi_cmnd
*scp
)
2461 mraid_device_t
*raid_dev
;
2465 unsigned long flags
;
2469 adapter
= SCP2ADAPTER(scp
);
2470 raid_dev
= ADAP2RAIDDEV(adapter
);
2472 con_log(CL_ANN
, (KERN_WARNING
2473 "megaraid: aborting-%ld cmd=%x <c=%d t=%d l=%d>\n",
2474 scp
->serial_number
, scp
->cmnd
[0], SCP2CHANNEL(scp
),
2475 SCP2TARGET(scp
), SCP2LUN(scp
)));
2477 // If FW has stopped responding, simply return failure
2478 if (raid_dev
->hw_error
) {
2479 con_log(CL_ANN
, (KERN_NOTICE
2480 "megaraid: hw error, not aborting\n"));
2484 // There might a race here, where the command was completed by the
2485 // firmware and now it is on the completed list. Before we could
2486 // complete the command to the kernel in dpc, the abort came.
2487 // Find out if this is the case to avoid the race.
2489 spin_lock_irqsave(COMPLETED_LIST_LOCK(adapter
), flags
);
2490 list_for_each_entry_safe(scb
, tmp
, &adapter
->completed_list
, list
) {
2492 if (scb
->scp
== scp
) { // Found command
2494 list_del_init(&scb
->list
); // from completed list
2496 con_log(CL_ANN
, (KERN_WARNING
2497 "megaraid: %ld:%d[%d:%d], abort from completed list\n",
2498 scp
->serial_number
, scb
->sno
,
2499 scb
->dev_channel
, scb
->dev_target
));
2501 scp
->result
= (DID_ABORT
<< 16);
2502 scp
->scsi_done(scp
);
2504 megaraid_dealloc_scb(adapter
, scb
);
2506 spin_unlock_irqrestore(COMPLETED_LIST_LOCK(adapter
),
2512 spin_unlock_irqrestore(COMPLETED_LIST_LOCK(adapter
), flags
);
2515 // Find out if this command is still on the pending list. If it is and
2516 // was never issued, abort and return success. If the command is owned
2517 // by the firmware, we must wait for it to complete by the FW.
2518 spin_lock_irqsave(PENDING_LIST_LOCK(adapter
), flags
);
2519 list_for_each_entry_safe(scb
, tmp
, &adapter
->pend_list
, list
) {
2521 if (scb
->scp
== scp
) { // Found command
2523 list_del_init(&scb
->list
); // from pending list
2525 ASSERT(!(scb
->state
& SCB_ISSUED
));
2527 con_log(CL_ANN
, (KERN_WARNING
2528 "megaraid abort: %ld[%d:%d], driver owner\n",
2529 scp
->serial_number
, scb
->dev_channel
,
2532 scp
->result
= (DID_ABORT
<< 16);
2533 scp
->scsi_done(scp
);
2535 megaraid_dealloc_scb(adapter
, scb
);
2537 spin_unlock_irqrestore(PENDING_LIST_LOCK(adapter
),
2543 spin_unlock_irqrestore(PENDING_LIST_LOCK(adapter
), flags
);
2546 // Check do we even own this command, in which case this would be
2547 // owned by the firmware. The only way to locate the FW scb is to
2548 // traverse through the list of all SCB, since driver does not
2549 // maintain these SCBs on any list
2551 spin_lock_irq(&adapter
->lock
);
2552 for (i
= 0; i
< MBOX_MAX_SCSI_CMDS
; i
++) {
2553 scb
= adapter
->kscb_list
+ i
;
2555 if (scb
->scp
== scp
) {
2559 if (!(scb
->state
& SCB_ISSUED
)) {
2560 con_log(CL_ANN
, (KERN_WARNING
2561 "megaraid abort: %ld%d[%d:%d], invalid state\n",
2562 scp
->serial_number
, scb
->sno
, scb
->dev_channel
,
2567 con_log(CL_ANN
, (KERN_WARNING
2568 "megaraid abort: %ld:%d[%d:%d], fw owner\n",
2569 scp
->serial_number
, scb
->sno
, scb
->dev_channel
,
2574 spin_unlock_irq(&adapter
->lock
);
2577 con_log(CL_ANN
, (KERN_WARNING
2578 "megaraid abort: scsi cmd:%ld, do now own\n",
2579 scp
->serial_number
));
2581 // FIXME: Should there be a callback for this command?
2585 // We cannot actually abort a command owned by firmware, return
2586 // failure and wait for reset. In host reset handler, we will find out
2587 // if the HBA is still live
2592 * megaraid_reset_handler - device reset hadler for mailbox based driver
2593 * @scp : reference command
2595 * Reset handler for the mailbox based controller. First try to find out if
2596 * the FW is still live, in which case the outstanding commands counter mut go
2597 * down to 0. If that happens, also issue the reservation reset command to
2598 * relinquish (possible) reservations on the logical drives connected to this
2602 megaraid_reset_handler(struct scsi_cmnd
*scp
)
2607 mraid_device_t
*raid_dev
;
2608 unsigned long flags
;
2609 uint8_t raw_mbox
[sizeof(mbox_t
)];
2611 int recovery_window
;
2616 adapter
= SCP2ADAPTER(scp
);
2617 raid_dev
= ADAP2RAIDDEV(adapter
);
2619 // return failure if adapter is not responding
2620 if (raid_dev
->hw_error
) {
2621 con_log(CL_ANN
, (KERN_NOTICE
2622 "megaraid: hw error, cannot reset\n"));
2627 // Under exceptional conditions, FW can take up to 3 minutes to
2628 // complete command processing. Wait for additional 2 minutes for the
2629 // pending commands counter to go down to 0. If it doesn't, let the
2630 // controller be marked offline
2631 // Also, reset all the commands currently owned by the driver
2632 spin_lock_irqsave(PENDING_LIST_LOCK(adapter
), flags
);
2633 list_for_each_entry_safe(scb
, tmp
, &adapter
->pend_list
, list
) {
2634 list_del_init(&scb
->list
); // from pending list
2636 if (scb
->sno
>= MBOX_MAX_SCSI_CMDS
) {
2637 con_log(CL_ANN
, (KERN_WARNING
2638 "megaraid: IOCTL packet with %d[%d:%d] being reset\n",
2639 scb
->sno
, scb
->dev_channel
, scb
->dev_target
));
2643 kioc
= (uioc_t
*)scb
->gp
;
2644 kioc
->status
= -EFAULT
;
2646 megaraid_mbox_mm_done(adapter
, scb
);
2648 if (scb
->scp
== scp
) { // Found command
2649 con_log(CL_ANN
, (KERN_WARNING
2650 "megaraid: %ld:%d[%d:%d], reset from pending list\n",
2651 scp
->serial_number
, scb
->sno
,
2652 scb
->dev_channel
, scb
->dev_target
));
2654 con_log(CL_ANN
, (KERN_WARNING
2655 "megaraid: IO packet with %d[%d:%d] being reset\n",
2656 scb
->sno
, scb
->dev_channel
, scb
->dev_target
));
2659 scb
->scp
->result
= (DID_RESET
<< 16);
2660 scb
->scp
->scsi_done(scb
->scp
);
2662 megaraid_dealloc_scb(adapter
, scb
);
2665 spin_unlock_irqrestore(PENDING_LIST_LOCK(adapter
), flags
);
2667 if (adapter
->outstanding_cmds
) {
2668 con_log(CL_ANN
, (KERN_NOTICE
2669 "megaraid: %d outstanding commands. Max wait %d sec\n",
2670 adapter
->outstanding_cmds
,
2671 (MBOX_RESET_WAIT
+ MBOX_RESET_EXT_WAIT
)));
2674 recovery_window
= MBOX_RESET_WAIT
+ MBOX_RESET_EXT_WAIT
;
2676 recovering
= adapter
->outstanding_cmds
;
2678 for (i
= 0; i
< recovery_window
; i
++) {
2680 megaraid_ack_sequence(adapter
);
2682 // print a message once every 5 seconds only
2685 "megaraid mbox: Wait for %d commands to complete:%d\n",
2686 adapter
->outstanding_cmds
,
2687 (MBOX_RESET_WAIT
+ MBOX_RESET_EXT_WAIT
) - i
));
2690 // bailout if no recovery happended in reset time
2691 if (adapter
->outstanding_cmds
== 0) {
2698 spin_lock(&adapter
->lock
);
2700 // If still outstanding commands, bail out
2701 if (adapter
->outstanding_cmds
) {
2702 con_log(CL_ANN
, (KERN_WARNING
2703 "megaraid mbox: critical hardware error!\n"));
2705 raid_dev
->hw_error
= 1;
2711 con_log(CL_ANN
, (KERN_NOTICE
2712 "megaraid mbox: reset sequence completed sucessfully\n"));
2716 // If the controller supports clustering, reset reservations
2722 // clear reservations if any
2723 raw_mbox
[0] = CLUSTER_CMD
;
2724 raw_mbox
[2] = RESET_RESERVATIONS
;
2727 if (mbox_post_sync_cmd_fast(adapter
, raw_mbox
) == 0) {
2729 (KERN_INFO
"megaraid: reservation reset\n"));
2733 con_log(CL_ANN
, (KERN_WARNING
2734 "megaraid: reservation reset failed\n"));
2738 spin_unlock_irq(&adapter
->lock
);
2743 * START: internal commands library
2745 * This section of the driver has the common routine used by the driver and
2746 * also has all the FW routines
2750 * mbox_post_sync_cmd() - blocking command to the mailbox based controllers
2751 * @adapter : controller's soft state
2752 * @raw_mbox : the mailbox
2754 * Issue a scb in synchronous and non-interrupt mode for mailbox based
2758 mbox_post_sync_cmd(adapter_t
*adapter
, uint8_t raw_mbox
[])
2760 mraid_device_t
*raid_dev
= ADAP2RAIDDEV(adapter
);
2767 mbox64
= raid_dev
->mbox64
;
2768 mbox
= raid_dev
->mbox
;
2771 * Wait until mailbox is free
2773 if (megaraid_busywait_mbox(raid_dev
) != 0)
2774 goto blocked_mailbox
;
2777 * Copy mailbox data into host structure
2779 memcpy((caddr_t
)mbox
, (caddr_t
)raw_mbox
, 16);
2784 mbox
->numstatus
= 0xFF;
2785 mbox
->status
= 0xFF;
2788 WRINDOOR(raid_dev
, raid_dev
->mbox_dma
| 0x1);
2790 // wait for maximum 1 second for status to post. If the status is not
2791 // available within 1 second, assume FW is initializing and wait
2792 // for an extended amount of time
2793 if (mbox
->numstatus
== 0xFF) { // status not yet available
2796 for (i
= 0; mbox
->numstatus
== 0xFF && i
< 1000; i
++) {
2803 con_log(CL_ANN
, (KERN_NOTICE
2804 "megaraid mailbox: wait for FW to boot "));
2806 for (i
= 0; (mbox
->numstatus
== 0xFF) &&
2807 (i
< MBOX_RESET_WAIT
); i
++) {
2809 con_log(CL_ANN
, ("\b\b\b\b\b[%03d]",
2810 MBOX_RESET_WAIT
- i
));
2814 if (i
== MBOX_RESET_WAIT
) {
2817 "\nmegaraid mailbox: status not available\n"));
2821 con_log(CL_ANN
, ("\b\b\b\b\b[ok] \n"));
2825 // wait for maximum 1 second for poll semaphore
2826 if (mbox
->poll
!= 0x77) {
2829 for (i
= 0; (mbox
->poll
!= 0x77) && (i
< 1000); i
++) {
2835 con_log(CL_ANN
, (KERN_WARNING
2836 "megaraid mailbox: could not get poll semaphore\n"));
2841 WRINDOOR(raid_dev
, raid_dev
->mbox_dma
| 0x2);
2844 // wait for maximum 1 second for acknowledgement
2845 if (RDINDOOR(raid_dev
) & 0x2) {
2848 for (i
= 0; (RDINDOOR(raid_dev
) & 0x2) && (i
< 1000); i
++) {
2854 con_log(CL_ANN
, (KERN_WARNING
2855 "megaraid mailbox: could not acknowledge\n"));
2862 status
= mbox
->status
;
2864 // invalidate the completed command id array. After command
2865 // completion, firmware would write the valid id.
2866 mbox
->numstatus
= 0xFF;
2867 mbox
->status
= 0xFF;
2868 for (i
= 0; i
< MBOX_MAX_FIRMWARE_STATUS
; i
++) {
2869 mbox
->completed
[i
] = 0xFF;
2876 con_log(CL_ANN
, (KERN_WARNING
"megaraid: blocked mailbox\n") );
2882 * mbox_post_sync_cmd_fast - blocking command to the mailbox based controllers
2883 * @adapter : controller's soft state
2884 * @raw_mbox : the mailbox
2886 * Issue a scb in synchronous and non-interrupt mode for mailbox based
2887 * controllers. This is a faster version of the synchronous command and
2888 * therefore can be called in interrupt-context as well.
2891 mbox_post_sync_cmd_fast(adapter_t
*adapter
, uint8_t raw_mbox
[])
2893 mraid_device_t
*raid_dev
= ADAP2RAIDDEV(adapter
);
2898 mbox
= raid_dev
->mbox
;
2900 // return immediately if the mailbox is busy
2901 if (mbox
->busy
) return -1;
2903 // Copy mailbox data into host structure
2904 memcpy((caddr_t
)mbox
, (caddr_t
)raw_mbox
, 14);
2909 mbox
->numstatus
= 0xFF;
2910 mbox
->status
= 0xFF;
2913 WRINDOOR(raid_dev
, raid_dev
->mbox_dma
| 0x1);
2915 for (i
= 0; i
< MBOX_SYNC_WAIT_CNT
; i
++) {
2916 if (mbox
->numstatus
!= 0xFF) break;
2918 udelay(MBOX_SYNC_DELAY_200
);
2921 if (i
== MBOX_SYNC_WAIT_CNT
) {
2922 // We may need to re-calibrate the counter
2923 con_log(CL_ANN
, (KERN_CRIT
2924 "megaraid: fast sync command timed out\n"));
2927 WRINDOOR(raid_dev
, raid_dev
->mbox_dma
| 0x2);
2930 return mbox
->status
;
2935 * megaraid_busywait_mbox() - Wait until the controller's mailbox is available
2936 * @raid_dev : RAID device (HBA) soft state
2938 * Wait until the controller's mailbox is available to accept more commands.
2939 * Wait for at most 1 second.
2942 megaraid_busywait_mbox(mraid_device_t
*raid_dev
)
2944 mbox_t
*mbox
= raid_dev
->mbox
;
2949 for (i
= 0; mbox
->busy
&& i
< 1000; i
++)
2953 if (i
< 1000) return 0;
2959 * megaraid_mbox_product_info - some static information about the controller
2960 * @adapter : our soft state
2962 * Issue commands to the controller to grab some parameters required by our
2966 megaraid_mbox_product_info(adapter_t
*adapter
)
2968 mraid_device_t
*raid_dev
= ADAP2RAIDDEV(adapter
);
2970 uint8_t raw_mbox
[sizeof(mbox_t
)];
2971 mraid_pinfo_t
*pinfo
;
2972 dma_addr_t pinfo_dma_h
;
2973 mraid_inquiry3_t
*mraid_inq3
;
2977 memset((caddr_t
)raw_mbox
, 0, sizeof(raw_mbox
));
2978 mbox
= (mbox_t
*)raw_mbox
;
2981 * Issue an ENQUIRY3 command to find out certain adapter parameters,
2982 * e.g., max channels, max commands etc.
2984 pinfo
= pci_alloc_consistent(adapter
->pdev
, sizeof(mraid_pinfo_t
),
2987 if (pinfo
== NULL
) {
2988 con_log(CL_ANN
, (KERN_WARNING
2989 "megaraid: out of memory, %s %d\n", __FUNCTION__
,
2994 memset(pinfo
, 0, sizeof(mraid_pinfo_t
));
2996 mbox
->xferaddr
= (uint32_t)adapter
->ibuf_dma_h
;
2997 memset((void *)adapter
->ibuf
, 0, MBOX_IBUF_SIZE
);
2999 raw_mbox
[0] = FC_NEW_CONFIG
;
3000 raw_mbox
[2] = NC_SUBOP_ENQUIRY3
;
3001 raw_mbox
[3] = ENQ3_GET_SOLICITED_FULL
;
3003 // Issue the command
3004 if (mbox_post_sync_cmd(adapter
, raw_mbox
) != 0) {
3006 con_log(CL_ANN
, (KERN_WARNING
"megaraid: Inquiry3 failed\n"));
3008 pci_free_consistent(adapter
->pdev
, sizeof(mraid_pinfo_t
),
3009 pinfo
, pinfo_dma_h
);
3015 * Collect information about state of each physical drive
3016 * attached to the controller. We will expose all the disks
3017 * which are not part of RAID
3019 mraid_inq3
= (mraid_inquiry3_t
*)adapter
->ibuf
;
3020 for (i
= 0; i
< MBOX_MAX_PHYSICAL_DRIVES
; i
++) {
3021 raid_dev
->pdrv_state
[i
] = mraid_inq3
->pdrv_state
[i
];
3025 * Get product info for information like number of channels,
3026 * maximum commands supported.
3028 memset((caddr_t
)raw_mbox
, 0, sizeof(raw_mbox
));
3029 mbox
->xferaddr
= (uint32_t)pinfo_dma_h
;
3031 raw_mbox
[0] = FC_NEW_CONFIG
;
3032 raw_mbox
[2] = NC_SUBOP_PRODUCT_INFO
;
3034 if (mbox_post_sync_cmd(adapter
, raw_mbox
) != 0) {
3036 con_log(CL_ANN
, (KERN_WARNING
3037 "megaraid: product info failed\n"));
3039 pci_free_consistent(adapter
->pdev
, sizeof(mraid_pinfo_t
),
3040 pinfo
, pinfo_dma_h
);
3046 * Setup some parameters for host, as required by our caller
3048 adapter
->max_channel
= pinfo
->nchannels
;
3051 * we will export all the logical drives on a single channel.
3052 * Add 1 since inquires do not come for inititor ID
3054 adapter
->max_target
= MAX_LOGICAL_DRIVES_40LD
+ 1;
3055 adapter
->max_lun
= 8; // up to 8 LUNs for non-disk devices
3058 * These are the maximum outstanding commands for the scsi-layer
3060 adapter
->max_cmds
= MBOX_MAX_SCSI_CMDS
;
3062 memset(adapter
->fw_version
, 0, VERSION_SIZE
);
3063 memset(adapter
->bios_version
, 0, VERSION_SIZE
);
3065 memcpy(adapter
->fw_version
, pinfo
->fw_version
, 4);
3066 adapter
->fw_version
[4] = 0;
3068 memcpy(adapter
->bios_version
, pinfo
->bios_version
, 4);
3069 adapter
->bios_version
[4] = 0;
3071 con_log(CL_ANN
, (KERN_NOTICE
3072 "megaraid: fw version:[%s] bios version:[%s]\n",
3073 adapter
->fw_version
, adapter
->bios_version
));
3075 pci_free_consistent(adapter
->pdev
, sizeof(mraid_pinfo_t
), pinfo
,
3084 * megaraid_mbox_extended_cdb - check for support for extended CDBs
3085 * @adapter : soft state for the controller
3087 * This routine check whether the controller in question supports extended
3088 * ( > 10 bytes ) CDBs.
3091 megaraid_mbox_extended_cdb(adapter_t
*adapter
)
3094 uint8_t raw_mbox
[sizeof(mbox_t
)];
3097 mbox
= (mbox_t
*)raw_mbox
;
3099 memset((caddr_t
)raw_mbox
, 0, sizeof(raw_mbox
));
3100 mbox
->xferaddr
= (uint32_t)adapter
->ibuf_dma_h
;
3102 memset((void *)adapter
->ibuf
, 0, MBOX_IBUF_SIZE
);
3104 raw_mbox
[0] = MAIN_MISC_OPCODE
;
3105 raw_mbox
[2] = SUPPORT_EXT_CDB
;
3111 if (mbox_post_sync_cmd(adapter
, raw_mbox
) != 0) {
3120 * megaraid_mbox_support_ha - Do we support clustering
3121 * @adapter : soft state for the controller
3122 * @init_id : ID of the initiator
3124 * Determine if the firmware supports clustering and the ID of the initiator.
3127 megaraid_mbox_support_ha(adapter_t
*adapter
, uint16_t *init_id
)
3130 uint8_t raw_mbox
[sizeof(mbox_t
)];
3134 mbox
= (mbox_t
*)raw_mbox
;
3136 memset((caddr_t
)raw_mbox
, 0, sizeof(raw_mbox
));
3138 mbox
->xferaddr
= (uint32_t)adapter
->ibuf_dma_h
;
3140 memset((void *)adapter
->ibuf
, 0, MBOX_IBUF_SIZE
);
3142 raw_mbox
[0] = GET_TARGET_ID
;
3144 // Issue the command
3147 if (mbox_post_sync_cmd(adapter
, raw_mbox
) == 0) {
3149 *init_id
= *(uint8_t *)adapter
->ibuf
;
3151 con_log(CL_ANN
, (KERN_INFO
3152 "megaraid: cluster firmware, initiator ID: %d\n",
3163 * megaraid_mbox_support_random_del - Do we support random deletion
3164 * @adapter : soft state for the controller
3166 * Determine if the firmware supports random deletion.
3167 * Return: 1 is operation supported, 0 otherwise
3170 megaraid_mbox_support_random_del(adapter_t
*adapter
)
3173 uint8_t raw_mbox
[sizeof(mbox_t
)];
3177 mbox
= (mbox_t
*)raw_mbox
;
3179 memset((caddr_t
)raw_mbox
, 0, sizeof(mbox_t
));
3181 raw_mbox
[0] = FC_DEL_LOGDRV
;
3182 raw_mbox
[2] = OP_SUP_DEL_LOGDRV
;
3184 // Issue the command
3186 if (mbox_post_sync_cmd(adapter
, raw_mbox
) == 0) {
3188 con_log(CL_DLEVEL1
, ("megaraid: supports random deletion\n"));
3198 * megaraid_mbox_get_max_sg - maximum sg elements supported by the firmware
3199 * @adapter : soft state for the controller
3201 * Find out the maximum number of scatter-gather elements supported by the
3205 megaraid_mbox_get_max_sg(adapter_t
*adapter
)
3208 uint8_t raw_mbox
[sizeof(mbox_t
)];
3212 mbox
= (mbox_t
*)raw_mbox
;
3214 memset((caddr_t
)raw_mbox
, 0, sizeof(mbox_t
));
3216 mbox
->xferaddr
= (uint32_t)adapter
->ibuf_dma_h
;
3218 memset((void *)adapter
->ibuf
, 0, MBOX_IBUF_SIZE
);
3220 raw_mbox
[0] = MAIN_MISC_OPCODE
;
3221 raw_mbox
[2] = GET_MAX_SG_SUPPORT
;
3223 // Issue the command
3224 if (mbox_post_sync_cmd(adapter
, raw_mbox
) == 0) {
3225 nsg
= *(uint8_t *)adapter
->ibuf
;
3228 nsg
= MBOX_DEFAULT_SG_SIZE
;
3231 if (nsg
> MBOX_MAX_SG_SIZE
) nsg
= MBOX_MAX_SG_SIZE
;
3238 * megaraid_mbox_enum_raid_scsi - enumerate the RAID and SCSI channels
3239 * @adapter : soft state for the controller
3241 * Enumerate the RAID and SCSI channels for ROMB platforms so that channels
3242 * can be exported as regular SCSI channels.
3245 megaraid_mbox_enum_raid_scsi(adapter_t
*adapter
)
3247 mraid_device_t
*raid_dev
= ADAP2RAIDDEV(adapter
);
3249 uint8_t raw_mbox
[sizeof(mbox_t
)];
3252 mbox
= (mbox_t
*)raw_mbox
;
3254 memset((caddr_t
)raw_mbox
, 0, sizeof(mbox_t
));
3256 mbox
->xferaddr
= (uint32_t)adapter
->ibuf_dma_h
;
3258 memset((void *)adapter
->ibuf
, 0, MBOX_IBUF_SIZE
);
3260 raw_mbox
[0] = CHNL_CLASS
;
3261 raw_mbox
[2] = GET_CHNL_CLASS
;
3263 // Issue the command. If the command fails, all channels are RAID
3265 raid_dev
->channel_class
= 0xFF;
3266 if (mbox_post_sync_cmd(adapter
, raw_mbox
) == 0) {
3267 raid_dev
->channel_class
= *(uint8_t *)adapter
->ibuf
;
3275 * megaraid_mbox_flush_cache - flush adapter and disks cache
3276 * @adapter : soft state for the controller
3278 * Flush adapter cache followed by disks cache.
3281 megaraid_mbox_flush_cache(adapter_t
*adapter
)
3284 uint8_t raw_mbox
[sizeof(mbox_t
)];
3287 mbox
= (mbox_t
*)raw_mbox
;
3289 memset((caddr_t
)raw_mbox
, 0, sizeof(mbox_t
));
3291 raw_mbox
[0] = FLUSH_ADAPTER
;
3293 if (mbox_post_sync_cmd(adapter
, raw_mbox
) != 0) {
3294 con_log(CL_ANN
, ("megaraid: flush adapter failed\n"));
3297 raw_mbox
[0] = FLUSH_SYSTEM
;
3299 if (mbox_post_sync_cmd(adapter
, raw_mbox
) != 0) {
3300 con_log(CL_ANN
, ("megaraid: flush disks cache failed\n"));
3308 * megaraid_mbox_fire_sync_cmd - fire the sync cmd
3309 * @adapter : soft state for the controller
3311 * Clears the pending cmds in FW and reinits its RAID structs.
3314 megaraid_mbox_fire_sync_cmd(adapter_t
*adapter
)
3317 uint8_t raw_mbox
[sizeof(mbox_t
)];
3318 mraid_device_t
*raid_dev
= ADAP2RAIDDEV(adapter
);
3324 mbox
= (mbox_t
*)raw_mbox
;
3326 memset((caddr_t
)raw_mbox
, 0, sizeof(mbox_t
));
3330 mbox64
= raid_dev
->mbox64
;
3331 mbox
= raid_dev
->mbox
;
3333 /* Wait until mailbox is free */
3334 if (megaraid_busywait_mbox(raid_dev
) != 0) {
3336 goto blocked_mailbox
;
3339 /* Copy mailbox data into host structure */
3340 memcpy((caddr_t
)mbox
, (caddr_t
)raw_mbox
, 16);
3345 mbox
->numstatus
= 0;
3349 WRINDOOR(raid_dev
, raid_dev
->mbox_dma
| 0x1);
3351 /* Wait for maximum 1 min for status to post.
3352 * If the Firmware SUPPORTS the ABOVE COMMAND,
3353 * mbox->cmd will be set to 0
3355 * the firmware will reject the command with
3356 * mbox->numstatus set to 1
3361 while (!mbox
->numstatus
&& mbox
->cmd
== 0xFF) {
3365 if (i
> 1000 * 60) {
3370 if (mbox
->numstatus
== 1)
3371 status
= 1; /*cmd not supported*/
3373 /* Check for interrupt line */
3374 dword
= RDOUTDOOR(raid_dev
);
3375 WROUTDOOR(raid_dev
, dword
);
3376 WRINDOOR(raid_dev
,2);
3381 con_log(CL_ANN
, (KERN_WARNING
"megaraid: blocked mailbox\n"));
3386 * megaraid_mbox_display_scb - display SCB information, mostly debug purposes
3387 * @adapter : controller's soft state
3388 * @scb : SCB to be displayed
3389 * @level : debug level for console print
3391 * Diplay information about the given SCB iff the current debug level is
3395 megaraid_mbox_display_scb(adapter_t
*adapter
, scb_t
*scb
)
3398 struct scsi_cmnd
*scp
;
3404 ccb
= (mbox_ccb_t
*)scb
->ccb
;
3410 con_log(level
, (KERN_NOTICE
3411 "megaraid mailbox: status:%#x cmd:%#x id:%#x ", scb
->status
,
3412 mbox
->cmd
, scb
->sno
));
3414 con_log(level
, ("sec:%#x lba:%#x addr:%#x ld:%d sg:%d\n",
3415 mbox
->numsectors
, mbox
->lba
, mbox
->xferaddr
, mbox
->logdrv
,
3420 con_log(level
, (KERN_NOTICE
"scsi cmnd: "));
3422 for (i
= 0; i
< scp
->cmd_len
; i
++) {
3423 con_log(level
, ("%#2.02x ", scp
->cmnd
[i
]));
3426 con_log(level
, ("\n"));
3433 * megaraid_mbox_setup_device_map - manage device ids
3434 * @adapter : Driver's soft state
3436 * Manange the device ids to have an appropraite mapping between the kernel
3437 * scsi addresses and megaraid scsi and logical drive addresses. We export
3438 * scsi devices on their actual addresses, whereas the logical drives are
3439 * exported on a virtual scsi channel.
3442 megaraid_mbox_setup_device_map(adapter_t
*adapter
)
3448 * First fill the values on the logical drive channel
3450 for (t
= 0; t
< LSI_MAX_LOGICAL_DRIVES_64LD
; t
++)
3451 adapter
->device_ids
[adapter
->max_channel
][t
] =
3452 (t
< adapter
->init_id
) ? t
: t
- 1;
3454 adapter
->device_ids
[adapter
->max_channel
][adapter
->init_id
] = 0xFF;
3457 * Fill the values on the physical devices channels
3459 for (c
= 0; c
< adapter
->max_channel
; c
++)
3460 for (t
= 0; t
< LSI_MAX_LOGICAL_DRIVES_64LD
; t
++)
3461 adapter
->device_ids
[c
][t
] = (c
<< 8) | t
;
3466 * END: internal commands library
3470 * START: Interface for the common management module
3472 * This is the module, which interfaces with the common mangement module to
3473 * provide support for ioctl and sysfs
3477 * megaraid_cmm_register - register with the mangement module
3478 * @adapter : HBA soft state
3480 * Register with the management module, which allows applications to issue
3481 * ioctl calls to the drivers. This interface is used by the management module
3482 * to setup sysfs support as well.
3485 megaraid_cmm_register(adapter_t
*adapter
)
3487 mraid_device_t
*raid_dev
= ADAP2RAIDDEV(adapter
);
3494 // Allocate memory for the base list of scb for management module.
3495 adapter
->uscb_list
= kcalloc(MBOX_MAX_USER_CMDS
, sizeof(scb_t
), GFP_KERNEL
);
3497 if (adapter
->uscb_list
== NULL
) {
3498 con_log(CL_ANN
, (KERN_WARNING
3499 "megaraid: out of memory, %s %d\n", __FUNCTION__
,
3505 // Initialize the synchronization parameters for resources for
3506 // commands for management module
3507 INIT_LIST_HEAD(&adapter
->uscb_pool
);
3509 spin_lock_init(USER_FREE_LIST_LOCK(adapter
));
3513 // link all the packets. Note, CCB for commands, coming from the
3514 // commom management module, mailbox physical address are already
3515 // setup by it. We just need placeholder for that in our local command
3517 for (i
= 0; i
< MBOX_MAX_USER_CMDS
; i
++) {
3519 scb
= adapter
->uscb_list
+ i
;
3520 ccb
= raid_dev
->uccb_list
+ i
;
3522 scb
->ccb
= (caddr_t
)ccb
;
3523 ccb
->mbox64
= raid_dev
->umbox64
+ i
;
3524 ccb
->mbox
= &ccb
->mbox64
->mbox32
;
3525 ccb
->raw_mbox
= (uint8_t *)ccb
->mbox
;
3529 // COMMAND ID 0 - (MBOX_MAX_SCSI_CMDS-1) ARE RESERVED FOR
3530 // COMMANDS COMING FROM IO SUBSYSTEM (MID-LAYER)
3531 scb
->sno
= i
+ MBOX_MAX_SCSI_CMDS
;
3534 scb
->state
= SCB_FREE
;
3535 scb
->dma_direction
= PCI_DMA_NONE
;
3536 scb
->dma_type
= MRAID_DMA_NONE
;
3537 scb
->dev_channel
= -1;
3538 scb
->dev_target
= -1;
3540 // put scb in the free pool
3541 list_add_tail(&scb
->list
, &adapter
->uscb_pool
);
3544 adp
.unique_id
= adapter
->unique_id
;
3545 adp
.drvr_type
= DRVRTYPE_MBOX
;
3546 adp
.drvr_data
= (unsigned long)adapter
;
3547 adp
.pdev
= adapter
->pdev
;
3548 adp
.issue_uioc
= megaraid_mbox_mm_handler
;
3549 adp
.timeout
= MBOX_RESET_WAIT
+ MBOX_RESET_EXT_WAIT
;
3550 adp
.max_kioc
= MBOX_MAX_USER_CMDS
;
3552 if ((rval
= mraid_mm_register_adp(&adp
)) != 0) {
3554 con_log(CL_ANN
, (KERN_WARNING
3555 "megaraid mbox: did not register with CMM\n"));
3557 kfree(adapter
->uscb_list
);
3565 * megaraid_cmm_unregister - un-register with the mangement module
3566 * @adapter : HBA soft state
3568 * Un-register with the management module.
3569 * FIXME: mgmt module must return failure for unregister if it has pending
3573 megaraid_cmm_unregister(adapter_t
*adapter
)
3575 kfree(adapter
->uscb_list
);
3576 mraid_mm_unregister_adp(adapter
->unique_id
);
3582 * megaraid_mbox_mm_handler - interface for CMM to issue commands to LLD
3583 * @drvr_data : LLD specific data
3584 * @kioc : CMM interface packet
3585 * @action : command action
3587 * This routine is invoked whenever the Common Mangement Module (CMM) has a
3588 * command for us. The 'action' parameter specifies if this is a new command
3592 megaraid_mbox_mm_handler(unsigned long drvr_data
, uioc_t
*kioc
, uint32_t action
)
3596 if (action
!= IOCTL_ISSUE
) {
3597 con_log(CL_ANN
, (KERN_WARNING
3598 "megaraid: unsupported management action:%#2x\n",
3603 adapter
= (adapter_t
*)drvr_data
;
3605 // make sure this adapter is not being detached right now.
3606 if (atomic_read(&adapter
->being_detached
)) {
3607 con_log(CL_ANN
, (KERN_WARNING
3608 "megaraid: reject management request, detaching\n"));
3612 switch (kioc
->opcode
) {
3616 kioc
->status
= gather_hbainfo(adapter
, (mraid_hba_info_t
*)
3617 (unsigned long)kioc
->buf_vaddr
);
3621 return kioc
->status
;
3625 return megaraid_mbox_mm_command(adapter
, kioc
);
3628 kioc
->status
= (-EINVAL
);
3633 return 0; // not reached
3637 * megaraid_mbox_mm_command - issues commands routed through CMM
3638 * @adapter : HBA soft state
3639 * @kioc : management command packet
3641 * Issues commands, which are routed through the management module.
3644 megaraid_mbox_mm_command(adapter_t
*adapter
, uioc_t
*kioc
)
3646 struct list_head
*head
= &adapter
->uscb_pool
;
3651 unsigned long flags
;
3653 // detach one scb from free pool
3654 spin_lock_irqsave(USER_FREE_LIST_LOCK(adapter
), flags
);
3656 if (list_empty(head
)) { // should never happen because of CMM
3658 con_log(CL_ANN
, (KERN_WARNING
3659 "megaraid mbox: bug in cmm handler, lost resources\n"));
3661 spin_unlock_irqrestore(USER_FREE_LIST_LOCK(adapter
), flags
);
3666 scb
= list_entry(head
->next
, scb_t
, list
);
3667 list_del_init(&scb
->list
);
3669 spin_unlock_irqrestore(USER_FREE_LIST_LOCK(adapter
), flags
);
3671 scb
->state
= SCB_ACTIVE
;
3672 scb
->dma_type
= MRAID_DMA_NONE
;
3673 scb
->dma_direction
= PCI_DMA_NONE
;
3675 ccb
= (mbox_ccb_t
*)scb
->ccb
;
3676 mbox64
= (mbox64_t
*)(unsigned long)kioc
->cmdbuf
;
3677 raw_mbox
= (uint8_t *)&mbox64
->mbox32
;
3679 memcpy(ccb
->mbox64
, mbox64
, sizeof(mbox64_t
));
3681 scb
->gp
= (unsigned long)kioc
;
3684 * If it is a logdrv random delete operation, we have to wait till
3685 * there are no outstanding cmds at the fw and then issue it directly
3687 if (raw_mbox
[0] == FC_DEL_LOGDRV
&& raw_mbox
[2] == OP_DEL_LOGDRV
) {
3689 if (wait_till_fw_empty(adapter
)) {
3690 con_log(CL_ANN
, (KERN_NOTICE
3691 "megaraid mbox: LD delete, timed out\n"));
3693 kioc
->status
= -ETIME
;
3697 megaraid_mbox_mm_done(adapter
, scb
);
3702 INIT_LIST_HEAD(&scb
->list
);
3704 scb
->state
= SCB_ISSUED
;
3705 if (mbox_post_cmd(adapter
, scb
) != 0) {
3707 con_log(CL_ANN
, (KERN_NOTICE
3708 "megaraid mbox: LD delete, mailbox busy\n"));
3710 kioc
->status
= -EBUSY
;
3714 megaraid_mbox_mm_done(adapter
, scb
);
3722 // put the command on the pending list and execute
3723 megaraid_mbox_runpendq(adapter
, scb
);
3730 wait_till_fw_empty(adapter_t
*adapter
)
3732 unsigned long flags
= 0;
3737 * Set the quiescent flag to stop issuing cmds to FW.
3739 spin_lock_irqsave(&adapter
->lock
, flags
);
3740 adapter
->quiescent
++;
3741 spin_unlock_irqrestore(&adapter
->lock
, flags
);
3744 * Wait till there are no more cmds outstanding at FW. Try for at most
3747 for (i
= 0; i
< 60 && adapter
->outstanding_cmds
; i
++) {
3748 con_log(CL_DLEVEL1
, (KERN_INFO
3749 "megaraid: FW has %d pending commands\n",
3750 adapter
->outstanding_cmds
));
3755 return adapter
->outstanding_cmds
;
3760 * megaraid_mbox_mm_done - callback for CMM commands
3761 * @adapter : HBA soft state
3762 * @scb : completed command
3764 * Callback routine for internal commands originated from the management
3768 megaraid_mbox_mm_done(adapter_t
*adapter
, scb_t
*scb
)
3773 unsigned long flags
;
3775 kioc
= (uioc_t
*)scb
->gp
;
3776 mbox64
= (mbox64_t
*)(unsigned long)kioc
->cmdbuf
;
3777 mbox64
->mbox32
.status
= scb
->status
;
3778 raw_mbox
= (uint8_t *)&mbox64
->mbox32
;
3781 // put scb in the free pool
3782 scb
->state
= SCB_FREE
;
3785 spin_lock_irqsave(USER_FREE_LIST_LOCK(adapter
), flags
);
3787 list_add(&scb
->list
, &adapter
->uscb_pool
);
3789 spin_unlock_irqrestore(USER_FREE_LIST_LOCK(adapter
), flags
);
3791 // if a delete logical drive operation succeeded, restart the
3793 if (raw_mbox
[0] == FC_DEL_LOGDRV
&& raw_mbox
[2] == OP_DEL_LOGDRV
) {
3795 adapter
->quiescent
--;
3797 megaraid_mbox_runpendq(adapter
, NULL
);
3807 * gather_hbainfo - HBA characteristics for the applications
3808 * @adapter : HBA soft state
3809 * @hinfo : pointer to the caller's host info strucuture
3812 gather_hbainfo(adapter_t
*adapter
, mraid_hba_info_t
*hinfo
)
3816 dmajor
= megaraid_mbox_version
[0];
3818 hinfo
->pci_vendor_id
= adapter
->pdev
->vendor
;
3819 hinfo
->pci_device_id
= adapter
->pdev
->device
;
3820 hinfo
->subsys_vendor_id
= adapter
->pdev
->subsystem_vendor
;
3821 hinfo
->subsys_device_id
= adapter
->pdev
->subsystem_device
;
3823 hinfo
->pci_bus
= adapter
->pdev
->bus
->number
;
3824 hinfo
->pci_dev_fn
= adapter
->pdev
->devfn
;
3825 hinfo
->pci_slot
= PCI_SLOT(adapter
->pdev
->devfn
);
3826 hinfo
->irq
= adapter
->host
->irq
;
3827 hinfo
->baseport
= ADAP2RAIDDEV(adapter
)->baseport
;
3829 hinfo
->unique_id
= (hinfo
->pci_bus
<< 8) | adapter
->pdev
->devfn
;
3830 hinfo
->host_no
= adapter
->host
->host_no
;
3836 * END: Interface for the common management module
3842 * megaraid_sysfs_alloc_resources - allocate sysfs related resources
3843 * @adapter : controller's soft state
3845 * Allocate packets required to issue FW calls whenever the sysfs attributes
3846 * are read. These attributes would require up-to-date information from the
3847 * FW. Also set up resources for mutual exclusion to share these resources and
3850 * Return 0 on success.
3851 * Return -ERROR_CODE on failure.
3854 megaraid_sysfs_alloc_resources(adapter_t
*adapter
)
3856 mraid_device_t
*raid_dev
= ADAP2RAIDDEV(adapter
);
3859 raid_dev
->sysfs_uioc
= kmalloc(sizeof(uioc_t
), GFP_KERNEL
);
3861 raid_dev
->sysfs_mbox64
= kmalloc(sizeof(mbox64_t
), GFP_KERNEL
);
3863 raid_dev
->sysfs_buffer
= pci_alloc_consistent(adapter
->pdev
,
3864 PAGE_SIZE
, &raid_dev
->sysfs_buffer_dma
);
3866 if (!raid_dev
->sysfs_uioc
|| !raid_dev
->sysfs_mbox64
||
3867 !raid_dev
->sysfs_buffer
) {
3869 con_log(CL_ANN
, (KERN_WARNING
3870 "megaraid: out of memory, %s %d\n", __FUNCTION__
,
3875 megaraid_sysfs_free_resources(adapter
);
3878 mutex_init(&raid_dev
->sysfs_mtx
);
3880 init_waitqueue_head(&raid_dev
->sysfs_wait_q
);
3887 * megaraid_sysfs_free_resources - free sysfs related resources
3888 * @adapter : controller's soft state
3890 * Free packets allocated for sysfs FW commands
3893 megaraid_sysfs_free_resources(adapter_t
*adapter
)
3895 mraid_device_t
*raid_dev
= ADAP2RAIDDEV(adapter
);
3897 kfree(raid_dev
->sysfs_uioc
);
3898 kfree(raid_dev
->sysfs_mbox64
);
3900 if (raid_dev
->sysfs_buffer
) {
3901 pci_free_consistent(adapter
->pdev
, PAGE_SIZE
,
3902 raid_dev
->sysfs_buffer
, raid_dev
->sysfs_buffer_dma
);
3908 * megaraid_sysfs_get_ldmap_done - callback for get ldmap
3909 * @uioc : completed packet
3911 * Callback routine called in the ISR/tasklet context for get ldmap call
3914 megaraid_sysfs_get_ldmap_done(uioc_t
*uioc
)
3916 adapter_t
*adapter
= (adapter_t
*)uioc
->buf_vaddr
;
3917 mraid_device_t
*raid_dev
= ADAP2RAIDDEV(adapter
);
3921 wake_up(&raid_dev
->sysfs_wait_q
);
3926 * megaraid_sysfs_get_ldmap_timeout - timeout handling for get ldmap
3927 * @data : timed out packet
3929 * Timeout routine to recover and return to application, in case the adapter
3930 * has stopped responding. A timeout of 60 seconds for this command seems like
3934 megaraid_sysfs_get_ldmap_timeout(unsigned long data
)
3936 uioc_t
*uioc
= (uioc_t
*)data
;
3937 adapter_t
*adapter
= (adapter_t
*)uioc
->buf_vaddr
;
3938 mraid_device_t
*raid_dev
= ADAP2RAIDDEV(adapter
);
3940 uioc
->status
= -ETIME
;
3942 wake_up(&raid_dev
->sysfs_wait_q
);
3947 * megaraid_sysfs_get_ldmap - get update logical drive map
3948 * @adapter : controller's soft state
3950 * This routine will be called whenever user reads the logical drive
3951 * attributes, go get the current logical drive mapping table from the
3952 * firmware. We use the managment API's to issue commands to the controller.
3954 * NOTE: The commands issuance functionality is not generalized and
3955 * implemented in context of "get ld map" command only. If required, the
3956 * command issuance logical can be trivially pulled out and implemented as a
3957 * standalone libary. For now, this should suffice since there is no other
3958 * user of this interface.
3960 * Return 0 on success.
3961 * Return -1 on failure.
3964 megaraid_sysfs_get_ldmap(adapter_t
*adapter
)
3966 mraid_device_t
*raid_dev
= ADAP2RAIDDEV(adapter
);
3971 struct timer_list sysfs_timer
;
3972 struct timer_list
*timerp
;
3977 * Allow only one read at a time to go through the sysfs attributes
3979 mutex_lock(&raid_dev
->sysfs_mtx
);
3981 uioc
= raid_dev
->sysfs_uioc
;
3982 mbox64
= raid_dev
->sysfs_mbox64
;
3983 ldmap
= raid_dev
->sysfs_buffer
;
3985 memset(uioc
, 0, sizeof(uioc_t
));
3986 memset(mbox64
, 0, sizeof(mbox64_t
));
3987 memset(ldmap
, 0, sizeof(raid_dev
->curr_ldmap
));
3989 mbox
= &mbox64
->mbox32
;
3990 raw_mbox
= (char *)mbox
;
3991 uioc
->cmdbuf
= (uint64_t)(unsigned long)mbox64
;
3992 uioc
->buf_vaddr
= (caddr_t
)adapter
;
3993 uioc
->status
= -ENODATA
;
3994 uioc
->done
= megaraid_sysfs_get_ldmap_done
;
3997 * Prepare the mailbox packet to get the current logical drive mapping
4000 mbox
->xferaddr
= (uint32_t)raid_dev
->sysfs_buffer_dma
;
4002 raw_mbox
[0] = FC_DEL_LOGDRV
;
4003 raw_mbox
[2] = OP_GET_LDID_MAP
;
4006 * Setup a timer to recover from a non-responding controller
4008 timerp
= &sysfs_timer
;
4011 timerp
->function
= megaraid_sysfs_get_ldmap_timeout
;
4012 timerp
->data
= (unsigned long)uioc
;
4013 timerp
->expires
= jiffies
+ 60 * HZ
;
4018 * Send the command to the firmware
4020 rval
= megaraid_mbox_mm_command(adapter
, uioc
);
4022 if (rval
== 0) { // command successfully issued
4023 wait_event(raid_dev
->sysfs_wait_q
, (uioc
->status
!= -ENODATA
));
4026 * Check if the command timed out
4028 if (uioc
->status
== -ETIME
) {
4029 con_log(CL_ANN
, (KERN_NOTICE
4030 "megaraid: sysfs get ld map timed out\n"));
4035 rval
= mbox
->status
;
4039 memcpy(raid_dev
->curr_ldmap
, ldmap
,
4040 sizeof(raid_dev
->curr_ldmap
));
4043 con_log(CL_ANN
, (KERN_NOTICE
4044 "megaraid: get ld map failed with %x\n", rval
));
4048 con_log(CL_ANN
, (KERN_NOTICE
4049 "megaraid: could not issue ldmap command:%x\n", rval
));
4053 del_timer_sync(timerp
);
4055 mutex_unlock(&raid_dev
->sysfs_mtx
);
4062 * megaraid_sysfs_show_app_hndl - display application handle for this adapter
4063 * @cdev : class device object representation for the host
4064 * @buf : buffer to send data to
4066 * Display the handle used by the applications while executing management
4067 * tasks on the adapter. We invoke a management module API to get the adapter
4068 * handle, since we do not interface with applications directly.
4071 megaraid_sysfs_show_app_hndl(struct class_device
*cdev
, char *buf
)
4073 struct Scsi_Host
*shost
= class_to_shost(cdev
);
4074 adapter_t
*adapter
= (adapter_t
*)SCSIHOST2ADAP(shost
);
4077 app_hndl
= mraid_mm_adapter_app_handle(adapter
->unique_id
);
4079 return snprintf(buf
, 8, "%u\n", app_hndl
);
4084 * megaraid_sysfs_show_ldnum - display the logical drive number for this device
4085 * @dev : device object representation for the scsi device
4086 * @attr : device attribute to show
4087 * @buf : buffer to send data to
4089 * Display the logical drive number for the device in question, if it a valid
4090 * logical drive. For physical devices, "-1" is returned.
4092 * The logical drive number is displayed in following format:
4094 * <SCSI ID> <LD NUM> <LD STICKY ID> <APP ADAPTER HANDLE>
4096 * <int> <int> <int> <int>
4099 megaraid_sysfs_show_ldnum(struct device
*dev
, struct device_attribute
*attr
, char *buf
)
4101 struct scsi_device
*sdev
= to_scsi_device(dev
);
4102 adapter_t
*adapter
= (adapter_t
*)SCSIHOST2ADAP(sdev
->host
);
4103 mraid_device_t
*raid_dev
= ADAP2RAIDDEV(adapter
);
4105 int logical_drv
= -1;
4107 uint32_t app_hndl
= 0;
4112 if (raid_dev
->random_del_supported
&&
4113 MRAID_IS_LOGICAL_SDEV(adapter
, sdev
)) {
4115 rval
= megaraid_sysfs_get_ldmap(adapter
);
4118 for (i
= 0; i
< MAX_LOGICAL_DRIVES_40LD
; i
++) {
4120 mapped_sdev_id
= sdev
->id
;
4122 if (sdev
->id
> adapter
->init_id
) {
4123 mapped_sdev_id
-= 1;
4126 if (raid_dev
->curr_ldmap
[i
] == mapped_sdev_id
) {
4132 ldid_map
= raid_dev
->curr_ldmap
[i
];
4134 app_hndl
= mraid_mm_adapter_app_handle(
4135 adapter
->unique_id
);
4142 con_log(CL_ANN
, (KERN_NOTICE
4143 "megaraid: sysfs get ld map failed: %x\n",
4148 return snprintf(buf
, 36, "%d %d %d %d\n", scsi_id
, logical_drv
,
4149 ldid_map
, app_hndl
);
4154 * END: Mailbox Low Level Driver
4156 module_init(megaraid_init
);
4157 module_exit(megaraid_exit
);
4159 /* vim: set ts=8 sw=8 tw=78 ai si: */