forked from ~ljy/RK356X_SDK_RELEASE

hc
2024-10-09 244b2c5ca8b14627e4a17755e5922221e121c771
kernel/drivers/scsi/mpt3sas/mpt3sas_ctl.c
....@@ -180,22 +180,26 @@
180180 case MPI2_FUNCTION_SMP_PASSTHROUGH:
181181 desc = "smp_passthrough";
182182 break;
183
+ case MPI2_FUNCTION_TOOLBOX:
184
+ desc = "toolbox";
185
+ break;
186
+ case MPI2_FUNCTION_NVME_ENCAPSULATED:
187
+ desc = "nvme_encapsulated";
188
+ break;
183189 }
184190
185191 if (!desc)
186192 return;
187193
188
- pr_info(MPT3SAS_FMT "%s: %s, smid(%d)\n",
189
- ioc->name, calling_function_name, desc, smid);
194
+ ioc_info(ioc, "%s: %s, smid(%d)\n", calling_function_name, desc, smid);
190195
191196 if (!mpi_reply)
192197 return;
193198
194199 if (mpi_reply->IOCStatus || mpi_reply->IOCLogInfo)
195
- pr_info(MPT3SAS_FMT
196
- "\tiocstatus(0x%04x), loginfo(0x%08x)\n",
197
- ioc->name, le16_to_cpu(mpi_reply->IOCStatus),
198
- le32_to_cpu(mpi_reply->IOCLogInfo));
200
+ ioc_info(ioc, "\tiocstatus(0x%04x), loginfo(0x%08x)\n",
201
+ le16_to_cpu(mpi_reply->IOCStatus),
202
+ le32_to_cpu(mpi_reply->IOCLogInfo));
199203
200204 if (mpi_request->Function == MPI2_FUNCTION_SCSI_IO_REQUEST ||
201205 mpi_request->Function ==
....@@ -208,38 +212,32 @@
208212 sas_device = mpt3sas_get_sdev_by_handle(ioc,
209213 le16_to_cpu(scsi_reply->DevHandle));
210214 if (sas_device) {
211
- pr_warn(MPT3SAS_FMT "\tsas_address(0x%016llx), phy(%d)\n",
212
- ioc->name, (unsigned long long)
213
- sas_device->sas_address, sas_device->phy);
214
- pr_warn(MPT3SAS_FMT
215
- "\tenclosure_logical_id(0x%016llx), slot(%d)\n",
216
- ioc->name, (unsigned long long)
217
- sas_device->enclosure_logical_id, sas_device->slot);
215
+ ioc_warn(ioc, "\tsas_address(0x%016llx), phy(%d)\n",
216
+ (u64)sas_device->sas_address,
217
+ sas_device->phy);
218
+ ioc_warn(ioc, "\tenclosure_logical_id(0x%016llx), slot(%d)\n",
219
+ (u64)sas_device->enclosure_logical_id,
220
+ sas_device->slot);
218221 sas_device_put(sas_device);
219222 }
220223 if (!sas_device) {
221224 pcie_device = mpt3sas_get_pdev_by_handle(ioc,
222225 le16_to_cpu(scsi_reply->DevHandle));
223226 if (pcie_device) {
224
- pr_warn(MPT3SAS_FMT
225
- "\tWWID(0x%016llx), port(%d)\n", ioc->name,
226
- (unsigned long long)pcie_device->wwid,
227
- pcie_device->port_num);
227
+ ioc_warn(ioc, "\tWWID(0x%016llx), port(%d)\n",
228
+ (unsigned long long)pcie_device->wwid,
229
+ pcie_device->port_num);
228230 if (pcie_device->enclosure_handle != 0)
229
- pr_warn(MPT3SAS_FMT
230
- "\tenclosure_logical_id(0x%016llx), slot(%d)\n",
231
- ioc->name, (unsigned long long)
232
- pcie_device->enclosure_logical_id,
233
- pcie_device->slot);
231
+ ioc_warn(ioc, "\tenclosure_logical_id(0x%016llx), slot(%d)\n",
232
+ (u64)pcie_device->enclosure_logical_id,
233
+ pcie_device->slot);
234234 pcie_device_put(pcie_device);
235235 }
236236 }
237237 if (scsi_reply->SCSIState || scsi_reply->SCSIStatus)
238
- pr_info(MPT3SAS_FMT
239
- "\tscsi_state(0x%02x), scsi_status"
240
- "(0x%02x)\n", ioc->name,
241
- scsi_reply->SCSIState,
242
- scsi_reply->SCSIStatus);
238
+ ioc_info(ioc, "\tscsi_state(0x%02x), scsi_status(0x%02x)\n",
239
+ scsi_reply->SCSIState,
240
+ scsi_reply->SCSIStatus);
243241 }
244242 }
245243
....@@ -466,8 +464,7 @@
466464 int i;
467465 u8 issue_reset;
468466
469
- dtmprintk(ioc, pr_info(MPT3SAS_FMT
470
- "%s: MPT3_IOC_PRE_RESET\n", ioc->name, __func__));
467
+ dtmprintk(ioc, ioc_info(ioc, "%s: MPT3_IOC_PRE_RESET\n", __func__));
471468 for (i = 0; i < MPI2_DIAG_BUF_TYPE_COUNT; i++) {
472469 if (!(ioc->diag_buffer_status[i] &
473470 MPT3_DIAG_BUFFER_IS_REGISTERED))
....@@ -475,20 +472,27 @@
475472 if ((ioc->diag_buffer_status[i] &
476473 MPT3_DIAG_BUFFER_IS_RELEASED))
477474 continue;
475
+
476
+ /*
477
+ * add a log message to indicate the release
478
+ */
479
+ ioc_info(ioc,
480
+ "%s: Releasing the trace buffer due to adapter reset.",
481
+ __func__);
478482 mpt3sas_send_diag_release(ioc, i, &issue_reset);
479483 }
480484 }
481485
482486 /**
483
- * mpt3sas_ctl_reset_handler - reset callback handler (for ctl)
487
+ * mpt3sas_ctl_reset_handler - clears outstanding ioctl cmd.
484488 * @ioc: per adapter object
485489 *
486490 * The handler for doing any required cleanup or initialization.
487491 */
488
-void mpt3sas_ctl_after_reset_handler(struct MPT3SAS_ADAPTER *ioc)
492
+void mpt3sas_ctl_clear_outstanding_ioctls(struct MPT3SAS_ADAPTER *ioc)
489493 {
490
- dtmprintk(ioc, pr_info(MPT3SAS_FMT
491
- "%s: MPT3_IOC_AFTER_RESET\n", ioc->name, __func__));
494
+ dtmprintk(ioc,
495
+ ioc_info(ioc, "%s: clear outstanding ioctl cmd\n", __func__));
492496 if (ioc->ctl_cmds.status & MPT3_CMD_PENDING) {
493497 ioc->ctl_cmds.status |= MPT3_CMD_RESET;
494498 mpt3sas_base_free_smid(ioc, ioc->ctl_cmds.smid);
....@@ -506,8 +510,7 @@
506510 {
507511 int i;
508512
509
- dtmprintk(ioc, pr_info(MPT3SAS_FMT
510
- "%s: MPT3_IOC_DONE_RESET\n", ioc->name, __func__));
513
+ dtmprintk(ioc, ioc_info(ioc, "%s: MPT3_IOC_DONE_RESET\n", __func__));
511514
512515 for (i = 0; i < MPI2_DIAG_BUF_TYPE_COUNT; i++) {
513516 if (!(ioc->diag_buffer_status[i] &
....@@ -607,15 +610,23 @@
607610 if (priv_data->sas_target->handle != handle)
608611 continue;
609612 st = scsi_cmd_priv(scmd);
610
- tm_request->TaskMID = cpu_to_le16(st->smid);
611
- found = 1;
613
+
614
+ /*
615
+ * If the given TaskMID from the user space is zero, then the
616
+ * first outstanding smid will be picked up. Otherwise,
617
+ * targeted smid will be the one.
618
+ */
619
+ if (!tm_request->TaskMID || tm_request->TaskMID == st->smid) {
620
+ tm_request->TaskMID = cpu_to_le16(st->smid);
621
+ found = 1;
622
+ }
612623 }
613624
614625 if (!found) {
615
- dctlprintk(ioc, pr_info(MPT3SAS_FMT
616
- "%s: handle(0x%04x), lun(%d), no active mid!!\n",
617
- ioc->name,
618
- desc, le16_to_cpu(tm_request->DevHandle), lun));
626
+ dctlprintk(ioc,
627
+ ioc_info(ioc, "%s: handle(0x%04x), lun(%d), no active mid!!\n",
628
+ desc, le16_to_cpu(tm_request->DevHandle),
629
+ lun));
619630 tm_reply = ioc->ctl_cmds.reply;
620631 tm_reply->DevHandle = tm_request->DevHandle;
621632 tm_reply->Function = MPI2_FUNCTION_SCSI_TASK_MGMT;
....@@ -631,10 +642,10 @@
631642 return 1;
632643 }
633644
634
- dctlprintk(ioc, pr_info(MPT3SAS_FMT
635
- "%s: handle(0x%04x), lun(%d), task_mid(%d)\n", ioc->name,
636
- desc, le16_to_cpu(tm_request->DevHandle), lun,
637
- le16_to_cpu(tm_request->TaskMID)));
645
+ dctlprintk(ioc,
646
+ ioc_info(ioc, "%s: handle(0x%04x), lun(%d), task_mid(%d)\n",
647
+ desc, le16_to_cpu(tm_request->DevHandle), lun,
648
+ le16_to_cpu(tm_request->TaskMID)));
638649 return 0;
639650 }
640651
....@@ -652,7 +663,6 @@
652663 MPI2DefaultReply_t *mpi_reply;
653664 Mpi26NVMeEncapsulatedRequest_t *nvme_encap_request = NULL;
654665 struct _pcie_device *pcie_device = NULL;
655
- u32 ioc_state;
656666 u16 smid;
657667 unsigned long timeout;
658668 u8 issue_reset;
....@@ -665,45 +675,24 @@
665675 dma_addr_t data_in_dma = 0;
666676 size_t data_in_sz = 0;
667677 long ret;
668
- u16 wait_state_count;
669678 u16 device_handle = MPT3SAS_INVALID_DEVICE_HANDLE;
670
- u8 tr_method = MPI26_SCSITASKMGMT_MSGFLAGS_PROTOCOL_LVL_RST_PCIE;
671679
672680 issue_reset = 0;
673681
674682 if (ioc->ctl_cmds.status != MPT3_CMD_NOT_USED) {
675
- pr_err(MPT3SAS_FMT "%s: ctl_cmd in use\n",
676
- ioc->name, __func__);
683
+ ioc_err(ioc, "%s: ctl_cmd in use\n", __func__);
677684 ret = -EAGAIN;
678685 goto out;
679686 }
680687
681
- wait_state_count = 0;
682
- ioc_state = mpt3sas_base_get_iocstate(ioc, 1);
683
- while (ioc_state != MPI2_IOC_STATE_OPERATIONAL) {
684
- if (wait_state_count++ == 10) {
685
- pr_err(MPT3SAS_FMT
686
- "%s: failed due to ioc not operational\n",
687
- ioc->name, __func__);
688
- ret = -EFAULT;
689
- goto out;
690
- }
691
- ssleep(1);
692
- ioc_state = mpt3sas_base_get_iocstate(ioc, 1);
693
- pr_info(MPT3SAS_FMT
694
- "%s: waiting for operational state(count=%d)\n",
695
- ioc->name,
696
- __func__, wait_state_count);
697
- }
698
- if (wait_state_count)
699
- pr_info(MPT3SAS_FMT "%s: ioc is operational\n",
700
- ioc->name, __func__);
688
+ ret = mpt3sas_wait_for_ioc(ioc, IOC_OPERATIONAL_WAIT_COUNT);
689
+ if (ret)
690
+ goto out;
701691
702692 mpi_request = kzalloc(ioc->request_sz, GFP_KERNEL);
703693 if (!mpi_request) {
704
- pr_err(MPT3SAS_FMT
705
- "%s: failed obtaining a memory for mpi_request\n",
706
- ioc->name, __func__);
694
+ ioc_err(ioc, "%s: failed obtaining a memory for mpi_request\n",
695
+ __func__);
707696 ret = -ENOMEM;
708697 goto out;
709698 }
....@@ -726,8 +715,7 @@
726715 if (mpi_request->Function == MPI2_FUNCTION_SCSI_TASK_MGMT) {
727716 smid = mpt3sas_base_get_smid_hpr(ioc, ioc->ctl_cb_idx);
728717 if (!smid) {
729
- pr_err(MPT3SAS_FMT "%s: failed obtaining a smid\n",
730
- ioc->name, __func__);
718
+ ioc_err(ioc, "%s: failed obtaining a smid\n", __func__);
731719 ret = -EAGAIN;
732720 goto out;
733721 }
....@@ -740,6 +728,7 @@
740728 ioc->ctl_cmds.status = MPT3_CMD_PENDING;
741729 memset(ioc->ctl_cmds.reply, 0, ioc->reply_sz);
742730 request = mpt3sas_base_get_msg_frame(ioc, smid);
731
+ memset(request, 0, ioc->request_sz);
743732 memcpy(request, mpi_request, karg.data_sge_offset*4);
744733 ioc->ctl_cmds.smid = smid;
745734 data_out_sz = karg.data_out_size;
....@@ -762,8 +751,8 @@
762751
763752 /* obtain dma-able memory for data transfer */
764753 if (data_out_sz) /* WRITE */ {
765
- data_out = pci_alloc_consistent(ioc->pdev, data_out_sz,
766
- &data_out_dma);
754
+ data_out = dma_alloc_coherent(&ioc->pdev->dev, data_out_sz,
755
+ &data_out_dma, GFP_KERNEL);
767756 if (!data_out) {
768757 pr_err("failure at %s:%d/%s()!\n", __FILE__,
769758 __LINE__, __func__);
....@@ -782,8 +771,8 @@
782771 }
783772
784773 if (data_in_sz) /* READ */ {
785
- data_in = pci_alloc_consistent(ioc->pdev, data_in_sz,
786
- &data_in_dma);
774
+ data_in = dma_alloc_coherent(&ioc->pdev->dev, data_in_sz,
775
+ &data_in_dma, GFP_KERNEL);
787776 if (!data_in) {
788777 pr_err("failure at %s:%d/%s()!\n", __FILE__,
789778 __LINE__, __func__);
....@@ -803,6 +792,18 @@
803792 case MPI2_FUNCTION_NVME_ENCAPSULATED:
804793 {
805794 nvme_encap_request = (Mpi26NVMeEncapsulatedRequest_t *)request;
795
+ if (!ioc->pcie_sg_lookup) {
796
+ dtmprintk(ioc, ioc_info(ioc,
797
+ "HBA doesn't support NVMe. Rejecting NVMe Encapsulated request.\n"
798
+ ));
799
+
800
+ if (ioc->logging_level & MPT_DEBUG_TM)
801
+ _debug_dump_mf(nvme_encap_request,
802
+ ioc->request_sz/4);
803
+ mpt3sas_base_free_smid(ioc, smid);
804
+ ret = -EINVAL;
805
+ goto out;
806
+ }
806807 /*
807808 * Get the Physical Address of the sense buffer.
808809 * Use Error Response buffer address field to hold the sense
....@@ -823,9 +824,9 @@
823824 ioc->build_nvme_prp(ioc, smid, nvme_encap_request,
824825 data_out_dma, data_out_sz, data_in_dma, data_in_sz);
825826 if (test_bit(device_handle, ioc->device_remove_in_progress)) {
826
- dtmprintk(ioc, pr_info(MPT3SAS_FMT "handle(0x%04x) :"
827
- "ioctl failed due to device removal in progress\n",
828
- ioc->name, device_handle));
827
+ dtmprintk(ioc,
828
+ ioc_info(ioc, "handle(0x%04x): ioctl failed due to device removal in progress\n",
829
+ device_handle));
829830 mpt3sas_base_free_smid(ioc, smid);
830831 ret = -EINVAL;
831832 goto out;
....@@ -843,9 +844,9 @@
843844 mpt3sas_base_get_sense_buffer_dma(ioc, smid);
844845 memset(ioc->ctl_cmds.sense, 0, SCSI_SENSE_BUFFERSIZE);
845846 if (test_bit(device_handle, ioc->device_remove_in_progress)) {
846
- dtmprintk(ioc, pr_info(MPT3SAS_FMT
847
- "handle(0x%04x) :ioctl failed due to device removal in progress\n",
848
- ioc->name, device_handle));
847
+ dtmprintk(ioc,
848
+ ioc_info(ioc, "handle(0x%04x) :ioctl failed due to device removal in progress\n",
849
+ device_handle));
849850 mpt3sas_base_free_smid(ioc, smid);
850851 ret = -EINVAL;
851852 goto out;
....@@ -855,7 +856,7 @@
855856 if (mpi_request->Function == MPI2_FUNCTION_SCSI_IO_REQUEST)
856857 ioc->put_smid_scsi_io(ioc, smid, device_handle);
857858 else
858
- mpt3sas_base_put_smid_default(ioc, smid);
859
+ ioc->put_smid_default(ioc, smid);
859860 break;
860861 }
861862 case MPI2_FUNCTION_SCSI_TASK_MGMT:
....@@ -863,10 +864,10 @@
863864 Mpi2SCSITaskManagementRequest_t *tm_request =
864865 (Mpi2SCSITaskManagementRequest_t *)request;
865866
866
- dtmprintk(ioc, pr_info(MPT3SAS_FMT
867
- "TASK_MGMT: handle(0x%04x), task_type(0x%02x)\n",
868
- ioc->name,
869
- le16_to_cpu(tm_request->DevHandle), tm_request->TaskType));
867
+ dtmprintk(ioc,
868
+ ioc_info(ioc, "TASK_MGMT: handle(0x%04x), task_type(0x%02x)\n",
869
+ le16_to_cpu(tm_request->DevHandle),
870
+ tm_request->TaskType));
870871 ioc->got_task_abort_from_ioctl = 1;
871872 if (tm_request->TaskType ==
872873 MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK ||
....@@ -881,9 +882,9 @@
881882 ioc->got_task_abort_from_ioctl = 0;
882883
883884 if (test_bit(device_handle, ioc->device_remove_in_progress)) {
884
- dtmprintk(ioc, pr_info(MPT3SAS_FMT
885
- "handle(0x%04x) :ioctl failed due to device removal in progress\n",
886
- ioc->name, device_handle));
885
+ dtmprintk(ioc,
886
+ ioc_info(ioc, "handle(0x%04x) :ioctl failed due to device removal in progress\n",
887
+ device_handle));
887888 mpt3sas_base_free_smid(ioc, smid);
888889 ret = -EINVAL;
889890 goto out;
....@@ -892,7 +893,7 @@
892893 tm_request->DevHandle));
893894 ioc->build_sg_mpi(ioc, psge, data_out_dma, data_out_sz,
894895 data_in_dma, data_in_sz);
895
- mpt3sas_base_put_smid_hi_priority(ioc, smid, 0);
896
+ ioc->put_smid_hi_priority(ioc, smid, 0);
896897 break;
897898 }
898899 case MPI2_FUNCTION_SMP_PASSTHROUGH:
....@@ -923,22 +924,22 @@
923924 }
924925 ioc->build_sg(ioc, psge, data_out_dma, data_out_sz, data_in_dma,
925926 data_in_sz);
926
- mpt3sas_base_put_smid_default(ioc, smid);
927
+ ioc->put_smid_default(ioc, smid);
927928 break;
928929 }
929930 case MPI2_FUNCTION_SATA_PASSTHROUGH:
930931 {
931932 if (test_bit(device_handle, ioc->device_remove_in_progress)) {
932
- dtmprintk(ioc, pr_info(MPT3SAS_FMT
933
- "handle(0x%04x) :ioctl failed due to device removal in progress\n",
934
- ioc->name, device_handle));
933
+ dtmprintk(ioc,
934
+ ioc_info(ioc, "handle(0x%04x) :ioctl failed due to device removal in progress\n",
935
+ device_handle));
935936 mpt3sas_base_free_smid(ioc, smid);
936937 ret = -EINVAL;
937938 goto out;
938939 }
939940 ioc->build_sg(ioc, psge, data_out_dma, data_out_sz, data_in_dma,
940941 data_in_sz);
941
- mpt3sas_base_put_smid_default(ioc, smid);
942
+ ioc->put_smid_default(ioc, smid);
942943 break;
943944 }
944945 case MPI2_FUNCTION_FW_DOWNLOAD:
....@@ -946,7 +947,7 @@
946947 {
947948 ioc->build_sg(ioc, psge, data_out_dma, data_out_sz, data_in_dma,
948949 data_in_sz);
949
- mpt3sas_base_put_smid_default(ioc, smid);
950
+ ioc->put_smid_default(ioc, smid);
950951 break;
951952 }
952953 case MPI2_FUNCTION_TOOLBOX:
....@@ -954,14 +955,38 @@
954955 Mpi2ToolboxCleanRequest_t *toolbox_request =
955956 (Mpi2ToolboxCleanRequest_t *)mpi_request;
956957
957
- if (toolbox_request->Tool == MPI2_TOOLBOX_DIAGNOSTIC_CLI_TOOL) {
958
+ if ((toolbox_request->Tool == MPI2_TOOLBOX_DIAGNOSTIC_CLI_TOOL)
959
+ || (toolbox_request->Tool ==
960
+ MPI26_TOOLBOX_BACKEND_PCIE_LANE_MARGIN))
958961 ioc->build_sg(ioc, psge, data_out_dma, data_out_sz,
959962 data_in_dma, data_in_sz);
960
- } else {
963
+ else if (toolbox_request->Tool ==
964
+ MPI2_TOOLBOX_MEMORY_MOVE_TOOL) {
965
+ Mpi2ToolboxMemMoveRequest_t *mem_move_request =
966
+ (Mpi2ToolboxMemMoveRequest_t *)request;
967
+ Mpi2SGESimple64_t tmp, *src = NULL, *dst = NULL;
968
+
969
+ ioc->build_sg_mpi(ioc, psge, data_out_dma,
970
+ data_out_sz, data_in_dma, data_in_sz);
971
+ if (data_out_sz && !data_in_sz) {
972
+ dst =
973
+ (Mpi2SGESimple64_t *)&mem_move_request->SGL;
974
+ src = (void *)dst + ioc->sge_size;
975
+
976
+ memcpy(&tmp, src, ioc->sge_size);
977
+ memcpy(src, dst, ioc->sge_size);
978
+ memcpy(dst, &tmp, ioc->sge_size);
979
+ }
980
+ if (ioc->logging_level & MPT_DEBUG_TM) {
981
+ ioc_info(ioc,
982
+ "Mpi2ToolboxMemMoveRequest_t request msg\n");
983
+ _debug_dump_mf(mem_move_request,
984
+ ioc->request_sz/4);
985
+ }
986
+ } else
961987 ioc->build_sg_mpi(ioc, psge, data_out_dma, data_out_sz,
962
- data_in_dma, data_in_sz);
963
- }
964
- mpt3sas_base_put_smid_default(ioc, smid);
988
+ data_in_dma, data_in_sz);
989
+ ioc->put_smid_default(ioc, smid);
965990 break;
966991 }
967992 case MPI2_FUNCTION_SAS_IO_UNIT_CONTROL:
....@@ -977,11 +1002,11 @@
9771002 }
9781003 /* drop to default case for posting the request */
9791004 }
980
- /* fall through */
1005
+ fallthrough;
9811006 default:
9821007 ioc->build_sg_mpi(ioc, psge, data_out_dma, data_out_sz,
9831008 data_in_dma, data_in_sz);
984
- mpt3sas_base_put_smid_default(ioc, smid);
1009
+ ioc->put_smid_default(ioc, smid);
9851010 break;
9861011 }
9871012
....@@ -1003,10 +1028,9 @@
10031028 ioc->ignore_loginfos = 0;
10041029 }
10051030 if (!(ioc->ctl_cmds.status & MPT3_CMD_COMPLETE)) {
1006
- issue_reset =
1007
- mpt3sas_base_check_cmd_timeout(ioc,
1008
- ioc->ctl_cmds.status, mpi_request,
1009
- karg.data_sge_offset);
1031
+ mpt3sas_check_cmd_timeout(ioc,
1032
+ ioc->ctl_cmds.status, mpi_request,
1033
+ karg.data_sge_offset, issue_reset);
10101034 goto issue_host_reset;
10111035 }
10121036
....@@ -1017,12 +1041,10 @@
10171041 Mpi2SCSITaskManagementReply_t *tm_reply =
10181042 (Mpi2SCSITaskManagementReply_t *)mpi_reply;
10191043
1020
- pr_info(MPT3SAS_FMT "TASK_MGMT: " \
1021
- "IOCStatus(0x%04x), IOCLogInfo(0x%08x), "
1022
- "TerminationCount(0x%08x)\n", ioc->name,
1023
- le16_to_cpu(tm_reply->IOCStatus),
1024
- le32_to_cpu(tm_reply->IOCLogInfo),
1025
- le32_to_cpu(tm_reply->TerminationCount));
1044
+ ioc_info(ioc, "TASK_MGMT: IOCStatus(0x%04x), IOCLogInfo(0x%08x), TerminationCount(0x%08x)\n",
1045
+ le16_to_cpu(tm_reply->IOCStatus),
1046
+ le32_to_cpu(tm_reply->IOCLogInfo),
1047
+ le32_to_cpu(tm_reply->TerminationCount));
10261048 }
10271049
10281050 /* copy out xdata to user */
....@@ -1054,9 +1076,7 @@
10541076 MPI2_FUNCTION_RAID_SCSI_IO_PASSTHROUGH || mpi_request->Function ==
10551077 MPI2_FUNCTION_NVME_ENCAPSULATED)) {
10561078 if (karg.sense_data_ptr == NULL) {
1057
- pr_info(MPT3SAS_FMT "Response buffer provided"
1058
- " by application is NULL; Response data will"
1059
- " not be returned.\n", ioc->name);
1079
+ ioc_info(ioc, "Response buffer provided by application is NULL; Response data will not be returned\n");
10601080 goto out;
10611081 }
10621082 sz_arg = (mpi_request->Function ==
....@@ -1079,22 +1099,25 @@
10791099 mpi_request->Function ==
10801100 MPI2_FUNCTION_RAID_SCSI_IO_PASSTHROUGH ||
10811101 mpi_request->Function == MPI2_FUNCTION_SATA_PASSTHROUGH)) {
1082
- pr_info(MPT3SAS_FMT "issue target reset: handle = (0x%04x)\n",
1083
- ioc->name,
1084
- le16_to_cpu(mpi_request->FunctionDependent1));
1102
+ ioc_info(ioc, "issue target reset: handle = (0x%04x)\n",
1103
+ le16_to_cpu(mpi_request->FunctionDependent1));
10851104 mpt3sas_halt_firmware(ioc);
10861105 pcie_device = mpt3sas_get_pdev_by_handle(ioc,
10871106 le16_to_cpu(mpi_request->FunctionDependent1));
1088
- if (pcie_device && (!ioc->tm_custom_handling))
1107
+ if (pcie_device && (!ioc->tm_custom_handling) &&
1108
+ (!(mpt3sas_scsih_is_pcie_scsi_device(
1109
+ pcie_device->device_info))))
10891110 mpt3sas_scsih_issue_locked_tm(ioc,
10901111 le16_to_cpu(mpi_request->FunctionDependent1),
1091
- 0, MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET, 0,
1112
+ 0, 0, 0,
1113
+ MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET, 0,
10921114 0, pcie_device->reset_timeout,
1093
- tr_method);
1115
+ MPI26_SCSITASKMGMT_MSGFLAGS_PROTOCOL_LVL_RST_PCIE);
10941116 else
10951117 mpt3sas_scsih_issue_locked_tm(ioc,
10961118 le16_to_cpu(mpi_request->FunctionDependent1),
1097
- 0, MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET, 0,
1119
+ 0, 0, 0,
1120
+ MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET, 0,
10981121 0, 30, MPI2_SCSITASKMGMT_MSGFLAGS_LINK_RESET);
10991122 } else
11001123 mpt3sas_base_hard_reset_handler(ioc, FORCE_BIG_HAMMER);
....@@ -1106,11 +1129,11 @@
11061129
11071130 /* free memory associated with sg buffers */
11081131 if (data_in)
1109
- pci_free_consistent(ioc->pdev, data_in_sz, data_in,
1132
+ dma_free_coherent(&ioc->pdev->dev, data_in_sz, data_in,
11101133 data_in_dma);
11111134
11121135 if (data_out)
1113
- pci_free_consistent(ioc->pdev, data_out_sz, data_out,
1136
+ dma_free_coherent(&ioc->pdev->dev, data_out_sz, data_out,
11141137 data_out_dma);
11151138
11161139 kfree(mpi_request);
....@@ -1128,8 +1151,8 @@
11281151 {
11291152 struct mpt3_ioctl_iocinfo karg;
11301153
1131
- dctlprintk(ioc, pr_info(MPT3SAS_FMT "%s: enter\n", ioc->name,
1132
- __func__));
1154
+ dctlprintk(ioc, ioc_info(ioc, "%s: enter\n",
1155
+ __func__));
11331156
11341157 memset(&karg, 0 , sizeof(karg));
11351158 if (ioc->pfacts)
....@@ -1188,8 +1211,8 @@
11881211 return -EFAULT;
11891212 }
11901213
1191
- dctlprintk(ioc, pr_info(MPT3SAS_FMT "%s: enter\n", ioc->name,
1192
- __func__));
1214
+ dctlprintk(ioc, ioc_info(ioc, "%s: enter\n",
1215
+ __func__));
11931216
11941217 karg.event_entries = MPT3SAS_CTL_EVENT_LOG_SIZE;
11951218 memcpy(karg.event_types, ioc->event_type,
....@@ -1219,8 +1242,8 @@
12191242 return -EFAULT;
12201243 }
12211244
1222
- dctlprintk(ioc, pr_info(MPT3SAS_FMT "%s: enter\n", ioc->name,
1223
- __func__));
1245
+ dctlprintk(ioc, ioc_info(ioc, "%s: enter\n",
1246
+ __func__));
12241247
12251248 memcpy(ioc->event_type, karg.event_types,
12261249 MPI2_EVENT_NOTIFY_EVENTMASK_WORDS * sizeof(u32));
....@@ -1259,8 +1282,8 @@
12591282 return -EFAULT;
12601283 }
12611284
1262
- dctlprintk(ioc, pr_info(MPT3SAS_FMT "%s: enter\n", ioc->name,
1263
- __func__));
1285
+ dctlprintk(ioc, ioc_info(ioc, "%s: enter\n",
1286
+ __func__));
12641287
12651288 number_bytes = karg.hdr.max_data_size -
12661289 sizeof(struct mpt3_ioctl_header);
....@@ -1306,12 +1329,12 @@
13061329 ioc->is_driver_loading)
13071330 return -EAGAIN;
13081331
1309
- dctlprintk(ioc, pr_info(MPT3SAS_FMT "%s: enter\n", ioc->name,
1310
- __func__));
1332
+ dctlprintk(ioc, ioc_info(ioc, "%s: enter\n",
1333
+ __func__));
13111334
13121335 retval = mpt3sas_base_hard_reset_handler(ioc, FORCE_BIG_HAMMER);
1313
- pr_info(MPT3SAS_FMT "host reset: %s\n",
1314
- ioc->name, ((!retval) ? "SUCCESS" : "FAILED"));
1336
+ ioc_info(ioc,
1337
+ "Ioctl: host reset: %s\n", ((!retval) ? "SUCCESS" : "FAILED"));
13151338 return 0;
13161339 }
13171340
....@@ -1440,8 +1463,8 @@
14401463 return -EFAULT;
14411464 }
14421465
1443
- dctlprintk(ioc, pr_info(MPT3SAS_FMT "%s\n", ioc->name,
1444
- __func__));
1466
+ dctlprintk(ioc, ioc_info(ioc, "%s\n",
1467
+ __func__));
14451468
14461469 rc = _ctl_btdh_search_sas_device(ioc, &karg);
14471470 if (!rc)
....@@ -1489,6 +1512,26 @@
14891512 return rc;
14901513 }
14911514
1515
+/**
1516
+ * _ctl_diag_get_bufftype - return diag buffer type
1517
+ * either TRACE, SNAPSHOT, or EXTENDED
1518
+ * @ioc: per adapter object
1519
+ * @unique_id: specifies the unique_id for the buffer
1520
+ *
1521
+ * returns MPT3_DIAG_UID_NOT_FOUND if the id not found
1522
+ */
1523
+static u8
1524
+_ctl_diag_get_bufftype(struct MPT3SAS_ADAPTER *ioc, u32 unique_id)
1525
+{
1526
+ u8 index;
1527
+
1528
+ for (index = 0; index < MPI2_DIAG_BUF_TYPE_COUNT; index++) {
1529
+ if (ioc->unique_id[index] == unique_id)
1530
+ return index;
1531
+ }
1532
+
1533
+ return MPT3_DIAG_UID_NOT_FOUND;
1534
+}
14921535
14931536 /**
14941537 * _ctl_diag_register_2 - wrapper for registering diag buffer support
....@@ -1512,53 +1555,123 @@
15121555 u32 ioc_state;
15131556 u8 issue_reset = 0;
15141557
1515
- dctlprintk(ioc, pr_info(MPT3SAS_FMT "%s\n", ioc->name,
1516
- __func__));
1558
+ dctlprintk(ioc, ioc_info(ioc, "%s\n",
1559
+ __func__));
15171560
15181561 ioc_state = mpt3sas_base_get_iocstate(ioc, 1);
15191562 if (ioc_state != MPI2_IOC_STATE_OPERATIONAL) {
1520
- pr_err(MPT3SAS_FMT
1521
- "%s: failed due to ioc not operational\n",
1522
- ioc->name, __func__);
1563
+ ioc_err(ioc, "%s: failed due to ioc not operational\n",
1564
+ __func__);
15231565 rc = -EAGAIN;
15241566 goto out;
15251567 }
15261568
15271569 if (ioc->ctl_cmds.status != MPT3_CMD_NOT_USED) {
1528
- pr_err(MPT3SAS_FMT "%s: ctl_cmd in use\n",
1529
- ioc->name, __func__);
1570
+ ioc_err(ioc, "%s: ctl_cmd in use\n", __func__);
15301571 rc = -EAGAIN;
15311572 goto out;
15321573 }
15331574
15341575 buffer_type = diag_register->buffer_type;
15351576 if (!_ctl_diag_capability(ioc, buffer_type)) {
1536
- pr_err(MPT3SAS_FMT
1537
- "%s: doesn't have capability for buffer_type(0x%02x)\n",
1538
- ioc->name, __func__, buffer_type);
1577
+ ioc_err(ioc, "%s: doesn't have capability for buffer_type(0x%02x)\n",
1578
+ __func__, buffer_type);
15391579 return -EPERM;
1580
+ }
1581
+
1582
+ if (diag_register->unique_id == 0) {
1583
+ ioc_err(ioc,
1584
+ "%s: Invalid UID(0x%08x), buffer_type(0x%02x)\n", __func__,
1585
+ diag_register->unique_id, buffer_type);
1586
+ return -EINVAL;
1587
+ }
1588
+
1589
+ if ((ioc->diag_buffer_status[buffer_type] &
1590
+ MPT3_DIAG_BUFFER_IS_APP_OWNED) &&
1591
+ !(ioc->diag_buffer_status[buffer_type] &
1592
+ MPT3_DIAG_BUFFER_IS_RELEASED)) {
1593
+ ioc_err(ioc,
1594
+ "%s: buffer_type(0x%02x) is already registered by application with UID(0x%08x)\n",
1595
+ __func__, buffer_type, ioc->unique_id[buffer_type]);
1596
+ return -EINVAL;
15401597 }
15411598
15421599 if (ioc->diag_buffer_status[buffer_type] &
15431600 MPT3_DIAG_BUFFER_IS_REGISTERED) {
1544
- pr_err(MPT3SAS_FMT
1545
- "%s: already has a registered buffer for buffer_type(0x%02x)\n",
1546
- ioc->name, __func__,
1547
- buffer_type);
1548
- return -EINVAL;
1601
+ /*
1602
+ * If driver posts buffer initially, then an application wants
1603
+ * to Register that buffer (own it) without Releasing first,
1604
+ * the application Register command MUST have the same buffer
1605
+ * type and size in the Register command (obtained from the
1606
+ * Query command). Otherwise that Register command will be
1607
+ * failed. If the application has released the buffer but wants
1608
+ * to re-register it, it should be allowed as long as the
1609
+ * Unique-Id/Size match.
1610
+ */
1611
+
1612
+ if (ioc->unique_id[buffer_type] == MPT3DIAGBUFFUNIQUEID &&
1613
+ ioc->diag_buffer_sz[buffer_type] ==
1614
+ diag_register->requested_buffer_size) {
1615
+
1616
+ if (!(ioc->diag_buffer_status[buffer_type] &
1617
+ MPT3_DIAG_BUFFER_IS_RELEASED)) {
1618
+ dctlprintk(ioc, ioc_info(ioc,
1619
+ "%s: diag_buffer (%d) ownership changed. old-ID(0x%08x), new-ID(0x%08x)\n",
1620
+ __func__, buffer_type,
1621
+ ioc->unique_id[buffer_type],
1622
+ diag_register->unique_id));
1623
+
1624
+ /*
1625
+ * Application wants to own the buffer with
1626
+ * the same size.
1627
+ */
1628
+ ioc->unique_id[buffer_type] =
1629
+ diag_register->unique_id;
1630
+ rc = 0; /* success */
1631
+ goto out;
1632
+ }
1633
+ } else if (ioc->unique_id[buffer_type] !=
1634
+ MPT3DIAGBUFFUNIQUEID) {
1635
+ if (ioc->unique_id[buffer_type] !=
1636
+ diag_register->unique_id ||
1637
+ ioc->diag_buffer_sz[buffer_type] !=
1638
+ diag_register->requested_buffer_size ||
1639
+ !(ioc->diag_buffer_status[buffer_type] &
1640
+ MPT3_DIAG_BUFFER_IS_RELEASED)) {
1641
+ ioc_err(ioc,
1642
+ "%s: already has a registered buffer for buffer_type(0x%02x)\n",
1643
+ __func__, buffer_type);
1644
+ return -EINVAL;
1645
+ }
1646
+ } else {
1647
+ ioc_err(ioc, "%s: already has a registered buffer for buffer_type(0x%02x)\n",
1648
+ __func__, buffer_type);
1649
+ return -EINVAL;
1650
+ }
1651
+ } else if (ioc->diag_buffer_status[buffer_type] &
1652
+ MPT3_DIAG_BUFFER_IS_DRIVER_ALLOCATED) {
1653
+
1654
+ if (ioc->unique_id[buffer_type] != MPT3DIAGBUFFUNIQUEID ||
1655
+ ioc->diag_buffer_sz[buffer_type] !=
1656
+ diag_register->requested_buffer_size) {
1657
+
1658
+ ioc_err(ioc,
1659
+ "%s: already a buffer is allocated for buffer_type(0x%02x) of size %d bytes, so please try registering again with same size\n",
1660
+ __func__, buffer_type,
1661
+ ioc->diag_buffer_sz[buffer_type]);
1662
+ return -EINVAL;
1663
+ }
15491664 }
15501665
15511666 if (diag_register->requested_buffer_size % 4) {
1552
- pr_err(MPT3SAS_FMT
1553
- "%s: the requested_buffer_size is not 4 byte aligned\n",
1554
- ioc->name, __func__);
1667
+ ioc_err(ioc, "%s: the requested_buffer_size is not 4 byte aligned\n",
1668
+ __func__);
15551669 return -EINVAL;
15561670 }
15571671
15581672 smid = mpt3sas_base_get_smid(ioc, ioc->ctl_cb_idx);
15591673 if (!smid) {
1560
- pr_err(MPT3SAS_FMT "%s: failed obtaining a smid\n",
1561
- ioc->name, __func__);
1674
+ ioc_err(ioc, "%s: failed obtaining a smid\n", __func__);
15621675 rc = -EAGAIN;
15631676 goto out;
15641677 }
....@@ -1572,7 +1685,8 @@
15721685 request_data = ioc->diag_buffer[buffer_type];
15731686 request_data_sz = diag_register->requested_buffer_size;
15741687 ioc->unique_id[buffer_type] = diag_register->unique_id;
1575
- ioc->diag_buffer_status[buffer_type] = 0;
1688
+ ioc->diag_buffer_status[buffer_type] &=
1689
+ MPT3_DIAG_BUFFER_IS_DRIVER_ALLOCATED;
15761690 memcpy(ioc->product_specific[buffer_type],
15771691 diag_register->product_specific, MPT3_PRODUCT_SPECIFIC_DWORDS);
15781692 ioc->diagnostic_flags[buffer_type] = diag_register->diagnostic_flags;
....@@ -1580,9 +1694,9 @@
15801694 if (request_data) {
15811695 request_data_dma = ioc->diag_buffer_dma[buffer_type];
15821696 if (request_data_sz != ioc->diag_buffer_sz[buffer_type]) {
1583
- pci_free_consistent(ioc->pdev,
1584
- ioc->diag_buffer_sz[buffer_type],
1585
- request_data, request_data_dma);
1697
+ dma_free_coherent(&ioc->pdev->dev,
1698
+ ioc->diag_buffer_sz[buffer_type],
1699
+ request_data, request_data_dma);
15861700 request_data = NULL;
15871701 }
15881702 }
....@@ -1590,12 +1704,11 @@
15901704 if (request_data == NULL) {
15911705 ioc->diag_buffer_sz[buffer_type] = 0;
15921706 ioc->diag_buffer_dma[buffer_type] = 0;
1593
- request_data = pci_alloc_consistent(
1594
- ioc->pdev, request_data_sz, &request_data_dma);
1707
+ request_data = dma_alloc_coherent(&ioc->pdev->dev,
1708
+ request_data_sz, &request_data_dma, GFP_KERNEL);
15951709 if (request_data == NULL) {
1596
- pr_err(MPT3SAS_FMT "%s: failed allocating memory" \
1597
- " for diag buffers, requested size(%d)\n",
1598
- ioc->name, __func__, request_data_sz);
1710
+ ioc_err(ioc, "%s: failed allocating memory for diag buffers, requested size(%d)\n",
1711
+ __func__, request_data_sz);
15991712 mpt3sas_base_free_smid(ioc, smid);
16001713 rc = -ENOMEM;
16011714 goto out;
....@@ -1613,33 +1726,31 @@
16131726 mpi_request->VF_ID = 0; /* TODO */
16141727 mpi_request->VP_ID = 0;
16151728
1616
- dctlprintk(ioc, pr_info(MPT3SAS_FMT
1617
- "%s: diag_buffer(0x%p), dma(0x%llx), sz(%d)\n",
1618
- ioc->name, __func__, request_data,
1619
- (unsigned long long)request_data_dma,
1620
- le32_to_cpu(mpi_request->BufferLength)));
1729
+ dctlprintk(ioc,
1730
+ ioc_info(ioc, "%s: diag_buffer(0x%p), dma(0x%llx), sz(%d)\n",
1731
+ __func__, request_data,
1732
+ (unsigned long long)request_data_dma,
1733
+ le32_to_cpu(mpi_request->BufferLength)));
16211734
16221735 for (i = 0; i < MPT3_PRODUCT_SPECIFIC_DWORDS; i++)
16231736 mpi_request->ProductSpecific[i] =
16241737 cpu_to_le32(ioc->product_specific[buffer_type][i]);
16251738
16261739 init_completion(&ioc->ctl_cmds.done);
1627
- mpt3sas_base_put_smid_default(ioc, smid);
1740
+ ioc->put_smid_default(ioc, smid);
16281741 wait_for_completion_timeout(&ioc->ctl_cmds.done,
16291742 MPT3_IOCTL_DEFAULT_TIMEOUT*HZ);
16301743
16311744 if (!(ioc->ctl_cmds.status & MPT3_CMD_COMPLETE)) {
1632
- issue_reset =
1633
- mpt3sas_base_check_cmd_timeout(ioc,
1634
- ioc->ctl_cmds.status, mpi_request,
1635
- sizeof(Mpi2DiagBufferPostRequest_t)/4);
1745
+ mpt3sas_check_cmd_timeout(ioc,
1746
+ ioc->ctl_cmds.status, mpi_request,
1747
+ sizeof(Mpi2DiagBufferPostRequest_t)/4, issue_reset);
16361748 goto issue_host_reset;
16371749 }
16381750
16391751 /* process the completed Reply Message Frame */
16401752 if ((ioc->ctl_cmds.status & MPT3_CMD_REPLY_VALID) == 0) {
1641
- pr_err(MPT3SAS_FMT "%s: no reply message\n",
1642
- ioc->name, __func__);
1753
+ ioc_err(ioc, "%s: no reply message\n", __func__);
16431754 rc = -EFAULT;
16441755 goto out;
16451756 }
....@@ -1650,13 +1761,11 @@
16501761 if (ioc_status == MPI2_IOCSTATUS_SUCCESS) {
16511762 ioc->diag_buffer_status[buffer_type] |=
16521763 MPT3_DIAG_BUFFER_IS_REGISTERED;
1653
- dctlprintk(ioc, pr_info(MPT3SAS_FMT "%s: success\n",
1654
- ioc->name, __func__));
1764
+ dctlprintk(ioc, ioc_info(ioc, "%s: success\n", __func__));
16551765 } else {
1656
- pr_info(MPT3SAS_FMT
1657
- "%s: ioc_status(0x%04x) log_info(0x%08x)\n",
1658
- ioc->name, __func__,
1659
- ioc_status, le32_to_cpu(mpi_reply->IOCLogInfo));
1766
+ ioc_info(ioc, "%s: ioc_status(0x%04x) log_info(0x%08x)\n",
1767
+ __func__,
1768
+ ioc_status, le32_to_cpu(mpi_reply->IOCLogInfo));
16601769 rc = -EFAULT;
16611770 }
16621771
....@@ -1666,9 +1775,12 @@
16661775
16671776 out:
16681777
1669
- if (rc && request_data)
1670
- pci_free_consistent(ioc->pdev, request_data_sz,
1778
+ if (rc && request_data) {
1779
+ dma_free_coherent(&ioc->pdev->dev, request_data_sz,
16711780 request_data, request_data_dma);
1781
+ ioc->diag_buffer_status[buffer_type] &=
1782
+ ~MPT3_DIAG_BUFFER_IS_DRIVER_ALLOCATED;
1783
+ }
16721784
16731785 ioc->ctl_cmds.status = MPT3_CMD_NOT_USED;
16741786 return rc;
....@@ -1686,24 +1798,84 @@
16861798 mpt3sas_enable_diag_buffer(struct MPT3SAS_ADAPTER *ioc, u8 bits_to_register)
16871799 {
16881800 struct mpt3_diag_register diag_register;
1801
+ u32 ret_val;
1802
+ u32 trace_buff_size = ioc->manu_pg11.HostTraceBufferMaxSizeKB<<10;
1803
+ u32 min_trace_buff_size = 0;
1804
+ u32 decr_trace_buff_size = 0;
16891805
16901806 memset(&diag_register, 0, sizeof(struct mpt3_diag_register));
16911807
16921808 if (bits_to_register & 1) {
1693
- pr_info(MPT3SAS_FMT "registering trace buffer support\n",
1694
- ioc->name);
1809
+ ioc_info(ioc, "registering trace buffer support\n");
16951810 ioc->diag_trigger_master.MasterData =
16961811 (MASTER_TRIGGER_FW_FAULT + MASTER_TRIGGER_ADAPTER_RESET);
16971812 diag_register.buffer_type = MPI2_DIAG_BUF_TYPE_TRACE;
1698
- /* register for 2MB buffers */
1699
- diag_register.requested_buffer_size = 2 * (1024 * 1024);
1700
- diag_register.unique_id = 0x7075900;
1701
- _ctl_diag_register_2(ioc, &diag_register);
1813
+ diag_register.unique_id =
1814
+ (ioc->hba_mpi_version_belonged == MPI2_VERSION) ?
1815
+ (MPT2DIAGBUFFUNIQUEID):(MPT3DIAGBUFFUNIQUEID);
1816
+
1817
+ if (trace_buff_size != 0) {
1818
+ diag_register.requested_buffer_size = trace_buff_size;
1819
+ min_trace_buff_size =
1820
+ ioc->manu_pg11.HostTraceBufferMinSizeKB<<10;
1821
+ decr_trace_buff_size =
1822
+ ioc->manu_pg11.HostTraceBufferDecrementSizeKB<<10;
1823
+
1824
+ if (min_trace_buff_size > trace_buff_size) {
1825
+ /* The buff size is not set correctly */
1826
+ ioc_err(ioc,
1827
+ "Min Trace Buff size (%d KB) greater than Max Trace Buff size (%d KB)\n",
1828
+ min_trace_buff_size>>10,
1829
+ trace_buff_size>>10);
1830
+ ioc_err(ioc,
1831
+ "Using zero Min Trace Buff Size\n");
1832
+ min_trace_buff_size = 0;
1833
+ }
1834
+
1835
+ if (decr_trace_buff_size == 0) {
1836
+ /*
1837
+ * retry the min size if decrement
1838
+ * is not available.
1839
+ */
1840
+ decr_trace_buff_size =
1841
+ trace_buff_size - min_trace_buff_size;
1842
+ }
1843
+ } else {
1844
+ /* register for 2MB buffers */
1845
+ diag_register.requested_buffer_size = 2 * (1024 * 1024);
1846
+ }
1847
+
1848
+ do {
1849
+ ret_val = _ctl_diag_register_2(ioc, &diag_register);
1850
+
1851
+ if (ret_val == -ENOMEM && min_trace_buff_size &&
1852
+ (trace_buff_size - decr_trace_buff_size) >=
1853
+ min_trace_buff_size) {
1854
+ /* adjust the buffer size */
1855
+ trace_buff_size -= decr_trace_buff_size;
1856
+ diag_register.requested_buffer_size =
1857
+ trace_buff_size;
1858
+ } else
1859
+ break;
1860
+ } while (true);
1861
+
1862
+ if (ret_val == -ENOMEM)
1863
+ ioc_err(ioc,
1864
+ "Cannot allocate trace buffer memory. Last memory tried = %d KB\n",
1865
+ diag_register.requested_buffer_size>>10);
1866
+ else if (ioc->diag_buffer_status[MPI2_DIAG_BUF_TYPE_TRACE]
1867
+ & MPT3_DIAG_BUFFER_IS_REGISTERED) {
1868
+ ioc_err(ioc, "Trace buffer memory %d KB allocated\n",
1869
+ diag_register.requested_buffer_size>>10);
1870
+ if (ioc->hba_mpi_version_belonged != MPI2_VERSION)
1871
+ ioc->diag_buffer_status[
1872
+ MPI2_DIAG_BUF_TYPE_TRACE] |=
1873
+ MPT3_DIAG_BUFFER_IS_DRIVER_ALLOCATED;
1874
+ }
17021875 }
17031876
17041877 if (bits_to_register & 2) {
1705
- pr_info(MPT3SAS_FMT "registering snapshot buffer support\n",
1706
- ioc->name);
1878
+ ioc_info(ioc, "registering snapshot buffer support\n");
17071879 diag_register.buffer_type = MPI2_DIAG_BUF_TYPE_SNAPSHOT;
17081880 /* register for 2MB buffers */
17091881 diag_register.requested_buffer_size = 2 * (1024 * 1024);
....@@ -1712,8 +1884,7 @@
17121884 }
17131885
17141886 if (bits_to_register & 4) {
1715
- pr_info(MPT3SAS_FMT "registering extended buffer support\n",
1716
- ioc->name);
1887
+ ioc_info(ioc, "registering extended buffer support\n");
17171888 diag_register.buffer_type = MPI2_DIAG_BUF_TYPE_EXTENDED;
17181889 /* register for 2MB buffers */
17191890 diag_register.requested_buffer_size = 2 * (1024 * 1024);
....@@ -1743,6 +1914,12 @@
17431914 }
17441915
17451916 rc = _ctl_diag_register_2(ioc, &karg);
1917
+
1918
+ if (!rc && (ioc->diag_buffer_status[karg.buffer_type] &
1919
+ MPT3_DIAG_BUFFER_IS_REGISTERED))
1920
+ ioc->diag_buffer_status[karg.buffer_type] |=
1921
+ MPT3_DIAG_BUFFER_IS_APP_OWNED;
1922
+
17461923 return rc;
17471924 }
17481925
....@@ -1769,53 +1946,63 @@
17691946 return -EFAULT;
17701947 }
17711948
1772
- dctlprintk(ioc, pr_info(MPT3SAS_FMT "%s\n", ioc->name,
1773
- __func__));
1949
+ dctlprintk(ioc, ioc_info(ioc, "%s\n",
1950
+ __func__));
17741951
1775
- buffer_type = karg.unique_id & 0x000000ff;
1952
+ buffer_type = _ctl_diag_get_bufftype(ioc, karg.unique_id);
1953
+ if (buffer_type == MPT3_DIAG_UID_NOT_FOUND) {
1954
+ ioc_err(ioc, "%s: buffer with unique_id(0x%08x) not found\n",
1955
+ __func__, karg.unique_id);
1956
+ return -EINVAL;
1957
+ }
1958
+
17761959 if (!_ctl_diag_capability(ioc, buffer_type)) {
1777
- pr_err(MPT3SAS_FMT
1778
- "%s: doesn't have capability for buffer_type(0x%02x)\n",
1779
- ioc->name, __func__, buffer_type);
1960
+ ioc_err(ioc, "%s: doesn't have capability for buffer_type(0x%02x)\n",
1961
+ __func__, buffer_type);
17801962 return -EPERM;
17811963 }
17821964
17831965 if ((ioc->diag_buffer_status[buffer_type] &
17841966 MPT3_DIAG_BUFFER_IS_REGISTERED) == 0) {
1785
- pr_err(MPT3SAS_FMT
1786
- "%s: buffer_type(0x%02x) is not registered\n",
1787
- ioc->name, __func__, buffer_type);
1967
+ ioc_err(ioc, "%s: buffer_type(0x%02x) is not registered\n",
1968
+ __func__, buffer_type);
17881969 return -EINVAL;
17891970 }
17901971 if ((ioc->diag_buffer_status[buffer_type] &
17911972 MPT3_DIAG_BUFFER_IS_RELEASED) == 0) {
1792
- pr_err(MPT3SAS_FMT
1793
- "%s: buffer_type(0x%02x) has not been released\n",
1794
- ioc->name, __func__, buffer_type);
1973
+ ioc_err(ioc, "%s: buffer_type(0x%02x) has not been released\n",
1974
+ __func__, buffer_type);
17951975 return -EINVAL;
17961976 }
17971977
17981978 if (karg.unique_id != ioc->unique_id[buffer_type]) {
1799
- pr_err(MPT3SAS_FMT
1800
- "%s: unique_id(0x%08x) is not registered\n",
1801
- ioc->name, __func__, karg.unique_id);
1979
+ ioc_err(ioc, "%s: unique_id(0x%08x) is not registered\n",
1980
+ __func__, karg.unique_id);
18021981 return -EINVAL;
18031982 }
18041983
18051984 request_data = ioc->diag_buffer[buffer_type];
18061985 if (!request_data) {
1807
- pr_err(MPT3SAS_FMT
1808
- "%s: doesn't have memory allocated for buffer_type(0x%02x)\n",
1809
- ioc->name, __func__, buffer_type);
1986
+ ioc_err(ioc, "%s: doesn't have memory allocated for buffer_type(0x%02x)\n",
1987
+ __func__, buffer_type);
18101988 return -ENOMEM;
18111989 }
18121990
1813
- request_data_sz = ioc->diag_buffer_sz[buffer_type];
1814
- request_data_dma = ioc->diag_buffer_dma[buffer_type];
1815
- pci_free_consistent(ioc->pdev, request_data_sz,
1816
- request_data, request_data_dma);
1817
- ioc->diag_buffer[buffer_type] = NULL;
1818
- ioc->diag_buffer_status[buffer_type] = 0;
1991
+ if (ioc->diag_buffer_status[buffer_type] &
1992
+ MPT3_DIAG_BUFFER_IS_DRIVER_ALLOCATED) {
1993
+ ioc->unique_id[buffer_type] = MPT3DIAGBUFFUNIQUEID;
1994
+ ioc->diag_buffer_status[buffer_type] &=
1995
+ ~MPT3_DIAG_BUFFER_IS_APP_OWNED;
1996
+ ioc->diag_buffer_status[buffer_type] &=
1997
+ ~MPT3_DIAG_BUFFER_IS_REGISTERED;
1998
+ } else {
1999
+ request_data_sz = ioc->diag_buffer_sz[buffer_type];
2000
+ request_data_dma = ioc->diag_buffer_dma[buffer_type];
2001
+ dma_free_coherent(&ioc->pdev->dev, request_data_sz,
2002
+ request_data, request_data_dma);
2003
+ ioc->diag_buffer[buffer_type] = NULL;
2004
+ ioc->diag_buffer_status[buffer_type] = 0;
2005
+ }
18192006 return 0;
18202007 }
18212008
....@@ -1842,51 +2029,58 @@
18422029 return -EFAULT;
18432030 }
18442031
1845
- dctlprintk(ioc, pr_info(MPT3SAS_FMT "%s\n", ioc->name,
1846
- __func__));
2032
+ dctlprintk(ioc, ioc_info(ioc, "%s\n",
2033
+ __func__));
18472034
18482035 karg.application_flags = 0;
18492036 buffer_type = karg.buffer_type;
18502037
18512038 if (!_ctl_diag_capability(ioc, buffer_type)) {
1852
- pr_err(MPT3SAS_FMT
1853
- "%s: doesn't have capability for buffer_type(0x%02x)\n",
1854
- ioc->name, __func__, buffer_type);
2039
+ ioc_err(ioc, "%s: doesn't have capability for buffer_type(0x%02x)\n",
2040
+ __func__, buffer_type);
18552041 return -EPERM;
18562042 }
18572043
1858
- if ((ioc->diag_buffer_status[buffer_type] &
1859
- MPT3_DIAG_BUFFER_IS_REGISTERED) == 0) {
1860
- pr_err(MPT3SAS_FMT
1861
- "%s: buffer_type(0x%02x) is not registered\n",
1862
- ioc->name, __func__, buffer_type);
1863
- return -EINVAL;
2044
+ if (!(ioc->diag_buffer_status[buffer_type] &
2045
+ MPT3_DIAG_BUFFER_IS_DRIVER_ALLOCATED)) {
2046
+ if ((ioc->diag_buffer_status[buffer_type] &
2047
+ MPT3_DIAG_BUFFER_IS_REGISTERED) == 0) {
2048
+ ioc_err(ioc, "%s: buffer_type(0x%02x) is not registered\n",
2049
+ __func__, buffer_type);
2050
+ return -EINVAL;
2051
+ }
18642052 }
18652053
1866
- if (karg.unique_id & 0xffffff00) {
2054
+ if (karg.unique_id) {
18672055 if (karg.unique_id != ioc->unique_id[buffer_type]) {
1868
- pr_err(MPT3SAS_FMT
1869
- "%s: unique_id(0x%08x) is not registered\n",
1870
- ioc->name, __func__, karg.unique_id);
2056
+ ioc_err(ioc, "%s: unique_id(0x%08x) is not registered\n",
2057
+ __func__, karg.unique_id);
18712058 return -EINVAL;
18722059 }
18732060 }
18742061
18752062 request_data = ioc->diag_buffer[buffer_type];
18762063 if (!request_data) {
1877
- pr_err(MPT3SAS_FMT
1878
- "%s: doesn't have buffer for buffer_type(0x%02x)\n",
1879
- ioc->name, __func__, buffer_type);
2064
+ ioc_err(ioc, "%s: doesn't have buffer for buffer_type(0x%02x)\n",
2065
+ __func__, buffer_type);
18802066 return -ENOMEM;
18812067 }
18822068
1883
- if (ioc->diag_buffer_status[buffer_type] & MPT3_DIAG_BUFFER_IS_RELEASED)
1884
- karg.application_flags = (MPT3_APP_FLAGS_APP_OWNED |
1885
- MPT3_APP_FLAGS_BUFFER_VALID);
1886
- else
1887
- karg.application_flags = (MPT3_APP_FLAGS_APP_OWNED |
1888
- MPT3_APP_FLAGS_BUFFER_VALID |
1889
- MPT3_APP_FLAGS_FW_BUFFER_ACCESS);
2069
+ if ((ioc->diag_buffer_status[buffer_type] &
2070
+ MPT3_DIAG_BUFFER_IS_REGISTERED))
2071
+ karg.application_flags |= MPT3_APP_FLAGS_BUFFER_VALID;
2072
+
2073
+ if (!(ioc->diag_buffer_status[buffer_type] &
2074
+ MPT3_DIAG_BUFFER_IS_RELEASED))
2075
+ karg.application_flags |= MPT3_APP_FLAGS_FW_BUFFER_ACCESS;
2076
+
2077
+ if (!(ioc->diag_buffer_status[buffer_type] &
2078
+ MPT3_DIAG_BUFFER_IS_DRIVER_ALLOCATED))
2079
+ karg.application_flags |= MPT3_APP_FLAGS_DYNAMIC_BUFFER_ALLOC;
2080
+
2081
+ if ((ioc->diag_buffer_status[buffer_type] &
2082
+ MPT3_DIAG_BUFFER_IS_APP_OWNED))
2083
+ karg.application_flags |= MPT3_APP_FLAGS_APP_OWNED;
18902084
18912085 for (i = 0; i < MPT3_PRODUCT_SPECIFIC_DWORDS; i++)
18922086 karg.product_specific[i] =
....@@ -1898,9 +2092,8 @@
18982092 karg.diagnostic_flags = ioc->diagnostic_flags[buffer_type];
18992093
19002094 if (copy_to_user(arg, &karg, sizeof(struct mpt3_diag_query))) {
1901
- pr_err(MPT3SAS_FMT
1902
- "%s: unable to write mpt3_diag_query data @ %p\n",
1903
- ioc->name, __func__, arg);
2095
+ ioc_err(ioc, "%s: unable to write mpt3_diag_query data @ %p\n",
2096
+ __func__, arg);
19042097 return -EFAULT;
19052098 }
19062099 return 0;
....@@ -1923,12 +2116,14 @@
19232116 u16 ioc_status;
19242117 u32 ioc_state;
19252118 int rc;
2119
+ u8 reset_needed = 0;
19262120
1927
- dctlprintk(ioc, pr_info(MPT3SAS_FMT "%s\n", ioc->name,
1928
- __func__));
2121
+ dctlprintk(ioc, ioc_info(ioc, "%s\n",
2122
+ __func__));
19292123
19302124 rc = 0;
19312125 *issue_reset = 0;
2126
+
19322127
19332128 ioc_state = mpt3sas_base_get_iocstate(ioc, 1);
19342129 if (ioc_state != MPI2_IOC_STATE_OPERATIONAL) {
....@@ -1936,24 +2131,22 @@
19362131 MPT3_DIAG_BUFFER_IS_REGISTERED)
19372132 ioc->diag_buffer_status[buffer_type] |=
19382133 MPT3_DIAG_BUFFER_IS_RELEASED;
1939
- dctlprintk(ioc, pr_info(MPT3SAS_FMT
1940
- "%s: skipping due to FAULT state\n", ioc->name,
1941
- __func__));
2134
+ dctlprintk(ioc,
2135
+ ioc_info(ioc, "%s: skipping due to FAULT state\n",
2136
+ __func__));
19422137 rc = -EAGAIN;
19432138 goto out;
19442139 }
19452140
19462141 if (ioc->ctl_cmds.status != MPT3_CMD_NOT_USED) {
1947
- pr_err(MPT3SAS_FMT "%s: ctl_cmd in use\n",
1948
- ioc->name, __func__);
2142
+ ioc_err(ioc, "%s: ctl_cmd in use\n", __func__);
19492143 rc = -EAGAIN;
19502144 goto out;
19512145 }
19522146
19532147 smid = mpt3sas_base_get_smid(ioc, ioc->ctl_cb_idx);
19542148 if (!smid) {
1955
- pr_err(MPT3SAS_FMT "%s: failed obtaining a smid\n",
1956
- ioc->name, __func__);
2149
+ ioc_err(ioc, "%s: failed obtaining a smid\n", __func__);
19572150 rc = -EAGAIN;
19582151 goto out;
19592152 }
....@@ -1969,22 +2162,22 @@
19692162 mpi_request->VP_ID = 0;
19702163
19712164 init_completion(&ioc->ctl_cmds.done);
1972
- mpt3sas_base_put_smid_default(ioc, smid);
2165
+ ioc->put_smid_default(ioc, smid);
19732166 wait_for_completion_timeout(&ioc->ctl_cmds.done,
19742167 MPT3_IOCTL_DEFAULT_TIMEOUT*HZ);
19752168
19762169 if (!(ioc->ctl_cmds.status & MPT3_CMD_COMPLETE)) {
1977
- *issue_reset = mpt3sas_base_check_cmd_timeout(ioc,
1978
- ioc->ctl_cmds.status, mpi_request,
1979
- sizeof(Mpi2DiagReleaseRequest_t)/4);
2170
+ mpt3sas_check_cmd_timeout(ioc,
2171
+ ioc->ctl_cmds.status, mpi_request,
2172
+ sizeof(Mpi2DiagReleaseRequest_t)/4, reset_needed);
2173
+ *issue_reset = reset_needed;
19802174 rc = -EFAULT;
19812175 goto out;
19822176 }
19832177
19842178 /* process the completed Reply Message Frame */
19852179 if ((ioc->ctl_cmds.status & MPT3_CMD_REPLY_VALID) == 0) {
1986
- pr_err(MPT3SAS_FMT "%s: no reply message\n",
1987
- ioc->name, __func__);
2180
+ ioc_err(ioc, "%s: no reply message\n", __func__);
19882181 rc = -EFAULT;
19892182 goto out;
19902183 }
....@@ -1995,13 +2188,11 @@
19952188 if (ioc_status == MPI2_IOCSTATUS_SUCCESS) {
19962189 ioc->diag_buffer_status[buffer_type] |=
19972190 MPT3_DIAG_BUFFER_IS_RELEASED;
1998
- dctlprintk(ioc, pr_info(MPT3SAS_FMT "%s: success\n",
1999
- ioc->name, __func__));
2191
+ dctlprintk(ioc, ioc_info(ioc, "%s: success\n", __func__));
20002192 } else {
2001
- pr_info(MPT3SAS_FMT
2002
- "%s: ioc_status(0x%04x) log_info(0x%08x)\n",
2003
- ioc->name, __func__,
2004
- ioc_status, le32_to_cpu(mpi_reply->IOCLogInfo));
2193
+ ioc_info(ioc, "%s: ioc_status(0x%04x) log_info(0x%08x)\n",
2194
+ __func__,
2195
+ ioc_status, le32_to_cpu(mpi_reply->IOCLogInfo));
20052196 rc = -EFAULT;
20062197 }
20072198
....@@ -2034,47 +2225,47 @@
20342225 return -EFAULT;
20352226 }
20362227
2037
- dctlprintk(ioc, pr_info(MPT3SAS_FMT "%s\n", ioc->name,
2038
- __func__));
2228
+ dctlprintk(ioc, ioc_info(ioc, "%s\n",
2229
+ __func__));
20392230
2040
- buffer_type = karg.unique_id & 0x000000ff;
2231
+ buffer_type = _ctl_diag_get_bufftype(ioc, karg.unique_id);
2232
+ if (buffer_type == MPT3_DIAG_UID_NOT_FOUND) {
2233
+ ioc_err(ioc, "%s: buffer with unique_id(0x%08x) not found\n",
2234
+ __func__, karg.unique_id);
2235
+ return -EINVAL;
2236
+ }
2237
+
20412238 if (!_ctl_diag_capability(ioc, buffer_type)) {
2042
- pr_err(MPT3SAS_FMT
2043
- "%s: doesn't have capability for buffer_type(0x%02x)\n",
2044
- ioc->name, __func__, buffer_type);
2239
+ ioc_err(ioc, "%s: doesn't have capability for buffer_type(0x%02x)\n",
2240
+ __func__, buffer_type);
20452241 return -EPERM;
20462242 }
20472243
20482244 if ((ioc->diag_buffer_status[buffer_type] &
20492245 MPT3_DIAG_BUFFER_IS_REGISTERED) == 0) {
2050
- pr_err(MPT3SAS_FMT
2051
- "%s: buffer_type(0x%02x) is not registered\n",
2052
- ioc->name, __func__, buffer_type);
2246
+ ioc_err(ioc, "%s: buffer_type(0x%02x) is not registered\n",
2247
+ __func__, buffer_type);
20532248 return -EINVAL;
20542249 }
20552250
20562251 if (karg.unique_id != ioc->unique_id[buffer_type]) {
2057
- pr_err(MPT3SAS_FMT
2058
- "%s: unique_id(0x%08x) is not registered\n",
2059
- ioc->name, __func__, karg.unique_id);
2252
+ ioc_err(ioc, "%s: unique_id(0x%08x) is not registered\n",
2253
+ __func__, karg.unique_id);
20602254 return -EINVAL;
20612255 }
20622256
20632257 if (ioc->diag_buffer_status[buffer_type] &
20642258 MPT3_DIAG_BUFFER_IS_RELEASED) {
2065
- pr_err(MPT3SAS_FMT
2066
- "%s: buffer_type(0x%02x) is already released\n",
2067
- ioc->name, __func__,
2068
- buffer_type);
2069
- return 0;
2259
+ ioc_err(ioc, "%s: buffer_type(0x%02x) is already released\n",
2260
+ __func__, buffer_type);
2261
+ return -EINVAL;
20702262 }
20712263
20722264 request_data = ioc->diag_buffer[buffer_type];
20732265
20742266 if (!request_data) {
2075
- pr_err(MPT3SAS_FMT
2076
- "%s: doesn't have memory allocated for buffer_type(0x%02x)\n",
2077
- ioc->name, __func__, buffer_type);
2267
+ ioc_err(ioc, "%s: doesn't have memory allocated for buffer_type(0x%02x)\n",
2268
+ __func__, buffer_type);
20782269 return -ENOMEM;
20792270 }
20802271
....@@ -2085,9 +2276,8 @@
20852276 MPT3_DIAG_BUFFER_IS_RELEASED;
20862277 ioc->diag_buffer_status[buffer_type] &=
20872278 ~MPT3_DIAG_BUFFER_IS_DIAG_RESET;
2088
- pr_err(MPT3SAS_FMT
2089
- "%s: buffer_type(0x%02x) was released due to host reset\n",
2090
- ioc->name, __func__, buffer_type);
2279
+ ioc_err(ioc, "%s: buffer_type(0x%02x) was released due to host reset\n",
2280
+ __func__, buffer_type);
20912281 return 0;
20922282 }
20932283
....@@ -2125,38 +2315,40 @@
21252315 return -EFAULT;
21262316 }
21272317
2128
- dctlprintk(ioc, pr_info(MPT3SAS_FMT "%s\n", ioc->name,
2129
- __func__));
2318
+ dctlprintk(ioc, ioc_info(ioc, "%s\n",
2319
+ __func__));
21302320
2131
- buffer_type = karg.unique_id & 0x000000ff;
2321
+ buffer_type = _ctl_diag_get_bufftype(ioc, karg.unique_id);
2322
+ if (buffer_type == MPT3_DIAG_UID_NOT_FOUND) {
2323
+ ioc_err(ioc, "%s: buffer with unique_id(0x%08x) not found\n",
2324
+ __func__, karg.unique_id);
2325
+ return -EINVAL;
2326
+ }
2327
+
21322328 if (!_ctl_diag_capability(ioc, buffer_type)) {
2133
- pr_err(MPT3SAS_FMT
2134
- "%s: doesn't have capability for buffer_type(0x%02x)\n",
2135
- ioc->name, __func__, buffer_type);
2329
+ ioc_err(ioc, "%s: doesn't have capability for buffer_type(0x%02x)\n",
2330
+ __func__, buffer_type);
21362331 return -EPERM;
21372332 }
21382333
21392334 if (karg.unique_id != ioc->unique_id[buffer_type]) {
2140
- pr_err(MPT3SAS_FMT
2141
- "%s: unique_id(0x%08x) is not registered\n",
2142
- ioc->name, __func__, karg.unique_id);
2335
+ ioc_err(ioc, "%s: unique_id(0x%08x) is not registered\n",
2336
+ __func__, karg.unique_id);
21432337 return -EINVAL;
21442338 }
21452339
21462340 request_data = ioc->diag_buffer[buffer_type];
21472341 if (!request_data) {
2148
- pr_err(MPT3SAS_FMT
2149
- "%s: doesn't have buffer for buffer_type(0x%02x)\n",
2150
- ioc->name, __func__, buffer_type);
2342
+ ioc_err(ioc, "%s: doesn't have buffer for buffer_type(0x%02x)\n",
2343
+ __func__, buffer_type);
21512344 return -ENOMEM;
21522345 }
21532346
21542347 request_size = ioc->diag_buffer_sz[buffer_type];
21552348
21562349 if ((karg.starting_offset % 4) || (karg.bytes_to_read % 4)) {
2157
- pr_err(MPT3SAS_FMT "%s: either the starting_offset " \
2158
- "or bytes_to_read are not 4 byte aligned\n", ioc->name,
2159
- __func__);
2350
+ ioc_err(ioc, "%s: either the starting_offset or bytes_to_read are not 4 byte aligned\n",
2351
+ __func__);
21602352 return -EINVAL;
21612353 }
21622354
....@@ -2164,10 +2356,10 @@
21642356 return -EINVAL;
21652357
21662358 diag_data = (void *)(request_data + karg.starting_offset);
2167
- dctlprintk(ioc, pr_info(MPT3SAS_FMT
2168
- "%s: diag_buffer(%p), offset(%d), sz(%d)\n",
2169
- ioc->name, __func__,
2170
- diag_data, karg.starting_offset, karg.bytes_to_read));
2359
+ dctlprintk(ioc,
2360
+ ioc_info(ioc, "%s: diag_buffer(%p), offset(%d), sz(%d)\n",
2361
+ __func__, diag_data, karg.starting_offset,
2362
+ karg.bytes_to_read));
21712363
21722364 /* Truncate data on requests that are too large */
21732365 if ((diag_data + karg.bytes_to_read < diag_data) ||
....@@ -2178,39 +2370,36 @@
21782370
21792371 if (copy_to_user((void __user *)uarg->diagnostic_data,
21802372 diag_data, copy_size)) {
2181
- pr_err(MPT3SAS_FMT
2182
- "%s: Unable to write mpt_diag_read_buffer_t data @ %p\n",
2183
- ioc->name, __func__, diag_data);
2373
+ ioc_err(ioc, "%s: Unable to write mpt_diag_read_buffer_t data @ %p\n",
2374
+ __func__, diag_data);
21842375 return -EFAULT;
21852376 }
21862377
21872378 if ((karg.flags & MPT3_FLAGS_REREGISTER) == 0)
21882379 return 0;
21892380
2190
- dctlprintk(ioc, pr_info(MPT3SAS_FMT
2191
- "%s: Reregister buffer_type(0x%02x)\n",
2192
- ioc->name, __func__, buffer_type));
2381
+ dctlprintk(ioc,
2382
+ ioc_info(ioc, "%s: Reregister buffer_type(0x%02x)\n",
2383
+ __func__, buffer_type));
21932384 if ((ioc->diag_buffer_status[buffer_type] &
21942385 MPT3_DIAG_BUFFER_IS_RELEASED) == 0) {
2195
- dctlprintk(ioc, pr_info(MPT3SAS_FMT
2196
- "%s: buffer_type(0x%02x) is still registered\n",
2197
- ioc->name, __func__, buffer_type));
2386
+ dctlprintk(ioc,
2387
+ ioc_info(ioc, "%s: buffer_type(0x%02x) is still registered\n",
2388
+ __func__, buffer_type));
21982389 return 0;
21992390 }
22002391 /* Get a free request frame and save the message context.
22012392 */
22022393
22032394 if (ioc->ctl_cmds.status != MPT3_CMD_NOT_USED) {
2204
- pr_err(MPT3SAS_FMT "%s: ctl_cmd in use\n",
2205
- ioc->name, __func__);
2395
+ ioc_err(ioc, "%s: ctl_cmd in use\n", __func__);
22062396 rc = -EAGAIN;
22072397 goto out;
22082398 }
22092399
22102400 smid = mpt3sas_base_get_smid(ioc, ioc->ctl_cb_idx);
22112401 if (!smid) {
2212
- pr_err(MPT3SAS_FMT "%s: failed obtaining a smid\n",
2213
- ioc->name, __func__);
2402
+ ioc_err(ioc, "%s: failed obtaining a smid\n", __func__);
22142403 rc = -EAGAIN;
22152404 goto out;
22162405 }
....@@ -2234,22 +2423,20 @@
22342423 mpi_request->VP_ID = 0;
22352424
22362425 init_completion(&ioc->ctl_cmds.done);
2237
- mpt3sas_base_put_smid_default(ioc, smid);
2426
+ ioc->put_smid_default(ioc, smid);
22382427 wait_for_completion_timeout(&ioc->ctl_cmds.done,
22392428 MPT3_IOCTL_DEFAULT_TIMEOUT*HZ);
22402429
22412430 if (!(ioc->ctl_cmds.status & MPT3_CMD_COMPLETE)) {
2242
- issue_reset =
2243
- mpt3sas_base_check_cmd_timeout(ioc,
2244
- ioc->ctl_cmds.status, mpi_request,
2245
- sizeof(Mpi2DiagBufferPostRequest_t)/4);
2431
+ mpt3sas_check_cmd_timeout(ioc,
2432
+ ioc->ctl_cmds.status, mpi_request,
2433
+ sizeof(Mpi2DiagBufferPostRequest_t)/4, issue_reset);
22462434 goto issue_host_reset;
22472435 }
22482436
22492437 /* process the completed Reply Message Frame */
22502438 if ((ioc->ctl_cmds.status & MPT3_CMD_REPLY_VALID) == 0) {
2251
- pr_err(MPT3SAS_FMT "%s: no reply message\n",
2252
- ioc->name, __func__);
2439
+ ioc_err(ioc, "%s: no reply message\n", __func__);
22532440 rc = -EFAULT;
22542441 goto out;
22552442 }
....@@ -2260,13 +2447,13 @@
22602447 if (ioc_status == MPI2_IOCSTATUS_SUCCESS) {
22612448 ioc->diag_buffer_status[buffer_type] |=
22622449 MPT3_DIAG_BUFFER_IS_REGISTERED;
2263
- dctlprintk(ioc, pr_info(MPT3SAS_FMT "%s: success\n",
2264
- ioc->name, __func__));
2450
+ ioc->diag_buffer_status[buffer_type] &=
2451
+ ~MPT3_DIAG_BUFFER_IS_RELEASED;
2452
+ dctlprintk(ioc, ioc_info(ioc, "%s: success\n", __func__));
22652453 } else {
2266
- pr_info(MPT3SAS_FMT
2267
- "%s: ioc_status(0x%04x) log_info(0x%08x)\n",
2268
- ioc->name, __func__,
2269
- ioc_status, le32_to_cpu(mpi_reply->IOCLogInfo));
2454
+ ioc_info(ioc, "%s: ioc_status(0x%04x) log_info(0x%08x)\n",
2455
+ __func__, ioc_status,
2456
+ le32_to_cpu(mpi_reply->IOCLogInfo));
22702457 rc = -EFAULT;
22712458 }
22722459
....@@ -2405,6 +2592,10 @@
24052592 break;
24062593 }
24072594
2595
+ if (karg.hdr.ioc_number != ioctl_header.ioc_number) {
2596
+ ret = -EINVAL;
2597
+ break;
2598
+ }
24082599 if (_IOC_SIZE(cmd) == sizeof(struct mpt3_ioctl_command)) {
24092600 uarg = arg;
24102601 ret = _ctl_do_mpt_command(ioc, karg, &uarg->mf);
....@@ -2451,8 +2642,9 @@
24512642 ret = _ctl_diag_read_buffer(ioc, arg);
24522643 break;
24532644 default:
2454
- dctlprintk(ioc, pr_info(MPT3SAS_FMT
2455
- "unsupported ioctl opcode(0x%08x)\n", ioc->name, cmd));
2645
+ dctlprintk(ioc,
2646
+ ioc_info(ioc, "unsupported ioctl opcode(0x%08x)\n",
2647
+ cmd));
24562648 break;
24572649 }
24582650
....@@ -2538,7 +2730,7 @@
25382730
25392731 /* scsi host attributes */
25402732 /**
2541
- * _ctl_version_fw_show - firmware version
2733
+ * version_fw_show - firmware version
25422734 * @cdev: pointer to embedded class device
25432735 * @attr: ?
25442736 * @buf: the buffer returned
....@@ -2546,7 +2738,7 @@
25462738 * A sysfs 'read-only' shost attribute.
25472739 */
25482740 static ssize_t
2549
-_ctl_version_fw_show(struct device *cdev, struct device_attribute *attr,
2741
+version_fw_show(struct device *cdev, struct device_attribute *attr,
25502742 char *buf)
25512743 {
25522744 struct Scsi_Host *shost = class_to_shost(cdev);
....@@ -2558,10 +2750,10 @@
25582750 (ioc->facts.FWVersion.Word & 0x0000FF00) >> 8,
25592751 ioc->facts.FWVersion.Word & 0x000000FF);
25602752 }
2561
-static DEVICE_ATTR(version_fw, S_IRUGO, _ctl_version_fw_show, NULL);
2753
+static DEVICE_ATTR_RO(version_fw);
25622754
25632755 /**
2564
- * _ctl_version_bios_show - bios version
2756
+ * version_bios_show - bios version
25652757 * @cdev: pointer to embedded class device
25662758 * @attr: ?
25672759 * @buf: the buffer returned
....@@ -2569,7 +2761,7 @@
25692761 * A sysfs 'read-only' shost attribute.
25702762 */
25712763 static ssize_t
2572
-_ctl_version_bios_show(struct device *cdev, struct device_attribute *attr,
2764
+version_bios_show(struct device *cdev, struct device_attribute *attr,
25732765 char *buf)
25742766 {
25752767 struct Scsi_Host *shost = class_to_shost(cdev);
....@@ -2583,10 +2775,10 @@
25832775 (version & 0x0000FF00) >> 8,
25842776 version & 0x000000FF);
25852777 }
2586
-static DEVICE_ATTR(version_bios, S_IRUGO, _ctl_version_bios_show, NULL);
2778
+static DEVICE_ATTR_RO(version_bios);
25872779
25882780 /**
2589
- * _ctl_version_mpi_show - MPI (message passing interface) version
2781
+ * version_mpi_show - MPI (message passing interface) version
25902782 * @cdev: pointer to embedded class device
25912783 * @attr: ?
25922784 * @buf: the buffer returned
....@@ -2594,7 +2786,7 @@
25942786 * A sysfs 'read-only' shost attribute.
25952787 */
25962788 static ssize_t
2597
-_ctl_version_mpi_show(struct device *cdev, struct device_attribute *attr,
2789
+version_mpi_show(struct device *cdev, struct device_attribute *attr,
25982790 char *buf)
25992791 {
26002792 struct Scsi_Host *shost = class_to_shost(cdev);
....@@ -2603,10 +2795,10 @@
26032795 return snprintf(buf, PAGE_SIZE, "%03x.%02x\n",
26042796 ioc->facts.MsgVersion, ioc->facts.HeaderVersion >> 8);
26052797 }
2606
-static DEVICE_ATTR(version_mpi, S_IRUGO, _ctl_version_mpi_show, NULL);
2798
+static DEVICE_ATTR_RO(version_mpi);
26072799
26082800 /**
2609
- * _ctl_version_product_show - product name
2801
+ * version_product_show - product name
26102802 * @cdev: pointer to embedded class device
26112803 * @attr: ?
26122804 * @buf: the buffer returned
....@@ -2614,7 +2806,7 @@
26142806 * A sysfs 'read-only' shost attribute.
26152807 */
26162808 static ssize_t
2617
-_ctl_version_product_show(struct device *cdev, struct device_attribute *attr,
2809
+version_product_show(struct device *cdev, struct device_attribute *attr,
26182810 char *buf)
26192811 {
26202812 struct Scsi_Host *shost = class_to_shost(cdev);
....@@ -2622,10 +2814,10 @@
26222814
26232815 return snprintf(buf, 16, "%s\n", ioc->manu_pg0.ChipName);
26242816 }
2625
-static DEVICE_ATTR(version_product, S_IRUGO, _ctl_version_product_show, NULL);
2817
+static DEVICE_ATTR_RO(version_product);
26262818
26272819 /**
2628
- * _ctl_version_nvdata_persistent_show - ndvata persistent version
2820
+ * version_nvdata_persistent_show - ndvata persistent version
26292821 * @cdev: pointer to embedded class device
26302822 * @attr: ?
26312823 * @buf: the buffer returned
....@@ -2633,7 +2825,7 @@
26332825 * A sysfs 'read-only' shost attribute.
26342826 */
26352827 static ssize_t
2636
-_ctl_version_nvdata_persistent_show(struct device *cdev,
2828
+version_nvdata_persistent_show(struct device *cdev,
26372829 struct device_attribute *attr, char *buf)
26382830 {
26392831 struct Scsi_Host *shost = class_to_shost(cdev);
....@@ -2642,11 +2834,10 @@
26422834 return snprintf(buf, PAGE_SIZE, "%08xh\n",
26432835 le32_to_cpu(ioc->iounit_pg0.NvdataVersionPersistent.Word));
26442836 }
2645
-static DEVICE_ATTR(version_nvdata_persistent, S_IRUGO,
2646
- _ctl_version_nvdata_persistent_show, NULL);
2837
+static DEVICE_ATTR_RO(version_nvdata_persistent);
26472838
26482839 /**
2649
- * _ctl_version_nvdata_default_show - nvdata default version
2840
+ * version_nvdata_default_show - nvdata default version
26502841 * @cdev: pointer to embedded class device
26512842 * @attr: ?
26522843 * @buf: the buffer returned
....@@ -2654,7 +2845,7 @@
26542845 * A sysfs 'read-only' shost attribute.
26552846 */
26562847 static ssize_t
2657
-_ctl_version_nvdata_default_show(struct device *cdev, struct device_attribute
2848
+version_nvdata_default_show(struct device *cdev, struct device_attribute
26582849 *attr, char *buf)
26592850 {
26602851 struct Scsi_Host *shost = class_to_shost(cdev);
....@@ -2663,11 +2854,10 @@
26632854 return snprintf(buf, PAGE_SIZE, "%08xh\n",
26642855 le32_to_cpu(ioc->iounit_pg0.NvdataVersionDefault.Word));
26652856 }
2666
-static DEVICE_ATTR(version_nvdata_default, S_IRUGO,
2667
- _ctl_version_nvdata_default_show, NULL);
2857
+static DEVICE_ATTR_RO(version_nvdata_default);
26682858
26692859 /**
2670
- * _ctl_board_name_show - board name
2860
+ * board_name_show - board name
26712861 * @cdev: pointer to embedded class device
26722862 * @attr: ?
26732863 * @buf: the buffer returned
....@@ -2675,7 +2865,7 @@
26752865 * A sysfs 'read-only' shost attribute.
26762866 */
26772867 static ssize_t
2678
-_ctl_board_name_show(struct device *cdev, struct device_attribute *attr,
2868
+board_name_show(struct device *cdev, struct device_attribute *attr,
26792869 char *buf)
26802870 {
26812871 struct Scsi_Host *shost = class_to_shost(cdev);
....@@ -2683,10 +2873,10 @@
26832873
26842874 return snprintf(buf, 16, "%s\n", ioc->manu_pg0.BoardName);
26852875 }
2686
-static DEVICE_ATTR(board_name, S_IRUGO, _ctl_board_name_show, NULL);
2876
+static DEVICE_ATTR_RO(board_name);
26872877
26882878 /**
2689
- * _ctl_board_assembly_show - board assembly name
2879
+ * board_assembly_show - board assembly name
26902880 * @cdev: pointer to embedded class device
26912881 * @attr: ?
26922882 * @buf: the buffer returned
....@@ -2694,7 +2884,7 @@
26942884 * A sysfs 'read-only' shost attribute.
26952885 */
26962886 static ssize_t
2697
-_ctl_board_assembly_show(struct device *cdev, struct device_attribute *attr,
2887
+board_assembly_show(struct device *cdev, struct device_attribute *attr,
26982888 char *buf)
26992889 {
27002890 struct Scsi_Host *shost = class_to_shost(cdev);
....@@ -2702,10 +2892,10 @@
27022892
27032893 return snprintf(buf, 16, "%s\n", ioc->manu_pg0.BoardAssembly);
27042894 }
2705
-static DEVICE_ATTR(board_assembly, S_IRUGO, _ctl_board_assembly_show, NULL);
2895
+static DEVICE_ATTR_RO(board_assembly);
27062896
27072897 /**
2708
- * _ctl_board_tracer_show - board tracer number
2898
+ * board_tracer_show - board tracer number
27092899 * @cdev: pointer to embedded class device
27102900 * @attr: ?
27112901 * @buf: the buffer returned
....@@ -2713,7 +2903,7 @@
27132903 * A sysfs 'read-only' shost attribute.
27142904 */
27152905 static ssize_t
2716
-_ctl_board_tracer_show(struct device *cdev, struct device_attribute *attr,
2906
+board_tracer_show(struct device *cdev, struct device_attribute *attr,
27172907 char *buf)
27182908 {
27192909 struct Scsi_Host *shost = class_to_shost(cdev);
....@@ -2721,10 +2911,10 @@
27212911
27222912 return snprintf(buf, 16, "%s\n", ioc->manu_pg0.BoardTracerNumber);
27232913 }
2724
-static DEVICE_ATTR(board_tracer, S_IRUGO, _ctl_board_tracer_show, NULL);
2914
+static DEVICE_ATTR_RO(board_tracer);
27252915
27262916 /**
2727
- * _ctl_io_delay_show - io missing delay
2917
+ * io_delay_show - io missing delay
27282918 * @cdev: pointer to embedded class device
27292919 * @attr: ?
27302920 * @buf: the buffer returned
....@@ -2735,7 +2925,7 @@
27352925 * A sysfs 'read-only' shost attribute.
27362926 */
27372927 static ssize_t
2738
-_ctl_io_delay_show(struct device *cdev, struct device_attribute *attr,
2928
+io_delay_show(struct device *cdev, struct device_attribute *attr,
27392929 char *buf)
27402930 {
27412931 struct Scsi_Host *shost = class_to_shost(cdev);
....@@ -2743,10 +2933,10 @@
27432933
27442934 return snprintf(buf, PAGE_SIZE, "%02d\n", ioc->io_missing_delay);
27452935 }
2746
-static DEVICE_ATTR(io_delay, S_IRUGO, _ctl_io_delay_show, NULL);
2936
+static DEVICE_ATTR_RO(io_delay);
27472937
27482938 /**
2749
- * _ctl_device_delay_show - device missing delay
2939
+ * device_delay_show - device missing delay
27502940 * @cdev: pointer to embedded class device
27512941 * @attr: ?
27522942 * @buf: the buffer returned
....@@ -2757,7 +2947,7 @@
27572947 * A sysfs 'read-only' shost attribute.
27582948 */
27592949 static ssize_t
2760
-_ctl_device_delay_show(struct device *cdev, struct device_attribute *attr,
2950
+device_delay_show(struct device *cdev, struct device_attribute *attr,
27612951 char *buf)
27622952 {
27632953 struct Scsi_Host *shost = class_to_shost(cdev);
....@@ -2765,10 +2955,10 @@
27652955
27662956 return snprintf(buf, PAGE_SIZE, "%02d\n", ioc->device_missing_delay);
27672957 }
2768
-static DEVICE_ATTR(device_delay, S_IRUGO, _ctl_device_delay_show, NULL);
2958
+static DEVICE_ATTR_RO(device_delay);
27692959
27702960 /**
2771
- * _ctl_fw_queue_depth_show - global credits
2961
+ * fw_queue_depth_show - global credits
27722962 * @cdev: pointer to embedded class device
27732963 * @attr: ?
27742964 * @buf: the buffer returned
....@@ -2778,7 +2968,7 @@
27782968 * A sysfs 'read-only' shost attribute.
27792969 */
27802970 static ssize_t
2781
-_ctl_fw_queue_depth_show(struct device *cdev, struct device_attribute *attr,
2971
+fw_queue_depth_show(struct device *cdev, struct device_attribute *attr,
27822972 char *buf)
27832973 {
27842974 struct Scsi_Host *shost = class_to_shost(cdev);
....@@ -2786,10 +2976,10 @@
27862976
27872977 return snprintf(buf, PAGE_SIZE, "%02d\n", ioc->facts.RequestCredit);
27882978 }
2789
-static DEVICE_ATTR(fw_queue_depth, S_IRUGO, _ctl_fw_queue_depth_show, NULL);
2979
+static DEVICE_ATTR_RO(fw_queue_depth);
27902980
27912981 /**
2792
- * _ctl_sas_address_show - sas address
2982
+ * sas_address_show - sas address
27932983 * @cdev: pointer to embedded class device
27942984 * @attr: ?
27952985 * @buf: the buffer returned
....@@ -2799,7 +2989,7 @@
27992989 * A sysfs 'read-only' shost attribute.
28002990 */
28012991 static ssize_t
2802
-_ctl_host_sas_address_show(struct device *cdev, struct device_attribute *attr,
2992
+host_sas_address_show(struct device *cdev, struct device_attribute *attr,
28032993 char *buf)
28042994
28052995 {
....@@ -2809,11 +2999,10 @@
28092999 return snprintf(buf, PAGE_SIZE, "0x%016llx\n",
28103000 (unsigned long long)ioc->sas_hba.sas_address);
28113001 }
2812
-static DEVICE_ATTR(host_sas_address, S_IRUGO,
2813
- _ctl_host_sas_address_show, NULL);
3002
+static DEVICE_ATTR_RO(host_sas_address);
28143003
28153004 /**
2816
- * _ctl_logging_level_show - logging level
3005
+ * logging_level_show - logging level
28173006 * @cdev: pointer to embedded class device
28183007 * @attr: ?
28193008 * @buf: the buffer returned
....@@ -2821,7 +3010,7 @@
28213010 * A sysfs 'read/write' shost attribute.
28223011 */
28233012 static ssize_t
2824
-_ctl_logging_level_show(struct device *cdev, struct device_attribute *attr,
3013
+logging_level_show(struct device *cdev, struct device_attribute *attr,
28253014 char *buf)
28263015 {
28273016 struct Scsi_Host *shost = class_to_shost(cdev);
....@@ -2830,7 +3019,7 @@
28303019 return snprintf(buf, PAGE_SIZE, "%08xh\n", ioc->logging_level);
28313020 }
28323021 static ssize_t
2833
-_ctl_logging_level_store(struct device *cdev, struct device_attribute *attr,
3022
+logging_level_store(struct device *cdev, struct device_attribute *attr,
28343023 const char *buf, size_t count)
28353024 {
28363025 struct Scsi_Host *shost = class_to_shost(cdev);
....@@ -2841,15 +3030,14 @@
28413030 return -EINVAL;
28423031
28433032 ioc->logging_level = val;
2844
- pr_info(MPT3SAS_FMT "logging_level=%08xh\n", ioc->name,
2845
- ioc->logging_level);
3033
+ ioc_info(ioc, "logging_level=%08xh\n",
3034
+ ioc->logging_level);
28463035 return strlen(buf);
28473036 }
2848
-static DEVICE_ATTR(logging_level, S_IRUGO | S_IWUSR, _ctl_logging_level_show,
2849
- _ctl_logging_level_store);
3037
+static DEVICE_ATTR_RW(logging_level);
28503038
28513039 /**
2852
- * _ctl_fwfault_debug_show - show/store fwfault_debug
3040
+ * fwfault_debug_show - show/store fwfault_debug
28533041 * @cdev: pointer to embedded class device
28543042 * @attr: ?
28553043 * @buf: the buffer returned
....@@ -2858,7 +3046,7 @@
28583046 * A sysfs 'read/write' shost attribute.
28593047 */
28603048 static ssize_t
2861
-_ctl_fwfault_debug_show(struct device *cdev, struct device_attribute *attr,
3049
+fwfault_debug_show(struct device *cdev, struct device_attribute *attr,
28623050 char *buf)
28633051 {
28643052 struct Scsi_Host *shost = class_to_shost(cdev);
....@@ -2867,7 +3055,7 @@
28673055 return snprintf(buf, PAGE_SIZE, "%d\n", ioc->fwfault_debug);
28683056 }
28693057 static ssize_t
2870
-_ctl_fwfault_debug_store(struct device *cdev, struct device_attribute *attr,
3058
+fwfault_debug_store(struct device *cdev, struct device_attribute *attr,
28713059 const char *buf, size_t count)
28723060 {
28733061 struct Scsi_Host *shost = class_to_shost(cdev);
....@@ -2878,15 +3066,14 @@
28783066 return -EINVAL;
28793067
28803068 ioc->fwfault_debug = val;
2881
- pr_info(MPT3SAS_FMT "fwfault_debug=%d\n", ioc->name,
2882
- ioc->fwfault_debug);
3069
+ ioc_info(ioc, "fwfault_debug=%d\n",
3070
+ ioc->fwfault_debug);
28833071 return strlen(buf);
28843072 }
2885
-static DEVICE_ATTR(fwfault_debug, S_IRUGO | S_IWUSR,
2886
- _ctl_fwfault_debug_show, _ctl_fwfault_debug_store);
3073
+static DEVICE_ATTR_RW(fwfault_debug);
28873074
28883075 /**
2889
- * _ctl_ioc_reset_count_show - ioc reset count
3076
+ * ioc_reset_count_show - ioc reset count
28903077 * @cdev: pointer to embedded class device
28913078 * @attr: ?
28923079 * @buf: the buffer returned
....@@ -2896,7 +3083,7 @@
28963083 * A sysfs 'read-only' shost attribute.
28973084 */
28983085 static ssize_t
2899
-_ctl_ioc_reset_count_show(struct device *cdev, struct device_attribute *attr,
3086
+ioc_reset_count_show(struct device *cdev, struct device_attribute *attr,
29003087 char *buf)
29013088 {
29023089 struct Scsi_Host *shost = class_to_shost(cdev);
....@@ -2904,10 +3091,10 @@
29043091
29053092 return snprintf(buf, PAGE_SIZE, "%d\n", ioc->ioc_reset_count);
29063093 }
2907
-static DEVICE_ATTR(ioc_reset_count, S_IRUGO, _ctl_ioc_reset_count_show, NULL);
3094
+static DEVICE_ATTR_RO(ioc_reset_count);
29083095
29093096 /**
2910
- * _ctl_ioc_reply_queue_count_show - number of reply queues
3097
+ * reply_queue_count_show - number of reply queues
29113098 * @cdev: pointer to embedded class device
29123099 * @attr: ?
29133100 * @buf: the buffer returned
....@@ -2917,7 +3104,7 @@
29173104 * A sysfs 'read-only' shost attribute.
29183105 */
29193106 static ssize_t
2920
-_ctl_ioc_reply_queue_count_show(struct device *cdev,
3107
+reply_queue_count_show(struct device *cdev,
29213108 struct device_attribute *attr, char *buf)
29223109 {
29233110 u8 reply_queue_count;
....@@ -2932,11 +3119,10 @@
29323119
29333120 return snprintf(buf, PAGE_SIZE, "%d\n", reply_queue_count);
29343121 }
2935
-static DEVICE_ATTR(reply_queue_count, S_IRUGO, _ctl_ioc_reply_queue_count_show,
2936
- NULL);
3122
+static DEVICE_ATTR_RO(reply_queue_count);
29373123
29383124 /**
2939
- * _ctl_BRM_status_show - Backup Rail Monitor Status
3125
+ * BRM_status_show - Backup Rail Monitor Status
29403126 * @cdev: pointer to embedded class device
29413127 * @attr: ?
29423128 * @buf: the buffer returned
....@@ -2946,7 +3132,7 @@
29463132 * A sysfs 'read-only' shost attribute.
29473133 */
29483134 static ssize_t
2949
-_ctl_BRM_status_show(struct device *cdev, struct device_attribute *attr,
3135
+BRM_status_show(struct device *cdev, struct device_attribute *attr,
29503136 char *buf)
29513137 {
29523138 struct Scsi_Host *shost = class_to_shost(cdev);
....@@ -2959,45 +3145,45 @@
29593145 ssize_t rc = 0;
29603146
29613147 if (!ioc->is_warpdrive) {
2962
- pr_err(MPT3SAS_FMT "%s: BRM attribute is only for"
2963
- " warpdrive\n", ioc->name, __func__);
2964
- goto out;
3148
+ ioc_err(ioc, "%s: BRM attribute is only for warpdrive\n",
3149
+ __func__);
3150
+ return 0;
29653151 }
29663152 /* pci_access_mutex lock acquired by sysfs show path */
29673153 mutex_lock(&ioc->pci_access_mutex);
2968
- if (ioc->pci_error_recovery || ioc->remove_host) {
2969
- mutex_unlock(&ioc->pci_access_mutex);
2970
- return 0;
2971
- }
3154
+ if (ioc->pci_error_recovery || ioc->remove_host)
3155
+ goto out;
29723156
29733157 /* allocate upto GPIOVal 36 entries */
29743158 sz = offsetof(Mpi2IOUnitPage3_t, GPIOVal) + (sizeof(u16) * 36);
29753159 io_unit_pg3 = kzalloc(sz, GFP_KERNEL);
29763160 if (!io_unit_pg3) {
2977
- pr_err(MPT3SAS_FMT "%s: failed allocating memory "
2978
- "for iounit_pg3: (%d) bytes\n", ioc->name, __func__, sz);
3161
+ rc = -ENOMEM;
3162
+ ioc_err(ioc, "%s: failed allocating memory for iounit_pg3: (%d) bytes\n",
3163
+ __func__, sz);
29793164 goto out;
29803165 }
29813166
29823167 if (mpt3sas_config_get_iounit_pg3(ioc, &mpi_reply, io_unit_pg3, sz) !=
29833168 0) {
2984
- pr_err(MPT3SAS_FMT
2985
- "%s: failed reading iounit_pg3\n", ioc->name,
2986
- __func__);
3169
+ ioc_err(ioc, "%s: failed reading iounit_pg3\n",
3170
+ __func__);
3171
+ rc = -EINVAL;
29873172 goto out;
29883173 }
29893174
29903175 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & MPI2_IOCSTATUS_MASK;
29913176 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
2992
- pr_err(MPT3SAS_FMT "%s: iounit_pg3 failed with "
2993
- "ioc_status(0x%04x)\n", ioc->name, __func__, ioc_status);
3177
+ ioc_err(ioc, "%s: iounit_pg3 failed with ioc_status(0x%04x)\n",
3178
+ __func__, ioc_status);
3179
+ rc = -EINVAL;
29943180 goto out;
29953181 }
29963182
29973183 if (io_unit_pg3->GPIOCount < 25) {
2998
- pr_err(MPT3SAS_FMT "%s: iounit_pg3->GPIOCount less than "
2999
- "25 entries, detected (%d) entries\n", ioc->name, __func__,
3000
- io_unit_pg3->GPIOCount);
3184
+ ioc_err(ioc, "%s: iounit_pg3->GPIOCount less than 25 entries, detected (%d) entries\n",
3185
+ __func__, io_unit_pg3->GPIOCount);
3186
+ rc = -EINVAL;
30013187 goto out;
30023188 }
30033189
....@@ -3010,7 +3196,7 @@
30103196 mutex_unlock(&ioc->pci_access_mutex);
30113197 return rc;
30123198 }
3013
-static DEVICE_ATTR(BRM_status, S_IRUGO, _ctl_BRM_status_show, NULL);
3199
+static DEVICE_ATTR_RO(BRM_status);
30143200
30153201 struct DIAG_BUFFER_START {
30163202 __le32 Size;
....@@ -3023,7 +3209,7 @@
30233209 };
30243210
30253211 /**
3026
- * _ctl_host_trace_buffer_size_show - host buffer size (trace only)
3212
+ * host_trace_buffer_size_show - host buffer size (trace only)
30273213 * @cdev: pointer to embedded class device
30283214 * @attr: ?
30293215 * @buf: the buffer returned
....@@ -3031,7 +3217,7 @@
30313217 * A sysfs 'read-only' shost attribute.
30323218 */
30333219 static ssize_t
3034
-_ctl_host_trace_buffer_size_show(struct device *cdev,
3220
+host_trace_buffer_size_show(struct device *cdev,
30353221 struct device_attribute *attr, char *buf)
30363222 {
30373223 struct Scsi_Host *shost = class_to_shost(cdev);
....@@ -3040,17 +3226,15 @@
30403226 struct DIAG_BUFFER_START *request_data;
30413227
30423228 if (!ioc->diag_buffer[MPI2_DIAG_BUF_TYPE_TRACE]) {
3043
- pr_err(MPT3SAS_FMT
3044
- "%s: host_trace_buffer is not registered\n",
3045
- ioc->name, __func__);
3229
+ ioc_err(ioc, "%s: host_trace_buffer is not registered\n",
3230
+ __func__);
30463231 return 0;
30473232 }
30483233
30493234 if ((ioc->diag_buffer_status[MPI2_DIAG_BUF_TYPE_TRACE] &
30503235 MPT3_DIAG_BUFFER_IS_REGISTERED) == 0) {
3051
- pr_err(MPT3SAS_FMT
3052
- "%s: host_trace_buffer is not registered\n",
3053
- ioc->name, __func__);
3236
+ ioc_err(ioc, "%s: host_trace_buffer is not registered\n",
3237
+ __func__);
30543238 return 0;
30553239 }
30563240
....@@ -3065,11 +3249,10 @@
30653249 ioc->ring_buffer_sz = size;
30663250 return snprintf(buf, PAGE_SIZE, "%d\n", size);
30673251 }
3068
-static DEVICE_ATTR(host_trace_buffer_size, S_IRUGO,
3069
- _ctl_host_trace_buffer_size_show, NULL);
3252
+static DEVICE_ATTR_RO(host_trace_buffer_size);
30703253
30713254 /**
3072
- * _ctl_host_trace_buffer_show - firmware ring buffer (trace only)
3255
+ * host_trace_buffer_show - firmware ring buffer (trace only)
30733256 * @cdev: pointer to embedded class device
30743257 * @attr: ?
30753258 * @buf: the buffer returned
....@@ -3081,7 +3264,7 @@
30813264 * offset to the same attribute, it will move the pointer.
30823265 */
30833266 static ssize_t
3084
-_ctl_host_trace_buffer_show(struct device *cdev, struct device_attribute *attr,
3267
+host_trace_buffer_show(struct device *cdev, struct device_attribute *attr,
30853268 char *buf)
30863269 {
30873270 struct Scsi_Host *shost = class_to_shost(cdev);
....@@ -3090,17 +3273,15 @@
30903273 u32 size;
30913274
30923275 if (!ioc->diag_buffer[MPI2_DIAG_BUF_TYPE_TRACE]) {
3093
- pr_err(MPT3SAS_FMT
3094
- "%s: host_trace_buffer is not registered\n",
3095
- ioc->name, __func__);
3276
+ ioc_err(ioc, "%s: host_trace_buffer is not registered\n",
3277
+ __func__);
30963278 return 0;
30973279 }
30983280
30993281 if ((ioc->diag_buffer_status[MPI2_DIAG_BUF_TYPE_TRACE] &
31003282 MPT3_DIAG_BUFFER_IS_REGISTERED) == 0) {
3101
- pr_err(MPT3SAS_FMT
3102
- "%s: host_trace_buffer is not registered\n",
3103
- ioc->name, __func__);
3283
+ ioc_err(ioc, "%s: host_trace_buffer is not registered\n",
3284
+ __func__);
31043285 return 0;
31053286 }
31063287
....@@ -3115,7 +3296,7 @@
31153296 }
31163297
31173298 static ssize_t
3118
-_ctl_host_trace_buffer_store(struct device *cdev, struct device_attribute *attr,
3299
+host_trace_buffer_store(struct device *cdev, struct device_attribute *attr,
31193300 const char *buf, size_t count)
31203301 {
31213302 struct Scsi_Host *shost = class_to_shost(cdev);
....@@ -3128,14 +3309,13 @@
31283309 ioc->ring_buffer_offset = val;
31293310 return strlen(buf);
31303311 }
3131
-static DEVICE_ATTR(host_trace_buffer, S_IRUGO | S_IWUSR,
3132
- _ctl_host_trace_buffer_show, _ctl_host_trace_buffer_store);
3312
+static DEVICE_ATTR_RW(host_trace_buffer);
31333313
31343314
31353315 /*****************************************/
31363316
31373317 /**
3138
- * _ctl_host_trace_buffer_enable_show - firmware ring buffer (trace only)
3318
+ * host_trace_buffer_enable_show - firmware ring buffer (trace only)
31393319 * @cdev: pointer to embedded class device
31403320 * @attr: ?
31413321 * @buf: the buffer returned
....@@ -3145,7 +3325,7 @@
31453325 * This is a mechnism to post/release host_trace_buffers
31463326 */
31473327 static ssize_t
3148
-_ctl_host_trace_buffer_enable_show(struct device *cdev,
3328
+host_trace_buffer_enable_show(struct device *cdev,
31493329 struct device_attribute *attr, char *buf)
31503330 {
31513331 struct Scsi_Host *shost = class_to_shost(cdev);
....@@ -3163,7 +3343,7 @@
31633343 }
31643344
31653345 static ssize_t
3166
-_ctl_host_trace_buffer_enable_store(struct device *cdev,
3346
+host_trace_buffer_enable_store(struct device *cdev,
31673347 struct device_attribute *attr, const char *buf, size_t count)
31683348 {
31693349 struct Scsi_Host *shost = class_to_shost(cdev);
....@@ -3189,13 +3369,49 @@
31893369 MPT3_DIAG_BUFFER_IS_RELEASED) == 0))
31903370 goto out;
31913371 memset(&diag_register, 0, sizeof(struct mpt3_diag_register));
3192
- pr_info(MPT3SAS_FMT "posting host trace buffers\n",
3193
- ioc->name);
3372
+ ioc_info(ioc, "posting host trace buffers\n");
31943373 diag_register.buffer_type = MPI2_DIAG_BUF_TYPE_TRACE;
3195
- diag_register.requested_buffer_size = (1024 * 1024);
3196
- diag_register.unique_id = 0x7075900;
3374
+
3375
+ if (ioc->manu_pg11.HostTraceBufferMaxSizeKB != 0 &&
3376
+ ioc->diag_buffer_sz[MPI2_DIAG_BUF_TYPE_TRACE] != 0) {
3377
+ /* post the same buffer allocated previously */
3378
+ diag_register.requested_buffer_size =
3379
+ ioc->diag_buffer_sz[MPI2_DIAG_BUF_TYPE_TRACE];
3380
+ } else {
3381
+ /*
3382
+ * Free the diag buffer memory which was previously
3383
+ * allocated by an application.
3384
+ */
3385
+ if ((ioc->diag_buffer_sz[MPI2_DIAG_BUF_TYPE_TRACE] != 0)
3386
+ &&
3387
+ (ioc->diag_buffer_status[MPI2_DIAG_BUF_TYPE_TRACE] &
3388
+ MPT3_DIAG_BUFFER_IS_APP_OWNED)) {
3389
+ dma_free_coherent(&ioc->pdev->dev,
3390
+ ioc->diag_buffer_sz[MPI2_DIAG_BUF_TYPE_TRACE],
3391
+ ioc->diag_buffer[MPI2_DIAG_BUF_TYPE_TRACE],
3392
+ ioc->diag_buffer_dma[MPI2_DIAG_BUF_TYPE_TRACE]);
3393
+ ioc->diag_buffer[MPI2_DIAG_BUF_TYPE_TRACE] =
3394
+ NULL;
3395
+ }
3396
+
3397
+ diag_register.requested_buffer_size = (1024 * 1024);
3398
+ }
3399
+
3400
+ diag_register.unique_id =
3401
+ (ioc->hba_mpi_version_belonged == MPI2_VERSION) ?
3402
+ (MPT2DIAGBUFFUNIQUEID):(MPT3DIAGBUFFUNIQUEID);
31973403 ioc->diag_buffer_status[MPI2_DIAG_BUF_TYPE_TRACE] = 0;
31983404 _ctl_diag_register_2(ioc, &diag_register);
3405
+ if (ioc->diag_buffer_status[MPI2_DIAG_BUF_TYPE_TRACE] &
3406
+ MPT3_DIAG_BUFFER_IS_REGISTERED) {
3407
+ ioc_info(ioc,
3408
+ "Trace buffer %d KB allocated through sysfs\n",
3409
+ diag_register.requested_buffer_size>>10);
3410
+ if (ioc->hba_mpi_version_belonged != MPI2_VERSION)
3411
+ ioc->diag_buffer_status[
3412
+ MPI2_DIAG_BUF_TYPE_TRACE] |=
3413
+ MPT3_DIAG_BUFFER_IS_DRIVER_ALLOCATED;
3414
+ }
31993415 } else if (!strcmp(str, "release")) {
32003416 /* exit out if host buffers are already released */
32013417 if (!ioc->diag_buffer[MPI2_DIAG_BUF_TYPE_TRACE])
....@@ -3206,8 +3422,7 @@
32063422 if ((ioc->diag_buffer_status[MPI2_DIAG_BUF_TYPE_TRACE] &
32073423 MPT3_DIAG_BUFFER_IS_RELEASED))
32083424 goto out;
3209
- pr_info(MPT3SAS_FMT "releasing host trace buffer\n",
3210
- ioc->name);
3425
+ ioc_info(ioc, "releasing host trace buffer\n");
32113426 mpt3sas_send_diag_release(ioc, MPI2_DIAG_BUF_TYPE_TRACE,
32123427 &issue_reset);
32133428 }
....@@ -3215,14 +3430,12 @@
32153430 out:
32163431 return strlen(buf);
32173432 }
3218
-static DEVICE_ATTR(host_trace_buffer_enable, S_IRUGO | S_IWUSR,
3219
- _ctl_host_trace_buffer_enable_show,
3220
- _ctl_host_trace_buffer_enable_store);
3433
+static DEVICE_ATTR_RW(host_trace_buffer_enable);
32213434
32223435 /*********** diagnostic trigger suppport *********************************/
32233436
32243437 /**
3225
- * _ctl_diag_trigger_master_show - show the diag_trigger_master attribute
3438
+ * diag_trigger_master_show - show the diag_trigger_master attribute
32263439 * @cdev: pointer to embedded class device
32273440 * @attr: ?
32283441 * @buf: the buffer returned
....@@ -3230,7 +3443,7 @@
32303443 * A sysfs 'read/write' shost attribute.
32313444 */
32323445 static ssize_t
3233
-_ctl_diag_trigger_master_show(struct device *cdev,
3446
+diag_trigger_master_show(struct device *cdev,
32343447 struct device_attribute *attr, char *buf)
32353448
32363449 {
....@@ -3247,7 +3460,7 @@
32473460 }
32483461
32493462 /**
3250
- * _ctl_diag_trigger_master_store - store the diag_trigger_master attribute
3463
+ * diag_trigger_master_store - store the diag_trigger_master attribute
32513464 * @cdev: pointer to embedded class device
32523465 * @attr: ?
32533466 * @buf: the buffer returned
....@@ -3256,7 +3469,7 @@
32563469 * A sysfs 'read/write' shost attribute.
32573470 */
32583471 static ssize_t
3259
-_ctl_diag_trigger_master_store(struct device *cdev,
3472
+diag_trigger_master_store(struct device *cdev,
32603473 struct device_attribute *attr, const char *buf, size_t count)
32613474
32623475 {
....@@ -3275,12 +3488,11 @@
32753488 spin_unlock_irqrestore(&ioc->diag_trigger_lock, flags);
32763489 return rc;
32773490 }
3278
-static DEVICE_ATTR(diag_trigger_master, S_IRUGO | S_IWUSR,
3279
- _ctl_diag_trigger_master_show, _ctl_diag_trigger_master_store);
3491
+static DEVICE_ATTR_RW(diag_trigger_master);
32803492
32813493
32823494 /**
3283
- * _ctl_diag_trigger_event_show - show the diag_trigger_event attribute
3495
+ * diag_trigger_event_show - show the diag_trigger_event attribute
32843496 * @cdev: pointer to embedded class device
32853497 * @attr: ?
32863498 * @buf: the buffer returned
....@@ -3288,7 +3500,7 @@
32883500 * A sysfs 'read/write' shost attribute.
32893501 */
32903502 static ssize_t
3291
-_ctl_diag_trigger_event_show(struct device *cdev,
3503
+diag_trigger_event_show(struct device *cdev,
32923504 struct device_attribute *attr, char *buf)
32933505 {
32943506 struct Scsi_Host *shost = class_to_shost(cdev);
....@@ -3304,7 +3516,7 @@
33043516 }
33053517
33063518 /**
3307
- * _ctl_diag_trigger_event_store - store the diag_trigger_event attribute
3519
+ * diag_trigger_event_store - store the diag_trigger_event attribute
33083520 * @cdev: pointer to embedded class device
33093521 * @attr: ?
33103522 * @buf: the buffer returned
....@@ -3313,7 +3525,7 @@
33133525 * A sysfs 'read/write' shost attribute.
33143526 */
33153527 static ssize_t
3316
-_ctl_diag_trigger_event_store(struct device *cdev,
3528
+diag_trigger_event_store(struct device *cdev,
33173529 struct device_attribute *attr, const char *buf, size_t count)
33183530
33193531 {
....@@ -3332,12 +3544,11 @@
33323544 spin_unlock_irqrestore(&ioc->diag_trigger_lock, flags);
33333545 return sz;
33343546 }
3335
-static DEVICE_ATTR(diag_trigger_event, S_IRUGO | S_IWUSR,
3336
- _ctl_diag_trigger_event_show, _ctl_diag_trigger_event_store);
3547
+static DEVICE_ATTR_RW(diag_trigger_event);
33373548
33383549
33393550 /**
3340
- * _ctl_diag_trigger_scsi_show - show the diag_trigger_scsi attribute
3551
+ * diag_trigger_scsi_show - show the diag_trigger_scsi attribute
33413552 * @cdev: pointer to embedded class device
33423553 * @attr: ?
33433554 * @buf: the buffer returned
....@@ -3345,7 +3556,7 @@
33453556 * A sysfs 'read/write' shost attribute.
33463557 */
33473558 static ssize_t
3348
-_ctl_diag_trigger_scsi_show(struct device *cdev,
3559
+diag_trigger_scsi_show(struct device *cdev,
33493560 struct device_attribute *attr, char *buf)
33503561 {
33513562 struct Scsi_Host *shost = class_to_shost(cdev);
....@@ -3361,7 +3572,7 @@
33613572 }
33623573
33633574 /**
3364
- * _ctl_diag_trigger_scsi_store - store the diag_trigger_scsi attribute
3575
+ * diag_trigger_scsi_store - store the diag_trigger_scsi attribute
33653576 * @cdev: pointer to embedded class device
33663577 * @attr: ?
33673578 * @buf: the buffer returned
....@@ -3370,7 +3581,7 @@
33703581 * A sysfs 'read/write' shost attribute.
33713582 */
33723583 static ssize_t
3373
-_ctl_diag_trigger_scsi_store(struct device *cdev,
3584
+diag_trigger_scsi_store(struct device *cdev,
33743585 struct device_attribute *attr, const char *buf, size_t count)
33753586 {
33763587 struct Scsi_Host *shost = class_to_shost(cdev);
....@@ -3379,21 +3590,19 @@
33793590 ssize_t sz;
33803591
33813592 spin_lock_irqsave(&ioc->diag_trigger_lock, flags);
3382
- sz = min(sizeof(struct SL_WH_SCSI_TRIGGERS_T), count);
3383
- memset(&ioc->diag_trigger_scsi, 0,
3384
- sizeof(struct SL_WH_EVENT_TRIGGERS_T));
3593
+ sz = min(sizeof(ioc->diag_trigger_scsi), count);
3594
+ memset(&ioc->diag_trigger_scsi, 0, sizeof(ioc->diag_trigger_scsi));
33853595 memcpy(&ioc->diag_trigger_scsi, buf, sz);
33863596 if (ioc->diag_trigger_scsi.ValidEntries > NUM_VALID_ENTRIES)
33873597 ioc->diag_trigger_scsi.ValidEntries = NUM_VALID_ENTRIES;
33883598 spin_unlock_irqrestore(&ioc->diag_trigger_lock, flags);
33893599 return sz;
33903600 }
3391
-static DEVICE_ATTR(diag_trigger_scsi, S_IRUGO | S_IWUSR,
3392
- _ctl_diag_trigger_scsi_show, _ctl_diag_trigger_scsi_store);
3601
+static DEVICE_ATTR_RW(diag_trigger_scsi);
33933602
33943603
33953604 /**
3396
- * _ctl_diag_trigger_scsi_show - show the diag_trigger_mpi attribute
3605
+ * diag_trigger_scsi_show - show the diag_trigger_mpi attribute
33973606 * @cdev: pointer to embedded class device
33983607 * @attr: ?
33993608 * @buf: the buffer returned
....@@ -3401,7 +3610,7 @@
34013610 * A sysfs 'read/write' shost attribute.
34023611 */
34033612 static ssize_t
3404
-_ctl_diag_trigger_mpi_show(struct device *cdev,
3613
+diag_trigger_mpi_show(struct device *cdev,
34053614 struct device_attribute *attr, char *buf)
34063615 {
34073616 struct Scsi_Host *shost = class_to_shost(cdev);
....@@ -3417,7 +3626,7 @@
34173626 }
34183627
34193628 /**
3420
- * _ctl_diag_trigger_mpi_store - store the diag_trigger_mpi attribute
3629
+ * diag_trigger_mpi_store - store the diag_trigger_mpi attribute
34213630 * @cdev: pointer to embedded class device
34223631 * @attr: ?
34233632 * @buf: the buffer returned
....@@ -3426,7 +3635,7 @@
34263635 * A sysfs 'read/write' shost attribute.
34273636 */
34283637 static ssize_t
3429
-_ctl_diag_trigger_mpi_store(struct device *cdev,
3638
+diag_trigger_mpi_store(struct device *cdev,
34303639 struct device_attribute *attr, const char *buf, size_t count)
34313640 {
34323641 struct Scsi_Host *shost = class_to_shost(cdev);
....@@ -3445,12 +3654,134 @@
34453654 return sz;
34463655 }
34473656
3448
-static DEVICE_ATTR(diag_trigger_mpi, S_IRUGO | S_IWUSR,
3449
- _ctl_diag_trigger_mpi_show, _ctl_diag_trigger_mpi_store);
3657
+static DEVICE_ATTR_RW(diag_trigger_mpi);
34503658
34513659 /*********** diagnostic trigger suppport *** END ****************************/
34523660
34533661 /*****************************************/
3662
+
3663
+/**
3664
+ * drv_support_bitmap_show - driver supported feature bitmap
3665
+ * @cdev: pointer to embedded class device
3666
+ * @attr: unused
3667
+ * @buf: the buffer returned
3668
+ *
3669
+ * A sysfs 'read-only' shost attribute.
3670
+ */
3671
+static ssize_t
3672
+drv_support_bitmap_show(struct device *cdev,
3673
+ struct device_attribute *attr, char *buf)
3674
+{
3675
+ struct Scsi_Host *shost = class_to_shost(cdev);
3676
+ struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
3677
+
3678
+ return snprintf(buf, PAGE_SIZE, "0x%08x\n", ioc->drv_support_bitmap);
3679
+}
3680
+static DEVICE_ATTR_RO(drv_support_bitmap);
3681
+
3682
+/**
3683
+ * enable_sdev_max_qd_show - display whether sdev max qd is enabled/disabled
3684
+ * @cdev: pointer to embedded class device
3685
+ * @attr: unused
3686
+ * @buf: the buffer returned
3687
+ *
3688
+ * A sysfs read/write shost attribute. This attribute is used to set the
3689
+ * targets queue depth to HBA IO queue depth if this attribute is enabled.
3690
+ */
3691
+static ssize_t
3692
+enable_sdev_max_qd_show(struct device *cdev,
3693
+ struct device_attribute *attr, char *buf)
3694
+{
3695
+ struct Scsi_Host *shost = class_to_shost(cdev);
3696
+ struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
3697
+
3698
+ return snprintf(buf, PAGE_SIZE, "%d\n", ioc->enable_sdev_max_qd);
3699
+}
3700
+
3701
+/**
3702
+ * enable_sdev_max_qd_store - Enable/disable sdev max qd
3703
+ * @cdev: pointer to embedded class device
3704
+ * @attr: unused
3705
+ * @buf: the buffer returned
3706
+ * @count: unused
3707
+ *
3708
+ * A sysfs read/write shost attribute. This attribute is used to set the
3709
+ * targets queue depth to HBA IO queue depth if this attribute is enabled.
3710
+ * If this attribute is disabled then targets will have corresponding default
3711
+ * queue depth.
3712
+ */
3713
+static ssize_t
3714
+enable_sdev_max_qd_store(struct device *cdev,
3715
+ struct device_attribute *attr, const char *buf, size_t count)
3716
+{
3717
+ struct Scsi_Host *shost = class_to_shost(cdev);
3718
+ struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
3719
+ struct MPT3SAS_DEVICE *sas_device_priv_data;
3720
+ struct MPT3SAS_TARGET *sas_target_priv_data;
3721
+ int val = 0;
3722
+ struct scsi_device *sdev;
3723
+ struct _raid_device *raid_device;
3724
+ int qdepth;
3725
+
3726
+ if (kstrtoint(buf, 0, &val) != 0)
3727
+ return -EINVAL;
3728
+
3729
+ switch (val) {
3730
+ case 0:
3731
+ ioc->enable_sdev_max_qd = 0;
3732
+ shost_for_each_device(sdev, ioc->shost) {
3733
+ sas_device_priv_data = sdev->hostdata;
3734
+ if (!sas_device_priv_data)
3735
+ continue;
3736
+ sas_target_priv_data = sas_device_priv_data->sas_target;
3737
+ if (!sas_target_priv_data)
3738
+ continue;
3739
+
3740
+ if (sas_target_priv_data->flags &
3741
+ MPT_TARGET_FLAGS_VOLUME) {
3742
+ raid_device =
3743
+ mpt3sas_raid_device_find_by_handle(ioc,
3744
+ sas_target_priv_data->handle);
3745
+
3746
+ switch (raid_device->volume_type) {
3747
+ case MPI2_RAID_VOL_TYPE_RAID0:
3748
+ if (raid_device->device_info &
3749
+ MPI2_SAS_DEVICE_INFO_SSP_TARGET)
3750
+ qdepth =
3751
+ MPT3SAS_SAS_QUEUE_DEPTH;
3752
+ else
3753
+ qdepth =
3754
+ MPT3SAS_SATA_QUEUE_DEPTH;
3755
+ break;
3756
+ case MPI2_RAID_VOL_TYPE_RAID1E:
3757
+ case MPI2_RAID_VOL_TYPE_RAID1:
3758
+ case MPI2_RAID_VOL_TYPE_RAID10:
3759
+ case MPI2_RAID_VOL_TYPE_UNKNOWN:
3760
+ default:
3761
+ qdepth = MPT3SAS_RAID_QUEUE_DEPTH;
3762
+ }
3763
+ } else if (sas_target_priv_data->flags &
3764
+ MPT_TARGET_FLAGS_PCIE_DEVICE)
3765
+ qdepth = MPT3SAS_NVME_QUEUE_DEPTH;
3766
+ else
3767
+ qdepth = MPT3SAS_SAS_QUEUE_DEPTH;
3768
+
3769
+ mpt3sas_scsih_change_queue_depth(sdev, qdepth);
3770
+ }
3771
+ break;
3772
+ case 1:
3773
+ ioc->enable_sdev_max_qd = 1;
3774
+ shost_for_each_device(sdev, ioc->shost)
3775
+ mpt3sas_scsih_change_queue_depth(sdev,
3776
+ shost->can_queue);
3777
+ break;
3778
+ default:
3779
+ return -EINVAL;
3780
+ }
3781
+
3782
+ return strlen(buf);
3783
+}
3784
+static DEVICE_ATTR_RW(enable_sdev_max_qd);
34543785
34553786 struct device_attribute *mpt3sas_host_attrs[] = {
34563787 &dev_attr_version_fw,
....@@ -3477,14 +3808,16 @@
34773808 &dev_attr_diag_trigger_event,
34783809 &dev_attr_diag_trigger_scsi,
34793810 &dev_attr_diag_trigger_mpi,
3811
+ &dev_attr_drv_support_bitmap,
34803812 &dev_attr_BRM_status,
3813
+ &dev_attr_enable_sdev_max_qd,
34813814 NULL,
34823815 };
34833816
34843817 /* device attributes */
34853818
34863819 /**
3487
- * _ctl_device_sas_address_show - sas address
3820
+ * sas_address_show - sas address
34883821 * @dev: pointer to embedded class device
34893822 * @attr: ?
34903823 * @buf: the buffer returned
....@@ -3494,7 +3827,7 @@
34943827 * A sysfs 'read-only' shost attribute.
34953828 */
34963829 static ssize_t
3497
-_ctl_device_sas_address_show(struct device *dev, struct device_attribute *attr,
3830
+sas_address_show(struct device *dev, struct device_attribute *attr,
34983831 char *buf)
34993832 {
35003833 struct scsi_device *sdev = to_scsi_device(dev);
....@@ -3503,10 +3836,10 @@
35033836 return snprintf(buf, PAGE_SIZE, "0x%016llx\n",
35043837 (unsigned long long)sas_device_priv_data->sas_target->sas_address);
35053838 }
3506
-static DEVICE_ATTR(sas_address, S_IRUGO, _ctl_device_sas_address_show, NULL);
3839
+static DEVICE_ATTR_RO(sas_address);
35073840
35083841 /**
3509
- * _ctl_device_handle_show - device handle
3842
+ * sas_device_handle_show - device handle
35103843 * @dev: pointer to embedded class device
35113844 * @attr: ?
35123845 * @buf: the buffer returned
....@@ -3516,7 +3849,7 @@
35163849 * A sysfs 'read-only' shost attribute.
35173850 */
35183851 static ssize_t
3519
-_ctl_device_handle_show(struct device *dev, struct device_attribute *attr,
3852
+sas_device_handle_show(struct device *dev, struct device_attribute *attr,
35203853 char *buf)
35213854 {
35223855 struct scsi_device *sdev = to_scsi_device(dev);
....@@ -3525,10 +3858,10 @@
35253858 return snprintf(buf, PAGE_SIZE, "0x%04x\n",
35263859 sas_device_priv_data->sas_target->handle);
35273860 }
3528
-static DEVICE_ATTR(sas_device_handle, S_IRUGO, _ctl_device_handle_show, NULL);
3861
+static DEVICE_ATTR_RO(sas_device_handle);
35293862
35303863 /**
3531
- * _ctl_device_ncq_io_prio_show - send prioritized io commands to device
3864
+ * sas_ncq_io_prio_show - send prioritized io commands to device
35323865 * @dev: pointer to embedded device
35333866 * @attr: ?
35343867 * @buf: the buffer returned
....@@ -3536,7 +3869,7 @@
35363869 * A sysfs 'read/write' sdev attribute, only works with SATA
35373870 */
35383871 static ssize_t
3539
-_ctl_device_ncq_prio_enable_show(struct device *dev,
3872
+sas_ncq_prio_enable_show(struct device *dev,
35403873 struct device_attribute *attr, char *buf)
35413874 {
35423875 struct scsi_device *sdev = to_scsi_device(dev);
....@@ -3547,7 +3880,7 @@
35473880 }
35483881
35493882 static ssize_t
3550
-_ctl_device_ncq_prio_enable_store(struct device *dev,
3883
+sas_ncq_prio_enable_store(struct device *dev,
35513884 struct device_attribute *attr,
35523885 const char *buf, size_t count)
35533886 {
....@@ -3564,9 +3897,7 @@
35643897 sas_device_priv_data->ncq_prio_enable = ncq_prio_enable;
35653898 return strlen(buf);
35663899 }
3567
-static DEVICE_ATTR(sas_ncq_prio_enable, S_IRUGO | S_IWUSR,
3568
- _ctl_device_ncq_prio_enable_show,
3569
- _ctl_device_ncq_prio_enable_store);
3900
+static DEVICE_ATTR_RW(sas_ncq_prio_enable);
35703901
35713902 struct device_attribute *mpt3sas_dev_attrs[] = {
35723903 &dev_attr_sas_address,
....@@ -3653,14 +3984,10 @@
36533984 for (i = 0; i < MPI2_DIAG_BUF_TYPE_COUNT; i++) {
36543985 if (!ioc->diag_buffer[i])
36553986 continue;
3656
- if (!(ioc->diag_buffer_status[i] &
3657
- MPT3_DIAG_BUFFER_IS_REGISTERED))
3658
- continue;
3659
- if ((ioc->diag_buffer_status[i] &
3660
- MPT3_DIAG_BUFFER_IS_RELEASED))
3661
- continue;
3662
- pci_free_consistent(ioc->pdev, ioc->diag_buffer_sz[i],
3663
- ioc->diag_buffer[i], ioc->diag_buffer_dma[i]);
3987
+ dma_free_coherent(&ioc->pdev->dev,
3988
+ ioc->diag_buffer_sz[i],
3989
+ ioc->diag_buffer[i],
3990
+ ioc->diag_buffer_dma[i]);
36643991 ioc->diag_buffer[i] = NULL;
36653992 ioc->diag_buffer_status[i] = 0;
36663993 }