ixgbe_common.c 57 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106
  1. /*******************************************************************************
  2. Intel 10 Gigabit PCI Express Linux driver
  3. Copyright(c) 1999 - 2009 Intel Corporation.
  4. This program is free software; you can redistribute it and/or modify it
  5. under the terms and conditions of the GNU General Public License,
  6. version 2, as published by the Free Software Foundation.
  7. This program is distributed in the hope it will be useful, but WITHOUT
  8. ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  9. FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  10. more details.
  11. You should have received a copy of the GNU General Public License along with
  12. this program; if not, write to the Free Software Foundation, Inc.,
  13. 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
  14. The full GNU General Public License is included in this distribution in
  15. the file called "COPYING".
  16. Contact Information:
  17. e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
  18. Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
  19. *******************************************************************************/
  20. #include <linux/pci.h>
  21. #include <linux/delay.h>
  22. #include <linux/sched.h>
  23. #include <linux/list.h>
  24. #include <linux/netdevice.h>
  25. #include "ixgbe.h"
  26. #include "ixgbe_common.h"
  27. #include "ixgbe_phy.h"
  28. static s32 ixgbe_poll_eeprom_eerd_done(struct ixgbe_hw *hw);
  29. static s32 ixgbe_acquire_eeprom(struct ixgbe_hw *hw);
  30. static s32 ixgbe_get_eeprom_semaphore(struct ixgbe_hw *hw);
  31. static void ixgbe_release_eeprom_semaphore(struct ixgbe_hw *hw);
  32. static s32 ixgbe_ready_eeprom(struct ixgbe_hw *hw);
  33. static void ixgbe_standby_eeprom(struct ixgbe_hw *hw);
  34. static void ixgbe_shift_out_eeprom_bits(struct ixgbe_hw *hw, u16 data,
  35. u16 count);
  36. static u16 ixgbe_shift_in_eeprom_bits(struct ixgbe_hw *hw, u16 count);
  37. static void ixgbe_raise_eeprom_clk(struct ixgbe_hw *hw, u32 *eec);
  38. static void ixgbe_lower_eeprom_clk(struct ixgbe_hw *hw, u32 *eec);
  39. static void ixgbe_release_eeprom(struct ixgbe_hw *hw);
  40. static u16 ixgbe_calc_eeprom_checksum(struct ixgbe_hw *hw);
  41. static void ixgbe_enable_rar(struct ixgbe_hw *hw, u32 index);
  42. static void ixgbe_disable_rar(struct ixgbe_hw *hw, u32 index);
  43. static s32 ixgbe_mta_vector(struct ixgbe_hw *hw, u8 *mc_addr);
  44. static void ixgbe_add_uc_addr(struct ixgbe_hw *hw, u8 *addr, u32 vmdq);
  45. /**
  46. * ixgbe_start_hw_generic - Prepare hardware for Tx/Rx
  47. * @hw: pointer to hardware structure
  48. *
  49. * Starts the hardware by filling the bus info structure and media type, clears
  50. * all on chip counters, initializes receive address registers, multicast
  51. * table, VLAN filter table, calls routine to set up link and flow control
  52. * settings, and leaves transmit and receive units disabled and uninitialized
  53. **/
  54. s32 ixgbe_start_hw_generic(struct ixgbe_hw *hw)
  55. {
  56. u32 ctrl_ext;
  57. /* Set the media type */
  58. hw->phy.media_type = hw->mac.ops.get_media_type(hw);
  59. /* Identify the PHY */
  60. hw->phy.ops.identify(hw);
  61. /* Clear the VLAN filter table */
  62. hw->mac.ops.clear_vfta(hw);
  63. /* Clear statistics registers */
  64. hw->mac.ops.clear_hw_cntrs(hw);
  65. /* Set No Snoop Disable */
  66. ctrl_ext = IXGBE_READ_REG(hw, IXGBE_CTRL_EXT);
  67. ctrl_ext |= IXGBE_CTRL_EXT_NS_DIS;
  68. IXGBE_WRITE_REG(hw, IXGBE_CTRL_EXT, ctrl_ext);
  69. IXGBE_WRITE_FLUSH(hw);
  70. /* Clear adapter stopped flag */
  71. hw->adapter_stopped = false;
  72. return 0;
  73. }
  74. /**
  75. * ixgbe_init_hw_generic - Generic hardware initialization
  76. * @hw: pointer to hardware structure
  77. *
  78. * Initialize the hardware by resetting the hardware, filling the bus info
  79. * structure and media type, clears all on chip counters, initializes receive
  80. * address registers, multicast table, VLAN filter table, calls routine to set
  81. * up link and flow control settings, and leaves transmit and receive units
  82. * disabled and uninitialized
  83. **/
  84. s32 ixgbe_init_hw_generic(struct ixgbe_hw *hw)
  85. {
  86. /* Reset the hardware */
  87. hw->mac.ops.reset_hw(hw);
  88. /* Start the HW */
  89. hw->mac.ops.start_hw(hw);
  90. return 0;
  91. }
  92. /**
  93. * ixgbe_clear_hw_cntrs_generic - Generic clear hardware counters
  94. * @hw: pointer to hardware structure
  95. *
  96. * Clears all hardware statistics counters by reading them from the hardware
  97. * Statistics counters are clear on read.
  98. **/
  99. s32 ixgbe_clear_hw_cntrs_generic(struct ixgbe_hw *hw)
  100. {
  101. u16 i = 0;
  102. IXGBE_READ_REG(hw, IXGBE_CRCERRS);
  103. IXGBE_READ_REG(hw, IXGBE_ILLERRC);
  104. IXGBE_READ_REG(hw, IXGBE_ERRBC);
  105. IXGBE_READ_REG(hw, IXGBE_MSPDC);
  106. for (i = 0; i < 8; i++)
  107. IXGBE_READ_REG(hw, IXGBE_MPC(i));
  108. IXGBE_READ_REG(hw, IXGBE_MLFC);
  109. IXGBE_READ_REG(hw, IXGBE_MRFC);
  110. IXGBE_READ_REG(hw, IXGBE_RLEC);
  111. IXGBE_READ_REG(hw, IXGBE_LXONTXC);
  112. IXGBE_READ_REG(hw, IXGBE_LXONRXC);
  113. IXGBE_READ_REG(hw, IXGBE_LXOFFTXC);
  114. IXGBE_READ_REG(hw, IXGBE_LXOFFRXC);
  115. for (i = 0; i < 8; i++) {
  116. IXGBE_READ_REG(hw, IXGBE_PXONTXC(i));
  117. IXGBE_READ_REG(hw, IXGBE_PXONRXC(i));
  118. IXGBE_READ_REG(hw, IXGBE_PXOFFTXC(i));
  119. IXGBE_READ_REG(hw, IXGBE_PXOFFRXC(i));
  120. }
  121. IXGBE_READ_REG(hw, IXGBE_PRC64);
  122. IXGBE_READ_REG(hw, IXGBE_PRC127);
  123. IXGBE_READ_REG(hw, IXGBE_PRC255);
  124. IXGBE_READ_REG(hw, IXGBE_PRC511);
  125. IXGBE_READ_REG(hw, IXGBE_PRC1023);
  126. IXGBE_READ_REG(hw, IXGBE_PRC1522);
  127. IXGBE_READ_REG(hw, IXGBE_GPRC);
  128. IXGBE_READ_REG(hw, IXGBE_BPRC);
  129. IXGBE_READ_REG(hw, IXGBE_MPRC);
  130. IXGBE_READ_REG(hw, IXGBE_GPTC);
  131. IXGBE_READ_REG(hw, IXGBE_GORCL);
  132. IXGBE_READ_REG(hw, IXGBE_GORCH);
  133. IXGBE_READ_REG(hw, IXGBE_GOTCL);
  134. IXGBE_READ_REG(hw, IXGBE_GOTCH);
  135. for (i = 0; i < 8; i++)
  136. IXGBE_READ_REG(hw, IXGBE_RNBC(i));
  137. IXGBE_READ_REG(hw, IXGBE_RUC);
  138. IXGBE_READ_REG(hw, IXGBE_RFC);
  139. IXGBE_READ_REG(hw, IXGBE_ROC);
  140. IXGBE_READ_REG(hw, IXGBE_RJC);
  141. IXGBE_READ_REG(hw, IXGBE_MNGPRC);
  142. IXGBE_READ_REG(hw, IXGBE_MNGPDC);
  143. IXGBE_READ_REG(hw, IXGBE_MNGPTC);
  144. IXGBE_READ_REG(hw, IXGBE_TORL);
  145. IXGBE_READ_REG(hw, IXGBE_TORH);
  146. IXGBE_READ_REG(hw, IXGBE_TPR);
  147. IXGBE_READ_REG(hw, IXGBE_TPT);
  148. IXGBE_READ_REG(hw, IXGBE_PTC64);
  149. IXGBE_READ_REG(hw, IXGBE_PTC127);
  150. IXGBE_READ_REG(hw, IXGBE_PTC255);
  151. IXGBE_READ_REG(hw, IXGBE_PTC511);
  152. IXGBE_READ_REG(hw, IXGBE_PTC1023);
  153. IXGBE_READ_REG(hw, IXGBE_PTC1522);
  154. IXGBE_READ_REG(hw, IXGBE_MPTC);
  155. IXGBE_READ_REG(hw, IXGBE_BPTC);
  156. for (i = 0; i < 16; i++) {
  157. IXGBE_READ_REG(hw, IXGBE_QPRC(i));
  158. IXGBE_READ_REG(hw, IXGBE_QBRC(i));
  159. IXGBE_READ_REG(hw, IXGBE_QPTC(i));
  160. IXGBE_READ_REG(hw, IXGBE_QBTC(i));
  161. }
  162. return 0;
  163. }
  164. /**
  165. * ixgbe_read_pba_num_generic - Reads part number from EEPROM
  166. * @hw: pointer to hardware structure
  167. * @pba_num: stores the part number from the EEPROM
  168. *
  169. * Reads the part number from the EEPROM.
  170. **/
  171. s32 ixgbe_read_pba_num_generic(struct ixgbe_hw *hw, u32 *pba_num)
  172. {
  173. s32 ret_val;
  174. u16 data;
  175. ret_val = hw->eeprom.ops.read(hw, IXGBE_PBANUM0_PTR, &data);
  176. if (ret_val) {
  177. hw_dbg(hw, "NVM Read Error\n");
  178. return ret_val;
  179. }
  180. *pba_num = (u32)(data << 16);
  181. ret_val = hw->eeprom.ops.read(hw, IXGBE_PBANUM1_PTR, &data);
  182. if (ret_val) {
  183. hw_dbg(hw, "NVM Read Error\n");
  184. return ret_val;
  185. }
  186. *pba_num |= data;
  187. return 0;
  188. }
  189. /**
  190. * ixgbe_get_mac_addr_generic - Generic get MAC address
  191. * @hw: pointer to hardware structure
  192. * @mac_addr: Adapter MAC address
  193. *
  194. * Reads the adapter's MAC address from first Receive Address Register (RAR0)
  195. * A reset of the adapter must be performed prior to calling this function
  196. * in order for the MAC address to have been loaded from the EEPROM into RAR0
  197. **/
  198. s32 ixgbe_get_mac_addr_generic(struct ixgbe_hw *hw, u8 *mac_addr)
  199. {
  200. u32 rar_high;
  201. u32 rar_low;
  202. u16 i;
  203. rar_high = IXGBE_READ_REG(hw, IXGBE_RAH(0));
  204. rar_low = IXGBE_READ_REG(hw, IXGBE_RAL(0));
  205. for (i = 0; i < 4; i++)
  206. mac_addr[i] = (u8)(rar_low >> (i*8));
  207. for (i = 0; i < 2; i++)
  208. mac_addr[i+4] = (u8)(rar_high >> (i*8));
  209. return 0;
  210. }
  211. /**
  212. * ixgbe_get_bus_info_generic - Generic set PCI bus info
  213. * @hw: pointer to hardware structure
  214. *
  215. * Sets the PCI bus info (speed, width, type) within the ixgbe_hw structure
  216. **/
  217. s32 ixgbe_get_bus_info_generic(struct ixgbe_hw *hw)
  218. {
  219. struct ixgbe_adapter *adapter = hw->back;
  220. struct ixgbe_mac_info *mac = &hw->mac;
  221. u16 link_status;
  222. hw->bus.type = ixgbe_bus_type_pci_express;
  223. /* Get the negotiated link width and speed from PCI config space */
  224. pci_read_config_word(adapter->pdev, IXGBE_PCI_LINK_STATUS,
  225. &link_status);
  226. switch (link_status & IXGBE_PCI_LINK_WIDTH) {
  227. case IXGBE_PCI_LINK_WIDTH_1:
  228. hw->bus.width = ixgbe_bus_width_pcie_x1;
  229. break;
  230. case IXGBE_PCI_LINK_WIDTH_2:
  231. hw->bus.width = ixgbe_bus_width_pcie_x2;
  232. break;
  233. case IXGBE_PCI_LINK_WIDTH_4:
  234. hw->bus.width = ixgbe_bus_width_pcie_x4;
  235. break;
  236. case IXGBE_PCI_LINK_WIDTH_8:
  237. hw->bus.width = ixgbe_bus_width_pcie_x8;
  238. break;
  239. default:
  240. hw->bus.width = ixgbe_bus_width_unknown;
  241. break;
  242. }
  243. switch (link_status & IXGBE_PCI_LINK_SPEED) {
  244. case IXGBE_PCI_LINK_SPEED_2500:
  245. hw->bus.speed = ixgbe_bus_speed_2500;
  246. break;
  247. case IXGBE_PCI_LINK_SPEED_5000:
  248. hw->bus.speed = ixgbe_bus_speed_5000;
  249. break;
  250. default:
  251. hw->bus.speed = ixgbe_bus_speed_unknown;
  252. break;
  253. }
  254. mac->ops.set_lan_id(hw);
  255. return 0;
  256. }
  257. /**
  258. * ixgbe_set_lan_id_multi_port_pcie - Set LAN id for PCIe multiple port devices
  259. * @hw: pointer to the HW structure
  260. *
  261. * Determines the LAN function id by reading memory-mapped registers
  262. * and swaps the port value if requested.
  263. **/
  264. void ixgbe_set_lan_id_multi_port_pcie(struct ixgbe_hw *hw)
  265. {
  266. struct ixgbe_bus_info *bus = &hw->bus;
  267. u32 reg;
  268. reg = IXGBE_READ_REG(hw, IXGBE_STATUS);
  269. bus->func = (reg & IXGBE_STATUS_LAN_ID) >> IXGBE_STATUS_LAN_ID_SHIFT;
  270. bus->lan_id = bus->func;
  271. /* check for a port swap */
  272. reg = IXGBE_READ_REG(hw, IXGBE_FACTPS);
  273. if (reg & IXGBE_FACTPS_LFS)
  274. bus->func ^= 0x1;
  275. }
  276. /**
  277. * ixgbe_stop_adapter_generic - Generic stop Tx/Rx units
  278. * @hw: pointer to hardware structure
  279. *
  280. * Sets the adapter_stopped flag within ixgbe_hw struct. Clears interrupts,
  281. * disables transmit and receive units. The adapter_stopped flag is used by
  282. * the shared code and drivers to determine if the adapter is in a stopped
  283. * state and should not touch the hardware.
  284. **/
  285. s32 ixgbe_stop_adapter_generic(struct ixgbe_hw *hw)
  286. {
  287. u32 number_of_queues;
  288. u32 reg_val;
  289. u16 i;
  290. /*
  291. * Set the adapter_stopped flag so other driver functions stop touching
  292. * the hardware
  293. */
  294. hw->adapter_stopped = true;
  295. /* Disable the receive unit */
  296. reg_val = IXGBE_READ_REG(hw, IXGBE_RXCTRL);
  297. reg_val &= ~(IXGBE_RXCTRL_RXEN);
  298. IXGBE_WRITE_REG(hw, IXGBE_RXCTRL, reg_val);
  299. IXGBE_WRITE_FLUSH(hw);
  300. msleep(2);
  301. /* Clear interrupt mask to stop from interrupts being generated */
  302. IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_IRQ_CLEAR_MASK);
  303. /* Clear any pending interrupts */
  304. IXGBE_READ_REG(hw, IXGBE_EICR);
  305. /* Disable the transmit unit. Each queue must be disabled. */
  306. number_of_queues = hw->mac.max_tx_queues;
  307. for (i = 0; i < number_of_queues; i++) {
  308. reg_val = IXGBE_READ_REG(hw, IXGBE_TXDCTL(i));
  309. if (reg_val & IXGBE_TXDCTL_ENABLE) {
  310. reg_val &= ~IXGBE_TXDCTL_ENABLE;
  311. IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(i), reg_val);
  312. }
  313. }
  314. /*
  315. * Prevent the PCI-E bus from from hanging by disabling PCI-E master
  316. * access and verify no pending requests
  317. */
  318. if (ixgbe_disable_pcie_master(hw) != 0)
  319. hw_dbg(hw, "PCI-E Master disable polling has failed.\n");
  320. return 0;
  321. }
  322. /**
  323. * ixgbe_led_on_generic - Turns on the software controllable LEDs.
  324. * @hw: pointer to hardware structure
  325. * @index: led number to turn on
  326. **/
  327. s32 ixgbe_led_on_generic(struct ixgbe_hw *hw, u32 index)
  328. {
  329. u32 led_reg = IXGBE_READ_REG(hw, IXGBE_LEDCTL);
  330. /* To turn on the LED, set mode to ON. */
  331. led_reg &= ~IXGBE_LED_MODE_MASK(index);
  332. led_reg |= IXGBE_LED_ON << IXGBE_LED_MODE_SHIFT(index);
  333. IXGBE_WRITE_REG(hw, IXGBE_LEDCTL, led_reg);
  334. IXGBE_WRITE_FLUSH(hw);
  335. return 0;
  336. }
  337. /**
  338. * ixgbe_led_off_generic - Turns off the software controllable LEDs.
  339. * @hw: pointer to hardware structure
  340. * @index: led number to turn off
  341. **/
  342. s32 ixgbe_led_off_generic(struct ixgbe_hw *hw, u32 index)
  343. {
  344. u32 led_reg = IXGBE_READ_REG(hw, IXGBE_LEDCTL);
  345. /* To turn off the LED, set mode to OFF. */
  346. led_reg &= ~IXGBE_LED_MODE_MASK(index);
  347. led_reg |= IXGBE_LED_OFF << IXGBE_LED_MODE_SHIFT(index);
  348. IXGBE_WRITE_REG(hw, IXGBE_LEDCTL, led_reg);
  349. IXGBE_WRITE_FLUSH(hw);
  350. return 0;
  351. }
  352. /**
  353. * ixgbe_init_eeprom_params_generic - Initialize EEPROM params
  354. * @hw: pointer to hardware structure
  355. *
  356. * Initializes the EEPROM parameters ixgbe_eeprom_info within the
  357. * ixgbe_hw struct in order to set up EEPROM access.
  358. **/
  359. s32 ixgbe_init_eeprom_params_generic(struct ixgbe_hw *hw)
  360. {
  361. struct ixgbe_eeprom_info *eeprom = &hw->eeprom;
  362. u32 eec;
  363. u16 eeprom_size;
  364. if (eeprom->type == ixgbe_eeprom_uninitialized) {
  365. eeprom->type = ixgbe_eeprom_none;
  366. /* Set default semaphore delay to 10ms which is a well
  367. * tested value */
  368. eeprom->semaphore_delay = 10;
  369. /*
  370. * Check for EEPROM present first.
  371. * If not present leave as none
  372. */
  373. eec = IXGBE_READ_REG(hw, IXGBE_EEC);
  374. if (eec & IXGBE_EEC_PRES) {
  375. eeprom->type = ixgbe_eeprom_spi;
  376. /*
  377. * SPI EEPROM is assumed here. This code would need to
  378. * change if a future EEPROM is not SPI.
  379. */
  380. eeprom_size = (u16)((eec & IXGBE_EEC_SIZE) >>
  381. IXGBE_EEC_SIZE_SHIFT);
  382. eeprom->word_size = 1 << (eeprom_size +
  383. IXGBE_EEPROM_WORD_SIZE_SHIFT);
  384. }
  385. if (eec & IXGBE_EEC_ADDR_SIZE)
  386. eeprom->address_bits = 16;
  387. else
  388. eeprom->address_bits = 8;
  389. hw_dbg(hw, "Eeprom params: type = %d, size = %d, address bits: "
  390. "%d\n", eeprom->type, eeprom->word_size,
  391. eeprom->address_bits);
  392. }
  393. return 0;
  394. }
  395. /**
  396. * ixgbe_write_eeprom_generic - Writes 16 bit value to EEPROM
  397. * @hw: pointer to hardware structure
  398. * @offset: offset within the EEPROM to be written to
  399. * @data: 16 bit word to be written to the EEPROM
  400. *
  401. * If ixgbe_eeprom_update_checksum is not called after this function, the
  402. * EEPROM will most likely contain an invalid checksum.
  403. **/
  404. s32 ixgbe_write_eeprom_generic(struct ixgbe_hw *hw, u16 offset, u16 data)
  405. {
  406. s32 status;
  407. u8 write_opcode = IXGBE_EEPROM_WRITE_OPCODE_SPI;
  408. hw->eeprom.ops.init_params(hw);
  409. if (offset >= hw->eeprom.word_size) {
  410. status = IXGBE_ERR_EEPROM;
  411. goto out;
  412. }
  413. /* Prepare the EEPROM for writing */
  414. status = ixgbe_acquire_eeprom(hw);
  415. if (status == 0) {
  416. if (ixgbe_ready_eeprom(hw) != 0) {
  417. ixgbe_release_eeprom(hw);
  418. status = IXGBE_ERR_EEPROM;
  419. }
  420. }
  421. if (status == 0) {
  422. ixgbe_standby_eeprom(hw);
  423. /* Send the WRITE ENABLE command (8 bit opcode ) */
  424. ixgbe_shift_out_eeprom_bits(hw, IXGBE_EEPROM_WREN_OPCODE_SPI,
  425. IXGBE_EEPROM_OPCODE_BITS);
  426. ixgbe_standby_eeprom(hw);
  427. /*
  428. * Some SPI eeproms use the 8th address bit embedded in the
  429. * opcode
  430. */
  431. if ((hw->eeprom.address_bits == 8) && (offset >= 128))
  432. write_opcode |= IXGBE_EEPROM_A8_OPCODE_SPI;
  433. /* Send the Write command (8-bit opcode + addr) */
  434. ixgbe_shift_out_eeprom_bits(hw, write_opcode,
  435. IXGBE_EEPROM_OPCODE_BITS);
  436. ixgbe_shift_out_eeprom_bits(hw, (u16)(offset*2),
  437. hw->eeprom.address_bits);
  438. /* Send the data */
  439. data = (data >> 8) | (data << 8);
  440. ixgbe_shift_out_eeprom_bits(hw, data, 16);
  441. ixgbe_standby_eeprom(hw);
  442. msleep(hw->eeprom.semaphore_delay);
  443. /* Done with writing - release the EEPROM */
  444. ixgbe_release_eeprom(hw);
  445. }
  446. out:
  447. return status;
  448. }
  449. /**
  450. * ixgbe_read_eeprom_bit_bang_generic - Read EEPROM word using bit-bang
  451. * @hw: pointer to hardware structure
  452. * @offset: offset within the EEPROM to be read
  453. * @data: read 16 bit value from EEPROM
  454. *
  455. * Reads 16 bit value from EEPROM through bit-bang method
  456. **/
  457. s32 ixgbe_read_eeprom_bit_bang_generic(struct ixgbe_hw *hw, u16 offset,
  458. u16 *data)
  459. {
  460. s32 status;
  461. u16 word_in;
  462. u8 read_opcode = IXGBE_EEPROM_READ_OPCODE_SPI;
  463. hw->eeprom.ops.init_params(hw);
  464. if (offset >= hw->eeprom.word_size) {
  465. status = IXGBE_ERR_EEPROM;
  466. goto out;
  467. }
  468. /* Prepare the EEPROM for reading */
  469. status = ixgbe_acquire_eeprom(hw);
  470. if (status == 0) {
  471. if (ixgbe_ready_eeprom(hw) != 0) {
  472. ixgbe_release_eeprom(hw);
  473. status = IXGBE_ERR_EEPROM;
  474. }
  475. }
  476. if (status == 0) {
  477. ixgbe_standby_eeprom(hw);
  478. /*
  479. * Some SPI eeproms use the 8th address bit embedded in the
  480. * opcode
  481. */
  482. if ((hw->eeprom.address_bits == 8) && (offset >= 128))
  483. read_opcode |= IXGBE_EEPROM_A8_OPCODE_SPI;
  484. /* Send the READ command (opcode + addr) */
  485. ixgbe_shift_out_eeprom_bits(hw, read_opcode,
  486. IXGBE_EEPROM_OPCODE_BITS);
  487. ixgbe_shift_out_eeprom_bits(hw, (u16)(offset*2),
  488. hw->eeprom.address_bits);
  489. /* Read the data. */
  490. word_in = ixgbe_shift_in_eeprom_bits(hw, 16);
  491. *data = (word_in >> 8) | (word_in << 8);
  492. /* End this read operation */
  493. ixgbe_release_eeprom(hw);
  494. }
  495. out:
  496. return status;
  497. }
  498. /**
  499. * ixgbe_read_eeprom_generic - Read EEPROM word using EERD
  500. * @hw: pointer to hardware structure
  501. * @offset: offset of word in the EEPROM to read
  502. * @data: word read from the EEPROM
  503. *
  504. * Reads a 16 bit word from the EEPROM using the EERD register.
  505. **/
  506. s32 ixgbe_read_eeprom_generic(struct ixgbe_hw *hw, u16 offset, u16 *data)
  507. {
  508. u32 eerd;
  509. s32 status;
  510. hw->eeprom.ops.init_params(hw);
  511. if (offset >= hw->eeprom.word_size) {
  512. status = IXGBE_ERR_EEPROM;
  513. goto out;
  514. }
  515. eerd = (offset << IXGBE_EEPROM_READ_ADDR_SHIFT) +
  516. IXGBE_EEPROM_READ_REG_START;
  517. IXGBE_WRITE_REG(hw, IXGBE_EERD, eerd);
  518. status = ixgbe_poll_eeprom_eerd_done(hw);
  519. if (status == 0)
  520. *data = (IXGBE_READ_REG(hw, IXGBE_EERD) >>
  521. IXGBE_EEPROM_READ_REG_DATA);
  522. else
  523. hw_dbg(hw, "Eeprom read timed out\n");
  524. out:
  525. return status;
  526. }
  527. /**
  528. * ixgbe_poll_eeprom_eerd_done - Poll EERD status
  529. * @hw: pointer to hardware structure
  530. *
  531. * Polls the status bit (bit 1) of the EERD to determine when the read is done.
  532. **/
  533. static s32 ixgbe_poll_eeprom_eerd_done(struct ixgbe_hw *hw)
  534. {
  535. u32 i;
  536. u32 reg;
  537. s32 status = IXGBE_ERR_EEPROM;
  538. for (i = 0; i < IXGBE_EERD_ATTEMPTS; i++) {
  539. reg = IXGBE_READ_REG(hw, IXGBE_EERD);
  540. if (reg & IXGBE_EEPROM_READ_REG_DONE) {
  541. status = 0;
  542. break;
  543. }
  544. udelay(5);
  545. }
  546. return status;
  547. }
  548. /**
  549. * ixgbe_acquire_eeprom - Acquire EEPROM using bit-bang
  550. * @hw: pointer to hardware structure
  551. *
  552. * Prepares EEPROM for access using bit-bang method. This function should
  553. * be called before issuing a command to the EEPROM.
  554. **/
  555. static s32 ixgbe_acquire_eeprom(struct ixgbe_hw *hw)
  556. {
  557. s32 status = 0;
  558. u32 eec = 0;
  559. u32 i;
  560. if (ixgbe_acquire_swfw_sync(hw, IXGBE_GSSR_EEP_SM) != 0)
  561. status = IXGBE_ERR_SWFW_SYNC;
  562. if (status == 0) {
  563. eec = IXGBE_READ_REG(hw, IXGBE_EEC);
  564. /* Request EEPROM Access */
  565. eec |= IXGBE_EEC_REQ;
  566. IXGBE_WRITE_REG(hw, IXGBE_EEC, eec);
  567. for (i = 0; i < IXGBE_EEPROM_GRANT_ATTEMPTS; i++) {
  568. eec = IXGBE_READ_REG(hw, IXGBE_EEC);
  569. if (eec & IXGBE_EEC_GNT)
  570. break;
  571. udelay(5);
  572. }
  573. /* Release if grant not acquired */
  574. if (!(eec & IXGBE_EEC_GNT)) {
  575. eec &= ~IXGBE_EEC_REQ;
  576. IXGBE_WRITE_REG(hw, IXGBE_EEC, eec);
  577. hw_dbg(hw, "Could not acquire EEPROM grant\n");
  578. ixgbe_release_swfw_sync(hw, IXGBE_GSSR_EEP_SM);
  579. status = IXGBE_ERR_EEPROM;
  580. }
  581. }
  582. /* Setup EEPROM for Read/Write */
  583. if (status == 0) {
  584. /* Clear CS and SK */
  585. eec &= ~(IXGBE_EEC_CS | IXGBE_EEC_SK);
  586. IXGBE_WRITE_REG(hw, IXGBE_EEC, eec);
  587. IXGBE_WRITE_FLUSH(hw);
  588. udelay(1);
  589. }
  590. return status;
  591. }
  592. /**
  593. * ixgbe_get_eeprom_semaphore - Get hardware semaphore
  594. * @hw: pointer to hardware structure
  595. *
  596. * Sets the hardware semaphores so EEPROM access can occur for bit-bang method
  597. **/
  598. static s32 ixgbe_get_eeprom_semaphore(struct ixgbe_hw *hw)
  599. {
  600. s32 status = IXGBE_ERR_EEPROM;
  601. u32 timeout;
  602. u32 i;
  603. u32 swsm;
  604. /* Set timeout value based on size of EEPROM */
  605. timeout = hw->eeprom.word_size + 1;
  606. /* Get SMBI software semaphore between device drivers first */
  607. for (i = 0; i < timeout; i++) {
  608. /*
  609. * If the SMBI bit is 0 when we read it, then the bit will be
  610. * set and we have the semaphore
  611. */
  612. swsm = IXGBE_READ_REG(hw, IXGBE_SWSM);
  613. if (!(swsm & IXGBE_SWSM_SMBI)) {
  614. status = 0;
  615. break;
  616. }
  617. msleep(1);
  618. }
  619. /* Now get the semaphore between SW/FW through the SWESMBI bit */
  620. if (status == 0) {
  621. for (i = 0; i < timeout; i++) {
  622. swsm = IXGBE_READ_REG(hw, IXGBE_SWSM);
  623. /* Set the SW EEPROM semaphore bit to request access */
  624. swsm |= IXGBE_SWSM_SWESMBI;
  625. IXGBE_WRITE_REG(hw, IXGBE_SWSM, swsm);
  626. /*
  627. * If we set the bit successfully then we got the
  628. * semaphore.
  629. */
  630. swsm = IXGBE_READ_REG(hw, IXGBE_SWSM);
  631. if (swsm & IXGBE_SWSM_SWESMBI)
  632. break;
  633. udelay(50);
  634. }
  635. /*
  636. * Release semaphores and return error if SW EEPROM semaphore
  637. * was not granted because we don't have access to the EEPROM
  638. */
  639. if (i >= timeout) {
  640. hw_dbg(hw, "Driver can't access the Eeprom - Semaphore "
  641. "not granted.\n");
  642. ixgbe_release_eeprom_semaphore(hw);
  643. status = IXGBE_ERR_EEPROM;
  644. }
  645. }
  646. return status;
  647. }
  648. /**
  649. * ixgbe_release_eeprom_semaphore - Release hardware semaphore
  650. * @hw: pointer to hardware structure
  651. *
  652. * This function clears hardware semaphore bits.
  653. **/
  654. static void ixgbe_release_eeprom_semaphore(struct ixgbe_hw *hw)
  655. {
  656. u32 swsm;
  657. swsm = IXGBE_READ_REG(hw, IXGBE_SWSM);
  658. /* Release both semaphores by writing 0 to the bits SWESMBI and SMBI */
  659. swsm &= ~(IXGBE_SWSM_SWESMBI | IXGBE_SWSM_SMBI);
  660. IXGBE_WRITE_REG(hw, IXGBE_SWSM, swsm);
  661. IXGBE_WRITE_FLUSH(hw);
  662. }
  663. /**
  664. * ixgbe_ready_eeprom - Polls for EEPROM ready
  665. * @hw: pointer to hardware structure
  666. **/
  667. static s32 ixgbe_ready_eeprom(struct ixgbe_hw *hw)
  668. {
  669. s32 status = 0;
  670. u16 i;
  671. u8 spi_stat_reg;
  672. /*
  673. * Read "Status Register" repeatedly until the LSB is cleared. The
  674. * EEPROM will signal that the command has been completed by clearing
  675. * bit 0 of the internal status register. If it's not cleared within
  676. * 5 milliseconds, then error out.
  677. */
  678. for (i = 0; i < IXGBE_EEPROM_MAX_RETRY_SPI; i += 5) {
  679. ixgbe_shift_out_eeprom_bits(hw, IXGBE_EEPROM_RDSR_OPCODE_SPI,
  680. IXGBE_EEPROM_OPCODE_BITS);
  681. spi_stat_reg = (u8)ixgbe_shift_in_eeprom_bits(hw, 8);
  682. if (!(spi_stat_reg & IXGBE_EEPROM_STATUS_RDY_SPI))
  683. break;
  684. udelay(5);
  685. ixgbe_standby_eeprom(hw);
  686. };
  687. /*
  688. * On some parts, SPI write time could vary from 0-20mSec on 3.3V
  689. * devices (and only 0-5mSec on 5V devices)
  690. */
  691. if (i >= IXGBE_EEPROM_MAX_RETRY_SPI) {
  692. hw_dbg(hw, "SPI EEPROM Status error\n");
  693. status = IXGBE_ERR_EEPROM;
  694. }
  695. return status;
  696. }
  697. /**
  698. * ixgbe_standby_eeprom - Returns EEPROM to a "standby" state
  699. * @hw: pointer to hardware structure
  700. **/
  701. static void ixgbe_standby_eeprom(struct ixgbe_hw *hw)
  702. {
  703. u32 eec;
  704. eec = IXGBE_READ_REG(hw, IXGBE_EEC);
  705. /* Toggle CS to flush commands */
  706. eec |= IXGBE_EEC_CS;
  707. IXGBE_WRITE_REG(hw, IXGBE_EEC, eec);
  708. IXGBE_WRITE_FLUSH(hw);
  709. udelay(1);
  710. eec &= ~IXGBE_EEC_CS;
  711. IXGBE_WRITE_REG(hw, IXGBE_EEC, eec);
  712. IXGBE_WRITE_FLUSH(hw);
  713. udelay(1);
  714. }
  715. /**
  716. * ixgbe_shift_out_eeprom_bits - Shift data bits out to the EEPROM.
  717. * @hw: pointer to hardware structure
  718. * @data: data to send to the EEPROM
  719. * @count: number of bits to shift out
  720. **/
  721. static void ixgbe_shift_out_eeprom_bits(struct ixgbe_hw *hw, u16 data,
  722. u16 count)
  723. {
  724. u32 eec;
  725. u32 mask;
  726. u32 i;
  727. eec = IXGBE_READ_REG(hw, IXGBE_EEC);
  728. /*
  729. * Mask is used to shift "count" bits of "data" out to the EEPROM
  730. * one bit at a time. Determine the starting bit based on count
  731. */
  732. mask = 0x01 << (count - 1);
  733. for (i = 0; i < count; i++) {
  734. /*
  735. * A "1" is shifted out to the EEPROM by setting bit "DI" to a
  736. * "1", and then raising and then lowering the clock (the SK
  737. * bit controls the clock input to the EEPROM). A "0" is
  738. * shifted out to the EEPROM by setting "DI" to "0" and then
  739. * raising and then lowering the clock.
  740. */
  741. if (data & mask)
  742. eec |= IXGBE_EEC_DI;
  743. else
  744. eec &= ~IXGBE_EEC_DI;
  745. IXGBE_WRITE_REG(hw, IXGBE_EEC, eec);
  746. IXGBE_WRITE_FLUSH(hw);
  747. udelay(1);
  748. ixgbe_raise_eeprom_clk(hw, &eec);
  749. ixgbe_lower_eeprom_clk(hw, &eec);
  750. /*
  751. * Shift mask to signify next bit of data to shift in to the
  752. * EEPROM
  753. */
  754. mask = mask >> 1;
  755. };
  756. /* We leave the "DI" bit set to "0" when we leave this routine. */
  757. eec &= ~IXGBE_EEC_DI;
  758. IXGBE_WRITE_REG(hw, IXGBE_EEC, eec);
  759. IXGBE_WRITE_FLUSH(hw);
  760. }
  761. /**
  762. * ixgbe_shift_in_eeprom_bits - Shift data bits in from the EEPROM
  763. * @hw: pointer to hardware structure
  764. **/
  765. static u16 ixgbe_shift_in_eeprom_bits(struct ixgbe_hw *hw, u16 count)
  766. {
  767. u32 eec;
  768. u32 i;
  769. u16 data = 0;
  770. /*
  771. * In order to read a register from the EEPROM, we need to shift
  772. * 'count' bits in from the EEPROM. Bits are "shifted in" by raising
  773. * the clock input to the EEPROM (setting the SK bit), and then reading
  774. * the value of the "DO" bit. During this "shifting in" process the
  775. * "DI" bit should always be clear.
  776. */
  777. eec = IXGBE_READ_REG(hw, IXGBE_EEC);
  778. eec &= ~(IXGBE_EEC_DO | IXGBE_EEC_DI);
  779. for (i = 0; i < count; i++) {
  780. data = data << 1;
  781. ixgbe_raise_eeprom_clk(hw, &eec);
  782. eec = IXGBE_READ_REG(hw, IXGBE_EEC);
  783. eec &= ~(IXGBE_EEC_DI);
  784. if (eec & IXGBE_EEC_DO)
  785. data |= 1;
  786. ixgbe_lower_eeprom_clk(hw, &eec);
  787. }
  788. return data;
  789. }
  790. /**
  791. * ixgbe_raise_eeprom_clk - Raises the EEPROM's clock input.
  792. * @hw: pointer to hardware structure
  793. * @eec: EEC register's current value
  794. **/
  795. static void ixgbe_raise_eeprom_clk(struct ixgbe_hw *hw, u32 *eec)
  796. {
  797. /*
  798. * Raise the clock input to the EEPROM
  799. * (setting the SK bit), then delay
  800. */
  801. *eec = *eec | IXGBE_EEC_SK;
  802. IXGBE_WRITE_REG(hw, IXGBE_EEC, *eec);
  803. IXGBE_WRITE_FLUSH(hw);
  804. udelay(1);
  805. }
  806. /**
  807. * ixgbe_lower_eeprom_clk - Lowers the EEPROM's clock input.
  808. * @hw: pointer to hardware structure
  809. * @eecd: EECD's current value
  810. **/
  811. static void ixgbe_lower_eeprom_clk(struct ixgbe_hw *hw, u32 *eec)
  812. {
  813. /*
  814. * Lower the clock input to the EEPROM (clearing the SK bit), then
  815. * delay
  816. */
  817. *eec = *eec & ~IXGBE_EEC_SK;
  818. IXGBE_WRITE_REG(hw, IXGBE_EEC, *eec);
  819. IXGBE_WRITE_FLUSH(hw);
  820. udelay(1);
  821. }
  822. /**
  823. * ixgbe_release_eeprom - Release EEPROM, release semaphores
  824. * @hw: pointer to hardware structure
  825. **/
  826. static void ixgbe_release_eeprom(struct ixgbe_hw *hw)
  827. {
  828. u32 eec;
  829. eec = IXGBE_READ_REG(hw, IXGBE_EEC);
  830. eec |= IXGBE_EEC_CS; /* Pull CS high */
  831. eec &= ~IXGBE_EEC_SK; /* Lower SCK */
  832. IXGBE_WRITE_REG(hw, IXGBE_EEC, eec);
  833. IXGBE_WRITE_FLUSH(hw);
  834. udelay(1);
  835. /* Stop requesting EEPROM access */
  836. eec &= ~IXGBE_EEC_REQ;
  837. IXGBE_WRITE_REG(hw, IXGBE_EEC, eec);
  838. ixgbe_release_swfw_sync(hw, IXGBE_GSSR_EEP_SM);
  839. }
  840. /**
  841. * ixgbe_calc_eeprom_checksum - Calculates and returns the checksum
  842. * @hw: pointer to hardware structure
  843. **/
  844. static u16 ixgbe_calc_eeprom_checksum(struct ixgbe_hw *hw)
  845. {
  846. u16 i;
  847. u16 j;
  848. u16 checksum = 0;
  849. u16 length = 0;
  850. u16 pointer = 0;
  851. u16 word = 0;
  852. /* Include 0x0-0x3F in the checksum */
  853. for (i = 0; i < IXGBE_EEPROM_CHECKSUM; i++) {
  854. if (hw->eeprom.ops.read(hw, i, &word) != 0) {
  855. hw_dbg(hw, "EEPROM read failed\n");
  856. break;
  857. }
  858. checksum += word;
  859. }
  860. /* Include all data from pointers except for the fw pointer */
  861. for (i = IXGBE_PCIE_ANALOG_PTR; i < IXGBE_FW_PTR; i++) {
  862. hw->eeprom.ops.read(hw, i, &pointer);
  863. /* Make sure the pointer seems valid */
  864. if (pointer != 0xFFFF && pointer != 0) {
  865. hw->eeprom.ops.read(hw, pointer, &length);
  866. if (length != 0xFFFF && length != 0) {
  867. for (j = pointer+1; j <= pointer+length; j++) {
  868. hw->eeprom.ops.read(hw, j, &word);
  869. checksum += word;
  870. }
  871. }
  872. }
  873. }
  874. checksum = (u16)IXGBE_EEPROM_SUM - checksum;
  875. return checksum;
  876. }
  877. /**
  878. * ixgbe_validate_eeprom_checksum_generic - Validate EEPROM checksum
  879. * @hw: pointer to hardware structure
  880. * @checksum_val: calculated checksum
  881. *
  882. * Performs checksum calculation and validates the EEPROM checksum. If the
  883. * caller does not need checksum_val, the value can be NULL.
  884. **/
  885. s32 ixgbe_validate_eeprom_checksum_generic(struct ixgbe_hw *hw,
  886. u16 *checksum_val)
  887. {
  888. s32 status;
  889. u16 checksum;
  890. u16 read_checksum = 0;
  891. /*
  892. * Read the first word from the EEPROM. If this times out or fails, do
  893. * not continue or we could be in for a very long wait while every
  894. * EEPROM read fails
  895. */
  896. status = hw->eeprom.ops.read(hw, 0, &checksum);
  897. if (status == 0) {
  898. checksum = ixgbe_calc_eeprom_checksum(hw);
  899. hw->eeprom.ops.read(hw, IXGBE_EEPROM_CHECKSUM, &read_checksum);
  900. /*
  901. * Verify read checksum from EEPROM is the same as
  902. * calculated checksum
  903. */
  904. if (read_checksum != checksum)
  905. status = IXGBE_ERR_EEPROM_CHECKSUM;
  906. /* If the user cares, return the calculated checksum */
  907. if (checksum_val)
  908. *checksum_val = checksum;
  909. } else {
  910. hw_dbg(hw, "EEPROM read failed\n");
  911. }
  912. return status;
  913. }
  914. /**
  915. * ixgbe_update_eeprom_checksum_generic - Updates the EEPROM checksum
  916. * @hw: pointer to hardware structure
  917. **/
  918. s32 ixgbe_update_eeprom_checksum_generic(struct ixgbe_hw *hw)
  919. {
  920. s32 status;
  921. u16 checksum;
  922. /*
  923. * Read the first word from the EEPROM. If this times out or fails, do
  924. * not continue or we could be in for a very long wait while every
  925. * EEPROM read fails
  926. */
  927. status = hw->eeprom.ops.read(hw, 0, &checksum);
  928. if (status == 0) {
  929. checksum = ixgbe_calc_eeprom_checksum(hw);
  930. status = hw->eeprom.ops.write(hw, IXGBE_EEPROM_CHECKSUM,
  931. checksum);
  932. } else {
  933. hw_dbg(hw, "EEPROM read failed\n");
  934. }
  935. return status;
  936. }
  937. /**
  938. * ixgbe_validate_mac_addr - Validate MAC address
  939. * @mac_addr: pointer to MAC address.
  940. *
  941. * Tests a MAC address to ensure it is a valid Individual Address
  942. **/
  943. s32 ixgbe_validate_mac_addr(u8 *mac_addr)
  944. {
  945. s32 status = 0;
  946. /* Make sure it is not a multicast address */
  947. if (IXGBE_IS_MULTICAST(mac_addr))
  948. status = IXGBE_ERR_INVALID_MAC_ADDR;
  949. /* Not a broadcast address */
  950. else if (IXGBE_IS_BROADCAST(mac_addr))
  951. status = IXGBE_ERR_INVALID_MAC_ADDR;
  952. /* Reject the zero address */
  953. else if (mac_addr[0] == 0 && mac_addr[1] == 0 && mac_addr[2] == 0 &&
  954. mac_addr[3] == 0 && mac_addr[4] == 0 && mac_addr[5] == 0)
  955. status = IXGBE_ERR_INVALID_MAC_ADDR;
  956. return status;
  957. }
  958. /**
  959. * ixgbe_set_rar_generic - Set Rx address register
  960. * @hw: pointer to hardware structure
  961. * @index: Receive address register to write
  962. * @addr: Address to put into receive address register
  963. * @vmdq: VMDq "set" or "pool" index
  964. * @enable_addr: set flag that address is active
  965. *
  966. * Puts an ethernet address into a receive address register.
  967. **/
  968. s32 ixgbe_set_rar_generic(struct ixgbe_hw *hw, u32 index, u8 *addr, u32 vmdq,
  969. u32 enable_addr)
  970. {
  971. u32 rar_low, rar_high;
  972. u32 rar_entries = hw->mac.num_rar_entries;
  973. /* setup VMDq pool selection before this RAR gets enabled */
  974. hw->mac.ops.set_vmdq(hw, index, vmdq);
  975. /* Make sure we are using a valid rar index range */
  976. if (index < rar_entries) {
  977. /*
  978. * HW expects these in little endian so we reverse the byte
  979. * order from network order (big endian) to little endian
  980. */
  981. rar_low = ((u32)addr[0] |
  982. ((u32)addr[1] << 8) |
  983. ((u32)addr[2] << 16) |
  984. ((u32)addr[3] << 24));
  985. /*
  986. * Some parts put the VMDq setting in the extra RAH bits,
  987. * so save everything except the lower 16 bits that hold part
  988. * of the address and the address valid bit.
  989. */
  990. rar_high = IXGBE_READ_REG(hw, IXGBE_RAH(index));
  991. rar_high &= ~(0x0000FFFF | IXGBE_RAH_AV);
  992. rar_high |= ((u32)addr[4] | ((u32)addr[5] << 8));
  993. if (enable_addr != 0)
  994. rar_high |= IXGBE_RAH_AV;
  995. IXGBE_WRITE_REG(hw, IXGBE_RAL(index), rar_low);
  996. IXGBE_WRITE_REG(hw, IXGBE_RAH(index), rar_high);
  997. } else {
  998. hw_dbg(hw, "RAR index %d is out of range.\n", index);
  999. }
  1000. return 0;
  1001. }
  1002. /**
  1003. * ixgbe_clear_rar_generic - Remove Rx address register
  1004. * @hw: pointer to hardware structure
  1005. * @index: Receive address register to write
  1006. *
  1007. * Clears an ethernet address from a receive address register.
  1008. **/
  1009. s32 ixgbe_clear_rar_generic(struct ixgbe_hw *hw, u32 index)
  1010. {
  1011. u32 rar_high;
  1012. u32 rar_entries = hw->mac.num_rar_entries;
  1013. /* Make sure we are using a valid rar index range */
  1014. if (index < rar_entries) {
  1015. /*
  1016. * Some parts put the VMDq setting in the extra RAH bits,
  1017. * so save everything except the lower 16 bits that hold part
  1018. * of the address and the address valid bit.
  1019. */
  1020. rar_high = IXGBE_READ_REG(hw, IXGBE_RAH(index));
  1021. rar_high &= ~(0x0000FFFF | IXGBE_RAH_AV);
  1022. IXGBE_WRITE_REG(hw, IXGBE_RAL(index), 0);
  1023. IXGBE_WRITE_REG(hw, IXGBE_RAH(index), rar_high);
  1024. } else {
  1025. hw_dbg(hw, "RAR index %d is out of range.\n", index);
  1026. }
  1027. /* clear VMDq pool/queue selection for this RAR */
  1028. hw->mac.ops.clear_vmdq(hw, index, IXGBE_CLEAR_VMDQ_ALL);
  1029. return 0;
  1030. }
  1031. /**
  1032. * ixgbe_enable_rar - Enable Rx address register
  1033. * @hw: pointer to hardware structure
  1034. * @index: index into the RAR table
  1035. *
  1036. * Enables the select receive address register.
  1037. **/
  1038. static void ixgbe_enable_rar(struct ixgbe_hw *hw, u32 index)
  1039. {
  1040. u32 rar_high;
  1041. rar_high = IXGBE_READ_REG(hw, IXGBE_RAH(index));
  1042. rar_high |= IXGBE_RAH_AV;
  1043. IXGBE_WRITE_REG(hw, IXGBE_RAH(index), rar_high);
  1044. }
  1045. /**
  1046. * ixgbe_disable_rar - Disable Rx address register
  1047. * @hw: pointer to hardware structure
  1048. * @index: index into the RAR table
  1049. *
  1050. * Disables the select receive address register.
  1051. **/
  1052. static void ixgbe_disable_rar(struct ixgbe_hw *hw, u32 index)
  1053. {
  1054. u32 rar_high;
  1055. rar_high = IXGBE_READ_REG(hw, IXGBE_RAH(index));
  1056. rar_high &= (~IXGBE_RAH_AV);
  1057. IXGBE_WRITE_REG(hw, IXGBE_RAH(index), rar_high);
  1058. }
  1059. /**
  1060. * ixgbe_init_rx_addrs_generic - Initializes receive address filters.
  1061. * @hw: pointer to hardware structure
  1062. *
  1063. * Places the MAC address in receive address register 0 and clears the rest
  1064. * of the receive address registers. Clears the multicast table. Assumes
  1065. * the receiver is in reset when the routine is called.
  1066. **/
  1067. s32 ixgbe_init_rx_addrs_generic(struct ixgbe_hw *hw)
  1068. {
  1069. u32 i;
  1070. u32 rar_entries = hw->mac.num_rar_entries;
  1071. /*
  1072. * If the current mac address is valid, assume it is a software override
  1073. * to the permanent address.
  1074. * Otherwise, use the permanent address from the eeprom.
  1075. */
  1076. if (ixgbe_validate_mac_addr(hw->mac.addr) ==
  1077. IXGBE_ERR_INVALID_MAC_ADDR) {
  1078. /* Get the MAC address from the RAR0 for later reference */
  1079. hw->mac.ops.get_mac_addr(hw, hw->mac.addr);
  1080. hw_dbg(hw, " Keeping Current RAR0 Addr =%.2X %.2X %.2X ",
  1081. hw->mac.addr[0], hw->mac.addr[1],
  1082. hw->mac.addr[2]);
  1083. hw_dbg(hw, "%.2X %.2X %.2X\n", hw->mac.addr[3],
  1084. hw->mac.addr[4], hw->mac.addr[5]);
  1085. } else {
  1086. /* Setup the receive address. */
  1087. hw_dbg(hw, "Overriding MAC Address in RAR[0]\n");
  1088. hw_dbg(hw, " New MAC Addr =%.2X %.2X %.2X ",
  1089. hw->mac.addr[0], hw->mac.addr[1],
  1090. hw->mac.addr[2]);
  1091. hw_dbg(hw, "%.2X %.2X %.2X\n", hw->mac.addr[3],
  1092. hw->mac.addr[4], hw->mac.addr[5]);
  1093. hw->mac.ops.set_rar(hw, 0, hw->mac.addr, 0, IXGBE_RAH_AV);
  1094. }
  1095. hw->addr_ctrl.overflow_promisc = 0;
  1096. hw->addr_ctrl.rar_used_count = 1;
  1097. /* Zero out the other receive addresses. */
  1098. hw_dbg(hw, "Clearing RAR[1-%d]\n", rar_entries - 1);
  1099. for (i = 1; i < rar_entries; i++) {
  1100. IXGBE_WRITE_REG(hw, IXGBE_RAL(i), 0);
  1101. IXGBE_WRITE_REG(hw, IXGBE_RAH(i), 0);
  1102. }
  1103. /* Clear the MTA */
  1104. hw->addr_ctrl.mc_addr_in_rar_count = 0;
  1105. hw->addr_ctrl.mta_in_use = 0;
  1106. IXGBE_WRITE_REG(hw, IXGBE_MCSTCTRL, hw->mac.mc_filter_type);
  1107. hw_dbg(hw, " Clearing MTA\n");
  1108. for (i = 0; i < hw->mac.mcft_size; i++)
  1109. IXGBE_WRITE_REG(hw, IXGBE_MTA(i), 0);
  1110. if (hw->mac.ops.init_uta_tables)
  1111. hw->mac.ops.init_uta_tables(hw);
  1112. return 0;
  1113. }
  1114. /**
  1115. * ixgbe_add_uc_addr - Adds a secondary unicast address.
  1116. * @hw: pointer to hardware structure
  1117. * @addr: new address
  1118. *
  1119. * Adds it to unused receive address register or goes into promiscuous mode.
  1120. **/
  1121. static void ixgbe_add_uc_addr(struct ixgbe_hw *hw, u8 *addr, u32 vmdq)
  1122. {
  1123. u32 rar_entries = hw->mac.num_rar_entries;
  1124. u32 rar;
  1125. hw_dbg(hw, " UC Addr = %.2X %.2X %.2X %.2X %.2X %.2X\n",
  1126. addr[0], addr[1], addr[2], addr[3], addr[4], addr[5]);
  1127. /*
  1128. * Place this address in the RAR if there is room,
  1129. * else put the controller into promiscuous mode
  1130. */
  1131. if (hw->addr_ctrl.rar_used_count < rar_entries) {
  1132. rar = hw->addr_ctrl.rar_used_count -
  1133. hw->addr_ctrl.mc_addr_in_rar_count;
  1134. hw->mac.ops.set_rar(hw, rar, addr, vmdq, IXGBE_RAH_AV);
  1135. hw_dbg(hw, "Added a secondary address to RAR[%d]\n", rar);
  1136. hw->addr_ctrl.rar_used_count++;
  1137. } else {
  1138. hw->addr_ctrl.overflow_promisc++;
  1139. }
  1140. hw_dbg(hw, "ixgbe_add_uc_addr Complete\n");
  1141. }
  1142. /**
  1143. * ixgbe_update_uc_addr_list_generic - Updates MAC list of secondary addresses
  1144. * @hw: pointer to hardware structure
  1145. * @addr_list: the list of new addresses
  1146. * @addr_count: number of addresses
  1147. * @next: iterator function to walk the address list
  1148. *
  1149. * The given list replaces any existing list. Clears the secondary addrs from
  1150. * receive address registers. Uses unused receive address registers for the
  1151. * first secondary addresses, and falls back to promiscuous mode as needed.
  1152. *
  1153. * Drivers using secondary unicast addresses must set user_set_promisc when
  1154. * manually putting the device into promiscuous mode.
  1155. **/
  1156. s32 ixgbe_update_uc_addr_list_generic(struct ixgbe_hw *hw,
  1157. struct list_head *uc_list)
  1158. {
  1159. u32 i;
  1160. u32 old_promisc_setting = hw->addr_ctrl.overflow_promisc;
  1161. u32 uc_addr_in_use;
  1162. u32 fctrl;
  1163. struct netdev_hw_addr *ha;
  1164. /*
  1165. * Clear accounting of old secondary address list,
  1166. * don't count RAR[0]
  1167. */
  1168. uc_addr_in_use = hw->addr_ctrl.rar_used_count - 1;
  1169. hw->addr_ctrl.rar_used_count -= uc_addr_in_use;
  1170. hw->addr_ctrl.overflow_promisc = 0;
  1171. /* Zero out the other receive addresses */
  1172. hw_dbg(hw, "Clearing RAR[1-%d]\n", uc_addr_in_use);
  1173. for (i = 1; i <= uc_addr_in_use; i++) {
  1174. IXGBE_WRITE_REG(hw, IXGBE_RAL(i), 0);
  1175. IXGBE_WRITE_REG(hw, IXGBE_RAH(i), 0);
  1176. }
  1177. /* Add the new addresses */
  1178. list_for_each_entry(ha, uc_list, list) {
  1179. hw_dbg(hw, " Adding the secondary addresses:\n");
  1180. ixgbe_add_uc_addr(hw, ha->addr, 0);
  1181. }
  1182. if (hw->addr_ctrl.overflow_promisc) {
  1183. /* enable promisc if not already in overflow or set by user */
  1184. if (!old_promisc_setting && !hw->addr_ctrl.user_set_promisc) {
  1185. hw_dbg(hw, " Entering address overflow promisc mode\n");
  1186. fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
  1187. fctrl |= IXGBE_FCTRL_UPE;
  1188. IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl);
  1189. }
  1190. } else {
  1191. /* only disable if set by overflow, not by user */
  1192. if (old_promisc_setting && !hw->addr_ctrl.user_set_promisc) {
  1193. hw_dbg(hw, " Leaving address overflow promisc mode\n");
  1194. fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
  1195. fctrl &= ~IXGBE_FCTRL_UPE;
  1196. IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl);
  1197. }
  1198. }
  1199. hw_dbg(hw, "ixgbe_update_uc_addr_list_generic Complete\n");
  1200. return 0;
  1201. }
  1202. /**
  1203. * ixgbe_mta_vector - Determines bit-vector in multicast table to set
  1204. * @hw: pointer to hardware structure
  1205. * @mc_addr: the multicast address
  1206. *
  1207. * Extracts the 12 bits, from a multicast address, to determine which
  1208. * bit-vector to set in the multicast table. The hardware uses 12 bits, from
  1209. * incoming rx multicast addresses, to determine the bit-vector to check in
  1210. * the MTA. Which of the 4 combination, of 12-bits, the hardware uses is set
  1211. * by the MO field of the MCSTCTRL. The MO field is set during initialization
  1212. * to mc_filter_type.
  1213. **/
  1214. static s32 ixgbe_mta_vector(struct ixgbe_hw *hw, u8 *mc_addr)
  1215. {
  1216. u32 vector = 0;
  1217. switch (hw->mac.mc_filter_type) {
  1218. case 0: /* use bits [47:36] of the address */
  1219. vector = ((mc_addr[4] >> 4) | (((u16)mc_addr[5]) << 4));
  1220. break;
  1221. case 1: /* use bits [46:35] of the address */
  1222. vector = ((mc_addr[4] >> 3) | (((u16)mc_addr[5]) << 5));
  1223. break;
  1224. case 2: /* use bits [45:34] of the address */
  1225. vector = ((mc_addr[4] >> 2) | (((u16)mc_addr[5]) << 6));
  1226. break;
  1227. case 3: /* use bits [43:32] of the address */
  1228. vector = ((mc_addr[4]) | (((u16)mc_addr[5]) << 8));
  1229. break;
  1230. default: /* Invalid mc_filter_type */
  1231. hw_dbg(hw, "MC filter type param set incorrectly\n");
  1232. break;
  1233. }
  1234. /* vector can only be 12-bits or boundary will be exceeded */
  1235. vector &= 0xFFF;
  1236. return vector;
  1237. }
  1238. /**
  1239. * ixgbe_set_mta - Set bit-vector in multicast table
  1240. * @hw: pointer to hardware structure
  1241. * @hash_value: Multicast address hash value
  1242. *
  1243. * Sets the bit-vector in the multicast table.
  1244. **/
  1245. static void ixgbe_set_mta(struct ixgbe_hw *hw, u8 *mc_addr)
  1246. {
  1247. u32 vector;
  1248. u32 vector_bit;
  1249. u32 vector_reg;
  1250. u32 mta_reg;
  1251. hw->addr_ctrl.mta_in_use++;
  1252. vector = ixgbe_mta_vector(hw, mc_addr);
  1253. hw_dbg(hw, " bit-vector = 0x%03X\n", vector);
  1254. /*
  1255. * The MTA is a register array of 128 32-bit registers. It is treated
  1256. * like an array of 4096 bits. We want to set bit
  1257. * BitArray[vector_value]. So we figure out what register the bit is
  1258. * in, read it, OR in the new bit, then write back the new value. The
  1259. * register is determined by the upper 7 bits of the vector value and
  1260. * the bit within that register are determined by the lower 5 bits of
  1261. * the value.
  1262. */
  1263. vector_reg = (vector >> 5) & 0x7F;
  1264. vector_bit = vector & 0x1F;
  1265. mta_reg = IXGBE_READ_REG(hw, IXGBE_MTA(vector_reg));
  1266. mta_reg |= (1 << vector_bit);
  1267. IXGBE_WRITE_REG(hw, IXGBE_MTA(vector_reg), mta_reg);
  1268. }
  1269. /**
  1270. * ixgbe_update_mc_addr_list_generic - Updates MAC list of multicast addresses
  1271. * @hw: pointer to hardware structure
  1272. * @mc_addr_list: the list of new multicast addresses
  1273. * @mc_addr_count: number of addresses
  1274. * @next: iterator function to walk the multicast address list
  1275. *
  1276. * The given list replaces any existing list. Clears the MC addrs from receive
  1277. * address registers and the multicast table. Uses unused receive address
  1278. * registers for the first multicast addresses, and hashes the rest into the
  1279. * multicast table.
  1280. **/
  1281. s32 ixgbe_update_mc_addr_list_generic(struct ixgbe_hw *hw, u8 *mc_addr_list,
  1282. u32 mc_addr_count, ixgbe_mc_addr_itr next)
  1283. {
  1284. u32 i;
  1285. u32 vmdq;
  1286. /*
  1287. * Set the new number of MC addresses that we are being requested to
  1288. * use.
  1289. */
  1290. hw->addr_ctrl.num_mc_addrs = mc_addr_count;
  1291. hw->addr_ctrl.mta_in_use = 0;
  1292. /* Clear the MTA */
  1293. hw_dbg(hw, " Clearing MTA\n");
  1294. for (i = 0; i < hw->mac.mcft_size; i++)
  1295. IXGBE_WRITE_REG(hw, IXGBE_MTA(i), 0);
  1296. /* Add the new addresses */
  1297. for (i = 0; i < mc_addr_count; i++) {
  1298. hw_dbg(hw, " Adding the multicast addresses:\n");
  1299. ixgbe_set_mta(hw, next(hw, &mc_addr_list, &vmdq));
  1300. }
  1301. /* Enable mta */
  1302. if (hw->addr_ctrl.mta_in_use > 0)
  1303. IXGBE_WRITE_REG(hw, IXGBE_MCSTCTRL,
  1304. IXGBE_MCSTCTRL_MFE | hw->mac.mc_filter_type);
  1305. hw_dbg(hw, "ixgbe_update_mc_addr_list_generic Complete\n");
  1306. return 0;
  1307. }
  1308. /**
  1309. * ixgbe_enable_mc_generic - Enable multicast address in RAR
  1310. * @hw: pointer to hardware structure
  1311. *
  1312. * Enables multicast address in RAR and the use of the multicast hash table.
  1313. **/
  1314. s32 ixgbe_enable_mc_generic(struct ixgbe_hw *hw)
  1315. {
  1316. u32 i;
  1317. u32 rar_entries = hw->mac.num_rar_entries;
  1318. struct ixgbe_addr_filter_info *a = &hw->addr_ctrl;
  1319. if (a->mc_addr_in_rar_count > 0)
  1320. for (i = (rar_entries - a->mc_addr_in_rar_count);
  1321. i < rar_entries; i++)
  1322. ixgbe_enable_rar(hw, i);
  1323. if (a->mta_in_use > 0)
  1324. IXGBE_WRITE_REG(hw, IXGBE_MCSTCTRL, IXGBE_MCSTCTRL_MFE |
  1325. hw->mac.mc_filter_type);
  1326. return 0;
  1327. }
  1328. /**
  1329. * ixgbe_disable_mc_generic - Disable multicast address in RAR
  1330. * @hw: pointer to hardware structure
  1331. *
  1332. * Disables multicast address in RAR and the use of the multicast hash table.
  1333. **/
  1334. s32 ixgbe_disable_mc_generic(struct ixgbe_hw *hw)
  1335. {
  1336. u32 i;
  1337. u32 rar_entries = hw->mac.num_rar_entries;
  1338. struct ixgbe_addr_filter_info *a = &hw->addr_ctrl;
  1339. if (a->mc_addr_in_rar_count > 0)
  1340. for (i = (rar_entries - a->mc_addr_in_rar_count);
  1341. i < rar_entries; i++)
  1342. ixgbe_disable_rar(hw, i);
  1343. if (a->mta_in_use > 0)
  1344. IXGBE_WRITE_REG(hw, IXGBE_MCSTCTRL, hw->mac.mc_filter_type);
  1345. return 0;
  1346. }
  1347. /**
  1348. * ixgbe_fc_enable - Enable flow control
  1349. * @hw: pointer to hardware structure
  1350. * @packetbuf_num: packet buffer number (0-7)
  1351. *
  1352. * Enable flow control according to the current settings.
  1353. **/
  1354. s32 ixgbe_fc_enable(struct ixgbe_hw *hw, s32 packetbuf_num)
  1355. {
  1356. s32 ret_val = 0;
  1357. u32 mflcn_reg;
  1358. u32 fccfg_reg;
  1359. u32 reg;
  1360. u32 rx_pba_size;
  1361. #ifdef CONFIG_DCB
  1362. if (hw->fc.requested_mode == ixgbe_fc_pfc)
  1363. goto out;
  1364. #endif /* CONFIG_DCB */
  1365. mflcn_reg = IXGBE_READ_REG(hw, IXGBE_MFLCN);
  1366. mflcn_reg &= ~(IXGBE_MFLCN_RFCE | IXGBE_MFLCN_RPFCE);
  1367. fccfg_reg = IXGBE_READ_REG(hw, IXGBE_FCCFG);
  1368. fccfg_reg &= ~(IXGBE_FCCFG_TFCE_802_3X | IXGBE_FCCFG_TFCE_PRIORITY);
  1369. /*
  1370. * The possible values of fc.current_mode are:
  1371. * 0: Flow control is completely disabled
  1372. * 1: Rx flow control is enabled (we can receive pause frames,
  1373. * but not send pause frames).
  1374. * 2: Tx flow control is enabled (we can send pause frames but
  1375. * we do not support receiving pause frames).
  1376. * 3: Both Rx and Tx flow control (symmetric) are enabled.
  1377. * 4: Priority Flow Control is enabled.
  1378. * other: Invalid.
  1379. */
  1380. switch (hw->fc.current_mode) {
  1381. case ixgbe_fc_none:
  1382. /* Flow control completely disabled by software override. */
  1383. break;
  1384. case ixgbe_fc_rx_pause:
  1385. /*
  1386. * Rx Flow control is enabled and Tx Flow control is
  1387. * disabled by software override. Since there really
  1388. * isn't a way to advertise that we are capable of RX
  1389. * Pause ONLY, we will advertise that we support both
  1390. * symmetric and asymmetric Rx PAUSE. Later, we will
  1391. * disable the adapter's ability to send PAUSE frames.
  1392. */
  1393. mflcn_reg |= IXGBE_MFLCN_RFCE;
  1394. break;
  1395. case ixgbe_fc_tx_pause:
  1396. /*
  1397. * Tx Flow control is enabled, and Rx Flow control is
  1398. * disabled by software override.
  1399. */
  1400. fccfg_reg |= IXGBE_FCCFG_TFCE_802_3X;
  1401. break;
  1402. case ixgbe_fc_full:
  1403. /* Flow control (both Rx and Tx) is enabled by SW override. */
  1404. mflcn_reg |= IXGBE_MFLCN_RFCE;
  1405. fccfg_reg |= IXGBE_FCCFG_TFCE_802_3X;
  1406. break;
  1407. #ifdef CONFIG_DCB
  1408. case ixgbe_fc_pfc:
  1409. goto out;
  1410. break;
  1411. #endif
  1412. default:
  1413. hw_dbg(hw, "Flow control param set incorrectly\n");
  1414. ret_val = -IXGBE_ERR_CONFIG;
  1415. goto out;
  1416. break;
  1417. }
  1418. /* Enable 802.3x based flow control settings. */
  1419. mflcn_reg |= IXGBE_MFLCN_DPF;
  1420. IXGBE_WRITE_REG(hw, IXGBE_MFLCN, mflcn_reg);
  1421. IXGBE_WRITE_REG(hw, IXGBE_FCCFG, fccfg_reg);
  1422. reg = IXGBE_READ_REG(hw, IXGBE_MTQC);
  1423. /* Thresholds are different for link flow control when in DCB mode */
  1424. if (reg & IXGBE_MTQC_RT_ENA) {
  1425. /* Always disable XON for LFC when in DCB mode */
  1426. IXGBE_WRITE_REG(hw, IXGBE_FCRTL_82599(packetbuf_num), 0);
  1427. rx_pba_size = IXGBE_READ_REG(hw, IXGBE_RXPBSIZE(packetbuf_num));
  1428. reg = (rx_pba_size >> 2) & 0xFFE0;
  1429. if (hw->fc.current_mode & ixgbe_fc_tx_pause)
  1430. reg |= IXGBE_FCRTH_FCEN;
  1431. IXGBE_WRITE_REG(hw, IXGBE_FCRTH_82599(packetbuf_num), reg);
  1432. } else {
  1433. /*
  1434. * Set up and enable Rx high/low water mark thresholds,
  1435. * enable XON.
  1436. */
  1437. if (hw->fc.current_mode & ixgbe_fc_tx_pause) {
  1438. if (hw->fc.send_xon) {
  1439. IXGBE_WRITE_REG(hw,
  1440. IXGBE_FCRTL_82599(packetbuf_num),
  1441. (hw->fc.low_water |
  1442. IXGBE_FCRTL_XONE));
  1443. } else {
  1444. IXGBE_WRITE_REG(hw,
  1445. IXGBE_FCRTL_82599(packetbuf_num),
  1446. hw->fc.low_water);
  1447. }
  1448. IXGBE_WRITE_REG(hw, IXGBE_FCRTH_82599(packetbuf_num),
  1449. (hw->fc.high_water | IXGBE_FCRTH_FCEN));
  1450. }
  1451. }
  1452. /* Configure pause time (2 TCs per register) */
  1453. reg = IXGBE_READ_REG(hw, IXGBE_FCTTV(packetbuf_num / 2));
  1454. if ((packetbuf_num & 1) == 0)
  1455. reg = (reg & 0xFFFF0000) | hw->fc.pause_time;
  1456. else
  1457. reg = (reg & 0x0000FFFF) | (hw->fc.pause_time << 16);
  1458. IXGBE_WRITE_REG(hw, IXGBE_FCTTV(packetbuf_num / 2), reg);
  1459. IXGBE_WRITE_REG(hw, IXGBE_FCRTV, (hw->fc.pause_time >> 1));
  1460. out:
  1461. return ret_val;
  1462. }
  1463. /**
  1464. * ixgbe_fc_autoneg - Configure flow control
  1465. * @hw: pointer to hardware structure
  1466. *
  1467. * Negotiates flow control capabilities with link partner using autoneg and
  1468. * applies the results.
  1469. **/
  1470. s32 ixgbe_fc_autoneg(struct ixgbe_hw *hw)
  1471. {
  1472. s32 ret_val = 0;
  1473. u32 i, reg, pcs_anadv_reg, pcs_lpab_reg;
  1474. reg = IXGBE_READ_REG(hw, IXGBE_PCS1GANA);
  1475. /*
  1476. * The possible values of fc.current_mode are:
  1477. * 0: Flow control is completely disabled
  1478. * 1: Rx flow control is enabled (we can receive pause frames,
  1479. * but not send pause frames).
  1480. * 2: Tx flow control is enabled (we can send pause frames but
  1481. * we do not support receiving pause frames).
  1482. * 3: Both Rx and Tx flow control (symmetric) are enabled.
  1483. * 4: Priority Flow Control is enabled.
  1484. * other: Invalid.
  1485. */
  1486. switch (hw->fc.current_mode) {
  1487. case ixgbe_fc_none:
  1488. /* Flow control completely disabled by software override. */
  1489. reg &= ~(IXGBE_PCS1GANA_SYM_PAUSE | IXGBE_PCS1GANA_ASM_PAUSE);
  1490. break;
  1491. case ixgbe_fc_rx_pause:
  1492. /*
  1493. * Rx Flow control is enabled and Tx Flow control is
  1494. * disabled by software override. Since there really
  1495. * isn't a way to advertise that we are capable of RX
  1496. * Pause ONLY, we will advertise that we support both
  1497. * symmetric and asymmetric Rx PAUSE. Later, we will
  1498. * disable the adapter's ability to send PAUSE frames.
  1499. */
  1500. reg |= (IXGBE_PCS1GANA_SYM_PAUSE | IXGBE_PCS1GANA_ASM_PAUSE);
  1501. break;
  1502. case ixgbe_fc_tx_pause:
  1503. /*
  1504. * Tx Flow control is enabled, and Rx Flow control is
  1505. * disabled by software override.
  1506. */
  1507. reg |= (IXGBE_PCS1GANA_ASM_PAUSE);
  1508. reg &= ~(IXGBE_PCS1GANA_SYM_PAUSE);
  1509. break;
  1510. case ixgbe_fc_full:
  1511. /* Flow control (both Rx and Tx) is enabled by SW override. */
  1512. reg |= (IXGBE_PCS1GANA_SYM_PAUSE | IXGBE_PCS1GANA_ASM_PAUSE);
  1513. break;
  1514. #ifdef CONFIG_DCB
  1515. case ixgbe_fc_pfc:
  1516. goto out;
  1517. break;
  1518. #endif
  1519. default:
  1520. hw_dbg(hw, "Flow control param set incorrectly\n");
  1521. ret_val = -IXGBE_ERR_CONFIG;
  1522. goto out;
  1523. break;
  1524. }
  1525. IXGBE_WRITE_REG(hw, IXGBE_PCS1GANA, reg);
  1526. reg = IXGBE_READ_REG(hw, IXGBE_PCS1GLCTL);
  1527. /* Set PCS register for autoneg */
  1528. /* Enable and restart autoneg */
  1529. reg |= IXGBE_PCS1GLCTL_AN_ENABLE | IXGBE_PCS1GLCTL_AN_RESTART;
  1530. /* Disable AN timeout */
  1531. if (hw->fc.strict_ieee)
  1532. reg &= ~IXGBE_PCS1GLCTL_AN_1G_TIMEOUT_EN;
  1533. hw_dbg(hw, "Configuring Autoneg; PCS_LCTL = 0x%08X\n", reg);
  1534. IXGBE_WRITE_REG(hw, IXGBE_PCS1GLCTL, reg);
  1535. /* See if autonegotiation has succeeded */
  1536. hw->mac.autoneg_succeeded = 0;
  1537. for (i = 0; i < FIBER_LINK_UP_LIMIT; i++) {
  1538. msleep(10);
  1539. reg = IXGBE_READ_REG(hw, IXGBE_PCS1GLSTA);
  1540. if ((reg & (IXGBE_PCS1GLSTA_LINK_OK |
  1541. IXGBE_PCS1GLSTA_AN_COMPLETE)) ==
  1542. (IXGBE_PCS1GLSTA_LINK_OK |
  1543. IXGBE_PCS1GLSTA_AN_COMPLETE)) {
  1544. if (!(reg & IXGBE_PCS1GLSTA_AN_TIMED_OUT))
  1545. hw->mac.autoneg_succeeded = 1;
  1546. break;
  1547. }
  1548. }
  1549. if (!hw->mac.autoneg_succeeded) {
  1550. /* Autoneg failed to achieve a link, so we turn fc off */
  1551. hw->fc.current_mode = ixgbe_fc_none;
  1552. hw_dbg(hw, "Flow Control = NONE.\n");
  1553. goto out;
  1554. }
  1555. /*
  1556. * Read the AN advertisement and LP ability registers and resolve
  1557. * local flow control settings accordingly
  1558. */
  1559. pcs_anadv_reg = IXGBE_READ_REG(hw, IXGBE_PCS1GANA);
  1560. pcs_lpab_reg = IXGBE_READ_REG(hw, IXGBE_PCS1GANLP);
  1561. if ((pcs_anadv_reg & IXGBE_PCS1GANA_SYM_PAUSE) &&
  1562. (pcs_lpab_reg & IXGBE_PCS1GANA_SYM_PAUSE)) {
  1563. /*
  1564. * Now we need to check if the user selected Rx ONLY
  1565. * of pause frames. In this case, we had to advertise
  1566. * FULL flow control because we could not advertise RX
  1567. * ONLY. Hence, we must now check to see if we need to
  1568. * turn OFF the TRANSMISSION of PAUSE frames.
  1569. */
  1570. if (hw->fc.requested_mode == ixgbe_fc_full) {
  1571. hw->fc.current_mode = ixgbe_fc_full;
  1572. hw_dbg(hw, "Flow Control = FULL.\n");
  1573. } else {
  1574. hw->fc.current_mode = ixgbe_fc_rx_pause;
  1575. hw_dbg(hw, "Flow Control = RX PAUSE frames only.\n");
  1576. }
  1577. } else if (!(pcs_anadv_reg & IXGBE_PCS1GANA_SYM_PAUSE) &&
  1578. (pcs_anadv_reg & IXGBE_PCS1GANA_ASM_PAUSE) &&
  1579. (pcs_lpab_reg & IXGBE_PCS1GANA_SYM_PAUSE) &&
  1580. (pcs_lpab_reg & IXGBE_PCS1GANA_ASM_PAUSE)) {
  1581. hw->fc.current_mode = ixgbe_fc_tx_pause;
  1582. hw_dbg(hw, "Flow Control = TX PAUSE frames only.\n");
  1583. } else if ((pcs_anadv_reg & IXGBE_PCS1GANA_SYM_PAUSE) &&
  1584. (pcs_anadv_reg & IXGBE_PCS1GANA_ASM_PAUSE) &&
  1585. !(pcs_lpab_reg & IXGBE_PCS1GANA_SYM_PAUSE) &&
  1586. (pcs_lpab_reg & IXGBE_PCS1GANA_ASM_PAUSE)) {
  1587. hw->fc.current_mode = ixgbe_fc_rx_pause;
  1588. hw_dbg(hw, "Flow Control = RX PAUSE frames only.\n");
  1589. } else {
  1590. hw->fc.current_mode = ixgbe_fc_none;
  1591. hw_dbg(hw, "Flow Control = NONE.\n");
  1592. }
  1593. out:
  1594. return ret_val;
  1595. }
  1596. /**
  1597. * ixgbe_setup_fc_generic - Set up flow control
  1598. * @hw: pointer to hardware structure
  1599. *
  1600. * Sets up flow control.
  1601. **/
  1602. s32 ixgbe_setup_fc_generic(struct ixgbe_hw *hw, s32 packetbuf_num)
  1603. {
  1604. s32 ret_val = 0;
  1605. ixgbe_link_speed speed;
  1606. bool link_up;
  1607. #ifdef CONFIG_DCB
  1608. if (hw->fc.requested_mode == ixgbe_fc_pfc) {
  1609. hw->fc.current_mode = hw->fc.requested_mode;
  1610. goto out;
  1611. }
  1612. #endif
  1613. /* Validate the packetbuf configuration */
  1614. if (packetbuf_num < 0 || packetbuf_num > 7) {
  1615. hw_dbg(hw, "Invalid packet buffer number [%d], expected range "
  1616. "is 0-7\n", packetbuf_num);
  1617. ret_val = IXGBE_ERR_INVALID_LINK_SETTINGS;
  1618. goto out;
  1619. }
  1620. /*
  1621. * Validate the water mark configuration. Zero water marks are invalid
  1622. * because it causes the controller to just blast out fc packets.
  1623. */
  1624. if (!hw->fc.low_water || !hw->fc.high_water || !hw->fc.pause_time) {
  1625. if (hw->fc.requested_mode != ixgbe_fc_none) {
  1626. hw_dbg(hw, "Invalid water mark configuration\n");
  1627. ret_val = IXGBE_ERR_INVALID_LINK_SETTINGS;
  1628. goto out;
  1629. }
  1630. }
  1631. /*
  1632. * Validate the requested mode. Strict IEEE mode does not allow
  1633. * ixgbe_fc_rx_pause because it will cause testing anomalies.
  1634. */
  1635. if (hw->fc.strict_ieee && hw->fc.requested_mode == ixgbe_fc_rx_pause) {
  1636. hw_dbg(hw, "ixgbe_fc_rx_pause not valid in strict "
  1637. "IEEE mode\n");
  1638. ret_val = IXGBE_ERR_INVALID_LINK_SETTINGS;
  1639. goto out;
  1640. }
  1641. /*
  1642. * 10gig parts do not have a word in the EEPROM to determine the
  1643. * default flow control setting, so we explicitly set it to full.
  1644. */
  1645. if (hw->fc.requested_mode == ixgbe_fc_default)
  1646. hw->fc.requested_mode = ixgbe_fc_full;
  1647. /*
  1648. * Save off the requested flow control mode for use later. Depending
  1649. * on the link partner's capabilities, we may or may not use this mode.
  1650. */
  1651. hw->fc.current_mode = hw->fc.requested_mode;
  1652. /* Decide whether to use autoneg or not. */
  1653. hw->mac.ops.check_link(hw, &speed, &link_up, false);
  1654. if (!hw->fc.disable_fc_autoneg && hw->phy.multispeed_fiber &&
  1655. (speed == IXGBE_LINK_SPEED_1GB_FULL))
  1656. ret_val = ixgbe_fc_autoneg(hw);
  1657. if (ret_val)
  1658. goto out;
  1659. ret_val = ixgbe_fc_enable(hw, packetbuf_num);
  1660. out:
  1661. return ret_val;
  1662. }
  1663. /**
  1664. * ixgbe_disable_pcie_master - Disable PCI-express master access
  1665. * @hw: pointer to hardware structure
  1666. *
  1667. * Disables PCI-Express master access and verifies there are no pending
  1668. * requests. IXGBE_ERR_MASTER_REQUESTS_PENDING is returned if master disable
  1669. * bit hasn't caused the master requests to be disabled, else 0
  1670. * is returned signifying master requests disabled.
  1671. **/
  1672. s32 ixgbe_disable_pcie_master(struct ixgbe_hw *hw)
  1673. {
  1674. u32 i;
  1675. u32 reg_val;
  1676. u32 number_of_queues;
  1677. s32 status = IXGBE_ERR_MASTER_REQUESTS_PENDING;
  1678. /* Disable the receive unit by stopping each queue */
  1679. number_of_queues = hw->mac.max_rx_queues;
  1680. for (i = 0; i < number_of_queues; i++) {
  1681. reg_val = IXGBE_READ_REG(hw, IXGBE_RXDCTL(i));
  1682. if (reg_val & IXGBE_RXDCTL_ENABLE) {
  1683. reg_val &= ~IXGBE_RXDCTL_ENABLE;
  1684. IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(i), reg_val);
  1685. }
  1686. }
  1687. reg_val = IXGBE_READ_REG(hw, IXGBE_CTRL);
  1688. reg_val |= IXGBE_CTRL_GIO_DIS;
  1689. IXGBE_WRITE_REG(hw, IXGBE_CTRL, reg_val);
  1690. for (i = 0; i < IXGBE_PCI_MASTER_DISABLE_TIMEOUT; i++) {
  1691. if (!(IXGBE_READ_REG(hw, IXGBE_STATUS) & IXGBE_STATUS_GIO)) {
  1692. status = 0;
  1693. break;
  1694. }
  1695. udelay(100);
  1696. }
  1697. return status;
  1698. }
  1699. /**
  1700. * ixgbe_acquire_swfw_sync - Acquire SWFW semaphore
  1701. * @hw: pointer to hardware structure
  1702. * @mask: Mask to specify which semaphore to acquire
  1703. *
  1704. * Acquires the SWFW semaphore thought the GSSR register for the specified
  1705. * function (CSR, PHY0, PHY1, EEPROM, Flash)
  1706. **/
  1707. s32 ixgbe_acquire_swfw_sync(struct ixgbe_hw *hw, u16 mask)
  1708. {
  1709. u32 gssr;
  1710. u32 swmask = mask;
  1711. u32 fwmask = mask << 5;
  1712. s32 timeout = 200;
  1713. while (timeout) {
  1714. if (ixgbe_get_eeprom_semaphore(hw))
  1715. return -IXGBE_ERR_SWFW_SYNC;
  1716. gssr = IXGBE_READ_REG(hw, IXGBE_GSSR);
  1717. if (!(gssr & (fwmask | swmask)))
  1718. break;
  1719. /*
  1720. * Firmware currently using resource (fwmask) or other software
  1721. * thread currently using resource (swmask)
  1722. */
  1723. ixgbe_release_eeprom_semaphore(hw);
  1724. msleep(5);
  1725. timeout--;
  1726. }
  1727. if (!timeout) {
  1728. hw_dbg(hw, "Driver can't access resource, GSSR timeout.\n");
  1729. return -IXGBE_ERR_SWFW_SYNC;
  1730. }
  1731. gssr |= swmask;
  1732. IXGBE_WRITE_REG(hw, IXGBE_GSSR, gssr);
  1733. ixgbe_release_eeprom_semaphore(hw);
  1734. return 0;
  1735. }
  1736. /**
  1737. * ixgbe_release_swfw_sync - Release SWFW semaphore
  1738. * @hw: pointer to hardware structure
  1739. * @mask: Mask to specify which semaphore to release
  1740. *
  1741. * Releases the SWFW semaphore thought the GSSR register for the specified
  1742. * function (CSR, PHY0, PHY1, EEPROM, Flash)
  1743. **/
  1744. void ixgbe_release_swfw_sync(struct ixgbe_hw *hw, u16 mask)
  1745. {
  1746. u32 gssr;
  1747. u32 swmask = mask;
  1748. ixgbe_get_eeprom_semaphore(hw);
  1749. gssr = IXGBE_READ_REG(hw, IXGBE_GSSR);
  1750. gssr &= ~swmask;
  1751. IXGBE_WRITE_REG(hw, IXGBE_GSSR, gssr);
  1752. ixgbe_release_eeprom_semaphore(hw);
  1753. }
  1754. /**
  1755. * ixgbe_enable_rx_dma_generic - Enable the Rx DMA unit
  1756. * @hw: pointer to hardware structure
  1757. * @regval: register value to write to RXCTRL
  1758. *
  1759. * Enables the Rx DMA unit
  1760. **/
  1761. s32 ixgbe_enable_rx_dma_generic(struct ixgbe_hw *hw, u32 regval)
  1762. {
  1763. IXGBE_WRITE_REG(hw, IXGBE_RXCTRL, regval);
  1764. return 0;
  1765. }
  1766. /**
  1767. * ixgbe_blink_led_start_generic - Blink LED based on index.
  1768. * @hw: pointer to hardware structure
  1769. * @index: led number to blink
  1770. **/
  1771. s32 ixgbe_blink_led_start_generic(struct ixgbe_hw *hw, u32 index)
  1772. {
  1773. ixgbe_link_speed speed = 0;
  1774. bool link_up = 0;
  1775. u32 autoc_reg = IXGBE_READ_REG(hw, IXGBE_AUTOC);
  1776. u32 led_reg = IXGBE_READ_REG(hw, IXGBE_LEDCTL);
  1777. /*
  1778. * Link must be up to auto-blink the LEDs;
  1779. * Force it if link is down.
  1780. */
  1781. hw->mac.ops.check_link(hw, &speed, &link_up, false);
  1782. if (!link_up) {
  1783. autoc_reg |= IXGBE_AUTOC_AN_RESTART;
  1784. autoc_reg |= IXGBE_AUTOC_FLU;
  1785. IXGBE_WRITE_REG(hw, IXGBE_AUTOC, autoc_reg);
  1786. msleep(10);
  1787. }
  1788. led_reg &= ~IXGBE_LED_MODE_MASK(index);
  1789. led_reg |= IXGBE_LED_BLINK(index);
  1790. IXGBE_WRITE_REG(hw, IXGBE_LEDCTL, led_reg);
  1791. IXGBE_WRITE_FLUSH(hw);
  1792. return 0;
  1793. }
  1794. /**
  1795. * ixgbe_blink_led_stop_generic - Stop blinking LED based on index.
  1796. * @hw: pointer to hardware structure
  1797. * @index: led number to stop blinking
  1798. **/
  1799. s32 ixgbe_blink_led_stop_generic(struct ixgbe_hw *hw, u32 index)
  1800. {
  1801. u32 autoc_reg = IXGBE_READ_REG(hw, IXGBE_AUTOC);
  1802. u32 led_reg = IXGBE_READ_REG(hw, IXGBE_LEDCTL);
  1803. autoc_reg &= ~IXGBE_AUTOC_FLU;
  1804. autoc_reg |= IXGBE_AUTOC_AN_RESTART;
  1805. IXGBE_WRITE_REG(hw, IXGBE_AUTOC, autoc_reg);
  1806. led_reg &= ~IXGBE_LED_MODE_MASK(index);
  1807. led_reg &= ~IXGBE_LED_BLINK(index);
  1808. led_reg |= IXGBE_LED_LINK_ACTIVE << IXGBE_LED_MODE_SHIFT(index);
  1809. IXGBE_WRITE_REG(hw, IXGBE_LEDCTL, led_reg);
  1810. IXGBE_WRITE_FLUSH(hw);
  1811. return 0;
  1812. }