fc_elsct.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Copyright(c) 2008 Intel Corporation. All rights reserved.
  4. *
  5. * Maintained at www.Open-FCoE.org
  6. */
  7. /*
  8. * Provide interface to send ELS/CT FC frames
  9. */
  10. #include <linux/export.h>
  11. #include <asm/unaligned.h>
  12. #include <scsi/fc/fc_gs.h>
  13. #include <scsi/fc/fc_ns.h>
  14. #include <scsi/fc/fc_els.h>
  15. #include <scsi/libfc.h>
  16. #include "fc_encode.h"
  17. #include "fc_libfc.h"
  18. /**
  19. * fc_elsct_send() - Send an ELS or CT frame
  20. * @lport: The local port to send the frame on
  21. * @did: The destination ID for the frame
  22. * @fp: The frame to be sent
  23. * @op: The operational code
  24. * @resp: The callback routine when the response is received
  25. * @arg: The argument to pass to the response callback routine
  26. * @timer_msec: The timeout period for the frame (in msecs)
  27. */
  28. struct fc_seq *fc_elsct_send(struct fc_lport *lport, u32 did,
  29. struct fc_frame *fp, unsigned int op,
  30. void (*resp)(struct fc_seq *,
  31. struct fc_frame *,
  32. void *),
  33. void *arg, u32 timer_msec)
  34. {
  35. enum fc_rctl r_ctl;
  36. enum fc_fh_type fh_type;
  37. int rc;
  38. /* ELS requests */
  39. if ((op >= ELS_LS_RJT) && (op <= ELS_AUTH_ELS))
  40. rc = fc_els_fill(lport, did, fp, op, &r_ctl, &fh_type);
  41. else {
  42. /* CT requests */
  43. rc = fc_ct_fill(lport, did, fp, op, &r_ctl, &fh_type, &did);
  44. }
  45. if (rc) {
  46. fc_frame_free(fp);
  47. return NULL;
  48. }
  49. fc_fill_fc_hdr(fp, r_ctl, did, lport->port_id, fh_type,
  50. FC_FCTL_REQ, 0);
  51. return fc_exch_seq_send(lport, fp, resp, NULL, arg, timer_msec);
  52. }
  53. EXPORT_SYMBOL(fc_elsct_send);
  54. /**
  55. * fc_elsct_init() - Initialize the ELS/CT layer
  56. * @lport: The local port to initialize the ELS/CT layer for
  57. */
  58. int fc_elsct_init(struct fc_lport *lport)
  59. {
  60. if (!lport->tt.elsct_send)
  61. lport->tt.elsct_send = fc_elsct_send;
  62. return 0;
  63. }
  64. EXPORT_SYMBOL(fc_elsct_init);
  65. /**
  66. * fc_els_resp_type() - Return a string describing the ELS response
  67. * @fp: The frame pointer or possible error code
  68. */
  69. const char *fc_els_resp_type(struct fc_frame *fp)
  70. {
  71. const char *msg;
  72. struct fc_frame_header *fh;
  73. struct fc_ct_hdr *ct;
  74. if (IS_ERR(fp)) {
  75. switch (-PTR_ERR(fp)) {
  76. case FC_NO_ERR:
  77. msg = "response no error";
  78. break;
  79. case FC_EX_TIMEOUT:
  80. msg = "response timeout";
  81. break;
  82. case FC_EX_CLOSED:
  83. msg = "response closed";
  84. break;
  85. default:
  86. msg = "response unknown error";
  87. break;
  88. }
  89. } else {
  90. fh = fc_frame_header_get(fp);
  91. switch (fh->fh_type) {
  92. case FC_TYPE_ELS:
  93. switch (fc_frame_payload_op(fp)) {
  94. case ELS_LS_ACC:
  95. msg = "accept";
  96. break;
  97. case ELS_LS_RJT:
  98. msg = "reject";
  99. break;
  100. default:
  101. msg = "response unknown ELS";
  102. break;
  103. }
  104. break;
  105. case FC_TYPE_CT:
  106. ct = fc_frame_payload_get(fp, sizeof(*ct));
  107. if (ct) {
  108. switch (ntohs(ct->ct_cmd)) {
  109. case FC_FS_ACC:
  110. msg = "CT accept";
  111. break;
  112. case FC_FS_RJT:
  113. msg = "CT reject";
  114. break;
  115. default:
  116. msg = "response unknown CT";
  117. break;
  118. }
  119. } else {
  120. msg = "short CT response";
  121. }
  122. break;
  123. default:
  124. msg = "response not ELS or CT";
  125. break;
  126. }
  127. }
  128. return msg;
  129. }