Vasu Dev | 9b34ecf | 2009-03-17 11:42:13 -0700 | [diff] [blame] | 1 | /* |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 2 | * Copyright (c) 2008-2009 Cisco Systems, Inc. All rights reserved. |
| 3 | * Copyright (c) 2009 Intel Corporation. All rights reserved. |
Vasu Dev | 9b34ecf | 2009-03-17 11:42:13 -0700 | [diff] [blame] | 4 | * |
| 5 | * This program is free software; you can redistribute it and/or modify it |
| 6 | * under the terms and conditions of the GNU General Public License, |
| 7 | * version 2, as published by the Free Software Foundation. |
| 8 | * |
| 9 | * This program is distributed in the hope it will be useful, but WITHOUT |
| 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
| 12 | * more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU General Public License along with |
| 15 | * this program; if not, write to the Free Software Foundation, Inc., |
| 16 | * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA. |
| 17 | * |
| 18 | * Maintained at www.Open-FCoE.org |
| 19 | */ |
| 20 | |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 21 | #include <linux/types.h> |
Vasu Dev | 9b34ecf | 2009-03-17 11:42:13 -0700 | [diff] [blame] | 22 | #include <linux/module.h> |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 23 | #include <linux/kernel.h> |
| 24 | #include <linux/list.h> |
| 25 | #include <linux/spinlock.h> |
| 26 | #include <linux/timer.h> |
Vasu Dev | 5e80f7f | 2009-03-17 11:42:18 -0700 | [diff] [blame] | 27 | #include <linux/netdevice.h> |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 28 | #include <linux/etherdevice.h> |
| 29 | #include <linux/ethtool.h> |
| 30 | #include <linux/if_ether.h> |
| 31 | #include <linux/if_vlan.h> |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 32 | #include <linux/errno.h> |
| 33 | #include <linux/bitops.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 34 | #include <linux/slab.h> |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 35 | #include <net/rtnetlink.h> |
| 36 | |
| 37 | #include <scsi/fc/fc_els.h> |
| 38 | #include <scsi/fc/fc_fs.h> |
| 39 | #include <scsi/fc/fc_fip.h> |
| 40 | #include <scsi/fc/fc_encaps.h> |
| 41 | #include <scsi/fc/fc_fcoe.h> |
Vasu Dev | 5e80f7f | 2009-03-17 11:42:18 -0700 | [diff] [blame] | 42 | |
| 43 | #include <scsi/libfc.h> |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 44 | #include <scsi/libfcoe.h> |
Vasu Dev | 9b34ecf | 2009-03-17 11:42:13 -0700 | [diff] [blame] | 45 | |
| 46 | MODULE_AUTHOR("Open-FCoE.org"); |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 47 | MODULE_DESCRIPTION("FIP discovery protocol support for FCoE HBAs"); |
Vasu Dev | 9b34ecf | 2009-03-17 11:42:13 -0700 | [diff] [blame] | 48 | MODULE_LICENSE("GPL v2"); |
Vasu Dev | 5e80f7f | 2009-03-17 11:42:18 -0700 | [diff] [blame] | 49 | |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 50 | #define FCOE_CTLR_MIN_FKA 500 /* min keep alive (mS) */ |
| 51 | #define FCOE_CTLR_DEF_FKA FIP_DEF_FKA /* default keep alive (mS) */ |
| 52 | |
| 53 | static void fcoe_ctlr_timeout(unsigned long); |
Joe Eykholt | 4291365 | 2010-03-12 16:08:23 -0800 | [diff] [blame] | 54 | static void fcoe_ctlr_timer_work(struct work_struct *); |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 55 | static void fcoe_ctlr_recv_work(struct work_struct *); |
| 56 | |
| 57 | static u8 fcoe_all_fcfs[ETH_ALEN] = FIP_ALL_FCF_MACS; |
| 58 | |
Robert Love | 650bd12 | 2009-06-10 15:31:05 -0700 | [diff] [blame] | 59 | unsigned int libfcoe_debug_logging; |
| 60 | module_param_named(debug_logging, libfcoe_debug_logging, int, S_IRUGO|S_IWUSR); |
| 61 | MODULE_PARM_DESC(debug_logging, "a bit mask of logging levels"); |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 62 | |
Robert Love | 70b51aa | 2009-11-03 11:47:45 -0800 | [diff] [blame] | 63 | #define LIBFCOE_LOGGING 0x01 /* General logging, not categorized */ |
Robert Love | 650bd12 | 2009-06-10 15:31:05 -0700 | [diff] [blame] | 64 | #define LIBFCOE_FIP_LOGGING 0x02 /* FIP logging */ |
| 65 | |
Robert Love | 70b51aa | 2009-11-03 11:47:45 -0800 | [diff] [blame] | 66 | #define LIBFCOE_CHECK_LOGGING(LEVEL, CMD) \ |
| 67 | do { \ |
| 68 | if (unlikely(libfcoe_debug_logging & LEVEL)) \ |
| 69 | do { \ |
| 70 | CMD; \ |
| 71 | } while (0); \ |
Joe Eykholt | a69b06b | 2009-08-25 13:58:42 -0700 | [diff] [blame] | 72 | } while (0) |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 73 | |
Robert Love | 650bd12 | 2009-06-10 15:31:05 -0700 | [diff] [blame] | 74 | #define LIBFCOE_DBG(fmt, args...) \ |
| 75 | LIBFCOE_CHECK_LOGGING(LIBFCOE_LOGGING, \ |
| 76 | printk(KERN_INFO "libfcoe: " fmt, ##args);) |
| 77 | |
Joe Eykholt | 0f51c2e | 2009-11-03 11:48:16 -0800 | [diff] [blame] | 78 | #define LIBFCOE_FIP_DBG(fip, fmt, args...) \ |
Robert Love | 650bd12 | 2009-06-10 15:31:05 -0700 | [diff] [blame] | 79 | LIBFCOE_CHECK_LOGGING(LIBFCOE_FIP_LOGGING, \ |
Joe Eykholt | 0f51c2e | 2009-11-03 11:48:16 -0800 | [diff] [blame] | 80 | printk(KERN_INFO "host%d: fip: " fmt, \ |
| 81 | (fip)->lp->host->host_no, ##args);) |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 82 | |
Joe Eykholt | 9b651da | 2010-07-20 15:20:24 -0700 | [diff] [blame^] | 83 | static const char *fcoe_ctlr_states[] = { |
| 84 | [FIP_ST_DISABLED] = "DISABLED", |
| 85 | [FIP_ST_LINK_WAIT] = "LINK_WAIT", |
| 86 | [FIP_ST_AUTO] = "AUTO", |
| 87 | [FIP_ST_NON_FIP] = "NON_FIP", |
| 88 | [FIP_ST_ENABLED] = "ENABLED", |
| 89 | }; |
| 90 | |
| 91 | static const char *fcoe_ctlr_state(enum fip_state state) |
| 92 | { |
| 93 | const char *cp = "unknown"; |
| 94 | |
| 95 | if (state < ARRAY_SIZE(fcoe_ctlr_states)) |
| 96 | cp = fcoe_ctlr_states[state]; |
| 97 | if (!cp) |
| 98 | cp = "unknown"; |
| 99 | return cp; |
| 100 | } |
| 101 | |
| 102 | /** |
| 103 | * fcoe_ctlr_set_state() - Set and do debug printing for the new FIP state. |
| 104 | * @fip: The FCoE controller |
| 105 | * @state: The new state |
| 106 | */ |
| 107 | static void fcoe_ctlr_set_state(struct fcoe_ctlr *fip, enum fip_state state) |
| 108 | { |
| 109 | if (state == fip->state) |
| 110 | return; |
| 111 | if (fip->lp) |
| 112 | LIBFCOE_FIP_DBG(fip, "state %s -> %s\n", |
| 113 | fcoe_ctlr_state(fip->state), fcoe_ctlr_state(state)); |
| 114 | fip->state = state; |
| 115 | } |
| 116 | |
Robert Love | 70b51aa | 2009-11-03 11:47:45 -0800 | [diff] [blame] | 117 | /** |
| 118 | * fcoe_ctlr_mtu_valid() - Check if a FCF's MTU is valid |
| 119 | * @fcf: The FCF to check |
| 120 | * |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 121 | * Return non-zero if FCF fcoe_size has been validated. |
| 122 | */ |
| 123 | static inline int fcoe_ctlr_mtu_valid(const struct fcoe_fcf *fcf) |
| 124 | { |
| 125 | return (fcf->flags & FIP_FL_SOL) != 0; |
| 126 | } |
| 127 | |
Robert Love | 70b51aa | 2009-11-03 11:47:45 -0800 | [diff] [blame] | 128 | /** |
| 129 | * fcoe_ctlr_fcf_usable() - Check if a FCF is usable |
| 130 | * @fcf: The FCF to check |
| 131 | * |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 132 | * Return non-zero if the FCF is usable. |
| 133 | */ |
| 134 | static inline int fcoe_ctlr_fcf_usable(struct fcoe_fcf *fcf) |
| 135 | { |
| 136 | u16 flags = FIP_FL_SOL | FIP_FL_AVAIL; |
| 137 | |
| 138 | return (fcf->flags & flags) == flags; |
| 139 | } |
| 140 | |
| 141 | /** |
Robert Love | 70b51aa | 2009-11-03 11:47:45 -0800 | [diff] [blame] | 142 | * fcoe_ctlr_init() - Initialize the FCoE Controller instance |
| 143 | * @fip: The FCoE controller to initialize |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 144 | */ |
Joe Eykholt | 3d902ac | 2010-07-20 15:19:58 -0700 | [diff] [blame] | 145 | void fcoe_ctlr_init(struct fcoe_ctlr *fip, enum fip_state mode) |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 146 | { |
Joe Eykholt | 9b651da | 2010-07-20 15:20:24 -0700 | [diff] [blame^] | 147 | fcoe_ctlr_set_state(fip, FIP_ST_LINK_WAIT); |
Joe Eykholt | 3d902ac | 2010-07-20 15:19:58 -0700 | [diff] [blame] | 148 | fip->mode = mode; |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 149 | INIT_LIST_HEAD(&fip->fcfs); |
Joe Eykholt | fdb068c | 2010-07-20 15:19:47 -0700 | [diff] [blame] | 150 | mutex_init(&fip->ctlr_mutex); |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 151 | fip->flogi_oxid = FC_XID_UNKNOWN; |
| 152 | setup_timer(&fip->timer, fcoe_ctlr_timeout, (unsigned long)fip); |
Joe Eykholt | 4291365 | 2010-03-12 16:08:23 -0800 | [diff] [blame] | 153 | INIT_WORK(&fip->timer_work, fcoe_ctlr_timer_work); |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 154 | INIT_WORK(&fip->recv_work, fcoe_ctlr_recv_work); |
| 155 | skb_queue_head_init(&fip->fip_recv_list); |
| 156 | } |
| 157 | EXPORT_SYMBOL(fcoe_ctlr_init); |
| 158 | |
| 159 | /** |
Robert Love | 70b51aa | 2009-11-03 11:47:45 -0800 | [diff] [blame] | 160 | * fcoe_ctlr_reset_fcfs() - Reset and free all FCFs for a controller |
| 161 | * @fip: The FCoE controller whose FCFs are to be reset |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 162 | * |
| 163 | * Called with &fcoe_ctlr lock held. |
| 164 | */ |
| 165 | static void fcoe_ctlr_reset_fcfs(struct fcoe_ctlr *fip) |
| 166 | { |
| 167 | struct fcoe_fcf *fcf; |
| 168 | struct fcoe_fcf *next; |
| 169 | |
| 170 | fip->sel_fcf = NULL; |
| 171 | list_for_each_entry_safe(fcf, next, &fip->fcfs, list) { |
| 172 | list_del(&fcf->list); |
| 173 | kfree(fcf); |
| 174 | } |
| 175 | fip->fcf_count = 0; |
| 176 | fip->sel_time = 0; |
| 177 | } |
| 178 | |
| 179 | /** |
Robert Love | 70b51aa | 2009-11-03 11:47:45 -0800 | [diff] [blame] | 180 | * fcoe_ctlr_destroy() - Disable and tear down a FCoE controller |
| 181 | * @fip: The FCoE controller to tear down |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 182 | * |
| 183 | * This is called by FCoE drivers before freeing the &fcoe_ctlr. |
| 184 | * |
| 185 | * The receive handler will have been deleted before this to guarantee |
| 186 | * that no more recv_work will be scheduled. |
| 187 | * |
| 188 | * The timer routine will simply return once we set FIP_ST_DISABLED. |
| 189 | * This guarantees that no further timeouts or work will be scheduled. |
| 190 | */ |
| 191 | void fcoe_ctlr_destroy(struct fcoe_ctlr *fip) |
| 192 | { |
Chris Leech | a4b7cfa | 2009-08-25 13:59:08 -0700 | [diff] [blame] | 193 | cancel_work_sync(&fip->recv_work); |
Joe Eykholt | 1f4aed8 | 2009-11-03 11:48:22 -0800 | [diff] [blame] | 194 | skb_queue_purge(&fip->fip_recv_list); |
Chris Leech | a4b7cfa | 2009-08-25 13:59:08 -0700 | [diff] [blame] | 195 | |
Joe Eykholt | fdb068c | 2010-07-20 15:19:47 -0700 | [diff] [blame] | 196 | mutex_lock(&fip->ctlr_mutex); |
Joe Eykholt | 9b651da | 2010-07-20 15:20:24 -0700 | [diff] [blame^] | 197 | fcoe_ctlr_set_state(fip, FIP_ST_DISABLED); |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 198 | fcoe_ctlr_reset_fcfs(fip); |
Joe Eykholt | fdb068c | 2010-07-20 15:19:47 -0700 | [diff] [blame] | 199 | mutex_unlock(&fip->ctlr_mutex); |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 200 | del_timer_sync(&fip->timer); |
Joe Eykholt | 4291365 | 2010-03-12 16:08:23 -0800 | [diff] [blame] | 201 | cancel_work_sync(&fip->timer_work); |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 202 | } |
| 203 | EXPORT_SYMBOL(fcoe_ctlr_destroy); |
| 204 | |
| 205 | /** |
Robert Love | 70b51aa | 2009-11-03 11:47:45 -0800 | [diff] [blame] | 206 | * fcoe_ctlr_fcoe_size() - Return the maximum FCoE size required for VN_Port |
| 207 | * @fip: The FCoE controller to get the maximum FCoE size from |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 208 | * |
| 209 | * Returns the maximum packet size including the FCoE header and trailer, |
| 210 | * but not including any Ethernet or VLAN headers. |
| 211 | */ |
| 212 | static inline u32 fcoe_ctlr_fcoe_size(struct fcoe_ctlr *fip) |
| 213 | { |
| 214 | /* |
| 215 | * Determine the max FCoE frame size allowed, including |
| 216 | * FCoE header and trailer. |
| 217 | * Note: lp->mfs is currently the payload size, not the frame size. |
| 218 | */ |
| 219 | return fip->lp->mfs + sizeof(struct fc_frame_header) + |
| 220 | sizeof(struct fcoe_hdr) + sizeof(struct fcoe_crc_eof); |
| 221 | } |
| 222 | |
| 223 | /** |
Robert Love | 70b51aa | 2009-11-03 11:47:45 -0800 | [diff] [blame] | 224 | * fcoe_ctlr_solicit() - Send a FIP solicitation |
| 225 | * @fip: The FCoE controller to send the solicitation on |
| 226 | * @fcf: The destination FCF (if NULL, a multicast solicitation is sent) |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 227 | */ |
| 228 | static void fcoe_ctlr_solicit(struct fcoe_ctlr *fip, struct fcoe_fcf *fcf) |
| 229 | { |
| 230 | struct sk_buff *skb; |
| 231 | struct fip_sol { |
| 232 | struct ethhdr eth; |
| 233 | struct fip_header fip; |
| 234 | struct { |
| 235 | struct fip_mac_desc mac; |
| 236 | struct fip_wwn_desc wwnn; |
| 237 | struct fip_size_desc size; |
| 238 | } __attribute__((packed)) desc; |
| 239 | } __attribute__((packed)) *sol; |
| 240 | u32 fcoe_size; |
| 241 | |
| 242 | skb = dev_alloc_skb(sizeof(*sol)); |
| 243 | if (!skb) |
| 244 | return; |
| 245 | |
| 246 | sol = (struct fip_sol *)skb->data; |
| 247 | |
| 248 | memset(sol, 0, sizeof(*sol)); |
| 249 | memcpy(sol->eth.h_dest, fcf ? fcf->fcf_mac : fcoe_all_fcfs, ETH_ALEN); |
| 250 | memcpy(sol->eth.h_source, fip->ctl_src_addr, ETH_ALEN); |
| 251 | sol->eth.h_proto = htons(ETH_P_FIP); |
| 252 | |
| 253 | sol->fip.fip_ver = FIP_VER_ENCAPS(FIP_VER); |
| 254 | sol->fip.fip_op = htons(FIP_OP_DISC); |
| 255 | sol->fip.fip_subcode = FIP_SC_SOL; |
| 256 | sol->fip.fip_dl_len = htons(sizeof(sol->desc) / FIP_BPW); |
| 257 | sol->fip.fip_flags = htons(FIP_FL_FPMA); |
Vasu Dev | 184dd34 | 2009-05-17 12:33:28 +0000 | [diff] [blame] | 258 | if (fip->spma) |
| 259 | sol->fip.fip_flags |= htons(FIP_FL_SPMA); |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 260 | |
| 261 | sol->desc.mac.fd_desc.fip_dtype = FIP_DT_MAC; |
| 262 | sol->desc.mac.fd_desc.fip_dlen = sizeof(sol->desc.mac) / FIP_BPW; |
| 263 | memcpy(sol->desc.mac.fd_mac, fip->ctl_src_addr, ETH_ALEN); |
| 264 | |
| 265 | sol->desc.wwnn.fd_desc.fip_dtype = FIP_DT_NAME; |
| 266 | sol->desc.wwnn.fd_desc.fip_dlen = sizeof(sol->desc.wwnn) / FIP_BPW; |
| 267 | put_unaligned_be64(fip->lp->wwnn, &sol->desc.wwnn.fd_wwn); |
| 268 | |
| 269 | fcoe_size = fcoe_ctlr_fcoe_size(fip); |
| 270 | sol->desc.size.fd_desc.fip_dtype = FIP_DT_FCOE_SIZE; |
| 271 | sol->desc.size.fd_desc.fip_dlen = sizeof(sol->desc.size) / FIP_BPW; |
| 272 | sol->desc.size.fd_size = htons(fcoe_size); |
| 273 | |
| 274 | skb_put(skb, sizeof(*sol)); |
Chris Leech | 0f49153 | 2009-05-06 10:52:18 -0700 | [diff] [blame] | 275 | skb->protocol = htons(ETH_P_FIP); |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 276 | skb_reset_mac_header(skb); |
| 277 | skb_reset_network_header(skb); |
| 278 | fip->send(fip, skb); |
| 279 | |
| 280 | if (!fcf) |
| 281 | fip->sol_time = jiffies; |
| 282 | } |
| 283 | |
| 284 | /** |
Robert Love | 70b51aa | 2009-11-03 11:47:45 -0800 | [diff] [blame] | 285 | * fcoe_ctlr_link_up() - Start FCoE controller |
| 286 | * @fip: The FCoE controller to start |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 287 | * |
| 288 | * Called from the LLD when the network link is ready. |
| 289 | */ |
| 290 | void fcoe_ctlr_link_up(struct fcoe_ctlr *fip) |
| 291 | { |
Joe Eykholt | fdb068c | 2010-07-20 15:19:47 -0700 | [diff] [blame] | 292 | mutex_lock(&fip->ctlr_mutex); |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 293 | if (fip->state == FIP_ST_NON_FIP || fip->state == FIP_ST_AUTO) { |
Joe Eykholt | fdb068c | 2010-07-20 15:19:47 -0700 | [diff] [blame] | 294 | mutex_unlock(&fip->ctlr_mutex); |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 295 | fc_linkup(fip->lp); |
| 296 | } else if (fip->state == FIP_ST_LINK_WAIT) { |
Joe Eykholt | 9b651da | 2010-07-20 15:20:24 -0700 | [diff] [blame^] | 297 | fcoe_ctlr_set_state(fip, fip->mode); |
Joe Eykholt | fdb068c | 2010-07-20 15:19:47 -0700 | [diff] [blame] | 298 | mutex_unlock(&fip->ctlr_mutex); |
Joe Eykholt | 22bcd22 | 2009-11-03 11:48:11 -0800 | [diff] [blame] | 299 | if (fip->state == FIP_ST_AUTO) |
Joe Eykholt | 0f51c2e | 2009-11-03 11:48:16 -0800 | [diff] [blame] | 300 | LIBFCOE_FIP_DBG(fip, "%s", "setting AUTO mode.\n"); |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 301 | fc_linkup(fip->lp); |
| 302 | fcoe_ctlr_solicit(fip, NULL); |
| 303 | } else |
Joe Eykholt | fdb068c | 2010-07-20 15:19:47 -0700 | [diff] [blame] | 304 | mutex_unlock(&fip->ctlr_mutex); |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 305 | } |
| 306 | EXPORT_SYMBOL(fcoe_ctlr_link_up); |
| 307 | |
| 308 | /** |
Robert Love | 70b51aa | 2009-11-03 11:47:45 -0800 | [diff] [blame] | 309 | * fcoe_ctlr_reset() - Reset a FCoE controller |
| 310 | * @fip: The FCoE controller to reset |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 311 | */ |
Joe Eykholt | dd42dac | 2009-11-03 11:48:27 -0800 | [diff] [blame] | 312 | static void fcoe_ctlr_reset(struct fcoe_ctlr *fip) |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 313 | { |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 314 | fcoe_ctlr_reset_fcfs(fip); |
| 315 | del_timer(&fip->timer); |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 316 | fip->ctlr_ka_time = 0; |
| 317 | fip->port_ka_time = 0; |
| 318 | fip->sol_time = 0; |
| 319 | fip->flogi_oxid = FC_XID_UNKNOWN; |
| 320 | fip->map_dest = 0; |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 321 | } |
| 322 | |
| 323 | /** |
Robert Love | 70b51aa | 2009-11-03 11:47:45 -0800 | [diff] [blame] | 324 | * fcoe_ctlr_link_down() - Stop a FCoE controller |
| 325 | * @fip: The FCoE controller to be stopped |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 326 | * |
| 327 | * Returns non-zero if the link was up and now isn't. |
| 328 | * |
| 329 | * Called from the LLD when the network link is not ready. |
| 330 | * There may be multiple calls while the link is down. |
| 331 | */ |
| 332 | int fcoe_ctlr_link_down(struct fcoe_ctlr *fip) |
| 333 | { |
Joe Eykholt | dd42dac | 2009-11-03 11:48:27 -0800 | [diff] [blame] | 334 | int link_dropped; |
| 335 | |
| 336 | LIBFCOE_FIP_DBG(fip, "link down.\n"); |
Joe Eykholt | fdb068c | 2010-07-20 15:19:47 -0700 | [diff] [blame] | 337 | mutex_lock(&fip->ctlr_mutex); |
Joe Eykholt | dd42dac | 2009-11-03 11:48:27 -0800 | [diff] [blame] | 338 | fcoe_ctlr_reset(fip); |
Joe Eykholt | 4291365 | 2010-03-12 16:08:23 -0800 | [diff] [blame] | 339 | link_dropped = fip->state != FIP_ST_LINK_WAIT; |
Joe Eykholt | 9b651da | 2010-07-20 15:20:24 -0700 | [diff] [blame^] | 340 | fcoe_ctlr_set_state(fip, FIP_ST_LINK_WAIT); |
Joe Eykholt | fdb068c | 2010-07-20 15:19:47 -0700 | [diff] [blame] | 341 | mutex_unlock(&fip->ctlr_mutex); |
Joe Eykholt | dd42dac | 2009-11-03 11:48:27 -0800 | [diff] [blame] | 342 | |
| 343 | if (link_dropped) |
| 344 | fc_linkdown(fip->lp); |
| 345 | return link_dropped; |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 346 | } |
| 347 | EXPORT_SYMBOL(fcoe_ctlr_link_down); |
| 348 | |
| 349 | /** |
Robert Love | 70b51aa | 2009-11-03 11:47:45 -0800 | [diff] [blame] | 350 | * fcoe_ctlr_send_keep_alive() - Send a keep-alive to the selected FCF |
| 351 | * @fip: The FCoE controller to send the FKA on |
| 352 | * @lport: libfc fc_lport to send from |
| 353 | * @ports: 0 for controller keep-alive, 1 for port keep-alive |
| 354 | * @sa: The source MAC address |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 355 | * |
| 356 | * A controller keep-alive is sent every fka_period (typically 8 seconds). |
| 357 | * The source MAC is the native MAC address. |
| 358 | * |
| 359 | * A port keep-alive is sent every 90 seconds while logged in. |
| 360 | * The source MAC is the assigned mapped source address. |
| 361 | * The destination is the FCF's F-port. |
| 362 | */ |
Chris Leech | 11b5618 | 2009-11-03 11:46:29 -0800 | [diff] [blame] | 363 | static void fcoe_ctlr_send_keep_alive(struct fcoe_ctlr *fip, |
| 364 | struct fc_lport *lport, |
| 365 | int ports, u8 *sa) |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 366 | { |
| 367 | struct sk_buff *skb; |
| 368 | struct fip_kal { |
| 369 | struct ethhdr eth; |
| 370 | struct fip_header fip; |
| 371 | struct fip_mac_desc mac; |
| 372 | } __attribute__((packed)) *kal; |
| 373 | struct fip_vn_desc *vn; |
| 374 | u32 len; |
| 375 | struct fc_lport *lp; |
| 376 | struct fcoe_fcf *fcf; |
| 377 | |
| 378 | fcf = fip->sel_fcf; |
| 379 | lp = fip->lp; |
Joe Eykholt | 281ae64 | 2010-06-11 16:43:33 -0700 | [diff] [blame] | 380 | if (!fcf || (ports && !lp->port_id)) |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 381 | return; |
| 382 | |
Yi Zou | be276cb | 2009-11-03 11:50:16 -0800 | [diff] [blame] | 383 | len = sizeof(*kal) + ports * sizeof(*vn); |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 384 | skb = dev_alloc_skb(len); |
| 385 | if (!skb) |
| 386 | return; |
| 387 | |
| 388 | kal = (struct fip_kal *)skb->data; |
| 389 | memset(kal, 0, len); |
| 390 | memcpy(kal->eth.h_dest, fcf->fcf_mac, ETH_ALEN); |
| 391 | memcpy(kal->eth.h_source, sa, ETH_ALEN); |
| 392 | kal->eth.h_proto = htons(ETH_P_FIP); |
| 393 | |
| 394 | kal->fip.fip_ver = FIP_VER_ENCAPS(FIP_VER); |
| 395 | kal->fip.fip_op = htons(FIP_OP_CTRL); |
| 396 | kal->fip.fip_subcode = FIP_SC_KEEP_ALIVE; |
| 397 | kal->fip.fip_dl_len = htons((sizeof(kal->mac) + |
Robert Love | 70b51aa | 2009-11-03 11:47:45 -0800 | [diff] [blame] | 398 | ports * sizeof(*vn)) / FIP_BPW); |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 399 | kal->fip.fip_flags = htons(FIP_FL_FPMA); |
Vasu Dev | 184dd34 | 2009-05-17 12:33:28 +0000 | [diff] [blame] | 400 | if (fip->spma) |
| 401 | kal->fip.fip_flags |= htons(FIP_FL_SPMA); |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 402 | |
| 403 | kal->mac.fd_desc.fip_dtype = FIP_DT_MAC; |
| 404 | kal->mac.fd_desc.fip_dlen = sizeof(kal->mac) / FIP_BPW; |
| 405 | memcpy(kal->mac.fd_mac, fip->ctl_src_addr, ETH_ALEN); |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 406 | if (ports) { |
| 407 | vn = (struct fip_vn_desc *)(kal + 1); |
| 408 | vn->fd_desc.fip_dtype = FIP_DT_VN_ID; |
| 409 | vn->fd_desc.fip_dlen = sizeof(*vn) / FIP_BPW; |
Chris Leech | 11b5618 | 2009-11-03 11:46:29 -0800 | [diff] [blame] | 410 | memcpy(vn->fd_mac, fip->get_src_addr(lport), ETH_ALEN); |
Kaladhar Musunuru | fb83153 | 2010-05-07 15:18:57 -0700 | [diff] [blame] | 411 | hton24(vn->fd_fc_id, lport->port_id); |
| 412 | put_unaligned_be64(lport->wwpn, &vn->fd_wwpn); |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 413 | } |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 414 | skb_put(skb, len); |
Chris Leech | 0f49153 | 2009-05-06 10:52:18 -0700 | [diff] [blame] | 415 | skb->protocol = htons(ETH_P_FIP); |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 416 | skb_reset_mac_header(skb); |
| 417 | skb_reset_network_header(skb); |
| 418 | fip->send(fip, skb); |
| 419 | } |
| 420 | |
| 421 | /** |
Robert Love | 70b51aa | 2009-11-03 11:47:45 -0800 | [diff] [blame] | 422 | * fcoe_ctlr_encaps() - Encapsulate an ELS frame for FIP, without sending it |
| 423 | * @fip: The FCoE controller for the ELS frame |
| 424 | * @dtype: The FIP descriptor type for the frame |
| 425 | * @skb: The FCoE ELS frame including FC header but no FCoE headers |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 426 | * |
| 427 | * Returns non-zero error code on failure. |
| 428 | * |
| 429 | * The caller must check that the length is a multiple of 4. |
| 430 | * |
| 431 | * The @skb must have enough headroom (28 bytes) and tailroom (8 bytes). |
| 432 | * Headroom includes the FIP encapsulation description, FIP header, and |
| 433 | * Ethernet header. The tailroom is for the FIP MAC descriptor. |
| 434 | */ |
Chris Leech | 11b5618 | 2009-11-03 11:46:29 -0800 | [diff] [blame] | 435 | static int fcoe_ctlr_encaps(struct fcoe_ctlr *fip, struct fc_lport *lport, |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 436 | u8 dtype, struct sk_buff *skb) |
| 437 | { |
| 438 | struct fip_encaps_head { |
| 439 | struct ethhdr eth; |
| 440 | struct fip_header fip; |
| 441 | struct fip_encaps encaps; |
| 442 | } __attribute__((packed)) *cap; |
| 443 | struct fip_mac_desc *mac; |
| 444 | struct fcoe_fcf *fcf; |
| 445 | size_t dlen; |
Yi Zou | 5a84bae | 2009-07-29 17:03:55 -0700 | [diff] [blame] | 446 | u16 fip_flags; |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 447 | |
| 448 | fcf = fip->sel_fcf; |
| 449 | if (!fcf) |
| 450 | return -ENODEV; |
Yi Zou | 5a84bae | 2009-07-29 17:03:55 -0700 | [diff] [blame] | 451 | |
| 452 | /* set flags according to both FCF and lport's capability on SPMA */ |
| 453 | fip_flags = fcf->flags; |
| 454 | fip_flags &= fip->spma ? FIP_FL_SPMA | FIP_FL_FPMA : FIP_FL_FPMA; |
| 455 | if (!fip_flags) |
| 456 | return -ENODEV; |
| 457 | |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 458 | dlen = sizeof(struct fip_encaps) + skb->len; /* len before push */ |
| 459 | cap = (struct fip_encaps_head *)skb_push(skb, sizeof(*cap)); |
| 460 | |
| 461 | memset(cap, 0, sizeof(*cap)); |
| 462 | memcpy(cap->eth.h_dest, fcf->fcf_mac, ETH_ALEN); |
| 463 | memcpy(cap->eth.h_source, fip->ctl_src_addr, ETH_ALEN); |
| 464 | cap->eth.h_proto = htons(ETH_P_FIP); |
| 465 | |
| 466 | cap->fip.fip_ver = FIP_VER_ENCAPS(FIP_VER); |
| 467 | cap->fip.fip_op = htons(FIP_OP_LS); |
| 468 | cap->fip.fip_subcode = FIP_SC_REQ; |
| 469 | cap->fip.fip_dl_len = htons((dlen + sizeof(*mac)) / FIP_BPW); |
Yi Zou | 5a84bae | 2009-07-29 17:03:55 -0700 | [diff] [blame] | 470 | cap->fip.fip_flags = htons(fip_flags); |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 471 | |
| 472 | cap->encaps.fd_desc.fip_dtype = dtype; |
| 473 | cap->encaps.fd_desc.fip_dlen = dlen / FIP_BPW; |
| 474 | |
| 475 | mac = (struct fip_mac_desc *)skb_put(skb, sizeof(*mac)); |
Kaladhar Musunuru | 8b889e4 | 2010-05-07 15:18:52 -0700 | [diff] [blame] | 476 | memset(mac, 0, sizeof(*mac)); |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 477 | mac->fd_desc.fip_dtype = FIP_DT_MAC; |
| 478 | mac->fd_desc.fip_dlen = sizeof(*mac) / FIP_BPW; |
Robert Love | 593abc0 | 2010-04-09 14:22:17 -0700 | [diff] [blame] | 479 | if (dtype != FIP_DT_FLOGI && dtype != FIP_DT_FDISC) { |
Chris Leech | 11b5618 | 2009-11-03 11:46:29 -0800 | [diff] [blame] | 480 | memcpy(mac->fd_mac, fip->get_src_addr(lport), ETH_ALEN); |
Robert Love | 593abc0 | 2010-04-09 14:22:17 -0700 | [diff] [blame] | 481 | } else if (fip_flags & FIP_FL_SPMA) { |
| 482 | LIBFCOE_FIP_DBG(fip, "FLOGI/FDISC sent with SPMA\n"); |
Vasu Dev | 184dd34 | 2009-05-17 12:33:28 +0000 | [diff] [blame] | 483 | memcpy(mac->fd_mac, fip->ctl_src_addr, ETH_ALEN); |
Robert Love | 593abc0 | 2010-04-09 14:22:17 -0700 | [diff] [blame] | 484 | } else { |
| 485 | LIBFCOE_FIP_DBG(fip, "FLOGI/FDISC sent with FPMA\n"); |
| 486 | /* FPMA only FLOGI must leave the MAC desc set to all 0s */ |
| 487 | } |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 488 | |
Chris Leech | 0f49153 | 2009-05-06 10:52:18 -0700 | [diff] [blame] | 489 | skb->protocol = htons(ETH_P_FIP); |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 490 | skb_reset_mac_header(skb); |
| 491 | skb_reset_network_header(skb); |
| 492 | return 0; |
| 493 | } |
| 494 | |
| 495 | /** |
| 496 | * fcoe_ctlr_els_send() - Send an ELS frame encapsulated by FIP if appropriate. |
| 497 | * @fip: FCoE controller. |
Chris Leech | 11b5618 | 2009-11-03 11:46:29 -0800 | [diff] [blame] | 498 | * @lport: libfc fc_lport to send from |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 499 | * @skb: FCoE ELS frame including FC header but no FCoE headers. |
| 500 | * |
| 501 | * Returns a non-zero error code if the frame should not be sent. |
| 502 | * Returns zero if the caller should send the frame with FCoE encapsulation. |
| 503 | * |
| 504 | * The caller must check that the length is a multiple of 4. |
| 505 | * The SKB must have enough headroom (28 bytes) and tailroom (8 bytes). |
| 506 | */ |
Chris Leech | 11b5618 | 2009-11-03 11:46:29 -0800 | [diff] [blame] | 507 | int fcoe_ctlr_els_send(struct fcoe_ctlr *fip, struct fc_lport *lport, |
| 508 | struct sk_buff *skb) |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 509 | { |
| 510 | struct fc_frame_header *fh; |
| 511 | u16 old_xid; |
| 512 | u8 op; |
Chris Leech | 11b5618 | 2009-11-03 11:46:29 -0800 | [diff] [blame] | 513 | u8 mac[ETH_ALEN]; |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 514 | |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 515 | fh = (struct fc_frame_header *)skb->data; |
| 516 | op = *(u8 *)(fh + 1); |
| 517 | |
Joe Eykholt | 5f48f70 | 2009-05-06 10:52:12 -0700 | [diff] [blame] | 518 | if (op == ELS_FLOGI) { |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 519 | old_xid = fip->flogi_oxid; |
| 520 | fip->flogi_oxid = ntohs(fh->fh_ox_id); |
| 521 | if (fip->state == FIP_ST_AUTO) { |
| 522 | if (old_xid == FC_XID_UNKNOWN) |
| 523 | fip->flogi_count = 0; |
| 524 | fip->flogi_count++; |
| 525 | if (fip->flogi_count < 3) |
| 526 | goto drop; |
| 527 | fip->map_dest = 1; |
| 528 | return 0; |
| 529 | } |
Joe Eykholt | 5f48f70 | 2009-05-06 10:52:12 -0700 | [diff] [blame] | 530 | if (fip->state == FIP_ST_NON_FIP) |
| 531 | fip->map_dest = 1; |
| 532 | } |
| 533 | |
| 534 | if (fip->state == FIP_ST_NON_FIP) |
| 535 | return 0; |
Joe Eykholt | f31f2a1 | 2009-11-03 11:48:32 -0800 | [diff] [blame] | 536 | if (!fip->sel_fcf) |
| 537 | goto drop; |
Joe Eykholt | 5f48f70 | 2009-05-06 10:52:12 -0700 | [diff] [blame] | 538 | |
| 539 | switch (op) { |
| 540 | case ELS_FLOGI: |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 541 | op = FIP_DT_FLOGI; |
| 542 | break; |
| 543 | case ELS_FDISC: |
| 544 | if (ntoh24(fh->fh_s_id)) |
| 545 | return 0; |
| 546 | op = FIP_DT_FDISC; |
| 547 | break; |
| 548 | case ELS_LOGO: |
| 549 | if (fip->state != FIP_ST_ENABLED) |
| 550 | return 0; |
| 551 | if (ntoh24(fh->fh_d_id) != FC_FID_FLOGI) |
| 552 | return 0; |
| 553 | op = FIP_DT_LOGO; |
| 554 | break; |
| 555 | case ELS_LS_ACC: |
| 556 | if (fip->flogi_oxid == FC_XID_UNKNOWN) |
| 557 | return 0; |
| 558 | if (!ntoh24(fh->fh_s_id)) |
| 559 | return 0; |
| 560 | if (fip->state == FIP_ST_AUTO) |
| 561 | return 0; |
| 562 | /* |
| 563 | * Here we must've gotten an SID by accepting an FLOGI |
| 564 | * from a point-to-point connection. Switch to using |
| 565 | * the source mac based on the SID. The destination |
| 566 | * MAC in this case would have been set by receving the |
| 567 | * FLOGI. |
| 568 | */ |
| 569 | fip->flogi_oxid = FC_XID_UNKNOWN; |
Chris Leech | 11b5618 | 2009-11-03 11:46:29 -0800 | [diff] [blame] | 570 | fc_fcoe_set_mac(mac, fh->fh_d_id); |
| 571 | fip->update_mac(lport, mac); |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 572 | return 0; |
| 573 | default: |
| 574 | if (fip->state != FIP_ST_ENABLED) |
| 575 | goto drop; |
| 576 | return 0; |
| 577 | } |
Chris Leech | 11b5618 | 2009-11-03 11:46:29 -0800 | [diff] [blame] | 578 | if (fcoe_ctlr_encaps(fip, lport, op, skb)) |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 579 | goto drop; |
| 580 | fip->send(fip, skb); |
| 581 | return -EINPROGRESS; |
| 582 | drop: |
| 583 | kfree_skb(skb); |
| 584 | return -EINVAL; |
| 585 | } |
| 586 | EXPORT_SYMBOL(fcoe_ctlr_els_send); |
| 587 | |
Robert Love | 70b51aa | 2009-11-03 11:47:45 -0800 | [diff] [blame] | 588 | /** |
| 589 | * fcoe_ctlr_age_fcfs() - Reset and free all old FCFs for a controller |
| 590 | * @fip: The FCoE controller to free FCFs on |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 591 | * |
Joe Eykholt | f018b73 | 2010-03-12 16:08:55 -0800 | [diff] [blame] | 592 | * Called with lock held and preemption disabled. |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 593 | * |
Joe Eykholt | 8690cb8 | 2010-06-11 16:44:10 -0700 | [diff] [blame] | 594 | * An FCF is considered old if we have missed two advertisements. |
| 595 | * That is, there have been no valid advertisement from it for 2.5 |
| 596 | * times its keep-alive period. |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 597 | * |
| 598 | * In addition, determine the time when an FCF selection can occur. |
Yi Zou | f3da80e | 2009-11-20 14:55:08 -0800 | [diff] [blame] | 599 | * |
| 600 | * Also, increment the MissDiscAdvCount when no advertisement is received |
| 601 | * for the corresponding FCF for 1.5 * FKA_ADV_PERIOD (FC-BB-5 LESB). |
Joe Eykholt | 8690cb8 | 2010-06-11 16:44:10 -0700 | [diff] [blame] | 602 | * |
| 603 | * Returns the time in jiffies for the next call. |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 604 | */ |
Joe Eykholt | 8690cb8 | 2010-06-11 16:44:10 -0700 | [diff] [blame] | 605 | static unsigned long fcoe_ctlr_age_fcfs(struct fcoe_ctlr *fip) |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 606 | { |
| 607 | struct fcoe_fcf *fcf; |
| 608 | struct fcoe_fcf *next; |
Joe Eykholt | 8690cb8 | 2010-06-11 16:44:10 -0700 | [diff] [blame] | 609 | unsigned long next_timer = jiffies + msecs_to_jiffies(FIP_VN_KA_PERIOD); |
| 610 | unsigned long deadline; |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 611 | unsigned long sel_time = 0; |
Joe Eykholt | f018b73 | 2010-03-12 16:08:55 -0800 | [diff] [blame] | 612 | struct fcoe_dev_stats *stats; |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 613 | |
Joe Eykholt | fdb068c | 2010-07-20 15:19:47 -0700 | [diff] [blame] | 614 | stats = per_cpu_ptr(fip->lp->dev_stats, get_cpu()); |
| 615 | |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 616 | list_for_each_entry_safe(fcf, next, &fip->fcfs, list) { |
Joe Eykholt | 8690cb8 | 2010-06-11 16:44:10 -0700 | [diff] [blame] | 617 | deadline = fcf->time + fcf->fka_period + fcf->fka_period / 2; |
| 618 | if (fip->sel_fcf == fcf) { |
| 619 | if (time_after(jiffies, deadline)) { |
Joe Eykholt | 8690cb8 | 2010-06-11 16:44:10 -0700 | [diff] [blame] | 620 | stats->MissDiscAdvCount++; |
| 621 | printk(KERN_INFO "libfcoe: host%d: " |
| 622 | "Missing Discovery Advertisement " |
| 623 | "for fab %16.16llx count %lld\n", |
| 624 | fip->lp->host->host_no, fcf->fabric_name, |
| 625 | stats->MissDiscAdvCount); |
| 626 | } else if (time_after(next_timer, deadline)) |
| 627 | next_timer = deadline; |
Yi Zou | f3da80e | 2009-11-20 14:55:08 -0800 | [diff] [blame] | 628 | } |
Joe Eykholt | 8690cb8 | 2010-06-11 16:44:10 -0700 | [diff] [blame] | 629 | |
| 630 | deadline += fcf->fka_period; |
Joe Eykholt | d99ee45 | 2010-06-11 16:44:15 -0700 | [diff] [blame] | 631 | if (time_after_eq(jiffies, deadline)) { |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 632 | if (fip->sel_fcf == fcf) |
| 633 | fip->sel_fcf = NULL; |
| 634 | list_del(&fcf->list); |
| 635 | WARN_ON(!fip->fcf_count); |
| 636 | fip->fcf_count--; |
| 637 | kfree(fcf); |
Joe Eykholt | f018b73 | 2010-03-12 16:08:55 -0800 | [diff] [blame] | 638 | stats->VLinkFailureCount++; |
Joe Eykholt | 8690cb8 | 2010-06-11 16:44:10 -0700 | [diff] [blame] | 639 | } else { |
| 640 | if (time_after(next_timer, deadline)) |
| 641 | next_timer = deadline; |
| 642 | if (fcoe_ctlr_mtu_valid(fcf) && |
| 643 | (!sel_time || time_before(sel_time, fcf->time))) |
| 644 | sel_time = fcf->time; |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 645 | } |
| 646 | } |
Joe Eykholt | fdb068c | 2010-07-20 15:19:47 -0700 | [diff] [blame] | 647 | put_cpu(); |
Joe Eykholt | d99ee45 | 2010-06-11 16:44:15 -0700 | [diff] [blame] | 648 | if (sel_time && !fip->sel_fcf && !fip->sel_time) { |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 649 | sel_time += msecs_to_jiffies(FCOE_CTLR_START_DELAY); |
| 650 | fip->sel_time = sel_time; |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 651 | } |
Joe Eykholt | d99ee45 | 2010-06-11 16:44:15 -0700 | [diff] [blame] | 652 | |
Joe Eykholt | 8690cb8 | 2010-06-11 16:44:10 -0700 | [diff] [blame] | 653 | return next_timer; |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 654 | } |
| 655 | |
| 656 | /** |
Robert Love | 70b51aa | 2009-11-03 11:47:45 -0800 | [diff] [blame] | 657 | * fcoe_ctlr_parse_adv() - Decode a FIP advertisement into a new FCF entry |
Joe Eykholt | 0f51c2e | 2009-11-03 11:48:16 -0800 | [diff] [blame] | 658 | * @fip: The FCoE controller receiving the advertisement |
Robert Love | 70b51aa | 2009-11-03 11:47:45 -0800 | [diff] [blame] | 659 | * @skb: The received FIP advertisement frame |
| 660 | * @fcf: The resulting FCF entry |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 661 | * |
| 662 | * Returns zero on a valid parsed advertisement, |
| 663 | * otherwise returns non zero value. |
| 664 | */ |
Joe Eykholt | 0f51c2e | 2009-11-03 11:48:16 -0800 | [diff] [blame] | 665 | static int fcoe_ctlr_parse_adv(struct fcoe_ctlr *fip, |
| 666 | struct sk_buff *skb, struct fcoe_fcf *fcf) |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 667 | { |
| 668 | struct fip_header *fiph; |
| 669 | struct fip_desc *desc = NULL; |
| 670 | struct fip_wwn_desc *wwn; |
| 671 | struct fip_fab_desc *fab; |
| 672 | struct fip_fka_desc *fka; |
| 673 | unsigned long t; |
| 674 | size_t rlen; |
| 675 | size_t dlen; |
Bhanu Prakash Gollapudi | 0a9c5d3 | 2010-06-11 16:44:25 -0700 | [diff] [blame] | 676 | u32 desc_mask; |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 677 | |
| 678 | memset(fcf, 0, sizeof(*fcf)); |
| 679 | fcf->fka_period = msecs_to_jiffies(FCOE_CTLR_DEF_FKA); |
| 680 | |
| 681 | fiph = (struct fip_header *)skb->data; |
| 682 | fcf->flags = ntohs(fiph->fip_flags); |
| 683 | |
Bhanu Prakash Gollapudi | 0a9c5d3 | 2010-06-11 16:44:25 -0700 | [diff] [blame] | 684 | /* |
| 685 | * mask of required descriptors. validating each one clears its bit. |
| 686 | */ |
| 687 | desc_mask = BIT(FIP_DT_PRI) | BIT(FIP_DT_MAC) | BIT(FIP_DT_NAME) | |
| 688 | BIT(FIP_DT_FAB) | BIT(FIP_DT_FKA); |
| 689 | |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 690 | rlen = ntohs(fiph->fip_dl_len) * 4; |
| 691 | if (rlen + sizeof(*fiph) > skb->len) |
| 692 | return -EINVAL; |
| 693 | |
| 694 | desc = (struct fip_desc *)(fiph + 1); |
| 695 | while (rlen > 0) { |
| 696 | dlen = desc->fip_dlen * FIP_BPW; |
| 697 | if (dlen < sizeof(*desc) || dlen > rlen) |
| 698 | return -EINVAL; |
Bhanu Prakash Gollapudi | 0a9c5d3 | 2010-06-11 16:44:25 -0700 | [diff] [blame] | 699 | /* Drop Adv if there are duplicate critical descriptors */ |
| 700 | if ((desc->fip_dtype < 32) && |
| 701 | !(desc_mask & 1U << desc->fip_dtype)) { |
| 702 | LIBFCOE_FIP_DBG(fip, "Duplicate Critical " |
| 703 | "Descriptors in FIP adv\n"); |
| 704 | return -EINVAL; |
| 705 | } |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 706 | switch (desc->fip_dtype) { |
| 707 | case FIP_DT_PRI: |
| 708 | if (dlen != sizeof(struct fip_pri_desc)) |
| 709 | goto len_err; |
| 710 | fcf->pri = ((struct fip_pri_desc *)desc)->fd_pri; |
Bhanu Prakash Gollapudi | 0a9c5d3 | 2010-06-11 16:44:25 -0700 | [diff] [blame] | 711 | desc_mask &= ~BIT(FIP_DT_PRI); |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 712 | break; |
| 713 | case FIP_DT_MAC: |
| 714 | if (dlen != sizeof(struct fip_mac_desc)) |
| 715 | goto len_err; |
| 716 | memcpy(fcf->fcf_mac, |
| 717 | ((struct fip_mac_desc *)desc)->fd_mac, |
| 718 | ETH_ALEN); |
| 719 | if (!is_valid_ether_addr(fcf->fcf_mac)) { |
Joe Eykholt | 0f51c2e | 2009-11-03 11:48:16 -0800 | [diff] [blame] | 720 | LIBFCOE_FIP_DBG(fip, "Invalid MAC address " |
Robert Love | 650bd12 | 2009-06-10 15:31:05 -0700 | [diff] [blame] | 721 | "in FIP adv\n"); |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 722 | return -EINVAL; |
| 723 | } |
Bhanu Prakash Gollapudi | 0a9c5d3 | 2010-06-11 16:44:25 -0700 | [diff] [blame] | 724 | desc_mask &= ~BIT(FIP_DT_MAC); |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 725 | break; |
| 726 | case FIP_DT_NAME: |
| 727 | if (dlen != sizeof(struct fip_wwn_desc)) |
| 728 | goto len_err; |
| 729 | wwn = (struct fip_wwn_desc *)desc; |
| 730 | fcf->switch_name = get_unaligned_be64(&wwn->fd_wwn); |
Bhanu Prakash Gollapudi | 0a9c5d3 | 2010-06-11 16:44:25 -0700 | [diff] [blame] | 731 | desc_mask &= ~BIT(FIP_DT_NAME); |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 732 | break; |
| 733 | case FIP_DT_FAB: |
| 734 | if (dlen != sizeof(struct fip_fab_desc)) |
| 735 | goto len_err; |
| 736 | fab = (struct fip_fab_desc *)desc; |
| 737 | fcf->fabric_name = get_unaligned_be64(&fab->fd_wwn); |
| 738 | fcf->vfid = ntohs(fab->fd_vfid); |
| 739 | fcf->fc_map = ntoh24(fab->fd_map); |
Bhanu Prakash Gollapudi | 0a9c5d3 | 2010-06-11 16:44:25 -0700 | [diff] [blame] | 740 | desc_mask &= ~BIT(FIP_DT_FAB); |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 741 | break; |
| 742 | case FIP_DT_FKA: |
| 743 | if (dlen != sizeof(struct fip_fka_desc)) |
| 744 | goto len_err; |
| 745 | fka = (struct fip_fka_desc *)desc; |
Yi Zou | 8cdffdc | 2009-11-20 14:54:57 -0800 | [diff] [blame] | 746 | if (fka->fd_flags & FIP_FKA_ADV_D) |
| 747 | fcf->fd_flags = 1; |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 748 | t = ntohl(fka->fd_fka_period); |
| 749 | if (t >= FCOE_CTLR_MIN_FKA) |
| 750 | fcf->fka_period = msecs_to_jiffies(t); |
Bhanu Prakash Gollapudi | 0a9c5d3 | 2010-06-11 16:44:25 -0700 | [diff] [blame] | 751 | desc_mask &= ~BIT(FIP_DT_FKA); |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 752 | break; |
| 753 | case FIP_DT_MAP_OUI: |
| 754 | case FIP_DT_FCOE_SIZE: |
| 755 | case FIP_DT_FLOGI: |
| 756 | case FIP_DT_FDISC: |
| 757 | case FIP_DT_LOGO: |
| 758 | case FIP_DT_ELP: |
| 759 | default: |
Joe Eykholt | 0f51c2e | 2009-11-03 11:48:16 -0800 | [diff] [blame] | 760 | LIBFCOE_FIP_DBG(fip, "unexpected descriptor type %x " |
Robert Love | 650bd12 | 2009-06-10 15:31:05 -0700 | [diff] [blame] | 761 | "in FIP adv\n", desc->fip_dtype); |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 762 | /* standard says ignore unknown descriptors >= 128 */ |
| 763 | if (desc->fip_dtype < FIP_DT_VENDOR_BASE) |
| 764 | return -EINVAL; |
Bhanu Prakash Gollapudi | 1508f3ec | 2010-06-11 16:43:38 -0700 | [diff] [blame] | 765 | break; |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 766 | } |
| 767 | desc = (struct fip_desc *)((char *)desc + dlen); |
| 768 | rlen -= dlen; |
| 769 | } |
| 770 | if (!fcf->fc_map || (fcf->fc_map & 0x10000)) |
| 771 | return -EINVAL; |
| 772 | if (!fcf->switch_name || !fcf->fabric_name) |
| 773 | return -EINVAL; |
Bhanu Prakash Gollapudi | 0a9c5d3 | 2010-06-11 16:44:25 -0700 | [diff] [blame] | 774 | if (desc_mask) { |
| 775 | LIBFCOE_FIP_DBG(fip, "adv missing descriptors mask %x\n", |
| 776 | desc_mask); |
| 777 | return -EINVAL; |
| 778 | } |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 779 | return 0; |
| 780 | |
| 781 | len_err: |
Joe Eykholt | 0f51c2e | 2009-11-03 11:48:16 -0800 | [diff] [blame] | 782 | LIBFCOE_FIP_DBG(fip, "FIP length error in descriptor type %x len %zu\n", |
Robert Love | 650bd12 | 2009-06-10 15:31:05 -0700 | [diff] [blame] | 783 | desc->fip_dtype, dlen); |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 784 | return -EINVAL; |
| 785 | } |
| 786 | |
| 787 | /** |
Robert Love | 70b51aa | 2009-11-03 11:47:45 -0800 | [diff] [blame] | 788 | * fcoe_ctlr_recv_adv() - Handle an incoming advertisement |
| 789 | * @fip: The FCoE controller receiving the advertisement |
| 790 | * @skb: The received FIP packet |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 791 | */ |
| 792 | static void fcoe_ctlr_recv_adv(struct fcoe_ctlr *fip, struct sk_buff *skb) |
| 793 | { |
| 794 | struct fcoe_fcf *fcf; |
| 795 | struct fcoe_fcf new; |
| 796 | struct fcoe_fcf *found; |
| 797 | unsigned long sol_tov = msecs_to_jiffies(FCOE_CTRL_SOL_TOV); |
| 798 | int first = 0; |
| 799 | int mtu_valid; |
| 800 | |
Joe Eykholt | 0f51c2e | 2009-11-03 11:48:16 -0800 | [diff] [blame] | 801 | if (fcoe_ctlr_parse_adv(fip, skb, &new)) |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 802 | return; |
| 803 | |
Joe Eykholt | fdb068c | 2010-07-20 15:19:47 -0700 | [diff] [blame] | 804 | mutex_lock(&fip->ctlr_mutex); |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 805 | first = list_empty(&fip->fcfs); |
| 806 | found = NULL; |
| 807 | list_for_each_entry(fcf, &fip->fcfs, list) { |
| 808 | if (fcf->switch_name == new.switch_name && |
| 809 | fcf->fabric_name == new.fabric_name && |
| 810 | fcf->fc_map == new.fc_map && |
| 811 | compare_ether_addr(fcf->fcf_mac, new.fcf_mac) == 0) { |
| 812 | found = fcf; |
| 813 | break; |
| 814 | } |
| 815 | } |
| 816 | if (!found) { |
| 817 | if (fip->fcf_count >= FCOE_CTLR_FCF_LIMIT) |
| 818 | goto out; |
| 819 | |
| 820 | fcf = kmalloc(sizeof(*fcf), GFP_ATOMIC); |
| 821 | if (!fcf) |
| 822 | goto out; |
| 823 | |
| 824 | fip->fcf_count++; |
| 825 | memcpy(fcf, &new, sizeof(new)); |
| 826 | list_add(&fcf->list, &fip->fcfs); |
| 827 | } else { |
| 828 | /* |
Joe Eykholt | c600fea | 2010-06-11 16:44:20 -0700 | [diff] [blame] | 829 | * Update the FCF's keep-alive descriptor flags. |
| 830 | * Other flag changes from new advertisements are |
| 831 | * ignored after a solicited advertisement is |
| 832 | * received and the FCF is selectable (usable). |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 833 | */ |
Joe Eykholt | c600fea | 2010-06-11 16:44:20 -0700 | [diff] [blame] | 834 | fcf->fd_flags = new.fd_flags; |
| 835 | if (!fcoe_ctlr_fcf_usable(fcf)) |
| 836 | fcf->flags = new.flags; |
| 837 | |
Joe Eykholt | d99ee45 | 2010-06-11 16:44:15 -0700 | [diff] [blame] | 838 | if (fcf == fip->sel_fcf && !fcf->fd_flags) { |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 839 | fip->ctlr_ka_time -= fcf->fka_period; |
| 840 | fip->ctlr_ka_time += new.fka_period; |
| 841 | if (time_before(fip->ctlr_ka_time, fip->timer.expires)) |
| 842 | mod_timer(&fip->timer, fip->ctlr_ka_time); |
Joe Eykholt | c600fea | 2010-06-11 16:44:20 -0700 | [diff] [blame] | 843 | } |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 844 | fcf->fka_period = new.fka_period; |
| 845 | memcpy(fcf->fcf_mac, new.fcf_mac, ETH_ALEN); |
| 846 | } |
| 847 | mtu_valid = fcoe_ctlr_mtu_valid(fcf); |
| 848 | fcf->time = jiffies; |
Robert Love | 650bd12 | 2009-06-10 15:31:05 -0700 | [diff] [blame] | 849 | if (!found) { |
Chris Leech | 9f8f3aa | 2010-04-09 14:23:16 -0700 | [diff] [blame] | 850 | LIBFCOE_FIP_DBG(fip, "New FCF for fab %16.16llx " |
| 851 | "map %x val %d\n", |
Robert Love | 650bd12 | 2009-06-10 15:31:05 -0700 | [diff] [blame] | 852 | fcf->fabric_name, fcf->fc_map, mtu_valid); |
| 853 | } |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 854 | |
| 855 | /* |
| 856 | * If this advertisement is not solicited and our max receive size |
| 857 | * hasn't been verified, send a solicited advertisement. |
| 858 | */ |
| 859 | if (!mtu_valid) |
| 860 | fcoe_ctlr_solicit(fip, fcf); |
| 861 | |
| 862 | /* |
| 863 | * If its been a while since we did a solicit, and this is |
| 864 | * the first advertisement we've received, do a multicast |
| 865 | * solicitation to gather as many advertisements as we can |
| 866 | * before selection occurs. |
| 867 | */ |
| 868 | if (first && time_after(jiffies, fip->sol_time + sol_tov)) |
| 869 | fcoe_ctlr_solicit(fip, NULL); |
| 870 | |
| 871 | /* |
| 872 | * If this is the first validated FCF, note the time and |
| 873 | * set a timer to trigger selection. |
| 874 | */ |
Joe Eykholt | d99ee45 | 2010-06-11 16:44:15 -0700 | [diff] [blame] | 875 | if (mtu_valid && !fip->sel_fcf && fcoe_ctlr_fcf_usable(fcf)) { |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 876 | fip->sel_time = jiffies + |
Robert Love | 70b51aa | 2009-11-03 11:47:45 -0800 | [diff] [blame] | 877 | msecs_to_jiffies(FCOE_CTLR_START_DELAY); |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 878 | if (!timer_pending(&fip->timer) || |
| 879 | time_before(fip->sel_time, fip->timer.expires)) |
| 880 | mod_timer(&fip->timer, fip->sel_time); |
| 881 | } |
| 882 | out: |
Joe Eykholt | fdb068c | 2010-07-20 15:19:47 -0700 | [diff] [blame] | 883 | mutex_unlock(&fip->ctlr_mutex); |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 884 | } |
| 885 | |
| 886 | /** |
Robert Love | 70b51aa | 2009-11-03 11:47:45 -0800 | [diff] [blame] | 887 | * fcoe_ctlr_recv_els() - Handle an incoming FIP encapsulated ELS frame |
| 888 | * @fip: The FCoE controller which received the packet |
| 889 | * @skb: The received FIP packet |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 890 | */ |
| 891 | static void fcoe_ctlr_recv_els(struct fcoe_ctlr *fip, struct sk_buff *skb) |
| 892 | { |
Robert Love | 70b51aa | 2009-11-03 11:47:45 -0800 | [diff] [blame] | 893 | struct fc_lport *lport = fip->lp; |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 894 | struct fip_header *fiph; |
Chris Leech | 11b5618 | 2009-11-03 11:46:29 -0800 | [diff] [blame] | 895 | struct fc_frame *fp = (struct fc_frame *)skb; |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 896 | struct fc_frame_header *fh = NULL; |
| 897 | struct fip_desc *desc; |
| 898 | struct fip_encaps *els; |
| 899 | struct fcoe_dev_stats *stats; |
| 900 | enum fip_desc_type els_dtype = 0; |
| 901 | u8 els_op; |
| 902 | u8 sub; |
| 903 | u8 granted_mac[ETH_ALEN] = { 0 }; |
| 904 | size_t els_len = 0; |
| 905 | size_t rlen; |
| 906 | size_t dlen; |
Bhanu Prakash Gollapudi | be61331 | 2010-06-11 16:44:36 -0700 | [diff] [blame] | 907 | u32 desc_mask = 0; |
| 908 | u32 desc_cnt = 0; |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 909 | |
| 910 | fiph = (struct fip_header *)skb->data; |
| 911 | sub = fiph->fip_subcode; |
| 912 | if (sub != FIP_SC_REQ && sub != FIP_SC_REP) |
| 913 | goto drop; |
| 914 | |
| 915 | rlen = ntohs(fiph->fip_dl_len) * 4; |
| 916 | if (rlen + sizeof(*fiph) > skb->len) |
| 917 | goto drop; |
| 918 | |
| 919 | desc = (struct fip_desc *)(fiph + 1); |
| 920 | while (rlen > 0) { |
Bhanu Prakash Gollapudi | be61331 | 2010-06-11 16:44:36 -0700 | [diff] [blame] | 921 | desc_cnt++; |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 922 | dlen = desc->fip_dlen * FIP_BPW; |
| 923 | if (dlen < sizeof(*desc) || dlen > rlen) |
| 924 | goto drop; |
Bhanu Prakash Gollapudi | 0a9c5d3 | 2010-06-11 16:44:25 -0700 | [diff] [blame] | 925 | /* Drop ELS if there are duplicate critical descriptors */ |
| 926 | if (desc->fip_dtype < 32) { |
Bhanu Prakash Gollapudi | be61331 | 2010-06-11 16:44:36 -0700 | [diff] [blame] | 927 | if (desc_mask & 1U << desc->fip_dtype) { |
Bhanu Prakash Gollapudi | 0a9c5d3 | 2010-06-11 16:44:25 -0700 | [diff] [blame] | 928 | LIBFCOE_FIP_DBG(fip, "Duplicate Critical " |
| 929 | "Descriptors in FIP ELS\n"); |
| 930 | goto drop; |
| 931 | } |
Bhanu Prakash Gollapudi | be61331 | 2010-06-11 16:44:36 -0700 | [diff] [blame] | 932 | desc_mask |= (1 << desc->fip_dtype); |
Bhanu Prakash Gollapudi | 0a9c5d3 | 2010-06-11 16:44:25 -0700 | [diff] [blame] | 933 | } |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 934 | switch (desc->fip_dtype) { |
| 935 | case FIP_DT_MAC: |
Bhanu Prakash Gollapudi | be61331 | 2010-06-11 16:44:36 -0700 | [diff] [blame] | 936 | if (desc_cnt == 1) { |
| 937 | LIBFCOE_FIP_DBG(fip, "FIP descriptors " |
| 938 | "received out of order\n"); |
| 939 | goto drop; |
| 940 | } |
| 941 | |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 942 | if (dlen != sizeof(struct fip_mac_desc)) |
| 943 | goto len_err; |
| 944 | memcpy(granted_mac, |
| 945 | ((struct fip_mac_desc *)desc)->fd_mac, |
| 946 | ETH_ALEN); |
| 947 | if (!is_valid_ether_addr(granted_mac)) { |
Joe Eykholt | 0f51c2e | 2009-11-03 11:48:16 -0800 | [diff] [blame] | 948 | LIBFCOE_FIP_DBG(fip, "Invalid MAC address " |
Robert Love | 650bd12 | 2009-06-10 15:31:05 -0700 | [diff] [blame] | 949 | "in FIP ELS\n"); |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 950 | goto drop; |
| 951 | } |
Chris Leech | 11b5618 | 2009-11-03 11:46:29 -0800 | [diff] [blame] | 952 | memcpy(fr_cb(fp)->granted_mac, granted_mac, ETH_ALEN); |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 953 | break; |
| 954 | case FIP_DT_FLOGI: |
| 955 | case FIP_DT_FDISC: |
| 956 | case FIP_DT_LOGO: |
| 957 | case FIP_DT_ELP: |
Bhanu Prakash Gollapudi | be61331 | 2010-06-11 16:44:36 -0700 | [diff] [blame] | 958 | if (desc_cnt != 1) { |
| 959 | LIBFCOE_FIP_DBG(fip, "FIP descriptors " |
| 960 | "received out of order\n"); |
| 961 | goto drop; |
| 962 | } |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 963 | if (fh) |
| 964 | goto drop; |
| 965 | if (dlen < sizeof(*els) + sizeof(*fh) + 1) |
| 966 | goto len_err; |
| 967 | els_len = dlen - sizeof(*els); |
| 968 | els = (struct fip_encaps *)desc; |
| 969 | fh = (struct fc_frame_header *)(els + 1); |
| 970 | els_dtype = desc->fip_dtype; |
| 971 | break; |
| 972 | default: |
Joe Eykholt | 0f51c2e | 2009-11-03 11:48:16 -0800 | [diff] [blame] | 973 | LIBFCOE_FIP_DBG(fip, "unexpected descriptor type %x " |
Robert Love | 650bd12 | 2009-06-10 15:31:05 -0700 | [diff] [blame] | 974 | "in FIP adv\n", desc->fip_dtype); |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 975 | /* standard says ignore unknown descriptors >= 128 */ |
| 976 | if (desc->fip_dtype < FIP_DT_VENDOR_BASE) |
| 977 | goto drop; |
Bhanu Prakash Gollapudi | be61331 | 2010-06-11 16:44:36 -0700 | [diff] [blame] | 978 | if (desc_cnt <= 2) { |
| 979 | LIBFCOE_FIP_DBG(fip, "FIP descriptors " |
| 980 | "received out of order\n"); |
| 981 | goto drop; |
| 982 | } |
Bhanu Prakash Gollapudi | 1508f3ec | 2010-06-11 16:43:38 -0700 | [diff] [blame] | 983 | break; |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 984 | } |
| 985 | desc = (struct fip_desc *)((char *)desc + dlen); |
| 986 | rlen -= dlen; |
| 987 | } |
| 988 | |
| 989 | if (!fh) |
| 990 | goto drop; |
| 991 | els_op = *(u8 *)(fh + 1); |
| 992 | |
Chris Leech | 11b5618 | 2009-11-03 11:46:29 -0800 | [diff] [blame] | 993 | if (els_dtype == FIP_DT_FLOGI && sub == FIP_SC_REP && |
| 994 | fip->flogi_oxid == ntohs(fh->fh_ox_id) && |
| 995 | els_op == ELS_LS_ACC && is_valid_ether_addr(granted_mac)) |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 996 | fip->flogi_oxid = FC_XID_UNKNOWN; |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 997 | |
Bhanu Prakash Gollapudi | be61331 | 2010-06-11 16:44:36 -0700 | [diff] [blame] | 998 | if ((desc_cnt == 0) || ((els_op != ELS_LS_RJT) && |
| 999 | (!(1U << FIP_DT_MAC & desc_mask)))) { |
| 1000 | LIBFCOE_FIP_DBG(fip, "Missing critical descriptors " |
| 1001 | "in FIP ELS\n"); |
| 1002 | goto drop; |
| 1003 | } |
| 1004 | |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 1005 | /* |
| 1006 | * Convert skb into an fc_frame containing only the ELS. |
| 1007 | */ |
| 1008 | skb_pull(skb, (u8 *)fh - skb->data); |
| 1009 | skb_trim(skb, els_len); |
| 1010 | fp = (struct fc_frame *)skb; |
| 1011 | fc_frame_init(fp); |
| 1012 | fr_sof(fp) = FC_SOF_I3; |
| 1013 | fr_eof(fp) = FC_EOF_T; |
Robert Love | 70b51aa | 2009-11-03 11:47:45 -0800 | [diff] [blame] | 1014 | fr_dev(fp) = lport; |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 1015 | |
Joe Eykholt | f018b73 | 2010-03-12 16:08:55 -0800 | [diff] [blame] | 1016 | stats = per_cpu_ptr(lport->dev_stats, get_cpu()); |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 1017 | stats->RxFrames++; |
| 1018 | stats->RxWords += skb->len / FIP_BPW; |
Joe Eykholt | f018b73 | 2010-03-12 16:08:55 -0800 | [diff] [blame] | 1019 | put_cpu(); |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 1020 | |
Robert Love | 70b51aa | 2009-11-03 11:47:45 -0800 | [diff] [blame] | 1021 | fc_exch_recv(lport, fp); |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 1022 | return; |
| 1023 | |
| 1024 | len_err: |
Joe Eykholt | 0f51c2e | 2009-11-03 11:48:16 -0800 | [diff] [blame] | 1025 | LIBFCOE_FIP_DBG(fip, "FIP length error in descriptor type %x len %zu\n", |
Robert Love | 650bd12 | 2009-06-10 15:31:05 -0700 | [diff] [blame] | 1026 | desc->fip_dtype, dlen); |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 1027 | drop: |
| 1028 | kfree_skb(skb); |
| 1029 | } |
| 1030 | |
| 1031 | /** |
Robert Love | 70b51aa | 2009-11-03 11:47:45 -0800 | [diff] [blame] | 1032 | * fcoe_ctlr_recv_els() - Handle an incoming link reset frame |
| 1033 | * @fip: The FCoE controller that received the frame |
| 1034 | * @fh: The received FIP header |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 1035 | * |
| 1036 | * There may be multiple VN_Port descriptors. |
| 1037 | * The overall length has already been checked. |
| 1038 | */ |
| 1039 | static void fcoe_ctlr_recv_clr_vlink(struct fcoe_ctlr *fip, |
Robert Love | 70b51aa | 2009-11-03 11:47:45 -0800 | [diff] [blame] | 1040 | struct fip_header *fh) |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 1041 | { |
| 1042 | struct fip_desc *desc; |
| 1043 | struct fip_mac_desc *mp; |
| 1044 | struct fip_wwn_desc *wp; |
| 1045 | struct fip_vn_desc *vp; |
| 1046 | size_t rlen; |
| 1047 | size_t dlen; |
| 1048 | struct fcoe_fcf *fcf = fip->sel_fcf; |
Robert Love | 70b51aa | 2009-11-03 11:47:45 -0800 | [diff] [blame] | 1049 | struct fc_lport *lport = fip->lp; |
Bhanu Prakash Gollapudi | 5550fda | 2010-06-11 16:44:31 -0700 | [diff] [blame] | 1050 | struct fc_lport *vn_port = NULL; |
| 1051 | u32 desc_mask; |
| 1052 | int is_vn_port = 0; |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 1053 | |
Joe Eykholt | 0f51c2e | 2009-11-03 11:48:16 -0800 | [diff] [blame] | 1054 | LIBFCOE_FIP_DBG(fip, "Clear Virtual Link received\n"); |
Robert Love | d29510a | 2010-05-07 15:18:30 -0700 | [diff] [blame] | 1055 | |
Robert Love | 7b2787e | 2010-05-07 15:18:41 -0700 | [diff] [blame] | 1056 | if (!fcf || !lport->port_id) |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 1057 | return; |
| 1058 | |
| 1059 | /* |
| 1060 | * mask of required descriptors. Validating each one clears its bit. |
| 1061 | */ |
| 1062 | desc_mask = BIT(FIP_DT_MAC) | BIT(FIP_DT_NAME) | BIT(FIP_DT_VN_ID); |
| 1063 | |
| 1064 | rlen = ntohs(fh->fip_dl_len) * FIP_BPW; |
| 1065 | desc = (struct fip_desc *)(fh + 1); |
| 1066 | while (rlen >= sizeof(*desc)) { |
| 1067 | dlen = desc->fip_dlen * FIP_BPW; |
| 1068 | if (dlen > rlen) |
| 1069 | return; |
Bhanu Prakash Gollapudi | 0a9c5d3 | 2010-06-11 16:44:25 -0700 | [diff] [blame] | 1070 | /* Drop CVL if there are duplicate critical descriptors */ |
| 1071 | if ((desc->fip_dtype < 32) && |
| 1072 | !(desc_mask & 1U << desc->fip_dtype)) { |
| 1073 | LIBFCOE_FIP_DBG(fip, "Duplicate Critical " |
| 1074 | "Descriptors in FIP CVL\n"); |
| 1075 | return; |
| 1076 | } |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 1077 | switch (desc->fip_dtype) { |
| 1078 | case FIP_DT_MAC: |
| 1079 | mp = (struct fip_mac_desc *)desc; |
| 1080 | if (dlen < sizeof(*mp)) |
| 1081 | return; |
| 1082 | if (compare_ether_addr(mp->fd_mac, fcf->fcf_mac)) |
| 1083 | return; |
| 1084 | desc_mask &= ~BIT(FIP_DT_MAC); |
| 1085 | break; |
| 1086 | case FIP_DT_NAME: |
| 1087 | wp = (struct fip_wwn_desc *)desc; |
| 1088 | if (dlen < sizeof(*wp)) |
| 1089 | return; |
| 1090 | if (get_unaligned_be64(&wp->fd_wwn) != fcf->switch_name) |
| 1091 | return; |
| 1092 | desc_mask &= ~BIT(FIP_DT_NAME); |
| 1093 | break; |
| 1094 | case FIP_DT_VN_ID: |
| 1095 | vp = (struct fip_vn_desc *)desc; |
| 1096 | if (dlen < sizeof(*vp)) |
| 1097 | return; |
| 1098 | if (compare_ether_addr(vp->fd_mac, |
Robert Love | 70b51aa | 2009-11-03 11:47:45 -0800 | [diff] [blame] | 1099 | fip->get_src_addr(lport)) == 0 && |
| 1100 | get_unaligned_be64(&vp->fd_wwpn) == lport->wwpn && |
Bhanu Prakash Gollapudi | 5550fda | 2010-06-11 16:44:31 -0700 | [diff] [blame] | 1101 | ntoh24(vp->fd_fc_id) == lport->port_id) { |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 1102 | desc_mask &= ~BIT(FIP_DT_VN_ID); |
Bhanu Prakash Gollapudi | 5550fda | 2010-06-11 16:44:31 -0700 | [diff] [blame] | 1103 | break; |
| 1104 | } |
| 1105 | /* check if clr_vlink is for NPIV port */ |
| 1106 | mutex_lock(&lport->lp_mutex); |
| 1107 | list_for_each_entry(vn_port, &lport->vports, list) { |
| 1108 | if (compare_ether_addr(vp->fd_mac, |
| 1109 | fip->get_src_addr(vn_port)) == 0 && |
| 1110 | (get_unaligned_be64(&vp->fd_wwpn) |
| 1111 | == vn_port->wwpn) && |
| 1112 | (ntoh24(vp->fd_fc_id) == |
| 1113 | fc_host_port_id(vn_port->host))) { |
| 1114 | desc_mask &= ~BIT(FIP_DT_VN_ID); |
| 1115 | is_vn_port = 1; |
| 1116 | break; |
| 1117 | } |
| 1118 | } |
| 1119 | mutex_unlock(&lport->lp_mutex); |
| 1120 | |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 1121 | break; |
| 1122 | default: |
| 1123 | /* standard says ignore unknown descriptors >= 128 */ |
| 1124 | if (desc->fip_dtype < FIP_DT_VENDOR_BASE) |
| 1125 | return; |
| 1126 | break; |
| 1127 | } |
| 1128 | desc = (struct fip_desc *)((char *)desc + dlen); |
| 1129 | rlen -= dlen; |
| 1130 | } |
| 1131 | |
| 1132 | /* |
| 1133 | * reset only if all required descriptors were present and valid. |
| 1134 | */ |
| 1135 | if (desc_mask) { |
Joe Eykholt | 0f51c2e | 2009-11-03 11:48:16 -0800 | [diff] [blame] | 1136 | LIBFCOE_FIP_DBG(fip, "missing descriptors mask %x\n", |
| 1137 | desc_mask); |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 1138 | } else { |
Joe Eykholt | 0f51c2e | 2009-11-03 11:48:16 -0800 | [diff] [blame] | 1139 | LIBFCOE_FIP_DBG(fip, "performing Clear Virtual Link\n"); |
Joe Eykholt | dd42dac | 2009-11-03 11:48:27 -0800 | [diff] [blame] | 1140 | |
Bhanu Prakash Gollapudi | 5550fda | 2010-06-11 16:44:31 -0700 | [diff] [blame] | 1141 | if (is_vn_port) |
| 1142 | fc_lport_reset(vn_port); |
| 1143 | else { |
Joe Eykholt | fdb068c | 2010-07-20 15:19:47 -0700 | [diff] [blame] | 1144 | mutex_lock(&fip->ctlr_mutex); |
Bhanu Prakash Gollapudi | 5550fda | 2010-06-11 16:44:31 -0700 | [diff] [blame] | 1145 | per_cpu_ptr(lport->dev_stats, |
Joe Eykholt | fdb068c | 2010-07-20 15:19:47 -0700 | [diff] [blame] | 1146 | get_cpu())->VLinkFailureCount++; |
| 1147 | put_cpu(); |
Bhanu Prakash Gollapudi | 5550fda | 2010-06-11 16:44:31 -0700 | [diff] [blame] | 1148 | fcoe_ctlr_reset(fip); |
Joe Eykholt | fdb068c | 2010-07-20 15:19:47 -0700 | [diff] [blame] | 1149 | mutex_unlock(&fip->ctlr_mutex); |
Joe Eykholt | dd42dac | 2009-11-03 11:48:27 -0800 | [diff] [blame] | 1150 | |
Bhanu Prakash Gollapudi | 5550fda | 2010-06-11 16:44:31 -0700 | [diff] [blame] | 1151 | fc_lport_reset(fip->lp); |
| 1152 | fcoe_ctlr_solicit(fip, NULL); |
| 1153 | } |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 1154 | } |
| 1155 | } |
| 1156 | |
| 1157 | /** |
Robert Love | 70b51aa | 2009-11-03 11:47:45 -0800 | [diff] [blame] | 1158 | * fcoe_ctlr_recv() - Receive a FIP packet |
| 1159 | * @fip: The FCoE controller that received the packet |
| 1160 | * @skb: The received FIP packet |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 1161 | * |
Joe Eykholt | 1f4aed8 | 2009-11-03 11:48:22 -0800 | [diff] [blame] | 1162 | * This may be called from either NET_RX_SOFTIRQ or IRQ. |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 1163 | */ |
| 1164 | void fcoe_ctlr_recv(struct fcoe_ctlr *fip, struct sk_buff *skb) |
| 1165 | { |
Joe Eykholt | 1f4aed8 | 2009-11-03 11:48:22 -0800 | [diff] [blame] | 1166 | skb_queue_tail(&fip->fip_recv_list, skb); |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 1167 | schedule_work(&fip->recv_work); |
| 1168 | } |
| 1169 | EXPORT_SYMBOL(fcoe_ctlr_recv); |
| 1170 | |
| 1171 | /** |
Robert Love | 70b51aa | 2009-11-03 11:47:45 -0800 | [diff] [blame] | 1172 | * fcoe_ctlr_recv_handler() - Receive a FIP frame |
| 1173 | * @fip: The FCoE controller that received the frame |
| 1174 | * @skb: The received FIP frame |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 1175 | * |
| 1176 | * Returns non-zero if the frame is dropped. |
| 1177 | */ |
| 1178 | static int fcoe_ctlr_recv_handler(struct fcoe_ctlr *fip, struct sk_buff *skb) |
| 1179 | { |
| 1180 | struct fip_header *fiph; |
| 1181 | struct ethhdr *eh; |
| 1182 | enum fip_state state; |
| 1183 | u16 op; |
| 1184 | u8 sub; |
| 1185 | |
| 1186 | if (skb_linearize(skb)) |
| 1187 | goto drop; |
| 1188 | if (skb->len < sizeof(*fiph)) |
| 1189 | goto drop; |
| 1190 | eh = eth_hdr(skb); |
| 1191 | if (compare_ether_addr(eh->h_dest, fip->ctl_src_addr) && |
| 1192 | compare_ether_addr(eh->h_dest, FIP_ALL_ENODE_MACS)) |
| 1193 | goto drop; |
| 1194 | fiph = (struct fip_header *)skb->data; |
| 1195 | op = ntohs(fiph->fip_op); |
| 1196 | sub = fiph->fip_subcode; |
| 1197 | |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 1198 | if (FIP_VER_DECAPS(fiph->fip_ver) != FIP_VER) |
| 1199 | goto drop; |
| 1200 | if (ntohs(fiph->fip_dl_len) * FIP_BPW + sizeof(*fiph) > skb->len) |
| 1201 | goto drop; |
| 1202 | |
Joe Eykholt | fdb068c | 2010-07-20 15:19:47 -0700 | [diff] [blame] | 1203 | mutex_lock(&fip->ctlr_mutex); |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 1204 | state = fip->state; |
| 1205 | if (state == FIP_ST_AUTO) { |
| 1206 | fip->map_dest = 0; |
Joe Eykholt | 9b651da | 2010-07-20 15:20:24 -0700 | [diff] [blame^] | 1207 | fcoe_ctlr_set_state(fip, FIP_ST_ENABLED); |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 1208 | state = FIP_ST_ENABLED; |
Joe Eykholt | 0f51c2e | 2009-11-03 11:48:16 -0800 | [diff] [blame] | 1209 | LIBFCOE_FIP_DBG(fip, "Using FIP mode\n"); |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 1210 | } |
Joe Eykholt | fdb068c | 2010-07-20 15:19:47 -0700 | [diff] [blame] | 1211 | mutex_unlock(&fip->ctlr_mutex); |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 1212 | if (state != FIP_ST_ENABLED) |
| 1213 | goto drop; |
| 1214 | |
| 1215 | if (op == FIP_OP_LS) { |
| 1216 | fcoe_ctlr_recv_els(fip, skb); /* consumes skb */ |
| 1217 | return 0; |
| 1218 | } |
| 1219 | if (op == FIP_OP_DISC && sub == FIP_SC_ADV) |
| 1220 | fcoe_ctlr_recv_adv(fip, skb); |
| 1221 | else if (op == FIP_OP_CTRL && sub == FIP_SC_CLR_VLINK) |
| 1222 | fcoe_ctlr_recv_clr_vlink(fip, fiph); |
| 1223 | kfree_skb(skb); |
| 1224 | return 0; |
| 1225 | drop: |
| 1226 | kfree_skb(skb); |
| 1227 | return -1; |
| 1228 | } |
| 1229 | |
| 1230 | /** |
Robert Love | 70b51aa | 2009-11-03 11:47:45 -0800 | [diff] [blame] | 1231 | * fcoe_ctlr_select() - Select the best FCF (if possible) |
| 1232 | * @fip: The FCoE controller |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 1233 | * |
| 1234 | * If there are conflicting advertisements, no FCF can be chosen. |
| 1235 | * |
| 1236 | * Called with lock held. |
| 1237 | */ |
| 1238 | static void fcoe_ctlr_select(struct fcoe_ctlr *fip) |
| 1239 | { |
| 1240 | struct fcoe_fcf *fcf; |
| 1241 | struct fcoe_fcf *best = NULL; |
| 1242 | |
| 1243 | list_for_each_entry(fcf, &fip->fcfs, list) { |
Chris Leech | 9f8f3aa | 2010-04-09 14:23:16 -0700 | [diff] [blame] | 1244 | LIBFCOE_FIP_DBG(fip, "consider FCF for fab %16.16llx " |
| 1245 | "VFID %d map %x val %d\n", |
| 1246 | fcf->fabric_name, fcf->vfid, |
Robert Love | 650bd12 | 2009-06-10 15:31:05 -0700 | [diff] [blame] | 1247 | fcf->fc_map, fcoe_ctlr_mtu_valid(fcf)); |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 1248 | if (!fcoe_ctlr_fcf_usable(fcf)) { |
Chris Leech | 9f8f3aa | 2010-04-09 14:23:16 -0700 | [diff] [blame] | 1249 | LIBFCOE_FIP_DBG(fip, "FCF for fab %16.16llx " |
| 1250 | "map %x %svalid %savailable\n", |
| 1251 | fcf->fabric_name, fcf->fc_map, |
| 1252 | (fcf->flags & FIP_FL_SOL) ? "" : "in", |
| 1253 | (fcf->flags & FIP_FL_AVAIL) ? |
| 1254 | "" : "un"); |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 1255 | continue; |
| 1256 | } |
| 1257 | if (!best) { |
| 1258 | best = fcf; |
| 1259 | continue; |
| 1260 | } |
| 1261 | if (fcf->fabric_name != best->fabric_name || |
| 1262 | fcf->vfid != best->vfid || |
| 1263 | fcf->fc_map != best->fc_map) { |
Joe Eykholt | 0f51c2e | 2009-11-03 11:48:16 -0800 | [diff] [blame] | 1264 | LIBFCOE_FIP_DBG(fip, "Conflicting fabric, VFID, " |
Robert Love | 650bd12 | 2009-06-10 15:31:05 -0700 | [diff] [blame] | 1265 | "or FC-MAP\n"); |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 1266 | return; |
| 1267 | } |
| 1268 | if (fcf->pri < best->pri) |
| 1269 | best = fcf; |
| 1270 | } |
| 1271 | fip->sel_fcf = best; |
| 1272 | } |
| 1273 | |
| 1274 | /** |
Robert Love | 70b51aa | 2009-11-03 11:47:45 -0800 | [diff] [blame] | 1275 | * fcoe_ctlr_timeout() - FIP timeout handler |
| 1276 | * @arg: The FCoE controller that timed out |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 1277 | */ |
| 1278 | static void fcoe_ctlr_timeout(unsigned long arg) |
| 1279 | { |
| 1280 | struct fcoe_ctlr *fip = (struct fcoe_ctlr *)arg; |
Joe Eykholt | fdb068c | 2010-07-20 15:19:47 -0700 | [diff] [blame] | 1281 | |
| 1282 | schedule_work(&fip->timer_work); |
| 1283 | } |
| 1284 | |
| 1285 | /** |
| 1286 | * fcoe_ctlr_timer_work() - Worker thread function for timer work |
| 1287 | * @work: Handle to a FCoE controller |
| 1288 | * |
| 1289 | * Ages FCFs. Triggers FCF selection if possible. |
| 1290 | * Sends keep-alives and resets. |
| 1291 | */ |
| 1292 | static void fcoe_ctlr_timer_work(struct work_struct *work) |
| 1293 | { |
| 1294 | struct fcoe_ctlr *fip; |
| 1295 | struct fc_lport *vport; |
| 1296 | u8 *mac; |
| 1297 | u8 reset = 0; |
| 1298 | u8 send_ctlr_ka = 0; |
| 1299 | u8 send_port_ka = 0; |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 1300 | struct fcoe_fcf *sel; |
| 1301 | struct fcoe_fcf *fcf; |
Joe Eykholt | 8690cb8 | 2010-06-11 16:44:10 -0700 | [diff] [blame] | 1302 | unsigned long next_timer; |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 1303 | |
Joe Eykholt | fdb068c | 2010-07-20 15:19:47 -0700 | [diff] [blame] | 1304 | fip = container_of(work, struct fcoe_ctlr, timer_work); |
| 1305 | |
| 1306 | mutex_lock(&fip->ctlr_mutex); |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 1307 | if (fip->state == FIP_ST_DISABLED) { |
Joe Eykholt | fdb068c | 2010-07-20 15:19:47 -0700 | [diff] [blame] | 1308 | mutex_unlock(&fip->ctlr_mutex); |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 1309 | return; |
| 1310 | } |
| 1311 | |
| 1312 | fcf = fip->sel_fcf; |
Joe Eykholt | 8690cb8 | 2010-06-11 16:44:10 -0700 | [diff] [blame] | 1313 | next_timer = fcoe_ctlr_age_fcfs(fip); |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 1314 | |
| 1315 | sel = fip->sel_fcf; |
Joe Eykholt | 8690cb8 | 2010-06-11 16:44:10 -0700 | [diff] [blame] | 1316 | if (!sel && fip->sel_time) { |
| 1317 | if (time_after_eq(jiffies, fip->sel_time)) { |
| 1318 | fcoe_ctlr_select(fip); |
| 1319 | sel = fip->sel_fcf; |
| 1320 | fip->sel_time = 0; |
| 1321 | } else if (time_after(next_timer, fip->sel_time)) |
| 1322 | next_timer = fip->sel_time; |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 1323 | } |
| 1324 | |
| 1325 | if (sel != fcf) { |
| 1326 | fcf = sel; /* the old FCF may have been freed */ |
| 1327 | if (sel) { |
Robert Love | 650bd12 | 2009-06-10 15:31:05 -0700 | [diff] [blame] | 1328 | printk(KERN_INFO "libfcoe: host%d: FIP selected " |
Johannes Berg | 66d6fae | 2009-07-15 17:21:14 +0200 | [diff] [blame] | 1329 | "Fibre-Channel Forwarder MAC %pM\n", |
| 1330 | fip->lp->host->host_no, sel->fcf_mac); |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 1331 | memcpy(fip->dest_addr, sel->fcf_mac, ETH_ALEN); |
| 1332 | fip->port_ka_time = jiffies + |
Robert Love | 70b51aa | 2009-11-03 11:47:45 -0800 | [diff] [blame] | 1333 | msecs_to_jiffies(FIP_VN_KA_PERIOD); |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 1334 | fip->ctlr_ka_time = jiffies + sel->fka_period; |
Joe Eykholt | d99ee45 | 2010-06-11 16:44:15 -0700 | [diff] [blame] | 1335 | if (time_after(next_timer, fip->ctlr_ka_time)) |
| 1336 | next_timer = fip->ctlr_ka_time; |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 1337 | } else { |
Robert Love | 650bd12 | 2009-06-10 15:31:05 -0700 | [diff] [blame] | 1338 | printk(KERN_NOTICE "libfcoe: host%d: " |
Robert Love | 70b51aa | 2009-11-03 11:47:45 -0800 | [diff] [blame] | 1339 | "FIP Fibre-Channel Forwarder timed out. " |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 1340 | "Starting FCF discovery.\n", |
| 1341 | fip->lp->host->host_no); |
Joe Eykholt | fdb068c | 2010-07-20 15:19:47 -0700 | [diff] [blame] | 1342 | reset = 1; |
Joe Eykholt | 4291365 | 2010-03-12 16:08:23 -0800 | [diff] [blame] | 1343 | schedule_work(&fip->timer_work); |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 1344 | } |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 1345 | } |
| 1346 | |
Yi Zou | 8cdffdc | 2009-11-20 14:54:57 -0800 | [diff] [blame] | 1347 | if (sel && !sel->fd_flags) { |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 1348 | if (time_after_eq(jiffies, fip->ctlr_ka_time)) { |
| 1349 | fip->ctlr_ka_time = jiffies + sel->fka_period; |
Joe Eykholt | fdb068c | 2010-07-20 15:19:47 -0700 | [diff] [blame] | 1350 | send_ctlr_ka = 1; |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 1351 | } |
| 1352 | if (time_after(next_timer, fip->ctlr_ka_time)) |
| 1353 | next_timer = fip->ctlr_ka_time; |
| 1354 | |
| 1355 | if (time_after_eq(jiffies, fip->port_ka_time)) { |
Bhanu Prakash Gollapudi | f47dd85 | 2010-01-21 10:16:00 -0800 | [diff] [blame] | 1356 | fip->port_ka_time = jiffies + |
Robert Love | 70b51aa | 2009-11-03 11:47:45 -0800 | [diff] [blame] | 1357 | msecs_to_jiffies(FIP_VN_KA_PERIOD); |
Joe Eykholt | fdb068c | 2010-07-20 15:19:47 -0700 | [diff] [blame] | 1358 | send_port_ka = 1; |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 1359 | } |
| 1360 | if (time_after(next_timer, fip->port_ka_time)) |
| 1361 | next_timer = fip->port_ka_time; |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 1362 | } |
Joe Eykholt | 8690cb8 | 2010-06-11 16:44:10 -0700 | [diff] [blame] | 1363 | if (!list_empty(&fip->fcfs)) |
| 1364 | mod_timer(&fip->timer, next_timer); |
Joe Eykholt | fdb068c | 2010-07-20 15:19:47 -0700 | [diff] [blame] | 1365 | mutex_unlock(&fip->ctlr_mutex); |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 1366 | |
Bhanu Prakash Gollapudi | 516a648 | 2010-06-11 16:43:44 -0700 | [diff] [blame] | 1367 | if (reset) { |
Joe Eykholt | dd42dac | 2009-11-03 11:48:27 -0800 | [diff] [blame] | 1368 | fc_lport_reset(fip->lp); |
Bhanu Prakash Gollapudi | 516a648 | 2010-06-11 16:43:44 -0700 | [diff] [blame] | 1369 | /* restart things with a solicitation */ |
| 1370 | fcoe_ctlr_solicit(fip, NULL); |
| 1371 | } |
Chris Leech | 11b5618 | 2009-11-03 11:46:29 -0800 | [diff] [blame] | 1372 | |
Joe Eykholt | fdb068c | 2010-07-20 15:19:47 -0700 | [diff] [blame] | 1373 | if (send_ctlr_ka) |
Chris Leech | 11b5618 | 2009-11-03 11:46:29 -0800 | [diff] [blame] | 1374 | fcoe_ctlr_send_keep_alive(fip, NULL, 0, fip->ctl_src_addr); |
Joe Eykholt | fdb068c | 2010-07-20 15:19:47 -0700 | [diff] [blame] | 1375 | |
| 1376 | if (send_port_ka) { |
Chris Leech | 11b5618 | 2009-11-03 11:46:29 -0800 | [diff] [blame] | 1377 | mutex_lock(&fip->lp->lp_mutex); |
| 1378 | mac = fip->get_src_addr(fip->lp); |
| 1379 | fcoe_ctlr_send_keep_alive(fip, fip->lp, 1, mac); |
| 1380 | list_for_each_entry(vport, &fip->lp->vports, list) { |
| 1381 | mac = fip->get_src_addr(vport); |
| 1382 | fcoe_ctlr_send_keep_alive(fip, vport, 1, mac); |
| 1383 | } |
| 1384 | mutex_unlock(&fip->lp->lp_mutex); |
| 1385 | } |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 1386 | } |
| 1387 | |
| 1388 | /** |
Robert Love | 70b51aa | 2009-11-03 11:47:45 -0800 | [diff] [blame] | 1389 | * fcoe_ctlr_recv_work() - Worker thread function for receiving FIP frames |
| 1390 | * @recv_work: Handle to a FCoE controller |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 1391 | */ |
| 1392 | static void fcoe_ctlr_recv_work(struct work_struct *recv_work) |
| 1393 | { |
| 1394 | struct fcoe_ctlr *fip; |
| 1395 | struct sk_buff *skb; |
| 1396 | |
| 1397 | fip = container_of(recv_work, struct fcoe_ctlr, recv_work); |
Joe Eykholt | 1f4aed8 | 2009-11-03 11:48:22 -0800 | [diff] [blame] | 1398 | while ((skb = skb_dequeue(&fip->fip_recv_list))) |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 1399 | fcoe_ctlr_recv_handler(fip, skb); |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 1400 | } |
| 1401 | |
| 1402 | /** |
Joe Eykholt | 386309c | 2009-11-03 11:49:16 -0800 | [diff] [blame] | 1403 | * fcoe_ctlr_recv_flogi() - Snoop pre-FIP receipt of FLOGI response |
Robert Love | 70b51aa | 2009-11-03 11:47:45 -0800 | [diff] [blame] | 1404 | * @fip: The FCoE controller |
| 1405 | * @fp: The FC frame to snoop |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 1406 | * |
| 1407 | * Snoop potential response to FLOGI or even incoming FLOGI. |
| 1408 | * |
| 1409 | * The caller has checked that we are waiting for login as indicated |
| 1410 | * by fip->flogi_oxid != FC_XID_UNKNOWN. |
| 1411 | * |
| 1412 | * The caller is responsible for freeing the frame. |
Joe Eykholt | 386309c | 2009-11-03 11:49:16 -0800 | [diff] [blame] | 1413 | * Fill in the granted_mac address. |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 1414 | * |
| 1415 | * Return non-zero if the frame should not be delivered to libfc. |
| 1416 | */ |
Chris Leech | 11b5618 | 2009-11-03 11:46:29 -0800 | [diff] [blame] | 1417 | int fcoe_ctlr_recv_flogi(struct fcoe_ctlr *fip, struct fc_lport *lport, |
Joe Eykholt | 386309c | 2009-11-03 11:49:16 -0800 | [diff] [blame] | 1418 | struct fc_frame *fp) |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 1419 | { |
| 1420 | struct fc_frame_header *fh; |
| 1421 | u8 op; |
Joe Eykholt | 386309c | 2009-11-03 11:49:16 -0800 | [diff] [blame] | 1422 | u8 *sa; |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 1423 | |
Joe Eykholt | 386309c | 2009-11-03 11:49:16 -0800 | [diff] [blame] | 1424 | sa = eth_hdr(&fp->skb)->h_source; |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 1425 | fh = fc_frame_header_get(fp); |
| 1426 | if (fh->fh_type != FC_TYPE_ELS) |
| 1427 | return 0; |
| 1428 | |
| 1429 | op = fc_frame_payload_op(fp); |
| 1430 | if (op == ELS_LS_ACC && fh->fh_r_ctl == FC_RCTL_ELS_REP && |
| 1431 | fip->flogi_oxid == ntohs(fh->fh_ox_id)) { |
| 1432 | |
Joe Eykholt | fdb068c | 2010-07-20 15:19:47 -0700 | [diff] [blame] | 1433 | mutex_lock(&fip->ctlr_mutex); |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 1434 | if (fip->state != FIP_ST_AUTO && fip->state != FIP_ST_NON_FIP) { |
Joe Eykholt | fdb068c | 2010-07-20 15:19:47 -0700 | [diff] [blame] | 1435 | mutex_unlock(&fip->ctlr_mutex); |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 1436 | return -EINVAL; |
| 1437 | } |
Joe Eykholt | 9b651da | 2010-07-20 15:20:24 -0700 | [diff] [blame^] | 1438 | fcoe_ctlr_set_state(fip, FIP_ST_NON_FIP); |
Joe Eykholt | 0f51c2e | 2009-11-03 11:48:16 -0800 | [diff] [blame] | 1439 | LIBFCOE_FIP_DBG(fip, |
| 1440 | "received FLOGI LS_ACC using non-FIP mode\n"); |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 1441 | |
| 1442 | /* |
| 1443 | * FLOGI accepted. |
| 1444 | * If the src mac addr is FC_OUI-based, then we mark the |
| 1445 | * address_mode flag to use FC_OUI-based Ethernet DA. |
| 1446 | * Otherwise we use the FCoE gateway addr |
| 1447 | */ |
| 1448 | if (!compare_ether_addr(sa, (u8[6])FC_FCOE_FLOGI_MAC)) { |
| 1449 | fip->map_dest = 1; |
| 1450 | } else { |
| 1451 | memcpy(fip->dest_addr, sa, ETH_ALEN); |
| 1452 | fip->map_dest = 0; |
| 1453 | } |
| 1454 | fip->flogi_oxid = FC_XID_UNKNOWN; |
Joe Eykholt | fdb068c | 2010-07-20 15:19:47 -0700 | [diff] [blame] | 1455 | mutex_unlock(&fip->ctlr_mutex); |
Joe Eykholt | 386309c | 2009-11-03 11:49:16 -0800 | [diff] [blame] | 1456 | fc_fcoe_set_mac(fr_cb(fp)->granted_mac, fh->fh_d_id); |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 1457 | } else if (op == ELS_FLOGI && fh->fh_r_ctl == FC_RCTL_ELS_REQ && sa) { |
| 1458 | /* |
| 1459 | * Save source MAC for point-to-point responses. |
| 1460 | */ |
Joe Eykholt | fdb068c | 2010-07-20 15:19:47 -0700 | [diff] [blame] | 1461 | mutex_lock(&fip->ctlr_mutex); |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 1462 | if (fip->state == FIP_ST_AUTO || fip->state == FIP_ST_NON_FIP) { |
| 1463 | memcpy(fip->dest_addr, sa, ETH_ALEN); |
| 1464 | fip->map_dest = 0; |
Joe Eykholt | e49bf61 | 2010-03-12 16:07:57 -0800 | [diff] [blame] | 1465 | if (fip->state == FIP_ST_AUTO) |
| 1466 | LIBFCOE_FIP_DBG(fip, "received non-FIP FLOGI. " |
| 1467 | "Setting non-FIP mode\n"); |
Joe Eykholt | 9b651da | 2010-07-20 15:20:24 -0700 | [diff] [blame^] | 1468 | fcoe_ctlr_set_state(fip, FIP_ST_NON_FIP); |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 1469 | } |
Joe Eykholt | fdb068c | 2010-07-20 15:19:47 -0700 | [diff] [blame] | 1470 | mutex_unlock(&fip->ctlr_mutex); |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 1471 | } |
| 1472 | return 0; |
| 1473 | } |
| 1474 | EXPORT_SYMBOL(fcoe_ctlr_recv_flogi); |
| 1475 | |
Vasu Dev | 5e80f7f | 2009-03-17 11:42:18 -0700 | [diff] [blame] | 1476 | /** |
Robert Love | 70b51aa | 2009-11-03 11:47:45 -0800 | [diff] [blame] | 1477 | * fcoe_wwn_from_mac() - Converts a 48-bit IEEE MAC address to a 64-bit FC WWN |
| 1478 | * @mac: The MAC address to convert |
| 1479 | * @scheme: The scheme to use when converting |
| 1480 | * @port: The port indicator for converting |
Vasu Dev | 5e80f7f | 2009-03-17 11:42:18 -0700 | [diff] [blame] | 1481 | * |
| 1482 | * Returns: u64 fc world wide name |
| 1483 | */ |
| 1484 | u64 fcoe_wwn_from_mac(unsigned char mac[MAX_ADDR_LEN], |
| 1485 | unsigned int scheme, unsigned int port) |
| 1486 | { |
| 1487 | u64 wwn; |
| 1488 | u64 host_mac; |
| 1489 | |
| 1490 | /* The MAC is in NO, so flip only the low 48 bits */ |
| 1491 | host_mac = ((u64) mac[0] << 40) | |
| 1492 | ((u64) mac[1] << 32) | |
| 1493 | ((u64) mac[2] << 24) | |
| 1494 | ((u64) mac[3] << 16) | |
| 1495 | ((u64) mac[4] << 8) | |
| 1496 | (u64) mac[5]; |
| 1497 | |
| 1498 | WARN_ON(host_mac >= (1ULL << 48)); |
| 1499 | wwn = host_mac | ((u64) scheme << 60); |
| 1500 | switch (scheme) { |
| 1501 | case 1: |
| 1502 | WARN_ON(port != 0); |
| 1503 | break; |
| 1504 | case 2: |
| 1505 | WARN_ON(port >= 0xfff); |
| 1506 | wwn |= (u64) port << 48; |
| 1507 | break; |
| 1508 | default: |
| 1509 | WARN_ON(1); |
| 1510 | break; |
| 1511 | } |
| 1512 | |
| 1513 | return wwn; |
| 1514 | } |
| 1515 | EXPORT_SYMBOL_GPL(fcoe_wwn_from_mac); |
| 1516 | |
| 1517 | /** |
Robert Love | 70b51aa | 2009-11-03 11:47:45 -0800 | [diff] [blame] | 1518 | * fcoe_libfc_config() - Sets up libfc related properties for local port |
| 1519 | * @lp: The local port to configure libfc for |
| 1520 | * @tt: The libfc function template |
Vasu Dev | 5e80f7f | 2009-03-17 11:42:18 -0700 | [diff] [blame] | 1521 | * |
| 1522 | * Returns : 0 for success |
| 1523 | */ |
Robert Love | 70b51aa | 2009-11-03 11:47:45 -0800 | [diff] [blame] | 1524 | int fcoe_libfc_config(struct fc_lport *lport, |
| 1525 | struct libfc_function_template *tt) |
Vasu Dev | 5e80f7f | 2009-03-17 11:42:18 -0700 | [diff] [blame] | 1526 | { |
| 1527 | /* Set the function pointers set by the LLDD */ |
Robert Love | 70b51aa | 2009-11-03 11:47:45 -0800 | [diff] [blame] | 1528 | memcpy(&lport->tt, tt, sizeof(*tt)); |
| 1529 | if (fc_fcp_init(lport)) |
Vasu Dev | 5e80f7f | 2009-03-17 11:42:18 -0700 | [diff] [blame] | 1530 | return -ENOMEM; |
Robert Love | 70b51aa | 2009-11-03 11:47:45 -0800 | [diff] [blame] | 1531 | fc_exch_init(lport); |
| 1532 | fc_elsct_init(lport); |
| 1533 | fc_lport_init(lport); |
| 1534 | fc_rport_init(lport); |
| 1535 | fc_disc_init(lport); |
Vasu Dev | 5e80f7f | 2009-03-17 11:42:18 -0700 | [diff] [blame] | 1536 | |
| 1537 | return 0; |
| 1538 | } |
| 1539 | EXPORT_SYMBOL_GPL(fcoe_libfc_config); |
Chris Leech | 11b5618 | 2009-11-03 11:46:29 -0800 | [diff] [blame] | 1540 | |