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; 555df6d737SAbhijeet Joglekar 565df6d737SAbhijeet Joglekar spin_lock_irqsave(&fnic->fnic_lock, flags); 575df6d737SAbhijeet Joglekar 585df6d737SAbhijeet Joglekar if (fnic->stop_rx_link_events) { 595df6d737SAbhijeet Joglekar spin_unlock_irqrestore(&fnic->fnic_lock, flags); 605df6d737SAbhijeet Joglekar return; 615df6d737SAbhijeet Joglekar } 625df6d737SAbhijeet Joglekar 635df6d737SAbhijeet Joglekar old_link_down_cnt = fnic->link_down_cnt; 645df6d737SAbhijeet Joglekar old_link_status = fnic->link_status; 655df6d737SAbhijeet Joglekar fnic->link_status = vnic_dev_link_status(fnic->vdev); 665df6d737SAbhijeet Joglekar fnic->link_down_cnt = vnic_dev_link_down_cnt(fnic->vdev); 675df6d737SAbhijeet Joglekar 685df6d737SAbhijeet Joglekar if (old_link_status == fnic->link_status) { 69abb14148SHiral Shah if (!fnic->link_status) { 705df6d737SAbhijeet Joglekar /* DOWN -> DOWN */ 715df6d737SAbhijeet Joglekar spin_unlock_irqrestore(&fnic->fnic_lock, flags); 72abb14148SHiral Shah fnic_fc_trace_set_data(fnic->lport->host->host_no, 73abb14148SHiral Shah FNIC_FC_LE, "Link Status: DOWN->DOWN", 74abb14148SHiral Shah strlen("Link Status: DOWN->DOWN")); 75abb14148SHiral Shah } else { 765df6d737SAbhijeet Joglekar if (old_link_down_cnt != fnic->link_down_cnt) { 775df6d737SAbhijeet Joglekar /* UP -> DOWN -> UP */ 785df6d737SAbhijeet Joglekar fnic->lport->host_stats.link_failure_count++; 795df6d737SAbhijeet Joglekar spin_unlock_irqrestore(&fnic->fnic_lock, flags); 80abb14148SHiral Shah fnic_fc_trace_set_data( 81abb14148SHiral Shah fnic->lport->host->host_no, 82abb14148SHiral Shah FNIC_FC_LE, 83abb14148SHiral Shah "Link Status:UP_DOWN_UP", 84abb14148SHiral Shah strlen("Link_Status:UP_DOWN_UP") 85abb14148SHiral Shah ); 865df6d737SAbhijeet Joglekar FNIC_FCS_DBG(KERN_DEBUG, fnic->lport->host, 875df6d737SAbhijeet Joglekar "link down\n"); 8878112e55SJoe Eykholt fcoe_ctlr_link_down(&fnic->ctlr); 89d3c995f1SHiral Patel if (fnic->config.flags & VFCF_FIP_CAPABLE) { 90d3c995f1SHiral Patel /* start FCoE VLAN discovery */ 91abb14148SHiral Shah fnic_fc_trace_set_data( 92abb14148SHiral Shah fnic->lport->host->host_no, 93abb14148SHiral Shah FNIC_FC_LE, 94abb14148SHiral Shah "Link Status: UP_DOWN_UP_VLAN", 95abb14148SHiral Shah strlen( 96abb14148SHiral Shah "Link Status: UP_DOWN_UP_VLAN") 97abb14148SHiral Shah ); 98d3c995f1SHiral Patel fnic_fcoe_send_vlan_req(fnic); 99d3c995f1SHiral Patel return; 100d3c995f1SHiral Patel } 1015df6d737SAbhijeet Joglekar FNIC_FCS_DBG(KERN_DEBUG, fnic->lport->host, 1025df6d737SAbhijeet Joglekar "link up\n"); 10378112e55SJoe Eykholt fcoe_ctlr_link_up(&fnic->ctlr); 10486001f24SHiral Shah } else { 1055df6d737SAbhijeet Joglekar /* UP -> UP */ 1065df6d737SAbhijeet Joglekar spin_unlock_irqrestore(&fnic->fnic_lock, flags); 107abb14148SHiral Shah fnic_fc_trace_set_data( 108abb14148SHiral Shah fnic->lport->host->host_no, FNIC_FC_LE, 109abb14148SHiral Shah "Link Status: UP_UP", 110abb14148SHiral Shah strlen("Link Status: UP_UP")); 1115df6d737SAbhijeet Joglekar } 11286001f24SHiral Shah } 1135df6d737SAbhijeet Joglekar } else if (fnic->link_status) { 1145df6d737SAbhijeet Joglekar /* DOWN -> UP */ 1155df6d737SAbhijeet Joglekar spin_unlock_irqrestore(&fnic->fnic_lock, flags); 116d3c995f1SHiral Patel if (fnic->config.flags & VFCF_FIP_CAPABLE) { 117d3c995f1SHiral Patel /* start FCoE VLAN discovery */ 118abb14148SHiral Shah fnic_fc_trace_set_data( 119abb14148SHiral Shah fnic->lport->host->host_no, 120abb14148SHiral Shah FNIC_FC_LE, "Link Status: DOWN_UP_VLAN", 121abb14148SHiral Shah strlen("Link Status: DOWN_UP_VLAN")); 122d3c995f1SHiral Patel fnic_fcoe_send_vlan_req(fnic); 123d3c995f1SHiral Patel return; 124d3c995f1SHiral Patel } 1255df6d737SAbhijeet Joglekar FNIC_FCS_DBG(KERN_DEBUG, fnic->lport->host, "link up\n"); 126abb14148SHiral Shah fnic_fc_trace_set_data(fnic->lport->host->host_no, FNIC_FC_LE, 127abb14148SHiral Shah "Link Status: DOWN_UP", strlen("Link Status: DOWN_UP")); 12878112e55SJoe Eykholt fcoe_ctlr_link_up(&fnic->ctlr); 1295df6d737SAbhijeet Joglekar } else { 1305df6d737SAbhijeet Joglekar /* UP -> DOWN */ 1315df6d737SAbhijeet Joglekar fnic->lport->host_stats.link_failure_count++; 1325df6d737SAbhijeet Joglekar spin_unlock_irqrestore(&fnic->fnic_lock, flags); 1335df6d737SAbhijeet Joglekar FNIC_FCS_DBG(KERN_DEBUG, fnic->lport->host, "link down\n"); 134abb14148SHiral Shah fnic_fc_trace_set_data( 135abb14148SHiral Shah fnic->lport->host->host_no, FNIC_FC_LE, 136abb14148SHiral Shah "Link Status: UP_DOWN", 137abb14148SHiral Shah strlen("Link Status: UP_DOWN")); 1380ee7b871SHiral Shah if (fnic->config.flags & VFCF_FIP_CAPABLE) { 1390ee7b871SHiral Shah FNIC_FCS_DBG(KERN_DEBUG, fnic->lport->host, 1400ee7b871SHiral Shah "deleting fip-timer during link-down\n"); 1410ee7b871SHiral Shah del_timer_sync(&fnic->fip_timer); 1420ee7b871SHiral Shah } 14378112e55SJoe Eykholt fcoe_ctlr_link_down(&fnic->ctlr); 1445df6d737SAbhijeet Joglekar } 1455df6d737SAbhijeet Joglekar 1465df6d737SAbhijeet Joglekar } 1475df6d737SAbhijeet Joglekar 1485df6d737SAbhijeet Joglekar /* 1495df6d737SAbhijeet Joglekar * This function passes incoming fabric frames to libFC 1505df6d737SAbhijeet Joglekar */ 1515df6d737SAbhijeet Joglekar void fnic_handle_frame(struct work_struct *work) 1525df6d737SAbhijeet Joglekar { 1535df6d737SAbhijeet Joglekar struct fnic *fnic = container_of(work, struct fnic, frame_work); 1545df6d737SAbhijeet Joglekar struct fc_lport *lp = fnic->lport; 1555df6d737SAbhijeet Joglekar unsigned long flags; 1565df6d737SAbhijeet Joglekar struct sk_buff *skb; 1575df6d737SAbhijeet Joglekar struct fc_frame *fp; 1585df6d737SAbhijeet Joglekar 1595df6d737SAbhijeet Joglekar while ((skb = skb_dequeue(&fnic->frame_queue))) { 1605df6d737SAbhijeet Joglekar 1615df6d737SAbhijeet Joglekar spin_lock_irqsave(&fnic->fnic_lock, flags); 1625df6d737SAbhijeet Joglekar if (fnic->stop_rx_link_events) { 1635df6d737SAbhijeet Joglekar spin_unlock_irqrestore(&fnic->fnic_lock, flags); 1645df6d737SAbhijeet Joglekar dev_kfree_skb(skb); 1655df6d737SAbhijeet Joglekar return; 1665df6d737SAbhijeet Joglekar } 1675df6d737SAbhijeet Joglekar fp = (struct fc_frame *)skb; 16878112e55SJoe Eykholt 16978112e55SJoe Eykholt /* 17078112e55SJoe Eykholt * If we're in a transitional state, just re-queue and return. 17178112e55SJoe Eykholt * The queue will be serviced when we get to a stable state. 17278112e55SJoe Eykholt */ 17378112e55SJoe Eykholt if (fnic->state != FNIC_IN_FC_MODE && 17478112e55SJoe Eykholt fnic->state != FNIC_IN_ETH_MODE) { 17578112e55SJoe Eykholt skb_queue_head(&fnic->frame_queue, skb); 17678112e55SJoe Eykholt spin_unlock_irqrestore(&fnic->fnic_lock, flags); 17778112e55SJoe Eykholt return; 1785df6d737SAbhijeet Joglekar } 1795df6d737SAbhijeet Joglekar spin_unlock_irqrestore(&fnic->fnic_lock, flags); 1805df6d737SAbhijeet Joglekar 18152ff878cSVasu Dev fc_exch_recv(lp, fp); 1825df6d737SAbhijeet Joglekar } 1835df6d737SAbhijeet Joglekar } 1845df6d737SAbhijeet Joglekar 185d3c995f1SHiral Patel void fnic_fcoe_evlist_free(struct fnic *fnic) 186d3c995f1SHiral Patel { 187d3c995f1SHiral Patel struct fnic_event *fevt = NULL; 188d3c995f1SHiral Patel struct fnic_event *next = NULL; 189d3c995f1SHiral Patel unsigned long flags; 190d3c995f1SHiral Patel 191d3c995f1SHiral Patel spin_lock_irqsave(&fnic->fnic_lock, flags); 192d3c995f1SHiral Patel if (list_empty(&fnic->evlist)) { 193d3c995f1SHiral Patel spin_unlock_irqrestore(&fnic->fnic_lock, flags); 194d3c995f1SHiral Patel return; 195d3c995f1SHiral Patel } 196d3c995f1SHiral Patel 197d3c995f1SHiral Patel list_for_each_entry_safe(fevt, next, &fnic->evlist, list) { 198d3c995f1SHiral Patel list_del(&fevt->list); 199d3c995f1SHiral Patel kfree(fevt); 200d3c995f1SHiral Patel } 201d3c995f1SHiral Patel spin_unlock_irqrestore(&fnic->fnic_lock, flags); 202d3c995f1SHiral Patel } 203d3c995f1SHiral Patel 204d3c995f1SHiral Patel void fnic_handle_event(struct work_struct *work) 205d3c995f1SHiral Patel { 206d3c995f1SHiral Patel struct fnic *fnic = container_of(work, struct fnic, event_work); 207d3c995f1SHiral Patel struct fnic_event *fevt = NULL; 208d3c995f1SHiral Patel struct fnic_event *next = NULL; 209d3c995f1SHiral Patel unsigned long flags; 210d3c995f1SHiral Patel 211d3c995f1SHiral Patel spin_lock_irqsave(&fnic->fnic_lock, flags); 212d3c995f1SHiral Patel if (list_empty(&fnic->evlist)) { 213d3c995f1SHiral Patel spin_unlock_irqrestore(&fnic->fnic_lock, flags); 214d3c995f1SHiral Patel return; 215d3c995f1SHiral Patel } 216d3c995f1SHiral Patel 217d3c995f1SHiral Patel list_for_each_entry_safe(fevt, next, &fnic->evlist, list) { 218d3c995f1SHiral Patel if (fnic->stop_rx_link_events) { 219d3c995f1SHiral Patel list_del(&fevt->list); 220d3c995f1SHiral Patel kfree(fevt); 221d3c995f1SHiral Patel spin_unlock_irqrestore(&fnic->fnic_lock, flags); 222d3c995f1SHiral Patel return; 223d3c995f1SHiral Patel } 224d3c995f1SHiral Patel /* 225d3c995f1SHiral Patel * If we're in a transitional state, just re-queue and return. 226d3c995f1SHiral Patel * The queue will be serviced when we get to a stable state. 227d3c995f1SHiral Patel */ 228d3c995f1SHiral Patel if (fnic->state != FNIC_IN_FC_MODE && 229d3c995f1SHiral Patel fnic->state != FNIC_IN_ETH_MODE) { 230d3c995f1SHiral Patel spin_unlock_irqrestore(&fnic->fnic_lock, flags); 231d3c995f1SHiral Patel return; 232d3c995f1SHiral Patel } 233d3c995f1SHiral Patel 234d3c995f1SHiral Patel list_del(&fevt->list); 235d3c995f1SHiral Patel switch (fevt->event) { 236d3c995f1SHiral Patel case FNIC_EVT_START_VLAN_DISC: 237d3c995f1SHiral Patel spin_unlock_irqrestore(&fnic->fnic_lock, flags); 238d3c995f1SHiral Patel fnic_fcoe_send_vlan_req(fnic); 239d3c995f1SHiral Patel spin_lock_irqsave(&fnic->fnic_lock, flags); 240d3c995f1SHiral Patel break; 241d3c995f1SHiral Patel case FNIC_EVT_START_FCF_DISC: 242d3c995f1SHiral Patel FNIC_FCS_DBG(KERN_DEBUG, fnic->lport->host, 243d3c995f1SHiral Patel "Start FCF Discovery\n"); 244d3c995f1SHiral Patel fnic_fcoe_start_fcf_disc(fnic); 245d3c995f1SHiral Patel break; 246d3c995f1SHiral Patel default: 247d3c995f1SHiral Patel FNIC_FCS_DBG(KERN_DEBUG, fnic->lport->host, 248d3c995f1SHiral Patel "Unknown event 0x%x\n", fevt->event); 249d3c995f1SHiral Patel break; 250d3c995f1SHiral Patel } 251d3c995f1SHiral Patel kfree(fevt); 252d3c995f1SHiral Patel } 253d3c995f1SHiral Patel spin_unlock_irqrestore(&fnic->fnic_lock, flags); 254d3c995f1SHiral Patel } 255d3c995f1SHiral Patel 256d3c995f1SHiral Patel /** 257d3c995f1SHiral Patel * Check if the Received FIP FLOGI frame is rejected 258d3c995f1SHiral Patel * @fip: The FCoE controller that received the frame 259d3c995f1SHiral Patel * @skb: The received FIP frame 260d3c995f1SHiral Patel * 261d3c995f1SHiral Patel * Returns non-zero if the frame is rejected with unsupported cmd with 262d3c995f1SHiral Patel * insufficient resource els explanation. 263d3c995f1SHiral Patel */ 264d3c995f1SHiral Patel static inline int is_fnic_fip_flogi_reject(struct fcoe_ctlr *fip, 265d3c995f1SHiral Patel struct sk_buff *skb) 266d3c995f1SHiral Patel { 267d3c995f1SHiral Patel struct fc_lport *lport = fip->lp; 268d3c995f1SHiral Patel struct fip_header *fiph; 269d3c995f1SHiral Patel struct fc_frame_header *fh = NULL; 270d3c995f1SHiral Patel struct fip_desc *desc; 271d3c995f1SHiral Patel struct fip_encaps *els; 272d3c995f1SHiral Patel enum fip_desc_type els_dtype = 0; 273d3c995f1SHiral Patel u16 op; 274d3c995f1SHiral Patel u8 els_op; 275d3c995f1SHiral Patel u8 sub; 276d3c995f1SHiral Patel 277d3c995f1SHiral Patel size_t els_len = 0; 278d3c995f1SHiral Patel size_t rlen; 279d3c995f1SHiral Patel size_t dlen = 0; 280d3c995f1SHiral Patel 281d3c995f1SHiral Patel if (skb_linearize(skb)) 282d3c995f1SHiral Patel return 0; 283d3c995f1SHiral Patel 284d3c995f1SHiral Patel if (skb->len < sizeof(*fiph)) 285d3c995f1SHiral Patel return 0; 286d3c995f1SHiral Patel 287d3c995f1SHiral Patel fiph = (struct fip_header *)skb->data; 288d3c995f1SHiral Patel op = ntohs(fiph->fip_op); 289d3c995f1SHiral Patel sub = fiph->fip_subcode; 290d3c995f1SHiral Patel 291d3c995f1SHiral Patel if (op != FIP_OP_LS) 292d3c995f1SHiral Patel return 0; 293d3c995f1SHiral Patel 294d3c995f1SHiral Patel if (sub != FIP_SC_REP) 295d3c995f1SHiral Patel return 0; 296d3c995f1SHiral Patel 297d3c995f1SHiral Patel rlen = ntohs(fiph->fip_dl_len) * 4; 298d3c995f1SHiral Patel if (rlen + sizeof(*fiph) > skb->len) 299d3c995f1SHiral Patel return 0; 300d3c995f1SHiral Patel 301d3c995f1SHiral Patel desc = (struct fip_desc *)(fiph + 1); 302d3c995f1SHiral Patel dlen = desc->fip_dlen * FIP_BPW; 303d3c995f1SHiral Patel 304d3c995f1SHiral Patel if (desc->fip_dtype == FIP_DT_FLOGI) { 305d3c995f1SHiral Patel 306d3c995f1SHiral Patel if (dlen < sizeof(*els) + sizeof(*fh) + 1) 307d3c995f1SHiral Patel return 0; 308d3c995f1SHiral Patel 309d3c995f1SHiral Patel els_len = dlen - sizeof(*els); 310d3c995f1SHiral Patel els = (struct fip_encaps *)desc; 311d3c995f1SHiral Patel fh = (struct fc_frame_header *)(els + 1); 312d3c995f1SHiral Patel els_dtype = desc->fip_dtype; 313d3c995f1SHiral Patel 314d3c995f1SHiral Patel if (!fh) 315d3c995f1SHiral Patel return 0; 316d3c995f1SHiral Patel 317d3c995f1SHiral Patel /* 318d3c995f1SHiral Patel * ELS command code, reason and explanation should be = Reject, 319d3c995f1SHiral Patel * unsupported command and insufficient resource 320d3c995f1SHiral Patel */ 321d3c995f1SHiral Patel els_op = *(u8 *)(fh + 1); 322d3c995f1SHiral Patel if (els_op == ELS_LS_RJT) { 323d3c995f1SHiral Patel shost_printk(KERN_INFO, lport->host, 324d3c995f1SHiral Patel "Flogi Request Rejected by Switch\n"); 325d3c995f1SHiral Patel return 1; 326d3c995f1SHiral Patel } 327d3c995f1SHiral Patel shost_printk(KERN_INFO, lport->host, 328d3c995f1SHiral Patel "Flogi Request Accepted by Switch\n"); 329d3c995f1SHiral Patel } 330d3c995f1SHiral Patel return 0; 331d3c995f1SHiral Patel } 332d3c995f1SHiral Patel 333d3c995f1SHiral Patel static void fnic_fcoe_send_vlan_req(struct fnic *fnic) 334d3c995f1SHiral Patel { 335d3c995f1SHiral Patel struct fcoe_ctlr *fip = &fnic->ctlr; 33667125b02SHiral Patel struct fnic_stats *fnic_stats = &fnic->fnic_stats; 337d3c995f1SHiral Patel struct sk_buff *skb; 338d3c995f1SHiral Patel char *eth_fr; 339d3c995f1SHiral Patel int fr_len; 340d3c995f1SHiral Patel struct fip_vlan *vlan; 341d3c995f1SHiral Patel u64 vlan_tov; 342d3c995f1SHiral Patel 343d3c995f1SHiral Patel fnic_fcoe_reset_vlans(fnic); 344d3c995f1SHiral Patel fnic->set_vlan(fnic, 0); 345b43abcbbSSatish Kharat 346b43abcbbSSatish Kharat if (printk_ratelimit()) 347d3c995f1SHiral Patel FNIC_FCS_DBG(KERN_INFO, fnic->lport->host, 348d3c995f1SHiral Patel "Sending VLAN request...\n"); 349b43abcbbSSatish Kharat 350d3c995f1SHiral Patel skb = dev_alloc_skb(sizeof(struct fip_vlan)); 351d3c995f1SHiral Patel if (!skb) 352d3c995f1SHiral Patel return; 353d3c995f1SHiral Patel 354d3c995f1SHiral Patel fr_len = sizeof(*vlan); 355d3c995f1SHiral Patel eth_fr = (char *)skb->data; 356d3c995f1SHiral Patel vlan = (struct fip_vlan *)eth_fr; 357d3c995f1SHiral Patel 358d3c995f1SHiral Patel memset(vlan, 0, sizeof(*vlan)); 359d3c995f1SHiral Patel memcpy(vlan->eth.h_source, fip->ctl_src_addr, ETH_ALEN); 360d3c995f1SHiral Patel memcpy(vlan->eth.h_dest, fcoe_all_fcfs, ETH_ALEN); 361d3c995f1SHiral Patel vlan->eth.h_proto = htons(ETH_P_FIP); 362d3c995f1SHiral Patel 363d3c995f1SHiral Patel vlan->fip.fip_ver = FIP_VER_ENCAPS(FIP_VER); 364d3c995f1SHiral Patel vlan->fip.fip_op = htons(FIP_OP_VLAN); 365b8e1aa3cSSatish Kharat vlan->fip.fip_subcode = FIP_SC_VL_REQ; 366d3c995f1SHiral Patel vlan->fip.fip_dl_len = htons(sizeof(vlan->desc) / FIP_BPW); 367d3c995f1SHiral Patel 368d3c995f1SHiral Patel vlan->desc.mac.fd_desc.fip_dtype = FIP_DT_MAC; 369d3c995f1SHiral Patel vlan->desc.mac.fd_desc.fip_dlen = sizeof(vlan->desc.mac) / FIP_BPW; 370d3c995f1SHiral Patel memcpy(&vlan->desc.mac.fd_mac, fip->ctl_src_addr, ETH_ALEN); 371d3c995f1SHiral Patel 372d3c995f1SHiral Patel vlan->desc.wwnn.fd_desc.fip_dtype = FIP_DT_NAME; 373d3c995f1SHiral Patel vlan->desc.wwnn.fd_desc.fip_dlen = sizeof(vlan->desc.wwnn) / FIP_BPW; 374d3c995f1SHiral Patel put_unaligned_be64(fip->lp->wwnn, &vlan->desc.wwnn.fd_wwn); 37567125b02SHiral Patel atomic64_inc(&fnic_stats->vlan_stats.vlan_disc_reqs); 376d3c995f1SHiral Patel 377d3c995f1SHiral Patel skb_put(skb, sizeof(*vlan)); 378d3c995f1SHiral Patel skb->protocol = htons(ETH_P_FIP); 379d3c995f1SHiral Patel skb_reset_mac_header(skb); 380d3c995f1SHiral Patel skb_reset_network_header(skb); 381d3c995f1SHiral Patel fip->send(fip, skb); 382d3c995f1SHiral Patel 383d3c995f1SHiral Patel /* set a timer so that we can retry if there no response */ 384d3c995f1SHiral Patel vlan_tov = jiffies + msecs_to_jiffies(FCOE_CTLR_FIPVLAN_TOV); 385d3c995f1SHiral Patel mod_timer(&fnic->fip_timer, round_jiffies(vlan_tov)); 386d3c995f1SHiral Patel } 387d3c995f1SHiral Patel 388d3c995f1SHiral Patel static void fnic_fcoe_process_vlan_resp(struct fnic *fnic, struct sk_buff *skb) 389d3c995f1SHiral Patel { 390d3c995f1SHiral Patel struct fcoe_ctlr *fip = &fnic->ctlr; 391d3c995f1SHiral Patel struct fip_header *fiph; 392d3c995f1SHiral Patel struct fip_desc *desc; 39367125b02SHiral Patel struct fnic_stats *fnic_stats = &fnic->fnic_stats; 394d3c995f1SHiral Patel u16 vid; 395d3c995f1SHiral Patel size_t rlen; 396d3c995f1SHiral Patel size_t dlen; 397d3c995f1SHiral Patel struct fcoe_vlan *vlan; 398d3c995f1SHiral Patel u64 sol_time; 399d3c995f1SHiral Patel unsigned long flags; 400d3c995f1SHiral Patel 401d3c995f1SHiral Patel FNIC_FCS_DBG(KERN_INFO, fnic->lport->host, 402d3c995f1SHiral Patel "Received VLAN response...\n"); 403d3c995f1SHiral Patel 404d3c995f1SHiral Patel fiph = (struct fip_header *) skb->data; 405d3c995f1SHiral Patel 406d3c995f1SHiral Patel FNIC_FCS_DBG(KERN_INFO, fnic->lport->host, 407d3c995f1SHiral Patel "Received VLAN response... OP 0x%x SUB_OP 0x%x\n", 408d3c995f1SHiral Patel ntohs(fiph->fip_op), fiph->fip_subcode); 409d3c995f1SHiral Patel 410d3c995f1SHiral Patel rlen = ntohs(fiph->fip_dl_len) * 4; 411d3c995f1SHiral Patel fnic_fcoe_reset_vlans(fnic); 412d3c995f1SHiral Patel spin_lock_irqsave(&fnic->vlans_lock, flags); 413d3c995f1SHiral Patel desc = (struct fip_desc *)(fiph + 1); 414d3c995f1SHiral Patel while (rlen > 0) { 415d3c995f1SHiral Patel dlen = desc->fip_dlen * FIP_BPW; 416d3c995f1SHiral Patel switch (desc->fip_dtype) { 417d3c995f1SHiral Patel case FIP_DT_VLAN: 418d3c995f1SHiral Patel vid = ntohs(((struct fip_vlan_desc *)desc)->fd_vlan); 419d3c995f1SHiral Patel shost_printk(KERN_INFO, fnic->lport->host, 420d3c995f1SHiral Patel "process_vlan_resp: FIP VLAN %d\n", vid); 421d3c995f1SHiral Patel vlan = kmalloc(sizeof(*vlan), 422d3c995f1SHiral Patel GFP_ATOMIC); 423d3c995f1SHiral Patel if (!vlan) { 424d3c995f1SHiral Patel /* retry from timer */ 425d3c995f1SHiral Patel spin_unlock_irqrestore(&fnic->vlans_lock, 426d3c995f1SHiral Patel flags); 427d3c995f1SHiral Patel goto out; 428d3c995f1SHiral Patel } 429d3c995f1SHiral Patel memset(vlan, 0, sizeof(struct fcoe_vlan)); 430d3c995f1SHiral Patel vlan->vid = vid & 0x0fff; 431d3c995f1SHiral Patel vlan->state = FIP_VLAN_AVAIL; 432d3c995f1SHiral Patel list_add_tail(&vlan->list, &fnic->vlans); 433d3c995f1SHiral Patel break; 434d3c995f1SHiral Patel } 435d3c995f1SHiral Patel desc = (struct fip_desc *)((char *)desc + dlen); 436d3c995f1SHiral Patel rlen -= dlen; 437d3c995f1SHiral Patel } 438d3c995f1SHiral Patel 439d3c995f1SHiral Patel /* any VLAN descriptors present ? */ 440d3c995f1SHiral Patel if (list_empty(&fnic->vlans)) { 441d3c995f1SHiral Patel /* retry from timer */ 44267125b02SHiral Patel atomic64_inc(&fnic_stats->vlan_stats.resp_withno_vlanID); 443d3c995f1SHiral Patel FNIC_FCS_DBG(KERN_INFO, fnic->lport->host, 444d3c995f1SHiral Patel "No VLAN descriptors in FIP VLAN response\n"); 445d3c995f1SHiral Patel spin_unlock_irqrestore(&fnic->vlans_lock, flags); 446d3c995f1SHiral Patel goto out; 447d3c995f1SHiral Patel } 448d3c995f1SHiral Patel 449d3c995f1SHiral Patel vlan = list_first_entry(&fnic->vlans, struct fcoe_vlan, list); 450d3c995f1SHiral Patel fnic->set_vlan(fnic, vlan->vid); 451d3c995f1SHiral Patel vlan->state = FIP_VLAN_SENT; /* sent now */ 452d3c995f1SHiral Patel vlan->sol_count++; 453d3c995f1SHiral Patel spin_unlock_irqrestore(&fnic->vlans_lock, flags); 454d3c995f1SHiral Patel 455d3c995f1SHiral Patel /* start the solicitation */ 456d3c995f1SHiral Patel fcoe_ctlr_link_up(fip); 457d3c995f1SHiral Patel 458d3c995f1SHiral Patel sol_time = jiffies + msecs_to_jiffies(FCOE_CTLR_START_DELAY); 459d3c995f1SHiral Patel mod_timer(&fnic->fip_timer, round_jiffies(sol_time)); 460d3c995f1SHiral Patel out: 461d3c995f1SHiral Patel return; 462d3c995f1SHiral Patel } 463d3c995f1SHiral Patel 464d3c995f1SHiral Patel static void fnic_fcoe_start_fcf_disc(struct fnic *fnic) 465d3c995f1SHiral Patel { 466d3c995f1SHiral Patel unsigned long flags; 467d3c995f1SHiral Patel struct fcoe_vlan *vlan; 468d3c995f1SHiral Patel u64 sol_time; 469d3c995f1SHiral Patel 470d3c995f1SHiral Patel spin_lock_irqsave(&fnic->vlans_lock, flags); 471d3c995f1SHiral Patel vlan = list_first_entry(&fnic->vlans, struct fcoe_vlan, list); 472d3c995f1SHiral Patel fnic->set_vlan(fnic, vlan->vid); 473d3c995f1SHiral Patel vlan->state = FIP_VLAN_SENT; /* sent now */ 474d3c995f1SHiral Patel vlan->sol_count = 1; 475d3c995f1SHiral Patel spin_unlock_irqrestore(&fnic->vlans_lock, flags); 476d3c995f1SHiral Patel 477d3c995f1SHiral Patel /* start the solicitation */ 478d3c995f1SHiral Patel fcoe_ctlr_link_up(&fnic->ctlr); 479d3c995f1SHiral Patel 480d3c995f1SHiral Patel sol_time = jiffies + msecs_to_jiffies(FCOE_CTLR_START_DELAY); 481d3c995f1SHiral Patel mod_timer(&fnic->fip_timer, round_jiffies(sol_time)); 482d3c995f1SHiral Patel } 483d3c995f1SHiral Patel 484d3c995f1SHiral Patel static int fnic_fcoe_vlan_check(struct fnic *fnic, u16 flag) 485d3c995f1SHiral Patel { 486d3c995f1SHiral Patel unsigned long flags; 487d3c995f1SHiral Patel struct fcoe_vlan *fvlan; 488d3c995f1SHiral Patel 489d3c995f1SHiral Patel spin_lock_irqsave(&fnic->vlans_lock, flags); 490d3c995f1SHiral Patel if (list_empty(&fnic->vlans)) { 491d3c995f1SHiral Patel spin_unlock_irqrestore(&fnic->vlans_lock, flags); 492d3c995f1SHiral Patel return -EINVAL; 493d3c995f1SHiral Patel } 494d3c995f1SHiral Patel 495d3c995f1SHiral Patel fvlan = list_first_entry(&fnic->vlans, struct fcoe_vlan, list); 496d3c995f1SHiral Patel if (fvlan->state == FIP_VLAN_USED) { 497d3c995f1SHiral Patel spin_unlock_irqrestore(&fnic->vlans_lock, flags); 498d3c995f1SHiral Patel return 0; 499d3c995f1SHiral Patel } 500d3c995f1SHiral Patel 501d3c995f1SHiral Patel if (fvlan->state == FIP_VLAN_SENT) { 502d3c995f1SHiral Patel fvlan->state = FIP_VLAN_USED; 503d3c995f1SHiral Patel spin_unlock_irqrestore(&fnic->vlans_lock, flags); 504d3c995f1SHiral Patel return 0; 505d3c995f1SHiral Patel } 506d3c995f1SHiral Patel spin_unlock_irqrestore(&fnic->vlans_lock, flags); 507d3c995f1SHiral Patel return -EINVAL; 508d3c995f1SHiral Patel } 509d3c995f1SHiral Patel 510d3c995f1SHiral Patel static void fnic_event_enq(struct fnic *fnic, enum fnic_evt ev) 511d3c995f1SHiral Patel { 512d3c995f1SHiral Patel struct fnic_event *fevt; 513d3c995f1SHiral Patel unsigned long flags; 514d3c995f1SHiral Patel 515d3c995f1SHiral Patel fevt = kmalloc(sizeof(*fevt), GFP_ATOMIC); 516d3c995f1SHiral Patel if (!fevt) 517d3c995f1SHiral Patel return; 518d3c995f1SHiral Patel 519d3c995f1SHiral Patel fevt->fnic = fnic; 520d3c995f1SHiral Patel fevt->event = ev; 521d3c995f1SHiral Patel 522d3c995f1SHiral Patel spin_lock_irqsave(&fnic->fnic_lock, flags); 523d3c995f1SHiral Patel list_add_tail(&fevt->list, &fnic->evlist); 524d3c995f1SHiral Patel spin_unlock_irqrestore(&fnic->fnic_lock, flags); 525d3c995f1SHiral Patel 526d3c995f1SHiral Patel schedule_work(&fnic->event_work); 527d3c995f1SHiral Patel } 528d3c995f1SHiral Patel 529d3c995f1SHiral Patel static int fnic_fcoe_handle_fip_frame(struct fnic *fnic, struct sk_buff *skb) 530d3c995f1SHiral Patel { 531d3c995f1SHiral Patel struct fip_header *fiph; 532d3c995f1SHiral Patel int ret = 1; 533d3c995f1SHiral Patel u16 op; 534d3c995f1SHiral Patel u8 sub; 535d3c995f1SHiral Patel 536d3c995f1SHiral Patel if (!skb || !(skb->data)) 537d3c995f1SHiral Patel return -1; 538d3c995f1SHiral Patel 539d3c995f1SHiral Patel if (skb_linearize(skb)) 540d3c995f1SHiral Patel goto drop; 541d3c995f1SHiral Patel 542d3c995f1SHiral Patel fiph = (struct fip_header *)skb->data; 543d3c995f1SHiral Patel op = ntohs(fiph->fip_op); 544d3c995f1SHiral Patel sub = fiph->fip_subcode; 545d3c995f1SHiral Patel 546d3c995f1SHiral Patel if (FIP_VER_DECAPS(fiph->fip_ver) != FIP_VER) 547d3c995f1SHiral Patel goto drop; 548d3c995f1SHiral Patel 549d3c995f1SHiral Patel if (ntohs(fiph->fip_dl_len) * FIP_BPW + sizeof(*fiph) > skb->len) 550d3c995f1SHiral Patel goto drop; 551d3c995f1SHiral Patel 552d3c995f1SHiral Patel if (op == FIP_OP_DISC && sub == FIP_SC_ADV) { 553d3c995f1SHiral Patel if (fnic_fcoe_vlan_check(fnic, ntohs(fiph->fip_flags))) 554d3c995f1SHiral Patel goto drop; 555d3c995f1SHiral Patel /* pass it on to fcoe */ 556d3c995f1SHiral Patel ret = 1; 5576a551c11SHannes Reinecke } else if (op == FIP_OP_VLAN && sub == FIP_SC_VL_NOTE) { 558d3c995f1SHiral Patel /* set the vlan as used */ 559d3c995f1SHiral Patel fnic_fcoe_process_vlan_resp(fnic, skb); 560d3c995f1SHiral Patel ret = 0; 561d3c995f1SHiral Patel } else if (op == FIP_OP_CTRL && sub == FIP_SC_CLR_VLINK) { 562d3c995f1SHiral Patel /* received CVL request, restart vlan disc */ 563d3c995f1SHiral Patel fnic_event_enq(fnic, FNIC_EVT_START_VLAN_DISC); 564d3c995f1SHiral Patel /* pass it on to fcoe */ 565d3c995f1SHiral Patel ret = 1; 566d3c995f1SHiral Patel } 567d3c995f1SHiral Patel drop: 568d3c995f1SHiral Patel return ret; 569d3c995f1SHiral Patel } 570d3c995f1SHiral Patel 571d3c995f1SHiral Patel void fnic_handle_fip_frame(struct work_struct *work) 572d3c995f1SHiral Patel { 573d3c995f1SHiral Patel struct fnic *fnic = container_of(work, struct fnic, fip_frame_work); 57467125b02SHiral Patel struct fnic_stats *fnic_stats = &fnic->fnic_stats; 575d3c995f1SHiral Patel unsigned long flags; 576d3c995f1SHiral Patel struct sk_buff *skb; 577d3c995f1SHiral Patel struct ethhdr *eh; 578d3c995f1SHiral Patel 579d3c995f1SHiral Patel while ((skb = skb_dequeue(&fnic->fip_frame_queue))) { 580d3c995f1SHiral Patel spin_lock_irqsave(&fnic->fnic_lock, flags); 581d3c995f1SHiral Patel if (fnic->stop_rx_link_events) { 582d3c995f1SHiral Patel spin_unlock_irqrestore(&fnic->fnic_lock, flags); 583d3c995f1SHiral Patel dev_kfree_skb(skb); 584d3c995f1SHiral Patel return; 585d3c995f1SHiral Patel } 586d3c995f1SHiral Patel /* 587d3c995f1SHiral Patel * If we're in a transitional state, just re-queue and return. 588d3c995f1SHiral Patel * The queue will be serviced when we get to a stable state. 589d3c995f1SHiral Patel */ 590d3c995f1SHiral Patel if (fnic->state != FNIC_IN_FC_MODE && 591d3c995f1SHiral Patel fnic->state != FNIC_IN_ETH_MODE) { 592d3c995f1SHiral Patel skb_queue_head(&fnic->fip_frame_queue, skb); 593d3c995f1SHiral Patel spin_unlock_irqrestore(&fnic->fnic_lock, flags); 594d3c995f1SHiral Patel return; 595d3c995f1SHiral Patel } 596d3c995f1SHiral Patel spin_unlock_irqrestore(&fnic->fnic_lock, flags); 597d3c995f1SHiral Patel eh = (struct ethhdr *)skb->data; 598d3c995f1SHiral Patel if (eh->h_proto == htons(ETH_P_FIP)) { 599d3c995f1SHiral Patel skb_pull(skb, sizeof(*eh)); 600d3c995f1SHiral Patel if (fnic_fcoe_handle_fip_frame(fnic, skb) <= 0) { 601d3c995f1SHiral Patel dev_kfree_skb(skb); 602d3c995f1SHiral Patel continue; 603d3c995f1SHiral Patel } 604d3c995f1SHiral Patel /* 605d3c995f1SHiral Patel * If there's FLOGI rejects - clear all 606d3c995f1SHiral Patel * fcf's & restart from scratch 607d3c995f1SHiral Patel */ 608d3c995f1SHiral Patel if (is_fnic_fip_flogi_reject(&fnic->ctlr, skb)) { 60967125b02SHiral Patel atomic64_inc( 61067125b02SHiral Patel &fnic_stats->vlan_stats.flogi_rejects); 611d3c995f1SHiral Patel shost_printk(KERN_INFO, fnic->lport->host, 612d3c995f1SHiral Patel "Trigger a Link down - VLAN Disc\n"); 613d3c995f1SHiral Patel fcoe_ctlr_link_down(&fnic->ctlr); 614d3c995f1SHiral Patel /* start FCoE VLAN discovery */ 615d3c995f1SHiral Patel fnic_fcoe_send_vlan_req(fnic); 616d3c995f1SHiral Patel dev_kfree_skb(skb); 617d3c995f1SHiral Patel continue; 618d3c995f1SHiral Patel } 619d3c995f1SHiral Patel fcoe_ctlr_recv(&fnic->ctlr, skb); 620d3c995f1SHiral Patel continue; 621d3c995f1SHiral Patel } 622d3c995f1SHiral Patel } 623d3c995f1SHiral Patel } 624d3c995f1SHiral Patel 62578112e55SJoe Eykholt /** 62678112e55SJoe Eykholt * fnic_import_rq_eth_pkt() - handle received FCoE or FIP frame. 62778112e55SJoe Eykholt * @fnic: fnic instance. 62878112e55SJoe Eykholt * @skb: Ethernet Frame. 62978112e55SJoe Eykholt */ 63078112e55SJoe Eykholt static inline int fnic_import_rq_eth_pkt(struct fnic *fnic, struct sk_buff *skb) 6315df6d737SAbhijeet Joglekar { 6325df6d737SAbhijeet Joglekar struct fc_frame *fp; 6335df6d737SAbhijeet Joglekar struct ethhdr *eh; 6345df6d737SAbhijeet Joglekar struct fcoe_hdr *fcoe_hdr; 6355df6d737SAbhijeet Joglekar struct fcoe_crc_eof *ft; 6365df6d737SAbhijeet Joglekar 63778112e55SJoe Eykholt /* 63878112e55SJoe Eykholt * Undo VLAN encapsulation if present. 63978112e55SJoe Eykholt */ 6405df6d737SAbhijeet Joglekar eh = (struct ethhdr *)skb->data; 64178112e55SJoe Eykholt if (eh->h_proto == htons(ETH_P_8021Q)) { 64278112e55SJoe Eykholt memmove((u8 *)eh + VLAN_HLEN, eh, ETH_ALEN * 2); 643*af72868bSJohannes Berg eh = skb_pull(skb, VLAN_HLEN); 64478112e55SJoe Eykholt skb_reset_mac_header(skb); 64578112e55SJoe Eykholt } 64678112e55SJoe Eykholt if (eh->h_proto == htons(ETH_P_FIP)) { 647d7fadce3SHiral Patel if (!(fnic->config.flags & VFCF_FIP_CAPABLE)) { 648d7fadce3SHiral Patel printk(KERN_ERR "Dropped FIP frame, as firmware " 649d7fadce3SHiral Patel "uses non-FIP mode, Enable FIP " 650d7fadce3SHiral Patel "using UCSM\n"); 651d7fadce3SHiral Patel goto drop; 652d7fadce3SHiral Patel } 653abb14148SHiral Shah if ((fnic_fc_trace_set_data(fnic->lport->host->host_no, 654abb14148SHiral Shah FNIC_FC_RECV|0x80, (char *)skb->data, skb->len)) != 0) { 655abb14148SHiral Shah printk(KERN_ERR "fnic ctlr frame trace error!!!"); 656abb14148SHiral Shah } 657d3c995f1SHiral Patel skb_queue_tail(&fnic->fip_frame_queue, skb); 658d3c995f1SHiral Patel queue_work(fnic_fip_queue, &fnic->fip_frame_work); 65978112e55SJoe Eykholt return 1; /* let caller know packet was used */ 66078112e55SJoe Eykholt } 66178112e55SJoe Eykholt if (eh->h_proto != htons(ETH_P_FCOE)) 66278112e55SJoe Eykholt goto drop; 66378112e55SJoe Eykholt skb_set_network_header(skb, sizeof(*eh)); 66478112e55SJoe Eykholt skb_pull(skb, sizeof(*eh)); 6655df6d737SAbhijeet Joglekar 6665df6d737SAbhijeet Joglekar fcoe_hdr = (struct fcoe_hdr *)skb->data; 6675df6d737SAbhijeet Joglekar if (FC_FCOE_DECAPS_VER(fcoe_hdr) != FC_FCOE_VER) 66878112e55SJoe Eykholt goto drop; 6695df6d737SAbhijeet Joglekar 6705df6d737SAbhijeet Joglekar fp = (struct fc_frame *)skb; 6715df6d737SAbhijeet Joglekar fc_frame_init(fp); 6725df6d737SAbhijeet Joglekar fr_sof(fp) = fcoe_hdr->fcoe_sof; 6735df6d737SAbhijeet Joglekar skb_pull(skb, sizeof(struct fcoe_hdr)); 67478112e55SJoe Eykholt skb_reset_transport_header(skb); 6755df6d737SAbhijeet Joglekar 67678112e55SJoe Eykholt ft = (struct fcoe_crc_eof *)(skb->data + skb->len - sizeof(*ft)); 6775df6d737SAbhijeet Joglekar fr_eof(fp) = ft->fcoe_eof; 67878112e55SJoe Eykholt skb_trim(skb, skb->len - sizeof(*ft)); 6795df6d737SAbhijeet Joglekar return 0; 68078112e55SJoe Eykholt drop: 68178112e55SJoe Eykholt dev_kfree_skb_irq(skb); 68278112e55SJoe Eykholt return -1; 6835df6d737SAbhijeet Joglekar } 6845df6d737SAbhijeet Joglekar 68578112e55SJoe Eykholt /** 68678112e55SJoe Eykholt * fnic_update_mac_locked() - set data MAC address and filters. 68778112e55SJoe Eykholt * @fnic: fnic instance. 68878112e55SJoe Eykholt * @new: newly-assigned FCoE MAC address. 68978112e55SJoe Eykholt * 69078112e55SJoe Eykholt * Called with the fnic lock held. 69178112e55SJoe Eykholt */ 69278112e55SJoe Eykholt void fnic_update_mac_locked(struct fnic *fnic, u8 *new) 6935df6d737SAbhijeet Joglekar { 69478112e55SJoe Eykholt u8 *ctl = fnic->ctlr.ctl_src_addr; 69578112e55SJoe Eykholt u8 *data = fnic->data_src_addr; 6965df6d737SAbhijeet Joglekar 69778112e55SJoe Eykholt if (is_zero_ether_addr(new)) 69878112e55SJoe Eykholt new = ctl; 6996942df7fSJoe Perches if (ether_addr_equal(data, new)) 70078112e55SJoe Eykholt return; 70178112e55SJoe Eykholt FNIC_FCS_DBG(KERN_DEBUG, fnic->lport->host, "update_mac %pM\n", new); 7026942df7fSJoe Perches if (!is_zero_ether_addr(data) && !ether_addr_equal(data, ctl)) 70378112e55SJoe Eykholt vnic_dev_del_addr(fnic->vdev, data); 70478112e55SJoe Eykholt memcpy(data, new, ETH_ALEN); 7056942df7fSJoe Perches if (!ether_addr_equal(new, ctl)) 70678112e55SJoe Eykholt vnic_dev_add_addr(fnic->vdev, new); 7075df6d737SAbhijeet Joglekar } 7085df6d737SAbhijeet Joglekar 70978112e55SJoe Eykholt /** 71078112e55SJoe Eykholt * fnic_update_mac() - set data MAC address and filters. 71178112e55SJoe Eykholt * @lport: local port. 71278112e55SJoe Eykholt * @new: newly-assigned FCoE MAC address. 7135df6d737SAbhijeet Joglekar */ 71478112e55SJoe Eykholt void fnic_update_mac(struct fc_lport *lport, u8 *new) 71578112e55SJoe Eykholt { 71678112e55SJoe Eykholt struct fnic *fnic = lport_priv(lport); 7175df6d737SAbhijeet Joglekar 71878112e55SJoe Eykholt spin_lock_irq(&fnic->fnic_lock); 71978112e55SJoe Eykholt fnic_update_mac_locked(fnic, new); 72078112e55SJoe Eykholt spin_unlock_irq(&fnic->fnic_lock); 7215df6d737SAbhijeet Joglekar } 7225df6d737SAbhijeet Joglekar 72378112e55SJoe Eykholt /** 72478112e55SJoe Eykholt * fnic_set_port_id() - set the port_ID after successful FLOGI. 72578112e55SJoe Eykholt * @lport: local port. 72678112e55SJoe Eykholt * @port_id: assigned FC_ID. 72778112e55SJoe Eykholt * @fp: received frame containing the FLOGI accept or NULL. 72878112e55SJoe Eykholt * 72978112e55SJoe Eykholt * This is called from libfc when a new FC_ID has been assigned. 73078112e55SJoe Eykholt * This causes us to reset the firmware to FC_MODE and setup the new MAC 73178112e55SJoe Eykholt * address and FC_ID. 73278112e55SJoe Eykholt * 73378112e55SJoe Eykholt * It is also called with FC_ID 0 when we're logged off. 73478112e55SJoe Eykholt * 73578112e55SJoe Eykholt * If the FC_ID is due to point-to-point, fp may be NULL. 7365df6d737SAbhijeet Joglekar */ 73778112e55SJoe Eykholt void fnic_set_port_id(struct fc_lport *lport, u32 port_id, struct fc_frame *fp) 73878112e55SJoe Eykholt { 73978112e55SJoe Eykholt struct fnic *fnic = lport_priv(lport); 74078112e55SJoe Eykholt u8 *mac; 74178112e55SJoe Eykholt int ret; 7425df6d737SAbhijeet Joglekar 74378112e55SJoe Eykholt FNIC_FCS_DBG(KERN_DEBUG, lport->host, "set port_id %x fp %p\n", 74478112e55SJoe Eykholt port_id, fp); 7455df6d737SAbhijeet Joglekar 74678112e55SJoe Eykholt /* 74778112e55SJoe Eykholt * If we're clearing the FC_ID, change to use the ctl_src_addr. 74878112e55SJoe Eykholt * Set ethernet mode to send FLOGI. 74978112e55SJoe Eykholt */ 75078112e55SJoe Eykholt if (!port_id) { 75178112e55SJoe Eykholt fnic_update_mac(lport, fnic->ctlr.ctl_src_addr); 75278112e55SJoe Eykholt fnic_set_eth_mode(fnic); 75378112e55SJoe Eykholt return; 75478112e55SJoe Eykholt } 75578112e55SJoe Eykholt 75678112e55SJoe Eykholt if (fp) { 75778112e55SJoe Eykholt mac = fr_cb(fp)->granted_mac; 75878112e55SJoe Eykholt if (is_zero_ether_addr(mac)) { 75978112e55SJoe Eykholt /* non-FIP - FLOGI already accepted - ignore return */ 76078112e55SJoe Eykholt fcoe_ctlr_recv_flogi(&fnic->ctlr, lport, fp); 76178112e55SJoe Eykholt } 76278112e55SJoe Eykholt fnic_update_mac(lport, mac); 76378112e55SJoe Eykholt } 76478112e55SJoe Eykholt 76578112e55SJoe Eykholt /* Change state to reflect transition to FC mode */ 76678112e55SJoe Eykholt spin_lock_irq(&fnic->fnic_lock); 76778112e55SJoe Eykholt if (fnic->state == FNIC_IN_ETH_MODE || fnic->state == FNIC_IN_FC_MODE) 7685df6d737SAbhijeet Joglekar fnic->state = FNIC_IN_ETH_TRANS_FC_MODE; 76978112e55SJoe Eykholt else { 7705df6d737SAbhijeet Joglekar FNIC_FCS_DBG(KERN_DEBUG, fnic->lport->host, 7715df6d737SAbhijeet Joglekar "Unexpected fnic state %s while" 7725df6d737SAbhijeet Joglekar " processing flogi resp\n", 7735df6d737SAbhijeet Joglekar fnic_state_to_str(fnic->state)); 77478112e55SJoe Eykholt spin_unlock_irq(&fnic->fnic_lock); 77578112e55SJoe Eykholt return; 7765df6d737SAbhijeet Joglekar } 77778112e55SJoe Eykholt spin_unlock_irq(&fnic->fnic_lock); 7785df6d737SAbhijeet Joglekar 7795df6d737SAbhijeet Joglekar /* 78078112e55SJoe Eykholt * Send FLOGI registration to firmware to set up FC mode. 78178112e55SJoe Eykholt * The new address will be set up when registration completes. 7825df6d737SAbhijeet Joglekar */ 78378112e55SJoe Eykholt ret = fnic_flogi_reg_handler(fnic, port_id); 7845df6d737SAbhijeet Joglekar 7855df6d737SAbhijeet Joglekar if (ret < 0) { 78678112e55SJoe Eykholt spin_lock_irq(&fnic->fnic_lock); 7875df6d737SAbhijeet Joglekar if (fnic->state == FNIC_IN_ETH_TRANS_FC_MODE) 7885df6d737SAbhijeet Joglekar fnic->state = FNIC_IN_ETH_MODE; 78978112e55SJoe Eykholt spin_unlock_irq(&fnic->fnic_lock); 7905df6d737SAbhijeet Joglekar } 7915df6d737SAbhijeet Joglekar } 7925df6d737SAbhijeet Joglekar 7935df6d737SAbhijeet Joglekar static void fnic_rq_cmpl_frame_recv(struct vnic_rq *rq, struct cq_desc 7945df6d737SAbhijeet Joglekar *cq_desc, struct vnic_rq_buf *buf, 7955df6d737SAbhijeet Joglekar int skipped __attribute__((unused)), 7965df6d737SAbhijeet Joglekar void *opaque) 7975df6d737SAbhijeet Joglekar { 7985df6d737SAbhijeet Joglekar struct fnic *fnic = vnic_dev_priv(rq->vdev); 7995df6d737SAbhijeet Joglekar struct sk_buff *skb; 8005df6d737SAbhijeet Joglekar struct fc_frame *fp; 80167125b02SHiral Patel struct fnic_stats *fnic_stats = &fnic->fnic_stats; 8025df6d737SAbhijeet Joglekar unsigned int eth_hdrs_stripped; 8035df6d737SAbhijeet Joglekar u8 type, color, eop, sop, ingress_port, vlan_stripped; 8045df6d737SAbhijeet Joglekar u8 fcoe = 0, fcoe_sof, fcoe_eof; 8055df6d737SAbhijeet Joglekar u8 fcoe_fc_crc_ok = 1, fcoe_enc_error = 0; 8065df6d737SAbhijeet Joglekar u8 tcp_udp_csum_ok, udp, tcp, ipv4_csum_ok; 8075df6d737SAbhijeet Joglekar u8 ipv6, ipv4, ipv4_fragment, rss_type, csum_not_calc; 8085df6d737SAbhijeet Joglekar u8 fcs_ok = 1, packet_error = 0; 8095df6d737SAbhijeet Joglekar u16 q_number, completed_index, bytes_written = 0, vlan, checksum; 8105df6d737SAbhijeet Joglekar u32 rss_hash; 8115df6d737SAbhijeet Joglekar u16 exchange_id, tmpl; 8125df6d737SAbhijeet Joglekar u8 sof = 0; 8135df6d737SAbhijeet Joglekar u8 eof = 0; 8145df6d737SAbhijeet Joglekar u32 fcp_bytes_written = 0; 8155df6d737SAbhijeet Joglekar unsigned long flags; 8165df6d737SAbhijeet Joglekar 8175df6d737SAbhijeet Joglekar pci_unmap_single(fnic->pdev, buf->dma_addr, buf->len, 8185df6d737SAbhijeet Joglekar PCI_DMA_FROMDEVICE); 8195df6d737SAbhijeet Joglekar skb = buf->os_buf; 82078112e55SJoe Eykholt fp = (struct fc_frame *)skb; 8215df6d737SAbhijeet Joglekar buf->os_buf = NULL; 8225df6d737SAbhijeet Joglekar 8235df6d737SAbhijeet Joglekar cq_desc_dec(cq_desc, &type, &color, &q_number, &completed_index); 8245df6d737SAbhijeet Joglekar if (type == CQ_DESC_TYPE_RQ_FCP) { 8255df6d737SAbhijeet Joglekar cq_fcp_rq_desc_dec((struct cq_fcp_rq_desc *)cq_desc, 8265df6d737SAbhijeet Joglekar &type, &color, &q_number, &completed_index, 8275df6d737SAbhijeet Joglekar &eop, &sop, &fcoe_fc_crc_ok, &exchange_id, 8285df6d737SAbhijeet Joglekar &tmpl, &fcp_bytes_written, &sof, &eof, 8295df6d737SAbhijeet Joglekar &ingress_port, &packet_error, 8305df6d737SAbhijeet Joglekar &fcoe_enc_error, &fcs_ok, &vlan_stripped, 8315df6d737SAbhijeet Joglekar &vlan); 8325df6d737SAbhijeet Joglekar eth_hdrs_stripped = 1; 83378112e55SJoe Eykholt skb_trim(skb, fcp_bytes_written); 83478112e55SJoe Eykholt fr_sof(fp) = sof; 83578112e55SJoe Eykholt fr_eof(fp) = eof; 8365df6d737SAbhijeet Joglekar 8375df6d737SAbhijeet Joglekar } else if (type == CQ_DESC_TYPE_RQ_ENET) { 8385df6d737SAbhijeet Joglekar cq_enet_rq_desc_dec((struct cq_enet_rq_desc *)cq_desc, 8395df6d737SAbhijeet Joglekar &type, &color, &q_number, &completed_index, 8405df6d737SAbhijeet Joglekar &ingress_port, &fcoe, &eop, &sop, 8415df6d737SAbhijeet Joglekar &rss_type, &csum_not_calc, &rss_hash, 8425df6d737SAbhijeet Joglekar &bytes_written, &packet_error, 8435df6d737SAbhijeet Joglekar &vlan_stripped, &vlan, &checksum, 8445df6d737SAbhijeet Joglekar &fcoe_sof, &fcoe_fc_crc_ok, 8455df6d737SAbhijeet Joglekar &fcoe_enc_error, &fcoe_eof, 8465df6d737SAbhijeet Joglekar &tcp_udp_csum_ok, &udp, &tcp, 8475df6d737SAbhijeet Joglekar &ipv4_csum_ok, &ipv6, &ipv4, 8485df6d737SAbhijeet Joglekar &ipv4_fragment, &fcs_ok); 8495df6d737SAbhijeet Joglekar eth_hdrs_stripped = 0; 85078112e55SJoe Eykholt skb_trim(skb, bytes_written); 85178112e55SJoe Eykholt if (!fcs_ok) { 85267125b02SHiral Patel atomic64_inc(&fnic_stats->misc_stats.frame_errors); 85378112e55SJoe Eykholt FNIC_FCS_DBG(KERN_DEBUG, fnic->lport->host, 85478112e55SJoe Eykholt "fcs error. dropping packet.\n"); 85578112e55SJoe Eykholt goto drop; 85678112e55SJoe Eykholt } 85778112e55SJoe Eykholt if (fnic_import_rq_eth_pkt(fnic, skb)) 85878112e55SJoe Eykholt return; 8595df6d737SAbhijeet Joglekar 8605df6d737SAbhijeet Joglekar } else { 8615df6d737SAbhijeet Joglekar /* wrong CQ type*/ 8625df6d737SAbhijeet Joglekar shost_printk(KERN_ERR, fnic->lport->host, 8635df6d737SAbhijeet Joglekar "fnic rq_cmpl wrong cq type x%x\n", type); 8645df6d737SAbhijeet Joglekar goto drop; 8655df6d737SAbhijeet Joglekar } 8665df6d737SAbhijeet Joglekar 8675df6d737SAbhijeet Joglekar if (!fcs_ok || packet_error || !fcoe_fc_crc_ok || fcoe_enc_error) { 86867125b02SHiral Patel atomic64_inc(&fnic_stats->misc_stats.frame_errors); 8695df6d737SAbhijeet Joglekar FNIC_FCS_DBG(KERN_DEBUG, fnic->lport->host, 8705df6d737SAbhijeet Joglekar "fnic rq_cmpl fcoe x%x fcsok x%x" 8715df6d737SAbhijeet Joglekar " pkterr x%x fcoe_fc_crc_ok x%x, fcoe_enc_err" 8725df6d737SAbhijeet Joglekar " x%x\n", 8735df6d737SAbhijeet Joglekar fcoe, fcs_ok, packet_error, 8745df6d737SAbhijeet Joglekar fcoe_fc_crc_ok, fcoe_enc_error); 8755df6d737SAbhijeet Joglekar goto drop; 8765df6d737SAbhijeet Joglekar } 8775df6d737SAbhijeet Joglekar 8785df6d737SAbhijeet Joglekar spin_lock_irqsave(&fnic->fnic_lock, flags); 8795df6d737SAbhijeet Joglekar if (fnic->stop_rx_link_events) { 8805df6d737SAbhijeet Joglekar spin_unlock_irqrestore(&fnic->fnic_lock, flags); 8815df6d737SAbhijeet Joglekar goto drop; 8825df6d737SAbhijeet Joglekar } 8835df6d737SAbhijeet Joglekar fr_dev(fp) = fnic->lport; 8845df6d737SAbhijeet Joglekar spin_unlock_irqrestore(&fnic->fnic_lock, flags); 885abb14148SHiral Shah if ((fnic_fc_trace_set_data(fnic->lport->host->host_no, FNIC_FC_RECV, 886abb14148SHiral Shah (char *)skb->data, skb->len)) != 0) { 887abb14148SHiral Shah printk(KERN_ERR "fnic ctlr frame trace error!!!"); 888abb14148SHiral Shah } 8895df6d737SAbhijeet Joglekar 8905df6d737SAbhijeet Joglekar skb_queue_tail(&fnic->frame_queue, skb); 8915df6d737SAbhijeet Joglekar queue_work(fnic_event_queue, &fnic->frame_work); 8925df6d737SAbhijeet Joglekar 8935df6d737SAbhijeet Joglekar return; 8945df6d737SAbhijeet Joglekar drop: 8955df6d737SAbhijeet Joglekar dev_kfree_skb_irq(skb); 8965df6d737SAbhijeet Joglekar } 8975df6d737SAbhijeet Joglekar 8985df6d737SAbhijeet Joglekar static int fnic_rq_cmpl_handler_cont(struct vnic_dev *vdev, 8995df6d737SAbhijeet Joglekar struct cq_desc *cq_desc, u8 type, 9005df6d737SAbhijeet Joglekar u16 q_number, u16 completed_index, 9015df6d737SAbhijeet Joglekar void *opaque) 9025df6d737SAbhijeet Joglekar { 9035df6d737SAbhijeet Joglekar struct fnic *fnic = vnic_dev_priv(vdev); 9045df6d737SAbhijeet Joglekar 9055df6d737SAbhijeet Joglekar vnic_rq_service(&fnic->rq[q_number], cq_desc, completed_index, 9065df6d737SAbhijeet Joglekar VNIC_RQ_RETURN_DESC, fnic_rq_cmpl_frame_recv, 9075df6d737SAbhijeet Joglekar NULL); 9085df6d737SAbhijeet Joglekar return 0; 9095df6d737SAbhijeet Joglekar } 9105df6d737SAbhijeet Joglekar 9115df6d737SAbhijeet Joglekar int fnic_rq_cmpl_handler(struct fnic *fnic, int rq_work_to_do) 9125df6d737SAbhijeet Joglekar { 9135df6d737SAbhijeet Joglekar unsigned int tot_rq_work_done = 0, cur_work_done; 9145df6d737SAbhijeet Joglekar unsigned int i; 9155df6d737SAbhijeet Joglekar int err; 9165df6d737SAbhijeet Joglekar 9175df6d737SAbhijeet Joglekar for (i = 0; i < fnic->rq_count; i++) { 9185df6d737SAbhijeet Joglekar cur_work_done = vnic_cq_service(&fnic->cq[i], rq_work_to_do, 9195df6d737SAbhijeet Joglekar fnic_rq_cmpl_handler_cont, 9205df6d737SAbhijeet Joglekar NULL); 9215df6d737SAbhijeet Joglekar if (cur_work_done) { 9225df6d737SAbhijeet Joglekar err = vnic_rq_fill(&fnic->rq[i], fnic_alloc_rq_frame); 9235df6d737SAbhijeet Joglekar if (err) 9245df6d737SAbhijeet Joglekar shost_printk(KERN_ERR, fnic->lport->host, 92525985edcSLucas De Marchi "fnic_alloc_rq_frame can't alloc" 9265df6d737SAbhijeet Joglekar " frame\n"); 9275df6d737SAbhijeet Joglekar } 9285df6d737SAbhijeet Joglekar tot_rq_work_done += cur_work_done; 9295df6d737SAbhijeet Joglekar } 9305df6d737SAbhijeet Joglekar 9315df6d737SAbhijeet Joglekar return tot_rq_work_done; 9325df6d737SAbhijeet Joglekar } 9335df6d737SAbhijeet Joglekar 9345df6d737SAbhijeet Joglekar /* 9355df6d737SAbhijeet Joglekar * This function is called once at init time to allocate and fill RQ 9365df6d737SAbhijeet Joglekar * buffers. Subsequently, it is called in the interrupt context after RQ 9375df6d737SAbhijeet Joglekar * buffer processing to replenish the buffers in the RQ 9385df6d737SAbhijeet Joglekar */ 9395df6d737SAbhijeet Joglekar int fnic_alloc_rq_frame(struct vnic_rq *rq) 9405df6d737SAbhijeet Joglekar { 9415df6d737SAbhijeet Joglekar struct fnic *fnic = vnic_dev_priv(rq->vdev); 9425df6d737SAbhijeet Joglekar struct sk_buff *skb; 9435df6d737SAbhijeet Joglekar u16 len; 9445df6d737SAbhijeet Joglekar dma_addr_t pa; 945fd6ddfa4SMaurizio Lombardi int r; 9465df6d737SAbhijeet Joglekar 9475df6d737SAbhijeet Joglekar len = FC_FRAME_HEADROOM + FC_MAX_FRAME + FC_FRAME_TAILROOM; 9485df6d737SAbhijeet Joglekar skb = dev_alloc_skb(len); 9495df6d737SAbhijeet Joglekar if (!skb) { 9505df6d737SAbhijeet Joglekar FNIC_FCS_DBG(KERN_DEBUG, fnic->lport->host, 9515df6d737SAbhijeet Joglekar "Unable to allocate RQ sk_buff\n"); 9525df6d737SAbhijeet Joglekar return -ENOMEM; 9535df6d737SAbhijeet Joglekar } 9545df6d737SAbhijeet Joglekar skb_reset_mac_header(skb); 9555df6d737SAbhijeet Joglekar skb_reset_transport_header(skb); 9565df6d737SAbhijeet Joglekar skb_reset_network_header(skb); 9575df6d737SAbhijeet Joglekar skb_put(skb, len); 9585df6d737SAbhijeet Joglekar pa = pci_map_single(fnic->pdev, skb->data, len, PCI_DMA_FROMDEVICE); 959fd6ddfa4SMaurizio Lombardi 960dd7328e4SDan Carpenter if (pci_dma_mapping_error(fnic->pdev, pa)) { 961dd7328e4SDan Carpenter r = -ENOMEM; 962fd6ddfa4SMaurizio Lombardi printk(KERN_ERR "PCI mapping failed with error %d\n", r); 963fd6ddfa4SMaurizio Lombardi goto free_skb; 964fd6ddfa4SMaurizio Lombardi } 965fd6ddfa4SMaurizio Lombardi 9665df6d737SAbhijeet Joglekar fnic_queue_rq_desc(rq, skb, pa, len); 9675df6d737SAbhijeet Joglekar return 0; 968fd6ddfa4SMaurizio Lombardi 969fd6ddfa4SMaurizio Lombardi free_skb: 970fd6ddfa4SMaurizio Lombardi kfree_skb(skb); 971fd6ddfa4SMaurizio Lombardi return r; 9725df6d737SAbhijeet Joglekar } 9735df6d737SAbhijeet Joglekar 9745df6d737SAbhijeet Joglekar void fnic_free_rq_buf(struct vnic_rq *rq, struct vnic_rq_buf *buf) 9755df6d737SAbhijeet Joglekar { 9765df6d737SAbhijeet Joglekar struct fc_frame *fp = buf->os_buf; 9775df6d737SAbhijeet Joglekar struct fnic *fnic = vnic_dev_priv(rq->vdev); 9785df6d737SAbhijeet Joglekar 9795df6d737SAbhijeet Joglekar pci_unmap_single(fnic->pdev, buf->dma_addr, buf->len, 9805df6d737SAbhijeet Joglekar PCI_DMA_FROMDEVICE); 9815df6d737SAbhijeet Joglekar 9825df6d737SAbhijeet Joglekar dev_kfree_skb(fp_skb(fp)); 9835df6d737SAbhijeet Joglekar buf->os_buf = NULL; 9845df6d737SAbhijeet Joglekar } 9855df6d737SAbhijeet Joglekar 98678112e55SJoe Eykholt /** 98778112e55SJoe Eykholt * fnic_eth_send() - Send Ethernet frame. 98878112e55SJoe Eykholt * @fip: fcoe_ctlr instance. 98978112e55SJoe Eykholt * @skb: Ethernet Frame, FIP, without VLAN encapsulation. 99078112e55SJoe Eykholt */ 99178112e55SJoe Eykholt void fnic_eth_send(struct fcoe_ctlr *fip, struct sk_buff *skb) 9925df6d737SAbhijeet Joglekar { 99378112e55SJoe Eykholt struct fnic *fnic = fnic_from_ctlr(fip); 99478112e55SJoe Eykholt struct vnic_wq *wq = &fnic->wq[0]; 99578112e55SJoe Eykholt dma_addr_t pa; 99678112e55SJoe Eykholt struct ethhdr *eth_hdr; 99778112e55SJoe Eykholt struct vlan_ethhdr *vlan_hdr; 99878112e55SJoe Eykholt unsigned long flags; 999fd6ddfa4SMaurizio Lombardi int r; 100078112e55SJoe Eykholt 100178112e55SJoe Eykholt if (!fnic->vlan_hw_insert) { 100278112e55SJoe Eykholt eth_hdr = (struct ethhdr *)skb_mac_header(skb); 100378112e55SJoe Eykholt vlan_hdr = (struct vlan_ethhdr *)skb_push(skb, 100478112e55SJoe Eykholt sizeof(*vlan_hdr) - sizeof(*eth_hdr)); 100578112e55SJoe Eykholt memcpy(vlan_hdr, eth_hdr, 2 * ETH_ALEN); 100678112e55SJoe Eykholt vlan_hdr->h_vlan_proto = htons(ETH_P_8021Q); 100778112e55SJoe Eykholt vlan_hdr->h_vlan_encapsulated_proto = eth_hdr->h_proto; 100878112e55SJoe Eykholt vlan_hdr->h_vlan_TCI = htons(fnic->vlan_id); 1009abb14148SHiral Shah if ((fnic_fc_trace_set_data(fnic->lport->host->host_no, 1010abb14148SHiral Shah FNIC_FC_SEND|0x80, (char *)eth_hdr, skb->len)) != 0) { 1011abb14148SHiral Shah printk(KERN_ERR "fnic ctlr frame trace error!!!"); 1012abb14148SHiral Shah } 1013abb14148SHiral Shah } else { 1014abb14148SHiral Shah if ((fnic_fc_trace_set_data(fnic->lport->host->host_no, 1015abb14148SHiral Shah FNIC_FC_SEND|0x80, (char *)skb->data, skb->len)) != 0) { 1016abb14148SHiral Shah printk(KERN_ERR "fnic ctlr frame trace error!!!"); 1017abb14148SHiral Shah } 10185df6d737SAbhijeet Joglekar } 10195df6d737SAbhijeet Joglekar 102078112e55SJoe Eykholt pa = pci_map_single(fnic->pdev, skb->data, skb->len, PCI_DMA_TODEVICE); 102178112e55SJoe Eykholt 1022fd6ddfa4SMaurizio Lombardi r = pci_dma_mapping_error(fnic->pdev, pa); 1023fd6ddfa4SMaurizio Lombardi if (r) { 1024fd6ddfa4SMaurizio Lombardi printk(KERN_ERR "PCI mapping failed with error %d\n", r); 1025fd6ddfa4SMaurizio Lombardi goto free_skb; 102678112e55SJoe Eykholt } 102778112e55SJoe Eykholt 1028fd6ddfa4SMaurizio Lombardi spin_lock_irqsave(&fnic->wq_lock[0], flags); 1029fd6ddfa4SMaurizio Lombardi if (!vnic_wq_desc_avail(wq)) 1030fd6ddfa4SMaurizio Lombardi goto irq_restore; 1031fd6ddfa4SMaurizio Lombardi 103278112e55SJoe Eykholt fnic_queue_wq_eth_desc(wq, skb, pa, skb->len, 1033c0773b7cSHiral Patel 0 /* hw inserts cos value */, 1034c0773b7cSHiral Patel fnic->vlan_id, 1); 103578112e55SJoe Eykholt spin_unlock_irqrestore(&fnic->wq_lock[0], flags); 1036fd6ddfa4SMaurizio Lombardi return; 1037fd6ddfa4SMaurizio Lombardi 1038fd6ddfa4SMaurizio Lombardi irq_restore: 1039fd6ddfa4SMaurizio Lombardi spin_unlock_irqrestore(&fnic->wq_lock[0], flags); 1040fd6ddfa4SMaurizio Lombardi pci_unmap_single(fnic->pdev, pa, skb->len, PCI_DMA_TODEVICE); 1041fd6ddfa4SMaurizio Lombardi free_skb: 1042fd6ddfa4SMaurizio Lombardi kfree_skb(skb); 104378112e55SJoe Eykholt } 104478112e55SJoe Eykholt 104578112e55SJoe Eykholt /* 104678112e55SJoe Eykholt * Send FC frame. 104778112e55SJoe Eykholt */ 104878112e55SJoe Eykholt static int fnic_send_frame(struct fnic *fnic, struct fc_frame *fp) 10495df6d737SAbhijeet Joglekar { 10505df6d737SAbhijeet Joglekar struct vnic_wq *wq = &fnic->wq[0]; 10515df6d737SAbhijeet Joglekar struct sk_buff *skb; 10525df6d737SAbhijeet Joglekar dma_addr_t pa; 10535df6d737SAbhijeet Joglekar struct ethhdr *eth_hdr; 10545df6d737SAbhijeet Joglekar struct vlan_ethhdr *vlan_hdr; 10555df6d737SAbhijeet Joglekar struct fcoe_hdr *fcoe_hdr; 10565df6d737SAbhijeet Joglekar struct fc_frame_header *fh; 10575df6d737SAbhijeet Joglekar u32 tot_len, eth_hdr_len; 10585df6d737SAbhijeet Joglekar int ret = 0; 10595df6d737SAbhijeet Joglekar unsigned long flags; 10605df6d737SAbhijeet Joglekar 10615df6d737SAbhijeet Joglekar fh = fc_frame_header_get(fp); 10625df6d737SAbhijeet Joglekar skb = fp_skb(fp); 10635df6d737SAbhijeet Joglekar 106478112e55SJoe Eykholt if (unlikely(fh->fh_r_ctl == FC_RCTL_ELS_REQ) && 106578112e55SJoe Eykholt fcoe_ctlr_els_send(&fnic->ctlr, fnic->lport, skb)) 106678112e55SJoe Eykholt return 0; 106778112e55SJoe Eykholt 10685df6d737SAbhijeet Joglekar if (!fnic->vlan_hw_insert) { 10695df6d737SAbhijeet Joglekar eth_hdr_len = sizeof(*vlan_hdr) + sizeof(*fcoe_hdr); 10705df6d737SAbhijeet Joglekar vlan_hdr = (struct vlan_ethhdr *)skb_push(skb, eth_hdr_len); 10715df6d737SAbhijeet Joglekar eth_hdr = (struct ethhdr *)vlan_hdr; 10725df6d737SAbhijeet Joglekar vlan_hdr->h_vlan_proto = htons(ETH_P_8021Q); 10735df6d737SAbhijeet Joglekar vlan_hdr->h_vlan_encapsulated_proto = htons(ETH_P_FCOE); 10745df6d737SAbhijeet Joglekar vlan_hdr->h_vlan_TCI = htons(fnic->vlan_id); 10755df6d737SAbhijeet Joglekar fcoe_hdr = (struct fcoe_hdr *)(vlan_hdr + 1); 10765df6d737SAbhijeet Joglekar } else { 10775df6d737SAbhijeet Joglekar eth_hdr_len = sizeof(*eth_hdr) + sizeof(*fcoe_hdr); 10785df6d737SAbhijeet Joglekar eth_hdr = (struct ethhdr *)skb_push(skb, eth_hdr_len); 10795df6d737SAbhijeet Joglekar eth_hdr->h_proto = htons(ETH_P_FCOE); 10805df6d737SAbhijeet Joglekar fcoe_hdr = (struct fcoe_hdr *)(eth_hdr + 1); 10815df6d737SAbhijeet Joglekar } 10825df6d737SAbhijeet Joglekar 108378112e55SJoe Eykholt if (fnic->ctlr.map_dest) 10845df6d737SAbhijeet Joglekar fc_fcoe_set_mac(eth_hdr->h_dest, fh->fh_d_id); 10855df6d737SAbhijeet Joglekar else 108678112e55SJoe Eykholt memcpy(eth_hdr->h_dest, fnic->ctlr.dest_addr, ETH_ALEN); 10875df6d737SAbhijeet Joglekar memcpy(eth_hdr->h_source, fnic->data_src_addr, ETH_ALEN); 10885df6d737SAbhijeet Joglekar 10895df6d737SAbhijeet Joglekar tot_len = skb->len; 10905df6d737SAbhijeet Joglekar BUG_ON(tot_len % 4); 10915df6d737SAbhijeet Joglekar 10925df6d737SAbhijeet Joglekar memset(fcoe_hdr, 0, sizeof(*fcoe_hdr)); 10935df6d737SAbhijeet Joglekar fcoe_hdr->fcoe_sof = fr_sof(fp); 10945df6d737SAbhijeet Joglekar if (FC_FCOE_VER) 10955df6d737SAbhijeet Joglekar FC_FCOE_ENCAPS_VER(fcoe_hdr, FC_FCOE_VER); 10965df6d737SAbhijeet Joglekar 10975df6d737SAbhijeet Joglekar pa = pci_map_single(fnic->pdev, eth_hdr, tot_len, PCI_DMA_TODEVICE); 10985df6d737SAbhijeet Joglekar 1099dd7328e4SDan Carpenter if (pci_dma_mapping_error(fnic->pdev, pa)) { 1100dd7328e4SDan Carpenter ret = -ENOMEM; 1101fd6ddfa4SMaurizio Lombardi printk(KERN_ERR "DMA map failed with error %d\n", ret); 1102fd6ddfa4SMaurizio Lombardi goto free_skb_on_err; 1103fd6ddfa4SMaurizio Lombardi } 1104fd6ddfa4SMaurizio Lombardi 1105abb14148SHiral Shah if ((fnic_fc_trace_set_data(fnic->lport->host->host_no, FNIC_FC_SEND, 1106abb14148SHiral Shah (char *)eth_hdr, tot_len)) != 0) { 1107abb14148SHiral Shah printk(KERN_ERR "fnic ctlr frame trace error!!!"); 1108abb14148SHiral Shah } 1109abb14148SHiral Shah 11105df6d737SAbhijeet Joglekar spin_lock_irqsave(&fnic->wq_lock[0], flags); 11115df6d737SAbhijeet Joglekar 11125df6d737SAbhijeet Joglekar if (!vnic_wq_desc_avail(wq)) { 11135df6d737SAbhijeet Joglekar pci_unmap_single(fnic->pdev, pa, 11145df6d737SAbhijeet Joglekar tot_len, PCI_DMA_TODEVICE); 11155df6d737SAbhijeet Joglekar ret = -1; 1116fd6ddfa4SMaurizio Lombardi goto irq_restore; 11175df6d737SAbhijeet Joglekar } 11185df6d737SAbhijeet Joglekar 11195df6d737SAbhijeet Joglekar fnic_queue_wq_desc(wq, skb, pa, tot_len, fr_eof(fp), 1120c0773b7cSHiral Patel 0 /* hw inserts cos value */, 1121c0773b7cSHiral Patel fnic->vlan_id, 1, 1, 1); 1122fd6ddfa4SMaurizio Lombardi 1123fd6ddfa4SMaurizio Lombardi irq_restore: 11245df6d737SAbhijeet Joglekar spin_unlock_irqrestore(&fnic->wq_lock[0], flags); 11255df6d737SAbhijeet Joglekar 1126fd6ddfa4SMaurizio Lombardi free_skb_on_err: 11275df6d737SAbhijeet Joglekar if (ret) 11285df6d737SAbhijeet Joglekar dev_kfree_skb_any(fp_skb(fp)); 11295df6d737SAbhijeet Joglekar 11305df6d737SAbhijeet Joglekar return ret; 11315df6d737SAbhijeet Joglekar } 11325df6d737SAbhijeet Joglekar 11335df6d737SAbhijeet Joglekar /* 11345df6d737SAbhijeet Joglekar * fnic_send 11355df6d737SAbhijeet Joglekar * Routine to send a raw frame 11365df6d737SAbhijeet Joglekar */ 11375df6d737SAbhijeet Joglekar int fnic_send(struct fc_lport *lp, struct fc_frame *fp) 11385df6d737SAbhijeet Joglekar { 11395df6d737SAbhijeet Joglekar struct fnic *fnic = lport_priv(lp); 11405df6d737SAbhijeet Joglekar unsigned long flags; 11415df6d737SAbhijeet Joglekar 11425df6d737SAbhijeet Joglekar if (fnic->in_remove) { 11435df6d737SAbhijeet Joglekar dev_kfree_skb(fp_skb(fp)); 114478112e55SJoe Eykholt return -1; 11455df6d737SAbhijeet Joglekar } 11465df6d737SAbhijeet Joglekar 114778112e55SJoe Eykholt /* 114878112e55SJoe Eykholt * Queue frame if in a transitional state. 114978112e55SJoe Eykholt * This occurs while registering the Port_ID / MAC address after FLOGI. 115078112e55SJoe Eykholt */ 115178112e55SJoe Eykholt spin_lock_irqsave(&fnic->fnic_lock, flags); 115278112e55SJoe Eykholt if (fnic->state != FNIC_IN_FC_MODE && fnic->state != FNIC_IN_ETH_MODE) { 115378112e55SJoe Eykholt skb_queue_tail(&fnic->tx_queue, fp_skb(fp)); 115478112e55SJoe Eykholt spin_unlock_irqrestore(&fnic->fnic_lock, flags); 115578112e55SJoe Eykholt return 0; 115678112e55SJoe Eykholt } 115778112e55SJoe Eykholt spin_unlock_irqrestore(&fnic->fnic_lock, flags); 11585df6d737SAbhijeet Joglekar 115978112e55SJoe Eykholt return fnic_send_frame(fnic, fp); 116078112e55SJoe Eykholt } 116178112e55SJoe Eykholt 116278112e55SJoe Eykholt /** 116378112e55SJoe Eykholt * fnic_flush_tx() - send queued frames. 116478112e55SJoe Eykholt * @fnic: fnic device 116578112e55SJoe Eykholt * 116678112e55SJoe Eykholt * Send frames that were waiting to go out in FC or Ethernet mode. 116778112e55SJoe Eykholt * Whenever changing modes we purge queued frames, so these frames should 116878112e55SJoe Eykholt * be queued for the stable mode that we're in, either FC or Ethernet. 116978112e55SJoe Eykholt * 117078112e55SJoe Eykholt * Called without fnic_lock held. 117178112e55SJoe Eykholt */ 117278112e55SJoe Eykholt void fnic_flush_tx(struct fnic *fnic) 117378112e55SJoe Eykholt { 117478112e55SJoe Eykholt struct sk_buff *skb; 117578112e55SJoe Eykholt struct fc_frame *fp; 117678112e55SJoe Eykholt 1177d9e9ab56SBrian Uchino while ((skb = skb_dequeue(&fnic->tx_queue))) { 117878112e55SJoe Eykholt fp = (struct fc_frame *)skb; 117978112e55SJoe Eykholt fnic_send_frame(fnic, fp); 118078112e55SJoe Eykholt } 118178112e55SJoe Eykholt } 118278112e55SJoe Eykholt 118378112e55SJoe Eykholt /** 118478112e55SJoe Eykholt * fnic_set_eth_mode() - put fnic into ethernet mode. 118578112e55SJoe Eykholt * @fnic: fnic device 118678112e55SJoe Eykholt * 118778112e55SJoe Eykholt * Called without fnic lock held. 118878112e55SJoe Eykholt */ 118978112e55SJoe Eykholt static void fnic_set_eth_mode(struct fnic *fnic) 119078112e55SJoe Eykholt { 119178112e55SJoe Eykholt unsigned long flags; 119278112e55SJoe Eykholt enum fnic_state old_state; 119378112e55SJoe Eykholt int ret; 11945df6d737SAbhijeet Joglekar 11955df6d737SAbhijeet Joglekar spin_lock_irqsave(&fnic->fnic_lock, flags); 11965df6d737SAbhijeet Joglekar again: 11975df6d737SAbhijeet Joglekar old_state = fnic->state; 11985df6d737SAbhijeet Joglekar switch (old_state) { 11995df6d737SAbhijeet Joglekar case FNIC_IN_FC_MODE: 12005df6d737SAbhijeet Joglekar case FNIC_IN_ETH_TRANS_FC_MODE: 12015df6d737SAbhijeet Joglekar default: 12025df6d737SAbhijeet Joglekar fnic->state = FNIC_IN_FC_TRANS_ETH_MODE; 12035df6d737SAbhijeet Joglekar spin_unlock_irqrestore(&fnic->fnic_lock, flags); 12045df6d737SAbhijeet Joglekar 12055df6d737SAbhijeet Joglekar ret = fnic_fw_reset_handler(fnic); 12065df6d737SAbhijeet Joglekar 12075df6d737SAbhijeet Joglekar spin_lock_irqsave(&fnic->fnic_lock, flags); 12085df6d737SAbhijeet Joglekar if (fnic->state != FNIC_IN_FC_TRANS_ETH_MODE) 12095df6d737SAbhijeet Joglekar goto again; 121078112e55SJoe Eykholt if (ret) 12115df6d737SAbhijeet Joglekar fnic->state = old_state; 12125df6d737SAbhijeet Joglekar break; 12135df6d737SAbhijeet Joglekar 12145df6d737SAbhijeet Joglekar case FNIC_IN_FC_TRANS_ETH_MODE: 12155df6d737SAbhijeet Joglekar case FNIC_IN_ETH_MODE: 12165df6d737SAbhijeet Joglekar break; 12175df6d737SAbhijeet Joglekar } 121878112e55SJoe Eykholt spin_unlock_irqrestore(&fnic->fnic_lock, flags); 12195df6d737SAbhijeet Joglekar } 12205df6d737SAbhijeet Joglekar 12215df6d737SAbhijeet Joglekar static void fnic_wq_complete_frame_send(struct vnic_wq *wq, 12225df6d737SAbhijeet Joglekar struct cq_desc *cq_desc, 12235df6d737SAbhijeet Joglekar struct vnic_wq_buf *buf, void *opaque) 12245df6d737SAbhijeet Joglekar { 12255df6d737SAbhijeet Joglekar struct sk_buff *skb = buf->os_buf; 12265df6d737SAbhijeet Joglekar struct fc_frame *fp = (struct fc_frame *)skb; 12275df6d737SAbhijeet Joglekar struct fnic *fnic = vnic_dev_priv(wq->vdev); 12285df6d737SAbhijeet Joglekar 12295df6d737SAbhijeet Joglekar pci_unmap_single(fnic->pdev, buf->dma_addr, 12305df6d737SAbhijeet Joglekar buf->len, PCI_DMA_TODEVICE); 12315df6d737SAbhijeet Joglekar dev_kfree_skb_irq(fp_skb(fp)); 12325df6d737SAbhijeet Joglekar buf->os_buf = NULL; 12335df6d737SAbhijeet Joglekar } 12345df6d737SAbhijeet Joglekar 12355df6d737SAbhijeet Joglekar static int fnic_wq_cmpl_handler_cont(struct vnic_dev *vdev, 12365df6d737SAbhijeet Joglekar struct cq_desc *cq_desc, u8 type, 12375df6d737SAbhijeet Joglekar u16 q_number, u16 completed_index, 12385df6d737SAbhijeet Joglekar void *opaque) 12395df6d737SAbhijeet Joglekar { 12405df6d737SAbhijeet Joglekar struct fnic *fnic = vnic_dev_priv(vdev); 12415df6d737SAbhijeet Joglekar unsigned long flags; 12425df6d737SAbhijeet Joglekar 12435df6d737SAbhijeet Joglekar spin_lock_irqsave(&fnic->wq_lock[q_number], flags); 12445df6d737SAbhijeet Joglekar vnic_wq_service(&fnic->wq[q_number], cq_desc, completed_index, 12455df6d737SAbhijeet Joglekar fnic_wq_complete_frame_send, NULL); 12465df6d737SAbhijeet Joglekar spin_unlock_irqrestore(&fnic->wq_lock[q_number], flags); 12475df6d737SAbhijeet Joglekar 12485df6d737SAbhijeet Joglekar return 0; 12495df6d737SAbhijeet Joglekar } 12505df6d737SAbhijeet Joglekar 12515df6d737SAbhijeet Joglekar int fnic_wq_cmpl_handler(struct fnic *fnic, int work_to_do) 12525df6d737SAbhijeet Joglekar { 12535df6d737SAbhijeet Joglekar unsigned int wq_work_done = 0; 12545df6d737SAbhijeet Joglekar unsigned int i; 12555df6d737SAbhijeet Joglekar 12565df6d737SAbhijeet Joglekar for (i = 0; i < fnic->raw_wq_count; i++) { 12575df6d737SAbhijeet Joglekar wq_work_done += vnic_cq_service(&fnic->cq[fnic->rq_count+i], 12585df6d737SAbhijeet Joglekar work_to_do, 12595df6d737SAbhijeet Joglekar fnic_wq_cmpl_handler_cont, 12605df6d737SAbhijeet Joglekar NULL); 12615df6d737SAbhijeet Joglekar } 12625df6d737SAbhijeet Joglekar 12635df6d737SAbhijeet Joglekar return wq_work_done; 12645df6d737SAbhijeet Joglekar } 12655df6d737SAbhijeet Joglekar 12665df6d737SAbhijeet Joglekar 12675df6d737SAbhijeet Joglekar void fnic_free_wq_buf(struct vnic_wq *wq, struct vnic_wq_buf *buf) 12685df6d737SAbhijeet Joglekar { 12695df6d737SAbhijeet Joglekar struct fc_frame *fp = buf->os_buf; 12705df6d737SAbhijeet Joglekar struct fnic *fnic = vnic_dev_priv(wq->vdev); 12715df6d737SAbhijeet Joglekar 12725df6d737SAbhijeet Joglekar pci_unmap_single(fnic->pdev, buf->dma_addr, 12735df6d737SAbhijeet Joglekar buf->len, PCI_DMA_TODEVICE); 12745df6d737SAbhijeet Joglekar 12755df6d737SAbhijeet Joglekar dev_kfree_skb(fp_skb(fp)); 12765df6d737SAbhijeet Joglekar buf->os_buf = NULL; 12775df6d737SAbhijeet Joglekar } 1278d3c995f1SHiral Patel 1279d3c995f1SHiral Patel void fnic_fcoe_reset_vlans(struct fnic *fnic) 1280d3c995f1SHiral Patel { 1281d3c995f1SHiral Patel unsigned long flags; 1282d3c995f1SHiral Patel struct fcoe_vlan *vlan; 1283d3c995f1SHiral Patel struct fcoe_vlan *next; 1284d3c995f1SHiral Patel 1285d3c995f1SHiral Patel /* 1286d3c995f1SHiral Patel * indicate a link down to fcoe so that all fcf's are free'd 1287d3c995f1SHiral Patel * might not be required since we did this before sending vlan 1288d3c995f1SHiral Patel * discovery request 1289d3c995f1SHiral Patel */ 1290d3c995f1SHiral Patel spin_lock_irqsave(&fnic->vlans_lock, flags); 1291d3c995f1SHiral Patel if (!list_empty(&fnic->vlans)) { 1292d3c995f1SHiral Patel list_for_each_entry_safe(vlan, next, &fnic->vlans, list) { 1293d3c995f1SHiral Patel list_del(&vlan->list); 1294d3c995f1SHiral Patel kfree(vlan); 1295d3c995f1SHiral Patel } 1296d3c995f1SHiral Patel } 1297d3c995f1SHiral Patel spin_unlock_irqrestore(&fnic->vlans_lock, flags); 1298d3c995f1SHiral Patel } 1299d3c995f1SHiral Patel 1300d3c995f1SHiral Patel void fnic_handle_fip_timer(struct fnic *fnic) 1301d3c995f1SHiral Patel { 1302d3c995f1SHiral Patel unsigned long flags; 1303d3c995f1SHiral Patel struct fcoe_vlan *vlan; 130467125b02SHiral Patel struct fnic_stats *fnic_stats = &fnic->fnic_stats; 1305d3c995f1SHiral Patel u64 sol_time; 1306d3c995f1SHiral Patel 1307d3c995f1SHiral Patel spin_lock_irqsave(&fnic->fnic_lock, flags); 1308d3c995f1SHiral Patel if (fnic->stop_rx_link_events) { 1309d3c995f1SHiral Patel spin_unlock_irqrestore(&fnic->fnic_lock, flags); 1310d3c995f1SHiral Patel return; 1311d3c995f1SHiral Patel } 1312d3c995f1SHiral Patel spin_unlock_irqrestore(&fnic->fnic_lock, flags); 1313d3c995f1SHiral Patel 13141917d42dSHannes Reinecke if (fnic->ctlr.mode == FIP_MODE_NON_FIP) 1315d3c995f1SHiral Patel return; 1316d3c995f1SHiral Patel 1317d3c995f1SHiral Patel spin_lock_irqsave(&fnic->vlans_lock, flags); 1318d3c995f1SHiral Patel if (list_empty(&fnic->vlans)) { 1319b43abcbbSSatish Kharat spin_unlock_irqrestore(&fnic->vlans_lock, flags); 1320d3c995f1SHiral Patel /* no vlans available, try again */ 1321b43abcbbSSatish Kharat if (printk_ratelimit()) 1322d3c995f1SHiral Patel FNIC_FCS_DBG(KERN_DEBUG, fnic->lport->host, 1323d3c995f1SHiral Patel "Start VLAN Discovery\n"); 1324d3c995f1SHiral Patel fnic_event_enq(fnic, FNIC_EVT_START_VLAN_DISC); 1325d3c995f1SHiral Patel return; 1326d3c995f1SHiral Patel } 1327d3c995f1SHiral Patel 1328d3c995f1SHiral Patel vlan = list_first_entry(&fnic->vlans, struct fcoe_vlan, list); 1329d3c995f1SHiral Patel shost_printk(KERN_DEBUG, fnic->lport->host, 1330d3c995f1SHiral Patel "fip_timer: vlan %d state %d sol_count %d\n", 1331d3c995f1SHiral Patel vlan->vid, vlan->state, vlan->sol_count); 1332d3c995f1SHiral Patel switch (vlan->state) { 1333d3c995f1SHiral Patel case FIP_VLAN_USED: 1334d3c995f1SHiral Patel FNIC_FCS_DBG(KERN_DEBUG, fnic->lport->host, 1335d3c995f1SHiral Patel "FIP VLAN is selected for FC transaction\n"); 1336d3c995f1SHiral Patel spin_unlock_irqrestore(&fnic->vlans_lock, flags); 1337d3c995f1SHiral Patel break; 1338d3c995f1SHiral Patel case FIP_VLAN_FAILED: 1339b43abcbbSSatish Kharat spin_unlock_irqrestore(&fnic->vlans_lock, flags); 1340d3c995f1SHiral Patel /* if all vlans are in failed state, restart vlan disc */ 1341b43abcbbSSatish Kharat if (printk_ratelimit()) 1342d3c995f1SHiral Patel FNIC_FCS_DBG(KERN_DEBUG, fnic->lport->host, 1343d3c995f1SHiral Patel "Start VLAN Discovery\n"); 1344d3c995f1SHiral Patel fnic_event_enq(fnic, FNIC_EVT_START_VLAN_DISC); 1345d3c995f1SHiral Patel break; 1346d3c995f1SHiral Patel case FIP_VLAN_SENT: 1347d3c995f1SHiral Patel if (vlan->sol_count >= FCOE_CTLR_MAX_SOL) { 1348d3c995f1SHiral Patel /* 1349d3c995f1SHiral Patel * no response on this vlan, remove from the list. 1350d3c995f1SHiral Patel * Try the next vlan 1351d3c995f1SHiral Patel */ 1352d3c995f1SHiral Patel shost_printk(KERN_INFO, fnic->lport->host, 1353d3c995f1SHiral Patel "Dequeue this VLAN ID %d from list\n", 1354d3c995f1SHiral Patel vlan->vid); 1355d3c995f1SHiral Patel list_del(&vlan->list); 1356d3c995f1SHiral Patel kfree(vlan); 1357d3c995f1SHiral Patel vlan = NULL; 1358d3c995f1SHiral Patel if (list_empty(&fnic->vlans)) { 1359d3c995f1SHiral Patel /* we exhausted all vlans, restart vlan disc */ 1360d3c995f1SHiral Patel spin_unlock_irqrestore(&fnic->vlans_lock, 1361d3c995f1SHiral Patel flags); 1362d3c995f1SHiral Patel shost_printk(KERN_INFO, fnic->lport->host, 1363d3c995f1SHiral Patel "fip_timer: vlan list empty, " 1364d3c995f1SHiral Patel "trigger vlan disc\n"); 1365d3c995f1SHiral Patel fnic_event_enq(fnic, FNIC_EVT_START_VLAN_DISC); 1366d3c995f1SHiral Patel return; 1367d3c995f1SHiral Patel } 1368d3c995f1SHiral Patel /* check the next vlan */ 1369d3c995f1SHiral Patel vlan = list_first_entry(&fnic->vlans, struct fcoe_vlan, 1370d3c995f1SHiral Patel list); 1371d3c995f1SHiral Patel fnic->set_vlan(fnic, vlan->vid); 1372d3c995f1SHiral Patel vlan->state = FIP_VLAN_SENT; /* sent now */ 1373d3c995f1SHiral Patel } 1374d3c995f1SHiral Patel spin_unlock_irqrestore(&fnic->vlans_lock, flags); 137567125b02SHiral Patel atomic64_inc(&fnic_stats->vlan_stats.sol_expiry_count); 1376d3c995f1SHiral Patel vlan->sol_count++; 1377d3c995f1SHiral Patel sol_time = jiffies + msecs_to_jiffies 1378d3c995f1SHiral Patel (FCOE_CTLR_START_DELAY); 1379d3c995f1SHiral Patel mod_timer(&fnic->fip_timer, round_jiffies(sol_time)); 1380d3c995f1SHiral Patel break; 1381d3c995f1SHiral Patel } 1382d3c995f1SHiral Patel } 1383