ixgbe_common.c 48 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734
  1. /*******************************************************************************
  2. Intel 10 Gigabit PCI Express Linux driver
  3. Copyright(c) 1999 - 2009 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. e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
  18. Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
  19. *******************************************************************************/
  20. #include <linux/pci.h>
  21. #include <linux/delay.h>
  22. #include <linux/sched.h>
  23. #include "ixgbe_common.h"
  24. #include "ixgbe_phy.h"
  25. static s32 ixgbe_poll_eeprom_eerd_done(struct ixgbe_hw *hw);
  26. static s32 ixgbe_acquire_eeprom(struct ixgbe_hw *hw);
  27. static s32 ixgbe_get_eeprom_semaphore(struct ixgbe_hw *hw);
  28. static void ixgbe_release_eeprom_semaphore(struct ixgbe_hw *hw);
  29. static s32 ixgbe_ready_eeprom(struct ixgbe_hw *hw);
  30. static void ixgbe_standby_eeprom(struct ixgbe_hw *hw);
  31. static void ixgbe_shift_out_eeprom_bits(struct ixgbe_hw *hw, u16 data,
  32. u16 count);
  33. static u16 ixgbe_shift_in_eeprom_bits(struct ixgbe_hw *hw, u16 count);
  34. static void ixgbe_raise_eeprom_clk(struct ixgbe_hw *hw, u32 *eec);
  35. static void ixgbe_lower_eeprom_clk(struct ixgbe_hw *hw, u32 *eec);
  36. static void ixgbe_release_eeprom(struct ixgbe_hw *hw);
  37. static u16 ixgbe_calc_eeprom_checksum(struct ixgbe_hw *hw);
  38. static void ixgbe_enable_rar(struct ixgbe_hw *hw, u32 index);
  39. static void ixgbe_disable_rar(struct ixgbe_hw *hw, u32 index);
  40. static s32 ixgbe_mta_vector(struct ixgbe_hw *hw, u8 *mc_addr);
  41. static void ixgbe_add_mc_addr(struct ixgbe_hw *hw, u8 *mc_addr);
  42. static void ixgbe_add_uc_addr(struct ixgbe_hw *hw, u8 *addr, u32 vmdq);
  43. /**
  44. * ixgbe_start_hw_generic - Prepare hardware for Tx/Rx
  45. * @hw: pointer to hardware structure
  46. *
  47. * Starts the hardware by filling the bus info structure and media type, clears
  48. * all on chip counters, initializes receive address registers, multicast
  49. * table, VLAN filter table, calls routine to set up link and flow control
  50. * settings, and leaves transmit and receive units disabled and uninitialized
  51. **/
  52. s32 ixgbe_start_hw_generic(struct ixgbe_hw *hw)
  53. {
  54. u32 ctrl_ext;
  55. /* Set the media type */
  56. hw->phy.media_type = hw->mac.ops.get_media_type(hw);
  57. /* Identify the PHY */
  58. hw->phy.ops.identify(hw);
  59. /*
  60. * Store MAC address from RAR0, clear receive address registers, and
  61. * clear the multicast table
  62. */
  63. hw->mac.ops.init_rx_addrs(hw);
  64. /* Clear the VLAN filter table */
  65. hw->mac.ops.clear_vfta(hw);
  66. /* Clear statistics registers */
  67. hw->mac.ops.clear_hw_cntrs(hw);
  68. /* Set No Snoop Disable */
  69. ctrl_ext = IXGBE_READ_REG(hw, IXGBE_CTRL_EXT);
  70. ctrl_ext |= IXGBE_CTRL_EXT_NS_DIS;
  71. IXGBE_WRITE_REG(hw, IXGBE_CTRL_EXT, ctrl_ext);
  72. IXGBE_WRITE_FLUSH(hw);
  73. /* Clear adapter stopped flag */
  74. hw->adapter_stopped = false;
  75. return 0;
  76. }
  77. /**
  78. * ixgbe_init_hw_generic - Generic hardware initialization
  79. * @hw: pointer to hardware structure
  80. *
  81. * Initialize the hardware by resetting the hardware, filling the bus info
  82. * structure and media type, clears all on chip counters, initializes receive
  83. * address registers, multicast table, VLAN filter table, calls routine to set
  84. * up link and flow control settings, and leaves transmit and receive units
  85. * disabled and uninitialized
  86. **/
  87. s32 ixgbe_init_hw_generic(struct ixgbe_hw *hw)
  88. {
  89. /* Reset the hardware */
  90. hw->mac.ops.reset_hw(hw);
  91. /* Start the HW */
  92. hw->mac.ops.start_hw(hw);
  93. return 0;
  94. }
  95. /**
  96. * ixgbe_clear_hw_cntrs_generic - Generic clear hardware counters
  97. * @hw: pointer to hardware structure
  98. *
  99. * Clears all hardware statistics counters by reading them from the hardware
  100. * Statistics counters are clear on read.
  101. **/
  102. s32 ixgbe_clear_hw_cntrs_generic(struct ixgbe_hw *hw)
  103. {
  104. u16 i = 0;
  105. IXGBE_READ_REG(hw, IXGBE_CRCERRS);
  106. IXGBE_READ_REG(hw, IXGBE_ILLERRC);
  107. IXGBE_READ_REG(hw, IXGBE_ERRBC);
  108. IXGBE_READ_REG(hw, IXGBE_MSPDC);
  109. for (i = 0; i < 8; i++)
  110. IXGBE_READ_REG(hw, IXGBE_MPC(i));
  111. IXGBE_READ_REG(hw, IXGBE_MLFC);
  112. IXGBE_READ_REG(hw, IXGBE_MRFC);
  113. IXGBE_READ_REG(hw, IXGBE_RLEC);
  114. IXGBE_READ_REG(hw, IXGBE_LXONTXC);
  115. IXGBE_READ_REG(hw, IXGBE_LXONRXC);
  116. IXGBE_READ_REG(hw, IXGBE_LXOFFTXC);
  117. IXGBE_READ_REG(hw, IXGBE_LXOFFRXC);
  118. for (i = 0; i < 8; i++) {
  119. IXGBE_READ_REG(hw, IXGBE_PXONTXC(i));
  120. IXGBE_READ_REG(hw, IXGBE_PXONRXC(i));
  121. IXGBE_READ_REG(hw, IXGBE_PXOFFTXC(i));
  122. IXGBE_READ_REG(hw, IXGBE_PXOFFRXC(i));
  123. }
  124. IXGBE_READ_REG(hw, IXGBE_PRC64);
  125. IXGBE_READ_REG(hw, IXGBE_PRC127);
  126. IXGBE_READ_REG(hw, IXGBE_PRC255);
  127. IXGBE_READ_REG(hw, IXGBE_PRC511);
  128. IXGBE_READ_REG(hw, IXGBE_PRC1023);
  129. IXGBE_READ_REG(hw, IXGBE_PRC1522);
  130. IXGBE_READ_REG(hw, IXGBE_GPRC);
  131. IXGBE_READ_REG(hw, IXGBE_BPRC);
  132. IXGBE_READ_REG(hw, IXGBE_MPRC);
  133. IXGBE_READ_REG(hw, IXGBE_GPTC);
  134. IXGBE_READ_REG(hw, IXGBE_GORCL);
  135. IXGBE_READ_REG(hw, IXGBE_GORCH);
  136. IXGBE_READ_REG(hw, IXGBE_GOTCL);
  137. IXGBE_READ_REG(hw, IXGBE_GOTCH);
  138. for (i = 0; i < 8; i++)
  139. IXGBE_READ_REG(hw, IXGBE_RNBC(i));
  140. IXGBE_READ_REG(hw, IXGBE_RUC);
  141. IXGBE_READ_REG(hw, IXGBE_RFC);
  142. IXGBE_READ_REG(hw, IXGBE_ROC);
  143. IXGBE_READ_REG(hw, IXGBE_RJC);
  144. IXGBE_READ_REG(hw, IXGBE_MNGPRC);
  145. IXGBE_READ_REG(hw, IXGBE_MNGPDC);
  146. IXGBE_READ_REG(hw, IXGBE_MNGPTC);
  147. IXGBE_READ_REG(hw, IXGBE_TORL);
  148. IXGBE_READ_REG(hw, IXGBE_TORH);
  149. IXGBE_READ_REG(hw, IXGBE_TPR);
  150. IXGBE_READ_REG(hw, IXGBE_TPT);
  151. IXGBE_READ_REG(hw, IXGBE_PTC64);
  152. IXGBE_READ_REG(hw, IXGBE_PTC127);
  153. IXGBE_READ_REG(hw, IXGBE_PTC255);
  154. IXGBE_READ_REG(hw, IXGBE_PTC511);
  155. IXGBE_READ_REG(hw, IXGBE_PTC1023);
  156. IXGBE_READ_REG(hw, IXGBE_PTC1522);
  157. IXGBE_READ_REG(hw, IXGBE_MPTC);
  158. IXGBE_READ_REG(hw, IXGBE_BPTC);
  159. for (i = 0; i < 16; i++) {
  160. IXGBE_READ_REG(hw, IXGBE_QPRC(i));
  161. IXGBE_READ_REG(hw, IXGBE_QBRC(i));
  162. IXGBE_READ_REG(hw, IXGBE_QPTC(i));
  163. IXGBE_READ_REG(hw, IXGBE_QBTC(i));
  164. }
  165. return 0;
  166. }
  167. /**
  168. * ixgbe_read_pba_num_generic - Reads part number from EEPROM
  169. * @hw: pointer to hardware structure
  170. * @pba_num: stores the part number from the EEPROM
  171. *
  172. * Reads the part number from the EEPROM.
  173. **/
  174. s32 ixgbe_read_pba_num_generic(struct ixgbe_hw *hw, u32 *pba_num)
  175. {
  176. s32 ret_val;
  177. u16 data;
  178. ret_val = hw->eeprom.ops.read(hw, IXGBE_PBANUM0_PTR, &data);
  179. if (ret_val) {
  180. hw_dbg(hw, "NVM Read Error\n");
  181. return ret_val;
  182. }
  183. *pba_num = (u32)(data << 16);
  184. ret_val = hw->eeprom.ops.read(hw, IXGBE_PBANUM1_PTR, &data);
  185. if (ret_val) {
  186. hw_dbg(hw, "NVM Read Error\n");
  187. return ret_val;
  188. }
  189. *pba_num |= data;
  190. return 0;
  191. }
  192. /**
  193. * ixgbe_get_mac_addr_generic - Generic get MAC address
  194. * @hw: pointer to hardware structure
  195. * @mac_addr: Adapter MAC address
  196. *
  197. * Reads the adapter's MAC address from first Receive Address Register (RAR0)
  198. * A reset of the adapter must be performed prior to calling this function
  199. * in order for the MAC address to have been loaded from the EEPROM into RAR0
  200. **/
  201. s32 ixgbe_get_mac_addr_generic(struct ixgbe_hw *hw, u8 *mac_addr)
  202. {
  203. u32 rar_high;
  204. u32 rar_low;
  205. u16 i;
  206. rar_high = IXGBE_READ_REG(hw, IXGBE_RAH(0));
  207. rar_low = IXGBE_READ_REG(hw, IXGBE_RAL(0));
  208. for (i = 0; i < 4; i++)
  209. mac_addr[i] = (u8)(rar_low >> (i*8));
  210. for (i = 0; i < 2; i++)
  211. mac_addr[i+4] = (u8)(rar_high >> (i*8));
  212. return 0;
  213. }
  214. /**
  215. * ixgbe_stop_adapter_generic - Generic stop Tx/Rx units
  216. * @hw: pointer to hardware structure
  217. *
  218. * Sets the adapter_stopped flag within ixgbe_hw struct. Clears interrupts,
  219. * disables transmit and receive units. The adapter_stopped flag is used by
  220. * the shared code and drivers to determine if the adapter is in a stopped
  221. * state and should not touch the hardware.
  222. **/
  223. s32 ixgbe_stop_adapter_generic(struct ixgbe_hw *hw)
  224. {
  225. u32 number_of_queues;
  226. u32 reg_val;
  227. u16 i;
  228. /*
  229. * Set the adapter_stopped flag so other driver functions stop touching
  230. * the hardware
  231. */
  232. hw->adapter_stopped = true;
  233. /* Disable the receive unit */
  234. reg_val = IXGBE_READ_REG(hw, IXGBE_RXCTRL);
  235. reg_val &= ~(IXGBE_RXCTRL_RXEN);
  236. IXGBE_WRITE_REG(hw, IXGBE_RXCTRL, reg_val);
  237. IXGBE_WRITE_FLUSH(hw);
  238. msleep(2);
  239. /* Clear interrupt mask to stop from interrupts being generated */
  240. IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_IRQ_CLEAR_MASK);
  241. /* Clear any pending interrupts */
  242. IXGBE_READ_REG(hw, IXGBE_EICR);
  243. /* Disable the transmit unit. Each queue must be disabled. */
  244. number_of_queues = hw->mac.max_tx_queues;
  245. for (i = 0; i < number_of_queues; i++) {
  246. reg_val = IXGBE_READ_REG(hw, IXGBE_TXDCTL(i));
  247. if (reg_val & IXGBE_TXDCTL_ENABLE) {
  248. reg_val &= ~IXGBE_TXDCTL_ENABLE;
  249. IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(i), reg_val);
  250. }
  251. }
  252. /*
  253. * Prevent the PCI-E bus from from hanging by disabling PCI-E master
  254. * access and verify no pending requests
  255. */
  256. if (ixgbe_disable_pcie_master(hw) != 0)
  257. hw_dbg(hw, "PCI-E Master disable polling has failed.\n");
  258. return 0;
  259. }
  260. /**
  261. * ixgbe_led_on_generic - Turns on the software controllable LEDs.
  262. * @hw: pointer to hardware structure
  263. * @index: led number to turn on
  264. **/
  265. s32 ixgbe_led_on_generic(struct ixgbe_hw *hw, u32 index)
  266. {
  267. u32 led_reg = IXGBE_READ_REG(hw, IXGBE_LEDCTL);
  268. /* To turn on the LED, set mode to ON. */
  269. led_reg &= ~IXGBE_LED_MODE_MASK(index);
  270. led_reg |= IXGBE_LED_ON << IXGBE_LED_MODE_SHIFT(index);
  271. IXGBE_WRITE_REG(hw, IXGBE_LEDCTL, led_reg);
  272. IXGBE_WRITE_FLUSH(hw);
  273. return 0;
  274. }
  275. /**
  276. * ixgbe_led_off_generic - Turns off the software controllable LEDs.
  277. * @hw: pointer to hardware structure
  278. * @index: led number to turn off
  279. **/
  280. s32 ixgbe_led_off_generic(struct ixgbe_hw *hw, u32 index)
  281. {
  282. u32 led_reg = IXGBE_READ_REG(hw, IXGBE_LEDCTL);
  283. /* To turn off the LED, set mode to OFF. */
  284. led_reg &= ~IXGBE_LED_MODE_MASK(index);
  285. led_reg |= IXGBE_LED_OFF << IXGBE_LED_MODE_SHIFT(index);
  286. IXGBE_WRITE_REG(hw, IXGBE_LEDCTL, led_reg);
  287. IXGBE_WRITE_FLUSH(hw);
  288. return 0;
  289. }
  290. /**
  291. * ixgbe_init_eeprom_params_generic - Initialize EEPROM params
  292. * @hw: pointer to hardware structure
  293. *
  294. * Initializes the EEPROM parameters ixgbe_eeprom_info within the
  295. * ixgbe_hw struct in order to set up EEPROM access.
  296. **/
  297. s32 ixgbe_init_eeprom_params_generic(struct ixgbe_hw *hw)
  298. {
  299. struct ixgbe_eeprom_info *eeprom = &hw->eeprom;
  300. u32 eec;
  301. u16 eeprom_size;
  302. if (eeprom->type == ixgbe_eeprom_uninitialized) {
  303. eeprom->type = ixgbe_eeprom_none;
  304. /* Set default semaphore delay to 10ms which is a well
  305. * tested value */
  306. eeprom->semaphore_delay = 10;
  307. /*
  308. * Check for EEPROM present first.
  309. * If not present leave as none
  310. */
  311. eec = IXGBE_READ_REG(hw, IXGBE_EEC);
  312. if (eec & IXGBE_EEC_PRES) {
  313. eeprom->type = ixgbe_eeprom_spi;
  314. /*
  315. * SPI EEPROM is assumed here. This code would need to
  316. * change if a future EEPROM is not SPI.
  317. */
  318. eeprom_size = (u16)((eec & IXGBE_EEC_SIZE) >>
  319. IXGBE_EEC_SIZE_SHIFT);
  320. eeprom->word_size = 1 << (eeprom_size +
  321. IXGBE_EEPROM_WORD_SIZE_SHIFT);
  322. }
  323. if (eec & IXGBE_EEC_ADDR_SIZE)
  324. eeprom->address_bits = 16;
  325. else
  326. eeprom->address_bits = 8;
  327. hw_dbg(hw, "Eeprom params: type = %d, size = %d, address bits: "
  328. "%d\n", eeprom->type, eeprom->word_size,
  329. eeprom->address_bits);
  330. }
  331. return 0;
  332. }
  333. /**
  334. * ixgbe_read_eeprom_bit_bang_generic - Read EEPROM word using bit-bang
  335. * @hw: pointer to hardware structure
  336. * @offset: offset within the EEPROM to be read
  337. * @data: read 16 bit value from EEPROM
  338. *
  339. * Reads 16 bit value from EEPROM through bit-bang method
  340. **/
  341. s32 ixgbe_read_eeprom_bit_bang_generic(struct ixgbe_hw *hw, u16 offset,
  342. u16 *data)
  343. {
  344. s32 status;
  345. u16 word_in;
  346. u8 read_opcode = IXGBE_EEPROM_READ_OPCODE_SPI;
  347. hw->eeprom.ops.init_params(hw);
  348. if (offset >= hw->eeprom.word_size) {
  349. status = IXGBE_ERR_EEPROM;
  350. goto out;
  351. }
  352. /* Prepare the EEPROM for reading */
  353. status = ixgbe_acquire_eeprom(hw);
  354. if (status == 0) {
  355. if (ixgbe_ready_eeprom(hw) != 0) {
  356. ixgbe_release_eeprom(hw);
  357. status = IXGBE_ERR_EEPROM;
  358. }
  359. }
  360. if (status == 0) {
  361. ixgbe_standby_eeprom(hw);
  362. /*
  363. * Some SPI eeproms use the 8th address bit embedded in the
  364. * opcode
  365. */
  366. if ((hw->eeprom.address_bits == 8) && (offset >= 128))
  367. read_opcode |= IXGBE_EEPROM_A8_OPCODE_SPI;
  368. /* Send the READ command (opcode + addr) */
  369. ixgbe_shift_out_eeprom_bits(hw, read_opcode,
  370. IXGBE_EEPROM_OPCODE_BITS);
  371. ixgbe_shift_out_eeprom_bits(hw, (u16)(offset*2),
  372. hw->eeprom.address_bits);
  373. /* Read the data. */
  374. word_in = ixgbe_shift_in_eeprom_bits(hw, 16);
  375. *data = (word_in >> 8) | (word_in << 8);
  376. /* End this read operation */
  377. ixgbe_release_eeprom(hw);
  378. }
  379. out:
  380. return status;
  381. }
  382. /**
  383. * ixgbe_read_eeprom_generic - Read EEPROM word using EERD
  384. * @hw: pointer to hardware structure
  385. * @offset: offset of word in the EEPROM to read
  386. * @data: word read from the EEPROM
  387. *
  388. * Reads a 16 bit word from the EEPROM using the EERD register.
  389. **/
  390. s32 ixgbe_read_eeprom_generic(struct ixgbe_hw *hw, u16 offset, u16 *data)
  391. {
  392. u32 eerd;
  393. s32 status;
  394. hw->eeprom.ops.init_params(hw);
  395. if (offset >= hw->eeprom.word_size) {
  396. status = IXGBE_ERR_EEPROM;
  397. goto out;
  398. }
  399. eerd = (offset << IXGBE_EEPROM_READ_ADDR_SHIFT) +
  400. IXGBE_EEPROM_READ_REG_START;
  401. IXGBE_WRITE_REG(hw, IXGBE_EERD, eerd);
  402. status = ixgbe_poll_eeprom_eerd_done(hw);
  403. if (status == 0)
  404. *data = (IXGBE_READ_REG(hw, IXGBE_EERD) >>
  405. IXGBE_EEPROM_READ_REG_DATA);
  406. else
  407. hw_dbg(hw, "Eeprom read timed out\n");
  408. out:
  409. return status;
  410. }
  411. /**
  412. * ixgbe_poll_eeprom_eerd_done - Poll EERD status
  413. * @hw: pointer to hardware structure
  414. *
  415. * Polls the status bit (bit 1) of the EERD to determine when the read is done.
  416. **/
  417. static s32 ixgbe_poll_eeprom_eerd_done(struct ixgbe_hw *hw)
  418. {
  419. u32 i;
  420. u32 reg;
  421. s32 status = IXGBE_ERR_EEPROM;
  422. for (i = 0; i < IXGBE_EERD_ATTEMPTS; i++) {
  423. reg = IXGBE_READ_REG(hw, IXGBE_EERD);
  424. if (reg & IXGBE_EEPROM_READ_REG_DONE) {
  425. status = 0;
  426. break;
  427. }
  428. udelay(5);
  429. }
  430. return status;
  431. }
  432. /**
  433. * ixgbe_acquire_eeprom - Acquire EEPROM using bit-bang
  434. * @hw: pointer to hardware structure
  435. *
  436. * Prepares EEPROM for access using bit-bang method. This function should
  437. * be called before issuing a command to the EEPROM.
  438. **/
  439. static s32 ixgbe_acquire_eeprom(struct ixgbe_hw *hw)
  440. {
  441. s32 status = 0;
  442. u32 eec;
  443. u32 i;
  444. if (ixgbe_acquire_swfw_sync(hw, IXGBE_GSSR_EEP_SM) != 0)
  445. status = IXGBE_ERR_SWFW_SYNC;
  446. if (status == 0) {
  447. eec = IXGBE_READ_REG(hw, IXGBE_EEC);
  448. /* Request EEPROM Access */
  449. eec |= IXGBE_EEC_REQ;
  450. IXGBE_WRITE_REG(hw, IXGBE_EEC, eec);
  451. for (i = 0; i < IXGBE_EEPROM_GRANT_ATTEMPTS; i++) {
  452. eec = IXGBE_READ_REG(hw, IXGBE_EEC);
  453. if (eec & IXGBE_EEC_GNT)
  454. break;
  455. udelay(5);
  456. }
  457. /* Release if grant not acquired */
  458. if (!(eec & IXGBE_EEC_GNT)) {
  459. eec &= ~IXGBE_EEC_REQ;
  460. IXGBE_WRITE_REG(hw, IXGBE_EEC, eec);
  461. hw_dbg(hw, "Could not acquire EEPROM grant\n");
  462. ixgbe_release_swfw_sync(hw, IXGBE_GSSR_EEP_SM);
  463. status = IXGBE_ERR_EEPROM;
  464. }
  465. }
  466. /* Setup EEPROM for Read/Write */
  467. if (status == 0) {
  468. /* Clear CS and SK */
  469. eec &= ~(IXGBE_EEC_CS | IXGBE_EEC_SK);
  470. IXGBE_WRITE_REG(hw, IXGBE_EEC, eec);
  471. IXGBE_WRITE_FLUSH(hw);
  472. udelay(1);
  473. }
  474. return status;
  475. }
  476. /**
  477. * ixgbe_get_eeprom_semaphore - Get hardware semaphore
  478. * @hw: pointer to hardware structure
  479. *
  480. * Sets the hardware semaphores so EEPROM access can occur for bit-bang method
  481. **/
  482. static s32 ixgbe_get_eeprom_semaphore(struct ixgbe_hw *hw)
  483. {
  484. s32 status = IXGBE_ERR_EEPROM;
  485. u32 timeout;
  486. u32 i;
  487. u32 swsm;
  488. /* Set timeout value based on size of EEPROM */
  489. timeout = hw->eeprom.word_size + 1;
  490. /* Get SMBI software semaphore between device drivers first */
  491. for (i = 0; i < timeout; i++) {
  492. /*
  493. * If the SMBI bit is 0 when we read it, then the bit will be
  494. * set and we have the semaphore
  495. */
  496. swsm = IXGBE_READ_REG(hw, IXGBE_SWSM);
  497. if (!(swsm & IXGBE_SWSM_SMBI)) {
  498. status = 0;
  499. break;
  500. }
  501. msleep(1);
  502. }
  503. /* Now get the semaphore between SW/FW through the SWESMBI bit */
  504. if (status == 0) {
  505. for (i = 0; i < timeout; i++) {
  506. swsm = IXGBE_READ_REG(hw, IXGBE_SWSM);
  507. /* Set the SW EEPROM semaphore bit to request access */
  508. swsm |= IXGBE_SWSM_SWESMBI;
  509. IXGBE_WRITE_REG(hw, IXGBE_SWSM, swsm);
  510. /*
  511. * If we set the bit successfully then we got the
  512. * semaphore.
  513. */
  514. swsm = IXGBE_READ_REG(hw, IXGBE_SWSM);
  515. if (swsm & IXGBE_SWSM_SWESMBI)
  516. break;
  517. udelay(50);
  518. }
  519. /*
  520. * Release semaphores and return error if SW EEPROM semaphore
  521. * was not granted because we don't have access to the EEPROM
  522. */
  523. if (i >= timeout) {
  524. hw_dbg(hw, "Driver can't access the Eeprom - Semaphore "
  525. "not granted.\n");
  526. ixgbe_release_eeprom_semaphore(hw);
  527. status = IXGBE_ERR_EEPROM;
  528. }
  529. }
  530. return status;
  531. }
  532. /**
  533. * ixgbe_release_eeprom_semaphore - Release hardware semaphore
  534. * @hw: pointer to hardware structure
  535. *
  536. * This function clears hardware semaphore bits.
  537. **/
  538. static void ixgbe_release_eeprom_semaphore(struct ixgbe_hw *hw)
  539. {
  540. u32 swsm;
  541. swsm = IXGBE_READ_REG(hw, IXGBE_SWSM);
  542. /* Release both semaphores by writing 0 to the bits SWESMBI and SMBI */
  543. swsm &= ~(IXGBE_SWSM_SWESMBI | IXGBE_SWSM_SMBI);
  544. IXGBE_WRITE_REG(hw, IXGBE_SWSM, swsm);
  545. IXGBE_WRITE_FLUSH(hw);
  546. }
  547. /**
  548. * ixgbe_ready_eeprom - Polls for EEPROM ready
  549. * @hw: pointer to hardware structure
  550. **/
  551. static s32 ixgbe_ready_eeprom(struct ixgbe_hw *hw)
  552. {
  553. s32 status = 0;
  554. u16 i;
  555. u8 spi_stat_reg;
  556. /*
  557. * Read "Status Register" repeatedly until the LSB is cleared. The
  558. * EEPROM will signal that the command has been completed by clearing
  559. * bit 0 of the internal status register. If it's not cleared within
  560. * 5 milliseconds, then error out.
  561. */
  562. for (i = 0; i < IXGBE_EEPROM_MAX_RETRY_SPI; i += 5) {
  563. ixgbe_shift_out_eeprom_bits(hw, IXGBE_EEPROM_RDSR_OPCODE_SPI,
  564. IXGBE_EEPROM_OPCODE_BITS);
  565. spi_stat_reg = (u8)ixgbe_shift_in_eeprom_bits(hw, 8);
  566. if (!(spi_stat_reg & IXGBE_EEPROM_STATUS_RDY_SPI))
  567. break;
  568. udelay(5);
  569. ixgbe_standby_eeprom(hw);
  570. };
  571. /*
  572. * On some parts, SPI write time could vary from 0-20mSec on 3.3V
  573. * devices (and only 0-5mSec on 5V devices)
  574. */
  575. if (i >= IXGBE_EEPROM_MAX_RETRY_SPI) {
  576. hw_dbg(hw, "SPI EEPROM Status error\n");
  577. status = IXGBE_ERR_EEPROM;
  578. }
  579. return status;
  580. }
  581. /**
  582. * ixgbe_standby_eeprom - Returns EEPROM to a "standby" state
  583. * @hw: pointer to hardware structure
  584. **/
  585. static void ixgbe_standby_eeprom(struct ixgbe_hw *hw)
  586. {
  587. u32 eec;
  588. eec = IXGBE_READ_REG(hw, IXGBE_EEC);
  589. /* Toggle CS to flush commands */
  590. eec |= IXGBE_EEC_CS;
  591. IXGBE_WRITE_REG(hw, IXGBE_EEC, eec);
  592. IXGBE_WRITE_FLUSH(hw);
  593. udelay(1);
  594. eec &= ~IXGBE_EEC_CS;
  595. IXGBE_WRITE_REG(hw, IXGBE_EEC, eec);
  596. IXGBE_WRITE_FLUSH(hw);
  597. udelay(1);
  598. }
  599. /**
  600. * ixgbe_shift_out_eeprom_bits - Shift data bits out to the EEPROM.
  601. * @hw: pointer to hardware structure
  602. * @data: data to send to the EEPROM
  603. * @count: number of bits to shift out
  604. **/
  605. static void ixgbe_shift_out_eeprom_bits(struct ixgbe_hw *hw, u16 data,
  606. u16 count)
  607. {
  608. u32 eec;
  609. u32 mask;
  610. u32 i;
  611. eec = IXGBE_READ_REG(hw, IXGBE_EEC);
  612. /*
  613. * Mask is used to shift "count" bits of "data" out to the EEPROM
  614. * one bit at a time. Determine the starting bit based on count
  615. */
  616. mask = 0x01 << (count - 1);
  617. for (i = 0; i < count; i++) {
  618. /*
  619. * A "1" is shifted out to the EEPROM by setting bit "DI" to a
  620. * "1", and then raising and then lowering the clock (the SK
  621. * bit controls the clock input to the EEPROM). A "0" is
  622. * shifted out to the EEPROM by setting "DI" to "0" and then
  623. * raising and then lowering the clock.
  624. */
  625. if (data & mask)
  626. eec |= IXGBE_EEC_DI;
  627. else
  628. eec &= ~IXGBE_EEC_DI;
  629. IXGBE_WRITE_REG(hw, IXGBE_EEC, eec);
  630. IXGBE_WRITE_FLUSH(hw);
  631. udelay(1);
  632. ixgbe_raise_eeprom_clk(hw, &eec);
  633. ixgbe_lower_eeprom_clk(hw, &eec);
  634. /*
  635. * Shift mask to signify next bit of data to shift in to the
  636. * EEPROM
  637. */
  638. mask = mask >> 1;
  639. };
  640. /* We leave the "DI" bit set to "0" when we leave this routine. */
  641. eec &= ~IXGBE_EEC_DI;
  642. IXGBE_WRITE_REG(hw, IXGBE_EEC, eec);
  643. IXGBE_WRITE_FLUSH(hw);
  644. }
  645. /**
  646. * ixgbe_shift_in_eeprom_bits - Shift data bits in from the EEPROM
  647. * @hw: pointer to hardware structure
  648. **/
  649. static u16 ixgbe_shift_in_eeprom_bits(struct ixgbe_hw *hw, u16 count)
  650. {
  651. u32 eec;
  652. u32 i;
  653. u16 data = 0;
  654. /*
  655. * In order to read a register from the EEPROM, we need to shift
  656. * 'count' bits in from the EEPROM. Bits are "shifted in" by raising
  657. * the clock input to the EEPROM (setting the SK bit), and then reading
  658. * the value of the "DO" bit. During this "shifting in" process the
  659. * "DI" bit should always be clear.
  660. */
  661. eec = IXGBE_READ_REG(hw, IXGBE_EEC);
  662. eec &= ~(IXGBE_EEC_DO | IXGBE_EEC_DI);
  663. for (i = 0; i < count; i++) {
  664. data = data << 1;
  665. ixgbe_raise_eeprom_clk(hw, &eec);
  666. eec = IXGBE_READ_REG(hw, IXGBE_EEC);
  667. eec &= ~(IXGBE_EEC_DI);
  668. if (eec & IXGBE_EEC_DO)
  669. data |= 1;
  670. ixgbe_lower_eeprom_clk(hw, &eec);
  671. }
  672. return data;
  673. }
  674. /**
  675. * ixgbe_raise_eeprom_clk - Raises the EEPROM's clock input.
  676. * @hw: pointer to hardware structure
  677. * @eec: EEC register's current value
  678. **/
  679. static void ixgbe_raise_eeprom_clk(struct ixgbe_hw *hw, u32 *eec)
  680. {
  681. /*
  682. * Raise the clock input to the EEPROM
  683. * (setting the SK bit), then delay
  684. */
  685. *eec = *eec | IXGBE_EEC_SK;
  686. IXGBE_WRITE_REG(hw, IXGBE_EEC, *eec);
  687. IXGBE_WRITE_FLUSH(hw);
  688. udelay(1);
  689. }
  690. /**
  691. * ixgbe_lower_eeprom_clk - Lowers the EEPROM's clock input.
  692. * @hw: pointer to hardware structure
  693. * @eecd: EECD's current value
  694. **/
  695. static void ixgbe_lower_eeprom_clk(struct ixgbe_hw *hw, u32 *eec)
  696. {
  697. /*
  698. * Lower the clock input to the EEPROM (clearing the SK bit), then
  699. * delay
  700. */
  701. *eec = *eec & ~IXGBE_EEC_SK;
  702. IXGBE_WRITE_REG(hw, IXGBE_EEC, *eec);
  703. IXGBE_WRITE_FLUSH(hw);
  704. udelay(1);
  705. }
  706. /**
  707. * ixgbe_release_eeprom - Release EEPROM, release semaphores
  708. * @hw: pointer to hardware structure
  709. **/
  710. static void ixgbe_release_eeprom(struct ixgbe_hw *hw)
  711. {
  712. u32 eec;
  713. eec = IXGBE_READ_REG(hw, IXGBE_EEC);
  714. eec |= IXGBE_EEC_CS; /* Pull CS high */
  715. eec &= ~IXGBE_EEC_SK; /* Lower SCK */
  716. IXGBE_WRITE_REG(hw, IXGBE_EEC, eec);
  717. IXGBE_WRITE_FLUSH(hw);
  718. udelay(1);
  719. /* Stop requesting EEPROM access */
  720. eec &= ~IXGBE_EEC_REQ;
  721. IXGBE_WRITE_REG(hw, IXGBE_EEC, eec);
  722. ixgbe_release_swfw_sync(hw, IXGBE_GSSR_EEP_SM);
  723. }
  724. /**
  725. * ixgbe_calc_eeprom_checksum - Calculates and returns the checksum
  726. * @hw: pointer to hardware structure
  727. **/
  728. static u16 ixgbe_calc_eeprom_checksum(struct ixgbe_hw *hw)
  729. {
  730. u16 i;
  731. u16 j;
  732. u16 checksum = 0;
  733. u16 length = 0;
  734. u16 pointer = 0;
  735. u16 word = 0;
  736. /* Include 0x0-0x3F in the checksum */
  737. for (i = 0; i < IXGBE_EEPROM_CHECKSUM; i++) {
  738. if (hw->eeprom.ops.read(hw, i, &word) != 0) {
  739. hw_dbg(hw, "EEPROM read failed\n");
  740. break;
  741. }
  742. checksum += word;
  743. }
  744. /* Include all data from pointers except for the fw pointer */
  745. for (i = IXGBE_PCIE_ANALOG_PTR; i < IXGBE_FW_PTR; i++) {
  746. hw->eeprom.ops.read(hw, i, &pointer);
  747. /* Make sure the pointer seems valid */
  748. if (pointer != 0xFFFF && pointer != 0) {
  749. hw->eeprom.ops.read(hw, pointer, &length);
  750. if (length != 0xFFFF && length != 0) {
  751. for (j = pointer+1; j <= pointer+length; j++) {
  752. hw->eeprom.ops.read(hw, j, &word);
  753. checksum += word;
  754. }
  755. }
  756. }
  757. }
  758. checksum = (u16)IXGBE_EEPROM_SUM - checksum;
  759. return checksum;
  760. }
  761. /**
  762. * ixgbe_validate_eeprom_checksum_generic - Validate EEPROM checksum
  763. * @hw: pointer to hardware structure
  764. * @checksum_val: calculated checksum
  765. *
  766. * Performs checksum calculation and validates the EEPROM checksum. If the
  767. * caller does not need checksum_val, the value can be NULL.
  768. **/
  769. s32 ixgbe_validate_eeprom_checksum_generic(struct ixgbe_hw *hw,
  770. u16 *checksum_val)
  771. {
  772. s32 status;
  773. u16 checksum;
  774. u16 read_checksum = 0;
  775. /*
  776. * Read the first word from the EEPROM. If this times out or fails, do
  777. * not continue or we could be in for a very long wait while every
  778. * EEPROM read fails
  779. */
  780. status = hw->eeprom.ops.read(hw, 0, &checksum);
  781. if (status == 0) {
  782. checksum = ixgbe_calc_eeprom_checksum(hw);
  783. hw->eeprom.ops.read(hw, IXGBE_EEPROM_CHECKSUM, &read_checksum);
  784. /*
  785. * Verify read checksum from EEPROM is the same as
  786. * calculated checksum
  787. */
  788. if (read_checksum != checksum)
  789. status = IXGBE_ERR_EEPROM_CHECKSUM;
  790. /* If the user cares, return the calculated checksum */
  791. if (checksum_val)
  792. *checksum_val = checksum;
  793. } else {
  794. hw_dbg(hw, "EEPROM read failed\n");
  795. }
  796. return status;
  797. }
  798. /**
  799. * ixgbe_update_eeprom_checksum_generic - Updates the EEPROM checksum
  800. * @hw: pointer to hardware structure
  801. **/
  802. s32 ixgbe_update_eeprom_checksum_generic(struct ixgbe_hw *hw)
  803. {
  804. s32 status;
  805. u16 checksum;
  806. /*
  807. * Read the first word from the EEPROM. If this times out or fails, do
  808. * not continue or we could be in for a very long wait while every
  809. * EEPROM read fails
  810. */
  811. status = hw->eeprom.ops.read(hw, 0, &checksum);
  812. if (status == 0) {
  813. checksum = ixgbe_calc_eeprom_checksum(hw);
  814. status = hw->eeprom.ops.write(hw, IXGBE_EEPROM_CHECKSUM,
  815. checksum);
  816. } else {
  817. hw_dbg(hw, "EEPROM read failed\n");
  818. }
  819. return status;
  820. }
  821. /**
  822. * ixgbe_validate_mac_addr - Validate MAC address
  823. * @mac_addr: pointer to MAC address.
  824. *
  825. * Tests a MAC address to ensure it is a valid Individual Address
  826. **/
  827. s32 ixgbe_validate_mac_addr(u8 *mac_addr)
  828. {
  829. s32 status = 0;
  830. /* Make sure it is not a multicast address */
  831. if (IXGBE_IS_MULTICAST(mac_addr))
  832. status = IXGBE_ERR_INVALID_MAC_ADDR;
  833. /* Not a broadcast address */
  834. else if (IXGBE_IS_BROADCAST(mac_addr))
  835. status = IXGBE_ERR_INVALID_MAC_ADDR;
  836. /* Reject the zero address */
  837. else if (mac_addr[0] == 0 && mac_addr[1] == 0 && mac_addr[2] == 0 &&
  838. mac_addr[3] == 0 && mac_addr[4] == 0 && mac_addr[5] == 0)
  839. status = IXGBE_ERR_INVALID_MAC_ADDR;
  840. return status;
  841. }
  842. /**
  843. * ixgbe_set_rar_generic - Set Rx address register
  844. * @hw: pointer to hardware structure
  845. * @index: Receive address register to write
  846. * @addr: Address to put into receive address register
  847. * @vmdq: VMDq "set" or "pool" index
  848. * @enable_addr: set flag that address is active
  849. *
  850. * Puts an ethernet address into a receive address register.
  851. **/
  852. s32 ixgbe_set_rar_generic(struct ixgbe_hw *hw, u32 index, u8 *addr, u32 vmdq,
  853. u32 enable_addr)
  854. {
  855. u32 rar_low, rar_high;
  856. u32 rar_entries = hw->mac.num_rar_entries;
  857. /* setup VMDq pool selection before this RAR gets enabled */
  858. hw->mac.ops.set_vmdq(hw, index, vmdq);
  859. /* Make sure we are using a valid rar index range */
  860. if (index < rar_entries) {
  861. /*
  862. * HW expects these in little endian so we reverse the byte
  863. * order from network order (big endian) to little endian
  864. */
  865. rar_low = ((u32)addr[0] |
  866. ((u32)addr[1] << 8) |
  867. ((u32)addr[2] << 16) |
  868. ((u32)addr[3] << 24));
  869. /*
  870. * Some parts put the VMDq setting in the extra RAH bits,
  871. * so save everything except the lower 16 bits that hold part
  872. * of the address and the address valid bit.
  873. */
  874. rar_high = IXGBE_READ_REG(hw, IXGBE_RAH(index));
  875. rar_high &= ~(0x0000FFFF | IXGBE_RAH_AV);
  876. rar_high |= ((u32)addr[4] | ((u32)addr[5] << 8));
  877. if (enable_addr != 0)
  878. rar_high |= IXGBE_RAH_AV;
  879. IXGBE_WRITE_REG(hw, IXGBE_RAL(index), rar_low);
  880. IXGBE_WRITE_REG(hw, IXGBE_RAH(index), rar_high);
  881. } else {
  882. hw_dbg(hw, "RAR index %d is out of range.\n", index);
  883. }
  884. return 0;
  885. }
  886. /**
  887. * ixgbe_clear_rar_generic - Remove Rx address register
  888. * @hw: pointer to hardware structure
  889. * @index: Receive address register to write
  890. *
  891. * Clears an ethernet address from a receive address register.
  892. **/
  893. s32 ixgbe_clear_rar_generic(struct ixgbe_hw *hw, u32 index)
  894. {
  895. u32 rar_high;
  896. u32 rar_entries = hw->mac.num_rar_entries;
  897. /* Make sure we are using a valid rar index range */
  898. if (index < rar_entries) {
  899. /*
  900. * Some parts put the VMDq setting in the extra RAH bits,
  901. * so save everything except the lower 16 bits that hold part
  902. * of the address and the address valid bit.
  903. */
  904. rar_high = IXGBE_READ_REG(hw, IXGBE_RAH(index));
  905. rar_high &= ~(0x0000FFFF | IXGBE_RAH_AV);
  906. IXGBE_WRITE_REG(hw, IXGBE_RAL(index), 0);
  907. IXGBE_WRITE_REG(hw, IXGBE_RAH(index), rar_high);
  908. } else {
  909. hw_dbg(hw, "RAR index %d is out of range.\n", index);
  910. }
  911. /* clear VMDq pool/queue selection for this RAR */
  912. hw->mac.ops.clear_vmdq(hw, index, IXGBE_CLEAR_VMDQ_ALL);
  913. return 0;
  914. }
  915. /**
  916. * ixgbe_enable_rar - Enable Rx address register
  917. * @hw: pointer to hardware structure
  918. * @index: index into the RAR table
  919. *
  920. * Enables the select receive address register.
  921. **/
  922. static void ixgbe_enable_rar(struct ixgbe_hw *hw, u32 index)
  923. {
  924. u32 rar_high;
  925. rar_high = IXGBE_READ_REG(hw, IXGBE_RAH(index));
  926. rar_high |= IXGBE_RAH_AV;
  927. IXGBE_WRITE_REG(hw, IXGBE_RAH(index), rar_high);
  928. }
  929. /**
  930. * ixgbe_disable_rar - Disable Rx address register
  931. * @hw: pointer to hardware structure
  932. * @index: index into the RAR table
  933. *
  934. * Disables the select receive address register.
  935. **/
  936. static void ixgbe_disable_rar(struct ixgbe_hw *hw, u32 index)
  937. {
  938. u32 rar_high;
  939. rar_high = IXGBE_READ_REG(hw, IXGBE_RAH(index));
  940. rar_high &= (~IXGBE_RAH_AV);
  941. IXGBE_WRITE_REG(hw, IXGBE_RAH(index), rar_high);
  942. }
  943. /**
  944. * ixgbe_init_rx_addrs_generic - Initializes receive address filters.
  945. * @hw: pointer to hardware structure
  946. *
  947. * Places the MAC address in receive address register 0 and clears the rest
  948. * of the receive address registers. Clears the multicast table. Assumes
  949. * the receiver is in reset when the routine is called.
  950. **/
  951. s32 ixgbe_init_rx_addrs_generic(struct ixgbe_hw *hw)
  952. {
  953. u32 i;
  954. u32 rar_entries = hw->mac.num_rar_entries;
  955. /*
  956. * If the current mac address is valid, assume it is a software override
  957. * to the permanent address.
  958. * Otherwise, use the permanent address from the eeprom.
  959. */
  960. if (ixgbe_validate_mac_addr(hw->mac.addr) ==
  961. IXGBE_ERR_INVALID_MAC_ADDR) {
  962. /* Get the MAC address from the RAR0 for later reference */
  963. hw->mac.ops.get_mac_addr(hw, hw->mac.addr);
  964. hw_dbg(hw, " Keeping Current RAR0 Addr =%.2X %.2X %.2X ",
  965. hw->mac.addr[0], hw->mac.addr[1],
  966. hw->mac.addr[2]);
  967. hw_dbg(hw, "%.2X %.2X %.2X\n", hw->mac.addr[3],
  968. hw->mac.addr[4], hw->mac.addr[5]);
  969. } else {
  970. /* Setup the receive address. */
  971. hw_dbg(hw, "Overriding MAC Address in RAR[0]\n");
  972. hw_dbg(hw, " New MAC Addr =%.2X %.2X %.2X ",
  973. hw->mac.addr[0], hw->mac.addr[1],
  974. hw->mac.addr[2]);
  975. hw_dbg(hw, "%.2X %.2X %.2X\n", hw->mac.addr[3],
  976. hw->mac.addr[4], hw->mac.addr[5]);
  977. hw->mac.ops.set_rar(hw, 0, hw->mac.addr, 0, IXGBE_RAH_AV);
  978. }
  979. hw->addr_ctrl.overflow_promisc = 0;
  980. hw->addr_ctrl.rar_used_count = 1;
  981. /* Zero out the other receive addresses. */
  982. hw_dbg(hw, "Clearing RAR[1-%d]\n", rar_entries - 1);
  983. for (i = 1; i < rar_entries; i++) {
  984. IXGBE_WRITE_REG(hw, IXGBE_RAL(i), 0);
  985. IXGBE_WRITE_REG(hw, IXGBE_RAH(i), 0);
  986. }
  987. /* Clear the MTA */
  988. hw->addr_ctrl.mc_addr_in_rar_count = 0;
  989. hw->addr_ctrl.mta_in_use = 0;
  990. IXGBE_WRITE_REG(hw, IXGBE_MCSTCTRL, hw->mac.mc_filter_type);
  991. hw_dbg(hw, " Clearing MTA\n");
  992. for (i = 0; i < hw->mac.mcft_size; i++)
  993. IXGBE_WRITE_REG(hw, IXGBE_MTA(i), 0);
  994. if (hw->mac.ops.init_uta_tables)
  995. hw->mac.ops.init_uta_tables(hw);
  996. return 0;
  997. }
  998. /**
  999. * ixgbe_add_uc_addr - Adds a secondary unicast address.
  1000. * @hw: pointer to hardware structure
  1001. * @addr: new address
  1002. *
  1003. * Adds it to unused receive address register or goes into promiscuous mode.
  1004. **/
  1005. static void ixgbe_add_uc_addr(struct ixgbe_hw *hw, u8 *addr, u32 vmdq)
  1006. {
  1007. u32 rar_entries = hw->mac.num_rar_entries;
  1008. u32 rar;
  1009. hw_dbg(hw, " UC Addr = %.2X %.2X %.2X %.2X %.2X %.2X\n",
  1010. addr[0], addr[1], addr[2], addr[3], addr[4], addr[5]);
  1011. /*
  1012. * Place this address in the RAR if there is room,
  1013. * else put the controller into promiscuous mode
  1014. */
  1015. if (hw->addr_ctrl.rar_used_count < rar_entries) {
  1016. rar = hw->addr_ctrl.rar_used_count -
  1017. hw->addr_ctrl.mc_addr_in_rar_count;
  1018. hw->mac.ops.set_rar(hw, rar, addr, vmdq, IXGBE_RAH_AV);
  1019. hw_dbg(hw, "Added a secondary address to RAR[%d]\n", rar);
  1020. hw->addr_ctrl.rar_used_count++;
  1021. } else {
  1022. hw->addr_ctrl.overflow_promisc++;
  1023. }
  1024. hw_dbg(hw, "ixgbe_add_uc_addr Complete\n");
  1025. }
  1026. /**
  1027. * ixgbe_update_uc_addr_list_generic - Updates MAC list of secondary addresses
  1028. * @hw: pointer to hardware structure
  1029. * @addr_list: the list of new addresses
  1030. * @addr_count: number of addresses
  1031. * @next: iterator function to walk the address list
  1032. *
  1033. * The given list replaces any existing list. Clears the secondary addrs from
  1034. * receive address registers. Uses unused receive address registers for the
  1035. * first secondary addresses, and falls back to promiscuous mode as needed.
  1036. *
  1037. * Drivers using secondary unicast addresses must set user_set_promisc when
  1038. * manually putting the device into promiscuous mode.
  1039. **/
  1040. s32 ixgbe_update_uc_addr_list_generic(struct ixgbe_hw *hw, u8 *addr_list,
  1041. u32 addr_count, ixgbe_mc_addr_itr next)
  1042. {
  1043. u8 *addr;
  1044. u32 i;
  1045. u32 old_promisc_setting = hw->addr_ctrl.overflow_promisc;
  1046. u32 uc_addr_in_use;
  1047. u32 fctrl;
  1048. u32 vmdq;
  1049. /*
  1050. * Clear accounting of old secondary address list,
  1051. * don't count RAR[0]
  1052. */
  1053. uc_addr_in_use = hw->addr_ctrl.rar_used_count -
  1054. hw->addr_ctrl.mc_addr_in_rar_count - 1;
  1055. hw->addr_ctrl.rar_used_count -= uc_addr_in_use;
  1056. hw->addr_ctrl.overflow_promisc = 0;
  1057. /* Zero out the other receive addresses */
  1058. hw_dbg(hw, "Clearing RAR[1-%d]\n", uc_addr_in_use);
  1059. for (i = 1; i <= uc_addr_in_use; i++) {
  1060. IXGBE_WRITE_REG(hw, IXGBE_RAL(i), 0);
  1061. IXGBE_WRITE_REG(hw, IXGBE_RAH(i), 0);
  1062. }
  1063. /* Add the new addresses */
  1064. for (i = 0; i < addr_count; i++) {
  1065. hw_dbg(hw, " Adding the secondary addresses:\n");
  1066. addr = next(hw, &addr_list, &vmdq);
  1067. ixgbe_add_uc_addr(hw, addr, vmdq);
  1068. }
  1069. if (hw->addr_ctrl.overflow_promisc) {
  1070. /* enable promisc if not already in overflow or set by user */
  1071. if (!old_promisc_setting && !hw->addr_ctrl.user_set_promisc) {
  1072. hw_dbg(hw, " Entering address overflow promisc mode\n");
  1073. fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
  1074. fctrl |= IXGBE_FCTRL_UPE;
  1075. IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl);
  1076. }
  1077. } else {
  1078. /* only disable if set by overflow, not by user */
  1079. if (old_promisc_setting && !hw->addr_ctrl.user_set_promisc) {
  1080. hw_dbg(hw, " Leaving address overflow promisc mode\n");
  1081. fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
  1082. fctrl &= ~IXGBE_FCTRL_UPE;
  1083. IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl);
  1084. }
  1085. }
  1086. hw_dbg(hw, "ixgbe_update_uc_addr_list_generic Complete\n");
  1087. return 0;
  1088. }
  1089. /**
  1090. * ixgbe_mta_vector - Determines bit-vector in multicast table to set
  1091. * @hw: pointer to hardware structure
  1092. * @mc_addr: the multicast address
  1093. *
  1094. * Extracts the 12 bits, from a multicast address, to determine which
  1095. * bit-vector to set in the multicast table. The hardware uses 12 bits, from
  1096. * incoming rx multicast addresses, to determine the bit-vector to check in
  1097. * the MTA. Which of the 4 combination, of 12-bits, the hardware uses is set
  1098. * by the MO field of the MCSTCTRL. The MO field is set during initialization
  1099. * to mc_filter_type.
  1100. **/
  1101. static s32 ixgbe_mta_vector(struct ixgbe_hw *hw, u8 *mc_addr)
  1102. {
  1103. u32 vector = 0;
  1104. switch (hw->mac.mc_filter_type) {
  1105. case 0: /* use bits [47:36] of the address */
  1106. vector = ((mc_addr[4] >> 4) | (((u16)mc_addr[5]) << 4));
  1107. break;
  1108. case 1: /* use bits [46:35] of the address */
  1109. vector = ((mc_addr[4] >> 3) | (((u16)mc_addr[5]) << 5));
  1110. break;
  1111. case 2: /* use bits [45:34] of the address */
  1112. vector = ((mc_addr[4] >> 2) | (((u16)mc_addr[5]) << 6));
  1113. break;
  1114. case 3: /* use bits [43:32] of the address */
  1115. vector = ((mc_addr[4]) | (((u16)mc_addr[5]) << 8));
  1116. break;
  1117. default: /* Invalid mc_filter_type */
  1118. hw_dbg(hw, "MC filter type param set incorrectly\n");
  1119. break;
  1120. }
  1121. /* vector can only be 12-bits or boundary will be exceeded */
  1122. vector &= 0xFFF;
  1123. return vector;
  1124. }
  1125. /**
  1126. * ixgbe_set_mta - Set bit-vector in multicast table
  1127. * @hw: pointer to hardware structure
  1128. * @hash_value: Multicast address hash value
  1129. *
  1130. * Sets the bit-vector in the multicast table.
  1131. **/
  1132. static void ixgbe_set_mta(struct ixgbe_hw *hw, u8 *mc_addr)
  1133. {
  1134. u32 vector;
  1135. u32 vector_bit;
  1136. u32 vector_reg;
  1137. u32 mta_reg;
  1138. hw->addr_ctrl.mta_in_use++;
  1139. vector = ixgbe_mta_vector(hw, mc_addr);
  1140. hw_dbg(hw, " bit-vector = 0x%03X\n", vector);
  1141. /*
  1142. * The MTA is a register array of 128 32-bit registers. It is treated
  1143. * like an array of 4096 bits. We want to set bit
  1144. * BitArray[vector_value]. So we figure out what register the bit is
  1145. * in, read it, OR in the new bit, then write back the new value. The
  1146. * register is determined by the upper 7 bits of the vector value and
  1147. * the bit within that register are determined by the lower 5 bits of
  1148. * the value.
  1149. */
  1150. vector_reg = (vector >> 5) & 0x7F;
  1151. vector_bit = vector & 0x1F;
  1152. mta_reg = IXGBE_READ_REG(hw, IXGBE_MTA(vector_reg));
  1153. mta_reg |= (1 << vector_bit);
  1154. IXGBE_WRITE_REG(hw, IXGBE_MTA(vector_reg), mta_reg);
  1155. }
  1156. /**
  1157. * ixgbe_add_mc_addr - Adds a multicast address.
  1158. * @hw: pointer to hardware structure
  1159. * @mc_addr: new multicast address
  1160. *
  1161. * Adds it to unused receive address register or to the multicast table.
  1162. **/
  1163. static void ixgbe_add_mc_addr(struct ixgbe_hw *hw, u8 *mc_addr)
  1164. {
  1165. u32 rar_entries = hw->mac.num_rar_entries;
  1166. u32 rar;
  1167. hw_dbg(hw, " MC Addr =%.2X %.2X %.2X %.2X %.2X %.2X\n",
  1168. mc_addr[0], mc_addr[1], mc_addr[2],
  1169. mc_addr[3], mc_addr[4], mc_addr[5]);
  1170. /*
  1171. * Place this multicast address in the RAR if there is room,
  1172. * else put it in the MTA
  1173. */
  1174. if (hw->addr_ctrl.rar_used_count < rar_entries) {
  1175. /* use RAR from the end up for multicast */
  1176. rar = rar_entries - hw->addr_ctrl.mc_addr_in_rar_count - 1;
  1177. hw->mac.ops.set_rar(hw, rar, mc_addr, 0, IXGBE_RAH_AV);
  1178. hw_dbg(hw, "Added a multicast address to RAR[%d]\n", rar);
  1179. hw->addr_ctrl.rar_used_count++;
  1180. hw->addr_ctrl.mc_addr_in_rar_count++;
  1181. } else {
  1182. ixgbe_set_mta(hw, mc_addr);
  1183. }
  1184. hw_dbg(hw, "ixgbe_add_mc_addr Complete\n");
  1185. }
  1186. /**
  1187. * ixgbe_update_mc_addr_list_generic - Updates MAC list of multicast addresses
  1188. * @hw: pointer to hardware structure
  1189. * @mc_addr_list: the list of new multicast addresses
  1190. * @mc_addr_count: number of addresses
  1191. * @next: iterator function to walk the multicast address list
  1192. *
  1193. * The given list replaces any existing list. Clears the MC addrs from receive
  1194. * address registers and the multicast table. Uses unused receive address
  1195. * registers for the first multicast addresses, and hashes the rest into the
  1196. * multicast table.
  1197. **/
  1198. s32 ixgbe_update_mc_addr_list_generic(struct ixgbe_hw *hw, u8 *mc_addr_list,
  1199. u32 mc_addr_count, ixgbe_mc_addr_itr next)
  1200. {
  1201. u32 i;
  1202. u32 rar_entries = hw->mac.num_rar_entries;
  1203. u32 vmdq;
  1204. /*
  1205. * Set the new number of MC addresses that we are being requested to
  1206. * use.
  1207. */
  1208. hw->addr_ctrl.num_mc_addrs = mc_addr_count;
  1209. hw->addr_ctrl.rar_used_count -= hw->addr_ctrl.mc_addr_in_rar_count;
  1210. hw->addr_ctrl.mc_addr_in_rar_count = 0;
  1211. hw->addr_ctrl.mta_in_use = 0;
  1212. /* Zero out the other receive addresses. */
  1213. hw_dbg(hw, "Clearing RAR[%d-%d]\n", hw->addr_ctrl.rar_used_count,
  1214. rar_entries - 1);
  1215. for (i = hw->addr_ctrl.rar_used_count; i < rar_entries; i++) {
  1216. IXGBE_WRITE_REG(hw, IXGBE_RAL(i), 0);
  1217. IXGBE_WRITE_REG(hw, IXGBE_RAH(i), 0);
  1218. }
  1219. /* Clear the MTA */
  1220. hw_dbg(hw, " Clearing MTA\n");
  1221. for (i = 0; i < hw->mac.mcft_size; i++)
  1222. IXGBE_WRITE_REG(hw, IXGBE_MTA(i), 0);
  1223. /* Add the new addresses */
  1224. for (i = 0; i < mc_addr_count; i++) {
  1225. hw_dbg(hw, " Adding the multicast addresses:\n");
  1226. ixgbe_add_mc_addr(hw, next(hw, &mc_addr_list, &vmdq));
  1227. }
  1228. /* Enable mta */
  1229. if (hw->addr_ctrl.mta_in_use > 0)
  1230. IXGBE_WRITE_REG(hw, IXGBE_MCSTCTRL,
  1231. IXGBE_MCSTCTRL_MFE | hw->mac.mc_filter_type);
  1232. hw_dbg(hw, "ixgbe_update_mc_addr_list_generic Complete\n");
  1233. return 0;
  1234. }
  1235. /**
  1236. * ixgbe_enable_mc_generic - Enable multicast address in RAR
  1237. * @hw: pointer to hardware structure
  1238. *
  1239. * Enables multicast address in RAR and the use of the multicast hash table.
  1240. **/
  1241. s32 ixgbe_enable_mc_generic(struct ixgbe_hw *hw)
  1242. {
  1243. u32 i;
  1244. u32 rar_entries = hw->mac.num_rar_entries;
  1245. struct ixgbe_addr_filter_info *a = &hw->addr_ctrl;
  1246. if (a->mc_addr_in_rar_count > 0)
  1247. for (i = (rar_entries - a->mc_addr_in_rar_count);
  1248. i < rar_entries; i++)
  1249. ixgbe_enable_rar(hw, i);
  1250. if (a->mta_in_use > 0)
  1251. IXGBE_WRITE_REG(hw, IXGBE_MCSTCTRL, IXGBE_MCSTCTRL_MFE |
  1252. hw->mac.mc_filter_type);
  1253. return 0;
  1254. }
  1255. /**
  1256. * ixgbe_disable_mc_generic - Disable multicast address in RAR
  1257. * @hw: pointer to hardware structure
  1258. *
  1259. * Disables multicast address in RAR and the use of the multicast hash table.
  1260. **/
  1261. s32 ixgbe_disable_mc_generic(struct ixgbe_hw *hw)
  1262. {
  1263. u32 i;
  1264. u32 rar_entries = hw->mac.num_rar_entries;
  1265. struct ixgbe_addr_filter_info *a = &hw->addr_ctrl;
  1266. if (a->mc_addr_in_rar_count > 0)
  1267. for (i = (rar_entries - a->mc_addr_in_rar_count);
  1268. i < rar_entries; i++)
  1269. ixgbe_disable_rar(hw, i);
  1270. if (a->mta_in_use > 0)
  1271. IXGBE_WRITE_REG(hw, IXGBE_MCSTCTRL, hw->mac.mc_filter_type);
  1272. return 0;
  1273. }
  1274. /**
  1275. * ixgbe_fc_autoneg - Configure flow control
  1276. * @hw: pointer to hardware structure
  1277. *
  1278. * Negotiates flow control capabilities with link partner using autoneg and
  1279. * applies the results.
  1280. **/
  1281. s32 ixgbe_fc_autoneg(struct ixgbe_hw *hw)
  1282. {
  1283. s32 ret_val = 0;
  1284. u32 i, reg, pcs_anadv_reg, pcs_lpab_reg;
  1285. reg = IXGBE_READ_REG(hw, IXGBE_PCS1GANA);
  1286. /*
  1287. * The possible values of fc.current_mode are:
  1288. * 0: Flow control is completely disabled
  1289. * 1: Rx flow control is enabled (we can receive pause frames,
  1290. * but not send pause frames).
  1291. * 2: Tx flow control is enabled (we can send pause frames but
  1292. * we do not support receiving pause frames).
  1293. * 3: Both Rx and Tx flow control (symmetric) are enabled.
  1294. * other: Invalid.
  1295. */
  1296. switch (hw->fc.current_mode) {
  1297. case ixgbe_fc_none:
  1298. /* Flow control completely disabled by software override. */
  1299. reg &= ~(IXGBE_PCS1GANA_SYM_PAUSE | IXGBE_PCS1GANA_ASM_PAUSE);
  1300. break;
  1301. case ixgbe_fc_rx_pause:
  1302. /*
  1303. * Rx Flow control is enabled and Tx Flow control is
  1304. * disabled by software override. Since there really
  1305. * isn't a way to advertise that we are capable of RX
  1306. * Pause ONLY, we will advertise that we support both
  1307. * symmetric and asymmetric Rx PAUSE. Later, we will
  1308. * disable the adapter's ability to send PAUSE frames.
  1309. */
  1310. reg |= (IXGBE_PCS1GANA_SYM_PAUSE | IXGBE_PCS1GANA_ASM_PAUSE);
  1311. break;
  1312. case ixgbe_fc_tx_pause:
  1313. /*
  1314. * Tx Flow control is enabled, and Rx Flow control is
  1315. * disabled by software override.
  1316. */
  1317. reg |= (IXGBE_PCS1GANA_ASM_PAUSE);
  1318. reg &= ~(IXGBE_PCS1GANA_SYM_PAUSE);
  1319. break;
  1320. case ixgbe_fc_full:
  1321. /* Flow control (both Rx and Tx) is enabled by SW override. */
  1322. reg |= (IXGBE_PCS1GANA_SYM_PAUSE | IXGBE_PCS1GANA_ASM_PAUSE);
  1323. break;
  1324. default:
  1325. hw_dbg(hw, "Flow control param set incorrectly\n");
  1326. ret_val = -IXGBE_ERR_CONFIG;
  1327. goto out;
  1328. break;
  1329. }
  1330. IXGBE_WRITE_REG(hw, IXGBE_PCS1GANA, reg);
  1331. reg = IXGBE_READ_REG(hw, IXGBE_PCS1GLCTL);
  1332. /* Set PCS register for autoneg */
  1333. /* Enable and restart autoneg */
  1334. reg |= IXGBE_PCS1GLCTL_AN_ENABLE | IXGBE_PCS1GLCTL_AN_RESTART;
  1335. /* Disable AN timeout */
  1336. if (hw->fc.strict_ieee)
  1337. reg &= ~IXGBE_PCS1GLCTL_AN_1G_TIMEOUT_EN;
  1338. hw_dbg(hw, "Configuring Autoneg; PCS_LCTL = 0x%08X\n", reg);
  1339. IXGBE_WRITE_REG(hw, IXGBE_PCS1GLCTL, reg);
  1340. /* See if autonegotiation has succeeded */
  1341. hw->mac.autoneg_succeeded = 0;
  1342. for (i = 0; i < FIBER_LINK_UP_LIMIT; i++) {
  1343. msleep(10);
  1344. reg = IXGBE_READ_REG(hw, IXGBE_PCS1GLSTA);
  1345. if ((reg & (IXGBE_PCS1GLSTA_LINK_OK |
  1346. IXGBE_PCS1GLSTA_AN_COMPLETE)) ==
  1347. (IXGBE_PCS1GLSTA_LINK_OK |
  1348. IXGBE_PCS1GLSTA_AN_COMPLETE)) {
  1349. if (!(reg & IXGBE_PCS1GLSTA_AN_TIMED_OUT))
  1350. hw->mac.autoneg_succeeded = 1;
  1351. break;
  1352. }
  1353. }
  1354. if (!hw->mac.autoneg_succeeded) {
  1355. /* Autoneg failed to achieve a link, so we turn fc off */
  1356. hw->fc.current_mode = ixgbe_fc_none;
  1357. hw_dbg(hw, "Flow Control = NONE.\n");
  1358. goto out;
  1359. }
  1360. /*
  1361. * Read the AN advertisement and LP ability registers and resolve
  1362. * local flow control settings accordingly
  1363. */
  1364. pcs_anadv_reg = IXGBE_READ_REG(hw, IXGBE_PCS1GANA);
  1365. pcs_lpab_reg = IXGBE_READ_REG(hw, IXGBE_PCS1GANLP);
  1366. if ((pcs_anadv_reg & IXGBE_PCS1GANA_SYM_PAUSE) &&
  1367. (pcs_lpab_reg & IXGBE_PCS1GANA_SYM_PAUSE)) {
  1368. /*
  1369. * Now we need to check if the user selected Rx ONLY
  1370. * of pause frames. In this case, we had to advertise
  1371. * FULL flow control because we could not advertise RX
  1372. * ONLY. Hence, we must now check to see if we need to
  1373. * turn OFF the TRANSMISSION of PAUSE frames.
  1374. */
  1375. if (hw->fc.requested_mode == ixgbe_fc_full) {
  1376. hw->fc.current_mode = ixgbe_fc_full;
  1377. hw_dbg(hw, "Flow Control = FULL.\n");
  1378. } else {
  1379. hw->fc.current_mode = ixgbe_fc_rx_pause;
  1380. hw_dbg(hw, "Flow Control = RX PAUSE frames only.\n");
  1381. }
  1382. } else if (!(pcs_anadv_reg & IXGBE_PCS1GANA_SYM_PAUSE) &&
  1383. (pcs_anadv_reg & IXGBE_PCS1GANA_ASM_PAUSE) &&
  1384. (pcs_lpab_reg & IXGBE_PCS1GANA_SYM_PAUSE) &&
  1385. (pcs_lpab_reg & IXGBE_PCS1GANA_ASM_PAUSE)) {
  1386. hw->fc.current_mode = ixgbe_fc_tx_pause;
  1387. hw_dbg(hw, "Flow Control = TX PAUSE frames only.\n");
  1388. } else if ((pcs_anadv_reg & IXGBE_PCS1GANA_SYM_PAUSE) &&
  1389. (pcs_anadv_reg & IXGBE_PCS1GANA_ASM_PAUSE) &&
  1390. !(pcs_lpab_reg & IXGBE_PCS1GANA_SYM_PAUSE) &&
  1391. (pcs_lpab_reg & IXGBE_PCS1GANA_ASM_PAUSE)) {
  1392. hw->fc.current_mode = ixgbe_fc_rx_pause;
  1393. hw_dbg(hw, "Flow Control = RX PAUSE frames only.\n");
  1394. } else {
  1395. hw->fc.current_mode = ixgbe_fc_none;
  1396. hw_dbg(hw, "Flow Control = NONE.\n");
  1397. }
  1398. out:
  1399. return ret_val;
  1400. }
  1401. /**
  1402. * ixgbe_disable_pcie_master - Disable PCI-express master access
  1403. * @hw: pointer to hardware structure
  1404. *
  1405. * Disables PCI-Express master access and verifies there are no pending
  1406. * requests. IXGBE_ERR_MASTER_REQUESTS_PENDING is returned if master disable
  1407. * bit hasn't caused the master requests to be disabled, else 0
  1408. * is returned signifying master requests disabled.
  1409. **/
  1410. s32 ixgbe_disable_pcie_master(struct ixgbe_hw *hw)
  1411. {
  1412. u32 i;
  1413. u32 reg_val;
  1414. u32 number_of_queues;
  1415. s32 status = IXGBE_ERR_MASTER_REQUESTS_PENDING;
  1416. /* Disable the receive unit by stopping each queue */
  1417. number_of_queues = hw->mac.max_rx_queues;
  1418. for (i = 0; i < number_of_queues; i++) {
  1419. reg_val = IXGBE_READ_REG(hw, IXGBE_RXDCTL(i));
  1420. if (reg_val & IXGBE_RXDCTL_ENABLE) {
  1421. reg_val &= ~IXGBE_RXDCTL_ENABLE;
  1422. IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(i), reg_val);
  1423. }
  1424. }
  1425. reg_val = IXGBE_READ_REG(hw, IXGBE_CTRL);
  1426. reg_val |= IXGBE_CTRL_GIO_DIS;
  1427. IXGBE_WRITE_REG(hw, IXGBE_CTRL, reg_val);
  1428. for (i = 0; i < IXGBE_PCI_MASTER_DISABLE_TIMEOUT; i++) {
  1429. if (!(IXGBE_READ_REG(hw, IXGBE_STATUS) & IXGBE_STATUS_GIO)) {
  1430. status = 0;
  1431. break;
  1432. }
  1433. udelay(100);
  1434. }
  1435. return status;
  1436. }
  1437. /**
  1438. * ixgbe_acquire_swfw_sync - Acquire SWFW semaphore
  1439. * @hw: pointer to hardware structure
  1440. * @mask: Mask to specify which semaphore to acquire
  1441. *
  1442. * Acquires the SWFW semaphore thought the GSSR register for the specified
  1443. * function (CSR, PHY0, PHY1, EEPROM, Flash)
  1444. **/
  1445. s32 ixgbe_acquire_swfw_sync(struct ixgbe_hw *hw, u16 mask)
  1446. {
  1447. u32 gssr;
  1448. u32 swmask = mask;
  1449. u32 fwmask = mask << 5;
  1450. s32 timeout = 200;
  1451. while (timeout) {
  1452. if (ixgbe_get_eeprom_semaphore(hw))
  1453. return -IXGBE_ERR_SWFW_SYNC;
  1454. gssr = IXGBE_READ_REG(hw, IXGBE_GSSR);
  1455. if (!(gssr & (fwmask | swmask)))
  1456. break;
  1457. /*
  1458. * Firmware currently using resource (fwmask) or other software
  1459. * thread currently using resource (swmask)
  1460. */
  1461. ixgbe_release_eeprom_semaphore(hw);
  1462. msleep(5);
  1463. timeout--;
  1464. }
  1465. if (!timeout) {
  1466. hw_dbg(hw, "Driver can't access resource, GSSR timeout.\n");
  1467. return -IXGBE_ERR_SWFW_SYNC;
  1468. }
  1469. gssr |= swmask;
  1470. IXGBE_WRITE_REG(hw, IXGBE_GSSR, gssr);
  1471. ixgbe_release_eeprom_semaphore(hw);
  1472. return 0;
  1473. }
  1474. /**
  1475. * ixgbe_release_swfw_sync - Release SWFW semaphore
  1476. * @hw: pointer to hardware structure
  1477. * @mask: Mask to specify which semaphore to release
  1478. *
  1479. * Releases the SWFW semaphore thought the GSSR register for the specified
  1480. * function (CSR, PHY0, PHY1, EEPROM, Flash)
  1481. **/
  1482. void ixgbe_release_swfw_sync(struct ixgbe_hw *hw, u16 mask)
  1483. {
  1484. u32 gssr;
  1485. u32 swmask = mask;
  1486. ixgbe_get_eeprom_semaphore(hw);
  1487. gssr = IXGBE_READ_REG(hw, IXGBE_GSSR);
  1488. gssr &= ~swmask;
  1489. IXGBE_WRITE_REG(hw, IXGBE_GSSR, gssr);
  1490. ixgbe_release_eeprom_semaphore(hw);
  1491. }