fc_elsct.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. /*
  2. * Copyright(c) 2008 Intel Corporation. All rights reserved.
  3. *
  4. * This program is free software; you can redistribute it and/or modify it
  5. * under the terms and conditions of the GNU General Public License,
  6. * version 2, as published by the Free Software Foundation.
  7. *
  8. * This program is distributed in the hope it will be useful, but WITHOUT
  9. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  10. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  11. * more details.
  12. *
  13. * You should have received a copy of the GNU General Public License along with
  14. * this program; if not, write to the Free Software Foundation, Inc.,
  15. * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
  16. *
  17. * Maintained at www.Open-FCoE.org
  18. */
  19. /*
  20. * Provide interface to send ELS/CT FC frames
  21. */
  22. #include <linux/export.h>
  23. #include <asm/unaligned.h>
  24. #include <scsi/fc/fc_gs.h>
  25. #include <scsi/fc/fc_ns.h>
  26. #include <scsi/fc/fc_els.h>
  27. #include <scsi/libfc.h>
  28. #include <scsi/fc_encode.h>
  29. #include "fc_libfc.h"
  30. /**
  31. * fc_elsct_send() - Send an ELS or CT frame
  32. * @lport: The local port to send the frame on
  33. * @did: The destination ID for the frame
  34. * @fp: The frame to be sent
  35. * @op: The operational code
  36. * @resp: The callback routine when the response is received
  37. * @arg: The argument to pass to the response callback routine
  38. * @timer_msec: The timeout period for the frame (in msecs)
  39. */
  40. struct fc_seq *fc_elsct_send(struct fc_lport *lport, u32 did,
  41. struct fc_frame *fp, unsigned int op,
  42. void (*resp)(struct fc_seq *,
  43. struct fc_frame *,
  44. void *),
  45. void *arg, u32 timer_msec)
  46. {
  47. enum fc_rctl r_ctl;
  48. enum fc_fh_type fh_type;
  49. int rc;
  50. /* ELS requests */
  51. if ((op >= ELS_LS_RJT) && (op <= ELS_AUTH_ELS))
  52. rc = fc_els_fill(lport, did, fp, op, &r_ctl, &fh_type);
  53. else {
  54. /* CT requests */
  55. rc = fc_ct_fill(lport, did, fp, op, &r_ctl, &fh_type);
  56. did = FC_FID_DIR_SERV;
  57. }
  58. if (rc) {
  59. fc_frame_free(fp);
  60. return NULL;
  61. }
  62. fc_fill_fc_hdr(fp, r_ctl, did, lport->port_id, fh_type,
  63. FC_FCTL_REQ, 0);
  64. return lport->tt.exch_seq_send(lport, fp, resp, NULL, arg, timer_msec);
  65. }
  66. EXPORT_SYMBOL(fc_elsct_send);
  67. /**
  68. * fc_elsct_init() - Initialize the ELS/CT layer
  69. * @lport: The local port to initialize the ELS/CT layer for
  70. */
  71. int fc_elsct_init(struct fc_lport *lport)
  72. {
  73. if (!lport->tt.elsct_send)
  74. lport->tt.elsct_send = fc_elsct_send;
  75. return 0;
  76. }
  77. EXPORT_SYMBOL(fc_elsct_init);
  78. /**
  79. * fc_els_resp_type() - Return a string describing the ELS response
  80. * @fp: The frame pointer or possible error code
  81. */
  82. const char *fc_els_resp_type(struct fc_frame *fp)
  83. {
  84. const char *msg;
  85. struct fc_frame_header *fh;
  86. struct fc_ct_hdr *ct;
  87. if (IS_ERR(fp)) {
  88. switch (-PTR_ERR(fp)) {
  89. case FC_NO_ERR:
  90. msg = "response no error";
  91. break;
  92. case FC_EX_TIMEOUT:
  93. msg = "response timeout";
  94. break;
  95. case FC_EX_CLOSED:
  96. msg = "response closed";
  97. break;
  98. default:
  99. msg = "response unknown error";
  100. break;
  101. }
  102. } else {
  103. fh = fc_frame_header_get(fp);
  104. switch (fh->fh_type) {
  105. case FC_TYPE_ELS:
  106. switch (fc_frame_payload_op(fp)) {
  107. case ELS_LS_ACC:
  108. msg = "accept";
  109. break;
  110. case ELS_LS_RJT:
  111. msg = "reject";
  112. break;
  113. default:
  114. msg = "response unknown ELS";
  115. break;
  116. }
  117. break;
  118. case FC_TYPE_CT:
  119. ct = fc_frame_payload_get(fp, sizeof(*ct));
  120. if (ct) {
  121. switch (ntohs(ct->ct_cmd)) {
  122. case FC_FS_ACC:
  123. msg = "CT accept";
  124. break;
  125. case FC_FS_RJT:
  126. msg = "CT reject";
  127. break;
  128. default:
  129. msg = "response unknown CT";
  130. break;
  131. }
  132. } else {
  133. msg = "short CT response";
  134. }
  135. break;
  136. default:
  137. msg = "response not ELS or CT";
  138. break;
  139. }
  140. }
  141. return msg;
  142. }