1 /* 2 * QLogic FCoE Offload Driver 3 * Copyright (c) 2016-2018 Cavium Inc. 4 * 5 * This software is available under the terms of the GNU General Public License 6 * (GPL) Version 2, available from the file COPYING in the main directory of 7 * this source tree. 8 */ 9 #include <linux/if_ether.h> 10 #include <linux/if_vlan.h> 11 #include "qedf.h" 12 13 extern const struct qed_fcoe_ops *qed_ops; 14 /* 15 * FIP VLAN functions that will eventually move to libfcoe. 16 */ 17 18 void qedf_fcoe_send_vlan_req(struct qedf_ctx *qedf) 19 { 20 struct sk_buff *skb; 21 char *eth_fr; 22 int fr_len; 23 struct fip_vlan *vlan; 24 #define MY_FIP_ALL_FCF_MACS ((__u8[6]) { 1, 0x10, 0x18, 1, 0, 2 }) 25 static u8 my_fcoe_all_fcfs[ETH_ALEN] = MY_FIP_ALL_FCF_MACS; 26 unsigned long flags = 0; 27 28 skb = dev_alloc_skb(sizeof(struct fip_vlan)); 29 if (!skb) 30 return; 31 32 fr_len = sizeof(*vlan); 33 eth_fr = (char *)skb->data; 34 vlan = (struct fip_vlan *)eth_fr; 35 36 memset(vlan, 0, sizeof(*vlan)); 37 ether_addr_copy(vlan->eth.h_source, qedf->mac); 38 ether_addr_copy(vlan->eth.h_dest, my_fcoe_all_fcfs); 39 vlan->eth.h_proto = htons(ETH_P_FIP); 40 41 vlan->fip.fip_ver = FIP_VER_ENCAPS(FIP_VER); 42 vlan->fip.fip_op = htons(FIP_OP_VLAN); 43 vlan->fip.fip_subcode = FIP_SC_VL_REQ; 44 vlan->fip.fip_dl_len = htons(sizeof(vlan->desc) / FIP_BPW); 45 46 vlan->desc.mac.fd_desc.fip_dtype = FIP_DT_MAC; 47 vlan->desc.mac.fd_desc.fip_dlen = sizeof(vlan->desc.mac) / FIP_BPW; 48 ether_addr_copy(vlan->desc.mac.fd_mac, qedf->mac); 49 50 vlan->desc.wwnn.fd_desc.fip_dtype = FIP_DT_NAME; 51 vlan->desc.wwnn.fd_desc.fip_dlen = sizeof(vlan->desc.wwnn) / FIP_BPW; 52 put_unaligned_be64(qedf->lport->wwnn, &vlan->desc.wwnn.fd_wwn); 53 54 skb_put(skb, sizeof(*vlan)); 55 skb->protocol = htons(ETH_P_FIP); 56 skb_reset_mac_header(skb); 57 skb_reset_network_header(skb); 58 59 QEDF_INFO(&(qedf->dbg_ctx), QEDF_LOG_DISC, "Sending FIP VLAN " 60 "request."); 61 62 if (atomic_read(&qedf->link_state) != QEDF_LINK_UP) { 63 QEDF_WARN(&(qedf->dbg_ctx), "Cannot send vlan request " 64 "because link is not up.\n"); 65 66 kfree_skb(skb); 67 return; 68 } 69 70 set_bit(QED_LL2_XMIT_FLAGS_FIP_DISCOVERY, &flags); 71 qed_ops->ll2->start_xmit(qedf->cdev, skb, flags); 72 } 73 74 static void qedf_fcoe_process_vlan_resp(struct qedf_ctx *qedf, 75 struct sk_buff *skb) 76 { 77 struct fip_header *fiph; 78 struct fip_desc *desc; 79 u16 vid = 0; 80 ssize_t rlen; 81 size_t dlen; 82 83 fiph = (struct fip_header *)(((void *)skb->data) + 2 * ETH_ALEN + 2); 84 85 rlen = ntohs(fiph->fip_dl_len) * 4; 86 desc = (struct fip_desc *)(fiph + 1); 87 while (rlen > 0) { 88 dlen = desc->fip_dlen * FIP_BPW; 89 switch (desc->fip_dtype) { 90 case FIP_DT_VLAN: 91 vid = ntohs(((struct fip_vlan_desc *)desc)->fd_vlan); 92 break; 93 } 94 desc = (struct fip_desc *)((char *)desc + dlen); 95 rlen -= dlen; 96 } 97 98 QEDF_INFO(&(qedf->dbg_ctx), QEDF_LOG_DISC, "VLAN response, " 99 "vid=0x%x.\n", vid); 100 101 if (vid > 0 && qedf->vlan_id != vid) { 102 qedf_set_vlan_id(qedf, vid); 103 104 /* Inform waiter that it's ok to call fcoe_ctlr_link up() */ 105 if (!completion_done(&qedf->fipvlan_compl)) 106 complete(&qedf->fipvlan_compl); 107 } 108 } 109 110 void qedf_fip_send(struct fcoe_ctlr *fip, struct sk_buff *skb) 111 { 112 struct qedf_ctx *qedf = container_of(fip, struct qedf_ctx, ctlr); 113 struct ethhdr *eth_hdr; 114 struct fip_header *fiph; 115 u16 op, vlan_tci = 0; 116 u8 sub; 117 118 if (!test_bit(QEDF_LL2_STARTED, &qedf->flags)) { 119 QEDF_WARN(&(qedf->dbg_ctx), "LL2 not started\n"); 120 kfree_skb(skb); 121 return; 122 } 123 124 fiph = (struct fip_header *) ((void *)skb->data + 2 * ETH_ALEN + 2); 125 eth_hdr = (struct ethhdr *)skb_mac_header(skb); 126 op = ntohs(fiph->fip_op); 127 sub = fiph->fip_subcode; 128 129 /* 130 * Add VLAN tag to non-offload FIP frame based on current stored VLAN 131 * for FIP/FCoE traffic. 132 */ 133 __vlan_hwaccel_put_tag(skb, htons(ETH_P_8021Q), qedf->vlan_id); 134 135 /* Get VLAN ID from skb for printing purposes */ 136 __vlan_hwaccel_get_tag(skb, &vlan_tci); 137 138 QEDF_INFO(&(qedf->dbg_ctx), QEDF_LOG_LL2, "FIP frame send: " 139 "dest=%pM op=%x sub=%x vlan=%04x.", eth_hdr->h_dest, op, sub, 140 vlan_tci); 141 if (qedf_dump_frames) 142 print_hex_dump(KERN_WARNING, "fip ", DUMP_PREFIX_OFFSET, 16, 1, 143 skb->data, skb->len, false); 144 145 qed_ops->ll2->start_xmit(qedf->cdev, skb, 0); 146 } 147 148 /* Process incoming FIP frames. */ 149 void qedf_fip_recv(struct qedf_ctx *qedf, struct sk_buff *skb) 150 { 151 struct ethhdr *eth_hdr; 152 struct fip_header *fiph; 153 struct fip_desc *desc; 154 struct fip_mac_desc *mp; 155 struct fip_wwn_desc *wp; 156 struct fip_vn_desc *vp; 157 size_t rlen, dlen; 158 u16 op; 159 u8 sub; 160 bool do_reset = false; 161 162 eth_hdr = (struct ethhdr *)skb_mac_header(skb); 163 fiph = (struct fip_header *) ((void *)skb->data + 2 * ETH_ALEN + 2); 164 op = ntohs(fiph->fip_op); 165 sub = fiph->fip_subcode; 166 167 QEDF_INFO(&(qedf->dbg_ctx), QEDF_LOG_LL2, "FIP frame received: " 168 "skb=%p fiph=%p source=%pM op=%x sub=%x", skb, fiph, 169 eth_hdr->h_source, op, sub); 170 if (qedf_dump_frames) 171 print_hex_dump(KERN_WARNING, "fip ", DUMP_PREFIX_OFFSET, 16, 1, 172 skb->data, skb->len, false); 173 174 /* Handle FIP VLAN resp in the driver */ 175 if (op == FIP_OP_VLAN && sub == FIP_SC_VL_NOTE) { 176 qedf_fcoe_process_vlan_resp(qedf, skb); 177 kfree_skb(skb); 178 } else if (op == FIP_OP_CTRL && sub == FIP_SC_CLR_VLINK) { 179 QEDF_INFO(&(qedf->dbg_ctx), QEDF_LOG_DISC, "Clear virtual " 180 "link received.\n"); 181 182 /* Check that an FCF has been selected by fcoe */ 183 if (qedf->ctlr.sel_fcf == NULL) { 184 QEDF_INFO(&(qedf->dbg_ctx), QEDF_LOG_DISC, 185 "Dropping CVL since FCF has not been selected " 186 "yet."); 187 kfree_skb(skb); 188 return; 189 } 190 191 /* 192 * We need to loop through the CVL descriptors to determine 193 * if we want to reset the fcoe link 194 */ 195 rlen = ntohs(fiph->fip_dl_len) * FIP_BPW; 196 desc = (struct fip_desc *)(fiph + 1); 197 while (rlen >= sizeof(*desc)) { 198 dlen = desc->fip_dlen * FIP_BPW; 199 switch (desc->fip_dtype) { 200 case FIP_DT_MAC: 201 mp = (struct fip_mac_desc *)desc; 202 QEDF_INFO(&(qedf->dbg_ctx), QEDF_LOG_LL2, 203 "fd_mac=%pM\n", mp->fd_mac); 204 if (ether_addr_equal(mp->fd_mac, 205 qedf->ctlr.sel_fcf->fcf_mac)) 206 do_reset = true; 207 break; 208 case FIP_DT_NAME: 209 wp = (struct fip_wwn_desc *)desc; 210 QEDF_INFO(&(qedf->dbg_ctx), QEDF_LOG_LL2, 211 "fc_wwpn=%016llx.\n", 212 get_unaligned_be64(&wp->fd_wwn)); 213 break; 214 case FIP_DT_VN_ID: 215 vp = (struct fip_vn_desc *)desc; 216 QEDF_INFO(&(qedf->dbg_ctx), QEDF_LOG_LL2, 217 "fd_fc_id=%x.\n", ntoh24(vp->fd_fc_id)); 218 if (ntoh24(vp->fd_fc_id) == 219 qedf->lport->port_id) 220 do_reset = true; 221 break; 222 default: 223 /* Ignore anything else */ 224 break; 225 } 226 desc = (struct fip_desc *)((char *)desc + dlen); 227 rlen -= dlen; 228 } 229 230 QEDF_INFO(&(qedf->dbg_ctx), QEDF_LOG_LL2, 231 "do_reset=%d.\n", do_reset); 232 if (do_reset) { 233 fcoe_ctlr_link_down(&qedf->ctlr); 234 qedf_wait_for_upload(qedf); 235 fcoe_ctlr_link_up(&qedf->ctlr); 236 } 237 kfree_skb(skb); 238 } else { 239 /* Everything else is handled by libfcoe */ 240 __skb_pull(skb, ETH_HLEN); 241 fcoe_ctlr_recv(&qedf->ctlr, skb); 242 } 243 } 244 245 u8 *qedf_get_src_mac(struct fc_lport *lport) 246 { 247 struct qedf_ctx *qedf = lport_priv(lport); 248 249 return qedf->data_src_addr; 250 } 251