ixgbe_fcoe.c 21 KB

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