15df6d737SAbhijeet Joglekar /* 25df6d737SAbhijeet Joglekar * Copyright 2008 Cisco Systems, Inc. All rights reserved. 35df6d737SAbhijeet Joglekar * Copyright 2007 Nuova Systems, Inc. All rights reserved. 45df6d737SAbhijeet Joglekar * 55df6d737SAbhijeet Joglekar * This program is free software; you may redistribute it and/or modify 65df6d737SAbhijeet Joglekar * it under the terms of the GNU General Public License as published by 75df6d737SAbhijeet Joglekar * the Free Software Foundation; version 2 of the License. 85df6d737SAbhijeet Joglekar * 95df6d737SAbhijeet Joglekar * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 105df6d737SAbhijeet Joglekar * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 115df6d737SAbhijeet Joglekar * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 125df6d737SAbhijeet Joglekar * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 135df6d737SAbhijeet Joglekar * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 145df6d737SAbhijeet Joglekar * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 155df6d737SAbhijeet Joglekar * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 165df6d737SAbhijeet Joglekar * SOFTWARE. 175df6d737SAbhijeet Joglekar */ 185df6d737SAbhijeet Joglekar #include <linux/errno.h> 195df6d737SAbhijeet Joglekar #include <linux/pci.h> 205a0e3ad6STejun Heo #include <linux/slab.h> 215df6d737SAbhijeet Joglekar #include <linux/skbuff.h> 225df6d737SAbhijeet Joglekar #include <linux/interrupt.h> 235df6d737SAbhijeet Joglekar #include <linux/spinlock.h> 245df6d737SAbhijeet Joglekar #include <linux/if_ether.h> 255df6d737SAbhijeet Joglekar #include <linux/if_vlan.h> 265df6d737SAbhijeet Joglekar #include <linux/workqueue.h> 2778112e55SJoe Eykholt #include <scsi/fc/fc_fip.h> 285df6d737SAbhijeet Joglekar #include <scsi/fc/fc_els.h> 295df6d737SAbhijeet Joglekar #include <scsi/fc/fc_fcoe.h> 305df6d737SAbhijeet Joglekar #include <scsi/fc_frame.h> 315df6d737SAbhijeet Joglekar #include <scsi/libfc.h> 325df6d737SAbhijeet Joglekar #include "fnic_io.h" 335df6d737SAbhijeet Joglekar #include "fnic.h" 34d3c995f1SHiral Patel #include "fnic_fip.h" 355df6d737SAbhijeet Joglekar #include "cq_enet_desc.h" 365df6d737SAbhijeet Joglekar #include "cq_exch_desc.h" 375df6d737SAbhijeet Joglekar 3886001f24SHiral Shah static u8 fcoe_all_fcfs[ETH_ALEN] = FIP_ALL_FCF_MACS; 39d3c995f1SHiral Patel struct workqueue_struct *fnic_fip_queue; 405df6d737SAbhijeet Joglekar struct workqueue_struct *fnic_event_queue; 415df6d737SAbhijeet Joglekar 4278112e55SJoe Eykholt static void fnic_set_eth_mode(struct fnic *); 43d3c995f1SHiral Patel static void fnic_fcoe_send_vlan_req(struct fnic *fnic); 44d3c995f1SHiral Patel static void fnic_fcoe_start_fcf_disc(struct fnic *fnic); 45d3c995f1SHiral Patel static void fnic_fcoe_process_vlan_resp(struct fnic *fnic, struct sk_buff *); 46d3c995f1SHiral Patel static int fnic_fcoe_vlan_check(struct fnic *fnic, u16 flag); 47d3c995f1SHiral Patel static int fnic_fcoe_handle_fip_frame(struct fnic *fnic, struct sk_buff *skb); 4878112e55SJoe Eykholt 495df6d737SAbhijeet Joglekar void fnic_handle_link(struct work_struct *work) 505df6d737SAbhijeet Joglekar { 515df6d737SAbhijeet Joglekar struct fnic *fnic = container_of(work, struct fnic, link_work); 525df6d737SAbhijeet Joglekar unsigned long flags; 535df6d737SAbhijeet Joglekar int old_link_status; 545df6d737SAbhijeet Joglekar u32 old_link_down_cnt; 5590302e95SJohn Pittman u64 old_port_speed, new_port_speed; 565df6d737SAbhijeet Joglekar 575df6d737SAbhijeet Joglekar spin_lock_irqsave(&fnic->fnic_lock, flags); 585df6d737SAbhijeet Joglekar 59f9e2beb9SKaran Tilak Kumar fnic->link_events = 1; /* less work to just set everytime*/ 60f9e2beb9SKaran Tilak Kumar 615df6d737SAbhijeet Joglekar if (fnic->stop_rx_link_events) { 625df6d737SAbhijeet Joglekar spin_unlock_irqrestore(&fnic->fnic_lock, flags); 635df6d737SAbhijeet Joglekar return; 645df6d737SAbhijeet Joglekar } 655df6d737SAbhijeet Joglekar 665df6d737SAbhijeet Joglekar old_link_down_cnt = fnic->link_down_cnt; 675df6d737SAbhijeet Joglekar old_link_status = fnic->link_status; 6890302e95SJohn Pittman old_port_speed = atomic64_read( 6990302e95SJohn Pittman &fnic->fnic_stats.misc_stats.current_port_speed); 7090302e95SJohn Pittman 715df6d737SAbhijeet Joglekar fnic->link_status = vnic_dev_link_status(fnic->vdev); 725df6d737SAbhijeet Joglekar fnic->link_down_cnt = vnic_dev_link_down_cnt(fnic->vdev); 735df6d737SAbhijeet Joglekar 7490302e95SJohn Pittman new_port_speed = vnic_dev_port_speed(fnic->vdev); 75d948e638SSatish Kharat atomic64_set(&fnic->fnic_stats.misc_stats.current_port_speed, 7690302e95SJohn Pittman new_port_speed); 7790302e95SJohn Pittman if (old_port_speed != new_port_speed) 78875d4edaSKaran Tilak Kumar FNIC_MAIN_DBG(KERN_INFO, fnic->lport->host, 7990302e95SJohn Pittman "Current vnic speed set to : %llu\n", 8090302e95SJohn Pittman new_port_speed); 81d948e638SSatish Kharat 82c22fa50bSSatish Kharat switch (vnic_dev_port_speed(fnic->vdev)) { 83c22fa50bSSatish Kharat case DCEM_PORTSPEED_10G: 84c22fa50bSSatish Kharat fc_host_speed(fnic->lport->host) = FC_PORTSPEED_10GBIT; 85c22fa50bSSatish Kharat fnic->lport->link_supported_speeds = FC_PORTSPEED_10GBIT; 86c22fa50bSSatish Kharat break; 87c01461a6SSatish Kharat case DCEM_PORTSPEED_20G: 88c01461a6SSatish Kharat fc_host_speed(fnic->lport->host) = FC_PORTSPEED_20GBIT; 89c01461a6SSatish Kharat fnic->lport->link_supported_speeds = FC_PORTSPEED_20GBIT; 90c01461a6SSatish Kharat break; 91c22fa50bSSatish Kharat case DCEM_PORTSPEED_25G: 92c22fa50bSSatish Kharat fc_host_speed(fnic->lport->host) = FC_PORTSPEED_25GBIT; 93c22fa50bSSatish Kharat fnic->lport->link_supported_speeds = FC_PORTSPEED_25GBIT; 94c22fa50bSSatish Kharat break; 95c22fa50bSSatish Kharat case DCEM_PORTSPEED_40G: 96c22fa50bSSatish Kharat case DCEM_PORTSPEED_4x10G: 97c22fa50bSSatish Kharat fc_host_speed(fnic->lport->host) = FC_PORTSPEED_40GBIT; 98c22fa50bSSatish Kharat fnic->lport->link_supported_speeds = FC_PORTSPEED_40GBIT; 99c22fa50bSSatish Kharat break; 100c22fa50bSSatish Kharat case DCEM_PORTSPEED_100G: 101c22fa50bSSatish Kharat fc_host_speed(fnic->lport->host) = FC_PORTSPEED_100GBIT; 102c22fa50bSSatish Kharat fnic->lport->link_supported_speeds = FC_PORTSPEED_100GBIT; 103c22fa50bSSatish Kharat break; 104c22fa50bSSatish Kharat default: 105c22fa50bSSatish Kharat fc_host_speed(fnic->lport->host) = FC_PORTSPEED_UNKNOWN; 106c22fa50bSSatish Kharat fnic->lport->link_supported_speeds = FC_PORTSPEED_UNKNOWN; 107c22fa50bSSatish Kharat break; 108c22fa50bSSatish Kharat } 109c22fa50bSSatish Kharat 1105df6d737SAbhijeet Joglekar if (old_link_status == fnic->link_status) { 111abb14148SHiral Shah if (!fnic->link_status) { 1125df6d737SAbhijeet Joglekar /* DOWN -> DOWN */ 1135df6d737SAbhijeet Joglekar spin_unlock_irqrestore(&fnic->fnic_lock, flags); 114abb14148SHiral Shah fnic_fc_trace_set_data(fnic->lport->host->host_no, 115abb14148SHiral Shah FNIC_FC_LE, "Link Status: DOWN->DOWN", 116abb14148SHiral Shah strlen("Link Status: DOWN->DOWN")); 117abb14148SHiral Shah } else { 1185df6d737SAbhijeet Joglekar if (old_link_down_cnt != fnic->link_down_cnt) { 1195df6d737SAbhijeet Joglekar /* UP -> DOWN -> UP */ 1205df6d737SAbhijeet Joglekar fnic->lport->host_stats.link_failure_count++; 1215df6d737SAbhijeet Joglekar spin_unlock_irqrestore(&fnic->fnic_lock, flags); 122abb14148SHiral Shah fnic_fc_trace_set_data( 123abb14148SHiral Shah fnic->lport->host->host_no, 124abb14148SHiral Shah FNIC_FC_LE, 125abb14148SHiral Shah "Link Status:UP_DOWN_UP", 126abb14148SHiral Shah strlen("Link_Status:UP_DOWN_UP") 127abb14148SHiral Shah ); 1285df6d737SAbhijeet Joglekar FNIC_FCS_DBG(KERN_DEBUG, fnic->lport->host, 1295df6d737SAbhijeet Joglekar "link down\n"); 13078112e55SJoe Eykholt fcoe_ctlr_link_down(&fnic->ctlr); 131d3c995f1SHiral Patel if (fnic->config.flags & VFCF_FIP_CAPABLE) { 132d3c995f1SHiral Patel /* start FCoE VLAN discovery */ 133abb14148SHiral Shah fnic_fc_trace_set_data( 134abb14148SHiral Shah fnic->lport->host->host_no, 135abb14148SHiral Shah FNIC_FC_LE, 136abb14148SHiral Shah "Link Status: UP_DOWN_UP_VLAN", 137abb14148SHiral Shah strlen( 138abb14148SHiral Shah "Link Status: UP_DOWN_UP_VLAN") 139abb14148SHiral Shah ); 140d3c995f1SHiral Patel fnic_fcoe_send_vlan_req(fnic); 141d3c995f1SHiral Patel return; 142d3c995f1SHiral Patel } 1435df6d737SAbhijeet Joglekar FNIC_FCS_DBG(KERN_DEBUG, fnic->lport->host, 1445df6d737SAbhijeet Joglekar "link up\n"); 14578112e55SJoe Eykholt fcoe_ctlr_link_up(&fnic->ctlr); 14686001f24SHiral Shah } else { 1475df6d737SAbhijeet Joglekar /* UP -> UP */ 1485df6d737SAbhijeet Joglekar spin_unlock_irqrestore(&fnic->fnic_lock, flags); 149abb14148SHiral Shah fnic_fc_trace_set_data( 150abb14148SHiral Shah fnic->lport->host->host_no, FNIC_FC_LE, 151abb14148SHiral Shah "Link Status: UP_UP", 152abb14148SHiral Shah strlen("Link Status: UP_UP")); 1535df6d737SAbhijeet Joglekar } 15486001f24SHiral Shah } 1555df6d737SAbhijeet Joglekar } else if (fnic->link_status) { 1565df6d737SAbhijeet Joglekar /* DOWN -> UP */ 1575df6d737SAbhijeet Joglekar spin_unlock_irqrestore(&fnic->fnic_lock, flags); 158d3c995f1SHiral Patel if (fnic->config.flags & VFCF_FIP_CAPABLE) { 159d3c995f1SHiral Patel /* start FCoE VLAN discovery */ 160abb14148SHiral Shah fnic_fc_trace_set_data( 161abb14148SHiral Shah fnic->lport->host->host_no, 162abb14148SHiral Shah FNIC_FC_LE, "Link Status: DOWN_UP_VLAN", 163abb14148SHiral Shah strlen("Link Status: DOWN_UP_VLAN")); 164d3c995f1SHiral Patel fnic_fcoe_send_vlan_req(fnic); 165d3c995f1SHiral Patel return; 166d3c995f1SHiral Patel } 1675df6d737SAbhijeet Joglekar FNIC_FCS_DBG(KERN_DEBUG, fnic->lport->host, "link up\n"); 168abb14148SHiral Shah fnic_fc_trace_set_data(fnic->lport->host->host_no, FNIC_FC_LE, 169abb14148SHiral Shah "Link Status: DOWN_UP", strlen("Link Status: DOWN_UP")); 17078112e55SJoe Eykholt fcoe_ctlr_link_up(&fnic->ctlr); 1715df6d737SAbhijeet Joglekar } else { 1725df6d737SAbhijeet Joglekar /* UP -> DOWN */ 1735df6d737SAbhijeet Joglekar fnic->lport->host_stats.link_failure_count++; 1745df6d737SAbhijeet Joglekar spin_unlock_irqrestore(&fnic->fnic_lock, flags); 1755df6d737SAbhijeet Joglekar FNIC_FCS_DBG(KERN_DEBUG, fnic->lport->host, "link down\n"); 176abb14148SHiral Shah fnic_fc_trace_set_data( 177abb14148SHiral Shah fnic->lport->host->host_no, FNIC_FC_LE, 178abb14148SHiral Shah "Link Status: UP_DOWN", 179abb14148SHiral Shah strlen("Link Status: UP_DOWN")); 1800ee7b871SHiral Shah if (fnic->config.flags & VFCF_FIP_CAPABLE) { 1810ee7b871SHiral Shah FNIC_FCS_DBG(KERN_DEBUG, fnic->lport->host, 1820ee7b871SHiral Shah "deleting fip-timer during link-down\n"); 1830ee7b871SHiral Shah del_timer_sync(&fnic->fip_timer); 1840ee7b871SHiral Shah } 18578112e55SJoe Eykholt fcoe_ctlr_link_down(&fnic->ctlr); 1865df6d737SAbhijeet Joglekar } 1875df6d737SAbhijeet Joglekar 1885df6d737SAbhijeet Joglekar } 1895df6d737SAbhijeet Joglekar 1905df6d737SAbhijeet Joglekar /* 1915df6d737SAbhijeet Joglekar * This function passes incoming fabric frames to libFC 1925df6d737SAbhijeet Joglekar */ 1935df6d737SAbhijeet Joglekar void fnic_handle_frame(struct work_struct *work) 1945df6d737SAbhijeet Joglekar { 1955df6d737SAbhijeet Joglekar struct fnic *fnic = container_of(work, struct fnic, frame_work); 1965df6d737SAbhijeet Joglekar struct fc_lport *lp = fnic->lport; 1975df6d737SAbhijeet Joglekar unsigned long flags; 1985df6d737SAbhijeet Joglekar struct sk_buff *skb; 1995df6d737SAbhijeet Joglekar struct fc_frame *fp; 2005df6d737SAbhijeet Joglekar 2015df6d737SAbhijeet Joglekar while ((skb = skb_dequeue(&fnic->frame_queue))) { 2025df6d737SAbhijeet Joglekar 2035df6d737SAbhijeet Joglekar spin_lock_irqsave(&fnic->fnic_lock, flags); 2045df6d737SAbhijeet Joglekar if (fnic->stop_rx_link_events) { 2055df6d737SAbhijeet Joglekar spin_unlock_irqrestore(&fnic->fnic_lock, flags); 2065df6d737SAbhijeet Joglekar dev_kfree_skb(skb); 2075df6d737SAbhijeet Joglekar return; 2085df6d737SAbhijeet Joglekar } 2095df6d737SAbhijeet Joglekar fp = (struct fc_frame *)skb; 21078112e55SJoe Eykholt 21178112e55SJoe Eykholt /* 21278112e55SJoe Eykholt * If we're in a transitional state, just re-queue and return. 21378112e55SJoe Eykholt * The queue will be serviced when we get to a stable state. 21478112e55SJoe Eykholt */ 21578112e55SJoe Eykholt if (fnic->state != FNIC_IN_FC_MODE && 21678112e55SJoe Eykholt fnic->state != FNIC_IN_ETH_MODE) { 21778112e55SJoe Eykholt skb_queue_head(&fnic->frame_queue, skb); 21878112e55SJoe Eykholt spin_unlock_irqrestore(&fnic->fnic_lock, flags); 21978112e55SJoe Eykholt return; 2205df6d737SAbhijeet Joglekar } 2215df6d737SAbhijeet Joglekar spin_unlock_irqrestore(&fnic->fnic_lock, flags); 2225df6d737SAbhijeet Joglekar 22352ff878cSVasu Dev fc_exch_recv(lp, fp); 2245df6d737SAbhijeet Joglekar } 2255df6d737SAbhijeet Joglekar } 2265df6d737SAbhijeet Joglekar 227d3c995f1SHiral Patel void fnic_fcoe_evlist_free(struct fnic *fnic) 228d3c995f1SHiral Patel { 229d3c995f1SHiral Patel struct fnic_event *fevt = NULL; 230d3c995f1SHiral Patel struct fnic_event *next = NULL; 231d3c995f1SHiral Patel unsigned long flags; 232d3c995f1SHiral Patel 233d3c995f1SHiral Patel spin_lock_irqsave(&fnic->fnic_lock, flags); 234d3c995f1SHiral Patel if (list_empty(&fnic->evlist)) { 235d3c995f1SHiral Patel spin_unlock_irqrestore(&fnic->fnic_lock, flags); 236d3c995f1SHiral Patel return; 237d3c995f1SHiral Patel } 238d3c995f1SHiral Patel 239d3c995f1SHiral Patel list_for_each_entry_safe(fevt, next, &fnic->evlist, list) { 240d3c995f1SHiral Patel list_del(&fevt->list); 241d3c995f1SHiral Patel kfree(fevt); 242d3c995f1SHiral Patel } 243d3c995f1SHiral Patel spin_unlock_irqrestore(&fnic->fnic_lock, flags); 244d3c995f1SHiral Patel } 245d3c995f1SHiral Patel 246d3c995f1SHiral Patel void fnic_handle_event(struct work_struct *work) 247d3c995f1SHiral Patel { 248d3c995f1SHiral Patel struct fnic *fnic = container_of(work, struct fnic, event_work); 249d3c995f1SHiral Patel struct fnic_event *fevt = NULL; 250d3c995f1SHiral Patel struct fnic_event *next = NULL; 251d3c995f1SHiral Patel unsigned long flags; 252d3c995f1SHiral Patel 253d3c995f1SHiral Patel spin_lock_irqsave(&fnic->fnic_lock, flags); 254d3c995f1SHiral Patel if (list_empty(&fnic->evlist)) { 255d3c995f1SHiral Patel spin_unlock_irqrestore(&fnic->fnic_lock, flags); 256d3c995f1SHiral Patel return; 257d3c995f1SHiral Patel } 258d3c995f1SHiral Patel 259d3c995f1SHiral Patel list_for_each_entry_safe(fevt, next, &fnic->evlist, list) { 260d3c995f1SHiral Patel if (fnic->stop_rx_link_events) { 261d3c995f1SHiral Patel list_del(&fevt->list); 262d3c995f1SHiral Patel kfree(fevt); 263d3c995f1SHiral Patel spin_unlock_irqrestore(&fnic->fnic_lock, flags); 264d3c995f1SHiral Patel return; 265d3c995f1SHiral Patel } 266d3c995f1SHiral Patel /* 267d3c995f1SHiral Patel * If we're in a transitional state, just re-queue and return. 268d3c995f1SHiral Patel * The queue will be serviced when we get to a stable state. 269d3c995f1SHiral Patel */ 270d3c995f1SHiral Patel if (fnic->state != FNIC_IN_FC_MODE && 271d3c995f1SHiral Patel fnic->state != FNIC_IN_ETH_MODE) { 272d3c995f1SHiral Patel spin_unlock_irqrestore(&fnic->fnic_lock, flags); 273d3c995f1SHiral Patel return; 274d3c995f1SHiral Patel } 275d3c995f1SHiral Patel 276d3c995f1SHiral Patel list_del(&fevt->list); 277d3c995f1SHiral Patel switch (fevt->event) { 278d3c995f1SHiral Patel case FNIC_EVT_START_VLAN_DISC: 279d3c995f1SHiral Patel spin_unlock_irqrestore(&fnic->fnic_lock, flags); 280d3c995f1SHiral Patel fnic_fcoe_send_vlan_req(fnic); 281d3c995f1SHiral Patel spin_lock_irqsave(&fnic->fnic_lock, flags); 282d3c995f1SHiral Patel break; 283d3c995f1SHiral Patel case FNIC_EVT_START_FCF_DISC: 284d3c995f1SHiral Patel FNIC_FCS_DBG(KERN_DEBUG, fnic->lport->host, 285d3c995f1SHiral Patel "Start FCF Discovery\n"); 286d3c995f1SHiral Patel fnic_fcoe_start_fcf_disc(fnic); 287d3c995f1SHiral Patel break; 288d3c995f1SHiral Patel default: 289d3c995f1SHiral Patel FNIC_FCS_DBG(KERN_DEBUG, fnic->lport->host, 290d3c995f1SHiral Patel "Unknown event 0x%x\n", fevt->event); 291d3c995f1SHiral Patel break; 292d3c995f1SHiral Patel } 293d3c995f1SHiral Patel kfree(fevt); 294d3c995f1SHiral Patel } 295d3c995f1SHiral Patel spin_unlock_irqrestore(&fnic->fnic_lock, flags); 296d3c995f1SHiral Patel } 297d3c995f1SHiral Patel 298d3c995f1SHiral Patel /** 299*2efd8631SLee Jones * is_fnic_fip_flogi_reject() - Check if the Received FIP FLOGI frame is rejected 300d3c995f1SHiral Patel * @fip: The FCoE controller that received the frame 301d3c995f1SHiral Patel * @skb: The received FIP frame 302d3c995f1SHiral Patel * 303d3c995f1SHiral Patel * Returns non-zero if the frame is rejected with unsupported cmd with 304d3c995f1SHiral Patel * insufficient resource els explanation. 305d3c995f1SHiral Patel */ 306d3c995f1SHiral Patel static inline int is_fnic_fip_flogi_reject(struct fcoe_ctlr *fip, 307d3c995f1SHiral Patel struct sk_buff *skb) 308d3c995f1SHiral Patel { 309d3c995f1SHiral Patel struct fc_lport *lport = fip->lp; 310d3c995f1SHiral Patel struct fip_header *fiph; 311d3c995f1SHiral Patel struct fc_frame_header *fh = NULL; 312d3c995f1SHiral Patel struct fip_desc *desc; 313d3c995f1SHiral Patel struct fip_encaps *els; 314d3c995f1SHiral Patel u16 op; 315d3c995f1SHiral Patel u8 els_op; 316d3c995f1SHiral Patel u8 sub; 317d3c995f1SHiral Patel 318d3c995f1SHiral Patel size_t rlen; 319d3c995f1SHiral Patel size_t dlen = 0; 320d3c995f1SHiral Patel 321d3c995f1SHiral Patel if (skb_linearize(skb)) 322d3c995f1SHiral Patel return 0; 323d3c995f1SHiral Patel 324d3c995f1SHiral Patel if (skb->len < sizeof(*fiph)) 325d3c995f1SHiral Patel return 0; 326d3c995f1SHiral Patel 327d3c995f1SHiral Patel fiph = (struct fip_header *)skb->data; 328d3c995f1SHiral Patel op = ntohs(fiph->fip_op); 329d3c995f1SHiral Patel sub = fiph->fip_subcode; 330d3c995f1SHiral Patel 331d3c995f1SHiral Patel if (op != FIP_OP_LS) 332d3c995f1SHiral Patel return 0; 333d3c995f1SHiral Patel 334d3c995f1SHiral Patel if (sub != FIP_SC_REP) 335d3c995f1SHiral Patel return 0; 336d3c995f1SHiral Patel 337d3c995f1SHiral Patel rlen = ntohs(fiph->fip_dl_len) * 4; 338d3c995f1SHiral Patel if (rlen + sizeof(*fiph) > skb->len) 339d3c995f1SHiral Patel return 0; 340d3c995f1SHiral Patel 341d3c995f1SHiral Patel desc = (struct fip_desc *)(fiph + 1); 342d3c995f1SHiral Patel dlen = desc->fip_dlen * FIP_BPW; 343d3c995f1SHiral Patel 344d3c995f1SHiral Patel if (desc->fip_dtype == FIP_DT_FLOGI) { 345d3c995f1SHiral Patel 346d3c995f1SHiral Patel if (dlen < sizeof(*els) + sizeof(*fh) + 1) 347d3c995f1SHiral Patel return 0; 348d3c995f1SHiral Patel 349d3c995f1SHiral Patel els = (struct fip_encaps *)desc; 350d3c995f1SHiral Patel fh = (struct fc_frame_header *)(els + 1); 351d3c995f1SHiral Patel 352d3c995f1SHiral Patel if (!fh) 353d3c995f1SHiral Patel return 0; 354d3c995f1SHiral Patel 355d3c995f1SHiral Patel /* 356d3c995f1SHiral Patel * ELS command code, reason and explanation should be = Reject, 357d3c995f1SHiral Patel * unsupported command and insufficient resource 358d3c995f1SHiral Patel */ 359d3c995f1SHiral Patel els_op = *(u8 *)(fh + 1); 360d3c995f1SHiral Patel if (els_op == ELS_LS_RJT) { 361d3c995f1SHiral Patel shost_printk(KERN_INFO, lport->host, 362d3c995f1SHiral Patel "Flogi Request Rejected by Switch\n"); 363d3c995f1SHiral Patel return 1; 364d3c995f1SHiral Patel } 365d3c995f1SHiral Patel shost_printk(KERN_INFO, lport->host, 366d3c995f1SHiral Patel "Flogi Request Accepted by Switch\n"); 367d3c995f1SHiral Patel } 368d3c995f1SHiral Patel return 0; 369d3c995f1SHiral Patel } 370d3c995f1SHiral Patel 371d3c995f1SHiral Patel static void fnic_fcoe_send_vlan_req(struct fnic *fnic) 372d3c995f1SHiral Patel { 373d3c995f1SHiral Patel struct fcoe_ctlr *fip = &fnic->ctlr; 37467125b02SHiral Patel struct fnic_stats *fnic_stats = &fnic->fnic_stats; 375d3c995f1SHiral Patel struct sk_buff *skb; 376d3c995f1SHiral Patel char *eth_fr; 377d3c995f1SHiral Patel struct fip_vlan *vlan; 378d3c995f1SHiral Patel u64 vlan_tov; 379d3c995f1SHiral Patel 380d3c995f1SHiral Patel fnic_fcoe_reset_vlans(fnic); 381d3c995f1SHiral Patel fnic->set_vlan(fnic, 0); 382b43abcbbSSatish Kharat 383b43abcbbSSatish Kharat if (printk_ratelimit()) 384d3c995f1SHiral Patel FNIC_FCS_DBG(KERN_INFO, fnic->lport->host, 385d3c995f1SHiral Patel "Sending VLAN request...\n"); 386b43abcbbSSatish Kharat 387d3c995f1SHiral Patel skb = dev_alloc_skb(sizeof(struct fip_vlan)); 388d3c995f1SHiral Patel if (!skb) 389d3c995f1SHiral Patel return; 390d3c995f1SHiral Patel 391d3c995f1SHiral Patel eth_fr = (char *)skb->data; 392d3c995f1SHiral Patel vlan = (struct fip_vlan *)eth_fr; 393d3c995f1SHiral Patel 394d3c995f1SHiral Patel memset(vlan, 0, sizeof(*vlan)); 395d3c995f1SHiral Patel memcpy(vlan->eth.h_source, fip->ctl_src_addr, ETH_ALEN); 396d3c995f1SHiral Patel memcpy(vlan->eth.h_dest, fcoe_all_fcfs, ETH_ALEN); 397d3c995f1SHiral Patel vlan->eth.h_proto = htons(ETH_P_FIP); 398d3c995f1SHiral Patel 399d3c995f1SHiral Patel vlan->fip.fip_ver = FIP_VER_ENCAPS(FIP_VER); 400d3c995f1SHiral Patel vlan->fip.fip_op = htons(FIP_OP_VLAN); 401b8e1aa3cSSatish Kharat vlan->fip.fip_subcode = FIP_SC_VL_REQ; 402d3c995f1SHiral Patel vlan->fip.fip_dl_len = htons(sizeof(vlan->desc) / FIP_BPW); 403d3c995f1SHiral Patel 404d3c995f1SHiral Patel vlan->desc.mac.fd_desc.fip_dtype = FIP_DT_MAC; 405d3c995f1SHiral Patel vlan->desc.mac.fd_desc.fip_dlen = sizeof(vlan->desc.mac) / FIP_BPW; 406d3c995f1SHiral Patel memcpy(&vlan->desc.mac.fd_mac, fip->ctl_src_addr, ETH_ALEN); 407d3c995f1SHiral Patel 408d3c995f1SHiral Patel vlan->desc.wwnn.fd_desc.fip_dtype = FIP_DT_NAME; 409d3c995f1SHiral Patel vlan->desc.wwnn.fd_desc.fip_dlen = sizeof(vlan->desc.wwnn) / FIP_BPW; 410d3c995f1SHiral Patel put_unaligned_be64(fip->lp->wwnn, &vlan->desc.wwnn.fd_wwn); 41167125b02SHiral Patel atomic64_inc(&fnic_stats->vlan_stats.vlan_disc_reqs); 412d3c995f1SHiral Patel 413d3c995f1SHiral Patel skb_put(skb, sizeof(*vlan)); 414d3c995f1SHiral Patel skb->protocol = htons(ETH_P_FIP); 415d3c995f1SHiral Patel skb_reset_mac_header(skb); 416d3c995f1SHiral Patel skb_reset_network_header(skb); 417d3c995f1SHiral Patel fip->send(fip, skb); 418d3c995f1SHiral Patel 419d3c995f1SHiral Patel /* set a timer so that we can retry if there no response */ 420d3c995f1SHiral Patel vlan_tov = jiffies + msecs_to_jiffies(FCOE_CTLR_FIPVLAN_TOV); 421d3c995f1SHiral Patel mod_timer(&fnic->fip_timer, round_jiffies(vlan_tov)); 422d3c995f1SHiral Patel } 423d3c995f1SHiral Patel 424d3c995f1SHiral Patel static void fnic_fcoe_process_vlan_resp(struct fnic *fnic, struct sk_buff *skb) 425d3c995f1SHiral Patel { 426d3c995f1SHiral Patel struct fcoe_ctlr *fip = &fnic->ctlr; 427d3c995f1SHiral Patel struct fip_header *fiph; 428d3c995f1SHiral Patel struct fip_desc *desc; 42967125b02SHiral Patel struct fnic_stats *fnic_stats = &fnic->fnic_stats; 430d3c995f1SHiral Patel u16 vid; 431d3c995f1SHiral Patel size_t rlen; 432d3c995f1SHiral Patel size_t dlen; 433d3c995f1SHiral Patel struct fcoe_vlan *vlan; 434d3c995f1SHiral Patel u64 sol_time; 435d3c995f1SHiral Patel unsigned long flags; 436d3c995f1SHiral Patel 437d3c995f1SHiral Patel FNIC_FCS_DBG(KERN_INFO, fnic->lport->host, 438d3c995f1SHiral Patel "Received VLAN response...\n"); 439d3c995f1SHiral Patel 440d3c995f1SHiral Patel fiph = (struct fip_header *) skb->data; 441d3c995f1SHiral Patel 442d3c995f1SHiral Patel FNIC_FCS_DBG(KERN_INFO, fnic->lport->host, 443d3c995f1SHiral Patel "Received VLAN response... OP 0x%x SUB_OP 0x%x\n", 444d3c995f1SHiral Patel ntohs(fiph->fip_op), fiph->fip_subcode); 445d3c995f1SHiral Patel 446d3c995f1SHiral Patel rlen = ntohs(fiph->fip_dl_len) * 4; 447d3c995f1SHiral Patel fnic_fcoe_reset_vlans(fnic); 448d3c995f1SHiral Patel spin_lock_irqsave(&fnic->vlans_lock, flags); 449d3c995f1SHiral Patel desc = (struct fip_desc *)(fiph + 1); 450d3c995f1SHiral Patel while (rlen > 0) { 451d3c995f1SHiral Patel dlen = desc->fip_dlen * FIP_BPW; 452d3c995f1SHiral Patel switch (desc->fip_dtype) { 453d3c995f1SHiral Patel case FIP_DT_VLAN: 454d3c995f1SHiral Patel vid = ntohs(((struct fip_vlan_desc *)desc)->fd_vlan); 455d3c995f1SHiral Patel shost_printk(KERN_INFO, fnic->lport->host, 456d3c995f1SHiral Patel "process_vlan_resp: FIP VLAN %d\n", vid); 457dbc1ebe7SRasmus Villemoes vlan = kzalloc(sizeof(*vlan), GFP_ATOMIC); 458d3c995f1SHiral Patel if (!vlan) { 459d3c995f1SHiral Patel /* retry from timer */ 460d3c995f1SHiral Patel spin_unlock_irqrestore(&fnic->vlans_lock, 461d3c995f1SHiral Patel flags); 462d3c995f1SHiral Patel goto out; 463d3c995f1SHiral Patel } 464d3c995f1SHiral Patel vlan->vid = vid & 0x0fff; 465d3c995f1SHiral Patel vlan->state = FIP_VLAN_AVAIL; 466d3c995f1SHiral Patel list_add_tail(&vlan->list, &fnic->vlans); 467d3c995f1SHiral Patel break; 468d3c995f1SHiral Patel } 469d3c995f1SHiral Patel desc = (struct fip_desc *)((char *)desc + dlen); 470d3c995f1SHiral Patel rlen -= dlen; 471d3c995f1SHiral Patel } 472d3c995f1SHiral Patel 473d3c995f1SHiral Patel /* any VLAN descriptors present ? */ 474d3c995f1SHiral Patel if (list_empty(&fnic->vlans)) { 475d3c995f1SHiral Patel /* retry from timer */ 47667125b02SHiral Patel atomic64_inc(&fnic_stats->vlan_stats.resp_withno_vlanID); 477d3c995f1SHiral Patel FNIC_FCS_DBG(KERN_INFO, fnic->lport->host, 478d3c995f1SHiral Patel "No VLAN descriptors in FIP VLAN response\n"); 479d3c995f1SHiral Patel spin_unlock_irqrestore(&fnic->vlans_lock, flags); 480d3c995f1SHiral Patel goto out; 481d3c995f1SHiral Patel } 482d3c995f1SHiral Patel 483d3c995f1SHiral Patel vlan = list_first_entry(&fnic->vlans, struct fcoe_vlan, list); 484d3c995f1SHiral Patel fnic->set_vlan(fnic, vlan->vid); 485d3c995f1SHiral Patel vlan->state = FIP_VLAN_SENT; /* sent now */ 486d3c995f1SHiral Patel vlan->sol_count++; 487d3c995f1SHiral Patel spin_unlock_irqrestore(&fnic->vlans_lock, flags); 488d3c995f1SHiral Patel 489d3c995f1SHiral Patel /* start the solicitation */ 490d3c995f1SHiral Patel fcoe_ctlr_link_up(fip); 491d3c995f1SHiral Patel 492d3c995f1SHiral Patel sol_time = jiffies + msecs_to_jiffies(FCOE_CTLR_START_DELAY); 493d3c995f1SHiral Patel mod_timer(&fnic->fip_timer, round_jiffies(sol_time)); 494d3c995f1SHiral Patel out: 495d3c995f1SHiral Patel return; 496d3c995f1SHiral Patel } 497d3c995f1SHiral Patel 498d3c995f1SHiral Patel static void fnic_fcoe_start_fcf_disc(struct fnic *fnic) 499d3c995f1SHiral Patel { 500d3c995f1SHiral Patel unsigned long flags; 501d3c995f1SHiral Patel struct fcoe_vlan *vlan; 502d3c995f1SHiral Patel u64 sol_time; 503d3c995f1SHiral Patel 504d3c995f1SHiral Patel spin_lock_irqsave(&fnic->vlans_lock, flags); 505d3c995f1SHiral Patel vlan = list_first_entry(&fnic->vlans, struct fcoe_vlan, list); 506d3c995f1SHiral Patel fnic->set_vlan(fnic, vlan->vid); 507d3c995f1SHiral Patel vlan->state = FIP_VLAN_SENT; /* sent now */ 508d3c995f1SHiral Patel vlan->sol_count = 1; 509d3c995f1SHiral Patel spin_unlock_irqrestore(&fnic->vlans_lock, flags); 510d3c995f1SHiral Patel 511d3c995f1SHiral Patel /* start the solicitation */ 512d3c995f1SHiral Patel fcoe_ctlr_link_up(&fnic->ctlr); 513d3c995f1SHiral Patel 514d3c995f1SHiral Patel sol_time = jiffies + msecs_to_jiffies(FCOE_CTLR_START_DELAY); 515d3c995f1SHiral Patel mod_timer(&fnic->fip_timer, round_jiffies(sol_time)); 516d3c995f1SHiral Patel } 517d3c995f1SHiral Patel 518d3c995f1SHiral Patel static int fnic_fcoe_vlan_check(struct fnic *fnic, u16 flag) 519d3c995f1SHiral Patel { 520d3c995f1SHiral Patel unsigned long flags; 521d3c995f1SHiral Patel struct fcoe_vlan *fvlan; 522d3c995f1SHiral Patel 523d3c995f1SHiral Patel spin_lock_irqsave(&fnic->vlans_lock, flags); 524d3c995f1SHiral Patel if (list_empty(&fnic->vlans)) { 525d3c995f1SHiral Patel spin_unlock_irqrestore(&fnic->vlans_lock, flags); 526d3c995f1SHiral Patel return -EINVAL; 527d3c995f1SHiral Patel } 528d3c995f1SHiral Patel 529d3c995f1SHiral Patel fvlan = list_first_entry(&fnic->vlans, struct fcoe_vlan, list); 530d3c995f1SHiral Patel if (fvlan->state == FIP_VLAN_USED) { 531d3c995f1SHiral Patel spin_unlock_irqrestore(&fnic->vlans_lock, flags); 532d3c995f1SHiral Patel return 0; 533d3c995f1SHiral Patel } 534d3c995f1SHiral Patel 535d3c995f1SHiral Patel if (fvlan->state == FIP_VLAN_SENT) { 536d3c995f1SHiral Patel fvlan->state = FIP_VLAN_USED; 537d3c995f1SHiral Patel spin_unlock_irqrestore(&fnic->vlans_lock, flags); 538d3c995f1SHiral Patel return 0; 539d3c995f1SHiral Patel } 540d3c995f1SHiral Patel spin_unlock_irqrestore(&fnic->vlans_lock, flags); 541d3c995f1SHiral Patel return -EINVAL; 542d3c995f1SHiral Patel } 543d3c995f1SHiral Patel 544d3c995f1SHiral Patel static void fnic_event_enq(struct fnic *fnic, enum fnic_evt ev) 545d3c995f1SHiral Patel { 546d3c995f1SHiral Patel struct fnic_event *fevt; 547d3c995f1SHiral Patel unsigned long flags; 548d3c995f1SHiral Patel 549d3c995f1SHiral Patel fevt = kmalloc(sizeof(*fevt), GFP_ATOMIC); 550d3c995f1SHiral Patel if (!fevt) 551d3c995f1SHiral Patel return; 552d3c995f1SHiral Patel 553d3c995f1SHiral Patel fevt->fnic = fnic; 554d3c995f1SHiral Patel fevt->event = ev; 555d3c995f1SHiral Patel 556d3c995f1SHiral Patel spin_lock_irqsave(&fnic->fnic_lock, flags); 557d3c995f1SHiral Patel list_add_tail(&fevt->list, &fnic->evlist); 558d3c995f1SHiral Patel spin_unlock_irqrestore(&fnic->fnic_lock, flags); 559d3c995f1SHiral Patel 560d3c995f1SHiral Patel schedule_work(&fnic->event_work); 561d3c995f1SHiral Patel } 562d3c995f1SHiral Patel 563d3c995f1SHiral Patel static int fnic_fcoe_handle_fip_frame(struct fnic *fnic, struct sk_buff *skb) 564d3c995f1SHiral Patel { 565d3c995f1SHiral Patel struct fip_header *fiph; 566d3c995f1SHiral Patel int ret = 1; 567d3c995f1SHiral Patel u16 op; 568d3c995f1SHiral Patel u8 sub; 569d3c995f1SHiral Patel 570d3c995f1SHiral Patel if (!skb || !(skb->data)) 571d3c995f1SHiral Patel return -1; 572d3c995f1SHiral Patel 573d3c995f1SHiral Patel if (skb_linearize(skb)) 574d3c995f1SHiral Patel goto drop; 575d3c995f1SHiral Patel 576d3c995f1SHiral Patel fiph = (struct fip_header *)skb->data; 577d3c995f1SHiral Patel op = ntohs(fiph->fip_op); 578d3c995f1SHiral Patel sub = fiph->fip_subcode; 579d3c995f1SHiral Patel 580d3c995f1SHiral Patel if (FIP_VER_DECAPS(fiph->fip_ver) != FIP_VER) 581d3c995f1SHiral Patel goto drop; 582d3c995f1SHiral Patel 583d3c995f1SHiral Patel if (ntohs(fiph->fip_dl_len) * FIP_BPW + sizeof(*fiph) > skb->len) 584d3c995f1SHiral Patel goto drop; 585d3c995f1SHiral Patel 586d3c995f1SHiral Patel if (op == FIP_OP_DISC && sub == FIP_SC_ADV) { 587d3c995f1SHiral Patel if (fnic_fcoe_vlan_check(fnic, ntohs(fiph->fip_flags))) 588d3c995f1SHiral Patel goto drop; 589d3c995f1SHiral Patel /* pass it on to fcoe */ 590d3c995f1SHiral Patel ret = 1; 5916a551c11SHannes Reinecke } else if (op == FIP_OP_VLAN && sub == FIP_SC_VL_NOTE) { 592d3c995f1SHiral Patel /* set the vlan as used */ 593d3c995f1SHiral Patel fnic_fcoe_process_vlan_resp(fnic, skb); 594d3c995f1SHiral Patel ret = 0; 595d3c995f1SHiral Patel } else if (op == FIP_OP_CTRL && sub == FIP_SC_CLR_VLINK) { 596d3c995f1SHiral Patel /* received CVL request, restart vlan disc */ 597d3c995f1SHiral Patel fnic_event_enq(fnic, FNIC_EVT_START_VLAN_DISC); 598d3c995f1SHiral Patel /* pass it on to fcoe */ 599d3c995f1SHiral Patel ret = 1; 600d3c995f1SHiral Patel } 601d3c995f1SHiral Patel drop: 602d3c995f1SHiral Patel return ret; 603d3c995f1SHiral Patel } 604d3c995f1SHiral Patel 605d3c995f1SHiral Patel void fnic_handle_fip_frame(struct work_struct *work) 606d3c995f1SHiral Patel { 607d3c995f1SHiral Patel struct fnic *fnic = container_of(work, struct fnic, fip_frame_work); 60867125b02SHiral Patel struct fnic_stats *fnic_stats = &fnic->fnic_stats; 609d3c995f1SHiral Patel unsigned long flags; 610d3c995f1SHiral Patel struct sk_buff *skb; 611d3c995f1SHiral Patel struct ethhdr *eh; 612d3c995f1SHiral Patel 613d3c995f1SHiral Patel while ((skb = skb_dequeue(&fnic->fip_frame_queue))) { 614d3c995f1SHiral Patel spin_lock_irqsave(&fnic->fnic_lock, flags); 615d3c995f1SHiral Patel if (fnic->stop_rx_link_events) { 616d3c995f1SHiral Patel spin_unlock_irqrestore(&fnic->fnic_lock, flags); 617d3c995f1SHiral Patel dev_kfree_skb(skb); 618d3c995f1SHiral Patel return; 619d3c995f1SHiral Patel } 620d3c995f1SHiral Patel /* 621d3c995f1SHiral Patel * If we're in a transitional state, just re-queue and return. 622d3c995f1SHiral Patel * The queue will be serviced when we get to a stable state. 623d3c995f1SHiral Patel */ 624d3c995f1SHiral Patel if (fnic->state != FNIC_IN_FC_MODE && 625d3c995f1SHiral Patel fnic->state != FNIC_IN_ETH_MODE) { 626d3c995f1SHiral Patel skb_queue_head(&fnic->fip_frame_queue, skb); 627d3c995f1SHiral Patel spin_unlock_irqrestore(&fnic->fnic_lock, flags); 628d3c995f1SHiral Patel return; 629d3c995f1SHiral Patel } 630d3c995f1SHiral Patel spin_unlock_irqrestore(&fnic->fnic_lock, flags); 631d3c995f1SHiral Patel eh = (struct ethhdr *)skb->data; 632d3c995f1SHiral Patel if (eh->h_proto == htons(ETH_P_FIP)) { 633d3c995f1SHiral Patel skb_pull(skb, sizeof(*eh)); 634d3c995f1SHiral Patel if (fnic_fcoe_handle_fip_frame(fnic, skb) <= 0) { 635d3c995f1SHiral Patel dev_kfree_skb(skb); 636d3c995f1SHiral Patel continue; 637d3c995f1SHiral Patel } 638d3c995f1SHiral Patel /* 639d3c995f1SHiral Patel * If there's FLOGI rejects - clear all 640d3c995f1SHiral Patel * fcf's & restart from scratch 641d3c995f1SHiral Patel */ 642d3c995f1SHiral Patel if (is_fnic_fip_flogi_reject(&fnic->ctlr, skb)) { 64367125b02SHiral Patel atomic64_inc( 64467125b02SHiral Patel &fnic_stats->vlan_stats.flogi_rejects); 645d3c995f1SHiral Patel shost_printk(KERN_INFO, fnic->lport->host, 646d3c995f1SHiral Patel "Trigger a Link down - VLAN Disc\n"); 647d3c995f1SHiral Patel fcoe_ctlr_link_down(&fnic->ctlr); 648d3c995f1SHiral Patel /* start FCoE VLAN discovery */ 649d3c995f1SHiral Patel fnic_fcoe_send_vlan_req(fnic); 650d3c995f1SHiral Patel dev_kfree_skb(skb); 651d3c995f1SHiral Patel continue; 652d3c995f1SHiral Patel } 653d3c995f1SHiral Patel fcoe_ctlr_recv(&fnic->ctlr, skb); 654d3c995f1SHiral Patel continue; 655d3c995f1SHiral Patel } 656d3c995f1SHiral Patel } 657d3c995f1SHiral Patel } 658d3c995f1SHiral Patel 65978112e55SJoe Eykholt /** 66078112e55SJoe Eykholt * fnic_import_rq_eth_pkt() - handle received FCoE or FIP frame. 66178112e55SJoe Eykholt * @fnic: fnic instance. 66278112e55SJoe Eykholt * @skb: Ethernet Frame. 66378112e55SJoe Eykholt */ 66478112e55SJoe Eykholt static inline int fnic_import_rq_eth_pkt(struct fnic *fnic, struct sk_buff *skb) 6655df6d737SAbhijeet Joglekar { 6665df6d737SAbhijeet Joglekar struct fc_frame *fp; 6675df6d737SAbhijeet Joglekar struct ethhdr *eh; 6685df6d737SAbhijeet Joglekar struct fcoe_hdr *fcoe_hdr; 6695df6d737SAbhijeet Joglekar struct fcoe_crc_eof *ft; 6705df6d737SAbhijeet Joglekar 67178112e55SJoe Eykholt /* 67278112e55SJoe Eykholt * Undo VLAN encapsulation if present. 67378112e55SJoe Eykholt */ 6745df6d737SAbhijeet Joglekar eh = (struct ethhdr *)skb->data; 67578112e55SJoe Eykholt if (eh->h_proto == htons(ETH_P_8021Q)) { 67678112e55SJoe Eykholt memmove((u8 *)eh + VLAN_HLEN, eh, ETH_ALEN * 2); 677af72868bSJohannes Berg eh = skb_pull(skb, VLAN_HLEN); 67878112e55SJoe Eykholt skb_reset_mac_header(skb); 67978112e55SJoe Eykholt } 68078112e55SJoe Eykholt if (eh->h_proto == htons(ETH_P_FIP)) { 681d7fadce3SHiral Patel if (!(fnic->config.flags & VFCF_FIP_CAPABLE)) { 682d7fadce3SHiral Patel printk(KERN_ERR "Dropped FIP frame, as firmware " 683d7fadce3SHiral Patel "uses non-FIP mode, Enable FIP " 684d7fadce3SHiral Patel "using UCSM\n"); 685d7fadce3SHiral Patel goto drop; 686d7fadce3SHiral Patel } 687abb14148SHiral Shah if ((fnic_fc_trace_set_data(fnic->lport->host->host_no, 688abb14148SHiral Shah FNIC_FC_RECV|0x80, (char *)skb->data, skb->len)) != 0) { 689abb14148SHiral Shah printk(KERN_ERR "fnic ctlr frame trace error!!!"); 690abb14148SHiral Shah } 691d3c995f1SHiral Patel skb_queue_tail(&fnic->fip_frame_queue, skb); 692d3c995f1SHiral Patel queue_work(fnic_fip_queue, &fnic->fip_frame_work); 69378112e55SJoe Eykholt return 1; /* let caller know packet was used */ 69478112e55SJoe Eykholt } 69578112e55SJoe Eykholt if (eh->h_proto != htons(ETH_P_FCOE)) 69678112e55SJoe Eykholt goto drop; 69778112e55SJoe Eykholt skb_set_network_header(skb, sizeof(*eh)); 69878112e55SJoe Eykholt skb_pull(skb, sizeof(*eh)); 6995df6d737SAbhijeet Joglekar 7005df6d737SAbhijeet Joglekar fcoe_hdr = (struct fcoe_hdr *)skb->data; 7015df6d737SAbhijeet Joglekar if (FC_FCOE_DECAPS_VER(fcoe_hdr) != FC_FCOE_VER) 70278112e55SJoe Eykholt goto drop; 7035df6d737SAbhijeet Joglekar 7045df6d737SAbhijeet Joglekar fp = (struct fc_frame *)skb; 7055df6d737SAbhijeet Joglekar fc_frame_init(fp); 7065df6d737SAbhijeet Joglekar fr_sof(fp) = fcoe_hdr->fcoe_sof; 7075df6d737SAbhijeet Joglekar skb_pull(skb, sizeof(struct fcoe_hdr)); 70878112e55SJoe Eykholt skb_reset_transport_header(skb); 7095df6d737SAbhijeet Joglekar 71078112e55SJoe Eykholt ft = (struct fcoe_crc_eof *)(skb->data + skb->len - sizeof(*ft)); 7115df6d737SAbhijeet Joglekar fr_eof(fp) = ft->fcoe_eof; 71278112e55SJoe Eykholt skb_trim(skb, skb->len - sizeof(*ft)); 7135df6d737SAbhijeet Joglekar return 0; 71478112e55SJoe Eykholt drop: 71578112e55SJoe Eykholt dev_kfree_skb_irq(skb); 71678112e55SJoe Eykholt return -1; 7175df6d737SAbhijeet Joglekar } 7185df6d737SAbhijeet Joglekar 71978112e55SJoe Eykholt /** 72078112e55SJoe Eykholt * fnic_update_mac_locked() - set data MAC address and filters. 72178112e55SJoe Eykholt * @fnic: fnic instance. 72278112e55SJoe Eykholt * @new: newly-assigned FCoE MAC address. 72378112e55SJoe Eykholt * 72478112e55SJoe Eykholt * Called with the fnic lock held. 72578112e55SJoe Eykholt */ 72678112e55SJoe Eykholt void fnic_update_mac_locked(struct fnic *fnic, u8 *new) 7275df6d737SAbhijeet Joglekar { 72878112e55SJoe Eykholt u8 *ctl = fnic->ctlr.ctl_src_addr; 72978112e55SJoe Eykholt u8 *data = fnic->data_src_addr; 7305df6d737SAbhijeet Joglekar 73178112e55SJoe Eykholt if (is_zero_ether_addr(new)) 73278112e55SJoe Eykholt new = ctl; 7336942df7fSJoe Perches if (ether_addr_equal(data, new)) 73478112e55SJoe Eykholt return; 73578112e55SJoe Eykholt FNIC_FCS_DBG(KERN_DEBUG, fnic->lport->host, "update_mac %pM\n", new); 7366942df7fSJoe Perches if (!is_zero_ether_addr(data) && !ether_addr_equal(data, ctl)) 73778112e55SJoe Eykholt vnic_dev_del_addr(fnic->vdev, data); 73878112e55SJoe Eykholt memcpy(data, new, ETH_ALEN); 7396942df7fSJoe Perches if (!ether_addr_equal(new, ctl)) 74078112e55SJoe Eykholt vnic_dev_add_addr(fnic->vdev, new); 7415df6d737SAbhijeet Joglekar } 7425df6d737SAbhijeet Joglekar 74378112e55SJoe Eykholt /** 74478112e55SJoe Eykholt * fnic_update_mac() - set data MAC address and filters. 74578112e55SJoe Eykholt * @lport: local port. 74678112e55SJoe Eykholt * @new: newly-assigned FCoE MAC address. 7475df6d737SAbhijeet Joglekar */ 74878112e55SJoe Eykholt void fnic_update_mac(struct fc_lport *lport, u8 *new) 74978112e55SJoe Eykholt { 75078112e55SJoe Eykholt struct fnic *fnic = lport_priv(lport); 7515df6d737SAbhijeet Joglekar 75278112e55SJoe Eykholt spin_lock_irq(&fnic->fnic_lock); 75378112e55SJoe Eykholt fnic_update_mac_locked(fnic, new); 75478112e55SJoe Eykholt spin_unlock_irq(&fnic->fnic_lock); 7555df6d737SAbhijeet Joglekar } 7565df6d737SAbhijeet Joglekar 75778112e55SJoe Eykholt /** 75878112e55SJoe Eykholt * fnic_set_port_id() - set the port_ID after successful FLOGI. 75978112e55SJoe Eykholt * @lport: local port. 76078112e55SJoe Eykholt * @port_id: assigned FC_ID. 76178112e55SJoe Eykholt * @fp: received frame containing the FLOGI accept or NULL. 76278112e55SJoe Eykholt * 76378112e55SJoe Eykholt * This is called from libfc when a new FC_ID has been assigned. 76478112e55SJoe Eykholt * This causes us to reset the firmware to FC_MODE and setup the new MAC 76578112e55SJoe Eykholt * address and FC_ID. 76678112e55SJoe Eykholt * 76778112e55SJoe Eykholt * It is also called with FC_ID 0 when we're logged off. 76878112e55SJoe Eykholt * 76978112e55SJoe Eykholt * If the FC_ID is due to point-to-point, fp may be NULL. 7705df6d737SAbhijeet Joglekar */ 77178112e55SJoe Eykholt void fnic_set_port_id(struct fc_lport *lport, u32 port_id, struct fc_frame *fp) 77278112e55SJoe Eykholt { 77378112e55SJoe Eykholt struct fnic *fnic = lport_priv(lport); 77478112e55SJoe Eykholt u8 *mac; 77578112e55SJoe Eykholt int ret; 7765df6d737SAbhijeet Joglekar 77778112e55SJoe Eykholt FNIC_FCS_DBG(KERN_DEBUG, lport->host, "set port_id %x fp %p\n", 77878112e55SJoe Eykholt port_id, fp); 7795df6d737SAbhijeet Joglekar 78078112e55SJoe Eykholt /* 78178112e55SJoe Eykholt * If we're clearing the FC_ID, change to use the ctl_src_addr. 78278112e55SJoe Eykholt * Set ethernet mode to send FLOGI. 78378112e55SJoe Eykholt */ 78478112e55SJoe Eykholt if (!port_id) { 78578112e55SJoe Eykholt fnic_update_mac(lport, fnic->ctlr.ctl_src_addr); 78678112e55SJoe Eykholt fnic_set_eth_mode(fnic); 78778112e55SJoe Eykholt return; 78878112e55SJoe Eykholt } 78978112e55SJoe Eykholt 79078112e55SJoe Eykholt if (fp) { 79178112e55SJoe Eykholt mac = fr_cb(fp)->granted_mac; 79278112e55SJoe Eykholt if (is_zero_ether_addr(mac)) { 79378112e55SJoe Eykholt /* non-FIP - FLOGI already accepted - ignore return */ 79478112e55SJoe Eykholt fcoe_ctlr_recv_flogi(&fnic->ctlr, lport, fp); 79578112e55SJoe Eykholt } 79678112e55SJoe Eykholt fnic_update_mac(lport, mac); 79778112e55SJoe Eykholt } 79878112e55SJoe Eykholt 79978112e55SJoe Eykholt /* Change state to reflect transition to FC mode */ 80078112e55SJoe Eykholt spin_lock_irq(&fnic->fnic_lock); 80178112e55SJoe Eykholt if (fnic->state == FNIC_IN_ETH_MODE || fnic->state == FNIC_IN_FC_MODE) 8025df6d737SAbhijeet Joglekar fnic->state = FNIC_IN_ETH_TRANS_FC_MODE; 80378112e55SJoe Eykholt else { 8045df6d737SAbhijeet Joglekar FNIC_FCS_DBG(KERN_DEBUG, fnic->lport->host, 8055df6d737SAbhijeet Joglekar "Unexpected fnic state %s while" 8065df6d737SAbhijeet Joglekar " processing flogi resp\n", 8075df6d737SAbhijeet Joglekar fnic_state_to_str(fnic->state)); 80878112e55SJoe Eykholt spin_unlock_irq(&fnic->fnic_lock); 80978112e55SJoe Eykholt return; 8105df6d737SAbhijeet Joglekar } 81178112e55SJoe Eykholt spin_unlock_irq(&fnic->fnic_lock); 8125df6d737SAbhijeet Joglekar 8135df6d737SAbhijeet Joglekar /* 81478112e55SJoe Eykholt * Send FLOGI registration to firmware to set up FC mode. 81578112e55SJoe Eykholt * The new address will be set up when registration completes. 8165df6d737SAbhijeet Joglekar */ 81778112e55SJoe Eykholt ret = fnic_flogi_reg_handler(fnic, port_id); 8185df6d737SAbhijeet Joglekar 8195df6d737SAbhijeet Joglekar if (ret < 0) { 82078112e55SJoe Eykholt spin_lock_irq(&fnic->fnic_lock); 8215df6d737SAbhijeet Joglekar if (fnic->state == FNIC_IN_ETH_TRANS_FC_MODE) 8225df6d737SAbhijeet Joglekar fnic->state = FNIC_IN_ETH_MODE; 82378112e55SJoe Eykholt spin_unlock_irq(&fnic->fnic_lock); 8245df6d737SAbhijeet Joglekar } 8255df6d737SAbhijeet Joglekar } 8265df6d737SAbhijeet Joglekar 8275df6d737SAbhijeet Joglekar static void fnic_rq_cmpl_frame_recv(struct vnic_rq *rq, struct cq_desc 8285df6d737SAbhijeet Joglekar *cq_desc, struct vnic_rq_buf *buf, 8295df6d737SAbhijeet Joglekar int skipped __attribute__((unused)), 8305df6d737SAbhijeet Joglekar void *opaque) 8315df6d737SAbhijeet Joglekar { 8325df6d737SAbhijeet Joglekar struct fnic *fnic = vnic_dev_priv(rq->vdev); 8335df6d737SAbhijeet Joglekar struct sk_buff *skb; 8345df6d737SAbhijeet Joglekar struct fc_frame *fp; 83567125b02SHiral Patel struct fnic_stats *fnic_stats = &fnic->fnic_stats; 8365df6d737SAbhijeet Joglekar u8 type, color, eop, sop, ingress_port, vlan_stripped; 8375df6d737SAbhijeet Joglekar u8 fcoe = 0, fcoe_sof, fcoe_eof; 8385df6d737SAbhijeet Joglekar u8 fcoe_fc_crc_ok = 1, fcoe_enc_error = 0; 8395df6d737SAbhijeet Joglekar u8 tcp_udp_csum_ok, udp, tcp, ipv4_csum_ok; 8405df6d737SAbhijeet Joglekar u8 ipv6, ipv4, ipv4_fragment, rss_type, csum_not_calc; 8415df6d737SAbhijeet Joglekar u8 fcs_ok = 1, packet_error = 0; 8425df6d737SAbhijeet Joglekar u16 q_number, completed_index, bytes_written = 0, vlan, checksum; 8435df6d737SAbhijeet Joglekar u32 rss_hash; 8445df6d737SAbhijeet Joglekar u16 exchange_id, tmpl; 8455df6d737SAbhijeet Joglekar u8 sof = 0; 8465df6d737SAbhijeet Joglekar u8 eof = 0; 8475df6d737SAbhijeet Joglekar u32 fcp_bytes_written = 0; 8485df6d737SAbhijeet Joglekar unsigned long flags; 8495df6d737SAbhijeet Joglekar 8507f9b0f77SChristoph Hellwig dma_unmap_single(&fnic->pdev->dev, buf->dma_addr, buf->len, 8517f9b0f77SChristoph Hellwig DMA_FROM_DEVICE); 8525df6d737SAbhijeet Joglekar skb = buf->os_buf; 85378112e55SJoe Eykholt fp = (struct fc_frame *)skb; 8545df6d737SAbhijeet Joglekar buf->os_buf = NULL; 8555df6d737SAbhijeet Joglekar 8565df6d737SAbhijeet Joglekar cq_desc_dec(cq_desc, &type, &color, &q_number, &completed_index); 8575df6d737SAbhijeet Joglekar if (type == CQ_DESC_TYPE_RQ_FCP) { 8585df6d737SAbhijeet Joglekar cq_fcp_rq_desc_dec((struct cq_fcp_rq_desc *)cq_desc, 8595df6d737SAbhijeet Joglekar &type, &color, &q_number, &completed_index, 8605df6d737SAbhijeet Joglekar &eop, &sop, &fcoe_fc_crc_ok, &exchange_id, 8615df6d737SAbhijeet Joglekar &tmpl, &fcp_bytes_written, &sof, &eof, 8625df6d737SAbhijeet Joglekar &ingress_port, &packet_error, 8635df6d737SAbhijeet Joglekar &fcoe_enc_error, &fcs_ok, &vlan_stripped, 8645df6d737SAbhijeet Joglekar &vlan); 86578112e55SJoe Eykholt skb_trim(skb, fcp_bytes_written); 86678112e55SJoe Eykholt fr_sof(fp) = sof; 86778112e55SJoe Eykholt fr_eof(fp) = eof; 8685df6d737SAbhijeet Joglekar 8695df6d737SAbhijeet Joglekar } else if (type == CQ_DESC_TYPE_RQ_ENET) { 8705df6d737SAbhijeet Joglekar cq_enet_rq_desc_dec((struct cq_enet_rq_desc *)cq_desc, 8715df6d737SAbhijeet Joglekar &type, &color, &q_number, &completed_index, 8725df6d737SAbhijeet Joglekar &ingress_port, &fcoe, &eop, &sop, 8735df6d737SAbhijeet Joglekar &rss_type, &csum_not_calc, &rss_hash, 8745df6d737SAbhijeet Joglekar &bytes_written, &packet_error, 8755df6d737SAbhijeet Joglekar &vlan_stripped, &vlan, &checksum, 8765df6d737SAbhijeet Joglekar &fcoe_sof, &fcoe_fc_crc_ok, 8775df6d737SAbhijeet Joglekar &fcoe_enc_error, &fcoe_eof, 8785df6d737SAbhijeet Joglekar &tcp_udp_csum_ok, &udp, &tcp, 8795df6d737SAbhijeet Joglekar &ipv4_csum_ok, &ipv6, &ipv4, 8805df6d737SAbhijeet Joglekar &ipv4_fragment, &fcs_ok); 88178112e55SJoe Eykholt skb_trim(skb, bytes_written); 88278112e55SJoe Eykholt if (!fcs_ok) { 88367125b02SHiral Patel atomic64_inc(&fnic_stats->misc_stats.frame_errors); 88478112e55SJoe Eykholt FNIC_FCS_DBG(KERN_DEBUG, fnic->lport->host, 88578112e55SJoe Eykholt "fcs error. dropping packet.\n"); 88678112e55SJoe Eykholt goto drop; 88778112e55SJoe Eykholt } 88878112e55SJoe Eykholt if (fnic_import_rq_eth_pkt(fnic, skb)) 88978112e55SJoe Eykholt return; 8905df6d737SAbhijeet Joglekar 8915df6d737SAbhijeet Joglekar } else { 8925df6d737SAbhijeet Joglekar /* wrong CQ type*/ 8935df6d737SAbhijeet Joglekar shost_printk(KERN_ERR, fnic->lport->host, 8945df6d737SAbhijeet Joglekar "fnic rq_cmpl wrong cq type x%x\n", type); 8955df6d737SAbhijeet Joglekar goto drop; 8965df6d737SAbhijeet Joglekar } 8975df6d737SAbhijeet Joglekar 8985df6d737SAbhijeet Joglekar if (!fcs_ok || packet_error || !fcoe_fc_crc_ok || fcoe_enc_error) { 89967125b02SHiral Patel atomic64_inc(&fnic_stats->misc_stats.frame_errors); 9005df6d737SAbhijeet Joglekar FNIC_FCS_DBG(KERN_DEBUG, fnic->lport->host, 9015df6d737SAbhijeet Joglekar "fnic rq_cmpl fcoe x%x fcsok x%x" 9025df6d737SAbhijeet Joglekar " pkterr x%x fcoe_fc_crc_ok x%x, fcoe_enc_err" 9035df6d737SAbhijeet Joglekar " x%x\n", 9045df6d737SAbhijeet Joglekar fcoe, fcs_ok, packet_error, 9055df6d737SAbhijeet Joglekar fcoe_fc_crc_ok, fcoe_enc_error); 9065df6d737SAbhijeet Joglekar goto drop; 9075df6d737SAbhijeet Joglekar } 9085df6d737SAbhijeet Joglekar 9095df6d737SAbhijeet Joglekar spin_lock_irqsave(&fnic->fnic_lock, flags); 9105df6d737SAbhijeet Joglekar if (fnic->stop_rx_link_events) { 9115df6d737SAbhijeet Joglekar spin_unlock_irqrestore(&fnic->fnic_lock, flags); 9125df6d737SAbhijeet Joglekar goto drop; 9135df6d737SAbhijeet Joglekar } 9145df6d737SAbhijeet Joglekar fr_dev(fp) = fnic->lport; 9155df6d737SAbhijeet Joglekar spin_unlock_irqrestore(&fnic->fnic_lock, flags); 916abb14148SHiral Shah if ((fnic_fc_trace_set_data(fnic->lport->host->host_no, FNIC_FC_RECV, 917abb14148SHiral Shah (char *)skb->data, skb->len)) != 0) { 918abb14148SHiral Shah printk(KERN_ERR "fnic ctlr frame trace error!!!"); 919abb14148SHiral Shah } 9205df6d737SAbhijeet Joglekar 9215df6d737SAbhijeet Joglekar skb_queue_tail(&fnic->frame_queue, skb); 9225df6d737SAbhijeet Joglekar queue_work(fnic_event_queue, &fnic->frame_work); 9235df6d737SAbhijeet Joglekar 9245df6d737SAbhijeet Joglekar return; 9255df6d737SAbhijeet Joglekar drop: 9265df6d737SAbhijeet Joglekar dev_kfree_skb_irq(skb); 9275df6d737SAbhijeet Joglekar } 9285df6d737SAbhijeet Joglekar 9295df6d737SAbhijeet Joglekar static int fnic_rq_cmpl_handler_cont(struct vnic_dev *vdev, 9305df6d737SAbhijeet Joglekar struct cq_desc *cq_desc, u8 type, 9315df6d737SAbhijeet Joglekar u16 q_number, u16 completed_index, 9325df6d737SAbhijeet Joglekar void *opaque) 9335df6d737SAbhijeet Joglekar { 9345df6d737SAbhijeet Joglekar struct fnic *fnic = vnic_dev_priv(vdev); 9355df6d737SAbhijeet Joglekar 9365df6d737SAbhijeet Joglekar vnic_rq_service(&fnic->rq[q_number], cq_desc, completed_index, 9375df6d737SAbhijeet Joglekar VNIC_RQ_RETURN_DESC, fnic_rq_cmpl_frame_recv, 9385df6d737SAbhijeet Joglekar NULL); 9395df6d737SAbhijeet Joglekar return 0; 9405df6d737SAbhijeet Joglekar } 9415df6d737SAbhijeet Joglekar 9425df6d737SAbhijeet Joglekar int fnic_rq_cmpl_handler(struct fnic *fnic, int rq_work_to_do) 9435df6d737SAbhijeet Joglekar { 9445df6d737SAbhijeet Joglekar unsigned int tot_rq_work_done = 0, cur_work_done; 9455df6d737SAbhijeet Joglekar unsigned int i; 9465df6d737SAbhijeet Joglekar int err; 9475df6d737SAbhijeet Joglekar 9485df6d737SAbhijeet Joglekar for (i = 0; i < fnic->rq_count; i++) { 9495df6d737SAbhijeet Joglekar cur_work_done = vnic_cq_service(&fnic->cq[i], rq_work_to_do, 9505df6d737SAbhijeet Joglekar fnic_rq_cmpl_handler_cont, 9515df6d737SAbhijeet Joglekar NULL); 9525df6d737SAbhijeet Joglekar if (cur_work_done) { 9535df6d737SAbhijeet Joglekar err = vnic_rq_fill(&fnic->rq[i], fnic_alloc_rq_frame); 9545df6d737SAbhijeet Joglekar if (err) 9555df6d737SAbhijeet Joglekar shost_printk(KERN_ERR, fnic->lport->host, 95625985edcSLucas De Marchi "fnic_alloc_rq_frame can't alloc" 9575df6d737SAbhijeet Joglekar " frame\n"); 9585df6d737SAbhijeet Joglekar } 9595df6d737SAbhijeet Joglekar tot_rq_work_done += cur_work_done; 9605df6d737SAbhijeet Joglekar } 9615df6d737SAbhijeet Joglekar 9625df6d737SAbhijeet Joglekar return tot_rq_work_done; 9635df6d737SAbhijeet Joglekar } 9645df6d737SAbhijeet Joglekar 9655df6d737SAbhijeet Joglekar /* 9665df6d737SAbhijeet Joglekar * This function is called once at init time to allocate and fill RQ 9675df6d737SAbhijeet Joglekar * buffers. Subsequently, it is called in the interrupt context after RQ 9685df6d737SAbhijeet Joglekar * buffer processing to replenish the buffers in the RQ 9695df6d737SAbhijeet Joglekar */ 9705df6d737SAbhijeet Joglekar int fnic_alloc_rq_frame(struct vnic_rq *rq) 9715df6d737SAbhijeet Joglekar { 9725df6d737SAbhijeet Joglekar struct fnic *fnic = vnic_dev_priv(rq->vdev); 9735df6d737SAbhijeet Joglekar struct sk_buff *skb; 9745df6d737SAbhijeet Joglekar u16 len; 9755df6d737SAbhijeet Joglekar dma_addr_t pa; 976fd6ddfa4SMaurizio Lombardi int r; 9775df6d737SAbhijeet Joglekar 9785df6d737SAbhijeet Joglekar len = FC_FRAME_HEADROOM + FC_MAX_FRAME + FC_FRAME_TAILROOM; 9795df6d737SAbhijeet Joglekar skb = dev_alloc_skb(len); 9805df6d737SAbhijeet Joglekar if (!skb) { 9815df6d737SAbhijeet Joglekar FNIC_FCS_DBG(KERN_DEBUG, fnic->lport->host, 9825df6d737SAbhijeet Joglekar "Unable to allocate RQ sk_buff\n"); 9835df6d737SAbhijeet Joglekar return -ENOMEM; 9845df6d737SAbhijeet Joglekar } 9855df6d737SAbhijeet Joglekar skb_reset_mac_header(skb); 9865df6d737SAbhijeet Joglekar skb_reset_transport_header(skb); 9875df6d737SAbhijeet Joglekar skb_reset_network_header(skb); 9885df6d737SAbhijeet Joglekar skb_put(skb, len); 9897f9b0f77SChristoph Hellwig pa = dma_map_single(&fnic->pdev->dev, skb->data, len, DMA_FROM_DEVICE); 9907f9b0f77SChristoph Hellwig if (dma_mapping_error(&fnic->pdev->dev, pa)) { 991dd7328e4SDan Carpenter r = -ENOMEM; 992fd6ddfa4SMaurizio Lombardi printk(KERN_ERR "PCI mapping failed with error %d\n", r); 993fd6ddfa4SMaurizio Lombardi goto free_skb; 994fd6ddfa4SMaurizio Lombardi } 995fd6ddfa4SMaurizio Lombardi 9965df6d737SAbhijeet Joglekar fnic_queue_rq_desc(rq, skb, pa, len); 9975df6d737SAbhijeet Joglekar return 0; 998fd6ddfa4SMaurizio Lombardi 999fd6ddfa4SMaurizio Lombardi free_skb: 1000fd6ddfa4SMaurizio Lombardi kfree_skb(skb); 1001fd6ddfa4SMaurizio Lombardi return r; 10025df6d737SAbhijeet Joglekar } 10035df6d737SAbhijeet Joglekar 10045df6d737SAbhijeet Joglekar void fnic_free_rq_buf(struct vnic_rq *rq, struct vnic_rq_buf *buf) 10055df6d737SAbhijeet Joglekar { 10065df6d737SAbhijeet Joglekar struct fc_frame *fp = buf->os_buf; 10075df6d737SAbhijeet Joglekar struct fnic *fnic = vnic_dev_priv(rq->vdev); 10085df6d737SAbhijeet Joglekar 10097f9b0f77SChristoph Hellwig dma_unmap_single(&fnic->pdev->dev, buf->dma_addr, buf->len, 10107f9b0f77SChristoph Hellwig DMA_FROM_DEVICE); 10115df6d737SAbhijeet Joglekar 10125df6d737SAbhijeet Joglekar dev_kfree_skb(fp_skb(fp)); 10135df6d737SAbhijeet Joglekar buf->os_buf = NULL; 10145df6d737SAbhijeet Joglekar } 10155df6d737SAbhijeet Joglekar 101678112e55SJoe Eykholt /** 101778112e55SJoe Eykholt * fnic_eth_send() - Send Ethernet frame. 101878112e55SJoe Eykholt * @fip: fcoe_ctlr instance. 101978112e55SJoe Eykholt * @skb: Ethernet Frame, FIP, without VLAN encapsulation. 102078112e55SJoe Eykholt */ 102178112e55SJoe Eykholt void fnic_eth_send(struct fcoe_ctlr *fip, struct sk_buff *skb) 10225df6d737SAbhijeet Joglekar { 102378112e55SJoe Eykholt struct fnic *fnic = fnic_from_ctlr(fip); 102478112e55SJoe Eykholt struct vnic_wq *wq = &fnic->wq[0]; 102578112e55SJoe Eykholt dma_addr_t pa; 102678112e55SJoe Eykholt struct ethhdr *eth_hdr; 102778112e55SJoe Eykholt struct vlan_ethhdr *vlan_hdr; 102878112e55SJoe Eykholt unsigned long flags; 102978112e55SJoe Eykholt 103078112e55SJoe Eykholt if (!fnic->vlan_hw_insert) { 103178112e55SJoe Eykholt eth_hdr = (struct ethhdr *)skb_mac_header(skb); 1032d58ff351SJohannes Berg vlan_hdr = skb_push(skb, sizeof(*vlan_hdr) - sizeof(*eth_hdr)); 103378112e55SJoe Eykholt memcpy(vlan_hdr, eth_hdr, 2 * ETH_ALEN); 103478112e55SJoe Eykholt vlan_hdr->h_vlan_proto = htons(ETH_P_8021Q); 103578112e55SJoe Eykholt vlan_hdr->h_vlan_encapsulated_proto = eth_hdr->h_proto; 103678112e55SJoe Eykholt vlan_hdr->h_vlan_TCI = htons(fnic->vlan_id); 1037abb14148SHiral Shah if ((fnic_fc_trace_set_data(fnic->lport->host->host_no, 1038abb14148SHiral Shah FNIC_FC_SEND|0x80, (char *)eth_hdr, skb->len)) != 0) { 1039abb14148SHiral Shah printk(KERN_ERR "fnic ctlr frame trace error!!!"); 1040abb14148SHiral Shah } 1041abb14148SHiral Shah } else { 1042abb14148SHiral Shah if ((fnic_fc_trace_set_data(fnic->lport->host->host_no, 1043abb14148SHiral Shah FNIC_FC_SEND|0x80, (char *)skb->data, skb->len)) != 0) { 1044abb14148SHiral Shah printk(KERN_ERR "fnic ctlr frame trace error!!!"); 1045abb14148SHiral Shah } 10465df6d737SAbhijeet Joglekar } 10475df6d737SAbhijeet Joglekar 10487f9b0f77SChristoph Hellwig pa = dma_map_single(&fnic->pdev->dev, skb->data, skb->len, 10497f9b0f77SChristoph Hellwig DMA_TO_DEVICE); 10507f9b0f77SChristoph Hellwig if (dma_mapping_error(&fnic->pdev->dev, pa)) { 10517f9b0f77SChristoph Hellwig printk(KERN_ERR "DMA mapping failed\n"); 1052fd6ddfa4SMaurizio Lombardi goto free_skb; 105378112e55SJoe Eykholt } 105478112e55SJoe Eykholt 1055fd6ddfa4SMaurizio Lombardi spin_lock_irqsave(&fnic->wq_lock[0], flags); 1056fd6ddfa4SMaurizio Lombardi if (!vnic_wq_desc_avail(wq)) 1057fd6ddfa4SMaurizio Lombardi goto irq_restore; 1058fd6ddfa4SMaurizio Lombardi 105978112e55SJoe Eykholt fnic_queue_wq_eth_desc(wq, skb, pa, skb->len, 1060c0773b7cSHiral Patel 0 /* hw inserts cos value */, 1061c0773b7cSHiral Patel fnic->vlan_id, 1); 106278112e55SJoe Eykholt spin_unlock_irqrestore(&fnic->wq_lock[0], flags); 1063fd6ddfa4SMaurizio Lombardi return; 1064fd6ddfa4SMaurizio Lombardi 1065fd6ddfa4SMaurizio Lombardi irq_restore: 1066fd6ddfa4SMaurizio Lombardi spin_unlock_irqrestore(&fnic->wq_lock[0], flags); 10677f9b0f77SChristoph Hellwig dma_unmap_single(&fnic->pdev->dev, pa, skb->len, DMA_TO_DEVICE); 1068fd6ddfa4SMaurizio Lombardi free_skb: 1069fd6ddfa4SMaurizio Lombardi kfree_skb(skb); 107078112e55SJoe Eykholt } 107178112e55SJoe Eykholt 107278112e55SJoe Eykholt /* 107378112e55SJoe Eykholt * Send FC frame. 107478112e55SJoe Eykholt */ 107578112e55SJoe Eykholt static int fnic_send_frame(struct fnic *fnic, struct fc_frame *fp) 10765df6d737SAbhijeet Joglekar { 10775df6d737SAbhijeet Joglekar struct vnic_wq *wq = &fnic->wq[0]; 10785df6d737SAbhijeet Joglekar struct sk_buff *skb; 10795df6d737SAbhijeet Joglekar dma_addr_t pa; 10805df6d737SAbhijeet Joglekar struct ethhdr *eth_hdr; 10815df6d737SAbhijeet Joglekar struct vlan_ethhdr *vlan_hdr; 10825df6d737SAbhijeet Joglekar struct fcoe_hdr *fcoe_hdr; 10835df6d737SAbhijeet Joglekar struct fc_frame_header *fh; 10845df6d737SAbhijeet Joglekar u32 tot_len, eth_hdr_len; 10855df6d737SAbhijeet Joglekar int ret = 0; 10865df6d737SAbhijeet Joglekar unsigned long flags; 10875df6d737SAbhijeet Joglekar 10885df6d737SAbhijeet Joglekar fh = fc_frame_header_get(fp); 10895df6d737SAbhijeet Joglekar skb = fp_skb(fp); 10905df6d737SAbhijeet Joglekar 109178112e55SJoe Eykholt if (unlikely(fh->fh_r_ctl == FC_RCTL_ELS_REQ) && 109278112e55SJoe Eykholt fcoe_ctlr_els_send(&fnic->ctlr, fnic->lport, skb)) 109378112e55SJoe Eykholt return 0; 109478112e55SJoe Eykholt 10955df6d737SAbhijeet Joglekar if (!fnic->vlan_hw_insert) { 10965df6d737SAbhijeet Joglekar eth_hdr_len = sizeof(*vlan_hdr) + sizeof(*fcoe_hdr); 1097d58ff351SJohannes Berg vlan_hdr = skb_push(skb, eth_hdr_len); 10985df6d737SAbhijeet Joglekar eth_hdr = (struct ethhdr *)vlan_hdr; 10995df6d737SAbhijeet Joglekar vlan_hdr->h_vlan_proto = htons(ETH_P_8021Q); 11005df6d737SAbhijeet Joglekar vlan_hdr->h_vlan_encapsulated_proto = htons(ETH_P_FCOE); 11015df6d737SAbhijeet Joglekar vlan_hdr->h_vlan_TCI = htons(fnic->vlan_id); 11025df6d737SAbhijeet Joglekar fcoe_hdr = (struct fcoe_hdr *)(vlan_hdr + 1); 11035df6d737SAbhijeet Joglekar } else { 11045df6d737SAbhijeet Joglekar eth_hdr_len = sizeof(*eth_hdr) + sizeof(*fcoe_hdr); 1105d58ff351SJohannes Berg eth_hdr = skb_push(skb, eth_hdr_len); 11065df6d737SAbhijeet Joglekar eth_hdr->h_proto = htons(ETH_P_FCOE); 11075df6d737SAbhijeet Joglekar fcoe_hdr = (struct fcoe_hdr *)(eth_hdr + 1); 11085df6d737SAbhijeet Joglekar } 11095df6d737SAbhijeet Joglekar 111078112e55SJoe Eykholt if (fnic->ctlr.map_dest) 11115df6d737SAbhijeet Joglekar fc_fcoe_set_mac(eth_hdr->h_dest, fh->fh_d_id); 11125df6d737SAbhijeet Joglekar else 111378112e55SJoe Eykholt memcpy(eth_hdr->h_dest, fnic->ctlr.dest_addr, ETH_ALEN); 11145df6d737SAbhijeet Joglekar memcpy(eth_hdr->h_source, fnic->data_src_addr, ETH_ALEN); 11155df6d737SAbhijeet Joglekar 11165df6d737SAbhijeet Joglekar tot_len = skb->len; 11175df6d737SAbhijeet Joglekar BUG_ON(tot_len % 4); 11185df6d737SAbhijeet Joglekar 11195df6d737SAbhijeet Joglekar memset(fcoe_hdr, 0, sizeof(*fcoe_hdr)); 11205df6d737SAbhijeet Joglekar fcoe_hdr->fcoe_sof = fr_sof(fp); 11215df6d737SAbhijeet Joglekar if (FC_FCOE_VER) 11225df6d737SAbhijeet Joglekar FC_FCOE_ENCAPS_VER(fcoe_hdr, FC_FCOE_VER); 11235df6d737SAbhijeet Joglekar 11247f9b0f77SChristoph Hellwig pa = dma_map_single(&fnic->pdev->dev, eth_hdr, tot_len, DMA_TO_DEVICE); 11257f9b0f77SChristoph Hellwig if (dma_mapping_error(&fnic->pdev->dev, pa)) { 1126dd7328e4SDan Carpenter ret = -ENOMEM; 1127fd6ddfa4SMaurizio Lombardi printk(KERN_ERR "DMA map failed with error %d\n", ret); 1128fd6ddfa4SMaurizio Lombardi goto free_skb_on_err; 1129fd6ddfa4SMaurizio Lombardi } 1130fd6ddfa4SMaurizio Lombardi 1131abb14148SHiral Shah if ((fnic_fc_trace_set_data(fnic->lport->host->host_no, FNIC_FC_SEND, 1132abb14148SHiral Shah (char *)eth_hdr, tot_len)) != 0) { 1133abb14148SHiral Shah printk(KERN_ERR "fnic ctlr frame trace error!!!"); 1134abb14148SHiral Shah } 1135abb14148SHiral Shah 11365df6d737SAbhijeet Joglekar spin_lock_irqsave(&fnic->wq_lock[0], flags); 11375df6d737SAbhijeet Joglekar 11385df6d737SAbhijeet Joglekar if (!vnic_wq_desc_avail(wq)) { 11397f9b0f77SChristoph Hellwig dma_unmap_single(&fnic->pdev->dev, pa, tot_len, DMA_TO_DEVICE); 11405df6d737SAbhijeet Joglekar ret = -1; 1141fd6ddfa4SMaurizio Lombardi goto irq_restore; 11425df6d737SAbhijeet Joglekar } 11435df6d737SAbhijeet Joglekar 11445df6d737SAbhijeet Joglekar fnic_queue_wq_desc(wq, skb, pa, tot_len, fr_eof(fp), 1145c0773b7cSHiral Patel 0 /* hw inserts cos value */, 1146c0773b7cSHiral Patel fnic->vlan_id, 1, 1, 1); 1147fd6ddfa4SMaurizio Lombardi 1148fd6ddfa4SMaurizio Lombardi irq_restore: 11495df6d737SAbhijeet Joglekar spin_unlock_irqrestore(&fnic->wq_lock[0], flags); 11505df6d737SAbhijeet Joglekar 1151fd6ddfa4SMaurizio Lombardi free_skb_on_err: 11525df6d737SAbhijeet Joglekar if (ret) 11535df6d737SAbhijeet Joglekar dev_kfree_skb_any(fp_skb(fp)); 11545df6d737SAbhijeet Joglekar 11555df6d737SAbhijeet Joglekar return ret; 11565df6d737SAbhijeet Joglekar } 11575df6d737SAbhijeet Joglekar 11585df6d737SAbhijeet Joglekar /* 11595df6d737SAbhijeet Joglekar * fnic_send 11605df6d737SAbhijeet Joglekar * Routine to send a raw frame 11615df6d737SAbhijeet Joglekar */ 11625df6d737SAbhijeet Joglekar int fnic_send(struct fc_lport *lp, struct fc_frame *fp) 11635df6d737SAbhijeet Joglekar { 11645df6d737SAbhijeet Joglekar struct fnic *fnic = lport_priv(lp); 11655df6d737SAbhijeet Joglekar unsigned long flags; 11665df6d737SAbhijeet Joglekar 11675df6d737SAbhijeet Joglekar if (fnic->in_remove) { 11685df6d737SAbhijeet Joglekar dev_kfree_skb(fp_skb(fp)); 116978112e55SJoe Eykholt return -1; 11705df6d737SAbhijeet Joglekar } 11715df6d737SAbhijeet Joglekar 117278112e55SJoe Eykholt /* 117378112e55SJoe Eykholt * Queue frame if in a transitional state. 117478112e55SJoe Eykholt * This occurs while registering the Port_ID / MAC address after FLOGI. 117578112e55SJoe Eykholt */ 117678112e55SJoe Eykholt spin_lock_irqsave(&fnic->fnic_lock, flags); 117778112e55SJoe Eykholt if (fnic->state != FNIC_IN_FC_MODE && fnic->state != FNIC_IN_ETH_MODE) { 117878112e55SJoe Eykholt skb_queue_tail(&fnic->tx_queue, fp_skb(fp)); 117978112e55SJoe Eykholt spin_unlock_irqrestore(&fnic->fnic_lock, flags); 118078112e55SJoe Eykholt return 0; 118178112e55SJoe Eykholt } 118278112e55SJoe Eykholt spin_unlock_irqrestore(&fnic->fnic_lock, flags); 11835df6d737SAbhijeet Joglekar 118478112e55SJoe Eykholt return fnic_send_frame(fnic, fp); 118578112e55SJoe Eykholt } 118678112e55SJoe Eykholt 118778112e55SJoe Eykholt /** 118878112e55SJoe Eykholt * fnic_flush_tx() - send queued frames. 118978112e55SJoe Eykholt * @fnic: fnic device 119078112e55SJoe Eykholt * 119178112e55SJoe Eykholt * Send frames that were waiting to go out in FC or Ethernet mode. 119278112e55SJoe Eykholt * Whenever changing modes we purge queued frames, so these frames should 119378112e55SJoe Eykholt * be queued for the stable mode that we're in, either FC or Ethernet. 119478112e55SJoe Eykholt * 119578112e55SJoe Eykholt * Called without fnic_lock held. 119678112e55SJoe Eykholt */ 119778112e55SJoe Eykholt void fnic_flush_tx(struct fnic *fnic) 119878112e55SJoe Eykholt { 119978112e55SJoe Eykholt struct sk_buff *skb; 120078112e55SJoe Eykholt struct fc_frame *fp; 120178112e55SJoe Eykholt 1202d9e9ab56SBrian Uchino while ((skb = skb_dequeue(&fnic->tx_queue))) { 120378112e55SJoe Eykholt fp = (struct fc_frame *)skb; 120478112e55SJoe Eykholt fnic_send_frame(fnic, fp); 120578112e55SJoe Eykholt } 120678112e55SJoe Eykholt } 120778112e55SJoe Eykholt 120878112e55SJoe Eykholt /** 120978112e55SJoe Eykholt * fnic_set_eth_mode() - put fnic into ethernet mode. 121078112e55SJoe Eykholt * @fnic: fnic device 121178112e55SJoe Eykholt * 121278112e55SJoe Eykholt * Called without fnic lock held. 121378112e55SJoe Eykholt */ 121478112e55SJoe Eykholt static void fnic_set_eth_mode(struct fnic *fnic) 121578112e55SJoe Eykholt { 121678112e55SJoe Eykholt unsigned long flags; 121778112e55SJoe Eykholt enum fnic_state old_state; 121878112e55SJoe Eykholt int ret; 12195df6d737SAbhijeet Joglekar 12205df6d737SAbhijeet Joglekar spin_lock_irqsave(&fnic->fnic_lock, flags); 12215df6d737SAbhijeet Joglekar again: 12225df6d737SAbhijeet Joglekar old_state = fnic->state; 12235df6d737SAbhijeet Joglekar switch (old_state) { 12245df6d737SAbhijeet Joglekar case FNIC_IN_FC_MODE: 12255df6d737SAbhijeet Joglekar case FNIC_IN_ETH_TRANS_FC_MODE: 12265df6d737SAbhijeet Joglekar default: 12275df6d737SAbhijeet Joglekar fnic->state = FNIC_IN_FC_TRANS_ETH_MODE; 12285df6d737SAbhijeet Joglekar spin_unlock_irqrestore(&fnic->fnic_lock, flags); 12295df6d737SAbhijeet Joglekar 12305df6d737SAbhijeet Joglekar ret = fnic_fw_reset_handler(fnic); 12315df6d737SAbhijeet Joglekar 12325df6d737SAbhijeet Joglekar spin_lock_irqsave(&fnic->fnic_lock, flags); 12335df6d737SAbhijeet Joglekar if (fnic->state != FNIC_IN_FC_TRANS_ETH_MODE) 12345df6d737SAbhijeet Joglekar goto again; 123578112e55SJoe Eykholt if (ret) 12365df6d737SAbhijeet Joglekar fnic->state = old_state; 12375df6d737SAbhijeet Joglekar break; 12385df6d737SAbhijeet Joglekar 12395df6d737SAbhijeet Joglekar case FNIC_IN_FC_TRANS_ETH_MODE: 12405df6d737SAbhijeet Joglekar case FNIC_IN_ETH_MODE: 12415df6d737SAbhijeet Joglekar break; 12425df6d737SAbhijeet Joglekar } 124378112e55SJoe Eykholt spin_unlock_irqrestore(&fnic->fnic_lock, flags); 12445df6d737SAbhijeet Joglekar } 12455df6d737SAbhijeet Joglekar 12465df6d737SAbhijeet Joglekar static void fnic_wq_complete_frame_send(struct vnic_wq *wq, 12475df6d737SAbhijeet Joglekar struct cq_desc *cq_desc, 12485df6d737SAbhijeet Joglekar struct vnic_wq_buf *buf, void *opaque) 12495df6d737SAbhijeet Joglekar { 12505df6d737SAbhijeet Joglekar struct sk_buff *skb = buf->os_buf; 12515df6d737SAbhijeet Joglekar struct fc_frame *fp = (struct fc_frame *)skb; 12525df6d737SAbhijeet Joglekar struct fnic *fnic = vnic_dev_priv(wq->vdev); 12535df6d737SAbhijeet Joglekar 12547f9b0f77SChristoph Hellwig dma_unmap_single(&fnic->pdev->dev, buf->dma_addr, buf->len, 12557f9b0f77SChristoph Hellwig DMA_TO_DEVICE); 12565df6d737SAbhijeet Joglekar dev_kfree_skb_irq(fp_skb(fp)); 12575df6d737SAbhijeet Joglekar buf->os_buf = NULL; 12585df6d737SAbhijeet Joglekar } 12595df6d737SAbhijeet Joglekar 12605df6d737SAbhijeet Joglekar static int fnic_wq_cmpl_handler_cont(struct vnic_dev *vdev, 12615df6d737SAbhijeet Joglekar struct cq_desc *cq_desc, u8 type, 12625df6d737SAbhijeet Joglekar u16 q_number, u16 completed_index, 12635df6d737SAbhijeet Joglekar void *opaque) 12645df6d737SAbhijeet Joglekar { 12655df6d737SAbhijeet Joglekar struct fnic *fnic = vnic_dev_priv(vdev); 12665df6d737SAbhijeet Joglekar unsigned long flags; 12675df6d737SAbhijeet Joglekar 12685df6d737SAbhijeet Joglekar spin_lock_irqsave(&fnic->wq_lock[q_number], flags); 12695df6d737SAbhijeet Joglekar vnic_wq_service(&fnic->wq[q_number], cq_desc, completed_index, 12705df6d737SAbhijeet Joglekar fnic_wq_complete_frame_send, NULL); 12715df6d737SAbhijeet Joglekar spin_unlock_irqrestore(&fnic->wq_lock[q_number], flags); 12725df6d737SAbhijeet Joglekar 12735df6d737SAbhijeet Joglekar return 0; 12745df6d737SAbhijeet Joglekar } 12755df6d737SAbhijeet Joglekar 12765df6d737SAbhijeet Joglekar int fnic_wq_cmpl_handler(struct fnic *fnic, int work_to_do) 12775df6d737SAbhijeet Joglekar { 12785df6d737SAbhijeet Joglekar unsigned int wq_work_done = 0; 12795df6d737SAbhijeet Joglekar unsigned int i; 12805df6d737SAbhijeet Joglekar 12815df6d737SAbhijeet Joglekar for (i = 0; i < fnic->raw_wq_count; i++) { 12825df6d737SAbhijeet Joglekar wq_work_done += vnic_cq_service(&fnic->cq[fnic->rq_count+i], 12835df6d737SAbhijeet Joglekar work_to_do, 12845df6d737SAbhijeet Joglekar fnic_wq_cmpl_handler_cont, 12855df6d737SAbhijeet Joglekar NULL); 12865df6d737SAbhijeet Joglekar } 12875df6d737SAbhijeet Joglekar 12885df6d737SAbhijeet Joglekar return wq_work_done; 12895df6d737SAbhijeet Joglekar } 12905df6d737SAbhijeet Joglekar 12915df6d737SAbhijeet Joglekar 12925df6d737SAbhijeet Joglekar void fnic_free_wq_buf(struct vnic_wq *wq, struct vnic_wq_buf *buf) 12935df6d737SAbhijeet Joglekar { 12945df6d737SAbhijeet Joglekar struct fc_frame *fp = buf->os_buf; 12955df6d737SAbhijeet Joglekar struct fnic *fnic = vnic_dev_priv(wq->vdev); 12965df6d737SAbhijeet Joglekar 12977f9b0f77SChristoph Hellwig dma_unmap_single(&fnic->pdev->dev, buf->dma_addr, buf->len, 12987f9b0f77SChristoph Hellwig DMA_TO_DEVICE); 12995df6d737SAbhijeet Joglekar 13005df6d737SAbhijeet Joglekar dev_kfree_skb(fp_skb(fp)); 13015df6d737SAbhijeet Joglekar buf->os_buf = NULL; 13025df6d737SAbhijeet Joglekar } 1303d3c995f1SHiral Patel 1304d3c995f1SHiral Patel void fnic_fcoe_reset_vlans(struct fnic *fnic) 1305d3c995f1SHiral Patel { 1306d3c995f1SHiral Patel unsigned long flags; 1307d3c995f1SHiral Patel struct fcoe_vlan *vlan; 1308d3c995f1SHiral Patel struct fcoe_vlan *next; 1309d3c995f1SHiral Patel 1310d3c995f1SHiral Patel /* 1311d3c995f1SHiral Patel * indicate a link down to fcoe so that all fcf's are free'd 1312d3c995f1SHiral Patel * might not be required since we did this before sending vlan 1313d3c995f1SHiral Patel * discovery request 1314d3c995f1SHiral Patel */ 1315d3c995f1SHiral Patel spin_lock_irqsave(&fnic->vlans_lock, flags); 1316d3c995f1SHiral Patel if (!list_empty(&fnic->vlans)) { 1317d3c995f1SHiral Patel list_for_each_entry_safe(vlan, next, &fnic->vlans, list) { 1318d3c995f1SHiral Patel list_del(&vlan->list); 1319d3c995f1SHiral Patel kfree(vlan); 1320d3c995f1SHiral Patel } 1321d3c995f1SHiral Patel } 1322d3c995f1SHiral Patel spin_unlock_irqrestore(&fnic->vlans_lock, flags); 1323d3c995f1SHiral Patel } 1324d3c995f1SHiral Patel 1325d3c995f1SHiral Patel void fnic_handle_fip_timer(struct fnic *fnic) 1326d3c995f1SHiral Patel { 1327d3c995f1SHiral Patel unsigned long flags; 1328d3c995f1SHiral Patel struct fcoe_vlan *vlan; 132967125b02SHiral Patel struct fnic_stats *fnic_stats = &fnic->fnic_stats; 1330d3c995f1SHiral Patel u64 sol_time; 1331d3c995f1SHiral Patel 1332d3c995f1SHiral Patel spin_lock_irqsave(&fnic->fnic_lock, flags); 1333d3c995f1SHiral Patel if (fnic->stop_rx_link_events) { 1334d3c995f1SHiral Patel spin_unlock_irqrestore(&fnic->fnic_lock, flags); 1335d3c995f1SHiral Patel return; 1336d3c995f1SHiral Patel } 1337d3c995f1SHiral Patel spin_unlock_irqrestore(&fnic->fnic_lock, flags); 1338d3c995f1SHiral Patel 13391917d42dSHannes Reinecke if (fnic->ctlr.mode == FIP_MODE_NON_FIP) 1340d3c995f1SHiral Patel return; 1341d3c995f1SHiral Patel 1342d3c995f1SHiral Patel spin_lock_irqsave(&fnic->vlans_lock, flags); 1343d3c995f1SHiral Patel if (list_empty(&fnic->vlans)) { 1344b43abcbbSSatish Kharat spin_unlock_irqrestore(&fnic->vlans_lock, flags); 1345d3c995f1SHiral Patel /* no vlans available, try again */ 1346b43abcbbSSatish Kharat if (printk_ratelimit()) 1347d3c995f1SHiral Patel FNIC_FCS_DBG(KERN_DEBUG, fnic->lport->host, 1348d3c995f1SHiral Patel "Start VLAN Discovery\n"); 1349d3c995f1SHiral Patel fnic_event_enq(fnic, FNIC_EVT_START_VLAN_DISC); 1350d3c995f1SHiral Patel return; 1351d3c995f1SHiral Patel } 1352d3c995f1SHiral Patel 1353d3c995f1SHiral Patel vlan = list_first_entry(&fnic->vlans, struct fcoe_vlan, list); 135490b3a938SKaran Tilak Kumar FNIC_FCS_DBG(KERN_DEBUG, fnic->lport->host, 1355d3c995f1SHiral Patel "fip_timer: vlan %d state %d sol_count %d\n", 1356d3c995f1SHiral Patel vlan->vid, vlan->state, vlan->sol_count); 1357d3c995f1SHiral Patel switch (vlan->state) { 1358d3c995f1SHiral Patel case FIP_VLAN_USED: 1359d3c995f1SHiral Patel FNIC_FCS_DBG(KERN_DEBUG, fnic->lport->host, 1360d3c995f1SHiral Patel "FIP VLAN is selected for FC transaction\n"); 1361d3c995f1SHiral Patel spin_unlock_irqrestore(&fnic->vlans_lock, flags); 1362d3c995f1SHiral Patel break; 1363d3c995f1SHiral Patel case FIP_VLAN_FAILED: 1364b43abcbbSSatish Kharat spin_unlock_irqrestore(&fnic->vlans_lock, flags); 1365d3c995f1SHiral Patel /* if all vlans are in failed state, restart vlan disc */ 1366b43abcbbSSatish Kharat if (printk_ratelimit()) 1367d3c995f1SHiral Patel FNIC_FCS_DBG(KERN_DEBUG, fnic->lport->host, 1368d3c995f1SHiral Patel "Start VLAN Discovery\n"); 1369d3c995f1SHiral Patel fnic_event_enq(fnic, FNIC_EVT_START_VLAN_DISC); 1370d3c995f1SHiral Patel break; 1371d3c995f1SHiral Patel case FIP_VLAN_SENT: 1372d3c995f1SHiral Patel if (vlan->sol_count >= FCOE_CTLR_MAX_SOL) { 1373d3c995f1SHiral Patel /* 1374d3c995f1SHiral Patel * no response on this vlan, remove from the list. 1375d3c995f1SHiral Patel * Try the next vlan 1376d3c995f1SHiral Patel */ 137790b3a938SKaran Tilak Kumar FNIC_FCS_DBG(KERN_INFO, fnic->lport->host, 1378d3c995f1SHiral Patel "Dequeue this VLAN ID %d from list\n", 1379d3c995f1SHiral Patel vlan->vid); 1380d3c995f1SHiral Patel list_del(&vlan->list); 1381d3c995f1SHiral Patel kfree(vlan); 1382d3c995f1SHiral Patel vlan = NULL; 1383d3c995f1SHiral Patel if (list_empty(&fnic->vlans)) { 1384d3c995f1SHiral Patel /* we exhausted all vlans, restart vlan disc */ 1385d3c995f1SHiral Patel spin_unlock_irqrestore(&fnic->vlans_lock, 1386d3c995f1SHiral Patel flags); 138790b3a938SKaran Tilak Kumar FNIC_FCS_DBG(KERN_INFO, fnic->lport->host, 1388d3c995f1SHiral Patel "fip_timer: vlan list empty, " 1389d3c995f1SHiral Patel "trigger vlan disc\n"); 1390d3c995f1SHiral Patel fnic_event_enq(fnic, FNIC_EVT_START_VLAN_DISC); 1391d3c995f1SHiral Patel return; 1392d3c995f1SHiral Patel } 1393d3c995f1SHiral Patel /* check the next vlan */ 1394d3c995f1SHiral Patel vlan = list_first_entry(&fnic->vlans, struct fcoe_vlan, 1395d3c995f1SHiral Patel list); 1396d3c995f1SHiral Patel fnic->set_vlan(fnic, vlan->vid); 1397d3c995f1SHiral Patel vlan->state = FIP_VLAN_SENT; /* sent now */ 1398d3c995f1SHiral Patel } 1399d3c995f1SHiral Patel spin_unlock_irqrestore(&fnic->vlans_lock, flags); 140067125b02SHiral Patel atomic64_inc(&fnic_stats->vlan_stats.sol_expiry_count); 1401d3c995f1SHiral Patel vlan->sol_count++; 1402d3c995f1SHiral Patel sol_time = jiffies + msecs_to_jiffies 1403d3c995f1SHiral Patel (FCOE_CTLR_START_DELAY); 1404d3c995f1SHiral Patel mod_timer(&fnic->fip_timer, round_jiffies(sol_time)); 1405d3c995f1SHiral Patel break; 1406d3c995f1SHiral Patel } 1407d3c995f1SHiral Patel } 1408