forked from ~ljy/RK356X_SDK_RELEASE

hc
2023-12-09 95099d4622f8cb224d94e314c7a8e0df60b13f87
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,7 +3214,7 @@
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);
....@@ -3016,14 +3233,13 @@
30163233 }
30173234
30183235 static ssize_t
3019
-megasas_fw_crash_buffer_show(struct device *cdev,
3236
+fw_crash_buffer_show(struct device *cdev,
30203237 struct device_attribute *attr, char *buf)
30213238 {
30223239 struct Scsi_Host *shost = class_to_shost(cdev);
30233240 struct megasas_instance *instance =
30243241 (struct megasas_instance *) shost->hostdata;
30253242 u32 size;
3026
- unsigned long buff_addr;
30273243 unsigned long dmachunk = CRASH_DMA_BUF_SIZE;
30283244 unsigned long chunk_left_bytes;
30293245 unsigned long src_addr;
....@@ -3040,8 +3256,6 @@
30403256 spin_unlock_irqrestore(&instance->crashdump_lock, flags);
30413257 return -EINVAL;
30423258 }
3043
-
3044
- buff_addr = (unsigned long) buf;
30453259
30463260 if (buff_offset > (instance->fw_crash_buffer_size * dmachunk)) {
30473261 dev_err(&instance->pdev->dev,
....@@ -3064,7 +3278,7 @@
30643278 }
30653279
30663280 static ssize_t
3067
-megasas_fw_crash_buffer_size_show(struct device *cdev,
3281
+fw_crash_buffer_size_show(struct device *cdev,
30683282 struct device_attribute *attr, char *buf)
30693283 {
30703284 struct Scsi_Host *shost = class_to_shost(cdev);
....@@ -3076,7 +3290,7 @@
30763290 }
30773291
30783292 static ssize_t
3079
-megasas_fw_crash_state_store(struct device *cdev,
3293
+fw_crash_state_store(struct device *cdev,
30803294 struct device_attribute *attr, const char *buf, size_t count)
30813295 {
30823296 struct Scsi_Host *shost = class_to_shost(cdev);
....@@ -3111,7 +3325,7 @@
31113325 }
31123326
31133327 static ssize_t
3114
-megasas_fw_crash_state_show(struct device *cdev,
3328
+fw_crash_state_show(struct device *cdev,
31153329 struct device_attribute *attr, char *buf)
31163330 {
31173331 struct Scsi_Host *shost = class_to_shost(cdev);
....@@ -3122,14 +3336,14 @@
31223336 }
31233337
31243338 static ssize_t
3125
-megasas_page_size_show(struct device *cdev,
3339
+page_size_show(struct device *cdev,
31263340 struct device_attribute *attr, char *buf)
31273341 {
31283342 return snprintf(buf, PAGE_SIZE, "%ld\n", (unsigned long)PAGE_SIZE - 1);
31293343 }
31303344
31313345 static ssize_t
3132
-megasas_ldio_outstanding_show(struct device *cdev, struct device_attribute *attr,
3346
+ldio_outstanding_show(struct device *cdev, struct device_attribute *attr,
31333347 char *buf)
31343348 {
31353349 struct Scsi_Host *shost = class_to_shost(cdev);
....@@ -3139,7 +3353,7 @@
31393353 }
31403354
31413355 static ssize_t
3142
-megasas_fw_cmds_outstanding_show(struct device *cdev,
3356
+fw_cmds_outstanding_show(struct device *cdev,
31433357 struct device_attribute *attr, char *buf)
31443358 {
31453359 struct Scsi_Host *shost = class_to_shost(cdev);
....@@ -3148,26 +3362,91 @@
31483362 return snprintf(buf, PAGE_SIZE, "%d\n", atomic_read(&instance->fw_outstanding));
31493363 }
31503364
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);
3365
+static ssize_t
3366
+enable_sdev_max_qd_show(struct device *cdev,
3367
+ struct device_attribute *attr, char *buf)
3368
+{
3369
+ struct Scsi_Host *shost = class_to_shost(cdev);
3370
+ struct megasas_instance *instance = (struct megasas_instance *)shost->hostdata;
31633371
3164
-struct device_attribute *megaraid_host_attrs[] = {
3372
+ return snprintf(buf, PAGE_SIZE, "%d\n", instance->enable_sdev_max_qd);
3373
+}
3374
+
3375
+static ssize_t
3376
+enable_sdev_max_qd_store(struct device *cdev,
3377
+ struct device_attribute *attr, const char *buf, size_t count)
3378
+{
3379
+ struct Scsi_Host *shost = class_to_shost(cdev);
3380
+ struct megasas_instance *instance = (struct megasas_instance *)shost->hostdata;
3381
+ u32 val = 0;
3382
+ bool is_target_prop;
3383
+ int ret_target_prop = DCMD_FAILED;
3384
+ struct scsi_device *sdev;
3385
+
3386
+ if (kstrtou32(buf, 0, &val) != 0) {
3387
+ pr_err("megasas: could not set enable_sdev_max_qd\n");
3388
+ return -EINVAL;
3389
+ }
3390
+
3391
+ mutex_lock(&instance->reset_mutex);
3392
+ if (val)
3393
+ instance->enable_sdev_max_qd = true;
3394
+ else
3395
+ instance->enable_sdev_max_qd = false;
3396
+
3397
+ shost_for_each_device(sdev, shost) {
3398
+ ret_target_prop = megasas_get_target_prop(instance, sdev);
3399
+ is_target_prop = (ret_target_prop == DCMD_SUCCESS) ? true : false;
3400
+ megasas_set_fw_assisted_qd(sdev, is_target_prop);
3401
+ }
3402
+ mutex_unlock(&instance->reset_mutex);
3403
+
3404
+ return strlen(buf);
3405
+}
3406
+
3407
+static ssize_t
3408
+dump_system_regs_show(struct device *cdev,
3409
+ struct device_attribute *attr, char *buf)
3410
+{
3411
+ struct Scsi_Host *shost = class_to_shost(cdev);
3412
+ struct megasas_instance *instance =
3413
+ (struct megasas_instance *)shost->hostdata;
3414
+
3415
+ return megasas_dump_sys_regs(instance->reg_set, buf);
3416
+}
3417
+
3418
+static ssize_t
3419
+raid_map_id_show(struct device *cdev, struct device_attribute *attr,
3420
+ char *buf)
3421
+{
3422
+ struct Scsi_Host *shost = class_to_shost(cdev);
3423
+ struct megasas_instance *instance =
3424
+ (struct megasas_instance *)shost->hostdata;
3425
+
3426
+ return snprintf(buf, PAGE_SIZE, "%ld\n",
3427
+ (unsigned long)instance->map_id);
3428
+}
3429
+
3430
+static DEVICE_ATTR_RW(fw_crash_buffer);
3431
+static DEVICE_ATTR_RO(fw_crash_buffer_size);
3432
+static DEVICE_ATTR_RW(fw_crash_state);
3433
+static DEVICE_ATTR_RO(page_size);
3434
+static DEVICE_ATTR_RO(ldio_outstanding);
3435
+static DEVICE_ATTR_RO(fw_cmds_outstanding);
3436
+static DEVICE_ATTR_RW(enable_sdev_max_qd);
3437
+static DEVICE_ATTR_RO(dump_system_regs);
3438
+static DEVICE_ATTR_RO(raid_map_id);
3439
+
3440
+static struct device_attribute *megaraid_host_attrs[] = {
31653441 &dev_attr_fw_crash_buffer_size,
31663442 &dev_attr_fw_crash_buffer,
31673443 &dev_attr_fw_crash_state,
31683444 &dev_attr_page_size,
31693445 &dev_attr_ldio_outstanding,
31703446 &dev_attr_fw_cmds_outstanding,
3447
+ &dev_attr_enable_sdev_max_qd,
3448
+ &dev_attr_dump_system_regs,
3449
+ &dev_attr_raid_map_id,
31713450 NULL,
31723451 };
31733452
....@@ -3189,9 +3468,8 @@
31893468 .eh_timed_out = megasas_reset_timer,
31903469 .shost_attrs = megaraid_host_attrs,
31913470 .bios_param = megasas_bios_param,
3192
- .use_clustering = ENABLE_CLUSTERING,
31933471 .change_queue_depth = scsi_change_queue_depth,
3194
- .no_write_same = 1,
3472
+ .max_segment_size = 0xffffffff,
31953473 };
31963474
31973475 /**
....@@ -3207,7 +3485,11 @@
32073485 megasas_complete_int_cmd(struct megasas_instance *instance,
32083486 struct megasas_cmd *cmd)
32093487 {
3210
- cmd->cmd_status_drv = cmd->frame->io.cmd_status;
3488
+ if (cmd->cmd_status_drv == DCMD_INIT)
3489
+ cmd->cmd_status_drv =
3490
+ (cmd->frame->io.cmd_status == MFI_STAT_OK) ?
3491
+ DCMD_SUCCESS : DCMD_FAILED;
3492
+
32113493 wake_up(&instance->int_cmd_wait_q);
32123494 }
32133495
....@@ -3226,8 +3508,24 @@
32263508 {
32273509 if (cmd->sync_cmd) {
32283510 cmd->sync_cmd = 0;
3229
- cmd->cmd_status_drv = 0;
3511
+ cmd->cmd_status_drv = DCMD_SUCCESS;
32303512 wake_up(&instance->abort_cmd_wait_q);
3513
+ }
3514
+}
3515
+
3516
+static void
3517
+megasas_set_ld_removed_by_fw(struct megasas_instance *instance)
3518
+{
3519
+ uint i;
3520
+
3521
+ for (i = 0; (i < MEGASAS_MAX_LD_IDS); i++) {
3522
+ if (instance->ld_ids_prev[i] != 0xff &&
3523
+ instance->ld_ids_from_raidmap[i] == 0xff) {
3524
+ if (megasas_dbg_lvl & LD_PD_DEBUG)
3525
+ dev_info(&instance->pdev->dev,
3526
+ "LD target ID %d removed from RAID map\n", i);
3527
+ instance->ld_tgtid_status[i] = LD_TARGET_ID_DELETED;
3528
+ }
32313529 }
32323530 }
32333531
....@@ -3281,6 +3579,7 @@
32813579 megasas_complete_int_cmd(instance, cmd);
32823580 break;
32833581 }
3582
+ fallthrough;
32843583
32853584 case MFI_CMD_LD_READ:
32863585 case MFI_CMD_LD_WRITE:
....@@ -3351,6 +3650,7 @@
33513650 case MFI_CMD_SMP:
33523651 case MFI_CMD_STP:
33533652 case MFI_CMD_NVME:
3653
+ case MFI_CMD_TOOLBOX:
33543654 megasas_complete_int_cmd(instance, cmd);
33553655 break;
33563656
....@@ -3391,9 +3691,13 @@
33913691 fusion->fast_path_io = 0;
33923692 }
33933693
3694
+ if (instance->adapter_type >= INVADER_SERIES)
3695
+ megasas_set_ld_removed_by_fw(instance);
3696
+
33943697 megasas_sync_map_info(instance);
33953698 spin_unlock_irqrestore(instance->host->host_lock,
33963699 flags);
3700
+
33973701 break;
33983702 }
33993703 if (opcode == MR_DCMD_CTRL_EVENT_GET_INFO ||
....@@ -3500,7 +3804,7 @@
35003804 dev_notice(&instance->pdev->dev, "%p synchronous cmd"
35013805 "on the internal reset queue,"
35023806 "issue it again.\n", cmd);
3503
- cmd->cmd_status_drv = MFI_STAT_INVALID_STATUS;
3807
+ cmd->cmd_status_drv = DCMD_INIT;
35043808 instance->instancet->fire_cmd(instance,
35053809 cmd->frame_phys_addr,
35063810 0, instance->reg_set);
....@@ -3538,7 +3842,7 @@
35383842 megasas_register_aen(instance, seq_num, class_locale.word);
35393843 }
35403844
3541
-/**
3845
+/*
35423846 * Move the internal reset pending commands to a deferred queue.
35433847 *
35443848 * We move the commands pending at internal reset time to a
....@@ -3546,7 +3850,7 @@
35463850 * completion of the internal reset sequence. if the internal reset
35473851 * did not complete in time, the kernel reset handler would flush
35483852 * these commands.
3549
- **/
3853
+ */
35503854 static void
35513855 megasas_internal_reset_defer_cmds(struct megasas_instance *instance)
35523856 {
....@@ -3668,9 +3972,8 @@
36683972 return IRQ_HANDLED;
36693973 }
36703974
3671
- if ((mfiStatus = instance->instancet->clear_intr(
3672
- instance->reg_set)
3673
- ) == 0) {
3975
+ mfiStatus = instance->instancet->clear_intr(instance);
3976
+ if (mfiStatus == 0) {
36743977 /* Hardware may not set outbound_intr_status in MSI-X mode */
36753978 if (!instance->msix_vectors)
36763979 return IRQ_NONE;
....@@ -3680,7 +3983,7 @@
36803983
36813984 if ((mfiStatus & MFI_INTR_FLAG_FIRMWARE_STATE_CHANGE)) {
36823985 fw_state = instance->instancet->read_fw_status_reg(
3683
- instance->reg_set) & MFI_STATE_MASK;
3986
+ instance) & MFI_STATE_MASK;
36843987
36853988 if (fw_state != MFI_STATE_FAULT) {
36863989 dev_notice(&instance->pdev->dev, "fw state:%x\n",
....@@ -3725,8 +4028,11 @@
37254028 tasklet_schedule(&instance->isr_tasklet);
37264029 return IRQ_HANDLED;
37274030 }
4031
+
37284032 /**
37294033 * megasas_isr - isr entry point
4034
+ * @irq: IRQ number
4035
+ * @devp: IRQ context address
37304036 */
37314037 static irqreturn_t megasas_isr(int irq, void *devp)
37324038 {
....@@ -3748,6 +4054,7 @@
37484054 /**
37494055 * megasas_transition_to_ready - Move the FW to READY state
37504056 * @instance: Adapter soft state
4057
+ * @ocr: Adapter reset state
37514058 *
37524059 * During the initialization, FW passes can potentially be in any one of
37534060 * several possible states. If the FW in operational, waiting-for-handshake
....@@ -3760,10 +4067,9 @@
37604067 int i;
37614068 u8 max_wait;
37624069 u32 fw_state;
3763
- u32 cur_state;
37644070 u32 abs_state, curr_abs_state;
37654071
3766
- abs_state = instance->instancet->read_fw_status_reg(instance->reg_set);
4072
+ abs_state = instance->instancet->read_fw_status_reg(instance);
37674073 fw_state = abs_state & MFI_STATE_MASK;
37684074
37694075 if (fw_state != MFI_STATE_READY)
....@@ -3775,13 +4081,18 @@
37754081 switch (fw_state) {
37764082
37774083 case MFI_STATE_FAULT:
3778
- dev_printk(KERN_DEBUG, &instance->pdev->dev, "FW in FAULT state!!\n");
4084
+ dev_printk(KERN_ERR, &instance->pdev->dev,
4085
+ "FW in FAULT state, Fault code:0x%x subcode:0x%x func:%s\n",
4086
+ abs_state & MFI_STATE_FAULT_CODE,
4087
+ abs_state & MFI_STATE_FAULT_SUBCODE, __func__);
37794088 if (ocr) {
37804089 max_wait = MEGASAS_RESET_WAIT_TIME;
3781
- cur_state = MFI_STATE_FAULT;
37824090 break;
3783
- } else
4091
+ } else {
4092
+ dev_printk(KERN_DEBUG, &instance->pdev->dev, "System Register set:\n");
4093
+ megasas_dump_reg_set(instance->reg_set);
37844094 return -ENODEV;
4095
+ }
37854096
37864097 case MFI_STATE_WAIT_HANDSHAKE:
37874098 /*
....@@ -3801,7 +4112,6 @@
38014112 &instance->reg_set->inbound_doorbell);
38024113
38034114 max_wait = MEGASAS_RESET_WAIT_TIME;
3804
- cur_state = MFI_STATE_WAIT_HANDSHAKE;
38054115 break;
38064116
38074117 case MFI_STATE_BOOT_MESSAGE_PENDING:
....@@ -3817,7 +4127,6 @@
38174127 &instance->reg_set->inbound_doorbell);
38184128
38194129 max_wait = MEGASAS_RESET_WAIT_TIME;
3820
- cur_state = MFI_STATE_BOOT_MESSAGE_PENDING;
38214130 break;
38224131
38234132 case MFI_STATE_OPERATIONAL:
....@@ -3835,7 +4144,8 @@
38354144
38364145 if (instance->adapter_type != MFI_SERIES) {
38374146 for (i = 0; i < (10 * 1000); i += 20) {
3838
- if (readl(
4147
+ if (megasas_readl(
4148
+ instance,
38394149 &instance->
38404150 reg_set->
38414151 doorbell) & 1)
....@@ -3849,7 +4159,6 @@
38494159 &instance->reg_set->inbound_doorbell);
38504160
38514161 max_wait = MEGASAS_RESET_WAIT_TIME;
3852
- cur_state = MFI_STATE_OPERATIONAL;
38534162 break;
38544163
38554164 case MFI_STATE_UNDEFINED:
....@@ -3857,37 +4166,33 @@
38574166 * This state should not last for more than 2 seconds
38584167 */
38594168 max_wait = MEGASAS_RESET_WAIT_TIME;
3860
- cur_state = MFI_STATE_UNDEFINED;
38614169 break;
38624170
38634171 case MFI_STATE_BB_INIT:
38644172 max_wait = MEGASAS_RESET_WAIT_TIME;
3865
- cur_state = MFI_STATE_BB_INIT;
38664173 break;
38674174
38684175 case MFI_STATE_FW_INIT:
38694176 max_wait = MEGASAS_RESET_WAIT_TIME;
3870
- cur_state = MFI_STATE_FW_INIT;
38714177 break;
38724178
38734179 case MFI_STATE_FW_INIT_2:
38744180 max_wait = MEGASAS_RESET_WAIT_TIME;
3875
- cur_state = MFI_STATE_FW_INIT_2;
38764181 break;
38774182
38784183 case MFI_STATE_DEVICE_SCAN:
38794184 max_wait = MEGASAS_RESET_WAIT_TIME;
3880
- cur_state = MFI_STATE_DEVICE_SCAN;
38814185 break;
38824186
38834187 case MFI_STATE_FLUSH_CACHE:
38844188 max_wait = MEGASAS_RESET_WAIT_TIME;
3885
- cur_state = MFI_STATE_FLUSH_CACHE;
38864189 break;
38874190
38884191 default:
38894192 dev_printk(KERN_DEBUG, &instance->pdev->dev, "Unknown state 0x%x\n",
38904193 fw_state);
4194
+ dev_printk(KERN_DEBUG, &instance->pdev->dev, "System Register set:\n");
4195
+ megasas_dump_reg_set(instance->reg_set);
38914196 return -ENODEV;
38924197 }
38934198
....@@ -3896,7 +4201,7 @@
38964201 */
38974202 for (i = 0; i < max_wait * 50; i++) {
38984203 curr_abs_state = instance->instancet->
3899
- read_fw_status_reg(instance->reg_set);
4204
+ read_fw_status_reg(instance);
39004205
39014206 if (abs_state == curr_abs_state) {
39024207 msleep(20);
....@@ -3910,6 +4215,8 @@
39104215 if (curr_abs_state == abs_state) {
39114216 dev_printk(KERN_DEBUG, &instance->pdev->dev, "FW state [%d] hasn't changed "
39124217 "in %d secs\n", fw_state, max_wait);
4218
+ dev_printk(KERN_DEBUG, &instance->pdev->dev, "System Register set:\n");
4219
+ megasas_dump_reg_set(instance->reg_set);
39134220 return -ENODEV;
39144221 }
39154222
....@@ -3973,21 +4280,10 @@
39734280 {
39744281 int i;
39754282 u16 max_cmd;
3976
- u32 sge_sz;
39774283 u32 frame_count;
39784284 struct megasas_cmd *cmd;
39794285
39804286 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);
39914287
39924288 /*
39934289 * For MFI controllers.
....@@ -4239,8 +4535,10 @@
42394535 switch (dcmd_timeout_ocr_possible(instance)) {
42404536 case INITIATE_OCR:
42414537 cmd->flags |= DRV_DCMD_SKIP_REFIRE;
4538
+ mutex_unlock(&instance->reset_mutex);
42424539 megasas_reset_fusion(instance->host,
42434540 MFI_IO_TIMEOUT_OCR);
4541
+ mutex_lock(&instance->reset_mutex);
42444542 break;
42454543 case KILL_ADAPTER:
42464544 megaraid_sas_kill_hba(instance);
....@@ -4276,7 +4574,6 @@
42764574 struct megasas_dcmd_frame *dcmd;
42774575 struct MR_PD_LIST *ci;
42784576 struct MR_PD_ADDRESS *pd_addr;
4279
- dma_addr_t ci_h = 0;
42804577
42814578 if (instance->pd_list_not_supported) {
42824579 dev_info(&instance->pdev->dev, "MR_DCMD_PD_LIST_QUERY "
....@@ -4285,7 +4582,6 @@
42854582 }
42864583
42874584 ci = instance->pd_list_buf;
4288
- ci_h = instance->pd_list_buf_h;
42894585
42904586 cmd = megasas_get_cmd(instance);
42914587
....@@ -4358,6 +4654,9 @@
43584654
43594655 case DCMD_SUCCESS:
43604656 pd_addr = ci->addr;
4657
+ if (megasas_dbg_lvl & LD_PD_DEBUG)
4658
+ dev_info(&instance->pdev->dev, "%s, sysPD count: 0x%x\n",
4659
+ __func__, le32_to_cpu(ci->count));
43614660
43624661 if ((le32_to_cpu(ci->count) >
43634662 (MEGASAS_MAX_PD_CHANNELS * MEGASAS_MAX_DEV_PER_CHANNEL)))
....@@ -4373,6 +4672,11 @@
43734672 pd_addr->scsiDevType;
43744673 instance->local_pd_list[le16_to_cpu(pd_addr->deviceId)].driveState =
43754674 MR_PD_STATE_SYSTEM;
4675
+ if (megasas_dbg_lvl & LD_PD_DEBUG)
4676
+ dev_info(&instance->pdev->dev,
4677
+ "PD%d: targetID: 0x%03x deviceType:0x%x\n",
4678
+ pd_index, le16_to_cpu(pd_addr->deviceId),
4679
+ pd_addr->scsiDevType);
43764680 pd_addr++;
43774681 }
43784682
....@@ -4476,6 +4780,10 @@
44764780 break;
44774781
44784782 case DCMD_SUCCESS:
4783
+ if (megasas_dbg_lvl & LD_PD_DEBUG)
4784
+ dev_info(&instance->pdev->dev, "%s, LD count: 0x%x\n",
4785
+ __func__, ld_count);
4786
+
44794787 if (ld_count > instance->fw_supported_vd_count)
44804788 break;
44814789
....@@ -4485,6 +4793,10 @@
44854793 if (ci->ldList[ld_index].state != 0) {
44864794 ids = ci->ldList[ld_index].ref.targetId;
44874795 instance->ld_ids[ids] = ci->ldList[ld_index].ref.targetId;
4796
+ if (megasas_dbg_lvl & LD_PD_DEBUG)
4797
+ dev_info(&instance->pdev->dev,
4798
+ "LD%d: targetID: 0x%03x\n",
4799
+ ld_index, ids);
44884800 }
44894801 }
44904802
....@@ -4500,7 +4812,7 @@
45004812 /**
45014813 * megasas_ld_list_query - Returns FW's ld_list structure
45024814 * @instance: Adapter soft state
4503
- * @ld_list: ld_list structure
4815
+ * @query_type: ld_list structure type
45044816 *
45054817 * Issues an internal command (DCMD) to get the FW's controller PD
45064818 * list structure. This information is mainly used to find out SYSTEM
....@@ -4588,6 +4900,10 @@
45884900 case DCMD_SUCCESS:
45894901 tgtid_count = le32_to_cpu(ci->count);
45904902
4903
+ if (megasas_dbg_lvl & LD_PD_DEBUG)
4904
+ dev_info(&instance->pdev->dev, "%s, LD count: 0x%x\n",
4905
+ __func__, tgtid_count);
4906
+
45914907 if ((tgtid_count > (instance->fw_supported_vd_count)))
45924908 break;
45934909
....@@ -4595,8 +4911,145 @@
45954911 for (ld_index = 0; ld_index < tgtid_count; ld_index++) {
45964912 ids = ci->targetId[ld_index];
45974913 instance->ld_ids[ids] = ci->targetId[ld_index];
4914
+ if (megasas_dbg_lvl & LD_PD_DEBUG)
4915
+ dev_info(&instance->pdev->dev, "LD%d: targetID: 0x%03x\n",
4916
+ ld_index, ci->targetId[ld_index]);
45984917 }
45994918
4919
+ break;
4920
+ }
4921
+
4922
+ if (ret != DCMD_TIMEOUT)
4923
+ megasas_return_cmd(instance, cmd);
4924
+
4925
+ return ret;
4926
+}
4927
+
4928
+/**
4929
+ * dcmd.opcode - MR_DCMD_CTRL_DEVICE_LIST_GET
4930
+ * dcmd.mbox - reserved
4931
+ * dcmd.sge IN - ptr to return MR_HOST_DEVICE_LIST structure
4932
+ * Desc: This DCMD will return the combined device list
4933
+ * Status: MFI_STAT_OK - List returned successfully
4934
+ * MFI_STAT_INVALID_CMD - Firmware support for the feature has been
4935
+ * disabled
4936
+ * @instance: Adapter soft state
4937
+ * @is_probe: Driver probe check
4938
+ * Return: 0 if DCMD succeeded
4939
+ * non-zero if failed
4940
+ */
4941
+static int
4942
+megasas_host_device_list_query(struct megasas_instance *instance,
4943
+ bool is_probe)
4944
+{
4945
+ int ret, i, target_id;
4946
+ struct megasas_cmd *cmd;
4947
+ struct megasas_dcmd_frame *dcmd;
4948
+ struct MR_HOST_DEVICE_LIST *ci;
4949
+ u32 count;
4950
+ dma_addr_t ci_h;
4951
+
4952
+ ci = instance->host_device_list_buf;
4953
+ ci_h = instance->host_device_list_buf_h;
4954
+
4955
+ cmd = megasas_get_cmd(instance);
4956
+
4957
+ if (!cmd) {
4958
+ dev_warn(&instance->pdev->dev,
4959
+ "%s: failed to get cmd\n",
4960
+ __func__);
4961
+ return -ENOMEM;
4962
+ }
4963
+
4964
+ dcmd = &cmd->frame->dcmd;
4965
+
4966
+ memset(ci, 0, sizeof(*ci));
4967
+ memset(dcmd->mbox.b, 0, MFI_MBOX_SIZE);
4968
+
4969
+ dcmd->mbox.b[0] = is_probe ? 0 : 1;
4970
+ dcmd->cmd = MFI_CMD_DCMD;
4971
+ dcmd->cmd_status = MFI_STAT_INVALID_STATUS;
4972
+ dcmd->sge_count = 1;
4973
+ dcmd->flags = MFI_FRAME_DIR_READ;
4974
+ dcmd->timeout = 0;
4975
+ dcmd->pad_0 = 0;
4976
+ dcmd->data_xfer_len = cpu_to_le32(HOST_DEVICE_LIST_SZ);
4977
+ dcmd->opcode = cpu_to_le32(MR_DCMD_CTRL_DEVICE_LIST_GET);
4978
+
4979
+ megasas_set_dma_settings(instance, dcmd, ci_h, HOST_DEVICE_LIST_SZ);
4980
+
4981
+ if (!instance->mask_interrupts) {
4982
+ ret = megasas_issue_blocked_cmd(instance, cmd,
4983
+ MFI_IO_TIMEOUT_SECS);
4984
+ } else {
4985
+ ret = megasas_issue_polled(instance, cmd);
4986
+ cmd->flags |= DRV_DCMD_SKIP_REFIRE;
4987
+ }
4988
+
4989
+ switch (ret) {
4990
+ case DCMD_SUCCESS:
4991
+ /* Fill the internal pd_list and ld_ids array based on
4992
+ * targetIds returned by FW
4993
+ */
4994
+ count = le32_to_cpu(ci->count);
4995
+
4996
+ if (count > (MEGASAS_MAX_PD + MAX_LOGICAL_DRIVES_EXT))
4997
+ break;
4998
+
4999
+ if (megasas_dbg_lvl & LD_PD_DEBUG)
5000
+ dev_info(&instance->pdev->dev, "%s, Device count: 0x%x\n",
5001
+ __func__, count);
5002
+
5003
+ memset(instance->local_pd_list, 0,
5004
+ MEGASAS_MAX_PD * sizeof(struct megasas_pd_list));
5005
+ memset(instance->ld_ids, 0xff, MAX_LOGICAL_DRIVES_EXT);
5006
+ for (i = 0; i < count; i++) {
5007
+ target_id = le16_to_cpu(ci->host_device_list[i].target_id);
5008
+ if (ci->host_device_list[i].flags.u.bits.is_sys_pd) {
5009
+ instance->local_pd_list[target_id].tid = target_id;
5010
+ instance->local_pd_list[target_id].driveType =
5011
+ ci->host_device_list[i].scsi_type;
5012
+ instance->local_pd_list[target_id].driveState =
5013
+ MR_PD_STATE_SYSTEM;
5014
+ if (megasas_dbg_lvl & LD_PD_DEBUG)
5015
+ dev_info(&instance->pdev->dev,
5016
+ "Device %d: PD targetID: 0x%03x deviceType:0x%x\n",
5017
+ i, target_id, ci->host_device_list[i].scsi_type);
5018
+ } else {
5019
+ instance->ld_ids[target_id] = target_id;
5020
+ if (megasas_dbg_lvl & LD_PD_DEBUG)
5021
+ dev_info(&instance->pdev->dev,
5022
+ "Device %d: LD targetID: 0x%03x\n",
5023
+ i, target_id);
5024
+ }
5025
+ }
5026
+
5027
+ memcpy(instance->pd_list, instance->local_pd_list,
5028
+ sizeof(instance->pd_list));
5029
+ break;
5030
+
5031
+ case DCMD_TIMEOUT:
5032
+ switch (dcmd_timeout_ocr_possible(instance)) {
5033
+ case INITIATE_OCR:
5034
+ cmd->flags |= DRV_DCMD_SKIP_REFIRE;
5035
+ mutex_unlock(&instance->reset_mutex);
5036
+ megasas_reset_fusion(instance->host,
5037
+ MFI_IO_TIMEOUT_OCR);
5038
+ mutex_lock(&instance->reset_mutex);
5039
+ break;
5040
+ case KILL_ADAPTER:
5041
+ megaraid_sas_kill_hba(instance);
5042
+ break;
5043
+ case IGNORE_TIMEOUT:
5044
+ dev_info(&instance->pdev->dev, "Ignore DCMD timeout: %s %d\n",
5045
+ __func__, __LINE__);
5046
+ break;
5047
+ }
5048
+ break;
5049
+ case DCMD_FAILED:
5050
+ dev_err(&instance->pdev->dev,
5051
+ "%s: MR_DCMD_CTRL_DEVICE_LIST_GET failed\n",
5052
+ __func__);
46005053 break;
46015054 }
46025055
....@@ -4639,9 +5092,9 @@
46395092 }
46405093
46415094 dev_info(&instance->pdev->dev,
4642
- "firmware type\t: %s\n",
4643
- instance->supportmax256vd ? "Extended VD(240 VD)firmware" :
4644
- "Legacy(64 VD) firmware");
5095
+ "FW provided supportMaxExtLDs: %d\tmax_lds: %d\n",
5096
+ instance->ctrl_info_buf->adapterOperations3.supportMaxExtLDs ? 1 : 0,
5097
+ instance->ctrl_info_buf->max_lds);
46455098
46465099 if (instance->max_raid_mapsize) {
46475100 ventura_map_sz = instance->max_raid_mapsize *
....@@ -4664,6 +5117,89 @@
46645117 }
46655118 /* irrespective of FW raid maps, driver raid map is constant */
46665119 fusion->drv_map_sz = sizeof(struct MR_DRV_RAID_MAP_ALL);
5120
+}
5121
+
5122
+/*
5123
+ * dcmd.opcode - MR_DCMD_CTRL_SNAPDUMP_GET_PROPERTIES
5124
+ * dcmd.hdr.length - number of bytes to read
5125
+ * dcmd.sge - Ptr to MR_SNAPDUMP_PROPERTIES
5126
+ * Desc: Fill in snapdump properties
5127
+ * Status: MFI_STAT_OK- Command successful
5128
+ */
5129
+void megasas_get_snapdump_properties(struct megasas_instance *instance)
5130
+{
5131
+ int ret = 0;
5132
+ struct megasas_cmd *cmd;
5133
+ struct megasas_dcmd_frame *dcmd;
5134
+ struct MR_SNAPDUMP_PROPERTIES *ci;
5135
+ dma_addr_t ci_h = 0;
5136
+
5137
+ ci = instance->snapdump_prop;
5138
+ ci_h = instance->snapdump_prop_h;
5139
+
5140
+ if (!ci)
5141
+ return;
5142
+
5143
+ cmd = megasas_get_cmd(instance);
5144
+
5145
+ if (!cmd) {
5146
+ dev_dbg(&instance->pdev->dev, "Failed to get a free cmd\n");
5147
+ return;
5148
+ }
5149
+
5150
+ dcmd = &cmd->frame->dcmd;
5151
+
5152
+ memset(ci, 0, sizeof(*ci));
5153
+ memset(dcmd->mbox.b, 0, MFI_MBOX_SIZE);
5154
+
5155
+ dcmd->cmd = MFI_CMD_DCMD;
5156
+ dcmd->cmd_status = MFI_STAT_INVALID_STATUS;
5157
+ dcmd->sge_count = 1;
5158
+ dcmd->flags = MFI_FRAME_DIR_READ;
5159
+ dcmd->timeout = 0;
5160
+ dcmd->pad_0 = 0;
5161
+ dcmd->data_xfer_len = cpu_to_le32(sizeof(struct MR_SNAPDUMP_PROPERTIES));
5162
+ dcmd->opcode = cpu_to_le32(MR_DCMD_CTRL_SNAPDUMP_GET_PROPERTIES);
5163
+
5164
+ megasas_set_dma_settings(instance, dcmd, ci_h,
5165
+ sizeof(struct MR_SNAPDUMP_PROPERTIES));
5166
+
5167
+ if (!instance->mask_interrupts) {
5168
+ ret = megasas_issue_blocked_cmd(instance, cmd,
5169
+ MFI_IO_TIMEOUT_SECS);
5170
+ } else {
5171
+ ret = megasas_issue_polled(instance, cmd);
5172
+ cmd->flags |= DRV_DCMD_SKIP_REFIRE;
5173
+ }
5174
+
5175
+ switch (ret) {
5176
+ case DCMD_SUCCESS:
5177
+ instance->snapdump_wait_time =
5178
+ min_t(u8, ci->trigger_min_num_sec_before_ocr,
5179
+ MEGASAS_MAX_SNAP_DUMP_WAIT_TIME);
5180
+ break;
5181
+
5182
+ case DCMD_TIMEOUT:
5183
+ switch (dcmd_timeout_ocr_possible(instance)) {
5184
+ case INITIATE_OCR:
5185
+ cmd->flags |= DRV_DCMD_SKIP_REFIRE;
5186
+ mutex_unlock(&instance->reset_mutex);
5187
+ megasas_reset_fusion(instance->host,
5188
+ MFI_IO_TIMEOUT_OCR);
5189
+ mutex_lock(&instance->reset_mutex);
5190
+ break;
5191
+ case KILL_ADAPTER:
5192
+ megaraid_sas_kill_hba(instance);
5193
+ break;
5194
+ case IGNORE_TIMEOUT:
5195
+ dev_info(&instance->pdev->dev, "Ignore DCMD timeout: %s %d\n",
5196
+ __func__, __LINE__);
5197
+ break;
5198
+ }
5199
+ }
5200
+
5201
+ if (ret != DCMD_TIMEOUT)
5202
+ megasas_return_cmd(instance, cmd);
46675203 }
46685204
46695205 /**
....@@ -4725,9 +5261,11 @@
47255261 * CPU endianness format.
47265262 */
47275263 le32_to_cpus((u32 *)&ci->properties.OnOffProperties);
5264
+ le16_to_cpus((u16 *)&ci->properties.on_off_properties2);
47285265 le32_to_cpus((u32 *)&ci->adapterOperations2);
47295266 le32_to_cpus((u32 *)&ci->adapterOperations3);
47305267 le16_to_cpus((u16 *)&ci->adapter_operations4);
5268
+ le32_to_cpus((u32 *)&ci->adapter_operations5);
47315269
47325270 /* Update the latest Ext VD info.
47335271 * From Init path, store current firmware details.
....@@ -4735,17 +5273,27 @@
47355273 * in case of Firmware upgrade without system reboot.
47365274 */
47375275 megasas_update_ext_vd_details(instance);
4738
- instance->use_seqnum_jbod_fp =
5276
+ instance->support_seqnum_jbod_fp =
47395277 ci->adapterOperations3.useSeqNumJbodFP;
47405278 instance->support_morethan256jbod =
47415279 ci->adapter_operations4.support_pd_map_target_id;
47425280 instance->support_nvme_passthru =
47435281 ci->adapter_operations4.support_nvme_passthru;
5282
+ instance->support_pci_lane_margining =
5283
+ ci->adapter_operations5.support_pci_lane_margining;
47445284 instance->task_abort_tmo = ci->TaskAbortTO;
47455285 instance->max_reset_tmo = ci->MaxResetTO;
47465286
47475287 /*Check whether controller is iMR or MR */
47485288 instance->is_imr = (ci->memory_size ? 0 : 1);
5289
+
5290
+ instance->snapdump_wait_time =
5291
+ (ci->properties.on_off_properties2.enable_snap_dump ?
5292
+ MEGASAS_DEFAULT_SNAP_DUMP_WAIT_TIME : 0);
5293
+
5294
+ instance->enable_fw_dev_list =
5295
+ ci->properties.on_off_properties2.enable_fw_dev_list;
5296
+
47495297 dev_info(&instance->pdev->dev,
47505298 "controller type\t: %s(%dMB)\n",
47515299 instance->is_imr ? "iMR" : "MR",
....@@ -4764,6 +5312,10 @@
47645312 dev_info(&instance->pdev->dev,
47655313 "FW provided TM TaskAbort/Reset timeout\t: %d secs/%d secs\n",
47665314 instance->task_abort_tmo, instance->max_reset_tmo);
5315
+ dev_info(&instance->pdev->dev, "JBOD sequence map support\t: %s\n",
5316
+ instance->support_seqnum_jbod_fp ? "Yes" : "No");
5317
+ dev_info(&instance->pdev->dev, "PCI Lane Margining support\t: %s\n",
5318
+ instance->support_pci_lane_margining ? "Yes" : "No");
47675319
47685320 break;
47695321
....@@ -4771,8 +5323,10 @@
47715323 switch (dcmd_timeout_ocr_possible(instance)) {
47725324 case INITIATE_OCR:
47735325 cmd->flags |= DRV_DCMD_SKIP_REFIRE;
5326
+ mutex_unlock(&instance->reset_mutex);
47745327 megasas_reset_fusion(instance->host,
47755328 MFI_IO_TIMEOUT_OCR);
5329
+ mutex_lock(&instance->reset_mutex);
47765330 break;
47775331 case KILL_ADAPTER:
47785332 megaraid_sas_kill_hba(instance);
....@@ -4947,16 +5501,13 @@
49475501 static u32
49485502 megasas_init_adapter_mfi(struct megasas_instance *instance)
49495503 {
4950
- struct megasas_register_set __iomem *reg_set;
49515504 u32 context_sz;
49525505 u32 reply_q_sz;
4953
-
4954
- reg_set = instance->reg_set;
49555506
49565507 /*
49575508 * Get various operational parameters from status register
49585509 */
4959
- instance->max_fw_cmds = instance->instancet->read_fw_status_reg(reg_set) & 0x00FFFF;
5510
+ instance->max_fw_cmds = instance->instancet->read_fw_status_reg(instance) & 0x00FFFF;
49605511 /*
49615512 * Reduce the max supported cmds by 1. This is to ensure that the
49625513 * reply_q_sz (1 more than the max cmd that driver may send)
....@@ -4964,7 +5515,7 @@
49645515 */
49655516 instance->max_fw_cmds = instance->max_fw_cmds-1;
49665517 instance->max_mfi_cmds = instance->max_fw_cmds;
4967
- instance->max_num_sge = (instance->instancet->read_fw_status_reg(reg_set) & 0xFF0000) >>
5518
+ instance->max_num_sge = (instance->instancet->read_fw_status_reg(instance) & 0xFF0000) >>
49685519 0x10;
49695520 /*
49705521 * For MFI skinny adapters, MEGASAS_SKINNY_INT_CMDS commands
....@@ -5000,9 +5551,8 @@
50005551 context_sz = sizeof(u32);
50015552 reply_q_sz = context_sz * (instance->max_fw_cmds + 1);
50025553
5003
- instance->reply_queue = pci_alloc_consistent(instance->pdev,
5004
- reply_q_sz,
5005
- &instance->reply_queue_h);
5554
+ instance->reply_queue = dma_alloc_coherent(&instance->pdev->dev,
5555
+ reply_q_sz, &instance->reply_queue_h, GFP_KERNEL);
50065556
50075557 if (!instance->reply_queue) {
50085558 dev_printk(KERN_DEBUG, &instance->pdev->dev, "Out of DMA mem for reply queue\n");
....@@ -5021,7 +5571,7 @@
50215571
50225572 instance->fw_support_ieee = 0;
50235573 instance->fw_support_ieee =
5024
- (instance->instancet->read_fw_status_reg(reg_set) &
5574
+ (instance->instancet->read_fw_status_reg(instance) &
50255575 0x04000000);
50265576
50275577 dev_notice(&instance->pdev->dev, "megasas_init_mfi: fw_support_ieee=%d",
....@@ -5034,13 +5584,32 @@
50345584
50355585 fail_fw_init:
50365586
5037
- pci_free_consistent(instance->pdev, reply_q_sz,
5587
+ dma_free_coherent(&instance->pdev->dev, reply_q_sz,
50385588 instance->reply_queue, instance->reply_queue_h);
50395589 fail_reply_queue:
50405590 megasas_free_cmds(instance);
50415591
50425592 fail_alloc_cmds:
50435593 return 1;
5594
+}
5595
+
5596
+static
5597
+void megasas_setup_irq_poll(struct megasas_instance *instance)
5598
+{
5599
+ struct megasas_irq_context *irq_ctx;
5600
+ u32 count, i;
5601
+
5602
+ count = instance->msix_vectors > 0 ? instance->msix_vectors : 1;
5603
+
5604
+ /* Initialize IRQ poll */
5605
+ for (i = 0; i < count; i++) {
5606
+ irq_ctx = &instance->irq_context[i];
5607
+ irq_ctx->os_irq = pci_irq_vector(instance->pdev, i);
5608
+ irq_ctx->irq_poll_scheduled = false;
5609
+ irq_poll_init(&irq_ctx->irqpoll,
5610
+ instance->threshold_reply_count,
5611
+ megasas_irqpoll);
5612
+ }
50445613 }
50455614
50465615 /*
....@@ -5059,14 +5628,18 @@
50595628 pdev = instance->pdev;
50605629 instance->irq_context[0].instance = instance;
50615630 instance->irq_context[0].MSIxIndex = 0;
5631
+ snprintf(instance->irq_context->name, MEGASAS_MSIX_NAME_LEN, "%s%u",
5632
+ "megasas", instance->host->host_no);
50625633 if (request_irq(pci_irq_vector(pdev, 0),
50635634 instance->instancet->service_isr, IRQF_SHARED,
5064
- "megasas", &instance->irq_context[0])) {
5635
+ instance->irq_context->name, &instance->irq_context[0])) {
50655636 dev_err(&instance->pdev->dev,
50665637 "Failed to register IRQ from %s %d\n",
50675638 __func__, __LINE__);
50685639 return -1;
50695640 }
5641
+ instance->perf_mode = MR_LATENCY_PERF_MODE;
5642
+ instance->low_latency_index_start = 0;
50705643 return 0;
50715644 }
50725645
....@@ -5091,16 +5664,23 @@
50915664 for (i = 0; i < instance->msix_vectors; i++) {
50925665 instance->irq_context[i].instance = instance;
50935666 instance->irq_context[i].MSIxIndex = i;
5667
+ snprintf(instance->irq_context[i].name, MEGASAS_MSIX_NAME_LEN, "%s%u-msix%u",
5668
+ "megasas", instance->host->host_no, i);
50945669 if (request_irq(pci_irq_vector(pdev, i),
5095
- instance->instancet->service_isr, 0, "megasas",
5670
+ instance->instancet->service_isr, 0, instance->irq_context[i].name,
50965671 &instance->irq_context[i])) {
50975672 dev_err(&instance->pdev->dev,
50985673 "Failed to register IRQ for vector %d.\n", i);
5099
- for (j = 0; j < i; j++)
5674
+ for (j = 0; j < i; j++) {
5675
+ if (j < instance->low_latency_index_start)
5676
+ irq_set_affinity_hint(
5677
+ pci_irq_vector(pdev, j), NULL);
51005678 free_irq(pci_irq_vector(pdev, j),
51015679 &instance->irq_context[j]);
5680
+ }
51025681 /* Retry irq register for IO_APIC*/
51035682 instance->msix_vectors = 0;
5683
+ instance->msix_load_balance = false;
51045684 if (is_probe) {
51055685 pci_free_irq_vectors(instance->pdev);
51065686 return megasas_setup_irqs_ioapic(instance);
....@@ -5109,6 +5689,7 @@
51095689 }
51105690 }
51115691 }
5692
+
51125693 return 0;
51135694 }
51145695
....@@ -5121,9 +5702,22 @@
51215702 megasas_destroy_irqs(struct megasas_instance *instance) {
51225703
51235704 int i;
5705
+ int count;
5706
+ struct megasas_irq_context *irq_ctx;
5707
+
5708
+ count = instance->msix_vectors > 0 ? instance->msix_vectors : 1;
5709
+ if (instance->adapter_type != MFI_SERIES) {
5710
+ for (i = 0; i < count; i++) {
5711
+ irq_ctx = &instance->irq_context[i];
5712
+ irq_poll_disable(&irq_ctx->irqpoll);
5713
+ }
5714
+ }
51245715
51255716 if (instance->msix_vectors)
51265717 for (i = 0; i < instance->msix_vectors; i++) {
5718
+ if (i < instance->low_latency_index_start)
5719
+ irq_set_affinity_hint(
5720
+ pci_irq_vector(instance->pdev, i), NULL);
51275721 free_irq(pci_irq_vector(instance->pdev, i),
51285722 &instance->irq_context[i]);
51295723 }
....@@ -5135,7 +5729,6 @@
51355729 /**
51365730 * megasas_setup_jbod_map - setup jbod map for FP seq_number.
51375731 * @instance: Adapter soft state
5138
- * @is_probe: Driver probe check
51395732 *
51405733 * Return 0 on success.
51415734 */
....@@ -5149,10 +5742,12 @@
51495742 pd_seq_map_sz = sizeof(struct MR_PD_CFG_SEQ_NUM_SYNC) +
51505743 (sizeof(struct MR_PD_CFG_SEQ) * (MAX_PHYSICAL_DEVICES - 1));
51515744
5745
+ instance->use_seqnum_jbod_fp =
5746
+ instance->support_seqnum_jbod_fp;
51525747 if (reset_devices || !fusion ||
5153
- !instance->ctrl_info_buf->adapterOperations3.useSeqNumJbodFP) {
5748
+ !instance->support_seqnum_jbod_fp) {
51545749 dev_info(&instance->pdev->dev,
5155
- "Jbod map is not supported %s %d\n",
5750
+ "JBOD sequence map is disabled %s %d\n",
51565751 __func__, __LINE__);
51575752 instance->use_seqnum_jbod_fp = false;
51585753 return;
....@@ -5191,9 +5786,11 @@
51915786 static void megasas_setup_reply_map(struct megasas_instance *instance)
51925787 {
51935788 const struct cpumask *mask;
5194
- unsigned int queue, cpu;
5789
+ unsigned int queue, cpu, low_latency_index_start;
51955790
5196
- for (queue = 0; queue < instance->msix_vectors; queue++) {
5791
+ low_latency_index_start = instance->low_latency_index_start;
5792
+
5793
+ for (queue = low_latency_index_start; queue < instance->msix_vectors; queue++) {
51975794 mask = pci_irq_get_affinity(instance->pdev, queue);
51985795 if (!mask)
51995796 goto fallback;
....@@ -5204,8 +5801,131 @@
52045801 return;
52055802
52065803 fallback:
5207
- for_each_possible_cpu(cpu)
5208
- instance->reply_map[cpu] = cpu % instance->msix_vectors;
5804
+ queue = low_latency_index_start;
5805
+ for_each_possible_cpu(cpu) {
5806
+ instance->reply_map[cpu] = queue;
5807
+ if (queue == (instance->msix_vectors - 1))
5808
+ queue = low_latency_index_start;
5809
+ else
5810
+ queue++;
5811
+ }
5812
+}
5813
+
5814
+/**
5815
+ * megasas_get_device_list - Get the PD and LD device list from FW.
5816
+ * @instance: Adapter soft state
5817
+ * @return: Success or failure
5818
+ *
5819
+ * Issue DCMDs to Firmware to get the PD and LD list.
5820
+ * Based on the FW support, driver sends the HOST_DEVICE_LIST or combination
5821
+ * of PD_LIST/LD_LIST_QUERY DCMDs to get the device list.
5822
+ */
5823
+static
5824
+int megasas_get_device_list(struct megasas_instance *instance)
5825
+{
5826
+ memset(instance->pd_list, 0,
5827
+ (MEGASAS_MAX_PD * sizeof(struct megasas_pd_list)));
5828
+ memset(instance->ld_ids, 0xff, MEGASAS_MAX_LD_IDS);
5829
+
5830
+ if (instance->enable_fw_dev_list) {
5831
+ if (megasas_host_device_list_query(instance, true))
5832
+ return FAILED;
5833
+ } else {
5834
+ if (megasas_get_pd_list(instance) < 0) {
5835
+ dev_err(&instance->pdev->dev, "failed to get PD list\n");
5836
+ return FAILED;
5837
+ }
5838
+
5839
+ if (megasas_ld_list_query(instance,
5840
+ MR_LD_QUERY_TYPE_EXPOSED_TO_HOST)) {
5841
+ dev_err(&instance->pdev->dev, "failed to get LD list\n");
5842
+ return FAILED;
5843
+ }
5844
+ }
5845
+
5846
+ return SUCCESS;
5847
+}
5848
+
5849
+/**
5850
+ * megasas_set_high_iops_queue_affinity_hint - Set affinity hint for high IOPS queues
5851
+ * @instance: Adapter soft state
5852
+ * return: void
5853
+ */
5854
+static inline void
5855
+megasas_set_high_iops_queue_affinity_hint(struct megasas_instance *instance)
5856
+{
5857
+ int i;
5858
+ int local_numa_node;
5859
+
5860
+ if (instance->perf_mode == MR_BALANCED_PERF_MODE) {
5861
+ local_numa_node = dev_to_node(&instance->pdev->dev);
5862
+
5863
+ for (i = 0; i < instance->low_latency_index_start; i++)
5864
+ irq_set_affinity_hint(pci_irq_vector(instance->pdev, i),
5865
+ cpumask_of_node(local_numa_node));
5866
+ }
5867
+}
5868
+
5869
+static int
5870
+__megasas_alloc_irq_vectors(struct megasas_instance *instance)
5871
+{
5872
+ int i, irq_flags;
5873
+ struct irq_affinity desc = { .pre_vectors = instance->low_latency_index_start };
5874
+ struct irq_affinity *descp = &desc;
5875
+
5876
+ irq_flags = PCI_IRQ_MSIX;
5877
+
5878
+ if (instance->smp_affinity_enable)
5879
+ irq_flags |= PCI_IRQ_AFFINITY;
5880
+ else
5881
+ descp = NULL;
5882
+
5883
+ i = pci_alloc_irq_vectors_affinity(instance->pdev,
5884
+ instance->low_latency_index_start,
5885
+ instance->msix_vectors, irq_flags, descp);
5886
+
5887
+ return i;
5888
+}
5889
+
5890
+/**
5891
+ * megasas_alloc_irq_vectors - Allocate IRQ vectors/enable MSI-x vectors
5892
+ * @instance: Adapter soft state
5893
+ * return: void
5894
+ */
5895
+static void
5896
+megasas_alloc_irq_vectors(struct megasas_instance *instance)
5897
+{
5898
+ int i;
5899
+ unsigned int num_msix_req;
5900
+
5901
+ i = __megasas_alloc_irq_vectors(instance);
5902
+
5903
+ if ((instance->perf_mode == MR_BALANCED_PERF_MODE) &&
5904
+ (i != instance->msix_vectors)) {
5905
+ if (instance->msix_vectors)
5906
+ pci_free_irq_vectors(instance->pdev);
5907
+ /* Disable Balanced IOPS mode and try realloc vectors */
5908
+ instance->perf_mode = MR_LATENCY_PERF_MODE;
5909
+ instance->low_latency_index_start = 1;
5910
+ num_msix_req = num_online_cpus() + instance->low_latency_index_start;
5911
+
5912
+ instance->msix_vectors = min(num_msix_req,
5913
+ instance->msix_vectors);
5914
+
5915
+ i = __megasas_alloc_irq_vectors(instance);
5916
+
5917
+ }
5918
+
5919
+ dev_info(&instance->pdev->dev,
5920
+ "requested/available msix %d/%d\n", instance->msix_vectors, i);
5921
+
5922
+ if (i > 0)
5923
+ instance->msix_vectors = i;
5924
+ else
5925
+ instance->msix_vectors = 0;
5926
+
5927
+ if (instance->smp_affinity_enable)
5928
+ megasas_set_high_iops_queue_affinity_hint(instance);
52095929 }
52105930
52115931 /**
....@@ -5219,15 +5939,17 @@
52195939 {
52205940 u32 max_sectors_1;
52215941 u32 max_sectors_2, tmp_sectors, msix_enable;
5222
- u32 scratch_pad_2, scratch_pad_3, scratch_pad_4, status_reg;
5942
+ u32 scratch_pad_1, scratch_pad_2, scratch_pad_3, status_reg;
52235943 resource_size_t base_addr;
5224
- struct megasas_register_set __iomem *reg_set;
5944
+ void *base_addr_phys;
52255945 struct megasas_ctrl_info *ctrl_info = NULL;
52265946 unsigned long bar_list;
5227
- int i, j, loop, fw_msix_count = 0;
5947
+ int i, j, loop;
52285948 struct IOV_111 *iovPtr;
52295949 struct fusion_context *fusion;
5230
- bool do_adp_reset = true;
5950
+ bool intr_coalescing;
5951
+ unsigned int num_msix_req;
5952
+ u16 lnksta, speed;
52315953
52325954 fusion = instance->ctrl_context;
52335955
....@@ -5241,14 +5963,17 @@
52415963 }
52425964
52435965 base_addr = pci_resource_start(instance->pdev, instance->bar);
5244
- instance->reg_set = ioremap_nocache(base_addr, 8192);
5966
+ instance->reg_set = ioremap(base_addr, 8192);
52455967
52465968 if (!instance->reg_set) {
52475969 dev_printk(KERN_DEBUG, &instance->pdev->dev, "Failed to map IO mem\n");
52485970 goto fail_ioremap;
52495971 }
52505972
5251
- reg_set = instance->reg_set;
5973
+ base_addr_phys = &base_addr;
5974
+ dev_printk(KERN_DEBUG, &instance->pdev->dev,
5975
+ "BAR:0x%lx BAR's base_addr(phys):%pa mapped virt_addr:0x%p\n",
5976
+ instance->bar, base_addr_phys, instance->reg_set);
52525977
52535978 if (instance->adapter_type != MFI_SERIES)
52545979 instance->instancet = &megasas_instance_template_fusion;
....@@ -5276,29 +6001,35 @@
52766001 }
52776002
52786003 if (megasas_transition_to_ready(instance, 0)) {
5279
- if (instance->adapter_type >= INVADER_SERIES) {
6004
+ dev_info(&instance->pdev->dev,
6005
+ "Failed to transition controller to ready from %s!\n",
6006
+ __func__);
6007
+ if (instance->adapter_type != MFI_SERIES) {
52806008 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) {
6009
+ instance);
6010
+ if (status_reg & MFI_RESET_ADAPTER) {
6011
+ if (megasas_adp_reset_wait_for_ready
6012
+ (instance, true, 0) == FAILED)
6013
+ goto fail_ready_state;
6014
+ } else {
6015
+ goto fail_ready_state;
6016
+ }
6017
+ } else {
52866018 atomic_set(&instance->fw_reset_no_pci_access, 1);
52876019 instance->instancet->adp_reset
52886020 (instance, instance->reg_set);
52896021 atomic_set(&instance->fw_reset_no_pci_access, 0);
5290
- dev_info(&instance->pdev->dev,
5291
- "FW restarted successfully from %s!\n",
5292
- __func__);
52936022
52946023 /*waiting for about 30 second before retry*/
52956024 ssleep(30);
52966025
52976026 if (megasas_transition_to_ready(instance, 0))
52986027 goto fail_ready_state;
5299
- } else {
5300
- goto fail_ready_state;
53016028 }
6029
+
6030
+ dev_info(&instance->pdev->dev,
6031
+ "FW restarted successfully from %s!\n",
6032
+ __func__);
53026033 }
53036034
53046035 megasas_init_ctrl_params(instance);
....@@ -5314,31 +6045,43 @@
53146045
53156046 fusion = instance->ctrl_context;
53166047
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 >>
6048
+ if (instance->adapter_type >= VENTURA_SERIES) {
6049
+ scratch_pad_2 =
6050
+ megasas_readl(instance,
6051
+ &instance->reg_set->outbound_scratch_pad_2);
6052
+ instance->max_raid_mapsize = ((scratch_pad_2 >>
53216053 MR_MAX_RAID_MAP_SIZE_OFFSET_SHIFT) &
53226054 MR_MAX_RAID_MAP_SIZE_MASK);
53236055 }
53246056
6057
+ instance->enable_sdev_max_qd = enable_sdev_max_qd;
6058
+
6059
+ switch (instance->adapter_type) {
6060
+ case VENTURA_SERIES:
6061
+ fusion->pcie_bw_limitation = true;
6062
+ break;
6063
+ case AERO_SERIES:
6064
+ fusion->r56_div_offload = true;
6065
+ break;
6066
+ default:
6067
+ break;
6068
+ }
6069
+
53256070 /* Check if MSI-X is supported while in ready state */
5326
- msix_enable = (instance->instancet->read_fw_status_reg(reg_set) &
6071
+ msix_enable = (instance->instancet->read_fw_status_reg(instance) &
53276072 0x4000000) >> 0x1a;
53286073 if (msix_enable && !msix_disable) {
5329
- int irq_flags = PCI_IRQ_MSIX;
53306074
5331
- scratch_pad_2 = readl
5332
- (&instance->reg_set->outbound_scratch_pad_2);
6075
+ scratch_pad_1 = megasas_readl
6076
+ (instance, &instance->reg_set->outbound_scratch_pad_1);
53336077 /* Check max MSI-X vectors */
53346078 if (fusion) {
53356079 if (instance->adapter_type == THUNDERBOLT_SERIES) {
53366080 /* Thunderbolt Series*/
5337
- instance->msix_vectors = (scratch_pad_2
6081
+ instance->msix_vectors = (scratch_pad_1
53386082 & MR_MAX_REPLY_QUEUES_OFFSET) + 1;
5339
- fw_msix_count = instance->msix_vectors;
53406083 } else {
5341
- instance->msix_vectors = ((scratch_pad_2
6084
+ instance->msix_vectors = ((scratch_pad_1
53426085 & MR_MAX_REPLY_QUEUES_EXT_OFFSET)
53436086 >> MR_MAX_REPLY_QUEUES_EXT_OFFSET_SHIFT) + 1;
53446087
....@@ -5355,6 +6098,7 @@
53556098 if (instance->msix_vectors > 8)
53566099 instance->msix_combined = true;
53576100 break;
6101
+ case AERO_SERIES:
53586102 case VENTURA_SERIES:
53596103 if (instance->msix_vectors > 16)
53606104 instance->msix_combined = true;
....@@ -5362,9 +6106,15 @@
53626106 }
53636107
53646108 if (rdpq_enable)
5365
- instance->is_rdpq = (scratch_pad_2 & MR_RDPQ_MODE_OFFSET) ?
6109
+ instance->is_rdpq = (scratch_pad_1 & MR_RDPQ_MODE_OFFSET) ?
53666110 1 : 0;
5367
- fw_msix_count = instance->msix_vectors;
6111
+
6112
+ if (instance->adapter_type >= INVADER_SERIES &&
6113
+ !instance->msix_combined) {
6114
+ instance->msix_load_balance = true;
6115
+ instance->smp_affinity_enable = false;
6116
+ }
6117
+
53686118 /* Save 1-15 reply post index address to local memory
53696119 * Index 0 is already saved from reg offset
53706120 * MPI2_REPLY_POST_HOST_INDEX_OFFSET
....@@ -5377,22 +6127,91 @@
53776127 + (loop * 0x10));
53786128 }
53796129 }
6130
+
6131
+ dev_info(&instance->pdev->dev,
6132
+ "firmware supports msix\t: (%d)",
6133
+ instance->msix_vectors);
53806134 if (msix_vectors)
53816135 instance->msix_vectors = min(msix_vectors,
53826136 instance->msix_vectors);
53836137 } else /* MFI adapters */
53846138 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;
6139
+
6140
+
6141
+ /*
6142
+ * For Aero (if some conditions are met), driver will configure a
6143
+ * few additional reply queues with interrupt coalescing enabled.
6144
+ * These queues with interrupt coalescing enabled are called
6145
+ * High IOPS queues and rest of reply queues (based on number of
6146
+ * logical CPUs) are termed as Low latency queues.
6147
+ *
6148
+ * Total Number of reply queues = High IOPS queues + low latency queues
6149
+ *
6150
+ * For rest of fusion adapters, 1 additional reply queue will be
6151
+ * reserved for management commands, rest of reply queues
6152
+ * (based on number of logical CPUs) will be used for IOs and
6153
+ * referenced as IO queues.
6154
+ * Total Number of reply queues = 1 + IO queues
6155
+ *
6156
+ * MFI adapters supports single MSI-x so single reply queue
6157
+ * will be used for IO and management commands.
6158
+ */
6159
+
6160
+ intr_coalescing = (scratch_pad_1 & MR_INTR_COALESCING_SUPPORT_OFFSET) ?
6161
+ true : false;
6162
+ if (intr_coalescing &&
6163
+ (num_online_cpus() >= MR_HIGH_IOPS_QUEUE_COUNT) &&
6164
+ (instance->msix_vectors == MEGASAS_MAX_MSIX_QUEUES))
6165
+ instance->perf_mode = MR_BALANCED_PERF_MODE;
53946166 else
5395
- instance->msix_vectors = 0;
6167
+ instance->perf_mode = MR_LATENCY_PERF_MODE;
6168
+
6169
+
6170
+ if (instance->adapter_type == AERO_SERIES) {
6171
+ pcie_capability_read_word(instance->pdev, PCI_EXP_LNKSTA, &lnksta);
6172
+ speed = lnksta & PCI_EXP_LNKSTA_CLS;
6173
+
6174
+ /*
6175
+ * For Aero, if PCIe link speed is <16 GT/s, then driver should operate
6176
+ * in latency perf mode and enable R1 PCI bandwidth algorithm
6177
+ */
6178
+ if (speed < 0x4) {
6179
+ instance->perf_mode = MR_LATENCY_PERF_MODE;
6180
+ fusion->pcie_bw_limitation = true;
6181
+ }
6182
+
6183
+ /*
6184
+ * Performance mode settings provided through module parameter-perf_mode will
6185
+ * take affect only for:
6186
+ * 1. Aero family of adapters.
6187
+ * 2. When user sets module parameter- perf_mode in range of 0-2.
6188
+ */
6189
+ if ((perf_mode >= MR_BALANCED_PERF_MODE) &&
6190
+ (perf_mode <= MR_LATENCY_PERF_MODE))
6191
+ instance->perf_mode = perf_mode;
6192
+ /*
6193
+ * If intr coalescing is not supported by controller FW, then IOPS
6194
+ * and Balanced modes are not feasible.
6195
+ */
6196
+ if (!intr_coalescing)
6197
+ instance->perf_mode = MR_LATENCY_PERF_MODE;
6198
+
6199
+ }
6200
+
6201
+ if (instance->perf_mode == MR_BALANCED_PERF_MODE)
6202
+ instance->low_latency_index_start =
6203
+ MR_HIGH_IOPS_QUEUE_COUNT;
6204
+ else
6205
+ instance->low_latency_index_start = 1;
6206
+
6207
+ num_msix_req = num_online_cpus() + instance->low_latency_index_start;
6208
+
6209
+ instance->msix_vectors = min(num_msix_req,
6210
+ instance->msix_vectors);
6211
+
6212
+ megasas_alloc_irq_vectors(instance);
6213
+ if (!instance->msix_vectors)
6214
+ instance->msix_load_balance = false;
53966215 }
53976216 /*
53986217 * MSI-X host index 0 is common for all adapter.
....@@ -5417,8 +6236,6 @@
54176236 megasas_setup_reply_map(instance);
54186237
54196238 dev_info(&instance->pdev->dev,
5420
- "firmware supports msix\t: (%d)", fw_msix_count);
5421
- dev_info(&instance->pdev->dev,
54226239 "current msix/online cpus\t: (%d/%d)\n",
54236240 instance->msix_vectors, (unsigned int)num_online_cpus());
54246241 dev_info(&instance->pdev->dev,
....@@ -5437,13 +6254,14 @@
54376254 if (instance->instancet->init_adapter(instance))
54386255 goto fail_init_adapter;
54396256
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) >=
6257
+ if (instance->adapter_type >= VENTURA_SERIES) {
6258
+ scratch_pad_3 =
6259
+ megasas_readl(instance,
6260
+ &instance->reg_set->outbound_scratch_pad_3);
6261
+ if ((scratch_pad_3 & MR_NVME_PAGE_SIZE_MASK) >=
54446262 MR_DEFAULT_NVME_PAGE_SHIFT)
54456263 instance->nvme_page_size =
5446
- (1 << (scratch_pad_4 & MR_NVME_PAGE_SIZE_MASK));
6264
+ (1 << (scratch_pad_3 & MR_NVME_PAGE_SIZE_MASK));
54476265
54486266 dev_info(&instance->pdev->dev,
54496267 "NVME page size\t: (%d)\n", instance->nvme_page_size);
....@@ -5454,26 +6272,24 @@
54546272 megasas_setup_irqs_ioapic(instance))
54556273 goto fail_init_adapter;
54566274
6275
+ if (instance->adapter_type != MFI_SERIES)
6276
+ megasas_setup_irq_poll(instance);
6277
+
54576278 instance->instancet->enable_intr(instance);
54586279
54596280 dev_info(&instance->pdev->dev, "INIT adapter done\n");
54606281
54616282 megasas_setup_jbod_map(instance);
54626283
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");
6284
+ if (megasas_get_device_list(instance) != SUCCESS) {
6285
+ dev_err(&instance->pdev->dev,
6286
+ "%s: megasas_get_device_list failed\n",
6287
+ __func__);
54706288 goto fail_get_ld_pd_list;
54716289 }
54726290
5473
- memset(instance->ld_ids, 0xff, MEGASAS_MAX_LD_IDS);
5474
-
54756291 /* stream detection initialization */
5476
- if (instance->adapter_type == VENTURA_SERIES) {
6292
+ if (instance->adapter_type >= VENTURA_SERIES) {
54776293 fusion->stream_detect_by_ld =
54786294 kcalloc(MAX_LOGICAL_DRIVES_EXT,
54796295 sizeof(struct LD_STREAM_DETECT *),
....@@ -5500,10 +6316,6 @@
55006316 = MR_STREAM_BITMAP;
55016317 }
55026318 }
5503
-
5504
- if (megasas_ld_list_query(instance,
5505
- MR_LD_QUERY_TYPE_EXPOSED_TO_HOST))
5506
- goto fail_get_ld_pd_list;
55076319
55086320 /*
55096321 * Compute the max allowed sectors per IO: The controller info has two
....@@ -5566,13 +6378,18 @@
55666378
55676379 else {
55686380 if (instance->crash_dump_buf)
5569
- pci_free_consistent(instance->pdev,
6381
+ dma_free_coherent(&instance->pdev->dev,
55706382 CRASH_DMA_BUF_SIZE,
55716383 instance->crash_dump_buf,
55726384 instance->crash_dump_h);
55736385 instance->crash_dump_buf = NULL;
55746386 }
55756387
6388
+ if (instance->snapdump_wait_time) {
6389
+ megasas_get_snapdump_properties(instance);
6390
+ dev_info(&instance->pdev->dev, "Snap dump wait time\t: %d\n",
6391
+ instance->snapdump_wait_time);
6392
+ }
55766393
55776394 dev_info(&instance->pdev->dev,
55786395 "pci id\t\t: (0x%04x)/(0x%04x)/(0x%04x)/(0x%04x)\n",
....@@ -5584,9 +6401,8 @@
55846401 instance->UnevenSpanSupport ? "yes" : "no");
55856402 dev_info(&instance->pdev->dev, "firmware crash dump : %s\n",
55866403 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
-
6404
+ dev_info(&instance->pdev->dev, "JBOD sequence map : %s\n",
6405
+ instance->use_seqnum_jbod_fp ? "enabled" : "disabled");
55906406
55916407 instance->max_sectors_per_req = instance->max_num_sge *
55926408 SGE_BUFFER_SIZE / 512;
....@@ -5610,14 +6426,28 @@
56106426
56116427 /* Launch SR-IOV heartbeat timer */
56126428 if (instance->requestorId) {
5613
- if (!megasas_sriov_start_heartbeat(instance, 1))
6429
+ if (!megasas_sriov_start_heartbeat(instance, 1)) {
56146430 megasas_start_timer(instance);
5615
- else
6431
+ } else {
56166432 instance->skip_heartbeat_timer_del = 1;
6433
+ goto fail_get_ld_pd_list;
6434
+ }
56176435 }
6436
+
6437
+ /*
6438
+ * Create and start watchdog thread which will monitor
6439
+ * controller state every 1 sec and trigger OCR when
6440
+ * it enters fault state
6441
+ */
6442
+ if (instance->adapter_type != MFI_SERIES)
6443
+ if (megasas_fusion_start_watchdog(instance) != SUCCESS)
6444
+ goto fail_start_watchdog;
56186445
56196446 return 0;
56206447
6448
+fail_start_watchdog:
6449
+ if (instance->requestorId && !instance->skip_heartbeat_timer_del)
6450
+ del_timer_sync(&instance->sriov_heartbeat_timer);
56216451 fail_get_ld_pd_list:
56226452 instance->instancet->disable_intr(instance);
56236453 megasas_destroy_irqs(instance);
....@@ -5648,7 +6478,7 @@
56486478 u32 reply_q_sz = sizeof(u32) *(instance->max_mfi_cmds + 1);
56496479
56506480 if (instance->reply_queue)
5651
- pci_free_consistent(instance->pdev, reply_q_sz,
6481
+ dma_free_coherent(&instance->pdev->dev, reply_q_sz,
56526482 instance->reply_queue, instance->reply_queue_h);
56536483
56546484 megasas_free_cmds(instance);
....@@ -5687,10 +6517,9 @@
56876517 }
56886518
56896519 dcmd = &cmd->frame->dcmd;
5690
- el_info = pci_zalloc_consistent(instance->pdev,
5691
- sizeof(struct megasas_evt_log_info),
5692
- &el_info_h);
5693
-
6520
+ el_info = dma_alloc_coherent(&instance->pdev->dev,
6521
+ sizeof(struct megasas_evt_log_info),
6522
+ &el_info_h, GFP_KERNEL);
56946523 if (!el_info) {
56956524 megasas_return_cmd(instance, cmd);
56966525 return -ENOMEM;
....@@ -5727,8 +6556,9 @@
57276556 eli->boot_seq_num = el_info->boot_seq_num;
57286557
57296558 dcmd_failed:
5730
- pci_free_consistent(instance->pdev, sizeof(struct megasas_evt_log_info),
5731
- el_info, el_info_h);
6559
+ dma_free_coherent(&instance->pdev->dev,
6560
+ sizeof(struct megasas_evt_log_info),
6561
+ el_info, el_info_h);
57326562
57336563 megasas_return_cmd(instance, cmd);
57346564
....@@ -5739,7 +6569,7 @@
57396569 * megasas_register_aen - Registers for asynchronous event notification
57406570 * @instance: Adapter soft state
57416571 * @seq_num: The starting sequence number
5742
- * @class_locale: Class of the event
6572
+ * @class_locale_word: Class of the event
57436573 *
57446574 * This function subscribes for AEN for events beyond the @seq_num. It requests
57456575 * to be notified if and only if the event is of type @class_locale
....@@ -5936,8 +6766,10 @@
59366766 switch (dcmd_timeout_ocr_possible(instance)) {
59376767 case INITIATE_OCR:
59386768 cmd->flags |= DRV_DCMD_SKIP_REFIRE;
6769
+ mutex_unlock(&instance->reset_mutex);
59396770 megasas_reset_fusion(instance->host,
59406771 MFI_IO_TIMEOUT_OCR);
6772
+ mutex_lock(&instance->reset_mutex);
59416773 break;
59426774 case KILL_ADAPTER:
59436775 megaraid_sas_kill_hba(instance);
....@@ -6072,7 +6904,7 @@
60726904 {
60736905 u64 consistent_mask;
60746906 struct pci_dev *pdev;
6075
- u32 scratch_pad_2;
6907
+ u32 scratch_pad_1;
60766908
60776909 pdev = instance->pdev;
60786910 consistent_mask = (instance->adapter_type >= VENTURA_SERIES) ?
....@@ -6090,10 +6922,10 @@
60906922 * If 32 bit DMA mask fails, then try for 64 bit mask
60916923 * for FW capable of handling 64 bit DMA.
60926924 */
6093
- scratch_pad_2 = readl
6094
- (&instance->reg_set->outbound_scratch_pad_2);
6925
+ scratch_pad_1 = megasas_readl
6926
+ (instance, &instance->reg_set->outbound_scratch_pad_1);
60956927
6096
- if (!(scratch_pad_2 & MR_CAN_HANDLE_64_BIT_DMA_OFFSET))
6928
+ if (!(scratch_pad_1 & MR_CAN_HANDLE_64_BIT_DMA_OFFSET))
60976929 goto fail_set_dma_mask;
60986930 else if (dma_set_mask_and_coherent(&pdev->dev,
60996931 DMA_BIT_MASK(63)))
....@@ -6108,7 +6940,7 @@
61086940 instance->consistent_mask_64bit = true;
61096941
61106942 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"),
6943
+ ((*pdev->dev.dma_mask == DMA_BIT_MASK(63)) ? "63" : "32"),
61126944 (instance->consistent_mask_64bit ? "63" : "32"));
61136945
61146946 return 0;
....@@ -6122,12 +6954,14 @@
61226954 /*
61236955 * megasas_set_adapter_type - Set adapter type.
61246956 * 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
- * };
6957
+ * different categories-
6958
+ * enum MR_ADAPTER_TYPE {
6959
+ * MFI_SERIES = 1,
6960
+ * THUNDERBOLT_SERIES = 2,
6961
+ * INVADER_SERIES = 3,
6962
+ * VENTURA_SERIES = 4,
6963
+ * AERO_SERIES = 5,
6964
+ * };
61316965 * @instance: Adapter soft state
61326966 * return: void
61336967 */
....@@ -6138,6 +6972,12 @@
61386972 instance->adapter_type = MFI_SERIES;
61396973 } else {
61406974 switch (instance->pdev->device) {
6975
+ case PCI_DEVICE_ID_LSI_AERO_10E1:
6976
+ case PCI_DEVICE_ID_LSI_AERO_10E2:
6977
+ case PCI_DEVICE_ID_LSI_AERO_10E5:
6978
+ case PCI_DEVICE_ID_LSI_AERO_10E6:
6979
+ instance->adapter_type = AERO_SERIES;
6980
+ break;
61416981 case PCI_DEVICE_ID_LSI_VENTURA:
61426982 case PCI_DEVICE_ID_LSI_CRUSADER:
61436983 case PCI_DEVICE_ID_LSI_HARPOON:
....@@ -6167,10 +7007,10 @@
61677007
61687008 static inline int megasas_alloc_mfi_ctrl_mem(struct megasas_instance *instance)
61697009 {
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);
7010
+ instance->producer = dma_alloc_coherent(&instance->pdev->dev,
7011
+ sizeof(u32), &instance->producer_h, GFP_KERNEL);
7012
+ instance->consumer = dma_alloc_coherent(&instance->pdev->dev,
7013
+ sizeof(u32), &instance->consumer_h, GFP_KERNEL);
61747014
61757015 if (!instance->producer || !instance->consumer) {
61767016 dev_err(&instance->pdev->dev,
....@@ -6205,6 +7045,7 @@
62057045 if (megasas_alloc_mfi_ctrl_mem(instance))
62067046 goto fail;
62077047 break;
7048
+ case AERO_SERIES:
62087049 case VENTURA_SERIES:
62097050 case THUNDERBOLT_SERIES:
62107051 case INVADER_SERIES:
....@@ -6232,11 +7073,11 @@
62327073 kfree(instance->reply_map);
62337074 if (instance->adapter_type == MFI_SERIES) {
62347075 if (instance->producer)
6235
- pci_free_consistent(instance->pdev, sizeof(u32),
7076
+ dma_free_coherent(&instance->pdev->dev, sizeof(u32),
62367077 instance->producer,
62377078 instance->producer_h);
62387079 if (instance->consumer)
6239
- pci_free_consistent(instance->pdev, sizeof(u32),
7080
+ dma_free_coherent(&instance->pdev->dev, sizeof(u32),
62407081 instance->consumer,
62417082 instance->consumer_h);
62427083 } else {
....@@ -6248,8 +7089,9 @@
62487089 * megasas_alloc_ctrl_dma_buffers - Allocate consistent DMA buffers during
62497090 * driver load time
62507091 *
6251
- * @instance- Adapter soft instance
6252
- * @return- O for SUCCESS
7092
+ * @instance: Adapter soft instance
7093
+ *
7094
+ * @return: O for SUCCESS
62537095 */
62547096 static inline
62557097 int megasas_alloc_ctrl_dma_buffers(struct megasas_instance *instance)
....@@ -6257,10 +7099,9 @@
62577099 struct pci_dev *pdev = instance->pdev;
62587100 struct fusion_context *fusion = instance->ctrl_context;
62597101
6260
- instance->evt_detail =
6261
- pci_alloc_consistent(pdev,
6262
- sizeof(struct megasas_evt_detail),
6263
- &instance->evt_detail_h);
7102
+ instance->evt_detail = dma_alloc_coherent(&pdev->dev,
7103
+ sizeof(struct megasas_evt_detail),
7104
+ &instance->evt_detail_h, GFP_KERNEL);
62647105
62657106 if (!instance->evt_detail) {
62667107 dev_err(&instance->pdev->dev,
....@@ -6280,12 +7121,32 @@
62807121 "Failed to allocate PD list buffer\n");
62817122 return -ENOMEM;
62827123 }
7124
+
7125
+ instance->snapdump_prop = dma_alloc_coherent(&pdev->dev,
7126
+ sizeof(struct MR_SNAPDUMP_PROPERTIES),
7127
+ &instance->snapdump_prop_h, GFP_KERNEL);
7128
+
7129
+ if (!instance->snapdump_prop)
7130
+ dev_err(&pdev->dev,
7131
+ "Failed to allocate snapdump properties buffer\n");
7132
+
7133
+ instance->host_device_list_buf = dma_alloc_coherent(&pdev->dev,
7134
+ HOST_DEVICE_LIST_SZ,
7135
+ &instance->host_device_list_buf_h,
7136
+ GFP_KERNEL);
7137
+
7138
+ if (!instance->host_device_list_buf) {
7139
+ dev_err(&pdev->dev,
7140
+ "Failed to allocate targetid list buffer\n");
7141
+ return -ENOMEM;
7142
+ }
7143
+
62837144 }
62847145
62857146 instance->pd_list_buf =
6286
- pci_alloc_consistent(pdev,
7147
+ dma_alloc_coherent(&pdev->dev,
62877148 MEGASAS_MAX_PD * sizeof(struct MR_PD_LIST),
6288
- &instance->pd_list_buf_h);
7149
+ &instance->pd_list_buf_h, GFP_KERNEL);
62897150
62907151 if (!instance->pd_list_buf) {
62917152 dev_err(&pdev->dev, "Failed to allocate PD list buffer\n");
....@@ -6293,9 +7154,9 @@
62937154 }
62947155
62957156 instance->ctrl_info_buf =
6296
- pci_alloc_consistent(pdev,
7157
+ dma_alloc_coherent(&pdev->dev,
62977158 sizeof(struct megasas_ctrl_info),
6298
- &instance->ctrl_info_buf_h);
7159
+ &instance->ctrl_info_buf_h, GFP_KERNEL);
62997160
63007161 if (!instance->ctrl_info_buf) {
63017162 dev_err(&pdev->dev,
....@@ -6304,9 +7165,9 @@
63047165 }
63057166
63067167 instance->ld_list_buf =
6307
- pci_alloc_consistent(pdev,
7168
+ dma_alloc_coherent(&pdev->dev,
63087169 sizeof(struct MR_LD_LIST),
6309
- &instance->ld_list_buf_h);
7170
+ &instance->ld_list_buf_h, GFP_KERNEL);
63107171
63117172 if (!instance->ld_list_buf) {
63127173 dev_err(&pdev->dev, "Failed to allocate LD list buffer\n");
....@@ -6314,9 +7175,9 @@
63147175 }
63157176
63167177 instance->ld_targetid_list_buf =
6317
- pci_alloc_consistent(pdev,
6318
- sizeof(struct MR_LD_TARGETID_LIST),
6319
- &instance->ld_targetid_list_buf_h);
7178
+ dma_alloc_coherent(&pdev->dev,
7179
+ sizeof(struct MR_LD_TARGETID_LIST),
7180
+ &instance->ld_targetid_list_buf_h, GFP_KERNEL);
63207181
63217182 if (!instance->ld_targetid_list_buf) {
63227183 dev_err(&pdev->dev,
....@@ -6326,21 +7187,20 @@
63267187
63277188 if (!reset_devices) {
63287189 instance->system_info_buf =
6329
- pci_alloc_consistent(pdev,
6330
- sizeof(struct MR_DRV_SYSTEM_INFO),
6331
- &instance->system_info_h);
7190
+ dma_alloc_coherent(&pdev->dev,
7191
+ sizeof(struct MR_DRV_SYSTEM_INFO),
7192
+ &instance->system_info_h, GFP_KERNEL);
63327193 instance->pd_info =
6333
- pci_alloc_consistent(pdev,
6334
- sizeof(struct MR_PD_INFO),
6335
- &instance->pd_info_h);
7194
+ dma_alloc_coherent(&pdev->dev,
7195
+ sizeof(struct MR_PD_INFO),
7196
+ &instance->pd_info_h, GFP_KERNEL);
63367197 instance->tgt_prop =
6337
- pci_alloc_consistent(pdev,
6338
- sizeof(struct MR_TARGET_PROPERTIES),
6339
- &instance->tgt_prop_h);
7198
+ dma_alloc_coherent(&pdev->dev,
7199
+ sizeof(struct MR_TARGET_PROPERTIES),
7200
+ &instance->tgt_prop_h, GFP_KERNEL);
63407201 instance->crash_dump_buf =
6341
- pci_alloc_consistent(pdev,
6342
- CRASH_DMA_BUF_SIZE,
6343
- &instance->crash_dump_h);
7202
+ dma_alloc_coherent(&pdev->dev, CRASH_DMA_BUF_SIZE,
7203
+ &instance->crash_dump_h, GFP_KERNEL);
63447204
63457205 if (!instance->system_info_buf)
63467206 dev_err(&instance->pdev->dev,
....@@ -6376,7 +7236,7 @@
63767236 struct fusion_context *fusion = instance->ctrl_context;
63777237
63787238 if (instance->evt_detail)
6379
- pci_free_consistent(pdev, sizeof(struct megasas_evt_detail),
7239
+ dma_free_coherent(&pdev->dev, sizeof(struct megasas_evt_detail),
63807240 instance->evt_detail,
63817241 instance->evt_detail_h);
63827242
....@@ -6387,43 +7247,56 @@
63877247 fusion->ioc_init_request_phys);
63887248
63897249 if (instance->pd_list_buf)
6390
- pci_free_consistent(pdev,
7250
+ dma_free_coherent(&pdev->dev,
63917251 MEGASAS_MAX_PD * sizeof(struct MR_PD_LIST),
63927252 instance->pd_list_buf,
63937253 instance->pd_list_buf_h);
63947254
63957255 if (instance->ld_list_buf)
6396
- pci_free_consistent(pdev, sizeof(struct MR_LD_LIST),
7256
+ dma_free_coherent(&pdev->dev, sizeof(struct MR_LD_LIST),
63977257 instance->ld_list_buf,
63987258 instance->ld_list_buf_h);
63997259
64007260 if (instance->ld_targetid_list_buf)
6401
- pci_free_consistent(pdev, sizeof(struct MR_LD_TARGETID_LIST),
7261
+ dma_free_coherent(&pdev->dev, sizeof(struct MR_LD_TARGETID_LIST),
64027262 instance->ld_targetid_list_buf,
64037263 instance->ld_targetid_list_buf_h);
64047264
64057265 if (instance->ctrl_info_buf)
6406
- pci_free_consistent(pdev, sizeof(struct megasas_ctrl_info),
7266
+ dma_free_coherent(&pdev->dev, sizeof(struct megasas_ctrl_info),
64077267 instance->ctrl_info_buf,
64087268 instance->ctrl_info_buf_h);
64097269
64107270 if (instance->system_info_buf)
6411
- pci_free_consistent(pdev, sizeof(struct MR_DRV_SYSTEM_INFO),
7271
+ dma_free_coherent(&pdev->dev, sizeof(struct MR_DRV_SYSTEM_INFO),
64127272 instance->system_info_buf,
64137273 instance->system_info_h);
64147274
64157275 if (instance->pd_info)
6416
- pci_free_consistent(pdev, sizeof(struct MR_PD_INFO),
7276
+ dma_free_coherent(&pdev->dev, sizeof(struct MR_PD_INFO),
64177277 instance->pd_info, instance->pd_info_h);
64187278
64197279 if (instance->tgt_prop)
6420
- pci_free_consistent(pdev, sizeof(struct MR_TARGET_PROPERTIES),
7280
+ dma_free_coherent(&pdev->dev, sizeof(struct MR_TARGET_PROPERTIES),
64217281 instance->tgt_prop, instance->tgt_prop_h);
64227282
64237283 if (instance->crash_dump_buf)
6424
- pci_free_consistent(pdev, CRASH_DMA_BUF_SIZE,
7284
+ dma_free_coherent(&pdev->dev, CRASH_DMA_BUF_SIZE,
64257285 instance->crash_dump_buf,
64267286 instance->crash_dump_h);
7287
+
7288
+ if (instance->snapdump_prop)
7289
+ dma_free_coherent(&pdev->dev,
7290
+ sizeof(struct MR_SNAPDUMP_PROPERTIES),
7291
+ instance->snapdump_prop,
7292
+ instance->snapdump_prop_h);
7293
+
7294
+ if (instance->host_device_list_buf)
7295
+ dma_free_coherent(&pdev->dev,
7296
+ HOST_DEVICE_LIST_SZ,
7297
+ instance->host_device_list_buf,
7298
+ instance->host_device_list_buf_h);
7299
+
64277300 }
64287301
64297302 /*
....@@ -6447,6 +7320,7 @@
64477320 INIT_LIST_HEAD(&instance->internal_reset_pending_q);
64487321
64497322 atomic_set(&instance->fw_outstanding, 0);
7323
+ atomic64_set(&instance->total_io_count, 0);
64507324
64517325 init_waitqueue_head(&instance->int_cmd_wait_q);
64527326 init_waitqueue_head(&instance->abort_cmd_wait_q);
....@@ -6469,13 +7343,13 @@
64697343 instance->last_time = 0;
64707344 instance->disableOnlineCtrlReset = 1;
64717345 instance->UnevenSpanSupport = 0;
7346
+ instance->smp_affinity_enable = smp_affinity_enable ? true : false;
7347
+ instance->msix_load_balance = false;
64727348
6473
- if (instance->adapter_type != MFI_SERIES) {
7349
+ if (instance->adapter_type != MFI_SERIES)
64747350 INIT_WORK(&instance->work_init, megasas_fusion_ocr_wq);
6475
- INIT_WORK(&instance->crash_init, megasas_fusion_crash_dump_wq);
6476
- } else {
7351
+ else
64777352 INIT_WORK(&instance->work_init, process_fw_state_change_wq);
6478
- }
64797353 }
64807354
64817355 /**
....@@ -6490,6 +7364,19 @@
64907364 struct Scsi_Host *host;
64917365 struct megasas_instance *instance;
64927366 u16 control = 0;
7367
+
7368
+ switch (pdev->device) {
7369
+ case PCI_DEVICE_ID_LSI_AERO_10E0:
7370
+ case PCI_DEVICE_ID_LSI_AERO_10E3:
7371
+ case PCI_DEVICE_ID_LSI_AERO_10E4:
7372
+ case PCI_DEVICE_ID_LSI_AERO_10E7:
7373
+ dev_err(&pdev->dev, "Adapter is in non secure mode\n");
7374
+ return 1;
7375
+ case PCI_DEVICE_ID_LSI_AERO_10E1:
7376
+ case PCI_DEVICE_ID_LSI_AERO_10E5:
7377
+ dev_info(&pdev->dev, "Adapter is in configurable secure mode\n");
7378
+ break;
7379
+ }
64937380
64947381 /* Reset MSI-X in the kdump kernel */
64957382 if (reset_devices) {
....@@ -6549,17 +7436,20 @@
65497436 if (instance->requestorId) {
65507437 if (instance->PlasmaFW111) {
65517438 instance->vf_affiliation_111 =
6552
- pci_alloc_consistent(pdev, sizeof(struct MR_LD_VF_AFFILIATION_111),
6553
- &instance->vf_affiliation_111_h);
7439
+ dma_alloc_coherent(&pdev->dev,
7440
+ sizeof(struct MR_LD_VF_AFFILIATION_111),
7441
+ &instance->vf_affiliation_111_h,
7442
+ GFP_KERNEL);
65547443 if (!instance->vf_affiliation_111)
65557444 dev_warn(&pdev->dev, "Can't allocate "
65567445 "memory for VF affiliation buffer\n");
65577446 } else {
65587447 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);
7448
+ dma_alloc_coherent(&pdev->dev,
7449
+ (MAX_LOGICAL_DRIVES + 1) *
7450
+ sizeof(struct MR_LD_VF_AFFILIATION),
7451
+ &instance->vf_affiliation_h,
7452
+ GFP_KERNEL);
65637453 if (!instance->vf_affiliation)
65647454 dev_warn(&pdev->dev, "Can't allocate "
65657455 "memory for VF affiliation buffer\n");
....@@ -6589,7 +7479,9 @@
65897479 /*
65907480 * Trigger SCSI to scan our drives
65917481 */
6592
- scsi_scan_host(host);
7482
+ if (!instance->enable_fw_dev_list ||
7483
+ (instance->host_device_list_buf->count > 0))
7484
+ scsi_scan_host(host);
65937485
65947486 /*
65957487 * Initiate AEN (Asynchronous Event Notification)
....@@ -6599,6 +7491,8 @@
65997491 goto fail_start_aen;
66007492 }
66017493
7494
+ megasas_setup_debugfs(instance);
7495
+
66027496 /* Get current SR-IOV LD/VF affiliation */
66037497 if (instance->requestorId)
66047498 megasas_get_ld_vf_affiliation(instance, 1);
....@@ -6606,10 +7500,15 @@
66067500 return 0;
66077501
66087502 fail_start_aen:
7503
+ instance->unload = 1;
7504
+ scsi_remove_host(instance->host);
66097505 fail_io_attach:
66107506 megasas_mgmt_info.count--;
66117507 megasas_mgmt_info.max_index--;
66127508 megasas_mgmt_info.instance[megasas_mgmt_info.max_index] = NULL;
7509
+
7510
+ if (instance->requestorId && !instance->skip_heartbeat_timer_del)
7511
+ del_timer_sync(&instance->sriov_heartbeat_timer);
66137512
66147513 instance->instancet->disable_intr(instance);
66157514 megasas_destroy_irqs(instance);
....@@ -6618,8 +7517,16 @@
66187517 megasas_release_fusion(instance);
66197518 else
66207519 megasas_release_mfi(instance);
7520
+
66217521 if (instance->msix_vectors)
66227522 pci_free_irq_vectors(instance->pdev);
7523
+ instance->msix_vectors = 0;
7524
+
7525
+ if (instance->fw_crash_state != UNAVAILABLE)
7526
+ megasas_free_host_crash_buffer(instance);
7527
+
7528
+ if (instance->adapter_type != MFI_SERIES)
7529
+ megasas_fusion_stop_watchdog(instance);
66237530 fail_init_mfi:
66247531 scsi_host_put(host);
66257532 fail_alloc_instance:
....@@ -6730,16 +7637,24 @@
67307637 static int
67317638 megasas_suspend(struct pci_dev *pdev, pm_message_t state)
67327639 {
6733
- struct Scsi_Host *host;
67347640 struct megasas_instance *instance;
67357641
67367642 instance = pci_get_drvdata(pdev);
6737
- host = instance->host;
7643
+
7644
+ if (!instance)
7645
+ return 0;
7646
+
67387647 instance->unload = 1;
7648
+
7649
+ dev_info(&pdev->dev, "%s is called\n", __func__);
67397650
67407651 /* Shutdown SR-IOV heartbeat timer */
67417652 if (instance->requestorId && !instance->skip_heartbeat_timer_del)
67427653 del_timer_sync(&instance->sriov_heartbeat_timer);
7654
+
7655
+ /* Stop the FW fault detection watchdog */
7656
+ if (instance->adapter_type != MFI_SERIES)
7657
+ megasas_fusion_stop_watchdog(instance);
67437658
67447659 megasas_flush_cache(instance);
67457660 megasas_shutdown_controller(instance, MR_DCMD_HIBERNATE_SHUTDOWN);
....@@ -6779,14 +7694,19 @@
67797694 int rval;
67807695 struct Scsi_Host *host;
67817696 struct megasas_instance *instance;
6782
- int irq_flags = PCI_IRQ_LEGACY;
7697
+ u32 status_reg;
67837698
67847699 instance = pci_get_drvdata(pdev);
7700
+
7701
+ if (!instance)
7702
+ return 0;
7703
+
67857704 host = instance->host;
67867705 pci_set_power_state(pdev, PCI_D0);
67877706 pci_enable_wake(pdev, PCI_D0, 0);
67887707 pci_restore_state(pdev);
67897708
7709
+ dev_info(&pdev->dev, "%s is called\n", __func__);
67907710 /*
67917711 * PCI prepping: enable device set bus mastering and dma mask
67927712 */
....@@ -6802,9 +7722,35 @@
68027722 /*
68037723 * We expect the FW state to be READY
68047724 */
6805
- if (megasas_transition_to_ready(instance, 0))
6806
- goto fail_ready_state;
68077725
7726
+ if (megasas_transition_to_ready(instance, 0)) {
7727
+ dev_info(&instance->pdev->dev,
7728
+ "Failed to transition controller to ready from %s!\n",
7729
+ __func__);
7730
+ if (instance->adapter_type != MFI_SERIES) {
7731
+ status_reg =
7732
+ instance->instancet->read_fw_status_reg(instance);
7733
+ if (!(status_reg & MFI_RESET_ADAPTER) ||
7734
+ ((megasas_adp_reset_wait_for_ready
7735
+ (instance, true, 0)) == FAILED))
7736
+ goto fail_ready_state;
7737
+ } else {
7738
+ atomic_set(&instance->fw_reset_no_pci_access, 1);
7739
+ instance->instancet->adp_reset
7740
+ (instance, instance->reg_set);
7741
+ atomic_set(&instance->fw_reset_no_pci_access, 0);
7742
+
7743
+ /* waiting for about 30 seconds before retry */
7744
+ ssleep(30);
7745
+
7746
+ if (megasas_transition_to_ready(instance, 0))
7747
+ goto fail_ready_state;
7748
+ }
7749
+
7750
+ dev_info(&instance->pdev->dev,
7751
+ "FW restarted successfully from %s!\n",
7752
+ __func__);
7753
+ }
68087754 if (megasas_set_dma_mask(instance))
68097755 goto fail_set_dma_mask;
68107756
....@@ -6816,16 +7762,15 @@
68167762 atomic_set(&instance->ldio_outstanding, 0);
68177763
68187764 /* 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;
7765
+ if (instance->msix_vectors)
7766
+ megasas_alloc_irq_vectors(instance);
7767
+
7768
+ if (!instance->msix_vectors) {
7769
+ rval = pci_alloc_irq_vectors(instance->pdev, 1, 1,
7770
+ PCI_IRQ_LEGACY);
7771
+ if (rval < 0)
7772
+ goto fail_reenable_msix;
68237773 }
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;
68297774
68307775 megasas_setup_reply_map(instance);
68317776
....@@ -6856,6 +7801,9 @@
68567801 megasas_setup_irqs_ioapic(instance))
68577802 goto fail_init_mfi;
68587803
7804
+ if (instance->adapter_type != MFI_SERIES)
7805
+ megasas_setup_irq_poll(instance);
7806
+
68597807 /* Re-launch SR-IOV heartbeat timer */
68607808 if (instance->requestorId) {
68617809 if (!megasas_sriov_start_heartbeat(instance, 0))
....@@ -6876,8 +7824,16 @@
68767824 if (megasas_start_aen(instance))
68777825 dev_err(&instance->pdev->dev, "Start AEN failed\n");
68787826
7827
+ /* Re-launch FW fault watchdog */
7828
+ if (instance->adapter_type != MFI_SERIES)
7829
+ if (megasas_fusion_start_watchdog(instance) != SUCCESS)
7830
+ goto fail_start_watchdog;
7831
+
68797832 return 0;
68807833
7834
+fail_start_watchdog:
7835
+ if (instance->requestorId && !instance->skip_heartbeat_timer_del)
7836
+ del_timer_sync(&instance->sriov_heartbeat_timer);
68817837 fail_init_mfi:
68827838 megasas_free_ctrl_dma_buffers(instance);
68837839 megasas_free_ctrl_mem(instance);
....@@ -6938,12 +7894,20 @@
69387894 u32 pd_seq_map_sz;
69397895
69407896 instance = pci_get_drvdata(pdev);
7897
+
7898
+ if (!instance)
7899
+ return;
7900
+
69417901 host = instance->host;
69427902 fusion = instance->ctrl_context;
69437903
69447904 /* Shutdown SR-IOV heartbeat timer */
69457905 if (instance->requestorId && !instance->skip_heartbeat_timer_del)
69467906 del_timer_sync(&instance->sriov_heartbeat_timer);
7907
+
7908
+ /* Stop the FW fault detection watchdog */
7909
+ if (instance->adapter_type != MFI_SERIES)
7910
+ megasas_fusion_stop_watchdog(instance);
69477911
69487912 if (instance->fw_crash_state != UNAVAILABLE)
69497913 megasas_free_host_crash_buffer(instance);
....@@ -6989,7 +7953,7 @@
69897953 if (instance->msix_vectors)
69907954 pci_free_irq_vectors(instance->pdev);
69917955
6992
- if (instance->adapter_type == VENTURA_SERIES) {
7956
+ if (instance->adapter_type >= VENTURA_SERIES) {
69937957 for (i = 0; i < MAX_LOGICAL_DRIVES_EXT; ++i)
69947958 kfree(fusion->stream_detect_by_ld[i]);
69957959 kfree(fusion->stream_detect_by_ld);
....@@ -7027,25 +7991,27 @@
70277991 }
70287992
70297993 if (instance->vf_affiliation)
7030
- pci_free_consistent(pdev, (MAX_LOGICAL_DRIVES + 1) *
7994
+ dma_free_coherent(&pdev->dev, (MAX_LOGICAL_DRIVES + 1) *
70317995 sizeof(struct MR_LD_VF_AFFILIATION),
70327996 instance->vf_affiliation,
70337997 instance->vf_affiliation_h);
70347998
70357999 if (instance->vf_affiliation_111)
7036
- pci_free_consistent(pdev,
8000
+ dma_free_coherent(&pdev->dev,
70378001 sizeof(struct MR_LD_VF_AFFILIATION_111),
70388002 instance->vf_affiliation_111,
70398003 instance->vf_affiliation_111_h);
70408004
70418005 if (instance->hb_host_mem)
7042
- pci_free_consistent(pdev, sizeof(struct MR_CTRL_HB_HOST_MEM),
8006
+ dma_free_coherent(&pdev->dev, sizeof(struct MR_CTRL_HB_HOST_MEM),
70438007 instance->hb_host_mem,
70448008 instance->hb_host_mem_h);
70458009
70468010 megasas_free_ctrl_dma_buffers(instance);
70478011
70488012 megasas_free_ctrl_mem(instance);
8013
+
8014
+ megasas_destroy_debugfs(instance);
70498015
70508016 scsi_host_put(host);
70518017
....@@ -7054,11 +8020,14 @@
70548020
70558021 /**
70568022 * megasas_shutdown - Shutdown entry point
7057
- * @device: Generic device structure
8023
+ * @pdev: Generic device structure
70588024 */
70598025 static void megasas_shutdown(struct pci_dev *pdev)
70608026 {
70618027 struct megasas_instance *instance = pci_get_drvdata(pdev);
8028
+
8029
+ if (!instance)
8030
+ return;
70628031
70638032 instance->unload = 1;
70648033
....@@ -7076,8 +8045,10 @@
70768045 pci_free_irq_vectors(instance->pdev);
70778046 }
70788047
7079
-/**
8048
+/*
70808049 * megasas_mgmt_open - char node "open" entry point
8050
+ * @inode: char node inode
8051
+ * @filep: char node file
70818052 */
70828053 static int megasas_mgmt_open(struct inode *inode, struct file *filep)
70838054 {
....@@ -7090,8 +8061,11 @@
70908061 return 0;
70918062 }
70928063
7093
-/**
8064
+/*
70948065 * megasas_mgmt_fasync - Async notifier registration from applications
8066
+ * @fd: char node file descriptor number
8067
+ * @filep: char node file
8068
+ * @mode: notifier on/off
70958069 *
70968070 * This function adds the calling process to a driver global queue. When an
70978071 * event occurs, SIGIO will be sent to all processes in this queue.
....@@ -7117,9 +8091,11 @@
71178091 return rc;
71188092 }
71198093
7120
-/**
8094
+/*
71218095 * megasas_mgmt_poll - char node "poll" entry point
7122
- * */
8096
+ * @filep: char node file
8097
+ * @wait: Events to poll for
8098
+ */
71238099 static __poll_t megasas_mgmt_poll(struct file *file, poll_table *wait)
71248100 {
71258101 __poll_t mask;
....@@ -7177,7 +8153,8 @@
71778153 /**
71788154 * megasas_mgmt_fw_ioctl - Issues management ioctls to FW
71798155 * @instance: Adapter soft state
7180
- * @argp: User's ioctl packet
8156
+ * @user_ioc: User's ioctl packet
8157
+ * @ioc: ioctl packet
71818158 */
71828159 static int
71838160 megasas_mgmt_fw_ioctl(struct megasas_instance *instance,
....@@ -7194,6 +8171,7 @@
71948171 dma_addr_t sense_handle;
71958172 void *sense_ptr;
71968173 u32 opcode = 0;
8174
+ int ret = DCMD_SUCCESS;
71978175
71988176 memset(kbuff_arr, 0, sizeof(kbuff_arr));
71998177
....@@ -7205,7 +8183,9 @@
72058183
72068184 if ((ioc->frame.hdr.cmd >= MFI_CMD_OP_COUNT) ||
72078185 ((ioc->frame.hdr.cmd == MFI_CMD_NVME) &&
7208
- !instance->support_nvme_passthru)) {
8186
+ !instance->support_nvme_passthru) ||
8187
+ ((ioc->frame.hdr.cmd == MFI_CMD_TOOLBOX) &&
8188
+ !instance->support_pci_lane_margining)) {
72098189 dev_err(&instance->pdev->dev,
72108190 "Received invalid ioctl command 0x%x\n",
72118191 ioc->frame.hdr.cmd);
....@@ -7241,10 +8221,13 @@
72418221 opcode = le32_to_cpu(cmd->frame->dcmd.opcode);
72428222
72438223 if (opcode == MR_DCMD_CTRL_SHUTDOWN) {
8224
+ mutex_lock(&instance->reset_mutex);
72448225 if (megasas_get_ctrl_info(instance) != DCMD_SUCCESS) {
72458226 megasas_return_cmd(instance, cmd);
8227
+ mutex_unlock(&instance->reset_mutex);
72468228 return -1;
72478229 }
8230
+ mutex_unlock(&instance->reset_mutex);
72488231 }
72498232
72508233 if (opcode == MR_DRIVER_SET_APP_CRASHDUMP_MODE) {
....@@ -7287,7 +8270,7 @@
72878270
72888271 /*
72898272 * We don't change the dma_coherent_mask, so
7290
- * pci_alloc_consistent only returns 32bit addresses
8273
+ * dma_alloc_coherent only returns 32bit addresses
72918274 */
72928275 if (instance->consistent_mask_64bit) {
72938276 kern_sge64[i].phys_addr = cpu_to_le64(buf_handle);
....@@ -7333,13 +8316,18 @@
73338316 * cmd to the SCSI mid-layer
73348317 */
73358318 cmd->sync_cmd = 1;
7336
- if (megasas_issue_blocked_cmd(instance, cmd, 0) == DCMD_NOT_FIRED) {
8319
+
8320
+ ret = megasas_issue_blocked_cmd(instance, cmd, 0);
8321
+ switch (ret) {
8322
+ case DCMD_INIT:
8323
+ case DCMD_BUSY:
73378324 cmd->sync_cmd = 0;
73388325 dev_err(&instance->pdev->dev,
73398326 "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;
8327
+ __func__, __LINE__, cmd->frame->hdr.cmd, opcode,
8328
+ cmd->cmd_status_drv);
8329
+ error = -EBUSY;
8330
+ goto out;
73438331 }
73448332
73458333 cmd->sync_cmd = 0;
....@@ -7510,6 +8498,9 @@
75108498
75118499 /**
75128500 * megasas_mgmt_ioctl - char node ioctl entry point
8501
+ * @file: char device file pointer
8502
+ * @cmd: ioctl command
8503
+ * @arg: ioctl command arguments address
75138504 */
75148505 static long
75158506 megasas_mgmt_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
....@@ -7690,6 +8681,14 @@
76908681
76918682 static DRIVER_ATTR_RO(support_nvme_encapsulation);
76928683
8684
+static ssize_t
8685
+support_pci_lane_margining_show(struct device_driver *dd, char *buf)
8686
+{
8687
+ return sprintf(buf, "%u\n", support_pci_lane_margining);
8688
+}
8689
+
8690
+static DRIVER_ATTR_RO(support_pci_lane_margining);
8691
+
76938692 static inline void megasas_remove_scsi_device(struct scsi_device *sdev)
76948693 {
76958694 sdev_printk(KERN_INFO, sdev, "SCSI device is removed\n");
....@@ -7697,102 +8696,103 @@
76978696 scsi_device_put(sdev);
76988697 }
76998698
7700
-static void
7701
-megasas_aen_polling(struct work_struct *work)
8699
+/**
8700
+ * megasas_update_device_list - Update the PD and LD device list from FW
8701
+ * after an AEN event notification
8702
+ * @instance: Adapter soft state
8703
+ * @event_type: Indicates type of event (PD or LD event)
8704
+ *
8705
+ * @return: Success or failure
8706
+ *
8707
+ * Issue DCMDs to Firmware to update the internal device list in driver.
8708
+ * Based on the FW support, driver sends the HOST_DEVICE_LIST or combination
8709
+ * of PD_LIST/LD_LIST_QUERY DCMDs to get the device list.
8710
+ */
8711
+static
8712
+int megasas_update_device_list(struct megasas_instance *instance,
8713
+ int event_type)
77028714 {
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;
8715
+ int dcmd_ret = DCMD_SUCCESS;
77158716
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
- }
8717
+ if (instance->enable_fw_dev_list) {
8718
+ dcmd_ret = megasas_host_device_list_query(instance, false);
8719
+ if (dcmd_ret != DCMD_SUCCESS)
8720
+ goto out;
77838721 } else {
7784
- dev_err(&instance->pdev->dev, "invalid evt_detail!\n");
7785
- mutex_unlock(&instance->reset_mutex);
7786
- kfree(ev);
7787
- return;
8722
+ if (event_type & SCAN_PD_CHANNEL) {
8723
+ dcmd_ret = megasas_get_pd_list(instance);
8724
+
8725
+ if (dcmd_ret != DCMD_SUCCESS)
8726
+ goto out;
8727
+ }
8728
+
8729
+ if (event_type & SCAN_VD_CHANNEL) {
8730
+ if (!instance->requestorId ||
8731
+ (instance->requestorId &&
8732
+ megasas_get_ld_vf_affiliation(instance, 0))) {
8733
+ dcmd_ret = megasas_ld_list_query(instance,
8734
+ MR_LD_QUERY_TYPE_EXPOSED_TO_HOST);
8735
+ if (dcmd_ret != DCMD_SUCCESS)
8736
+ goto out;
8737
+ }
8738
+ }
77888739 }
77898740
7790
- mutex_unlock(&instance->reset_mutex);
8741
+out:
8742
+ return dcmd_ret;
8743
+}
77918744
7792
- if (doscan & SCAN_PD_CHANNEL) {
8745
+/**
8746
+ * megasas_add_remove_devices - Add/remove devices to SCSI mid-layer
8747
+ * after an AEN event notification
8748
+ * @instance: Adapter soft state
8749
+ * @scan_type: Indicates type of devices (PD/LD) to add
8750
+ * @return void
8751
+ */
8752
+static
8753
+void megasas_add_remove_devices(struct megasas_instance *instance,
8754
+ int scan_type)
8755
+{
8756
+ int i, j;
8757
+ u16 pd_index = 0;
8758
+ u16 ld_index = 0;
8759
+ u16 channel = 0, id = 0;
8760
+ struct Scsi_Host *host;
8761
+ struct scsi_device *sdev1;
8762
+ struct MR_HOST_DEVICE_LIST *targetid_list = NULL;
8763
+ struct MR_HOST_DEVICE_LIST_ENTRY *targetid_entry = NULL;
8764
+
8765
+ host = instance->host;
8766
+
8767
+ if (instance->enable_fw_dev_list) {
8768
+ targetid_list = instance->host_device_list_buf;
8769
+ for (i = 0; i < targetid_list->count; i++) {
8770
+ targetid_entry = &targetid_list->host_device_list[i];
8771
+ if (targetid_entry->flags.u.bits.is_sys_pd) {
8772
+ channel = le16_to_cpu(targetid_entry->target_id) /
8773
+ MEGASAS_MAX_DEV_PER_CHANNEL;
8774
+ id = le16_to_cpu(targetid_entry->target_id) %
8775
+ MEGASAS_MAX_DEV_PER_CHANNEL;
8776
+ } else {
8777
+ channel = MEGASAS_MAX_PD_CHANNELS +
8778
+ (le16_to_cpu(targetid_entry->target_id) /
8779
+ MEGASAS_MAX_DEV_PER_CHANNEL);
8780
+ id = le16_to_cpu(targetid_entry->target_id) %
8781
+ MEGASAS_MAX_DEV_PER_CHANNEL;
8782
+ }
8783
+ sdev1 = scsi_device_lookup(host, channel, id, 0);
8784
+ if (!sdev1) {
8785
+ scsi_add_device(host, channel, id, 0);
8786
+ } else {
8787
+ scsi_device_put(sdev1);
8788
+ }
8789
+ }
8790
+ }
8791
+
8792
+ if (scan_type & SCAN_PD_CHANNEL) {
77938793 for (i = 0; i < MEGASAS_MAX_PD_CHANNELS; i++) {
77948794 for (j = 0; j < MEGASAS_MAX_DEV_PER_CHANNEL; j++) {
7795
- pd_index = i*MEGASAS_MAX_DEV_PER_CHANNEL + j;
8795
+ pd_index = i * MEGASAS_MAX_DEV_PER_CHANNEL + j;
77968796 sdev1 = scsi_device_lookup(host, i, j, 0);
77978797 if (instance->pd_list[pd_index].driveState ==
77988798 MR_PD_STATE_SYSTEM) {
....@@ -7808,11 +8808,12 @@
78088808 }
78098809 }
78108810
7811
- if (doscan & SCAN_VD_CHANNEL) {
8811
+ if (scan_type & SCAN_VD_CHANNEL) {
78128812 for (i = 0; i < MEGASAS_MAX_LD_CHANNELS; i++) {
78138813 for (j = 0; j < MEGASAS_MAX_DEV_PER_CHANNEL; j++) {
78148814 ld_index = (i * MEGASAS_MAX_DEV_PER_CHANNEL) + j;
7815
- sdev1 = scsi_device_lookup(host, MEGASAS_MAX_PD_CHANNELS + i, j, 0);
8815
+ sdev1 = scsi_device_lookup(host,
8816
+ MEGASAS_MAX_PD_CHANNELS + i, j, 0);
78168817 if (instance->ld_ids[ld_index] != 0xff) {
78178818 if (!sdev1)
78188819 scsi_add_device(host, MEGASAS_MAX_PD_CHANNELS + i, j, 0);
....@@ -7825,6 +8826,97 @@
78258826 }
78268827 }
78278828 }
8829
+
8830
+}
8831
+
8832
+static void
8833
+megasas_aen_polling(struct work_struct *work)
8834
+{
8835
+ struct megasas_aen_event *ev =
8836
+ container_of(work, struct megasas_aen_event, hotplug_work.work);
8837
+ struct megasas_instance *instance = ev->instance;
8838
+ union megasas_evt_class_locale class_locale;
8839
+ int event_type = 0;
8840
+ u32 seq_num;
8841
+ u16 ld_target_id;
8842
+ int error;
8843
+ u8 dcmd_ret = DCMD_SUCCESS;
8844
+ struct scsi_device *sdev1;
8845
+
8846
+ if (!instance) {
8847
+ printk(KERN_ERR "invalid instance!\n");
8848
+ kfree(ev);
8849
+ return;
8850
+ }
8851
+
8852
+ /* Don't run the event workqueue thread if OCR is running */
8853
+ mutex_lock(&instance->reset_mutex);
8854
+
8855
+ instance->ev = NULL;
8856
+ if (instance->evt_detail) {
8857
+ megasas_decode_evt(instance);
8858
+
8859
+ switch (le32_to_cpu(instance->evt_detail->code)) {
8860
+
8861
+ case MR_EVT_PD_INSERTED:
8862
+ case MR_EVT_PD_REMOVED:
8863
+ event_type = SCAN_PD_CHANNEL;
8864
+ break;
8865
+
8866
+ case MR_EVT_LD_OFFLINE:
8867
+ case MR_EVT_LD_DELETED:
8868
+ ld_target_id = instance->evt_detail->args.ld.target_id;
8869
+ sdev1 = scsi_device_lookup(instance->host,
8870
+ MEGASAS_MAX_PD_CHANNELS +
8871
+ (ld_target_id / MEGASAS_MAX_DEV_PER_CHANNEL),
8872
+ (ld_target_id - MEGASAS_MAX_DEV_PER_CHANNEL),
8873
+ 0);
8874
+ if (sdev1)
8875
+ megasas_remove_scsi_device(sdev1);
8876
+
8877
+ event_type = SCAN_VD_CHANNEL;
8878
+ break;
8879
+ case MR_EVT_LD_CREATED:
8880
+ event_type = SCAN_VD_CHANNEL;
8881
+ break;
8882
+
8883
+ case MR_EVT_CFG_CLEARED:
8884
+ case MR_EVT_CTRL_HOST_BUS_SCAN_REQUESTED:
8885
+ case MR_EVT_FOREIGN_CFG_IMPORTED:
8886
+ case MR_EVT_LD_STATE_CHANGE:
8887
+ event_type = SCAN_PD_CHANNEL | SCAN_VD_CHANNEL;
8888
+ dev_info(&instance->pdev->dev, "scanning for scsi%d...\n",
8889
+ instance->host->host_no);
8890
+ break;
8891
+
8892
+ case MR_EVT_CTRL_PROP_CHANGED:
8893
+ dcmd_ret = megasas_get_ctrl_info(instance);
8894
+ if (dcmd_ret == DCMD_SUCCESS &&
8895
+ instance->snapdump_wait_time) {
8896
+ megasas_get_snapdump_properties(instance);
8897
+ dev_info(&instance->pdev->dev,
8898
+ "Snap dump wait time\t: %d\n",
8899
+ instance->snapdump_wait_time);
8900
+ }
8901
+ break;
8902
+ default:
8903
+ event_type = 0;
8904
+ break;
8905
+ }
8906
+ } else {
8907
+ dev_err(&instance->pdev->dev, "invalid evt_detail!\n");
8908
+ mutex_unlock(&instance->reset_mutex);
8909
+ kfree(ev);
8910
+ return;
8911
+ }
8912
+
8913
+ if (event_type)
8914
+ dcmd_ret = megasas_update_device_list(instance, event_type);
8915
+
8916
+ mutex_unlock(&instance->reset_mutex);
8917
+
8918
+ if (event_type && dcmd_ret == DCMD_SUCCESS)
8919
+ megasas_add_remove_devices(instance, event_type);
78288920
78298921 if (dcmd_ret == DCMD_SUCCESS)
78308922 seq_num = le32_to_cpu(instance->evt_detail->seq_num) + 1;
....@@ -7879,6 +8971,7 @@
78798971 support_poll_for_event = 2;
78808972 support_device_change = 1;
78818973 support_nvme_encapsulation = true;
8974
+ support_pci_lane_margining = true;
78828975
78838976 memset(&megasas_mgmt_info, 0, sizeof(megasas_mgmt_info));
78848977
....@@ -7894,6 +8987,8 @@
78948987
78958988 megasas_mgmt_majorno = rval;
78968989
8990
+ megasas_init_debugfs();
8991
+
78978992 /*
78988993 * Register ourselves as PCI hotplug module
78998994 */
....@@ -7902,6 +8997,12 @@
79028997 if (rval) {
79038998 printk(KERN_DEBUG "megasas: PCI hotplug registration failed \n");
79048999 goto err_pcidrv;
9000
+ }
9001
+
9002
+ if ((event_log_level < MFI_EVT_CLASS_DEBUG) ||
9003
+ (event_log_level > MFI_EVT_CLASS_DEAD)) {
9004
+ 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");
9005
+ event_log_level = MFI_EVT_CLASS_CRITICAL;
79059006 }
79069007
79079008 rval = driver_create_file(&megasas_pci_driver.driver,
....@@ -7933,7 +9034,16 @@
79339034 if (rval)
79349035 goto err_dcf_support_nvme_encapsulation;
79359036
9037
+ rval = driver_create_file(&megasas_pci_driver.driver,
9038
+ &driver_attr_support_pci_lane_margining);
9039
+ if (rval)
9040
+ goto err_dcf_support_pci_lane_margining;
9041
+
79369042 return rval;
9043
+
9044
+err_dcf_support_pci_lane_margining:
9045
+ driver_remove_file(&megasas_pci_driver.driver,
9046
+ &driver_attr_support_nvme_encapsulation);
79379047
79389048 err_dcf_support_nvme_encapsulation:
79399049 driver_remove_file(&megasas_pci_driver.driver,
....@@ -7953,6 +9063,7 @@
79539063 err_dcf_attr_ver:
79549064 pci_unregister_driver(&megasas_pci_driver);
79559065 err_pcidrv:
9066
+ megasas_exit_debugfs();
79569067 unregister_chrdev(megasas_mgmt_majorno, "megaraid_sas_ioctl");
79579068 return rval;
79589069 }
....@@ -7973,8 +9084,11 @@
79739084 driver_remove_file(&megasas_pci_driver.driver, &driver_attr_version);
79749085 driver_remove_file(&megasas_pci_driver.driver,
79759086 &driver_attr_support_nvme_encapsulation);
9087
+ driver_remove_file(&megasas_pci_driver.driver,
9088
+ &driver_attr_support_pci_lane_margining);
79769089
79779090 pci_unregister_driver(&megasas_pci_driver);
9091
+ megasas_exit_debugfs();
79789092 unregister_chrdev(megasas_mgmt_majorno, "megaraid_sas_ioctl");
79799093 }
79809094