ixgbe_fcoe.c 21 KB

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