bnx2x_cmn.c 92 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593
  1. /* bnx2x_cmn.c: Broadcom Everest network driver.
  2. *
  3. * Copyright (c) 2007-2011 Broadcom Corporation
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation.
  8. *
  9. * Maintained by: Eilon Greenstein <eilong@broadcom.com>
  10. * Written by: Eliezer Tamir
  11. * Based on code from Michael Chan's bnx2 driver
  12. * UDP CSUM errata workaround by Arik Gendelman
  13. * Slowpath and fastpath rework by Vladislav Zolotarov
  14. * Statistics and Link management by Yitchak Gertner
  15. *
  16. */
  17. #include <linux/etherdevice.h>
  18. #include <linux/if_vlan.h>
  19. #include <linux/interrupt.h>
  20. #include <linux/ip.h>
  21. #include <net/ipv6.h>
  22. #include <net/ip6_checksum.h>
  23. #include <linux/firmware.h>
  24. #include <linux/prefetch.h>
  25. #include "bnx2x_cmn.h"
  26. #include "bnx2x_init.h"
  27. #include "bnx2x_sp.h"
  28. /**
  29. * bnx2x_bz_fp - zero content of the fastpath structure.
  30. *
  31. * @bp: driver handle
  32. * @index: fastpath index to be zeroed
  33. *
  34. * Makes sure the contents of the bp->fp[index].napi is kept
  35. * intact.
  36. */
  37. static inline void bnx2x_bz_fp(struct bnx2x *bp, int index)
  38. {
  39. struct bnx2x_fastpath *fp = &bp->fp[index];
  40. struct napi_struct orig_napi = fp->napi;
  41. /* bzero bnx2x_fastpath contents */
  42. memset(fp, 0, sizeof(*fp));
  43. /* Restore the NAPI object as it has been already initialized */
  44. fp->napi = orig_napi;
  45. fp->bp = bp;
  46. fp->index = index;
  47. if (IS_ETH_FP(fp))
  48. fp->max_cos = bp->max_cos;
  49. else
  50. /* Special queues support only one CoS */
  51. fp->max_cos = 1;
  52. /*
  53. * set the tpa flag for each queue. The tpa flag determines the queue
  54. * minimal size so it must be set prior to queue memory allocation
  55. */
  56. fp->disable_tpa = ((bp->flags & TPA_ENABLE_FLAG) == 0);
  57. #ifdef BCM_CNIC
  58. /* We don't want TPA on an FCoE L2 ring */
  59. if (IS_FCOE_FP(fp))
  60. fp->disable_tpa = 1;
  61. #endif
  62. }
  63. /**
  64. * bnx2x_move_fp - move content of the fastpath structure.
  65. *
  66. * @bp: driver handle
  67. * @from: source FP index
  68. * @to: destination FP index
  69. *
  70. * Makes sure the contents of the bp->fp[to].napi is kept
  71. * intact.
  72. */
  73. static inline void bnx2x_move_fp(struct bnx2x *bp, int from, int to)
  74. {
  75. struct bnx2x_fastpath *from_fp = &bp->fp[from];
  76. struct bnx2x_fastpath *to_fp = &bp->fp[to];
  77. struct napi_struct orig_napi = to_fp->napi;
  78. /* Move bnx2x_fastpath contents */
  79. memcpy(to_fp, from_fp, sizeof(*to_fp));
  80. to_fp->index = to;
  81. /* Restore the NAPI object as it has been already initialized */
  82. to_fp->napi = orig_napi;
  83. }
  84. int load_count[2][3] = { {0} }; /* per-path: 0-common, 1-port0, 2-port1 */
  85. /* free skb in the packet ring at pos idx
  86. * return idx of last bd freed
  87. */
  88. static u16 bnx2x_free_tx_pkt(struct bnx2x *bp, struct bnx2x_fp_txdata *txdata,
  89. u16 idx)
  90. {
  91. struct sw_tx_bd *tx_buf = &txdata->tx_buf_ring[idx];
  92. struct eth_tx_start_bd *tx_start_bd;
  93. struct eth_tx_bd *tx_data_bd;
  94. struct sk_buff *skb = tx_buf->skb;
  95. u16 bd_idx = TX_BD(tx_buf->first_bd), new_cons;
  96. int nbd;
  97. /* prefetch skb end pointer to speedup dev_kfree_skb() */
  98. prefetch(&skb->end);
  99. DP(BNX2X_MSG_FP, "fp[%d]: pkt_idx %d buff @(%p)->skb %p\n",
  100. txdata->txq_index, idx, tx_buf, skb);
  101. /* unmap first bd */
  102. DP(BNX2X_MSG_OFF, "free bd_idx %d\n", bd_idx);
  103. tx_start_bd = &txdata->tx_desc_ring[bd_idx].start_bd;
  104. dma_unmap_single(&bp->pdev->dev, BD_UNMAP_ADDR(tx_start_bd),
  105. BD_UNMAP_LEN(tx_start_bd), DMA_TO_DEVICE);
  106. nbd = le16_to_cpu(tx_start_bd->nbd) - 1;
  107. #ifdef BNX2X_STOP_ON_ERROR
  108. if ((nbd - 1) > (MAX_SKB_FRAGS + 2)) {
  109. BNX2X_ERR("BAD nbd!\n");
  110. bnx2x_panic();
  111. }
  112. #endif
  113. new_cons = nbd + tx_buf->first_bd;
  114. /* Get the next bd */
  115. bd_idx = TX_BD(NEXT_TX_IDX(bd_idx));
  116. /* Skip a parse bd... */
  117. --nbd;
  118. bd_idx = TX_BD(NEXT_TX_IDX(bd_idx));
  119. /* ...and the TSO split header bd since they have no mapping */
  120. if (tx_buf->flags & BNX2X_TSO_SPLIT_BD) {
  121. --nbd;
  122. bd_idx = TX_BD(NEXT_TX_IDX(bd_idx));
  123. }
  124. /* now free frags */
  125. while (nbd > 0) {
  126. DP(BNX2X_MSG_OFF, "free frag bd_idx %d\n", bd_idx);
  127. tx_data_bd = &txdata->tx_desc_ring[bd_idx].reg_bd;
  128. dma_unmap_page(&bp->pdev->dev, BD_UNMAP_ADDR(tx_data_bd),
  129. BD_UNMAP_LEN(tx_data_bd), DMA_TO_DEVICE);
  130. if (--nbd)
  131. bd_idx = TX_BD(NEXT_TX_IDX(bd_idx));
  132. }
  133. /* release skb */
  134. WARN_ON(!skb);
  135. dev_kfree_skb_any(skb);
  136. tx_buf->first_bd = 0;
  137. tx_buf->skb = NULL;
  138. return new_cons;
  139. }
  140. int bnx2x_tx_int(struct bnx2x *bp, struct bnx2x_fp_txdata *txdata)
  141. {
  142. struct netdev_queue *txq;
  143. u16 hw_cons, sw_cons, bd_cons = txdata->tx_bd_cons;
  144. #ifdef BNX2X_STOP_ON_ERROR
  145. if (unlikely(bp->panic))
  146. return -1;
  147. #endif
  148. txq = netdev_get_tx_queue(bp->dev, txdata->txq_index);
  149. hw_cons = le16_to_cpu(*txdata->tx_cons_sb);
  150. sw_cons = txdata->tx_pkt_cons;
  151. while (sw_cons != hw_cons) {
  152. u16 pkt_cons;
  153. pkt_cons = TX_BD(sw_cons);
  154. DP(NETIF_MSG_TX_DONE, "queue[%d]: hw_cons %u sw_cons %u "
  155. " pkt_cons %u\n",
  156. txdata->txq_index, hw_cons, sw_cons, pkt_cons);
  157. bd_cons = bnx2x_free_tx_pkt(bp, txdata, pkt_cons);
  158. sw_cons++;
  159. }
  160. txdata->tx_pkt_cons = sw_cons;
  161. txdata->tx_bd_cons = bd_cons;
  162. /* Need to make the tx_bd_cons update visible to start_xmit()
  163. * before checking for netif_tx_queue_stopped(). Without the
  164. * memory barrier, there is a small possibility that
  165. * start_xmit() will miss it and cause the queue to be stopped
  166. * forever.
  167. * On the other hand we need an rmb() here to ensure the proper
  168. * ordering of bit testing in the following
  169. * netif_tx_queue_stopped(txq) call.
  170. */
  171. smp_mb();
  172. if (unlikely(netif_tx_queue_stopped(txq))) {
  173. /* Taking tx_lock() is needed to prevent reenabling the queue
  174. * while it's empty. This could have happen if rx_action() gets
  175. * suspended in bnx2x_tx_int() after the condition before
  176. * netif_tx_wake_queue(), while tx_action (bnx2x_start_xmit()):
  177. *
  178. * stops the queue->sees fresh tx_bd_cons->releases the queue->
  179. * sends some packets consuming the whole queue again->
  180. * stops the queue
  181. */
  182. __netif_tx_lock(txq, smp_processor_id());
  183. if ((netif_tx_queue_stopped(txq)) &&
  184. (bp->state == BNX2X_STATE_OPEN) &&
  185. (bnx2x_tx_avail(bp, txdata) >= MAX_SKB_FRAGS + 3))
  186. netif_tx_wake_queue(txq);
  187. __netif_tx_unlock(txq);
  188. }
  189. return 0;
  190. }
  191. static inline void bnx2x_update_last_max_sge(struct bnx2x_fastpath *fp,
  192. u16 idx)
  193. {
  194. u16 last_max = fp->last_max_sge;
  195. if (SUB_S16(idx, last_max) > 0)
  196. fp->last_max_sge = idx;
  197. }
  198. static void bnx2x_update_sge_prod(struct bnx2x_fastpath *fp,
  199. struct eth_fast_path_rx_cqe *fp_cqe)
  200. {
  201. struct bnx2x *bp = fp->bp;
  202. u16 sge_len = SGE_PAGE_ALIGN(le16_to_cpu(fp_cqe->pkt_len) -
  203. le16_to_cpu(fp_cqe->len_on_bd)) >>
  204. SGE_PAGE_SHIFT;
  205. u16 last_max, last_elem, first_elem;
  206. u16 delta = 0;
  207. u16 i;
  208. if (!sge_len)
  209. return;
  210. /* First mark all used pages */
  211. for (i = 0; i < sge_len; i++)
  212. BIT_VEC64_CLEAR_BIT(fp->sge_mask,
  213. RX_SGE(le16_to_cpu(fp_cqe->sgl_or_raw_data.sgl[i])));
  214. DP(NETIF_MSG_RX_STATUS, "fp_cqe->sgl[%d] = %d\n",
  215. sge_len - 1, le16_to_cpu(fp_cqe->sgl_or_raw_data.sgl[sge_len - 1]));
  216. /* Here we assume that the last SGE index is the biggest */
  217. prefetch((void *)(fp->sge_mask));
  218. bnx2x_update_last_max_sge(fp,
  219. le16_to_cpu(fp_cqe->sgl_or_raw_data.sgl[sge_len - 1]));
  220. last_max = RX_SGE(fp->last_max_sge);
  221. last_elem = last_max >> BIT_VEC64_ELEM_SHIFT;
  222. first_elem = RX_SGE(fp->rx_sge_prod) >> BIT_VEC64_ELEM_SHIFT;
  223. /* If ring is not full */
  224. if (last_elem + 1 != first_elem)
  225. last_elem++;
  226. /* Now update the prod */
  227. for (i = first_elem; i != last_elem; i = NEXT_SGE_MASK_ELEM(i)) {
  228. if (likely(fp->sge_mask[i]))
  229. break;
  230. fp->sge_mask[i] = BIT_VEC64_ELEM_ONE_MASK;
  231. delta += BIT_VEC64_ELEM_SZ;
  232. }
  233. if (delta > 0) {
  234. fp->rx_sge_prod += delta;
  235. /* clear page-end entries */
  236. bnx2x_clear_sge_mask_next_elems(fp);
  237. }
  238. DP(NETIF_MSG_RX_STATUS,
  239. "fp->last_max_sge = %d fp->rx_sge_prod = %d\n",
  240. fp->last_max_sge, fp->rx_sge_prod);
  241. }
  242. static void bnx2x_tpa_start(struct bnx2x_fastpath *fp, u16 queue,
  243. struct sk_buff *skb, u16 cons, u16 prod,
  244. struct eth_fast_path_rx_cqe *cqe)
  245. {
  246. struct bnx2x *bp = fp->bp;
  247. struct sw_rx_bd *cons_rx_buf = &fp->rx_buf_ring[cons];
  248. struct sw_rx_bd *prod_rx_buf = &fp->rx_buf_ring[prod];
  249. struct eth_rx_bd *prod_bd = &fp->rx_desc_ring[prod];
  250. dma_addr_t mapping;
  251. struct bnx2x_agg_info *tpa_info = &fp->tpa_info[queue];
  252. struct sw_rx_bd *first_buf = &tpa_info->first_buf;
  253. /* print error if current state != stop */
  254. if (tpa_info->tpa_state != BNX2X_TPA_STOP)
  255. BNX2X_ERR("start of bin not in stop [%d]\n", queue);
  256. /* Try to map an empty skb from the aggregation info */
  257. mapping = dma_map_single(&bp->pdev->dev,
  258. first_buf->skb->data,
  259. fp->rx_buf_size, DMA_FROM_DEVICE);
  260. /*
  261. * ...if it fails - move the skb from the consumer to the producer
  262. * and set the current aggregation state as ERROR to drop it
  263. * when TPA_STOP arrives.
  264. */
  265. if (unlikely(dma_mapping_error(&bp->pdev->dev, mapping))) {
  266. /* Move the BD from the consumer to the producer */
  267. bnx2x_reuse_rx_skb(fp, cons, prod);
  268. tpa_info->tpa_state = BNX2X_TPA_ERROR;
  269. return;
  270. }
  271. /* move empty skb from pool to prod */
  272. prod_rx_buf->skb = first_buf->skb;
  273. dma_unmap_addr_set(prod_rx_buf, mapping, mapping);
  274. /* point prod_bd to new skb */
  275. prod_bd->addr_hi = cpu_to_le32(U64_HI(mapping));
  276. prod_bd->addr_lo = cpu_to_le32(U64_LO(mapping));
  277. /* move partial skb from cons to pool (don't unmap yet) */
  278. *first_buf = *cons_rx_buf;
  279. /* mark bin state as START */
  280. tpa_info->parsing_flags =
  281. le16_to_cpu(cqe->pars_flags.flags);
  282. tpa_info->vlan_tag = le16_to_cpu(cqe->vlan_tag);
  283. tpa_info->tpa_state = BNX2X_TPA_START;
  284. tpa_info->len_on_bd = le16_to_cpu(cqe->len_on_bd);
  285. tpa_info->placement_offset = cqe->placement_offset;
  286. #ifdef BNX2X_STOP_ON_ERROR
  287. fp->tpa_queue_used |= (1 << queue);
  288. #ifdef _ASM_GENERIC_INT_L64_H
  289. DP(NETIF_MSG_RX_STATUS, "fp->tpa_queue_used = 0x%lx\n",
  290. #else
  291. DP(NETIF_MSG_RX_STATUS, "fp->tpa_queue_used = 0x%llx\n",
  292. #endif
  293. fp->tpa_queue_used);
  294. #endif
  295. }
  296. /* Timestamp option length allowed for TPA aggregation:
  297. *
  298. * nop nop kind length echo val
  299. */
  300. #define TPA_TSTAMP_OPT_LEN 12
  301. /**
  302. * bnx2x_set_lro_mss - calculate the approximate value of the MSS
  303. *
  304. * @bp: driver handle
  305. * @parsing_flags: parsing flags from the START CQE
  306. * @len_on_bd: total length of the first packet for the
  307. * aggregation.
  308. *
  309. * Approximate value of the MSS for this aggregation calculated using
  310. * the first packet of it.
  311. */
  312. static inline u16 bnx2x_set_lro_mss(struct bnx2x *bp, u16 parsing_flags,
  313. u16 len_on_bd)
  314. {
  315. /*
  316. * TPA arrgregation won't have either IP options or TCP options
  317. * other than timestamp or IPv6 extension headers.
  318. */
  319. u16 hdrs_len = ETH_HLEN + sizeof(struct tcphdr);
  320. if (GET_FLAG(parsing_flags, PARSING_FLAGS_OVER_ETHERNET_PROTOCOL) ==
  321. PRS_FLAG_OVERETH_IPV6)
  322. hdrs_len += sizeof(struct ipv6hdr);
  323. else /* IPv4 */
  324. hdrs_len += sizeof(struct iphdr);
  325. /* Check if there was a TCP timestamp, if there is it's will
  326. * always be 12 bytes length: nop nop kind length echo val.
  327. *
  328. * Otherwise FW would close the aggregation.
  329. */
  330. if (parsing_flags & PARSING_FLAGS_TIME_STAMP_EXIST_FLAG)
  331. hdrs_len += TPA_TSTAMP_OPT_LEN;
  332. return len_on_bd - hdrs_len;
  333. }
  334. static int bnx2x_fill_frag_skb(struct bnx2x *bp, struct bnx2x_fastpath *fp,
  335. u16 queue, struct sk_buff *skb,
  336. struct eth_end_agg_rx_cqe *cqe,
  337. u16 cqe_idx)
  338. {
  339. struct sw_rx_page *rx_pg, old_rx_pg;
  340. u32 i, frag_len, frag_size, pages;
  341. int err;
  342. int j;
  343. struct bnx2x_agg_info *tpa_info = &fp->tpa_info[queue];
  344. u16 len_on_bd = tpa_info->len_on_bd;
  345. frag_size = le16_to_cpu(cqe->pkt_len) - len_on_bd;
  346. pages = SGE_PAGE_ALIGN(frag_size) >> SGE_PAGE_SHIFT;
  347. /* This is needed in order to enable forwarding support */
  348. if (frag_size)
  349. skb_shinfo(skb)->gso_size = bnx2x_set_lro_mss(bp,
  350. tpa_info->parsing_flags, len_on_bd);
  351. #ifdef BNX2X_STOP_ON_ERROR
  352. if (pages > min_t(u32, 8, MAX_SKB_FRAGS)*SGE_PAGE_SIZE*PAGES_PER_SGE) {
  353. BNX2X_ERR("SGL length is too long: %d. CQE index is %d\n",
  354. pages, cqe_idx);
  355. BNX2X_ERR("cqe->pkt_len = %d\n", cqe->pkt_len);
  356. bnx2x_panic();
  357. return -EINVAL;
  358. }
  359. #endif
  360. /* Run through the SGL and compose the fragmented skb */
  361. for (i = 0, j = 0; i < pages; i += PAGES_PER_SGE, j++) {
  362. u16 sge_idx = RX_SGE(le16_to_cpu(cqe->sgl_or_raw_data.sgl[j]));
  363. /* FW gives the indices of the SGE as if the ring is an array
  364. (meaning that "next" element will consume 2 indices) */
  365. frag_len = min(frag_size, (u32)(SGE_PAGE_SIZE*PAGES_PER_SGE));
  366. rx_pg = &fp->rx_page_ring[sge_idx];
  367. old_rx_pg = *rx_pg;
  368. /* If we fail to allocate a substitute page, we simply stop
  369. where we are and drop the whole packet */
  370. err = bnx2x_alloc_rx_sge(bp, fp, sge_idx);
  371. if (unlikely(err)) {
  372. fp->eth_q_stats.rx_skb_alloc_failed++;
  373. return err;
  374. }
  375. /* Unmap the page as we r going to pass it to the stack */
  376. dma_unmap_page(&bp->pdev->dev,
  377. dma_unmap_addr(&old_rx_pg, mapping),
  378. SGE_PAGE_SIZE*PAGES_PER_SGE, DMA_FROM_DEVICE);
  379. /* Add one frag and update the appropriate fields in the skb */
  380. skb_fill_page_desc(skb, j, old_rx_pg.page, 0, frag_len);
  381. skb->data_len += frag_len;
  382. skb->truesize += frag_len;
  383. skb->len += frag_len;
  384. frag_size -= frag_len;
  385. }
  386. return 0;
  387. }
  388. static void bnx2x_tpa_stop(struct bnx2x *bp, struct bnx2x_fastpath *fp,
  389. u16 queue, struct eth_end_agg_rx_cqe *cqe,
  390. u16 cqe_idx)
  391. {
  392. struct bnx2x_agg_info *tpa_info = &fp->tpa_info[queue];
  393. struct sw_rx_bd *rx_buf = &tpa_info->first_buf;
  394. u8 pad = tpa_info->placement_offset;
  395. u16 len = tpa_info->len_on_bd;
  396. struct sk_buff *skb = rx_buf->skb;
  397. /* alloc new skb */
  398. struct sk_buff *new_skb;
  399. u8 old_tpa_state = tpa_info->tpa_state;
  400. tpa_info->tpa_state = BNX2X_TPA_STOP;
  401. /* If we there was an error during the handling of the TPA_START -
  402. * drop this aggregation.
  403. */
  404. if (old_tpa_state == BNX2X_TPA_ERROR)
  405. goto drop;
  406. /* Try to allocate the new skb */
  407. new_skb = netdev_alloc_skb(bp->dev, fp->rx_buf_size);
  408. /* Unmap skb in the pool anyway, as we are going to change
  409. pool entry status to BNX2X_TPA_STOP even if new skb allocation
  410. fails. */
  411. dma_unmap_single(&bp->pdev->dev, dma_unmap_addr(rx_buf, mapping),
  412. fp->rx_buf_size, DMA_FROM_DEVICE);
  413. if (likely(new_skb)) {
  414. prefetch(skb);
  415. prefetch(((char *)(skb)) + L1_CACHE_BYTES);
  416. #ifdef BNX2X_STOP_ON_ERROR
  417. if (pad + len > fp->rx_buf_size) {
  418. BNX2X_ERR("skb_put is about to fail... "
  419. "pad %d len %d rx_buf_size %d\n",
  420. pad, len, fp->rx_buf_size);
  421. bnx2x_panic();
  422. return;
  423. }
  424. #endif
  425. skb_reserve(skb, pad);
  426. skb_put(skb, len);
  427. skb->protocol = eth_type_trans(skb, bp->dev);
  428. skb->ip_summed = CHECKSUM_UNNECESSARY;
  429. if (!bnx2x_fill_frag_skb(bp, fp, queue, skb, cqe, cqe_idx)) {
  430. if (tpa_info->parsing_flags & PARSING_FLAGS_VLAN)
  431. __vlan_hwaccel_put_tag(skb, tpa_info->vlan_tag);
  432. napi_gro_receive(&fp->napi, skb);
  433. } else {
  434. DP(NETIF_MSG_RX_STATUS, "Failed to allocate new pages"
  435. " - dropping packet!\n");
  436. dev_kfree_skb_any(skb);
  437. }
  438. /* put new skb in bin */
  439. rx_buf->skb = new_skb;
  440. return;
  441. }
  442. drop:
  443. /* drop the packet and keep the buffer in the bin */
  444. DP(NETIF_MSG_RX_STATUS,
  445. "Failed to allocate or map a new skb - dropping packet!\n");
  446. fp->eth_q_stats.rx_skb_alloc_failed++;
  447. }
  448. /* Set Toeplitz hash value in the skb using the value from the
  449. * CQE (calculated by HW).
  450. */
  451. static inline void bnx2x_set_skb_rxhash(struct bnx2x *bp, union eth_rx_cqe *cqe,
  452. struct sk_buff *skb)
  453. {
  454. /* Set Toeplitz hash from CQE */
  455. if ((bp->dev->features & NETIF_F_RXHASH) &&
  456. (cqe->fast_path_cqe.status_flags &
  457. ETH_FAST_PATH_RX_CQE_RSS_HASH_FLG))
  458. skb->rxhash =
  459. le32_to_cpu(cqe->fast_path_cqe.rss_hash_result);
  460. }
  461. int bnx2x_rx_int(struct bnx2x_fastpath *fp, int budget)
  462. {
  463. struct bnx2x *bp = fp->bp;
  464. u16 bd_cons, bd_prod, bd_prod_fw, comp_ring_cons;
  465. u16 hw_comp_cons, sw_comp_cons, sw_comp_prod;
  466. int rx_pkt = 0;
  467. #ifdef BNX2X_STOP_ON_ERROR
  468. if (unlikely(bp->panic))
  469. return 0;
  470. #endif
  471. /* CQ "next element" is of the size of the regular element,
  472. that's why it's ok here */
  473. hw_comp_cons = le16_to_cpu(*fp->rx_cons_sb);
  474. if ((hw_comp_cons & MAX_RCQ_DESC_CNT) == MAX_RCQ_DESC_CNT)
  475. hw_comp_cons++;
  476. bd_cons = fp->rx_bd_cons;
  477. bd_prod = fp->rx_bd_prod;
  478. bd_prod_fw = bd_prod;
  479. sw_comp_cons = fp->rx_comp_cons;
  480. sw_comp_prod = fp->rx_comp_prod;
  481. /* Memory barrier necessary as speculative reads of the rx
  482. * buffer can be ahead of the index in the status block
  483. */
  484. rmb();
  485. DP(NETIF_MSG_RX_STATUS,
  486. "queue[%d]: hw_comp_cons %u sw_comp_cons %u\n",
  487. fp->index, hw_comp_cons, sw_comp_cons);
  488. while (sw_comp_cons != hw_comp_cons) {
  489. struct sw_rx_bd *rx_buf = NULL;
  490. struct sk_buff *skb;
  491. union eth_rx_cqe *cqe;
  492. struct eth_fast_path_rx_cqe *cqe_fp;
  493. u8 cqe_fp_flags;
  494. enum eth_rx_cqe_type cqe_fp_type;
  495. u16 len, pad;
  496. #ifdef BNX2X_STOP_ON_ERROR
  497. if (unlikely(bp->panic))
  498. return 0;
  499. #endif
  500. comp_ring_cons = RCQ_BD(sw_comp_cons);
  501. bd_prod = RX_BD(bd_prod);
  502. bd_cons = RX_BD(bd_cons);
  503. /* Prefetch the page containing the BD descriptor
  504. at producer's index. It will be needed when new skb is
  505. allocated */
  506. prefetch((void *)(PAGE_ALIGN((unsigned long)
  507. (&fp->rx_desc_ring[bd_prod])) -
  508. PAGE_SIZE + 1));
  509. cqe = &fp->rx_comp_ring[comp_ring_cons];
  510. cqe_fp = &cqe->fast_path_cqe;
  511. cqe_fp_flags = cqe_fp->type_error_flags;
  512. cqe_fp_type = cqe_fp_flags & ETH_FAST_PATH_RX_CQE_TYPE;
  513. DP(NETIF_MSG_RX_STATUS, "CQE type %x err %x status %x"
  514. " queue %x vlan %x len %u\n", CQE_TYPE(cqe_fp_flags),
  515. cqe_fp_flags, cqe_fp->status_flags,
  516. le32_to_cpu(cqe_fp->rss_hash_result),
  517. le16_to_cpu(cqe_fp->vlan_tag), le16_to_cpu(cqe_fp->pkt_len));
  518. /* is this a slowpath msg? */
  519. if (unlikely(CQE_TYPE_SLOW(cqe_fp_type))) {
  520. bnx2x_sp_event(fp, cqe);
  521. goto next_cqe;
  522. /* this is an rx packet */
  523. } else {
  524. rx_buf = &fp->rx_buf_ring[bd_cons];
  525. skb = rx_buf->skb;
  526. prefetch(skb);
  527. if (!CQE_TYPE_FAST(cqe_fp_type)) {
  528. #ifdef BNX2X_STOP_ON_ERROR
  529. /* sanity check */
  530. if (fp->disable_tpa &&
  531. (CQE_TYPE_START(cqe_fp_type) ||
  532. CQE_TYPE_STOP(cqe_fp_type)))
  533. BNX2X_ERR("START/STOP packet while "
  534. "disable_tpa type %x\n",
  535. CQE_TYPE(cqe_fp_type));
  536. #endif
  537. if (CQE_TYPE_START(cqe_fp_type)) {
  538. u16 queue = cqe_fp->queue_index;
  539. DP(NETIF_MSG_RX_STATUS,
  540. "calling tpa_start on queue %d\n",
  541. queue);
  542. bnx2x_tpa_start(fp, queue, skb,
  543. bd_cons, bd_prod,
  544. cqe_fp);
  545. /* Set Toeplitz hash for LRO skb */
  546. bnx2x_set_skb_rxhash(bp, cqe, skb);
  547. goto next_rx;
  548. } else {
  549. u16 queue =
  550. cqe->end_agg_cqe.queue_index;
  551. DP(NETIF_MSG_RX_STATUS,
  552. "calling tpa_stop on queue %d\n",
  553. queue);
  554. bnx2x_tpa_stop(bp, fp, queue,
  555. &cqe->end_agg_cqe,
  556. comp_ring_cons);
  557. #ifdef BNX2X_STOP_ON_ERROR
  558. if (bp->panic)
  559. return 0;
  560. #endif
  561. bnx2x_update_sge_prod(fp, cqe_fp);
  562. goto next_cqe;
  563. }
  564. }
  565. /* non TPA */
  566. len = le16_to_cpu(cqe_fp->pkt_len);
  567. pad = cqe_fp->placement_offset;
  568. dma_sync_single_for_cpu(&bp->pdev->dev,
  569. dma_unmap_addr(rx_buf, mapping),
  570. pad + RX_COPY_THRESH,
  571. DMA_FROM_DEVICE);
  572. prefetch(((char *)(skb)) + L1_CACHE_BYTES);
  573. /* is this an error packet? */
  574. if (unlikely(cqe_fp_flags & ETH_RX_ERROR_FALGS)) {
  575. DP(NETIF_MSG_RX_ERR,
  576. "ERROR flags %x rx packet %u\n",
  577. cqe_fp_flags, sw_comp_cons);
  578. fp->eth_q_stats.rx_err_discard_pkt++;
  579. goto reuse_rx;
  580. }
  581. /* Since we don't have a jumbo ring
  582. * copy small packets if mtu > 1500
  583. */
  584. if ((bp->dev->mtu > ETH_MAX_PACKET_SIZE) &&
  585. (len <= RX_COPY_THRESH)) {
  586. struct sk_buff *new_skb;
  587. new_skb = netdev_alloc_skb(bp->dev, len + pad);
  588. if (new_skb == NULL) {
  589. DP(NETIF_MSG_RX_ERR,
  590. "ERROR packet dropped "
  591. "because of alloc failure\n");
  592. fp->eth_q_stats.rx_skb_alloc_failed++;
  593. goto reuse_rx;
  594. }
  595. /* aligned copy */
  596. skb_copy_from_linear_data_offset(skb, pad,
  597. new_skb->data + pad, len);
  598. skb_reserve(new_skb, pad);
  599. skb_put(new_skb, len);
  600. bnx2x_reuse_rx_skb(fp, bd_cons, bd_prod);
  601. skb = new_skb;
  602. } else
  603. if (likely(bnx2x_alloc_rx_skb(bp, fp, bd_prod) == 0)) {
  604. dma_unmap_single(&bp->pdev->dev,
  605. dma_unmap_addr(rx_buf, mapping),
  606. fp->rx_buf_size,
  607. DMA_FROM_DEVICE);
  608. skb_reserve(skb, pad);
  609. skb_put(skb, len);
  610. } else {
  611. DP(NETIF_MSG_RX_ERR,
  612. "ERROR packet dropped because "
  613. "of alloc failure\n");
  614. fp->eth_q_stats.rx_skb_alloc_failed++;
  615. reuse_rx:
  616. bnx2x_reuse_rx_skb(fp, bd_cons, bd_prod);
  617. goto next_rx;
  618. }
  619. skb->protocol = eth_type_trans(skb, bp->dev);
  620. /* Set Toeplitz hash for a none-LRO skb */
  621. bnx2x_set_skb_rxhash(bp, cqe, skb);
  622. skb_checksum_none_assert(skb);
  623. if (bp->dev->features & NETIF_F_RXCSUM) {
  624. if (likely(BNX2X_RX_CSUM_OK(cqe)))
  625. skb->ip_summed = CHECKSUM_UNNECESSARY;
  626. else
  627. fp->eth_q_stats.hw_csum_err++;
  628. }
  629. }
  630. skb_record_rx_queue(skb, fp->index);
  631. if (le16_to_cpu(cqe_fp->pars_flags.flags) &
  632. PARSING_FLAGS_VLAN)
  633. __vlan_hwaccel_put_tag(skb,
  634. le16_to_cpu(cqe_fp->vlan_tag));
  635. napi_gro_receive(&fp->napi, skb);
  636. next_rx:
  637. rx_buf->skb = NULL;
  638. bd_cons = NEXT_RX_IDX(bd_cons);
  639. bd_prod = NEXT_RX_IDX(bd_prod);
  640. bd_prod_fw = NEXT_RX_IDX(bd_prod_fw);
  641. rx_pkt++;
  642. next_cqe:
  643. sw_comp_prod = NEXT_RCQ_IDX(sw_comp_prod);
  644. sw_comp_cons = NEXT_RCQ_IDX(sw_comp_cons);
  645. if (rx_pkt == budget)
  646. break;
  647. } /* while */
  648. fp->rx_bd_cons = bd_cons;
  649. fp->rx_bd_prod = bd_prod_fw;
  650. fp->rx_comp_cons = sw_comp_cons;
  651. fp->rx_comp_prod = sw_comp_prod;
  652. /* Update producers */
  653. bnx2x_update_rx_prod(bp, fp, bd_prod_fw, sw_comp_prod,
  654. fp->rx_sge_prod);
  655. fp->rx_pkt += rx_pkt;
  656. fp->rx_calls++;
  657. return rx_pkt;
  658. }
  659. static irqreturn_t bnx2x_msix_fp_int(int irq, void *fp_cookie)
  660. {
  661. struct bnx2x_fastpath *fp = fp_cookie;
  662. struct bnx2x *bp = fp->bp;
  663. u8 cos;
  664. DP(BNX2X_MSG_FP, "got an MSI-X interrupt on IDX:SB "
  665. "[fp %d fw_sd %d igusb %d]\n",
  666. fp->index, fp->fw_sb_id, fp->igu_sb_id);
  667. bnx2x_ack_sb(bp, fp->igu_sb_id, USTORM_ID, 0, IGU_INT_DISABLE, 0);
  668. #ifdef BNX2X_STOP_ON_ERROR
  669. if (unlikely(bp->panic))
  670. return IRQ_HANDLED;
  671. #endif
  672. /* Handle Rx and Tx according to MSI-X vector */
  673. prefetch(fp->rx_cons_sb);
  674. for_each_cos_in_tx_queue(fp, cos)
  675. prefetch(fp->txdata[cos].tx_cons_sb);
  676. prefetch(&fp->sb_running_index[SM_RX_ID]);
  677. napi_schedule(&bnx2x_fp(bp, fp->index, napi));
  678. return IRQ_HANDLED;
  679. }
  680. /* HW Lock for shared dual port PHYs */
  681. void bnx2x_acquire_phy_lock(struct bnx2x *bp)
  682. {
  683. mutex_lock(&bp->port.phy_mutex);
  684. if (bp->port.need_hw_lock)
  685. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_MDIO);
  686. }
  687. void bnx2x_release_phy_lock(struct bnx2x *bp)
  688. {
  689. if (bp->port.need_hw_lock)
  690. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_MDIO);
  691. mutex_unlock(&bp->port.phy_mutex);
  692. }
  693. /* calculates MF speed according to current linespeed and MF configuration */
  694. u16 bnx2x_get_mf_speed(struct bnx2x *bp)
  695. {
  696. u16 line_speed = bp->link_vars.line_speed;
  697. if (IS_MF(bp)) {
  698. u16 maxCfg = bnx2x_extract_max_cfg(bp,
  699. bp->mf_config[BP_VN(bp)]);
  700. /* Calculate the current MAX line speed limit for the MF
  701. * devices
  702. */
  703. if (IS_MF_SI(bp))
  704. line_speed = (line_speed * maxCfg) / 100;
  705. else { /* SD mode */
  706. u16 vn_max_rate = maxCfg * 100;
  707. if (vn_max_rate < line_speed)
  708. line_speed = vn_max_rate;
  709. }
  710. }
  711. return line_speed;
  712. }
  713. /**
  714. * bnx2x_fill_report_data - fill link report data to report
  715. *
  716. * @bp: driver handle
  717. * @data: link state to update
  718. *
  719. * It uses a none-atomic bit operations because is called under the mutex.
  720. */
  721. static inline void bnx2x_fill_report_data(struct bnx2x *bp,
  722. struct bnx2x_link_report_data *data)
  723. {
  724. u16 line_speed = bnx2x_get_mf_speed(bp);
  725. memset(data, 0, sizeof(*data));
  726. /* Fill the report data: efective line speed */
  727. data->line_speed = line_speed;
  728. /* Link is down */
  729. if (!bp->link_vars.link_up || (bp->flags & MF_FUNC_DIS))
  730. __set_bit(BNX2X_LINK_REPORT_LINK_DOWN,
  731. &data->link_report_flags);
  732. /* Full DUPLEX */
  733. if (bp->link_vars.duplex == DUPLEX_FULL)
  734. __set_bit(BNX2X_LINK_REPORT_FD, &data->link_report_flags);
  735. /* Rx Flow Control is ON */
  736. if (bp->link_vars.flow_ctrl & BNX2X_FLOW_CTRL_RX)
  737. __set_bit(BNX2X_LINK_REPORT_RX_FC_ON, &data->link_report_flags);
  738. /* Tx Flow Control is ON */
  739. if (bp->link_vars.flow_ctrl & BNX2X_FLOW_CTRL_TX)
  740. __set_bit(BNX2X_LINK_REPORT_TX_FC_ON, &data->link_report_flags);
  741. }
  742. /**
  743. * bnx2x_link_report - report link status to OS.
  744. *
  745. * @bp: driver handle
  746. *
  747. * Calls the __bnx2x_link_report() under the same locking scheme
  748. * as a link/PHY state managing code to ensure a consistent link
  749. * reporting.
  750. */
  751. void bnx2x_link_report(struct bnx2x *bp)
  752. {
  753. bnx2x_acquire_phy_lock(bp);
  754. __bnx2x_link_report(bp);
  755. bnx2x_release_phy_lock(bp);
  756. }
  757. /**
  758. * __bnx2x_link_report - report link status to OS.
  759. *
  760. * @bp: driver handle
  761. *
  762. * None atomic inmlementation.
  763. * Should be called under the phy_lock.
  764. */
  765. void __bnx2x_link_report(struct bnx2x *bp)
  766. {
  767. struct bnx2x_link_report_data cur_data;
  768. /* reread mf_cfg */
  769. if (!CHIP_IS_E1(bp))
  770. bnx2x_read_mf_cfg(bp);
  771. /* Read the current link report info */
  772. bnx2x_fill_report_data(bp, &cur_data);
  773. /* Don't report link down or exactly the same link status twice */
  774. if (!memcmp(&cur_data, &bp->last_reported_link, sizeof(cur_data)) ||
  775. (test_bit(BNX2X_LINK_REPORT_LINK_DOWN,
  776. &bp->last_reported_link.link_report_flags) &&
  777. test_bit(BNX2X_LINK_REPORT_LINK_DOWN,
  778. &cur_data.link_report_flags)))
  779. return;
  780. bp->link_cnt++;
  781. /* We are going to report a new link parameters now -
  782. * remember the current data for the next time.
  783. */
  784. memcpy(&bp->last_reported_link, &cur_data, sizeof(cur_data));
  785. if (test_bit(BNX2X_LINK_REPORT_LINK_DOWN,
  786. &cur_data.link_report_flags)) {
  787. netif_carrier_off(bp->dev);
  788. netdev_err(bp->dev, "NIC Link is Down\n");
  789. return;
  790. } else {
  791. netif_carrier_on(bp->dev);
  792. netdev_info(bp->dev, "NIC Link is Up, ");
  793. pr_cont("%d Mbps ", cur_data.line_speed);
  794. if (test_and_clear_bit(BNX2X_LINK_REPORT_FD,
  795. &cur_data.link_report_flags))
  796. pr_cont("full duplex");
  797. else
  798. pr_cont("half duplex");
  799. /* Handle the FC at the end so that only these flags would be
  800. * possibly set. This way we may easily check if there is no FC
  801. * enabled.
  802. */
  803. if (cur_data.link_report_flags) {
  804. if (test_bit(BNX2X_LINK_REPORT_RX_FC_ON,
  805. &cur_data.link_report_flags)) {
  806. pr_cont(", receive ");
  807. if (test_bit(BNX2X_LINK_REPORT_TX_FC_ON,
  808. &cur_data.link_report_flags))
  809. pr_cont("& transmit ");
  810. } else {
  811. pr_cont(", transmit ");
  812. }
  813. pr_cont("flow control ON");
  814. }
  815. pr_cont("\n");
  816. }
  817. }
  818. void bnx2x_init_rx_rings(struct bnx2x *bp)
  819. {
  820. int func = BP_FUNC(bp);
  821. u16 ring_prod;
  822. int i, j;
  823. /* Allocate TPA resources */
  824. for_each_rx_queue(bp, j) {
  825. struct bnx2x_fastpath *fp = &bp->fp[j];
  826. DP(NETIF_MSG_IFUP,
  827. "mtu %d rx_buf_size %d\n", bp->dev->mtu, fp->rx_buf_size);
  828. if (!fp->disable_tpa) {
  829. /* Fill the per-aggregtion pool */
  830. for (i = 0; i < MAX_AGG_QS(bp); i++) {
  831. struct bnx2x_agg_info *tpa_info =
  832. &fp->tpa_info[i];
  833. struct sw_rx_bd *first_buf =
  834. &tpa_info->first_buf;
  835. first_buf->skb = netdev_alloc_skb(bp->dev,
  836. fp->rx_buf_size);
  837. if (!first_buf->skb) {
  838. BNX2X_ERR("Failed to allocate TPA "
  839. "skb pool for queue[%d] - "
  840. "disabling TPA on this "
  841. "queue!\n", j);
  842. bnx2x_free_tpa_pool(bp, fp, i);
  843. fp->disable_tpa = 1;
  844. break;
  845. }
  846. dma_unmap_addr_set(first_buf, mapping, 0);
  847. tpa_info->tpa_state = BNX2X_TPA_STOP;
  848. }
  849. /* "next page" elements initialization */
  850. bnx2x_set_next_page_sgl(fp);
  851. /* set SGEs bit mask */
  852. bnx2x_init_sge_ring_bit_mask(fp);
  853. /* Allocate SGEs and initialize the ring elements */
  854. for (i = 0, ring_prod = 0;
  855. i < MAX_RX_SGE_CNT*NUM_RX_SGE_PAGES; i++) {
  856. if (bnx2x_alloc_rx_sge(bp, fp, ring_prod) < 0) {
  857. BNX2X_ERR("was only able to allocate "
  858. "%d rx sges\n", i);
  859. BNX2X_ERR("disabling TPA for "
  860. "queue[%d]\n", j);
  861. /* Cleanup already allocated elements */
  862. bnx2x_free_rx_sge_range(bp, fp,
  863. ring_prod);
  864. bnx2x_free_tpa_pool(bp, fp,
  865. MAX_AGG_QS(bp));
  866. fp->disable_tpa = 1;
  867. ring_prod = 0;
  868. break;
  869. }
  870. ring_prod = NEXT_SGE_IDX(ring_prod);
  871. }
  872. fp->rx_sge_prod = ring_prod;
  873. }
  874. }
  875. for_each_rx_queue(bp, j) {
  876. struct bnx2x_fastpath *fp = &bp->fp[j];
  877. fp->rx_bd_cons = 0;
  878. /* Activate BD ring */
  879. /* Warning!
  880. * this will generate an interrupt (to the TSTORM)
  881. * must only be done after chip is initialized
  882. */
  883. bnx2x_update_rx_prod(bp, fp, fp->rx_bd_prod, fp->rx_comp_prod,
  884. fp->rx_sge_prod);
  885. if (j != 0)
  886. continue;
  887. if (CHIP_IS_E1(bp)) {
  888. REG_WR(bp, BAR_USTRORM_INTMEM +
  889. USTORM_MEM_WORKAROUND_ADDRESS_OFFSET(func),
  890. U64_LO(fp->rx_comp_mapping));
  891. REG_WR(bp, BAR_USTRORM_INTMEM +
  892. USTORM_MEM_WORKAROUND_ADDRESS_OFFSET(func) + 4,
  893. U64_HI(fp->rx_comp_mapping));
  894. }
  895. }
  896. }
  897. static void bnx2x_free_tx_skbs(struct bnx2x *bp)
  898. {
  899. int i;
  900. u8 cos;
  901. for_each_tx_queue(bp, i) {
  902. struct bnx2x_fastpath *fp = &bp->fp[i];
  903. for_each_cos_in_tx_queue(fp, cos) {
  904. struct bnx2x_fp_txdata *txdata = &fp->txdata[cos];
  905. u16 bd_cons = txdata->tx_bd_cons;
  906. u16 sw_prod = txdata->tx_pkt_prod;
  907. u16 sw_cons = txdata->tx_pkt_cons;
  908. while (sw_cons != sw_prod) {
  909. bd_cons = bnx2x_free_tx_pkt(bp, txdata,
  910. TX_BD(sw_cons));
  911. sw_cons++;
  912. }
  913. }
  914. }
  915. }
  916. static void bnx2x_free_rx_bds(struct bnx2x_fastpath *fp)
  917. {
  918. struct bnx2x *bp = fp->bp;
  919. int i;
  920. /* ring wasn't allocated */
  921. if (fp->rx_buf_ring == NULL)
  922. return;
  923. for (i = 0; i < NUM_RX_BD; i++) {
  924. struct sw_rx_bd *rx_buf = &fp->rx_buf_ring[i];
  925. struct sk_buff *skb = rx_buf->skb;
  926. if (skb == NULL)
  927. continue;
  928. dma_unmap_single(&bp->pdev->dev,
  929. dma_unmap_addr(rx_buf, mapping),
  930. fp->rx_buf_size, DMA_FROM_DEVICE);
  931. rx_buf->skb = NULL;
  932. dev_kfree_skb(skb);
  933. }
  934. }
  935. static void bnx2x_free_rx_skbs(struct bnx2x *bp)
  936. {
  937. int j;
  938. for_each_rx_queue(bp, j) {
  939. struct bnx2x_fastpath *fp = &bp->fp[j];
  940. bnx2x_free_rx_bds(fp);
  941. if (!fp->disable_tpa)
  942. bnx2x_free_tpa_pool(bp, fp, MAX_AGG_QS(bp));
  943. }
  944. }
  945. void bnx2x_free_skbs(struct bnx2x *bp)
  946. {
  947. bnx2x_free_tx_skbs(bp);
  948. bnx2x_free_rx_skbs(bp);
  949. }
  950. void bnx2x_update_max_mf_config(struct bnx2x *bp, u32 value)
  951. {
  952. /* load old values */
  953. u32 mf_cfg = bp->mf_config[BP_VN(bp)];
  954. if (value != bnx2x_extract_max_cfg(bp, mf_cfg)) {
  955. /* leave all but MAX value */
  956. mf_cfg &= ~FUNC_MF_CFG_MAX_BW_MASK;
  957. /* set new MAX value */
  958. mf_cfg |= (value << FUNC_MF_CFG_MAX_BW_SHIFT)
  959. & FUNC_MF_CFG_MAX_BW_MASK;
  960. bnx2x_fw_command(bp, DRV_MSG_CODE_SET_MF_BW, mf_cfg);
  961. }
  962. }
  963. /**
  964. * bnx2x_free_msix_irqs - free previously requested MSI-X IRQ vectors
  965. *
  966. * @bp: driver handle
  967. * @nvecs: number of vectors to be released
  968. */
  969. static void bnx2x_free_msix_irqs(struct bnx2x *bp, int nvecs)
  970. {
  971. int i, offset = 0;
  972. if (nvecs == offset)
  973. return;
  974. free_irq(bp->msix_table[offset].vector, bp->dev);
  975. DP(NETIF_MSG_IFDOWN, "released sp irq (%d)\n",
  976. bp->msix_table[offset].vector);
  977. offset++;
  978. #ifdef BCM_CNIC
  979. if (nvecs == offset)
  980. return;
  981. offset++;
  982. #endif
  983. for_each_eth_queue(bp, i) {
  984. if (nvecs == offset)
  985. return;
  986. DP(NETIF_MSG_IFDOWN, "about to release fp #%d->%d "
  987. "irq\n", i, bp->msix_table[offset].vector);
  988. free_irq(bp->msix_table[offset++].vector, &bp->fp[i]);
  989. }
  990. }
  991. void bnx2x_free_irq(struct bnx2x *bp)
  992. {
  993. if (bp->flags & USING_MSIX_FLAG)
  994. bnx2x_free_msix_irqs(bp, BNX2X_NUM_ETH_QUEUES(bp) +
  995. CNIC_PRESENT + 1);
  996. else if (bp->flags & USING_MSI_FLAG)
  997. free_irq(bp->pdev->irq, bp->dev);
  998. else
  999. free_irq(bp->pdev->irq, bp->dev);
  1000. }
  1001. int bnx2x_enable_msix(struct bnx2x *bp)
  1002. {
  1003. int msix_vec = 0, i, rc, req_cnt;
  1004. bp->msix_table[msix_vec].entry = msix_vec;
  1005. DP(NETIF_MSG_IFUP, "msix_table[0].entry = %d (slowpath)\n",
  1006. bp->msix_table[0].entry);
  1007. msix_vec++;
  1008. #ifdef BCM_CNIC
  1009. bp->msix_table[msix_vec].entry = msix_vec;
  1010. DP(NETIF_MSG_IFUP, "msix_table[%d].entry = %d (CNIC)\n",
  1011. bp->msix_table[msix_vec].entry, bp->msix_table[msix_vec].entry);
  1012. msix_vec++;
  1013. #endif
  1014. /* We need separate vectors for ETH queues only (not FCoE) */
  1015. for_each_eth_queue(bp, i) {
  1016. bp->msix_table[msix_vec].entry = msix_vec;
  1017. DP(NETIF_MSG_IFUP, "msix_table[%d].entry = %d "
  1018. "(fastpath #%u)\n", msix_vec, msix_vec, i);
  1019. msix_vec++;
  1020. }
  1021. req_cnt = BNX2X_NUM_ETH_QUEUES(bp) + CNIC_PRESENT + 1;
  1022. rc = pci_enable_msix(bp->pdev, &bp->msix_table[0], req_cnt);
  1023. /*
  1024. * reconfigure number of tx/rx queues according to available
  1025. * MSI-X vectors
  1026. */
  1027. if (rc >= BNX2X_MIN_MSIX_VEC_CNT) {
  1028. /* how less vectors we will have? */
  1029. int diff = req_cnt - rc;
  1030. DP(NETIF_MSG_IFUP,
  1031. "Trying to use less MSI-X vectors: %d\n", rc);
  1032. rc = pci_enable_msix(bp->pdev, &bp->msix_table[0], rc);
  1033. if (rc) {
  1034. DP(NETIF_MSG_IFUP,
  1035. "MSI-X is not attainable rc %d\n", rc);
  1036. return rc;
  1037. }
  1038. /*
  1039. * decrease number of queues by number of unallocated entries
  1040. */
  1041. bp->num_queues -= diff;
  1042. DP(NETIF_MSG_IFUP, "New queue configuration set: %d\n",
  1043. bp->num_queues);
  1044. } else if (rc) {
  1045. /* fall to INTx if not enough memory */
  1046. if (rc == -ENOMEM)
  1047. bp->flags |= DISABLE_MSI_FLAG;
  1048. DP(NETIF_MSG_IFUP, "MSI-X is not attainable rc %d\n", rc);
  1049. return rc;
  1050. }
  1051. bp->flags |= USING_MSIX_FLAG;
  1052. return 0;
  1053. }
  1054. static int bnx2x_req_msix_irqs(struct bnx2x *bp)
  1055. {
  1056. int i, rc, offset = 0;
  1057. rc = request_irq(bp->msix_table[offset++].vector,
  1058. bnx2x_msix_sp_int, 0,
  1059. bp->dev->name, bp->dev);
  1060. if (rc) {
  1061. BNX2X_ERR("request sp irq failed\n");
  1062. return -EBUSY;
  1063. }
  1064. #ifdef BCM_CNIC
  1065. offset++;
  1066. #endif
  1067. for_each_eth_queue(bp, i) {
  1068. struct bnx2x_fastpath *fp = &bp->fp[i];
  1069. snprintf(fp->name, sizeof(fp->name), "%s-fp-%d",
  1070. bp->dev->name, i);
  1071. rc = request_irq(bp->msix_table[offset].vector,
  1072. bnx2x_msix_fp_int, 0, fp->name, fp);
  1073. if (rc) {
  1074. BNX2X_ERR("request fp #%d irq (%d) failed rc %d\n", i,
  1075. bp->msix_table[offset].vector, rc);
  1076. bnx2x_free_msix_irqs(bp, offset);
  1077. return -EBUSY;
  1078. }
  1079. offset++;
  1080. }
  1081. i = BNX2X_NUM_ETH_QUEUES(bp);
  1082. offset = 1 + CNIC_PRESENT;
  1083. netdev_info(bp->dev, "using MSI-X IRQs: sp %d fp[%d] %d"
  1084. " ... fp[%d] %d\n",
  1085. bp->msix_table[0].vector,
  1086. 0, bp->msix_table[offset].vector,
  1087. i - 1, bp->msix_table[offset + i - 1].vector);
  1088. return 0;
  1089. }
  1090. int bnx2x_enable_msi(struct bnx2x *bp)
  1091. {
  1092. int rc;
  1093. rc = pci_enable_msi(bp->pdev);
  1094. if (rc) {
  1095. DP(NETIF_MSG_IFUP, "MSI is not attainable\n");
  1096. return -1;
  1097. }
  1098. bp->flags |= USING_MSI_FLAG;
  1099. return 0;
  1100. }
  1101. static int bnx2x_req_irq(struct bnx2x *bp)
  1102. {
  1103. unsigned long flags;
  1104. int rc;
  1105. if (bp->flags & USING_MSI_FLAG)
  1106. flags = 0;
  1107. else
  1108. flags = IRQF_SHARED;
  1109. rc = request_irq(bp->pdev->irq, bnx2x_interrupt, flags,
  1110. bp->dev->name, bp->dev);
  1111. return rc;
  1112. }
  1113. static inline int bnx2x_setup_irqs(struct bnx2x *bp)
  1114. {
  1115. int rc = 0;
  1116. if (bp->flags & USING_MSIX_FLAG) {
  1117. rc = bnx2x_req_msix_irqs(bp);
  1118. if (rc)
  1119. return rc;
  1120. } else {
  1121. bnx2x_ack_int(bp);
  1122. rc = bnx2x_req_irq(bp);
  1123. if (rc) {
  1124. BNX2X_ERR("IRQ request failed rc %d, aborting\n", rc);
  1125. return rc;
  1126. }
  1127. if (bp->flags & USING_MSI_FLAG) {
  1128. bp->dev->irq = bp->pdev->irq;
  1129. netdev_info(bp->dev, "using MSI IRQ %d\n",
  1130. bp->pdev->irq);
  1131. }
  1132. }
  1133. return 0;
  1134. }
  1135. static inline void bnx2x_napi_enable(struct bnx2x *bp)
  1136. {
  1137. int i;
  1138. for_each_rx_queue(bp, i)
  1139. napi_enable(&bnx2x_fp(bp, i, napi));
  1140. }
  1141. static inline void bnx2x_napi_disable(struct bnx2x *bp)
  1142. {
  1143. int i;
  1144. for_each_rx_queue(bp, i)
  1145. napi_disable(&bnx2x_fp(bp, i, napi));
  1146. }
  1147. void bnx2x_netif_start(struct bnx2x *bp)
  1148. {
  1149. if (netif_running(bp->dev)) {
  1150. bnx2x_napi_enable(bp);
  1151. bnx2x_int_enable(bp);
  1152. if (bp->state == BNX2X_STATE_OPEN)
  1153. netif_tx_wake_all_queues(bp->dev);
  1154. }
  1155. }
  1156. void bnx2x_netif_stop(struct bnx2x *bp, int disable_hw)
  1157. {
  1158. bnx2x_int_disable_sync(bp, disable_hw);
  1159. bnx2x_napi_disable(bp);
  1160. }
  1161. u16 bnx2x_select_queue(struct net_device *dev, struct sk_buff *skb)
  1162. {
  1163. struct bnx2x *bp = netdev_priv(dev);
  1164. #ifdef BCM_CNIC
  1165. if (!NO_FCOE(bp)) {
  1166. struct ethhdr *hdr = (struct ethhdr *)skb->data;
  1167. u16 ether_type = ntohs(hdr->h_proto);
  1168. /* Skip VLAN tag if present */
  1169. if (ether_type == ETH_P_8021Q) {
  1170. struct vlan_ethhdr *vhdr =
  1171. (struct vlan_ethhdr *)skb->data;
  1172. ether_type = ntohs(vhdr->h_vlan_encapsulated_proto);
  1173. }
  1174. /* If ethertype is FCoE or FIP - use FCoE ring */
  1175. if ((ether_type == ETH_P_FCOE) || (ether_type == ETH_P_FIP))
  1176. return bnx2x_fcoe_tx(bp, txq_index);
  1177. }
  1178. #endif
  1179. /* select a non-FCoE queue */
  1180. return __skb_tx_hash(dev, skb, BNX2X_NUM_ETH_QUEUES(bp));
  1181. }
  1182. void bnx2x_set_num_queues(struct bnx2x *bp)
  1183. {
  1184. switch (bp->multi_mode) {
  1185. case ETH_RSS_MODE_DISABLED:
  1186. bp->num_queues = 1;
  1187. break;
  1188. case ETH_RSS_MODE_REGULAR:
  1189. bp->num_queues = bnx2x_calc_num_queues(bp);
  1190. break;
  1191. default:
  1192. bp->num_queues = 1;
  1193. break;
  1194. }
  1195. /* Add special queues */
  1196. bp->num_queues += NON_ETH_CONTEXT_USE;
  1197. }
  1198. /**
  1199. * bnx2x_set_real_num_queues - configure netdev->real_num_[tx,rx]_queues
  1200. *
  1201. * @bp: Driver handle
  1202. *
  1203. * We currently support for at most 16 Tx queues for each CoS thus we will
  1204. * allocate a multiple of 16 for ETH L2 rings according to the value of the
  1205. * bp->max_cos.
  1206. *
  1207. * If there is an FCoE L2 queue the appropriate Tx queue will have the next
  1208. * index after all ETH L2 indices.
  1209. *
  1210. * If the actual number of Tx queues (for each CoS) is less than 16 then there
  1211. * will be the holes at the end of each group of 16 ETh L2 indices (0..15,
  1212. * 16..31,...) with indicies that are not coupled with any real Tx queue.
  1213. *
  1214. * The proper configuration of skb->queue_mapping is handled by
  1215. * bnx2x_select_queue() and __skb_tx_hash().
  1216. *
  1217. * bnx2x_setup_tc() takes care of the proper TC mappings so that __skb_tx_hash()
  1218. * will return a proper Tx index if TC is enabled (netdev->num_tc > 0).
  1219. */
  1220. static inline int bnx2x_set_real_num_queues(struct bnx2x *bp)
  1221. {
  1222. int rc, tx, rx;
  1223. tx = MAX_TXQS_PER_COS * bp->max_cos;
  1224. rx = BNX2X_NUM_ETH_QUEUES(bp);
  1225. /* account for fcoe queue */
  1226. #ifdef BCM_CNIC
  1227. if (!NO_FCOE(bp)) {
  1228. rx += FCOE_PRESENT;
  1229. tx += FCOE_PRESENT;
  1230. }
  1231. #endif
  1232. rc = netif_set_real_num_tx_queues(bp->dev, tx);
  1233. if (rc) {
  1234. BNX2X_ERR("Failed to set real number of Tx queues: %d\n", rc);
  1235. return rc;
  1236. }
  1237. rc = netif_set_real_num_rx_queues(bp->dev, rx);
  1238. if (rc) {
  1239. BNX2X_ERR("Failed to set real number of Rx queues: %d\n", rc);
  1240. return rc;
  1241. }
  1242. DP(NETIF_MSG_DRV, "Setting real num queues to (tx, rx) (%d, %d)\n",
  1243. tx, rx);
  1244. return rc;
  1245. }
  1246. static inline void bnx2x_set_rx_buf_size(struct bnx2x *bp)
  1247. {
  1248. int i;
  1249. for_each_queue(bp, i) {
  1250. struct bnx2x_fastpath *fp = &bp->fp[i];
  1251. /* Always use a mini-jumbo MTU for the FCoE L2 ring */
  1252. if (IS_FCOE_IDX(i))
  1253. /*
  1254. * Although there are no IP frames expected to arrive to
  1255. * this ring we still want to add an
  1256. * IP_HEADER_ALIGNMENT_PADDING to prevent a buffer
  1257. * overrun attack.
  1258. */
  1259. fp->rx_buf_size =
  1260. BNX2X_FCOE_MINI_JUMBO_MTU + ETH_OVREHEAD +
  1261. BNX2X_FW_RX_ALIGN + IP_HEADER_ALIGNMENT_PADDING;
  1262. else
  1263. fp->rx_buf_size =
  1264. bp->dev->mtu + ETH_OVREHEAD +
  1265. BNX2X_FW_RX_ALIGN + IP_HEADER_ALIGNMENT_PADDING;
  1266. }
  1267. }
  1268. static inline int bnx2x_init_rss_pf(struct bnx2x *bp)
  1269. {
  1270. int i;
  1271. u8 ind_table[T_ETH_INDIRECTION_TABLE_SIZE] = {0};
  1272. u8 num_eth_queues = BNX2X_NUM_ETH_QUEUES(bp);
  1273. /*
  1274. * Prepare the inital contents fo the indirection table if RSS is
  1275. * enabled
  1276. */
  1277. if (bp->multi_mode != ETH_RSS_MODE_DISABLED) {
  1278. for (i = 0; i < sizeof(ind_table); i++)
  1279. ind_table[i] =
  1280. bp->fp->cl_id + (i % num_eth_queues);
  1281. }
  1282. /*
  1283. * For 57710 and 57711 SEARCHER configuration (rss_keys) is
  1284. * per-port, so if explicit configuration is needed , do it only
  1285. * for a PMF.
  1286. *
  1287. * For 57712 and newer on the other hand it's a per-function
  1288. * configuration.
  1289. */
  1290. return bnx2x_config_rss_pf(bp, ind_table,
  1291. bp->port.pmf || !CHIP_IS_E1x(bp));
  1292. }
  1293. int bnx2x_config_rss_pf(struct bnx2x *bp, u8 *ind_table, bool config_hash)
  1294. {
  1295. struct bnx2x_config_rss_params params = {0};
  1296. int i;
  1297. /* Although RSS is meaningless when there is a single HW queue we
  1298. * still need it enabled in order to have HW Rx hash generated.
  1299. *
  1300. * if (!is_eth_multi(bp))
  1301. * bp->multi_mode = ETH_RSS_MODE_DISABLED;
  1302. */
  1303. params.rss_obj = &bp->rss_conf_obj;
  1304. __set_bit(RAMROD_COMP_WAIT, &params.ramrod_flags);
  1305. /* RSS mode */
  1306. switch (bp->multi_mode) {
  1307. case ETH_RSS_MODE_DISABLED:
  1308. __set_bit(BNX2X_RSS_MODE_DISABLED, &params.rss_flags);
  1309. break;
  1310. case ETH_RSS_MODE_REGULAR:
  1311. __set_bit(BNX2X_RSS_MODE_REGULAR, &params.rss_flags);
  1312. break;
  1313. case ETH_RSS_MODE_VLAN_PRI:
  1314. __set_bit(BNX2X_RSS_MODE_VLAN_PRI, &params.rss_flags);
  1315. break;
  1316. case ETH_RSS_MODE_E1HOV_PRI:
  1317. __set_bit(BNX2X_RSS_MODE_E1HOV_PRI, &params.rss_flags);
  1318. break;
  1319. case ETH_RSS_MODE_IP_DSCP:
  1320. __set_bit(BNX2X_RSS_MODE_IP_DSCP, &params.rss_flags);
  1321. break;
  1322. default:
  1323. BNX2X_ERR("Unknown multi_mode: %d\n", bp->multi_mode);
  1324. return -EINVAL;
  1325. }
  1326. /* If RSS is enabled */
  1327. if (bp->multi_mode != ETH_RSS_MODE_DISABLED) {
  1328. /* RSS configuration */
  1329. __set_bit(BNX2X_RSS_IPV4, &params.rss_flags);
  1330. __set_bit(BNX2X_RSS_IPV4_TCP, &params.rss_flags);
  1331. __set_bit(BNX2X_RSS_IPV6, &params.rss_flags);
  1332. __set_bit(BNX2X_RSS_IPV6_TCP, &params.rss_flags);
  1333. /* Hash bits */
  1334. params.rss_result_mask = MULTI_MASK;
  1335. memcpy(params.ind_table, ind_table, sizeof(params.ind_table));
  1336. if (config_hash) {
  1337. /* RSS keys */
  1338. for (i = 0; i < sizeof(params.rss_key) / 4; i++)
  1339. params.rss_key[i] = random32();
  1340. __set_bit(BNX2X_RSS_SET_SRCH, &params.rss_flags);
  1341. }
  1342. }
  1343. return bnx2x_config_rss(bp, &params);
  1344. }
  1345. static inline int bnx2x_init_hw(struct bnx2x *bp, u32 load_code)
  1346. {
  1347. struct bnx2x_func_state_params func_params = {0};
  1348. /* Prepare parameters for function state transitions */
  1349. __set_bit(RAMROD_COMP_WAIT, &func_params.ramrod_flags);
  1350. func_params.f_obj = &bp->func_obj;
  1351. func_params.cmd = BNX2X_F_CMD_HW_INIT;
  1352. func_params.params.hw_init.load_phase = load_code;
  1353. return bnx2x_func_state_change(bp, &func_params);
  1354. }
  1355. /*
  1356. * Cleans the object that have internal lists without sending
  1357. * ramrods. Should be run when interrutps are disabled.
  1358. */
  1359. static void bnx2x_squeeze_objects(struct bnx2x *bp)
  1360. {
  1361. int rc;
  1362. unsigned long ramrod_flags = 0, vlan_mac_flags = 0;
  1363. struct bnx2x_mcast_ramrod_params rparam = {0};
  1364. struct bnx2x_vlan_mac_obj *mac_obj = &bp->fp->mac_obj;
  1365. /***************** Cleanup MACs' object first *************************/
  1366. /* Wait for completion of requested */
  1367. __set_bit(RAMROD_COMP_WAIT, &ramrod_flags);
  1368. /* Perform a dry cleanup */
  1369. __set_bit(RAMROD_DRV_CLR_ONLY, &ramrod_flags);
  1370. /* Clean ETH primary MAC */
  1371. __set_bit(BNX2X_ETH_MAC, &vlan_mac_flags);
  1372. rc = mac_obj->delete_all(bp, &bp->fp->mac_obj, &vlan_mac_flags,
  1373. &ramrod_flags);
  1374. if (rc != 0)
  1375. BNX2X_ERR("Failed to clean ETH MACs: %d\n", rc);
  1376. /* Cleanup UC list */
  1377. vlan_mac_flags = 0;
  1378. __set_bit(BNX2X_UC_LIST_MAC, &vlan_mac_flags);
  1379. rc = mac_obj->delete_all(bp, mac_obj, &vlan_mac_flags,
  1380. &ramrod_flags);
  1381. if (rc != 0)
  1382. BNX2X_ERR("Failed to clean UC list MACs: %d\n", rc);
  1383. /***************** Now clean mcast object *****************************/
  1384. rparam.mcast_obj = &bp->mcast_obj;
  1385. __set_bit(RAMROD_DRV_CLR_ONLY, &rparam.ramrod_flags);
  1386. /* Add a DEL command... */
  1387. rc = bnx2x_config_mcast(bp, &rparam, BNX2X_MCAST_CMD_DEL);
  1388. if (rc < 0)
  1389. BNX2X_ERR("Failed to add a new DEL command to a multi-cast "
  1390. "object: %d\n", rc);
  1391. /* ...and wait until all pending commands are cleared */
  1392. rc = bnx2x_config_mcast(bp, &rparam, BNX2X_MCAST_CMD_CONT);
  1393. while (rc != 0) {
  1394. if (rc < 0) {
  1395. BNX2X_ERR("Failed to clean multi-cast object: %d\n",
  1396. rc);
  1397. return;
  1398. }
  1399. rc = bnx2x_config_mcast(bp, &rparam, BNX2X_MCAST_CMD_CONT);
  1400. }
  1401. }
  1402. #ifndef BNX2X_STOP_ON_ERROR
  1403. #define LOAD_ERROR_EXIT(bp, label) \
  1404. do { \
  1405. (bp)->state = BNX2X_STATE_ERROR; \
  1406. goto label; \
  1407. } while (0)
  1408. #else
  1409. #define LOAD_ERROR_EXIT(bp, label) \
  1410. do { \
  1411. (bp)->state = BNX2X_STATE_ERROR; \
  1412. (bp)->panic = 1; \
  1413. return -EBUSY; \
  1414. } while (0)
  1415. #endif
  1416. /* must be called with rtnl_lock */
  1417. int bnx2x_nic_load(struct bnx2x *bp, int load_mode)
  1418. {
  1419. int port = BP_PORT(bp);
  1420. u32 load_code;
  1421. int i, rc;
  1422. #ifdef BNX2X_STOP_ON_ERROR
  1423. if (unlikely(bp->panic))
  1424. return -EPERM;
  1425. #endif
  1426. bp->state = BNX2X_STATE_OPENING_WAIT4_LOAD;
  1427. /* Set the initial link reported state to link down */
  1428. bnx2x_acquire_phy_lock(bp);
  1429. memset(&bp->last_reported_link, 0, sizeof(bp->last_reported_link));
  1430. __set_bit(BNX2X_LINK_REPORT_LINK_DOWN,
  1431. &bp->last_reported_link.link_report_flags);
  1432. bnx2x_release_phy_lock(bp);
  1433. /* must be called before memory allocation and HW init */
  1434. bnx2x_ilt_set_info(bp);
  1435. /*
  1436. * Zero fastpath structures preserving invariants like napi, which are
  1437. * allocated only once, fp index, max_cos, bp pointer.
  1438. * Also set fp->disable_tpa.
  1439. */
  1440. for_each_queue(bp, i)
  1441. bnx2x_bz_fp(bp, i);
  1442. /* Set the receive queues buffer size */
  1443. bnx2x_set_rx_buf_size(bp);
  1444. if (bnx2x_alloc_mem(bp))
  1445. return -ENOMEM;
  1446. /* As long as bnx2x_alloc_mem() may possibly update
  1447. * bp->num_queues, bnx2x_set_real_num_queues() should always
  1448. * come after it.
  1449. */
  1450. rc = bnx2x_set_real_num_queues(bp);
  1451. if (rc) {
  1452. BNX2X_ERR("Unable to set real_num_queues\n");
  1453. LOAD_ERROR_EXIT(bp, load_error0);
  1454. }
  1455. /* configure multi cos mappings in kernel.
  1456. * this configuration may be overriden by a multi class queue discipline
  1457. * or by a dcbx negotiation result.
  1458. */
  1459. bnx2x_setup_tc(bp->dev, bp->max_cos);
  1460. bnx2x_napi_enable(bp);
  1461. /* Send LOAD_REQUEST command to MCP
  1462. * Returns the type of LOAD command:
  1463. * if it is the first port to be initialized
  1464. * common blocks should be initialized, otherwise - not
  1465. */
  1466. if (!BP_NOMCP(bp)) {
  1467. load_code = bnx2x_fw_command(bp, DRV_MSG_CODE_LOAD_REQ, 0);
  1468. if (!load_code) {
  1469. BNX2X_ERR("MCP response failure, aborting\n");
  1470. rc = -EBUSY;
  1471. LOAD_ERROR_EXIT(bp, load_error1);
  1472. }
  1473. if (load_code == FW_MSG_CODE_DRV_LOAD_REFUSED) {
  1474. rc = -EBUSY; /* other port in diagnostic mode */
  1475. LOAD_ERROR_EXIT(bp, load_error1);
  1476. }
  1477. } else {
  1478. int path = BP_PATH(bp);
  1479. DP(NETIF_MSG_IFUP, "NO MCP - load counts[%d] %d, %d, %d\n",
  1480. path, load_count[path][0], load_count[path][1],
  1481. load_count[path][2]);
  1482. load_count[path][0]++;
  1483. load_count[path][1 + port]++;
  1484. DP(NETIF_MSG_IFUP, "NO MCP - new load counts[%d] %d, %d, %d\n",
  1485. path, load_count[path][0], load_count[path][1],
  1486. load_count[path][2]);
  1487. if (load_count[path][0] == 1)
  1488. load_code = FW_MSG_CODE_DRV_LOAD_COMMON;
  1489. else if (load_count[path][1 + port] == 1)
  1490. load_code = FW_MSG_CODE_DRV_LOAD_PORT;
  1491. else
  1492. load_code = FW_MSG_CODE_DRV_LOAD_FUNCTION;
  1493. }
  1494. if ((load_code == FW_MSG_CODE_DRV_LOAD_COMMON) ||
  1495. (load_code == FW_MSG_CODE_DRV_LOAD_COMMON_CHIP) ||
  1496. (load_code == FW_MSG_CODE_DRV_LOAD_PORT)) {
  1497. bp->port.pmf = 1;
  1498. /*
  1499. * We need the barrier to ensure the ordering between the
  1500. * writing to bp->port.pmf here and reading it from the
  1501. * bnx2x_periodic_task().
  1502. */
  1503. smp_mb();
  1504. queue_delayed_work(bnx2x_wq, &bp->period_task, 0);
  1505. } else
  1506. bp->port.pmf = 0;
  1507. DP(NETIF_MSG_LINK, "pmf %d\n", bp->port.pmf);
  1508. /* Init Function state controlling object */
  1509. bnx2x__init_func_obj(bp);
  1510. /* Initialize HW */
  1511. rc = bnx2x_init_hw(bp, load_code);
  1512. if (rc) {
  1513. BNX2X_ERR("HW init failed, aborting\n");
  1514. bnx2x_fw_command(bp, DRV_MSG_CODE_LOAD_DONE, 0);
  1515. LOAD_ERROR_EXIT(bp, load_error2);
  1516. }
  1517. /* Connect to IRQs */
  1518. rc = bnx2x_setup_irqs(bp);
  1519. if (rc) {
  1520. bnx2x_fw_command(bp, DRV_MSG_CODE_LOAD_DONE, 0);
  1521. LOAD_ERROR_EXIT(bp, load_error2);
  1522. }
  1523. /* Setup NIC internals and enable interrupts */
  1524. bnx2x_nic_init(bp, load_code);
  1525. /* Init per-function objects */
  1526. bnx2x_init_bp_objs(bp);
  1527. if (((load_code == FW_MSG_CODE_DRV_LOAD_COMMON) ||
  1528. (load_code == FW_MSG_CODE_DRV_LOAD_COMMON_CHIP)) &&
  1529. (bp->common.shmem2_base)) {
  1530. if (SHMEM2_HAS(bp, dcc_support))
  1531. SHMEM2_WR(bp, dcc_support,
  1532. (SHMEM_DCC_SUPPORT_DISABLE_ENABLE_PF_TLV |
  1533. SHMEM_DCC_SUPPORT_BANDWIDTH_ALLOCATION_TLV));
  1534. }
  1535. bp->state = BNX2X_STATE_OPENING_WAIT4_PORT;
  1536. rc = bnx2x_func_start(bp);
  1537. if (rc) {
  1538. BNX2X_ERR("Function start failed!\n");
  1539. bnx2x_fw_command(bp, DRV_MSG_CODE_LOAD_DONE, 0);
  1540. LOAD_ERROR_EXIT(bp, load_error3);
  1541. }
  1542. /* Send LOAD_DONE command to MCP */
  1543. if (!BP_NOMCP(bp)) {
  1544. load_code = bnx2x_fw_command(bp, DRV_MSG_CODE_LOAD_DONE, 0);
  1545. if (!load_code) {
  1546. BNX2X_ERR("MCP response failure, aborting\n");
  1547. rc = -EBUSY;
  1548. LOAD_ERROR_EXIT(bp, load_error3);
  1549. }
  1550. }
  1551. rc = bnx2x_setup_leading(bp);
  1552. if (rc) {
  1553. BNX2X_ERR("Setup leading failed!\n");
  1554. LOAD_ERROR_EXIT(bp, load_error3);
  1555. }
  1556. #ifdef BCM_CNIC
  1557. /* Enable Timer scan */
  1558. REG_WR(bp, TM_REG_EN_LINEAR0_TIMER + port*4, 1);
  1559. #endif
  1560. for_each_nondefault_queue(bp, i) {
  1561. rc = bnx2x_setup_queue(bp, &bp->fp[i], 0);
  1562. if (rc)
  1563. LOAD_ERROR_EXIT(bp, load_error4);
  1564. }
  1565. rc = bnx2x_init_rss_pf(bp);
  1566. if (rc)
  1567. LOAD_ERROR_EXIT(bp, load_error4);
  1568. /* Now when Clients are configured we are ready to work */
  1569. bp->state = BNX2X_STATE_OPEN;
  1570. /* Configure a ucast MAC */
  1571. rc = bnx2x_set_eth_mac(bp, true);
  1572. if (rc)
  1573. LOAD_ERROR_EXIT(bp, load_error4);
  1574. if (bp->pending_max) {
  1575. bnx2x_update_max_mf_config(bp, bp->pending_max);
  1576. bp->pending_max = 0;
  1577. }
  1578. if (bp->port.pmf)
  1579. bnx2x_initial_phy_init(bp, load_mode);
  1580. /* Start fast path */
  1581. /* Initialize Rx filter. */
  1582. netif_addr_lock_bh(bp->dev);
  1583. bnx2x_set_rx_mode(bp->dev);
  1584. netif_addr_unlock_bh(bp->dev);
  1585. /* Start the Tx */
  1586. switch (load_mode) {
  1587. case LOAD_NORMAL:
  1588. /* Tx queue should be only reenabled */
  1589. netif_tx_wake_all_queues(bp->dev);
  1590. break;
  1591. case LOAD_OPEN:
  1592. netif_tx_start_all_queues(bp->dev);
  1593. smp_mb__after_clear_bit();
  1594. break;
  1595. case LOAD_DIAG:
  1596. bp->state = BNX2X_STATE_DIAG;
  1597. break;
  1598. default:
  1599. break;
  1600. }
  1601. if (!bp->port.pmf)
  1602. bnx2x__link_status_update(bp);
  1603. /* start the timer */
  1604. mod_timer(&bp->timer, jiffies + bp->current_interval);
  1605. #ifdef BCM_CNIC
  1606. bnx2x_setup_cnic_irq_info(bp);
  1607. if (bp->state == BNX2X_STATE_OPEN)
  1608. bnx2x_cnic_notify(bp, CNIC_CTL_START_CMD);
  1609. #endif
  1610. bnx2x_inc_load_cnt(bp);
  1611. /* Wait for all pending SP commands to complete */
  1612. if (!bnx2x_wait_sp_comp(bp, ~0x0UL)) {
  1613. BNX2X_ERR("Timeout waiting for SP elements to complete\n");
  1614. bnx2x_nic_unload(bp, UNLOAD_CLOSE);
  1615. return -EBUSY;
  1616. }
  1617. bnx2x_dcbx_init(bp);
  1618. return 0;
  1619. #ifndef BNX2X_STOP_ON_ERROR
  1620. load_error4:
  1621. #ifdef BCM_CNIC
  1622. /* Disable Timer scan */
  1623. REG_WR(bp, TM_REG_EN_LINEAR0_TIMER + port*4, 0);
  1624. #endif
  1625. load_error3:
  1626. bnx2x_int_disable_sync(bp, 1);
  1627. /* Clean queueable objects */
  1628. bnx2x_squeeze_objects(bp);
  1629. /* Free SKBs, SGEs, TPA pool and driver internals */
  1630. bnx2x_free_skbs(bp);
  1631. for_each_rx_queue(bp, i)
  1632. bnx2x_free_rx_sge_range(bp, bp->fp + i, NUM_RX_SGE);
  1633. /* Release IRQs */
  1634. bnx2x_free_irq(bp);
  1635. load_error2:
  1636. if (!BP_NOMCP(bp)) {
  1637. bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_REQ_WOL_MCP, 0);
  1638. bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_DONE, 0);
  1639. }
  1640. bp->port.pmf = 0;
  1641. load_error1:
  1642. bnx2x_napi_disable(bp);
  1643. load_error0:
  1644. bnx2x_free_mem(bp);
  1645. return rc;
  1646. #endif /* ! BNX2X_STOP_ON_ERROR */
  1647. }
  1648. /* must be called with rtnl_lock */
  1649. int bnx2x_nic_unload(struct bnx2x *bp, int unload_mode)
  1650. {
  1651. int i;
  1652. bool global = false;
  1653. if ((bp->state == BNX2X_STATE_CLOSED) ||
  1654. (bp->state == BNX2X_STATE_ERROR)) {
  1655. /* We can get here if the driver has been unloaded
  1656. * during parity error recovery and is either waiting for a
  1657. * leader to complete or for other functions to unload and
  1658. * then ifdown has been issued. In this case we want to
  1659. * unload and let other functions to complete a recovery
  1660. * process.
  1661. */
  1662. bp->recovery_state = BNX2X_RECOVERY_DONE;
  1663. bp->is_leader = 0;
  1664. bnx2x_release_leader_lock(bp);
  1665. smp_mb();
  1666. DP(NETIF_MSG_HW, "Releasing a leadership...\n");
  1667. return -EINVAL;
  1668. }
  1669. /*
  1670. * It's important to set the bp->state to the value different from
  1671. * BNX2X_STATE_OPEN and only then stop the Tx. Otherwise bnx2x_tx_int()
  1672. * may restart the Tx from the NAPI context (see bnx2x_tx_int()).
  1673. */
  1674. bp->state = BNX2X_STATE_CLOSING_WAIT4_HALT;
  1675. smp_mb();
  1676. /* Stop Tx */
  1677. bnx2x_tx_disable(bp);
  1678. #ifdef BCM_CNIC
  1679. bnx2x_cnic_notify(bp, CNIC_CTL_STOP_CMD);
  1680. #endif
  1681. bp->rx_mode = BNX2X_RX_MODE_NONE;
  1682. del_timer_sync(&bp->timer);
  1683. /* Set ALWAYS_ALIVE bit in shmem */
  1684. bp->fw_drv_pulse_wr_seq |= DRV_PULSE_ALWAYS_ALIVE;
  1685. bnx2x_drv_pulse(bp);
  1686. bnx2x_stats_handle(bp, STATS_EVENT_STOP);
  1687. /* Cleanup the chip if needed */
  1688. if (unload_mode != UNLOAD_RECOVERY)
  1689. bnx2x_chip_cleanup(bp, unload_mode);
  1690. else {
  1691. /* Send the UNLOAD_REQUEST to the MCP */
  1692. bnx2x_send_unload_req(bp, unload_mode);
  1693. /*
  1694. * Prevent transactions to host from the functions on the
  1695. * engine that doesn't reset global blocks in case of global
  1696. * attention once gloabl blocks are reset and gates are opened
  1697. * (the engine which leader will perform the recovery
  1698. * last).
  1699. */
  1700. if (!CHIP_IS_E1x(bp))
  1701. bnx2x_pf_disable(bp);
  1702. /* Disable HW interrupts, NAPI */
  1703. bnx2x_netif_stop(bp, 1);
  1704. /* Release IRQs */
  1705. bnx2x_free_irq(bp);
  1706. /* Report UNLOAD_DONE to MCP */
  1707. bnx2x_send_unload_done(bp);
  1708. }
  1709. /*
  1710. * At this stage no more interrupts will arrive so we may safly clean
  1711. * the queueable objects here in case they failed to get cleaned so far.
  1712. */
  1713. bnx2x_squeeze_objects(bp);
  1714. /* There should be no more pending SP commands at this stage */
  1715. bp->sp_state = 0;
  1716. bp->port.pmf = 0;
  1717. /* Free SKBs, SGEs, TPA pool and driver internals */
  1718. bnx2x_free_skbs(bp);
  1719. for_each_rx_queue(bp, i)
  1720. bnx2x_free_rx_sge_range(bp, bp->fp + i, NUM_RX_SGE);
  1721. bnx2x_free_mem(bp);
  1722. bp->state = BNX2X_STATE_CLOSED;
  1723. /* Check if there are pending parity attentions. If there are - set
  1724. * RECOVERY_IN_PROGRESS.
  1725. */
  1726. if (bnx2x_chk_parity_attn(bp, &global, false)) {
  1727. bnx2x_set_reset_in_progress(bp);
  1728. /* Set RESET_IS_GLOBAL if needed */
  1729. if (global)
  1730. bnx2x_set_reset_global(bp);
  1731. }
  1732. /* The last driver must disable a "close the gate" if there is no
  1733. * parity attention or "process kill" pending.
  1734. */
  1735. if (!bnx2x_dec_load_cnt(bp) && bnx2x_reset_is_done(bp, BP_PATH(bp)))
  1736. bnx2x_disable_close_the_gate(bp);
  1737. return 0;
  1738. }
  1739. int bnx2x_set_power_state(struct bnx2x *bp, pci_power_t state)
  1740. {
  1741. u16 pmcsr;
  1742. /* If there is no power capability, silently succeed */
  1743. if (!bp->pm_cap) {
  1744. DP(NETIF_MSG_HW, "No power capability. Breaking.\n");
  1745. return 0;
  1746. }
  1747. pci_read_config_word(bp->pdev, bp->pm_cap + PCI_PM_CTRL, &pmcsr);
  1748. switch (state) {
  1749. case PCI_D0:
  1750. pci_write_config_word(bp->pdev, bp->pm_cap + PCI_PM_CTRL,
  1751. ((pmcsr & ~PCI_PM_CTRL_STATE_MASK) |
  1752. PCI_PM_CTRL_PME_STATUS));
  1753. if (pmcsr & PCI_PM_CTRL_STATE_MASK)
  1754. /* delay required during transition out of D3hot */
  1755. msleep(20);
  1756. break;
  1757. case PCI_D3hot:
  1758. /* If there are other clients above don't
  1759. shut down the power */
  1760. if (atomic_read(&bp->pdev->enable_cnt) != 1)
  1761. return 0;
  1762. /* Don't shut down the power for emulation and FPGA */
  1763. if (CHIP_REV_IS_SLOW(bp))
  1764. return 0;
  1765. pmcsr &= ~PCI_PM_CTRL_STATE_MASK;
  1766. pmcsr |= 3;
  1767. if (bp->wol)
  1768. pmcsr |= PCI_PM_CTRL_PME_ENABLE;
  1769. pci_write_config_word(bp->pdev, bp->pm_cap + PCI_PM_CTRL,
  1770. pmcsr);
  1771. /* No more memory access after this point until
  1772. * device is brought back to D0.
  1773. */
  1774. break;
  1775. default:
  1776. return -EINVAL;
  1777. }
  1778. return 0;
  1779. }
  1780. /*
  1781. * net_device service functions
  1782. */
  1783. int bnx2x_poll(struct napi_struct *napi, int budget)
  1784. {
  1785. int work_done = 0;
  1786. u8 cos;
  1787. struct bnx2x_fastpath *fp = container_of(napi, struct bnx2x_fastpath,
  1788. napi);
  1789. struct bnx2x *bp = fp->bp;
  1790. while (1) {
  1791. #ifdef BNX2X_STOP_ON_ERROR
  1792. if (unlikely(bp->panic)) {
  1793. napi_complete(napi);
  1794. return 0;
  1795. }
  1796. #endif
  1797. for_each_cos_in_tx_queue(fp, cos)
  1798. if (bnx2x_tx_queue_has_work(&fp->txdata[cos]))
  1799. bnx2x_tx_int(bp, &fp->txdata[cos]);
  1800. if (bnx2x_has_rx_work(fp)) {
  1801. work_done += bnx2x_rx_int(fp, budget - work_done);
  1802. /* must not complete if we consumed full budget */
  1803. if (work_done >= budget)
  1804. break;
  1805. }
  1806. /* Fall out from the NAPI loop if needed */
  1807. if (!(bnx2x_has_rx_work(fp) || bnx2x_has_tx_work(fp))) {
  1808. #ifdef BCM_CNIC
  1809. /* No need to update SB for FCoE L2 ring as long as
  1810. * it's connected to the default SB and the SB
  1811. * has been updated when NAPI was scheduled.
  1812. */
  1813. if (IS_FCOE_FP(fp)) {
  1814. napi_complete(napi);
  1815. break;
  1816. }
  1817. #endif
  1818. bnx2x_update_fpsb_idx(fp);
  1819. /* bnx2x_has_rx_work() reads the status block,
  1820. * thus we need to ensure that status block indices
  1821. * have been actually read (bnx2x_update_fpsb_idx)
  1822. * prior to this check (bnx2x_has_rx_work) so that
  1823. * we won't write the "newer" value of the status block
  1824. * to IGU (if there was a DMA right after
  1825. * bnx2x_has_rx_work and if there is no rmb, the memory
  1826. * reading (bnx2x_update_fpsb_idx) may be postponed
  1827. * to right before bnx2x_ack_sb). In this case there
  1828. * will never be another interrupt until there is
  1829. * another update of the status block, while there
  1830. * is still unhandled work.
  1831. */
  1832. rmb();
  1833. if (!(bnx2x_has_rx_work(fp) || bnx2x_has_tx_work(fp))) {
  1834. napi_complete(napi);
  1835. /* Re-enable interrupts */
  1836. DP(NETIF_MSG_HW,
  1837. "Update index to %d\n", fp->fp_hc_idx);
  1838. bnx2x_ack_sb(bp, fp->igu_sb_id, USTORM_ID,
  1839. le16_to_cpu(fp->fp_hc_idx),
  1840. IGU_INT_ENABLE, 1);
  1841. break;
  1842. }
  1843. }
  1844. }
  1845. return work_done;
  1846. }
  1847. /* we split the first BD into headers and data BDs
  1848. * to ease the pain of our fellow microcode engineers
  1849. * we use one mapping for both BDs
  1850. * So far this has only been observed to happen
  1851. * in Other Operating Systems(TM)
  1852. */
  1853. static noinline u16 bnx2x_tx_split(struct bnx2x *bp,
  1854. struct bnx2x_fp_txdata *txdata,
  1855. struct sw_tx_bd *tx_buf,
  1856. struct eth_tx_start_bd **tx_bd, u16 hlen,
  1857. u16 bd_prod, int nbd)
  1858. {
  1859. struct eth_tx_start_bd *h_tx_bd = *tx_bd;
  1860. struct eth_tx_bd *d_tx_bd;
  1861. dma_addr_t mapping;
  1862. int old_len = le16_to_cpu(h_tx_bd->nbytes);
  1863. /* first fix first BD */
  1864. h_tx_bd->nbd = cpu_to_le16(nbd);
  1865. h_tx_bd->nbytes = cpu_to_le16(hlen);
  1866. DP(NETIF_MSG_TX_QUEUED, "TSO split header size is %d "
  1867. "(%x:%x) nbd %d\n", h_tx_bd->nbytes, h_tx_bd->addr_hi,
  1868. h_tx_bd->addr_lo, h_tx_bd->nbd);
  1869. /* now get a new data BD
  1870. * (after the pbd) and fill it */
  1871. bd_prod = TX_BD(NEXT_TX_IDX(bd_prod));
  1872. d_tx_bd = &txdata->tx_desc_ring[bd_prod].reg_bd;
  1873. mapping = HILO_U64(le32_to_cpu(h_tx_bd->addr_hi),
  1874. le32_to_cpu(h_tx_bd->addr_lo)) + hlen;
  1875. d_tx_bd->addr_hi = cpu_to_le32(U64_HI(mapping));
  1876. d_tx_bd->addr_lo = cpu_to_le32(U64_LO(mapping));
  1877. d_tx_bd->nbytes = cpu_to_le16(old_len - hlen);
  1878. /* this marks the BD as one that has no individual mapping */
  1879. tx_buf->flags |= BNX2X_TSO_SPLIT_BD;
  1880. DP(NETIF_MSG_TX_QUEUED,
  1881. "TSO split data size is %d (%x:%x)\n",
  1882. d_tx_bd->nbytes, d_tx_bd->addr_hi, d_tx_bd->addr_lo);
  1883. /* update tx_bd */
  1884. *tx_bd = (struct eth_tx_start_bd *)d_tx_bd;
  1885. return bd_prod;
  1886. }
  1887. static inline u16 bnx2x_csum_fix(unsigned char *t_header, u16 csum, s8 fix)
  1888. {
  1889. if (fix > 0)
  1890. csum = (u16) ~csum_fold(csum_sub(csum,
  1891. csum_partial(t_header - fix, fix, 0)));
  1892. else if (fix < 0)
  1893. csum = (u16) ~csum_fold(csum_add(csum,
  1894. csum_partial(t_header, -fix, 0)));
  1895. return swab16(csum);
  1896. }
  1897. static inline u32 bnx2x_xmit_type(struct bnx2x *bp, struct sk_buff *skb)
  1898. {
  1899. u32 rc;
  1900. if (skb->ip_summed != CHECKSUM_PARTIAL)
  1901. rc = XMIT_PLAIN;
  1902. else {
  1903. if (vlan_get_protocol(skb) == htons(ETH_P_IPV6)) {
  1904. rc = XMIT_CSUM_V6;
  1905. if (ipv6_hdr(skb)->nexthdr == IPPROTO_TCP)
  1906. rc |= XMIT_CSUM_TCP;
  1907. } else {
  1908. rc = XMIT_CSUM_V4;
  1909. if (ip_hdr(skb)->protocol == IPPROTO_TCP)
  1910. rc |= XMIT_CSUM_TCP;
  1911. }
  1912. }
  1913. if (skb_is_gso_v6(skb))
  1914. rc |= XMIT_GSO_V6 | XMIT_CSUM_TCP | XMIT_CSUM_V6;
  1915. else if (skb_is_gso(skb))
  1916. rc |= XMIT_GSO_V4 | XMIT_CSUM_V4 | XMIT_CSUM_TCP;
  1917. return rc;
  1918. }
  1919. #if (MAX_SKB_FRAGS >= MAX_FETCH_BD - 3)
  1920. /* check if packet requires linearization (packet is too fragmented)
  1921. no need to check fragmentation if page size > 8K (there will be no
  1922. violation to FW restrictions) */
  1923. static int bnx2x_pkt_req_lin(struct bnx2x *bp, struct sk_buff *skb,
  1924. u32 xmit_type)
  1925. {
  1926. int to_copy = 0;
  1927. int hlen = 0;
  1928. int first_bd_sz = 0;
  1929. /* 3 = 1 (for linear data BD) + 2 (for PBD and last BD) */
  1930. if (skb_shinfo(skb)->nr_frags >= (MAX_FETCH_BD - 3)) {
  1931. if (xmit_type & XMIT_GSO) {
  1932. unsigned short lso_mss = skb_shinfo(skb)->gso_size;
  1933. /* Check if LSO packet needs to be copied:
  1934. 3 = 1 (for headers BD) + 2 (for PBD and last BD) */
  1935. int wnd_size = MAX_FETCH_BD - 3;
  1936. /* Number of windows to check */
  1937. int num_wnds = skb_shinfo(skb)->nr_frags - wnd_size;
  1938. int wnd_idx = 0;
  1939. int frag_idx = 0;
  1940. u32 wnd_sum = 0;
  1941. /* Headers length */
  1942. hlen = (int)(skb_transport_header(skb) - skb->data) +
  1943. tcp_hdrlen(skb);
  1944. /* Amount of data (w/o headers) on linear part of SKB*/
  1945. first_bd_sz = skb_headlen(skb) - hlen;
  1946. wnd_sum = first_bd_sz;
  1947. /* Calculate the first sum - it's special */
  1948. for (frag_idx = 0; frag_idx < wnd_size - 1; frag_idx++)
  1949. wnd_sum +=
  1950. skb_shinfo(skb)->frags[frag_idx].size;
  1951. /* If there was data on linear skb data - check it */
  1952. if (first_bd_sz > 0) {
  1953. if (unlikely(wnd_sum < lso_mss)) {
  1954. to_copy = 1;
  1955. goto exit_lbl;
  1956. }
  1957. wnd_sum -= first_bd_sz;
  1958. }
  1959. /* Others are easier: run through the frag list and
  1960. check all windows */
  1961. for (wnd_idx = 0; wnd_idx <= num_wnds; wnd_idx++) {
  1962. wnd_sum +=
  1963. skb_shinfo(skb)->frags[wnd_idx + wnd_size - 1].size;
  1964. if (unlikely(wnd_sum < lso_mss)) {
  1965. to_copy = 1;
  1966. break;
  1967. }
  1968. wnd_sum -=
  1969. skb_shinfo(skb)->frags[wnd_idx].size;
  1970. }
  1971. } else {
  1972. /* in non-LSO too fragmented packet should always
  1973. be linearized */
  1974. to_copy = 1;
  1975. }
  1976. }
  1977. exit_lbl:
  1978. if (unlikely(to_copy))
  1979. DP(NETIF_MSG_TX_QUEUED,
  1980. "Linearization IS REQUIRED for %s packet. "
  1981. "num_frags %d hlen %d first_bd_sz %d\n",
  1982. (xmit_type & XMIT_GSO) ? "LSO" : "non-LSO",
  1983. skb_shinfo(skb)->nr_frags, hlen, first_bd_sz);
  1984. return to_copy;
  1985. }
  1986. #endif
  1987. static inline void bnx2x_set_pbd_gso_e2(struct sk_buff *skb, u32 *parsing_data,
  1988. u32 xmit_type)
  1989. {
  1990. *parsing_data |= (skb_shinfo(skb)->gso_size <<
  1991. ETH_TX_PARSE_BD_E2_LSO_MSS_SHIFT) &
  1992. ETH_TX_PARSE_BD_E2_LSO_MSS;
  1993. if ((xmit_type & XMIT_GSO_V6) &&
  1994. (ipv6_hdr(skb)->nexthdr == NEXTHDR_IPV6))
  1995. *parsing_data |= ETH_TX_PARSE_BD_E2_IPV6_WITH_EXT_HDR;
  1996. }
  1997. /**
  1998. * bnx2x_set_pbd_gso - update PBD in GSO case.
  1999. *
  2000. * @skb: packet skb
  2001. * @pbd: parse BD
  2002. * @xmit_type: xmit flags
  2003. */
  2004. static inline void bnx2x_set_pbd_gso(struct sk_buff *skb,
  2005. struct eth_tx_parse_bd_e1x *pbd,
  2006. u32 xmit_type)
  2007. {
  2008. pbd->lso_mss = cpu_to_le16(skb_shinfo(skb)->gso_size);
  2009. pbd->tcp_send_seq = swab32(tcp_hdr(skb)->seq);
  2010. pbd->tcp_flags = pbd_tcp_flags(skb);
  2011. if (xmit_type & XMIT_GSO_V4) {
  2012. pbd->ip_id = swab16(ip_hdr(skb)->id);
  2013. pbd->tcp_pseudo_csum =
  2014. swab16(~csum_tcpudp_magic(ip_hdr(skb)->saddr,
  2015. ip_hdr(skb)->daddr,
  2016. 0, IPPROTO_TCP, 0));
  2017. } else
  2018. pbd->tcp_pseudo_csum =
  2019. swab16(~csum_ipv6_magic(&ipv6_hdr(skb)->saddr,
  2020. &ipv6_hdr(skb)->daddr,
  2021. 0, IPPROTO_TCP, 0));
  2022. pbd->global_data |= ETH_TX_PARSE_BD_E1X_PSEUDO_CS_WITHOUT_LEN;
  2023. }
  2024. /**
  2025. * bnx2x_set_pbd_csum_e2 - update PBD with checksum and return header length
  2026. *
  2027. * @bp: driver handle
  2028. * @skb: packet skb
  2029. * @parsing_data: data to be updated
  2030. * @xmit_type: xmit flags
  2031. *
  2032. * 57712 related
  2033. */
  2034. static inline u8 bnx2x_set_pbd_csum_e2(struct bnx2x *bp, struct sk_buff *skb,
  2035. u32 *parsing_data, u32 xmit_type)
  2036. {
  2037. *parsing_data |=
  2038. ((((u8 *)skb_transport_header(skb) - skb->data) >> 1) <<
  2039. ETH_TX_PARSE_BD_E2_TCP_HDR_START_OFFSET_W_SHIFT) &
  2040. ETH_TX_PARSE_BD_E2_TCP_HDR_START_OFFSET_W;
  2041. if (xmit_type & XMIT_CSUM_TCP) {
  2042. *parsing_data |= ((tcp_hdrlen(skb) / 4) <<
  2043. ETH_TX_PARSE_BD_E2_TCP_HDR_LENGTH_DW_SHIFT) &
  2044. ETH_TX_PARSE_BD_E2_TCP_HDR_LENGTH_DW;
  2045. return skb_transport_header(skb) + tcp_hdrlen(skb) - skb->data;
  2046. } else
  2047. /* We support checksum offload for TCP and UDP only.
  2048. * No need to pass the UDP header length - it's a constant.
  2049. */
  2050. return skb_transport_header(skb) +
  2051. sizeof(struct udphdr) - skb->data;
  2052. }
  2053. static inline void bnx2x_set_sbd_csum(struct bnx2x *bp, struct sk_buff *skb,
  2054. struct eth_tx_start_bd *tx_start_bd, u32 xmit_type)
  2055. {
  2056. tx_start_bd->bd_flags.as_bitfield |= ETH_TX_BD_FLAGS_L4_CSUM;
  2057. if (xmit_type & XMIT_CSUM_V4)
  2058. tx_start_bd->bd_flags.as_bitfield |=
  2059. ETH_TX_BD_FLAGS_IP_CSUM;
  2060. else
  2061. tx_start_bd->bd_flags.as_bitfield |=
  2062. ETH_TX_BD_FLAGS_IPV6;
  2063. if (!(xmit_type & XMIT_CSUM_TCP))
  2064. tx_start_bd->bd_flags.as_bitfield |= ETH_TX_BD_FLAGS_IS_UDP;
  2065. }
  2066. /**
  2067. * bnx2x_set_pbd_csum - update PBD with checksum and return header length
  2068. *
  2069. * @bp: driver handle
  2070. * @skb: packet skb
  2071. * @pbd: parse BD to be updated
  2072. * @xmit_type: xmit flags
  2073. */
  2074. static inline u8 bnx2x_set_pbd_csum(struct bnx2x *bp, struct sk_buff *skb,
  2075. struct eth_tx_parse_bd_e1x *pbd,
  2076. u32 xmit_type)
  2077. {
  2078. u8 hlen = (skb_network_header(skb) - skb->data) >> 1;
  2079. /* for now NS flag is not used in Linux */
  2080. pbd->global_data =
  2081. (hlen | ((skb->protocol == cpu_to_be16(ETH_P_8021Q)) <<
  2082. ETH_TX_PARSE_BD_E1X_LLC_SNAP_EN_SHIFT));
  2083. pbd->ip_hlen_w = (skb_transport_header(skb) -
  2084. skb_network_header(skb)) >> 1;
  2085. hlen += pbd->ip_hlen_w;
  2086. /* We support checksum offload for TCP and UDP only */
  2087. if (xmit_type & XMIT_CSUM_TCP)
  2088. hlen += tcp_hdrlen(skb) / 2;
  2089. else
  2090. hlen += sizeof(struct udphdr) / 2;
  2091. pbd->total_hlen_w = cpu_to_le16(hlen);
  2092. hlen = hlen*2;
  2093. if (xmit_type & XMIT_CSUM_TCP) {
  2094. pbd->tcp_pseudo_csum = swab16(tcp_hdr(skb)->check);
  2095. } else {
  2096. s8 fix = SKB_CS_OFF(skb); /* signed! */
  2097. DP(NETIF_MSG_TX_QUEUED,
  2098. "hlen %d fix %d csum before fix %x\n",
  2099. le16_to_cpu(pbd->total_hlen_w), fix, SKB_CS(skb));
  2100. /* HW bug: fixup the CSUM */
  2101. pbd->tcp_pseudo_csum =
  2102. bnx2x_csum_fix(skb_transport_header(skb),
  2103. SKB_CS(skb), fix);
  2104. DP(NETIF_MSG_TX_QUEUED, "csum after fix %x\n",
  2105. pbd->tcp_pseudo_csum);
  2106. }
  2107. return hlen;
  2108. }
  2109. /* called with netif_tx_lock
  2110. * bnx2x_tx_int() runs without netif_tx_lock unless it needs to call
  2111. * netif_wake_queue()
  2112. */
  2113. netdev_tx_t bnx2x_start_xmit(struct sk_buff *skb, struct net_device *dev)
  2114. {
  2115. struct bnx2x *bp = netdev_priv(dev);
  2116. struct bnx2x_fastpath *fp;
  2117. struct netdev_queue *txq;
  2118. struct bnx2x_fp_txdata *txdata;
  2119. struct sw_tx_bd *tx_buf;
  2120. struct eth_tx_start_bd *tx_start_bd, *first_bd;
  2121. struct eth_tx_bd *tx_data_bd, *total_pkt_bd = NULL;
  2122. struct eth_tx_parse_bd_e1x *pbd_e1x = NULL;
  2123. struct eth_tx_parse_bd_e2 *pbd_e2 = NULL;
  2124. u32 pbd_e2_parsing_data = 0;
  2125. u16 pkt_prod, bd_prod;
  2126. int nbd, txq_index, fp_index, txdata_index;
  2127. dma_addr_t mapping;
  2128. u32 xmit_type = bnx2x_xmit_type(bp, skb);
  2129. int i;
  2130. u8 hlen = 0;
  2131. __le16 pkt_size = 0;
  2132. struct ethhdr *eth;
  2133. u8 mac_type = UNICAST_ADDRESS;
  2134. #ifdef BNX2X_STOP_ON_ERROR
  2135. if (unlikely(bp->panic))
  2136. return NETDEV_TX_BUSY;
  2137. #endif
  2138. txq_index = skb_get_queue_mapping(skb);
  2139. txq = netdev_get_tx_queue(dev, txq_index);
  2140. BUG_ON(txq_index >= MAX_ETH_TXQ_IDX(bp) + FCOE_PRESENT);
  2141. /* decode the fastpath index and the cos index from the txq */
  2142. fp_index = TXQ_TO_FP(txq_index);
  2143. txdata_index = TXQ_TO_COS(txq_index);
  2144. #ifdef BCM_CNIC
  2145. /*
  2146. * Override the above for the FCoE queue:
  2147. * - FCoE fp entry is right after the ETH entries.
  2148. * - FCoE L2 queue uses bp->txdata[0] only.
  2149. */
  2150. if (unlikely(!NO_FCOE(bp) && (txq_index ==
  2151. bnx2x_fcoe_tx(bp, txq_index)))) {
  2152. fp_index = FCOE_IDX;
  2153. txdata_index = 0;
  2154. }
  2155. #endif
  2156. /* enable this debug print to view the transmission queue being used
  2157. DP(BNX2X_MSG_FP, "indices: txq %d, fp %d, txdata %d",
  2158. txq_index, fp_index, txdata_index); */
  2159. /* locate the fastpath and the txdata */
  2160. fp = &bp->fp[fp_index];
  2161. txdata = &fp->txdata[txdata_index];
  2162. /* enable this debug print to view the tranmission details
  2163. DP(BNX2X_MSG_FP,"transmitting packet cid %d fp index %d txdata_index %d"
  2164. " tx_data ptr %p fp pointer %p",
  2165. txdata->cid, fp_index, txdata_index, txdata, fp); */
  2166. if (unlikely(bnx2x_tx_avail(bp, txdata) <
  2167. (skb_shinfo(skb)->nr_frags + 3))) {
  2168. fp->eth_q_stats.driver_xoff++;
  2169. netif_tx_stop_queue(txq);
  2170. BNX2X_ERR("BUG! Tx ring full when queue awake!\n");
  2171. return NETDEV_TX_BUSY;
  2172. }
  2173. DP(NETIF_MSG_TX_QUEUED, "queue[%d]: SKB: summed %x protocol %x "
  2174. "protocol(%x,%x) gso type %x xmit_type %x\n",
  2175. txq_index, skb->ip_summed, skb->protocol, ipv6_hdr(skb)->nexthdr,
  2176. ip_hdr(skb)->protocol, skb_shinfo(skb)->gso_type, xmit_type);
  2177. eth = (struct ethhdr *)skb->data;
  2178. /* set flag according to packet type (UNICAST_ADDRESS is default)*/
  2179. if (unlikely(is_multicast_ether_addr(eth->h_dest))) {
  2180. if (is_broadcast_ether_addr(eth->h_dest))
  2181. mac_type = BROADCAST_ADDRESS;
  2182. else
  2183. mac_type = MULTICAST_ADDRESS;
  2184. }
  2185. #if (MAX_SKB_FRAGS >= MAX_FETCH_BD - 3)
  2186. /* First, check if we need to linearize the skb (due to FW
  2187. restrictions). No need to check fragmentation if page size > 8K
  2188. (there will be no violation to FW restrictions) */
  2189. if (bnx2x_pkt_req_lin(bp, skb, xmit_type)) {
  2190. /* Statistics of linearization */
  2191. bp->lin_cnt++;
  2192. if (skb_linearize(skb) != 0) {
  2193. DP(NETIF_MSG_TX_QUEUED, "SKB linearization failed - "
  2194. "silently dropping this SKB\n");
  2195. dev_kfree_skb_any(skb);
  2196. return NETDEV_TX_OK;
  2197. }
  2198. }
  2199. #endif
  2200. /* Map skb linear data for DMA */
  2201. mapping = dma_map_single(&bp->pdev->dev, skb->data,
  2202. skb_headlen(skb), DMA_TO_DEVICE);
  2203. if (unlikely(dma_mapping_error(&bp->pdev->dev, mapping))) {
  2204. DP(NETIF_MSG_TX_QUEUED, "SKB mapping failed - "
  2205. "silently dropping this SKB\n");
  2206. dev_kfree_skb_any(skb);
  2207. return NETDEV_TX_OK;
  2208. }
  2209. /*
  2210. Please read carefully. First we use one BD which we mark as start,
  2211. then we have a parsing info BD (used for TSO or xsum),
  2212. and only then we have the rest of the TSO BDs.
  2213. (don't forget to mark the last one as last,
  2214. and to unmap only AFTER you write to the BD ...)
  2215. And above all, all pdb sizes are in words - NOT DWORDS!
  2216. */
  2217. /* get current pkt produced now - advance it just before sending packet
  2218. * since mapping of pages may fail and cause packet to be dropped
  2219. */
  2220. pkt_prod = txdata->tx_pkt_prod;
  2221. bd_prod = TX_BD(txdata->tx_bd_prod);
  2222. /* get a tx_buf and first BD
  2223. * tx_start_bd may be changed during SPLIT,
  2224. * but first_bd will always stay first
  2225. */
  2226. tx_buf = &txdata->tx_buf_ring[TX_BD(pkt_prod)];
  2227. tx_start_bd = &txdata->tx_desc_ring[bd_prod].start_bd;
  2228. first_bd = tx_start_bd;
  2229. tx_start_bd->bd_flags.as_bitfield = ETH_TX_BD_FLAGS_START_BD;
  2230. SET_FLAG(tx_start_bd->general_data, ETH_TX_START_BD_ETH_ADDR_TYPE,
  2231. mac_type);
  2232. /* header nbd */
  2233. SET_FLAG(tx_start_bd->general_data, ETH_TX_START_BD_HDR_NBDS, 1);
  2234. /* remember the first BD of the packet */
  2235. tx_buf->first_bd = txdata->tx_bd_prod;
  2236. tx_buf->skb = skb;
  2237. tx_buf->flags = 0;
  2238. DP(NETIF_MSG_TX_QUEUED,
  2239. "sending pkt %u @%p next_idx %u bd %u @%p\n",
  2240. pkt_prod, tx_buf, txdata->tx_pkt_prod, bd_prod, tx_start_bd);
  2241. if (vlan_tx_tag_present(skb)) {
  2242. tx_start_bd->vlan_or_ethertype =
  2243. cpu_to_le16(vlan_tx_tag_get(skb));
  2244. tx_start_bd->bd_flags.as_bitfield |=
  2245. (X_ETH_OUTBAND_VLAN << ETH_TX_BD_FLAGS_VLAN_MODE_SHIFT);
  2246. } else
  2247. tx_start_bd->vlan_or_ethertype = cpu_to_le16(pkt_prod);
  2248. /* turn on parsing and get a BD */
  2249. bd_prod = TX_BD(NEXT_TX_IDX(bd_prod));
  2250. if (xmit_type & XMIT_CSUM)
  2251. bnx2x_set_sbd_csum(bp, skb, tx_start_bd, xmit_type);
  2252. if (!CHIP_IS_E1x(bp)) {
  2253. pbd_e2 = &txdata->tx_desc_ring[bd_prod].parse_bd_e2;
  2254. memset(pbd_e2, 0, sizeof(struct eth_tx_parse_bd_e2));
  2255. /* Set PBD in checksum offload case */
  2256. if (xmit_type & XMIT_CSUM)
  2257. hlen = bnx2x_set_pbd_csum_e2(bp, skb,
  2258. &pbd_e2_parsing_data,
  2259. xmit_type);
  2260. if (IS_MF_SI(bp)) {
  2261. /*
  2262. * fill in the MAC addresses in the PBD - for local
  2263. * switching
  2264. */
  2265. bnx2x_set_fw_mac_addr(&pbd_e2->src_mac_addr_hi,
  2266. &pbd_e2->src_mac_addr_mid,
  2267. &pbd_e2->src_mac_addr_lo,
  2268. eth->h_source);
  2269. bnx2x_set_fw_mac_addr(&pbd_e2->dst_mac_addr_hi,
  2270. &pbd_e2->dst_mac_addr_mid,
  2271. &pbd_e2->dst_mac_addr_lo,
  2272. eth->h_dest);
  2273. }
  2274. } else {
  2275. pbd_e1x = &txdata->tx_desc_ring[bd_prod].parse_bd_e1x;
  2276. memset(pbd_e1x, 0, sizeof(struct eth_tx_parse_bd_e1x));
  2277. /* Set PBD in checksum offload case */
  2278. if (xmit_type & XMIT_CSUM)
  2279. hlen = bnx2x_set_pbd_csum(bp, skb, pbd_e1x, xmit_type);
  2280. }
  2281. /* Setup the data pointer of the first BD of the packet */
  2282. tx_start_bd->addr_hi = cpu_to_le32(U64_HI(mapping));
  2283. tx_start_bd->addr_lo = cpu_to_le32(U64_LO(mapping));
  2284. nbd = 2; /* start_bd + pbd + frags (updated when pages are mapped) */
  2285. tx_start_bd->nbytes = cpu_to_le16(skb_headlen(skb));
  2286. pkt_size = tx_start_bd->nbytes;
  2287. DP(NETIF_MSG_TX_QUEUED, "first bd @%p addr (%x:%x) nbd %d"
  2288. " nbytes %d flags %x vlan %x\n",
  2289. tx_start_bd, tx_start_bd->addr_hi, tx_start_bd->addr_lo,
  2290. le16_to_cpu(tx_start_bd->nbd), le16_to_cpu(tx_start_bd->nbytes),
  2291. tx_start_bd->bd_flags.as_bitfield,
  2292. le16_to_cpu(tx_start_bd->vlan_or_ethertype));
  2293. if (xmit_type & XMIT_GSO) {
  2294. DP(NETIF_MSG_TX_QUEUED,
  2295. "TSO packet len %d hlen %d total len %d tso size %d\n",
  2296. skb->len, hlen, skb_headlen(skb),
  2297. skb_shinfo(skb)->gso_size);
  2298. tx_start_bd->bd_flags.as_bitfield |= ETH_TX_BD_FLAGS_SW_LSO;
  2299. if (unlikely(skb_headlen(skb) > hlen))
  2300. bd_prod = bnx2x_tx_split(bp, txdata, tx_buf,
  2301. &tx_start_bd, hlen,
  2302. bd_prod, ++nbd);
  2303. if (!CHIP_IS_E1x(bp))
  2304. bnx2x_set_pbd_gso_e2(skb, &pbd_e2_parsing_data,
  2305. xmit_type);
  2306. else
  2307. bnx2x_set_pbd_gso(skb, pbd_e1x, xmit_type);
  2308. }
  2309. /* Set the PBD's parsing_data field if not zero
  2310. * (for the chips newer than 57711).
  2311. */
  2312. if (pbd_e2_parsing_data)
  2313. pbd_e2->parsing_data = cpu_to_le32(pbd_e2_parsing_data);
  2314. tx_data_bd = (struct eth_tx_bd *)tx_start_bd;
  2315. /* Handle fragmented skb */
  2316. for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) {
  2317. skb_frag_t *frag = &skb_shinfo(skb)->frags[i];
  2318. mapping = dma_map_page(&bp->pdev->dev, frag->page,
  2319. frag->page_offset, frag->size,
  2320. DMA_TO_DEVICE);
  2321. if (unlikely(dma_mapping_error(&bp->pdev->dev, mapping))) {
  2322. DP(NETIF_MSG_TX_QUEUED, "Unable to map page - "
  2323. "dropping packet...\n");
  2324. /* we need unmap all buffers already mapped
  2325. * for this SKB;
  2326. * first_bd->nbd need to be properly updated
  2327. * before call to bnx2x_free_tx_pkt
  2328. */
  2329. first_bd->nbd = cpu_to_le16(nbd);
  2330. bnx2x_free_tx_pkt(bp, txdata,
  2331. TX_BD(txdata->tx_pkt_prod));
  2332. return NETDEV_TX_OK;
  2333. }
  2334. bd_prod = TX_BD(NEXT_TX_IDX(bd_prod));
  2335. tx_data_bd = &txdata->tx_desc_ring[bd_prod].reg_bd;
  2336. if (total_pkt_bd == NULL)
  2337. total_pkt_bd = &txdata->tx_desc_ring[bd_prod].reg_bd;
  2338. tx_data_bd->addr_hi = cpu_to_le32(U64_HI(mapping));
  2339. tx_data_bd->addr_lo = cpu_to_le32(U64_LO(mapping));
  2340. tx_data_bd->nbytes = cpu_to_le16(frag->size);
  2341. le16_add_cpu(&pkt_size, frag->size);
  2342. nbd++;
  2343. DP(NETIF_MSG_TX_QUEUED,
  2344. "frag %d bd @%p addr (%x:%x) nbytes %d\n",
  2345. i, tx_data_bd, tx_data_bd->addr_hi, tx_data_bd->addr_lo,
  2346. le16_to_cpu(tx_data_bd->nbytes));
  2347. }
  2348. DP(NETIF_MSG_TX_QUEUED, "last bd @%p\n", tx_data_bd);
  2349. /* update with actual num BDs */
  2350. first_bd->nbd = cpu_to_le16(nbd);
  2351. bd_prod = TX_BD(NEXT_TX_IDX(bd_prod));
  2352. /* now send a tx doorbell, counting the next BD
  2353. * if the packet contains or ends with it
  2354. */
  2355. if (TX_BD_POFF(bd_prod) < nbd)
  2356. nbd++;
  2357. /* total_pkt_bytes should be set on the first data BD if
  2358. * it's not an LSO packet and there is more than one
  2359. * data BD. In this case pkt_size is limited by an MTU value.
  2360. * However we prefer to set it for an LSO packet (while we don't
  2361. * have to) in order to save some CPU cycles in a none-LSO
  2362. * case, when we much more care about them.
  2363. */
  2364. if (total_pkt_bd != NULL)
  2365. total_pkt_bd->total_pkt_bytes = pkt_size;
  2366. if (pbd_e1x)
  2367. DP(NETIF_MSG_TX_QUEUED,
  2368. "PBD (E1X) @%p ip_data %x ip_hlen %u ip_id %u lso_mss %u"
  2369. " tcp_flags %x xsum %x seq %u hlen %u\n",
  2370. pbd_e1x, pbd_e1x->global_data, pbd_e1x->ip_hlen_w,
  2371. pbd_e1x->ip_id, pbd_e1x->lso_mss, pbd_e1x->tcp_flags,
  2372. pbd_e1x->tcp_pseudo_csum, pbd_e1x->tcp_send_seq,
  2373. le16_to_cpu(pbd_e1x->total_hlen_w));
  2374. if (pbd_e2)
  2375. DP(NETIF_MSG_TX_QUEUED,
  2376. "PBD (E2) @%p dst %x %x %x src %x %x %x parsing_data %x\n",
  2377. pbd_e2, pbd_e2->dst_mac_addr_hi, pbd_e2->dst_mac_addr_mid,
  2378. pbd_e2->dst_mac_addr_lo, pbd_e2->src_mac_addr_hi,
  2379. pbd_e2->src_mac_addr_mid, pbd_e2->src_mac_addr_lo,
  2380. pbd_e2->parsing_data);
  2381. DP(NETIF_MSG_TX_QUEUED, "doorbell: nbd %d bd %u\n", nbd, bd_prod);
  2382. txdata->tx_pkt_prod++;
  2383. /*
  2384. * Make sure that the BD data is updated before updating the producer
  2385. * since FW might read the BD right after the producer is updated.
  2386. * This is only applicable for weak-ordered memory model archs such
  2387. * as IA-64. The following barrier is also mandatory since FW will
  2388. * assumes packets must have BDs.
  2389. */
  2390. wmb();
  2391. txdata->tx_db.data.prod += nbd;
  2392. barrier();
  2393. DOORBELL(bp, txdata->cid, txdata->tx_db.raw);
  2394. mmiowb();
  2395. txdata->tx_bd_prod += nbd;
  2396. if (unlikely(bnx2x_tx_avail(bp, txdata) < MAX_SKB_FRAGS + 3)) {
  2397. netif_tx_stop_queue(txq);
  2398. /* paired memory barrier is in bnx2x_tx_int(), we have to keep
  2399. * ordering of set_bit() in netif_tx_stop_queue() and read of
  2400. * fp->bd_tx_cons */
  2401. smp_mb();
  2402. fp->eth_q_stats.driver_xoff++;
  2403. if (bnx2x_tx_avail(bp, txdata) >= MAX_SKB_FRAGS + 3)
  2404. netif_tx_wake_queue(txq);
  2405. }
  2406. txdata->tx_pkt++;
  2407. return NETDEV_TX_OK;
  2408. }
  2409. /**
  2410. * bnx2x_setup_tc - routine to configure net_device for multi tc
  2411. *
  2412. * @netdev: net device to configure
  2413. * @tc: number of traffic classes to enable
  2414. *
  2415. * callback connected to the ndo_setup_tc function pointer
  2416. */
  2417. int bnx2x_setup_tc(struct net_device *dev, u8 num_tc)
  2418. {
  2419. int cos, prio, count, offset;
  2420. struct bnx2x *bp = netdev_priv(dev);
  2421. /* setup tc must be called under rtnl lock */
  2422. ASSERT_RTNL();
  2423. /* no traffic classes requested. aborting */
  2424. if (!num_tc) {
  2425. netdev_reset_tc(dev);
  2426. return 0;
  2427. }
  2428. /* requested to support too many traffic classes */
  2429. if (num_tc > bp->max_cos) {
  2430. DP(NETIF_MSG_TX_ERR, "support for too many traffic classes"
  2431. " requested: %d. max supported is %d",
  2432. num_tc, bp->max_cos);
  2433. return -EINVAL;
  2434. }
  2435. /* declare amount of supported traffic classes */
  2436. if (netdev_set_num_tc(dev, num_tc)) {
  2437. DP(NETIF_MSG_TX_ERR, "failed to declare %d traffic classes",
  2438. num_tc);
  2439. return -EINVAL;
  2440. }
  2441. /* configure priority to traffic class mapping */
  2442. for (prio = 0; prio < BNX2X_MAX_PRIORITY; prio++) {
  2443. netdev_set_prio_tc_map(dev, prio, bp->prio_to_cos[prio]);
  2444. DP(BNX2X_MSG_SP, "mapping priority %d to tc %d",
  2445. prio, bp->prio_to_cos[prio]);
  2446. }
  2447. /* Use this configuration to diffrentiate tc0 from other COSes
  2448. This can be used for ets or pfc, and save the effort of setting
  2449. up a multio class queue disc or negotiating DCBX with a switch
  2450. netdev_set_prio_tc_map(dev, 0, 0);
  2451. DP(BNX2X_MSG_SP, "mapping priority %d to tc %d", 0, 0);
  2452. for (prio = 1; prio < 16; prio++) {
  2453. netdev_set_prio_tc_map(dev, prio, 1);
  2454. DP(BNX2X_MSG_SP, "mapping priority %d to tc %d", prio, 1);
  2455. } */
  2456. /* configure traffic class to transmission queue mapping */
  2457. for (cos = 0; cos < bp->max_cos; cos++) {
  2458. count = BNX2X_NUM_ETH_QUEUES(bp);
  2459. offset = cos * MAX_TXQS_PER_COS;
  2460. netdev_set_tc_queue(dev, cos, count, offset);
  2461. DP(BNX2X_MSG_SP, "mapping tc %d to offset %d count %d",
  2462. cos, offset, count);
  2463. }
  2464. return 0;
  2465. }
  2466. /* called with rtnl_lock */
  2467. int bnx2x_change_mac_addr(struct net_device *dev, void *p)
  2468. {
  2469. struct sockaddr *addr = p;
  2470. struct bnx2x *bp = netdev_priv(dev);
  2471. int rc = 0;
  2472. if (!is_valid_ether_addr((u8 *)(addr->sa_data)))
  2473. return -EINVAL;
  2474. if (netif_running(dev)) {
  2475. rc = bnx2x_set_eth_mac(bp, false);
  2476. if (rc)
  2477. return rc;
  2478. }
  2479. memcpy(dev->dev_addr, addr->sa_data, dev->addr_len);
  2480. if (netif_running(dev))
  2481. rc = bnx2x_set_eth_mac(bp, true);
  2482. return rc;
  2483. }
  2484. static void bnx2x_free_fp_mem_at(struct bnx2x *bp, int fp_index)
  2485. {
  2486. union host_hc_status_block *sb = &bnx2x_fp(bp, fp_index, status_blk);
  2487. struct bnx2x_fastpath *fp = &bp->fp[fp_index];
  2488. u8 cos;
  2489. /* Common */
  2490. #ifdef BCM_CNIC
  2491. if (IS_FCOE_IDX(fp_index)) {
  2492. memset(sb, 0, sizeof(union host_hc_status_block));
  2493. fp->status_blk_mapping = 0;
  2494. } else {
  2495. #endif
  2496. /* status blocks */
  2497. if (!CHIP_IS_E1x(bp))
  2498. BNX2X_PCI_FREE(sb->e2_sb,
  2499. bnx2x_fp(bp, fp_index,
  2500. status_blk_mapping),
  2501. sizeof(struct host_hc_status_block_e2));
  2502. else
  2503. BNX2X_PCI_FREE(sb->e1x_sb,
  2504. bnx2x_fp(bp, fp_index,
  2505. status_blk_mapping),
  2506. sizeof(struct host_hc_status_block_e1x));
  2507. #ifdef BCM_CNIC
  2508. }
  2509. #endif
  2510. /* Rx */
  2511. if (!skip_rx_queue(bp, fp_index)) {
  2512. bnx2x_free_rx_bds(fp);
  2513. /* fastpath rx rings: rx_buf rx_desc rx_comp */
  2514. BNX2X_FREE(bnx2x_fp(bp, fp_index, rx_buf_ring));
  2515. BNX2X_PCI_FREE(bnx2x_fp(bp, fp_index, rx_desc_ring),
  2516. bnx2x_fp(bp, fp_index, rx_desc_mapping),
  2517. sizeof(struct eth_rx_bd) * NUM_RX_BD);
  2518. BNX2X_PCI_FREE(bnx2x_fp(bp, fp_index, rx_comp_ring),
  2519. bnx2x_fp(bp, fp_index, rx_comp_mapping),
  2520. sizeof(struct eth_fast_path_rx_cqe) *
  2521. NUM_RCQ_BD);
  2522. /* SGE ring */
  2523. BNX2X_FREE(bnx2x_fp(bp, fp_index, rx_page_ring));
  2524. BNX2X_PCI_FREE(bnx2x_fp(bp, fp_index, rx_sge_ring),
  2525. bnx2x_fp(bp, fp_index, rx_sge_mapping),
  2526. BCM_PAGE_SIZE * NUM_RX_SGE_PAGES);
  2527. }
  2528. /* Tx */
  2529. if (!skip_tx_queue(bp, fp_index)) {
  2530. /* fastpath tx rings: tx_buf tx_desc */
  2531. for_each_cos_in_tx_queue(fp, cos) {
  2532. struct bnx2x_fp_txdata *txdata = &fp->txdata[cos];
  2533. DP(BNX2X_MSG_SP,
  2534. "freeing tx memory of fp %d cos %d cid %d",
  2535. fp_index, cos, txdata->cid);
  2536. BNX2X_FREE(txdata->tx_buf_ring);
  2537. BNX2X_PCI_FREE(txdata->tx_desc_ring,
  2538. txdata->tx_desc_mapping,
  2539. sizeof(union eth_tx_bd_types) * NUM_TX_BD);
  2540. }
  2541. }
  2542. /* end of fastpath */
  2543. }
  2544. void bnx2x_free_fp_mem(struct bnx2x *bp)
  2545. {
  2546. int i;
  2547. for_each_queue(bp, i)
  2548. bnx2x_free_fp_mem_at(bp, i);
  2549. }
  2550. static inline void set_sb_shortcuts(struct bnx2x *bp, int index)
  2551. {
  2552. union host_hc_status_block status_blk = bnx2x_fp(bp, index, status_blk);
  2553. if (!CHIP_IS_E1x(bp)) {
  2554. bnx2x_fp(bp, index, sb_index_values) =
  2555. (__le16 *)status_blk.e2_sb->sb.index_values;
  2556. bnx2x_fp(bp, index, sb_running_index) =
  2557. (__le16 *)status_blk.e2_sb->sb.running_index;
  2558. } else {
  2559. bnx2x_fp(bp, index, sb_index_values) =
  2560. (__le16 *)status_blk.e1x_sb->sb.index_values;
  2561. bnx2x_fp(bp, index, sb_running_index) =
  2562. (__le16 *)status_blk.e1x_sb->sb.running_index;
  2563. }
  2564. }
  2565. static int bnx2x_alloc_fp_mem_at(struct bnx2x *bp, int index)
  2566. {
  2567. union host_hc_status_block *sb;
  2568. struct bnx2x_fastpath *fp = &bp->fp[index];
  2569. int ring_size = 0;
  2570. u8 cos;
  2571. int rx_ring_size = 0;
  2572. /* if rx_ring_size specified - use it */
  2573. if (!bp->rx_ring_size) {
  2574. rx_ring_size = MAX_RX_AVAIL/BNX2X_NUM_RX_QUEUES(bp);
  2575. /* allocate at least number of buffers required by FW */
  2576. rx_ring_size = max_t(int, bp->disable_tpa ? MIN_RX_SIZE_NONTPA :
  2577. MIN_RX_SIZE_TPA, rx_ring_size);
  2578. bp->rx_ring_size = rx_ring_size;
  2579. } else
  2580. rx_ring_size = bp->rx_ring_size;
  2581. /* Common */
  2582. sb = &bnx2x_fp(bp, index, status_blk);
  2583. #ifdef BCM_CNIC
  2584. if (!IS_FCOE_IDX(index)) {
  2585. #endif
  2586. /* status blocks */
  2587. if (!CHIP_IS_E1x(bp))
  2588. BNX2X_PCI_ALLOC(sb->e2_sb,
  2589. &bnx2x_fp(bp, index, status_blk_mapping),
  2590. sizeof(struct host_hc_status_block_e2));
  2591. else
  2592. BNX2X_PCI_ALLOC(sb->e1x_sb,
  2593. &bnx2x_fp(bp, index, status_blk_mapping),
  2594. sizeof(struct host_hc_status_block_e1x));
  2595. #ifdef BCM_CNIC
  2596. }
  2597. #endif
  2598. /* FCoE Queue uses Default SB and doesn't ACK the SB, thus no need to
  2599. * set shortcuts for it.
  2600. */
  2601. if (!IS_FCOE_IDX(index))
  2602. set_sb_shortcuts(bp, index);
  2603. /* Tx */
  2604. if (!skip_tx_queue(bp, index)) {
  2605. /* fastpath tx rings: tx_buf tx_desc */
  2606. for_each_cos_in_tx_queue(fp, cos) {
  2607. struct bnx2x_fp_txdata *txdata = &fp->txdata[cos];
  2608. DP(BNX2X_MSG_SP, "allocating tx memory of "
  2609. "fp %d cos %d",
  2610. index, cos);
  2611. BNX2X_ALLOC(txdata->tx_buf_ring,
  2612. sizeof(struct sw_tx_bd) * NUM_TX_BD);
  2613. BNX2X_PCI_ALLOC(txdata->tx_desc_ring,
  2614. &txdata->tx_desc_mapping,
  2615. sizeof(union eth_tx_bd_types) * NUM_TX_BD);
  2616. }
  2617. }
  2618. /* Rx */
  2619. if (!skip_rx_queue(bp, index)) {
  2620. /* fastpath rx rings: rx_buf rx_desc rx_comp */
  2621. BNX2X_ALLOC(bnx2x_fp(bp, index, rx_buf_ring),
  2622. sizeof(struct sw_rx_bd) * NUM_RX_BD);
  2623. BNX2X_PCI_ALLOC(bnx2x_fp(bp, index, rx_desc_ring),
  2624. &bnx2x_fp(bp, index, rx_desc_mapping),
  2625. sizeof(struct eth_rx_bd) * NUM_RX_BD);
  2626. BNX2X_PCI_ALLOC(bnx2x_fp(bp, index, rx_comp_ring),
  2627. &bnx2x_fp(bp, index, rx_comp_mapping),
  2628. sizeof(struct eth_fast_path_rx_cqe) *
  2629. NUM_RCQ_BD);
  2630. /* SGE ring */
  2631. BNX2X_ALLOC(bnx2x_fp(bp, index, rx_page_ring),
  2632. sizeof(struct sw_rx_page) * NUM_RX_SGE);
  2633. BNX2X_PCI_ALLOC(bnx2x_fp(bp, index, rx_sge_ring),
  2634. &bnx2x_fp(bp, index, rx_sge_mapping),
  2635. BCM_PAGE_SIZE * NUM_RX_SGE_PAGES);
  2636. /* RX BD ring */
  2637. bnx2x_set_next_page_rx_bd(fp);
  2638. /* CQ ring */
  2639. bnx2x_set_next_page_rx_cq(fp);
  2640. /* BDs */
  2641. ring_size = bnx2x_alloc_rx_bds(fp, rx_ring_size);
  2642. if (ring_size < rx_ring_size)
  2643. goto alloc_mem_err;
  2644. }
  2645. return 0;
  2646. /* handles low memory cases */
  2647. alloc_mem_err:
  2648. BNX2X_ERR("Unable to allocate full memory for queue %d (size %d)\n",
  2649. index, ring_size);
  2650. /* FW will drop all packets if queue is not big enough,
  2651. * In these cases we disable the queue
  2652. * Min size is different for OOO, TPA and non-TPA queues
  2653. */
  2654. if (ring_size < (fp->disable_tpa ?
  2655. MIN_RX_SIZE_NONTPA : MIN_RX_SIZE_TPA)) {
  2656. /* release memory allocated for this queue */
  2657. bnx2x_free_fp_mem_at(bp, index);
  2658. return -ENOMEM;
  2659. }
  2660. return 0;
  2661. }
  2662. int bnx2x_alloc_fp_mem(struct bnx2x *bp)
  2663. {
  2664. int i;
  2665. /**
  2666. * 1. Allocate FP for leading - fatal if error
  2667. * 2. {CNIC} Allocate FCoE FP - fatal if error
  2668. * 3. {CNIC} Allocate OOO + FWD - disable OOO if error
  2669. * 4. Allocate RSS - fix number of queues if error
  2670. */
  2671. /* leading */
  2672. if (bnx2x_alloc_fp_mem_at(bp, 0))
  2673. return -ENOMEM;
  2674. #ifdef BCM_CNIC
  2675. if (!NO_FCOE(bp))
  2676. /* FCoE */
  2677. if (bnx2x_alloc_fp_mem_at(bp, FCOE_IDX))
  2678. /* we will fail load process instead of mark
  2679. * NO_FCOE_FLAG
  2680. */
  2681. return -ENOMEM;
  2682. #endif
  2683. /* RSS */
  2684. for_each_nondefault_eth_queue(bp, i)
  2685. if (bnx2x_alloc_fp_mem_at(bp, i))
  2686. break;
  2687. /* handle memory failures */
  2688. if (i != BNX2X_NUM_ETH_QUEUES(bp)) {
  2689. int delta = BNX2X_NUM_ETH_QUEUES(bp) - i;
  2690. WARN_ON(delta < 0);
  2691. #ifdef BCM_CNIC
  2692. /**
  2693. * move non eth FPs next to last eth FP
  2694. * must be done in that order
  2695. * FCOE_IDX < FWD_IDX < OOO_IDX
  2696. */
  2697. /* move FCoE fp even NO_FCOE_FLAG is on */
  2698. bnx2x_move_fp(bp, FCOE_IDX, FCOE_IDX - delta);
  2699. #endif
  2700. bp->num_queues -= delta;
  2701. BNX2X_ERR("Adjusted num of queues from %d to %d\n",
  2702. bp->num_queues + delta, bp->num_queues);
  2703. }
  2704. return 0;
  2705. }
  2706. void bnx2x_free_mem_bp(struct bnx2x *bp)
  2707. {
  2708. kfree(bp->fp);
  2709. kfree(bp->msix_table);
  2710. kfree(bp->ilt);
  2711. }
  2712. int __devinit bnx2x_alloc_mem_bp(struct bnx2x *bp)
  2713. {
  2714. struct bnx2x_fastpath *fp;
  2715. struct msix_entry *tbl;
  2716. struct bnx2x_ilt *ilt;
  2717. int msix_table_size = 0;
  2718. /*
  2719. * The biggest MSI-X table we might need is as a maximum number of fast
  2720. * path IGU SBs plus default SB (for PF).
  2721. */
  2722. msix_table_size = bp->igu_sb_cnt + 1;
  2723. /* fp array: RSS plus CNIC related L2 queues */
  2724. fp = kzalloc((BNX2X_MAX_RSS_COUNT(bp) + NON_ETH_CONTEXT_USE) *
  2725. sizeof(*fp), GFP_KERNEL);
  2726. if (!fp)
  2727. goto alloc_err;
  2728. bp->fp = fp;
  2729. /* msix table */
  2730. tbl = kzalloc(msix_table_size * sizeof(*tbl), GFP_KERNEL);
  2731. if (!tbl)
  2732. goto alloc_err;
  2733. bp->msix_table = tbl;
  2734. /* ilt */
  2735. ilt = kzalloc(sizeof(*ilt), GFP_KERNEL);
  2736. if (!ilt)
  2737. goto alloc_err;
  2738. bp->ilt = ilt;
  2739. return 0;
  2740. alloc_err:
  2741. bnx2x_free_mem_bp(bp);
  2742. return -ENOMEM;
  2743. }
  2744. int bnx2x_reload_if_running(struct net_device *dev)
  2745. {
  2746. struct bnx2x *bp = netdev_priv(dev);
  2747. if (unlikely(!netif_running(dev)))
  2748. return 0;
  2749. bnx2x_nic_unload(bp, UNLOAD_NORMAL);
  2750. return bnx2x_nic_load(bp, LOAD_NORMAL);
  2751. }
  2752. int bnx2x_get_cur_phy_idx(struct bnx2x *bp)
  2753. {
  2754. u32 sel_phy_idx = 0;
  2755. if (bp->link_params.num_phys <= 1)
  2756. return INT_PHY;
  2757. if (bp->link_vars.link_up) {
  2758. sel_phy_idx = EXT_PHY1;
  2759. /* In case link is SERDES, check if the EXT_PHY2 is the one */
  2760. if ((bp->link_vars.link_status & LINK_STATUS_SERDES_LINK) &&
  2761. (bp->link_params.phy[EXT_PHY2].supported & SUPPORTED_FIBRE))
  2762. sel_phy_idx = EXT_PHY2;
  2763. } else {
  2764. switch (bnx2x_phy_selection(&bp->link_params)) {
  2765. case PORT_HW_CFG_PHY_SELECTION_HARDWARE_DEFAULT:
  2766. case PORT_HW_CFG_PHY_SELECTION_FIRST_PHY:
  2767. case PORT_HW_CFG_PHY_SELECTION_FIRST_PHY_PRIORITY:
  2768. sel_phy_idx = EXT_PHY1;
  2769. break;
  2770. case PORT_HW_CFG_PHY_SELECTION_SECOND_PHY:
  2771. case PORT_HW_CFG_PHY_SELECTION_SECOND_PHY_PRIORITY:
  2772. sel_phy_idx = EXT_PHY2;
  2773. break;
  2774. }
  2775. }
  2776. return sel_phy_idx;
  2777. }
  2778. int bnx2x_get_link_cfg_idx(struct bnx2x *bp)
  2779. {
  2780. u32 sel_phy_idx = bnx2x_get_cur_phy_idx(bp);
  2781. /*
  2782. * The selected actived PHY is always after swapping (in case PHY
  2783. * swapping is enabled). So when swapping is enabled, we need to reverse
  2784. * the configuration
  2785. */
  2786. if (bp->link_params.multi_phy_config &
  2787. PORT_HW_CFG_PHY_SWAPPED_ENABLED) {
  2788. if (sel_phy_idx == EXT_PHY1)
  2789. sel_phy_idx = EXT_PHY2;
  2790. else if (sel_phy_idx == EXT_PHY2)
  2791. sel_phy_idx = EXT_PHY1;
  2792. }
  2793. return LINK_CONFIG_IDX(sel_phy_idx);
  2794. }
  2795. #if defined(NETDEV_FCOE_WWNN) && defined(BCM_CNIC)
  2796. int bnx2x_fcoe_get_wwn(struct net_device *dev, u64 *wwn, int type)
  2797. {
  2798. struct bnx2x *bp = netdev_priv(dev);
  2799. struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
  2800. switch (type) {
  2801. case NETDEV_FCOE_WWNN:
  2802. *wwn = HILO_U64(cp->fcoe_wwn_node_name_hi,
  2803. cp->fcoe_wwn_node_name_lo);
  2804. break;
  2805. case NETDEV_FCOE_WWPN:
  2806. *wwn = HILO_U64(cp->fcoe_wwn_port_name_hi,
  2807. cp->fcoe_wwn_port_name_lo);
  2808. break;
  2809. default:
  2810. return -EINVAL;
  2811. }
  2812. return 0;
  2813. }
  2814. #endif
  2815. /* called with rtnl_lock */
  2816. int bnx2x_change_mtu(struct net_device *dev, int new_mtu)
  2817. {
  2818. struct bnx2x *bp = netdev_priv(dev);
  2819. if (bp->recovery_state != BNX2X_RECOVERY_DONE) {
  2820. printk(KERN_ERR "Handling parity error recovery. Try again later\n");
  2821. return -EAGAIN;
  2822. }
  2823. if ((new_mtu > ETH_MAX_JUMBO_PACKET_SIZE) ||
  2824. ((new_mtu + ETH_HLEN) < ETH_MIN_PACKET_SIZE))
  2825. return -EINVAL;
  2826. /* This does not race with packet allocation
  2827. * because the actual alloc size is
  2828. * only updated as part of load
  2829. */
  2830. dev->mtu = new_mtu;
  2831. return bnx2x_reload_if_running(dev);
  2832. }
  2833. u32 bnx2x_fix_features(struct net_device *dev, u32 features)
  2834. {
  2835. struct bnx2x *bp = netdev_priv(dev);
  2836. /* TPA requires Rx CSUM offloading */
  2837. if (!(features & NETIF_F_RXCSUM) || bp->disable_tpa)
  2838. features &= ~NETIF_F_LRO;
  2839. return features;
  2840. }
  2841. int bnx2x_set_features(struct net_device *dev, u32 features)
  2842. {
  2843. struct bnx2x *bp = netdev_priv(dev);
  2844. u32 flags = bp->flags;
  2845. bool bnx2x_reload = false;
  2846. if (features & NETIF_F_LRO)
  2847. flags |= TPA_ENABLE_FLAG;
  2848. else
  2849. flags &= ~TPA_ENABLE_FLAG;
  2850. if (features & NETIF_F_LOOPBACK) {
  2851. if (bp->link_params.loopback_mode != LOOPBACK_BMAC) {
  2852. bp->link_params.loopback_mode = LOOPBACK_BMAC;
  2853. bnx2x_reload = true;
  2854. }
  2855. } else {
  2856. if (bp->link_params.loopback_mode != LOOPBACK_NONE) {
  2857. bp->link_params.loopback_mode = LOOPBACK_NONE;
  2858. bnx2x_reload = true;
  2859. }
  2860. }
  2861. if (flags ^ bp->flags) {
  2862. bp->flags = flags;
  2863. bnx2x_reload = true;
  2864. }
  2865. if (bnx2x_reload) {
  2866. if (bp->recovery_state == BNX2X_RECOVERY_DONE)
  2867. return bnx2x_reload_if_running(dev);
  2868. /* else: bnx2x_nic_load() will be called at end of recovery */
  2869. }
  2870. return 0;
  2871. }
  2872. void bnx2x_tx_timeout(struct net_device *dev)
  2873. {
  2874. struct bnx2x *bp = netdev_priv(dev);
  2875. #ifdef BNX2X_STOP_ON_ERROR
  2876. if (!bp->panic)
  2877. bnx2x_panic();
  2878. #endif
  2879. smp_mb__before_clear_bit();
  2880. set_bit(BNX2X_SP_RTNL_TX_TIMEOUT, &bp->sp_rtnl_state);
  2881. smp_mb__after_clear_bit();
  2882. /* This allows the netif to be shutdown gracefully before resetting */
  2883. schedule_delayed_work(&bp->sp_rtnl_task, 0);
  2884. }
  2885. int bnx2x_suspend(struct pci_dev *pdev, pm_message_t state)
  2886. {
  2887. struct net_device *dev = pci_get_drvdata(pdev);
  2888. struct bnx2x *bp;
  2889. if (!dev) {
  2890. dev_err(&pdev->dev, "BAD net device from bnx2x_init_one\n");
  2891. return -ENODEV;
  2892. }
  2893. bp = netdev_priv(dev);
  2894. rtnl_lock();
  2895. pci_save_state(pdev);
  2896. if (!netif_running(dev)) {
  2897. rtnl_unlock();
  2898. return 0;
  2899. }
  2900. netif_device_detach(dev);
  2901. bnx2x_nic_unload(bp, UNLOAD_CLOSE);
  2902. bnx2x_set_power_state(bp, pci_choose_state(pdev, state));
  2903. rtnl_unlock();
  2904. return 0;
  2905. }
  2906. int bnx2x_resume(struct pci_dev *pdev)
  2907. {
  2908. struct net_device *dev = pci_get_drvdata(pdev);
  2909. struct bnx2x *bp;
  2910. int rc;
  2911. if (!dev) {
  2912. dev_err(&pdev->dev, "BAD net device from bnx2x_init_one\n");
  2913. return -ENODEV;
  2914. }
  2915. bp = netdev_priv(dev);
  2916. if (bp->recovery_state != BNX2X_RECOVERY_DONE) {
  2917. printk(KERN_ERR "Handling parity error recovery. Try again later\n");
  2918. return -EAGAIN;
  2919. }
  2920. rtnl_lock();
  2921. pci_restore_state(pdev);
  2922. if (!netif_running(dev)) {
  2923. rtnl_unlock();
  2924. return 0;
  2925. }
  2926. bnx2x_set_power_state(bp, PCI_D0);
  2927. netif_device_attach(dev);
  2928. /* Since the chip was reset, clear the FW sequence number */
  2929. bp->fw_seq = 0;
  2930. rc = bnx2x_nic_load(bp, LOAD_OPEN);
  2931. rtnl_unlock();
  2932. return rc;
  2933. }
  2934. void bnx2x_set_ctx_validation(struct bnx2x *bp, struct eth_context *cxt,
  2935. u32 cid)
  2936. {
  2937. /* ustorm cxt validation */
  2938. cxt->ustorm_ag_context.cdu_usage =
  2939. CDU_RSRVD_VALUE_TYPE_A(HW_CID(bp, cid),
  2940. CDU_REGION_NUMBER_UCM_AG, ETH_CONNECTION_TYPE);
  2941. /* xcontext validation */
  2942. cxt->xstorm_ag_context.cdu_reserved =
  2943. CDU_RSRVD_VALUE_TYPE_A(HW_CID(bp, cid),
  2944. CDU_REGION_NUMBER_XCM_AG, ETH_CONNECTION_TYPE);
  2945. }
  2946. static inline void storm_memset_hc_timeout(struct bnx2x *bp, u8 port,
  2947. u8 fw_sb_id, u8 sb_index,
  2948. u8 ticks)
  2949. {
  2950. u32 addr = BAR_CSTRORM_INTMEM +
  2951. CSTORM_STATUS_BLOCK_DATA_TIMEOUT_OFFSET(fw_sb_id, sb_index);
  2952. REG_WR8(bp, addr, ticks);
  2953. DP(NETIF_MSG_HW, "port %x fw_sb_id %d sb_index %d ticks %d\n",
  2954. port, fw_sb_id, sb_index, ticks);
  2955. }
  2956. static inline void storm_memset_hc_disable(struct bnx2x *bp, u8 port,
  2957. u16 fw_sb_id, u8 sb_index,
  2958. u8 disable)
  2959. {
  2960. u32 enable_flag = disable ? 0 : (1 << HC_INDEX_DATA_HC_ENABLED_SHIFT);
  2961. u32 addr = BAR_CSTRORM_INTMEM +
  2962. CSTORM_STATUS_BLOCK_DATA_FLAGS_OFFSET(fw_sb_id, sb_index);
  2963. u16 flags = REG_RD16(bp, addr);
  2964. /* clear and set */
  2965. flags &= ~HC_INDEX_DATA_HC_ENABLED;
  2966. flags |= enable_flag;
  2967. REG_WR16(bp, addr, flags);
  2968. DP(NETIF_MSG_HW, "port %x fw_sb_id %d sb_index %d disable %d\n",
  2969. port, fw_sb_id, sb_index, disable);
  2970. }
  2971. void bnx2x_update_coalesce_sb_index(struct bnx2x *bp, u8 fw_sb_id,
  2972. u8 sb_index, u8 disable, u16 usec)
  2973. {
  2974. int port = BP_PORT(bp);
  2975. u8 ticks = usec / BNX2X_BTR;
  2976. storm_memset_hc_timeout(bp, port, fw_sb_id, sb_index, ticks);
  2977. disable = disable ? 1 : (usec ? 0 : 1);
  2978. storm_memset_hc_disable(bp, port, fw_sb_id, sb_index, disable);
  2979. }