Robert Love | 85b4aa4 | 2008-12-09 15:10:24 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright(c) 2007 - 2008 Intel Corporation. All rights reserved. |
| 3 | * |
| 4 | * This program is free software; you can redistribute it and/or modify it |
| 5 | * under the terms and conditions of the GNU General Public License, |
| 6 | * version 2, as published by the Free Software Foundation. |
| 7 | * |
| 8 | * This program is distributed in the hope it will be useful, but WITHOUT |
| 9 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 10 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
| 11 | * more details. |
| 12 | * |
| 13 | * You should have received a copy of the GNU General Public License along with |
| 14 | * this program; if not, write to the Free Software Foundation, Inc., |
| 15 | * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA. |
| 16 | * |
| 17 | * Maintained at www.Open-FCoE.org |
| 18 | */ |
| 19 | |
| 20 | #include <linux/module.h> |
| 21 | #include <linux/version.h> |
| 22 | #include <linux/kernel.h> |
| 23 | #include <linux/spinlock.h> |
| 24 | #include <linux/skbuff.h> |
| 25 | #include <linux/netdevice.h> |
| 26 | #include <linux/etherdevice.h> |
| 27 | #include <linux/ethtool.h> |
| 28 | #include <linux/if_ether.h> |
| 29 | #include <linux/if_vlan.h> |
| 30 | #include <linux/kthread.h> |
| 31 | #include <linux/crc32.h> |
| 32 | #include <linux/cpu.h> |
| 33 | #include <linux/fs.h> |
| 34 | #include <linux/sysfs.h> |
| 35 | #include <linux/ctype.h> |
| 36 | #include <scsi/scsi_tcq.h> |
| 37 | #include <scsi/scsicam.h> |
| 38 | #include <scsi/scsi_transport.h> |
| 39 | #include <scsi/scsi_transport_fc.h> |
| 40 | #include <net/rtnetlink.h> |
| 41 | |
| 42 | #include <scsi/fc/fc_encaps.h> |
| 43 | |
| 44 | #include <scsi/libfc.h> |
| 45 | #include <scsi/fc_frame.h> |
| 46 | #include <scsi/libfcoe.h> |
| 47 | #include <scsi/fc_transport_fcoe.h> |
| 48 | |
| 49 | static int debug_fcoe; |
| 50 | |
| 51 | #define FCOE_MAX_QUEUE_DEPTH 256 |
Vasu Dev | c826a31 | 2009-02-27 10:56:27 -0800 | [diff] [blame] | 52 | #define FCOE_LOW_QUEUE_DEPTH 32 |
Robert Love | 85b4aa4 | 2008-12-09 15:10:24 -0800 | [diff] [blame] | 53 | |
| 54 | /* destination address mode */ |
| 55 | #define FCOE_GW_ADDR_MODE 0x00 |
| 56 | #define FCOE_FCOUI_ADDR_MODE 0x01 |
| 57 | |
| 58 | #define FCOE_WORD_TO_BYTE 4 |
| 59 | |
| 60 | MODULE_AUTHOR("Open-FCoE.org"); |
| 61 | MODULE_DESCRIPTION("FCoE"); |
| 62 | MODULE_LICENSE("GPL"); |
| 63 | |
| 64 | /* fcoe host list */ |
| 65 | LIST_HEAD(fcoe_hostlist); |
| 66 | DEFINE_RWLOCK(fcoe_hostlist_lock); |
| 67 | DEFINE_TIMER(fcoe_timer, NULL, 0, 0); |
Robert Love | 5e5e92d | 2009-03-17 11:41:35 -0700 | [diff] [blame] | 68 | DEFINE_PER_CPU(struct fcoe_percpu_s, fcoe_percpu); |
Robert Love | 85b4aa4 | 2008-12-09 15:10:24 -0800 | [diff] [blame] | 69 | |
| 70 | |
| 71 | /* Function Prototyes */ |
| 72 | static int fcoe_check_wait_queue(struct fc_lport *); |
Robert Love | 85b4aa4 | 2008-12-09 15:10:24 -0800 | [diff] [blame] | 73 | static void fcoe_recv_flogi(struct fcoe_softc *, struct fc_frame *, u8 *); |
Robert Love | 85b4aa4 | 2008-12-09 15:10:24 -0800 | [diff] [blame] | 74 | static int fcoe_device_notification(struct notifier_block *, ulong, void *); |
| 75 | static void fcoe_dev_setup(void); |
| 76 | static void fcoe_dev_cleanup(void); |
| 77 | |
| 78 | /* notification function from net device */ |
| 79 | static struct notifier_block fcoe_notifier = { |
| 80 | .notifier_call = fcoe_device_notification, |
| 81 | }; |
| 82 | |
Robert Love | 85b4aa4 | 2008-12-09 15:10:24 -0800 | [diff] [blame] | 83 | /** |
Robert Love | 34f42a0 | 2009-02-27 10:55:45 -0800 | [diff] [blame] | 84 | * fcoe_rcv() - this is the fcoe receive function called by NET_RX_SOFTIRQ |
Robert Love | 85b4aa4 | 2008-12-09 15:10:24 -0800 | [diff] [blame] | 85 | * @skb: the receive skb |
| 86 | * @dev: associated net device |
| 87 | * @ptype: context |
| 88 | * @odldev: last device |
| 89 | * |
| 90 | * this function will receive the packet and build fc frame and pass it up |
| 91 | * |
| 92 | * Returns: 0 for success |
Robert Love | 34f42a0 | 2009-02-27 10:55:45 -0800 | [diff] [blame] | 93 | */ |
Robert Love | 85b4aa4 | 2008-12-09 15:10:24 -0800 | [diff] [blame] | 94 | int fcoe_rcv(struct sk_buff *skb, struct net_device *dev, |
| 95 | struct packet_type *ptype, struct net_device *olddev) |
| 96 | { |
| 97 | struct fc_lport *lp; |
| 98 | struct fcoe_rcv_info *fr; |
| 99 | struct fcoe_softc *fc; |
Robert Love | 85b4aa4 | 2008-12-09 15:10:24 -0800 | [diff] [blame] | 100 | struct fc_frame_header *fh; |
Robert Love | 85b4aa4 | 2008-12-09 15:10:24 -0800 | [diff] [blame] | 101 | struct fcoe_percpu_s *fps; |
Robert Love | 38eccab | 2009-03-17 11:41:30 -0700 | [diff] [blame] | 102 | unsigned short oxid; |
| 103 | unsigned int cpu_idx; |
Robert Love | 85b4aa4 | 2008-12-09 15:10:24 -0800 | [diff] [blame] | 104 | |
| 105 | fc = container_of(ptype, struct fcoe_softc, fcoe_packet_type); |
| 106 | lp = fc->lp; |
| 107 | if (unlikely(lp == NULL)) { |
| 108 | FC_DBG("cannot find hba structure"); |
| 109 | goto err2; |
| 110 | } |
| 111 | |
| 112 | if (unlikely(debug_fcoe)) { |
| 113 | FC_DBG("skb_info: len:%d data_len:%d head:%p data:%p tail:%p " |
| 114 | "end:%p sum:%d dev:%s", skb->len, skb->data_len, |
| 115 | skb->head, skb->data, skb_tail_pointer(skb), |
| 116 | skb_end_pointer(skb), skb->csum, |
| 117 | skb->dev ? skb->dev->name : "<NULL>"); |
| 118 | |
| 119 | } |
| 120 | |
| 121 | /* check for FCOE packet type */ |
| 122 | if (unlikely(eth_hdr(skb)->h_proto != htons(ETH_P_FCOE))) { |
| 123 | FC_DBG("wrong FC type frame"); |
| 124 | goto err; |
| 125 | } |
| 126 | |
| 127 | /* |
| 128 | * Check for minimum frame length, and make sure required FCoE |
| 129 | * and FC headers are pulled into the linear data area. |
| 130 | */ |
| 131 | if (unlikely((skb->len < FCOE_MIN_FRAME) || |
| 132 | !pskb_may_pull(skb, FCOE_HEADER_LEN))) |
| 133 | goto err; |
| 134 | |
| 135 | skb_set_transport_header(skb, sizeof(struct fcoe_hdr)); |
| 136 | fh = (struct fc_frame_header *) skb_transport_header(skb); |
| 137 | |
| 138 | oxid = ntohs(fh->fh_ox_id); |
| 139 | |
| 140 | fr = fcoe_dev_from_skb(skb); |
| 141 | fr->fr_dev = lp; |
| 142 | fr->ptype = ptype; |
| 143 | cpu_idx = 0; |
Robert Love | 5e5e92d | 2009-03-17 11:41:35 -0700 | [diff] [blame] | 144 | |
Robert Love | 85b4aa4 | 2008-12-09 15:10:24 -0800 | [diff] [blame] | 145 | #ifdef CONFIG_SMP |
| 146 | /* |
| 147 | * The incoming frame exchange id(oxid) is ANDed with num of online |
| 148 | * cpu bits to get cpu_idx and then this cpu_idx is used for selecting |
| 149 | * a per cpu kernel thread from fcoe_percpu. In case the cpu is |
| 150 | * offline or no kernel thread for derived cpu_idx then cpu_idx is |
| 151 | * initialize to first online cpu index. |
| 152 | */ |
| 153 | cpu_idx = oxid & (num_online_cpus() - 1); |
Robert Love | 5e5e92d | 2009-03-17 11:41:35 -0700 | [diff] [blame] | 154 | if (!cpu_online(cpu_idx)) |
Robert Love | 85b4aa4 | 2008-12-09 15:10:24 -0800 | [diff] [blame] | 155 | cpu_idx = first_cpu(cpu_online_map); |
Robert Love | 5e5e92d | 2009-03-17 11:41:35 -0700 | [diff] [blame] | 156 | |
Robert Love | 85b4aa4 | 2008-12-09 15:10:24 -0800 | [diff] [blame] | 157 | #endif |
Robert Love | 5e5e92d | 2009-03-17 11:41:35 -0700 | [diff] [blame] | 158 | |
| 159 | fps = &per_cpu(fcoe_percpu, cpu_idx); |
Robert Love | 85b4aa4 | 2008-12-09 15:10:24 -0800 | [diff] [blame] | 160 | |
| 161 | spin_lock_bh(&fps->fcoe_rx_list.lock); |
| 162 | __skb_queue_tail(&fps->fcoe_rx_list, skb); |
| 163 | if (fps->fcoe_rx_list.qlen == 1) |
| 164 | wake_up_process(fps->thread); |
| 165 | |
| 166 | spin_unlock_bh(&fps->fcoe_rx_list.lock); |
| 167 | |
| 168 | return 0; |
| 169 | err: |
Robert Love | 582b45b | 2009-03-31 15:51:50 -0700 | [diff] [blame^] | 170 | fc_lport_get_stats(lp)->ErrorFrames++; |
Robert Love | 85b4aa4 | 2008-12-09 15:10:24 -0800 | [diff] [blame] | 171 | |
| 172 | err2: |
| 173 | kfree_skb(skb); |
| 174 | return -1; |
| 175 | } |
| 176 | EXPORT_SYMBOL_GPL(fcoe_rcv); |
| 177 | |
| 178 | /** |
Robert Love | 34f42a0 | 2009-02-27 10:55:45 -0800 | [diff] [blame] | 179 | * fcoe_start_io() - pass to netdev to start xmit for fcoe |
Robert Love | 85b4aa4 | 2008-12-09 15:10:24 -0800 | [diff] [blame] | 180 | * @skb: the skb to be xmitted |
| 181 | * |
| 182 | * Returns: 0 for success |
Robert Love | 34f42a0 | 2009-02-27 10:55:45 -0800 | [diff] [blame] | 183 | */ |
Robert Love | 85b4aa4 | 2008-12-09 15:10:24 -0800 | [diff] [blame] | 184 | static inline int fcoe_start_io(struct sk_buff *skb) |
| 185 | { |
| 186 | int rc; |
| 187 | |
| 188 | skb_get(skb); |
| 189 | rc = dev_queue_xmit(skb); |
| 190 | if (rc != 0) |
| 191 | return rc; |
| 192 | kfree_skb(skb); |
| 193 | return 0; |
| 194 | } |
| 195 | |
| 196 | /** |
Robert Love | 34f42a0 | 2009-02-27 10:55:45 -0800 | [diff] [blame] | 197 | * fcoe_get_paged_crc_eof() - in case we need alloc a page for crc_eof |
Robert Love | 85b4aa4 | 2008-12-09 15:10:24 -0800 | [diff] [blame] | 198 | * @skb: the skb to be xmitted |
| 199 | * @tlen: total len |
| 200 | * |
| 201 | * Returns: 0 for success |
Robert Love | 34f42a0 | 2009-02-27 10:55:45 -0800 | [diff] [blame] | 202 | */ |
Robert Love | 85b4aa4 | 2008-12-09 15:10:24 -0800 | [diff] [blame] | 203 | static int fcoe_get_paged_crc_eof(struct sk_buff *skb, int tlen) |
| 204 | { |
| 205 | struct fcoe_percpu_s *fps; |
| 206 | struct page *page; |
Robert Love | 85b4aa4 | 2008-12-09 15:10:24 -0800 | [diff] [blame] | 207 | |
Robert Love | 5e5e92d | 2009-03-17 11:41:35 -0700 | [diff] [blame] | 208 | fps = &get_cpu_var(fcoe_percpu); |
Robert Love | 85b4aa4 | 2008-12-09 15:10:24 -0800 | [diff] [blame] | 209 | page = fps->crc_eof_page; |
| 210 | if (!page) { |
| 211 | page = alloc_page(GFP_ATOMIC); |
| 212 | if (!page) { |
Robert Love | 5e5e92d | 2009-03-17 11:41:35 -0700 | [diff] [blame] | 213 | put_cpu_var(fcoe_percpu); |
Robert Love | 85b4aa4 | 2008-12-09 15:10:24 -0800 | [diff] [blame] | 214 | return -ENOMEM; |
| 215 | } |
| 216 | fps->crc_eof_page = page; |
| 217 | WARN_ON(fps->crc_eof_offset != 0); |
| 218 | } |
| 219 | |
| 220 | get_page(page); |
| 221 | skb_fill_page_desc(skb, skb_shinfo(skb)->nr_frags, page, |
| 222 | fps->crc_eof_offset, tlen); |
| 223 | skb->len += tlen; |
| 224 | skb->data_len += tlen; |
| 225 | skb->truesize += tlen; |
| 226 | fps->crc_eof_offset += sizeof(struct fcoe_crc_eof); |
| 227 | |
| 228 | if (fps->crc_eof_offset >= PAGE_SIZE) { |
| 229 | fps->crc_eof_page = NULL; |
| 230 | fps->crc_eof_offset = 0; |
| 231 | put_page(page); |
| 232 | } |
Robert Love | 5e5e92d | 2009-03-17 11:41:35 -0700 | [diff] [blame] | 233 | put_cpu_var(fcoe_percpu); |
Robert Love | 85b4aa4 | 2008-12-09 15:10:24 -0800 | [diff] [blame] | 234 | return 0; |
| 235 | } |
| 236 | |
| 237 | /** |
Robert Love | 34f42a0 | 2009-02-27 10:55:45 -0800 | [diff] [blame] | 238 | * fcoe_fc_crc() - calculates FC CRC in this fcoe skb |
Robert Love | 85b4aa4 | 2008-12-09 15:10:24 -0800 | [diff] [blame] | 239 | * @fp: the fc_frame containg data to be checksummed |
| 240 | * |
| 241 | * This uses crc32() to calculate the crc for fc frame |
| 242 | * Return : 32 bit crc |
Robert Love | 34f42a0 | 2009-02-27 10:55:45 -0800 | [diff] [blame] | 243 | */ |
Robert Love | 85b4aa4 | 2008-12-09 15:10:24 -0800 | [diff] [blame] | 244 | u32 fcoe_fc_crc(struct fc_frame *fp) |
| 245 | { |
| 246 | struct sk_buff *skb = fp_skb(fp); |
| 247 | struct skb_frag_struct *frag; |
| 248 | unsigned char *data; |
| 249 | unsigned long off, len, clen; |
| 250 | u32 crc; |
| 251 | unsigned i; |
| 252 | |
| 253 | crc = crc32(~0, skb->data, skb_headlen(skb)); |
| 254 | |
| 255 | for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) { |
| 256 | frag = &skb_shinfo(skb)->frags[i]; |
| 257 | off = frag->page_offset; |
| 258 | len = frag->size; |
| 259 | while (len > 0) { |
| 260 | clen = min(len, PAGE_SIZE - (off & ~PAGE_MASK)); |
| 261 | data = kmap_atomic(frag->page + (off >> PAGE_SHIFT), |
| 262 | KM_SKB_DATA_SOFTIRQ); |
| 263 | crc = crc32(crc, data + (off & ~PAGE_MASK), clen); |
| 264 | kunmap_atomic(data, KM_SKB_DATA_SOFTIRQ); |
| 265 | off += clen; |
| 266 | len -= clen; |
| 267 | } |
| 268 | } |
| 269 | return crc; |
| 270 | } |
| 271 | EXPORT_SYMBOL_GPL(fcoe_fc_crc); |
| 272 | |
| 273 | /** |
Robert Love | 34f42a0 | 2009-02-27 10:55:45 -0800 | [diff] [blame] | 274 | * fcoe_xmit() - FCoE frame transmit function |
Robert Love | 85b4aa4 | 2008-12-09 15:10:24 -0800 | [diff] [blame] | 275 | * @lp: the associated local port |
| 276 | * @fp: the fc_frame to be transmitted |
| 277 | * |
| 278 | * Return : 0 for success |
Robert Love | 34f42a0 | 2009-02-27 10:55:45 -0800 | [diff] [blame] | 279 | */ |
Robert Love | 85b4aa4 | 2008-12-09 15:10:24 -0800 | [diff] [blame] | 280 | int fcoe_xmit(struct fc_lport *lp, struct fc_frame *fp) |
| 281 | { |
| 282 | int wlen, rc = 0; |
| 283 | u32 crc; |
| 284 | struct ethhdr *eh; |
| 285 | struct fcoe_crc_eof *cp; |
| 286 | struct sk_buff *skb; |
| 287 | struct fcoe_dev_stats *stats; |
| 288 | struct fc_frame_header *fh; |
| 289 | unsigned int hlen; /* header length implies the version */ |
| 290 | unsigned int tlen; /* trailer length */ |
| 291 | unsigned int elen; /* eth header, may include vlan */ |
| 292 | int flogi_in_progress = 0; |
| 293 | struct fcoe_softc *fc; |
| 294 | u8 sof, eof; |
| 295 | struct fcoe_hdr *hp; |
| 296 | |
| 297 | WARN_ON((fr_len(fp) % sizeof(u32)) != 0); |
| 298 | |
Robert Love | fc47ff6 | 2009-02-27 10:55:55 -0800 | [diff] [blame] | 299 | fc = lport_priv(lp); |
Robert Love | 85b4aa4 | 2008-12-09 15:10:24 -0800 | [diff] [blame] | 300 | /* |
| 301 | * if it is a flogi then we need to learn gw-addr |
| 302 | * and my own fcid |
| 303 | */ |
| 304 | fh = fc_frame_header_get(fp); |
| 305 | if (unlikely(fh->fh_r_ctl == FC_RCTL_ELS_REQ)) { |
| 306 | if (fc_frame_payload_op(fp) == ELS_FLOGI) { |
| 307 | fc->flogi_oxid = ntohs(fh->fh_ox_id); |
| 308 | fc->address_mode = FCOE_FCOUI_ADDR_MODE; |
| 309 | fc->flogi_progress = 1; |
| 310 | flogi_in_progress = 1; |
| 311 | } else if (fc->flogi_progress && ntoh24(fh->fh_s_id) != 0) { |
| 312 | /* |
| 313 | * Here we must've gotten an SID by accepting an FLOGI |
| 314 | * from a point-to-point connection. Switch to using |
| 315 | * the source mac based on the SID. The destination |
| 316 | * MAC in this case would have been set by receving the |
| 317 | * FLOGI. |
| 318 | */ |
| 319 | fc_fcoe_set_mac(fc->data_src_addr, fh->fh_s_id); |
| 320 | fc->flogi_progress = 0; |
| 321 | } |
| 322 | } |
| 323 | |
| 324 | skb = fp_skb(fp); |
| 325 | sof = fr_sof(fp); |
| 326 | eof = fr_eof(fp); |
| 327 | |
| 328 | elen = (fc->real_dev->priv_flags & IFF_802_1Q_VLAN) ? |
| 329 | sizeof(struct vlan_ethhdr) : sizeof(struct ethhdr); |
| 330 | hlen = sizeof(struct fcoe_hdr); |
| 331 | tlen = sizeof(struct fcoe_crc_eof); |
| 332 | wlen = (skb->len - tlen + sizeof(crc)) / FCOE_WORD_TO_BYTE; |
| 333 | |
| 334 | /* crc offload */ |
| 335 | if (likely(lp->crc_offload)) { |
Yi Zou | 39ca9a0 | 2009-02-27 14:07:15 -0800 | [diff] [blame] | 336 | skb->ip_summed = CHECKSUM_PARTIAL; |
Robert Love | 85b4aa4 | 2008-12-09 15:10:24 -0800 | [diff] [blame] | 337 | skb->csum_start = skb_headroom(skb); |
| 338 | skb->csum_offset = skb->len; |
| 339 | crc = 0; |
| 340 | } else { |
| 341 | skb->ip_summed = CHECKSUM_NONE; |
| 342 | crc = fcoe_fc_crc(fp); |
| 343 | } |
| 344 | |
| 345 | /* copy fc crc and eof to the skb buff */ |
| 346 | if (skb_is_nonlinear(skb)) { |
| 347 | skb_frag_t *frag; |
| 348 | if (fcoe_get_paged_crc_eof(skb, tlen)) { |
Roel Kluin | e904158 | 2009-02-27 10:56:22 -0800 | [diff] [blame] | 349 | kfree_skb(skb); |
Robert Love | 85b4aa4 | 2008-12-09 15:10:24 -0800 | [diff] [blame] | 350 | return -ENOMEM; |
| 351 | } |
| 352 | frag = &skb_shinfo(skb)->frags[skb_shinfo(skb)->nr_frags - 1]; |
| 353 | cp = kmap_atomic(frag->page, KM_SKB_DATA_SOFTIRQ) |
| 354 | + frag->page_offset; |
| 355 | } else { |
| 356 | cp = (struct fcoe_crc_eof *)skb_put(skb, tlen); |
| 357 | } |
| 358 | |
| 359 | memset(cp, 0, sizeof(*cp)); |
| 360 | cp->fcoe_eof = eof; |
| 361 | cp->fcoe_crc32 = cpu_to_le32(~crc); |
| 362 | |
| 363 | if (skb_is_nonlinear(skb)) { |
| 364 | kunmap_atomic(cp, KM_SKB_DATA_SOFTIRQ); |
| 365 | cp = NULL; |
| 366 | } |
| 367 | |
| 368 | /* adjust skb netowrk/transport offsets to match mac/fcoe/fc */ |
| 369 | skb_push(skb, elen + hlen); |
| 370 | skb_reset_mac_header(skb); |
| 371 | skb_reset_network_header(skb); |
| 372 | skb->mac_len = elen; |
Yi Zou | 211c738 | 2009-02-27 14:06:37 -0800 | [diff] [blame] | 373 | skb->protocol = htons(ETH_P_FCOE); |
Robert Love | 85b4aa4 | 2008-12-09 15:10:24 -0800 | [diff] [blame] | 374 | skb->dev = fc->real_dev; |
| 375 | |
| 376 | /* fill up mac and fcoe headers */ |
| 377 | eh = eth_hdr(skb); |
| 378 | eh->h_proto = htons(ETH_P_FCOE); |
| 379 | if (fc->address_mode == FCOE_FCOUI_ADDR_MODE) |
| 380 | fc_fcoe_set_mac(eh->h_dest, fh->fh_d_id); |
| 381 | else |
| 382 | /* insert GW address */ |
| 383 | memcpy(eh->h_dest, fc->dest_addr, ETH_ALEN); |
| 384 | |
| 385 | if (unlikely(flogi_in_progress)) |
| 386 | memcpy(eh->h_source, fc->ctl_src_addr, ETH_ALEN); |
| 387 | else |
| 388 | memcpy(eh->h_source, fc->data_src_addr, ETH_ALEN); |
| 389 | |
| 390 | hp = (struct fcoe_hdr *)(eh + 1); |
| 391 | memset(hp, 0, sizeof(*hp)); |
| 392 | if (FC_FCOE_VER) |
| 393 | FC_FCOE_ENCAPS_VER(hp, FC_FCOE_VER); |
| 394 | hp->fcoe_sof = sof; |
| 395 | |
Yi Zou | 39ca9a0 | 2009-02-27 14:07:15 -0800 | [diff] [blame] | 396 | #ifdef NETIF_F_FSO |
| 397 | /* fcoe lso, mss is in max_payload which is non-zero for FCP data */ |
| 398 | if (lp->seq_offload && fr_max_payload(fp)) { |
| 399 | skb_shinfo(skb)->gso_type = SKB_GSO_FCOE; |
| 400 | skb_shinfo(skb)->gso_size = fr_max_payload(fp); |
| 401 | } else { |
| 402 | skb_shinfo(skb)->gso_type = 0; |
| 403 | skb_shinfo(skb)->gso_size = 0; |
| 404 | } |
| 405 | #endif |
Robert Love | 85b4aa4 | 2008-12-09 15:10:24 -0800 | [diff] [blame] | 406 | /* update tx stats: regardless if LLD fails */ |
Robert Love | 582b45b | 2009-03-31 15:51:50 -0700 | [diff] [blame^] | 407 | stats = fc_lport_get_stats(lp); |
| 408 | stats->TxFrames++; |
| 409 | stats->TxWords += wlen; |
Robert Love | 85b4aa4 | 2008-12-09 15:10:24 -0800 | [diff] [blame] | 410 | |
| 411 | /* send down to lld */ |
| 412 | fr_dev(fp) = lp; |
| 413 | if (fc->fcoe_pending_queue.qlen) |
| 414 | rc = fcoe_check_wait_queue(lp); |
| 415 | |
| 416 | if (rc == 0) |
| 417 | rc = fcoe_start_io(skb); |
| 418 | |
| 419 | if (rc) { |
Chris Leech | 55c8baf | 2009-02-27 10:56:32 -0800 | [diff] [blame] | 420 | spin_lock_bh(&fc->fcoe_pending_queue.lock); |
| 421 | __skb_queue_tail(&fc->fcoe_pending_queue, skb); |
| 422 | spin_unlock_bh(&fc->fcoe_pending_queue.lock); |
Robert Love | 85b4aa4 | 2008-12-09 15:10:24 -0800 | [diff] [blame] | 423 | if (fc->fcoe_pending_queue.qlen > FCOE_MAX_QUEUE_DEPTH) |
Vasu Dev | bc0e17f | 2009-02-27 10:54:57 -0800 | [diff] [blame] | 424 | lp->qfull = 1; |
Robert Love | 85b4aa4 | 2008-12-09 15:10:24 -0800 | [diff] [blame] | 425 | } |
| 426 | |
| 427 | return 0; |
| 428 | } |
| 429 | EXPORT_SYMBOL_GPL(fcoe_xmit); |
| 430 | |
Robert Love | 34f42a0 | 2009-02-27 10:55:45 -0800 | [diff] [blame] | 431 | /** |
| 432 | * fcoe_percpu_receive_thread() - recv thread per cpu |
Robert Love | 85b4aa4 | 2008-12-09 15:10:24 -0800 | [diff] [blame] | 433 | * @arg: ptr to the fcoe per cpu struct |
| 434 | * |
| 435 | * Return: 0 for success |
Robert Love | 85b4aa4 | 2008-12-09 15:10:24 -0800 | [diff] [blame] | 436 | */ |
| 437 | int fcoe_percpu_receive_thread(void *arg) |
| 438 | { |
| 439 | struct fcoe_percpu_s *p = arg; |
| 440 | u32 fr_len; |
| 441 | struct fc_lport *lp; |
| 442 | struct fcoe_rcv_info *fr; |
| 443 | struct fcoe_dev_stats *stats; |
| 444 | struct fc_frame_header *fh; |
| 445 | struct sk_buff *skb; |
| 446 | struct fcoe_crc_eof crc_eof; |
| 447 | struct fc_frame *fp; |
| 448 | u8 *mac = NULL; |
| 449 | struct fcoe_softc *fc; |
| 450 | struct fcoe_hdr *hp; |
| 451 | |
Robert Love | 4469c19 | 2009-02-27 10:56:38 -0800 | [diff] [blame] | 452 | set_user_nice(current, -20); |
Robert Love | 85b4aa4 | 2008-12-09 15:10:24 -0800 | [diff] [blame] | 453 | |
| 454 | while (!kthread_should_stop()) { |
| 455 | |
| 456 | spin_lock_bh(&p->fcoe_rx_list.lock); |
| 457 | while ((skb = __skb_dequeue(&p->fcoe_rx_list)) == NULL) { |
| 458 | set_current_state(TASK_INTERRUPTIBLE); |
| 459 | spin_unlock_bh(&p->fcoe_rx_list.lock); |
| 460 | schedule(); |
| 461 | set_current_state(TASK_RUNNING); |
| 462 | if (kthread_should_stop()) |
| 463 | return 0; |
| 464 | spin_lock_bh(&p->fcoe_rx_list.lock); |
| 465 | } |
| 466 | spin_unlock_bh(&p->fcoe_rx_list.lock); |
| 467 | fr = fcoe_dev_from_skb(skb); |
| 468 | lp = fr->fr_dev; |
| 469 | if (unlikely(lp == NULL)) { |
| 470 | FC_DBG("invalid HBA Structure"); |
| 471 | kfree_skb(skb); |
| 472 | continue; |
| 473 | } |
| 474 | |
Robert Love | 85b4aa4 | 2008-12-09 15:10:24 -0800 | [diff] [blame] | 475 | if (unlikely(debug_fcoe)) { |
| 476 | FC_DBG("skb_info: len:%d data_len:%d head:%p data:%p " |
| 477 | "tail:%p end:%p sum:%d dev:%s", |
| 478 | skb->len, skb->data_len, |
| 479 | skb->head, skb->data, skb_tail_pointer(skb), |
| 480 | skb_end_pointer(skb), skb->csum, |
| 481 | skb->dev ? skb->dev->name : "<NULL>"); |
| 482 | } |
| 483 | |
| 484 | /* |
| 485 | * Save source MAC address before discarding header. |
| 486 | */ |
| 487 | fc = lport_priv(lp); |
| 488 | if (unlikely(fc->flogi_progress)) |
| 489 | mac = eth_hdr(skb)->h_source; |
| 490 | |
| 491 | if (skb_is_nonlinear(skb)) |
| 492 | skb_linearize(skb); /* not ideal */ |
| 493 | |
| 494 | /* |
| 495 | * Frame length checks and setting up the header pointers |
| 496 | * was done in fcoe_rcv already. |
| 497 | */ |
| 498 | hp = (struct fcoe_hdr *) skb_network_header(skb); |
| 499 | fh = (struct fc_frame_header *) skb_transport_header(skb); |
| 500 | |
Robert Love | 582b45b | 2009-03-31 15:51:50 -0700 | [diff] [blame^] | 501 | stats = fc_lport_get_stats(lp); |
Robert Love | 85b4aa4 | 2008-12-09 15:10:24 -0800 | [diff] [blame] | 502 | if (unlikely(FC_FCOE_DECAPS_VER(hp) != FC_FCOE_VER)) { |
Robert Love | 582b45b | 2009-03-31 15:51:50 -0700 | [diff] [blame^] | 503 | if (stats->ErrorFrames < 5) |
| 504 | printk(KERN_WARNING "FCoE version " |
| 505 | "mismatch: The frame has " |
| 506 | "version %x, but the " |
| 507 | "initiator supports version " |
| 508 | "%x\n", FC_FCOE_DECAPS_VER(hp), |
| 509 | FC_FCOE_VER); |
| 510 | stats->ErrorFrames++; |
Robert Love | 85b4aa4 | 2008-12-09 15:10:24 -0800 | [diff] [blame] | 511 | kfree_skb(skb); |
| 512 | continue; |
| 513 | } |
| 514 | |
| 515 | skb_pull(skb, sizeof(struct fcoe_hdr)); |
| 516 | fr_len = skb->len - sizeof(struct fcoe_crc_eof); |
| 517 | |
Robert Love | 582b45b | 2009-03-31 15:51:50 -0700 | [diff] [blame^] | 518 | stats->RxFrames++; |
| 519 | stats->RxWords += fr_len / FCOE_WORD_TO_BYTE; |
Robert Love | 85b4aa4 | 2008-12-09 15:10:24 -0800 | [diff] [blame] | 520 | |
| 521 | fp = (struct fc_frame *)skb; |
| 522 | fc_frame_init(fp); |
| 523 | fr_dev(fp) = lp; |
| 524 | fr_sof(fp) = hp->fcoe_sof; |
| 525 | |
| 526 | /* Copy out the CRC and EOF trailer for access */ |
| 527 | if (skb_copy_bits(skb, fr_len, &crc_eof, sizeof(crc_eof))) { |
| 528 | kfree_skb(skb); |
| 529 | continue; |
| 530 | } |
| 531 | fr_eof(fp) = crc_eof.fcoe_eof; |
| 532 | fr_crc(fp) = crc_eof.fcoe_crc32; |
| 533 | if (pskb_trim(skb, fr_len)) { |
| 534 | kfree_skb(skb); |
| 535 | continue; |
| 536 | } |
| 537 | |
| 538 | /* |
| 539 | * We only check CRC if no offload is available and if it is |
| 540 | * it's solicited data, in which case, the FCP layer would |
| 541 | * check it during the copy. |
| 542 | */ |
Yi Zou | 07c00ec | 2009-02-27 14:07:31 -0800 | [diff] [blame] | 543 | if (lp->crc_offload && skb->ip_summed == CHECKSUM_UNNECESSARY) |
Robert Love | 85b4aa4 | 2008-12-09 15:10:24 -0800 | [diff] [blame] | 544 | fr_flags(fp) &= ~FCPHF_CRC_UNCHECKED; |
| 545 | else |
| 546 | fr_flags(fp) |= FCPHF_CRC_UNCHECKED; |
| 547 | |
| 548 | fh = fc_frame_header_get(fp); |
| 549 | if (fh->fh_r_ctl == FC_RCTL_DD_SOL_DATA && |
| 550 | fh->fh_type == FC_TYPE_FCP) { |
| 551 | fc_exch_recv(lp, lp->emp, fp); |
| 552 | continue; |
| 553 | } |
| 554 | if (fr_flags(fp) & FCPHF_CRC_UNCHECKED) { |
| 555 | if (le32_to_cpu(fr_crc(fp)) != |
| 556 | ~crc32(~0, skb->data, fr_len)) { |
| 557 | if (debug_fcoe || stats->InvalidCRCCount < 5) |
| 558 | printk(KERN_WARNING "fcoe: dropping " |
| 559 | "frame with CRC error\n"); |
| 560 | stats->InvalidCRCCount++; |
| 561 | stats->ErrorFrames++; |
| 562 | fc_frame_free(fp); |
| 563 | continue; |
| 564 | } |
| 565 | fr_flags(fp) &= ~FCPHF_CRC_UNCHECKED; |
| 566 | } |
| 567 | /* non flogi and non data exchanges are handled here */ |
| 568 | if (unlikely(fc->flogi_progress)) |
| 569 | fcoe_recv_flogi(fc, fp, mac); |
| 570 | fc_exch_recv(lp, lp->emp, fp); |
| 571 | } |
| 572 | return 0; |
| 573 | } |
| 574 | |
| 575 | /** |
Robert Love | 34f42a0 | 2009-02-27 10:55:45 -0800 | [diff] [blame] | 576 | * fcoe_recv_flogi() - flogi receive function |
Robert Love | 85b4aa4 | 2008-12-09 15:10:24 -0800 | [diff] [blame] | 577 | * @fc: associated fcoe_softc |
| 578 | * @fp: the recieved frame |
| 579 | * @sa: the source address of this flogi |
| 580 | * |
| 581 | * This is responsible to parse the flogi response and sets the corresponding |
| 582 | * mac address for the initiator, eitehr OUI based or GW based. |
| 583 | * |
| 584 | * Returns: none |
Robert Love | 34f42a0 | 2009-02-27 10:55:45 -0800 | [diff] [blame] | 585 | */ |
Robert Love | 85b4aa4 | 2008-12-09 15:10:24 -0800 | [diff] [blame] | 586 | static void fcoe_recv_flogi(struct fcoe_softc *fc, struct fc_frame *fp, u8 *sa) |
| 587 | { |
| 588 | struct fc_frame_header *fh; |
| 589 | u8 op; |
| 590 | |
| 591 | fh = fc_frame_header_get(fp); |
| 592 | if (fh->fh_type != FC_TYPE_ELS) |
| 593 | return; |
| 594 | op = fc_frame_payload_op(fp); |
| 595 | if (op == ELS_LS_ACC && fh->fh_r_ctl == FC_RCTL_ELS_REP && |
| 596 | fc->flogi_oxid == ntohs(fh->fh_ox_id)) { |
| 597 | /* |
| 598 | * FLOGI accepted. |
| 599 | * If the src mac addr is FC_OUI-based, then we mark the |
| 600 | * address_mode flag to use FC_OUI-based Ethernet DA. |
| 601 | * Otherwise we use the FCoE gateway addr |
| 602 | */ |
| 603 | if (!compare_ether_addr(sa, (u8[6]) FC_FCOE_FLOGI_MAC)) { |
| 604 | fc->address_mode = FCOE_FCOUI_ADDR_MODE; |
| 605 | } else { |
| 606 | memcpy(fc->dest_addr, sa, ETH_ALEN); |
| 607 | fc->address_mode = FCOE_GW_ADDR_MODE; |
| 608 | } |
| 609 | |
| 610 | /* |
| 611 | * Remove any previously-set unicast MAC filter. |
| 612 | * Add secondary FCoE MAC address filter for our OUI. |
| 613 | */ |
| 614 | rtnl_lock(); |
| 615 | if (compare_ether_addr(fc->data_src_addr, (u8[6]) { 0 })) |
| 616 | dev_unicast_delete(fc->real_dev, fc->data_src_addr, |
| 617 | ETH_ALEN); |
| 618 | fc_fcoe_set_mac(fc->data_src_addr, fh->fh_d_id); |
| 619 | dev_unicast_add(fc->real_dev, fc->data_src_addr, ETH_ALEN); |
| 620 | rtnl_unlock(); |
| 621 | |
| 622 | fc->flogi_progress = 0; |
| 623 | } else if (op == ELS_FLOGI && fh->fh_r_ctl == FC_RCTL_ELS_REQ && sa) { |
| 624 | /* |
| 625 | * Save source MAC for point-to-point responses. |
| 626 | */ |
| 627 | memcpy(fc->dest_addr, sa, ETH_ALEN); |
| 628 | fc->address_mode = FCOE_GW_ADDR_MODE; |
| 629 | } |
| 630 | } |
| 631 | |
| 632 | /** |
Robert Love | 34f42a0 | 2009-02-27 10:55:45 -0800 | [diff] [blame] | 633 | * fcoe_watchdog() - fcoe timer callback |
Robert Love | 85b4aa4 | 2008-12-09 15:10:24 -0800 | [diff] [blame] | 634 | * @vp: |
| 635 | * |
Vasu Dev | bc0e17f | 2009-02-27 10:54:57 -0800 | [diff] [blame] | 636 | * This checks the pending queue length for fcoe and set lport qfull |
Robert Love | 85b4aa4 | 2008-12-09 15:10:24 -0800 | [diff] [blame] | 637 | * if the FCOE_MAX_QUEUE_DEPTH is reached. This is done for all fc_lport on the |
| 638 | * fcoe_hostlist. |
| 639 | * |
| 640 | * Returns: 0 for success |
Robert Love | 34f42a0 | 2009-02-27 10:55:45 -0800 | [diff] [blame] | 641 | */ |
Robert Love | 85b4aa4 | 2008-12-09 15:10:24 -0800 | [diff] [blame] | 642 | void fcoe_watchdog(ulong vp) |
| 643 | { |
Robert Love | 85b4aa4 | 2008-12-09 15:10:24 -0800 | [diff] [blame] | 644 | struct fcoe_softc *fc; |
Robert Love | 85b4aa4 | 2008-12-09 15:10:24 -0800 | [diff] [blame] | 645 | |
| 646 | read_lock(&fcoe_hostlist_lock); |
| 647 | list_for_each_entry(fc, &fcoe_hostlist, list) { |
Vasu Dev | c826a31 | 2009-02-27 10:56:27 -0800 | [diff] [blame] | 648 | if (fc->lp) |
| 649 | fcoe_check_wait_queue(fc->lp); |
Robert Love | 85b4aa4 | 2008-12-09 15:10:24 -0800 | [diff] [blame] | 650 | } |
| 651 | read_unlock(&fcoe_hostlist_lock); |
| 652 | |
| 653 | fcoe_timer.expires = jiffies + (1 * HZ); |
| 654 | add_timer(&fcoe_timer); |
| 655 | } |
| 656 | |
| 657 | |
| 658 | /** |
Robert Love | 34f42a0 | 2009-02-27 10:55:45 -0800 | [diff] [blame] | 659 | * fcoe_check_wait_queue() - put the skb into fcoe pending xmit queue |
Robert Love | 85b4aa4 | 2008-12-09 15:10:24 -0800 | [diff] [blame] | 660 | * @lp: the fc_port for this skb |
| 661 | * @skb: the associated skb to be xmitted |
| 662 | * |
| 663 | * This empties the wait_queue, dequeue the head of the wait_queue queue |
| 664 | * and calls fcoe_start_io() for each packet, if all skb have been |
Vasu Dev | c826a31 | 2009-02-27 10:56:27 -0800 | [diff] [blame] | 665 | * transmitted, return qlen or -1 if a error occurs, then restore |
| 666 | * wait_queue and try again later. |
Robert Love | 85b4aa4 | 2008-12-09 15:10:24 -0800 | [diff] [blame] | 667 | * |
| 668 | * The wait_queue is used when the skb transmit fails. skb will go |
| 669 | * in the wait_queue which will be emptied by the time function OR |
| 670 | * by the next skb transmit. |
| 671 | * |
| 672 | * Returns: 0 for success |
Robert Love | 34f42a0 | 2009-02-27 10:55:45 -0800 | [diff] [blame] | 673 | */ |
Robert Love | 85b4aa4 | 2008-12-09 15:10:24 -0800 | [diff] [blame] | 674 | static int fcoe_check_wait_queue(struct fc_lport *lp) |
| 675 | { |
Chris Leech | 55c8baf | 2009-02-27 10:56:32 -0800 | [diff] [blame] | 676 | struct fcoe_softc *fc = lport_priv(lp); |
Robert Love | 85b4aa4 | 2008-12-09 15:10:24 -0800 | [diff] [blame] | 677 | struct sk_buff *skb; |
Vasu Dev | c826a31 | 2009-02-27 10:56:27 -0800 | [diff] [blame] | 678 | int rc = -1; |
Robert Love | 85b4aa4 | 2008-12-09 15:10:24 -0800 | [diff] [blame] | 679 | |
Robert Love | 85b4aa4 | 2008-12-09 15:10:24 -0800 | [diff] [blame] | 680 | spin_lock_bh(&fc->fcoe_pending_queue.lock); |
Vasu Dev | c826a31 | 2009-02-27 10:56:27 -0800 | [diff] [blame] | 681 | if (fc->fcoe_pending_queue_active) |
| 682 | goto out; |
| 683 | fc->fcoe_pending_queue_active = 1; |
Chris Leech | 55c8baf | 2009-02-27 10:56:32 -0800 | [diff] [blame] | 684 | |
| 685 | while (fc->fcoe_pending_queue.qlen) { |
| 686 | /* keep qlen > 0 until fcoe_start_io succeeds */ |
| 687 | fc->fcoe_pending_queue.qlen++; |
| 688 | skb = __skb_dequeue(&fc->fcoe_pending_queue); |
| 689 | |
| 690 | spin_unlock_bh(&fc->fcoe_pending_queue.lock); |
| 691 | rc = fcoe_start_io(skb); |
| 692 | spin_lock_bh(&fc->fcoe_pending_queue.lock); |
| 693 | |
| 694 | if (rc) { |
| 695 | __skb_queue_head(&fc->fcoe_pending_queue, skb); |
| 696 | /* undo temporary increment above */ |
| 697 | fc->fcoe_pending_queue.qlen--; |
| 698 | break; |
Robert Love | 85b4aa4 | 2008-12-09 15:10:24 -0800 | [diff] [blame] | 699 | } |
Chris Leech | 55c8baf | 2009-02-27 10:56:32 -0800 | [diff] [blame] | 700 | /* undo temporary increment above */ |
| 701 | fc->fcoe_pending_queue.qlen--; |
Robert Love | 85b4aa4 | 2008-12-09 15:10:24 -0800 | [diff] [blame] | 702 | } |
Chris Leech | 55c8baf | 2009-02-27 10:56:32 -0800 | [diff] [blame] | 703 | |
| 704 | if (fc->fcoe_pending_queue.qlen < FCOE_LOW_QUEUE_DEPTH) |
| 705 | lp->qfull = 0; |
Vasu Dev | c826a31 | 2009-02-27 10:56:27 -0800 | [diff] [blame] | 706 | fc->fcoe_pending_queue_active = 0; |
| 707 | rc = fc->fcoe_pending_queue.qlen; |
| 708 | out: |
Robert Love | 85b4aa4 | 2008-12-09 15:10:24 -0800 | [diff] [blame] | 709 | spin_unlock_bh(&fc->fcoe_pending_queue.lock); |
Vasu Dev | c826a31 | 2009-02-27 10:56:27 -0800 | [diff] [blame] | 710 | return rc; |
Robert Love | 85b4aa4 | 2008-12-09 15:10:24 -0800 | [diff] [blame] | 711 | } |
| 712 | |
| 713 | /** |
Robert Love | 34f42a0 | 2009-02-27 10:55:45 -0800 | [diff] [blame] | 714 | * fcoe_dev_setup() - setup link change notification interface |
| 715 | */ |
| 716 | static void fcoe_dev_setup() |
Robert Love | 85b4aa4 | 2008-12-09 15:10:24 -0800 | [diff] [blame] | 717 | { |
| 718 | /* |
| 719 | * here setup a interface specific wd time to |
| 720 | * monitor the link state |
| 721 | */ |
| 722 | register_netdevice_notifier(&fcoe_notifier); |
| 723 | } |
| 724 | |
| 725 | /** |
Robert Love | 34f42a0 | 2009-02-27 10:55:45 -0800 | [diff] [blame] | 726 | * fcoe_dev_setup() - cleanup link change notification interface |
| 727 | */ |
Robert Love | 85b4aa4 | 2008-12-09 15:10:24 -0800 | [diff] [blame] | 728 | static void fcoe_dev_cleanup(void) |
| 729 | { |
| 730 | unregister_netdevice_notifier(&fcoe_notifier); |
| 731 | } |
| 732 | |
| 733 | /** |
Robert Love | 34f42a0 | 2009-02-27 10:55:45 -0800 | [diff] [blame] | 734 | * fcoe_device_notification() - netdev event notification callback |
Robert Love | 85b4aa4 | 2008-12-09 15:10:24 -0800 | [diff] [blame] | 735 | * @notifier: context of the notification |
| 736 | * @event: type of event |
| 737 | * @ptr: fixed array for output parsed ifname |
| 738 | * |
| 739 | * This function is called by the ethernet driver in case of link change event |
| 740 | * |
| 741 | * Returns: 0 for success |
Robert Love | 34f42a0 | 2009-02-27 10:55:45 -0800 | [diff] [blame] | 742 | */ |
Robert Love | 85b4aa4 | 2008-12-09 15:10:24 -0800 | [diff] [blame] | 743 | static int fcoe_device_notification(struct notifier_block *notifier, |
| 744 | ulong event, void *ptr) |
| 745 | { |
| 746 | struct fc_lport *lp = NULL; |
| 747 | struct net_device *real_dev = ptr; |
| 748 | struct fcoe_softc *fc; |
| 749 | struct fcoe_dev_stats *stats; |
Vasu Dev | bc0e17f | 2009-02-27 10:54:57 -0800 | [diff] [blame] | 750 | u32 new_link_up; |
Robert Love | 85b4aa4 | 2008-12-09 15:10:24 -0800 | [diff] [blame] | 751 | u32 mfs; |
| 752 | int rc = NOTIFY_OK; |
| 753 | |
| 754 | read_lock(&fcoe_hostlist_lock); |
| 755 | list_for_each_entry(fc, &fcoe_hostlist, list) { |
| 756 | if (fc->real_dev == real_dev) { |
| 757 | lp = fc->lp; |
| 758 | break; |
| 759 | } |
| 760 | } |
| 761 | read_unlock(&fcoe_hostlist_lock); |
| 762 | if (lp == NULL) { |
| 763 | rc = NOTIFY_DONE; |
| 764 | goto out; |
| 765 | } |
| 766 | |
Vasu Dev | bc0e17f | 2009-02-27 10:54:57 -0800 | [diff] [blame] | 767 | new_link_up = lp->link_up; |
Robert Love | 85b4aa4 | 2008-12-09 15:10:24 -0800 | [diff] [blame] | 768 | switch (event) { |
| 769 | case NETDEV_DOWN: |
| 770 | case NETDEV_GOING_DOWN: |
Vasu Dev | bc0e17f | 2009-02-27 10:54:57 -0800 | [diff] [blame] | 771 | new_link_up = 0; |
Robert Love | 85b4aa4 | 2008-12-09 15:10:24 -0800 | [diff] [blame] | 772 | break; |
| 773 | case NETDEV_UP: |
| 774 | case NETDEV_CHANGE: |
Vasu Dev | bc0e17f | 2009-02-27 10:54:57 -0800 | [diff] [blame] | 775 | new_link_up = !fcoe_link_ok(lp); |
Robert Love | 85b4aa4 | 2008-12-09 15:10:24 -0800 | [diff] [blame] | 776 | break; |
| 777 | case NETDEV_CHANGEMTU: |
| 778 | mfs = fc->real_dev->mtu - |
| 779 | (sizeof(struct fcoe_hdr) + |
| 780 | sizeof(struct fcoe_crc_eof)); |
| 781 | if (mfs >= FC_MIN_MAX_FRAME) |
| 782 | fc_set_mfs(lp, mfs); |
Vasu Dev | bc0e17f | 2009-02-27 10:54:57 -0800 | [diff] [blame] | 783 | new_link_up = !fcoe_link_ok(lp); |
Robert Love | 85b4aa4 | 2008-12-09 15:10:24 -0800 | [diff] [blame] | 784 | break; |
| 785 | case NETDEV_REGISTER: |
| 786 | break; |
| 787 | default: |
| 788 | FC_DBG("unknown event %ld call", event); |
| 789 | } |
Vasu Dev | bc0e17f | 2009-02-27 10:54:57 -0800 | [diff] [blame] | 790 | if (lp->link_up != new_link_up) { |
| 791 | if (new_link_up) |
Robert Love | 85b4aa4 | 2008-12-09 15:10:24 -0800 | [diff] [blame] | 792 | fc_linkup(lp); |
| 793 | else { |
Robert Love | 582b45b | 2009-03-31 15:51:50 -0700 | [diff] [blame^] | 794 | stats = fc_lport_get_stats(lp); |
| 795 | stats->LinkFailureCount++; |
Robert Love | 85b4aa4 | 2008-12-09 15:10:24 -0800 | [diff] [blame] | 796 | fc_linkdown(lp); |
| 797 | fcoe_clean_pending_queue(lp); |
| 798 | } |
| 799 | } |
| 800 | out: |
| 801 | return rc; |
| 802 | } |
| 803 | |
| 804 | /** |
Robert Love | 34f42a0 | 2009-02-27 10:55:45 -0800 | [diff] [blame] | 805 | * fcoe_if_to_netdev() - parse a name buffer to get netdev |
Robert Love | 85b4aa4 | 2008-12-09 15:10:24 -0800 | [diff] [blame] | 806 | * @ifname: fixed array for output parsed ifname |
| 807 | * @buffer: incoming buffer to be copied |
| 808 | * |
| 809 | * Returns: NULL or ptr to netdeive |
Robert Love | 34f42a0 | 2009-02-27 10:55:45 -0800 | [diff] [blame] | 810 | */ |
Robert Love | 85b4aa4 | 2008-12-09 15:10:24 -0800 | [diff] [blame] | 811 | static struct net_device *fcoe_if_to_netdev(const char *buffer) |
| 812 | { |
| 813 | char *cp; |
| 814 | char ifname[IFNAMSIZ + 2]; |
| 815 | |
| 816 | if (buffer) { |
| 817 | strlcpy(ifname, buffer, IFNAMSIZ); |
| 818 | cp = ifname + strlen(ifname); |
| 819 | while (--cp >= ifname && *cp == '\n') |
| 820 | *cp = '\0'; |
| 821 | return dev_get_by_name(&init_net, ifname); |
| 822 | } |
| 823 | return NULL; |
| 824 | } |
| 825 | |
| 826 | /** |
Robert Love | 34f42a0 | 2009-02-27 10:55:45 -0800 | [diff] [blame] | 827 | * fcoe_netdev_to_module_owner() - finds out the nic drive moddule of the netdev |
Robert Love | 85b4aa4 | 2008-12-09 15:10:24 -0800 | [diff] [blame] | 828 | * @netdev: the target netdev |
| 829 | * |
| 830 | * Returns: ptr to the struct module, NULL for failure |
Robert Love | 34f42a0 | 2009-02-27 10:55:45 -0800 | [diff] [blame] | 831 | */ |
Robert Love | b2ab99c | 2009-02-27 10:55:50 -0800 | [diff] [blame] | 832 | static struct module * |
| 833 | fcoe_netdev_to_module_owner(const struct net_device *netdev) |
Robert Love | 85b4aa4 | 2008-12-09 15:10:24 -0800 | [diff] [blame] | 834 | { |
| 835 | struct device *dev; |
| 836 | |
| 837 | if (!netdev) |
| 838 | return NULL; |
| 839 | |
| 840 | dev = netdev->dev.parent; |
| 841 | if (!dev) |
| 842 | return NULL; |
| 843 | |
| 844 | if (!dev->driver) |
| 845 | return NULL; |
| 846 | |
| 847 | return dev->driver->owner; |
| 848 | } |
| 849 | |
| 850 | /** |
Robert Love | 34f42a0 | 2009-02-27 10:55:45 -0800 | [diff] [blame] | 851 | * fcoe_ethdrv_get() - Hold the Ethernet driver |
Robert Love | 85b4aa4 | 2008-12-09 15:10:24 -0800 | [diff] [blame] | 852 | * @netdev: the target netdev |
| 853 | * |
Robert Love | 34f42a0 | 2009-02-27 10:55:45 -0800 | [diff] [blame] | 854 | * Holds the Ethernet driver module by try_module_get() for |
| 855 | * the corresponding netdev. |
| 856 | * |
Robert Love | 85b4aa4 | 2008-12-09 15:10:24 -0800 | [diff] [blame] | 857 | * Returns: 0 for succsss |
Robert Love | 34f42a0 | 2009-02-27 10:55:45 -0800 | [diff] [blame] | 858 | */ |
Robert Love | 85b4aa4 | 2008-12-09 15:10:24 -0800 | [diff] [blame] | 859 | static int fcoe_ethdrv_get(const struct net_device *netdev) |
| 860 | { |
| 861 | struct module *owner; |
| 862 | |
| 863 | owner = fcoe_netdev_to_module_owner(netdev); |
| 864 | if (owner) { |
James Bottomley | 56b854b | 2008-12-29 15:45:41 -0600 | [diff] [blame] | 865 | printk(KERN_DEBUG "fcoe:hold driver module %s for %s\n", |
| 866 | module_name(owner), netdev->name); |
Robert Love | 85b4aa4 | 2008-12-09 15:10:24 -0800 | [diff] [blame] | 867 | return try_module_get(owner); |
| 868 | } |
| 869 | return -ENODEV; |
| 870 | } |
| 871 | |
| 872 | /** |
Robert Love | 34f42a0 | 2009-02-27 10:55:45 -0800 | [diff] [blame] | 873 | * fcoe_ethdrv_put() - Release the Ethernet driver |
Robert Love | 85b4aa4 | 2008-12-09 15:10:24 -0800 | [diff] [blame] | 874 | * @netdev: the target netdev |
| 875 | * |
Robert Love | 34f42a0 | 2009-02-27 10:55:45 -0800 | [diff] [blame] | 876 | * Releases the Ethernet driver module by module_put for |
| 877 | * the corresponding netdev. |
| 878 | * |
Robert Love | 85b4aa4 | 2008-12-09 15:10:24 -0800 | [diff] [blame] | 879 | * Returns: 0 for succsss |
Robert Love | 34f42a0 | 2009-02-27 10:55:45 -0800 | [diff] [blame] | 880 | */ |
Robert Love | 85b4aa4 | 2008-12-09 15:10:24 -0800 | [diff] [blame] | 881 | static int fcoe_ethdrv_put(const struct net_device *netdev) |
| 882 | { |
| 883 | struct module *owner; |
| 884 | |
| 885 | owner = fcoe_netdev_to_module_owner(netdev); |
| 886 | if (owner) { |
James Bottomley | 56b854b | 2008-12-29 15:45:41 -0600 | [diff] [blame] | 887 | printk(KERN_DEBUG "fcoe:release driver module %s for %s\n", |
| 888 | module_name(owner), netdev->name); |
Robert Love | 85b4aa4 | 2008-12-09 15:10:24 -0800 | [diff] [blame] | 889 | module_put(owner); |
| 890 | return 0; |
| 891 | } |
| 892 | return -ENODEV; |
| 893 | } |
| 894 | |
| 895 | /** |
Robert Love | 34f42a0 | 2009-02-27 10:55:45 -0800 | [diff] [blame] | 896 | * fcoe_destroy() - handles the destroy from sysfs |
Robert Love | 85b4aa4 | 2008-12-09 15:10:24 -0800 | [diff] [blame] | 897 | * @buffer: expcted to be a eth if name |
| 898 | * @kp: associated kernel param |
| 899 | * |
| 900 | * Returns: 0 for success |
Robert Love | 34f42a0 | 2009-02-27 10:55:45 -0800 | [diff] [blame] | 901 | */ |
Robert Love | 85b4aa4 | 2008-12-09 15:10:24 -0800 | [diff] [blame] | 902 | static int fcoe_destroy(const char *buffer, struct kernel_param *kp) |
| 903 | { |
| 904 | int rc; |
| 905 | struct net_device *netdev; |
| 906 | |
| 907 | netdev = fcoe_if_to_netdev(buffer); |
| 908 | if (!netdev) { |
| 909 | rc = -ENODEV; |
| 910 | goto out_nodev; |
| 911 | } |
| 912 | /* look for existing lport */ |
| 913 | if (!fcoe_hostlist_lookup(netdev)) { |
| 914 | rc = -ENODEV; |
| 915 | goto out_putdev; |
| 916 | } |
| 917 | /* pass to transport */ |
| 918 | rc = fcoe_transport_release(netdev); |
| 919 | if (rc) { |
| 920 | printk(KERN_ERR "fcoe: fcoe_transport_release(%s) failed\n", |
| 921 | netdev->name); |
| 922 | rc = -EIO; |
| 923 | goto out_putdev; |
| 924 | } |
| 925 | fcoe_ethdrv_put(netdev); |
| 926 | rc = 0; |
| 927 | out_putdev: |
| 928 | dev_put(netdev); |
| 929 | out_nodev: |
| 930 | return rc; |
| 931 | } |
| 932 | |
| 933 | /** |
Robert Love | 34f42a0 | 2009-02-27 10:55:45 -0800 | [diff] [blame] | 934 | * fcoe_create() - Handles the create call from sysfs |
Robert Love | 85b4aa4 | 2008-12-09 15:10:24 -0800 | [diff] [blame] | 935 | * @buffer: expcted to be a eth if name |
| 936 | * @kp: associated kernel param |
| 937 | * |
| 938 | * Returns: 0 for success |
Robert Love | 34f42a0 | 2009-02-27 10:55:45 -0800 | [diff] [blame] | 939 | */ |
Robert Love | 85b4aa4 | 2008-12-09 15:10:24 -0800 | [diff] [blame] | 940 | static int fcoe_create(const char *buffer, struct kernel_param *kp) |
| 941 | { |
| 942 | int rc; |
| 943 | struct net_device *netdev; |
| 944 | |
| 945 | netdev = fcoe_if_to_netdev(buffer); |
| 946 | if (!netdev) { |
| 947 | rc = -ENODEV; |
| 948 | goto out_nodev; |
| 949 | } |
| 950 | /* look for existing lport */ |
| 951 | if (fcoe_hostlist_lookup(netdev)) { |
| 952 | rc = -EEXIST; |
| 953 | goto out_putdev; |
| 954 | } |
| 955 | fcoe_ethdrv_get(netdev); |
| 956 | |
| 957 | /* pass to transport */ |
| 958 | rc = fcoe_transport_attach(netdev); |
| 959 | if (rc) { |
| 960 | printk(KERN_ERR "fcoe: fcoe_transport_attach(%s) failed\n", |
| 961 | netdev->name); |
| 962 | fcoe_ethdrv_put(netdev); |
| 963 | rc = -EIO; |
| 964 | goto out_putdev; |
| 965 | } |
| 966 | rc = 0; |
| 967 | out_putdev: |
| 968 | dev_put(netdev); |
| 969 | out_nodev: |
| 970 | return rc; |
| 971 | } |
| 972 | |
| 973 | module_param_call(create, fcoe_create, NULL, NULL, S_IWUSR); |
| 974 | __MODULE_PARM_TYPE(create, "string"); |
| 975 | MODULE_PARM_DESC(create, "Create fcoe port using net device passed in."); |
| 976 | module_param_call(destroy, fcoe_destroy, NULL, NULL, S_IWUSR); |
| 977 | __MODULE_PARM_TYPE(destroy, "string"); |
| 978 | MODULE_PARM_DESC(destroy, "Destroy fcoe port"); |
| 979 | |
Robert Love | 34f42a0 | 2009-02-27 10:55:45 -0800 | [diff] [blame] | 980 | /** |
| 981 | * fcoe_link_ok() - Check if link is ok for the fc_lport |
Robert Love | 85b4aa4 | 2008-12-09 15:10:24 -0800 | [diff] [blame] | 982 | * @lp: ptr to the fc_lport |
| 983 | * |
| 984 | * Any permanently-disqualifying conditions have been previously checked. |
| 985 | * This also updates the speed setting, which may change with link for 100/1000. |
| 986 | * |
| 987 | * This function should probably be checking for PAUSE support at some point |
| 988 | * in the future. Currently Per-priority-pause is not determinable using |
| 989 | * ethtool, so we shouldn't be restrictive until that problem is resolved. |
| 990 | * |
| 991 | * Returns: 0 if link is OK for use by FCoE. |
| 992 | * |
| 993 | */ |
| 994 | int fcoe_link_ok(struct fc_lport *lp) |
| 995 | { |
Robert Love | fc47ff6 | 2009-02-27 10:55:55 -0800 | [diff] [blame] | 996 | struct fcoe_softc *fc = lport_priv(lp); |
Robert Love | 85b4aa4 | 2008-12-09 15:10:24 -0800 | [diff] [blame] | 997 | struct net_device *dev = fc->real_dev; |
| 998 | struct ethtool_cmd ecmd = { ETHTOOL_GSET }; |
| 999 | int rc = 0; |
| 1000 | |
| 1001 | if ((dev->flags & IFF_UP) && netif_carrier_ok(dev)) { |
| 1002 | dev = fc->phys_dev; |
| 1003 | if (dev->ethtool_ops->get_settings) { |
| 1004 | dev->ethtool_ops->get_settings(dev, &ecmd); |
| 1005 | lp->link_supported_speeds &= |
| 1006 | ~(FC_PORTSPEED_1GBIT | FC_PORTSPEED_10GBIT); |
| 1007 | if (ecmd.supported & (SUPPORTED_1000baseT_Half | |
| 1008 | SUPPORTED_1000baseT_Full)) |
| 1009 | lp->link_supported_speeds |= FC_PORTSPEED_1GBIT; |
| 1010 | if (ecmd.supported & SUPPORTED_10000baseT_Full) |
| 1011 | lp->link_supported_speeds |= |
| 1012 | FC_PORTSPEED_10GBIT; |
| 1013 | if (ecmd.speed == SPEED_1000) |
| 1014 | lp->link_speed = FC_PORTSPEED_1GBIT; |
| 1015 | if (ecmd.speed == SPEED_10000) |
| 1016 | lp->link_speed = FC_PORTSPEED_10GBIT; |
| 1017 | } |
| 1018 | } else |
| 1019 | rc = -1; |
| 1020 | |
| 1021 | return rc; |
| 1022 | } |
| 1023 | EXPORT_SYMBOL_GPL(fcoe_link_ok); |
| 1024 | |
Robert Love | 34f42a0 | 2009-02-27 10:55:45 -0800 | [diff] [blame] | 1025 | /** |
| 1026 | * fcoe_percpu_clean() - Clear the pending skbs for an lport |
Robert Love | 85b4aa4 | 2008-12-09 15:10:24 -0800 | [diff] [blame] | 1027 | * @lp: the fc_lport |
| 1028 | */ |
| 1029 | void fcoe_percpu_clean(struct fc_lport *lp) |
| 1030 | { |
Robert Love | 85b4aa4 | 2008-12-09 15:10:24 -0800 | [diff] [blame] | 1031 | struct fcoe_percpu_s *pp; |
| 1032 | struct fcoe_rcv_info *fr; |
| 1033 | struct sk_buff_head *list; |
| 1034 | struct sk_buff *skb, *next; |
| 1035 | struct sk_buff *head; |
Robert Love | 5e5e92d | 2009-03-17 11:41:35 -0700 | [diff] [blame] | 1036 | unsigned int cpu; |
Robert Love | 85b4aa4 | 2008-12-09 15:10:24 -0800 | [diff] [blame] | 1037 | |
Robert Love | 5e5e92d | 2009-03-17 11:41:35 -0700 | [diff] [blame] | 1038 | for_each_possible_cpu(cpu) { |
| 1039 | pp = &per_cpu(fcoe_percpu, cpu); |
| 1040 | spin_lock_bh(&pp->fcoe_rx_list.lock); |
| 1041 | list = &pp->fcoe_rx_list; |
| 1042 | head = list->next; |
| 1043 | for (skb = head; skb != (struct sk_buff *)list; |
| 1044 | skb = next) { |
| 1045 | next = skb->next; |
| 1046 | fr = fcoe_dev_from_skb(skb); |
| 1047 | if (fr->fr_dev == lp) { |
| 1048 | __skb_unlink(skb, list); |
| 1049 | kfree_skb(skb); |
Robert Love | 85b4aa4 | 2008-12-09 15:10:24 -0800 | [diff] [blame] | 1050 | } |
Robert Love | 85b4aa4 | 2008-12-09 15:10:24 -0800 | [diff] [blame] | 1051 | } |
Robert Love | 5e5e92d | 2009-03-17 11:41:35 -0700 | [diff] [blame] | 1052 | spin_unlock_bh(&pp->fcoe_rx_list.lock); |
Robert Love | 85b4aa4 | 2008-12-09 15:10:24 -0800 | [diff] [blame] | 1053 | } |
| 1054 | } |
| 1055 | EXPORT_SYMBOL_GPL(fcoe_percpu_clean); |
| 1056 | |
| 1057 | /** |
Robert Love | 34f42a0 | 2009-02-27 10:55:45 -0800 | [diff] [blame] | 1058 | * fcoe_clean_pending_queue() - Dequeue a skb and free it |
Robert Love | 85b4aa4 | 2008-12-09 15:10:24 -0800 | [diff] [blame] | 1059 | * @lp: the corresponding fc_lport |
| 1060 | * |
| 1061 | * Returns: none |
Robert Love | 34f42a0 | 2009-02-27 10:55:45 -0800 | [diff] [blame] | 1062 | */ |
Robert Love | 85b4aa4 | 2008-12-09 15:10:24 -0800 | [diff] [blame] | 1063 | void fcoe_clean_pending_queue(struct fc_lport *lp) |
| 1064 | { |
| 1065 | struct fcoe_softc *fc = lport_priv(lp); |
| 1066 | struct sk_buff *skb; |
| 1067 | |
| 1068 | spin_lock_bh(&fc->fcoe_pending_queue.lock); |
| 1069 | while ((skb = __skb_dequeue(&fc->fcoe_pending_queue)) != NULL) { |
| 1070 | spin_unlock_bh(&fc->fcoe_pending_queue.lock); |
| 1071 | kfree_skb(skb); |
| 1072 | spin_lock_bh(&fc->fcoe_pending_queue.lock); |
| 1073 | } |
| 1074 | spin_unlock_bh(&fc->fcoe_pending_queue.lock); |
| 1075 | } |
| 1076 | EXPORT_SYMBOL_GPL(fcoe_clean_pending_queue); |
| 1077 | |
| 1078 | /** |
Robert Love | 34f42a0 | 2009-02-27 10:55:45 -0800 | [diff] [blame] | 1079 | * libfc_host_alloc() - Allocate a Scsi_Host with room for the fc_lport |
Robert Love | 85b4aa4 | 2008-12-09 15:10:24 -0800 | [diff] [blame] | 1080 | * @sht: ptr to the scsi host templ |
| 1081 | * @priv_size: size of private data after fc_lport |
| 1082 | * |
| 1083 | * Returns: ptr to Scsi_Host |
Robert Love | 34f42a0 | 2009-02-27 10:55:45 -0800 | [diff] [blame] | 1084 | * TODO: to libfc? |
Robert Love | 85b4aa4 | 2008-12-09 15:10:24 -0800 | [diff] [blame] | 1085 | */ |
Robert Love | b2ab99c | 2009-02-27 10:55:50 -0800 | [diff] [blame] | 1086 | static inline struct Scsi_Host * |
| 1087 | libfc_host_alloc(struct scsi_host_template *sht, int priv_size) |
Robert Love | 85b4aa4 | 2008-12-09 15:10:24 -0800 | [diff] [blame] | 1088 | { |
| 1089 | return scsi_host_alloc(sht, sizeof(struct fc_lport) + priv_size); |
| 1090 | } |
| 1091 | |
| 1092 | /** |
Robert Love | 34f42a0 | 2009-02-27 10:55:45 -0800 | [diff] [blame] | 1093 | * fcoe_host_alloc() - Allocate a Scsi_Host with room for the fcoe_softc |
Robert Love | 85b4aa4 | 2008-12-09 15:10:24 -0800 | [diff] [blame] | 1094 | * @sht: ptr to the scsi host templ |
| 1095 | * @priv_size: size of private data after fc_lport |
| 1096 | * |
| 1097 | * Returns: ptr to Scsi_Host |
| 1098 | */ |
| 1099 | struct Scsi_Host *fcoe_host_alloc(struct scsi_host_template *sht, int priv_size) |
| 1100 | { |
| 1101 | return libfc_host_alloc(sht, sizeof(struct fcoe_softc) + priv_size); |
| 1102 | } |
| 1103 | EXPORT_SYMBOL_GPL(fcoe_host_alloc); |
| 1104 | |
Robert Love | 34f42a0 | 2009-02-27 10:55:45 -0800 | [diff] [blame] | 1105 | /** |
| 1106 | * fcoe_reset() - Resets the fcoe |
Robert Love | 85b4aa4 | 2008-12-09 15:10:24 -0800 | [diff] [blame] | 1107 | * @shost: shost the reset is from |
| 1108 | * |
| 1109 | * Returns: always 0 |
| 1110 | */ |
| 1111 | int fcoe_reset(struct Scsi_Host *shost) |
| 1112 | { |
| 1113 | struct fc_lport *lport = shost_priv(shost); |
| 1114 | fc_lport_reset(lport); |
| 1115 | return 0; |
| 1116 | } |
| 1117 | EXPORT_SYMBOL_GPL(fcoe_reset); |
| 1118 | |
Robert Love | 34f42a0 | 2009-02-27 10:55:45 -0800 | [diff] [blame] | 1119 | /** |
| 1120 | * fcoe_wwn_from_mac() - Converts 48-bit IEEE MAC address to 64-bit FC WWN. |
Robert Love | 85b4aa4 | 2008-12-09 15:10:24 -0800 | [diff] [blame] | 1121 | * @mac: mac address |
| 1122 | * @scheme: check port |
| 1123 | * @port: port indicator for converting |
| 1124 | * |
| 1125 | * Returns: u64 fc world wide name |
| 1126 | */ |
| 1127 | u64 fcoe_wwn_from_mac(unsigned char mac[MAX_ADDR_LEN], |
| 1128 | unsigned int scheme, unsigned int port) |
| 1129 | { |
| 1130 | u64 wwn; |
| 1131 | u64 host_mac; |
| 1132 | |
| 1133 | /* The MAC is in NO, so flip only the low 48 bits */ |
| 1134 | host_mac = ((u64) mac[0] << 40) | |
| 1135 | ((u64) mac[1] << 32) | |
| 1136 | ((u64) mac[2] << 24) | |
| 1137 | ((u64) mac[3] << 16) | |
| 1138 | ((u64) mac[4] << 8) | |
| 1139 | (u64) mac[5]; |
| 1140 | |
| 1141 | WARN_ON(host_mac >= (1ULL << 48)); |
| 1142 | wwn = host_mac | ((u64) scheme << 60); |
| 1143 | switch (scheme) { |
| 1144 | case 1: |
| 1145 | WARN_ON(port != 0); |
| 1146 | break; |
| 1147 | case 2: |
| 1148 | WARN_ON(port >= 0xfff); |
| 1149 | wwn |= (u64) port << 48; |
| 1150 | break; |
| 1151 | default: |
| 1152 | WARN_ON(1); |
| 1153 | break; |
| 1154 | } |
| 1155 | |
| 1156 | return wwn; |
| 1157 | } |
| 1158 | EXPORT_SYMBOL_GPL(fcoe_wwn_from_mac); |
Robert Love | 34f42a0 | 2009-02-27 10:55:45 -0800 | [diff] [blame] | 1159 | |
| 1160 | /** |
| 1161 | * fcoe_hostlist_lookup_softc() - find the corresponding lport by a given device |
Robert Love | 85b4aa4 | 2008-12-09 15:10:24 -0800 | [diff] [blame] | 1162 | * @device: this is currently ptr to net_device |
| 1163 | * |
| 1164 | * Returns: NULL or the located fcoe_softc |
| 1165 | */ |
Robert Love | b2ab99c | 2009-02-27 10:55:50 -0800 | [diff] [blame] | 1166 | static struct fcoe_softc * |
| 1167 | fcoe_hostlist_lookup_softc(const struct net_device *dev) |
Robert Love | 85b4aa4 | 2008-12-09 15:10:24 -0800 | [diff] [blame] | 1168 | { |
| 1169 | struct fcoe_softc *fc; |
| 1170 | |
| 1171 | read_lock(&fcoe_hostlist_lock); |
| 1172 | list_for_each_entry(fc, &fcoe_hostlist, list) { |
| 1173 | if (fc->real_dev == dev) { |
| 1174 | read_unlock(&fcoe_hostlist_lock); |
| 1175 | return fc; |
| 1176 | } |
| 1177 | } |
| 1178 | read_unlock(&fcoe_hostlist_lock); |
| 1179 | return NULL; |
| 1180 | } |
| 1181 | |
Robert Love | 34f42a0 | 2009-02-27 10:55:45 -0800 | [diff] [blame] | 1182 | /** |
| 1183 | * fcoe_hostlist_lookup() - Find the corresponding lport by netdev |
Robert Love | 85b4aa4 | 2008-12-09 15:10:24 -0800 | [diff] [blame] | 1184 | * @netdev: ptr to net_device |
| 1185 | * |
| 1186 | * Returns: 0 for success |
| 1187 | */ |
| 1188 | struct fc_lport *fcoe_hostlist_lookup(const struct net_device *netdev) |
| 1189 | { |
| 1190 | struct fcoe_softc *fc; |
| 1191 | |
| 1192 | fc = fcoe_hostlist_lookup_softc(netdev); |
| 1193 | |
| 1194 | return (fc) ? fc->lp : NULL; |
| 1195 | } |
| 1196 | EXPORT_SYMBOL_GPL(fcoe_hostlist_lookup); |
| 1197 | |
Robert Love | 34f42a0 | 2009-02-27 10:55:45 -0800 | [diff] [blame] | 1198 | /** |
| 1199 | * fcoe_hostlist_add() - Add a lport to lports list |
Robert Love | 85b4aa4 | 2008-12-09 15:10:24 -0800 | [diff] [blame] | 1200 | * @lp: ptr to the fc_lport to badded |
| 1201 | * |
| 1202 | * Returns: 0 for success |
| 1203 | */ |
| 1204 | int fcoe_hostlist_add(const struct fc_lport *lp) |
| 1205 | { |
| 1206 | struct fcoe_softc *fc; |
| 1207 | |
| 1208 | fc = fcoe_hostlist_lookup_softc(fcoe_netdev(lp)); |
| 1209 | if (!fc) { |
Robert Love | fc47ff6 | 2009-02-27 10:55:55 -0800 | [diff] [blame] | 1210 | fc = lport_priv(lp); |
Robert Love | 85b4aa4 | 2008-12-09 15:10:24 -0800 | [diff] [blame] | 1211 | write_lock_bh(&fcoe_hostlist_lock); |
| 1212 | list_add_tail(&fc->list, &fcoe_hostlist); |
| 1213 | write_unlock_bh(&fcoe_hostlist_lock); |
| 1214 | } |
| 1215 | return 0; |
| 1216 | } |
| 1217 | EXPORT_SYMBOL_GPL(fcoe_hostlist_add); |
| 1218 | |
Robert Love | 34f42a0 | 2009-02-27 10:55:45 -0800 | [diff] [blame] | 1219 | /** |
| 1220 | * fcoe_hostlist_remove() - remove a lport from lports list |
Robert Love | 85b4aa4 | 2008-12-09 15:10:24 -0800 | [diff] [blame] | 1221 | * @lp: ptr to the fc_lport to badded |
| 1222 | * |
| 1223 | * Returns: 0 for success |
| 1224 | */ |
| 1225 | int fcoe_hostlist_remove(const struct fc_lport *lp) |
| 1226 | { |
| 1227 | struct fcoe_softc *fc; |
| 1228 | |
| 1229 | fc = fcoe_hostlist_lookup_softc(fcoe_netdev(lp)); |
| 1230 | BUG_ON(!fc); |
| 1231 | write_lock_bh(&fcoe_hostlist_lock); |
| 1232 | list_del(&fc->list); |
| 1233 | write_unlock_bh(&fcoe_hostlist_lock); |
| 1234 | |
| 1235 | return 0; |
| 1236 | } |
| 1237 | EXPORT_SYMBOL_GPL(fcoe_hostlist_remove); |
| 1238 | |
| 1239 | /** |
Robert Love | 34f42a0 | 2009-02-27 10:55:45 -0800 | [diff] [blame] | 1240 | * fcoe_libfc_config() - sets up libfc related properties for lport |
Robert Love | 85b4aa4 | 2008-12-09 15:10:24 -0800 | [diff] [blame] | 1241 | * @lp: ptr to the fc_lport |
| 1242 | * @tt: libfc function template |
| 1243 | * |
| 1244 | * Returns : 0 for success |
Robert Love | 34f42a0 | 2009-02-27 10:55:45 -0800 | [diff] [blame] | 1245 | */ |
Robert Love | 85b4aa4 | 2008-12-09 15:10:24 -0800 | [diff] [blame] | 1246 | int fcoe_libfc_config(struct fc_lport *lp, struct libfc_function_template *tt) |
| 1247 | { |
| 1248 | /* Set the function pointers set by the LLDD */ |
| 1249 | memcpy(&lp->tt, tt, sizeof(*tt)); |
| 1250 | if (fc_fcp_init(lp)) |
| 1251 | return -ENOMEM; |
| 1252 | fc_exch_init(lp); |
| 1253 | fc_elsct_init(lp); |
| 1254 | fc_lport_init(lp); |
| 1255 | fc_rport_init(lp); |
| 1256 | fc_disc_init(lp); |
| 1257 | |
| 1258 | return 0; |
| 1259 | } |
| 1260 | EXPORT_SYMBOL_GPL(fcoe_libfc_config); |
| 1261 | |
| 1262 | /** |
Robert Love | 34f42a0 | 2009-02-27 10:55:45 -0800 | [diff] [blame] | 1263 | * fcoe_init() - fcoe module loading initialization |
Robert Love | 85b4aa4 | 2008-12-09 15:10:24 -0800 | [diff] [blame] | 1264 | * |
| 1265 | * Initialization routine |
| 1266 | * 1. Will create fc transport software structure |
| 1267 | * 2. initialize the link list of port information structure |
| 1268 | * |
| 1269 | * Returns 0 on success, negative on failure |
Robert Love | 34f42a0 | 2009-02-27 10:55:45 -0800 | [diff] [blame] | 1270 | */ |
Robert Love | 85b4aa4 | 2008-12-09 15:10:24 -0800 | [diff] [blame] | 1271 | static int __init fcoe_init(void) |
| 1272 | { |
Robert Love | 38eccab | 2009-03-17 11:41:30 -0700 | [diff] [blame] | 1273 | unsigned int cpu; |
Robert Love | 85b4aa4 | 2008-12-09 15:10:24 -0800 | [diff] [blame] | 1274 | struct fcoe_percpu_s *p; |
| 1275 | |
Robert Love | 85b4aa4 | 2008-12-09 15:10:24 -0800 | [diff] [blame] | 1276 | INIT_LIST_HEAD(&fcoe_hostlist); |
| 1277 | rwlock_init(&fcoe_hostlist_lock); |
| 1278 | |
Robert Love | 38eccab | 2009-03-17 11:41:30 -0700 | [diff] [blame] | 1279 | for_each_possible_cpu(cpu) { |
Robert Love | 5e5e92d | 2009-03-17 11:41:35 -0700 | [diff] [blame] | 1280 | p = &per_cpu(fcoe_percpu, cpu); |
Robert Love | 38eccab | 2009-03-17 11:41:30 -0700 | [diff] [blame] | 1281 | skb_queue_head_init(&p->fcoe_rx_list); |
| 1282 | } |
| 1283 | |
Robert Love | 85b4aa4 | 2008-12-09 15:10:24 -0800 | [diff] [blame] | 1284 | /* |
| 1285 | * initialize per CPU interrupt thread |
| 1286 | */ |
| 1287 | for_each_online_cpu(cpu) { |
Robert Love | 5e5e92d | 2009-03-17 11:41:35 -0700 | [diff] [blame] | 1288 | p = &per_cpu(fcoe_percpu, cpu); |
| 1289 | p->thread = kthread_create(fcoe_percpu_receive_thread, |
| 1290 | (void *)p, "fcoethread/%d", cpu); |
Robert Love | 85b4aa4 | 2008-12-09 15:10:24 -0800 | [diff] [blame] | 1291 | |
Robert Love | 5e5e92d | 2009-03-17 11:41:35 -0700 | [diff] [blame] | 1292 | /* |
| 1293 | * If there is no error then bind the thread to the CPU |
| 1294 | * and wake it up. |
| 1295 | */ |
| 1296 | if (!IS_ERR(p->thread)) { |
| 1297 | kthread_bind(p->thread, cpu); |
| 1298 | wake_up_process(p->thread); |
| 1299 | } else { |
| 1300 | p->thread = NULL; |
Robert Love | 85b4aa4 | 2008-12-09 15:10:24 -0800 | [diff] [blame] | 1301 | } |
| 1302 | } |
| 1303 | |
| 1304 | /* |
| 1305 | * setup link change notification |
| 1306 | */ |
| 1307 | fcoe_dev_setup(); |
| 1308 | |
Robert Love | a468f32 | 2009-02-27 10:56:00 -0800 | [diff] [blame] | 1309 | setup_timer(&fcoe_timer, fcoe_watchdog, 0); |
| 1310 | |
| 1311 | mod_timer(&fcoe_timer, jiffies + (10 * HZ)); |
Robert Love | 85b4aa4 | 2008-12-09 15:10:24 -0800 | [diff] [blame] | 1312 | |
| 1313 | /* initiatlize the fcoe transport */ |
| 1314 | fcoe_transport_init(); |
| 1315 | |
| 1316 | fcoe_sw_init(); |
| 1317 | |
| 1318 | return 0; |
| 1319 | } |
| 1320 | module_init(fcoe_init); |
| 1321 | |
| 1322 | /** |
Robert Love | 34f42a0 | 2009-02-27 10:55:45 -0800 | [diff] [blame] | 1323 | * fcoe_exit() - fcoe module unloading cleanup |
Robert Love | 85b4aa4 | 2008-12-09 15:10:24 -0800 | [diff] [blame] | 1324 | * |
| 1325 | * Returns 0 on success, negative on failure |
Robert Love | 34f42a0 | 2009-02-27 10:55:45 -0800 | [diff] [blame] | 1326 | */ |
Robert Love | 85b4aa4 | 2008-12-09 15:10:24 -0800 | [diff] [blame] | 1327 | static void __exit fcoe_exit(void) |
| 1328 | { |
Robert Love | 5e5e92d | 2009-03-17 11:41:35 -0700 | [diff] [blame] | 1329 | unsigned int cpu; |
Robert Love | 85b4aa4 | 2008-12-09 15:10:24 -0800 | [diff] [blame] | 1330 | struct fcoe_softc *fc, *tmp; |
| 1331 | struct fcoe_percpu_s *p; |
| 1332 | struct sk_buff *skb; |
| 1333 | |
Robert Love | 85b4aa4 | 2008-12-09 15:10:24 -0800 | [diff] [blame] | 1334 | fcoe_dev_cleanup(); |
| 1335 | |
Robert Love | 582b45b | 2009-03-31 15:51:50 -0700 | [diff] [blame^] | 1336 | /* Stop the timer */ |
Robert Love | 85b4aa4 | 2008-12-09 15:10:24 -0800 | [diff] [blame] | 1337 | del_timer_sync(&fcoe_timer); |
| 1338 | |
Robert Love | b2ab99c | 2009-02-27 10:55:50 -0800 | [diff] [blame] | 1339 | /* releases the associated fcoe transport for each lport */ |
Robert Love | 85b4aa4 | 2008-12-09 15:10:24 -0800 | [diff] [blame] | 1340 | list_for_each_entry_safe(fc, tmp, &fcoe_hostlist, list) |
| 1341 | fcoe_transport_release(fc->real_dev); |
| 1342 | |
Robert Love | 5e5e92d | 2009-03-17 11:41:35 -0700 | [diff] [blame] | 1343 | for_each_possible_cpu(cpu) { |
| 1344 | p = &per_cpu(fcoe_percpu, cpu); |
| 1345 | if (p->thread) { |
| 1346 | kthread_stop(p->thread); |
Robert Love | 85b4aa4 | 2008-12-09 15:10:24 -0800 | [diff] [blame] | 1347 | spin_lock_bh(&p->fcoe_rx_list.lock); |
| 1348 | while ((skb = __skb_dequeue(&p->fcoe_rx_list)) != NULL) |
| 1349 | kfree_skb(skb); |
| 1350 | spin_unlock_bh(&p->fcoe_rx_list.lock); |
Robert Love | 5e5e92d | 2009-03-17 11:41:35 -0700 | [diff] [blame] | 1351 | if (p->crc_eof_page) |
| 1352 | put_page(p->crc_eof_page); |
Robert Love | 85b4aa4 | 2008-12-09 15:10:24 -0800 | [diff] [blame] | 1353 | } |
| 1354 | } |
| 1355 | |
| 1356 | /* remove sw trasnport */ |
| 1357 | fcoe_sw_exit(); |
| 1358 | |
| 1359 | /* detach the transport */ |
| 1360 | fcoe_transport_exit(); |
| 1361 | } |
| 1362 | module_exit(fcoe_exit); |