1 // SPDX-License-Identifier: GPL-2.0-or-later
4 * Linux MegaRAID device driver
6 * Copyright (c) 2003-2004 LSI Logic Corporation.
8 * FILE : megaraid_mbox.c
9 * Version : v2.20.5.1 (Nov 16 2006)
12 * Atul Mukker <Atul.Mukker@lsi.com>
13 * Sreenivas Bagalkote <Sreenivas.Bagalkote@lsi.com>
14 * Manoj Jose <Manoj.Jose@lsi.com>
17 * List of supported controllers
19 * OEM Product Name VID DID SSVID SSID
20 * --- ------------ --- --- ---- ----
21 * Dell PERC3/QC 101E 1960 1028 0471
22 * Dell PERC3/DC 101E 1960 1028 0493
23 * Dell PERC3/SC 101E 1960 1028 0475
24 * Dell PERC3/Di 1028 1960 1028 0123
25 * Dell PERC4/SC 1000 1960 1028 0520
26 * Dell PERC4/DC 1000 1960 1028 0518
27 * Dell PERC4/QC 1000 0407 1028 0531
28 * Dell PERC4/Di 1028 000F 1028 014A
29 * Dell PERC 4e/Si 1028 0013 1028 016c
30 * Dell PERC 4e/Di 1028 0013 1028 016d
31 * Dell PERC 4e/Di 1028 0013 1028 016e
32 * Dell PERC 4e/Di 1028 0013 1028 016f
33 * Dell PERC 4e/Di 1028 0013 1028 0170
34 * Dell PERC 4e/DC 1000 0408 1028 0002
35 * Dell PERC 4e/SC 1000 0408 1028 0001
37 * LSI MegaRAID SCSI 320-0 1000 1960 1000 A520
38 * LSI MegaRAID SCSI 320-1 1000 1960 1000 0520
39 * LSI MegaRAID SCSI 320-2 1000 1960 1000 0518
40 * LSI MegaRAID SCSI 320-0X 1000 0407 1000 0530
41 * LSI MegaRAID SCSI 320-2X 1000 0407 1000 0532
42 * LSI MegaRAID SCSI 320-4X 1000 0407 1000 0531
43 * LSI MegaRAID SCSI 320-1E 1000 0408 1000 0001
44 * LSI MegaRAID SCSI 320-2E 1000 0408 1000 0002
45 * LSI MegaRAID SATA 150-4 1000 1960 1000 4523
46 * LSI MegaRAID SATA 150-6 1000 1960 1000 0523
47 * LSI MegaRAID SATA 300-4X 1000 0409 1000 3004
48 * LSI MegaRAID SATA 300-8X 1000 0409 1000 3008
50 * INTEL RAID Controller SRCU42X 1000 0407 8086 0532
51 * INTEL RAID Controller SRCS16 1000 1960 8086 0523
52 * INTEL RAID Controller SRCU42E 1000 0408 8086 0002
53 * INTEL RAID Controller SRCZCRX 1000 0407 8086 0530
54 * INTEL RAID Controller SRCS28X 1000 0409 8086 3008
55 * INTEL RAID Controller SROMBU42E 1000 0408 8086 3431
56 * INTEL RAID Controller SROMBU42E 1000 0408 8086 3499
57 * INTEL RAID Controller SRCU51L 1000 1960 8086 0520
59 * FSC MegaRAID PCI Express ROMB 1000 0408 1734 1065
61 * ACER MegaRAID ROMB-2E 1000 0408 1025 004D
63 * NEC MegaRAID PCI Express ROMB 1000 0408 1033 8287
65 * For history of changes, see Documentation/scsi/ChangeLog.megaraid
68 #include <linux/slab.h>
69 #include <linux/module.h>
70 #include "megaraid_mbox.h"
72 static int megaraid_init(void);
73 static void megaraid_exit(void);
75 static int megaraid_probe_one(struct pci_dev
*, const struct pci_device_id
*);
76 static void megaraid_detach_one(struct pci_dev
*);
77 static void megaraid_mbox_shutdown(struct pci_dev
*);
79 static int megaraid_io_attach(adapter_t
*);
80 static void megaraid_io_detach(adapter_t
*);
82 static int megaraid_init_mbox(adapter_t
*);
83 static void megaraid_fini_mbox(adapter_t
*);
85 static int megaraid_alloc_cmd_packets(adapter_t
*);
86 static void megaraid_free_cmd_packets(adapter_t
*);
88 static int megaraid_mbox_setup_dma_pools(adapter_t
*);
89 static void megaraid_mbox_teardown_dma_pools(adapter_t
*);
91 static int megaraid_sysfs_alloc_resources(adapter_t
*);
92 static void megaraid_sysfs_free_resources(adapter_t
*);
94 static int megaraid_abort_handler(struct scsi_cmnd
*);
95 static int megaraid_reset_handler(struct scsi_cmnd
*);
97 static int mbox_post_sync_cmd(adapter_t
*, uint8_t []);
98 static int mbox_post_sync_cmd_fast(adapter_t
*, uint8_t []);
99 static int megaraid_busywait_mbox(mraid_device_t
*);
100 static int megaraid_mbox_product_info(adapter_t
*);
101 static int megaraid_mbox_extended_cdb(adapter_t
*);
102 static int megaraid_mbox_support_ha(adapter_t
*, uint16_t *);
103 static int megaraid_mbox_support_random_del(adapter_t
*);
104 static int megaraid_mbox_get_max_sg(adapter_t
*);
105 static void megaraid_mbox_enum_raid_scsi(adapter_t
*);
106 static void megaraid_mbox_flush_cache(adapter_t
*);
107 static int megaraid_mbox_fire_sync_cmd(adapter_t
*);
109 static void megaraid_mbox_display_scb(adapter_t
*, scb_t
*);
110 static void megaraid_mbox_setup_device_map(adapter_t
*);
112 static int megaraid_queue_command(struct Scsi_Host
*, struct scsi_cmnd
*);
113 static scb_t
*megaraid_mbox_build_cmd(adapter_t
*, struct scsi_cmnd
*, int *);
114 static void megaraid_mbox_runpendq(adapter_t
*, scb_t
*);
115 static void megaraid_mbox_prepare_pthru(adapter_t
*, scb_t
*,
117 static void megaraid_mbox_prepare_epthru(adapter_t
*, scb_t
*,
120 static irqreturn_t
megaraid_isr(int, void *);
122 static void megaraid_mbox_dpc(unsigned long);
124 static ssize_t
megaraid_sysfs_show_app_hndl(struct device
*, struct device_attribute
*attr
, char *);
125 static ssize_t
megaraid_sysfs_show_ldnum(struct device
*, struct device_attribute
*attr
, char *);
127 static int megaraid_cmm_register(adapter_t
*);
128 static int megaraid_cmm_unregister(adapter_t
*);
129 static int megaraid_mbox_mm_handler(unsigned long, uioc_t
*, uint32_t);
130 static int megaraid_mbox_mm_command(adapter_t
*, uioc_t
*);
131 static void megaraid_mbox_mm_done(adapter_t
*, scb_t
*);
132 static int gather_hbainfo(adapter_t
*, mraid_hba_info_t
*);
133 static int wait_till_fw_empty(adapter_t
*);
137 MODULE_AUTHOR("megaraidlinux@lsi.com");
138 MODULE_DESCRIPTION("LSI Logic MegaRAID Mailbox Driver");
139 MODULE_LICENSE("GPL");
140 MODULE_VERSION(MEGARAID_VERSION
);
143 * ### modules parameters for driver ###
147 * Set to enable driver to expose unconfigured disk to kernel
149 static int megaraid_expose_unconf_disks
= 0;
150 module_param_named(unconf_disks
, megaraid_expose_unconf_disks
, int, 0);
151 MODULE_PARM_DESC(unconf_disks
,
152 "Set to expose unconfigured disks to kernel (default=0)");
155 * driver wait time if the adapter's mailbox is busy
157 static unsigned int max_mbox_busy_wait
= MBOX_BUSY_WAIT
;
158 module_param_named(busy_wait
, max_mbox_busy_wait
, int, 0);
159 MODULE_PARM_DESC(busy_wait
,
160 "Max wait for mailbox in microseconds if busy (default=10)");
163 * number of sectors per IO command
165 static unsigned int megaraid_max_sectors
= MBOX_MAX_SECTORS
;
166 module_param_named(max_sectors
, megaraid_max_sectors
, int, 0);
167 MODULE_PARM_DESC(max_sectors
,
168 "Maximum number of sectors per IO command (default=128)");
171 * number of commands per logical unit
173 static unsigned int megaraid_cmd_per_lun
= MBOX_DEF_CMD_PER_LUN
;
174 module_param_named(cmd_per_lun
, megaraid_cmd_per_lun
, int, 0);
175 MODULE_PARM_DESC(cmd_per_lun
,
176 "Maximum number of commands per logical unit (default=64)");
180 * Fast driver load option, skip scanning for physical devices during load.
181 * This would result in non-disk devices being skipped during driver load
182 * time. These can be later added though, using /proc/scsi/scsi
184 static unsigned int megaraid_fast_load
= 0;
185 module_param_named(fast_load
, megaraid_fast_load
, int, 0);
186 MODULE_PARM_DESC(fast_load
,
187 "Faster loading of the driver, skips physical devices! (default=0)");
191 * mraid_debug level - threshold for amount of information to be displayed by
192 * the driver. This level can be changed through modules parameters, ioctl or
193 * sysfs/proc interface. By default, print the announcement messages only.
195 int mraid_debug_level
= CL_ANN
;
196 module_param_named(debug_level
, mraid_debug_level
, int, 0);
197 MODULE_PARM_DESC(debug_level
, "Debug level for driver (default=0)");
200 * PCI table for all supported controllers.
202 static struct pci_device_id pci_id_table_g
[] = {
205 PCI_DEVICE_ID_PERC4_DI_DISCOVERY
,
207 PCI_SUBSYS_ID_PERC4_DI_DISCOVERY
,
210 PCI_VENDOR_ID_LSI_LOGIC
,
211 PCI_DEVICE_ID_PERC4_SC
,
213 PCI_SUBSYS_ID_PERC4_SC
,
216 PCI_VENDOR_ID_LSI_LOGIC
,
217 PCI_DEVICE_ID_PERC4_DC
,
219 PCI_SUBSYS_ID_PERC4_DC
,
222 PCI_VENDOR_ID_LSI_LOGIC
,
229 PCI_DEVICE_ID_PERC4_DI_EVERGLADES
,
231 PCI_SUBSYS_ID_PERC4_DI_EVERGLADES
,
235 PCI_DEVICE_ID_PERC4E_SI_BIGBEND
,
237 PCI_SUBSYS_ID_PERC4E_SI_BIGBEND
,
241 PCI_DEVICE_ID_PERC4E_DI_KOBUK
,
243 PCI_SUBSYS_ID_PERC4E_DI_KOBUK
,
247 PCI_DEVICE_ID_PERC4E_DI_CORVETTE
,
249 PCI_SUBSYS_ID_PERC4E_DI_CORVETTE
,
253 PCI_DEVICE_ID_PERC4E_DI_EXPEDITION
,
255 PCI_SUBSYS_ID_PERC4E_DI_EXPEDITION
,
259 PCI_DEVICE_ID_PERC4E_DI_GUADALUPE
,
261 PCI_SUBSYS_ID_PERC4E_DI_GUADALUPE
,
264 PCI_VENDOR_ID_LSI_LOGIC
,
265 PCI_DEVICE_ID_DOBSON
,
271 PCI_DEVICE_ID_AMI_MEGARAID3
,
276 PCI_VENDOR_ID_LSI_LOGIC
,
277 PCI_DEVICE_ID_AMI_MEGARAID3
,
282 PCI_VENDOR_ID_LSI_LOGIC
,
283 PCI_DEVICE_ID_LINDSAY
,
287 {0} /* Terminating entry */
289 MODULE_DEVICE_TABLE(pci
, pci_id_table_g
);
292 static struct pci_driver megaraid_pci_driver
= {
294 .id_table
= pci_id_table_g
,
295 .probe
= megaraid_probe_one
,
296 .remove
= megaraid_detach_one
,
297 .shutdown
= megaraid_mbox_shutdown
,
302 // definitions for the device attributes for exporting logical drive number
303 // for a scsi address (Host, Channel, Id, Lun)
305 static DEVICE_ATTR(megaraid_mbox_app_hndl
, S_IRUSR
, megaraid_sysfs_show_app_hndl
,
308 // Host template initializer for megaraid mbox sysfs device attributes
309 static struct device_attribute
*megaraid_shost_attrs
[] = {
310 &dev_attr_megaraid_mbox_app_hndl
,
315 static DEVICE_ATTR(megaraid_mbox_ld
, S_IRUSR
, megaraid_sysfs_show_ldnum
, NULL
);
317 // Host template initializer for megaraid mbox sysfs device attributes
318 static struct device_attribute
*megaraid_sdev_attrs
[] = {
319 &dev_attr_megaraid_mbox_ld
,
324 * Scsi host template for megaraid unified driver
326 static struct scsi_host_template megaraid_template_g
= {
327 .module
= THIS_MODULE
,
328 .name
= "LSI Logic MegaRAID driver",
329 .proc_name
= "megaraid",
330 .queuecommand
= megaraid_queue_command
,
331 .eh_abort_handler
= megaraid_abort_handler
,
332 .eh_host_reset_handler
= megaraid_reset_handler
,
333 .change_queue_depth
= scsi_change_queue_depth
,
335 .sdev_attrs
= megaraid_sdev_attrs
,
336 .shost_attrs
= megaraid_shost_attrs
,
341 * megaraid_init - module load hook
343 * We register ourselves as hotplug enabled module and let PCI subsystem
344 * discover our adapters.
351 // Announce the driver version
352 con_log(CL_ANN
, (KERN_INFO
"megaraid: %s %s\n", MEGARAID_VERSION
,
353 MEGARAID_EXT_VERSION
));
355 // check validity of module parameters
356 if (megaraid_cmd_per_lun
> MBOX_MAX_SCSI_CMDS
) {
358 con_log(CL_ANN
, (KERN_WARNING
359 "megaraid mailbox: max commands per lun reset to %d\n",
360 MBOX_MAX_SCSI_CMDS
));
362 megaraid_cmd_per_lun
= MBOX_MAX_SCSI_CMDS
;
366 // register as a PCI hot-plug driver module
367 rval
= pci_register_driver(&megaraid_pci_driver
);
369 con_log(CL_ANN
, (KERN_WARNING
370 "megaraid: could not register hotplug support.\n"));
378 * megaraid_exit - driver unload entry point
380 * We simply unwrap the megaraid_init routine here.
385 con_log(CL_DLEVEL1
, (KERN_NOTICE
"megaraid: unloading framework\n"));
387 // unregister as PCI hotplug driver
388 pci_unregister_driver(&megaraid_pci_driver
);
395 * megaraid_probe_one - PCI hotplug entry point
396 * @pdev : handle to this controller's PCI configuration space
397 * @id : pci device id of the class of controllers
399 * This routine should be called whenever a new adapter is detected by the
400 * PCI hotplug susbsystem.
403 megaraid_probe_one(struct pci_dev
*pdev
, const struct pci_device_id
*id
)
408 // detected a new controller
409 con_log(CL_ANN
, (KERN_INFO
410 "megaraid: probe new device %#4.04x:%#4.04x:%#4.04x:%#4.04x: ",
411 pdev
->vendor
, pdev
->device
, pdev
->subsystem_vendor
,
412 pdev
->subsystem_device
));
414 con_log(CL_ANN
, ("bus %d:slot %d:func %d\n", pdev
->bus
->number
,
415 PCI_SLOT(pdev
->devfn
), PCI_FUNC(pdev
->devfn
)));
417 if (pci_enable_device(pdev
)) {
418 con_log(CL_ANN
, (KERN_WARNING
419 "megaraid: pci_enable_device failed\n"));
424 // Enable bus-mastering on this controller
425 pci_set_master(pdev
);
427 // Allocate the per driver initialization structure
428 adapter
= kzalloc(sizeof(adapter_t
), GFP_KERNEL
);
430 if (adapter
== NULL
) {
431 con_log(CL_ANN
, (KERN_WARNING
432 "megaraid: out of memory, %s %d.\n", __func__
, __LINE__
));
438 // set up PCI related soft state and other pre-known parameters
439 adapter
->unique_id
= pdev
->bus
->number
<< 8 | pdev
->devfn
;
440 adapter
->irq
= pdev
->irq
;
441 adapter
->pdev
= pdev
;
443 atomic_set(&adapter
->being_detached
, 0);
445 // Setup the default DMA mask. This would be changed later on
446 // depending on hardware capabilities
447 if (dma_set_mask(&adapter
->pdev
->dev
, DMA_BIT_MASK(32))) {
448 con_log(CL_ANN
, (KERN_WARNING
449 "megaraid: dma_set_mask failed:%d\n", __LINE__
));
451 goto out_free_adapter
;
455 // Initialize the synchronization lock for kernel and LLD
456 spin_lock_init(&adapter
->lock
);
458 // Initialize the command queues: the list of free SCBs and the list
460 INIT_LIST_HEAD(&adapter
->kscb_pool
);
461 spin_lock_init(SCSI_FREE_LIST_LOCK(adapter
));
463 INIT_LIST_HEAD(&adapter
->pend_list
);
464 spin_lock_init(PENDING_LIST_LOCK(adapter
));
466 INIT_LIST_HEAD(&adapter
->completed_list
);
467 spin_lock_init(COMPLETED_LIST_LOCK(adapter
));
470 // Start the mailbox based controller
471 if (megaraid_init_mbox(adapter
) != 0) {
472 con_log(CL_ANN
, (KERN_WARNING
473 "megaraid: mailbox adapter did not initialize\n"));
475 goto out_free_adapter
;
478 // Register with LSI Common Management Module
479 if (megaraid_cmm_register(adapter
) != 0) {
481 con_log(CL_ANN
, (KERN_WARNING
482 "megaraid: could not register with management module\n"));
487 // setup adapter handle in PCI soft state
488 pci_set_drvdata(pdev
, adapter
);
490 // attach with scsi mid-layer
491 if (megaraid_io_attach(adapter
) != 0) {
493 con_log(CL_ANN
, (KERN_WARNING
"megaraid: io attach failed\n"));
501 megaraid_cmm_unregister(adapter
);
503 megaraid_fini_mbox(adapter
);
507 pci_disable_device(pdev
);
514 * megaraid_detach_one - release framework resources and call LLD release routine
515 * @pdev : handle for our PCI configuration space
517 * This routine is called during driver unload. We free all the allocated
518 * resources and call the corresponding LLD so that it can also release all
521 * This routine is also called from the PCI hotplug system.
524 megaraid_detach_one(struct pci_dev
*pdev
)
527 struct Scsi_Host
*host
;
530 // Start a rollback on this adapter
531 adapter
= pci_get_drvdata(pdev
);
534 con_log(CL_ANN
, (KERN_CRIT
535 "megaraid: Invalid detach on %#4.04x:%#4.04x:%#4.04x:%#4.04x\n",
536 pdev
->vendor
, pdev
->device
, pdev
->subsystem_vendor
,
537 pdev
->subsystem_device
));
542 con_log(CL_ANN
, (KERN_NOTICE
543 "megaraid: detaching device %#4.04x:%#4.04x:%#4.04x:%#4.04x\n",
544 pdev
->vendor
, pdev
->device
, pdev
->subsystem_vendor
,
545 pdev
->subsystem_device
));
549 host
= adapter
->host
;
551 // do not allow any more requests from the management module for this
553 // FIXME: How do we account for the request which might still be
555 atomic_set(&adapter
->being_detached
, 1);
557 // detach from the IO sub-system
558 megaraid_io_detach(adapter
);
560 // Unregister from common management module
562 // FIXME: this must return success or failure for conditions if there
563 // is a command pending with LLD or not.
564 megaraid_cmm_unregister(adapter
);
566 // finalize the mailbox based controller and release all resources
567 megaraid_fini_mbox(adapter
);
573 pci_disable_device(pdev
);
580 * megaraid_mbox_shutdown - PCI shutdown for megaraid HBA
581 * @pdev : generic driver model device
583 * Shutdown notification, perform flush cache.
586 megaraid_mbox_shutdown(struct pci_dev
*pdev
)
588 adapter_t
*adapter
= pci_get_drvdata(pdev
);
592 con_log(CL_ANN
, (KERN_WARNING
593 "megaraid: null device in shutdown\n"));
598 con_log(CL_ANN
, (KERN_INFO
"megaraid: flushing adapter %d...",
601 megaraid_mbox_flush_cache(adapter
);
603 con_log(CL_ANN
, ("done\n"));
608 * megaraid_io_attach - attach a device with the IO subsystem
609 * @adapter : controller's soft state
611 * Attach this device with the IO subsystem.
614 megaraid_io_attach(adapter_t
*adapter
)
616 struct Scsi_Host
*host
;
618 // Initialize SCSI Host structure
619 host
= scsi_host_alloc(&megaraid_template_g
, 8);
621 con_log(CL_ANN
, (KERN_WARNING
622 "megaraid mbox: scsi_register failed\n"));
627 SCSIHOST2ADAP(host
) = (caddr_t
)adapter
;
628 adapter
->host
= host
;
630 host
->irq
= adapter
->irq
;
631 host
->unique_id
= adapter
->unique_id
;
632 host
->can_queue
= adapter
->max_cmds
;
633 host
->this_id
= adapter
->init_id
;
634 host
->sg_tablesize
= adapter
->sglen
;
635 host
->max_sectors
= adapter
->max_sectors
;
636 host
->cmd_per_lun
= adapter
->cmd_per_lun
;
637 host
->max_channel
= adapter
->max_channel
;
638 host
->max_id
= adapter
->max_target
;
639 host
->max_lun
= adapter
->max_lun
;
642 // notify mid-layer about the new controller
643 if (scsi_add_host(host
, &adapter
->pdev
->dev
)) {
645 con_log(CL_ANN
, (KERN_WARNING
646 "megaraid mbox: scsi_add_host failed\n"));
653 scsi_scan_host(host
);
660 * megaraid_io_detach - detach a device from the IO subsystem
661 * @adapter : controller's soft state
663 * Detach this device from the IO subsystem.
666 megaraid_io_detach(adapter_t
*adapter
)
668 struct Scsi_Host
*host
;
670 con_log(CL_DLEVEL1
, (KERN_INFO
"megaraid: io detach\n"));
672 host
= adapter
->host
;
674 scsi_remove_host(host
);
681 * START: Mailbox Low Level Driver
683 * This is section specific to the single mailbox based controllers
687 * megaraid_init_mbox - initialize controller
688 * @adapter : our soft state
690 * - Allocate 16-byte aligned mailbox memory for firmware handshake
691 * - Allocate controller's memory resources
692 * - Find out all initialization data
693 * - Allocate memory required for all the commands
694 * - Use internal library of FW routines, build up complete soft state
697 megaraid_init_mbox(adapter_t
*adapter
)
699 struct pci_dev
*pdev
;
700 mraid_device_t
*raid_dev
;
705 adapter
->ito
= MBOX_TIMEOUT
;
706 pdev
= adapter
->pdev
;
709 * Allocate and initialize the init data structure for mailbox
712 raid_dev
= kzalloc(sizeof(mraid_device_t
), GFP_KERNEL
);
713 if (raid_dev
== NULL
) return -1;
717 * Attach the adapter soft state to raid device soft state
719 adapter
->raid_device
= (caddr_t
)raid_dev
;
720 raid_dev
->fast_load
= megaraid_fast_load
;
724 raid_dev
->baseport
= pci_resource_start(pdev
, 0);
726 if (pci_request_regions(pdev
, "MegaRAID: LSI Logic Corporation") != 0) {
728 con_log(CL_ANN
, (KERN_WARNING
729 "megaraid: mem region busy\n"));
731 goto out_free_raid_dev
;
734 raid_dev
->baseaddr
= ioremap(raid_dev
->baseport
, 128);
736 if (!raid_dev
->baseaddr
) {
738 con_log(CL_ANN
, (KERN_WARNING
739 "megaraid: could not map hba memory\n") );
741 goto out_release_regions
;
744 /* initialize the mutual exclusion lock for the mailbox */
745 spin_lock_init(&raid_dev
->mailbox_lock
);
747 /* allocate memory required for commands */
748 if (megaraid_alloc_cmd_packets(adapter
) != 0)
752 * Issue SYNC cmd to flush the pending cmds in the adapter
753 * and initialize its internal state
756 if (megaraid_mbox_fire_sync_cmd(adapter
))
757 con_log(CL_ANN
, ("megaraid: sync cmd failed\n"));
760 * Setup the rest of the soft state using the library of
764 /* request IRQ and register the interrupt service routine */
765 if (request_irq(adapter
->irq
, megaraid_isr
, IRQF_SHARED
, "megaraid",
768 con_log(CL_ANN
, (KERN_WARNING
769 "megaraid: Couldn't register IRQ %d!\n", adapter
->irq
));
775 if (megaraid_mbox_product_info(adapter
) != 0)
778 // Do we support extended CDBs
779 adapter
->max_cdb_sz
= 10;
780 if (megaraid_mbox_extended_cdb(adapter
) == 0) {
781 adapter
->max_cdb_sz
= 16;
785 * Do we support cluster environment, if we do, what is the initiator
787 * NOTE: In a non-cluster aware firmware environment, the LLD should
788 * return 7 as initiator id.
791 adapter
->init_id
= -1;
792 if (megaraid_mbox_support_ha(adapter
, &adapter
->init_id
) == 0) {
797 * Prepare the device ids array to have the mapping between the kernel
798 * device address and megaraid device address.
799 * We export the physical devices on their actual addresses. The
800 * logical drives are exported on a virtual SCSI channel
802 megaraid_mbox_setup_device_map(adapter
);
804 // If the firmware supports random deletion, update the device id map
805 if (megaraid_mbox_support_random_del(adapter
)) {
807 // Change the logical drives numbers in device_ids array one
808 // slot in device_ids is reserved for target id, that's why
810 for (i
= 0; i
<= MAX_LOGICAL_DRIVES_40LD
; i
++) {
811 adapter
->device_ids
[adapter
->max_channel
][i
] += 0x80;
813 adapter
->device_ids
[adapter
->max_channel
][adapter
->init_id
] =
816 raid_dev
->random_del_supported
= 1;
820 * find out the maximum number of scatter-gather elements supported by
823 adapter
->sglen
= megaraid_mbox_get_max_sg(adapter
);
825 // enumerate RAID and SCSI channels so that all devices on SCSI
826 // channels can later be exported, including disk devices
827 megaraid_mbox_enum_raid_scsi(adapter
);
830 * Other parameters required by upper layer
832 * maximum number of sectors per IO command
834 adapter
->max_sectors
= megaraid_max_sectors
;
837 * number of queued commands per LUN.
839 adapter
->cmd_per_lun
= megaraid_cmd_per_lun
;
842 * Allocate resources required to issue FW calls, when sysfs is
845 if (megaraid_sysfs_alloc_resources(adapter
) != 0)
848 // Set the DMA mask to 64-bit. All supported controllers as capable of
850 pci_read_config_dword(adapter
->pdev
, PCI_CONF_AMISIG64
, &magic64
);
852 if (((magic64
== HBA_SIGNATURE_64_BIT
) &&
853 ((adapter
->pdev
->subsystem_device
!=
854 PCI_SUBSYS_ID_MEGARAID_SATA_150_6
) &&
855 (adapter
->pdev
->subsystem_device
!=
856 PCI_SUBSYS_ID_MEGARAID_SATA_150_4
))) ||
857 (adapter
->pdev
->vendor
== PCI_VENDOR_ID_LSI_LOGIC
&&
858 adapter
->pdev
->device
== PCI_DEVICE_ID_VERDE
) ||
859 (adapter
->pdev
->vendor
== PCI_VENDOR_ID_LSI_LOGIC
&&
860 adapter
->pdev
->device
== PCI_DEVICE_ID_DOBSON
) ||
861 (adapter
->pdev
->vendor
== PCI_VENDOR_ID_LSI_LOGIC
&&
862 adapter
->pdev
->device
== PCI_DEVICE_ID_LINDSAY
) ||
863 (adapter
->pdev
->vendor
== PCI_VENDOR_ID_DELL
&&
864 adapter
->pdev
->device
== PCI_DEVICE_ID_PERC4_DI_EVERGLADES
) ||
865 (adapter
->pdev
->vendor
== PCI_VENDOR_ID_DELL
&&
866 adapter
->pdev
->device
== PCI_DEVICE_ID_PERC4E_DI_KOBUK
)) {
867 if (dma_set_mask(&adapter
->pdev
->dev
, DMA_BIT_MASK(64))) {
868 con_log(CL_ANN
, (KERN_WARNING
869 "megaraid: DMA mask for 64-bit failed\n"));
871 if (dma_set_mask(&adapter
->pdev
->dev
,
873 con_log(CL_ANN
, (KERN_WARNING
874 "megaraid: 32-bit DMA mask failed\n"));
875 goto out_free_sysfs_res
;
880 // setup tasklet for DPC
881 tasklet_init(&adapter
->dpc_h
, megaraid_mbox_dpc
,
882 (unsigned long)adapter
);
884 con_log(CL_DLEVEL1
, (KERN_INFO
885 "megaraid mbox hba successfully initialized\n"));
890 megaraid_sysfs_free_resources(adapter
);
892 free_irq(adapter
->irq
, adapter
);
894 megaraid_free_cmd_packets(adapter
);
896 iounmap(raid_dev
->baseaddr
);
898 pci_release_regions(pdev
);
907 * megaraid_fini_mbox - undo controller initialization
908 * @adapter : our soft state
911 megaraid_fini_mbox(adapter_t
*adapter
)
913 mraid_device_t
*raid_dev
= ADAP2RAIDDEV(adapter
);
916 megaraid_mbox_flush_cache(adapter
);
918 tasklet_kill(&adapter
->dpc_h
);
920 megaraid_sysfs_free_resources(adapter
);
922 megaraid_free_cmd_packets(adapter
);
924 free_irq(adapter
->irq
, adapter
);
926 iounmap(raid_dev
->baseaddr
);
928 pci_release_regions(adapter
->pdev
);
937 * megaraid_alloc_cmd_packets - allocate shared mailbox
938 * @adapter : soft state of the raid controller
940 * Allocate and align the shared mailbox. This mailbox is used to issue
941 * all the commands. For IO based controllers, the mailbox is also registered
942 * with the FW. Allocate memory for all commands as well.
943 * This is our big allocator.
946 megaraid_alloc_cmd_packets(adapter_t
*adapter
)
948 mraid_device_t
*raid_dev
= ADAP2RAIDDEV(adapter
);
949 struct pci_dev
*pdev
;
953 struct mraid_pci_blk
*epthru_pci_blk
;
954 struct mraid_pci_blk
*sg_pci_blk
;
955 struct mraid_pci_blk
*mbox_pci_blk
;
958 pdev
= adapter
->pdev
;
962 * Allocate the common 16-byte aligned memory for the handshake
965 raid_dev
->una_mbox64
= dma_alloc_coherent(&adapter
->pdev
->dev
,
967 &raid_dev
->una_mbox64_dma
,
970 if (!raid_dev
->una_mbox64
) {
971 con_log(CL_ANN
, (KERN_WARNING
972 "megaraid: out of memory, %s %d\n", __func__
,
978 * Align the mailbox at 16-byte boundary
980 raid_dev
->mbox
= &raid_dev
->una_mbox64
->mbox32
;
982 raid_dev
->mbox
= (mbox_t
*)((((unsigned long)raid_dev
->mbox
) + 15) &
985 raid_dev
->mbox64
= (mbox64_t
*)(((unsigned long)raid_dev
->mbox
) - 8);
987 align
= ((void *)raid_dev
->mbox
-
988 ((void *)&raid_dev
->una_mbox64
->mbox32
));
990 raid_dev
->mbox_dma
= (unsigned long)raid_dev
->una_mbox64_dma
+ 8 +
993 // Allocate memory for commands issued internally
994 adapter
->ibuf
= dma_alloc_coherent(&pdev
->dev
, MBOX_IBUF_SIZE
,
995 &adapter
->ibuf_dma_h
, GFP_KERNEL
);
996 if (!adapter
->ibuf
) {
998 con_log(CL_ANN
, (KERN_WARNING
999 "megaraid: out of memory, %s %d\n", __func__
,
1002 goto out_free_common_mbox
;
1005 // Allocate memory for our SCSI Command Blocks and their associated
1009 * Allocate memory for the base list of scb. Later allocate memory for
1010 * CCBs and embedded components of each CCB and point the pointers in
1011 * scb to the allocated components
1012 * NOTE: The code to allocate SCB will be duplicated in all the LLD
1013 * since the calling routine does not yet know the number of available
1016 adapter
->kscb_list
= kcalloc(MBOX_MAX_SCSI_CMDS
, sizeof(scb_t
), GFP_KERNEL
);
1018 if (adapter
->kscb_list
== NULL
) {
1019 con_log(CL_ANN
, (KERN_WARNING
1020 "megaraid: out of memory, %s %d\n", __func__
,
1025 // memory allocation for our command packets
1026 if (megaraid_mbox_setup_dma_pools(adapter
) != 0) {
1027 con_log(CL_ANN
, (KERN_WARNING
1028 "megaraid: out of memory, %s %d\n", __func__
,
1030 goto out_free_scb_list
;
1033 // Adjust the scb pointers and link in the free pool
1034 epthru_pci_blk
= raid_dev
->epthru_pool
;
1035 sg_pci_blk
= raid_dev
->sg_pool
;
1036 mbox_pci_blk
= raid_dev
->mbox_pool
;
1038 for (i
= 0; i
< MBOX_MAX_SCSI_CMDS
; i
++) {
1039 scb
= adapter
->kscb_list
+ i
;
1040 ccb
= raid_dev
->ccb_list
+ i
;
1042 ccb
->mbox
= (mbox_t
*)(mbox_pci_blk
[i
].vaddr
+ 16);
1043 ccb
->raw_mbox
= (uint8_t *)ccb
->mbox
;
1044 ccb
->mbox64
= (mbox64_t
*)(mbox_pci_blk
[i
].vaddr
+ 8);
1045 ccb
->mbox_dma_h
= (unsigned long)mbox_pci_blk
[i
].dma_addr
+ 16;
1047 // make sure the mailbox is aligned properly
1048 if (ccb
->mbox_dma_h
& 0x0F) {
1049 con_log(CL_ANN
, (KERN_CRIT
1050 "megaraid mbox: not aligned on 16-bytes\n"));
1052 goto out_teardown_dma_pools
;
1055 ccb
->epthru
= (mraid_epassthru_t
*)
1056 epthru_pci_blk
[i
].vaddr
;
1057 ccb
->epthru_dma_h
= epthru_pci_blk
[i
].dma_addr
;
1058 ccb
->pthru
= (mraid_passthru_t
*)ccb
->epthru
;
1059 ccb
->pthru_dma_h
= ccb
->epthru_dma_h
;
1062 ccb
->sgl64
= (mbox_sgl64
*)sg_pci_blk
[i
].vaddr
;
1063 ccb
->sgl_dma_h
= sg_pci_blk
[i
].dma_addr
;
1064 ccb
->sgl32
= (mbox_sgl32
*)ccb
->sgl64
;
1066 scb
->ccb
= (caddr_t
)ccb
;
1069 scb
->sno
= i
; // command index
1072 scb
->state
= SCB_FREE
;
1073 scb
->dma_direction
= DMA_NONE
;
1074 scb
->dma_type
= MRAID_DMA_NONE
;
1075 scb
->dev_channel
= -1;
1076 scb
->dev_target
= -1;
1078 // put scb in the free pool
1079 list_add_tail(&scb
->list
, &adapter
->kscb_pool
);
1084 out_teardown_dma_pools
:
1085 megaraid_mbox_teardown_dma_pools(adapter
);
1087 kfree(adapter
->kscb_list
);
1089 dma_free_coherent(&pdev
->dev
, MBOX_IBUF_SIZE
, (void *)adapter
->ibuf
,
1090 adapter
->ibuf_dma_h
);
1091 out_free_common_mbox
:
1092 dma_free_coherent(&adapter
->pdev
->dev
, sizeof(mbox64_t
),
1093 (caddr_t
)raid_dev
->una_mbox64
, raid_dev
->una_mbox64_dma
);
1100 * megaraid_free_cmd_packets - free memory
1101 * @adapter : soft state of the raid controller
1103 * Release memory resources allocated for commands.
1106 megaraid_free_cmd_packets(adapter_t
*adapter
)
1108 mraid_device_t
*raid_dev
= ADAP2RAIDDEV(adapter
);
1110 megaraid_mbox_teardown_dma_pools(adapter
);
1112 kfree(adapter
->kscb_list
);
1114 dma_free_coherent(&adapter
->pdev
->dev
, MBOX_IBUF_SIZE
,
1115 (void *)adapter
->ibuf
, adapter
->ibuf_dma_h
);
1117 dma_free_coherent(&adapter
->pdev
->dev
, sizeof(mbox64_t
),
1118 (caddr_t
)raid_dev
->una_mbox64
, raid_dev
->una_mbox64_dma
);
1124 * megaraid_mbox_setup_dma_pools - setup dma pool for command packets
1125 * @adapter : HBA soft state
1127 * Setup the dma pools for mailbox, passthru and extended passthru structures,
1128 * and scatter-gather lists.
1131 megaraid_mbox_setup_dma_pools(adapter_t
*adapter
)
1133 mraid_device_t
*raid_dev
= ADAP2RAIDDEV(adapter
);
1134 struct mraid_pci_blk
*epthru_pci_blk
;
1135 struct mraid_pci_blk
*sg_pci_blk
;
1136 struct mraid_pci_blk
*mbox_pci_blk
;
1141 // Allocate memory for 16-bytes aligned mailboxes
1142 raid_dev
->mbox_pool_handle
= dma_pool_create("megaraid mbox pool",
1143 &adapter
->pdev
->dev
,
1144 sizeof(mbox64_t
) + 16,
1147 if (raid_dev
->mbox_pool_handle
== NULL
) {
1148 goto fail_setup_dma_pool
;
1151 mbox_pci_blk
= raid_dev
->mbox_pool
;
1152 for (i
= 0; i
< MBOX_MAX_SCSI_CMDS
; i
++) {
1153 mbox_pci_blk
[i
].vaddr
= dma_pool_alloc(
1154 raid_dev
->mbox_pool_handle
,
1156 &mbox_pci_blk
[i
].dma_addr
);
1157 if (!mbox_pci_blk
[i
].vaddr
) {
1158 goto fail_setup_dma_pool
;
1163 * Allocate memory for each embedded passthru strucuture pointer
1164 * Request for a 128 bytes aligned structure for each passthru command
1166 * Since passthru and extended passthru commands are exclusive, they
1167 * share common memory pool. Passthru structures piggyback on memory
1168 * allocted to extended passthru since passthru is smaller of the two
1170 raid_dev
->epthru_pool_handle
= dma_pool_create("megaraid mbox pthru",
1171 &adapter
->pdev
->dev
, sizeof(mraid_epassthru_t
), 128, 0);
1173 if (raid_dev
->epthru_pool_handle
== NULL
) {
1174 goto fail_setup_dma_pool
;
1177 epthru_pci_blk
= raid_dev
->epthru_pool
;
1178 for (i
= 0; i
< MBOX_MAX_SCSI_CMDS
; i
++) {
1179 epthru_pci_blk
[i
].vaddr
= dma_pool_alloc(
1180 raid_dev
->epthru_pool_handle
,
1182 &epthru_pci_blk
[i
].dma_addr
);
1183 if (!epthru_pci_blk
[i
].vaddr
) {
1184 goto fail_setup_dma_pool
;
1189 // Allocate memory for each scatter-gather list. Request for 512 bytes
1190 // alignment for each sg list
1191 raid_dev
->sg_pool_handle
= dma_pool_create("megaraid mbox sg",
1192 &adapter
->pdev
->dev
,
1193 sizeof(mbox_sgl64
) * MBOX_MAX_SG_SIZE
,
1196 if (raid_dev
->sg_pool_handle
== NULL
) {
1197 goto fail_setup_dma_pool
;
1200 sg_pci_blk
= raid_dev
->sg_pool
;
1201 for (i
= 0; i
< MBOX_MAX_SCSI_CMDS
; i
++) {
1202 sg_pci_blk
[i
].vaddr
= dma_pool_alloc(
1203 raid_dev
->sg_pool_handle
,
1205 &sg_pci_blk
[i
].dma_addr
);
1206 if (!sg_pci_blk
[i
].vaddr
) {
1207 goto fail_setup_dma_pool
;
1213 fail_setup_dma_pool
:
1214 megaraid_mbox_teardown_dma_pools(adapter
);
1220 * megaraid_mbox_teardown_dma_pools - teardown dma pools for command packets
1221 * @adapter : HBA soft state
1223 * Teardown the dma pool for mailbox, passthru and extended passthru
1224 * structures, and scatter-gather lists.
1227 megaraid_mbox_teardown_dma_pools(adapter_t
*adapter
)
1229 mraid_device_t
*raid_dev
= ADAP2RAIDDEV(adapter
);
1230 struct mraid_pci_blk
*epthru_pci_blk
;
1231 struct mraid_pci_blk
*sg_pci_blk
;
1232 struct mraid_pci_blk
*mbox_pci_blk
;
1236 sg_pci_blk
= raid_dev
->sg_pool
;
1237 for (i
= 0; i
< MBOX_MAX_SCSI_CMDS
&& sg_pci_blk
[i
].vaddr
; i
++) {
1238 dma_pool_free(raid_dev
->sg_pool_handle
, sg_pci_blk
[i
].vaddr
,
1239 sg_pci_blk
[i
].dma_addr
);
1241 dma_pool_destroy(raid_dev
->sg_pool_handle
);
1244 epthru_pci_blk
= raid_dev
->epthru_pool
;
1245 for (i
= 0; i
< MBOX_MAX_SCSI_CMDS
&& epthru_pci_blk
[i
].vaddr
; i
++) {
1246 dma_pool_free(raid_dev
->epthru_pool_handle
,
1247 epthru_pci_blk
[i
].vaddr
, epthru_pci_blk
[i
].dma_addr
);
1249 dma_pool_destroy(raid_dev
->epthru_pool_handle
);
1252 mbox_pci_blk
= raid_dev
->mbox_pool
;
1253 for (i
= 0; i
< MBOX_MAX_SCSI_CMDS
&& mbox_pci_blk
[i
].vaddr
; i
++) {
1254 dma_pool_free(raid_dev
->mbox_pool_handle
,
1255 mbox_pci_blk
[i
].vaddr
, mbox_pci_blk
[i
].dma_addr
);
1257 dma_pool_destroy(raid_dev
->mbox_pool_handle
);
1264 * megaraid_alloc_scb - detach and return a scb from the free list
1265 * @adapter : controller's soft state
1266 * @scp : pointer to the scsi command to be executed
1268 * Return the scb from the head of the free list. %NULL if there are none
1272 megaraid_alloc_scb(adapter_t
*adapter
, struct scsi_cmnd
*scp
)
1274 struct list_head
*head
= &adapter
->kscb_pool
;
1276 unsigned long flags
;
1278 // detach scb from free pool
1279 spin_lock_irqsave(SCSI_FREE_LIST_LOCK(adapter
), flags
);
1281 if (list_empty(head
)) {
1282 spin_unlock_irqrestore(SCSI_FREE_LIST_LOCK(adapter
), flags
);
1286 scb
= list_entry(head
->next
, scb_t
, list
);
1287 list_del_init(&scb
->list
);
1289 spin_unlock_irqrestore(SCSI_FREE_LIST_LOCK(adapter
), flags
);
1291 scb
->state
= SCB_ACTIVE
;
1293 scb
->dma_type
= MRAID_DMA_NONE
;
1300 * megaraid_dealloc_scb - return the scb to the free pool
1301 * @adapter : controller's soft state
1302 * @scb : scb to be freed
1304 * Return the scb back to the free list of scbs. The caller must 'flush' the
1305 * SCB before calling us. E.g., performing pci_unamp and/or pci_sync etc.
1306 * NOTE NOTE: Make sure the scb is not on any list before calling this
1310 megaraid_dealloc_scb(adapter_t
*adapter
, scb_t
*scb
)
1312 unsigned long flags
;
1314 // put scb in the free pool
1315 scb
->state
= SCB_FREE
;
1317 spin_lock_irqsave(SCSI_FREE_LIST_LOCK(adapter
), flags
);
1319 list_add(&scb
->list
, &adapter
->kscb_pool
);
1321 spin_unlock_irqrestore(SCSI_FREE_LIST_LOCK(adapter
), flags
);
1328 * megaraid_mbox_mksgl - make the scatter-gather list
1329 * @adapter : controller's soft state
1330 * @scb : scsi control block
1332 * Prepare the scatter-gather list.
1335 megaraid_mbox_mksgl(adapter_t
*adapter
, scb_t
*scb
)
1337 struct scatterlist
*sgl
;
1339 struct scsi_cmnd
*scp
;
1345 ccb
= (mbox_ccb_t
*)scb
->ccb
;
1347 sgcnt
= scsi_dma_map(scp
);
1348 BUG_ON(sgcnt
< 0 || sgcnt
> adapter
->sglen
);
1350 // no mapping required if no data to be transferred
1354 scb
->dma_type
= MRAID_DMA_WSG
;
1356 scsi_for_each_sg(scp
, sgl
, sgcnt
, i
) {
1357 ccb
->sgl64
[i
].address
= sg_dma_address(sgl
);
1358 ccb
->sgl64
[i
].length
= sg_dma_len(sgl
);
1361 // Return count of SG nodes
1367 * mbox_post_cmd - issue a mailbox command
1368 * @adapter : controller's soft state
1369 * @scb : command to be issued
1371 * Post the command to the controller if mailbox is available.
1374 mbox_post_cmd(adapter_t
*adapter
, scb_t
*scb
)
1376 mraid_device_t
*raid_dev
= ADAP2RAIDDEV(adapter
);
1380 unsigned long flags
;
1384 ccb
= (mbox_ccb_t
*)scb
->ccb
;
1385 mbox
= raid_dev
->mbox
;
1386 mbox64
= raid_dev
->mbox64
;
1389 * Check for busy mailbox. If it is, return failure - the caller
1390 * should retry later.
1392 spin_lock_irqsave(MAILBOX_LOCK(raid_dev
), flags
);
1394 if (unlikely(mbox
->busy
)) {
1399 } while(mbox
->busy
&& (i
< max_mbox_busy_wait
));
1403 spin_unlock_irqrestore(MAILBOX_LOCK(raid_dev
), flags
);
1410 // Copy this command's mailbox data into "adapter's" mailbox
1411 memcpy((caddr_t
)mbox64
, (caddr_t
)ccb
->mbox64
, 22);
1412 mbox
->cmdid
= scb
->sno
;
1414 adapter
->outstanding_cmds
++;
1416 mbox
->busy
= 1; // Set busy
1421 WRINDOOR(raid_dev
, raid_dev
->mbox_dma
| 0x1);
1423 spin_unlock_irqrestore(MAILBOX_LOCK(raid_dev
), flags
);
1430 * megaraid_queue_command - generic queue entry point for all LLDs
1431 * @scp : pointer to the scsi command to be executed
1432 * @done : callback routine to be called after the cmd has be completed
1434 * Queue entry point for mailbox based controllers.
1437 megaraid_queue_command_lck(struct scsi_cmnd
*scp
, void (*done
)(struct scsi_cmnd
*))
1443 adapter
= SCP2ADAPTER(scp
);
1444 scp
->scsi_done
= done
;
1448 * Allocate and build a SCB request
1449 * if_busy flag will be set if megaraid_mbox_build_cmd() command could
1450 * not allocate scb. We will return non-zero status in that case.
1451 * NOTE: scb can be null even though certain commands completed
1452 * successfully, e.g., MODE_SENSE and TEST_UNIT_READY, it would
1453 * return 0 in that case, and we would do the callback right away.
1456 scb
= megaraid_mbox_build_cmd(adapter
, scp
, &if_busy
);
1457 if (!scb
) { // command already completed
1462 megaraid_mbox_runpendq(adapter
, scb
);
1466 static DEF_SCSI_QCMD(megaraid_queue_command
)
1469 * megaraid_mbox_build_cmd - transform the mid-layer scsi commands
1470 * @adapter : controller's soft state
1471 * @scp : mid-layer scsi command pointer
1472 * @busy : set if request could not be completed because of lack of
1475 * Transform the mid-layer scsi command to megaraid firmware lingua.
1476 * Convert the command issued by mid-layer to format understood by megaraid
1477 * firmware. We also complete certain commands without sending them to firmware.
1480 megaraid_mbox_build_cmd(adapter_t
*adapter
, struct scsi_cmnd
*scp
, int *busy
)
1482 mraid_device_t
*rdev
= ADAP2RAIDDEV(adapter
);
1487 mraid_passthru_t
*pthru
;
1491 char skip
[] = "skipping";
1492 char scan
[] = "scanning";
1497 * Get the appropriate device map for the device this command is
1500 MRAID_GET_DEVICE_MAP(adapter
, scp
, channel
, target
, islogical
);
1503 * Logical drive commands
1506 switch (scp
->cmnd
[0]) {
1507 case TEST_UNIT_READY
:
1509 * Do we support clustering and is the support enabled
1510 * If no, return success always
1513 scp
->result
= (DID_OK
<< 16);
1517 if (!(scb
= megaraid_alloc_scb(adapter
, scp
))) {
1518 scp
->result
= (DID_ERROR
<< 16);
1523 scb
->dma_direction
= scp
->sc_data_direction
;
1524 scb
->dev_channel
= 0xFF;
1525 scb
->dev_target
= target
;
1526 ccb
= (mbox_ccb_t
*)scb
->ccb
;
1529 * The command id will be provided by the command
1532 ccb
->raw_mbox
[0] = CLUSTER_CMD
;
1533 ccb
->raw_mbox
[2] = RESERVATION_STATUS
;
1534 ccb
->raw_mbox
[3] = target
;
1540 struct scatterlist
*sgl
;
1543 sgl
= scsi_sglist(scp
);
1545 vaddr
= (caddr_t
) sg_virt(&sgl
[0]);
1547 memset(vaddr
, 0, scp
->cmnd
[4]);
1550 con_log(CL_ANN
, (KERN_WARNING
1551 "megaraid mailbox: invalid sg:%d\n",
1555 scp
->result
= (DID_OK
<< 16);
1560 * Display the channel scan for logical drives
1561 * Do not display scan for a channel if already done.
1563 if (!(rdev
->last_disp
& (1L << SCP2CHANNEL(scp
)))) {
1565 con_log(CL_ANN
, (KERN_INFO
1566 "scsi[%d]: scanning scsi channel %d",
1567 adapter
->host
->host_no
,
1571 " [virtual] for logical drives\n"));
1573 rdev
->last_disp
|= (1L << SCP2CHANNEL(scp
));
1576 if (scp
->cmnd
[1] & MEGA_SCSI_INQ_EVPD
) {
1577 scp
->sense_buffer
[0] = 0x70;
1578 scp
->sense_buffer
[2] = ILLEGAL_REQUEST
;
1579 scp
->sense_buffer
[12] = MEGA_INVALID_FIELD_IN_CDB
;
1580 scp
->result
= CHECK_CONDITION
<< 1;
1588 * Do not allow LUN > 0 for logical drives and
1589 * requests for more than 40 logical drives
1592 scp
->result
= (DID_BAD_TARGET
<< 16);
1595 if ((target
% 0x80) >= MAX_LOGICAL_DRIVES_40LD
) {
1596 scp
->result
= (DID_BAD_TARGET
<< 16);
1601 /* Allocate a SCB and initialize passthru */
1602 if (!(scb
= megaraid_alloc_scb(adapter
, scp
))) {
1603 scp
->result
= (DID_ERROR
<< 16);
1608 ccb
= (mbox_ccb_t
*)scb
->ccb
;
1609 scb
->dev_channel
= 0xFF;
1610 scb
->dev_target
= target
;
1613 mbox64
= ccb
->mbox64
;
1617 pthru
->reqsenselen
= 14;
1618 pthru
->islogical
= 1;
1619 pthru
->logdrv
= target
;
1620 pthru
->cdblen
= scp
->cmd_len
;
1621 memcpy(pthru
->cdb
, scp
->cmnd
, scp
->cmd_len
);
1623 mbox
->cmd
= MBOXCMD_PASSTHRU64
;
1624 scb
->dma_direction
= scp
->sc_data_direction
;
1626 pthru
->dataxferlen
= scsi_bufflen(scp
);
1627 pthru
->dataxferaddr
= ccb
->sgl_dma_h
;
1628 pthru
->numsge
= megaraid_mbox_mksgl(adapter
,
1631 mbox
->xferaddr
= 0xFFFFFFFF;
1632 mbox64
->xferaddr_lo
= (uint32_t )ccb
->pthru_dma_h
;
1633 mbox64
->xferaddr_hi
= 0;
1645 * Allocate a SCB and initialize mailbox
1647 if (!(scb
= megaraid_alloc_scb(adapter
, scp
))) {
1648 scp
->result
= (DID_ERROR
<< 16);
1652 ccb
= (mbox_ccb_t
*)scb
->ccb
;
1653 scb
->dev_channel
= 0xFF;
1654 scb
->dev_target
= target
;
1656 mbox64
= ccb
->mbox64
;
1657 mbox
->logdrv
= target
;
1660 * A little HACK: 2nd bit is zero for all scsi read
1661 * commands and is set for all scsi write commands
1663 mbox
->cmd
= (scp
->cmnd
[0] & 0x02) ? MBOXCMD_LWRITE64
:
1667 * 6-byte READ(0x08) or WRITE(0x0A) cdb
1669 if (scp
->cmd_len
== 6) {
1670 mbox
->numsectors
= (uint32_t)scp
->cmnd
[4];
1672 ((uint32_t)scp
->cmnd
[1] << 16) |
1673 ((uint32_t)scp
->cmnd
[2] << 8) |
1674 (uint32_t)scp
->cmnd
[3];
1676 mbox
->lba
&= 0x1FFFFF;
1680 * 10-byte READ(0x28) or WRITE(0x2A) cdb
1682 else if (scp
->cmd_len
== 10) {
1684 (uint32_t)scp
->cmnd
[8] |
1685 ((uint32_t)scp
->cmnd
[7] << 8);
1687 ((uint32_t)scp
->cmnd
[2] << 24) |
1688 ((uint32_t)scp
->cmnd
[3] << 16) |
1689 ((uint32_t)scp
->cmnd
[4] << 8) |
1690 (uint32_t)scp
->cmnd
[5];
1694 * 12-byte READ(0xA8) or WRITE(0xAA) cdb
1696 else if (scp
->cmd_len
== 12) {
1698 ((uint32_t)scp
->cmnd
[2] << 24) |
1699 ((uint32_t)scp
->cmnd
[3] << 16) |
1700 ((uint32_t)scp
->cmnd
[4] << 8) |
1701 (uint32_t)scp
->cmnd
[5];
1704 ((uint32_t)scp
->cmnd
[6] << 24) |
1705 ((uint32_t)scp
->cmnd
[7] << 16) |
1706 ((uint32_t)scp
->cmnd
[8] << 8) |
1707 (uint32_t)scp
->cmnd
[9];
1710 con_log(CL_ANN
, (KERN_WARNING
1711 "megaraid: unsupported CDB length\n"));
1713 megaraid_dealloc_scb(adapter
, scb
);
1715 scp
->result
= (DID_ERROR
<< 16);
1719 scb
->dma_direction
= scp
->sc_data_direction
;
1721 // Calculate Scatter-Gather info
1722 mbox64
->xferaddr_lo
= (uint32_t )ccb
->sgl_dma_h
;
1723 mbox
->numsge
= megaraid_mbox_mksgl(adapter
,
1725 mbox
->xferaddr
= 0xFFFFFFFF;
1726 mbox64
->xferaddr_hi
= 0;
1733 * Do we support clustering and is the support enabled
1736 scp
->result
= (DID_BAD_TARGET
<< 16);
1741 * Allocate a SCB and initialize mailbox
1743 if (!(scb
= megaraid_alloc_scb(adapter
, scp
))) {
1744 scp
->result
= (DID_ERROR
<< 16);
1749 ccb
= (mbox_ccb_t
*)scb
->ccb
;
1750 scb
->dev_channel
= 0xFF;
1751 scb
->dev_target
= target
;
1752 ccb
->raw_mbox
[0] = CLUSTER_CMD
;
1753 ccb
->raw_mbox
[2] = (scp
->cmnd
[0] == RESERVE
) ?
1754 RESERVE_LD
: RELEASE_LD
;
1756 ccb
->raw_mbox
[3] = target
;
1757 scb
->dma_direction
= scp
->sc_data_direction
;
1762 scp
->result
= (DID_BAD_TARGET
<< 16);
1766 else { // Passthru device commands
1768 // Do not allow access to target id > 15 or LUN > 7
1769 if (target
> 15 || SCP2LUN(scp
) > 7) {
1770 scp
->result
= (DID_BAD_TARGET
<< 16);
1774 // if fast load option was set and scan for last device is
1775 // over, reset the fast_load flag so that during a possible
1776 // next scan, devices can be made available
1777 if (rdev
->fast_load
&& (target
== 15) &&
1778 (SCP2CHANNEL(scp
) == adapter
->max_channel
-1)) {
1780 con_log(CL_ANN
, (KERN_INFO
1781 "megaraid[%d]: physical device scan re-enabled\n",
1782 adapter
->host
->host_no
));
1783 rdev
->fast_load
= 0;
1787 * Display the channel scan for physical devices
1789 if (!(rdev
->last_disp
& (1L << SCP2CHANNEL(scp
)))) {
1791 ss
= rdev
->fast_load
? skip
: scan
;
1793 con_log(CL_ANN
, (KERN_INFO
1794 "scsi[%d]: %s scsi channel %d [Phy %d]",
1795 adapter
->host
->host_no
, ss
, SCP2CHANNEL(scp
),
1799 " for non-raid devices\n"));
1801 rdev
->last_disp
|= (1L << SCP2CHANNEL(scp
));
1804 // disable channel sweep if fast load option given
1805 if (rdev
->fast_load
) {
1806 scp
->result
= (DID_BAD_TARGET
<< 16);
1810 // Allocate a SCB and initialize passthru
1811 if (!(scb
= megaraid_alloc_scb(adapter
, scp
))) {
1812 scp
->result
= (DID_ERROR
<< 16);
1817 ccb
= (mbox_ccb_t
*)scb
->ccb
;
1818 scb
->dev_channel
= channel
;
1819 scb
->dev_target
= target
;
1820 scb
->dma_direction
= scp
->sc_data_direction
;
1822 mbox64
= ccb
->mbox64
;
1824 // Does this firmware support extended CDBs
1825 if (adapter
->max_cdb_sz
== 16) {
1826 mbox
->cmd
= MBOXCMD_EXTPTHRU
;
1828 megaraid_mbox_prepare_epthru(adapter
, scb
, scp
);
1830 mbox64
->xferaddr_lo
= (uint32_t)ccb
->epthru_dma_h
;
1831 mbox64
->xferaddr_hi
= 0;
1832 mbox
->xferaddr
= 0xFFFFFFFF;
1835 mbox
->cmd
= MBOXCMD_PASSTHRU64
;
1837 megaraid_mbox_prepare_pthru(adapter
, scb
, scp
);
1839 mbox64
->xferaddr_lo
= (uint32_t)ccb
->pthru_dma_h
;
1840 mbox64
->xferaddr_hi
= 0;
1841 mbox
->xferaddr
= 0xFFFFFFFF;
1851 * megaraid_mbox_runpendq - execute commands queued in the pending queue
1852 * @adapter : controller's soft state
1853 * @scb_q : SCB to be queued in the pending list
1855 * Scan the pending list for commands which are not yet issued and try to
1856 * post to the controller. The SCB can be a null pointer, which would indicate
1857 * no SCB to be queue, just try to execute the ones in the pending list.
1859 * NOTE: We do not actually traverse the pending list. The SCBs are plucked
1860 * out from the head of the pending list. If it is successfully issued, the
1861 * next SCB is at the head now.
1864 megaraid_mbox_runpendq(adapter_t
*adapter
, scb_t
*scb_q
)
1867 unsigned long flags
;
1869 spin_lock_irqsave(PENDING_LIST_LOCK(adapter
), flags
);
1872 scb_q
->state
= SCB_PENDQ
;
1873 list_add_tail(&scb_q
->list
, &adapter
->pend_list
);
1876 // if the adapter in not in quiescent mode, post the commands to FW
1877 if (adapter
->quiescent
) {
1878 spin_unlock_irqrestore(PENDING_LIST_LOCK(adapter
), flags
);
1882 while (!list_empty(&adapter
->pend_list
)) {
1884 assert_spin_locked(PENDING_LIST_LOCK(adapter
));
1886 scb
= list_entry(adapter
->pend_list
.next
, scb_t
, list
);
1888 // remove the scb from the pending list and try to
1889 // issue. If we are unable to issue it, put back in
1890 // the pending list and return
1892 list_del_init(&scb
->list
);
1894 spin_unlock_irqrestore(PENDING_LIST_LOCK(adapter
), flags
);
1896 // if mailbox was busy, return SCB back to pending
1897 // list. Make sure to add at the head, since that's
1898 // where it would have been removed from
1900 scb
->state
= SCB_ISSUED
;
1902 if (mbox_post_cmd(adapter
, scb
) != 0) {
1904 spin_lock_irqsave(PENDING_LIST_LOCK(adapter
), flags
);
1906 scb
->state
= SCB_PENDQ
;
1908 list_add(&scb
->list
, &adapter
->pend_list
);
1910 spin_unlock_irqrestore(PENDING_LIST_LOCK(adapter
),
1916 spin_lock_irqsave(PENDING_LIST_LOCK(adapter
), flags
);
1919 spin_unlock_irqrestore(PENDING_LIST_LOCK(adapter
), flags
);
1927 * megaraid_mbox_prepare_pthru - prepare a command for physical devices
1928 * @adapter : pointer to controller's soft state
1929 * @scb : scsi control block
1930 * @scp : scsi command from the mid-layer
1932 * Prepare a command for the scsi physical devices.
1935 megaraid_mbox_prepare_pthru(adapter_t
*adapter
, scb_t
*scb
,
1936 struct scsi_cmnd
*scp
)
1939 mraid_passthru_t
*pthru
;
1943 ccb
= (mbox_ccb_t
*)scb
->ccb
;
1945 channel
= scb
->dev_channel
;
1946 target
= scb
->dev_target
;
1948 // 0=6sec, 1=60sec, 2=10min, 3=3hrs, 4=NO timeout
1951 pthru
->islogical
= 0;
1953 pthru
->target
= (channel
<< 4) | target
;
1954 pthru
->logdrv
= SCP2LUN(scp
);
1955 pthru
->reqsenselen
= 14;
1956 pthru
->cdblen
= scp
->cmd_len
;
1958 memcpy(pthru
->cdb
, scp
->cmnd
, scp
->cmd_len
);
1960 if (scsi_bufflen(scp
)) {
1961 pthru
->dataxferlen
= scsi_bufflen(scp
);
1962 pthru
->dataxferaddr
= ccb
->sgl_dma_h
;
1963 pthru
->numsge
= megaraid_mbox_mksgl(adapter
, scb
);
1966 pthru
->dataxferaddr
= 0;
1967 pthru
->dataxferlen
= 0;
1975 * megaraid_mbox_prepare_epthru - prepare a command for physical devices
1976 * @adapter : pointer to controller's soft state
1977 * @scb : scsi control block
1978 * @scp : scsi command from the mid-layer
1980 * Prepare a command for the scsi physical devices. This routine prepares
1981 * commands for devices which can take extended CDBs (>10 bytes).
1984 megaraid_mbox_prepare_epthru(adapter_t
*adapter
, scb_t
*scb
,
1985 struct scsi_cmnd
*scp
)
1988 mraid_epassthru_t
*epthru
;
1992 ccb
= (mbox_ccb_t
*)scb
->ccb
;
1993 epthru
= ccb
->epthru
;
1994 channel
= scb
->dev_channel
;
1995 target
= scb
->dev_target
;
1997 // 0=6sec, 1=60sec, 2=10min, 3=3hrs, 4=NO timeout
1998 epthru
->timeout
= 4;
2000 epthru
->islogical
= 0;
2001 epthru
->channel
= 0;
2002 epthru
->target
= (channel
<< 4) | target
;
2003 epthru
->logdrv
= SCP2LUN(scp
);
2004 epthru
->reqsenselen
= 14;
2005 epthru
->cdblen
= scp
->cmd_len
;
2007 memcpy(epthru
->cdb
, scp
->cmnd
, scp
->cmd_len
);
2009 if (scsi_bufflen(scp
)) {
2010 epthru
->dataxferlen
= scsi_bufflen(scp
);
2011 epthru
->dataxferaddr
= ccb
->sgl_dma_h
;
2012 epthru
->numsge
= megaraid_mbox_mksgl(adapter
, scb
);
2015 epthru
->dataxferaddr
= 0;
2016 epthru
->dataxferlen
= 0;
2024 * megaraid_ack_sequence - interrupt ack sequence for memory mapped HBAs
2025 * @adapter : controller's soft state
2027 * Interrupt acknowledgement sequence for memory mapped HBAs. Find out the
2028 * completed command and put them on the completed list for later processing.
2030 * Returns: 1 if the interrupt is valid, 0 otherwise
2033 megaraid_ack_sequence(adapter_t
*adapter
)
2035 mraid_device_t
*raid_dev
= ADAP2RAIDDEV(adapter
);
2039 uint8_t completed
[MBOX_MAX_FIRMWARE_STATUS
];
2040 struct list_head clist
;
2043 unsigned long flags
;
2047 mbox
= raid_dev
->mbox
;
2049 // move the SCBs from the firmware completed array to our local list
2050 INIT_LIST_HEAD(&clist
);
2052 // loop till F/W has more commands for us to complete
2054 spin_lock_irqsave(MAILBOX_LOCK(raid_dev
), flags
);
2057 * Check if a valid interrupt is pending. If found, force the
2058 * interrupt line low.
2060 dword
= RDOUTDOOR(raid_dev
);
2061 if (dword
!= 0x10001234) break;
2065 WROUTDOOR(raid_dev
, 0x10001234);
2068 // wait for valid numstatus to post
2069 for (i
= 0; i
< 0xFFFFF; i
++) {
2070 if (mbox
->numstatus
!= 0xFF) {
2071 nstatus
= mbox
->numstatus
;
2076 mbox
->numstatus
= 0xFF;
2078 adapter
->outstanding_cmds
-= nstatus
;
2080 for (i
= 0; i
< nstatus
; i
++) {
2082 // wait for valid command index to post
2083 for (j
= 0; j
< 0xFFFFF; j
++) {
2084 if (mbox
->completed
[i
] != 0xFF) break;
2087 completed
[i
] = mbox
->completed
[i
];
2088 mbox
->completed
[i
] = 0xFF;
2090 if (completed
[i
] == 0xFF) {
2091 con_log(CL_ANN
, (KERN_CRIT
2092 "megaraid: command posting timed out\n"));
2098 // Get SCB associated with this command id
2099 if (completed
[i
] >= MBOX_MAX_SCSI_CMDS
) {
2101 scb
= adapter
->uscb_list
+ (completed
[i
] -
2102 MBOX_MAX_SCSI_CMDS
);
2106 scb
= adapter
->kscb_list
+ completed
[i
];
2109 scb
->status
= mbox
->status
;
2110 list_add_tail(&scb
->list
, &clist
);
2113 // Acknowledge interrupt
2114 WRINDOOR(raid_dev
, 0x02);
2118 spin_unlock_irqrestore(MAILBOX_LOCK(raid_dev
), flags
);
2121 // put the completed commands in the completed list. DPC would
2122 // complete these commands later
2123 spin_lock_irqsave(COMPLETED_LIST_LOCK(adapter
), flags
);
2125 list_splice(&clist
, &adapter
->completed_list
);
2127 spin_unlock_irqrestore(COMPLETED_LIST_LOCK(adapter
), flags
);
2130 // schedule the DPC if there is some work for it
2132 tasklet_schedule(&adapter
->dpc_h
);
2139 * megaraid_isr - isr for memory based mailbox based controllers
2141 * @devp : pointer to our soft state
2143 * Interrupt service routine for memory-mapped mailbox controllers.
2146 megaraid_isr(int irq
, void *devp
)
2148 adapter_t
*adapter
= devp
;
2151 handled
= megaraid_ack_sequence(adapter
);
2153 /* Loop through any pending requests */
2154 if (!adapter
->quiescent
) {
2155 megaraid_mbox_runpendq(adapter
, NULL
);
2158 return IRQ_RETVAL(handled
);
2163 * megaraid_mbox_dpc - the tasklet to complete the commands from completed list
2164 * @devp : pointer to HBA soft state
2166 * Pick up the commands from the completed list and send back to the owners.
2167 * This is a reentrant function and does not assume any locks are held while
2168 * it is being called.
2171 megaraid_mbox_dpc(unsigned long devp
)
2173 adapter_t
*adapter
= (adapter_t
*)devp
;
2174 mraid_device_t
*raid_dev
;
2175 struct list_head clist
;
2176 struct scatterlist
*sgl
;
2179 struct scsi_cmnd
*scp
;
2180 mraid_passthru_t
*pthru
;
2181 mraid_epassthru_t
*epthru
;
2187 unsigned long flags
;
2193 if (!adapter
) return;
2195 raid_dev
= ADAP2RAIDDEV(adapter
);
2197 // move the SCBs from the completed list to our local list
2198 INIT_LIST_HEAD(&clist
);
2200 spin_lock_irqsave(COMPLETED_LIST_LOCK(adapter
), flags
);
2202 list_splice_init(&adapter
->completed_list
, &clist
);
2204 spin_unlock_irqrestore(COMPLETED_LIST_LOCK(adapter
), flags
);
2207 list_for_each_entry_safe(scb
, tmp
, &clist
, list
) {
2209 status
= scb
->status
;
2211 ccb
= (mbox_ccb_t
*)scb
->ccb
;
2213 epthru
= ccb
->epthru
;
2216 // Make sure f/w has completed a valid command
2217 if (scb
->state
!= SCB_ISSUED
) {
2218 con_log(CL_ANN
, (KERN_CRIT
2219 "megaraid critical err: invalid command %d:%d:%p\n",
2220 scb
->sno
, scb
->state
, scp
));
2222 continue; // Must never happen!
2225 // check for the management command and complete it right away
2226 if (scb
->sno
>= MBOX_MAX_SCSI_CMDS
) {
2227 scb
->state
= SCB_FREE
;
2228 scb
->status
= status
;
2230 // remove from local clist
2231 list_del_init(&scb
->list
);
2233 kioc
= (uioc_t
*)scb
->gp
;
2236 megaraid_mbox_mm_done(adapter
, scb
);
2241 // Was an abort issued for this command earlier
2242 if (scb
->state
& SCB_ABORT
) {
2243 con_log(CL_ANN
, (KERN_NOTICE
2244 "megaraid: aborted cmd [%x] completed\n",
2249 * If the inquiry came of a disk drive which is not part of
2250 * any RAID array, expose it to the kernel. For this to be
2251 * enabled, user must set the "megaraid_expose_unconf_disks"
2252 * flag to 1 by specifying it on module parameter list.
2253 * This would enable data migration off drives from other
2256 islogical
= MRAID_IS_LOGICAL(adapter
, scp
);
2257 if (scp
->cmnd
[0] == INQUIRY
&& status
== 0 && islogical
== 0
2258 && IS_RAID_CH(raid_dev
, scb
->dev_channel
)) {
2260 sgl
= scsi_sglist(scp
);
2262 c
= *(unsigned char *) sg_virt(&sgl
[0]);
2264 con_log(CL_ANN
, (KERN_WARNING
2265 "megaraid mailbox: invalid sg:%d\n",
2270 if ((c
& 0x1F ) == TYPE_DISK
) {
2271 pdev_index
= (scb
->dev_channel
* 16) +
2274 raid_dev
->pdrv_state
[pdev_index
] & 0x0F;
2276 if (pdev_state
== PDRV_ONLINE
||
2277 pdev_state
== PDRV_FAILED
||
2278 pdev_state
== PDRV_RBLD
||
2279 pdev_state
== PDRV_HOTSPARE
||
2280 megaraid_expose_unconf_disks
== 0) {
2287 // Convert MegaRAID status to Linux error code
2292 scp
->result
= (DID_OK
<< 16);
2297 /* set sense_buffer and result fields */
2298 if (mbox
->cmd
== MBOXCMD_PASSTHRU
||
2299 mbox
->cmd
== MBOXCMD_PASSTHRU64
) {
2301 memcpy(scp
->sense_buffer
, pthru
->reqsensearea
,
2304 scp
->result
= DRIVER_SENSE
<< 24 |
2305 DID_OK
<< 16 | CHECK_CONDITION
<< 1;
2308 if (mbox
->cmd
== MBOXCMD_EXTPTHRU
) {
2310 memcpy(scp
->sense_buffer
,
2311 epthru
->reqsensearea
, 14);
2313 scp
->result
= DRIVER_SENSE
<< 24 |
2315 CHECK_CONDITION
<< 1;
2317 scp
->sense_buffer
[0] = 0x70;
2318 scp
->sense_buffer
[2] = ABORTED_COMMAND
;
2319 scp
->result
= CHECK_CONDITION
<< 1;
2326 scp
->result
= DID_BUS_BUSY
<< 16 | status
;
2332 * If TEST_UNIT_READY fails, we know RESERVATION_STATUS
2335 if (scp
->cmnd
[0] == TEST_UNIT_READY
) {
2336 scp
->result
= DID_ERROR
<< 16 |
2337 RESERVATION_CONFLICT
<< 1;
2341 * Error code returned is 1 if Reserve or Release
2342 * failed or the input parameter is invalid
2344 if (status
== 1 && (scp
->cmnd
[0] == RESERVE
||
2345 scp
->cmnd
[0] == RELEASE
)) {
2347 scp
->result
= DID_ERROR
<< 16 |
2348 RESERVATION_CONFLICT
<< 1;
2351 scp
->result
= DID_BAD_TARGET
<< 16 | status
;
2355 // print a debug message for all failed commands
2357 megaraid_mbox_display_scb(adapter
, scb
);
2360 scsi_dma_unmap(scp
);
2362 // remove from local clist
2363 list_del_init(&scb
->list
);
2365 // put back in free list
2366 megaraid_dealloc_scb(adapter
, scb
);
2368 // send the scsi packet back to kernel
2369 scp
->scsi_done(scp
);
2377 * megaraid_abort_handler - abort the scsi command
2378 * @scp : command to be aborted
2380 * Abort a previous SCSI request. Only commands on the pending list can be
2381 * aborted. All the commands issued to the F/W must complete.
2384 megaraid_abort_handler(struct scsi_cmnd
*scp
)
2387 mraid_device_t
*raid_dev
;
2391 unsigned long flags
;
2395 adapter
= SCP2ADAPTER(scp
);
2396 raid_dev
= ADAP2RAIDDEV(adapter
);
2398 con_log(CL_ANN
, (KERN_WARNING
2399 "megaraid: aborting cmd=%x <c=%d t=%d l=%d>\n",
2400 scp
->cmnd
[0], SCP2CHANNEL(scp
),
2401 SCP2TARGET(scp
), SCP2LUN(scp
)));
2403 // If FW has stopped responding, simply return failure
2404 if (raid_dev
->hw_error
) {
2405 con_log(CL_ANN
, (KERN_NOTICE
2406 "megaraid: hw error, not aborting\n"));
2410 // There might a race here, where the command was completed by the
2411 // firmware and now it is on the completed list. Before we could
2412 // complete the command to the kernel in dpc, the abort came.
2413 // Find out if this is the case to avoid the race.
2415 spin_lock_irqsave(COMPLETED_LIST_LOCK(adapter
), flags
);
2416 list_for_each_entry_safe(scb
, tmp
, &adapter
->completed_list
, list
) {
2418 if (scb
->scp
== scp
) { // Found command
2420 list_del_init(&scb
->list
); // from completed list
2422 con_log(CL_ANN
, (KERN_WARNING
2423 "megaraid: %d[%d:%d], abort from completed list\n",
2424 scb
->sno
, scb
->dev_channel
, scb
->dev_target
));
2426 scp
->result
= (DID_ABORT
<< 16);
2427 scp
->scsi_done(scp
);
2429 megaraid_dealloc_scb(adapter
, scb
);
2431 spin_unlock_irqrestore(COMPLETED_LIST_LOCK(adapter
),
2437 spin_unlock_irqrestore(COMPLETED_LIST_LOCK(adapter
), flags
);
2440 // Find out if this command is still on the pending list. If it is and
2441 // was never issued, abort and return success. If the command is owned
2442 // by the firmware, we must wait for it to complete by the FW.
2443 spin_lock_irqsave(PENDING_LIST_LOCK(adapter
), flags
);
2444 list_for_each_entry_safe(scb
, tmp
, &adapter
->pend_list
, list
) {
2446 if (scb
->scp
== scp
) { // Found command
2448 list_del_init(&scb
->list
); // from pending list
2450 ASSERT(!(scb
->state
& SCB_ISSUED
));
2452 con_log(CL_ANN
, (KERN_WARNING
2453 "megaraid abort: [%d:%d], driver owner\n",
2454 scb
->dev_channel
, scb
->dev_target
));
2456 scp
->result
= (DID_ABORT
<< 16);
2457 scp
->scsi_done(scp
);
2459 megaraid_dealloc_scb(adapter
, scb
);
2461 spin_unlock_irqrestore(PENDING_LIST_LOCK(adapter
),
2467 spin_unlock_irqrestore(PENDING_LIST_LOCK(adapter
), flags
);
2470 // Check do we even own this command, in which case this would be
2471 // owned by the firmware. The only way to locate the FW scb is to
2472 // traverse through the list of all SCB, since driver does not
2473 // maintain these SCBs on any list
2475 spin_lock_irq(&adapter
->lock
);
2476 for (i
= 0; i
< MBOX_MAX_SCSI_CMDS
; i
++) {
2477 scb
= adapter
->kscb_list
+ i
;
2479 if (scb
->scp
== scp
) {
2483 if (!(scb
->state
& SCB_ISSUED
)) {
2484 con_log(CL_ANN
, (KERN_WARNING
2485 "megaraid abort: %d[%d:%d], invalid state\n",
2486 scb
->sno
, scb
->dev_channel
, scb
->dev_target
));
2490 con_log(CL_ANN
, (KERN_WARNING
2491 "megaraid abort: %d[%d:%d], fw owner\n",
2492 scb
->sno
, scb
->dev_channel
, scb
->dev_target
));
2496 spin_unlock_irq(&adapter
->lock
);
2499 con_log(CL_ANN
, (KERN_WARNING
"megaraid abort: do now own\n"));
2501 // FIXME: Should there be a callback for this command?
2505 // We cannot actually abort a command owned by firmware, return
2506 // failure and wait for reset. In host reset handler, we will find out
2507 // if the HBA is still live
2512 * megaraid_reset_handler - device reset handler for mailbox based driver
2513 * @scp : reference command
2515 * Reset handler for the mailbox based controller. First try to find out if
2516 * the FW is still live, in which case the outstanding commands counter mut go
2517 * down to 0. If that happens, also issue the reservation reset command to
2518 * relinquish (possible) reservations on the logical drives connected to this
2522 megaraid_reset_handler(struct scsi_cmnd
*scp
)
2527 mraid_device_t
*raid_dev
;
2528 unsigned long flags
;
2529 uint8_t raw_mbox
[sizeof(mbox_t
)];
2531 int recovery_window
;
2535 adapter
= SCP2ADAPTER(scp
);
2536 raid_dev
= ADAP2RAIDDEV(adapter
);
2538 // return failure if adapter is not responding
2539 if (raid_dev
->hw_error
) {
2540 con_log(CL_ANN
, (KERN_NOTICE
2541 "megaraid: hw error, cannot reset\n"));
2545 // Under exceptional conditions, FW can take up to 3 minutes to
2546 // complete command processing. Wait for additional 2 minutes for the
2547 // pending commands counter to go down to 0. If it doesn't, let the
2548 // controller be marked offline
2549 // Also, reset all the commands currently owned by the driver
2550 spin_lock_irqsave(PENDING_LIST_LOCK(adapter
), flags
);
2551 list_for_each_entry_safe(scb
, tmp
, &adapter
->pend_list
, list
) {
2552 list_del_init(&scb
->list
); // from pending list
2554 if (scb
->sno
>= MBOX_MAX_SCSI_CMDS
) {
2555 con_log(CL_ANN
, (KERN_WARNING
2556 "megaraid: IOCTL packet with %d[%d:%d] being reset\n",
2557 scb
->sno
, scb
->dev_channel
, scb
->dev_target
));
2561 kioc
= (uioc_t
*)scb
->gp
;
2562 kioc
->status
= -EFAULT
;
2564 megaraid_mbox_mm_done(adapter
, scb
);
2566 if (scb
->scp
== scp
) { // Found command
2567 con_log(CL_ANN
, (KERN_WARNING
2568 "megaraid: %d[%d:%d], reset from pending list\n",
2569 scb
->sno
, scb
->dev_channel
, scb
->dev_target
));
2571 con_log(CL_ANN
, (KERN_WARNING
2572 "megaraid: IO packet with %d[%d:%d] being reset\n",
2573 scb
->sno
, scb
->dev_channel
, scb
->dev_target
));
2576 scb
->scp
->result
= (DID_RESET
<< 16);
2577 scb
->scp
->scsi_done(scb
->scp
);
2579 megaraid_dealloc_scb(adapter
, scb
);
2582 spin_unlock_irqrestore(PENDING_LIST_LOCK(adapter
), flags
);
2584 if (adapter
->outstanding_cmds
) {
2585 con_log(CL_ANN
, (KERN_NOTICE
2586 "megaraid: %d outstanding commands. Max wait %d sec\n",
2587 adapter
->outstanding_cmds
,
2588 (MBOX_RESET_WAIT
+ MBOX_RESET_EXT_WAIT
)));
2591 recovery_window
= MBOX_RESET_WAIT
+ MBOX_RESET_EXT_WAIT
;
2593 for (i
= 0; i
< recovery_window
; i
++) {
2595 megaraid_ack_sequence(adapter
);
2597 // print a message once every 5 seconds only
2600 "megaraid mbox: Wait for %d commands to complete:%d\n",
2601 adapter
->outstanding_cmds
,
2602 (MBOX_RESET_WAIT
+ MBOX_RESET_EXT_WAIT
) - i
));
2605 // bailout if no recovery happened in reset time
2606 if (adapter
->outstanding_cmds
== 0) {
2613 spin_lock(&adapter
->lock
);
2615 // If still outstanding commands, bail out
2616 if (adapter
->outstanding_cmds
) {
2617 con_log(CL_ANN
, (KERN_WARNING
2618 "megaraid mbox: critical hardware error!\n"));
2620 raid_dev
->hw_error
= 1;
2626 con_log(CL_ANN
, (KERN_NOTICE
2627 "megaraid mbox: reset sequence completed successfully\n"));
2631 // If the controller supports clustering, reset reservations
2637 // clear reservations if any
2638 raw_mbox
[0] = CLUSTER_CMD
;
2639 raw_mbox
[2] = RESET_RESERVATIONS
;
2642 if (mbox_post_sync_cmd_fast(adapter
, raw_mbox
) == 0) {
2644 (KERN_INFO
"megaraid: reservation reset\n"));
2648 con_log(CL_ANN
, (KERN_WARNING
2649 "megaraid: reservation reset failed\n"));
2653 spin_unlock(&adapter
->lock
);
2658 * START: internal commands library
2660 * This section of the driver has the common routine used by the driver and
2661 * also has all the FW routines
2665 * mbox_post_sync_cmd() - blocking command to the mailbox based controllers
2666 * @adapter : controller's soft state
2667 * @raw_mbox : the mailbox
2669 * Issue a scb in synchronous and non-interrupt mode for mailbox based
2673 mbox_post_sync_cmd(adapter_t
*adapter
, uint8_t raw_mbox
[])
2675 mraid_device_t
*raid_dev
= ADAP2RAIDDEV(adapter
);
2680 mbox
= raid_dev
->mbox
;
2683 * Wait until mailbox is free
2685 if (megaraid_busywait_mbox(raid_dev
) != 0)
2686 goto blocked_mailbox
;
2689 * Copy mailbox data into host structure
2691 memcpy((caddr_t
)mbox
, (caddr_t
)raw_mbox
, 16);
2696 mbox
->numstatus
= 0xFF;
2697 mbox
->status
= 0xFF;
2700 WRINDOOR(raid_dev
, raid_dev
->mbox_dma
| 0x1);
2702 // wait for maximum 1 second for status to post. If the status is not
2703 // available within 1 second, assume FW is initializing and wait
2704 // for an extended amount of time
2705 if (mbox
->numstatus
== 0xFF) { // status not yet available
2708 for (i
= 0; mbox
->numstatus
== 0xFF && i
< 1000; i
++) {
2715 con_log(CL_ANN
, (KERN_NOTICE
2716 "megaraid mailbox: wait for FW to boot "));
2718 for (i
= 0; (mbox
->numstatus
== 0xFF) &&
2719 (i
< MBOX_RESET_WAIT
); i
++) {
2721 con_log(CL_ANN
, ("\b\b\b\b\b[%03d]",
2722 MBOX_RESET_WAIT
- i
));
2726 if (i
== MBOX_RESET_WAIT
) {
2729 "\nmegaraid mailbox: status not available\n"));
2733 con_log(CL_ANN
, ("\b\b\b\b\b[ok] \n"));
2737 // wait for maximum 1 second for poll semaphore
2738 if (mbox
->poll
!= 0x77) {
2741 for (i
= 0; (mbox
->poll
!= 0x77) && (i
< 1000); i
++) {
2747 con_log(CL_ANN
, (KERN_WARNING
2748 "megaraid mailbox: could not get poll semaphore\n"));
2753 WRINDOOR(raid_dev
, raid_dev
->mbox_dma
| 0x2);
2756 // wait for maximum 1 second for acknowledgement
2757 if (RDINDOOR(raid_dev
) & 0x2) {
2760 for (i
= 0; (RDINDOOR(raid_dev
) & 0x2) && (i
< 1000); i
++) {
2766 con_log(CL_ANN
, (KERN_WARNING
2767 "megaraid mailbox: could not acknowledge\n"));
2774 status
= mbox
->status
;
2776 // invalidate the completed command id array. After command
2777 // completion, firmware would write the valid id.
2778 mbox
->numstatus
= 0xFF;
2779 mbox
->status
= 0xFF;
2780 for (i
= 0; i
< MBOX_MAX_FIRMWARE_STATUS
; i
++) {
2781 mbox
->completed
[i
] = 0xFF;
2788 con_log(CL_ANN
, (KERN_WARNING
"megaraid: blocked mailbox\n") );
2794 * mbox_post_sync_cmd_fast - blocking command to the mailbox based controllers
2795 * @adapter : controller's soft state
2796 * @raw_mbox : the mailbox
2798 * Issue a scb in synchronous and non-interrupt mode for mailbox based
2799 * controllers. This is a faster version of the synchronous command and
2800 * therefore can be called in interrupt-context as well.
2803 mbox_post_sync_cmd_fast(adapter_t
*adapter
, uint8_t raw_mbox
[])
2805 mraid_device_t
*raid_dev
= ADAP2RAIDDEV(adapter
);
2810 mbox
= raid_dev
->mbox
;
2812 // return immediately if the mailbox is busy
2813 if (mbox
->busy
) return -1;
2815 // Copy mailbox data into host structure
2816 memcpy((caddr_t
)mbox
, (caddr_t
)raw_mbox
, 14);
2821 mbox
->numstatus
= 0xFF;
2822 mbox
->status
= 0xFF;
2825 WRINDOOR(raid_dev
, raid_dev
->mbox_dma
| 0x1);
2827 for (i
= 0; i
< MBOX_SYNC_WAIT_CNT
; i
++) {
2828 if (mbox
->numstatus
!= 0xFF) break;
2830 udelay(MBOX_SYNC_DELAY_200
);
2833 if (i
== MBOX_SYNC_WAIT_CNT
) {
2834 // We may need to re-calibrate the counter
2835 con_log(CL_ANN
, (KERN_CRIT
2836 "megaraid: fast sync command timed out\n"));
2839 WRINDOOR(raid_dev
, raid_dev
->mbox_dma
| 0x2);
2842 return mbox
->status
;
2847 * megaraid_busywait_mbox() - Wait until the controller's mailbox is available
2848 * @raid_dev : RAID device (HBA) soft state
2850 * Wait until the controller's mailbox is available to accept more commands.
2851 * Wait for at most 1 second.
2854 megaraid_busywait_mbox(mraid_device_t
*raid_dev
)
2856 mbox_t
*mbox
= raid_dev
->mbox
;
2861 for (i
= 0; mbox
->busy
&& i
< 1000; i
++)
2865 if (i
< 1000) return 0;
2871 * megaraid_mbox_product_info - some static information about the controller
2872 * @adapter : our soft state
2874 * Issue commands to the controller to grab some parameters required by our
2878 megaraid_mbox_product_info(adapter_t
*adapter
)
2880 mraid_device_t
*raid_dev
= ADAP2RAIDDEV(adapter
);
2882 uint8_t raw_mbox
[sizeof(mbox_t
)];
2883 mraid_pinfo_t
*pinfo
;
2884 dma_addr_t pinfo_dma_h
;
2885 mraid_inquiry3_t
*mraid_inq3
;
2889 memset((caddr_t
)raw_mbox
, 0, sizeof(raw_mbox
));
2890 mbox
= (mbox_t
*)raw_mbox
;
2893 * Issue an ENQUIRY3 command to find out certain adapter parameters,
2894 * e.g., max channels, max commands etc.
2896 pinfo
= dma_alloc_coherent(&adapter
->pdev
->dev
, sizeof(mraid_pinfo_t
),
2897 &pinfo_dma_h
, GFP_KERNEL
);
2898 if (pinfo
== NULL
) {
2899 con_log(CL_ANN
, (KERN_WARNING
2900 "megaraid: out of memory, %s %d\n", __func__
,
2906 mbox
->xferaddr
= (uint32_t)adapter
->ibuf_dma_h
;
2907 memset((void *)adapter
->ibuf
, 0, MBOX_IBUF_SIZE
);
2909 raw_mbox
[0] = FC_NEW_CONFIG
;
2910 raw_mbox
[2] = NC_SUBOP_ENQUIRY3
;
2911 raw_mbox
[3] = ENQ3_GET_SOLICITED_FULL
;
2913 // Issue the command
2914 if (mbox_post_sync_cmd(adapter
, raw_mbox
) != 0) {
2916 con_log(CL_ANN
, (KERN_WARNING
"megaraid: Inquiry3 failed\n"));
2918 dma_free_coherent(&adapter
->pdev
->dev
, sizeof(mraid_pinfo_t
),
2919 pinfo
, pinfo_dma_h
);
2925 * Collect information about state of each physical drive
2926 * attached to the controller. We will expose all the disks
2927 * which are not part of RAID
2929 mraid_inq3
= (mraid_inquiry3_t
*)adapter
->ibuf
;
2930 for (i
= 0; i
< MBOX_MAX_PHYSICAL_DRIVES
; i
++) {
2931 raid_dev
->pdrv_state
[i
] = mraid_inq3
->pdrv_state
[i
];
2935 * Get product info for information like number of channels,
2936 * maximum commands supported.
2938 memset((caddr_t
)raw_mbox
, 0, sizeof(raw_mbox
));
2939 mbox
->xferaddr
= (uint32_t)pinfo_dma_h
;
2941 raw_mbox
[0] = FC_NEW_CONFIG
;
2942 raw_mbox
[2] = NC_SUBOP_PRODUCT_INFO
;
2944 if (mbox_post_sync_cmd(adapter
, raw_mbox
) != 0) {
2946 con_log(CL_ANN
, (KERN_WARNING
2947 "megaraid: product info failed\n"));
2949 dma_free_coherent(&adapter
->pdev
->dev
, sizeof(mraid_pinfo_t
),
2950 pinfo
, pinfo_dma_h
);
2956 * Setup some parameters for host, as required by our caller
2958 adapter
->max_channel
= pinfo
->nchannels
;
2961 * we will export all the logical drives on a single channel.
2962 * Add 1 since inquires do not come for inititor ID
2964 adapter
->max_target
= MAX_LOGICAL_DRIVES_40LD
+ 1;
2965 adapter
->max_lun
= 8; // up to 8 LUNs for non-disk devices
2968 * These are the maximum outstanding commands for the scsi-layer
2970 adapter
->max_cmds
= MBOX_MAX_SCSI_CMDS
;
2972 memset(adapter
->fw_version
, 0, VERSION_SIZE
);
2973 memset(adapter
->bios_version
, 0, VERSION_SIZE
);
2975 memcpy(adapter
->fw_version
, pinfo
->fw_version
, 4);
2976 adapter
->fw_version
[4] = 0;
2978 memcpy(adapter
->bios_version
, pinfo
->bios_version
, 4);
2979 adapter
->bios_version
[4] = 0;
2981 con_log(CL_ANN
, (KERN_NOTICE
2982 "megaraid: fw version:[%s] bios version:[%s]\n",
2983 adapter
->fw_version
, adapter
->bios_version
));
2985 dma_free_coherent(&adapter
->pdev
->dev
, sizeof(mraid_pinfo_t
), pinfo
,
2994 * megaraid_mbox_extended_cdb - check for support for extended CDBs
2995 * @adapter : soft state for the controller
2997 * This routine check whether the controller in question supports extended
2998 * ( > 10 bytes ) CDBs.
3001 megaraid_mbox_extended_cdb(adapter_t
*adapter
)
3004 uint8_t raw_mbox
[sizeof(mbox_t
)];
3007 mbox
= (mbox_t
*)raw_mbox
;
3009 memset((caddr_t
)raw_mbox
, 0, sizeof(raw_mbox
));
3010 mbox
->xferaddr
= (uint32_t)adapter
->ibuf_dma_h
;
3012 memset((void *)adapter
->ibuf
, 0, MBOX_IBUF_SIZE
);
3014 raw_mbox
[0] = MAIN_MISC_OPCODE
;
3015 raw_mbox
[2] = SUPPORT_EXT_CDB
;
3021 if (mbox_post_sync_cmd(adapter
, raw_mbox
) != 0) {
3030 * megaraid_mbox_support_ha - Do we support clustering
3031 * @adapter : soft state for the controller
3032 * @init_id : ID of the initiator
3034 * Determine if the firmware supports clustering and the ID of the initiator.
3037 megaraid_mbox_support_ha(adapter_t
*adapter
, uint16_t *init_id
)
3040 uint8_t raw_mbox
[sizeof(mbox_t
)];
3044 mbox
= (mbox_t
*)raw_mbox
;
3046 memset((caddr_t
)raw_mbox
, 0, sizeof(raw_mbox
));
3048 mbox
->xferaddr
= (uint32_t)adapter
->ibuf_dma_h
;
3050 memset((void *)adapter
->ibuf
, 0, MBOX_IBUF_SIZE
);
3052 raw_mbox
[0] = GET_TARGET_ID
;
3054 // Issue the command
3057 if (mbox_post_sync_cmd(adapter
, raw_mbox
) == 0) {
3059 *init_id
= *(uint8_t *)adapter
->ibuf
;
3061 con_log(CL_ANN
, (KERN_INFO
3062 "megaraid: cluster firmware, initiator ID: %d\n",
3073 * megaraid_mbox_support_random_del - Do we support random deletion
3074 * @adapter : soft state for the controller
3076 * Determine if the firmware supports random deletion.
3077 * Return: 1 is operation supported, 0 otherwise
3080 megaraid_mbox_support_random_del(adapter_t
*adapter
)
3082 uint8_t raw_mbox
[sizeof(mbox_t
)];
3086 * Newer firmware on Dell CERC expect a different
3087 * random deletion handling, so disable it.
3089 if (adapter
->pdev
->vendor
== PCI_VENDOR_ID_AMI
&&
3090 adapter
->pdev
->device
== PCI_DEVICE_ID_AMI_MEGARAID3
&&
3091 adapter
->pdev
->subsystem_vendor
== PCI_VENDOR_ID_DELL
&&
3092 adapter
->pdev
->subsystem_device
== PCI_SUBSYS_ID_CERC_ATA100_4CH
&&
3093 (adapter
->fw_version
[0] > '6' ||
3094 (adapter
->fw_version
[0] == '6' &&
3095 adapter
->fw_version
[2] > '6') ||
3096 (adapter
->fw_version
[0] == '6'
3097 && adapter
->fw_version
[2] == '6'
3098 && adapter
->fw_version
[3] > '1'))) {
3099 con_log(CL_DLEVEL1
, ("megaraid: disable random deletion\n"));
3103 memset((caddr_t
)raw_mbox
, 0, sizeof(mbox_t
));
3105 raw_mbox
[0] = FC_DEL_LOGDRV
;
3106 raw_mbox
[2] = OP_SUP_DEL_LOGDRV
;
3108 // Issue the command
3110 if (mbox_post_sync_cmd(adapter
, raw_mbox
) == 0) {
3112 con_log(CL_DLEVEL1
, ("megaraid: supports random deletion\n"));
3122 * megaraid_mbox_get_max_sg - maximum sg elements supported by the firmware
3123 * @adapter : soft state for the controller
3125 * Find out the maximum number of scatter-gather elements supported by the
3129 megaraid_mbox_get_max_sg(adapter_t
*adapter
)
3132 uint8_t raw_mbox
[sizeof(mbox_t
)];
3136 mbox
= (mbox_t
*)raw_mbox
;
3138 memset((caddr_t
)raw_mbox
, 0, sizeof(mbox_t
));
3140 mbox
->xferaddr
= (uint32_t)adapter
->ibuf_dma_h
;
3142 memset((void *)adapter
->ibuf
, 0, MBOX_IBUF_SIZE
);
3144 raw_mbox
[0] = MAIN_MISC_OPCODE
;
3145 raw_mbox
[2] = GET_MAX_SG_SUPPORT
;
3147 // Issue the command
3148 if (mbox_post_sync_cmd(adapter
, raw_mbox
) == 0) {
3149 nsg
= *(uint8_t *)adapter
->ibuf
;
3152 nsg
= MBOX_DEFAULT_SG_SIZE
;
3155 if (nsg
> MBOX_MAX_SG_SIZE
) nsg
= MBOX_MAX_SG_SIZE
;
3162 * megaraid_mbox_enum_raid_scsi - enumerate the RAID and SCSI channels
3163 * @adapter : soft state for the controller
3165 * Enumerate the RAID and SCSI channels for ROMB platforms so that channels
3166 * can be exported as regular SCSI channels.
3169 megaraid_mbox_enum_raid_scsi(adapter_t
*adapter
)
3171 mraid_device_t
*raid_dev
= ADAP2RAIDDEV(adapter
);
3173 uint8_t raw_mbox
[sizeof(mbox_t
)];
3176 mbox
= (mbox_t
*)raw_mbox
;
3178 memset((caddr_t
)raw_mbox
, 0, sizeof(mbox_t
));
3180 mbox
->xferaddr
= (uint32_t)adapter
->ibuf_dma_h
;
3182 memset((void *)adapter
->ibuf
, 0, MBOX_IBUF_SIZE
);
3184 raw_mbox
[0] = CHNL_CLASS
;
3185 raw_mbox
[2] = GET_CHNL_CLASS
;
3187 // Issue the command. If the command fails, all channels are RAID
3189 raid_dev
->channel_class
= 0xFF;
3190 if (mbox_post_sync_cmd(adapter
, raw_mbox
) == 0) {
3191 raid_dev
->channel_class
= *(uint8_t *)adapter
->ibuf
;
3199 * megaraid_mbox_flush_cache - flush adapter and disks cache
3200 * @adapter : soft state for the controller
3202 * Flush adapter cache followed by disks cache.
3205 megaraid_mbox_flush_cache(adapter_t
*adapter
)
3207 uint8_t raw_mbox
[sizeof(mbox_t
)];
3209 memset((caddr_t
)raw_mbox
, 0, sizeof(mbox_t
));
3211 raw_mbox
[0] = FLUSH_ADAPTER
;
3213 if (mbox_post_sync_cmd(adapter
, raw_mbox
) != 0) {
3214 con_log(CL_ANN
, ("megaraid: flush adapter failed\n"));
3217 raw_mbox
[0] = FLUSH_SYSTEM
;
3219 if (mbox_post_sync_cmd(adapter
, raw_mbox
) != 0) {
3220 con_log(CL_ANN
, ("megaraid: flush disks cache failed\n"));
3228 * megaraid_mbox_fire_sync_cmd - fire the sync cmd
3229 * @adapter : soft state for the controller
3231 * Clears the pending cmds in FW and reinits its RAID structs.
3234 megaraid_mbox_fire_sync_cmd(adapter_t
*adapter
)
3237 uint8_t raw_mbox
[sizeof(mbox_t
)];
3238 mraid_device_t
*raid_dev
= ADAP2RAIDDEV(adapter
);
3243 mbox
= (mbox_t
*)raw_mbox
;
3245 memset((caddr_t
)raw_mbox
, 0, sizeof(mbox_t
));
3249 mbox
= raid_dev
->mbox
;
3251 /* Wait until mailbox is free */
3252 if (megaraid_busywait_mbox(raid_dev
) != 0) {
3254 goto blocked_mailbox
;
3257 /* Copy mailbox data into host structure */
3258 memcpy((caddr_t
)mbox
, (caddr_t
)raw_mbox
, 16);
3263 mbox
->numstatus
= 0;
3267 WRINDOOR(raid_dev
, raid_dev
->mbox_dma
| 0x1);
3269 /* Wait for maximum 1 min for status to post.
3270 * If the Firmware SUPPORTS the ABOVE COMMAND,
3271 * mbox->cmd will be set to 0
3273 * the firmware will reject the command with
3274 * mbox->numstatus set to 1
3279 while (!mbox
->numstatus
&& mbox
->cmd
== 0xFF) {
3283 if (i
> 1000 * 60) {
3288 if (mbox
->numstatus
== 1)
3289 status
= 1; /*cmd not supported*/
3291 /* Check for interrupt line */
3292 dword
= RDOUTDOOR(raid_dev
);
3293 WROUTDOOR(raid_dev
, dword
);
3294 WRINDOOR(raid_dev
,2);
3299 con_log(CL_ANN
, (KERN_WARNING
"megaraid: blocked mailbox\n"));
3304 * megaraid_mbox_display_scb - display SCB information, mostly debug purposes
3305 * @adapter : controller's soft state
3306 * @scb : SCB to be displayed
3308 * Diplay information about the given SCB iff the current debug level is
3312 megaraid_mbox_display_scb(adapter_t
*adapter
, scb_t
*scb
)
3315 struct scsi_cmnd
*scp
;
3321 ccb
= (mbox_ccb_t
*)scb
->ccb
;
3327 con_log(level
, (KERN_NOTICE
3328 "megaraid mailbox: status:%#x cmd:%#x id:%#x ", scb
->status
,
3329 mbox
->cmd
, scb
->sno
));
3331 con_log(level
, ("sec:%#x lba:%#x addr:%#x ld:%d sg:%d\n",
3332 mbox
->numsectors
, mbox
->lba
, mbox
->xferaddr
, mbox
->logdrv
,
3337 con_log(level
, (KERN_NOTICE
"scsi cmnd: "));
3339 for (i
= 0; i
< scp
->cmd_len
; i
++) {
3340 con_log(level
, ("%#2.02x ", scp
->cmnd
[i
]));
3343 con_log(level
, ("\n"));
3350 * megaraid_mbox_setup_device_map - manage device ids
3351 * @adapter : Driver's soft state
3353 * Manage the device ids to have an appropriate mapping between the kernel
3354 * scsi addresses and megaraid scsi and logical drive addresses. We export
3355 * scsi devices on their actual addresses, whereas the logical drives are
3356 * exported on a virtual scsi channel.
3359 megaraid_mbox_setup_device_map(adapter_t
*adapter
)
3365 * First fill the values on the logical drive channel
3367 for (t
= 0; t
< LSI_MAX_LOGICAL_DRIVES_64LD
; t
++)
3368 adapter
->device_ids
[adapter
->max_channel
][t
] =
3369 (t
< adapter
->init_id
) ? t
: t
- 1;
3371 adapter
->device_ids
[adapter
->max_channel
][adapter
->init_id
] = 0xFF;
3374 * Fill the values on the physical devices channels
3376 for (c
= 0; c
< adapter
->max_channel
; c
++)
3377 for (t
= 0; t
< LSI_MAX_LOGICAL_DRIVES_64LD
; t
++)
3378 adapter
->device_ids
[c
][t
] = (c
<< 8) | t
;
3383 * END: internal commands library
3387 * START: Interface for the common management module
3389 * This is the module, which interfaces with the common management module to
3390 * provide support for ioctl and sysfs
3394 * megaraid_cmm_register - register with the management module
3395 * @adapter : HBA soft state
3397 * Register with the management module, which allows applications to issue
3398 * ioctl calls to the drivers. This interface is used by the management module
3399 * to setup sysfs support as well.
3402 megaraid_cmm_register(adapter_t
*adapter
)
3404 mraid_device_t
*raid_dev
= ADAP2RAIDDEV(adapter
);
3411 // Allocate memory for the base list of scb for management module.
3412 adapter
->uscb_list
= kcalloc(MBOX_MAX_USER_CMDS
, sizeof(scb_t
), GFP_KERNEL
);
3414 if (adapter
->uscb_list
== NULL
) {
3415 con_log(CL_ANN
, (KERN_WARNING
3416 "megaraid: out of memory, %s %d\n", __func__
,
3422 // Initialize the synchronization parameters for resources for
3423 // commands for management module
3424 INIT_LIST_HEAD(&adapter
->uscb_pool
);
3426 spin_lock_init(USER_FREE_LIST_LOCK(adapter
));
3430 // link all the packets. Note, CCB for commands, coming from the
3431 // commom management module, mailbox physical address are already
3432 // setup by it. We just need placeholder for that in our local command
3434 for (i
= 0; i
< MBOX_MAX_USER_CMDS
; i
++) {
3436 scb
= adapter
->uscb_list
+ i
;
3437 ccb
= raid_dev
->uccb_list
+ i
;
3439 scb
->ccb
= (caddr_t
)ccb
;
3440 ccb
->mbox64
= raid_dev
->umbox64
+ i
;
3441 ccb
->mbox
= &ccb
->mbox64
->mbox32
;
3442 ccb
->raw_mbox
= (uint8_t *)ccb
->mbox
;
3446 // COMMAND ID 0 - (MBOX_MAX_SCSI_CMDS-1) ARE RESERVED FOR
3447 // COMMANDS COMING FROM IO SUBSYSTEM (MID-LAYER)
3448 scb
->sno
= i
+ MBOX_MAX_SCSI_CMDS
;
3451 scb
->state
= SCB_FREE
;
3452 scb
->dma_direction
= DMA_NONE
;
3453 scb
->dma_type
= MRAID_DMA_NONE
;
3454 scb
->dev_channel
= -1;
3455 scb
->dev_target
= -1;
3457 // put scb in the free pool
3458 list_add_tail(&scb
->list
, &adapter
->uscb_pool
);
3461 adp
.unique_id
= adapter
->unique_id
;
3462 adp
.drvr_type
= DRVRTYPE_MBOX
;
3463 adp
.drvr_data
= (unsigned long)adapter
;
3464 adp
.pdev
= adapter
->pdev
;
3465 adp
.issue_uioc
= megaraid_mbox_mm_handler
;
3466 adp
.timeout
= MBOX_RESET_WAIT
+ MBOX_RESET_EXT_WAIT
;
3467 adp
.max_kioc
= MBOX_MAX_USER_CMDS
;
3469 if ((rval
= mraid_mm_register_adp(&adp
)) != 0) {
3471 con_log(CL_ANN
, (KERN_WARNING
3472 "megaraid mbox: did not register with CMM\n"));
3474 kfree(adapter
->uscb_list
);
3482 * megaraid_cmm_unregister - un-register with the management module
3483 * @adapter : HBA soft state
3485 * Un-register with the management module.
3486 * FIXME: mgmt module must return failure for unregister if it has pending
3490 megaraid_cmm_unregister(adapter_t
*adapter
)
3492 kfree(adapter
->uscb_list
);
3493 mraid_mm_unregister_adp(adapter
->unique_id
);
3499 * megaraid_mbox_mm_handler - interface for CMM to issue commands to LLD
3500 * @drvr_data : LLD specific data
3501 * @kioc : CMM interface packet
3502 * @action : command action
3504 * This routine is invoked whenever the Common Management Module (CMM) has a
3505 * command for us. The 'action' parameter specifies if this is a new command
3509 megaraid_mbox_mm_handler(unsigned long drvr_data
, uioc_t
*kioc
, uint32_t action
)
3513 if (action
!= IOCTL_ISSUE
) {
3514 con_log(CL_ANN
, (KERN_WARNING
3515 "megaraid: unsupported management action:%#2x\n",
3520 adapter
= (adapter_t
*)drvr_data
;
3522 // make sure this adapter is not being detached right now.
3523 if (atomic_read(&adapter
->being_detached
)) {
3524 con_log(CL_ANN
, (KERN_WARNING
3525 "megaraid: reject management request, detaching\n"));
3529 switch (kioc
->opcode
) {
3533 kioc
->status
= gather_hbainfo(adapter
, (mraid_hba_info_t
*)
3534 (unsigned long)kioc
->buf_vaddr
);
3538 return kioc
->status
;
3542 return megaraid_mbox_mm_command(adapter
, kioc
);
3545 kioc
->status
= (-EINVAL
);
3550 return 0; // not reached
3554 * megaraid_mbox_mm_command - issues commands routed through CMM
3555 * @adapter : HBA soft state
3556 * @kioc : management command packet
3558 * Issues commands, which are routed through the management module.
3561 megaraid_mbox_mm_command(adapter_t
*adapter
, uioc_t
*kioc
)
3563 struct list_head
*head
= &adapter
->uscb_pool
;
3568 unsigned long flags
;
3570 // detach one scb from free pool
3571 spin_lock_irqsave(USER_FREE_LIST_LOCK(adapter
), flags
);
3573 if (list_empty(head
)) { // should never happen because of CMM
3575 con_log(CL_ANN
, (KERN_WARNING
3576 "megaraid mbox: bug in cmm handler, lost resources\n"));
3578 spin_unlock_irqrestore(USER_FREE_LIST_LOCK(adapter
), flags
);
3583 scb
= list_entry(head
->next
, scb_t
, list
);
3584 list_del_init(&scb
->list
);
3586 spin_unlock_irqrestore(USER_FREE_LIST_LOCK(adapter
), flags
);
3588 scb
->state
= SCB_ACTIVE
;
3589 scb
->dma_type
= MRAID_DMA_NONE
;
3590 scb
->dma_direction
= DMA_NONE
;
3592 ccb
= (mbox_ccb_t
*)scb
->ccb
;
3593 mbox64
= (mbox64_t
*)(unsigned long)kioc
->cmdbuf
;
3594 raw_mbox
= (uint8_t *)&mbox64
->mbox32
;
3596 memcpy(ccb
->mbox64
, mbox64
, sizeof(mbox64_t
));
3598 scb
->gp
= (unsigned long)kioc
;
3601 * If it is a logdrv random delete operation, we have to wait till
3602 * there are no outstanding cmds at the fw and then issue it directly
3604 if (raw_mbox
[0] == FC_DEL_LOGDRV
&& raw_mbox
[2] == OP_DEL_LOGDRV
) {
3606 if (wait_till_fw_empty(adapter
)) {
3607 con_log(CL_ANN
, (KERN_NOTICE
3608 "megaraid mbox: LD delete, timed out\n"));
3610 kioc
->status
= -ETIME
;
3614 megaraid_mbox_mm_done(adapter
, scb
);
3619 INIT_LIST_HEAD(&scb
->list
);
3621 scb
->state
= SCB_ISSUED
;
3622 if (mbox_post_cmd(adapter
, scb
) != 0) {
3624 con_log(CL_ANN
, (KERN_NOTICE
3625 "megaraid mbox: LD delete, mailbox busy\n"));
3627 kioc
->status
= -EBUSY
;
3631 megaraid_mbox_mm_done(adapter
, scb
);
3639 // put the command on the pending list and execute
3640 megaraid_mbox_runpendq(adapter
, scb
);
3647 wait_till_fw_empty(adapter_t
*adapter
)
3649 unsigned long flags
= 0;
3654 * Set the quiescent flag to stop issuing cmds to FW.
3656 spin_lock_irqsave(&adapter
->lock
, flags
);
3657 adapter
->quiescent
++;
3658 spin_unlock_irqrestore(&adapter
->lock
, flags
);
3661 * Wait till there are no more cmds outstanding at FW. Try for at most
3664 for (i
= 0; i
< 60 && adapter
->outstanding_cmds
; i
++) {
3665 con_log(CL_DLEVEL1
, (KERN_INFO
3666 "megaraid: FW has %d pending commands\n",
3667 adapter
->outstanding_cmds
));
3672 return adapter
->outstanding_cmds
;
3677 * megaraid_mbox_mm_done - callback for CMM commands
3678 * @adapter : HBA soft state
3679 * @scb : completed command
3681 * Callback routine for internal commands originated from the management
3685 megaraid_mbox_mm_done(adapter_t
*adapter
, scb_t
*scb
)
3690 unsigned long flags
;
3692 kioc
= (uioc_t
*)scb
->gp
;
3693 mbox64
= (mbox64_t
*)(unsigned long)kioc
->cmdbuf
;
3694 mbox64
->mbox32
.status
= scb
->status
;
3695 raw_mbox
= (uint8_t *)&mbox64
->mbox32
;
3698 // put scb in the free pool
3699 scb
->state
= SCB_FREE
;
3702 spin_lock_irqsave(USER_FREE_LIST_LOCK(adapter
), flags
);
3704 list_add(&scb
->list
, &adapter
->uscb_pool
);
3706 spin_unlock_irqrestore(USER_FREE_LIST_LOCK(adapter
), flags
);
3708 // if a delete logical drive operation succeeded, restart the
3710 if (raw_mbox
[0] == FC_DEL_LOGDRV
&& raw_mbox
[2] == OP_DEL_LOGDRV
) {
3712 adapter
->quiescent
--;
3714 megaraid_mbox_runpendq(adapter
, NULL
);
3724 * gather_hbainfo - HBA characteristics for the applications
3725 * @adapter : HBA soft state
3726 * @hinfo : pointer to the caller's host info strucuture
3729 gather_hbainfo(adapter_t
*adapter
, mraid_hba_info_t
*hinfo
)
3731 hinfo
->pci_vendor_id
= adapter
->pdev
->vendor
;
3732 hinfo
->pci_device_id
= adapter
->pdev
->device
;
3733 hinfo
->subsys_vendor_id
= adapter
->pdev
->subsystem_vendor
;
3734 hinfo
->subsys_device_id
= adapter
->pdev
->subsystem_device
;
3736 hinfo
->pci_bus
= adapter
->pdev
->bus
->number
;
3737 hinfo
->pci_dev_fn
= adapter
->pdev
->devfn
;
3738 hinfo
->pci_slot
= PCI_SLOT(adapter
->pdev
->devfn
);
3739 hinfo
->irq
= adapter
->host
->irq
;
3740 hinfo
->baseport
= ADAP2RAIDDEV(adapter
)->baseport
;
3742 hinfo
->unique_id
= (hinfo
->pci_bus
<< 8) | adapter
->pdev
->devfn
;
3743 hinfo
->host_no
= adapter
->host
->host_no
;
3749 * END: Interface for the common management module
3755 * megaraid_sysfs_alloc_resources - allocate sysfs related resources
3756 * @adapter : controller's soft state
3758 * Allocate packets required to issue FW calls whenever the sysfs attributes
3759 * are read. These attributes would require up-to-date information from the
3760 * FW. Also set up resources for mutual exclusion to share these resources and
3763 * Return 0 on success.
3764 * Return -ERROR_CODE on failure.
3767 megaraid_sysfs_alloc_resources(adapter_t
*adapter
)
3769 mraid_device_t
*raid_dev
= ADAP2RAIDDEV(adapter
);
3772 raid_dev
->sysfs_uioc
= kmalloc(sizeof(uioc_t
), GFP_KERNEL
);
3774 raid_dev
->sysfs_mbox64
= kmalloc(sizeof(mbox64_t
), GFP_KERNEL
);
3776 raid_dev
->sysfs_buffer
= dma_alloc_coherent(&adapter
->pdev
->dev
,
3777 PAGE_SIZE
, &raid_dev
->sysfs_buffer_dma
, GFP_KERNEL
);
3779 if (!raid_dev
->sysfs_uioc
|| !raid_dev
->sysfs_mbox64
||
3780 !raid_dev
->sysfs_buffer
) {
3782 con_log(CL_ANN
, (KERN_WARNING
3783 "megaraid: out of memory, %s %d\n", __func__
,
3788 megaraid_sysfs_free_resources(adapter
);
3791 mutex_init(&raid_dev
->sysfs_mtx
);
3793 init_waitqueue_head(&raid_dev
->sysfs_wait_q
);
3800 * megaraid_sysfs_free_resources - free sysfs related resources
3801 * @adapter : controller's soft state
3803 * Free packets allocated for sysfs FW commands
3806 megaraid_sysfs_free_resources(adapter_t
*adapter
)
3808 mraid_device_t
*raid_dev
= ADAP2RAIDDEV(adapter
);
3810 kfree(raid_dev
->sysfs_uioc
);
3811 kfree(raid_dev
->sysfs_mbox64
);
3813 if (raid_dev
->sysfs_buffer
) {
3814 dma_free_coherent(&adapter
->pdev
->dev
, PAGE_SIZE
,
3815 raid_dev
->sysfs_buffer
, raid_dev
->sysfs_buffer_dma
);
3821 * megaraid_sysfs_get_ldmap_done - callback for get ldmap
3822 * @uioc : completed packet
3824 * Callback routine called in the ISR/tasklet context for get ldmap call
3827 megaraid_sysfs_get_ldmap_done(uioc_t
*uioc
)
3829 adapter_t
*adapter
= (adapter_t
*)uioc
->buf_vaddr
;
3830 mraid_device_t
*raid_dev
= ADAP2RAIDDEV(adapter
);
3834 wake_up(&raid_dev
->sysfs_wait_q
);
3838 * megaraid_sysfs_get_ldmap_timeout - timeout handling for get ldmap
3839 * @t : timed out timer
3841 * Timeout routine to recover and return to application, in case the adapter
3842 * has stopped responding. A timeout of 60 seconds for this command seems like
3846 megaraid_sysfs_get_ldmap_timeout(struct timer_list
*t
)
3848 struct uioc_timeout
*timeout
= from_timer(timeout
, t
, timer
);
3849 uioc_t
*uioc
= timeout
->uioc
;
3850 adapter_t
*adapter
= (adapter_t
*)uioc
->buf_vaddr
;
3851 mraid_device_t
*raid_dev
= ADAP2RAIDDEV(adapter
);
3853 uioc
->status
= -ETIME
;
3855 wake_up(&raid_dev
->sysfs_wait_q
);
3860 * megaraid_sysfs_get_ldmap - get update logical drive map
3861 * @adapter : controller's soft state
3863 * This routine will be called whenever user reads the logical drive
3864 * attributes, go get the current logical drive mapping table from the
3865 * firmware. We use the management API's to issue commands to the controller.
3867 * NOTE: The commands issuance functionality is not generalized and
3868 * implemented in context of "get ld map" command only. If required, the
3869 * command issuance logical can be trivially pulled out and implemented as a
3870 * standalone library. For now, this should suffice since there is no other
3871 * user of this interface.
3873 * Return 0 on success.
3874 * Return -1 on failure.
3877 megaraid_sysfs_get_ldmap(adapter_t
*adapter
)
3879 mraid_device_t
*raid_dev
= ADAP2RAIDDEV(adapter
);
3884 struct uioc_timeout timeout
;
3889 * Allow only one read at a time to go through the sysfs attributes
3891 mutex_lock(&raid_dev
->sysfs_mtx
);
3893 uioc
= raid_dev
->sysfs_uioc
;
3894 mbox64
= raid_dev
->sysfs_mbox64
;
3895 ldmap
= raid_dev
->sysfs_buffer
;
3897 memset(uioc
, 0, sizeof(uioc_t
));
3898 memset(mbox64
, 0, sizeof(mbox64_t
));
3899 memset(ldmap
, 0, sizeof(raid_dev
->curr_ldmap
));
3901 mbox
= &mbox64
->mbox32
;
3902 raw_mbox
= (char *)mbox
;
3903 uioc
->cmdbuf
= (uint64_t)(unsigned long)mbox64
;
3904 uioc
->buf_vaddr
= (caddr_t
)adapter
;
3905 uioc
->status
= -ENODATA
;
3906 uioc
->done
= megaraid_sysfs_get_ldmap_done
;
3909 * Prepare the mailbox packet to get the current logical drive mapping
3912 mbox
->xferaddr
= (uint32_t)raid_dev
->sysfs_buffer_dma
;
3914 raw_mbox
[0] = FC_DEL_LOGDRV
;
3915 raw_mbox
[2] = OP_GET_LDID_MAP
;
3918 * Setup a timer to recover from a non-responding controller
3920 timeout
.uioc
= uioc
;
3921 timer_setup_on_stack(&timeout
.timer
,
3922 megaraid_sysfs_get_ldmap_timeout
, 0);
3924 timeout
.timer
.expires
= jiffies
+ 60 * HZ
;
3925 add_timer(&timeout
.timer
);
3928 * Send the command to the firmware
3930 rval
= megaraid_mbox_mm_command(adapter
, uioc
);
3932 if (rval
== 0) { // command successfully issued
3933 wait_event(raid_dev
->sysfs_wait_q
, (uioc
->status
!= -ENODATA
));
3936 * Check if the command timed out
3938 if (uioc
->status
== -ETIME
) {
3939 con_log(CL_ANN
, (KERN_NOTICE
3940 "megaraid: sysfs get ld map timed out\n"));
3945 rval
= mbox
->status
;
3949 memcpy(raid_dev
->curr_ldmap
, ldmap
,
3950 sizeof(raid_dev
->curr_ldmap
));
3953 con_log(CL_ANN
, (KERN_NOTICE
3954 "megaraid: get ld map failed with %x\n", rval
));
3958 con_log(CL_ANN
, (KERN_NOTICE
3959 "megaraid: could not issue ldmap command:%x\n", rval
));
3963 del_timer_sync(&timeout
.timer
);
3964 destroy_timer_on_stack(&timeout
.timer
);
3966 mutex_unlock(&raid_dev
->sysfs_mtx
);
3973 * megaraid_sysfs_show_app_hndl - display application handle for this adapter
3974 * @dev : class device object representation for the host
3975 * @attr : device attribute (unused)
3976 * @buf : buffer to send data to
3978 * Display the handle used by the applications while executing management
3979 * tasks on the adapter. We invoke a management module API to get the adapter
3980 * handle, since we do not interface with applications directly.
3983 megaraid_sysfs_show_app_hndl(struct device
*dev
, struct device_attribute
*attr
,
3986 struct Scsi_Host
*shost
= class_to_shost(dev
);
3987 adapter_t
*adapter
= (adapter_t
*)SCSIHOST2ADAP(shost
);
3990 app_hndl
= mraid_mm_adapter_app_handle(adapter
->unique_id
);
3992 return snprintf(buf
, 8, "%u\n", app_hndl
);
3997 * megaraid_sysfs_show_ldnum - display the logical drive number for this device
3998 * @dev : device object representation for the scsi device
3999 * @attr : device attribute to show
4000 * @buf : buffer to send data to
4002 * Display the logical drive number for the device in question, if it a valid
4003 * logical drive. For physical devices, "-1" is returned.
4005 * The logical drive number is displayed in following format:
4007 * <SCSI ID> <LD NUM> <LD STICKY ID> <APP ADAPTER HANDLE>
4009 * <int> <int> <int> <int>
4012 megaraid_sysfs_show_ldnum(struct device
*dev
, struct device_attribute
*attr
, char *buf
)
4014 struct scsi_device
*sdev
= to_scsi_device(dev
);
4015 adapter_t
*adapter
= (adapter_t
*)SCSIHOST2ADAP(sdev
->host
);
4016 mraid_device_t
*raid_dev
= ADAP2RAIDDEV(adapter
);
4018 int logical_drv
= -1;
4020 uint32_t app_hndl
= 0;
4025 if (raid_dev
->random_del_supported
&&
4026 MRAID_IS_LOGICAL_SDEV(adapter
, sdev
)) {
4028 rval
= megaraid_sysfs_get_ldmap(adapter
);
4031 for (i
= 0; i
< MAX_LOGICAL_DRIVES_40LD
; i
++) {
4033 mapped_sdev_id
= sdev
->id
;
4035 if (sdev
->id
> adapter
->init_id
) {
4036 mapped_sdev_id
-= 1;
4039 if (raid_dev
->curr_ldmap
[i
] == mapped_sdev_id
) {
4045 ldid_map
= raid_dev
->curr_ldmap
[i
];
4047 app_hndl
= mraid_mm_adapter_app_handle(
4048 adapter
->unique_id
);
4055 con_log(CL_ANN
, (KERN_NOTICE
4056 "megaraid: sysfs get ld map failed: %x\n",
4061 return snprintf(buf
, 36, "%d %d %d %d\n", scsi_id
, logical_drv
,
4062 ldid_map
, app_hndl
);
4067 * END: Mailbox Low Level Driver
4069 module_init(megaraid_init
);
4070 module_exit(megaraid_exit
);
4072 /* vim: set ts=8 sw=8 tw=78 ai si: */