manage.c 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367
  1. /*******************************************************************************
  2. Intel PRO/1000 Linux driver
  3. Copyright(c) 1999 - 2012 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. #include "e1000.h"
  22. enum e1000_mng_mode {
  23. e1000_mng_mode_none = 0,
  24. e1000_mng_mode_asf,
  25. e1000_mng_mode_pt,
  26. e1000_mng_mode_ipmi,
  27. e1000_mng_mode_host_if_only
  28. };
  29. #define E1000_FACTPS_MNGCG 0x20000000
  30. /* Intel(R) Active Management Technology signature */
  31. #define E1000_IAMT_SIGNATURE 0x544D4149
  32. /**
  33. * e1000_calculate_checksum - Calculate checksum for buffer
  34. * @buffer: pointer to EEPROM
  35. * @length: size of EEPROM to calculate a checksum for
  36. *
  37. * Calculates the checksum for some buffer on a specified length. The
  38. * checksum calculated is returned.
  39. **/
  40. static u8 e1000_calculate_checksum(u8 *buffer, u32 length)
  41. {
  42. u32 i;
  43. u8 sum = 0;
  44. if (!buffer)
  45. return 0;
  46. for (i = 0; i < length; i++)
  47. sum += buffer[i];
  48. return (u8)(0 - sum);
  49. }
  50. /**
  51. * e1000_mng_enable_host_if - Checks host interface is enabled
  52. * @hw: pointer to the HW structure
  53. *
  54. * Returns E1000_success upon success, else E1000_ERR_HOST_INTERFACE_COMMAND
  55. *
  56. * This function checks whether the HOST IF is enabled for command operation
  57. * and also checks whether the previous command is completed. It busy waits
  58. * in case of previous command is not completed.
  59. **/
  60. static s32 e1000_mng_enable_host_if(struct e1000_hw *hw)
  61. {
  62. u32 hicr;
  63. u8 i;
  64. if (!hw->mac.arc_subsystem_valid) {
  65. e_dbg("ARC subsystem not valid.\n");
  66. return -E1000_ERR_HOST_INTERFACE_COMMAND;
  67. }
  68. /* Check that the host interface is enabled. */
  69. hicr = er32(HICR);
  70. if (!(hicr & E1000_HICR_EN)) {
  71. e_dbg("E1000_HOST_EN bit disabled.\n");
  72. return -E1000_ERR_HOST_INTERFACE_COMMAND;
  73. }
  74. /* check the previous command is completed */
  75. for (i = 0; i < E1000_MNG_DHCP_COMMAND_TIMEOUT; i++) {
  76. hicr = er32(HICR);
  77. if (!(hicr & E1000_HICR_C))
  78. break;
  79. mdelay(1);
  80. }
  81. if (i == E1000_MNG_DHCP_COMMAND_TIMEOUT) {
  82. e_dbg("Previous command timeout failed .\n");
  83. return -E1000_ERR_HOST_INTERFACE_COMMAND;
  84. }
  85. return 0;
  86. }
  87. /**
  88. * e1000e_check_mng_mode_generic - Generic check management mode
  89. * @hw: pointer to the HW structure
  90. *
  91. * Reads the firmware semaphore register and returns true (>0) if
  92. * manageability is enabled, else false (0).
  93. **/
  94. bool e1000e_check_mng_mode_generic(struct e1000_hw *hw)
  95. {
  96. u32 fwsm = er32(FWSM);
  97. return (fwsm & E1000_FWSM_MODE_MASK) ==
  98. (E1000_MNG_IAMT_MODE << E1000_FWSM_MODE_SHIFT);
  99. }
  100. /**
  101. * e1000e_enable_tx_pkt_filtering - Enable packet filtering on Tx
  102. * @hw: pointer to the HW structure
  103. *
  104. * Enables packet filtering on transmit packets if manageability is enabled
  105. * and host interface is enabled.
  106. **/
  107. bool e1000e_enable_tx_pkt_filtering(struct e1000_hw *hw)
  108. {
  109. struct e1000_host_mng_dhcp_cookie *hdr = &hw->mng_cookie;
  110. u32 *buffer = (u32 *)&hw->mng_cookie;
  111. u32 offset;
  112. s32 ret_val, hdr_csum, csum;
  113. u8 i, len;
  114. hw->mac.tx_pkt_filtering = true;
  115. /* No manageability, no filtering */
  116. if (!hw->mac.ops.check_mng_mode(hw)) {
  117. hw->mac.tx_pkt_filtering = false;
  118. return hw->mac.tx_pkt_filtering;
  119. }
  120. /*
  121. * If we can't read from the host interface for whatever
  122. * reason, disable filtering.
  123. */
  124. ret_val = e1000_mng_enable_host_if(hw);
  125. if (ret_val) {
  126. hw->mac.tx_pkt_filtering = false;
  127. return hw->mac.tx_pkt_filtering;
  128. }
  129. /* Read in the header. Length and offset are in dwords. */
  130. len = E1000_MNG_DHCP_COOKIE_LENGTH >> 2;
  131. offset = E1000_MNG_DHCP_COOKIE_OFFSET >> 2;
  132. for (i = 0; i < len; i++)
  133. *(buffer + i) = E1000_READ_REG_ARRAY(hw, E1000_HOST_IF,
  134. offset + i);
  135. hdr_csum = hdr->checksum;
  136. hdr->checksum = 0;
  137. csum = e1000_calculate_checksum((u8 *)hdr,
  138. E1000_MNG_DHCP_COOKIE_LENGTH);
  139. /*
  140. * If either the checksums or signature don't match, then
  141. * the cookie area isn't considered valid, in which case we
  142. * take the safe route of assuming Tx filtering is enabled.
  143. */
  144. if ((hdr_csum != csum) || (hdr->signature != E1000_IAMT_SIGNATURE)) {
  145. hw->mac.tx_pkt_filtering = true;
  146. return hw->mac.tx_pkt_filtering;
  147. }
  148. /* Cookie area is valid, make the final check for filtering. */
  149. if (!(hdr->status & E1000_MNG_DHCP_COOKIE_STATUS_PARSING))
  150. hw->mac.tx_pkt_filtering = false;
  151. return hw->mac.tx_pkt_filtering;
  152. }
  153. /**
  154. * e1000_mng_write_cmd_header - Writes manageability command header
  155. * @hw: pointer to the HW structure
  156. * @hdr: pointer to the host interface command header
  157. *
  158. * Writes the command header after does the checksum calculation.
  159. **/
  160. static s32 e1000_mng_write_cmd_header(struct e1000_hw *hw,
  161. struct e1000_host_mng_command_header *hdr)
  162. {
  163. u16 i, length = sizeof(struct e1000_host_mng_command_header);
  164. /* Write the whole command header structure with new checksum. */
  165. hdr->checksum = e1000_calculate_checksum((u8 *)hdr, length);
  166. length >>= 2;
  167. /* Write the relevant command block into the ram area. */
  168. for (i = 0; i < length; i++) {
  169. E1000_WRITE_REG_ARRAY(hw, E1000_HOST_IF, i, *((u32 *)hdr + i));
  170. e1e_flush();
  171. }
  172. return 0;
  173. }
  174. /**
  175. * e1000_mng_host_if_write - Write to the manageability host interface
  176. * @hw: pointer to the HW structure
  177. * @buffer: pointer to the host interface buffer
  178. * @length: size of the buffer
  179. * @offset: location in the buffer to write to
  180. * @sum: sum of the data (not checksum)
  181. *
  182. * This function writes the buffer content at the offset given on the host if.
  183. * It also does alignment considerations to do the writes in most efficient
  184. * way. Also fills up the sum of the buffer in *buffer parameter.
  185. **/
  186. static s32 e1000_mng_host_if_write(struct e1000_hw *hw, u8 *buffer,
  187. u16 length, u16 offset, u8 *sum)
  188. {
  189. u8 *tmp;
  190. u8 *bufptr = buffer;
  191. u32 data = 0;
  192. u16 remaining, i, j, prev_bytes;
  193. /* sum = only sum of the data and it is not checksum */
  194. if (length == 0 || offset + length > E1000_HI_MAX_MNG_DATA_LENGTH)
  195. return -E1000_ERR_PARAM;
  196. tmp = (u8 *)&data;
  197. prev_bytes = offset & 0x3;
  198. offset >>= 2;
  199. if (prev_bytes) {
  200. data = E1000_READ_REG_ARRAY(hw, E1000_HOST_IF, offset);
  201. for (j = prev_bytes; j < sizeof(u32); j++) {
  202. *(tmp + j) = *bufptr++;
  203. *sum += *(tmp + j);
  204. }
  205. E1000_WRITE_REG_ARRAY(hw, E1000_HOST_IF, offset, data);
  206. length -= j - prev_bytes;
  207. offset++;
  208. }
  209. remaining = length & 0x3;
  210. length -= remaining;
  211. /* Calculate length in DWORDs */
  212. length >>= 2;
  213. /*
  214. * The device driver writes the relevant command block into the
  215. * ram area.
  216. */
  217. for (i = 0; i < length; i++) {
  218. for (j = 0; j < sizeof(u32); j++) {
  219. *(tmp + j) = *bufptr++;
  220. *sum += *(tmp + j);
  221. }
  222. E1000_WRITE_REG_ARRAY(hw, E1000_HOST_IF, offset + i, data);
  223. }
  224. if (remaining) {
  225. for (j = 0; j < sizeof(u32); j++) {
  226. if (j < remaining)
  227. *(tmp + j) = *bufptr++;
  228. else
  229. *(tmp + j) = 0;
  230. *sum += *(tmp + j);
  231. }
  232. E1000_WRITE_REG_ARRAY(hw, E1000_HOST_IF, offset + i, data);
  233. }
  234. return 0;
  235. }
  236. /**
  237. * e1000e_mng_write_dhcp_info - Writes DHCP info to host interface
  238. * @hw: pointer to the HW structure
  239. * @buffer: pointer to the host interface
  240. * @length: size of the buffer
  241. *
  242. * Writes the DHCP information to the host interface.
  243. **/
  244. s32 e1000e_mng_write_dhcp_info(struct e1000_hw *hw, u8 *buffer, u16 length)
  245. {
  246. struct e1000_host_mng_command_header hdr;
  247. s32 ret_val;
  248. u32 hicr;
  249. hdr.command_id = E1000_MNG_DHCP_TX_PAYLOAD_CMD;
  250. hdr.command_length = length;
  251. hdr.reserved1 = 0;
  252. hdr.reserved2 = 0;
  253. hdr.checksum = 0;
  254. /* Enable the host interface */
  255. ret_val = e1000_mng_enable_host_if(hw);
  256. if (ret_val)
  257. return ret_val;
  258. /* Populate the host interface with the contents of "buffer". */
  259. ret_val = e1000_mng_host_if_write(hw, buffer, length,
  260. sizeof(hdr), &(hdr.checksum));
  261. if (ret_val)
  262. return ret_val;
  263. /* Write the manageability command header */
  264. ret_val = e1000_mng_write_cmd_header(hw, &hdr);
  265. if (ret_val)
  266. return ret_val;
  267. /* Tell the ARC a new command is pending. */
  268. hicr = er32(HICR);
  269. ew32(HICR, hicr | E1000_HICR_C);
  270. return 0;
  271. }
  272. /**
  273. * e1000e_enable_mng_pass_thru - Check if management passthrough is needed
  274. * @hw: pointer to the HW structure
  275. *
  276. * Verifies the hardware needs to leave interface enabled so that frames can
  277. * be directed to and from the management interface.
  278. **/
  279. bool e1000e_enable_mng_pass_thru(struct e1000_hw *hw)
  280. {
  281. u32 manc;
  282. u32 fwsm, factps;
  283. manc = er32(MANC);
  284. if (!(manc & E1000_MANC_RCV_TCO_EN))
  285. return false;
  286. if (hw->mac.has_fwsm) {
  287. fwsm = er32(FWSM);
  288. factps = er32(FACTPS);
  289. if (!(factps & E1000_FACTPS_MNGCG) &&
  290. ((fwsm & E1000_FWSM_MODE_MASK) ==
  291. (e1000_mng_mode_pt << E1000_FWSM_MODE_SHIFT)))
  292. return true;
  293. } else if ((hw->mac.type == e1000_82574) ||
  294. (hw->mac.type == e1000_82583)) {
  295. u16 data;
  296. factps = er32(FACTPS);
  297. e1000_read_nvm(hw, NVM_INIT_CONTROL2_REG, 1, &data);
  298. if (!(factps & E1000_FACTPS_MNGCG) &&
  299. ((data & E1000_NVM_INIT_CTRL2_MNGM) ==
  300. (e1000_mng_mode_pt << 13)))
  301. return true;
  302. } else if ((manc & E1000_MANC_SMBUS_EN) &&
  303. !(manc & E1000_MANC_ASF_EN)) {
  304. return true;
  305. }
  306. return false;
  307. }