ixgbe_82599.c 86 KB

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