ixgbe_fcoe.c 27 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006
  1. /*******************************************************************************
  2. Intel 10 Gigabit PCI Express Linux driver
  3. Copyright(c) 1999 - 2013 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. #include <linux/if_ether.h>
  22. #include <linux/gfp.h>
  23. #include <linux/if_vlan.h>
  24. #include <scsi/scsi_cmnd.h>
  25. #include <scsi/scsi_device.h>
  26. #include <scsi/fc/fc_fs.h>
  27. #include <scsi/fc/fc_fcoe.h>
  28. #include <scsi/libfc.h>
  29. #include <scsi/libfcoe.h>
  30. /**
  31. * ixgbe_fcoe_clear_ddp - clear the given ddp context
  32. * @ddp: ptr to the ixgbe_fcoe_ddp
  33. *
  34. * Returns : none
  35. *
  36. */
  37. static inline void ixgbe_fcoe_clear_ddp(struct ixgbe_fcoe_ddp *ddp)
  38. {
  39. ddp->len = 0;
  40. ddp->err = 1;
  41. ddp->udl = NULL;
  42. ddp->udp = 0UL;
  43. ddp->sgl = NULL;
  44. ddp->sgc = 0;
  45. }
  46. /**
  47. * ixgbe_fcoe_ddp_put - free the ddp context for a given xid
  48. * @netdev: the corresponding net_device
  49. * @xid: the xid that corresponding ddp will be freed
  50. *
  51. * This is the implementation of net_device_ops.ndo_fcoe_ddp_done
  52. * and it is expected to be called by ULD, i.e., FCP layer of libfc
  53. * to release the corresponding ddp context when the I/O is done.
  54. *
  55. * Returns : data length already ddp-ed in bytes
  56. */
  57. int ixgbe_fcoe_ddp_put(struct net_device *netdev, u16 xid)
  58. {
  59. int len = 0;
  60. struct ixgbe_fcoe *fcoe;
  61. struct ixgbe_adapter *adapter;
  62. struct ixgbe_fcoe_ddp *ddp;
  63. u32 fcbuff;
  64. if (!netdev)
  65. goto out_ddp_put;
  66. if (xid >= IXGBE_FCOE_DDP_MAX)
  67. goto out_ddp_put;
  68. adapter = netdev_priv(netdev);
  69. fcoe = &adapter->fcoe;
  70. ddp = &fcoe->ddp[xid];
  71. if (!ddp->udl)
  72. goto out_ddp_put;
  73. len = ddp->len;
  74. /* if there an error, force to invalidate ddp context */
  75. if (ddp->err) {
  76. spin_lock_bh(&fcoe->lock);
  77. IXGBE_WRITE_REG(&adapter->hw, IXGBE_FCFLT, 0);
  78. IXGBE_WRITE_REG(&adapter->hw, IXGBE_FCFLTRW,
  79. (xid | IXGBE_FCFLTRW_WE));
  80. IXGBE_WRITE_REG(&adapter->hw, IXGBE_FCBUFF, 0);
  81. IXGBE_WRITE_REG(&adapter->hw, IXGBE_FCDMARW,
  82. (xid | IXGBE_FCDMARW_WE));
  83. /* guaranteed to be invalidated after 100us */
  84. IXGBE_WRITE_REG(&adapter->hw, IXGBE_FCDMARW,
  85. (xid | IXGBE_FCDMARW_RE));
  86. fcbuff = IXGBE_READ_REG(&adapter->hw, IXGBE_FCBUFF);
  87. spin_unlock_bh(&fcoe->lock);
  88. if (fcbuff & IXGBE_FCBUFF_VALID)
  89. udelay(100);
  90. }
  91. if (ddp->sgl)
  92. dma_unmap_sg(&adapter->pdev->dev, ddp->sgl, ddp->sgc,
  93. DMA_FROM_DEVICE);
  94. if (ddp->pool) {
  95. dma_pool_free(ddp->pool, ddp->udl, ddp->udp);
  96. ddp->pool = NULL;
  97. }
  98. ixgbe_fcoe_clear_ddp(ddp);
  99. out_ddp_put:
  100. return len;
  101. }
  102. /**
  103. * ixgbe_fcoe_ddp_setup - called to set up ddp context
  104. * @netdev: the corresponding net_device
  105. * @xid: the exchange id requesting ddp
  106. * @sgl: the scatter-gather list for this request
  107. * @sgc: the number of scatter-gather items
  108. *
  109. * Returns : 1 for success and 0 for no ddp
  110. */
  111. static int ixgbe_fcoe_ddp_setup(struct net_device *netdev, u16 xid,
  112. struct scatterlist *sgl, unsigned int sgc,
  113. int target_mode)
  114. {
  115. struct ixgbe_adapter *adapter;
  116. struct ixgbe_hw *hw;
  117. struct ixgbe_fcoe *fcoe;
  118. struct ixgbe_fcoe_ddp *ddp;
  119. struct ixgbe_fcoe_ddp_pool *ddp_pool;
  120. struct scatterlist *sg;
  121. unsigned int i, j, dmacount;
  122. unsigned int len;
  123. static const unsigned int bufflen = IXGBE_FCBUFF_MIN;
  124. unsigned int firstoff = 0;
  125. unsigned int lastsize;
  126. unsigned int thisoff = 0;
  127. unsigned int thislen = 0;
  128. u32 fcbuff, fcdmarw, fcfltrw, fcrxctl;
  129. dma_addr_t addr = 0;
  130. if (!netdev || !sgl)
  131. return 0;
  132. adapter = netdev_priv(netdev);
  133. if (xid >= IXGBE_FCOE_DDP_MAX) {
  134. e_warn(drv, "xid=0x%x out-of-range\n", xid);
  135. return 0;
  136. }
  137. /* no DDP if we are already down or resetting */
  138. if (test_bit(__IXGBE_DOWN, &adapter->state) ||
  139. test_bit(__IXGBE_RESETTING, &adapter->state))
  140. return 0;
  141. fcoe = &adapter->fcoe;
  142. ddp = &fcoe->ddp[xid];
  143. if (ddp->sgl) {
  144. e_err(drv, "xid 0x%x w/ non-null sgl=%p nents=%d\n",
  145. xid, ddp->sgl, ddp->sgc);
  146. return 0;
  147. }
  148. ixgbe_fcoe_clear_ddp(ddp);
  149. if (!fcoe->ddp_pool) {
  150. e_warn(drv, "No ddp_pool resources allocated\n");
  151. return 0;
  152. }
  153. ddp_pool = per_cpu_ptr(fcoe->ddp_pool, get_cpu());
  154. if (!ddp_pool->pool) {
  155. e_warn(drv, "xid=0x%x no ddp pool for fcoe\n", xid);
  156. goto out_noddp;
  157. }
  158. /* setup dma from scsi command sgl */
  159. dmacount = dma_map_sg(&adapter->pdev->dev, sgl, sgc, DMA_FROM_DEVICE);
  160. if (dmacount == 0) {
  161. e_err(drv, "xid 0x%x DMA map error\n", xid);
  162. goto out_noddp;
  163. }
  164. /* alloc the udl from per cpu ddp pool */
  165. ddp->udl = dma_pool_alloc(ddp_pool->pool, GFP_ATOMIC, &ddp->udp);
  166. if (!ddp->udl) {
  167. e_err(drv, "failed allocated ddp context\n");
  168. goto out_noddp_unmap;
  169. }
  170. ddp->pool = ddp_pool->pool;
  171. ddp->sgl = sgl;
  172. ddp->sgc = sgc;
  173. j = 0;
  174. for_each_sg(sgl, sg, dmacount, i) {
  175. addr = sg_dma_address(sg);
  176. len = sg_dma_len(sg);
  177. while (len) {
  178. /* max number of buffers allowed in one DDP context */
  179. if (j >= IXGBE_BUFFCNT_MAX) {
  180. ddp_pool->noddp++;
  181. goto out_noddp_free;
  182. }
  183. /* get the offset of length of current buffer */
  184. thisoff = addr & ((dma_addr_t)bufflen - 1);
  185. thislen = min((bufflen - thisoff), len);
  186. /*
  187. * all but the 1st buffer (j == 0)
  188. * must be aligned on bufflen
  189. */
  190. if ((j != 0) && (thisoff))
  191. goto out_noddp_free;
  192. /*
  193. * all but the last buffer
  194. * ((i == (dmacount - 1)) && (thislen == len))
  195. * must end at bufflen
  196. */
  197. if (((i != (dmacount - 1)) || (thislen != len))
  198. && ((thislen + thisoff) != bufflen))
  199. goto out_noddp_free;
  200. ddp->udl[j] = (u64)(addr - thisoff);
  201. /* only the first buffer may have none-zero offset */
  202. if (j == 0)
  203. firstoff = thisoff;
  204. len -= thislen;
  205. addr += thislen;
  206. j++;
  207. }
  208. }
  209. /* only the last buffer may have non-full bufflen */
  210. lastsize = thisoff + thislen;
  211. /*
  212. * lastsize can not be buffer len.
  213. * If it is then adding another buffer with lastsize = 1.
  214. */
  215. if (lastsize == bufflen) {
  216. if (j >= IXGBE_BUFFCNT_MAX) {
  217. ddp_pool->noddp_ext_buff++;
  218. goto out_noddp_free;
  219. }
  220. ddp->udl[j] = (u64)(fcoe->extra_ddp_buffer_dma);
  221. j++;
  222. lastsize = 1;
  223. }
  224. put_cpu();
  225. fcbuff = (IXGBE_FCBUFF_4KB << IXGBE_FCBUFF_BUFFSIZE_SHIFT);
  226. fcbuff |= ((j & 0xff) << IXGBE_FCBUFF_BUFFCNT_SHIFT);
  227. fcbuff |= (firstoff << IXGBE_FCBUFF_OFFSET_SHIFT);
  228. /* Set WRCONTX bit to allow DDP for target */
  229. if (target_mode)
  230. fcbuff |= (IXGBE_FCBUFF_WRCONTX);
  231. fcbuff |= (IXGBE_FCBUFF_VALID);
  232. fcdmarw = xid;
  233. fcdmarw |= IXGBE_FCDMARW_WE;
  234. fcdmarw |= (lastsize << IXGBE_FCDMARW_LASTSIZE_SHIFT);
  235. fcfltrw = xid;
  236. fcfltrw |= IXGBE_FCFLTRW_WE;
  237. /* program DMA context */
  238. hw = &adapter->hw;
  239. spin_lock_bh(&fcoe->lock);
  240. /* turn on last frame indication for target mode as FCP_RSPtarget is
  241. * supposed to send FCP_RSP when it is done. */
  242. if (target_mode && !test_bit(__IXGBE_FCOE_TARGET, &fcoe->mode)) {
  243. set_bit(__IXGBE_FCOE_TARGET, &fcoe->mode);
  244. fcrxctl = IXGBE_READ_REG(hw, IXGBE_FCRXCTRL);
  245. fcrxctl |= IXGBE_FCRXCTRL_LASTSEQH;
  246. IXGBE_WRITE_REG(hw, IXGBE_FCRXCTRL, fcrxctl);
  247. }
  248. IXGBE_WRITE_REG(hw, IXGBE_FCPTRL, ddp->udp & DMA_BIT_MASK(32));
  249. IXGBE_WRITE_REG(hw, IXGBE_FCPTRH, (u64)ddp->udp >> 32);
  250. IXGBE_WRITE_REG(hw, IXGBE_FCBUFF, fcbuff);
  251. IXGBE_WRITE_REG(hw, IXGBE_FCDMARW, fcdmarw);
  252. /* program filter context */
  253. IXGBE_WRITE_REG(hw, IXGBE_FCPARAM, 0);
  254. IXGBE_WRITE_REG(hw, IXGBE_FCFLT, IXGBE_FCFLT_VALID);
  255. IXGBE_WRITE_REG(hw, IXGBE_FCFLTRW, fcfltrw);
  256. spin_unlock_bh(&fcoe->lock);
  257. return 1;
  258. out_noddp_free:
  259. dma_pool_free(ddp->pool, ddp->udl, ddp->udp);
  260. ixgbe_fcoe_clear_ddp(ddp);
  261. out_noddp_unmap:
  262. dma_unmap_sg(&adapter->pdev->dev, sgl, sgc, DMA_FROM_DEVICE);
  263. out_noddp:
  264. put_cpu();
  265. return 0;
  266. }
  267. /**
  268. * ixgbe_fcoe_ddp_get - called to set up ddp context in initiator mode
  269. * @netdev: the corresponding net_device
  270. * @xid: the exchange id requesting ddp
  271. * @sgl: the scatter-gather list for this request
  272. * @sgc: the number of scatter-gather items
  273. *
  274. * This is the implementation of net_device_ops.ndo_fcoe_ddp_setup
  275. * and is expected to be called from ULD, e.g., FCP layer of libfc
  276. * to set up ddp for the corresponding xid of the given sglist for
  277. * the corresponding I/O.
  278. *
  279. * Returns : 1 for success and 0 for no ddp
  280. */
  281. int ixgbe_fcoe_ddp_get(struct net_device *netdev, u16 xid,
  282. struct scatterlist *sgl, unsigned int sgc)
  283. {
  284. return ixgbe_fcoe_ddp_setup(netdev, xid, sgl, sgc, 0);
  285. }
  286. /**
  287. * ixgbe_fcoe_ddp_target - called to set up ddp context in target mode
  288. * @netdev: the corresponding net_device
  289. * @xid: the exchange id requesting ddp
  290. * @sgl: the scatter-gather list for this request
  291. * @sgc: the number of scatter-gather items
  292. *
  293. * This is the implementation of net_device_ops.ndo_fcoe_ddp_target
  294. * and is expected to be called from ULD, e.g., FCP layer of libfc
  295. * to set up ddp for the corresponding xid of the given sglist for
  296. * the corresponding I/O. The DDP in target mode is a write I/O request
  297. * from the initiator.
  298. *
  299. * Returns : 1 for success and 0 for no ddp
  300. */
  301. int ixgbe_fcoe_ddp_target(struct net_device *netdev, u16 xid,
  302. struct scatterlist *sgl, unsigned int sgc)
  303. {
  304. return ixgbe_fcoe_ddp_setup(netdev, xid, sgl, sgc, 1);
  305. }
  306. /**
  307. * ixgbe_fcoe_ddp - check ddp status and mark it done
  308. * @adapter: ixgbe adapter
  309. * @rx_desc: advanced rx descriptor
  310. * @skb: the skb holding the received data
  311. *
  312. * This checks ddp status.
  313. *
  314. * Returns : < 0 indicates an error or not a FCiE ddp, 0 indicates
  315. * not passing the skb to ULD, > 0 indicates is the length of data
  316. * being ddped.
  317. */
  318. int ixgbe_fcoe_ddp(struct ixgbe_adapter *adapter,
  319. union ixgbe_adv_rx_desc *rx_desc,
  320. struct sk_buff *skb)
  321. {
  322. int rc = -EINVAL;
  323. struct ixgbe_fcoe *fcoe;
  324. struct ixgbe_fcoe_ddp *ddp;
  325. struct fc_frame_header *fh;
  326. struct fcoe_crc_eof *crc;
  327. __le32 fcerr = ixgbe_test_staterr(rx_desc, IXGBE_RXDADV_ERR_FCERR);
  328. __le32 ddp_err;
  329. u32 fctl;
  330. u16 xid;
  331. if (fcerr == cpu_to_le32(IXGBE_FCERR_BADCRC))
  332. skb->ip_summed = CHECKSUM_NONE;
  333. else
  334. skb->ip_summed = CHECKSUM_UNNECESSARY;
  335. if (eth_hdr(skb)->h_proto == htons(ETH_P_8021Q))
  336. fh = (struct fc_frame_header *)(skb->data +
  337. sizeof(struct vlan_hdr) + sizeof(struct fcoe_hdr));
  338. else
  339. fh = (struct fc_frame_header *)(skb->data +
  340. sizeof(struct fcoe_hdr));
  341. fctl = ntoh24(fh->fh_f_ctl);
  342. if (fctl & FC_FC_EX_CTX)
  343. xid = be16_to_cpu(fh->fh_ox_id);
  344. else
  345. xid = be16_to_cpu(fh->fh_rx_id);
  346. if (xid >= IXGBE_FCOE_DDP_MAX)
  347. goto ddp_out;
  348. fcoe = &adapter->fcoe;
  349. ddp = &fcoe->ddp[xid];
  350. if (!ddp->udl)
  351. goto ddp_out;
  352. ddp_err = ixgbe_test_staterr(rx_desc, IXGBE_RXDADV_ERR_FCEOFE |
  353. IXGBE_RXDADV_ERR_FCERR);
  354. if (ddp_err)
  355. goto ddp_out;
  356. switch (ixgbe_test_staterr(rx_desc, IXGBE_RXDADV_STAT_FCSTAT)) {
  357. /* return 0 to bypass going to ULD for DDPed data */
  358. case __constant_cpu_to_le32(IXGBE_RXDADV_STAT_FCSTAT_DDP):
  359. /* update length of DDPed data */
  360. ddp->len = le32_to_cpu(rx_desc->wb.lower.hi_dword.rss);
  361. rc = 0;
  362. break;
  363. /* unmap the sg list when FCPRSP is received */
  364. case __constant_cpu_to_le32(IXGBE_RXDADV_STAT_FCSTAT_FCPRSP):
  365. dma_unmap_sg(&adapter->pdev->dev, ddp->sgl,
  366. ddp->sgc, DMA_FROM_DEVICE);
  367. ddp->err = ddp_err;
  368. ddp->sgl = NULL;
  369. ddp->sgc = 0;
  370. /* fall through */
  371. /* if DDP length is present pass it through to ULD */
  372. case __constant_cpu_to_le32(IXGBE_RXDADV_STAT_FCSTAT_NODDP):
  373. /* update length of DDPed data */
  374. ddp->len = le32_to_cpu(rx_desc->wb.lower.hi_dword.rss);
  375. if (ddp->len)
  376. rc = ddp->len;
  377. break;
  378. /* no match will return as an error */
  379. case __constant_cpu_to_le32(IXGBE_RXDADV_STAT_FCSTAT_NOMTCH):
  380. default:
  381. break;
  382. }
  383. /* In target mode, check the last data frame of the sequence.
  384. * For DDP in target mode, data is already DDPed but the header
  385. * indication of the last data frame ould allow is to tell if we
  386. * got all the data and the ULP can send FCP_RSP back, as this is
  387. * not a full fcoe frame, we fill the trailer here so it won't be
  388. * dropped by the ULP stack.
  389. */
  390. if ((fh->fh_r_ctl == FC_RCTL_DD_SOL_DATA) &&
  391. (fctl & FC_FC_END_SEQ)) {
  392. skb_linearize(skb);
  393. crc = (struct fcoe_crc_eof *)skb_put(skb, sizeof(*crc));
  394. crc->fcoe_eof = FC_EOF_T;
  395. }
  396. ddp_out:
  397. return rc;
  398. }
  399. /**
  400. * ixgbe_fso - ixgbe FCoE Sequence Offload (FSO)
  401. * @tx_ring: tx desc ring
  402. * @first: first tx_buffer structure containing skb, tx_flags, and protocol
  403. * @hdr_len: hdr_len to be returned
  404. *
  405. * This sets up large send offload for FCoE
  406. *
  407. * Returns : 0 indicates success, < 0 for error
  408. */
  409. int ixgbe_fso(struct ixgbe_ring *tx_ring,
  410. struct ixgbe_tx_buffer *first,
  411. u8 *hdr_len)
  412. {
  413. struct sk_buff *skb = first->skb;
  414. struct fc_frame_header *fh;
  415. u32 vlan_macip_lens;
  416. u32 fcoe_sof_eof = 0;
  417. u32 mss_l4len_idx;
  418. u8 sof, eof;
  419. if (skb_is_gso(skb) && (skb_shinfo(skb)->gso_type != SKB_GSO_FCOE)) {
  420. dev_err(tx_ring->dev, "Wrong gso type %d:expecting SKB_GSO_FCOE\n",
  421. skb_shinfo(skb)->gso_type);
  422. return -EINVAL;
  423. }
  424. /* resets the header to point fcoe/fc */
  425. skb_set_network_header(skb, skb->mac_len);
  426. skb_set_transport_header(skb, skb->mac_len +
  427. sizeof(struct fcoe_hdr));
  428. /* sets up SOF and ORIS */
  429. sof = ((struct fcoe_hdr *)skb_network_header(skb))->fcoe_sof;
  430. switch (sof) {
  431. case FC_SOF_I2:
  432. fcoe_sof_eof = IXGBE_ADVTXD_FCOEF_ORIS;
  433. break;
  434. case FC_SOF_I3:
  435. fcoe_sof_eof = IXGBE_ADVTXD_FCOEF_SOF |
  436. IXGBE_ADVTXD_FCOEF_ORIS;
  437. break;
  438. case FC_SOF_N2:
  439. break;
  440. case FC_SOF_N3:
  441. fcoe_sof_eof = IXGBE_ADVTXD_FCOEF_SOF;
  442. break;
  443. default:
  444. dev_warn(tx_ring->dev, "unknown sof = 0x%x\n", sof);
  445. return -EINVAL;
  446. }
  447. /* the first byte of the last dword is EOF */
  448. skb_copy_bits(skb, skb->len - 4, &eof, 1);
  449. /* sets up EOF and ORIE */
  450. switch (eof) {
  451. case FC_EOF_N:
  452. fcoe_sof_eof |= IXGBE_ADVTXD_FCOEF_EOF_N;
  453. break;
  454. case FC_EOF_T:
  455. /* lso needs ORIE */
  456. if (skb_is_gso(skb))
  457. fcoe_sof_eof |= IXGBE_ADVTXD_FCOEF_EOF_N |
  458. IXGBE_ADVTXD_FCOEF_ORIE;
  459. else
  460. fcoe_sof_eof |= IXGBE_ADVTXD_FCOEF_EOF_T;
  461. break;
  462. case FC_EOF_NI:
  463. fcoe_sof_eof |= IXGBE_ADVTXD_FCOEF_EOF_NI;
  464. break;
  465. case FC_EOF_A:
  466. fcoe_sof_eof |= IXGBE_ADVTXD_FCOEF_EOF_A;
  467. break;
  468. default:
  469. dev_warn(tx_ring->dev, "unknown eof = 0x%x\n", eof);
  470. return -EINVAL;
  471. }
  472. /* sets up PARINC indicating data offset */
  473. fh = (struct fc_frame_header *)skb_transport_header(skb);
  474. if (fh->fh_f_ctl[2] & FC_FC_REL_OFF)
  475. fcoe_sof_eof |= IXGBE_ADVTXD_FCOEF_PARINC;
  476. /* include trailer in headlen as it is replicated per frame */
  477. *hdr_len = sizeof(struct fcoe_crc_eof);
  478. /* hdr_len includes fc_hdr if FCoE LSO is enabled */
  479. if (skb_is_gso(skb)) {
  480. *hdr_len += skb_transport_offset(skb) +
  481. sizeof(struct fc_frame_header);
  482. /* update gso_segs and bytecount */
  483. first->gso_segs = DIV_ROUND_UP(skb->len - *hdr_len,
  484. skb_shinfo(skb)->gso_size);
  485. first->bytecount += (first->gso_segs - 1) * *hdr_len;
  486. first->tx_flags |= IXGBE_TX_FLAGS_TSO;
  487. }
  488. /* set flag indicating FCOE to ixgbe_tx_map call */
  489. first->tx_flags |= IXGBE_TX_FLAGS_FCOE | IXGBE_TX_FLAGS_CC;
  490. /* mss_l4len_id: use 0 for FSO as TSO, no need for L4LEN */
  491. mss_l4len_idx = skb_shinfo(skb)->gso_size << IXGBE_ADVTXD_MSS_SHIFT;
  492. /* vlan_macip_lens: HEADLEN, MACLEN, VLAN tag */
  493. vlan_macip_lens = skb_transport_offset(skb) +
  494. sizeof(struct fc_frame_header);
  495. vlan_macip_lens |= (skb_transport_offset(skb) - 4)
  496. << IXGBE_ADVTXD_MACLEN_SHIFT;
  497. vlan_macip_lens |= first->tx_flags & IXGBE_TX_FLAGS_VLAN_MASK;
  498. /* write context desc */
  499. ixgbe_tx_ctxtdesc(tx_ring, vlan_macip_lens, fcoe_sof_eof,
  500. IXGBE_ADVTXT_TUCMD_FCOE, mss_l4len_idx);
  501. return 0;
  502. }
  503. static void ixgbe_fcoe_dma_pool_free(struct ixgbe_fcoe *fcoe, unsigned int cpu)
  504. {
  505. struct ixgbe_fcoe_ddp_pool *ddp_pool;
  506. ddp_pool = per_cpu_ptr(fcoe->ddp_pool, cpu);
  507. if (ddp_pool->pool)
  508. dma_pool_destroy(ddp_pool->pool);
  509. ddp_pool->pool = NULL;
  510. }
  511. static int ixgbe_fcoe_dma_pool_alloc(struct ixgbe_fcoe *fcoe,
  512. struct device *dev,
  513. unsigned int cpu)
  514. {
  515. struct ixgbe_fcoe_ddp_pool *ddp_pool;
  516. struct dma_pool *pool;
  517. char pool_name[32];
  518. snprintf(pool_name, 32, "ixgbe_fcoe_ddp_%d", cpu);
  519. pool = dma_pool_create(pool_name, dev, IXGBE_FCPTR_MAX,
  520. IXGBE_FCPTR_ALIGN, PAGE_SIZE);
  521. if (!pool)
  522. return -ENOMEM;
  523. ddp_pool = per_cpu_ptr(fcoe->ddp_pool, cpu);
  524. ddp_pool->pool = pool;
  525. ddp_pool->noddp = 0;
  526. ddp_pool->noddp_ext_buff = 0;
  527. return 0;
  528. }
  529. /**
  530. * ixgbe_configure_fcoe - configures registers for fcoe at start
  531. * @adapter: ptr to ixgbe adapter
  532. *
  533. * This sets up FCoE related registers
  534. *
  535. * Returns : none
  536. */
  537. void ixgbe_configure_fcoe(struct ixgbe_adapter *adapter)
  538. {
  539. struct ixgbe_ring_feature *fcoe = &adapter->ring_feature[RING_F_FCOE];
  540. struct ixgbe_hw *hw = &adapter->hw;
  541. int i, fcoe_q, fcoe_i;
  542. u32 etqf;
  543. /* Minimal functionality for FCoE requires at least CRC offloads */
  544. if (!(adapter->netdev->features & NETIF_F_FCOE_CRC))
  545. return;
  546. /* Enable L2 EtherType filter for FCoE, needed for FCoE CRC and DDP */
  547. etqf = ETH_P_FCOE | IXGBE_ETQF_FCOE | IXGBE_ETQF_FILTER_EN;
  548. if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) {
  549. etqf |= IXGBE_ETQF_POOL_ENABLE;
  550. etqf |= VMDQ_P(0) << IXGBE_ETQF_POOL_SHIFT;
  551. }
  552. IXGBE_WRITE_REG(hw, IXGBE_ETQF(IXGBE_ETQF_FILTER_FCOE), etqf);
  553. IXGBE_WRITE_REG(hw, IXGBE_ETQS(IXGBE_ETQF_FILTER_FCOE), 0);
  554. /* leave registers un-configured if FCoE is disabled */
  555. if (!(adapter->flags & IXGBE_FLAG_FCOE_ENABLED))
  556. return;
  557. /* Use one or more Rx queues for FCoE by redirection table */
  558. for (i = 0; i < IXGBE_FCRETA_SIZE; i++) {
  559. fcoe_i = fcoe->offset + (i % fcoe->indices);
  560. fcoe_i &= IXGBE_FCRETA_ENTRY_MASK;
  561. fcoe_q = adapter->rx_ring[fcoe_i]->reg_idx;
  562. IXGBE_WRITE_REG(hw, IXGBE_FCRETA(i), fcoe_q);
  563. }
  564. IXGBE_WRITE_REG(hw, IXGBE_FCRECTL, IXGBE_FCRECTL_ENA);
  565. /* Enable L2 EtherType filter for FIP */
  566. etqf = ETH_P_FIP | IXGBE_ETQF_FILTER_EN;
  567. if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) {
  568. etqf |= IXGBE_ETQF_POOL_ENABLE;
  569. etqf |= VMDQ_P(0) << IXGBE_ETQF_POOL_SHIFT;
  570. }
  571. IXGBE_WRITE_REG(hw, IXGBE_ETQF(IXGBE_ETQF_FILTER_FIP), etqf);
  572. /* Send FIP frames to the first FCoE queue */
  573. fcoe_q = adapter->rx_ring[fcoe->offset]->reg_idx;
  574. IXGBE_WRITE_REG(hw, IXGBE_ETQS(IXGBE_ETQF_FILTER_FIP),
  575. IXGBE_ETQS_QUEUE_EN |
  576. (fcoe_q << IXGBE_ETQS_RX_QUEUE_SHIFT));
  577. /* Configure FCoE Rx control */
  578. IXGBE_WRITE_REG(hw, IXGBE_FCRXCTRL,
  579. IXGBE_FCRXCTRL_FCCRCBO |
  580. (FC_FCOE_VER << IXGBE_FCRXCTRL_FCOEVER_SHIFT));
  581. }
  582. /**
  583. * ixgbe_free_fcoe_ddp_resources - release all fcoe ddp context resources
  584. * @adapter : ixgbe adapter
  585. *
  586. * Cleans up outstanding ddp context resources
  587. *
  588. * Returns : none
  589. */
  590. void ixgbe_free_fcoe_ddp_resources(struct ixgbe_adapter *adapter)
  591. {
  592. struct ixgbe_fcoe *fcoe = &adapter->fcoe;
  593. int cpu, i;
  594. /* do nothing if no DDP pools were allocated */
  595. if (!fcoe->ddp_pool)
  596. return;
  597. for (i = 0; i < IXGBE_FCOE_DDP_MAX; i++)
  598. ixgbe_fcoe_ddp_put(adapter->netdev, i);
  599. for_each_possible_cpu(cpu)
  600. ixgbe_fcoe_dma_pool_free(fcoe, cpu);
  601. dma_unmap_single(&adapter->pdev->dev,
  602. fcoe->extra_ddp_buffer_dma,
  603. IXGBE_FCBUFF_MIN,
  604. DMA_FROM_DEVICE);
  605. kfree(fcoe->extra_ddp_buffer);
  606. fcoe->extra_ddp_buffer = NULL;
  607. fcoe->extra_ddp_buffer_dma = 0;
  608. }
  609. /**
  610. * ixgbe_setup_fcoe_ddp_resources - setup all fcoe ddp context resources
  611. * @adapter: ixgbe adapter
  612. *
  613. * Sets up ddp context resouces
  614. *
  615. * Returns : 0 indicates success or -EINVAL on failure
  616. */
  617. int ixgbe_setup_fcoe_ddp_resources(struct ixgbe_adapter *adapter)
  618. {
  619. struct ixgbe_fcoe *fcoe = &adapter->fcoe;
  620. struct device *dev = &adapter->pdev->dev;
  621. void *buffer;
  622. dma_addr_t dma;
  623. unsigned int cpu;
  624. /* do nothing if no DDP pools were allocated */
  625. if (!fcoe->ddp_pool)
  626. return 0;
  627. /* Extra buffer to be shared by all DDPs for HW work around */
  628. buffer = kmalloc(IXGBE_FCBUFF_MIN, GFP_ATOMIC);
  629. if (!buffer)
  630. return -ENOMEM;
  631. dma = dma_map_single(dev, buffer, IXGBE_FCBUFF_MIN, DMA_FROM_DEVICE);
  632. if (dma_mapping_error(dev, dma)) {
  633. e_err(drv, "failed to map extra DDP buffer\n");
  634. kfree(buffer);
  635. return -ENOMEM;
  636. }
  637. fcoe->extra_ddp_buffer = buffer;
  638. fcoe->extra_ddp_buffer_dma = dma;
  639. /* allocate pci pool for each cpu */
  640. for_each_possible_cpu(cpu) {
  641. int err = ixgbe_fcoe_dma_pool_alloc(fcoe, dev, cpu);
  642. if (!err)
  643. continue;
  644. e_err(drv, "failed to alloc DDP pool on cpu:%d\n", cpu);
  645. ixgbe_free_fcoe_ddp_resources(adapter);
  646. return -ENOMEM;
  647. }
  648. return 0;
  649. }
  650. static int ixgbe_fcoe_ddp_enable(struct ixgbe_adapter *adapter)
  651. {
  652. struct ixgbe_fcoe *fcoe = &adapter->fcoe;
  653. if (!(adapter->flags & IXGBE_FLAG_FCOE_CAPABLE))
  654. return -EINVAL;
  655. fcoe->ddp_pool = alloc_percpu(struct ixgbe_fcoe_ddp_pool);
  656. if (!fcoe->ddp_pool) {
  657. e_err(drv, "failed to allocate percpu DDP resources\n");
  658. return -ENOMEM;
  659. }
  660. adapter->netdev->fcoe_ddp_xid = IXGBE_FCOE_DDP_MAX - 1;
  661. return 0;
  662. }
  663. static void ixgbe_fcoe_ddp_disable(struct ixgbe_adapter *adapter)
  664. {
  665. struct ixgbe_fcoe *fcoe = &adapter->fcoe;
  666. adapter->netdev->fcoe_ddp_xid = 0;
  667. if (!fcoe->ddp_pool)
  668. return;
  669. free_percpu(fcoe->ddp_pool);
  670. fcoe->ddp_pool = NULL;
  671. }
  672. /**
  673. * ixgbe_fcoe_enable - turn on FCoE offload feature
  674. * @netdev: the corresponding netdev
  675. *
  676. * Turns on FCoE offload feature in 82599.
  677. *
  678. * Returns : 0 indicates success or -EINVAL on failure
  679. */
  680. int ixgbe_fcoe_enable(struct net_device *netdev)
  681. {
  682. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  683. struct ixgbe_fcoe *fcoe = &adapter->fcoe;
  684. atomic_inc(&fcoe->refcnt);
  685. if (!(adapter->flags & IXGBE_FLAG_FCOE_CAPABLE))
  686. return -EINVAL;
  687. if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED)
  688. return -EINVAL;
  689. e_info(drv, "Enabling FCoE offload features.\n");
  690. if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
  691. e_warn(probe, "Enabling FCoE on PF will disable legacy VFs\n");
  692. if (netif_running(netdev))
  693. netdev->netdev_ops->ndo_stop(netdev);
  694. /* Allocate per CPU memory to track DDP pools */
  695. ixgbe_fcoe_ddp_enable(adapter);
  696. /* enable FCoE and notify stack */
  697. adapter->flags |= IXGBE_FLAG_FCOE_ENABLED;
  698. netdev->features |= NETIF_F_FCOE_MTU;
  699. netdev_features_change(netdev);
  700. /* release existing queues and reallocate them */
  701. ixgbe_clear_interrupt_scheme(adapter);
  702. ixgbe_init_interrupt_scheme(adapter);
  703. if (netif_running(netdev))
  704. netdev->netdev_ops->ndo_open(netdev);
  705. return 0;
  706. }
  707. /**
  708. * ixgbe_fcoe_disable - turn off FCoE offload feature
  709. * @netdev: the corresponding netdev
  710. *
  711. * Turns off FCoE offload feature in 82599.
  712. *
  713. * Returns : 0 indicates success or -EINVAL on failure
  714. */
  715. int ixgbe_fcoe_disable(struct net_device *netdev)
  716. {
  717. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  718. if (!atomic_dec_and_test(&adapter->fcoe.refcnt))
  719. return -EINVAL;
  720. if (!(adapter->flags & IXGBE_FLAG_FCOE_ENABLED))
  721. return -EINVAL;
  722. e_info(drv, "Disabling FCoE offload features.\n");
  723. if (netif_running(netdev))
  724. netdev->netdev_ops->ndo_stop(netdev);
  725. /* Free per CPU memory to track DDP pools */
  726. ixgbe_fcoe_ddp_disable(adapter);
  727. /* disable FCoE and notify stack */
  728. adapter->flags &= ~IXGBE_FLAG_FCOE_ENABLED;
  729. netdev->features &= ~NETIF_F_FCOE_MTU;
  730. netdev_features_change(netdev);
  731. /* release existing queues and reallocate them */
  732. ixgbe_clear_interrupt_scheme(adapter);
  733. ixgbe_init_interrupt_scheme(adapter);
  734. if (netif_running(netdev))
  735. netdev->netdev_ops->ndo_open(netdev);
  736. return 0;
  737. }
  738. /**
  739. * ixgbe_fcoe_get_wwn - get world wide name for the node or the port
  740. * @netdev : ixgbe adapter
  741. * @wwn : the world wide name
  742. * @type: the type of world wide name
  743. *
  744. * Returns the node or port world wide name if both the prefix and the san
  745. * mac address are valid, then the wwn is formed based on the NAA-2 for
  746. * IEEE Extended name identifier (ref. to T10 FC-LS Spec., Sec. 15.3).
  747. *
  748. * Returns : 0 on success
  749. */
  750. int ixgbe_fcoe_get_wwn(struct net_device *netdev, u64 *wwn, int type)
  751. {
  752. int rc = -EINVAL;
  753. u16 prefix = 0xffff;
  754. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  755. struct ixgbe_mac_info *mac = &adapter->hw.mac;
  756. switch (type) {
  757. case NETDEV_FCOE_WWNN:
  758. prefix = mac->wwnn_prefix;
  759. break;
  760. case NETDEV_FCOE_WWPN:
  761. prefix = mac->wwpn_prefix;
  762. break;
  763. default:
  764. break;
  765. }
  766. if ((prefix != 0xffff) &&
  767. is_valid_ether_addr(mac->san_addr)) {
  768. *wwn = ((u64) prefix << 48) |
  769. ((u64) mac->san_addr[0] << 40) |
  770. ((u64) mac->san_addr[1] << 32) |
  771. ((u64) mac->san_addr[2] << 24) |
  772. ((u64) mac->san_addr[3] << 16) |
  773. ((u64) mac->san_addr[4] << 8) |
  774. ((u64) mac->san_addr[5]);
  775. rc = 0;
  776. }
  777. return rc;
  778. }
  779. /**
  780. * ixgbe_fcoe_get_hbainfo - get FCoE HBA information
  781. * @netdev : ixgbe adapter
  782. * @info : HBA information
  783. *
  784. * Returns ixgbe HBA information
  785. *
  786. * Returns : 0 on success
  787. */
  788. int ixgbe_fcoe_get_hbainfo(struct net_device *netdev,
  789. struct netdev_fcoe_hbainfo *info)
  790. {
  791. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  792. struct ixgbe_hw *hw = &adapter->hw;
  793. int i, pos;
  794. u8 buf[8];
  795. if (!info)
  796. return -EINVAL;
  797. /* Don't return information on unsupported devices */
  798. if (hw->mac.type != ixgbe_mac_82599EB &&
  799. hw->mac.type != ixgbe_mac_X540)
  800. return -EINVAL;
  801. /* Manufacturer */
  802. snprintf(info->manufacturer, sizeof(info->manufacturer),
  803. "Intel Corporation");
  804. /* Serial Number */
  805. /* Get the PCI-e Device Serial Number Capability */
  806. pos = pci_find_ext_capability(adapter->pdev, PCI_EXT_CAP_ID_DSN);
  807. if (pos) {
  808. pos += 4;
  809. for (i = 0; i < 8; i++)
  810. pci_read_config_byte(adapter->pdev, pos + i, &buf[i]);
  811. snprintf(info->serial_number, sizeof(info->serial_number),
  812. "%02X%02X%02X%02X%02X%02X%02X%02X",
  813. buf[7], buf[6], buf[5], buf[4],
  814. buf[3], buf[2], buf[1], buf[0]);
  815. } else
  816. snprintf(info->serial_number, sizeof(info->serial_number),
  817. "Unknown");
  818. /* Hardware Version */
  819. snprintf(info->hardware_version,
  820. sizeof(info->hardware_version),
  821. "Rev %d", hw->revision_id);
  822. /* Driver Name/Version */
  823. snprintf(info->driver_version,
  824. sizeof(info->driver_version),
  825. "%s v%s",
  826. ixgbe_driver_name,
  827. ixgbe_driver_version);
  828. /* Firmware Version */
  829. snprintf(info->firmware_version,
  830. sizeof(info->firmware_version),
  831. "0x%08x",
  832. (adapter->eeprom_verh << 16) |
  833. adapter->eeprom_verl);
  834. /* Model */
  835. if (hw->mac.type == ixgbe_mac_82599EB) {
  836. snprintf(info->model,
  837. sizeof(info->model),
  838. "Intel 82599");
  839. } else {
  840. snprintf(info->model,
  841. sizeof(info->model),
  842. "Intel X540");
  843. }
  844. /* Model Description */
  845. snprintf(info->model_description,
  846. sizeof(info->model_description),
  847. "%s",
  848. ixgbe_default_device_descr);
  849. return 0;
  850. }
  851. /**
  852. * ixgbe_fcoe_get_tc - get the current TC that fcoe is mapped to
  853. * @adapter - pointer to the device adapter structure
  854. *
  855. * Return : TC that FCoE is mapped to
  856. */
  857. u8 ixgbe_fcoe_get_tc(struct ixgbe_adapter *adapter)
  858. {
  859. #ifdef CONFIG_IXGBE_DCB
  860. return netdev_get_prio_tc_map(adapter->netdev, adapter->fcoe.up);
  861. #else
  862. return 0;
  863. #endif
  864. }