forked from ~ljy/RK356X_SDK_RELEASE

hc
2024-05-13 9d77db3c730780c8ef5ccd4b66403ff5675cfe4e
kernel/drivers/scsi/megaraid/megaraid_sas_base.c
....@@ -1,34 +1,20 @@
1
+// SPDX-License-Identifier: GPL-2.0-or-later
12 /*
23 * Linux MegaRAID driver for SAS based RAID controllers
34 *
45 * Copyright (c) 2003-2013 LSI Corporation
5
- * Copyright (c) 2013-2014 Avago Technologies
6
+ * Copyright (c) 2013-2016 Avago Technologies
7
+ * Copyright (c) 2016-2018 Broadcom Inc.
68 *
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 2
10
- * of the License, or (at your option) any later version.
11
- *
12
- * This program is distributed in the hope that it will be useful,
13
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
- * GNU General Public License for more details.
16
- *
17
- * You should have received a copy of the GNU General Public License
18
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
19
- *
20
- * Authors: Avago Technologies
9
+ * Authors: Broadcom Inc.
2110 * Sreenivas Bagalkote
2211 * Sumant Patro
2312 * Bo Yang
2413 * Adam Radford
25
- * Kashyap Desai <kashyap.desai@avagotech.com>
26
- * Sumit Saxena <sumit.saxena@avagotech.com>
14
+ * Kashyap Desai <kashyap.desai@broadcom.com>
15
+ * Sumit Saxena <sumit.saxena@broadcom.com>
2716 *
28
- * Send feedback to: megaraidlinux.pdl@avagotech.com
29
- *
30
- * Mail to: Avago Technologies, 350 West Trimble Road, Building 90,
31
- * San Jose, California 95131
17
+ * Send feedback to: megaraidlinux.pdl@broadcom.com
3218 */
3319
3420 #include <linux/kernel.h>
....@@ -50,12 +36,14 @@
5036 #include <linux/mutex.h>
5137 #include <linux/poll.h>
5238 #include <linux/vmalloc.h>
39
+#include <linux/irq_poll.h>
5340
5441 #include <scsi/scsi.h>
5542 #include <scsi/scsi_cmnd.h>
5643 #include <scsi/scsi_device.h>
5744 #include <scsi/scsi_host.h>
5845 #include <scsi/scsi_tcq.h>
46
+#include <scsi/scsi_dbg.h>
5947 #include "megaraid_sas_fusion.h"
6048 #include "megaraid_sas.h"
6149
....@@ -64,52 +52,71 @@
6452 * Will be set in megasas_init_mfi if user does not provide
6553 */
6654 static unsigned int max_sectors;
67
-module_param_named(max_sectors, max_sectors, int, 0);
55
+module_param_named(max_sectors, max_sectors, int, 0444);
6856 MODULE_PARM_DESC(max_sectors,
6957 "Maximum number of sectors per IO command");
7058
7159 static int msix_disable;
72
-module_param(msix_disable, int, S_IRUGO);
60
+module_param(msix_disable, int, 0444);
7361 MODULE_PARM_DESC(msix_disable, "Disable MSI-X interrupt handling. Default: 0");
7462
7563 static unsigned int msix_vectors;
76
-module_param(msix_vectors, int, S_IRUGO);
64
+module_param(msix_vectors, int, 0444);
7765 MODULE_PARM_DESC(msix_vectors, "MSI-X max vector count. Default: Set by FW");
7866
7967 static int allow_vf_ioctls;
80
-module_param(allow_vf_ioctls, int, S_IRUGO);
68
+module_param(allow_vf_ioctls, int, 0444);
8169 MODULE_PARM_DESC(allow_vf_ioctls, "Allow ioctls in SR-IOV VF mode. Default: 0");
8270
8371 static unsigned int throttlequeuedepth = MEGASAS_THROTTLE_QUEUE_DEPTH;
84
-module_param(throttlequeuedepth, int, S_IRUGO);
72
+module_param(throttlequeuedepth, int, 0444);
8573 MODULE_PARM_DESC(throttlequeuedepth,
8674 "Adapter queue depth when throttled due to I/O timeout. Default: 16");
8775
8876 unsigned int resetwaittime = MEGASAS_RESET_WAIT_TIME;
89
-module_param(resetwaittime, int, S_IRUGO);
90
-MODULE_PARM_DESC(resetwaittime, "Wait time in seconds after I/O timeout "
91
- "before resetting adapter. Default: 180");
77
+module_param(resetwaittime, int, 0444);
78
+MODULE_PARM_DESC(resetwaittime, "Wait time in (1-180s) after I/O timeout before resetting adapter. Default: 180s");
9279
93
-int smp_affinity_enable = 1;
94
-module_param(smp_affinity_enable, int, S_IRUGO);
80
+static int smp_affinity_enable = 1;
81
+module_param(smp_affinity_enable, int, 0444);
9582 MODULE_PARM_DESC(smp_affinity_enable, "SMP affinity feature enable/disable Default: enable(1)");
9683
97
-int rdpq_enable = 1;
98
-module_param(rdpq_enable, int, S_IRUGO);
99
-MODULE_PARM_DESC(rdpq_enable, " Allocate reply queue in chunks for large queue depth enable/disable Default: disable(0)");
84
+static int rdpq_enable = 1;
85
+module_param(rdpq_enable, int, 0444);
86
+MODULE_PARM_DESC(rdpq_enable, "Allocate reply queue in chunks for large queue depth enable/disable Default: enable(1)");
10087
10188 unsigned int dual_qdepth_disable;
102
-module_param(dual_qdepth_disable, int, S_IRUGO);
89
+module_param(dual_qdepth_disable, int, 0444);
10390 MODULE_PARM_DESC(dual_qdepth_disable, "Disable dual queue depth feature. Default: 0");
10491
105
-unsigned int scmd_timeout = MEGASAS_DEFAULT_CMD_TIMEOUT;
106
-module_param(scmd_timeout, int, S_IRUGO);
92
+static unsigned int scmd_timeout = MEGASAS_DEFAULT_CMD_TIMEOUT;
93
+module_param(scmd_timeout, int, 0444);
10794 MODULE_PARM_DESC(scmd_timeout, "scsi command timeout (10-90s), default 90s. See megasas_reset_timer.");
95
+
96
+int perf_mode = -1;
97
+module_param(perf_mode, int, 0444);
98
+MODULE_PARM_DESC(perf_mode, "Performance mode (only for Aero adapters), options:\n\t\t"
99
+ "0 - balanced: High iops and low latency queues are allocated &\n\t\t"
100
+ "interrupt coalescing is enabled only on high iops queues\n\t\t"
101
+ "1 - iops: High iops queues are not allocated &\n\t\t"
102
+ "interrupt coalescing is enabled on all queues\n\t\t"
103
+ "2 - latency: High iops queues are not allocated &\n\t\t"
104
+ "interrupt coalescing is disabled on all queues\n\t\t"
105
+ "default mode is 'balanced'"
106
+ );
107
+
108
+int event_log_level = MFI_EVT_CLASS_CRITICAL;
109
+module_param(event_log_level, int, 0644);
110
+MODULE_PARM_DESC(event_log_level, "Asynchronous event logging level- range is: -2(CLASS_DEBUG) to 4(CLASS_DEAD), Default: 2(CLASS_CRITICAL)");
111
+
112
+unsigned int enable_sdev_max_qd;
113
+module_param(enable_sdev_max_qd, int, 0444);
114
+MODULE_PARM_DESC(enable_sdev_max_qd, "Enable sdev max qd as can_queue. Default: 0");
108115
109116 MODULE_LICENSE("GPL");
110117 MODULE_VERSION(MEGASAS_VERSION);
111
-MODULE_AUTHOR("megaraidlinux.pdl@avagotech.com");
112
-MODULE_DESCRIPTION("Avago MegaRAID SAS Driver");
118
+MODULE_AUTHOR("megaraidlinux.pdl@broadcom.com");
119
+MODULE_DESCRIPTION("Broadcom MegaRAID SAS Driver");
113120
114121 int megasas_transition_to_ready(struct megasas_instance *instance, int ocr);
115122 static int megasas_get_pd_list(struct megasas_instance *instance);
....@@ -120,6 +127,8 @@
120127 u32 seq_num, u32 class_locale_word);
121128 static void megasas_get_pd_info(struct megasas_instance *instance,
122129 struct scsi_device *sdev);
130
+static void
131
+megasas_set_ld_removed_by_fw(struct megasas_instance *instance);
123132
124133 /*
125134 * PCI ID table for all supported controllers
....@@ -165,6 +174,14 @@
165174 {PCI_DEVICE(PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_TOMCAT)},
166175 {PCI_DEVICE(PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_VENTURA_4PORT)},
167176 {PCI_DEVICE(PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_CRUSADER_4PORT)},
177
+ {PCI_DEVICE(PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_AERO_10E1)},
178
+ {PCI_DEVICE(PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_AERO_10E2)},
179
+ {PCI_DEVICE(PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_AERO_10E5)},
180
+ {PCI_DEVICE(PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_AERO_10E6)},
181
+ {PCI_DEVICE(PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_AERO_10E0)},
182
+ {PCI_DEVICE(PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_AERO_10E3)},
183
+ {PCI_DEVICE(PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_AERO_10E4)},
184
+ {PCI_DEVICE(PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_AERO_10E7)},
168185 {}
169186 };
170187
....@@ -181,15 +198,18 @@
181198 u32 megasas_dbg_lvl;
182199 static u32 support_device_change;
183200 static bool support_nvme_encapsulation;
201
+static bool support_pci_lane_margining;
184202
185203 /* define lock for aen poll */
186
-spinlock_t poll_aen_lock;
204
+static spinlock_t poll_aen_lock;
205
+
206
+extern struct dentry *megasas_debugfs_root;
187207
188208 void
189209 megasas_complete_cmd(struct megasas_instance *instance, struct megasas_cmd *cmd,
190210 u8 alt_status);
191211 static u32
192
-megasas_read_fw_status_reg_gen2(struct megasas_register_set __iomem *regs);
212
+megasas_read_fw_status_reg_gen2(struct megasas_instance *instance);
193213 static int
194214 megasas_adp_reset_gen2(struct megasas_instance *instance,
195215 struct megasas_register_set __iomem *reg_set);
....@@ -219,6 +239,28 @@
219239 static inline void
220240 megasas_init_ctrl_params(struct megasas_instance *instance);
221241
242
+u32 megasas_readl(struct megasas_instance *instance,
243
+ const volatile void __iomem *addr)
244
+{
245
+ u32 i = 0, ret_val;
246
+ /*
247
+ * Due to a HW errata in Aero controllers, reads to certain
248
+ * Fusion registers could intermittently return all zeroes.
249
+ * This behavior is transient in nature and subsequent reads will
250
+ * return valid value. As a workaround in driver, retry readl for
251
+ * upto three times until a non-zero value is read.
252
+ */
253
+ if (instance->adapter_type == AERO_SERIES) {
254
+ do {
255
+ ret_val = readl(addr);
256
+ i++;
257
+ } while (ret_val == 0 && i < 3);
258
+ return ret_val;
259
+ } else {
260
+ return readl(addr);
261
+ }
262
+}
263
+
222264 /**
223265 * megasas_set_dma_settings - Populate DMA address, length and flags for DCMDs
224266 * @instance: Adapter soft state
....@@ -244,7 +286,7 @@
244286 }
245287 }
246288
247
-void
289
+static void
248290 megasas_issue_dcmd(struct megasas_instance *instance, struct megasas_cmd *cmd)
249291 {
250292 instance->instancet->fire_cmd(instance,
....@@ -368,23 +410,35 @@
368410 union megasas_evt_class_locale class_locale;
369411 class_locale.word = le32_to_cpu(evt_detail->cl.word);
370412
371
- if (class_locale.members.class >= MFI_EVT_CLASS_CRITICAL)
413
+ if ((event_log_level < MFI_EVT_CLASS_DEBUG) ||
414
+ (event_log_level > MFI_EVT_CLASS_DEAD)) {
415
+ printk(KERN_WARNING "megaraid_sas: provided event log level is out of range, setting it to default 2(CLASS_CRITICAL), permissible range is: -2 to 4\n");
416
+ event_log_level = MFI_EVT_CLASS_CRITICAL;
417
+ }
418
+
419
+ if (class_locale.members.class >= event_log_level)
372420 dev_info(&instance->pdev->dev, "%d (%s/0x%04x/%s) - %s\n",
373421 le32_to_cpu(evt_detail->seq_num),
374422 format_timestamp(le32_to_cpu(evt_detail->time_stamp)),
375423 (class_locale.members.locale),
376424 format_class(class_locale.members.class),
377425 evt_detail->description);
426
+
427
+ if (megasas_dbg_lvl & LD_PD_DEBUG)
428
+ dev_info(&instance->pdev->dev,
429
+ "evt_detail.args.ld.target_id/index %d/%d\n",
430
+ evt_detail->args.ld.target_id, evt_detail->args.ld.ld_index);
431
+
378432 }
379433
380
-/**
381
-* The following functions are defined for xscale
382
-* (deviceid : 1064R, PERC5) controllers
383
-*/
434
+/*
435
+ * The following functions are defined for xscale
436
+ * (deviceid : 1064R, PERC5) controllers
437
+ */
384438
385439 /**
386440 * megasas_enable_intr_xscale - Enables interrupts
387
- * @regs: MFI register set
441
+ * @instance: Adapter soft state
388442 */
389443 static inline void
390444 megasas_enable_intr_xscale(struct megasas_instance *instance)
....@@ -400,7 +454,7 @@
400454
401455 /**
402456 * megasas_disable_intr_xscale -Disables interrupt
403
- * @regs: MFI register set
457
+ * @instance: Adapter soft state
404458 */
405459 static inline void
406460 megasas_disable_intr_xscale(struct megasas_instance *instance)
....@@ -416,22 +470,24 @@
416470
417471 /**
418472 * megasas_read_fw_status_reg_xscale - returns the current FW status value
419
- * @regs: MFI register set
473
+ * @instance: Adapter soft state
420474 */
421475 static u32
422
-megasas_read_fw_status_reg_xscale(struct megasas_register_set __iomem * regs)
476
+megasas_read_fw_status_reg_xscale(struct megasas_instance *instance)
423477 {
424
- return readl(&(regs)->outbound_msg_0);
478
+ return readl(&instance->reg_set->outbound_msg_0);
425479 }
426480 /**
427481 * megasas_clear_interrupt_xscale - Check & clear interrupt
428
- * @regs: MFI register set
482
+ * @instance: Adapter soft state
429483 */
430484 static int
431
-megasas_clear_intr_xscale(struct megasas_register_set __iomem * regs)
485
+megasas_clear_intr_xscale(struct megasas_instance *instance)
432486 {
433487 u32 status;
434488 u32 mfiStatus = 0;
489
+ struct megasas_register_set __iomem *regs;
490
+ regs = instance->reg_set;
435491
436492 /*
437493 * Check if it is our interrupt
....@@ -457,9 +513,10 @@
457513
458514 /**
459515 * megasas_fire_cmd_xscale - Sends command to the FW
460
- * @frame_phys_addr : Physical address of cmd
461
- * @frame_count : Number of frames for the command
462
- * @regs : MFI register set
516
+ * @instance: Adapter soft state
517
+ * @frame_phys_addr : Physical address of cmd
518
+ * @frame_count : Number of frames for the command
519
+ * @regs : MFI register set
463520 */
464521 static inline void
465522 megasas_fire_cmd_xscale(struct megasas_instance *instance,
....@@ -477,7 +534,8 @@
477534
478535 /**
479536 * megasas_adp_reset_xscale - For controller reset
480
- * @regs: MFI register set
537
+ * @instance: Adapter soft state
538
+ * @regs: MFI register set
481539 */
482540 static int
483541 megasas_adp_reset_xscale(struct megasas_instance *instance,
....@@ -518,7 +576,8 @@
518576
519577 /**
520578 * megasas_check_reset_xscale - For controller reset check
521
- * @regs: MFI register set
579
+ * @instance: Adapter soft state
580
+ * @regs: MFI register set
522581 */
523582 static int
524583 megasas_check_reset_xscale(struct megasas_instance *instance,
....@@ -547,19 +606,19 @@
547606 .issue_dcmd = megasas_issue_dcmd,
548607 };
549608
550
-/**
551
-* This is the end of set of functions & definitions specific
552
-* to xscale (deviceid : 1064R, PERC5) controllers
553
-*/
609
+/*
610
+ * This is the end of set of functions & definitions specific
611
+ * to xscale (deviceid : 1064R, PERC5) controllers
612
+ */
554613
555
-/**
556
-* The following functions are defined for ppc (deviceid : 0x60)
557
-* controllers
558
-*/
614
+/*
615
+ * The following functions are defined for ppc (deviceid : 0x60)
616
+ * controllers
617
+ */
559618
560619 /**
561620 * megasas_enable_intr_ppc - Enables interrupts
562
- * @regs: MFI register set
621
+ * @instance: Adapter soft state
563622 */
564623 static inline void
565624 megasas_enable_intr_ppc(struct megasas_instance *instance)
....@@ -577,7 +636,7 @@
577636
578637 /**
579638 * megasas_disable_intr_ppc - Disable interrupt
580
- * @regs: MFI register set
639
+ * @instance: Adapter soft state
581640 */
582641 static inline void
583642 megasas_disable_intr_ppc(struct megasas_instance *instance)
....@@ -593,22 +652,24 @@
593652
594653 /**
595654 * megasas_read_fw_status_reg_ppc - returns the current FW status value
596
- * @regs: MFI register set
655
+ * @instance: Adapter soft state
597656 */
598657 static u32
599
-megasas_read_fw_status_reg_ppc(struct megasas_register_set __iomem * regs)
658
+megasas_read_fw_status_reg_ppc(struct megasas_instance *instance)
600659 {
601
- return readl(&(regs)->outbound_scratch_pad);
660
+ return readl(&instance->reg_set->outbound_scratch_pad_0);
602661 }
603662
604663 /**
605664 * megasas_clear_interrupt_ppc - Check & clear interrupt
606
- * @regs: MFI register set
665
+ * @instance: Adapter soft state
607666 */
608667 static int
609
-megasas_clear_intr_ppc(struct megasas_register_set __iomem * regs)
668
+megasas_clear_intr_ppc(struct megasas_instance *instance)
610669 {
611670 u32 status, mfiStatus = 0;
671
+ struct megasas_register_set __iomem *regs;
672
+ regs = instance->reg_set;
612673
613674 /*
614675 * Check if it is our interrupt
....@@ -634,9 +695,10 @@
634695
635696 /**
636697 * megasas_fire_cmd_ppc - Sends command to the FW
637
- * @frame_phys_addr : Physical address of cmd
638
- * @frame_count : Number of frames for the command
639
- * @regs : MFI register set
698
+ * @instance: Adapter soft state
699
+ * @frame_phys_addr: Physical address of cmd
700
+ * @frame_count: Number of frames for the command
701
+ * @regs: MFI register set
640702 */
641703 static inline void
642704 megasas_fire_cmd_ppc(struct megasas_instance *instance,
....@@ -654,7 +716,8 @@
654716
655717 /**
656718 * megasas_check_reset_ppc - For controller reset check
657
- * @regs: MFI register set
719
+ * @instance: Adapter soft state
720
+ * @regs: MFI register set
658721 */
659722 static int
660723 megasas_check_reset_ppc(struct megasas_instance *instance,
....@@ -684,7 +747,7 @@
684747
685748 /**
686749 * megasas_enable_intr_skinny - Enables interrupts
687
- * @regs: MFI register set
750
+ * @instance: Adapter soft state
688751 */
689752 static inline void
690753 megasas_enable_intr_skinny(struct megasas_instance *instance)
....@@ -702,7 +765,7 @@
702765
703766 /**
704767 * megasas_disable_intr_skinny - Disables interrupt
705
- * @regs: MFI register set
768
+ * @instance: Adapter soft state
706769 */
707770 static inline void
708771 megasas_disable_intr_skinny(struct megasas_instance *instance)
....@@ -718,23 +781,25 @@
718781
719782 /**
720783 * megasas_read_fw_status_reg_skinny - returns the current FW status value
721
- * @regs: MFI register set
784
+ * @instance: Adapter soft state
722785 */
723786 static u32
724
-megasas_read_fw_status_reg_skinny(struct megasas_register_set __iomem *regs)
787
+megasas_read_fw_status_reg_skinny(struct megasas_instance *instance)
725788 {
726
- return readl(&(regs)->outbound_scratch_pad);
789
+ return readl(&instance->reg_set->outbound_scratch_pad_0);
727790 }
728791
729792 /**
730793 * megasas_clear_interrupt_skinny - Check & clear interrupt
731
- * @regs: MFI register set
794
+ * @instance: Adapter soft state
732795 */
733796 static int
734
-megasas_clear_intr_skinny(struct megasas_register_set __iomem *regs)
797
+megasas_clear_intr_skinny(struct megasas_instance *instance)
735798 {
736799 u32 status;
737800 u32 mfiStatus = 0;
801
+ struct megasas_register_set __iomem *regs;
802
+ regs = instance->reg_set;
738803
739804 /*
740805 * Check if it is our interrupt
....@@ -748,7 +813,7 @@
748813 /*
749814 * Check if it is our interrupt
750815 */
751
- if ((megasas_read_fw_status_reg_skinny(regs) & MFI_STATE_MASK) ==
816
+ if ((megasas_read_fw_status_reg_skinny(instance) & MFI_STATE_MASK) ==
752817 MFI_STATE_FAULT) {
753818 mfiStatus = MFI_INTR_FLAG_FIRMWARE_STATE_CHANGE;
754819 } else
....@@ -769,9 +834,10 @@
769834
770835 /**
771836 * megasas_fire_cmd_skinny - Sends command to the FW
772
- * @frame_phys_addr : Physical address of cmd
773
- * @frame_count : Number of frames for the command
774
- * @regs : MFI register set
837
+ * @instance: Adapter soft state
838
+ * @frame_phys_addr: Physical address of cmd
839
+ * @frame_count: Number of frames for the command
840
+ * @regs: MFI register set
775841 */
776842 static inline void
777843 megasas_fire_cmd_skinny(struct megasas_instance *instance,
....@@ -786,13 +852,13 @@
786852 &(regs)->inbound_high_queue_port);
787853 writel((lower_32_bits(frame_phys_addr) | (frame_count<<1))|1,
788854 &(regs)->inbound_low_queue_port);
789
- mmiowb();
790855 spin_unlock_irqrestore(&instance->hba_lock, flags);
791856 }
792857
793858 /**
794859 * megasas_check_reset_skinny - For controller reset check
795
- * @regs: MFI register set
860
+ * @instance: Adapter soft state
861
+ * @regs: MFI register set
796862 */
797863 static int
798864 megasas_check_reset_skinny(struct megasas_instance *instance,
....@@ -821,14 +887,14 @@
821887 };
822888
823889
824
-/**
825
-* The following functions are defined for gen2 (deviceid : 0x78 0x79)
826
-* controllers
827
-*/
890
+/*
891
+ * The following functions are defined for gen2 (deviceid : 0x78 0x79)
892
+ * controllers
893
+ */
828894
829895 /**
830896 * megasas_enable_intr_gen2 - Enables interrupts
831
- * @regs: MFI register set
897
+ * @instance: Adapter soft state
832898 */
833899 static inline void
834900 megasas_enable_intr_gen2(struct megasas_instance *instance)
....@@ -847,7 +913,7 @@
847913
848914 /**
849915 * megasas_disable_intr_gen2 - Disables interrupt
850
- * @regs: MFI register set
916
+ * @instance: Adapter soft state
851917 */
852918 static inline void
853919 megasas_disable_intr_gen2(struct megasas_instance *instance)
....@@ -863,23 +929,25 @@
863929
864930 /**
865931 * megasas_read_fw_status_reg_gen2 - returns the current FW status value
866
- * @regs: MFI register set
932
+ * @instance: Adapter soft state
867933 */
868934 static u32
869
-megasas_read_fw_status_reg_gen2(struct megasas_register_set __iomem *regs)
935
+megasas_read_fw_status_reg_gen2(struct megasas_instance *instance)
870936 {
871
- return readl(&(regs)->outbound_scratch_pad);
937
+ return readl(&instance->reg_set->outbound_scratch_pad_0);
872938 }
873939
874940 /**
875941 * megasas_clear_interrupt_gen2 - Check & clear interrupt
876
- * @regs: MFI register set
942
+ * @instance: Adapter soft state
877943 */
878944 static int
879
-megasas_clear_intr_gen2(struct megasas_register_set __iomem *regs)
945
+megasas_clear_intr_gen2(struct megasas_instance *instance)
880946 {
881947 u32 status;
882948 u32 mfiStatus = 0;
949
+ struct megasas_register_set __iomem *regs;
950
+ regs = instance->reg_set;
883951
884952 /*
885953 * Check if it is our interrupt
....@@ -904,11 +972,13 @@
904972
905973 return mfiStatus;
906974 }
975
+
907976 /**
908977 * megasas_fire_cmd_gen2 - Sends command to the FW
909
- * @frame_phys_addr : Physical address of cmd
910
- * @frame_count : Number of frames for the command
911
- * @regs : MFI register set
978
+ * @instance: Adapter soft state
979
+ * @frame_phys_addr: Physical address of cmd
980
+ * @frame_count: Number of frames for the command
981
+ * @regs: MFI register set
912982 */
913983 static inline void
914984 megasas_fire_cmd_gen2(struct megasas_instance *instance,
....@@ -926,7 +996,8 @@
926996
927997 /**
928998 * megasas_adp_reset_gen2 - For controller reset
929
- * @regs: MFI register set
999
+ * @instance: Adapter soft state
1000
+ * @reg_set: MFI register set
9301001 */
9311002 static int
9321003 megasas_adp_reset_gen2(struct megasas_instance *instance,
....@@ -986,7 +1057,8 @@
9861057
9871058 /**
9881059 * megasas_check_reset_gen2 - For controller reset check
989
- * @regs: MFI register set
1060
+ * @instance: Adapter soft state
1061
+ * @regs: MFI register set
9901062 */
9911063 static int
9921064 megasas_check_reset_gen2(struct megasas_instance *instance,
....@@ -1014,10 +1086,10 @@
10141086 .issue_dcmd = megasas_issue_dcmd,
10151087 };
10161088
1017
-/**
1018
-* This is the end of set of functions & definitions
1019
-* specific to gen2 (deviceid : 0x78, 0x79) controllers
1020
-*/
1089
+/*
1090
+ * This is the end of set of functions & definitions
1091
+ * specific to gen2 (deviceid : 0x78, 0x79) controllers
1092
+ */
10211093
10221094 /*
10231095 * Template added for TB (Fusion)
....@@ -1042,7 +1114,7 @@
10421114 if (atomic_read(&instance->adprecovery) == MEGASAS_HW_CRITICAL_ERROR) {
10431115 dev_err(&instance->pdev->dev, "Failed from %s %d\n",
10441116 __func__, __LINE__);
1045
- return DCMD_NOT_FIRED;
1117
+ return DCMD_INIT;
10461118 }
10471119
10481120 instance->instancet->issue_dcmd(instance, cmd);
....@@ -1066,30 +1138,30 @@
10661138 struct megasas_cmd *cmd, int timeout)
10671139 {
10681140 int ret = 0;
1069
- cmd->cmd_status_drv = MFI_STAT_INVALID_STATUS;
1141
+ cmd->cmd_status_drv = DCMD_INIT;
10701142
10711143 if (atomic_read(&instance->adprecovery) == MEGASAS_HW_CRITICAL_ERROR) {
10721144 dev_err(&instance->pdev->dev, "Failed from %s %d\n",
10731145 __func__, __LINE__);
1074
- return DCMD_NOT_FIRED;
1146
+ return DCMD_INIT;
10751147 }
10761148
10771149 instance->instancet->issue_dcmd(instance, cmd);
10781150
10791151 if (timeout) {
10801152 ret = wait_event_timeout(instance->int_cmd_wait_q,
1081
- cmd->cmd_status_drv != MFI_STAT_INVALID_STATUS, timeout * HZ);
1153
+ cmd->cmd_status_drv != DCMD_INIT, timeout * HZ);
10821154 if (!ret) {
1083
- dev_err(&instance->pdev->dev, "Failed from %s %d DCMD Timed out\n",
1084
- __func__, __LINE__);
1155
+ dev_err(&instance->pdev->dev,
1156
+ "DCMD(opcode: 0x%x) is timed out, func:%s\n",
1157
+ cmd->frame->dcmd.opcode, __func__);
10851158 return DCMD_TIMEOUT;
10861159 }
10871160 } else
10881161 wait_event(instance->int_cmd_wait_q,
1089
- cmd->cmd_status_drv != MFI_STAT_INVALID_STATUS);
1162
+ cmd->cmd_status_drv != DCMD_INIT);
10901163
1091
- return (cmd->cmd_status_drv == MFI_STAT_OK) ?
1092
- DCMD_SUCCESS : DCMD_FAILED;
1164
+ return cmd->cmd_status_drv;
10931165 }
10941166
10951167 /**
....@@ -1110,6 +1182,7 @@
11101182 struct megasas_cmd *cmd;
11111183 struct megasas_abort_frame *abort_fr;
11121184 int ret = 0;
1185
+ u32 opcode;
11131186
11141187 cmd = megasas_get_cmd(instance);
11151188
....@@ -1131,33 +1204,34 @@
11311204 cpu_to_le32(upper_32_bits(cmd_to_abort->frame_phys_addr));
11321205
11331206 cmd->sync_cmd = 1;
1134
- cmd->cmd_status_drv = MFI_STAT_INVALID_STATUS;
1207
+ cmd->cmd_status_drv = DCMD_INIT;
11351208
11361209 if (atomic_read(&instance->adprecovery) == MEGASAS_HW_CRITICAL_ERROR) {
11371210 dev_err(&instance->pdev->dev, "Failed from %s %d\n",
11381211 __func__, __LINE__);
1139
- return DCMD_NOT_FIRED;
1212
+ return DCMD_INIT;
11401213 }
11411214
11421215 instance->instancet->issue_dcmd(instance, cmd);
11431216
11441217 if (timeout) {
11451218 ret = wait_event_timeout(instance->abort_cmd_wait_q,
1146
- cmd->cmd_status_drv != MFI_STAT_INVALID_STATUS, timeout * HZ);
1219
+ cmd->cmd_status_drv != DCMD_INIT, timeout * HZ);
11471220 if (!ret) {
1148
- dev_err(&instance->pdev->dev, "Failed from %s %d Abort Timed out\n",
1149
- __func__, __LINE__);
1221
+ opcode = cmd_to_abort->frame->dcmd.opcode;
1222
+ dev_err(&instance->pdev->dev,
1223
+ "Abort(to be aborted DCMD opcode: 0x%x) is timed out func:%s\n",
1224
+ opcode, __func__);
11501225 return DCMD_TIMEOUT;
11511226 }
11521227 } else
11531228 wait_event(instance->abort_cmd_wait_q,
1154
- cmd->cmd_status_drv != MFI_STAT_INVALID_STATUS);
1229
+ cmd->cmd_status_drv != DCMD_INIT);
11551230
11561231 cmd->sync_cmd = 0;
11571232
11581233 megasas_return_cmd(instance, cmd);
1159
- return (cmd->cmd_status_drv == MFI_STAT_OK) ?
1160
- DCMD_SUCCESS : DCMD_FAILED;
1234
+ return cmd->cmd_status_drv;
11611235 }
11621236
11631237 /**
....@@ -1330,11 +1404,11 @@
13301404 device_id = MEGASAS_DEV_INDEX(scp);
13311405 pthru = (struct megasas_pthru_frame *)cmd->frame;
13321406
1333
- if (scp->sc_data_direction == PCI_DMA_TODEVICE)
1407
+ if (scp->sc_data_direction == DMA_TO_DEVICE)
13341408 flags = MFI_FRAME_DIR_WRITE;
1335
- else if (scp->sc_data_direction == PCI_DMA_FROMDEVICE)
1409
+ else if (scp->sc_data_direction == DMA_FROM_DEVICE)
13361410 flags = MFI_FRAME_DIR_READ;
1337
- else if (scp->sc_data_direction == PCI_DMA_NONE)
1411
+ else if (scp->sc_data_direction == DMA_NONE)
13381412 flags = MFI_FRAME_DIR_NONE;
13391413
13401414 if (instance->flag_ieee == 1) {
....@@ -1428,9 +1502,9 @@
14281502 device_id = MEGASAS_DEV_INDEX(scp);
14291503 ldio = (struct megasas_io_frame *)cmd->frame;
14301504
1431
- if (scp->sc_data_direction == PCI_DMA_TODEVICE)
1505
+ if (scp->sc_data_direction == DMA_TO_DEVICE)
14321506 flags = MFI_FRAME_DIR_WRITE;
1433
- else if (scp->sc_data_direction == PCI_DMA_FROMDEVICE)
1507
+ else if (scp->sc_data_direction == DMA_FROM_DEVICE)
14341508 flags = MFI_FRAME_DIR_READ;
14351509
14361510 if (instance->flag_ieee == 1) {
....@@ -1550,7 +1624,7 @@
15501624 /**
15511625 * megasas_cmd_type - Checks if the cmd is for logical drive/sysPD
15521626 * and whether it's RW or non RW
1553
- * @scmd: SCSI command
1627
+ * @cmd: SCSI command
15541628 *
15551629 */
15561630 inline int megasas_cmd_type(struct scsi_cmnd *cmd)
....@@ -1690,14 +1764,15 @@
16901764
16911765 /**
16921766 * megasas_queue_command - Queue entry point
1767
+ * @shost: adapter SCSI host
16931768 * @scmd: SCSI command to be queued
1694
- * @done: Callback entry point
16951769 */
16961770 static int
16971771 megasas_queue_command(struct Scsi_Host *shost, struct scsi_cmnd *scmd)
16981772 {
16991773 struct megasas_instance *instance;
17001774 struct MR_PRIV_DEVICE *mr_device_priv_data;
1775
+ u32 ld_tgt_id;
17011776
17021777 instance = (struct megasas_instance *)
17031778 scmd->device->host->hostdata;
....@@ -1724,17 +1799,21 @@
17241799 }
17251800 }
17261801
1727
- if (atomic_read(&instance->adprecovery) == MEGASAS_HW_CRITICAL_ERROR) {
1802
+ mr_device_priv_data = scmd->device->hostdata;
1803
+ if (!mr_device_priv_data ||
1804
+ (atomic_read(&instance->adprecovery) == MEGASAS_HW_CRITICAL_ERROR)) {
17281805 scmd->result = DID_NO_CONNECT << 16;
17291806 scmd->scsi_done(scmd);
17301807 return 0;
17311808 }
17321809
1733
- mr_device_priv_data = scmd->device->hostdata;
1734
- if (!mr_device_priv_data) {
1735
- scmd->result = DID_NO_CONNECT << 16;
1736
- scmd->scsi_done(scmd);
1737
- return 0;
1810
+ if (MEGASAS_IS_LOGICAL(scmd->device)) {
1811
+ ld_tgt_id = MEGASAS_TARGET_ID(scmd->device);
1812
+ if (instance->ld_tgtid_status[ld_tgt_id] == LD_TARGET_ID_DELETED) {
1813
+ scmd->result = DID_NO_CONNECT << 16;
1814
+ scmd->scsi_done(scmd);
1815
+ return 0;
1816
+ }
17381817 }
17391818
17401819 if (atomic_read(&instance->adprecovery) != MEGASAS_HBA_OPERATIONAL)
....@@ -1826,6 +1905,10 @@
18261905
18271906 mr_device_priv_data->is_tm_capable =
18281907 raid->capability.tmCapable;
1908
+
1909
+ if (!raid->flags.isEPD)
1910
+ sdev->no_write_same = 1;
1911
+
18291912 } else if (instance->use_seqnum_jbod_fp) {
18301913 pd_index = (sdev->channel * MEGASAS_MAX_DEV_PER_CHANNEL) +
18311914 sdev->id;
....@@ -1884,6 +1967,51 @@
18841967 blk_queue_virt_boundary(sdev->request_queue, mr_nvme_pg_size - 1);
18851968 }
18861969
1970
+/*
1971
+ * megasas_set_fw_assisted_qd -
1972
+ * set device queue depth to can_queue
1973
+ * set device queue depth to fw assisted qd
1974
+ *
1975
+ * @sdev: scsi device
1976
+ * @is_target_prop true, if fw provided target properties.
1977
+ */
1978
+static void megasas_set_fw_assisted_qd(struct scsi_device *sdev,
1979
+ bool is_target_prop)
1980
+{
1981
+ u8 interface_type;
1982
+ u32 device_qd = MEGASAS_DEFAULT_CMD_PER_LUN;
1983
+ u32 tgt_device_qd;
1984
+ struct megasas_instance *instance;
1985
+ struct MR_PRIV_DEVICE *mr_device_priv_data;
1986
+
1987
+ instance = megasas_lookup_instance(sdev->host->host_no);
1988
+ mr_device_priv_data = sdev->hostdata;
1989
+ interface_type = mr_device_priv_data->interface_type;
1990
+
1991
+ switch (interface_type) {
1992
+ case SAS_PD:
1993
+ device_qd = MEGASAS_SAS_QD;
1994
+ break;
1995
+ case SATA_PD:
1996
+ device_qd = MEGASAS_SATA_QD;
1997
+ break;
1998
+ case NVME_PD:
1999
+ device_qd = MEGASAS_NVME_QD;
2000
+ break;
2001
+ }
2002
+
2003
+ if (is_target_prop) {
2004
+ tgt_device_qd = le32_to_cpu(instance->tgt_prop->device_qdepth);
2005
+ if (tgt_device_qd)
2006
+ device_qd = min(instance->host->can_queue,
2007
+ (int)tgt_device_qd);
2008
+ }
2009
+
2010
+ if (instance->enable_sdev_max_qd && interface_type != UNKNOWN_DRIVE)
2011
+ device_qd = instance->host->can_queue;
2012
+
2013
+ scsi_change_queue_depth(sdev, device_qd);
2014
+}
18872015
18882016 /*
18892017 * megasas_set_static_target_properties -
....@@ -1900,54 +2028,26 @@
19002028 static void megasas_set_static_target_properties(struct scsi_device *sdev,
19012029 bool is_target_prop)
19022030 {
1903
- u16 target_index = 0;
1904
- u8 interface_type;
1905
- u32 device_qd = MEGASAS_DEFAULT_CMD_PER_LUN;
19062031 u32 max_io_size_kb = MR_DEFAULT_NVME_MDTS_KB;
1907
- u32 tgt_device_qd;
19082032 struct megasas_instance *instance;
1909
- struct MR_PRIV_DEVICE *mr_device_priv_data;
19102033
19112034 instance = megasas_lookup_instance(sdev->host->host_no);
1912
- mr_device_priv_data = sdev->hostdata;
1913
- interface_type = mr_device_priv_data->interface_type;
19142035
19152036 /*
19162037 * The RAID firmware may require extended timeouts.
19172038 */
19182039 blk_queue_rq_timeout(sdev->request_queue, scmd_timeout * HZ);
19192040
1920
- target_index = (sdev->channel * MEGASAS_MAX_DEV_PER_CHANNEL) + sdev->id;
1921
-
1922
- switch (interface_type) {
1923
- case SAS_PD:
1924
- device_qd = MEGASAS_SAS_QD;
1925
- break;
1926
- case SATA_PD:
1927
- device_qd = MEGASAS_SATA_QD;
1928
- break;
1929
- case NVME_PD:
1930
- device_qd = MEGASAS_NVME_QD;
1931
- break;
1932
- }
1933
-
1934
- if (is_target_prop) {
1935
- tgt_device_qd = le32_to_cpu(instance->tgt_prop->device_qdepth);
1936
- if (tgt_device_qd &&
1937
- (tgt_device_qd <= instance->host->can_queue))
1938
- device_qd = tgt_device_qd;
1939
-
1940
- /* max_io_size_kb will be set to non zero for
1941
- * nvme based vd and syspd.
1942
- */
2041
+ /* max_io_size_kb will be set to non zero for
2042
+ * nvme based vd and syspd.
2043
+ */
2044
+ if (is_target_prop)
19432045 max_io_size_kb = le32_to_cpu(instance->tgt_prop->max_io_size_kb);
1944
- }
19452046
19462047 if (instance->nvme_page_size && max_io_size_kb)
19472048 megasas_set_nvme_device_properties(sdev, (max_io_size_kb << 10));
19482049
1949
- scsi_change_queue_depth(sdev, device_qd);
1950
-
2050
+ megasas_set_fw_assisted_qd(sdev, is_target_prop);
19512051 }
19522052
19532053
....@@ -1993,7 +2093,7 @@
19932093
19942094 static int megasas_slave_alloc(struct scsi_device *sdev)
19952095 {
1996
- u16 pd_index = 0;
2096
+ u16 pd_index = 0, ld_tgt_id;
19972097 struct megasas_instance *instance ;
19982098 struct MR_PRIV_DEVICE *mr_device_priv_data;
19992099
....@@ -2011,6 +2111,9 @@
20112111 goto scan_target;
20122112 }
20132113 return -ENXIO;
2114
+ } else if (!MEGASAS_IS_LUN_VALID(sdev)) {
2115
+ sdev_printk(KERN_INFO, sdev, "%s: invalid LUN\n", __func__);
2116
+ return -ENXIO;
20142117 }
20152118
20162119 scan_target:
....@@ -2018,6 +2121,14 @@
20182121 GFP_KERNEL);
20192122 if (!mr_device_priv_data)
20202123 return -ENOMEM;
2124
+
2125
+ if (MEGASAS_IS_LOGICAL(sdev)) {
2126
+ ld_tgt_id = MEGASAS_TARGET_ID(sdev);
2127
+ instance->ld_tgtid_status[ld_tgt_id] = LD_TARGET_ID_ACTIVE;
2128
+ if (megasas_dbg_lvl & LD_PD_DEBUG)
2129
+ sdev_printk(KERN_INFO, sdev, "LD target ID %d created.\n", ld_tgt_id);
2130
+ }
2131
+
20212132 sdev->hostdata = mr_device_priv_data;
20222133
20232134 atomic_set(&mr_device_priv_data->r1_ldio_hint,
....@@ -2027,6 +2138,23 @@
20272138
20282139 static void megasas_slave_destroy(struct scsi_device *sdev)
20292140 {
2141
+ u16 ld_tgt_id;
2142
+ struct megasas_instance *instance;
2143
+
2144
+ instance = megasas_lookup_instance(sdev->host->host_no);
2145
+
2146
+ if (MEGASAS_IS_LOGICAL(sdev)) {
2147
+ if (!MEGASAS_IS_LUN_VALID(sdev)) {
2148
+ sdev_printk(KERN_INFO, sdev, "%s: invalid LUN\n", __func__);
2149
+ return;
2150
+ }
2151
+ ld_tgt_id = MEGASAS_TARGET_ID(sdev);
2152
+ instance->ld_tgtid_status[ld_tgt_id] = LD_TARGET_ID_DELETED;
2153
+ if (megasas_dbg_lvl & LD_PD_DEBUG)
2154
+ sdev_printk(KERN_INFO, sdev,
2155
+ "LD target ID %d removed from OS stack\n", ld_tgt_id);
2156
+ }
2157
+
20302158 kfree(sdev->hostdata);
20312159 sdev->hostdata = NULL;
20322160 }
....@@ -2072,6 +2200,12 @@
20722200
20732201 void megaraid_sas_kill_hba(struct megasas_instance *instance)
20742202 {
2203
+ if (atomic_read(&instance->adprecovery) == MEGASAS_HW_CRITICAL_ERROR) {
2204
+ dev_warn(&instance->pdev->dev,
2205
+ "Adapter already dead, skipping kill HBA\n");
2206
+ return;
2207
+ }
2208
+
20752209 /* Set critical error to block I/O & ioctls in case caller didn't */
20762210 atomic_set(&instance->adprecovery, MEGASAS_HW_CRITICAL_ERROR);
20772211 /* Wait 1 second to ensure IO or ioctls in build have posted */
....@@ -2079,9 +2213,11 @@
20792213 if ((instance->pdev->device == PCI_DEVICE_ID_LSI_SAS0073SKINNY) ||
20802214 (instance->pdev->device == PCI_DEVICE_ID_LSI_SAS0071SKINNY) ||
20812215 (instance->adapter_type != MFI_SERIES)) {
2082
- writel(MFI_STOP_ADP, &instance->reg_set->doorbell);
2083
- /* Flush */
2084
- readl(&instance->reg_set->doorbell);
2216
+ if (!instance->requestorId) {
2217
+ writel(MFI_STOP_ADP, &instance->reg_set->doorbell);
2218
+ /* Flush */
2219
+ readl(&instance->reg_set->doorbell);
2220
+ }
20852221 if (instance->requestorId && instance->peerIsPresent)
20862222 memset(instance->ld_ids, 0xff, MEGASAS_MAX_LD_IDS);
20872223 } else {
....@@ -2191,7 +2327,7 @@
21912327 static void
21922328 process_fw_state_change_wq(struct work_struct *work);
21932329
2194
-void megasas_do_ocr(struct megasas_instance *instance)
2330
+static void megasas_do_ocr(struct megasas_instance *instance)
21952331 {
21962332 if ((instance->pdev->device == PCI_DEVICE_ID_LSI_SAS1064R) ||
21972333 (instance->pdev->device == PCI_DEVICE_ID_DELL_PERC5) ||
....@@ -2240,9 +2376,9 @@
22402376 sizeof(struct MR_LD_VF_AFFILIATION_111));
22412377 else {
22422378 new_affiliation_111 =
2243
- pci_zalloc_consistent(instance->pdev,
2244
- sizeof(struct MR_LD_VF_AFFILIATION_111),
2245
- &new_affiliation_111_h);
2379
+ dma_alloc_coherent(&instance->pdev->dev,
2380
+ sizeof(struct MR_LD_VF_AFFILIATION_111),
2381
+ &new_affiliation_111_h, GFP_KERNEL);
22462382 if (!new_affiliation_111) {
22472383 dev_printk(KERN_DEBUG, &instance->pdev->dev, "SR-IOV: Couldn't allocate "
22482384 "memory for new affiliation for scsi%d\n",
....@@ -2302,7 +2438,7 @@
23022438 }
23032439 out:
23042440 if (new_affiliation_111) {
2305
- pci_free_consistent(instance->pdev,
2441
+ dma_free_coherent(&instance->pdev->dev,
23062442 sizeof(struct MR_LD_VF_AFFILIATION_111),
23072443 new_affiliation_111,
23082444 new_affiliation_111_h);
....@@ -2347,10 +2483,9 @@
23472483 sizeof(struct MR_LD_VF_AFFILIATION));
23482484 else {
23492485 new_affiliation =
2350
- pci_zalloc_consistent(instance->pdev,
2351
- (MAX_LOGICAL_DRIVES + 1) *
2352
- sizeof(struct MR_LD_VF_AFFILIATION),
2353
- &new_affiliation_h);
2486
+ dma_alloc_coherent(&instance->pdev->dev,
2487
+ (MAX_LOGICAL_DRIVES + 1) * sizeof(struct MR_LD_VF_AFFILIATION),
2488
+ &new_affiliation_h, GFP_KERNEL);
23542489 if (!new_affiliation) {
23552490 dev_printk(KERN_DEBUG, &instance->pdev->dev, "SR-IOV: Couldn't allocate "
23562491 "memory for new affiliation for scsi%d\n",
....@@ -2470,7 +2605,7 @@
24702605 }
24712606
24722607 if (new_affiliation)
2473
- pci_free_consistent(instance->pdev,
2608
+ dma_free_coherent(&instance->pdev->dev,
24742609 (MAX_LOGICAL_DRIVES + 1) *
24752610 sizeof(struct MR_LD_VF_AFFILIATION),
24762611 new_affiliation, new_affiliation_h);
....@@ -2513,9 +2648,10 @@
25132648
25142649 if (initial) {
25152650 instance->hb_host_mem =
2516
- pci_zalloc_consistent(instance->pdev,
2517
- sizeof(struct MR_CTRL_HB_HOST_MEM),
2518
- &instance->hb_host_mem_h);
2651
+ dma_alloc_coherent(&instance->pdev->dev,
2652
+ sizeof(struct MR_CTRL_HB_HOST_MEM),
2653
+ &instance->hb_host_mem_h,
2654
+ GFP_KERNEL);
25192655 if (!instance->hb_host_mem) {
25202656 dev_printk(KERN_DEBUG, &instance->pdev->dev, "SR-IOV: Couldn't allocate"
25212657 " memory for heartbeat host memory for scsi%d\n",
....@@ -2646,7 +2782,7 @@
26462782 "reset queue\n",
26472783 reset_cmd);
26482784
2649
- reset_cmd->cmd_status_drv = MFI_STAT_INVALID_STATUS;
2785
+ reset_cmd->cmd_status_drv = DCMD_INIT;
26502786 instance->instancet->fire_cmd(instance,
26512787 reset_cmd->frame_phys_addr,
26522788 0, instance->reg_set);
....@@ -2682,7 +2818,7 @@
26822818
26832819 i = 0;
26842820 outstanding = atomic_read(&instance->fw_outstanding);
2685
- fw_state = instance->instancet->read_fw_status_reg(instance->reg_set) & MFI_STATE_MASK;
2821
+ fw_state = instance->instancet->read_fw_status_reg(instance) & MFI_STATE_MASK;
26862822
26872823 if ((!outstanding && (fw_state == MFI_STATE_OPERATIONAL)))
26882824 goto no_outstanding;
....@@ -2692,7 +2828,7 @@
26922828 do {
26932829 if ((fw_state == MFI_STATE_FAULT) || atomic_read(&instance->fw_outstanding)) {
26942830 dev_info(&instance->pdev->dev,
2695
- "%s:%d waiting_for_outstanding: before issue OCR. FW state = 0x%x, oustanding 0x%x\n",
2831
+ "%s:%d waiting_for_outstanding: before issue OCR. FW state = 0x%x, outstanding 0x%x\n",
26962832 __func__, __LINE__, fw_state, atomic_read(&instance->fw_outstanding));
26972833 if (i == 3)
26982834 goto kill_hba_and_failed;
....@@ -2711,7 +2847,7 @@
27112847
27122848 outstanding = atomic_read(&instance->fw_outstanding);
27132849
2714
- fw_state = instance->instancet->read_fw_status_reg(instance->reg_set) & MFI_STATE_MASK;
2850
+ fw_state = instance->instancet->read_fw_status_reg(instance) & MFI_STATE_MASK;
27152851 if ((!outstanding && (fw_state == MFI_STATE_OPERATIONAL)))
27162852 goto no_outstanding;
27172853 }
....@@ -2802,25 +2938,110 @@
28022938 }
28032939
28042940 /**
2805
- * megasas_dump_frame - This function will dump MPT/MFI frame
2941
+ * megasas_dump - This function will print hexdump of provided buffer.
2942
+ * @buf: Buffer to be dumped
2943
+ * @sz: Size in bytes
2944
+ * @format: Different formats of dumping e.g. format=n will
2945
+ * cause only 'n' 32 bit words to be dumped in a single
2946
+ * line.
28062947 */
2807
-static inline void
2808
-megasas_dump_frame(void *mpi_request, int sz)
2948
+inline void
2949
+megasas_dump(void *buf, int sz, int format)
28092950 {
28102951 int i;
2811
- __le32 *mfp = (__le32 *)mpi_request;
2952
+ __le32 *buf_loc = (__le32 *)buf;
28122953
2813
- printk(KERN_INFO "IO request frame:\n\t");
2814
- for (i = 0; i < sz / sizeof(__le32); i++) {
2815
- if (i && ((i % 8) == 0))
2816
- printk("\n\t");
2817
- printk("%08x ", le32_to_cpu(mfp[i]));
2954
+ for (i = 0; i < (sz / sizeof(__le32)); i++) {
2955
+ if ((i % format) == 0) {
2956
+ if (i != 0)
2957
+ printk(KERN_CONT "\n");
2958
+ printk(KERN_CONT "%08x: ", (i * 4));
2959
+ }
2960
+ printk(KERN_CONT "%08x ", le32_to_cpu(buf_loc[i]));
28182961 }
2819
- printk("\n");
2962
+ printk(KERN_CONT "\n");
2963
+}
2964
+
2965
+/**
2966
+ * megasas_dump_reg_set - This function will print hexdump of register set
2967
+ * @reg_set: Register set to be dumped
2968
+ */
2969
+inline void
2970
+megasas_dump_reg_set(void __iomem *reg_set)
2971
+{
2972
+ unsigned int i, sz = 256;
2973
+ u32 __iomem *reg = (u32 __iomem *)reg_set;
2974
+
2975
+ for (i = 0; i < (sz / sizeof(u32)); i++)
2976
+ printk("%08x: %08x\n", (i * 4), readl(&reg[i]));
2977
+}
2978
+
2979
+/**
2980
+ * megasas_dump_fusion_io - This function will print key details
2981
+ * of SCSI IO
2982
+ * @scmd: SCSI command pointer of SCSI IO
2983
+ */
2984
+void
2985
+megasas_dump_fusion_io(struct scsi_cmnd *scmd)
2986
+{
2987
+ struct megasas_cmd_fusion *cmd;
2988
+ union MEGASAS_REQUEST_DESCRIPTOR_UNION *req_desc;
2989
+ struct megasas_instance *instance;
2990
+
2991
+ cmd = (struct megasas_cmd_fusion *)scmd->SCp.ptr;
2992
+ instance = (struct megasas_instance *)scmd->device->host->hostdata;
2993
+
2994
+ scmd_printk(KERN_INFO, scmd,
2995
+ "scmd: (0x%p) retries: 0x%x allowed: 0x%x\n",
2996
+ scmd, scmd->retries, scmd->allowed);
2997
+ scsi_print_command(scmd);
2998
+
2999
+ if (cmd) {
3000
+ req_desc = (union MEGASAS_REQUEST_DESCRIPTOR_UNION *)cmd->request_desc;
3001
+ scmd_printk(KERN_INFO, scmd, "Request descriptor details:\n");
3002
+ scmd_printk(KERN_INFO, scmd,
3003
+ "RequestFlags:0x%x MSIxIndex:0x%x SMID:0x%x LMID:0x%x DevHandle:0x%x\n",
3004
+ req_desc->SCSIIO.RequestFlags,
3005
+ req_desc->SCSIIO.MSIxIndex, req_desc->SCSIIO.SMID,
3006
+ req_desc->SCSIIO.LMID, req_desc->SCSIIO.DevHandle);
3007
+
3008
+ printk(KERN_INFO "IO request frame:\n");
3009
+ megasas_dump(cmd->io_request,
3010
+ MEGA_MPI2_RAID_DEFAULT_IO_FRAME_SIZE, 8);
3011
+ printk(KERN_INFO "Chain frame:\n");
3012
+ megasas_dump(cmd->sg_frame,
3013
+ instance->max_chain_frame_sz, 8);
3014
+ }
3015
+
3016
+}
3017
+
3018
+/*
3019
+ * megasas_dump_sys_regs - This function will dump system registers through
3020
+ * sysfs.
3021
+ * @reg_set: Pointer to System register set.
3022
+ * @buf: Buffer to which output is to be written.
3023
+ * @return: Number of bytes written to buffer.
3024
+ */
3025
+static inline ssize_t
3026
+megasas_dump_sys_regs(void __iomem *reg_set, char *buf)
3027
+{
3028
+ unsigned int i, sz = 256;
3029
+ int bytes_wrote = 0;
3030
+ char *loc = (char *)buf;
3031
+ u32 __iomem *reg = (u32 __iomem *)reg_set;
3032
+
3033
+ for (i = 0; i < sz / sizeof(u32); i++) {
3034
+ bytes_wrote += scnprintf(loc + bytes_wrote,
3035
+ PAGE_SIZE - bytes_wrote,
3036
+ "%08x: %08x\n", (i * 4),
3037
+ readl(&reg[i]));
3038
+ }
3039
+ return bytes_wrote;
28203040 }
28213041
28223042 /**
28233043 * megasas_reset_bus_host - Bus & host reset handler entry point
3044
+ * @scmd: Mid-layer SCSI command
28243045 */
28253046 static int megasas_reset_bus_host(struct scsi_cmnd *scmd)
28263047 {
....@@ -2830,24 +3051,20 @@
28303051 instance = (struct megasas_instance *)scmd->device->host->hostdata;
28313052
28323053 scmd_printk(KERN_INFO, scmd,
2833
- "Controller reset is requested due to IO timeout\n"
2834
- "SCSI command pointer: (%p)\t SCSI host state: %d\t"
2835
- " SCSI host busy: %d\t FW outstanding: %d\n",
2836
- scmd, scmd->device->host->shost_state,
3054
+ "OCR is requested due to IO timeout!!\n");
3055
+
3056
+ scmd_printk(KERN_INFO, scmd,
3057
+ "SCSI host state: %d SCSI host busy: %d FW outstanding: %d\n",
3058
+ scmd->device->host->shost_state,
28373059 scsi_host_busy(scmd->device->host),
28383060 atomic_read(&instance->fw_outstanding));
2839
-
28403061 /*
28413062 * First wait for all commands to complete
28423063 */
28433064 if (instance->adapter_type == MFI_SERIES) {
28443065 ret = megasas_generic_reset(scmd);
28453066 } else {
2846
- struct megasas_cmd_fusion *cmd;
2847
- cmd = (struct megasas_cmd_fusion *)scmd->SCp.ptr;
2848
- if (cmd)
2849
- megasas_dump_frame(cmd->io_request,
2850
- MEGA_MPI2_RAID_DEFAULT_IO_FRAME_SIZE);
3067
+ megasas_dump_fusion_io(scmd);
28513068 ret = megasas_reset_fusion(scmd->device->host,
28523069 SCSIIO_TIMEOUT_OCR);
28533070 }
....@@ -2997,56 +3214,51 @@
29973214 }
29983215
29993216 static ssize_t
3000
-megasas_fw_crash_buffer_store(struct device *cdev,
3217
+fw_crash_buffer_store(struct device *cdev,
30013218 struct device_attribute *attr, const char *buf, size_t count)
30023219 {
30033220 struct Scsi_Host *shost = class_to_shost(cdev);
30043221 struct megasas_instance *instance =
30053222 (struct megasas_instance *) shost->hostdata;
30063223 int val = 0;
3007
- unsigned long flags;
30083224
30093225 if (kstrtoint(buf, 0, &val) != 0)
30103226 return -EINVAL;
30113227
3012
- spin_lock_irqsave(&instance->crashdump_lock, flags);
3228
+ mutex_lock(&instance->crashdump_lock);
30133229 instance->fw_crash_buffer_offset = val;
3014
- spin_unlock_irqrestore(&instance->crashdump_lock, flags);
3230
+ mutex_unlock(&instance->crashdump_lock);
30153231 return strlen(buf);
30163232 }
30173233
30183234 static ssize_t
3019
-megasas_fw_crash_buffer_show(struct device *cdev,
3235
+fw_crash_buffer_show(struct device *cdev,
30203236 struct device_attribute *attr, char *buf)
30213237 {
30223238 struct Scsi_Host *shost = class_to_shost(cdev);
30233239 struct megasas_instance *instance =
30243240 (struct megasas_instance *) shost->hostdata;
30253241 u32 size;
3026
- unsigned long buff_addr;
30273242 unsigned long dmachunk = CRASH_DMA_BUF_SIZE;
30283243 unsigned long chunk_left_bytes;
30293244 unsigned long src_addr;
3030
- unsigned long flags;
30313245 u32 buff_offset;
30323246
3033
- spin_lock_irqsave(&instance->crashdump_lock, flags);
3247
+ mutex_lock(&instance->crashdump_lock);
30343248 buff_offset = instance->fw_crash_buffer_offset;
3035
- if (!instance->crash_dump_buf &&
3249
+ if (!instance->crash_dump_buf ||
30363250 !((instance->fw_crash_state == AVAILABLE) ||
30373251 (instance->fw_crash_state == COPYING))) {
30383252 dev_err(&instance->pdev->dev,
30393253 "Firmware crash dump is not available\n");
3040
- spin_unlock_irqrestore(&instance->crashdump_lock, flags);
3254
+ mutex_unlock(&instance->crashdump_lock);
30413255 return -EINVAL;
30423256 }
3043
-
3044
- buff_addr = (unsigned long) buf;
30453257
30463258 if (buff_offset > (instance->fw_crash_buffer_size * dmachunk)) {
30473259 dev_err(&instance->pdev->dev,
30483260 "Firmware crash dump offset is out of range\n");
3049
- spin_unlock_irqrestore(&instance->crashdump_lock, flags);
3261
+ mutex_unlock(&instance->crashdump_lock);
30503262 return 0;
30513263 }
30523264
....@@ -3058,13 +3270,13 @@
30583270 src_addr = (unsigned long)instance->crash_buf[buff_offset / dmachunk] +
30593271 (buff_offset % dmachunk);
30603272 memcpy(buf, (void *)src_addr, size);
3061
- spin_unlock_irqrestore(&instance->crashdump_lock, flags);
3273
+ mutex_unlock(&instance->crashdump_lock);
30623274
30633275 return size;
30643276 }
30653277
30663278 static ssize_t
3067
-megasas_fw_crash_buffer_size_show(struct device *cdev,
3279
+fw_crash_buffer_size_show(struct device *cdev,
30683280 struct device_attribute *attr, char *buf)
30693281 {
30703282 struct Scsi_Host *shost = class_to_shost(cdev);
....@@ -3076,14 +3288,13 @@
30763288 }
30773289
30783290 static ssize_t
3079
-megasas_fw_crash_state_store(struct device *cdev,
3291
+fw_crash_state_store(struct device *cdev,
30803292 struct device_attribute *attr, const char *buf, size_t count)
30813293 {
30823294 struct Scsi_Host *shost = class_to_shost(cdev);
30833295 struct megasas_instance *instance =
30843296 (struct megasas_instance *) shost->hostdata;
30853297 int val = 0;
3086
- unsigned long flags;
30873298
30883299 if (kstrtoint(buf, 0, &val) != 0)
30893300 return -EINVAL;
....@@ -3097,9 +3308,9 @@
30973308 instance->fw_crash_state = val;
30983309
30993310 if ((val == COPIED) || (val == COPY_ERROR)) {
3100
- spin_lock_irqsave(&instance->crashdump_lock, flags);
3311
+ mutex_lock(&instance->crashdump_lock);
31013312 megasas_free_host_crash_buffer(instance);
3102
- spin_unlock_irqrestore(&instance->crashdump_lock, flags);
3313
+ mutex_unlock(&instance->crashdump_lock);
31033314 if (val == COPY_ERROR)
31043315 dev_info(&instance->pdev->dev, "application failed to "
31053316 "copy Firmware crash dump\n");
....@@ -3111,7 +3322,7 @@
31113322 }
31123323
31133324 static ssize_t
3114
-megasas_fw_crash_state_show(struct device *cdev,
3325
+fw_crash_state_show(struct device *cdev,
31153326 struct device_attribute *attr, char *buf)
31163327 {
31173328 struct Scsi_Host *shost = class_to_shost(cdev);
....@@ -3122,14 +3333,14 @@
31223333 }
31233334
31243335 static ssize_t
3125
-megasas_page_size_show(struct device *cdev,
3336
+page_size_show(struct device *cdev,
31263337 struct device_attribute *attr, char *buf)
31273338 {
31283339 return snprintf(buf, PAGE_SIZE, "%ld\n", (unsigned long)PAGE_SIZE - 1);
31293340 }
31303341
31313342 static ssize_t
3132
-megasas_ldio_outstanding_show(struct device *cdev, struct device_attribute *attr,
3343
+ldio_outstanding_show(struct device *cdev, struct device_attribute *attr,
31333344 char *buf)
31343345 {
31353346 struct Scsi_Host *shost = class_to_shost(cdev);
....@@ -3139,7 +3350,7 @@
31393350 }
31403351
31413352 static ssize_t
3142
-megasas_fw_cmds_outstanding_show(struct device *cdev,
3353
+fw_cmds_outstanding_show(struct device *cdev,
31433354 struct device_attribute *attr, char *buf)
31443355 {
31453356 struct Scsi_Host *shost = class_to_shost(cdev);
....@@ -3148,26 +3359,91 @@
31483359 return snprintf(buf, PAGE_SIZE, "%d\n", atomic_read(&instance->fw_outstanding));
31493360 }
31503361
3151
-static DEVICE_ATTR(fw_crash_buffer, S_IRUGO | S_IWUSR,
3152
- megasas_fw_crash_buffer_show, megasas_fw_crash_buffer_store);
3153
-static DEVICE_ATTR(fw_crash_buffer_size, S_IRUGO,
3154
- megasas_fw_crash_buffer_size_show, NULL);
3155
-static DEVICE_ATTR(fw_crash_state, S_IRUGO | S_IWUSR,
3156
- megasas_fw_crash_state_show, megasas_fw_crash_state_store);
3157
-static DEVICE_ATTR(page_size, S_IRUGO,
3158
- megasas_page_size_show, NULL);
3159
-static DEVICE_ATTR(ldio_outstanding, S_IRUGO,
3160
- megasas_ldio_outstanding_show, NULL);
3161
-static DEVICE_ATTR(fw_cmds_outstanding, S_IRUGO,
3162
- megasas_fw_cmds_outstanding_show, NULL);
3362
+static ssize_t
3363
+enable_sdev_max_qd_show(struct device *cdev,
3364
+ struct device_attribute *attr, char *buf)
3365
+{
3366
+ struct Scsi_Host *shost = class_to_shost(cdev);
3367
+ struct megasas_instance *instance = (struct megasas_instance *)shost->hostdata;
31633368
3164
-struct device_attribute *megaraid_host_attrs[] = {
3369
+ return snprintf(buf, PAGE_SIZE, "%d\n", instance->enable_sdev_max_qd);
3370
+}
3371
+
3372
+static ssize_t
3373
+enable_sdev_max_qd_store(struct device *cdev,
3374
+ struct device_attribute *attr, const char *buf, size_t count)
3375
+{
3376
+ struct Scsi_Host *shost = class_to_shost(cdev);
3377
+ struct megasas_instance *instance = (struct megasas_instance *)shost->hostdata;
3378
+ u32 val = 0;
3379
+ bool is_target_prop;
3380
+ int ret_target_prop = DCMD_FAILED;
3381
+ struct scsi_device *sdev;
3382
+
3383
+ if (kstrtou32(buf, 0, &val) != 0) {
3384
+ pr_err("megasas: could not set enable_sdev_max_qd\n");
3385
+ return -EINVAL;
3386
+ }
3387
+
3388
+ mutex_lock(&instance->reset_mutex);
3389
+ if (val)
3390
+ instance->enable_sdev_max_qd = true;
3391
+ else
3392
+ instance->enable_sdev_max_qd = false;
3393
+
3394
+ shost_for_each_device(sdev, shost) {
3395
+ ret_target_prop = megasas_get_target_prop(instance, sdev);
3396
+ is_target_prop = (ret_target_prop == DCMD_SUCCESS) ? true : false;
3397
+ megasas_set_fw_assisted_qd(sdev, is_target_prop);
3398
+ }
3399
+ mutex_unlock(&instance->reset_mutex);
3400
+
3401
+ return strlen(buf);
3402
+}
3403
+
3404
+static ssize_t
3405
+dump_system_regs_show(struct device *cdev,
3406
+ struct device_attribute *attr, char *buf)
3407
+{
3408
+ struct Scsi_Host *shost = class_to_shost(cdev);
3409
+ struct megasas_instance *instance =
3410
+ (struct megasas_instance *)shost->hostdata;
3411
+
3412
+ return megasas_dump_sys_regs(instance->reg_set, buf);
3413
+}
3414
+
3415
+static ssize_t
3416
+raid_map_id_show(struct device *cdev, struct device_attribute *attr,
3417
+ char *buf)
3418
+{
3419
+ struct Scsi_Host *shost = class_to_shost(cdev);
3420
+ struct megasas_instance *instance =
3421
+ (struct megasas_instance *)shost->hostdata;
3422
+
3423
+ return snprintf(buf, PAGE_SIZE, "%ld\n",
3424
+ (unsigned long)instance->map_id);
3425
+}
3426
+
3427
+static DEVICE_ATTR_RW(fw_crash_buffer);
3428
+static DEVICE_ATTR_RO(fw_crash_buffer_size);
3429
+static DEVICE_ATTR_RW(fw_crash_state);
3430
+static DEVICE_ATTR_RO(page_size);
3431
+static DEVICE_ATTR_RO(ldio_outstanding);
3432
+static DEVICE_ATTR_RO(fw_cmds_outstanding);
3433
+static DEVICE_ATTR_RW(enable_sdev_max_qd);
3434
+static DEVICE_ATTR_RO(dump_system_regs);
3435
+static DEVICE_ATTR_RO(raid_map_id);
3436
+
3437
+static struct device_attribute *megaraid_host_attrs[] = {
31653438 &dev_attr_fw_crash_buffer_size,
31663439 &dev_attr_fw_crash_buffer,
31673440 &dev_attr_fw_crash_state,
31683441 &dev_attr_page_size,
31693442 &dev_attr_ldio_outstanding,
31703443 &dev_attr_fw_cmds_outstanding,
3444
+ &dev_attr_enable_sdev_max_qd,
3445
+ &dev_attr_dump_system_regs,
3446
+ &dev_attr_raid_map_id,
31713447 NULL,
31723448 };
31733449
....@@ -3189,9 +3465,8 @@
31893465 .eh_timed_out = megasas_reset_timer,
31903466 .shost_attrs = megaraid_host_attrs,
31913467 .bios_param = megasas_bios_param,
3192
- .use_clustering = ENABLE_CLUSTERING,
31933468 .change_queue_depth = scsi_change_queue_depth,
3194
- .no_write_same = 1,
3469
+ .max_segment_size = 0xffffffff,
31953470 };
31963471
31973472 /**
....@@ -3207,7 +3482,11 @@
32073482 megasas_complete_int_cmd(struct megasas_instance *instance,
32083483 struct megasas_cmd *cmd)
32093484 {
3210
- cmd->cmd_status_drv = cmd->frame->io.cmd_status;
3485
+ if (cmd->cmd_status_drv == DCMD_INIT)
3486
+ cmd->cmd_status_drv =
3487
+ (cmd->frame->io.cmd_status == MFI_STAT_OK) ?
3488
+ DCMD_SUCCESS : DCMD_FAILED;
3489
+
32113490 wake_up(&instance->int_cmd_wait_q);
32123491 }
32133492
....@@ -3226,8 +3505,24 @@
32263505 {
32273506 if (cmd->sync_cmd) {
32283507 cmd->sync_cmd = 0;
3229
- cmd->cmd_status_drv = 0;
3508
+ cmd->cmd_status_drv = DCMD_SUCCESS;
32303509 wake_up(&instance->abort_cmd_wait_q);
3510
+ }
3511
+}
3512
+
3513
+static void
3514
+megasas_set_ld_removed_by_fw(struct megasas_instance *instance)
3515
+{
3516
+ uint i;
3517
+
3518
+ for (i = 0; (i < MEGASAS_MAX_LD_IDS); i++) {
3519
+ if (instance->ld_ids_prev[i] != 0xff &&
3520
+ instance->ld_ids_from_raidmap[i] == 0xff) {
3521
+ if (megasas_dbg_lvl & LD_PD_DEBUG)
3522
+ dev_info(&instance->pdev->dev,
3523
+ "LD target ID %d removed from RAID map\n", i);
3524
+ instance->ld_tgtid_status[i] = LD_TARGET_ID_DELETED;
3525
+ }
32313526 }
32323527 }
32333528
....@@ -3281,6 +3576,7 @@
32813576 megasas_complete_int_cmd(instance, cmd);
32823577 break;
32833578 }
3579
+ fallthrough;
32843580
32853581 case MFI_CMD_LD_READ:
32863582 case MFI_CMD_LD_WRITE:
....@@ -3351,6 +3647,7 @@
33513647 case MFI_CMD_SMP:
33523648 case MFI_CMD_STP:
33533649 case MFI_CMD_NVME:
3650
+ case MFI_CMD_TOOLBOX:
33543651 megasas_complete_int_cmd(instance, cmd);
33553652 break;
33563653
....@@ -3391,9 +3688,13 @@
33913688 fusion->fast_path_io = 0;
33923689 }
33933690
3691
+ if (instance->adapter_type >= INVADER_SERIES)
3692
+ megasas_set_ld_removed_by_fw(instance);
3693
+
33943694 megasas_sync_map_info(instance);
33953695 spin_unlock_irqrestore(instance->host->host_lock,
33963696 flags);
3697
+
33973698 break;
33983699 }
33993700 if (opcode == MR_DCMD_CTRL_EVENT_GET_INFO ||
....@@ -3500,7 +3801,7 @@
35003801 dev_notice(&instance->pdev->dev, "%p synchronous cmd"
35013802 "on the internal reset queue,"
35023803 "issue it again.\n", cmd);
3503
- cmd->cmd_status_drv = MFI_STAT_INVALID_STATUS;
3804
+ cmd->cmd_status_drv = DCMD_INIT;
35043805 instance->instancet->fire_cmd(instance,
35053806 cmd->frame_phys_addr,
35063807 0, instance->reg_set);
....@@ -3538,7 +3839,7 @@
35383839 megasas_register_aen(instance, seq_num, class_locale.word);
35393840 }
35403841
3541
-/**
3842
+/*
35423843 * Move the internal reset pending commands to a deferred queue.
35433844 *
35443845 * We move the commands pending at internal reset time to a
....@@ -3546,7 +3847,7 @@
35463847 * completion of the internal reset sequence. if the internal reset
35473848 * did not complete in time, the kernel reset handler would flush
35483849 * these commands.
3549
- **/
3850
+ */
35503851 static void
35513852 megasas_internal_reset_defer_cmds(struct megasas_instance *instance)
35523853 {
....@@ -3668,9 +3969,8 @@
36683969 return IRQ_HANDLED;
36693970 }
36703971
3671
- if ((mfiStatus = instance->instancet->clear_intr(
3672
- instance->reg_set)
3673
- ) == 0) {
3972
+ mfiStatus = instance->instancet->clear_intr(instance);
3973
+ if (mfiStatus == 0) {
36743974 /* Hardware may not set outbound_intr_status in MSI-X mode */
36753975 if (!instance->msix_vectors)
36763976 return IRQ_NONE;
....@@ -3680,7 +3980,7 @@
36803980
36813981 if ((mfiStatus & MFI_INTR_FLAG_FIRMWARE_STATE_CHANGE)) {
36823982 fw_state = instance->instancet->read_fw_status_reg(
3683
- instance->reg_set) & MFI_STATE_MASK;
3983
+ instance) & MFI_STATE_MASK;
36843984
36853985 if (fw_state != MFI_STATE_FAULT) {
36863986 dev_notice(&instance->pdev->dev, "fw state:%x\n",
....@@ -3725,8 +4025,11 @@
37254025 tasklet_schedule(&instance->isr_tasklet);
37264026 return IRQ_HANDLED;
37274027 }
4028
+
37284029 /**
37294030 * megasas_isr - isr entry point
4031
+ * @irq: IRQ number
4032
+ * @devp: IRQ context address
37304033 */
37314034 static irqreturn_t megasas_isr(int irq, void *devp)
37324035 {
....@@ -3748,6 +4051,7 @@
37484051 /**
37494052 * megasas_transition_to_ready - Move the FW to READY state
37504053 * @instance: Adapter soft state
4054
+ * @ocr: Adapter reset state
37514055 *
37524056 * During the initialization, FW passes can potentially be in any one of
37534057 * several possible states. If the FW in operational, waiting-for-handshake
....@@ -3760,10 +4064,9 @@
37604064 int i;
37614065 u8 max_wait;
37624066 u32 fw_state;
3763
- u32 cur_state;
37644067 u32 abs_state, curr_abs_state;
37654068
3766
- abs_state = instance->instancet->read_fw_status_reg(instance->reg_set);
4069
+ abs_state = instance->instancet->read_fw_status_reg(instance);
37674070 fw_state = abs_state & MFI_STATE_MASK;
37684071
37694072 if (fw_state != MFI_STATE_READY)
....@@ -3775,13 +4078,18 @@
37754078 switch (fw_state) {
37764079
37774080 case MFI_STATE_FAULT:
3778
- dev_printk(KERN_DEBUG, &instance->pdev->dev, "FW in FAULT state!!\n");
4081
+ dev_printk(KERN_ERR, &instance->pdev->dev,
4082
+ "FW in FAULT state, Fault code:0x%x subcode:0x%x func:%s\n",
4083
+ abs_state & MFI_STATE_FAULT_CODE,
4084
+ abs_state & MFI_STATE_FAULT_SUBCODE, __func__);
37794085 if (ocr) {
37804086 max_wait = MEGASAS_RESET_WAIT_TIME;
3781
- cur_state = MFI_STATE_FAULT;
37824087 break;
3783
- } else
4088
+ } else {
4089
+ dev_printk(KERN_DEBUG, &instance->pdev->dev, "System Register set:\n");
4090
+ megasas_dump_reg_set(instance->reg_set);
37844091 return -ENODEV;
4092
+ }
37854093
37864094 case MFI_STATE_WAIT_HANDSHAKE:
37874095 /*
....@@ -3801,7 +4109,6 @@
38014109 &instance->reg_set->inbound_doorbell);
38024110
38034111 max_wait = MEGASAS_RESET_WAIT_TIME;
3804
- cur_state = MFI_STATE_WAIT_HANDSHAKE;
38054112 break;
38064113
38074114 case MFI_STATE_BOOT_MESSAGE_PENDING:
....@@ -3817,7 +4124,6 @@
38174124 &instance->reg_set->inbound_doorbell);
38184125
38194126 max_wait = MEGASAS_RESET_WAIT_TIME;
3820
- cur_state = MFI_STATE_BOOT_MESSAGE_PENDING;
38214127 break;
38224128
38234129 case MFI_STATE_OPERATIONAL:
....@@ -3835,7 +4141,8 @@
38354141
38364142 if (instance->adapter_type != MFI_SERIES) {
38374143 for (i = 0; i < (10 * 1000); i += 20) {
3838
- if (readl(
4144
+ if (megasas_readl(
4145
+ instance,
38394146 &instance->
38404147 reg_set->
38414148 doorbell) & 1)
....@@ -3849,7 +4156,6 @@
38494156 &instance->reg_set->inbound_doorbell);
38504157
38514158 max_wait = MEGASAS_RESET_WAIT_TIME;
3852
- cur_state = MFI_STATE_OPERATIONAL;
38534159 break;
38544160
38554161 case MFI_STATE_UNDEFINED:
....@@ -3857,37 +4163,33 @@
38574163 * This state should not last for more than 2 seconds
38584164 */
38594165 max_wait = MEGASAS_RESET_WAIT_TIME;
3860
- cur_state = MFI_STATE_UNDEFINED;
38614166 break;
38624167
38634168 case MFI_STATE_BB_INIT:
38644169 max_wait = MEGASAS_RESET_WAIT_TIME;
3865
- cur_state = MFI_STATE_BB_INIT;
38664170 break;
38674171
38684172 case MFI_STATE_FW_INIT:
38694173 max_wait = MEGASAS_RESET_WAIT_TIME;
3870
- cur_state = MFI_STATE_FW_INIT;
38714174 break;
38724175
38734176 case MFI_STATE_FW_INIT_2:
38744177 max_wait = MEGASAS_RESET_WAIT_TIME;
3875
- cur_state = MFI_STATE_FW_INIT_2;
38764178 break;
38774179
38784180 case MFI_STATE_DEVICE_SCAN:
38794181 max_wait = MEGASAS_RESET_WAIT_TIME;
3880
- cur_state = MFI_STATE_DEVICE_SCAN;
38814182 break;
38824183
38834184 case MFI_STATE_FLUSH_CACHE:
38844185 max_wait = MEGASAS_RESET_WAIT_TIME;
3885
- cur_state = MFI_STATE_FLUSH_CACHE;
38864186 break;
38874187
38884188 default:
38894189 dev_printk(KERN_DEBUG, &instance->pdev->dev, "Unknown state 0x%x\n",
38904190 fw_state);
4191
+ dev_printk(KERN_DEBUG, &instance->pdev->dev, "System Register set:\n");
4192
+ megasas_dump_reg_set(instance->reg_set);
38914193 return -ENODEV;
38924194 }
38934195
....@@ -3896,7 +4198,7 @@
38964198 */
38974199 for (i = 0; i < max_wait * 50; i++) {
38984200 curr_abs_state = instance->instancet->
3899
- read_fw_status_reg(instance->reg_set);
4201
+ read_fw_status_reg(instance);
39004202
39014203 if (abs_state == curr_abs_state) {
39024204 msleep(20);
....@@ -3910,6 +4212,8 @@
39104212 if (curr_abs_state == abs_state) {
39114213 dev_printk(KERN_DEBUG, &instance->pdev->dev, "FW state [%d] hasn't changed "
39124214 "in %d secs\n", fw_state, max_wait);
4215
+ dev_printk(KERN_DEBUG, &instance->pdev->dev, "System Register set:\n");
4216
+ megasas_dump_reg_set(instance->reg_set);
39134217 return -ENODEV;
39144218 }
39154219
....@@ -3973,21 +4277,10 @@
39734277 {
39744278 int i;
39754279 u16 max_cmd;
3976
- u32 sge_sz;
39774280 u32 frame_count;
39784281 struct megasas_cmd *cmd;
39794282
39804283 max_cmd = instance->max_mfi_cmds;
3981
-
3982
- /*
3983
- * Size of our frame is 64 bytes for MFI frame, followed by max SG
3984
- * elements and finally SCSI_SENSE_BUFFERSIZE bytes for sense buffer
3985
- */
3986
- sge_sz = (IS_DMA64) ? sizeof(struct megasas_sge64) :
3987
- sizeof(struct megasas_sge32);
3988
-
3989
- if (instance->flag_ieee)
3990
- sge_sz = sizeof(struct megasas_sge_skinny);
39914284
39924285 /*
39934286 * For MFI controllers.
....@@ -4239,8 +4532,10 @@
42394532 switch (dcmd_timeout_ocr_possible(instance)) {
42404533 case INITIATE_OCR:
42414534 cmd->flags |= DRV_DCMD_SKIP_REFIRE;
4535
+ mutex_unlock(&instance->reset_mutex);
42424536 megasas_reset_fusion(instance->host,
42434537 MFI_IO_TIMEOUT_OCR);
4538
+ mutex_lock(&instance->reset_mutex);
42444539 break;
42454540 case KILL_ADAPTER:
42464541 megaraid_sas_kill_hba(instance);
....@@ -4276,7 +4571,6 @@
42764571 struct megasas_dcmd_frame *dcmd;
42774572 struct MR_PD_LIST *ci;
42784573 struct MR_PD_ADDRESS *pd_addr;
4279
- dma_addr_t ci_h = 0;
42804574
42814575 if (instance->pd_list_not_supported) {
42824576 dev_info(&instance->pdev->dev, "MR_DCMD_PD_LIST_QUERY "
....@@ -4285,7 +4579,6 @@
42854579 }
42864580
42874581 ci = instance->pd_list_buf;
4288
- ci_h = instance->pd_list_buf_h;
42894582
42904583 cmd = megasas_get_cmd(instance);
42914584
....@@ -4358,6 +4651,9 @@
43584651
43594652 case DCMD_SUCCESS:
43604653 pd_addr = ci->addr;
4654
+ if (megasas_dbg_lvl & LD_PD_DEBUG)
4655
+ dev_info(&instance->pdev->dev, "%s, sysPD count: 0x%x\n",
4656
+ __func__, le32_to_cpu(ci->count));
43614657
43624658 if ((le32_to_cpu(ci->count) >
43634659 (MEGASAS_MAX_PD_CHANNELS * MEGASAS_MAX_DEV_PER_CHANNEL)))
....@@ -4373,6 +4669,11 @@
43734669 pd_addr->scsiDevType;
43744670 instance->local_pd_list[le16_to_cpu(pd_addr->deviceId)].driveState =
43754671 MR_PD_STATE_SYSTEM;
4672
+ if (megasas_dbg_lvl & LD_PD_DEBUG)
4673
+ dev_info(&instance->pdev->dev,
4674
+ "PD%d: targetID: 0x%03x deviceType:0x%x\n",
4675
+ pd_index, le16_to_cpu(pd_addr->deviceId),
4676
+ pd_addr->scsiDevType);
43764677 pd_addr++;
43774678 }
43784679
....@@ -4476,6 +4777,10 @@
44764777 break;
44774778
44784779 case DCMD_SUCCESS:
4780
+ if (megasas_dbg_lvl & LD_PD_DEBUG)
4781
+ dev_info(&instance->pdev->dev, "%s, LD count: 0x%x\n",
4782
+ __func__, ld_count);
4783
+
44794784 if (ld_count > instance->fw_supported_vd_count)
44804785 break;
44814786
....@@ -4485,6 +4790,10 @@
44854790 if (ci->ldList[ld_index].state != 0) {
44864791 ids = ci->ldList[ld_index].ref.targetId;
44874792 instance->ld_ids[ids] = ci->ldList[ld_index].ref.targetId;
4793
+ if (megasas_dbg_lvl & LD_PD_DEBUG)
4794
+ dev_info(&instance->pdev->dev,
4795
+ "LD%d: targetID: 0x%03x\n",
4796
+ ld_index, ids);
44884797 }
44894798 }
44904799
....@@ -4500,7 +4809,7 @@
45004809 /**
45014810 * megasas_ld_list_query - Returns FW's ld_list structure
45024811 * @instance: Adapter soft state
4503
- * @ld_list: ld_list structure
4812
+ * @query_type: ld_list structure type
45044813 *
45054814 * Issues an internal command (DCMD) to get the FW's controller PD
45064815 * list structure. This information is mainly used to find out SYSTEM
....@@ -4588,6 +4897,10 @@
45884897 case DCMD_SUCCESS:
45894898 tgtid_count = le32_to_cpu(ci->count);
45904899
4900
+ if (megasas_dbg_lvl & LD_PD_DEBUG)
4901
+ dev_info(&instance->pdev->dev, "%s, LD count: 0x%x\n",
4902
+ __func__, tgtid_count);
4903
+
45914904 if ((tgtid_count > (instance->fw_supported_vd_count)))
45924905 break;
45934906
....@@ -4595,8 +4908,145 @@
45954908 for (ld_index = 0; ld_index < tgtid_count; ld_index++) {
45964909 ids = ci->targetId[ld_index];
45974910 instance->ld_ids[ids] = ci->targetId[ld_index];
4911
+ if (megasas_dbg_lvl & LD_PD_DEBUG)
4912
+ dev_info(&instance->pdev->dev, "LD%d: targetID: 0x%03x\n",
4913
+ ld_index, ci->targetId[ld_index]);
45984914 }
45994915
4916
+ break;
4917
+ }
4918
+
4919
+ if (ret != DCMD_TIMEOUT)
4920
+ megasas_return_cmd(instance, cmd);
4921
+
4922
+ return ret;
4923
+}
4924
+
4925
+/**
4926
+ * dcmd.opcode - MR_DCMD_CTRL_DEVICE_LIST_GET
4927
+ * dcmd.mbox - reserved
4928
+ * dcmd.sge IN - ptr to return MR_HOST_DEVICE_LIST structure
4929
+ * Desc: This DCMD will return the combined device list
4930
+ * Status: MFI_STAT_OK - List returned successfully
4931
+ * MFI_STAT_INVALID_CMD - Firmware support for the feature has been
4932
+ * disabled
4933
+ * @instance: Adapter soft state
4934
+ * @is_probe: Driver probe check
4935
+ * Return: 0 if DCMD succeeded
4936
+ * non-zero if failed
4937
+ */
4938
+static int
4939
+megasas_host_device_list_query(struct megasas_instance *instance,
4940
+ bool is_probe)
4941
+{
4942
+ int ret, i, target_id;
4943
+ struct megasas_cmd *cmd;
4944
+ struct megasas_dcmd_frame *dcmd;
4945
+ struct MR_HOST_DEVICE_LIST *ci;
4946
+ u32 count;
4947
+ dma_addr_t ci_h;
4948
+
4949
+ ci = instance->host_device_list_buf;
4950
+ ci_h = instance->host_device_list_buf_h;
4951
+
4952
+ cmd = megasas_get_cmd(instance);
4953
+
4954
+ if (!cmd) {
4955
+ dev_warn(&instance->pdev->dev,
4956
+ "%s: failed to get cmd\n",
4957
+ __func__);
4958
+ return -ENOMEM;
4959
+ }
4960
+
4961
+ dcmd = &cmd->frame->dcmd;
4962
+
4963
+ memset(ci, 0, sizeof(*ci));
4964
+ memset(dcmd->mbox.b, 0, MFI_MBOX_SIZE);
4965
+
4966
+ dcmd->mbox.b[0] = is_probe ? 0 : 1;
4967
+ dcmd->cmd = MFI_CMD_DCMD;
4968
+ dcmd->cmd_status = MFI_STAT_INVALID_STATUS;
4969
+ dcmd->sge_count = 1;
4970
+ dcmd->flags = MFI_FRAME_DIR_READ;
4971
+ dcmd->timeout = 0;
4972
+ dcmd->pad_0 = 0;
4973
+ dcmd->data_xfer_len = cpu_to_le32(HOST_DEVICE_LIST_SZ);
4974
+ dcmd->opcode = cpu_to_le32(MR_DCMD_CTRL_DEVICE_LIST_GET);
4975
+
4976
+ megasas_set_dma_settings(instance, dcmd, ci_h, HOST_DEVICE_LIST_SZ);
4977
+
4978
+ if (!instance->mask_interrupts) {
4979
+ ret = megasas_issue_blocked_cmd(instance, cmd,
4980
+ MFI_IO_TIMEOUT_SECS);
4981
+ } else {
4982
+ ret = megasas_issue_polled(instance, cmd);
4983
+ cmd->flags |= DRV_DCMD_SKIP_REFIRE;
4984
+ }
4985
+
4986
+ switch (ret) {
4987
+ case DCMD_SUCCESS:
4988
+ /* Fill the internal pd_list and ld_ids array based on
4989
+ * targetIds returned by FW
4990
+ */
4991
+ count = le32_to_cpu(ci->count);
4992
+
4993
+ if (count > (MEGASAS_MAX_PD + MAX_LOGICAL_DRIVES_EXT))
4994
+ break;
4995
+
4996
+ if (megasas_dbg_lvl & LD_PD_DEBUG)
4997
+ dev_info(&instance->pdev->dev, "%s, Device count: 0x%x\n",
4998
+ __func__, count);
4999
+
5000
+ memset(instance->local_pd_list, 0,
5001
+ MEGASAS_MAX_PD * sizeof(struct megasas_pd_list));
5002
+ memset(instance->ld_ids, 0xff, MAX_LOGICAL_DRIVES_EXT);
5003
+ for (i = 0; i < count; i++) {
5004
+ target_id = le16_to_cpu(ci->host_device_list[i].target_id);
5005
+ if (ci->host_device_list[i].flags.u.bits.is_sys_pd) {
5006
+ instance->local_pd_list[target_id].tid = target_id;
5007
+ instance->local_pd_list[target_id].driveType =
5008
+ ci->host_device_list[i].scsi_type;
5009
+ instance->local_pd_list[target_id].driveState =
5010
+ MR_PD_STATE_SYSTEM;
5011
+ if (megasas_dbg_lvl & LD_PD_DEBUG)
5012
+ dev_info(&instance->pdev->dev,
5013
+ "Device %d: PD targetID: 0x%03x deviceType:0x%x\n",
5014
+ i, target_id, ci->host_device_list[i].scsi_type);
5015
+ } else {
5016
+ instance->ld_ids[target_id] = target_id;
5017
+ if (megasas_dbg_lvl & LD_PD_DEBUG)
5018
+ dev_info(&instance->pdev->dev,
5019
+ "Device %d: LD targetID: 0x%03x\n",
5020
+ i, target_id);
5021
+ }
5022
+ }
5023
+
5024
+ memcpy(instance->pd_list, instance->local_pd_list,
5025
+ sizeof(instance->pd_list));
5026
+ break;
5027
+
5028
+ case DCMD_TIMEOUT:
5029
+ switch (dcmd_timeout_ocr_possible(instance)) {
5030
+ case INITIATE_OCR:
5031
+ cmd->flags |= DRV_DCMD_SKIP_REFIRE;
5032
+ mutex_unlock(&instance->reset_mutex);
5033
+ megasas_reset_fusion(instance->host,
5034
+ MFI_IO_TIMEOUT_OCR);
5035
+ mutex_lock(&instance->reset_mutex);
5036
+ break;
5037
+ case KILL_ADAPTER:
5038
+ megaraid_sas_kill_hba(instance);
5039
+ break;
5040
+ case IGNORE_TIMEOUT:
5041
+ dev_info(&instance->pdev->dev, "Ignore DCMD timeout: %s %d\n",
5042
+ __func__, __LINE__);
5043
+ break;
5044
+ }
5045
+ break;
5046
+ case DCMD_FAILED:
5047
+ dev_err(&instance->pdev->dev,
5048
+ "%s: MR_DCMD_CTRL_DEVICE_LIST_GET failed\n",
5049
+ __func__);
46005050 break;
46015051 }
46025052
....@@ -4639,9 +5089,9 @@
46395089 }
46405090
46415091 dev_info(&instance->pdev->dev,
4642
- "firmware type\t: %s\n",
4643
- instance->supportmax256vd ? "Extended VD(240 VD)firmware" :
4644
- "Legacy(64 VD) firmware");
5092
+ "FW provided supportMaxExtLDs: %d\tmax_lds: %d\n",
5093
+ instance->ctrl_info_buf->adapterOperations3.supportMaxExtLDs ? 1 : 0,
5094
+ instance->ctrl_info_buf->max_lds);
46455095
46465096 if (instance->max_raid_mapsize) {
46475097 ventura_map_sz = instance->max_raid_mapsize *
....@@ -4664,6 +5114,89 @@
46645114 }
46655115 /* irrespective of FW raid maps, driver raid map is constant */
46665116 fusion->drv_map_sz = sizeof(struct MR_DRV_RAID_MAP_ALL);
5117
+}
5118
+
5119
+/*
5120
+ * dcmd.opcode - MR_DCMD_CTRL_SNAPDUMP_GET_PROPERTIES
5121
+ * dcmd.hdr.length - number of bytes to read
5122
+ * dcmd.sge - Ptr to MR_SNAPDUMP_PROPERTIES
5123
+ * Desc: Fill in snapdump properties
5124
+ * Status: MFI_STAT_OK- Command successful
5125
+ */
5126
+void megasas_get_snapdump_properties(struct megasas_instance *instance)
5127
+{
5128
+ int ret = 0;
5129
+ struct megasas_cmd *cmd;
5130
+ struct megasas_dcmd_frame *dcmd;
5131
+ struct MR_SNAPDUMP_PROPERTIES *ci;
5132
+ dma_addr_t ci_h = 0;
5133
+
5134
+ ci = instance->snapdump_prop;
5135
+ ci_h = instance->snapdump_prop_h;
5136
+
5137
+ if (!ci)
5138
+ return;
5139
+
5140
+ cmd = megasas_get_cmd(instance);
5141
+
5142
+ if (!cmd) {
5143
+ dev_dbg(&instance->pdev->dev, "Failed to get a free cmd\n");
5144
+ return;
5145
+ }
5146
+
5147
+ dcmd = &cmd->frame->dcmd;
5148
+
5149
+ memset(ci, 0, sizeof(*ci));
5150
+ memset(dcmd->mbox.b, 0, MFI_MBOX_SIZE);
5151
+
5152
+ dcmd->cmd = MFI_CMD_DCMD;
5153
+ dcmd->cmd_status = MFI_STAT_INVALID_STATUS;
5154
+ dcmd->sge_count = 1;
5155
+ dcmd->flags = MFI_FRAME_DIR_READ;
5156
+ dcmd->timeout = 0;
5157
+ dcmd->pad_0 = 0;
5158
+ dcmd->data_xfer_len = cpu_to_le32(sizeof(struct MR_SNAPDUMP_PROPERTIES));
5159
+ dcmd->opcode = cpu_to_le32(MR_DCMD_CTRL_SNAPDUMP_GET_PROPERTIES);
5160
+
5161
+ megasas_set_dma_settings(instance, dcmd, ci_h,
5162
+ sizeof(struct MR_SNAPDUMP_PROPERTIES));
5163
+
5164
+ if (!instance->mask_interrupts) {
5165
+ ret = megasas_issue_blocked_cmd(instance, cmd,
5166
+ MFI_IO_TIMEOUT_SECS);
5167
+ } else {
5168
+ ret = megasas_issue_polled(instance, cmd);
5169
+ cmd->flags |= DRV_DCMD_SKIP_REFIRE;
5170
+ }
5171
+
5172
+ switch (ret) {
5173
+ case DCMD_SUCCESS:
5174
+ instance->snapdump_wait_time =
5175
+ min_t(u8, ci->trigger_min_num_sec_before_ocr,
5176
+ MEGASAS_MAX_SNAP_DUMP_WAIT_TIME);
5177
+ break;
5178
+
5179
+ case DCMD_TIMEOUT:
5180
+ switch (dcmd_timeout_ocr_possible(instance)) {
5181
+ case INITIATE_OCR:
5182
+ cmd->flags |= DRV_DCMD_SKIP_REFIRE;
5183
+ mutex_unlock(&instance->reset_mutex);
5184
+ megasas_reset_fusion(instance->host,
5185
+ MFI_IO_TIMEOUT_OCR);
5186
+ mutex_lock(&instance->reset_mutex);
5187
+ break;
5188
+ case KILL_ADAPTER:
5189
+ megaraid_sas_kill_hba(instance);
5190
+ break;
5191
+ case IGNORE_TIMEOUT:
5192
+ dev_info(&instance->pdev->dev, "Ignore DCMD timeout: %s %d\n",
5193
+ __func__, __LINE__);
5194
+ break;
5195
+ }
5196
+ }
5197
+
5198
+ if (ret != DCMD_TIMEOUT)
5199
+ megasas_return_cmd(instance, cmd);
46675200 }
46685201
46695202 /**
....@@ -4725,9 +5258,11 @@
47255258 * CPU endianness format.
47265259 */
47275260 le32_to_cpus((u32 *)&ci->properties.OnOffProperties);
5261
+ le16_to_cpus((u16 *)&ci->properties.on_off_properties2);
47285262 le32_to_cpus((u32 *)&ci->adapterOperations2);
47295263 le32_to_cpus((u32 *)&ci->adapterOperations3);
47305264 le16_to_cpus((u16 *)&ci->adapter_operations4);
5265
+ le32_to_cpus((u32 *)&ci->adapter_operations5);
47315266
47325267 /* Update the latest Ext VD info.
47335268 * From Init path, store current firmware details.
....@@ -4735,17 +5270,27 @@
47355270 * in case of Firmware upgrade without system reboot.
47365271 */
47375272 megasas_update_ext_vd_details(instance);
4738
- instance->use_seqnum_jbod_fp =
5273
+ instance->support_seqnum_jbod_fp =
47395274 ci->adapterOperations3.useSeqNumJbodFP;
47405275 instance->support_morethan256jbod =
47415276 ci->adapter_operations4.support_pd_map_target_id;
47425277 instance->support_nvme_passthru =
47435278 ci->adapter_operations4.support_nvme_passthru;
5279
+ instance->support_pci_lane_margining =
5280
+ ci->adapter_operations5.support_pci_lane_margining;
47445281 instance->task_abort_tmo = ci->TaskAbortTO;
47455282 instance->max_reset_tmo = ci->MaxResetTO;
47465283
47475284 /*Check whether controller is iMR or MR */
47485285 instance->is_imr = (ci->memory_size ? 0 : 1);
5286
+
5287
+ instance->snapdump_wait_time =
5288
+ (ci->properties.on_off_properties2.enable_snap_dump ?
5289
+ MEGASAS_DEFAULT_SNAP_DUMP_WAIT_TIME : 0);
5290
+
5291
+ instance->enable_fw_dev_list =
5292
+ ci->properties.on_off_properties2.enable_fw_dev_list;
5293
+
47495294 dev_info(&instance->pdev->dev,
47505295 "controller type\t: %s(%dMB)\n",
47515296 instance->is_imr ? "iMR" : "MR",
....@@ -4764,6 +5309,10 @@
47645309 dev_info(&instance->pdev->dev,
47655310 "FW provided TM TaskAbort/Reset timeout\t: %d secs/%d secs\n",
47665311 instance->task_abort_tmo, instance->max_reset_tmo);
5312
+ dev_info(&instance->pdev->dev, "JBOD sequence map support\t: %s\n",
5313
+ instance->support_seqnum_jbod_fp ? "Yes" : "No");
5314
+ dev_info(&instance->pdev->dev, "PCI Lane Margining support\t: %s\n",
5315
+ instance->support_pci_lane_margining ? "Yes" : "No");
47675316
47685317 break;
47695318
....@@ -4771,8 +5320,10 @@
47715320 switch (dcmd_timeout_ocr_possible(instance)) {
47725321 case INITIATE_OCR:
47735322 cmd->flags |= DRV_DCMD_SKIP_REFIRE;
5323
+ mutex_unlock(&instance->reset_mutex);
47745324 megasas_reset_fusion(instance->host,
47755325 MFI_IO_TIMEOUT_OCR);
5326
+ mutex_lock(&instance->reset_mutex);
47765327 break;
47775328 case KILL_ADAPTER:
47785329 megaraid_sas_kill_hba(instance);
....@@ -4947,16 +5498,13 @@
49475498 static u32
49485499 megasas_init_adapter_mfi(struct megasas_instance *instance)
49495500 {
4950
- struct megasas_register_set __iomem *reg_set;
49515501 u32 context_sz;
49525502 u32 reply_q_sz;
4953
-
4954
- reg_set = instance->reg_set;
49555503
49565504 /*
49575505 * Get various operational parameters from status register
49585506 */
4959
- instance->max_fw_cmds = instance->instancet->read_fw_status_reg(reg_set) & 0x00FFFF;
5507
+ instance->max_fw_cmds = instance->instancet->read_fw_status_reg(instance) & 0x00FFFF;
49605508 /*
49615509 * Reduce the max supported cmds by 1. This is to ensure that the
49625510 * reply_q_sz (1 more than the max cmd that driver may send)
....@@ -4964,7 +5512,7 @@
49645512 */
49655513 instance->max_fw_cmds = instance->max_fw_cmds-1;
49665514 instance->max_mfi_cmds = instance->max_fw_cmds;
4967
- instance->max_num_sge = (instance->instancet->read_fw_status_reg(reg_set) & 0xFF0000) >>
5515
+ instance->max_num_sge = (instance->instancet->read_fw_status_reg(instance) & 0xFF0000) >>
49685516 0x10;
49695517 /*
49705518 * For MFI skinny adapters, MEGASAS_SKINNY_INT_CMDS commands
....@@ -5000,9 +5548,8 @@
50005548 context_sz = sizeof(u32);
50015549 reply_q_sz = context_sz * (instance->max_fw_cmds + 1);
50025550
5003
- instance->reply_queue = pci_alloc_consistent(instance->pdev,
5004
- reply_q_sz,
5005
- &instance->reply_queue_h);
5551
+ instance->reply_queue = dma_alloc_coherent(&instance->pdev->dev,
5552
+ reply_q_sz, &instance->reply_queue_h, GFP_KERNEL);
50065553
50075554 if (!instance->reply_queue) {
50085555 dev_printk(KERN_DEBUG, &instance->pdev->dev, "Out of DMA mem for reply queue\n");
....@@ -5021,7 +5568,7 @@
50215568
50225569 instance->fw_support_ieee = 0;
50235570 instance->fw_support_ieee =
5024
- (instance->instancet->read_fw_status_reg(reg_set) &
5571
+ (instance->instancet->read_fw_status_reg(instance) &
50255572 0x04000000);
50265573
50275574 dev_notice(&instance->pdev->dev, "megasas_init_mfi: fw_support_ieee=%d",
....@@ -5034,13 +5581,32 @@
50345581
50355582 fail_fw_init:
50365583
5037
- pci_free_consistent(instance->pdev, reply_q_sz,
5584
+ dma_free_coherent(&instance->pdev->dev, reply_q_sz,
50385585 instance->reply_queue, instance->reply_queue_h);
50395586 fail_reply_queue:
50405587 megasas_free_cmds(instance);
50415588
50425589 fail_alloc_cmds:
50435590 return 1;
5591
+}
5592
+
5593
+static
5594
+void megasas_setup_irq_poll(struct megasas_instance *instance)
5595
+{
5596
+ struct megasas_irq_context *irq_ctx;
5597
+ u32 count, i;
5598
+
5599
+ count = instance->msix_vectors > 0 ? instance->msix_vectors : 1;
5600
+
5601
+ /* Initialize IRQ poll */
5602
+ for (i = 0; i < count; i++) {
5603
+ irq_ctx = &instance->irq_context[i];
5604
+ irq_ctx->os_irq = pci_irq_vector(instance->pdev, i);
5605
+ irq_ctx->irq_poll_scheduled = false;
5606
+ irq_poll_init(&irq_ctx->irqpoll,
5607
+ instance->threshold_reply_count,
5608
+ megasas_irqpoll);
5609
+ }
50445610 }
50455611
50465612 /*
....@@ -5059,14 +5625,18 @@
50595625 pdev = instance->pdev;
50605626 instance->irq_context[0].instance = instance;
50615627 instance->irq_context[0].MSIxIndex = 0;
5628
+ snprintf(instance->irq_context->name, MEGASAS_MSIX_NAME_LEN, "%s%u",
5629
+ "megasas", instance->host->host_no);
50625630 if (request_irq(pci_irq_vector(pdev, 0),
50635631 instance->instancet->service_isr, IRQF_SHARED,
5064
- "megasas", &instance->irq_context[0])) {
5632
+ instance->irq_context->name, &instance->irq_context[0])) {
50655633 dev_err(&instance->pdev->dev,
50665634 "Failed to register IRQ from %s %d\n",
50675635 __func__, __LINE__);
50685636 return -1;
50695637 }
5638
+ instance->perf_mode = MR_LATENCY_PERF_MODE;
5639
+ instance->low_latency_index_start = 0;
50705640 return 0;
50715641 }
50725642
....@@ -5091,16 +5661,23 @@
50915661 for (i = 0; i < instance->msix_vectors; i++) {
50925662 instance->irq_context[i].instance = instance;
50935663 instance->irq_context[i].MSIxIndex = i;
5664
+ snprintf(instance->irq_context[i].name, MEGASAS_MSIX_NAME_LEN, "%s%u-msix%u",
5665
+ "megasas", instance->host->host_no, i);
50945666 if (request_irq(pci_irq_vector(pdev, i),
5095
- instance->instancet->service_isr, 0, "megasas",
5667
+ instance->instancet->service_isr, 0, instance->irq_context[i].name,
50965668 &instance->irq_context[i])) {
50975669 dev_err(&instance->pdev->dev,
50985670 "Failed to register IRQ for vector %d.\n", i);
5099
- for (j = 0; j < i; j++)
5671
+ for (j = 0; j < i; j++) {
5672
+ if (j < instance->low_latency_index_start)
5673
+ irq_set_affinity_hint(
5674
+ pci_irq_vector(pdev, j), NULL);
51005675 free_irq(pci_irq_vector(pdev, j),
51015676 &instance->irq_context[j]);
5677
+ }
51025678 /* Retry irq register for IO_APIC*/
51035679 instance->msix_vectors = 0;
5680
+ instance->msix_load_balance = false;
51045681 if (is_probe) {
51055682 pci_free_irq_vectors(instance->pdev);
51065683 return megasas_setup_irqs_ioapic(instance);
....@@ -5109,6 +5686,7 @@
51095686 }
51105687 }
51115688 }
5689
+
51125690 return 0;
51135691 }
51145692
....@@ -5121,9 +5699,22 @@
51215699 megasas_destroy_irqs(struct megasas_instance *instance) {
51225700
51235701 int i;
5702
+ int count;
5703
+ struct megasas_irq_context *irq_ctx;
5704
+
5705
+ count = instance->msix_vectors > 0 ? instance->msix_vectors : 1;
5706
+ if (instance->adapter_type != MFI_SERIES) {
5707
+ for (i = 0; i < count; i++) {
5708
+ irq_ctx = &instance->irq_context[i];
5709
+ irq_poll_disable(&irq_ctx->irqpoll);
5710
+ }
5711
+ }
51245712
51255713 if (instance->msix_vectors)
51265714 for (i = 0; i < instance->msix_vectors; i++) {
5715
+ if (i < instance->low_latency_index_start)
5716
+ irq_set_affinity_hint(
5717
+ pci_irq_vector(instance->pdev, i), NULL);
51275718 free_irq(pci_irq_vector(instance->pdev, i),
51285719 &instance->irq_context[i]);
51295720 }
....@@ -5135,7 +5726,6 @@
51355726 /**
51365727 * megasas_setup_jbod_map - setup jbod map for FP seq_number.
51375728 * @instance: Adapter soft state
5138
- * @is_probe: Driver probe check
51395729 *
51405730 * Return 0 on success.
51415731 */
....@@ -5149,10 +5739,12 @@
51495739 pd_seq_map_sz = sizeof(struct MR_PD_CFG_SEQ_NUM_SYNC) +
51505740 (sizeof(struct MR_PD_CFG_SEQ) * (MAX_PHYSICAL_DEVICES - 1));
51515741
5742
+ instance->use_seqnum_jbod_fp =
5743
+ instance->support_seqnum_jbod_fp;
51525744 if (reset_devices || !fusion ||
5153
- !instance->ctrl_info_buf->adapterOperations3.useSeqNumJbodFP) {
5745
+ !instance->support_seqnum_jbod_fp) {
51545746 dev_info(&instance->pdev->dev,
5155
- "Jbod map is not supported %s %d\n",
5747
+ "JBOD sequence map is disabled %s %d\n",
51565748 __func__, __LINE__);
51575749 instance->use_seqnum_jbod_fp = false;
51585750 return;
....@@ -5191,9 +5783,11 @@
51915783 static void megasas_setup_reply_map(struct megasas_instance *instance)
51925784 {
51935785 const struct cpumask *mask;
5194
- unsigned int queue, cpu;
5786
+ unsigned int queue, cpu, low_latency_index_start;
51955787
5196
- for (queue = 0; queue < instance->msix_vectors; queue++) {
5788
+ low_latency_index_start = instance->low_latency_index_start;
5789
+
5790
+ for (queue = low_latency_index_start; queue < instance->msix_vectors; queue++) {
51975791 mask = pci_irq_get_affinity(instance->pdev, queue);
51985792 if (!mask)
51995793 goto fallback;
....@@ -5204,8 +5798,131 @@
52045798 return;
52055799
52065800 fallback:
5207
- for_each_possible_cpu(cpu)
5208
- instance->reply_map[cpu] = cpu % instance->msix_vectors;
5801
+ queue = low_latency_index_start;
5802
+ for_each_possible_cpu(cpu) {
5803
+ instance->reply_map[cpu] = queue;
5804
+ if (queue == (instance->msix_vectors - 1))
5805
+ queue = low_latency_index_start;
5806
+ else
5807
+ queue++;
5808
+ }
5809
+}
5810
+
5811
+/**
5812
+ * megasas_get_device_list - Get the PD and LD device list from FW.
5813
+ * @instance: Adapter soft state
5814
+ * @return: Success or failure
5815
+ *
5816
+ * Issue DCMDs to Firmware to get the PD and LD list.
5817
+ * Based on the FW support, driver sends the HOST_DEVICE_LIST or combination
5818
+ * of PD_LIST/LD_LIST_QUERY DCMDs to get the device list.
5819
+ */
5820
+static
5821
+int megasas_get_device_list(struct megasas_instance *instance)
5822
+{
5823
+ memset(instance->pd_list, 0,
5824
+ (MEGASAS_MAX_PD * sizeof(struct megasas_pd_list)));
5825
+ memset(instance->ld_ids, 0xff, MEGASAS_MAX_LD_IDS);
5826
+
5827
+ if (instance->enable_fw_dev_list) {
5828
+ if (megasas_host_device_list_query(instance, true))
5829
+ return FAILED;
5830
+ } else {
5831
+ if (megasas_get_pd_list(instance) < 0) {
5832
+ dev_err(&instance->pdev->dev, "failed to get PD list\n");
5833
+ return FAILED;
5834
+ }
5835
+
5836
+ if (megasas_ld_list_query(instance,
5837
+ MR_LD_QUERY_TYPE_EXPOSED_TO_HOST)) {
5838
+ dev_err(&instance->pdev->dev, "failed to get LD list\n");
5839
+ return FAILED;
5840
+ }
5841
+ }
5842
+
5843
+ return SUCCESS;
5844
+}
5845
+
5846
+/**
5847
+ * megasas_set_high_iops_queue_affinity_hint - Set affinity hint for high IOPS queues
5848
+ * @instance: Adapter soft state
5849
+ * return: void
5850
+ */
5851
+static inline void
5852
+megasas_set_high_iops_queue_affinity_hint(struct megasas_instance *instance)
5853
+{
5854
+ int i;
5855
+ int local_numa_node;
5856
+
5857
+ if (instance->perf_mode == MR_BALANCED_PERF_MODE) {
5858
+ local_numa_node = dev_to_node(&instance->pdev->dev);
5859
+
5860
+ for (i = 0; i < instance->low_latency_index_start; i++)
5861
+ irq_set_affinity_hint(pci_irq_vector(instance->pdev, i),
5862
+ cpumask_of_node(local_numa_node));
5863
+ }
5864
+}
5865
+
5866
+static int
5867
+__megasas_alloc_irq_vectors(struct megasas_instance *instance)
5868
+{
5869
+ int i, irq_flags;
5870
+ struct irq_affinity desc = { .pre_vectors = instance->low_latency_index_start };
5871
+ struct irq_affinity *descp = &desc;
5872
+
5873
+ irq_flags = PCI_IRQ_MSIX;
5874
+
5875
+ if (instance->smp_affinity_enable)
5876
+ irq_flags |= PCI_IRQ_AFFINITY;
5877
+ else
5878
+ descp = NULL;
5879
+
5880
+ i = pci_alloc_irq_vectors_affinity(instance->pdev,
5881
+ instance->low_latency_index_start,
5882
+ instance->msix_vectors, irq_flags, descp);
5883
+
5884
+ return i;
5885
+}
5886
+
5887
+/**
5888
+ * megasas_alloc_irq_vectors - Allocate IRQ vectors/enable MSI-x vectors
5889
+ * @instance: Adapter soft state
5890
+ * return: void
5891
+ */
5892
+static void
5893
+megasas_alloc_irq_vectors(struct megasas_instance *instance)
5894
+{
5895
+ int i;
5896
+ unsigned int num_msix_req;
5897
+
5898
+ i = __megasas_alloc_irq_vectors(instance);
5899
+
5900
+ if ((instance->perf_mode == MR_BALANCED_PERF_MODE) &&
5901
+ (i != instance->msix_vectors)) {
5902
+ if (instance->msix_vectors)
5903
+ pci_free_irq_vectors(instance->pdev);
5904
+ /* Disable Balanced IOPS mode and try realloc vectors */
5905
+ instance->perf_mode = MR_LATENCY_PERF_MODE;
5906
+ instance->low_latency_index_start = 1;
5907
+ num_msix_req = num_online_cpus() + instance->low_latency_index_start;
5908
+
5909
+ instance->msix_vectors = min(num_msix_req,
5910
+ instance->msix_vectors);
5911
+
5912
+ i = __megasas_alloc_irq_vectors(instance);
5913
+
5914
+ }
5915
+
5916
+ dev_info(&instance->pdev->dev,
5917
+ "requested/available msix %d/%d\n", instance->msix_vectors, i);
5918
+
5919
+ if (i > 0)
5920
+ instance->msix_vectors = i;
5921
+ else
5922
+ instance->msix_vectors = 0;
5923
+
5924
+ if (instance->smp_affinity_enable)
5925
+ megasas_set_high_iops_queue_affinity_hint(instance);
52095926 }
52105927
52115928 /**
....@@ -5219,15 +5936,17 @@
52195936 {
52205937 u32 max_sectors_1;
52215938 u32 max_sectors_2, tmp_sectors, msix_enable;
5222
- u32 scratch_pad_2, scratch_pad_3, scratch_pad_4, status_reg;
5939
+ u32 scratch_pad_1, scratch_pad_2, scratch_pad_3, status_reg;
52235940 resource_size_t base_addr;
5224
- struct megasas_register_set __iomem *reg_set;
5941
+ void *base_addr_phys;
52255942 struct megasas_ctrl_info *ctrl_info = NULL;
52265943 unsigned long bar_list;
5227
- int i, j, loop, fw_msix_count = 0;
5944
+ int i, j, loop;
52285945 struct IOV_111 *iovPtr;
52295946 struct fusion_context *fusion;
5230
- bool do_adp_reset = true;
5947
+ bool intr_coalescing;
5948
+ unsigned int num_msix_req;
5949
+ u16 lnksta, speed;
52315950
52325951 fusion = instance->ctrl_context;
52335952
....@@ -5241,14 +5960,17 @@
52415960 }
52425961
52435962 base_addr = pci_resource_start(instance->pdev, instance->bar);
5244
- instance->reg_set = ioremap_nocache(base_addr, 8192);
5963
+ instance->reg_set = ioremap(base_addr, 8192);
52455964
52465965 if (!instance->reg_set) {
52475966 dev_printk(KERN_DEBUG, &instance->pdev->dev, "Failed to map IO mem\n");
52485967 goto fail_ioremap;
52495968 }
52505969
5251
- reg_set = instance->reg_set;
5970
+ base_addr_phys = &base_addr;
5971
+ dev_printk(KERN_DEBUG, &instance->pdev->dev,
5972
+ "BAR:0x%lx BAR's base_addr(phys):%pa mapped virt_addr:0x%p\n",
5973
+ instance->bar, base_addr_phys, instance->reg_set);
52525974
52535975 if (instance->adapter_type != MFI_SERIES)
52545976 instance->instancet = &megasas_instance_template_fusion;
....@@ -5276,29 +5998,35 @@
52765998 }
52775999
52786000 if (megasas_transition_to_ready(instance, 0)) {
5279
- if (instance->adapter_type >= INVADER_SERIES) {
6001
+ dev_info(&instance->pdev->dev,
6002
+ "Failed to transition controller to ready from %s!\n",
6003
+ __func__);
6004
+ if (instance->adapter_type != MFI_SERIES) {
52806005 status_reg = instance->instancet->read_fw_status_reg(
5281
- instance->reg_set);
5282
- do_adp_reset = status_reg & MFI_RESET_ADAPTER;
5283
- }
5284
-
5285
- if (do_adp_reset) {
6006
+ instance);
6007
+ if (status_reg & MFI_RESET_ADAPTER) {
6008
+ if (megasas_adp_reset_wait_for_ready
6009
+ (instance, true, 0) == FAILED)
6010
+ goto fail_ready_state;
6011
+ } else {
6012
+ goto fail_ready_state;
6013
+ }
6014
+ } else {
52866015 atomic_set(&instance->fw_reset_no_pci_access, 1);
52876016 instance->instancet->adp_reset
52886017 (instance, instance->reg_set);
52896018 atomic_set(&instance->fw_reset_no_pci_access, 0);
5290
- dev_info(&instance->pdev->dev,
5291
- "FW restarted successfully from %s!\n",
5292
- __func__);
52936019
52946020 /*waiting for about 30 second before retry*/
52956021 ssleep(30);
52966022
52976023 if (megasas_transition_to_ready(instance, 0))
52986024 goto fail_ready_state;
5299
- } else {
5300
- goto fail_ready_state;
53016025 }
6026
+
6027
+ dev_info(&instance->pdev->dev,
6028
+ "FW restarted successfully from %s!\n",
6029
+ __func__);
53026030 }
53036031
53046032 megasas_init_ctrl_params(instance);
....@@ -5314,31 +6042,43 @@
53146042
53156043 fusion = instance->ctrl_context;
53166044
5317
- if (instance->adapter_type == VENTURA_SERIES) {
5318
- scratch_pad_3 =
5319
- readl(&instance->reg_set->outbound_scratch_pad_3);
5320
- instance->max_raid_mapsize = ((scratch_pad_3 >>
6045
+ if (instance->adapter_type >= VENTURA_SERIES) {
6046
+ scratch_pad_2 =
6047
+ megasas_readl(instance,
6048
+ &instance->reg_set->outbound_scratch_pad_2);
6049
+ instance->max_raid_mapsize = ((scratch_pad_2 >>
53216050 MR_MAX_RAID_MAP_SIZE_OFFSET_SHIFT) &
53226051 MR_MAX_RAID_MAP_SIZE_MASK);
53236052 }
53246053
6054
+ instance->enable_sdev_max_qd = enable_sdev_max_qd;
6055
+
6056
+ switch (instance->adapter_type) {
6057
+ case VENTURA_SERIES:
6058
+ fusion->pcie_bw_limitation = true;
6059
+ break;
6060
+ case AERO_SERIES:
6061
+ fusion->r56_div_offload = true;
6062
+ break;
6063
+ default:
6064
+ break;
6065
+ }
6066
+
53256067 /* Check if MSI-X is supported while in ready state */
5326
- msix_enable = (instance->instancet->read_fw_status_reg(reg_set) &
6068
+ msix_enable = (instance->instancet->read_fw_status_reg(instance) &
53276069 0x4000000) >> 0x1a;
53286070 if (msix_enable && !msix_disable) {
5329
- int irq_flags = PCI_IRQ_MSIX;
53306071
5331
- scratch_pad_2 = readl
5332
- (&instance->reg_set->outbound_scratch_pad_2);
6072
+ scratch_pad_1 = megasas_readl
6073
+ (instance, &instance->reg_set->outbound_scratch_pad_1);
53336074 /* Check max MSI-X vectors */
53346075 if (fusion) {
53356076 if (instance->adapter_type == THUNDERBOLT_SERIES) {
53366077 /* Thunderbolt Series*/
5337
- instance->msix_vectors = (scratch_pad_2
6078
+ instance->msix_vectors = (scratch_pad_1
53386079 & MR_MAX_REPLY_QUEUES_OFFSET) + 1;
5339
- fw_msix_count = instance->msix_vectors;
53406080 } else {
5341
- instance->msix_vectors = ((scratch_pad_2
6081
+ instance->msix_vectors = ((scratch_pad_1
53426082 & MR_MAX_REPLY_QUEUES_EXT_OFFSET)
53436083 >> MR_MAX_REPLY_QUEUES_EXT_OFFSET_SHIFT) + 1;
53446084
....@@ -5355,6 +6095,7 @@
53556095 if (instance->msix_vectors > 8)
53566096 instance->msix_combined = true;
53576097 break;
6098
+ case AERO_SERIES:
53586099 case VENTURA_SERIES:
53596100 if (instance->msix_vectors > 16)
53606101 instance->msix_combined = true;
....@@ -5362,9 +6103,15 @@
53626103 }
53636104
53646105 if (rdpq_enable)
5365
- instance->is_rdpq = (scratch_pad_2 & MR_RDPQ_MODE_OFFSET) ?
6106
+ instance->is_rdpq = (scratch_pad_1 & MR_RDPQ_MODE_OFFSET) ?
53666107 1 : 0;
5367
- fw_msix_count = instance->msix_vectors;
6108
+
6109
+ if (instance->adapter_type >= INVADER_SERIES &&
6110
+ !instance->msix_combined) {
6111
+ instance->msix_load_balance = true;
6112
+ instance->smp_affinity_enable = false;
6113
+ }
6114
+
53686115 /* Save 1-15 reply post index address to local memory
53696116 * Index 0 is already saved from reg offset
53706117 * MPI2_REPLY_POST_HOST_INDEX_OFFSET
....@@ -5377,22 +6124,91 @@
53776124 + (loop * 0x10));
53786125 }
53796126 }
6127
+
6128
+ dev_info(&instance->pdev->dev,
6129
+ "firmware supports msix\t: (%d)",
6130
+ instance->msix_vectors);
53806131 if (msix_vectors)
53816132 instance->msix_vectors = min(msix_vectors,
53826133 instance->msix_vectors);
53836134 } else /* MFI adapters */
53846135 instance->msix_vectors = 1;
5385
- /* Don't bother allocating more MSI-X vectors than cpus */
5386
- instance->msix_vectors = min(instance->msix_vectors,
5387
- (unsigned int)num_online_cpus());
5388
- if (smp_affinity_enable)
5389
- irq_flags |= PCI_IRQ_AFFINITY;
5390
- i = pci_alloc_irq_vectors(instance->pdev, 1,
5391
- instance->msix_vectors, irq_flags);
5392
- if (i > 0)
5393
- instance->msix_vectors = i;
6136
+
6137
+
6138
+ /*
6139
+ * For Aero (if some conditions are met), driver will configure a
6140
+ * few additional reply queues with interrupt coalescing enabled.
6141
+ * These queues with interrupt coalescing enabled are called
6142
+ * High IOPS queues and rest of reply queues (based on number of
6143
+ * logical CPUs) are termed as Low latency queues.
6144
+ *
6145
+ * Total Number of reply queues = High IOPS queues + low latency queues
6146
+ *
6147
+ * For rest of fusion adapters, 1 additional reply queue will be
6148
+ * reserved for management commands, rest of reply queues
6149
+ * (based on number of logical CPUs) will be used for IOs and
6150
+ * referenced as IO queues.
6151
+ * Total Number of reply queues = 1 + IO queues
6152
+ *
6153
+ * MFI adapters supports single MSI-x so single reply queue
6154
+ * will be used for IO and management commands.
6155
+ */
6156
+
6157
+ intr_coalescing = (scratch_pad_1 & MR_INTR_COALESCING_SUPPORT_OFFSET) ?
6158
+ true : false;
6159
+ if (intr_coalescing &&
6160
+ (num_online_cpus() >= MR_HIGH_IOPS_QUEUE_COUNT) &&
6161
+ (instance->msix_vectors == MEGASAS_MAX_MSIX_QUEUES))
6162
+ instance->perf_mode = MR_BALANCED_PERF_MODE;
53946163 else
5395
- instance->msix_vectors = 0;
6164
+ instance->perf_mode = MR_LATENCY_PERF_MODE;
6165
+
6166
+
6167
+ if (instance->adapter_type == AERO_SERIES) {
6168
+ pcie_capability_read_word(instance->pdev, PCI_EXP_LNKSTA, &lnksta);
6169
+ speed = lnksta & PCI_EXP_LNKSTA_CLS;
6170
+
6171
+ /*
6172
+ * For Aero, if PCIe link speed is <16 GT/s, then driver should operate
6173
+ * in latency perf mode and enable R1 PCI bandwidth algorithm
6174
+ */
6175
+ if (speed < 0x4) {
6176
+ instance->perf_mode = MR_LATENCY_PERF_MODE;
6177
+ fusion->pcie_bw_limitation = true;
6178
+ }
6179
+
6180
+ /*
6181
+ * Performance mode settings provided through module parameter-perf_mode will
6182
+ * take affect only for:
6183
+ * 1. Aero family of adapters.
6184
+ * 2. When user sets module parameter- perf_mode in range of 0-2.
6185
+ */
6186
+ if ((perf_mode >= MR_BALANCED_PERF_MODE) &&
6187
+ (perf_mode <= MR_LATENCY_PERF_MODE))
6188
+ instance->perf_mode = perf_mode;
6189
+ /*
6190
+ * If intr coalescing is not supported by controller FW, then IOPS
6191
+ * and Balanced modes are not feasible.
6192
+ */
6193
+ if (!intr_coalescing)
6194
+ instance->perf_mode = MR_LATENCY_PERF_MODE;
6195
+
6196
+ }
6197
+
6198
+ if (instance->perf_mode == MR_BALANCED_PERF_MODE)
6199
+ instance->low_latency_index_start =
6200
+ MR_HIGH_IOPS_QUEUE_COUNT;
6201
+ else
6202
+ instance->low_latency_index_start = 1;
6203
+
6204
+ num_msix_req = num_online_cpus() + instance->low_latency_index_start;
6205
+
6206
+ instance->msix_vectors = min(num_msix_req,
6207
+ instance->msix_vectors);
6208
+
6209
+ megasas_alloc_irq_vectors(instance);
6210
+ if (!instance->msix_vectors)
6211
+ instance->msix_load_balance = false;
53966212 }
53976213 /*
53986214 * MSI-X host index 0 is common for all adapter.
....@@ -5417,8 +6233,6 @@
54176233 megasas_setup_reply_map(instance);
54186234
54196235 dev_info(&instance->pdev->dev,
5420
- "firmware supports msix\t: (%d)", fw_msix_count);
5421
- dev_info(&instance->pdev->dev,
54226236 "current msix/online cpus\t: (%d/%d)\n",
54236237 instance->msix_vectors, (unsigned int)num_online_cpus());
54246238 dev_info(&instance->pdev->dev,
....@@ -5437,13 +6251,14 @@
54376251 if (instance->instancet->init_adapter(instance))
54386252 goto fail_init_adapter;
54396253
5440
- if (instance->adapter_type == VENTURA_SERIES) {
5441
- scratch_pad_4 =
5442
- readl(&instance->reg_set->outbound_scratch_pad_4);
5443
- if ((scratch_pad_4 & MR_NVME_PAGE_SIZE_MASK) >=
6254
+ if (instance->adapter_type >= VENTURA_SERIES) {
6255
+ scratch_pad_3 =
6256
+ megasas_readl(instance,
6257
+ &instance->reg_set->outbound_scratch_pad_3);
6258
+ if ((scratch_pad_3 & MR_NVME_PAGE_SIZE_MASK) >=
54446259 MR_DEFAULT_NVME_PAGE_SHIFT)
54456260 instance->nvme_page_size =
5446
- (1 << (scratch_pad_4 & MR_NVME_PAGE_SIZE_MASK));
6261
+ (1 << (scratch_pad_3 & MR_NVME_PAGE_SIZE_MASK));
54476262
54486263 dev_info(&instance->pdev->dev,
54496264 "NVME page size\t: (%d)\n", instance->nvme_page_size);
....@@ -5454,26 +6269,24 @@
54546269 megasas_setup_irqs_ioapic(instance))
54556270 goto fail_init_adapter;
54566271
6272
+ if (instance->adapter_type != MFI_SERIES)
6273
+ megasas_setup_irq_poll(instance);
6274
+
54576275 instance->instancet->enable_intr(instance);
54586276
54596277 dev_info(&instance->pdev->dev, "INIT adapter done\n");
54606278
54616279 megasas_setup_jbod_map(instance);
54626280
5463
- /** for passthrough
5464
- * the following function will get the PD LIST.
5465
- */
5466
- memset(instance->pd_list, 0,
5467
- (MEGASAS_MAX_PD * sizeof(struct megasas_pd_list)));
5468
- if (megasas_get_pd_list(instance) < 0) {
5469
- dev_err(&instance->pdev->dev, "failed to get PD list\n");
6281
+ if (megasas_get_device_list(instance) != SUCCESS) {
6282
+ dev_err(&instance->pdev->dev,
6283
+ "%s: megasas_get_device_list failed\n",
6284
+ __func__);
54706285 goto fail_get_ld_pd_list;
54716286 }
54726287
5473
- memset(instance->ld_ids, 0xff, MEGASAS_MAX_LD_IDS);
5474
-
54756288 /* stream detection initialization */
5476
- if (instance->adapter_type == VENTURA_SERIES) {
6289
+ if (instance->adapter_type >= VENTURA_SERIES) {
54776290 fusion->stream_detect_by_ld =
54786291 kcalloc(MAX_LOGICAL_DRIVES_EXT,
54796292 sizeof(struct LD_STREAM_DETECT *),
....@@ -5500,10 +6313,6 @@
55006313 = MR_STREAM_BITMAP;
55016314 }
55026315 }
5503
-
5504
- if (megasas_ld_list_query(instance,
5505
- MR_LD_QUERY_TYPE_EXPOSED_TO_HOST))
5506
- goto fail_get_ld_pd_list;
55076316
55086317 /*
55096318 * Compute the max allowed sectors per IO: The controller info has two
....@@ -5566,13 +6375,18 @@
55666375
55676376 else {
55686377 if (instance->crash_dump_buf)
5569
- pci_free_consistent(instance->pdev,
6378
+ dma_free_coherent(&instance->pdev->dev,
55706379 CRASH_DMA_BUF_SIZE,
55716380 instance->crash_dump_buf,
55726381 instance->crash_dump_h);
55736382 instance->crash_dump_buf = NULL;
55746383 }
55756384
6385
+ if (instance->snapdump_wait_time) {
6386
+ megasas_get_snapdump_properties(instance);
6387
+ dev_info(&instance->pdev->dev, "Snap dump wait time\t: %d\n",
6388
+ instance->snapdump_wait_time);
6389
+ }
55766390
55776391 dev_info(&instance->pdev->dev,
55786392 "pci id\t\t: (0x%04x)/(0x%04x)/(0x%04x)/(0x%04x)\n",
....@@ -5584,9 +6398,8 @@
55846398 instance->UnevenSpanSupport ? "yes" : "no");
55856399 dev_info(&instance->pdev->dev, "firmware crash dump : %s\n",
55866400 instance->crash_dump_drv_support ? "yes" : "no");
5587
- dev_info(&instance->pdev->dev, "jbod sync map : %s\n",
5588
- instance->use_seqnum_jbod_fp ? "yes" : "no");
5589
-
6401
+ dev_info(&instance->pdev->dev, "JBOD sequence map : %s\n",
6402
+ instance->use_seqnum_jbod_fp ? "enabled" : "disabled");
55906403
55916404 instance->max_sectors_per_req = instance->max_num_sge *
55926405 SGE_BUFFER_SIZE / 512;
....@@ -5610,14 +6423,28 @@
56106423
56116424 /* Launch SR-IOV heartbeat timer */
56126425 if (instance->requestorId) {
5613
- if (!megasas_sriov_start_heartbeat(instance, 1))
6426
+ if (!megasas_sriov_start_heartbeat(instance, 1)) {
56146427 megasas_start_timer(instance);
5615
- else
6428
+ } else {
56166429 instance->skip_heartbeat_timer_del = 1;
6430
+ goto fail_get_ld_pd_list;
6431
+ }
56176432 }
6433
+
6434
+ /*
6435
+ * Create and start watchdog thread which will monitor
6436
+ * controller state every 1 sec and trigger OCR when
6437
+ * it enters fault state
6438
+ */
6439
+ if (instance->adapter_type != MFI_SERIES)
6440
+ if (megasas_fusion_start_watchdog(instance) != SUCCESS)
6441
+ goto fail_start_watchdog;
56186442
56196443 return 0;
56206444
6445
+fail_start_watchdog:
6446
+ if (instance->requestorId && !instance->skip_heartbeat_timer_del)
6447
+ del_timer_sync(&instance->sriov_heartbeat_timer);
56216448 fail_get_ld_pd_list:
56226449 instance->instancet->disable_intr(instance);
56236450 megasas_destroy_irqs(instance);
....@@ -5648,7 +6475,7 @@
56486475 u32 reply_q_sz = sizeof(u32) *(instance->max_mfi_cmds + 1);
56496476
56506477 if (instance->reply_queue)
5651
- pci_free_consistent(instance->pdev, reply_q_sz,
6478
+ dma_free_coherent(&instance->pdev->dev, reply_q_sz,
56526479 instance->reply_queue, instance->reply_queue_h);
56536480
56546481 megasas_free_cmds(instance);
....@@ -5687,10 +6514,9 @@
56876514 }
56886515
56896516 dcmd = &cmd->frame->dcmd;
5690
- el_info = pci_zalloc_consistent(instance->pdev,
5691
- sizeof(struct megasas_evt_log_info),
5692
- &el_info_h);
5693
-
6517
+ el_info = dma_alloc_coherent(&instance->pdev->dev,
6518
+ sizeof(struct megasas_evt_log_info),
6519
+ &el_info_h, GFP_KERNEL);
56946520 if (!el_info) {
56956521 megasas_return_cmd(instance, cmd);
56966522 return -ENOMEM;
....@@ -5727,8 +6553,9 @@
57276553 eli->boot_seq_num = el_info->boot_seq_num;
57286554
57296555 dcmd_failed:
5730
- pci_free_consistent(instance->pdev, sizeof(struct megasas_evt_log_info),
5731
- el_info, el_info_h);
6556
+ dma_free_coherent(&instance->pdev->dev,
6557
+ sizeof(struct megasas_evt_log_info),
6558
+ el_info, el_info_h);
57326559
57336560 megasas_return_cmd(instance, cmd);
57346561
....@@ -5739,7 +6566,7 @@
57396566 * megasas_register_aen - Registers for asynchronous event notification
57406567 * @instance: Adapter soft state
57416568 * @seq_num: The starting sequence number
5742
- * @class_locale: Class of the event
6569
+ * @class_locale_word: Class of the event
57436570 *
57446571 * This function subscribes for AEN for events beyond the @seq_num. It requests
57456572 * to be notified if and only if the event is of type @class_locale
....@@ -5936,8 +6763,10 @@
59366763 switch (dcmd_timeout_ocr_possible(instance)) {
59376764 case INITIATE_OCR:
59386765 cmd->flags |= DRV_DCMD_SKIP_REFIRE;
6766
+ mutex_unlock(&instance->reset_mutex);
59396767 megasas_reset_fusion(instance->host,
59406768 MFI_IO_TIMEOUT_OCR);
6769
+ mutex_lock(&instance->reset_mutex);
59416770 break;
59426771 case KILL_ADAPTER:
59436772 megaraid_sas_kill_hba(instance);
....@@ -6072,7 +6901,7 @@
60726901 {
60736902 u64 consistent_mask;
60746903 struct pci_dev *pdev;
6075
- u32 scratch_pad_2;
6904
+ u32 scratch_pad_1;
60766905
60776906 pdev = instance->pdev;
60786907 consistent_mask = (instance->adapter_type >= VENTURA_SERIES) ?
....@@ -6090,10 +6919,10 @@
60906919 * If 32 bit DMA mask fails, then try for 64 bit mask
60916920 * for FW capable of handling 64 bit DMA.
60926921 */
6093
- scratch_pad_2 = readl
6094
- (&instance->reg_set->outbound_scratch_pad_2);
6922
+ scratch_pad_1 = megasas_readl
6923
+ (instance, &instance->reg_set->outbound_scratch_pad_1);
60956924
6096
- if (!(scratch_pad_2 & MR_CAN_HANDLE_64_BIT_DMA_OFFSET))
6925
+ if (!(scratch_pad_1 & MR_CAN_HANDLE_64_BIT_DMA_OFFSET))
60976926 goto fail_set_dma_mask;
60986927 else if (dma_set_mask_and_coherent(&pdev->dev,
60996928 DMA_BIT_MASK(63)))
....@@ -6108,7 +6937,7 @@
61086937 instance->consistent_mask_64bit = true;
61096938
61106939 dev_info(&pdev->dev, "%s bit DMA mask and %s bit consistent mask\n",
6111
- ((*pdev->dev.dma_mask == DMA_BIT_MASK(64)) ? "63" : "32"),
6940
+ ((*pdev->dev.dma_mask == DMA_BIT_MASK(63)) ? "63" : "32"),
61126941 (instance->consistent_mask_64bit ? "63" : "32"));
61136942
61146943 return 0;
....@@ -6122,12 +6951,14 @@
61226951 /*
61236952 * megasas_set_adapter_type - Set adapter type.
61246953 * Supported controllers can be divided in
6125
- * 4 categories- enum MR_ADAPTER_TYPE {
6126
- * MFI_SERIES = 1,
6127
- * THUNDERBOLT_SERIES = 2,
6128
- * INVADER_SERIES = 3,
6129
- * VENTURA_SERIES = 4,
6130
- * };
6954
+ * different categories-
6955
+ * enum MR_ADAPTER_TYPE {
6956
+ * MFI_SERIES = 1,
6957
+ * THUNDERBOLT_SERIES = 2,
6958
+ * INVADER_SERIES = 3,
6959
+ * VENTURA_SERIES = 4,
6960
+ * AERO_SERIES = 5,
6961
+ * };
61316962 * @instance: Adapter soft state
61326963 * return: void
61336964 */
....@@ -6138,6 +6969,12 @@
61386969 instance->adapter_type = MFI_SERIES;
61396970 } else {
61406971 switch (instance->pdev->device) {
6972
+ case PCI_DEVICE_ID_LSI_AERO_10E1:
6973
+ case PCI_DEVICE_ID_LSI_AERO_10E2:
6974
+ case PCI_DEVICE_ID_LSI_AERO_10E5:
6975
+ case PCI_DEVICE_ID_LSI_AERO_10E6:
6976
+ instance->adapter_type = AERO_SERIES;
6977
+ break;
61416978 case PCI_DEVICE_ID_LSI_VENTURA:
61426979 case PCI_DEVICE_ID_LSI_CRUSADER:
61436980 case PCI_DEVICE_ID_LSI_HARPOON:
....@@ -6167,10 +7004,10 @@
61677004
61687005 static inline int megasas_alloc_mfi_ctrl_mem(struct megasas_instance *instance)
61697006 {
6170
- instance->producer = pci_alloc_consistent(instance->pdev, sizeof(u32),
6171
- &instance->producer_h);
6172
- instance->consumer = pci_alloc_consistent(instance->pdev, sizeof(u32),
6173
- &instance->consumer_h);
7007
+ instance->producer = dma_alloc_coherent(&instance->pdev->dev,
7008
+ sizeof(u32), &instance->producer_h, GFP_KERNEL);
7009
+ instance->consumer = dma_alloc_coherent(&instance->pdev->dev,
7010
+ sizeof(u32), &instance->consumer_h, GFP_KERNEL);
61747011
61757012 if (!instance->producer || !instance->consumer) {
61767013 dev_err(&instance->pdev->dev,
....@@ -6205,6 +7042,7 @@
62057042 if (megasas_alloc_mfi_ctrl_mem(instance))
62067043 goto fail;
62077044 break;
7045
+ case AERO_SERIES:
62087046 case VENTURA_SERIES:
62097047 case THUNDERBOLT_SERIES:
62107048 case INVADER_SERIES:
....@@ -6232,11 +7070,11 @@
62327070 kfree(instance->reply_map);
62337071 if (instance->adapter_type == MFI_SERIES) {
62347072 if (instance->producer)
6235
- pci_free_consistent(instance->pdev, sizeof(u32),
7073
+ dma_free_coherent(&instance->pdev->dev, sizeof(u32),
62367074 instance->producer,
62377075 instance->producer_h);
62387076 if (instance->consumer)
6239
- pci_free_consistent(instance->pdev, sizeof(u32),
7077
+ dma_free_coherent(&instance->pdev->dev, sizeof(u32),
62407078 instance->consumer,
62417079 instance->consumer_h);
62427080 } else {
....@@ -6248,8 +7086,9 @@
62487086 * megasas_alloc_ctrl_dma_buffers - Allocate consistent DMA buffers during
62497087 * driver load time
62507088 *
6251
- * @instance- Adapter soft instance
6252
- * @return- O for SUCCESS
7089
+ * @instance: Adapter soft instance
7090
+ *
7091
+ * @return: O for SUCCESS
62537092 */
62547093 static inline
62557094 int megasas_alloc_ctrl_dma_buffers(struct megasas_instance *instance)
....@@ -6257,10 +7096,9 @@
62577096 struct pci_dev *pdev = instance->pdev;
62587097 struct fusion_context *fusion = instance->ctrl_context;
62597098
6260
- instance->evt_detail =
6261
- pci_alloc_consistent(pdev,
6262
- sizeof(struct megasas_evt_detail),
6263
- &instance->evt_detail_h);
7099
+ instance->evt_detail = dma_alloc_coherent(&pdev->dev,
7100
+ sizeof(struct megasas_evt_detail),
7101
+ &instance->evt_detail_h, GFP_KERNEL);
62647102
62657103 if (!instance->evt_detail) {
62667104 dev_err(&instance->pdev->dev,
....@@ -6280,12 +7118,32 @@
62807118 "Failed to allocate PD list buffer\n");
62817119 return -ENOMEM;
62827120 }
7121
+
7122
+ instance->snapdump_prop = dma_alloc_coherent(&pdev->dev,
7123
+ sizeof(struct MR_SNAPDUMP_PROPERTIES),
7124
+ &instance->snapdump_prop_h, GFP_KERNEL);
7125
+
7126
+ if (!instance->snapdump_prop)
7127
+ dev_err(&pdev->dev,
7128
+ "Failed to allocate snapdump properties buffer\n");
7129
+
7130
+ instance->host_device_list_buf = dma_alloc_coherent(&pdev->dev,
7131
+ HOST_DEVICE_LIST_SZ,
7132
+ &instance->host_device_list_buf_h,
7133
+ GFP_KERNEL);
7134
+
7135
+ if (!instance->host_device_list_buf) {
7136
+ dev_err(&pdev->dev,
7137
+ "Failed to allocate targetid list buffer\n");
7138
+ return -ENOMEM;
7139
+ }
7140
+
62837141 }
62847142
62857143 instance->pd_list_buf =
6286
- pci_alloc_consistent(pdev,
7144
+ dma_alloc_coherent(&pdev->dev,
62877145 MEGASAS_MAX_PD * sizeof(struct MR_PD_LIST),
6288
- &instance->pd_list_buf_h);
7146
+ &instance->pd_list_buf_h, GFP_KERNEL);
62897147
62907148 if (!instance->pd_list_buf) {
62917149 dev_err(&pdev->dev, "Failed to allocate PD list buffer\n");
....@@ -6293,9 +7151,9 @@
62937151 }
62947152
62957153 instance->ctrl_info_buf =
6296
- pci_alloc_consistent(pdev,
7154
+ dma_alloc_coherent(&pdev->dev,
62977155 sizeof(struct megasas_ctrl_info),
6298
- &instance->ctrl_info_buf_h);
7156
+ &instance->ctrl_info_buf_h, GFP_KERNEL);
62997157
63007158 if (!instance->ctrl_info_buf) {
63017159 dev_err(&pdev->dev,
....@@ -6304,9 +7162,9 @@
63047162 }
63057163
63067164 instance->ld_list_buf =
6307
- pci_alloc_consistent(pdev,
7165
+ dma_alloc_coherent(&pdev->dev,
63087166 sizeof(struct MR_LD_LIST),
6309
- &instance->ld_list_buf_h);
7167
+ &instance->ld_list_buf_h, GFP_KERNEL);
63107168
63117169 if (!instance->ld_list_buf) {
63127170 dev_err(&pdev->dev, "Failed to allocate LD list buffer\n");
....@@ -6314,9 +7172,9 @@
63147172 }
63157173
63167174 instance->ld_targetid_list_buf =
6317
- pci_alloc_consistent(pdev,
6318
- sizeof(struct MR_LD_TARGETID_LIST),
6319
- &instance->ld_targetid_list_buf_h);
7175
+ dma_alloc_coherent(&pdev->dev,
7176
+ sizeof(struct MR_LD_TARGETID_LIST),
7177
+ &instance->ld_targetid_list_buf_h, GFP_KERNEL);
63207178
63217179 if (!instance->ld_targetid_list_buf) {
63227180 dev_err(&pdev->dev,
....@@ -6326,21 +7184,20 @@
63267184
63277185 if (!reset_devices) {
63287186 instance->system_info_buf =
6329
- pci_alloc_consistent(pdev,
6330
- sizeof(struct MR_DRV_SYSTEM_INFO),
6331
- &instance->system_info_h);
7187
+ dma_alloc_coherent(&pdev->dev,
7188
+ sizeof(struct MR_DRV_SYSTEM_INFO),
7189
+ &instance->system_info_h, GFP_KERNEL);
63327190 instance->pd_info =
6333
- pci_alloc_consistent(pdev,
6334
- sizeof(struct MR_PD_INFO),
6335
- &instance->pd_info_h);
7191
+ dma_alloc_coherent(&pdev->dev,
7192
+ sizeof(struct MR_PD_INFO),
7193
+ &instance->pd_info_h, GFP_KERNEL);
63367194 instance->tgt_prop =
6337
- pci_alloc_consistent(pdev,
6338
- sizeof(struct MR_TARGET_PROPERTIES),
6339
- &instance->tgt_prop_h);
7195
+ dma_alloc_coherent(&pdev->dev,
7196
+ sizeof(struct MR_TARGET_PROPERTIES),
7197
+ &instance->tgt_prop_h, GFP_KERNEL);
63407198 instance->crash_dump_buf =
6341
- pci_alloc_consistent(pdev,
6342
- CRASH_DMA_BUF_SIZE,
6343
- &instance->crash_dump_h);
7199
+ dma_alloc_coherent(&pdev->dev, CRASH_DMA_BUF_SIZE,
7200
+ &instance->crash_dump_h, GFP_KERNEL);
63447201
63457202 if (!instance->system_info_buf)
63467203 dev_err(&instance->pdev->dev,
....@@ -6376,7 +7233,7 @@
63767233 struct fusion_context *fusion = instance->ctrl_context;
63777234
63787235 if (instance->evt_detail)
6379
- pci_free_consistent(pdev, sizeof(struct megasas_evt_detail),
7236
+ dma_free_coherent(&pdev->dev, sizeof(struct megasas_evt_detail),
63807237 instance->evt_detail,
63817238 instance->evt_detail_h);
63827239
....@@ -6387,43 +7244,56 @@
63877244 fusion->ioc_init_request_phys);
63887245
63897246 if (instance->pd_list_buf)
6390
- pci_free_consistent(pdev,
7247
+ dma_free_coherent(&pdev->dev,
63917248 MEGASAS_MAX_PD * sizeof(struct MR_PD_LIST),
63927249 instance->pd_list_buf,
63937250 instance->pd_list_buf_h);
63947251
63957252 if (instance->ld_list_buf)
6396
- pci_free_consistent(pdev, sizeof(struct MR_LD_LIST),
7253
+ dma_free_coherent(&pdev->dev, sizeof(struct MR_LD_LIST),
63977254 instance->ld_list_buf,
63987255 instance->ld_list_buf_h);
63997256
64007257 if (instance->ld_targetid_list_buf)
6401
- pci_free_consistent(pdev, sizeof(struct MR_LD_TARGETID_LIST),
7258
+ dma_free_coherent(&pdev->dev, sizeof(struct MR_LD_TARGETID_LIST),
64027259 instance->ld_targetid_list_buf,
64037260 instance->ld_targetid_list_buf_h);
64047261
64057262 if (instance->ctrl_info_buf)
6406
- pci_free_consistent(pdev, sizeof(struct megasas_ctrl_info),
7263
+ dma_free_coherent(&pdev->dev, sizeof(struct megasas_ctrl_info),
64077264 instance->ctrl_info_buf,
64087265 instance->ctrl_info_buf_h);
64097266
64107267 if (instance->system_info_buf)
6411
- pci_free_consistent(pdev, sizeof(struct MR_DRV_SYSTEM_INFO),
7268
+ dma_free_coherent(&pdev->dev, sizeof(struct MR_DRV_SYSTEM_INFO),
64127269 instance->system_info_buf,
64137270 instance->system_info_h);
64147271
64157272 if (instance->pd_info)
6416
- pci_free_consistent(pdev, sizeof(struct MR_PD_INFO),
7273
+ dma_free_coherent(&pdev->dev, sizeof(struct MR_PD_INFO),
64177274 instance->pd_info, instance->pd_info_h);
64187275
64197276 if (instance->tgt_prop)
6420
- pci_free_consistent(pdev, sizeof(struct MR_TARGET_PROPERTIES),
7277
+ dma_free_coherent(&pdev->dev, sizeof(struct MR_TARGET_PROPERTIES),
64217278 instance->tgt_prop, instance->tgt_prop_h);
64227279
64237280 if (instance->crash_dump_buf)
6424
- pci_free_consistent(pdev, CRASH_DMA_BUF_SIZE,
7281
+ dma_free_coherent(&pdev->dev, CRASH_DMA_BUF_SIZE,
64257282 instance->crash_dump_buf,
64267283 instance->crash_dump_h);
7284
+
7285
+ if (instance->snapdump_prop)
7286
+ dma_free_coherent(&pdev->dev,
7287
+ sizeof(struct MR_SNAPDUMP_PROPERTIES),
7288
+ instance->snapdump_prop,
7289
+ instance->snapdump_prop_h);
7290
+
7291
+ if (instance->host_device_list_buf)
7292
+ dma_free_coherent(&pdev->dev,
7293
+ HOST_DEVICE_LIST_SZ,
7294
+ instance->host_device_list_buf,
7295
+ instance->host_device_list_buf_h);
7296
+
64277297 }
64287298
64297299 /*
....@@ -6447,11 +7317,12 @@
64477317 INIT_LIST_HEAD(&instance->internal_reset_pending_q);
64487318
64497319 atomic_set(&instance->fw_outstanding, 0);
7320
+ atomic64_set(&instance->total_io_count, 0);
64507321
64517322 init_waitqueue_head(&instance->int_cmd_wait_q);
64527323 init_waitqueue_head(&instance->abort_cmd_wait_q);
64537324
6454
- spin_lock_init(&instance->crashdump_lock);
7325
+ mutex_init(&instance->crashdump_lock);
64557326 spin_lock_init(&instance->mfi_pool_lock);
64567327 spin_lock_init(&instance->hba_lock);
64577328 spin_lock_init(&instance->stream_lock);
....@@ -6469,13 +7340,13 @@
64697340 instance->last_time = 0;
64707341 instance->disableOnlineCtrlReset = 1;
64717342 instance->UnevenSpanSupport = 0;
7343
+ instance->smp_affinity_enable = smp_affinity_enable ? true : false;
7344
+ instance->msix_load_balance = false;
64727345
6473
- if (instance->adapter_type != MFI_SERIES) {
7346
+ if (instance->adapter_type != MFI_SERIES)
64747347 INIT_WORK(&instance->work_init, megasas_fusion_ocr_wq);
6475
- INIT_WORK(&instance->crash_init, megasas_fusion_crash_dump_wq);
6476
- } else {
7348
+ else
64777349 INIT_WORK(&instance->work_init, process_fw_state_change_wq);
6478
- }
64797350 }
64807351
64817352 /**
....@@ -6490,6 +7361,19 @@
64907361 struct Scsi_Host *host;
64917362 struct megasas_instance *instance;
64927363 u16 control = 0;
7364
+
7365
+ switch (pdev->device) {
7366
+ case PCI_DEVICE_ID_LSI_AERO_10E0:
7367
+ case PCI_DEVICE_ID_LSI_AERO_10E3:
7368
+ case PCI_DEVICE_ID_LSI_AERO_10E4:
7369
+ case PCI_DEVICE_ID_LSI_AERO_10E7:
7370
+ dev_err(&pdev->dev, "Adapter is in non secure mode\n");
7371
+ return 1;
7372
+ case PCI_DEVICE_ID_LSI_AERO_10E1:
7373
+ case PCI_DEVICE_ID_LSI_AERO_10E5:
7374
+ dev_info(&pdev->dev, "Adapter is in configurable secure mode\n");
7375
+ break;
7376
+ }
64937377
64947378 /* Reset MSI-X in the kdump kernel */
64957379 if (reset_devices) {
....@@ -6549,17 +7433,20 @@
65497433 if (instance->requestorId) {
65507434 if (instance->PlasmaFW111) {
65517435 instance->vf_affiliation_111 =
6552
- pci_alloc_consistent(pdev, sizeof(struct MR_LD_VF_AFFILIATION_111),
6553
- &instance->vf_affiliation_111_h);
7436
+ dma_alloc_coherent(&pdev->dev,
7437
+ sizeof(struct MR_LD_VF_AFFILIATION_111),
7438
+ &instance->vf_affiliation_111_h,
7439
+ GFP_KERNEL);
65547440 if (!instance->vf_affiliation_111)
65557441 dev_warn(&pdev->dev, "Can't allocate "
65567442 "memory for VF affiliation buffer\n");
65577443 } else {
65587444 instance->vf_affiliation =
6559
- pci_alloc_consistent(pdev,
6560
- (MAX_LOGICAL_DRIVES + 1) *
6561
- sizeof(struct MR_LD_VF_AFFILIATION),
6562
- &instance->vf_affiliation_h);
7445
+ dma_alloc_coherent(&pdev->dev,
7446
+ (MAX_LOGICAL_DRIVES + 1) *
7447
+ sizeof(struct MR_LD_VF_AFFILIATION),
7448
+ &instance->vf_affiliation_h,
7449
+ GFP_KERNEL);
65637450 if (!instance->vf_affiliation)
65647451 dev_warn(&pdev->dev, "Can't allocate "
65657452 "memory for VF affiliation buffer\n");
....@@ -6589,7 +7476,9 @@
65897476 /*
65907477 * Trigger SCSI to scan our drives
65917478 */
6592
- scsi_scan_host(host);
7479
+ if (!instance->enable_fw_dev_list ||
7480
+ (instance->host_device_list_buf->count > 0))
7481
+ scsi_scan_host(host);
65937482
65947483 /*
65957484 * Initiate AEN (Asynchronous Event Notification)
....@@ -6599,6 +7488,8 @@
65997488 goto fail_start_aen;
66007489 }
66017490
7491
+ megasas_setup_debugfs(instance);
7492
+
66027493 /* Get current SR-IOV LD/VF affiliation */
66037494 if (instance->requestorId)
66047495 megasas_get_ld_vf_affiliation(instance, 1);
....@@ -6606,10 +7497,15 @@
66067497 return 0;
66077498
66087499 fail_start_aen:
7500
+ instance->unload = 1;
7501
+ scsi_remove_host(instance->host);
66097502 fail_io_attach:
66107503 megasas_mgmt_info.count--;
66117504 megasas_mgmt_info.max_index--;
66127505 megasas_mgmt_info.instance[megasas_mgmt_info.max_index] = NULL;
7506
+
7507
+ if (instance->requestorId && !instance->skip_heartbeat_timer_del)
7508
+ del_timer_sync(&instance->sriov_heartbeat_timer);
66137509
66147510 instance->instancet->disable_intr(instance);
66157511 megasas_destroy_irqs(instance);
....@@ -6618,8 +7514,16 @@
66187514 megasas_release_fusion(instance);
66197515 else
66207516 megasas_release_mfi(instance);
7517
+
66217518 if (instance->msix_vectors)
66227519 pci_free_irq_vectors(instance->pdev);
7520
+ instance->msix_vectors = 0;
7521
+
7522
+ if (instance->fw_crash_state != UNAVAILABLE)
7523
+ megasas_free_host_crash_buffer(instance);
7524
+
7525
+ if (instance->adapter_type != MFI_SERIES)
7526
+ megasas_fusion_stop_watchdog(instance);
66237527 fail_init_mfi:
66247528 scsi_host_put(host);
66257529 fail_alloc_instance:
....@@ -6730,16 +7634,24 @@
67307634 static int
67317635 megasas_suspend(struct pci_dev *pdev, pm_message_t state)
67327636 {
6733
- struct Scsi_Host *host;
67347637 struct megasas_instance *instance;
67357638
67367639 instance = pci_get_drvdata(pdev);
6737
- host = instance->host;
7640
+
7641
+ if (!instance)
7642
+ return 0;
7643
+
67387644 instance->unload = 1;
7645
+
7646
+ dev_info(&pdev->dev, "%s is called\n", __func__);
67397647
67407648 /* Shutdown SR-IOV heartbeat timer */
67417649 if (instance->requestorId && !instance->skip_heartbeat_timer_del)
67427650 del_timer_sync(&instance->sriov_heartbeat_timer);
7651
+
7652
+ /* Stop the FW fault detection watchdog */
7653
+ if (instance->adapter_type != MFI_SERIES)
7654
+ megasas_fusion_stop_watchdog(instance);
67437655
67447656 megasas_flush_cache(instance);
67457657 megasas_shutdown_controller(instance, MR_DCMD_HIBERNATE_SHUTDOWN);
....@@ -6779,14 +7691,19 @@
67797691 int rval;
67807692 struct Scsi_Host *host;
67817693 struct megasas_instance *instance;
6782
- int irq_flags = PCI_IRQ_LEGACY;
7694
+ u32 status_reg;
67837695
67847696 instance = pci_get_drvdata(pdev);
7697
+
7698
+ if (!instance)
7699
+ return 0;
7700
+
67857701 host = instance->host;
67867702 pci_set_power_state(pdev, PCI_D0);
67877703 pci_enable_wake(pdev, PCI_D0, 0);
67887704 pci_restore_state(pdev);
67897705
7706
+ dev_info(&pdev->dev, "%s is called\n", __func__);
67907707 /*
67917708 * PCI prepping: enable device set bus mastering and dma mask
67927709 */
....@@ -6802,9 +7719,35 @@
68027719 /*
68037720 * We expect the FW state to be READY
68047721 */
6805
- if (megasas_transition_to_ready(instance, 0))
6806
- goto fail_ready_state;
68077722
7723
+ if (megasas_transition_to_ready(instance, 0)) {
7724
+ dev_info(&instance->pdev->dev,
7725
+ "Failed to transition controller to ready from %s!\n",
7726
+ __func__);
7727
+ if (instance->adapter_type != MFI_SERIES) {
7728
+ status_reg =
7729
+ instance->instancet->read_fw_status_reg(instance);
7730
+ if (!(status_reg & MFI_RESET_ADAPTER) ||
7731
+ ((megasas_adp_reset_wait_for_ready
7732
+ (instance, true, 0)) == FAILED))
7733
+ goto fail_ready_state;
7734
+ } else {
7735
+ atomic_set(&instance->fw_reset_no_pci_access, 1);
7736
+ instance->instancet->adp_reset
7737
+ (instance, instance->reg_set);
7738
+ atomic_set(&instance->fw_reset_no_pci_access, 0);
7739
+
7740
+ /* waiting for about 30 seconds before retry */
7741
+ ssleep(30);
7742
+
7743
+ if (megasas_transition_to_ready(instance, 0))
7744
+ goto fail_ready_state;
7745
+ }
7746
+
7747
+ dev_info(&instance->pdev->dev,
7748
+ "FW restarted successfully from %s!\n",
7749
+ __func__);
7750
+ }
68087751 if (megasas_set_dma_mask(instance))
68097752 goto fail_set_dma_mask;
68107753
....@@ -6816,16 +7759,15 @@
68167759 atomic_set(&instance->ldio_outstanding, 0);
68177760
68187761 /* Now re-enable MSI-X */
6819
- if (instance->msix_vectors) {
6820
- irq_flags = PCI_IRQ_MSIX;
6821
- if (smp_affinity_enable)
6822
- irq_flags |= PCI_IRQ_AFFINITY;
7762
+ if (instance->msix_vectors)
7763
+ megasas_alloc_irq_vectors(instance);
7764
+
7765
+ if (!instance->msix_vectors) {
7766
+ rval = pci_alloc_irq_vectors(instance->pdev, 1, 1,
7767
+ PCI_IRQ_LEGACY);
7768
+ if (rval < 0)
7769
+ goto fail_reenable_msix;
68237770 }
6824
- rval = pci_alloc_irq_vectors(instance->pdev, 1,
6825
- instance->msix_vectors ?
6826
- instance->msix_vectors : 1, irq_flags);
6827
- if (rval < 0)
6828
- goto fail_reenable_msix;
68297771
68307772 megasas_setup_reply_map(instance);
68317773
....@@ -6856,6 +7798,9 @@
68567798 megasas_setup_irqs_ioapic(instance))
68577799 goto fail_init_mfi;
68587800
7801
+ if (instance->adapter_type != MFI_SERIES)
7802
+ megasas_setup_irq_poll(instance);
7803
+
68597804 /* Re-launch SR-IOV heartbeat timer */
68607805 if (instance->requestorId) {
68617806 if (!megasas_sriov_start_heartbeat(instance, 0))
....@@ -6876,8 +7821,16 @@
68767821 if (megasas_start_aen(instance))
68777822 dev_err(&instance->pdev->dev, "Start AEN failed\n");
68787823
7824
+ /* Re-launch FW fault watchdog */
7825
+ if (instance->adapter_type != MFI_SERIES)
7826
+ if (megasas_fusion_start_watchdog(instance) != SUCCESS)
7827
+ goto fail_start_watchdog;
7828
+
68797829 return 0;
68807830
7831
+fail_start_watchdog:
7832
+ if (instance->requestorId && !instance->skip_heartbeat_timer_del)
7833
+ del_timer_sync(&instance->sriov_heartbeat_timer);
68817834 fail_init_mfi:
68827835 megasas_free_ctrl_dma_buffers(instance);
68837836 megasas_free_ctrl_mem(instance);
....@@ -6938,12 +7891,20 @@
69387891 u32 pd_seq_map_sz;
69397892
69407893 instance = pci_get_drvdata(pdev);
7894
+
7895
+ if (!instance)
7896
+ return;
7897
+
69417898 host = instance->host;
69427899 fusion = instance->ctrl_context;
69437900
69447901 /* Shutdown SR-IOV heartbeat timer */
69457902 if (instance->requestorId && !instance->skip_heartbeat_timer_del)
69467903 del_timer_sync(&instance->sriov_heartbeat_timer);
7904
+
7905
+ /* Stop the FW fault detection watchdog */
7906
+ if (instance->adapter_type != MFI_SERIES)
7907
+ megasas_fusion_stop_watchdog(instance);
69477908
69487909 if (instance->fw_crash_state != UNAVAILABLE)
69497910 megasas_free_host_crash_buffer(instance);
....@@ -6989,7 +7950,7 @@
69897950 if (instance->msix_vectors)
69907951 pci_free_irq_vectors(instance->pdev);
69917952
6992
- if (instance->adapter_type == VENTURA_SERIES) {
7953
+ if (instance->adapter_type >= VENTURA_SERIES) {
69937954 for (i = 0; i < MAX_LOGICAL_DRIVES_EXT; ++i)
69947955 kfree(fusion->stream_detect_by_ld[i]);
69957956 kfree(fusion->stream_detect_by_ld);
....@@ -7027,25 +7988,27 @@
70277988 }
70287989
70297990 if (instance->vf_affiliation)
7030
- pci_free_consistent(pdev, (MAX_LOGICAL_DRIVES + 1) *
7991
+ dma_free_coherent(&pdev->dev, (MAX_LOGICAL_DRIVES + 1) *
70317992 sizeof(struct MR_LD_VF_AFFILIATION),
70327993 instance->vf_affiliation,
70337994 instance->vf_affiliation_h);
70347995
70357996 if (instance->vf_affiliation_111)
7036
- pci_free_consistent(pdev,
7997
+ dma_free_coherent(&pdev->dev,
70377998 sizeof(struct MR_LD_VF_AFFILIATION_111),
70387999 instance->vf_affiliation_111,
70398000 instance->vf_affiliation_111_h);
70408001
70418002 if (instance->hb_host_mem)
7042
- pci_free_consistent(pdev, sizeof(struct MR_CTRL_HB_HOST_MEM),
8003
+ dma_free_coherent(&pdev->dev, sizeof(struct MR_CTRL_HB_HOST_MEM),
70438004 instance->hb_host_mem,
70448005 instance->hb_host_mem_h);
70458006
70468007 megasas_free_ctrl_dma_buffers(instance);
70478008
70488009 megasas_free_ctrl_mem(instance);
8010
+
8011
+ megasas_destroy_debugfs(instance);
70498012
70508013 scsi_host_put(host);
70518014
....@@ -7054,11 +8017,14 @@
70548017
70558018 /**
70568019 * megasas_shutdown - Shutdown entry point
7057
- * @device: Generic device structure
8020
+ * @pdev: Generic device structure
70588021 */
70598022 static void megasas_shutdown(struct pci_dev *pdev)
70608023 {
70618024 struct megasas_instance *instance = pci_get_drvdata(pdev);
8025
+
8026
+ if (!instance)
8027
+ return;
70628028
70638029 instance->unload = 1;
70648030
....@@ -7076,8 +8042,10 @@
70768042 pci_free_irq_vectors(instance->pdev);
70778043 }
70788044
7079
-/**
8045
+/*
70808046 * megasas_mgmt_open - char node "open" entry point
8047
+ * @inode: char node inode
8048
+ * @filep: char node file
70818049 */
70828050 static int megasas_mgmt_open(struct inode *inode, struct file *filep)
70838051 {
....@@ -7090,8 +8058,11 @@
70908058 return 0;
70918059 }
70928060
7093
-/**
8061
+/*
70948062 * megasas_mgmt_fasync - Async notifier registration from applications
8063
+ * @fd: char node file descriptor number
8064
+ * @filep: char node file
8065
+ * @mode: notifier on/off
70958066 *
70968067 * This function adds the calling process to a driver global queue. When an
70978068 * event occurs, SIGIO will be sent to all processes in this queue.
....@@ -7117,9 +8088,11 @@
71178088 return rc;
71188089 }
71198090
7120
-/**
8091
+/*
71218092 * megasas_mgmt_poll - char node "poll" entry point
7122
- * */
8093
+ * @filep: char node file
8094
+ * @wait: Events to poll for
8095
+ */
71238096 static __poll_t megasas_mgmt_poll(struct file *file, poll_table *wait)
71248097 {
71258098 __poll_t mask;
....@@ -7177,7 +8150,8 @@
71778150 /**
71788151 * megasas_mgmt_fw_ioctl - Issues management ioctls to FW
71798152 * @instance: Adapter soft state
7180
- * @argp: User's ioctl packet
8153
+ * @user_ioc: User's ioctl packet
8154
+ * @ioc: ioctl packet
71818155 */
71828156 static int
71838157 megasas_mgmt_fw_ioctl(struct megasas_instance *instance,
....@@ -7194,6 +8168,7 @@
71948168 dma_addr_t sense_handle;
71958169 void *sense_ptr;
71968170 u32 opcode = 0;
8171
+ int ret = DCMD_SUCCESS;
71978172
71988173 memset(kbuff_arr, 0, sizeof(kbuff_arr));
71998174
....@@ -7205,7 +8180,9 @@
72058180
72068181 if ((ioc->frame.hdr.cmd >= MFI_CMD_OP_COUNT) ||
72078182 ((ioc->frame.hdr.cmd == MFI_CMD_NVME) &&
7208
- !instance->support_nvme_passthru)) {
8183
+ !instance->support_nvme_passthru) ||
8184
+ ((ioc->frame.hdr.cmd == MFI_CMD_TOOLBOX) &&
8185
+ !instance->support_pci_lane_margining)) {
72098186 dev_err(&instance->pdev->dev,
72108187 "Received invalid ioctl command 0x%x\n",
72118188 ioc->frame.hdr.cmd);
....@@ -7241,10 +8218,13 @@
72418218 opcode = le32_to_cpu(cmd->frame->dcmd.opcode);
72428219
72438220 if (opcode == MR_DCMD_CTRL_SHUTDOWN) {
8221
+ mutex_lock(&instance->reset_mutex);
72448222 if (megasas_get_ctrl_info(instance) != DCMD_SUCCESS) {
72458223 megasas_return_cmd(instance, cmd);
8224
+ mutex_unlock(&instance->reset_mutex);
72468225 return -1;
72478226 }
8227
+ mutex_unlock(&instance->reset_mutex);
72488228 }
72498229
72508230 if (opcode == MR_DRIVER_SET_APP_CRASHDUMP_MODE) {
....@@ -7287,7 +8267,7 @@
72878267
72888268 /*
72898269 * We don't change the dma_coherent_mask, so
7290
- * pci_alloc_consistent only returns 32bit addresses
8270
+ * dma_alloc_coherent only returns 32bit addresses
72918271 */
72928272 if (instance->consistent_mask_64bit) {
72938273 kern_sge64[i].phys_addr = cpu_to_le64(buf_handle);
....@@ -7333,13 +8313,18 @@
73338313 * cmd to the SCSI mid-layer
73348314 */
73358315 cmd->sync_cmd = 1;
7336
- if (megasas_issue_blocked_cmd(instance, cmd, 0) == DCMD_NOT_FIRED) {
8316
+
8317
+ ret = megasas_issue_blocked_cmd(instance, cmd, 0);
8318
+ switch (ret) {
8319
+ case DCMD_INIT:
8320
+ case DCMD_BUSY:
73378321 cmd->sync_cmd = 0;
73388322 dev_err(&instance->pdev->dev,
73398323 "return -EBUSY from %s %d cmd 0x%x opcode 0x%x cmd->cmd_status_drv 0x%x\n",
7340
- __func__, __LINE__, cmd->frame->hdr.cmd, opcode,
7341
- cmd->cmd_status_drv);
7342
- return -EBUSY;
8324
+ __func__, __LINE__, cmd->frame->hdr.cmd, opcode,
8325
+ cmd->cmd_status_drv);
8326
+ error = -EBUSY;
8327
+ goto out;
73438328 }
73448329
73458330 cmd->sync_cmd = 0;
....@@ -7510,6 +8495,9 @@
75108495
75118496 /**
75128497 * megasas_mgmt_ioctl - char node ioctl entry point
8498
+ * @file: char device file pointer
8499
+ * @cmd: ioctl command
8500
+ * @arg: ioctl command arguments address
75138501 */
75148502 static long
75158503 megasas_mgmt_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
....@@ -7690,6 +8678,14 @@
76908678
76918679 static DRIVER_ATTR_RO(support_nvme_encapsulation);
76928680
8681
+static ssize_t
8682
+support_pci_lane_margining_show(struct device_driver *dd, char *buf)
8683
+{
8684
+ return sprintf(buf, "%u\n", support_pci_lane_margining);
8685
+}
8686
+
8687
+static DRIVER_ATTR_RO(support_pci_lane_margining);
8688
+
76938689 static inline void megasas_remove_scsi_device(struct scsi_device *sdev)
76948690 {
76958691 sdev_printk(KERN_INFO, sdev, "SCSI device is removed\n");
....@@ -7697,102 +8693,103 @@
76978693 scsi_device_put(sdev);
76988694 }
76998695
7700
-static void
7701
-megasas_aen_polling(struct work_struct *work)
8696
+/**
8697
+ * megasas_update_device_list - Update the PD and LD device list from FW
8698
+ * after an AEN event notification
8699
+ * @instance: Adapter soft state
8700
+ * @event_type: Indicates type of event (PD or LD event)
8701
+ *
8702
+ * @return: Success or failure
8703
+ *
8704
+ * Issue DCMDs to Firmware to update the internal device list in driver.
8705
+ * Based on the FW support, driver sends the HOST_DEVICE_LIST or combination
8706
+ * of PD_LIST/LD_LIST_QUERY DCMDs to get the device list.
8707
+ */
8708
+static
8709
+int megasas_update_device_list(struct megasas_instance *instance,
8710
+ int event_type)
77028711 {
7703
- struct megasas_aen_event *ev =
7704
- container_of(work, struct megasas_aen_event, hotplug_work.work);
7705
- struct megasas_instance *instance = ev->instance;
7706
- union megasas_evt_class_locale class_locale;
7707
- struct Scsi_Host *host;
7708
- struct scsi_device *sdev1;
7709
- u16 pd_index = 0;
7710
- u16 ld_index = 0;
7711
- int i, j, doscan = 0;
7712
- u32 seq_num, wait_time = MEGASAS_RESET_WAIT_TIME;
7713
- int error;
7714
- u8 dcmd_ret = DCMD_SUCCESS;
8712
+ int dcmd_ret = DCMD_SUCCESS;
77158713
7716
- if (!instance) {
7717
- printk(KERN_ERR "invalid instance!\n");
7718
- kfree(ev);
7719
- return;
7720
- }
7721
-
7722
- /* Adjust event workqueue thread wait time for VF mode */
7723
- if (instance->requestorId)
7724
- wait_time = MEGASAS_ROUTINE_WAIT_TIME_VF;
7725
-
7726
- /* Don't run the event workqueue thread if OCR is running */
7727
- mutex_lock(&instance->reset_mutex);
7728
-
7729
- instance->ev = NULL;
7730
- host = instance->host;
7731
- if (instance->evt_detail) {
7732
- megasas_decode_evt(instance);
7733
-
7734
- switch (le32_to_cpu(instance->evt_detail->code)) {
7735
-
7736
- case MR_EVT_PD_INSERTED:
7737
- case MR_EVT_PD_REMOVED:
7738
- dcmd_ret = megasas_get_pd_list(instance);
7739
- if (dcmd_ret == DCMD_SUCCESS)
7740
- doscan = SCAN_PD_CHANNEL;
7741
- break;
7742
-
7743
- case MR_EVT_LD_OFFLINE:
7744
- case MR_EVT_CFG_CLEARED:
7745
- case MR_EVT_LD_DELETED:
7746
- case MR_EVT_LD_CREATED:
7747
- if (!instance->requestorId ||
7748
- (instance->requestorId && megasas_get_ld_vf_affiliation(instance, 0)))
7749
- dcmd_ret = megasas_ld_list_query(instance, MR_LD_QUERY_TYPE_EXPOSED_TO_HOST);
7750
-
7751
- if (dcmd_ret == DCMD_SUCCESS)
7752
- doscan = SCAN_VD_CHANNEL;
7753
-
7754
- break;
7755
-
7756
- case MR_EVT_CTRL_HOST_BUS_SCAN_REQUESTED:
7757
- case MR_EVT_FOREIGN_CFG_IMPORTED:
7758
- case MR_EVT_LD_STATE_CHANGE:
7759
- dcmd_ret = megasas_get_pd_list(instance);
7760
-
7761
- if (dcmd_ret != DCMD_SUCCESS)
7762
- break;
7763
-
7764
- if (!instance->requestorId ||
7765
- (instance->requestorId && megasas_get_ld_vf_affiliation(instance, 0)))
7766
- dcmd_ret = megasas_ld_list_query(instance, MR_LD_QUERY_TYPE_EXPOSED_TO_HOST);
7767
-
7768
- if (dcmd_ret != DCMD_SUCCESS)
7769
- break;
7770
-
7771
- doscan = SCAN_VD_CHANNEL | SCAN_PD_CHANNEL;
7772
- dev_info(&instance->pdev->dev, "scanning for scsi%d...\n",
7773
- instance->host->host_no);
7774
- break;
7775
-
7776
- case MR_EVT_CTRL_PROP_CHANGED:
7777
- dcmd_ret = megasas_get_ctrl_info(instance);
7778
- break;
7779
- default:
7780
- doscan = 0;
7781
- break;
7782
- }
8714
+ if (instance->enable_fw_dev_list) {
8715
+ dcmd_ret = megasas_host_device_list_query(instance, false);
8716
+ if (dcmd_ret != DCMD_SUCCESS)
8717
+ goto out;
77838718 } else {
7784
- dev_err(&instance->pdev->dev, "invalid evt_detail!\n");
7785
- mutex_unlock(&instance->reset_mutex);
7786
- kfree(ev);
7787
- return;
8719
+ if (event_type & SCAN_PD_CHANNEL) {
8720
+ dcmd_ret = megasas_get_pd_list(instance);
8721
+
8722
+ if (dcmd_ret != DCMD_SUCCESS)
8723
+ goto out;
8724
+ }
8725
+
8726
+ if (event_type & SCAN_VD_CHANNEL) {
8727
+ if (!instance->requestorId ||
8728
+ (instance->requestorId &&
8729
+ megasas_get_ld_vf_affiliation(instance, 0))) {
8730
+ dcmd_ret = megasas_ld_list_query(instance,
8731
+ MR_LD_QUERY_TYPE_EXPOSED_TO_HOST);
8732
+ if (dcmd_ret != DCMD_SUCCESS)
8733
+ goto out;
8734
+ }
8735
+ }
77888736 }
77898737
7790
- mutex_unlock(&instance->reset_mutex);
8738
+out:
8739
+ return dcmd_ret;
8740
+}
77918741
7792
- if (doscan & SCAN_PD_CHANNEL) {
8742
+/**
8743
+ * megasas_add_remove_devices - Add/remove devices to SCSI mid-layer
8744
+ * after an AEN event notification
8745
+ * @instance: Adapter soft state
8746
+ * @scan_type: Indicates type of devices (PD/LD) to add
8747
+ * @return void
8748
+ */
8749
+static
8750
+void megasas_add_remove_devices(struct megasas_instance *instance,
8751
+ int scan_type)
8752
+{
8753
+ int i, j;
8754
+ u16 pd_index = 0;
8755
+ u16 ld_index = 0;
8756
+ u16 channel = 0, id = 0;
8757
+ struct Scsi_Host *host;
8758
+ struct scsi_device *sdev1;
8759
+ struct MR_HOST_DEVICE_LIST *targetid_list = NULL;
8760
+ struct MR_HOST_DEVICE_LIST_ENTRY *targetid_entry = NULL;
8761
+
8762
+ host = instance->host;
8763
+
8764
+ if (instance->enable_fw_dev_list) {
8765
+ targetid_list = instance->host_device_list_buf;
8766
+ for (i = 0; i < targetid_list->count; i++) {
8767
+ targetid_entry = &targetid_list->host_device_list[i];
8768
+ if (targetid_entry->flags.u.bits.is_sys_pd) {
8769
+ channel = le16_to_cpu(targetid_entry->target_id) /
8770
+ MEGASAS_MAX_DEV_PER_CHANNEL;
8771
+ id = le16_to_cpu(targetid_entry->target_id) %
8772
+ MEGASAS_MAX_DEV_PER_CHANNEL;
8773
+ } else {
8774
+ channel = MEGASAS_MAX_PD_CHANNELS +
8775
+ (le16_to_cpu(targetid_entry->target_id) /
8776
+ MEGASAS_MAX_DEV_PER_CHANNEL);
8777
+ id = le16_to_cpu(targetid_entry->target_id) %
8778
+ MEGASAS_MAX_DEV_PER_CHANNEL;
8779
+ }
8780
+ sdev1 = scsi_device_lookup(host, channel, id, 0);
8781
+ if (!sdev1) {
8782
+ scsi_add_device(host, channel, id, 0);
8783
+ } else {
8784
+ scsi_device_put(sdev1);
8785
+ }
8786
+ }
8787
+ }
8788
+
8789
+ if (scan_type & SCAN_PD_CHANNEL) {
77938790 for (i = 0; i < MEGASAS_MAX_PD_CHANNELS; i++) {
77948791 for (j = 0; j < MEGASAS_MAX_DEV_PER_CHANNEL; j++) {
7795
- pd_index = i*MEGASAS_MAX_DEV_PER_CHANNEL + j;
8792
+ pd_index = i * MEGASAS_MAX_DEV_PER_CHANNEL + j;
77968793 sdev1 = scsi_device_lookup(host, i, j, 0);
77978794 if (instance->pd_list[pd_index].driveState ==
77988795 MR_PD_STATE_SYSTEM) {
....@@ -7808,11 +8805,12 @@
78088805 }
78098806 }
78108807
7811
- if (doscan & SCAN_VD_CHANNEL) {
8808
+ if (scan_type & SCAN_VD_CHANNEL) {
78128809 for (i = 0; i < MEGASAS_MAX_LD_CHANNELS; i++) {
78138810 for (j = 0; j < MEGASAS_MAX_DEV_PER_CHANNEL; j++) {
78148811 ld_index = (i * MEGASAS_MAX_DEV_PER_CHANNEL) + j;
7815
- sdev1 = scsi_device_lookup(host, MEGASAS_MAX_PD_CHANNELS + i, j, 0);
8812
+ sdev1 = scsi_device_lookup(host,
8813
+ MEGASAS_MAX_PD_CHANNELS + i, j, 0);
78168814 if (instance->ld_ids[ld_index] != 0xff) {
78178815 if (!sdev1)
78188816 scsi_add_device(host, MEGASAS_MAX_PD_CHANNELS + i, j, 0);
....@@ -7825,6 +8823,97 @@
78258823 }
78268824 }
78278825 }
8826
+
8827
+}
8828
+
8829
+static void
8830
+megasas_aen_polling(struct work_struct *work)
8831
+{
8832
+ struct megasas_aen_event *ev =
8833
+ container_of(work, struct megasas_aen_event, hotplug_work.work);
8834
+ struct megasas_instance *instance = ev->instance;
8835
+ union megasas_evt_class_locale class_locale;
8836
+ int event_type = 0;
8837
+ u32 seq_num;
8838
+ u16 ld_target_id;
8839
+ int error;
8840
+ u8 dcmd_ret = DCMD_SUCCESS;
8841
+ struct scsi_device *sdev1;
8842
+
8843
+ if (!instance) {
8844
+ printk(KERN_ERR "invalid instance!\n");
8845
+ kfree(ev);
8846
+ return;
8847
+ }
8848
+
8849
+ /* Don't run the event workqueue thread if OCR is running */
8850
+ mutex_lock(&instance->reset_mutex);
8851
+
8852
+ instance->ev = NULL;
8853
+ if (instance->evt_detail) {
8854
+ megasas_decode_evt(instance);
8855
+
8856
+ switch (le32_to_cpu(instance->evt_detail->code)) {
8857
+
8858
+ case MR_EVT_PD_INSERTED:
8859
+ case MR_EVT_PD_REMOVED:
8860
+ event_type = SCAN_PD_CHANNEL;
8861
+ break;
8862
+
8863
+ case MR_EVT_LD_OFFLINE:
8864
+ case MR_EVT_LD_DELETED:
8865
+ ld_target_id = instance->evt_detail->args.ld.target_id;
8866
+ sdev1 = scsi_device_lookup(instance->host,
8867
+ MEGASAS_MAX_PD_CHANNELS +
8868
+ (ld_target_id / MEGASAS_MAX_DEV_PER_CHANNEL),
8869
+ (ld_target_id - MEGASAS_MAX_DEV_PER_CHANNEL),
8870
+ 0);
8871
+ if (sdev1)
8872
+ megasas_remove_scsi_device(sdev1);
8873
+
8874
+ event_type = SCAN_VD_CHANNEL;
8875
+ break;
8876
+ case MR_EVT_LD_CREATED:
8877
+ event_type = SCAN_VD_CHANNEL;
8878
+ break;
8879
+
8880
+ case MR_EVT_CFG_CLEARED:
8881
+ case MR_EVT_CTRL_HOST_BUS_SCAN_REQUESTED:
8882
+ case MR_EVT_FOREIGN_CFG_IMPORTED:
8883
+ case MR_EVT_LD_STATE_CHANGE:
8884
+ event_type = SCAN_PD_CHANNEL | SCAN_VD_CHANNEL;
8885
+ dev_info(&instance->pdev->dev, "scanning for scsi%d...\n",
8886
+ instance->host->host_no);
8887
+ break;
8888
+
8889
+ case MR_EVT_CTRL_PROP_CHANGED:
8890
+ dcmd_ret = megasas_get_ctrl_info(instance);
8891
+ if (dcmd_ret == DCMD_SUCCESS &&
8892
+ instance->snapdump_wait_time) {
8893
+ megasas_get_snapdump_properties(instance);
8894
+ dev_info(&instance->pdev->dev,
8895
+ "Snap dump wait time\t: %d\n",
8896
+ instance->snapdump_wait_time);
8897
+ }
8898
+ break;
8899
+ default:
8900
+ event_type = 0;
8901
+ break;
8902
+ }
8903
+ } else {
8904
+ dev_err(&instance->pdev->dev, "invalid evt_detail!\n");
8905
+ mutex_unlock(&instance->reset_mutex);
8906
+ kfree(ev);
8907
+ return;
8908
+ }
8909
+
8910
+ if (event_type)
8911
+ dcmd_ret = megasas_update_device_list(instance, event_type);
8912
+
8913
+ mutex_unlock(&instance->reset_mutex);
8914
+
8915
+ if (event_type && dcmd_ret == DCMD_SUCCESS)
8916
+ megasas_add_remove_devices(instance, event_type);
78288917
78298918 if (dcmd_ret == DCMD_SUCCESS)
78308919 seq_num = le32_to_cpu(instance->evt_detail->seq_num) + 1;
....@@ -7879,6 +8968,7 @@
78798968 support_poll_for_event = 2;
78808969 support_device_change = 1;
78818970 support_nvme_encapsulation = true;
8971
+ support_pci_lane_margining = true;
78828972
78838973 memset(&megasas_mgmt_info, 0, sizeof(megasas_mgmt_info));
78848974
....@@ -7894,6 +8984,8 @@
78948984
78958985 megasas_mgmt_majorno = rval;
78968986
8987
+ megasas_init_debugfs();
8988
+
78978989 /*
78988990 * Register ourselves as PCI hotplug module
78998991 */
....@@ -7902,6 +8994,12 @@
79028994 if (rval) {
79038995 printk(KERN_DEBUG "megasas: PCI hotplug registration failed \n");
79048996 goto err_pcidrv;
8997
+ }
8998
+
8999
+ if ((event_log_level < MFI_EVT_CLASS_DEBUG) ||
9000
+ (event_log_level > MFI_EVT_CLASS_DEAD)) {
9001
+ pr_warn("megaraid_sas: provided event log level is out of range, setting it to default 2(CLASS_CRITICAL), permissible range is: -2 to 4\n");
9002
+ event_log_level = MFI_EVT_CLASS_CRITICAL;
79059003 }
79069004
79079005 rval = driver_create_file(&megasas_pci_driver.driver,
....@@ -7933,7 +9031,16 @@
79339031 if (rval)
79349032 goto err_dcf_support_nvme_encapsulation;
79359033
9034
+ rval = driver_create_file(&megasas_pci_driver.driver,
9035
+ &driver_attr_support_pci_lane_margining);
9036
+ if (rval)
9037
+ goto err_dcf_support_pci_lane_margining;
9038
+
79369039 return rval;
9040
+
9041
+err_dcf_support_pci_lane_margining:
9042
+ driver_remove_file(&megasas_pci_driver.driver,
9043
+ &driver_attr_support_nvme_encapsulation);
79379044
79389045 err_dcf_support_nvme_encapsulation:
79399046 driver_remove_file(&megasas_pci_driver.driver,
....@@ -7953,6 +9060,7 @@
79539060 err_dcf_attr_ver:
79549061 pci_unregister_driver(&megasas_pci_driver);
79559062 err_pcidrv:
9063
+ megasas_exit_debugfs();
79569064 unregister_chrdev(megasas_mgmt_majorno, "megaraid_sas_ioctl");
79579065 return rval;
79589066 }
....@@ -7973,8 +9081,11 @@
79739081 driver_remove_file(&megasas_pci_driver.driver, &driver_attr_version);
79749082 driver_remove_file(&megasas_pci_driver.driver,
79759083 &driver_attr_support_nvme_encapsulation);
9084
+ driver_remove_file(&megasas_pci_driver.driver,
9085
+ &driver_attr_support_pci_lane_margining);
79769086
79779087 pci_unregister_driver(&megasas_pci_driver);
9088
+ megasas_exit_debugfs();
79789089 unregister_chrdev(megasas_mgmt_majorno, "megaraid_sas_ioctl");
79799090 }
79809091