ixgbevf_main.c 90 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410
  1. /*******************************************************************************
  2. Intel 82599 Virtual Function driver
  3. Copyright(c) 1999 - 2012 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. /******************************************************************************
  21. Copyright (c)2006 - 2007 Myricom, Inc. for some LRO specific code
  22. ******************************************************************************/
  23. #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  24. #include <linux/types.h>
  25. #include <linux/bitops.h>
  26. #include <linux/module.h>
  27. #include <linux/pci.h>
  28. #include <linux/netdevice.h>
  29. #include <linux/vmalloc.h>
  30. #include <linux/string.h>
  31. #include <linux/in.h>
  32. #include <linux/ip.h>
  33. #include <linux/tcp.h>
  34. #include <linux/sctp.h>
  35. #include <linux/ipv6.h>
  36. #include <linux/slab.h>
  37. #include <net/checksum.h>
  38. #include <net/ip6_checksum.h>
  39. #include <linux/ethtool.h>
  40. #include <linux/if.h>
  41. #include <linux/if_vlan.h>
  42. #include <linux/prefetch.h>
  43. #include "ixgbevf.h"
  44. const char ixgbevf_driver_name[] = "ixgbevf";
  45. static const char ixgbevf_driver_string[] =
  46. "Intel(R) 10 Gigabit PCI Express Virtual Function Network Driver";
  47. #define DRV_VERSION "2.6.0-k"
  48. const char ixgbevf_driver_version[] = DRV_VERSION;
  49. static char ixgbevf_copyright[] =
  50. "Copyright (c) 2009 - 2012 Intel Corporation.";
  51. static const struct ixgbevf_info *ixgbevf_info_tbl[] = {
  52. [board_82599_vf] = &ixgbevf_82599_vf_info,
  53. [board_X540_vf] = &ixgbevf_X540_vf_info,
  54. };
  55. /* ixgbevf_pci_tbl - PCI Device ID Table
  56. *
  57. * Wildcard entries (PCI_ANY_ID) should come last
  58. * Last entry must be all 0s
  59. *
  60. * { Vendor ID, Device ID, SubVendor ID, SubDevice ID,
  61. * Class, Class Mask, private data (not used) }
  62. */
  63. static struct pci_device_id ixgbevf_pci_tbl[] = {
  64. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_VF),
  65. board_82599_vf},
  66. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X540_VF),
  67. board_X540_vf},
  68. /* required last entry */
  69. {0, }
  70. };
  71. MODULE_DEVICE_TABLE(pci, ixgbevf_pci_tbl);
  72. MODULE_AUTHOR("Intel Corporation, <linux.nics@intel.com>");
  73. MODULE_DESCRIPTION("Intel(R) 82599 Virtual Function Driver");
  74. MODULE_LICENSE("GPL");
  75. MODULE_VERSION(DRV_VERSION);
  76. #define DEFAULT_MSG_ENABLE (NETIF_MSG_DRV|NETIF_MSG_PROBE|NETIF_MSG_LINK)
  77. static int debug = -1;
  78. module_param(debug, int, 0);
  79. MODULE_PARM_DESC(debug, "Debug level (0=none,...,16=all)");
  80. /* forward decls */
  81. static void ixgbevf_set_itr(struct ixgbevf_q_vector *q_vector);
  82. static inline void ixgbevf_release_rx_desc(struct ixgbe_hw *hw,
  83. struct ixgbevf_ring *rx_ring,
  84. u32 val)
  85. {
  86. /*
  87. * Force memory writes to complete before letting h/w
  88. * know there are new descriptors to fetch. (Only
  89. * applicable for weak-ordered memory model archs,
  90. * such as IA-64).
  91. */
  92. wmb();
  93. IXGBE_WRITE_REG(hw, IXGBE_VFRDT(rx_ring->reg_idx), val);
  94. }
  95. /**
  96. * ixgbevf_set_ivar - set IVAR registers - maps interrupt causes to vectors
  97. * @adapter: pointer to adapter struct
  98. * @direction: 0 for Rx, 1 for Tx, -1 for other causes
  99. * @queue: queue to map the corresponding interrupt to
  100. * @msix_vector: the vector to map to the corresponding queue
  101. *
  102. */
  103. static void ixgbevf_set_ivar(struct ixgbevf_adapter *adapter, s8 direction,
  104. u8 queue, u8 msix_vector)
  105. {
  106. u32 ivar, index;
  107. struct ixgbe_hw *hw = &adapter->hw;
  108. if (direction == -1) {
  109. /* other causes */
  110. msix_vector |= IXGBE_IVAR_ALLOC_VAL;
  111. ivar = IXGBE_READ_REG(hw, IXGBE_VTIVAR_MISC);
  112. ivar &= ~0xFF;
  113. ivar |= msix_vector;
  114. IXGBE_WRITE_REG(hw, IXGBE_VTIVAR_MISC, ivar);
  115. } else {
  116. /* tx or rx causes */
  117. msix_vector |= IXGBE_IVAR_ALLOC_VAL;
  118. index = ((16 * (queue & 1)) + (8 * direction));
  119. ivar = IXGBE_READ_REG(hw, IXGBE_VTIVAR(queue >> 1));
  120. ivar &= ~(0xFF << index);
  121. ivar |= (msix_vector << index);
  122. IXGBE_WRITE_REG(hw, IXGBE_VTIVAR(queue >> 1), ivar);
  123. }
  124. }
  125. static void ixgbevf_unmap_and_free_tx_resource(struct ixgbevf_ring *tx_ring,
  126. struct ixgbevf_tx_buffer
  127. *tx_buffer_info)
  128. {
  129. if (tx_buffer_info->dma) {
  130. if (tx_buffer_info->mapped_as_page)
  131. dma_unmap_page(tx_ring->dev,
  132. tx_buffer_info->dma,
  133. tx_buffer_info->length,
  134. DMA_TO_DEVICE);
  135. else
  136. dma_unmap_single(tx_ring->dev,
  137. tx_buffer_info->dma,
  138. tx_buffer_info->length,
  139. DMA_TO_DEVICE);
  140. tx_buffer_info->dma = 0;
  141. }
  142. if (tx_buffer_info->skb) {
  143. dev_kfree_skb_any(tx_buffer_info->skb);
  144. tx_buffer_info->skb = NULL;
  145. }
  146. tx_buffer_info->time_stamp = 0;
  147. /* tx_buffer_info must be completely set up in the transmit path */
  148. }
  149. #define IXGBE_MAX_TXD_PWR 14
  150. #define IXGBE_MAX_DATA_PER_TXD (1 << IXGBE_MAX_TXD_PWR)
  151. /* Tx Descriptors needed, worst case */
  152. #define TXD_USE_COUNT(S) DIV_ROUND_UP((S), IXGBE_MAX_DATA_PER_TXD)
  153. #define DESC_NEEDED (MAX_SKB_FRAGS + 4)
  154. static void ixgbevf_tx_timeout(struct net_device *netdev);
  155. /**
  156. * ixgbevf_clean_tx_irq - Reclaim resources after transmit completes
  157. * @q_vector: board private structure
  158. * @tx_ring: tx ring to clean
  159. **/
  160. static bool ixgbevf_clean_tx_irq(struct ixgbevf_q_vector *q_vector,
  161. struct ixgbevf_ring *tx_ring)
  162. {
  163. struct ixgbevf_adapter *adapter = q_vector->adapter;
  164. union ixgbe_adv_tx_desc *tx_desc, *eop_desc;
  165. struct ixgbevf_tx_buffer *tx_buffer_info;
  166. unsigned int i, eop, count = 0;
  167. unsigned int total_bytes = 0, total_packets = 0;
  168. if (test_bit(__IXGBEVF_DOWN, &adapter->state))
  169. return true;
  170. i = tx_ring->next_to_clean;
  171. eop = tx_ring->tx_buffer_info[i].next_to_watch;
  172. eop_desc = IXGBEVF_TX_DESC(tx_ring, eop);
  173. while ((eop_desc->wb.status & cpu_to_le32(IXGBE_TXD_STAT_DD)) &&
  174. (count < tx_ring->count)) {
  175. bool cleaned = false;
  176. rmb(); /* read buffer_info after eop_desc */
  177. /* eop could change between read and DD-check */
  178. if (unlikely(eop != tx_ring->tx_buffer_info[i].next_to_watch))
  179. goto cont_loop;
  180. for ( ; !cleaned; count++) {
  181. struct sk_buff *skb;
  182. tx_desc = IXGBEVF_TX_DESC(tx_ring, i);
  183. tx_buffer_info = &tx_ring->tx_buffer_info[i];
  184. cleaned = (i == eop);
  185. skb = tx_buffer_info->skb;
  186. if (cleaned && skb) {
  187. unsigned int segs, bytecount;
  188. /* gso_segs is currently only valid for tcp */
  189. segs = skb_shinfo(skb)->gso_segs ?: 1;
  190. /* multiply data chunks by size of headers */
  191. bytecount = ((segs - 1) * skb_headlen(skb)) +
  192. skb->len;
  193. total_packets += segs;
  194. total_bytes += bytecount;
  195. }
  196. ixgbevf_unmap_and_free_tx_resource(tx_ring,
  197. tx_buffer_info);
  198. tx_desc->wb.status = 0;
  199. i++;
  200. if (i == tx_ring->count)
  201. i = 0;
  202. }
  203. cont_loop:
  204. eop = tx_ring->tx_buffer_info[i].next_to_watch;
  205. eop_desc = IXGBEVF_TX_DESC(tx_ring, eop);
  206. }
  207. tx_ring->next_to_clean = i;
  208. #define TX_WAKE_THRESHOLD (DESC_NEEDED * 2)
  209. if (unlikely(count && netif_carrier_ok(tx_ring->netdev) &&
  210. (IXGBE_DESC_UNUSED(tx_ring) >= TX_WAKE_THRESHOLD))) {
  211. /* Make sure that anybody stopping the queue after this
  212. * sees the new next_to_clean.
  213. */
  214. smp_mb();
  215. if (__netif_subqueue_stopped(tx_ring->netdev,
  216. tx_ring->queue_index) &&
  217. !test_bit(__IXGBEVF_DOWN, &adapter->state)) {
  218. netif_wake_subqueue(tx_ring->netdev,
  219. tx_ring->queue_index);
  220. ++adapter->restart_queue;
  221. }
  222. }
  223. u64_stats_update_begin(&tx_ring->syncp);
  224. tx_ring->total_bytes += total_bytes;
  225. tx_ring->total_packets += total_packets;
  226. u64_stats_update_end(&tx_ring->syncp);
  227. return count < tx_ring->count;
  228. }
  229. /**
  230. * ixgbevf_receive_skb - Send a completed packet up the stack
  231. * @q_vector: structure containing interrupt and ring information
  232. * @skb: packet to send up
  233. * @status: hardware indication of status of receive
  234. * @rx_desc: rx descriptor
  235. **/
  236. static void ixgbevf_receive_skb(struct ixgbevf_q_vector *q_vector,
  237. struct sk_buff *skb, u8 status,
  238. union ixgbe_adv_rx_desc *rx_desc)
  239. {
  240. struct ixgbevf_adapter *adapter = q_vector->adapter;
  241. bool is_vlan = (status & IXGBE_RXD_STAT_VP);
  242. u16 tag = le16_to_cpu(rx_desc->wb.upper.vlan);
  243. if (is_vlan && test_bit(tag & VLAN_VID_MASK, adapter->active_vlans))
  244. __vlan_hwaccel_put_tag(skb, tag);
  245. napi_gro_receive(&q_vector->napi, skb);
  246. }
  247. /**
  248. * ixgbevf_rx_checksum - indicate in skb if hw indicated a good cksum
  249. * @adapter: address of board private structure
  250. * @status_err: hardware indication of status of receive
  251. * @skb: skb currently being received and modified
  252. **/
  253. static inline void ixgbevf_rx_checksum(struct ixgbevf_adapter *adapter,
  254. struct ixgbevf_ring *ring,
  255. u32 status_err, struct sk_buff *skb)
  256. {
  257. skb_checksum_none_assert(skb);
  258. /* Rx csum disabled */
  259. if (!(ring->netdev->features & NETIF_F_RXCSUM))
  260. return;
  261. /* if IP and error */
  262. if ((status_err & IXGBE_RXD_STAT_IPCS) &&
  263. (status_err & IXGBE_RXDADV_ERR_IPE)) {
  264. adapter->hw_csum_rx_error++;
  265. return;
  266. }
  267. if (!(status_err & IXGBE_RXD_STAT_L4CS))
  268. return;
  269. if (status_err & IXGBE_RXDADV_ERR_TCPE) {
  270. adapter->hw_csum_rx_error++;
  271. return;
  272. }
  273. /* It must be a TCP or UDP packet with a valid checksum */
  274. skb->ip_summed = CHECKSUM_UNNECESSARY;
  275. adapter->hw_csum_rx_good++;
  276. }
  277. /**
  278. * ixgbevf_alloc_rx_buffers - Replace used receive buffers; packet split
  279. * @adapter: address of board private structure
  280. **/
  281. static void ixgbevf_alloc_rx_buffers(struct ixgbevf_adapter *adapter,
  282. struct ixgbevf_ring *rx_ring,
  283. int cleaned_count)
  284. {
  285. struct pci_dev *pdev = adapter->pdev;
  286. union ixgbe_adv_rx_desc *rx_desc;
  287. struct ixgbevf_rx_buffer *bi;
  288. struct sk_buff *skb;
  289. unsigned int i = rx_ring->next_to_use;
  290. bi = &rx_ring->rx_buffer_info[i];
  291. while (cleaned_count--) {
  292. rx_desc = IXGBEVF_RX_DESC(rx_ring, i);
  293. skb = bi->skb;
  294. if (!skb) {
  295. skb = netdev_alloc_skb_ip_align(rx_ring->netdev,
  296. rx_ring->rx_buf_len);
  297. if (!skb) {
  298. adapter->alloc_rx_buff_failed++;
  299. goto no_buffers;
  300. }
  301. bi->skb = skb;
  302. }
  303. if (!bi->dma) {
  304. bi->dma = dma_map_single(&pdev->dev, skb->data,
  305. rx_ring->rx_buf_len,
  306. DMA_FROM_DEVICE);
  307. }
  308. rx_desc->read.pkt_addr = cpu_to_le64(bi->dma);
  309. i++;
  310. if (i == rx_ring->count)
  311. i = 0;
  312. bi = &rx_ring->rx_buffer_info[i];
  313. }
  314. no_buffers:
  315. if (rx_ring->next_to_use != i) {
  316. rx_ring->next_to_use = i;
  317. ixgbevf_release_rx_desc(&adapter->hw, rx_ring, i);
  318. }
  319. }
  320. static inline void ixgbevf_irq_enable_queues(struct ixgbevf_adapter *adapter,
  321. u32 qmask)
  322. {
  323. struct ixgbe_hw *hw = &adapter->hw;
  324. IXGBE_WRITE_REG(hw, IXGBE_VTEIMS, qmask);
  325. }
  326. static bool ixgbevf_clean_rx_irq(struct ixgbevf_q_vector *q_vector,
  327. struct ixgbevf_ring *rx_ring,
  328. int budget)
  329. {
  330. struct ixgbevf_adapter *adapter = q_vector->adapter;
  331. struct pci_dev *pdev = adapter->pdev;
  332. union ixgbe_adv_rx_desc *rx_desc, *next_rxd;
  333. struct ixgbevf_rx_buffer *rx_buffer_info, *next_buffer;
  334. struct sk_buff *skb;
  335. unsigned int i;
  336. u32 len, staterr;
  337. int cleaned_count = 0;
  338. unsigned int total_rx_bytes = 0, total_rx_packets = 0;
  339. i = rx_ring->next_to_clean;
  340. rx_desc = IXGBEVF_RX_DESC(rx_ring, i);
  341. staterr = le32_to_cpu(rx_desc->wb.upper.status_error);
  342. rx_buffer_info = &rx_ring->rx_buffer_info[i];
  343. while (staterr & IXGBE_RXD_STAT_DD) {
  344. if (!budget)
  345. break;
  346. budget--;
  347. rmb(); /* read descriptor and rx_buffer_info after status DD */
  348. len = le16_to_cpu(rx_desc->wb.upper.length);
  349. skb = rx_buffer_info->skb;
  350. prefetch(skb->data - NET_IP_ALIGN);
  351. rx_buffer_info->skb = NULL;
  352. if (rx_buffer_info->dma) {
  353. dma_unmap_single(&pdev->dev, rx_buffer_info->dma,
  354. rx_ring->rx_buf_len,
  355. DMA_FROM_DEVICE);
  356. rx_buffer_info->dma = 0;
  357. skb_put(skb, len);
  358. }
  359. i++;
  360. if (i == rx_ring->count)
  361. i = 0;
  362. next_rxd = IXGBEVF_RX_DESC(rx_ring, i);
  363. prefetch(next_rxd);
  364. cleaned_count++;
  365. next_buffer = &rx_ring->rx_buffer_info[i];
  366. if (!(staterr & IXGBE_RXD_STAT_EOP)) {
  367. skb->next = next_buffer->skb;
  368. skb->next->prev = skb;
  369. adapter->non_eop_descs++;
  370. goto next_desc;
  371. }
  372. /* ERR_MASK will only have valid bits if EOP set */
  373. if (unlikely(staterr & IXGBE_RXDADV_ERR_FRAME_ERR_MASK)) {
  374. dev_kfree_skb_irq(skb);
  375. goto next_desc;
  376. }
  377. ixgbevf_rx_checksum(adapter, rx_ring, staterr, skb);
  378. /* probably a little skewed due to removing CRC */
  379. total_rx_bytes += skb->len;
  380. total_rx_packets++;
  381. /*
  382. * Work around issue of some types of VM to VM loop back
  383. * packets not getting split correctly
  384. */
  385. if (staterr & IXGBE_RXD_STAT_LB) {
  386. u32 header_fixup_len = skb_headlen(skb);
  387. if (header_fixup_len < 14)
  388. skb_push(skb, header_fixup_len);
  389. }
  390. skb->protocol = eth_type_trans(skb, rx_ring->netdev);
  391. ixgbevf_receive_skb(q_vector, skb, staterr, rx_desc);
  392. next_desc:
  393. rx_desc->wb.upper.status_error = 0;
  394. /* return some buffers to hardware, one at a time is too slow */
  395. if (cleaned_count >= IXGBEVF_RX_BUFFER_WRITE) {
  396. ixgbevf_alloc_rx_buffers(adapter, rx_ring,
  397. cleaned_count);
  398. cleaned_count = 0;
  399. }
  400. /* use prefetched values */
  401. rx_desc = next_rxd;
  402. rx_buffer_info = &rx_ring->rx_buffer_info[i];
  403. staterr = le32_to_cpu(rx_desc->wb.upper.status_error);
  404. }
  405. rx_ring->next_to_clean = i;
  406. cleaned_count = IXGBE_DESC_UNUSED(rx_ring);
  407. if (cleaned_count)
  408. ixgbevf_alloc_rx_buffers(adapter, rx_ring, cleaned_count);
  409. u64_stats_update_begin(&rx_ring->syncp);
  410. rx_ring->total_packets += total_rx_packets;
  411. rx_ring->total_bytes += total_rx_bytes;
  412. u64_stats_update_end(&rx_ring->syncp);
  413. return !!budget;
  414. }
  415. /**
  416. * ixgbevf_poll - NAPI polling calback
  417. * @napi: napi struct with our devices info in it
  418. * @budget: amount of work driver is allowed to do this pass, in packets
  419. *
  420. * This function will clean more than one or more rings associated with a
  421. * q_vector.
  422. **/
  423. static int ixgbevf_poll(struct napi_struct *napi, int budget)
  424. {
  425. struct ixgbevf_q_vector *q_vector =
  426. container_of(napi, struct ixgbevf_q_vector, napi);
  427. struct ixgbevf_adapter *adapter = q_vector->adapter;
  428. struct ixgbevf_ring *ring;
  429. int per_ring_budget;
  430. bool clean_complete = true;
  431. ixgbevf_for_each_ring(ring, q_vector->tx)
  432. clean_complete &= ixgbevf_clean_tx_irq(q_vector, ring);
  433. /* attempt to distribute budget to each queue fairly, but don't allow
  434. * the budget to go below 1 because we'll exit polling */
  435. if (q_vector->rx.count > 1)
  436. per_ring_budget = max(budget/q_vector->rx.count, 1);
  437. else
  438. per_ring_budget = budget;
  439. ixgbevf_for_each_ring(ring, q_vector->rx)
  440. clean_complete &= ixgbevf_clean_rx_irq(q_vector, ring,
  441. per_ring_budget);
  442. /* If all work not completed, return budget and keep polling */
  443. if (!clean_complete)
  444. return budget;
  445. /* all work done, exit the polling mode */
  446. napi_complete(napi);
  447. if (adapter->rx_itr_setting & 1)
  448. ixgbevf_set_itr(q_vector);
  449. if (!test_bit(__IXGBEVF_DOWN, &adapter->state))
  450. ixgbevf_irq_enable_queues(adapter,
  451. 1 << q_vector->v_idx);
  452. return 0;
  453. }
  454. /**
  455. * ixgbevf_write_eitr - write VTEITR register in hardware specific way
  456. * @q_vector: structure containing interrupt and ring information
  457. */
  458. static void ixgbevf_write_eitr(struct ixgbevf_q_vector *q_vector)
  459. {
  460. struct ixgbevf_adapter *adapter = q_vector->adapter;
  461. struct ixgbe_hw *hw = &adapter->hw;
  462. int v_idx = q_vector->v_idx;
  463. u32 itr_reg = q_vector->itr & IXGBE_MAX_EITR;
  464. /*
  465. * set the WDIS bit to not clear the timer bits and cause an
  466. * immediate assertion of the interrupt
  467. */
  468. itr_reg |= IXGBE_EITR_CNT_WDIS;
  469. IXGBE_WRITE_REG(hw, IXGBE_VTEITR(v_idx), itr_reg);
  470. }
  471. /**
  472. * ixgbevf_configure_msix - Configure MSI-X hardware
  473. * @adapter: board private structure
  474. *
  475. * ixgbevf_configure_msix sets up the hardware to properly generate MSI-X
  476. * interrupts.
  477. **/
  478. static void ixgbevf_configure_msix(struct ixgbevf_adapter *adapter)
  479. {
  480. struct ixgbevf_q_vector *q_vector;
  481. int q_vectors, v_idx;
  482. q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
  483. adapter->eims_enable_mask = 0;
  484. /*
  485. * Populate the IVAR table and set the ITR values to the
  486. * corresponding register.
  487. */
  488. for (v_idx = 0; v_idx < q_vectors; v_idx++) {
  489. struct ixgbevf_ring *ring;
  490. q_vector = adapter->q_vector[v_idx];
  491. ixgbevf_for_each_ring(ring, q_vector->rx)
  492. ixgbevf_set_ivar(adapter, 0, ring->reg_idx, v_idx);
  493. ixgbevf_for_each_ring(ring, q_vector->tx)
  494. ixgbevf_set_ivar(adapter, 1, ring->reg_idx, v_idx);
  495. if (q_vector->tx.ring && !q_vector->rx.ring) {
  496. /* tx only vector */
  497. if (adapter->tx_itr_setting == 1)
  498. q_vector->itr = IXGBE_10K_ITR;
  499. else
  500. q_vector->itr = adapter->tx_itr_setting;
  501. } else {
  502. /* rx or rx/tx vector */
  503. if (adapter->rx_itr_setting == 1)
  504. q_vector->itr = IXGBE_20K_ITR;
  505. else
  506. q_vector->itr = adapter->rx_itr_setting;
  507. }
  508. /* add q_vector eims value to global eims_enable_mask */
  509. adapter->eims_enable_mask |= 1 << v_idx;
  510. ixgbevf_write_eitr(q_vector);
  511. }
  512. ixgbevf_set_ivar(adapter, -1, 1, v_idx);
  513. /* setup eims_other and add value to global eims_enable_mask */
  514. adapter->eims_other = 1 << v_idx;
  515. adapter->eims_enable_mask |= adapter->eims_other;
  516. }
  517. enum latency_range {
  518. lowest_latency = 0,
  519. low_latency = 1,
  520. bulk_latency = 2,
  521. latency_invalid = 255
  522. };
  523. /**
  524. * ixgbevf_update_itr - update the dynamic ITR value based on statistics
  525. * @q_vector: structure containing interrupt and ring information
  526. * @ring_container: structure containing ring performance data
  527. *
  528. * Stores a new ITR value based on packets and byte
  529. * counts during the last interrupt. The advantage of per interrupt
  530. * computation is faster updates and more accurate ITR for the current
  531. * traffic pattern. Constants in this function were computed
  532. * based on theoretical maximum wire speed and thresholds were set based
  533. * on testing data as well as attempting to minimize response time
  534. * while increasing bulk throughput.
  535. **/
  536. static void ixgbevf_update_itr(struct ixgbevf_q_vector *q_vector,
  537. struct ixgbevf_ring_container *ring_container)
  538. {
  539. int bytes = ring_container->total_bytes;
  540. int packets = ring_container->total_packets;
  541. u32 timepassed_us;
  542. u64 bytes_perint;
  543. u8 itr_setting = ring_container->itr;
  544. if (packets == 0)
  545. return;
  546. /* simple throttlerate management
  547. * 0-20MB/s lowest (100000 ints/s)
  548. * 20-100MB/s low (20000 ints/s)
  549. * 100-1249MB/s bulk (8000 ints/s)
  550. */
  551. /* what was last interrupt timeslice? */
  552. timepassed_us = q_vector->itr >> 2;
  553. bytes_perint = bytes / timepassed_us; /* bytes/usec */
  554. switch (itr_setting) {
  555. case lowest_latency:
  556. if (bytes_perint > 10)
  557. itr_setting = low_latency;
  558. break;
  559. case low_latency:
  560. if (bytes_perint > 20)
  561. itr_setting = bulk_latency;
  562. else if (bytes_perint <= 10)
  563. itr_setting = lowest_latency;
  564. break;
  565. case bulk_latency:
  566. if (bytes_perint <= 20)
  567. itr_setting = low_latency;
  568. break;
  569. }
  570. /* clear work counters since we have the values we need */
  571. ring_container->total_bytes = 0;
  572. ring_container->total_packets = 0;
  573. /* write updated itr to ring container */
  574. ring_container->itr = itr_setting;
  575. }
  576. static void ixgbevf_set_itr(struct ixgbevf_q_vector *q_vector)
  577. {
  578. u32 new_itr = q_vector->itr;
  579. u8 current_itr;
  580. ixgbevf_update_itr(q_vector, &q_vector->tx);
  581. ixgbevf_update_itr(q_vector, &q_vector->rx);
  582. current_itr = max(q_vector->rx.itr, q_vector->tx.itr);
  583. switch (current_itr) {
  584. /* counts and packets in update_itr are dependent on these numbers */
  585. case lowest_latency:
  586. new_itr = IXGBE_100K_ITR;
  587. break;
  588. case low_latency:
  589. new_itr = IXGBE_20K_ITR;
  590. break;
  591. case bulk_latency:
  592. default:
  593. new_itr = IXGBE_8K_ITR;
  594. break;
  595. }
  596. if (new_itr != q_vector->itr) {
  597. /* do an exponential smoothing */
  598. new_itr = (10 * new_itr * q_vector->itr) /
  599. ((9 * new_itr) + q_vector->itr);
  600. /* save the algorithm value here */
  601. q_vector->itr = new_itr;
  602. ixgbevf_write_eitr(q_vector);
  603. }
  604. }
  605. static irqreturn_t ixgbevf_msix_other(int irq, void *data)
  606. {
  607. struct ixgbevf_adapter *adapter = data;
  608. struct ixgbe_hw *hw = &adapter->hw;
  609. hw->mac.get_link_status = 1;
  610. if (!test_bit(__IXGBEVF_DOWN, &adapter->state))
  611. mod_timer(&adapter->watchdog_timer, jiffies);
  612. IXGBE_WRITE_REG(hw, IXGBE_VTEIMS, adapter->eims_other);
  613. return IRQ_HANDLED;
  614. }
  615. /**
  616. * ixgbevf_msix_clean_rings - single unshared vector rx clean (all queues)
  617. * @irq: unused
  618. * @data: pointer to our q_vector struct for this interrupt vector
  619. **/
  620. static irqreturn_t ixgbevf_msix_clean_rings(int irq, void *data)
  621. {
  622. struct ixgbevf_q_vector *q_vector = data;
  623. /* EIAM disabled interrupts (on this vector) for us */
  624. if (q_vector->rx.ring || q_vector->tx.ring)
  625. napi_schedule(&q_vector->napi);
  626. return IRQ_HANDLED;
  627. }
  628. static inline void map_vector_to_rxq(struct ixgbevf_adapter *a, int v_idx,
  629. int r_idx)
  630. {
  631. struct ixgbevf_q_vector *q_vector = a->q_vector[v_idx];
  632. a->rx_ring[r_idx].next = q_vector->rx.ring;
  633. q_vector->rx.ring = &a->rx_ring[r_idx];
  634. q_vector->rx.count++;
  635. }
  636. static inline void map_vector_to_txq(struct ixgbevf_adapter *a, int v_idx,
  637. int t_idx)
  638. {
  639. struct ixgbevf_q_vector *q_vector = a->q_vector[v_idx];
  640. a->tx_ring[t_idx].next = q_vector->tx.ring;
  641. q_vector->tx.ring = &a->tx_ring[t_idx];
  642. q_vector->tx.count++;
  643. }
  644. /**
  645. * ixgbevf_map_rings_to_vectors - Maps descriptor rings to vectors
  646. * @adapter: board private structure to initialize
  647. *
  648. * This function maps descriptor rings to the queue-specific vectors
  649. * we were allotted through the MSI-X enabling code. Ideally, we'd have
  650. * one vector per ring/queue, but on a constrained vector budget, we
  651. * group the rings as "efficiently" as possible. You would add new
  652. * mapping configurations in here.
  653. **/
  654. static int ixgbevf_map_rings_to_vectors(struct ixgbevf_adapter *adapter)
  655. {
  656. int q_vectors;
  657. int v_start = 0;
  658. int rxr_idx = 0, txr_idx = 0;
  659. int rxr_remaining = adapter->num_rx_queues;
  660. int txr_remaining = adapter->num_tx_queues;
  661. int i, j;
  662. int rqpv, tqpv;
  663. int err = 0;
  664. q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
  665. /*
  666. * The ideal configuration...
  667. * We have enough vectors to map one per queue.
  668. */
  669. if (q_vectors == adapter->num_rx_queues + adapter->num_tx_queues) {
  670. for (; rxr_idx < rxr_remaining; v_start++, rxr_idx++)
  671. map_vector_to_rxq(adapter, v_start, rxr_idx);
  672. for (; txr_idx < txr_remaining; v_start++, txr_idx++)
  673. map_vector_to_txq(adapter, v_start, txr_idx);
  674. goto out;
  675. }
  676. /*
  677. * If we don't have enough vectors for a 1-to-1
  678. * mapping, we'll have to group them so there are
  679. * multiple queues per vector.
  680. */
  681. /* Re-adjusting *qpv takes care of the remainder. */
  682. for (i = v_start; i < q_vectors; i++) {
  683. rqpv = DIV_ROUND_UP(rxr_remaining, q_vectors - i);
  684. for (j = 0; j < rqpv; j++) {
  685. map_vector_to_rxq(adapter, i, rxr_idx);
  686. rxr_idx++;
  687. rxr_remaining--;
  688. }
  689. }
  690. for (i = v_start; i < q_vectors; i++) {
  691. tqpv = DIV_ROUND_UP(txr_remaining, q_vectors - i);
  692. for (j = 0; j < tqpv; j++) {
  693. map_vector_to_txq(adapter, i, txr_idx);
  694. txr_idx++;
  695. txr_remaining--;
  696. }
  697. }
  698. out:
  699. return err;
  700. }
  701. /**
  702. * ixgbevf_request_msix_irqs - Initialize MSI-X interrupts
  703. * @adapter: board private structure
  704. *
  705. * ixgbevf_request_msix_irqs allocates MSI-X vectors and requests
  706. * interrupts from the kernel.
  707. **/
  708. static int ixgbevf_request_msix_irqs(struct ixgbevf_adapter *adapter)
  709. {
  710. struct net_device *netdev = adapter->netdev;
  711. int q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
  712. int vector, err;
  713. int ri = 0, ti = 0;
  714. for (vector = 0; vector < q_vectors; vector++) {
  715. struct ixgbevf_q_vector *q_vector = adapter->q_vector[vector];
  716. struct msix_entry *entry = &adapter->msix_entries[vector];
  717. if (q_vector->tx.ring && q_vector->rx.ring) {
  718. snprintf(q_vector->name, sizeof(q_vector->name) - 1,
  719. "%s-%s-%d", netdev->name, "TxRx", ri++);
  720. ti++;
  721. } else if (q_vector->rx.ring) {
  722. snprintf(q_vector->name, sizeof(q_vector->name) - 1,
  723. "%s-%s-%d", netdev->name, "rx", ri++);
  724. } else if (q_vector->tx.ring) {
  725. snprintf(q_vector->name, sizeof(q_vector->name) - 1,
  726. "%s-%s-%d", netdev->name, "tx", ti++);
  727. } else {
  728. /* skip this unused q_vector */
  729. continue;
  730. }
  731. err = request_irq(entry->vector, &ixgbevf_msix_clean_rings, 0,
  732. q_vector->name, q_vector);
  733. if (err) {
  734. hw_dbg(&adapter->hw,
  735. "request_irq failed for MSIX interrupt "
  736. "Error: %d\n", err);
  737. goto free_queue_irqs;
  738. }
  739. }
  740. err = request_irq(adapter->msix_entries[vector].vector,
  741. &ixgbevf_msix_other, 0, netdev->name, adapter);
  742. if (err) {
  743. hw_dbg(&adapter->hw,
  744. "request_irq for msix_other failed: %d\n", err);
  745. goto free_queue_irqs;
  746. }
  747. return 0;
  748. free_queue_irqs:
  749. while (vector) {
  750. vector--;
  751. free_irq(adapter->msix_entries[vector].vector,
  752. adapter->q_vector[vector]);
  753. }
  754. pci_disable_msix(adapter->pdev);
  755. kfree(adapter->msix_entries);
  756. adapter->msix_entries = NULL;
  757. return err;
  758. }
  759. static inline void ixgbevf_reset_q_vectors(struct ixgbevf_adapter *adapter)
  760. {
  761. int i, q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
  762. for (i = 0; i < q_vectors; i++) {
  763. struct ixgbevf_q_vector *q_vector = adapter->q_vector[i];
  764. q_vector->rx.ring = NULL;
  765. q_vector->tx.ring = NULL;
  766. q_vector->rx.count = 0;
  767. q_vector->tx.count = 0;
  768. }
  769. }
  770. /**
  771. * ixgbevf_request_irq - initialize interrupts
  772. * @adapter: board private structure
  773. *
  774. * Attempts to configure interrupts using the best available
  775. * capabilities of the hardware and kernel.
  776. **/
  777. static int ixgbevf_request_irq(struct ixgbevf_adapter *adapter)
  778. {
  779. int err = 0;
  780. err = ixgbevf_request_msix_irqs(adapter);
  781. if (err)
  782. hw_dbg(&adapter->hw,
  783. "request_irq failed, Error %d\n", err);
  784. return err;
  785. }
  786. static void ixgbevf_free_irq(struct ixgbevf_adapter *adapter)
  787. {
  788. int i, q_vectors;
  789. q_vectors = adapter->num_msix_vectors;
  790. i = q_vectors - 1;
  791. free_irq(adapter->msix_entries[i].vector, adapter);
  792. i--;
  793. for (; i >= 0; i--) {
  794. /* free only the irqs that were actually requested */
  795. if (!adapter->q_vector[i]->rx.ring &&
  796. !adapter->q_vector[i]->tx.ring)
  797. continue;
  798. free_irq(adapter->msix_entries[i].vector,
  799. adapter->q_vector[i]);
  800. }
  801. ixgbevf_reset_q_vectors(adapter);
  802. }
  803. /**
  804. * ixgbevf_irq_disable - Mask off interrupt generation on the NIC
  805. * @adapter: board private structure
  806. **/
  807. static inline void ixgbevf_irq_disable(struct ixgbevf_adapter *adapter)
  808. {
  809. struct ixgbe_hw *hw = &adapter->hw;
  810. int i;
  811. IXGBE_WRITE_REG(hw, IXGBE_VTEIAM, 0);
  812. IXGBE_WRITE_REG(hw, IXGBE_VTEIMC, ~0);
  813. IXGBE_WRITE_REG(hw, IXGBE_VTEIAC, 0);
  814. IXGBE_WRITE_FLUSH(hw);
  815. for (i = 0; i < adapter->num_msix_vectors; i++)
  816. synchronize_irq(adapter->msix_entries[i].vector);
  817. }
  818. /**
  819. * ixgbevf_irq_enable - Enable default interrupt generation settings
  820. * @adapter: board private structure
  821. **/
  822. static inline void ixgbevf_irq_enable(struct ixgbevf_adapter *adapter)
  823. {
  824. struct ixgbe_hw *hw = &adapter->hw;
  825. IXGBE_WRITE_REG(hw, IXGBE_VTEIAM, adapter->eims_enable_mask);
  826. IXGBE_WRITE_REG(hw, IXGBE_VTEIAC, adapter->eims_enable_mask);
  827. IXGBE_WRITE_REG(hw, IXGBE_VTEIMS, adapter->eims_enable_mask);
  828. }
  829. /**
  830. * ixgbevf_configure_tx - Configure 82599 VF Transmit Unit after Reset
  831. * @adapter: board private structure
  832. *
  833. * Configure the Tx unit of the MAC after a reset.
  834. **/
  835. static void ixgbevf_configure_tx(struct ixgbevf_adapter *adapter)
  836. {
  837. u64 tdba;
  838. struct ixgbe_hw *hw = &adapter->hw;
  839. u32 i, j, tdlen, txctrl;
  840. /* Setup the HW Tx Head and Tail descriptor pointers */
  841. for (i = 0; i < adapter->num_tx_queues; i++) {
  842. struct ixgbevf_ring *ring = &adapter->tx_ring[i];
  843. j = ring->reg_idx;
  844. tdba = ring->dma;
  845. tdlen = ring->count * sizeof(union ixgbe_adv_tx_desc);
  846. IXGBE_WRITE_REG(hw, IXGBE_VFTDBAL(j),
  847. (tdba & DMA_BIT_MASK(32)));
  848. IXGBE_WRITE_REG(hw, IXGBE_VFTDBAH(j), (tdba >> 32));
  849. IXGBE_WRITE_REG(hw, IXGBE_VFTDLEN(j), tdlen);
  850. IXGBE_WRITE_REG(hw, IXGBE_VFTDH(j), 0);
  851. IXGBE_WRITE_REG(hw, IXGBE_VFTDT(j), 0);
  852. adapter->tx_ring[i].head = IXGBE_VFTDH(j);
  853. adapter->tx_ring[i].tail = IXGBE_VFTDT(j);
  854. /* Disable Tx Head Writeback RO bit, since this hoses
  855. * bookkeeping if things aren't delivered in order.
  856. */
  857. txctrl = IXGBE_READ_REG(hw, IXGBE_VFDCA_TXCTRL(j));
  858. txctrl &= ~IXGBE_DCA_TXCTRL_TX_WB_RO_EN;
  859. IXGBE_WRITE_REG(hw, IXGBE_VFDCA_TXCTRL(j), txctrl);
  860. }
  861. }
  862. #define IXGBE_SRRCTL_BSIZEHDRSIZE_SHIFT 2
  863. static void ixgbevf_configure_srrctl(struct ixgbevf_adapter *adapter, int index)
  864. {
  865. struct ixgbevf_ring *rx_ring;
  866. struct ixgbe_hw *hw = &adapter->hw;
  867. u32 srrctl;
  868. rx_ring = &adapter->rx_ring[index];
  869. srrctl = IXGBE_SRRCTL_DROP_EN;
  870. srrctl |= IXGBE_SRRCTL_DESCTYPE_ADV_ONEBUF;
  871. srrctl |= ALIGN(rx_ring->rx_buf_len, 1024) >>
  872. IXGBE_SRRCTL_BSIZEPKT_SHIFT;
  873. IXGBE_WRITE_REG(hw, IXGBE_VFSRRCTL(index), srrctl);
  874. }
  875. static void ixgbevf_set_rx_buffer_len(struct ixgbevf_adapter *adapter)
  876. {
  877. struct ixgbe_hw *hw = &adapter->hw;
  878. struct net_device *netdev = adapter->netdev;
  879. int max_frame = netdev->mtu + ETH_HLEN + ETH_FCS_LEN;
  880. int i;
  881. u16 rx_buf_len;
  882. /* notify the PF of our intent to use this size of frame */
  883. ixgbevf_rlpml_set_vf(hw, max_frame);
  884. /* PF will allow an extra 4 bytes past for vlan tagged frames */
  885. max_frame += VLAN_HLEN;
  886. /*
  887. * Make best use of allocation by using all but 1K of a
  888. * power of 2 allocation that will be used for skb->head.
  889. */
  890. if ((hw->mac.type == ixgbe_mac_X540_vf) &&
  891. (max_frame <= MAXIMUM_ETHERNET_VLAN_SIZE))
  892. rx_buf_len = MAXIMUM_ETHERNET_VLAN_SIZE;
  893. else if (max_frame <= IXGBEVF_RXBUFFER_3K)
  894. rx_buf_len = IXGBEVF_RXBUFFER_3K;
  895. else if (max_frame <= IXGBEVF_RXBUFFER_7K)
  896. rx_buf_len = IXGBEVF_RXBUFFER_7K;
  897. else if (max_frame <= IXGBEVF_RXBUFFER_15K)
  898. rx_buf_len = IXGBEVF_RXBUFFER_15K;
  899. else
  900. rx_buf_len = IXGBEVF_MAX_RXBUFFER;
  901. for (i = 0; i < adapter->num_rx_queues; i++)
  902. adapter->rx_ring[i].rx_buf_len = rx_buf_len;
  903. }
  904. /**
  905. * ixgbevf_configure_rx - Configure 82599 VF Receive Unit after Reset
  906. * @adapter: board private structure
  907. *
  908. * Configure the Rx unit of the MAC after a reset.
  909. **/
  910. static void ixgbevf_configure_rx(struct ixgbevf_adapter *adapter)
  911. {
  912. u64 rdba;
  913. struct ixgbe_hw *hw = &adapter->hw;
  914. int i, j;
  915. u32 rdlen;
  916. /* PSRTYPE must be initialized in 82599 */
  917. IXGBE_WRITE_REG(hw, IXGBE_VFPSRTYPE, 0);
  918. /* set_rx_buffer_len must be called before ring initialization */
  919. ixgbevf_set_rx_buffer_len(adapter);
  920. rdlen = adapter->rx_ring[0].count * sizeof(union ixgbe_adv_rx_desc);
  921. /* Setup the HW Rx Head and Tail Descriptor Pointers and
  922. * the Base and Length of the Rx Descriptor Ring */
  923. for (i = 0; i < adapter->num_rx_queues; i++) {
  924. rdba = adapter->rx_ring[i].dma;
  925. j = adapter->rx_ring[i].reg_idx;
  926. IXGBE_WRITE_REG(hw, IXGBE_VFRDBAL(j),
  927. (rdba & DMA_BIT_MASK(32)));
  928. IXGBE_WRITE_REG(hw, IXGBE_VFRDBAH(j), (rdba >> 32));
  929. IXGBE_WRITE_REG(hw, IXGBE_VFRDLEN(j), rdlen);
  930. IXGBE_WRITE_REG(hw, IXGBE_VFRDH(j), 0);
  931. IXGBE_WRITE_REG(hw, IXGBE_VFRDT(j), 0);
  932. adapter->rx_ring[i].head = IXGBE_VFRDH(j);
  933. adapter->rx_ring[i].tail = IXGBE_VFRDT(j);
  934. ixgbevf_configure_srrctl(adapter, j);
  935. }
  936. }
  937. static int ixgbevf_vlan_rx_add_vid(struct net_device *netdev, u16 vid)
  938. {
  939. struct ixgbevf_adapter *adapter = netdev_priv(netdev);
  940. struct ixgbe_hw *hw = &adapter->hw;
  941. spin_lock(&adapter->mbx_lock);
  942. /* add VID to filter table */
  943. if (hw->mac.ops.set_vfta)
  944. hw->mac.ops.set_vfta(hw, vid, 0, true);
  945. spin_unlock(&adapter->mbx_lock);
  946. set_bit(vid, adapter->active_vlans);
  947. return 0;
  948. }
  949. static int ixgbevf_vlan_rx_kill_vid(struct net_device *netdev, u16 vid)
  950. {
  951. struct ixgbevf_adapter *adapter = netdev_priv(netdev);
  952. struct ixgbe_hw *hw = &adapter->hw;
  953. spin_lock(&adapter->mbx_lock);
  954. /* remove VID from filter table */
  955. if (hw->mac.ops.set_vfta)
  956. hw->mac.ops.set_vfta(hw, vid, 0, false);
  957. spin_unlock(&adapter->mbx_lock);
  958. clear_bit(vid, adapter->active_vlans);
  959. return 0;
  960. }
  961. static void ixgbevf_restore_vlan(struct ixgbevf_adapter *adapter)
  962. {
  963. u16 vid;
  964. for_each_set_bit(vid, adapter->active_vlans, VLAN_N_VID)
  965. ixgbevf_vlan_rx_add_vid(adapter->netdev, vid);
  966. }
  967. static int ixgbevf_write_uc_addr_list(struct net_device *netdev)
  968. {
  969. struct ixgbevf_adapter *adapter = netdev_priv(netdev);
  970. struct ixgbe_hw *hw = &adapter->hw;
  971. int count = 0;
  972. if ((netdev_uc_count(netdev)) > 10) {
  973. pr_err("Too many unicast filters - No Space\n");
  974. return -ENOSPC;
  975. }
  976. if (!netdev_uc_empty(netdev)) {
  977. struct netdev_hw_addr *ha;
  978. netdev_for_each_uc_addr(ha, netdev) {
  979. hw->mac.ops.set_uc_addr(hw, ++count, ha->addr);
  980. udelay(200);
  981. }
  982. } else {
  983. /*
  984. * If the list is empty then send message to PF driver to
  985. * clear all macvlans on this VF.
  986. */
  987. hw->mac.ops.set_uc_addr(hw, 0, NULL);
  988. }
  989. return count;
  990. }
  991. /**
  992. * ixgbevf_set_rx_mode - Multicast set
  993. * @netdev: network interface device structure
  994. *
  995. * The set_rx_method entry point is called whenever the multicast address
  996. * list or the network interface flags are updated. This routine is
  997. * responsible for configuring the hardware for proper multicast mode.
  998. **/
  999. static void ixgbevf_set_rx_mode(struct net_device *netdev)
  1000. {
  1001. struct ixgbevf_adapter *adapter = netdev_priv(netdev);
  1002. struct ixgbe_hw *hw = &adapter->hw;
  1003. spin_lock(&adapter->mbx_lock);
  1004. /* reprogram multicast list */
  1005. if (hw->mac.ops.update_mc_addr_list)
  1006. hw->mac.ops.update_mc_addr_list(hw, netdev);
  1007. ixgbevf_write_uc_addr_list(netdev);
  1008. spin_unlock(&adapter->mbx_lock);
  1009. }
  1010. static void ixgbevf_napi_enable_all(struct ixgbevf_adapter *adapter)
  1011. {
  1012. int q_idx;
  1013. struct ixgbevf_q_vector *q_vector;
  1014. int q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
  1015. for (q_idx = 0; q_idx < q_vectors; q_idx++) {
  1016. q_vector = adapter->q_vector[q_idx];
  1017. napi_enable(&q_vector->napi);
  1018. }
  1019. }
  1020. static void ixgbevf_napi_disable_all(struct ixgbevf_adapter *adapter)
  1021. {
  1022. int q_idx;
  1023. struct ixgbevf_q_vector *q_vector;
  1024. int q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
  1025. for (q_idx = 0; q_idx < q_vectors; q_idx++) {
  1026. q_vector = adapter->q_vector[q_idx];
  1027. napi_disable(&q_vector->napi);
  1028. }
  1029. }
  1030. static void ixgbevf_configure(struct ixgbevf_adapter *adapter)
  1031. {
  1032. struct net_device *netdev = adapter->netdev;
  1033. int i;
  1034. ixgbevf_set_rx_mode(netdev);
  1035. ixgbevf_restore_vlan(adapter);
  1036. ixgbevf_configure_tx(adapter);
  1037. ixgbevf_configure_rx(adapter);
  1038. for (i = 0; i < adapter->num_rx_queues; i++) {
  1039. struct ixgbevf_ring *ring = &adapter->rx_ring[i];
  1040. ixgbevf_alloc_rx_buffers(adapter, ring,
  1041. IXGBE_DESC_UNUSED(ring));
  1042. }
  1043. }
  1044. #define IXGBE_MAX_RX_DESC_POLL 10
  1045. static inline void ixgbevf_rx_desc_queue_enable(struct ixgbevf_adapter *adapter,
  1046. int rxr)
  1047. {
  1048. struct ixgbe_hw *hw = &adapter->hw;
  1049. int j = adapter->rx_ring[rxr].reg_idx;
  1050. int k;
  1051. for (k = 0; k < IXGBE_MAX_RX_DESC_POLL; k++) {
  1052. if (IXGBE_READ_REG(hw, IXGBE_VFRXDCTL(j)) & IXGBE_RXDCTL_ENABLE)
  1053. break;
  1054. else
  1055. msleep(1);
  1056. }
  1057. if (k >= IXGBE_MAX_RX_DESC_POLL) {
  1058. hw_dbg(hw, "RXDCTL.ENABLE on Rx queue %d "
  1059. "not set within the polling period\n", rxr);
  1060. }
  1061. ixgbevf_release_rx_desc(&adapter->hw, &adapter->rx_ring[rxr],
  1062. (adapter->rx_ring[rxr].count - 1));
  1063. }
  1064. static void ixgbevf_save_reset_stats(struct ixgbevf_adapter *adapter)
  1065. {
  1066. /* Only save pre-reset stats if there are some */
  1067. if (adapter->stats.vfgprc || adapter->stats.vfgptc) {
  1068. adapter->stats.saved_reset_vfgprc += adapter->stats.vfgprc -
  1069. adapter->stats.base_vfgprc;
  1070. adapter->stats.saved_reset_vfgptc += adapter->stats.vfgptc -
  1071. adapter->stats.base_vfgptc;
  1072. adapter->stats.saved_reset_vfgorc += adapter->stats.vfgorc -
  1073. adapter->stats.base_vfgorc;
  1074. adapter->stats.saved_reset_vfgotc += adapter->stats.vfgotc -
  1075. adapter->stats.base_vfgotc;
  1076. adapter->stats.saved_reset_vfmprc += adapter->stats.vfmprc -
  1077. adapter->stats.base_vfmprc;
  1078. }
  1079. }
  1080. static void ixgbevf_init_last_counter_stats(struct ixgbevf_adapter *adapter)
  1081. {
  1082. struct ixgbe_hw *hw = &adapter->hw;
  1083. adapter->stats.last_vfgprc = IXGBE_READ_REG(hw, IXGBE_VFGPRC);
  1084. adapter->stats.last_vfgorc = IXGBE_READ_REG(hw, IXGBE_VFGORC_LSB);
  1085. adapter->stats.last_vfgorc |=
  1086. (((u64)(IXGBE_READ_REG(hw, IXGBE_VFGORC_MSB))) << 32);
  1087. adapter->stats.last_vfgptc = IXGBE_READ_REG(hw, IXGBE_VFGPTC);
  1088. adapter->stats.last_vfgotc = IXGBE_READ_REG(hw, IXGBE_VFGOTC_LSB);
  1089. adapter->stats.last_vfgotc |=
  1090. (((u64)(IXGBE_READ_REG(hw, IXGBE_VFGOTC_MSB))) << 32);
  1091. adapter->stats.last_vfmprc = IXGBE_READ_REG(hw, IXGBE_VFMPRC);
  1092. adapter->stats.base_vfgprc = adapter->stats.last_vfgprc;
  1093. adapter->stats.base_vfgorc = adapter->stats.last_vfgorc;
  1094. adapter->stats.base_vfgptc = adapter->stats.last_vfgptc;
  1095. adapter->stats.base_vfgotc = adapter->stats.last_vfgotc;
  1096. adapter->stats.base_vfmprc = adapter->stats.last_vfmprc;
  1097. }
  1098. static void ixgbevf_negotiate_api(struct ixgbevf_adapter *adapter)
  1099. {
  1100. struct ixgbe_hw *hw = &adapter->hw;
  1101. int api[] = { ixgbe_mbox_api_10,
  1102. ixgbe_mbox_api_unknown };
  1103. int err = 0, idx = 0;
  1104. spin_lock(&adapter->mbx_lock);
  1105. while (api[idx] != ixgbe_mbox_api_unknown) {
  1106. err = ixgbevf_negotiate_api_version(hw, api[idx]);
  1107. if (!err)
  1108. break;
  1109. idx++;
  1110. }
  1111. spin_unlock(&adapter->mbx_lock);
  1112. }
  1113. static void ixgbevf_up_complete(struct ixgbevf_adapter *adapter)
  1114. {
  1115. struct net_device *netdev = adapter->netdev;
  1116. struct ixgbe_hw *hw = &adapter->hw;
  1117. int i, j = 0;
  1118. int num_rx_rings = adapter->num_rx_queues;
  1119. u32 txdctl, rxdctl;
  1120. for (i = 0; i < adapter->num_tx_queues; i++) {
  1121. j = adapter->tx_ring[i].reg_idx;
  1122. txdctl = IXGBE_READ_REG(hw, IXGBE_VFTXDCTL(j));
  1123. /* enable WTHRESH=8 descriptors, to encourage burst writeback */
  1124. txdctl |= (8 << 16);
  1125. IXGBE_WRITE_REG(hw, IXGBE_VFTXDCTL(j), txdctl);
  1126. }
  1127. for (i = 0; i < adapter->num_tx_queues; i++) {
  1128. j = adapter->tx_ring[i].reg_idx;
  1129. txdctl = IXGBE_READ_REG(hw, IXGBE_VFTXDCTL(j));
  1130. txdctl |= IXGBE_TXDCTL_ENABLE;
  1131. IXGBE_WRITE_REG(hw, IXGBE_VFTXDCTL(j), txdctl);
  1132. }
  1133. for (i = 0; i < num_rx_rings; i++) {
  1134. j = adapter->rx_ring[i].reg_idx;
  1135. rxdctl = IXGBE_READ_REG(hw, IXGBE_VFRXDCTL(j));
  1136. rxdctl |= IXGBE_RXDCTL_ENABLE | IXGBE_RXDCTL_VME;
  1137. if (hw->mac.type == ixgbe_mac_X540_vf) {
  1138. rxdctl &= ~IXGBE_RXDCTL_RLPMLMASK;
  1139. rxdctl |= ((netdev->mtu + ETH_HLEN + ETH_FCS_LEN) |
  1140. IXGBE_RXDCTL_RLPML_EN);
  1141. }
  1142. IXGBE_WRITE_REG(hw, IXGBE_VFRXDCTL(j), rxdctl);
  1143. ixgbevf_rx_desc_queue_enable(adapter, i);
  1144. }
  1145. ixgbevf_configure_msix(adapter);
  1146. spin_lock(&adapter->mbx_lock);
  1147. if (hw->mac.ops.set_rar) {
  1148. if (is_valid_ether_addr(hw->mac.addr))
  1149. hw->mac.ops.set_rar(hw, 0, hw->mac.addr, 0);
  1150. else
  1151. hw->mac.ops.set_rar(hw, 0, hw->mac.perm_addr, 0);
  1152. }
  1153. spin_unlock(&adapter->mbx_lock);
  1154. clear_bit(__IXGBEVF_DOWN, &adapter->state);
  1155. ixgbevf_napi_enable_all(adapter);
  1156. /* enable transmits */
  1157. netif_tx_start_all_queues(netdev);
  1158. ixgbevf_save_reset_stats(adapter);
  1159. ixgbevf_init_last_counter_stats(adapter);
  1160. hw->mac.get_link_status = 1;
  1161. mod_timer(&adapter->watchdog_timer, jiffies);
  1162. }
  1163. void ixgbevf_up(struct ixgbevf_adapter *adapter)
  1164. {
  1165. struct ixgbe_hw *hw = &adapter->hw;
  1166. ixgbevf_negotiate_api(adapter);
  1167. ixgbevf_configure(adapter);
  1168. ixgbevf_up_complete(adapter);
  1169. /* clear any pending interrupts, may auto mask */
  1170. IXGBE_READ_REG(hw, IXGBE_VTEICR);
  1171. ixgbevf_irq_enable(adapter);
  1172. }
  1173. /**
  1174. * ixgbevf_clean_rx_ring - Free Rx Buffers per Queue
  1175. * @adapter: board private structure
  1176. * @rx_ring: ring to free buffers from
  1177. **/
  1178. static void ixgbevf_clean_rx_ring(struct ixgbevf_adapter *adapter,
  1179. struct ixgbevf_ring *rx_ring)
  1180. {
  1181. struct pci_dev *pdev = adapter->pdev;
  1182. unsigned long size;
  1183. unsigned int i;
  1184. if (!rx_ring->rx_buffer_info)
  1185. return;
  1186. /* Free all the Rx ring sk_buffs */
  1187. for (i = 0; i < rx_ring->count; i++) {
  1188. struct ixgbevf_rx_buffer *rx_buffer_info;
  1189. rx_buffer_info = &rx_ring->rx_buffer_info[i];
  1190. if (rx_buffer_info->dma) {
  1191. dma_unmap_single(&pdev->dev, rx_buffer_info->dma,
  1192. rx_ring->rx_buf_len,
  1193. DMA_FROM_DEVICE);
  1194. rx_buffer_info->dma = 0;
  1195. }
  1196. if (rx_buffer_info->skb) {
  1197. struct sk_buff *skb = rx_buffer_info->skb;
  1198. rx_buffer_info->skb = NULL;
  1199. do {
  1200. struct sk_buff *this = skb;
  1201. skb = skb->prev;
  1202. dev_kfree_skb(this);
  1203. } while (skb);
  1204. }
  1205. }
  1206. size = sizeof(struct ixgbevf_rx_buffer) * rx_ring->count;
  1207. memset(rx_ring->rx_buffer_info, 0, size);
  1208. /* Zero out the descriptor ring */
  1209. memset(rx_ring->desc, 0, rx_ring->size);
  1210. rx_ring->next_to_clean = 0;
  1211. rx_ring->next_to_use = 0;
  1212. if (rx_ring->head)
  1213. writel(0, adapter->hw.hw_addr + rx_ring->head);
  1214. if (rx_ring->tail)
  1215. writel(0, adapter->hw.hw_addr + rx_ring->tail);
  1216. }
  1217. /**
  1218. * ixgbevf_clean_tx_ring - Free Tx Buffers
  1219. * @adapter: board private structure
  1220. * @tx_ring: ring to be cleaned
  1221. **/
  1222. static void ixgbevf_clean_tx_ring(struct ixgbevf_adapter *adapter,
  1223. struct ixgbevf_ring *tx_ring)
  1224. {
  1225. struct ixgbevf_tx_buffer *tx_buffer_info;
  1226. unsigned long size;
  1227. unsigned int i;
  1228. if (!tx_ring->tx_buffer_info)
  1229. return;
  1230. /* Free all the Tx ring sk_buffs */
  1231. for (i = 0; i < tx_ring->count; i++) {
  1232. tx_buffer_info = &tx_ring->tx_buffer_info[i];
  1233. ixgbevf_unmap_and_free_tx_resource(tx_ring, tx_buffer_info);
  1234. }
  1235. size = sizeof(struct ixgbevf_tx_buffer) * tx_ring->count;
  1236. memset(tx_ring->tx_buffer_info, 0, size);
  1237. memset(tx_ring->desc, 0, tx_ring->size);
  1238. tx_ring->next_to_use = 0;
  1239. tx_ring->next_to_clean = 0;
  1240. if (tx_ring->head)
  1241. writel(0, adapter->hw.hw_addr + tx_ring->head);
  1242. if (tx_ring->tail)
  1243. writel(0, adapter->hw.hw_addr + tx_ring->tail);
  1244. }
  1245. /**
  1246. * ixgbevf_clean_all_rx_rings - Free Rx Buffers for all queues
  1247. * @adapter: board private structure
  1248. **/
  1249. static void ixgbevf_clean_all_rx_rings(struct ixgbevf_adapter *adapter)
  1250. {
  1251. int i;
  1252. for (i = 0; i < adapter->num_rx_queues; i++)
  1253. ixgbevf_clean_rx_ring(adapter, &adapter->rx_ring[i]);
  1254. }
  1255. /**
  1256. * ixgbevf_clean_all_tx_rings - Free Tx Buffers for all queues
  1257. * @adapter: board private structure
  1258. **/
  1259. static void ixgbevf_clean_all_tx_rings(struct ixgbevf_adapter *adapter)
  1260. {
  1261. int i;
  1262. for (i = 0; i < adapter->num_tx_queues; i++)
  1263. ixgbevf_clean_tx_ring(adapter, &adapter->tx_ring[i]);
  1264. }
  1265. void ixgbevf_down(struct ixgbevf_adapter *adapter)
  1266. {
  1267. struct net_device *netdev = adapter->netdev;
  1268. struct ixgbe_hw *hw = &adapter->hw;
  1269. u32 txdctl;
  1270. int i, j;
  1271. /* signal that we are down to the interrupt handler */
  1272. set_bit(__IXGBEVF_DOWN, &adapter->state);
  1273. /* disable receives */
  1274. netif_tx_disable(netdev);
  1275. msleep(10);
  1276. netif_tx_stop_all_queues(netdev);
  1277. ixgbevf_irq_disable(adapter);
  1278. ixgbevf_napi_disable_all(adapter);
  1279. del_timer_sync(&adapter->watchdog_timer);
  1280. /* can't call flush scheduled work here because it can deadlock
  1281. * if linkwatch_event tries to acquire the rtnl_lock which we are
  1282. * holding */
  1283. while (adapter->flags & IXGBE_FLAG_IN_WATCHDOG_TASK)
  1284. msleep(1);
  1285. /* disable transmits in the hardware now that interrupts are off */
  1286. for (i = 0; i < adapter->num_tx_queues; i++) {
  1287. j = adapter->tx_ring[i].reg_idx;
  1288. txdctl = IXGBE_READ_REG(hw, IXGBE_VFTXDCTL(j));
  1289. IXGBE_WRITE_REG(hw, IXGBE_VFTXDCTL(j),
  1290. (txdctl & ~IXGBE_TXDCTL_ENABLE));
  1291. }
  1292. netif_carrier_off(netdev);
  1293. if (!pci_channel_offline(adapter->pdev))
  1294. ixgbevf_reset(adapter);
  1295. ixgbevf_clean_all_tx_rings(adapter);
  1296. ixgbevf_clean_all_rx_rings(adapter);
  1297. }
  1298. void ixgbevf_reinit_locked(struct ixgbevf_adapter *adapter)
  1299. {
  1300. WARN_ON(in_interrupt());
  1301. while (test_and_set_bit(__IXGBEVF_RESETTING, &adapter->state))
  1302. msleep(1);
  1303. /*
  1304. * Check if PF is up before re-init. If not then skip until
  1305. * later when the PF is up and ready to service requests from
  1306. * the VF via mailbox. If the VF is up and running then the
  1307. * watchdog task will continue to schedule reset tasks until
  1308. * the PF is up and running.
  1309. */
  1310. ixgbevf_down(adapter);
  1311. ixgbevf_up(adapter);
  1312. clear_bit(__IXGBEVF_RESETTING, &adapter->state);
  1313. }
  1314. void ixgbevf_reset(struct ixgbevf_adapter *adapter)
  1315. {
  1316. struct ixgbe_hw *hw = &adapter->hw;
  1317. struct net_device *netdev = adapter->netdev;
  1318. spin_lock(&adapter->mbx_lock);
  1319. if (hw->mac.ops.reset_hw(hw))
  1320. hw_dbg(hw, "PF still resetting\n");
  1321. else
  1322. hw->mac.ops.init_hw(hw);
  1323. spin_unlock(&adapter->mbx_lock);
  1324. if (is_valid_ether_addr(adapter->hw.mac.addr)) {
  1325. memcpy(netdev->dev_addr, adapter->hw.mac.addr,
  1326. netdev->addr_len);
  1327. memcpy(netdev->perm_addr, adapter->hw.mac.addr,
  1328. netdev->addr_len);
  1329. }
  1330. }
  1331. static void ixgbevf_acquire_msix_vectors(struct ixgbevf_adapter *adapter,
  1332. int vectors)
  1333. {
  1334. int err, vector_threshold;
  1335. /* We'll want at least 2 (vector_threshold):
  1336. * 1) TxQ[0] + RxQ[0] handler
  1337. * 2) Other (Link Status Change, etc.)
  1338. */
  1339. vector_threshold = MIN_MSIX_COUNT;
  1340. /* The more we get, the more we will assign to Tx/Rx Cleanup
  1341. * for the separate queues...where Rx Cleanup >= Tx Cleanup.
  1342. * Right now, we simply care about how many we'll get; we'll
  1343. * set them up later while requesting irq's.
  1344. */
  1345. while (vectors >= vector_threshold) {
  1346. err = pci_enable_msix(adapter->pdev, adapter->msix_entries,
  1347. vectors);
  1348. if (!err) /* Success in acquiring all requested vectors. */
  1349. break;
  1350. else if (err < 0)
  1351. vectors = 0; /* Nasty failure, quit now */
  1352. else /* err == number of vectors we should try again with */
  1353. vectors = err;
  1354. }
  1355. if (vectors < vector_threshold) {
  1356. /* Can't allocate enough MSI-X interrupts? Oh well.
  1357. * This just means we'll go with either a single MSI
  1358. * vector or fall back to legacy interrupts.
  1359. */
  1360. hw_dbg(&adapter->hw,
  1361. "Unable to allocate MSI-X interrupts\n");
  1362. kfree(adapter->msix_entries);
  1363. adapter->msix_entries = NULL;
  1364. } else {
  1365. /*
  1366. * Adjust for only the vectors we'll use, which is minimum
  1367. * of max_msix_q_vectors + NON_Q_VECTORS, or the number of
  1368. * vectors we were allocated.
  1369. */
  1370. adapter->num_msix_vectors = vectors;
  1371. }
  1372. }
  1373. /**
  1374. * ixgbevf_set_num_queues - Allocate queues for device, feature dependent
  1375. * @adapter: board private structure to initialize
  1376. *
  1377. * This is the top level queue allocation routine. The order here is very
  1378. * important, starting with the "most" number of features turned on at once,
  1379. * and ending with the smallest set of features. This way large combinations
  1380. * can be allocated if they're turned on, and smaller combinations are the
  1381. * fallthrough conditions.
  1382. *
  1383. **/
  1384. static void ixgbevf_set_num_queues(struct ixgbevf_adapter *adapter)
  1385. {
  1386. /* Start with base case */
  1387. adapter->num_rx_queues = 1;
  1388. adapter->num_tx_queues = 1;
  1389. }
  1390. /**
  1391. * ixgbevf_alloc_queues - Allocate memory for all rings
  1392. * @adapter: board private structure to initialize
  1393. *
  1394. * We allocate one ring per queue at run-time since we don't know the
  1395. * number of queues at compile-time. The polling_netdev array is
  1396. * intended for Multiqueue, but should work fine with a single queue.
  1397. **/
  1398. static int ixgbevf_alloc_queues(struct ixgbevf_adapter *adapter)
  1399. {
  1400. int i;
  1401. adapter->tx_ring = kcalloc(adapter->num_tx_queues,
  1402. sizeof(struct ixgbevf_ring), GFP_KERNEL);
  1403. if (!adapter->tx_ring)
  1404. goto err_tx_ring_allocation;
  1405. adapter->rx_ring = kcalloc(adapter->num_rx_queues,
  1406. sizeof(struct ixgbevf_ring), GFP_KERNEL);
  1407. if (!adapter->rx_ring)
  1408. goto err_rx_ring_allocation;
  1409. for (i = 0; i < adapter->num_tx_queues; i++) {
  1410. adapter->tx_ring[i].count = adapter->tx_ring_count;
  1411. adapter->tx_ring[i].queue_index = i;
  1412. adapter->tx_ring[i].reg_idx = i;
  1413. adapter->tx_ring[i].dev = &adapter->pdev->dev;
  1414. adapter->tx_ring[i].netdev = adapter->netdev;
  1415. }
  1416. for (i = 0; i < adapter->num_rx_queues; i++) {
  1417. adapter->rx_ring[i].count = adapter->rx_ring_count;
  1418. adapter->rx_ring[i].queue_index = i;
  1419. adapter->rx_ring[i].reg_idx = i;
  1420. adapter->rx_ring[i].dev = &adapter->pdev->dev;
  1421. adapter->rx_ring[i].netdev = adapter->netdev;
  1422. }
  1423. return 0;
  1424. err_rx_ring_allocation:
  1425. kfree(adapter->tx_ring);
  1426. err_tx_ring_allocation:
  1427. return -ENOMEM;
  1428. }
  1429. /**
  1430. * ixgbevf_set_interrupt_capability - set MSI-X or FAIL if not supported
  1431. * @adapter: board private structure to initialize
  1432. *
  1433. * Attempt to configure the interrupts using the best available
  1434. * capabilities of the hardware and the kernel.
  1435. **/
  1436. static int ixgbevf_set_interrupt_capability(struct ixgbevf_adapter *adapter)
  1437. {
  1438. int err = 0;
  1439. int vector, v_budget;
  1440. /*
  1441. * It's easy to be greedy for MSI-X vectors, but it really
  1442. * doesn't do us much good if we have a lot more vectors
  1443. * than CPU's. So let's be conservative and only ask for
  1444. * (roughly) the same number of vectors as there are CPU's.
  1445. * The default is to use pairs of vectors.
  1446. */
  1447. v_budget = max(adapter->num_rx_queues, adapter->num_tx_queues);
  1448. v_budget = min_t(int, v_budget, num_online_cpus());
  1449. v_budget += NON_Q_VECTORS;
  1450. /* A failure in MSI-X entry allocation isn't fatal, but it does
  1451. * mean we disable MSI-X capabilities of the adapter. */
  1452. adapter->msix_entries = kcalloc(v_budget,
  1453. sizeof(struct msix_entry), GFP_KERNEL);
  1454. if (!adapter->msix_entries) {
  1455. err = -ENOMEM;
  1456. goto out;
  1457. }
  1458. for (vector = 0; vector < v_budget; vector++)
  1459. adapter->msix_entries[vector].entry = vector;
  1460. ixgbevf_acquire_msix_vectors(adapter, v_budget);
  1461. out:
  1462. return err;
  1463. }
  1464. /**
  1465. * ixgbevf_alloc_q_vectors - Allocate memory for interrupt vectors
  1466. * @adapter: board private structure to initialize
  1467. *
  1468. * We allocate one q_vector per queue interrupt. If allocation fails we
  1469. * return -ENOMEM.
  1470. **/
  1471. static int ixgbevf_alloc_q_vectors(struct ixgbevf_adapter *adapter)
  1472. {
  1473. int q_idx, num_q_vectors;
  1474. struct ixgbevf_q_vector *q_vector;
  1475. num_q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
  1476. for (q_idx = 0; q_idx < num_q_vectors; q_idx++) {
  1477. q_vector = kzalloc(sizeof(struct ixgbevf_q_vector), GFP_KERNEL);
  1478. if (!q_vector)
  1479. goto err_out;
  1480. q_vector->adapter = adapter;
  1481. q_vector->v_idx = q_idx;
  1482. netif_napi_add(adapter->netdev, &q_vector->napi,
  1483. ixgbevf_poll, 64);
  1484. adapter->q_vector[q_idx] = q_vector;
  1485. }
  1486. return 0;
  1487. err_out:
  1488. while (q_idx) {
  1489. q_idx--;
  1490. q_vector = adapter->q_vector[q_idx];
  1491. netif_napi_del(&q_vector->napi);
  1492. kfree(q_vector);
  1493. adapter->q_vector[q_idx] = NULL;
  1494. }
  1495. return -ENOMEM;
  1496. }
  1497. /**
  1498. * ixgbevf_free_q_vectors - Free memory allocated for interrupt vectors
  1499. * @adapter: board private structure to initialize
  1500. *
  1501. * This function frees the memory allocated to the q_vectors. In addition if
  1502. * NAPI is enabled it will delete any references to the NAPI struct prior
  1503. * to freeing the q_vector.
  1504. **/
  1505. static void ixgbevf_free_q_vectors(struct ixgbevf_adapter *adapter)
  1506. {
  1507. int q_idx, num_q_vectors;
  1508. int napi_vectors;
  1509. num_q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
  1510. napi_vectors = adapter->num_rx_queues;
  1511. for (q_idx = 0; q_idx < num_q_vectors; q_idx++) {
  1512. struct ixgbevf_q_vector *q_vector = adapter->q_vector[q_idx];
  1513. adapter->q_vector[q_idx] = NULL;
  1514. if (q_idx < napi_vectors)
  1515. netif_napi_del(&q_vector->napi);
  1516. kfree(q_vector);
  1517. }
  1518. }
  1519. /**
  1520. * ixgbevf_reset_interrupt_capability - Reset MSIX setup
  1521. * @adapter: board private structure
  1522. *
  1523. **/
  1524. static void ixgbevf_reset_interrupt_capability(struct ixgbevf_adapter *adapter)
  1525. {
  1526. pci_disable_msix(adapter->pdev);
  1527. kfree(adapter->msix_entries);
  1528. adapter->msix_entries = NULL;
  1529. }
  1530. /**
  1531. * ixgbevf_init_interrupt_scheme - Determine if MSIX is supported and init
  1532. * @adapter: board private structure to initialize
  1533. *
  1534. **/
  1535. static int ixgbevf_init_interrupt_scheme(struct ixgbevf_adapter *adapter)
  1536. {
  1537. int err;
  1538. /* Number of supported queues */
  1539. ixgbevf_set_num_queues(adapter);
  1540. err = ixgbevf_set_interrupt_capability(adapter);
  1541. if (err) {
  1542. hw_dbg(&adapter->hw,
  1543. "Unable to setup interrupt capabilities\n");
  1544. goto err_set_interrupt;
  1545. }
  1546. err = ixgbevf_alloc_q_vectors(adapter);
  1547. if (err) {
  1548. hw_dbg(&adapter->hw, "Unable to allocate memory for queue "
  1549. "vectors\n");
  1550. goto err_alloc_q_vectors;
  1551. }
  1552. err = ixgbevf_alloc_queues(adapter);
  1553. if (err) {
  1554. pr_err("Unable to allocate memory for queues\n");
  1555. goto err_alloc_queues;
  1556. }
  1557. hw_dbg(&adapter->hw, "Multiqueue %s: Rx Queue count = %u, "
  1558. "Tx Queue count = %u\n",
  1559. (adapter->num_rx_queues > 1) ? "Enabled" :
  1560. "Disabled", adapter->num_rx_queues, adapter->num_tx_queues);
  1561. set_bit(__IXGBEVF_DOWN, &adapter->state);
  1562. return 0;
  1563. err_alloc_queues:
  1564. ixgbevf_free_q_vectors(adapter);
  1565. err_alloc_q_vectors:
  1566. ixgbevf_reset_interrupt_capability(adapter);
  1567. err_set_interrupt:
  1568. return err;
  1569. }
  1570. /**
  1571. * ixgbevf_clear_interrupt_scheme - Clear the current interrupt scheme settings
  1572. * @adapter: board private structure to clear interrupt scheme on
  1573. *
  1574. * We go through and clear interrupt specific resources and reset the structure
  1575. * to pre-load conditions
  1576. **/
  1577. static void ixgbevf_clear_interrupt_scheme(struct ixgbevf_adapter *adapter)
  1578. {
  1579. adapter->num_tx_queues = 0;
  1580. adapter->num_rx_queues = 0;
  1581. ixgbevf_free_q_vectors(adapter);
  1582. ixgbevf_reset_interrupt_capability(adapter);
  1583. }
  1584. /**
  1585. * ixgbevf_sw_init - Initialize general software structures
  1586. * (struct ixgbevf_adapter)
  1587. * @adapter: board private structure to initialize
  1588. *
  1589. * ixgbevf_sw_init initializes the Adapter private data structure.
  1590. * Fields are initialized based on PCI device information and
  1591. * OS network device settings (MTU size).
  1592. **/
  1593. static int __devinit ixgbevf_sw_init(struct ixgbevf_adapter *adapter)
  1594. {
  1595. struct ixgbe_hw *hw = &adapter->hw;
  1596. struct pci_dev *pdev = adapter->pdev;
  1597. int err;
  1598. /* PCI config space info */
  1599. hw->vendor_id = pdev->vendor;
  1600. hw->device_id = pdev->device;
  1601. hw->revision_id = pdev->revision;
  1602. hw->subsystem_vendor_id = pdev->subsystem_vendor;
  1603. hw->subsystem_device_id = pdev->subsystem_device;
  1604. hw->mbx.ops.init_params(hw);
  1605. hw->mac.max_tx_queues = MAX_TX_QUEUES;
  1606. hw->mac.max_rx_queues = MAX_RX_QUEUES;
  1607. err = hw->mac.ops.reset_hw(hw);
  1608. if (err) {
  1609. dev_info(&pdev->dev,
  1610. "PF still in reset state, assigning new address\n");
  1611. eth_hw_addr_random(adapter->netdev);
  1612. memcpy(adapter->hw.mac.addr, adapter->netdev->dev_addr,
  1613. adapter->netdev->addr_len);
  1614. } else {
  1615. err = hw->mac.ops.init_hw(hw);
  1616. if (err) {
  1617. pr_err("init_shared_code failed: %d\n", err);
  1618. goto out;
  1619. }
  1620. memcpy(adapter->netdev->dev_addr, adapter->hw.mac.addr,
  1621. adapter->netdev->addr_len);
  1622. }
  1623. /* lock to protect mailbox accesses */
  1624. spin_lock_init(&adapter->mbx_lock);
  1625. /* Enable dynamic interrupt throttling rates */
  1626. adapter->rx_itr_setting = 1;
  1627. adapter->tx_itr_setting = 1;
  1628. /* set default ring sizes */
  1629. adapter->tx_ring_count = IXGBEVF_DEFAULT_TXD;
  1630. adapter->rx_ring_count = IXGBEVF_DEFAULT_RXD;
  1631. set_bit(__IXGBEVF_DOWN, &adapter->state);
  1632. return 0;
  1633. out:
  1634. return err;
  1635. }
  1636. #define UPDATE_VF_COUNTER_32bit(reg, last_counter, counter) \
  1637. { \
  1638. u32 current_counter = IXGBE_READ_REG(hw, reg); \
  1639. if (current_counter < last_counter) \
  1640. counter += 0x100000000LL; \
  1641. last_counter = current_counter; \
  1642. counter &= 0xFFFFFFFF00000000LL; \
  1643. counter |= current_counter; \
  1644. }
  1645. #define UPDATE_VF_COUNTER_36bit(reg_lsb, reg_msb, last_counter, counter) \
  1646. { \
  1647. u64 current_counter_lsb = IXGBE_READ_REG(hw, reg_lsb); \
  1648. u64 current_counter_msb = IXGBE_READ_REG(hw, reg_msb); \
  1649. u64 current_counter = (current_counter_msb << 32) | \
  1650. current_counter_lsb; \
  1651. if (current_counter < last_counter) \
  1652. counter += 0x1000000000LL; \
  1653. last_counter = current_counter; \
  1654. counter &= 0xFFFFFFF000000000LL; \
  1655. counter |= current_counter; \
  1656. }
  1657. /**
  1658. * ixgbevf_update_stats - Update the board statistics counters.
  1659. * @adapter: board private structure
  1660. **/
  1661. void ixgbevf_update_stats(struct ixgbevf_adapter *adapter)
  1662. {
  1663. struct ixgbe_hw *hw = &adapter->hw;
  1664. UPDATE_VF_COUNTER_32bit(IXGBE_VFGPRC, adapter->stats.last_vfgprc,
  1665. adapter->stats.vfgprc);
  1666. UPDATE_VF_COUNTER_32bit(IXGBE_VFGPTC, adapter->stats.last_vfgptc,
  1667. adapter->stats.vfgptc);
  1668. UPDATE_VF_COUNTER_36bit(IXGBE_VFGORC_LSB, IXGBE_VFGORC_MSB,
  1669. adapter->stats.last_vfgorc,
  1670. adapter->stats.vfgorc);
  1671. UPDATE_VF_COUNTER_36bit(IXGBE_VFGOTC_LSB, IXGBE_VFGOTC_MSB,
  1672. adapter->stats.last_vfgotc,
  1673. adapter->stats.vfgotc);
  1674. UPDATE_VF_COUNTER_32bit(IXGBE_VFMPRC, adapter->stats.last_vfmprc,
  1675. adapter->stats.vfmprc);
  1676. }
  1677. /**
  1678. * ixgbevf_watchdog - Timer Call-back
  1679. * @data: pointer to adapter cast into an unsigned long
  1680. **/
  1681. static void ixgbevf_watchdog(unsigned long data)
  1682. {
  1683. struct ixgbevf_adapter *adapter = (struct ixgbevf_adapter *)data;
  1684. struct ixgbe_hw *hw = &adapter->hw;
  1685. u32 eics = 0;
  1686. int i;
  1687. /*
  1688. * Do the watchdog outside of interrupt context due to the lovely
  1689. * delays that some of the newer hardware requires
  1690. */
  1691. if (test_bit(__IXGBEVF_DOWN, &adapter->state))
  1692. goto watchdog_short_circuit;
  1693. /* get one bit for every active tx/rx interrupt vector */
  1694. for (i = 0; i < adapter->num_msix_vectors - NON_Q_VECTORS; i++) {
  1695. struct ixgbevf_q_vector *qv = adapter->q_vector[i];
  1696. if (qv->rx.ring || qv->tx.ring)
  1697. eics |= 1 << i;
  1698. }
  1699. IXGBE_WRITE_REG(hw, IXGBE_VTEICS, eics);
  1700. watchdog_short_circuit:
  1701. schedule_work(&adapter->watchdog_task);
  1702. }
  1703. /**
  1704. * ixgbevf_tx_timeout - Respond to a Tx Hang
  1705. * @netdev: network interface device structure
  1706. **/
  1707. static void ixgbevf_tx_timeout(struct net_device *netdev)
  1708. {
  1709. struct ixgbevf_adapter *adapter = netdev_priv(netdev);
  1710. /* Do the reset outside of interrupt context */
  1711. schedule_work(&adapter->reset_task);
  1712. }
  1713. static void ixgbevf_reset_task(struct work_struct *work)
  1714. {
  1715. struct ixgbevf_adapter *adapter;
  1716. adapter = container_of(work, struct ixgbevf_adapter, reset_task);
  1717. /* If we're already down or resetting, just bail */
  1718. if (test_bit(__IXGBEVF_DOWN, &adapter->state) ||
  1719. test_bit(__IXGBEVF_RESETTING, &adapter->state))
  1720. return;
  1721. adapter->tx_timeout_count++;
  1722. ixgbevf_reinit_locked(adapter);
  1723. }
  1724. /**
  1725. * ixgbevf_watchdog_task - worker thread to bring link up
  1726. * @work: pointer to work_struct containing our data
  1727. **/
  1728. static void ixgbevf_watchdog_task(struct work_struct *work)
  1729. {
  1730. struct ixgbevf_adapter *adapter = container_of(work,
  1731. struct ixgbevf_adapter,
  1732. watchdog_task);
  1733. struct net_device *netdev = adapter->netdev;
  1734. struct ixgbe_hw *hw = &adapter->hw;
  1735. u32 link_speed = adapter->link_speed;
  1736. bool link_up = adapter->link_up;
  1737. adapter->flags |= IXGBE_FLAG_IN_WATCHDOG_TASK;
  1738. /*
  1739. * Always check the link on the watchdog because we have
  1740. * no LSC interrupt
  1741. */
  1742. if (hw->mac.ops.check_link) {
  1743. s32 need_reset;
  1744. spin_lock(&adapter->mbx_lock);
  1745. need_reset = hw->mac.ops.check_link(hw, &link_speed,
  1746. &link_up, false);
  1747. spin_unlock(&adapter->mbx_lock);
  1748. if (need_reset) {
  1749. adapter->link_up = link_up;
  1750. adapter->link_speed = link_speed;
  1751. netif_carrier_off(netdev);
  1752. netif_tx_stop_all_queues(netdev);
  1753. schedule_work(&adapter->reset_task);
  1754. goto pf_has_reset;
  1755. }
  1756. } else {
  1757. /* always assume link is up, if no check link
  1758. * function */
  1759. link_speed = IXGBE_LINK_SPEED_10GB_FULL;
  1760. link_up = true;
  1761. }
  1762. adapter->link_up = link_up;
  1763. adapter->link_speed = link_speed;
  1764. if (link_up) {
  1765. if (!netif_carrier_ok(netdev)) {
  1766. hw_dbg(&adapter->hw, "NIC Link is Up, %u Gbps\n",
  1767. (link_speed == IXGBE_LINK_SPEED_10GB_FULL) ?
  1768. 10 : 1);
  1769. netif_carrier_on(netdev);
  1770. netif_tx_wake_all_queues(netdev);
  1771. }
  1772. } else {
  1773. adapter->link_up = false;
  1774. adapter->link_speed = 0;
  1775. if (netif_carrier_ok(netdev)) {
  1776. hw_dbg(&adapter->hw, "NIC Link is Down\n");
  1777. netif_carrier_off(netdev);
  1778. netif_tx_stop_all_queues(netdev);
  1779. }
  1780. }
  1781. ixgbevf_update_stats(adapter);
  1782. pf_has_reset:
  1783. /* Reset the timer */
  1784. if (!test_bit(__IXGBEVF_DOWN, &adapter->state))
  1785. mod_timer(&adapter->watchdog_timer,
  1786. round_jiffies(jiffies + (2 * HZ)));
  1787. adapter->flags &= ~IXGBE_FLAG_IN_WATCHDOG_TASK;
  1788. }
  1789. /**
  1790. * ixgbevf_free_tx_resources - Free Tx Resources per Queue
  1791. * @adapter: board private structure
  1792. * @tx_ring: Tx descriptor ring for a specific queue
  1793. *
  1794. * Free all transmit software resources
  1795. **/
  1796. void ixgbevf_free_tx_resources(struct ixgbevf_adapter *adapter,
  1797. struct ixgbevf_ring *tx_ring)
  1798. {
  1799. struct pci_dev *pdev = adapter->pdev;
  1800. ixgbevf_clean_tx_ring(adapter, tx_ring);
  1801. vfree(tx_ring->tx_buffer_info);
  1802. tx_ring->tx_buffer_info = NULL;
  1803. dma_free_coherent(&pdev->dev, tx_ring->size, tx_ring->desc,
  1804. tx_ring->dma);
  1805. tx_ring->desc = NULL;
  1806. }
  1807. /**
  1808. * ixgbevf_free_all_tx_resources - Free Tx Resources for All Queues
  1809. * @adapter: board private structure
  1810. *
  1811. * Free all transmit software resources
  1812. **/
  1813. static void ixgbevf_free_all_tx_resources(struct ixgbevf_adapter *adapter)
  1814. {
  1815. int i;
  1816. for (i = 0; i < adapter->num_tx_queues; i++)
  1817. if (adapter->tx_ring[i].desc)
  1818. ixgbevf_free_tx_resources(adapter,
  1819. &adapter->tx_ring[i]);
  1820. }
  1821. /**
  1822. * ixgbevf_setup_tx_resources - allocate Tx resources (Descriptors)
  1823. * @adapter: board private structure
  1824. * @tx_ring: tx descriptor ring (for a specific queue) to setup
  1825. *
  1826. * Return 0 on success, negative on failure
  1827. **/
  1828. int ixgbevf_setup_tx_resources(struct ixgbevf_adapter *adapter,
  1829. struct ixgbevf_ring *tx_ring)
  1830. {
  1831. struct pci_dev *pdev = adapter->pdev;
  1832. int size;
  1833. size = sizeof(struct ixgbevf_tx_buffer) * tx_ring->count;
  1834. tx_ring->tx_buffer_info = vzalloc(size);
  1835. if (!tx_ring->tx_buffer_info)
  1836. goto err;
  1837. /* round up to nearest 4K */
  1838. tx_ring->size = tx_ring->count * sizeof(union ixgbe_adv_tx_desc);
  1839. tx_ring->size = ALIGN(tx_ring->size, 4096);
  1840. tx_ring->desc = dma_alloc_coherent(&pdev->dev, tx_ring->size,
  1841. &tx_ring->dma, GFP_KERNEL);
  1842. if (!tx_ring->desc)
  1843. goto err;
  1844. tx_ring->next_to_use = 0;
  1845. tx_ring->next_to_clean = 0;
  1846. return 0;
  1847. err:
  1848. vfree(tx_ring->tx_buffer_info);
  1849. tx_ring->tx_buffer_info = NULL;
  1850. hw_dbg(&adapter->hw, "Unable to allocate memory for the transmit "
  1851. "descriptor ring\n");
  1852. return -ENOMEM;
  1853. }
  1854. /**
  1855. * ixgbevf_setup_all_tx_resources - allocate all queues Tx resources
  1856. * @adapter: board private structure
  1857. *
  1858. * If this function returns with an error, then it's possible one or
  1859. * more of the rings is populated (while the rest are not). It is the
  1860. * callers duty to clean those orphaned rings.
  1861. *
  1862. * Return 0 on success, negative on failure
  1863. **/
  1864. static int ixgbevf_setup_all_tx_resources(struct ixgbevf_adapter *adapter)
  1865. {
  1866. int i, err = 0;
  1867. for (i = 0; i < adapter->num_tx_queues; i++) {
  1868. err = ixgbevf_setup_tx_resources(adapter, &adapter->tx_ring[i]);
  1869. if (!err)
  1870. continue;
  1871. hw_dbg(&adapter->hw,
  1872. "Allocation for Tx Queue %u failed\n", i);
  1873. break;
  1874. }
  1875. return err;
  1876. }
  1877. /**
  1878. * ixgbevf_setup_rx_resources - allocate Rx resources (Descriptors)
  1879. * @adapter: board private structure
  1880. * @rx_ring: rx descriptor ring (for a specific queue) to setup
  1881. *
  1882. * Returns 0 on success, negative on failure
  1883. **/
  1884. int ixgbevf_setup_rx_resources(struct ixgbevf_adapter *adapter,
  1885. struct ixgbevf_ring *rx_ring)
  1886. {
  1887. struct pci_dev *pdev = adapter->pdev;
  1888. int size;
  1889. size = sizeof(struct ixgbevf_rx_buffer) * rx_ring->count;
  1890. rx_ring->rx_buffer_info = vzalloc(size);
  1891. if (!rx_ring->rx_buffer_info)
  1892. goto alloc_failed;
  1893. /* Round up to nearest 4K */
  1894. rx_ring->size = rx_ring->count * sizeof(union ixgbe_adv_rx_desc);
  1895. rx_ring->size = ALIGN(rx_ring->size, 4096);
  1896. rx_ring->desc = dma_alloc_coherent(&pdev->dev, rx_ring->size,
  1897. &rx_ring->dma, GFP_KERNEL);
  1898. if (!rx_ring->desc) {
  1899. hw_dbg(&adapter->hw,
  1900. "Unable to allocate memory for "
  1901. "the receive descriptor ring\n");
  1902. vfree(rx_ring->rx_buffer_info);
  1903. rx_ring->rx_buffer_info = NULL;
  1904. goto alloc_failed;
  1905. }
  1906. rx_ring->next_to_clean = 0;
  1907. rx_ring->next_to_use = 0;
  1908. return 0;
  1909. alloc_failed:
  1910. return -ENOMEM;
  1911. }
  1912. /**
  1913. * ixgbevf_setup_all_rx_resources - allocate all queues Rx resources
  1914. * @adapter: board private structure
  1915. *
  1916. * If this function returns with an error, then it's possible one or
  1917. * more of the rings is populated (while the rest are not). It is the
  1918. * callers duty to clean those orphaned rings.
  1919. *
  1920. * Return 0 on success, negative on failure
  1921. **/
  1922. static int ixgbevf_setup_all_rx_resources(struct ixgbevf_adapter *adapter)
  1923. {
  1924. int i, err = 0;
  1925. for (i = 0; i < adapter->num_rx_queues; i++) {
  1926. err = ixgbevf_setup_rx_resources(adapter, &adapter->rx_ring[i]);
  1927. if (!err)
  1928. continue;
  1929. hw_dbg(&adapter->hw,
  1930. "Allocation for Rx Queue %u failed\n", i);
  1931. break;
  1932. }
  1933. return err;
  1934. }
  1935. /**
  1936. * ixgbevf_free_rx_resources - Free Rx Resources
  1937. * @adapter: board private structure
  1938. * @rx_ring: ring to clean the resources from
  1939. *
  1940. * Free all receive software resources
  1941. **/
  1942. void ixgbevf_free_rx_resources(struct ixgbevf_adapter *adapter,
  1943. struct ixgbevf_ring *rx_ring)
  1944. {
  1945. struct pci_dev *pdev = adapter->pdev;
  1946. ixgbevf_clean_rx_ring(adapter, rx_ring);
  1947. vfree(rx_ring->rx_buffer_info);
  1948. rx_ring->rx_buffer_info = NULL;
  1949. dma_free_coherent(&pdev->dev, rx_ring->size, rx_ring->desc,
  1950. rx_ring->dma);
  1951. rx_ring->desc = NULL;
  1952. }
  1953. /**
  1954. * ixgbevf_free_all_rx_resources - Free Rx Resources for All Queues
  1955. * @adapter: board private structure
  1956. *
  1957. * Free all receive software resources
  1958. **/
  1959. static void ixgbevf_free_all_rx_resources(struct ixgbevf_adapter *adapter)
  1960. {
  1961. int i;
  1962. for (i = 0; i < adapter->num_rx_queues; i++)
  1963. if (adapter->rx_ring[i].desc)
  1964. ixgbevf_free_rx_resources(adapter,
  1965. &adapter->rx_ring[i]);
  1966. }
  1967. /**
  1968. * ixgbevf_open - Called when a network interface is made active
  1969. * @netdev: network interface device structure
  1970. *
  1971. * Returns 0 on success, negative value on failure
  1972. *
  1973. * The open entry point is called when a network interface is made
  1974. * active by the system (IFF_UP). At this point all resources needed
  1975. * for transmit and receive operations are allocated, the interrupt
  1976. * handler is registered with the OS, the watchdog timer is started,
  1977. * and the stack is notified that the interface is ready.
  1978. **/
  1979. static int ixgbevf_open(struct net_device *netdev)
  1980. {
  1981. struct ixgbevf_adapter *adapter = netdev_priv(netdev);
  1982. struct ixgbe_hw *hw = &adapter->hw;
  1983. int err;
  1984. /* disallow open during test */
  1985. if (test_bit(__IXGBEVF_TESTING, &adapter->state))
  1986. return -EBUSY;
  1987. if (hw->adapter_stopped) {
  1988. ixgbevf_reset(adapter);
  1989. /* if adapter is still stopped then PF isn't up and
  1990. * the vf can't start. */
  1991. if (hw->adapter_stopped) {
  1992. err = IXGBE_ERR_MBX;
  1993. pr_err("Unable to start - perhaps the PF Driver isn't "
  1994. "up yet\n");
  1995. goto err_setup_reset;
  1996. }
  1997. }
  1998. ixgbevf_negotiate_api(adapter);
  1999. /* allocate transmit descriptors */
  2000. err = ixgbevf_setup_all_tx_resources(adapter);
  2001. if (err)
  2002. goto err_setup_tx;
  2003. /* allocate receive descriptors */
  2004. err = ixgbevf_setup_all_rx_resources(adapter);
  2005. if (err)
  2006. goto err_setup_rx;
  2007. ixgbevf_configure(adapter);
  2008. /*
  2009. * Map the Tx/Rx rings to the vectors we were allotted.
  2010. * if request_irq will be called in this function map_rings
  2011. * must be called *before* up_complete
  2012. */
  2013. ixgbevf_map_rings_to_vectors(adapter);
  2014. ixgbevf_up_complete(adapter);
  2015. /* clear any pending interrupts, may auto mask */
  2016. IXGBE_READ_REG(hw, IXGBE_VTEICR);
  2017. err = ixgbevf_request_irq(adapter);
  2018. if (err)
  2019. goto err_req_irq;
  2020. ixgbevf_irq_enable(adapter);
  2021. return 0;
  2022. err_req_irq:
  2023. ixgbevf_down(adapter);
  2024. ixgbevf_free_irq(adapter);
  2025. err_setup_rx:
  2026. ixgbevf_free_all_rx_resources(adapter);
  2027. err_setup_tx:
  2028. ixgbevf_free_all_tx_resources(adapter);
  2029. ixgbevf_reset(adapter);
  2030. err_setup_reset:
  2031. return err;
  2032. }
  2033. /**
  2034. * ixgbevf_close - Disables a network interface
  2035. * @netdev: network interface device structure
  2036. *
  2037. * Returns 0, this is not allowed to fail
  2038. *
  2039. * The close entry point is called when an interface is de-activated
  2040. * by the OS. The hardware is still under the drivers control, but
  2041. * needs to be disabled. A global MAC reset is issued to stop the
  2042. * hardware, and all transmit and receive resources are freed.
  2043. **/
  2044. static int ixgbevf_close(struct net_device *netdev)
  2045. {
  2046. struct ixgbevf_adapter *adapter = netdev_priv(netdev);
  2047. ixgbevf_down(adapter);
  2048. ixgbevf_free_irq(adapter);
  2049. ixgbevf_free_all_tx_resources(adapter);
  2050. ixgbevf_free_all_rx_resources(adapter);
  2051. return 0;
  2052. }
  2053. static void ixgbevf_tx_ctxtdesc(struct ixgbevf_ring *tx_ring,
  2054. u32 vlan_macip_lens, u32 type_tucmd,
  2055. u32 mss_l4len_idx)
  2056. {
  2057. struct ixgbe_adv_tx_context_desc *context_desc;
  2058. u16 i = tx_ring->next_to_use;
  2059. context_desc = IXGBEVF_TX_CTXTDESC(tx_ring, i);
  2060. i++;
  2061. tx_ring->next_to_use = (i < tx_ring->count) ? i : 0;
  2062. /* set bits to identify this as an advanced context descriptor */
  2063. type_tucmd |= IXGBE_TXD_CMD_DEXT | IXGBE_ADVTXD_DTYP_CTXT;
  2064. context_desc->vlan_macip_lens = cpu_to_le32(vlan_macip_lens);
  2065. context_desc->seqnum_seed = 0;
  2066. context_desc->type_tucmd_mlhl = cpu_to_le32(type_tucmd);
  2067. context_desc->mss_l4len_idx = cpu_to_le32(mss_l4len_idx);
  2068. }
  2069. static int ixgbevf_tso(struct ixgbevf_ring *tx_ring,
  2070. struct sk_buff *skb, u32 tx_flags, u8 *hdr_len)
  2071. {
  2072. u32 vlan_macip_lens, type_tucmd;
  2073. u32 mss_l4len_idx, l4len;
  2074. if (!skb_is_gso(skb))
  2075. return 0;
  2076. if (skb_header_cloned(skb)) {
  2077. int err = pskb_expand_head(skb, 0, 0, GFP_ATOMIC);
  2078. if (err)
  2079. return err;
  2080. }
  2081. /* ADV DTYP TUCMD MKRLOC/ISCSIHEDLEN */
  2082. type_tucmd = IXGBE_ADVTXD_TUCMD_L4T_TCP;
  2083. if (skb->protocol == htons(ETH_P_IP)) {
  2084. struct iphdr *iph = ip_hdr(skb);
  2085. iph->tot_len = 0;
  2086. iph->check = 0;
  2087. tcp_hdr(skb)->check = ~csum_tcpudp_magic(iph->saddr,
  2088. iph->daddr, 0,
  2089. IPPROTO_TCP,
  2090. 0);
  2091. type_tucmd |= IXGBE_ADVTXD_TUCMD_IPV4;
  2092. } else if (skb_is_gso_v6(skb)) {
  2093. ipv6_hdr(skb)->payload_len = 0;
  2094. tcp_hdr(skb)->check =
  2095. ~csum_ipv6_magic(&ipv6_hdr(skb)->saddr,
  2096. &ipv6_hdr(skb)->daddr,
  2097. 0, IPPROTO_TCP, 0);
  2098. }
  2099. /* compute header lengths */
  2100. l4len = tcp_hdrlen(skb);
  2101. *hdr_len += l4len;
  2102. *hdr_len = skb_transport_offset(skb) + l4len;
  2103. /* mss_l4len_id: use 1 as index for TSO */
  2104. mss_l4len_idx = l4len << IXGBE_ADVTXD_L4LEN_SHIFT;
  2105. mss_l4len_idx |= skb_shinfo(skb)->gso_size << IXGBE_ADVTXD_MSS_SHIFT;
  2106. mss_l4len_idx |= 1 << IXGBE_ADVTXD_IDX_SHIFT;
  2107. /* vlan_macip_lens: HEADLEN, MACLEN, VLAN tag */
  2108. vlan_macip_lens = skb_network_header_len(skb);
  2109. vlan_macip_lens |= skb_network_offset(skb) << IXGBE_ADVTXD_MACLEN_SHIFT;
  2110. vlan_macip_lens |= tx_flags & IXGBE_TX_FLAGS_VLAN_MASK;
  2111. ixgbevf_tx_ctxtdesc(tx_ring, vlan_macip_lens,
  2112. type_tucmd, mss_l4len_idx);
  2113. return 1;
  2114. }
  2115. static bool ixgbevf_tx_csum(struct ixgbevf_ring *tx_ring,
  2116. struct sk_buff *skb, u32 tx_flags)
  2117. {
  2118. u32 vlan_macip_lens = 0;
  2119. u32 mss_l4len_idx = 0;
  2120. u32 type_tucmd = 0;
  2121. if (skb->ip_summed == CHECKSUM_PARTIAL) {
  2122. u8 l4_hdr = 0;
  2123. switch (skb->protocol) {
  2124. case __constant_htons(ETH_P_IP):
  2125. vlan_macip_lens |= skb_network_header_len(skb);
  2126. type_tucmd |= IXGBE_ADVTXD_TUCMD_IPV4;
  2127. l4_hdr = ip_hdr(skb)->protocol;
  2128. break;
  2129. case __constant_htons(ETH_P_IPV6):
  2130. vlan_macip_lens |= skb_network_header_len(skb);
  2131. l4_hdr = ipv6_hdr(skb)->nexthdr;
  2132. break;
  2133. default:
  2134. if (unlikely(net_ratelimit())) {
  2135. dev_warn(tx_ring->dev,
  2136. "partial checksum but proto=%x!\n",
  2137. skb->protocol);
  2138. }
  2139. break;
  2140. }
  2141. switch (l4_hdr) {
  2142. case IPPROTO_TCP:
  2143. type_tucmd |= IXGBE_ADVTXD_TUCMD_L4T_TCP;
  2144. mss_l4len_idx = tcp_hdrlen(skb) <<
  2145. IXGBE_ADVTXD_L4LEN_SHIFT;
  2146. break;
  2147. case IPPROTO_SCTP:
  2148. type_tucmd |= IXGBE_ADVTXD_TUCMD_L4T_SCTP;
  2149. mss_l4len_idx = sizeof(struct sctphdr) <<
  2150. IXGBE_ADVTXD_L4LEN_SHIFT;
  2151. break;
  2152. case IPPROTO_UDP:
  2153. mss_l4len_idx = sizeof(struct udphdr) <<
  2154. IXGBE_ADVTXD_L4LEN_SHIFT;
  2155. break;
  2156. default:
  2157. if (unlikely(net_ratelimit())) {
  2158. dev_warn(tx_ring->dev,
  2159. "partial checksum but l4 proto=%x!\n",
  2160. l4_hdr);
  2161. }
  2162. break;
  2163. }
  2164. }
  2165. /* vlan_macip_lens: MACLEN, VLAN tag */
  2166. vlan_macip_lens |= skb_network_offset(skb) << IXGBE_ADVTXD_MACLEN_SHIFT;
  2167. vlan_macip_lens |= tx_flags & IXGBE_TX_FLAGS_VLAN_MASK;
  2168. ixgbevf_tx_ctxtdesc(tx_ring, vlan_macip_lens,
  2169. type_tucmd, mss_l4len_idx);
  2170. return (skb->ip_summed == CHECKSUM_PARTIAL);
  2171. }
  2172. static int ixgbevf_tx_map(struct ixgbevf_ring *tx_ring,
  2173. struct sk_buff *skb, u32 tx_flags,
  2174. unsigned int first)
  2175. {
  2176. struct ixgbevf_tx_buffer *tx_buffer_info;
  2177. unsigned int len;
  2178. unsigned int total = skb->len;
  2179. unsigned int offset = 0, size;
  2180. int count = 0;
  2181. unsigned int nr_frags = skb_shinfo(skb)->nr_frags;
  2182. unsigned int f;
  2183. int i;
  2184. i = tx_ring->next_to_use;
  2185. len = min(skb_headlen(skb), total);
  2186. while (len) {
  2187. tx_buffer_info = &tx_ring->tx_buffer_info[i];
  2188. size = min(len, (unsigned int)IXGBE_MAX_DATA_PER_TXD);
  2189. tx_buffer_info->length = size;
  2190. tx_buffer_info->mapped_as_page = false;
  2191. tx_buffer_info->dma = dma_map_single(tx_ring->dev,
  2192. skb->data + offset,
  2193. size, DMA_TO_DEVICE);
  2194. if (dma_mapping_error(tx_ring->dev, tx_buffer_info->dma))
  2195. goto dma_error;
  2196. tx_buffer_info->next_to_watch = i;
  2197. len -= size;
  2198. total -= size;
  2199. offset += size;
  2200. count++;
  2201. i++;
  2202. if (i == tx_ring->count)
  2203. i = 0;
  2204. }
  2205. for (f = 0; f < nr_frags; f++) {
  2206. const struct skb_frag_struct *frag;
  2207. frag = &skb_shinfo(skb)->frags[f];
  2208. len = min((unsigned int)skb_frag_size(frag), total);
  2209. offset = 0;
  2210. while (len) {
  2211. tx_buffer_info = &tx_ring->tx_buffer_info[i];
  2212. size = min(len, (unsigned int)IXGBE_MAX_DATA_PER_TXD);
  2213. tx_buffer_info->length = size;
  2214. tx_buffer_info->dma =
  2215. skb_frag_dma_map(tx_ring->dev, frag,
  2216. offset, size, DMA_TO_DEVICE);
  2217. tx_buffer_info->mapped_as_page = true;
  2218. if (dma_mapping_error(tx_ring->dev,
  2219. tx_buffer_info->dma))
  2220. goto dma_error;
  2221. tx_buffer_info->next_to_watch = i;
  2222. len -= size;
  2223. total -= size;
  2224. offset += size;
  2225. count++;
  2226. i++;
  2227. if (i == tx_ring->count)
  2228. i = 0;
  2229. }
  2230. if (total == 0)
  2231. break;
  2232. }
  2233. if (i == 0)
  2234. i = tx_ring->count - 1;
  2235. else
  2236. i = i - 1;
  2237. tx_ring->tx_buffer_info[i].skb = skb;
  2238. tx_ring->tx_buffer_info[first].next_to_watch = i;
  2239. tx_ring->tx_buffer_info[first].time_stamp = jiffies;
  2240. return count;
  2241. dma_error:
  2242. dev_err(tx_ring->dev, "TX DMA map failed\n");
  2243. /* clear timestamp and dma mappings for failed tx_buffer_info map */
  2244. tx_buffer_info->dma = 0;
  2245. tx_buffer_info->next_to_watch = 0;
  2246. count--;
  2247. /* clear timestamp and dma mappings for remaining portion of packet */
  2248. while (count >= 0) {
  2249. count--;
  2250. i--;
  2251. if (i < 0)
  2252. i += tx_ring->count;
  2253. tx_buffer_info = &tx_ring->tx_buffer_info[i];
  2254. ixgbevf_unmap_and_free_tx_resource(tx_ring, tx_buffer_info);
  2255. }
  2256. return count;
  2257. }
  2258. static void ixgbevf_tx_queue(struct ixgbevf_ring *tx_ring, int tx_flags,
  2259. int count, u32 paylen, u8 hdr_len)
  2260. {
  2261. union ixgbe_adv_tx_desc *tx_desc = NULL;
  2262. struct ixgbevf_tx_buffer *tx_buffer_info;
  2263. u32 olinfo_status = 0, cmd_type_len = 0;
  2264. unsigned int i;
  2265. u32 txd_cmd = IXGBE_TXD_CMD_EOP | IXGBE_TXD_CMD_RS | IXGBE_TXD_CMD_IFCS;
  2266. cmd_type_len |= IXGBE_ADVTXD_DTYP_DATA;
  2267. cmd_type_len |= IXGBE_ADVTXD_DCMD_IFCS | IXGBE_ADVTXD_DCMD_DEXT;
  2268. if (tx_flags & IXGBE_TX_FLAGS_VLAN)
  2269. cmd_type_len |= IXGBE_ADVTXD_DCMD_VLE;
  2270. if (tx_flags & IXGBE_TX_FLAGS_CSUM)
  2271. olinfo_status |= IXGBE_ADVTXD_POPTS_TXSM;
  2272. if (tx_flags & IXGBE_TX_FLAGS_TSO) {
  2273. cmd_type_len |= IXGBE_ADVTXD_DCMD_TSE;
  2274. /* use index 1 context for tso */
  2275. olinfo_status |= (1 << IXGBE_ADVTXD_IDX_SHIFT);
  2276. if (tx_flags & IXGBE_TX_FLAGS_IPV4)
  2277. olinfo_status |= IXGBE_ADVTXD_POPTS_IXSM;
  2278. }
  2279. /*
  2280. * Check Context must be set if Tx switch is enabled, which it
  2281. * always is for case where virtual functions are running
  2282. */
  2283. olinfo_status |= IXGBE_ADVTXD_CC;
  2284. olinfo_status |= ((paylen - hdr_len) << IXGBE_ADVTXD_PAYLEN_SHIFT);
  2285. i = tx_ring->next_to_use;
  2286. while (count--) {
  2287. tx_buffer_info = &tx_ring->tx_buffer_info[i];
  2288. tx_desc = IXGBEVF_TX_DESC(tx_ring, i);
  2289. tx_desc->read.buffer_addr = cpu_to_le64(tx_buffer_info->dma);
  2290. tx_desc->read.cmd_type_len =
  2291. cpu_to_le32(cmd_type_len | tx_buffer_info->length);
  2292. tx_desc->read.olinfo_status = cpu_to_le32(olinfo_status);
  2293. i++;
  2294. if (i == tx_ring->count)
  2295. i = 0;
  2296. }
  2297. tx_desc->read.cmd_type_len |= cpu_to_le32(txd_cmd);
  2298. tx_ring->next_to_use = i;
  2299. }
  2300. static int __ixgbevf_maybe_stop_tx(struct ixgbevf_ring *tx_ring, int size)
  2301. {
  2302. struct ixgbevf_adapter *adapter = netdev_priv(tx_ring->netdev);
  2303. netif_stop_subqueue(tx_ring->netdev, tx_ring->queue_index);
  2304. /* Herbert's original patch had:
  2305. * smp_mb__after_netif_stop_queue();
  2306. * but since that doesn't exist yet, just open code it. */
  2307. smp_mb();
  2308. /* We need to check again in a case another CPU has just
  2309. * made room available. */
  2310. if (likely(IXGBE_DESC_UNUSED(tx_ring) < size))
  2311. return -EBUSY;
  2312. /* A reprieve! - use start_queue because it doesn't call schedule */
  2313. netif_start_subqueue(tx_ring->netdev, tx_ring->queue_index);
  2314. ++adapter->restart_queue;
  2315. return 0;
  2316. }
  2317. static int ixgbevf_maybe_stop_tx(struct ixgbevf_ring *tx_ring, int size)
  2318. {
  2319. if (likely(IXGBE_DESC_UNUSED(tx_ring) >= size))
  2320. return 0;
  2321. return __ixgbevf_maybe_stop_tx(tx_ring, size);
  2322. }
  2323. static int ixgbevf_xmit_frame(struct sk_buff *skb, struct net_device *netdev)
  2324. {
  2325. struct ixgbevf_adapter *adapter = netdev_priv(netdev);
  2326. struct ixgbevf_ring *tx_ring;
  2327. unsigned int first;
  2328. unsigned int tx_flags = 0;
  2329. u8 hdr_len = 0;
  2330. int r_idx = 0, tso;
  2331. u16 count = TXD_USE_COUNT(skb_headlen(skb));
  2332. #if PAGE_SIZE > IXGBE_MAX_DATA_PER_TXD
  2333. unsigned short f;
  2334. #endif
  2335. tx_ring = &adapter->tx_ring[r_idx];
  2336. /*
  2337. * need: 1 descriptor per page * PAGE_SIZE/IXGBE_MAX_DATA_PER_TXD,
  2338. * + 1 desc for skb_headlen/IXGBE_MAX_DATA_PER_TXD,
  2339. * + 2 desc gap to keep tail from touching head,
  2340. * + 1 desc for context descriptor,
  2341. * otherwise try next time
  2342. */
  2343. #if PAGE_SIZE > IXGBE_MAX_DATA_PER_TXD
  2344. for (f = 0; f < skb_shinfo(skb)->nr_frags; f++)
  2345. count += TXD_USE_COUNT(skb_shinfo(skb)->frags[f].size);
  2346. #else
  2347. count += skb_shinfo(skb)->nr_frags;
  2348. #endif
  2349. if (ixgbevf_maybe_stop_tx(tx_ring, count + 3)) {
  2350. adapter->tx_busy++;
  2351. return NETDEV_TX_BUSY;
  2352. }
  2353. if (vlan_tx_tag_present(skb)) {
  2354. tx_flags |= vlan_tx_tag_get(skb);
  2355. tx_flags <<= IXGBE_TX_FLAGS_VLAN_SHIFT;
  2356. tx_flags |= IXGBE_TX_FLAGS_VLAN;
  2357. }
  2358. first = tx_ring->next_to_use;
  2359. if (skb->protocol == htons(ETH_P_IP))
  2360. tx_flags |= IXGBE_TX_FLAGS_IPV4;
  2361. tso = ixgbevf_tso(tx_ring, skb, tx_flags, &hdr_len);
  2362. if (tso < 0) {
  2363. dev_kfree_skb_any(skb);
  2364. return NETDEV_TX_OK;
  2365. }
  2366. if (tso)
  2367. tx_flags |= IXGBE_TX_FLAGS_TSO | IXGBE_TX_FLAGS_CSUM;
  2368. else if (ixgbevf_tx_csum(tx_ring, skb, tx_flags))
  2369. tx_flags |= IXGBE_TX_FLAGS_CSUM;
  2370. ixgbevf_tx_queue(tx_ring, tx_flags,
  2371. ixgbevf_tx_map(tx_ring, skb, tx_flags, first),
  2372. skb->len, hdr_len);
  2373. /*
  2374. * Force memory writes to complete before letting h/w
  2375. * know there are new descriptors to fetch. (Only
  2376. * applicable for weak-ordered memory model archs,
  2377. * such as IA-64).
  2378. */
  2379. wmb();
  2380. writel(tx_ring->next_to_use, adapter->hw.hw_addr + tx_ring->tail);
  2381. ixgbevf_maybe_stop_tx(tx_ring, DESC_NEEDED);
  2382. return NETDEV_TX_OK;
  2383. }
  2384. /**
  2385. * ixgbevf_set_mac - Change the Ethernet Address of the NIC
  2386. * @netdev: network interface device structure
  2387. * @p: pointer to an address structure
  2388. *
  2389. * Returns 0 on success, negative on failure
  2390. **/
  2391. static int ixgbevf_set_mac(struct net_device *netdev, void *p)
  2392. {
  2393. struct ixgbevf_adapter *adapter = netdev_priv(netdev);
  2394. struct ixgbe_hw *hw = &adapter->hw;
  2395. struct sockaddr *addr = p;
  2396. if (!is_valid_ether_addr(addr->sa_data))
  2397. return -EADDRNOTAVAIL;
  2398. memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
  2399. memcpy(hw->mac.addr, addr->sa_data, netdev->addr_len);
  2400. spin_lock(&adapter->mbx_lock);
  2401. if (hw->mac.ops.set_rar)
  2402. hw->mac.ops.set_rar(hw, 0, hw->mac.addr, 0);
  2403. spin_unlock(&adapter->mbx_lock);
  2404. return 0;
  2405. }
  2406. /**
  2407. * ixgbevf_change_mtu - Change the Maximum Transfer Unit
  2408. * @netdev: network interface device structure
  2409. * @new_mtu: new value for maximum frame size
  2410. *
  2411. * Returns 0 on success, negative on failure
  2412. **/
  2413. static int ixgbevf_change_mtu(struct net_device *netdev, int new_mtu)
  2414. {
  2415. struct ixgbevf_adapter *adapter = netdev_priv(netdev);
  2416. int max_frame = new_mtu + ETH_HLEN + ETH_FCS_LEN;
  2417. int max_possible_frame = MAXIMUM_ETHERNET_VLAN_SIZE;
  2418. if (adapter->hw.mac.type == ixgbe_mac_X540_vf)
  2419. max_possible_frame = IXGBE_MAX_JUMBO_FRAME_SIZE;
  2420. /* MTU < 68 is an error and causes problems on some kernels */
  2421. if ((new_mtu < 68) || (max_frame > max_possible_frame))
  2422. return -EINVAL;
  2423. hw_dbg(&adapter->hw, "changing MTU from %d to %d\n",
  2424. netdev->mtu, new_mtu);
  2425. /* must set new MTU before calling down or up */
  2426. netdev->mtu = new_mtu;
  2427. if (netif_running(netdev))
  2428. ixgbevf_reinit_locked(adapter);
  2429. return 0;
  2430. }
  2431. static int ixgbevf_suspend(struct pci_dev *pdev, pm_message_t state)
  2432. {
  2433. struct net_device *netdev = pci_get_drvdata(pdev);
  2434. struct ixgbevf_adapter *adapter = netdev_priv(netdev);
  2435. #ifdef CONFIG_PM
  2436. int retval = 0;
  2437. #endif
  2438. netif_device_detach(netdev);
  2439. if (netif_running(netdev)) {
  2440. rtnl_lock();
  2441. ixgbevf_down(adapter);
  2442. ixgbevf_free_irq(adapter);
  2443. ixgbevf_free_all_tx_resources(adapter);
  2444. ixgbevf_free_all_rx_resources(adapter);
  2445. rtnl_unlock();
  2446. }
  2447. ixgbevf_clear_interrupt_scheme(adapter);
  2448. #ifdef CONFIG_PM
  2449. retval = pci_save_state(pdev);
  2450. if (retval)
  2451. return retval;
  2452. #endif
  2453. pci_disable_device(pdev);
  2454. return 0;
  2455. }
  2456. #ifdef CONFIG_PM
  2457. static int ixgbevf_resume(struct pci_dev *pdev)
  2458. {
  2459. struct ixgbevf_adapter *adapter = pci_get_drvdata(pdev);
  2460. struct net_device *netdev = adapter->netdev;
  2461. u32 err;
  2462. pci_set_power_state(pdev, PCI_D0);
  2463. pci_restore_state(pdev);
  2464. /*
  2465. * pci_restore_state clears dev->state_saved so call
  2466. * pci_save_state to restore it.
  2467. */
  2468. pci_save_state(pdev);
  2469. err = pci_enable_device_mem(pdev);
  2470. if (err) {
  2471. dev_err(&pdev->dev, "Cannot enable PCI device from suspend\n");
  2472. return err;
  2473. }
  2474. pci_set_master(pdev);
  2475. rtnl_lock();
  2476. err = ixgbevf_init_interrupt_scheme(adapter);
  2477. rtnl_unlock();
  2478. if (err) {
  2479. dev_err(&pdev->dev, "Cannot initialize interrupts\n");
  2480. return err;
  2481. }
  2482. ixgbevf_reset(adapter);
  2483. if (netif_running(netdev)) {
  2484. err = ixgbevf_open(netdev);
  2485. if (err)
  2486. return err;
  2487. }
  2488. netif_device_attach(netdev);
  2489. return err;
  2490. }
  2491. #endif /* CONFIG_PM */
  2492. static void ixgbevf_shutdown(struct pci_dev *pdev)
  2493. {
  2494. ixgbevf_suspend(pdev, PMSG_SUSPEND);
  2495. }
  2496. static struct rtnl_link_stats64 *ixgbevf_get_stats(struct net_device *netdev,
  2497. struct rtnl_link_stats64 *stats)
  2498. {
  2499. struct ixgbevf_adapter *adapter = netdev_priv(netdev);
  2500. unsigned int start;
  2501. u64 bytes, packets;
  2502. const struct ixgbevf_ring *ring;
  2503. int i;
  2504. ixgbevf_update_stats(adapter);
  2505. stats->multicast = adapter->stats.vfmprc - adapter->stats.base_vfmprc;
  2506. for (i = 0; i < adapter->num_rx_queues; i++) {
  2507. ring = &adapter->rx_ring[i];
  2508. do {
  2509. start = u64_stats_fetch_begin_bh(&ring->syncp);
  2510. bytes = ring->total_bytes;
  2511. packets = ring->total_packets;
  2512. } while (u64_stats_fetch_retry_bh(&ring->syncp, start));
  2513. stats->rx_bytes += bytes;
  2514. stats->rx_packets += packets;
  2515. }
  2516. for (i = 0; i < adapter->num_tx_queues; i++) {
  2517. ring = &adapter->tx_ring[i];
  2518. do {
  2519. start = u64_stats_fetch_begin_bh(&ring->syncp);
  2520. bytes = ring->total_bytes;
  2521. packets = ring->total_packets;
  2522. } while (u64_stats_fetch_retry_bh(&ring->syncp, start));
  2523. stats->tx_bytes += bytes;
  2524. stats->tx_packets += packets;
  2525. }
  2526. return stats;
  2527. }
  2528. static const struct net_device_ops ixgbevf_netdev_ops = {
  2529. .ndo_open = ixgbevf_open,
  2530. .ndo_stop = ixgbevf_close,
  2531. .ndo_start_xmit = ixgbevf_xmit_frame,
  2532. .ndo_set_rx_mode = ixgbevf_set_rx_mode,
  2533. .ndo_get_stats64 = ixgbevf_get_stats,
  2534. .ndo_validate_addr = eth_validate_addr,
  2535. .ndo_set_mac_address = ixgbevf_set_mac,
  2536. .ndo_change_mtu = ixgbevf_change_mtu,
  2537. .ndo_tx_timeout = ixgbevf_tx_timeout,
  2538. .ndo_vlan_rx_add_vid = ixgbevf_vlan_rx_add_vid,
  2539. .ndo_vlan_rx_kill_vid = ixgbevf_vlan_rx_kill_vid,
  2540. };
  2541. static void ixgbevf_assign_netdev_ops(struct net_device *dev)
  2542. {
  2543. dev->netdev_ops = &ixgbevf_netdev_ops;
  2544. ixgbevf_set_ethtool_ops(dev);
  2545. dev->watchdog_timeo = 5 * HZ;
  2546. }
  2547. /**
  2548. * ixgbevf_probe - Device Initialization Routine
  2549. * @pdev: PCI device information struct
  2550. * @ent: entry in ixgbevf_pci_tbl
  2551. *
  2552. * Returns 0 on success, negative on failure
  2553. *
  2554. * ixgbevf_probe initializes an adapter identified by a pci_dev structure.
  2555. * The OS initialization, configuring of the adapter private structure,
  2556. * and a hardware reset occur.
  2557. **/
  2558. static int __devinit ixgbevf_probe(struct pci_dev *pdev,
  2559. const struct pci_device_id *ent)
  2560. {
  2561. struct net_device *netdev;
  2562. struct ixgbevf_adapter *adapter = NULL;
  2563. struct ixgbe_hw *hw = NULL;
  2564. const struct ixgbevf_info *ii = ixgbevf_info_tbl[ent->driver_data];
  2565. static int cards_found;
  2566. int err, pci_using_dac;
  2567. err = pci_enable_device(pdev);
  2568. if (err)
  2569. return err;
  2570. if (!dma_set_mask(&pdev->dev, DMA_BIT_MASK(64)) &&
  2571. !dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(64))) {
  2572. pci_using_dac = 1;
  2573. } else {
  2574. err = dma_set_mask(&pdev->dev, DMA_BIT_MASK(32));
  2575. if (err) {
  2576. err = dma_set_coherent_mask(&pdev->dev,
  2577. DMA_BIT_MASK(32));
  2578. if (err) {
  2579. dev_err(&pdev->dev, "No usable DMA "
  2580. "configuration, aborting\n");
  2581. goto err_dma;
  2582. }
  2583. }
  2584. pci_using_dac = 0;
  2585. }
  2586. err = pci_request_regions(pdev, ixgbevf_driver_name);
  2587. if (err) {
  2588. dev_err(&pdev->dev, "pci_request_regions failed 0x%x\n", err);
  2589. goto err_pci_reg;
  2590. }
  2591. pci_set_master(pdev);
  2592. netdev = alloc_etherdev_mq(sizeof(struct ixgbevf_adapter),
  2593. MAX_TX_QUEUES);
  2594. if (!netdev) {
  2595. err = -ENOMEM;
  2596. goto err_alloc_etherdev;
  2597. }
  2598. SET_NETDEV_DEV(netdev, &pdev->dev);
  2599. pci_set_drvdata(pdev, netdev);
  2600. adapter = netdev_priv(netdev);
  2601. adapter->netdev = netdev;
  2602. adapter->pdev = pdev;
  2603. hw = &adapter->hw;
  2604. hw->back = adapter;
  2605. adapter->msg_enable = netif_msg_init(debug, DEFAULT_MSG_ENABLE);
  2606. /*
  2607. * call save state here in standalone driver because it relies on
  2608. * adapter struct to exist, and needs to call netdev_priv
  2609. */
  2610. pci_save_state(pdev);
  2611. hw->hw_addr = ioremap(pci_resource_start(pdev, 0),
  2612. pci_resource_len(pdev, 0));
  2613. if (!hw->hw_addr) {
  2614. err = -EIO;
  2615. goto err_ioremap;
  2616. }
  2617. ixgbevf_assign_netdev_ops(netdev);
  2618. adapter->bd_number = cards_found;
  2619. /* Setup hw api */
  2620. memcpy(&hw->mac.ops, ii->mac_ops, sizeof(hw->mac.ops));
  2621. hw->mac.type = ii->mac;
  2622. memcpy(&hw->mbx.ops, &ixgbevf_mbx_ops,
  2623. sizeof(struct ixgbe_mbx_operations));
  2624. /* setup the private structure */
  2625. err = ixgbevf_sw_init(adapter);
  2626. if (err)
  2627. goto err_sw_init;
  2628. /* The HW MAC address was set and/or determined in sw_init */
  2629. memcpy(netdev->perm_addr, adapter->hw.mac.addr, netdev->addr_len);
  2630. if (!is_valid_ether_addr(netdev->dev_addr)) {
  2631. pr_err("invalid MAC address\n");
  2632. err = -EIO;
  2633. goto err_sw_init;
  2634. }
  2635. netdev->hw_features = NETIF_F_SG |
  2636. NETIF_F_IP_CSUM |
  2637. NETIF_F_IPV6_CSUM |
  2638. NETIF_F_TSO |
  2639. NETIF_F_TSO6 |
  2640. NETIF_F_RXCSUM;
  2641. netdev->features = netdev->hw_features |
  2642. NETIF_F_HW_VLAN_TX |
  2643. NETIF_F_HW_VLAN_RX |
  2644. NETIF_F_HW_VLAN_FILTER;
  2645. netdev->vlan_features |= NETIF_F_TSO;
  2646. netdev->vlan_features |= NETIF_F_TSO6;
  2647. netdev->vlan_features |= NETIF_F_IP_CSUM;
  2648. netdev->vlan_features |= NETIF_F_IPV6_CSUM;
  2649. netdev->vlan_features |= NETIF_F_SG;
  2650. if (pci_using_dac)
  2651. netdev->features |= NETIF_F_HIGHDMA;
  2652. netdev->priv_flags |= IFF_UNICAST_FLT;
  2653. init_timer(&adapter->watchdog_timer);
  2654. adapter->watchdog_timer.function = ixgbevf_watchdog;
  2655. adapter->watchdog_timer.data = (unsigned long)adapter;
  2656. INIT_WORK(&adapter->reset_task, ixgbevf_reset_task);
  2657. INIT_WORK(&adapter->watchdog_task, ixgbevf_watchdog_task);
  2658. err = ixgbevf_init_interrupt_scheme(adapter);
  2659. if (err)
  2660. goto err_sw_init;
  2661. /* pick up the PCI bus settings for reporting later */
  2662. if (hw->mac.ops.get_bus_info)
  2663. hw->mac.ops.get_bus_info(hw);
  2664. strcpy(netdev->name, "eth%d");
  2665. err = register_netdev(netdev);
  2666. if (err)
  2667. goto err_register;
  2668. netif_carrier_off(netdev);
  2669. ixgbevf_init_last_counter_stats(adapter);
  2670. /* print the MAC address */
  2671. hw_dbg(hw, "%pM\n", netdev->dev_addr);
  2672. hw_dbg(hw, "MAC: %d\n", hw->mac.type);
  2673. hw_dbg(hw, "Intel(R) 82599 Virtual Function\n");
  2674. cards_found++;
  2675. return 0;
  2676. err_register:
  2677. ixgbevf_clear_interrupt_scheme(adapter);
  2678. err_sw_init:
  2679. ixgbevf_reset_interrupt_capability(adapter);
  2680. iounmap(hw->hw_addr);
  2681. err_ioremap:
  2682. free_netdev(netdev);
  2683. err_alloc_etherdev:
  2684. pci_release_regions(pdev);
  2685. err_pci_reg:
  2686. err_dma:
  2687. pci_disable_device(pdev);
  2688. return err;
  2689. }
  2690. /**
  2691. * ixgbevf_remove - Device Removal Routine
  2692. * @pdev: PCI device information struct
  2693. *
  2694. * ixgbevf_remove is called by the PCI subsystem to alert the driver
  2695. * that it should release a PCI device. The could be caused by a
  2696. * Hot-Plug event, or because the driver is going to be removed from
  2697. * memory.
  2698. **/
  2699. static void __devexit ixgbevf_remove(struct pci_dev *pdev)
  2700. {
  2701. struct net_device *netdev = pci_get_drvdata(pdev);
  2702. struct ixgbevf_adapter *adapter = netdev_priv(netdev);
  2703. set_bit(__IXGBEVF_DOWN, &adapter->state);
  2704. del_timer_sync(&adapter->watchdog_timer);
  2705. cancel_work_sync(&adapter->reset_task);
  2706. cancel_work_sync(&adapter->watchdog_task);
  2707. if (netdev->reg_state == NETREG_REGISTERED)
  2708. unregister_netdev(netdev);
  2709. ixgbevf_clear_interrupt_scheme(adapter);
  2710. ixgbevf_reset_interrupt_capability(adapter);
  2711. iounmap(adapter->hw.hw_addr);
  2712. pci_release_regions(pdev);
  2713. hw_dbg(&adapter->hw, "Remove complete\n");
  2714. kfree(adapter->tx_ring);
  2715. kfree(adapter->rx_ring);
  2716. free_netdev(netdev);
  2717. pci_disable_device(pdev);
  2718. }
  2719. /**
  2720. * ixgbevf_io_error_detected - called when PCI error is detected
  2721. * @pdev: Pointer to PCI device
  2722. * @state: The current pci connection state
  2723. *
  2724. * This function is called after a PCI bus error affecting
  2725. * this device has been detected.
  2726. */
  2727. static pci_ers_result_t ixgbevf_io_error_detected(struct pci_dev *pdev,
  2728. pci_channel_state_t state)
  2729. {
  2730. struct net_device *netdev = pci_get_drvdata(pdev);
  2731. struct ixgbevf_adapter *adapter = netdev_priv(netdev);
  2732. netif_device_detach(netdev);
  2733. if (state == pci_channel_io_perm_failure)
  2734. return PCI_ERS_RESULT_DISCONNECT;
  2735. if (netif_running(netdev))
  2736. ixgbevf_down(adapter);
  2737. pci_disable_device(pdev);
  2738. /* Request a slot slot reset. */
  2739. return PCI_ERS_RESULT_NEED_RESET;
  2740. }
  2741. /**
  2742. * ixgbevf_io_slot_reset - called after the pci bus has been reset.
  2743. * @pdev: Pointer to PCI device
  2744. *
  2745. * Restart the card from scratch, as if from a cold-boot. Implementation
  2746. * resembles the first-half of the ixgbevf_resume routine.
  2747. */
  2748. static pci_ers_result_t ixgbevf_io_slot_reset(struct pci_dev *pdev)
  2749. {
  2750. struct net_device *netdev = pci_get_drvdata(pdev);
  2751. struct ixgbevf_adapter *adapter = netdev_priv(netdev);
  2752. if (pci_enable_device_mem(pdev)) {
  2753. dev_err(&pdev->dev,
  2754. "Cannot re-enable PCI device after reset.\n");
  2755. return PCI_ERS_RESULT_DISCONNECT;
  2756. }
  2757. pci_set_master(pdev);
  2758. ixgbevf_reset(adapter);
  2759. return PCI_ERS_RESULT_RECOVERED;
  2760. }
  2761. /**
  2762. * ixgbevf_io_resume - called when traffic can start flowing again.
  2763. * @pdev: Pointer to PCI device
  2764. *
  2765. * This callback is called when the error recovery driver tells us that
  2766. * its OK to resume normal operation. Implementation resembles the
  2767. * second-half of the ixgbevf_resume routine.
  2768. */
  2769. static void ixgbevf_io_resume(struct pci_dev *pdev)
  2770. {
  2771. struct net_device *netdev = pci_get_drvdata(pdev);
  2772. struct ixgbevf_adapter *adapter = netdev_priv(netdev);
  2773. if (netif_running(netdev))
  2774. ixgbevf_up(adapter);
  2775. netif_device_attach(netdev);
  2776. }
  2777. /* PCI Error Recovery (ERS) */
  2778. static struct pci_error_handlers ixgbevf_err_handler = {
  2779. .error_detected = ixgbevf_io_error_detected,
  2780. .slot_reset = ixgbevf_io_slot_reset,
  2781. .resume = ixgbevf_io_resume,
  2782. };
  2783. static struct pci_driver ixgbevf_driver = {
  2784. .name = ixgbevf_driver_name,
  2785. .id_table = ixgbevf_pci_tbl,
  2786. .probe = ixgbevf_probe,
  2787. .remove = __devexit_p(ixgbevf_remove),
  2788. #ifdef CONFIG_PM
  2789. /* Power Management Hooks */
  2790. .suspend = ixgbevf_suspend,
  2791. .resume = ixgbevf_resume,
  2792. #endif
  2793. .shutdown = ixgbevf_shutdown,
  2794. .err_handler = &ixgbevf_err_handler
  2795. };
  2796. /**
  2797. * ixgbevf_init_module - Driver Registration Routine
  2798. *
  2799. * ixgbevf_init_module is the first routine called when the driver is
  2800. * loaded. All it does is register with the PCI subsystem.
  2801. **/
  2802. static int __init ixgbevf_init_module(void)
  2803. {
  2804. int ret;
  2805. pr_info("%s - version %s\n", ixgbevf_driver_string,
  2806. ixgbevf_driver_version);
  2807. pr_info("%s\n", ixgbevf_copyright);
  2808. ret = pci_register_driver(&ixgbevf_driver);
  2809. return ret;
  2810. }
  2811. module_init(ixgbevf_init_module);
  2812. /**
  2813. * ixgbevf_exit_module - Driver Exit Cleanup Routine
  2814. *
  2815. * ixgbevf_exit_module is called just before the driver is removed
  2816. * from memory.
  2817. **/
  2818. static void __exit ixgbevf_exit_module(void)
  2819. {
  2820. pci_unregister_driver(&ixgbevf_driver);
  2821. }
  2822. #ifdef DEBUG
  2823. /**
  2824. * ixgbevf_get_hw_dev_name - return device name string
  2825. * used by hardware layer to print debugging information
  2826. **/
  2827. char *ixgbevf_get_hw_dev_name(struct ixgbe_hw *hw)
  2828. {
  2829. struct ixgbevf_adapter *adapter = hw->back;
  2830. return adapter->netdev->name;
  2831. }
  2832. #endif
  2833. module_exit(ixgbevf_exit_module);
  2834. /* ixgbevf_main.c */