ixgbe_common.c 75 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751
  1. /*******************************************************************************
  2. Intel 10 Gigabit PCI Express Linux driver
  3. Copyright(c) 1999 - 2010 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/netdevice.h>
  24. #include "ixgbe.h"
  25. #include "ixgbe_common.h"
  26. #include "ixgbe_phy.h"
  27. static s32 ixgbe_acquire_eeprom(struct ixgbe_hw *hw);
  28. static s32 ixgbe_get_eeprom_semaphore(struct ixgbe_hw *hw);
  29. static void ixgbe_release_eeprom_semaphore(struct ixgbe_hw *hw);
  30. static s32 ixgbe_ready_eeprom(struct ixgbe_hw *hw);
  31. static void ixgbe_standby_eeprom(struct ixgbe_hw *hw);
  32. static void ixgbe_shift_out_eeprom_bits(struct ixgbe_hw *hw, u16 data,
  33. u16 count);
  34. static u16 ixgbe_shift_in_eeprom_bits(struct ixgbe_hw *hw, u16 count);
  35. static void ixgbe_raise_eeprom_clk(struct ixgbe_hw *hw, u32 *eec);
  36. static void ixgbe_lower_eeprom_clk(struct ixgbe_hw *hw, u32 *eec);
  37. static void ixgbe_release_eeprom(struct ixgbe_hw *hw);
  38. static u16 ixgbe_calc_eeprom_checksum(struct ixgbe_hw *hw);
  39. static void ixgbe_enable_rar(struct ixgbe_hw *hw, u32 index);
  40. static void ixgbe_disable_rar(struct ixgbe_hw *hw, u32 index);
  41. static s32 ixgbe_mta_vector(struct ixgbe_hw *hw, u8 *mc_addr);
  42. static void ixgbe_add_uc_addr(struct ixgbe_hw *hw, u8 *addr, u32 vmdq);
  43. static s32 ixgbe_setup_fc(struct ixgbe_hw *hw, s32 packetbuf_num);
  44. /**
  45. * ixgbe_start_hw_generic - Prepare hardware for Tx/Rx
  46. * @hw: pointer to hardware structure
  47. *
  48. * Starts the hardware by filling the bus info structure and media type, clears
  49. * all on chip counters, initializes receive address registers, multicast
  50. * table, VLAN filter table, calls routine to set up link and flow control
  51. * settings, and leaves transmit and receive units disabled and uninitialized
  52. **/
  53. s32 ixgbe_start_hw_generic(struct ixgbe_hw *hw)
  54. {
  55. u32 ctrl_ext;
  56. /* Set the media type */
  57. hw->phy.media_type = hw->mac.ops.get_media_type(hw);
  58. /* Identify the PHY */
  59. hw->phy.ops.identify(hw);
  60. /* Clear the VLAN filter table */
  61. hw->mac.ops.clear_vfta(hw);
  62. /* Clear statistics registers */
  63. hw->mac.ops.clear_hw_cntrs(hw);
  64. /* Set No Snoop Disable */
  65. ctrl_ext = IXGBE_READ_REG(hw, IXGBE_CTRL_EXT);
  66. ctrl_ext |= IXGBE_CTRL_EXT_NS_DIS;
  67. IXGBE_WRITE_REG(hw, IXGBE_CTRL_EXT, ctrl_ext);
  68. IXGBE_WRITE_FLUSH(hw);
  69. /* Setup flow control */
  70. ixgbe_setup_fc(hw, 0);
  71. /* Clear adapter stopped flag */
  72. hw->adapter_stopped = false;
  73. return 0;
  74. }
  75. /**
  76. * ixgbe_init_hw_generic - Generic hardware initialization
  77. * @hw: pointer to hardware structure
  78. *
  79. * Initialize the hardware by resetting the hardware, filling the bus info
  80. * structure and media type, clears all on chip counters, initializes receive
  81. * address registers, multicast table, VLAN filter table, calls routine to set
  82. * up link and flow control settings, and leaves transmit and receive units
  83. * disabled and uninitialized
  84. **/
  85. s32 ixgbe_init_hw_generic(struct ixgbe_hw *hw)
  86. {
  87. s32 status;
  88. /* Reset the hardware */
  89. status = hw->mac.ops.reset_hw(hw);
  90. if (status == 0) {
  91. /* Start the HW */
  92. status = hw->mac.ops.start_hw(hw);
  93. }
  94. return status;
  95. }
  96. /**
  97. * ixgbe_clear_hw_cntrs_generic - Generic clear hardware counters
  98. * @hw: pointer to hardware structure
  99. *
  100. * Clears all hardware statistics counters by reading them from the hardware
  101. * Statistics counters are clear on read.
  102. **/
  103. s32 ixgbe_clear_hw_cntrs_generic(struct ixgbe_hw *hw)
  104. {
  105. u16 i = 0;
  106. IXGBE_READ_REG(hw, IXGBE_CRCERRS);
  107. IXGBE_READ_REG(hw, IXGBE_ILLERRC);
  108. IXGBE_READ_REG(hw, IXGBE_ERRBC);
  109. IXGBE_READ_REG(hw, IXGBE_MSPDC);
  110. for (i = 0; i < 8; i++)
  111. IXGBE_READ_REG(hw, IXGBE_MPC(i));
  112. IXGBE_READ_REG(hw, IXGBE_MLFC);
  113. IXGBE_READ_REG(hw, IXGBE_MRFC);
  114. IXGBE_READ_REG(hw, IXGBE_RLEC);
  115. IXGBE_READ_REG(hw, IXGBE_LXONTXC);
  116. IXGBE_READ_REG(hw, IXGBE_LXONRXC);
  117. IXGBE_READ_REG(hw, IXGBE_LXOFFTXC);
  118. IXGBE_READ_REG(hw, IXGBE_LXOFFRXC);
  119. for (i = 0; i < 8; i++) {
  120. IXGBE_READ_REG(hw, IXGBE_PXONTXC(i));
  121. IXGBE_READ_REG(hw, IXGBE_PXONRXC(i));
  122. IXGBE_READ_REG(hw, IXGBE_PXOFFTXC(i));
  123. IXGBE_READ_REG(hw, IXGBE_PXOFFRXC(i));
  124. }
  125. IXGBE_READ_REG(hw, IXGBE_PRC64);
  126. IXGBE_READ_REG(hw, IXGBE_PRC127);
  127. IXGBE_READ_REG(hw, IXGBE_PRC255);
  128. IXGBE_READ_REG(hw, IXGBE_PRC511);
  129. IXGBE_READ_REG(hw, IXGBE_PRC1023);
  130. IXGBE_READ_REG(hw, IXGBE_PRC1522);
  131. IXGBE_READ_REG(hw, IXGBE_GPRC);
  132. IXGBE_READ_REG(hw, IXGBE_BPRC);
  133. IXGBE_READ_REG(hw, IXGBE_MPRC);
  134. IXGBE_READ_REG(hw, IXGBE_GPTC);
  135. IXGBE_READ_REG(hw, IXGBE_GORCL);
  136. IXGBE_READ_REG(hw, IXGBE_GORCH);
  137. IXGBE_READ_REG(hw, IXGBE_GOTCL);
  138. IXGBE_READ_REG(hw, IXGBE_GOTCH);
  139. for (i = 0; i < 8; i++)
  140. IXGBE_READ_REG(hw, IXGBE_RNBC(i));
  141. IXGBE_READ_REG(hw, IXGBE_RUC);
  142. IXGBE_READ_REG(hw, IXGBE_RFC);
  143. IXGBE_READ_REG(hw, IXGBE_ROC);
  144. IXGBE_READ_REG(hw, IXGBE_RJC);
  145. IXGBE_READ_REG(hw, IXGBE_MNGPRC);
  146. IXGBE_READ_REG(hw, IXGBE_MNGPDC);
  147. IXGBE_READ_REG(hw, IXGBE_MNGPTC);
  148. IXGBE_READ_REG(hw, IXGBE_TORL);
  149. IXGBE_READ_REG(hw, IXGBE_TORH);
  150. IXGBE_READ_REG(hw, IXGBE_TPR);
  151. IXGBE_READ_REG(hw, IXGBE_TPT);
  152. IXGBE_READ_REG(hw, IXGBE_PTC64);
  153. IXGBE_READ_REG(hw, IXGBE_PTC127);
  154. IXGBE_READ_REG(hw, IXGBE_PTC255);
  155. IXGBE_READ_REG(hw, IXGBE_PTC511);
  156. IXGBE_READ_REG(hw, IXGBE_PTC1023);
  157. IXGBE_READ_REG(hw, IXGBE_PTC1522);
  158. IXGBE_READ_REG(hw, IXGBE_MPTC);
  159. IXGBE_READ_REG(hw, IXGBE_BPTC);
  160. for (i = 0; i < 16; i++) {
  161. IXGBE_READ_REG(hw, IXGBE_QPRC(i));
  162. IXGBE_READ_REG(hw, IXGBE_QBRC(i));
  163. IXGBE_READ_REG(hw, IXGBE_QPTC(i));
  164. IXGBE_READ_REG(hw, IXGBE_QBTC(i));
  165. }
  166. return 0;
  167. }
  168. /**
  169. * ixgbe_read_pba_num_generic - Reads part number from EEPROM
  170. * @hw: pointer to hardware structure
  171. * @pba_num: stores the part number from the EEPROM
  172. *
  173. * Reads the part number from the EEPROM.
  174. **/
  175. s32 ixgbe_read_pba_num_generic(struct ixgbe_hw *hw, u32 *pba_num)
  176. {
  177. s32 ret_val;
  178. u16 data;
  179. ret_val = hw->eeprom.ops.read(hw, IXGBE_PBANUM0_PTR, &data);
  180. if (ret_val) {
  181. hw_dbg(hw, "NVM Read Error\n");
  182. return ret_val;
  183. }
  184. *pba_num = (u32)(data << 16);
  185. ret_val = hw->eeprom.ops.read(hw, IXGBE_PBANUM1_PTR, &data);
  186. if (ret_val) {
  187. hw_dbg(hw, "NVM Read Error\n");
  188. return ret_val;
  189. }
  190. *pba_num |= data;
  191. return 0;
  192. }
  193. /**
  194. * ixgbe_get_mac_addr_generic - Generic get MAC address
  195. * @hw: pointer to hardware structure
  196. * @mac_addr: Adapter MAC address
  197. *
  198. * Reads the adapter's MAC address from first Receive Address Register (RAR0)
  199. * A reset of the adapter must be performed prior to calling this function
  200. * in order for the MAC address to have been loaded from the EEPROM into RAR0
  201. **/
  202. s32 ixgbe_get_mac_addr_generic(struct ixgbe_hw *hw, u8 *mac_addr)
  203. {
  204. u32 rar_high;
  205. u32 rar_low;
  206. u16 i;
  207. rar_high = IXGBE_READ_REG(hw, IXGBE_RAH(0));
  208. rar_low = IXGBE_READ_REG(hw, IXGBE_RAL(0));
  209. for (i = 0; i < 4; i++)
  210. mac_addr[i] = (u8)(rar_low >> (i*8));
  211. for (i = 0; i < 2; i++)
  212. mac_addr[i+4] = (u8)(rar_high >> (i*8));
  213. return 0;
  214. }
  215. /**
  216. * ixgbe_get_bus_info_generic - Generic set PCI bus info
  217. * @hw: pointer to hardware structure
  218. *
  219. * Sets the PCI bus info (speed, width, type) within the ixgbe_hw structure
  220. **/
  221. s32 ixgbe_get_bus_info_generic(struct ixgbe_hw *hw)
  222. {
  223. struct ixgbe_adapter *adapter = hw->back;
  224. struct ixgbe_mac_info *mac = &hw->mac;
  225. u16 link_status;
  226. hw->bus.type = ixgbe_bus_type_pci_express;
  227. /* Get the negotiated link width and speed from PCI config space */
  228. pci_read_config_word(adapter->pdev, IXGBE_PCI_LINK_STATUS,
  229. &link_status);
  230. switch (link_status & IXGBE_PCI_LINK_WIDTH) {
  231. case IXGBE_PCI_LINK_WIDTH_1:
  232. hw->bus.width = ixgbe_bus_width_pcie_x1;
  233. break;
  234. case IXGBE_PCI_LINK_WIDTH_2:
  235. hw->bus.width = ixgbe_bus_width_pcie_x2;
  236. break;
  237. case IXGBE_PCI_LINK_WIDTH_4:
  238. hw->bus.width = ixgbe_bus_width_pcie_x4;
  239. break;
  240. case IXGBE_PCI_LINK_WIDTH_8:
  241. hw->bus.width = ixgbe_bus_width_pcie_x8;
  242. break;
  243. default:
  244. hw->bus.width = ixgbe_bus_width_unknown;
  245. break;
  246. }
  247. switch (link_status & IXGBE_PCI_LINK_SPEED) {
  248. case IXGBE_PCI_LINK_SPEED_2500:
  249. hw->bus.speed = ixgbe_bus_speed_2500;
  250. break;
  251. case IXGBE_PCI_LINK_SPEED_5000:
  252. hw->bus.speed = ixgbe_bus_speed_5000;
  253. break;
  254. default:
  255. hw->bus.speed = ixgbe_bus_speed_unknown;
  256. break;
  257. }
  258. mac->ops.set_lan_id(hw);
  259. return 0;
  260. }
  261. /**
  262. * ixgbe_set_lan_id_multi_port_pcie - Set LAN id for PCIe multiple port devices
  263. * @hw: pointer to the HW structure
  264. *
  265. * Determines the LAN function id by reading memory-mapped registers
  266. * and swaps the port value if requested.
  267. **/
  268. void ixgbe_set_lan_id_multi_port_pcie(struct ixgbe_hw *hw)
  269. {
  270. struct ixgbe_bus_info *bus = &hw->bus;
  271. u32 reg;
  272. reg = IXGBE_READ_REG(hw, IXGBE_STATUS);
  273. bus->func = (reg & IXGBE_STATUS_LAN_ID) >> IXGBE_STATUS_LAN_ID_SHIFT;
  274. bus->lan_id = bus->func;
  275. /* check for a port swap */
  276. reg = IXGBE_READ_REG(hw, IXGBE_FACTPS);
  277. if (reg & IXGBE_FACTPS_LFS)
  278. bus->func ^= 0x1;
  279. }
  280. /**
  281. * ixgbe_stop_adapter_generic - Generic stop Tx/Rx units
  282. * @hw: pointer to hardware structure
  283. *
  284. * Sets the adapter_stopped flag within ixgbe_hw struct. Clears interrupts,
  285. * disables transmit and receive units. The adapter_stopped flag is used by
  286. * the shared code and drivers to determine if the adapter is in a stopped
  287. * state and should not touch the hardware.
  288. **/
  289. s32 ixgbe_stop_adapter_generic(struct ixgbe_hw *hw)
  290. {
  291. u32 number_of_queues;
  292. u32 reg_val;
  293. u16 i;
  294. /*
  295. * Set the adapter_stopped flag so other driver functions stop touching
  296. * the hardware
  297. */
  298. hw->adapter_stopped = true;
  299. /* Disable the receive unit */
  300. reg_val = IXGBE_READ_REG(hw, IXGBE_RXCTRL);
  301. reg_val &= ~(IXGBE_RXCTRL_RXEN);
  302. IXGBE_WRITE_REG(hw, IXGBE_RXCTRL, reg_val);
  303. IXGBE_WRITE_FLUSH(hw);
  304. msleep(2);
  305. /* Clear interrupt mask to stop from interrupts being generated */
  306. IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_IRQ_CLEAR_MASK);
  307. /* Clear any pending interrupts */
  308. IXGBE_READ_REG(hw, IXGBE_EICR);
  309. /* Disable the transmit unit. Each queue must be disabled. */
  310. number_of_queues = hw->mac.max_tx_queues;
  311. for (i = 0; i < number_of_queues; i++) {
  312. reg_val = IXGBE_READ_REG(hw, IXGBE_TXDCTL(i));
  313. if (reg_val & IXGBE_TXDCTL_ENABLE) {
  314. reg_val &= ~IXGBE_TXDCTL_ENABLE;
  315. IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(i), reg_val);
  316. }
  317. }
  318. /*
  319. * Prevent the PCI-E bus from from hanging by disabling PCI-E master
  320. * access and verify no pending requests
  321. */
  322. if (ixgbe_disable_pcie_master(hw) != 0)
  323. hw_dbg(hw, "PCI-E Master disable polling has failed.\n");
  324. return 0;
  325. }
  326. /**
  327. * ixgbe_led_on_generic - Turns on the software controllable LEDs.
  328. * @hw: pointer to hardware structure
  329. * @index: led number to turn on
  330. **/
  331. s32 ixgbe_led_on_generic(struct ixgbe_hw *hw, u32 index)
  332. {
  333. u32 led_reg = IXGBE_READ_REG(hw, IXGBE_LEDCTL);
  334. /* To turn on the LED, set mode to ON. */
  335. led_reg &= ~IXGBE_LED_MODE_MASK(index);
  336. led_reg |= IXGBE_LED_ON << IXGBE_LED_MODE_SHIFT(index);
  337. IXGBE_WRITE_REG(hw, IXGBE_LEDCTL, led_reg);
  338. IXGBE_WRITE_FLUSH(hw);
  339. return 0;
  340. }
  341. /**
  342. * ixgbe_led_off_generic - Turns off the software controllable LEDs.
  343. * @hw: pointer to hardware structure
  344. * @index: led number to turn off
  345. **/
  346. s32 ixgbe_led_off_generic(struct ixgbe_hw *hw, u32 index)
  347. {
  348. u32 led_reg = IXGBE_READ_REG(hw, IXGBE_LEDCTL);
  349. /* To turn off the LED, set mode to OFF. */
  350. led_reg &= ~IXGBE_LED_MODE_MASK(index);
  351. led_reg |= IXGBE_LED_OFF << IXGBE_LED_MODE_SHIFT(index);
  352. IXGBE_WRITE_REG(hw, IXGBE_LEDCTL, led_reg);
  353. IXGBE_WRITE_FLUSH(hw);
  354. return 0;
  355. }
  356. /**
  357. * ixgbe_init_eeprom_params_generic - Initialize EEPROM params
  358. * @hw: pointer to hardware structure
  359. *
  360. * Initializes the EEPROM parameters ixgbe_eeprom_info within the
  361. * ixgbe_hw struct in order to set up EEPROM access.
  362. **/
  363. s32 ixgbe_init_eeprom_params_generic(struct ixgbe_hw *hw)
  364. {
  365. struct ixgbe_eeprom_info *eeprom = &hw->eeprom;
  366. u32 eec;
  367. u16 eeprom_size;
  368. if (eeprom->type == ixgbe_eeprom_uninitialized) {
  369. eeprom->type = ixgbe_eeprom_none;
  370. /* Set default semaphore delay to 10ms which is a well
  371. * tested value */
  372. eeprom->semaphore_delay = 10;
  373. /*
  374. * Check for EEPROM present first.
  375. * If not present leave as none
  376. */
  377. eec = IXGBE_READ_REG(hw, IXGBE_EEC);
  378. if (eec & IXGBE_EEC_PRES) {
  379. eeprom->type = ixgbe_eeprom_spi;
  380. /*
  381. * SPI EEPROM is assumed here. This code would need to
  382. * change if a future EEPROM is not SPI.
  383. */
  384. eeprom_size = (u16)((eec & IXGBE_EEC_SIZE) >>
  385. IXGBE_EEC_SIZE_SHIFT);
  386. eeprom->word_size = 1 << (eeprom_size +
  387. IXGBE_EEPROM_WORD_SIZE_SHIFT);
  388. }
  389. if (eec & IXGBE_EEC_ADDR_SIZE)
  390. eeprom->address_bits = 16;
  391. else
  392. eeprom->address_bits = 8;
  393. hw_dbg(hw, "Eeprom params: type = %d, size = %d, address bits: "
  394. "%d\n", eeprom->type, eeprom->word_size,
  395. eeprom->address_bits);
  396. }
  397. return 0;
  398. }
  399. /**
  400. * ixgbe_write_eeprom_generic - Writes 16 bit value to EEPROM
  401. * @hw: pointer to hardware structure
  402. * @offset: offset within the EEPROM to be written to
  403. * @data: 16 bit word to be written to the EEPROM
  404. *
  405. * If ixgbe_eeprom_update_checksum is not called after this function, the
  406. * EEPROM will most likely contain an invalid checksum.
  407. **/
  408. s32 ixgbe_write_eeprom_generic(struct ixgbe_hw *hw, u16 offset, u16 data)
  409. {
  410. s32 status;
  411. u8 write_opcode = IXGBE_EEPROM_WRITE_OPCODE_SPI;
  412. hw->eeprom.ops.init_params(hw);
  413. if (offset >= hw->eeprom.word_size) {
  414. status = IXGBE_ERR_EEPROM;
  415. goto out;
  416. }
  417. /* Prepare the EEPROM for writing */
  418. status = ixgbe_acquire_eeprom(hw);
  419. if (status == 0) {
  420. if (ixgbe_ready_eeprom(hw) != 0) {
  421. ixgbe_release_eeprom(hw);
  422. status = IXGBE_ERR_EEPROM;
  423. }
  424. }
  425. if (status == 0) {
  426. ixgbe_standby_eeprom(hw);
  427. /* Send the WRITE ENABLE command (8 bit opcode ) */
  428. ixgbe_shift_out_eeprom_bits(hw, IXGBE_EEPROM_WREN_OPCODE_SPI,
  429. IXGBE_EEPROM_OPCODE_BITS);
  430. ixgbe_standby_eeprom(hw);
  431. /*
  432. * Some SPI eeproms use the 8th address bit embedded in the
  433. * opcode
  434. */
  435. if ((hw->eeprom.address_bits == 8) && (offset >= 128))
  436. write_opcode |= IXGBE_EEPROM_A8_OPCODE_SPI;
  437. /* Send the Write command (8-bit opcode + addr) */
  438. ixgbe_shift_out_eeprom_bits(hw, write_opcode,
  439. IXGBE_EEPROM_OPCODE_BITS);
  440. ixgbe_shift_out_eeprom_bits(hw, (u16)(offset*2),
  441. hw->eeprom.address_bits);
  442. /* Send the data */
  443. data = (data >> 8) | (data << 8);
  444. ixgbe_shift_out_eeprom_bits(hw, data, 16);
  445. ixgbe_standby_eeprom(hw);
  446. msleep(hw->eeprom.semaphore_delay);
  447. /* Done with writing - release the EEPROM */
  448. ixgbe_release_eeprom(hw);
  449. }
  450. out:
  451. return status;
  452. }
  453. /**
  454. * ixgbe_read_eeprom_bit_bang_generic - Read EEPROM word using bit-bang
  455. * @hw: pointer to hardware structure
  456. * @offset: offset within the EEPROM to be read
  457. * @data: read 16 bit value from EEPROM
  458. *
  459. * Reads 16 bit value from EEPROM through bit-bang method
  460. **/
  461. s32 ixgbe_read_eeprom_bit_bang_generic(struct ixgbe_hw *hw, u16 offset,
  462. u16 *data)
  463. {
  464. s32 status;
  465. u16 word_in;
  466. u8 read_opcode = IXGBE_EEPROM_READ_OPCODE_SPI;
  467. hw->eeprom.ops.init_params(hw);
  468. if (offset >= hw->eeprom.word_size) {
  469. status = IXGBE_ERR_EEPROM;
  470. goto out;
  471. }
  472. /* Prepare the EEPROM for reading */
  473. status = ixgbe_acquire_eeprom(hw);
  474. if (status == 0) {
  475. if (ixgbe_ready_eeprom(hw) != 0) {
  476. ixgbe_release_eeprom(hw);
  477. status = IXGBE_ERR_EEPROM;
  478. }
  479. }
  480. if (status == 0) {
  481. ixgbe_standby_eeprom(hw);
  482. /*
  483. * Some SPI eeproms use the 8th address bit embedded in the
  484. * opcode
  485. */
  486. if ((hw->eeprom.address_bits == 8) && (offset >= 128))
  487. read_opcode |= IXGBE_EEPROM_A8_OPCODE_SPI;
  488. /* Send the READ command (opcode + addr) */
  489. ixgbe_shift_out_eeprom_bits(hw, read_opcode,
  490. IXGBE_EEPROM_OPCODE_BITS);
  491. ixgbe_shift_out_eeprom_bits(hw, (u16)(offset*2),
  492. hw->eeprom.address_bits);
  493. /* Read the data. */
  494. word_in = ixgbe_shift_in_eeprom_bits(hw, 16);
  495. *data = (word_in >> 8) | (word_in << 8);
  496. /* End this read operation */
  497. ixgbe_release_eeprom(hw);
  498. }
  499. out:
  500. return status;
  501. }
  502. /**
  503. * ixgbe_read_eerd_generic - Read EEPROM word using EERD
  504. * @hw: pointer to hardware structure
  505. * @offset: offset of word in the EEPROM to read
  506. * @data: word read from the EEPROM
  507. *
  508. * Reads a 16 bit word from the EEPROM using the EERD register.
  509. **/
  510. s32 ixgbe_read_eerd_generic(struct ixgbe_hw *hw, u16 offset, u16 *data)
  511. {
  512. u32 eerd;
  513. s32 status;
  514. hw->eeprom.ops.init_params(hw);
  515. if (offset >= hw->eeprom.word_size) {
  516. status = IXGBE_ERR_EEPROM;
  517. goto out;
  518. }
  519. eerd = (offset << IXGBE_EEPROM_RW_ADDR_SHIFT) +
  520. IXGBE_EEPROM_RW_REG_START;
  521. IXGBE_WRITE_REG(hw, IXGBE_EERD, eerd);
  522. status = ixgbe_poll_eerd_eewr_done(hw, IXGBE_NVM_POLL_READ);
  523. if (status == 0)
  524. *data = (IXGBE_READ_REG(hw, IXGBE_EERD) >>
  525. IXGBE_EEPROM_RW_REG_DATA);
  526. else
  527. hw_dbg(hw, "Eeprom read timed out\n");
  528. out:
  529. return status;
  530. }
  531. /**
  532. * ixgbe_poll_eerd_eewr_done - Poll EERD read or EEWR write status
  533. * @hw: pointer to hardware structure
  534. * @ee_reg: EEPROM flag for polling
  535. *
  536. * Polls the status bit (bit 1) of the EERD or EEWR to determine when the
  537. * read or write is done respectively.
  538. **/
  539. s32 ixgbe_poll_eerd_eewr_done(struct ixgbe_hw *hw, u32 ee_reg)
  540. {
  541. u32 i;
  542. u32 reg;
  543. s32 status = IXGBE_ERR_EEPROM;
  544. for (i = 0; i < IXGBE_EERD_EEWR_ATTEMPTS; i++) {
  545. if (ee_reg == IXGBE_NVM_POLL_READ)
  546. reg = IXGBE_READ_REG(hw, IXGBE_EERD);
  547. else
  548. reg = IXGBE_READ_REG(hw, IXGBE_EEWR);
  549. if (reg & IXGBE_EEPROM_RW_REG_DONE) {
  550. status = 0;
  551. break;
  552. }
  553. udelay(5);
  554. }
  555. return status;
  556. }
  557. /**
  558. * ixgbe_acquire_eeprom - Acquire EEPROM using bit-bang
  559. * @hw: pointer to hardware structure
  560. *
  561. * Prepares EEPROM for access using bit-bang method. This function should
  562. * be called before issuing a command to the EEPROM.
  563. **/
  564. static s32 ixgbe_acquire_eeprom(struct ixgbe_hw *hw)
  565. {
  566. s32 status = 0;
  567. u32 eec = 0;
  568. u32 i;
  569. if (ixgbe_acquire_swfw_sync(hw, IXGBE_GSSR_EEP_SM) != 0)
  570. status = IXGBE_ERR_SWFW_SYNC;
  571. if (status == 0) {
  572. eec = IXGBE_READ_REG(hw, IXGBE_EEC);
  573. /* Request EEPROM Access */
  574. eec |= IXGBE_EEC_REQ;
  575. IXGBE_WRITE_REG(hw, IXGBE_EEC, eec);
  576. for (i = 0; i < IXGBE_EEPROM_GRANT_ATTEMPTS; i++) {
  577. eec = IXGBE_READ_REG(hw, IXGBE_EEC);
  578. if (eec & IXGBE_EEC_GNT)
  579. break;
  580. udelay(5);
  581. }
  582. /* Release if grant not acquired */
  583. if (!(eec & IXGBE_EEC_GNT)) {
  584. eec &= ~IXGBE_EEC_REQ;
  585. IXGBE_WRITE_REG(hw, IXGBE_EEC, eec);
  586. hw_dbg(hw, "Could not acquire EEPROM grant\n");
  587. ixgbe_release_swfw_sync(hw, IXGBE_GSSR_EEP_SM);
  588. status = IXGBE_ERR_EEPROM;
  589. }
  590. }
  591. /* Setup EEPROM for Read/Write */
  592. if (status == 0) {
  593. /* Clear CS and SK */
  594. eec &= ~(IXGBE_EEC_CS | IXGBE_EEC_SK);
  595. IXGBE_WRITE_REG(hw, IXGBE_EEC, eec);
  596. IXGBE_WRITE_FLUSH(hw);
  597. udelay(1);
  598. }
  599. return status;
  600. }
  601. /**
  602. * ixgbe_get_eeprom_semaphore - Get hardware semaphore
  603. * @hw: pointer to hardware structure
  604. *
  605. * Sets the hardware semaphores so EEPROM access can occur for bit-bang method
  606. **/
  607. static s32 ixgbe_get_eeprom_semaphore(struct ixgbe_hw *hw)
  608. {
  609. s32 status = IXGBE_ERR_EEPROM;
  610. u32 timeout;
  611. u32 i;
  612. u32 swsm;
  613. /* Set timeout value based on size of EEPROM */
  614. timeout = hw->eeprom.word_size + 1;
  615. /* Get SMBI software semaphore between device drivers first */
  616. for (i = 0; i < timeout; i++) {
  617. /*
  618. * If the SMBI bit is 0 when we read it, then the bit will be
  619. * set and we have the semaphore
  620. */
  621. swsm = IXGBE_READ_REG(hw, IXGBE_SWSM);
  622. if (!(swsm & IXGBE_SWSM_SMBI)) {
  623. status = 0;
  624. break;
  625. }
  626. msleep(1);
  627. }
  628. /* Now get the semaphore between SW/FW through the SWESMBI bit */
  629. if (status == 0) {
  630. for (i = 0; i < timeout; i++) {
  631. swsm = IXGBE_READ_REG(hw, IXGBE_SWSM);
  632. /* Set the SW EEPROM semaphore bit to request access */
  633. swsm |= IXGBE_SWSM_SWESMBI;
  634. IXGBE_WRITE_REG(hw, IXGBE_SWSM, swsm);
  635. /*
  636. * If we set the bit successfully then we got the
  637. * semaphore.
  638. */
  639. swsm = IXGBE_READ_REG(hw, IXGBE_SWSM);
  640. if (swsm & IXGBE_SWSM_SWESMBI)
  641. break;
  642. udelay(50);
  643. }
  644. /*
  645. * Release semaphores and return error if SW EEPROM semaphore
  646. * was not granted because we don't have access to the EEPROM
  647. */
  648. if (i >= timeout) {
  649. hw_dbg(hw, "Driver can't access the Eeprom - Semaphore "
  650. "not granted.\n");
  651. ixgbe_release_eeprom_semaphore(hw);
  652. status = IXGBE_ERR_EEPROM;
  653. }
  654. }
  655. return status;
  656. }
  657. /**
  658. * ixgbe_release_eeprom_semaphore - Release hardware semaphore
  659. * @hw: pointer to hardware structure
  660. *
  661. * This function clears hardware semaphore bits.
  662. **/
  663. static void ixgbe_release_eeprom_semaphore(struct ixgbe_hw *hw)
  664. {
  665. u32 swsm;
  666. swsm = IXGBE_READ_REG(hw, IXGBE_SWSM);
  667. /* Release both semaphores by writing 0 to the bits SWESMBI and SMBI */
  668. swsm &= ~(IXGBE_SWSM_SWESMBI | IXGBE_SWSM_SMBI);
  669. IXGBE_WRITE_REG(hw, IXGBE_SWSM, swsm);
  670. IXGBE_WRITE_FLUSH(hw);
  671. }
  672. /**
  673. * ixgbe_ready_eeprom - Polls for EEPROM ready
  674. * @hw: pointer to hardware structure
  675. **/
  676. static s32 ixgbe_ready_eeprom(struct ixgbe_hw *hw)
  677. {
  678. s32 status = 0;
  679. u16 i;
  680. u8 spi_stat_reg;
  681. /*
  682. * Read "Status Register" repeatedly until the LSB is cleared. The
  683. * EEPROM will signal that the command has been completed by clearing
  684. * bit 0 of the internal status register. If it's not cleared within
  685. * 5 milliseconds, then error out.
  686. */
  687. for (i = 0; i < IXGBE_EEPROM_MAX_RETRY_SPI; i += 5) {
  688. ixgbe_shift_out_eeprom_bits(hw, IXGBE_EEPROM_RDSR_OPCODE_SPI,
  689. IXGBE_EEPROM_OPCODE_BITS);
  690. spi_stat_reg = (u8)ixgbe_shift_in_eeprom_bits(hw, 8);
  691. if (!(spi_stat_reg & IXGBE_EEPROM_STATUS_RDY_SPI))
  692. break;
  693. udelay(5);
  694. ixgbe_standby_eeprom(hw);
  695. };
  696. /*
  697. * On some parts, SPI write time could vary from 0-20mSec on 3.3V
  698. * devices (and only 0-5mSec on 5V devices)
  699. */
  700. if (i >= IXGBE_EEPROM_MAX_RETRY_SPI) {
  701. hw_dbg(hw, "SPI EEPROM Status error\n");
  702. status = IXGBE_ERR_EEPROM;
  703. }
  704. return status;
  705. }
  706. /**
  707. * ixgbe_standby_eeprom - Returns EEPROM to a "standby" state
  708. * @hw: pointer to hardware structure
  709. **/
  710. static void ixgbe_standby_eeprom(struct ixgbe_hw *hw)
  711. {
  712. u32 eec;
  713. eec = IXGBE_READ_REG(hw, IXGBE_EEC);
  714. /* Toggle CS to flush commands */
  715. eec |= IXGBE_EEC_CS;
  716. IXGBE_WRITE_REG(hw, IXGBE_EEC, eec);
  717. IXGBE_WRITE_FLUSH(hw);
  718. udelay(1);
  719. eec &= ~IXGBE_EEC_CS;
  720. IXGBE_WRITE_REG(hw, IXGBE_EEC, eec);
  721. IXGBE_WRITE_FLUSH(hw);
  722. udelay(1);
  723. }
  724. /**
  725. * ixgbe_shift_out_eeprom_bits - Shift data bits out to the EEPROM.
  726. * @hw: pointer to hardware structure
  727. * @data: data to send to the EEPROM
  728. * @count: number of bits to shift out
  729. **/
  730. static void ixgbe_shift_out_eeprom_bits(struct ixgbe_hw *hw, u16 data,
  731. u16 count)
  732. {
  733. u32 eec;
  734. u32 mask;
  735. u32 i;
  736. eec = IXGBE_READ_REG(hw, IXGBE_EEC);
  737. /*
  738. * Mask is used to shift "count" bits of "data" out to the EEPROM
  739. * one bit at a time. Determine the starting bit based on count
  740. */
  741. mask = 0x01 << (count - 1);
  742. for (i = 0; i < count; i++) {
  743. /*
  744. * A "1" is shifted out to the EEPROM by setting bit "DI" to a
  745. * "1", and then raising and then lowering the clock (the SK
  746. * bit controls the clock input to the EEPROM). A "0" is
  747. * shifted out to the EEPROM by setting "DI" to "0" and then
  748. * raising and then lowering the clock.
  749. */
  750. if (data & mask)
  751. eec |= IXGBE_EEC_DI;
  752. else
  753. eec &= ~IXGBE_EEC_DI;
  754. IXGBE_WRITE_REG(hw, IXGBE_EEC, eec);
  755. IXGBE_WRITE_FLUSH(hw);
  756. udelay(1);
  757. ixgbe_raise_eeprom_clk(hw, &eec);
  758. ixgbe_lower_eeprom_clk(hw, &eec);
  759. /*
  760. * Shift mask to signify next bit of data to shift in to the
  761. * EEPROM
  762. */
  763. mask = mask >> 1;
  764. };
  765. /* We leave the "DI" bit set to "0" when we leave this routine. */
  766. eec &= ~IXGBE_EEC_DI;
  767. IXGBE_WRITE_REG(hw, IXGBE_EEC, eec);
  768. IXGBE_WRITE_FLUSH(hw);
  769. }
  770. /**
  771. * ixgbe_shift_in_eeprom_bits - Shift data bits in from the EEPROM
  772. * @hw: pointer to hardware structure
  773. **/
  774. static u16 ixgbe_shift_in_eeprom_bits(struct ixgbe_hw *hw, u16 count)
  775. {
  776. u32 eec;
  777. u32 i;
  778. u16 data = 0;
  779. /*
  780. * In order to read a register from the EEPROM, we need to shift
  781. * 'count' bits in from the EEPROM. Bits are "shifted in" by raising
  782. * the clock input to the EEPROM (setting the SK bit), and then reading
  783. * the value of the "DO" bit. During this "shifting in" process the
  784. * "DI" bit should always be clear.
  785. */
  786. eec = IXGBE_READ_REG(hw, IXGBE_EEC);
  787. eec &= ~(IXGBE_EEC_DO | IXGBE_EEC_DI);
  788. for (i = 0; i < count; i++) {
  789. data = data << 1;
  790. ixgbe_raise_eeprom_clk(hw, &eec);
  791. eec = IXGBE_READ_REG(hw, IXGBE_EEC);
  792. eec &= ~(IXGBE_EEC_DI);
  793. if (eec & IXGBE_EEC_DO)
  794. data |= 1;
  795. ixgbe_lower_eeprom_clk(hw, &eec);
  796. }
  797. return data;
  798. }
  799. /**
  800. * ixgbe_raise_eeprom_clk - Raises the EEPROM's clock input.
  801. * @hw: pointer to hardware structure
  802. * @eec: EEC register's current value
  803. **/
  804. static void ixgbe_raise_eeprom_clk(struct ixgbe_hw *hw, u32 *eec)
  805. {
  806. /*
  807. * Raise the clock input to the EEPROM
  808. * (setting the SK bit), then delay
  809. */
  810. *eec = *eec | IXGBE_EEC_SK;
  811. IXGBE_WRITE_REG(hw, IXGBE_EEC, *eec);
  812. IXGBE_WRITE_FLUSH(hw);
  813. udelay(1);
  814. }
  815. /**
  816. * ixgbe_lower_eeprom_clk - Lowers the EEPROM's clock input.
  817. * @hw: pointer to hardware structure
  818. * @eecd: EECD's current value
  819. **/
  820. static void ixgbe_lower_eeprom_clk(struct ixgbe_hw *hw, u32 *eec)
  821. {
  822. /*
  823. * Lower the clock input to the EEPROM (clearing the SK bit), then
  824. * delay
  825. */
  826. *eec = *eec & ~IXGBE_EEC_SK;
  827. IXGBE_WRITE_REG(hw, IXGBE_EEC, *eec);
  828. IXGBE_WRITE_FLUSH(hw);
  829. udelay(1);
  830. }
  831. /**
  832. * ixgbe_release_eeprom - Release EEPROM, release semaphores
  833. * @hw: pointer to hardware structure
  834. **/
  835. static void ixgbe_release_eeprom(struct ixgbe_hw *hw)
  836. {
  837. u32 eec;
  838. eec = IXGBE_READ_REG(hw, IXGBE_EEC);
  839. eec |= IXGBE_EEC_CS; /* Pull CS high */
  840. eec &= ~IXGBE_EEC_SK; /* Lower SCK */
  841. IXGBE_WRITE_REG(hw, IXGBE_EEC, eec);
  842. IXGBE_WRITE_FLUSH(hw);
  843. udelay(1);
  844. /* Stop requesting EEPROM access */
  845. eec &= ~IXGBE_EEC_REQ;
  846. IXGBE_WRITE_REG(hw, IXGBE_EEC, eec);
  847. ixgbe_release_swfw_sync(hw, IXGBE_GSSR_EEP_SM);
  848. }
  849. /**
  850. * ixgbe_calc_eeprom_checksum - Calculates and returns the checksum
  851. * @hw: pointer to hardware structure
  852. **/
  853. static u16 ixgbe_calc_eeprom_checksum(struct ixgbe_hw *hw)
  854. {
  855. u16 i;
  856. u16 j;
  857. u16 checksum = 0;
  858. u16 length = 0;
  859. u16 pointer = 0;
  860. u16 word = 0;
  861. /* Include 0x0-0x3F in the checksum */
  862. for (i = 0; i < IXGBE_EEPROM_CHECKSUM; i++) {
  863. if (hw->eeprom.ops.read(hw, i, &word) != 0) {
  864. hw_dbg(hw, "EEPROM read failed\n");
  865. break;
  866. }
  867. checksum += word;
  868. }
  869. /* Include all data from pointers except for the fw pointer */
  870. for (i = IXGBE_PCIE_ANALOG_PTR; i < IXGBE_FW_PTR; i++) {
  871. hw->eeprom.ops.read(hw, i, &pointer);
  872. /* Make sure the pointer seems valid */
  873. if (pointer != 0xFFFF && pointer != 0) {
  874. hw->eeprom.ops.read(hw, pointer, &length);
  875. if (length != 0xFFFF && length != 0) {
  876. for (j = pointer+1; j <= pointer+length; j++) {
  877. hw->eeprom.ops.read(hw, j, &word);
  878. checksum += word;
  879. }
  880. }
  881. }
  882. }
  883. checksum = (u16)IXGBE_EEPROM_SUM - checksum;
  884. return checksum;
  885. }
  886. /**
  887. * ixgbe_validate_eeprom_checksum_generic - Validate EEPROM checksum
  888. * @hw: pointer to hardware structure
  889. * @checksum_val: calculated checksum
  890. *
  891. * Performs checksum calculation and validates the EEPROM checksum. If the
  892. * caller does not need checksum_val, the value can be NULL.
  893. **/
  894. s32 ixgbe_validate_eeprom_checksum_generic(struct ixgbe_hw *hw,
  895. u16 *checksum_val)
  896. {
  897. s32 status;
  898. u16 checksum;
  899. u16 read_checksum = 0;
  900. /*
  901. * Read the first word from the EEPROM. If this times out or fails, do
  902. * not continue or we could be in for a very long wait while every
  903. * EEPROM read fails
  904. */
  905. status = hw->eeprom.ops.read(hw, 0, &checksum);
  906. if (status == 0) {
  907. checksum = ixgbe_calc_eeprom_checksum(hw);
  908. hw->eeprom.ops.read(hw, IXGBE_EEPROM_CHECKSUM, &read_checksum);
  909. /*
  910. * Verify read checksum from EEPROM is the same as
  911. * calculated checksum
  912. */
  913. if (read_checksum != checksum)
  914. status = IXGBE_ERR_EEPROM_CHECKSUM;
  915. /* If the user cares, return the calculated checksum */
  916. if (checksum_val)
  917. *checksum_val = checksum;
  918. } else {
  919. hw_dbg(hw, "EEPROM read failed\n");
  920. }
  921. return status;
  922. }
  923. /**
  924. * ixgbe_update_eeprom_checksum_generic - Updates the EEPROM checksum
  925. * @hw: pointer to hardware structure
  926. **/
  927. s32 ixgbe_update_eeprom_checksum_generic(struct ixgbe_hw *hw)
  928. {
  929. s32 status;
  930. u16 checksum;
  931. /*
  932. * Read the first word from the EEPROM. If this times out or fails, do
  933. * not continue or we could be in for a very long wait while every
  934. * EEPROM read fails
  935. */
  936. status = hw->eeprom.ops.read(hw, 0, &checksum);
  937. if (status == 0) {
  938. checksum = ixgbe_calc_eeprom_checksum(hw);
  939. status = hw->eeprom.ops.write(hw, IXGBE_EEPROM_CHECKSUM,
  940. checksum);
  941. } else {
  942. hw_dbg(hw, "EEPROM read failed\n");
  943. }
  944. return status;
  945. }
  946. /**
  947. * ixgbe_validate_mac_addr - Validate MAC address
  948. * @mac_addr: pointer to MAC address.
  949. *
  950. * Tests a MAC address to ensure it is a valid Individual Address
  951. **/
  952. s32 ixgbe_validate_mac_addr(u8 *mac_addr)
  953. {
  954. s32 status = 0;
  955. /* Make sure it is not a multicast address */
  956. if (IXGBE_IS_MULTICAST(mac_addr))
  957. status = IXGBE_ERR_INVALID_MAC_ADDR;
  958. /* Not a broadcast address */
  959. else if (IXGBE_IS_BROADCAST(mac_addr))
  960. status = IXGBE_ERR_INVALID_MAC_ADDR;
  961. /* Reject the zero address */
  962. else if (mac_addr[0] == 0 && mac_addr[1] == 0 && mac_addr[2] == 0 &&
  963. mac_addr[3] == 0 && mac_addr[4] == 0 && mac_addr[5] == 0)
  964. status = IXGBE_ERR_INVALID_MAC_ADDR;
  965. return status;
  966. }
  967. /**
  968. * ixgbe_set_rar_generic - Set Rx address register
  969. * @hw: pointer to hardware structure
  970. * @index: Receive address register to write
  971. * @addr: Address to put into receive address register
  972. * @vmdq: VMDq "set" or "pool" index
  973. * @enable_addr: set flag that address is active
  974. *
  975. * Puts an ethernet address into a receive address register.
  976. **/
  977. s32 ixgbe_set_rar_generic(struct ixgbe_hw *hw, u32 index, u8 *addr, u32 vmdq,
  978. u32 enable_addr)
  979. {
  980. u32 rar_low, rar_high;
  981. u32 rar_entries = hw->mac.num_rar_entries;
  982. /* setup VMDq pool selection before this RAR gets enabled */
  983. hw->mac.ops.set_vmdq(hw, index, vmdq);
  984. /* Make sure we are using a valid rar index range */
  985. if (index < rar_entries) {
  986. /*
  987. * HW expects these in little endian so we reverse the byte
  988. * order from network order (big endian) to little endian
  989. */
  990. rar_low = ((u32)addr[0] |
  991. ((u32)addr[1] << 8) |
  992. ((u32)addr[2] << 16) |
  993. ((u32)addr[3] << 24));
  994. /*
  995. * Some parts put the VMDq setting in the extra RAH bits,
  996. * so save everything except the lower 16 bits that hold part
  997. * of the address and the address valid bit.
  998. */
  999. rar_high = IXGBE_READ_REG(hw, IXGBE_RAH(index));
  1000. rar_high &= ~(0x0000FFFF | IXGBE_RAH_AV);
  1001. rar_high |= ((u32)addr[4] | ((u32)addr[5] << 8));
  1002. if (enable_addr != 0)
  1003. rar_high |= IXGBE_RAH_AV;
  1004. IXGBE_WRITE_REG(hw, IXGBE_RAL(index), rar_low);
  1005. IXGBE_WRITE_REG(hw, IXGBE_RAH(index), rar_high);
  1006. } else {
  1007. hw_dbg(hw, "RAR index %d is out of range.\n", index);
  1008. return IXGBE_ERR_RAR_INDEX;
  1009. }
  1010. return 0;
  1011. }
  1012. /**
  1013. * ixgbe_clear_rar_generic - Remove Rx address register
  1014. * @hw: pointer to hardware structure
  1015. * @index: Receive address register to write
  1016. *
  1017. * Clears an ethernet address from a receive address register.
  1018. **/
  1019. s32 ixgbe_clear_rar_generic(struct ixgbe_hw *hw, u32 index)
  1020. {
  1021. u32 rar_high;
  1022. u32 rar_entries = hw->mac.num_rar_entries;
  1023. /* Make sure we are using a valid rar index range */
  1024. if (index < rar_entries) {
  1025. /*
  1026. * Some parts put the VMDq setting in the extra RAH bits,
  1027. * so save everything except the lower 16 bits that hold part
  1028. * of the address and the address valid bit.
  1029. */
  1030. rar_high = IXGBE_READ_REG(hw, IXGBE_RAH(index));
  1031. rar_high &= ~(0x0000FFFF | IXGBE_RAH_AV);
  1032. IXGBE_WRITE_REG(hw, IXGBE_RAL(index), 0);
  1033. IXGBE_WRITE_REG(hw, IXGBE_RAH(index), rar_high);
  1034. } else {
  1035. hw_dbg(hw, "RAR index %d is out of range.\n", index);
  1036. return IXGBE_ERR_RAR_INDEX;
  1037. }
  1038. /* clear VMDq pool/queue selection for this RAR */
  1039. hw->mac.ops.clear_vmdq(hw, index, IXGBE_CLEAR_VMDQ_ALL);
  1040. return 0;
  1041. }
  1042. /**
  1043. * ixgbe_enable_rar - Enable Rx address register
  1044. * @hw: pointer to hardware structure
  1045. * @index: index into the RAR table
  1046. *
  1047. * Enables the select receive address register.
  1048. **/
  1049. static void ixgbe_enable_rar(struct ixgbe_hw *hw, u32 index)
  1050. {
  1051. u32 rar_high;
  1052. rar_high = IXGBE_READ_REG(hw, IXGBE_RAH(index));
  1053. rar_high |= IXGBE_RAH_AV;
  1054. IXGBE_WRITE_REG(hw, IXGBE_RAH(index), rar_high);
  1055. }
  1056. /**
  1057. * ixgbe_disable_rar - Disable Rx address register
  1058. * @hw: pointer to hardware structure
  1059. * @index: index into the RAR table
  1060. *
  1061. * Disables the select receive address register.
  1062. **/
  1063. static void ixgbe_disable_rar(struct ixgbe_hw *hw, u32 index)
  1064. {
  1065. u32 rar_high;
  1066. rar_high = IXGBE_READ_REG(hw, IXGBE_RAH(index));
  1067. rar_high &= (~IXGBE_RAH_AV);
  1068. IXGBE_WRITE_REG(hw, IXGBE_RAH(index), rar_high);
  1069. }
  1070. /**
  1071. * ixgbe_init_rx_addrs_generic - Initializes receive address filters.
  1072. * @hw: pointer to hardware structure
  1073. *
  1074. * Places the MAC address in receive address register 0 and clears the rest
  1075. * of the receive address registers. Clears the multicast table. Assumes
  1076. * the receiver is in reset when the routine is called.
  1077. **/
  1078. s32 ixgbe_init_rx_addrs_generic(struct ixgbe_hw *hw)
  1079. {
  1080. u32 i;
  1081. u32 rar_entries = hw->mac.num_rar_entries;
  1082. /*
  1083. * If the current mac address is valid, assume it is a software override
  1084. * to the permanent address.
  1085. * Otherwise, use the permanent address from the eeprom.
  1086. */
  1087. if (ixgbe_validate_mac_addr(hw->mac.addr) ==
  1088. IXGBE_ERR_INVALID_MAC_ADDR) {
  1089. /* Get the MAC address from the RAR0 for later reference */
  1090. hw->mac.ops.get_mac_addr(hw, hw->mac.addr);
  1091. hw_dbg(hw, " Keeping Current RAR0 Addr =%pM\n", hw->mac.addr);
  1092. } else {
  1093. /* Setup the receive address. */
  1094. hw_dbg(hw, "Overriding MAC Address in RAR[0]\n");
  1095. hw_dbg(hw, " New MAC Addr =%pM\n", hw->mac.addr);
  1096. hw->mac.ops.set_rar(hw, 0, hw->mac.addr, 0, IXGBE_RAH_AV);
  1097. }
  1098. hw->addr_ctrl.overflow_promisc = 0;
  1099. hw->addr_ctrl.rar_used_count = 1;
  1100. /* Zero out the other receive addresses. */
  1101. hw_dbg(hw, "Clearing RAR[1-%d]\n", rar_entries - 1);
  1102. for (i = 1; i < rar_entries; i++) {
  1103. IXGBE_WRITE_REG(hw, IXGBE_RAL(i), 0);
  1104. IXGBE_WRITE_REG(hw, IXGBE_RAH(i), 0);
  1105. }
  1106. /* Clear the MTA */
  1107. hw->addr_ctrl.mc_addr_in_rar_count = 0;
  1108. hw->addr_ctrl.mta_in_use = 0;
  1109. IXGBE_WRITE_REG(hw, IXGBE_MCSTCTRL, hw->mac.mc_filter_type);
  1110. hw_dbg(hw, " Clearing MTA\n");
  1111. for (i = 0; i < hw->mac.mcft_size; i++)
  1112. IXGBE_WRITE_REG(hw, IXGBE_MTA(i), 0);
  1113. if (hw->mac.ops.init_uta_tables)
  1114. hw->mac.ops.init_uta_tables(hw);
  1115. return 0;
  1116. }
  1117. /**
  1118. * ixgbe_add_uc_addr - Adds a secondary unicast address.
  1119. * @hw: pointer to hardware structure
  1120. * @addr: new address
  1121. *
  1122. * Adds it to unused receive address register or goes into promiscuous mode.
  1123. **/
  1124. static void ixgbe_add_uc_addr(struct ixgbe_hw *hw, u8 *addr, u32 vmdq)
  1125. {
  1126. u32 rar_entries = hw->mac.num_rar_entries;
  1127. u32 rar;
  1128. hw_dbg(hw, " UC Addr = %.2X %.2X %.2X %.2X %.2X %.2X\n",
  1129. addr[0], addr[1], addr[2], addr[3], addr[4], addr[5]);
  1130. /*
  1131. * Place this address in the RAR if there is room,
  1132. * else put the controller into promiscuous mode
  1133. */
  1134. if (hw->addr_ctrl.rar_used_count < rar_entries) {
  1135. rar = hw->addr_ctrl.rar_used_count -
  1136. hw->addr_ctrl.mc_addr_in_rar_count;
  1137. hw->mac.ops.set_rar(hw, rar, addr, vmdq, IXGBE_RAH_AV);
  1138. hw_dbg(hw, "Added a secondary address to RAR[%d]\n", rar);
  1139. hw->addr_ctrl.rar_used_count++;
  1140. } else {
  1141. hw->addr_ctrl.overflow_promisc++;
  1142. }
  1143. hw_dbg(hw, "ixgbe_add_uc_addr Complete\n");
  1144. }
  1145. /**
  1146. * ixgbe_update_uc_addr_list_generic - Updates MAC list of secondary addresses
  1147. * @hw: pointer to hardware structure
  1148. * @netdev: pointer to net device structure
  1149. *
  1150. * The given list replaces any existing list. Clears the secondary addrs from
  1151. * receive address registers. Uses unused receive address registers for the
  1152. * first secondary addresses, and falls back to promiscuous mode as needed.
  1153. *
  1154. * Drivers using secondary unicast addresses must set user_set_promisc when
  1155. * manually putting the device into promiscuous mode.
  1156. **/
  1157. s32 ixgbe_update_uc_addr_list_generic(struct ixgbe_hw *hw,
  1158. struct net_device *netdev)
  1159. {
  1160. u32 i;
  1161. u32 old_promisc_setting = hw->addr_ctrl.overflow_promisc;
  1162. u32 uc_addr_in_use;
  1163. u32 fctrl;
  1164. struct netdev_hw_addr *ha;
  1165. /*
  1166. * Clear accounting of old secondary address list,
  1167. * don't count RAR[0]
  1168. */
  1169. uc_addr_in_use = hw->addr_ctrl.rar_used_count - 1;
  1170. hw->addr_ctrl.rar_used_count -= uc_addr_in_use;
  1171. hw->addr_ctrl.overflow_promisc = 0;
  1172. /* Zero out the other receive addresses */
  1173. hw_dbg(hw, "Clearing RAR[1-%d]\n", uc_addr_in_use + 1);
  1174. for (i = 0; i < uc_addr_in_use; i++) {
  1175. IXGBE_WRITE_REG(hw, IXGBE_RAL(1+i), 0);
  1176. IXGBE_WRITE_REG(hw, IXGBE_RAH(1+i), 0);
  1177. }
  1178. /* Add the new addresses */
  1179. netdev_for_each_uc_addr(ha, netdev) {
  1180. hw_dbg(hw, " Adding the secondary addresses:\n");
  1181. ixgbe_add_uc_addr(hw, ha->addr, 0);
  1182. }
  1183. if (hw->addr_ctrl.overflow_promisc) {
  1184. /* enable promisc if not already in overflow or set by user */
  1185. if (!old_promisc_setting && !hw->addr_ctrl.user_set_promisc) {
  1186. hw_dbg(hw, " Entering address overflow promisc mode\n");
  1187. fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
  1188. fctrl |= IXGBE_FCTRL_UPE;
  1189. IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl);
  1190. hw->addr_ctrl.uc_set_promisc = true;
  1191. }
  1192. } else {
  1193. /* only disable if set by overflow, not by user */
  1194. if ((old_promisc_setting && hw->addr_ctrl.uc_set_promisc) &&
  1195. !(hw->addr_ctrl.user_set_promisc)) {
  1196. hw_dbg(hw, " Leaving address overflow promisc mode\n");
  1197. fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
  1198. fctrl &= ~IXGBE_FCTRL_UPE;
  1199. IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl);
  1200. hw->addr_ctrl.uc_set_promisc = false;
  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. * @netdev: pointer to net device structure
  1277. *
  1278. * The given list replaces any existing list. Clears the MC addrs from receive
  1279. * address registers and the multicast table. Uses unused receive address
  1280. * registers for the first multicast addresses, and hashes the rest into the
  1281. * multicast table.
  1282. **/
  1283. s32 ixgbe_update_mc_addr_list_generic(struct ixgbe_hw *hw,
  1284. struct net_device *netdev)
  1285. {
  1286. struct netdev_hw_addr *ha;
  1287. u32 i;
  1288. /*
  1289. * Set the new number of MC addresses that we are being requested to
  1290. * use.
  1291. */
  1292. hw->addr_ctrl.num_mc_addrs = netdev_mc_count(netdev);
  1293. hw->addr_ctrl.mta_in_use = 0;
  1294. /* Clear the MTA */
  1295. hw_dbg(hw, " Clearing MTA\n");
  1296. for (i = 0; i < hw->mac.mcft_size; i++)
  1297. IXGBE_WRITE_REG(hw, IXGBE_MTA(i), 0);
  1298. /* Add the new addresses */
  1299. netdev_for_each_mc_addr(ha, netdev) {
  1300. hw_dbg(hw, " Adding the multicast addresses:\n");
  1301. ixgbe_set_mta(hw, ha->addr);
  1302. }
  1303. /* Enable mta */
  1304. if (hw->addr_ctrl.mta_in_use > 0)
  1305. IXGBE_WRITE_REG(hw, IXGBE_MCSTCTRL,
  1306. IXGBE_MCSTCTRL_MFE | hw->mac.mc_filter_type);
  1307. hw_dbg(hw, "ixgbe_update_mc_addr_list_generic Complete\n");
  1308. return 0;
  1309. }
  1310. /**
  1311. * ixgbe_enable_mc_generic - Enable multicast address in RAR
  1312. * @hw: pointer to hardware structure
  1313. *
  1314. * Enables multicast address in RAR and the use of the multicast hash table.
  1315. **/
  1316. s32 ixgbe_enable_mc_generic(struct ixgbe_hw *hw)
  1317. {
  1318. u32 i;
  1319. u32 rar_entries = hw->mac.num_rar_entries;
  1320. struct ixgbe_addr_filter_info *a = &hw->addr_ctrl;
  1321. if (a->mc_addr_in_rar_count > 0)
  1322. for (i = (rar_entries - a->mc_addr_in_rar_count);
  1323. i < rar_entries; i++)
  1324. ixgbe_enable_rar(hw, i);
  1325. if (a->mta_in_use > 0)
  1326. IXGBE_WRITE_REG(hw, IXGBE_MCSTCTRL, IXGBE_MCSTCTRL_MFE |
  1327. hw->mac.mc_filter_type);
  1328. return 0;
  1329. }
  1330. /**
  1331. * ixgbe_disable_mc_generic - Disable multicast address in RAR
  1332. * @hw: pointer to hardware structure
  1333. *
  1334. * Disables multicast address in RAR and the use of the multicast hash table.
  1335. **/
  1336. s32 ixgbe_disable_mc_generic(struct ixgbe_hw *hw)
  1337. {
  1338. u32 i;
  1339. u32 rar_entries = hw->mac.num_rar_entries;
  1340. struct ixgbe_addr_filter_info *a = &hw->addr_ctrl;
  1341. if (a->mc_addr_in_rar_count > 0)
  1342. for (i = (rar_entries - a->mc_addr_in_rar_count);
  1343. i < rar_entries; i++)
  1344. ixgbe_disable_rar(hw, i);
  1345. if (a->mta_in_use > 0)
  1346. IXGBE_WRITE_REG(hw, IXGBE_MCSTCTRL, hw->mac.mc_filter_type);
  1347. return 0;
  1348. }
  1349. /**
  1350. * ixgbe_fc_enable_generic - Enable flow control
  1351. * @hw: pointer to hardware structure
  1352. * @packetbuf_num: packet buffer number (0-7)
  1353. *
  1354. * Enable flow control according to the current settings.
  1355. **/
  1356. s32 ixgbe_fc_enable_generic(struct ixgbe_hw *hw, s32 packetbuf_num)
  1357. {
  1358. s32 ret_val = 0;
  1359. u32 mflcn_reg, fccfg_reg;
  1360. u32 reg;
  1361. u32 rx_pba_size;
  1362. #ifdef CONFIG_DCB
  1363. if (hw->fc.requested_mode == ixgbe_fc_pfc)
  1364. goto out;
  1365. #endif /* CONFIG_DCB */
  1366. /* Negotiate the fc mode to use */
  1367. ret_val = ixgbe_fc_autoneg(hw);
  1368. if (ret_val)
  1369. goto out;
  1370. /* Disable any previous flow control settings */
  1371. mflcn_reg = IXGBE_READ_REG(hw, IXGBE_MFLCN);
  1372. mflcn_reg &= ~(IXGBE_MFLCN_RFCE | IXGBE_MFLCN_RPFCE);
  1373. fccfg_reg = IXGBE_READ_REG(hw, IXGBE_FCCFG);
  1374. fccfg_reg &= ~(IXGBE_FCCFG_TFCE_802_3X | IXGBE_FCCFG_TFCE_PRIORITY);
  1375. /*
  1376. * The possible values of fc.current_mode are:
  1377. * 0: Flow control is completely disabled
  1378. * 1: Rx flow control is enabled (we can receive pause frames,
  1379. * but not send pause frames).
  1380. * 2: Tx flow control is enabled (we can send pause frames but
  1381. * we do not support receiving pause frames).
  1382. * 3: Both Rx and Tx flow control (symmetric) are enabled.
  1383. * 4: Priority Flow Control is enabled.
  1384. * other: Invalid.
  1385. */
  1386. switch (hw->fc.current_mode) {
  1387. case ixgbe_fc_none:
  1388. /*
  1389. * Flow control is disabled by software override or autoneg.
  1390. * The code below will actually disable it in the HW.
  1391. */
  1392. break;
  1393. case ixgbe_fc_rx_pause:
  1394. /*
  1395. * Rx Flow control is enabled and Tx Flow control is
  1396. * disabled by software override. Since there really
  1397. * isn't a way to advertise that we are capable of RX
  1398. * Pause ONLY, we will advertise that we support both
  1399. * symmetric and asymmetric Rx PAUSE. Later, we will
  1400. * disable the adapter's ability to send PAUSE frames.
  1401. */
  1402. mflcn_reg |= IXGBE_MFLCN_RFCE;
  1403. break;
  1404. case ixgbe_fc_tx_pause:
  1405. /*
  1406. * Tx Flow control is enabled, and Rx Flow control is
  1407. * disabled by software override.
  1408. */
  1409. fccfg_reg |= IXGBE_FCCFG_TFCE_802_3X;
  1410. break;
  1411. case ixgbe_fc_full:
  1412. /* Flow control (both Rx and Tx) is enabled by SW override. */
  1413. mflcn_reg |= IXGBE_MFLCN_RFCE;
  1414. fccfg_reg |= IXGBE_FCCFG_TFCE_802_3X;
  1415. break;
  1416. #ifdef CONFIG_DCB
  1417. case ixgbe_fc_pfc:
  1418. goto out;
  1419. break;
  1420. #endif /* CONFIG_DCB */
  1421. default:
  1422. hw_dbg(hw, "Flow control param set incorrectly\n");
  1423. ret_val = IXGBE_ERR_CONFIG;
  1424. goto out;
  1425. break;
  1426. }
  1427. /* Set 802.3x based flow control settings. */
  1428. mflcn_reg |= IXGBE_MFLCN_DPF;
  1429. IXGBE_WRITE_REG(hw, IXGBE_MFLCN, mflcn_reg);
  1430. IXGBE_WRITE_REG(hw, IXGBE_FCCFG, fccfg_reg);
  1431. reg = IXGBE_READ_REG(hw, IXGBE_MTQC);
  1432. /* Thresholds are different for link flow control when in DCB mode */
  1433. if (reg & IXGBE_MTQC_RT_ENA) {
  1434. rx_pba_size = IXGBE_READ_REG(hw, IXGBE_RXPBSIZE(packetbuf_num));
  1435. /* Always disable XON for LFC when in DCB mode */
  1436. reg = (rx_pba_size >> 5) & 0xFFE0;
  1437. IXGBE_WRITE_REG(hw, IXGBE_FCRTL_82599(packetbuf_num), reg);
  1438. reg = (rx_pba_size >> 2) & 0xFFE0;
  1439. if (hw->fc.current_mode & ixgbe_fc_tx_pause)
  1440. reg |= IXGBE_FCRTH_FCEN;
  1441. IXGBE_WRITE_REG(hw, IXGBE_FCRTH_82599(packetbuf_num), reg);
  1442. } else {
  1443. /*
  1444. * Set up and enable Rx high/low water mark thresholds,
  1445. * enable XON.
  1446. */
  1447. if (hw->fc.current_mode & ixgbe_fc_tx_pause) {
  1448. if (hw->fc.send_xon) {
  1449. IXGBE_WRITE_REG(hw,
  1450. IXGBE_FCRTL_82599(packetbuf_num),
  1451. (hw->fc.low_water |
  1452. IXGBE_FCRTL_XONE));
  1453. } else {
  1454. IXGBE_WRITE_REG(hw,
  1455. IXGBE_FCRTL_82599(packetbuf_num),
  1456. hw->fc.low_water);
  1457. }
  1458. IXGBE_WRITE_REG(hw, IXGBE_FCRTH_82599(packetbuf_num),
  1459. (hw->fc.high_water | IXGBE_FCRTH_FCEN));
  1460. }
  1461. }
  1462. /* Configure pause time (2 TCs per register) */
  1463. reg = IXGBE_READ_REG(hw, IXGBE_FCTTV(packetbuf_num / 2));
  1464. if ((packetbuf_num & 1) == 0)
  1465. reg = (reg & 0xFFFF0000) | hw->fc.pause_time;
  1466. else
  1467. reg = (reg & 0x0000FFFF) | (hw->fc.pause_time << 16);
  1468. IXGBE_WRITE_REG(hw, IXGBE_FCTTV(packetbuf_num / 2), reg);
  1469. IXGBE_WRITE_REG(hw, IXGBE_FCRTV, (hw->fc.pause_time >> 1));
  1470. out:
  1471. return ret_val;
  1472. }
  1473. /**
  1474. * ixgbe_fc_autoneg - Configure flow control
  1475. * @hw: pointer to hardware structure
  1476. *
  1477. * Compares our advertised flow control capabilities to those advertised by
  1478. * our link partner, and determines the proper flow control mode to use.
  1479. **/
  1480. s32 ixgbe_fc_autoneg(struct ixgbe_hw *hw)
  1481. {
  1482. s32 ret_val = 0;
  1483. ixgbe_link_speed speed;
  1484. u32 pcs_anadv_reg, pcs_lpab_reg, linkstat;
  1485. u32 links2, anlp1_reg, autoc_reg, links;
  1486. bool link_up;
  1487. /*
  1488. * AN should have completed when the cable was plugged in.
  1489. * Look for reasons to bail out. Bail out if:
  1490. * - FC autoneg is disabled, or if
  1491. * - link is not up.
  1492. *
  1493. * Since we're being called from an LSC, link is already known to be up.
  1494. * So use link_up_wait_to_complete=false.
  1495. */
  1496. hw->mac.ops.check_link(hw, &speed, &link_up, false);
  1497. if (hw->fc.disable_fc_autoneg || (!link_up)) {
  1498. hw->fc.fc_was_autonegged = false;
  1499. hw->fc.current_mode = hw->fc.requested_mode;
  1500. goto out;
  1501. }
  1502. /*
  1503. * On backplane, bail out if
  1504. * - backplane autoneg was not completed, or if
  1505. * - we are 82599 and link partner is not AN enabled
  1506. */
  1507. if (hw->phy.media_type == ixgbe_media_type_backplane) {
  1508. links = IXGBE_READ_REG(hw, IXGBE_LINKS);
  1509. if ((links & IXGBE_LINKS_KX_AN_COMP) == 0) {
  1510. hw->fc.fc_was_autonegged = false;
  1511. hw->fc.current_mode = hw->fc.requested_mode;
  1512. goto out;
  1513. }
  1514. if (hw->mac.type == ixgbe_mac_82599EB) {
  1515. links2 = IXGBE_READ_REG(hw, IXGBE_LINKS2);
  1516. if ((links2 & IXGBE_LINKS2_AN_SUPPORTED) == 0) {
  1517. hw->fc.fc_was_autonegged = false;
  1518. hw->fc.current_mode = hw->fc.requested_mode;
  1519. goto out;
  1520. }
  1521. }
  1522. }
  1523. /*
  1524. * On multispeed fiber at 1g, bail out if
  1525. * - link is up but AN did not complete, or if
  1526. * - link is up and AN completed but timed out
  1527. */
  1528. if (hw->phy.multispeed_fiber && (speed == IXGBE_LINK_SPEED_1GB_FULL)) {
  1529. linkstat = IXGBE_READ_REG(hw, IXGBE_PCS1GLSTA);
  1530. if (((linkstat & IXGBE_PCS1GLSTA_AN_COMPLETE) == 0) ||
  1531. ((linkstat & IXGBE_PCS1GLSTA_AN_TIMED_OUT) == 1)) {
  1532. hw->fc.fc_was_autonegged = false;
  1533. hw->fc.current_mode = hw->fc.requested_mode;
  1534. goto out;
  1535. }
  1536. }
  1537. /*
  1538. * Bail out on
  1539. * - copper or CX4 adapters
  1540. * - fiber adapters running at 10gig
  1541. */
  1542. if ((hw->phy.media_type == ixgbe_media_type_copper) ||
  1543. (hw->phy.media_type == ixgbe_media_type_cx4) ||
  1544. ((hw->phy.media_type == ixgbe_media_type_fiber) &&
  1545. (speed == IXGBE_LINK_SPEED_10GB_FULL))) {
  1546. hw->fc.fc_was_autonegged = false;
  1547. hw->fc.current_mode = hw->fc.requested_mode;
  1548. goto out;
  1549. }
  1550. /*
  1551. * Read the AN advertisement and LP ability registers and resolve
  1552. * local flow control settings accordingly
  1553. */
  1554. if ((speed == IXGBE_LINK_SPEED_1GB_FULL) &&
  1555. (hw->phy.media_type != ixgbe_media_type_backplane)) {
  1556. pcs_anadv_reg = IXGBE_READ_REG(hw, IXGBE_PCS1GANA);
  1557. pcs_lpab_reg = IXGBE_READ_REG(hw, IXGBE_PCS1GANLP);
  1558. if ((pcs_anadv_reg & IXGBE_PCS1GANA_SYM_PAUSE) &&
  1559. (pcs_lpab_reg & IXGBE_PCS1GANA_SYM_PAUSE)) {
  1560. /*
  1561. * Now we need to check if the user selected Rx ONLY
  1562. * of pause frames. In this case, we had to advertise
  1563. * FULL flow control because we could not advertise RX
  1564. * ONLY. Hence, we must now check to see if we need to
  1565. * turn OFF the TRANSMISSION of PAUSE frames.
  1566. */
  1567. if (hw->fc.requested_mode == ixgbe_fc_full) {
  1568. hw->fc.current_mode = ixgbe_fc_full;
  1569. hw_dbg(hw, "Flow Control = FULL.\n");
  1570. } else {
  1571. hw->fc.current_mode = ixgbe_fc_rx_pause;
  1572. hw_dbg(hw, "Flow Control=RX PAUSE only\n");
  1573. }
  1574. } else if (!(pcs_anadv_reg & IXGBE_PCS1GANA_SYM_PAUSE) &&
  1575. (pcs_anadv_reg & IXGBE_PCS1GANA_ASM_PAUSE) &&
  1576. (pcs_lpab_reg & IXGBE_PCS1GANA_SYM_PAUSE) &&
  1577. (pcs_lpab_reg & IXGBE_PCS1GANA_ASM_PAUSE)) {
  1578. hw->fc.current_mode = ixgbe_fc_tx_pause;
  1579. hw_dbg(hw, "Flow Control = TX PAUSE frames only.\n");
  1580. } else if ((pcs_anadv_reg & IXGBE_PCS1GANA_SYM_PAUSE) &&
  1581. (pcs_anadv_reg & IXGBE_PCS1GANA_ASM_PAUSE) &&
  1582. !(pcs_lpab_reg & IXGBE_PCS1GANA_SYM_PAUSE) &&
  1583. (pcs_lpab_reg & IXGBE_PCS1GANA_ASM_PAUSE)) {
  1584. hw->fc.current_mode = ixgbe_fc_rx_pause;
  1585. hw_dbg(hw, "Flow Control = RX PAUSE frames only.\n");
  1586. } else {
  1587. hw->fc.current_mode = ixgbe_fc_none;
  1588. hw_dbg(hw, "Flow Control = NONE.\n");
  1589. }
  1590. }
  1591. if (hw->phy.media_type == ixgbe_media_type_backplane) {
  1592. /*
  1593. * Read the 10g AN autoc and LP ability registers and resolve
  1594. * local flow control settings accordingly
  1595. */
  1596. autoc_reg = IXGBE_READ_REG(hw, IXGBE_AUTOC);
  1597. anlp1_reg = IXGBE_READ_REG(hw, IXGBE_ANLP1);
  1598. if ((autoc_reg & IXGBE_AUTOC_SYM_PAUSE) &&
  1599. (anlp1_reg & IXGBE_ANLP1_SYM_PAUSE)) {
  1600. /*
  1601. * Now we need to check if the user selected Rx ONLY
  1602. * of pause frames. In this case, we had to advertise
  1603. * FULL flow control because we could not advertise RX
  1604. * ONLY. Hence, we must now check to see if we need to
  1605. * turn OFF the TRANSMISSION of PAUSE frames.
  1606. */
  1607. if (hw->fc.requested_mode == ixgbe_fc_full) {
  1608. hw->fc.current_mode = ixgbe_fc_full;
  1609. hw_dbg(hw, "Flow Control = FULL.\n");
  1610. } else {
  1611. hw->fc.current_mode = ixgbe_fc_rx_pause;
  1612. hw_dbg(hw, "Flow Control=RX PAUSE only\n");
  1613. }
  1614. } else if (!(autoc_reg & IXGBE_AUTOC_SYM_PAUSE) &&
  1615. (autoc_reg & IXGBE_AUTOC_ASM_PAUSE) &&
  1616. (anlp1_reg & IXGBE_ANLP1_SYM_PAUSE) &&
  1617. (anlp1_reg & IXGBE_ANLP1_ASM_PAUSE)) {
  1618. hw->fc.current_mode = ixgbe_fc_tx_pause;
  1619. hw_dbg(hw, "Flow Control = TX PAUSE frames only.\n");
  1620. } else if ((autoc_reg & IXGBE_AUTOC_SYM_PAUSE) &&
  1621. (autoc_reg & IXGBE_AUTOC_ASM_PAUSE) &&
  1622. !(anlp1_reg & IXGBE_ANLP1_SYM_PAUSE) &&
  1623. (anlp1_reg & IXGBE_ANLP1_ASM_PAUSE)) {
  1624. hw->fc.current_mode = ixgbe_fc_rx_pause;
  1625. hw_dbg(hw, "Flow Control = RX PAUSE frames only.\n");
  1626. } else {
  1627. hw->fc.current_mode = ixgbe_fc_none;
  1628. hw_dbg(hw, "Flow Control = NONE.\n");
  1629. }
  1630. }
  1631. /* Record that current_mode is the result of a successful autoneg */
  1632. hw->fc.fc_was_autonegged = true;
  1633. out:
  1634. return ret_val;
  1635. }
  1636. /**
  1637. * ixgbe_setup_fc - Set up flow control
  1638. * @hw: pointer to hardware structure
  1639. *
  1640. * Called at init time to set up flow control.
  1641. **/
  1642. static s32 ixgbe_setup_fc(struct ixgbe_hw *hw, s32 packetbuf_num)
  1643. {
  1644. s32 ret_val = 0;
  1645. u32 reg;
  1646. #ifdef CONFIG_DCB
  1647. if (hw->fc.requested_mode == ixgbe_fc_pfc) {
  1648. hw->fc.current_mode = hw->fc.requested_mode;
  1649. goto out;
  1650. }
  1651. #endif
  1652. /* Validate the packetbuf configuration */
  1653. if (packetbuf_num < 0 || packetbuf_num > 7) {
  1654. hw_dbg(hw, "Invalid packet buffer number [%d], expected range "
  1655. "is 0-7\n", packetbuf_num);
  1656. ret_val = IXGBE_ERR_INVALID_LINK_SETTINGS;
  1657. goto out;
  1658. }
  1659. /*
  1660. * Validate the water mark configuration. Zero water marks are invalid
  1661. * because it causes the controller to just blast out fc packets.
  1662. */
  1663. if (!hw->fc.low_water || !hw->fc.high_water || !hw->fc.pause_time) {
  1664. hw_dbg(hw, "Invalid water mark configuration\n");
  1665. ret_val = IXGBE_ERR_INVALID_LINK_SETTINGS;
  1666. goto out;
  1667. }
  1668. /*
  1669. * Validate the requested mode. Strict IEEE mode does not allow
  1670. * ixgbe_fc_rx_pause because it will cause us to fail at UNH.
  1671. */
  1672. if (hw->fc.strict_ieee && hw->fc.requested_mode == ixgbe_fc_rx_pause) {
  1673. hw_dbg(hw, "ixgbe_fc_rx_pause not valid in strict "
  1674. "IEEE mode\n");
  1675. ret_val = IXGBE_ERR_INVALID_LINK_SETTINGS;
  1676. goto out;
  1677. }
  1678. /*
  1679. * 10gig parts do not have a word in the EEPROM to determine the
  1680. * default flow control setting, so we explicitly set it to full.
  1681. */
  1682. if (hw->fc.requested_mode == ixgbe_fc_default)
  1683. hw->fc.requested_mode = ixgbe_fc_full;
  1684. /*
  1685. * Set up the 1G flow control advertisement registers so the HW will be
  1686. * able to do fc autoneg once the cable is plugged in. If we end up
  1687. * using 10g instead, this is harmless.
  1688. */
  1689. reg = IXGBE_READ_REG(hw, IXGBE_PCS1GANA);
  1690. /*
  1691. * The possible values of fc.requested_mode are:
  1692. * 0: Flow control is completely disabled
  1693. * 1: Rx flow control is enabled (we can receive pause frames,
  1694. * but not send pause frames).
  1695. * 2: Tx flow control is enabled (we can send pause frames but
  1696. * we do not support receiving pause frames).
  1697. * 3: Both Rx and Tx flow control (symmetric) are enabled.
  1698. #ifdef CONFIG_DCB
  1699. * 4: Priority Flow Control is enabled.
  1700. #endif
  1701. * other: Invalid.
  1702. */
  1703. switch (hw->fc.requested_mode) {
  1704. case ixgbe_fc_none:
  1705. /* Flow control completely disabled by software override. */
  1706. reg &= ~(IXGBE_PCS1GANA_SYM_PAUSE | IXGBE_PCS1GANA_ASM_PAUSE);
  1707. break;
  1708. case ixgbe_fc_rx_pause:
  1709. /*
  1710. * Rx Flow control is enabled and Tx Flow control is
  1711. * disabled by software override. Since there really
  1712. * isn't a way to advertise that we are capable of RX
  1713. * Pause ONLY, we will advertise that we support both
  1714. * symmetric and asymmetric Rx PAUSE. Later, we will
  1715. * disable the adapter's ability to send PAUSE frames.
  1716. */
  1717. reg |= (IXGBE_PCS1GANA_SYM_PAUSE | IXGBE_PCS1GANA_ASM_PAUSE);
  1718. break;
  1719. case ixgbe_fc_tx_pause:
  1720. /*
  1721. * Tx Flow control is enabled, and Rx Flow control is
  1722. * disabled by software override.
  1723. */
  1724. reg |= (IXGBE_PCS1GANA_ASM_PAUSE);
  1725. reg &= ~(IXGBE_PCS1GANA_SYM_PAUSE);
  1726. break;
  1727. case ixgbe_fc_full:
  1728. /* Flow control (both Rx and Tx) is enabled by SW override. */
  1729. reg |= (IXGBE_PCS1GANA_SYM_PAUSE | IXGBE_PCS1GANA_ASM_PAUSE);
  1730. break;
  1731. #ifdef CONFIG_DCB
  1732. case ixgbe_fc_pfc:
  1733. goto out;
  1734. break;
  1735. #endif /* CONFIG_DCB */
  1736. default:
  1737. hw_dbg(hw, "Flow control param set incorrectly\n");
  1738. ret_val = IXGBE_ERR_CONFIG;
  1739. goto out;
  1740. break;
  1741. }
  1742. IXGBE_WRITE_REG(hw, IXGBE_PCS1GANA, reg);
  1743. reg = IXGBE_READ_REG(hw, IXGBE_PCS1GLCTL);
  1744. /* Disable AN timeout */
  1745. if (hw->fc.strict_ieee)
  1746. reg &= ~IXGBE_PCS1GLCTL_AN_1G_TIMEOUT_EN;
  1747. IXGBE_WRITE_REG(hw, IXGBE_PCS1GLCTL, reg);
  1748. hw_dbg(hw, "Set up FC; PCS1GLCTL = 0x%08X\n", reg);
  1749. /*
  1750. * Set up the 10G flow control advertisement registers so the HW
  1751. * can do fc autoneg once the cable is plugged in. If we end up
  1752. * using 1g instead, this is harmless.
  1753. */
  1754. reg = IXGBE_READ_REG(hw, IXGBE_AUTOC);
  1755. /*
  1756. * The possible values of fc.requested_mode are:
  1757. * 0: Flow control is completely disabled
  1758. * 1: Rx flow control is enabled (we can receive pause frames,
  1759. * but not send pause frames).
  1760. * 2: Tx flow control is enabled (we can send pause frames but
  1761. * we do not support receiving pause frames).
  1762. * 3: Both Rx and Tx flow control (symmetric) are enabled.
  1763. * other: Invalid.
  1764. */
  1765. switch (hw->fc.requested_mode) {
  1766. case ixgbe_fc_none:
  1767. /* Flow control completely disabled by software override. */
  1768. reg &= ~(IXGBE_AUTOC_SYM_PAUSE | IXGBE_AUTOC_ASM_PAUSE);
  1769. break;
  1770. case ixgbe_fc_rx_pause:
  1771. /*
  1772. * Rx Flow control is enabled and Tx Flow control is
  1773. * disabled by software override. Since there really
  1774. * isn't a way to advertise that we are capable of RX
  1775. * Pause ONLY, we will advertise that we support both
  1776. * symmetric and asymmetric Rx PAUSE. Later, we will
  1777. * disable the adapter's ability to send PAUSE frames.
  1778. */
  1779. reg |= (IXGBE_AUTOC_SYM_PAUSE | IXGBE_AUTOC_ASM_PAUSE);
  1780. break;
  1781. case ixgbe_fc_tx_pause:
  1782. /*
  1783. * Tx Flow control is enabled, and Rx Flow control is
  1784. * disabled by software override.
  1785. */
  1786. reg |= (IXGBE_AUTOC_ASM_PAUSE);
  1787. reg &= ~(IXGBE_AUTOC_SYM_PAUSE);
  1788. break;
  1789. case ixgbe_fc_full:
  1790. /* Flow control (both Rx and Tx) is enabled by SW override. */
  1791. reg |= (IXGBE_AUTOC_SYM_PAUSE | IXGBE_AUTOC_ASM_PAUSE);
  1792. break;
  1793. #ifdef CONFIG_DCB
  1794. case ixgbe_fc_pfc:
  1795. goto out;
  1796. break;
  1797. #endif /* CONFIG_DCB */
  1798. default:
  1799. hw_dbg(hw, "Flow control param set incorrectly\n");
  1800. ret_val = IXGBE_ERR_CONFIG;
  1801. goto out;
  1802. break;
  1803. }
  1804. /*
  1805. * AUTOC restart handles negotiation of 1G and 10G. There is
  1806. * no need to set the PCS1GCTL register.
  1807. */
  1808. reg |= IXGBE_AUTOC_AN_RESTART;
  1809. IXGBE_WRITE_REG(hw, IXGBE_AUTOC, reg);
  1810. hw_dbg(hw, "Set up FC; IXGBE_AUTOC = 0x%08X\n", reg);
  1811. out:
  1812. return ret_val;
  1813. }
  1814. /**
  1815. * ixgbe_disable_pcie_master - Disable PCI-express master access
  1816. * @hw: pointer to hardware structure
  1817. *
  1818. * Disables PCI-Express master access and verifies there are no pending
  1819. * requests. IXGBE_ERR_MASTER_REQUESTS_PENDING is returned if master disable
  1820. * bit hasn't caused the master requests to be disabled, else 0
  1821. * is returned signifying master requests disabled.
  1822. **/
  1823. s32 ixgbe_disable_pcie_master(struct ixgbe_hw *hw)
  1824. {
  1825. u32 i;
  1826. u32 reg_val;
  1827. u32 number_of_queues;
  1828. s32 status = IXGBE_ERR_MASTER_REQUESTS_PENDING;
  1829. /* Disable the receive unit by stopping each queue */
  1830. number_of_queues = hw->mac.max_rx_queues;
  1831. for (i = 0; i < number_of_queues; i++) {
  1832. reg_val = IXGBE_READ_REG(hw, IXGBE_RXDCTL(i));
  1833. if (reg_val & IXGBE_RXDCTL_ENABLE) {
  1834. reg_val &= ~IXGBE_RXDCTL_ENABLE;
  1835. IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(i), reg_val);
  1836. }
  1837. }
  1838. reg_val = IXGBE_READ_REG(hw, IXGBE_CTRL);
  1839. reg_val |= IXGBE_CTRL_GIO_DIS;
  1840. IXGBE_WRITE_REG(hw, IXGBE_CTRL, reg_val);
  1841. for (i = 0; i < IXGBE_PCI_MASTER_DISABLE_TIMEOUT; i++) {
  1842. if (!(IXGBE_READ_REG(hw, IXGBE_STATUS) & IXGBE_STATUS_GIO)) {
  1843. status = 0;
  1844. break;
  1845. }
  1846. udelay(100);
  1847. }
  1848. return status;
  1849. }
  1850. /**
  1851. * ixgbe_acquire_swfw_sync - Acquire SWFW semaphore
  1852. * @hw: pointer to hardware structure
  1853. * @mask: Mask to specify which semaphore to acquire
  1854. *
  1855. * Acquires the SWFW semaphore thought the GSSR register for the specified
  1856. * function (CSR, PHY0, PHY1, EEPROM, Flash)
  1857. **/
  1858. s32 ixgbe_acquire_swfw_sync(struct ixgbe_hw *hw, u16 mask)
  1859. {
  1860. u32 gssr;
  1861. u32 swmask = mask;
  1862. u32 fwmask = mask << 5;
  1863. s32 timeout = 200;
  1864. while (timeout) {
  1865. if (ixgbe_get_eeprom_semaphore(hw))
  1866. return IXGBE_ERR_SWFW_SYNC;
  1867. gssr = IXGBE_READ_REG(hw, IXGBE_GSSR);
  1868. if (!(gssr & (fwmask | swmask)))
  1869. break;
  1870. /*
  1871. * Firmware currently using resource (fwmask) or other software
  1872. * thread currently using resource (swmask)
  1873. */
  1874. ixgbe_release_eeprom_semaphore(hw);
  1875. msleep(5);
  1876. timeout--;
  1877. }
  1878. if (!timeout) {
  1879. hw_dbg(hw, "Driver can't access resource, GSSR timeout.\n");
  1880. return IXGBE_ERR_SWFW_SYNC;
  1881. }
  1882. gssr |= swmask;
  1883. IXGBE_WRITE_REG(hw, IXGBE_GSSR, gssr);
  1884. ixgbe_release_eeprom_semaphore(hw);
  1885. return 0;
  1886. }
  1887. /**
  1888. * ixgbe_release_swfw_sync - Release SWFW semaphore
  1889. * @hw: pointer to hardware structure
  1890. * @mask: Mask to specify which semaphore to release
  1891. *
  1892. * Releases the SWFW semaphore thought the GSSR register for the specified
  1893. * function (CSR, PHY0, PHY1, EEPROM, Flash)
  1894. **/
  1895. void ixgbe_release_swfw_sync(struct ixgbe_hw *hw, u16 mask)
  1896. {
  1897. u32 gssr;
  1898. u32 swmask = mask;
  1899. ixgbe_get_eeprom_semaphore(hw);
  1900. gssr = IXGBE_READ_REG(hw, IXGBE_GSSR);
  1901. gssr &= ~swmask;
  1902. IXGBE_WRITE_REG(hw, IXGBE_GSSR, gssr);
  1903. ixgbe_release_eeprom_semaphore(hw);
  1904. }
  1905. /**
  1906. * ixgbe_enable_rx_dma_generic - Enable the Rx DMA unit
  1907. * @hw: pointer to hardware structure
  1908. * @regval: register value to write to RXCTRL
  1909. *
  1910. * Enables the Rx DMA unit
  1911. **/
  1912. s32 ixgbe_enable_rx_dma_generic(struct ixgbe_hw *hw, u32 regval)
  1913. {
  1914. IXGBE_WRITE_REG(hw, IXGBE_RXCTRL, regval);
  1915. return 0;
  1916. }
  1917. /**
  1918. * ixgbe_blink_led_start_generic - Blink LED based on index.
  1919. * @hw: pointer to hardware structure
  1920. * @index: led number to blink
  1921. **/
  1922. s32 ixgbe_blink_led_start_generic(struct ixgbe_hw *hw, u32 index)
  1923. {
  1924. ixgbe_link_speed speed = 0;
  1925. bool link_up = 0;
  1926. u32 autoc_reg = IXGBE_READ_REG(hw, IXGBE_AUTOC);
  1927. u32 led_reg = IXGBE_READ_REG(hw, IXGBE_LEDCTL);
  1928. /*
  1929. * Link must be up to auto-blink the LEDs;
  1930. * Force it if link is down.
  1931. */
  1932. hw->mac.ops.check_link(hw, &speed, &link_up, false);
  1933. if (!link_up) {
  1934. autoc_reg |= IXGBE_AUTOC_AN_RESTART;
  1935. autoc_reg |= IXGBE_AUTOC_FLU;
  1936. IXGBE_WRITE_REG(hw, IXGBE_AUTOC, autoc_reg);
  1937. msleep(10);
  1938. }
  1939. led_reg &= ~IXGBE_LED_MODE_MASK(index);
  1940. led_reg |= IXGBE_LED_BLINK(index);
  1941. IXGBE_WRITE_REG(hw, IXGBE_LEDCTL, led_reg);
  1942. IXGBE_WRITE_FLUSH(hw);
  1943. return 0;
  1944. }
  1945. /**
  1946. * ixgbe_blink_led_stop_generic - Stop blinking LED based on index.
  1947. * @hw: pointer to hardware structure
  1948. * @index: led number to stop blinking
  1949. **/
  1950. s32 ixgbe_blink_led_stop_generic(struct ixgbe_hw *hw, u32 index)
  1951. {
  1952. u32 autoc_reg = IXGBE_READ_REG(hw, IXGBE_AUTOC);
  1953. u32 led_reg = IXGBE_READ_REG(hw, IXGBE_LEDCTL);
  1954. autoc_reg &= ~IXGBE_AUTOC_FLU;
  1955. autoc_reg |= IXGBE_AUTOC_AN_RESTART;
  1956. IXGBE_WRITE_REG(hw, IXGBE_AUTOC, autoc_reg);
  1957. led_reg &= ~IXGBE_LED_MODE_MASK(index);
  1958. led_reg &= ~IXGBE_LED_BLINK(index);
  1959. led_reg |= IXGBE_LED_LINK_ACTIVE << IXGBE_LED_MODE_SHIFT(index);
  1960. IXGBE_WRITE_REG(hw, IXGBE_LEDCTL, led_reg);
  1961. IXGBE_WRITE_FLUSH(hw);
  1962. return 0;
  1963. }
  1964. /**
  1965. * ixgbe_get_san_mac_addr_offset - Get SAN MAC address offset from the EEPROM
  1966. * @hw: pointer to hardware structure
  1967. * @san_mac_offset: SAN MAC address offset
  1968. *
  1969. * This function will read the EEPROM location for the SAN MAC address
  1970. * pointer, and returns the value at that location. This is used in both
  1971. * get and set mac_addr routines.
  1972. **/
  1973. static s32 ixgbe_get_san_mac_addr_offset(struct ixgbe_hw *hw,
  1974. u16 *san_mac_offset)
  1975. {
  1976. /*
  1977. * First read the EEPROM pointer to see if the MAC addresses are
  1978. * available.
  1979. */
  1980. hw->eeprom.ops.read(hw, IXGBE_SAN_MAC_ADDR_PTR, san_mac_offset);
  1981. return 0;
  1982. }
  1983. /**
  1984. * ixgbe_get_san_mac_addr_generic - SAN MAC address retrieval from the EEPROM
  1985. * @hw: pointer to hardware structure
  1986. * @san_mac_addr: SAN MAC address
  1987. *
  1988. * Reads the SAN MAC address from the EEPROM, if it's available. This is
  1989. * per-port, so set_lan_id() must be called before reading the addresses.
  1990. * set_lan_id() is called by identify_sfp(), but this cannot be relied
  1991. * upon for non-SFP connections, so we must call it here.
  1992. **/
  1993. s32 ixgbe_get_san_mac_addr_generic(struct ixgbe_hw *hw, u8 *san_mac_addr)
  1994. {
  1995. u16 san_mac_data, san_mac_offset;
  1996. u8 i;
  1997. /*
  1998. * First read the EEPROM pointer to see if the MAC addresses are
  1999. * available. If they're not, no point in calling set_lan_id() here.
  2000. */
  2001. ixgbe_get_san_mac_addr_offset(hw, &san_mac_offset);
  2002. if ((san_mac_offset == 0) || (san_mac_offset == 0xFFFF)) {
  2003. /*
  2004. * No addresses available in this EEPROM. It's not an
  2005. * error though, so just wipe the local address and return.
  2006. */
  2007. for (i = 0; i < 6; i++)
  2008. san_mac_addr[i] = 0xFF;
  2009. goto san_mac_addr_out;
  2010. }
  2011. /* make sure we know which port we need to program */
  2012. hw->mac.ops.set_lan_id(hw);
  2013. /* apply the port offset to the address offset */
  2014. (hw->bus.func) ? (san_mac_offset += IXGBE_SAN_MAC_ADDR_PORT1_OFFSET) :
  2015. (san_mac_offset += IXGBE_SAN_MAC_ADDR_PORT0_OFFSET);
  2016. for (i = 0; i < 3; i++) {
  2017. hw->eeprom.ops.read(hw, san_mac_offset, &san_mac_data);
  2018. san_mac_addr[i * 2] = (u8)(san_mac_data);
  2019. san_mac_addr[i * 2 + 1] = (u8)(san_mac_data >> 8);
  2020. san_mac_offset++;
  2021. }
  2022. san_mac_addr_out:
  2023. return 0;
  2024. }
  2025. /**
  2026. * ixgbe_get_pcie_msix_count_generic - Gets MSI-X vector count
  2027. * @hw: pointer to hardware structure
  2028. *
  2029. * Read PCIe configuration space, and get the MSI-X vector count from
  2030. * the capabilities table.
  2031. **/
  2032. u32 ixgbe_get_pcie_msix_count_generic(struct ixgbe_hw *hw)
  2033. {
  2034. struct ixgbe_adapter *adapter = hw->back;
  2035. u16 msix_count;
  2036. pci_read_config_word(adapter->pdev, IXGBE_PCIE_MSIX_82599_CAPS,
  2037. &msix_count);
  2038. msix_count &= IXGBE_PCIE_MSIX_TBL_SZ_MASK;
  2039. /* MSI-X count is zero-based in HW, so increment to give proper value */
  2040. msix_count++;
  2041. return msix_count;
  2042. }
  2043. /**
  2044. * ixgbe_clear_vmdq_generic - Disassociate a VMDq pool index from a rx address
  2045. * @hw: pointer to hardware struct
  2046. * @rar: receive address register index to disassociate
  2047. * @vmdq: VMDq pool index to remove from the rar
  2048. **/
  2049. s32 ixgbe_clear_vmdq_generic(struct ixgbe_hw *hw, u32 rar, u32 vmdq)
  2050. {
  2051. u32 mpsar_lo, mpsar_hi;
  2052. u32 rar_entries = hw->mac.num_rar_entries;
  2053. if (rar < rar_entries) {
  2054. mpsar_lo = IXGBE_READ_REG(hw, IXGBE_MPSAR_LO(rar));
  2055. mpsar_hi = IXGBE_READ_REG(hw, IXGBE_MPSAR_HI(rar));
  2056. if (!mpsar_lo && !mpsar_hi)
  2057. goto done;
  2058. if (vmdq == IXGBE_CLEAR_VMDQ_ALL) {
  2059. if (mpsar_lo) {
  2060. IXGBE_WRITE_REG(hw, IXGBE_MPSAR_LO(rar), 0);
  2061. mpsar_lo = 0;
  2062. }
  2063. if (mpsar_hi) {
  2064. IXGBE_WRITE_REG(hw, IXGBE_MPSAR_HI(rar), 0);
  2065. mpsar_hi = 0;
  2066. }
  2067. } else if (vmdq < 32) {
  2068. mpsar_lo &= ~(1 << vmdq);
  2069. IXGBE_WRITE_REG(hw, IXGBE_MPSAR_LO(rar), mpsar_lo);
  2070. } else {
  2071. mpsar_hi &= ~(1 << (vmdq - 32));
  2072. IXGBE_WRITE_REG(hw, IXGBE_MPSAR_HI(rar), mpsar_hi);
  2073. }
  2074. /* was that the last pool using this rar? */
  2075. if (mpsar_lo == 0 && mpsar_hi == 0 && rar != 0)
  2076. hw->mac.ops.clear_rar(hw, rar);
  2077. } else {
  2078. hw_dbg(hw, "RAR index %d is out of range.\n", rar);
  2079. }
  2080. done:
  2081. return 0;
  2082. }
  2083. /**
  2084. * ixgbe_set_vmdq_generic - Associate a VMDq pool index with a rx address
  2085. * @hw: pointer to hardware struct
  2086. * @rar: receive address register index to associate with a VMDq index
  2087. * @vmdq: VMDq pool index
  2088. **/
  2089. s32 ixgbe_set_vmdq_generic(struct ixgbe_hw *hw, u32 rar, u32 vmdq)
  2090. {
  2091. u32 mpsar;
  2092. u32 rar_entries = hw->mac.num_rar_entries;
  2093. if (rar < rar_entries) {
  2094. if (vmdq < 32) {
  2095. mpsar = IXGBE_READ_REG(hw, IXGBE_MPSAR_LO(rar));
  2096. mpsar |= 1 << vmdq;
  2097. IXGBE_WRITE_REG(hw, IXGBE_MPSAR_LO(rar), mpsar);
  2098. } else {
  2099. mpsar = IXGBE_READ_REG(hw, IXGBE_MPSAR_HI(rar));
  2100. mpsar |= 1 << (vmdq - 32);
  2101. IXGBE_WRITE_REG(hw, IXGBE_MPSAR_HI(rar), mpsar);
  2102. }
  2103. } else {
  2104. hw_dbg(hw, "RAR index %d is out of range.\n", rar);
  2105. }
  2106. return 0;
  2107. }
  2108. /**
  2109. * ixgbe_init_uta_tables_generic - Initialize the Unicast Table Array
  2110. * @hw: pointer to hardware structure
  2111. **/
  2112. s32 ixgbe_init_uta_tables_generic(struct ixgbe_hw *hw)
  2113. {
  2114. int i;
  2115. for (i = 0; i < 128; i++)
  2116. IXGBE_WRITE_REG(hw, IXGBE_UTA(i), 0);
  2117. return 0;
  2118. }
  2119. /**
  2120. * ixgbe_find_vlvf_slot - find the vlanid or the first empty slot
  2121. * @hw: pointer to hardware structure
  2122. * @vlan: VLAN id to write to VLAN filter
  2123. *
  2124. * return the VLVF index where this VLAN id should be placed
  2125. *
  2126. **/
  2127. s32 ixgbe_find_vlvf_slot(struct ixgbe_hw *hw, u32 vlan)
  2128. {
  2129. u32 bits = 0;
  2130. u32 first_empty_slot = 0;
  2131. s32 regindex;
  2132. /* short cut the special case */
  2133. if (vlan == 0)
  2134. return 0;
  2135. /*
  2136. * Search for the vlan id in the VLVF entries. Save off the first empty
  2137. * slot found along the way
  2138. */
  2139. for (regindex = 1; regindex < IXGBE_VLVF_ENTRIES; regindex++) {
  2140. bits = IXGBE_READ_REG(hw, IXGBE_VLVF(regindex));
  2141. if (!bits && !(first_empty_slot))
  2142. first_empty_slot = regindex;
  2143. else if ((bits & 0x0FFF) == vlan)
  2144. break;
  2145. }
  2146. /*
  2147. * If regindex is less than IXGBE_VLVF_ENTRIES, then we found the vlan
  2148. * in the VLVF. Else use the first empty VLVF register for this
  2149. * vlan id.
  2150. */
  2151. if (regindex >= IXGBE_VLVF_ENTRIES) {
  2152. if (first_empty_slot)
  2153. regindex = first_empty_slot;
  2154. else {
  2155. hw_dbg(hw, "No space in VLVF.\n");
  2156. regindex = IXGBE_ERR_NO_SPACE;
  2157. }
  2158. }
  2159. return regindex;
  2160. }
  2161. /**
  2162. * ixgbe_set_vfta_generic - Set VLAN filter table
  2163. * @hw: pointer to hardware structure
  2164. * @vlan: VLAN id to write to VLAN filter
  2165. * @vind: VMDq output index that maps queue to VLAN id in VFVFB
  2166. * @vlan_on: boolean flag to turn on/off VLAN in VFVF
  2167. *
  2168. * Turn on/off specified VLAN in the VLAN filter table.
  2169. **/
  2170. s32 ixgbe_set_vfta_generic(struct ixgbe_hw *hw, u32 vlan, u32 vind,
  2171. bool vlan_on)
  2172. {
  2173. s32 regindex;
  2174. u32 bitindex;
  2175. u32 vfta;
  2176. u32 bits;
  2177. u32 vt;
  2178. u32 targetbit;
  2179. bool vfta_changed = false;
  2180. if (vlan > 4095)
  2181. return IXGBE_ERR_PARAM;
  2182. /*
  2183. * this is a 2 part operation - first the VFTA, then the
  2184. * VLVF and VLVFB if VT Mode is set
  2185. * We don't write the VFTA until we know the VLVF part succeeded.
  2186. */
  2187. /* Part 1
  2188. * The VFTA is a bitstring made up of 128 32-bit registers
  2189. * that enable the particular VLAN id, much like the MTA:
  2190. * bits[11-5]: which register
  2191. * bits[4-0]: which bit in the register
  2192. */
  2193. regindex = (vlan >> 5) & 0x7F;
  2194. bitindex = vlan & 0x1F;
  2195. targetbit = (1 << bitindex);
  2196. vfta = IXGBE_READ_REG(hw, IXGBE_VFTA(regindex));
  2197. if (vlan_on) {
  2198. if (!(vfta & targetbit)) {
  2199. vfta |= targetbit;
  2200. vfta_changed = true;
  2201. }
  2202. } else {
  2203. if ((vfta & targetbit)) {
  2204. vfta &= ~targetbit;
  2205. vfta_changed = true;
  2206. }
  2207. }
  2208. /* Part 2
  2209. * If VT Mode is set
  2210. * Either vlan_on
  2211. * make sure the vlan is in VLVF
  2212. * set the vind bit in the matching VLVFB
  2213. * Or !vlan_on
  2214. * clear the pool bit and possibly the vind
  2215. */
  2216. vt = IXGBE_READ_REG(hw, IXGBE_VT_CTL);
  2217. if (vt & IXGBE_VT_CTL_VT_ENABLE) {
  2218. s32 vlvf_index;
  2219. vlvf_index = ixgbe_find_vlvf_slot(hw, vlan);
  2220. if (vlvf_index < 0)
  2221. return vlvf_index;
  2222. if (vlan_on) {
  2223. /* set the pool bit */
  2224. if (vind < 32) {
  2225. bits = IXGBE_READ_REG(hw,
  2226. IXGBE_VLVFB(vlvf_index*2));
  2227. bits |= (1 << vind);
  2228. IXGBE_WRITE_REG(hw,
  2229. IXGBE_VLVFB(vlvf_index*2),
  2230. bits);
  2231. } else {
  2232. bits = IXGBE_READ_REG(hw,
  2233. IXGBE_VLVFB((vlvf_index*2)+1));
  2234. bits |= (1 << (vind-32));
  2235. IXGBE_WRITE_REG(hw,
  2236. IXGBE_VLVFB((vlvf_index*2)+1),
  2237. bits);
  2238. }
  2239. } else {
  2240. /* clear the pool bit */
  2241. if (vind < 32) {
  2242. bits = IXGBE_READ_REG(hw,
  2243. IXGBE_VLVFB(vlvf_index*2));
  2244. bits &= ~(1 << vind);
  2245. IXGBE_WRITE_REG(hw,
  2246. IXGBE_VLVFB(vlvf_index*2),
  2247. bits);
  2248. bits |= IXGBE_READ_REG(hw,
  2249. IXGBE_VLVFB((vlvf_index*2)+1));
  2250. } else {
  2251. bits = IXGBE_READ_REG(hw,
  2252. IXGBE_VLVFB((vlvf_index*2)+1));
  2253. bits &= ~(1 << (vind-32));
  2254. IXGBE_WRITE_REG(hw,
  2255. IXGBE_VLVFB((vlvf_index*2)+1),
  2256. bits);
  2257. bits |= IXGBE_READ_REG(hw,
  2258. IXGBE_VLVFB(vlvf_index*2));
  2259. }
  2260. }
  2261. /*
  2262. * If there are still bits set in the VLVFB registers
  2263. * for the VLAN ID indicated we need to see if the
  2264. * caller is requesting that we clear the VFTA entry bit.
  2265. * If the caller has requested that we clear the VFTA
  2266. * entry bit but there are still pools/VFs using this VLAN
  2267. * ID entry then ignore the request. We're not worried
  2268. * about the case where we're turning the VFTA VLAN ID
  2269. * entry bit on, only when requested to turn it off as
  2270. * there may be multiple pools and/or VFs using the
  2271. * VLAN ID entry. In that case we cannot clear the
  2272. * VFTA bit until all pools/VFs using that VLAN ID have also
  2273. * been cleared. This will be indicated by "bits" being
  2274. * zero.
  2275. */
  2276. if (bits) {
  2277. IXGBE_WRITE_REG(hw, IXGBE_VLVF(vlvf_index),
  2278. (IXGBE_VLVF_VIEN | vlan));
  2279. if (!vlan_on) {
  2280. /* someone wants to clear the vfta entry
  2281. * but some pools/VFs are still using it.
  2282. * Ignore it. */
  2283. vfta_changed = false;
  2284. }
  2285. }
  2286. else
  2287. IXGBE_WRITE_REG(hw, IXGBE_VLVF(vlvf_index), 0);
  2288. }
  2289. if (vfta_changed)
  2290. IXGBE_WRITE_REG(hw, IXGBE_VFTA(regindex), vfta);
  2291. return 0;
  2292. }
  2293. /**
  2294. * ixgbe_clear_vfta_generic - Clear VLAN filter table
  2295. * @hw: pointer to hardware structure
  2296. *
  2297. * Clears the VLAN filer table, and the VMDq index associated with the filter
  2298. **/
  2299. s32 ixgbe_clear_vfta_generic(struct ixgbe_hw *hw)
  2300. {
  2301. u32 offset;
  2302. for (offset = 0; offset < hw->mac.vft_size; offset++)
  2303. IXGBE_WRITE_REG(hw, IXGBE_VFTA(offset), 0);
  2304. for (offset = 0; offset < IXGBE_VLVF_ENTRIES; offset++) {
  2305. IXGBE_WRITE_REG(hw, IXGBE_VLVF(offset), 0);
  2306. IXGBE_WRITE_REG(hw, IXGBE_VLVFB(offset*2), 0);
  2307. IXGBE_WRITE_REG(hw, IXGBE_VLVFB((offset*2)+1), 0);
  2308. }
  2309. return 0;
  2310. }
  2311. /**
  2312. * ixgbe_check_mac_link_generic - Determine link and speed status
  2313. * @hw: pointer to hardware structure
  2314. * @speed: pointer to link speed
  2315. * @link_up: true when link is up
  2316. * @link_up_wait_to_complete: bool used to wait for link up or not
  2317. *
  2318. * Reads the links register to determine if link is up and the current speed
  2319. **/
  2320. s32 ixgbe_check_mac_link_generic(struct ixgbe_hw *hw, ixgbe_link_speed *speed,
  2321. bool *link_up, bool link_up_wait_to_complete)
  2322. {
  2323. u32 links_reg;
  2324. u32 i;
  2325. links_reg = IXGBE_READ_REG(hw, IXGBE_LINKS);
  2326. if (link_up_wait_to_complete) {
  2327. for (i = 0; i < IXGBE_LINK_UP_TIME; i++) {
  2328. if (links_reg & IXGBE_LINKS_UP) {
  2329. *link_up = true;
  2330. break;
  2331. } else {
  2332. *link_up = false;
  2333. }
  2334. msleep(100);
  2335. links_reg = IXGBE_READ_REG(hw, IXGBE_LINKS);
  2336. }
  2337. } else {
  2338. if (links_reg & IXGBE_LINKS_UP)
  2339. *link_up = true;
  2340. else
  2341. *link_up = false;
  2342. }
  2343. if ((links_reg & IXGBE_LINKS_SPEED_82599) ==
  2344. IXGBE_LINKS_SPEED_10G_82599)
  2345. *speed = IXGBE_LINK_SPEED_10GB_FULL;
  2346. else if ((links_reg & IXGBE_LINKS_SPEED_82599) ==
  2347. IXGBE_LINKS_SPEED_1G_82599)
  2348. *speed = IXGBE_LINK_SPEED_1GB_FULL;
  2349. else
  2350. *speed = IXGBE_LINK_SPEED_100_FULL;
  2351. /* if link is down, zero out the current_mode */
  2352. if (*link_up == false) {
  2353. hw->fc.current_mode = ixgbe_fc_none;
  2354. hw->fc.fc_was_autonegged = false;
  2355. }
  2356. return 0;
  2357. }
  2358. /**
  2359. * ixgbe_get_wwn_prefix_generic - Get alternative WWNN/WWPN prefix from
  2360. * the EEPROM
  2361. * @hw: pointer to hardware structure
  2362. * @wwnn_prefix: the alternative WWNN prefix
  2363. * @wwpn_prefix: the alternative WWPN prefix
  2364. *
  2365. * This function will read the EEPROM from the alternative SAN MAC address
  2366. * block to check the support for the alternative WWNN/WWPN prefix support.
  2367. **/
  2368. s32 ixgbe_get_wwn_prefix_generic(struct ixgbe_hw *hw, u16 *wwnn_prefix,
  2369. u16 *wwpn_prefix)
  2370. {
  2371. u16 offset, caps;
  2372. u16 alt_san_mac_blk_offset;
  2373. /* clear output first */
  2374. *wwnn_prefix = 0xFFFF;
  2375. *wwpn_prefix = 0xFFFF;
  2376. /* check if alternative SAN MAC is supported */
  2377. hw->eeprom.ops.read(hw, IXGBE_ALT_SAN_MAC_ADDR_BLK_PTR,
  2378. &alt_san_mac_blk_offset);
  2379. if ((alt_san_mac_blk_offset == 0) ||
  2380. (alt_san_mac_blk_offset == 0xFFFF))
  2381. goto wwn_prefix_out;
  2382. /* check capability in alternative san mac address block */
  2383. offset = alt_san_mac_blk_offset + IXGBE_ALT_SAN_MAC_ADDR_CAPS_OFFSET;
  2384. hw->eeprom.ops.read(hw, offset, &caps);
  2385. if (!(caps & IXGBE_ALT_SAN_MAC_ADDR_CAPS_ALTWWN))
  2386. goto wwn_prefix_out;
  2387. /* get the corresponding prefix for WWNN/WWPN */
  2388. offset = alt_san_mac_blk_offset + IXGBE_ALT_SAN_MAC_ADDR_WWNN_OFFSET;
  2389. hw->eeprom.ops.read(hw, offset, wwnn_prefix);
  2390. offset = alt_san_mac_blk_offset + IXGBE_ALT_SAN_MAC_ADDR_WWPN_OFFSET;
  2391. hw->eeprom.ops.read(hw, offset, wwpn_prefix);
  2392. wwn_prefix_out:
  2393. return 0;
  2394. }