aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/scsi/fcoe/libfcoe.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/scsi/fcoe/libfcoe.c')
-rw-r--r--drivers/scsi/fcoe/libfcoe.c436
1 files changed, 238 insertions, 198 deletions
diff --git a/drivers/scsi/fcoe/libfcoe.c b/drivers/scsi/fcoe/libfcoe.c
index 11ae5c94608b..3440da48d169 100644
--- a/drivers/scsi/fcoe/libfcoe.c
+++ b/drivers/scsi/fcoe/libfcoe.c
@@ -31,6 +31,7 @@
31#include <linux/if_vlan.h> 31#include <linux/if_vlan.h>
32#include <linux/errno.h> 32#include <linux/errno.h>
33#include <linux/bitops.h> 33#include <linux/bitops.h>
34#include <linux/slab.h>
34#include <net/rtnetlink.h> 35#include <net/rtnetlink.h>
35 36
36#include <scsi/fc/fc_els.h> 37#include <scsi/fc/fc_els.h>
@@ -59,26 +60,30 @@ unsigned int libfcoe_debug_logging;
59module_param_named(debug_logging, libfcoe_debug_logging, int, S_IRUGO|S_IWUSR); 60module_param_named(debug_logging, libfcoe_debug_logging, int, S_IRUGO|S_IWUSR);
60MODULE_PARM_DESC(debug_logging, "a bit mask of logging levels"); 61MODULE_PARM_DESC(debug_logging, "a bit mask of logging levels");
61 62
62#define LIBFCOE_LOGGING 0x01 /* General logging, not categorized */ 63#define LIBFCOE_LOGGING 0x01 /* General logging, not categorized */
63#define LIBFCOE_FIP_LOGGING 0x02 /* FIP logging */ 64#define LIBFCOE_FIP_LOGGING 0x02 /* FIP logging */
64 65
65#define LIBFCOE_CHECK_LOGGING(LEVEL, CMD) \ 66#define LIBFCOE_CHECK_LOGGING(LEVEL, CMD) \
66do { \ 67do { \
67 if (unlikely(libfcoe_debug_logging & LEVEL)) \ 68 if (unlikely(libfcoe_debug_logging & LEVEL)) \
68 do { \ 69 do { \
69 CMD; \ 70 CMD; \
70 } while (0); \ 71 } while (0); \
71} while (0) 72} while (0)
72 73
73#define LIBFCOE_DBG(fmt, args...) \ 74#define LIBFCOE_DBG(fmt, args...) \
74 LIBFCOE_CHECK_LOGGING(LIBFCOE_LOGGING, \ 75 LIBFCOE_CHECK_LOGGING(LIBFCOE_LOGGING, \
75 printk(KERN_INFO "libfcoe: " fmt, ##args);) 76 printk(KERN_INFO "libfcoe: " fmt, ##args);)
76 77
77#define LIBFCOE_FIP_DBG(fmt, args...) \ 78#define LIBFCOE_FIP_DBG(fip, fmt, args...) \
78 LIBFCOE_CHECK_LOGGING(LIBFCOE_FIP_LOGGING, \ 79 LIBFCOE_CHECK_LOGGING(LIBFCOE_FIP_LOGGING, \
79 printk(KERN_INFO "fip: " fmt, ##args);) 80 printk(KERN_INFO "host%d: fip: " fmt, \
81 (fip)->lp->host->host_no, ##args);)
80 82
81/* 83/**
84 * fcoe_ctlr_mtu_valid() - Check if a FCF's MTU is valid
85 * @fcf: The FCF to check
86 *
82 * Return non-zero if FCF fcoe_size has been validated. 87 * Return non-zero if FCF fcoe_size has been validated.
83 */ 88 */
84static inline int fcoe_ctlr_mtu_valid(const struct fcoe_fcf *fcf) 89static inline int fcoe_ctlr_mtu_valid(const struct fcoe_fcf *fcf)
@@ -86,7 +91,10 @@ static inline int fcoe_ctlr_mtu_valid(const struct fcoe_fcf *fcf)
86 return (fcf->flags & FIP_FL_SOL) != 0; 91 return (fcf->flags & FIP_FL_SOL) != 0;
87} 92}
88 93
89/* 94/**
95 * fcoe_ctlr_fcf_usable() - Check if a FCF is usable
96 * @fcf: The FCF to check
97 *
90 * Return non-zero if the FCF is usable. 98 * Return non-zero if the FCF is usable.
91 */ 99 */
92static inline int fcoe_ctlr_fcf_usable(struct fcoe_fcf *fcf) 100static inline int fcoe_ctlr_fcf_usable(struct fcoe_fcf *fcf)
@@ -97,12 +105,13 @@ static inline int fcoe_ctlr_fcf_usable(struct fcoe_fcf *fcf)
97} 105}
98 106
99/** 107/**
100 * fcoe_ctlr_init() - Initialize the FCoE Controller instance. 108 * fcoe_ctlr_init() - Initialize the FCoE Controller instance
101 * @fip: FCoE controller. 109 * @fip: The FCoE controller to initialize
102 */ 110 */
103void fcoe_ctlr_init(struct fcoe_ctlr *fip) 111void fcoe_ctlr_init(struct fcoe_ctlr *fip)
104{ 112{
105 fip->state = FIP_ST_LINK_WAIT; 113 fip->state = FIP_ST_LINK_WAIT;
114 fip->mode = FIP_ST_AUTO;
106 INIT_LIST_HEAD(&fip->fcfs); 115 INIT_LIST_HEAD(&fip->fcfs);
107 spin_lock_init(&fip->lock); 116 spin_lock_init(&fip->lock);
108 fip->flogi_oxid = FC_XID_UNKNOWN; 117 fip->flogi_oxid = FC_XID_UNKNOWN;
@@ -114,8 +123,8 @@ void fcoe_ctlr_init(struct fcoe_ctlr *fip)
114EXPORT_SYMBOL(fcoe_ctlr_init); 123EXPORT_SYMBOL(fcoe_ctlr_init);
115 124
116/** 125/**
117 * fcoe_ctlr_reset_fcfs() - Reset and free all FCFs for a controller. 126 * fcoe_ctlr_reset_fcfs() - Reset and free all FCFs for a controller
118 * @fip: FCoE controller. 127 * @fip: The FCoE controller whose FCFs are to be reset
119 * 128 *
120 * Called with &fcoe_ctlr lock held. 129 * Called with &fcoe_ctlr lock held.
121 */ 130 */
@@ -134,8 +143,8 @@ static void fcoe_ctlr_reset_fcfs(struct fcoe_ctlr *fip)
134} 143}
135 144
136/** 145/**
137 * fcoe_ctlr_destroy() - Disable and tear-down the FCoE controller. 146 * fcoe_ctlr_destroy() - Disable and tear down a FCoE controller
138 * @fip: FCoE controller. 147 * @fip: The FCoE controller to tear down
139 * 148 *
140 * This is called by FCoE drivers before freeing the &fcoe_ctlr. 149 * This is called by FCoE drivers before freeing the &fcoe_ctlr.
141 * 150 *
@@ -148,9 +157,7 @@ static void fcoe_ctlr_reset_fcfs(struct fcoe_ctlr *fip)
148void fcoe_ctlr_destroy(struct fcoe_ctlr *fip) 157void fcoe_ctlr_destroy(struct fcoe_ctlr *fip)
149{ 158{
150 cancel_work_sync(&fip->recv_work); 159 cancel_work_sync(&fip->recv_work);
151 spin_lock_bh(&fip->fip_recv_list.lock); 160 skb_queue_purge(&fip->fip_recv_list);
152 __skb_queue_purge(&fip->fip_recv_list);
153 spin_unlock_bh(&fip->fip_recv_list.lock);
154 161
155 spin_lock_bh(&fip->lock); 162 spin_lock_bh(&fip->lock);
156 fip->state = FIP_ST_DISABLED; 163 fip->state = FIP_ST_DISABLED;
@@ -162,8 +169,8 @@ void fcoe_ctlr_destroy(struct fcoe_ctlr *fip)
162EXPORT_SYMBOL(fcoe_ctlr_destroy); 169EXPORT_SYMBOL(fcoe_ctlr_destroy);
163 170
164/** 171/**
165 * fcoe_ctlr_fcoe_size() - Return the maximum FCoE size required for VN_Port. 172 * fcoe_ctlr_fcoe_size() - Return the maximum FCoE size required for VN_Port
166 * @fip: FCoE controller. 173 * @fip: The FCoE controller to get the maximum FCoE size from
167 * 174 *
168 * Returns the maximum packet size including the FCoE header and trailer, 175 * Returns the maximum packet size including the FCoE header and trailer,
169 * but not including any Ethernet or VLAN headers. 176 * but not including any Ethernet or VLAN headers.
@@ -180,9 +187,9 @@ static inline u32 fcoe_ctlr_fcoe_size(struct fcoe_ctlr *fip)
180} 187}
181 188
182/** 189/**
183 * fcoe_ctlr_solicit() - Send a solicitation. 190 * fcoe_ctlr_solicit() - Send a FIP solicitation
184 * @fip: FCoE controller. 191 * @fip: The FCoE controller to send the solicitation on
185 * @fcf: Destination FCF. If NULL, a multicast solicitation is sent. 192 * @fcf: The destination FCF (if NULL, a multicast solicitation is sent)
186 */ 193 */
187static void fcoe_ctlr_solicit(struct fcoe_ctlr *fip, struct fcoe_fcf *fcf) 194static void fcoe_ctlr_solicit(struct fcoe_ctlr *fip, struct fcoe_fcf *fcf)
188{ 195{
@@ -241,8 +248,8 @@ static void fcoe_ctlr_solicit(struct fcoe_ctlr *fip, struct fcoe_fcf *fcf)
241} 248}
242 249
243/** 250/**
244 * fcoe_ctlr_link_up() - Start FCoE controller. 251 * fcoe_ctlr_link_up() - Start FCoE controller
245 * @fip: FCoE controller. 252 * @fip: The FCoE controller to start
246 * 253 *
247 * Called from the LLD when the network link is ready. 254 * Called from the LLD when the network link is ready.
248 */ 255 */
@@ -255,11 +262,12 @@ void fcoe_ctlr_link_up(struct fcoe_ctlr *fip)
255 spin_unlock_bh(&fip->lock); 262 spin_unlock_bh(&fip->lock);
256 fc_linkup(fip->lp); 263 fc_linkup(fip->lp);
257 } else if (fip->state == FIP_ST_LINK_WAIT) { 264 } else if (fip->state == FIP_ST_LINK_WAIT) {
258 fip->state = FIP_ST_AUTO; 265 fip->state = fip->mode;
259 fip->last_link = 1; 266 fip->last_link = 1;
260 fip->link = 1; 267 fip->link = 1;
261 spin_unlock_bh(&fip->lock); 268 spin_unlock_bh(&fip->lock);
262 LIBFCOE_FIP_DBG("%s", "setting AUTO mode.\n"); 269 if (fip->state == FIP_ST_AUTO)
270 LIBFCOE_FIP_DBG(fip, "%s", "setting AUTO mode.\n");
263 fc_linkup(fip->lp); 271 fc_linkup(fip->lp);
264 fcoe_ctlr_solicit(fip, NULL); 272 fcoe_ctlr_solicit(fip, NULL);
265 } else 273 } else
@@ -268,45 +276,23 @@ void fcoe_ctlr_link_up(struct fcoe_ctlr *fip)
268EXPORT_SYMBOL(fcoe_ctlr_link_up); 276EXPORT_SYMBOL(fcoe_ctlr_link_up);
269 277
270/** 278/**
271 * fcoe_ctlr_reset() - Reset FIP. 279 * fcoe_ctlr_reset() - Reset a FCoE controller
272 * @fip: FCoE controller. 280 * @fip: The FCoE controller to reset
273 * @new_state: FIP state to be entered.
274 *
275 * Returns non-zero if the link was up and now isn't.
276 */ 281 */
277static int fcoe_ctlr_reset(struct fcoe_ctlr *fip, enum fip_state new_state) 282static void fcoe_ctlr_reset(struct fcoe_ctlr *fip)
278{ 283{
279 struct fc_lport *lp = fip->lp;
280 int link_dropped;
281
282 spin_lock_bh(&fip->lock);
283 fcoe_ctlr_reset_fcfs(fip); 284 fcoe_ctlr_reset_fcfs(fip);
284 del_timer(&fip->timer); 285 del_timer(&fip->timer);
285 fip->state = new_state;
286 fip->ctlr_ka_time = 0; 286 fip->ctlr_ka_time = 0;
287 fip->port_ka_time = 0; 287 fip->port_ka_time = 0;
288 fip->sol_time = 0; 288 fip->sol_time = 0;
289 fip->flogi_oxid = FC_XID_UNKNOWN; 289 fip->flogi_oxid = FC_XID_UNKNOWN;
290 fip->map_dest = 0; 290 fip->map_dest = 0;
291 fip->last_link = 0;
292 link_dropped = fip->link;
293 fip->link = 0;
294 spin_unlock_bh(&fip->lock);
295
296 if (link_dropped)
297 fc_linkdown(lp);
298
299 if (new_state == FIP_ST_ENABLED) {
300 fcoe_ctlr_solicit(fip, NULL);
301 fc_linkup(lp);
302 link_dropped = 0;
303 }
304 return link_dropped;
305} 291}
306 292
307/** 293/**
308 * fcoe_ctlr_link_down() - Stop FCoE controller. 294 * fcoe_ctlr_link_down() - Stop a FCoE controller
309 * @fip: FCoE controller. 295 * @fip: The FCoE controller to be stopped
310 * 296 *
311 * Returns non-zero if the link was up and now isn't. 297 * Returns non-zero if the link was up and now isn't.
312 * 298 *
@@ -315,15 +301,29 @@ static int fcoe_ctlr_reset(struct fcoe_ctlr *fip, enum fip_state new_state)
315 */ 301 */
316int fcoe_ctlr_link_down(struct fcoe_ctlr *fip) 302int fcoe_ctlr_link_down(struct fcoe_ctlr *fip)
317{ 303{
318 return fcoe_ctlr_reset(fip, FIP_ST_LINK_WAIT); 304 int link_dropped;
305
306 LIBFCOE_FIP_DBG(fip, "link down.\n");
307 spin_lock_bh(&fip->lock);
308 fcoe_ctlr_reset(fip);
309 link_dropped = fip->link;
310 fip->link = 0;
311 fip->last_link = 0;
312 fip->state = FIP_ST_LINK_WAIT;
313 spin_unlock_bh(&fip->lock);
314
315 if (link_dropped)
316 fc_linkdown(fip->lp);
317 return link_dropped;
319} 318}
320EXPORT_SYMBOL(fcoe_ctlr_link_down); 319EXPORT_SYMBOL(fcoe_ctlr_link_down);
321 320
322/** 321/**
323 * fcoe_ctlr_send_keep_alive() - Send a keep-alive to the selected FCF. 322 * fcoe_ctlr_send_keep_alive() - Send a keep-alive to the selected FCF
324 * @fip: FCoE controller. 323 * @fip: The FCoE controller to send the FKA on
325 * @ports: 0 for controller keep-alive, 1 for port keep-alive. 324 * @lport: libfc fc_lport to send from
326 * @sa: source MAC address. 325 * @ports: 0 for controller keep-alive, 1 for port keep-alive
326 * @sa: The source MAC address
327 * 327 *
328 * A controller keep-alive is sent every fka_period (typically 8 seconds). 328 * A controller keep-alive is sent every fka_period (typically 8 seconds).
329 * The source MAC is the native MAC address. 329 * The source MAC is the native MAC address.
@@ -332,7 +332,9 @@ EXPORT_SYMBOL(fcoe_ctlr_link_down);
332 * The source MAC is the assigned mapped source address. 332 * The source MAC is the assigned mapped source address.
333 * The destination is the FCF's F-port. 333 * The destination is the FCF's F-port.
334 */ 334 */
335static void fcoe_ctlr_send_keep_alive(struct fcoe_ctlr *fip, int ports, u8 *sa) 335static void fcoe_ctlr_send_keep_alive(struct fcoe_ctlr *fip,
336 struct fc_lport *lport,
337 int ports, u8 *sa)
336{ 338{
337 struct sk_buff *skb; 339 struct sk_buff *skb;
338 struct fip_kal { 340 struct fip_kal {
@@ -350,8 +352,7 @@ static void fcoe_ctlr_send_keep_alive(struct fcoe_ctlr *fip, int ports, u8 *sa)
350 if (!fcf || !fc_host_port_id(lp->host)) 352 if (!fcf || !fc_host_port_id(lp->host))
351 return; 353 return;
352 354
353 len = fcoe_ctlr_fcoe_size(fip) + sizeof(struct ethhdr); 355 len = sizeof(*kal) + ports * sizeof(*vn);
354 BUG_ON(len < sizeof(*kal) + sizeof(*vn));
355 skb = dev_alloc_skb(len); 356 skb = dev_alloc_skb(len);
356 if (!skb) 357 if (!skb)
357 return; 358 return;
@@ -366,7 +367,7 @@ static void fcoe_ctlr_send_keep_alive(struct fcoe_ctlr *fip, int ports, u8 *sa)
366 kal->fip.fip_op = htons(FIP_OP_CTRL); 367 kal->fip.fip_op = htons(FIP_OP_CTRL);
367 kal->fip.fip_subcode = FIP_SC_KEEP_ALIVE; 368 kal->fip.fip_subcode = FIP_SC_KEEP_ALIVE;
368 kal->fip.fip_dl_len = htons((sizeof(kal->mac) + 369 kal->fip.fip_dl_len = htons((sizeof(kal->mac) +
369 ports * sizeof(*vn)) / FIP_BPW); 370 ports * sizeof(*vn)) / FIP_BPW);
370 kal->fip.fip_flags = htons(FIP_FL_FPMA); 371 kal->fip.fip_flags = htons(FIP_FL_FPMA);
371 if (fip->spma) 372 if (fip->spma)
372 kal->fip.fip_flags |= htons(FIP_FL_SPMA); 373 kal->fip.fip_flags |= htons(FIP_FL_SPMA);
@@ -374,16 +375,14 @@ static void fcoe_ctlr_send_keep_alive(struct fcoe_ctlr *fip, int ports, u8 *sa)
374 kal->mac.fd_desc.fip_dtype = FIP_DT_MAC; 375 kal->mac.fd_desc.fip_dtype = FIP_DT_MAC;
375 kal->mac.fd_desc.fip_dlen = sizeof(kal->mac) / FIP_BPW; 376 kal->mac.fd_desc.fip_dlen = sizeof(kal->mac) / FIP_BPW;
376 memcpy(kal->mac.fd_mac, fip->ctl_src_addr, ETH_ALEN); 377 memcpy(kal->mac.fd_mac, fip->ctl_src_addr, ETH_ALEN);
377
378 if (ports) { 378 if (ports) {
379 vn = (struct fip_vn_desc *)(kal + 1); 379 vn = (struct fip_vn_desc *)(kal + 1);
380 vn->fd_desc.fip_dtype = FIP_DT_VN_ID; 380 vn->fd_desc.fip_dtype = FIP_DT_VN_ID;
381 vn->fd_desc.fip_dlen = sizeof(*vn) / FIP_BPW; 381 vn->fd_desc.fip_dlen = sizeof(*vn) / FIP_BPW;
382 memcpy(vn->fd_mac, fip->data_src_addr, ETH_ALEN); 382 memcpy(vn->fd_mac, fip->get_src_addr(lport), ETH_ALEN);
383 hton24(vn->fd_fc_id, fc_host_port_id(lp->host)); 383 hton24(vn->fd_fc_id, fc_host_port_id(lp->host));
384 put_unaligned_be64(lp->wwpn, &vn->fd_wwpn); 384 put_unaligned_be64(lp->wwpn, &vn->fd_wwpn);
385 } 385 }
386
387 skb_put(skb, len); 386 skb_put(skb, len);
388 skb->protocol = htons(ETH_P_FIP); 387 skb->protocol = htons(ETH_P_FIP);
389 skb_reset_mac_header(skb); 388 skb_reset_mac_header(skb);
@@ -392,10 +391,10 @@ static void fcoe_ctlr_send_keep_alive(struct fcoe_ctlr *fip, int ports, u8 *sa)
392} 391}
393 392
394/** 393/**
395 * fcoe_ctlr_encaps() - Encapsulate an ELS frame for FIP, without sending it. 394 * fcoe_ctlr_encaps() - Encapsulate an ELS frame for FIP, without sending it
396 * @fip: FCoE controller. 395 * @fip: The FCoE controller for the ELS frame
397 * @dtype: FIP descriptor type for the frame. 396 * @dtype: The FIP descriptor type for the frame
398 * @skb: FCoE ELS frame including FC header but no FCoE headers. 397 * @skb: The FCoE ELS frame including FC header but no FCoE headers
399 * 398 *
400 * Returns non-zero error code on failure. 399 * Returns non-zero error code on failure.
401 * 400 *
@@ -405,7 +404,7 @@ static void fcoe_ctlr_send_keep_alive(struct fcoe_ctlr *fip, int ports, u8 *sa)
405 * Headroom includes the FIP encapsulation description, FIP header, and 404 * Headroom includes the FIP encapsulation description, FIP header, and
406 * Ethernet header. The tailroom is for the FIP MAC descriptor. 405 * Ethernet header. The tailroom is for the FIP MAC descriptor.
407 */ 406 */
408static int fcoe_ctlr_encaps(struct fcoe_ctlr *fip, 407static int fcoe_ctlr_encaps(struct fcoe_ctlr *fip, struct fc_lport *lport,
409 u8 dtype, struct sk_buff *skb) 408 u8 dtype, struct sk_buff *skb)
410{ 409{
411 struct fip_encaps_head { 410 struct fip_encaps_head {
@@ -449,8 +448,8 @@ static int fcoe_ctlr_encaps(struct fcoe_ctlr *fip,
449 memset(mac, 0, sizeof(mac)); 448 memset(mac, 0, sizeof(mac));
450 mac->fd_desc.fip_dtype = FIP_DT_MAC; 449 mac->fd_desc.fip_dtype = FIP_DT_MAC;
451 mac->fd_desc.fip_dlen = sizeof(*mac) / FIP_BPW; 450 mac->fd_desc.fip_dlen = sizeof(*mac) / FIP_BPW;
452 if (dtype != FIP_DT_FLOGI) 451 if (dtype != FIP_DT_FLOGI && dtype != FIP_DT_FDISC)
453 memcpy(mac->fd_mac, fip->data_src_addr, ETH_ALEN); 452 memcpy(mac->fd_mac, fip->get_src_addr(lport), ETH_ALEN);
454 else if (fip->spma) 453 else if (fip->spma)
455 memcpy(mac->fd_mac, fip->ctl_src_addr, ETH_ALEN); 454 memcpy(mac->fd_mac, fip->ctl_src_addr, ETH_ALEN);
456 455
@@ -463,6 +462,7 @@ static int fcoe_ctlr_encaps(struct fcoe_ctlr *fip,
463/** 462/**
464 * fcoe_ctlr_els_send() - Send an ELS frame encapsulated by FIP if appropriate. 463 * fcoe_ctlr_els_send() - Send an ELS frame encapsulated by FIP if appropriate.
465 * @fip: FCoE controller. 464 * @fip: FCoE controller.
465 * @lport: libfc fc_lport to send from
466 * @skb: FCoE ELS frame including FC header but no FCoE headers. 466 * @skb: FCoE ELS frame including FC header but no FCoE headers.
467 * 467 *
468 * Returns a non-zero error code if the frame should not be sent. 468 * Returns a non-zero error code if the frame should not be sent.
@@ -471,11 +471,13 @@ static int fcoe_ctlr_encaps(struct fcoe_ctlr *fip,
471 * The caller must check that the length is a multiple of 4. 471 * The caller must check that the length is a multiple of 4.
472 * The SKB must have enough headroom (28 bytes) and tailroom (8 bytes). 472 * The SKB must have enough headroom (28 bytes) and tailroom (8 bytes).
473 */ 473 */
474int fcoe_ctlr_els_send(struct fcoe_ctlr *fip, struct sk_buff *skb) 474int fcoe_ctlr_els_send(struct fcoe_ctlr *fip, struct fc_lport *lport,
475 struct sk_buff *skb)
475{ 476{
476 struct fc_frame_header *fh; 477 struct fc_frame_header *fh;
477 u16 old_xid; 478 u16 old_xid;
478 u8 op; 479 u8 op;
480 u8 mac[ETH_ALEN];
479 481
480 fh = (struct fc_frame_header *)skb->data; 482 fh = (struct fc_frame_header *)skb->data;
481 op = *(u8 *)(fh + 1); 483 op = *(u8 *)(fh + 1);
@@ -498,6 +500,8 @@ int fcoe_ctlr_els_send(struct fcoe_ctlr *fip, struct sk_buff *skb)
498 500
499 if (fip->state == FIP_ST_NON_FIP) 501 if (fip->state == FIP_ST_NON_FIP)
500 return 0; 502 return 0;
503 if (!fip->sel_fcf)
504 goto drop;
501 505
502 switch (op) { 506 switch (op) {
503 case ELS_FLOGI: 507 case ELS_FLOGI:
@@ -530,14 +534,15 @@ int fcoe_ctlr_els_send(struct fcoe_ctlr *fip, struct sk_buff *skb)
530 * FLOGI. 534 * FLOGI.
531 */ 535 */
532 fip->flogi_oxid = FC_XID_UNKNOWN; 536 fip->flogi_oxid = FC_XID_UNKNOWN;
533 fc_fcoe_set_mac(fip->data_src_addr, fh->fh_s_id); 537 fc_fcoe_set_mac(mac, fh->fh_d_id);
538 fip->update_mac(lport, mac);
534 return 0; 539 return 0;
535 default: 540 default:
536 if (fip->state != FIP_ST_ENABLED) 541 if (fip->state != FIP_ST_ENABLED)
537 goto drop; 542 goto drop;
538 return 0; 543 return 0;
539 } 544 }
540 if (fcoe_ctlr_encaps(fip, op, skb)) 545 if (fcoe_ctlr_encaps(fip, lport, op, skb))
541 goto drop; 546 goto drop;
542 fip->send(fip, skb); 547 fip->send(fip, skb);
543 return -EINPROGRESS; 548 return -EINPROGRESS;
@@ -547,9 +552,9 @@ drop:
547} 552}
548EXPORT_SYMBOL(fcoe_ctlr_els_send); 553EXPORT_SYMBOL(fcoe_ctlr_els_send);
549 554
550/* 555/**
551 * fcoe_ctlr_age_fcfs() - Reset and free all old FCFs for a controller. 556 * fcoe_ctlr_age_fcfs() - Reset and free all old FCFs for a controller
552 * @fip: FCoE controller. 557 * @fip: The FCoE controller to free FCFs on
553 * 558 *
554 * Called with lock held. 559 * Called with lock held.
555 * 560 *
@@ -558,14 +563,28 @@ EXPORT_SYMBOL(fcoe_ctlr_els_send);
558 * times its keep-alive period including fuzz. 563 * times its keep-alive period including fuzz.
559 * 564 *
560 * In addition, determine the time when an FCF selection can occur. 565 * In addition, determine the time when an FCF selection can occur.
566 *
567 * Also, increment the MissDiscAdvCount when no advertisement is received
568 * for the corresponding FCF for 1.5 * FKA_ADV_PERIOD (FC-BB-5 LESB).
561 */ 569 */
562static void fcoe_ctlr_age_fcfs(struct fcoe_ctlr *fip) 570static void fcoe_ctlr_age_fcfs(struct fcoe_ctlr *fip)
563{ 571{
564 struct fcoe_fcf *fcf; 572 struct fcoe_fcf *fcf;
565 struct fcoe_fcf *next; 573 struct fcoe_fcf *next;
566 unsigned long sel_time = 0; 574 unsigned long sel_time = 0;
575 unsigned long mda_time = 0;
567 576
568 list_for_each_entry_safe(fcf, next, &fip->fcfs, list) { 577 list_for_each_entry_safe(fcf, next, &fip->fcfs, list) {
578 mda_time = fcf->fka_period + (fcf->fka_period >> 1);
579 if ((fip->sel_fcf == fcf) &&
580 (time_after(jiffies, fcf->time + mda_time))) {
581 mod_timer(&fip->timer, jiffies + mda_time);
582 fc_lport_get_stats(fip->lp)->MissDiscAdvCount++;
583 printk(KERN_INFO "libfcoe: host%d: Missing Discovery "
584 "Advertisement for fab %llx count %lld\n",
585 fip->lp->host->host_no, fcf->fabric_name,
586 fc_lport_get_stats(fip->lp)->MissDiscAdvCount);
587 }
569 if (time_after(jiffies, fcf->time + fcf->fka_period * 3 + 588 if (time_after(jiffies, fcf->time + fcf->fka_period * 3 +
570 msecs_to_jiffies(FIP_FCF_FUZZ * 3))) { 589 msecs_to_jiffies(FIP_FCF_FUZZ * 3))) {
571 if (fip->sel_fcf == fcf) 590 if (fip->sel_fcf == fcf)
@@ -574,6 +593,7 @@ static void fcoe_ctlr_age_fcfs(struct fcoe_ctlr *fip)
574 WARN_ON(!fip->fcf_count); 593 WARN_ON(!fip->fcf_count);
575 fip->fcf_count--; 594 fip->fcf_count--;
576 kfree(fcf); 595 kfree(fcf);
596 fc_lport_get_stats(fip->lp)->VLinkFailureCount++;
577 } else if (fcoe_ctlr_mtu_valid(fcf) && 597 } else if (fcoe_ctlr_mtu_valid(fcf) &&
578 (!sel_time || time_before(sel_time, fcf->time))) { 598 (!sel_time || time_before(sel_time, fcf->time))) {
579 sel_time = fcf->time; 599 sel_time = fcf->time;
@@ -590,14 +610,16 @@ static void fcoe_ctlr_age_fcfs(struct fcoe_ctlr *fip)
590} 610}
591 611
592/** 612/**
593 * fcoe_ctlr_parse_adv() - Decode a FIP advertisement into a new FCF entry. 613 * fcoe_ctlr_parse_adv() - Decode a FIP advertisement into a new FCF entry
594 * @skb: received FIP advertisement frame 614 * @fip: The FCoE controller receiving the advertisement
595 * @fcf: resulting FCF entry. 615 * @skb: The received FIP advertisement frame
616 * @fcf: The resulting FCF entry
596 * 617 *
597 * Returns zero on a valid parsed advertisement, 618 * Returns zero on a valid parsed advertisement,
598 * otherwise returns non zero value. 619 * otherwise returns non zero value.
599 */ 620 */
600static int fcoe_ctlr_parse_adv(struct sk_buff *skb, struct fcoe_fcf *fcf) 621static int fcoe_ctlr_parse_adv(struct fcoe_ctlr *fip,
622 struct sk_buff *skb, struct fcoe_fcf *fcf)
601{ 623{
602 struct fip_header *fiph; 624 struct fip_header *fiph;
603 struct fip_desc *desc = NULL; 625 struct fip_desc *desc = NULL;
@@ -636,7 +658,7 @@ static int fcoe_ctlr_parse_adv(struct sk_buff *skb, struct fcoe_fcf *fcf)
636 ((struct fip_mac_desc *)desc)->fd_mac, 658 ((struct fip_mac_desc *)desc)->fd_mac,
637 ETH_ALEN); 659 ETH_ALEN);
638 if (!is_valid_ether_addr(fcf->fcf_mac)) { 660 if (!is_valid_ether_addr(fcf->fcf_mac)) {
639 LIBFCOE_FIP_DBG("Invalid MAC address " 661 LIBFCOE_FIP_DBG(fip, "Invalid MAC address "
640 "in FIP adv\n"); 662 "in FIP adv\n");
641 return -EINVAL; 663 return -EINVAL;
642 } 664 }
@@ -659,6 +681,8 @@ static int fcoe_ctlr_parse_adv(struct sk_buff *skb, struct fcoe_fcf *fcf)
659 if (dlen != sizeof(struct fip_fka_desc)) 681 if (dlen != sizeof(struct fip_fka_desc))
660 goto len_err; 682 goto len_err;
661 fka = (struct fip_fka_desc *)desc; 683 fka = (struct fip_fka_desc *)desc;
684 if (fka->fd_flags & FIP_FKA_ADV_D)
685 fcf->fd_flags = 1;
662 t = ntohl(fka->fd_fka_period); 686 t = ntohl(fka->fd_fka_period);
663 if (t >= FCOE_CTLR_MIN_FKA) 687 if (t >= FCOE_CTLR_MIN_FKA)
664 fcf->fka_period = msecs_to_jiffies(t); 688 fcf->fka_period = msecs_to_jiffies(t);
@@ -670,7 +694,7 @@ static int fcoe_ctlr_parse_adv(struct sk_buff *skb, struct fcoe_fcf *fcf)
670 case FIP_DT_LOGO: 694 case FIP_DT_LOGO:
671 case FIP_DT_ELP: 695 case FIP_DT_ELP:
672 default: 696 default:
673 LIBFCOE_FIP_DBG("unexpected descriptor type %x " 697 LIBFCOE_FIP_DBG(fip, "unexpected descriptor type %x "
674 "in FIP adv\n", desc->fip_dtype); 698 "in FIP adv\n", desc->fip_dtype);
675 /* standard says ignore unknown descriptors >= 128 */ 699 /* standard says ignore unknown descriptors >= 128 */
676 if (desc->fip_dtype < FIP_DT_VENDOR_BASE) 700 if (desc->fip_dtype < FIP_DT_VENDOR_BASE)
@@ -687,15 +711,15 @@ static int fcoe_ctlr_parse_adv(struct sk_buff *skb, struct fcoe_fcf *fcf)
687 return 0; 711 return 0;
688 712
689len_err: 713len_err:
690 LIBFCOE_FIP_DBG("FIP length error in descriptor type %x len %zu\n", 714 LIBFCOE_FIP_DBG(fip, "FIP length error in descriptor type %x len %zu\n",
691 desc->fip_dtype, dlen); 715 desc->fip_dtype, dlen);
692 return -EINVAL; 716 return -EINVAL;
693} 717}
694 718
695/** 719/**
696 * fcoe_ctlr_recv_adv() - Handle an incoming advertisement. 720 * fcoe_ctlr_recv_adv() - Handle an incoming advertisement
697 * @fip: FCoE controller. 721 * @fip: The FCoE controller receiving the advertisement
698 * @skb: Received FIP packet. 722 * @skb: The received FIP packet
699 */ 723 */
700static void fcoe_ctlr_recv_adv(struct fcoe_ctlr *fip, struct sk_buff *skb) 724static void fcoe_ctlr_recv_adv(struct fcoe_ctlr *fip, struct sk_buff *skb)
701{ 725{
@@ -706,7 +730,7 @@ static void fcoe_ctlr_recv_adv(struct fcoe_ctlr *fip, struct sk_buff *skb)
706 int first = 0; 730 int first = 0;
707 int mtu_valid; 731 int mtu_valid;
708 732
709 if (fcoe_ctlr_parse_adv(skb, &new)) 733 if (fcoe_ctlr_parse_adv(fip, skb, &new))
710 return; 734 return;
711 735
712 spin_lock_bh(&fip->lock); 736 spin_lock_bh(&fip->lock);
@@ -752,7 +776,7 @@ static void fcoe_ctlr_recv_adv(struct fcoe_ctlr *fip, struct sk_buff *skb)
752 mtu_valid = fcoe_ctlr_mtu_valid(fcf); 776 mtu_valid = fcoe_ctlr_mtu_valid(fcf);
753 fcf->time = jiffies; 777 fcf->time = jiffies;
754 if (!found) { 778 if (!found) {
755 LIBFCOE_FIP_DBG("New FCF for fab %llx map %x val %d\n", 779 LIBFCOE_FIP_DBG(fip, "New FCF for fab %llx map %x val %d\n",
756 fcf->fabric_name, fcf->fc_map, mtu_valid); 780 fcf->fabric_name, fcf->fc_map, mtu_valid);
757 } 781 }
758 782
@@ -778,7 +802,7 @@ static void fcoe_ctlr_recv_adv(struct fcoe_ctlr *fip, struct sk_buff *skb)
778 */ 802 */
779 if (mtu_valid && !fip->sel_time && fcoe_ctlr_fcf_usable(fcf)) { 803 if (mtu_valid && !fip->sel_time && fcoe_ctlr_fcf_usable(fcf)) {
780 fip->sel_time = jiffies + 804 fip->sel_time = jiffies +
781 msecs_to_jiffies(FCOE_CTLR_START_DELAY); 805 msecs_to_jiffies(FCOE_CTLR_START_DELAY);
782 if (!timer_pending(&fip->timer) || 806 if (!timer_pending(&fip->timer) ||
783 time_before(fip->sel_time, fip->timer.expires)) 807 time_before(fip->sel_time, fip->timer.expires))
784 mod_timer(&fip->timer, fip->sel_time); 808 mod_timer(&fip->timer, fip->sel_time);
@@ -788,15 +812,15 @@ out:
788} 812}
789 813
790/** 814/**
791 * fcoe_ctlr_recv_els() - Handle an incoming FIP-encapsulated ELS frame. 815 * fcoe_ctlr_recv_els() - Handle an incoming FIP encapsulated ELS frame
792 * @fip: FCoE controller. 816 * @fip: The FCoE controller which received the packet
793 * @skb: Received FIP packet. 817 * @skb: The received FIP packet
794 */ 818 */
795static void fcoe_ctlr_recv_els(struct fcoe_ctlr *fip, struct sk_buff *skb) 819static void fcoe_ctlr_recv_els(struct fcoe_ctlr *fip, struct sk_buff *skb)
796{ 820{
797 struct fc_lport *lp = fip->lp; 821 struct fc_lport *lport = fip->lp;
798 struct fip_header *fiph; 822 struct fip_header *fiph;
799 struct fc_frame *fp; 823 struct fc_frame *fp = (struct fc_frame *)skb;
800 struct fc_frame_header *fh = NULL; 824 struct fc_frame_header *fh = NULL;
801 struct fip_desc *desc; 825 struct fip_desc *desc;
802 struct fip_encaps *els; 826 struct fip_encaps *els;
@@ -831,10 +855,11 @@ static void fcoe_ctlr_recv_els(struct fcoe_ctlr *fip, struct sk_buff *skb)
831 ((struct fip_mac_desc *)desc)->fd_mac, 855 ((struct fip_mac_desc *)desc)->fd_mac,
832 ETH_ALEN); 856 ETH_ALEN);
833 if (!is_valid_ether_addr(granted_mac)) { 857 if (!is_valid_ether_addr(granted_mac)) {
834 LIBFCOE_FIP_DBG("Invalid MAC address " 858 LIBFCOE_FIP_DBG(fip, "Invalid MAC address "
835 "in FIP ELS\n"); 859 "in FIP ELS\n");
836 goto drop; 860 goto drop;
837 } 861 }
862 memcpy(fr_cb(fp)->granted_mac, granted_mac, ETH_ALEN);
838 break; 863 break;
839 case FIP_DT_FLOGI: 864 case FIP_DT_FLOGI:
840 case FIP_DT_FDISC: 865 case FIP_DT_FDISC:
@@ -850,7 +875,7 @@ static void fcoe_ctlr_recv_els(struct fcoe_ctlr *fip, struct sk_buff *skb)
850 els_dtype = desc->fip_dtype; 875 els_dtype = desc->fip_dtype;
851 break; 876 break;
852 default: 877 default:
853 LIBFCOE_FIP_DBG("unexpected descriptor type %x " 878 LIBFCOE_FIP_DBG(fip, "unexpected descriptor type %x "
854 "in FIP adv\n", desc->fip_dtype); 879 "in FIP adv\n", desc->fip_dtype);
855 /* standard says ignore unknown descriptors >= 128 */ 880 /* standard says ignore unknown descriptors >= 128 */
856 if (desc->fip_dtype < FIP_DT_VENDOR_BASE) 881 if (desc->fip_dtype < FIP_DT_VENDOR_BASE)
@@ -867,11 +892,8 @@ static void fcoe_ctlr_recv_els(struct fcoe_ctlr *fip, struct sk_buff *skb)
867 892
868 if (els_dtype == FIP_DT_FLOGI && sub == FIP_SC_REP && 893 if (els_dtype == FIP_DT_FLOGI && sub == FIP_SC_REP &&
869 fip->flogi_oxid == ntohs(fh->fh_ox_id) && 894 fip->flogi_oxid == ntohs(fh->fh_ox_id) &&
870 els_op == ELS_LS_ACC && is_valid_ether_addr(granted_mac)) { 895 els_op == ELS_LS_ACC && is_valid_ether_addr(granted_mac))
871 fip->flogi_oxid = FC_XID_UNKNOWN; 896 fip->flogi_oxid = FC_XID_UNKNOWN;
872 fip->update_mac(fip, fip->data_src_addr, granted_mac);
873 memcpy(fip->data_src_addr, granted_mac, ETH_ALEN);
874 }
875 897
876 /* 898 /*
877 * Convert skb into an fc_frame containing only the ELS. 899 * Convert skb into an fc_frame containing only the ELS.
@@ -882,32 +904,32 @@ static void fcoe_ctlr_recv_els(struct fcoe_ctlr *fip, struct sk_buff *skb)
882 fc_frame_init(fp); 904 fc_frame_init(fp);
883 fr_sof(fp) = FC_SOF_I3; 905 fr_sof(fp) = FC_SOF_I3;
884 fr_eof(fp) = FC_EOF_T; 906 fr_eof(fp) = FC_EOF_T;
885 fr_dev(fp) = lp; 907 fr_dev(fp) = lport;
886 908
887 stats = fc_lport_get_stats(lp); 909 stats = fc_lport_get_stats(lport);
888 stats->RxFrames++; 910 stats->RxFrames++;
889 stats->RxWords += skb->len / FIP_BPW; 911 stats->RxWords += skb->len / FIP_BPW;
890 912
891 fc_exch_recv(lp, fp); 913 fc_exch_recv(lport, fp);
892 return; 914 return;
893 915
894len_err: 916len_err:
895 LIBFCOE_FIP_DBG("FIP length error in descriptor type %x len %zu\n", 917 LIBFCOE_FIP_DBG(fip, "FIP length error in descriptor type %x len %zu\n",
896 desc->fip_dtype, dlen); 918 desc->fip_dtype, dlen);
897drop: 919drop:
898 kfree_skb(skb); 920 kfree_skb(skb);
899} 921}
900 922
901/** 923/**
902 * fcoe_ctlr_recv_els() - Handle an incoming link reset frame. 924 * fcoe_ctlr_recv_els() - Handle an incoming link reset frame
903 * @fip: FCoE controller. 925 * @fip: The FCoE controller that received the frame
904 * @fh: Received FIP header. 926 * @fh: The received FIP header
905 * 927 *
906 * There may be multiple VN_Port descriptors. 928 * There may be multiple VN_Port descriptors.
907 * The overall length has already been checked. 929 * The overall length has already been checked.
908 */ 930 */
909static void fcoe_ctlr_recv_clr_vlink(struct fcoe_ctlr *fip, 931static void fcoe_ctlr_recv_clr_vlink(struct fcoe_ctlr *fip,
910 struct fip_header *fh) 932 struct fip_header *fh)
911{ 933{
912 struct fip_desc *desc; 934 struct fip_desc *desc;
913 struct fip_mac_desc *mp; 935 struct fip_mac_desc *mp;
@@ -916,13 +938,13 @@ static void fcoe_ctlr_recv_clr_vlink(struct fcoe_ctlr *fip,
916 size_t rlen; 938 size_t rlen;
917 size_t dlen; 939 size_t dlen;
918 struct fcoe_fcf *fcf = fip->sel_fcf; 940 struct fcoe_fcf *fcf = fip->sel_fcf;
919 struct fc_lport *lp = fip->lp; 941 struct fc_lport *lport = fip->lp;
920 u32 desc_mask; 942 u32 desc_mask;
921 943
922 LIBFCOE_FIP_DBG("Clear Virtual Link received\n"); 944 LIBFCOE_FIP_DBG(fip, "Clear Virtual Link received\n");
923 if (!fcf) 945 if (!fcf)
924 return; 946 return;
925 if (!fcf || !fc_host_port_id(lp->host)) 947 if (!fcf || !fc_host_port_id(lport->host))
926 return; 948 return;
927 949
928 /* 950 /*
@@ -958,9 +980,10 @@ static void fcoe_ctlr_recv_clr_vlink(struct fcoe_ctlr *fip,
958 if (dlen < sizeof(*vp)) 980 if (dlen < sizeof(*vp))
959 return; 981 return;
960 if (compare_ether_addr(vp->fd_mac, 982 if (compare_ether_addr(vp->fd_mac,
961 fip->data_src_addr) == 0 && 983 fip->get_src_addr(lport)) == 0 &&
962 get_unaligned_be64(&vp->fd_wwpn) == lp->wwpn && 984 get_unaligned_be64(&vp->fd_wwpn) == lport->wwpn &&
963 ntoh24(vp->fd_fc_id) == fc_host_port_id(lp->host)) 985 ntoh24(vp->fd_fc_id) ==
986 fc_host_port_id(lport->host))
964 desc_mask &= ~BIT(FIP_DT_VN_ID); 987 desc_mask &= ~BIT(FIP_DT_VN_ID);
965 break; 988 break;
966 default: 989 default:
@@ -977,33 +1000,39 @@ static void fcoe_ctlr_recv_clr_vlink(struct fcoe_ctlr *fip,
977 * reset only if all required descriptors were present and valid. 1000 * reset only if all required descriptors were present and valid.
978 */ 1001 */
979 if (desc_mask) { 1002 if (desc_mask) {
980 LIBFCOE_FIP_DBG("missing descriptors mask %x\n", desc_mask); 1003 LIBFCOE_FIP_DBG(fip, "missing descriptors mask %x\n",
1004 desc_mask);
981 } else { 1005 } else {
982 LIBFCOE_FIP_DBG("performing Clear Virtual Link\n"); 1006 LIBFCOE_FIP_DBG(fip, "performing Clear Virtual Link\n");
983 fcoe_ctlr_reset(fip, FIP_ST_ENABLED); 1007
1008 spin_lock_bh(&fip->lock);
1009 fc_lport_get_stats(lport)->VLinkFailureCount++;
1010 fcoe_ctlr_reset(fip);
1011 spin_unlock_bh(&fip->lock);
1012
1013 fc_lport_reset(fip->lp);
1014 fcoe_ctlr_solicit(fip, NULL);
984 } 1015 }
985} 1016}
986 1017
987/** 1018/**
988 * fcoe_ctlr_recv() - Receive a FIP frame. 1019 * fcoe_ctlr_recv() - Receive a FIP packet
989 * @fip: FCoE controller. 1020 * @fip: The FCoE controller that received the packet
990 * @skb: Received FIP packet. 1021 * @skb: The received FIP packet
991 * 1022 *
992 * This is called from NET_RX_SOFTIRQ. 1023 * This may be called from either NET_RX_SOFTIRQ or IRQ.
993 */ 1024 */
994void fcoe_ctlr_recv(struct fcoe_ctlr *fip, struct sk_buff *skb) 1025void fcoe_ctlr_recv(struct fcoe_ctlr *fip, struct sk_buff *skb)
995{ 1026{
996 spin_lock_bh(&fip->fip_recv_list.lock); 1027 skb_queue_tail(&fip->fip_recv_list, skb);
997 __skb_queue_tail(&fip->fip_recv_list, skb);
998 spin_unlock_bh(&fip->fip_recv_list.lock);
999 schedule_work(&fip->recv_work); 1028 schedule_work(&fip->recv_work);
1000} 1029}
1001EXPORT_SYMBOL(fcoe_ctlr_recv); 1030EXPORT_SYMBOL(fcoe_ctlr_recv);
1002 1031
1003/** 1032/**
1004 * fcoe_ctlr_recv_handler() - Receive a FIP frame. 1033 * fcoe_ctlr_recv_handler() - Receive a FIP frame
1005 * @fip: FCoE controller. 1034 * @fip: The FCoE controller that received the frame
1006 * @skb: Received FIP packet. 1035 * @skb: The received FIP frame
1007 * 1036 *
1008 * Returns non-zero if the frame is dropped. 1037 * Returns non-zero if the frame is dropped.
1009 */ 1038 */
@@ -1038,7 +1067,7 @@ static int fcoe_ctlr_recv_handler(struct fcoe_ctlr *fip, struct sk_buff *skb)
1038 fip->map_dest = 0; 1067 fip->map_dest = 0;
1039 fip->state = FIP_ST_ENABLED; 1068 fip->state = FIP_ST_ENABLED;
1040 state = FIP_ST_ENABLED; 1069 state = FIP_ST_ENABLED;
1041 LIBFCOE_FIP_DBG("Using FIP mode\n"); 1070 LIBFCOE_FIP_DBG(fip, "Using FIP mode\n");
1042 } 1071 }
1043 spin_unlock_bh(&fip->lock); 1072 spin_unlock_bh(&fip->lock);
1044 if (state != FIP_ST_ENABLED) 1073 if (state != FIP_ST_ENABLED)
@@ -1060,8 +1089,8 @@ drop:
1060} 1089}
1061 1090
1062/** 1091/**
1063 * fcoe_ctlr_select() - Select the best FCF, if possible. 1092 * fcoe_ctlr_select() - Select the best FCF (if possible)
1064 * @fip: FCoE controller. 1093 * @fip: The FCoE controller
1065 * 1094 *
1066 * If there are conflicting advertisements, no FCF can be chosen. 1095 * If there are conflicting advertisements, no FCF can be chosen.
1067 * 1096 *
@@ -1073,11 +1102,11 @@ static void fcoe_ctlr_select(struct fcoe_ctlr *fip)
1073 struct fcoe_fcf *best = NULL; 1102 struct fcoe_fcf *best = NULL;
1074 1103
1075 list_for_each_entry(fcf, &fip->fcfs, list) { 1104 list_for_each_entry(fcf, &fip->fcfs, list) {
1076 LIBFCOE_FIP_DBG("consider FCF for fab %llx VFID %d map %x " 1105 LIBFCOE_FIP_DBG(fip, "consider FCF for fab %llx VFID %d map %x "
1077 "val %d\n", fcf->fabric_name, fcf->vfid, 1106 "val %d\n", fcf->fabric_name, fcf->vfid,
1078 fcf->fc_map, fcoe_ctlr_mtu_valid(fcf)); 1107 fcf->fc_map, fcoe_ctlr_mtu_valid(fcf));
1079 if (!fcoe_ctlr_fcf_usable(fcf)) { 1108 if (!fcoe_ctlr_fcf_usable(fcf)) {
1080 LIBFCOE_FIP_DBG("FCF for fab %llx map %x %svalid " 1109 LIBFCOE_FIP_DBG(fip, "FCF for fab %llx map %x %svalid "
1081 "%savailable\n", fcf->fabric_name, 1110 "%savailable\n", fcf->fabric_name,
1082 fcf->fc_map, (fcf->flags & FIP_FL_SOL) 1111 fcf->fc_map, (fcf->flags & FIP_FL_SOL)
1083 ? "" : "in", (fcf->flags & FIP_FL_AVAIL) 1112 ? "" : "in", (fcf->flags & FIP_FL_AVAIL)
@@ -1091,7 +1120,7 @@ static void fcoe_ctlr_select(struct fcoe_ctlr *fip)
1091 if (fcf->fabric_name != best->fabric_name || 1120 if (fcf->fabric_name != best->fabric_name ||
1092 fcf->vfid != best->vfid || 1121 fcf->vfid != best->vfid ||
1093 fcf->fc_map != best->fc_map) { 1122 fcf->fc_map != best->fc_map) {
1094 LIBFCOE_FIP_DBG("Conflicting fabric, VFID, " 1123 LIBFCOE_FIP_DBG(fip, "Conflicting fabric, VFID, "
1095 "or FC-MAP\n"); 1124 "or FC-MAP\n");
1096 return; 1125 return;
1097 } 1126 }
@@ -1102,8 +1131,8 @@ static void fcoe_ctlr_select(struct fcoe_ctlr *fip)
1102} 1131}
1103 1132
1104/** 1133/**
1105 * fcoe_ctlr_timeout() - FIP timer function. 1134 * fcoe_ctlr_timeout() - FIP timeout handler
1106 * @arg: &fcoe_ctlr pointer. 1135 * @arg: The FCoE controller that timed out
1107 * 1136 *
1108 * Ages FCFs. Triggers FCF selection if possible. Sends keep-alives. 1137 * Ages FCFs. Triggers FCF selection if possible. Sends keep-alives.
1109 */ 1138 */
@@ -1113,8 +1142,6 @@ static void fcoe_ctlr_timeout(unsigned long arg)
1113 struct fcoe_fcf *sel; 1142 struct fcoe_fcf *sel;
1114 struct fcoe_fcf *fcf; 1143 struct fcoe_fcf *fcf;
1115 unsigned long next_timer = jiffies + msecs_to_jiffies(FIP_VN_KA_PERIOD); 1144 unsigned long next_timer = jiffies + msecs_to_jiffies(FIP_VN_KA_PERIOD);
1116 u8 send_ctlr_ka;
1117 u8 send_port_ka;
1118 1145
1119 spin_lock_bh(&fip->lock); 1146 spin_lock_bh(&fip->lock);
1120 if (fip->state == FIP_ST_DISABLED) { 1147 if (fip->state == FIP_ST_DISABLED) {
@@ -1140,53 +1167,47 @@ static void fcoe_ctlr_timeout(unsigned long arg)
1140 fip->lp->host->host_no, sel->fcf_mac); 1167 fip->lp->host->host_no, sel->fcf_mac);
1141 memcpy(fip->dest_addr, sel->fcf_mac, ETH_ALEN); 1168 memcpy(fip->dest_addr, sel->fcf_mac, ETH_ALEN);
1142 fip->port_ka_time = jiffies + 1169 fip->port_ka_time = jiffies +
1143 msecs_to_jiffies(FIP_VN_KA_PERIOD); 1170 msecs_to_jiffies(FIP_VN_KA_PERIOD);
1144 fip->ctlr_ka_time = jiffies + sel->fka_period; 1171 fip->ctlr_ka_time = jiffies + sel->fka_period;
1145 fip->link = 1;
1146 } else { 1172 } else {
1147 printk(KERN_NOTICE "libfcoe: host%d: " 1173 printk(KERN_NOTICE "libfcoe: host%d: "
1148 "FIP Fibre-Channel Forwarder timed out. " 1174 "FIP Fibre-Channel Forwarder timed out. "
1149 "Starting FCF discovery.\n", 1175 "Starting FCF discovery.\n",
1150 fip->lp->host->host_no); 1176 fip->lp->host->host_no);
1151 fip->link = 0; 1177 fip->reset_req = 1;
1178 schedule_work(&fip->link_work);
1152 } 1179 }
1153 schedule_work(&fip->link_work);
1154 } 1180 }
1155 1181
1156 send_ctlr_ka = 0; 1182 if (sel && !sel->fd_flags) {
1157 send_port_ka = 0;
1158 if (sel) {
1159 if (time_after_eq(jiffies, fip->ctlr_ka_time)) { 1183 if (time_after_eq(jiffies, fip->ctlr_ka_time)) {
1160 fip->ctlr_ka_time = jiffies + sel->fka_period; 1184 fip->ctlr_ka_time = jiffies + sel->fka_period;
1161 send_ctlr_ka = 1; 1185 fip->send_ctlr_ka = 1;
1162 } 1186 }
1163 if (time_after(next_timer, fip->ctlr_ka_time)) 1187 if (time_after(next_timer, fip->ctlr_ka_time))
1164 next_timer = fip->ctlr_ka_time; 1188 next_timer = fip->ctlr_ka_time;
1165 1189
1166 if (time_after_eq(jiffies, fip->port_ka_time)) { 1190 if (time_after_eq(jiffies, fip->port_ka_time)) {
1167 fip->port_ka_time += jiffies + 1191 fip->port_ka_time = jiffies +
1168 msecs_to_jiffies(FIP_VN_KA_PERIOD); 1192 msecs_to_jiffies(FIP_VN_KA_PERIOD);
1169 send_port_ka = 1; 1193 fip->send_port_ka = 1;
1170 } 1194 }
1171 if (time_after(next_timer, fip->port_ka_time)) 1195 if (time_after(next_timer, fip->port_ka_time))
1172 next_timer = fip->port_ka_time; 1196 next_timer = fip->port_ka_time;
1173 mod_timer(&fip->timer, next_timer); 1197 mod_timer(&fip->timer, next_timer);
1174 } else if (fip->sel_time) { 1198 } else if (fip->sel_time) {
1175 next_timer = fip->sel_time + 1199 next_timer = fip->sel_time +
1176 msecs_to_jiffies(FCOE_CTLR_START_DELAY); 1200 msecs_to_jiffies(FCOE_CTLR_START_DELAY);
1177 mod_timer(&fip->timer, next_timer); 1201 mod_timer(&fip->timer, next_timer);
1178 } 1202 }
1203 if (fip->send_ctlr_ka || fip->send_port_ka)
1204 schedule_work(&fip->link_work);
1179 spin_unlock_bh(&fip->lock); 1205 spin_unlock_bh(&fip->lock);
1180
1181 if (send_ctlr_ka)
1182 fcoe_ctlr_send_keep_alive(fip, 0, fip->ctl_src_addr);
1183 if (send_port_ka)
1184 fcoe_ctlr_send_keep_alive(fip, 1, fip->data_src_addr);
1185} 1206}
1186 1207
1187/** 1208/**
1188 * fcoe_ctlr_link_work() - worker thread function for link changes. 1209 * fcoe_ctlr_link_work() - Worker thread function for link changes
1189 * @work: pointer to link_work member inside &fcoe_ctlr. 1210 * @work: Handle to a FCoE controller
1190 * 1211 *
1191 * See if the link status has changed and if so, report it. 1212 * See if the link status has changed and if so, report it.
1192 * 1213 *
@@ -1196,27 +1217,49 @@ static void fcoe_ctlr_timeout(unsigned long arg)
1196static void fcoe_ctlr_link_work(struct work_struct *work) 1217static void fcoe_ctlr_link_work(struct work_struct *work)
1197{ 1218{
1198 struct fcoe_ctlr *fip; 1219 struct fcoe_ctlr *fip;
1220 struct fc_lport *vport;
1221 u8 *mac;
1199 int link; 1222 int link;
1200 int last_link; 1223 int last_link;
1224 int reset;
1201 1225
1202 fip = container_of(work, struct fcoe_ctlr, link_work); 1226 fip = container_of(work, struct fcoe_ctlr, link_work);
1203 spin_lock_bh(&fip->lock); 1227 spin_lock_bh(&fip->lock);
1204 last_link = fip->last_link; 1228 last_link = fip->last_link;
1205 link = fip->link; 1229 link = fip->link;
1206 fip->last_link = link; 1230 fip->last_link = link;
1231 reset = fip->reset_req;
1232 fip->reset_req = 0;
1207 spin_unlock_bh(&fip->lock); 1233 spin_unlock_bh(&fip->lock);
1208 1234
1209 if (last_link != link) { 1235 if (last_link != link) {
1210 if (link) 1236 if (link)
1211 fc_linkup(fip->lp); 1237 fc_linkup(fip->lp);
1212 else 1238 else
1213 fcoe_ctlr_reset(fip, FIP_ST_LINK_WAIT); 1239 fc_linkdown(fip->lp);
1240 } else if (reset && link)
1241 fc_lport_reset(fip->lp);
1242
1243 if (fip->send_ctlr_ka) {
1244 fip->send_ctlr_ka = 0;
1245 fcoe_ctlr_send_keep_alive(fip, NULL, 0, fip->ctl_src_addr);
1246 }
1247 if (fip->send_port_ka) {
1248 fip->send_port_ka = 0;
1249 mutex_lock(&fip->lp->lp_mutex);
1250 mac = fip->get_src_addr(fip->lp);
1251 fcoe_ctlr_send_keep_alive(fip, fip->lp, 1, mac);
1252 list_for_each_entry(vport, &fip->lp->vports, list) {
1253 mac = fip->get_src_addr(vport);
1254 fcoe_ctlr_send_keep_alive(fip, vport, 1, mac);
1255 }
1256 mutex_unlock(&fip->lp->lp_mutex);
1214 } 1257 }
1215} 1258}
1216 1259
1217/** 1260/**
1218 * fcoe_ctlr_recv_work() - Worker thread function for receiving FIP frames. 1261 * fcoe_ctlr_recv_work() - Worker thread function for receiving FIP frames
1219 * @recv_work: pointer to recv_work member inside &fcoe_ctlr. 1262 * @recv_work: Handle to a FCoE controller
1220 */ 1263 */
1221static void fcoe_ctlr_recv_work(struct work_struct *recv_work) 1264static void fcoe_ctlr_recv_work(struct work_struct *recv_work)
1222{ 1265{
@@ -1224,20 +1267,14 @@ static void fcoe_ctlr_recv_work(struct work_struct *recv_work)
1224 struct sk_buff *skb; 1267 struct sk_buff *skb;
1225 1268
1226 fip = container_of(recv_work, struct fcoe_ctlr, recv_work); 1269 fip = container_of(recv_work, struct fcoe_ctlr, recv_work);
1227 spin_lock_bh(&fip->fip_recv_list.lock); 1270 while ((skb = skb_dequeue(&fip->fip_recv_list)))
1228 while ((skb = __skb_dequeue(&fip->fip_recv_list))) {
1229 spin_unlock_bh(&fip->fip_recv_list.lock);
1230 fcoe_ctlr_recv_handler(fip, skb); 1271 fcoe_ctlr_recv_handler(fip, skb);
1231 spin_lock_bh(&fip->fip_recv_list.lock);
1232 }
1233 spin_unlock_bh(&fip->fip_recv_list.lock);
1234} 1272}
1235 1273
1236/** 1274/**
1237 * fcoe_ctlr_recv_flogi() - snoop Pre-FIP receipt of FLOGI response or request. 1275 * fcoe_ctlr_recv_flogi() - Snoop pre-FIP receipt of FLOGI response
1238 * @fip: FCoE controller. 1276 * @fip: The FCoE controller
1239 * @fp: FC frame. 1277 * @fp: The FC frame to snoop
1240 * @sa: Ethernet source MAC address from received FCoE frame.
1241 * 1278 *
1242 * Snoop potential response to FLOGI or even incoming FLOGI. 1279 * Snoop potential response to FLOGI or even incoming FLOGI.
1243 * 1280 *
@@ -1245,15 +1282,18 @@ static void fcoe_ctlr_recv_work(struct work_struct *recv_work)
1245 * by fip->flogi_oxid != FC_XID_UNKNOWN. 1282 * by fip->flogi_oxid != FC_XID_UNKNOWN.
1246 * 1283 *
1247 * The caller is responsible for freeing the frame. 1284 * The caller is responsible for freeing the frame.
1285 * Fill in the granted_mac address.
1248 * 1286 *
1249 * Return non-zero if the frame should not be delivered to libfc. 1287 * Return non-zero if the frame should not be delivered to libfc.
1250 */ 1288 */
1251int fcoe_ctlr_recv_flogi(struct fcoe_ctlr *fip, struct fc_frame *fp, u8 *sa) 1289int fcoe_ctlr_recv_flogi(struct fcoe_ctlr *fip, struct fc_lport *lport,
1290 struct fc_frame *fp)
1252{ 1291{
1253 struct fc_frame_header *fh; 1292 struct fc_frame_header *fh;
1254 u8 op; 1293 u8 op;
1255 u8 mac[ETH_ALEN]; 1294 u8 *sa;
1256 1295
1296 sa = eth_hdr(&fp->skb)->h_source;
1257 fh = fc_frame_header_get(fp); 1297 fh = fc_frame_header_get(fp);
1258 if (fh->fh_type != FC_TYPE_ELS) 1298 if (fh->fh_type != FC_TYPE_ELS)
1259 return 0; 1299 return 0;
@@ -1268,7 +1308,8 @@ int fcoe_ctlr_recv_flogi(struct fcoe_ctlr *fip, struct fc_frame *fp, u8 *sa)
1268 return -EINVAL; 1308 return -EINVAL;
1269 } 1309 }
1270 fip->state = FIP_ST_NON_FIP; 1310 fip->state = FIP_ST_NON_FIP;
1271 LIBFCOE_FIP_DBG("received FLOGI LS_ACC using non-FIP mode\n"); 1311 LIBFCOE_FIP_DBG(fip,
1312 "received FLOGI LS_ACC using non-FIP mode\n");
1272 1313
1273 /* 1314 /*
1274 * FLOGI accepted. 1315 * FLOGI accepted.
@@ -1283,11 +1324,8 @@ int fcoe_ctlr_recv_flogi(struct fcoe_ctlr *fip, struct fc_frame *fp, u8 *sa)
1283 fip->map_dest = 0; 1324 fip->map_dest = 0;
1284 } 1325 }
1285 fip->flogi_oxid = FC_XID_UNKNOWN; 1326 fip->flogi_oxid = FC_XID_UNKNOWN;
1286 memcpy(mac, fip->data_src_addr, ETH_ALEN);
1287 fc_fcoe_set_mac(fip->data_src_addr, fh->fh_d_id);
1288 spin_unlock_bh(&fip->lock); 1327 spin_unlock_bh(&fip->lock);
1289 1328 fc_fcoe_set_mac(fr_cb(fp)->granted_mac, fh->fh_d_id);
1290 fip->update_mac(fip, mac, fip->data_src_addr);
1291 } else if (op == ELS_FLOGI && fh->fh_r_ctl == FC_RCTL_ELS_REQ && sa) { 1329 } else if (op == ELS_FLOGI && fh->fh_r_ctl == FC_RCTL_ELS_REQ && sa) {
1292 /* 1330 /*
1293 * Save source MAC for point-to-point responses. 1331 * Save source MAC for point-to-point responses.
@@ -1297,7 +1335,7 @@ int fcoe_ctlr_recv_flogi(struct fcoe_ctlr *fip, struct fc_frame *fp, u8 *sa)
1297 memcpy(fip->dest_addr, sa, ETH_ALEN); 1335 memcpy(fip->dest_addr, sa, ETH_ALEN);
1298 fip->map_dest = 0; 1336 fip->map_dest = 0;
1299 if (fip->state == FIP_ST_NON_FIP) 1337 if (fip->state == FIP_ST_NON_FIP)
1300 LIBFCOE_FIP_DBG("received FLOGI REQ, " 1338 LIBFCOE_FIP_DBG(fip, "received FLOGI REQ, "
1301 "using non-FIP mode\n"); 1339 "using non-FIP mode\n");
1302 fip->state = FIP_ST_NON_FIP; 1340 fip->state = FIP_ST_NON_FIP;
1303 } 1341 }
@@ -1308,10 +1346,10 @@ int fcoe_ctlr_recv_flogi(struct fcoe_ctlr *fip, struct fc_frame *fp, u8 *sa)
1308EXPORT_SYMBOL(fcoe_ctlr_recv_flogi); 1346EXPORT_SYMBOL(fcoe_ctlr_recv_flogi);
1309 1347
1310/** 1348/**
1311 * fcoe_wwn_from_mac() - Converts 48-bit IEEE MAC address to 64-bit FC WWN. 1349 * fcoe_wwn_from_mac() - Converts a 48-bit IEEE MAC address to a 64-bit FC WWN
1312 * @mac: mac address 1350 * @mac: The MAC address to convert
1313 * @scheme: check port 1351 * @scheme: The scheme to use when converting
1314 * @port: port indicator for converting 1352 * @port: The port indicator for converting
1315 * 1353 *
1316 * Returns: u64 fc world wide name 1354 * Returns: u64 fc world wide name
1317 */ 1355 */
@@ -1349,24 +1387,26 @@ u64 fcoe_wwn_from_mac(unsigned char mac[MAX_ADDR_LEN],
1349EXPORT_SYMBOL_GPL(fcoe_wwn_from_mac); 1387EXPORT_SYMBOL_GPL(fcoe_wwn_from_mac);
1350 1388
1351/** 1389/**
1352 * fcoe_libfc_config() - sets up libfc related properties for lport 1390 * fcoe_libfc_config() - Sets up libfc related properties for local port
1353 * @lp: ptr to the fc_lport 1391 * @lp: The local port to configure libfc for
1354 * @tt: libfc function template 1392 * @tt: The libfc function template
1355 * 1393 *
1356 * Returns : 0 for success 1394 * Returns : 0 for success
1357 */ 1395 */
1358int fcoe_libfc_config(struct fc_lport *lp, struct libfc_function_template *tt) 1396int fcoe_libfc_config(struct fc_lport *lport,
1397 struct libfc_function_template *tt)
1359{ 1398{
1360 /* Set the function pointers set by the LLDD */ 1399 /* Set the function pointers set by the LLDD */
1361 memcpy(&lp->tt, tt, sizeof(*tt)); 1400 memcpy(&lport->tt, tt, sizeof(*tt));
1362 if (fc_fcp_init(lp)) 1401 if (fc_fcp_init(lport))
1363 return -ENOMEM; 1402 return -ENOMEM;
1364 fc_exch_init(lp); 1403 fc_exch_init(lport);
1365 fc_elsct_init(lp); 1404 fc_elsct_init(lport);
1366 fc_lport_init(lp); 1405 fc_lport_init(lport);
1367 fc_rport_init(lp); 1406 fc_rport_init(lport);
1368 fc_disc_init(lp); 1407 fc_disc_init(lport);
1369 1408
1370 return 0; 1409 return 0;
1371} 1410}
1372EXPORT_SYMBOL_GPL(fcoe_libfc_config); 1411EXPORT_SYMBOL_GPL(fcoe_libfc_config);
1412