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> |
| 97 | |
Robert Love | 8866a5d | 2009-11-03 11:45:58 -0800 | [diff] [blame] | 98 | #include "fc_libfc.h" |
| 99 | |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 100 | /* Fabric IDs to use for point-to-point mode, chosen on whims. */ |
| 101 | #define FC_LOCAL_PTP_FID_LO 0x010101 |
| 102 | #define FC_LOCAL_PTP_FID_HI 0x010102 |
| 103 | |
| 104 | #define DNS_DELAY 3 /* Discovery delay after RSCN (in seconds)*/ |
| 105 | |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 106 | static void fc_lport_error(struct fc_lport *, struct fc_frame *); |
| 107 | |
| 108 | static void fc_lport_enter_reset(struct fc_lport *); |
| 109 | static void fc_lport_enter_flogi(struct fc_lport *); |
| 110 | static void fc_lport_enter_dns(struct fc_lport *); |
Chris Leech | c914f7d | 2009-11-03 11:47:12 -0800 | [diff] [blame^] | 111 | 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] | 112 | static void fc_lport_enter_scr(struct fc_lport *); |
| 113 | static void fc_lport_enter_ready(struct fc_lport *); |
| 114 | static void fc_lport_enter_logo(struct fc_lport *); |
| 115 | |
| 116 | static const char *fc_lport_state_names[] = { |
Joe Eykholt | b1d9fd5 | 2009-07-29 17:04:22 -0700 | [diff] [blame] | 117 | [LPORT_ST_DISABLED] = "disabled", |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 118 | [LPORT_ST_FLOGI] = "FLOGI", |
| 119 | [LPORT_ST_DNS] = "dNS", |
Chris Leech | c9c7bd7 | 2009-11-03 11:46:51 -0800 | [diff] [blame] | 120 | [LPORT_ST_RNN_ID] = "RNN_ID", |
Chris Leech | 5baa17c | 2009-11-03 11:46:56 -0800 | [diff] [blame] | 121 | [LPORT_ST_RSNN_NN] = "RSNN_NN", |
Chris Leech | c9866a5 | 2009-11-03 11:47:01 -0800 | [diff] [blame] | 122 | [LPORT_ST_RSPN_ID] = "RSPN_ID", |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 123 | [LPORT_ST_RFT_ID] = "RFT_ID", |
| 124 | [LPORT_ST_SCR] = "SCR", |
| 125 | [LPORT_ST_READY] = "Ready", |
| 126 | [LPORT_ST_LOGO] = "LOGO", |
| 127 | [LPORT_ST_RESET] = "reset", |
| 128 | }; |
| 129 | |
| 130 | static int fc_frame_drop(struct fc_lport *lport, struct fc_frame *fp) |
| 131 | { |
| 132 | fc_frame_free(fp); |
| 133 | return 0; |
| 134 | } |
| 135 | |
| 136 | /** |
Robert Love | 34f42a0 | 2009-02-27 10:55:45 -0800 | [diff] [blame] | 137 | * fc_lport_rport_callback() - Event handler for rport events |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 138 | * @lport: The lport which is receiving the event |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame] | 139 | * @rdata: private remote port data |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 140 | * @event: The event that occured |
| 141 | * |
| 142 | * Locking Note: The rport lock should not be held when calling |
| 143 | * this function. |
| 144 | */ |
| 145 | static void fc_lport_rport_callback(struct fc_lport *lport, |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame] | 146 | struct fc_rport_priv *rdata, |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 147 | enum fc_rport_event event) |
| 148 | { |
Robert Love | 7414705 | 2009-06-10 15:31:10 -0700 | [diff] [blame] | 149 | 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] | 150 | rdata->ids.port_id); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 151 | |
Joe Eykholt | b5cbf08 | 2009-08-25 14:01:44 -0700 | [diff] [blame] | 152 | mutex_lock(&lport->lp_mutex); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 153 | switch (event) { |
Joe Eykholt | 4c0f62b | 2009-08-25 14:01:12 -0700 | [diff] [blame] | 154 | case RPORT_EV_READY: |
Joe Eykholt | b5cbf08 | 2009-08-25 14:01:44 -0700 | [diff] [blame] | 155 | if (lport->state == LPORT_ST_DNS) { |
| 156 | lport->dns_rp = rdata; |
Chris Leech | c914f7d | 2009-11-03 11:47:12 -0800 | [diff] [blame^] | 157 | fc_lport_enter_ns(lport, LPORT_ST_RNN_ID); |
Joe Eykholt | b5cbf08 | 2009-08-25 14:01:44 -0700 | [diff] [blame] | 158 | } else { |
| 159 | FC_LPORT_DBG(lport, "Received an READY event " |
| 160 | "on port (%6x) for the directory " |
| 161 | "server, but the lport is not " |
| 162 | "in the DNS state, it's in the " |
| 163 | "%d state", rdata->ids.port_id, |
| 164 | lport->state); |
| 165 | lport->tt.rport_logoff(rdata); |
| 166 | } |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 167 | break; |
| 168 | case RPORT_EV_LOGO: |
| 169 | case RPORT_EV_FAILED: |
| 170 | case RPORT_EV_STOP: |
Joe Eykholt | b5cbf08 | 2009-08-25 14:01:44 -0700 | [diff] [blame] | 171 | lport->dns_rp = NULL; |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 172 | break; |
| 173 | case RPORT_EV_NONE: |
| 174 | break; |
| 175 | } |
Joe Eykholt | b5cbf08 | 2009-08-25 14:01:44 -0700 | [diff] [blame] | 176 | mutex_unlock(&lport->lp_mutex); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 177 | } |
| 178 | |
| 179 | /** |
Robert Love | 34f42a0 | 2009-02-27 10:55:45 -0800 | [diff] [blame] | 180 | * fc_lport_state() - Return a string which represents the lport's state |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 181 | * @lport: The lport whose state is to converted to a string |
| 182 | */ |
| 183 | static const char *fc_lport_state(struct fc_lport *lport) |
| 184 | { |
| 185 | const char *cp; |
| 186 | |
| 187 | cp = fc_lport_state_names[lport->state]; |
| 188 | if (!cp) |
| 189 | cp = "unknown"; |
| 190 | return cp; |
| 191 | } |
| 192 | |
| 193 | /** |
Robert Love | 34f42a0 | 2009-02-27 10:55:45 -0800 | [diff] [blame] | 194 | * fc_lport_ptp_setup() - Create an rport for point-to-point mode |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 195 | * @lport: The lport to attach the ptp rport to |
| 196 | * @fid: The FID of the ptp rport |
| 197 | * @remote_wwpn: The WWPN of the ptp rport |
| 198 | * @remote_wwnn: The WWNN of the ptp rport |
| 199 | */ |
| 200 | static void fc_lport_ptp_setup(struct fc_lport *lport, |
| 201 | u32 remote_fid, u64 remote_wwpn, |
| 202 | u64 remote_wwnn) |
| 203 | { |
Joe Eykholt | 48f0090 | 2009-08-25 14:01:50 -0700 | [diff] [blame] | 204 | mutex_lock(&lport->disc.disc_mutex); |
| 205 | if (lport->ptp_rp) |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 206 | lport->tt.rport_logoff(lport->ptp_rp); |
Robert Love | 9737e6a | 2009-08-25 14:02:59 -0700 | [diff] [blame] | 207 | lport->ptp_rp = lport->tt.rport_create(lport, remote_fid); |
| 208 | lport->ptp_rp->ids.port_name = remote_wwpn; |
| 209 | lport->ptp_rp->ids.node_name = remote_wwnn; |
Joe Eykholt | 48f0090 | 2009-08-25 14:01:50 -0700 | [diff] [blame] | 210 | mutex_unlock(&lport->disc.disc_mutex); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 211 | |
| 212 | lport->tt.rport_login(lport->ptp_rp); |
| 213 | |
| 214 | fc_lport_enter_ready(lport); |
| 215 | } |
| 216 | |
| 217 | void fc_get_host_port_type(struct Scsi_Host *shost) |
| 218 | { |
| 219 | /* TODO - currently just NPORT */ |
| 220 | fc_host_port_type(shost) = FC_PORTTYPE_NPORT; |
| 221 | } |
| 222 | EXPORT_SYMBOL(fc_get_host_port_type); |
| 223 | |
| 224 | void fc_get_host_port_state(struct Scsi_Host *shost) |
| 225 | { |
| 226 | struct fc_lport *lp = shost_priv(shost); |
| 227 | |
Chris Leech | 8faecdd | 2009-11-03 11:46:19 -0800 | [diff] [blame] | 228 | mutex_lock(&lp->lp_mutex); |
| 229 | if (!lp->link_up) |
| 230 | fc_host_port_state(shost) = FC_PORTSTATE_LINKDOWN; |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 231 | else |
Chris Leech | 8faecdd | 2009-11-03 11:46:19 -0800 | [diff] [blame] | 232 | switch (lp->state) { |
| 233 | case LPORT_ST_READY: |
| 234 | fc_host_port_state(shost) = FC_PORTSTATE_ONLINE; |
| 235 | break; |
| 236 | default: |
| 237 | fc_host_port_state(shost) = FC_PORTSTATE_OFFLINE; |
| 238 | } |
| 239 | mutex_unlock(&lp->lp_mutex); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 240 | } |
| 241 | EXPORT_SYMBOL(fc_get_host_port_state); |
| 242 | |
| 243 | void fc_get_host_speed(struct Scsi_Host *shost) |
| 244 | { |
| 245 | struct fc_lport *lport = shost_priv(shost); |
| 246 | |
| 247 | fc_host_speed(shost) = lport->link_speed; |
| 248 | } |
| 249 | EXPORT_SYMBOL(fc_get_host_speed); |
| 250 | |
| 251 | struct fc_host_statistics *fc_get_host_stats(struct Scsi_Host *shost) |
| 252 | { |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 253 | struct fc_host_statistics *fcoe_stats; |
| 254 | struct fc_lport *lp = shost_priv(shost); |
| 255 | struct timespec v0, v1; |
Robert Love | 582b45b | 2009-03-31 15:51:50 -0700 | [diff] [blame] | 256 | unsigned int cpu; |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 257 | |
| 258 | fcoe_stats = &lp->host_stats; |
| 259 | memset(fcoe_stats, 0, sizeof(struct fc_host_statistics)); |
| 260 | |
| 261 | jiffies_to_timespec(jiffies, &v0); |
| 262 | jiffies_to_timespec(lp->boot_time, &v1); |
| 263 | fcoe_stats->seconds_since_last_reset = (v0.tv_sec - v1.tv_sec); |
| 264 | |
Robert Love | 582b45b | 2009-03-31 15:51:50 -0700 | [diff] [blame] | 265 | for_each_possible_cpu(cpu) { |
| 266 | struct fcoe_dev_stats *stats; |
| 267 | |
| 268 | stats = per_cpu_ptr(lp->dev_stats, cpu); |
| 269 | |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 270 | fcoe_stats->tx_frames += stats->TxFrames; |
| 271 | fcoe_stats->tx_words += stats->TxWords; |
| 272 | fcoe_stats->rx_frames += stats->RxFrames; |
| 273 | fcoe_stats->rx_words += stats->RxWords; |
| 274 | fcoe_stats->error_frames += stats->ErrorFrames; |
| 275 | fcoe_stats->invalid_crc_count += stats->InvalidCRCCount; |
| 276 | fcoe_stats->fcp_input_requests += stats->InputRequests; |
| 277 | fcoe_stats->fcp_output_requests += stats->OutputRequests; |
| 278 | fcoe_stats->fcp_control_requests += stats->ControlRequests; |
| 279 | fcoe_stats->fcp_input_megabytes += stats->InputMegabytes; |
| 280 | fcoe_stats->fcp_output_megabytes += stats->OutputMegabytes; |
| 281 | fcoe_stats->link_failure_count += stats->LinkFailureCount; |
| 282 | } |
| 283 | fcoe_stats->lip_count = -1; |
| 284 | fcoe_stats->nos_count = -1; |
| 285 | fcoe_stats->loss_of_sync_count = -1; |
| 286 | fcoe_stats->loss_of_signal_count = -1; |
| 287 | fcoe_stats->prim_seq_protocol_err_count = -1; |
| 288 | fcoe_stats->dumped_frames = -1; |
| 289 | return fcoe_stats; |
| 290 | } |
| 291 | EXPORT_SYMBOL(fc_get_host_stats); |
| 292 | |
| 293 | /* |
| 294 | * Fill in FLOGI command for request. |
| 295 | */ |
| 296 | static void |
| 297 | fc_lport_flogi_fill(struct fc_lport *lport, struct fc_els_flogi *flogi, |
| 298 | unsigned int op) |
| 299 | { |
| 300 | struct fc_els_csp *sp; |
| 301 | struct fc_els_cssp *cp; |
| 302 | |
| 303 | memset(flogi, 0, sizeof(*flogi)); |
| 304 | flogi->fl_cmd = (u8) op; |
| 305 | put_unaligned_be64(lport->wwpn, &flogi->fl_wwpn); |
| 306 | put_unaligned_be64(lport->wwnn, &flogi->fl_wwnn); |
| 307 | sp = &flogi->fl_csp; |
| 308 | sp->sp_hi_ver = 0x20; |
| 309 | sp->sp_lo_ver = 0x20; |
| 310 | sp->sp_bb_cred = htons(10); /* this gets set by gateway */ |
| 311 | sp->sp_bb_data = htons((u16) lport->mfs); |
| 312 | cp = &flogi->fl_cssp[3 - 1]; /* class 3 parameters */ |
| 313 | cp->cp_class = htons(FC_CPC_VALID | FC_CPC_SEQ); |
| 314 | if (op != ELS_FLOGI) { |
| 315 | sp->sp_features = htons(FC_SP_FT_CIRO); |
| 316 | sp->sp_tot_seq = htons(255); /* seq. we accept */ |
| 317 | sp->sp_rel_off = htons(0x1f); |
| 318 | sp->sp_e_d_tov = htonl(lport->e_d_tov); |
| 319 | |
| 320 | cp->cp_rdfs = htons((u16) lport->mfs); |
| 321 | cp->cp_con_seq = htons(255); |
| 322 | cp->cp_open_seq = 1; |
| 323 | } |
| 324 | } |
| 325 | |
| 326 | /* |
| 327 | * Add a supported FC-4 type. |
| 328 | */ |
| 329 | static void fc_lport_add_fc4_type(struct fc_lport *lport, enum fc_fh_type type) |
| 330 | { |
| 331 | __be32 *mp; |
| 332 | |
| 333 | mp = &lport->fcts.ff_type_map[type / FC_NS_BPW]; |
| 334 | *mp = htonl(ntohl(*mp) | 1UL << (type % FC_NS_BPW)); |
| 335 | } |
| 336 | |
| 337 | /** |
Robert Love | 34f42a0 | 2009-02-27 10:55:45 -0800 | [diff] [blame] | 338 | * fc_lport_recv_rlir_req() - Handle received Registered Link Incident Report. |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 339 | * @lport: Fibre Channel local port recieving the RLIR |
| 340 | * @sp: current sequence in the RLIR exchange |
| 341 | * @fp: RLIR request frame |
| 342 | * |
Joe Eykholt | 1b69bc0 | 2009-10-21 16:27:17 -0700 | [diff] [blame] | 343 | * Locking Note: The lport lock is expected to be held before calling |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 344 | * this function. |
| 345 | */ |
| 346 | static void fc_lport_recv_rlir_req(struct fc_seq *sp, struct fc_frame *fp, |
| 347 | struct fc_lport *lport) |
| 348 | { |
Robert Love | 7414705 | 2009-06-10 15:31:10 -0700 | [diff] [blame] | 349 | FC_LPORT_DBG(lport, "Received RLIR request while in state %s\n", |
| 350 | fc_lport_state(lport)); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 351 | |
| 352 | lport->tt.seq_els_rsp_send(sp, ELS_LS_ACC, NULL); |
| 353 | fc_frame_free(fp); |
| 354 | } |
| 355 | |
| 356 | /** |
Robert Love | 34f42a0 | 2009-02-27 10:55:45 -0800 | [diff] [blame] | 357 | * fc_lport_recv_echo_req() - Handle received ECHO request |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 358 | * @lport: Fibre Channel local port recieving the ECHO |
| 359 | * @sp: current sequence in the ECHO exchange |
| 360 | * @fp: ECHO request frame |
| 361 | * |
Joe Eykholt | 1b69bc0 | 2009-10-21 16:27:17 -0700 | [diff] [blame] | 362 | * Locking Note: The lport lock is expected to be held before calling |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 363 | * this function. |
| 364 | */ |
| 365 | static void fc_lport_recv_echo_req(struct fc_seq *sp, struct fc_frame *in_fp, |
| 366 | struct fc_lport *lport) |
| 367 | { |
| 368 | struct fc_frame *fp; |
| 369 | struct fc_exch *ep = fc_seq_exch(sp); |
| 370 | unsigned int len; |
| 371 | void *pp; |
| 372 | void *dp; |
| 373 | u32 f_ctl; |
| 374 | |
Joe Eykholt | 1b69bc0 | 2009-10-21 16:27:17 -0700 | [diff] [blame] | 375 | FC_LPORT_DBG(lport, "Received ECHO request while in state %s\n", |
Robert Love | 7414705 | 2009-06-10 15:31:10 -0700 | [diff] [blame] | 376 | fc_lport_state(lport)); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 377 | |
| 378 | len = fr_len(in_fp) - sizeof(struct fc_frame_header); |
| 379 | pp = fc_frame_payload_get(in_fp, len); |
| 380 | |
| 381 | if (len < sizeof(__be32)) |
| 382 | len = sizeof(__be32); |
| 383 | |
| 384 | fp = fc_frame_alloc(lport, len); |
| 385 | if (fp) { |
| 386 | dp = fc_frame_payload_get(fp, len); |
| 387 | memcpy(dp, pp, len); |
Joe Eykholt | 1b69bc0 | 2009-10-21 16:27:17 -0700 | [diff] [blame] | 388 | *((__be32 *)dp) = htonl(ELS_LS_ACC << 24); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 389 | sp = lport->tt.seq_start_next(sp); |
| 390 | f_ctl = FC_FC_EX_CTX | FC_FC_LAST_SEQ | FC_FC_END_SEQ; |
| 391 | fc_fill_fc_hdr(fp, FC_RCTL_ELS_REP, ep->did, ep->sid, |
| 392 | FC_TYPE_ELS, f_ctl, 0); |
| 393 | lport->tt.seq_send(lport, sp, fp); |
| 394 | } |
| 395 | fc_frame_free(in_fp); |
| 396 | } |
| 397 | |
| 398 | /** |
Joe Eykholt | 1b69bc0 | 2009-10-21 16:27:17 -0700 | [diff] [blame] | 399 | * fc_lport_recv_rnid_req() - Handle received Request Node ID data request |
| 400 | * @sp: The sequence in the RNID exchange |
| 401 | * @fp: The RNID request frame |
| 402 | * @lport: The local port recieving the RNID |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 403 | * |
Joe Eykholt | 1b69bc0 | 2009-10-21 16:27:17 -0700 | [diff] [blame] | 404 | * Locking Note: The lport lock is expected to be held before calling |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 405 | * this function. |
| 406 | */ |
| 407 | static void fc_lport_recv_rnid_req(struct fc_seq *sp, struct fc_frame *in_fp, |
| 408 | struct fc_lport *lport) |
| 409 | { |
| 410 | struct fc_frame *fp; |
| 411 | struct fc_exch *ep = fc_seq_exch(sp); |
| 412 | struct fc_els_rnid *req; |
| 413 | struct { |
| 414 | struct fc_els_rnid_resp rnid; |
| 415 | struct fc_els_rnid_cid cid; |
| 416 | struct fc_els_rnid_gen gen; |
| 417 | } *rp; |
| 418 | struct fc_seq_els_data rjt_data; |
| 419 | u8 fmt; |
| 420 | size_t len; |
| 421 | u32 f_ctl; |
| 422 | |
Robert Love | 7414705 | 2009-06-10 15:31:10 -0700 | [diff] [blame] | 423 | FC_LPORT_DBG(lport, "Received RNID request while in state %s\n", |
| 424 | fc_lport_state(lport)); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 425 | |
| 426 | req = fc_frame_payload_get(in_fp, sizeof(*req)); |
| 427 | if (!req) { |
| 428 | rjt_data.fp = NULL; |
| 429 | rjt_data.reason = ELS_RJT_LOGIC; |
| 430 | rjt_data.explan = ELS_EXPL_NONE; |
| 431 | lport->tt.seq_els_rsp_send(sp, ELS_LS_RJT, &rjt_data); |
| 432 | } else { |
| 433 | fmt = req->rnid_fmt; |
| 434 | len = sizeof(*rp); |
| 435 | if (fmt != ELS_RNIDF_GEN || |
| 436 | ntohl(lport->rnid_gen.rnid_atype) == 0) { |
| 437 | fmt = ELS_RNIDF_NONE; /* nothing to provide */ |
| 438 | len -= sizeof(rp->gen); |
| 439 | } |
| 440 | fp = fc_frame_alloc(lport, len); |
| 441 | if (fp) { |
| 442 | rp = fc_frame_payload_get(fp, len); |
| 443 | memset(rp, 0, len); |
| 444 | rp->rnid.rnid_cmd = ELS_LS_ACC; |
| 445 | rp->rnid.rnid_fmt = fmt; |
| 446 | rp->rnid.rnid_cid_len = sizeof(rp->cid); |
| 447 | rp->cid.rnid_wwpn = htonll(lport->wwpn); |
| 448 | rp->cid.rnid_wwnn = htonll(lport->wwnn); |
| 449 | if (fmt == ELS_RNIDF_GEN) { |
| 450 | rp->rnid.rnid_sid_len = sizeof(rp->gen); |
| 451 | memcpy(&rp->gen, &lport->rnid_gen, |
| 452 | sizeof(rp->gen)); |
| 453 | } |
| 454 | sp = lport->tt.seq_start_next(sp); |
| 455 | f_ctl = FC_FC_EX_CTX | FC_FC_LAST_SEQ; |
| 456 | f_ctl |= FC_FC_END_SEQ | FC_FC_SEQ_INIT; |
| 457 | fc_fill_fc_hdr(fp, FC_RCTL_ELS_REP, ep->did, ep->sid, |
| 458 | FC_TYPE_ELS, f_ctl, 0); |
| 459 | lport->tt.seq_send(lport, sp, fp); |
| 460 | } |
| 461 | } |
| 462 | fc_frame_free(in_fp); |
| 463 | } |
| 464 | |
| 465 | /** |
Robert Love | 34f42a0 | 2009-02-27 10:55:45 -0800 | [diff] [blame] | 466 | * fc_lport_recv_logo_req() - Handle received fabric LOGO request |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 467 | * @lport: Fibre Channel local port recieving the LOGO |
| 468 | * @sp: current sequence in the LOGO exchange |
| 469 | * @fp: LOGO request frame |
| 470 | * |
| 471 | * Locking Note: The lport lock is exected to be held before calling |
| 472 | * this function. |
| 473 | */ |
| 474 | static void fc_lport_recv_logo_req(struct fc_seq *sp, struct fc_frame *fp, |
| 475 | struct fc_lport *lport) |
| 476 | { |
| 477 | lport->tt.seq_els_rsp_send(sp, ELS_LS_ACC, NULL); |
| 478 | fc_lport_enter_reset(lport); |
| 479 | fc_frame_free(fp); |
| 480 | } |
| 481 | |
| 482 | /** |
Robert Love | 34f42a0 | 2009-02-27 10:55:45 -0800 | [diff] [blame] | 483 | * fc_fabric_login() - Start the lport state machine |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 484 | * @lport: The lport that should log into the fabric |
| 485 | * |
| 486 | * Locking Note: This function should not be called |
| 487 | * with the lport lock held. |
| 488 | */ |
| 489 | int fc_fabric_login(struct fc_lport *lport) |
| 490 | { |
| 491 | int rc = -1; |
| 492 | |
| 493 | mutex_lock(&lport->lp_mutex); |
Joe Eykholt | b1d9fd5 | 2009-07-29 17:04:22 -0700 | [diff] [blame] | 494 | if (lport->state == LPORT_ST_DISABLED) { |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 495 | fc_lport_enter_reset(lport); |
| 496 | rc = 0; |
| 497 | } |
| 498 | mutex_unlock(&lport->lp_mutex); |
| 499 | |
| 500 | return rc; |
| 501 | } |
| 502 | EXPORT_SYMBOL(fc_fabric_login); |
| 503 | |
| 504 | /** |
Chris Leech | 8faecdd | 2009-11-03 11:46:19 -0800 | [diff] [blame] | 505 | * __fc_linkup() - Handler for transport linkup events |
| 506 | * @lport: The lport whose link is up |
| 507 | * |
| 508 | * Locking: must be called with the lp_mutex held |
| 509 | */ |
| 510 | void __fc_linkup(struct fc_lport *lport) |
| 511 | { |
| 512 | if (!lport->link_up) { |
| 513 | lport->link_up = 1; |
| 514 | |
| 515 | if (lport->state == LPORT_ST_RESET) |
| 516 | fc_lport_enter_flogi(lport); |
| 517 | } |
| 518 | } |
| 519 | |
| 520 | /** |
Robert Love | 34f42a0 | 2009-02-27 10:55:45 -0800 | [diff] [blame] | 521 | * fc_linkup() - Handler for transport linkup events |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 522 | * @lport: The lport whose link is up |
| 523 | */ |
| 524 | void fc_linkup(struct fc_lport *lport) |
| 525 | { |
Robert Love | 7414705 | 2009-06-10 15:31:10 -0700 | [diff] [blame] | 526 | printk(KERN_INFO "libfc: Link up on port (%6x)\n", |
| 527 | fc_host_port_id(lport->host)); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 528 | |
| 529 | mutex_lock(&lport->lp_mutex); |
Chris Leech | 8faecdd | 2009-11-03 11:46:19 -0800 | [diff] [blame] | 530 | __fc_linkup(lport); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 531 | mutex_unlock(&lport->lp_mutex); |
| 532 | } |
| 533 | EXPORT_SYMBOL(fc_linkup); |
| 534 | |
| 535 | /** |
Chris Leech | 8faecdd | 2009-11-03 11:46:19 -0800 | [diff] [blame] | 536 | * __fc_linkdown() - Handler for transport linkdown events |
| 537 | * @lport: The lport whose link is down |
| 538 | * |
| 539 | * Locking: must be called with the lp_mutex held |
| 540 | */ |
| 541 | void __fc_linkdown(struct fc_lport *lport) |
| 542 | { |
| 543 | if (lport->link_up) { |
| 544 | lport->link_up = 0; |
| 545 | fc_lport_enter_reset(lport); |
| 546 | lport->tt.fcp_cleanup(lport); |
| 547 | } |
| 548 | } |
| 549 | |
| 550 | /** |
Robert Love | 34f42a0 | 2009-02-27 10:55:45 -0800 | [diff] [blame] | 551 | * fc_linkdown() - Handler for transport linkdown events |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 552 | * @lport: The lport whose link is down |
| 553 | */ |
| 554 | void fc_linkdown(struct fc_lport *lport) |
| 555 | { |
Robert Love | 7414705 | 2009-06-10 15:31:10 -0700 | [diff] [blame] | 556 | printk(KERN_INFO "libfc: Link down on port (%6x)\n", |
| 557 | fc_host_port_id(lport->host)); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 558 | |
Chris Leech | 8faecdd | 2009-11-03 11:46:19 -0800 | [diff] [blame] | 559 | mutex_lock(&lport->lp_mutex); |
| 560 | __fc_linkdown(lport); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 561 | mutex_unlock(&lport->lp_mutex); |
| 562 | } |
| 563 | EXPORT_SYMBOL(fc_linkdown); |
| 564 | |
| 565 | /** |
Robert Love | 34f42a0 | 2009-02-27 10:55:45 -0800 | [diff] [blame] | 566 | * fc_fabric_logoff() - Logout of the fabric |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 567 | * @lport: fc_lport pointer to logoff the fabric |
| 568 | * |
| 569 | * Return value: |
| 570 | * 0 for success, -1 for failure |
Robert Love | 34f42a0 | 2009-02-27 10:55:45 -0800 | [diff] [blame] | 571 | */ |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 572 | int fc_fabric_logoff(struct fc_lport *lport) |
| 573 | { |
| 574 | lport->tt.disc_stop_final(lport); |
| 575 | mutex_lock(&lport->lp_mutex); |
Abhijeet Joglekar | a0fd2e4 | 2009-04-21 16:27:09 -0700 | [diff] [blame] | 576 | if (lport->dns_rp) |
| 577 | lport->tt.rport_logoff(lport->dns_rp); |
| 578 | mutex_unlock(&lport->lp_mutex); |
| 579 | lport->tt.rport_flush_queue(); |
| 580 | mutex_lock(&lport->lp_mutex); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 581 | fc_lport_enter_logo(lport); |
| 582 | mutex_unlock(&lport->lp_mutex); |
Steve Ma | f7db2c15 | 2009-02-27 10:55:13 -0800 | [diff] [blame] | 583 | cancel_delayed_work_sync(&lport->retry_work); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 584 | return 0; |
| 585 | } |
| 586 | EXPORT_SYMBOL(fc_fabric_logoff); |
| 587 | |
| 588 | /** |
Robert Love | 34f42a0 | 2009-02-27 10:55:45 -0800 | [diff] [blame] | 589 | * fc_lport_destroy() - unregister a fc_lport |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 590 | * @lport: fc_lport pointer to unregister |
| 591 | * |
| 592 | * Return value: |
| 593 | * None |
| 594 | * Note: |
| 595 | * exit routine for fc_lport instance |
| 596 | * clean-up all the allocated memory |
| 597 | * and free up other system resources. |
| 598 | * |
Robert Love | 34f42a0 | 2009-02-27 10:55:45 -0800 | [diff] [blame] | 599 | */ |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 600 | int fc_lport_destroy(struct fc_lport *lport) |
| 601 | { |
Abhijeet Joglekar | bbf1566 | 2009-04-21 16:27:14 -0700 | [diff] [blame] | 602 | mutex_lock(&lport->lp_mutex); |
Joe Eykholt | b1d9fd5 | 2009-07-29 17:04:22 -0700 | [diff] [blame] | 603 | lport->state = LPORT_ST_DISABLED; |
Abhijeet Joglekar | bbf1566 | 2009-04-21 16:27:14 -0700 | [diff] [blame] | 604 | lport->link_up = 0; |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 605 | lport->tt.frame_send = fc_frame_drop; |
Abhijeet Joglekar | bbf1566 | 2009-04-21 16:27:14 -0700 | [diff] [blame] | 606 | mutex_unlock(&lport->lp_mutex); |
| 607 | |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 608 | lport->tt.fcp_abort_io(lport); |
Joe Eykholt | e9ba8b4 | 2009-07-29 17:04:33 -0700 | [diff] [blame] | 609 | lport->tt.disc_stop_final(lport); |
Abhijeet Joglekar | 1f6ff36 | 2009-02-27 10:54:35 -0800 | [diff] [blame] | 610 | lport->tt.exch_mgr_reset(lport, 0, 0); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 611 | return 0; |
| 612 | } |
| 613 | EXPORT_SYMBOL(fc_lport_destroy); |
| 614 | |
| 615 | /** |
Robert Love | 34f42a0 | 2009-02-27 10:55:45 -0800 | [diff] [blame] | 616 | * fc_set_mfs() - sets up the mfs for the corresponding fc_lport |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 617 | * @lport: fc_lport pointer to unregister |
| 618 | * @mfs: the new mfs for fc_lport |
| 619 | * |
| 620 | * Set mfs for the given fc_lport to the new mfs. |
| 621 | * |
| 622 | * Return: 0 for success |
Robert Love | 34f42a0 | 2009-02-27 10:55:45 -0800 | [diff] [blame] | 623 | */ |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 624 | int fc_set_mfs(struct fc_lport *lport, u32 mfs) |
| 625 | { |
| 626 | unsigned int old_mfs; |
| 627 | int rc = -EINVAL; |
| 628 | |
| 629 | mutex_lock(&lport->lp_mutex); |
| 630 | |
| 631 | old_mfs = lport->mfs; |
| 632 | |
| 633 | if (mfs >= FC_MIN_MAX_FRAME) { |
| 634 | mfs &= ~3; |
| 635 | if (mfs > FC_MAX_FRAME) |
| 636 | mfs = FC_MAX_FRAME; |
| 637 | mfs -= sizeof(struct fc_frame_header); |
| 638 | lport->mfs = mfs; |
| 639 | rc = 0; |
| 640 | } |
| 641 | |
| 642 | if (!rc && mfs < old_mfs) |
| 643 | fc_lport_enter_reset(lport); |
| 644 | |
| 645 | mutex_unlock(&lport->lp_mutex); |
| 646 | |
| 647 | return rc; |
| 648 | } |
| 649 | EXPORT_SYMBOL(fc_set_mfs); |
| 650 | |
| 651 | /** |
Robert Love | 34f42a0 | 2009-02-27 10:55:45 -0800 | [diff] [blame] | 652 | * fc_lport_disc_callback() - Callback for discovery events |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 653 | * @lport: FC local port |
| 654 | * @event: The discovery event |
| 655 | */ |
| 656 | void fc_lport_disc_callback(struct fc_lport *lport, enum fc_disc_event event) |
| 657 | { |
| 658 | switch (event) { |
| 659 | case DISC_EV_SUCCESS: |
Robert Love | 7414705 | 2009-06-10 15:31:10 -0700 | [diff] [blame] | 660 | FC_LPORT_DBG(lport, "Discovery succeeded\n"); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 661 | break; |
| 662 | case DISC_EV_FAILED: |
Robert Love | 7414705 | 2009-06-10 15:31:10 -0700 | [diff] [blame] | 663 | printk(KERN_ERR "libfc: Discovery failed for port (%6x)\n", |
| 664 | fc_host_port_id(lport->host)); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 665 | mutex_lock(&lport->lp_mutex); |
| 666 | fc_lport_enter_reset(lport); |
| 667 | mutex_unlock(&lport->lp_mutex); |
| 668 | break; |
| 669 | case DISC_EV_NONE: |
| 670 | WARN_ON(1); |
| 671 | break; |
| 672 | } |
| 673 | } |
| 674 | |
| 675 | /** |
Robert Love | 34f42a0 | 2009-02-27 10:55:45 -0800 | [diff] [blame] | 676 | * fc_rport_enter_ready() - Enter the ready state and start discovery |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 677 | * @lport: Fibre Channel local port that is ready |
| 678 | * |
| 679 | * Locking Note: The lport lock is expected to be held before calling |
| 680 | * this routine. |
| 681 | */ |
| 682 | static void fc_lport_enter_ready(struct fc_lport *lport) |
| 683 | { |
Robert Love | 7414705 | 2009-06-10 15:31:10 -0700 | [diff] [blame] | 684 | FC_LPORT_DBG(lport, "Entered READY from state %s\n", |
| 685 | fc_lport_state(lport)); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 686 | |
| 687 | fc_lport_state_enter(lport, LPORT_ST_READY); |
Chris Leech | 8faecdd | 2009-11-03 11:46:19 -0800 | [diff] [blame] | 688 | if (lport->vport) |
| 689 | fc_vport_set_state(lport->vport, FC_VPORT_ACTIVE); |
| 690 | fc_vports_linkchange(lport); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 691 | |
Joe Eykholt | 29d898e | 2009-08-25 14:02:49 -0700 | [diff] [blame] | 692 | if (!lport->ptp_rp) |
| 693 | lport->tt.disc_start(fc_lport_disc_callback, lport); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 694 | } |
| 695 | |
| 696 | /** |
Robert Love | 34f42a0 | 2009-02-27 10:55:45 -0800 | [diff] [blame] | 697 | * fc_lport_recv_flogi_req() - Receive a FLOGI request |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 698 | * @sp_in: The sequence the FLOGI is on |
| 699 | * @rx_fp: The frame the FLOGI is in |
| 700 | * @lport: The lport that recieved the request |
| 701 | * |
| 702 | * A received FLOGI request indicates a point-to-point connection. |
| 703 | * Accept it with the common service parameters indicating our N port. |
| 704 | * Set up to do a PLOGI if we have the higher-number WWPN. |
| 705 | * |
Joe Eykholt | 1b69bc0 | 2009-10-21 16:27:17 -0700 | [diff] [blame] | 706 | * Locking Note: The lport lock is expected to be held before calling |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 707 | * this function. |
| 708 | */ |
| 709 | static void fc_lport_recv_flogi_req(struct fc_seq *sp_in, |
| 710 | struct fc_frame *rx_fp, |
| 711 | struct fc_lport *lport) |
| 712 | { |
| 713 | struct fc_frame *fp; |
| 714 | struct fc_frame_header *fh; |
| 715 | struct fc_seq *sp; |
| 716 | struct fc_exch *ep; |
| 717 | struct fc_els_flogi *flp; |
| 718 | struct fc_els_flogi *new_flp; |
| 719 | u64 remote_wwpn; |
| 720 | u32 remote_fid; |
| 721 | u32 local_fid; |
| 722 | u32 f_ctl; |
| 723 | |
Robert Love | 7414705 | 2009-06-10 15:31:10 -0700 | [diff] [blame] | 724 | FC_LPORT_DBG(lport, "Received FLOGI request while in state %s\n", |
| 725 | fc_lport_state(lport)); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 726 | |
| 727 | fh = fc_frame_header_get(rx_fp); |
| 728 | remote_fid = ntoh24(fh->fh_s_id); |
| 729 | flp = fc_frame_payload_get(rx_fp, sizeof(*flp)); |
| 730 | if (!flp) |
| 731 | goto out; |
| 732 | remote_wwpn = get_unaligned_be64(&flp->fl_wwpn); |
| 733 | if (remote_wwpn == lport->wwpn) { |
Robert Love | 7414705 | 2009-06-10 15:31:10 -0700 | [diff] [blame] | 734 | printk(KERN_WARNING "libfc: Received FLOGI from port " |
| 735 | "with same WWPN %llx\n", remote_wwpn); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 736 | goto out; |
| 737 | } |
Robert Love | 7414705 | 2009-06-10 15:31:10 -0700 | [diff] [blame] | 738 | FC_LPORT_DBG(lport, "FLOGI from port WWPN %llx\n", remote_wwpn); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 739 | |
| 740 | /* |
| 741 | * XXX what is the right thing to do for FIDs? |
| 742 | * The originator might expect our S_ID to be 0xfffffe. |
| 743 | * But if so, both of us could end up with the same FID. |
| 744 | */ |
| 745 | local_fid = FC_LOCAL_PTP_FID_LO; |
| 746 | if (remote_wwpn < lport->wwpn) { |
| 747 | local_fid = FC_LOCAL_PTP_FID_HI; |
| 748 | if (!remote_fid || remote_fid == local_fid) |
| 749 | remote_fid = FC_LOCAL_PTP_FID_LO; |
| 750 | } else if (!remote_fid) { |
| 751 | remote_fid = FC_LOCAL_PTP_FID_HI; |
| 752 | } |
| 753 | |
| 754 | fc_host_port_id(lport->host) = local_fid; |
| 755 | |
| 756 | fp = fc_frame_alloc(lport, sizeof(*flp)); |
| 757 | if (fp) { |
| 758 | sp = lport->tt.seq_start_next(fr_seq(rx_fp)); |
| 759 | new_flp = fc_frame_payload_get(fp, sizeof(*flp)); |
| 760 | fc_lport_flogi_fill(lport, new_flp, ELS_FLOGI); |
| 761 | new_flp->fl_cmd = (u8) ELS_LS_ACC; |
| 762 | |
| 763 | /* |
| 764 | * Send the response. If this fails, the originator should |
| 765 | * repeat the sequence. |
| 766 | */ |
| 767 | f_ctl = FC_FC_EX_CTX | FC_FC_LAST_SEQ | FC_FC_END_SEQ; |
| 768 | ep = fc_seq_exch(sp); |
| 769 | fc_fill_fc_hdr(fp, FC_RCTL_ELS_REP, ep->did, ep->sid, |
| 770 | FC_TYPE_ELS, f_ctl, 0); |
| 771 | lport->tt.seq_send(lport, sp, fp); |
| 772 | |
| 773 | } else { |
| 774 | fc_lport_error(lport, fp); |
| 775 | } |
| 776 | fc_lport_ptp_setup(lport, remote_fid, remote_wwpn, |
| 777 | get_unaligned_be64(&flp->fl_wwnn)); |
| 778 | |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 779 | out: |
| 780 | sp = fr_seq(rx_fp); |
| 781 | fc_frame_free(rx_fp); |
| 782 | } |
| 783 | |
| 784 | /** |
Robert Love | 34f42a0 | 2009-02-27 10:55:45 -0800 | [diff] [blame] | 785 | * fc_lport_recv_req() - The generic lport request handler |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 786 | * @lport: The lport that received the request |
| 787 | * @sp: The sequence the request is on |
| 788 | * @fp: The frame the request is in |
| 789 | * |
| 790 | * This function will see if the lport handles the request or |
| 791 | * if an rport should handle the request. |
| 792 | * |
| 793 | * Locking Note: This function should not be called with the lport |
| 794 | * lock held becuase it will grab the lock. |
| 795 | */ |
| 796 | static void fc_lport_recv_req(struct fc_lport *lport, struct fc_seq *sp, |
| 797 | struct fc_frame *fp) |
| 798 | { |
| 799 | struct fc_frame_header *fh = fc_frame_header_get(fp); |
| 800 | void (*recv) (struct fc_seq *, struct fc_frame *, struct fc_lport *); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 801 | |
| 802 | mutex_lock(&lport->lp_mutex); |
| 803 | |
| 804 | /* |
| 805 | * Handle special ELS cases like FLOGI, LOGO, and |
| 806 | * RSCN here. These don't require a session. |
| 807 | * Even if we had a session, it might not be ready. |
| 808 | */ |
Joe Eykholt | e9ba8b4 | 2009-07-29 17:04:33 -0700 | [diff] [blame] | 809 | if (!lport->link_up) |
| 810 | fc_frame_free(fp); |
| 811 | else if (fh->fh_type == FC_TYPE_ELS && |
| 812 | fh->fh_r_ctl == FC_RCTL_ELS_REQ) { |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 813 | /* |
| 814 | * Check opcode. |
| 815 | */ |
Joe Eykholt | 131203a | 2009-08-25 14:03:10 -0700 | [diff] [blame] | 816 | recv = lport->tt.rport_recv_req; |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 817 | switch (fc_frame_payload_op(fp)) { |
| 818 | case ELS_FLOGI: |
| 819 | recv = fc_lport_recv_flogi_req; |
| 820 | break; |
| 821 | case ELS_LOGO: |
| 822 | fh = fc_frame_header_get(fp); |
| 823 | if (ntoh24(fh->fh_s_id) == FC_FID_FLOGI) |
| 824 | recv = fc_lport_recv_logo_req; |
| 825 | break; |
| 826 | case ELS_RSCN: |
| 827 | recv = lport->tt.disc_recv_req; |
| 828 | break; |
| 829 | case ELS_ECHO: |
| 830 | recv = fc_lport_recv_echo_req; |
| 831 | break; |
| 832 | case ELS_RLIR: |
| 833 | recv = fc_lport_recv_rlir_req; |
| 834 | break; |
| 835 | case ELS_RNID: |
| 836 | recv = fc_lport_recv_rnid_req; |
| 837 | break; |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 838 | } |
| 839 | |
Joe Eykholt | 131203a | 2009-08-25 14:03:10 -0700 | [diff] [blame] | 840 | recv(sp, fp, lport); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 841 | } else { |
Robert Love | 7414705 | 2009-06-10 15:31:10 -0700 | [diff] [blame] | 842 | FC_LPORT_DBG(lport, "dropping invalid frame (eof %x)\n", |
| 843 | fr_eof(fp)); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 844 | fc_frame_free(fp); |
| 845 | } |
| 846 | mutex_unlock(&lport->lp_mutex); |
| 847 | |
| 848 | /* |
| 849 | * The common exch_done for all request may not be good |
| 850 | * if any request requires longer hold on exhange. XXX |
| 851 | */ |
| 852 | lport->tt.exch_done(sp); |
| 853 | } |
| 854 | |
| 855 | /** |
Robert Love | 34f42a0 | 2009-02-27 10:55:45 -0800 | [diff] [blame] | 856 | * fc_lport_reset() - Reset an lport |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 857 | * @lport: The lport which should be reset |
| 858 | * |
| 859 | * Locking Note: This functions should not be called with the |
| 860 | * lport lock held. |
| 861 | */ |
| 862 | int fc_lport_reset(struct fc_lport *lport) |
| 863 | { |
Steve Ma | f7db2c15 | 2009-02-27 10:55:13 -0800 | [diff] [blame] | 864 | cancel_delayed_work_sync(&lport->retry_work); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 865 | mutex_lock(&lport->lp_mutex); |
| 866 | fc_lport_enter_reset(lport); |
| 867 | mutex_unlock(&lport->lp_mutex); |
| 868 | return 0; |
| 869 | } |
| 870 | EXPORT_SYMBOL(fc_lport_reset); |
| 871 | |
| 872 | /** |
Joe Eykholt | 1190d92 | 2009-07-29 17:04:27 -0700 | [diff] [blame] | 873 | * fc_lport_reset_locked() - Reset the local port |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 874 | * @lport: Fibre Channel local port to be reset |
| 875 | * |
| 876 | * Locking Note: The lport lock is expected to be held before calling |
| 877 | * this routine. |
| 878 | */ |
Joe Eykholt | 1190d92 | 2009-07-29 17:04:27 -0700 | [diff] [blame] | 879 | static void fc_lport_reset_locked(struct fc_lport *lport) |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 880 | { |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 881 | if (lport->dns_rp) |
| 882 | lport->tt.rport_logoff(lport->dns_rp); |
| 883 | |
Joe Eykholt | 48f0090 | 2009-08-25 14:01:50 -0700 | [diff] [blame] | 884 | lport->ptp_rp = NULL; |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 885 | |
| 886 | lport->tt.disc_stop(lport); |
| 887 | |
Abhijeet Joglekar | 1f6ff36 | 2009-02-27 10:54:35 -0800 | [diff] [blame] | 888 | lport->tt.exch_mgr_reset(lport, 0, 0); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 889 | fc_host_fabric_name(lport->host) = 0; |
| 890 | fc_host_port_id(lport->host) = 0; |
Joe Eykholt | 1190d92 | 2009-07-29 17:04:27 -0700 | [diff] [blame] | 891 | } |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 892 | |
Joe Eykholt | 1190d92 | 2009-07-29 17:04:27 -0700 | [diff] [blame] | 893 | /** |
| 894 | * fc_lport_enter_reset() - Reset the local port |
| 895 | * @lport: Fibre Channel local port to be reset |
| 896 | * |
| 897 | * Locking Note: The lport lock is expected to be held before calling |
| 898 | * this routine. |
| 899 | */ |
| 900 | static void fc_lport_enter_reset(struct fc_lport *lport) |
| 901 | { |
| 902 | FC_LPORT_DBG(lport, "Entered RESET state from %s state\n", |
| 903 | fc_lport_state(lport)); |
| 904 | |
Chris Leech | 8faecdd | 2009-11-03 11:46:19 -0800 | [diff] [blame] | 905 | if (lport->vport) { |
| 906 | if (lport->link_up) |
| 907 | fc_vport_set_state(lport->vport, FC_VPORT_INITIALIZING); |
| 908 | else |
| 909 | fc_vport_set_state(lport->vport, FC_VPORT_LINKDOWN); |
| 910 | } |
Joe Eykholt | 1190d92 | 2009-07-29 17:04:27 -0700 | [diff] [blame] | 911 | fc_lport_state_enter(lport, LPORT_ST_RESET); |
Chris Leech | 8faecdd | 2009-11-03 11:46:19 -0800 | [diff] [blame] | 912 | fc_vports_linkchange(lport); |
Joe Eykholt | 1190d92 | 2009-07-29 17:04:27 -0700 | [diff] [blame] | 913 | fc_lport_reset_locked(lport); |
Vasu Dev | bc0e17f | 2009-02-27 10:54:57 -0800 | [diff] [blame] | 914 | if (lport->link_up) |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 915 | fc_lport_enter_flogi(lport); |
| 916 | } |
| 917 | |
| 918 | /** |
Joe Eykholt | 1190d92 | 2009-07-29 17:04:27 -0700 | [diff] [blame] | 919 | * fc_lport_enter_disabled() - disable the local port |
| 920 | * @lport: Fibre Channel local port to be reset |
| 921 | * |
| 922 | * Locking Note: The lport lock is expected to be held before calling |
| 923 | * this routine. |
| 924 | */ |
| 925 | static void fc_lport_enter_disabled(struct fc_lport *lport) |
| 926 | { |
| 927 | FC_LPORT_DBG(lport, "Entered disabled state from %s state\n", |
| 928 | fc_lport_state(lport)); |
| 929 | |
| 930 | fc_lport_state_enter(lport, LPORT_ST_DISABLED); |
Chris Leech | 8faecdd | 2009-11-03 11:46:19 -0800 | [diff] [blame] | 931 | fc_vports_linkchange(lport); |
Joe Eykholt | 1190d92 | 2009-07-29 17:04:27 -0700 | [diff] [blame] | 932 | fc_lport_reset_locked(lport); |
| 933 | } |
| 934 | |
| 935 | /** |
Robert Love | 34f42a0 | 2009-02-27 10:55:45 -0800 | [diff] [blame] | 936 | * fc_lport_error() - Handler for any errors |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 937 | * @lport: The fc_lport object |
| 938 | * @fp: The frame pointer |
| 939 | * |
| 940 | * If the error was caused by a resource allocation failure |
| 941 | * then wait for half a second and retry, otherwise retry |
| 942 | * after the e_d_tov time. |
| 943 | */ |
| 944 | static void fc_lport_error(struct fc_lport *lport, struct fc_frame *fp) |
| 945 | { |
| 946 | unsigned long delay = 0; |
Robert Love | 7414705 | 2009-06-10 15:31:10 -0700 | [diff] [blame] | 947 | FC_LPORT_DBG(lport, "Error %ld in state %s, retries %d\n", |
| 948 | PTR_ERR(fp), fc_lport_state(lport), |
| 949 | lport->retry_count); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 950 | |
| 951 | if (!fp || PTR_ERR(fp) == -FC_EX_TIMEOUT) { |
| 952 | /* |
| 953 | * Memory allocation failure, or the exchange timed out. |
| 954 | * Retry after delay |
| 955 | */ |
| 956 | if (lport->retry_count < lport->max_retry_count) { |
| 957 | lport->retry_count++; |
| 958 | if (!fp) |
| 959 | delay = msecs_to_jiffies(500); |
| 960 | else |
| 961 | delay = msecs_to_jiffies(lport->e_d_tov); |
| 962 | |
| 963 | schedule_delayed_work(&lport->retry_work, delay); |
| 964 | } else { |
| 965 | switch (lport->state) { |
Joe Eykholt | b1d9fd5 | 2009-07-29 17:04:22 -0700 | [diff] [blame] | 966 | case LPORT_ST_DISABLED: |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 967 | case LPORT_ST_READY: |
| 968 | case LPORT_ST_RESET: |
Chris Leech | c9c7bd7 | 2009-11-03 11:46:51 -0800 | [diff] [blame] | 969 | case LPORT_ST_RNN_ID: |
Chris Leech | 5baa17c | 2009-11-03 11:46:56 -0800 | [diff] [blame] | 970 | case LPORT_ST_RSNN_NN: |
Chris Leech | c9866a5 | 2009-11-03 11:47:01 -0800 | [diff] [blame] | 971 | case LPORT_ST_RSPN_ID: |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 972 | case LPORT_ST_RFT_ID: |
| 973 | case LPORT_ST_SCR: |
| 974 | case LPORT_ST_DNS: |
| 975 | case LPORT_ST_FLOGI: |
| 976 | case LPORT_ST_LOGO: |
| 977 | fc_lport_enter_reset(lport); |
| 978 | break; |
| 979 | } |
| 980 | } |
| 981 | } |
| 982 | } |
| 983 | |
| 984 | /** |
Chris Leech | 7cccc15 | 2009-11-03 11:47:07 -0800 | [diff] [blame] | 985 | * fc_lport_ns_resp() - Handle response to a name server |
| 986 | * registration exchange |
| 987 | * @sp: current sequence in exchange |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 988 | * @fp: response frame |
| 989 | * @lp_arg: Fibre Channel host port instance |
| 990 | * |
| 991 | * Locking Note: This function will be called without the lport lock |
| 992 | * held, but it will lock, call an _enter_* function or fc_lport_error |
| 993 | * and then unlock the lport. |
| 994 | */ |
Chris Leech | 7cccc15 | 2009-11-03 11:47:07 -0800 | [diff] [blame] | 995 | static void fc_lport_ns_resp(struct fc_seq *sp, struct fc_frame *fp, |
| 996 | void *lp_arg) |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 997 | { |
| 998 | struct fc_lport *lport = lp_arg; |
| 999 | struct fc_frame_header *fh; |
| 1000 | struct fc_ct_hdr *ct; |
| 1001 | |
Chris Leech | 7cccc15 | 2009-11-03 11:47:07 -0800 | [diff] [blame] | 1002 | 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] | 1003 | |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 1004 | if (fp == ERR_PTR(-FC_EX_CLOSED)) |
| 1005 | return; |
| 1006 | |
| 1007 | mutex_lock(&lport->lp_mutex); |
| 1008 | |
Chris Leech | 7cccc15 | 2009-11-03 11:47:07 -0800 | [diff] [blame] | 1009 | if (lport->state < LPORT_ST_RNN_ID || lport->state > LPORT_ST_RFT_ID) { |
| 1010 | FC_LPORT_DBG(lport, "Received a name server response, " |
| 1011 | "but in state %s\n", fc_lport_state(lport)); |
Abhijeet Joglekar | 76f6804 | 2009-04-21 16:26:58 -0700 | [diff] [blame] | 1012 | if (IS_ERR(fp)) |
| 1013 | goto err; |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 1014 | goto out; |
| 1015 | } |
| 1016 | |
Abhijeet Joglekar | 76f6804 | 2009-04-21 16:26:58 -0700 | [diff] [blame] | 1017 | if (IS_ERR(fp)) { |
| 1018 | fc_lport_error(lport, fp); |
| 1019 | goto err; |
| 1020 | } |
| 1021 | |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 1022 | fh = fc_frame_header_get(fp); |
| 1023 | ct = fc_frame_payload_get(fp, sizeof(*ct)); |
| 1024 | |
| 1025 | if (fh && ct && fh->fh_type == FC_TYPE_CT && |
| 1026 | ct->ct_fs_type == FC_FST_DIR && |
| 1027 | ct->ct_fs_subtype == FC_NS_SUBTYPE && |
| 1028 | ntohs(ct->ct_cmd) == FC_FS_ACC) |
Chris Leech | 7cccc15 | 2009-11-03 11:47:07 -0800 | [diff] [blame] | 1029 | switch (lport->state) { |
| 1030 | case LPORT_ST_RNN_ID: |
Chris Leech | c914f7d | 2009-11-03 11:47:12 -0800 | [diff] [blame^] | 1031 | fc_lport_enter_ns(lport, LPORT_ST_RSNN_NN); |
Chris Leech | 7cccc15 | 2009-11-03 11:47:07 -0800 | [diff] [blame] | 1032 | break; |
| 1033 | case LPORT_ST_RSNN_NN: |
Chris Leech | c914f7d | 2009-11-03 11:47:12 -0800 | [diff] [blame^] | 1034 | fc_lport_enter_ns(lport, LPORT_ST_RSPN_ID); |
Chris Leech | 7cccc15 | 2009-11-03 11:47:07 -0800 | [diff] [blame] | 1035 | break; |
| 1036 | case LPORT_ST_RSPN_ID: |
Chris Leech | c914f7d | 2009-11-03 11:47:12 -0800 | [diff] [blame^] | 1037 | fc_lport_enter_ns(lport, LPORT_ST_RFT_ID); |
Chris Leech | 7cccc15 | 2009-11-03 11:47:07 -0800 | [diff] [blame] | 1038 | break; |
| 1039 | case LPORT_ST_RFT_ID: |
| 1040 | fc_lport_enter_scr(lport); |
| 1041 | break; |
| 1042 | default: |
| 1043 | /* should have already been caught by state checks */ |
| 1044 | break; |
| 1045 | } |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 1046 | else |
| 1047 | fc_lport_error(lport, fp); |
| 1048 | out: |
| 1049 | fc_frame_free(fp); |
| 1050 | err: |
| 1051 | mutex_unlock(&lport->lp_mutex); |
| 1052 | } |
| 1053 | |
| 1054 | /** |
Robert Love | 34f42a0 | 2009-02-27 10:55:45 -0800 | [diff] [blame] | 1055 | * fc_lport_scr_resp() - Handle response to State Change Register (SCR) request |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 1056 | * @sp: current sequence in SCR exchange |
| 1057 | * @fp: response frame |
| 1058 | * @lp_arg: Fibre Channel lport port instance that sent the registration request |
| 1059 | * |
| 1060 | * Locking Note: This function will be called without the lport lock |
| 1061 | * held, but it will lock, call an _enter_* function or fc_lport_error |
| 1062 | * and then unlock the lport. |
| 1063 | */ |
| 1064 | static void fc_lport_scr_resp(struct fc_seq *sp, struct fc_frame *fp, |
| 1065 | void *lp_arg) |
| 1066 | { |
| 1067 | struct fc_lport *lport = lp_arg; |
| 1068 | u8 op; |
| 1069 | |
Joe Eykholt | f657d29 | 2009-08-25 14:03:21 -0700 | [diff] [blame] | 1070 | FC_LPORT_DBG(lport, "Received a SCR %s\n", fc_els_resp_type(fp)); |
| 1071 | |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 1072 | if (fp == ERR_PTR(-FC_EX_CLOSED)) |
| 1073 | return; |
| 1074 | |
| 1075 | mutex_lock(&lport->lp_mutex); |
| 1076 | |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 1077 | if (lport->state != LPORT_ST_SCR) { |
Robert Love | 7414705 | 2009-06-10 15:31:10 -0700 | [diff] [blame] | 1078 | FC_LPORT_DBG(lport, "Received a SCR response, but in state " |
| 1079 | "%s\n", fc_lport_state(lport)); |
Abhijeet Joglekar | 76f6804 | 2009-04-21 16:26:58 -0700 | [diff] [blame] | 1080 | if (IS_ERR(fp)) |
| 1081 | goto err; |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 1082 | goto out; |
| 1083 | } |
| 1084 | |
Abhijeet Joglekar | 76f6804 | 2009-04-21 16:26:58 -0700 | [diff] [blame] | 1085 | if (IS_ERR(fp)) { |
| 1086 | fc_lport_error(lport, fp); |
| 1087 | goto err; |
| 1088 | } |
| 1089 | |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 1090 | op = fc_frame_payload_op(fp); |
| 1091 | if (op == ELS_LS_ACC) |
| 1092 | fc_lport_enter_ready(lport); |
| 1093 | else |
| 1094 | fc_lport_error(lport, fp); |
| 1095 | |
| 1096 | out: |
| 1097 | fc_frame_free(fp); |
| 1098 | err: |
| 1099 | mutex_unlock(&lport->lp_mutex); |
| 1100 | } |
| 1101 | |
| 1102 | /** |
Robert Love | 34f42a0 | 2009-02-27 10:55:45 -0800 | [diff] [blame] | 1103 | * fc_lport_enter_scr() - Send a State Change Register (SCR) request |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 1104 | * @lport: Fibre Channel local port to register for state changes |
| 1105 | * |
| 1106 | * Locking Note: The lport lock is expected to be held before calling |
| 1107 | * this routine. |
| 1108 | */ |
| 1109 | static void fc_lport_enter_scr(struct fc_lport *lport) |
| 1110 | { |
| 1111 | struct fc_frame *fp; |
| 1112 | |
Robert Love | 7414705 | 2009-06-10 15:31:10 -0700 | [diff] [blame] | 1113 | FC_LPORT_DBG(lport, "Entered SCR state from %s state\n", |
| 1114 | fc_lport_state(lport)); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 1115 | |
| 1116 | fc_lport_state_enter(lport, LPORT_ST_SCR); |
| 1117 | |
| 1118 | fp = fc_frame_alloc(lport, sizeof(struct fc_els_scr)); |
| 1119 | if (!fp) { |
| 1120 | fc_lport_error(lport, fp); |
| 1121 | return; |
| 1122 | } |
| 1123 | |
Joe Eykholt | a46f327 | 2009-08-25 14:00:55 -0700 | [diff] [blame] | 1124 | if (!lport->tt.elsct_send(lport, FC_FID_FCTRL, fp, ELS_SCR, |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 1125 | fc_lport_scr_resp, lport, lport->e_d_tov)) |
Chris Leech | 8f550f9 | 2009-10-21 16:28:09 -0700 | [diff] [blame] | 1126 | fc_lport_error(lport, NULL); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 1127 | } |
| 1128 | |
| 1129 | /** |
Chris Leech | c914f7d | 2009-11-03 11:47:12 -0800 | [diff] [blame^] | 1130 | * fc_lport_enter_ns() - register some object with the name server |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 1131 | * @lport: Fibre Channel local port to register |
| 1132 | * |
| 1133 | * Locking Note: The lport lock is expected to be held before calling |
| 1134 | * this routine. |
| 1135 | */ |
Chris Leech | c914f7d | 2009-11-03 11:47:12 -0800 | [diff] [blame^] | 1136 | 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] | 1137 | { |
| 1138 | struct fc_frame *fp; |
Chris Leech | c914f7d | 2009-11-03 11:47:12 -0800 | [diff] [blame^] | 1139 | enum fc_ns_req cmd; |
| 1140 | int size = sizeof(struct fc_ct_hdr); |
Chris Leech | c9866a5 | 2009-11-03 11:47:01 -0800 | [diff] [blame] | 1141 | size_t len; |
| 1142 | |
Chris Leech | c914f7d | 2009-11-03 11:47:12 -0800 | [diff] [blame^] | 1143 | FC_LPORT_DBG(lport, "Entered %s state from %s state\n", |
| 1144 | fc_lport_state_names[state], |
Chris Leech | c9866a5 | 2009-11-03 11:47:01 -0800 | [diff] [blame] | 1145 | fc_lport_state(lport)); |
| 1146 | |
Chris Leech | c914f7d | 2009-11-03 11:47:12 -0800 | [diff] [blame^] | 1147 | fc_lport_state_enter(lport, state); |
Chris Leech | c9866a5 | 2009-11-03 11:47:01 -0800 | [diff] [blame] | 1148 | |
Chris Leech | c914f7d | 2009-11-03 11:47:12 -0800 | [diff] [blame^] | 1149 | switch (state) { |
| 1150 | case LPORT_ST_RNN_ID: |
| 1151 | cmd = FC_NS_RNN_ID; |
| 1152 | size += sizeof(struct fc_ns_rn_id); |
| 1153 | break; |
| 1154 | case LPORT_ST_RSNN_NN: |
| 1155 | len = strnlen(fc_host_symbolic_name(lport->host), 255); |
| 1156 | /* if there is no symbolic name, skip to RFT_ID */ |
| 1157 | if (!len) |
| 1158 | return fc_lport_enter_ns(lport, LPORT_ST_RFT_ID); |
| 1159 | cmd = FC_NS_RSNN_NN; |
| 1160 | size += sizeof(struct fc_ns_rsnn) + len; |
| 1161 | break; |
| 1162 | case LPORT_ST_RSPN_ID: |
| 1163 | len = strnlen(fc_host_symbolic_name(lport->host), 255); |
| 1164 | /* if there is no symbolic name, skip to RFT_ID */ |
| 1165 | if (!len) |
| 1166 | return fc_lport_enter_ns(lport, LPORT_ST_RFT_ID); |
| 1167 | cmd = FC_NS_RSPN_ID; |
| 1168 | size += sizeof(struct fc_ns_rspn) + len; |
| 1169 | break; |
| 1170 | case LPORT_ST_RFT_ID: |
| 1171 | cmd = FC_NS_RFT_ID; |
| 1172 | size += sizeof(struct fc_ns_rft); |
| 1173 | break; |
| 1174 | default: |
| 1175 | fc_lport_error(lport, NULL); |
| 1176 | return; |
| 1177 | } |
| 1178 | |
| 1179 | fp = fc_frame_alloc(lport, size); |
Chris Leech | c9866a5 | 2009-11-03 11:47:01 -0800 | [diff] [blame] | 1180 | if (!fp) { |
| 1181 | fc_lport_error(lport, fp); |
| 1182 | return; |
| 1183 | } |
| 1184 | |
Chris Leech | c914f7d | 2009-11-03 11:47:12 -0800 | [diff] [blame^] | 1185 | if (!lport->tt.elsct_send(lport, FC_FID_DIR_SERV, fp, cmd, |
Chris Leech | 7cccc15 | 2009-11-03 11:47:07 -0800 | [diff] [blame] | 1186 | fc_lport_ns_resp, |
Chris Leech | c9c7bd7 | 2009-11-03 11:46:51 -0800 | [diff] [blame] | 1187 | lport, lport->e_d_tov)) |
| 1188 | fc_lport_error(lport, fp); |
| 1189 | } |
| 1190 | |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 1191 | static struct fc_rport_operations fc_lport_rport_ops = { |
| 1192 | .event_callback = fc_lport_rport_callback, |
| 1193 | }; |
| 1194 | |
| 1195 | /** |
Robert Love | 34f42a0 | 2009-02-27 10:55:45 -0800 | [diff] [blame] | 1196 | * fc_rport_enter_dns() - Create a rport to the name server |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 1197 | * @lport: Fibre Channel local port requesting a rport for the name server |
| 1198 | * |
| 1199 | * Locking Note: The lport lock is expected to be held before calling |
| 1200 | * this routine. |
| 1201 | */ |
| 1202 | static void fc_lport_enter_dns(struct fc_lport *lport) |
| 1203 | { |
Joe Eykholt | ab28f1f | 2009-08-25 14:00:34 -0700 | [diff] [blame] | 1204 | struct fc_rport_priv *rdata; |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 1205 | |
Robert Love | 7414705 | 2009-06-10 15:31:10 -0700 | [diff] [blame] | 1206 | FC_LPORT_DBG(lport, "Entered DNS state from %s state\n", |
| 1207 | fc_lport_state(lport)); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 1208 | |
| 1209 | fc_lport_state_enter(lport, LPORT_ST_DNS); |
| 1210 | |
Joe Eykholt | 48f0090 | 2009-08-25 14:01:50 -0700 | [diff] [blame] | 1211 | mutex_lock(&lport->disc.disc_mutex); |
Robert Love | 9737e6a | 2009-08-25 14:02:59 -0700 | [diff] [blame] | 1212 | rdata = lport->tt.rport_create(lport, FC_FID_DIR_SERV); |
Joe Eykholt | 48f0090 | 2009-08-25 14:01:50 -0700 | [diff] [blame] | 1213 | mutex_unlock(&lport->disc.disc_mutex); |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame] | 1214 | if (!rdata) |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 1215 | goto err; |
| 1216 | |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 1217 | rdata->ops = &fc_lport_rport_ops; |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame] | 1218 | lport->tt.rport_login(rdata); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 1219 | return; |
| 1220 | |
| 1221 | err: |
| 1222 | fc_lport_error(lport, NULL); |
| 1223 | } |
| 1224 | |
| 1225 | /** |
Robert Love | 34f42a0 | 2009-02-27 10:55:45 -0800 | [diff] [blame] | 1226 | * fc_lport_timeout() - Handler for the retry_work timer. |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 1227 | * @work: The work struct of the fc_lport |
| 1228 | */ |
| 1229 | static void fc_lport_timeout(struct work_struct *work) |
| 1230 | { |
| 1231 | struct fc_lport *lport = |
| 1232 | container_of(work, struct fc_lport, |
| 1233 | retry_work.work); |
| 1234 | |
| 1235 | mutex_lock(&lport->lp_mutex); |
| 1236 | |
| 1237 | switch (lport->state) { |
Joe Eykholt | b1d9fd5 | 2009-07-29 17:04:22 -0700 | [diff] [blame] | 1238 | case LPORT_ST_DISABLED: |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 1239 | WARN_ON(1); |
| 1240 | break; |
Joe Eykholt | 22655ac | 2009-10-21 16:27:22 -0700 | [diff] [blame] | 1241 | case LPORT_ST_READY: |
| 1242 | WARN_ON(1); |
| 1243 | break; |
| 1244 | case LPORT_ST_RESET: |
| 1245 | break; |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 1246 | case LPORT_ST_FLOGI: |
| 1247 | fc_lport_enter_flogi(lport); |
| 1248 | break; |
| 1249 | case LPORT_ST_DNS: |
| 1250 | fc_lport_enter_dns(lport); |
| 1251 | break; |
Chris Leech | c9c7bd7 | 2009-11-03 11:46:51 -0800 | [diff] [blame] | 1252 | case LPORT_ST_RNN_ID: |
Chris Leech | 5baa17c | 2009-11-03 11:46:56 -0800 | [diff] [blame] | 1253 | case LPORT_ST_RSNN_NN: |
Chris Leech | c9866a5 | 2009-11-03 11:47:01 -0800 | [diff] [blame] | 1254 | case LPORT_ST_RSPN_ID: |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 1255 | case LPORT_ST_RFT_ID: |
Chris Leech | c914f7d | 2009-11-03 11:47:12 -0800 | [diff] [blame^] | 1256 | fc_lport_enter_ns(lport, lport->state); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 1257 | break; |
| 1258 | case LPORT_ST_SCR: |
| 1259 | fc_lport_enter_scr(lport); |
| 1260 | break; |
| 1261 | case LPORT_ST_LOGO: |
| 1262 | fc_lport_enter_logo(lport); |
| 1263 | break; |
| 1264 | } |
| 1265 | |
| 1266 | mutex_unlock(&lport->lp_mutex); |
| 1267 | } |
| 1268 | |
| 1269 | /** |
Robert Love | 34f42a0 | 2009-02-27 10:55:45 -0800 | [diff] [blame] | 1270 | * fc_lport_logo_resp() - Handle response to LOGO request |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 1271 | * @sp: current sequence in LOGO exchange |
| 1272 | * @fp: response frame |
| 1273 | * @lp_arg: Fibre Channel lport port instance that sent the LOGO request |
| 1274 | * |
| 1275 | * Locking Note: This function will be called without the lport lock |
| 1276 | * held, but it will lock, call an _enter_* function or fc_lport_error |
| 1277 | * and then unlock the lport. |
| 1278 | */ |
Chris Leech | 11b5618 | 2009-11-03 11:46:29 -0800 | [diff] [blame] | 1279 | void fc_lport_logo_resp(struct fc_seq *sp, struct fc_frame *fp, |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 1280 | void *lp_arg) |
| 1281 | { |
| 1282 | struct fc_lport *lport = lp_arg; |
| 1283 | u8 op; |
| 1284 | |
Joe Eykholt | f657d29 | 2009-08-25 14:03:21 -0700 | [diff] [blame] | 1285 | FC_LPORT_DBG(lport, "Received a LOGO %s\n", fc_els_resp_type(fp)); |
| 1286 | |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 1287 | if (fp == ERR_PTR(-FC_EX_CLOSED)) |
| 1288 | return; |
| 1289 | |
| 1290 | mutex_lock(&lport->lp_mutex); |
| 1291 | |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 1292 | if (lport->state != LPORT_ST_LOGO) { |
Robert Love | 7414705 | 2009-06-10 15:31:10 -0700 | [diff] [blame] | 1293 | FC_LPORT_DBG(lport, "Received a LOGO response, but in state " |
| 1294 | "%s\n", fc_lport_state(lport)); |
Abhijeet Joglekar | 76f6804 | 2009-04-21 16:26:58 -0700 | [diff] [blame] | 1295 | if (IS_ERR(fp)) |
| 1296 | goto err; |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 1297 | goto out; |
| 1298 | } |
| 1299 | |
Abhijeet Joglekar | 76f6804 | 2009-04-21 16:26:58 -0700 | [diff] [blame] | 1300 | if (IS_ERR(fp)) { |
| 1301 | fc_lport_error(lport, fp); |
| 1302 | goto err; |
| 1303 | } |
| 1304 | |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 1305 | op = fc_frame_payload_op(fp); |
| 1306 | if (op == ELS_LS_ACC) |
Joe Eykholt | 1190d92 | 2009-07-29 17:04:27 -0700 | [diff] [blame] | 1307 | fc_lport_enter_disabled(lport); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 1308 | else |
| 1309 | fc_lport_error(lport, fp); |
| 1310 | |
| 1311 | out: |
| 1312 | fc_frame_free(fp); |
| 1313 | err: |
| 1314 | mutex_unlock(&lport->lp_mutex); |
| 1315 | } |
Chris Leech | 11b5618 | 2009-11-03 11:46:29 -0800 | [diff] [blame] | 1316 | EXPORT_SYMBOL(fc_lport_logo_resp); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 1317 | |
| 1318 | /** |
Robert Love | 34f42a0 | 2009-02-27 10:55:45 -0800 | [diff] [blame] | 1319 | * fc_rport_enter_logo() - Logout of the fabric |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 1320 | * @lport: Fibre Channel local port to be logged out |
| 1321 | * |
| 1322 | * Locking Note: The lport lock is expected to be held before calling |
| 1323 | * this routine. |
| 1324 | */ |
| 1325 | static void fc_lport_enter_logo(struct fc_lport *lport) |
| 1326 | { |
| 1327 | struct fc_frame *fp; |
| 1328 | struct fc_els_logo *logo; |
| 1329 | |
Robert Love | 7414705 | 2009-06-10 15:31:10 -0700 | [diff] [blame] | 1330 | FC_LPORT_DBG(lport, "Entered LOGO state from %s state\n", |
| 1331 | fc_lport_state(lport)); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 1332 | |
| 1333 | fc_lport_state_enter(lport, LPORT_ST_LOGO); |
Chris Leech | 8faecdd | 2009-11-03 11:46:19 -0800 | [diff] [blame] | 1334 | fc_vports_linkchange(lport); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 1335 | |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 1336 | fp = fc_frame_alloc(lport, sizeof(*logo)); |
| 1337 | if (!fp) { |
| 1338 | fc_lport_error(lport, fp); |
| 1339 | return; |
| 1340 | } |
| 1341 | |
Joe Eykholt | a46f327 | 2009-08-25 14:00:55 -0700 | [diff] [blame] | 1342 | if (!lport->tt.elsct_send(lport, FC_FID_FLOGI, fp, ELS_LOGO, |
| 1343 | fc_lport_logo_resp, lport, lport->e_d_tov)) |
Chris Leech | 8f550f9 | 2009-10-21 16:28:09 -0700 | [diff] [blame] | 1344 | fc_lport_error(lport, NULL); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 1345 | } |
| 1346 | |
| 1347 | /** |
Robert Love | 34f42a0 | 2009-02-27 10:55:45 -0800 | [diff] [blame] | 1348 | * fc_lport_flogi_resp() - Handle response to FLOGI request |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 1349 | * @sp: current sequence in FLOGI exchange |
| 1350 | * @fp: response frame |
| 1351 | * @lp_arg: Fibre Channel lport port instance that sent the FLOGI request |
| 1352 | * |
| 1353 | * Locking Note: This function will be called without the lport lock |
| 1354 | * held, but it will lock, call an _enter_* function or fc_lport_error |
| 1355 | * and then unlock the lport. |
| 1356 | */ |
Chris Leech | 11b5618 | 2009-11-03 11:46:29 -0800 | [diff] [blame] | 1357 | void fc_lport_flogi_resp(struct fc_seq *sp, struct fc_frame *fp, |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 1358 | void *lp_arg) |
| 1359 | { |
| 1360 | struct fc_lport *lport = lp_arg; |
| 1361 | struct fc_frame_header *fh; |
| 1362 | struct fc_els_flogi *flp; |
| 1363 | u32 did; |
| 1364 | u16 csp_flags; |
| 1365 | unsigned int r_a_tov; |
| 1366 | unsigned int e_d_tov; |
| 1367 | u16 mfs; |
| 1368 | |
Joe Eykholt | f657d29 | 2009-08-25 14:03:21 -0700 | [diff] [blame] | 1369 | FC_LPORT_DBG(lport, "Received a FLOGI %s\n", fc_els_resp_type(fp)); |
| 1370 | |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 1371 | if (fp == ERR_PTR(-FC_EX_CLOSED)) |
| 1372 | return; |
| 1373 | |
| 1374 | mutex_lock(&lport->lp_mutex); |
| 1375 | |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 1376 | if (lport->state != LPORT_ST_FLOGI) { |
Robert Love | 7414705 | 2009-06-10 15:31:10 -0700 | [diff] [blame] | 1377 | FC_LPORT_DBG(lport, "Received a FLOGI response, but in state " |
| 1378 | "%s\n", fc_lport_state(lport)); |
Abhijeet Joglekar | 76f6804 | 2009-04-21 16:26:58 -0700 | [diff] [blame] | 1379 | if (IS_ERR(fp)) |
| 1380 | goto err; |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 1381 | goto out; |
| 1382 | } |
| 1383 | |
Abhijeet Joglekar | 76f6804 | 2009-04-21 16:26:58 -0700 | [diff] [blame] | 1384 | if (IS_ERR(fp)) { |
| 1385 | fc_lport_error(lport, fp); |
| 1386 | goto err; |
| 1387 | } |
| 1388 | |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 1389 | fh = fc_frame_header_get(fp); |
| 1390 | did = ntoh24(fh->fh_d_id); |
| 1391 | if (fc_frame_payload_op(fp) == ELS_LS_ACC && did != 0) { |
| 1392 | |
Robert Love | 7414705 | 2009-06-10 15:31:10 -0700 | [diff] [blame] | 1393 | printk(KERN_INFO "libfc: Assigned FID (%6x) in FLOGI response\n", |
| 1394 | did); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 1395 | fc_host_port_id(lport->host) = did; |
| 1396 | |
| 1397 | flp = fc_frame_payload_get(fp, sizeof(*flp)); |
| 1398 | if (flp) { |
| 1399 | mfs = ntohs(flp->fl_csp.sp_bb_data) & |
| 1400 | FC_SP_BB_DATA_MASK; |
| 1401 | if (mfs >= FC_SP_MIN_MAX_PAYLOAD && |
| 1402 | mfs < lport->mfs) |
| 1403 | lport->mfs = mfs; |
| 1404 | csp_flags = ntohs(flp->fl_csp.sp_features); |
| 1405 | r_a_tov = ntohl(flp->fl_csp.sp_r_a_tov); |
| 1406 | e_d_tov = ntohl(flp->fl_csp.sp_e_d_tov); |
| 1407 | if (csp_flags & FC_SP_FT_EDTR) |
| 1408 | e_d_tov /= 1000000; |
Chris Leech | db36c06 | 2009-11-03 11:46:24 -0800 | [diff] [blame] | 1409 | |
| 1410 | lport->npiv_enabled = !!(csp_flags & FC_SP_FT_NPIV_ACC); |
| 1411 | |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 1412 | if ((csp_flags & FC_SP_FT_FPORT) == 0) { |
| 1413 | if (e_d_tov > lport->e_d_tov) |
| 1414 | lport->e_d_tov = e_d_tov; |
| 1415 | lport->r_a_tov = 2 * e_d_tov; |
Robert Love | 7414705 | 2009-06-10 15:31:10 -0700 | [diff] [blame] | 1416 | printk(KERN_INFO "libfc: Port (%6x) entered " |
| 1417 | "point to point mode\n", did); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 1418 | fc_lport_ptp_setup(lport, ntoh24(fh->fh_s_id), |
| 1419 | get_unaligned_be64( |
| 1420 | &flp->fl_wwpn), |
| 1421 | get_unaligned_be64( |
| 1422 | &flp->fl_wwnn)); |
| 1423 | } else { |
| 1424 | lport->e_d_tov = e_d_tov; |
| 1425 | lport->r_a_tov = r_a_tov; |
| 1426 | fc_host_fabric_name(lport->host) = |
| 1427 | get_unaligned_be64(&flp->fl_wwnn); |
| 1428 | fc_lport_enter_dns(lport); |
| 1429 | } |
| 1430 | } |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 1431 | } else { |
Robert Love | 7414705 | 2009-06-10 15:31:10 -0700 | [diff] [blame] | 1432 | FC_LPORT_DBG(lport, "Bad FLOGI response\n"); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 1433 | } |
| 1434 | |
| 1435 | out: |
| 1436 | fc_frame_free(fp); |
| 1437 | err: |
| 1438 | mutex_unlock(&lport->lp_mutex); |
| 1439 | } |
Chris Leech | 11b5618 | 2009-11-03 11:46:29 -0800 | [diff] [blame] | 1440 | EXPORT_SYMBOL(fc_lport_flogi_resp); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 1441 | |
| 1442 | /** |
Robert Love | 34f42a0 | 2009-02-27 10:55:45 -0800 | [diff] [blame] | 1443 | * fc_rport_enter_flogi() - Send a FLOGI request to the fabric manager |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 1444 | * @lport: Fibre Channel local port to be logged in to the fabric |
| 1445 | * |
| 1446 | * Locking Note: The lport lock is expected to be held before calling |
| 1447 | * this routine. |
| 1448 | */ |
| 1449 | void fc_lport_enter_flogi(struct fc_lport *lport) |
| 1450 | { |
| 1451 | struct fc_frame *fp; |
| 1452 | |
Robert Love | 7414705 | 2009-06-10 15:31:10 -0700 | [diff] [blame] | 1453 | FC_LPORT_DBG(lport, "Entered FLOGI state from %s state\n", |
| 1454 | fc_lport_state(lport)); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 1455 | |
| 1456 | fc_lport_state_enter(lport, LPORT_ST_FLOGI); |
| 1457 | |
| 1458 | fp = fc_frame_alloc(lport, sizeof(struct fc_els_flogi)); |
| 1459 | if (!fp) |
| 1460 | return fc_lport_error(lport, fp); |
| 1461 | |
Chris Leech | db36c06 | 2009-11-03 11:46:24 -0800 | [diff] [blame] | 1462 | if (!lport->tt.elsct_send(lport, FC_FID_FLOGI, fp, |
| 1463 | lport->vport ? ELS_FDISC : ELS_FLOGI, |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 1464 | fc_lport_flogi_resp, lport, lport->e_d_tov)) |
Chris Leech | 8f550f9 | 2009-10-21 16:28:09 -0700 | [diff] [blame] | 1465 | fc_lport_error(lport, NULL); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 1466 | } |
| 1467 | |
| 1468 | /* Configure a fc_lport */ |
| 1469 | int fc_lport_config(struct fc_lport *lport) |
| 1470 | { |
| 1471 | INIT_DELAYED_WORK(&lport->retry_work, fc_lport_timeout); |
| 1472 | mutex_init(&lport->lp_mutex); |
| 1473 | |
Joe Eykholt | b1d9fd5 | 2009-07-29 17:04:22 -0700 | [diff] [blame] | 1474 | fc_lport_state_enter(lport, LPORT_ST_DISABLED); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 1475 | |
| 1476 | fc_lport_add_fc4_type(lport, FC_TYPE_FCP); |
| 1477 | fc_lport_add_fc4_type(lport, FC_TYPE_CT); |
| 1478 | |
| 1479 | return 0; |
| 1480 | } |
| 1481 | EXPORT_SYMBOL(fc_lport_config); |
| 1482 | |
| 1483 | int fc_lport_init(struct fc_lport *lport) |
| 1484 | { |
| 1485 | if (!lport->tt.lport_recv) |
| 1486 | lport->tt.lport_recv = fc_lport_recv_req; |
| 1487 | |
| 1488 | if (!lport->tt.lport_reset) |
| 1489 | lport->tt.lport_reset = fc_lport_reset; |
| 1490 | |
| 1491 | fc_host_port_type(lport->host) = FC_PORTTYPE_NPORT; |
| 1492 | fc_host_node_name(lport->host) = lport->wwnn; |
| 1493 | fc_host_port_name(lport->host) = lport->wwpn; |
| 1494 | fc_host_supported_classes(lport->host) = FC_COS_CLASS3; |
| 1495 | memset(fc_host_supported_fc4s(lport->host), 0, |
| 1496 | sizeof(fc_host_supported_fc4s(lport->host))); |
| 1497 | fc_host_supported_fc4s(lport->host)[2] = 1; |
| 1498 | fc_host_supported_fc4s(lport->host)[7] = 1; |
| 1499 | |
| 1500 | /* This value is also unchanging */ |
| 1501 | memset(fc_host_active_fc4s(lport->host), 0, |
| 1502 | sizeof(fc_host_active_fc4s(lport->host))); |
| 1503 | fc_host_active_fc4s(lport->host)[2] = 1; |
| 1504 | fc_host_active_fc4s(lport->host)[7] = 1; |
| 1505 | fc_host_maxframe_size(lport->host) = lport->mfs; |
| 1506 | fc_host_supported_speeds(lport->host) = 0; |
| 1507 | if (lport->link_supported_speeds & FC_PORTSPEED_1GBIT) |
| 1508 | fc_host_supported_speeds(lport->host) |= FC_PORTSPEED_1GBIT; |
| 1509 | if (lport->link_supported_speeds & FC_PORTSPEED_10GBIT) |
| 1510 | fc_host_supported_speeds(lport->host) |= FC_PORTSPEED_10GBIT; |
| 1511 | |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 1512 | return 0; |
| 1513 | } |
| 1514 | EXPORT_SYMBOL(fc_lport_init); |