i40e_fcoe.c 44 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567
  1. /*******************************************************************************
  2. *
  3. * Intel Ethernet Controller XL710 Family Linux Driver
  4. * Copyright(c) 2013 - 2015 Intel Corporation.
  5. *
  6. * This program is free software; you can redistribute it and/or modify it
  7. * under the terms and conditions of the GNU General Public License,
  8. * version 2, as published by the Free Software Foundation.
  9. *
  10. * This program is distributed in the hope it will be useful, but WITHOUT
  11. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  12. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  13. * more details.
  14. *
  15. * You should have received a copy of the GNU General Public License along
  16. * with this program. If not, see <http://www.gnu.org/licenses/>.
  17. *
  18. * The full GNU General Public License is included in this distribution in
  19. * the file called "COPYING".
  20. *
  21. * Contact Information:
  22. * e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
  23. * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
  24. *
  25. ******************************************************************************/
  26. #include <linux/if_ether.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_fip.h>
  31. #include <scsi/fc/fc_fcoe.h>
  32. #include <scsi/libfc.h>
  33. #include <scsi/libfcoe.h>
  34. #include <uapi/linux/dcbnl.h>
  35. #include "i40e.h"
  36. #include "i40e_fcoe.h"
  37. /**
  38. * i40e_rx_is_fcoe - returns true if the rx packet type is FCoE
  39. * @ptype: the packet type field from rx descriptor write-back
  40. **/
  41. static inline bool i40e_rx_is_fcoe(u16 ptype)
  42. {
  43. return (ptype >= I40E_RX_PTYPE_L2_FCOE_PAY3) &&
  44. (ptype <= I40E_RX_PTYPE_L2_FCOE_VFT_FCOTHER);
  45. }
  46. /**
  47. * i40e_fcoe_sof_is_class2 - returns true if this is a FC Class 2 SOF
  48. * @sof: the FCoE start of frame delimiter
  49. **/
  50. static inline bool i40e_fcoe_sof_is_class2(u8 sof)
  51. {
  52. return (sof == FC_SOF_I2) || (sof == FC_SOF_N2);
  53. }
  54. /**
  55. * i40e_fcoe_sof_is_class3 - returns true if this is a FC Class 3 SOF
  56. * @sof: the FCoE start of frame delimiter
  57. **/
  58. static inline bool i40e_fcoe_sof_is_class3(u8 sof)
  59. {
  60. return (sof == FC_SOF_I3) || (sof == FC_SOF_N3);
  61. }
  62. /**
  63. * i40e_fcoe_sof_is_supported - returns true if the FC SOF is supported by HW
  64. * @sof: the input SOF value from the frame
  65. **/
  66. static inline bool i40e_fcoe_sof_is_supported(u8 sof)
  67. {
  68. return i40e_fcoe_sof_is_class2(sof) ||
  69. i40e_fcoe_sof_is_class3(sof);
  70. }
  71. /**
  72. * i40e_fcoe_fc_sof - pull the SOF from FCoE header in the frame
  73. * @skb: the frame whose EOF is to be pulled from
  74. **/
  75. static inline int i40e_fcoe_fc_sof(struct sk_buff *skb, u8 *sof)
  76. {
  77. *sof = ((struct fcoe_hdr *)skb_network_header(skb))->fcoe_sof;
  78. if (!i40e_fcoe_sof_is_supported(*sof))
  79. return -EINVAL;
  80. return 0;
  81. }
  82. /**
  83. * i40e_fcoe_eof_is_supported - returns true if the EOF is supported by HW
  84. * @eof: the input EOF value from the frame
  85. **/
  86. static inline bool i40e_fcoe_eof_is_supported(u8 eof)
  87. {
  88. return (eof == FC_EOF_N) || (eof == FC_EOF_T) ||
  89. (eof == FC_EOF_NI) || (eof == FC_EOF_A);
  90. }
  91. /**
  92. * i40e_fcoe_fc_eof - pull EOF from FCoE trailer in the frame
  93. * @skb: the frame whose EOF is to be pulled from
  94. **/
  95. static inline int i40e_fcoe_fc_eof(struct sk_buff *skb, u8 *eof)
  96. {
  97. /* the first byte of the last dword is EOF */
  98. skb_copy_bits(skb, skb->len - 4, eof, 1);
  99. if (!i40e_fcoe_eof_is_supported(*eof))
  100. return -EINVAL;
  101. return 0;
  102. }
  103. /**
  104. * i40e_fcoe_ctxt_eof - convert input FC EOF for descriptor programming
  105. * @eof: the input eof value from the frame
  106. *
  107. * The FC EOF is converted to the value understood by HW for descriptor
  108. * programming. Never call this w/o calling i40e_fcoe_eof_is_supported()
  109. * first and that already checks for all supported valid eof values.
  110. **/
  111. static inline u32 i40e_fcoe_ctxt_eof(u8 eof)
  112. {
  113. switch (eof) {
  114. case FC_EOF_N:
  115. return I40E_TX_DESC_CMD_L4T_EOFT_EOF_N;
  116. case FC_EOF_T:
  117. return I40E_TX_DESC_CMD_L4T_EOFT_EOF_T;
  118. case FC_EOF_NI:
  119. return I40E_TX_DESC_CMD_L4T_EOFT_EOF_NI;
  120. case FC_EOF_A:
  121. return I40E_TX_DESC_CMD_L4T_EOFT_EOF_A;
  122. default:
  123. /* Supported valid eof shall be already checked by
  124. * calling i40e_fcoe_eof_is_supported() first,
  125. * therefore this default case shall never hit.
  126. */
  127. WARN_ON(1);
  128. return -EINVAL;
  129. }
  130. }
  131. /**
  132. * i40e_fcoe_xid_is_valid - returns true if the exchange id is valid
  133. * @xid: the exchange id
  134. **/
  135. static inline bool i40e_fcoe_xid_is_valid(u16 xid)
  136. {
  137. return (xid != FC_XID_UNKNOWN) && (xid < I40E_FCOE_DDP_MAX);
  138. }
  139. /**
  140. * i40e_fcoe_ddp_unmap - unmap the mapped sglist associated
  141. * @pf: pointer to PF
  142. * @ddp: sw DDP context
  143. *
  144. * Unmap the scatter-gather list associated with the given SW DDP context
  145. *
  146. * Returns: data length already ddp-ed in bytes
  147. *
  148. **/
  149. static inline void i40e_fcoe_ddp_unmap(struct i40e_pf *pf,
  150. struct i40e_fcoe_ddp *ddp)
  151. {
  152. if (test_and_set_bit(__I40E_FCOE_DDP_UNMAPPED, &ddp->flags))
  153. return;
  154. if (ddp->sgl) {
  155. dma_unmap_sg(&pf->pdev->dev, ddp->sgl, ddp->sgc,
  156. DMA_FROM_DEVICE);
  157. ddp->sgl = NULL;
  158. ddp->sgc = 0;
  159. }
  160. if (ddp->pool) {
  161. dma_pool_free(ddp->pool, ddp->udl, ddp->udp);
  162. ddp->pool = NULL;
  163. }
  164. }
  165. /**
  166. * i40e_fcoe_ddp_clear - clear the given SW DDP context
  167. * @ddp - SW DDP context
  168. **/
  169. static inline void i40e_fcoe_ddp_clear(struct i40e_fcoe_ddp *ddp)
  170. {
  171. memset(ddp, 0, sizeof(struct i40e_fcoe_ddp));
  172. ddp->xid = FC_XID_UNKNOWN;
  173. ddp->flags = __I40E_FCOE_DDP_NONE;
  174. }
  175. /**
  176. * i40e_fcoe_progid_is_fcoe - check if the prog_id is for FCoE
  177. * @id: the prog id for the programming status Rx descriptor write-back
  178. **/
  179. static inline bool i40e_fcoe_progid_is_fcoe(u8 id)
  180. {
  181. return (id == I40E_RX_PROG_STATUS_DESC_FCOE_CTXT_PROG_STATUS) ||
  182. (id == I40E_RX_PROG_STATUS_DESC_FCOE_CTXT_INVL_STATUS);
  183. }
  184. /**
  185. * i40e_fcoe_fc_get_xid - get xid from the frame header
  186. * @fh: the fc frame header
  187. *
  188. * In case the incoming frame's exchange is originated from
  189. * the initiator, then received frame's exchange id is ANDed
  190. * with fc_cpu_mask bits to get the same cpu on which exchange
  191. * was originated, otherwise just use the current cpu.
  192. *
  193. * Returns ox_id if exchange originator, rx_id if responder
  194. **/
  195. static inline u16 i40e_fcoe_fc_get_xid(struct fc_frame_header *fh)
  196. {
  197. u32 f_ctl = ntoh24(fh->fh_f_ctl);
  198. return (f_ctl & FC_FC_EX_CTX) ?
  199. be16_to_cpu(fh->fh_ox_id) :
  200. be16_to_cpu(fh->fh_rx_id);
  201. }
  202. /**
  203. * i40e_fcoe_fc_frame_header - get fc frame header from skb
  204. * @skb: packet
  205. *
  206. * This checks if there is a VLAN header and returns the data
  207. * pointer to the start of the fc_frame_header.
  208. *
  209. * Returns pointer to the fc_frame_header
  210. **/
  211. static inline struct fc_frame_header *i40e_fcoe_fc_frame_header(
  212. struct sk_buff *skb)
  213. {
  214. void *fh = skb->data + sizeof(struct fcoe_hdr);
  215. if (eth_hdr(skb)->h_proto == htons(ETH_P_8021Q))
  216. fh += sizeof(struct vlan_hdr);
  217. return (struct fc_frame_header *)fh;
  218. }
  219. /**
  220. * i40e_fcoe_ddp_put - release the DDP context for a given exchange id
  221. * @netdev: the corresponding net_device
  222. * @xid: the exchange id that corresponding DDP context will be released
  223. *
  224. * This is the implementation of net_device_ops.ndo_fcoe_ddp_done
  225. * and it is expected to be called by ULD, i.e., FCP layer of libfc
  226. * to release the corresponding ddp context when the I/O is done.
  227. *
  228. * Returns : data length already ddp-ed in bytes
  229. **/
  230. static int i40e_fcoe_ddp_put(struct net_device *netdev, u16 xid)
  231. {
  232. struct i40e_netdev_priv *np = netdev_priv(netdev);
  233. struct i40e_pf *pf = np->vsi->back;
  234. struct i40e_fcoe *fcoe = &pf->fcoe;
  235. int len = 0;
  236. struct i40e_fcoe_ddp *ddp = &fcoe->ddp[xid];
  237. if (!fcoe || !ddp)
  238. goto out;
  239. if (test_bit(__I40E_FCOE_DDP_DONE, &ddp->flags))
  240. len = ddp->len;
  241. i40e_fcoe_ddp_unmap(pf, ddp);
  242. out:
  243. return len;
  244. }
  245. /**
  246. * i40e_fcoe_sw_init - sets up the HW for FCoE
  247. * @pf: pointer to PF
  248. **/
  249. void i40e_init_pf_fcoe(struct i40e_pf *pf)
  250. {
  251. struct i40e_hw *hw = &pf->hw;
  252. u32 val;
  253. pf->flags &= ~I40E_FLAG_FCOE_ENABLED;
  254. pf->num_fcoe_qps = 0;
  255. pf->fcoe_hmc_cntx_num = 0;
  256. pf->fcoe_hmc_filt_num = 0;
  257. if (!pf->hw.func_caps.fcoe) {
  258. dev_dbg(&pf->pdev->dev, "FCoE capability is disabled\n");
  259. return;
  260. }
  261. if (!pf->hw.func_caps.dcb) {
  262. dev_warn(&pf->pdev->dev,
  263. "Hardware is not DCB capable not enabling FCoE.\n");
  264. return;
  265. }
  266. /* enable FCoE hash filter */
  267. val = rd32(hw, I40E_PFQF_HENA(1));
  268. val |= BIT(I40E_FILTER_PCTYPE_FCOE_OX - 32);
  269. val |= BIT(I40E_FILTER_PCTYPE_FCOE_RX - 32);
  270. val &= I40E_PFQF_HENA_PTYPE_ENA_MASK;
  271. wr32(hw, I40E_PFQF_HENA(1), val);
  272. /* enable flag */
  273. pf->flags |= I40E_FLAG_FCOE_ENABLED;
  274. pf->num_fcoe_qps = I40E_DEFAULT_FCOE;
  275. /* Reserve 4K DDP contexts and 20K filter size for FCoE */
  276. pf->fcoe_hmc_cntx_num = BIT(I40E_DMA_CNTX_SIZE_4K) *
  277. I40E_DMA_CNTX_BASE_SIZE;
  278. pf->fcoe_hmc_filt_num = pf->fcoe_hmc_cntx_num +
  279. BIT(I40E_HASH_FILTER_SIZE_16K) *
  280. I40E_HASH_FILTER_BASE_SIZE;
  281. /* FCoE object: max 16K filter buckets and 4K DMA contexts */
  282. pf->filter_settings.fcoe_filt_num = I40E_HASH_FILTER_SIZE_16K;
  283. pf->filter_settings.fcoe_cntx_num = I40E_DMA_CNTX_SIZE_4K;
  284. /* Setup max frame with FCoE_MTU plus L2 overheads */
  285. val = rd32(hw, I40E_GLFCOE_RCTL);
  286. val &= ~I40E_GLFCOE_RCTL_MAX_SIZE_MASK;
  287. val |= ((FCOE_MTU + ETH_HLEN + VLAN_HLEN + ETH_FCS_LEN)
  288. << I40E_GLFCOE_RCTL_MAX_SIZE_SHIFT);
  289. wr32(hw, I40E_GLFCOE_RCTL, val);
  290. dev_info(&pf->pdev->dev, "FCoE is supported.\n");
  291. }
  292. /**
  293. * i40e_get_fcoe_tc_map - Return TC map for FCoE APP
  294. * @pf: pointer to PF
  295. *
  296. **/
  297. u8 i40e_get_fcoe_tc_map(struct i40e_pf *pf)
  298. {
  299. struct i40e_dcb_app_priority_table app;
  300. struct i40e_hw *hw = &pf->hw;
  301. u8 enabled_tc = 0;
  302. u8 tc, i;
  303. /* Get the FCoE APP TLV */
  304. struct i40e_dcbx_config *dcbcfg = &hw->local_dcbx_config;
  305. for (i = 0; i < dcbcfg->numapps; i++) {
  306. app = dcbcfg->app[i];
  307. if (app.selector == IEEE_8021QAZ_APP_SEL_ETHERTYPE &&
  308. app.protocolid == ETH_P_FCOE) {
  309. tc = dcbcfg->etscfg.prioritytable[app.priority];
  310. enabled_tc |= BIT(tc);
  311. break;
  312. }
  313. }
  314. /* TC0 if there is no TC defined for FCoE APP TLV */
  315. enabled_tc = enabled_tc ? enabled_tc : 0x1;
  316. return enabled_tc;
  317. }
  318. /**
  319. * i40e_fcoe_vsi_init - prepares the VSI context for creating a FCoE VSI
  320. * @vsi: pointer to the associated VSI struct
  321. * @ctxt: pointer to the associated VSI context to be passed to HW
  322. *
  323. * Returns 0 on success or < 0 on error
  324. **/
  325. int i40e_fcoe_vsi_init(struct i40e_vsi *vsi, struct i40e_vsi_context *ctxt)
  326. {
  327. struct i40e_aqc_vsi_properties_data *info = &ctxt->info;
  328. struct i40e_pf *pf = vsi->back;
  329. struct i40e_hw *hw = &pf->hw;
  330. u8 enabled_tc = 0;
  331. if (!(pf->flags & I40E_FLAG_FCOE_ENABLED)) {
  332. dev_err(&pf->pdev->dev,
  333. "FCoE is not enabled for this device\n");
  334. return -EPERM;
  335. }
  336. /* initialize the hardware for FCoE */
  337. ctxt->pf_num = hw->pf_id;
  338. ctxt->vf_num = 0;
  339. ctxt->uplink_seid = vsi->uplink_seid;
  340. ctxt->connection_type = I40E_AQ_VSI_CONN_TYPE_NORMAL;
  341. ctxt->flags = I40E_AQ_VSI_TYPE_PF;
  342. /* FCoE VSI would need the following sections */
  343. info->valid_sections |= cpu_to_le16(I40E_AQ_VSI_PROP_QUEUE_OPT_VALID);
  344. /* FCoE VSI does not need these sections */
  345. info->valid_sections &= cpu_to_le16(~(I40E_AQ_VSI_PROP_SECURITY_VALID |
  346. I40E_AQ_VSI_PROP_VLAN_VALID |
  347. I40E_AQ_VSI_PROP_CAS_PV_VALID |
  348. I40E_AQ_VSI_PROP_INGRESS_UP_VALID |
  349. I40E_AQ_VSI_PROP_EGRESS_UP_VALID));
  350. if (i40e_is_vsi_uplink_mode_veb(vsi)) {
  351. info->valid_sections |=
  352. cpu_to_le16(I40E_AQ_VSI_PROP_SWITCH_VALID);
  353. info->switch_id =
  354. cpu_to_le16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB);
  355. }
  356. enabled_tc = i40e_get_fcoe_tc_map(pf);
  357. i40e_vsi_setup_queue_map(vsi, ctxt, enabled_tc, true);
  358. /* set up queue option section: only enable FCoE */
  359. info->queueing_opt_flags = I40E_AQ_VSI_QUE_OPT_FCOE_ENA;
  360. return 0;
  361. }
  362. /**
  363. * i40e_fcoe_enable - this is the implementation of ndo_fcoe_enable,
  364. * indicating the upper FCoE protocol stack is ready to use FCoE
  365. * offload features.
  366. *
  367. * @netdev: pointer to the netdev that FCoE is created on
  368. *
  369. * Returns 0 on success
  370. *
  371. * in RTNL
  372. *
  373. **/
  374. int i40e_fcoe_enable(struct net_device *netdev)
  375. {
  376. struct i40e_netdev_priv *np = netdev_priv(netdev);
  377. struct i40e_vsi *vsi = np->vsi;
  378. struct i40e_pf *pf = vsi->back;
  379. struct i40e_fcoe *fcoe = &pf->fcoe;
  380. if (!(pf->flags & I40E_FLAG_FCOE_ENABLED)) {
  381. netdev_err(netdev, "HW does not support FCoE.\n");
  382. return -ENODEV;
  383. }
  384. if (vsi->type != I40E_VSI_FCOE) {
  385. netdev_err(netdev, "interface does not support FCoE.\n");
  386. return -EBUSY;
  387. }
  388. atomic_inc(&fcoe->refcnt);
  389. return 0;
  390. }
  391. /**
  392. * i40e_fcoe_disable- disables FCoE for upper FCoE protocol stack.
  393. * @dev: pointer to the netdev that FCoE is created on
  394. *
  395. * Returns 0 on success
  396. *
  397. **/
  398. int i40e_fcoe_disable(struct net_device *netdev)
  399. {
  400. struct i40e_netdev_priv *np = netdev_priv(netdev);
  401. struct i40e_vsi *vsi = np->vsi;
  402. struct i40e_pf *pf = vsi->back;
  403. struct i40e_fcoe *fcoe = &pf->fcoe;
  404. if (!(pf->flags & I40E_FLAG_FCOE_ENABLED)) {
  405. netdev_err(netdev, "device does not support FCoE\n");
  406. return -ENODEV;
  407. }
  408. if (vsi->type != I40E_VSI_FCOE)
  409. return -EBUSY;
  410. if (!atomic_dec_and_test(&fcoe->refcnt))
  411. return -EINVAL;
  412. netdev_info(netdev, "FCoE disabled\n");
  413. return 0;
  414. }
  415. /**
  416. * i40e_fcoe_dma_pool_free - free the per cpu pool for FCoE DDP
  417. * @fcoe: the FCoE sw object
  418. * @dev: the device that the pool is associated with
  419. * @cpu: the cpu for this pool
  420. *
  421. **/
  422. static void i40e_fcoe_dma_pool_free(struct i40e_fcoe *fcoe,
  423. struct device *dev,
  424. unsigned int cpu)
  425. {
  426. struct i40e_fcoe_ddp_pool *ddp_pool;
  427. ddp_pool = per_cpu_ptr(fcoe->ddp_pool, cpu);
  428. if (!ddp_pool->pool) {
  429. dev_warn(dev, "DDP pool already freed for cpu %d\n", cpu);
  430. return;
  431. }
  432. dma_pool_destroy(ddp_pool->pool);
  433. ddp_pool->pool = NULL;
  434. }
  435. /**
  436. * i40e_fcoe_dma_pool_create - per cpu pool for FCoE DDP
  437. * @fcoe: the FCoE sw object
  438. * @dev: the device that the pool is associated with
  439. * @cpu: the cpu for this pool
  440. *
  441. * Returns 0 on successful or non zero on failure
  442. *
  443. **/
  444. static int i40e_fcoe_dma_pool_create(struct i40e_fcoe *fcoe,
  445. struct device *dev,
  446. unsigned int cpu)
  447. {
  448. struct i40e_fcoe_ddp_pool *ddp_pool;
  449. struct dma_pool *pool;
  450. char pool_name[32];
  451. ddp_pool = per_cpu_ptr(fcoe->ddp_pool, cpu);
  452. if (ddp_pool && ddp_pool->pool) {
  453. dev_warn(dev, "DDP pool already allocated for cpu %d\n", cpu);
  454. return 0;
  455. }
  456. snprintf(pool_name, sizeof(pool_name), "i40e_fcoe_ddp_%d", cpu);
  457. pool = dma_pool_create(pool_name, dev, I40E_FCOE_DDP_PTR_MAX,
  458. I40E_FCOE_DDP_PTR_ALIGN, PAGE_SIZE);
  459. if (!pool) {
  460. dev_err(dev, "dma_pool_create %s failed\n", pool_name);
  461. return -ENOMEM;
  462. }
  463. ddp_pool->pool = pool;
  464. return 0;
  465. }
  466. /**
  467. * i40e_fcoe_free_ddp_resources - release FCoE DDP resources
  468. * @vsi: the vsi FCoE is associated with
  469. *
  470. **/
  471. void i40e_fcoe_free_ddp_resources(struct i40e_vsi *vsi)
  472. {
  473. struct i40e_pf *pf = vsi->back;
  474. struct i40e_fcoe *fcoe = &pf->fcoe;
  475. int cpu, i;
  476. /* do nothing if not FCoE VSI */
  477. if (vsi->type != I40E_VSI_FCOE)
  478. return;
  479. /* do nothing if no DDP pools were allocated */
  480. if (!fcoe->ddp_pool)
  481. return;
  482. for (i = 0; i < I40E_FCOE_DDP_MAX; i++)
  483. i40e_fcoe_ddp_put(vsi->netdev, i);
  484. for_each_possible_cpu(cpu)
  485. i40e_fcoe_dma_pool_free(fcoe, &pf->pdev->dev, cpu);
  486. free_percpu(fcoe->ddp_pool);
  487. fcoe->ddp_pool = NULL;
  488. netdev_info(vsi->netdev, "VSI %d,%d FCoE DDP resources released\n",
  489. vsi->id, vsi->seid);
  490. }
  491. /**
  492. * i40e_fcoe_setup_ddp_resources - allocate per cpu DDP resources
  493. * @vsi: the VSI FCoE is associated with
  494. *
  495. * Returns 0 on successful or non zero on failure
  496. *
  497. **/
  498. int i40e_fcoe_setup_ddp_resources(struct i40e_vsi *vsi)
  499. {
  500. struct i40e_pf *pf = vsi->back;
  501. struct device *dev = &pf->pdev->dev;
  502. struct i40e_fcoe *fcoe = &pf->fcoe;
  503. unsigned int cpu;
  504. int i;
  505. if (vsi->type != I40E_VSI_FCOE)
  506. return -ENODEV;
  507. /* do nothing if no DDP pools were allocated */
  508. if (fcoe->ddp_pool)
  509. return -EEXIST;
  510. /* allocate per CPU memory to track DDP pools */
  511. fcoe->ddp_pool = alloc_percpu(struct i40e_fcoe_ddp_pool);
  512. if (!fcoe->ddp_pool) {
  513. dev_err(&pf->pdev->dev, "failed to allocate percpu DDP\n");
  514. return -ENOMEM;
  515. }
  516. /* allocate pci pool for each cpu */
  517. for_each_possible_cpu(cpu) {
  518. if (!i40e_fcoe_dma_pool_create(fcoe, dev, cpu))
  519. continue;
  520. dev_err(dev, "failed to alloc DDP pool on cpu:%d\n", cpu);
  521. i40e_fcoe_free_ddp_resources(vsi);
  522. return -ENOMEM;
  523. }
  524. /* initialize the sw context */
  525. for (i = 0; i < I40E_FCOE_DDP_MAX; i++)
  526. i40e_fcoe_ddp_clear(&fcoe->ddp[i]);
  527. netdev_info(vsi->netdev, "VSI %d,%d FCoE DDP resources allocated\n",
  528. vsi->id, vsi->seid);
  529. return 0;
  530. }
  531. /**
  532. * i40e_fcoe_handle_status - check the Programming Status for FCoE
  533. * @rx_ring: the Rx ring for this descriptor
  534. * @rx_desc: the Rx descriptor for Programming Status, not a packet descriptor.
  535. *
  536. * Check if this is the Rx Programming Status descriptor write-back for FCoE.
  537. * This is used to verify if the context/filter programming or invalidation
  538. * requested by SW to the HW is successful or not and take actions accordingly.
  539. **/
  540. void i40e_fcoe_handle_status(struct i40e_ring *rx_ring,
  541. union i40e_rx_desc *rx_desc, u8 prog_id)
  542. {
  543. struct i40e_pf *pf = rx_ring->vsi->back;
  544. struct i40e_fcoe *fcoe = &pf->fcoe;
  545. struct i40e_fcoe_ddp *ddp;
  546. u32 error;
  547. u16 xid;
  548. u64 qw;
  549. /* we only care for FCoE here */
  550. if (!i40e_fcoe_progid_is_fcoe(prog_id))
  551. return;
  552. xid = le32_to_cpu(rx_desc->wb.qword0.hi_dword.fcoe_param) &
  553. (I40E_FCOE_DDP_MAX - 1);
  554. if (!i40e_fcoe_xid_is_valid(xid))
  555. return;
  556. ddp = &fcoe->ddp[xid];
  557. WARN_ON(xid != ddp->xid);
  558. qw = le64_to_cpu(rx_desc->wb.qword1.status_error_len);
  559. error = (qw & I40E_RX_PROG_STATUS_DESC_QW1_ERROR_MASK) >>
  560. I40E_RX_PROG_STATUS_DESC_QW1_ERROR_SHIFT;
  561. /* DDP context programming status: failure or success */
  562. if (prog_id == I40E_RX_PROG_STATUS_DESC_FCOE_CTXT_PROG_STATUS) {
  563. if (I40E_RX_PROG_FCOE_ERROR_TBL_FULL(error)) {
  564. dev_err(&pf->pdev->dev, "xid %x ddp->xid %x TABLE FULL\n",
  565. xid, ddp->xid);
  566. ddp->prerr |= I40E_RX_PROG_FCOE_ERROR_TBL_FULL_BIT;
  567. }
  568. if (I40E_RX_PROG_FCOE_ERROR_CONFLICT(error)) {
  569. dev_err(&pf->pdev->dev, "xid %x ddp->xid %x CONFLICT\n",
  570. xid, ddp->xid);
  571. ddp->prerr |= I40E_RX_PROG_FCOE_ERROR_CONFLICT_BIT;
  572. }
  573. }
  574. /* DDP context invalidation status: failure or success */
  575. if (prog_id == I40E_RX_PROG_STATUS_DESC_FCOE_CTXT_INVL_STATUS) {
  576. if (I40E_RX_PROG_FCOE_ERROR_INVLFAIL(error)) {
  577. dev_err(&pf->pdev->dev, "xid %x ddp->xid %x INVALIDATION FAILURE\n",
  578. xid, ddp->xid);
  579. ddp->prerr |= I40E_RX_PROG_FCOE_ERROR_INVLFAIL_BIT;
  580. }
  581. /* clear the flag so we can retry invalidation */
  582. clear_bit(__I40E_FCOE_DDP_ABORTED, &ddp->flags);
  583. }
  584. /* unmap DMA */
  585. i40e_fcoe_ddp_unmap(pf, ddp);
  586. i40e_fcoe_ddp_clear(ddp);
  587. }
  588. /**
  589. * i40e_fcoe_handle_offload - check ddp status and mark it done
  590. * @adapter: i40e adapter
  591. * @rx_desc: advanced rx descriptor
  592. * @skb: the skb holding the received data
  593. *
  594. * This checks ddp status.
  595. *
  596. * Returns : < 0 indicates an error or not a FCOE ddp, 0 indicates
  597. * not passing the skb to ULD, > 0 indicates is the length of data
  598. * being ddped.
  599. *
  600. **/
  601. int i40e_fcoe_handle_offload(struct i40e_ring *rx_ring,
  602. union i40e_rx_desc *rx_desc,
  603. struct sk_buff *skb)
  604. {
  605. struct i40e_pf *pf = rx_ring->vsi->back;
  606. struct i40e_fcoe *fcoe = &pf->fcoe;
  607. struct fc_frame_header *fh = NULL;
  608. struct i40e_fcoe_ddp *ddp = NULL;
  609. u32 status, fltstat;
  610. u32 error, fcerr;
  611. int rc = -EINVAL;
  612. u16 ptype;
  613. u16 xid;
  614. u64 qw;
  615. /* check this rxd is for programming status */
  616. qw = le64_to_cpu(rx_desc->wb.qword1.status_error_len);
  617. /* packet descriptor, check packet type */
  618. ptype = (qw & I40E_RXD_QW1_PTYPE_MASK) >> I40E_RXD_QW1_PTYPE_SHIFT;
  619. if (!i40e_rx_is_fcoe(ptype))
  620. goto out_no_ddp;
  621. error = (qw & I40E_RXD_QW1_ERROR_MASK) >> I40E_RXD_QW1_ERROR_SHIFT;
  622. fcerr = (error >> I40E_RX_DESC_ERROR_L3L4E_SHIFT) &
  623. I40E_RX_DESC_FCOE_ERROR_MASK;
  624. /* check stateless offload error */
  625. if (unlikely(fcerr == I40E_RX_DESC_ERROR_L3L4E_PROT)) {
  626. dev_err(&pf->pdev->dev, "Protocol Error\n");
  627. skb->ip_summed = CHECKSUM_NONE;
  628. } else {
  629. skb->ip_summed = CHECKSUM_UNNECESSARY;
  630. }
  631. /* check hw status on ddp */
  632. status = (qw & I40E_RXD_QW1_STATUS_MASK) >> I40E_RXD_QW1_STATUS_SHIFT;
  633. fltstat = (status >> I40E_RX_DESC_STATUS_FLTSTAT_SHIFT) &
  634. I40E_RX_DESC_FLTSTAT_FCMASK;
  635. /* now we are ready to check DDP */
  636. fh = i40e_fcoe_fc_frame_header(skb);
  637. xid = i40e_fcoe_fc_get_xid(fh);
  638. if (!i40e_fcoe_xid_is_valid(xid))
  639. goto out_no_ddp;
  640. /* non DDP normal receive, return to the protocol stack */
  641. if (fltstat == I40E_RX_DESC_FLTSTAT_NOMTCH)
  642. goto out_no_ddp;
  643. /* do we have a sw ddp context setup ? */
  644. ddp = &fcoe->ddp[xid];
  645. if (!ddp->sgl)
  646. goto out_no_ddp;
  647. /* fetch xid from hw rxd wb, which should match up the sw ctxt */
  648. xid = le16_to_cpu(rx_desc->wb.qword0.lo_dword.mirr_fcoe.fcoe_ctx_id);
  649. if (ddp->xid != xid) {
  650. dev_err(&pf->pdev->dev, "xid 0x%x does not match ctx_xid 0x%x\n",
  651. ddp->xid, xid);
  652. goto out_put_ddp;
  653. }
  654. /* the same exchange has already errored out */
  655. if (ddp->fcerr) {
  656. dev_err(&pf->pdev->dev, "xid 0x%x fcerr 0x%x reported fcer 0x%x\n",
  657. xid, ddp->fcerr, fcerr);
  658. goto out_put_ddp;
  659. }
  660. /* fcoe param is valid by now with correct DDPed length */
  661. ddp->len = le32_to_cpu(rx_desc->wb.qword0.hi_dword.fcoe_param);
  662. ddp->fcerr = fcerr;
  663. /* header posting only, useful only for target mode and debugging */
  664. if (fltstat == I40E_RX_DESC_FLTSTAT_DDP) {
  665. /* For target mode, we get header of the last packet but it
  666. * does not have the FCoE trailer field, i.e., CRC and EOF
  667. * Ordered Set since they are offloaded by the HW, so fill
  668. * it up correspondingly to allow the packet to pass through
  669. * to the upper protocol stack.
  670. */
  671. u32 f_ctl = ntoh24(fh->fh_f_ctl);
  672. if ((f_ctl & FC_FC_END_SEQ) &&
  673. (fh->fh_r_ctl == FC_RCTL_DD_SOL_DATA)) {
  674. struct fcoe_crc_eof *crc = NULL;
  675. crc = (struct fcoe_crc_eof *)skb_put(skb, sizeof(*crc));
  676. crc->fcoe_eof = FC_EOF_T;
  677. } else {
  678. /* otherwise, drop the header only frame */
  679. rc = 0;
  680. goto out_no_ddp;
  681. }
  682. }
  683. out_put_ddp:
  684. /* either we got RSP or we have an error, unmap DMA in both cases */
  685. i40e_fcoe_ddp_unmap(pf, ddp);
  686. if (ddp->len && !ddp->fcerr) {
  687. int pkts;
  688. rc = ddp->len;
  689. i40e_fcoe_ddp_clear(ddp);
  690. ddp->len = rc;
  691. pkts = DIV_ROUND_UP(rc, 2048);
  692. rx_ring->stats.bytes += rc;
  693. rx_ring->stats.packets += pkts;
  694. rx_ring->q_vector->rx.total_bytes += rc;
  695. rx_ring->q_vector->rx.total_packets += pkts;
  696. set_bit(__I40E_FCOE_DDP_DONE, &ddp->flags);
  697. }
  698. out_no_ddp:
  699. return rc;
  700. }
  701. /**
  702. * i40e_fcoe_ddp_setup - called to set up ddp context
  703. * @netdev: the corresponding net_device
  704. * @xid: the exchange id requesting ddp
  705. * @sgl: the scatter-gather list for this request
  706. * @sgc: the number of scatter-gather items
  707. * @target_mode: indicates this is a DDP request for target
  708. *
  709. * Returns : 1 for success and 0 for no DDP on this I/O
  710. **/
  711. static int i40e_fcoe_ddp_setup(struct net_device *netdev, u16 xid,
  712. struct scatterlist *sgl, unsigned int sgc,
  713. int target_mode)
  714. {
  715. static const unsigned int bufflen = I40E_FCOE_DDP_BUF_MIN;
  716. struct i40e_netdev_priv *np = netdev_priv(netdev);
  717. struct i40e_fcoe_ddp_pool *ddp_pool;
  718. struct i40e_pf *pf = np->vsi->back;
  719. struct i40e_fcoe *fcoe = &pf->fcoe;
  720. unsigned int i, j, dmacount;
  721. struct i40e_fcoe_ddp *ddp;
  722. unsigned int firstoff = 0;
  723. unsigned int thisoff = 0;
  724. unsigned int thislen = 0;
  725. struct scatterlist *sg;
  726. dma_addr_t addr = 0;
  727. unsigned int len;
  728. if (xid >= I40E_FCOE_DDP_MAX) {
  729. dev_warn(&pf->pdev->dev, "xid=0x%x out-of-range\n", xid);
  730. return 0;
  731. }
  732. /* no DDP if we are already down or resetting */
  733. if (test_bit(__I40E_DOWN, &pf->state) ||
  734. test_bit(__I40E_NEEDS_RESTART, &pf->state)) {
  735. dev_info(&pf->pdev->dev, "xid=0x%x device in reset/down\n",
  736. xid);
  737. return 0;
  738. }
  739. ddp = &fcoe->ddp[xid];
  740. if (ddp->sgl) {
  741. dev_info(&pf->pdev->dev, "xid 0x%x w/ non-null sgl=%p nents=%d\n",
  742. xid, ddp->sgl, ddp->sgc);
  743. return 0;
  744. }
  745. i40e_fcoe_ddp_clear(ddp);
  746. if (!fcoe->ddp_pool) {
  747. dev_info(&pf->pdev->dev, "No DDP pool, xid 0x%x\n", xid);
  748. return 0;
  749. }
  750. ddp_pool = per_cpu_ptr(fcoe->ddp_pool, get_cpu());
  751. if (!ddp_pool->pool) {
  752. dev_info(&pf->pdev->dev, "No percpu ddp pool, xid 0x%x\n", xid);
  753. goto out_noddp;
  754. }
  755. /* setup dma from scsi command sgl */
  756. dmacount = dma_map_sg(&pf->pdev->dev, sgl, sgc, DMA_FROM_DEVICE);
  757. if (dmacount == 0) {
  758. dev_info(&pf->pdev->dev, "dma_map_sg for sgl %p, sgc %d failed\n",
  759. sgl, sgc);
  760. goto out_noddp_unmap;
  761. }
  762. /* alloc the udl from our ddp pool */
  763. ddp->udl = dma_pool_alloc(ddp_pool->pool, GFP_ATOMIC, &ddp->udp);
  764. if (!ddp->udl) {
  765. dev_info(&pf->pdev->dev,
  766. "Failed allocated ddp context, xid 0x%x\n", xid);
  767. goto out_noddp_unmap;
  768. }
  769. j = 0;
  770. ddp->len = 0;
  771. for_each_sg(sgl, sg, dmacount, i) {
  772. addr = sg_dma_address(sg);
  773. len = sg_dma_len(sg);
  774. ddp->len += len;
  775. while (len) {
  776. /* max number of buffers allowed in one DDP context */
  777. if (j >= I40E_FCOE_DDP_BUFFCNT_MAX) {
  778. dev_info(&pf->pdev->dev,
  779. "xid=%x:%d,%d,%d:addr=%llx not enough descriptors\n",
  780. xid, i, j, dmacount, (u64)addr);
  781. goto out_noddp_free;
  782. }
  783. /* get the offset of length of current buffer */
  784. thisoff = addr & ((dma_addr_t)bufflen - 1);
  785. thislen = min_t(unsigned int, (bufflen - thisoff), len);
  786. /* all but the 1st buffer (j == 0)
  787. * must be aligned on bufflen
  788. */
  789. if ((j != 0) && (thisoff))
  790. goto out_noddp_free;
  791. /* all but the last buffer
  792. * ((i == (dmacount - 1)) && (thislen == len))
  793. * must end at bufflen
  794. */
  795. if (((i != (dmacount - 1)) || (thislen != len)) &&
  796. ((thislen + thisoff) != bufflen))
  797. goto out_noddp_free;
  798. ddp->udl[j] = (u64)(addr - thisoff);
  799. /* only the first buffer may have none-zero offset */
  800. if (j == 0)
  801. firstoff = thisoff;
  802. len -= thislen;
  803. addr += thislen;
  804. j++;
  805. }
  806. }
  807. /* only the last buffer may have non-full bufflen */
  808. ddp->lastsize = thisoff + thislen;
  809. ddp->firstoff = firstoff;
  810. ddp->list_len = j;
  811. ddp->pool = ddp_pool->pool;
  812. ddp->sgl = sgl;
  813. ddp->sgc = sgc;
  814. ddp->xid = xid;
  815. if (target_mode)
  816. set_bit(__I40E_FCOE_DDP_TARGET, &ddp->flags);
  817. set_bit(__I40E_FCOE_DDP_INITALIZED, &ddp->flags);
  818. put_cpu();
  819. return 1; /* Success */
  820. out_noddp_free:
  821. dma_pool_free(ddp->pool, ddp->udl, ddp->udp);
  822. i40e_fcoe_ddp_clear(ddp);
  823. out_noddp_unmap:
  824. dma_unmap_sg(&pf->pdev->dev, sgl, sgc, DMA_FROM_DEVICE);
  825. out_noddp:
  826. put_cpu();
  827. return 0;
  828. }
  829. /**
  830. * i40e_fcoe_ddp_get - called to set up ddp context in initiator mode
  831. * @netdev: the corresponding net_device
  832. * @xid: the exchange id requesting ddp
  833. * @sgl: the scatter-gather list for this request
  834. * @sgc: the number of scatter-gather items
  835. *
  836. * This is the implementation of net_device_ops.ndo_fcoe_ddp_setup
  837. * and is expected to be called from ULD, e.g., FCP layer of libfc
  838. * to set up ddp for the corresponding xid of the given sglist for
  839. * the corresponding I/O.
  840. *
  841. * Returns : 1 for success and 0 for no ddp
  842. **/
  843. static int i40e_fcoe_ddp_get(struct net_device *netdev, u16 xid,
  844. struct scatterlist *sgl, unsigned int sgc)
  845. {
  846. return i40e_fcoe_ddp_setup(netdev, xid, sgl, sgc, 0);
  847. }
  848. /**
  849. * i40e_fcoe_ddp_target - called to set up ddp context in target mode
  850. * @netdev: the corresponding net_device
  851. * @xid: the exchange id requesting ddp
  852. * @sgl: the scatter-gather list for this request
  853. * @sgc: the number of scatter-gather items
  854. *
  855. * This is the implementation of net_device_ops.ndo_fcoe_ddp_target
  856. * and is expected to be called from ULD, e.g., FCP layer of libfc
  857. * to set up ddp for the corresponding xid of the given sglist for
  858. * the corresponding I/O. The DDP in target mode is a write I/O request
  859. * from the initiator.
  860. *
  861. * Returns : 1 for success and 0 for no ddp
  862. **/
  863. static int i40e_fcoe_ddp_target(struct net_device *netdev, u16 xid,
  864. struct scatterlist *sgl, unsigned int sgc)
  865. {
  866. return i40e_fcoe_ddp_setup(netdev, xid, sgl, sgc, 1);
  867. }
  868. /**
  869. * i40e_fcoe_program_ddp - programs the HW DDP related descriptors
  870. * @tx_ring: transmit ring for this packet
  871. * @skb: the packet to be sent out
  872. * @sof: the SOF to indicate class of service
  873. *
  874. * Determine if it is READ/WRITE command, and finds out if there is
  875. * a matching SW DDP context for this command. DDP is applicable
  876. * only in case of READ if initiator or WRITE in case of
  877. * responder (via checking XFER_RDY).
  878. *
  879. * Note: caller checks sof and ddp sw context
  880. *
  881. * Returns : none
  882. *
  883. **/
  884. static void i40e_fcoe_program_ddp(struct i40e_ring *tx_ring,
  885. struct sk_buff *skb,
  886. struct i40e_fcoe_ddp *ddp, u8 sof)
  887. {
  888. struct i40e_fcoe_filter_context_desc *filter_desc = NULL;
  889. struct i40e_fcoe_queue_context_desc *queue_desc = NULL;
  890. struct i40e_fcoe_ddp_context_desc *ddp_desc = NULL;
  891. struct i40e_pf *pf = tx_ring->vsi->back;
  892. u16 i = tx_ring->next_to_use;
  893. struct fc_frame_header *fh;
  894. u64 flags_rsvd_lanq = 0;
  895. bool target_mode;
  896. /* check if abort is still pending */
  897. if (test_bit(__I40E_FCOE_DDP_ABORTED, &ddp->flags)) {
  898. dev_warn(&pf->pdev->dev,
  899. "DDP abort is still pending xid:%hx and ddp->flags:%lx:\n",
  900. ddp->xid, ddp->flags);
  901. return;
  902. }
  903. /* set the flag to indicate this is programmed */
  904. if (test_and_set_bit(__I40E_FCOE_DDP_PROGRAMMED, &ddp->flags)) {
  905. dev_warn(&pf->pdev->dev,
  906. "DDP is already programmed for xid:%hx and ddp->flags:%lx:\n",
  907. ddp->xid, ddp->flags);
  908. return;
  909. }
  910. /* Prepare the DDP context descriptor */
  911. ddp_desc = I40E_DDP_CONTEXT_DESC(tx_ring, i);
  912. i++;
  913. if (i == tx_ring->count)
  914. i = 0;
  915. ddp_desc->type_cmd_foff_lsize =
  916. cpu_to_le64(I40E_TX_DESC_DTYPE_DDP_CTX |
  917. ((u64)I40E_FCOE_DDP_CTX_DESC_BSIZE_4K <<
  918. I40E_FCOE_DDP_CTX_QW1_CMD_SHIFT) |
  919. ((u64)ddp->firstoff <<
  920. I40E_FCOE_DDP_CTX_QW1_FOFF_SHIFT) |
  921. ((u64)ddp->lastsize <<
  922. I40E_FCOE_DDP_CTX_QW1_LSIZE_SHIFT));
  923. ddp_desc->rsvd = cpu_to_le64(0);
  924. /* target mode needs last packet in the sequence */
  925. target_mode = test_bit(__I40E_FCOE_DDP_TARGET, &ddp->flags);
  926. if (target_mode)
  927. ddp_desc->type_cmd_foff_lsize |=
  928. cpu_to_le64(I40E_FCOE_DDP_CTX_DESC_LASTSEQH);
  929. /* Prepare queue_context descriptor */
  930. queue_desc = I40E_QUEUE_CONTEXT_DESC(tx_ring, i++);
  931. if (i == tx_ring->count)
  932. i = 0;
  933. queue_desc->dmaindx_fbase = cpu_to_le64(ddp->xid | ((u64)ddp->udp));
  934. queue_desc->flen_tph = cpu_to_le64(ddp->list_len |
  935. ((u64)(I40E_FCOE_QUEUE_CTX_DESC_TPHRDESC |
  936. I40E_FCOE_QUEUE_CTX_DESC_TPHDATA) <<
  937. I40E_FCOE_QUEUE_CTX_QW1_TPH_SHIFT));
  938. /* Prepare filter_context_desc */
  939. filter_desc = I40E_FILTER_CONTEXT_DESC(tx_ring, i);
  940. i++;
  941. if (i == tx_ring->count)
  942. i = 0;
  943. fh = (struct fc_frame_header *)skb_transport_header(skb);
  944. filter_desc->param = cpu_to_le32(ntohl(fh->fh_parm_offset));
  945. filter_desc->seqn = cpu_to_le16(ntohs(fh->fh_seq_cnt));
  946. filter_desc->rsvd_dmaindx = cpu_to_le16(ddp->xid <<
  947. I40E_FCOE_FILTER_CTX_QW0_DMAINDX_SHIFT);
  948. flags_rsvd_lanq = I40E_FCOE_FILTER_CTX_DESC_CTYP_DDP;
  949. flags_rsvd_lanq |= (u64)(target_mode ?
  950. I40E_FCOE_FILTER_CTX_DESC_ENODE_RSP :
  951. I40E_FCOE_FILTER_CTX_DESC_ENODE_INIT);
  952. flags_rsvd_lanq |= (u64)((sof == FC_SOF_I2 || sof == FC_SOF_N2) ?
  953. I40E_FCOE_FILTER_CTX_DESC_FC_CLASS2 :
  954. I40E_FCOE_FILTER_CTX_DESC_FC_CLASS3);
  955. flags_rsvd_lanq |= ((u64)skb->queue_mapping <<
  956. I40E_FCOE_FILTER_CTX_QW1_LANQINDX_SHIFT);
  957. filter_desc->flags_rsvd_lanq = cpu_to_le64(flags_rsvd_lanq);
  958. /* By this time, all offload related descriptors has been programmed */
  959. tx_ring->next_to_use = i;
  960. }
  961. /**
  962. * i40e_fcoe_invalidate_ddp - invalidates DDP in case of abort
  963. * @tx_ring: transmit ring for this packet
  964. * @skb: the packet associated w/ this DDP invalidation, i.e., ABTS
  965. * @ddp: the SW DDP context for this DDP
  966. *
  967. * Programs the Tx context descriptor to do DDP invalidation.
  968. **/
  969. static void i40e_fcoe_invalidate_ddp(struct i40e_ring *tx_ring,
  970. struct sk_buff *skb,
  971. struct i40e_fcoe_ddp *ddp)
  972. {
  973. struct i40e_tx_context_desc *context_desc;
  974. int i;
  975. if (test_and_set_bit(__I40E_FCOE_DDP_ABORTED, &ddp->flags))
  976. return;
  977. i = tx_ring->next_to_use;
  978. context_desc = I40E_TX_CTXTDESC(tx_ring, i);
  979. i++;
  980. if (i == tx_ring->count)
  981. i = 0;
  982. context_desc->tunneling_params = cpu_to_le32(0);
  983. context_desc->l2tag2 = cpu_to_le16(0);
  984. context_desc->rsvd = cpu_to_le16(0);
  985. context_desc->type_cmd_tso_mss = cpu_to_le64(
  986. I40E_TX_DESC_DTYPE_FCOE_CTX |
  987. (I40E_FCOE_TX_CTX_DESC_OPCODE_DDP_CTX_INVL <<
  988. I40E_TXD_CTX_QW1_CMD_SHIFT) |
  989. (I40E_FCOE_TX_CTX_DESC_OPCODE_SINGLE_SEND <<
  990. I40E_TXD_CTX_QW1_CMD_SHIFT));
  991. tx_ring->next_to_use = i;
  992. }
  993. /**
  994. * i40e_fcoe_handle_ddp - check we should setup or invalidate DDP
  995. * @tx_ring: transmit ring for this packet
  996. * @skb: the packet to be sent out
  997. * @sof: the SOF to indicate class of service
  998. *
  999. * Determine if it is ABTS/READ/XFER_RDY, and finds out if there is
  1000. * a matching SW DDP context for this command. DDP is applicable
  1001. * only in case of READ if initiator or WRITE in case of
  1002. * responder (via checking XFER_RDY). In case this is an ABTS, send
  1003. * just invalidate the context.
  1004. **/
  1005. static void i40e_fcoe_handle_ddp(struct i40e_ring *tx_ring,
  1006. struct sk_buff *skb, u8 sof)
  1007. {
  1008. struct i40e_pf *pf = tx_ring->vsi->back;
  1009. struct i40e_fcoe *fcoe = &pf->fcoe;
  1010. struct fc_frame_header *fh;
  1011. struct i40e_fcoe_ddp *ddp;
  1012. u32 f_ctl;
  1013. u8 r_ctl;
  1014. u16 xid;
  1015. fh = (struct fc_frame_header *)skb_transport_header(skb);
  1016. f_ctl = ntoh24(fh->fh_f_ctl);
  1017. r_ctl = fh->fh_r_ctl;
  1018. ddp = NULL;
  1019. if ((r_ctl == FC_RCTL_DD_DATA_DESC) && (f_ctl & FC_FC_EX_CTX)) {
  1020. /* exchange responder? if so, XFER_RDY for write */
  1021. xid = ntohs(fh->fh_rx_id);
  1022. if (i40e_fcoe_xid_is_valid(xid)) {
  1023. ddp = &fcoe->ddp[xid];
  1024. if ((ddp->xid == xid) &&
  1025. (test_bit(__I40E_FCOE_DDP_TARGET, &ddp->flags)))
  1026. i40e_fcoe_program_ddp(tx_ring, skb, ddp, sof);
  1027. }
  1028. } else if (r_ctl == FC_RCTL_DD_UNSOL_CMD) {
  1029. /* exchange originator, check READ cmd */
  1030. xid = ntohs(fh->fh_ox_id);
  1031. if (i40e_fcoe_xid_is_valid(xid)) {
  1032. ddp = &fcoe->ddp[xid];
  1033. if ((ddp->xid == xid) &&
  1034. (!test_bit(__I40E_FCOE_DDP_TARGET, &ddp->flags)))
  1035. i40e_fcoe_program_ddp(tx_ring, skb, ddp, sof);
  1036. }
  1037. } else if (r_ctl == FC_RCTL_BA_ABTS) {
  1038. /* exchange originator, check ABTS */
  1039. xid = ntohs(fh->fh_ox_id);
  1040. if (i40e_fcoe_xid_is_valid(xid)) {
  1041. ddp = &fcoe->ddp[xid];
  1042. if ((ddp->xid == xid) &&
  1043. (!test_bit(__I40E_FCOE_DDP_TARGET, &ddp->flags)))
  1044. i40e_fcoe_invalidate_ddp(tx_ring, skb, ddp);
  1045. }
  1046. }
  1047. }
  1048. /**
  1049. * i40e_fcoe_tso - set up FCoE TSO
  1050. * @tx_ring: ring to send buffer on
  1051. * @skb: send buffer
  1052. * @tx_flags: collected send information
  1053. * @hdr_len: the tso header length
  1054. * @sof: the SOF to indicate class of service
  1055. *
  1056. * Note must already have sof checked to be either class 2 or class 3 before
  1057. * calling this function.
  1058. *
  1059. * Returns 1 to indicate sequence segmentation offload is properly setup
  1060. * or returns 0 to indicate no tso is needed, otherwise returns error
  1061. * code to drop the frame.
  1062. **/
  1063. static int i40e_fcoe_tso(struct i40e_ring *tx_ring,
  1064. struct sk_buff *skb,
  1065. u32 tx_flags, u8 *hdr_len, u8 sof)
  1066. {
  1067. struct i40e_tx_context_desc *context_desc;
  1068. u32 cd_type, cd_cmd, cd_tso_len, cd_mss;
  1069. struct fc_frame_header *fh;
  1070. u64 cd_type_cmd_tso_mss;
  1071. /* must match gso type as FCoE */
  1072. if (!skb_is_gso(skb))
  1073. return 0;
  1074. /* is it the expected gso type for FCoE ?*/
  1075. if (skb_shinfo(skb)->gso_type != SKB_GSO_FCOE) {
  1076. netdev_err(skb->dev,
  1077. "wrong gso type %d:expecting SKB_GSO_FCOE\n",
  1078. skb_shinfo(skb)->gso_type);
  1079. return -EINVAL;
  1080. }
  1081. /* header and trailer are inserted by hw */
  1082. *hdr_len = skb_transport_offset(skb) + sizeof(struct fc_frame_header) +
  1083. sizeof(struct fcoe_crc_eof);
  1084. /* check sof to decide a class 2 or 3 TSO */
  1085. if (likely(i40e_fcoe_sof_is_class3(sof)))
  1086. cd_cmd = I40E_FCOE_TX_CTX_DESC_OPCODE_TSO_FC_CLASS3;
  1087. else
  1088. cd_cmd = I40E_FCOE_TX_CTX_DESC_OPCODE_TSO_FC_CLASS2;
  1089. /* param field valid? */
  1090. fh = (struct fc_frame_header *)skb_transport_header(skb);
  1091. if (fh->fh_f_ctl[2] & FC_FC_REL_OFF)
  1092. cd_cmd |= I40E_FCOE_TX_CTX_DESC_RELOFF;
  1093. /* fill the field values */
  1094. cd_type = I40E_TX_DESC_DTYPE_FCOE_CTX;
  1095. cd_tso_len = skb->len - *hdr_len;
  1096. cd_mss = skb_shinfo(skb)->gso_size;
  1097. cd_type_cmd_tso_mss =
  1098. ((u64)cd_type << I40E_TXD_CTX_QW1_DTYPE_SHIFT) |
  1099. ((u64)cd_cmd << I40E_TXD_CTX_QW1_CMD_SHIFT) |
  1100. ((u64)cd_tso_len << I40E_TXD_CTX_QW1_TSO_LEN_SHIFT) |
  1101. ((u64)cd_mss << I40E_TXD_CTX_QW1_MSS_SHIFT);
  1102. /* grab the next descriptor */
  1103. context_desc = I40E_TX_CTXTDESC(tx_ring, tx_ring->next_to_use);
  1104. tx_ring->next_to_use++;
  1105. if (tx_ring->next_to_use == tx_ring->count)
  1106. tx_ring->next_to_use = 0;
  1107. context_desc->tunneling_params = 0;
  1108. context_desc->l2tag2 = cpu_to_le16((tx_flags & I40E_TX_FLAGS_VLAN_MASK)
  1109. >> I40E_TX_FLAGS_VLAN_SHIFT);
  1110. context_desc->type_cmd_tso_mss = cpu_to_le64(cd_type_cmd_tso_mss);
  1111. return 1;
  1112. }
  1113. /**
  1114. * i40e_fcoe_tx_map - build the tx descriptor
  1115. * @tx_ring: ring to send buffer on
  1116. * @skb: send buffer
  1117. * @first: first buffer info buffer to use
  1118. * @tx_flags: collected send information
  1119. * @hdr_len: ptr to the size of the packet header
  1120. * @eof: the frame eof value
  1121. *
  1122. * Note, for FCoE, sof and eof are already checked
  1123. **/
  1124. static void i40e_fcoe_tx_map(struct i40e_ring *tx_ring,
  1125. struct sk_buff *skb,
  1126. struct i40e_tx_buffer *first,
  1127. u32 tx_flags, u8 hdr_len, u8 eof)
  1128. {
  1129. u32 td_offset = 0;
  1130. u32 td_cmd = 0;
  1131. u32 maclen;
  1132. /* insert CRC */
  1133. td_cmd = I40E_TX_DESC_CMD_ICRC;
  1134. /* setup MACLEN */
  1135. maclen = skb_network_offset(skb);
  1136. if (tx_flags & I40E_TX_FLAGS_SW_VLAN)
  1137. maclen += sizeof(struct vlan_hdr);
  1138. if (skb->protocol == htons(ETH_P_FCOE)) {
  1139. /* for FCoE, maclen should exclude ether type */
  1140. maclen -= 2;
  1141. /* setup type as FCoE and EOF insertion */
  1142. td_cmd |= (I40E_TX_DESC_CMD_FCOET | i40e_fcoe_ctxt_eof(eof));
  1143. /* setup FCoELEN and FCLEN */
  1144. td_offset |= ((((sizeof(struct fcoe_hdr) + 2) >> 2) <<
  1145. I40E_TX_DESC_LENGTH_IPLEN_SHIFT) |
  1146. ((sizeof(struct fc_frame_header) >> 2) <<
  1147. I40E_TX_DESC_LENGTH_L4_FC_LEN_SHIFT));
  1148. /* trim to exclude trailer */
  1149. pskb_trim(skb, skb->len - sizeof(struct fcoe_crc_eof));
  1150. }
  1151. /* MACLEN is ether header length in words not bytes */
  1152. td_offset |= (maclen >> 1) << I40E_TX_DESC_LENGTH_MACLEN_SHIFT;
  1153. i40e_tx_map(tx_ring, skb, first, tx_flags, hdr_len, td_cmd, td_offset);
  1154. }
  1155. /**
  1156. * i40e_fcoe_set_skb_header - adjust skb header point for FIP/FCoE/FC
  1157. * @skb: the skb to be adjusted
  1158. *
  1159. * Returns true if this skb is a FCoE/FIP or VLAN carried FCoE/FIP and then
  1160. * adjusts the skb header pointers correspondingly. Otherwise, returns false.
  1161. **/
  1162. static inline int i40e_fcoe_set_skb_header(struct sk_buff *skb)
  1163. {
  1164. __be16 protocol = skb->protocol;
  1165. skb_reset_mac_header(skb);
  1166. skb->mac_len = sizeof(struct ethhdr);
  1167. if (protocol == htons(ETH_P_8021Q)) {
  1168. struct vlan_ethhdr *veth = (struct vlan_ethhdr *)eth_hdr(skb);
  1169. protocol = veth->h_vlan_encapsulated_proto;
  1170. skb->mac_len += sizeof(struct vlan_hdr);
  1171. }
  1172. /* FCoE or FIP only */
  1173. if ((protocol != htons(ETH_P_FIP)) &&
  1174. (protocol != htons(ETH_P_FCOE)))
  1175. return -EINVAL;
  1176. /* set header to L2 of FCoE/FIP */
  1177. skb_set_network_header(skb, skb->mac_len);
  1178. if (protocol == htons(ETH_P_FIP))
  1179. return 0;
  1180. /* set header to L3 of FC */
  1181. skb_set_transport_header(skb, skb->mac_len + sizeof(struct fcoe_hdr));
  1182. return 0;
  1183. }
  1184. /**
  1185. * i40e_fcoe_xmit_frame - transmit buffer
  1186. * @skb: send buffer
  1187. * @netdev: the fcoe netdev
  1188. *
  1189. * Returns 0 if sent, else an error code
  1190. **/
  1191. static netdev_tx_t i40e_fcoe_xmit_frame(struct sk_buff *skb,
  1192. struct net_device *netdev)
  1193. {
  1194. struct i40e_netdev_priv *np = netdev_priv(skb->dev);
  1195. struct i40e_vsi *vsi = np->vsi;
  1196. struct i40e_ring *tx_ring = vsi->tx_rings[skb->queue_mapping];
  1197. struct i40e_tx_buffer *first;
  1198. u32 tx_flags = 0;
  1199. u8 hdr_len = 0;
  1200. u8 sof = 0;
  1201. u8 eof = 0;
  1202. int fso;
  1203. if (i40e_fcoe_set_skb_header(skb))
  1204. goto out_drop;
  1205. if (!i40e_xmit_descriptor_count(skb, tx_ring))
  1206. return NETDEV_TX_BUSY;
  1207. /* prepare the xmit flags */
  1208. if (i40e_tx_prepare_vlan_flags(skb, tx_ring, &tx_flags))
  1209. goto out_drop;
  1210. /* record the location of the first descriptor for this packet */
  1211. first = &tx_ring->tx_bi[tx_ring->next_to_use];
  1212. /* FIP is a regular L2 traffic w/o offload */
  1213. if (skb->protocol == htons(ETH_P_FIP))
  1214. goto out_send;
  1215. /* check sof and eof, only supports FC Class 2 or 3 */
  1216. if (i40e_fcoe_fc_sof(skb, &sof) || i40e_fcoe_fc_eof(skb, &eof)) {
  1217. netdev_err(netdev, "SOF/EOF error:%02x - %02x\n", sof, eof);
  1218. goto out_drop;
  1219. }
  1220. /* always do FCCRC for FCoE */
  1221. tx_flags |= I40E_TX_FLAGS_FCCRC;
  1222. /* check we should do sequence offload */
  1223. fso = i40e_fcoe_tso(tx_ring, skb, tx_flags, &hdr_len, sof);
  1224. if (fso < 0)
  1225. goto out_drop;
  1226. else if (fso)
  1227. tx_flags |= I40E_TX_FLAGS_FSO;
  1228. else
  1229. i40e_fcoe_handle_ddp(tx_ring, skb, sof);
  1230. out_send:
  1231. /* send out the packet */
  1232. i40e_fcoe_tx_map(tx_ring, skb, first, tx_flags, hdr_len, eof);
  1233. i40e_maybe_stop_tx(tx_ring, DESC_NEEDED);
  1234. return NETDEV_TX_OK;
  1235. out_drop:
  1236. dev_kfree_skb_any(skb);
  1237. return NETDEV_TX_OK;
  1238. }
  1239. /**
  1240. * i40e_fcoe_change_mtu - NDO callback to change the Maximum Transfer Unit
  1241. * @netdev: network interface device structure
  1242. * @new_mtu: new value for maximum frame size
  1243. *
  1244. * Returns error as operation not permitted
  1245. *
  1246. **/
  1247. static int i40e_fcoe_change_mtu(struct net_device *netdev, int new_mtu)
  1248. {
  1249. netdev_warn(netdev, "MTU change is not supported on FCoE interfaces\n");
  1250. return -EPERM;
  1251. }
  1252. /**
  1253. * i40e_fcoe_set_features - set the netdev feature flags
  1254. * @netdev: ptr to the netdev being adjusted
  1255. * @features: the feature set that the stack is suggesting
  1256. *
  1257. **/
  1258. static int i40e_fcoe_set_features(struct net_device *netdev,
  1259. netdev_features_t features)
  1260. {
  1261. struct i40e_netdev_priv *np = netdev_priv(netdev);
  1262. struct i40e_vsi *vsi = np->vsi;
  1263. if (features & NETIF_F_HW_VLAN_CTAG_RX)
  1264. i40e_vlan_stripping_enable(vsi);
  1265. else
  1266. i40e_vlan_stripping_disable(vsi);
  1267. return 0;
  1268. }
  1269. static const struct net_device_ops i40e_fcoe_netdev_ops = {
  1270. .ndo_open = i40e_open,
  1271. .ndo_stop = i40e_close,
  1272. .ndo_get_stats64 = i40e_get_netdev_stats_struct,
  1273. .ndo_set_rx_mode = i40e_set_rx_mode,
  1274. .ndo_validate_addr = eth_validate_addr,
  1275. .ndo_set_mac_address = i40e_set_mac,
  1276. .ndo_change_mtu = i40e_fcoe_change_mtu,
  1277. .ndo_do_ioctl = i40e_ioctl,
  1278. .ndo_tx_timeout = i40e_tx_timeout,
  1279. .ndo_vlan_rx_add_vid = i40e_vlan_rx_add_vid,
  1280. .ndo_vlan_rx_kill_vid = i40e_vlan_rx_kill_vid,
  1281. .ndo_setup_tc = i40e_setup_tc,
  1282. #ifdef CONFIG_NET_POLL_CONTROLLER
  1283. .ndo_poll_controller = i40e_netpoll,
  1284. #endif
  1285. .ndo_start_xmit = i40e_fcoe_xmit_frame,
  1286. .ndo_fcoe_enable = i40e_fcoe_enable,
  1287. .ndo_fcoe_disable = i40e_fcoe_disable,
  1288. .ndo_fcoe_ddp_setup = i40e_fcoe_ddp_get,
  1289. .ndo_fcoe_ddp_done = i40e_fcoe_ddp_put,
  1290. .ndo_fcoe_ddp_target = i40e_fcoe_ddp_target,
  1291. .ndo_set_features = i40e_fcoe_set_features,
  1292. };
  1293. /* fcoe network device type */
  1294. static struct device_type fcoe_netdev_type = {
  1295. .name = "fcoe",
  1296. };
  1297. /**
  1298. * i40e_fcoe_config_netdev - prepares the VSI context for creating a FCoE VSI
  1299. * @vsi: pointer to the associated VSI struct
  1300. * @ctxt: pointer to the associated VSI context to be passed to HW
  1301. *
  1302. * Returns 0 on success or < 0 on error
  1303. **/
  1304. void i40e_fcoe_config_netdev(struct net_device *netdev, struct i40e_vsi *vsi)
  1305. {
  1306. struct i40e_hw *hw = &vsi->back->hw;
  1307. struct i40e_pf *pf = vsi->back;
  1308. if (vsi->type != I40E_VSI_FCOE)
  1309. return;
  1310. netdev->features = (NETIF_F_HW_VLAN_CTAG_TX |
  1311. NETIF_F_HW_VLAN_CTAG_RX |
  1312. NETIF_F_HW_VLAN_CTAG_FILTER);
  1313. netdev->vlan_features = netdev->features;
  1314. netdev->vlan_features &= ~(NETIF_F_HW_VLAN_CTAG_TX |
  1315. NETIF_F_HW_VLAN_CTAG_RX |
  1316. NETIF_F_HW_VLAN_CTAG_FILTER);
  1317. netdev->fcoe_ddp_xid = I40E_FCOE_DDP_MAX - 1;
  1318. netdev->features |= NETIF_F_ALL_FCOE;
  1319. netdev->vlan_features |= NETIF_F_ALL_FCOE;
  1320. netdev->hw_features |= netdev->features;
  1321. netdev->priv_flags |= IFF_UNICAST_FLT;
  1322. netdev->priv_flags |= IFF_SUPP_NOFCS;
  1323. strlcpy(netdev->name, "fcoe%d", IFNAMSIZ-1);
  1324. netdev->mtu = FCOE_MTU;
  1325. SET_NETDEV_DEV(netdev, &pf->pdev->dev);
  1326. SET_NETDEV_DEVTYPE(netdev, &fcoe_netdev_type);
  1327. /* set different dev_port value 1 for FCoE netdev than the default
  1328. * zero dev_port value for PF netdev, this helps biosdevname user
  1329. * tool to differentiate them correctly while both attached to the
  1330. * same PCI function.
  1331. */
  1332. netdev->dev_port = 1;
  1333. spin_lock_bh(&vsi->mac_filter_list_lock);
  1334. i40e_add_filter(vsi, hw->mac.san_addr, 0, false, false);
  1335. i40e_add_filter(vsi, (u8[6]) FC_FCOE_FLOGI_MAC, 0, false, false);
  1336. i40e_add_filter(vsi, FIP_ALL_FCOE_MACS, 0, false, false);
  1337. i40e_add_filter(vsi, FIP_ALL_ENODE_MACS, 0, false, false);
  1338. spin_unlock_bh(&vsi->mac_filter_list_lock);
  1339. /* use san mac */
  1340. ether_addr_copy(netdev->dev_addr, hw->mac.san_addr);
  1341. ether_addr_copy(netdev->perm_addr, hw->mac.san_addr);
  1342. /* fcoe netdev ops */
  1343. netdev->netdev_ops = &i40e_fcoe_netdev_ops;
  1344. }
  1345. /**
  1346. * i40e_fcoe_vsi_setup - allocate and set up FCoE VSI
  1347. * @pf: the PF that VSI is associated with
  1348. *
  1349. **/
  1350. void i40e_fcoe_vsi_setup(struct i40e_pf *pf)
  1351. {
  1352. struct i40e_vsi *vsi;
  1353. u16 seid;
  1354. int i;
  1355. if (!(pf->flags & I40E_FLAG_FCOE_ENABLED))
  1356. return;
  1357. BUG_ON(!pf->vsi[pf->lan_vsi]);
  1358. for (i = 0; i < pf->num_alloc_vsi; i++) {
  1359. vsi = pf->vsi[i];
  1360. if (vsi && vsi->type == I40E_VSI_FCOE) {
  1361. dev_warn(&pf->pdev->dev,
  1362. "FCoE VSI already created\n");
  1363. return;
  1364. }
  1365. }
  1366. seid = pf->vsi[pf->lan_vsi]->seid;
  1367. vsi = i40e_vsi_setup(pf, I40E_VSI_FCOE, seid, 0);
  1368. if (vsi) {
  1369. dev_dbg(&pf->pdev->dev,
  1370. "Successfully created FCoE VSI seid %d id %d uplink_seid %d PF seid %d\n",
  1371. vsi->seid, vsi->id, vsi->uplink_seid, seid);
  1372. } else {
  1373. dev_info(&pf->pdev->dev, "Failed to create FCoE VSI\n");
  1374. }
  1375. }