151dce24bSJeff Kirsher // SPDX-License-Identifier: GPL-2.0
251dce24bSJeff Kirsher /* Copyright(c) 1999 - 2018 Intel Corporation. */
3dee1ad47SJeff Kirsher
4dee1ad47SJeff Kirsher #include "ixgbe.h"
5dee1ad47SJeff Kirsher #include <linux/if_ether.h>
6dee1ad47SJeff Kirsher #include <linux/gfp.h>
7dee1ad47SJeff Kirsher #include <linux/if_vlan.h>
834a2a3b8SJeff Kirsher #include <generated/utsrelease.h>
9dee1ad47SJeff Kirsher #include <scsi/scsi_cmnd.h>
10dee1ad47SJeff Kirsher #include <scsi/scsi_device.h>
11dee1ad47SJeff Kirsher #include <scsi/fc/fc_fs.h>
12dee1ad47SJeff Kirsher #include <scsi/fc/fc_fcoe.h>
13dee1ad47SJeff Kirsher #include <scsi/libfc.h>
14dee1ad47SJeff Kirsher #include <scsi/libfcoe.h>
15dee1ad47SJeff Kirsher
16dee1ad47SJeff Kirsher /**
17dee1ad47SJeff Kirsher * ixgbe_fcoe_clear_ddp - clear the given ddp context
1849ce9c2cSBen Hutchings * @ddp: ptr to the ixgbe_fcoe_ddp
19dee1ad47SJeff Kirsher *
20dee1ad47SJeff Kirsher * Returns : none
21dee1ad47SJeff Kirsher *
22dee1ad47SJeff Kirsher */
ixgbe_fcoe_clear_ddp(struct ixgbe_fcoe_ddp * ddp)23dee1ad47SJeff Kirsher static inline void ixgbe_fcoe_clear_ddp(struct ixgbe_fcoe_ddp *ddp)
24dee1ad47SJeff Kirsher {
25dee1ad47SJeff Kirsher ddp->len = 0;
26dee1ad47SJeff Kirsher ddp->err = 1;
27dee1ad47SJeff Kirsher ddp->udl = NULL;
28dee1ad47SJeff Kirsher ddp->udp = 0UL;
29dee1ad47SJeff Kirsher ddp->sgl = NULL;
30dee1ad47SJeff Kirsher ddp->sgc = 0;
31dee1ad47SJeff Kirsher }
32dee1ad47SJeff Kirsher
33dee1ad47SJeff Kirsher /**
34dee1ad47SJeff Kirsher * ixgbe_fcoe_ddp_put - free the ddp context for a given xid
35dee1ad47SJeff Kirsher * @netdev: the corresponding net_device
36dee1ad47SJeff Kirsher * @xid: the xid that corresponding ddp will be freed
37dee1ad47SJeff Kirsher *
38dee1ad47SJeff Kirsher * This is the implementation of net_device_ops.ndo_fcoe_ddp_done
39dee1ad47SJeff Kirsher * and it is expected to be called by ULD, i.e., FCP layer of libfc
40dee1ad47SJeff Kirsher * to release the corresponding ddp context when the I/O is done.
41dee1ad47SJeff Kirsher *
42dee1ad47SJeff Kirsher * Returns : data length already ddp-ed in bytes
43dee1ad47SJeff Kirsher */
ixgbe_fcoe_ddp_put(struct net_device * netdev,u16 xid)44dee1ad47SJeff Kirsher int ixgbe_fcoe_ddp_put(struct net_device *netdev, u16 xid)
45dee1ad47SJeff Kirsher {
46e90dd264SMark Rustad int len;
47dee1ad47SJeff Kirsher struct ixgbe_fcoe *fcoe;
48dee1ad47SJeff Kirsher struct ixgbe_adapter *adapter;
49dee1ad47SJeff Kirsher struct ixgbe_fcoe_ddp *ddp;
50ea412015SVasu Dev struct ixgbe_hw *hw;
51dee1ad47SJeff Kirsher u32 fcbuff;
52dee1ad47SJeff Kirsher
53dee1ad47SJeff Kirsher if (!netdev)
54e90dd264SMark Rustad return 0;
55dee1ad47SJeff Kirsher
56f10166abSVasu Dev if (xid >= netdev->fcoe_ddp_xid)
57e90dd264SMark Rustad return 0;
58dee1ad47SJeff Kirsher
59dee1ad47SJeff Kirsher adapter = netdev_priv(netdev);
60dee1ad47SJeff Kirsher fcoe = &adapter->fcoe;
61dee1ad47SJeff Kirsher ddp = &fcoe->ddp[xid];
62dee1ad47SJeff Kirsher if (!ddp->udl)
63e90dd264SMark Rustad return 0;
64dee1ad47SJeff Kirsher
65ea412015SVasu Dev hw = &adapter->hw;
66dee1ad47SJeff Kirsher len = ddp->len;
67ea412015SVasu Dev /* if no error then skip ddp context invalidation */
68ea412015SVasu Dev if (!ddp->err)
69ea412015SVasu Dev goto skip_ddpinv;
70ea412015SVasu Dev
71ea412015SVasu Dev if (hw->mac.type == ixgbe_mac_X550) {
72ea412015SVasu Dev /* X550 does not require DDP FCoE lock */
73ea412015SVasu Dev
74ea412015SVasu Dev IXGBE_WRITE_REG(hw, IXGBE_FCDFC(0, xid), 0);
75ea412015SVasu Dev IXGBE_WRITE_REG(hw, IXGBE_FCDFC(3, xid),
76dee1ad47SJeff Kirsher (xid | IXGBE_FCFLTRW_WE));
77ea412015SVasu Dev
78ea412015SVasu Dev /* program FCBUFF */
79ea412015SVasu Dev IXGBE_WRITE_REG(hw, IXGBE_FCDDC(2, xid), 0);
80ea412015SVasu Dev
81ea412015SVasu Dev /* program FCDMARW */
82ea412015SVasu Dev IXGBE_WRITE_REG(hw, IXGBE_FCDDC(3, xid),
83ea412015SVasu Dev (xid | IXGBE_FCDMARW_WE));
84ea412015SVasu Dev
85ea412015SVasu Dev /* read FCBUFF to check context invalidated */
86ea412015SVasu Dev IXGBE_WRITE_REG(hw, IXGBE_FCDDC(3, xid),
87ea412015SVasu Dev (xid | IXGBE_FCDMARW_RE));
88ea412015SVasu Dev fcbuff = IXGBE_READ_REG(hw, IXGBE_FCDDC(2, xid));
89ea412015SVasu Dev } else {
90ea412015SVasu Dev /* other hardware requires DDP FCoE lock */
91ea412015SVasu Dev spin_lock_bh(&fcoe->lock);
92ea412015SVasu Dev IXGBE_WRITE_REG(hw, IXGBE_FCFLT, 0);
93ea412015SVasu Dev IXGBE_WRITE_REG(hw, IXGBE_FCFLTRW,
94ea412015SVasu Dev (xid | IXGBE_FCFLTRW_WE));
95ea412015SVasu Dev IXGBE_WRITE_REG(hw, IXGBE_FCBUFF, 0);
96ea412015SVasu Dev IXGBE_WRITE_REG(hw, IXGBE_FCDMARW,
97dee1ad47SJeff Kirsher (xid | IXGBE_FCDMARW_WE));
98dee1ad47SJeff Kirsher
99dee1ad47SJeff Kirsher /* guaranteed to be invalidated after 100us */
100ea412015SVasu Dev IXGBE_WRITE_REG(hw, IXGBE_FCDMARW,
101dee1ad47SJeff Kirsher (xid | IXGBE_FCDMARW_RE));
102ea412015SVasu Dev fcbuff = IXGBE_READ_REG(hw, IXGBE_FCBUFF);
103dee1ad47SJeff Kirsher spin_unlock_bh(&fcoe->lock);
104dee1ad47SJeff Kirsher }
105ea412015SVasu Dev
106ea412015SVasu Dev if (fcbuff & IXGBE_FCBUFF_VALID)
107ea412015SVasu Dev usleep_range(100, 150);
108ea412015SVasu Dev
109ea412015SVasu Dev skip_ddpinv:
110dee1ad47SJeff Kirsher if (ddp->sgl)
1111bf91cdcSAlexander Duyck dma_unmap_sg(&adapter->pdev->dev, ddp->sgl, ddp->sgc,
112dee1ad47SJeff Kirsher DMA_FROM_DEVICE);
113dee1ad47SJeff Kirsher if (ddp->pool) {
1141bf91cdcSAlexander Duyck dma_pool_free(ddp->pool, ddp->udl, ddp->udp);
115dee1ad47SJeff Kirsher ddp->pool = NULL;
116dee1ad47SJeff Kirsher }
117dee1ad47SJeff Kirsher
118dee1ad47SJeff Kirsher ixgbe_fcoe_clear_ddp(ddp);
119dee1ad47SJeff Kirsher
120dee1ad47SJeff Kirsher return len;
121dee1ad47SJeff Kirsher }
122dee1ad47SJeff Kirsher
123dee1ad47SJeff Kirsher /**
124dee1ad47SJeff Kirsher * ixgbe_fcoe_ddp_setup - called to set up ddp context
125dee1ad47SJeff Kirsher * @netdev: the corresponding net_device
126dee1ad47SJeff Kirsher * @xid: the exchange id requesting ddp
127dee1ad47SJeff Kirsher * @sgl: the scatter-gather list for this request
128dee1ad47SJeff Kirsher * @sgc: the number of scatter-gather items
1295ba643c6STony Nguyen * @target_mode: 1 to setup target mode, 0 to setup initiator mode
130dee1ad47SJeff Kirsher *
131dee1ad47SJeff Kirsher * Returns : 1 for success and 0 for no ddp
132dee1ad47SJeff Kirsher */
ixgbe_fcoe_ddp_setup(struct net_device * netdev,u16 xid,struct scatterlist * sgl,unsigned int sgc,int target_mode)133dee1ad47SJeff Kirsher static int ixgbe_fcoe_ddp_setup(struct net_device *netdev, u16 xid,
134dee1ad47SJeff Kirsher struct scatterlist *sgl, unsigned int sgc,
135dee1ad47SJeff Kirsher int target_mode)
136dee1ad47SJeff Kirsher {
137dee1ad47SJeff Kirsher struct ixgbe_adapter *adapter;
138dee1ad47SJeff Kirsher struct ixgbe_hw *hw;
139dee1ad47SJeff Kirsher struct ixgbe_fcoe *fcoe;
140dee1ad47SJeff Kirsher struct ixgbe_fcoe_ddp *ddp;
1415a1ee270SAlexander Duyck struct ixgbe_fcoe_ddp_pool *ddp_pool;
142dee1ad47SJeff Kirsher struct scatterlist *sg;
143dee1ad47SJeff Kirsher unsigned int i, j, dmacount;
144dee1ad47SJeff Kirsher unsigned int len;
145dee1ad47SJeff Kirsher static const unsigned int bufflen = IXGBE_FCBUFF_MIN;
146dee1ad47SJeff Kirsher unsigned int firstoff = 0;
147dee1ad47SJeff Kirsher unsigned int lastsize;
148dee1ad47SJeff Kirsher unsigned int thisoff = 0;
149dee1ad47SJeff Kirsher unsigned int thislen = 0;
150dee1ad47SJeff Kirsher u32 fcbuff, fcdmarw, fcfltrw, fcrxctl;
151dee1ad47SJeff Kirsher dma_addr_t addr = 0;
152dee1ad47SJeff Kirsher
153dee1ad47SJeff Kirsher if (!netdev || !sgl)
154dee1ad47SJeff Kirsher return 0;
155dee1ad47SJeff Kirsher
156dee1ad47SJeff Kirsher adapter = netdev_priv(netdev);
157f10166abSVasu Dev if (xid >= netdev->fcoe_ddp_xid) {
158dee1ad47SJeff Kirsher e_warn(drv, "xid=0x%x out-of-range\n", xid);
159dee1ad47SJeff Kirsher return 0;
160dee1ad47SJeff Kirsher }
161dee1ad47SJeff Kirsher
162dee1ad47SJeff Kirsher /* no DDP if we are already down or resetting */
163dee1ad47SJeff Kirsher if (test_bit(__IXGBE_DOWN, &adapter->state) ||
164dee1ad47SJeff Kirsher test_bit(__IXGBE_RESETTING, &adapter->state))
165dee1ad47SJeff Kirsher return 0;
166dee1ad47SJeff Kirsher
167dee1ad47SJeff Kirsher fcoe = &adapter->fcoe;
168dee1ad47SJeff Kirsher ddp = &fcoe->ddp[xid];
169dee1ad47SJeff Kirsher if (ddp->sgl) {
170dee1ad47SJeff Kirsher e_err(drv, "xid 0x%x w/ non-null sgl=%p nents=%d\n",
171dee1ad47SJeff Kirsher xid, ddp->sgl, ddp->sgc);
172dee1ad47SJeff Kirsher return 0;
173dee1ad47SJeff Kirsher }
174dee1ad47SJeff Kirsher ixgbe_fcoe_clear_ddp(ddp);
175dee1ad47SJeff Kirsher
1765a1ee270SAlexander Duyck
1775a1ee270SAlexander Duyck if (!fcoe->ddp_pool) {
1785a1ee270SAlexander Duyck e_warn(drv, "No ddp_pool resources allocated\n");
1795a1ee270SAlexander Duyck return 0;
1805a1ee270SAlexander Duyck }
1815a1ee270SAlexander Duyck
1825a1ee270SAlexander Duyck ddp_pool = per_cpu_ptr(fcoe->ddp_pool, get_cpu());
1835a1ee270SAlexander Duyck if (!ddp_pool->pool) {
1845a1ee270SAlexander Duyck e_warn(drv, "xid=0x%x no ddp pool for fcoe\n", xid);
1855a1ee270SAlexander Duyck goto out_noddp;
1865a1ee270SAlexander Duyck }
1875a1ee270SAlexander Duyck
188dee1ad47SJeff Kirsher /* setup dma from scsi command sgl */
1891bf91cdcSAlexander Duyck dmacount = dma_map_sg(&adapter->pdev->dev, sgl, sgc, DMA_FROM_DEVICE);
190dee1ad47SJeff Kirsher if (dmacount == 0) {
191dee1ad47SJeff Kirsher e_err(drv, "xid 0x%x DMA map error\n", xid);
1925a1ee270SAlexander Duyck goto out_noddp;
193dee1ad47SJeff Kirsher }
194dee1ad47SJeff Kirsher
195dee1ad47SJeff Kirsher /* alloc the udl from per cpu ddp pool */
196fa39ab51SMike Christie ddp->udl = dma_pool_alloc(ddp_pool->pool, GFP_ATOMIC, &ddp->udp);
197dee1ad47SJeff Kirsher if (!ddp->udl) {
198dee1ad47SJeff Kirsher e_err(drv, "failed allocated ddp context\n");
199dee1ad47SJeff Kirsher goto out_noddp_unmap;
200dee1ad47SJeff Kirsher }
2015a1ee270SAlexander Duyck ddp->pool = ddp_pool->pool;
202dee1ad47SJeff Kirsher ddp->sgl = sgl;
203dee1ad47SJeff Kirsher ddp->sgc = sgc;
204dee1ad47SJeff Kirsher
205dee1ad47SJeff Kirsher j = 0;
206dee1ad47SJeff Kirsher for_each_sg(sgl, sg, dmacount, i) {
207dee1ad47SJeff Kirsher addr = sg_dma_address(sg);
208dee1ad47SJeff Kirsher len = sg_dma_len(sg);
209dee1ad47SJeff Kirsher while (len) {
210dee1ad47SJeff Kirsher /* max number of buffers allowed in one DDP context */
211dee1ad47SJeff Kirsher if (j >= IXGBE_BUFFCNT_MAX) {
2125a1ee270SAlexander Duyck ddp_pool->noddp++;
213dee1ad47SJeff Kirsher goto out_noddp_free;
214dee1ad47SJeff Kirsher }
215dee1ad47SJeff Kirsher
216dee1ad47SJeff Kirsher /* get the offset of length of current buffer */
217dee1ad47SJeff Kirsher thisoff = addr & ((dma_addr_t)bufflen - 1);
218dee1ad47SJeff Kirsher thislen = min((bufflen - thisoff), len);
219dee1ad47SJeff Kirsher /*
220dee1ad47SJeff Kirsher * all but the 1st buffer (j == 0)
221dee1ad47SJeff Kirsher * must be aligned on bufflen
222dee1ad47SJeff Kirsher */
223dee1ad47SJeff Kirsher if ((j != 0) && (thisoff))
224dee1ad47SJeff Kirsher goto out_noddp_free;
225dee1ad47SJeff Kirsher /*
226dee1ad47SJeff Kirsher * all but the last buffer
227dee1ad47SJeff Kirsher * ((i == (dmacount - 1)) && (thislen == len))
228dee1ad47SJeff Kirsher * must end at bufflen
229dee1ad47SJeff Kirsher */
230dee1ad47SJeff Kirsher if (((i != (dmacount - 1)) || (thislen != len))
231dee1ad47SJeff Kirsher && ((thislen + thisoff) != bufflen))
232dee1ad47SJeff Kirsher goto out_noddp_free;
233dee1ad47SJeff Kirsher
234dee1ad47SJeff Kirsher ddp->udl[j] = (u64)(addr - thisoff);
235dee1ad47SJeff Kirsher /* only the first buffer may have none-zero offset */
236dee1ad47SJeff Kirsher if (j == 0)
237dee1ad47SJeff Kirsher firstoff = thisoff;
238dee1ad47SJeff Kirsher len -= thislen;
239dee1ad47SJeff Kirsher addr += thislen;
240dee1ad47SJeff Kirsher j++;
241dee1ad47SJeff Kirsher }
242dee1ad47SJeff Kirsher }
243dee1ad47SJeff Kirsher /* only the last buffer may have non-full bufflen */
244dee1ad47SJeff Kirsher lastsize = thisoff + thislen;
245dee1ad47SJeff Kirsher
246dee1ad47SJeff Kirsher /*
247dee1ad47SJeff Kirsher * lastsize can not be buffer len.
248dee1ad47SJeff Kirsher * If it is then adding another buffer with lastsize = 1.
249dee1ad47SJeff Kirsher */
250dee1ad47SJeff Kirsher if (lastsize == bufflen) {
251dee1ad47SJeff Kirsher if (j >= IXGBE_BUFFCNT_MAX) {
2525a1ee270SAlexander Duyck ddp_pool->noddp_ext_buff++;
253dee1ad47SJeff Kirsher goto out_noddp_free;
254dee1ad47SJeff Kirsher }
255dee1ad47SJeff Kirsher
256dee1ad47SJeff Kirsher ddp->udl[j] = (u64)(fcoe->extra_ddp_buffer_dma);
257dee1ad47SJeff Kirsher j++;
258dee1ad47SJeff Kirsher lastsize = 1;
259dee1ad47SJeff Kirsher }
260dee1ad47SJeff Kirsher put_cpu();
261dee1ad47SJeff Kirsher
262dee1ad47SJeff Kirsher fcbuff = (IXGBE_FCBUFF_4KB << IXGBE_FCBUFF_BUFFSIZE_SHIFT);
263dee1ad47SJeff Kirsher fcbuff |= ((j & 0xff) << IXGBE_FCBUFF_BUFFCNT_SHIFT);
264dee1ad47SJeff Kirsher fcbuff |= (firstoff << IXGBE_FCBUFF_OFFSET_SHIFT);
265dee1ad47SJeff Kirsher /* Set WRCONTX bit to allow DDP for target */
266dee1ad47SJeff Kirsher if (target_mode)
267dee1ad47SJeff Kirsher fcbuff |= (IXGBE_FCBUFF_WRCONTX);
268dee1ad47SJeff Kirsher fcbuff |= (IXGBE_FCBUFF_VALID);
269dee1ad47SJeff Kirsher
270dee1ad47SJeff Kirsher fcdmarw = xid;
271dee1ad47SJeff Kirsher fcdmarw |= IXGBE_FCDMARW_WE;
272dee1ad47SJeff Kirsher fcdmarw |= (lastsize << IXGBE_FCDMARW_LASTSIZE_SHIFT);
273dee1ad47SJeff Kirsher
274dee1ad47SJeff Kirsher fcfltrw = xid;
275dee1ad47SJeff Kirsher fcfltrw |= IXGBE_FCFLTRW_WE;
276dee1ad47SJeff Kirsher
277dee1ad47SJeff Kirsher /* program DMA context */
278dee1ad47SJeff Kirsher hw = &adapter->hw;
279dee1ad47SJeff Kirsher
280dee1ad47SJeff Kirsher /* turn on last frame indication for target mode as FCP_RSPtarget is
281dee1ad47SJeff Kirsher * supposed to send FCP_RSP when it is done. */
282dee1ad47SJeff Kirsher if (target_mode && !test_bit(__IXGBE_FCOE_TARGET, &fcoe->mode)) {
283dee1ad47SJeff Kirsher set_bit(__IXGBE_FCOE_TARGET, &fcoe->mode);
284dee1ad47SJeff Kirsher fcrxctl = IXGBE_READ_REG(hw, IXGBE_FCRXCTRL);
285dee1ad47SJeff Kirsher fcrxctl |= IXGBE_FCRXCTRL_LASTSEQH;
286dee1ad47SJeff Kirsher IXGBE_WRITE_REG(hw, IXGBE_FCRXCTRL, fcrxctl);
287dee1ad47SJeff Kirsher }
288dee1ad47SJeff Kirsher
289ea412015SVasu Dev if (hw->mac.type == ixgbe_mac_X550) {
290ea412015SVasu Dev /* X550 does not require DDP lock */
291ea412015SVasu Dev
292ea412015SVasu Dev IXGBE_WRITE_REG(hw, IXGBE_FCDDC(0, xid),
293ea412015SVasu Dev ddp->udp & DMA_BIT_MASK(32));
294ea412015SVasu Dev IXGBE_WRITE_REG(hw, IXGBE_FCDDC(1, xid), (u64)ddp->udp >> 32);
295ea412015SVasu Dev IXGBE_WRITE_REG(hw, IXGBE_FCDDC(2, xid), fcbuff);
296ea412015SVasu Dev IXGBE_WRITE_REG(hw, IXGBE_FCDDC(3, xid), fcdmarw);
297ea412015SVasu Dev /* program filter context */
298ea412015SVasu Dev IXGBE_WRITE_REG(hw, IXGBE_FCDFC(0, xid), IXGBE_FCFLT_VALID);
299ea412015SVasu Dev IXGBE_WRITE_REG(hw, IXGBE_FCDFC(1, xid), 0);
300ea412015SVasu Dev IXGBE_WRITE_REG(hw, IXGBE_FCDFC(3, xid), fcfltrw);
301ea412015SVasu Dev } else {
302ea412015SVasu Dev /* DDP lock for indirect DDP context access */
303ea412015SVasu Dev spin_lock_bh(&fcoe->lock);
304ea412015SVasu Dev
305dee1ad47SJeff Kirsher IXGBE_WRITE_REG(hw, IXGBE_FCPTRL, ddp->udp & DMA_BIT_MASK(32));
306dee1ad47SJeff Kirsher IXGBE_WRITE_REG(hw, IXGBE_FCPTRH, (u64)ddp->udp >> 32);
307dee1ad47SJeff Kirsher IXGBE_WRITE_REG(hw, IXGBE_FCBUFF, fcbuff);
308dee1ad47SJeff Kirsher IXGBE_WRITE_REG(hw, IXGBE_FCDMARW, fcdmarw);
309dee1ad47SJeff Kirsher /* program filter context */
310dee1ad47SJeff Kirsher IXGBE_WRITE_REG(hw, IXGBE_FCPARAM, 0);
311dee1ad47SJeff Kirsher IXGBE_WRITE_REG(hw, IXGBE_FCFLT, IXGBE_FCFLT_VALID);
312dee1ad47SJeff Kirsher IXGBE_WRITE_REG(hw, IXGBE_FCFLTRW, fcfltrw);
313dee1ad47SJeff Kirsher
314dee1ad47SJeff Kirsher spin_unlock_bh(&fcoe->lock);
315ea412015SVasu Dev }
316dee1ad47SJeff Kirsher
317dee1ad47SJeff Kirsher return 1;
318dee1ad47SJeff Kirsher
319dee1ad47SJeff Kirsher out_noddp_free:
3205a1ee270SAlexander Duyck dma_pool_free(ddp->pool, ddp->udl, ddp->udp);
321dee1ad47SJeff Kirsher ixgbe_fcoe_clear_ddp(ddp);
322dee1ad47SJeff Kirsher
323dee1ad47SJeff Kirsher out_noddp_unmap:
3241bf91cdcSAlexander Duyck dma_unmap_sg(&adapter->pdev->dev, sgl, sgc, DMA_FROM_DEVICE);
3255a1ee270SAlexander Duyck out_noddp:
326dee1ad47SJeff Kirsher put_cpu();
327dee1ad47SJeff Kirsher return 0;
328dee1ad47SJeff Kirsher }
329dee1ad47SJeff Kirsher
330dee1ad47SJeff Kirsher /**
331dee1ad47SJeff Kirsher * ixgbe_fcoe_ddp_get - called to set up ddp context in initiator mode
332dee1ad47SJeff Kirsher * @netdev: the corresponding net_device
333dee1ad47SJeff Kirsher * @xid: the exchange id requesting ddp
334dee1ad47SJeff Kirsher * @sgl: the scatter-gather list for this request
335dee1ad47SJeff Kirsher * @sgc: the number of scatter-gather items
336dee1ad47SJeff Kirsher *
337dee1ad47SJeff Kirsher * This is the implementation of net_device_ops.ndo_fcoe_ddp_setup
338dee1ad47SJeff Kirsher * and is expected to be called from ULD, e.g., FCP layer of libfc
339dee1ad47SJeff Kirsher * to set up ddp for the corresponding xid of the given sglist for
340dee1ad47SJeff Kirsher * the corresponding I/O.
341dee1ad47SJeff Kirsher *
342dee1ad47SJeff Kirsher * Returns : 1 for success and 0 for no ddp
343dee1ad47SJeff Kirsher */
ixgbe_fcoe_ddp_get(struct net_device * netdev,u16 xid,struct scatterlist * sgl,unsigned int sgc)344dee1ad47SJeff Kirsher int ixgbe_fcoe_ddp_get(struct net_device *netdev, u16 xid,
345dee1ad47SJeff Kirsher struct scatterlist *sgl, unsigned int sgc)
346dee1ad47SJeff Kirsher {
347dee1ad47SJeff Kirsher return ixgbe_fcoe_ddp_setup(netdev, xid, sgl, sgc, 0);
348dee1ad47SJeff Kirsher }
349dee1ad47SJeff Kirsher
350dee1ad47SJeff Kirsher /**
351dee1ad47SJeff Kirsher * ixgbe_fcoe_ddp_target - called to set up ddp context in target mode
352dee1ad47SJeff Kirsher * @netdev: the corresponding net_device
353dee1ad47SJeff Kirsher * @xid: the exchange id requesting ddp
354dee1ad47SJeff Kirsher * @sgl: the scatter-gather list for this request
355dee1ad47SJeff Kirsher * @sgc: the number of scatter-gather items
356dee1ad47SJeff Kirsher *
357dee1ad47SJeff Kirsher * This is the implementation of net_device_ops.ndo_fcoe_ddp_target
358dee1ad47SJeff Kirsher * and is expected to be called from ULD, e.g., FCP layer of libfc
359dee1ad47SJeff Kirsher * to set up ddp for the corresponding xid of the given sglist for
360dee1ad47SJeff Kirsher * the corresponding I/O. The DDP in target mode is a write I/O request
361dee1ad47SJeff Kirsher * from the initiator.
362dee1ad47SJeff Kirsher *
363dee1ad47SJeff Kirsher * Returns : 1 for success and 0 for no ddp
364dee1ad47SJeff Kirsher */
ixgbe_fcoe_ddp_target(struct net_device * netdev,u16 xid,struct scatterlist * sgl,unsigned int sgc)365dee1ad47SJeff Kirsher int ixgbe_fcoe_ddp_target(struct net_device *netdev, u16 xid,
366dee1ad47SJeff Kirsher struct scatterlist *sgl, unsigned int sgc)
367dee1ad47SJeff Kirsher {
368dee1ad47SJeff Kirsher return ixgbe_fcoe_ddp_setup(netdev, xid, sgl, sgc, 1);
369dee1ad47SJeff Kirsher }
370dee1ad47SJeff Kirsher
371dee1ad47SJeff Kirsher /**
372dee1ad47SJeff Kirsher * ixgbe_fcoe_ddp - check ddp status and mark it done
373dee1ad47SJeff Kirsher * @adapter: ixgbe adapter
374dee1ad47SJeff Kirsher * @rx_desc: advanced rx descriptor
375dee1ad47SJeff Kirsher * @skb: the skb holding the received data
376dee1ad47SJeff Kirsher *
377dee1ad47SJeff Kirsher * This checks ddp status.
378dee1ad47SJeff Kirsher *
379dee1ad47SJeff Kirsher * Returns : < 0 indicates an error or not a FCiE ddp, 0 indicates
380dee1ad47SJeff Kirsher * not passing the skb to ULD, > 0 indicates is the length of data
381dee1ad47SJeff Kirsher * being ddped.
382dee1ad47SJeff Kirsher */
ixgbe_fcoe_ddp(struct ixgbe_adapter * adapter,union ixgbe_adv_rx_desc * rx_desc,struct sk_buff * skb)383dee1ad47SJeff Kirsher int ixgbe_fcoe_ddp(struct ixgbe_adapter *adapter,
384dee1ad47SJeff Kirsher union ixgbe_adv_rx_desc *rx_desc,
385f56e0cb1SAlexander Duyck struct sk_buff *skb)
386dee1ad47SJeff Kirsher {
387dee1ad47SJeff Kirsher int rc = -EINVAL;
388dee1ad47SJeff Kirsher struct ixgbe_fcoe *fcoe;
389dee1ad47SJeff Kirsher struct ixgbe_fcoe_ddp *ddp;
390dee1ad47SJeff Kirsher struct fc_frame_header *fh;
391dee1ad47SJeff Kirsher struct fcoe_crc_eof *crc;
392f56e0cb1SAlexander Duyck __le32 fcerr = ixgbe_test_staterr(rx_desc, IXGBE_RXDADV_ERR_FCERR);
393f56e0cb1SAlexander Duyck __le32 ddp_err;
394ea412015SVasu Dev int ddp_max;
395f56e0cb1SAlexander Duyck u32 fctl;
396f56e0cb1SAlexander Duyck u16 xid;
397dee1ad47SJeff Kirsher
398f56e0cb1SAlexander Duyck if (fcerr == cpu_to_le32(IXGBE_FCERR_BADCRC))
399f56e0cb1SAlexander Duyck skb->ip_summed = CHECKSUM_NONE;
400dee1ad47SJeff Kirsher else
401dee1ad47SJeff Kirsher skb->ip_summed = CHECKSUM_UNNECESSARY;
402dee1ad47SJeff Kirsher
403dee1ad47SJeff Kirsher if (eth_hdr(skb)->h_proto == htons(ETH_P_8021Q))
404dee1ad47SJeff Kirsher fh = (struct fc_frame_header *)(skb->data +
405dee1ad47SJeff Kirsher sizeof(struct vlan_hdr) + sizeof(struct fcoe_hdr));
406dee1ad47SJeff Kirsher else
407dee1ad47SJeff Kirsher fh = (struct fc_frame_header *)(skb->data +
408dee1ad47SJeff Kirsher sizeof(struct fcoe_hdr));
409f56e0cb1SAlexander Duyck
410dee1ad47SJeff Kirsher fctl = ntoh24(fh->fh_f_ctl);
411dee1ad47SJeff Kirsher if (fctl & FC_FC_EX_CTX)
412dee1ad47SJeff Kirsher xid = be16_to_cpu(fh->fh_ox_id);
413dee1ad47SJeff Kirsher else
414dee1ad47SJeff Kirsher xid = be16_to_cpu(fh->fh_rx_id);
415dee1ad47SJeff Kirsher
416ea412015SVasu Dev ddp_max = IXGBE_FCOE_DDP_MAX;
417ea412015SVasu Dev /* X550 has different DDP Max limit */
418ea412015SVasu Dev if (adapter->hw.mac.type == ixgbe_mac_X550)
419ea412015SVasu Dev ddp_max = IXGBE_FCOE_DDP_MAX_X550;
420ea412015SVasu Dev if (xid >= ddp_max)
421e90dd264SMark Rustad return -EINVAL;
422dee1ad47SJeff Kirsher
423dee1ad47SJeff Kirsher fcoe = &adapter->fcoe;
424dee1ad47SJeff Kirsher ddp = &fcoe->ddp[xid];
425dee1ad47SJeff Kirsher if (!ddp->udl)
426e90dd264SMark Rustad return -EINVAL;
427dee1ad47SJeff Kirsher
428f56e0cb1SAlexander Duyck ddp_err = ixgbe_test_staterr(rx_desc, IXGBE_RXDADV_ERR_FCEOFE |
429f56e0cb1SAlexander Duyck IXGBE_RXDADV_ERR_FCERR);
430f56e0cb1SAlexander Duyck if (ddp_err)
431e90dd264SMark Rustad return -EINVAL;
432dee1ad47SJeff Kirsher
433f56e0cb1SAlexander Duyck switch (ixgbe_test_staterr(rx_desc, IXGBE_RXDADV_STAT_FCSTAT)) {
434f56e0cb1SAlexander Duyck /* return 0 to bypass going to ULD for DDPed data */
435a1108ffdSJoe Perches case cpu_to_le32(IXGBE_RXDADV_STAT_FCSTAT_DDP):
436dee1ad47SJeff Kirsher /* update length of DDPed data */
437dee1ad47SJeff Kirsher ddp->len = le32_to_cpu(rx_desc->wb.lower.hi_dword.rss);
438f56e0cb1SAlexander Duyck rc = 0;
439f56e0cb1SAlexander Duyck break;
440f56e0cb1SAlexander Duyck /* unmap the sg list when FCPRSP is received */
441a1108ffdSJoe Perches case cpu_to_le32(IXGBE_RXDADV_STAT_FCSTAT_FCPRSP):
4421bf91cdcSAlexander Duyck dma_unmap_sg(&adapter->pdev->dev, ddp->sgl,
443dee1ad47SJeff Kirsher ddp->sgc, DMA_FROM_DEVICE);
4449cfbfa70SCathy Zhou ddp->err = (__force u32)ddp_err;
445dee1ad47SJeff Kirsher ddp->sgl = NULL;
446dee1ad47SJeff Kirsher ddp->sgc = 0;
4475463fce6SJeff Kirsher fallthrough;
448f56e0cb1SAlexander Duyck /* if DDP length is present pass it through to ULD */
449a1108ffdSJoe Perches case cpu_to_le32(IXGBE_RXDADV_STAT_FCSTAT_NODDP):
450f56e0cb1SAlexander Duyck /* update length of DDPed data */
451f56e0cb1SAlexander Duyck ddp->len = le32_to_cpu(rx_desc->wb.lower.hi_dword.rss);
452f56e0cb1SAlexander Duyck if (ddp->len)
453dee1ad47SJeff Kirsher rc = ddp->len;
454f56e0cb1SAlexander Duyck break;
455f56e0cb1SAlexander Duyck /* no match will return as an error */
456a1108ffdSJoe Perches case cpu_to_le32(IXGBE_RXDADV_STAT_FCSTAT_NOMTCH):
457f56e0cb1SAlexander Duyck default:
458f56e0cb1SAlexander Duyck break;
459dee1ad47SJeff Kirsher }
460f56e0cb1SAlexander Duyck
461dee1ad47SJeff Kirsher /* In target mode, check the last data frame of the sequence.
462dee1ad47SJeff Kirsher * For DDP in target mode, data is already DDPed but the header
463dee1ad47SJeff Kirsher * indication of the last data frame ould allow is to tell if we
464dee1ad47SJeff Kirsher * got all the data and the ULP can send FCP_RSP back, as this is
465dee1ad47SJeff Kirsher * not a full fcoe frame, we fill the trailer here so it won't be
466dee1ad47SJeff Kirsher * dropped by the ULP stack.
467dee1ad47SJeff Kirsher */
468dee1ad47SJeff Kirsher if ((fh->fh_r_ctl == FC_RCTL_DD_SOL_DATA) &&
469dee1ad47SJeff Kirsher (fctl & FC_FC_END_SEQ)) {
470441e1719SYi Zou skb_linearize(skb);
4714df864c1SJohannes Berg crc = skb_put(skb, sizeof(*crc));
472dee1ad47SJeff Kirsher crc->fcoe_eof = FC_EOF_T;
473dee1ad47SJeff Kirsher }
474e90dd264SMark Rustad
475dee1ad47SJeff Kirsher return rc;
476dee1ad47SJeff Kirsher }
477dee1ad47SJeff Kirsher
478dee1ad47SJeff Kirsher /**
479dee1ad47SJeff Kirsher * ixgbe_fso - ixgbe FCoE Sequence Offload (FSO)
480dee1ad47SJeff Kirsher * @tx_ring: tx desc ring
481fd0db0edSAlexander Duyck * @first: first tx_buffer structure containing skb, tx_flags, and protocol
482dee1ad47SJeff Kirsher * @hdr_len: hdr_len to be returned
483dee1ad47SJeff Kirsher *
484dee1ad47SJeff Kirsher * This sets up large send offload for FCoE
485dee1ad47SJeff Kirsher *
486244e27adSAlexander Duyck * Returns : 0 indicates success, < 0 for error
487dee1ad47SJeff Kirsher */
ixgbe_fso(struct ixgbe_ring * tx_ring,struct ixgbe_tx_buffer * first,u8 * hdr_len)488fd0db0edSAlexander Duyck int ixgbe_fso(struct ixgbe_ring *tx_ring,
489fd0db0edSAlexander Duyck struct ixgbe_tx_buffer *first,
490244e27adSAlexander Duyck u8 *hdr_len)
491dee1ad47SJeff Kirsher {
492fd0db0edSAlexander Duyck struct sk_buff *skb = first->skb;
493dee1ad47SJeff Kirsher struct fc_frame_header *fh;
494dee1ad47SJeff Kirsher u32 vlan_macip_lens;
495dee1ad47SJeff Kirsher u32 fcoe_sof_eof = 0;
496dee1ad47SJeff Kirsher u32 mss_l4len_idx;
4978b75451bSNeerav Parikh u32 type_tucmd = IXGBE_ADVTXT_TUCMD_FCOE;
498dee1ad47SJeff Kirsher u8 sof, eof;
499dee1ad47SJeff Kirsher
500dee1ad47SJeff Kirsher if (skb_is_gso(skb) && (skb_shinfo(skb)->gso_type != SKB_GSO_FCOE)) {
501dee1ad47SJeff Kirsher dev_err(tx_ring->dev, "Wrong gso type %d:expecting SKB_GSO_FCOE\n",
502dee1ad47SJeff Kirsher skb_shinfo(skb)->gso_type);
503dee1ad47SJeff Kirsher return -EINVAL;
504dee1ad47SJeff Kirsher }
505dee1ad47SJeff Kirsher
506dee1ad47SJeff Kirsher /* resets the header to point fcoe/fc */
507dee1ad47SJeff Kirsher skb_set_network_header(skb, skb->mac_len);
508dee1ad47SJeff Kirsher skb_set_transport_header(skb, skb->mac_len +
509dee1ad47SJeff Kirsher sizeof(struct fcoe_hdr));
510dee1ad47SJeff Kirsher
511dee1ad47SJeff Kirsher /* sets up SOF and ORIS */
512dee1ad47SJeff Kirsher sof = ((struct fcoe_hdr *)skb_network_header(skb))->fcoe_sof;
513dee1ad47SJeff Kirsher switch (sof) {
514dee1ad47SJeff Kirsher case FC_SOF_I2:
515dee1ad47SJeff Kirsher fcoe_sof_eof = IXGBE_ADVTXD_FCOEF_ORIS;
516dee1ad47SJeff Kirsher break;
517dee1ad47SJeff Kirsher case FC_SOF_I3:
518dee1ad47SJeff Kirsher fcoe_sof_eof = IXGBE_ADVTXD_FCOEF_SOF |
519dee1ad47SJeff Kirsher IXGBE_ADVTXD_FCOEF_ORIS;
520dee1ad47SJeff Kirsher break;
521dee1ad47SJeff Kirsher case FC_SOF_N2:
522dee1ad47SJeff Kirsher break;
523dee1ad47SJeff Kirsher case FC_SOF_N3:
524dee1ad47SJeff Kirsher fcoe_sof_eof = IXGBE_ADVTXD_FCOEF_SOF;
525dee1ad47SJeff Kirsher break;
526dee1ad47SJeff Kirsher default:
527dee1ad47SJeff Kirsher dev_warn(tx_ring->dev, "unknown sof = 0x%x\n", sof);
528dee1ad47SJeff Kirsher return -EINVAL;
529dee1ad47SJeff Kirsher }
530dee1ad47SJeff Kirsher
531dee1ad47SJeff Kirsher /* the first byte of the last dword is EOF */
532dee1ad47SJeff Kirsher skb_copy_bits(skb, skb->len - 4, &eof, 1);
533dee1ad47SJeff Kirsher /* sets up EOF and ORIE */
534dee1ad47SJeff Kirsher switch (eof) {
535dee1ad47SJeff Kirsher case FC_EOF_N:
536dee1ad47SJeff Kirsher fcoe_sof_eof |= IXGBE_ADVTXD_FCOEF_EOF_N;
537dee1ad47SJeff Kirsher break;
538dee1ad47SJeff Kirsher case FC_EOF_T:
539dee1ad47SJeff Kirsher /* lso needs ORIE */
540dee1ad47SJeff Kirsher if (skb_is_gso(skb))
541dee1ad47SJeff Kirsher fcoe_sof_eof |= IXGBE_ADVTXD_FCOEF_EOF_N |
542dee1ad47SJeff Kirsher IXGBE_ADVTXD_FCOEF_ORIE;
543dee1ad47SJeff Kirsher else
544dee1ad47SJeff Kirsher fcoe_sof_eof |= IXGBE_ADVTXD_FCOEF_EOF_T;
545dee1ad47SJeff Kirsher break;
546dee1ad47SJeff Kirsher case FC_EOF_NI:
547dee1ad47SJeff Kirsher fcoe_sof_eof |= IXGBE_ADVTXD_FCOEF_EOF_NI;
548dee1ad47SJeff Kirsher break;
549dee1ad47SJeff Kirsher case FC_EOF_A:
550dee1ad47SJeff Kirsher fcoe_sof_eof |= IXGBE_ADVTXD_FCOEF_EOF_A;
551dee1ad47SJeff Kirsher break;
552dee1ad47SJeff Kirsher default:
553dee1ad47SJeff Kirsher dev_warn(tx_ring->dev, "unknown eof = 0x%x\n", eof);
554dee1ad47SJeff Kirsher return -EINVAL;
555dee1ad47SJeff Kirsher }
556dee1ad47SJeff Kirsher
557dee1ad47SJeff Kirsher /* sets up PARINC indicating data offset */
558dee1ad47SJeff Kirsher fh = (struct fc_frame_header *)skb_transport_header(skb);
559dee1ad47SJeff Kirsher if (fh->fh_f_ctl[2] & FC_FC_REL_OFF)
560dee1ad47SJeff Kirsher fcoe_sof_eof |= IXGBE_ADVTXD_FCOEF_PARINC;
561dee1ad47SJeff Kirsher
562dee1ad47SJeff Kirsher /* include trailer in headlen as it is replicated per frame */
563dee1ad47SJeff Kirsher *hdr_len = sizeof(struct fcoe_crc_eof);
564dee1ad47SJeff Kirsher
565dee1ad47SJeff Kirsher /* hdr_len includes fc_hdr if FCoE LSO is enabled */
566091a6246SAlexander Duyck if (skb_is_gso(skb)) {
567091a6246SAlexander Duyck *hdr_len += skb_transport_offset(skb) +
568091a6246SAlexander Duyck sizeof(struct fc_frame_header);
569091a6246SAlexander Duyck /* update gso_segs and bytecount */
570091a6246SAlexander Duyck first->gso_segs = DIV_ROUND_UP(skb->len - *hdr_len,
571091a6246SAlexander Duyck skb_shinfo(skb)->gso_size);
572091a6246SAlexander Duyck first->bytecount += (first->gso_segs - 1) * *hdr_len;
573472148c3SAlexander Duyck first->tx_flags |= IXGBE_TX_FLAGS_TSO;
5748b75451bSNeerav Parikh /* Hardware expects L4T to be RSV for FCoE TSO */
5758b75451bSNeerav Parikh type_tucmd |= IXGBE_ADVTXD_TUCMD_L4T_RSV;
576091a6246SAlexander Duyck }
577dee1ad47SJeff Kirsher
578244e27adSAlexander Duyck /* set flag indicating FCOE to ixgbe_tx_map call */
579472148c3SAlexander Duyck first->tx_flags |= IXGBE_TX_FLAGS_FCOE | IXGBE_TX_FLAGS_CC;
580244e27adSAlexander Duyck
581c44f5f51SAlexander Duyck /* mss_l4len_id: use 0 for FSO as TSO, no need for L4LEN */
582dee1ad47SJeff Kirsher mss_l4len_idx = skb_shinfo(skb)->gso_size << IXGBE_ADVTXD_MSS_SHIFT;
583dee1ad47SJeff Kirsher
584dee1ad47SJeff Kirsher /* vlan_macip_lens: HEADLEN, MACLEN, VLAN tag */
585dee1ad47SJeff Kirsher vlan_macip_lens = skb_transport_offset(skb) +
586dee1ad47SJeff Kirsher sizeof(struct fc_frame_header);
587dee1ad47SJeff Kirsher vlan_macip_lens |= (skb_transport_offset(skb) - 4)
588dee1ad47SJeff Kirsher << IXGBE_ADVTXD_MACLEN_SHIFT;
589244e27adSAlexander Duyck vlan_macip_lens |= first->tx_flags & IXGBE_TX_FLAGS_VLAN_MASK;
590dee1ad47SJeff Kirsher
591dee1ad47SJeff Kirsher /* write context desc */
592dee1ad47SJeff Kirsher ixgbe_tx_ctxtdesc(tx_ring, vlan_macip_lens, fcoe_sof_eof,
5938b75451bSNeerav Parikh type_tucmd, mss_l4len_idx);
594dee1ad47SJeff Kirsher
595244e27adSAlexander Duyck return 0;
596dee1ad47SJeff Kirsher }
597dee1ad47SJeff Kirsher
ixgbe_fcoe_dma_pool_free(struct ixgbe_fcoe * fcoe,unsigned int cpu)5985a1ee270SAlexander Duyck static void ixgbe_fcoe_dma_pool_free(struct ixgbe_fcoe *fcoe, unsigned int cpu)
5995a1ee270SAlexander Duyck {
6005a1ee270SAlexander Duyck struct ixgbe_fcoe_ddp_pool *ddp_pool;
6015a1ee270SAlexander Duyck
6025a1ee270SAlexander Duyck ddp_pool = per_cpu_ptr(fcoe->ddp_pool, cpu);
6035a1ee270SAlexander Duyck dma_pool_destroy(ddp_pool->pool);
6045a1ee270SAlexander Duyck ddp_pool->pool = NULL;
6055a1ee270SAlexander Duyck }
6065a1ee270SAlexander Duyck
ixgbe_fcoe_dma_pool_alloc(struct ixgbe_fcoe * fcoe,struct device * dev,unsigned int cpu)6075a1ee270SAlexander Duyck static int ixgbe_fcoe_dma_pool_alloc(struct ixgbe_fcoe *fcoe,
6085a1ee270SAlexander Duyck struct device *dev,
6095a1ee270SAlexander Duyck unsigned int cpu)
6105a1ee270SAlexander Duyck {
6115a1ee270SAlexander Duyck struct ixgbe_fcoe_ddp_pool *ddp_pool;
6125a1ee270SAlexander Duyck struct dma_pool *pool;
6135a1ee270SAlexander Duyck char pool_name[32];
6145a1ee270SAlexander Duyck
6150e7bcee4SMasanari Iida snprintf(pool_name, 32, "ixgbe_fcoe_ddp_%u", cpu);
6165a1ee270SAlexander Duyck
6175a1ee270SAlexander Duyck pool = dma_pool_create(pool_name, dev, IXGBE_FCPTR_MAX,
6185a1ee270SAlexander Duyck IXGBE_FCPTR_ALIGN, PAGE_SIZE);
6195a1ee270SAlexander Duyck if (!pool)
6205a1ee270SAlexander Duyck return -ENOMEM;
6215a1ee270SAlexander Duyck
6225a1ee270SAlexander Duyck ddp_pool = per_cpu_ptr(fcoe->ddp_pool, cpu);
6235a1ee270SAlexander Duyck ddp_pool->pool = pool;
6245a1ee270SAlexander Duyck ddp_pool->noddp = 0;
6255a1ee270SAlexander Duyck ddp_pool->noddp_ext_buff = 0;
6265a1ee270SAlexander Duyck
6275a1ee270SAlexander Duyck return 0;
628dee1ad47SJeff Kirsher }
629dee1ad47SJeff Kirsher
630dee1ad47SJeff Kirsher /**
631dee1ad47SJeff Kirsher * ixgbe_configure_fcoe - configures registers for fcoe at start
632dee1ad47SJeff Kirsher * @adapter: ptr to ixgbe adapter
633dee1ad47SJeff Kirsher *
634dee1ad47SJeff Kirsher * This sets up FCoE related registers
635dee1ad47SJeff Kirsher *
636dee1ad47SJeff Kirsher * Returns : none
637dee1ad47SJeff Kirsher */
ixgbe_configure_fcoe(struct ixgbe_adapter * adapter)638dee1ad47SJeff Kirsher void ixgbe_configure_fcoe(struct ixgbe_adapter *adapter)
639dee1ad47SJeff Kirsher {
6407c8ae65aSAlexander Duyck struct ixgbe_ring_feature *fcoe = &adapter->ring_feature[RING_F_FCOE];
641dee1ad47SJeff Kirsher struct ixgbe_hw *hw = &adapter->hw;
642ea412015SVasu Dev int i, fcoe_q, fcoe_i, fcoe_q_h = 0;
643ea412015SVasu Dev int fcreta_size;
64481faddefSAlexander Duyck u32 etqf;
645dee1ad47SJeff Kirsher
646a58915c7SAlexander Duyck /* Minimal functionality for FCoE requires at least CRC offloads */
647a58915c7SAlexander Duyck if (!(adapter->netdev->features & NETIF_F_FCOE_CRC))
648dee1ad47SJeff Kirsher return;
649dee1ad47SJeff Kirsher
650a58915c7SAlexander Duyck /* Enable L2 EtherType filter for FCoE, needed for FCoE CRC and DDP */
65181faddefSAlexander Duyck etqf = ETH_P_FCOE | IXGBE_ETQF_FCOE | IXGBE_ETQF_FILTER_EN;
65281faddefSAlexander Duyck if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) {
65381faddefSAlexander Duyck etqf |= IXGBE_ETQF_POOL_ENABLE;
65481faddefSAlexander Duyck etqf |= VMDQ_P(0) << IXGBE_ETQF_POOL_SHIFT;
65581faddefSAlexander Duyck }
65681faddefSAlexander Duyck IXGBE_WRITE_REG(hw, IXGBE_ETQF(IXGBE_ETQF_FILTER_FCOE), etqf);
65781faddefSAlexander Duyck IXGBE_WRITE_REG(hw, IXGBE_ETQS(IXGBE_ETQF_FILTER_FCOE), 0);
65881faddefSAlexander Duyck
659a58915c7SAlexander Duyck /* leave registers un-configured if FCoE is disabled */
660a58915c7SAlexander Duyck if (!(adapter->flags & IXGBE_FLAG_FCOE_ENABLED))
661a58915c7SAlexander Duyck return;
662a58915c7SAlexander Duyck
66381faddefSAlexander Duyck /* Use one or more Rx queues for FCoE by redirection table */
664ea412015SVasu Dev fcreta_size = IXGBE_FCRETA_SIZE;
665ea412015SVasu Dev if (adapter->hw.mac.type == ixgbe_mac_X550)
666ea412015SVasu Dev fcreta_size = IXGBE_FCRETA_SIZE_X550;
667ea412015SVasu Dev
668ea412015SVasu Dev for (i = 0; i < fcreta_size; i++) {
669ea412015SVasu Dev if (adapter->hw.mac.type == ixgbe_mac_X550) {
670ea412015SVasu Dev int fcoe_i_h = fcoe->offset + ((i + fcreta_size) %
671ea412015SVasu Dev fcoe->indices);
672ea412015SVasu Dev fcoe_q_h = adapter->rx_ring[fcoe_i_h]->reg_idx;
6734d893c10SJesse Brandeburg fcoe_q_h = FIELD_PREP(IXGBE_FCRETA_ENTRY_HIGH_MASK,
6744d893c10SJesse Brandeburg fcoe_q_h);
675ea412015SVasu Dev }
676ea412015SVasu Dev
6777c8ae65aSAlexander Duyck fcoe_i = fcoe->offset + (i % fcoe->indices);
678dee1ad47SJeff Kirsher fcoe_i &= IXGBE_FCRETA_ENTRY_MASK;
679dee1ad47SJeff Kirsher fcoe_q = adapter->rx_ring[fcoe_i]->reg_idx;
680ea412015SVasu Dev fcoe_q |= fcoe_q_h;
681dee1ad47SJeff Kirsher IXGBE_WRITE_REG(hw, IXGBE_FCRETA(i), fcoe_q);
682dee1ad47SJeff Kirsher }
683dee1ad47SJeff Kirsher IXGBE_WRITE_REG(hw, IXGBE_FCRECTL, IXGBE_FCRECTL_ENA);
68481faddefSAlexander Duyck
68581faddefSAlexander Duyck /* Enable L2 EtherType filter for FIP */
68681faddefSAlexander Duyck etqf = ETH_P_FIP | IXGBE_ETQF_FILTER_EN;
68781faddefSAlexander Duyck if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) {
68881faddefSAlexander Duyck etqf |= IXGBE_ETQF_POOL_ENABLE;
68981faddefSAlexander Duyck etqf |= VMDQ_P(0) << IXGBE_ETQF_POOL_SHIFT;
690dee1ad47SJeff Kirsher }
69181faddefSAlexander Duyck IXGBE_WRITE_REG(hw, IXGBE_ETQF(IXGBE_ETQF_FILTER_FIP), etqf);
69281faddefSAlexander Duyck
69381faddefSAlexander Duyck /* Send FIP frames to the first FCoE queue */
6947c8ae65aSAlexander Duyck fcoe_q = adapter->rx_ring[fcoe->offset]->reg_idx;
695dee1ad47SJeff Kirsher IXGBE_WRITE_REG(hw, IXGBE_ETQS(IXGBE_ETQF_FILTER_FIP),
696dee1ad47SJeff Kirsher IXGBE_ETQS_QUEUE_EN |
697dee1ad47SJeff Kirsher (fcoe_q << IXGBE_ETQS_RX_QUEUE_SHIFT));
698dee1ad47SJeff Kirsher
69981faddefSAlexander Duyck /* Configure FCoE Rx control */
70081faddefSAlexander Duyck IXGBE_WRITE_REG(hw, IXGBE_FCRXCTRL,
70181faddefSAlexander Duyck IXGBE_FCRXCTRL_FCCRCBO |
702dee1ad47SJeff Kirsher (FC_FCOE_VER << IXGBE_FCRXCTRL_FCOEVER_SHIFT));
703dee1ad47SJeff Kirsher }
704dee1ad47SJeff Kirsher
705dee1ad47SJeff Kirsher /**
7067c8ae65aSAlexander Duyck * ixgbe_free_fcoe_ddp_resources - release all fcoe ddp context resources
707dee1ad47SJeff Kirsher * @adapter : ixgbe adapter
708dee1ad47SJeff Kirsher *
709dee1ad47SJeff Kirsher * Cleans up outstanding ddp context resources
710dee1ad47SJeff Kirsher *
711dee1ad47SJeff Kirsher * Returns : none
712dee1ad47SJeff Kirsher */
ixgbe_free_fcoe_ddp_resources(struct ixgbe_adapter * adapter)7137c8ae65aSAlexander Duyck void ixgbe_free_fcoe_ddp_resources(struct ixgbe_adapter *adapter)
714dee1ad47SJeff Kirsher {
715dee1ad47SJeff Kirsher struct ixgbe_fcoe *fcoe = &adapter->fcoe;
716ea412015SVasu Dev int cpu, i, ddp_max;
717dee1ad47SJeff Kirsher
7187c8ae65aSAlexander Duyck /* do nothing if no DDP pools were allocated */
7195a1ee270SAlexander Duyck if (!fcoe->ddp_pool)
720dee1ad47SJeff Kirsher return;
721dee1ad47SJeff Kirsher
722ea412015SVasu Dev ddp_max = IXGBE_FCOE_DDP_MAX;
723ea412015SVasu Dev /* X550 has different DDP Max limit */
724ea412015SVasu Dev if (adapter->hw.mac.type == ixgbe_mac_X550)
725ea412015SVasu Dev ddp_max = IXGBE_FCOE_DDP_MAX_X550;
726ea412015SVasu Dev
727ea412015SVasu Dev for (i = 0; i < ddp_max; i++)
728dee1ad47SJeff Kirsher ixgbe_fcoe_ddp_put(adapter->netdev, i);
7295a1ee270SAlexander Duyck
7307c8ae65aSAlexander Duyck for_each_possible_cpu(cpu)
7317c8ae65aSAlexander Duyck ixgbe_fcoe_dma_pool_free(fcoe, cpu);
7327c8ae65aSAlexander Duyck
733dee1ad47SJeff Kirsher dma_unmap_single(&adapter->pdev->dev,
734dee1ad47SJeff Kirsher fcoe->extra_ddp_buffer_dma,
735dee1ad47SJeff Kirsher IXGBE_FCBUFF_MIN,
736dee1ad47SJeff Kirsher DMA_FROM_DEVICE);
737dee1ad47SJeff Kirsher kfree(fcoe->extra_ddp_buffer);
7385a1ee270SAlexander Duyck
7397c8ae65aSAlexander Duyck fcoe->extra_ddp_buffer = NULL;
7407c8ae65aSAlexander Duyck fcoe->extra_ddp_buffer_dma = 0;
7417c8ae65aSAlexander Duyck }
7427c8ae65aSAlexander Duyck
7437c8ae65aSAlexander Duyck /**
7447c8ae65aSAlexander Duyck * ixgbe_setup_fcoe_ddp_resources - setup all fcoe ddp context resources
7457c8ae65aSAlexander Duyck * @adapter: ixgbe adapter
7467c8ae65aSAlexander Duyck *
7477c8ae65aSAlexander Duyck * Sets up ddp context resouces
7487c8ae65aSAlexander Duyck *
7497c8ae65aSAlexander Duyck * Returns : 0 indicates success or -EINVAL on failure
7507c8ae65aSAlexander Duyck */
ixgbe_setup_fcoe_ddp_resources(struct ixgbe_adapter * adapter)7517c8ae65aSAlexander Duyck int ixgbe_setup_fcoe_ddp_resources(struct ixgbe_adapter *adapter)
7527c8ae65aSAlexander Duyck {
7537c8ae65aSAlexander Duyck struct ixgbe_fcoe *fcoe = &adapter->fcoe;
7547c8ae65aSAlexander Duyck struct device *dev = &adapter->pdev->dev;
7557c8ae65aSAlexander Duyck void *buffer;
7567c8ae65aSAlexander Duyck dma_addr_t dma;
7577c8ae65aSAlexander Duyck unsigned int cpu;
7587c8ae65aSAlexander Duyck
7597c8ae65aSAlexander Duyck /* do nothing if no DDP pools were allocated */
7607c8ae65aSAlexander Duyck if (!fcoe->ddp_pool)
7617c8ae65aSAlexander Duyck return 0;
7627c8ae65aSAlexander Duyck
7637c8ae65aSAlexander Duyck /* Extra buffer to be shared by all DDPs for HW work around */
764374f78f7SJia-Ju Bai buffer = kmalloc(IXGBE_FCBUFF_MIN, GFP_KERNEL);
76514f8dc49SJoe Perches if (!buffer)
7667c8ae65aSAlexander Duyck return -ENOMEM;
7677c8ae65aSAlexander Duyck
7687c8ae65aSAlexander Duyck dma = dma_map_single(dev, buffer, IXGBE_FCBUFF_MIN, DMA_FROM_DEVICE);
7697c8ae65aSAlexander Duyck if (dma_mapping_error(dev, dma)) {
7707c8ae65aSAlexander Duyck e_err(drv, "failed to map extra DDP buffer\n");
7717c8ae65aSAlexander Duyck kfree(buffer);
7727c8ae65aSAlexander Duyck return -ENOMEM;
7737c8ae65aSAlexander Duyck }
7747c8ae65aSAlexander Duyck
7757c8ae65aSAlexander Duyck fcoe->extra_ddp_buffer = buffer;
7767c8ae65aSAlexander Duyck fcoe->extra_ddp_buffer_dma = dma;
7777c8ae65aSAlexander Duyck
7787c8ae65aSAlexander Duyck /* allocate pci pool for each cpu */
7797c8ae65aSAlexander Duyck for_each_possible_cpu(cpu) {
7807c8ae65aSAlexander Duyck int err = ixgbe_fcoe_dma_pool_alloc(fcoe, dev, cpu);
7817c8ae65aSAlexander Duyck if (!err)
7827c8ae65aSAlexander Duyck continue;
7837c8ae65aSAlexander Duyck
7847c8ae65aSAlexander Duyck e_err(drv, "failed to alloc DDP pool on cpu:%d\n", cpu);
7857c8ae65aSAlexander Duyck ixgbe_free_fcoe_ddp_resources(adapter);
7867c8ae65aSAlexander Duyck return -ENOMEM;
7877c8ae65aSAlexander Duyck }
7887c8ae65aSAlexander Duyck
7897c8ae65aSAlexander Duyck return 0;
7907c8ae65aSAlexander Duyck }
7917c8ae65aSAlexander Duyck
ixgbe_fcoe_ddp_enable(struct ixgbe_adapter * adapter)7927c8ae65aSAlexander Duyck static int ixgbe_fcoe_ddp_enable(struct ixgbe_adapter *adapter)
7937c8ae65aSAlexander Duyck {
7947c8ae65aSAlexander Duyck struct ixgbe_fcoe *fcoe = &adapter->fcoe;
7957c8ae65aSAlexander Duyck
7967c8ae65aSAlexander Duyck if (!(adapter->flags & IXGBE_FLAG_FCOE_CAPABLE))
7977c8ae65aSAlexander Duyck return -EINVAL;
7987c8ae65aSAlexander Duyck
7997c8ae65aSAlexander Duyck fcoe->ddp_pool = alloc_percpu(struct ixgbe_fcoe_ddp_pool);
8007c8ae65aSAlexander Duyck
8017c8ae65aSAlexander Duyck if (!fcoe->ddp_pool) {
8027c8ae65aSAlexander Duyck e_err(drv, "failed to allocate percpu DDP resources\n");
8037c8ae65aSAlexander Duyck return -ENOMEM;
8047c8ae65aSAlexander Duyck }
8057c8ae65aSAlexander Duyck
8067c8ae65aSAlexander Duyck adapter->netdev->fcoe_ddp_xid = IXGBE_FCOE_DDP_MAX - 1;
807ea412015SVasu Dev /* X550 has different DDP Max limit */
808ea412015SVasu Dev if (adapter->hw.mac.type == ixgbe_mac_X550)
809ea412015SVasu Dev adapter->netdev->fcoe_ddp_xid = IXGBE_FCOE_DDP_MAX_X550 - 1;
8107c8ae65aSAlexander Duyck
8117c8ae65aSAlexander Duyck return 0;
8127c8ae65aSAlexander Duyck }
8137c8ae65aSAlexander Duyck
ixgbe_fcoe_ddp_disable(struct ixgbe_adapter * adapter)8147c8ae65aSAlexander Duyck static void ixgbe_fcoe_ddp_disable(struct ixgbe_adapter *adapter)
8157c8ae65aSAlexander Duyck {
8167c8ae65aSAlexander Duyck struct ixgbe_fcoe *fcoe = &adapter->fcoe;
8177c8ae65aSAlexander Duyck
8187c8ae65aSAlexander Duyck adapter->netdev->fcoe_ddp_xid = 0;
8197c8ae65aSAlexander Duyck
8207c8ae65aSAlexander Duyck if (!fcoe->ddp_pool)
8217c8ae65aSAlexander Duyck return;
8227c8ae65aSAlexander Duyck
8237c8ae65aSAlexander Duyck free_percpu(fcoe->ddp_pool);
8247c8ae65aSAlexander Duyck fcoe->ddp_pool = NULL;
825dee1ad47SJeff Kirsher }
826dee1ad47SJeff Kirsher
827dee1ad47SJeff Kirsher /**
828dee1ad47SJeff Kirsher * ixgbe_fcoe_enable - turn on FCoE offload feature
829dee1ad47SJeff Kirsher * @netdev: the corresponding netdev
830dee1ad47SJeff Kirsher *
831dee1ad47SJeff Kirsher * Turns on FCoE offload feature in 82599.
832dee1ad47SJeff Kirsher *
833dee1ad47SJeff Kirsher * Returns : 0 indicates success or -EINVAL on failure
834dee1ad47SJeff Kirsher */
ixgbe_fcoe_enable(struct net_device * netdev)835dee1ad47SJeff Kirsher int ixgbe_fcoe_enable(struct net_device *netdev)
836dee1ad47SJeff Kirsher {
837dee1ad47SJeff Kirsher struct ixgbe_adapter *adapter = netdev_priv(netdev);
838dee1ad47SJeff Kirsher struct ixgbe_fcoe *fcoe = &adapter->fcoe;
839dee1ad47SJeff Kirsher
8407c8ae65aSAlexander Duyck atomic_inc(&fcoe->refcnt);
841dee1ad47SJeff Kirsher
842dee1ad47SJeff Kirsher if (!(adapter->flags & IXGBE_FLAG_FCOE_CAPABLE))
8437c8ae65aSAlexander Duyck return -EINVAL;
844dee1ad47SJeff Kirsher
845dee1ad47SJeff Kirsher if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED)
8467c8ae65aSAlexander Duyck return -EINVAL;
847dee1ad47SJeff Kirsher
848dee1ad47SJeff Kirsher e_info(drv, "Enabling FCoE offload features.\n");
849872844ddSAlexander Duyck
850872844ddSAlexander Duyck if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
851872844ddSAlexander Duyck e_warn(probe, "Enabling FCoE on PF will disable legacy VFs\n");
852872844ddSAlexander Duyck
853dee1ad47SJeff Kirsher if (netif_running(netdev))
854dee1ad47SJeff Kirsher netdev->netdev_ops->ndo_stop(netdev);
855dee1ad47SJeff Kirsher
8567c8ae65aSAlexander Duyck /* Allocate per CPU memory to track DDP pools */
8577c8ae65aSAlexander Duyck ixgbe_fcoe_ddp_enable(adapter);
858dee1ad47SJeff Kirsher
8597c8ae65aSAlexander Duyck /* enable FCoE and notify stack */
860dee1ad47SJeff Kirsher adapter->flags |= IXGBE_FLAG_FCOE_ENABLED;
861*782dbbf5SAlexander Lobakin netdev->fcoe_mtu = true;
862dee1ad47SJeff Kirsher netdev_features_change(netdev);
863dee1ad47SJeff Kirsher
8647c8ae65aSAlexander Duyck /* release existing queues and reallocate them */
8657c8ae65aSAlexander Duyck ixgbe_clear_interrupt_scheme(adapter);
8667c8ae65aSAlexander Duyck ixgbe_init_interrupt_scheme(adapter);
8677c8ae65aSAlexander Duyck
868dee1ad47SJeff Kirsher if (netif_running(netdev))
869dee1ad47SJeff Kirsher netdev->netdev_ops->ndo_open(netdev);
870dee1ad47SJeff Kirsher
8717c8ae65aSAlexander Duyck return 0;
872dee1ad47SJeff Kirsher }
873dee1ad47SJeff Kirsher
874dee1ad47SJeff Kirsher /**
875dee1ad47SJeff Kirsher * ixgbe_fcoe_disable - turn off FCoE offload feature
876dee1ad47SJeff Kirsher * @netdev: the corresponding netdev
877dee1ad47SJeff Kirsher *
878dee1ad47SJeff Kirsher * Turns off FCoE offload feature in 82599.
879dee1ad47SJeff Kirsher *
880dee1ad47SJeff Kirsher * Returns : 0 indicates success or -EINVAL on failure
881dee1ad47SJeff Kirsher */
ixgbe_fcoe_disable(struct net_device * netdev)882dee1ad47SJeff Kirsher int ixgbe_fcoe_disable(struct net_device *netdev)
883dee1ad47SJeff Kirsher {
884dee1ad47SJeff Kirsher struct ixgbe_adapter *adapter = netdev_priv(netdev);
885dee1ad47SJeff Kirsher
8867c8ae65aSAlexander Duyck if (!atomic_dec_and_test(&adapter->fcoe.refcnt))
8877c8ae65aSAlexander Duyck return -EINVAL;
888dee1ad47SJeff Kirsher
889dee1ad47SJeff Kirsher if (!(adapter->flags & IXGBE_FLAG_FCOE_ENABLED))
8907c8ae65aSAlexander Duyck return -EINVAL;
891dee1ad47SJeff Kirsher
892dee1ad47SJeff Kirsher e_info(drv, "Disabling FCoE offload features.\n");
893dee1ad47SJeff Kirsher if (netif_running(netdev))
894dee1ad47SJeff Kirsher netdev->netdev_ops->ndo_stop(netdev);
895dee1ad47SJeff Kirsher
8967c8ae65aSAlexander Duyck /* Free per CPU memory to track DDP pools */
8977c8ae65aSAlexander Duyck ixgbe_fcoe_ddp_disable(adapter);
8987c8ae65aSAlexander Duyck
8997c8ae65aSAlexander Duyck /* disable FCoE and notify stack */
900dee1ad47SJeff Kirsher adapter->flags &= ~IXGBE_FLAG_FCOE_ENABLED;
901*782dbbf5SAlexander Lobakin netdev->fcoe_mtu = false;
9027c8ae65aSAlexander Duyck
9037c8ae65aSAlexander Duyck netdev_features_change(netdev);
9047c8ae65aSAlexander Duyck
9057c8ae65aSAlexander Duyck /* release existing queues and reallocate them */
9067c8ae65aSAlexander Duyck ixgbe_clear_interrupt_scheme(adapter);
907dee1ad47SJeff Kirsher ixgbe_init_interrupt_scheme(adapter);
908dee1ad47SJeff Kirsher
909dee1ad47SJeff Kirsher if (netif_running(netdev))
910dee1ad47SJeff Kirsher netdev->netdev_ops->ndo_open(netdev);
911dee1ad47SJeff Kirsher
9127c8ae65aSAlexander Duyck return 0;
913dee1ad47SJeff Kirsher }
914dee1ad47SJeff Kirsher
915dee1ad47SJeff Kirsher /**
916dee1ad47SJeff Kirsher * ixgbe_fcoe_get_wwn - get world wide name for the node or the port
917dee1ad47SJeff Kirsher * @netdev : ixgbe adapter
918dee1ad47SJeff Kirsher * @wwn : the world wide name
919dee1ad47SJeff Kirsher * @type: the type of world wide name
920dee1ad47SJeff Kirsher *
921dee1ad47SJeff Kirsher * Returns the node or port world wide name if both the prefix and the san
922dee1ad47SJeff Kirsher * mac address are valid, then the wwn is formed based on the NAA-2 for
923dee1ad47SJeff Kirsher * IEEE Extended name identifier (ref. to T10 FC-LS Spec., Sec. 15.3).
924dee1ad47SJeff Kirsher *
925dee1ad47SJeff Kirsher * Returns : 0 on success
926dee1ad47SJeff Kirsher */
ixgbe_fcoe_get_wwn(struct net_device * netdev,u64 * wwn,int type)927dee1ad47SJeff Kirsher int ixgbe_fcoe_get_wwn(struct net_device *netdev, u64 *wwn, int type)
928dee1ad47SJeff Kirsher {
929dee1ad47SJeff Kirsher u16 prefix = 0xffff;
930dee1ad47SJeff Kirsher struct ixgbe_adapter *adapter = netdev_priv(netdev);
931dee1ad47SJeff Kirsher struct ixgbe_mac_info *mac = &adapter->hw.mac;
932dee1ad47SJeff Kirsher
933dee1ad47SJeff Kirsher switch (type) {
934dee1ad47SJeff Kirsher case NETDEV_FCOE_WWNN:
935dee1ad47SJeff Kirsher prefix = mac->wwnn_prefix;
936dee1ad47SJeff Kirsher break;
937dee1ad47SJeff Kirsher case NETDEV_FCOE_WWPN:
938dee1ad47SJeff Kirsher prefix = mac->wwpn_prefix;
939dee1ad47SJeff Kirsher break;
940dee1ad47SJeff Kirsher default:
941dee1ad47SJeff Kirsher break;
942dee1ad47SJeff Kirsher }
943dee1ad47SJeff Kirsher
944dee1ad47SJeff Kirsher if ((prefix != 0xffff) &&
945dee1ad47SJeff Kirsher is_valid_ether_addr(mac->san_addr)) {
946dee1ad47SJeff Kirsher *wwn = ((u64) prefix << 48) |
947dee1ad47SJeff Kirsher ((u64) mac->san_addr[0] << 40) |
948dee1ad47SJeff Kirsher ((u64) mac->san_addr[1] << 32) |
949dee1ad47SJeff Kirsher ((u64) mac->san_addr[2] << 24) |
950dee1ad47SJeff Kirsher ((u64) mac->san_addr[3] << 16) |
951dee1ad47SJeff Kirsher ((u64) mac->san_addr[4] << 8) |
952dee1ad47SJeff Kirsher ((u64) mac->san_addr[5]);
953e90dd264SMark Rustad return 0;
954dee1ad47SJeff Kirsher }
955e90dd264SMark Rustad return -EINVAL;
956dee1ad47SJeff Kirsher }
957ea81875aSNeerav Parikh
958ea81875aSNeerav Parikh /**
959ea81875aSNeerav Parikh * ixgbe_fcoe_get_hbainfo - get FCoE HBA information
960ea81875aSNeerav Parikh * @netdev : ixgbe adapter
961ea81875aSNeerav Parikh * @info : HBA information
962ea81875aSNeerav Parikh *
963ea81875aSNeerav Parikh * Returns ixgbe HBA information
964ea81875aSNeerav Parikh *
965ea81875aSNeerav Parikh * Returns : 0 on success
966ea81875aSNeerav Parikh */
ixgbe_fcoe_get_hbainfo(struct net_device * netdev,struct netdev_fcoe_hbainfo * info)967ea81875aSNeerav Parikh int ixgbe_fcoe_get_hbainfo(struct net_device *netdev,
968ea81875aSNeerav Parikh struct netdev_fcoe_hbainfo *info)
969ea81875aSNeerav Parikh {
970ea81875aSNeerav Parikh struct ixgbe_adapter *adapter = netdev_priv(netdev);
971ea81875aSNeerav Parikh struct ixgbe_hw *hw = &adapter->hw;
972f998958dSJacob Keller u64 dsn;
973ea81875aSNeerav Parikh
974ea81875aSNeerav Parikh if (!info)
975ea81875aSNeerav Parikh return -EINVAL;
976ea81875aSNeerav Parikh
977ea81875aSNeerav Parikh /* Don't return information on unsupported devices */
978b262a9a7SUsha Ketineni if (!(adapter->flags & IXGBE_FLAG_FCOE_ENABLED))
979ea81875aSNeerav Parikh return -EINVAL;
980ea81875aSNeerav Parikh
981ea81875aSNeerav Parikh /* Manufacturer */
982ea81875aSNeerav Parikh snprintf(info->manufacturer, sizeof(info->manufacturer),
983ea81875aSNeerav Parikh "Intel Corporation");
984ea81875aSNeerav Parikh
985ea81875aSNeerav Parikh /* Serial Number */
986ea81875aSNeerav Parikh
987ea81875aSNeerav Parikh /* Get the PCI-e Device Serial Number Capability */
988f998958dSJacob Keller dsn = pci_get_dsn(adapter->pdev);
989f998958dSJacob Keller if (dsn)
990ea81875aSNeerav Parikh snprintf(info->serial_number, sizeof(info->serial_number),
991f998958dSJacob Keller "%016llX", dsn);
992f998958dSJacob Keller else
993ea81875aSNeerav Parikh snprintf(info->serial_number, sizeof(info->serial_number),
994ea81875aSNeerav Parikh "Unknown");
995ea81875aSNeerav Parikh
996ea81875aSNeerav Parikh /* Hardware Version */
997ea81875aSNeerav Parikh snprintf(info->hardware_version,
998ea81875aSNeerav Parikh sizeof(info->hardware_version),
999ea81875aSNeerav Parikh "Rev %d", hw->revision_id);
1000ea81875aSNeerav Parikh /* Driver Name/Version */
1001ea81875aSNeerav Parikh snprintf(info->driver_version,
1002ea81875aSNeerav Parikh sizeof(info->driver_version),
1003ea81875aSNeerav Parikh "%s v%s",
1004ea81875aSNeerav Parikh ixgbe_driver_name,
100534a2a3b8SJeff Kirsher UTS_RELEASE);
1006ea81875aSNeerav Parikh /* Firmware Version */
1007f029c781SWolfram Sang strscpy(info->firmware_version, adapter->eeprom_id,
100873834aecSPaul Greenwalt sizeof(info->firmware_version));
1009ea81875aSNeerav Parikh
1010ea81875aSNeerav Parikh /* Model */
1011ea81875aSNeerav Parikh if (hw->mac.type == ixgbe_mac_82599EB) {
1012ea81875aSNeerav Parikh snprintf(info->model,
1013ea81875aSNeerav Parikh sizeof(info->model),
1014ea81875aSNeerav Parikh "Intel 82599");
1015b262a9a7SUsha Ketineni } else if (hw->mac.type == ixgbe_mac_X550) {
1016b262a9a7SUsha Ketineni snprintf(info->model,
1017b262a9a7SUsha Ketineni sizeof(info->model),
1018b262a9a7SUsha Ketineni "Intel X550");
1019ea81875aSNeerav Parikh } else {
1020ea81875aSNeerav Parikh snprintf(info->model,
1021ea81875aSNeerav Parikh sizeof(info->model),
1022ea81875aSNeerav Parikh "Intel X540");
1023ea81875aSNeerav Parikh }
1024ea81875aSNeerav Parikh
1025ea81875aSNeerav Parikh /* Model Description */
1026ea81875aSNeerav Parikh snprintf(info->model_description,
1027ea81875aSNeerav Parikh sizeof(info->model_description),
1028ea81875aSNeerav Parikh "%s",
1029ea81875aSNeerav Parikh ixgbe_default_device_descr);
1030ea81875aSNeerav Parikh
1031ea81875aSNeerav Parikh return 0;
1032ea81875aSNeerav Parikh }
1033800bd607SAlexander Duyck
1034800bd607SAlexander Duyck /**
1035800bd607SAlexander Duyck * ixgbe_fcoe_get_tc - get the current TC that fcoe is mapped to
10365ba643c6STony Nguyen * @adapter: pointer to the device adapter structure
1037800bd607SAlexander Duyck *
1038800bd607SAlexander Duyck * Return : TC that FCoE is mapped to
1039800bd607SAlexander Duyck */
ixgbe_fcoe_get_tc(struct ixgbe_adapter * adapter)1040800bd607SAlexander Duyck u8 ixgbe_fcoe_get_tc(struct ixgbe_adapter *adapter)
1041800bd607SAlexander Duyck {
1042800bd607SAlexander Duyck #ifdef CONFIG_IXGBE_DCB
1043800bd607SAlexander Duyck return netdev_get_prio_tc_map(adapter->netdev, adapter->fcoe.up);
1044800bd607SAlexander Duyck #else
1045800bd607SAlexander Duyck return 0;
1046800bd607SAlexander Duyck #endif
1047800bd607SAlexander Duyck }
1048