ixgbe_common.c 32 KB

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