ixgbe_common.c 79 KB

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