forked from ~ljy/RK356X_SDK_RELEASE

hc
2024-10-09 244b2c5ca8b14627e4a17755e5922221e121c771
kernel/drivers/scsi/mpt3sas/mpt3sas_config.c
....@@ -101,9 +101,6 @@
101101 Mpi2ConfigRequest_t *mpi_request;
102102 char *desc = NULL;
103103
104
- if (!(ioc->logging_level & MPT_DEBUG_CONFIG))
105
- return;
106
-
107104 mpi_request = mpt3sas_base_get_msg_frame(ioc, smid);
108105 switch (mpi_request->Header.PageType & MPI2_CONFIG_PAGETYPE_MASK) {
109106 case MPI2_CONFIG_PAGETYPE_IO_UNIT:
....@@ -119,7 +116,7 @@
119116 desc = "raid_volume";
120117 break;
121118 case MPI2_CONFIG_PAGETYPE_MANUFACTURING:
122
- desc = "manufaucturing";
119
+ desc = "manufacturing";
123120 break;
124121 case MPI2_CONFIG_PAGETYPE_RAID_PHYSDISK:
125122 desc = "physdisk";
....@@ -175,20 +172,18 @@
175172 if (!desc)
176173 return;
177174
178
- pr_info(MPT3SAS_FMT
179
- "%s: %s(%d), action(%d), form(0x%08x), smid(%d)\n",
180
- ioc->name, calling_function_name, desc,
181
- mpi_request->Header.PageNumber, mpi_request->Action,
182
- le32_to_cpu(mpi_request->PageAddress), smid);
175
+ ioc_info(ioc, "%s: %s(%d), action(%d), form(0x%08x), smid(%d)\n",
176
+ calling_function_name, desc,
177
+ mpi_request->Header.PageNumber, mpi_request->Action,
178
+ le32_to_cpu(mpi_request->PageAddress), smid);
183179
184180 if (!mpi_reply)
185181 return;
186182
187183 if (mpi_reply->IOCStatus || mpi_reply->IOCLogInfo)
188
- pr_info(MPT3SAS_FMT
189
- "\tiocstatus(0x%04x), loginfo(0x%08x)\n",
190
- ioc->name, le16_to_cpu(mpi_reply->IOCStatus),
191
- le32_to_cpu(mpi_reply->IOCLogInfo));
184
+ ioc_info(ioc, "\tiocstatus(0x%04x), loginfo(0x%08x)\n",
185
+ le16_to_cpu(mpi_reply->IOCStatus),
186
+ le32_to_cpu(mpi_reply->IOCLogInfo));
192187 }
193188
194189 /**
....@@ -210,9 +205,8 @@
210205 mem->page = dma_alloc_coherent(&ioc->pdev->dev, mem->sz,
211206 &mem->page_dma, GFP_KERNEL);
212207 if (!mem->page) {
213
- pr_err(MPT3SAS_FMT
214
- "%s: dma_alloc_coherent failed asking for (%d) bytes!!\n",
215
- ioc->name, __func__, mem->sz);
208
+ ioc_err(ioc, "%s: dma_alloc_coherent failed asking for (%d) bytes!!\n",
209
+ __func__, mem->sz);
216210 r = -ENOMEM;
217211 }
218212 } else { /* use tmp buffer if less than 512 bytes */
....@@ -272,7 +266,8 @@
272266 mpi_reply->MsgLength*4);
273267 }
274268 ioc->config_cmds.status &= ~MPT3_CMD_PENDING;
275
- _config_display_some_debug(ioc, smid, "config_done", mpi_reply);
269
+ if (ioc->logging_level & MPT_DEBUG_CONFIG)
270
+ _config_display_some_debug(ioc, smid, "config_done", mpi_reply);
276271 ioc->config_cmds.smid = USHRT_MAX;
277272 complete(&ioc->config_cmds.done);
278273 return 1;
....@@ -303,18 +298,15 @@
303298 void *config_page, u16 config_page_sz)
304299 {
305300 u16 smid;
306
- u32 ioc_state;
307301 Mpi2ConfigRequest_t *config_request;
308302 int r;
309303 u8 retry_count, issue_host_reset = 0;
310
- u16 wait_state_count;
311304 struct config_request mem;
312305 u32 ioc_status = UINT_MAX;
313306
314307 mutex_lock(&ioc->config_cmds.mutex);
315308 if (ioc->config_cmds.status != MPT3_CMD_NOT_USED) {
316
- pr_err(MPT3SAS_FMT "%s: config_cmd in use\n",
317
- ioc->name, __func__);
309
+ ioc_err(ioc, "%s: config_cmd in use\n", __func__);
318310 mutex_unlock(&ioc->config_cmds.mutex);
319311 return -EAGAIN;
320312 }
....@@ -362,53 +354,40 @@
362354 r = -EFAULT;
363355 goto free_mem;
364356 }
365
- pr_info(MPT3SAS_FMT "%s: attempting retry (%d)\n",
366
- ioc->name, __func__, retry_count);
357
+ ioc_info(ioc, "%s: attempting retry (%d)\n",
358
+ __func__, retry_count);
367359 }
368
- wait_state_count = 0;
369
- ioc_state = mpt3sas_base_get_iocstate(ioc, 1);
370
- while (ioc_state != MPI2_IOC_STATE_OPERATIONAL) {
371
- if (wait_state_count++ == MPT3_CONFIG_PAGE_DEFAULT_TIMEOUT) {
372
- pr_err(MPT3SAS_FMT
373
- "%s: failed due to ioc not operational\n",
374
- ioc->name, __func__);
375
- ioc->config_cmds.status = MPT3_CMD_NOT_USED;
376
- r = -EFAULT;
377
- goto free_mem;
378
- }
379
- ssleep(1);
380
- ioc_state = mpt3sas_base_get_iocstate(ioc, 1);
381
- pr_info(MPT3SAS_FMT
382
- "%s: waiting for operational state(count=%d)\n",
383
- ioc->name, __func__, wait_state_count);
384
- }
385
- if (wait_state_count)
386
- pr_info(MPT3SAS_FMT "%s: ioc is operational\n",
387
- ioc->name, __func__);
360
+
361
+ r = mpt3sas_wait_for_ioc(ioc, MPT3_CONFIG_PAGE_DEFAULT_TIMEOUT);
362
+ if (r)
363
+ goto free_mem;
388364
389365 smid = mpt3sas_base_get_smid(ioc, ioc->config_cb_idx);
390366 if (!smid) {
391
- pr_err(MPT3SAS_FMT "%s: failed obtaining a smid\n",
392
- ioc->name, __func__);
367
+ ioc_err(ioc, "%s: failed obtaining a smid\n", __func__);
393368 ioc->config_cmds.status = MPT3_CMD_NOT_USED;
394369 r = -EAGAIN;
395370 goto free_mem;
396371 }
397372
398373 r = 0;
399
- memset(mpi_reply, 0, sizeof(Mpi2ConfigReply_t));
374
+ memset(ioc->config_cmds.reply, 0, sizeof(Mpi2ConfigReply_t));
400375 ioc->config_cmds.status = MPT3_CMD_PENDING;
401376 config_request = mpt3sas_base_get_msg_frame(ioc, smid);
402377 ioc->config_cmds.smid = smid;
403378 memcpy(config_request, mpi_request, sizeof(Mpi2ConfigRequest_t));
404
- _config_display_some_debug(ioc, smid, "config_request", NULL);
379
+ if (ioc->logging_level & MPT_DEBUG_CONFIG)
380
+ _config_display_some_debug(ioc, smid, "config_request", NULL);
405381 init_completion(&ioc->config_cmds.done);
406
- mpt3sas_base_put_smid_default(ioc, smid);
382
+ ioc->put_smid_default(ioc, smid);
407383 wait_for_completion_timeout(&ioc->config_cmds.done, timeout*HZ);
408384 if (!(ioc->config_cmds.status & MPT3_CMD_COMPLETE)) {
409
- mpt3sas_base_check_cmd_timeout(ioc,
410
- ioc->config_cmds.status, mpi_request,
411
- sizeof(Mpi2ConfigRequest_t)/4);
385
+ if (!(ioc->logging_level & MPT_DEBUG_CONFIG))
386
+ _config_display_some_debug(ioc,
387
+ smid, "config_request", NULL);
388
+ ioc_err(ioc, "%s: command timeout\n", __func__);
389
+ mpt3sas_base_check_cmd_timeout(ioc, ioc->config_cmds.status,
390
+ mpi_request, sizeof(Mpi2ConfigRequest_t) / 4);
412391 retry_count++;
413392 if (ioc->config_cmds.smid == smid)
414393 mpt3sas_base_free_smid(ioc, smid);
....@@ -427,34 +406,37 @@
427406 /* Reply Frame Sanity Checks to workaround FW issues */
428407 if ((mpi_request->Header.PageType & 0xF) !=
429408 (mpi_reply->Header.PageType & 0xF)) {
409
+ if (!(ioc->logging_level & MPT_DEBUG_CONFIG))
410
+ _config_display_some_debug(ioc,
411
+ smid, "config_request", NULL);
430412 _debug_dump_mf(mpi_request, ioc->request_sz/4);
431
- _debug_dump_reply(mpi_reply, ioc->request_sz/4);
432
- panic(KERN_WARNING MPT3SAS_FMT "%s: Firmware BUG:" \
433
- " mpi_reply mismatch: Requested PageType(0x%02x)" \
434
- " Reply PageType(0x%02x)\n", \
435
- ioc->name, __func__,
436
- (mpi_request->Header.PageType & 0xF),
437
- (mpi_reply->Header.PageType & 0xF));
413
+ _debug_dump_reply(mpi_reply, ioc->reply_sz/4);
414
+ panic("%s: %s: Firmware BUG: mpi_reply mismatch: Requested PageType(0x%02x) Reply PageType(0x%02x)\n",
415
+ ioc->name, __func__,
416
+ mpi_request->Header.PageType & 0xF,
417
+ mpi_reply->Header.PageType & 0xF);
438418 }
439419
440420 if (((mpi_request->Header.PageType & 0xF) ==
441421 MPI2_CONFIG_PAGETYPE_EXTENDED) &&
442422 mpi_request->ExtPageType != mpi_reply->ExtPageType) {
423
+ if (!(ioc->logging_level & MPT_DEBUG_CONFIG))
424
+ _config_display_some_debug(ioc,
425
+ smid, "config_request", NULL);
443426 _debug_dump_mf(mpi_request, ioc->request_sz/4);
444
- _debug_dump_reply(mpi_reply, ioc->request_sz/4);
445
- panic(KERN_WARNING MPT3SAS_FMT "%s: Firmware BUG:" \
446
- " mpi_reply mismatch: Requested ExtPageType(0x%02x)"
447
- " Reply ExtPageType(0x%02x)\n",
448
- ioc->name, __func__, mpi_request->ExtPageType,
449
- mpi_reply->ExtPageType);
427
+ _debug_dump_reply(mpi_reply, ioc->reply_sz/4);
428
+ panic("%s: %s: Firmware BUG: mpi_reply mismatch: Requested ExtPageType(0x%02x) Reply ExtPageType(0x%02x)\n",
429
+ ioc->name, __func__,
430
+ mpi_request->ExtPageType,
431
+ mpi_reply->ExtPageType);
450432 }
451433 ioc_status = le16_to_cpu(mpi_reply->IOCStatus)
452434 & MPI2_IOCSTATUS_MASK;
453435 }
454436
455437 if (retry_count)
456
- pr_info(MPT3SAS_FMT "%s: retry (%d) completed!!\n", \
457
- ioc->name, __func__, retry_count);
438
+ ioc_info(ioc, "%s: retry (%d) completed!!\n",
439
+ __func__, retry_count);
458440
459441 if ((ioc_status == MPI2_IOCSTATUS_SUCCESS) &&
460442 config_page && mpi_request->Action ==
....@@ -465,34 +447,32 @@
465447 if (p) {
466448 if ((mpi_request->Header.PageType & 0xF) !=
467449 (p[3] & 0xF)) {
450
+ if (!(ioc->logging_level & MPT_DEBUG_CONFIG))
451
+ _config_display_some_debug(ioc,
452
+ smid, "config_request", NULL);
468453 _debug_dump_mf(mpi_request, ioc->request_sz/4);
469
- _debug_dump_reply(mpi_reply, ioc->request_sz/4);
454
+ _debug_dump_reply(mpi_reply, ioc->reply_sz/4);
470455 _debug_dump_config(p, min_t(u16, mem.sz,
471456 config_page_sz)/4);
472
- panic(KERN_WARNING MPT3SAS_FMT
473
- "%s: Firmware BUG:" \
474
- " config page mismatch:"
475
- " Requested PageType(0x%02x)"
476
- " Reply PageType(0x%02x)\n",
477
- ioc->name, __func__,
478
- (mpi_request->Header.PageType & 0xF),
479
- (p[3] & 0xF));
457
+ panic("%s: %s: Firmware BUG: config page mismatch: Requested PageType(0x%02x) Reply PageType(0x%02x)\n",
458
+ ioc->name, __func__,
459
+ mpi_request->Header.PageType & 0xF,
460
+ p[3] & 0xF);
480461 }
481462
482463 if (((mpi_request->Header.PageType & 0xF) ==
483464 MPI2_CONFIG_PAGETYPE_EXTENDED) &&
484465 (mpi_request->ExtPageType != p[6])) {
466
+ if (!(ioc->logging_level & MPT_DEBUG_CONFIG))
467
+ _config_display_some_debug(ioc,
468
+ smid, "config_request", NULL);
485469 _debug_dump_mf(mpi_request, ioc->request_sz/4);
486
- _debug_dump_reply(mpi_reply, ioc->request_sz/4);
470
+ _debug_dump_reply(mpi_reply, ioc->reply_sz/4);
487471 _debug_dump_config(p, min_t(u16, mem.sz,
488472 config_page_sz)/4);
489
- panic(KERN_WARNING MPT3SAS_FMT
490
- "%s: Firmware BUG:" \
491
- " config page mismatch:"
492
- " Requested ExtPageType(0x%02x)"
493
- " Reply ExtPageType(0x%02x)\n",
494
- ioc->name, __func__,
495
- mpi_request->ExtPageType, p[6]);
473
+ panic("%s: %s: Firmware BUG: config page mismatch: Requested ExtPageType(0x%02x) Reply ExtPageType(0x%02x)\n",
474
+ ioc->name, __func__,
475
+ mpi_request->ExtPageType, p[6]);
496476 }
497477 }
498478 memcpy(config_page, mem.page, min_t(u16, mem.sz,
....@@ -983,6 +963,77 @@
983963 out:
984964 return r;
985965 }
966
+/**
967
+ * mpt3sas_config_get_ioc_pg1 - obtain ioc page 1
968
+ * @ioc: per adapter object
969
+ * @mpi_reply: reply mf payload returned from firmware
970
+ * @config_page: contents of the config page
971
+ * Context: sleep.
972
+ *
973
+ * Return: 0 for success, non-zero for failure.
974
+ */
975
+int
976
+mpt3sas_config_get_ioc_pg1(struct MPT3SAS_ADAPTER *ioc,
977
+ Mpi2ConfigReply_t *mpi_reply, Mpi2IOCPage1_t *config_page)
978
+{
979
+ Mpi2ConfigRequest_t mpi_request;
980
+ int r;
981
+
982
+ memset(&mpi_request, 0, sizeof(Mpi2ConfigRequest_t));
983
+ mpi_request.Function = MPI2_FUNCTION_CONFIG;
984
+ mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_HEADER;
985
+ mpi_request.Header.PageType = MPI2_CONFIG_PAGETYPE_IOC;
986
+ mpi_request.Header.PageNumber = 1;
987
+ mpi_request.Header.PageVersion = MPI2_IOCPAGE8_PAGEVERSION;
988
+ ioc->build_zero_len_sge_mpi(ioc, &mpi_request.PageBufferSGE);
989
+ r = _config_request(ioc, &mpi_request, mpi_reply,
990
+ MPT3_CONFIG_PAGE_DEFAULT_TIMEOUT, NULL, 0);
991
+ if (r)
992
+ goto out;
993
+
994
+ mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_READ_CURRENT;
995
+ r = _config_request(ioc, &mpi_request, mpi_reply,
996
+ MPT3_CONFIG_PAGE_DEFAULT_TIMEOUT, config_page,
997
+ sizeof(*config_page));
998
+ out:
999
+ return r;
1000
+}
1001
+
1002
+/**
1003
+ * mpt3sas_config_set_ioc_pg1 - modify ioc page 1
1004
+ * @ioc: per adapter object
1005
+ * @mpi_reply: reply mf payload returned from firmware
1006
+ * @config_page: contents of the config page
1007
+ * Context: sleep.
1008
+ *
1009
+ * Return: 0 for success, non-zero for failure.
1010
+ */
1011
+int
1012
+mpt3sas_config_set_ioc_pg1(struct MPT3SAS_ADAPTER *ioc,
1013
+ Mpi2ConfigReply_t *mpi_reply, Mpi2IOCPage1_t *config_page)
1014
+{
1015
+ Mpi2ConfigRequest_t mpi_request;
1016
+ int r;
1017
+
1018
+ memset(&mpi_request, 0, sizeof(Mpi2ConfigRequest_t));
1019
+ mpi_request.Function = MPI2_FUNCTION_CONFIG;
1020
+ mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_HEADER;
1021
+ mpi_request.Header.PageType = MPI2_CONFIG_PAGETYPE_IOC;
1022
+ mpi_request.Header.PageNumber = 1;
1023
+ mpi_request.Header.PageVersion = MPI2_IOCPAGE8_PAGEVERSION;
1024
+ ioc->build_zero_len_sge_mpi(ioc, &mpi_request.PageBufferSGE);
1025
+ r = _config_request(ioc, &mpi_request, mpi_reply,
1026
+ MPT3_CONFIG_PAGE_DEFAULT_TIMEOUT, NULL, 0);
1027
+ if (r)
1028
+ goto out;
1029
+
1030
+ mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_WRITE_CURRENT;
1031
+ r = _config_request(ioc, &mpi_request, mpi_reply,
1032
+ MPT3_CONFIG_PAGE_DEFAULT_TIMEOUT, config_page,
1033
+ sizeof(*config_page));
1034
+ out:
1035
+ return r;
1036
+}
9861037
9871038 /**
9881039 * mpt3sas_config_get_sas_device_pg0 - obtain sas device page 0