Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright(c) 2007 - 2008 Intel Corporation. All rights reserved. |
| 3 | * |
| 4 | * This program is free software; you can redistribute it and/or modify it |
| 5 | * under the terms and conditions of the GNU General Public License, |
| 6 | * version 2, as published by the Free Software Foundation. |
| 7 | * |
| 8 | * This program is distributed in the hope it will be useful, but WITHOUT |
| 9 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 10 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
| 11 | * more details. |
| 12 | * |
| 13 | * You should have received a copy of the GNU General Public License along with |
| 14 | * this program; if not, write to the Free Software Foundation, Inc., |
| 15 | * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA. |
| 16 | * |
| 17 | * Maintained at www.Open-FCoE.org |
| 18 | */ |
| 19 | |
| 20 | /* |
| 21 | * Target Discovery |
| 22 | * |
| 23 | * This block discovers all FC-4 remote ports, including FCP initiators. It |
| 24 | * also handles RSCN events and re-discovery if necessary. |
| 25 | */ |
| 26 | |
| 27 | /* |
| 28 | * DISC LOCKING |
| 29 | * |
| 30 | * The disc mutex is can be locked when acquiring rport locks, but may not |
| 31 | * be held when acquiring the lport lock. Refer to fc_lport.c for more |
| 32 | * details. |
| 33 | */ |
| 34 | |
| 35 | #include <linux/timer.h> |
| 36 | #include <linux/err.h> |
| 37 | #include <asm/unaligned.h> |
| 38 | |
| 39 | #include <scsi/fc/fc_gs.h> |
| 40 | |
| 41 | #include <scsi/libfc.h> |
| 42 | |
| 43 | #define FC_DISC_RETRY_LIMIT 3 /* max retries */ |
| 44 | #define FC_DISC_RETRY_DELAY 500UL /* (msecs) delay */ |
| 45 | |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 46 | static void fc_disc_gpn_ft_req(struct fc_disc *); |
| 47 | static void fc_disc_gpn_ft_resp(struct fc_seq *, struct fc_frame *, void *); |
Joe Eykholt | f211fa5 | 2009-08-25 14:01:01 -0700 | [diff] [blame] | 48 | static int fc_disc_new_target(struct fc_disc *, struct fc_rport_priv *, |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 49 | struct fc_rport_identifiers *); |
Joe Eykholt | 786681b | 2009-08-25 14:01:29 -0700 | [diff] [blame] | 50 | static void fc_disc_done(struct fc_disc *, enum fc_disc_event); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 51 | static void fc_disc_timeout(struct work_struct *); |
| 52 | static void fc_disc_single(struct fc_disc *, struct fc_disc_port *); |
| 53 | static void fc_disc_restart(struct fc_disc *); |
| 54 | |
| 55 | /** |
Robert Love | 34f42a0 | 2009-02-27 10:55:45 -0800 | [diff] [blame] | 56 | * fc_disc_lookup_rport() - lookup a remote port by port_id |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 57 | * @lport: Fibre Channel host port instance |
| 58 | * @port_id: remote port port_id to match |
| 59 | */ |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame] | 60 | struct fc_rport_priv *fc_disc_lookup_rport(const struct fc_lport *lport, |
| 61 | u32 port_id) |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 62 | { |
| 63 | const struct fc_disc *disc = &lport->disc; |
Joe Eykholt | ab28f1f | 2009-08-25 14:00:34 -0700 | [diff] [blame] | 64 | struct fc_rport_priv *rdata; |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 65 | |
| 66 | list_for_each_entry(rdata, &disc->rports, peers) { |
Joe Eykholt | 9e9d045 | 2009-08-25 14:01:18 -0700 | [diff] [blame] | 67 | if (rdata->ids.port_id == port_id && |
| 68 | rdata->rp_state != RPORT_ST_DELETE) |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame] | 69 | return rdata; |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 70 | } |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame] | 71 | return NULL; |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 72 | } |
| 73 | |
| 74 | /** |
Robert Love | 34f42a0 | 2009-02-27 10:55:45 -0800 | [diff] [blame] | 75 | * fc_disc_stop_rports() - delete all the remote ports associated with the lport |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 76 | * @disc: The discovery job to stop rports on |
| 77 | * |
| 78 | * Locking Note: This function expects that the lport mutex is locked before |
| 79 | * calling it. |
| 80 | */ |
| 81 | void fc_disc_stop_rports(struct fc_disc *disc) |
| 82 | { |
| 83 | struct fc_lport *lport; |
Joe Eykholt | ab28f1f | 2009-08-25 14:00:34 -0700 | [diff] [blame] | 84 | struct fc_rport_priv *rdata, *next; |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 85 | |
| 86 | lport = disc->lport; |
| 87 | |
| 88 | mutex_lock(&disc->disc_mutex); |
Joe Eykholt | 9e9d045 | 2009-08-25 14:01:18 -0700 | [diff] [blame] | 89 | list_for_each_entry_safe(rdata, next, &disc->rports, peers) |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame] | 90 | lport->tt.rport_logoff(rdata); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 91 | mutex_unlock(&disc->disc_mutex); |
| 92 | } |
| 93 | |
| 94 | /** |
Robert Love | 34f42a0 | 2009-02-27 10:55:45 -0800 | [diff] [blame] | 95 | * fc_disc_rport_callback() - Event handler for rport events |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 96 | * @lport: The lport which is receiving the event |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame] | 97 | * @rdata: private remote port data |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 98 | * @event: The event that occured |
| 99 | * |
| 100 | * Locking Note: The rport lock should not be held when calling |
| 101 | * this function. |
| 102 | */ |
| 103 | static void fc_disc_rport_callback(struct fc_lport *lport, |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame] | 104 | struct fc_rport_priv *rdata, |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 105 | enum fc_rport_event event) |
| 106 | { |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 107 | struct fc_disc *disc = &lport->disc; |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 108 | |
Robert Love | 7414705 | 2009-06-10 15:31:10 -0700 | [diff] [blame] | 109 | FC_DISC_DBG(disc, "Received a %d event for port (%6x)\n", event, |
Joe Eykholt | f211fa5 | 2009-08-25 14:01:01 -0700 | [diff] [blame] | 110 | rdata->ids.port_id); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 111 | |
Abhijeet Joglekar | b4c6f54 | 2009-04-21 16:27:04 -0700 | [diff] [blame] | 112 | switch (event) { |
Joe Eykholt | 4c0f62b | 2009-08-25 14:01:12 -0700 | [diff] [blame] | 113 | case RPORT_EV_READY: |
Abhijeet Joglekar | b4c6f54 | 2009-04-21 16:27:04 -0700 | [diff] [blame] | 114 | break; |
| 115 | case RPORT_EV_LOGO: |
| 116 | case RPORT_EV_FAILED: |
| 117 | case RPORT_EV_STOP: |
Abhijeet Joglekar | b4c6f54 | 2009-04-21 16:27:04 -0700 | [diff] [blame] | 118 | break; |
| 119 | default: |
| 120 | break; |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 121 | } |
| 122 | |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 123 | } |
| 124 | |
| 125 | /** |
Robert Love | 34f42a0 | 2009-02-27 10:55:45 -0800 | [diff] [blame] | 126 | * fc_disc_recv_rscn_req() - Handle Registered State Change Notification (RSCN) |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 127 | * @sp: Current sequence of the RSCN exchange |
| 128 | * @fp: RSCN Frame |
| 129 | * @lport: Fibre Channel host port instance |
| 130 | * |
| 131 | * Locking Note: This function expects that the disc_mutex is locked |
| 132 | * before it is called. |
| 133 | */ |
| 134 | static void fc_disc_recv_rscn_req(struct fc_seq *sp, struct fc_frame *fp, |
| 135 | struct fc_disc *disc) |
| 136 | { |
| 137 | struct fc_lport *lport; |
Joe Eykholt | ab28f1f | 2009-08-25 14:00:34 -0700 | [diff] [blame] | 138 | struct fc_rport_priv *rdata; |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 139 | struct fc_els_rscn *rp; |
| 140 | struct fc_els_rscn_page *pp; |
| 141 | struct fc_seq_els_data rjt_data; |
| 142 | unsigned int len; |
| 143 | int redisc = 0; |
| 144 | enum fc_els_rscn_ev_qual ev_qual; |
| 145 | enum fc_els_rscn_addr_fmt fmt; |
| 146 | LIST_HEAD(disc_ports); |
| 147 | struct fc_disc_port *dp, *next; |
| 148 | |
| 149 | lport = disc->lport; |
| 150 | |
Robert Love | 7414705 | 2009-06-10 15:31:10 -0700 | [diff] [blame] | 151 | FC_DISC_DBG(disc, "Received an RSCN event\n"); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 152 | |
| 153 | /* make sure the frame contains an RSCN message */ |
| 154 | rp = fc_frame_payload_get(fp, sizeof(*rp)); |
| 155 | if (!rp) |
| 156 | goto reject; |
| 157 | /* make sure the page length is as expected (4 bytes) */ |
| 158 | if (rp->rscn_page_len != sizeof(*pp)) |
| 159 | goto reject; |
| 160 | /* get the RSCN payload length */ |
| 161 | len = ntohs(rp->rscn_plen); |
| 162 | if (len < sizeof(*rp)) |
| 163 | goto reject; |
| 164 | /* make sure the frame contains the expected payload */ |
| 165 | rp = fc_frame_payload_get(fp, len); |
| 166 | if (!rp) |
| 167 | goto reject; |
| 168 | /* payload must be a multiple of the RSCN page size */ |
| 169 | len -= sizeof(*rp); |
| 170 | if (len % sizeof(*pp)) |
| 171 | goto reject; |
| 172 | |
| 173 | for (pp = (void *)(rp + 1); len > 0; len -= sizeof(*pp), pp++) { |
| 174 | ev_qual = pp->rscn_page_flags >> ELS_RSCN_EV_QUAL_BIT; |
| 175 | ev_qual &= ELS_RSCN_EV_QUAL_MASK; |
| 176 | fmt = pp->rscn_page_flags >> ELS_RSCN_ADDR_FMT_BIT; |
| 177 | fmt &= ELS_RSCN_ADDR_FMT_MASK; |
| 178 | /* |
| 179 | * if we get an address format other than port |
| 180 | * (area, domain, fabric), then do a full discovery |
| 181 | */ |
| 182 | switch (fmt) { |
| 183 | case ELS_ADDR_FMT_PORT: |
Robert Love | 7414705 | 2009-06-10 15:31:10 -0700 | [diff] [blame] | 184 | FC_DISC_DBG(disc, "Port address format for port " |
| 185 | "(%6x)\n", ntoh24(pp->rscn_fid)); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 186 | dp = kzalloc(sizeof(*dp), GFP_KERNEL); |
| 187 | if (!dp) { |
| 188 | redisc = 1; |
| 189 | break; |
| 190 | } |
| 191 | dp->lp = lport; |
| 192 | dp->ids.port_id = ntoh24(pp->rscn_fid); |
| 193 | dp->ids.port_name = -1; |
| 194 | dp->ids.node_name = -1; |
| 195 | dp->ids.roles = FC_RPORT_ROLE_UNKNOWN; |
| 196 | list_add_tail(&dp->peers, &disc_ports); |
| 197 | break; |
| 198 | case ELS_ADDR_FMT_AREA: |
| 199 | case ELS_ADDR_FMT_DOM: |
| 200 | case ELS_ADDR_FMT_FAB: |
| 201 | default: |
Robert Love | 7414705 | 2009-06-10 15:31:10 -0700 | [diff] [blame] | 202 | FC_DISC_DBG(disc, "Address format is (%d)\n", fmt); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 203 | redisc = 1; |
| 204 | break; |
| 205 | } |
| 206 | } |
| 207 | lport->tt.seq_els_rsp_send(sp, ELS_LS_ACC, NULL); |
| 208 | if (redisc) { |
Robert Love | 7414705 | 2009-06-10 15:31:10 -0700 | [diff] [blame] | 209 | FC_DISC_DBG(disc, "RSCN received: rediscovering\n"); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 210 | fc_disc_restart(disc); |
| 211 | } else { |
Robert Love | 7414705 | 2009-06-10 15:31:10 -0700 | [diff] [blame] | 212 | FC_DISC_DBG(disc, "RSCN received: not rediscovering. " |
| 213 | "redisc %d state %d in_prog %d\n", |
| 214 | redisc, lport->state, disc->pending); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 215 | list_for_each_entry_safe(dp, next, &disc_ports, peers) { |
| 216 | list_del(&dp->peers); |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame] | 217 | rdata = lport->tt.rport_lookup(lport, dp->ids.port_id); |
| 218 | if (rdata) { |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame] | 219 | lport->tt.rport_logoff(rdata); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 220 | } |
| 221 | fc_disc_single(disc, dp); |
| 222 | } |
| 223 | } |
| 224 | fc_frame_free(fp); |
| 225 | return; |
| 226 | reject: |
Robert Love | 7414705 | 2009-06-10 15:31:10 -0700 | [diff] [blame] | 227 | FC_DISC_DBG(disc, "Received a bad RSCN frame\n"); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 228 | rjt_data.fp = NULL; |
| 229 | rjt_data.reason = ELS_RJT_LOGIC; |
| 230 | rjt_data.explan = ELS_EXPL_NONE; |
| 231 | lport->tt.seq_els_rsp_send(sp, ELS_LS_RJT, &rjt_data); |
| 232 | fc_frame_free(fp); |
| 233 | } |
| 234 | |
| 235 | /** |
Robert Love | 34f42a0 | 2009-02-27 10:55:45 -0800 | [diff] [blame] | 236 | * fc_disc_recv_req() - Handle incoming requests |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 237 | * @sp: Current sequence of the request exchange |
| 238 | * @fp: The frame |
| 239 | * @lport: The FC local port |
| 240 | * |
| 241 | * Locking Note: This function is called from the EM and will lock |
| 242 | * the disc_mutex before calling the handler for the |
| 243 | * request. |
| 244 | */ |
| 245 | static void fc_disc_recv_req(struct fc_seq *sp, struct fc_frame *fp, |
| 246 | struct fc_lport *lport) |
| 247 | { |
| 248 | u8 op; |
| 249 | struct fc_disc *disc = &lport->disc; |
| 250 | |
| 251 | op = fc_frame_payload_op(fp); |
| 252 | switch (op) { |
| 253 | case ELS_RSCN: |
| 254 | mutex_lock(&disc->disc_mutex); |
| 255 | fc_disc_recv_rscn_req(sp, fp, disc); |
| 256 | mutex_unlock(&disc->disc_mutex); |
| 257 | break; |
| 258 | default: |
Robert Love | 7414705 | 2009-06-10 15:31:10 -0700 | [diff] [blame] | 259 | FC_DISC_DBG(disc, "Received an unsupported request, " |
| 260 | "the opcode is (%x)\n", op); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 261 | break; |
| 262 | } |
| 263 | } |
| 264 | |
| 265 | /** |
Robert Love | 34f42a0 | 2009-02-27 10:55:45 -0800 | [diff] [blame] | 266 | * fc_disc_restart() - Restart discovery |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 267 | * @lport: FC discovery context |
| 268 | * |
| 269 | * Locking Note: This function expects that the disc mutex |
| 270 | * is already locked. |
| 271 | */ |
| 272 | static void fc_disc_restart(struct fc_disc *disc) |
| 273 | { |
Joe Eykholt | ab28f1f | 2009-08-25 14:00:34 -0700 | [diff] [blame] | 274 | struct fc_rport_priv *rdata, *next; |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 275 | struct fc_lport *lport = disc->lport; |
| 276 | |
Robert Love | 7414705 | 2009-06-10 15:31:10 -0700 | [diff] [blame] | 277 | FC_DISC_DBG(disc, "Restarting discovery\n"); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 278 | |
Joe Eykholt | 9e9d045 | 2009-08-25 14:01:18 -0700 | [diff] [blame] | 279 | list_for_each_entry_safe(rdata, next, &disc->rports, peers) |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame] | 280 | lport->tt.rport_logoff(rdata); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 281 | |
| 282 | disc->requested = 1; |
| 283 | if (!disc->pending) |
| 284 | fc_disc_gpn_ft_req(disc); |
| 285 | } |
| 286 | |
| 287 | /** |
Robert Love | 34f42a0 | 2009-02-27 10:55:45 -0800 | [diff] [blame] | 288 | * fc_disc_start() - Fibre Channel Target discovery |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 289 | * @lport: FC local port |
| 290 | * |
| 291 | * Returns non-zero if discovery cannot be started. |
| 292 | */ |
| 293 | static void fc_disc_start(void (*disc_callback)(struct fc_lport *, |
| 294 | enum fc_disc_event), |
| 295 | struct fc_lport *lport) |
| 296 | { |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame] | 297 | struct fc_rport_priv *rdata; |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 298 | struct fc_disc *disc = &lport->disc; |
| 299 | |
| 300 | /* |
| 301 | * At this point we may have a new disc job or an existing |
| 302 | * one. Either way, let's lock when we make changes to it |
| 303 | * and send the GPN_FT request. |
| 304 | */ |
| 305 | mutex_lock(&disc->disc_mutex); |
| 306 | |
| 307 | disc->disc_callback = disc_callback; |
| 308 | |
| 309 | /* |
| 310 | * If not ready, or already running discovery, just set request flag. |
| 311 | */ |
| 312 | disc->requested = 1; |
| 313 | |
| 314 | if (disc->pending) { |
| 315 | mutex_unlock(&disc->disc_mutex); |
| 316 | return; |
| 317 | } |
| 318 | |
| 319 | /* |
| 320 | * Handle point-to-point mode as a simple discovery |
| 321 | * of the remote port. Yucky, yucky, yuck, yuck! |
| 322 | */ |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame] | 323 | rdata = disc->lport->ptp_rp; |
| 324 | if (rdata) { |
Joe Eykholt | f211fa5 | 2009-08-25 14:01:01 -0700 | [diff] [blame] | 325 | kref_get(&rdata->kref); |
| 326 | if (!fc_disc_new_target(disc, rdata, &rdata->ids)) { |
Joe Eykholt | 786681b | 2009-08-25 14:01:29 -0700 | [diff] [blame] | 327 | fc_disc_done(disc, DISC_EV_SUCCESS); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 328 | } |
Joe Eykholt | f211fa5 | 2009-08-25 14:01:01 -0700 | [diff] [blame] | 329 | kref_put(&rdata->kref, rdata->local_port->tt.rport_destroy); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 330 | } else { |
| 331 | fc_disc_gpn_ft_req(disc); /* get ports by FC-4 type */ |
| 332 | } |
| 333 | |
| 334 | mutex_unlock(&disc->disc_mutex); |
| 335 | } |
| 336 | |
| 337 | static struct fc_rport_operations fc_disc_rport_ops = { |
| 338 | .event_callback = fc_disc_rport_callback, |
| 339 | }; |
| 340 | |
| 341 | /** |
Robert Love | 34f42a0 | 2009-02-27 10:55:45 -0800 | [diff] [blame] | 342 | * fc_disc_new_target() - Handle new target found by discovery |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 343 | * @lport: FC local port |
Joe Eykholt | f211fa5 | 2009-08-25 14:01:01 -0700 | [diff] [blame] | 344 | * @rdata: The previous FC remote port priv (NULL if new remote port) |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 345 | * @ids: Identifiers for the new FC remote port |
| 346 | * |
| 347 | * Locking Note: This function expects that the disc_mutex is locked |
| 348 | * before it is called. |
| 349 | */ |
| 350 | static int fc_disc_new_target(struct fc_disc *disc, |
Joe Eykholt | f211fa5 | 2009-08-25 14:01:01 -0700 | [diff] [blame] | 351 | struct fc_rport_priv *rdata, |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 352 | struct fc_rport_identifiers *ids) |
| 353 | { |
| 354 | struct fc_lport *lport = disc->lport; |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 355 | int error = 0; |
| 356 | |
Joe Eykholt | f211fa5 | 2009-08-25 14:01:01 -0700 | [diff] [blame] | 357 | if (rdata && ids->port_name) { |
| 358 | if (rdata->ids.port_name == -1) { |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 359 | /* |
| 360 | * Set WWN and fall through to notify of create. |
| 361 | */ |
Joe Eykholt | f211fa5 | 2009-08-25 14:01:01 -0700 | [diff] [blame] | 362 | rdata->ids.port_name = ids->port_name; |
| 363 | rdata->ids.node_name = ids->node_name; |
| 364 | } else if (rdata->ids.port_name != ids->port_name) { |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 365 | /* |
| 366 | * This is a new port with the same FCID as |
| 367 | * a previously-discovered port. Presumably the old |
| 368 | * port logged out and a new port logged in and was |
| 369 | * assigned the same FCID. This should be rare. |
| 370 | * Delete the old one and fall thru to re-create. |
| 371 | */ |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame] | 372 | lport->tt.rport_logoff(rdata); |
Joe Eykholt | f211fa5 | 2009-08-25 14:01:01 -0700 | [diff] [blame] | 373 | rdata = NULL; |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 374 | } |
| 375 | } |
| 376 | if (((ids->port_name != -1) || (ids->port_id != -1)) && |
| 377 | ids->port_id != fc_host_port_id(lport->host) && |
| 378 | ids->port_name != lport->wwpn) { |
Joe Eykholt | f211fa5 | 2009-08-25 14:01:01 -0700 | [diff] [blame] | 379 | if (!rdata) { |
Joe Eykholt | 19f97e3 | 2009-08-25 14:01:55 -0700 | [diff] [blame^] | 380 | rdata = lport->tt.rport_create(lport, ids); |
| 381 | if (!rdata) |
| 382 | error = -ENOMEM; |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 383 | } |
Joe Eykholt | f211fa5 | 2009-08-25 14:01:01 -0700 | [diff] [blame] | 384 | if (rdata) { |
Robert Love | d3b3332 | 2009-02-27 10:55:29 -0800 | [diff] [blame] | 385 | rdata->ops = &fc_disc_rport_ops; |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame] | 386 | lport->tt.rport_login(rdata); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 387 | } |
| 388 | } |
| 389 | return error; |
| 390 | } |
| 391 | |
| 392 | /** |
Robert Love | 34f42a0 | 2009-02-27 10:55:45 -0800 | [diff] [blame] | 393 | * fc_disc_done() - Discovery has been completed |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 394 | * @disc: FC discovery context |
Joe Eykholt | 786681b | 2009-08-25 14:01:29 -0700 | [diff] [blame] | 395 | * @event: discovery completion status |
| 396 | * |
Abhijeet Joglekar | 0d228c0 | 2009-04-21 16:26:52 -0700 | [diff] [blame] | 397 | * Locking Note: This function expects that the disc mutex is locked before |
| 398 | * it is called. The discovery callback is then made with the lock released, |
| 399 | * and the lock is re-taken before returning from this function |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 400 | */ |
Joe Eykholt | 786681b | 2009-08-25 14:01:29 -0700 | [diff] [blame] | 401 | static void fc_disc_done(struct fc_disc *disc, enum fc_disc_event event) |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 402 | { |
| 403 | struct fc_lport *lport = disc->lport; |
| 404 | |
Robert Love | 7414705 | 2009-06-10 15:31:10 -0700 | [diff] [blame] | 405 | FC_DISC_DBG(disc, "Discovery complete\n"); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 406 | |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 407 | if (disc->requested) |
| 408 | fc_disc_gpn_ft_req(disc); |
| 409 | else |
| 410 | disc->pending = 0; |
Abhijeet Joglekar | 0d228c0 | 2009-04-21 16:26:52 -0700 | [diff] [blame] | 411 | |
| 412 | mutex_unlock(&disc->disc_mutex); |
| 413 | disc->disc_callback(lport, event); |
| 414 | mutex_lock(&disc->disc_mutex); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 415 | } |
| 416 | |
| 417 | /** |
Robert Love | 34f42a0 | 2009-02-27 10:55:45 -0800 | [diff] [blame] | 418 | * fc_disc_error() - Handle error on dNS request |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 419 | * @disc: FC discovery context |
| 420 | * @fp: The frame pointer |
| 421 | */ |
| 422 | static void fc_disc_error(struct fc_disc *disc, struct fc_frame *fp) |
| 423 | { |
| 424 | struct fc_lport *lport = disc->lport; |
| 425 | unsigned long delay = 0; |
Robert Love | 7414705 | 2009-06-10 15:31:10 -0700 | [diff] [blame] | 426 | |
| 427 | FC_DISC_DBG(disc, "Error %ld, retries %d/%d\n", |
| 428 | PTR_ERR(fp), disc->retry_count, |
| 429 | FC_DISC_RETRY_LIMIT); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 430 | |
| 431 | if (!fp || PTR_ERR(fp) == -FC_EX_TIMEOUT) { |
| 432 | /* |
| 433 | * Memory allocation failure, or the exchange timed out, |
| 434 | * retry after delay. |
| 435 | */ |
| 436 | if (disc->retry_count < FC_DISC_RETRY_LIMIT) { |
| 437 | /* go ahead and retry */ |
| 438 | if (!fp) |
| 439 | delay = msecs_to_jiffies(FC_DISC_RETRY_DELAY); |
| 440 | else { |
| 441 | delay = msecs_to_jiffies(lport->e_d_tov); |
| 442 | |
| 443 | /* timeout faster first time */ |
| 444 | if (!disc->retry_count) |
| 445 | delay /= 4; |
| 446 | } |
| 447 | disc->retry_count++; |
| 448 | schedule_delayed_work(&disc->disc_work, delay); |
Joe Eykholt | 786681b | 2009-08-25 14:01:29 -0700 | [diff] [blame] | 449 | } else |
| 450 | fc_disc_done(disc, DISC_EV_FAILED); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 451 | } |
| 452 | } |
| 453 | |
| 454 | /** |
Robert Love | 34f42a0 | 2009-02-27 10:55:45 -0800 | [diff] [blame] | 455 | * fc_disc_gpn_ft_req() - Send Get Port Names by FC-4 type (GPN_FT) request |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 456 | * @lport: FC discovery context |
| 457 | * |
| 458 | * Locking Note: This function expects that the disc_mutex is locked |
| 459 | * before it is called. |
| 460 | */ |
| 461 | static void fc_disc_gpn_ft_req(struct fc_disc *disc) |
| 462 | { |
| 463 | struct fc_frame *fp; |
| 464 | struct fc_lport *lport = disc->lport; |
| 465 | |
| 466 | WARN_ON(!fc_lport_test_ready(lport)); |
| 467 | |
| 468 | disc->pending = 1; |
| 469 | disc->requested = 0; |
| 470 | |
| 471 | disc->buf_len = 0; |
| 472 | disc->seq_count = 0; |
| 473 | fp = fc_frame_alloc(lport, |
| 474 | sizeof(struct fc_ct_hdr) + |
| 475 | sizeof(struct fc_ns_gid_ft)); |
| 476 | if (!fp) |
| 477 | goto err; |
| 478 | |
Joe Eykholt | a46f327 | 2009-08-25 14:00:55 -0700 | [diff] [blame] | 479 | if (lport->tt.elsct_send(lport, 0, fp, |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 480 | FC_NS_GPN_FT, |
| 481 | fc_disc_gpn_ft_resp, |
| 482 | disc, lport->e_d_tov)) |
| 483 | return; |
| 484 | err: |
| 485 | fc_disc_error(disc, fp); |
| 486 | } |
| 487 | |
| 488 | /** |
Joe Eykholt | 786681b | 2009-08-25 14:01:29 -0700 | [diff] [blame] | 489 | * fc_disc_gpn_ft_parse() - Parse the body of the dNS GPN_FT response. |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 490 | * @lport: Fibre Channel host port instance |
| 491 | * @buf: GPN_FT response buffer |
| 492 | * @len: size of response buffer |
Joe Eykholt | 786681b | 2009-08-25 14:01:29 -0700 | [diff] [blame] | 493 | * |
| 494 | * Goes through the list of IDs and names resulting from a request. |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 495 | */ |
| 496 | static int fc_disc_gpn_ft_parse(struct fc_disc *disc, void *buf, size_t len) |
| 497 | { |
| 498 | struct fc_lport *lport; |
| 499 | struct fc_gpn_ft_resp *np; |
| 500 | char *bp; |
| 501 | size_t plen; |
| 502 | size_t tlen; |
| 503 | int error = 0; |
Joe Eykholt | 795d86f | 2009-08-25 14:00:39 -0700 | [diff] [blame] | 504 | struct fc_rport_identifiers ids; |
Joe Eykholt | ab28f1f | 2009-08-25 14:00:34 -0700 | [diff] [blame] | 505 | struct fc_rport_priv *rdata; |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 506 | |
| 507 | lport = disc->lport; |
| 508 | |
| 509 | /* |
| 510 | * Handle partial name record left over from previous call. |
| 511 | */ |
| 512 | bp = buf; |
| 513 | plen = len; |
| 514 | np = (struct fc_gpn_ft_resp *)bp; |
| 515 | tlen = disc->buf_len; |
| 516 | if (tlen) { |
| 517 | WARN_ON(tlen >= sizeof(*np)); |
| 518 | plen = sizeof(*np) - tlen; |
| 519 | WARN_ON(plen <= 0); |
| 520 | WARN_ON(plen >= sizeof(*np)); |
| 521 | if (plen > len) |
| 522 | plen = len; |
| 523 | np = &disc->partial_buf; |
| 524 | memcpy((char *)np + tlen, bp, plen); |
| 525 | |
| 526 | /* |
| 527 | * Set bp so that the loop below will advance it to the |
| 528 | * first valid full name element. |
| 529 | */ |
| 530 | bp -= tlen; |
| 531 | len += tlen; |
| 532 | plen += tlen; |
| 533 | disc->buf_len = (unsigned char) plen; |
| 534 | if (plen == sizeof(*np)) |
| 535 | disc->buf_len = 0; |
| 536 | } |
| 537 | |
| 538 | /* |
| 539 | * Handle full name records, including the one filled from above. |
| 540 | * Normally, np == bp and plen == len, but from the partial case above, |
| 541 | * bp, len describe the overall buffer, and np, plen describe the |
| 542 | * partial buffer, which if would usually be full now. |
| 543 | * After the first time through the loop, things return to "normal". |
| 544 | */ |
| 545 | while (plen >= sizeof(*np)) { |
Joe Eykholt | 795d86f | 2009-08-25 14:00:39 -0700 | [diff] [blame] | 546 | ids.port_id = ntoh24(np->fp_fid); |
| 547 | ids.port_name = ntohll(np->fp_wwpn); |
| 548 | ids.node_name = -1; |
| 549 | ids.roles = FC_RPORT_ROLE_UNKNOWN; |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 550 | |
Joe Eykholt | 795d86f | 2009-08-25 14:00:39 -0700 | [diff] [blame] | 551 | if (ids.port_id != fc_host_port_id(lport->host) && |
| 552 | ids.port_name != lport->wwpn) { |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame] | 553 | rdata = lport->tt.rport_create(lport, &ids); |
| 554 | if (rdata) { |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 555 | rdata->ops = &fc_disc_rport_ops; |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame] | 556 | lport->tt.rport_login(rdata); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 557 | } else |
Robert Love | 7414705 | 2009-06-10 15:31:10 -0700 | [diff] [blame] | 558 | printk(KERN_WARNING "libfc: Failed to allocate " |
| 559 | "memory for the newly discovered port " |
Joe Eykholt | 795d86f | 2009-08-25 14:00:39 -0700 | [diff] [blame] | 560 | "(%6x)\n", ids.port_id); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 561 | } |
| 562 | |
| 563 | if (np->fp_flags & FC_NS_FID_LAST) { |
Joe Eykholt | 786681b | 2009-08-25 14:01:29 -0700 | [diff] [blame] | 564 | fc_disc_done(disc, DISC_EV_SUCCESS); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 565 | len = 0; |
| 566 | break; |
| 567 | } |
| 568 | len -= sizeof(*np); |
| 569 | bp += sizeof(*np); |
| 570 | np = (struct fc_gpn_ft_resp *)bp; |
| 571 | plen = len; |
| 572 | } |
| 573 | |
| 574 | /* |
| 575 | * Save any partial record at the end of the buffer for next time. |
| 576 | */ |
| 577 | if (error == 0 && len > 0 && len < sizeof(*np)) { |
| 578 | if (np != &disc->partial_buf) { |
Robert Love | 7414705 | 2009-06-10 15:31:10 -0700 | [diff] [blame] | 579 | FC_DISC_DBG(disc, "Partial buffer remains " |
| 580 | "for discovery\n"); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 581 | memcpy(&disc->partial_buf, np, len); |
| 582 | } |
| 583 | disc->buf_len = (unsigned char) len; |
| 584 | } else { |
| 585 | disc->buf_len = 0; |
| 586 | } |
| 587 | return error; |
| 588 | } |
| 589 | |
Robert Love | 34f42a0 | 2009-02-27 10:55:45 -0800 | [diff] [blame] | 590 | /** |
| 591 | * fc_disc_timeout() - Retry handler for the disc component |
| 592 | * @work: Structure holding disc obj that needs retry discovery |
| 593 | * |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 594 | * Handle retry of memory allocation for remote ports. |
| 595 | */ |
| 596 | static void fc_disc_timeout(struct work_struct *work) |
| 597 | { |
| 598 | struct fc_disc *disc = container_of(work, |
| 599 | struct fc_disc, |
| 600 | disc_work.work); |
| 601 | mutex_lock(&disc->disc_mutex); |
| 602 | if (disc->requested && !disc->pending) |
| 603 | fc_disc_gpn_ft_req(disc); |
| 604 | mutex_unlock(&disc->disc_mutex); |
| 605 | } |
| 606 | |
| 607 | /** |
Robert Love | 34f42a0 | 2009-02-27 10:55:45 -0800 | [diff] [blame] | 608 | * fc_disc_gpn_ft_resp() - Handle a response frame from Get Port Names (GPN_FT) |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 609 | * @sp: Current sequence of GPN_FT exchange |
| 610 | * @fp: response frame |
| 611 | * @lp_arg: Fibre Channel host port instance |
| 612 | * |
Abhijeet Joglekar | 0d228c0 | 2009-04-21 16:26:52 -0700 | [diff] [blame] | 613 | * Locking Note: This function is called without disc mutex held, and |
| 614 | * should do all its processing with the mutex held |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 615 | */ |
| 616 | static void fc_disc_gpn_ft_resp(struct fc_seq *sp, struct fc_frame *fp, |
| 617 | void *disc_arg) |
| 618 | { |
| 619 | struct fc_disc *disc = disc_arg; |
| 620 | struct fc_ct_hdr *cp; |
| 621 | struct fc_frame_header *fh; |
| 622 | unsigned int seq_cnt; |
| 623 | void *buf = NULL; |
| 624 | unsigned int len; |
| 625 | int error; |
| 626 | |
Abhijeet Joglekar | 0d228c0 | 2009-04-21 16:26:52 -0700 | [diff] [blame] | 627 | mutex_lock(&disc->disc_mutex); |
Robert Love | 7414705 | 2009-06-10 15:31:10 -0700 | [diff] [blame] | 628 | FC_DISC_DBG(disc, "Received a GPN_FT response\n"); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 629 | |
| 630 | if (IS_ERR(fp)) { |
| 631 | fc_disc_error(disc, fp); |
Abhijeet Joglekar | 0d228c0 | 2009-04-21 16:26:52 -0700 | [diff] [blame] | 632 | mutex_unlock(&disc->disc_mutex); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 633 | return; |
| 634 | } |
| 635 | |
| 636 | WARN_ON(!fc_frame_is_linear(fp)); /* buffer must be contiguous */ |
| 637 | fh = fc_frame_header_get(fp); |
| 638 | len = fr_len(fp) - sizeof(*fh); |
| 639 | seq_cnt = ntohs(fh->fh_seq_cnt); |
| 640 | if (fr_sof(fp) == FC_SOF_I3 && seq_cnt == 0 && |
| 641 | disc->seq_count == 0) { |
| 642 | cp = fc_frame_payload_get(fp, sizeof(*cp)); |
| 643 | if (!cp) { |
Robert Love | 7414705 | 2009-06-10 15:31:10 -0700 | [diff] [blame] | 644 | FC_DISC_DBG(disc, "GPN_FT response too short, len %d\n", |
| 645 | fr_len(fp)); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 646 | } else if (ntohs(cp->ct_cmd) == FC_FS_ACC) { |
| 647 | |
Robert Love | 34f42a0 | 2009-02-27 10:55:45 -0800 | [diff] [blame] | 648 | /* Accepted, parse the response. */ |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 649 | buf = cp + 1; |
| 650 | len -= sizeof(*cp); |
| 651 | } else if (ntohs(cp->ct_cmd) == FC_FS_RJT) { |
Robert Love | 7414705 | 2009-06-10 15:31:10 -0700 | [diff] [blame] | 652 | FC_DISC_DBG(disc, "GPN_FT rejected reason %x exp %x " |
| 653 | "(check zoning)\n", cp->ct_reason, |
| 654 | cp->ct_explan); |
Joe Eykholt | 786681b | 2009-08-25 14:01:29 -0700 | [diff] [blame] | 655 | fc_disc_done(disc, DISC_EV_FAILED); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 656 | } else { |
Robert Love | 7414705 | 2009-06-10 15:31:10 -0700 | [diff] [blame] | 657 | FC_DISC_DBG(disc, "GPN_FT unexpected response code " |
| 658 | "%x\n", ntohs(cp->ct_cmd)); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 659 | } |
| 660 | } else if (fr_sof(fp) == FC_SOF_N3 && |
| 661 | seq_cnt == disc->seq_count) { |
| 662 | buf = fh + 1; |
| 663 | } else { |
Robert Love | 7414705 | 2009-06-10 15:31:10 -0700 | [diff] [blame] | 664 | FC_DISC_DBG(disc, "GPN_FT unexpected frame - out of sequence? " |
| 665 | "seq_cnt %x expected %x sof %x eof %x\n", |
| 666 | seq_cnt, disc->seq_count, fr_sof(fp), fr_eof(fp)); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 667 | } |
| 668 | if (buf) { |
| 669 | error = fc_disc_gpn_ft_parse(disc, buf, len); |
| 670 | if (error) |
| 671 | fc_disc_error(disc, fp); |
| 672 | else |
| 673 | disc->seq_count++; |
| 674 | } |
| 675 | fc_frame_free(fp); |
Abhijeet Joglekar | 0d228c0 | 2009-04-21 16:26:52 -0700 | [diff] [blame] | 676 | |
| 677 | mutex_unlock(&disc->disc_mutex); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 678 | } |
| 679 | |
| 680 | /** |
Robert Love | 34f42a0 | 2009-02-27 10:55:45 -0800 | [diff] [blame] | 681 | * fc_disc_single() - Discover the directory information for a single target |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 682 | * @lport: FC local port |
| 683 | * @dp: The port to rediscover |
| 684 | * |
| 685 | * Locking Note: This function expects that the disc_mutex is locked |
| 686 | * before it is called. |
| 687 | */ |
| 688 | static void fc_disc_single(struct fc_disc *disc, struct fc_disc_port *dp) |
| 689 | { |
| 690 | struct fc_lport *lport; |
Joe Eykholt | ab28f1f | 2009-08-25 14:00:34 -0700 | [diff] [blame] | 691 | struct fc_rport_priv *rdata; |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 692 | |
| 693 | lport = disc->lport; |
| 694 | |
| 695 | if (dp->ids.port_id == fc_host_port_id(lport->host)) |
| 696 | goto out; |
| 697 | |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame] | 698 | rdata = lport->tt.rport_create(lport, &dp->ids); |
| 699 | if (rdata) { |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 700 | rdata->ops = &fc_disc_rport_ops; |
| 701 | kfree(dp); |
Joe Eykholt | 9fb9d32 | 2009-08-25 14:00:50 -0700 | [diff] [blame] | 702 | lport->tt.rport_login(rdata); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 703 | } |
| 704 | return; |
| 705 | out: |
| 706 | kfree(dp); |
| 707 | } |
| 708 | |
| 709 | /** |
Robert Love | 34f42a0 | 2009-02-27 10:55:45 -0800 | [diff] [blame] | 710 | * fc_disc_stop() - Stop discovery for a given lport |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 711 | * @lport: The lport that discovery should stop for |
| 712 | */ |
| 713 | void fc_disc_stop(struct fc_lport *lport) |
| 714 | { |
| 715 | struct fc_disc *disc = &lport->disc; |
| 716 | |
| 717 | if (disc) { |
| 718 | cancel_delayed_work_sync(&disc->disc_work); |
| 719 | fc_disc_stop_rports(disc); |
| 720 | } |
| 721 | } |
| 722 | |
| 723 | /** |
Robert Love | 34f42a0 | 2009-02-27 10:55:45 -0800 | [diff] [blame] | 724 | * fc_disc_stop_final() - Stop discovery for a given lport |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 725 | * @lport: The lport that discovery should stop for |
| 726 | * |
| 727 | * This function will block until discovery has been |
| 728 | * completely stopped and all rports have been deleted. |
| 729 | */ |
| 730 | void fc_disc_stop_final(struct fc_lport *lport) |
| 731 | { |
| 732 | fc_disc_stop(lport); |
| 733 | lport->tt.rport_flush_queue(); |
| 734 | } |
| 735 | |
| 736 | /** |
Robert Love | 34f42a0 | 2009-02-27 10:55:45 -0800 | [diff] [blame] | 737 | * fc_disc_init() - Initialize the discovery block |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 738 | * @lport: FC local port |
| 739 | */ |
| 740 | int fc_disc_init(struct fc_lport *lport) |
| 741 | { |
| 742 | struct fc_disc *disc; |
| 743 | |
| 744 | if (!lport->tt.disc_start) |
| 745 | lport->tt.disc_start = fc_disc_start; |
| 746 | |
| 747 | if (!lport->tt.disc_stop) |
| 748 | lport->tt.disc_stop = fc_disc_stop; |
| 749 | |
| 750 | if (!lport->tt.disc_stop_final) |
| 751 | lport->tt.disc_stop_final = fc_disc_stop_final; |
| 752 | |
| 753 | if (!lport->tt.disc_recv_req) |
| 754 | lport->tt.disc_recv_req = fc_disc_recv_req; |
| 755 | |
| 756 | if (!lport->tt.rport_lookup) |
| 757 | lport->tt.rport_lookup = fc_disc_lookup_rport; |
| 758 | |
| 759 | disc = &lport->disc; |
| 760 | INIT_DELAYED_WORK(&disc->disc_work, fc_disc_timeout); |
| 761 | mutex_init(&disc->disc_mutex); |
| 762 | INIT_LIST_HEAD(&disc->rports); |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 763 | |
| 764 | disc->lport = lport; |
Robert Love | 42e9a92 | 2008-12-09 15:10:17 -0800 | [diff] [blame] | 765 | |
| 766 | return 0; |
| 767 | } |
| 768 | EXPORT_SYMBOL(fc_disc_init); |