ixgbe_common.c 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179
  1. /*******************************************************************************
  2. Intel 10 Gigabit PCI Express Linux driver
  3. Copyright(c) 1999 - 2007 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 <linux/pci.h>
  22. #include <linux/delay.h>
  23. #include <linux/sched.h>
  24. #include "ixgbe_common.h"
  25. #include "ixgbe_phy.h"
  26. static s32 ixgbe_clear_hw_cntrs(struct ixgbe_hw *hw);
  27. static s32 ixgbe_poll_eeprom_eerd_done(struct ixgbe_hw *hw);
  28. static s32 ixgbe_get_eeprom_semaphore(struct ixgbe_hw *hw);
  29. static void ixgbe_release_eeprom_semaphore(struct ixgbe_hw *hw);
  30. static u16 ixgbe_calc_eeprom_checksum(struct ixgbe_hw *hw);
  31. static s32 ixgbe_clear_vfta(struct ixgbe_hw *hw);
  32. static s32 ixgbe_init_rx_addrs(struct ixgbe_hw *hw);
  33. static s32 ixgbe_mta_vector(struct ixgbe_hw *hw, u8 *mc_addr);
  34. static void ixgbe_add_mc_addr(struct ixgbe_hw *hw, u8 *mc_addr);
  35. /**
  36. * ixgbe_start_hw - 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. s32 ixgbe_start_hw(struct ixgbe_hw *hw)
  45. {
  46. u32 ctrl_ext;
  47. /* Set the media type */
  48. hw->phy.media_type = hw->mac.ops.get_media_type(hw);
  49. /* Identify the PHY */
  50. ixgbe_identify_phy(hw);
  51. /*
  52. * Store MAC address from RAR0, clear receive address registers, and
  53. * clear the multicast table
  54. */
  55. ixgbe_init_rx_addrs(hw);
  56. /* Clear the VLAN filter table */
  57. ixgbe_clear_vfta(hw);
  58. /* Set up link */
  59. hw->mac.ops.setup_link(hw);
  60. /* Clear statistics registers */
  61. ixgbe_clear_hw_cntrs(hw);
  62. /* Set No Snoop Disable */
  63. ctrl_ext = IXGBE_READ_REG(hw, IXGBE_CTRL_EXT);
  64. ctrl_ext |= IXGBE_CTRL_EXT_NS_DIS;
  65. IXGBE_WRITE_REG(hw, IXGBE_CTRL_EXT, ctrl_ext);
  66. IXGBE_WRITE_FLUSH(hw);
  67. /* Clear adapter stopped flag */
  68. hw->adapter_stopped = false;
  69. return 0;
  70. }
  71. /**
  72. * ixgbe_init_hw - Generic hardware initialization
  73. * @hw: pointer to hardware structure
  74. *
  75. * Initialize the hardware by reseting the hardware, filling the bus info
  76. * structure and media type, clears all on chip counters, initializes receive
  77. * address registers, multicast table, VLAN filter table, calls routine to set
  78. * up link and flow control settings, and leaves transmit and receive units
  79. * disabled and uninitialized
  80. **/
  81. s32 ixgbe_init_hw(struct ixgbe_hw *hw)
  82. {
  83. /* Reset the hardware */
  84. hw->mac.ops.reset(hw);
  85. /* Start the HW */
  86. ixgbe_start_hw(hw);
  87. return 0;
  88. }
  89. /**
  90. * ixgbe_clear_hw_cntrs - Generic clear hardware counters
  91. * @hw: pointer to hardware structure
  92. *
  93. * Clears all hardware statistics counters by reading them from the hardware
  94. * Statistics counters are clear on read.
  95. **/
  96. static s32 ixgbe_clear_hw_cntrs(struct ixgbe_hw *hw)
  97. {
  98. u16 i = 0;
  99. IXGBE_READ_REG(hw, IXGBE_CRCERRS);
  100. IXGBE_READ_REG(hw, IXGBE_ILLERRC);
  101. IXGBE_READ_REG(hw, IXGBE_ERRBC);
  102. IXGBE_READ_REG(hw, IXGBE_MSPDC);
  103. for (i = 0; i < 8; i++)
  104. IXGBE_READ_REG(hw, IXGBE_MPC(i));
  105. IXGBE_READ_REG(hw, IXGBE_MLFC);
  106. IXGBE_READ_REG(hw, IXGBE_MRFC);
  107. IXGBE_READ_REG(hw, IXGBE_RLEC);
  108. IXGBE_READ_REG(hw, IXGBE_LXONTXC);
  109. IXGBE_READ_REG(hw, IXGBE_LXONRXC);
  110. IXGBE_READ_REG(hw, IXGBE_LXOFFTXC);
  111. IXGBE_READ_REG(hw, IXGBE_LXOFFRXC);
  112. for (i = 0; i < 8; i++) {
  113. IXGBE_READ_REG(hw, IXGBE_PXONTXC(i));
  114. IXGBE_READ_REG(hw, IXGBE_PXONRXC(i));
  115. IXGBE_READ_REG(hw, IXGBE_PXOFFTXC(i));
  116. IXGBE_READ_REG(hw, IXGBE_PXOFFRXC(i));
  117. }
  118. IXGBE_READ_REG(hw, IXGBE_PRC64);
  119. IXGBE_READ_REG(hw, IXGBE_PRC127);
  120. IXGBE_READ_REG(hw, IXGBE_PRC255);
  121. IXGBE_READ_REG(hw, IXGBE_PRC511);
  122. IXGBE_READ_REG(hw, IXGBE_PRC1023);
  123. IXGBE_READ_REG(hw, IXGBE_PRC1522);
  124. IXGBE_READ_REG(hw, IXGBE_GPRC);
  125. IXGBE_READ_REG(hw, IXGBE_BPRC);
  126. IXGBE_READ_REG(hw, IXGBE_MPRC);
  127. IXGBE_READ_REG(hw, IXGBE_GPTC);
  128. IXGBE_READ_REG(hw, IXGBE_GORCL);
  129. IXGBE_READ_REG(hw, IXGBE_GORCH);
  130. IXGBE_READ_REG(hw, IXGBE_GOTCL);
  131. IXGBE_READ_REG(hw, IXGBE_GOTCH);
  132. for (i = 0; i < 8; i++)
  133. IXGBE_READ_REG(hw, IXGBE_RNBC(i));
  134. IXGBE_READ_REG(hw, IXGBE_RUC);
  135. IXGBE_READ_REG(hw, IXGBE_RFC);
  136. IXGBE_READ_REG(hw, IXGBE_ROC);
  137. IXGBE_READ_REG(hw, IXGBE_RJC);
  138. IXGBE_READ_REG(hw, IXGBE_MNGPRC);
  139. IXGBE_READ_REG(hw, IXGBE_MNGPDC);
  140. IXGBE_READ_REG(hw, IXGBE_MNGPTC);
  141. IXGBE_READ_REG(hw, IXGBE_TORL);
  142. IXGBE_READ_REG(hw, IXGBE_TORH);
  143. IXGBE_READ_REG(hw, IXGBE_TPR);
  144. IXGBE_READ_REG(hw, IXGBE_TPT);
  145. IXGBE_READ_REG(hw, IXGBE_PTC64);
  146. IXGBE_READ_REG(hw, IXGBE_PTC127);
  147. IXGBE_READ_REG(hw, IXGBE_PTC255);
  148. IXGBE_READ_REG(hw, IXGBE_PTC511);
  149. IXGBE_READ_REG(hw, IXGBE_PTC1023);
  150. IXGBE_READ_REG(hw, IXGBE_PTC1522);
  151. IXGBE_READ_REG(hw, IXGBE_MPTC);
  152. IXGBE_READ_REG(hw, IXGBE_BPTC);
  153. for (i = 0; i < 16; i++) {
  154. IXGBE_READ_REG(hw, IXGBE_QPRC(i));
  155. IXGBE_READ_REG(hw, IXGBE_QBRC(i));
  156. IXGBE_READ_REG(hw, IXGBE_QPTC(i));
  157. IXGBE_READ_REG(hw, IXGBE_QBTC(i));
  158. }
  159. return 0;
  160. }
  161. /**
  162. * ixgbe_get_mac_addr - Generic get MAC address
  163. * @hw: pointer to hardware structure
  164. * @mac_addr: Adapter MAC address
  165. *
  166. * Reads the adapter's MAC address from first Receive Address Register (RAR0)
  167. * A reset of the adapter must be performed prior to calling this function
  168. * in order for the MAC address to have been loaded from the EEPROM into RAR0
  169. **/
  170. s32 ixgbe_get_mac_addr(struct ixgbe_hw *hw, u8 *mac_addr)
  171. {
  172. u32 rar_high;
  173. u32 rar_low;
  174. u16 i;
  175. rar_high = IXGBE_READ_REG(hw, IXGBE_RAH(0));
  176. rar_low = IXGBE_READ_REG(hw, IXGBE_RAL(0));
  177. for (i = 0; i < 4; i++)
  178. mac_addr[i] = (u8)(rar_low >> (i*8));
  179. for (i = 0; i < 2; i++)
  180. mac_addr[i+4] = (u8)(rar_high >> (i*8));
  181. return 0;
  182. }
  183. s32 ixgbe_read_part_num(struct ixgbe_hw *hw, u32 *part_num)
  184. {
  185. s32 ret_val;
  186. u16 data;
  187. ret_val = ixgbe_read_eeprom(hw, IXGBE_PBANUM0_PTR, &data);
  188. if (ret_val) {
  189. hw_dbg(hw, "NVM Read Error\n");
  190. return ret_val;
  191. }
  192. *part_num = (u32)(data << 16);
  193. ret_val = ixgbe_read_eeprom(hw, IXGBE_PBANUM1_PTR, &data);
  194. if (ret_val) {
  195. hw_dbg(hw, "NVM Read Error\n");
  196. return ret_val;
  197. }
  198. *part_num |= data;
  199. return 0;
  200. }
  201. /**
  202. * ixgbe_stop_adapter - Generic stop TX/RX units
  203. * @hw: pointer to hardware structure
  204. *
  205. * Sets the adapter_stopped flag within ixgbe_hw struct. Clears interrupts,
  206. * disables transmit and receive units. The adapter_stopped flag is used by
  207. * the shared code and drivers to determine if the adapter is in a stopped
  208. * state and should not touch the hardware.
  209. **/
  210. s32 ixgbe_stop_adapter(struct ixgbe_hw *hw)
  211. {
  212. u32 number_of_queues;
  213. u32 reg_val;
  214. u16 i;
  215. /*
  216. * Set the adapter_stopped flag so other driver functions stop touching
  217. * the hardware
  218. */
  219. hw->adapter_stopped = true;
  220. /* Disable the receive unit */
  221. reg_val = IXGBE_READ_REG(hw, IXGBE_RXCTRL);
  222. reg_val &= ~(IXGBE_RXCTRL_RXEN);
  223. IXGBE_WRITE_REG(hw, IXGBE_RXCTRL, reg_val);
  224. msleep(2);
  225. /* Clear interrupt mask to stop from interrupts being generated */
  226. IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_IRQ_CLEAR_MASK);
  227. /* Clear any pending interrupts */
  228. IXGBE_READ_REG(hw, IXGBE_EICR);
  229. /* Disable the transmit unit. Each queue must be disabled. */
  230. number_of_queues = hw->mac.num_tx_queues;
  231. for (i = 0; i < number_of_queues; i++) {
  232. reg_val = IXGBE_READ_REG(hw, IXGBE_TXDCTL(i));
  233. if (reg_val & IXGBE_TXDCTL_ENABLE) {
  234. reg_val &= ~IXGBE_TXDCTL_ENABLE;
  235. IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(i), reg_val);
  236. }
  237. }
  238. return 0;
  239. }
  240. /**
  241. * ixgbe_led_on - Turns on the software controllable LEDs.
  242. * @hw: pointer to hardware structure
  243. * @index: led number to turn on
  244. **/
  245. s32 ixgbe_led_on(struct ixgbe_hw *hw, u32 index)
  246. {
  247. u32 led_reg = IXGBE_READ_REG(hw, IXGBE_LEDCTL);
  248. /* To turn on the LED, set mode to ON. */
  249. led_reg &= ~IXGBE_LED_MODE_MASK(index);
  250. led_reg |= IXGBE_LED_ON << IXGBE_LED_MODE_SHIFT(index);
  251. IXGBE_WRITE_REG(hw, IXGBE_LEDCTL, led_reg);
  252. IXGBE_WRITE_FLUSH(hw);
  253. return 0;
  254. }
  255. /**
  256. * ixgbe_led_off - Turns off the software controllable LEDs.
  257. * @hw: pointer to hardware structure
  258. * @index: led number to turn off
  259. **/
  260. s32 ixgbe_led_off(struct ixgbe_hw *hw, u32 index)
  261. {
  262. u32 led_reg = IXGBE_READ_REG(hw, IXGBE_LEDCTL);
  263. /* To turn off the LED, set mode to OFF. */
  264. led_reg &= ~IXGBE_LED_MODE_MASK(index);
  265. led_reg |= IXGBE_LED_OFF << IXGBE_LED_MODE_SHIFT(index);
  266. IXGBE_WRITE_REG(hw, IXGBE_LEDCTL, led_reg);
  267. IXGBE_WRITE_FLUSH(hw);
  268. return 0;
  269. }
  270. /**
  271. * ixgbe_init_eeprom - Initialize EEPROM params
  272. * @hw: pointer to hardware structure
  273. *
  274. * Initializes the EEPROM parameters ixgbe_eeprom_info within the
  275. * ixgbe_hw struct in order to set up EEPROM access.
  276. **/
  277. s32 ixgbe_init_eeprom(struct ixgbe_hw *hw)
  278. {
  279. struct ixgbe_eeprom_info *eeprom = &hw->eeprom;
  280. u32 eec;
  281. u16 eeprom_size;
  282. if (eeprom->type == ixgbe_eeprom_uninitialized) {
  283. eeprom->type = ixgbe_eeprom_none;
  284. /*
  285. * Check for EEPROM present first.
  286. * If not present leave as none
  287. */
  288. eec = IXGBE_READ_REG(hw, IXGBE_EEC);
  289. if (eec & IXGBE_EEC_PRES) {
  290. eeprom->type = ixgbe_eeprom_spi;
  291. /*
  292. * SPI EEPROM is assumed here. This code would need to
  293. * change if a future EEPROM is not SPI.
  294. */
  295. eeprom_size = (u16)((eec & IXGBE_EEC_SIZE) >>
  296. IXGBE_EEC_SIZE_SHIFT);
  297. eeprom->word_size = 1 << (eeprom_size +
  298. IXGBE_EEPROM_WORD_SIZE_SHIFT);
  299. }
  300. if (eec & IXGBE_EEC_ADDR_SIZE)
  301. eeprom->address_bits = 16;
  302. else
  303. eeprom->address_bits = 8;
  304. hw_dbg(hw, "Eeprom params: type = %d, size = %d, address bits: "
  305. "%d\n", eeprom->type, eeprom->word_size,
  306. eeprom->address_bits);
  307. }
  308. return 0;
  309. }
  310. /**
  311. * ixgbe_read_eeprom - Read EEPROM word using EERD
  312. * @hw: pointer to hardware structure
  313. * @offset: offset of word in the EEPROM to read
  314. * @data: word read from the EEPROM
  315. *
  316. * Reads a 16 bit word from the EEPROM using the EERD register.
  317. **/
  318. s32 ixgbe_read_eeprom(struct ixgbe_hw *hw, u16 offset, u16 *data)
  319. {
  320. u32 eerd;
  321. s32 status;
  322. eerd = (offset << IXGBE_EEPROM_READ_ADDR_SHIFT) +
  323. IXGBE_EEPROM_READ_REG_START;
  324. IXGBE_WRITE_REG(hw, IXGBE_EERD, eerd);
  325. status = ixgbe_poll_eeprom_eerd_done(hw);
  326. if (status == 0)
  327. *data = (IXGBE_READ_REG(hw, IXGBE_EERD) >>
  328. IXGBE_EEPROM_READ_REG_DATA);
  329. else
  330. hw_dbg(hw, "Eeprom read timed out\n");
  331. return status;
  332. }
  333. /**
  334. * ixgbe_poll_eeprom_eerd_done - Poll EERD status
  335. * @hw: pointer to hardware structure
  336. *
  337. * Polls the status bit (bit 1) of the EERD to determine when the read is done.
  338. **/
  339. static s32 ixgbe_poll_eeprom_eerd_done(struct ixgbe_hw *hw)
  340. {
  341. u32 i;
  342. u32 reg;
  343. s32 status = IXGBE_ERR_EEPROM;
  344. for (i = 0; i < IXGBE_EERD_ATTEMPTS; i++) {
  345. reg = IXGBE_READ_REG(hw, IXGBE_EERD);
  346. if (reg & IXGBE_EEPROM_READ_REG_DONE) {
  347. status = 0;
  348. break;
  349. }
  350. udelay(5);
  351. }
  352. return status;
  353. }
  354. /**
  355. * ixgbe_get_eeprom_semaphore - Get hardware semaphore
  356. * @hw: pointer to hardware structure
  357. *
  358. * Sets the hardware semaphores so EEPROM access can occur for bit-bang method
  359. **/
  360. static s32 ixgbe_get_eeprom_semaphore(struct ixgbe_hw *hw)
  361. {
  362. s32 status = IXGBE_ERR_EEPROM;
  363. u32 timeout;
  364. u32 i;
  365. u32 swsm;
  366. /* Set timeout value based on size of EEPROM */
  367. timeout = hw->eeprom.word_size + 1;
  368. /* Get SMBI software semaphore between device drivers first */
  369. for (i = 0; i < timeout; i++) {
  370. /*
  371. * If the SMBI bit is 0 when we read it, then the bit will be
  372. * set and we have the semaphore
  373. */
  374. swsm = IXGBE_READ_REG(hw, IXGBE_SWSM);
  375. if (!(swsm & IXGBE_SWSM_SMBI)) {
  376. status = 0;
  377. break;
  378. }
  379. msleep(1);
  380. }
  381. /* Now get the semaphore between SW/FW through the SWESMBI bit */
  382. if (status == 0) {
  383. for (i = 0; i < timeout; i++) {
  384. swsm = IXGBE_READ_REG(hw, IXGBE_SWSM);
  385. /* Set the SW EEPROM semaphore bit to request access */
  386. swsm |= IXGBE_SWSM_SWESMBI;
  387. IXGBE_WRITE_REG(hw, IXGBE_SWSM, swsm);
  388. /*
  389. * If we set the bit successfully then we got the
  390. * semaphore.
  391. */
  392. swsm = IXGBE_READ_REG(hw, IXGBE_SWSM);
  393. if (swsm & IXGBE_SWSM_SWESMBI)
  394. break;
  395. udelay(50);
  396. }
  397. /*
  398. * Release semaphores and return error if SW EEPROM semaphore
  399. * was not granted because we don't have access to the EEPROM
  400. */
  401. if (i >= timeout) {
  402. hw_dbg(hw, "Driver can't access the Eeprom - Semaphore "
  403. "not granted.\n");
  404. ixgbe_release_eeprom_semaphore(hw);
  405. status = IXGBE_ERR_EEPROM;
  406. }
  407. }
  408. return status;
  409. }
  410. /**
  411. * ixgbe_release_eeprom_semaphore - Release hardware semaphore
  412. * @hw: pointer to hardware structure
  413. *
  414. * This function clears hardware semaphore bits.
  415. **/
  416. static void ixgbe_release_eeprom_semaphore(struct ixgbe_hw *hw)
  417. {
  418. u32 swsm;
  419. swsm = IXGBE_READ_REG(hw, IXGBE_SWSM);
  420. /* Release both semaphores by writing 0 to the bits SWESMBI and SMBI */
  421. swsm &= ~(IXGBE_SWSM_SWESMBI | IXGBE_SWSM_SMBI);
  422. IXGBE_WRITE_REG(hw, IXGBE_SWSM, swsm);
  423. IXGBE_WRITE_FLUSH(hw);
  424. }
  425. /**
  426. * ixgbe_calc_eeprom_checksum - Calculates and returns the checksum
  427. * @hw: pointer to hardware structure
  428. **/
  429. static u16 ixgbe_calc_eeprom_checksum(struct ixgbe_hw *hw)
  430. {
  431. u16 i;
  432. u16 j;
  433. u16 checksum = 0;
  434. u16 length = 0;
  435. u16 pointer = 0;
  436. u16 word = 0;
  437. /* Include 0x0-0x3F in the checksum */
  438. for (i = 0; i < IXGBE_EEPROM_CHECKSUM; i++) {
  439. if (ixgbe_read_eeprom(hw, i, &word) != 0) {
  440. hw_dbg(hw, "EEPROM read failed\n");
  441. break;
  442. }
  443. checksum += word;
  444. }
  445. /* Include all data from pointers except for the fw pointer */
  446. for (i = IXGBE_PCIE_ANALOG_PTR; i < IXGBE_FW_PTR; i++) {
  447. ixgbe_read_eeprom(hw, i, &pointer);
  448. /* Make sure the pointer seems valid */
  449. if (pointer != 0xFFFF && pointer != 0) {
  450. ixgbe_read_eeprom(hw, pointer, &length);
  451. if (length != 0xFFFF && length != 0) {
  452. for (j = pointer+1; j <= pointer+length; j++) {
  453. ixgbe_read_eeprom(hw, j, &word);
  454. checksum += word;
  455. }
  456. }
  457. }
  458. }
  459. checksum = (u16)IXGBE_EEPROM_SUM - checksum;
  460. return checksum;
  461. }
  462. /**
  463. * ixgbe_validate_eeprom_checksum - Validate EEPROM checksum
  464. * @hw: pointer to hardware structure
  465. * @checksum_val: calculated checksum
  466. *
  467. * Performs checksum calculation and validates the EEPROM checksum. If the
  468. * caller does not need checksum_val, the value can be NULL.
  469. **/
  470. s32 ixgbe_validate_eeprom_checksum(struct ixgbe_hw *hw, u16 *checksum_val)
  471. {
  472. s32 status;
  473. u16 checksum;
  474. u16 read_checksum = 0;
  475. /*
  476. * Read the first word from the EEPROM. If this times out or fails, do
  477. * not continue or we could be in for a very long wait while every
  478. * EEPROM read fails
  479. */
  480. status = ixgbe_read_eeprom(hw, 0, &checksum);
  481. if (status == 0) {
  482. checksum = ixgbe_calc_eeprom_checksum(hw);
  483. ixgbe_read_eeprom(hw, IXGBE_EEPROM_CHECKSUM, &read_checksum);
  484. /*
  485. * Verify read checksum from EEPROM is the same as
  486. * calculated checksum
  487. */
  488. if (read_checksum != checksum)
  489. status = IXGBE_ERR_EEPROM_CHECKSUM;
  490. /* If the user cares, return the calculated checksum */
  491. if (checksum_val)
  492. *checksum_val = checksum;
  493. } else {
  494. hw_dbg(hw, "EEPROM read failed\n");
  495. }
  496. return status;
  497. }
  498. /**
  499. * ixgbe_validate_mac_addr - Validate MAC address
  500. * @mac_addr: pointer to MAC address.
  501. *
  502. * Tests a MAC address to ensure it is a valid Individual Address
  503. **/
  504. s32 ixgbe_validate_mac_addr(u8 *mac_addr)
  505. {
  506. s32 status = 0;
  507. /* Make sure it is not a multicast address */
  508. if (IXGBE_IS_MULTICAST(mac_addr))
  509. status = IXGBE_ERR_INVALID_MAC_ADDR;
  510. /* Not a broadcast address */
  511. else if (IXGBE_IS_BROADCAST(mac_addr))
  512. status = IXGBE_ERR_INVALID_MAC_ADDR;
  513. /* Reject the zero address */
  514. else if (mac_addr[0] == 0 && mac_addr[1] == 0 && mac_addr[2] == 0 &&
  515. mac_addr[3] == 0 && mac_addr[4] == 0 && mac_addr[5] == 0)
  516. status = IXGBE_ERR_INVALID_MAC_ADDR;
  517. return status;
  518. }
  519. /**
  520. * ixgbe_set_rar - Set RX address register
  521. * @hw: pointer to hardware structure
  522. * @addr: Address to put into receive address register
  523. * @index: Receive address register to write
  524. * @vind: Vind to set RAR to
  525. * @enable_addr: set flag that address is active
  526. *
  527. * Puts an ethernet address into a receive address register.
  528. **/
  529. s32 ixgbe_set_rar(struct ixgbe_hw *hw, u32 index, u8 *addr, u32 vind,
  530. u32 enable_addr)
  531. {
  532. u32 rar_low, rar_high;
  533. /*
  534. * HW expects these in little endian so we reverse the byte order from
  535. * network order (big endian) to little endian
  536. */
  537. rar_low = ((u32)addr[0] |
  538. ((u32)addr[1] << 8) |
  539. ((u32)addr[2] << 16) |
  540. ((u32)addr[3] << 24));
  541. rar_high = ((u32)addr[4] |
  542. ((u32)addr[5] << 8) |
  543. ((vind << IXGBE_RAH_VIND_SHIFT) & IXGBE_RAH_VIND_MASK));
  544. if (enable_addr != 0)
  545. rar_high |= IXGBE_RAH_AV;
  546. IXGBE_WRITE_REG(hw, IXGBE_RAL(index), rar_low);
  547. IXGBE_WRITE_REG(hw, IXGBE_RAH(index), rar_high);
  548. return 0;
  549. }
  550. /**
  551. * ixgbe_init_rx_addrs - Initializes receive address filters.
  552. * @hw: pointer to hardware structure
  553. *
  554. * Places the MAC address in receive address register 0 and clears the rest
  555. * of the receive addresss registers. Clears the multicast table. Assumes
  556. * the receiver is in reset when the routine is called.
  557. **/
  558. static s32 ixgbe_init_rx_addrs(struct ixgbe_hw *hw)
  559. {
  560. u32 i;
  561. u32 rar_entries = hw->mac.num_rx_addrs;
  562. /*
  563. * If the current mac address is valid, assume it is a software override
  564. * to the permanent address.
  565. * Otherwise, use the permanent address from the eeprom.
  566. */
  567. if (ixgbe_validate_mac_addr(hw->mac.addr) ==
  568. IXGBE_ERR_INVALID_MAC_ADDR) {
  569. /* Get the MAC address from the RAR0 for later reference */
  570. ixgbe_get_mac_addr(hw, hw->mac.addr);
  571. hw_dbg(hw, " Keeping Current RAR0 Addr =%.2X %.2X %.2X ",
  572. hw->mac.addr[0], hw->mac.addr[1],
  573. hw->mac.addr[2]);
  574. hw_dbg(hw, "%.2X %.2X %.2X\n", hw->mac.addr[3],
  575. hw->mac.addr[4], hw->mac.addr[5]);
  576. } else {
  577. /* Setup the receive address. */
  578. hw_dbg(hw, "Overriding MAC Address in RAR[0]\n");
  579. hw_dbg(hw, " New MAC Addr =%.2X %.2X %.2X ",
  580. hw->mac.addr[0], hw->mac.addr[1],
  581. hw->mac.addr[2]);
  582. hw_dbg(hw, "%.2X %.2X %.2X\n", hw->mac.addr[3],
  583. hw->mac.addr[4], hw->mac.addr[5]);
  584. ixgbe_set_rar(hw, 0, hw->mac.addr, 0, IXGBE_RAH_AV);
  585. }
  586. hw->addr_ctrl.rar_used_count = 1;
  587. /* Zero out the other receive addresses. */
  588. hw_dbg(hw, "Clearing RAR[1-15]\n");
  589. for (i = 1; i < rar_entries; i++) {
  590. IXGBE_WRITE_REG(hw, IXGBE_RAL(i), 0);
  591. IXGBE_WRITE_REG(hw, IXGBE_RAH(i), 0);
  592. }
  593. /* Clear the MTA */
  594. hw->addr_ctrl.mc_addr_in_rar_count = 0;
  595. hw->addr_ctrl.mta_in_use = 0;
  596. IXGBE_WRITE_REG(hw, IXGBE_MCSTCTRL, hw->mac.mc_filter_type);
  597. hw_dbg(hw, " Clearing MTA\n");
  598. for (i = 0; i < IXGBE_MC_TBL_SIZE; i++)
  599. IXGBE_WRITE_REG(hw, IXGBE_MTA(i), 0);
  600. return 0;
  601. }
  602. /**
  603. * ixgbe_mta_vector - Determines bit-vector in multicast table to set
  604. * @hw: pointer to hardware structure
  605. * @mc_addr: the multicast address
  606. *
  607. * Extracts the 12 bits, from a multicast address, to determine which
  608. * bit-vector to set in the multicast table. The hardware uses 12 bits, from
  609. * incoming rx multicast addresses, to determine the bit-vector to check in
  610. * the MTA. Which of the 4 combination, of 12-bits, the hardware uses is set
  611. * by the MO field of the MCSTCTRL. The MO field is set during initalization
  612. * to mc_filter_type.
  613. **/
  614. static s32 ixgbe_mta_vector(struct ixgbe_hw *hw, u8 *mc_addr)
  615. {
  616. u32 vector = 0;
  617. switch (hw->mac.mc_filter_type) {
  618. case 0: /* use bits [47:36] of the address */
  619. vector = ((mc_addr[4] >> 4) | (((u16)mc_addr[5]) << 4));
  620. break;
  621. case 1: /* use bits [46:35] of the address */
  622. vector = ((mc_addr[4] >> 3) | (((u16)mc_addr[5]) << 5));
  623. break;
  624. case 2: /* use bits [45:34] of the address */
  625. vector = ((mc_addr[4] >> 2) | (((u16)mc_addr[5]) << 6));
  626. break;
  627. case 3: /* use bits [43:32] of the address */
  628. vector = ((mc_addr[4]) | (((u16)mc_addr[5]) << 8));
  629. break;
  630. default: /* Invalid mc_filter_type */
  631. hw_dbg(hw, "MC filter type param set incorrectly\n");
  632. break;
  633. }
  634. /* vector can only be 12-bits or boundary will be exceeded */
  635. vector &= 0xFFF;
  636. return vector;
  637. }
  638. /**
  639. * ixgbe_set_mta - Set bit-vector in multicast table
  640. * @hw: pointer to hardware structure
  641. * @hash_value: Multicast address hash value
  642. *
  643. * Sets the bit-vector in the multicast table.
  644. **/
  645. static void ixgbe_set_mta(struct ixgbe_hw *hw, u8 *mc_addr)
  646. {
  647. u32 vector;
  648. u32 vector_bit;
  649. u32 vector_reg;
  650. u32 mta_reg;
  651. hw->addr_ctrl.mta_in_use++;
  652. vector = ixgbe_mta_vector(hw, mc_addr);
  653. hw_dbg(hw, " bit-vector = 0x%03X\n", vector);
  654. /*
  655. * The MTA is a register array of 128 32-bit registers. It is treated
  656. * like an array of 4096 bits. We want to set bit
  657. * BitArray[vector_value]. So we figure out what register the bit is
  658. * in, read it, OR in the new bit, then write back the new value. The
  659. * register is determined by the upper 7 bits of the vector value and
  660. * the bit within that register are determined by the lower 5 bits of
  661. * the value.
  662. */
  663. vector_reg = (vector >> 5) & 0x7F;
  664. vector_bit = vector & 0x1F;
  665. mta_reg = IXGBE_READ_REG(hw, IXGBE_MTA(vector_reg));
  666. mta_reg |= (1 << vector_bit);
  667. IXGBE_WRITE_REG(hw, IXGBE_MTA(vector_reg), mta_reg);
  668. }
  669. /**
  670. * ixgbe_add_mc_addr - Adds a multicast address.
  671. * @hw: pointer to hardware structure
  672. * @mc_addr: new multicast address
  673. *
  674. * Adds it to unused receive address register or to the multicast table.
  675. **/
  676. static void ixgbe_add_mc_addr(struct ixgbe_hw *hw, u8 *mc_addr)
  677. {
  678. u32 rar_entries = hw->mac.num_rx_addrs;
  679. hw_dbg(hw, " MC Addr =%.2X %.2X %.2X %.2X %.2X %.2X\n",
  680. mc_addr[0], mc_addr[1], mc_addr[2],
  681. mc_addr[3], mc_addr[4], mc_addr[5]);
  682. /*
  683. * Place this multicast address in the RAR if there is room,
  684. * else put it in the MTA
  685. */
  686. if (hw->addr_ctrl.rar_used_count < rar_entries) {
  687. ixgbe_set_rar(hw, hw->addr_ctrl.rar_used_count,
  688. mc_addr, 0, IXGBE_RAH_AV);
  689. hw_dbg(hw, "Added a multicast address to RAR[%d]\n",
  690. hw->addr_ctrl.rar_used_count);
  691. hw->addr_ctrl.rar_used_count++;
  692. hw->addr_ctrl.mc_addr_in_rar_count++;
  693. } else {
  694. ixgbe_set_mta(hw, mc_addr);
  695. }
  696. hw_dbg(hw, "ixgbe_add_mc_addr Complete\n");
  697. }
  698. /**
  699. * ixgbe_update_mc_addr_list - Updates MAC list of multicast addresses
  700. * @hw: pointer to hardware structure
  701. * @mc_addr_list: the list of new multicast addresses
  702. * @mc_addr_count: number of addresses
  703. * @pad: number of bytes between addresses in the list
  704. *
  705. * The given list replaces any existing list. Clears the MC addrs from receive
  706. * address registers and the multicast table. Uses unsed receive address
  707. * registers for the first multicast addresses, and hashes the rest into the
  708. * multicast table.
  709. **/
  710. s32 ixgbe_update_mc_addr_list(struct ixgbe_hw *hw, u8 *mc_addr_list,
  711. u32 mc_addr_count, u32 pad)
  712. {
  713. u32 i;
  714. u32 rar_entries = hw->mac.num_rx_addrs;
  715. /*
  716. * Set the new number of MC addresses that we are being requested to
  717. * use.
  718. */
  719. hw->addr_ctrl.num_mc_addrs = mc_addr_count;
  720. hw->addr_ctrl.rar_used_count -= hw->addr_ctrl.mc_addr_in_rar_count;
  721. hw->addr_ctrl.mc_addr_in_rar_count = 0;
  722. hw->addr_ctrl.mta_in_use = 0;
  723. /* Zero out the other receive addresses. */
  724. hw_dbg(hw, "Clearing RAR[1-15]\n");
  725. for (i = hw->addr_ctrl.rar_used_count; i < rar_entries; i++) {
  726. IXGBE_WRITE_REG(hw, IXGBE_RAL(i), 0);
  727. IXGBE_WRITE_REG(hw, IXGBE_RAH(i), 0);
  728. }
  729. /* Clear the MTA */
  730. hw_dbg(hw, " Clearing MTA\n");
  731. for (i = 0; i < IXGBE_MC_TBL_SIZE; i++)
  732. IXGBE_WRITE_REG(hw, IXGBE_MTA(i), 0);
  733. /* Add the new addresses */
  734. for (i = 0; i < mc_addr_count; i++) {
  735. hw_dbg(hw, " Adding the multicast addresses:\n");
  736. ixgbe_add_mc_addr(hw, mc_addr_list +
  737. (i * (IXGBE_ETH_LENGTH_OF_ADDRESS + pad)));
  738. }
  739. /* Enable mta */
  740. if (hw->addr_ctrl.mta_in_use > 0)
  741. IXGBE_WRITE_REG(hw, IXGBE_MCSTCTRL,
  742. IXGBE_MCSTCTRL_MFE | hw->mac.mc_filter_type);
  743. hw_dbg(hw, "ixgbe_update_mc_addr_list Complete\n");
  744. return 0;
  745. }
  746. /**
  747. * ixgbe_clear_vfta - Clear VLAN filter table
  748. * @hw: pointer to hardware structure
  749. *
  750. * Clears the VLAN filer table, and the VMDq index associated with the filter
  751. **/
  752. static s32 ixgbe_clear_vfta(struct ixgbe_hw *hw)
  753. {
  754. u32 offset;
  755. u32 vlanbyte;
  756. for (offset = 0; offset < IXGBE_VLAN_FILTER_TBL_SIZE; offset++)
  757. IXGBE_WRITE_REG(hw, IXGBE_VFTA(offset), 0);
  758. for (vlanbyte = 0; vlanbyte < 4; vlanbyte++)
  759. for (offset = 0; offset < IXGBE_VLAN_FILTER_TBL_SIZE; offset++)
  760. IXGBE_WRITE_REG(hw, IXGBE_VFTAVIND(vlanbyte, offset),
  761. 0);
  762. return 0;
  763. }
  764. /**
  765. * ixgbe_set_vfta - Set VLAN filter table
  766. * @hw: pointer to hardware structure
  767. * @vlan: VLAN id to write to VLAN filter
  768. * @vind: VMDq output index that maps queue to VLAN id in VFTA
  769. * @vlan_on: boolean flag to turn on/off VLAN in VFTA
  770. *
  771. * Turn on/off specified VLAN in the VLAN filter table.
  772. **/
  773. s32 ixgbe_set_vfta(struct ixgbe_hw *hw, u32 vlan, u32 vind,
  774. bool vlan_on)
  775. {
  776. u32 VftaIndex;
  777. u32 BitOffset;
  778. u32 VftaReg;
  779. u32 VftaByte;
  780. /* Determine 32-bit word position in array */
  781. VftaIndex = (vlan >> 5) & 0x7F; /* upper seven bits */
  782. /* Determine the location of the (VMD) queue index */
  783. VftaByte = ((vlan >> 3) & 0x03); /* bits (4:3) indicating byte array */
  784. BitOffset = (vlan & 0x7) << 2; /* lower 3 bits indicate nibble */
  785. /* Set the nibble for VMD queue index */
  786. VftaReg = IXGBE_READ_REG(hw, IXGBE_VFTAVIND(VftaByte, VftaIndex));
  787. VftaReg &= (~(0x0F << BitOffset));
  788. VftaReg |= (vind << BitOffset);
  789. IXGBE_WRITE_REG(hw, IXGBE_VFTAVIND(VftaByte, VftaIndex), VftaReg);
  790. /* Determine the location of the bit for this VLAN id */
  791. BitOffset = vlan & 0x1F; /* lower five bits */
  792. VftaReg = IXGBE_READ_REG(hw, IXGBE_VFTA(VftaIndex));
  793. if (vlan_on)
  794. /* Turn on this VLAN id */
  795. VftaReg |= (1 << BitOffset);
  796. else
  797. /* Turn off this VLAN id */
  798. VftaReg &= ~(1 << BitOffset);
  799. IXGBE_WRITE_REG(hw, IXGBE_VFTA(VftaIndex), VftaReg);
  800. return 0;
  801. }
  802. /**
  803. * ixgbe_setup_fc - Configure flow control settings
  804. * @hw: pointer to hardware structure
  805. * @packetbuf_num: packet buffer number (0-7)
  806. *
  807. * Configures the flow control settings based on SW configuration.
  808. * This function is used for 802.3x flow control configuration only.
  809. **/
  810. s32 ixgbe_setup_fc(struct ixgbe_hw *hw, s32 packetbuf_num)
  811. {
  812. u32 frctl_reg;
  813. u32 rmcs_reg;
  814. if (packetbuf_num < 0 || packetbuf_num > 7)
  815. hw_dbg(hw, "Invalid packet buffer number [%d], expected range "
  816. "is 0-7\n", packetbuf_num);
  817. frctl_reg = IXGBE_READ_REG(hw, IXGBE_FCTRL);
  818. frctl_reg &= ~(IXGBE_FCTRL_RFCE | IXGBE_FCTRL_RPFCE);
  819. rmcs_reg = IXGBE_READ_REG(hw, IXGBE_RMCS);
  820. rmcs_reg &= ~(IXGBE_RMCS_TFCE_PRIORITY | IXGBE_RMCS_TFCE_802_3X);
  821. /*
  822. * We want to save off the original Flow Control configuration just in
  823. * case we get disconnected and then reconnected into a different hub
  824. * or switch with different Flow Control capabilities.
  825. */
  826. hw->fc.type = hw->fc.original_type;
  827. /*
  828. * The possible values of the "flow_control" parameter are:
  829. * 0: Flow control is completely disabled
  830. * 1: Rx flow control is enabled (we can receive pause frames but not
  831. * send pause frames).
  832. * 2: Tx flow control is enabled (we can send pause frames but we do not
  833. * support receiving pause frames)
  834. * 3: Both Rx and TX flow control (symmetric) are enabled.
  835. * other: Invalid.
  836. */
  837. switch (hw->fc.type) {
  838. case ixgbe_fc_none:
  839. break;
  840. case ixgbe_fc_rx_pause:
  841. /*
  842. * RX Flow control is enabled,
  843. * and TX Flow control is disabled.
  844. */
  845. frctl_reg |= IXGBE_FCTRL_RFCE;
  846. break;
  847. case ixgbe_fc_tx_pause:
  848. /*
  849. * TX Flow control is enabled, and RX Flow control is disabled,
  850. * by a software over-ride.
  851. */
  852. rmcs_reg |= IXGBE_RMCS_TFCE_802_3X;
  853. break;
  854. case ixgbe_fc_full:
  855. /*
  856. * Flow control (both RX and TX) is enabled by a software
  857. * over-ride.
  858. */
  859. frctl_reg |= IXGBE_FCTRL_RFCE;
  860. rmcs_reg |= IXGBE_RMCS_TFCE_802_3X;
  861. break;
  862. default:
  863. /* We should never get here. The value should be 0-3. */
  864. hw_dbg(hw, "Flow control param set incorrectly\n");
  865. break;
  866. }
  867. /* Enable 802.3x based flow control settings. */
  868. IXGBE_WRITE_REG(hw, IXGBE_FCTRL, frctl_reg);
  869. IXGBE_WRITE_REG(hw, IXGBE_RMCS, rmcs_reg);
  870. /*
  871. * We need to set up the Receive Threshold high and low water
  872. * marks as well as (optionally) enabling the transmission of
  873. * XON frames.
  874. */
  875. if (hw->fc.type & ixgbe_fc_tx_pause) {
  876. if (hw->fc.send_xon) {
  877. IXGBE_WRITE_REG(hw, IXGBE_FCRTL(packetbuf_num),
  878. (hw->fc.low_water | IXGBE_FCRTL_XONE));
  879. } else {
  880. IXGBE_WRITE_REG(hw, IXGBE_FCRTL(packetbuf_num),
  881. hw->fc.low_water);
  882. }
  883. IXGBE_WRITE_REG(hw, IXGBE_FCRTH(packetbuf_num),
  884. (hw->fc.high_water)|IXGBE_FCRTH_FCEN);
  885. }
  886. IXGBE_WRITE_REG(hw, IXGBE_FCTTV(0), hw->fc.pause_time);
  887. IXGBE_WRITE_REG(hw, IXGBE_FCRTV, (hw->fc.pause_time >> 1));
  888. return 0;
  889. }
  890. /**
  891. * ixgbe_disable_pcie_master - Disable PCI-express master access
  892. * @hw: pointer to hardware structure
  893. *
  894. * Disables PCI-Express master access and verifies there are no pending
  895. * requests. IXGBE_ERR_MASTER_REQUESTS_PENDING is returned if master disable
  896. * bit hasn't caused the master requests to be disabled, else 0
  897. * is returned signifying master requests disabled.
  898. **/
  899. s32 ixgbe_disable_pcie_master(struct ixgbe_hw *hw)
  900. {
  901. u32 ctrl;
  902. s32 i;
  903. s32 status = IXGBE_ERR_MASTER_REQUESTS_PENDING;
  904. ctrl = IXGBE_READ_REG(hw, IXGBE_CTRL);
  905. ctrl |= IXGBE_CTRL_GIO_DIS;
  906. IXGBE_WRITE_REG(hw, IXGBE_CTRL, ctrl);
  907. for (i = 0; i < IXGBE_PCI_MASTER_DISABLE_TIMEOUT; i++) {
  908. if (!(IXGBE_READ_REG(hw, IXGBE_STATUS) & IXGBE_STATUS_GIO)) {
  909. status = 0;
  910. break;
  911. }
  912. udelay(100);
  913. }
  914. return status;
  915. }
  916. /**
  917. * ixgbe_acquire_swfw_sync - Aquire SWFW semaphore
  918. * @hw: pointer to hardware structure
  919. * @mask: Mask to specify wich semaphore to acquire
  920. *
  921. * Aquires the SWFW semaphore throught the GSSR register for the specified
  922. * function (CSR, PHY0, PHY1, EEPROM, Flash)
  923. **/
  924. s32 ixgbe_acquire_swfw_sync(struct ixgbe_hw *hw, u16 mask)
  925. {
  926. u32 gssr;
  927. u32 swmask = mask;
  928. u32 fwmask = mask << 5;
  929. s32 timeout = 200;
  930. while (timeout) {
  931. if (ixgbe_get_eeprom_semaphore(hw))
  932. return -IXGBE_ERR_SWFW_SYNC;
  933. gssr = IXGBE_READ_REG(hw, IXGBE_GSSR);
  934. if (!(gssr & (fwmask | swmask)))
  935. break;
  936. /*
  937. * Firmware currently using resource (fwmask) or other software
  938. * thread currently using resource (swmask)
  939. */
  940. ixgbe_release_eeprom_semaphore(hw);
  941. msleep(5);
  942. timeout--;
  943. }
  944. if (!timeout) {
  945. hw_dbg(hw, "Driver can't access resource, GSSR timeout.\n");
  946. return -IXGBE_ERR_SWFW_SYNC;
  947. }
  948. gssr |= swmask;
  949. IXGBE_WRITE_REG(hw, IXGBE_GSSR, gssr);
  950. ixgbe_release_eeprom_semaphore(hw);
  951. return 0;
  952. }
  953. /**
  954. * ixgbe_release_swfw_sync - Release SWFW semaphore
  955. * @hw: pointer to hardware structure
  956. * @mask: Mask to specify wich semaphore to release
  957. *
  958. * Releases the SWFW semaphore throught the GSSR register for the specified
  959. * function (CSR, PHY0, PHY1, EEPROM, Flash)
  960. **/
  961. void ixgbe_release_swfw_sync(struct ixgbe_hw *hw, u16 mask)
  962. {
  963. u32 gssr;
  964. u32 swmask = mask;
  965. ixgbe_get_eeprom_semaphore(hw);
  966. gssr = IXGBE_READ_REG(hw, IXGBE_GSSR);
  967. gssr &= ~swmask;
  968. IXGBE_WRITE_REG(hw, IXGBE_GSSR, gssr);
  969. ixgbe_release_eeprom_semaphore(hw);
  970. }
  971. /**
  972. * ixgbe_read_analog_reg8 - Reads 8 bit Atlas analog register
  973. * @hw: pointer to hardware structure
  974. * @reg: analog register to read
  975. * @val: read value
  976. *
  977. * Performs write operation to analog register specified.
  978. **/
  979. s32 ixgbe_read_analog_reg8(struct ixgbe_hw *hw, u32 reg, u8 *val)
  980. {
  981. u32 atlas_ctl;
  982. IXGBE_WRITE_REG(hw, IXGBE_ATLASCTL,
  983. IXGBE_ATLASCTL_WRITE_CMD | (reg << 8));
  984. IXGBE_WRITE_FLUSH(hw);
  985. udelay(10);
  986. atlas_ctl = IXGBE_READ_REG(hw, IXGBE_ATLASCTL);
  987. *val = (u8)atlas_ctl;
  988. return 0;
  989. }
  990. /**
  991. * ixgbe_write_analog_reg8 - Writes 8 bit Atlas analog register
  992. * @hw: pointer to hardware structure
  993. * @reg: atlas register to write
  994. * @val: value to write
  995. *
  996. * Performs write operation to Atlas analog register specified.
  997. **/
  998. s32 ixgbe_write_analog_reg8(struct ixgbe_hw *hw, u32 reg, u8 val)
  999. {
  1000. u32 atlas_ctl;
  1001. atlas_ctl = (reg << 8) | val;
  1002. IXGBE_WRITE_REG(hw, IXGBE_ATLASCTL, atlas_ctl);
  1003. IXGBE_WRITE_FLUSH(hw);
  1004. udelay(10);
  1005. return 0;
  1006. }