Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright(c) 2007 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 | * PORT LOCKING NOTES |
| 22 | * |
| 23 | * These comments only apply to the 'port code' which consists of the lport, |
| 24 | * disc and rport blocks. |
| 25 | * |
| 26 | * MOTIVATION |
| 27 | * |
| 28 | * The lport, disc and rport blocks all have mutexes that are used to protect |
| 29 | * those objects. The main motivation for these locks is to prevent from |
| 30 | * having an lport reset just before we send a frame. In that scenario the |
| 31 | * lport's FID would get set to zero and then we'd send a frame with an |
| 32 | * invalid SID. We also need to ensure that states don't change unexpectedly |
| 33 | * while processing another state. |
| 34 | * |
| 35 | * HEIRARCHY |
| 36 | * |
| 37 | * The following heirarchy defines the locking rules. A greater lock |
| 38 | * may be held before acquiring a lesser lock, but a lesser lock should never |
| 39 | * be held while attempting to acquire a greater lock. Here is the heirarchy- |
| 40 | * |
| 41 | * lport > disc, lport > rport, disc > rport |
| 42 | * |
| 43 | * CALLBACKS |
| 44 | * |
| 45 | * The callbacks cause complications with this scheme. There is a callback |
| 46 | * from the rport (to either lport or disc) and a callback from disc |
| 47 | * (to the lport). |
| 48 | * |
| 49 | * As rports exit the rport state machine a callback is made to the owner of |
| 50 | * the rport to notify success or failure. Since the callback is likely to |
| 51 | * cause the lport or disc to grab its lock we cannot hold the rport lock |
| 52 | * while making the callback. To ensure that the rport is not free'd while |
| 53 | * processing the callback the rport callbacks are serialized through a |
| 54 | * single-threaded workqueue. An rport would never be free'd while in a |
| 55 | * callback handler becuase no other rport work in this queue can be executed |
| 56 | * at the same time. |
| 57 | * |
| 58 | * When discovery succeeds or fails a callback is made to the lport as |
| 59 | * notification. Currently, succesful discovery causes the lport to take no |
| 60 | * action. A failure will cause the lport to reset. There is likely a circular |
| 61 | * locking problem with this implementation. |
| 62 | */ |
| 63 | |
| 64 | /* |
| 65 | * LPORT LOCKING |
| 66 | * |
| 67 | * The critical sections protected by the lport's mutex are quite broad and |
| 68 | * may be improved upon in the future. The lport code and its locking doesn't |
| 69 | * influence the I/O path, so excessive locking doesn't penalize I/O |
| 70 | * performance. |
| 71 | * |
| 72 | * The strategy is to lock whenever processing a request or response. Note |
| 73 | * that every _enter_* function corresponds to a state change. They generally |
| 74 | * change the lports state and then send a request out on the wire. We lock |
| 75 | * before calling any of these functions to protect that state change. This |
| 76 | * means that the entry points into the lport block manage the locks while |
| 77 | * the state machine can transition between states (i.e. _enter_* functions) |
| 78 | * while always staying protected. |
| 79 | * |
| 80 | * When handling responses we also hold the lport mutex broadly. When the |
| 81 | * lport receives the response frame it locks the mutex and then calls the |
| 82 | * appropriate handler for the particuar response. Generally a response will |
| 83 | * trigger a state change and so the lock must already be held. |
| 84 | * |
| 85 | * Retries also have to consider the locking. The retries occur from a work |
| 86 | * context and the work function will lock the lport and then retry the state |
| 87 | * (i.e. _enter_* function). |
| 88 | */ |
| 89 | |
| 90 | #include <linux/timer.h> |
| 91 | #include <asm/unaligned.h> |
| 92 | |
| 93 | #include <scsi/fc/fc_gs.h> |
| 94 | |
| 95 | #include <scsi/libfc.h> |
| 96 | #include <scsi/fc_encode.h> |
Steve Ma | a51ab39 | 2009-11-03 11:47:34 -0800 | [diff] [blame] | 97 | #include <linux/scatterlist.h> |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 98 | |
Robert Love | 8866a5d | 2009-11-03 11:45:58 -0800 | [diff] [blame] | 99 | #include "fc_libfc.h" |
| 100 | |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 101 | /* Fabric IDs to use for point-to-point mode, chosen on whims. */ |
| 102 | #define FC_LOCAL_PTP_FID_LO 0x010101 |
| 103 | #define FC_LOCAL_PTP_FID_HI 0x010102 |
| 104 | |
| 105 | #define DNS_DELAY 3 /* Discovery delay after RSCN (in seconds)*/ |
| 106 | |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 107 | static void fc_lport_error(struct fc_lport *, struct fc_frame *); |
| 108 | |
| 109 | static void fc_lport_enter_reset(struct fc_lport *); |
| 110 | static void fc_lport_enter_flogi(struct fc_lport *); |
| 111 | static void fc_lport_enter_dns(struct fc_lport *); |
Chris Leech | c914f7d | 2009-11-03 11:47:12 -0800 | [diff] [blame] | 112 | static void fc_lport_enter_ns(struct fc_lport *, enum fc_lport_state); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 113 | static void fc_lport_enter_scr(struct fc_lport *); |
| 114 | static void fc_lport_enter_ready(struct fc_lport *); |
| 115 | static void fc_lport_enter_logo(struct fc_lport *); |
| 116 | |
| 117 | static const char *fc_lport_state_names[] = { |
Joe Eykholt | b1d9fd5 | 2009-07-29 17:04:22 -0700 | [diff] [blame] | 118 | [LPORT_ST_DISABLED] = "disabled", |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 119 | [LPORT_ST_FLOGI] = "FLOGI", |
| 120 | [LPORT_ST_DNS] = "dNS", |
Chris Leech | c9c7bd7 | 2009-11-03 11:46:51 -0800 | [diff] [blame] | 121 | [LPORT_ST_RNN_ID] = "RNN_ID", |
Chris Leech | 5baa17c | 2009-11-03 11:46:56 -0800 | [diff] [blame] | 122 | [LPORT_ST_RSNN_NN] = "RSNN_NN", |
Chris Leech | c9866a5 | 2009-11-03 11:47:01 -0800 | [diff] [blame] | 123 | [LPORT_ST_RSPN_ID] = "RSPN_ID", |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 124 | [LPORT_ST_RFT_ID] = "RFT_ID", |
| 125 | [LPORT_ST_SCR] = "SCR", |
| 126 | [LPORT_ST_READY] = "Ready", |
| 127 | [LPORT_ST_LOGO] = "LOGO", |
| 128 | [LPORT_ST_RESET] = "reset", |
| 129 | }; |
| 130 | |
Steve Ma | a51ab39 | 2009-11-03 11:47:34 -0800 | [diff] [blame] | 131 | /** |
| 132 | * struct fc_bsg_info - FC Passthrough managemet structure |
| 133 | * @job: The passthrough job |
| 134 | * @lport: The local port to pass through a command |
| 135 | * @rsp_code: The expected response code |
Robert Love | 3a3b42b | 2009-11-03 11:47:39 -0800 | [diff] [blame] | 136 | * @sg: job->reply_payload.sg_list |
Steve Ma | a51ab39 | 2009-11-03 11:47:34 -0800 | [diff] [blame] | 137 | * @nents: job->reply_payload.sg_cnt |
| 138 | * @offset: The offset into the response data |
| 139 | */ |
| 140 | struct fc_bsg_info { |
| 141 | struct fc_bsg_job *job; |
| 142 | struct fc_lport *lport; |
| 143 | u16 rsp_code; |
| 144 | struct scatterlist *sg; |
| 145 | u32 nents; |
| 146 | size_t offset; |
| 147 | }; |
| 148 | |
Robert Love | 3a3b42b | 2009-11-03 11:47:39 -0800 | [diff] [blame] | 149 | /** |
| 150 | * fc_frame_drop() - Dummy frame handler |
| 151 | * @lport: The local port the frame was received on |
| 152 | * @fp: The received frame |
| 153 | */ |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 154 | static int fc_frame_drop(struct fc_lport *lport, struct fc_frame *fp) |
| 155 | { |
| 156 | fc_frame_free(fp); |
| 157 | return 0; |
| 158 | } |
| 159 | |
| 160 | /** |
Robert Love | 34f42a0 | 2009-02-27 10:55:45 -0800 | [diff] [blame] | 161 | * fc_lport_rport_callback() - Event handler for rport events |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 162 | * @lport: The lport which is receiving the event |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame] | 163 | * @rdata: private remote port data |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 164 | * @event: The event that occured |
| 165 | * |
| 166 | * Locking Note: The rport lock should not be held when calling |
| 167 | * this function. |
| 168 | */ |
| 169 | static void fc_lport_rport_callback(struct fc_lport *lport, |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame] | 170 | struct fc_rport_priv *rdata, |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 171 | enum fc_rport_event event) |
| 172 | { |
Robert Love | 7414705 | 2009-06-10 15:31:10 -0700 | [diff] [blame] | 173 | FC_LPORT_DBG(lport, "Received a %d event for port (%6x)\n", event, |
Joe Eykholt | f211fa5 | 2009-08-25 14:01:01 -0700 | [diff] [blame] | 174 | rdata->ids.port_id); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 175 | |
Joe Eykholt | b5cbf08 | 2009-08-25 14:01:44 -0700 | [diff] [blame] | 176 | mutex_lock(&lport->lp_mutex); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 177 | switch (event) { |
Joe Eykholt | 4c0f62b | 2009-08-25 14:01:12 -0700 | [diff] [blame] | 178 | case RPORT_EV_READY: |
Joe Eykholt | b5cbf08 | 2009-08-25 14:01:44 -0700 | [diff] [blame] | 179 | if (lport->state == LPORT_ST_DNS) { |
Robert Love | 3a3b42b | 2009-11-03 11:47:39 -0800 | [diff] [blame] | 180 | lport->dns_rdata = rdata; |
Chris Leech | c914f7d | 2009-11-03 11:47:12 -0800 | [diff] [blame] | 181 | fc_lport_enter_ns(lport, LPORT_ST_RNN_ID); |
Joe Eykholt | b5cbf08 | 2009-08-25 14:01:44 -0700 | [diff] [blame] | 182 | } else { |
| 183 | FC_LPORT_DBG(lport, "Received an READY event " |
| 184 | "on port (%6x) for the directory " |
| 185 | "server, but the lport is not " |
| 186 | "in the DNS state, it's in the " |
| 187 | "%d state", rdata->ids.port_id, |
| 188 | lport->state); |
| 189 | lport->tt.rport_logoff(rdata); |
| 190 | } |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 191 | break; |
| 192 | case RPORT_EV_LOGO: |
| 193 | case RPORT_EV_FAILED: |
| 194 | case RPORT_EV_STOP: |
Robert Love | 3a3b42b | 2009-11-03 11:47:39 -0800 | [diff] [blame] | 195 | lport->dns_rdata = NULL; |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 196 | break; |
| 197 | case RPORT_EV_NONE: |
| 198 | break; |
| 199 | } |
Joe Eykholt | b5cbf08 | 2009-08-25 14:01:44 -0700 | [diff] [blame] | 200 | mutex_unlock(&lport->lp_mutex); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 201 | } |
| 202 | |
| 203 | /** |
Robert Love | 34f42a0 | 2009-02-27 10:55:45 -0800 | [diff] [blame] | 204 | * fc_lport_state() - Return a string which represents the lport's state |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 205 | * @lport: The lport whose state is to converted to a string |
| 206 | */ |
| 207 | static const char *fc_lport_state(struct fc_lport *lport) |
| 208 | { |
| 209 | const char *cp; |
| 210 | |
| 211 | cp = fc_lport_state_names[lport->state]; |
| 212 | if (!cp) |
| 213 | cp = "unknown"; |
| 214 | return cp; |
| 215 | } |
| 216 | |
| 217 | /** |
Robert Love | 34f42a0 | 2009-02-27 10:55:45 -0800 | [diff] [blame] | 218 | * fc_lport_ptp_setup() - Create an rport for point-to-point mode |
Robert Love | 3a3b42b | 2009-11-03 11:47:39 -0800 | [diff] [blame] | 219 | * @lport: The lport to attach the ptp rport to |
| 220 | * @remote_fid: The FID of the ptp rport |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 221 | * @remote_wwpn: The WWPN of the ptp rport |
| 222 | * @remote_wwnn: The WWNN of the ptp rport |
| 223 | */ |
| 224 | static void fc_lport_ptp_setup(struct fc_lport *lport, |
| 225 | u32 remote_fid, u64 remote_wwpn, |
| 226 | u64 remote_wwnn) |
| 227 | { |
Joe Eykholt | 48f0090 | 2009-08-25 14:01:50 -0700 | [diff] [blame] | 228 | mutex_lock(&lport->disc.disc_mutex); |
Robert Love | 3a3b42b | 2009-11-03 11:47:39 -0800 | [diff] [blame] | 229 | if (lport->ptp_rdata) |
| 230 | lport->tt.rport_logoff(lport->ptp_rdata); |
| 231 | lport->ptp_rdata = lport->tt.rport_create(lport, remote_fid); |
| 232 | lport->ptp_rdata->ids.port_name = remote_wwpn; |
| 233 | lport->ptp_rdata->ids.node_name = remote_wwnn; |
Joe Eykholt | 48f0090 | 2009-08-25 14:01:50 -0700 | [diff] [blame] | 234 | mutex_unlock(&lport->disc.disc_mutex); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 235 | |
Robert Love | 3a3b42b | 2009-11-03 11:47:39 -0800 | [diff] [blame] | 236 | lport->tt.rport_login(lport->ptp_rdata); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 237 | |
| 238 | fc_lport_enter_ready(lport); |
| 239 | } |
| 240 | |
Robert Love | 3a3b42b | 2009-11-03 11:47:39 -0800 | [diff] [blame] | 241 | /** |
| 242 | * fc_get_host_port_type() - Return the port type of the given Scsi_Host |
| 243 | * @shost: The SCSI host whose port type is to be determined |
| 244 | */ |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 245 | void fc_get_host_port_type(struct Scsi_Host *shost) |
| 246 | { |
| 247 | /* TODO - currently just NPORT */ |
| 248 | fc_host_port_type(shost) = FC_PORTTYPE_NPORT; |
| 249 | } |
| 250 | EXPORT_SYMBOL(fc_get_host_port_type); |
| 251 | |
Robert Love | 3a3b42b | 2009-11-03 11:47:39 -0800 | [diff] [blame] | 252 | /** |
| 253 | * fc_get_host_port_state() - Return the port state of the given Scsi_Host |
| 254 | * @shost: The SCSI host whose port state is to be determined |
| 255 | */ |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 256 | void fc_get_host_port_state(struct Scsi_Host *shost) |
| 257 | { |
Robert Love | 3a3b42b | 2009-11-03 11:47:39 -0800 | [diff] [blame] | 258 | struct fc_lport *lport = shost_priv(shost); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 259 | |
Robert Love | 3a3b42b | 2009-11-03 11:47:39 -0800 | [diff] [blame] | 260 | mutex_lock(&lport->lp_mutex); |
| 261 | if (!lport->link_up) |
Chris Leech | 8faecdd | 2009-11-03 11:46:19 -0800 | [diff] [blame] | 262 | fc_host_port_state(shost) = FC_PORTSTATE_LINKDOWN; |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 263 | else |
Robert Love | 3a3b42b | 2009-11-03 11:47:39 -0800 | [diff] [blame] | 264 | switch (lport->state) { |
Chris Leech | 8faecdd | 2009-11-03 11:46:19 -0800 | [diff] [blame] | 265 | case LPORT_ST_READY: |
| 266 | fc_host_port_state(shost) = FC_PORTSTATE_ONLINE; |
| 267 | break; |
| 268 | default: |
| 269 | fc_host_port_state(shost) = FC_PORTSTATE_OFFLINE; |
| 270 | } |
Robert Love | 3a3b42b | 2009-11-03 11:47:39 -0800 | [diff] [blame] | 271 | mutex_unlock(&lport->lp_mutex); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 272 | } |
| 273 | EXPORT_SYMBOL(fc_get_host_port_state); |
| 274 | |
Robert Love | 3a3b42b | 2009-11-03 11:47:39 -0800 | [diff] [blame] | 275 | /** |
| 276 | * fc_get_host_speed() - Return the speed of the given Scsi_Host |
| 277 | * @shost: The SCSI host whose port speed is to be determined |
| 278 | */ |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 279 | void fc_get_host_speed(struct Scsi_Host *shost) |
| 280 | { |
| 281 | struct fc_lport *lport = shost_priv(shost); |
| 282 | |
| 283 | fc_host_speed(shost) = lport->link_speed; |
| 284 | } |
| 285 | EXPORT_SYMBOL(fc_get_host_speed); |
| 286 | |
Robert Love | 3a3b42b | 2009-11-03 11:47:39 -0800 | [diff] [blame] | 287 | /** |
| 288 | * fc_get_host_stats() - Return the Scsi_Host's statistics |
| 289 | * @shost: The SCSI host whose statistics are to be returned |
| 290 | */ |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 291 | struct fc_host_statistics *fc_get_host_stats(struct Scsi_Host *shost) |
| 292 | { |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 293 | struct fc_host_statistics *fcoe_stats; |
Robert Love | 3a3b42b | 2009-11-03 11:47:39 -0800 | [diff] [blame] | 294 | struct fc_lport *lport = shost_priv(shost); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 295 | struct timespec v0, v1; |
Robert Love | 582b45b | 2009-03-31 15:51:50 -0700 | [diff] [blame] | 296 | unsigned int cpu; |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 297 | |
Robert Love | 3a3b42b | 2009-11-03 11:47:39 -0800 | [diff] [blame] | 298 | fcoe_stats = &lport->host_stats; |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 299 | memset(fcoe_stats, 0, sizeof(struct fc_host_statistics)); |
| 300 | |
| 301 | jiffies_to_timespec(jiffies, &v0); |
Robert Love | 3a3b42b | 2009-11-03 11:47:39 -0800 | [diff] [blame] | 302 | jiffies_to_timespec(lport->boot_time, &v1); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 303 | fcoe_stats->seconds_since_last_reset = (v0.tv_sec - v1.tv_sec); |
| 304 | |
Robert Love | 582b45b | 2009-03-31 15:51:50 -0700 | [diff] [blame] | 305 | for_each_possible_cpu(cpu) { |
| 306 | struct fcoe_dev_stats *stats; |
| 307 | |
Robert Love | 3a3b42b | 2009-11-03 11:47:39 -0800 | [diff] [blame] | 308 | stats = per_cpu_ptr(lport->dev_stats, cpu); |
Robert Love | 582b45b | 2009-03-31 15:51:50 -0700 | [diff] [blame] | 309 | |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 310 | fcoe_stats->tx_frames += stats->TxFrames; |
| 311 | fcoe_stats->tx_words += stats->TxWords; |
| 312 | fcoe_stats->rx_frames += stats->RxFrames; |
| 313 | fcoe_stats->rx_words += stats->RxWords; |
| 314 | fcoe_stats->error_frames += stats->ErrorFrames; |
| 315 | fcoe_stats->invalid_crc_count += stats->InvalidCRCCount; |
| 316 | fcoe_stats->fcp_input_requests += stats->InputRequests; |
| 317 | fcoe_stats->fcp_output_requests += stats->OutputRequests; |
| 318 | fcoe_stats->fcp_control_requests += stats->ControlRequests; |
| 319 | fcoe_stats->fcp_input_megabytes += stats->InputMegabytes; |
| 320 | fcoe_stats->fcp_output_megabytes += stats->OutputMegabytes; |
| 321 | fcoe_stats->link_failure_count += stats->LinkFailureCount; |
| 322 | } |
| 323 | fcoe_stats->lip_count = -1; |
| 324 | fcoe_stats->nos_count = -1; |
| 325 | fcoe_stats->loss_of_sync_count = -1; |
| 326 | fcoe_stats->loss_of_signal_count = -1; |
| 327 | fcoe_stats->prim_seq_protocol_err_count = -1; |
| 328 | fcoe_stats->dumped_frames = -1; |
| 329 | return fcoe_stats; |
| 330 | } |
| 331 | EXPORT_SYMBOL(fc_get_host_stats); |
| 332 | |
Robert Love | 3a3b42b | 2009-11-03 11:47:39 -0800 | [diff] [blame] | 333 | /** |
| 334 | * fc_lport_flogi_fill() - Fill in FLOGI command for request |
| 335 | * @lport: The local port the FLOGI is for |
| 336 | * @flogi: The FLOGI command |
| 337 | * @op: The opcode |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 338 | */ |
Robert Love | 3a3b42b | 2009-11-03 11:47:39 -0800 | [diff] [blame] | 339 | static void fc_lport_flogi_fill(struct fc_lport *lport, |
| 340 | struct fc_els_flogi *flogi, |
| 341 | unsigned int op) |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 342 | { |
| 343 | struct fc_els_csp *sp; |
| 344 | struct fc_els_cssp *cp; |
| 345 | |
| 346 | memset(flogi, 0, sizeof(*flogi)); |
| 347 | flogi->fl_cmd = (u8) op; |
| 348 | put_unaligned_be64(lport->wwpn, &flogi->fl_wwpn); |
| 349 | put_unaligned_be64(lport->wwnn, &flogi->fl_wwnn); |
| 350 | sp = &flogi->fl_csp; |
| 351 | sp->sp_hi_ver = 0x20; |
| 352 | sp->sp_lo_ver = 0x20; |
| 353 | sp->sp_bb_cred = htons(10); /* this gets set by gateway */ |
| 354 | sp->sp_bb_data = htons((u16) lport->mfs); |
| 355 | cp = &flogi->fl_cssp[3 - 1]; /* class 3 parameters */ |
| 356 | cp->cp_class = htons(FC_CPC_VALID | FC_CPC_SEQ); |
| 357 | if (op != ELS_FLOGI) { |
| 358 | sp->sp_features = htons(FC_SP_FT_CIRO); |
| 359 | sp->sp_tot_seq = htons(255); /* seq. we accept */ |
| 360 | sp->sp_rel_off = htons(0x1f); |
| 361 | sp->sp_e_d_tov = htonl(lport->e_d_tov); |
| 362 | |
| 363 | cp->cp_rdfs = htons((u16) lport->mfs); |
| 364 | cp->cp_con_seq = htons(255); |
| 365 | cp->cp_open_seq = 1; |
| 366 | } |
| 367 | } |
| 368 | |
Robert Love | 3a3b42b | 2009-11-03 11:47:39 -0800 | [diff] [blame] | 369 | /** |
| 370 | * fc_lport_add_fc4_type() - Add a supported FC-4 type to a local port |
| 371 | * @lport: The local port to add a new FC-4 type to |
| 372 | * @type: The new FC-4 type |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 373 | */ |
| 374 | static void fc_lport_add_fc4_type(struct fc_lport *lport, enum fc_fh_type type) |
| 375 | { |
| 376 | __be32 *mp; |
| 377 | |
| 378 | mp = &lport->fcts.ff_type_map[type / FC_NS_BPW]; |
| 379 | *mp = htonl(ntohl(*mp) | 1UL << (type % FC_NS_BPW)); |
| 380 | } |
| 381 | |
| 382 | /** |
Robert Love | 34f42a0 | 2009-02-27 10:55:45 -0800 | [diff] [blame] | 383 | * fc_lport_recv_rlir_req() - Handle received Registered Link Incident Report. |
Robert Love | 3a3b42b | 2009-11-03 11:47:39 -0800 | [diff] [blame] | 384 | * @sp: The sequence in the RLIR exchange |
| 385 | * @fp: The RLIR request frame |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 386 | * @lport: Fibre Channel local port recieving the RLIR |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 387 | * |
Joe Eykholt | 1b69bc0 | 2009-10-21 16:27:17 -0700 | [diff] [blame] | 388 | * Locking Note: The lport lock is expected to be held before calling |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 389 | * this function. |
| 390 | */ |
| 391 | static void fc_lport_recv_rlir_req(struct fc_seq *sp, struct fc_frame *fp, |
| 392 | struct fc_lport *lport) |
| 393 | { |
Robert Love | 7414705 | 2009-06-10 15:31:10 -0700 | [diff] [blame] | 394 | FC_LPORT_DBG(lport, "Received RLIR request while in state %s\n", |
| 395 | fc_lport_state(lport)); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 396 | |
| 397 | lport->tt.seq_els_rsp_send(sp, ELS_LS_ACC, NULL); |
| 398 | fc_frame_free(fp); |
| 399 | } |
| 400 | |
| 401 | /** |
Robert Love | 34f42a0 | 2009-02-27 10:55:45 -0800 | [diff] [blame] | 402 | * fc_lport_recv_echo_req() - Handle received ECHO request |
Robert Love | 3a3b42b | 2009-11-03 11:47:39 -0800 | [diff] [blame] | 403 | * @sp: The sequence in the ECHO exchange |
| 404 | * @fp: ECHO request frame |
| 405 | * @lport: The local port recieving the ECHO |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 406 | * |
Joe Eykholt | 1b69bc0 | 2009-10-21 16:27:17 -0700 | [diff] [blame] | 407 | * Locking Note: The lport lock is expected to be held before calling |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 408 | * this function. |
| 409 | */ |
| 410 | static void fc_lport_recv_echo_req(struct fc_seq *sp, struct fc_frame *in_fp, |
| 411 | struct fc_lport *lport) |
| 412 | { |
| 413 | struct fc_frame *fp; |
| 414 | struct fc_exch *ep = fc_seq_exch(sp); |
| 415 | unsigned int len; |
| 416 | void *pp; |
| 417 | void *dp; |
| 418 | u32 f_ctl; |
| 419 | |
Joe Eykholt | 1b69bc0 | 2009-10-21 16:27:17 -0700 | [diff] [blame] | 420 | FC_LPORT_DBG(lport, "Received ECHO request while in state %s\n", |
Robert Love | 7414705 | 2009-06-10 15:31:10 -0700 | [diff] [blame] | 421 | fc_lport_state(lport)); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 422 | |
| 423 | len = fr_len(in_fp) - sizeof(struct fc_frame_header); |
| 424 | pp = fc_frame_payload_get(in_fp, len); |
| 425 | |
| 426 | if (len < sizeof(__be32)) |
| 427 | len = sizeof(__be32); |
| 428 | |
| 429 | fp = fc_frame_alloc(lport, len); |
| 430 | if (fp) { |
| 431 | dp = fc_frame_payload_get(fp, len); |
| 432 | memcpy(dp, pp, len); |
Joe Eykholt | 1b69bc0 | 2009-10-21 16:27:17 -0700 | [diff] [blame] | 433 | *((__be32 *)dp) = htonl(ELS_LS_ACC << 24); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 434 | sp = lport->tt.seq_start_next(sp); |
| 435 | f_ctl = FC_FC_EX_CTX | FC_FC_LAST_SEQ | FC_FC_END_SEQ; |
| 436 | fc_fill_fc_hdr(fp, FC_RCTL_ELS_REP, ep->did, ep->sid, |
| 437 | FC_TYPE_ELS, f_ctl, 0); |
| 438 | lport->tt.seq_send(lport, sp, fp); |
| 439 | } |
| 440 | fc_frame_free(in_fp); |
| 441 | } |
| 442 | |
| 443 | /** |
Joe Eykholt | 1b69bc0 | 2009-10-21 16:27:17 -0700 | [diff] [blame] | 444 | * fc_lport_recv_rnid_req() - Handle received Request Node ID data request |
| 445 | * @sp: The sequence in the RNID exchange |
| 446 | * @fp: The RNID request frame |
| 447 | * @lport: The local port recieving the RNID |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 448 | * |
Joe Eykholt | 1b69bc0 | 2009-10-21 16:27:17 -0700 | [diff] [blame] | 449 | * Locking Note: The lport lock is expected to be held before calling |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 450 | * this function. |
| 451 | */ |
| 452 | static void fc_lport_recv_rnid_req(struct fc_seq *sp, struct fc_frame *in_fp, |
| 453 | struct fc_lport *lport) |
| 454 | { |
| 455 | struct fc_frame *fp; |
| 456 | struct fc_exch *ep = fc_seq_exch(sp); |
| 457 | struct fc_els_rnid *req; |
| 458 | struct { |
| 459 | struct fc_els_rnid_resp rnid; |
| 460 | struct fc_els_rnid_cid cid; |
| 461 | struct fc_els_rnid_gen gen; |
| 462 | } *rp; |
| 463 | struct fc_seq_els_data rjt_data; |
| 464 | u8 fmt; |
| 465 | size_t len; |
| 466 | u32 f_ctl; |
| 467 | |
Robert Love | 7414705 | 2009-06-10 15:31:10 -0700 | [diff] [blame] | 468 | FC_LPORT_DBG(lport, "Received RNID request while in state %s\n", |
| 469 | fc_lport_state(lport)); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 470 | |
| 471 | req = fc_frame_payload_get(in_fp, sizeof(*req)); |
| 472 | if (!req) { |
| 473 | rjt_data.fp = NULL; |
| 474 | rjt_data.reason = ELS_RJT_LOGIC; |
| 475 | rjt_data.explan = ELS_EXPL_NONE; |
| 476 | lport->tt.seq_els_rsp_send(sp, ELS_LS_RJT, &rjt_data); |
| 477 | } else { |
| 478 | fmt = req->rnid_fmt; |
| 479 | len = sizeof(*rp); |
| 480 | if (fmt != ELS_RNIDF_GEN || |
| 481 | ntohl(lport->rnid_gen.rnid_atype) == 0) { |
| 482 | fmt = ELS_RNIDF_NONE; /* nothing to provide */ |
| 483 | len -= sizeof(rp->gen); |
| 484 | } |
| 485 | fp = fc_frame_alloc(lport, len); |
| 486 | if (fp) { |
| 487 | rp = fc_frame_payload_get(fp, len); |
| 488 | memset(rp, 0, len); |
| 489 | rp->rnid.rnid_cmd = ELS_LS_ACC; |
| 490 | rp->rnid.rnid_fmt = fmt; |
| 491 | rp->rnid.rnid_cid_len = sizeof(rp->cid); |
| 492 | rp->cid.rnid_wwpn = htonll(lport->wwpn); |
| 493 | rp->cid.rnid_wwnn = htonll(lport->wwnn); |
| 494 | if (fmt == ELS_RNIDF_GEN) { |
| 495 | rp->rnid.rnid_sid_len = sizeof(rp->gen); |
| 496 | memcpy(&rp->gen, &lport->rnid_gen, |
| 497 | sizeof(rp->gen)); |
| 498 | } |
| 499 | sp = lport->tt.seq_start_next(sp); |
| 500 | f_ctl = FC_FC_EX_CTX | FC_FC_LAST_SEQ; |
| 501 | f_ctl |= FC_FC_END_SEQ | FC_FC_SEQ_INIT; |
| 502 | fc_fill_fc_hdr(fp, FC_RCTL_ELS_REP, ep->did, ep->sid, |
| 503 | FC_TYPE_ELS, f_ctl, 0); |
| 504 | lport->tt.seq_send(lport, sp, fp); |
| 505 | } |
| 506 | } |
| 507 | fc_frame_free(in_fp); |
| 508 | } |
| 509 | |
| 510 | /** |
Robert Love | 34f42a0 | 2009-02-27 10:55:45 -0800 | [diff] [blame] | 511 | * fc_lport_recv_logo_req() - Handle received fabric LOGO request |
Robert Love | 3a3b42b | 2009-11-03 11:47:39 -0800 | [diff] [blame] | 512 | * @sp: The sequence in the LOGO exchange |
| 513 | * @fp: The LOGO request frame |
| 514 | * @lport: The local port recieving the LOGO |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 515 | * |
| 516 | * Locking Note: The lport lock is exected to be held before calling |
| 517 | * this function. |
| 518 | */ |
| 519 | static void fc_lport_recv_logo_req(struct fc_seq *sp, struct fc_frame *fp, |
| 520 | struct fc_lport *lport) |
| 521 | { |
| 522 | lport->tt.seq_els_rsp_send(sp, ELS_LS_ACC, NULL); |
| 523 | fc_lport_enter_reset(lport); |
| 524 | fc_frame_free(fp); |
| 525 | } |
| 526 | |
| 527 | /** |
Robert Love | 34f42a0 | 2009-02-27 10:55:45 -0800 | [diff] [blame] | 528 | * fc_fabric_login() - Start the lport state machine |
Robert Love | 3a3b42b | 2009-11-03 11:47:39 -0800 | [diff] [blame] | 529 | * @lport: The local port that should log into the fabric |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 530 | * |
| 531 | * Locking Note: This function should not be called |
| 532 | * with the lport lock held. |
| 533 | */ |
| 534 | int fc_fabric_login(struct fc_lport *lport) |
| 535 | { |
| 536 | int rc = -1; |
| 537 | |
| 538 | mutex_lock(&lport->lp_mutex); |
Joe Eykholt | b1d9fd5 | 2009-07-29 17:04:22 -0700 | [diff] [blame] | 539 | if (lport->state == LPORT_ST_DISABLED) { |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 540 | fc_lport_enter_reset(lport); |
| 541 | rc = 0; |
| 542 | } |
| 543 | mutex_unlock(&lport->lp_mutex); |
| 544 | |
| 545 | return rc; |
| 546 | } |
| 547 | EXPORT_SYMBOL(fc_fabric_login); |
| 548 | |
| 549 | /** |
Chris Leech | 8faecdd | 2009-11-03 11:46:19 -0800 | [diff] [blame] | 550 | * __fc_linkup() - Handler for transport linkup events |
| 551 | * @lport: The lport whose link is up |
| 552 | * |
| 553 | * Locking: must be called with the lp_mutex held |
| 554 | */ |
| 555 | void __fc_linkup(struct fc_lport *lport) |
| 556 | { |
| 557 | if (!lport->link_up) { |
| 558 | lport->link_up = 1; |
| 559 | |
| 560 | if (lport->state == LPORT_ST_RESET) |
| 561 | fc_lport_enter_flogi(lport); |
| 562 | } |
| 563 | } |
| 564 | |
| 565 | /** |
Robert Love | 34f42a0 | 2009-02-27 10:55:45 -0800 | [diff] [blame] | 566 | * fc_linkup() - Handler for transport linkup events |
Robert Love | 3a3b42b | 2009-11-03 11:47:39 -0800 | [diff] [blame] | 567 | * @lport: The local port whose link is up |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 568 | */ |
| 569 | void fc_linkup(struct fc_lport *lport) |
| 570 | { |
Joe Eykholt | e6d8a1b | 2009-11-03 11:49:11 -0800 | [diff] [blame^] | 571 | printk(KERN_INFO "host%d: libfc: Link up on port (%6x)\n", |
| 572 | lport->host->host_no, fc_host_port_id(lport->host)); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 573 | |
| 574 | mutex_lock(&lport->lp_mutex); |
Chris Leech | 8faecdd | 2009-11-03 11:46:19 -0800 | [diff] [blame] | 575 | __fc_linkup(lport); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 576 | mutex_unlock(&lport->lp_mutex); |
| 577 | } |
| 578 | EXPORT_SYMBOL(fc_linkup); |
| 579 | |
| 580 | /** |
Chris Leech | 8faecdd | 2009-11-03 11:46:19 -0800 | [diff] [blame] | 581 | * __fc_linkdown() - Handler for transport linkdown events |
| 582 | * @lport: The lport whose link is down |
| 583 | * |
| 584 | * Locking: must be called with the lp_mutex held |
| 585 | */ |
| 586 | void __fc_linkdown(struct fc_lport *lport) |
| 587 | { |
| 588 | if (lport->link_up) { |
| 589 | lport->link_up = 0; |
| 590 | fc_lport_enter_reset(lport); |
| 591 | lport->tt.fcp_cleanup(lport); |
| 592 | } |
| 593 | } |
| 594 | |
| 595 | /** |
Robert Love | 34f42a0 | 2009-02-27 10:55:45 -0800 | [diff] [blame] | 596 | * fc_linkdown() - Handler for transport linkdown events |
Robert Love | 3a3b42b | 2009-11-03 11:47:39 -0800 | [diff] [blame] | 597 | * @lport: The local port whose link is down |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 598 | */ |
| 599 | void fc_linkdown(struct fc_lport *lport) |
| 600 | { |
Joe Eykholt | e6d8a1b | 2009-11-03 11:49:11 -0800 | [diff] [blame^] | 601 | printk(KERN_INFO "host%d: libfc: Link down on port (%6x)\n", |
| 602 | lport->host->host_no, fc_host_port_id(lport->host)); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 603 | |
Chris Leech | 8faecdd | 2009-11-03 11:46:19 -0800 | [diff] [blame] | 604 | mutex_lock(&lport->lp_mutex); |
| 605 | __fc_linkdown(lport); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 606 | mutex_unlock(&lport->lp_mutex); |
| 607 | } |
| 608 | EXPORT_SYMBOL(fc_linkdown); |
| 609 | |
| 610 | /** |
Robert Love | 34f42a0 | 2009-02-27 10:55:45 -0800 | [diff] [blame] | 611 | * fc_fabric_logoff() - Logout of the fabric |
Robert Love | 3a3b42b | 2009-11-03 11:47:39 -0800 | [diff] [blame] | 612 | * @lport: The local port to logoff the fabric |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 613 | * |
| 614 | * Return value: |
| 615 | * 0 for success, -1 for failure |
Robert Love | 34f42a0 | 2009-02-27 10:55:45 -0800 | [diff] [blame] | 616 | */ |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 617 | int fc_fabric_logoff(struct fc_lport *lport) |
| 618 | { |
| 619 | lport->tt.disc_stop_final(lport); |
| 620 | mutex_lock(&lport->lp_mutex); |
Robert Love | 3a3b42b | 2009-11-03 11:47:39 -0800 | [diff] [blame] | 621 | if (lport->dns_rdata) |
| 622 | lport->tt.rport_logoff(lport->dns_rdata); |
Abhijeet Joglekar | a0fd2e4 | 2009-04-21 16:27:09 -0700 | [diff] [blame] | 623 | mutex_unlock(&lport->lp_mutex); |
| 624 | lport->tt.rport_flush_queue(); |
| 625 | mutex_lock(&lport->lp_mutex); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 626 | fc_lport_enter_logo(lport); |
| 627 | mutex_unlock(&lport->lp_mutex); |
Steve Ma | f7db2c15 | 2009-02-27 10:55:13 -0800 | [diff] [blame] | 628 | cancel_delayed_work_sync(&lport->retry_work); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 629 | return 0; |
| 630 | } |
| 631 | EXPORT_SYMBOL(fc_fabric_logoff); |
| 632 | |
| 633 | /** |
Robert Love | 3a3b42b | 2009-11-03 11:47:39 -0800 | [diff] [blame] | 634 | * fc_lport_destroy() - Unregister a fc_lport |
| 635 | * @lport: The local port to unregister |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 636 | * |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 637 | * Note: |
| 638 | * exit routine for fc_lport instance |
| 639 | * clean-up all the allocated memory |
| 640 | * and free up other system resources. |
| 641 | * |
Robert Love | 34f42a0 | 2009-02-27 10:55:45 -0800 | [diff] [blame] | 642 | */ |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 643 | int fc_lport_destroy(struct fc_lport *lport) |
| 644 | { |
Abhijeet Joglekar | bbf1566 | 2009-04-21 16:27:14 -0700 | [diff] [blame] | 645 | mutex_lock(&lport->lp_mutex); |
Joe Eykholt | b1d9fd5 | 2009-07-29 17:04:22 -0700 | [diff] [blame] | 646 | lport->state = LPORT_ST_DISABLED; |
Abhijeet Joglekar | bbf1566 | 2009-04-21 16:27:14 -0700 | [diff] [blame] | 647 | lport->link_up = 0; |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 648 | lport->tt.frame_send = fc_frame_drop; |
Abhijeet Joglekar | bbf1566 | 2009-04-21 16:27:14 -0700 | [diff] [blame] | 649 | mutex_unlock(&lport->lp_mutex); |
| 650 | |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 651 | lport->tt.fcp_abort_io(lport); |
Joe Eykholt | e9ba8b4 | 2009-07-29 17:04:33 -0700 | [diff] [blame] | 652 | lport->tt.disc_stop_final(lport); |
Abhijeet Joglekar | 1f6ff36 | 2009-02-27 10:54:35 -0800 | [diff] [blame] | 653 | lport->tt.exch_mgr_reset(lport, 0, 0); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 654 | return 0; |
| 655 | } |
| 656 | EXPORT_SYMBOL(fc_lport_destroy); |
| 657 | |
| 658 | /** |
Robert Love | 3a3b42b | 2009-11-03 11:47:39 -0800 | [diff] [blame] | 659 | * fc_set_mfs() - Set the maximum frame size for a local port |
| 660 | * @lport: The local port to set the MFS for |
| 661 | * @mfs: The new MFS |
Robert Love | 34f42a0 | 2009-02-27 10:55:45 -0800 | [diff] [blame] | 662 | */ |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 663 | int fc_set_mfs(struct fc_lport *lport, u32 mfs) |
| 664 | { |
| 665 | unsigned int old_mfs; |
| 666 | int rc = -EINVAL; |
| 667 | |
| 668 | mutex_lock(&lport->lp_mutex); |
| 669 | |
| 670 | old_mfs = lport->mfs; |
| 671 | |
| 672 | if (mfs >= FC_MIN_MAX_FRAME) { |
| 673 | mfs &= ~3; |
| 674 | if (mfs > FC_MAX_FRAME) |
| 675 | mfs = FC_MAX_FRAME; |
| 676 | mfs -= sizeof(struct fc_frame_header); |
| 677 | lport->mfs = mfs; |
| 678 | rc = 0; |
| 679 | } |
| 680 | |
| 681 | if (!rc && mfs < old_mfs) |
| 682 | fc_lport_enter_reset(lport); |
| 683 | |
| 684 | mutex_unlock(&lport->lp_mutex); |
| 685 | |
| 686 | return rc; |
| 687 | } |
| 688 | EXPORT_SYMBOL(fc_set_mfs); |
| 689 | |
| 690 | /** |
Robert Love | 34f42a0 | 2009-02-27 10:55:45 -0800 | [diff] [blame] | 691 | * fc_lport_disc_callback() - Callback for discovery events |
Robert Love | 3a3b42b | 2009-11-03 11:47:39 -0800 | [diff] [blame] | 692 | * @lport: The local port receiving the event |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 693 | * @event: The discovery event |
| 694 | */ |
| 695 | void fc_lport_disc_callback(struct fc_lport *lport, enum fc_disc_event event) |
| 696 | { |
| 697 | switch (event) { |
| 698 | case DISC_EV_SUCCESS: |
Robert Love | 7414705 | 2009-06-10 15:31:10 -0700 | [diff] [blame] | 699 | FC_LPORT_DBG(lport, "Discovery succeeded\n"); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 700 | break; |
| 701 | case DISC_EV_FAILED: |
Joe Eykholt | e6d8a1b | 2009-11-03 11:49:11 -0800 | [diff] [blame^] | 702 | printk(KERN_ERR "host%d: libfc: " |
| 703 | "Discovery failed for port (%6x)\n", |
| 704 | lport->host->host_no, fc_host_port_id(lport->host)); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 705 | mutex_lock(&lport->lp_mutex); |
| 706 | fc_lport_enter_reset(lport); |
| 707 | mutex_unlock(&lport->lp_mutex); |
| 708 | break; |
| 709 | case DISC_EV_NONE: |
| 710 | WARN_ON(1); |
| 711 | break; |
| 712 | } |
| 713 | } |
| 714 | |
| 715 | /** |
Robert Love | 34f42a0 | 2009-02-27 10:55:45 -0800 | [diff] [blame] | 716 | * fc_rport_enter_ready() - Enter the ready state and start discovery |
Robert Love | 3a3b42b | 2009-11-03 11:47:39 -0800 | [diff] [blame] | 717 | * @lport: The local port that is ready |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 718 | * |
| 719 | * Locking Note: The lport lock is expected to be held before calling |
| 720 | * this routine. |
| 721 | */ |
| 722 | static void fc_lport_enter_ready(struct fc_lport *lport) |
| 723 | { |
Robert Love | 7414705 | 2009-06-10 15:31:10 -0700 | [diff] [blame] | 724 | FC_LPORT_DBG(lport, "Entered READY from state %s\n", |
| 725 | fc_lport_state(lport)); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 726 | |
| 727 | fc_lport_state_enter(lport, LPORT_ST_READY); |
Chris Leech | 8faecdd | 2009-11-03 11:46:19 -0800 | [diff] [blame] | 728 | if (lport->vport) |
| 729 | fc_vport_set_state(lport->vport, FC_VPORT_ACTIVE); |
| 730 | fc_vports_linkchange(lport); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 731 | |
Robert Love | 3a3b42b | 2009-11-03 11:47:39 -0800 | [diff] [blame] | 732 | if (!lport->ptp_rdata) |
Joe Eykholt | 29d898e | 2009-08-25 14:02:49 -0700 | [diff] [blame] | 733 | lport->tt.disc_start(fc_lport_disc_callback, lport); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 734 | } |
| 735 | |
| 736 | /** |
Joe Eykholt | 093bb6a | 2009-11-03 11:49:05 -0800 | [diff] [blame] | 737 | * fc_lport_set_port_id() - set the local port Port ID |
| 738 | * @lport: The local port which will have its Port ID set. |
| 739 | * @port_id: The new port ID. |
| 740 | * @fp: The frame containing the incoming request, or NULL. |
| 741 | * |
| 742 | * Locking Note: The lport lock is expected to be held before calling |
| 743 | * this function. |
| 744 | */ |
| 745 | static void fc_lport_set_port_id(struct fc_lport *lport, u32 port_id, |
| 746 | struct fc_frame *fp) |
| 747 | { |
| 748 | if (port_id) |
| 749 | printk(KERN_INFO "host%d: Assigned Port ID %6x\n", |
| 750 | lport->host->host_no, port_id); |
| 751 | |
| 752 | fc_host_port_id(lport->host) = port_id; |
| 753 | if (lport->tt.lport_set_port_id) |
| 754 | lport->tt.lport_set_port_id(lport, port_id, fp); |
| 755 | } |
| 756 | |
| 757 | /** |
Robert Love | 34f42a0 | 2009-02-27 10:55:45 -0800 | [diff] [blame] | 758 | * fc_lport_recv_flogi_req() - Receive a FLOGI request |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 759 | * @sp_in: The sequence the FLOGI is on |
Robert Love | 3a3b42b | 2009-11-03 11:47:39 -0800 | [diff] [blame] | 760 | * @rx_fp: The FLOGI frame |
| 761 | * @lport: The local port that recieved the request |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 762 | * |
| 763 | * A received FLOGI request indicates a point-to-point connection. |
| 764 | * Accept it with the common service parameters indicating our N port. |
| 765 | * Set up to do a PLOGI if we have the higher-number WWPN. |
| 766 | * |
Joe Eykholt | 1b69bc0 | 2009-10-21 16:27:17 -0700 | [diff] [blame] | 767 | * Locking Note: The lport lock is expected to be held before calling |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 768 | * this function. |
| 769 | */ |
| 770 | static void fc_lport_recv_flogi_req(struct fc_seq *sp_in, |
| 771 | struct fc_frame *rx_fp, |
| 772 | struct fc_lport *lport) |
| 773 | { |
| 774 | struct fc_frame *fp; |
| 775 | struct fc_frame_header *fh; |
| 776 | struct fc_seq *sp; |
| 777 | struct fc_exch *ep; |
| 778 | struct fc_els_flogi *flp; |
| 779 | struct fc_els_flogi *new_flp; |
| 780 | u64 remote_wwpn; |
| 781 | u32 remote_fid; |
| 782 | u32 local_fid; |
| 783 | u32 f_ctl; |
| 784 | |
Robert Love | 7414705 | 2009-06-10 15:31:10 -0700 | [diff] [blame] | 785 | FC_LPORT_DBG(lport, "Received FLOGI request while in state %s\n", |
| 786 | fc_lport_state(lport)); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 787 | |
| 788 | fh = fc_frame_header_get(rx_fp); |
| 789 | remote_fid = ntoh24(fh->fh_s_id); |
| 790 | flp = fc_frame_payload_get(rx_fp, sizeof(*flp)); |
| 791 | if (!flp) |
| 792 | goto out; |
| 793 | remote_wwpn = get_unaligned_be64(&flp->fl_wwpn); |
| 794 | if (remote_wwpn == lport->wwpn) { |
Joe Eykholt | e6d8a1b | 2009-11-03 11:49:11 -0800 | [diff] [blame^] | 795 | printk(KERN_WARNING "host%d: libfc: Received FLOGI from port " |
| 796 | "with same WWPN %llx\n", |
| 797 | lport->host->host_no, remote_wwpn); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 798 | goto out; |
| 799 | } |
Robert Love | 7414705 | 2009-06-10 15:31:10 -0700 | [diff] [blame] | 800 | FC_LPORT_DBG(lport, "FLOGI from port WWPN %llx\n", remote_wwpn); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 801 | |
| 802 | /* |
| 803 | * XXX what is the right thing to do for FIDs? |
| 804 | * The originator might expect our S_ID to be 0xfffffe. |
| 805 | * But if so, both of us could end up with the same FID. |
| 806 | */ |
| 807 | local_fid = FC_LOCAL_PTP_FID_LO; |
| 808 | if (remote_wwpn < lport->wwpn) { |
| 809 | local_fid = FC_LOCAL_PTP_FID_HI; |
| 810 | if (!remote_fid || remote_fid == local_fid) |
| 811 | remote_fid = FC_LOCAL_PTP_FID_LO; |
| 812 | } else if (!remote_fid) { |
| 813 | remote_fid = FC_LOCAL_PTP_FID_HI; |
| 814 | } |
| 815 | |
Joe Eykholt | 093bb6a | 2009-11-03 11:49:05 -0800 | [diff] [blame] | 816 | fc_lport_set_port_id(lport, local_fid, rx_fp); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 817 | |
| 818 | fp = fc_frame_alloc(lport, sizeof(*flp)); |
| 819 | if (fp) { |
| 820 | sp = lport->tt.seq_start_next(fr_seq(rx_fp)); |
| 821 | new_flp = fc_frame_payload_get(fp, sizeof(*flp)); |
| 822 | fc_lport_flogi_fill(lport, new_flp, ELS_FLOGI); |
| 823 | new_flp->fl_cmd = (u8) ELS_LS_ACC; |
| 824 | |
| 825 | /* |
| 826 | * Send the response. If this fails, the originator should |
| 827 | * repeat the sequence. |
| 828 | */ |
| 829 | f_ctl = FC_FC_EX_CTX | FC_FC_LAST_SEQ | FC_FC_END_SEQ; |
| 830 | ep = fc_seq_exch(sp); |
| 831 | fc_fill_fc_hdr(fp, FC_RCTL_ELS_REP, ep->did, ep->sid, |
| 832 | FC_TYPE_ELS, f_ctl, 0); |
| 833 | lport->tt.seq_send(lport, sp, fp); |
| 834 | |
| 835 | } else { |
| 836 | fc_lport_error(lport, fp); |
| 837 | } |
| 838 | fc_lport_ptp_setup(lport, remote_fid, remote_wwpn, |
| 839 | get_unaligned_be64(&flp->fl_wwnn)); |
| 840 | |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 841 | out: |
| 842 | sp = fr_seq(rx_fp); |
| 843 | fc_frame_free(rx_fp); |
| 844 | } |
| 845 | |
| 846 | /** |
Robert Love | 34f42a0 | 2009-02-27 10:55:45 -0800 | [diff] [blame] | 847 | * fc_lport_recv_req() - The generic lport request handler |
Robert Love | 3a3b42b | 2009-11-03 11:47:39 -0800 | [diff] [blame] | 848 | * @lport: The local port that received the request |
| 849 | * @sp: The sequence the request is on |
| 850 | * @fp: The request frame |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 851 | * |
| 852 | * This function will see if the lport handles the request or |
| 853 | * if an rport should handle the request. |
| 854 | * |
| 855 | * Locking Note: This function should not be called with the lport |
| 856 | * lock held becuase it will grab the lock. |
| 857 | */ |
| 858 | static void fc_lport_recv_req(struct fc_lport *lport, struct fc_seq *sp, |
| 859 | struct fc_frame *fp) |
| 860 | { |
| 861 | struct fc_frame_header *fh = fc_frame_header_get(fp); |
| 862 | void (*recv) (struct fc_seq *, struct fc_frame *, struct fc_lport *); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 863 | |
| 864 | mutex_lock(&lport->lp_mutex); |
| 865 | |
| 866 | /* |
| 867 | * Handle special ELS cases like FLOGI, LOGO, and |
| 868 | * RSCN here. These don't require a session. |
| 869 | * Even if we had a session, it might not be ready. |
| 870 | */ |
Joe Eykholt | e9ba8b4 | 2009-07-29 17:04:33 -0700 | [diff] [blame] | 871 | if (!lport->link_up) |
| 872 | fc_frame_free(fp); |
| 873 | else if (fh->fh_type == FC_TYPE_ELS && |
| 874 | fh->fh_r_ctl == FC_RCTL_ELS_REQ) { |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 875 | /* |
| 876 | * Check opcode. |
| 877 | */ |
Joe Eykholt | 131203a | 2009-08-25 14:03:10 -0700 | [diff] [blame] | 878 | recv = lport->tt.rport_recv_req; |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 879 | switch (fc_frame_payload_op(fp)) { |
| 880 | case ELS_FLOGI: |
| 881 | recv = fc_lport_recv_flogi_req; |
| 882 | break; |
| 883 | case ELS_LOGO: |
| 884 | fh = fc_frame_header_get(fp); |
| 885 | if (ntoh24(fh->fh_s_id) == FC_FID_FLOGI) |
| 886 | recv = fc_lport_recv_logo_req; |
| 887 | break; |
| 888 | case ELS_RSCN: |
| 889 | recv = lport->tt.disc_recv_req; |
| 890 | break; |
| 891 | case ELS_ECHO: |
| 892 | recv = fc_lport_recv_echo_req; |
| 893 | break; |
| 894 | case ELS_RLIR: |
| 895 | recv = fc_lport_recv_rlir_req; |
| 896 | break; |
| 897 | case ELS_RNID: |
| 898 | recv = fc_lport_recv_rnid_req; |
| 899 | break; |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 900 | } |
| 901 | |
Joe Eykholt | 131203a | 2009-08-25 14:03:10 -0700 | [diff] [blame] | 902 | recv(sp, fp, lport); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 903 | } else { |
Robert Love | 7414705 | 2009-06-10 15:31:10 -0700 | [diff] [blame] | 904 | FC_LPORT_DBG(lport, "dropping invalid frame (eof %x)\n", |
| 905 | fr_eof(fp)); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 906 | fc_frame_free(fp); |
| 907 | } |
| 908 | mutex_unlock(&lport->lp_mutex); |
| 909 | |
| 910 | /* |
| 911 | * The common exch_done for all request may not be good |
| 912 | * if any request requires longer hold on exhange. XXX |
| 913 | */ |
| 914 | lport->tt.exch_done(sp); |
| 915 | } |
| 916 | |
| 917 | /** |
Robert Love | 3a3b42b | 2009-11-03 11:47:39 -0800 | [diff] [blame] | 918 | * fc_lport_reset() - Reset a local port |
| 919 | * @lport: The local port which should be reset |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 920 | * |
| 921 | * Locking Note: This functions should not be called with the |
| 922 | * lport lock held. |
| 923 | */ |
| 924 | int fc_lport_reset(struct fc_lport *lport) |
| 925 | { |
Steve Ma | f7db2c15 | 2009-02-27 10:55:13 -0800 | [diff] [blame] | 926 | cancel_delayed_work_sync(&lport->retry_work); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 927 | mutex_lock(&lport->lp_mutex); |
| 928 | fc_lport_enter_reset(lport); |
| 929 | mutex_unlock(&lport->lp_mutex); |
| 930 | return 0; |
| 931 | } |
| 932 | EXPORT_SYMBOL(fc_lport_reset); |
| 933 | |
| 934 | /** |
Robert Love | 3a3b42b | 2009-11-03 11:47:39 -0800 | [diff] [blame] | 935 | * fc_lport_reset_locked() - Reset the local port w/ the lport lock held |
| 936 | * @lport: The local port to be reset |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 937 | * |
| 938 | * Locking Note: The lport lock is expected to be held before calling |
| 939 | * this routine. |
| 940 | */ |
Joe Eykholt | 1190d92 | 2009-07-29 17:04:27 -0700 | [diff] [blame] | 941 | static void fc_lport_reset_locked(struct fc_lport *lport) |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 942 | { |
Robert Love | 3a3b42b | 2009-11-03 11:47:39 -0800 | [diff] [blame] | 943 | if (lport->dns_rdata) |
| 944 | lport->tt.rport_logoff(lport->dns_rdata); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 945 | |
Robert Love | 3a3b42b | 2009-11-03 11:47:39 -0800 | [diff] [blame] | 946 | lport->ptp_rdata = NULL; |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 947 | |
| 948 | lport->tt.disc_stop(lport); |
| 949 | |
Abhijeet Joglekar | 1f6ff36 | 2009-02-27 10:54:35 -0800 | [diff] [blame] | 950 | lport->tt.exch_mgr_reset(lport, 0, 0); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 951 | fc_host_fabric_name(lport->host) = 0; |
Joe Eykholt | 093bb6a | 2009-11-03 11:49:05 -0800 | [diff] [blame] | 952 | |
| 953 | if (fc_host_port_id(lport->host)) |
| 954 | fc_lport_set_port_id(lport, 0, NULL); |
Joe Eykholt | 1190d92 | 2009-07-29 17:04:27 -0700 | [diff] [blame] | 955 | } |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 956 | |
Joe Eykholt | 1190d92 | 2009-07-29 17:04:27 -0700 | [diff] [blame] | 957 | /** |
| 958 | * fc_lport_enter_reset() - Reset the local port |
Robert Love | 3a3b42b | 2009-11-03 11:47:39 -0800 | [diff] [blame] | 959 | * @lport: The local port to be reset |
Joe Eykholt | 1190d92 | 2009-07-29 17:04:27 -0700 | [diff] [blame] | 960 | * |
| 961 | * Locking Note: The lport lock is expected to be held before calling |
| 962 | * this routine. |
| 963 | */ |
| 964 | static void fc_lport_enter_reset(struct fc_lport *lport) |
| 965 | { |
| 966 | FC_LPORT_DBG(lport, "Entered RESET state from %s state\n", |
| 967 | fc_lport_state(lport)); |
| 968 | |
Chris Leech | 8faecdd | 2009-11-03 11:46:19 -0800 | [diff] [blame] | 969 | if (lport->vport) { |
| 970 | if (lport->link_up) |
| 971 | fc_vport_set_state(lport->vport, FC_VPORT_INITIALIZING); |
| 972 | else |
| 973 | fc_vport_set_state(lport->vport, FC_VPORT_LINKDOWN); |
| 974 | } |
Joe Eykholt | 1190d92 | 2009-07-29 17:04:27 -0700 | [diff] [blame] | 975 | fc_lport_state_enter(lport, LPORT_ST_RESET); |
Chris Leech | 8faecdd | 2009-11-03 11:46:19 -0800 | [diff] [blame] | 976 | fc_vports_linkchange(lport); |
Joe Eykholt | 1190d92 | 2009-07-29 17:04:27 -0700 | [diff] [blame] | 977 | fc_lport_reset_locked(lport); |
Vasu Dev | bc0e17f | 2009-02-27 10:54:57 -0800 | [diff] [blame] | 978 | if (lport->link_up) |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 979 | fc_lport_enter_flogi(lport); |
| 980 | } |
| 981 | |
| 982 | /** |
Robert Love | 3a3b42b | 2009-11-03 11:47:39 -0800 | [diff] [blame] | 983 | * fc_lport_enter_disabled() - Disable the local port |
| 984 | * @lport: The local port to be reset |
Joe Eykholt | 1190d92 | 2009-07-29 17:04:27 -0700 | [diff] [blame] | 985 | * |
| 986 | * Locking Note: The lport lock is expected to be held before calling |
| 987 | * this routine. |
| 988 | */ |
| 989 | static void fc_lport_enter_disabled(struct fc_lport *lport) |
| 990 | { |
| 991 | FC_LPORT_DBG(lport, "Entered disabled state from %s state\n", |
| 992 | fc_lport_state(lport)); |
| 993 | |
| 994 | fc_lport_state_enter(lport, LPORT_ST_DISABLED); |
Chris Leech | 8faecdd | 2009-11-03 11:46:19 -0800 | [diff] [blame] | 995 | fc_vports_linkchange(lport); |
Joe Eykholt | 1190d92 | 2009-07-29 17:04:27 -0700 | [diff] [blame] | 996 | fc_lport_reset_locked(lport); |
| 997 | } |
| 998 | |
| 999 | /** |
Robert Love | 34f42a0 | 2009-02-27 10:55:45 -0800 | [diff] [blame] | 1000 | * fc_lport_error() - Handler for any errors |
Robert Love | 3a3b42b | 2009-11-03 11:47:39 -0800 | [diff] [blame] | 1001 | * @lport: The local port that the error was on |
| 1002 | * @fp: The error code encoded in a frame pointer |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 1003 | * |
| 1004 | * If the error was caused by a resource allocation failure |
| 1005 | * then wait for half a second and retry, otherwise retry |
| 1006 | * after the e_d_tov time. |
| 1007 | */ |
| 1008 | static void fc_lport_error(struct fc_lport *lport, struct fc_frame *fp) |
| 1009 | { |
| 1010 | unsigned long delay = 0; |
Robert Love | 7414705 | 2009-06-10 15:31:10 -0700 | [diff] [blame] | 1011 | FC_LPORT_DBG(lport, "Error %ld in state %s, retries %d\n", |
| 1012 | PTR_ERR(fp), fc_lport_state(lport), |
| 1013 | lport->retry_count); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 1014 | |
| 1015 | if (!fp || PTR_ERR(fp) == -FC_EX_TIMEOUT) { |
| 1016 | /* |
| 1017 | * Memory allocation failure, or the exchange timed out. |
| 1018 | * Retry after delay |
| 1019 | */ |
| 1020 | if (lport->retry_count < lport->max_retry_count) { |
| 1021 | lport->retry_count++; |
| 1022 | if (!fp) |
| 1023 | delay = msecs_to_jiffies(500); |
| 1024 | else |
| 1025 | delay = msecs_to_jiffies(lport->e_d_tov); |
| 1026 | |
| 1027 | schedule_delayed_work(&lport->retry_work, delay); |
| 1028 | } else { |
| 1029 | switch (lport->state) { |
Joe Eykholt | b1d9fd5 | 2009-07-29 17:04:22 -0700 | [diff] [blame] | 1030 | case LPORT_ST_DISABLED: |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 1031 | case LPORT_ST_READY: |
| 1032 | case LPORT_ST_RESET: |
Chris Leech | c9c7bd7 | 2009-11-03 11:46:51 -0800 | [diff] [blame] | 1033 | case LPORT_ST_RNN_ID: |
Chris Leech | 5baa17c | 2009-11-03 11:46:56 -0800 | [diff] [blame] | 1034 | case LPORT_ST_RSNN_NN: |
Chris Leech | c9866a5 | 2009-11-03 11:47:01 -0800 | [diff] [blame] | 1035 | case LPORT_ST_RSPN_ID: |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 1036 | case LPORT_ST_RFT_ID: |
| 1037 | case LPORT_ST_SCR: |
| 1038 | case LPORT_ST_DNS: |
| 1039 | case LPORT_ST_FLOGI: |
| 1040 | case LPORT_ST_LOGO: |
| 1041 | fc_lport_enter_reset(lport); |
| 1042 | break; |
| 1043 | } |
| 1044 | } |
| 1045 | } |
| 1046 | } |
| 1047 | |
| 1048 | /** |
Chris Leech | 7cccc15 | 2009-11-03 11:47:07 -0800 | [diff] [blame] | 1049 | * fc_lport_ns_resp() - Handle response to a name server |
Robert Love | 3a3b42b | 2009-11-03 11:47:39 -0800 | [diff] [blame] | 1050 | * registration exchange |
| 1051 | * @sp: current sequence in exchange |
| 1052 | * @fp: response frame |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 1053 | * @lp_arg: Fibre Channel host port instance |
| 1054 | * |
| 1055 | * Locking Note: This function will be called without the lport lock |
Robert Love | 3a3b42b | 2009-11-03 11:47:39 -0800 | [diff] [blame] | 1056 | * held, but it will lock, call an _enter_* function or fc_lport_error() |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 1057 | * and then unlock the lport. |
| 1058 | */ |
Chris Leech | 7cccc15 | 2009-11-03 11:47:07 -0800 | [diff] [blame] | 1059 | static void fc_lport_ns_resp(struct fc_seq *sp, struct fc_frame *fp, |
| 1060 | void *lp_arg) |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 1061 | { |
| 1062 | struct fc_lport *lport = lp_arg; |
| 1063 | struct fc_frame_header *fh; |
| 1064 | struct fc_ct_hdr *ct; |
| 1065 | |
Chris Leech | 7cccc15 | 2009-11-03 11:47:07 -0800 | [diff] [blame] | 1066 | FC_LPORT_DBG(lport, "Received a ns %s\n", fc_els_resp_type(fp)); |
Joe Eykholt | f657d29 | 2009-08-25 14:03:21 -0700 | [diff] [blame] | 1067 | |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 1068 | if (fp == ERR_PTR(-FC_EX_CLOSED)) |
| 1069 | return; |
| 1070 | |
| 1071 | mutex_lock(&lport->lp_mutex); |
| 1072 | |
Chris Leech | 7cccc15 | 2009-11-03 11:47:07 -0800 | [diff] [blame] | 1073 | if (lport->state < LPORT_ST_RNN_ID || lport->state > LPORT_ST_RFT_ID) { |
| 1074 | FC_LPORT_DBG(lport, "Received a name server response, " |
Robert Love | 3a3b42b | 2009-11-03 11:47:39 -0800 | [diff] [blame] | 1075 | "but in state %s\n", fc_lport_state(lport)); |
Abhijeet Joglekar | 76f6804 | 2009-04-21 16:26:58 -0700 | [diff] [blame] | 1076 | if (IS_ERR(fp)) |
| 1077 | goto err; |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 1078 | goto out; |
| 1079 | } |
| 1080 | |
Abhijeet Joglekar | 76f6804 | 2009-04-21 16:26:58 -0700 | [diff] [blame] | 1081 | if (IS_ERR(fp)) { |
| 1082 | fc_lport_error(lport, fp); |
| 1083 | goto err; |
| 1084 | } |
| 1085 | |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 1086 | fh = fc_frame_header_get(fp); |
| 1087 | ct = fc_frame_payload_get(fp, sizeof(*ct)); |
| 1088 | |
| 1089 | if (fh && ct && fh->fh_type == FC_TYPE_CT && |
| 1090 | ct->ct_fs_type == FC_FST_DIR && |
| 1091 | ct->ct_fs_subtype == FC_NS_SUBTYPE && |
| 1092 | ntohs(ct->ct_cmd) == FC_FS_ACC) |
Chris Leech | 7cccc15 | 2009-11-03 11:47:07 -0800 | [diff] [blame] | 1093 | switch (lport->state) { |
| 1094 | case LPORT_ST_RNN_ID: |
Chris Leech | c914f7d | 2009-11-03 11:47:12 -0800 | [diff] [blame] | 1095 | fc_lport_enter_ns(lport, LPORT_ST_RSNN_NN); |
Chris Leech | 7cccc15 | 2009-11-03 11:47:07 -0800 | [diff] [blame] | 1096 | break; |
| 1097 | case LPORT_ST_RSNN_NN: |
Chris Leech | c914f7d | 2009-11-03 11:47:12 -0800 | [diff] [blame] | 1098 | fc_lport_enter_ns(lport, LPORT_ST_RSPN_ID); |
Chris Leech | 7cccc15 | 2009-11-03 11:47:07 -0800 | [diff] [blame] | 1099 | break; |
| 1100 | case LPORT_ST_RSPN_ID: |
Chris Leech | c914f7d | 2009-11-03 11:47:12 -0800 | [diff] [blame] | 1101 | fc_lport_enter_ns(lport, LPORT_ST_RFT_ID); |
Chris Leech | 7cccc15 | 2009-11-03 11:47:07 -0800 | [diff] [blame] | 1102 | break; |
| 1103 | case LPORT_ST_RFT_ID: |
| 1104 | fc_lport_enter_scr(lport); |
| 1105 | break; |
| 1106 | default: |
| 1107 | /* should have already been caught by state checks */ |
| 1108 | break; |
| 1109 | } |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 1110 | else |
| 1111 | fc_lport_error(lport, fp); |
| 1112 | out: |
| 1113 | fc_frame_free(fp); |
| 1114 | err: |
| 1115 | mutex_unlock(&lport->lp_mutex); |
| 1116 | } |
| 1117 | |
| 1118 | /** |
Robert Love | 34f42a0 | 2009-02-27 10:55:45 -0800 | [diff] [blame] | 1119 | * fc_lport_scr_resp() - Handle response to State Change Register (SCR) request |
Robert Love | 3a3b42b | 2009-11-03 11:47:39 -0800 | [diff] [blame] | 1120 | * @sp: current sequence in SCR exchange |
| 1121 | * @fp: response frame |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 1122 | * @lp_arg: Fibre Channel lport port instance that sent the registration request |
| 1123 | * |
| 1124 | * Locking Note: This function will be called without the lport lock |
| 1125 | * held, but it will lock, call an _enter_* function or fc_lport_error |
| 1126 | * and then unlock the lport. |
| 1127 | */ |
| 1128 | static void fc_lport_scr_resp(struct fc_seq *sp, struct fc_frame *fp, |
| 1129 | void *lp_arg) |
| 1130 | { |
| 1131 | struct fc_lport *lport = lp_arg; |
| 1132 | u8 op; |
| 1133 | |
Joe Eykholt | f657d29 | 2009-08-25 14:03:21 -0700 | [diff] [blame] | 1134 | FC_LPORT_DBG(lport, "Received a SCR %s\n", fc_els_resp_type(fp)); |
| 1135 | |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 1136 | if (fp == ERR_PTR(-FC_EX_CLOSED)) |
| 1137 | return; |
| 1138 | |
| 1139 | mutex_lock(&lport->lp_mutex); |
| 1140 | |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 1141 | if (lport->state != LPORT_ST_SCR) { |
Robert Love | 7414705 | 2009-06-10 15:31:10 -0700 | [diff] [blame] | 1142 | FC_LPORT_DBG(lport, "Received a SCR response, but in state " |
| 1143 | "%s\n", fc_lport_state(lport)); |
Abhijeet Joglekar | 76f6804 | 2009-04-21 16:26:58 -0700 | [diff] [blame] | 1144 | if (IS_ERR(fp)) |
| 1145 | goto err; |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 1146 | goto out; |
| 1147 | } |
| 1148 | |
Abhijeet Joglekar | 76f6804 | 2009-04-21 16:26:58 -0700 | [diff] [blame] | 1149 | if (IS_ERR(fp)) { |
| 1150 | fc_lport_error(lport, fp); |
| 1151 | goto err; |
| 1152 | } |
| 1153 | |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 1154 | op = fc_frame_payload_op(fp); |
| 1155 | if (op == ELS_LS_ACC) |
| 1156 | fc_lport_enter_ready(lport); |
| 1157 | else |
| 1158 | fc_lport_error(lport, fp); |
| 1159 | |
| 1160 | out: |
| 1161 | fc_frame_free(fp); |
| 1162 | err: |
| 1163 | mutex_unlock(&lport->lp_mutex); |
| 1164 | } |
| 1165 | |
| 1166 | /** |
Robert Love | 3a3b42b | 2009-11-03 11:47:39 -0800 | [diff] [blame] | 1167 | * fc_lport_enter_scr() - Send a SCR (State Change Register) request |
| 1168 | * @lport: The local port to register for state changes |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 1169 | * |
| 1170 | * Locking Note: The lport lock is expected to be held before calling |
| 1171 | * this routine. |
| 1172 | */ |
| 1173 | static void fc_lport_enter_scr(struct fc_lport *lport) |
| 1174 | { |
| 1175 | struct fc_frame *fp; |
| 1176 | |
Robert Love | 7414705 | 2009-06-10 15:31:10 -0700 | [diff] [blame] | 1177 | FC_LPORT_DBG(lport, "Entered SCR state from %s state\n", |
| 1178 | fc_lport_state(lport)); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 1179 | |
| 1180 | fc_lport_state_enter(lport, LPORT_ST_SCR); |
| 1181 | |
| 1182 | fp = fc_frame_alloc(lport, sizeof(struct fc_els_scr)); |
| 1183 | if (!fp) { |
| 1184 | fc_lport_error(lport, fp); |
| 1185 | return; |
| 1186 | } |
| 1187 | |
Joe Eykholt | a46f327 | 2009-08-25 14:00:55 -0700 | [diff] [blame] | 1188 | if (!lport->tt.elsct_send(lport, FC_FID_FCTRL, fp, ELS_SCR, |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 1189 | fc_lport_scr_resp, lport, lport->e_d_tov)) |
Chris Leech | 8f550f9 | 2009-10-21 16:28:09 -0700 | [diff] [blame] | 1190 | fc_lport_error(lport, NULL); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 1191 | } |
| 1192 | |
| 1193 | /** |
Chris Leech | c914f7d | 2009-11-03 11:47:12 -0800 | [diff] [blame] | 1194 | * fc_lport_enter_ns() - register some object with the name server |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 1195 | * @lport: Fibre Channel local port to register |
| 1196 | * |
| 1197 | * Locking Note: The lport lock is expected to be held before calling |
| 1198 | * this routine. |
| 1199 | */ |
Chris Leech | c914f7d | 2009-11-03 11:47:12 -0800 | [diff] [blame] | 1200 | static void fc_lport_enter_ns(struct fc_lport *lport, enum fc_lport_state state) |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 1201 | { |
| 1202 | struct fc_frame *fp; |
Chris Leech | c914f7d | 2009-11-03 11:47:12 -0800 | [diff] [blame] | 1203 | enum fc_ns_req cmd; |
| 1204 | int size = sizeof(struct fc_ct_hdr); |
Chris Leech | c9866a5 | 2009-11-03 11:47:01 -0800 | [diff] [blame] | 1205 | size_t len; |
| 1206 | |
Chris Leech | c914f7d | 2009-11-03 11:47:12 -0800 | [diff] [blame] | 1207 | FC_LPORT_DBG(lport, "Entered %s state from %s state\n", |
| 1208 | fc_lport_state_names[state], |
Chris Leech | c9866a5 | 2009-11-03 11:47:01 -0800 | [diff] [blame] | 1209 | fc_lport_state(lport)); |
| 1210 | |
Chris Leech | c914f7d | 2009-11-03 11:47:12 -0800 | [diff] [blame] | 1211 | fc_lport_state_enter(lport, state); |
Chris Leech | c9866a5 | 2009-11-03 11:47:01 -0800 | [diff] [blame] | 1212 | |
Chris Leech | c914f7d | 2009-11-03 11:47:12 -0800 | [diff] [blame] | 1213 | switch (state) { |
| 1214 | case LPORT_ST_RNN_ID: |
| 1215 | cmd = FC_NS_RNN_ID; |
| 1216 | size += sizeof(struct fc_ns_rn_id); |
| 1217 | break; |
| 1218 | case LPORT_ST_RSNN_NN: |
| 1219 | len = strnlen(fc_host_symbolic_name(lport->host), 255); |
| 1220 | /* if there is no symbolic name, skip to RFT_ID */ |
| 1221 | if (!len) |
| 1222 | return fc_lport_enter_ns(lport, LPORT_ST_RFT_ID); |
| 1223 | cmd = FC_NS_RSNN_NN; |
| 1224 | size += sizeof(struct fc_ns_rsnn) + len; |
| 1225 | break; |
| 1226 | case LPORT_ST_RSPN_ID: |
| 1227 | len = strnlen(fc_host_symbolic_name(lport->host), 255); |
| 1228 | /* if there is no symbolic name, skip to RFT_ID */ |
| 1229 | if (!len) |
| 1230 | return fc_lport_enter_ns(lport, LPORT_ST_RFT_ID); |
| 1231 | cmd = FC_NS_RSPN_ID; |
| 1232 | size += sizeof(struct fc_ns_rspn) + len; |
| 1233 | break; |
| 1234 | case LPORT_ST_RFT_ID: |
| 1235 | cmd = FC_NS_RFT_ID; |
| 1236 | size += sizeof(struct fc_ns_rft); |
| 1237 | break; |
| 1238 | default: |
| 1239 | fc_lport_error(lport, NULL); |
| 1240 | return; |
| 1241 | } |
| 1242 | |
| 1243 | fp = fc_frame_alloc(lport, size); |
Chris Leech | c9866a5 | 2009-11-03 11:47:01 -0800 | [diff] [blame] | 1244 | if (!fp) { |
| 1245 | fc_lport_error(lport, fp); |
| 1246 | return; |
| 1247 | } |
| 1248 | |
Chris Leech | c914f7d | 2009-11-03 11:47:12 -0800 | [diff] [blame] | 1249 | if (!lport->tt.elsct_send(lport, FC_FID_DIR_SERV, fp, cmd, |
Chris Leech | 7cccc15 | 2009-11-03 11:47:07 -0800 | [diff] [blame] | 1250 | fc_lport_ns_resp, |
Chris Leech | c9c7bd7 | 2009-11-03 11:46:51 -0800 | [diff] [blame] | 1251 | lport, lport->e_d_tov)) |
| 1252 | fc_lport_error(lport, fp); |
| 1253 | } |
| 1254 | |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 1255 | static struct fc_rport_operations fc_lport_rport_ops = { |
| 1256 | .event_callback = fc_lport_rport_callback, |
| 1257 | }; |
| 1258 | |
| 1259 | /** |
Robert Love | 3a3b42b | 2009-11-03 11:47:39 -0800 | [diff] [blame] | 1260 | * fc_rport_enter_dns() - Create a fc_rport for the name server |
| 1261 | * @lport: The local port requesting a remote port for the name server |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 1262 | * |
| 1263 | * Locking Note: The lport lock is expected to be held before calling |
| 1264 | * this routine. |
| 1265 | */ |
| 1266 | static void fc_lport_enter_dns(struct fc_lport *lport) |
| 1267 | { |
Joe Eykholt | ab28f1f | 2009-08-25 14:00:34 -0700 | [diff] [blame] | 1268 | struct fc_rport_priv *rdata; |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 1269 | |
Robert Love | 7414705 | 2009-06-10 15:31:10 -0700 | [diff] [blame] | 1270 | FC_LPORT_DBG(lport, "Entered DNS state from %s state\n", |
| 1271 | fc_lport_state(lport)); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 1272 | |
| 1273 | fc_lport_state_enter(lport, LPORT_ST_DNS); |
| 1274 | |
Joe Eykholt | 48f0090 | 2009-08-25 14:01:50 -0700 | [diff] [blame] | 1275 | mutex_lock(&lport->disc.disc_mutex); |
Robert Love | 9737e6a | 2009-08-25 14:02:59 -0700 | [diff] [blame] | 1276 | rdata = lport->tt.rport_create(lport, FC_FID_DIR_SERV); |
Joe Eykholt | 48f0090 | 2009-08-25 14:01:50 -0700 | [diff] [blame] | 1277 | mutex_unlock(&lport->disc.disc_mutex); |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame] | 1278 | if (!rdata) |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 1279 | goto err; |
| 1280 | |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 1281 | rdata->ops = &fc_lport_rport_ops; |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame] | 1282 | lport->tt.rport_login(rdata); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 1283 | return; |
| 1284 | |
| 1285 | err: |
| 1286 | fc_lport_error(lport, NULL); |
| 1287 | } |
| 1288 | |
| 1289 | /** |
Robert Love | 3a3b42b | 2009-11-03 11:47:39 -0800 | [diff] [blame] | 1290 | * fc_lport_timeout() - Handler for the retry_work timer |
| 1291 | * @work: The work struct of the local port |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 1292 | */ |
| 1293 | static void fc_lport_timeout(struct work_struct *work) |
| 1294 | { |
| 1295 | struct fc_lport *lport = |
| 1296 | container_of(work, struct fc_lport, |
| 1297 | retry_work.work); |
| 1298 | |
| 1299 | mutex_lock(&lport->lp_mutex); |
| 1300 | |
| 1301 | switch (lport->state) { |
Joe Eykholt | b1d9fd5 | 2009-07-29 17:04:22 -0700 | [diff] [blame] | 1302 | case LPORT_ST_DISABLED: |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 1303 | WARN_ON(1); |
| 1304 | break; |
Joe Eykholt | 22655ac | 2009-10-21 16:27:22 -0700 | [diff] [blame] | 1305 | case LPORT_ST_READY: |
| 1306 | WARN_ON(1); |
| 1307 | break; |
| 1308 | case LPORT_ST_RESET: |
| 1309 | break; |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 1310 | case LPORT_ST_FLOGI: |
| 1311 | fc_lport_enter_flogi(lport); |
| 1312 | break; |
| 1313 | case LPORT_ST_DNS: |
| 1314 | fc_lport_enter_dns(lport); |
| 1315 | break; |
Chris Leech | c9c7bd7 | 2009-11-03 11:46:51 -0800 | [diff] [blame] | 1316 | case LPORT_ST_RNN_ID: |
Chris Leech | 5baa17c | 2009-11-03 11:46:56 -0800 | [diff] [blame] | 1317 | case LPORT_ST_RSNN_NN: |
Chris Leech | c9866a5 | 2009-11-03 11:47:01 -0800 | [diff] [blame] | 1318 | case LPORT_ST_RSPN_ID: |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 1319 | case LPORT_ST_RFT_ID: |
Chris Leech | c914f7d | 2009-11-03 11:47:12 -0800 | [diff] [blame] | 1320 | fc_lport_enter_ns(lport, lport->state); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 1321 | break; |
| 1322 | case LPORT_ST_SCR: |
| 1323 | fc_lport_enter_scr(lport); |
| 1324 | break; |
| 1325 | case LPORT_ST_LOGO: |
| 1326 | fc_lport_enter_logo(lport); |
| 1327 | break; |
| 1328 | } |
| 1329 | |
| 1330 | mutex_unlock(&lport->lp_mutex); |
| 1331 | } |
| 1332 | |
| 1333 | /** |
Robert Love | 34f42a0 | 2009-02-27 10:55:45 -0800 | [diff] [blame] | 1334 | * fc_lport_logo_resp() - Handle response to LOGO request |
Robert Love | 3a3b42b | 2009-11-03 11:47:39 -0800 | [diff] [blame] | 1335 | * @sp: The sequence that the LOGO was on |
| 1336 | * @fp: The LOGO frame |
| 1337 | * @lp_arg: The lport port that received the LOGO request |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 1338 | * |
| 1339 | * Locking Note: This function will be called without the lport lock |
Robert Love | 3a3b42b | 2009-11-03 11:47:39 -0800 | [diff] [blame] | 1340 | * held, but it will lock, call an _enter_* function or fc_lport_error() |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 1341 | * and then unlock the lport. |
| 1342 | */ |
Chris Leech | 11b5618 | 2009-11-03 11:46:29 -0800 | [diff] [blame] | 1343 | void fc_lport_logo_resp(struct fc_seq *sp, struct fc_frame *fp, |
Robert Love | 3a3b42b | 2009-11-03 11:47:39 -0800 | [diff] [blame] | 1344 | void *lp_arg) |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 1345 | { |
| 1346 | struct fc_lport *lport = lp_arg; |
| 1347 | u8 op; |
| 1348 | |
Joe Eykholt | f657d29 | 2009-08-25 14:03:21 -0700 | [diff] [blame] | 1349 | FC_LPORT_DBG(lport, "Received a LOGO %s\n", fc_els_resp_type(fp)); |
| 1350 | |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 1351 | if (fp == ERR_PTR(-FC_EX_CLOSED)) |
| 1352 | return; |
| 1353 | |
| 1354 | mutex_lock(&lport->lp_mutex); |
| 1355 | |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 1356 | if (lport->state != LPORT_ST_LOGO) { |
Robert Love | 7414705 | 2009-06-10 15:31:10 -0700 | [diff] [blame] | 1357 | FC_LPORT_DBG(lport, "Received a LOGO response, but in state " |
| 1358 | "%s\n", fc_lport_state(lport)); |
Abhijeet Joglekar | 76f6804 | 2009-04-21 16:26:58 -0700 | [diff] [blame] | 1359 | if (IS_ERR(fp)) |
| 1360 | goto err; |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 1361 | goto out; |
| 1362 | } |
| 1363 | |
Abhijeet Joglekar | 76f6804 | 2009-04-21 16:26:58 -0700 | [diff] [blame] | 1364 | if (IS_ERR(fp)) { |
| 1365 | fc_lport_error(lport, fp); |
| 1366 | goto err; |
| 1367 | } |
| 1368 | |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 1369 | op = fc_frame_payload_op(fp); |
| 1370 | if (op == ELS_LS_ACC) |
Joe Eykholt | 1190d92 | 2009-07-29 17:04:27 -0700 | [diff] [blame] | 1371 | fc_lport_enter_disabled(lport); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 1372 | else |
| 1373 | fc_lport_error(lport, fp); |
| 1374 | |
| 1375 | out: |
| 1376 | fc_frame_free(fp); |
| 1377 | err: |
| 1378 | mutex_unlock(&lport->lp_mutex); |
| 1379 | } |
Chris Leech | 11b5618 | 2009-11-03 11:46:29 -0800 | [diff] [blame] | 1380 | EXPORT_SYMBOL(fc_lport_logo_resp); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 1381 | |
| 1382 | /** |
Robert Love | 34f42a0 | 2009-02-27 10:55:45 -0800 | [diff] [blame] | 1383 | * fc_rport_enter_logo() - Logout of the fabric |
Robert Love | 3a3b42b | 2009-11-03 11:47:39 -0800 | [diff] [blame] | 1384 | * @lport: The local port to be logged out |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 1385 | * |
| 1386 | * Locking Note: The lport lock is expected to be held before calling |
| 1387 | * this routine. |
| 1388 | */ |
| 1389 | static void fc_lport_enter_logo(struct fc_lport *lport) |
| 1390 | { |
| 1391 | struct fc_frame *fp; |
| 1392 | struct fc_els_logo *logo; |
| 1393 | |
Robert Love | 7414705 | 2009-06-10 15:31:10 -0700 | [diff] [blame] | 1394 | FC_LPORT_DBG(lport, "Entered LOGO state from %s state\n", |
| 1395 | fc_lport_state(lport)); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 1396 | |
| 1397 | fc_lport_state_enter(lport, LPORT_ST_LOGO); |
Chris Leech | 8faecdd | 2009-11-03 11:46:19 -0800 | [diff] [blame] | 1398 | fc_vports_linkchange(lport); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 1399 | |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 1400 | fp = fc_frame_alloc(lport, sizeof(*logo)); |
| 1401 | if (!fp) { |
| 1402 | fc_lport_error(lport, fp); |
| 1403 | return; |
| 1404 | } |
| 1405 | |
Joe Eykholt | a46f327 | 2009-08-25 14:00:55 -0700 | [diff] [blame] | 1406 | if (!lport->tt.elsct_send(lport, FC_FID_FLOGI, fp, ELS_LOGO, |
| 1407 | fc_lport_logo_resp, lport, lport->e_d_tov)) |
Chris Leech | 8f550f9 | 2009-10-21 16:28:09 -0700 | [diff] [blame] | 1408 | fc_lport_error(lport, NULL); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 1409 | } |
| 1410 | |
| 1411 | /** |
Robert Love | 34f42a0 | 2009-02-27 10:55:45 -0800 | [diff] [blame] | 1412 | * fc_lport_flogi_resp() - Handle response to FLOGI request |
Robert Love | 3a3b42b | 2009-11-03 11:47:39 -0800 | [diff] [blame] | 1413 | * @sp: The sequence that the FLOGI was on |
| 1414 | * @fp: The FLOGI response frame |
| 1415 | * @lp_arg: The lport port that received the FLOGI response |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 1416 | * |
| 1417 | * Locking Note: This function will be called without the lport lock |
Robert Love | 3a3b42b | 2009-11-03 11:47:39 -0800 | [diff] [blame] | 1418 | * held, but it will lock, call an _enter_* function or fc_lport_error() |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 1419 | * and then unlock the lport. |
| 1420 | */ |
Chris Leech | 11b5618 | 2009-11-03 11:46:29 -0800 | [diff] [blame] | 1421 | void fc_lport_flogi_resp(struct fc_seq *sp, struct fc_frame *fp, |
Robert Love | 3a3b42b | 2009-11-03 11:47:39 -0800 | [diff] [blame] | 1422 | void *lp_arg) |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 1423 | { |
| 1424 | struct fc_lport *lport = lp_arg; |
| 1425 | struct fc_frame_header *fh; |
| 1426 | struct fc_els_flogi *flp; |
| 1427 | u32 did; |
| 1428 | u16 csp_flags; |
| 1429 | unsigned int r_a_tov; |
| 1430 | unsigned int e_d_tov; |
| 1431 | u16 mfs; |
| 1432 | |
Joe Eykholt | f657d29 | 2009-08-25 14:03:21 -0700 | [diff] [blame] | 1433 | FC_LPORT_DBG(lport, "Received a FLOGI %s\n", fc_els_resp_type(fp)); |
| 1434 | |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 1435 | if (fp == ERR_PTR(-FC_EX_CLOSED)) |
| 1436 | return; |
| 1437 | |
| 1438 | mutex_lock(&lport->lp_mutex); |
| 1439 | |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 1440 | if (lport->state != LPORT_ST_FLOGI) { |
Robert Love | 7414705 | 2009-06-10 15:31:10 -0700 | [diff] [blame] | 1441 | FC_LPORT_DBG(lport, "Received a FLOGI response, but in state " |
| 1442 | "%s\n", fc_lport_state(lport)); |
Abhijeet Joglekar | 76f6804 | 2009-04-21 16:26:58 -0700 | [diff] [blame] | 1443 | if (IS_ERR(fp)) |
| 1444 | goto err; |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 1445 | goto out; |
| 1446 | } |
| 1447 | |
Abhijeet Joglekar | 76f6804 | 2009-04-21 16:26:58 -0700 | [diff] [blame] | 1448 | if (IS_ERR(fp)) { |
| 1449 | fc_lport_error(lport, fp); |
| 1450 | goto err; |
| 1451 | } |
| 1452 | |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 1453 | fh = fc_frame_header_get(fp); |
| 1454 | did = ntoh24(fh->fh_d_id); |
| 1455 | if (fc_frame_payload_op(fp) == ELS_LS_ACC && did != 0) { |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 1456 | flp = fc_frame_payload_get(fp, sizeof(*flp)); |
| 1457 | if (flp) { |
| 1458 | mfs = ntohs(flp->fl_csp.sp_bb_data) & |
| 1459 | FC_SP_BB_DATA_MASK; |
| 1460 | if (mfs >= FC_SP_MIN_MAX_PAYLOAD && |
| 1461 | mfs < lport->mfs) |
| 1462 | lport->mfs = mfs; |
| 1463 | csp_flags = ntohs(flp->fl_csp.sp_features); |
| 1464 | r_a_tov = ntohl(flp->fl_csp.sp_r_a_tov); |
| 1465 | e_d_tov = ntohl(flp->fl_csp.sp_e_d_tov); |
| 1466 | if (csp_flags & FC_SP_FT_EDTR) |
| 1467 | e_d_tov /= 1000000; |
Chris Leech | db36c06 | 2009-11-03 11:46:24 -0800 | [diff] [blame] | 1468 | |
| 1469 | lport->npiv_enabled = !!(csp_flags & FC_SP_FT_NPIV_ACC); |
| 1470 | |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 1471 | if ((csp_flags & FC_SP_FT_FPORT) == 0) { |
| 1472 | if (e_d_tov > lport->e_d_tov) |
| 1473 | lport->e_d_tov = e_d_tov; |
| 1474 | lport->r_a_tov = 2 * e_d_tov; |
Joe Eykholt | 093bb6a | 2009-11-03 11:49:05 -0800 | [diff] [blame] | 1475 | fc_lport_set_port_id(lport, did, fp); |
Joe Eykholt | e6d8a1b | 2009-11-03 11:49:11 -0800 | [diff] [blame^] | 1476 | printk(KERN_INFO "host%d: libfc: " |
| 1477 | "Port (%6x) entered " |
| 1478 | "point-to-point mode\n", |
| 1479 | lport->host->host_no, did); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 1480 | fc_lport_ptp_setup(lport, ntoh24(fh->fh_s_id), |
| 1481 | get_unaligned_be64( |
| 1482 | &flp->fl_wwpn), |
| 1483 | get_unaligned_be64( |
| 1484 | &flp->fl_wwnn)); |
| 1485 | } else { |
| 1486 | lport->e_d_tov = e_d_tov; |
| 1487 | lport->r_a_tov = r_a_tov; |
| 1488 | fc_host_fabric_name(lport->host) = |
| 1489 | get_unaligned_be64(&flp->fl_wwnn); |
Joe Eykholt | 093bb6a | 2009-11-03 11:49:05 -0800 | [diff] [blame] | 1490 | fc_lport_set_port_id(lport, did, fp); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 1491 | fc_lport_enter_dns(lport); |
| 1492 | } |
| 1493 | } |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 1494 | } else { |
Robert Love | 7414705 | 2009-06-10 15:31:10 -0700 | [diff] [blame] | 1495 | FC_LPORT_DBG(lport, "Bad FLOGI response\n"); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 1496 | } |
| 1497 | |
| 1498 | out: |
| 1499 | fc_frame_free(fp); |
| 1500 | err: |
| 1501 | mutex_unlock(&lport->lp_mutex); |
| 1502 | } |
Chris Leech | 11b5618 | 2009-11-03 11:46:29 -0800 | [diff] [blame] | 1503 | EXPORT_SYMBOL(fc_lport_flogi_resp); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 1504 | |
| 1505 | /** |
Robert Love | 34f42a0 | 2009-02-27 10:55:45 -0800 | [diff] [blame] | 1506 | * fc_rport_enter_flogi() - Send a FLOGI request to the fabric manager |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 1507 | * @lport: Fibre Channel local port to be logged in to the fabric |
| 1508 | * |
| 1509 | * Locking Note: The lport lock is expected to be held before calling |
| 1510 | * this routine. |
| 1511 | */ |
| 1512 | void fc_lport_enter_flogi(struct fc_lport *lport) |
| 1513 | { |
| 1514 | struct fc_frame *fp; |
| 1515 | |
Robert Love | 7414705 | 2009-06-10 15:31:10 -0700 | [diff] [blame] | 1516 | FC_LPORT_DBG(lport, "Entered FLOGI state from %s state\n", |
| 1517 | fc_lport_state(lport)); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 1518 | |
| 1519 | fc_lport_state_enter(lport, LPORT_ST_FLOGI); |
| 1520 | |
| 1521 | fp = fc_frame_alloc(lport, sizeof(struct fc_els_flogi)); |
| 1522 | if (!fp) |
| 1523 | return fc_lport_error(lport, fp); |
| 1524 | |
Chris Leech | db36c06 | 2009-11-03 11:46:24 -0800 | [diff] [blame] | 1525 | if (!lport->tt.elsct_send(lport, FC_FID_FLOGI, fp, |
| 1526 | lport->vport ? ELS_FDISC : ELS_FLOGI, |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 1527 | fc_lport_flogi_resp, lport, lport->e_d_tov)) |
Chris Leech | 8f550f9 | 2009-10-21 16:28:09 -0700 | [diff] [blame] | 1528 | fc_lport_error(lport, NULL); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 1529 | } |
| 1530 | |
Robert Love | 3a3b42b | 2009-11-03 11:47:39 -0800 | [diff] [blame] | 1531 | /** |
| 1532 | * fc_lport_config() - Configure a fc_lport |
| 1533 | * @lport: The local port to be configured |
| 1534 | */ |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 1535 | int fc_lport_config(struct fc_lport *lport) |
| 1536 | { |
| 1537 | INIT_DELAYED_WORK(&lport->retry_work, fc_lport_timeout); |
| 1538 | mutex_init(&lport->lp_mutex); |
| 1539 | |
Joe Eykholt | b1d9fd5 | 2009-07-29 17:04:22 -0700 | [diff] [blame] | 1540 | fc_lport_state_enter(lport, LPORT_ST_DISABLED); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 1541 | |
| 1542 | fc_lport_add_fc4_type(lport, FC_TYPE_FCP); |
| 1543 | fc_lport_add_fc4_type(lport, FC_TYPE_CT); |
| 1544 | |
| 1545 | return 0; |
| 1546 | } |
| 1547 | EXPORT_SYMBOL(fc_lport_config); |
| 1548 | |
Robert Love | 3a3b42b | 2009-11-03 11:47:39 -0800 | [diff] [blame] | 1549 | /** |
| 1550 | * fc_lport_init() - Initialize the lport layer for a local port |
| 1551 | * @lport: The local port to initialize the exchange layer for |
| 1552 | */ |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 1553 | int fc_lport_init(struct fc_lport *lport) |
| 1554 | { |
| 1555 | if (!lport->tt.lport_recv) |
| 1556 | lport->tt.lport_recv = fc_lport_recv_req; |
| 1557 | |
| 1558 | if (!lport->tt.lport_reset) |
| 1559 | lport->tt.lport_reset = fc_lport_reset; |
| 1560 | |
| 1561 | fc_host_port_type(lport->host) = FC_PORTTYPE_NPORT; |
| 1562 | fc_host_node_name(lport->host) = lport->wwnn; |
| 1563 | fc_host_port_name(lport->host) = lport->wwpn; |
| 1564 | fc_host_supported_classes(lport->host) = FC_COS_CLASS3; |
| 1565 | memset(fc_host_supported_fc4s(lport->host), 0, |
| 1566 | sizeof(fc_host_supported_fc4s(lport->host))); |
| 1567 | fc_host_supported_fc4s(lport->host)[2] = 1; |
| 1568 | fc_host_supported_fc4s(lport->host)[7] = 1; |
| 1569 | |
| 1570 | /* This value is also unchanging */ |
| 1571 | memset(fc_host_active_fc4s(lport->host), 0, |
| 1572 | sizeof(fc_host_active_fc4s(lport->host))); |
| 1573 | fc_host_active_fc4s(lport->host)[2] = 1; |
| 1574 | fc_host_active_fc4s(lport->host)[7] = 1; |
| 1575 | fc_host_maxframe_size(lport->host) = lport->mfs; |
| 1576 | fc_host_supported_speeds(lport->host) = 0; |
| 1577 | if (lport->link_supported_speeds & FC_PORTSPEED_1GBIT) |
| 1578 | fc_host_supported_speeds(lport->host) |= FC_PORTSPEED_1GBIT; |
| 1579 | if (lport->link_supported_speeds & FC_PORTSPEED_10GBIT) |
| 1580 | fc_host_supported_speeds(lport->host) |= FC_PORTSPEED_10GBIT; |
| 1581 | |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 1582 | return 0; |
| 1583 | } |
| 1584 | EXPORT_SYMBOL(fc_lport_init); |
Steve Ma | a51ab39 | 2009-11-03 11:47:34 -0800 | [diff] [blame] | 1585 | |
| 1586 | /** |
Robert Love | 3a3b42b | 2009-11-03 11:47:39 -0800 | [diff] [blame] | 1587 | * fc_lport_bsg_resp() - The common response handler for FC Passthrough requests |
| 1588 | * @sp: The sequence for the FC Passthrough response |
| 1589 | * @fp: The response frame |
| 1590 | * @info_arg: The BSG info that the response is for |
Steve Ma | a51ab39 | 2009-11-03 11:47:34 -0800 | [diff] [blame] | 1591 | */ |
| 1592 | static void fc_lport_bsg_resp(struct fc_seq *sp, struct fc_frame *fp, |
| 1593 | void *info_arg) |
| 1594 | { |
| 1595 | struct fc_bsg_info *info = info_arg; |
| 1596 | struct fc_bsg_job *job = info->job; |
| 1597 | struct fc_lport *lport = info->lport; |
| 1598 | struct fc_frame_header *fh; |
| 1599 | size_t len; |
| 1600 | void *buf; |
| 1601 | |
| 1602 | if (IS_ERR(fp)) { |
| 1603 | job->reply->result = (PTR_ERR(fp) == -FC_EX_CLOSED) ? |
| 1604 | -ECONNABORTED : -ETIMEDOUT; |
| 1605 | job->reply_len = sizeof(uint32_t); |
| 1606 | job->state_flags |= FC_RQST_STATE_DONE; |
| 1607 | job->job_done(job); |
| 1608 | kfree(info); |
| 1609 | return; |
| 1610 | } |
| 1611 | |
| 1612 | mutex_lock(&lport->lp_mutex); |
| 1613 | fh = fc_frame_header_get(fp); |
| 1614 | len = fr_len(fp) - sizeof(*fh); |
| 1615 | buf = fc_frame_payload_get(fp, 0); |
| 1616 | |
| 1617 | if (fr_sof(fp) == FC_SOF_I3 && !ntohs(fh->fh_seq_cnt)) { |
| 1618 | /* Get the response code from the first frame payload */ |
| 1619 | unsigned short cmd = (info->rsp_code == FC_FS_ACC) ? |
| 1620 | ntohs(((struct fc_ct_hdr *)buf)->ct_cmd) : |
| 1621 | (unsigned short)fc_frame_payload_op(fp); |
| 1622 | |
| 1623 | /* Save the reply status of the job */ |
| 1624 | job->reply->reply_data.ctels_reply.status = |
| 1625 | (cmd == info->rsp_code) ? |
| 1626 | FC_CTELS_STATUS_OK : FC_CTELS_STATUS_REJECT; |
| 1627 | } |
| 1628 | |
| 1629 | job->reply->reply_payload_rcv_len += |
| 1630 | fc_copy_buffer_to_sglist(buf, len, info->sg, &info->nents, |
| 1631 | &info->offset, KM_BIO_SRC_IRQ, NULL); |
| 1632 | |
| 1633 | if (fr_eof(fp) == FC_EOF_T && |
| 1634 | (ntoh24(fh->fh_f_ctl) & (FC_FC_LAST_SEQ | FC_FC_END_SEQ)) == |
| 1635 | (FC_FC_LAST_SEQ | FC_FC_END_SEQ)) { |
| 1636 | if (job->reply->reply_payload_rcv_len > |
| 1637 | job->reply_payload.payload_len) |
| 1638 | job->reply->reply_payload_rcv_len = |
| 1639 | job->reply_payload.payload_len; |
| 1640 | job->reply->result = 0; |
| 1641 | job->state_flags |= FC_RQST_STATE_DONE; |
| 1642 | job->job_done(job); |
| 1643 | kfree(info); |
| 1644 | } |
| 1645 | fc_frame_free(fp); |
| 1646 | mutex_unlock(&lport->lp_mutex); |
| 1647 | } |
| 1648 | |
| 1649 | /** |
Robert Love | 3a3b42b | 2009-11-03 11:47:39 -0800 | [diff] [blame] | 1650 | * fc_lport_els_request() - Send ELS passthrough request |
| 1651 | * @job: The BSG Passthrough job |
Steve Ma | a51ab39 | 2009-11-03 11:47:34 -0800 | [diff] [blame] | 1652 | * @lport: The local port sending the request |
Robert Love | 3a3b42b | 2009-11-03 11:47:39 -0800 | [diff] [blame] | 1653 | * @did: The destination port id |
Steve Ma | a51ab39 | 2009-11-03 11:47:34 -0800 | [diff] [blame] | 1654 | * |
| 1655 | * Locking Note: The lport lock is expected to be held before calling |
| 1656 | * this routine. |
| 1657 | */ |
| 1658 | static int fc_lport_els_request(struct fc_bsg_job *job, |
| 1659 | struct fc_lport *lport, |
| 1660 | u32 did, u32 tov) |
| 1661 | { |
| 1662 | struct fc_bsg_info *info; |
| 1663 | struct fc_frame *fp; |
| 1664 | struct fc_frame_header *fh; |
| 1665 | char *pp; |
| 1666 | int len; |
| 1667 | |
| 1668 | fp = fc_frame_alloc(lport, sizeof(struct fc_frame_header) + |
| 1669 | job->request_payload.payload_len); |
| 1670 | if (!fp) |
| 1671 | return -ENOMEM; |
| 1672 | |
| 1673 | len = job->request_payload.payload_len; |
| 1674 | pp = fc_frame_payload_get(fp, len); |
| 1675 | |
| 1676 | sg_copy_to_buffer(job->request_payload.sg_list, |
| 1677 | job->request_payload.sg_cnt, |
| 1678 | pp, len); |
| 1679 | |
| 1680 | fh = fc_frame_header_get(fp); |
| 1681 | fh->fh_r_ctl = FC_RCTL_ELS_REQ; |
| 1682 | hton24(fh->fh_d_id, did); |
| 1683 | hton24(fh->fh_s_id, fc_host_port_id(lport->host)); |
| 1684 | fh->fh_type = FC_TYPE_ELS; |
| 1685 | hton24(fh->fh_f_ctl, FC_FC_FIRST_SEQ | |
| 1686 | FC_FC_END_SEQ | FC_FC_SEQ_INIT); |
| 1687 | fh->fh_cs_ctl = 0; |
| 1688 | fh->fh_df_ctl = 0; |
| 1689 | fh->fh_parm_offset = 0; |
| 1690 | |
| 1691 | info = kzalloc(sizeof(struct fc_bsg_info), GFP_KERNEL); |
| 1692 | if (!info) { |
| 1693 | fc_frame_free(fp); |
| 1694 | return -ENOMEM; |
| 1695 | } |
| 1696 | |
| 1697 | info->job = job; |
| 1698 | info->lport = lport; |
| 1699 | info->rsp_code = ELS_LS_ACC; |
| 1700 | info->nents = job->reply_payload.sg_cnt; |
| 1701 | info->sg = job->reply_payload.sg_list; |
| 1702 | |
| 1703 | if (!lport->tt.exch_seq_send(lport, fp, fc_lport_bsg_resp, |
| 1704 | NULL, info, tov)) |
| 1705 | return -ECOMM; |
| 1706 | return 0; |
| 1707 | } |
| 1708 | |
| 1709 | /** |
Robert Love | 3a3b42b | 2009-11-03 11:47:39 -0800 | [diff] [blame] | 1710 | * fc_lport_ct_request() - Send CT Passthrough request |
| 1711 | * @job: The BSG Passthrough job |
Steve Ma | a51ab39 | 2009-11-03 11:47:34 -0800 | [diff] [blame] | 1712 | * @lport: The local port sending the request |
| 1713 | * @did: The destination FC-ID |
Robert Love | 3a3b42b | 2009-11-03 11:47:39 -0800 | [diff] [blame] | 1714 | * @tov: The timeout period to wait for the response |
Steve Ma | a51ab39 | 2009-11-03 11:47:34 -0800 | [diff] [blame] | 1715 | * |
| 1716 | * Locking Note: The lport lock is expected to be held before calling |
| 1717 | * this routine. |
| 1718 | */ |
| 1719 | static int fc_lport_ct_request(struct fc_bsg_job *job, |
| 1720 | struct fc_lport *lport, u32 did, u32 tov) |
| 1721 | { |
| 1722 | struct fc_bsg_info *info; |
| 1723 | struct fc_frame *fp; |
| 1724 | struct fc_frame_header *fh; |
| 1725 | struct fc_ct_req *ct; |
| 1726 | size_t len; |
| 1727 | |
| 1728 | fp = fc_frame_alloc(lport, sizeof(struct fc_ct_hdr) + |
| 1729 | job->request_payload.payload_len); |
| 1730 | if (!fp) |
| 1731 | return -ENOMEM; |
| 1732 | |
| 1733 | len = job->request_payload.payload_len; |
| 1734 | ct = fc_frame_payload_get(fp, len); |
| 1735 | |
| 1736 | sg_copy_to_buffer(job->request_payload.sg_list, |
| 1737 | job->request_payload.sg_cnt, |
| 1738 | ct, len); |
| 1739 | |
| 1740 | fh = fc_frame_header_get(fp); |
| 1741 | fh->fh_r_ctl = FC_RCTL_DD_UNSOL_CTL; |
| 1742 | hton24(fh->fh_d_id, did); |
| 1743 | hton24(fh->fh_s_id, fc_host_port_id(lport->host)); |
| 1744 | fh->fh_type = FC_TYPE_CT; |
| 1745 | hton24(fh->fh_f_ctl, FC_FC_FIRST_SEQ | |
| 1746 | FC_FC_END_SEQ | FC_FC_SEQ_INIT); |
| 1747 | fh->fh_cs_ctl = 0; |
| 1748 | fh->fh_df_ctl = 0; |
| 1749 | fh->fh_parm_offset = 0; |
| 1750 | |
| 1751 | info = kzalloc(sizeof(struct fc_bsg_info), GFP_KERNEL); |
| 1752 | if (!info) { |
| 1753 | fc_frame_free(fp); |
| 1754 | return -ENOMEM; |
| 1755 | } |
| 1756 | |
| 1757 | info->job = job; |
| 1758 | info->lport = lport; |
| 1759 | info->rsp_code = FC_FS_ACC; |
| 1760 | info->nents = job->reply_payload.sg_cnt; |
| 1761 | info->sg = job->reply_payload.sg_list; |
| 1762 | |
| 1763 | if (!lport->tt.exch_seq_send(lport, fp, fc_lport_bsg_resp, |
| 1764 | NULL, info, tov)) |
| 1765 | return -ECOMM; |
| 1766 | return 0; |
| 1767 | } |
| 1768 | |
| 1769 | /** |
| 1770 | * fc_lport_bsg_request() - The common entry point for sending |
Robert Love | 3a3b42b | 2009-11-03 11:47:39 -0800 | [diff] [blame] | 1771 | * FC Passthrough requests |
| 1772 | * @job: The BSG passthrough job |
Steve Ma | a51ab39 | 2009-11-03 11:47:34 -0800 | [diff] [blame] | 1773 | */ |
| 1774 | int fc_lport_bsg_request(struct fc_bsg_job *job) |
| 1775 | { |
| 1776 | struct request *rsp = job->req->next_rq; |
| 1777 | struct Scsi_Host *shost = job->shost; |
| 1778 | struct fc_lport *lport = shost_priv(shost); |
| 1779 | struct fc_rport *rport; |
| 1780 | struct fc_rport_priv *rdata; |
| 1781 | int rc = -EINVAL; |
| 1782 | u32 did; |
| 1783 | |
| 1784 | job->reply->reply_payload_rcv_len = 0; |
| 1785 | rsp->resid_len = job->reply_payload.payload_len; |
| 1786 | |
| 1787 | mutex_lock(&lport->lp_mutex); |
| 1788 | |
| 1789 | switch (job->request->msgcode) { |
| 1790 | case FC_BSG_RPT_ELS: |
| 1791 | rport = job->rport; |
| 1792 | if (!rport) |
| 1793 | break; |
| 1794 | |
| 1795 | rdata = rport->dd_data; |
| 1796 | rc = fc_lport_els_request(job, lport, rport->port_id, |
| 1797 | rdata->e_d_tov); |
| 1798 | break; |
| 1799 | |
| 1800 | case FC_BSG_RPT_CT: |
| 1801 | rport = job->rport; |
| 1802 | if (!rport) |
| 1803 | break; |
| 1804 | |
| 1805 | rdata = rport->dd_data; |
| 1806 | rc = fc_lport_ct_request(job, lport, rport->port_id, |
| 1807 | rdata->e_d_tov); |
| 1808 | break; |
| 1809 | |
| 1810 | case FC_BSG_HST_CT: |
| 1811 | did = ntoh24(job->request->rqst_data.h_ct.port_id); |
| 1812 | if (did == FC_FID_DIR_SERV) |
Robert Love | 3a3b42b | 2009-11-03 11:47:39 -0800 | [diff] [blame] | 1813 | rdata = lport->dns_rdata; |
Steve Ma | a51ab39 | 2009-11-03 11:47:34 -0800 | [diff] [blame] | 1814 | else |
| 1815 | rdata = lport->tt.rport_lookup(lport, did); |
| 1816 | |
| 1817 | if (!rdata) |
| 1818 | break; |
| 1819 | |
| 1820 | rc = fc_lport_ct_request(job, lport, did, rdata->e_d_tov); |
| 1821 | break; |
| 1822 | |
| 1823 | case FC_BSG_HST_ELS_NOLOGIN: |
| 1824 | did = ntoh24(job->request->rqst_data.h_els.port_id); |
| 1825 | rc = fc_lport_els_request(job, lport, did, lport->e_d_tov); |
| 1826 | break; |
| 1827 | } |
| 1828 | |
| 1829 | mutex_unlock(&lport->lp_mutex); |
| 1830 | return rc; |
| 1831 | } |
| 1832 | EXPORT_SYMBOL(fc_lport_bsg_request); |