ixgbe_common.c 79 KB

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