ixgbe_common.c 62 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244
  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 <linux/list.h>
  24. #include <linux/netdevice.h>
  25. #include "ixgbe.h"
  26. #include "ixgbe_common.h"
  27. #include "ixgbe_phy.h"
  28. static s32 ixgbe_poll_eeprom_eerd_done(struct ixgbe_hw *hw);
  29. static s32 ixgbe_acquire_eeprom(struct ixgbe_hw *hw);
  30. static s32 ixgbe_get_eeprom_semaphore(struct ixgbe_hw *hw);
  31. static void ixgbe_release_eeprom_semaphore(struct ixgbe_hw *hw);
  32. static s32 ixgbe_ready_eeprom(struct ixgbe_hw *hw);
  33. static void ixgbe_standby_eeprom(struct ixgbe_hw *hw);
  34. static void ixgbe_shift_out_eeprom_bits(struct ixgbe_hw *hw, u16 data,
  35. u16 count);
  36. static u16 ixgbe_shift_in_eeprom_bits(struct ixgbe_hw *hw, u16 count);
  37. static void ixgbe_raise_eeprom_clk(struct ixgbe_hw *hw, u32 *eec);
  38. static void ixgbe_lower_eeprom_clk(struct ixgbe_hw *hw, u32 *eec);
  39. static void ixgbe_release_eeprom(struct ixgbe_hw *hw);
  40. static u16 ixgbe_calc_eeprom_checksum(struct ixgbe_hw *hw);
  41. static void ixgbe_enable_rar(struct ixgbe_hw *hw, u32 index);
  42. static void ixgbe_disable_rar(struct ixgbe_hw *hw, u32 index);
  43. static s32 ixgbe_mta_vector(struct ixgbe_hw *hw, u8 *mc_addr);
  44. static void ixgbe_add_uc_addr(struct ixgbe_hw *hw, u8 *addr, u32 vmdq);
  45. static s32 ixgbe_setup_fc(struct ixgbe_hw *hw, s32 packetbuf_num);
  46. /**
  47. * ixgbe_start_hw_generic - Prepare hardware for Tx/Rx
  48. * @hw: pointer to hardware structure
  49. *
  50. * Starts the hardware by filling the bus info structure and media type, clears
  51. * all on chip counters, initializes receive address registers, multicast
  52. * table, VLAN filter table, calls routine to set up link and flow control
  53. * settings, and leaves transmit and receive units disabled and uninitialized
  54. **/
  55. s32 ixgbe_start_hw_generic(struct ixgbe_hw *hw)
  56. {
  57. u32 ctrl_ext;
  58. /* Set the media type */
  59. hw->phy.media_type = hw->mac.ops.get_media_type(hw);
  60. /* Identify the PHY */
  61. hw->phy.ops.identify(hw);
  62. /* Clear the VLAN filter table */
  63. hw->mac.ops.clear_vfta(hw);
  64. /* Clear statistics registers */
  65. hw->mac.ops.clear_hw_cntrs(hw);
  66. /* Set No Snoop Disable */
  67. ctrl_ext = IXGBE_READ_REG(hw, IXGBE_CTRL_EXT);
  68. ctrl_ext |= IXGBE_CTRL_EXT_NS_DIS;
  69. IXGBE_WRITE_REG(hw, IXGBE_CTRL_EXT, ctrl_ext);
  70. IXGBE_WRITE_FLUSH(hw);
  71. /* Setup flow control */
  72. ixgbe_setup_fc(hw, 0);
  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. s32 status;
  90. /* Reset the hardware */
  91. status = hw->mac.ops.reset_hw(hw);
  92. if (status == 0) {
  93. /* Start the HW */
  94. status = hw->mac.ops.start_hw(hw);
  95. }
  96. return status;
  97. }
  98. /**
  99. * ixgbe_clear_hw_cntrs_generic - Generic clear hardware counters
  100. * @hw: pointer to hardware structure
  101. *
  102. * Clears all hardware statistics counters by reading them from the hardware
  103. * Statistics counters are clear on read.
  104. **/
  105. s32 ixgbe_clear_hw_cntrs_generic(struct ixgbe_hw *hw)
  106. {
  107. u16 i = 0;
  108. IXGBE_READ_REG(hw, IXGBE_CRCERRS);
  109. IXGBE_READ_REG(hw, IXGBE_ILLERRC);
  110. IXGBE_READ_REG(hw, IXGBE_ERRBC);
  111. IXGBE_READ_REG(hw, IXGBE_MSPDC);
  112. for (i = 0; i < 8; i++)
  113. IXGBE_READ_REG(hw, IXGBE_MPC(i));
  114. IXGBE_READ_REG(hw, IXGBE_MLFC);
  115. IXGBE_READ_REG(hw, IXGBE_MRFC);
  116. IXGBE_READ_REG(hw, IXGBE_RLEC);
  117. IXGBE_READ_REG(hw, IXGBE_LXONTXC);
  118. IXGBE_READ_REG(hw, IXGBE_LXONRXC);
  119. IXGBE_READ_REG(hw, IXGBE_LXOFFTXC);
  120. IXGBE_READ_REG(hw, IXGBE_LXOFFRXC);
  121. for (i = 0; i < 8; i++) {
  122. IXGBE_READ_REG(hw, IXGBE_PXONTXC(i));
  123. IXGBE_READ_REG(hw, IXGBE_PXONRXC(i));
  124. IXGBE_READ_REG(hw, IXGBE_PXOFFTXC(i));
  125. IXGBE_READ_REG(hw, IXGBE_PXOFFRXC(i));
  126. }
  127. IXGBE_READ_REG(hw, IXGBE_PRC64);
  128. IXGBE_READ_REG(hw, IXGBE_PRC127);
  129. IXGBE_READ_REG(hw, IXGBE_PRC255);
  130. IXGBE_READ_REG(hw, IXGBE_PRC511);
  131. IXGBE_READ_REG(hw, IXGBE_PRC1023);
  132. IXGBE_READ_REG(hw, IXGBE_PRC1522);
  133. IXGBE_READ_REG(hw, IXGBE_GPRC);
  134. IXGBE_READ_REG(hw, IXGBE_BPRC);
  135. IXGBE_READ_REG(hw, IXGBE_MPRC);
  136. IXGBE_READ_REG(hw, IXGBE_GPTC);
  137. IXGBE_READ_REG(hw, IXGBE_GORCL);
  138. IXGBE_READ_REG(hw, IXGBE_GORCH);
  139. IXGBE_READ_REG(hw, IXGBE_GOTCL);
  140. IXGBE_READ_REG(hw, IXGBE_GOTCH);
  141. for (i = 0; i < 8; i++)
  142. IXGBE_READ_REG(hw, IXGBE_RNBC(i));
  143. IXGBE_READ_REG(hw, IXGBE_RUC);
  144. IXGBE_READ_REG(hw, IXGBE_RFC);
  145. IXGBE_READ_REG(hw, IXGBE_ROC);
  146. IXGBE_READ_REG(hw, IXGBE_RJC);
  147. IXGBE_READ_REG(hw, IXGBE_MNGPRC);
  148. IXGBE_READ_REG(hw, IXGBE_MNGPDC);
  149. IXGBE_READ_REG(hw, IXGBE_MNGPTC);
  150. IXGBE_READ_REG(hw, IXGBE_TORL);
  151. IXGBE_READ_REG(hw, IXGBE_TORH);
  152. IXGBE_READ_REG(hw, IXGBE_TPR);
  153. IXGBE_READ_REG(hw, IXGBE_TPT);
  154. IXGBE_READ_REG(hw, IXGBE_PTC64);
  155. IXGBE_READ_REG(hw, IXGBE_PTC127);
  156. IXGBE_READ_REG(hw, IXGBE_PTC255);
  157. IXGBE_READ_REG(hw, IXGBE_PTC511);
  158. IXGBE_READ_REG(hw, IXGBE_PTC1023);
  159. IXGBE_READ_REG(hw, IXGBE_PTC1522);
  160. IXGBE_READ_REG(hw, IXGBE_MPTC);
  161. IXGBE_READ_REG(hw, IXGBE_BPTC);
  162. for (i = 0; i < 16; i++) {
  163. IXGBE_READ_REG(hw, IXGBE_QPRC(i));
  164. IXGBE_READ_REG(hw, IXGBE_QBRC(i));
  165. IXGBE_READ_REG(hw, IXGBE_QPTC(i));
  166. IXGBE_READ_REG(hw, IXGBE_QBTC(i));
  167. }
  168. return 0;
  169. }
  170. /**
  171. * ixgbe_read_pba_num_generic - Reads part number from EEPROM
  172. * @hw: pointer to hardware structure
  173. * @pba_num: stores the part number from the EEPROM
  174. *
  175. * Reads the part number from the EEPROM.
  176. **/
  177. s32 ixgbe_read_pba_num_generic(struct ixgbe_hw *hw, u32 *pba_num)
  178. {
  179. s32 ret_val;
  180. u16 data;
  181. ret_val = hw->eeprom.ops.read(hw, IXGBE_PBANUM0_PTR, &data);
  182. if (ret_val) {
  183. hw_dbg(hw, "NVM Read Error\n");
  184. return ret_val;
  185. }
  186. *pba_num = (u32)(data << 16);
  187. ret_val = hw->eeprom.ops.read(hw, IXGBE_PBANUM1_PTR, &data);
  188. if (ret_val) {
  189. hw_dbg(hw, "NVM Read Error\n");
  190. return ret_val;
  191. }
  192. *pba_num |= data;
  193. return 0;
  194. }
  195. /**
  196. * ixgbe_get_mac_addr_generic - Generic get MAC address
  197. * @hw: pointer to hardware structure
  198. * @mac_addr: Adapter MAC address
  199. *
  200. * Reads the adapter's MAC address from first Receive Address Register (RAR0)
  201. * A reset of the adapter must be performed prior to calling this function
  202. * in order for the MAC address to have been loaded from the EEPROM into RAR0
  203. **/
  204. s32 ixgbe_get_mac_addr_generic(struct ixgbe_hw *hw, u8 *mac_addr)
  205. {
  206. u32 rar_high;
  207. u32 rar_low;
  208. u16 i;
  209. rar_high = IXGBE_READ_REG(hw, IXGBE_RAH(0));
  210. rar_low = IXGBE_READ_REG(hw, IXGBE_RAL(0));
  211. for (i = 0; i < 4; i++)
  212. mac_addr[i] = (u8)(rar_low >> (i*8));
  213. for (i = 0; i < 2; i++)
  214. mac_addr[i+4] = (u8)(rar_high >> (i*8));
  215. return 0;
  216. }
  217. /**
  218. * ixgbe_get_bus_info_generic - Generic set PCI bus info
  219. * @hw: pointer to hardware structure
  220. *
  221. * Sets the PCI bus info (speed, width, type) within the ixgbe_hw structure
  222. **/
  223. s32 ixgbe_get_bus_info_generic(struct ixgbe_hw *hw)
  224. {
  225. struct ixgbe_adapter *adapter = hw->back;
  226. struct ixgbe_mac_info *mac = &hw->mac;
  227. u16 link_status;
  228. hw->bus.type = ixgbe_bus_type_pci_express;
  229. /* Get the negotiated link width and speed from PCI config space */
  230. pci_read_config_word(adapter->pdev, IXGBE_PCI_LINK_STATUS,
  231. &link_status);
  232. switch (link_status & IXGBE_PCI_LINK_WIDTH) {
  233. case IXGBE_PCI_LINK_WIDTH_1:
  234. hw->bus.width = ixgbe_bus_width_pcie_x1;
  235. break;
  236. case IXGBE_PCI_LINK_WIDTH_2:
  237. hw->bus.width = ixgbe_bus_width_pcie_x2;
  238. break;
  239. case IXGBE_PCI_LINK_WIDTH_4:
  240. hw->bus.width = ixgbe_bus_width_pcie_x4;
  241. break;
  242. case IXGBE_PCI_LINK_WIDTH_8:
  243. hw->bus.width = ixgbe_bus_width_pcie_x8;
  244. break;
  245. default:
  246. hw->bus.width = ixgbe_bus_width_unknown;
  247. break;
  248. }
  249. switch (link_status & IXGBE_PCI_LINK_SPEED) {
  250. case IXGBE_PCI_LINK_SPEED_2500:
  251. hw->bus.speed = ixgbe_bus_speed_2500;
  252. break;
  253. case IXGBE_PCI_LINK_SPEED_5000:
  254. hw->bus.speed = ixgbe_bus_speed_5000;
  255. break;
  256. default:
  257. hw->bus.speed = ixgbe_bus_speed_unknown;
  258. break;
  259. }
  260. mac->ops.set_lan_id(hw);
  261. return 0;
  262. }
  263. /**
  264. * ixgbe_set_lan_id_multi_port_pcie - Set LAN id for PCIe multiple port devices
  265. * @hw: pointer to the HW structure
  266. *
  267. * Determines the LAN function id by reading memory-mapped registers
  268. * and swaps the port value if requested.
  269. **/
  270. void ixgbe_set_lan_id_multi_port_pcie(struct ixgbe_hw *hw)
  271. {
  272. struct ixgbe_bus_info *bus = &hw->bus;
  273. u32 reg;
  274. reg = IXGBE_READ_REG(hw, IXGBE_STATUS);
  275. bus->func = (reg & IXGBE_STATUS_LAN_ID) >> IXGBE_STATUS_LAN_ID_SHIFT;
  276. bus->lan_id = bus->func;
  277. /* check for a port swap */
  278. reg = IXGBE_READ_REG(hw, IXGBE_FACTPS);
  279. if (reg & IXGBE_FACTPS_LFS)
  280. bus->func ^= 0x1;
  281. }
  282. /**
  283. * ixgbe_stop_adapter_generic - Generic stop Tx/Rx units
  284. * @hw: pointer to hardware structure
  285. *
  286. * Sets the adapter_stopped flag within ixgbe_hw struct. Clears interrupts,
  287. * disables transmit and receive units. The adapter_stopped flag is used by
  288. * the shared code and drivers to determine if the adapter is in a stopped
  289. * state and should not touch the hardware.
  290. **/
  291. s32 ixgbe_stop_adapter_generic(struct ixgbe_hw *hw)
  292. {
  293. u32 number_of_queues;
  294. u32 reg_val;
  295. u16 i;
  296. /*
  297. * Set the adapter_stopped flag so other driver functions stop touching
  298. * the hardware
  299. */
  300. hw->adapter_stopped = true;
  301. /* Disable the receive unit */
  302. reg_val = IXGBE_READ_REG(hw, IXGBE_RXCTRL);
  303. reg_val &= ~(IXGBE_RXCTRL_RXEN);
  304. IXGBE_WRITE_REG(hw, IXGBE_RXCTRL, reg_val);
  305. IXGBE_WRITE_FLUSH(hw);
  306. msleep(2);
  307. /* Clear interrupt mask to stop from interrupts being generated */
  308. IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_IRQ_CLEAR_MASK);
  309. /* Clear any pending interrupts */
  310. IXGBE_READ_REG(hw, IXGBE_EICR);
  311. /* Disable the transmit unit. Each queue must be disabled. */
  312. number_of_queues = hw->mac.max_tx_queues;
  313. for (i = 0; i < number_of_queues; i++) {
  314. reg_val = IXGBE_READ_REG(hw, IXGBE_TXDCTL(i));
  315. if (reg_val & IXGBE_TXDCTL_ENABLE) {
  316. reg_val &= ~IXGBE_TXDCTL_ENABLE;
  317. IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(i), reg_val);
  318. }
  319. }
  320. /*
  321. * Prevent the PCI-E bus from from hanging by disabling PCI-E master
  322. * access and verify no pending requests
  323. */
  324. if (ixgbe_disable_pcie_master(hw) != 0)
  325. hw_dbg(hw, "PCI-E Master disable polling has failed.\n");
  326. return 0;
  327. }
  328. /**
  329. * ixgbe_led_on_generic - Turns on the software controllable LEDs.
  330. * @hw: pointer to hardware structure
  331. * @index: led number to turn on
  332. **/
  333. s32 ixgbe_led_on_generic(struct ixgbe_hw *hw, u32 index)
  334. {
  335. u32 led_reg = IXGBE_READ_REG(hw, IXGBE_LEDCTL);
  336. /* To turn on the LED, set mode to ON. */
  337. led_reg &= ~IXGBE_LED_MODE_MASK(index);
  338. led_reg |= IXGBE_LED_ON << IXGBE_LED_MODE_SHIFT(index);
  339. IXGBE_WRITE_REG(hw, IXGBE_LEDCTL, led_reg);
  340. IXGBE_WRITE_FLUSH(hw);
  341. return 0;
  342. }
  343. /**
  344. * ixgbe_led_off_generic - Turns off the software controllable LEDs.
  345. * @hw: pointer to hardware structure
  346. * @index: led number to turn off
  347. **/
  348. s32 ixgbe_led_off_generic(struct ixgbe_hw *hw, u32 index)
  349. {
  350. u32 led_reg = IXGBE_READ_REG(hw, IXGBE_LEDCTL);
  351. /* To turn off the LED, set mode to OFF. */
  352. led_reg &= ~IXGBE_LED_MODE_MASK(index);
  353. led_reg |= IXGBE_LED_OFF << IXGBE_LED_MODE_SHIFT(index);
  354. IXGBE_WRITE_REG(hw, IXGBE_LEDCTL, led_reg);
  355. IXGBE_WRITE_FLUSH(hw);
  356. return 0;
  357. }
  358. /**
  359. * ixgbe_init_eeprom_params_generic - Initialize EEPROM params
  360. * @hw: pointer to hardware structure
  361. *
  362. * Initializes the EEPROM parameters ixgbe_eeprom_info within the
  363. * ixgbe_hw struct in order to set up EEPROM access.
  364. **/
  365. s32 ixgbe_init_eeprom_params_generic(struct ixgbe_hw *hw)
  366. {
  367. struct ixgbe_eeprom_info *eeprom = &hw->eeprom;
  368. u32 eec;
  369. u16 eeprom_size;
  370. if (eeprom->type == ixgbe_eeprom_uninitialized) {
  371. eeprom->type = ixgbe_eeprom_none;
  372. /* Set default semaphore delay to 10ms which is a well
  373. * tested value */
  374. eeprom->semaphore_delay = 10;
  375. /*
  376. * Check for EEPROM present first.
  377. * If not present leave as none
  378. */
  379. eec = IXGBE_READ_REG(hw, IXGBE_EEC);
  380. if (eec & IXGBE_EEC_PRES) {
  381. eeprom->type = ixgbe_eeprom_spi;
  382. /*
  383. * SPI EEPROM is assumed here. This code would need to
  384. * change if a future EEPROM is not SPI.
  385. */
  386. eeprom_size = (u16)((eec & IXGBE_EEC_SIZE) >>
  387. IXGBE_EEC_SIZE_SHIFT);
  388. eeprom->word_size = 1 << (eeprom_size +
  389. IXGBE_EEPROM_WORD_SIZE_SHIFT);
  390. }
  391. if (eec & IXGBE_EEC_ADDR_SIZE)
  392. eeprom->address_bits = 16;
  393. else
  394. eeprom->address_bits = 8;
  395. hw_dbg(hw, "Eeprom params: type = %d, size = %d, address bits: "
  396. "%d\n", eeprom->type, eeprom->word_size,
  397. eeprom->address_bits);
  398. }
  399. return 0;
  400. }
  401. /**
  402. * ixgbe_write_eeprom_generic - Writes 16 bit value to EEPROM
  403. * @hw: pointer to hardware structure
  404. * @offset: offset within the EEPROM to be written to
  405. * @data: 16 bit word to be written to the EEPROM
  406. *
  407. * If ixgbe_eeprom_update_checksum is not called after this function, the
  408. * EEPROM will most likely contain an invalid checksum.
  409. **/
  410. s32 ixgbe_write_eeprom_generic(struct ixgbe_hw *hw, u16 offset, u16 data)
  411. {
  412. s32 status;
  413. u8 write_opcode = IXGBE_EEPROM_WRITE_OPCODE_SPI;
  414. hw->eeprom.ops.init_params(hw);
  415. if (offset >= hw->eeprom.word_size) {
  416. status = IXGBE_ERR_EEPROM;
  417. goto out;
  418. }
  419. /* Prepare the EEPROM for writing */
  420. status = ixgbe_acquire_eeprom(hw);
  421. if (status == 0) {
  422. if (ixgbe_ready_eeprom(hw) != 0) {
  423. ixgbe_release_eeprom(hw);
  424. status = IXGBE_ERR_EEPROM;
  425. }
  426. }
  427. if (status == 0) {
  428. ixgbe_standby_eeprom(hw);
  429. /* Send the WRITE ENABLE command (8 bit opcode ) */
  430. ixgbe_shift_out_eeprom_bits(hw, IXGBE_EEPROM_WREN_OPCODE_SPI,
  431. IXGBE_EEPROM_OPCODE_BITS);
  432. ixgbe_standby_eeprom(hw);
  433. /*
  434. * Some SPI eeproms use the 8th address bit embedded in the
  435. * opcode
  436. */
  437. if ((hw->eeprom.address_bits == 8) && (offset >= 128))
  438. write_opcode |= IXGBE_EEPROM_A8_OPCODE_SPI;
  439. /* Send the Write command (8-bit opcode + addr) */
  440. ixgbe_shift_out_eeprom_bits(hw, write_opcode,
  441. IXGBE_EEPROM_OPCODE_BITS);
  442. ixgbe_shift_out_eeprom_bits(hw, (u16)(offset*2),
  443. hw->eeprom.address_bits);
  444. /* Send the data */
  445. data = (data >> 8) | (data << 8);
  446. ixgbe_shift_out_eeprom_bits(hw, data, 16);
  447. ixgbe_standby_eeprom(hw);
  448. msleep(hw->eeprom.semaphore_delay);
  449. /* Done with writing - release the EEPROM */
  450. ixgbe_release_eeprom(hw);
  451. }
  452. out:
  453. return status;
  454. }
  455. /**
  456. * ixgbe_read_eeprom_bit_bang_generic - Read EEPROM word using bit-bang
  457. * @hw: pointer to hardware structure
  458. * @offset: offset within the EEPROM to be read
  459. * @data: read 16 bit value from EEPROM
  460. *
  461. * Reads 16 bit value from EEPROM through bit-bang method
  462. **/
  463. s32 ixgbe_read_eeprom_bit_bang_generic(struct ixgbe_hw *hw, u16 offset,
  464. u16 *data)
  465. {
  466. s32 status;
  467. u16 word_in;
  468. u8 read_opcode = IXGBE_EEPROM_READ_OPCODE_SPI;
  469. hw->eeprom.ops.init_params(hw);
  470. if (offset >= hw->eeprom.word_size) {
  471. status = IXGBE_ERR_EEPROM;
  472. goto out;
  473. }
  474. /* Prepare the EEPROM for reading */
  475. status = ixgbe_acquire_eeprom(hw);
  476. if (status == 0) {
  477. if (ixgbe_ready_eeprom(hw) != 0) {
  478. ixgbe_release_eeprom(hw);
  479. status = IXGBE_ERR_EEPROM;
  480. }
  481. }
  482. if (status == 0) {
  483. ixgbe_standby_eeprom(hw);
  484. /*
  485. * Some SPI eeproms use the 8th address bit embedded in the
  486. * opcode
  487. */
  488. if ((hw->eeprom.address_bits == 8) && (offset >= 128))
  489. read_opcode |= IXGBE_EEPROM_A8_OPCODE_SPI;
  490. /* Send the READ command (opcode + addr) */
  491. ixgbe_shift_out_eeprom_bits(hw, read_opcode,
  492. IXGBE_EEPROM_OPCODE_BITS);
  493. ixgbe_shift_out_eeprom_bits(hw, (u16)(offset*2),
  494. hw->eeprom.address_bits);
  495. /* Read the data. */
  496. word_in = ixgbe_shift_in_eeprom_bits(hw, 16);
  497. *data = (word_in >> 8) | (word_in << 8);
  498. /* End this read operation */
  499. ixgbe_release_eeprom(hw);
  500. }
  501. out:
  502. return status;
  503. }
  504. /**
  505. * ixgbe_read_eeprom_generic - Read EEPROM word using EERD
  506. * @hw: pointer to hardware structure
  507. * @offset: offset of word in the EEPROM to read
  508. * @data: word read from the EEPROM
  509. *
  510. * Reads a 16 bit word from the EEPROM using the EERD register.
  511. **/
  512. s32 ixgbe_read_eeprom_generic(struct ixgbe_hw *hw, u16 offset, u16 *data)
  513. {
  514. u32 eerd;
  515. s32 status;
  516. hw->eeprom.ops.init_params(hw);
  517. if (offset >= hw->eeprom.word_size) {
  518. status = IXGBE_ERR_EEPROM;
  519. goto out;
  520. }
  521. eerd = (offset << IXGBE_EEPROM_READ_ADDR_SHIFT) +
  522. IXGBE_EEPROM_READ_REG_START;
  523. IXGBE_WRITE_REG(hw, IXGBE_EERD, eerd);
  524. status = ixgbe_poll_eeprom_eerd_done(hw);
  525. if (status == 0)
  526. *data = (IXGBE_READ_REG(hw, IXGBE_EERD) >>
  527. IXGBE_EEPROM_READ_REG_DATA);
  528. else
  529. hw_dbg(hw, "Eeprom read timed out\n");
  530. out:
  531. return status;
  532. }
  533. /**
  534. * ixgbe_poll_eeprom_eerd_done - Poll EERD status
  535. * @hw: pointer to hardware structure
  536. *
  537. * Polls the status bit (bit 1) of the EERD to determine when the read is done.
  538. **/
  539. static s32 ixgbe_poll_eeprom_eerd_done(struct ixgbe_hw *hw)
  540. {
  541. u32 i;
  542. u32 reg;
  543. s32 status = IXGBE_ERR_EEPROM;
  544. for (i = 0; i < IXGBE_EERD_ATTEMPTS; i++) {
  545. reg = IXGBE_READ_REG(hw, IXGBE_EERD);
  546. if (reg & IXGBE_EEPROM_READ_REG_DONE) {
  547. status = 0;
  548. break;
  549. }
  550. udelay(5);
  551. }
  552. return status;
  553. }
  554. /**
  555. * ixgbe_acquire_eeprom - Acquire EEPROM using bit-bang
  556. * @hw: pointer to hardware structure
  557. *
  558. * Prepares EEPROM for access using bit-bang method. This function should
  559. * be called before issuing a command to the EEPROM.
  560. **/
  561. static s32 ixgbe_acquire_eeprom(struct ixgbe_hw *hw)
  562. {
  563. s32 status = 0;
  564. u32 eec = 0;
  565. u32 i;
  566. if (ixgbe_acquire_swfw_sync(hw, IXGBE_GSSR_EEP_SM) != 0)
  567. status = IXGBE_ERR_SWFW_SYNC;
  568. if (status == 0) {
  569. eec = IXGBE_READ_REG(hw, IXGBE_EEC);
  570. /* Request EEPROM Access */
  571. eec |= IXGBE_EEC_REQ;
  572. IXGBE_WRITE_REG(hw, IXGBE_EEC, eec);
  573. for (i = 0; i < IXGBE_EEPROM_GRANT_ATTEMPTS; i++) {
  574. eec = IXGBE_READ_REG(hw, IXGBE_EEC);
  575. if (eec & IXGBE_EEC_GNT)
  576. break;
  577. udelay(5);
  578. }
  579. /* Release if grant not acquired */
  580. if (!(eec & IXGBE_EEC_GNT)) {
  581. eec &= ~IXGBE_EEC_REQ;
  582. IXGBE_WRITE_REG(hw, IXGBE_EEC, eec);
  583. hw_dbg(hw, "Could not acquire EEPROM grant\n");
  584. ixgbe_release_swfw_sync(hw, IXGBE_GSSR_EEP_SM);
  585. status = IXGBE_ERR_EEPROM;
  586. }
  587. }
  588. /* Setup EEPROM for Read/Write */
  589. if (status == 0) {
  590. /* Clear CS and SK */
  591. eec &= ~(IXGBE_EEC_CS | IXGBE_EEC_SK);
  592. IXGBE_WRITE_REG(hw, IXGBE_EEC, eec);
  593. IXGBE_WRITE_FLUSH(hw);
  594. udelay(1);
  595. }
  596. return status;
  597. }
  598. /**
  599. * ixgbe_get_eeprom_semaphore - Get hardware semaphore
  600. * @hw: pointer to hardware structure
  601. *
  602. * Sets the hardware semaphores so EEPROM access can occur for bit-bang method
  603. **/
  604. static s32 ixgbe_get_eeprom_semaphore(struct ixgbe_hw *hw)
  605. {
  606. s32 status = IXGBE_ERR_EEPROM;
  607. u32 timeout;
  608. u32 i;
  609. u32 swsm;
  610. /* Set timeout value based on size of EEPROM */
  611. timeout = hw->eeprom.word_size + 1;
  612. /* Get SMBI software semaphore between device drivers first */
  613. for (i = 0; i < timeout; i++) {
  614. /*
  615. * If the SMBI bit is 0 when we read it, then the bit will be
  616. * set and we have the semaphore
  617. */
  618. swsm = IXGBE_READ_REG(hw, IXGBE_SWSM);
  619. if (!(swsm & IXGBE_SWSM_SMBI)) {
  620. status = 0;
  621. break;
  622. }
  623. msleep(1);
  624. }
  625. /* Now get the semaphore between SW/FW through the SWESMBI bit */
  626. if (status == 0) {
  627. for (i = 0; i < timeout; i++) {
  628. swsm = IXGBE_READ_REG(hw, IXGBE_SWSM);
  629. /* Set the SW EEPROM semaphore bit to request access */
  630. swsm |= IXGBE_SWSM_SWESMBI;
  631. IXGBE_WRITE_REG(hw, IXGBE_SWSM, swsm);
  632. /*
  633. * If we set the bit successfully then we got the
  634. * semaphore.
  635. */
  636. swsm = IXGBE_READ_REG(hw, IXGBE_SWSM);
  637. if (swsm & IXGBE_SWSM_SWESMBI)
  638. break;
  639. udelay(50);
  640. }
  641. /*
  642. * Release semaphores and return error if SW EEPROM semaphore
  643. * was not granted because we don't have access to the EEPROM
  644. */
  645. if (i >= timeout) {
  646. hw_dbg(hw, "Driver can't access the Eeprom - Semaphore "
  647. "not granted.\n");
  648. ixgbe_release_eeprom_semaphore(hw);
  649. status = IXGBE_ERR_EEPROM;
  650. }
  651. }
  652. return status;
  653. }
  654. /**
  655. * ixgbe_release_eeprom_semaphore - Release hardware semaphore
  656. * @hw: pointer to hardware structure
  657. *
  658. * This function clears hardware semaphore bits.
  659. **/
  660. static void ixgbe_release_eeprom_semaphore(struct ixgbe_hw *hw)
  661. {
  662. u32 swsm;
  663. swsm = IXGBE_READ_REG(hw, IXGBE_SWSM);
  664. /* Release both semaphores by writing 0 to the bits SWESMBI and SMBI */
  665. swsm &= ~(IXGBE_SWSM_SWESMBI | IXGBE_SWSM_SMBI);
  666. IXGBE_WRITE_REG(hw, IXGBE_SWSM, swsm);
  667. IXGBE_WRITE_FLUSH(hw);
  668. }
  669. /**
  670. * ixgbe_ready_eeprom - Polls for EEPROM ready
  671. * @hw: pointer to hardware structure
  672. **/
  673. static s32 ixgbe_ready_eeprom(struct ixgbe_hw *hw)
  674. {
  675. s32 status = 0;
  676. u16 i;
  677. u8 spi_stat_reg;
  678. /*
  679. * Read "Status Register" repeatedly until the LSB is cleared. The
  680. * EEPROM will signal that the command has been completed by clearing
  681. * bit 0 of the internal status register. If it's not cleared within
  682. * 5 milliseconds, then error out.
  683. */
  684. for (i = 0; i < IXGBE_EEPROM_MAX_RETRY_SPI; i += 5) {
  685. ixgbe_shift_out_eeprom_bits(hw, IXGBE_EEPROM_RDSR_OPCODE_SPI,
  686. IXGBE_EEPROM_OPCODE_BITS);
  687. spi_stat_reg = (u8)ixgbe_shift_in_eeprom_bits(hw, 8);
  688. if (!(spi_stat_reg & IXGBE_EEPROM_STATUS_RDY_SPI))
  689. break;
  690. udelay(5);
  691. ixgbe_standby_eeprom(hw);
  692. };
  693. /*
  694. * On some parts, SPI write time could vary from 0-20mSec on 3.3V
  695. * devices (and only 0-5mSec on 5V devices)
  696. */
  697. if (i >= IXGBE_EEPROM_MAX_RETRY_SPI) {
  698. hw_dbg(hw, "SPI EEPROM Status error\n");
  699. status = IXGBE_ERR_EEPROM;
  700. }
  701. return status;
  702. }
  703. /**
  704. * ixgbe_standby_eeprom - Returns EEPROM to a "standby" state
  705. * @hw: pointer to hardware structure
  706. **/
  707. static void ixgbe_standby_eeprom(struct ixgbe_hw *hw)
  708. {
  709. u32 eec;
  710. eec = IXGBE_READ_REG(hw, IXGBE_EEC);
  711. /* Toggle CS to flush commands */
  712. eec |= IXGBE_EEC_CS;
  713. IXGBE_WRITE_REG(hw, IXGBE_EEC, eec);
  714. IXGBE_WRITE_FLUSH(hw);
  715. udelay(1);
  716. eec &= ~IXGBE_EEC_CS;
  717. IXGBE_WRITE_REG(hw, IXGBE_EEC, eec);
  718. IXGBE_WRITE_FLUSH(hw);
  719. udelay(1);
  720. }
  721. /**
  722. * ixgbe_shift_out_eeprom_bits - Shift data bits out to the EEPROM.
  723. * @hw: pointer to hardware structure
  724. * @data: data to send to the EEPROM
  725. * @count: number of bits to shift out
  726. **/
  727. static void ixgbe_shift_out_eeprom_bits(struct ixgbe_hw *hw, u16 data,
  728. u16 count)
  729. {
  730. u32 eec;
  731. u32 mask;
  732. u32 i;
  733. eec = IXGBE_READ_REG(hw, IXGBE_EEC);
  734. /*
  735. * Mask is used to shift "count" bits of "data" out to the EEPROM
  736. * one bit at a time. Determine the starting bit based on count
  737. */
  738. mask = 0x01 << (count - 1);
  739. for (i = 0; i < count; i++) {
  740. /*
  741. * A "1" is shifted out to the EEPROM by setting bit "DI" to a
  742. * "1", and then raising and then lowering the clock (the SK
  743. * bit controls the clock input to the EEPROM). A "0" is
  744. * shifted out to the EEPROM by setting "DI" to "0" and then
  745. * raising and then lowering the clock.
  746. */
  747. if (data & mask)
  748. eec |= IXGBE_EEC_DI;
  749. else
  750. eec &= ~IXGBE_EEC_DI;
  751. IXGBE_WRITE_REG(hw, IXGBE_EEC, eec);
  752. IXGBE_WRITE_FLUSH(hw);
  753. udelay(1);
  754. ixgbe_raise_eeprom_clk(hw, &eec);
  755. ixgbe_lower_eeprom_clk(hw, &eec);
  756. /*
  757. * Shift mask to signify next bit of data to shift in to the
  758. * EEPROM
  759. */
  760. mask = mask >> 1;
  761. };
  762. /* We leave the "DI" bit set to "0" when we leave this routine. */
  763. eec &= ~IXGBE_EEC_DI;
  764. IXGBE_WRITE_REG(hw, IXGBE_EEC, eec);
  765. IXGBE_WRITE_FLUSH(hw);
  766. }
  767. /**
  768. * ixgbe_shift_in_eeprom_bits - Shift data bits in from the EEPROM
  769. * @hw: pointer to hardware structure
  770. **/
  771. static u16 ixgbe_shift_in_eeprom_bits(struct ixgbe_hw *hw, u16 count)
  772. {
  773. u32 eec;
  774. u32 i;
  775. u16 data = 0;
  776. /*
  777. * In order to read a register from the EEPROM, we need to shift
  778. * 'count' bits in from the EEPROM. Bits are "shifted in" by raising
  779. * the clock input to the EEPROM (setting the SK bit), and then reading
  780. * the value of the "DO" bit. During this "shifting in" process the
  781. * "DI" bit should always be clear.
  782. */
  783. eec = IXGBE_READ_REG(hw, IXGBE_EEC);
  784. eec &= ~(IXGBE_EEC_DO | IXGBE_EEC_DI);
  785. for (i = 0; i < count; i++) {
  786. data = data << 1;
  787. ixgbe_raise_eeprom_clk(hw, &eec);
  788. eec = IXGBE_READ_REG(hw, IXGBE_EEC);
  789. eec &= ~(IXGBE_EEC_DI);
  790. if (eec & IXGBE_EEC_DO)
  791. data |= 1;
  792. ixgbe_lower_eeprom_clk(hw, &eec);
  793. }
  794. return data;
  795. }
  796. /**
  797. * ixgbe_raise_eeprom_clk - Raises the EEPROM's clock input.
  798. * @hw: pointer to hardware structure
  799. * @eec: EEC register's current value
  800. **/
  801. static void ixgbe_raise_eeprom_clk(struct ixgbe_hw *hw, u32 *eec)
  802. {
  803. /*
  804. * Raise the clock input to the EEPROM
  805. * (setting the SK bit), then delay
  806. */
  807. *eec = *eec | IXGBE_EEC_SK;
  808. IXGBE_WRITE_REG(hw, IXGBE_EEC, *eec);
  809. IXGBE_WRITE_FLUSH(hw);
  810. udelay(1);
  811. }
  812. /**
  813. * ixgbe_lower_eeprom_clk - Lowers the EEPROM's clock input.
  814. * @hw: pointer to hardware structure
  815. * @eecd: EECD's current value
  816. **/
  817. static void ixgbe_lower_eeprom_clk(struct ixgbe_hw *hw, u32 *eec)
  818. {
  819. /*
  820. * Lower the clock input to the EEPROM (clearing the SK bit), then
  821. * delay
  822. */
  823. *eec = *eec & ~IXGBE_EEC_SK;
  824. IXGBE_WRITE_REG(hw, IXGBE_EEC, *eec);
  825. IXGBE_WRITE_FLUSH(hw);
  826. udelay(1);
  827. }
  828. /**
  829. * ixgbe_release_eeprom - Release EEPROM, release semaphores
  830. * @hw: pointer to hardware structure
  831. **/
  832. static void ixgbe_release_eeprom(struct ixgbe_hw *hw)
  833. {
  834. u32 eec;
  835. eec = IXGBE_READ_REG(hw, IXGBE_EEC);
  836. eec |= IXGBE_EEC_CS; /* Pull CS high */
  837. eec &= ~IXGBE_EEC_SK; /* Lower SCK */
  838. IXGBE_WRITE_REG(hw, IXGBE_EEC, eec);
  839. IXGBE_WRITE_FLUSH(hw);
  840. udelay(1);
  841. /* Stop requesting EEPROM access */
  842. eec &= ~IXGBE_EEC_REQ;
  843. IXGBE_WRITE_REG(hw, IXGBE_EEC, eec);
  844. ixgbe_release_swfw_sync(hw, IXGBE_GSSR_EEP_SM);
  845. }
  846. /**
  847. * ixgbe_calc_eeprom_checksum - Calculates and returns the checksum
  848. * @hw: pointer to hardware structure
  849. **/
  850. static u16 ixgbe_calc_eeprom_checksum(struct ixgbe_hw *hw)
  851. {
  852. u16 i;
  853. u16 j;
  854. u16 checksum = 0;
  855. u16 length = 0;
  856. u16 pointer = 0;
  857. u16 word = 0;
  858. /* Include 0x0-0x3F in the checksum */
  859. for (i = 0; i < IXGBE_EEPROM_CHECKSUM; i++) {
  860. if (hw->eeprom.ops.read(hw, i, &word) != 0) {
  861. hw_dbg(hw, "EEPROM read failed\n");
  862. break;
  863. }
  864. checksum += word;
  865. }
  866. /* Include all data from pointers except for the fw pointer */
  867. for (i = IXGBE_PCIE_ANALOG_PTR; i < IXGBE_FW_PTR; i++) {
  868. hw->eeprom.ops.read(hw, i, &pointer);
  869. /* Make sure the pointer seems valid */
  870. if (pointer != 0xFFFF && pointer != 0) {
  871. hw->eeprom.ops.read(hw, pointer, &length);
  872. if (length != 0xFFFF && length != 0) {
  873. for (j = pointer+1; j <= pointer+length; j++) {
  874. hw->eeprom.ops.read(hw, j, &word);
  875. checksum += word;
  876. }
  877. }
  878. }
  879. }
  880. checksum = (u16)IXGBE_EEPROM_SUM - checksum;
  881. return checksum;
  882. }
  883. /**
  884. * ixgbe_validate_eeprom_checksum_generic - Validate EEPROM checksum
  885. * @hw: pointer to hardware structure
  886. * @checksum_val: calculated checksum
  887. *
  888. * Performs checksum calculation and validates the EEPROM checksum. If the
  889. * caller does not need checksum_val, the value can be NULL.
  890. **/
  891. s32 ixgbe_validate_eeprom_checksum_generic(struct ixgbe_hw *hw,
  892. u16 *checksum_val)
  893. {
  894. s32 status;
  895. u16 checksum;
  896. u16 read_checksum = 0;
  897. /*
  898. * Read the first word from the EEPROM. If this times out or fails, do
  899. * not continue or we could be in for a very long wait while every
  900. * EEPROM read fails
  901. */
  902. status = hw->eeprom.ops.read(hw, 0, &checksum);
  903. if (status == 0) {
  904. checksum = ixgbe_calc_eeprom_checksum(hw);
  905. hw->eeprom.ops.read(hw, IXGBE_EEPROM_CHECKSUM, &read_checksum);
  906. /*
  907. * Verify read checksum from EEPROM is the same as
  908. * calculated checksum
  909. */
  910. if (read_checksum != checksum)
  911. status = IXGBE_ERR_EEPROM_CHECKSUM;
  912. /* If the user cares, return the calculated checksum */
  913. if (checksum_val)
  914. *checksum_val = checksum;
  915. } else {
  916. hw_dbg(hw, "EEPROM read failed\n");
  917. }
  918. return status;
  919. }
  920. /**
  921. * ixgbe_update_eeprom_checksum_generic - Updates the EEPROM checksum
  922. * @hw: pointer to hardware structure
  923. **/
  924. s32 ixgbe_update_eeprom_checksum_generic(struct ixgbe_hw *hw)
  925. {
  926. s32 status;
  927. u16 checksum;
  928. /*
  929. * Read the first word from the EEPROM. If this times out or fails, do
  930. * not continue or we could be in for a very long wait while every
  931. * EEPROM read fails
  932. */
  933. status = hw->eeprom.ops.read(hw, 0, &checksum);
  934. if (status == 0) {
  935. checksum = ixgbe_calc_eeprom_checksum(hw);
  936. status = hw->eeprom.ops.write(hw, IXGBE_EEPROM_CHECKSUM,
  937. checksum);
  938. } else {
  939. hw_dbg(hw, "EEPROM read failed\n");
  940. }
  941. return status;
  942. }
  943. /**
  944. * ixgbe_validate_mac_addr - Validate MAC address
  945. * @mac_addr: pointer to MAC address.
  946. *
  947. * Tests a MAC address to ensure it is a valid Individual Address
  948. **/
  949. s32 ixgbe_validate_mac_addr(u8 *mac_addr)
  950. {
  951. s32 status = 0;
  952. /* Make sure it is not a multicast address */
  953. if (IXGBE_IS_MULTICAST(mac_addr))
  954. status = IXGBE_ERR_INVALID_MAC_ADDR;
  955. /* Not a broadcast address */
  956. else if (IXGBE_IS_BROADCAST(mac_addr))
  957. status = IXGBE_ERR_INVALID_MAC_ADDR;
  958. /* Reject the zero address */
  959. else if (mac_addr[0] == 0 && mac_addr[1] == 0 && mac_addr[2] == 0 &&
  960. mac_addr[3] == 0 && mac_addr[4] == 0 && mac_addr[5] == 0)
  961. status = IXGBE_ERR_INVALID_MAC_ADDR;
  962. return status;
  963. }
  964. /**
  965. * ixgbe_set_rar_generic - Set Rx address register
  966. * @hw: pointer to hardware structure
  967. * @index: Receive address register to write
  968. * @addr: Address to put into receive address register
  969. * @vmdq: VMDq "set" or "pool" index
  970. * @enable_addr: set flag that address is active
  971. *
  972. * Puts an ethernet address into a receive address register.
  973. **/
  974. s32 ixgbe_set_rar_generic(struct ixgbe_hw *hw, u32 index, u8 *addr, u32 vmdq,
  975. u32 enable_addr)
  976. {
  977. u32 rar_low, rar_high;
  978. u32 rar_entries = hw->mac.num_rar_entries;
  979. /* setup VMDq pool selection before this RAR gets enabled */
  980. hw->mac.ops.set_vmdq(hw, index, vmdq);
  981. /* Make sure we are using a valid rar index range */
  982. if (index < rar_entries) {
  983. /*
  984. * HW expects these in little endian so we reverse the byte
  985. * order from network order (big endian) to little endian
  986. */
  987. rar_low = ((u32)addr[0] |
  988. ((u32)addr[1] << 8) |
  989. ((u32)addr[2] << 16) |
  990. ((u32)addr[3] << 24));
  991. /*
  992. * Some parts put the VMDq setting in the extra RAH bits,
  993. * so save everything except the lower 16 bits that hold part
  994. * of the address and the address valid bit.
  995. */
  996. rar_high = IXGBE_READ_REG(hw, IXGBE_RAH(index));
  997. rar_high &= ~(0x0000FFFF | IXGBE_RAH_AV);
  998. rar_high |= ((u32)addr[4] | ((u32)addr[5] << 8));
  999. if (enable_addr != 0)
  1000. rar_high |= IXGBE_RAH_AV;
  1001. IXGBE_WRITE_REG(hw, IXGBE_RAL(index), rar_low);
  1002. IXGBE_WRITE_REG(hw, IXGBE_RAH(index), rar_high);
  1003. } else {
  1004. hw_dbg(hw, "RAR index %d is out of range.\n", index);
  1005. }
  1006. return 0;
  1007. }
  1008. /**
  1009. * ixgbe_clear_rar_generic - Remove Rx address register
  1010. * @hw: pointer to hardware structure
  1011. * @index: Receive address register to write
  1012. *
  1013. * Clears an ethernet address from a receive address register.
  1014. **/
  1015. s32 ixgbe_clear_rar_generic(struct ixgbe_hw *hw, u32 index)
  1016. {
  1017. u32 rar_high;
  1018. u32 rar_entries = hw->mac.num_rar_entries;
  1019. /* Make sure we are using a valid rar index range */
  1020. if (index < rar_entries) {
  1021. /*
  1022. * Some parts put the VMDq setting in the extra RAH bits,
  1023. * so save everything except the lower 16 bits that hold part
  1024. * of the address and the address valid bit.
  1025. */
  1026. rar_high = IXGBE_READ_REG(hw, IXGBE_RAH(index));
  1027. rar_high &= ~(0x0000FFFF | IXGBE_RAH_AV);
  1028. IXGBE_WRITE_REG(hw, IXGBE_RAL(index), 0);
  1029. IXGBE_WRITE_REG(hw, IXGBE_RAH(index), rar_high);
  1030. } else {
  1031. hw_dbg(hw, "RAR index %d is out of range.\n", index);
  1032. }
  1033. /* clear VMDq pool/queue selection for this RAR */
  1034. hw->mac.ops.clear_vmdq(hw, index, IXGBE_CLEAR_VMDQ_ALL);
  1035. return 0;
  1036. }
  1037. /**
  1038. * ixgbe_enable_rar - Enable Rx address register
  1039. * @hw: pointer to hardware structure
  1040. * @index: index into the RAR table
  1041. *
  1042. * Enables the select receive address register.
  1043. **/
  1044. static void ixgbe_enable_rar(struct ixgbe_hw *hw, u32 index)
  1045. {
  1046. u32 rar_high;
  1047. rar_high = IXGBE_READ_REG(hw, IXGBE_RAH(index));
  1048. rar_high |= IXGBE_RAH_AV;
  1049. IXGBE_WRITE_REG(hw, IXGBE_RAH(index), rar_high);
  1050. }
  1051. /**
  1052. * ixgbe_disable_rar - Disable Rx address register
  1053. * @hw: pointer to hardware structure
  1054. * @index: index into the RAR table
  1055. *
  1056. * Disables the select receive address register.
  1057. **/
  1058. static void ixgbe_disable_rar(struct ixgbe_hw *hw, u32 index)
  1059. {
  1060. u32 rar_high;
  1061. rar_high = IXGBE_READ_REG(hw, IXGBE_RAH(index));
  1062. rar_high &= (~IXGBE_RAH_AV);
  1063. IXGBE_WRITE_REG(hw, IXGBE_RAH(index), rar_high);
  1064. }
  1065. /**
  1066. * ixgbe_init_rx_addrs_generic - Initializes receive address filters.
  1067. * @hw: pointer to hardware structure
  1068. *
  1069. * Places the MAC address in receive address register 0 and clears the rest
  1070. * of the receive address registers. Clears the multicast table. Assumes
  1071. * the receiver is in reset when the routine is called.
  1072. **/
  1073. s32 ixgbe_init_rx_addrs_generic(struct ixgbe_hw *hw)
  1074. {
  1075. u32 i;
  1076. u32 rar_entries = hw->mac.num_rar_entries;
  1077. /*
  1078. * If the current mac address is valid, assume it is a software override
  1079. * to the permanent address.
  1080. * Otherwise, use the permanent address from the eeprom.
  1081. */
  1082. if (ixgbe_validate_mac_addr(hw->mac.addr) ==
  1083. IXGBE_ERR_INVALID_MAC_ADDR) {
  1084. /* Get the MAC address from the RAR0 for later reference */
  1085. hw->mac.ops.get_mac_addr(hw, hw->mac.addr);
  1086. hw_dbg(hw, " Keeping Current RAR0 Addr =%.2X %.2X %.2X ",
  1087. hw->mac.addr[0], hw->mac.addr[1],
  1088. hw->mac.addr[2]);
  1089. hw_dbg(hw, "%.2X %.2X %.2X\n", hw->mac.addr[3],
  1090. hw->mac.addr[4], hw->mac.addr[5]);
  1091. } else {
  1092. /* Setup the receive address. */
  1093. hw_dbg(hw, "Overriding MAC Address in RAR[0]\n");
  1094. hw_dbg(hw, " New MAC Addr =%.2X %.2X %.2X ",
  1095. hw->mac.addr[0], hw->mac.addr[1],
  1096. hw->mac.addr[2]);
  1097. hw_dbg(hw, "%.2X %.2X %.2X\n", hw->mac.addr[3],
  1098. hw->mac.addr[4], hw->mac.addr[5]);
  1099. hw->mac.ops.set_rar(hw, 0, hw->mac.addr, 0, IXGBE_RAH_AV);
  1100. }
  1101. hw->addr_ctrl.overflow_promisc = 0;
  1102. hw->addr_ctrl.rar_used_count = 1;
  1103. /* Zero out the other receive addresses. */
  1104. hw_dbg(hw, "Clearing RAR[1-%d]\n", rar_entries - 1);
  1105. for (i = 1; i < rar_entries; i++) {
  1106. IXGBE_WRITE_REG(hw, IXGBE_RAL(i), 0);
  1107. IXGBE_WRITE_REG(hw, IXGBE_RAH(i), 0);
  1108. }
  1109. /* Clear the MTA */
  1110. hw->addr_ctrl.mc_addr_in_rar_count = 0;
  1111. hw->addr_ctrl.mta_in_use = 0;
  1112. IXGBE_WRITE_REG(hw, IXGBE_MCSTCTRL, hw->mac.mc_filter_type);
  1113. hw_dbg(hw, " Clearing MTA\n");
  1114. for (i = 0; i < hw->mac.mcft_size; i++)
  1115. IXGBE_WRITE_REG(hw, IXGBE_MTA(i), 0);
  1116. if (hw->mac.ops.init_uta_tables)
  1117. hw->mac.ops.init_uta_tables(hw);
  1118. return 0;
  1119. }
  1120. /**
  1121. * ixgbe_add_uc_addr - Adds a secondary unicast address.
  1122. * @hw: pointer to hardware structure
  1123. * @addr: new address
  1124. *
  1125. * Adds it to unused receive address register or goes into promiscuous mode.
  1126. **/
  1127. static void ixgbe_add_uc_addr(struct ixgbe_hw *hw, u8 *addr, u32 vmdq)
  1128. {
  1129. u32 rar_entries = hw->mac.num_rar_entries;
  1130. u32 rar;
  1131. hw_dbg(hw, " UC Addr = %.2X %.2X %.2X %.2X %.2X %.2X\n",
  1132. addr[0], addr[1], addr[2], addr[3], addr[4], addr[5]);
  1133. /*
  1134. * Place this address in the RAR if there is room,
  1135. * else put the controller into promiscuous mode
  1136. */
  1137. if (hw->addr_ctrl.rar_used_count < rar_entries) {
  1138. rar = hw->addr_ctrl.rar_used_count -
  1139. hw->addr_ctrl.mc_addr_in_rar_count;
  1140. hw->mac.ops.set_rar(hw, rar, addr, vmdq, IXGBE_RAH_AV);
  1141. hw_dbg(hw, "Added a secondary address to RAR[%d]\n", rar);
  1142. hw->addr_ctrl.rar_used_count++;
  1143. } else {
  1144. hw->addr_ctrl.overflow_promisc++;
  1145. }
  1146. hw_dbg(hw, "ixgbe_add_uc_addr Complete\n");
  1147. }
  1148. /**
  1149. * ixgbe_update_uc_addr_list_generic - Updates MAC list of secondary addresses
  1150. * @hw: pointer to hardware structure
  1151. * @uc_list: the list of new addresses
  1152. *
  1153. * The given list replaces any existing list. Clears the secondary addrs from
  1154. * receive address registers. Uses unused receive address registers for the
  1155. * first secondary addresses, and falls back to promiscuous mode as needed.
  1156. *
  1157. * Drivers using secondary unicast addresses must set user_set_promisc when
  1158. * manually putting the device into promiscuous mode.
  1159. **/
  1160. s32 ixgbe_update_uc_addr_list_generic(struct ixgbe_hw *hw,
  1161. struct list_head *uc_list)
  1162. {
  1163. u32 i;
  1164. u32 old_promisc_setting = hw->addr_ctrl.overflow_promisc;
  1165. u32 uc_addr_in_use;
  1166. u32 fctrl;
  1167. struct netdev_hw_addr *ha;
  1168. /*
  1169. * Clear accounting of old secondary address list,
  1170. * don't count RAR[0]
  1171. */
  1172. uc_addr_in_use = hw->addr_ctrl.rar_used_count - 1;
  1173. hw->addr_ctrl.rar_used_count -= uc_addr_in_use;
  1174. hw->addr_ctrl.overflow_promisc = 0;
  1175. /* Zero out the other receive addresses */
  1176. hw_dbg(hw, "Clearing RAR[1-%d]\n", uc_addr_in_use);
  1177. for (i = 1; i <= uc_addr_in_use; i++) {
  1178. IXGBE_WRITE_REG(hw, IXGBE_RAL(i), 0);
  1179. IXGBE_WRITE_REG(hw, IXGBE_RAH(i), 0);
  1180. }
  1181. /* Add the new addresses */
  1182. list_for_each_entry(ha, uc_list, list) {
  1183. hw_dbg(hw, " Adding the secondary addresses:\n");
  1184. ixgbe_add_uc_addr(hw, ha->addr, 0);
  1185. }
  1186. if (hw->addr_ctrl.overflow_promisc) {
  1187. /* enable promisc if not already in overflow or set by user */
  1188. if (!old_promisc_setting && !hw->addr_ctrl.user_set_promisc) {
  1189. hw_dbg(hw, " Entering address overflow promisc mode\n");
  1190. fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
  1191. fctrl |= IXGBE_FCTRL_UPE;
  1192. IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl);
  1193. }
  1194. } else {
  1195. /* only disable if set by overflow, not by user */
  1196. if (old_promisc_setting && !hw->addr_ctrl.user_set_promisc) {
  1197. hw_dbg(hw, " Leaving address overflow promisc mode\n");
  1198. fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
  1199. fctrl &= ~IXGBE_FCTRL_UPE;
  1200. IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl);
  1201. }
  1202. }
  1203. hw_dbg(hw, "ixgbe_update_uc_addr_list_generic Complete\n");
  1204. return 0;
  1205. }
  1206. /**
  1207. * ixgbe_mta_vector - Determines bit-vector in multicast table to set
  1208. * @hw: pointer to hardware structure
  1209. * @mc_addr: the multicast address
  1210. *
  1211. * Extracts the 12 bits, from a multicast address, to determine which
  1212. * bit-vector to set in the multicast table. The hardware uses 12 bits, from
  1213. * incoming rx multicast addresses, to determine the bit-vector to check in
  1214. * the MTA. Which of the 4 combination, of 12-bits, the hardware uses is set
  1215. * by the MO field of the MCSTCTRL. The MO field is set during initialization
  1216. * to mc_filter_type.
  1217. **/
  1218. static s32 ixgbe_mta_vector(struct ixgbe_hw *hw, u8 *mc_addr)
  1219. {
  1220. u32 vector = 0;
  1221. switch (hw->mac.mc_filter_type) {
  1222. case 0: /* use bits [47:36] of the address */
  1223. vector = ((mc_addr[4] >> 4) | (((u16)mc_addr[5]) << 4));
  1224. break;
  1225. case 1: /* use bits [46:35] of the address */
  1226. vector = ((mc_addr[4] >> 3) | (((u16)mc_addr[5]) << 5));
  1227. break;
  1228. case 2: /* use bits [45:34] of the address */
  1229. vector = ((mc_addr[4] >> 2) | (((u16)mc_addr[5]) << 6));
  1230. break;
  1231. case 3: /* use bits [43:32] of the address */
  1232. vector = ((mc_addr[4]) | (((u16)mc_addr[5]) << 8));
  1233. break;
  1234. default: /* Invalid mc_filter_type */
  1235. hw_dbg(hw, "MC filter type param set incorrectly\n");
  1236. break;
  1237. }
  1238. /* vector can only be 12-bits or boundary will be exceeded */
  1239. vector &= 0xFFF;
  1240. return vector;
  1241. }
  1242. /**
  1243. * ixgbe_set_mta - Set bit-vector in multicast table
  1244. * @hw: pointer to hardware structure
  1245. * @hash_value: Multicast address hash value
  1246. *
  1247. * Sets the bit-vector in the multicast table.
  1248. **/
  1249. static void ixgbe_set_mta(struct ixgbe_hw *hw, u8 *mc_addr)
  1250. {
  1251. u32 vector;
  1252. u32 vector_bit;
  1253. u32 vector_reg;
  1254. u32 mta_reg;
  1255. hw->addr_ctrl.mta_in_use++;
  1256. vector = ixgbe_mta_vector(hw, mc_addr);
  1257. hw_dbg(hw, " bit-vector = 0x%03X\n", vector);
  1258. /*
  1259. * The MTA is a register array of 128 32-bit registers. It is treated
  1260. * like an array of 4096 bits. We want to set bit
  1261. * BitArray[vector_value]. So we figure out what register the bit is
  1262. * in, read it, OR in the new bit, then write back the new value. The
  1263. * register is determined by the upper 7 bits of the vector value and
  1264. * the bit within that register are determined by the lower 5 bits of
  1265. * the value.
  1266. */
  1267. vector_reg = (vector >> 5) & 0x7F;
  1268. vector_bit = vector & 0x1F;
  1269. mta_reg = IXGBE_READ_REG(hw, IXGBE_MTA(vector_reg));
  1270. mta_reg |= (1 << vector_bit);
  1271. IXGBE_WRITE_REG(hw, IXGBE_MTA(vector_reg), mta_reg);
  1272. }
  1273. /**
  1274. * ixgbe_update_mc_addr_list_generic - Updates MAC list of multicast addresses
  1275. * @hw: pointer to hardware structure
  1276. * @mc_addr_list: the list of new multicast addresses
  1277. * @mc_addr_count: number of addresses
  1278. * @next: iterator function to walk the multicast address list
  1279. *
  1280. * The given list replaces any existing list. Clears the MC addrs from receive
  1281. * address registers and the multicast table. Uses unused receive address
  1282. * registers for the first multicast addresses, and hashes the rest into the
  1283. * multicast table.
  1284. **/
  1285. s32 ixgbe_update_mc_addr_list_generic(struct ixgbe_hw *hw, u8 *mc_addr_list,
  1286. u32 mc_addr_count, ixgbe_mc_addr_itr next)
  1287. {
  1288. u32 i;
  1289. u32 vmdq;
  1290. /*
  1291. * Set the new number of MC addresses that we are being requested to
  1292. * use.
  1293. */
  1294. hw->addr_ctrl.num_mc_addrs = mc_addr_count;
  1295. hw->addr_ctrl.mta_in_use = 0;
  1296. /* Clear the MTA */
  1297. hw_dbg(hw, " Clearing MTA\n");
  1298. for (i = 0; i < hw->mac.mcft_size; i++)
  1299. IXGBE_WRITE_REG(hw, IXGBE_MTA(i), 0);
  1300. /* Add the new addresses */
  1301. for (i = 0; i < mc_addr_count; i++) {
  1302. hw_dbg(hw, " Adding the multicast addresses:\n");
  1303. ixgbe_set_mta(hw, next(hw, &mc_addr_list, &vmdq));
  1304. }
  1305. /* Enable mta */
  1306. if (hw->addr_ctrl.mta_in_use > 0)
  1307. IXGBE_WRITE_REG(hw, IXGBE_MCSTCTRL,
  1308. IXGBE_MCSTCTRL_MFE | hw->mac.mc_filter_type);
  1309. hw_dbg(hw, "ixgbe_update_mc_addr_list_generic Complete\n");
  1310. return 0;
  1311. }
  1312. /**
  1313. * ixgbe_enable_mc_generic - Enable multicast address in RAR
  1314. * @hw: pointer to hardware structure
  1315. *
  1316. * Enables multicast address in RAR and the use of the multicast hash table.
  1317. **/
  1318. s32 ixgbe_enable_mc_generic(struct ixgbe_hw *hw)
  1319. {
  1320. u32 i;
  1321. u32 rar_entries = hw->mac.num_rar_entries;
  1322. struct ixgbe_addr_filter_info *a = &hw->addr_ctrl;
  1323. if (a->mc_addr_in_rar_count > 0)
  1324. for (i = (rar_entries - a->mc_addr_in_rar_count);
  1325. i < rar_entries; i++)
  1326. ixgbe_enable_rar(hw, i);
  1327. if (a->mta_in_use > 0)
  1328. IXGBE_WRITE_REG(hw, IXGBE_MCSTCTRL, IXGBE_MCSTCTRL_MFE |
  1329. hw->mac.mc_filter_type);
  1330. return 0;
  1331. }
  1332. /**
  1333. * ixgbe_disable_mc_generic - Disable multicast address in RAR
  1334. * @hw: pointer to hardware structure
  1335. *
  1336. * Disables multicast address in RAR and the use of the multicast hash table.
  1337. **/
  1338. s32 ixgbe_disable_mc_generic(struct ixgbe_hw *hw)
  1339. {
  1340. u32 i;
  1341. u32 rar_entries = hw->mac.num_rar_entries;
  1342. struct ixgbe_addr_filter_info *a = &hw->addr_ctrl;
  1343. if (a->mc_addr_in_rar_count > 0)
  1344. for (i = (rar_entries - a->mc_addr_in_rar_count);
  1345. i < rar_entries; i++)
  1346. ixgbe_disable_rar(hw, i);
  1347. if (a->mta_in_use > 0)
  1348. IXGBE_WRITE_REG(hw, IXGBE_MCSTCTRL, hw->mac.mc_filter_type);
  1349. return 0;
  1350. }
  1351. /**
  1352. * ixgbe_fc_enable_generic - Enable flow control
  1353. * @hw: pointer to hardware structure
  1354. * @packetbuf_num: packet buffer number (0-7)
  1355. *
  1356. * Enable flow control according to the current settings.
  1357. **/
  1358. s32 ixgbe_fc_enable_generic(struct ixgbe_hw *hw, s32 packetbuf_num)
  1359. {
  1360. s32 ret_val = 0;
  1361. u32 mflcn_reg, fccfg_reg;
  1362. u32 reg;
  1363. u32 rx_pba_size;
  1364. #ifdef CONFIG_DCB
  1365. if (hw->fc.requested_mode == ixgbe_fc_pfc)
  1366. goto out;
  1367. #endif /* CONFIG_DCB */
  1368. /* Negotiate the fc mode to use */
  1369. ret_val = ixgbe_fc_autoneg(hw);
  1370. if (ret_val)
  1371. goto out;
  1372. /* Disable any previous flow control settings */
  1373. mflcn_reg = IXGBE_READ_REG(hw, IXGBE_MFLCN);
  1374. mflcn_reg &= ~(IXGBE_MFLCN_RFCE | IXGBE_MFLCN_RPFCE);
  1375. fccfg_reg = IXGBE_READ_REG(hw, IXGBE_FCCFG);
  1376. fccfg_reg &= ~(IXGBE_FCCFG_TFCE_802_3X | IXGBE_FCCFG_TFCE_PRIORITY);
  1377. /*
  1378. * The possible values of fc.current_mode are:
  1379. * 0: Flow control is completely disabled
  1380. * 1: Rx flow control is enabled (we can receive pause frames,
  1381. * but not send pause frames).
  1382. * 2: Tx flow control is enabled (we can send pause frames but
  1383. * we do not support receiving pause frames).
  1384. * 3: Both Rx and Tx flow control (symmetric) are enabled.
  1385. * 4: Priority Flow Control is enabled.
  1386. * other: Invalid.
  1387. */
  1388. switch (hw->fc.current_mode) {
  1389. case ixgbe_fc_none:
  1390. /*
  1391. * Flow control is disabled by software override or autoneg.
  1392. * The code below will actually disable it in the HW.
  1393. */
  1394. break;
  1395. case ixgbe_fc_rx_pause:
  1396. /*
  1397. * Rx Flow control is enabled and Tx Flow control is
  1398. * disabled by software override. Since there really
  1399. * isn't a way to advertise that we are capable of RX
  1400. * Pause ONLY, we will advertise that we support both
  1401. * symmetric and asymmetric Rx PAUSE. Later, we will
  1402. * disable the adapter's ability to send PAUSE frames.
  1403. */
  1404. mflcn_reg |= IXGBE_MFLCN_RFCE;
  1405. break;
  1406. case ixgbe_fc_tx_pause:
  1407. /*
  1408. * Tx Flow control is enabled, and Rx Flow control is
  1409. * disabled by software override.
  1410. */
  1411. fccfg_reg |= IXGBE_FCCFG_TFCE_802_3X;
  1412. break;
  1413. case ixgbe_fc_full:
  1414. /* Flow control (both Rx and Tx) is enabled by SW override. */
  1415. mflcn_reg |= IXGBE_MFLCN_RFCE;
  1416. fccfg_reg |= IXGBE_FCCFG_TFCE_802_3X;
  1417. break;
  1418. #ifdef CONFIG_DCB
  1419. case ixgbe_fc_pfc:
  1420. goto out;
  1421. break;
  1422. #endif /* CONFIG_DCB */
  1423. default:
  1424. hw_dbg(hw, "Flow control param set incorrectly\n");
  1425. ret_val = IXGBE_ERR_CONFIG;
  1426. goto out;
  1427. break;
  1428. }
  1429. /* Set 802.3x based flow control settings. */
  1430. mflcn_reg |= IXGBE_MFLCN_DPF;
  1431. IXGBE_WRITE_REG(hw, IXGBE_MFLCN, mflcn_reg);
  1432. IXGBE_WRITE_REG(hw, IXGBE_FCCFG, fccfg_reg);
  1433. reg = IXGBE_READ_REG(hw, IXGBE_MTQC);
  1434. /* Thresholds are different for link flow control when in DCB mode */
  1435. if (reg & IXGBE_MTQC_RT_ENA) {
  1436. rx_pba_size = IXGBE_READ_REG(hw, IXGBE_RXPBSIZE(packetbuf_num));
  1437. /* Always disable XON for LFC when in DCB mode */
  1438. reg = (rx_pba_size >> 5) & 0xFFE0;
  1439. IXGBE_WRITE_REG(hw, IXGBE_FCRTL_82599(packetbuf_num), reg);
  1440. reg = (rx_pba_size >> 2) & 0xFFE0;
  1441. if (hw->fc.current_mode & ixgbe_fc_tx_pause)
  1442. reg |= IXGBE_FCRTH_FCEN;
  1443. IXGBE_WRITE_REG(hw, IXGBE_FCRTH_82599(packetbuf_num), reg);
  1444. } else {
  1445. /*
  1446. * Set up and enable Rx high/low water mark thresholds,
  1447. * enable XON.
  1448. */
  1449. if (hw->fc.current_mode & ixgbe_fc_tx_pause) {
  1450. if (hw->fc.send_xon) {
  1451. IXGBE_WRITE_REG(hw,
  1452. IXGBE_FCRTL_82599(packetbuf_num),
  1453. (hw->fc.low_water |
  1454. IXGBE_FCRTL_XONE));
  1455. } else {
  1456. IXGBE_WRITE_REG(hw,
  1457. IXGBE_FCRTL_82599(packetbuf_num),
  1458. hw->fc.low_water);
  1459. }
  1460. IXGBE_WRITE_REG(hw, IXGBE_FCRTH_82599(packetbuf_num),
  1461. (hw->fc.high_water | IXGBE_FCRTH_FCEN));
  1462. }
  1463. }
  1464. /* Configure pause time (2 TCs per register) */
  1465. reg = IXGBE_READ_REG(hw, IXGBE_FCTTV(packetbuf_num / 2));
  1466. if ((packetbuf_num & 1) == 0)
  1467. reg = (reg & 0xFFFF0000) | hw->fc.pause_time;
  1468. else
  1469. reg = (reg & 0x0000FFFF) | (hw->fc.pause_time << 16);
  1470. IXGBE_WRITE_REG(hw, IXGBE_FCTTV(packetbuf_num / 2), reg);
  1471. IXGBE_WRITE_REG(hw, IXGBE_FCRTV, (hw->fc.pause_time >> 1));
  1472. out:
  1473. return ret_val;
  1474. }
  1475. /**
  1476. * ixgbe_fc_autoneg - Configure flow control
  1477. * @hw: pointer to hardware structure
  1478. *
  1479. * Compares our advertised flow control capabilities to those advertised by
  1480. * our link partner, and determines the proper flow control mode to use.
  1481. **/
  1482. s32 ixgbe_fc_autoneg(struct ixgbe_hw *hw)
  1483. {
  1484. s32 ret_val = 0;
  1485. ixgbe_link_speed speed;
  1486. u32 pcs_anadv_reg, pcs_lpab_reg, linkstat;
  1487. u32 links2, anlp1_reg, autoc_reg, links;
  1488. bool link_up;
  1489. /*
  1490. * AN should have completed when the cable was plugged in.
  1491. * Look for reasons to bail out. Bail out if:
  1492. * - FC autoneg is disabled, or if
  1493. * - link is not up.
  1494. *
  1495. * Since we're being called from an LSC, link is already known to be up.
  1496. * So use link_up_wait_to_complete=false.
  1497. */
  1498. hw->mac.ops.check_link(hw, &speed, &link_up, false);
  1499. if (hw->fc.disable_fc_autoneg || (!link_up)) {
  1500. hw->fc.fc_was_autonegged = false;
  1501. hw->fc.current_mode = hw->fc.requested_mode;
  1502. goto out;
  1503. }
  1504. /*
  1505. * On backplane, bail out if
  1506. * - backplane autoneg was not completed, or if
  1507. * - link partner is not AN enabled
  1508. */
  1509. if (hw->phy.media_type == ixgbe_media_type_backplane) {
  1510. links = IXGBE_READ_REG(hw, IXGBE_LINKS);
  1511. links2 = IXGBE_READ_REG(hw, IXGBE_LINKS2);
  1512. if (((links & IXGBE_LINKS_KX_AN_COMP) == 0) ||
  1513. ((links2 & IXGBE_LINKS2_AN_SUPPORTED) == 0)) {
  1514. hw->fc.fc_was_autonegged = false;
  1515. hw->fc.current_mode = hw->fc.requested_mode;
  1516. goto out;
  1517. }
  1518. }
  1519. /*
  1520. * On multispeed fiber at 1g, bail out if
  1521. * - link is up but AN did not complete, or if
  1522. * - link is up and AN completed but timed out
  1523. */
  1524. if (hw->phy.multispeed_fiber && (speed == IXGBE_LINK_SPEED_1GB_FULL)) {
  1525. linkstat = IXGBE_READ_REG(hw, IXGBE_PCS1GLSTA);
  1526. if (((linkstat & IXGBE_PCS1GLSTA_AN_COMPLETE) == 0) ||
  1527. ((linkstat & IXGBE_PCS1GLSTA_AN_TIMED_OUT) == 1)) {
  1528. hw->fc.fc_was_autonegged = false;
  1529. hw->fc.current_mode = hw->fc.requested_mode;
  1530. goto out;
  1531. }
  1532. }
  1533. /*
  1534. * Read the AN advertisement and LP ability registers and resolve
  1535. * local flow control settings accordingly
  1536. */
  1537. if ((speed == IXGBE_LINK_SPEED_1GB_FULL) &&
  1538. (hw->phy.media_type != ixgbe_media_type_backplane)) {
  1539. pcs_anadv_reg = IXGBE_READ_REG(hw, IXGBE_PCS1GANA);
  1540. pcs_lpab_reg = IXGBE_READ_REG(hw, IXGBE_PCS1GANLP);
  1541. if ((pcs_anadv_reg & IXGBE_PCS1GANA_SYM_PAUSE) &&
  1542. (pcs_lpab_reg & IXGBE_PCS1GANA_SYM_PAUSE)) {
  1543. /*
  1544. * Now we need to check if the user selected Rx ONLY
  1545. * of pause frames. In this case, we had to advertise
  1546. * FULL flow control because we could not advertise RX
  1547. * ONLY. Hence, we must now check to see if we need to
  1548. * turn OFF the TRANSMISSION of PAUSE frames.
  1549. */
  1550. if (hw->fc.requested_mode == ixgbe_fc_full) {
  1551. hw->fc.current_mode = ixgbe_fc_full;
  1552. hw_dbg(hw, "Flow Control = FULL.\n");
  1553. } else {
  1554. hw->fc.current_mode = ixgbe_fc_rx_pause;
  1555. hw_dbg(hw, "Flow Control=RX PAUSE only\n");
  1556. }
  1557. } else if (!(pcs_anadv_reg & IXGBE_PCS1GANA_SYM_PAUSE) &&
  1558. (pcs_anadv_reg & IXGBE_PCS1GANA_ASM_PAUSE) &&
  1559. (pcs_lpab_reg & IXGBE_PCS1GANA_SYM_PAUSE) &&
  1560. (pcs_lpab_reg & IXGBE_PCS1GANA_ASM_PAUSE)) {
  1561. hw->fc.current_mode = ixgbe_fc_tx_pause;
  1562. hw_dbg(hw, "Flow Control = TX PAUSE frames only.\n");
  1563. } else if ((pcs_anadv_reg & IXGBE_PCS1GANA_SYM_PAUSE) &&
  1564. (pcs_anadv_reg & IXGBE_PCS1GANA_ASM_PAUSE) &&
  1565. !(pcs_lpab_reg & IXGBE_PCS1GANA_SYM_PAUSE) &&
  1566. (pcs_lpab_reg & IXGBE_PCS1GANA_ASM_PAUSE)) {
  1567. hw->fc.current_mode = ixgbe_fc_rx_pause;
  1568. hw_dbg(hw, "Flow Control = RX PAUSE frames only.\n");
  1569. } else {
  1570. hw->fc.current_mode = ixgbe_fc_none;
  1571. hw_dbg(hw, "Flow Control = NONE.\n");
  1572. }
  1573. }
  1574. if (hw->phy.media_type == ixgbe_media_type_backplane) {
  1575. /*
  1576. * Read the 10g AN autoc and LP ability registers and resolve
  1577. * local flow control settings accordingly
  1578. */
  1579. autoc_reg = IXGBE_READ_REG(hw, IXGBE_AUTOC);
  1580. anlp1_reg = IXGBE_READ_REG(hw, IXGBE_ANLP1);
  1581. if ((autoc_reg & IXGBE_AUTOC_SYM_PAUSE) &&
  1582. (anlp1_reg & IXGBE_ANLP1_SYM_PAUSE)) {
  1583. /*
  1584. * Now we need to check if the user selected Rx ONLY
  1585. * of pause frames. In this case, we had to advertise
  1586. * FULL flow control because we could not advertise RX
  1587. * ONLY. Hence, we must now check to see if we need to
  1588. * turn OFF the TRANSMISSION of PAUSE frames.
  1589. */
  1590. if (hw->fc.requested_mode == ixgbe_fc_full) {
  1591. hw->fc.current_mode = ixgbe_fc_full;
  1592. hw_dbg(hw, "Flow Control = FULL.\n");
  1593. } else {
  1594. hw->fc.current_mode = ixgbe_fc_rx_pause;
  1595. hw_dbg(hw, "Flow Control=RX PAUSE only\n");
  1596. }
  1597. } else if (!(autoc_reg & IXGBE_AUTOC_SYM_PAUSE) &&
  1598. (autoc_reg & IXGBE_AUTOC_ASM_PAUSE) &&
  1599. (anlp1_reg & IXGBE_ANLP1_SYM_PAUSE) &&
  1600. (anlp1_reg & IXGBE_ANLP1_ASM_PAUSE)) {
  1601. hw->fc.current_mode = ixgbe_fc_tx_pause;
  1602. hw_dbg(hw, "Flow Control = TX PAUSE frames only.\n");
  1603. } else if ((autoc_reg & IXGBE_AUTOC_SYM_PAUSE) &&
  1604. (autoc_reg & IXGBE_AUTOC_ASM_PAUSE) &&
  1605. !(anlp1_reg & IXGBE_ANLP1_SYM_PAUSE) &&
  1606. (anlp1_reg & IXGBE_ANLP1_ASM_PAUSE)) {
  1607. hw->fc.current_mode = ixgbe_fc_rx_pause;
  1608. hw_dbg(hw, "Flow Control = RX PAUSE frames only.\n");
  1609. } else {
  1610. hw->fc.current_mode = ixgbe_fc_none;
  1611. hw_dbg(hw, "Flow Control = NONE.\n");
  1612. }
  1613. }
  1614. /* Record that current_mode is the result of a successful autoneg */
  1615. hw->fc.fc_was_autonegged = true;
  1616. out:
  1617. return ret_val;
  1618. }
  1619. /**
  1620. * ixgbe_setup_fc - Set up flow control
  1621. * @hw: pointer to hardware structure
  1622. *
  1623. * Called at init time to set up flow control.
  1624. **/
  1625. static s32 ixgbe_setup_fc(struct ixgbe_hw *hw, s32 packetbuf_num)
  1626. {
  1627. s32 ret_val = 0;
  1628. u32 reg;
  1629. #ifdef CONFIG_DCB
  1630. if (hw->fc.requested_mode == ixgbe_fc_pfc) {
  1631. hw->fc.current_mode = hw->fc.requested_mode;
  1632. goto out;
  1633. }
  1634. #endif
  1635. /* Validate the packetbuf configuration */
  1636. if (packetbuf_num < 0 || packetbuf_num > 7) {
  1637. hw_dbg(hw, "Invalid packet buffer number [%d], expected range "
  1638. "is 0-7\n", packetbuf_num);
  1639. ret_val = IXGBE_ERR_INVALID_LINK_SETTINGS;
  1640. goto out;
  1641. }
  1642. /*
  1643. * Validate the water mark configuration. Zero water marks are invalid
  1644. * because it causes the controller to just blast out fc packets.
  1645. */
  1646. if (!hw->fc.low_water || !hw->fc.high_water || !hw->fc.pause_time) {
  1647. hw_dbg(hw, "Invalid water mark configuration\n");
  1648. ret_val = IXGBE_ERR_INVALID_LINK_SETTINGS;
  1649. goto out;
  1650. }
  1651. /*
  1652. * Validate the requested mode. Strict IEEE mode does not allow
  1653. * ixgbe_fc_rx_pause because it will cause us to fail at UNH.
  1654. */
  1655. if (hw->fc.strict_ieee && hw->fc.requested_mode == ixgbe_fc_rx_pause) {
  1656. hw_dbg(hw, "ixgbe_fc_rx_pause not valid in strict "
  1657. "IEEE mode\n");
  1658. ret_val = IXGBE_ERR_INVALID_LINK_SETTINGS;
  1659. goto out;
  1660. }
  1661. /*
  1662. * 10gig parts do not have a word in the EEPROM to determine the
  1663. * default flow control setting, so we explicitly set it to full.
  1664. */
  1665. if (hw->fc.requested_mode == ixgbe_fc_default)
  1666. hw->fc.requested_mode = ixgbe_fc_full;
  1667. /*
  1668. * Set up the 1G flow control advertisement registers so the HW will be
  1669. * able to do fc autoneg once the cable is plugged in. If we end up
  1670. * using 10g instead, this is harmless.
  1671. */
  1672. reg = IXGBE_READ_REG(hw, IXGBE_PCS1GANA);
  1673. /*
  1674. * The possible values of fc.requested_mode are:
  1675. * 0: Flow control is completely disabled
  1676. * 1: Rx flow control is enabled (we can receive pause frames,
  1677. * but not send pause frames).
  1678. * 2: Tx flow control is enabled (we can send pause frames but
  1679. * we do not support receiving pause frames).
  1680. * 3: Both Rx and Tx flow control (symmetric) are enabled.
  1681. #ifdef CONFIG_DCB
  1682. * 4: Priority Flow Control is enabled.
  1683. #endif
  1684. * other: Invalid.
  1685. */
  1686. switch (hw->fc.requested_mode) {
  1687. case ixgbe_fc_none:
  1688. /* Flow control completely disabled by software override. */
  1689. reg &= ~(IXGBE_PCS1GANA_SYM_PAUSE | IXGBE_PCS1GANA_ASM_PAUSE);
  1690. break;
  1691. case ixgbe_fc_rx_pause:
  1692. /*
  1693. * Rx Flow control is enabled and Tx Flow control is
  1694. * disabled by software override. Since there really
  1695. * isn't a way to advertise that we are capable of RX
  1696. * Pause ONLY, we will advertise that we support both
  1697. * symmetric and asymmetric Rx PAUSE. Later, we will
  1698. * disable the adapter's ability to send PAUSE frames.
  1699. */
  1700. reg |= (IXGBE_PCS1GANA_SYM_PAUSE | IXGBE_PCS1GANA_ASM_PAUSE);
  1701. break;
  1702. case ixgbe_fc_tx_pause:
  1703. /*
  1704. * Tx Flow control is enabled, and Rx Flow control is
  1705. * disabled by software override.
  1706. */
  1707. reg |= (IXGBE_PCS1GANA_ASM_PAUSE);
  1708. reg &= ~(IXGBE_PCS1GANA_SYM_PAUSE);
  1709. break;
  1710. case ixgbe_fc_full:
  1711. /* Flow control (both Rx and Tx) is enabled by SW override. */
  1712. reg |= (IXGBE_PCS1GANA_SYM_PAUSE | IXGBE_PCS1GANA_ASM_PAUSE);
  1713. break;
  1714. #ifdef CONFIG_DCB
  1715. case ixgbe_fc_pfc:
  1716. goto out;
  1717. break;
  1718. #endif /* CONFIG_DCB */
  1719. default:
  1720. hw_dbg(hw, "Flow control param set incorrectly\n");
  1721. ret_val = IXGBE_ERR_CONFIG;
  1722. goto out;
  1723. break;
  1724. }
  1725. IXGBE_WRITE_REG(hw, IXGBE_PCS1GANA, reg);
  1726. reg = IXGBE_READ_REG(hw, IXGBE_PCS1GLCTL);
  1727. /* Disable AN timeout */
  1728. if (hw->fc.strict_ieee)
  1729. reg &= ~IXGBE_PCS1GLCTL_AN_1G_TIMEOUT_EN;
  1730. IXGBE_WRITE_REG(hw, IXGBE_PCS1GLCTL, reg);
  1731. hw_dbg(hw, "Set up FC; PCS1GLCTL = 0x%08X\n", reg);
  1732. /*
  1733. * Set up the 10G flow control advertisement registers so the HW
  1734. * can do fc autoneg once the cable is plugged in. If we end up
  1735. * using 1g instead, this is harmless.
  1736. */
  1737. reg = IXGBE_READ_REG(hw, IXGBE_AUTOC);
  1738. /*
  1739. * The possible values of fc.requested_mode are:
  1740. * 0: Flow control is completely disabled
  1741. * 1: Rx flow control is enabled (we can receive pause frames,
  1742. * but not send pause frames).
  1743. * 2: Tx flow control is enabled (we can send pause frames but
  1744. * we do not support receiving pause frames).
  1745. * 3: Both Rx and Tx flow control (symmetric) are enabled.
  1746. * other: Invalid.
  1747. */
  1748. switch (hw->fc.requested_mode) {
  1749. case ixgbe_fc_none:
  1750. /* Flow control completely disabled by software override. */
  1751. reg &= ~(IXGBE_AUTOC_SYM_PAUSE | IXGBE_AUTOC_ASM_PAUSE);
  1752. break;
  1753. case ixgbe_fc_rx_pause:
  1754. /*
  1755. * Rx Flow control is enabled and Tx Flow control is
  1756. * disabled by software override. Since there really
  1757. * isn't a way to advertise that we are capable of RX
  1758. * Pause ONLY, we will advertise that we support both
  1759. * symmetric and asymmetric Rx PAUSE. Later, we will
  1760. * disable the adapter's ability to send PAUSE frames.
  1761. */
  1762. reg |= (IXGBE_AUTOC_SYM_PAUSE | IXGBE_AUTOC_ASM_PAUSE);
  1763. break;
  1764. case ixgbe_fc_tx_pause:
  1765. /*
  1766. * Tx Flow control is enabled, and Rx Flow control is
  1767. * disabled by software override.
  1768. */
  1769. reg |= (IXGBE_AUTOC_ASM_PAUSE);
  1770. reg &= ~(IXGBE_AUTOC_SYM_PAUSE);
  1771. break;
  1772. case ixgbe_fc_full:
  1773. /* Flow control (both Rx and Tx) is enabled by SW override. */
  1774. reg |= (IXGBE_AUTOC_SYM_PAUSE | IXGBE_AUTOC_ASM_PAUSE);
  1775. break;
  1776. #ifdef CONFIG_DCB
  1777. case ixgbe_fc_pfc:
  1778. goto out;
  1779. break;
  1780. #endif /* CONFIG_DCB */
  1781. default:
  1782. hw_dbg(hw, "Flow control param set incorrectly\n");
  1783. ret_val = IXGBE_ERR_CONFIG;
  1784. goto out;
  1785. break;
  1786. }
  1787. /*
  1788. * AUTOC restart handles negotiation of 1G and 10G. There is
  1789. * no need to set the PCS1GCTL register.
  1790. */
  1791. reg |= IXGBE_AUTOC_AN_RESTART;
  1792. IXGBE_WRITE_REG(hw, IXGBE_AUTOC, reg);
  1793. hw_dbg(hw, "Set up FC; IXGBE_AUTOC = 0x%08X\n", reg);
  1794. out:
  1795. return ret_val;
  1796. }
  1797. /**
  1798. * ixgbe_disable_pcie_master - Disable PCI-express master access
  1799. * @hw: pointer to hardware structure
  1800. *
  1801. * Disables PCI-Express master access and verifies there are no pending
  1802. * requests. IXGBE_ERR_MASTER_REQUESTS_PENDING is returned if master disable
  1803. * bit hasn't caused the master requests to be disabled, else 0
  1804. * is returned signifying master requests disabled.
  1805. **/
  1806. s32 ixgbe_disable_pcie_master(struct ixgbe_hw *hw)
  1807. {
  1808. u32 i;
  1809. u32 reg_val;
  1810. u32 number_of_queues;
  1811. s32 status = IXGBE_ERR_MASTER_REQUESTS_PENDING;
  1812. /* Disable the receive unit by stopping each queue */
  1813. number_of_queues = hw->mac.max_rx_queues;
  1814. for (i = 0; i < number_of_queues; i++) {
  1815. reg_val = IXGBE_READ_REG(hw, IXGBE_RXDCTL(i));
  1816. if (reg_val & IXGBE_RXDCTL_ENABLE) {
  1817. reg_val &= ~IXGBE_RXDCTL_ENABLE;
  1818. IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(i), reg_val);
  1819. }
  1820. }
  1821. reg_val = IXGBE_READ_REG(hw, IXGBE_CTRL);
  1822. reg_val |= IXGBE_CTRL_GIO_DIS;
  1823. IXGBE_WRITE_REG(hw, IXGBE_CTRL, reg_val);
  1824. for (i = 0; i < IXGBE_PCI_MASTER_DISABLE_TIMEOUT; i++) {
  1825. if (!(IXGBE_READ_REG(hw, IXGBE_STATUS) & IXGBE_STATUS_GIO)) {
  1826. status = 0;
  1827. break;
  1828. }
  1829. udelay(100);
  1830. }
  1831. return status;
  1832. }
  1833. /**
  1834. * ixgbe_acquire_swfw_sync - Acquire SWFW semaphore
  1835. * @hw: pointer to hardware structure
  1836. * @mask: Mask to specify which semaphore to acquire
  1837. *
  1838. * Acquires the SWFW semaphore thought the GSSR register for the specified
  1839. * function (CSR, PHY0, PHY1, EEPROM, Flash)
  1840. **/
  1841. s32 ixgbe_acquire_swfw_sync(struct ixgbe_hw *hw, u16 mask)
  1842. {
  1843. u32 gssr;
  1844. u32 swmask = mask;
  1845. u32 fwmask = mask << 5;
  1846. s32 timeout = 200;
  1847. while (timeout) {
  1848. if (ixgbe_get_eeprom_semaphore(hw))
  1849. return IXGBE_ERR_SWFW_SYNC;
  1850. gssr = IXGBE_READ_REG(hw, IXGBE_GSSR);
  1851. if (!(gssr & (fwmask | swmask)))
  1852. break;
  1853. /*
  1854. * Firmware currently using resource (fwmask) or other software
  1855. * thread currently using resource (swmask)
  1856. */
  1857. ixgbe_release_eeprom_semaphore(hw);
  1858. msleep(5);
  1859. timeout--;
  1860. }
  1861. if (!timeout) {
  1862. hw_dbg(hw, "Driver can't access resource, GSSR timeout.\n");
  1863. return IXGBE_ERR_SWFW_SYNC;
  1864. }
  1865. gssr |= swmask;
  1866. IXGBE_WRITE_REG(hw, IXGBE_GSSR, gssr);
  1867. ixgbe_release_eeprom_semaphore(hw);
  1868. return 0;
  1869. }
  1870. /**
  1871. * ixgbe_release_swfw_sync - Release SWFW semaphore
  1872. * @hw: pointer to hardware structure
  1873. * @mask: Mask to specify which semaphore to release
  1874. *
  1875. * Releases the SWFW semaphore thought the GSSR register for the specified
  1876. * function (CSR, PHY0, PHY1, EEPROM, Flash)
  1877. **/
  1878. void ixgbe_release_swfw_sync(struct ixgbe_hw *hw, u16 mask)
  1879. {
  1880. u32 gssr;
  1881. u32 swmask = mask;
  1882. ixgbe_get_eeprom_semaphore(hw);
  1883. gssr = IXGBE_READ_REG(hw, IXGBE_GSSR);
  1884. gssr &= ~swmask;
  1885. IXGBE_WRITE_REG(hw, IXGBE_GSSR, gssr);
  1886. ixgbe_release_eeprom_semaphore(hw);
  1887. }
  1888. /**
  1889. * ixgbe_enable_rx_dma_generic - Enable the Rx DMA unit
  1890. * @hw: pointer to hardware structure
  1891. * @regval: register value to write to RXCTRL
  1892. *
  1893. * Enables the Rx DMA unit
  1894. **/
  1895. s32 ixgbe_enable_rx_dma_generic(struct ixgbe_hw *hw, u32 regval)
  1896. {
  1897. IXGBE_WRITE_REG(hw, IXGBE_RXCTRL, regval);
  1898. return 0;
  1899. }
  1900. /**
  1901. * ixgbe_blink_led_start_generic - Blink LED based on index.
  1902. * @hw: pointer to hardware structure
  1903. * @index: led number to blink
  1904. **/
  1905. s32 ixgbe_blink_led_start_generic(struct ixgbe_hw *hw, u32 index)
  1906. {
  1907. ixgbe_link_speed speed = 0;
  1908. bool link_up = 0;
  1909. u32 autoc_reg = IXGBE_READ_REG(hw, IXGBE_AUTOC);
  1910. u32 led_reg = IXGBE_READ_REG(hw, IXGBE_LEDCTL);
  1911. /*
  1912. * Link must be up to auto-blink the LEDs;
  1913. * Force it if link is down.
  1914. */
  1915. hw->mac.ops.check_link(hw, &speed, &link_up, false);
  1916. if (!link_up) {
  1917. autoc_reg |= IXGBE_AUTOC_AN_RESTART;
  1918. autoc_reg |= IXGBE_AUTOC_FLU;
  1919. IXGBE_WRITE_REG(hw, IXGBE_AUTOC, autoc_reg);
  1920. msleep(10);
  1921. }
  1922. led_reg &= ~IXGBE_LED_MODE_MASK(index);
  1923. led_reg |= IXGBE_LED_BLINK(index);
  1924. IXGBE_WRITE_REG(hw, IXGBE_LEDCTL, led_reg);
  1925. IXGBE_WRITE_FLUSH(hw);
  1926. return 0;
  1927. }
  1928. /**
  1929. * ixgbe_blink_led_stop_generic - Stop blinking LED based on index.
  1930. * @hw: pointer to hardware structure
  1931. * @index: led number to stop blinking
  1932. **/
  1933. s32 ixgbe_blink_led_stop_generic(struct ixgbe_hw *hw, u32 index)
  1934. {
  1935. u32 autoc_reg = IXGBE_READ_REG(hw, IXGBE_AUTOC);
  1936. u32 led_reg = IXGBE_READ_REG(hw, IXGBE_LEDCTL);
  1937. autoc_reg &= ~IXGBE_AUTOC_FLU;
  1938. autoc_reg |= IXGBE_AUTOC_AN_RESTART;
  1939. IXGBE_WRITE_REG(hw, IXGBE_AUTOC, autoc_reg);
  1940. led_reg &= ~IXGBE_LED_MODE_MASK(index);
  1941. led_reg &= ~IXGBE_LED_BLINK(index);
  1942. led_reg |= IXGBE_LED_LINK_ACTIVE << IXGBE_LED_MODE_SHIFT(index);
  1943. IXGBE_WRITE_REG(hw, IXGBE_LEDCTL, led_reg);
  1944. IXGBE_WRITE_FLUSH(hw);
  1945. return 0;
  1946. }