hc
2023-12-11 d2ccde1c8e90d38cee87a1b0309ad2827f3fd30d
kernel/drivers/scsi/smartpqi/smartpqi.h
....@@ -1,18 +1,11 @@
1
+/* SPDX-License-Identifier: GPL-2.0 */
12 /*
23 * driver for Microsemi PQI-based storage controllers
3
- * Copyright (c) 2016-2017 Microsemi Corporation
4
+ * Copyright (c) 2019-2020 Microchip Technology Inc. and its subsidiaries
5
+ * Copyright (c) 2016-2018 Microsemi Corporation
46 * Copyright (c) 2016 PMC-Sierra, Inc.
57 *
6
- * This program is free software; you can redistribute it and/or modify
7
- * it under the terms of the GNU General Public License as published by
8
- * the Free Software Foundation; version 2 of the License.
9
- *
10
- * This program is distributed in the hope that it will be useful,
11
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
- * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
13
- * NON INFRINGEMENT. See the GNU General Public License for more details.
14
- *
15
- * Questions/Comments/Bugfixes to esc.storagedev@microsemi.com
8
+ * Questions/Comments/Bugfixes to storagedev@microchip.com
169 *
1710 */
1811
....@@ -20,6 +13,9 @@
2013
2114 #if !defined(_SMARTPQI_H)
2215 #define _SMARTPQI_H
16
+
17
+#include <scsi/scsi_host.h>
18
+#include <linux/bsg-lib.h>
2319
2420 #pragma pack(1)
2521
....@@ -96,6 +92,12 @@
9692 */
9793 struct pqi_device_registers pqi_registers; /* 4000h */
9894 };
95
+
96
+#if ((HZ) < 1000)
97
+#define PQI_HZ 1000
98
+#else
99
+#define PQI_HZ (HZ)
100
+#endif
99101
100102 #define PQI_DEVICE_REGISTERS_OFFSET 0x4000
101103
....@@ -274,7 +276,9 @@
274276 u8 reserved4 : 2;
275277 u8 additional_cdb_bytes_usage : 3;
276278 u8 reserved5 : 3;
277
- u8 cdb[32];
279
+ u8 cdb[16];
280
+ u8 reserved6[12];
281
+ __le32 timeout;
278282 struct pqi_sg_descriptor
279283 sg_descriptors[PQI_MAX_EMBEDDED_SG_DESCRIPTORS];
280284 };
....@@ -347,14 +351,28 @@
347351
348352 #define PQI_MAX_EVENT_DESCRIPTORS 255
349353
354
+#define PQI_EVENT_OFA_MEMORY_ALLOCATION 0x0
355
+#define PQI_EVENT_OFA_QUIESCE 0x1
356
+#define PQI_EVENT_OFA_CANCELLED 0x2
357
+
350358 struct pqi_event_response {
351359 struct pqi_iu_header header;
352360 u8 event_type;
353361 u8 reserved2 : 7;
354
- u8 request_acknowlege : 1;
362
+ u8 request_acknowledge : 1;
355363 __le16 event_id;
356364 __le32 additional_event_id;
357
- u8 data[16];
365
+ union {
366
+ struct {
367
+ __le32 bytes_requested;
368
+ u8 reserved[12];
369
+ } ofa_memory_allocation;
370
+
371
+ struct {
372
+ __le16 reason; /* reason for cancellation */
373
+ u8 reserved[14];
374
+ } ofa_cancelled;
375
+ } data;
358376 };
359377
360378 struct pqi_event_acknowledge_request {
....@@ -369,7 +387,8 @@
369387 struct pqi_iu_header header;
370388 __le16 request_id;
371389 __le16 nexus_id;
372
- u8 reserved[4];
390
+ u8 reserved[2];
391
+ __le16 timeout;
373392 u8 lun_number[8];
374393 __le16 protocol_specific;
375394 __le16 outbound_queue_id_to_manage;
....@@ -387,6 +406,54 @@
387406 __le16 nexus_id;
388407 u8 additional_response_info[3];
389408 u8 response_code;
409
+};
410
+
411
+struct pqi_vendor_general_request {
412
+ struct pqi_iu_header header;
413
+ __le16 request_id;
414
+ __le16 function_code;
415
+ union {
416
+ struct {
417
+ __le16 first_section;
418
+ __le16 last_section;
419
+ u8 reserved[48];
420
+ } config_table_update;
421
+
422
+ struct {
423
+ __le64 buffer_address;
424
+ __le32 buffer_length;
425
+ u8 reserved[40];
426
+ } ofa_memory_allocation;
427
+ } data;
428
+};
429
+
430
+struct pqi_vendor_general_response {
431
+ struct pqi_iu_header header;
432
+ __le16 request_id;
433
+ __le16 function_code;
434
+ __le16 status;
435
+ u8 reserved[2];
436
+};
437
+
438
+#define PQI_VENDOR_GENERAL_CONFIG_TABLE_UPDATE 0
439
+#define PQI_VENDOR_GENERAL_HOST_MEMORY_UPDATE 1
440
+
441
+#define PQI_OFA_VERSION 1
442
+#define PQI_OFA_SIGNATURE "OFA_QRM"
443
+#define PQI_OFA_MAX_SG_DESCRIPTORS 64
444
+
445
+#define PQI_OFA_MEMORY_DESCRIPTOR_LENGTH \
446
+ (offsetof(struct pqi_ofa_memory, sg_descriptor) + \
447
+ (PQI_OFA_MAX_SG_DESCRIPTORS * sizeof(struct pqi_sg_descriptor)))
448
+
449
+struct pqi_ofa_memory {
450
+ __le64 signature; /* "OFA_QRM" */
451
+ __le16 version; /* version of this struct (1 = 1st version) */
452
+ u8 reserved[62];
453
+ __le32 bytes_allocated; /* total allocated memory in bytes */
454
+ __le16 num_memory_descriptors;
455
+ u8 reserved1[2];
456
+ struct pqi_sg_descriptor sg_descriptor[1];
390457 };
391458
392459 struct pqi_aio_error_info {
....@@ -419,6 +486,7 @@
419486 #define PQI_REQUEST_IU_GENERAL_ADMIN 0x60
420487 #define PQI_REQUEST_IU_REPORT_VENDOR_EVENT_CONFIG 0x72
421488 #define PQI_REQUEST_IU_SET_VENDOR_EVENT_CONFIG 0x73
489
+#define PQI_REQUEST_IU_VENDOR_GENERAL 0x75
422490 #define PQI_REQUEST_IU_ACKNOWLEDGE_VENDOR_EVENT 0xf6
423491
424492 #define PQI_RESPONSE_IU_GENERAL_MANAGEMENT 0x81
....@@ -430,6 +498,7 @@
430498 #define PQI_RESPONSE_IU_AIO_PATH_IO_ERROR 0xf3
431499 #define PQI_RESPONSE_IU_AIO_PATH_DISABLED 0xf4
432500 #define PQI_RESPONSE_IU_VENDOR_EVENT 0xf5
501
+#define PQI_RESPONSE_IU_VENDOR_GENERAL 0xf7
433502
434503 #define PQI_GENERAL_ADMIN_FUNCTION_REPORT_DEVICE_CAPABILITY 0x0
435504 #define PQI_GENERAL_ADMIN_FUNCTION_CREATE_IQ 0x10
....@@ -492,6 +561,7 @@
492561 #define PQI_EVENT_TYPE_HARDWARE 0x2
493562 #define PQI_EVENT_TYPE_PHYSICAL_DEVICE 0x4
494563 #define PQI_EVENT_TYPE_LOGICAL_DEVICE 0x5
564
+#define PQI_EVENT_TYPE_OFA 0xfb
495565 #define PQI_EVENT_TYPE_AIO_STATE_CHANGE 0xfd
496566 #define PQI_EVENT_TYPE_AIO_CONFIG_CHANGE 0xfe
497567
....@@ -556,6 +626,7 @@
556626 #define SOP_TASK_ATTRIBUTE_ACA 4
557627
558628 #define SOP_TMF_COMPLETE 0x0
629
+#define SOP_TMF_REJECTED 0x4
559630 #define SOP_TMF_FUNCTION_SUCCEEDED 0x8
560631
561632 /* additional CDB bytes usage field codes */
....@@ -644,11 +715,13 @@
644715 #define PQI_CONFIG_TABLE_MAX_LENGTH ((u16)~0)
645716
646717 /* configuration table section IDs */
718
+#define PQI_CONFIG_TABLE_ALL_SECTIONS (-1)
647719 #define PQI_CONFIG_TABLE_SECTION_GENERAL_INFO 0
648720 #define PQI_CONFIG_TABLE_SECTION_FIRMWARE_FEATURES 1
649721 #define PQI_CONFIG_TABLE_SECTION_FIRMWARE_ERRATA 2
650722 #define PQI_CONFIG_TABLE_SECTION_DEBUG 3
651723 #define PQI_CONFIG_TABLE_SECTION_HEARTBEAT 4
724
+#define PQI_CONFIG_TABLE_SECTION_SOFT_RESET 5
652725
653726 struct pqi_config_table {
654727 u8 signature[8]; /* "CFGTABLE" */
....@@ -680,6 +753,20 @@
680753 /* command */
681754 };
682755
756
+struct pqi_config_table_firmware_features {
757
+ struct pqi_config_table_section_header header;
758
+ __le16 num_elements;
759
+ u8 features_supported[];
760
+/* u8 features_requested_by_host[]; */
761
+/* u8 features_enabled[]; */
762
+};
763
+
764
+#define PQI_FIRMWARE_FEATURE_OFA 0
765
+#define PQI_FIRMWARE_FEATURE_SMP 1
766
+#define PQI_FIRMWARE_FEATURE_SOFT_RESET_HANDSHAKE 11
767
+#define PQI_FIRMWARE_FEATURE_RAID_IU_TIMEOUT 13
768
+#define PQI_FIRMWARE_FEATURE_TMF_IU_TIMEOUT 14
769
+
683770 struct pqi_config_table_debug {
684771 struct pqi_config_table_section_header header;
685772 __le32 scratchpad;
....@@ -688,6 +775,22 @@
688775 struct pqi_config_table_heartbeat {
689776 struct pqi_config_table_section_header header;
690777 __le32 heartbeat_counter;
778
+};
779
+
780
+struct pqi_config_table_soft_reset {
781
+ struct pqi_config_table_section_header header;
782
+ u8 soft_reset_status;
783
+};
784
+
785
+#define PQI_SOFT_RESET_INITIATE 0x1
786
+#define PQI_SOFT_RESET_ABORT 0x2
787
+
788
+enum pqi_soft_reset_status {
789
+ RESET_INITIATE_FIRMWARE,
790
+ RESET_INITIATE_DRIVER,
791
+ RESET_ABORT,
792
+ RESET_NORESPONSE,
793
+ RESET_TIMEDOUT
691794 };
692795
693796 union pqi_reset_register {
....@@ -724,12 +827,20 @@
724827 #define PQI_HBA_BUS 2
725828 #define PQI_EXTERNAL_RAID_VOLUME_BUS 3
726829 #define PQI_MAX_BUS PQI_EXTERNAL_RAID_VOLUME_BUS
830
+#define PQI_VSEP_CISS_BTL 379
727831
728832 struct report_lun_header {
729833 __be32 list_length;
730
- u8 extended_response;
834
+ u8 flags;
731835 u8 reserved[3];
732836 };
837
+
838
+/* for flags field of struct report_lun_header */
839
+#define CISS_REPORT_LOG_FLAG_UNIQUE_LUN_ID (1 << 0)
840
+#define CISS_REPORT_LOG_FLAG_QUEUE_DEPTH (1 << 5)
841
+#define CISS_REPORT_LOG_FLAG_DRIVE_TYPE_MIX (1 << 6)
842
+
843
+#define CISS_REPORT_PHYS_FLAG_OTHER (1 << 1)
733844
734845 struct report_log_lun_extended_entry {
735846 u8 lunid[8];
....@@ -752,7 +863,7 @@
752863 };
753864
754865 /* for device_flags field of struct report_phys_lun_extended_entry */
755
-#define REPORT_PHYS_LUN_DEV_FLAG_AIO_ENABLED 0x8
866
+#define CISS_REPORT_PHYS_DEV_FLAG_AIO_ENABLED 0x8
756867
757868 struct report_phys_lun_extended {
758869 struct report_lun_header header;
....@@ -765,7 +876,7 @@
765876 u8 reserved[2];
766877 };
767878
768
-/* constants for flags field of RAID map */
879
+/* for flags field of RAID map */
769880 #define RAID_MAP_ENCRYPTION_ENABLED 0x1
770881
771882 struct raid_map {
....@@ -810,13 +921,16 @@
810921 u8 volume_id[16];
811922 u8 is_physical_device : 1;
812923 u8 is_external_raid_device : 1;
924
+ u8 is_expander_smp_device : 1;
813925 u8 target_lun_valid : 1;
814926 u8 device_gone : 1;
815927 u8 new_device : 1;
816928 u8 keep_device : 1;
817929 u8 volume_offline : 1;
930
+ u8 rescan : 1;
818931 bool aio_enabled; /* only valid for physical disks */
819932 bool in_reset;
933
+ bool in_remove;
820934 bool device_offline;
821935 u8 vendor[8]; /* bytes 8-15 of inquiry data */
822936 u8 model[16]; /* bytes 16-31 of inquiry data */
....@@ -829,6 +943,9 @@
829943 u8 active_path_index;
830944 u8 path_map;
831945 u8 bay;
946
+ u8 box_index;
947
+ u8 phys_box_on_bus;
948
+ u8 phy_connected_dev_type;
832949 u8 box[8];
833950 u16 phys_connector[8];
834951 bool raid_bypass_configured; /* RAID bypass configured */
....@@ -846,11 +963,10 @@
846963 struct list_head delete_list_entry;
847964
848965 atomic_t scsi_cmds_outstanding;
966
+ atomic_t raid_bypass_cnt;
849967 };
850968
851969 /* VPD inquiry pages */
852
-#define SCSI_VPD_SUPPORTED_PAGES 0x0 /* standard page */
853
-#define SCSI_VPD_DEVICE_ID 0x83 /* standard page */
854970 #define CISS_VPD_LV_DEVICE_GEOMETRY 0xc1 /* vendor-specific page */
855971 #define CISS_VPD_LV_BYPASS_STATUS 0xc2 /* vendor-specific page */
856972 #define CISS_VPD_LV_STATUS 0xc3 /* vendor-specific page */
....@@ -916,6 +1032,7 @@
9161032 struct pqi_sas_port {
9171033 struct list_head port_list_entry;
9181034 u64 sas_address;
1035
+ struct pqi_scsi_dev *device;
9191036 struct sas_port *port;
9201037 int next_phy_index;
9211038 struct list_head phy_list_head;
....@@ -947,13 +1064,15 @@
9471064 struct list_head request_list_entry;
9481065 };
9491066
950
-#define PQI_NUM_SUPPORTED_EVENTS 6
1067
+#define PQI_NUM_SUPPORTED_EVENTS 7
9511068
9521069 struct pqi_event {
9531070 bool pending;
9541071 u8 event_type;
9551072 __le16 event_id;
9561073 __le32 additional_event_id;
1074
+ __le32 ofa_bytes_requested;
1075
+ __le16 ofa_cancel_reason;
9571076 };
9581077
9591078 #define PQI_RESERVED_IO_SLOTS_LUN_RESET 1
....@@ -967,6 +1086,9 @@
9671086 unsigned int ctrl_id;
9681087 struct pci_dev *pci_dev;
9691088 char firmware_version[11];
1089
+ char serial_number[17];
1090
+ char model[17];
1091
+ char vendor[9];
9701092 void __iomem *iomem_base;
9711093 struct pqi_ctrl_registers __iomem *registers;
9721094 struct pqi_device_registers __iomem *pqi_registers;
....@@ -1014,12 +1136,19 @@
10141136
10151137 struct mutex scan_mutex;
10161138 struct mutex lun_reset_mutex;
1139
+ struct mutex ofa_mutex; /* serialize ofa */
10171140 bool controller_online;
10181141 bool block_requests;
1142
+ bool block_device_reset;
1143
+ bool in_ofa;
1144
+ bool in_shutdown;
10191145 u8 inbound_spanning_supported : 1;
10201146 u8 outbound_spanning_supported : 1;
10211147 u8 pqi_mode_enabled : 1;
10221148 u8 pqi_reset_quiesce_supported : 1;
1149
+ u8 soft_reset_handshake_supported : 1;
1150
+ u8 raid_iu_timeout_supported: 1;
1151
+ u8 tmf_iu_timeout_supported: 1;
10231152
10241153 struct list_head scsi_device_list;
10251154 spinlock_t scsi_device_list_lock;
....@@ -1040,6 +1169,7 @@
10401169 int previous_num_interrupts;
10411170 u32 previous_heartbeat_count;
10421171 __le32 __iomem *heartbeat_counter;
1172
+ u8 __iomem *soft_reset_status;
10431173 struct timer_list heartbeat_timer;
10441174 struct work_struct ctrl_offline_work;
10451175
....@@ -1051,6 +1181,11 @@
10511181 struct list_head raid_bypass_retry_list;
10521182 spinlock_t raid_bypass_retry_list_lock;
10531183 struct work_struct raid_bypass_retry_work;
1184
+
1185
+ struct pqi_ofa_memory *pqi_ofa_mem_virt_addr;
1186
+ dma_addr_t pqi_ofa_mem_dma_handle;
1187
+ void **pqi_ofa_chunk_virt_addr;
1188
+ atomic_t sync_cmds_outstanding;
10541189 };
10551190
10561191 enum pqi_ctrl_mode {
....@@ -1069,10 +1204,6 @@
10691204 #define CISS_REPORT_PHYS 0xc3 /* Report Physical LUNs */
10701205 #define CISS_GET_RAID_MAP 0xc8
10711206
1072
-/* constants for CISS_REPORT_LOG/CISS_REPORT_PHYS commands */
1073
-#define CISS_REPORT_LOG_EXTENDED 0x1
1074
-#define CISS_REPORT_PHYS_EXTENDED 0x2
1075
-
10761207 /* BMIC commands */
10771208 #define BMIC_IDENTIFY_CONTROLLER 0x11
10781209 #define BMIC_IDENTIFY_PHYSICAL_DEVICE 0x15
....@@ -1080,8 +1211,13 @@
10801211 #define BMIC_WRITE 0x27
10811212 #define BMIC_SENSE_CONTROLLER_PARAMETERS 0x64
10821213 #define BMIC_SENSE_SUBSYSTEM_INFORMATION 0x66
1214
+#define BMIC_CSMI_PASSTHRU 0x68
10831215 #define BMIC_WRITE_HOST_WELLNESS 0xa5
10841216 #define BMIC_FLUSH_CACHE 0xc2
1217
+#define BMIC_SET_DIAG_OPTIONS 0xf4
1218
+#define BMIC_SENSE_DIAG_OPTIONS 0xf5
1219
+
1220
+#define CSMI_CC_SAS_SMP_PASSTHRU 0x17
10851221
10861222 #define SA_FLUSH_CACHE 0x1
10871223
....@@ -1104,10 +1240,26 @@
11041240 __le16 extended_logical_unit_count;
11051241 u8 reserved1[34];
11061242 __le16 firmware_build_number;
1107
- u8 reserved2[100];
1243
+ u8 reserved2[8];
1244
+ u8 vendor_id[8];
1245
+ u8 product_id[16];
1246
+ u8 reserved3[68];
11081247 u8 controller_mode;
1109
- u8 reserved3[32];
1248
+ u8 reserved4[32];
11101249 };
1250
+
1251
+struct bmic_sense_subsystem_info {
1252
+ u8 reserved[44];
1253
+ u8 ctrl_serial_number[16];
1254
+};
1255
+
1256
+/* constants for device_type field */
1257
+#define SA_DEVICE_TYPE_SATA 0x1
1258
+#define SA_DEVICE_TYPE_SAS 0x2
1259
+#define SA_DEVICE_TYPE_EXPANDER_SMP 0x5
1260
+#define SA_DEVICE_TYPE_SES 0x6
1261
+#define SA_DEVICE_TYPE_CONTROLLER 0x7
1262
+#define SA_DEVICE_TYPE_NVME 0x9
11111263
11121264 struct bmic_identify_physical_device {
11131265 u8 scsi_bus; /* SCSI Bus number on controller */
....@@ -1133,7 +1285,7 @@
11331285 __le32 rpm; /* drive rotational speed in RPM */
11341286 u8 device_type; /* type of drive */
11351287 u8 sata_version; /* only valid when device_type = */
1136
- /* BMIC_DEVICE_TYPE_SATA */
1288
+ /* SA_DEVICE_TYPE_SATA */
11371289 __le64 big_total_block_count;
11381290 __le64 ris_starting_lba;
11391291 __le32 ris_size;
....@@ -1189,6 +1341,50 @@
11891341 u8 padding_to_multiple_of_512[9];
11901342 };
11911343
1344
+struct bmic_smp_request {
1345
+ u8 frame_type;
1346
+ u8 function;
1347
+ u8 allocated_response_length;
1348
+ u8 request_length;
1349
+ u8 additional_request_bytes[1016];
1350
+};
1351
+
1352
+struct bmic_smp_response {
1353
+ u8 frame_type;
1354
+ u8 function;
1355
+ u8 function_result;
1356
+ u8 response_length;
1357
+ u8 additional_response_bytes[1016];
1358
+};
1359
+
1360
+struct bmic_csmi_ioctl_header {
1361
+ __le32 header_length;
1362
+ u8 signature[8];
1363
+ __le32 timeout;
1364
+ __le32 control_code;
1365
+ __le32 return_code;
1366
+ __le32 length;
1367
+};
1368
+
1369
+struct bmic_csmi_smp_passthru {
1370
+ u8 phy_identifier;
1371
+ u8 port_identifier;
1372
+ u8 connection_rate;
1373
+ u8 reserved;
1374
+ __be64 destination_sas_address;
1375
+ __le32 request_length;
1376
+ struct bmic_smp_request request;
1377
+ u8 connection_status;
1378
+ u8 reserved1[3];
1379
+ __le32 response_length;
1380
+ struct bmic_smp_response response;
1381
+};
1382
+
1383
+struct bmic_csmi_smp_passthru_buffer {
1384
+ struct bmic_csmi_ioctl_header ioctl_header;
1385
+ struct bmic_csmi_smp_passthru parameters;
1386
+};
1387
+
11921388 struct bmic_flush_cache {
11931389 u8 disable_flag;
11941390 u8 system_power_action;
....@@ -1206,7 +1402,31 @@
12061402 RESTART = 4
12071403 };
12081404
1405
+struct bmic_diag_options {
1406
+ __le32 options;
1407
+};
1408
+
12091409 #pragma pack()
1410
+
1411
+static inline void pqi_ctrl_busy(struct pqi_ctrl_info *ctrl_info)
1412
+{
1413
+ atomic_inc(&ctrl_info->num_busy_threads);
1414
+}
1415
+
1416
+static inline void pqi_ctrl_unbusy(struct pqi_ctrl_info *ctrl_info)
1417
+{
1418
+ atomic_dec(&ctrl_info->num_busy_threads);
1419
+}
1420
+
1421
+static inline struct pqi_ctrl_info *shost_to_hba(struct Scsi_Host *shost)
1422
+{
1423
+ void *hostdata = shost_priv(shost);
1424
+
1425
+ return *((struct pqi_ctrl_info **)hostdata);
1426
+}
1427
+
1428
+void pqi_sas_smp_handler(struct bsg_job *job, struct Scsi_Host *shost,
1429
+ struct sas_rphy *rphy);
12101430
12111431 int pqi_add_sas_host(struct Scsi_Host *shost, struct pqi_ctrl_info *ctrl_info);
12121432 void pqi_delete_sas_host(struct pqi_ctrl_info *ctrl_info);
....@@ -1216,6 +1436,9 @@
12161436 struct pqi_scsi_dev *pqi_find_device_by_sas_rphy(
12171437 struct pqi_ctrl_info *ctrl_info, struct sas_rphy *rphy);
12181438 void pqi_prep_for_scsi_done(struct scsi_cmnd *scmd);
1439
+int pqi_csmi_smp_passthru(struct pqi_ctrl_info *ctrl_info,
1440
+ struct bmic_csmi_smp_passthru_buffer *buffer, size_t buffer_length,
1441
+ struct pqi_raid_error_info *error_info);
12191442
12201443 extern struct sas_function_template pqi_sas_transport_functions;
12211444