forked from ~ljy/RK356X_SDK_RELEASE

hc
2024-05-10 9999e48639b3cecb08ffb37358bcba3b48161b29
kernel/drivers/s390/scsi/zfcp_scsi.c
....@@ -4,7 +4,7 @@
44 *
55 * Interface to Linux SCSI midlayer.
66 *
7
- * Copyright IBM Corp. 2002, 2018
7
+ * Copyright IBM Corp. 2002, 2020
88 */
99
1010 #define KMSG_COMPONENT "zfcp"
....@@ -27,7 +27,11 @@
2727
2828 static bool enable_dif;
2929 module_param_named(dif, enable_dif, bool, 0400);
30
-MODULE_PARM_DESC(dif, "Enable DIF/DIX data integrity support");
30
+MODULE_PARM_DESC(dif, "Enable DIF data integrity support (default off)");
31
+
32
+bool zfcp_experimental_dix;
33
+module_param_named(dix, zfcp_experimental_dix, bool, 0400);
34
+MODULE_PARM_DESC(dix, "Enable experimental DIX (data integrity extension) support which implies DIF support (default off)");
3135
3236 static bool allow_lun_scan = true;
3337 module_param(allow_lun_scan, bool, 0600);
....@@ -235,7 +239,9 @@
235239 (struct zfcp_scsi_req_filter *)data;
236240
237241 /* already aborted - prevent side-effects - or not a SCSI command */
238
- if (old_req->data == NULL || old_req->fsf_command != FSF_QTCB_FCP_CMND)
242
+ if (old_req->data == NULL ||
243
+ zfcp_fsf_req_is_status_read_buffer(old_req) ||
244
+ old_req->qtcb->header.fsf_command != FSF_QTCB_FCP_CMND)
239245 return;
240246
241247 /* (tmf_scope == FCP_TMF_TGT_RESET || tmf_scope == FCP_TMF_LUN_RESET) */
....@@ -435,8 +441,9 @@
435441 .max_sectors = (((QDIO_MAX_ELEMENTS_PER_BUFFER - 1)
436442 * ZFCP_QDIO_MAX_SBALS_PER_REQ) - 2) * 8,
437443 /* GCD, adjusted later */
444
+ /* report size limit per scatter-gather segment */
445
+ .max_segment_size = ZFCP_QDIO_SBALE_LEN,
438446 .dma_boundary = ZFCP_QDIO_SBALE_LEN - 1,
439
- .use_clustering = 1,
440447 .shost_attrs = zfcp_sysfs_shost_attrs,
441448 .sdev_attrs = zfcp_sysfs_sdev_attrs,
442449 .track_queue_depth = 1,
....@@ -444,26 +451,39 @@
444451 };
445452
446453 /**
447
- * zfcp_scsi_adapter_register - Register SCSI and FC host with SCSI midlayer
454
+ * zfcp_scsi_adapter_register() - Allocate and register SCSI and FC host with
455
+ * SCSI midlayer
448456 * @adapter: The zfcp adapter to register with the SCSI midlayer
457
+ *
458
+ * Allocates the SCSI host object for the given adapter, sets basic properties
459
+ * (such as the transport template, QDIO limits, ...), and registers it with
460
+ * the midlayer.
461
+ *
462
+ * During registration with the midlayer the corresponding FC host object for
463
+ * the referenced transport class is also implicitely allocated.
464
+ *
465
+ * Upon success adapter->scsi_host is set, and upon failure it remains NULL. If
466
+ * adapter->scsi_host is already set, nothing is done.
467
+ *
468
+ * Return:
469
+ * * 0 - Allocation and registration was successful
470
+ * * -EEXIST - SCSI and FC host did already exist, nothing was done, nothing
471
+ * was changed
472
+ * * -EIO - Allocation or registration failed
449473 */
450474 int zfcp_scsi_adapter_register(struct zfcp_adapter *adapter)
451475 {
452476 struct ccw_dev_id dev_id;
453477
454478 if (adapter->scsi_host)
455
- return 0;
479
+ return -EEXIST;
456480
457481 ccw_device_get_id(adapter->ccw_device, &dev_id);
458482 /* register adapter as SCSI host with mid layer of SCSI stack */
459483 adapter->scsi_host = scsi_host_alloc(&zfcp_scsi_host_template,
460484 sizeof (struct zfcp_adapter *));
461
- if (!adapter->scsi_host) {
462
- dev_err(&adapter->ccw_device->dev,
463
- "Registering the FCP device with the "
464
- "SCSI stack failed\n");
465
- return -EIO;
466
- }
485
+ if (!adapter->scsi_host)
486
+ goto err_out;
467487
468488 /* tell the SCSI stack some characteristics of this adapter */
469489 adapter->scsi_host->max_id = 511;
....@@ -473,14 +493,23 @@
473493 adapter->scsi_host->max_cmd_len = 16; /* in struct fcp_cmnd */
474494 adapter->scsi_host->transportt = zfcp_scsi_transport_template;
475495
496
+ /* make all basic properties known at registration time */
497
+ zfcp_qdio_shost_update(adapter, adapter->qdio);
498
+ zfcp_scsi_set_prot(adapter);
499
+
476500 adapter->scsi_host->hostdata[0] = (unsigned long) adapter;
477501
478502 if (scsi_add_host(adapter->scsi_host, &adapter->ccw_device->dev)) {
479503 scsi_host_put(adapter->scsi_host);
480
- return -EIO;
504
+ goto err_out;
481505 }
482506
483507 return 0;
508
+err_out:
509
+ adapter->scsi_host = NULL;
510
+ dev_err(&adapter->ccw_device->dev,
511
+ "Registering the FCP device with the SCSI stack failed\n");
512
+ return -EIO;
484513 }
485514
486515 /**
....@@ -598,7 +627,7 @@
598627 return NULL;
599628
600629 ret = zfcp_fsf_exchange_port_data_sync(adapter->qdio, data);
601
- if (ret) {
630
+ if (ret != 0 && ret != -EAGAIN) {
602631 kfree(data);
603632 return NULL;
604633 }
....@@ -627,7 +656,7 @@
627656 return;
628657
629658 ret = zfcp_fsf_exchange_port_data_sync(adapter->qdio, data);
630
- if (ret)
659
+ if (ret != 0 && ret != -EAGAIN)
631660 kfree(data);
632661 else {
633662 adapter->stats_reset = jiffies/HZ;
....@@ -801,11 +830,11 @@
801830 data_div = atomic_read(&adapter->status) &
802831 ZFCP_STATUS_ADAPTER_DATA_DIV_ENABLED;
803832
804
- if (enable_dif &&
833
+ if ((enable_dif || zfcp_experimental_dix) &&
805834 adapter->adapter_features & FSF_FEATURE_DIF_PROT_TYPE1)
806835 mask |= SHOST_DIF_TYPE1_PROTECTION;
807836
808
- if (enable_dif && data_div &&
837
+ if (zfcp_experimental_dix && data_div &&
809838 adapter->adapter_features & FSF_FEATURE_DIX_PROT_TCPIP) {
810839 mask |= SHOST_DIX_TYPE1_PROTECTION;
811840 scsi_host_set_guard(shost, SHOST_DIX_GUARD_IP);
....@@ -834,6 +863,95 @@
834863 set_host_byte(scmd, DID_SOFT_ERROR);
835864 }
836865
866
+void zfcp_scsi_shost_update_config_data(
867
+ struct zfcp_adapter *const adapter,
868
+ const struct fsf_qtcb_bottom_config *const bottom,
869
+ const bool bottom_incomplete)
870
+{
871
+ struct Scsi_Host *const shost = adapter->scsi_host;
872
+ const struct fc_els_flogi *nsp, *plogi;
873
+
874
+ if (shost == NULL)
875
+ return;
876
+
877
+ snprintf(fc_host_firmware_version(shost), FC_VERSION_STRING_SIZE,
878
+ "0x%08x", bottom->lic_version);
879
+
880
+ if (adapter->adapter_features & FSF_FEATURE_HBAAPI_MANAGEMENT) {
881
+ snprintf(fc_host_hardware_version(shost),
882
+ FC_VERSION_STRING_SIZE,
883
+ "0x%08x", bottom->hardware_version);
884
+ memcpy(fc_host_serial_number(shost), bottom->serial_number,
885
+ min(FC_SERIAL_NUMBER_SIZE, 17));
886
+ EBCASC(fc_host_serial_number(shost),
887
+ min(FC_SERIAL_NUMBER_SIZE, 17));
888
+ }
889
+
890
+ /* adjust pointers for missing command code */
891
+ nsp = (struct fc_els_flogi *) ((u8 *)&bottom->nport_serv_param
892
+ - sizeof(u32));
893
+ plogi = (struct fc_els_flogi *) ((u8 *)&bottom->plogi_payload
894
+ - sizeof(u32));
895
+
896
+ snprintf(fc_host_manufacturer(shost), FC_SERIAL_NUMBER_SIZE, "%s",
897
+ "IBM");
898
+ fc_host_port_name(shost) = be64_to_cpu(nsp->fl_wwpn);
899
+ fc_host_node_name(shost) = be64_to_cpu(nsp->fl_wwnn);
900
+ fc_host_supported_classes(shost) = FC_COS_CLASS2 | FC_COS_CLASS3;
901
+
902
+ zfcp_scsi_set_prot(adapter);
903
+
904
+ /* do not evaluate invalid fields */
905
+ if (bottom_incomplete)
906
+ return;
907
+
908
+ fc_host_port_id(shost) = ntoh24(bottom->s_id);
909
+ fc_host_speed(shost) =
910
+ zfcp_fsf_convert_portspeed(bottom->fc_link_speed);
911
+
912
+ snprintf(fc_host_model(shost), FC_SYMBOLIC_NAME_SIZE, "0x%04x",
913
+ bottom->adapter_type);
914
+
915
+ switch (bottom->fc_topology) {
916
+ case FSF_TOPO_P2P:
917
+ fc_host_port_type(shost) = FC_PORTTYPE_PTP;
918
+ fc_host_fabric_name(shost) = 0;
919
+ break;
920
+ case FSF_TOPO_FABRIC:
921
+ fc_host_fabric_name(shost) = be64_to_cpu(plogi->fl_wwnn);
922
+ if (bottom->connection_features & FSF_FEATURE_NPIV_MODE)
923
+ fc_host_port_type(shost) = FC_PORTTYPE_NPIV;
924
+ else
925
+ fc_host_port_type(shost) = FC_PORTTYPE_NPORT;
926
+ break;
927
+ case FSF_TOPO_AL:
928
+ fc_host_port_type(shost) = FC_PORTTYPE_NLPORT;
929
+ fallthrough;
930
+ default:
931
+ fc_host_fabric_name(shost) = 0;
932
+ break;
933
+ }
934
+}
935
+
936
+void zfcp_scsi_shost_update_port_data(
937
+ struct zfcp_adapter *const adapter,
938
+ const struct fsf_qtcb_bottom_port *const bottom)
939
+{
940
+ struct Scsi_Host *const shost = adapter->scsi_host;
941
+
942
+ if (shost == NULL)
943
+ return;
944
+
945
+ fc_host_permanent_port_name(shost) = bottom->wwpn;
946
+ fc_host_maxframe_size(shost) = bottom->maximum_frame_size;
947
+ fc_host_supported_speeds(shost) =
948
+ zfcp_fsf_convert_portspeed(bottom->supported_speed);
949
+ memcpy(fc_host_supported_fc4s(shost), bottom->supported_fc4_types,
950
+ FC_FC4_LIST_SIZE);
951
+ memcpy(fc_host_active_fc4s(shost), bottom->active_fc4_types,
952
+ FC_FC4_LIST_SIZE);
953
+}
954
+
837955 struct fc_function_template zfcp_transport_functions = {
838956 .show_starget_port_id = 1,
839957 .show_starget_port_name = 1,
....@@ -849,6 +967,10 @@
849967 .show_host_supported_speeds = 1,
850968 .show_host_maxframe_size = 1,
851969 .show_host_serial_number = 1,
970
+ .show_host_manufacturer = 1,
971
+ .show_host_model = 1,
972
+ .show_host_hardware_version = 1,
973
+ .show_host_firmware_version = 1,
852974 .get_fc_host_stats = zfcp_scsi_get_fc_host_stats,
853975 .reset_fc_host_stats = zfcp_scsi_reset_fc_host_stats,
854976 .set_rport_dev_loss_tmo = zfcp_scsi_set_rport_dev_loss_tmo,
....@@ -864,5 +986,6 @@
864986 .show_host_symbolic_name = 1,
865987 .show_host_speed = 1,
866988 .show_host_port_id = 1,
989
+ .show_host_fabric_name = 1,
867990 .dd_bsg_size = sizeof(struct zfcp_fsf_ct_els),
868991 };