hc
2024-01-03 2f7c68cb55ecb7331f2381deb497c27155f32faf
kernel/drivers/scsi/mpt3sas/mpt3sas_transport.c
....@@ -146,25 +146,22 @@
146146 u32 ioc_status;
147147
148148 if (ioc->shost_recovery || ioc->pci_error_recovery) {
149
- pr_info(MPT3SAS_FMT "%s: host reset in progress!\n",
150
- __func__, ioc->name);
149
+ ioc_info(ioc, "%s: host reset in progress!\n", __func__);
151150 return -EFAULT;
152151 }
153152
154153 if ((mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0,
155154 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle))) {
156
- pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
157
- ioc->name, __FILE__, __LINE__, __func__);
155
+ ioc_err(ioc, "failure at %s:%d/%s()!\n",
156
+ __FILE__, __LINE__, __func__);
158157 return -ENXIO;
159158 }
160159
161160 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
162161 MPI2_IOCSTATUS_MASK;
163162 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
164
- pr_err(MPT3SAS_FMT
165
- "handle(0x%04x), ioc_status(0x%04x)\nfailure at %s:%d/%s()!\n",
166
- ioc->name, handle, ioc_status,
167
- __FILE__, __LINE__, __func__);
163
+ ioc_err(ioc, "handle(0x%04x), ioc_status(0x%04x) failure at %s:%d/%s()!\n",
164
+ handle, ioc_status, __FILE__, __LINE__, __func__);
168165 return -EIO;
169166 }
170167
....@@ -299,7 +296,6 @@
299296 struct rep_manu_request *manufacture_request;
300297 int rc;
301298 u16 smid;
302
- u32 ioc_state;
303299 void *psge;
304300 u8 issue_reset = 0;
305301 void *data_out = NULL;
....@@ -307,48 +303,28 @@
307303 dma_addr_t data_in_dma;
308304 size_t data_in_sz;
309305 size_t data_out_sz;
310
- u16 wait_state_count;
311306
312307 if (ioc->shost_recovery || ioc->pci_error_recovery) {
313
- pr_info(MPT3SAS_FMT "%s: host reset in progress!\n",
314
- __func__, ioc->name);
308
+ ioc_info(ioc, "%s: host reset in progress!\n", __func__);
315309 return -EFAULT;
316310 }
317311
318312 mutex_lock(&ioc->transport_cmds.mutex);
319313
320314 if (ioc->transport_cmds.status != MPT3_CMD_NOT_USED) {
321
- pr_err(MPT3SAS_FMT "%s: transport_cmds in use\n",
322
- ioc->name, __func__);
315
+ ioc_err(ioc, "%s: transport_cmds in use\n", __func__);
323316 rc = -EAGAIN;
324317 goto out;
325318 }
326319 ioc->transport_cmds.status = MPT3_CMD_PENDING;
327320
328
- wait_state_count = 0;
329
- ioc_state = mpt3sas_base_get_iocstate(ioc, 1);
330
- while (ioc_state != MPI2_IOC_STATE_OPERATIONAL) {
331
- if (wait_state_count++ == 10) {
332
- pr_err(MPT3SAS_FMT
333
- "%s: failed due to ioc not operational\n",
334
- ioc->name, __func__);
335
- rc = -EFAULT;
336
- goto out;
337
- }
338
- ssleep(1);
339
- ioc_state = mpt3sas_base_get_iocstate(ioc, 1);
340
- pr_info(MPT3SAS_FMT
341
- "%s: waiting for operational state(count=%d)\n",
342
- ioc->name, __func__, wait_state_count);
343
- }
344
- if (wait_state_count)
345
- pr_info(MPT3SAS_FMT "%s: ioc is operational\n",
346
- ioc->name, __func__);
321
+ rc = mpt3sas_wait_for_ioc(ioc, IOC_OPERATIONAL_WAIT_COUNT);
322
+ if (rc)
323
+ goto out;
347324
348325 smid = mpt3sas_base_get_smid(ioc, ioc->transport_cb_idx);
349326 if (!smid) {
350
- pr_err(MPT3SAS_FMT "%s: failed obtaining a smid\n",
351
- ioc->name, __func__);
327
+ ioc_err(ioc, "%s: failed obtaining a smid\n", __func__);
352328 rc = -EAGAIN;
353329 goto out;
354330 }
....@@ -359,9 +335,8 @@
359335
360336 data_out_sz = sizeof(struct rep_manu_request);
361337 data_in_sz = sizeof(struct rep_manu_reply);
362
- data_out = pci_alloc_consistent(ioc->pdev, data_out_sz + data_in_sz,
363
- &data_out_dma);
364
-
338
+ data_out = dma_alloc_coherent(&ioc->pdev->dev, data_out_sz + data_in_sz,
339
+ &data_out_dma, GFP_KERNEL);
365340 if (!data_out) {
366341 pr_err("failure at %s:%d/%s()!\n", __FILE__,
367342 __LINE__, __func__);
....@@ -388,16 +363,15 @@
388363 ioc->build_sg(ioc, psge, data_out_dma, data_out_sz, data_in_dma,
389364 data_in_sz);
390365
391
- dtransportprintk(ioc, pr_info(MPT3SAS_FMT
392
- "report_manufacture - send to sas_addr(0x%016llx)\n",
393
- ioc->name, (unsigned long long)sas_address));
366
+ dtransportprintk(ioc,
367
+ ioc_info(ioc, "report_manufacture - send to sas_addr(0x%016llx)\n",
368
+ (u64)sas_address));
394369 init_completion(&ioc->transport_cmds.done);
395
- mpt3sas_base_put_smid_default(ioc, smid);
370
+ ioc->put_smid_default(ioc, smid);
396371 wait_for_completion_timeout(&ioc->transport_cmds.done, 10*HZ);
397372
398373 if (!(ioc->transport_cmds.status & MPT3_CMD_COMPLETE)) {
399
- pr_err(MPT3SAS_FMT "%s: timeout\n",
400
- ioc->name, __func__);
374
+ ioc_err(ioc, "%s: timeout\n", __func__);
401375 _debug_dump_mf(mpi_request,
402376 sizeof(Mpi2SmpPassthroughRequest_t)/4);
403377 if (!(ioc->transport_cmds.status & MPT3_CMD_RESET))
....@@ -405,17 +379,16 @@
405379 goto issue_host_reset;
406380 }
407381
408
- dtransportprintk(ioc, pr_info(MPT3SAS_FMT
409
- "report_manufacture - complete\n", ioc->name));
382
+ dtransportprintk(ioc, ioc_info(ioc, "report_manufacture - complete\n"));
410383
411384 if (ioc->transport_cmds.status & MPT3_CMD_REPLY_VALID) {
412385 u8 *tmp;
413386
414387 mpi_reply = ioc->transport_cmds.reply;
415388
416
- dtransportprintk(ioc, pr_info(MPT3SAS_FMT
417
- "report_manufacture - reply data transfer size(%d)\n",
418
- ioc->name, le16_to_cpu(mpi_reply->ResponseDataLength)));
389
+ dtransportprintk(ioc,
390
+ ioc_info(ioc, "report_manufacture - reply data transfer size(%d)\n",
391
+ le16_to_cpu(mpi_reply->ResponseDataLength)));
419392
420393 if (le16_to_cpu(mpi_reply->ResponseDataLength) !=
421394 sizeof(struct rep_manu_reply))
....@@ -439,8 +412,8 @@
439412 manufacture_reply->component_revision_id;
440413 }
441414 } else
442
- dtransportprintk(ioc, pr_info(MPT3SAS_FMT
443
- "report_manufacture - no reply\n", ioc->name));
415
+ dtransportprintk(ioc,
416
+ ioc_info(ioc, "report_manufacture - no reply\n"));
444417
445418 issue_host_reset:
446419 if (issue_reset)
....@@ -448,7 +421,7 @@
448421 out:
449422 ioc->transport_cmds.status = MPT3_CMD_NOT_USED;
450423 if (data_out)
451
- pci_free_consistent(ioc->pdev, data_out_sz + data_in_sz,
424
+ dma_free_coherent(&ioc->pdev->dev, data_out_sz + data_in_sz,
452425 data_out, data_out_dma);
453426
454427 mutex_unlock(&ioc->transport_cmds.mutex);
....@@ -643,8 +616,8 @@
643616 mpt3sas_port = kzalloc(sizeof(struct _sas_port),
644617 GFP_KERNEL);
645618 if (!mpt3sas_port) {
646
- pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
647
- ioc->name, __FILE__, __LINE__, __func__);
619
+ ioc_err(ioc, "failure at %s:%d/%s()!\n",
620
+ __FILE__, __LINE__, __func__);
648621 return NULL;
649622 }
650623
....@@ -655,22 +628,21 @@
655628 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
656629
657630 if (!sas_node) {
658
- pr_err(MPT3SAS_FMT
659
- "%s: Could not find parent sas_address(0x%016llx)!\n",
660
- ioc->name, __func__, (unsigned long long)sas_address);
631
+ ioc_err(ioc, "%s: Could not find parent sas_address(0x%016llx)!\n",
632
+ __func__, (u64)sas_address);
661633 goto out_fail;
662634 }
663635
664636 if ((_transport_set_identify(ioc, handle,
665637 &mpt3sas_port->remote_identify))) {
666
- pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
667
- ioc->name, __FILE__, __LINE__, __func__);
638
+ ioc_err(ioc, "failure at %s:%d/%s()!\n",
639
+ __FILE__, __LINE__, __func__);
668640 goto out_fail;
669641 }
670642
671643 if (mpt3sas_port->remote_identify.device_type == SAS_PHY_UNUSED) {
672
- pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
673
- ioc->name, __FILE__, __LINE__, __func__);
644
+ ioc_err(ioc, "failure at %s:%d/%s()!\n",
645
+ __FILE__, __LINE__, __func__);
674646 goto out_fail;
675647 }
676648
....@@ -687,20 +659,20 @@
687659 }
688660
689661 if (!mpt3sas_port->num_phys) {
690
- pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
691
- ioc->name, __FILE__, __LINE__, __func__);
662
+ ioc_err(ioc, "failure at %s:%d/%s()!\n",
663
+ __FILE__, __LINE__, __func__);
692664 goto out_fail;
693665 }
694666
695667 if (!sas_node->parent_dev) {
696
- pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
697
- ioc->name, __FILE__, __LINE__, __func__);
668
+ ioc_err(ioc, "failure at %s:%d/%s()!\n",
669
+ __FILE__, __LINE__, __func__);
698670 goto out_fail;
699671 }
700672 port = sas_port_alloc_num(sas_node->parent_dev);
701
- if ((sas_port_add(port))) {
702
- pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
703
- ioc->name, __FILE__, __LINE__, __func__);
673
+ if (!port || (sas_port_add(port))) {
674
+ ioc_err(ioc, "failure at %s:%d/%s()!\n",
675
+ __FILE__, __LINE__, __func__);
704676 goto out_fail;
705677 }
706678
....@@ -723,23 +695,32 @@
723695 rphy = sas_expander_alloc(port,
724696 mpt3sas_port->remote_identify.device_type);
725697
698
+ if (!rphy) {
699
+ ioc_err(ioc, "failure at %s:%d/%s()!\n",
700
+ __FILE__, __LINE__, __func__);
701
+ goto out_delete_port;
702
+ }
703
+
726704 rphy->identify = mpt3sas_port->remote_identify;
727705
728706 if (mpt3sas_port->remote_identify.device_type == SAS_END_DEVICE) {
729707 sas_device = mpt3sas_get_sdev_by_addr(ioc,
730708 mpt3sas_port->remote_identify.sas_address);
731709 if (!sas_device) {
732
- dfailprintk(ioc, printk(MPT3SAS_FMT
733
- "failure at %s:%d/%s()!\n",
734
- ioc->name, __FILE__, __LINE__, __func__));
710
+ dfailprintk(ioc,
711
+ ioc_info(ioc, "failure at %s:%d/%s()!\n",
712
+ __FILE__, __LINE__, __func__));
735713 goto out_fail;
736714 }
737715 sas_device->pend_sas_rphy_add = 1;
738716 }
739717
740718 if ((sas_rphy_add(rphy))) {
741
- pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
742
- ioc->name, __FILE__, __LINE__, __func__);
719
+ ioc_err(ioc, "failure at %s:%d/%s()!\n",
720
+ __FILE__, __LINE__, __func__);
721
+ sas_rphy_free(rphy);
722
+ rphy = NULL;
723
+ goto out_delete_port;
743724 }
744725
745726 if (mpt3sas_port->remote_identify.device_type == SAS_END_DEVICE) {
....@@ -747,11 +728,10 @@
747728 sas_device_put(sas_device);
748729 }
749730
750
- if ((ioc->logging_level & MPT_DEBUG_TRANSPORT))
751
- dev_printk(KERN_INFO, &rphy->dev,
752
- "add: handle(0x%04x), sas_addr(0x%016llx)\n",
753
- handle, (unsigned long long)
754
- mpt3sas_port->remote_identify.sas_address);
731
+ dev_info(&rphy->dev,
732
+ "add: handle(0x%04x), sas_addr(0x%016llx)\n", handle,
733
+ (unsigned long long)mpt3sas_port->remote_identify.sas_address);
734
+
755735 mpt3sas_port->rphy = rphy;
756736 spin_lock_irqsave(&ioc->sas_node_lock, flags);
757737 list_add_tail(&mpt3sas_port->port_list, &sas_node->sas_port_list);
....@@ -767,7 +747,10 @@
767747 rphy_to_expander_device(rphy));
768748 return mpt3sas_port;
769749
770
- out_fail:
750
+out_delete_port:
751
+ sas_port_delete(port);
752
+
753
+out_fail:
771754 list_for_each_entry_safe(mpt3sas_phy, next, &mpt3sas_port->phy_list,
772755 port_siblings)
773756 list_del(&mpt3sas_phy->port_siblings);
....@@ -841,6 +824,8 @@
841824 }
842825 if (!ioc->remove_host)
843826 sas_port_delete(mpt3sas_port->port);
827
+ ioc_info(ioc, "%s: removed: sas_addr(0x%016llx)\n",
828
+ __func__, (unsigned long long)sas_address);
844829 kfree(mpt3sas_port);
845830 }
846831
....@@ -864,14 +849,14 @@
864849 INIT_LIST_HEAD(&mpt3sas_phy->port_siblings);
865850 phy = sas_phy_alloc(parent_dev, phy_index);
866851 if (!phy) {
867
- pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
868
- ioc->name, __FILE__, __LINE__, __func__);
852
+ ioc_err(ioc, "failure at %s:%d/%s()!\n",
853
+ __FILE__, __LINE__, __func__);
869854 return -1;
870855 }
871856 if ((_transport_set_identify(ioc, mpt3sas_phy->handle,
872857 &mpt3sas_phy->identify))) {
873
- pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
874
- ioc->name, __FILE__, __LINE__, __func__);
858
+ ioc_err(ioc, "failure at %s:%d/%s()!\n",
859
+ __FILE__, __LINE__, __func__);
875860 sas_phy_free(phy);
876861 return -1;
877862 }
....@@ -893,8 +878,8 @@
893878 phy_pg0.ProgrammedLinkRate >> 4);
894879
895880 if ((sas_phy_add(phy))) {
896
- pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
897
- ioc->name, __FILE__, __LINE__, __func__);
881
+ ioc_err(ioc, "failure at %s:%d/%s()!\n",
882
+ __FILE__, __LINE__, __func__);
898883 sas_phy_free(phy);
899884 return -1;
900885 }
....@@ -932,14 +917,14 @@
932917 INIT_LIST_HEAD(&mpt3sas_phy->port_siblings);
933918 phy = sas_phy_alloc(parent_dev, phy_index);
934919 if (!phy) {
935
- pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
936
- ioc->name, __FILE__, __LINE__, __func__);
920
+ ioc_err(ioc, "failure at %s:%d/%s()!\n",
921
+ __FILE__, __LINE__, __func__);
937922 return -1;
938923 }
939924 if ((_transport_set_identify(ioc, mpt3sas_phy->handle,
940925 &mpt3sas_phy->identify))) {
941
- pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
942
- ioc->name, __FILE__, __LINE__, __func__);
926
+ ioc_err(ioc, "failure at %s:%d/%s()!\n",
927
+ __FILE__, __LINE__, __func__);
943928 sas_phy_free(phy);
944929 return -1;
945930 }
....@@ -963,8 +948,8 @@
963948 expander_pg1.ProgrammedLinkRate >> 4);
964949
965950 if ((sas_phy_add(phy))) {
966
- pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
967
- ioc->name, __FILE__, __LINE__, __func__);
951
+ ioc_err(ioc, "failure at %s:%d/%s()!\n",
952
+ __FILE__, __LINE__, __func__);
968953 sas_phy_free(phy);
969954 return -1;
970955 }
....@@ -1092,54 +1077,33 @@
10921077 struct phy_error_log_reply *phy_error_log_reply;
10931078 int rc;
10941079 u16 smid;
1095
- u32 ioc_state;
10961080 void *psge;
10971081 u8 issue_reset = 0;
10981082 void *data_out = NULL;
10991083 dma_addr_t data_out_dma;
11001084 u32 sz;
1101
- u16 wait_state_count;
11021085
11031086 if (ioc->shost_recovery || ioc->pci_error_recovery) {
1104
- pr_info(MPT3SAS_FMT "%s: host reset in progress!\n",
1105
- __func__, ioc->name);
1087
+ ioc_info(ioc, "%s: host reset in progress!\n", __func__);
11061088 return -EFAULT;
11071089 }
11081090
11091091 mutex_lock(&ioc->transport_cmds.mutex);
11101092
11111093 if (ioc->transport_cmds.status != MPT3_CMD_NOT_USED) {
1112
- pr_err(MPT3SAS_FMT "%s: transport_cmds in use\n",
1113
- ioc->name, __func__);
1094
+ ioc_err(ioc, "%s: transport_cmds in use\n", __func__);
11141095 rc = -EAGAIN;
11151096 goto out;
11161097 }
11171098 ioc->transport_cmds.status = MPT3_CMD_PENDING;
11181099
1119
- wait_state_count = 0;
1120
- ioc_state = mpt3sas_base_get_iocstate(ioc, 1);
1121
- while (ioc_state != MPI2_IOC_STATE_OPERATIONAL) {
1122
- if (wait_state_count++ == 10) {
1123
- pr_err(MPT3SAS_FMT
1124
- "%s: failed due to ioc not operational\n",
1125
- ioc->name, __func__);
1126
- rc = -EFAULT;
1127
- goto out;
1128
- }
1129
- ssleep(1);
1130
- ioc_state = mpt3sas_base_get_iocstate(ioc, 1);
1131
- pr_info(MPT3SAS_FMT
1132
- "%s: waiting for operational state(count=%d)\n",
1133
- ioc->name, __func__, wait_state_count);
1134
- }
1135
- if (wait_state_count)
1136
- pr_info(MPT3SAS_FMT "%s: ioc is operational\n",
1137
- ioc->name, __func__);
1100
+ rc = mpt3sas_wait_for_ioc(ioc, IOC_OPERATIONAL_WAIT_COUNT);
1101
+ if (rc)
1102
+ goto out;
11381103
11391104 smid = mpt3sas_base_get_smid(ioc, ioc->transport_cb_idx);
11401105 if (!smid) {
1141
- pr_err(MPT3SAS_FMT "%s: failed obtaining a smid\n",
1142
- ioc->name, __func__);
1106
+ ioc_err(ioc, "%s: failed obtaining a smid\n", __func__);
11431107 rc = -EAGAIN;
11441108 goto out;
11451109 }
....@@ -1149,7 +1113,8 @@
11491113
11501114 sz = sizeof(struct phy_error_log_request) +
11511115 sizeof(struct phy_error_log_reply);
1152
- data_out = pci_alloc_consistent(ioc->pdev, sz, &data_out_dma);
1116
+ data_out = dma_alloc_coherent(&ioc->pdev->dev, sz, &data_out_dma,
1117
+ GFP_KERNEL);
11531118 if (!data_out) {
11541119 pr_err("failure at %s:%d/%s()!\n", __FILE__,
11551120 __LINE__, __func__);
....@@ -1182,17 +1147,16 @@
11821147 data_out_dma + sizeof(struct phy_error_log_request),
11831148 sizeof(struct phy_error_log_reply));
11841149
1185
- dtransportprintk(ioc, pr_info(MPT3SAS_FMT
1186
- "phy_error_log - send to sas_addr(0x%016llx), phy(%d)\n",
1187
- ioc->name, (unsigned long long)phy->identify.sas_address,
1188
- phy->number));
1150
+ dtransportprintk(ioc,
1151
+ ioc_info(ioc, "phy_error_log - send to sas_addr(0x%016llx), phy(%d)\n",
1152
+ (u64)phy->identify.sas_address,
1153
+ phy->number));
11891154 init_completion(&ioc->transport_cmds.done);
1190
- mpt3sas_base_put_smid_default(ioc, smid);
1155
+ ioc->put_smid_default(ioc, smid);
11911156 wait_for_completion_timeout(&ioc->transport_cmds.done, 10*HZ);
11921157
11931158 if (!(ioc->transport_cmds.status & MPT3_CMD_COMPLETE)) {
1194
- pr_err(MPT3SAS_FMT "%s: timeout\n",
1195
- ioc->name, __func__);
1159
+ ioc_err(ioc, "%s: timeout\n", __func__);
11961160 _debug_dump_mf(mpi_request,
11971161 sizeof(Mpi2SmpPassthroughRequest_t)/4);
11981162 if (!(ioc->transport_cmds.status & MPT3_CMD_RESET))
....@@ -1200,16 +1164,15 @@
12001164 goto issue_host_reset;
12011165 }
12021166
1203
- dtransportprintk(ioc, pr_info(MPT3SAS_FMT
1204
- "phy_error_log - complete\n", ioc->name));
1167
+ dtransportprintk(ioc, ioc_info(ioc, "phy_error_log - complete\n"));
12051168
12061169 if (ioc->transport_cmds.status & MPT3_CMD_REPLY_VALID) {
12071170
12081171 mpi_reply = ioc->transport_cmds.reply;
12091172
1210
- dtransportprintk(ioc, pr_info(MPT3SAS_FMT
1211
- "phy_error_log - reply data transfer size(%d)\n",
1212
- ioc->name, le16_to_cpu(mpi_reply->ResponseDataLength)));
1173
+ dtransportprintk(ioc,
1174
+ ioc_info(ioc, "phy_error_log - reply data transfer size(%d)\n",
1175
+ le16_to_cpu(mpi_reply->ResponseDataLength)));
12131176
12141177 if (le16_to_cpu(mpi_reply->ResponseDataLength) !=
12151178 sizeof(struct phy_error_log_reply))
....@@ -1218,9 +1181,9 @@
12181181 phy_error_log_reply = data_out +
12191182 sizeof(struct phy_error_log_request);
12201183
1221
- dtransportprintk(ioc, pr_info(MPT3SAS_FMT
1222
- "phy_error_log - function_result(%d)\n",
1223
- ioc->name, phy_error_log_reply->function_result));
1184
+ dtransportprintk(ioc,
1185
+ ioc_info(ioc, "phy_error_log - function_result(%d)\n",
1186
+ phy_error_log_reply->function_result));
12241187
12251188 phy->invalid_dword_count =
12261189 be32_to_cpu(phy_error_log_reply->invalid_dword);
....@@ -1232,8 +1195,8 @@
12321195 be32_to_cpu(phy_error_log_reply->phy_reset_problem);
12331196 rc = 0;
12341197 } else
1235
- dtransportprintk(ioc, pr_info(MPT3SAS_FMT
1236
- "phy_error_log - no reply\n", ioc->name));
1198
+ dtransportprintk(ioc,
1199
+ ioc_info(ioc, "phy_error_log - no reply\n"));
12371200
12381201 issue_host_reset:
12391202 if (issue_reset)
....@@ -1241,7 +1204,7 @@
12411204 out:
12421205 ioc->transport_cmds.status = MPT3_CMD_NOT_USED;
12431206 if (data_out)
1244
- pci_free_consistent(ioc->pdev, sz, data_out, data_out_dma);
1207
+ dma_free_coherent(&ioc->pdev->dev, sz, data_out, data_out_dma);
12451208
12461209 mutex_unlock(&ioc->transport_cmds.mutex);
12471210 return rc;
....@@ -1276,17 +1239,16 @@
12761239 /* get hba phy error logs */
12771240 if ((mpt3sas_config_get_phy_pg1(ioc, &mpi_reply, &phy_pg1,
12781241 phy->number))) {
1279
- pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
1280
- ioc->name, __FILE__, __LINE__, __func__);
1242
+ ioc_err(ioc, "failure at %s:%d/%s()!\n",
1243
+ __FILE__, __LINE__, __func__);
12811244 return -ENXIO;
12821245 }
12831246
12841247 if (mpi_reply.IOCStatus || mpi_reply.IOCLogInfo)
1285
- pr_info(MPT3SAS_FMT
1286
- "phy(%d), ioc_status (0x%04x), loginfo(0x%08x)\n",
1287
- ioc->name, phy->number,
1288
- le16_to_cpu(mpi_reply.IOCStatus),
1289
- le32_to_cpu(mpi_reply.IOCLogInfo));
1248
+ ioc_info(ioc, "phy(%d), ioc_status (0x%04x), loginfo(0x%08x)\n",
1249
+ phy->number,
1250
+ le16_to_cpu(mpi_reply.IOCStatus),
1251
+ le32_to_cpu(mpi_reply.IOCLogInfo));
12901252
12911253 phy->invalid_dword_count = le32_to_cpu(phy_pg1.InvalidDwordCount);
12921254 phy->running_disparity_error_count =
....@@ -1405,54 +1367,33 @@
14051367 struct phy_control_reply *phy_control_reply;
14061368 int rc;
14071369 u16 smid;
1408
- u32 ioc_state;
14091370 void *psge;
14101371 u8 issue_reset = 0;
14111372 void *data_out = NULL;
14121373 dma_addr_t data_out_dma;
14131374 u32 sz;
1414
- u16 wait_state_count;
14151375
14161376 if (ioc->shost_recovery || ioc->pci_error_recovery) {
1417
- pr_info(MPT3SAS_FMT "%s: host reset in progress!\n",
1418
- __func__, ioc->name);
1377
+ ioc_info(ioc, "%s: host reset in progress!\n", __func__);
14191378 return -EFAULT;
14201379 }
14211380
14221381 mutex_lock(&ioc->transport_cmds.mutex);
14231382
14241383 if (ioc->transport_cmds.status != MPT3_CMD_NOT_USED) {
1425
- pr_err(MPT3SAS_FMT "%s: transport_cmds in use\n",
1426
- ioc->name, __func__);
1384
+ ioc_err(ioc, "%s: transport_cmds in use\n", __func__);
14271385 rc = -EAGAIN;
14281386 goto out;
14291387 }
14301388 ioc->transport_cmds.status = MPT3_CMD_PENDING;
14311389
1432
- wait_state_count = 0;
1433
- ioc_state = mpt3sas_base_get_iocstate(ioc, 1);
1434
- while (ioc_state != MPI2_IOC_STATE_OPERATIONAL) {
1435
- if (wait_state_count++ == 10) {
1436
- pr_err(MPT3SAS_FMT
1437
- "%s: failed due to ioc not operational\n",
1438
- ioc->name, __func__);
1439
- rc = -EFAULT;
1440
- goto out;
1441
- }
1442
- ssleep(1);
1443
- ioc_state = mpt3sas_base_get_iocstate(ioc, 1);
1444
- pr_info(MPT3SAS_FMT
1445
- "%s: waiting for operational state(count=%d)\n",
1446
- ioc->name, __func__, wait_state_count);
1447
- }
1448
- if (wait_state_count)
1449
- pr_info(MPT3SAS_FMT "%s: ioc is operational\n",
1450
- ioc->name, __func__);
1390
+ rc = mpt3sas_wait_for_ioc(ioc, IOC_OPERATIONAL_WAIT_COUNT);
1391
+ if (rc)
1392
+ goto out;
14511393
14521394 smid = mpt3sas_base_get_smid(ioc, ioc->transport_cb_idx);
14531395 if (!smid) {
1454
- pr_err(MPT3SAS_FMT "%s: failed obtaining a smid\n",
1455
- ioc->name, __func__);
1396
+ ioc_err(ioc, "%s: failed obtaining a smid\n", __func__);
14561397 rc = -EAGAIN;
14571398 goto out;
14581399 }
....@@ -1462,7 +1403,8 @@
14621403
14631404 sz = sizeof(struct phy_control_request) +
14641405 sizeof(struct phy_control_reply);
1465
- data_out = pci_alloc_consistent(ioc->pdev, sz, &data_out_dma);
1406
+ data_out = dma_alloc_coherent(&ioc->pdev->dev, sz, &data_out_dma,
1407
+ GFP_KERNEL);
14661408 if (!data_out) {
14671409 pr_err("failure at %s:%d/%s()!\n", __FILE__,
14681410 __LINE__, __func__);
....@@ -1500,17 +1442,16 @@
15001442 data_out_dma + sizeof(struct phy_control_request),
15011443 sizeof(struct phy_control_reply));
15021444
1503
- dtransportprintk(ioc, pr_info(MPT3SAS_FMT
1504
- "phy_control - send to sas_addr(0x%016llx), phy(%d), opcode(%d)\n",
1505
- ioc->name, (unsigned long long)phy->identify.sas_address,
1506
- phy->number, phy_operation));
1445
+ dtransportprintk(ioc,
1446
+ ioc_info(ioc, "phy_control - send to sas_addr(0x%016llx), phy(%d), opcode(%d)\n",
1447
+ (u64)phy->identify.sas_address,
1448
+ phy->number, phy_operation));
15071449 init_completion(&ioc->transport_cmds.done);
1508
- mpt3sas_base_put_smid_default(ioc, smid);
1450
+ ioc->put_smid_default(ioc, smid);
15091451 wait_for_completion_timeout(&ioc->transport_cmds.done, 10*HZ);
15101452
15111453 if (!(ioc->transport_cmds.status & MPT3_CMD_COMPLETE)) {
1512
- pr_err(MPT3SAS_FMT "%s: timeout\n",
1513
- ioc->name, __func__);
1454
+ ioc_err(ioc, "%s: timeout\n", __func__);
15141455 _debug_dump_mf(mpi_request,
15151456 sizeof(Mpi2SmpPassthroughRequest_t)/4);
15161457 if (!(ioc->transport_cmds.status & MPT3_CMD_RESET))
....@@ -1518,16 +1459,15 @@
15181459 goto issue_host_reset;
15191460 }
15201461
1521
- dtransportprintk(ioc, pr_info(MPT3SAS_FMT
1522
- "phy_control - complete\n", ioc->name));
1462
+ dtransportprintk(ioc, ioc_info(ioc, "phy_control - complete\n"));
15231463
15241464 if (ioc->transport_cmds.status & MPT3_CMD_REPLY_VALID) {
15251465
15261466 mpi_reply = ioc->transport_cmds.reply;
15271467
1528
- dtransportprintk(ioc, pr_info(MPT3SAS_FMT
1529
- "phy_control - reply data transfer size(%d)\n",
1530
- ioc->name, le16_to_cpu(mpi_reply->ResponseDataLength)));
1468
+ dtransportprintk(ioc,
1469
+ ioc_info(ioc, "phy_control - reply data transfer size(%d)\n",
1470
+ le16_to_cpu(mpi_reply->ResponseDataLength)));
15311471
15321472 if (le16_to_cpu(mpi_reply->ResponseDataLength) !=
15331473 sizeof(struct phy_control_reply))
....@@ -1536,14 +1476,14 @@
15361476 phy_control_reply = data_out +
15371477 sizeof(struct phy_control_request);
15381478
1539
- dtransportprintk(ioc, pr_info(MPT3SAS_FMT
1540
- "phy_control - function_result(%d)\n",
1541
- ioc->name, phy_control_reply->function_result));
1479
+ dtransportprintk(ioc,
1480
+ ioc_info(ioc, "phy_control - function_result(%d)\n",
1481
+ phy_control_reply->function_result));
15421482
15431483 rc = 0;
15441484 } else
1545
- dtransportprintk(ioc, pr_info(MPT3SAS_FMT
1546
- "phy_control - no reply\n", ioc->name));
1485
+ dtransportprintk(ioc,
1486
+ ioc_info(ioc, "phy_control - no reply\n"));
15471487
15481488 issue_host_reset:
15491489 if (issue_reset)
....@@ -1551,7 +1491,8 @@
15511491 out:
15521492 ioc->transport_cmds.status = MPT3_CMD_NOT_USED;
15531493 if (data_out)
1554
- pci_free_consistent(ioc->pdev, sz, data_out, data_out_dma);
1494
+ dma_free_coherent(&ioc->pdev->dev, sz, data_out,
1495
+ data_out_dma);
15551496
15561497 mutex_unlock(&ioc->transport_cmds.mutex);
15571498 return rc;
....@@ -1594,16 +1535,15 @@
15941535 mpi_request.PhyNum = phy->number;
15951536
15961537 if ((mpt3sas_base_sas_iounit_control(ioc, &mpi_reply, &mpi_request))) {
1597
- pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
1598
- ioc->name, __FILE__, __LINE__, __func__);
1538
+ ioc_err(ioc, "failure at %s:%d/%s()!\n",
1539
+ __FILE__, __LINE__, __func__);
15991540 return -ENXIO;
16001541 }
16011542
16021543 if (mpi_reply.IOCStatus || mpi_reply.IOCLogInfo)
1603
- pr_info(MPT3SAS_FMT
1604
- "phy(%d), ioc_status(0x%04x), loginfo(0x%08x)\n",
1605
- ioc->name, phy->number, le16_to_cpu(mpi_reply.IOCStatus),
1606
- le32_to_cpu(mpi_reply.IOCLogInfo));
1544
+ ioc_info(ioc, "phy(%d), ioc_status(0x%04x), loginfo(0x%08x)\n",
1545
+ phy->number, le16_to_cpu(mpi_reply.IOCStatus),
1546
+ le32_to_cpu(mpi_reply.IOCLogInfo));
16071547
16081548 return 0;
16091549 }
....@@ -1650,23 +1590,23 @@
16501590 sizeof(Mpi2SasIOUnit0PhyData_t));
16511591 sas_iounit_pg0 = kzalloc(sz, GFP_KERNEL);
16521592 if (!sas_iounit_pg0) {
1653
- pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
1654
- ioc->name, __FILE__, __LINE__, __func__);
1593
+ ioc_err(ioc, "failure at %s:%d/%s()!\n",
1594
+ __FILE__, __LINE__, __func__);
16551595 rc = -ENOMEM;
16561596 goto out;
16571597 }
16581598 if ((mpt3sas_config_get_sas_iounit_pg0(ioc, &mpi_reply,
16591599 sas_iounit_pg0, sz))) {
1660
- pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
1661
- ioc->name, __FILE__, __LINE__, __func__);
1600
+ ioc_err(ioc, "failure at %s:%d/%s()!\n",
1601
+ __FILE__, __LINE__, __func__);
16621602 rc = -ENXIO;
16631603 goto out;
16641604 }
16651605 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
16661606 MPI2_IOCSTATUS_MASK;
16671607 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
1668
- pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
1669
- ioc->name, __FILE__, __LINE__, __func__);
1608
+ ioc_err(ioc, "failure at %s:%d/%s()!\n",
1609
+ __FILE__, __LINE__, __func__);
16701610 rc = -EIO;
16711611 goto out;
16721612 }
....@@ -1675,10 +1615,8 @@
16751615 for (i = 0, discovery_active = 0; i < ioc->sas_hba.num_phys ; i++) {
16761616 if (sas_iounit_pg0->PhyData[i].PortFlags &
16771617 MPI2_SASIOUNIT0_PORTFLAGS_DISCOVERY_IN_PROGRESS) {
1678
- pr_err(MPT3SAS_FMT "discovery is active on " \
1679
- "port = %d, phy = %d: unable to enable/disable "
1680
- "phys, try again later!\n", ioc->name,
1681
- sas_iounit_pg0->PhyData[i].Port, i);
1618
+ ioc_err(ioc, "discovery is active on port = %d, phy = %d: unable to enable/disable phys, try again later!\n",
1619
+ sas_iounit_pg0->PhyData[i].Port, i);
16821620 discovery_active = 1;
16831621 }
16841622 }
....@@ -1693,23 +1631,23 @@
16931631 sizeof(Mpi2SasIOUnit1PhyData_t));
16941632 sas_iounit_pg1 = kzalloc(sz, GFP_KERNEL);
16951633 if (!sas_iounit_pg1) {
1696
- pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
1697
- ioc->name, __FILE__, __LINE__, __func__);
1634
+ ioc_err(ioc, "failure at %s:%d/%s()!\n",
1635
+ __FILE__, __LINE__, __func__);
16981636 rc = -ENOMEM;
16991637 goto out;
17001638 }
17011639 if ((mpt3sas_config_get_sas_iounit_pg1(ioc, &mpi_reply,
17021640 sas_iounit_pg1, sz))) {
1703
- pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
1704
- ioc->name, __FILE__, __LINE__, __func__);
1641
+ ioc_err(ioc, "failure at %s:%d/%s()!\n",
1642
+ __FILE__, __LINE__, __func__);
17051643 rc = -ENXIO;
17061644 goto out;
17071645 }
17081646 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
17091647 MPI2_IOCSTATUS_MASK;
17101648 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
1711
- pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
1712
- ioc->name, __FILE__, __LINE__, __func__);
1649
+ ioc_err(ioc, "failure at %s:%d/%s()!\n",
1650
+ __FILE__, __LINE__, __func__);
17131651 rc = -EIO;
17141652 goto out;
17151653 }
....@@ -1801,23 +1739,23 @@
18011739 sizeof(Mpi2SasIOUnit1PhyData_t));
18021740 sas_iounit_pg1 = kzalloc(sz, GFP_KERNEL);
18031741 if (!sas_iounit_pg1) {
1804
- pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
1805
- ioc->name, __FILE__, __LINE__, __func__);
1742
+ ioc_err(ioc, "failure at %s:%d/%s()!\n",
1743
+ __FILE__, __LINE__, __func__);
18061744 rc = -ENOMEM;
18071745 goto out;
18081746 }
18091747 if ((mpt3sas_config_get_sas_iounit_pg1(ioc, &mpi_reply,
18101748 sas_iounit_pg1, sz))) {
1811
- pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
1812
- ioc->name, __FILE__, __LINE__, __func__);
1749
+ ioc_err(ioc, "failure at %s:%d/%s()!\n",
1750
+ __FILE__, __LINE__, __func__);
18131751 rc = -ENXIO;
18141752 goto out;
18151753 }
18161754 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
18171755 MPI2_IOCSTATUS_MASK;
18181756 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
1819
- pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
1820
- ioc->name, __FILE__, __LINE__, __func__);
1757
+ ioc_err(ioc, "failure at %s:%d/%s()!\n",
1758
+ __FILE__, __LINE__, __func__);
18211759 rc = -EIO;
18221760 goto out;
18231761 }
....@@ -1836,8 +1774,8 @@
18361774
18371775 if (mpt3sas_config_set_sas_iounit_pg1(ioc, &mpi_reply, sas_iounit_pg1,
18381776 sz)) {
1839
- pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n",
1840
- ioc->name, __FILE__, __LINE__, __func__);
1777
+ ioc_err(ioc, "failure at %s:%d/%s()!\n",
1778
+ __FILE__, __LINE__, __func__);
18411779 rc = -ENXIO;
18421780 goto out;
18431781 }
....@@ -1913,7 +1851,6 @@
19131851 Mpi2SmpPassthroughReply_t *mpi_reply;
19141852 int rc;
19151853 u16 smid;
1916
- u32 ioc_state;
19171854 void *psge;
19181855 dma_addr_t dma_addr_in;
19191856 dma_addr_t dma_addr_out;
....@@ -1921,12 +1858,10 @@
19211858 void *addr_out = NULL;
19221859 size_t dma_len_in;
19231860 size_t dma_len_out;
1924
- u16 wait_state_count;
19251861 unsigned int reslen = 0;
19261862
19271863 if (ioc->shost_recovery || ioc->pci_error_recovery) {
1928
- pr_info(MPT3SAS_FMT "%s: host reset in progress!\n",
1929
- __func__, ioc->name);
1864
+ ioc_info(ioc, "%s: host reset in progress!\n", __func__);
19301865 rc = -EFAULT;
19311866 goto job_done;
19321867 }
....@@ -1936,8 +1871,8 @@
19361871 goto job_done;
19371872
19381873 if (ioc->transport_cmds.status != MPT3_CMD_NOT_USED) {
1939
- pr_err(MPT3SAS_FMT "%s: transport_cmds in use\n", ioc->name,
1940
- __func__);
1874
+ ioc_err(ioc, "%s: transport_cmds in use\n",
1875
+ __func__);
19411876 rc = -EAGAIN;
19421877 goto out;
19431878 }
....@@ -1958,30 +1893,13 @@
19581893 if (rc)
19591894 goto unmap_out;
19601895
1961
- wait_state_count = 0;
1962
- ioc_state = mpt3sas_base_get_iocstate(ioc, 1);
1963
- while (ioc_state != MPI2_IOC_STATE_OPERATIONAL) {
1964
- if (wait_state_count++ == 10) {
1965
- pr_err(MPT3SAS_FMT
1966
- "%s: failed due to ioc not operational\n",
1967
- ioc->name, __func__);
1968
- rc = -EFAULT;
1969
- goto unmap_in;
1970
- }
1971
- ssleep(1);
1972
- ioc_state = mpt3sas_base_get_iocstate(ioc, 1);
1973
- pr_info(MPT3SAS_FMT
1974
- "%s: waiting for operational state(count=%d)\n",
1975
- ioc->name, __func__, wait_state_count);
1976
- }
1977
- if (wait_state_count)
1978
- pr_info(MPT3SAS_FMT "%s: ioc is operational\n",
1979
- ioc->name, __func__);
1896
+ rc = mpt3sas_wait_for_ioc(ioc, IOC_OPERATIONAL_WAIT_COUNT);
1897
+ if (rc)
1898
+ goto unmap_in;
19801899
19811900 smid = mpt3sas_base_get_smid(ioc, ioc->transport_cb_idx);
19821901 if (!smid) {
1983
- pr_err(MPT3SAS_FMT "%s: failed obtaining a smid\n",
1984
- ioc->name, __func__);
1902
+ ioc_err(ioc, "%s: failed obtaining a smid\n", __func__);
19851903 rc = -EAGAIN;
19861904 goto unmap_in;
19871905 }
....@@ -2002,16 +1920,15 @@
20021920 ioc->build_sg(ioc, psge, dma_addr_out, dma_len_out - 4, dma_addr_in,
20031921 dma_len_in - 4);
20041922
2005
- dtransportprintk(ioc, pr_info(MPT3SAS_FMT
2006
- "%s - sending smp request\n", ioc->name, __func__));
1923
+ dtransportprintk(ioc,
1924
+ ioc_info(ioc, "%s: sending smp request\n", __func__));
20071925
20081926 init_completion(&ioc->transport_cmds.done);
2009
- mpt3sas_base_put_smid_default(ioc, smid);
1927
+ ioc->put_smid_default(ioc, smid);
20101928 wait_for_completion_timeout(&ioc->transport_cmds.done, 10*HZ);
20111929
20121930 if (!(ioc->transport_cmds.status & MPT3_CMD_COMPLETE)) {
2013
- pr_err(MPT3SAS_FMT "%s : timeout\n",
2014
- __func__, ioc->name);
1931
+ ioc_err(ioc, "%s: timeout\n", __func__);
20151932 _debug_dump_mf(mpi_request,
20161933 sizeof(Mpi2SmpPassthroughRequest_t)/4);
20171934 if (!(ioc->transport_cmds.status & MPT3_CMD_RESET)) {
....@@ -2021,12 +1938,11 @@
20211938 }
20221939 }
20231940
2024
- dtransportprintk(ioc, pr_info(MPT3SAS_FMT
2025
- "%s - complete\n", ioc->name, __func__));
1941
+ dtransportprintk(ioc, ioc_info(ioc, "%s - complete\n", __func__));
20261942
20271943 if (!(ioc->transport_cmds.status & MPT3_CMD_REPLY_VALID)) {
2028
- dtransportprintk(ioc, pr_info(MPT3SAS_FMT
2029
- "%s - no reply\n", ioc->name, __func__));
1944
+ dtransportprintk(ioc,
1945
+ ioc_info(ioc, "%s: no reply\n", __func__));
20301946 rc = -ENXIO;
20311947 goto unmap_in;
20321948 }
....@@ -2034,9 +1950,9 @@
20341950 mpi_reply = ioc->transport_cmds.reply;
20351951
20361952 dtransportprintk(ioc,
2037
- pr_info(MPT3SAS_FMT "%s - reply data transfer size(%d)\n",
2038
- ioc->name, __func__,
2039
- le16_to_cpu(mpi_reply->ResponseDataLength)));
1953
+ ioc_info(ioc, "%s: reply data transfer size(%d)\n",
1954
+ __func__,
1955
+ le16_to_cpu(mpi_reply->ResponseDataLength)));
20401956
20411957 memcpy(job->reply, mpi_reply, sizeof(*mpi_reply));
20421958 job->reply_len = sizeof(*mpi_reply);