You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

igbvf_vf.c 13KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456
  1. /*******************************************************************************
  2. Intel(R) 82576 Virtual Function Linux driver
  3. Copyright(c) 1999 - 2008 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, write to the Free Software Foundation, Inc.,
  13. 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
  14. The full GNU General Public License is included in this distribution in
  15. the file called "COPYING".
  16. Contact Information:
  17. Linux NICS <linux.nics@intel.com>
  18. e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
  19. Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
  20. *******************************************************************************/
  21. FILE_LICENCE ( GPL2_ONLY );
  22. #include "igbvf_vf.h"
  23. static s32 igbvf_init_mac_params_vf(struct e1000_hw *hw);
  24. static s32 igbvf_check_for_link_vf(struct e1000_hw *hw);
  25. static s32 igbvf_get_link_up_info_vf(struct e1000_hw *hw, u16 *speed,
  26. u16 *duplex);
  27. static s32 igbvf_init_hw_vf(struct e1000_hw *hw);
  28. static s32 igbvf_reset_hw_vf(struct e1000_hw *hw);
  29. static void igbvf_update_mc_addr_list_vf(struct e1000_hw *hw, u8 *, u32);
  30. static void igbvf_rar_set_vf(struct e1000_hw *, u8 *, u32);
  31. static s32 igbvf_read_mac_addr_vf(struct e1000_hw *);
  32. /**
  33. * igbvf_init_mac_params_vf - Inits MAC params
  34. * @hw: pointer to the HW structure
  35. **/
  36. static s32 igbvf_init_mac_params_vf(struct e1000_hw *hw)
  37. {
  38. struct e1000_mac_info *mac = &hw->mac;
  39. DEBUGFUNC("igbvf_init_mac_params_vf");
  40. /* VF's have no MTA Registers - PF feature only */
  41. mac->mta_reg_count = 128;
  42. /* VF's have no access to RAR entries */
  43. mac->rar_entry_count = 1;
  44. /* Function pointers */
  45. /* reset */
  46. mac->ops.reset_hw = igbvf_reset_hw_vf;
  47. /* hw initialization */
  48. mac->ops.init_hw = igbvf_init_hw_vf;
  49. /* check for link */
  50. mac->ops.check_for_link = igbvf_check_for_link_vf;
  51. /* link info */
  52. mac->ops.get_link_up_info = igbvf_get_link_up_info_vf;
  53. /* multicast address update */
  54. mac->ops.update_mc_addr_list = igbvf_update_mc_addr_list_vf;
  55. /* set mac address */
  56. mac->ops.rar_set = igbvf_rar_set_vf;
  57. /* read mac address */
  58. mac->ops.read_mac_addr = igbvf_read_mac_addr_vf;
  59. return E1000_SUCCESS;
  60. }
  61. /**
  62. * igbvf_init_function_pointers_vf - Inits function pointers
  63. * @hw: pointer to the HW structure
  64. **/
  65. void igbvf_init_function_pointers_vf(struct e1000_hw *hw)
  66. {
  67. DEBUGFUNC("igbvf_init_function_pointers_vf");
  68. hw->mac.ops.init_params = igbvf_init_mac_params_vf;
  69. hw->mbx.ops.init_params = igbvf_init_mbx_params_vf;
  70. }
  71. /**
  72. * igbvf_get_link_up_info_vf - Gets link info.
  73. * @hw: pointer to the HW structure
  74. * @speed: pointer to 16 bit value to store link speed.
  75. * @duplex: pointer to 16 bit value to store duplex.
  76. *
  77. * Since we cannot read the PHY and get accurate link info, we must rely upon
  78. * the status register's data which is often stale and inaccurate.
  79. **/
  80. static s32 igbvf_get_link_up_info_vf(struct e1000_hw *hw, u16 *speed,
  81. u16 *duplex)
  82. {
  83. s32 status;
  84. DEBUGFUNC("igbvf_get_link_up_info_vf");
  85. status = E1000_READ_REG(hw, E1000_STATUS);
  86. if (status & E1000_STATUS_SPEED_1000) {
  87. *speed = SPEED_1000;
  88. DEBUGOUT("1000 Mbs, ");
  89. } else if (status & E1000_STATUS_SPEED_100) {
  90. *speed = SPEED_100;
  91. DEBUGOUT("100 Mbs, ");
  92. } else {
  93. *speed = SPEED_10;
  94. DEBUGOUT("10 Mbs, ");
  95. }
  96. if (status & E1000_STATUS_FD) {
  97. *duplex = FULL_DUPLEX;
  98. DEBUGOUT("Full Duplex\n");
  99. } else {
  100. *duplex = HALF_DUPLEX;
  101. DEBUGOUT("Half Duplex\n");
  102. }
  103. return E1000_SUCCESS;
  104. }
  105. /**
  106. * igbvf_reset_hw_vf - Resets the HW
  107. * @hw: pointer to the HW structure
  108. *
  109. * VF's provide a function level reset. This is done using bit 26 of ctrl_reg.
  110. * This is all the reset we can perform on a VF.
  111. **/
  112. static s32 igbvf_reset_hw_vf(struct e1000_hw *hw)
  113. {
  114. struct e1000_mbx_info *mbx = &hw->mbx;
  115. u32 timeout = E1000_VF_INIT_TIMEOUT;
  116. s32 ret_val = -E1000_ERR_MAC_INIT;
  117. u32 ctrl, msgbuf[3];
  118. u8 *addr = (u8 *)(&msgbuf[1]);
  119. DEBUGFUNC("igbvf_reset_hw_vf");
  120. DEBUGOUT("Issuing a function level reset to MAC\n");
  121. ctrl = E1000_READ_REG(hw, E1000_CTRL);
  122. E1000_WRITE_REG(hw, E1000_CTRL, ctrl | E1000_CTRL_RST);
  123. /* we cannot reset while the RSTI / RSTD bits are asserted */
  124. while (!mbx->ops.check_for_rst(hw, 0) && timeout) {
  125. timeout--;
  126. usec_delay(5);
  127. }
  128. if (timeout) {
  129. /* mailbox timeout can now become active */
  130. mbx->timeout = E1000_VF_MBX_INIT_TIMEOUT;
  131. msgbuf[0] = E1000_VF_RESET;
  132. mbx->ops.write_posted(hw, msgbuf, 1, 0);
  133. msec_delay(10);
  134. /* set our "perm_addr" based on info provided by PF */
  135. ret_val = mbx->ops.read_posted(hw, msgbuf, 3, 0);
  136. if (!ret_val) {
  137. if (msgbuf[0] == (E1000_VF_RESET |
  138. E1000_VT_MSGTYPE_ACK))
  139. memcpy(hw->mac.perm_addr, addr, 6);
  140. else
  141. ret_val = -E1000_ERR_MAC_INIT;
  142. }
  143. }
  144. return ret_val;
  145. }
  146. /**
  147. * igbvf_init_hw_vf - Inits the HW
  148. * @hw: pointer to the HW structure
  149. *
  150. * Not much to do here except clear the PF Reset indication if there is one.
  151. **/
  152. static s32 igbvf_init_hw_vf(struct e1000_hw *hw)
  153. {
  154. DEBUGFUNC("igbvf_init_hw_vf");
  155. /* attempt to set and restore our mac address */
  156. igbvf_rar_set_vf(hw, hw->mac.addr, 0);
  157. return E1000_SUCCESS;
  158. }
  159. /**
  160. * igbvf_rar_set_vf - set device MAC address
  161. * @hw: pointer to the HW structure
  162. * @addr: pointer to the receive address
  163. * @index receive address array register
  164. **/
  165. static void igbvf_rar_set_vf(struct e1000_hw *hw, u8 * addr, u32 index __unused)
  166. {
  167. struct e1000_mbx_info *mbx = &hw->mbx;
  168. u32 msgbuf[3];
  169. u8 *msg_addr = (u8 *)(&msgbuf[1]);
  170. s32 ret_val;
  171. memset(msgbuf, 0, 12);
  172. msgbuf[0] = E1000_VF_SET_MAC_ADDR;
  173. memcpy(msg_addr, addr, 6);
  174. ret_val = mbx->ops.write_posted(hw, msgbuf, 3, 0);
  175. if (!ret_val)
  176. ret_val = mbx->ops.read_posted(hw, msgbuf, 3, 0);
  177. msgbuf[0] &= ~E1000_VT_MSGTYPE_CTS;
  178. /* if nacked the address was rejected, use "perm_addr" */
  179. if (!ret_val &&
  180. (msgbuf[0] == (E1000_VF_SET_MAC_ADDR | E1000_VT_MSGTYPE_NACK)))
  181. igbvf_read_mac_addr_vf(hw);
  182. }
  183. /**
  184. * igbvf_hash_mc_addr_vf - Generate a multicast hash value
  185. * @hw: pointer to the HW structure
  186. * @mc_addr: pointer to a multicast address
  187. *
  188. * Generates a multicast address hash value which is used to determine
  189. * the multicast filter table array address and new table value. See
  190. * igbvf_mta_set_generic()
  191. **/
  192. static u32 igbvf_hash_mc_addr_vf(struct e1000_hw *hw, u8 *mc_addr)
  193. {
  194. u32 hash_value, hash_mask;
  195. u8 bit_shift = 0;
  196. DEBUGFUNC("igbvf_hash_mc_addr_generic");
  197. /* Register count multiplied by bits per register */
  198. hash_mask = (hw->mac.mta_reg_count * 32) - 1;
  199. /*
  200. * The bit_shift is the number of left-shifts
  201. * where 0xFF would still fall within the hash mask.
  202. */
  203. while (hash_mask >> bit_shift != 0xFF)
  204. bit_shift++;
  205. hash_value = hash_mask & (((mc_addr[4] >> (8 - bit_shift)) |
  206. (((u16) mc_addr[5]) << bit_shift)));
  207. return hash_value;
  208. }
  209. /**
  210. * igbvf_update_mc_addr_list_vf - Update Multicast addresses
  211. * @hw: pointer to the HW structure
  212. * @mc_addr_list: array of multicast addresses to program
  213. * @mc_addr_count: number of multicast addresses to program
  214. *
  215. * Updates the Multicast Table Array.
  216. * The caller must have a packed mc_addr_list of multicast addresses.
  217. **/
  218. void igbvf_update_mc_addr_list_vf(struct e1000_hw *hw,
  219. u8 *mc_addr_list, u32 mc_addr_count)
  220. {
  221. struct e1000_mbx_info *mbx = &hw->mbx;
  222. u32 msgbuf[E1000_VFMAILBOX_SIZE];
  223. u16 *hash_list = (u16 *)&msgbuf[1];
  224. u32 hash_value;
  225. u32 i;
  226. DEBUGFUNC("igbvf_update_mc_addr_list_vf");
  227. /* Each entry in the list uses 1 16 bit word. We have 30
  228. * 16 bit words available in our HW msg buffer (minus 1 for the
  229. * msg type). That's 30 hash values if we pack 'em right. If
  230. * there are more than 30 MC addresses to add then punt the
  231. * extras for now and then add code to handle more than 30 later.
  232. * It would be unusual for a server to request that many multi-cast
  233. * addresses except for in large enterprise network environments.
  234. */
  235. DEBUGOUT1("MC Addr Count = %d\n", mc_addr_count);
  236. msgbuf[0] = E1000_VF_SET_MULTICAST;
  237. if (mc_addr_count > 30) {
  238. msgbuf[0] |= E1000_VF_SET_MULTICAST_OVERFLOW;
  239. mc_addr_count = 30;
  240. }
  241. msgbuf[0] |= mc_addr_count << E1000_VT_MSGINFO_SHIFT;
  242. for (i = 0; i < mc_addr_count; i++) {
  243. hash_value = igbvf_hash_mc_addr_vf(hw, mc_addr_list);
  244. DEBUGOUT1("Hash value = 0x%03X\n", hash_value);
  245. hash_list[i] = hash_value & 0x0FFF;
  246. mc_addr_list += ETH_ADDR_LEN;
  247. }
  248. mbx->ops.write_posted(hw, msgbuf, E1000_VFMAILBOX_SIZE, 0);
  249. }
  250. /**
  251. * igbvf_vfta_set_vf - Set/Unset vlan filter table address
  252. * @hw: pointer to the HW structure
  253. * @vid: determines the vfta register and bit to set/unset
  254. * @set: if true then set bit, else clear bit
  255. **/
  256. void igbvf_vfta_set_vf(struct e1000_hw *hw, u16 vid, bool set)
  257. {
  258. struct e1000_mbx_info *mbx = &hw->mbx;
  259. u32 msgbuf[2];
  260. msgbuf[0] = E1000_VF_SET_VLAN;
  261. msgbuf[1] = vid;
  262. /* Setting the 8 bit field MSG INFO to TRUE indicates "add" */
  263. if (set)
  264. msgbuf[0] |= E1000_VF_SET_VLAN_ADD;
  265. mbx->ops.write_posted(hw, msgbuf, 2, 0);
  266. }
  267. /** igbvf_rlpml_set_vf - Set the maximum receive packet length
  268. * @hw: pointer to the HW structure
  269. * @max_size: value to assign to max frame size
  270. **/
  271. void igbvf_rlpml_set_vf(struct e1000_hw *hw, u16 max_size)
  272. {
  273. struct e1000_mbx_info *mbx = &hw->mbx;
  274. u32 msgbuf[2];
  275. msgbuf[0] = E1000_VF_SET_LPE;
  276. msgbuf[1] = max_size;
  277. mbx->ops.write_posted(hw, msgbuf, 2, 0);
  278. }
  279. /**
  280. * igbvf_promisc_set_vf - Set flags for Unicast or Multicast promisc
  281. * @hw: pointer to the HW structure
  282. * @uni: boolean indicating unicast promisc status
  283. * @multi: boolean indicating multicast promisc status
  284. **/
  285. s32 igbvf_promisc_set_vf(struct e1000_hw *hw, enum e1000_promisc_type type)
  286. {
  287. struct e1000_mbx_info *mbx = &hw->mbx;
  288. u32 msgbuf = E1000_VF_SET_PROMISC;
  289. s32 ret_val;
  290. switch (type) {
  291. case e1000_promisc_multicast:
  292. msgbuf |= E1000_VF_SET_PROMISC_MULTICAST;
  293. break;
  294. case e1000_promisc_enabled:
  295. msgbuf |= E1000_VF_SET_PROMISC_MULTICAST;
  296. /* Fall through */
  297. case e1000_promisc_unicast:
  298. msgbuf |= E1000_VF_SET_PROMISC_UNICAST;
  299. case e1000_promisc_disabled:
  300. break;
  301. default:
  302. return -E1000_ERR_MAC_INIT;
  303. }
  304. ret_val = mbx->ops.write_posted(hw, &msgbuf, 1, 0);
  305. if (!ret_val)
  306. ret_val = mbx->ops.read_posted(hw, &msgbuf, 1, 0);
  307. if (!ret_val && !(msgbuf & E1000_VT_MSGTYPE_ACK))
  308. ret_val = -E1000_ERR_MAC_INIT;
  309. return ret_val;
  310. }
  311. /**
  312. * igbvf_read_mac_addr_vf - Read device MAC address
  313. * @hw: pointer to the HW structure
  314. **/
  315. static s32 igbvf_read_mac_addr_vf(struct e1000_hw *hw)
  316. {
  317. int i;
  318. for (i = 0; i < ETH_ADDR_LEN; i++)
  319. hw->mac.addr[i] = hw->mac.perm_addr[i];
  320. return E1000_SUCCESS;
  321. }
  322. /**
  323. * igbvf_check_for_link_vf - Check for link for a virtual interface
  324. * @hw: pointer to the HW structure
  325. *
  326. * Checks to see if the underlying PF is still talking to the VF and
  327. * if it is then it reports the link state to the hardware, otherwise
  328. * it reports link down and returns an error.
  329. **/
  330. static s32 igbvf_check_for_link_vf(struct e1000_hw *hw)
  331. {
  332. struct e1000_mbx_info *mbx = &hw->mbx;
  333. struct e1000_mac_info *mac = &hw->mac;
  334. s32 ret_val = E1000_SUCCESS;
  335. u32 in_msg = 0;
  336. DEBUGFUNC("igbvf_check_for_link_vf");
  337. /*
  338. * We only want to run this if there has been a rst asserted.
  339. * in this case that could mean a link change, device reset,
  340. * or a virtual function reset
  341. */
  342. /* If we were hit with a reset drop the link */
  343. if (!mbx->ops.check_for_rst(hw, 0))
  344. mac->get_link_status = true;
  345. if (!mac->get_link_status)
  346. goto out;
  347. /* if link status is down no point in checking to see if pf is up */
  348. if (!(E1000_READ_REG(hw, E1000_STATUS) & E1000_STATUS_LU))
  349. goto out;
  350. /* if the read failed it could just be a mailbox collision, best wait
  351. * until we are called again and don't report an error */
  352. if (mbx->ops.read(hw, &in_msg, 1, 0))
  353. goto out;
  354. /* if incoming message isn't clear to send we are waiting on response */
  355. if (!(in_msg & E1000_VT_MSGTYPE_CTS)) {
  356. /* message is not CTS and is NACK we have lost CTS status */
  357. if (in_msg & E1000_VT_MSGTYPE_NACK)
  358. ret_val = -E1000_ERR_MAC_INIT;
  359. goto out;
  360. }
  361. /* at this point we know the PF is talking to us, check and see if
  362. * we are still accepting timeout or if we had a timeout failure.
  363. * if we failed then we will need to reinit */
  364. if (!mbx->timeout) {
  365. ret_val = -E1000_ERR_MAC_INIT;
  366. goto out;
  367. }
  368. /* if we passed all the tests above then the link is up and we no
  369. * longer need to check for link */
  370. mac->get_link_status = false;
  371. out:
  372. return ret_val;
  373. }