ixgbe_common.c 78 KB

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