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