Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 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 | /* |
| 21 | * Provide interface to send ELS/CT FC frames |
| 22 | */ |
| 23 | |
| 24 | #include <asm/unaligned.h> |
| 25 | #include <scsi/fc/fc_gs.h> |
| 26 | #include <scsi/fc/fc_ns.h> |
| 27 | #include <scsi/fc/fc_els.h> |
| 28 | #include <scsi/libfc.h> |
| 29 | #include <scsi/fc_encode.h> |
| 30 | |
| 31 | /* |
| 32 | * fc_elsct_send - sends ELS/CT frame |
| 33 | */ |
| 34 | static struct fc_seq *fc_elsct_send(struct fc_lport *lport, |
Joe Eykholt | a46f327 | 2009-08-25 14:00:55 -0700 | [diff] [blame] | 35 | u32 did, |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 36 | struct fc_frame *fp, |
| 37 | unsigned int op, |
| 38 | void (*resp)(struct fc_seq *, |
| 39 | struct fc_frame *fp, |
| 40 | void *arg), |
| 41 | void *arg, u32 timer_msec) |
| 42 | { |
| 43 | enum fc_rctl r_ctl; |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 44 | enum fc_fh_type fh_type; |
| 45 | int rc; |
| 46 | |
| 47 | /* ELS requests */ |
| 48 | if ((op >= ELS_LS_RJT) && (op <= ELS_AUTH_ELS)) |
Joe Eykholt | a46f327 | 2009-08-25 14:00:55 -0700 | [diff] [blame] | 49 | rc = fc_els_fill(lport, did, fp, op, &r_ctl, &fh_type); |
| 50 | else { |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 51 | /* CT requests */ |
Joe Eykholt | 2ab7e1e | 2009-08-25 14:03:58 -0700 | [diff] [blame] | 52 | rc = fc_ct_fill(lport, did, fp, op, &r_ctl, &fh_type); |
Joe Eykholt | a46f327 | 2009-08-25 14:00:55 -0700 | [diff] [blame] | 53 | did = FC_FID_DIR_SERV; |
| 54 | } |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 55 | |
Chris Leech | 8f550f9 | 2009-10-21 16:28:09 -0700 | [diff] [blame^] | 56 | if (rc) { |
| 57 | fc_frame_free(fp); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 58 | return NULL; |
Chris Leech | 8f550f9 | 2009-10-21 16:28:09 -0700 | [diff] [blame^] | 59 | } |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 60 | |
| 61 | fc_fill_fc_hdr(fp, r_ctl, did, fc_host_port_id(lport->host), fh_type, |
| 62 | FC_FC_FIRST_SEQ | FC_FC_END_SEQ | FC_FC_SEQ_INIT, 0); |
| 63 | |
| 64 | return lport->tt.exch_seq_send(lport, fp, resp, NULL, arg, timer_msec); |
| 65 | } |
| 66 | |
| 67 | int fc_elsct_init(struct fc_lport *lport) |
| 68 | { |
| 69 | if (!lport->tt.elsct_send) |
| 70 | lport->tt.elsct_send = fc_elsct_send; |
| 71 | |
| 72 | return 0; |
| 73 | } |
| 74 | EXPORT_SYMBOL(fc_elsct_init); |
Joe Eykholt | f657d29 | 2009-08-25 14:03:21 -0700 | [diff] [blame] | 75 | |
| 76 | /** |
| 77 | * fc_els_resp_type() - return string describing ELS response for debug. |
| 78 | * @fp: frame pointer with possible error code. |
| 79 | */ |
| 80 | const char *fc_els_resp_type(struct fc_frame *fp) |
| 81 | { |
| 82 | const char *msg; |
| 83 | if (IS_ERR(fp)) { |
| 84 | switch (-PTR_ERR(fp)) { |
| 85 | case FC_NO_ERR: |
| 86 | msg = "response no error"; |
| 87 | break; |
| 88 | case FC_EX_TIMEOUT: |
| 89 | msg = "response timeout"; |
| 90 | break; |
| 91 | case FC_EX_CLOSED: |
| 92 | msg = "response closed"; |
| 93 | break; |
| 94 | default: |
| 95 | msg = "response unknown error"; |
| 96 | break; |
| 97 | } |
| 98 | } else { |
| 99 | switch (fc_frame_payload_op(fp)) { |
| 100 | case ELS_LS_ACC: |
| 101 | msg = "accept"; |
| 102 | break; |
| 103 | case ELS_LS_RJT: |
| 104 | msg = "reject"; |
| 105 | break; |
| 106 | default: |
| 107 | msg = "response unknown ELS"; |
| 108 | break; |
| 109 | } |
| 110 | } |
| 111 | return msg; |
| 112 | } |