fc_elsct.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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 <asm/unaligned.h>
  23. #include <scsi/fc/fc_gs.h>
  24. #include <scsi/fc/fc_ns.h>
  25. #include <scsi/fc/fc_els.h>
  26. #include <scsi/libfc.h>
  27. #include <scsi/fc_encode.h>
  28. /*
  29. * fc_elsct_send - sends ELS/CT frame
  30. */
  31. static struct fc_seq *fc_elsct_send(struct fc_lport *lport,
  32. u32 did,
  33. struct fc_frame *fp,
  34. unsigned int op,
  35. void (*resp)(struct fc_seq *,
  36. struct fc_frame *fp,
  37. void *arg),
  38. void *arg, u32 timer_msec)
  39. {
  40. enum fc_rctl r_ctl;
  41. enum fc_fh_type fh_type;
  42. int rc;
  43. /* ELS requests */
  44. if ((op >= ELS_LS_RJT) && (op <= ELS_AUTH_ELS))
  45. rc = fc_els_fill(lport, did, fp, op, &r_ctl, &fh_type);
  46. else {
  47. /* CT requests */
  48. rc = fc_ct_fill(lport, did, fp, op, &r_ctl, &fh_type);
  49. did = FC_FID_DIR_SERV;
  50. }
  51. if (rc)
  52. return NULL;
  53. fc_fill_fc_hdr(fp, r_ctl, did, fc_host_port_id(lport->host), fh_type,
  54. FC_FC_FIRST_SEQ | FC_FC_END_SEQ | FC_FC_SEQ_INIT, 0);
  55. return lport->tt.exch_seq_send(lport, fp, resp, NULL, arg, timer_msec);
  56. }
  57. int fc_elsct_init(struct fc_lport *lport)
  58. {
  59. if (!lport->tt.elsct_send)
  60. lport->tt.elsct_send = fc_elsct_send;
  61. return 0;
  62. }
  63. EXPORT_SYMBOL(fc_elsct_init);
  64. /**
  65. * fc_els_resp_type() - return string describing ELS response for debug.
  66. * @fp: frame pointer with possible error code.
  67. */
  68. const char *fc_els_resp_type(struct fc_frame *fp)
  69. {
  70. const char *msg;
  71. if (IS_ERR(fp)) {
  72. switch (-PTR_ERR(fp)) {
  73. case FC_NO_ERR:
  74. msg = "response no error";
  75. break;
  76. case FC_EX_TIMEOUT:
  77. msg = "response timeout";
  78. break;
  79. case FC_EX_CLOSED:
  80. msg = "response closed";
  81. break;
  82. default:
  83. msg = "response unknown error";
  84. break;
  85. }
  86. } else {
  87. switch (fc_frame_payload_op(fp)) {
  88. case ELS_LS_ACC:
  89. msg = "accept";
  90. break;
  91. case ELS_LS_RJT:
  92. msg = "reject";
  93. break;
  94. default:
  95. msg = "response unknown ELS";
  96. break;
  97. }
  98. }
  99. return msg;
  100. }