ixgbe_82599.c 87 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784
  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 "ixgbe.h"
  24. #include "ixgbe_phy.h"
  25. #include "ixgbe_mbx.h"
  26. #define IXGBE_82599_MAX_TX_QUEUES 128
  27. #define IXGBE_82599_MAX_RX_QUEUES 128
  28. #define IXGBE_82599_RAR_ENTRIES 128
  29. #define IXGBE_82599_MC_TBL_SIZE 128
  30. #define IXGBE_82599_VFT_TBL_SIZE 128
  31. void ixgbe_disable_tx_laser_multispeed_fiber(struct ixgbe_hw *hw);
  32. void ixgbe_enable_tx_laser_multispeed_fiber(struct ixgbe_hw *hw);
  33. void ixgbe_flap_tx_laser_multispeed_fiber(struct ixgbe_hw *hw);
  34. s32 ixgbe_setup_mac_link_multispeed_fiber(struct ixgbe_hw *hw,
  35. ixgbe_link_speed speed,
  36. bool autoneg,
  37. bool autoneg_wait_to_complete);
  38. static s32 ixgbe_setup_mac_link_smartspeed(struct ixgbe_hw *hw,
  39. ixgbe_link_speed speed,
  40. bool autoneg,
  41. bool autoneg_wait_to_complete);
  42. s32 ixgbe_start_mac_link_82599(struct ixgbe_hw *hw,
  43. bool autoneg_wait_to_complete);
  44. s32 ixgbe_setup_mac_link_82599(struct ixgbe_hw *hw,
  45. ixgbe_link_speed speed,
  46. bool autoneg,
  47. bool autoneg_wait_to_complete);
  48. static s32 ixgbe_get_copper_link_capabilities_82599(struct ixgbe_hw *hw,
  49. ixgbe_link_speed *speed,
  50. bool *autoneg);
  51. static s32 ixgbe_setup_copper_link_82599(struct ixgbe_hw *hw,
  52. ixgbe_link_speed speed,
  53. bool autoneg,
  54. bool autoneg_wait_to_complete);
  55. static s32 ixgbe_verify_fw_version_82599(struct ixgbe_hw *hw);
  56. static void ixgbe_init_mac_link_ops_82599(struct ixgbe_hw *hw)
  57. {
  58. struct ixgbe_mac_info *mac = &hw->mac;
  59. if (hw->phy.multispeed_fiber) {
  60. /* Set up dual speed SFP+ support */
  61. mac->ops.setup_link = &ixgbe_setup_mac_link_multispeed_fiber;
  62. mac->ops.disable_tx_laser =
  63. &ixgbe_disable_tx_laser_multispeed_fiber;
  64. mac->ops.enable_tx_laser =
  65. &ixgbe_enable_tx_laser_multispeed_fiber;
  66. mac->ops.flap_tx_laser = &ixgbe_flap_tx_laser_multispeed_fiber;
  67. } else {
  68. mac->ops.disable_tx_laser = NULL;
  69. mac->ops.enable_tx_laser = NULL;
  70. mac->ops.flap_tx_laser = NULL;
  71. if ((mac->ops.get_media_type(hw) ==
  72. ixgbe_media_type_backplane) &&
  73. (hw->phy.smart_speed == ixgbe_smart_speed_auto ||
  74. hw->phy.smart_speed == ixgbe_smart_speed_on))
  75. mac->ops.setup_link = &ixgbe_setup_mac_link_smartspeed;
  76. else
  77. mac->ops.setup_link = &ixgbe_setup_mac_link_82599;
  78. }
  79. }
  80. static s32 ixgbe_setup_sfp_modules_82599(struct ixgbe_hw *hw)
  81. {
  82. s32 ret_val = 0;
  83. u16 list_offset, data_offset, data_value;
  84. if (hw->phy.sfp_type != ixgbe_sfp_type_unknown) {
  85. ixgbe_init_mac_link_ops_82599(hw);
  86. hw->phy.ops.reset = NULL;
  87. ret_val = ixgbe_get_sfp_init_sequence_offsets(hw, &list_offset,
  88. &data_offset);
  89. if (ret_val != 0)
  90. goto setup_sfp_out;
  91. /* PHY config will finish before releasing the semaphore */
  92. ret_val = ixgbe_acquire_swfw_sync(hw, IXGBE_GSSR_MAC_CSR_SM);
  93. if (ret_val != 0) {
  94. ret_val = IXGBE_ERR_SWFW_SYNC;
  95. goto setup_sfp_out;
  96. }
  97. hw->eeprom.ops.read(hw, ++data_offset, &data_value);
  98. while (data_value != 0xffff) {
  99. IXGBE_WRITE_REG(hw, IXGBE_CORECTL, data_value);
  100. IXGBE_WRITE_FLUSH(hw);
  101. hw->eeprom.ops.read(hw, ++data_offset, &data_value);
  102. }
  103. /* Now restart DSP by setting Restart_AN */
  104. IXGBE_WRITE_REG(hw, IXGBE_AUTOC,
  105. (IXGBE_READ_REG(hw, IXGBE_AUTOC) | IXGBE_AUTOC_AN_RESTART));
  106. /* Release the semaphore */
  107. ixgbe_release_swfw_sync(hw, IXGBE_GSSR_MAC_CSR_SM);
  108. /* Delay obtaining semaphore again to allow FW access */
  109. msleep(hw->eeprom.semaphore_delay);
  110. }
  111. setup_sfp_out:
  112. return ret_val;
  113. }
  114. /**
  115. * ixgbe_get_pcie_msix_count_82599 - Gets MSI-X vector count
  116. * @hw: pointer to hardware structure
  117. *
  118. * Read PCIe configuration space, and get the MSI-X vector count from
  119. * the capabilities table.
  120. **/
  121. static u32 ixgbe_get_pcie_msix_count_82599(struct ixgbe_hw *hw)
  122. {
  123. struct ixgbe_adapter *adapter = hw->back;
  124. u16 msix_count;
  125. pci_read_config_word(adapter->pdev, IXGBE_PCIE_MSIX_82599_CAPS,
  126. &msix_count);
  127. msix_count &= IXGBE_PCIE_MSIX_TBL_SZ_MASK;
  128. /* MSI-X count is zero-based in HW, so increment to give proper value */
  129. msix_count++;
  130. return msix_count;
  131. }
  132. static s32 ixgbe_get_invariants_82599(struct ixgbe_hw *hw)
  133. {
  134. struct ixgbe_mac_info *mac = &hw->mac;
  135. ixgbe_init_mac_link_ops_82599(hw);
  136. mac->mcft_size = IXGBE_82599_MC_TBL_SIZE;
  137. mac->vft_size = IXGBE_82599_VFT_TBL_SIZE;
  138. mac->num_rar_entries = IXGBE_82599_RAR_ENTRIES;
  139. mac->max_rx_queues = IXGBE_82599_MAX_RX_QUEUES;
  140. mac->max_tx_queues = IXGBE_82599_MAX_TX_QUEUES;
  141. mac->max_msix_vectors = ixgbe_get_pcie_msix_count_82599(hw);
  142. return 0;
  143. }
  144. /**
  145. * ixgbe_init_phy_ops_82599 - PHY/SFP specific init
  146. * @hw: pointer to hardware structure
  147. *
  148. * Initialize any function pointers that were not able to be
  149. * set during get_invariants because the PHY/SFP type was
  150. * not known. Perform the SFP init if necessary.
  151. *
  152. **/
  153. static s32 ixgbe_init_phy_ops_82599(struct ixgbe_hw *hw)
  154. {
  155. struct ixgbe_mac_info *mac = &hw->mac;
  156. struct ixgbe_phy_info *phy = &hw->phy;
  157. s32 ret_val = 0;
  158. /* Identify the PHY or SFP module */
  159. ret_val = phy->ops.identify(hw);
  160. /* Setup function pointers based on detected SFP module and speeds */
  161. ixgbe_init_mac_link_ops_82599(hw);
  162. /* If copper media, overwrite with copper function pointers */
  163. if (mac->ops.get_media_type(hw) == ixgbe_media_type_copper) {
  164. mac->ops.setup_link = &ixgbe_setup_copper_link_82599;
  165. mac->ops.get_link_capabilities =
  166. &ixgbe_get_copper_link_capabilities_82599;
  167. }
  168. /* Set necessary function pointers based on phy type */
  169. switch (hw->phy.type) {
  170. case ixgbe_phy_tn:
  171. phy->ops.check_link = &ixgbe_check_phy_link_tnx;
  172. phy->ops.get_firmware_version =
  173. &ixgbe_get_phy_firmware_version_tnx;
  174. break;
  175. default:
  176. break;
  177. }
  178. return ret_val;
  179. }
  180. /**
  181. * ixgbe_get_link_capabilities_82599 - Determines link capabilities
  182. * @hw: pointer to hardware structure
  183. * @speed: pointer to link speed
  184. * @negotiation: true when autoneg or autotry is enabled
  185. *
  186. * Determines the link capabilities by reading the AUTOC register.
  187. **/
  188. static s32 ixgbe_get_link_capabilities_82599(struct ixgbe_hw *hw,
  189. ixgbe_link_speed *speed,
  190. bool *negotiation)
  191. {
  192. s32 status = 0;
  193. u32 autoc = 0;
  194. /*
  195. * Determine link capabilities based on the stored value of AUTOC,
  196. * which represents EEPROM defaults. If AUTOC value has not been
  197. * stored, use the current register value.
  198. */
  199. if (hw->mac.orig_link_settings_stored)
  200. autoc = hw->mac.orig_autoc;
  201. else
  202. autoc = IXGBE_READ_REG(hw, IXGBE_AUTOC);
  203. switch (autoc & IXGBE_AUTOC_LMS_MASK) {
  204. case IXGBE_AUTOC_LMS_1G_LINK_NO_AN:
  205. *speed = IXGBE_LINK_SPEED_1GB_FULL;
  206. *negotiation = false;
  207. break;
  208. case IXGBE_AUTOC_LMS_10G_LINK_NO_AN:
  209. *speed = IXGBE_LINK_SPEED_10GB_FULL;
  210. *negotiation = false;
  211. break;
  212. case IXGBE_AUTOC_LMS_1G_AN:
  213. *speed = IXGBE_LINK_SPEED_1GB_FULL;
  214. *negotiation = true;
  215. break;
  216. case IXGBE_AUTOC_LMS_10G_SERIAL:
  217. *speed = IXGBE_LINK_SPEED_10GB_FULL;
  218. *negotiation = false;
  219. break;
  220. case IXGBE_AUTOC_LMS_KX4_KX_KR:
  221. case IXGBE_AUTOC_LMS_KX4_KX_KR_1G_AN:
  222. *speed = IXGBE_LINK_SPEED_UNKNOWN;
  223. if (autoc & IXGBE_AUTOC_KR_SUPP)
  224. *speed |= IXGBE_LINK_SPEED_10GB_FULL;
  225. if (autoc & IXGBE_AUTOC_KX4_SUPP)
  226. *speed |= IXGBE_LINK_SPEED_10GB_FULL;
  227. if (autoc & IXGBE_AUTOC_KX_SUPP)
  228. *speed |= IXGBE_LINK_SPEED_1GB_FULL;
  229. *negotiation = true;
  230. break;
  231. case IXGBE_AUTOC_LMS_KX4_KX_KR_SGMII:
  232. *speed = IXGBE_LINK_SPEED_100_FULL;
  233. if (autoc & IXGBE_AUTOC_KR_SUPP)
  234. *speed |= IXGBE_LINK_SPEED_10GB_FULL;
  235. if (autoc & IXGBE_AUTOC_KX4_SUPP)
  236. *speed |= IXGBE_LINK_SPEED_10GB_FULL;
  237. if (autoc & IXGBE_AUTOC_KX_SUPP)
  238. *speed |= IXGBE_LINK_SPEED_1GB_FULL;
  239. *negotiation = true;
  240. break;
  241. case IXGBE_AUTOC_LMS_SGMII_1G_100M:
  242. *speed = IXGBE_LINK_SPEED_1GB_FULL | IXGBE_LINK_SPEED_100_FULL;
  243. *negotiation = false;
  244. break;
  245. default:
  246. status = IXGBE_ERR_LINK_SETUP;
  247. goto out;
  248. break;
  249. }
  250. if (hw->phy.multispeed_fiber) {
  251. *speed |= IXGBE_LINK_SPEED_10GB_FULL |
  252. IXGBE_LINK_SPEED_1GB_FULL;
  253. *negotiation = true;
  254. }
  255. out:
  256. return status;
  257. }
  258. /**
  259. * ixgbe_get_copper_link_capabilities_82599 - Determines link capabilities
  260. * @hw: pointer to hardware structure
  261. * @speed: pointer to link speed
  262. * @autoneg: boolean auto-negotiation value
  263. *
  264. * Determines the link capabilities by reading the AUTOC register.
  265. **/
  266. static s32 ixgbe_get_copper_link_capabilities_82599(struct ixgbe_hw *hw,
  267. ixgbe_link_speed *speed,
  268. bool *autoneg)
  269. {
  270. s32 status = IXGBE_ERR_LINK_SETUP;
  271. u16 speed_ability;
  272. *speed = 0;
  273. *autoneg = true;
  274. status = hw->phy.ops.read_reg(hw, MDIO_SPEED, MDIO_MMD_PMAPMD,
  275. &speed_ability);
  276. if (status == 0) {
  277. if (speed_ability & MDIO_SPEED_10G)
  278. *speed |= IXGBE_LINK_SPEED_10GB_FULL;
  279. if (speed_ability & MDIO_PMA_SPEED_1000)
  280. *speed |= IXGBE_LINK_SPEED_1GB_FULL;
  281. }
  282. return status;
  283. }
  284. /**
  285. * ixgbe_get_media_type_82599 - Get media type
  286. * @hw: pointer to hardware structure
  287. *
  288. * Returns the media type (fiber, copper, backplane)
  289. **/
  290. static enum ixgbe_media_type ixgbe_get_media_type_82599(struct ixgbe_hw *hw)
  291. {
  292. enum ixgbe_media_type media_type;
  293. /* Detect if there is a copper PHY attached. */
  294. if (hw->phy.type == ixgbe_phy_cu_unknown ||
  295. hw->phy.type == ixgbe_phy_tn) {
  296. media_type = ixgbe_media_type_copper;
  297. goto out;
  298. }
  299. switch (hw->device_id) {
  300. case IXGBE_DEV_ID_82599_KX4:
  301. case IXGBE_DEV_ID_82599_KX4_MEZZ:
  302. case IXGBE_DEV_ID_82599_COMBO_BACKPLANE:
  303. case IXGBE_DEV_ID_82599_KR:
  304. case IXGBE_DEV_ID_82599_XAUI_LOM:
  305. /* Default device ID is mezzanine card KX/KX4 */
  306. media_type = ixgbe_media_type_backplane;
  307. break;
  308. case IXGBE_DEV_ID_82599_SFP:
  309. case IXGBE_DEV_ID_82599_SFP_EM:
  310. media_type = ixgbe_media_type_fiber;
  311. break;
  312. case IXGBE_DEV_ID_82599_CX4:
  313. media_type = ixgbe_media_type_cx4;
  314. break;
  315. default:
  316. media_type = ixgbe_media_type_unknown;
  317. break;
  318. }
  319. out:
  320. return media_type;
  321. }
  322. /**
  323. * ixgbe_start_mac_link_82599 - Setup MAC link settings
  324. * @hw: pointer to hardware structure
  325. * @autoneg_wait_to_complete: true when waiting for completion is needed
  326. *
  327. * Configures link settings based on values in the ixgbe_hw struct.
  328. * Restarts the link. Performs autonegotiation if needed.
  329. **/
  330. s32 ixgbe_start_mac_link_82599(struct ixgbe_hw *hw,
  331. bool autoneg_wait_to_complete)
  332. {
  333. u32 autoc_reg;
  334. u32 links_reg;
  335. u32 i;
  336. s32 status = 0;
  337. /* Restart link */
  338. autoc_reg = IXGBE_READ_REG(hw, IXGBE_AUTOC);
  339. autoc_reg |= IXGBE_AUTOC_AN_RESTART;
  340. IXGBE_WRITE_REG(hw, IXGBE_AUTOC, autoc_reg);
  341. /* Only poll for autoneg to complete if specified to do so */
  342. if (autoneg_wait_to_complete) {
  343. if ((autoc_reg & IXGBE_AUTOC_LMS_MASK) ==
  344. IXGBE_AUTOC_LMS_KX4_KX_KR ||
  345. (autoc_reg & IXGBE_AUTOC_LMS_MASK) ==
  346. IXGBE_AUTOC_LMS_KX4_KX_KR_1G_AN ||
  347. (autoc_reg & IXGBE_AUTOC_LMS_MASK) ==
  348. IXGBE_AUTOC_LMS_KX4_KX_KR_SGMII) {
  349. links_reg = 0; /* Just in case Autoneg time = 0 */
  350. for (i = 0; i < IXGBE_AUTO_NEG_TIME; i++) {
  351. links_reg = IXGBE_READ_REG(hw, IXGBE_LINKS);
  352. if (links_reg & IXGBE_LINKS_KX_AN_COMP)
  353. break;
  354. msleep(100);
  355. }
  356. if (!(links_reg & IXGBE_LINKS_KX_AN_COMP)) {
  357. status = IXGBE_ERR_AUTONEG_NOT_COMPLETE;
  358. hw_dbg(hw, "Autoneg did not complete.\n");
  359. }
  360. }
  361. }
  362. /* Add delay to filter out noises during initial link setup */
  363. msleep(50);
  364. return status;
  365. }
  366. /**
  367. * ixgbe_disable_tx_laser_multispeed_fiber - Disable Tx laser
  368. * @hw: pointer to hardware structure
  369. *
  370. * The base drivers may require better control over SFP+ module
  371. * PHY states. This includes selectively shutting down the Tx
  372. * laser on the PHY, effectively halting physical link.
  373. **/
  374. void ixgbe_disable_tx_laser_multispeed_fiber(struct ixgbe_hw *hw)
  375. {
  376. u32 esdp_reg = IXGBE_READ_REG(hw, IXGBE_ESDP);
  377. /* Disable tx laser; allow 100us to go dark per spec */
  378. esdp_reg |= IXGBE_ESDP_SDP3;
  379. IXGBE_WRITE_REG(hw, IXGBE_ESDP, esdp_reg);
  380. IXGBE_WRITE_FLUSH(hw);
  381. udelay(100);
  382. }
  383. /**
  384. * ixgbe_enable_tx_laser_multispeed_fiber - Enable Tx laser
  385. * @hw: pointer to hardware structure
  386. *
  387. * The base drivers may require better control over SFP+ module
  388. * PHY states. This includes selectively turning on the Tx
  389. * laser on the PHY, effectively starting physical link.
  390. **/
  391. void ixgbe_enable_tx_laser_multispeed_fiber(struct ixgbe_hw *hw)
  392. {
  393. u32 esdp_reg = IXGBE_READ_REG(hw, IXGBE_ESDP);
  394. /* Enable tx laser; allow 100ms to light up */
  395. esdp_reg &= ~IXGBE_ESDP_SDP3;
  396. IXGBE_WRITE_REG(hw, IXGBE_ESDP, esdp_reg);
  397. IXGBE_WRITE_FLUSH(hw);
  398. msleep(100);
  399. }
  400. /**
  401. * ixgbe_flap_tx_laser_multispeed_fiber - Flap Tx laser
  402. * @hw: pointer to hardware structure
  403. *
  404. * When the driver changes the link speeds that it can support,
  405. * it sets autotry_restart to true to indicate that we need to
  406. * initiate a new autotry session with the link partner. To do
  407. * so, we set the speed then disable and re-enable the tx laser, to
  408. * alert the link partner that it also needs to restart autotry on its
  409. * end. This is consistent with true clause 37 autoneg, which also
  410. * involves a loss of signal.
  411. **/
  412. void ixgbe_flap_tx_laser_multispeed_fiber(struct ixgbe_hw *hw)
  413. {
  414. hw_dbg(hw, "ixgbe_flap_tx_laser_multispeed_fiber\n");
  415. if (hw->mac.autotry_restart) {
  416. ixgbe_disable_tx_laser_multispeed_fiber(hw);
  417. ixgbe_enable_tx_laser_multispeed_fiber(hw);
  418. hw->mac.autotry_restart = false;
  419. }
  420. }
  421. /**
  422. * ixgbe_setup_mac_link_multispeed_fiber - Set MAC link speed
  423. * @hw: pointer to hardware structure
  424. * @speed: new link speed
  425. * @autoneg: true if autonegotiation enabled
  426. * @autoneg_wait_to_complete: true when waiting for completion is needed
  427. *
  428. * Set the link speed in the AUTOC register and restarts link.
  429. **/
  430. s32 ixgbe_setup_mac_link_multispeed_fiber(struct ixgbe_hw *hw,
  431. ixgbe_link_speed speed,
  432. bool autoneg,
  433. bool autoneg_wait_to_complete)
  434. {
  435. s32 status = 0;
  436. ixgbe_link_speed phy_link_speed;
  437. ixgbe_link_speed highest_link_speed = IXGBE_LINK_SPEED_UNKNOWN;
  438. u32 speedcnt = 0;
  439. u32 esdp_reg = IXGBE_READ_REG(hw, IXGBE_ESDP);
  440. bool link_up = false;
  441. bool negotiation;
  442. int i;
  443. /* Mask off requested but non-supported speeds */
  444. hw->mac.ops.get_link_capabilities(hw, &phy_link_speed, &negotiation);
  445. speed &= phy_link_speed;
  446. /*
  447. * Try each speed one by one, highest priority first. We do this in
  448. * software because 10gb fiber doesn't support speed autonegotiation.
  449. */
  450. if (speed & IXGBE_LINK_SPEED_10GB_FULL) {
  451. speedcnt++;
  452. highest_link_speed = IXGBE_LINK_SPEED_10GB_FULL;
  453. /* If we already have link at this speed, just jump out */
  454. hw->mac.ops.check_link(hw, &phy_link_speed, &link_up, false);
  455. if ((phy_link_speed == IXGBE_LINK_SPEED_10GB_FULL) && link_up)
  456. goto out;
  457. /* Set the module link speed */
  458. esdp_reg |= (IXGBE_ESDP_SDP5_DIR | IXGBE_ESDP_SDP5);
  459. IXGBE_WRITE_REG(hw, IXGBE_ESDP, esdp_reg);
  460. IXGBE_WRITE_FLUSH(hw);
  461. /* Allow module to change analog characteristics (1G->10G) */
  462. msleep(40);
  463. status = ixgbe_setup_mac_link_82599(hw,
  464. IXGBE_LINK_SPEED_10GB_FULL,
  465. autoneg,
  466. autoneg_wait_to_complete);
  467. if (status != 0)
  468. return status;
  469. /* Flap the tx laser if it has not already been done */
  470. hw->mac.ops.flap_tx_laser(hw);
  471. /*
  472. * Wait for the controller to acquire link. Per IEEE 802.3ap,
  473. * Section 73.10.2, we may have to wait up to 500ms if KR is
  474. * attempted. 82599 uses the same timing for 10g SFI.
  475. */
  476. for (i = 0; i < 5; i++) {
  477. /* Wait for the link partner to also set speed */
  478. msleep(100);
  479. /* If we have link, just jump out */
  480. hw->mac.ops.check_link(hw, &phy_link_speed,
  481. &link_up, false);
  482. if (link_up)
  483. goto out;
  484. }
  485. }
  486. if (speed & IXGBE_LINK_SPEED_1GB_FULL) {
  487. speedcnt++;
  488. if (highest_link_speed == IXGBE_LINK_SPEED_UNKNOWN)
  489. highest_link_speed = IXGBE_LINK_SPEED_1GB_FULL;
  490. /* If we already have link at this speed, just jump out */
  491. hw->mac.ops.check_link(hw, &phy_link_speed, &link_up, false);
  492. if ((phy_link_speed == IXGBE_LINK_SPEED_1GB_FULL) && link_up)
  493. goto out;
  494. /* Set the module link speed */
  495. esdp_reg &= ~IXGBE_ESDP_SDP5;
  496. esdp_reg |= IXGBE_ESDP_SDP5_DIR;
  497. IXGBE_WRITE_REG(hw, IXGBE_ESDP, esdp_reg);
  498. IXGBE_WRITE_FLUSH(hw);
  499. /* Allow module to change analog characteristics (10G->1G) */
  500. msleep(40);
  501. status = ixgbe_setup_mac_link_82599(hw,
  502. IXGBE_LINK_SPEED_1GB_FULL,
  503. autoneg,
  504. autoneg_wait_to_complete);
  505. if (status != 0)
  506. return status;
  507. /* Flap the tx laser if it has not already been done */
  508. hw->mac.ops.flap_tx_laser(hw);
  509. /* Wait for the link partner to also set speed */
  510. msleep(100);
  511. /* If we have link, just jump out */
  512. hw->mac.ops.check_link(hw, &phy_link_speed, &link_up, false);
  513. if (link_up)
  514. goto out;
  515. }
  516. /*
  517. * We didn't get link. Configure back to the highest speed we tried,
  518. * (if there was more than one). We call ourselves back with just the
  519. * single highest speed that the user requested.
  520. */
  521. if (speedcnt > 1)
  522. status = ixgbe_setup_mac_link_multispeed_fiber(hw,
  523. highest_link_speed,
  524. autoneg,
  525. autoneg_wait_to_complete);
  526. out:
  527. /* Set autoneg_advertised value based on input link speed */
  528. hw->phy.autoneg_advertised = 0;
  529. if (speed & IXGBE_LINK_SPEED_10GB_FULL)
  530. hw->phy.autoneg_advertised |= IXGBE_LINK_SPEED_10GB_FULL;
  531. if (speed & IXGBE_LINK_SPEED_1GB_FULL)
  532. hw->phy.autoneg_advertised |= IXGBE_LINK_SPEED_1GB_FULL;
  533. return status;
  534. }
  535. /**
  536. * ixgbe_setup_mac_link_smartspeed - Set MAC link speed using SmartSpeed
  537. * @hw: pointer to hardware structure
  538. * @speed: new link speed
  539. * @autoneg: true if autonegotiation enabled
  540. * @autoneg_wait_to_complete: true when waiting for completion is needed
  541. *
  542. * Implements the Intel SmartSpeed algorithm.
  543. **/
  544. static s32 ixgbe_setup_mac_link_smartspeed(struct ixgbe_hw *hw,
  545. ixgbe_link_speed speed, bool autoneg,
  546. bool autoneg_wait_to_complete)
  547. {
  548. s32 status = 0;
  549. ixgbe_link_speed link_speed;
  550. s32 i, j;
  551. bool link_up = false;
  552. u32 autoc_reg = IXGBE_READ_REG(hw, IXGBE_AUTOC);
  553. struct ixgbe_adapter *adapter = hw->back;
  554. hw_dbg(hw, "ixgbe_setup_mac_link_smartspeed.\n");
  555. /* Set autoneg_advertised value based on input link speed */
  556. hw->phy.autoneg_advertised = 0;
  557. if (speed & IXGBE_LINK_SPEED_10GB_FULL)
  558. hw->phy.autoneg_advertised |= IXGBE_LINK_SPEED_10GB_FULL;
  559. if (speed & IXGBE_LINK_SPEED_1GB_FULL)
  560. hw->phy.autoneg_advertised |= IXGBE_LINK_SPEED_1GB_FULL;
  561. if (speed & IXGBE_LINK_SPEED_100_FULL)
  562. hw->phy.autoneg_advertised |= IXGBE_LINK_SPEED_100_FULL;
  563. /*
  564. * Implement Intel SmartSpeed algorithm. SmartSpeed will reduce the
  565. * autoneg advertisement if link is unable to be established at the
  566. * highest negotiated rate. This can sometimes happen due to integrity
  567. * issues with the physical media connection.
  568. */
  569. /* First, try to get link with full advertisement */
  570. hw->phy.smart_speed_active = false;
  571. for (j = 0; j < IXGBE_SMARTSPEED_MAX_RETRIES; j++) {
  572. status = ixgbe_setup_mac_link_82599(hw, speed, autoneg,
  573. autoneg_wait_to_complete);
  574. if (status)
  575. goto out;
  576. /*
  577. * Wait for the controller to acquire link. Per IEEE 802.3ap,
  578. * Section 73.10.2, we may have to wait up to 500ms if KR is
  579. * attempted, or 200ms if KX/KX4/BX/BX4 is attempted, per
  580. * Table 9 in the AN MAS.
  581. */
  582. for (i = 0; i < 5; i++) {
  583. mdelay(100);
  584. /* If we have link, just jump out */
  585. hw->mac.ops.check_link(hw, &link_speed,
  586. &link_up, false);
  587. if (link_up)
  588. goto out;
  589. }
  590. }
  591. /*
  592. * We didn't get link. If we advertised KR plus one of KX4/KX
  593. * (or BX4/BX), then disable KR and try again.
  594. */
  595. if (((autoc_reg & IXGBE_AUTOC_KR_SUPP) == 0) ||
  596. ((autoc_reg & IXGBE_AUTOC_KX4_KX_SUPP_MASK) == 0))
  597. goto out;
  598. /* Turn SmartSpeed on to disable KR support */
  599. hw->phy.smart_speed_active = true;
  600. status = ixgbe_setup_mac_link_82599(hw, speed, autoneg,
  601. autoneg_wait_to_complete);
  602. if (status)
  603. goto out;
  604. /*
  605. * Wait for the controller to acquire link. 600ms will allow for
  606. * the AN link_fail_inhibit_timer as well for multiple cycles of
  607. * parallel detect, both 10g and 1g. This allows for the maximum
  608. * connect attempts as defined in the AN MAS table 73-7.
  609. */
  610. for (i = 0; i < 6; i++) {
  611. mdelay(100);
  612. /* If we have link, just jump out */
  613. hw->mac.ops.check_link(hw, &link_speed,
  614. &link_up, false);
  615. if (link_up)
  616. goto out;
  617. }
  618. /* We didn't get link. Turn SmartSpeed back off. */
  619. hw->phy.smart_speed_active = false;
  620. status = ixgbe_setup_mac_link_82599(hw, speed, autoneg,
  621. autoneg_wait_to_complete);
  622. out:
  623. if (link_up && (link_speed == IXGBE_LINK_SPEED_1GB_FULL))
  624. netif_info(adapter, hw, adapter->netdev, "Smartspeed has"
  625. " downgraded the link speed from the maximum"
  626. " advertised\n");
  627. return status;
  628. }
  629. /**
  630. * ixgbe_check_mac_link_82599 - Determine link and speed status
  631. * @hw: pointer to hardware structure
  632. * @speed: pointer to link speed
  633. * @link_up: true when link is up
  634. * @link_up_wait_to_complete: bool used to wait for link up or not
  635. *
  636. * Reads the links register to determine if link is up and the current speed
  637. **/
  638. static s32 ixgbe_check_mac_link_82599(struct ixgbe_hw *hw,
  639. ixgbe_link_speed *speed,
  640. bool *link_up,
  641. bool link_up_wait_to_complete)
  642. {
  643. u32 links_reg;
  644. u32 i;
  645. links_reg = IXGBE_READ_REG(hw, IXGBE_LINKS);
  646. if (link_up_wait_to_complete) {
  647. for (i = 0; i < IXGBE_LINK_UP_TIME; i++) {
  648. if (links_reg & IXGBE_LINKS_UP) {
  649. *link_up = true;
  650. break;
  651. } else {
  652. *link_up = false;
  653. }
  654. msleep(100);
  655. links_reg = IXGBE_READ_REG(hw, IXGBE_LINKS);
  656. }
  657. } else {
  658. if (links_reg & IXGBE_LINKS_UP)
  659. *link_up = true;
  660. else
  661. *link_up = false;
  662. }
  663. if ((links_reg & IXGBE_LINKS_SPEED_82599) ==
  664. IXGBE_LINKS_SPEED_10G_82599)
  665. *speed = IXGBE_LINK_SPEED_10GB_FULL;
  666. else if ((links_reg & IXGBE_LINKS_SPEED_82599) ==
  667. IXGBE_LINKS_SPEED_1G_82599)
  668. *speed = IXGBE_LINK_SPEED_1GB_FULL;
  669. else
  670. *speed = IXGBE_LINK_SPEED_100_FULL;
  671. /* if link is down, zero out the current_mode */
  672. if (*link_up == false) {
  673. hw->fc.current_mode = ixgbe_fc_none;
  674. hw->fc.fc_was_autonegged = false;
  675. }
  676. return 0;
  677. }
  678. /**
  679. * ixgbe_setup_mac_link_82599 - Set MAC link speed
  680. * @hw: pointer to hardware structure
  681. * @speed: new link speed
  682. * @autoneg: true if autonegotiation enabled
  683. * @autoneg_wait_to_complete: true when waiting for completion is needed
  684. *
  685. * Set the link speed in the AUTOC register and restarts link.
  686. **/
  687. s32 ixgbe_setup_mac_link_82599(struct ixgbe_hw *hw,
  688. ixgbe_link_speed speed, bool autoneg,
  689. bool autoneg_wait_to_complete)
  690. {
  691. s32 status = 0;
  692. u32 autoc = IXGBE_READ_REG(hw, IXGBE_AUTOC);
  693. u32 autoc2 = IXGBE_READ_REG(hw, IXGBE_AUTOC2);
  694. u32 start_autoc = autoc;
  695. u32 orig_autoc = 0;
  696. u32 link_mode = autoc & IXGBE_AUTOC_LMS_MASK;
  697. u32 pma_pmd_1g = autoc & IXGBE_AUTOC_1G_PMA_PMD_MASK;
  698. u32 pma_pmd_10g_serial = autoc2 & IXGBE_AUTOC2_10G_SERIAL_PMA_PMD_MASK;
  699. u32 links_reg;
  700. u32 i;
  701. ixgbe_link_speed link_capabilities = IXGBE_LINK_SPEED_UNKNOWN;
  702. /* Check to see if speed passed in is supported. */
  703. hw->mac.ops.get_link_capabilities(hw, &link_capabilities, &autoneg);
  704. speed &= link_capabilities;
  705. if (speed == IXGBE_LINK_SPEED_UNKNOWN) {
  706. status = IXGBE_ERR_LINK_SETUP;
  707. goto out;
  708. }
  709. /* Use stored value (EEPROM defaults) of AUTOC to find KR/KX4 support*/
  710. if (hw->mac.orig_link_settings_stored)
  711. orig_autoc = hw->mac.orig_autoc;
  712. else
  713. orig_autoc = autoc;
  714. if (link_mode == IXGBE_AUTOC_LMS_KX4_KX_KR ||
  715. link_mode == IXGBE_AUTOC_LMS_KX4_KX_KR_1G_AN ||
  716. link_mode == IXGBE_AUTOC_LMS_KX4_KX_KR_SGMII) {
  717. /* Set KX4/KX/KR support according to speed requested */
  718. autoc &= ~(IXGBE_AUTOC_KX4_KX_SUPP_MASK | IXGBE_AUTOC_KR_SUPP);
  719. if (speed & IXGBE_LINK_SPEED_10GB_FULL)
  720. if (orig_autoc & IXGBE_AUTOC_KX4_SUPP)
  721. autoc |= IXGBE_AUTOC_KX4_SUPP;
  722. if ((orig_autoc & IXGBE_AUTOC_KR_SUPP) &&
  723. (hw->phy.smart_speed_active == false))
  724. autoc |= IXGBE_AUTOC_KR_SUPP;
  725. if (speed & IXGBE_LINK_SPEED_1GB_FULL)
  726. autoc |= IXGBE_AUTOC_KX_SUPP;
  727. } else if ((pma_pmd_1g == IXGBE_AUTOC_1G_SFI) &&
  728. (link_mode == IXGBE_AUTOC_LMS_1G_LINK_NO_AN ||
  729. link_mode == IXGBE_AUTOC_LMS_1G_AN)) {
  730. /* Switch from 1G SFI to 10G SFI if requested */
  731. if ((speed == IXGBE_LINK_SPEED_10GB_FULL) &&
  732. (pma_pmd_10g_serial == IXGBE_AUTOC2_10G_SFI)) {
  733. autoc &= ~IXGBE_AUTOC_LMS_MASK;
  734. autoc |= IXGBE_AUTOC_LMS_10G_SERIAL;
  735. }
  736. } else if ((pma_pmd_10g_serial == IXGBE_AUTOC2_10G_SFI) &&
  737. (link_mode == IXGBE_AUTOC_LMS_10G_SERIAL)) {
  738. /* Switch from 10G SFI to 1G SFI if requested */
  739. if ((speed == IXGBE_LINK_SPEED_1GB_FULL) &&
  740. (pma_pmd_1g == IXGBE_AUTOC_1G_SFI)) {
  741. autoc &= ~IXGBE_AUTOC_LMS_MASK;
  742. if (autoneg)
  743. autoc |= IXGBE_AUTOC_LMS_1G_AN;
  744. else
  745. autoc |= IXGBE_AUTOC_LMS_1G_LINK_NO_AN;
  746. }
  747. }
  748. if (autoc != start_autoc) {
  749. /* Restart link */
  750. autoc |= IXGBE_AUTOC_AN_RESTART;
  751. IXGBE_WRITE_REG(hw, IXGBE_AUTOC, autoc);
  752. /* Only poll for autoneg to complete if specified to do so */
  753. if (autoneg_wait_to_complete) {
  754. if (link_mode == IXGBE_AUTOC_LMS_KX4_KX_KR ||
  755. link_mode == IXGBE_AUTOC_LMS_KX4_KX_KR_1G_AN ||
  756. link_mode == IXGBE_AUTOC_LMS_KX4_KX_KR_SGMII) {
  757. links_reg = 0; /*Just in case Autoneg time=0*/
  758. for (i = 0; i < IXGBE_AUTO_NEG_TIME; i++) {
  759. links_reg =
  760. IXGBE_READ_REG(hw, IXGBE_LINKS);
  761. if (links_reg & IXGBE_LINKS_KX_AN_COMP)
  762. break;
  763. msleep(100);
  764. }
  765. if (!(links_reg & IXGBE_LINKS_KX_AN_COMP)) {
  766. status =
  767. IXGBE_ERR_AUTONEG_NOT_COMPLETE;
  768. hw_dbg(hw, "Autoneg did not "
  769. "complete.\n");
  770. }
  771. }
  772. }
  773. /* Add delay to filter out noises during initial link setup */
  774. msleep(50);
  775. }
  776. out:
  777. return status;
  778. }
  779. /**
  780. * ixgbe_setup_copper_link_82599 - Set the PHY autoneg advertised field
  781. * @hw: pointer to hardware structure
  782. * @speed: new link speed
  783. * @autoneg: true if autonegotiation enabled
  784. * @autoneg_wait_to_complete: true if waiting is needed to complete
  785. *
  786. * Restarts link on PHY and MAC based on settings passed in.
  787. **/
  788. static s32 ixgbe_setup_copper_link_82599(struct ixgbe_hw *hw,
  789. ixgbe_link_speed speed,
  790. bool autoneg,
  791. bool autoneg_wait_to_complete)
  792. {
  793. s32 status;
  794. /* Setup the PHY according to input speed */
  795. status = hw->phy.ops.setup_link_speed(hw, speed, autoneg,
  796. autoneg_wait_to_complete);
  797. /* Set up MAC */
  798. ixgbe_start_mac_link_82599(hw, autoneg_wait_to_complete);
  799. return status;
  800. }
  801. /**
  802. * ixgbe_reset_hw_82599 - Perform hardware reset
  803. * @hw: pointer to hardware structure
  804. *
  805. * Resets the hardware by resetting the transmit and receive units, masks
  806. * and clears all interrupts, perform a PHY reset, and perform a link (MAC)
  807. * reset.
  808. **/
  809. static s32 ixgbe_reset_hw_82599(struct ixgbe_hw *hw)
  810. {
  811. s32 status = 0;
  812. u32 ctrl;
  813. u32 i;
  814. u32 autoc;
  815. u32 autoc2;
  816. /* Call adapter stop to disable tx/rx and clear interrupts */
  817. hw->mac.ops.stop_adapter(hw);
  818. /* PHY ops must be identified and initialized prior to reset */
  819. /* Init PHY and function pointers, perform SFP setup */
  820. status = hw->phy.ops.init(hw);
  821. if (status == IXGBE_ERR_SFP_NOT_SUPPORTED)
  822. goto reset_hw_out;
  823. /* Setup SFP module if there is one present. */
  824. if (hw->phy.sfp_setup_needed) {
  825. status = hw->mac.ops.setup_sfp(hw);
  826. hw->phy.sfp_setup_needed = false;
  827. }
  828. /* Reset PHY */
  829. if (hw->phy.reset_disable == false && hw->phy.ops.reset != NULL)
  830. hw->phy.ops.reset(hw);
  831. /*
  832. * Prevent the PCI-E bus from from hanging by disabling PCI-E master
  833. * access and verify no pending requests before reset
  834. */
  835. status = ixgbe_disable_pcie_master(hw);
  836. if (status != 0) {
  837. status = IXGBE_ERR_MASTER_REQUESTS_PENDING;
  838. hw_dbg(hw, "PCI-E Master disable polling has failed.\n");
  839. }
  840. /*
  841. * Issue global reset to the MAC. This needs to be a SW reset.
  842. * If link reset is used, it might reset the MAC when mng is using it
  843. */
  844. ctrl = IXGBE_READ_REG(hw, IXGBE_CTRL);
  845. IXGBE_WRITE_REG(hw, IXGBE_CTRL, (ctrl | IXGBE_CTRL_RST));
  846. IXGBE_WRITE_FLUSH(hw);
  847. /* Poll for reset bit to self-clear indicating reset is complete */
  848. for (i = 0; i < 10; i++) {
  849. udelay(1);
  850. ctrl = IXGBE_READ_REG(hw, IXGBE_CTRL);
  851. if (!(ctrl & IXGBE_CTRL_RST))
  852. break;
  853. }
  854. if (ctrl & IXGBE_CTRL_RST) {
  855. status = IXGBE_ERR_RESET_FAILED;
  856. hw_dbg(hw, "Reset polling failed to complete.\n");
  857. }
  858. msleep(50);
  859. /*
  860. * Store the original AUTOC/AUTOC2 values if they have not been
  861. * stored off yet. Otherwise restore the stored original
  862. * values since the reset operation sets back to defaults.
  863. */
  864. autoc = IXGBE_READ_REG(hw, IXGBE_AUTOC);
  865. autoc2 = IXGBE_READ_REG(hw, IXGBE_AUTOC2);
  866. if (hw->mac.orig_link_settings_stored == false) {
  867. hw->mac.orig_autoc = autoc;
  868. hw->mac.orig_autoc2 = autoc2;
  869. hw->mac.orig_link_settings_stored = true;
  870. } else {
  871. if (autoc != hw->mac.orig_autoc)
  872. IXGBE_WRITE_REG(hw, IXGBE_AUTOC, (hw->mac.orig_autoc |
  873. IXGBE_AUTOC_AN_RESTART));
  874. if ((autoc2 & IXGBE_AUTOC2_UPPER_MASK) !=
  875. (hw->mac.orig_autoc2 & IXGBE_AUTOC2_UPPER_MASK)) {
  876. autoc2 &= ~IXGBE_AUTOC2_UPPER_MASK;
  877. autoc2 |= (hw->mac.orig_autoc2 &
  878. IXGBE_AUTOC2_UPPER_MASK);
  879. IXGBE_WRITE_REG(hw, IXGBE_AUTOC2, autoc2);
  880. }
  881. }
  882. /*
  883. * Store MAC address from RAR0, clear receive address registers, and
  884. * clear the multicast table. Also reset num_rar_entries to 128,
  885. * since we modify this value when programming the SAN MAC address.
  886. */
  887. hw->mac.num_rar_entries = 128;
  888. hw->mac.ops.init_rx_addrs(hw);
  889. /* Store the permanent mac address */
  890. hw->mac.ops.get_mac_addr(hw, hw->mac.perm_addr);
  891. /* Store the permanent SAN mac address */
  892. hw->mac.ops.get_san_mac_addr(hw, hw->mac.san_addr);
  893. /* Add the SAN MAC address to the RAR only if it's a valid address */
  894. if (ixgbe_validate_mac_addr(hw->mac.san_addr) == 0) {
  895. hw->mac.ops.set_rar(hw, hw->mac.num_rar_entries - 1,
  896. hw->mac.san_addr, 0, IXGBE_RAH_AV);
  897. /* Reserve the last RAR for the SAN MAC address */
  898. hw->mac.num_rar_entries--;
  899. }
  900. /* Store the alternative WWNN/WWPN prefix */
  901. hw->mac.ops.get_wwn_prefix(hw, &hw->mac.wwnn_prefix,
  902. &hw->mac.wwpn_prefix);
  903. reset_hw_out:
  904. return status;
  905. }
  906. /**
  907. * ixgbe_clear_vmdq_82599 - Disassociate a VMDq pool index from a rx address
  908. * @hw: pointer to hardware struct
  909. * @rar: receive address register index to disassociate
  910. * @vmdq: VMDq pool index to remove from the rar
  911. **/
  912. static s32 ixgbe_clear_vmdq_82599(struct ixgbe_hw *hw, u32 rar, u32 vmdq)
  913. {
  914. u32 mpsar_lo, mpsar_hi;
  915. u32 rar_entries = hw->mac.num_rar_entries;
  916. if (rar < rar_entries) {
  917. mpsar_lo = IXGBE_READ_REG(hw, IXGBE_MPSAR_LO(rar));
  918. mpsar_hi = IXGBE_READ_REG(hw, IXGBE_MPSAR_HI(rar));
  919. if (!mpsar_lo && !mpsar_hi)
  920. goto done;
  921. if (vmdq == IXGBE_CLEAR_VMDQ_ALL) {
  922. if (mpsar_lo) {
  923. IXGBE_WRITE_REG(hw, IXGBE_MPSAR_LO(rar), 0);
  924. mpsar_lo = 0;
  925. }
  926. if (mpsar_hi) {
  927. IXGBE_WRITE_REG(hw, IXGBE_MPSAR_HI(rar), 0);
  928. mpsar_hi = 0;
  929. }
  930. } else if (vmdq < 32) {
  931. mpsar_lo &= ~(1 << vmdq);
  932. IXGBE_WRITE_REG(hw, IXGBE_MPSAR_LO(rar), mpsar_lo);
  933. } else {
  934. mpsar_hi &= ~(1 << (vmdq - 32));
  935. IXGBE_WRITE_REG(hw, IXGBE_MPSAR_HI(rar), mpsar_hi);
  936. }
  937. /* was that the last pool using this rar? */
  938. if (mpsar_lo == 0 && mpsar_hi == 0 && rar != 0)
  939. hw->mac.ops.clear_rar(hw, rar);
  940. } else {
  941. hw_dbg(hw, "RAR index %d is out of range.\n", rar);
  942. }
  943. done:
  944. return 0;
  945. }
  946. /**
  947. * ixgbe_set_vmdq_82599 - Associate a VMDq pool index with a rx address
  948. * @hw: pointer to hardware struct
  949. * @rar: receive address register index to associate with a VMDq index
  950. * @vmdq: VMDq pool index
  951. **/
  952. static s32 ixgbe_set_vmdq_82599(struct ixgbe_hw *hw, u32 rar, u32 vmdq)
  953. {
  954. u32 mpsar;
  955. u32 rar_entries = hw->mac.num_rar_entries;
  956. if (rar < rar_entries) {
  957. if (vmdq < 32) {
  958. mpsar = IXGBE_READ_REG(hw, IXGBE_MPSAR_LO(rar));
  959. mpsar |= 1 << vmdq;
  960. IXGBE_WRITE_REG(hw, IXGBE_MPSAR_LO(rar), mpsar);
  961. } else {
  962. mpsar = IXGBE_READ_REG(hw, IXGBE_MPSAR_HI(rar));
  963. mpsar |= 1 << (vmdq - 32);
  964. IXGBE_WRITE_REG(hw, IXGBE_MPSAR_HI(rar), mpsar);
  965. }
  966. } else {
  967. hw_dbg(hw, "RAR index %d is out of range.\n", rar);
  968. }
  969. return 0;
  970. }
  971. /**
  972. * ixgbe_set_vfta_82599 - Set VLAN filter table
  973. * @hw: pointer to hardware structure
  974. * @vlan: VLAN id to write to VLAN filter
  975. * @vind: VMDq output index that maps queue to VLAN id in VFVFB
  976. * @vlan_on: boolean flag to turn on/off VLAN in VFVF
  977. *
  978. * Turn on/off specified VLAN in the VLAN filter table.
  979. **/
  980. static s32 ixgbe_set_vfta_82599(struct ixgbe_hw *hw, u32 vlan, u32 vind,
  981. bool vlan_on)
  982. {
  983. u32 regindex;
  984. u32 vlvf_index;
  985. u32 bitindex;
  986. u32 bits;
  987. u32 first_empty_slot;
  988. u32 vt_ctl;
  989. if (vlan > 4095)
  990. return IXGBE_ERR_PARAM;
  991. /*
  992. * this is a 2 part operation - first the VFTA, then the
  993. * VLVF and VLVFB if vind is set
  994. */
  995. /* Part 1
  996. * The VFTA is a bitstring made up of 128 32-bit registers
  997. * that enable the particular VLAN id, much like the MTA:
  998. * bits[11-5]: which register
  999. * bits[4-0]: which bit in the register
  1000. */
  1001. regindex = (vlan >> 5) & 0x7F;
  1002. bitindex = vlan & 0x1F;
  1003. bits = IXGBE_READ_REG(hw, IXGBE_VFTA(regindex));
  1004. if (vlan_on)
  1005. bits |= (1 << bitindex);
  1006. else
  1007. bits &= ~(1 << bitindex);
  1008. IXGBE_WRITE_REG(hw, IXGBE_VFTA(regindex), bits);
  1009. /* Part 2
  1010. * If VT mode is set
  1011. * Either vlan_on
  1012. * make sure the vlan is in VLVF
  1013. * set the vind bit in the matching VLVFB
  1014. * Or !vlan_on
  1015. * clear the pool bit and possibly the vind
  1016. */
  1017. vt_ctl = IXGBE_READ_REG(hw, IXGBE_VT_CTL);
  1018. if (!(vt_ctl & IXGBE_VT_CTL_VT_ENABLE))
  1019. goto out;
  1020. /* find the vlanid or the first empty slot */
  1021. first_empty_slot = 0;
  1022. for (vlvf_index = 1; vlvf_index < IXGBE_VLVF_ENTRIES; vlvf_index++) {
  1023. bits = IXGBE_READ_REG(hw, IXGBE_VLVF(vlvf_index));
  1024. if (!bits && !first_empty_slot)
  1025. first_empty_slot = vlvf_index;
  1026. else if ((bits & 0x0FFF) == vlan)
  1027. break;
  1028. }
  1029. if (vlvf_index >= IXGBE_VLVF_ENTRIES) {
  1030. if (first_empty_slot)
  1031. vlvf_index = first_empty_slot;
  1032. else {
  1033. hw_dbg(hw, "No space in VLVF.\n");
  1034. goto out;
  1035. }
  1036. }
  1037. if (vlan_on) {
  1038. /* set the pool bit */
  1039. if (vind < 32) {
  1040. bits = IXGBE_READ_REG(hw,
  1041. IXGBE_VLVFB(vlvf_index * 2));
  1042. bits |= (1 << vind);
  1043. IXGBE_WRITE_REG(hw,
  1044. IXGBE_VLVFB(vlvf_index * 2), bits);
  1045. } else {
  1046. bits = IXGBE_READ_REG(hw,
  1047. IXGBE_VLVFB((vlvf_index * 2) + 1));
  1048. bits |= (1 << (vind - 32));
  1049. IXGBE_WRITE_REG(hw,
  1050. IXGBE_VLVFB((vlvf_index * 2) + 1), bits);
  1051. }
  1052. } else {
  1053. /* clear the pool bit */
  1054. if (vind < 32) {
  1055. bits = IXGBE_READ_REG(hw,
  1056. IXGBE_VLVFB(vlvf_index * 2));
  1057. bits &= ~(1 << vind);
  1058. IXGBE_WRITE_REG(hw,
  1059. IXGBE_VLVFB(vlvf_index * 2), bits);
  1060. bits |= IXGBE_READ_REG(hw,
  1061. IXGBE_VLVFB((vlvf_index * 2) + 1));
  1062. } else {
  1063. bits = IXGBE_READ_REG(hw,
  1064. IXGBE_VLVFB((vlvf_index * 2) + 1));
  1065. bits &= ~(1 << (vind - 32));
  1066. IXGBE_WRITE_REG(hw,
  1067. IXGBE_VLVFB((vlvf_index * 2) + 1), bits);
  1068. bits |= IXGBE_READ_REG(hw,
  1069. IXGBE_VLVFB(vlvf_index * 2));
  1070. }
  1071. }
  1072. if (bits) {
  1073. IXGBE_WRITE_REG(hw, IXGBE_VLVF(vlvf_index),
  1074. (IXGBE_VLVF_VIEN | vlan));
  1075. /* if bits is non-zero then some pools/VFs are still
  1076. * using this VLAN ID. Force the VFTA entry to on */
  1077. bits = IXGBE_READ_REG(hw, IXGBE_VFTA(regindex));
  1078. bits |= (1 << bitindex);
  1079. IXGBE_WRITE_REG(hw, IXGBE_VFTA(regindex), bits);
  1080. }
  1081. else
  1082. IXGBE_WRITE_REG(hw, IXGBE_VLVF(vlvf_index), 0);
  1083. out:
  1084. return 0;
  1085. }
  1086. /**
  1087. * ixgbe_clear_vfta_82599 - Clear VLAN filter table
  1088. * @hw: pointer to hardware structure
  1089. *
  1090. * Clears the VLAN filer table, and the VMDq index associated with the filter
  1091. **/
  1092. static s32 ixgbe_clear_vfta_82599(struct ixgbe_hw *hw)
  1093. {
  1094. u32 offset;
  1095. for (offset = 0; offset < hw->mac.vft_size; offset++)
  1096. IXGBE_WRITE_REG(hw, IXGBE_VFTA(offset), 0);
  1097. for (offset = 0; offset < IXGBE_VLVF_ENTRIES; offset++) {
  1098. IXGBE_WRITE_REG(hw, IXGBE_VLVF(offset), 0);
  1099. IXGBE_WRITE_REG(hw, IXGBE_VLVFB(offset * 2), 0);
  1100. IXGBE_WRITE_REG(hw, IXGBE_VLVFB((offset * 2) + 1), 0);
  1101. }
  1102. return 0;
  1103. }
  1104. /**
  1105. * ixgbe_init_uta_tables_82599 - Initialize the Unicast Table Array
  1106. * @hw: pointer to hardware structure
  1107. **/
  1108. static s32 ixgbe_init_uta_tables_82599(struct ixgbe_hw *hw)
  1109. {
  1110. int i;
  1111. hw_dbg(hw, " Clearing UTA\n");
  1112. for (i = 0; i < 128; i++)
  1113. IXGBE_WRITE_REG(hw, IXGBE_UTA(i), 0);
  1114. return 0;
  1115. }
  1116. /**
  1117. * ixgbe_reinit_fdir_tables_82599 - Reinitialize Flow Director tables.
  1118. * @hw: pointer to hardware structure
  1119. **/
  1120. s32 ixgbe_reinit_fdir_tables_82599(struct ixgbe_hw *hw)
  1121. {
  1122. int i;
  1123. u32 fdirctrl = IXGBE_READ_REG(hw, IXGBE_FDIRCTRL);
  1124. fdirctrl &= ~IXGBE_FDIRCTRL_INIT_DONE;
  1125. /*
  1126. * Before starting reinitialization process,
  1127. * FDIRCMD.CMD must be zero.
  1128. */
  1129. for (i = 0; i < IXGBE_FDIRCMD_CMD_POLL; i++) {
  1130. if (!(IXGBE_READ_REG(hw, IXGBE_FDIRCMD) &
  1131. IXGBE_FDIRCMD_CMD_MASK))
  1132. break;
  1133. udelay(10);
  1134. }
  1135. if (i >= IXGBE_FDIRCMD_CMD_POLL) {
  1136. hw_dbg(hw ,"Flow Director previous command isn't complete, "
  1137. "aborting table re-initialization.\n");
  1138. return IXGBE_ERR_FDIR_REINIT_FAILED;
  1139. }
  1140. IXGBE_WRITE_REG(hw, IXGBE_FDIRFREE, 0);
  1141. IXGBE_WRITE_FLUSH(hw);
  1142. /*
  1143. * 82599 adapters flow director init flow cannot be restarted,
  1144. * Workaround 82599 silicon errata by performing the following steps
  1145. * before re-writing the FDIRCTRL control register with the same value.
  1146. * - write 1 to bit 8 of FDIRCMD register &
  1147. * - write 0 to bit 8 of FDIRCMD register
  1148. */
  1149. IXGBE_WRITE_REG(hw, IXGBE_FDIRCMD,
  1150. (IXGBE_READ_REG(hw, IXGBE_FDIRCMD) |
  1151. IXGBE_FDIRCMD_CLEARHT));
  1152. IXGBE_WRITE_FLUSH(hw);
  1153. IXGBE_WRITE_REG(hw, IXGBE_FDIRCMD,
  1154. (IXGBE_READ_REG(hw, IXGBE_FDIRCMD) &
  1155. ~IXGBE_FDIRCMD_CLEARHT));
  1156. IXGBE_WRITE_FLUSH(hw);
  1157. /*
  1158. * Clear FDIR Hash register to clear any leftover hashes
  1159. * waiting to be programmed.
  1160. */
  1161. IXGBE_WRITE_REG(hw, IXGBE_FDIRHASH, 0x00);
  1162. IXGBE_WRITE_FLUSH(hw);
  1163. IXGBE_WRITE_REG(hw, IXGBE_FDIRCTRL, fdirctrl);
  1164. IXGBE_WRITE_FLUSH(hw);
  1165. /* Poll init-done after we write FDIRCTRL register */
  1166. for (i = 0; i < IXGBE_FDIR_INIT_DONE_POLL; i++) {
  1167. if (IXGBE_READ_REG(hw, IXGBE_FDIRCTRL) &
  1168. IXGBE_FDIRCTRL_INIT_DONE)
  1169. break;
  1170. udelay(10);
  1171. }
  1172. if (i >= IXGBE_FDIR_INIT_DONE_POLL) {
  1173. hw_dbg(hw, "Flow Director Signature poll time exceeded!\n");
  1174. return IXGBE_ERR_FDIR_REINIT_FAILED;
  1175. }
  1176. /* Clear FDIR statistics registers (read to clear) */
  1177. IXGBE_READ_REG(hw, IXGBE_FDIRUSTAT);
  1178. IXGBE_READ_REG(hw, IXGBE_FDIRFSTAT);
  1179. IXGBE_READ_REG(hw, IXGBE_FDIRMATCH);
  1180. IXGBE_READ_REG(hw, IXGBE_FDIRMISS);
  1181. IXGBE_READ_REG(hw, IXGBE_FDIRLEN);
  1182. return 0;
  1183. }
  1184. /**
  1185. * ixgbe_init_fdir_signature_82599 - Initialize Flow Director signature filters
  1186. * @hw: pointer to hardware structure
  1187. * @pballoc: which mode to allocate filters with
  1188. **/
  1189. s32 ixgbe_init_fdir_signature_82599(struct ixgbe_hw *hw, u32 pballoc)
  1190. {
  1191. u32 fdirctrl = 0;
  1192. u32 pbsize;
  1193. int i;
  1194. /*
  1195. * Before enabling Flow Director, the Rx Packet Buffer size
  1196. * must be reduced. The new value is the current size minus
  1197. * flow director memory usage size.
  1198. */
  1199. pbsize = (1 << (IXGBE_FDIR_PBALLOC_SIZE_SHIFT + pballoc));
  1200. IXGBE_WRITE_REG(hw, IXGBE_RXPBSIZE(0),
  1201. (IXGBE_READ_REG(hw, IXGBE_RXPBSIZE(0)) - pbsize));
  1202. /*
  1203. * The defaults in the HW for RX PB 1-7 are not zero and so should be
  1204. * intialized to zero for non DCB mode otherwise actual total RX PB
  1205. * would be bigger than programmed and filter space would run into
  1206. * the PB 0 region.
  1207. */
  1208. for (i = 1; i < 8; i++)
  1209. IXGBE_WRITE_REG(hw, IXGBE_RXPBSIZE(i), 0);
  1210. /* Send interrupt when 64 filters are left */
  1211. fdirctrl |= 4 << IXGBE_FDIRCTRL_FULL_THRESH_SHIFT;
  1212. /* Set the maximum length per hash bucket to 0xA filters */
  1213. fdirctrl |= 0xA << IXGBE_FDIRCTRL_MAX_LENGTH_SHIFT;
  1214. switch (pballoc) {
  1215. case IXGBE_FDIR_PBALLOC_64K:
  1216. /* 8k - 1 signature filters */
  1217. fdirctrl |= IXGBE_FDIRCTRL_PBALLOC_64K;
  1218. break;
  1219. case IXGBE_FDIR_PBALLOC_128K:
  1220. /* 16k - 1 signature filters */
  1221. fdirctrl |= IXGBE_FDIRCTRL_PBALLOC_128K;
  1222. break;
  1223. case IXGBE_FDIR_PBALLOC_256K:
  1224. /* 32k - 1 signature filters */
  1225. fdirctrl |= IXGBE_FDIRCTRL_PBALLOC_256K;
  1226. break;
  1227. default:
  1228. /* bad value */
  1229. return IXGBE_ERR_CONFIG;
  1230. };
  1231. /* Move the flexible bytes to use the ethertype - shift 6 words */
  1232. fdirctrl |= (0x6 << IXGBE_FDIRCTRL_FLEX_SHIFT);
  1233. fdirctrl |= IXGBE_FDIRCTRL_REPORT_STATUS;
  1234. /* Prime the keys for hashing */
  1235. IXGBE_WRITE_REG(hw, IXGBE_FDIRHKEY,
  1236. htonl(IXGBE_ATR_BUCKET_HASH_KEY));
  1237. IXGBE_WRITE_REG(hw, IXGBE_FDIRSKEY,
  1238. htonl(IXGBE_ATR_SIGNATURE_HASH_KEY));
  1239. /*
  1240. * Poll init-done after we write the register. Estimated times:
  1241. * 10G: PBALLOC = 11b, timing is 60us
  1242. * 1G: PBALLOC = 11b, timing is 600us
  1243. * 100M: PBALLOC = 11b, timing is 6ms
  1244. *
  1245. * Multiple these timings by 4 if under full Rx load
  1246. *
  1247. * So we'll poll for IXGBE_FDIR_INIT_DONE_POLL times, sleeping for
  1248. * 1 msec per poll time. If we're at line rate and drop to 100M, then
  1249. * this might not finish in our poll time, but we can live with that
  1250. * for now.
  1251. */
  1252. IXGBE_WRITE_REG(hw, IXGBE_FDIRCTRL, fdirctrl);
  1253. IXGBE_WRITE_FLUSH(hw);
  1254. for (i = 0; i < IXGBE_FDIR_INIT_DONE_POLL; i++) {
  1255. if (IXGBE_READ_REG(hw, IXGBE_FDIRCTRL) &
  1256. IXGBE_FDIRCTRL_INIT_DONE)
  1257. break;
  1258. msleep(1);
  1259. }
  1260. if (i >= IXGBE_FDIR_INIT_DONE_POLL)
  1261. hw_dbg(hw, "Flow Director Signature poll time exceeded!\n");
  1262. return 0;
  1263. }
  1264. /**
  1265. * ixgbe_init_fdir_perfect_82599 - Initialize Flow Director perfect filters
  1266. * @hw: pointer to hardware structure
  1267. * @pballoc: which mode to allocate filters with
  1268. **/
  1269. s32 ixgbe_init_fdir_perfect_82599(struct ixgbe_hw *hw, u32 pballoc)
  1270. {
  1271. u32 fdirctrl = 0;
  1272. u32 pbsize;
  1273. int i;
  1274. /*
  1275. * Before enabling Flow Director, the Rx Packet Buffer size
  1276. * must be reduced. The new value is the current size minus
  1277. * flow director memory usage size.
  1278. */
  1279. pbsize = (1 << (IXGBE_FDIR_PBALLOC_SIZE_SHIFT + pballoc));
  1280. IXGBE_WRITE_REG(hw, IXGBE_RXPBSIZE(0),
  1281. (IXGBE_READ_REG(hw, IXGBE_RXPBSIZE(0)) - pbsize));
  1282. /*
  1283. * The defaults in the HW for RX PB 1-7 are not zero and so should be
  1284. * intialized to zero for non DCB mode otherwise actual total RX PB
  1285. * would be bigger than programmed and filter space would run into
  1286. * the PB 0 region.
  1287. */
  1288. for (i = 1; i < 8; i++)
  1289. IXGBE_WRITE_REG(hw, IXGBE_RXPBSIZE(i), 0);
  1290. /* Send interrupt when 64 filters are left */
  1291. fdirctrl |= 4 << IXGBE_FDIRCTRL_FULL_THRESH_SHIFT;
  1292. /* Initialize the drop queue to Rx queue 127 */
  1293. fdirctrl |= (127 << IXGBE_FDIRCTRL_DROP_Q_SHIFT);
  1294. switch (pballoc) {
  1295. case IXGBE_FDIR_PBALLOC_64K:
  1296. /* 2k - 1 perfect filters */
  1297. fdirctrl |= IXGBE_FDIRCTRL_PBALLOC_64K;
  1298. break;
  1299. case IXGBE_FDIR_PBALLOC_128K:
  1300. /* 4k - 1 perfect filters */
  1301. fdirctrl |= IXGBE_FDIRCTRL_PBALLOC_128K;
  1302. break;
  1303. case IXGBE_FDIR_PBALLOC_256K:
  1304. /* 8k - 1 perfect filters */
  1305. fdirctrl |= IXGBE_FDIRCTRL_PBALLOC_256K;
  1306. break;
  1307. default:
  1308. /* bad value */
  1309. return IXGBE_ERR_CONFIG;
  1310. };
  1311. /* Turn perfect match filtering on */
  1312. fdirctrl |= IXGBE_FDIRCTRL_PERFECT_MATCH;
  1313. fdirctrl |= IXGBE_FDIRCTRL_REPORT_STATUS;
  1314. /* Move the flexible bytes to use the ethertype - shift 6 words */
  1315. fdirctrl |= (0x6 << IXGBE_FDIRCTRL_FLEX_SHIFT);
  1316. /* Prime the keys for hashing */
  1317. IXGBE_WRITE_REG(hw, IXGBE_FDIRHKEY,
  1318. htonl(IXGBE_ATR_BUCKET_HASH_KEY));
  1319. IXGBE_WRITE_REG(hw, IXGBE_FDIRSKEY,
  1320. htonl(IXGBE_ATR_SIGNATURE_HASH_KEY));
  1321. /*
  1322. * Poll init-done after we write the register. Estimated times:
  1323. * 10G: PBALLOC = 11b, timing is 60us
  1324. * 1G: PBALLOC = 11b, timing is 600us
  1325. * 100M: PBALLOC = 11b, timing is 6ms
  1326. *
  1327. * Multiple these timings by 4 if under full Rx load
  1328. *
  1329. * So we'll poll for IXGBE_FDIR_INIT_DONE_POLL times, sleeping for
  1330. * 1 msec per poll time. If we're at line rate and drop to 100M, then
  1331. * this might not finish in our poll time, but we can live with that
  1332. * for now.
  1333. */
  1334. /* Set the maximum length per hash bucket to 0xA filters */
  1335. fdirctrl |= (0xA << IXGBE_FDIRCTRL_MAX_LENGTH_SHIFT);
  1336. IXGBE_WRITE_REG(hw, IXGBE_FDIRCTRL, fdirctrl);
  1337. IXGBE_WRITE_FLUSH(hw);
  1338. for (i = 0; i < IXGBE_FDIR_INIT_DONE_POLL; i++) {
  1339. if (IXGBE_READ_REG(hw, IXGBE_FDIRCTRL) &
  1340. IXGBE_FDIRCTRL_INIT_DONE)
  1341. break;
  1342. msleep(1);
  1343. }
  1344. if (i >= IXGBE_FDIR_INIT_DONE_POLL)
  1345. hw_dbg(hw, "Flow Director Perfect poll time exceeded!\n");
  1346. return 0;
  1347. }
  1348. /**
  1349. * ixgbe_atr_compute_hash_82599 - Compute the hashes for SW ATR
  1350. * @stream: input bitstream to compute the hash on
  1351. * @key: 32-bit hash key
  1352. **/
  1353. static u16 ixgbe_atr_compute_hash_82599(struct ixgbe_atr_input *atr_input,
  1354. u32 key)
  1355. {
  1356. /*
  1357. * The algorithm is as follows:
  1358. * Hash[15:0] = Sum { S[n] x K[n+16] }, n = 0...350
  1359. * where Sum {A[n]}, n = 0...n is bitwise XOR of A[0], A[1]...A[n]
  1360. * and A[n] x B[n] is bitwise AND between same length strings
  1361. *
  1362. * K[n] is 16 bits, defined as:
  1363. * for n modulo 32 >= 15, K[n] = K[n % 32 : (n % 32) - 15]
  1364. * for n modulo 32 < 15, K[n] =
  1365. * K[(n % 32:0) | (31:31 - (14 - (n % 32)))]
  1366. *
  1367. * S[n] is 16 bits, defined as:
  1368. * for n >= 15, S[n] = S[n:n - 15]
  1369. * for n < 15, S[n] = S[(n:0) | (350:350 - (14 - n))]
  1370. *
  1371. * To simplify for programming, the algorithm is implemented
  1372. * in software this way:
  1373. *
  1374. * Key[31:0], Stream[335:0]
  1375. *
  1376. * tmp_key[11 * 32 - 1:0] = 11{Key[31:0] = key concatenated 11 times
  1377. * int_key[350:0] = tmp_key[351:1]
  1378. * int_stream[365:0] = Stream[14:0] | Stream[335:0] | Stream[335:321]
  1379. *
  1380. * hash[15:0] = 0;
  1381. * for (i = 0; i < 351; i++) {
  1382. * if (int_key[i])
  1383. * hash ^= int_stream[(i + 15):i];
  1384. * }
  1385. */
  1386. union {
  1387. u64 fill[6];
  1388. u32 key[11];
  1389. u8 key_stream[44];
  1390. } tmp_key;
  1391. u8 *stream = (u8 *)atr_input;
  1392. u8 int_key[44]; /* upper-most bit unused */
  1393. u8 hash_str[46]; /* upper-most 2 bits unused */
  1394. u16 hash_result = 0;
  1395. int i, j, k, h;
  1396. /*
  1397. * Initialize the fill member to prevent warnings
  1398. * on some compilers
  1399. */
  1400. tmp_key.fill[0] = 0;
  1401. /* First load the temporary key stream */
  1402. for (i = 0; i < 6; i++) {
  1403. u64 fillkey = ((u64)key << 32) | key;
  1404. tmp_key.fill[i] = fillkey;
  1405. }
  1406. /*
  1407. * Set the interim key for the hashing. Bit 352 is unused, so we must
  1408. * shift and compensate when building the key.
  1409. */
  1410. int_key[0] = tmp_key.key_stream[0] >> 1;
  1411. for (i = 1, j = 0; i < 44; i++) {
  1412. unsigned int this_key = tmp_key.key_stream[j] << 7;
  1413. j++;
  1414. int_key[i] = (u8)(this_key | (tmp_key.key_stream[j] >> 1));
  1415. }
  1416. /*
  1417. * Set the interim bit string for the hashing. Bits 368 and 367 are
  1418. * unused, so shift and compensate when building the string.
  1419. */
  1420. hash_str[0] = (stream[40] & 0x7f) >> 1;
  1421. for (i = 1, j = 40; i < 46; i++) {
  1422. unsigned int this_str = stream[j] << 7;
  1423. j++;
  1424. if (j > 41)
  1425. j = 0;
  1426. hash_str[i] = (u8)(this_str | (stream[j] >> 1));
  1427. }
  1428. /*
  1429. * Now compute the hash. i is the index into hash_str, j is into our
  1430. * key stream, k is counting the number of bits, and h interates within
  1431. * each byte.
  1432. */
  1433. for (i = 45, j = 43, k = 0; k < 351 && i >= 2 && j >= 0; i--, j--) {
  1434. for (h = 0; h < 8 && k < 351; h++, k++) {
  1435. if (int_key[j] & (1 << h)) {
  1436. /*
  1437. * Key bit is set, XOR in the current 16-bit
  1438. * string. Example of processing:
  1439. * h = 0,
  1440. * tmp = (hash_str[i - 2] & 0 << 16) |
  1441. * (hash_str[i - 1] & 0xff << 8) |
  1442. * (hash_str[i] & 0xff >> 0)
  1443. * So tmp = hash_str[15 + k:k], since the
  1444. * i + 2 clause rolls off the 16-bit value
  1445. * h = 7,
  1446. * tmp = (hash_str[i - 2] & 0x7f << 9) |
  1447. * (hash_str[i - 1] & 0xff << 1) |
  1448. * (hash_str[i] & 0x80 >> 7)
  1449. */
  1450. int tmp = (hash_str[i] >> h);
  1451. tmp |= (hash_str[i - 1] << (8 - h));
  1452. tmp |= (int)(hash_str[i - 2] & ((1 << h) - 1))
  1453. << (16 - h);
  1454. hash_result ^= (u16)tmp;
  1455. }
  1456. }
  1457. }
  1458. return hash_result;
  1459. }
  1460. /**
  1461. * ixgbe_atr_set_vlan_id_82599 - Sets the VLAN id in the ATR input stream
  1462. * @input: input stream to modify
  1463. * @vlan: the VLAN id to load
  1464. **/
  1465. s32 ixgbe_atr_set_vlan_id_82599(struct ixgbe_atr_input *input, u16 vlan)
  1466. {
  1467. input->byte_stream[IXGBE_ATR_VLAN_OFFSET + 1] = vlan >> 8;
  1468. input->byte_stream[IXGBE_ATR_VLAN_OFFSET] = vlan & 0xff;
  1469. return 0;
  1470. }
  1471. /**
  1472. * ixgbe_atr_set_src_ipv4_82599 - Sets the source IPv4 address
  1473. * @input: input stream to modify
  1474. * @src_addr: the IP address to load
  1475. **/
  1476. s32 ixgbe_atr_set_src_ipv4_82599(struct ixgbe_atr_input *input, u32 src_addr)
  1477. {
  1478. input->byte_stream[IXGBE_ATR_SRC_IPV4_OFFSET + 3] = src_addr >> 24;
  1479. input->byte_stream[IXGBE_ATR_SRC_IPV4_OFFSET + 2] =
  1480. (src_addr >> 16) & 0xff;
  1481. input->byte_stream[IXGBE_ATR_SRC_IPV4_OFFSET + 1] =
  1482. (src_addr >> 8) & 0xff;
  1483. input->byte_stream[IXGBE_ATR_SRC_IPV4_OFFSET] = src_addr & 0xff;
  1484. return 0;
  1485. }
  1486. /**
  1487. * ixgbe_atr_set_dst_ipv4_82599 - Sets the destination IPv4 address
  1488. * @input: input stream to modify
  1489. * @dst_addr: the IP address to load
  1490. **/
  1491. s32 ixgbe_atr_set_dst_ipv4_82599(struct ixgbe_atr_input *input, u32 dst_addr)
  1492. {
  1493. input->byte_stream[IXGBE_ATR_DST_IPV4_OFFSET + 3] = dst_addr >> 24;
  1494. input->byte_stream[IXGBE_ATR_DST_IPV4_OFFSET + 2] =
  1495. (dst_addr >> 16) & 0xff;
  1496. input->byte_stream[IXGBE_ATR_DST_IPV4_OFFSET + 1] =
  1497. (dst_addr >> 8) & 0xff;
  1498. input->byte_stream[IXGBE_ATR_DST_IPV4_OFFSET] = dst_addr & 0xff;
  1499. return 0;
  1500. }
  1501. /**
  1502. * ixgbe_atr_set_src_ipv6_82599 - Sets the source IPv6 address
  1503. * @input: input stream to modify
  1504. * @src_addr_1: the first 4 bytes of the IP address to load
  1505. * @src_addr_2: the second 4 bytes of the IP address to load
  1506. * @src_addr_3: the third 4 bytes of the IP address to load
  1507. * @src_addr_4: the fourth 4 bytes of the IP address to load
  1508. **/
  1509. s32 ixgbe_atr_set_src_ipv6_82599(struct ixgbe_atr_input *input,
  1510. u32 src_addr_1, u32 src_addr_2,
  1511. u32 src_addr_3, u32 src_addr_4)
  1512. {
  1513. input->byte_stream[IXGBE_ATR_SRC_IPV6_OFFSET] = src_addr_4 & 0xff;
  1514. input->byte_stream[IXGBE_ATR_SRC_IPV6_OFFSET + 1] =
  1515. (src_addr_4 >> 8) & 0xff;
  1516. input->byte_stream[IXGBE_ATR_SRC_IPV6_OFFSET + 2] =
  1517. (src_addr_4 >> 16) & 0xff;
  1518. input->byte_stream[IXGBE_ATR_SRC_IPV6_OFFSET + 3] = src_addr_4 >> 24;
  1519. input->byte_stream[IXGBE_ATR_SRC_IPV6_OFFSET + 4] = src_addr_3 & 0xff;
  1520. input->byte_stream[IXGBE_ATR_SRC_IPV6_OFFSET + 5] =
  1521. (src_addr_3 >> 8) & 0xff;
  1522. input->byte_stream[IXGBE_ATR_SRC_IPV6_OFFSET + 6] =
  1523. (src_addr_3 >> 16) & 0xff;
  1524. input->byte_stream[IXGBE_ATR_SRC_IPV6_OFFSET + 7] = src_addr_3 >> 24;
  1525. input->byte_stream[IXGBE_ATR_SRC_IPV6_OFFSET + 8] = src_addr_2 & 0xff;
  1526. input->byte_stream[IXGBE_ATR_SRC_IPV6_OFFSET + 9] =
  1527. (src_addr_2 >> 8) & 0xff;
  1528. input->byte_stream[IXGBE_ATR_SRC_IPV6_OFFSET + 10] =
  1529. (src_addr_2 >> 16) & 0xff;
  1530. input->byte_stream[IXGBE_ATR_SRC_IPV6_OFFSET + 11] = src_addr_2 >> 24;
  1531. input->byte_stream[IXGBE_ATR_SRC_IPV6_OFFSET + 12] = src_addr_1 & 0xff;
  1532. input->byte_stream[IXGBE_ATR_SRC_IPV6_OFFSET + 13] =
  1533. (src_addr_1 >> 8) & 0xff;
  1534. input->byte_stream[IXGBE_ATR_SRC_IPV6_OFFSET + 14] =
  1535. (src_addr_1 >> 16) & 0xff;
  1536. input->byte_stream[IXGBE_ATR_SRC_IPV6_OFFSET + 15] = src_addr_1 >> 24;
  1537. return 0;
  1538. }
  1539. /**
  1540. * ixgbe_atr_set_dst_ipv6_82599 - Sets the destination IPv6 address
  1541. * @input: input stream to modify
  1542. * @dst_addr_1: the first 4 bytes of the IP address to load
  1543. * @dst_addr_2: the second 4 bytes of the IP address to load
  1544. * @dst_addr_3: the third 4 bytes of the IP address to load
  1545. * @dst_addr_4: the fourth 4 bytes of the IP address to load
  1546. **/
  1547. s32 ixgbe_atr_set_dst_ipv6_82599(struct ixgbe_atr_input *input,
  1548. u32 dst_addr_1, u32 dst_addr_2,
  1549. u32 dst_addr_3, u32 dst_addr_4)
  1550. {
  1551. input->byte_stream[IXGBE_ATR_DST_IPV6_OFFSET] = dst_addr_4 & 0xff;
  1552. input->byte_stream[IXGBE_ATR_DST_IPV6_OFFSET + 1] =
  1553. (dst_addr_4 >> 8) & 0xff;
  1554. input->byte_stream[IXGBE_ATR_DST_IPV6_OFFSET + 2] =
  1555. (dst_addr_4 >> 16) & 0xff;
  1556. input->byte_stream[IXGBE_ATR_DST_IPV6_OFFSET + 3] = dst_addr_4 >> 24;
  1557. input->byte_stream[IXGBE_ATR_DST_IPV6_OFFSET + 4] = dst_addr_3 & 0xff;
  1558. input->byte_stream[IXGBE_ATR_DST_IPV6_OFFSET + 5] =
  1559. (dst_addr_3 >> 8) & 0xff;
  1560. input->byte_stream[IXGBE_ATR_DST_IPV6_OFFSET + 6] =
  1561. (dst_addr_3 >> 16) & 0xff;
  1562. input->byte_stream[IXGBE_ATR_DST_IPV6_OFFSET + 7] = dst_addr_3 >> 24;
  1563. input->byte_stream[IXGBE_ATR_DST_IPV6_OFFSET + 8] = dst_addr_2 & 0xff;
  1564. input->byte_stream[IXGBE_ATR_DST_IPV6_OFFSET + 9] =
  1565. (dst_addr_2 >> 8) & 0xff;
  1566. input->byte_stream[IXGBE_ATR_DST_IPV6_OFFSET + 10] =
  1567. (dst_addr_2 >> 16) & 0xff;
  1568. input->byte_stream[IXGBE_ATR_DST_IPV6_OFFSET + 11] = dst_addr_2 >> 24;
  1569. input->byte_stream[IXGBE_ATR_DST_IPV6_OFFSET + 12] = dst_addr_1 & 0xff;
  1570. input->byte_stream[IXGBE_ATR_DST_IPV6_OFFSET + 13] =
  1571. (dst_addr_1 >> 8) & 0xff;
  1572. input->byte_stream[IXGBE_ATR_DST_IPV6_OFFSET + 14] =
  1573. (dst_addr_1 >> 16) & 0xff;
  1574. input->byte_stream[IXGBE_ATR_DST_IPV6_OFFSET + 15] = dst_addr_1 >> 24;
  1575. return 0;
  1576. }
  1577. /**
  1578. * ixgbe_atr_set_src_port_82599 - Sets the source port
  1579. * @input: input stream to modify
  1580. * @src_port: the source port to load
  1581. **/
  1582. s32 ixgbe_atr_set_src_port_82599(struct ixgbe_atr_input *input, u16 src_port)
  1583. {
  1584. input->byte_stream[IXGBE_ATR_SRC_PORT_OFFSET + 1] = src_port >> 8;
  1585. input->byte_stream[IXGBE_ATR_SRC_PORT_OFFSET] = src_port & 0xff;
  1586. return 0;
  1587. }
  1588. /**
  1589. * ixgbe_atr_set_dst_port_82599 - Sets the destination port
  1590. * @input: input stream to modify
  1591. * @dst_port: the destination port to load
  1592. **/
  1593. s32 ixgbe_atr_set_dst_port_82599(struct ixgbe_atr_input *input, u16 dst_port)
  1594. {
  1595. input->byte_stream[IXGBE_ATR_DST_PORT_OFFSET + 1] = dst_port >> 8;
  1596. input->byte_stream[IXGBE_ATR_DST_PORT_OFFSET] = dst_port & 0xff;
  1597. return 0;
  1598. }
  1599. /**
  1600. * ixgbe_atr_set_flex_byte_82599 - Sets the flexible bytes
  1601. * @input: input stream to modify
  1602. * @flex_bytes: the flexible bytes to load
  1603. **/
  1604. s32 ixgbe_atr_set_flex_byte_82599(struct ixgbe_atr_input *input, u16 flex_byte)
  1605. {
  1606. input->byte_stream[IXGBE_ATR_FLEX_BYTE_OFFSET + 1] = flex_byte >> 8;
  1607. input->byte_stream[IXGBE_ATR_FLEX_BYTE_OFFSET] = flex_byte & 0xff;
  1608. return 0;
  1609. }
  1610. /**
  1611. * ixgbe_atr_set_vm_pool_82599 - Sets the Virtual Machine pool
  1612. * @input: input stream to modify
  1613. * @vm_pool: the Virtual Machine pool to load
  1614. **/
  1615. s32 ixgbe_atr_set_vm_pool_82599(struct ixgbe_atr_input *input,
  1616. u8 vm_pool)
  1617. {
  1618. input->byte_stream[IXGBE_ATR_VM_POOL_OFFSET] = vm_pool;
  1619. return 0;
  1620. }
  1621. /**
  1622. * ixgbe_atr_set_l4type_82599 - Sets the layer 4 packet type
  1623. * @input: input stream to modify
  1624. * @l4type: the layer 4 type value to load
  1625. **/
  1626. s32 ixgbe_atr_set_l4type_82599(struct ixgbe_atr_input *input, u8 l4type)
  1627. {
  1628. input->byte_stream[IXGBE_ATR_L4TYPE_OFFSET] = l4type;
  1629. return 0;
  1630. }
  1631. /**
  1632. * ixgbe_atr_get_vlan_id_82599 - Gets the VLAN id from the ATR input stream
  1633. * @input: input stream to search
  1634. * @vlan: the VLAN id to load
  1635. **/
  1636. static s32 ixgbe_atr_get_vlan_id_82599(struct ixgbe_atr_input *input, u16 *vlan)
  1637. {
  1638. *vlan = input->byte_stream[IXGBE_ATR_VLAN_OFFSET];
  1639. *vlan |= input->byte_stream[IXGBE_ATR_VLAN_OFFSET + 1] << 8;
  1640. return 0;
  1641. }
  1642. /**
  1643. * ixgbe_atr_get_src_ipv4_82599 - Gets the source IPv4 address
  1644. * @input: input stream to search
  1645. * @src_addr: the IP address to load
  1646. **/
  1647. static s32 ixgbe_atr_get_src_ipv4_82599(struct ixgbe_atr_input *input,
  1648. u32 *src_addr)
  1649. {
  1650. *src_addr = input->byte_stream[IXGBE_ATR_SRC_IPV4_OFFSET];
  1651. *src_addr |= input->byte_stream[IXGBE_ATR_SRC_IPV4_OFFSET + 1] << 8;
  1652. *src_addr |= input->byte_stream[IXGBE_ATR_SRC_IPV4_OFFSET + 2] << 16;
  1653. *src_addr |= input->byte_stream[IXGBE_ATR_SRC_IPV4_OFFSET + 3] << 24;
  1654. return 0;
  1655. }
  1656. /**
  1657. * ixgbe_atr_get_dst_ipv4_82599 - Gets the destination IPv4 address
  1658. * @input: input stream to search
  1659. * @dst_addr: the IP address to load
  1660. **/
  1661. static s32 ixgbe_atr_get_dst_ipv4_82599(struct ixgbe_atr_input *input,
  1662. u32 *dst_addr)
  1663. {
  1664. *dst_addr = input->byte_stream[IXGBE_ATR_DST_IPV4_OFFSET];
  1665. *dst_addr |= input->byte_stream[IXGBE_ATR_DST_IPV4_OFFSET + 1] << 8;
  1666. *dst_addr |= input->byte_stream[IXGBE_ATR_DST_IPV4_OFFSET + 2] << 16;
  1667. *dst_addr |= input->byte_stream[IXGBE_ATR_DST_IPV4_OFFSET + 3] << 24;
  1668. return 0;
  1669. }
  1670. /**
  1671. * ixgbe_atr_get_src_ipv6_82599 - Gets the source IPv6 address
  1672. * @input: input stream to search
  1673. * @src_addr_1: the first 4 bytes of the IP address to load
  1674. * @src_addr_2: the second 4 bytes of the IP address to load
  1675. * @src_addr_3: the third 4 bytes of the IP address to load
  1676. * @src_addr_4: the fourth 4 bytes of the IP address to load
  1677. **/
  1678. static s32 ixgbe_atr_get_src_ipv6_82599(struct ixgbe_atr_input *input,
  1679. u32 *src_addr_1, u32 *src_addr_2,
  1680. u32 *src_addr_3, u32 *src_addr_4)
  1681. {
  1682. *src_addr_1 = input->byte_stream[IXGBE_ATR_SRC_IPV6_OFFSET + 12];
  1683. *src_addr_1 = input->byte_stream[IXGBE_ATR_SRC_IPV6_OFFSET + 13] << 8;
  1684. *src_addr_1 = input->byte_stream[IXGBE_ATR_SRC_IPV6_OFFSET + 14] << 16;
  1685. *src_addr_1 = input->byte_stream[IXGBE_ATR_SRC_IPV6_OFFSET + 15] << 24;
  1686. *src_addr_2 = input->byte_stream[IXGBE_ATR_SRC_IPV6_OFFSET + 8];
  1687. *src_addr_2 = input->byte_stream[IXGBE_ATR_SRC_IPV6_OFFSET + 9] << 8;
  1688. *src_addr_2 = input->byte_stream[IXGBE_ATR_SRC_IPV6_OFFSET + 10] << 16;
  1689. *src_addr_2 = input->byte_stream[IXGBE_ATR_SRC_IPV6_OFFSET + 11] << 24;
  1690. *src_addr_3 = input->byte_stream[IXGBE_ATR_SRC_IPV6_OFFSET + 4];
  1691. *src_addr_3 = input->byte_stream[IXGBE_ATR_SRC_IPV6_OFFSET + 5] << 8;
  1692. *src_addr_3 = input->byte_stream[IXGBE_ATR_SRC_IPV6_OFFSET + 6] << 16;
  1693. *src_addr_3 = input->byte_stream[IXGBE_ATR_SRC_IPV6_OFFSET + 7] << 24;
  1694. *src_addr_4 = input->byte_stream[IXGBE_ATR_SRC_IPV6_OFFSET];
  1695. *src_addr_4 = input->byte_stream[IXGBE_ATR_SRC_IPV6_OFFSET + 1] << 8;
  1696. *src_addr_4 = input->byte_stream[IXGBE_ATR_SRC_IPV6_OFFSET + 2] << 16;
  1697. *src_addr_4 = input->byte_stream[IXGBE_ATR_SRC_IPV6_OFFSET + 3] << 24;
  1698. return 0;
  1699. }
  1700. /**
  1701. * ixgbe_atr_get_dst_ipv6_82599 - Gets the destination IPv6 address
  1702. * @input: input stream to search
  1703. * @dst_addr_1: the first 4 bytes of the IP address to load
  1704. * @dst_addr_2: the second 4 bytes of the IP address to load
  1705. * @dst_addr_3: the third 4 bytes of the IP address to load
  1706. * @dst_addr_4: the fourth 4 bytes of the IP address to load
  1707. **/
  1708. s32 ixgbe_atr_get_dst_ipv6_82599(struct ixgbe_atr_input *input,
  1709. u32 *dst_addr_1, u32 *dst_addr_2,
  1710. u32 *dst_addr_3, u32 *dst_addr_4)
  1711. {
  1712. *dst_addr_1 = input->byte_stream[IXGBE_ATR_DST_IPV6_OFFSET + 12];
  1713. *dst_addr_1 = input->byte_stream[IXGBE_ATR_DST_IPV6_OFFSET + 13] << 8;
  1714. *dst_addr_1 = input->byte_stream[IXGBE_ATR_DST_IPV6_OFFSET + 14] << 16;
  1715. *dst_addr_1 = input->byte_stream[IXGBE_ATR_DST_IPV6_OFFSET + 15] << 24;
  1716. *dst_addr_2 = input->byte_stream[IXGBE_ATR_DST_IPV6_OFFSET + 8];
  1717. *dst_addr_2 = input->byte_stream[IXGBE_ATR_DST_IPV6_OFFSET + 9] << 8;
  1718. *dst_addr_2 = input->byte_stream[IXGBE_ATR_DST_IPV6_OFFSET + 10] << 16;
  1719. *dst_addr_2 = input->byte_stream[IXGBE_ATR_DST_IPV6_OFFSET + 11] << 24;
  1720. *dst_addr_3 = input->byte_stream[IXGBE_ATR_DST_IPV6_OFFSET + 4];
  1721. *dst_addr_3 = input->byte_stream[IXGBE_ATR_DST_IPV6_OFFSET + 5] << 8;
  1722. *dst_addr_3 = input->byte_stream[IXGBE_ATR_DST_IPV6_OFFSET + 6] << 16;
  1723. *dst_addr_3 = input->byte_stream[IXGBE_ATR_DST_IPV6_OFFSET + 7] << 24;
  1724. *dst_addr_4 = input->byte_stream[IXGBE_ATR_DST_IPV6_OFFSET];
  1725. *dst_addr_4 = input->byte_stream[IXGBE_ATR_DST_IPV6_OFFSET + 1] << 8;
  1726. *dst_addr_4 = input->byte_stream[IXGBE_ATR_DST_IPV6_OFFSET + 2] << 16;
  1727. *dst_addr_4 = input->byte_stream[IXGBE_ATR_DST_IPV6_OFFSET + 3] << 24;
  1728. return 0;
  1729. }
  1730. /**
  1731. * ixgbe_atr_get_src_port_82599 - Gets the source port
  1732. * @input: input stream to modify
  1733. * @src_port: the source port to load
  1734. *
  1735. * Even though the input is given in big-endian, the FDIRPORT registers
  1736. * expect the ports to be programmed in little-endian. Hence the need to swap
  1737. * endianness when retrieving the data. This can be confusing since the
  1738. * internal hash engine expects it to be big-endian.
  1739. **/
  1740. static s32 ixgbe_atr_get_src_port_82599(struct ixgbe_atr_input *input,
  1741. u16 *src_port)
  1742. {
  1743. *src_port = input->byte_stream[IXGBE_ATR_SRC_PORT_OFFSET] << 8;
  1744. *src_port |= input->byte_stream[IXGBE_ATR_SRC_PORT_OFFSET + 1];
  1745. return 0;
  1746. }
  1747. /**
  1748. * ixgbe_atr_get_dst_port_82599 - Gets the destination port
  1749. * @input: input stream to modify
  1750. * @dst_port: the destination port to load
  1751. *
  1752. * Even though the input is given in big-endian, the FDIRPORT registers
  1753. * expect the ports to be programmed in little-endian. Hence the need to swap
  1754. * endianness when retrieving the data. This can be confusing since the
  1755. * internal hash engine expects it to be big-endian.
  1756. **/
  1757. static s32 ixgbe_atr_get_dst_port_82599(struct ixgbe_atr_input *input,
  1758. u16 *dst_port)
  1759. {
  1760. *dst_port = input->byte_stream[IXGBE_ATR_DST_PORT_OFFSET] << 8;
  1761. *dst_port |= input->byte_stream[IXGBE_ATR_DST_PORT_OFFSET + 1];
  1762. return 0;
  1763. }
  1764. /**
  1765. * ixgbe_atr_get_flex_byte_82599 - Gets the flexible bytes
  1766. * @input: input stream to modify
  1767. * @flex_bytes: the flexible bytes to load
  1768. **/
  1769. static s32 ixgbe_atr_get_flex_byte_82599(struct ixgbe_atr_input *input,
  1770. u16 *flex_byte)
  1771. {
  1772. *flex_byte = input->byte_stream[IXGBE_ATR_FLEX_BYTE_OFFSET];
  1773. *flex_byte |= input->byte_stream[IXGBE_ATR_FLEX_BYTE_OFFSET + 1] << 8;
  1774. return 0;
  1775. }
  1776. /**
  1777. * ixgbe_atr_get_vm_pool_82599 - Gets the Virtual Machine pool
  1778. * @input: input stream to modify
  1779. * @vm_pool: the Virtual Machine pool to load
  1780. **/
  1781. s32 ixgbe_atr_get_vm_pool_82599(struct ixgbe_atr_input *input,
  1782. u8 *vm_pool)
  1783. {
  1784. *vm_pool = input->byte_stream[IXGBE_ATR_VM_POOL_OFFSET];
  1785. return 0;
  1786. }
  1787. /**
  1788. * ixgbe_atr_get_l4type_82599 - Gets the layer 4 packet type
  1789. * @input: input stream to modify
  1790. * @l4type: the layer 4 type value to load
  1791. **/
  1792. static s32 ixgbe_atr_get_l4type_82599(struct ixgbe_atr_input *input,
  1793. u8 *l4type)
  1794. {
  1795. *l4type = input->byte_stream[IXGBE_ATR_L4TYPE_OFFSET];
  1796. return 0;
  1797. }
  1798. /**
  1799. * ixgbe_atr_add_signature_filter_82599 - Adds a signature hash filter
  1800. * @hw: pointer to hardware structure
  1801. * @stream: input bitstream
  1802. * @queue: queue index to direct traffic to
  1803. **/
  1804. s32 ixgbe_fdir_add_signature_filter_82599(struct ixgbe_hw *hw,
  1805. struct ixgbe_atr_input *input,
  1806. u8 queue)
  1807. {
  1808. u64 fdirhashcmd;
  1809. u64 fdircmd;
  1810. u32 fdirhash;
  1811. u16 bucket_hash, sig_hash;
  1812. u8 l4type;
  1813. bucket_hash = ixgbe_atr_compute_hash_82599(input,
  1814. IXGBE_ATR_BUCKET_HASH_KEY);
  1815. /* bucket_hash is only 15 bits */
  1816. bucket_hash &= IXGBE_ATR_HASH_MASK;
  1817. sig_hash = ixgbe_atr_compute_hash_82599(input,
  1818. IXGBE_ATR_SIGNATURE_HASH_KEY);
  1819. /* Get the l4type in order to program FDIRCMD properly */
  1820. /* lowest 2 bits are FDIRCMD.L4TYPE, third lowest bit is FDIRCMD.IPV6 */
  1821. ixgbe_atr_get_l4type_82599(input, &l4type);
  1822. /*
  1823. * The lower 32-bits of fdirhashcmd is for FDIRHASH, the upper 32-bits
  1824. * is for FDIRCMD. Then do a 64-bit register write from FDIRHASH.
  1825. */
  1826. fdirhash = sig_hash << IXGBE_FDIRHASH_SIG_SW_INDEX_SHIFT | bucket_hash;
  1827. fdircmd = (IXGBE_FDIRCMD_CMD_ADD_FLOW | IXGBE_FDIRCMD_FILTER_UPDATE |
  1828. IXGBE_FDIRCMD_LAST | IXGBE_FDIRCMD_QUEUE_EN);
  1829. switch (l4type & IXGBE_ATR_L4TYPE_MASK) {
  1830. case IXGBE_ATR_L4TYPE_TCP:
  1831. fdircmd |= IXGBE_FDIRCMD_L4TYPE_TCP;
  1832. break;
  1833. case IXGBE_ATR_L4TYPE_UDP:
  1834. fdircmd |= IXGBE_FDIRCMD_L4TYPE_UDP;
  1835. break;
  1836. case IXGBE_ATR_L4TYPE_SCTP:
  1837. fdircmd |= IXGBE_FDIRCMD_L4TYPE_SCTP;
  1838. break;
  1839. default:
  1840. hw_dbg(hw, "Error on l4type input\n");
  1841. return IXGBE_ERR_CONFIG;
  1842. }
  1843. if (l4type & IXGBE_ATR_L4TYPE_IPV6_MASK)
  1844. fdircmd |= IXGBE_FDIRCMD_IPV6;
  1845. fdircmd |= ((u64)queue << IXGBE_FDIRCMD_RX_QUEUE_SHIFT);
  1846. fdirhashcmd = ((fdircmd << 32) | fdirhash);
  1847. IXGBE_WRITE_REG64(hw, IXGBE_FDIRHASH, fdirhashcmd);
  1848. return 0;
  1849. }
  1850. /**
  1851. * ixgbe_fdir_add_perfect_filter_82599 - Adds a perfect filter
  1852. * @hw: pointer to hardware structure
  1853. * @input: input bitstream
  1854. * @input_masks: bitwise masks for relevant fields
  1855. * @soft_id: software index into the silicon hash tables for filter storage
  1856. * @queue: queue index to direct traffic to
  1857. *
  1858. * Note that the caller to this function must lock before calling, since the
  1859. * hardware writes must be protected from one another.
  1860. **/
  1861. s32 ixgbe_fdir_add_perfect_filter_82599(struct ixgbe_hw *hw,
  1862. struct ixgbe_atr_input *input,
  1863. struct ixgbe_atr_input_masks *input_masks,
  1864. u16 soft_id, u8 queue)
  1865. {
  1866. u32 fdircmd = 0;
  1867. u32 fdirhash;
  1868. u32 src_ipv4 = 0, dst_ipv4 = 0;
  1869. u32 src_ipv6_1, src_ipv6_2, src_ipv6_3, src_ipv6_4;
  1870. u16 src_port, dst_port, vlan_id, flex_bytes;
  1871. u16 bucket_hash;
  1872. u8 l4type;
  1873. u8 fdirm = 0;
  1874. /* Get our input values */
  1875. ixgbe_atr_get_l4type_82599(input, &l4type);
  1876. /*
  1877. * Check l4type formatting, and bail out before we touch the hardware
  1878. * if there's a configuration issue
  1879. */
  1880. switch (l4type & IXGBE_ATR_L4TYPE_MASK) {
  1881. case IXGBE_ATR_L4TYPE_TCP:
  1882. fdircmd |= IXGBE_FDIRCMD_L4TYPE_TCP;
  1883. break;
  1884. case IXGBE_ATR_L4TYPE_UDP:
  1885. fdircmd |= IXGBE_FDIRCMD_L4TYPE_UDP;
  1886. break;
  1887. case IXGBE_ATR_L4TYPE_SCTP:
  1888. fdircmd |= IXGBE_FDIRCMD_L4TYPE_SCTP;
  1889. break;
  1890. default:
  1891. hw_dbg(hw, "Error on l4type input\n");
  1892. return IXGBE_ERR_CONFIG;
  1893. }
  1894. bucket_hash = ixgbe_atr_compute_hash_82599(input,
  1895. IXGBE_ATR_BUCKET_HASH_KEY);
  1896. /* bucket_hash is only 15 bits */
  1897. bucket_hash &= IXGBE_ATR_HASH_MASK;
  1898. ixgbe_atr_get_vlan_id_82599(input, &vlan_id);
  1899. ixgbe_atr_get_src_port_82599(input, &src_port);
  1900. ixgbe_atr_get_dst_port_82599(input, &dst_port);
  1901. ixgbe_atr_get_flex_byte_82599(input, &flex_bytes);
  1902. fdirhash = soft_id << IXGBE_FDIRHASH_SIG_SW_INDEX_SHIFT | bucket_hash;
  1903. /* Now figure out if we're IPv4 or IPv6 */
  1904. if (l4type & IXGBE_ATR_L4TYPE_IPV6_MASK) {
  1905. /* IPv6 */
  1906. ixgbe_atr_get_src_ipv6_82599(input, &src_ipv6_1, &src_ipv6_2,
  1907. &src_ipv6_3, &src_ipv6_4);
  1908. IXGBE_WRITE_REG(hw, IXGBE_FDIRSIPv6(0), src_ipv6_1);
  1909. IXGBE_WRITE_REG(hw, IXGBE_FDIRSIPv6(1), src_ipv6_2);
  1910. IXGBE_WRITE_REG(hw, IXGBE_FDIRSIPv6(2), src_ipv6_3);
  1911. /* The last 4 bytes is the same register as IPv4 */
  1912. IXGBE_WRITE_REG(hw, IXGBE_FDIRIPSA, src_ipv6_4);
  1913. fdircmd |= IXGBE_FDIRCMD_IPV6;
  1914. fdircmd |= IXGBE_FDIRCMD_IPv6DMATCH;
  1915. } else {
  1916. /* IPv4 */
  1917. ixgbe_atr_get_src_ipv4_82599(input, &src_ipv4);
  1918. IXGBE_WRITE_REG(hw, IXGBE_FDIRIPSA, src_ipv4);
  1919. }
  1920. ixgbe_atr_get_dst_ipv4_82599(input, &dst_ipv4);
  1921. IXGBE_WRITE_REG(hw, IXGBE_FDIRIPDA, dst_ipv4);
  1922. IXGBE_WRITE_REG(hw, IXGBE_FDIRVLAN, (vlan_id |
  1923. (flex_bytes << IXGBE_FDIRVLAN_FLEX_SHIFT)));
  1924. IXGBE_WRITE_REG(hw, IXGBE_FDIRPORT, (src_port |
  1925. (dst_port << IXGBE_FDIRPORT_DESTINATION_SHIFT)));
  1926. /*
  1927. * Program the relevant mask registers. If src/dst_port or src/dst_addr
  1928. * are zero, then assume a full mask for that field. Also assume that
  1929. * a VLAN of 0 is unspecified, so mask that out as well. L4type
  1930. * cannot be masked out in this implementation.
  1931. *
  1932. * This also assumes IPv4 only. IPv6 masking isn't supported at this
  1933. * point in time.
  1934. */
  1935. if (src_ipv4 == 0)
  1936. IXGBE_WRITE_REG(hw, IXGBE_FDIRSIP4M, 0xffffffff);
  1937. else
  1938. IXGBE_WRITE_REG(hw, IXGBE_FDIRSIP4M, input_masks->src_ip_mask);
  1939. if (dst_ipv4 == 0)
  1940. IXGBE_WRITE_REG(hw, IXGBE_FDIRDIP4M, 0xffffffff);
  1941. else
  1942. IXGBE_WRITE_REG(hw, IXGBE_FDIRDIP4M, input_masks->dst_ip_mask);
  1943. switch (l4type & IXGBE_ATR_L4TYPE_MASK) {
  1944. case IXGBE_ATR_L4TYPE_TCP:
  1945. if (src_port == 0)
  1946. IXGBE_WRITE_REG(hw, IXGBE_FDIRTCPM, 0xffff);
  1947. else
  1948. IXGBE_WRITE_REG(hw, IXGBE_FDIRTCPM,
  1949. input_masks->src_port_mask);
  1950. if (dst_port == 0)
  1951. IXGBE_WRITE_REG(hw, IXGBE_FDIRTCPM,
  1952. (IXGBE_READ_REG(hw, IXGBE_FDIRTCPM) |
  1953. (0xffff << 16)));
  1954. else
  1955. IXGBE_WRITE_REG(hw, IXGBE_FDIRTCPM,
  1956. (IXGBE_READ_REG(hw, IXGBE_FDIRTCPM) |
  1957. (input_masks->dst_port_mask << 16)));
  1958. break;
  1959. case IXGBE_ATR_L4TYPE_UDP:
  1960. if (src_port == 0)
  1961. IXGBE_WRITE_REG(hw, IXGBE_FDIRUDPM, 0xffff);
  1962. else
  1963. IXGBE_WRITE_REG(hw, IXGBE_FDIRUDPM,
  1964. input_masks->src_port_mask);
  1965. if (dst_port == 0)
  1966. IXGBE_WRITE_REG(hw, IXGBE_FDIRUDPM,
  1967. (IXGBE_READ_REG(hw, IXGBE_FDIRUDPM) |
  1968. (0xffff << 16)));
  1969. else
  1970. IXGBE_WRITE_REG(hw, IXGBE_FDIRUDPM,
  1971. (IXGBE_READ_REG(hw, IXGBE_FDIRUDPM) |
  1972. (input_masks->src_port_mask << 16)));
  1973. break;
  1974. default:
  1975. /* this already would have failed above */
  1976. break;
  1977. }
  1978. /* Program the last mask register, FDIRM */
  1979. if (input_masks->vlan_id_mask || !vlan_id)
  1980. /* Mask both VLAN and VLANP - bits 0 and 1 */
  1981. fdirm |= 0x3;
  1982. if (input_masks->data_mask || !flex_bytes)
  1983. /* Flex bytes need masking, so mask the whole thing - bit 4 */
  1984. fdirm |= 0x10;
  1985. /* Now mask VM pool and destination IPv6 - bits 5 and 2 */
  1986. fdirm |= 0x24;
  1987. IXGBE_WRITE_REG(hw, IXGBE_FDIRM, fdirm);
  1988. fdircmd |= IXGBE_FDIRCMD_CMD_ADD_FLOW;
  1989. fdircmd |= IXGBE_FDIRCMD_FILTER_UPDATE;
  1990. fdircmd |= IXGBE_FDIRCMD_LAST;
  1991. fdircmd |= IXGBE_FDIRCMD_QUEUE_EN;
  1992. fdircmd |= queue << IXGBE_FDIRCMD_RX_QUEUE_SHIFT;
  1993. IXGBE_WRITE_REG(hw, IXGBE_FDIRHASH, fdirhash);
  1994. IXGBE_WRITE_REG(hw, IXGBE_FDIRCMD, fdircmd);
  1995. return 0;
  1996. }
  1997. /**
  1998. * ixgbe_read_analog_reg8_82599 - Reads 8 bit Omer analog register
  1999. * @hw: pointer to hardware structure
  2000. * @reg: analog register to read
  2001. * @val: read value
  2002. *
  2003. * Performs read operation to Omer analog register specified.
  2004. **/
  2005. static s32 ixgbe_read_analog_reg8_82599(struct ixgbe_hw *hw, u32 reg, u8 *val)
  2006. {
  2007. u32 core_ctl;
  2008. IXGBE_WRITE_REG(hw, IXGBE_CORECTL, IXGBE_CORECTL_WRITE_CMD |
  2009. (reg << 8));
  2010. IXGBE_WRITE_FLUSH(hw);
  2011. udelay(10);
  2012. core_ctl = IXGBE_READ_REG(hw, IXGBE_CORECTL);
  2013. *val = (u8)core_ctl;
  2014. return 0;
  2015. }
  2016. /**
  2017. * ixgbe_write_analog_reg8_82599 - Writes 8 bit Omer analog register
  2018. * @hw: pointer to hardware structure
  2019. * @reg: atlas register to write
  2020. * @val: value to write
  2021. *
  2022. * Performs write operation to Omer analog register specified.
  2023. **/
  2024. static s32 ixgbe_write_analog_reg8_82599(struct ixgbe_hw *hw, u32 reg, u8 val)
  2025. {
  2026. u32 core_ctl;
  2027. core_ctl = (reg << 8) | val;
  2028. IXGBE_WRITE_REG(hw, IXGBE_CORECTL, core_ctl);
  2029. IXGBE_WRITE_FLUSH(hw);
  2030. udelay(10);
  2031. return 0;
  2032. }
  2033. /**
  2034. * ixgbe_start_hw_82599 - Prepare hardware for Tx/Rx
  2035. * @hw: pointer to hardware structure
  2036. *
  2037. * Starts the hardware using the generic start_hw function.
  2038. * Then performs device-specific:
  2039. * Clears the rate limiter registers.
  2040. **/
  2041. static s32 ixgbe_start_hw_82599(struct ixgbe_hw *hw)
  2042. {
  2043. u32 q_num;
  2044. s32 ret_val;
  2045. ret_val = ixgbe_start_hw_generic(hw);
  2046. /* Clear the rate limiters */
  2047. for (q_num = 0; q_num < hw->mac.max_tx_queues; q_num++) {
  2048. IXGBE_WRITE_REG(hw, IXGBE_RTTDQSEL, q_num);
  2049. IXGBE_WRITE_REG(hw, IXGBE_RTTBCNRC, 0);
  2050. }
  2051. IXGBE_WRITE_FLUSH(hw);
  2052. /* We need to run link autotry after the driver loads */
  2053. hw->mac.autotry_restart = true;
  2054. if (ret_val == 0)
  2055. ret_val = ixgbe_verify_fw_version_82599(hw);
  2056. return ret_val;
  2057. }
  2058. /**
  2059. * ixgbe_identify_phy_82599 - Get physical layer module
  2060. * @hw: pointer to hardware structure
  2061. *
  2062. * Determines the physical layer module found on the current adapter.
  2063. **/
  2064. static s32 ixgbe_identify_phy_82599(struct ixgbe_hw *hw)
  2065. {
  2066. s32 status = IXGBE_ERR_PHY_ADDR_INVALID;
  2067. status = ixgbe_identify_phy_generic(hw);
  2068. if (status != 0)
  2069. status = ixgbe_identify_sfp_module_generic(hw);
  2070. return status;
  2071. }
  2072. /**
  2073. * ixgbe_get_supported_physical_layer_82599 - Returns physical layer type
  2074. * @hw: pointer to hardware structure
  2075. *
  2076. * Determines physical layer capabilities of the current configuration.
  2077. **/
  2078. static u32 ixgbe_get_supported_physical_layer_82599(struct ixgbe_hw *hw)
  2079. {
  2080. u32 physical_layer = IXGBE_PHYSICAL_LAYER_UNKNOWN;
  2081. u32 autoc = IXGBE_READ_REG(hw, IXGBE_AUTOC);
  2082. u32 autoc2 = IXGBE_READ_REG(hw, IXGBE_AUTOC2);
  2083. u32 pma_pmd_10g_serial = autoc2 & IXGBE_AUTOC2_10G_SERIAL_PMA_PMD_MASK;
  2084. u32 pma_pmd_10g_parallel = autoc & IXGBE_AUTOC_10G_PMA_PMD_MASK;
  2085. u32 pma_pmd_1g = autoc & IXGBE_AUTOC_1G_PMA_PMD_MASK;
  2086. u16 ext_ability = 0;
  2087. u8 comp_codes_10g = 0;
  2088. hw->phy.ops.identify(hw);
  2089. if (hw->phy.type == ixgbe_phy_tn ||
  2090. hw->phy.type == ixgbe_phy_cu_unknown) {
  2091. hw->phy.ops.read_reg(hw, MDIO_PMA_EXTABLE, MDIO_MMD_PMAPMD,
  2092. &ext_ability);
  2093. if (ext_ability & MDIO_PMA_EXTABLE_10GBT)
  2094. physical_layer |= IXGBE_PHYSICAL_LAYER_10GBASE_T;
  2095. if (ext_ability & MDIO_PMA_EXTABLE_1000BT)
  2096. physical_layer |= IXGBE_PHYSICAL_LAYER_1000BASE_T;
  2097. if (ext_ability & MDIO_PMA_EXTABLE_100BTX)
  2098. physical_layer |= IXGBE_PHYSICAL_LAYER_100BASE_TX;
  2099. goto out;
  2100. }
  2101. switch (autoc & IXGBE_AUTOC_LMS_MASK) {
  2102. case IXGBE_AUTOC_LMS_1G_AN:
  2103. case IXGBE_AUTOC_LMS_1G_LINK_NO_AN:
  2104. if (pma_pmd_1g == IXGBE_AUTOC_1G_KX_BX) {
  2105. physical_layer = IXGBE_PHYSICAL_LAYER_1000BASE_KX |
  2106. IXGBE_PHYSICAL_LAYER_1000BASE_BX;
  2107. goto out;
  2108. } else
  2109. /* SFI mode so read SFP module */
  2110. goto sfp_check;
  2111. break;
  2112. case IXGBE_AUTOC_LMS_10G_LINK_NO_AN:
  2113. if (pma_pmd_10g_parallel == IXGBE_AUTOC_10G_CX4)
  2114. physical_layer = IXGBE_PHYSICAL_LAYER_10GBASE_CX4;
  2115. else if (pma_pmd_10g_parallel == IXGBE_AUTOC_10G_KX4)
  2116. physical_layer = IXGBE_PHYSICAL_LAYER_10GBASE_KX4;
  2117. else if (pma_pmd_10g_parallel == IXGBE_AUTOC_10G_XAUI)
  2118. physical_layer = IXGBE_PHYSICAL_LAYER_10GBASE_XAUI;
  2119. goto out;
  2120. break;
  2121. case IXGBE_AUTOC_LMS_10G_SERIAL:
  2122. if (pma_pmd_10g_serial == IXGBE_AUTOC2_10G_KR) {
  2123. physical_layer = IXGBE_PHYSICAL_LAYER_10GBASE_KR;
  2124. goto out;
  2125. } else if (pma_pmd_10g_serial == IXGBE_AUTOC2_10G_SFI)
  2126. goto sfp_check;
  2127. break;
  2128. case IXGBE_AUTOC_LMS_KX4_KX_KR:
  2129. case IXGBE_AUTOC_LMS_KX4_KX_KR_1G_AN:
  2130. if (autoc & IXGBE_AUTOC_KX_SUPP)
  2131. physical_layer |= IXGBE_PHYSICAL_LAYER_1000BASE_KX;
  2132. if (autoc & IXGBE_AUTOC_KX4_SUPP)
  2133. physical_layer |= IXGBE_PHYSICAL_LAYER_10GBASE_KX4;
  2134. if (autoc & IXGBE_AUTOC_KR_SUPP)
  2135. physical_layer |= IXGBE_PHYSICAL_LAYER_10GBASE_KR;
  2136. goto out;
  2137. break;
  2138. default:
  2139. goto out;
  2140. break;
  2141. }
  2142. sfp_check:
  2143. /* SFP check must be done last since DA modules are sometimes used to
  2144. * test KR mode - we need to id KR mode correctly before SFP module.
  2145. * Call identify_sfp because the pluggable module may have changed */
  2146. hw->phy.ops.identify_sfp(hw);
  2147. if (hw->phy.sfp_type == ixgbe_sfp_type_not_present)
  2148. goto out;
  2149. switch (hw->phy.type) {
  2150. case ixgbe_phy_tw_tyco:
  2151. case ixgbe_phy_tw_unknown:
  2152. physical_layer = IXGBE_PHYSICAL_LAYER_SFP_PLUS_CU;
  2153. break;
  2154. case ixgbe_phy_sfp_avago:
  2155. case ixgbe_phy_sfp_ftl:
  2156. case ixgbe_phy_sfp_intel:
  2157. case ixgbe_phy_sfp_unknown:
  2158. hw->phy.ops.read_i2c_eeprom(hw,
  2159. IXGBE_SFF_10GBE_COMP_CODES, &comp_codes_10g);
  2160. if (comp_codes_10g & IXGBE_SFF_10GBASESR_CAPABLE)
  2161. physical_layer = IXGBE_PHYSICAL_LAYER_10GBASE_SR;
  2162. else if (comp_codes_10g & IXGBE_SFF_10GBASELR_CAPABLE)
  2163. physical_layer = IXGBE_PHYSICAL_LAYER_10GBASE_LR;
  2164. break;
  2165. default:
  2166. break;
  2167. }
  2168. out:
  2169. return physical_layer;
  2170. }
  2171. /**
  2172. * ixgbe_enable_rx_dma_82599 - Enable the Rx DMA unit on 82599
  2173. * @hw: pointer to hardware structure
  2174. * @regval: register value to write to RXCTRL
  2175. *
  2176. * Enables the Rx DMA unit for 82599
  2177. **/
  2178. static s32 ixgbe_enable_rx_dma_82599(struct ixgbe_hw *hw, u32 regval)
  2179. {
  2180. #define IXGBE_MAX_SECRX_POLL 30
  2181. int i;
  2182. int secrxreg;
  2183. /*
  2184. * Workaround for 82599 silicon errata when enabling the Rx datapath.
  2185. * If traffic is incoming before we enable the Rx unit, it could hang
  2186. * the Rx DMA unit. Therefore, make sure the security engine is
  2187. * completely disabled prior to enabling the Rx unit.
  2188. */
  2189. secrxreg = IXGBE_READ_REG(hw, IXGBE_SECRXCTRL);
  2190. secrxreg |= IXGBE_SECRXCTRL_RX_DIS;
  2191. IXGBE_WRITE_REG(hw, IXGBE_SECRXCTRL, secrxreg);
  2192. for (i = 0; i < IXGBE_MAX_SECRX_POLL; i++) {
  2193. secrxreg = IXGBE_READ_REG(hw, IXGBE_SECRXSTAT);
  2194. if (secrxreg & IXGBE_SECRXSTAT_SECRX_RDY)
  2195. break;
  2196. else
  2197. udelay(10);
  2198. }
  2199. /* For informational purposes only */
  2200. if (i >= IXGBE_MAX_SECRX_POLL)
  2201. hw_dbg(hw, "Rx unit being enabled before security "
  2202. "path fully disabled. Continuing with init.\n");
  2203. IXGBE_WRITE_REG(hw, IXGBE_RXCTRL, regval);
  2204. secrxreg = IXGBE_READ_REG(hw, IXGBE_SECRXCTRL);
  2205. secrxreg &= ~IXGBE_SECRXCTRL_RX_DIS;
  2206. IXGBE_WRITE_REG(hw, IXGBE_SECRXCTRL, secrxreg);
  2207. IXGBE_WRITE_FLUSH(hw);
  2208. return 0;
  2209. }
  2210. /**
  2211. * ixgbe_get_device_caps_82599 - Get additional device capabilities
  2212. * @hw: pointer to hardware structure
  2213. * @device_caps: the EEPROM word with the extra device capabilities
  2214. *
  2215. * This function will read the EEPROM location for the device capabilities,
  2216. * and return the word through device_caps.
  2217. **/
  2218. static s32 ixgbe_get_device_caps_82599(struct ixgbe_hw *hw, u16 *device_caps)
  2219. {
  2220. hw->eeprom.ops.read(hw, IXGBE_DEVICE_CAPS, device_caps);
  2221. return 0;
  2222. }
  2223. /**
  2224. * ixgbe_get_san_mac_addr_offset_82599 - SAN MAC address offset for 82599
  2225. * @hw: pointer to hardware structure
  2226. * @san_mac_offset: SAN MAC address offset
  2227. *
  2228. * This function will read the EEPROM location for the SAN MAC address
  2229. * pointer, and returns the value at that location. This is used in both
  2230. * get and set mac_addr routines.
  2231. **/
  2232. static s32 ixgbe_get_san_mac_addr_offset_82599(struct ixgbe_hw *hw,
  2233. u16 *san_mac_offset)
  2234. {
  2235. /*
  2236. * First read the EEPROM pointer to see if the MAC addresses are
  2237. * available.
  2238. */
  2239. hw->eeprom.ops.read(hw, IXGBE_SAN_MAC_ADDR_PTR, san_mac_offset);
  2240. return 0;
  2241. }
  2242. /**
  2243. * ixgbe_get_san_mac_addr_82599 - SAN MAC address retrieval for 82599
  2244. * @hw: pointer to hardware structure
  2245. * @san_mac_addr: SAN MAC address
  2246. *
  2247. * Reads the SAN MAC address from the EEPROM, if it's available. This is
  2248. * per-port, so set_lan_id() must be called before reading the addresses.
  2249. * set_lan_id() is called by identify_sfp(), but this cannot be relied
  2250. * upon for non-SFP connections, so we must call it here.
  2251. **/
  2252. static s32 ixgbe_get_san_mac_addr_82599(struct ixgbe_hw *hw, u8 *san_mac_addr)
  2253. {
  2254. u16 san_mac_data, san_mac_offset;
  2255. u8 i;
  2256. /*
  2257. * First read the EEPROM pointer to see if the MAC addresses are
  2258. * available. If they're not, no point in calling set_lan_id() here.
  2259. */
  2260. ixgbe_get_san_mac_addr_offset_82599(hw, &san_mac_offset);
  2261. if ((san_mac_offset == 0) || (san_mac_offset == 0xFFFF)) {
  2262. /*
  2263. * No addresses available in this EEPROM. It's not an
  2264. * error though, so just wipe the local address and return.
  2265. */
  2266. for (i = 0; i < 6; i++)
  2267. san_mac_addr[i] = 0xFF;
  2268. goto san_mac_addr_out;
  2269. }
  2270. /* make sure we know which port we need to program */
  2271. hw->mac.ops.set_lan_id(hw);
  2272. /* apply the port offset to the address offset */
  2273. (hw->bus.func) ? (san_mac_offset += IXGBE_SAN_MAC_ADDR_PORT1_OFFSET) :
  2274. (san_mac_offset += IXGBE_SAN_MAC_ADDR_PORT0_OFFSET);
  2275. for (i = 0; i < 3; i++) {
  2276. hw->eeprom.ops.read(hw, san_mac_offset, &san_mac_data);
  2277. san_mac_addr[i * 2] = (u8)(san_mac_data);
  2278. san_mac_addr[i * 2 + 1] = (u8)(san_mac_data >> 8);
  2279. san_mac_offset++;
  2280. }
  2281. san_mac_addr_out:
  2282. return 0;
  2283. }
  2284. /**
  2285. * ixgbe_verify_fw_version_82599 - verify fw version for 82599
  2286. * @hw: pointer to hardware structure
  2287. *
  2288. * Verifies that installed the firmware version is 0.6 or higher
  2289. * for SFI devices. All 82599 SFI devices should have version 0.6 or higher.
  2290. *
  2291. * Returns IXGBE_ERR_EEPROM_VERSION if the FW is not present or
  2292. * if the FW version is not supported.
  2293. **/
  2294. static s32 ixgbe_verify_fw_version_82599(struct ixgbe_hw *hw)
  2295. {
  2296. s32 status = IXGBE_ERR_EEPROM_VERSION;
  2297. u16 fw_offset, fw_ptp_cfg_offset;
  2298. u16 fw_version = 0;
  2299. /* firmware check is only necessary for SFI devices */
  2300. if (hw->phy.media_type != ixgbe_media_type_fiber) {
  2301. status = 0;
  2302. goto fw_version_out;
  2303. }
  2304. /* get the offset to the Firmware Module block */
  2305. hw->eeprom.ops.read(hw, IXGBE_FW_PTR, &fw_offset);
  2306. if ((fw_offset == 0) || (fw_offset == 0xFFFF))
  2307. goto fw_version_out;
  2308. /* get the offset to the Pass Through Patch Configuration block */
  2309. hw->eeprom.ops.read(hw, (fw_offset +
  2310. IXGBE_FW_PASSTHROUGH_PATCH_CONFIG_PTR),
  2311. &fw_ptp_cfg_offset);
  2312. if ((fw_ptp_cfg_offset == 0) || (fw_ptp_cfg_offset == 0xFFFF))
  2313. goto fw_version_out;
  2314. /* get the firmware version */
  2315. hw->eeprom.ops.read(hw, (fw_ptp_cfg_offset +
  2316. IXGBE_FW_PATCH_VERSION_4),
  2317. &fw_version);
  2318. if (fw_version > 0x5)
  2319. status = 0;
  2320. fw_version_out:
  2321. return status;
  2322. }
  2323. /**
  2324. * ixgbe_get_wwn_prefix_82599 - Get alternative WWNN/WWPN prefix from
  2325. * the EEPROM
  2326. * @hw: pointer to hardware structure
  2327. * @wwnn_prefix: the alternative WWNN prefix
  2328. * @wwpn_prefix: the alternative WWPN prefix
  2329. *
  2330. * This function will read the EEPROM from the alternative SAN MAC address
  2331. * block to check the support for the alternative WWNN/WWPN prefix support.
  2332. **/
  2333. static s32 ixgbe_get_wwn_prefix_82599(struct ixgbe_hw *hw, u16 *wwnn_prefix,
  2334. u16 *wwpn_prefix)
  2335. {
  2336. u16 offset, caps;
  2337. u16 alt_san_mac_blk_offset;
  2338. /* clear output first */
  2339. *wwnn_prefix = 0xFFFF;
  2340. *wwpn_prefix = 0xFFFF;
  2341. /* check if alternative SAN MAC is supported */
  2342. hw->eeprom.ops.read(hw, IXGBE_ALT_SAN_MAC_ADDR_BLK_PTR,
  2343. &alt_san_mac_blk_offset);
  2344. if ((alt_san_mac_blk_offset == 0) ||
  2345. (alt_san_mac_blk_offset == 0xFFFF))
  2346. goto wwn_prefix_out;
  2347. /* check capability in alternative san mac address block */
  2348. offset = alt_san_mac_blk_offset + IXGBE_ALT_SAN_MAC_ADDR_CAPS_OFFSET;
  2349. hw->eeprom.ops.read(hw, offset, &caps);
  2350. if (!(caps & IXGBE_ALT_SAN_MAC_ADDR_CAPS_ALTWWN))
  2351. goto wwn_prefix_out;
  2352. /* get the corresponding prefix for WWNN/WWPN */
  2353. offset = alt_san_mac_blk_offset + IXGBE_ALT_SAN_MAC_ADDR_WWNN_OFFSET;
  2354. hw->eeprom.ops.read(hw, offset, wwnn_prefix);
  2355. offset = alt_san_mac_blk_offset + IXGBE_ALT_SAN_MAC_ADDR_WWPN_OFFSET;
  2356. hw->eeprom.ops.read(hw, offset, wwpn_prefix);
  2357. wwn_prefix_out:
  2358. return 0;
  2359. }
  2360. static struct ixgbe_mac_operations mac_ops_82599 = {
  2361. .init_hw = &ixgbe_init_hw_generic,
  2362. .reset_hw = &ixgbe_reset_hw_82599,
  2363. .start_hw = &ixgbe_start_hw_82599,
  2364. .clear_hw_cntrs = &ixgbe_clear_hw_cntrs_generic,
  2365. .get_media_type = &ixgbe_get_media_type_82599,
  2366. .get_supported_physical_layer = &ixgbe_get_supported_physical_layer_82599,
  2367. .enable_rx_dma = &ixgbe_enable_rx_dma_82599,
  2368. .get_mac_addr = &ixgbe_get_mac_addr_generic,
  2369. .get_san_mac_addr = &ixgbe_get_san_mac_addr_82599,
  2370. .get_device_caps = &ixgbe_get_device_caps_82599,
  2371. .get_wwn_prefix = &ixgbe_get_wwn_prefix_82599,
  2372. .stop_adapter = &ixgbe_stop_adapter_generic,
  2373. .get_bus_info = &ixgbe_get_bus_info_generic,
  2374. .set_lan_id = &ixgbe_set_lan_id_multi_port_pcie,
  2375. .read_analog_reg8 = &ixgbe_read_analog_reg8_82599,
  2376. .write_analog_reg8 = &ixgbe_write_analog_reg8_82599,
  2377. .setup_link = &ixgbe_setup_mac_link_82599,
  2378. .check_link = &ixgbe_check_mac_link_82599,
  2379. .get_link_capabilities = &ixgbe_get_link_capabilities_82599,
  2380. .led_on = &ixgbe_led_on_generic,
  2381. .led_off = &ixgbe_led_off_generic,
  2382. .blink_led_start = &ixgbe_blink_led_start_generic,
  2383. .blink_led_stop = &ixgbe_blink_led_stop_generic,
  2384. .set_rar = &ixgbe_set_rar_generic,
  2385. .clear_rar = &ixgbe_clear_rar_generic,
  2386. .set_vmdq = &ixgbe_set_vmdq_82599,
  2387. .clear_vmdq = &ixgbe_clear_vmdq_82599,
  2388. .init_rx_addrs = &ixgbe_init_rx_addrs_generic,
  2389. .update_uc_addr_list = &ixgbe_update_uc_addr_list_generic,
  2390. .update_mc_addr_list = &ixgbe_update_mc_addr_list_generic,
  2391. .enable_mc = &ixgbe_enable_mc_generic,
  2392. .disable_mc = &ixgbe_disable_mc_generic,
  2393. .clear_vfta = &ixgbe_clear_vfta_82599,
  2394. .set_vfta = &ixgbe_set_vfta_82599,
  2395. .fc_enable = &ixgbe_fc_enable_generic,
  2396. .init_uta_tables = &ixgbe_init_uta_tables_82599,
  2397. .setup_sfp = &ixgbe_setup_sfp_modules_82599,
  2398. };
  2399. static struct ixgbe_eeprom_operations eeprom_ops_82599 = {
  2400. .init_params = &ixgbe_init_eeprom_params_generic,
  2401. .read = &ixgbe_read_eeprom_generic,
  2402. .write = &ixgbe_write_eeprom_generic,
  2403. .validate_checksum = &ixgbe_validate_eeprom_checksum_generic,
  2404. .update_checksum = &ixgbe_update_eeprom_checksum_generic,
  2405. };
  2406. static struct ixgbe_phy_operations phy_ops_82599 = {
  2407. .identify = &ixgbe_identify_phy_82599,
  2408. .identify_sfp = &ixgbe_identify_sfp_module_generic,
  2409. .init = &ixgbe_init_phy_ops_82599,
  2410. .reset = &ixgbe_reset_phy_generic,
  2411. .read_reg = &ixgbe_read_phy_reg_generic,
  2412. .write_reg = &ixgbe_write_phy_reg_generic,
  2413. .setup_link = &ixgbe_setup_phy_link_generic,
  2414. .setup_link_speed = &ixgbe_setup_phy_link_speed_generic,
  2415. .read_i2c_byte = &ixgbe_read_i2c_byte_generic,
  2416. .write_i2c_byte = &ixgbe_write_i2c_byte_generic,
  2417. .read_i2c_eeprom = &ixgbe_read_i2c_eeprom_generic,
  2418. .write_i2c_eeprom = &ixgbe_write_i2c_eeprom_generic,
  2419. };
  2420. struct ixgbe_info ixgbe_82599_info = {
  2421. .mac = ixgbe_mac_82599EB,
  2422. .get_invariants = &ixgbe_get_invariants_82599,
  2423. .mac_ops = &mac_ops_82599,
  2424. .eeprom_ops = &eeprom_ops_82599,
  2425. .phy_ops = &phy_ops_82599,
  2426. .mbx_ops = &mbx_ops_82599,
  2427. };