ixgbe_common.c 58 KB

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