vf.c 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038
  1. /*******************************************************************************
  2. Intel 82599 Virtual Function driver
  3. Copyright(c) 1999 - 2015 Intel Corporation.
  4. This program is free software; you can redistribute it and/or modify it
  5. under the terms and conditions of the GNU General Public License,
  6. version 2, as published by the Free Software Foundation.
  7. This program is distributed in the hope it will be useful, but WITHOUT
  8. ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  9. FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  10. more details.
  11. You should have received a copy of the GNU General Public License along with
  12. this program; if not, see <http://www.gnu.org/licenses/>.
  13. The full GNU General Public License is included in this distribution in
  14. the file called "COPYING".
  15. Contact Information:
  16. e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
  17. Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
  18. *******************************************************************************/
  19. #include "vf.h"
  20. #include "ixgbevf.h"
  21. /* On Hyper-V, to reset, we need to read from this offset
  22. * from the PCI config space. This is the mechanism used on
  23. * Hyper-V to support PF/VF communication.
  24. */
  25. #define IXGBE_HV_RESET_OFFSET 0x201
  26. static inline s32 ixgbevf_write_msg_read_ack(struct ixgbe_hw *hw, u32 *msg,
  27. u32 *retmsg, u16 size)
  28. {
  29. struct ixgbe_mbx_info *mbx = &hw->mbx;
  30. s32 retval = mbx->ops.write_posted(hw, msg, size);
  31. if (retval)
  32. return retval;
  33. return mbx->ops.read_posted(hw, retmsg, size);
  34. }
  35. /**
  36. * ixgbevf_start_hw_vf - Prepare hardware for Tx/Rx
  37. * @hw: pointer to hardware structure
  38. *
  39. * Starts the hardware by filling the bus info structure and media type, clears
  40. * all on chip counters, initializes receive address registers, multicast
  41. * table, VLAN filter table, calls routine to set up link and flow control
  42. * settings, and leaves transmit and receive units disabled and uninitialized
  43. **/
  44. static s32 ixgbevf_start_hw_vf(struct ixgbe_hw *hw)
  45. {
  46. /* Clear adapter stopped flag */
  47. hw->adapter_stopped = false;
  48. return 0;
  49. }
  50. /**
  51. * ixgbevf_init_hw_vf - virtual function hardware initialization
  52. * @hw: pointer to hardware structure
  53. *
  54. * Initialize the hardware by resetting the hardware and then starting
  55. * the hardware
  56. **/
  57. static s32 ixgbevf_init_hw_vf(struct ixgbe_hw *hw)
  58. {
  59. s32 status = hw->mac.ops.start_hw(hw);
  60. hw->mac.ops.get_mac_addr(hw, hw->mac.addr);
  61. return status;
  62. }
  63. /**
  64. * ixgbevf_reset_hw_vf - Performs hardware reset
  65. * @hw: pointer to hardware structure
  66. *
  67. * Resets the hardware by resetting the transmit and receive units, masks and
  68. * clears all interrupts.
  69. **/
  70. static s32 ixgbevf_reset_hw_vf(struct ixgbe_hw *hw)
  71. {
  72. struct ixgbe_mbx_info *mbx = &hw->mbx;
  73. u32 timeout = IXGBE_VF_INIT_TIMEOUT;
  74. s32 ret_val = IXGBE_ERR_INVALID_MAC_ADDR;
  75. u32 msgbuf[IXGBE_VF_PERMADDR_MSG_LEN];
  76. u8 *addr = (u8 *)(&msgbuf[1]);
  77. /* Call adapter stop to disable tx/rx and clear interrupts */
  78. hw->mac.ops.stop_adapter(hw);
  79. /* reset the api version */
  80. hw->api_version = ixgbe_mbox_api_10;
  81. IXGBE_WRITE_REG(hw, IXGBE_VFCTRL, IXGBE_CTRL_RST);
  82. IXGBE_WRITE_FLUSH(hw);
  83. /* we cannot reset while the RSTI / RSTD bits are asserted */
  84. while (!mbx->ops.check_for_rst(hw) && timeout) {
  85. timeout--;
  86. udelay(5);
  87. }
  88. if (!timeout)
  89. return IXGBE_ERR_RESET_FAILED;
  90. /* mailbox timeout can now become active */
  91. mbx->timeout = IXGBE_VF_MBX_INIT_TIMEOUT;
  92. msgbuf[0] = IXGBE_VF_RESET;
  93. mbx->ops.write_posted(hw, msgbuf, 1);
  94. mdelay(10);
  95. /* set our "perm_addr" based on info provided by PF
  96. * also set up the mc_filter_type which is piggy backed
  97. * on the mac address in word 3
  98. */
  99. ret_val = mbx->ops.read_posted(hw, msgbuf, IXGBE_VF_PERMADDR_MSG_LEN);
  100. if (ret_val)
  101. return ret_val;
  102. /* New versions of the PF may NACK the reset return message
  103. * to indicate that no MAC address has yet been assigned for
  104. * the VF.
  105. */
  106. if (msgbuf[0] != (IXGBE_VF_RESET | IXGBE_VT_MSGTYPE_ACK) &&
  107. msgbuf[0] != (IXGBE_VF_RESET | IXGBE_VT_MSGTYPE_NACK))
  108. return IXGBE_ERR_INVALID_MAC_ADDR;
  109. if (msgbuf[0] == (IXGBE_VF_RESET | IXGBE_VT_MSGTYPE_ACK))
  110. ether_addr_copy(hw->mac.perm_addr, addr);
  111. hw->mac.mc_filter_type = msgbuf[IXGBE_VF_MC_TYPE_WORD];
  112. return 0;
  113. }
  114. /**
  115. * Hyper-V variant; the VF/PF communication is through the PCI
  116. * config space.
  117. * @hw: pointer to private hardware struct
  118. */
  119. static s32 ixgbevf_hv_reset_hw_vf(struct ixgbe_hw *hw)
  120. {
  121. #if IS_ENABLED(CONFIG_PCI_MMCONFIG)
  122. struct ixgbevf_adapter *adapter = hw->back;
  123. int i;
  124. for (i = 0; i < 6; i++)
  125. pci_read_config_byte(adapter->pdev,
  126. (i + IXGBE_HV_RESET_OFFSET),
  127. &hw->mac.perm_addr[i]);
  128. return 0;
  129. #else
  130. pr_err("PCI_MMCONFIG needs to be enabled for Hyper-V\n");
  131. return -EOPNOTSUPP;
  132. #endif
  133. }
  134. /**
  135. * ixgbevf_stop_hw_vf - Generic stop Tx/Rx units
  136. * @hw: pointer to hardware structure
  137. *
  138. * Sets the adapter_stopped flag within ixgbe_hw struct. Clears interrupts,
  139. * disables transmit and receive units. The adapter_stopped flag is used by
  140. * the shared code and drivers to determine if the adapter is in a stopped
  141. * state and should not touch the hardware.
  142. **/
  143. static s32 ixgbevf_stop_hw_vf(struct ixgbe_hw *hw)
  144. {
  145. u32 number_of_queues;
  146. u32 reg_val;
  147. u16 i;
  148. /* Set the adapter_stopped flag so other driver functions stop touching
  149. * the hardware
  150. */
  151. hw->adapter_stopped = true;
  152. /* Disable the receive unit by stopped each queue */
  153. number_of_queues = hw->mac.max_rx_queues;
  154. for (i = 0; i < number_of_queues; i++) {
  155. reg_val = IXGBE_READ_REG(hw, IXGBE_VFRXDCTL(i));
  156. if (reg_val & IXGBE_RXDCTL_ENABLE) {
  157. reg_val &= ~IXGBE_RXDCTL_ENABLE;
  158. IXGBE_WRITE_REG(hw, IXGBE_VFRXDCTL(i), reg_val);
  159. }
  160. }
  161. IXGBE_WRITE_FLUSH(hw);
  162. /* Clear interrupt mask to stop from interrupts being generated */
  163. IXGBE_WRITE_REG(hw, IXGBE_VTEIMC, IXGBE_VF_IRQ_CLEAR_MASK);
  164. /* Clear any pending interrupts */
  165. IXGBE_READ_REG(hw, IXGBE_VTEICR);
  166. /* Disable the transmit unit. Each queue must be disabled. */
  167. number_of_queues = hw->mac.max_tx_queues;
  168. for (i = 0; i < number_of_queues; i++) {
  169. reg_val = IXGBE_READ_REG(hw, IXGBE_VFTXDCTL(i));
  170. if (reg_val & IXGBE_TXDCTL_ENABLE) {
  171. reg_val &= ~IXGBE_TXDCTL_ENABLE;
  172. IXGBE_WRITE_REG(hw, IXGBE_VFTXDCTL(i), reg_val);
  173. }
  174. }
  175. return 0;
  176. }
  177. /**
  178. * ixgbevf_mta_vector - Determines bit-vector in multicast table to set
  179. * @hw: pointer to hardware structure
  180. * @mc_addr: the multicast address
  181. *
  182. * Extracts the 12 bits, from a multicast address, to determine which
  183. * bit-vector to set in the multicast table. The hardware uses 12 bits, from
  184. * incoming Rx multicast addresses, to determine the bit-vector to check in
  185. * the MTA. Which of the 4 combination, of 12-bits, the hardware uses is set
  186. * by the MO field of the MCSTCTRL. The MO field is set during initialization
  187. * to mc_filter_type.
  188. **/
  189. static s32 ixgbevf_mta_vector(struct ixgbe_hw *hw, u8 *mc_addr)
  190. {
  191. u32 vector = 0;
  192. switch (hw->mac.mc_filter_type) {
  193. case 0: /* use bits [47:36] of the address */
  194. vector = ((mc_addr[4] >> 4) | (((u16)mc_addr[5]) << 4));
  195. break;
  196. case 1: /* use bits [46:35] of the address */
  197. vector = ((mc_addr[4] >> 3) | (((u16)mc_addr[5]) << 5));
  198. break;
  199. case 2: /* use bits [45:34] of the address */
  200. vector = ((mc_addr[4] >> 2) | (((u16)mc_addr[5]) << 6));
  201. break;
  202. case 3: /* use bits [43:32] of the address */
  203. vector = ((mc_addr[4]) | (((u16)mc_addr[5]) << 8));
  204. break;
  205. default: /* Invalid mc_filter_type */
  206. break;
  207. }
  208. /* vector can only be 12-bits or boundary will be exceeded */
  209. vector &= 0xFFF;
  210. return vector;
  211. }
  212. /**
  213. * ixgbevf_get_mac_addr_vf - Read device MAC address
  214. * @hw: pointer to the HW structure
  215. * @mac_addr: pointer to storage for retrieved MAC address
  216. **/
  217. static s32 ixgbevf_get_mac_addr_vf(struct ixgbe_hw *hw, u8 *mac_addr)
  218. {
  219. ether_addr_copy(mac_addr, hw->mac.perm_addr);
  220. return 0;
  221. }
  222. static s32 ixgbevf_set_uc_addr_vf(struct ixgbe_hw *hw, u32 index, u8 *addr)
  223. {
  224. u32 msgbuf[3], msgbuf_chk;
  225. u8 *msg_addr = (u8 *)(&msgbuf[1]);
  226. s32 ret_val;
  227. memset(msgbuf, 0, sizeof(msgbuf));
  228. /* If index is one then this is the start of a new list and needs
  229. * indication to the PF so it can do it's own list management.
  230. * If it is zero then that tells the PF to just clear all of
  231. * this VF's macvlans and there is no new list.
  232. */
  233. msgbuf[0] |= index << IXGBE_VT_MSGINFO_SHIFT;
  234. msgbuf[0] |= IXGBE_VF_SET_MACVLAN;
  235. msgbuf_chk = msgbuf[0];
  236. if (addr)
  237. ether_addr_copy(msg_addr, addr);
  238. ret_val = ixgbevf_write_msg_read_ack(hw, msgbuf, msgbuf,
  239. ARRAY_SIZE(msgbuf));
  240. if (!ret_val) {
  241. msgbuf[0] &= ~IXGBE_VT_MSGTYPE_CTS;
  242. if (msgbuf[0] == (msgbuf_chk | IXGBE_VT_MSGTYPE_NACK))
  243. return -ENOMEM;
  244. }
  245. return ret_val;
  246. }
  247. static s32 ixgbevf_hv_set_uc_addr_vf(struct ixgbe_hw *hw, u32 index, u8 *addr)
  248. {
  249. return -EOPNOTSUPP;
  250. }
  251. /**
  252. * ixgbevf_get_reta_locked - get the RSS redirection table (RETA) contents.
  253. * @hw: pointer to hardware structure
  254. * @reta: buffer to fill with RETA contents.
  255. * @num_rx_queues: Number of Rx queues configured for this port
  256. *
  257. * The "reta" buffer should be big enough to contain 32 registers.
  258. *
  259. * Returns: 0 on success.
  260. * if API doesn't support this operation - (-EOPNOTSUPP).
  261. */
  262. int ixgbevf_get_reta_locked(struct ixgbe_hw *hw, u32 *reta, int num_rx_queues)
  263. {
  264. int err, i, j;
  265. u32 msgbuf[IXGBE_VFMAILBOX_SIZE];
  266. u32 *hw_reta = &msgbuf[1];
  267. u32 mask = 0;
  268. /* We have to use a mailbox for 82599 and x540 devices only.
  269. * For these devices RETA has 128 entries.
  270. * Also these VFs support up to 4 RSS queues. Therefore PF will compress
  271. * 16 RETA entries in each DWORD giving 2 bits to each entry.
  272. */
  273. int dwords = IXGBEVF_82599_RETA_SIZE / 16;
  274. /* We support the RSS querying for 82599 and x540 devices only.
  275. * Thus return an error if API doesn't support RETA querying or querying
  276. * is not supported for this device type.
  277. */
  278. switch (hw->api_version) {
  279. case ixgbe_mbox_api_13:
  280. case ixgbe_mbox_api_12:
  281. if (hw->mac.type < ixgbe_mac_X550_vf)
  282. break;
  283. /* fall through */
  284. default:
  285. return -EOPNOTSUPP;
  286. }
  287. msgbuf[0] = IXGBE_VF_GET_RETA;
  288. err = hw->mbx.ops.write_posted(hw, msgbuf, 1);
  289. if (err)
  290. return err;
  291. err = hw->mbx.ops.read_posted(hw, msgbuf, dwords + 1);
  292. if (err)
  293. return err;
  294. msgbuf[0] &= ~IXGBE_VT_MSGTYPE_CTS;
  295. /* If the operation has been refused by a PF return -EPERM */
  296. if (msgbuf[0] == (IXGBE_VF_GET_RETA | IXGBE_VT_MSGTYPE_NACK))
  297. return -EPERM;
  298. /* If we didn't get an ACK there must have been
  299. * some sort of mailbox error so we should treat it
  300. * as such.
  301. */
  302. if (msgbuf[0] != (IXGBE_VF_GET_RETA | IXGBE_VT_MSGTYPE_ACK))
  303. return IXGBE_ERR_MBX;
  304. /* ixgbevf doesn't support more than 2 queues at the moment */
  305. if (num_rx_queues > 1)
  306. mask = 0x1;
  307. for (i = 0; i < dwords; i++)
  308. for (j = 0; j < 16; j++)
  309. reta[i * 16 + j] = (hw_reta[i] >> (2 * j)) & mask;
  310. return 0;
  311. }
  312. /**
  313. * ixgbevf_get_rss_key_locked - get the RSS Random Key
  314. * @hw: pointer to the HW structure
  315. * @rss_key: buffer to fill with RSS Hash Key contents.
  316. *
  317. * The "rss_key" buffer should be big enough to contain 10 registers.
  318. *
  319. * Returns: 0 on success.
  320. * if API doesn't support this operation - (-EOPNOTSUPP).
  321. */
  322. int ixgbevf_get_rss_key_locked(struct ixgbe_hw *hw, u8 *rss_key)
  323. {
  324. int err;
  325. u32 msgbuf[IXGBE_VFMAILBOX_SIZE];
  326. /* We currently support the RSS Random Key retrieval for 82599 and x540
  327. * devices only.
  328. *
  329. * Thus return an error if API doesn't support RSS Random Key retrieval
  330. * or if the operation is not supported for this device type.
  331. */
  332. switch (hw->api_version) {
  333. case ixgbe_mbox_api_13:
  334. case ixgbe_mbox_api_12:
  335. if (hw->mac.type < ixgbe_mac_X550_vf)
  336. break;
  337. /* fall through */
  338. default:
  339. return -EOPNOTSUPP;
  340. }
  341. msgbuf[0] = IXGBE_VF_GET_RSS_KEY;
  342. err = hw->mbx.ops.write_posted(hw, msgbuf, 1);
  343. if (err)
  344. return err;
  345. err = hw->mbx.ops.read_posted(hw, msgbuf, 11);
  346. if (err)
  347. return err;
  348. msgbuf[0] &= ~IXGBE_VT_MSGTYPE_CTS;
  349. /* If the operation has been refused by a PF return -EPERM */
  350. if (msgbuf[0] == (IXGBE_VF_GET_RSS_KEY | IXGBE_VT_MSGTYPE_NACK))
  351. return -EPERM;
  352. /* If we didn't get an ACK there must have been
  353. * some sort of mailbox error so we should treat it
  354. * as such.
  355. */
  356. if (msgbuf[0] != (IXGBE_VF_GET_RSS_KEY | IXGBE_VT_MSGTYPE_ACK))
  357. return IXGBE_ERR_MBX;
  358. memcpy(rss_key, msgbuf + 1, IXGBEVF_RSS_HASH_KEY_SIZE);
  359. return 0;
  360. }
  361. /**
  362. * ixgbevf_set_rar_vf - set device MAC address
  363. * @hw: pointer to hardware structure
  364. * @index: Receive address register to write
  365. * @addr: Address to put into receive address register
  366. * @vmdq: Unused in this implementation
  367. **/
  368. static s32 ixgbevf_set_rar_vf(struct ixgbe_hw *hw, u32 index, u8 *addr,
  369. u32 vmdq)
  370. {
  371. u32 msgbuf[3];
  372. u8 *msg_addr = (u8 *)(&msgbuf[1]);
  373. s32 ret_val;
  374. memset(msgbuf, 0, sizeof(msgbuf));
  375. msgbuf[0] = IXGBE_VF_SET_MAC_ADDR;
  376. ether_addr_copy(msg_addr, addr);
  377. ret_val = ixgbevf_write_msg_read_ack(hw, msgbuf, msgbuf,
  378. ARRAY_SIZE(msgbuf));
  379. msgbuf[0] &= ~IXGBE_VT_MSGTYPE_CTS;
  380. /* if nacked the address was rejected, use "perm_addr" */
  381. if (!ret_val &&
  382. (msgbuf[0] == (IXGBE_VF_SET_MAC_ADDR | IXGBE_VT_MSGTYPE_NACK))) {
  383. ixgbevf_get_mac_addr_vf(hw, hw->mac.addr);
  384. return IXGBE_ERR_MBX;
  385. }
  386. return ret_val;
  387. }
  388. /**
  389. * ixgbevf_hv_set_rar_vf - set device MAC address Hyper-V variant
  390. * @hw: pointer to hardware structure
  391. * @index: Receive address register to write
  392. * @addr: Address to put into receive address register
  393. * @vmdq: Unused in this implementation
  394. *
  395. * We don't really allow setting the device MAC address. However,
  396. * if the address being set is the permanent MAC address we will
  397. * permit that.
  398. **/
  399. static s32 ixgbevf_hv_set_rar_vf(struct ixgbe_hw *hw, u32 index, u8 *addr,
  400. u32 vmdq)
  401. {
  402. if (ether_addr_equal(addr, hw->mac.perm_addr))
  403. return 0;
  404. return -EOPNOTSUPP;
  405. }
  406. /**
  407. * ixgbevf_update_mc_addr_list_vf - Update Multicast addresses
  408. * @hw: pointer to the HW structure
  409. * @netdev: pointer to net device structure
  410. *
  411. * Updates the Multicast Table Array.
  412. **/
  413. static s32 ixgbevf_update_mc_addr_list_vf(struct ixgbe_hw *hw,
  414. struct net_device *netdev)
  415. {
  416. struct netdev_hw_addr *ha;
  417. u32 msgbuf[IXGBE_VFMAILBOX_SIZE];
  418. u16 *vector_list = (u16 *)&msgbuf[1];
  419. u32 cnt, i;
  420. /* Each entry in the list uses 1 16 bit word. We have 30
  421. * 16 bit words available in our HW msg buffer (minus 1 for the
  422. * msg type). That's 30 hash values if we pack 'em right. If
  423. * there are more than 30 MC addresses to add then punt the
  424. * extras for now and then add code to handle more than 30 later.
  425. * It would be unusual for a server to request that many multi-cast
  426. * addresses except for in large enterprise network environments.
  427. */
  428. cnt = netdev_mc_count(netdev);
  429. if (cnt > 30)
  430. cnt = 30;
  431. msgbuf[0] = IXGBE_VF_SET_MULTICAST;
  432. msgbuf[0] |= cnt << IXGBE_VT_MSGINFO_SHIFT;
  433. i = 0;
  434. netdev_for_each_mc_addr(ha, netdev) {
  435. if (i == cnt)
  436. break;
  437. if (is_link_local_ether_addr(ha->addr))
  438. continue;
  439. vector_list[i++] = ixgbevf_mta_vector(hw, ha->addr);
  440. }
  441. ixgbevf_write_msg_read_ack(hw, msgbuf, msgbuf, IXGBE_VFMAILBOX_SIZE);
  442. return 0;
  443. }
  444. /**
  445. * Hyper-V variant - just a stub.
  446. * @hw: unused
  447. * @netdev: unused
  448. */
  449. static s32 ixgbevf_hv_update_mc_addr_list_vf(struct ixgbe_hw *hw,
  450. struct net_device *netdev)
  451. {
  452. return -EOPNOTSUPP;
  453. }
  454. /**
  455. * ixgbevf_update_xcast_mode - Update Multicast mode
  456. * @hw: pointer to the HW structure
  457. * @xcast_mode: new multicast mode
  458. *
  459. * Updates the Multicast Mode of VF.
  460. **/
  461. static s32 ixgbevf_update_xcast_mode(struct ixgbe_hw *hw, int xcast_mode)
  462. {
  463. u32 msgbuf[2];
  464. s32 err;
  465. switch (hw->api_version) {
  466. case ixgbe_mbox_api_12:
  467. /* promisc introduced in 1.3 version */
  468. if (xcast_mode == IXGBEVF_XCAST_MODE_PROMISC)
  469. return -EOPNOTSUPP;
  470. /* Fall threw */
  471. case ixgbe_mbox_api_13:
  472. break;
  473. default:
  474. return -EOPNOTSUPP;
  475. }
  476. msgbuf[0] = IXGBE_VF_UPDATE_XCAST_MODE;
  477. msgbuf[1] = xcast_mode;
  478. err = ixgbevf_write_msg_read_ack(hw, msgbuf, msgbuf,
  479. ARRAY_SIZE(msgbuf));
  480. if (err)
  481. return err;
  482. msgbuf[0] &= ~IXGBE_VT_MSGTYPE_CTS;
  483. if (msgbuf[0] == (IXGBE_VF_UPDATE_XCAST_MODE | IXGBE_VT_MSGTYPE_NACK))
  484. return -EPERM;
  485. return 0;
  486. }
  487. /**
  488. * Hyper-V variant - just a stub.
  489. * @hw: unused
  490. * @xcast_mode: unused
  491. */
  492. static s32 ixgbevf_hv_update_xcast_mode(struct ixgbe_hw *hw, int xcast_mode)
  493. {
  494. return -EOPNOTSUPP;
  495. }
  496. /**
  497. * ixgbevf_set_vfta_vf - Set/Unset VLAN filter table address
  498. * @hw: pointer to the HW structure
  499. * @vlan: 12 bit VLAN ID
  500. * @vind: unused by VF drivers
  501. * @vlan_on: if true then set bit, else clear bit
  502. **/
  503. static s32 ixgbevf_set_vfta_vf(struct ixgbe_hw *hw, u32 vlan, u32 vind,
  504. bool vlan_on)
  505. {
  506. u32 msgbuf[2];
  507. s32 err;
  508. msgbuf[0] = IXGBE_VF_SET_VLAN;
  509. msgbuf[1] = vlan;
  510. /* Setting the 8 bit field MSG INFO to TRUE indicates "add" */
  511. msgbuf[0] |= vlan_on << IXGBE_VT_MSGINFO_SHIFT;
  512. err = ixgbevf_write_msg_read_ack(hw, msgbuf, msgbuf,
  513. ARRAY_SIZE(msgbuf));
  514. if (err)
  515. goto mbx_err;
  516. /* remove extra bits from the message */
  517. msgbuf[0] &= ~IXGBE_VT_MSGTYPE_CTS;
  518. msgbuf[0] &= ~(0xFF << IXGBE_VT_MSGINFO_SHIFT);
  519. if (msgbuf[0] != (IXGBE_VF_SET_VLAN | IXGBE_VT_MSGTYPE_ACK))
  520. err = IXGBE_ERR_INVALID_ARGUMENT;
  521. mbx_err:
  522. return err;
  523. }
  524. /**
  525. * Hyper-V variant - just a stub.
  526. * @hw: unused
  527. * @vlan: unused
  528. * @vind: unused
  529. * @vlan_on: unused
  530. */
  531. static s32 ixgbevf_hv_set_vfta_vf(struct ixgbe_hw *hw, u32 vlan, u32 vind,
  532. bool vlan_on)
  533. {
  534. return -EOPNOTSUPP;
  535. }
  536. /**
  537. * ixgbevf_setup_mac_link_vf - Setup MAC link settings
  538. * @hw: pointer to hardware structure
  539. * @speed: Unused in this implementation
  540. * @autoneg: Unused in this implementation
  541. * @autoneg_wait_to_complete: Unused in this implementation
  542. *
  543. * Do nothing and return success. VF drivers are not allowed to change
  544. * global settings. Maintained for driver compatibility.
  545. **/
  546. static s32 ixgbevf_setup_mac_link_vf(struct ixgbe_hw *hw,
  547. ixgbe_link_speed speed, bool autoneg,
  548. bool autoneg_wait_to_complete)
  549. {
  550. return 0;
  551. }
  552. /**
  553. * ixgbevf_check_mac_link_vf - Get link/speed status
  554. * @hw: pointer to hardware structure
  555. * @speed: pointer to link speed
  556. * @link_up: true is link is up, false otherwise
  557. * @autoneg_wait_to_complete: unused
  558. *
  559. * Reads the links register to determine if link is up and the current speed
  560. **/
  561. static s32 ixgbevf_check_mac_link_vf(struct ixgbe_hw *hw,
  562. ixgbe_link_speed *speed,
  563. bool *link_up,
  564. bool autoneg_wait_to_complete)
  565. {
  566. struct ixgbe_mbx_info *mbx = &hw->mbx;
  567. struct ixgbe_mac_info *mac = &hw->mac;
  568. s32 ret_val = 0;
  569. u32 links_reg;
  570. u32 in_msg = 0;
  571. /* If we were hit with a reset drop the link */
  572. if (!mbx->ops.check_for_rst(hw) || !mbx->timeout)
  573. mac->get_link_status = true;
  574. if (!mac->get_link_status)
  575. goto out;
  576. /* if link status is down no point in checking to see if pf is up */
  577. links_reg = IXGBE_READ_REG(hw, IXGBE_VFLINKS);
  578. if (!(links_reg & IXGBE_LINKS_UP))
  579. goto out;
  580. /* for SFP+ modules and DA cables on 82599 it can take up to 500usecs
  581. * before the link status is correct
  582. */
  583. if (mac->type == ixgbe_mac_82599_vf) {
  584. int i;
  585. for (i = 0; i < 5; i++) {
  586. udelay(100);
  587. links_reg = IXGBE_READ_REG(hw, IXGBE_VFLINKS);
  588. if (!(links_reg & IXGBE_LINKS_UP))
  589. goto out;
  590. }
  591. }
  592. switch (links_reg & IXGBE_LINKS_SPEED_82599) {
  593. case IXGBE_LINKS_SPEED_10G_82599:
  594. *speed = IXGBE_LINK_SPEED_10GB_FULL;
  595. break;
  596. case IXGBE_LINKS_SPEED_1G_82599:
  597. *speed = IXGBE_LINK_SPEED_1GB_FULL;
  598. break;
  599. case IXGBE_LINKS_SPEED_100_82599:
  600. *speed = IXGBE_LINK_SPEED_100_FULL;
  601. break;
  602. }
  603. /* if the read failed it could just be a mailbox collision, best wait
  604. * until we are called again and don't report an error
  605. */
  606. if (mbx->ops.read(hw, &in_msg, 1))
  607. goto out;
  608. if (!(in_msg & IXGBE_VT_MSGTYPE_CTS)) {
  609. /* msg is not CTS and is NACK we must have lost CTS status */
  610. if (in_msg & IXGBE_VT_MSGTYPE_NACK)
  611. ret_val = -1;
  612. goto out;
  613. }
  614. /* the pf is talking, if we timed out in the past we reinit */
  615. if (!mbx->timeout) {
  616. ret_val = -1;
  617. goto out;
  618. }
  619. /* if we passed all the tests above then the link is up and we no
  620. * longer need to check for link
  621. */
  622. mac->get_link_status = false;
  623. out:
  624. *link_up = !mac->get_link_status;
  625. return ret_val;
  626. }
  627. /**
  628. * Hyper-V variant; there is no mailbox communication.
  629. * @hw: pointer to private hardware struct
  630. * @speed: pointer to link speed
  631. * @link_up: true is link is up, false otherwise
  632. * @autoneg_wait_to_complete: unused
  633. */
  634. static s32 ixgbevf_hv_check_mac_link_vf(struct ixgbe_hw *hw,
  635. ixgbe_link_speed *speed,
  636. bool *link_up,
  637. bool autoneg_wait_to_complete)
  638. {
  639. struct ixgbe_mbx_info *mbx = &hw->mbx;
  640. struct ixgbe_mac_info *mac = &hw->mac;
  641. u32 links_reg;
  642. /* If we were hit with a reset drop the link */
  643. if (!mbx->ops.check_for_rst(hw) || !mbx->timeout)
  644. mac->get_link_status = true;
  645. if (!mac->get_link_status)
  646. goto out;
  647. /* if link status is down no point in checking to see if pf is up */
  648. links_reg = IXGBE_READ_REG(hw, IXGBE_VFLINKS);
  649. if (!(links_reg & IXGBE_LINKS_UP))
  650. goto out;
  651. /* for SFP+ modules and DA cables on 82599 it can take up to 500usecs
  652. * before the link status is correct
  653. */
  654. if (mac->type == ixgbe_mac_82599_vf) {
  655. int i;
  656. for (i = 0; i < 5; i++) {
  657. udelay(100);
  658. links_reg = IXGBE_READ_REG(hw, IXGBE_VFLINKS);
  659. if (!(links_reg & IXGBE_LINKS_UP))
  660. goto out;
  661. }
  662. }
  663. switch (links_reg & IXGBE_LINKS_SPEED_82599) {
  664. case IXGBE_LINKS_SPEED_10G_82599:
  665. *speed = IXGBE_LINK_SPEED_10GB_FULL;
  666. break;
  667. case IXGBE_LINKS_SPEED_1G_82599:
  668. *speed = IXGBE_LINK_SPEED_1GB_FULL;
  669. break;
  670. case IXGBE_LINKS_SPEED_100_82599:
  671. *speed = IXGBE_LINK_SPEED_100_FULL;
  672. break;
  673. }
  674. /* if we passed all the tests above then the link is up and we no
  675. * longer need to check for link
  676. */
  677. mac->get_link_status = false;
  678. out:
  679. *link_up = !mac->get_link_status;
  680. return 0;
  681. }
  682. /**
  683. * ixgbevf_set_rlpml_vf - Set the maximum receive packet length
  684. * @hw: pointer to the HW structure
  685. * @max_size: value to assign to max frame size
  686. **/
  687. static s32 ixgbevf_set_rlpml_vf(struct ixgbe_hw *hw, u16 max_size)
  688. {
  689. u32 msgbuf[2];
  690. s32 ret_val;
  691. msgbuf[0] = IXGBE_VF_SET_LPE;
  692. msgbuf[1] = max_size;
  693. ret_val = ixgbevf_write_msg_read_ack(hw, msgbuf, msgbuf,
  694. ARRAY_SIZE(msgbuf));
  695. if (ret_val)
  696. return ret_val;
  697. if ((msgbuf[0] & IXGBE_VF_SET_LPE) &&
  698. (msgbuf[0] & IXGBE_VT_MSGTYPE_NACK))
  699. return IXGBE_ERR_MBX;
  700. return 0;
  701. }
  702. /**
  703. * ixgbevf_hv_set_rlpml_vf - Set the maximum receive packet length
  704. * @hw: pointer to the HW structure
  705. * @max_size: value to assign to max frame size
  706. * Hyper-V variant.
  707. **/
  708. static s32 ixgbevf_hv_set_rlpml_vf(struct ixgbe_hw *hw, u16 max_size)
  709. {
  710. u32 reg;
  711. /* If we are on Hyper-V, we implement this functionality
  712. * differently.
  713. */
  714. reg = IXGBE_READ_REG(hw, IXGBE_VFRXDCTL(0));
  715. /* CRC == 4 */
  716. reg |= ((max_size + 4) | IXGBE_RXDCTL_RLPML_EN);
  717. IXGBE_WRITE_REG(hw, IXGBE_VFRXDCTL(0), reg);
  718. return 0;
  719. }
  720. /**
  721. * ixgbevf_negotiate_api_version_vf - Negotiate supported API version
  722. * @hw: pointer to the HW structure
  723. * @api: integer containing requested API version
  724. **/
  725. static int ixgbevf_negotiate_api_version_vf(struct ixgbe_hw *hw, int api)
  726. {
  727. int err;
  728. u32 msg[3];
  729. /* Negotiate the mailbox API version */
  730. msg[0] = IXGBE_VF_API_NEGOTIATE;
  731. msg[1] = api;
  732. msg[2] = 0;
  733. err = ixgbevf_write_msg_read_ack(hw, msg, msg, ARRAY_SIZE(msg));
  734. if (!err) {
  735. msg[0] &= ~IXGBE_VT_MSGTYPE_CTS;
  736. /* Store value and return 0 on success */
  737. if (msg[0] == (IXGBE_VF_API_NEGOTIATE | IXGBE_VT_MSGTYPE_ACK)) {
  738. hw->api_version = api;
  739. return 0;
  740. }
  741. err = IXGBE_ERR_INVALID_ARGUMENT;
  742. }
  743. return err;
  744. }
  745. /**
  746. * ixgbevf_hv_negotiate_api_version_vf - Negotiate supported API version
  747. * @hw: pointer to the HW structure
  748. * @api: integer containing requested API version
  749. * Hyper-V version - only ixgbe_mbox_api_10 supported.
  750. **/
  751. static int ixgbevf_hv_negotiate_api_version_vf(struct ixgbe_hw *hw, int api)
  752. {
  753. /* Hyper-V only supports api version ixgbe_mbox_api_10 */
  754. if (api != ixgbe_mbox_api_10)
  755. return IXGBE_ERR_INVALID_ARGUMENT;
  756. return 0;
  757. }
  758. int ixgbevf_get_queues(struct ixgbe_hw *hw, unsigned int *num_tcs,
  759. unsigned int *default_tc)
  760. {
  761. int err;
  762. u32 msg[5];
  763. /* do nothing if API doesn't support ixgbevf_get_queues */
  764. switch (hw->api_version) {
  765. case ixgbe_mbox_api_11:
  766. case ixgbe_mbox_api_12:
  767. case ixgbe_mbox_api_13:
  768. break;
  769. default:
  770. return 0;
  771. }
  772. /* Fetch queue configuration from the PF */
  773. msg[0] = IXGBE_VF_GET_QUEUE;
  774. msg[1] = msg[2] = msg[3] = msg[4] = 0;
  775. err = ixgbevf_write_msg_read_ack(hw, msg, msg, ARRAY_SIZE(msg));
  776. if (!err) {
  777. msg[0] &= ~IXGBE_VT_MSGTYPE_CTS;
  778. /* if we we didn't get an ACK there must have been
  779. * some sort of mailbox error so we should treat it
  780. * as such
  781. */
  782. if (msg[0] != (IXGBE_VF_GET_QUEUE | IXGBE_VT_MSGTYPE_ACK))
  783. return IXGBE_ERR_MBX;
  784. /* record and validate values from message */
  785. hw->mac.max_tx_queues = msg[IXGBE_VF_TX_QUEUES];
  786. if (hw->mac.max_tx_queues == 0 ||
  787. hw->mac.max_tx_queues > IXGBE_VF_MAX_TX_QUEUES)
  788. hw->mac.max_tx_queues = IXGBE_VF_MAX_TX_QUEUES;
  789. hw->mac.max_rx_queues = msg[IXGBE_VF_RX_QUEUES];
  790. if (hw->mac.max_rx_queues == 0 ||
  791. hw->mac.max_rx_queues > IXGBE_VF_MAX_RX_QUEUES)
  792. hw->mac.max_rx_queues = IXGBE_VF_MAX_RX_QUEUES;
  793. *num_tcs = msg[IXGBE_VF_TRANS_VLAN];
  794. /* in case of unknown state assume we cannot tag frames */
  795. if (*num_tcs > hw->mac.max_rx_queues)
  796. *num_tcs = 1;
  797. *default_tc = msg[IXGBE_VF_DEF_QUEUE];
  798. /* default to queue 0 on out-of-bounds queue number */
  799. if (*default_tc >= hw->mac.max_tx_queues)
  800. *default_tc = 0;
  801. }
  802. return err;
  803. }
  804. static const struct ixgbe_mac_operations ixgbevf_mac_ops = {
  805. .init_hw = ixgbevf_init_hw_vf,
  806. .reset_hw = ixgbevf_reset_hw_vf,
  807. .start_hw = ixgbevf_start_hw_vf,
  808. .get_mac_addr = ixgbevf_get_mac_addr_vf,
  809. .stop_adapter = ixgbevf_stop_hw_vf,
  810. .setup_link = ixgbevf_setup_mac_link_vf,
  811. .check_link = ixgbevf_check_mac_link_vf,
  812. .negotiate_api_version = ixgbevf_negotiate_api_version_vf,
  813. .set_rar = ixgbevf_set_rar_vf,
  814. .update_mc_addr_list = ixgbevf_update_mc_addr_list_vf,
  815. .update_xcast_mode = ixgbevf_update_xcast_mode,
  816. .set_uc_addr = ixgbevf_set_uc_addr_vf,
  817. .set_vfta = ixgbevf_set_vfta_vf,
  818. .set_rlpml = ixgbevf_set_rlpml_vf,
  819. };
  820. static const struct ixgbe_mac_operations ixgbevf_hv_mac_ops = {
  821. .init_hw = ixgbevf_init_hw_vf,
  822. .reset_hw = ixgbevf_hv_reset_hw_vf,
  823. .start_hw = ixgbevf_start_hw_vf,
  824. .get_mac_addr = ixgbevf_get_mac_addr_vf,
  825. .stop_adapter = ixgbevf_stop_hw_vf,
  826. .setup_link = ixgbevf_setup_mac_link_vf,
  827. .check_link = ixgbevf_hv_check_mac_link_vf,
  828. .negotiate_api_version = ixgbevf_hv_negotiate_api_version_vf,
  829. .set_rar = ixgbevf_hv_set_rar_vf,
  830. .update_mc_addr_list = ixgbevf_hv_update_mc_addr_list_vf,
  831. .update_xcast_mode = ixgbevf_hv_update_xcast_mode,
  832. .set_uc_addr = ixgbevf_hv_set_uc_addr_vf,
  833. .set_vfta = ixgbevf_hv_set_vfta_vf,
  834. .set_rlpml = ixgbevf_hv_set_rlpml_vf,
  835. };
  836. const struct ixgbevf_info ixgbevf_82599_vf_info = {
  837. .mac = ixgbe_mac_82599_vf,
  838. .mac_ops = &ixgbevf_mac_ops,
  839. };
  840. const struct ixgbevf_info ixgbevf_82599_vf_hv_info = {
  841. .mac = ixgbe_mac_82599_vf,
  842. .mac_ops = &ixgbevf_hv_mac_ops,
  843. };
  844. const struct ixgbevf_info ixgbevf_X540_vf_info = {
  845. .mac = ixgbe_mac_X540_vf,
  846. .mac_ops = &ixgbevf_mac_ops,
  847. };
  848. const struct ixgbevf_info ixgbevf_X540_vf_hv_info = {
  849. .mac = ixgbe_mac_X540_vf,
  850. .mac_ops = &ixgbevf_hv_mac_ops,
  851. };
  852. const struct ixgbevf_info ixgbevf_X550_vf_info = {
  853. .mac = ixgbe_mac_X550_vf,
  854. .mac_ops = &ixgbevf_mac_ops,
  855. };
  856. const struct ixgbevf_info ixgbevf_X550_vf_hv_info = {
  857. .mac = ixgbe_mac_X550_vf,
  858. .mac_ops = &ixgbevf_hv_mac_ops,
  859. };
  860. const struct ixgbevf_info ixgbevf_X550EM_x_vf_info = {
  861. .mac = ixgbe_mac_X550EM_x_vf,
  862. .mac_ops = &ixgbevf_mac_ops,
  863. };
  864. const struct ixgbevf_info ixgbevf_X550EM_x_vf_hv_info = {
  865. .mac = ixgbe_mac_X550EM_x_vf,
  866. .mac_ops = &ixgbevf_hv_mac_ops,
  867. };
  868. const struct ixgbevf_info ixgbevf_x550em_a_vf_info = {
  869. .mac = ixgbe_mac_x550em_a_vf,
  870. .mac_ops = &ixgbevf_mac_ops,
  871. };