1 /*******************************************************************************
3 * Intel Ethernet Controller XL710 Family Linux Driver
4 * Copyright(c) 2013 - 2015 Intel Corporation.
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms and conditions of the GNU General Public License,
8 * version 2, as published by the Free Software Foundation.
10 * This program is distributed in the hope it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
15 * You should have received a copy of the GNU General Public License along
16 * with this program. If not, see <http://www.gnu.org/licenses/>.
18 * The full GNU General Public License is included in this distribution in
19 * the file called "COPYING".
21 * Contact Information:
22 * e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
23 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
25 ******************************************************************************/
28 #include <linux/if_ether.h>
29 #include <scsi/scsi_cmnd.h>
30 #include <scsi/scsi_device.h>
31 #include <scsi/fc/fc_fs.h>
32 #include <scsi/fc/fc_fip.h>
33 #include <scsi/fc/fc_fcoe.h>
34 #include <scsi/libfc.h>
35 #include <scsi/libfcoe.h>
36 #include <uapi/linux/dcbnl.h>
39 #include "i40e_fcoe.h"
42 * i40e_rx_is_fcoe - returns true if the rx packet type is FCoE
43 * @ptype: the packet type field from rx descriptor write-back
45 static inline bool i40e_rx_is_fcoe(u16 ptype
)
47 return (ptype
>= I40E_RX_PTYPE_L2_FCOE_PAY3
) &&
48 (ptype
<= I40E_RX_PTYPE_L2_FCOE_VFT_FCOTHER
);
52 * i40e_fcoe_sof_is_class2 - returns true if this is a FC Class 2 SOF
53 * @sof: the FCoE start of frame delimiter
55 static inline bool i40e_fcoe_sof_is_class2(u8 sof
)
57 return (sof
== FC_SOF_I2
) || (sof
== FC_SOF_N2
);
61 * i40e_fcoe_sof_is_class3 - returns true if this is a FC Class 3 SOF
62 * @sof: the FCoE start of frame delimiter
64 static inline bool i40e_fcoe_sof_is_class3(u8 sof
)
66 return (sof
== FC_SOF_I3
) || (sof
== FC_SOF_N3
);
70 * i40e_fcoe_sof_is_supported - returns true if the FC SOF is supported by HW
71 * @sof: the input SOF value from the frame
73 static inline bool i40e_fcoe_sof_is_supported(u8 sof
)
75 return i40e_fcoe_sof_is_class2(sof
) ||
76 i40e_fcoe_sof_is_class3(sof
);
80 * i40e_fcoe_fc_sof - pull the SOF from FCoE header in the frame
81 * @skb: the frame whose EOF is to be pulled from
83 static inline int i40e_fcoe_fc_sof(struct sk_buff
*skb
, u8
*sof
)
85 *sof
= ((struct fcoe_hdr
*)skb_network_header(skb
))->fcoe_sof
;
87 if (!i40e_fcoe_sof_is_supported(*sof
))
93 * i40e_fcoe_eof_is_supported - returns true if the EOF is supported by HW
94 * @eof: the input EOF value from the frame
96 static inline bool i40e_fcoe_eof_is_supported(u8 eof
)
98 return (eof
== FC_EOF_N
) || (eof
== FC_EOF_T
) ||
99 (eof
== FC_EOF_NI
) || (eof
== FC_EOF_A
);
103 * i40e_fcoe_fc_eof - pull EOF from FCoE trailer in the frame
104 * @skb: the frame whose EOF is to be pulled from
106 static inline int i40e_fcoe_fc_eof(struct sk_buff
*skb
, u8
*eof
)
108 /* the first byte of the last dword is EOF */
109 skb_copy_bits(skb
, skb
->len
- 4, eof
, 1);
111 if (!i40e_fcoe_eof_is_supported(*eof
))
117 * i40e_fcoe_ctxt_eof - convert input FC EOF for descriptor programming
118 * @eof: the input eof value from the frame
120 * The FC EOF is converted to the value understood by HW for descriptor
121 * programming. Never call this w/o calling i40e_fcoe_eof_is_supported()
124 static inline u32
i40e_fcoe_ctxt_eof(u8 eof
)
128 return I40E_TX_DESC_CMD_L4T_EOFT_EOF_N
;
130 return I40E_TX_DESC_CMD_L4T_EOFT_EOF_T
;
132 return I40E_TX_DESC_CMD_L4T_EOFT_EOF_NI
;
134 return I40E_TX_DESC_CMD_L4T_EOFT_EOF_A
;
136 /* FIXME: still returns 0 */
137 pr_err("Unrecognized EOF %x\n", eof
);
143 * i40e_fcoe_xid_is_valid - returns true if the exchange id is valid
144 * @xid: the exchange id
146 static inline bool i40e_fcoe_xid_is_valid(u16 xid
)
148 return (xid
!= FC_XID_UNKNOWN
) && (xid
< I40E_FCOE_DDP_MAX
);
152 * i40e_fcoe_ddp_unmap - unmap the mapped sglist associated
154 * @ddp: sw DDP context
156 * Unmap the scatter-gather list associated with the given SW DDP context
158 * Returns: data length already ddp-ed in bytes
161 static inline void i40e_fcoe_ddp_unmap(struct i40e_pf
*pf
,
162 struct i40e_fcoe_ddp
*ddp
)
164 if (test_and_set_bit(__I40E_FCOE_DDP_UNMAPPED
, &ddp
->flags
))
168 dma_unmap_sg(&pf
->pdev
->dev
, ddp
->sgl
, ddp
->sgc
,
175 dma_pool_free(ddp
->pool
, ddp
->udl
, ddp
->udp
);
181 * i40e_fcoe_ddp_clear - clear the given SW DDP context
182 * @ddp - SW DDP context
184 static inline void i40e_fcoe_ddp_clear(struct i40e_fcoe_ddp
*ddp
)
186 memset(ddp
, 0, sizeof(struct i40e_fcoe_ddp
));
187 ddp
->xid
= FC_XID_UNKNOWN
;
188 ddp
->flags
= __I40E_FCOE_DDP_NONE
;
192 * i40e_fcoe_progid_is_fcoe - check if the prog_id is for FCoE
193 * @id: the prog id for the programming status Rx descriptor write-back
195 static inline bool i40e_fcoe_progid_is_fcoe(u8 id
)
197 return (id
== I40E_RX_PROG_STATUS_DESC_FCOE_CTXT_PROG_STATUS
) ||
198 (id
== I40E_RX_PROG_STATUS_DESC_FCOE_CTXT_INVL_STATUS
);
202 * i40e_fcoe_fc_get_xid - get xid from the frame header
203 * @fh: the fc frame header
205 * In case the incoming frame's exchange is originated from
206 * the initiator, then received frame's exchange id is ANDed
207 * with fc_cpu_mask bits to get the same cpu on which exchange
208 * was originated, otherwise just use the current cpu.
210 * Returns ox_id if exchange originator, rx_id if responder
212 static inline u16
i40e_fcoe_fc_get_xid(struct fc_frame_header
*fh
)
214 u32 f_ctl
= ntoh24(fh
->fh_f_ctl
);
216 return (f_ctl
& FC_FC_EX_CTX
) ?
217 be16_to_cpu(fh
->fh_ox_id
) :
218 be16_to_cpu(fh
->fh_rx_id
);
222 * i40e_fcoe_fc_frame_header - get fc frame header from skb
225 * This checks if there is a VLAN header and returns the data
226 * pointer to the start of the fc_frame_header.
228 * Returns pointer to the fc_frame_header
230 static inline struct fc_frame_header
*i40e_fcoe_fc_frame_header(
233 void *fh
= skb
->data
+ sizeof(struct fcoe_hdr
);
235 if (eth_hdr(skb
)->h_proto
== htons(ETH_P_8021Q
))
236 fh
+= sizeof(struct vlan_hdr
);
238 return (struct fc_frame_header
*)fh
;
242 * i40e_fcoe_ddp_put - release the DDP context for a given exchange id
243 * @netdev: the corresponding net_device
244 * @xid: the exchange id that corresponding DDP context will be released
246 * This is the implementation of net_device_ops.ndo_fcoe_ddp_done
247 * and it is expected to be called by ULD, i.e., FCP layer of libfc
248 * to release the corresponding ddp context when the I/O is done.
250 * Returns : data length already ddp-ed in bytes
252 static int i40e_fcoe_ddp_put(struct net_device
*netdev
, u16 xid
)
254 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
255 struct i40e_pf
*pf
= np
->vsi
->back
;
256 struct i40e_fcoe
*fcoe
= &pf
->fcoe
;
258 struct i40e_fcoe_ddp
*ddp
= &fcoe
->ddp
[xid
];
263 if (test_bit(__I40E_FCOE_DDP_DONE
, &ddp
->flags
))
265 i40e_fcoe_ddp_unmap(pf
, ddp
);
271 * i40e_fcoe_sw_init - sets up the HW for FCoE
274 * Returns 0 if FCoE is supported otherwise the error code
276 int i40e_init_pf_fcoe(struct i40e_pf
*pf
)
278 struct i40e_hw
*hw
= &pf
->hw
;
281 pf
->flags
&= ~I40E_FLAG_FCOE_ENABLED
;
282 pf
->num_fcoe_qps
= 0;
283 pf
->fcoe_hmc_cntx_num
= 0;
284 pf
->fcoe_hmc_filt_num
= 0;
286 if (!pf
->hw
.func_caps
.fcoe
) {
287 dev_info(&pf
->pdev
->dev
, "FCoE capability is disabled\n");
291 if (!pf
->hw
.func_caps
.dcb
) {
292 dev_warn(&pf
->pdev
->dev
,
293 "Hardware is not DCB capable not enabling FCoE.\n");
297 /* enable FCoE hash filter */
298 val
= rd32(hw
, I40E_PFQF_HENA(1));
299 val
|= 1 << (I40E_FILTER_PCTYPE_FCOE_OX
- 32);
300 val
|= 1 << (I40E_FILTER_PCTYPE_FCOE_RX
- 32);
301 val
&= I40E_PFQF_HENA_PTYPE_ENA_MASK
;
302 wr32(hw
, I40E_PFQF_HENA(1), val
);
305 pf
->flags
|= I40E_FLAG_FCOE_ENABLED
;
306 pf
->num_fcoe_qps
= I40E_DEFAULT_FCOE
;
308 /* Reserve 4K DDP contexts and 20K filter size for FCoE */
309 pf
->fcoe_hmc_cntx_num
= (1 << I40E_DMA_CNTX_SIZE_4K
) *
310 I40E_DMA_CNTX_BASE_SIZE
;
311 pf
->fcoe_hmc_filt_num
= pf
->fcoe_hmc_cntx_num
+
312 (1 << I40E_HASH_FILTER_SIZE_16K
) *
313 I40E_HASH_FILTER_BASE_SIZE
;
315 /* FCoE object: max 16K filter buckets and 4K DMA contexts */
316 pf
->filter_settings
.fcoe_filt_num
= I40E_HASH_FILTER_SIZE_16K
;
317 pf
->filter_settings
.fcoe_cntx_num
= I40E_DMA_CNTX_SIZE_4K
;
319 /* Setup max frame with FCoE_MTU plus L2 overheads */
320 val
= rd32(hw
, I40E_GLFCOE_RCTL
);
321 val
&= ~I40E_GLFCOE_RCTL_MAX_SIZE_MASK
;
322 val
|= ((FCOE_MTU
+ ETH_HLEN
+ VLAN_HLEN
+ ETH_FCS_LEN
)
323 << I40E_GLFCOE_RCTL_MAX_SIZE_SHIFT
);
324 wr32(hw
, I40E_GLFCOE_RCTL
, val
);
326 dev_info(&pf
->pdev
->dev
, "FCoE is supported.\n");
331 * i40e_get_fcoe_tc_map - Return TC map for FCoE APP
335 u8
i40e_get_fcoe_tc_map(struct i40e_pf
*pf
)
337 struct i40e_dcb_app_priority_table app
;
338 struct i40e_hw
*hw
= &pf
->hw
;
341 /* Get the FCoE APP TLV */
342 struct i40e_dcbx_config
*dcbcfg
= &hw
->local_dcbx_config
;
344 for (i
= 0; i
< dcbcfg
->numapps
; i
++) {
345 app
= dcbcfg
->app
[i
];
346 if (app
.selector
== IEEE_8021QAZ_APP_SEL_ETHERTYPE
&&
347 app
.protocolid
== ETH_P_FCOE
) {
348 tc
= dcbcfg
->etscfg
.prioritytable
[app
.priority
];
349 enabled_tc
|= (1 << tc
);
354 /* TC0 if there is no TC defined for FCoE APP TLV */
355 enabled_tc
= enabled_tc
? enabled_tc
: 0x1;
361 * i40e_fcoe_vsi_init - prepares the VSI context for creating a FCoE VSI
362 * @vsi: pointer to the associated VSI struct
363 * @ctxt: pointer to the associated VSI context to be passed to HW
365 * Returns 0 on success or < 0 on error
367 int i40e_fcoe_vsi_init(struct i40e_vsi
*vsi
, struct i40e_vsi_context
*ctxt
)
369 struct i40e_aqc_vsi_properties_data
*info
= &ctxt
->info
;
370 struct i40e_pf
*pf
= vsi
->back
;
371 struct i40e_hw
*hw
= &pf
->hw
;
374 if (!(pf
->flags
& I40E_FLAG_FCOE_ENABLED
)) {
375 dev_err(&pf
->pdev
->dev
,
376 "FCoE is not enabled for this device\n");
380 /* initialize the hardware for FCoE */
381 ctxt
->pf_num
= hw
->pf_id
;
383 ctxt
->uplink_seid
= vsi
->uplink_seid
;
384 ctxt
->connection_type
= I40E_AQ_VSI_CONN_TYPE_NORMAL
;
385 ctxt
->flags
= I40E_AQ_VSI_TYPE_PF
;
387 /* FCoE VSI would need the following sections */
388 info
->valid_sections
|= cpu_to_le16(I40E_AQ_VSI_PROP_QUEUE_OPT_VALID
);
390 /* FCoE VSI does not need these sections */
391 info
->valid_sections
&= cpu_to_le16(~(I40E_AQ_VSI_PROP_SECURITY_VALID
|
392 I40E_AQ_VSI_PROP_VLAN_VALID
|
393 I40E_AQ_VSI_PROP_CAS_PV_VALID
|
394 I40E_AQ_VSI_PROP_INGRESS_UP_VALID
|
395 I40E_AQ_VSI_PROP_EGRESS_UP_VALID
));
397 if (i40e_is_vsi_uplink_mode_veb(vsi
)) {
398 info
->valid_sections
|=
399 cpu_to_le16(I40E_AQ_VSI_PROP_SWITCH_VALID
);
401 cpu_to_le16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB
);
403 enabled_tc
= i40e_get_fcoe_tc_map(pf
);
404 i40e_vsi_setup_queue_map(vsi
, ctxt
, enabled_tc
, true);
406 /* set up queue option section: only enable FCoE */
407 info
->queueing_opt_flags
= I40E_AQ_VSI_QUE_OPT_FCOE_ENA
;
413 * i40e_fcoe_enable - this is the implementation of ndo_fcoe_enable,
414 * indicating the upper FCoE protocol stack is ready to use FCoE
417 * @netdev: pointer to the netdev that FCoE is created on
419 * Returns 0 on success
424 int i40e_fcoe_enable(struct net_device
*netdev
)
426 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
427 struct i40e_vsi
*vsi
= np
->vsi
;
428 struct i40e_pf
*pf
= vsi
->back
;
429 struct i40e_fcoe
*fcoe
= &pf
->fcoe
;
431 if (!(pf
->flags
& I40E_FLAG_FCOE_ENABLED
)) {
432 netdev_err(netdev
, "HW does not support FCoE.\n");
436 if (vsi
->type
!= I40E_VSI_FCOE
) {
437 netdev_err(netdev
, "interface does not support FCoE.\n");
441 atomic_inc(&fcoe
->refcnt
);
447 * i40e_fcoe_disable- disables FCoE for upper FCoE protocol stack.
448 * @dev: pointer to the netdev that FCoE is created on
450 * Returns 0 on success
453 int i40e_fcoe_disable(struct net_device
*netdev
)
455 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
456 struct i40e_vsi
*vsi
= np
->vsi
;
457 struct i40e_pf
*pf
= vsi
->back
;
458 struct i40e_fcoe
*fcoe
= &pf
->fcoe
;
460 if (!(pf
->flags
& I40E_FLAG_FCOE_ENABLED
)) {
461 netdev_err(netdev
, "device does not support FCoE\n");
464 if (vsi
->type
!= I40E_VSI_FCOE
)
467 if (!atomic_dec_and_test(&fcoe
->refcnt
))
470 netdev_info(netdev
, "FCoE disabled\n");
476 * i40e_fcoe_dma_pool_free - free the per cpu pool for FCoE DDP
477 * @fcoe: the FCoE sw object
478 * @dev: the device that the pool is associated with
479 * @cpu: the cpu for this pool
482 static void i40e_fcoe_dma_pool_free(struct i40e_fcoe
*fcoe
,
486 struct i40e_fcoe_ddp_pool
*ddp_pool
;
488 ddp_pool
= per_cpu_ptr(fcoe
->ddp_pool
, cpu
);
489 if (!ddp_pool
->pool
) {
490 dev_warn(dev
, "DDP pool already freed for cpu %d\n", cpu
);
493 dma_pool_destroy(ddp_pool
->pool
);
494 ddp_pool
->pool
= NULL
;
498 * i40e_fcoe_dma_pool_create - per cpu pool for FCoE DDP
499 * @fcoe: the FCoE sw object
500 * @dev: the device that the pool is associated with
501 * @cpu: the cpu for this pool
503 * Returns 0 on successful or non zero on failure
506 static int i40e_fcoe_dma_pool_create(struct i40e_fcoe
*fcoe
,
510 struct i40e_fcoe_ddp_pool
*ddp_pool
;
511 struct dma_pool
*pool
;
514 ddp_pool
= per_cpu_ptr(fcoe
->ddp_pool
, cpu
);
515 if (ddp_pool
&& ddp_pool
->pool
) {
516 dev_warn(dev
, "DDP pool already allocated for cpu %d\n", cpu
);
519 snprintf(pool_name
, sizeof(pool_name
), "i40e_fcoe_ddp_%d", cpu
);
520 pool
= dma_pool_create(pool_name
, dev
, I40E_FCOE_DDP_PTR_MAX
,
521 I40E_FCOE_DDP_PTR_ALIGN
, PAGE_SIZE
);
523 dev_err(dev
, "dma_pool_create %s failed\n", pool_name
);
526 ddp_pool
->pool
= pool
;
531 * i40e_fcoe_free_ddp_resources - release FCoE DDP resources
532 * @vsi: the vsi FCoE is associated with
535 void i40e_fcoe_free_ddp_resources(struct i40e_vsi
*vsi
)
537 struct i40e_pf
*pf
= vsi
->back
;
538 struct i40e_fcoe
*fcoe
= &pf
->fcoe
;
541 /* do nothing if not FCoE VSI */
542 if (vsi
->type
!= I40E_VSI_FCOE
)
545 /* do nothing if no DDP pools were allocated */
549 for (i
= 0; i
< I40E_FCOE_DDP_MAX
; i
++)
550 i40e_fcoe_ddp_put(vsi
->netdev
, i
);
552 for_each_possible_cpu(cpu
)
553 i40e_fcoe_dma_pool_free(fcoe
, &pf
->pdev
->dev
, cpu
);
555 free_percpu(fcoe
->ddp_pool
);
556 fcoe
->ddp_pool
= NULL
;
558 netdev_info(vsi
->netdev
, "VSI %d,%d FCoE DDP resources released\n",
563 * i40e_fcoe_setup_ddp_resources - allocate per cpu DDP resources
564 * @vsi: the VSI FCoE is associated with
566 * Returns 0 on successful or non zero on failure
569 int i40e_fcoe_setup_ddp_resources(struct i40e_vsi
*vsi
)
571 struct i40e_pf
*pf
= vsi
->back
;
572 struct device
*dev
= &pf
->pdev
->dev
;
573 struct i40e_fcoe
*fcoe
= &pf
->fcoe
;
577 if (vsi
->type
!= I40E_VSI_FCOE
)
580 /* do nothing if no DDP pools were allocated */
584 /* allocate per CPU memory to track DDP pools */
585 fcoe
->ddp_pool
= alloc_percpu(struct i40e_fcoe_ddp_pool
);
586 if (!fcoe
->ddp_pool
) {
587 dev_err(&pf
->pdev
->dev
, "failed to allocate percpu DDP\n");
591 /* allocate pci pool for each cpu */
592 for_each_possible_cpu(cpu
) {
593 if (!i40e_fcoe_dma_pool_create(fcoe
, dev
, cpu
))
596 dev_err(dev
, "failed to alloc DDP pool on cpu:%d\n", cpu
);
597 i40e_fcoe_free_ddp_resources(vsi
);
601 /* initialize the sw context */
602 for (i
= 0; i
< I40E_FCOE_DDP_MAX
; i
++)
603 i40e_fcoe_ddp_clear(&fcoe
->ddp
[i
]);
605 netdev_info(vsi
->netdev
, "VSI %d,%d FCoE DDP resources allocated\n",
612 * i40e_fcoe_handle_status - check the Programming Status for FCoE
613 * @rx_ring: the Rx ring for this descriptor
614 * @rx_desc: the Rx descriptor for Programming Status, not a packet descriptor.
616 * Check if this is the Rx Programming Status descriptor write-back for FCoE.
617 * This is used to verify if the context/filter programming or invalidation
618 * requested by SW to the HW is successful or not and take actions accordingly.
620 void i40e_fcoe_handle_status(struct i40e_ring
*rx_ring
,
621 union i40e_rx_desc
*rx_desc
, u8 prog_id
)
623 struct i40e_pf
*pf
= rx_ring
->vsi
->back
;
624 struct i40e_fcoe
*fcoe
= &pf
->fcoe
;
625 struct i40e_fcoe_ddp
*ddp
;
630 /* we only care for FCoE here */
631 if (!i40e_fcoe_progid_is_fcoe(prog_id
))
634 xid
= le32_to_cpu(rx_desc
->wb
.qword0
.hi_dword
.fcoe_param
) &
635 (I40E_FCOE_DDP_MAX
- 1);
637 if (!i40e_fcoe_xid_is_valid(xid
))
640 ddp
= &fcoe
->ddp
[xid
];
641 WARN_ON(xid
!= ddp
->xid
);
643 qw
= le64_to_cpu(rx_desc
->wb
.qword1
.status_error_len
);
644 error
= (qw
& I40E_RX_PROG_STATUS_DESC_QW1_ERROR_MASK
) >>
645 I40E_RX_PROG_STATUS_DESC_QW1_ERROR_SHIFT
;
647 /* DDP context programming status: failure or success */
648 if (prog_id
== I40E_RX_PROG_STATUS_DESC_FCOE_CTXT_PROG_STATUS
) {
649 if (I40E_RX_PROG_FCOE_ERROR_TBL_FULL(error
)) {
650 dev_err(&pf
->pdev
->dev
, "xid %x ddp->xid %x TABLE FULL\n",
652 ddp
->prerr
|= I40E_RX_PROG_FCOE_ERROR_TBL_FULL_BIT
;
654 if (I40E_RX_PROG_FCOE_ERROR_CONFLICT(error
)) {
655 dev_err(&pf
->pdev
->dev
, "xid %x ddp->xid %x CONFLICT\n",
657 ddp
->prerr
|= I40E_RX_PROG_FCOE_ERROR_CONFLICT_BIT
;
661 /* DDP context invalidation status: failure or success */
662 if (prog_id
== I40E_RX_PROG_STATUS_DESC_FCOE_CTXT_INVL_STATUS
) {
663 if (I40E_RX_PROG_FCOE_ERROR_INVLFAIL(error
)) {
664 dev_err(&pf
->pdev
->dev
, "xid %x ddp->xid %x INVALIDATION FAILURE\n",
666 ddp
->prerr
|= I40E_RX_PROG_FCOE_ERROR_INVLFAIL_BIT
;
668 /* clear the flag so we can retry invalidation */
669 clear_bit(__I40E_FCOE_DDP_ABORTED
, &ddp
->flags
);
673 i40e_fcoe_ddp_unmap(pf
, ddp
);
674 i40e_fcoe_ddp_clear(ddp
);
678 * i40e_fcoe_handle_offload - check ddp status and mark it done
679 * @adapter: i40e adapter
680 * @rx_desc: advanced rx descriptor
681 * @skb: the skb holding the received data
683 * This checks ddp status.
685 * Returns : < 0 indicates an error or not a FCOE ddp, 0 indicates
686 * not passing the skb to ULD, > 0 indicates is the length of data
690 int i40e_fcoe_handle_offload(struct i40e_ring
*rx_ring
,
691 union i40e_rx_desc
*rx_desc
,
694 struct i40e_pf
*pf
= rx_ring
->vsi
->back
;
695 struct i40e_fcoe
*fcoe
= &pf
->fcoe
;
696 struct fc_frame_header
*fh
= NULL
;
697 struct i40e_fcoe_ddp
*ddp
= NULL
;
705 /* check this rxd is for programming status */
706 qw
= le64_to_cpu(rx_desc
->wb
.qword1
.status_error_len
);
707 /* packet descriptor, check packet type */
708 ptype
= (qw
& I40E_RXD_QW1_PTYPE_MASK
) >> I40E_RXD_QW1_PTYPE_SHIFT
;
709 if (!i40e_rx_is_fcoe(ptype
))
712 error
= (qw
& I40E_RXD_QW1_ERROR_MASK
) >> I40E_RXD_QW1_ERROR_SHIFT
;
713 fcerr
= (error
>> I40E_RX_DESC_ERROR_L3L4E_SHIFT
) &
714 I40E_RX_DESC_FCOE_ERROR_MASK
;
716 /* check stateless offload error */
717 if (unlikely(fcerr
== I40E_RX_DESC_ERROR_L3L4E_PROT
)) {
718 dev_err(&pf
->pdev
->dev
, "Protocol Error\n");
719 skb
->ip_summed
= CHECKSUM_NONE
;
721 skb
->ip_summed
= CHECKSUM_UNNECESSARY
;
724 /* check hw status on ddp */
725 status
= (qw
& I40E_RXD_QW1_STATUS_MASK
) >> I40E_RXD_QW1_STATUS_SHIFT
;
726 fltstat
= (status
>> I40E_RX_DESC_STATUS_FLTSTAT_SHIFT
) &
727 I40E_RX_DESC_FLTSTAT_FCMASK
;
729 /* now we are ready to check DDP */
730 fh
= i40e_fcoe_fc_frame_header(skb
);
731 xid
= i40e_fcoe_fc_get_xid(fh
);
732 if (!i40e_fcoe_xid_is_valid(xid
))
735 /* non DDP normal receive, return to the protocol stack */
736 if (fltstat
== I40E_RX_DESC_FLTSTAT_NOMTCH
)
739 /* do we have a sw ddp context setup ? */
740 ddp
= &fcoe
->ddp
[xid
];
744 /* fetch xid from hw rxd wb, which should match up the sw ctxt */
745 xid
= le16_to_cpu(rx_desc
->wb
.qword0
.lo_dword
.mirr_fcoe
.fcoe_ctx_id
);
746 if (ddp
->xid
!= xid
) {
747 dev_err(&pf
->pdev
->dev
, "xid 0x%x does not match ctx_xid 0x%x\n",
752 /* the same exchange has already errored out */
754 dev_err(&pf
->pdev
->dev
, "xid 0x%x fcerr 0x%x reported fcer 0x%x\n",
755 xid
, ddp
->fcerr
, fcerr
);
759 /* fcoe param is valid by now with correct DDPed length */
760 ddp
->len
= le32_to_cpu(rx_desc
->wb
.qword0
.hi_dword
.fcoe_param
);
762 /* header posting only, useful only for target mode and debugging */
763 if (fltstat
== I40E_RX_DESC_FLTSTAT_DDP
) {
764 /* For target mode, we get header of the last packet but it
765 * does not have the FCoE trailer field, i.e., CRC and EOF
766 * Ordered Set since they are offloaded by the HW, so fill
767 * it up correspondingly to allow the packet to pass through
768 * to the upper protocol stack.
770 u32 f_ctl
= ntoh24(fh
->fh_f_ctl
);
772 if ((f_ctl
& FC_FC_END_SEQ
) &&
773 (fh
->fh_r_ctl
== FC_RCTL_DD_SOL_DATA
)) {
774 struct fcoe_crc_eof
*crc
= NULL
;
776 crc
= (struct fcoe_crc_eof
*)skb_put(skb
, sizeof(*crc
));
777 crc
->fcoe_eof
= FC_EOF_T
;
779 /* otherwise, drop the header only frame */
786 /* either we got RSP or we have an error, unmap DMA in both cases */
787 i40e_fcoe_ddp_unmap(pf
, ddp
);
788 if (ddp
->len
&& !ddp
->fcerr
) {
792 i40e_fcoe_ddp_clear(ddp
);
794 pkts
= DIV_ROUND_UP(rc
, 2048);
795 rx_ring
->stats
.bytes
+= rc
;
796 rx_ring
->stats
.packets
+= pkts
;
797 rx_ring
->q_vector
->rx
.total_bytes
+= rc
;
798 rx_ring
->q_vector
->rx
.total_packets
+= pkts
;
799 set_bit(__I40E_FCOE_DDP_DONE
, &ddp
->flags
);
807 * i40e_fcoe_ddp_setup - called to set up ddp context
808 * @netdev: the corresponding net_device
809 * @xid: the exchange id requesting ddp
810 * @sgl: the scatter-gather list for this request
811 * @sgc: the number of scatter-gather items
812 * @target_mode: indicates this is a DDP request for target
814 * Returns : 1 for success and 0 for no DDP on this I/O
816 static int i40e_fcoe_ddp_setup(struct net_device
*netdev
, u16 xid
,
817 struct scatterlist
*sgl
, unsigned int sgc
,
820 static const unsigned int bufflen
= I40E_FCOE_DDP_BUF_MIN
;
821 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
822 struct i40e_fcoe_ddp_pool
*ddp_pool
;
823 struct i40e_pf
*pf
= np
->vsi
->back
;
824 struct i40e_fcoe
*fcoe
= &pf
->fcoe
;
825 unsigned int i
, j
, dmacount
;
826 struct i40e_fcoe_ddp
*ddp
;
827 unsigned int firstoff
= 0;
828 unsigned int thisoff
= 0;
829 unsigned int thislen
= 0;
830 struct scatterlist
*sg
;
834 if (xid
>= I40E_FCOE_DDP_MAX
) {
835 dev_warn(&pf
->pdev
->dev
, "xid=0x%x out-of-range\n", xid
);
839 /* no DDP if we are already down or resetting */
840 if (test_bit(__I40E_DOWN
, &pf
->state
) ||
841 test_bit(__I40E_NEEDS_RESTART
, &pf
->state
)) {
842 dev_info(&pf
->pdev
->dev
, "xid=0x%x device in reset/down\n",
847 ddp
= &fcoe
->ddp
[xid
];
849 dev_info(&pf
->pdev
->dev
, "xid 0x%x w/ non-null sgl=%p nents=%d\n",
850 xid
, ddp
->sgl
, ddp
->sgc
);
853 i40e_fcoe_ddp_clear(ddp
);
855 if (!fcoe
->ddp_pool
) {
856 dev_info(&pf
->pdev
->dev
, "No DDP pool, xid 0x%x\n", xid
);
860 ddp_pool
= per_cpu_ptr(fcoe
->ddp_pool
, get_cpu());
861 if (!ddp_pool
->pool
) {
862 dev_info(&pf
->pdev
->dev
, "No percpu ddp pool, xid 0x%x\n", xid
);
866 /* setup dma from scsi command sgl */
867 dmacount
= dma_map_sg(&pf
->pdev
->dev
, sgl
, sgc
, DMA_FROM_DEVICE
);
869 dev_info(&pf
->pdev
->dev
, "dma_map_sg for sgl %p, sgc %d failed\n",
871 goto out_noddp_unmap
;
874 /* alloc the udl from our ddp pool */
875 ddp
->udl
= dma_pool_alloc(ddp_pool
->pool
, GFP_ATOMIC
, &ddp
->udp
);
877 dev_info(&pf
->pdev
->dev
,
878 "Failed allocated ddp context, xid 0x%x\n", xid
);
879 goto out_noddp_unmap
;
884 for_each_sg(sgl
, sg
, dmacount
, i
) {
885 addr
= sg_dma_address(sg
);
886 len
= sg_dma_len(sg
);
889 /* max number of buffers allowed in one DDP context */
890 if (j
>= I40E_FCOE_DDP_BUFFCNT_MAX
) {
891 dev_info(&pf
->pdev
->dev
,
892 "xid=%x:%d,%d,%d:addr=%llx not enough descriptors\n",
893 xid
, i
, j
, dmacount
, (u64
)addr
);
897 /* get the offset of length of current buffer */
898 thisoff
= addr
& ((dma_addr_t
)bufflen
- 1);
899 thislen
= min_t(unsigned int, (bufflen
- thisoff
), len
);
900 /* all but the 1st buffer (j == 0)
901 * must be aligned on bufflen
903 if ((j
!= 0) && (thisoff
))
906 /* all but the last buffer
907 * ((i == (dmacount - 1)) && (thislen == len))
908 * must end at bufflen
910 if (((i
!= (dmacount
- 1)) || (thislen
!= len
)) &&
911 ((thislen
+ thisoff
) != bufflen
))
914 ddp
->udl
[j
] = (u64
)(addr
- thisoff
);
915 /* only the first buffer may have none-zero offset */
923 /* only the last buffer may have non-full bufflen */
924 ddp
->lastsize
= thisoff
+ thislen
;
925 ddp
->firstoff
= firstoff
;
927 ddp
->pool
= ddp_pool
->pool
;
932 set_bit(__I40E_FCOE_DDP_TARGET
, &ddp
->flags
);
933 set_bit(__I40E_FCOE_DDP_INITALIZED
, &ddp
->flags
);
936 return 1; /* Success */
939 dma_pool_free(ddp
->pool
, ddp
->udl
, ddp
->udp
);
940 i40e_fcoe_ddp_clear(ddp
);
943 dma_unmap_sg(&pf
->pdev
->dev
, sgl
, sgc
, DMA_FROM_DEVICE
);
950 * i40e_fcoe_ddp_get - called to set up ddp context in initiator mode
951 * @netdev: the corresponding net_device
952 * @xid: the exchange id requesting ddp
953 * @sgl: the scatter-gather list for this request
954 * @sgc: the number of scatter-gather items
956 * This is the implementation of net_device_ops.ndo_fcoe_ddp_setup
957 * and is expected to be called from ULD, e.g., FCP layer of libfc
958 * to set up ddp for the corresponding xid of the given sglist for
959 * the corresponding I/O.
961 * Returns : 1 for success and 0 for no ddp
963 static int i40e_fcoe_ddp_get(struct net_device
*netdev
, u16 xid
,
964 struct scatterlist
*sgl
, unsigned int sgc
)
966 return i40e_fcoe_ddp_setup(netdev
, xid
, sgl
, sgc
, 0);
970 * i40e_fcoe_ddp_target - called to set up ddp context in target mode
971 * @netdev: the corresponding net_device
972 * @xid: the exchange id requesting ddp
973 * @sgl: the scatter-gather list for this request
974 * @sgc: the number of scatter-gather items
976 * This is the implementation of net_device_ops.ndo_fcoe_ddp_target
977 * and is expected to be called from ULD, e.g., FCP layer of libfc
978 * to set up ddp for the corresponding xid of the given sglist for
979 * the corresponding I/O. The DDP in target mode is a write I/O request
980 * from the initiator.
982 * Returns : 1 for success and 0 for no ddp
984 static int i40e_fcoe_ddp_target(struct net_device
*netdev
, u16 xid
,
985 struct scatterlist
*sgl
, unsigned int sgc
)
987 return i40e_fcoe_ddp_setup(netdev
, xid
, sgl
, sgc
, 1);
991 * i40e_fcoe_program_ddp - programs the HW DDP related descriptors
992 * @tx_ring: transmit ring for this packet
993 * @skb: the packet to be sent out
994 * @sof: the SOF to indicate class of service
996 * Determine if it is READ/WRITE command, and finds out if there is
997 * a matching SW DDP context for this command. DDP is applicable
998 * only in case of READ if initiator or WRITE in case of
999 * responder (via checking XFER_RDY).
1001 * Note: caller checks sof and ddp sw context
1006 static void i40e_fcoe_program_ddp(struct i40e_ring
*tx_ring
,
1007 struct sk_buff
*skb
,
1008 struct i40e_fcoe_ddp
*ddp
, u8 sof
)
1010 struct i40e_fcoe_filter_context_desc
*filter_desc
= NULL
;
1011 struct i40e_fcoe_queue_context_desc
*queue_desc
= NULL
;
1012 struct i40e_fcoe_ddp_context_desc
*ddp_desc
= NULL
;
1013 struct i40e_pf
*pf
= tx_ring
->vsi
->back
;
1014 u16 i
= tx_ring
->next_to_use
;
1015 struct fc_frame_header
*fh
;
1016 u64 flags_rsvd_lanq
= 0;
1019 /* check if abort is still pending */
1020 if (test_bit(__I40E_FCOE_DDP_ABORTED
, &ddp
->flags
)) {
1021 dev_warn(&pf
->pdev
->dev
,
1022 "DDP abort is still pending xid:%hx and ddp->flags:%lx:\n",
1023 ddp
->xid
, ddp
->flags
);
1027 /* set the flag to indicate this is programmed */
1028 if (test_and_set_bit(__I40E_FCOE_DDP_PROGRAMMED
, &ddp
->flags
)) {
1029 dev_warn(&pf
->pdev
->dev
,
1030 "DDP is already programmed for xid:%hx and ddp->flags:%lx:\n",
1031 ddp
->xid
, ddp
->flags
);
1035 /* Prepare the DDP context descriptor */
1036 ddp_desc
= I40E_DDP_CONTEXT_DESC(tx_ring
, i
);
1038 if (i
== tx_ring
->count
)
1041 ddp_desc
->type_cmd_foff_lsize
=
1042 cpu_to_le64(I40E_TX_DESC_DTYPE_DDP_CTX
|
1043 ((u64
)I40E_FCOE_DDP_CTX_DESC_BSIZE_4K
<<
1044 I40E_FCOE_DDP_CTX_QW1_CMD_SHIFT
) |
1045 ((u64
)ddp
->firstoff
<<
1046 I40E_FCOE_DDP_CTX_QW1_FOFF_SHIFT
) |
1047 ((u64
)ddp
->lastsize
<<
1048 I40E_FCOE_DDP_CTX_QW1_LSIZE_SHIFT
));
1049 ddp_desc
->rsvd
= cpu_to_le64(0);
1051 /* target mode needs last packet in the sequence */
1052 target_mode
= test_bit(__I40E_FCOE_DDP_TARGET
, &ddp
->flags
);
1054 ddp_desc
->type_cmd_foff_lsize
|=
1055 cpu_to_le64(I40E_FCOE_DDP_CTX_DESC_LASTSEQH
);
1057 /* Prepare queue_context descriptor */
1058 queue_desc
= I40E_QUEUE_CONTEXT_DESC(tx_ring
, i
++);
1059 if (i
== tx_ring
->count
)
1061 queue_desc
->dmaindx_fbase
= cpu_to_le64(ddp
->xid
| ((u64
)ddp
->udp
));
1062 queue_desc
->flen_tph
= cpu_to_le64(ddp
->list_len
|
1063 ((u64
)(I40E_FCOE_QUEUE_CTX_DESC_TPHRDESC
|
1064 I40E_FCOE_QUEUE_CTX_DESC_TPHDATA
) <<
1065 I40E_FCOE_QUEUE_CTX_QW1_TPH_SHIFT
));
1067 /* Prepare filter_context_desc */
1068 filter_desc
= I40E_FILTER_CONTEXT_DESC(tx_ring
, i
);
1070 if (i
== tx_ring
->count
)
1073 fh
= (struct fc_frame_header
*)skb_transport_header(skb
);
1074 filter_desc
->param
= cpu_to_le32(ntohl(fh
->fh_parm_offset
));
1075 filter_desc
->seqn
= cpu_to_le16(ntohs(fh
->fh_seq_cnt
));
1076 filter_desc
->rsvd_dmaindx
= cpu_to_le16(ddp
->xid
<<
1077 I40E_FCOE_FILTER_CTX_QW0_DMAINDX_SHIFT
);
1079 flags_rsvd_lanq
= I40E_FCOE_FILTER_CTX_DESC_CTYP_DDP
;
1080 flags_rsvd_lanq
|= (u64
)(target_mode
?
1081 I40E_FCOE_FILTER_CTX_DESC_ENODE_RSP
:
1082 I40E_FCOE_FILTER_CTX_DESC_ENODE_INIT
);
1084 flags_rsvd_lanq
|= (u64
)((sof
== FC_SOF_I2
|| sof
== FC_SOF_N2
) ?
1085 I40E_FCOE_FILTER_CTX_DESC_FC_CLASS2
:
1086 I40E_FCOE_FILTER_CTX_DESC_FC_CLASS3
);
1088 flags_rsvd_lanq
|= ((u64
)skb
->queue_mapping
<<
1089 I40E_FCOE_FILTER_CTX_QW1_LANQINDX_SHIFT
);
1090 filter_desc
->flags_rsvd_lanq
= cpu_to_le64(flags_rsvd_lanq
);
1092 /* By this time, all offload related descriptors has been programmed */
1093 tx_ring
->next_to_use
= i
;
1097 * i40e_fcoe_invalidate_ddp - invalidates DDP in case of abort
1098 * @tx_ring: transmit ring for this packet
1099 * @skb: the packet associated w/ this DDP invalidation, i.e., ABTS
1100 * @ddp: the SW DDP context for this DDP
1102 * Programs the Tx context descriptor to do DDP invalidation.
1104 static void i40e_fcoe_invalidate_ddp(struct i40e_ring
*tx_ring
,
1105 struct sk_buff
*skb
,
1106 struct i40e_fcoe_ddp
*ddp
)
1108 struct i40e_tx_context_desc
*context_desc
;
1111 if (test_and_set_bit(__I40E_FCOE_DDP_ABORTED
, &ddp
->flags
))
1114 i
= tx_ring
->next_to_use
;
1115 context_desc
= I40E_TX_CTXTDESC(tx_ring
, i
);
1117 if (i
== tx_ring
->count
)
1120 context_desc
->tunneling_params
= cpu_to_le32(0);
1121 context_desc
->l2tag2
= cpu_to_le16(0);
1122 context_desc
->rsvd
= cpu_to_le16(0);
1123 context_desc
->type_cmd_tso_mss
= cpu_to_le64(
1124 I40E_TX_DESC_DTYPE_FCOE_CTX
|
1125 (I40E_FCOE_TX_CTX_DESC_OPCODE_DDP_CTX_INVL
<<
1126 I40E_TXD_CTX_QW1_CMD_SHIFT
) |
1127 (I40E_FCOE_TX_CTX_DESC_OPCODE_SINGLE_SEND
<<
1128 I40E_TXD_CTX_QW1_CMD_SHIFT
));
1129 tx_ring
->next_to_use
= i
;
1133 * i40e_fcoe_handle_ddp - check we should setup or invalidate DDP
1134 * @tx_ring: transmit ring for this packet
1135 * @skb: the packet to be sent out
1136 * @sof: the SOF to indicate class of service
1138 * Determine if it is ABTS/READ/XFER_RDY, and finds out if there is
1139 * a matching SW DDP context for this command. DDP is applicable
1140 * only in case of READ if initiator or WRITE in case of
1141 * responder (via checking XFER_RDY). In case this is an ABTS, send
1142 * just invalidate the context.
1144 static void i40e_fcoe_handle_ddp(struct i40e_ring
*tx_ring
,
1145 struct sk_buff
*skb
, u8 sof
)
1147 struct i40e_pf
*pf
= tx_ring
->vsi
->back
;
1148 struct i40e_fcoe
*fcoe
= &pf
->fcoe
;
1149 struct fc_frame_header
*fh
;
1150 struct i40e_fcoe_ddp
*ddp
;
1155 fh
= (struct fc_frame_header
*)skb_transport_header(skb
);
1156 f_ctl
= ntoh24(fh
->fh_f_ctl
);
1157 r_ctl
= fh
->fh_r_ctl
;
1160 if ((r_ctl
== FC_RCTL_DD_DATA_DESC
) && (f_ctl
& FC_FC_EX_CTX
)) {
1161 /* exchange responder? if so, XFER_RDY for write */
1162 xid
= ntohs(fh
->fh_rx_id
);
1163 if (i40e_fcoe_xid_is_valid(xid
)) {
1164 ddp
= &fcoe
->ddp
[xid
];
1165 if ((ddp
->xid
== xid
) &&
1166 (test_bit(__I40E_FCOE_DDP_TARGET
, &ddp
->flags
)))
1167 i40e_fcoe_program_ddp(tx_ring
, skb
, ddp
, sof
);
1169 } else if (r_ctl
== FC_RCTL_DD_UNSOL_CMD
) {
1170 /* exchange originator, check READ cmd */
1171 xid
= ntohs(fh
->fh_ox_id
);
1172 if (i40e_fcoe_xid_is_valid(xid
)) {
1173 ddp
= &fcoe
->ddp
[xid
];
1174 if ((ddp
->xid
== xid
) &&
1175 (!test_bit(__I40E_FCOE_DDP_TARGET
, &ddp
->flags
)))
1176 i40e_fcoe_program_ddp(tx_ring
, skb
, ddp
, sof
);
1178 } else if (r_ctl
== FC_RCTL_BA_ABTS
) {
1179 /* exchange originator, check ABTS */
1180 xid
= ntohs(fh
->fh_ox_id
);
1181 if (i40e_fcoe_xid_is_valid(xid
)) {
1182 ddp
= &fcoe
->ddp
[xid
];
1183 if ((ddp
->xid
== xid
) &&
1184 (!test_bit(__I40E_FCOE_DDP_TARGET
, &ddp
->flags
)))
1185 i40e_fcoe_invalidate_ddp(tx_ring
, skb
, ddp
);
1191 * i40e_fcoe_tso - set up FCoE TSO
1192 * @tx_ring: ring to send buffer on
1194 * @tx_flags: collected send information
1195 * @hdr_len: the tso header length
1196 * @sof: the SOF to indicate class of service
1198 * Note must already have sof checked to be either class 2 or class 3 before
1199 * calling this function.
1201 * Returns 1 to indicate sequence segmentation offload is properly setup
1202 * or returns 0 to indicate no tso is needed, otherwise returns error
1203 * code to drop the frame.
1205 static int i40e_fcoe_tso(struct i40e_ring
*tx_ring
,
1206 struct sk_buff
*skb
,
1207 u32 tx_flags
, u8
*hdr_len
, u8 sof
)
1209 struct i40e_tx_context_desc
*context_desc
;
1210 u32 cd_type
, cd_cmd
, cd_tso_len
, cd_mss
;
1211 struct fc_frame_header
*fh
;
1212 u64 cd_type_cmd_tso_mss
;
1214 /* must match gso type as FCoE */
1215 if (!skb_is_gso(skb
))
1218 /* is it the expected gso type for FCoE ?*/
1219 if (skb_shinfo(skb
)->gso_type
!= SKB_GSO_FCOE
) {
1220 netdev_err(skb
->dev
,
1221 "wrong gso type %d:expecting SKB_GSO_FCOE\n",
1222 skb_shinfo(skb
)->gso_type
);
1226 /* header and trailer are inserted by hw */
1227 *hdr_len
= skb_transport_offset(skb
) + sizeof(struct fc_frame_header
) +
1228 sizeof(struct fcoe_crc_eof
);
1230 /* check sof to decide a class 2 or 3 TSO */
1231 if (likely(i40e_fcoe_sof_is_class3(sof
)))
1232 cd_cmd
= I40E_FCOE_TX_CTX_DESC_OPCODE_TSO_FC_CLASS3
;
1234 cd_cmd
= I40E_FCOE_TX_CTX_DESC_OPCODE_TSO_FC_CLASS2
;
1236 /* param field valid? */
1237 fh
= (struct fc_frame_header
*)skb_transport_header(skb
);
1238 if (fh
->fh_f_ctl
[2] & FC_FC_REL_OFF
)
1239 cd_cmd
|= I40E_FCOE_TX_CTX_DESC_RELOFF
;
1241 /* fill the field values */
1242 cd_type
= I40E_TX_DESC_DTYPE_FCOE_CTX
;
1243 cd_tso_len
= skb
->len
- *hdr_len
;
1244 cd_mss
= skb_shinfo(skb
)->gso_size
;
1245 cd_type_cmd_tso_mss
=
1246 ((u64
)cd_type
<< I40E_TXD_CTX_QW1_DTYPE_SHIFT
) |
1247 ((u64
)cd_cmd
<< I40E_TXD_CTX_QW1_CMD_SHIFT
) |
1248 ((u64
)cd_tso_len
<< I40E_TXD_CTX_QW1_TSO_LEN_SHIFT
) |
1249 ((u64
)cd_mss
<< I40E_TXD_CTX_QW1_MSS_SHIFT
);
1251 /* grab the next descriptor */
1252 context_desc
= I40E_TX_CTXTDESC(tx_ring
, tx_ring
->next_to_use
);
1253 tx_ring
->next_to_use
++;
1254 if (tx_ring
->next_to_use
== tx_ring
->count
)
1255 tx_ring
->next_to_use
= 0;
1257 context_desc
->tunneling_params
= 0;
1258 context_desc
->l2tag2
= cpu_to_le16((tx_flags
& I40E_TX_FLAGS_VLAN_MASK
)
1259 >> I40E_TX_FLAGS_VLAN_SHIFT
);
1260 context_desc
->type_cmd_tso_mss
= cpu_to_le64(cd_type_cmd_tso_mss
);
1266 * i40e_fcoe_tx_map - build the tx descriptor
1267 * @tx_ring: ring to send buffer on
1269 * @first: first buffer info buffer to use
1270 * @tx_flags: collected send information
1271 * @hdr_len: ptr to the size of the packet header
1272 * @eof: the frame eof value
1274 * Note, for FCoE, sof and eof are already checked
1276 static void i40e_fcoe_tx_map(struct i40e_ring
*tx_ring
,
1277 struct sk_buff
*skb
,
1278 struct i40e_tx_buffer
*first
,
1279 u32 tx_flags
, u8 hdr_len
, u8 eof
)
1286 td_cmd
= I40E_TX_DESC_CMD_ICRC
;
1289 maclen
= skb_network_offset(skb
);
1290 if (tx_flags
& I40E_TX_FLAGS_SW_VLAN
)
1291 maclen
+= sizeof(struct vlan_hdr
);
1293 if (skb
->protocol
== htons(ETH_P_FCOE
)) {
1294 /* for FCoE, maclen should exclude ether type */
1296 /* setup type as FCoE and EOF insertion */
1297 td_cmd
|= (I40E_TX_DESC_CMD_FCOET
| i40e_fcoe_ctxt_eof(eof
));
1298 /* setup FCoELEN and FCLEN */
1299 td_offset
|= ((((sizeof(struct fcoe_hdr
) + 2) >> 2) <<
1300 I40E_TX_DESC_LENGTH_IPLEN_SHIFT
) |
1301 ((sizeof(struct fc_frame_header
) >> 2) <<
1302 I40E_TX_DESC_LENGTH_L4_FC_LEN_SHIFT
));
1303 /* trim to exclude trailer */
1304 pskb_trim(skb
, skb
->len
- sizeof(struct fcoe_crc_eof
));
1307 /* MACLEN is ether header length in words not bytes */
1308 td_offset
|= (maclen
>> 1) << I40E_TX_DESC_LENGTH_MACLEN_SHIFT
;
1310 return i40e_tx_map(tx_ring
, skb
, first
, tx_flags
, hdr_len
,
1315 * i40e_fcoe_set_skb_header - adjust skb header point for FIP/FCoE/FC
1316 * @skb: the skb to be adjusted
1318 * Returns true if this skb is a FCoE/FIP or VLAN carried FCoE/FIP and then
1319 * adjusts the skb header pointers correspondingly. Otherwise, returns false.
1321 static inline int i40e_fcoe_set_skb_header(struct sk_buff
*skb
)
1323 __be16 protocol
= skb
->protocol
;
1325 skb_reset_mac_header(skb
);
1326 skb
->mac_len
= sizeof(struct ethhdr
);
1327 if (protocol
== htons(ETH_P_8021Q
)) {
1328 struct vlan_ethhdr
*veth
= (struct vlan_ethhdr
*)eth_hdr(skb
);
1330 protocol
= veth
->h_vlan_encapsulated_proto
;
1331 skb
->mac_len
+= sizeof(struct vlan_hdr
);
1334 /* FCoE or FIP only */
1335 if ((protocol
!= htons(ETH_P_FIP
)) &&
1336 (protocol
!= htons(ETH_P_FCOE
)))
1339 /* set header to L2 of FCoE/FIP */
1340 skb_set_network_header(skb
, skb
->mac_len
);
1341 if (protocol
== htons(ETH_P_FIP
))
1344 /* set header to L3 of FC */
1345 skb_set_transport_header(skb
, skb
->mac_len
+ sizeof(struct fcoe_hdr
));
1350 * i40e_fcoe_xmit_frame - transmit buffer
1352 * @netdev: the fcoe netdev
1354 * Returns 0 if sent, else an error code
1356 static netdev_tx_t
i40e_fcoe_xmit_frame(struct sk_buff
*skb
,
1357 struct net_device
*netdev
)
1359 struct i40e_netdev_priv
*np
= netdev_priv(skb
->dev
);
1360 struct i40e_vsi
*vsi
= np
->vsi
;
1361 struct i40e_ring
*tx_ring
= vsi
->tx_rings
[skb
->queue_mapping
];
1362 struct i40e_tx_buffer
*first
;
1369 if (i40e_fcoe_set_skb_header(skb
))
1372 if (!i40e_xmit_descriptor_count(skb
, tx_ring
))
1373 return NETDEV_TX_BUSY
;
1375 /* prepare the xmit flags */
1376 if (i40e_tx_prepare_vlan_flags(skb
, tx_ring
, &tx_flags
))
1379 /* record the location of the first descriptor for this packet */
1380 first
= &tx_ring
->tx_bi
[tx_ring
->next_to_use
];
1382 /* FIP is a regular L2 traffic w/o offload */
1383 if (skb
->protocol
== htons(ETH_P_FIP
))
1386 /* check sof and eof, only supports FC Class 2 or 3 */
1387 if (i40e_fcoe_fc_sof(skb
, &sof
) || i40e_fcoe_fc_eof(skb
, &eof
)) {
1388 netdev_err(netdev
, "SOF/EOF error:%02x - %02x\n", sof
, eof
);
1392 /* always do FCCRC for FCoE */
1393 tx_flags
|= I40E_TX_FLAGS_FCCRC
;
1395 /* check we should do sequence offload */
1396 fso
= i40e_fcoe_tso(tx_ring
, skb
, tx_flags
, &hdr_len
, sof
);
1400 tx_flags
|= I40E_TX_FLAGS_FSO
;
1402 i40e_fcoe_handle_ddp(tx_ring
, skb
, sof
);
1405 /* send out the packet */
1406 i40e_fcoe_tx_map(tx_ring
, skb
, first
, tx_flags
, hdr_len
, eof
);
1408 i40e_maybe_stop_tx(tx_ring
, DESC_NEEDED
);
1409 return NETDEV_TX_OK
;
1412 dev_kfree_skb_any(skb
);
1413 return NETDEV_TX_OK
;
1417 * i40e_fcoe_change_mtu - NDO callback to change the Maximum Transfer Unit
1418 * @netdev: network interface device structure
1419 * @new_mtu: new value for maximum frame size
1421 * Returns error as operation not permitted
1424 static int i40e_fcoe_change_mtu(struct net_device
*netdev
, int new_mtu
)
1426 netdev_warn(netdev
, "MTU change is not supported on FCoE interfaces\n");
1431 * i40e_fcoe_set_features - set the netdev feature flags
1432 * @netdev: ptr to the netdev being adjusted
1433 * @features: the feature set that the stack is suggesting
1436 static int i40e_fcoe_set_features(struct net_device
*netdev
,
1437 netdev_features_t features
)
1439 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
1440 struct i40e_vsi
*vsi
= np
->vsi
;
1442 if (features
& NETIF_F_HW_VLAN_CTAG_RX
)
1443 i40e_vlan_stripping_enable(vsi
);
1445 i40e_vlan_stripping_disable(vsi
);
1451 static const struct net_device_ops i40e_fcoe_netdev_ops
= {
1452 .ndo_open
= i40e_open
,
1453 .ndo_stop
= i40e_close
,
1454 .ndo_get_stats64
= i40e_get_netdev_stats_struct
,
1455 .ndo_set_rx_mode
= i40e_set_rx_mode
,
1456 .ndo_validate_addr
= eth_validate_addr
,
1457 .ndo_set_mac_address
= i40e_set_mac
,
1458 .ndo_change_mtu
= i40e_fcoe_change_mtu
,
1459 .ndo_do_ioctl
= i40e_ioctl
,
1460 .ndo_tx_timeout
= i40e_tx_timeout
,
1461 .ndo_vlan_rx_add_vid
= i40e_vlan_rx_add_vid
,
1462 .ndo_vlan_rx_kill_vid
= i40e_vlan_rx_kill_vid
,
1463 .ndo_setup_tc
= i40e_setup_tc
,
1465 #ifdef CONFIG_NET_POLL_CONTROLLER
1466 .ndo_poll_controller
= i40e_netpoll
,
1468 .ndo_start_xmit
= i40e_fcoe_xmit_frame
,
1469 .ndo_fcoe_enable
= i40e_fcoe_enable
,
1470 .ndo_fcoe_disable
= i40e_fcoe_disable
,
1471 .ndo_fcoe_ddp_setup
= i40e_fcoe_ddp_get
,
1472 .ndo_fcoe_ddp_done
= i40e_fcoe_ddp_put
,
1473 .ndo_fcoe_ddp_target
= i40e_fcoe_ddp_target
,
1474 .ndo_set_features
= i40e_fcoe_set_features
,
1477 /* fcoe network device type */
1478 static struct device_type fcoe_netdev_type
= {
1483 * i40e_fcoe_config_netdev - prepares the VSI context for creating a FCoE VSI
1484 * @vsi: pointer to the associated VSI struct
1485 * @ctxt: pointer to the associated VSI context to be passed to HW
1487 * Returns 0 on success or < 0 on error
1489 void i40e_fcoe_config_netdev(struct net_device
*netdev
, struct i40e_vsi
*vsi
)
1491 struct i40e_hw
*hw
= &vsi
->back
->hw
;
1492 struct i40e_pf
*pf
= vsi
->back
;
1494 if (vsi
->type
!= I40E_VSI_FCOE
)
1497 netdev
->features
= (NETIF_F_HW_VLAN_CTAG_TX
|
1498 NETIF_F_HW_VLAN_CTAG_RX
|
1499 NETIF_F_HW_VLAN_CTAG_FILTER
);
1501 netdev
->vlan_features
= netdev
->features
;
1502 netdev
->vlan_features
&= ~(NETIF_F_HW_VLAN_CTAG_TX
|
1503 NETIF_F_HW_VLAN_CTAG_RX
|
1504 NETIF_F_HW_VLAN_CTAG_FILTER
);
1505 netdev
->fcoe_ddp_xid
= I40E_FCOE_DDP_MAX
- 1;
1506 netdev
->features
|= NETIF_F_ALL_FCOE
;
1507 netdev
->vlan_features
|= NETIF_F_ALL_FCOE
;
1508 netdev
->hw_features
|= netdev
->features
;
1509 netdev
->priv_flags
|= IFF_UNICAST_FLT
;
1510 netdev
->priv_flags
|= IFF_SUPP_NOFCS
;
1512 strlcpy(netdev
->name
, "fcoe%d", IFNAMSIZ
-1);
1513 netdev
->mtu
= FCOE_MTU
;
1514 SET_NETDEV_DEV(netdev
, &pf
->pdev
->dev
);
1515 SET_NETDEV_DEVTYPE(netdev
, &fcoe_netdev_type
);
1516 /* set different dev_port value 1 for FCoE netdev than the default
1517 * zero dev_port value for PF netdev, this helps biosdevname user
1518 * tool to differentiate them correctly while both attached to the
1519 * same PCI function.
1521 netdev
->dev_port
= 1;
1522 i40e_add_filter(vsi
, hw
->mac
.san_addr
, 0, false, false);
1523 i40e_add_filter(vsi
, (u8
[6]) FC_FCOE_FLOGI_MAC
, 0, false, false);
1524 i40e_add_filter(vsi
, FIP_ALL_FCOE_MACS
, 0, false, false);
1525 i40e_add_filter(vsi
, FIP_ALL_ENODE_MACS
, 0, false, false);
1528 ether_addr_copy(netdev
->dev_addr
, hw
->mac
.san_addr
);
1529 ether_addr_copy(netdev
->perm_addr
, hw
->mac
.san_addr
);
1530 /* fcoe netdev ops */
1531 netdev
->netdev_ops
= &i40e_fcoe_netdev_ops
;
1535 * i40e_fcoe_vsi_setup - allocate and set up FCoE VSI
1536 * @pf: the pf that VSI is associated with
1539 void i40e_fcoe_vsi_setup(struct i40e_pf
*pf
)
1541 struct i40e_vsi
*vsi
;
1545 if (!(pf
->flags
& I40E_FLAG_FCOE_ENABLED
))
1548 BUG_ON(!pf
->vsi
[pf
->lan_vsi
]);
1550 for (i
= 0; i
< pf
->num_alloc_vsi
; i
++) {
1552 if (vsi
&& vsi
->type
== I40E_VSI_FCOE
) {
1553 dev_warn(&pf
->pdev
->dev
,
1554 "FCoE VSI already created\n");
1559 seid
= pf
->vsi
[pf
->lan_vsi
]->seid
;
1560 vsi
= i40e_vsi_setup(pf
, I40E_VSI_FCOE
, seid
, 0);
1562 dev_dbg(&pf
->pdev
->dev
,
1563 "Successfully created FCoE VSI seid %d id %d uplink_seid %d pf seid %d\n",
1564 vsi
->seid
, vsi
->id
, vsi
->uplink_seid
, seid
);
1566 dev_info(&pf
->pdev
->dev
, "Failed to create FCoE VSI\n");