ixgbe_fcoe.c 23 KB

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