3 * Linux MegaRAID device driver
5 * Copyright (c) 2003-2004 LSI Logic Corporation.
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version
10 * 2 of the License, or (at your option) any later version.
12 * FILE : megaraid_mbox.c
13 * Version : v2.20.5.1 (Nov 16 2006)
16 * Atul Mukker <Atul.Mukker@lsi.com>
17 * Sreenivas Bagalkote <Sreenivas.Bagalkote@lsi.com>
18 * Manoj Jose <Manoj.Jose@lsi.com>
21 * List of supported controllers
23 * OEM Product Name VID DID SSVID SSID
24 * --- ------------ --- --- ---- ----
25 * Dell PERC3/QC 101E 1960 1028 0471
26 * Dell PERC3/DC 101E 1960 1028 0493
27 * Dell PERC3/SC 101E 1960 1028 0475
28 * Dell PERC3/Di 1028 1960 1028 0123
29 * Dell PERC4/SC 1000 1960 1028 0520
30 * Dell PERC4/DC 1000 1960 1028 0518
31 * Dell PERC4/QC 1000 0407 1028 0531
32 * Dell PERC4/Di 1028 000F 1028 014A
33 * Dell PERC 4e/Si 1028 0013 1028 016c
34 * Dell PERC 4e/Di 1028 0013 1028 016d
35 * Dell PERC 4e/Di 1028 0013 1028 016e
36 * Dell PERC 4e/Di 1028 0013 1028 016f
37 * Dell PERC 4e/Di 1028 0013 1028 0170
38 * Dell PERC 4e/DC 1000 0408 1028 0002
39 * Dell PERC 4e/SC 1000 0408 1028 0001
42 * LSI MegaRAID SCSI 320-0 1000 1960 1000 A520
43 * LSI MegaRAID SCSI 320-1 1000 1960 1000 0520
44 * LSI MegaRAID SCSI 320-2 1000 1960 1000 0518
45 * LSI MegaRAID SCSI 320-0X 1000 0407 1000 0530
46 * LSI MegaRAID SCSI 320-2X 1000 0407 1000 0532
47 * LSI MegaRAID SCSI 320-4X 1000 0407 1000 0531
48 * LSI MegaRAID SCSI 320-1E 1000 0408 1000 0001
49 * LSI MegaRAID SCSI 320-2E 1000 0408 1000 0002
50 * LSI MegaRAID SATA 150-4 1000 1960 1000 4523
51 * LSI MegaRAID SATA 150-6 1000 1960 1000 0523
52 * LSI MegaRAID SATA 300-4X 1000 0409 1000 3004
53 * LSI MegaRAID SATA 300-8X 1000 0409 1000 3008
55 * INTEL RAID Controller SRCU42X 1000 0407 8086 0532
56 * INTEL RAID Controller SRCS16 1000 1960 8086 0523
57 * INTEL RAID Controller SRCU42E 1000 0408 8086 0002
58 * INTEL RAID Controller SRCZCRX 1000 0407 8086 0530
59 * INTEL RAID Controller SRCS28X 1000 0409 8086 3008
60 * INTEL RAID Controller SROMBU42E 1000 0408 8086 3431
61 * INTEL RAID Controller SROMBU42E 1000 0408 8086 3499
62 * INTEL RAID Controller SRCU51L 1000 1960 8086 0520
64 * FSC MegaRAID PCI Express ROMB 1000 0408 1734 1065
66 * ACER MegaRAID ROMB-2E 1000 0408 1025 004D
68 * NEC MegaRAID PCI Express ROMB 1000 0408 1033 8287
70 * For history of changes, see Documentation/scsi/ChangeLog.megaraid
73 #include <linux/slab.h>
74 #include <linux/module.h>
75 #include "megaraid_mbox.h"
77 static int megaraid_init(void);
78 static void megaraid_exit(void);
80 static int megaraid_probe_one(struct pci_dev
*, const struct pci_device_id
*);
81 static void megaraid_detach_one(struct pci_dev
*);
82 static void megaraid_mbox_shutdown(struct pci_dev
*);
84 static int megaraid_io_attach(adapter_t
*);
85 static void megaraid_io_detach(adapter_t
*);
87 static int megaraid_init_mbox(adapter_t
*);
88 static void megaraid_fini_mbox(adapter_t
*);
90 static int megaraid_alloc_cmd_packets(adapter_t
*);
91 static void megaraid_free_cmd_packets(adapter_t
*);
93 static int megaraid_mbox_setup_dma_pools(adapter_t
*);
94 static void megaraid_mbox_teardown_dma_pools(adapter_t
*);
96 static int megaraid_sysfs_alloc_resources(adapter_t
*);
97 static void megaraid_sysfs_free_resources(adapter_t
*);
99 static int megaraid_abort_handler(struct scsi_cmnd
*);
100 static int megaraid_reset_handler(struct scsi_cmnd
*);
102 static int mbox_post_sync_cmd(adapter_t
*, uint8_t []);
103 static int mbox_post_sync_cmd_fast(adapter_t
*, uint8_t []);
104 static int megaraid_busywait_mbox(mraid_device_t
*);
105 static int megaraid_mbox_product_info(adapter_t
*);
106 static int megaraid_mbox_extended_cdb(adapter_t
*);
107 static int megaraid_mbox_support_ha(adapter_t
*, uint16_t *);
108 static int megaraid_mbox_support_random_del(adapter_t
*);
109 static int megaraid_mbox_get_max_sg(adapter_t
*);
110 static void megaraid_mbox_enum_raid_scsi(adapter_t
*);
111 static void megaraid_mbox_flush_cache(adapter_t
*);
112 static int megaraid_mbox_fire_sync_cmd(adapter_t
*);
114 static void megaraid_mbox_display_scb(adapter_t
*, scb_t
*);
115 static void megaraid_mbox_setup_device_map(adapter_t
*);
117 static int megaraid_queue_command(struct Scsi_Host
*, struct scsi_cmnd
*);
118 static scb_t
*megaraid_mbox_build_cmd(adapter_t
*, struct scsi_cmnd
*, int *);
119 static void megaraid_mbox_runpendq(adapter_t
*, scb_t
*);
120 static void megaraid_mbox_prepare_pthru(adapter_t
*, scb_t
*,
122 static void megaraid_mbox_prepare_epthru(adapter_t
*, scb_t
*,
125 static irqreturn_t
megaraid_isr(int, void *);
127 static void megaraid_mbox_dpc(unsigned long);
129 static ssize_t
megaraid_sysfs_show_app_hndl(struct device
*, struct device_attribute
*attr
, char *);
130 static ssize_t
megaraid_sysfs_show_ldnum(struct device
*, struct device_attribute
*attr
, char *);
132 static int megaraid_cmm_register(adapter_t
*);
133 static int megaraid_cmm_unregister(adapter_t
*);
134 static int megaraid_mbox_mm_handler(unsigned long, uioc_t
*, uint32_t);
135 static int megaraid_mbox_mm_command(adapter_t
*, uioc_t
*);
136 static void megaraid_mbox_mm_done(adapter_t
*, scb_t
*);
137 static int gather_hbainfo(adapter_t
*, mraid_hba_info_t
*);
138 static int wait_till_fw_empty(adapter_t
*);
142 MODULE_AUTHOR("megaraidlinux@lsi.com");
143 MODULE_DESCRIPTION("LSI Logic MegaRAID Mailbox Driver");
144 MODULE_LICENSE("GPL");
145 MODULE_VERSION(MEGARAID_VERSION
);
148 * ### modules parameters for driver ###
152 * Set to enable driver to expose unconfigured disk to kernel
154 static int megaraid_expose_unconf_disks
= 0;
155 module_param_named(unconf_disks
, megaraid_expose_unconf_disks
, int, 0);
156 MODULE_PARM_DESC(unconf_disks
,
157 "Set to expose unconfigured disks to kernel (default=0)");
160 * driver wait time if the adapter's mailbox is busy
162 static unsigned int max_mbox_busy_wait
= MBOX_BUSY_WAIT
;
163 module_param_named(busy_wait
, max_mbox_busy_wait
, int, 0);
164 MODULE_PARM_DESC(busy_wait
,
165 "Max wait for mailbox in microseconds if busy (default=10)");
168 * number of sectors per IO command
170 static unsigned int megaraid_max_sectors
= MBOX_MAX_SECTORS
;
171 module_param_named(max_sectors
, megaraid_max_sectors
, int, 0);
172 MODULE_PARM_DESC(max_sectors
,
173 "Maximum number of sectors per IO command (default=128)");
176 * number of commands per logical unit
178 static unsigned int megaraid_cmd_per_lun
= MBOX_DEF_CMD_PER_LUN
;
179 module_param_named(cmd_per_lun
, megaraid_cmd_per_lun
, int, 0);
180 MODULE_PARM_DESC(cmd_per_lun
,
181 "Maximum number of commands per logical unit (default=64)");
185 * Fast driver load option, skip scanning for physical devices during load.
186 * This would result in non-disk devices being skipped during driver load
187 * time. These can be later added though, using /proc/scsi/scsi
189 static unsigned int megaraid_fast_load
= 0;
190 module_param_named(fast_load
, megaraid_fast_load
, int, 0);
191 MODULE_PARM_DESC(fast_load
,
192 "Faster loading of the driver, skips physical devices! (default=0)");
196 * mraid_debug level - threshold for amount of information to be displayed by
197 * the driver. This level can be changed through modules parameters, ioctl or
198 * sysfs/proc interface. By default, print the announcement messages only.
200 int mraid_debug_level
= CL_ANN
;
201 module_param_named(debug_level
, mraid_debug_level
, int, 0);
202 MODULE_PARM_DESC(debug_level
, "Debug level for driver (default=0)");
205 * ### global data ###
207 static uint8_t megaraid_mbox_version
[8] =
208 { 0x02, 0x20, 0x04, 0x06, 3, 7, 20, 5 };
212 * PCI table for all supported controllers.
214 static struct pci_device_id pci_id_table_g
[] = {
217 PCI_DEVICE_ID_PERC4_DI_DISCOVERY
,
219 PCI_SUBSYS_ID_PERC4_DI_DISCOVERY
,
222 PCI_VENDOR_ID_LSI_LOGIC
,
223 PCI_DEVICE_ID_PERC4_SC
,
225 PCI_SUBSYS_ID_PERC4_SC
,
228 PCI_VENDOR_ID_LSI_LOGIC
,
229 PCI_DEVICE_ID_PERC4_DC
,
231 PCI_SUBSYS_ID_PERC4_DC
,
234 PCI_VENDOR_ID_LSI_LOGIC
,
241 PCI_DEVICE_ID_PERC4_DI_EVERGLADES
,
243 PCI_SUBSYS_ID_PERC4_DI_EVERGLADES
,
247 PCI_DEVICE_ID_PERC4E_SI_BIGBEND
,
249 PCI_SUBSYS_ID_PERC4E_SI_BIGBEND
,
253 PCI_DEVICE_ID_PERC4E_DI_KOBUK
,
255 PCI_SUBSYS_ID_PERC4E_DI_KOBUK
,
259 PCI_DEVICE_ID_PERC4E_DI_CORVETTE
,
261 PCI_SUBSYS_ID_PERC4E_DI_CORVETTE
,
265 PCI_DEVICE_ID_PERC4E_DI_EXPEDITION
,
267 PCI_SUBSYS_ID_PERC4E_DI_EXPEDITION
,
271 PCI_DEVICE_ID_PERC4E_DI_GUADALUPE
,
273 PCI_SUBSYS_ID_PERC4E_DI_GUADALUPE
,
276 PCI_VENDOR_ID_LSI_LOGIC
,
277 PCI_DEVICE_ID_DOBSON
,
283 PCI_DEVICE_ID_AMI_MEGARAID3
,
288 PCI_VENDOR_ID_LSI_LOGIC
,
289 PCI_DEVICE_ID_AMI_MEGARAID3
,
294 PCI_VENDOR_ID_LSI_LOGIC
,
295 PCI_DEVICE_ID_LINDSAY
,
299 {0} /* Terminating entry */
301 MODULE_DEVICE_TABLE(pci
, pci_id_table_g
);
304 static struct pci_driver megaraid_pci_driver
= {
306 .id_table
= pci_id_table_g
,
307 .probe
= megaraid_probe_one
,
308 .remove
= megaraid_detach_one
,
309 .shutdown
= megaraid_mbox_shutdown
,
314 // definitions for the device attributes for exporting logical drive number
315 // for a scsi address (Host, Channel, Id, Lun)
317 DEVICE_ATTR(megaraid_mbox_app_hndl
, S_IRUSR
, megaraid_sysfs_show_app_hndl
,
320 // Host template initializer for megaraid mbox sysfs device attributes
321 static struct device_attribute
*megaraid_shost_attrs
[] = {
322 &dev_attr_megaraid_mbox_app_hndl
,
327 DEVICE_ATTR(megaraid_mbox_ld
, S_IRUSR
, megaraid_sysfs_show_ldnum
, NULL
);
329 // Host template initializer for megaraid mbox sysfs device attributes
330 static struct device_attribute
*megaraid_sdev_attrs
[] = {
331 &dev_attr_megaraid_mbox_ld
,
336 * megaraid_change_queue_depth - Change the device's queue depth
337 * @sdev: scsi device struct
338 * @qdepth: depth to set
339 * @reason: calling context
344 static int megaraid_change_queue_depth(struct scsi_device
*sdev
, int qdepth
,
347 if (reason
!= SCSI_QDEPTH_DEFAULT
)
350 scsi_adjust_queue_depth(sdev
, qdepth
);
351 return sdev
->queue_depth
;
355 * Scsi host template for megaraid unified driver
357 static struct scsi_host_template megaraid_template_g
= {
358 .module
= THIS_MODULE
,
359 .name
= "LSI Logic MegaRAID driver",
360 .proc_name
= "megaraid",
361 .queuecommand
= megaraid_queue_command
,
362 .eh_abort_handler
= megaraid_abort_handler
,
363 .eh_device_reset_handler
= megaraid_reset_handler
,
364 .eh_bus_reset_handler
= megaraid_reset_handler
,
365 .eh_host_reset_handler
= megaraid_reset_handler
,
366 .change_queue_depth
= megaraid_change_queue_depth
,
367 .use_clustering
= ENABLE_CLUSTERING
,
369 .sdev_attrs
= megaraid_sdev_attrs
,
370 .shost_attrs
= megaraid_shost_attrs
,
375 * megaraid_init - module load hook
377 * We register ourselves as hotplug enabled module and let PCI subsystem
378 * discover our adapters.
385 // Announce the driver version
386 con_log(CL_ANN
, (KERN_INFO
"megaraid: %s %s\n", MEGARAID_VERSION
,
387 MEGARAID_EXT_VERSION
));
389 // check validity of module parameters
390 if (megaraid_cmd_per_lun
> MBOX_MAX_SCSI_CMDS
) {
392 con_log(CL_ANN
, (KERN_WARNING
393 "megaraid mailbox: max commands per lun reset to %d\n",
394 MBOX_MAX_SCSI_CMDS
));
396 megaraid_cmd_per_lun
= MBOX_MAX_SCSI_CMDS
;
400 // register as a PCI hot-plug driver module
401 rval
= pci_register_driver(&megaraid_pci_driver
);
403 con_log(CL_ANN
, (KERN_WARNING
404 "megaraid: could not register hotplug support.\n"));
412 * megaraid_exit - driver unload entry point
414 * We simply unwrap the megaraid_init routine here.
419 con_log(CL_DLEVEL1
, (KERN_NOTICE
"megaraid: unloading framework\n"));
421 // unregister as PCI hotplug driver
422 pci_unregister_driver(&megaraid_pci_driver
);
429 * megaraid_probe_one - PCI hotplug entry point
430 * @pdev : handle to this controller's PCI configuration space
431 * @id : pci device id of the class of controllers
433 * This routine should be called whenever a new adapter is detected by the
434 * PCI hotplug susbsystem.
437 megaraid_probe_one(struct pci_dev
*pdev
, const struct pci_device_id
*id
)
442 // detected a new controller
443 con_log(CL_ANN
, (KERN_INFO
444 "megaraid: probe new device %#4.04x:%#4.04x:%#4.04x:%#4.04x: ",
445 pdev
->vendor
, pdev
->device
, pdev
->subsystem_vendor
,
446 pdev
->subsystem_device
));
448 con_log(CL_ANN
, ("bus %d:slot %d:func %d\n", pdev
->bus
->number
,
449 PCI_SLOT(pdev
->devfn
), PCI_FUNC(pdev
->devfn
)));
451 if (pci_enable_device(pdev
)) {
452 con_log(CL_ANN
, (KERN_WARNING
453 "megaraid: pci_enable_device failed\n"));
458 // Enable bus-mastering on this controller
459 pci_set_master(pdev
);
461 // Allocate the per driver initialization structure
462 adapter
= kzalloc(sizeof(adapter_t
), GFP_KERNEL
);
464 if (adapter
== NULL
) {
465 con_log(CL_ANN
, (KERN_WARNING
466 "megaraid: out of memory, %s %d.\n", __func__
, __LINE__
));
472 // set up PCI related soft state and other pre-known parameters
473 adapter
->unique_id
= pdev
->bus
->number
<< 8 | pdev
->devfn
;
474 adapter
->irq
= pdev
->irq
;
475 adapter
->pdev
= pdev
;
477 atomic_set(&adapter
->being_detached
, 0);
479 // Setup the default DMA mask. This would be changed later on
480 // depending on hardware capabilities
481 if (pci_set_dma_mask(adapter
->pdev
, DMA_BIT_MASK(32)) != 0) {
483 con_log(CL_ANN
, (KERN_WARNING
484 "megaraid: pci_set_dma_mask failed:%d\n", __LINE__
));
486 goto out_free_adapter
;
490 // Initialize the synchronization lock for kernel and LLD
491 spin_lock_init(&adapter
->lock
);
493 // Initialize the command queues: the list of free SCBs and the list
495 INIT_LIST_HEAD(&adapter
->kscb_pool
);
496 spin_lock_init(SCSI_FREE_LIST_LOCK(adapter
));
498 INIT_LIST_HEAD(&adapter
->pend_list
);
499 spin_lock_init(PENDING_LIST_LOCK(adapter
));
501 INIT_LIST_HEAD(&adapter
->completed_list
);
502 spin_lock_init(COMPLETED_LIST_LOCK(adapter
));
505 // Start the mailbox based controller
506 if (megaraid_init_mbox(adapter
) != 0) {
507 con_log(CL_ANN
, (KERN_WARNING
508 "megaraid: maibox adapter did not initialize\n"));
510 goto out_free_adapter
;
513 // Register with LSI Common Management Module
514 if (megaraid_cmm_register(adapter
) != 0) {
516 con_log(CL_ANN
, (KERN_WARNING
517 "megaraid: could not register with management module\n"));
522 // setup adapter handle in PCI soft state
523 pci_set_drvdata(pdev
, adapter
);
525 // attach with scsi mid-layer
526 if (megaraid_io_attach(adapter
) != 0) {
528 con_log(CL_ANN
, (KERN_WARNING
"megaraid: io attach failed\n"));
536 megaraid_cmm_unregister(adapter
);
538 megaraid_fini_mbox(adapter
);
542 pci_disable_device(pdev
);
549 * megaraid_detach_one - release framework resources and call LLD release routine
550 * @pdev : handle for our PCI configuration space
552 * This routine is called during driver unload. We free all the allocated
553 * resources and call the corresponding LLD so that it can also release all
556 * This routine is also called from the PCI hotplug system.
559 megaraid_detach_one(struct pci_dev
*pdev
)
562 struct Scsi_Host
*host
;
565 // Start a rollback on this adapter
566 adapter
= pci_get_drvdata(pdev
);
569 con_log(CL_ANN
, (KERN_CRIT
570 "megaraid: Invalid detach on %#4.04x:%#4.04x:%#4.04x:%#4.04x\n",
571 pdev
->vendor
, pdev
->device
, pdev
->subsystem_vendor
,
572 pdev
->subsystem_device
));
577 con_log(CL_ANN
, (KERN_NOTICE
578 "megaraid: detaching device %#4.04x:%#4.04x:%#4.04x:%#4.04x\n",
579 pdev
->vendor
, pdev
->device
, pdev
->subsystem_vendor
,
580 pdev
->subsystem_device
));
584 host
= adapter
->host
;
586 // do not allow any more requests from the management module for this
588 // FIXME: How do we account for the request which might still be
590 atomic_set(&adapter
->being_detached
, 1);
592 // detach from the IO sub-system
593 megaraid_io_detach(adapter
);
595 // Unregister from common management module
597 // FIXME: this must return success or failure for conditions if there
598 // is a command pending with LLD or not.
599 megaraid_cmm_unregister(adapter
);
601 // finalize the mailbox based controller and release all resources
602 megaraid_fini_mbox(adapter
);
608 pci_disable_device(pdev
);
615 * megaraid_mbox_shutdown - PCI shutdown for megaraid HBA
616 * @pdev : generic driver model device
618 * Shutdown notification, perform flush cache.
621 megaraid_mbox_shutdown(struct pci_dev
*pdev
)
623 adapter_t
*adapter
= pci_get_drvdata(pdev
);
627 con_log(CL_ANN
, (KERN_WARNING
628 "megaraid: null device in shutdown\n"));
633 con_log(CL_ANN
, (KERN_INFO
"megaraid: flushing adapter %d...",
636 megaraid_mbox_flush_cache(adapter
);
638 con_log(CL_ANN
, ("done\n"));
643 * megaraid_io_attach - attach a device with the IO subsystem
644 * @adapter : controller's soft state
646 * Attach this device with the IO subsystem.
649 megaraid_io_attach(adapter_t
*adapter
)
651 struct Scsi_Host
*host
;
653 // Initialize SCSI Host structure
654 host
= scsi_host_alloc(&megaraid_template_g
, 8);
656 con_log(CL_ANN
, (KERN_WARNING
657 "megaraid mbox: scsi_register failed\n"));
662 SCSIHOST2ADAP(host
) = (caddr_t
)adapter
;
663 adapter
->host
= host
;
665 host
->irq
= adapter
->irq
;
666 host
->unique_id
= adapter
->unique_id
;
667 host
->can_queue
= adapter
->max_cmds
;
668 host
->this_id
= adapter
->init_id
;
669 host
->sg_tablesize
= adapter
->sglen
;
670 host
->max_sectors
= adapter
->max_sectors
;
671 host
->cmd_per_lun
= adapter
->cmd_per_lun
;
672 host
->max_channel
= adapter
->max_channel
;
673 host
->max_id
= adapter
->max_target
;
674 host
->max_lun
= adapter
->max_lun
;
677 // notify mid-layer about the new controller
678 if (scsi_add_host(host
, &adapter
->pdev
->dev
)) {
680 con_log(CL_ANN
, (KERN_WARNING
681 "megaraid mbox: scsi_add_host failed\n"));
688 scsi_scan_host(host
);
695 * megaraid_io_detach - detach a device from the IO subsystem
696 * @adapter : controller's soft state
698 * Detach this device from the IO subsystem.
701 megaraid_io_detach(adapter_t
*adapter
)
703 struct Scsi_Host
*host
;
705 con_log(CL_DLEVEL1
, (KERN_INFO
"megaraid: io detach\n"));
707 host
= adapter
->host
;
709 scsi_remove_host(host
);
716 * START: Mailbox Low Level Driver
718 * This is section specific to the single mailbox based controllers
722 * megaraid_init_mbox - initialize controller
723 * @adapter : our soft state
725 * - Allocate 16-byte aligned mailbox memory for firmware handshake
726 * - Allocate controller's memory resources
727 * - Find out all initialization data
728 * - Allocate memory required for all the commands
729 * - Use internal library of FW routines, build up complete soft state
732 megaraid_init_mbox(adapter_t
*adapter
)
734 struct pci_dev
*pdev
;
735 mraid_device_t
*raid_dev
;
740 adapter
->ito
= MBOX_TIMEOUT
;
741 pdev
= adapter
->pdev
;
744 * Allocate and initialize the init data structure for mailbox
747 raid_dev
= kzalloc(sizeof(mraid_device_t
), GFP_KERNEL
);
748 if (raid_dev
== NULL
) return -1;
752 * Attach the adapter soft state to raid device soft state
754 adapter
->raid_device
= (caddr_t
)raid_dev
;
755 raid_dev
->fast_load
= megaraid_fast_load
;
759 raid_dev
->baseport
= pci_resource_start(pdev
, 0);
761 if (pci_request_regions(pdev
, "MegaRAID: LSI Logic Corporation") != 0) {
763 con_log(CL_ANN
, (KERN_WARNING
764 "megaraid: mem region busy\n"));
766 goto out_free_raid_dev
;
769 raid_dev
->baseaddr
= ioremap_nocache(raid_dev
->baseport
, 128);
771 if (!raid_dev
->baseaddr
) {
773 con_log(CL_ANN
, (KERN_WARNING
774 "megaraid: could not map hba memory\n") );
776 goto out_release_regions
;
779 /* initialize the mutual exclusion lock for the mailbox */
780 spin_lock_init(&raid_dev
->mailbox_lock
);
782 /* allocate memory required for commands */
783 if (megaraid_alloc_cmd_packets(adapter
) != 0)
787 * Issue SYNC cmd to flush the pending cmds in the adapter
788 * and initialize its internal state
791 if (megaraid_mbox_fire_sync_cmd(adapter
))
792 con_log(CL_ANN
, ("megaraid: sync cmd failed\n"));
795 * Setup the rest of the soft state using the library of
799 /* request IRQ and register the interrupt service routine */
800 if (request_irq(adapter
->irq
, megaraid_isr
, IRQF_SHARED
, "megaraid",
803 con_log(CL_ANN
, (KERN_WARNING
804 "megaraid: Couldn't register IRQ %d!\n", adapter
->irq
));
810 if (megaraid_mbox_product_info(adapter
) != 0)
813 // Do we support extended CDBs
814 adapter
->max_cdb_sz
= 10;
815 if (megaraid_mbox_extended_cdb(adapter
) == 0) {
816 adapter
->max_cdb_sz
= 16;
820 * Do we support cluster environment, if we do, what is the initiator
822 * NOTE: In a non-cluster aware firmware environment, the LLD should
823 * return 7 as initiator id.
826 adapter
->init_id
= -1;
827 if (megaraid_mbox_support_ha(adapter
, &adapter
->init_id
) == 0) {
832 * Prepare the device ids array to have the mapping between the kernel
833 * device address and megaraid device address.
834 * We export the physical devices on their actual addresses. The
835 * logical drives are exported on a virtual SCSI channel
837 megaraid_mbox_setup_device_map(adapter
);
839 // If the firmware supports random deletion, update the device id map
840 if (megaraid_mbox_support_random_del(adapter
)) {
842 // Change the logical drives numbers in device_ids array one
843 // slot in device_ids is reserved for target id, that's why
845 for (i
= 0; i
<= MAX_LOGICAL_DRIVES_40LD
; i
++) {
846 adapter
->device_ids
[adapter
->max_channel
][i
] += 0x80;
848 adapter
->device_ids
[adapter
->max_channel
][adapter
->init_id
] =
851 raid_dev
->random_del_supported
= 1;
855 * find out the maximum number of scatter-gather elements supported by
858 adapter
->sglen
= megaraid_mbox_get_max_sg(adapter
);
860 // enumerate RAID and SCSI channels so that all devices on SCSI
861 // channels can later be exported, including disk devices
862 megaraid_mbox_enum_raid_scsi(adapter
);
865 * Other parameters required by upper layer
867 * maximum number of sectors per IO command
869 adapter
->max_sectors
= megaraid_max_sectors
;
872 * number of queued commands per LUN.
874 adapter
->cmd_per_lun
= megaraid_cmd_per_lun
;
877 * Allocate resources required to issue FW calls, when sysfs is
880 if (megaraid_sysfs_alloc_resources(adapter
) != 0)
883 // Set the DMA mask to 64-bit. All supported controllers as capable of
885 pci_read_config_dword(adapter
->pdev
, PCI_CONF_AMISIG64
, &magic64
);
887 if (((magic64
== HBA_SIGNATURE_64_BIT
) &&
888 ((adapter
->pdev
->subsystem_device
!=
889 PCI_SUBSYS_ID_MEGARAID_SATA_150_6
) &&
890 (adapter
->pdev
->subsystem_device
!=
891 PCI_SUBSYS_ID_MEGARAID_SATA_150_4
))) ||
892 (adapter
->pdev
->vendor
== PCI_VENDOR_ID_LSI_LOGIC
&&
893 adapter
->pdev
->device
== PCI_DEVICE_ID_VERDE
) ||
894 (adapter
->pdev
->vendor
== PCI_VENDOR_ID_LSI_LOGIC
&&
895 adapter
->pdev
->device
== PCI_DEVICE_ID_DOBSON
) ||
896 (adapter
->pdev
->vendor
== PCI_VENDOR_ID_LSI_LOGIC
&&
897 adapter
->pdev
->device
== PCI_DEVICE_ID_LINDSAY
) ||
898 (adapter
->pdev
->vendor
== PCI_VENDOR_ID_DELL
&&
899 adapter
->pdev
->device
== PCI_DEVICE_ID_PERC4_DI_EVERGLADES
) ||
900 (adapter
->pdev
->vendor
== PCI_VENDOR_ID_DELL
&&
901 adapter
->pdev
->device
== PCI_DEVICE_ID_PERC4E_DI_KOBUK
)) {
902 if (pci_set_dma_mask(adapter
->pdev
, DMA_BIT_MASK(64))) {
903 con_log(CL_ANN
, (KERN_WARNING
904 "megaraid: DMA mask for 64-bit failed\n"));
906 if (pci_set_dma_mask (adapter
->pdev
, DMA_BIT_MASK(32))) {
907 con_log(CL_ANN
, (KERN_WARNING
908 "megaraid: 32-bit DMA mask failed\n"));
909 goto out_free_sysfs_res
;
914 // setup tasklet for DPC
915 tasklet_init(&adapter
->dpc_h
, megaraid_mbox_dpc
,
916 (unsigned long)adapter
);
918 con_log(CL_DLEVEL1
, (KERN_INFO
919 "megaraid mbox hba successfully initialized\n"));
924 megaraid_sysfs_free_resources(adapter
);
926 free_irq(adapter
->irq
, adapter
);
928 megaraid_free_cmd_packets(adapter
);
930 iounmap(raid_dev
->baseaddr
);
932 pci_release_regions(pdev
);
941 * megaraid_fini_mbox - undo controller initialization
942 * @adapter : our soft state
945 megaraid_fini_mbox(adapter_t
*adapter
)
947 mraid_device_t
*raid_dev
= ADAP2RAIDDEV(adapter
);
950 megaraid_mbox_flush_cache(adapter
);
952 tasklet_kill(&adapter
->dpc_h
);
954 megaraid_sysfs_free_resources(adapter
);
956 megaraid_free_cmd_packets(adapter
);
958 free_irq(adapter
->irq
, adapter
);
960 iounmap(raid_dev
->baseaddr
);
962 pci_release_regions(adapter
->pdev
);
971 * megaraid_alloc_cmd_packets - allocate shared mailbox
972 * @adapter : soft state of the raid controller
974 * Allocate and align the shared mailbox. This maibox is used to issue
975 * all the commands. For IO based controllers, the mailbox is also registered
976 * with the FW. Allocate memory for all commands as well.
977 * This is our big allocator.
980 megaraid_alloc_cmd_packets(adapter_t
*adapter
)
982 mraid_device_t
*raid_dev
= ADAP2RAIDDEV(adapter
);
983 struct pci_dev
*pdev
;
987 struct mraid_pci_blk
*epthru_pci_blk
;
988 struct mraid_pci_blk
*sg_pci_blk
;
989 struct mraid_pci_blk
*mbox_pci_blk
;
992 pdev
= adapter
->pdev
;
996 * Allocate the common 16-byte aligned memory for the handshake
999 raid_dev
->una_mbox64
= pci_zalloc_consistent(adapter
->pdev
,
1001 &raid_dev
->una_mbox64_dma
);
1003 if (!raid_dev
->una_mbox64
) {
1004 con_log(CL_ANN
, (KERN_WARNING
1005 "megaraid: out of memory, %s %d\n", __func__
,
1011 * Align the mailbox at 16-byte boundary
1013 raid_dev
->mbox
= &raid_dev
->una_mbox64
->mbox32
;
1015 raid_dev
->mbox
= (mbox_t
*)((((unsigned long)raid_dev
->mbox
) + 15) &
1018 raid_dev
->mbox64
= (mbox64_t
*)(((unsigned long)raid_dev
->mbox
) - 8);
1020 align
= ((void *)raid_dev
->mbox
-
1021 ((void *)&raid_dev
->una_mbox64
->mbox32
));
1023 raid_dev
->mbox_dma
= (unsigned long)raid_dev
->una_mbox64_dma
+ 8 +
1026 // Allocate memory for commands issued internally
1027 adapter
->ibuf
= pci_zalloc_consistent(pdev
, MBOX_IBUF_SIZE
,
1028 &adapter
->ibuf_dma_h
);
1029 if (!adapter
->ibuf
) {
1031 con_log(CL_ANN
, (KERN_WARNING
1032 "megaraid: out of memory, %s %d\n", __func__
,
1035 goto out_free_common_mbox
;
1038 // Allocate memory for our SCSI Command Blocks and their associated
1042 * Allocate memory for the base list of scb. Later allocate memory for
1043 * CCBs and embedded components of each CCB and point the pointers in
1044 * scb to the allocated components
1045 * NOTE: The code to allocate SCB will be duplicated in all the LLD
1046 * since the calling routine does not yet know the number of available
1049 adapter
->kscb_list
= kcalloc(MBOX_MAX_SCSI_CMDS
, sizeof(scb_t
), GFP_KERNEL
);
1051 if (adapter
->kscb_list
== NULL
) {
1052 con_log(CL_ANN
, (KERN_WARNING
1053 "megaraid: out of memory, %s %d\n", __func__
,
1058 // memory allocation for our command packets
1059 if (megaraid_mbox_setup_dma_pools(adapter
) != 0) {
1060 con_log(CL_ANN
, (KERN_WARNING
1061 "megaraid: out of memory, %s %d\n", __func__
,
1063 goto out_free_scb_list
;
1066 // Adjust the scb pointers and link in the free pool
1067 epthru_pci_blk
= raid_dev
->epthru_pool
;
1068 sg_pci_blk
= raid_dev
->sg_pool
;
1069 mbox_pci_blk
= raid_dev
->mbox_pool
;
1071 for (i
= 0; i
< MBOX_MAX_SCSI_CMDS
; i
++) {
1072 scb
= adapter
->kscb_list
+ i
;
1073 ccb
= raid_dev
->ccb_list
+ i
;
1075 ccb
->mbox
= (mbox_t
*)(mbox_pci_blk
[i
].vaddr
+ 16);
1076 ccb
->raw_mbox
= (uint8_t *)ccb
->mbox
;
1077 ccb
->mbox64
= (mbox64_t
*)(mbox_pci_blk
[i
].vaddr
+ 8);
1078 ccb
->mbox_dma_h
= (unsigned long)mbox_pci_blk
[i
].dma_addr
+ 16;
1080 // make sure the mailbox is aligned properly
1081 if (ccb
->mbox_dma_h
& 0x0F) {
1082 con_log(CL_ANN
, (KERN_CRIT
1083 "megaraid mbox: not aligned on 16-bytes\n"));
1085 goto out_teardown_dma_pools
;
1088 ccb
->epthru
= (mraid_epassthru_t
*)
1089 epthru_pci_blk
[i
].vaddr
;
1090 ccb
->epthru_dma_h
= epthru_pci_blk
[i
].dma_addr
;
1091 ccb
->pthru
= (mraid_passthru_t
*)ccb
->epthru
;
1092 ccb
->pthru_dma_h
= ccb
->epthru_dma_h
;
1095 ccb
->sgl64
= (mbox_sgl64
*)sg_pci_blk
[i
].vaddr
;
1096 ccb
->sgl_dma_h
= sg_pci_blk
[i
].dma_addr
;
1097 ccb
->sgl32
= (mbox_sgl32
*)ccb
->sgl64
;
1099 scb
->ccb
= (caddr_t
)ccb
;
1102 scb
->sno
= i
; // command index
1105 scb
->state
= SCB_FREE
;
1106 scb
->dma_direction
= PCI_DMA_NONE
;
1107 scb
->dma_type
= MRAID_DMA_NONE
;
1108 scb
->dev_channel
= -1;
1109 scb
->dev_target
= -1;
1111 // put scb in the free pool
1112 list_add_tail(&scb
->list
, &adapter
->kscb_pool
);
1117 out_teardown_dma_pools
:
1118 megaraid_mbox_teardown_dma_pools(adapter
);
1120 kfree(adapter
->kscb_list
);
1122 pci_free_consistent(pdev
, MBOX_IBUF_SIZE
, (void *)adapter
->ibuf
,
1123 adapter
->ibuf_dma_h
);
1124 out_free_common_mbox
:
1125 pci_free_consistent(adapter
->pdev
, sizeof(mbox64_t
),
1126 (caddr_t
)raid_dev
->una_mbox64
, raid_dev
->una_mbox64_dma
);
1133 * megaraid_free_cmd_packets - free memory
1134 * @adapter : soft state of the raid controller
1136 * Release memory resources allocated for commands.
1139 megaraid_free_cmd_packets(adapter_t
*adapter
)
1141 mraid_device_t
*raid_dev
= ADAP2RAIDDEV(adapter
);
1143 megaraid_mbox_teardown_dma_pools(adapter
);
1145 kfree(adapter
->kscb_list
);
1147 pci_free_consistent(adapter
->pdev
, MBOX_IBUF_SIZE
,
1148 (void *)adapter
->ibuf
, adapter
->ibuf_dma_h
);
1150 pci_free_consistent(adapter
->pdev
, sizeof(mbox64_t
),
1151 (caddr_t
)raid_dev
->una_mbox64
, raid_dev
->una_mbox64_dma
);
1157 * megaraid_mbox_setup_dma_pools - setup dma pool for command packets
1158 * @adapter : HBA soft state
1160 * Setup the dma pools for mailbox, passthru and extended passthru structures,
1161 * and scatter-gather lists.
1164 megaraid_mbox_setup_dma_pools(adapter_t
*adapter
)
1166 mraid_device_t
*raid_dev
= ADAP2RAIDDEV(adapter
);
1167 struct mraid_pci_blk
*epthru_pci_blk
;
1168 struct mraid_pci_blk
*sg_pci_blk
;
1169 struct mraid_pci_blk
*mbox_pci_blk
;
1174 // Allocate memory for 16-bytes aligned mailboxes
1175 raid_dev
->mbox_pool_handle
= pci_pool_create("megaraid mbox pool",
1177 sizeof(mbox64_t
) + 16,
1180 if (raid_dev
->mbox_pool_handle
== NULL
) {
1181 goto fail_setup_dma_pool
;
1184 mbox_pci_blk
= raid_dev
->mbox_pool
;
1185 for (i
= 0; i
< MBOX_MAX_SCSI_CMDS
; i
++) {
1186 mbox_pci_blk
[i
].vaddr
= pci_pool_alloc(
1187 raid_dev
->mbox_pool_handle
,
1189 &mbox_pci_blk
[i
].dma_addr
);
1190 if (!mbox_pci_blk
[i
].vaddr
) {
1191 goto fail_setup_dma_pool
;
1196 * Allocate memory for each embedded passthru strucuture pointer
1197 * Request for a 128 bytes aligned structure for each passthru command
1199 * Since passthru and extended passthru commands are exclusive, they
1200 * share common memory pool. Passthru structures piggyback on memory
1201 * allocted to extended passthru since passthru is smaller of the two
1203 raid_dev
->epthru_pool_handle
= pci_pool_create("megaraid mbox pthru",
1204 adapter
->pdev
, sizeof(mraid_epassthru_t
), 128, 0);
1206 if (raid_dev
->epthru_pool_handle
== NULL
) {
1207 goto fail_setup_dma_pool
;
1210 epthru_pci_blk
= raid_dev
->epthru_pool
;
1211 for (i
= 0; i
< MBOX_MAX_SCSI_CMDS
; i
++) {
1212 epthru_pci_blk
[i
].vaddr
= pci_pool_alloc(
1213 raid_dev
->epthru_pool_handle
,
1215 &epthru_pci_blk
[i
].dma_addr
);
1216 if (!epthru_pci_blk
[i
].vaddr
) {
1217 goto fail_setup_dma_pool
;
1222 // Allocate memory for each scatter-gather list. Request for 512 bytes
1223 // alignment for each sg list
1224 raid_dev
->sg_pool_handle
= pci_pool_create("megaraid mbox sg",
1226 sizeof(mbox_sgl64
) * MBOX_MAX_SG_SIZE
,
1229 if (raid_dev
->sg_pool_handle
== NULL
) {
1230 goto fail_setup_dma_pool
;
1233 sg_pci_blk
= raid_dev
->sg_pool
;
1234 for (i
= 0; i
< MBOX_MAX_SCSI_CMDS
; i
++) {
1235 sg_pci_blk
[i
].vaddr
= pci_pool_alloc(
1236 raid_dev
->sg_pool_handle
,
1238 &sg_pci_blk
[i
].dma_addr
);
1239 if (!sg_pci_blk
[i
].vaddr
) {
1240 goto fail_setup_dma_pool
;
1246 fail_setup_dma_pool
:
1247 megaraid_mbox_teardown_dma_pools(adapter
);
1253 * megaraid_mbox_teardown_dma_pools - teardown dma pools for command packets
1254 * @adapter : HBA soft state
1256 * Teardown the dma pool for mailbox, passthru and extended passthru
1257 * structures, and scatter-gather lists.
1260 megaraid_mbox_teardown_dma_pools(adapter_t
*adapter
)
1262 mraid_device_t
*raid_dev
= ADAP2RAIDDEV(adapter
);
1263 struct mraid_pci_blk
*epthru_pci_blk
;
1264 struct mraid_pci_blk
*sg_pci_blk
;
1265 struct mraid_pci_blk
*mbox_pci_blk
;
1269 sg_pci_blk
= raid_dev
->sg_pool
;
1270 for (i
= 0; i
< MBOX_MAX_SCSI_CMDS
&& sg_pci_blk
[i
].vaddr
; i
++) {
1271 pci_pool_free(raid_dev
->sg_pool_handle
, sg_pci_blk
[i
].vaddr
,
1272 sg_pci_blk
[i
].dma_addr
);
1274 if (raid_dev
->sg_pool_handle
)
1275 pci_pool_destroy(raid_dev
->sg_pool_handle
);
1278 epthru_pci_blk
= raid_dev
->epthru_pool
;
1279 for (i
= 0; i
< MBOX_MAX_SCSI_CMDS
&& epthru_pci_blk
[i
].vaddr
; i
++) {
1280 pci_pool_free(raid_dev
->epthru_pool_handle
,
1281 epthru_pci_blk
[i
].vaddr
, epthru_pci_blk
[i
].dma_addr
);
1283 if (raid_dev
->epthru_pool_handle
)
1284 pci_pool_destroy(raid_dev
->epthru_pool_handle
);
1287 mbox_pci_blk
= raid_dev
->mbox_pool
;
1288 for (i
= 0; i
< MBOX_MAX_SCSI_CMDS
&& mbox_pci_blk
[i
].vaddr
; i
++) {
1289 pci_pool_free(raid_dev
->mbox_pool_handle
,
1290 mbox_pci_blk
[i
].vaddr
, mbox_pci_blk
[i
].dma_addr
);
1292 if (raid_dev
->mbox_pool_handle
)
1293 pci_pool_destroy(raid_dev
->mbox_pool_handle
);
1300 * megaraid_alloc_scb - detach and return a scb from the free list
1301 * @adapter : controller's soft state
1302 * @scp : pointer to the scsi command to be executed
1304 * Return the scb from the head of the free list. %NULL if there are none
1308 megaraid_alloc_scb(adapter_t
*adapter
, struct scsi_cmnd
*scp
)
1310 struct list_head
*head
= &adapter
->kscb_pool
;
1312 unsigned long flags
;
1314 // detach scb from free pool
1315 spin_lock_irqsave(SCSI_FREE_LIST_LOCK(adapter
), flags
);
1317 if (list_empty(head
)) {
1318 spin_unlock_irqrestore(SCSI_FREE_LIST_LOCK(adapter
), flags
);
1322 scb
= list_entry(head
->next
, scb_t
, list
);
1323 list_del_init(&scb
->list
);
1325 spin_unlock_irqrestore(SCSI_FREE_LIST_LOCK(adapter
), flags
);
1327 scb
->state
= SCB_ACTIVE
;
1329 scb
->dma_type
= MRAID_DMA_NONE
;
1336 * megaraid_dealloc_scb - return the scb to the free pool
1337 * @adapter : controller's soft state
1338 * @scb : scb to be freed
1340 * Return the scb back to the free list of scbs. The caller must 'flush' the
1341 * SCB before calling us. E.g., performing pci_unamp and/or pci_sync etc.
1342 * NOTE NOTE: Make sure the scb is not on any list before calling this
1346 megaraid_dealloc_scb(adapter_t
*adapter
, scb_t
*scb
)
1348 unsigned long flags
;
1350 // put scb in the free pool
1351 scb
->state
= SCB_FREE
;
1353 spin_lock_irqsave(SCSI_FREE_LIST_LOCK(adapter
), flags
);
1355 list_add(&scb
->list
, &adapter
->kscb_pool
);
1357 spin_unlock_irqrestore(SCSI_FREE_LIST_LOCK(adapter
), flags
);
1364 * megaraid_mbox_mksgl - make the scatter-gather list
1365 * @adapter : controller's soft state
1366 * @scb : scsi control block
1368 * Prepare the scatter-gather list.
1371 megaraid_mbox_mksgl(adapter_t
*adapter
, scb_t
*scb
)
1373 struct scatterlist
*sgl
;
1375 struct scsi_cmnd
*scp
;
1381 ccb
= (mbox_ccb_t
*)scb
->ccb
;
1383 sgcnt
= scsi_dma_map(scp
);
1384 BUG_ON(sgcnt
< 0 || sgcnt
> adapter
->sglen
);
1386 // no mapping required if no data to be transferred
1390 scb
->dma_type
= MRAID_DMA_WSG
;
1392 scsi_for_each_sg(scp
, sgl
, sgcnt
, i
) {
1393 ccb
->sgl64
[i
].address
= sg_dma_address(sgl
);
1394 ccb
->sgl64
[i
].length
= sg_dma_len(sgl
);
1397 // Return count of SG nodes
1403 * mbox_post_cmd - issue a mailbox command
1404 * @adapter : controller's soft state
1405 * @scb : command to be issued
1407 * Post the command to the controller if mailbox is available.
1410 mbox_post_cmd(adapter_t
*adapter
, scb_t
*scb
)
1412 mraid_device_t
*raid_dev
= ADAP2RAIDDEV(adapter
);
1416 unsigned long flags
;
1420 ccb
= (mbox_ccb_t
*)scb
->ccb
;
1421 mbox
= raid_dev
->mbox
;
1422 mbox64
= raid_dev
->mbox64
;
1425 * Check for busy mailbox. If it is, return failure - the caller
1426 * should retry later.
1428 spin_lock_irqsave(MAILBOX_LOCK(raid_dev
), flags
);
1430 if (unlikely(mbox
->busy
)) {
1435 } while(mbox
->busy
&& (i
< max_mbox_busy_wait
));
1439 spin_unlock_irqrestore(MAILBOX_LOCK(raid_dev
), flags
);
1446 // Copy this command's mailbox data into "adapter's" mailbox
1447 memcpy((caddr_t
)mbox64
, (caddr_t
)ccb
->mbox64
, 22);
1448 mbox
->cmdid
= scb
->sno
;
1450 adapter
->outstanding_cmds
++;
1452 if (scb
->dma_direction
== PCI_DMA_TODEVICE
)
1453 pci_dma_sync_sg_for_device(adapter
->pdev
,
1454 scsi_sglist(scb
->scp
),
1455 scsi_sg_count(scb
->scp
),
1458 mbox
->busy
= 1; // Set busy
1463 WRINDOOR(raid_dev
, raid_dev
->mbox_dma
| 0x1);
1465 spin_unlock_irqrestore(MAILBOX_LOCK(raid_dev
), flags
);
1472 * megaraid_queue_command - generic queue entry point for all LLDs
1473 * @scp : pointer to the scsi command to be executed
1474 * @done : callback routine to be called after the cmd has be completed
1476 * Queue entry point for mailbox based controllers.
1479 megaraid_queue_command_lck(struct scsi_cmnd
*scp
, void (*done
)(struct scsi_cmnd
*))
1485 adapter
= SCP2ADAPTER(scp
);
1486 scp
->scsi_done
= done
;
1490 * Allocate and build a SCB request
1491 * if_busy flag will be set if megaraid_mbox_build_cmd() command could
1492 * not allocate scb. We will return non-zero status in that case.
1493 * NOTE: scb can be null even though certain commands completed
1494 * successfully, e.g., MODE_SENSE and TEST_UNIT_READY, it would
1495 * return 0 in that case, and we would do the callback right away.
1498 scb
= megaraid_mbox_build_cmd(adapter
, scp
, &if_busy
);
1499 if (!scb
) { // command already completed
1504 megaraid_mbox_runpendq(adapter
, scb
);
1508 static DEF_SCSI_QCMD(megaraid_queue_command
)
1511 * megaraid_mbox_build_cmd - transform the mid-layer scsi commands
1512 * @adapter : controller's soft state
1513 * @scp : mid-layer scsi command pointer
1514 * @busy : set if request could not be completed because of lack of
1517 * Transform the mid-layer scsi command to megaraid firmware lingua.
1518 * Convert the command issued by mid-layer to format understood by megaraid
1519 * firmware. We also complete certain commands without sending them to firmware.
1522 megaraid_mbox_build_cmd(adapter_t
*adapter
, struct scsi_cmnd
*scp
, int *busy
)
1524 mraid_device_t
*rdev
= ADAP2RAIDDEV(adapter
);
1529 mraid_passthru_t
*pthru
;
1533 char skip
[] = "skipping";
1534 char scan
[] = "scanning";
1539 * Get the appropriate device map for the device this command is
1542 MRAID_GET_DEVICE_MAP(adapter
, scp
, channel
, target
, islogical
);
1545 * Logical drive commands
1548 switch (scp
->cmnd
[0]) {
1549 case TEST_UNIT_READY
:
1551 * Do we support clustering and is the support enabled
1552 * If no, return success always
1555 scp
->result
= (DID_OK
<< 16);
1559 if (!(scb
= megaraid_alloc_scb(adapter
, scp
))) {
1560 scp
->result
= (DID_ERROR
<< 16);
1565 scb
->dma_direction
= scp
->sc_data_direction
;
1566 scb
->dev_channel
= 0xFF;
1567 scb
->dev_target
= target
;
1568 ccb
= (mbox_ccb_t
*)scb
->ccb
;
1571 * The command id will be provided by the command
1574 ccb
->raw_mbox
[0] = CLUSTER_CMD
;
1575 ccb
->raw_mbox
[2] = RESERVATION_STATUS
;
1576 ccb
->raw_mbox
[3] = target
;
1582 struct scatterlist
*sgl
;
1585 sgl
= scsi_sglist(scp
);
1587 vaddr
= (caddr_t
) sg_virt(&sgl
[0]);
1589 memset(vaddr
, 0, scp
->cmnd
[4]);
1592 con_log(CL_ANN
, (KERN_WARNING
1593 "megaraid mailbox: invalid sg:%d\n",
1597 scp
->result
= (DID_OK
<< 16);
1602 * Display the channel scan for logical drives
1603 * Do not display scan for a channel if already done.
1605 if (!(rdev
->last_disp
& (1L << SCP2CHANNEL(scp
)))) {
1607 con_log(CL_ANN
, (KERN_INFO
1608 "scsi[%d]: scanning scsi channel %d",
1609 adapter
->host
->host_no
,
1613 " [virtual] for logical drives\n"));
1615 rdev
->last_disp
|= (1L << SCP2CHANNEL(scp
));
1618 if (scp
->cmnd
[1] & MEGA_SCSI_INQ_EVPD
) {
1619 scp
->sense_buffer
[0] = 0x70;
1620 scp
->sense_buffer
[2] = ILLEGAL_REQUEST
;
1621 scp
->sense_buffer
[12] = MEGA_INVALID_FIELD_IN_CDB
;
1622 scp
->result
= CHECK_CONDITION
<< 1;
1630 * Do not allow LUN > 0 for logical drives and
1631 * requests for more than 40 logical drives
1634 scp
->result
= (DID_BAD_TARGET
<< 16);
1637 if ((target
% 0x80) >= MAX_LOGICAL_DRIVES_40LD
) {
1638 scp
->result
= (DID_BAD_TARGET
<< 16);
1643 /* Allocate a SCB and initialize passthru */
1644 if (!(scb
= megaraid_alloc_scb(adapter
, scp
))) {
1645 scp
->result
= (DID_ERROR
<< 16);
1650 ccb
= (mbox_ccb_t
*)scb
->ccb
;
1651 scb
->dev_channel
= 0xFF;
1652 scb
->dev_target
= target
;
1655 mbox64
= ccb
->mbox64
;
1659 pthru
->reqsenselen
= 14;
1660 pthru
->islogical
= 1;
1661 pthru
->logdrv
= target
;
1662 pthru
->cdblen
= scp
->cmd_len
;
1663 memcpy(pthru
->cdb
, scp
->cmnd
, scp
->cmd_len
);
1665 mbox
->cmd
= MBOXCMD_PASSTHRU64
;
1666 scb
->dma_direction
= scp
->sc_data_direction
;
1668 pthru
->dataxferlen
= scsi_bufflen(scp
);
1669 pthru
->dataxferaddr
= ccb
->sgl_dma_h
;
1670 pthru
->numsge
= megaraid_mbox_mksgl(adapter
,
1673 mbox
->xferaddr
= 0xFFFFFFFF;
1674 mbox64
->xferaddr_lo
= (uint32_t )ccb
->pthru_dma_h
;
1675 mbox64
->xferaddr_hi
= 0;
1687 * Allocate a SCB and initialize mailbox
1689 if (!(scb
= megaraid_alloc_scb(adapter
, scp
))) {
1690 scp
->result
= (DID_ERROR
<< 16);
1694 ccb
= (mbox_ccb_t
*)scb
->ccb
;
1695 scb
->dev_channel
= 0xFF;
1696 scb
->dev_target
= target
;
1698 mbox64
= ccb
->mbox64
;
1699 mbox
->logdrv
= target
;
1702 * A little HACK: 2nd bit is zero for all scsi read
1703 * commands and is set for all scsi write commands
1705 mbox
->cmd
= (scp
->cmnd
[0] & 0x02) ? MBOXCMD_LWRITE64
:
1709 * 6-byte READ(0x08) or WRITE(0x0A) cdb
1711 if (scp
->cmd_len
== 6) {
1712 mbox
->numsectors
= (uint32_t)scp
->cmnd
[4];
1714 ((uint32_t)scp
->cmnd
[1] << 16) |
1715 ((uint32_t)scp
->cmnd
[2] << 8) |
1716 (uint32_t)scp
->cmnd
[3];
1718 mbox
->lba
&= 0x1FFFFF;
1722 * 10-byte READ(0x28) or WRITE(0x2A) cdb
1724 else if (scp
->cmd_len
== 10) {
1726 (uint32_t)scp
->cmnd
[8] |
1727 ((uint32_t)scp
->cmnd
[7] << 8);
1729 ((uint32_t)scp
->cmnd
[2] << 24) |
1730 ((uint32_t)scp
->cmnd
[3] << 16) |
1731 ((uint32_t)scp
->cmnd
[4] << 8) |
1732 (uint32_t)scp
->cmnd
[5];
1736 * 12-byte READ(0xA8) or WRITE(0xAA) cdb
1738 else if (scp
->cmd_len
== 12) {
1740 ((uint32_t)scp
->cmnd
[2] << 24) |
1741 ((uint32_t)scp
->cmnd
[3] << 16) |
1742 ((uint32_t)scp
->cmnd
[4] << 8) |
1743 (uint32_t)scp
->cmnd
[5];
1746 ((uint32_t)scp
->cmnd
[6] << 24) |
1747 ((uint32_t)scp
->cmnd
[7] << 16) |
1748 ((uint32_t)scp
->cmnd
[8] << 8) |
1749 (uint32_t)scp
->cmnd
[9];
1752 con_log(CL_ANN
, (KERN_WARNING
1753 "megaraid: unsupported CDB length\n"));
1755 megaraid_dealloc_scb(adapter
, scb
);
1757 scp
->result
= (DID_ERROR
<< 16);
1761 scb
->dma_direction
= scp
->sc_data_direction
;
1763 // Calculate Scatter-Gather info
1764 mbox64
->xferaddr_lo
= (uint32_t )ccb
->sgl_dma_h
;
1765 mbox
->numsge
= megaraid_mbox_mksgl(adapter
,
1767 mbox
->xferaddr
= 0xFFFFFFFF;
1768 mbox64
->xferaddr_hi
= 0;
1775 * Do we support clustering and is the support enabled
1778 scp
->result
= (DID_BAD_TARGET
<< 16);
1783 * Allocate a SCB and initialize mailbox
1785 if (!(scb
= megaraid_alloc_scb(adapter
, scp
))) {
1786 scp
->result
= (DID_ERROR
<< 16);
1791 ccb
= (mbox_ccb_t
*)scb
->ccb
;
1792 scb
->dev_channel
= 0xFF;
1793 scb
->dev_target
= target
;
1794 ccb
->raw_mbox
[0] = CLUSTER_CMD
;
1795 ccb
->raw_mbox
[2] = (scp
->cmnd
[0] == RESERVE
) ?
1796 RESERVE_LD
: RELEASE_LD
;
1798 ccb
->raw_mbox
[3] = target
;
1799 scb
->dma_direction
= scp
->sc_data_direction
;
1804 scp
->result
= (DID_BAD_TARGET
<< 16);
1808 else { // Passthru device commands
1810 // Do not allow access to target id > 15 or LUN > 7
1811 if (target
> 15 || SCP2LUN(scp
) > 7) {
1812 scp
->result
= (DID_BAD_TARGET
<< 16);
1816 // if fast load option was set and scan for last device is
1817 // over, reset the fast_load flag so that during a possible
1818 // next scan, devices can be made available
1819 if (rdev
->fast_load
&& (target
== 15) &&
1820 (SCP2CHANNEL(scp
) == adapter
->max_channel
-1)) {
1822 con_log(CL_ANN
, (KERN_INFO
1823 "megaraid[%d]: physical device scan re-enabled\n",
1824 adapter
->host
->host_no
));
1825 rdev
->fast_load
= 0;
1829 * Display the channel scan for physical devices
1831 if (!(rdev
->last_disp
& (1L << SCP2CHANNEL(scp
)))) {
1833 ss
= rdev
->fast_load
? skip
: scan
;
1835 con_log(CL_ANN
, (KERN_INFO
1836 "scsi[%d]: %s scsi channel %d [Phy %d]",
1837 adapter
->host
->host_no
, ss
, SCP2CHANNEL(scp
),
1841 " for non-raid devices\n"));
1843 rdev
->last_disp
|= (1L << SCP2CHANNEL(scp
));
1846 // disable channel sweep if fast load option given
1847 if (rdev
->fast_load
) {
1848 scp
->result
= (DID_BAD_TARGET
<< 16);
1852 // Allocate a SCB and initialize passthru
1853 if (!(scb
= megaraid_alloc_scb(adapter
, scp
))) {
1854 scp
->result
= (DID_ERROR
<< 16);
1859 ccb
= (mbox_ccb_t
*)scb
->ccb
;
1860 scb
->dev_channel
= channel
;
1861 scb
->dev_target
= target
;
1862 scb
->dma_direction
= scp
->sc_data_direction
;
1864 mbox64
= ccb
->mbox64
;
1866 // Does this firmware support extended CDBs
1867 if (adapter
->max_cdb_sz
== 16) {
1868 mbox
->cmd
= MBOXCMD_EXTPTHRU
;
1870 megaraid_mbox_prepare_epthru(adapter
, scb
, scp
);
1872 mbox64
->xferaddr_lo
= (uint32_t)ccb
->epthru_dma_h
;
1873 mbox64
->xferaddr_hi
= 0;
1874 mbox
->xferaddr
= 0xFFFFFFFF;
1877 mbox
->cmd
= MBOXCMD_PASSTHRU64
;
1879 megaraid_mbox_prepare_pthru(adapter
, scb
, scp
);
1881 mbox64
->xferaddr_lo
= (uint32_t)ccb
->pthru_dma_h
;
1882 mbox64
->xferaddr_hi
= 0;
1883 mbox
->xferaddr
= 0xFFFFFFFF;
1893 * megaraid_mbox_runpendq - execute commands queued in the pending queue
1894 * @adapter : controller's soft state
1895 * @scb_q : SCB to be queued in the pending list
1897 * Scan the pending list for commands which are not yet issued and try to
1898 * post to the controller. The SCB can be a null pointer, which would indicate
1899 * no SCB to be queue, just try to execute the ones in the pending list.
1901 * NOTE: We do not actually traverse the pending list. The SCBs are plucked
1902 * out from the head of the pending list. If it is successfully issued, the
1903 * next SCB is at the head now.
1906 megaraid_mbox_runpendq(adapter_t
*adapter
, scb_t
*scb_q
)
1909 unsigned long flags
;
1911 spin_lock_irqsave(PENDING_LIST_LOCK(adapter
), flags
);
1914 scb_q
->state
= SCB_PENDQ
;
1915 list_add_tail(&scb_q
->list
, &adapter
->pend_list
);
1918 // if the adapter in not in quiescent mode, post the commands to FW
1919 if (adapter
->quiescent
) {
1920 spin_unlock_irqrestore(PENDING_LIST_LOCK(adapter
), flags
);
1924 while (!list_empty(&adapter
->pend_list
)) {
1926 assert_spin_locked(PENDING_LIST_LOCK(adapter
));
1928 scb
= list_entry(adapter
->pend_list
.next
, scb_t
, list
);
1930 // remove the scb from the pending list and try to
1931 // issue. If we are unable to issue it, put back in
1932 // the pending list and return
1934 list_del_init(&scb
->list
);
1936 spin_unlock_irqrestore(PENDING_LIST_LOCK(adapter
), flags
);
1938 // if mailbox was busy, return SCB back to pending
1939 // list. Make sure to add at the head, since that's
1940 // where it would have been removed from
1942 scb
->state
= SCB_ISSUED
;
1944 if (mbox_post_cmd(adapter
, scb
) != 0) {
1946 spin_lock_irqsave(PENDING_LIST_LOCK(adapter
), flags
);
1948 scb
->state
= SCB_PENDQ
;
1950 list_add(&scb
->list
, &adapter
->pend_list
);
1952 spin_unlock_irqrestore(PENDING_LIST_LOCK(adapter
),
1958 spin_lock_irqsave(PENDING_LIST_LOCK(adapter
), flags
);
1961 spin_unlock_irqrestore(PENDING_LIST_LOCK(adapter
), flags
);
1969 * megaraid_mbox_prepare_pthru - prepare a command for physical devices
1970 * @adapter : pointer to controller's soft state
1971 * @scb : scsi control block
1972 * @scp : scsi command from the mid-layer
1974 * Prepare a command for the scsi physical devices.
1977 megaraid_mbox_prepare_pthru(adapter_t
*adapter
, scb_t
*scb
,
1978 struct scsi_cmnd
*scp
)
1981 mraid_passthru_t
*pthru
;
1985 ccb
= (mbox_ccb_t
*)scb
->ccb
;
1987 channel
= scb
->dev_channel
;
1988 target
= scb
->dev_target
;
1990 // 0=6sec, 1=60sec, 2=10min, 3=3hrs, 4=NO timeout
1993 pthru
->islogical
= 0;
1995 pthru
->target
= (channel
<< 4) | target
;
1996 pthru
->logdrv
= SCP2LUN(scp
);
1997 pthru
->reqsenselen
= 14;
1998 pthru
->cdblen
= scp
->cmd_len
;
2000 memcpy(pthru
->cdb
, scp
->cmnd
, scp
->cmd_len
);
2002 if (scsi_bufflen(scp
)) {
2003 pthru
->dataxferlen
= scsi_bufflen(scp
);
2004 pthru
->dataxferaddr
= ccb
->sgl_dma_h
;
2005 pthru
->numsge
= megaraid_mbox_mksgl(adapter
, scb
);
2008 pthru
->dataxferaddr
= 0;
2009 pthru
->dataxferlen
= 0;
2017 * megaraid_mbox_prepare_epthru - prepare a command for physical devices
2018 * @adapter : pointer to controller's soft state
2019 * @scb : scsi control block
2020 * @scp : scsi command from the mid-layer
2022 * Prepare a command for the scsi physical devices. This routine prepares
2023 * commands for devices which can take extended CDBs (>10 bytes).
2026 megaraid_mbox_prepare_epthru(adapter_t
*adapter
, scb_t
*scb
,
2027 struct scsi_cmnd
*scp
)
2030 mraid_epassthru_t
*epthru
;
2034 ccb
= (mbox_ccb_t
*)scb
->ccb
;
2035 epthru
= ccb
->epthru
;
2036 channel
= scb
->dev_channel
;
2037 target
= scb
->dev_target
;
2039 // 0=6sec, 1=60sec, 2=10min, 3=3hrs, 4=NO timeout
2040 epthru
->timeout
= 4;
2042 epthru
->islogical
= 0;
2043 epthru
->channel
= 0;
2044 epthru
->target
= (channel
<< 4) | target
;
2045 epthru
->logdrv
= SCP2LUN(scp
);
2046 epthru
->reqsenselen
= 14;
2047 epthru
->cdblen
= scp
->cmd_len
;
2049 memcpy(epthru
->cdb
, scp
->cmnd
, scp
->cmd_len
);
2051 if (scsi_bufflen(scp
)) {
2052 epthru
->dataxferlen
= scsi_bufflen(scp
);
2053 epthru
->dataxferaddr
= ccb
->sgl_dma_h
;
2054 epthru
->numsge
= megaraid_mbox_mksgl(adapter
, scb
);
2057 epthru
->dataxferaddr
= 0;
2058 epthru
->dataxferlen
= 0;
2066 * megaraid_ack_sequence - interrupt ack sequence for memory mapped HBAs
2067 * @adapter : controller's soft state
2069 * Interrupt acknowledgement sequence for memory mapped HBAs. Find out the
2070 * completed command and put them on the completed list for later processing.
2072 * Returns: 1 if the interrupt is valid, 0 otherwise
2075 megaraid_ack_sequence(adapter_t
*adapter
)
2077 mraid_device_t
*raid_dev
= ADAP2RAIDDEV(adapter
);
2081 uint8_t completed
[MBOX_MAX_FIRMWARE_STATUS
];
2082 struct list_head clist
;
2085 unsigned long flags
;
2089 mbox
= raid_dev
->mbox
;
2091 // move the SCBs from the firmware completed array to our local list
2092 INIT_LIST_HEAD(&clist
);
2094 // loop till F/W has more commands for us to complete
2096 spin_lock_irqsave(MAILBOX_LOCK(raid_dev
), flags
);
2099 * Check if a valid interrupt is pending. If found, force the
2100 * interrupt line low.
2102 dword
= RDOUTDOOR(raid_dev
);
2103 if (dword
!= 0x10001234) break;
2107 WROUTDOOR(raid_dev
, 0x10001234);
2110 // wait for valid numstatus to post
2111 for (i
= 0; i
< 0xFFFFF; i
++) {
2112 if (mbox
->numstatus
!= 0xFF) {
2113 nstatus
= mbox
->numstatus
;
2118 mbox
->numstatus
= 0xFF;
2120 adapter
->outstanding_cmds
-= nstatus
;
2122 for (i
= 0; i
< nstatus
; i
++) {
2124 // wait for valid command index to post
2125 for (j
= 0; j
< 0xFFFFF; j
++) {
2126 if (mbox
->completed
[i
] != 0xFF) break;
2129 completed
[i
] = mbox
->completed
[i
];
2130 mbox
->completed
[i
] = 0xFF;
2132 if (completed
[i
] == 0xFF) {
2133 con_log(CL_ANN
, (KERN_CRIT
2134 "megaraid: command posting timed out\n"));
2140 // Get SCB associated with this command id
2141 if (completed
[i
] >= MBOX_MAX_SCSI_CMDS
) {
2143 scb
= adapter
->uscb_list
+ (completed
[i
] -
2144 MBOX_MAX_SCSI_CMDS
);
2148 scb
= adapter
->kscb_list
+ completed
[i
];
2151 scb
->status
= mbox
->status
;
2152 list_add_tail(&scb
->list
, &clist
);
2155 // Acknowledge interrupt
2156 WRINDOOR(raid_dev
, 0x02);
2160 spin_unlock_irqrestore(MAILBOX_LOCK(raid_dev
), flags
);
2163 // put the completed commands in the completed list. DPC would
2164 // complete these commands later
2165 spin_lock_irqsave(COMPLETED_LIST_LOCK(adapter
), flags
);
2167 list_splice(&clist
, &adapter
->completed_list
);
2169 spin_unlock_irqrestore(COMPLETED_LIST_LOCK(adapter
), flags
);
2172 // schedule the DPC if there is some work for it
2174 tasklet_schedule(&adapter
->dpc_h
);
2181 * megaraid_isr - isr for memory based mailbox based controllers
2183 * @devp : pointer to our soft state
2185 * Interrupt service routine for memory-mapped mailbox controllers.
2188 megaraid_isr(int irq
, void *devp
)
2190 adapter_t
*adapter
= devp
;
2193 handled
= megaraid_ack_sequence(adapter
);
2195 /* Loop through any pending requests */
2196 if (!adapter
->quiescent
) {
2197 megaraid_mbox_runpendq(adapter
, NULL
);
2200 return IRQ_RETVAL(handled
);
2205 * megaraid_mbox_sync_scb - sync kernel buffers
2206 * @adapter : controller's soft state
2207 * @scb : pointer to the resource packet
2209 * DMA sync if required.
2212 megaraid_mbox_sync_scb(adapter_t
*adapter
, scb_t
*scb
)
2216 ccb
= (mbox_ccb_t
*)scb
->ccb
;
2218 if (scb
->dma_direction
== PCI_DMA_FROMDEVICE
)
2219 pci_dma_sync_sg_for_cpu(adapter
->pdev
,
2220 scsi_sglist(scb
->scp
),
2221 scsi_sg_count(scb
->scp
),
2222 PCI_DMA_FROMDEVICE
);
2224 scsi_dma_unmap(scb
->scp
);
2230 * megaraid_mbox_dpc - the tasklet to complete the commands from completed list
2231 * @devp : pointer to HBA soft state
2233 * Pick up the commands from the completed list and send back to the owners.
2234 * This is a reentrant function and does not assume any locks are held while
2235 * it is being called.
2238 megaraid_mbox_dpc(unsigned long devp
)
2240 adapter_t
*adapter
= (adapter_t
*)devp
;
2241 mraid_device_t
*raid_dev
;
2242 struct list_head clist
;
2243 struct scatterlist
*sgl
;
2246 struct scsi_cmnd
*scp
;
2247 mraid_passthru_t
*pthru
;
2248 mraid_epassthru_t
*epthru
;
2254 unsigned long flags
;
2260 if (!adapter
) return;
2262 raid_dev
= ADAP2RAIDDEV(adapter
);
2264 // move the SCBs from the completed list to our local list
2265 INIT_LIST_HEAD(&clist
);
2267 spin_lock_irqsave(COMPLETED_LIST_LOCK(adapter
), flags
);
2269 list_splice_init(&adapter
->completed_list
, &clist
);
2271 spin_unlock_irqrestore(COMPLETED_LIST_LOCK(adapter
), flags
);
2274 list_for_each_entry_safe(scb
, tmp
, &clist
, list
) {
2276 status
= scb
->status
;
2278 ccb
= (mbox_ccb_t
*)scb
->ccb
;
2280 epthru
= ccb
->epthru
;
2283 // Make sure f/w has completed a valid command
2284 if (scb
->state
!= SCB_ISSUED
) {
2285 con_log(CL_ANN
, (KERN_CRIT
2286 "megaraid critical err: invalid command %d:%d:%p\n",
2287 scb
->sno
, scb
->state
, scp
));
2289 continue; // Must never happen!
2292 // check for the management command and complete it right away
2293 if (scb
->sno
>= MBOX_MAX_SCSI_CMDS
) {
2294 scb
->state
= SCB_FREE
;
2295 scb
->status
= status
;
2297 // remove from local clist
2298 list_del_init(&scb
->list
);
2300 kioc
= (uioc_t
*)scb
->gp
;
2303 megaraid_mbox_mm_done(adapter
, scb
);
2308 // Was an abort issued for this command earlier
2309 if (scb
->state
& SCB_ABORT
) {
2310 con_log(CL_ANN
, (KERN_NOTICE
2311 "megaraid: aborted cmd [%x] completed\n",
2316 * If the inquiry came of a disk drive which is not part of
2317 * any RAID array, expose it to the kernel. For this to be
2318 * enabled, user must set the "megaraid_expose_unconf_disks"
2319 * flag to 1 by specifying it on module parameter list.
2320 * This would enable data migration off drives from other
2323 islogical
= MRAID_IS_LOGICAL(adapter
, scp
);
2324 if (scp
->cmnd
[0] == INQUIRY
&& status
== 0 && islogical
== 0
2325 && IS_RAID_CH(raid_dev
, scb
->dev_channel
)) {
2327 sgl
= scsi_sglist(scp
);
2329 c
= *(unsigned char *) sg_virt(&sgl
[0]);
2331 con_log(CL_ANN
, (KERN_WARNING
2332 "megaraid mailbox: invalid sg:%d\n",
2337 if ((c
& 0x1F ) == TYPE_DISK
) {
2338 pdev_index
= (scb
->dev_channel
* 16) +
2341 raid_dev
->pdrv_state
[pdev_index
] & 0x0F;
2343 if (pdev_state
== PDRV_ONLINE
||
2344 pdev_state
== PDRV_FAILED
||
2345 pdev_state
== PDRV_RBLD
||
2346 pdev_state
== PDRV_HOTSPARE
||
2347 megaraid_expose_unconf_disks
== 0) {
2354 // Convert MegaRAID status to Linux error code
2359 scp
->result
= (DID_OK
<< 16);
2364 /* set sense_buffer and result fields */
2365 if (mbox
->cmd
== MBOXCMD_PASSTHRU
||
2366 mbox
->cmd
== MBOXCMD_PASSTHRU64
) {
2368 memcpy(scp
->sense_buffer
, pthru
->reqsensearea
,
2371 scp
->result
= DRIVER_SENSE
<< 24 |
2372 DID_OK
<< 16 | CHECK_CONDITION
<< 1;
2375 if (mbox
->cmd
== MBOXCMD_EXTPTHRU
) {
2377 memcpy(scp
->sense_buffer
,
2378 epthru
->reqsensearea
, 14);
2380 scp
->result
= DRIVER_SENSE
<< 24 |
2382 CHECK_CONDITION
<< 1;
2384 scp
->sense_buffer
[0] = 0x70;
2385 scp
->sense_buffer
[2] = ABORTED_COMMAND
;
2386 scp
->result
= CHECK_CONDITION
<< 1;
2393 scp
->result
= DID_BUS_BUSY
<< 16 | status
;
2399 * If TEST_UNIT_READY fails, we know RESERVATION_STATUS
2402 if (scp
->cmnd
[0] == TEST_UNIT_READY
) {
2403 scp
->result
= DID_ERROR
<< 16 |
2404 RESERVATION_CONFLICT
<< 1;
2408 * Error code returned is 1 if Reserve or Release
2409 * failed or the input parameter is invalid
2411 if (status
== 1 && (scp
->cmnd
[0] == RESERVE
||
2412 scp
->cmnd
[0] == RELEASE
)) {
2414 scp
->result
= DID_ERROR
<< 16 |
2415 RESERVATION_CONFLICT
<< 1;
2418 scp
->result
= DID_BAD_TARGET
<< 16 | status
;
2422 // print a debug message for all failed commands
2424 megaraid_mbox_display_scb(adapter
, scb
);
2427 // Free our internal resources and call the mid-layer callback
2429 megaraid_mbox_sync_scb(adapter
, scb
);
2431 // remove from local clist
2432 list_del_init(&scb
->list
);
2434 // put back in free list
2435 megaraid_dealloc_scb(adapter
, scb
);
2437 // send the scsi packet back to kernel
2438 scp
->scsi_done(scp
);
2446 * megaraid_abort_handler - abort the scsi command
2447 * @scp : command to be aborted
2449 * Abort a previous SCSI request. Only commands on the pending list can be
2450 * aborted. All the commands issued to the F/W must complete.
2453 megaraid_abort_handler(struct scsi_cmnd
*scp
)
2456 mraid_device_t
*raid_dev
;
2460 unsigned long flags
;
2464 adapter
= SCP2ADAPTER(scp
);
2465 raid_dev
= ADAP2RAIDDEV(adapter
);
2467 con_log(CL_ANN
, (KERN_WARNING
2468 "megaraid: aborting cmd=%x <c=%d t=%d l=%d>\n",
2469 scp
->cmnd
[0], SCP2CHANNEL(scp
),
2470 SCP2TARGET(scp
), SCP2LUN(scp
)));
2472 // If FW has stopped responding, simply return failure
2473 if (raid_dev
->hw_error
) {
2474 con_log(CL_ANN
, (KERN_NOTICE
2475 "megaraid: hw error, not aborting\n"));
2479 // There might a race here, where the command was completed by the
2480 // firmware and now it is on the completed list. Before we could
2481 // complete the command to the kernel in dpc, the abort came.
2482 // Find out if this is the case to avoid the race.
2484 spin_lock_irqsave(COMPLETED_LIST_LOCK(adapter
), flags
);
2485 list_for_each_entry_safe(scb
, tmp
, &adapter
->completed_list
, list
) {
2487 if (scb
->scp
== scp
) { // Found command
2489 list_del_init(&scb
->list
); // from completed list
2491 con_log(CL_ANN
, (KERN_WARNING
2492 "megaraid: %d[%d:%d], abort from completed list\n",
2493 scb
->sno
, scb
->dev_channel
, scb
->dev_target
));
2495 scp
->result
= (DID_ABORT
<< 16);
2496 scp
->scsi_done(scp
);
2498 megaraid_dealloc_scb(adapter
, scb
);
2500 spin_unlock_irqrestore(COMPLETED_LIST_LOCK(adapter
),
2506 spin_unlock_irqrestore(COMPLETED_LIST_LOCK(adapter
), flags
);
2509 // Find out if this command is still on the pending list. If it is and
2510 // was never issued, abort and return success. If the command is owned
2511 // by the firmware, we must wait for it to complete by the FW.
2512 spin_lock_irqsave(PENDING_LIST_LOCK(adapter
), flags
);
2513 list_for_each_entry_safe(scb
, tmp
, &adapter
->pend_list
, list
) {
2515 if (scb
->scp
== scp
) { // Found command
2517 list_del_init(&scb
->list
); // from pending list
2519 ASSERT(!(scb
->state
& SCB_ISSUED
));
2521 con_log(CL_ANN
, (KERN_WARNING
2522 "megaraid abort: [%d:%d], driver owner\n",
2523 scb
->dev_channel
, scb
->dev_target
));
2525 scp
->result
= (DID_ABORT
<< 16);
2526 scp
->scsi_done(scp
);
2528 megaraid_dealloc_scb(adapter
, scb
);
2530 spin_unlock_irqrestore(PENDING_LIST_LOCK(adapter
),
2536 spin_unlock_irqrestore(PENDING_LIST_LOCK(adapter
), flags
);
2539 // Check do we even own this command, in which case this would be
2540 // owned by the firmware. The only way to locate the FW scb is to
2541 // traverse through the list of all SCB, since driver does not
2542 // maintain these SCBs on any list
2544 spin_lock_irq(&adapter
->lock
);
2545 for (i
= 0; i
< MBOX_MAX_SCSI_CMDS
; i
++) {
2546 scb
= adapter
->kscb_list
+ i
;
2548 if (scb
->scp
== scp
) {
2552 if (!(scb
->state
& SCB_ISSUED
)) {
2553 con_log(CL_ANN
, (KERN_WARNING
2554 "megaraid abort: %d[%d:%d], invalid state\n",
2555 scb
->sno
, scb
->dev_channel
, scb
->dev_target
));
2559 con_log(CL_ANN
, (KERN_WARNING
2560 "megaraid abort: %d[%d:%d], fw owner\n",
2561 scb
->sno
, scb
->dev_channel
, scb
->dev_target
));
2565 spin_unlock_irq(&adapter
->lock
);
2568 con_log(CL_ANN
, (KERN_WARNING
"megaraid abort: do now own\n"));
2570 // FIXME: Should there be a callback for this command?
2574 // We cannot actually abort a command owned by firmware, return
2575 // failure and wait for reset. In host reset handler, we will find out
2576 // if the HBA is still live
2581 * megaraid_reset_handler - device reset handler for mailbox based driver
2582 * @scp : reference command
2584 * Reset handler for the mailbox based controller. First try to find out if
2585 * the FW is still live, in which case the outstanding commands counter mut go
2586 * down to 0. If that happens, also issue the reservation reset command to
2587 * relinquish (possible) reservations on the logical drives connected to this
2591 megaraid_reset_handler(struct scsi_cmnd
*scp
)
2596 mraid_device_t
*raid_dev
;
2597 unsigned long flags
;
2598 uint8_t raw_mbox
[sizeof(mbox_t
)];
2600 int recovery_window
;
2605 adapter
= SCP2ADAPTER(scp
);
2606 raid_dev
= ADAP2RAIDDEV(adapter
);
2608 // return failure if adapter is not responding
2609 if (raid_dev
->hw_error
) {
2610 con_log(CL_ANN
, (KERN_NOTICE
2611 "megaraid: hw error, cannot reset\n"));
2616 // Under exceptional conditions, FW can take up to 3 minutes to
2617 // complete command processing. Wait for additional 2 minutes for the
2618 // pending commands counter to go down to 0. If it doesn't, let the
2619 // controller be marked offline
2620 // Also, reset all the commands currently owned by the driver
2621 spin_lock_irqsave(PENDING_LIST_LOCK(adapter
), flags
);
2622 list_for_each_entry_safe(scb
, tmp
, &adapter
->pend_list
, list
) {
2623 list_del_init(&scb
->list
); // from pending list
2625 if (scb
->sno
>= MBOX_MAX_SCSI_CMDS
) {
2626 con_log(CL_ANN
, (KERN_WARNING
2627 "megaraid: IOCTL packet with %d[%d:%d] being reset\n",
2628 scb
->sno
, scb
->dev_channel
, scb
->dev_target
));
2632 kioc
= (uioc_t
*)scb
->gp
;
2633 kioc
->status
= -EFAULT
;
2635 megaraid_mbox_mm_done(adapter
, scb
);
2637 if (scb
->scp
== scp
) { // Found command
2638 con_log(CL_ANN
, (KERN_WARNING
2639 "megaraid: %d[%d:%d], reset from pending list\n",
2640 scb
->sno
, scb
->dev_channel
, scb
->dev_target
));
2642 con_log(CL_ANN
, (KERN_WARNING
2643 "megaraid: IO packet with %d[%d:%d] being reset\n",
2644 scb
->sno
, scb
->dev_channel
, scb
->dev_target
));
2647 scb
->scp
->result
= (DID_RESET
<< 16);
2648 scb
->scp
->scsi_done(scb
->scp
);
2650 megaraid_dealloc_scb(adapter
, scb
);
2653 spin_unlock_irqrestore(PENDING_LIST_LOCK(adapter
), flags
);
2655 if (adapter
->outstanding_cmds
) {
2656 con_log(CL_ANN
, (KERN_NOTICE
2657 "megaraid: %d outstanding commands. Max wait %d sec\n",
2658 adapter
->outstanding_cmds
,
2659 (MBOX_RESET_WAIT
+ MBOX_RESET_EXT_WAIT
)));
2662 recovery_window
= MBOX_RESET_WAIT
+ MBOX_RESET_EXT_WAIT
;
2664 recovering
= adapter
->outstanding_cmds
;
2666 for (i
= 0; i
< recovery_window
; i
++) {
2668 megaraid_ack_sequence(adapter
);
2670 // print a message once every 5 seconds only
2673 "megaraid mbox: Wait for %d commands to complete:%d\n",
2674 adapter
->outstanding_cmds
,
2675 (MBOX_RESET_WAIT
+ MBOX_RESET_EXT_WAIT
) - i
));
2678 // bailout if no recovery happened in reset time
2679 if (adapter
->outstanding_cmds
== 0) {
2686 spin_lock(&adapter
->lock
);
2688 // If still outstanding commands, bail out
2689 if (adapter
->outstanding_cmds
) {
2690 con_log(CL_ANN
, (KERN_WARNING
2691 "megaraid mbox: critical hardware error!\n"));
2693 raid_dev
->hw_error
= 1;
2699 con_log(CL_ANN
, (KERN_NOTICE
2700 "megaraid mbox: reset sequence completed successfully\n"));
2704 // If the controller supports clustering, reset reservations
2710 // clear reservations if any
2711 raw_mbox
[0] = CLUSTER_CMD
;
2712 raw_mbox
[2] = RESET_RESERVATIONS
;
2715 if (mbox_post_sync_cmd_fast(adapter
, raw_mbox
) == 0) {
2717 (KERN_INFO
"megaraid: reservation reset\n"));
2721 con_log(CL_ANN
, (KERN_WARNING
2722 "megaraid: reservation reset failed\n"));
2726 spin_unlock(&adapter
->lock
);
2731 * START: internal commands library
2733 * This section of the driver has the common routine used by the driver and
2734 * also has all the FW routines
2738 * mbox_post_sync_cmd() - blocking command to the mailbox based controllers
2739 * @adapter : controller's soft state
2740 * @raw_mbox : the mailbox
2742 * Issue a scb in synchronous and non-interrupt mode for mailbox based
2746 mbox_post_sync_cmd(adapter_t
*adapter
, uint8_t raw_mbox
[])
2748 mraid_device_t
*raid_dev
= ADAP2RAIDDEV(adapter
);
2755 mbox64
= raid_dev
->mbox64
;
2756 mbox
= raid_dev
->mbox
;
2759 * Wait until mailbox is free
2761 if (megaraid_busywait_mbox(raid_dev
) != 0)
2762 goto blocked_mailbox
;
2765 * Copy mailbox data into host structure
2767 memcpy((caddr_t
)mbox
, (caddr_t
)raw_mbox
, 16);
2772 mbox
->numstatus
= 0xFF;
2773 mbox
->status
= 0xFF;
2776 WRINDOOR(raid_dev
, raid_dev
->mbox_dma
| 0x1);
2778 // wait for maximum 1 second for status to post. If the status is not
2779 // available within 1 second, assume FW is initializing and wait
2780 // for an extended amount of time
2781 if (mbox
->numstatus
== 0xFF) { // status not yet available
2784 for (i
= 0; mbox
->numstatus
== 0xFF && i
< 1000; i
++) {
2791 con_log(CL_ANN
, (KERN_NOTICE
2792 "megaraid mailbox: wait for FW to boot "));
2794 for (i
= 0; (mbox
->numstatus
== 0xFF) &&
2795 (i
< MBOX_RESET_WAIT
); i
++) {
2797 con_log(CL_ANN
, ("\b\b\b\b\b[%03d]",
2798 MBOX_RESET_WAIT
- i
));
2802 if (i
== MBOX_RESET_WAIT
) {
2805 "\nmegaraid mailbox: status not available\n"));
2809 con_log(CL_ANN
, ("\b\b\b\b\b[ok] \n"));
2813 // wait for maximum 1 second for poll semaphore
2814 if (mbox
->poll
!= 0x77) {
2817 for (i
= 0; (mbox
->poll
!= 0x77) && (i
< 1000); i
++) {
2823 con_log(CL_ANN
, (KERN_WARNING
2824 "megaraid mailbox: could not get poll semaphore\n"));
2829 WRINDOOR(raid_dev
, raid_dev
->mbox_dma
| 0x2);
2832 // wait for maximum 1 second for acknowledgement
2833 if (RDINDOOR(raid_dev
) & 0x2) {
2836 for (i
= 0; (RDINDOOR(raid_dev
) & 0x2) && (i
< 1000); i
++) {
2842 con_log(CL_ANN
, (KERN_WARNING
2843 "megaraid mailbox: could not acknowledge\n"));
2850 status
= mbox
->status
;
2852 // invalidate the completed command id array. After command
2853 // completion, firmware would write the valid id.
2854 mbox
->numstatus
= 0xFF;
2855 mbox
->status
= 0xFF;
2856 for (i
= 0; i
< MBOX_MAX_FIRMWARE_STATUS
; i
++) {
2857 mbox
->completed
[i
] = 0xFF;
2864 con_log(CL_ANN
, (KERN_WARNING
"megaraid: blocked mailbox\n") );
2870 * mbox_post_sync_cmd_fast - blocking command to the mailbox based controllers
2871 * @adapter : controller's soft state
2872 * @raw_mbox : the mailbox
2874 * Issue a scb in synchronous and non-interrupt mode for mailbox based
2875 * controllers. This is a faster version of the synchronous command and
2876 * therefore can be called in interrupt-context as well.
2879 mbox_post_sync_cmd_fast(adapter_t
*adapter
, uint8_t raw_mbox
[])
2881 mraid_device_t
*raid_dev
= ADAP2RAIDDEV(adapter
);
2886 mbox
= raid_dev
->mbox
;
2888 // return immediately if the mailbox is busy
2889 if (mbox
->busy
) return -1;
2891 // Copy mailbox data into host structure
2892 memcpy((caddr_t
)mbox
, (caddr_t
)raw_mbox
, 14);
2897 mbox
->numstatus
= 0xFF;
2898 mbox
->status
= 0xFF;
2901 WRINDOOR(raid_dev
, raid_dev
->mbox_dma
| 0x1);
2903 for (i
= 0; i
< MBOX_SYNC_WAIT_CNT
; i
++) {
2904 if (mbox
->numstatus
!= 0xFF) break;
2906 udelay(MBOX_SYNC_DELAY_200
);
2909 if (i
== MBOX_SYNC_WAIT_CNT
) {
2910 // We may need to re-calibrate the counter
2911 con_log(CL_ANN
, (KERN_CRIT
2912 "megaraid: fast sync command timed out\n"));
2915 WRINDOOR(raid_dev
, raid_dev
->mbox_dma
| 0x2);
2918 return mbox
->status
;
2923 * megaraid_busywait_mbox() - Wait until the controller's mailbox is available
2924 * @raid_dev : RAID device (HBA) soft state
2926 * Wait until the controller's mailbox is available to accept more commands.
2927 * Wait for at most 1 second.
2930 megaraid_busywait_mbox(mraid_device_t
*raid_dev
)
2932 mbox_t
*mbox
= raid_dev
->mbox
;
2937 for (i
= 0; mbox
->busy
&& i
< 1000; i
++)
2941 if (i
< 1000) return 0;
2947 * megaraid_mbox_product_info - some static information about the controller
2948 * @adapter : our soft state
2950 * Issue commands to the controller to grab some parameters required by our
2954 megaraid_mbox_product_info(adapter_t
*adapter
)
2956 mraid_device_t
*raid_dev
= ADAP2RAIDDEV(adapter
);
2958 uint8_t raw_mbox
[sizeof(mbox_t
)];
2959 mraid_pinfo_t
*pinfo
;
2960 dma_addr_t pinfo_dma_h
;
2961 mraid_inquiry3_t
*mraid_inq3
;
2965 memset((caddr_t
)raw_mbox
, 0, sizeof(raw_mbox
));
2966 mbox
= (mbox_t
*)raw_mbox
;
2969 * Issue an ENQUIRY3 command to find out certain adapter parameters,
2970 * e.g., max channels, max commands etc.
2972 pinfo
= pci_zalloc_consistent(adapter
->pdev
, sizeof(mraid_pinfo_t
),
2975 if (pinfo
== NULL
) {
2976 con_log(CL_ANN
, (KERN_WARNING
2977 "megaraid: out of memory, %s %d\n", __func__
,
2983 mbox
->xferaddr
= (uint32_t)adapter
->ibuf_dma_h
;
2984 memset((void *)adapter
->ibuf
, 0, MBOX_IBUF_SIZE
);
2986 raw_mbox
[0] = FC_NEW_CONFIG
;
2987 raw_mbox
[2] = NC_SUBOP_ENQUIRY3
;
2988 raw_mbox
[3] = ENQ3_GET_SOLICITED_FULL
;
2990 // Issue the command
2991 if (mbox_post_sync_cmd(adapter
, raw_mbox
) != 0) {
2993 con_log(CL_ANN
, (KERN_WARNING
"megaraid: Inquiry3 failed\n"));
2995 pci_free_consistent(adapter
->pdev
, sizeof(mraid_pinfo_t
),
2996 pinfo
, pinfo_dma_h
);
3002 * Collect information about state of each physical drive
3003 * attached to the controller. We will expose all the disks
3004 * which are not part of RAID
3006 mraid_inq3
= (mraid_inquiry3_t
*)adapter
->ibuf
;
3007 for (i
= 0; i
< MBOX_MAX_PHYSICAL_DRIVES
; i
++) {
3008 raid_dev
->pdrv_state
[i
] = mraid_inq3
->pdrv_state
[i
];
3012 * Get product info for information like number of channels,
3013 * maximum commands supported.
3015 memset((caddr_t
)raw_mbox
, 0, sizeof(raw_mbox
));
3016 mbox
->xferaddr
= (uint32_t)pinfo_dma_h
;
3018 raw_mbox
[0] = FC_NEW_CONFIG
;
3019 raw_mbox
[2] = NC_SUBOP_PRODUCT_INFO
;
3021 if (mbox_post_sync_cmd(adapter
, raw_mbox
) != 0) {
3023 con_log(CL_ANN
, (KERN_WARNING
3024 "megaraid: product info failed\n"));
3026 pci_free_consistent(adapter
->pdev
, sizeof(mraid_pinfo_t
),
3027 pinfo
, pinfo_dma_h
);
3033 * Setup some parameters for host, as required by our caller
3035 adapter
->max_channel
= pinfo
->nchannels
;
3038 * we will export all the logical drives on a single channel.
3039 * Add 1 since inquires do not come for inititor ID
3041 adapter
->max_target
= MAX_LOGICAL_DRIVES_40LD
+ 1;
3042 adapter
->max_lun
= 8; // up to 8 LUNs for non-disk devices
3045 * These are the maximum outstanding commands for the scsi-layer
3047 adapter
->max_cmds
= MBOX_MAX_SCSI_CMDS
;
3049 memset(adapter
->fw_version
, 0, VERSION_SIZE
);
3050 memset(adapter
->bios_version
, 0, VERSION_SIZE
);
3052 memcpy(adapter
->fw_version
, pinfo
->fw_version
, 4);
3053 adapter
->fw_version
[4] = 0;
3055 memcpy(adapter
->bios_version
, pinfo
->bios_version
, 4);
3056 adapter
->bios_version
[4] = 0;
3058 con_log(CL_ANN
, (KERN_NOTICE
3059 "megaraid: fw version:[%s] bios version:[%s]\n",
3060 adapter
->fw_version
, adapter
->bios_version
));
3062 pci_free_consistent(adapter
->pdev
, sizeof(mraid_pinfo_t
), pinfo
,
3071 * megaraid_mbox_extended_cdb - check for support for extended CDBs
3072 * @adapter : soft state for the controller
3074 * This routine check whether the controller in question supports extended
3075 * ( > 10 bytes ) CDBs.
3078 megaraid_mbox_extended_cdb(adapter_t
*adapter
)
3081 uint8_t raw_mbox
[sizeof(mbox_t
)];
3084 mbox
= (mbox_t
*)raw_mbox
;
3086 memset((caddr_t
)raw_mbox
, 0, sizeof(raw_mbox
));
3087 mbox
->xferaddr
= (uint32_t)adapter
->ibuf_dma_h
;
3089 memset((void *)adapter
->ibuf
, 0, MBOX_IBUF_SIZE
);
3091 raw_mbox
[0] = MAIN_MISC_OPCODE
;
3092 raw_mbox
[2] = SUPPORT_EXT_CDB
;
3098 if (mbox_post_sync_cmd(adapter
, raw_mbox
) != 0) {
3107 * megaraid_mbox_support_ha - Do we support clustering
3108 * @adapter : soft state for the controller
3109 * @init_id : ID of the initiator
3111 * Determine if the firmware supports clustering and the ID of the initiator.
3114 megaraid_mbox_support_ha(adapter_t
*adapter
, uint16_t *init_id
)
3117 uint8_t raw_mbox
[sizeof(mbox_t
)];
3121 mbox
= (mbox_t
*)raw_mbox
;
3123 memset((caddr_t
)raw_mbox
, 0, sizeof(raw_mbox
));
3125 mbox
->xferaddr
= (uint32_t)adapter
->ibuf_dma_h
;
3127 memset((void *)adapter
->ibuf
, 0, MBOX_IBUF_SIZE
);
3129 raw_mbox
[0] = GET_TARGET_ID
;
3131 // Issue the command
3134 if (mbox_post_sync_cmd(adapter
, raw_mbox
) == 0) {
3136 *init_id
= *(uint8_t *)adapter
->ibuf
;
3138 con_log(CL_ANN
, (KERN_INFO
3139 "megaraid: cluster firmware, initiator ID: %d\n",
3150 * megaraid_mbox_support_random_del - Do we support random deletion
3151 * @adapter : soft state for the controller
3153 * Determine if the firmware supports random deletion.
3154 * Return: 1 is operation supported, 0 otherwise
3157 megaraid_mbox_support_random_del(adapter_t
*adapter
)
3160 uint8_t raw_mbox
[sizeof(mbox_t
)];
3164 * Newer firmware on Dell CERC expect a different
3165 * random deletion handling, so disable it.
3167 if (adapter
->pdev
->vendor
== PCI_VENDOR_ID_AMI
&&
3168 adapter
->pdev
->device
== PCI_DEVICE_ID_AMI_MEGARAID3
&&
3169 adapter
->pdev
->subsystem_vendor
== PCI_VENDOR_ID_DELL
&&
3170 adapter
->pdev
->subsystem_device
== PCI_SUBSYS_ID_CERC_ATA100_4CH
&&
3171 (adapter
->fw_version
[0] > '6' ||
3172 (adapter
->fw_version
[0] == '6' &&
3173 adapter
->fw_version
[2] > '6') ||
3174 (adapter
->fw_version
[0] == '6'
3175 && adapter
->fw_version
[2] == '6'
3176 && adapter
->fw_version
[3] > '1'))) {
3177 con_log(CL_DLEVEL1
, ("megaraid: disable random deletion\n"));
3181 mbox
= (mbox_t
*)raw_mbox
;
3183 memset((caddr_t
)raw_mbox
, 0, sizeof(mbox_t
));
3185 raw_mbox
[0] = FC_DEL_LOGDRV
;
3186 raw_mbox
[2] = OP_SUP_DEL_LOGDRV
;
3188 // Issue the command
3190 if (mbox_post_sync_cmd(adapter
, raw_mbox
) == 0) {
3192 con_log(CL_DLEVEL1
, ("megaraid: supports random deletion\n"));
3202 * megaraid_mbox_get_max_sg - maximum sg elements supported by the firmware
3203 * @adapter : soft state for the controller
3205 * Find out the maximum number of scatter-gather elements supported by the
3209 megaraid_mbox_get_max_sg(adapter_t
*adapter
)
3212 uint8_t raw_mbox
[sizeof(mbox_t
)];
3216 mbox
= (mbox_t
*)raw_mbox
;
3218 memset((caddr_t
)raw_mbox
, 0, sizeof(mbox_t
));
3220 mbox
->xferaddr
= (uint32_t)adapter
->ibuf_dma_h
;
3222 memset((void *)adapter
->ibuf
, 0, MBOX_IBUF_SIZE
);
3224 raw_mbox
[0] = MAIN_MISC_OPCODE
;
3225 raw_mbox
[2] = GET_MAX_SG_SUPPORT
;
3227 // Issue the command
3228 if (mbox_post_sync_cmd(adapter
, raw_mbox
) == 0) {
3229 nsg
= *(uint8_t *)adapter
->ibuf
;
3232 nsg
= MBOX_DEFAULT_SG_SIZE
;
3235 if (nsg
> MBOX_MAX_SG_SIZE
) nsg
= MBOX_MAX_SG_SIZE
;
3242 * megaraid_mbox_enum_raid_scsi - enumerate the RAID and SCSI channels
3243 * @adapter : soft state for the controller
3245 * Enumerate the RAID and SCSI channels for ROMB platforms so that channels
3246 * can be exported as regular SCSI channels.
3249 megaraid_mbox_enum_raid_scsi(adapter_t
*adapter
)
3251 mraid_device_t
*raid_dev
= ADAP2RAIDDEV(adapter
);
3253 uint8_t raw_mbox
[sizeof(mbox_t
)];
3256 mbox
= (mbox_t
*)raw_mbox
;
3258 memset((caddr_t
)raw_mbox
, 0, sizeof(mbox_t
));
3260 mbox
->xferaddr
= (uint32_t)adapter
->ibuf_dma_h
;
3262 memset((void *)adapter
->ibuf
, 0, MBOX_IBUF_SIZE
);
3264 raw_mbox
[0] = CHNL_CLASS
;
3265 raw_mbox
[2] = GET_CHNL_CLASS
;
3267 // Issue the command. If the command fails, all channels are RAID
3269 raid_dev
->channel_class
= 0xFF;
3270 if (mbox_post_sync_cmd(adapter
, raw_mbox
) == 0) {
3271 raid_dev
->channel_class
= *(uint8_t *)adapter
->ibuf
;
3279 * megaraid_mbox_flush_cache - flush adapter and disks cache
3280 * @adapter : soft state for the controller
3282 * Flush adapter cache followed by disks cache.
3285 megaraid_mbox_flush_cache(adapter_t
*adapter
)
3288 uint8_t raw_mbox
[sizeof(mbox_t
)];
3291 mbox
= (mbox_t
*)raw_mbox
;
3293 memset((caddr_t
)raw_mbox
, 0, sizeof(mbox_t
));
3295 raw_mbox
[0] = FLUSH_ADAPTER
;
3297 if (mbox_post_sync_cmd(adapter
, raw_mbox
) != 0) {
3298 con_log(CL_ANN
, ("megaraid: flush adapter failed\n"));
3301 raw_mbox
[0] = FLUSH_SYSTEM
;
3303 if (mbox_post_sync_cmd(adapter
, raw_mbox
) != 0) {
3304 con_log(CL_ANN
, ("megaraid: flush disks cache failed\n"));
3312 * megaraid_mbox_fire_sync_cmd - fire the sync cmd
3313 * @adapter : soft state for the controller
3315 * Clears the pending cmds in FW and reinits its RAID structs.
3318 megaraid_mbox_fire_sync_cmd(adapter_t
*adapter
)
3321 uint8_t raw_mbox
[sizeof(mbox_t
)];
3322 mraid_device_t
*raid_dev
= ADAP2RAIDDEV(adapter
);
3328 mbox
= (mbox_t
*)raw_mbox
;
3330 memset((caddr_t
)raw_mbox
, 0, sizeof(mbox_t
));
3334 mbox64
= raid_dev
->mbox64
;
3335 mbox
= raid_dev
->mbox
;
3337 /* Wait until mailbox is free */
3338 if (megaraid_busywait_mbox(raid_dev
) != 0) {
3340 goto blocked_mailbox
;
3343 /* Copy mailbox data into host structure */
3344 memcpy((caddr_t
)mbox
, (caddr_t
)raw_mbox
, 16);
3349 mbox
->numstatus
= 0;
3353 WRINDOOR(raid_dev
, raid_dev
->mbox_dma
| 0x1);
3355 /* Wait for maximum 1 min for status to post.
3356 * If the Firmware SUPPORTS the ABOVE COMMAND,
3357 * mbox->cmd will be set to 0
3359 * the firmware will reject the command with
3360 * mbox->numstatus set to 1
3365 while (!mbox
->numstatus
&& mbox
->cmd
== 0xFF) {
3369 if (i
> 1000 * 60) {
3374 if (mbox
->numstatus
== 1)
3375 status
= 1; /*cmd not supported*/
3377 /* Check for interrupt line */
3378 dword
= RDOUTDOOR(raid_dev
);
3379 WROUTDOOR(raid_dev
, dword
);
3380 WRINDOOR(raid_dev
,2);
3385 con_log(CL_ANN
, (KERN_WARNING
"megaraid: blocked mailbox\n"));
3390 * megaraid_mbox_display_scb - display SCB information, mostly debug purposes
3391 * @adapter : controller's soft state
3392 * @scb : SCB to be displayed
3393 * @level : debug level for console print
3395 * Diplay information about the given SCB iff the current debug level is
3399 megaraid_mbox_display_scb(adapter_t
*adapter
, scb_t
*scb
)
3402 struct scsi_cmnd
*scp
;
3408 ccb
= (mbox_ccb_t
*)scb
->ccb
;
3414 con_log(level
, (KERN_NOTICE
3415 "megaraid mailbox: status:%#x cmd:%#x id:%#x ", scb
->status
,
3416 mbox
->cmd
, scb
->sno
));
3418 con_log(level
, ("sec:%#x lba:%#x addr:%#x ld:%d sg:%d\n",
3419 mbox
->numsectors
, mbox
->lba
, mbox
->xferaddr
, mbox
->logdrv
,
3424 con_log(level
, (KERN_NOTICE
"scsi cmnd: "));
3426 for (i
= 0; i
< scp
->cmd_len
; i
++) {
3427 con_log(level
, ("%#2.02x ", scp
->cmnd
[i
]));
3430 con_log(level
, ("\n"));
3437 * megaraid_mbox_setup_device_map - manage device ids
3438 * @adapter : Driver's soft state
3440 * Manage the device ids to have an appropriate mapping between the kernel
3441 * scsi addresses and megaraid scsi and logical drive addresses. We export
3442 * scsi devices on their actual addresses, whereas the logical drives are
3443 * exported on a virtual scsi channel.
3446 megaraid_mbox_setup_device_map(adapter_t
*adapter
)
3452 * First fill the values on the logical drive channel
3454 for (t
= 0; t
< LSI_MAX_LOGICAL_DRIVES_64LD
; t
++)
3455 adapter
->device_ids
[adapter
->max_channel
][t
] =
3456 (t
< adapter
->init_id
) ? t
: t
- 1;
3458 adapter
->device_ids
[adapter
->max_channel
][adapter
->init_id
] = 0xFF;
3461 * Fill the values on the physical devices channels
3463 for (c
= 0; c
< adapter
->max_channel
; c
++)
3464 for (t
= 0; t
< LSI_MAX_LOGICAL_DRIVES_64LD
; t
++)
3465 adapter
->device_ids
[c
][t
] = (c
<< 8) | t
;
3470 * END: internal commands library
3474 * START: Interface for the common management module
3476 * This is the module, which interfaces with the common management module to
3477 * provide support for ioctl and sysfs
3481 * megaraid_cmm_register - register with the management module
3482 * @adapter : HBA soft state
3484 * Register with the management module, which allows applications to issue
3485 * ioctl calls to the drivers. This interface is used by the management module
3486 * to setup sysfs support as well.
3489 megaraid_cmm_register(adapter_t
*adapter
)
3491 mraid_device_t
*raid_dev
= ADAP2RAIDDEV(adapter
);
3498 // Allocate memory for the base list of scb for management module.
3499 adapter
->uscb_list
= kcalloc(MBOX_MAX_USER_CMDS
, sizeof(scb_t
), GFP_KERNEL
);
3501 if (adapter
->uscb_list
== NULL
) {
3502 con_log(CL_ANN
, (KERN_WARNING
3503 "megaraid: out of memory, %s %d\n", __func__
,
3509 // Initialize the synchronization parameters for resources for
3510 // commands for management module
3511 INIT_LIST_HEAD(&adapter
->uscb_pool
);
3513 spin_lock_init(USER_FREE_LIST_LOCK(adapter
));
3517 // link all the packets. Note, CCB for commands, coming from the
3518 // commom management module, mailbox physical address are already
3519 // setup by it. We just need placeholder for that in our local command
3521 for (i
= 0; i
< MBOX_MAX_USER_CMDS
; i
++) {
3523 scb
= adapter
->uscb_list
+ i
;
3524 ccb
= raid_dev
->uccb_list
+ i
;
3526 scb
->ccb
= (caddr_t
)ccb
;
3527 ccb
->mbox64
= raid_dev
->umbox64
+ i
;
3528 ccb
->mbox
= &ccb
->mbox64
->mbox32
;
3529 ccb
->raw_mbox
= (uint8_t *)ccb
->mbox
;
3533 // COMMAND ID 0 - (MBOX_MAX_SCSI_CMDS-1) ARE RESERVED FOR
3534 // COMMANDS COMING FROM IO SUBSYSTEM (MID-LAYER)
3535 scb
->sno
= i
+ MBOX_MAX_SCSI_CMDS
;
3538 scb
->state
= SCB_FREE
;
3539 scb
->dma_direction
= PCI_DMA_NONE
;
3540 scb
->dma_type
= MRAID_DMA_NONE
;
3541 scb
->dev_channel
= -1;
3542 scb
->dev_target
= -1;
3544 // put scb in the free pool
3545 list_add_tail(&scb
->list
, &adapter
->uscb_pool
);
3548 adp
.unique_id
= adapter
->unique_id
;
3549 adp
.drvr_type
= DRVRTYPE_MBOX
;
3550 adp
.drvr_data
= (unsigned long)adapter
;
3551 adp
.pdev
= adapter
->pdev
;
3552 adp
.issue_uioc
= megaraid_mbox_mm_handler
;
3553 adp
.timeout
= MBOX_RESET_WAIT
+ MBOX_RESET_EXT_WAIT
;
3554 adp
.max_kioc
= MBOX_MAX_USER_CMDS
;
3556 if ((rval
= mraid_mm_register_adp(&adp
)) != 0) {
3558 con_log(CL_ANN
, (KERN_WARNING
3559 "megaraid mbox: did not register with CMM\n"));
3561 kfree(adapter
->uscb_list
);
3569 * megaraid_cmm_unregister - un-register with the management module
3570 * @adapter : HBA soft state
3572 * Un-register with the management module.
3573 * FIXME: mgmt module must return failure for unregister if it has pending
3577 megaraid_cmm_unregister(adapter_t
*adapter
)
3579 kfree(adapter
->uscb_list
);
3580 mraid_mm_unregister_adp(adapter
->unique_id
);
3586 * megaraid_mbox_mm_handler - interface for CMM to issue commands to LLD
3587 * @drvr_data : LLD specific data
3588 * @kioc : CMM interface packet
3589 * @action : command action
3591 * This routine is invoked whenever the Common Management Module (CMM) has a
3592 * command for us. The 'action' parameter specifies if this is a new command
3596 megaraid_mbox_mm_handler(unsigned long drvr_data
, uioc_t
*kioc
, uint32_t action
)
3600 if (action
!= IOCTL_ISSUE
) {
3601 con_log(CL_ANN
, (KERN_WARNING
3602 "megaraid: unsupported management action:%#2x\n",
3607 adapter
= (adapter_t
*)drvr_data
;
3609 // make sure this adapter is not being detached right now.
3610 if (atomic_read(&adapter
->being_detached
)) {
3611 con_log(CL_ANN
, (KERN_WARNING
3612 "megaraid: reject management request, detaching\n"));
3616 switch (kioc
->opcode
) {
3620 kioc
->status
= gather_hbainfo(adapter
, (mraid_hba_info_t
*)
3621 (unsigned long)kioc
->buf_vaddr
);
3625 return kioc
->status
;
3629 return megaraid_mbox_mm_command(adapter
, kioc
);
3632 kioc
->status
= (-EINVAL
);
3637 return 0; // not reached
3641 * megaraid_mbox_mm_command - issues commands routed through CMM
3642 * @adapter : HBA soft state
3643 * @kioc : management command packet
3645 * Issues commands, which are routed through the management module.
3648 megaraid_mbox_mm_command(adapter_t
*adapter
, uioc_t
*kioc
)
3650 struct list_head
*head
= &adapter
->uscb_pool
;
3655 unsigned long flags
;
3657 // detach one scb from free pool
3658 spin_lock_irqsave(USER_FREE_LIST_LOCK(adapter
), flags
);
3660 if (list_empty(head
)) { // should never happen because of CMM
3662 con_log(CL_ANN
, (KERN_WARNING
3663 "megaraid mbox: bug in cmm handler, lost resources\n"));
3665 spin_unlock_irqrestore(USER_FREE_LIST_LOCK(adapter
), flags
);
3670 scb
= list_entry(head
->next
, scb_t
, list
);
3671 list_del_init(&scb
->list
);
3673 spin_unlock_irqrestore(USER_FREE_LIST_LOCK(adapter
), flags
);
3675 scb
->state
= SCB_ACTIVE
;
3676 scb
->dma_type
= MRAID_DMA_NONE
;
3677 scb
->dma_direction
= PCI_DMA_NONE
;
3679 ccb
= (mbox_ccb_t
*)scb
->ccb
;
3680 mbox64
= (mbox64_t
*)(unsigned long)kioc
->cmdbuf
;
3681 raw_mbox
= (uint8_t *)&mbox64
->mbox32
;
3683 memcpy(ccb
->mbox64
, mbox64
, sizeof(mbox64_t
));
3685 scb
->gp
= (unsigned long)kioc
;
3688 * If it is a logdrv random delete operation, we have to wait till
3689 * there are no outstanding cmds at the fw and then issue it directly
3691 if (raw_mbox
[0] == FC_DEL_LOGDRV
&& raw_mbox
[2] == OP_DEL_LOGDRV
) {
3693 if (wait_till_fw_empty(adapter
)) {
3694 con_log(CL_ANN
, (KERN_NOTICE
3695 "megaraid mbox: LD delete, timed out\n"));
3697 kioc
->status
= -ETIME
;
3701 megaraid_mbox_mm_done(adapter
, scb
);
3706 INIT_LIST_HEAD(&scb
->list
);
3708 scb
->state
= SCB_ISSUED
;
3709 if (mbox_post_cmd(adapter
, scb
) != 0) {
3711 con_log(CL_ANN
, (KERN_NOTICE
3712 "megaraid mbox: LD delete, mailbox busy\n"));
3714 kioc
->status
= -EBUSY
;
3718 megaraid_mbox_mm_done(adapter
, scb
);
3726 // put the command on the pending list and execute
3727 megaraid_mbox_runpendq(adapter
, scb
);
3734 wait_till_fw_empty(adapter_t
*adapter
)
3736 unsigned long flags
= 0;
3741 * Set the quiescent flag to stop issuing cmds to FW.
3743 spin_lock_irqsave(&adapter
->lock
, flags
);
3744 adapter
->quiescent
++;
3745 spin_unlock_irqrestore(&adapter
->lock
, flags
);
3748 * Wait till there are no more cmds outstanding at FW. Try for at most
3751 for (i
= 0; i
< 60 && adapter
->outstanding_cmds
; i
++) {
3752 con_log(CL_DLEVEL1
, (KERN_INFO
3753 "megaraid: FW has %d pending commands\n",
3754 adapter
->outstanding_cmds
));
3759 return adapter
->outstanding_cmds
;
3764 * megaraid_mbox_mm_done - callback for CMM commands
3765 * @adapter : HBA soft state
3766 * @scb : completed command
3768 * Callback routine for internal commands originated from the management
3772 megaraid_mbox_mm_done(adapter_t
*adapter
, scb_t
*scb
)
3777 unsigned long flags
;
3779 kioc
= (uioc_t
*)scb
->gp
;
3780 mbox64
= (mbox64_t
*)(unsigned long)kioc
->cmdbuf
;
3781 mbox64
->mbox32
.status
= scb
->status
;
3782 raw_mbox
= (uint8_t *)&mbox64
->mbox32
;
3785 // put scb in the free pool
3786 scb
->state
= SCB_FREE
;
3789 spin_lock_irqsave(USER_FREE_LIST_LOCK(adapter
), flags
);
3791 list_add(&scb
->list
, &adapter
->uscb_pool
);
3793 spin_unlock_irqrestore(USER_FREE_LIST_LOCK(adapter
), flags
);
3795 // if a delete logical drive operation succeeded, restart the
3797 if (raw_mbox
[0] == FC_DEL_LOGDRV
&& raw_mbox
[2] == OP_DEL_LOGDRV
) {
3799 adapter
->quiescent
--;
3801 megaraid_mbox_runpendq(adapter
, NULL
);
3811 * gather_hbainfo - HBA characteristics for the applications
3812 * @adapter : HBA soft state
3813 * @hinfo : pointer to the caller's host info strucuture
3816 gather_hbainfo(adapter_t
*adapter
, mraid_hba_info_t
*hinfo
)
3820 dmajor
= megaraid_mbox_version
[0];
3822 hinfo
->pci_vendor_id
= adapter
->pdev
->vendor
;
3823 hinfo
->pci_device_id
= adapter
->pdev
->device
;
3824 hinfo
->subsys_vendor_id
= adapter
->pdev
->subsystem_vendor
;
3825 hinfo
->subsys_device_id
= adapter
->pdev
->subsystem_device
;
3827 hinfo
->pci_bus
= adapter
->pdev
->bus
->number
;
3828 hinfo
->pci_dev_fn
= adapter
->pdev
->devfn
;
3829 hinfo
->pci_slot
= PCI_SLOT(adapter
->pdev
->devfn
);
3830 hinfo
->irq
= adapter
->host
->irq
;
3831 hinfo
->baseport
= ADAP2RAIDDEV(adapter
)->baseport
;
3833 hinfo
->unique_id
= (hinfo
->pci_bus
<< 8) | adapter
->pdev
->devfn
;
3834 hinfo
->host_no
= adapter
->host
->host_no
;
3840 * END: Interface for the common management module
3846 * megaraid_sysfs_alloc_resources - allocate sysfs related resources
3847 * @adapter : controller's soft state
3849 * Allocate packets required to issue FW calls whenever the sysfs attributes
3850 * are read. These attributes would require up-to-date information from the
3851 * FW. Also set up resources for mutual exclusion to share these resources and
3854 * Return 0 on success.
3855 * Return -ERROR_CODE on failure.
3858 megaraid_sysfs_alloc_resources(adapter_t
*adapter
)
3860 mraid_device_t
*raid_dev
= ADAP2RAIDDEV(adapter
);
3863 raid_dev
->sysfs_uioc
= kmalloc(sizeof(uioc_t
), GFP_KERNEL
);
3865 raid_dev
->sysfs_mbox64
= kmalloc(sizeof(mbox64_t
), GFP_KERNEL
);
3867 raid_dev
->sysfs_buffer
= pci_alloc_consistent(adapter
->pdev
,
3868 PAGE_SIZE
, &raid_dev
->sysfs_buffer_dma
);
3870 if (!raid_dev
->sysfs_uioc
|| !raid_dev
->sysfs_mbox64
||
3871 !raid_dev
->sysfs_buffer
) {
3873 con_log(CL_ANN
, (KERN_WARNING
3874 "megaraid: out of memory, %s %d\n", __func__
,
3879 megaraid_sysfs_free_resources(adapter
);
3882 mutex_init(&raid_dev
->sysfs_mtx
);
3884 init_waitqueue_head(&raid_dev
->sysfs_wait_q
);
3891 * megaraid_sysfs_free_resources - free sysfs related resources
3892 * @adapter : controller's soft state
3894 * Free packets allocated for sysfs FW commands
3897 megaraid_sysfs_free_resources(adapter_t
*adapter
)
3899 mraid_device_t
*raid_dev
= ADAP2RAIDDEV(adapter
);
3901 kfree(raid_dev
->sysfs_uioc
);
3902 kfree(raid_dev
->sysfs_mbox64
);
3904 if (raid_dev
->sysfs_buffer
) {
3905 pci_free_consistent(adapter
->pdev
, PAGE_SIZE
,
3906 raid_dev
->sysfs_buffer
, raid_dev
->sysfs_buffer_dma
);
3912 * megaraid_sysfs_get_ldmap_done - callback for get ldmap
3913 * @uioc : completed packet
3915 * Callback routine called in the ISR/tasklet context for get ldmap call
3918 megaraid_sysfs_get_ldmap_done(uioc_t
*uioc
)
3920 adapter_t
*adapter
= (adapter_t
*)uioc
->buf_vaddr
;
3921 mraid_device_t
*raid_dev
= ADAP2RAIDDEV(adapter
);
3925 wake_up(&raid_dev
->sysfs_wait_q
);
3930 * megaraid_sysfs_get_ldmap_timeout - timeout handling for get ldmap
3931 * @data : timed out packet
3933 * Timeout routine to recover and return to application, in case the adapter
3934 * has stopped responding. A timeout of 60 seconds for this command seems like
3938 megaraid_sysfs_get_ldmap_timeout(unsigned long data
)
3940 uioc_t
*uioc
= (uioc_t
*)data
;
3941 adapter_t
*adapter
= (adapter_t
*)uioc
->buf_vaddr
;
3942 mraid_device_t
*raid_dev
= ADAP2RAIDDEV(adapter
);
3944 uioc
->status
= -ETIME
;
3946 wake_up(&raid_dev
->sysfs_wait_q
);
3951 * megaraid_sysfs_get_ldmap - get update logical drive map
3952 * @adapter : controller's soft state
3954 * This routine will be called whenever user reads the logical drive
3955 * attributes, go get the current logical drive mapping table from the
3956 * firmware. We use the management API's to issue commands to the controller.
3958 * NOTE: The commands issuance functionality is not generalized and
3959 * implemented in context of "get ld map" command only. If required, the
3960 * command issuance logical can be trivially pulled out and implemented as a
3961 * standalone library. For now, this should suffice since there is no other
3962 * user of this interface.
3964 * Return 0 on success.
3965 * Return -1 on failure.
3968 megaraid_sysfs_get_ldmap(adapter_t
*adapter
)
3970 mraid_device_t
*raid_dev
= ADAP2RAIDDEV(adapter
);
3975 struct timer_list sysfs_timer
;
3976 struct timer_list
*timerp
;
3981 * Allow only one read at a time to go through the sysfs attributes
3983 mutex_lock(&raid_dev
->sysfs_mtx
);
3985 uioc
= raid_dev
->sysfs_uioc
;
3986 mbox64
= raid_dev
->sysfs_mbox64
;
3987 ldmap
= raid_dev
->sysfs_buffer
;
3989 memset(uioc
, 0, sizeof(uioc_t
));
3990 memset(mbox64
, 0, sizeof(mbox64_t
));
3991 memset(ldmap
, 0, sizeof(raid_dev
->curr_ldmap
));
3993 mbox
= &mbox64
->mbox32
;
3994 raw_mbox
= (char *)mbox
;
3995 uioc
->cmdbuf
= (uint64_t)(unsigned long)mbox64
;
3996 uioc
->buf_vaddr
= (caddr_t
)adapter
;
3997 uioc
->status
= -ENODATA
;
3998 uioc
->done
= megaraid_sysfs_get_ldmap_done
;
4001 * Prepare the mailbox packet to get the current logical drive mapping
4004 mbox
->xferaddr
= (uint32_t)raid_dev
->sysfs_buffer_dma
;
4006 raw_mbox
[0] = FC_DEL_LOGDRV
;
4007 raw_mbox
[2] = OP_GET_LDID_MAP
;
4010 * Setup a timer to recover from a non-responding controller
4012 timerp
= &sysfs_timer
;
4015 timerp
->function
= megaraid_sysfs_get_ldmap_timeout
;
4016 timerp
->data
= (unsigned long)uioc
;
4017 timerp
->expires
= jiffies
+ 60 * HZ
;
4022 * Send the command to the firmware
4024 rval
= megaraid_mbox_mm_command(adapter
, uioc
);
4026 if (rval
== 0) { // command successfully issued
4027 wait_event(raid_dev
->sysfs_wait_q
, (uioc
->status
!= -ENODATA
));
4030 * Check if the command timed out
4032 if (uioc
->status
== -ETIME
) {
4033 con_log(CL_ANN
, (KERN_NOTICE
4034 "megaraid: sysfs get ld map timed out\n"));
4039 rval
= mbox
->status
;
4043 memcpy(raid_dev
->curr_ldmap
, ldmap
,
4044 sizeof(raid_dev
->curr_ldmap
));
4047 con_log(CL_ANN
, (KERN_NOTICE
4048 "megaraid: get ld map failed with %x\n", rval
));
4052 con_log(CL_ANN
, (KERN_NOTICE
4053 "megaraid: could not issue ldmap command:%x\n", rval
));
4057 del_timer_sync(timerp
);
4059 mutex_unlock(&raid_dev
->sysfs_mtx
);
4066 * megaraid_sysfs_show_app_hndl - display application handle for this adapter
4067 * @cdev : class device object representation for the host
4068 * @buf : buffer to send data to
4070 * Display the handle used by the applications while executing management
4071 * tasks on the adapter. We invoke a management module API to get the adapter
4072 * handle, since we do not interface with applications directly.
4075 megaraid_sysfs_show_app_hndl(struct device
*dev
, struct device_attribute
*attr
,
4078 struct Scsi_Host
*shost
= class_to_shost(dev
);
4079 adapter_t
*adapter
= (adapter_t
*)SCSIHOST2ADAP(shost
);
4082 app_hndl
= mraid_mm_adapter_app_handle(adapter
->unique_id
);
4084 return snprintf(buf
, 8, "%u\n", app_hndl
);
4089 * megaraid_sysfs_show_ldnum - display the logical drive number for this device
4090 * @dev : device object representation for the scsi device
4091 * @attr : device attribute to show
4092 * @buf : buffer to send data to
4094 * Display the logical drive number for the device in question, if it a valid
4095 * logical drive. For physical devices, "-1" is returned.
4097 * The logical drive number is displayed in following format:
4099 * <SCSI ID> <LD NUM> <LD STICKY ID> <APP ADAPTER HANDLE>
4101 * <int> <int> <int> <int>
4104 megaraid_sysfs_show_ldnum(struct device
*dev
, struct device_attribute
*attr
, char *buf
)
4106 struct scsi_device
*sdev
= to_scsi_device(dev
);
4107 adapter_t
*adapter
= (adapter_t
*)SCSIHOST2ADAP(sdev
->host
);
4108 mraid_device_t
*raid_dev
= ADAP2RAIDDEV(adapter
);
4110 int logical_drv
= -1;
4112 uint32_t app_hndl
= 0;
4117 if (raid_dev
->random_del_supported
&&
4118 MRAID_IS_LOGICAL_SDEV(adapter
, sdev
)) {
4120 rval
= megaraid_sysfs_get_ldmap(adapter
);
4123 for (i
= 0; i
< MAX_LOGICAL_DRIVES_40LD
; i
++) {
4125 mapped_sdev_id
= sdev
->id
;
4127 if (sdev
->id
> adapter
->init_id
) {
4128 mapped_sdev_id
-= 1;
4131 if (raid_dev
->curr_ldmap
[i
] == mapped_sdev_id
) {
4137 ldid_map
= raid_dev
->curr_ldmap
[i
];
4139 app_hndl
= mraid_mm_adapter_app_handle(
4140 adapter
->unique_id
);
4147 con_log(CL_ANN
, (KERN_NOTICE
4148 "megaraid: sysfs get ld map failed: %x\n",
4153 return snprintf(buf
, 36, "%d %d %d %d\n", scsi_id
, logical_drv
,
4154 ldid_map
, app_hndl
);
4159 * END: Mailbox Low Level Driver
4161 module_init(megaraid_init
);
4162 module_exit(megaraid_exit
);
4164 /* vim: set ts=8 sw=8 tw=78 ai si: */