vf.c 27 KB

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