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