siena_sriov.c 45 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644
  1. /****************************************************************************
  2. * Driver for Solarflare Solarstorm network controllers and boards
  3. * Copyright 2010-2011 Solarflare Communications Inc.
  4. *
  5. * This program is free software; you can redistribute it and/or modify it
  6. * under the terms of the GNU General Public License version 2 as published
  7. * by the Free Software Foundation, incorporated herein by reference.
  8. */
  9. #include <linux/pci.h>
  10. #include <linux/module.h>
  11. #include "net_driver.h"
  12. #include "efx.h"
  13. #include "nic.h"
  14. #include "io.h"
  15. #include "mcdi.h"
  16. #include "filter.h"
  17. #include "mcdi_pcol.h"
  18. #include "farch_regs.h"
  19. #include "vfdi.h"
  20. /* Number of longs required to track all the VIs in a VF */
  21. #define VI_MASK_LENGTH BITS_TO_LONGS(1 << EFX_VI_SCALE_MAX)
  22. /* Maximum number of RX queues supported */
  23. #define VF_MAX_RX_QUEUES 63
  24. /**
  25. * enum efx_vf_tx_filter_mode - TX MAC filtering behaviour
  26. * @VF_TX_FILTER_OFF: Disabled
  27. * @VF_TX_FILTER_AUTO: Enabled if MAC address assigned to VF and only
  28. * 2 TX queues allowed per VF.
  29. * @VF_TX_FILTER_ON: Enabled
  30. */
  31. enum efx_vf_tx_filter_mode {
  32. VF_TX_FILTER_OFF,
  33. VF_TX_FILTER_AUTO,
  34. VF_TX_FILTER_ON,
  35. };
  36. /**
  37. * struct efx_vf - Back-end resource and protocol state for a PCI VF
  38. * @efx: The Efx NIC owning this VF
  39. * @pci_rid: The PCI requester ID for this VF
  40. * @pci_name: The PCI name (formatted address) of this VF
  41. * @index: Index of VF within its port and PF.
  42. * @req: VFDI incoming request work item. Incoming USR_EV events are received
  43. * by the NAPI handler, but must be handled by executing MCDI requests
  44. * inside a work item.
  45. * @req_addr: VFDI incoming request DMA address (in VF's PCI address space).
  46. * @req_type: Expected next incoming (from VF) %VFDI_EV_TYPE member.
  47. * @req_seqno: Expected next incoming (from VF) %VFDI_EV_SEQ member.
  48. * @msg_seqno: Next %VFDI_EV_SEQ member to reply to VF. Protected by
  49. * @status_lock
  50. * @busy: VFDI request queued to be processed or being processed. Receiving
  51. * a VFDI request when @busy is set is an error condition.
  52. * @buf: Incoming VFDI requests are DMA from the VF into this buffer.
  53. * @buftbl_base: Buffer table entries for this VF start at this index.
  54. * @rx_filtering: Receive filtering has been requested by the VF driver.
  55. * @rx_filter_flags: The flags sent in the %VFDI_OP_INSERT_FILTER request.
  56. * @rx_filter_qid: VF relative qid for RX filter requested by VF.
  57. * @rx_filter_id: Receive MAC filter ID. Only one filter per VF is supported.
  58. * @tx_filter_mode: Transmit MAC filtering mode.
  59. * @tx_filter_id: Transmit MAC filter ID.
  60. * @addr: The MAC address and outer vlan tag of the VF.
  61. * @status_addr: VF DMA address of page for &struct vfdi_status updates.
  62. * @status_lock: Mutex protecting @msg_seqno, @status_addr, @addr,
  63. * @peer_page_addrs and @peer_page_count from simultaneous
  64. * updates by the VM and consumption by
  65. * efx_sriov_update_vf_addr()
  66. * @peer_page_addrs: Pointer to an array of guest pages for local addresses.
  67. * @peer_page_count: Number of entries in @peer_page_count.
  68. * @evq0_addrs: Array of guest pages backing evq0.
  69. * @evq0_count: Number of entries in @evq0_addrs.
  70. * @flush_waitq: wait queue used by %VFDI_OP_FINI_ALL_QUEUES handler
  71. * to wait for flush completions.
  72. * @txq_lock: Mutex for TX queue allocation.
  73. * @txq_mask: Mask of initialized transmit queues.
  74. * @txq_count: Number of initialized transmit queues.
  75. * @rxq_mask: Mask of initialized receive queues.
  76. * @rxq_count: Number of initialized receive queues.
  77. * @rxq_retry_mask: Mask or receive queues that need to be flushed again
  78. * due to flush failure.
  79. * @rxq_retry_count: Number of receive queues in @rxq_retry_mask.
  80. * @reset_work: Work item to schedule a VF reset.
  81. */
  82. struct efx_vf {
  83. struct efx_nic *efx;
  84. unsigned int pci_rid;
  85. char pci_name[13]; /* dddd:bb:dd.f */
  86. unsigned int index;
  87. struct work_struct req;
  88. u64 req_addr;
  89. int req_type;
  90. unsigned req_seqno;
  91. unsigned msg_seqno;
  92. bool busy;
  93. struct efx_buffer buf;
  94. unsigned buftbl_base;
  95. bool rx_filtering;
  96. enum efx_filter_flags rx_filter_flags;
  97. unsigned rx_filter_qid;
  98. int rx_filter_id;
  99. enum efx_vf_tx_filter_mode tx_filter_mode;
  100. int tx_filter_id;
  101. struct vfdi_endpoint addr;
  102. u64 status_addr;
  103. struct mutex status_lock;
  104. u64 *peer_page_addrs;
  105. unsigned peer_page_count;
  106. u64 evq0_addrs[EFX_MAX_VF_EVQ_SIZE * sizeof(efx_qword_t) /
  107. EFX_BUF_SIZE];
  108. unsigned evq0_count;
  109. wait_queue_head_t flush_waitq;
  110. struct mutex txq_lock;
  111. unsigned long txq_mask[VI_MASK_LENGTH];
  112. unsigned txq_count;
  113. unsigned long rxq_mask[VI_MASK_LENGTH];
  114. unsigned rxq_count;
  115. unsigned long rxq_retry_mask[VI_MASK_LENGTH];
  116. atomic_t rxq_retry_count;
  117. struct work_struct reset_work;
  118. };
  119. struct efx_memcpy_req {
  120. unsigned int from_rid;
  121. void *from_buf;
  122. u64 from_addr;
  123. unsigned int to_rid;
  124. u64 to_addr;
  125. unsigned length;
  126. };
  127. /**
  128. * struct efx_local_addr - A MAC address on the vswitch without a VF.
  129. *
  130. * Siena does not have a switch, so VFs can't transmit data to each
  131. * other. Instead the VFs must be made aware of the local addresses
  132. * on the vswitch, so that they can arrange for an alternative
  133. * software datapath to be used.
  134. *
  135. * @link: List head for insertion into efx->local_addr_list.
  136. * @addr: Ethernet address
  137. */
  138. struct efx_local_addr {
  139. struct list_head link;
  140. u8 addr[ETH_ALEN];
  141. };
  142. /**
  143. * struct efx_endpoint_page - Page of vfdi_endpoint structures
  144. *
  145. * @link: List head for insertion into efx->local_page_list.
  146. * @ptr: Pointer to page.
  147. * @addr: DMA address of page.
  148. */
  149. struct efx_endpoint_page {
  150. struct list_head link;
  151. void *ptr;
  152. dma_addr_t addr;
  153. };
  154. /* Buffer table entries are reserved txq0,rxq0,evq0,txq1,rxq1,evq1 */
  155. #define EFX_BUFTBL_TXQ_BASE(_vf, _qid) \
  156. ((_vf)->buftbl_base + EFX_VF_BUFTBL_PER_VI * (_qid))
  157. #define EFX_BUFTBL_RXQ_BASE(_vf, _qid) \
  158. (EFX_BUFTBL_TXQ_BASE(_vf, _qid) + \
  159. (EFX_MAX_DMAQ_SIZE * sizeof(efx_qword_t) / EFX_BUF_SIZE))
  160. #define EFX_BUFTBL_EVQ_BASE(_vf, _qid) \
  161. (EFX_BUFTBL_TXQ_BASE(_vf, _qid) + \
  162. (2 * EFX_MAX_DMAQ_SIZE * sizeof(efx_qword_t) / EFX_BUF_SIZE))
  163. #define EFX_FIELD_MASK(_field) \
  164. ((1 << _field ## _WIDTH) - 1)
  165. /* VFs can only use this many transmit channels */
  166. static unsigned int vf_max_tx_channels = 2;
  167. module_param(vf_max_tx_channels, uint, 0444);
  168. MODULE_PARM_DESC(vf_max_tx_channels,
  169. "Limit the number of TX channels VFs can use");
  170. static int max_vfs = -1;
  171. module_param(max_vfs, int, 0444);
  172. MODULE_PARM_DESC(max_vfs,
  173. "Reduce the number of VFs initialized by the driver");
  174. /* Workqueue used by VFDI communication. We can't use the global
  175. * workqueue because it may be running the VF driver's probe()
  176. * routine, which will be blocked there waiting for a VFDI response.
  177. */
  178. static struct workqueue_struct *vfdi_workqueue;
  179. static unsigned abs_index(struct efx_vf *vf, unsigned index)
  180. {
  181. return EFX_VI_BASE + vf->index * efx_vf_size(vf->efx) + index;
  182. }
  183. static int efx_sriov_cmd(struct efx_nic *efx, bool enable,
  184. unsigned *vi_scale_out, unsigned *vf_total_out)
  185. {
  186. MCDI_DECLARE_BUF(inbuf, MC_CMD_SRIOV_IN_LEN);
  187. MCDI_DECLARE_BUF(outbuf, MC_CMD_SRIOV_OUT_LEN);
  188. unsigned vi_scale, vf_total;
  189. size_t outlen;
  190. int rc;
  191. MCDI_SET_DWORD(inbuf, SRIOV_IN_ENABLE, enable ? 1 : 0);
  192. MCDI_SET_DWORD(inbuf, SRIOV_IN_VI_BASE, EFX_VI_BASE);
  193. MCDI_SET_DWORD(inbuf, SRIOV_IN_VF_COUNT, efx->vf_count);
  194. rc = efx_mcdi_rpc(efx, MC_CMD_SRIOV, inbuf, MC_CMD_SRIOV_IN_LEN,
  195. outbuf, MC_CMD_SRIOV_OUT_LEN, &outlen);
  196. if (rc)
  197. return rc;
  198. if (outlen < MC_CMD_SRIOV_OUT_LEN)
  199. return -EIO;
  200. vf_total = MCDI_DWORD(outbuf, SRIOV_OUT_VF_TOTAL);
  201. vi_scale = MCDI_DWORD(outbuf, SRIOV_OUT_VI_SCALE);
  202. if (vi_scale > EFX_VI_SCALE_MAX)
  203. return -EOPNOTSUPP;
  204. if (vi_scale_out)
  205. *vi_scale_out = vi_scale;
  206. if (vf_total_out)
  207. *vf_total_out = vf_total;
  208. return 0;
  209. }
  210. static void efx_sriov_usrev(struct efx_nic *efx, bool enabled)
  211. {
  212. efx_oword_t reg;
  213. EFX_POPULATE_OWORD_2(reg,
  214. FRF_CZ_USREV_DIS, enabled ? 0 : 1,
  215. FRF_CZ_DFLT_EVQ, efx->vfdi_channel->channel);
  216. efx_writeo(efx, &reg, FR_CZ_USR_EV_CFG);
  217. }
  218. static int efx_sriov_memcpy(struct efx_nic *efx, struct efx_memcpy_req *req,
  219. unsigned int count)
  220. {
  221. MCDI_DECLARE_BUF(inbuf, MCDI_CTL_SDU_LEN_MAX_V1);
  222. MCDI_DECLARE_STRUCT_PTR(record);
  223. unsigned int index, used;
  224. u64 from_addr;
  225. u32 from_rid;
  226. int rc;
  227. mb(); /* Finish writing source/reading dest before DMA starts */
  228. if (WARN_ON(count > MC_CMD_MEMCPY_IN_RECORD_MAXNUM))
  229. return -ENOBUFS;
  230. used = MC_CMD_MEMCPY_IN_LEN(count);
  231. for (index = 0; index < count; index++) {
  232. record = MCDI_ARRAY_STRUCT_PTR(inbuf, MEMCPY_IN_RECORD, index);
  233. MCDI_SET_DWORD(record, MEMCPY_RECORD_TYPEDEF_NUM_RECORDS,
  234. count);
  235. MCDI_SET_DWORD(record, MEMCPY_RECORD_TYPEDEF_TO_RID,
  236. req->to_rid);
  237. MCDI_SET_QWORD(record, MEMCPY_RECORD_TYPEDEF_TO_ADDR,
  238. req->to_addr);
  239. if (req->from_buf == NULL) {
  240. from_rid = req->from_rid;
  241. from_addr = req->from_addr;
  242. } else {
  243. if (WARN_ON(used + req->length >
  244. MCDI_CTL_SDU_LEN_MAX_V1)) {
  245. rc = -ENOBUFS;
  246. goto out;
  247. }
  248. from_rid = MC_CMD_MEMCPY_RECORD_TYPEDEF_RID_INLINE;
  249. from_addr = used;
  250. memcpy(_MCDI_PTR(inbuf, used), req->from_buf,
  251. req->length);
  252. used += req->length;
  253. }
  254. MCDI_SET_DWORD(record, MEMCPY_RECORD_TYPEDEF_FROM_RID, from_rid);
  255. MCDI_SET_QWORD(record, MEMCPY_RECORD_TYPEDEF_FROM_ADDR,
  256. from_addr);
  257. MCDI_SET_DWORD(record, MEMCPY_RECORD_TYPEDEF_LENGTH,
  258. req->length);
  259. ++req;
  260. }
  261. rc = efx_mcdi_rpc(efx, MC_CMD_MEMCPY, inbuf, used, NULL, 0, NULL);
  262. out:
  263. mb(); /* Don't write source/read dest before DMA is complete */
  264. return rc;
  265. }
  266. /* The TX filter is entirely controlled by this driver, and is modified
  267. * underneath the feet of the VF
  268. */
  269. static void efx_sriov_reset_tx_filter(struct efx_vf *vf)
  270. {
  271. struct efx_nic *efx = vf->efx;
  272. struct efx_filter_spec filter;
  273. u16 vlan;
  274. int rc;
  275. if (vf->tx_filter_id != -1) {
  276. efx_filter_remove_id_safe(efx, EFX_FILTER_PRI_REQUIRED,
  277. vf->tx_filter_id);
  278. netif_dbg(efx, hw, efx->net_dev, "Removed vf %s tx filter %d\n",
  279. vf->pci_name, vf->tx_filter_id);
  280. vf->tx_filter_id = -1;
  281. }
  282. if (is_zero_ether_addr(vf->addr.mac_addr))
  283. return;
  284. /* Turn on TX filtering automatically if not explicitly
  285. * enabled or disabled.
  286. */
  287. if (vf->tx_filter_mode == VF_TX_FILTER_AUTO && vf_max_tx_channels <= 2)
  288. vf->tx_filter_mode = VF_TX_FILTER_ON;
  289. vlan = ntohs(vf->addr.tci) & VLAN_VID_MASK;
  290. efx_filter_init_tx(&filter, abs_index(vf, 0));
  291. rc = efx_filter_set_eth_local(&filter,
  292. vlan ? vlan : EFX_FILTER_VID_UNSPEC,
  293. vf->addr.mac_addr);
  294. BUG_ON(rc);
  295. rc = efx_filter_insert_filter(efx, &filter, true);
  296. if (rc < 0) {
  297. netif_warn(efx, hw, efx->net_dev,
  298. "Unable to migrate tx filter for vf %s\n",
  299. vf->pci_name);
  300. } else {
  301. netif_dbg(efx, hw, efx->net_dev, "Inserted vf %s tx filter %d\n",
  302. vf->pci_name, rc);
  303. vf->tx_filter_id = rc;
  304. }
  305. }
  306. /* The RX filter is managed here on behalf of the VF driver */
  307. static void efx_sriov_reset_rx_filter(struct efx_vf *vf)
  308. {
  309. struct efx_nic *efx = vf->efx;
  310. struct efx_filter_spec filter;
  311. u16 vlan;
  312. int rc;
  313. if (vf->rx_filter_id != -1) {
  314. efx_filter_remove_id_safe(efx, EFX_FILTER_PRI_REQUIRED,
  315. vf->rx_filter_id);
  316. netif_dbg(efx, hw, efx->net_dev, "Removed vf %s rx filter %d\n",
  317. vf->pci_name, vf->rx_filter_id);
  318. vf->rx_filter_id = -1;
  319. }
  320. if (!vf->rx_filtering || is_zero_ether_addr(vf->addr.mac_addr))
  321. return;
  322. vlan = ntohs(vf->addr.tci) & VLAN_VID_MASK;
  323. efx_filter_init_rx(&filter, EFX_FILTER_PRI_REQUIRED,
  324. vf->rx_filter_flags,
  325. abs_index(vf, vf->rx_filter_qid));
  326. rc = efx_filter_set_eth_local(&filter,
  327. vlan ? vlan : EFX_FILTER_VID_UNSPEC,
  328. vf->addr.mac_addr);
  329. BUG_ON(rc);
  330. rc = efx_filter_insert_filter(efx, &filter, true);
  331. if (rc < 0) {
  332. netif_warn(efx, hw, efx->net_dev,
  333. "Unable to insert rx filter for vf %s\n",
  334. vf->pci_name);
  335. } else {
  336. netif_dbg(efx, hw, efx->net_dev, "Inserted vf %s rx filter %d\n",
  337. vf->pci_name, rc);
  338. vf->rx_filter_id = rc;
  339. }
  340. }
  341. static void __efx_sriov_update_vf_addr(struct efx_vf *vf)
  342. {
  343. efx_sriov_reset_tx_filter(vf);
  344. efx_sriov_reset_rx_filter(vf);
  345. queue_work(vfdi_workqueue, &vf->efx->peer_work);
  346. }
  347. /* Push the peer list to this VF. The caller must hold status_lock to interlock
  348. * with VFDI requests, and they must be serialised against manipulation of
  349. * local_page_list, either by acquiring local_lock or by running from
  350. * efx_sriov_peer_work()
  351. */
  352. static void __efx_sriov_push_vf_status(struct efx_vf *vf)
  353. {
  354. struct efx_nic *efx = vf->efx;
  355. struct vfdi_status *status = efx->vfdi_status.addr;
  356. struct efx_memcpy_req copy[4];
  357. struct efx_endpoint_page *epp;
  358. unsigned int pos, count;
  359. unsigned data_offset;
  360. efx_qword_t event;
  361. WARN_ON(!mutex_is_locked(&vf->status_lock));
  362. WARN_ON(!vf->status_addr);
  363. status->local = vf->addr;
  364. status->generation_end = ++status->generation_start;
  365. memset(copy, '\0', sizeof(copy));
  366. /* Write generation_start */
  367. copy[0].from_buf = &status->generation_start;
  368. copy[0].to_rid = vf->pci_rid;
  369. copy[0].to_addr = vf->status_addr + offsetof(struct vfdi_status,
  370. generation_start);
  371. copy[0].length = sizeof(status->generation_start);
  372. /* DMA the rest of the structure (excluding the generations). This
  373. * assumes that the non-generation portion of vfdi_status is in
  374. * one chunk starting at the version member.
  375. */
  376. data_offset = offsetof(struct vfdi_status, version);
  377. copy[1].from_rid = efx->pci_dev->devfn;
  378. copy[1].from_addr = efx->vfdi_status.dma_addr + data_offset;
  379. copy[1].to_rid = vf->pci_rid;
  380. copy[1].to_addr = vf->status_addr + data_offset;
  381. copy[1].length = status->length - data_offset;
  382. /* Copy the peer pages */
  383. pos = 2;
  384. count = 0;
  385. list_for_each_entry(epp, &efx->local_page_list, link) {
  386. if (count == vf->peer_page_count) {
  387. /* The VF driver will know they need to provide more
  388. * pages because peer_addr_count is too large.
  389. */
  390. break;
  391. }
  392. copy[pos].from_buf = NULL;
  393. copy[pos].from_rid = efx->pci_dev->devfn;
  394. copy[pos].from_addr = epp->addr;
  395. copy[pos].to_rid = vf->pci_rid;
  396. copy[pos].to_addr = vf->peer_page_addrs[count];
  397. copy[pos].length = EFX_PAGE_SIZE;
  398. if (++pos == ARRAY_SIZE(copy)) {
  399. efx_sriov_memcpy(efx, copy, ARRAY_SIZE(copy));
  400. pos = 0;
  401. }
  402. ++count;
  403. }
  404. /* Write generation_end */
  405. copy[pos].from_buf = &status->generation_end;
  406. copy[pos].to_rid = vf->pci_rid;
  407. copy[pos].to_addr = vf->status_addr + offsetof(struct vfdi_status,
  408. generation_end);
  409. copy[pos].length = sizeof(status->generation_end);
  410. efx_sriov_memcpy(efx, copy, pos + 1);
  411. /* Notify the guest */
  412. EFX_POPULATE_QWORD_3(event,
  413. FSF_AZ_EV_CODE, FSE_CZ_EV_CODE_USER_EV,
  414. VFDI_EV_SEQ, (vf->msg_seqno & 0xff),
  415. VFDI_EV_TYPE, VFDI_EV_TYPE_STATUS);
  416. ++vf->msg_seqno;
  417. efx_generate_event(efx, EFX_VI_BASE + vf->index * efx_vf_size(efx),
  418. &event);
  419. }
  420. static void efx_sriov_bufs(struct efx_nic *efx, unsigned offset,
  421. u64 *addr, unsigned count)
  422. {
  423. efx_qword_t buf;
  424. unsigned pos;
  425. for (pos = 0; pos < count; ++pos) {
  426. EFX_POPULATE_QWORD_3(buf,
  427. FRF_AZ_BUF_ADR_REGION, 0,
  428. FRF_AZ_BUF_ADR_FBUF,
  429. addr ? addr[pos] >> 12 : 0,
  430. FRF_AZ_BUF_OWNER_ID_FBUF, 0);
  431. efx_sram_writeq(efx, efx->membase + FR_BZ_BUF_FULL_TBL,
  432. &buf, offset + pos);
  433. }
  434. }
  435. static bool bad_vf_index(struct efx_nic *efx, unsigned index)
  436. {
  437. return index >= efx_vf_size(efx);
  438. }
  439. static bool bad_buf_count(unsigned buf_count, unsigned max_entry_count)
  440. {
  441. unsigned max_buf_count = max_entry_count *
  442. sizeof(efx_qword_t) / EFX_BUF_SIZE;
  443. return ((buf_count & (buf_count - 1)) || buf_count > max_buf_count);
  444. }
  445. /* Check that VI specified by per-port index belongs to a VF.
  446. * Optionally set VF index and VI index within the VF.
  447. */
  448. static bool map_vi_index(struct efx_nic *efx, unsigned abs_index,
  449. struct efx_vf **vf_out, unsigned *rel_index_out)
  450. {
  451. unsigned vf_i;
  452. if (abs_index < EFX_VI_BASE)
  453. return true;
  454. vf_i = (abs_index - EFX_VI_BASE) / efx_vf_size(efx);
  455. if (vf_i >= efx->vf_init_count)
  456. return true;
  457. if (vf_out)
  458. *vf_out = efx->vf + vf_i;
  459. if (rel_index_out)
  460. *rel_index_out = abs_index % efx_vf_size(efx);
  461. return false;
  462. }
  463. static int efx_vfdi_init_evq(struct efx_vf *vf)
  464. {
  465. struct efx_nic *efx = vf->efx;
  466. struct vfdi_req *req = vf->buf.addr;
  467. unsigned vf_evq = req->u.init_evq.index;
  468. unsigned buf_count = req->u.init_evq.buf_count;
  469. unsigned abs_evq = abs_index(vf, vf_evq);
  470. unsigned buftbl = EFX_BUFTBL_EVQ_BASE(vf, vf_evq);
  471. efx_oword_t reg;
  472. if (bad_vf_index(efx, vf_evq) ||
  473. bad_buf_count(buf_count, EFX_MAX_VF_EVQ_SIZE)) {
  474. if (net_ratelimit())
  475. netif_err(efx, hw, efx->net_dev,
  476. "ERROR: Invalid INIT_EVQ from %s: evq %d bufs %d\n",
  477. vf->pci_name, vf_evq, buf_count);
  478. return VFDI_RC_EINVAL;
  479. }
  480. efx_sriov_bufs(efx, buftbl, req->u.init_evq.addr, buf_count);
  481. EFX_POPULATE_OWORD_3(reg,
  482. FRF_CZ_TIMER_Q_EN, 1,
  483. FRF_CZ_HOST_NOTIFY_MODE, 0,
  484. FRF_CZ_TIMER_MODE, FFE_CZ_TIMER_MODE_DIS);
  485. efx_writeo_table(efx, &reg, FR_BZ_TIMER_TBL, abs_evq);
  486. EFX_POPULATE_OWORD_3(reg,
  487. FRF_AZ_EVQ_EN, 1,
  488. FRF_AZ_EVQ_SIZE, __ffs(buf_count),
  489. FRF_AZ_EVQ_BUF_BASE_ID, buftbl);
  490. efx_writeo_table(efx, &reg, FR_BZ_EVQ_PTR_TBL, abs_evq);
  491. if (vf_evq == 0) {
  492. memcpy(vf->evq0_addrs, req->u.init_evq.addr,
  493. buf_count * sizeof(u64));
  494. vf->evq0_count = buf_count;
  495. }
  496. return VFDI_RC_SUCCESS;
  497. }
  498. static int efx_vfdi_init_rxq(struct efx_vf *vf)
  499. {
  500. struct efx_nic *efx = vf->efx;
  501. struct vfdi_req *req = vf->buf.addr;
  502. unsigned vf_rxq = req->u.init_rxq.index;
  503. unsigned vf_evq = req->u.init_rxq.evq;
  504. unsigned buf_count = req->u.init_rxq.buf_count;
  505. unsigned buftbl = EFX_BUFTBL_RXQ_BASE(vf, vf_rxq);
  506. unsigned label;
  507. efx_oword_t reg;
  508. if (bad_vf_index(efx, vf_evq) || bad_vf_index(efx, vf_rxq) ||
  509. vf_rxq >= VF_MAX_RX_QUEUES ||
  510. bad_buf_count(buf_count, EFX_MAX_DMAQ_SIZE)) {
  511. if (net_ratelimit())
  512. netif_err(efx, hw, efx->net_dev,
  513. "ERROR: Invalid INIT_RXQ from %s: rxq %d evq %d "
  514. "buf_count %d\n", vf->pci_name, vf_rxq,
  515. vf_evq, buf_count);
  516. return VFDI_RC_EINVAL;
  517. }
  518. if (__test_and_set_bit(req->u.init_rxq.index, vf->rxq_mask))
  519. ++vf->rxq_count;
  520. efx_sriov_bufs(efx, buftbl, req->u.init_rxq.addr, buf_count);
  521. label = req->u.init_rxq.label & EFX_FIELD_MASK(FRF_AZ_RX_DESCQ_LABEL);
  522. EFX_POPULATE_OWORD_6(reg,
  523. FRF_AZ_RX_DESCQ_BUF_BASE_ID, buftbl,
  524. FRF_AZ_RX_DESCQ_EVQ_ID, abs_index(vf, vf_evq),
  525. FRF_AZ_RX_DESCQ_LABEL, label,
  526. FRF_AZ_RX_DESCQ_SIZE, __ffs(buf_count),
  527. FRF_AZ_RX_DESCQ_JUMBO,
  528. !!(req->u.init_rxq.flags &
  529. VFDI_RXQ_FLAG_SCATTER_EN),
  530. FRF_AZ_RX_DESCQ_EN, 1);
  531. efx_writeo_table(efx, &reg, FR_BZ_RX_DESC_PTR_TBL,
  532. abs_index(vf, vf_rxq));
  533. return VFDI_RC_SUCCESS;
  534. }
  535. static int efx_vfdi_init_txq(struct efx_vf *vf)
  536. {
  537. struct efx_nic *efx = vf->efx;
  538. struct vfdi_req *req = vf->buf.addr;
  539. unsigned vf_txq = req->u.init_txq.index;
  540. unsigned vf_evq = req->u.init_txq.evq;
  541. unsigned buf_count = req->u.init_txq.buf_count;
  542. unsigned buftbl = EFX_BUFTBL_TXQ_BASE(vf, vf_txq);
  543. unsigned label, eth_filt_en;
  544. efx_oword_t reg;
  545. if (bad_vf_index(efx, vf_evq) || bad_vf_index(efx, vf_txq) ||
  546. vf_txq >= vf_max_tx_channels ||
  547. bad_buf_count(buf_count, EFX_MAX_DMAQ_SIZE)) {
  548. if (net_ratelimit())
  549. netif_err(efx, hw, efx->net_dev,
  550. "ERROR: Invalid INIT_TXQ from %s: txq %d evq %d "
  551. "buf_count %d\n", vf->pci_name, vf_txq,
  552. vf_evq, buf_count);
  553. return VFDI_RC_EINVAL;
  554. }
  555. mutex_lock(&vf->txq_lock);
  556. if (__test_and_set_bit(req->u.init_txq.index, vf->txq_mask))
  557. ++vf->txq_count;
  558. mutex_unlock(&vf->txq_lock);
  559. efx_sriov_bufs(efx, buftbl, req->u.init_txq.addr, buf_count);
  560. eth_filt_en = vf->tx_filter_mode == VF_TX_FILTER_ON;
  561. label = req->u.init_txq.label & EFX_FIELD_MASK(FRF_AZ_TX_DESCQ_LABEL);
  562. EFX_POPULATE_OWORD_8(reg,
  563. FRF_CZ_TX_DPT_Q_MASK_WIDTH, min(efx->vi_scale, 1U),
  564. FRF_CZ_TX_DPT_ETH_FILT_EN, eth_filt_en,
  565. FRF_AZ_TX_DESCQ_EN, 1,
  566. FRF_AZ_TX_DESCQ_BUF_BASE_ID, buftbl,
  567. FRF_AZ_TX_DESCQ_EVQ_ID, abs_index(vf, vf_evq),
  568. FRF_AZ_TX_DESCQ_LABEL, label,
  569. FRF_AZ_TX_DESCQ_SIZE, __ffs(buf_count),
  570. FRF_BZ_TX_NON_IP_DROP_DIS, 1);
  571. efx_writeo_table(efx, &reg, FR_BZ_TX_DESC_PTR_TBL,
  572. abs_index(vf, vf_txq));
  573. return VFDI_RC_SUCCESS;
  574. }
  575. /* Returns true when efx_vfdi_fini_all_queues should wake */
  576. static bool efx_vfdi_flush_wake(struct efx_vf *vf)
  577. {
  578. /* Ensure that all updates are visible to efx_vfdi_fini_all_queues() */
  579. smp_mb();
  580. return (!vf->txq_count && !vf->rxq_count) ||
  581. atomic_read(&vf->rxq_retry_count);
  582. }
  583. static void efx_vfdi_flush_clear(struct efx_vf *vf)
  584. {
  585. memset(vf->txq_mask, 0, sizeof(vf->txq_mask));
  586. vf->txq_count = 0;
  587. memset(vf->rxq_mask, 0, sizeof(vf->rxq_mask));
  588. vf->rxq_count = 0;
  589. memset(vf->rxq_retry_mask, 0, sizeof(vf->rxq_retry_mask));
  590. atomic_set(&vf->rxq_retry_count, 0);
  591. }
  592. static int efx_vfdi_fini_all_queues(struct efx_vf *vf)
  593. {
  594. struct efx_nic *efx = vf->efx;
  595. efx_oword_t reg;
  596. unsigned count = efx_vf_size(efx);
  597. unsigned vf_offset = EFX_VI_BASE + vf->index * efx_vf_size(efx);
  598. unsigned timeout = HZ;
  599. unsigned index, rxqs_count;
  600. MCDI_DECLARE_BUF(inbuf, MC_CMD_FLUSH_RX_QUEUES_IN_LENMAX);
  601. int rc;
  602. BUILD_BUG_ON(VF_MAX_RX_QUEUES >
  603. MC_CMD_FLUSH_RX_QUEUES_IN_QID_OFST_MAXNUM);
  604. rtnl_lock();
  605. siena_prepare_flush(efx);
  606. rtnl_unlock();
  607. /* Flush all the initialized queues */
  608. rxqs_count = 0;
  609. for (index = 0; index < count; ++index) {
  610. if (test_bit(index, vf->txq_mask)) {
  611. EFX_POPULATE_OWORD_2(reg,
  612. FRF_AZ_TX_FLUSH_DESCQ_CMD, 1,
  613. FRF_AZ_TX_FLUSH_DESCQ,
  614. vf_offset + index);
  615. efx_writeo(efx, &reg, FR_AZ_TX_FLUSH_DESCQ);
  616. }
  617. if (test_bit(index, vf->rxq_mask)) {
  618. MCDI_SET_ARRAY_DWORD(
  619. inbuf, FLUSH_RX_QUEUES_IN_QID_OFST,
  620. rxqs_count, vf_offset + index);
  621. rxqs_count++;
  622. }
  623. }
  624. atomic_set(&vf->rxq_retry_count, 0);
  625. while (timeout && (vf->rxq_count || vf->txq_count)) {
  626. rc = efx_mcdi_rpc(efx, MC_CMD_FLUSH_RX_QUEUES, inbuf,
  627. MC_CMD_FLUSH_RX_QUEUES_IN_LEN(rxqs_count),
  628. NULL, 0, NULL);
  629. WARN_ON(rc < 0);
  630. timeout = wait_event_timeout(vf->flush_waitq,
  631. efx_vfdi_flush_wake(vf),
  632. timeout);
  633. rxqs_count = 0;
  634. for (index = 0; index < count; ++index) {
  635. if (test_and_clear_bit(index, vf->rxq_retry_mask)) {
  636. atomic_dec(&vf->rxq_retry_count);
  637. MCDI_SET_ARRAY_DWORD(
  638. inbuf, FLUSH_RX_QUEUES_IN_QID_OFST,
  639. rxqs_count, vf_offset + index);
  640. rxqs_count++;
  641. }
  642. }
  643. }
  644. rtnl_lock();
  645. siena_finish_flush(efx);
  646. rtnl_unlock();
  647. /* Irrespective of success/failure, fini the queues */
  648. EFX_ZERO_OWORD(reg);
  649. for (index = 0; index < count; ++index) {
  650. efx_writeo_table(efx, &reg, FR_BZ_RX_DESC_PTR_TBL,
  651. vf_offset + index);
  652. efx_writeo_table(efx, &reg, FR_BZ_TX_DESC_PTR_TBL,
  653. vf_offset + index);
  654. efx_writeo_table(efx, &reg, FR_BZ_EVQ_PTR_TBL,
  655. vf_offset + index);
  656. efx_writeo_table(efx, &reg, FR_BZ_TIMER_TBL,
  657. vf_offset + index);
  658. }
  659. efx_sriov_bufs(efx, vf->buftbl_base, NULL,
  660. EFX_VF_BUFTBL_PER_VI * efx_vf_size(efx));
  661. efx_vfdi_flush_clear(vf);
  662. vf->evq0_count = 0;
  663. return timeout ? 0 : VFDI_RC_ETIMEDOUT;
  664. }
  665. static int efx_vfdi_insert_filter(struct efx_vf *vf)
  666. {
  667. struct efx_nic *efx = vf->efx;
  668. struct vfdi_req *req = vf->buf.addr;
  669. unsigned vf_rxq = req->u.mac_filter.rxq;
  670. unsigned flags;
  671. if (bad_vf_index(efx, vf_rxq) || vf->rx_filtering) {
  672. if (net_ratelimit())
  673. netif_err(efx, hw, efx->net_dev,
  674. "ERROR: Invalid INSERT_FILTER from %s: rxq %d "
  675. "flags 0x%x\n", vf->pci_name, vf_rxq,
  676. req->u.mac_filter.flags);
  677. return VFDI_RC_EINVAL;
  678. }
  679. flags = 0;
  680. if (req->u.mac_filter.flags & VFDI_MAC_FILTER_FLAG_RSS)
  681. flags |= EFX_FILTER_FLAG_RX_RSS;
  682. if (req->u.mac_filter.flags & VFDI_MAC_FILTER_FLAG_SCATTER)
  683. flags |= EFX_FILTER_FLAG_RX_SCATTER;
  684. vf->rx_filter_flags = flags;
  685. vf->rx_filter_qid = vf_rxq;
  686. vf->rx_filtering = true;
  687. efx_sriov_reset_rx_filter(vf);
  688. queue_work(vfdi_workqueue, &efx->peer_work);
  689. return VFDI_RC_SUCCESS;
  690. }
  691. static int efx_vfdi_remove_all_filters(struct efx_vf *vf)
  692. {
  693. vf->rx_filtering = false;
  694. efx_sriov_reset_rx_filter(vf);
  695. queue_work(vfdi_workqueue, &vf->efx->peer_work);
  696. return VFDI_RC_SUCCESS;
  697. }
  698. static int efx_vfdi_set_status_page(struct efx_vf *vf)
  699. {
  700. struct efx_nic *efx = vf->efx;
  701. struct vfdi_req *req = vf->buf.addr;
  702. u64 page_count = req->u.set_status_page.peer_page_count;
  703. u64 max_page_count =
  704. (EFX_PAGE_SIZE -
  705. offsetof(struct vfdi_req, u.set_status_page.peer_page_addr[0]))
  706. / sizeof(req->u.set_status_page.peer_page_addr[0]);
  707. if (!req->u.set_status_page.dma_addr || page_count > max_page_count) {
  708. if (net_ratelimit())
  709. netif_err(efx, hw, efx->net_dev,
  710. "ERROR: Invalid SET_STATUS_PAGE from %s\n",
  711. vf->pci_name);
  712. return VFDI_RC_EINVAL;
  713. }
  714. mutex_lock(&efx->local_lock);
  715. mutex_lock(&vf->status_lock);
  716. vf->status_addr = req->u.set_status_page.dma_addr;
  717. kfree(vf->peer_page_addrs);
  718. vf->peer_page_addrs = NULL;
  719. vf->peer_page_count = 0;
  720. if (page_count) {
  721. vf->peer_page_addrs = kcalloc(page_count, sizeof(u64),
  722. GFP_KERNEL);
  723. if (vf->peer_page_addrs) {
  724. memcpy(vf->peer_page_addrs,
  725. req->u.set_status_page.peer_page_addr,
  726. page_count * sizeof(u64));
  727. vf->peer_page_count = page_count;
  728. }
  729. }
  730. __efx_sriov_push_vf_status(vf);
  731. mutex_unlock(&vf->status_lock);
  732. mutex_unlock(&efx->local_lock);
  733. return VFDI_RC_SUCCESS;
  734. }
  735. static int efx_vfdi_clear_status_page(struct efx_vf *vf)
  736. {
  737. mutex_lock(&vf->status_lock);
  738. vf->status_addr = 0;
  739. mutex_unlock(&vf->status_lock);
  740. return VFDI_RC_SUCCESS;
  741. }
  742. typedef int (*efx_vfdi_op_t)(struct efx_vf *vf);
  743. static const efx_vfdi_op_t vfdi_ops[VFDI_OP_LIMIT] = {
  744. [VFDI_OP_INIT_EVQ] = efx_vfdi_init_evq,
  745. [VFDI_OP_INIT_TXQ] = efx_vfdi_init_txq,
  746. [VFDI_OP_INIT_RXQ] = efx_vfdi_init_rxq,
  747. [VFDI_OP_FINI_ALL_QUEUES] = efx_vfdi_fini_all_queues,
  748. [VFDI_OP_INSERT_FILTER] = efx_vfdi_insert_filter,
  749. [VFDI_OP_REMOVE_ALL_FILTERS] = efx_vfdi_remove_all_filters,
  750. [VFDI_OP_SET_STATUS_PAGE] = efx_vfdi_set_status_page,
  751. [VFDI_OP_CLEAR_STATUS_PAGE] = efx_vfdi_clear_status_page,
  752. };
  753. static void efx_sriov_vfdi(struct work_struct *work)
  754. {
  755. struct efx_vf *vf = container_of(work, struct efx_vf, req);
  756. struct efx_nic *efx = vf->efx;
  757. struct vfdi_req *req = vf->buf.addr;
  758. struct efx_memcpy_req copy[2];
  759. int rc;
  760. /* Copy this page into the local address space */
  761. memset(copy, '\0', sizeof(copy));
  762. copy[0].from_rid = vf->pci_rid;
  763. copy[0].from_addr = vf->req_addr;
  764. copy[0].to_rid = efx->pci_dev->devfn;
  765. copy[0].to_addr = vf->buf.dma_addr;
  766. copy[0].length = EFX_PAGE_SIZE;
  767. rc = efx_sriov_memcpy(efx, copy, 1);
  768. if (rc) {
  769. /* If we can't get the request, we can't reply to the caller */
  770. if (net_ratelimit())
  771. netif_err(efx, hw, efx->net_dev,
  772. "ERROR: Unable to fetch VFDI request from %s rc %d\n",
  773. vf->pci_name, -rc);
  774. vf->busy = false;
  775. return;
  776. }
  777. if (req->op < VFDI_OP_LIMIT && vfdi_ops[req->op] != NULL) {
  778. rc = vfdi_ops[req->op](vf);
  779. if (rc == 0) {
  780. netif_dbg(efx, hw, efx->net_dev,
  781. "vfdi request %d from %s ok\n",
  782. req->op, vf->pci_name);
  783. }
  784. } else {
  785. netif_dbg(efx, hw, efx->net_dev,
  786. "ERROR: Unrecognised request %d from VF %s addr "
  787. "%llx\n", req->op, vf->pci_name,
  788. (unsigned long long)vf->req_addr);
  789. rc = VFDI_RC_EOPNOTSUPP;
  790. }
  791. /* Allow subsequent VF requests */
  792. vf->busy = false;
  793. smp_wmb();
  794. /* Respond to the request */
  795. req->rc = rc;
  796. req->op = VFDI_OP_RESPONSE;
  797. memset(copy, '\0', sizeof(copy));
  798. copy[0].from_buf = &req->rc;
  799. copy[0].to_rid = vf->pci_rid;
  800. copy[0].to_addr = vf->req_addr + offsetof(struct vfdi_req, rc);
  801. copy[0].length = sizeof(req->rc);
  802. copy[1].from_buf = &req->op;
  803. copy[1].to_rid = vf->pci_rid;
  804. copy[1].to_addr = vf->req_addr + offsetof(struct vfdi_req, op);
  805. copy[1].length = sizeof(req->op);
  806. (void) efx_sriov_memcpy(efx, copy, ARRAY_SIZE(copy));
  807. }
  808. /* After a reset the event queues inside the guests no longer exist. Fill the
  809. * event ring in guest memory with VFDI reset events, then (re-initialise) the
  810. * event queue to raise an interrupt. The guest driver will then recover.
  811. */
  812. static void efx_sriov_reset_vf(struct efx_vf *vf, struct efx_buffer *buffer)
  813. {
  814. struct efx_nic *efx = vf->efx;
  815. struct efx_memcpy_req copy_req[4];
  816. efx_qword_t event;
  817. unsigned int pos, count, k, buftbl, abs_evq;
  818. efx_oword_t reg;
  819. efx_dword_t ptr;
  820. int rc;
  821. BUG_ON(buffer->len != EFX_PAGE_SIZE);
  822. if (!vf->evq0_count)
  823. return;
  824. BUG_ON(vf->evq0_count & (vf->evq0_count - 1));
  825. mutex_lock(&vf->status_lock);
  826. EFX_POPULATE_QWORD_3(event,
  827. FSF_AZ_EV_CODE, FSE_CZ_EV_CODE_USER_EV,
  828. VFDI_EV_SEQ, vf->msg_seqno,
  829. VFDI_EV_TYPE, VFDI_EV_TYPE_RESET);
  830. vf->msg_seqno++;
  831. for (pos = 0; pos < EFX_PAGE_SIZE; pos += sizeof(event))
  832. memcpy(buffer->addr + pos, &event, sizeof(event));
  833. for (pos = 0; pos < vf->evq0_count; pos += count) {
  834. count = min_t(unsigned, vf->evq0_count - pos,
  835. ARRAY_SIZE(copy_req));
  836. for (k = 0; k < count; k++) {
  837. copy_req[k].from_buf = NULL;
  838. copy_req[k].from_rid = efx->pci_dev->devfn;
  839. copy_req[k].from_addr = buffer->dma_addr;
  840. copy_req[k].to_rid = vf->pci_rid;
  841. copy_req[k].to_addr = vf->evq0_addrs[pos + k];
  842. copy_req[k].length = EFX_PAGE_SIZE;
  843. }
  844. rc = efx_sriov_memcpy(efx, copy_req, count);
  845. if (rc) {
  846. if (net_ratelimit())
  847. netif_err(efx, hw, efx->net_dev,
  848. "ERROR: Unable to notify %s of reset"
  849. ": %d\n", vf->pci_name, -rc);
  850. break;
  851. }
  852. }
  853. /* Reinitialise, arm and trigger evq0 */
  854. abs_evq = abs_index(vf, 0);
  855. buftbl = EFX_BUFTBL_EVQ_BASE(vf, 0);
  856. efx_sriov_bufs(efx, buftbl, vf->evq0_addrs, vf->evq0_count);
  857. EFX_POPULATE_OWORD_3(reg,
  858. FRF_CZ_TIMER_Q_EN, 1,
  859. FRF_CZ_HOST_NOTIFY_MODE, 0,
  860. FRF_CZ_TIMER_MODE, FFE_CZ_TIMER_MODE_DIS);
  861. efx_writeo_table(efx, &reg, FR_BZ_TIMER_TBL, abs_evq);
  862. EFX_POPULATE_OWORD_3(reg,
  863. FRF_AZ_EVQ_EN, 1,
  864. FRF_AZ_EVQ_SIZE, __ffs(vf->evq0_count),
  865. FRF_AZ_EVQ_BUF_BASE_ID, buftbl);
  866. efx_writeo_table(efx, &reg, FR_BZ_EVQ_PTR_TBL, abs_evq);
  867. EFX_POPULATE_DWORD_1(ptr, FRF_AZ_EVQ_RPTR, 0);
  868. efx_writed(efx, &ptr, FR_BZ_EVQ_RPTR + FR_BZ_EVQ_RPTR_STEP * abs_evq);
  869. mutex_unlock(&vf->status_lock);
  870. }
  871. static void efx_sriov_reset_vf_work(struct work_struct *work)
  872. {
  873. struct efx_vf *vf = container_of(work, struct efx_vf, req);
  874. struct efx_nic *efx = vf->efx;
  875. struct efx_buffer buf;
  876. if (!efx_nic_alloc_buffer(efx, &buf, EFX_PAGE_SIZE, GFP_NOIO)) {
  877. efx_sriov_reset_vf(vf, &buf);
  878. efx_nic_free_buffer(efx, &buf);
  879. }
  880. }
  881. static void efx_sriov_handle_no_channel(struct efx_nic *efx)
  882. {
  883. netif_err(efx, drv, efx->net_dev,
  884. "ERROR: IOV requires MSI-X and 1 additional interrupt"
  885. "vector. IOV disabled\n");
  886. efx->vf_count = 0;
  887. }
  888. static int efx_sriov_probe_channel(struct efx_channel *channel)
  889. {
  890. channel->efx->vfdi_channel = channel;
  891. return 0;
  892. }
  893. static void
  894. efx_sriov_get_channel_name(struct efx_channel *channel, char *buf, size_t len)
  895. {
  896. snprintf(buf, len, "%s-iov", channel->efx->name);
  897. }
  898. static const struct efx_channel_type efx_sriov_channel_type = {
  899. .handle_no_channel = efx_sriov_handle_no_channel,
  900. .pre_probe = efx_sriov_probe_channel,
  901. .post_remove = efx_channel_dummy_op_void,
  902. .get_name = efx_sriov_get_channel_name,
  903. /* no copy operation; channel must not be reallocated */
  904. .keep_eventq = true,
  905. };
  906. void efx_sriov_probe(struct efx_nic *efx)
  907. {
  908. unsigned count;
  909. if (!max_vfs)
  910. return;
  911. if (efx_sriov_cmd(efx, false, &efx->vi_scale, &count))
  912. return;
  913. if (count > 0 && count > max_vfs)
  914. count = max_vfs;
  915. /* efx_nic_dimension_resources() will reduce vf_count as appopriate */
  916. efx->vf_count = count;
  917. efx->extra_channel_type[EFX_EXTRA_CHANNEL_IOV] = &efx_sriov_channel_type;
  918. }
  919. /* Copy the list of individual addresses into the vfdi_status.peers
  920. * array and auxillary pages, protected by %local_lock. Drop that lock
  921. * and then broadcast the address list to every VF.
  922. */
  923. static void efx_sriov_peer_work(struct work_struct *data)
  924. {
  925. struct efx_nic *efx = container_of(data, struct efx_nic, peer_work);
  926. struct vfdi_status *vfdi_status = efx->vfdi_status.addr;
  927. struct efx_vf *vf;
  928. struct efx_local_addr *local_addr;
  929. struct vfdi_endpoint *peer;
  930. struct efx_endpoint_page *epp;
  931. struct list_head pages;
  932. unsigned int peer_space;
  933. unsigned int peer_count;
  934. unsigned int pos;
  935. mutex_lock(&efx->local_lock);
  936. /* Move the existing peer pages off %local_page_list */
  937. INIT_LIST_HEAD(&pages);
  938. list_splice_tail_init(&efx->local_page_list, &pages);
  939. /* Populate the VF addresses starting from entry 1 (entry 0 is
  940. * the PF address)
  941. */
  942. peer = vfdi_status->peers + 1;
  943. peer_space = ARRAY_SIZE(vfdi_status->peers) - 1;
  944. peer_count = 1;
  945. for (pos = 0; pos < efx->vf_count; ++pos) {
  946. vf = efx->vf + pos;
  947. mutex_lock(&vf->status_lock);
  948. if (vf->rx_filtering && !is_zero_ether_addr(vf->addr.mac_addr)) {
  949. *peer++ = vf->addr;
  950. ++peer_count;
  951. --peer_space;
  952. BUG_ON(peer_space == 0);
  953. }
  954. mutex_unlock(&vf->status_lock);
  955. }
  956. /* Fill the remaining addresses */
  957. list_for_each_entry(local_addr, &efx->local_addr_list, link) {
  958. memcpy(peer->mac_addr, local_addr->addr, ETH_ALEN);
  959. peer->tci = 0;
  960. ++peer;
  961. ++peer_count;
  962. if (--peer_space == 0) {
  963. if (list_empty(&pages)) {
  964. epp = kmalloc(sizeof(*epp), GFP_KERNEL);
  965. if (!epp)
  966. break;
  967. epp->ptr = dma_alloc_coherent(
  968. &efx->pci_dev->dev, EFX_PAGE_SIZE,
  969. &epp->addr, GFP_KERNEL);
  970. if (!epp->ptr) {
  971. kfree(epp);
  972. break;
  973. }
  974. } else {
  975. epp = list_first_entry(
  976. &pages, struct efx_endpoint_page, link);
  977. list_del(&epp->link);
  978. }
  979. list_add_tail(&epp->link, &efx->local_page_list);
  980. peer = (struct vfdi_endpoint *)epp->ptr;
  981. peer_space = EFX_PAGE_SIZE / sizeof(struct vfdi_endpoint);
  982. }
  983. }
  984. vfdi_status->peer_count = peer_count;
  985. mutex_unlock(&efx->local_lock);
  986. /* Free any now unused endpoint pages */
  987. while (!list_empty(&pages)) {
  988. epp = list_first_entry(
  989. &pages, struct efx_endpoint_page, link);
  990. list_del(&epp->link);
  991. dma_free_coherent(&efx->pci_dev->dev, EFX_PAGE_SIZE,
  992. epp->ptr, epp->addr);
  993. kfree(epp);
  994. }
  995. /* Finally, push the pages */
  996. for (pos = 0; pos < efx->vf_count; ++pos) {
  997. vf = efx->vf + pos;
  998. mutex_lock(&vf->status_lock);
  999. if (vf->status_addr)
  1000. __efx_sriov_push_vf_status(vf);
  1001. mutex_unlock(&vf->status_lock);
  1002. }
  1003. }
  1004. static void efx_sriov_free_local(struct efx_nic *efx)
  1005. {
  1006. struct efx_local_addr *local_addr;
  1007. struct efx_endpoint_page *epp;
  1008. while (!list_empty(&efx->local_addr_list)) {
  1009. local_addr = list_first_entry(&efx->local_addr_list,
  1010. struct efx_local_addr, link);
  1011. list_del(&local_addr->link);
  1012. kfree(local_addr);
  1013. }
  1014. while (!list_empty(&efx->local_page_list)) {
  1015. epp = list_first_entry(&efx->local_page_list,
  1016. struct efx_endpoint_page, link);
  1017. list_del(&epp->link);
  1018. dma_free_coherent(&efx->pci_dev->dev, EFX_PAGE_SIZE,
  1019. epp->ptr, epp->addr);
  1020. kfree(epp);
  1021. }
  1022. }
  1023. static int efx_sriov_vf_alloc(struct efx_nic *efx)
  1024. {
  1025. unsigned index;
  1026. struct efx_vf *vf;
  1027. efx->vf = kzalloc(sizeof(struct efx_vf) * efx->vf_count, GFP_KERNEL);
  1028. if (!efx->vf)
  1029. return -ENOMEM;
  1030. for (index = 0; index < efx->vf_count; ++index) {
  1031. vf = efx->vf + index;
  1032. vf->efx = efx;
  1033. vf->index = index;
  1034. vf->rx_filter_id = -1;
  1035. vf->tx_filter_mode = VF_TX_FILTER_AUTO;
  1036. vf->tx_filter_id = -1;
  1037. INIT_WORK(&vf->req, efx_sriov_vfdi);
  1038. INIT_WORK(&vf->reset_work, efx_sriov_reset_vf_work);
  1039. init_waitqueue_head(&vf->flush_waitq);
  1040. mutex_init(&vf->status_lock);
  1041. mutex_init(&vf->txq_lock);
  1042. }
  1043. return 0;
  1044. }
  1045. static void efx_sriov_vfs_fini(struct efx_nic *efx)
  1046. {
  1047. struct efx_vf *vf;
  1048. unsigned int pos;
  1049. for (pos = 0; pos < efx->vf_count; ++pos) {
  1050. vf = efx->vf + pos;
  1051. efx_nic_free_buffer(efx, &vf->buf);
  1052. kfree(vf->peer_page_addrs);
  1053. vf->peer_page_addrs = NULL;
  1054. vf->peer_page_count = 0;
  1055. vf->evq0_count = 0;
  1056. }
  1057. }
  1058. static int efx_sriov_vfs_init(struct efx_nic *efx)
  1059. {
  1060. struct pci_dev *pci_dev = efx->pci_dev;
  1061. unsigned index, devfn, sriov, buftbl_base;
  1062. u16 offset, stride;
  1063. struct efx_vf *vf;
  1064. int rc;
  1065. sriov = pci_find_ext_capability(pci_dev, PCI_EXT_CAP_ID_SRIOV);
  1066. if (!sriov)
  1067. return -ENOENT;
  1068. pci_read_config_word(pci_dev, sriov + PCI_SRIOV_VF_OFFSET, &offset);
  1069. pci_read_config_word(pci_dev, sriov + PCI_SRIOV_VF_STRIDE, &stride);
  1070. buftbl_base = efx->vf_buftbl_base;
  1071. devfn = pci_dev->devfn + offset;
  1072. for (index = 0; index < efx->vf_count; ++index) {
  1073. vf = efx->vf + index;
  1074. /* Reserve buffer entries */
  1075. vf->buftbl_base = buftbl_base;
  1076. buftbl_base += EFX_VF_BUFTBL_PER_VI * efx_vf_size(efx);
  1077. vf->pci_rid = devfn;
  1078. snprintf(vf->pci_name, sizeof(vf->pci_name),
  1079. "%04x:%02x:%02x.%d",
  1080. pci_domain_nr(pci_dev->bus), pci_dev->bus->number,
  1081. PCI_SLOT(devfn), PCI_FUNC(devfn));
  1082. rc = efx_nic_alloc_buffer(efx, &vf->buf, EFX_PAGE_SIZE,
  1083. GFP_KERNEL);
  1084. if (rc)
  1085. goto fail;
  1086. devfn += stride;
  1087. }
  1088. return 0;
  1089. fail:
  1090. efx_sriov_vfs_fini(efx);
  1091. return rc;
  1092. }
  1093. int efx_sriov_init(struct efx_nic *efx)
  1094. {
  1095. struct net_device *net_dev = efx->net_dev;
  1096. struct vfdi_status *vfdi_status;
  1097. int rc;
  1098. /* Ensure there's room for vf_channel */
  1099. BUILD_BUG_ON(EFX_MAX_CHANNELS + 1 >= EFX_VI_BASE);
  1100. /* Ensure that VI_BASE is aligned on VI_SCALE */
  1101. BUILD_BUG_ON(EFX_VI_BASE & ((1 << EFX_VI_SCALE_MAX) - 1));
  1102. if (efx->vf_count == 0)
  1103. return 0;
  1104. rc = efx_sriov_cmd(efx, true, NULL, NULL);
  1105. if (rc)
  1106. goto fail_cmd;
  1107. rc = efx_nic_alloc_buffer(efx, &efx->vfdi_status, sizeof(*vfdi_status),
  1108. GFP_KERNEL);
  1109. if (rc)
  1110. goto fail_status;
  1111. vfdi_status = efx->vfdi_status.addr;
  1112. memset(vfdi_status, 0, sizeof(*vfdi_status));
  1113. vfdi_status->version = 1;
  1114. vfdi_status->length = sizeof(*vfdi_status);
  1115. vfdi_status->max_tx_channels = vf_max_tx_channels;
  1116. vfdi_status->vi_scale = efx->vi_scale;
  1117. vfdi_status->rss_rxq_count = efx->rss_spread;
  1118. vfdi_status->peer_count = 1 + efx->vf_count;
  1119. vfdi_status->timer_quantum_ns = efx->timer_quantum_ns;
  1120. rc = efx_sriov_vf_alloc(efx);
  1121. if (rc)
  1122. goto fail_alloc;
  1123. mutex_init(&efx->local_lock);
  1124. INIT_WORK(&efx->peer_work, efx_sriov_peer_work);
  1125. INIT_LIST_HEAD(&efx->local_addr_list);
  1126. INIT_LIST_HEAD(&efx->local_page_list);
  1127. rc = efx_sriov_vfs_init(efx);
  1128. if (rc)
  1129. goto fail_vfs;
  1130. rtnl_lock();
  1131. memcpy(vfdi_status->peers[0].mac_addr,
  1132. net_dev->dev_addr, ETH_ALEN);
  1133. efx->vf_init_count = efx->vf_count;
  1134. rtnl_unlock();
  1135. efx_sriov_usrev(efx, true);
  1136. /* At this point we must be ready to accept VFDI requests */
  1137. rc = pci_enable_sriov(efx->pci_dev, efx->vf_count);
  1138. if (rc)
  1139. goto fail_pci;
  1140. netif_info(efx, probe, net_dev,
  1141. "enabled SR-IOV for %d VFs, %d VI per VF\n",
  1142. efx->vf_count, efx_vf_size(efx));
  1143. return 0;
  1144. fail_pci:
  1145. efx_sriov_usrev(efx, false);
  1146. rtnl_lock();
  1147. efx->vf_init_count = 0;
  1148. rtnl_unlock();
  1149. efx_sriov_vfs_fini(efx);
  1150. fail_vfs:
  1151. cancel_work_sync(&efx->peer_work);
  1152. efx_sriov_free_local(efx);
  1153. kfree(efx->vf);
  1154. fail_alloc:
  1155. efx_nic_free_buffer(efx, &efx->vfdi_status);
  1156. fail_status:
  1157. efx_sriov_cmd(efx, false, NULL, NULL);
  1158. fail_cmd:
  1159. return rc;
  1160. }
  1161. void efx_sriov_fini(struct efx_nic *efx)
  1162. {
  1163. struct efx_vf *vf;
  1164. unsigned int pos;
  1165. if (efx->vf_init_count == 0)
  1166. return;
  1167. /* Disable all interfaces to reconfiguration */
  1168. BUG_ON(efx->vfdi_channel->enabled);
  1169. efx_sriov_usrev(efx, false);
  1170. rtnl_lock();
  1171. efx->vf_init_count = 0;
  1172. rtnl_unlock();
  1173. /* Flush all reconfiguration work */
  1174. for (pos = 0; pos < efx->vf_count; ++pos) {
  1175. vf = efx->vf + pos;
  1176. cancel_work_sync(&vf->req);
  1177. cancel_work_sync(&vf->reset_work);
  1178. }
  1179. cancel_work_sync(&efx->peer_work);
  1180. pci_disable_sriov(efx->pci_dev);
  1181. /* Tear down back-end state */
  1182. efx_sriov_vfs_fini(efx);
  1183. efx_sriov_free_local(efx);
  1184. kfree(efx->vf);
  1185. efx_nic_free_buffer(efx, &efx->vfdi_status);
  1186. efx_sriov_cmd(efx, false, NULL, NULL);
  1187. }
  1188. void efx_sriov_event(struct efx_channel *channel, efx_qword_t *event)
  1189. {
  1190. struct efx_nic *efx = channel->efx;
  1191. struct efx_vf *vf;
  1192. unsigned qid, seq, type, data;
  1193. qid = EFX_QWORD_FIELD(*event, FSF_CZ_USER_QID);
  1194. /* USR_EV_REG_VALUE is dword0, so access the VFDI_EV fields directly */
  1195. BUILD_BUG_ON(FSF_CZ_USER_EV_REG_VALUE_LBN != 0);
  1196. seq = EFX_QWORD_FIELD(*event, VFDI_EV_SEQ);
  1197. type = EFX_QWORD_FIELD(*event, VFDI_EV_TYPE);
  1198. data = EFX_QWORD_FIELD(*event, VFDI_EV_DATA);
  1199. netif_vdbg(efx, hw, efx->net_dev,
  1200. "USR_EV event from qid %d seq 0x%x type %d data 0x%x\n",
  1201. qid, seq, type, data);
  1202. if (map_vi_index(efx, qid, &vf, NULL))
  1203. return;
  1204. if (vf->busy)
  1205. goto error;
  1206. if (type == VFDI_EV_TYPE_REQ_WORD0) {
  1207. /* Resynchronise */
  1208. vf->req_type = VFDI_EV_TYPE_REQ_WORD0;
  1209. vf->req_seqno = seq + 1;
  1210. vf->req_addr = 0;
  1211. } else if (seq != (vf->req_seqno++ & 0xff) || type != vf->req_type)
  1212. goto error;
  1213. switch (vf->req_type) {
  1214. case VFDI_EV_TYPE_REQ_WORD0:
  1215. case VFDI_EV_TYPE_REQ_WORD1:
  1216. case VFDI_EV_TYPE_REQ_WORD2:
  1217. vf->req_addr |= (u64)data << (vf->req_type << 4);
  1218. ++vf->req_type;
  1219. return;
  1220. case VFDI_EV_TYPE_REQ_WORD3:
  1221. vf->req_addr |= (u64)data << 48;
  1222. vf->req_type = VFDI_EV_TYPE_REQ_WORD0;
  1223. vf->busy = true;
  1224. queue_work(vfdi_workqueue, &vf->req);
  1225. return;
  1226. }
  1227. error:
  1228. if (net_ratelimit())
  1229. netif_err(efx, hw, efx->net_dev,
  1230. "ERROR: Screaming VFDI request from %s\n",
  1231. vf->pci_name);
  1232. /* Reset the request and sequence number */
  1233. vf->req_type = VFDI_EV_TYPE_REQ_WORD0;
  1234. vf->req_seqno = seq + 1;
  1235. }
  1236. void efx_sriov_flr(struct efx_nic *efx, unsigned vf_i)
  1237. {
  1238. struct efx_vf *vf;
  1239. if (vf_i > efx->vf_init_count)
  1240. return;
  1241. vf = efx->vf + vf_i;
  1242. netif_info(efx, hw, efx->net_dev,
  1243. "FLR on VF %s\n", vf->pci_name);
  1244. vf->status_addr = 0;
  1245. efx_vfdi_remove_all_filters(vf);
  1246. efx_vfdi_flush_clear(vf);
  1247. vf->evq0_count = 0;
  1248. }
  1249. void efx_sriov_mac_address_changed(struct efx_nic *efx)
  1250. {
  1251. struct vfdi_status *vfdi_status = efx->vfdi_status.addr;
  1252. if (!efx->vf_init_count)
  1253. return;
  1254. memcpy(vfdi_status->peers[0].mac_addr,
  1255. efx->net_dev->dev_addr, ETH_ALEN);
  1256. queue_work(vfdi_workqueue, &efx->peer_work);
  1257. }
  1258. void efx_sriov_tx_flush_done(struct efx_nic *efx, efx_qword_t *event)
  1259. {
  1260. struct efx_vf *vf;
  1261. unsigned queue, qid;
  1262. queue = EFX_QWORD_FIELD(*event, FSF_AZ_DRIVER_EV_SUBDATA);
  1263. if (map_vi_index(efx, queue, &vf, &qid))
  1264. return;
  1265. /* Ignore flush completions triggered by an FLR */
  1266. if (!test_bit(qid, vf->txq_mask))
  1267. return;
  1268. __clear_bit(qid, vf->txq_mask);
  1269. --vf->txq_count;
  1270. if (efx_vfdi_flush_wake(vf))
  1271. wake_up(&vf->flush_waitq);
  1272. }
  1273. void efx_sriov_rx_flush_done(struct efx_nic *efx, efx_qword_t *event)
  1274. {
  1275. struct efx_vf *vf;
  1276. unsigned ev_failed, queue, qid;
  1277. queue = EFX_QWORD_FIELD(*event, FSF_AZ_DRIVER_EV_RX_DESCQ_ID);
  1278. ev_failed = EFX_QWORD_FIELD(*event,
  1279. FSF_AZ_DRIVER_EV_RX_FLUSH_FAIL);
  1280. if (map_vi_index(efx, queue, &vf, &qid))
  1281. return;
  1282. if (!test_bit(qid, vf->rxq_mask))
  1283. return;
  1284. if (ev_failed) {
  1285. set_bit(qid, vf->rxq_retry_mask);
  1286. atomic_inc(&vf->rxq_retry_count);
  1287. } else {
  1288. __clear_bit(qid, vf->rxq_mask);
  1289. --vf->rxq_count;
  1290. }
  1291. if (efx_vfdi_flush_wake(vf))
  1292. wake_up(&vf->flush_waitq);
  1293. }
  1294. /* Called from napi. Schedule the reset work item */
  1295. void efx_sriov_desc_fetch_err(struct efx_nic *efx, unsigned dmaq)
  1296. {
  1297. struct efx_vf *vf;
  1298. unsigned int rel;
  1299. if (map_vi_index(efx, dmaq, &vf, &rel))
  1300. return;
  1301. if (net_ratelimit())
  1302. netif_err(efx, hw, efx->net_dev,
  1303. "VF %d DMA Q %d reports descriptor fetch error.\n",
  1304. vf->index, rel);
  1305. queue_work(vfdi_workqueue, &vf->reset_work);
  1306. }
  1307. /* Reset all VFs */
  1308. void efx_sriov_reset(struct efx_nic *efx)
  1309. {
  1310. unsigned int vf_i;
  1311. struct efx_buffer buf;
  1312. struct efx_vf *vf;
  1313. ASSERT_RTNL();
  1314. if (efx->vf_init_count == 0)
  1315. return;
  1316. efx_sriov_usrev(efx, true);
  1317. (void)efx_sriov_cmd(efx, true, NULL, NULL);
  1318. if (efx_nic_alloc_buffer(efx, &buf, EFX_PAGE_SIZE, GFP_NOIO))
  1319. return;
  1320. for (vf_i = 0; vf_i < efx->vf_init_count; ++vf_i) {
  1321. vf = efx->vf + vf_i;
  1322. efx_sriov_reset_vf(vf, &buf);
  1323. }
  1324. efx_nic_free_buffer(efx, &buf);
  1325. }
  1326. int efx_init_sriov(void)
  1327. {
  1328. /* A single threaded workqueue is sufficient. efx_sriov_vfdi() and
  1329. * efx_sriov_peer_work() spend almost all their time sleeping for
  1330. * MCDI to complete anyway
  1331. */
  1332. vfdi_workqueue = create_singlethread_workqueue("sfc_vfdi");
  1333. if (!vfdi_workqueue)
  1334. return -ENOMEM;
  1335. return 0;
  1336. }
  1337. void efx_fini_sriov(void)
  1338. {
  1339. destroy_workqueue(vfdi_workqueue);
  1340. }
  1341. int efx_sriov_set_vf_mac(struct net_device *net_dev, int vf_i, u8 *mac)
  1342. {
  1343. struct efx_nic *efx = netdev_priv(net_dev);
  1344. struct efx_vf *vf;
  1345. if (vf_i >= efx->vf_init_count)
  1346. return -EINVAL;
  1347. vf = efx->vf + vf_i;
  1348. mutex_lock(&vf->status_lock);
  1349. memcpy(vf->addr.mac_addr, mac, ETH_ALEN);
  1350. __efx_sriov_update_vf_addr(vf);
  1351. mutex_unlock(&vf->status_lock);
  1352. return 0;
  1353. }
  1354. int efx_sriov_set_vf_vlan(struct net_device *net_dev, int vf_i,
  1355. u16 vlan, u8 qos)
  1356. {
  1357. struct efx_nic *efx = netdev_priv(net_dev);
  1358. struct efx_vf *vf;
  1359. u16 tci;
  1360. if (vf_i >= efx->vf_init_count)
  1361. return -EINVAL;
  1362. vf = efx->vf + vf_i;
  1363. mutex_lock(&vf->status_lock);
  1364. tci = (vlan & VLAN_VID_MASK) | ((qos & 0x7) << VLAN_PRIO_SHIFT);
  1365. vf->addr.tci = htons(tci);
  1366. __efx_sriov_update_vf_addr(vf);
  1367. mutex_unlock(&vf->status_lock);
  1368. return 0;
  1369. }
  1370. int efx_sriov_set_vf_spoofchk(struct net_device *net_dev, int vf_i,
  1371. bool spoofchk)
  1372. {
  1373. struct efx_nic *efx = netdev_priv(net_dev);
  1374. struct efx_vf *vf;
  1375. int rc;
  1376. if (vf_i >= efx->vf_init_count)
  1377. return -EINVAL;
  1378. vf = efx->vf + vf_i;
  1379. mutex_lock(&vf->txq_lock);
  1380. if (vf->txq_count == 0) {
  1381. vf->tx_filter_mode =
  1382. spoofchk ? VF_TX_FILTER_ON : VF_TX_FILTER_OFF;
  1383. rc = 0;
  1384. } else {
  1385. /* This cannot be changed while TX queues are running */
  1386. rc = -EBUSY;
  1387. }
  1388. mutex_unlock(&vf->txq_lock);
  1389. return rc;
  1390. }
  1391. int efx_sriov_get_vf_config(struct net_device *net_dev, int vf_i,
  1392. struct ifla_vf_info *ivi)
  1393. {
  1394. struct efx_nic *efx = netdev_priv(net_dev);
  1395. struct efx_vf *vf;
  1396. u16 tci;
  1397. if (vf_i >= efx->vf_init_count)
  1398. return -EINVAL;
  1399. vf = efx->vf + vf_i;
  1400. ivi->vf = vf_i;
  1401. memcpy(ivi->mac, vf->addr.mac_addr, ETH_ALEN);
  1402. ivi->tx_rate = 0;
  1403. tci = ntohs(vf->addr.tci);
  1404. ivi->vlan = tci & VLAN_VID_MASK;
  1405. ivi->qos = (tci >> VLAN_PRIO_SHIFT) & 0x7;
  1406. ivi->spoofchk = vf->tx_filter_mode == VF_TX_FILTER_ON;
  1407. return 0;
  1408. }