i40e_fcoe.c 44 KB

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