ixgbe_fcoe.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720
  1. /*******************************************************************************
  2. Intel 10 Gigabit PCI Express Linux driver
  3. Copyright(c) 1999 - 2009 Intel Corporation.
  4. This program is free software; you can redistribute it and/or modify it
  5. under the terms and conditions of the GNU General Public License,
  6. version 2, as published by the Free Software Foundation.
  7. This program is distributed in the hope it will be useful, but WITHOUT
  8. ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  9. FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  10. more details.
  11. You should have received a copy of the GNU General Public License along with
  12. this program; if not, write to the Free Software Foundation, Inc.,
  13. 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
  14. The full GNU General Public License is included in this distribution in
  15. the file called "COPYING".
  16. Contact Information:
  17. e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
  18. Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
  19. *******************************************************************************/
  20. #include "ixgbe.h"
  21. #ifdef CONFIG_IXGBE_DCB
  22. #include "ixgbe_dcb_82599.h"
  23. #endif /* CONFIG_IXGBE_DCB */
  24. #include <linux/if_ether.h>
  25. #include <scsi/scsi_cmnd.h>
  26. #include <scsi/scsi_device.h>
  27. #include <scsi/fc/fc_fs.h>
  28. #include <scsi/fc/fc_fcoe.h>
  29. #include <scsi/libfc.h>
  30. #include <scsi/libfcoe.h>
  31. /**
  32. * ixgbe_rx_is_fcoe - check the rx desc for incoming pkt type
  33. * @rx_desc: advanced rx descriptor
  34. *
  35. * Returns : true if it is FCoE pkt
  36. */
  37. static inline bool ixgbe_rx_is_fcoe(union ixgbe_adv_rx_desc *rx_desc)
  38. {
  39. u16 p;
  40. p = le16_to_cpu(rx_desc->wb.lower.lo_dword.hs_rss.pkt_info);
  41. if (p & IXGBE_RXDADV_PKTTYPE_ETQF) {
  42. p &= IXGBE_RXDADV_PKTTYPE_ETQF_MASK;
  43. p >>= IXGBE_RXDADV_PKTTYPE_ETQF_SHIFT;
  44. return p == IXGBE_ETQF_FILTER_FCOE;
  45. }
  46. return false;
  47. }
  48. /**
  49. * ixgbe_fcoe_clear_ddp - clear the given ddp context
  50. * @ddp - ptr to the ixgbe_fcoe_ddp
  51. *
  52. * Returns : none
  53. *
  54. */
  55. static inline void ixgbe_fcoe_clear_ddp(struct ixgbe_fcoe_ddp *ddp)
  56. {
  57. ddp->len = 0;
  58. ddp->err = 0;
  59. ddp->udl = NULL;
  60. ddp->udp = 0UL;
  61. ddp->sgl = NULL;
  62. ddp->sgc = 0;
  63. }
  64. /**
  65. * ixgbe_fcoe_ddp_put - free the ddp context for a given xid
  66. * @netdev: the corresponding net_device
  67. * @xid: the xid that corresponding ddp will be freed
  68. *
  69. * This is the implementation of net_device_ops.ndo_fcoe_ddp_done
  70. * and it is expected to be called by ULD, i.e., FCP layer of libfc
  71. * to release the corresponding ddp context when the I/O is done.
  72. *
  73. * Returns : data length already ddp-ed in bytes
  74. */
  75. int ixgbe_fcoe_ddp_put(struct net_device *netdev, u16 xid)
  76. {
  77. int len = 0;
  78. struct ixgbe_fcoe *fcoe;
  79. struct ixgbe_adapter *adapter;
  80. struct ixgbe_fcoe_ddp *ddp;
  81. if (!netdev)
  82. goto out_ddp_put;
  83. if (xid >= IXGBE_FCOE_DDP_MAX)
  84. goto out_ddp_put;
  85. adapter = netdev_priv(netdev);
  86. fcoe = &adapter->fcoe;
  87. ddp = &fcoe->ddp[xid];
  88. if (!ddp->udl)
  89. goto out_ddp_put;
  90. len = ddp->len;
  91. /* if there an error, force to invalidate ddp context */
  92. if (ddp->err) {
  93. spin_lock_bh(&fcoe->lock);
  94. IXGBE_WRITE_REG(&adapter->hw, IXGBE_FCFLT, 0);
  95. IXGBE_WRITE_REG(&adapter->hw, IXGBE_FCFLTRW,
  96. (xid | IXGBE_FCFLTRW_WE));
  97. IXGBE_WRITE_REG(&adapter->hw, IXGBE_FCBUFF, 0);
  98. IXGBE_WRITE_REG(&adapter->hw, IXGBE_FCDMARW,
  99. (xid | IXGBE_FCDMARW_WE));
  100. spin_unlock_bh(&fcoe->lock);
  101. }
  102. if (ddp->sgl)
  103. pci_unmap_sg(adapter->pdev, ddp->sgl, ddp->sgc,
  104. DMA_FROM_DEVICE);
  105. pci_pool_free(fcoe->pool, ddp->udl, ddp->udp);
  106. ixgbe_fcoe_clear_ddp(ddp);
  107. out_ddp_put:
  108. return len;
  109. }
  110. /**
  111. * ixgbe_fcoe_ddp_get - called to set up ddp context
  112. * @netdev: the corresponding net_device
  113. * @xid: the exchange id requesting ddp
  114. * @sgl: the scatter-gather list for this request
  115. * @sgc: the number of scatter-gather items
  116. *
  117. * This is the implementation of net_device_ops.ndo_fcoe_ddp_setup
  118. * and is expected to be called from ULD, e.g., FCP layer of libfc
  119. * to set up ddp for the corresponding xid of the given sglist for
  120. * the corresponding I/O.
  121. *
  122. * Returns : 1 for success and 0 for no ddp
  123. */
  124. int ixgbe_fcoe_ddp_get(struct net_device *netdev, u16 xid,
  125. struct scatterlist *sgl, unsigned int sgc)
  126. {
  127. struct ixgbe_adapter *adapter;
  128. struct ixgbe_hw *hw;
  129. struct ixgbe_fcoe *fcoe;
  130. struct ixgbe_fcoe_ddp *ddp;
  131. struct scatterlist *sg;
  132. unsigned int i, j, dmacount;
  133. unsigned int len;
  134. static const unsigned int bufflen = 4096;
  135. unsigned int firstoff = 0;
  136. unsigned int lastsize;
  137. unsigned int thisoff = 0;
  138. unsigned int thislen = 0;
  139. u32 fcbuff, fcdmarw, fcfltrw;
  140. dma_addr_t addr;
  141. if (!netdev || !sgl)
  142. return 0;
  143. adapter = netdev_priv(netdev);
  144. if (xid >= IXGBE_FCOE_DDP_MAX) {
  145. DPRINTK(DRV, WARNING, "xid=0x%x out-of-range\n", xid);
  146. return 0;
  147. }
  148. fcoe = &adapter->fcoe;
  149. if (!fcoe->pool) {
  150. DPRINTK(DRV, WARNING, "xid=0x%x no ddp pool for fcoe\n", xid);
  151. return 0;
  152. }
  153. ddp = &fcoe->ddp[xid];
  154. if (ddp->sgl) {
  155. DPRINTK(DRV, ERR, "xid 0x%x w/ non-null sgl=%p nents=%d\n",
  156. xid, ddp->sgl, ddp->sgc);
  157. return 0;
  158. }
  159. ixgbe_fcoe_clear_ddp(ddp);
  160. /* setup dma from scsi command sgl */
  161. dmacount = pci_map_sg(adapter->pdev, sgl, sgc, DMA_FROM_DEVICE);
  162. if (dmacount == 0) {
  163. DPRINTK(DRV, ERR, "xid 0x%x DMA map error\n", xid);
  164. return 0;
  165. }
  166. /* alloc the udl from our ddp pool */
  167. ddp->udl = pci_pool_alloc(fcoe->pool, GFP_KERNEL, &ddp->udp);
  168. if (!ddp->udl) {
  169. DPRINTK(DRV, ERR, "failed allocated ddp context\n");
  170. goto out_noddp_unmap;
  171. }
  172. ddp->sgl = sgl;
  173. ddp->sgc = sgc;
  174. j = 0;
  175. for_each_sg(sgl, sg, dmacount, i) {
  176. addr = sg_dma_address(sg);
  177. len = sg_dma_len(sg);
  178. while (len) {
  179. /* get the offset of length of current buffer */
  180. thisoff = addr & ((dma_addr_t)bufflen - 1);
  181. thislen = min((bufflen - thisoff), len);
  182. /*
  183. * all but the 1st buffer (j == 0)
  184. * must be aligned on bufflen
  185. */
  186. if ((j != 0) && (thisoff))
  187. goto out_noddp_free;
  188. /*
  189. * all but the last buffer
  190. * ((i == (dmacount - 1)) && (thislen == len))
  191. * must end at bufflen
  192. */
  193. if (((i != (dmacount - 1)) || (thislen != len))
  194. && ((thislen + thisoff) != bufflen))
  195. goto out_noddp_free;
  196. ddp->udl[j] = (u64)(addr - thisoff);
  197. /* only the first buffer may have none-zero offset */
  198. if (j == 0)
  199. firstoff = thisoff;
  200. len -= thislen;
  201. addr += thislen;
  202. j++;
  203. /* max number of buffers allowed in one DDP context */
  204. if (j > IXGBE_BUFFCNT_MAX) {
  205. DPRINTK(DRV, ERR, "xid=%x:%d,%d,%d:addr=%llx "
  206. "not enough descriptors\n",
  207. xid, i, j, dmacount, (u64)addr);
  208. goto out_noddp_free;
  209. }
  210. }
  211. }
  212. /* only the last buffer may have non-full bufflen */
  213. lastsize = thisoff + thislen;
  214. fcbuff = (IXGBE_FCBUFF_4KB << IXGBE_FCBUFF_BUFFSIZE_SHIFT);
  215. fcbuff |= (j << IXGBE_FCBUFF_BUFFCNT_SHIFT);
  216. fcbuff |= (firstoff << IXGBE_FCBUFF_OFFSET_SHIFT);
  217. fcbuff |= (IXGBE_FCBUFF_VALID);
  218. fcdmarw = xid;
  219. fcdmarw |= IXGBE_FCDMARW_WE;
  220. fcdmarw |= (lastsize << IXGBE_FCDMARW_LASTSIZE_SHIFT);
  221. fcfltrw = xid;
  222. fcfltrw |= IXGBE_FCFLTRW_WE;
  223. /* program DMA context */
  224. hw = &adapter->hw;
  225. spin_lock_bh(&fcoe->lock);
  226. IXGBE_WRITE_REG(hw, IXGBE_FCPTRL, ddp->udp & DMA_BIT_MASK(32));
  227. IXGBE_WRITE_REG(hw, IXGBE_FCPTRH, (u64)ddp->udp >> 32);
  228. IXGBE_WRITE_REG(hw, IXGBE_FCBUFF, fcbuff);
  229. IXGBE_WRITE_REG(hw, IXGBE_FCDMARW, fcdmarw);
  230. /* program filter context */
  231. IXGBE_WRITE_REG(hw, IXGBE_FCPARAM, 0);
  232. IXGBE_WRITE_REG(hw, IXGBE_FCFLT, IXGBE_FCFLT_VALID);
  233. IXGBE_WRITE_REG(hw, IXGBE_FCFLTRW, fcfltrw);
  234. spin_unlock_bh(&fcoe->lock);
  235. return 1;
  236. out_noddp_free:
  237. pci_pool_free(fcoe->pool, ddp->udl, ddp->udp);
  238. ixgbe_fcoe_clear_ddp(ddp);
  239. out_noddp_unmap:
  240. pci_unmap_sg(adapter->pdev, sgl, sgc, DMA_FROM_DEVICE);
  241. return 0;
  242. }
  243. /**
  244. * ixgbe_fcoe_ddp - check ddp status and mark it done
  245. * @adapter: ixgbe adapter
  246. * @rx_desc: advanced rx descriptor
  247. * @skb: the skb holding the received data
  248. *
  249. * This checks ddp status.
  250. *
  251. * Returns : < 0 indicates an error or not a FCiE ddp, 0 indicates
  252. * not passing the skb to ULD, > 0 indicates is the length of data
  253. * being ddped.
  254. */
  255. int ixgbe_fcoe_ddp(struct ixgbe_adapter *adapter,
  256. union ixgbe_adv_rx_desc *rx_desc,
  257. struct sk_buff *skb)
  258. {
  259. u16 xid;
  260. u32 fctl;
  261. u32 sterr, fceofe, fcerr, fcstat;
  262. int rc = -EINVAL;
  263. struct ixgbe_fcoe *fcoe;
  264. struct ixgbe_fcoe_ddp *ddp;
  265. struct fc_frame_header *fh;
  266. if (!ixgbe_rx_is_fcoe(rx_desc))
  267. goto ddp_out;
  268. skb->ip_summed = CHECKSUM_UNNECESSARY;
  269. sterr = le32_to_cpu(rx_desc->wb.upper.status_error);
  270. fcerr = (sterr & IXGBE_RXDADV_ERR_FCERR);
  271. fceofe = (sterr & IXGBE_RXDADV_ERR_FCEOFE);
  272. if (fcerr == IXGBE_FCERR_BADCRC)
  273. skb->ip_summed = CHECKSUM_NONE;
  274. skb_reset_network_header(skb);
  275. skb_set_transport_header(skb, skb_network_offset(skb) +
  276. sizeof(struct fcoe_hdr));
  277. fh = (struct fc_frame_header *)skb_transport_header(skb);
  278. fctl = ntoh24(fh->fh_f_ctl);
  279. if (fctl & FC_FC_EX_CTX)
  280. xid = be16_to_cpu(fh->fh_ox_id);
  281. else
  282. xid = be16_to_cpu(fh->fh_rx_id);
  283. if (xid >= IXGBE_FCOE_DDP_MAX)
  284. goto ddp_out;
  285. fcoe = &adapter->fcoe;
  286. ddp = &fcoe->ddp[xid];
  287. if (!ddp->udl)
  288. goto ddp_out;
  289. ddp->err = (fcerr | fceofe);
  290. if (ddp->err)
  291. goto ddp_out;
  292. fcstat = (sterr & IXGBE_RXDADV_STAT_FCSTAT);
  293. if (fcstat) {
  294. /* update length of DDPed data */
  295. ddp->len = le32_to_cpu(rx_desc->wb.lower.hi_dword.rss);
  296. /* unmap the sg list when FCP_RSP is received */
  297. if (fcstat == IXGBE_RXDADV_STAT_FCSTAT_FCPRSP) {
  298. pci_unmap_sg(adapter->pdev, ddp->sgl,
  299. ddp->sgc, DMA_FROM_DEVICE);
  300. ddp->sgl = NULL;
  301. ddp->sgc = 0;
  302. }
  303. /* return 0 to bypass going to ULD for DDPed data */
  304. if (fcstat == IXGBE_RXDADV_STAT_FCSTAT_DDP)
  305. rc = 0;
  306. else if (ddp->len)
  307. rc = ddp->len;
  308. }
  309. ddp_out:
  310. return rc;
  311. }
  312. /**
  313. * ixgbe_fso - ixgbe FCoE Sequence Offload (FSO)
  314. * @adapter: ixgbe adapter
  315. * @tx_ring: tx desc ring
  316. * @skb: associated skb
  317. * @tx_flags: tx flags
  318. * @hdr_len: hdr_len to be returned
  319. *
  320. * This sets up large send offload for FCoE
  321. *
  322. * Returns : 0 indicates no FSO, > 0 for FSO, < 0 for error
  323. */
  324. int ixgbe_fso(struct ixgbe_adapter *adapter,
  325. struct ixgbe_ring *tx_ring, struct sk_buff *skb,
  326. u32 tx_flags, u8 *hdr_len)
  327. {
  328. u8 sof, eof;
  329. u32 vlan_macip_lens;
  330. u32 fcoe_sof_eof;
  331. u32 type_tucmd;
  332. u32 mss_l4len_idx;
  333. int mss = 0;
  334. unsigned int i;
  335. struct ixgbe_tx_buffer *tx_buffer_info;
  336. struct ixgbe_adv_tx_context_desc *context_desc;
  337. struct fc_frame_header *fh;
  338. if (skb_is_gso(skb) && (skb_shinfo(skb)->gso_type != SKB_GSO_FCOE)) {
  339. DPRINTK(DRV, ERR, "Wrong gso type %d:expecting SKB_GSO_FCOE\n",
  340. skb_shinfo(skb)->gso_type);
  341. return -EINVAL;
  342. }
  343. /* resets the header to point fcoe/fc */
  344. skb_set_network_header(skb, skb->mac_len);
  345. skb_set_transport_header(skb, skb->mac_len +
  346. sizeof(struct fcoe_hdr));
  347. /* sets up SOF and ORIS */
  348. fcoe_sof_eof = 0;
  349. sof = ((struct fcoe_hdr *)skb_network_header(skb))->fcoe_sof;
  350. switch (sof) {
  351. case FC_SOF_I2:
  352. fcoe_sof_eof |= IXGBE_ADVTXD_FCOEF_ORIS;
  353. break;
  354. case FC_SOF_I3:
  355. fcoe_sof_eof |= IXGBE_ADVTXD_FCOEF_SOF;
  356. fcoe_sof_eof |= IXGBE_ADVTXD_FCOEF_ORIS;
  357. break;
  358. case FC_SOF_N2:
  359. break;
  360. case FC_SOF_N3:
  361. fcoe_sof_eof |= IXGBE_ADVTXD_FCOEF_SOF;
  362. break;
  363. default:
  364. DPRINTK(DRV, WARNING, "unknown sof = 0x%x\n", sof);
  365. return -EINVAL;
  366. }
  367. /* the first byte of the last dword is EOF */
  368. skb_copy_bits(skb, skb->len - 4, &eof, 1);
  369. /* sets up EOF and ORIE */
  370. switch (eof) {
  371. case FC_EOF_N:
  372. fcoe_sof_eof |= IXGBE_ADVTXD_FCOEF_EOF_N;
  373. break;
  374. case FC_EOF_T:
  375. /* lso needs ORIE */
  376. if (skb_is_gso(skb)) {
  377. fcoe_sof_eof |= IXGBE_ADVTXD_FCOEF_EOF_N;
  378. fcoe_sof_eof |= IXGBE_ADVTXD_FCOEF_ORIE;
  379. } else {
  380. fcoe_sof_eof |= IXGBE_ADVTXD_FCOEF_EOF_T;
  381. }
  382. break;
  383. case FC_EOF_NI:
  384. fcoe_sof_eof |= IXGBE_ADVTXD_FCOEF_EOF_NI;
  385. break;
  386. case FC_EOF_A:
  387. fcoe_sof_eof |= IXGBE_ADVTXD_FCOEF_EOF_A;
  388. break;
  389. default:
  390. DPRINTK(DRV, WARNING, "unknown eof = 0x%x\n", eof);
  391. return -EINVAL;
  392. }
  393. /* sets up PARINC indicating data offset */
  394. fh = (struct fc_frame_header *)skb_transport_header(skb);
  395. if (fh->fh_f_ctl[2] & FC_FC_REL_OFF)
  396. fcoe_sof_eof |= IXGBE_ADVTXD_FCOEF_PARINC;
  397. /* hdr_len includes fc_hdr if FCoE lso is enabled */
  398. *hdr_len = sizeof(struct fcoe_crc_eof);
  399. if (skb_is_gso(skb))
  400. *hdr_len += (skb_transport_offset(skb) +
  401. sizeof(struct fc_frame_header));
  402. /* vlan_macip_lens: HEADLEN, MACLEN, VLAN tag */
  403. vlan_macip_lens = (skb_transport_offset(skb) +
  404. sizeof(struct fc_frame_header));
  405. vlan_macip_lens |= ((skb_transport_offset(skb) - 4)
  406. << IXGBE_ADVTXD_MACLEN_SHIFT);
  407. vlan_macip_lens |= (tx_flags & IXGBE_TX_FLAGS_VLAN_MASK);
  408. /* type_tycmd and mss: set TUCMD.FCoE to enable offload */
  409. type_tucmd = IXGBE_TXD_CMD_DEXT | IXGBE_ADVTXD_DTYP_CTXT |
  410. IXGBE_ADVTXT_TUCMD_FCOE;
  411. if (skb_is_gso(skb))
  412. mss = skb_shinfo(skb)->gso_size;
  413. /* mss_l4len_id: use 1 for FSO as TSO, no need for L4LEN */
  414. mss_l4len_idx = (mss << IXGBE_ADVTXD_MSS_SHIFT) |
  415. (1 << IXGBE_ADVTXD_IDX_SHIFT);
  416. /* write context desc */
  417. i = tx_ring->next_to_use;
  418. context_desc = IXGBE_TX_CTXTDESC_ADV(*tx_ring, i);
  419. context_desc->vlan_macip_lens = cpu_to_le32(vlan_macip_lens);
  420. context_desc->seqnum_seed = cpu_to_le32(fcoe_sof_eof);
  421. context_desc->type_tucmd_mlhl = cpu_to_le32(type_tucmd);
  422. context_desc->mss_l4len_idx = cpu_to_le32(mss_l4len_idx);
  423. tx_buffer_info = &tx_ring->tx_buffer_info[i];
  424. tx_buffer_info->time_stamp = jiffies;
  425. tx_buffer_info->next_to_watch = i;
  426. i++;
  427. if (i == tx_ring->count)
  428. i = 0;
  429. tx_ring->next_to_use = i;
  430. return skb_is_gso(skb);
  431. }
  432. /**
  433. * ixgbe_configure_fcoe - configures registers for fcoe at start
  434. * @adapter: ptr to ixgbe adapter
  435. *
  436. * This sets up FCoE related registers
  437. *
  438. * Returns : none
  439. */
  440. void ixgbe_configure_fcoe(struct ixgbe_adapter *adapter)
  441. {
  442. int i, fcoe_q, fcoe_i;
  443. struct ixgbe_hw *hw = &adapter->hw;
  444. struct ixgbe_fcoe *fcoe = &adapter->fcoe;
  445. struct ixgbe_ring_feature *f = &adapter->ring_feature[RING_F_FCOE];
  446. /* create the pool for ddp if not created yet */
  447. if (!fcoe->pool) {
  448. /* allocate ddp pool */
  449. fcoe->pool = pci_pool_create("ixgbe_fcoe_ddp",
  450. adapter->pdev, IXGBE_FCPTR_MAX,
  451. IXGBE_FCPTR_ALIGN, PAGE_SIZE);
  452. if (!fcoe->pool)
  453. DPRINTK(DRV, ERR,
  454. "failed to allocated FCoE DDP pool\n");
  455. spin_lock_init(&fcoe->lock);
  456. }
  457. /* Enable L2 eth type filter for FCoE */
  458. IXGBE_WRITE_REG(hw, IXGBE_ETQF(IXGBE_ETQF_FILTER_FCOE),
  459. (ETH_P_FCOE | IXGBE_ETQF_FCOE | IXGBE_ETQF_FILTER_EN));
  460. if (adapter->ring_feature[RING_F_FCOE].indices) {
  461. /* Use multiple rx queues for FCoE by redirection table */
  462. for (i = 0; i < IXGBE_FCRETA_SIZE; i++) {
  463. fcoe_i = f->mask + i % f->indices;
  464. fcoe_i &= IXGBE_FCRETA_ENTRY_MASK;
  465. fcoe_q = adapter->rx_ring[fcoe_i].reg_idx;
  466. IXGBE_WRITE_REG(hw, IXGBE_FCRETA(i), fcoe_q);
  467. }
  468. IXGBE_WRITE_REG(hw, IXGBE_FCRECTL, IXGBE_FCRECTL_ENA);
  469. IXGBE_WRITE_REG(hw, IXGBE_ETQS(IXGBE_ETQF_FILTER_FCOE), 0);
  470. } else {
  471. /* Use single rx queue for FCoE */
  472. fcoe_i = f->mask;
  473. fcoe_q = adapter->rx_ring[fcoe_i].reg_idx;
  474. IXGBE_WRITE_REG(hw, IXGBE_FCRECTL, 0);
  475. IXGBE_WRITE_REG(hw, IXGBE_ETQS(IXGBE_ETQF_FILTER_FCOE),
  476. IXGBE_ETQS_QUEUE_EN |
  477. (fcoe_q << IXGBE_ETQS_RX_QUEUE_SHIFT));
  478. }
  479. IXGBE_WRITE_REG(hw, IXGBE_FCRXCTRL,
  480. IXGBE_FCRXCTRL_FCOELLI |
  481. IXGBE_FCRXCTRL_FCCRCBO |
  482. (FC_FCOE_VER << IXGBE_FCRXCTRL_FCOEVER_SHIFT));
  483. }
  484. /**
  485. * ixgbe_cleanup_fcoe - release all fcoe ddp context resources
  486. * @adapter : ixgbe adapter
  487. *
  488. * Cleans up outstanding ddp context resources
  489. *
  490. * Returns : none
  491. */
  492. void ixgbe_cleanup_fcoe(struct ixgbe_adapter *adapter)
  493. {
  494. int i;
  495. struct ixgbe_fcoe *fcoe = &adapter->fcoe;
  496. /* release ddp resource */
  497. if (fcoe->pool) {
  498. for (i = 0; i < IXGBE_FCOE_DDP_MAX; i++)
  499. ixgbe_fcoe_ddp_put(adapter->netdev, i);
  500. pci_pool_destroy(fcoe->pool);
  501. fcoe->pool = NULL;
  502. }
  503. }
  504. /**
  505. * ixgbe_fcoe_enable - turn on FCoE offload feature
  506. * @netdev: the corresponding netdev
  507. *
  508. * Turns on FCoE offload feature in 82599.
  509. *
  510. * Returns : 0 indicates success or -EINVAL on failure
  511. */
  512. int ixgbe_fcoe_enable(struct net_device *netdev)
  513. {
  514. int rc = -EINVAL;
  515. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  516. if (!(adapter->flags & IXGBE_FLAG_FCOE_CAPABLE))
  517. goto out_enable;
  518. if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED)
  519. goto out_enable;
  520. DPRINTK(DRV, INFO, "Enabling FCoE offload features.\n");
  521. if (netif_running(netdev))
  522. netdev->netdev_ops->ndo_stop(netdev);
  523. ixgbe_clear_interrupt_scheme(adapter);
  524. adapter->flags |= IXGBE_FLAG_FCOE_ENABLED;
  525. adapter->ring_feature[RING_F_FCOE].indices = IXGBE_FCRETA_SIZE;
  526. netdev->features |= NETIF_F_FCOE_CRC;
  527. netdev->features |= NETIF_F_FSO;
  528. netdev->features |= NETIF_F_FCOE_MTU;
  529. netdev->vlan_features |= NETIF_F_FCOE_CRC;
  530. netdev->vlan_features |= NETIF_F_FSO;
  531. netdev->vlan_features |= NETIF_F_FCOE_MTU;
  532. netdev->fcoe_ddp_xid = IXGBE_FCOE_DDP_MAX - 1;
  533. netdev_features_change(netdev);
  534. ixgbe_init_interrupt_scheme(adapter);
  535. if (netif_running(netdev))
  536. netdev->netdev_ops->ndo_open(netdev);
  537. rc = 0;
  538. out_enable:
  539. return rc;
  540. }
  541. /**
  542. * ixgbe_fcoe_disable - turn off FCoE offload feature
  543. * @netdev: the corresponding netdev
  544. *
  545. * Turns off FCoE offload feature in 82599.
  546. *
  547. * Returns : 0 indicates success or -EINVAL on failure
  548. */
  549. int ixgbe_fcoe_disable(struct net_device *netdev)
  550. {
  551. int rc = -EINVAL;
  552. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  553. if (!(adapter->flags & IXGBE_FLAG_FCOE_CAPABLE))
  554. goto out_disable;
  555. if (!(adapter->flags & IXGBE_FLAG_FCOE_ENABLED))
  556. goto out_disable;
  557. DPRINTK(DRV, INFO, "Disabling FCoE offload features.\n");
  558. if (netif_running(netdev))
  559. netdev->netdev_ops->ndo_stop(netdev);
  560. ixgbe_clear_interrupt_scheme(adapter);
  561. adapter->flags &= ~IXGBE_FLAG_FCOE_ENABLED;
  562. adapter->ring_feature[RING_F_FCOE].indices = 0;
  563. netdev->features &= ~NETIF_F_FCOE_CRC;
  564. netdev->features &= ~NETIF_F_FSO;
  565. netdev->features &= ~NETIF_F_FCOE_MTU;
  566. netdev->vlan_features &= ~NETIF_F_FCOE_CRC;
  567. netdev->vlan_features &= ~NETIF_F_FSO;
  568. netdev->vlan_features &= ~NETIF_F_FCOE_MTU;
  569. netdev->fcoe_ddp_xid = 0;
  570. netdev_features_change(netdev);
  571. ixgbe_cleanup_fcoe(adapter);
  572. ixgbe_init_interrupt_scheme(adapter);
  573. if (netif_running(netdev))
  574. netdev->netdev_ops->ndo_open(netdev);
  575. rc = 0;
  576. out_disable:
  577. return rc;
  578. }
  579. #ifdef CONFIG_IXGBE_DCB
  580. /**
  581. * ixgbe_fcoe_getapp - retrieves current user priority bitmap for FCoE
  582. * @adapter : ixgbe adapter
  583. *
  584. * Finds out the corresponding user priority bitmap from the current
  585. * traffic class that FCoE belongs to. Returns 0 as the invalid user
  586. * priority bitmap to indicate an error.
  587. *
  588. * Returns : 802.1p user priority bitmap for FCoE
  589. */
  590. u8 ixgbe_fcoe_getapp(struct ixgbe_adapter *adapter)
  591. {
  592. int i;
  593. u8 tc;
  594. u32 up2tc;
  595. up2tc = IXGBE_READ_REG(&adapter->hw, IXGBE_RTTUP2TC);
  596. for (i = 0; i < MAX_USER_PRIORITY; i++) {
  597. tc = (u8)(up2tc >> (i * IXGBE_RTTUP2TC_UP_SHIFT));
  598. tc &= (MAX_TRAFFIC_CLASS - 1);
  599. if (adapter->fcoe.tc == tc)
  600. return 1 << i;
  601. }
  602. return 0;
  603. }
  604. /**
  605. * ixgbe_fcoe_setapp - sets the user priority bitmap for FCoE
  606. * @adapter : ixgbe adapter
  607. * @up : 802.1p user priority bitmap
  608. *
  609. * Finds out the traffic class from the input user priority
  610. * bitmap for FCoE.
  611. *
  612. * Returns : 0 on success otherwise returns 1 on error
  613. */
  614. u8 ixgbe_fcoe_setapp(struct ixgbe_adapter *adapter, u8 up)
  615. {
  616. int i;
  617. u32 up2tc;
  618. /* valid user priority bitmap must not be 0 */
  619. if (up) {
  620. /* from user priority to the corresponding traffic class */
  621. up2tc = IXGBE_READ_REG(&adapter->hw, IXGBE_RTTUP2TC);
  622. for (i = 0; i < MAX_USER_PRIORITY; i++) {
  623. if (up & (1 << i)) {
  624. up2tc >>= (i * IXGBE_RTTUP2TC_UP_SHIFT);
  625. up2tc &= (MAX_TRAFFIC_CLASS - 1);
  626. adapter->fcoe.tc = (u8)up2tc;
  627. return 0;
  628. }
  629. }
  630. }
  631. return 1;
  632. }
  633. #endif /* CONFIG_IXGBE_DCB */