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 | |
Paul Gortmaker | 0970366 | 2011-05-27 09:37:25 -0400 | [diff] [blame] | 24 | #include <linux/export.h> |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 25 | #include <asm/unaligned.h> |
| 26 | #include <scsi/fc/fc_gs.h> |
| 27 | #include <scsi/fc/fc_ns.h> |
| 28 | #include <scsi/fc/fc_els.h> |
| 29 | #include <scsi/libfc.h> |
| 30 | #include <scsi/fc_encode.h> |
Bart Van Assche | c6b21c9 | 2012-01-13 17:26:20 -0800 | [diff] [blame] | 31 | #include "fc_libfc.h" |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 32 | |
Robert Love | 3a3b42b | 2009-11-03 11:47:39 -0800 | [diff] [blame] | 33 | /** |
| 34 | * fc_elsct_send() - Send an ELS or CT frame |
| 35 | * @lport: The local port to send the frame on |
| 36 | * @did: The destination ID for the frame |
| 37 | * @fp: The frame to be sent |
| 38 | * @op: The operational code |
| 39 | * @resp: The callback routine when the response is received |
| 40 | * @arg: The argument to pass to the response callback routine |
| 41 | * @timer_msec: The timeout period for the frame (in msecs) |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 42 | */ |
Robert Love | 3a3b42b | 2009-11-03 11:47:39 -0800 | [diff] [blame] | 43 | struct fc_seq *fc_elsct_send(struct fc_lport *lport, u32 did, |
| 44 | struct fc_frame *fp, unsigned int op, |
| 45 | void (*resp)(struct fc_seq *, |
| 46 | struct fc_frame *, |
| 47 | void *), |
| 48 | void *arg, u32 timer_msec) |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 49 | { |
| 50 | enum fc_rctl r_ctl; |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 51 | enum fc_fh_type fh_type; |
| 52 | int rc; |
| 53 | |
| 54 | /* ELS requests */ |
| 55 | if ((op >= ELS_LS_RJT) && (op <= ELS_AUTH_ELS)) |
Joe Eykholt | a46f327 | 2009-08-25 14:00:55 -0700 | [diff] [blame] | 56 | rc = fc_els_fill(lport, did, fp, op, &r_ctl, &fh_type); |
| 57 | else { |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 58 | /* CT requests */ |
Neerav Parikh | 1ea2c1d | 2012-01-22 17:30:00 -0800 | [diff] [blame] | 59 | rc = fc_ct_fill(lport, did, fp, op, &r_ctl, &fh_type, &did); |
Joe Eykholt | a46f327 | 2009-08-25 14:00:55 -0700 | [diff] [blame] | 60 | } |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 61 | |
Chris Leech | 8f550f9 | 2009-10-21 16:28:09 -0700 | [diff] [blame] | 62 | if (rc) { |
| 63 | fc_frame_free(fp); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 64 | return NULL; |
Chris Leech | 8f550f9 | 2009-10-21 16:28:09 -0700 | [diff] [blame] | 65 | } |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 66 | |
Robert Love | 7b2787e | 2010-05-07 15:18:41 -0700 | [diff] [blame] | 67 | fc_fill_fc_hdr(fp, r_ctl, did, lport->port_id, fh_type, |
Joe Eykholt | 24f089e | 2010-07-20 15:21:01 -0700 | [diff] [blame] | 68 | FC_FCTL_REQ, 0); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 69 | |
| 70 | return lport->tt.exch_seq_send(lport, fp, resp, NULL, arg, timer_msec); |
| 71 | } |
Chris Leech | 11b5618 | 2009-11-03 11:46:29 -0800 | [diff] [blame] | 72 | EXPORT_SYMBOL(fc_elsct_send); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 73 | |
Robert Love | 3a3b42b | 2009-11-03 11:47:39 -0800 | [diff] [blame] | 74 | /** |
| 75 | * fc_elsct_init() - Initialize the ELS/CT layer |
| 76 | * @lport: The local port to initialize the ELS/CT layer for |
| 77 | */ |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 78 | int fc_elsct_init(struct fc_lport *lport) |
| 79 | { |
| 80 | if (!lport->tt.elsct_send) |
| 81 | lport->tt.elsct_send = fc_elsct_send; |
| 82 | |
| 83 | return 0; |
| 84 | } |
| 85 | EXPORT_SYMBOL(fc_elsct_init); |
Joe Eykholt | f657d29 | 2009-08-25 14:03:21 -0700 | [diff] [blame] | 86 | |
| 87 | /** |
Robert Love | 3a3b42b | 2009-11-03 11:47:39 -0800 | [diff] [blame] | 88 | * fc_els_resp_type() - Return a string describing the ELS response |
| 89 | * @fp: The frame pointer or possible error code |
Joe Eykholt | f657d29 | 2009-08-25 14:03:21 -0700 | [diff] [blame] | 90 | */ |
| 91 | const char *fc_els_resp_type(struct fc_frame *fp) |
| 92 | { |
| 93 | const char *msg; |
Joe Eykholt | 52a6690 | 2009-11-03 11:49:00 -0800 | [diff] [blame] | 94 | struct fc_frame_header *fh; |
| 95 | struct fc_ct_hdr *ct; |
| 96 | |
Joe Eykholt | f657d29 | 2009-08-25 14:03:21 -0700 | [diff] [blame] | 97 | if (IS_ERR(fp)) { |
| 98 | switch (-PTR_ERR(fp)) { |
| 99 | case FC_NO_ERR: |
| 100 | msg = "response no error"; |
| 101 | break; |
| 102 | case FC_EX_TIMEOUT: |
| 103 | msg = "response timeout"; |
| 104 | break; |
| 105 | case FC_EX_CLOSED: |
| 106 | msg = "response closed"; |
| 107 | break; |
| 108 | default: |
| 109 | msg = "response unknown error"; |
| 110 | break; |
| 111 | } |
| 112 | } else { |
Joe Eykholt | 52a6690 | 2009-11-03 11:49:00 -0800 | [diff] [blame] | 113 | fh = fc_frame_header_get(fp); |
| 114 | switch (fh->fh_type) { |
| 115 | case FC_TYPE_ELS: |
| 116 | switch (fc_frame_payload_op(fp)) { |
| 117 | case ELS_LS_ACC: |
| 118 | msg = "accept"; |
| 119 | break; |
| 120 | case ELS_LS_RJT: |
| 121 | msg = "reject"; |
| 122 | break; |
| 123 | default: |
| 124 | msg = "response unknown ELS"; |
| 125 | break; |
| 126 | } |
Joe Eykholt | f657d29 | 2009-08-25 14:03:21 -0700 | [diff] [blame] | 127 | break; |
Joe Eykholt | 52a6690 | 2009-11-03 11:49:00 -0800 | [diff] [blame] | 128 | case FC_TYPE_CT: |
| 129 | ct = fc_frame_payload_get(fp, sizeof(*ct)); |
| 130 | if (ct) { |
| 131 | switch (ntohs(ct->ct_cmd)) { |
| 132 | case FC_FS_ACC: |
| 133 | msg = "CT accept"; |
| 134 | break; |
| 135 | case FC_FS_RJT: |
| 136 | msg = "CT reject"; |
| 137 | break; |
| 138 | default: |
| 139 | msg = "response unknown CT"; |
| 140 | break; |
| 141 | } |
| 142 | } else { |
| 143 | msg = "short CT response"; |
| 144 | } |
Joe Eykholt | f657d29 | 2009-08-25 14:03:21 -0700 | [diff] [blame] | 145 | break; |
| 146 | default: |
Joe Eykholt | 52a6690 | 2009-11-03 11:49:00 -0800 | [diff] [blame] | 147 | msg = "response not ELS or CT"; |
Joe Eykholt | f657d29 | 2009-08-25 14:03:21 -0700 | [diff] [blame] | 148 | break; |
| 149 | } |
| 150 | } |
| 151 | return msg; |
| 152 | } |