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