2 * QLogic FCoE Offload Driver
3 * Copyright (c) 2016 Cavium Inc.
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
9 #include <linux/if_ether.h>
10 #include <linux/if_vlan.h>
13 extern const struct qed_fcoe_ops
*qed_ops
;
15 * FIP VLAN functions that will eventually move to libfcoe.
18 void qedf_fcoe_send_vlan_req(struct qedf_ctx
*qedf
)
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
;
27 skb
= dev_alloc_skb(sizeof(struct fip_vlan
));
31 fr_len
= sizeof(*vlan
);
32 eth_fr
= (char *)skb
->data
;
33 vlan
= (struct fip_vlan
*)eth_fr
;
35 memset(vlan
, 0, sizeof(*vlan
));
36 ether_addr_copy(vlan
->eth
.h_source
, qedf
->mac
);
37 ether_addr_copy(vlan
->eth
.h_dest
, my_fcoe_all_fcfs
);
38 vlan
->eth
.h_proto
= htons(ETH_P_FIP
);
40 vlan
->fip
.fip_ver
= FIP_VER_ENCAPS(FIP_VER
);
41 vlan
->fip
.fip_op
= htons(FIP_OP_VLAN
);
42 vlan
->fip
.fip_subcode
= FIP_SC_VL_REQ
;
43 vlan
->fip
.fip_dl_len
= htons(sizeof(vlan
->desc
) / FIP_BPW
);
45 vlan
->desc
.mac
.fd_desc
.fip_dtype
= FIP_DT_MAC
;
46 vlan
->desc
.mac
.fd_desc
.fip_dlen
= sizeof(vlan
->desc
.mac
) / FIP_BPW
;
47 ether_addr_copy(vlan
->desc
.mac
.fd_mac
, qedf
->mac
);
49 vlan
->desc
.wwnn
.fd_desc
.fip_dtype
= FIP_DT_NAME
;
50 vlan
->desc
.wwnn
.fd_desc
.fip_dlen
= sizeof(vlan
->desc
.wwnn
) / FIP_BPW
;
51 put_unaligned_be64(qedf
->lport
->wwnn
, &vlan
->desc
.wwnn
.fd_wwn
);
53 skb_put(skb
, sizeof(*vlan
));
54 skb
->protocol
= htons(ETH_P_FIP
);
55 skb_reset_mac_header(skb
);
56 skb_reset_network_header(skb
);
58 QEDF_INFO(&(qedf
->dbg_ctx
), QEDF_LOG_DISC
, "Sending FIP VLAN "
61 if (atomic_read(&qedf
->link_state
) != QEDF_LINK_UP
) {
62 QEDF_WARN(&(qedf
->dbg_ctx
), "Cannot send vlan request "
63 "because link is not up.\n");
68 qed_ops
->ll2
->start_xmit(qedf
->cdev
, skb
);
71 static void qedf_fcoe_process_vlan_resp(struct qedf_ctx
*qedf
,
74 struct fip_header
*fiph
;
75 struct fip_desc
*desc
;
80 fiph
= (struct fip_header
*)(((void *)skb
->data
) + 2 * ETH_ALEN
+ 2);
82 rlen
= ntohs(fiph
->fip_dl_len
) * 4;
83 desc
= (struct fip_desc
*)(fiph
+ 1);
85 dlen
= desc
->fip_dlen
* FIP_BPW
;
86 switch (desc
->fip_dtype
) {
88 vid
= ntohs(((struct fip_vlan_desc
*)desc
)->fd_vlan
);
91 desc
= (struct fip_desc
*)((char *)desc
+ dlen
);
95 QEDF_INFO(&(qedf
->dbg_ctx
), QEDF_LOG_DISC
, "VLAN response, "
98 if (vid
> 0 && qedf
->vlan_id
!= vid
) {
99 qedf_set_vlan_id(qedf
, vid
);
101 /* Inform waiter that it's ok to call fcoe_ctlr_link up() */
102 if (!completion_done(&qedf
->fipvlan_compl
))
103 complete(&qedf
->fipvlan_compl
);
107 void qedf_fip_send(struct fcoe_ctlr
*fip
, struct sk_buff
*skb
)
109 struct qedf_ctx
*qedf
= container_of(fip
, struct qedf_ctx
, ctlr
);
110 struct ethhdr
*eth_hdr
;
111 struct vlan_ethhdr
*vlan_hdr
;
112 struct fip_header
*fiph
;
113 u16 op
, vlan_tci
= 0;
116 if (!test_bit(QEDF_LL2_STARTED
, &qedf
->flags
)) {
117 QEDF_WARN(&(qedf
->dbg_ctx
), "LL2 not started\n");
122 fiph
= (struct fip_header
*) ((void *)skb
->data
+ 2 * ETH_ALEN
+ 2);
123 eth_hdr
= (struct ethhdr
*)skb_mac_header(skb
);
124 op
= ntohs(fiph
->fip_op
);
125 sub
= fiph
->fip_subcode
;
127 if (!qedf
->vlan_hw_insert
) {
128 vlan_hdr
= (struct vlan_ethhdr
*)skb_push(skb
, sizeof(*vlan_hdr
)
130 memcpy(vlan_hdr
, eth_hdr
, 2 * ETH_ALEN
);
131 vlan_hdr
->h_vlan_proto
= htons(ETH_P_8021Q
);
132 vlan_hdr
->h_vlan_encapsulated_proto
= eth_hdr
->h_proto
;
133 vlan_hdr
->h_vlan_TCI
= vlan_tci
= htons(qedf
->vlan_id
);
136 /* Update eth_hdr since we added a VLAN tag */
137 eth_hdr
= (struct ethhdr
*)skb_mac_header(skb
);
139 QEDF_INFO(&(qedf
->dbg_ctx
), QEDF_LOG_LL2
, "FIP frame send: "
140 "dest=%pM op=%x sub=%x vlan=%04x.", eth_hdr
->h_dest
, op
, sub
,
142 if (qedf_dump_frames
)
143 print_hex_dump(KERN_WARNING
, "fip ", DUMP_PREFIX_OFFSET
, 16, 1,
144 skb
->data
, skb
->len
, false);
146 qed_ops
->ll2
->start_xmit(qedf
->cdev
, skb
);
149 /* Process incoming FIP frames. */
150 void qedf_fip_recv(struct qedf_ctx
*qedf
, struct sk_buff
*skb
)
152 struct ethhdr
*eth_hdr
;
153 struct fip_header
*fiph
;
154 struct fip_desc
*desc
;
155 struct fip_mac_desc
*mp
;
156 struct fip_wwn_desc
*wp
;
157 struct fip_vn_desc
*vp
;
159 uint32_t cvl_port_id
;
160 __u8 cvl_mac
[ETH_ALEN
];
164 eth_hdr
= (struct ethhdr
*)skb_mac_header(skb
);
165 fiph
= (struct fip_header
*) ((void *)skb
->data
+ 2 * ETH_ALEN
+ 2);
166 op
= ntohs(fiph
->fip_op
);
167 sub
= fiph
->fip_subcode
;
169 QEDF_INFO(&(qedf
->dbg_ctx
), QEDF_LOG_LL2
, "FIP frame received: "
170 "skb=%p fiph=%p source=%pM op=%x sub=%x", skb
, fiph
,
171 eth_hdr
->h_source
, op
, sub
);
172 if (qedf_dump_frames
)
173 print_hex_dump(KERN_WARNING
, "fip ", DUMP_PREFIX_OFFSET
, 16, 1,
174 skb
->data
, skb
->len
, false);
176 /* Handle FIP VLAN resp in the driver */
177 if (op
== FIP_OP_VLAN
&& sub
== FIP_SC_VL_NOTE
) {
178 qedf_fcoe_process_vlan_resp(qedf
, skb
);
179 qedf
->vlan_hw_insert
= 0;
181 } else if (op
== FIP_OP_CTRL
&& sub
== FIP_SC_CLR_VLINK
) {
182 QEDF_INFO(&(qedf
->dbg_ctx
), QEDF_LOG_DISC
, "Clear virtual "
185 /* Check that an FCF has been selected by fcoe */
186 if (qedf
->ctlr
.sel_fcf
== NULL
) {
187 QEDF_INFO(&(qedf
->dbg_ctx
), QEDF_LOG_DISC
,
188 "Dropping CVL since FCF has not been selected "
194 memset(cvl_mac
, 0, ETH_ALEN
);
196 * We need to loop through the CVL descriptors to determine
197 * if we want to reset the fcoe link
199 rlen
= ntohs(fiph
->fip_dl_len
) * FIP_BPW
;
200 desc
= (struct fip_desc
*)(fiph
+ 1);
201 while (rlen
>= sizeof(*desc
)) {
202 dlen
= desc
->fip_dlen
* FIP_BPW
;
203 switch (desc
->fip_dtype
) {
205 mp
= (struct fip_mac_desc
*)desc
;
206 QEDF_INFO(&(qedf
->dbg_ctx
), QEDF_LOG_LL2
,
207 "fd_mac=%pM\n", mp
->fd_mac
);
208 ether_addr_copy(cvl_mac
, mp
->fd_mac
);
211 wp
= (struct fip_wwn_desc
*)desc
;
212 QEDF_INFO(&(qedf
->dbg_ctx
), QEDF_LOG_LL2
,
213 "fc_wwpn=%016llx.\n",
214 get_unaligned_be64(&wp
->fd_wwn
));
217 vp
= (struct fip_vn_desc
*)desc
;
218 QEDF_INFO(&(qedf
->dbg_ctx
), QEDF_LOG_LL2
,
219 "fd_fc_id=%x.\n", ntoh24(vp
->fd_fc_id
));
220 cvl_port_id
= ntoh24(vp
->fd_fc_id
);
223 /* Ignore anything else */
226 desc
= (struct fip_desc
*)((char *)desc
+ dlen
);
230 QEDF_INFO(&(qedf
->dbg_ctx
), QEDF_LOG_LL2
,
231 "cvl_port_id=%06x cvl_mac=%pM.\n", cvl_port_id
,
233 if (cvl_port_id
== qedf
->lport
->port_id
&&
234 ether_addr_equal(cvl_mac
,
235 qedf
->ctlr
.sel_fcf
->fcf_mac
)) {
236 fcoe_ctlr_link_down(&qedf
->ctlr
);
237 qedf_wait_for_upload(qedf
);
238 fcoe_ctlr_link_up(&qedf
->ctlr
);
242 /* Everything else is handled by libfcoe */
243 __skb_pull(skb
, ETH_HLEN
);
244 fcoe_ctlr_recv(&qedf
->ctlr
, skb
);
248 void qedf_update_src_mac(struct fc_lport
*lport
, u8
*addr
)
250 struct qedf_ctx
*qedf
= lport_priv(lport
);
252 QEDF_INFO(&(qedf
->dbg_ctx
), QEDF_LOG_DISC
,
253 "Setting data_src_addr=%pM.\n", addr
);
254 ether_addr_copy(qedf
->data_src_addr
, addr
);
257 u8
*qedf_get_src_mac(struct fc_lport
*lport
)
261 struct qedf_ctx
*qedf
= lport_priv(lport
);
263 /* We need to use the lport port_id to create the data_src_addr */
264 if (is_zero_ether_addr(qedf
->data_src_addr
)) {
265 hton24(port_id
, lport
->port_id
);
266 fc_fcoe_set_mac(mac
, port_id
);
267 qedf
->ctlr
.update_mac(lport
, mac
);
269 return qedf
->data_src_addr
;