bnx2x_cmn.c 74 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957
  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/ip.h>
  20. #include <net/ipv6.h>
  21. #include <net/ip6_checksum.h>
  22. #include <linux/firmware.h>
  23. #include <linux/prefetch.h>
  24. #include "bnx2x_cmn.h"
  25. #include "bnx2x_init.h"
  26. static int bnx2x_setup_irqs(struct bnx2x *bp);
  27. /**
  28. * bnx2x_bz_fp - zero content of the fastpath structure.
  29. *
  30. * @bp: driver handle
  31. * @index: fastpath index to be zeroed
  32. *
  33. * Makes sure the contents of the bp->fp[index].napi is kept
  34. * intact.
  35. */
  36. static inline void bnx2x_bz_fp(struct bnx2x *bp, int index)
  37. {
  38. struct bnx2x_fastpath *fp = &bp->fp[index];
  39. struct napi_struct orig_napi = fp->napi;
  40. /* bzero bnx2x_fastpath contents */
  41. memset(fp, 0, sizeof(*fp));
  42. /* Restore the NAPI object as it has been already initialized */
  43. fp->napi = orig_napi;
  44. }
  45. /**
  46. * bnx2x_move_fp - move content of the fastpath structure.
  47. *
  48. * @bp: driver handle
  49. * @from: source FP index
  50. * @to: destination FP index
  51. *
  52. * Makes sure the contents of the bp->fp[to].napi is kept
  53. * intact.
  54. */
  55. static inline void bnx2x_move_fp(struct bnx2x *bp, int from, int to)
  56. {
  57. struct bnx2x_fastpath *from_fp = &bp->fp[from];
  58. struct bnx2x_fastpath *to_fp = &bp->fp[to];
  59. struct napi_struct orig_napi = to_fp->napi;
  60. /* Move bnx2x_fastpath contents */
  61. memcpy(to_fp, from_fp, sizeof(*to_fp));
  62. to_fp->index = to;
  63. /* Restore the NAPI object as it has been already initialized */
  64. to_fp->napi = orig_napi;
  65. }
  66. /* free skb in the packet ring at pos idx
  67. * return idx of last bd freed
  68. */
  69. static u16 bnx2x_free_tx_pkt(struct bnx2x *bp, struct bnx2x_fastpath *fp,
  70. u16 idx)
  71. {
  72. struct sw_tx_bd *tx_buf = &fp->tx_buf_ring[idx];
  73. struct eth_tx_start_bd *tx_start_bd;
  74. struct eth_tx_bd *tx_data_bd;
  75. struct sk_buff *skb = tx_buf->skb;
  76. u16 bd_idx = TX_BD(tx_buf->first_bd), new_cons;
  77. int nbd;
  78. /* prefetch skb end pointer to speedup dev_kfree_skb() */
  79. prefetch(&skb->end);
  80. DP(BNX2X_MSG_OFF, "pkt_idx %d buff @(%p)->skb %p\n",
  81. idx, tx_buf, skb);
  82. /* unmap first bd */
  83. DP(BNX2X_MSG_OFF, "free bd_idx %d\n", bd_idx);
  84. tx_start_bd = &fp->tx_desc_ring[bd_idx].start_bd;
  85. dma_unmap_single(&bp->pdev->dev, BD_UNMAP_ADDR(tx_start_bd),
  86. BD_UNMAP_LEN(tx_start_bd), DMA_TO_DEVICE);
  87. nbd = le16_to_cpu(tx_start_bd->nbd) - 1;
  88. #ifdef BNX2X_STOP_ON_ERROR
  89. if ((nbd - 1) > (MAX_SKB_FRAGS + 2)) {
  90. BNX2X_ERR("BAD nbd!\n");
  91. bnx2x_panic();
  92. }
  93. #endif
  94. new_cons = nbd + tx_buf->first_bd;
  95. /* Get the next bd */
  96. bd_idx = TX_BD(NEXT_TX_IDX(bd_idx));
  97. /* Skip a parse bd... */
  98. --nbd;
  99. bd_idx = TX_BD(NEXT_TX_IDX(bd_idx));
  100. /* ...and the TSO split header bd since they have no mapping */
  101. if (tx_buf->flags & BNX2X_TSO_SPLIT_BD) {
  102. --nbd;
  103. bd_idx = TX_BD(NEXT_TX_IDX(bd_idx));
  104. }
  105. /* now free frags */
  106. while (nbd > 0) {
  107. DP(BNX2X_MSG_OFF, "free frag bd_idx %d\n", bd_idx);
  108. tx_data_bd = &fp->tx_desc_ring[bd_idx].reg_bd;
  109. dma_unmap_page(&bp->pdev->dev, BD_UNMAP_ADDR(tx_data_bd),
  110. BD_UNMAP_LEN(tx_data_bd), DMA_TO_DEVICE);
  111. if (--nbd)
  112. bd_idx = TX_BD(NEXT_TX_IDX(bd_idx));
  113. }
  114. /* release skb */
  115. WARN_ON(!skb);
  116. dev_kfree_skb_any(skb);
  117. tx_buf->first_bd = 0;
  118. tx_buf->skb = NULL;
  119. return new_cons;
  120. }
  121. int bnx2x_tx_int(struct bnx2x_fastpath *fp)
  122. {
  123. struct bnx2x *bp = fp->bp;
  124. struct netdev_queue *txq;
  125. u16 hw_cons, sw_cons, bd_cons = fp->tx_bd_cons;
  126. #ifdef BNX2X_STOP_ON_ERROR
  127. if (unlikely(bp->panic))
  128. return -1;
  129. #endif
  130. txq = netdev_get_tx_queue(bp->dev, fp->index);
  131. hw_cons = le16_to_cpu(*fp->tx_cons_sb);
  132. sw_cons = fp->tx_pkt_cons;
  133. while (sw_cons != hw_cons) {
  134. u16 pkt_cons;
  135. pkt_cons = TX_BD(sw_cons);
  136. DP(NETIF_MSG_TX_DONE, "queue[%d]: hw_cons %u sw_cons %u "
  137. " pkt_cons %u\n",
  138. fp->index, hw_cons, sw_cons, pkt_cons);
  139. bd_cons = bnx2x_free_tx_pkt(bp, fp, pkt_cons);
  140. sw_cons++;
  141. }
  142. fp->tx_pkt_cons = sw_cons;
  143. fp->tx_bd_cons = bd_cons;
  144. /* Need to make the tx_bd_cons update visible to start_xmit()
  145. * before checking for netif_tx_queue_stopped(). Without the
  146. * memory barrier, there is a small possibility that
  147. * start_xmit() will miss it and cause the queue to be stopped
  148. * forever.
  149. */
  150. smp_mb();
  151. if (unlikely(netif_tx_queue_stopped(txq))) {
  152. /* Taking tx_lock() is needed to prevent reenabling the queue
  153. * while it's empty. This could have happen if rx_action() gets
  154. * suspended in bnx2x_tx_int() after the condition before
  155. * netif_tx_wake_queue(), while tx_action (bnx2x_start_xmit()):
  156. *
  157. * stops the queue->sees fresh tx_bd_cons->releases the queue->
  158. * sends some packets consuming the whole queue again->
  159. * stops the queue
  160. */
  161. __netif_tx_lock(txq, smp_processor_id());
  162. if ((netif_tx_queue_stopped(txq)) &&
  163. (bp->state == BNX2X_STATE_OPEN) &&
  164. (bnx2x_tx_avail(fp) >= MAX_SKB_FRAGS + 3))
  165. netif_tx_wake_queue(txq);
  166. __netif_tx_unlock(txq);
  167. }
  168. return 0;
  169. }
  170. static inline void bnx2x_update_last_max_sge(struct bnx2x_fastpath *fp,
  171. u16 idx)
  172. {
  173. u16 last_max = fp->last_max_sge;
  174. if (SUB_S16(idx, last_max) > 0)
  175. fp->last_max_sge = idx;
  176. }
  177. static void bnx2x_update_sge_prod(struct bnx2x_fastpath *fp,
  178. struct eth_fast_path_rx_cqe *fp_cqe)
  179. {
  180. struct bnx2x *bp = fp->bp;
  181. u16 sge_len = SGE_PAGE_ALIGN(le16_to_cpu(fp_cqe->pkt_len) -
  182. le16_to_cpu(fp_cqe->len_on_bd)) >>
  183. SGE_PAGE_SHIFT;
  184. u16 last_max, last_elem, first_elem;
  185. u16 delta = 0;
  186. u16 i;
  187. if (!sge_len)
  188. return;
  189. /* First mark all used pages */
  190. for (i = 0; i < sge_len; i++)
  191. SGE_MASK_CLEAR_BIT(fp,
  192. RX_SGE(le16_to_cpu(fp_cqe->sgl_or_raw_data.sgl[i])));
  193. DP(NETIF_MSG_RX_STATUS, "fp_cqe->sgl[%d] = %d\n",
  194. sge_len - 1, le16_to_cpu(fp_cqe->sgl_or_raw_data.sgl[sge_len - 1]));
  195. /* Here we assume that the last SGE index is the biggest */
  196. prefetch((void *)(fp->sge_mask));
  197. bnx2x_update_last_max_sge(fp,
  198. le16_to_cpu(fp_cqe->sgl_or_raw_data.sgl[sge_len - 1]));
  199. last_max = RX_SGE(fp->last_max_sge);
  200. last_elem = last_max >> RX_SGE_MASK_ELEM_SHIFT;
  201. first_elem = RX_SGE(fp->rx_sge_prod) >> RX_SGE_MASK_ELEM_SHIFT;
  202. /* If ring is not full */
  203. if (last_elem + 1 != first_elem)
  204. last_elem++;
  205. /* Now update the prod */
  206. for (i = first_elem; i != last_elem; i = NEXT_SGE_MASK_ELEM(i)) {
  207. if (likely(fp->sge_mask[i]))
  208. break;
  209. fp->sge_mask[i] = RX_SGE_MASK_ELEM_ONE_MASK;
  210. delta += RX_SGE_MASK_ELEM_SZ;
  211. }
  212. if (delta > 0) {
  213. fp->rx_sge_prod += delta;
  214. /* clear page-end entries */
  215. bnx2x_clear_sge_mask_next_elems(fp);
  216. }
  217. DP(NETIF_MSG_RX_STATUS,
  218. "fp->last_max_sge = %d fp->rx_sge_prod = %d\n",
  219. fp->last_max_sge, fp->rx_sge_prod);
  220. }
  221. static void bnx2x_tpa_start(struct bnx2x_fastpath *fp, u16 queue,
  222. struct sk_buff *skb, u16 cons, u16 prod)
  223. {
  224. struct bnx2x *bp = fp->bp;
  225. struct sw_rx_bd *cons_rx_buf = &fp->rx_buf_ring[cons];
  226. struct sw_rx_bd *prod_rx_buf = &fp->rx_buf_ring[prod];
  227. struct eth_rx_bd *prod_bd = &fp->rx_desc_ring[prod];
  228. dma_addr_t mapping;
  229. /* move empty skb from pool to prod and map it */
  230. prod_rx_buf->skb = fp->tpa_pool[queue].skb;
  231. mapping = dma_map_single(&bp->pdev->dev, fp->tpa_pool[queue].skb->data,
  232. fp->rx_buf_size, DMA_FROM_DEVICE);
  233. dma_unmap_addr_set(prod_rx_buf, mapping, mapping);
  234. /* move partial skb from cons to pool (don't unmap yet) */
  235. fp->tpa_pool[queue] = *cons_rx_buf;
  236. /* mark bin state as start - print error if current state != stop */
  237. if (fp->tpa_state[queue] != BNX2X_TPA_STOP)
  238. BNX2X_ERR("start of bin not in stop [%d]\n", queue);
  239. fp->tpa_state[queue] = BNX2X_TPA_START;
  240. /* point prod_bd to new skb */
  241. prod_bd->addr_hi = cpu_to_le32(U64_HI(mapping));
  242. prod_bd->addr_lo = cpu_to_le32(U64_LO(mapping));
  243. #ifdef BNX2X_STOP_ON_ERROR
  244. fp->tpa_queue_used |= (1 << queue);
  245. #ifdef _ASM_GENERIC_INT_L64_H
  246. DP(NETIF_MSG_RX_STATUS, "fp->tpa_queue_used = 0x%lx\n",
  247. #else
  248. DP(NETIF_MSG_RX_STATUS, "fp->tpa_queue_used = 0x%llx\n",
  249. #endif
  250. fp->tpa_queue_used);
  251. #endif
  252. }
  253. /* Timestamp option length allowed for TPA aggregation:
  254. *
  255. * nop nop kind length echo val
  256. */
  257. #define TPA_TSTAMP_OPT_LEN 12
  258. /**
  259. * bnx2x_set_lro_mss - calculate the approximate value of the MSS
  260. *
  261. * @bp: driver handle
  262. * @parsing_flags: parsing flags from the START CQE
  263. * @len_on_bd: total length of the first packet for the
  264. * aggregation.
  265. *
  266. * Approximate value of the MSS for this aggregation calculated using
  267. * the first packet of it.
  268. */
  269. static inline u16 bnx2x_set_lro_mss(struct bnx2x *bp, u16 parsing_flags,
  270. u16 len_on_bd)
  271. {
  272. /* TPA arrgregation won't have an IP options and TCP options
  273. * other than timestamp.
  274. */
  275. u16 hdrs_len = ETH_HLEN + sizeof(struct iphdr) + sizeof(struct tcphdr);
  276. /* Check if there was a TCP timestamp, if there is it's will
  277. * always be 12 bytes length: nop nop kind length echo val.
  278. *
  279. * Otherwise FW would close the aggregation.
  280. */
  281. if (parsing_flags & PARSING_FLAGS_TIME_STAMP_EXIST_FLAG)
  282. hdrs_len += TPA_TSTAMP_OPT_LEN;
  283. return len_on_bd - hdrs_len;
  284. }
  285. static int bnx2x_fill_frag_skb(struct bnx2x *bp, struct bnx2x_fastpath *fp,
  286. struct sk_buff *skb,
  287. struct eth_fast_path_rx_cqe *fp_cqe,
  288. u16 cqe_idx, u16 parsing_flags)
  289. {
  290. struct sw_rx_page *rx_pg, old_rx_pg;
  291. u16 len_on_bd = le16_to_cpu(fp_cqe->len_on_bd);
  292. u32 i, frag_len, frag_size, pages;
  293. int err;
  294. int j;
  295. frag_size = le16_to_cpu(fp_cqe->pkt_len) - len_on_bd;
  296. pages = SGE_PAGE_ALIGN(frag_size) >> SGE_PAGE_SHIFT;
  297. /* This is needed in order to enable forwarding support */
  298. if (frag_size)
  299. skb_shinfo(skb)->gso_size = bnx2x_set_lro_mss(bp, parsing_flags,
  300. len_on_bd);
  301. #ifdef BNX2X_STOP_ON_ERROR
  302. if (pages > min_t(u32, 8, MAX_SKB_FRAGS)*SGE_PAGE_SIZE*PAGES_PER_SGE) {
  303. BNX2X_ERR("SGL length is too long: %d. CQE index is %d\n",
  304. pages, cqe_idx);
  305. BNX2X_ERR("fp_cqe->pkt_len = %d fp_cqe->len_on_bd = %d\n",
  306. fp_cqe->pkt_len, len_on_bd);
  307. bnx2x_panic();
  308. return -EINVAL;
  309. }
  310. #endif
  311. /* Run through the SGL and compose the fragmented skb */
  312. for (i = 0, j = 0; i < pages; i += PAGES_PER_SGE, j++) {
  313. u16 sge_idx =
  314. RX_SGE(le16_to_cpu(fp_cqe->sgl_or_raw_data.sgl[j]));
  315. /* FW gives the indices of the SGE as if the ring is an array
  316. (meaning that "next" element will consume 2 indices) */
  317. frag_len = min(frag_size, (u32)(SGE_PAGE_SIZE*PAGES_PER_SGE));
  318. rx_pg = &fp->rx_page_ring[sge_idx];
  319. old_rx_pg = *rx_pg;
  320. /* If we fail to allocate a substitute page, we simply stop
  321. where we are and drop the whole packet */
  322. err = bnx2x_alloc_rx_sge(bp, fp, sge_idx);
  323. if (unlikely(err)) {
  324. fp->eth_q_stats.rx_skb_alloc_failed++;
  325. return err;
  326. }
  327. /* Unmap the page as we r going to pass it to the stack */
  328. dma_unmap_page(&bp->pdev->dev,
  329. dma_unmap_addr(&old_rx_pg, mapping),
  330. SGE_PAGE_SIZE*PAGES_PER_SGE, DMA_FROM_DEVICE);
  331. /* Add one frag and update the appropriate fields in the skb */
  332. skb_fill_page_desc(skb, j, old_rx_pg.page, 0, frag_len);
  333. skb->data_len += frag_len;
  334. skb->truesize += frag_len;
  335. skb->len += frag_len;
  336. frag_size -= frag_len;
  337. }
  338. return 0;
  339. }
  340. static void bnx2x_tpa_stop(struct bnx2x *bp, struct bnx2x_fastpath *fp,
  341. u16 queue, int pad, int len, union eth_rx_cqe *cqe,
  342. u16 cqe_idx)
  343. {
  344. struct sw_rx_bd *rx_buf = &fp->tpa_pool[queue];
  345. struct sk_buff *skb = rx_buf->skb;
  346. /* alloc new skb */
  347. struct sk_buff *new_skb = netdev_alloc_skb(bp->dev, fp->rx_buf_size);
  348. /* Unmap skb in the pool anyway, as we are going to change
  349. pool entry status to BNX2X_TPA_STOP even if new skb allocation
  350. fails. */
  351. dma_unmap_single(&bp->pdev->dev, dma_unmap_addr(rx_buf, mapping),
  352. fp->rx_buf_size, DMA_FROM_DEVICE);
  353. if (likely(new_skb)) {
  354. /* fix ip xsum and give it to the stack */
  355. /* (no need to map the new skb) */
  356. u16 parsing_flags =
  357. le16_to_cpu(cqe->fast_path_cqe.pars_flags.flags);
  358. prefetch(skb);
  359. prefetch(((char *)(skb)) + L1_CACHE_BYTES);
  360. #ifdef BNX2X_STOP_ON_ERROR
  361. if (pad + len > fp->rx_buf_size) {
  362. BNX2X_ERR("skb_put is about to fail... "
  363. "pad %d len %d rx_buf_size %d\n",
  364. pad, len, fp->rx_buf_size);
  365. bnx2x_panic();
  366. return;
  367. }
  368. #endif
  369. skb_reserve(skb, pad);
  370. skb_put(skb, len);
  371. skb->protocol = eth_type_trans(skb, bp->dev);
  372. skb->ip_summed = CHECKSUM_UNNECESSARY;
  373. {
  374. struct iphdr *iph;
  375. iph = (struct iphdr *)skb->data;
  376. iph->check = 0;
  377. iph->check = ip_fast_csum((u8 *)iph, iph->ihl);
  378. }
  379. if (!bnx2x_fill_frag_skb(bp, fp, skb,
  380. &cqe->fast_path_cqe, cqe_idx,
  381. parsing_flags)) {
  382. if (parsing_flags & PARSING_FLAGS_VLAN)
  383. __vlan_hwaccel_put_tag(skb,
  384. le16_to_cpu(cqe->fast_path_cqe.
  385. vlan_tag));
  386. napi_gro_receive(&fp->napi, skb);
  387. } else {
  388. DP(NETIF_MSG_RX_STATUS, "Failed to allocate new pages"
  389. " - dropping packet!\n");
  390. dev_kfree_skb_any(skb);
  391. }
  392. /* put new skb in bin */
  393. fp->tpa_pool[queue].skb = new_skb;
  394. } else {
  395. /* else drop the packet and keep the buffer in the bin */
  396. DP(NETIF_MSG_RX_STATUS,
  397. "Failed to allocate new skb - dropping packet!\n");
  398. fp->eth_q_stats.rx_skb_alloc_failed++;
  399. }
  400. fp->tpa_state[queue] = BNX2X_TPA_STOP;
  401. }
  402. /* Set Toeplitz hash value in the skb using the value from the
  403. * CQE (calculated by HW).
  404. */
  405. static inline void bnx2x_set_skb_rxhash(struct bnx2x *bp, union eth_rx_cqe *cqe,
  406. struct sk_buff *skb)
  407. {
  408. /* Set Toeplitz hash from CQE */
  409. if ((bp->dev->features & NETIF_F_RXHASH) &&
  410. (cqe->fast_path_cqe.status_flags &
  411. ETH_FAST_PATH_RX_CQE_RSS_HASH_FLG))
  412. skb->rxhash =
  413. le32_to_cpu(cqe->fast_path_cqe.rss_hash_result);
  414. }
  415. int bnx2x_rx_int(struct bnx2x_fastpath *fp, int budget)
  416. {
  417. struct bnx2x *bp = fp->bp;
  418. u16 bd_cons, bd_prod, bd_prod_fw, comp_ring_cons;
  419. u16 hw_comp_cons, sw_comp_cons, sw_comp_prod;
  420. int rx_pkt = 0;
  421. #ifdef BNX2X_STOP_ON_ERROR
  422. if (unlikely(bp->panic))
  423. return 0;
  424. #endif
  425. /* CQ "next element" is of the size of the regular element,
  426. that's why it's ok here */
  427. hw_comp_cons = le16_to_cpu(*fp->rx_cons_sb);
  428. if ((hw_comp_cons & MAX_RCQ_DESC_CNT) == MAX_RCQ_DESC_CNT)
  429. hw_comp_cons++;
  430. bd_cons = fp->rx_bd_cons;
  431. bd_prod = fp->rx_bd_prod;
  432. bd_prod_fw = bd_prod;
  433. sw_comp_cons = fp->rx_comp_cons;
  434. sw_comp_prod = fp->rx_comp_prod;
  435. /* Memory barrier necessary as speculative reads of the rx
  436. * buffer can be ahead of the index in the status block
  437. */
  438. rmb();
  439. DP(NETIF_MSG_RX_STATUS,
  440. "queue[%d]: hw_comp_cons %u sw_comp_cons %u\n",
  441. fp->index, hw_comp_cons, sw_comp_cons);
  442. while (sw_comp_cons != hw_comp_cons) {
  443. struct sw_rx_bd *rx_buf = NULL;
  444. struct sk_buff *skb;
  445. union eth_rx_cqe *cqe;
  446. u8 cqe_fp_flags;
  447. u16 len, pad;
  448. comp_ring_cons = RCQ_BD(sw_comp_cons);
  449. bd_prod = RX_BD(bd_prod);
  450. bd_cons = RX_BD(bd_cons);
  451. /* Prefetch the page containing the BD descriptor
  452. at producer's index. It will be needed when new skb is
  453. allocated */
  454. prefetch((void *)(PAGE_ALIGN((unsigned long)
  455. (&fp->rx_desc_ring[bd_prod])) -
  456. PAGE_SIZE + 1));
  457. cqe = &fp->rx_comp_ring[comp_ring_cons];
  458. cqe_fp_flags = cqe->fast_path_cqe.type_error_flags;
  459. DP(NETIF_MSG_RX_STATUS, "CQE type %x err %x status %x"
  460. " queue %x vlan %x len %u\n", CQE_TYPE(cqe_fp_flags),
  461. cqe_fp_flags, cqe->fast_path_cqe.status_flags,
  462. le32_to_cpu(cqe->fast_path_cqe.rss_hash_result),
  463. le16_to_cpu(cqe->fast_path_cqe.vlan_tag),
  464. le16_to_cpu(cqe->fast_path_cqe.pkt_len));
  465. /* is this a slowpath msg? */
  466. if (unlikely(CQE_TYPE(cqe_fp_flags))) {
  467. bnx2x_sp_event(fp, cqe);
  468. goto next_cqe;
  469. /* this is an rx packet */
  470. } else {
  471. rx_buf = &fp->rx_buf_ring[bd_cons];
  472. skb = rx_buf->skb;
  473. prefetch(skb);
  474. len = le16_to_cpu(cqe->fast_path_cqe.pkt_len);
  475. pad = cqe->fast_path_cqe.placement_offset;
  476. /* - If CQE is marked both TPA_START and TPA_END it is
  477. * a non-TPA CQE.
  478. * - FP CQE will always have either TPA_START or/and
  479. * TPA_STOP flags set.
  480. */
  481. if ((!fp->disable_tpa) &&
  482. (TPA_TYPE(cqe_fp_flags) !=
  483. (TPA_TYPE_START | TPA_TYPE_END))) {
  484. u16 queue = cqe->fast_path_cqe.queue_index;
  485. if (TPA_TYPE(cqe_fp_flags) == TPA_TYPE_START) {
  486. DP(NETIF_MSG_RX_STATUS,
  487. "calling tpa_start on queue %d\n",
  488. queue);
  489. bnx2x_tpa_start(fp, queue, skb,
  490. bd_cons, bd_prod);
  491. /* Set Toeplitz hash for an LRO skb */
  492. bnx2x_set_skb_rxhash(bp, cqe, skb);
  493. goto next_rx;
  494. } else { /* TPA_STOP */
  495. DP(NETIF_MSG_RX_STATUS,
  496. "calling tpa_stop on queue %d\n",
  497. queue);
  498. if (!BNX2X_RX_SUM_FIX(cqe))
  499. BNX2X_ERR("STOP on none TCP "
  500. "data\n");
  501. /* This is a size of the linear data
  502. on this skb */
  503. len = le16_to_cpu(cqe->fast_path_cqe.
  504. len_on_bd);
  505. bnx2x_tpa_stop(bp, fp, queue, pad,
  506. len, cqe, comp_ring_cons);
  507. #ifdef BNX2X_STOP_ON_ERROR
  508. if (bp->panic)
  509. return 0;
  510. #endif
  511. bnx2x_update_sge_prod(fp,
  512. &cqe->fast_path_cqe);
  513. goto next_cqe;
  514. }
  515. }
  516. dma_sync_single_for_device(&bp->pdev->dev,
  517. dma_unmap_addr(rx_buf, mapping),
  518. pad + RX_COPY_THRESH,
  519. DMA_FROM_DEVICE);
  520. prefetch(((char *)(skb)) + L1_CACHE_BYTES);
  521. /* is this an error packet? */
  522. if (unlikely(cqe_fp_flags & ETH_RX_ERROR_FALGS)) {
  523. DP(NETIF_MSG_RX_ERR,
  524. "ERROR flags %x rx packet %u\n",
  525. cqe_fp_flags, sw_comp_cons);
  526. fp->eth_q_stats.rx_err_discard_pkt++;
  527. goto reuse_rx;
  528. }
  529. /* Since we don't have a jumbo ring
  530. * copy small packets if mtu > 1500
  531. */
  532. if ((bp->dev->mtu > ETH_MAX_PACKET_SIZE) &&
  533. (len <= RX_COPY_THRESH)) {
  534. struct sk_buff *new_skb;
  535. new_skb = netdev_alloc_skb(bp->dev,
  536. len + pad);
  537. if (new_skb == NULL) {
  538. DP(NETIF_MSG_RX_ERR,
  539. "ERROR packet dropped "
  540. "because of alloc failure\n");
  541. fp->eth_q_stats.rx_skb_alloc_failed++;
  542. goto reuse_rx;
  543. }
  544. /* aligned copy */
  545. skb_copy_from_linear_data_offset(skb, pad,
  546. new_skb->data + pad, len);
  547. skb_reserve(new_skb, pad);
  548. skb_put(new_skb, len);
  549. bnx2x_reuse_rx_skb(fp, bd_cons, bd_prod);
  550. skb = new_skb;
  551. } else
  552. if (likely(bnx2x_alloc_rx_skb(bp, fp, bd_prod) == 0)) {
  553. dma_unmap_single(&bp->pdev->dev,
  554. dma_unmap_addr(rx_buf, mapping),
  555. fp->rx_buf_size,
  556. DMA_FROM_DEVICE);
  557. skb_reserve(skb, pad);
  558. skb_put(skb, len);
  559. } else {
  560. DP(NETIF_MSG_RX_ERR,
  561. "ERROR packet dropped because "
  562. "of alloc failure\n");
  563. fp->eth_q_stats.rx_skb_alloc_failed++;
  564. reuse_rx:
  565. bnx2x_reuse_rx_skb(fp, bd_cons, bd_prod);
  566. goto next_rx;
  567. }
  568. skb->protocol = eth_type_trans(skb, bp->dev);
  569. /* Set Toeplitz hash for a none-LRO skb */
  570. bnx2x_set_skb_rxhash(bp, cqe, skb);
  571. skb_checksum_none_assert(skb);
  572. if (bp->dev->features & NETIF_F_RXCSUM) {
  573. if (likely(BNX2X_RX_CSUM_OK(cqe)))
  574. skb->ip_summed = CHECKSUM_UNNECESSARY;
  575. else
  576. fp->eth_q_stats.hw_csum_err++;
  577. }
  578. }
  579. skb_record_rx_queue(skb, fp->index);
  580. if (le16_to_cpu(cqe->fast_path_cqe.pars_flags.flags) &
  581. PARSING_FLAGS_VLAN)
  582. __vlan_hwaccel_put_tag(skb,
  583. le16_to_cpu(cqe->fast_path_cqe.vlan_tag));
  584. napi_gro_receive(&fp->napi, skb);
  585. next_rx:
  586. rx_buf->skb = NULL;
  587. bd_cons = NEXT_RX_IDX(bd_cons);
  588. bd_prod = NEXT_RX_IDX(bd_prod);
  589. bd_prod_fw = NEXT_RX_IDX(bd_prod_fw);
  590. rx_pkt++;
  591. next_cqe:
  592. sw_comp_prod = NEXT_RCQ_IDX(sw_comp_prod);
  593. sw_comp_cons = NEXT_RCQ_IDX(sw_comp_cons);
  594. if (rx_pkt == budget)
  595. break;
  596. } /* while */
  597. fp->rx_bd_cons = bd_cons;
  598. fp->rx_bd_prod = bd_prod_fw;
  599. fp->rx_comp_cons = sw_comp_cons;
  600. fp->rx_comp_prod = sw_comp_prod;
  601. /* Update producers */
  602. bnx2x_update_rx_prod(bp, fp, bd_prod_fw, sw_comp_prod,
  603. fp->rx_sge_prod);
  604. fp->rx_pkt += rx_pkt;
  605. fp->rx_calls++;
  606. return rx_pkt;
  607. }
  608. static irqreturn_t bnx2x_msix_fp_int(int irq, void *fp_cookie)
  609. {
  610. struct bnx2x_fastpath *fp = fp_cookie;
  611. struct bnx2x *bp = fp->bp;
  612. /* Return here if interrupt is disabled */
  613. if (unlikely(atomic_read(&bp->intr_sem) != 0)) {
  614. DP(NETIF_MSG_INTR, "called but intr_sem not 0, returning\n");
  615. return IRQ_HANDLED;
  616. }
  617. DP(BNX2X_MSG_FP, "got an MSI-X interrupt on IDX:SB "
  618. "[fp %d fw_sd %d igusb %d]\n",
  619. fp->index, fp->fw_sb_id, fp->igu_sb_id);
  620. bnx2x_ack_sb(bp, fp->igu_sb_id, USTORM_ID, 0, IGU_INT_DISABLE, 0);
  621. #ifdef BNX2X_STOP_ON_ERROR
  622. if (unlikely(bp->panic))
  623. return IRQ_HANDLED;
  624. #endif
  625. /* Handle Rx and Tx according to MSI-X vector */
  626. prefetch(fp->rx_cons_sb);
  627. prefetch(fp->tx_cons_sb);
  628. prefetch(&fp->sb_running_index[SM_RX_ID]);
  629. napi_schedule(&bnx2x_fp(bp, fp->index, napi));
  630. return IRQ_HANDLED;
  631. }
  632. /* HW Lock for shared dual port PHYs */
  633. void bnx2x_acquire_phy_lock(struct bnx2x *bp)
  634. {
  635. mutex_lock(&bp->port.phy_mutex);
  636. if (bp->port.need_hw_lock)
  637. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_MDIO);
  638. }
  639. void bnx2x_release_phy_lock(struct bnx2x *bp)
  640. {
  641. if (bp->port.need_hw_lock)
  642. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_MDIO);
  643. mutex_unlock(&bp->port.phy_mutex);
  644. }
  645. /* calculates MF speed according to current linespeed and MF configuration */
  646. u16 bnx2x_get_mf_speed(struct bnx2x *bp)
  647. {
  648. u16 line_speed = bp->link_vars.line_speed;
  649. if (IS_MF(bp)) {
  650. u16 maxCfg = bnx2x_extract_max_cfg(bp,
  651. bp->mf_config[BP_VN(bp)]);
  652. /* Calculate the current MAX line speed limit for the MF
  653. * devices
  654. */
  655. if (IS_MF_SI(bp))
  656. line_speed = (line_speed * maxCfg) / 100;
  657. else { /* SD mode */
  658. u16 vn_max_rate = maxCfg * 100;
  659. if (vn_max_rate < line_speed)
  660. line_speed = vn_max_rate;
  661. }
  662. }
  663. return line_speed;
  664. }
  665. /**
  666. * bnx2x_fill_report_data - fill link report data to report
  667. *
  668. * @bp: driver handle
  669. * @data: link state to update
  670. *
  671. * It uses a none-atomic bit operations because is called under the mutex.
  672. */
  673. static inline void bnx2x_fill_report_data(struct bnx2x *bp,
  674. struct bnx2x_link_report_data *data)
  675. {
  676. u16 line_speed = bnx2x_get_mf_speed(bp);
  677. memset(data, 0, sizeof(*data));
  678. /* Fill the report data: efective line speed */
  679. data->line_speed = line_speed;
  680. /* Link is down */
  681. if (!bp->link_vars.link_up || (bp->flags & MF_FUNC_DIS))
  682. __set_bit(BNX2X_LINK_REPORT_LINK_DOWN,
  683. &data->link_report_flags);
  684. /* Full DUPLEX */
  685. if (bp->link_vars.duplex == DUPLEX_FULL)
  686. __set_bit(BNX2X_LINK_REPORT_FD, &data->link_report_flags);
  687. /* Rx Flow Control is ON */
  688. if (bp->link_vars.flow_ctrl & BNX2X_FLOW_CTRL_RX)
  689. __set_bit(BNX2X_LINK_REPORT_RX_FC_ON, &data->link_report_flags);
  690. /* Tx Flow Control is ON */
  691. if (bp->link_vars.flow_ctrl & BNX2X_FLOW_CTRL_TX)
  692. __set_bit(BNX2X_LINK_REPORT_TX_FC_ON, &data->link_report_flags);
  693. }
  694. /**
  695. * bnx2x_link_report - report link status to OS.
  696. *
  697. * @bp: driver handle
  698. *
  699. * Calls the __bnx2x_link_report() under the same locking scheme
  700. * as a link/PHY state managing code to ensure a consistent link
  701. * reporting.
  702. */
  703. void bnx2x_link_report(struct bnx2x *bp)
  704. {
  705. bnx2x_acquire_phy_lock(bp);
  706. __bnx2x_link_report(bp);
  707. bnx2x_release_phy_lock(bp);
  708. }
  709. /**
  710. * __bnx2x_link_report - report link status to OS.
  711. *
  712. * @bp: driver handle
  713. *
  714. * None atomic inmlementation.
  715. * Should be called under the phy_lock.
  716. */
  717. void __bnx2x_link_report(struct bnx2x *bp)
  718. {
  719. struct bnx2x_link_report_data cur_data;
  720. /* reread mf_cfg */
  721. if (!CHIP_IS_E1(bp))
  722. bnx2x_read_mf_cfg(bp);
  723. /* Read the current link report info */
  724. bnx2x_fill_report_data(bp, &cur_data);
  725. /* Don't report link down or exactly the same link status twice */
  726. if (!memcmp(&cur_data, &bp->last_reported_link, sizeof(cur_data)) ||
  727. (test_bit(BNX2X_LINK_REPORT_LINK_DOWN,
  728. &bp->last_reported_link.link_report_flags) &&
  729. test_bit(BNX2X_LINK_REPORT_LINK_DOWN,
  730. &cur_data.link_report_flags)))
  731. return;
  732. bp->link_cnt++;
  733. /* We are going to report a new link parameters now -
  734. * remember the current data for the next time.
  735. */
  736. memcpy(&bp->last_reported_link, &cur_data, sizeof(cur_data));
  737. if (test_bit(BNX2X_LINK_REPORT_LINK_DOWN,
  738. &cur_data.link_report_flags)) {
  739. netif_carrier_off(bp->dev);
  740. netdev_err(bp->dev, "NIC Link is Down\n");
  741. return;
  742. } else {
  743. netif_carrier_on(bp->dev);
  744. netdev_info(bp->dev, "NIC Link is Up, ");
  745. pr_cont("%d Mbps ", cur_data.line_speed);
  746. if (test_and_clear_bit(BNX2X_LINK_REPORT_FD,
  747. &cur_data.link_report_flags))
  748. pr_cont("full duplex");
  749. else
  750. pr_cont("half duplex");
  751. /* Handle the FC at the end so that only these flags would be
  752. * possibly set. This way we may easily check if there is no FC
  753. * enabled.
  754. */
  755. if (cur_data.link_report_flags) {
  756. if (test_bit(BNX2X_LINK_REPORT_RX_FC_ON,
  757. &cur_data.link_report_flags)) {
  758. pr_cont(", receive ");
  759. if (test_bit(BNX2X_LINK_REPORT_TX_FC_ON,
  760. &cur_data.link_report_flags))
  761. pr_cont("& transmit ");
  762. } else {
  763. pr_cont(", transmit ");
  764. }
  765. pr_cont("flow control ON");
  766. }
  767. pr_cont("\n");
  768. }
  769. }
  770. void bnx2x_init_rx_rings(struct bnx2x *bp)
  771. {
  772. int func = BP_FUNC(bp);
  773. int max_agg_queues = CHIP_IS_E1(bp) ? ETH_MAX_AGGREGATION_QUEUES_E1 :
  774. ETH_MAX_AGGREGATION_QUEUES_E1H;
  775. u16 ring_prod;
  776. int i, j;
  777. /* Allocate TPA resources */
  778. for_each_rx_queue(bp, j) {
  779. struct bnx2x_fastpath *fp = &bp->fp[j];
  780. DP(NETIF_MSG_IFUP,
  781. "mtu %d rx_buf_size %d\n", bp->dev->mtu, fp->rx_buf_size);
  782. if (!fp->disable_tpa) {
  783. /* Fill the per-aggregation pool */
  784. for (i = 0; i < max_agg_queues; i++) {
  785. fp->tpa_pool[i].skb =
  786. netdev_alloc_skb(bp->dev, fp->rx_buf_size);
  787. if (!fp->tpa_pool[i].skb) {
  788. BNX2X_ERR("Failed to allocate TPA "
  789. "skb pool for queue[%d] - "
  790. "disabling TPA on this "
  791. "queue!\n", j);
  792. bnx2x_free_tpa_pool(bp, fp, i);
  793. fp->disable_tpa = 1;
  794. break;
  795. }
  796. dma_unmap_addr_set((struct sw_rx_bd *)
  797. &bp->fp->tpa_pool[i],
  798. mapping, 0);
  799. fp->tpa_state[i] = BNX2X_TPA_STOP;
  800. }
  801. /* "next page" elements initialization */
  802. bnx2x_set_next_page_sgl(fp);
  803. /* set SGEs bit mask */
  804. bnx2x_init_sge_ring_bit_mask(fp);
  805. /* Allocate SGEs and initialize the ring elements */
  806. for (i = 0, ring_prod = 0;
  807. i < MAX_RX_SGE_CNT*NUM_RX_SGE_PAGES; i++) {
  808. if (bnx2x_alloc_rx_sge(bp, fp, ring_prod) < 0) {
  809. BNX2X_ERR("was only able to allocate "
  810. "%d rx sges\n", i);
  811. BNX2X_ERR("disabling TPA for"
  812. " queue[%d]\n", j);
  813. /* Cleanup already allocated elements */
  814. bnx2x_free_rx_sge_range(bp,
  815. fp, ring_prod);
  816. bnx2x_free_tpa_pool(bp,
  817. fp, max_agg_queues);
  818. fp->disable_tpa = 1;
  819. ring_prod = 0;
  820. break;
  821. }
  822. ring_prod = NEXT_SGE_IDX(ring_prod);
  823. }
  824. fp->rx_sge_prod = ring_prod;
  825. }
  826. }
  827. for_each_rx_queue(bp, j) {
  828. struct bnx2x_fastpath *fp = &bp->fp[j];
  829. fp->rx_bd_cons = 0;
  830. /* Activate BD ring */
  831. /* Warning!
  832. * this will generate an interrupt (to the TSTORM)
  833. * must only be done after chip is initialized
  834. */
  835. bnx2x_update_rx_prod(bp, fp, fp->rx_bd_prod, fp->rx_comp_prod,
  836. fp->rx_sge_prod);
  837. if (j != 0)
  838. continue;
  839. if (!CHIP_IS_E2(bp)) {
  840. REG_WR(bp, BAR_USTRORM_INTMEM +
  841. USTORM_MEM_WORKAROUND_ADDRESS_OFFSET(func),
  842. U64_LO(fp->rx_comp_mapping));
  843. REG_WR(bp, BAR_USTRORM_INTMEM +
  844. USTORM_MEM_WORKAROUND_ADDRESS_OFFSET(func) + 4,
  845. U64_HI(fp->rx_comp_mapping));
  846. }
  847. }
  848. }
  849. static void bnx2x_free_tx_skbs(struct bnx2x *bp)
  850. {
  851. int i;
  852. for_each_tx_queue(bp, i) {
  853. struct bnx2x_fastpath *fp = &bp->fp[i];
  854. u16 bd_cons = fp->tx_bd_cons;
  855. u16 sw_prod = fp->tx_pkt_prod;
  856. u16 sw_cons = fp->tx_pkt_cons;
  857. while (sw_cons != sw_prod) {
  858. bd_cons = bnx2x_free_tx_pkt(bp, fp, TX_BD(sw_cons));
  859. sw_cons++;
  860. }
  861. }
  862. }
  863. static void bnx2x_free_rx_bds(struct bnx2x_fastpath *fp)
  864. {
  865. struct bnx2x *bp = fp->bp;
  866. int i;
  867. /* ring wasn't allocated */
  868. if (fp->rx_buf_ring == NULL)
  869. return;
  870. for (i = 0; i < NUM_RX_BD; i++) {
  871. struct sw_rx_bd *rx_buf = &fp->rx_buf_ring[i];
  872. struct sk_buff *skb = rx_buf->skb;
  873. if (skb == NULL)
  874. continue;
  875. dma_unmap_single(&bp->pdev->dev,
  876. dma_unmap_addr(rx_buf, mapping),
  877. fp->rx_buf_size, DMA_FROM_DEVICE);
  878. rx_buf->skb = NULL;
  879. dev_kfree_skb(skb);
  880. }
  881. }
  882. static void bnx2x_free_rx_skbs(struct bnx2x *bp)
  883. {
  884. int j;
  885. for_each_rx_queue(bp, j) {
  886. struct bnx2x_fastpath *fp = &bp->fp[j];
  887. bnx2x_free_rx_bds(fp);
  888. if (!fp->disable_tpa)
  889. bnx2x_free_tpa_pool(bp, fp, CHIP_IS_E1(bp) ?
  890. ETH_MAX_AGGREGATION_QUEUES_E1 :
  891. ETH_MAX_AGGREGATION_QUEUES_E1H);
  892. }
  893. }
  894. void bnx2x_free_skbs(struct bnx2x *bp)
  895. {
  896. bnx2x_free_tx_skbs(bp);
  897. bnx2x_free_rx_skbs(bp);
  898. }
  899. void bnx2x_update_max_mf_config(struct bnx2x *bp, u32 value)
  900. {
  901. /* load old values */
  902. u32 mf_cfg = bp->mf_config[BP_VN(bp)];
  903. if (value != bnx2x_extract_max_cfg(bp, mf_cfg)) {
  904. /* leave all but MAX value */
  905. mf_cfg &= ~FUNC_MF_CFG_MAX_BW_MASK;
  906. /* set new MAX value */
  907. mf_cfg |= (value << FUNC_MF_CFG_MAX_BW_SHIFT)
  908. & FUNC_MF_CFG_MAX_BW_MASK;
  909. bnx2x_fw_command(bp, DRV_MSG_CODE_SET_MF_BW, mf_cfg);
  910. }
  911. }
  912. static void bnx2x_free_msix_irqs(struct bnx2x *bp)
  913. {
  914. int i, offset = 1;
  915. free_irq(bp->msix_table[0].vector, bp->dev);
  916. DP(NETIF_MSG_IFDOWN, "released sp irq (%d)\n",
  917. bp->msix_table[0].vector);
  918. #ifdef BCM_CNIC
  919. offset++;
  920. #endif
  921. for_each_eth_queue(bp, i) {
  922. DP(NETIF_MSG_IFDOWN, "about to release fp #%d->%d irq "
  923. "state %x\n", i, bp->msix_table[i + offset].vector,
  924. bnx2x_fp(bp, i, state));
  925. free_irq(bp->msix_table[i + offset].vector, &bp->fp[i]);
  926. }
  927. }
  928. void bnx2x_free_irq(struct bnx2x *bp)
  929. {
  930. if (bp->flags & USING_MSIX_FLAG)
  931. bnx2x_free_msix_irqs(bp);
  932. else if (bp->flags & USING_MSI_FLAG)
  933. free_irq(bp->pdev->irq, bp->dev);
  934. else
  935. free_irq(bp->pdev->irq, bp->dev);
  936. }
  937. int bnx2x_enable_msix(struct bnx2x *bp)
  938. {
  939. int msix_vec = 0, i, rc, req_cnt;
  940. bp->msix_table[msix_vec].entry = msix_vec;
  941. DP(NETIF_MSG_IFUP, "msix_table[0].entry = %d (slowpath)\n",
  942. bp->msix_table[0].entry);
  943. msix_vec++;
  944. #ifdef BCM_CNIC
  945. bp->msix_table[msix_vec].entry = msix_vec;
  946. DP(NETIF_MSG_IFUP, "msix_table[%d].entry = %d (CNIC)\n",
  947. bp->msix_table[msix_vec].entry, bp->msix_table[msix_vec].entry);
  948. msix_vec++;
  949. #endif
  950. for_each_eth_queue(bp, i) {
  951. bp->msix_table[msix_vec].entry = msix_vec;
  952. DP(NETIF_MSG_IFUP, "msix_table[%d].entry = %d "
  953. "(fastpath #%u)\n", msix_vec, msix_vec, i);
  954. msix_vec++;
  955. }
  956. req_cnt = BNX2X_NUM_ETH_QUEUES(bp) + CNIC_CONTEXT_USE + 1;
  957. rc = pci_enable_msix(bp->pdev, &bp->msix_table[0], req_cnt);
  958. /*
  959. * reconfigure number of tx/rx queues according to available
  960. * MSI-X vectors
  961. */
  962. if (rc >= BNX2X_MIN_MSIX_VEC_CNT) {
  963. /* how less vectors we will have? */
  964. int diff = req_cnt - rc;
  965. DP(NETIF_MSG_IFUP,
  966. "Trying to use less MSI-X vectors: %d\n", rc);
  967. rc = pci_enable_msix(bp->pdev, &bp->msix_table[0], rc);
  968. if (rc) {
  969. DP(NETIF_MSG_IFUP,
  970. "MSI-X is not attainable rc %d\n", rc);
  971. return rc;
  972. }
  973. /*
  974. * decrease number of queues by number of unallocated entries
  975. */
  976. bp->num_queues -= diff;
  977. DP(NETIF_MSG_IFUP, "New queue configuration set: %d\n",
  978. bp->num_queues);
  979. } else if (rc) {
  980. /* fall to INTx if not enough memory */
  981. if (rc == -ENOMEM)
  982. bp->flags |= DISABLE_MSI_FLAG;
  983. DP(NETIF_MSG_IFUP, "MSI-X is not attainable rc %d\n", rc);
  984. return rc;
  985. }
  986. bp->flags |= USING_MSIX_FLAG;
  987. return 0;
  988. }
  989. static int bnx2x_req_msix_irqs(struct bnx2x *bp)
  990. {
  991. int i, rc, offset = 1;
  992. rc = request_irq(bp->msix_table[0].vector, bnx2x_msix_sp_int, 0,
  993. bp->dev->name, bp->dev);
  994. if (rc) {
  995. BNX2X_ERR("request sp irq failed\n");
  996. return -EBUSY;
  997. }
  998. #ifdef BCM_CNIC
  999. offset++;
  1000. #endif
  1001. for_each_eth_queue(bp, i) {
  1002. struct bnx2x_fastpath *fp = &bp->fp[i];
  1003. snprintf(fp->name, sizeof(fp->name), "%s-fp-%d",
  1004. bp->dev->name, i);
  1005. rc = request_irq(bp->msix_table[offset].vector,
  1006. bnx2x_msix_fp_int, 0, fp->name, fp);
  1007. if (rc) {
  1008. BNX2X_ERR("request fp #%d irq failed rc %d\n", i, rc);
  1009. bnx2x_free_msix_irqs(bp);
  1010. return -EBUSY;
  1011. }
  1012. offset++;
  1013. fp->state = BNX2X_FP_STATE_IRQ;
  1014. }
  1015. i = BNX2X_NUM_ETH_QUEUES(bp);
  1016. offset = 1 + CNIC_CONTEXT_USE;
  1017. netdev_info(bp->dev, "using MSI-X IRQs: sp %d fp[%d] %d"
  1018. " ... fp[%d] %d\n",
  1019. bp->msix_table[0].vector,
  1020. 0, bp->msix_table[offset].vector,
  1021. i - 1, bp->msix_table[offset + i - 1].vector);
  1022. return 0;
  1023. }
  1024. int bnx2x_enable_msi(struct bnx2x *bp)
  1025. {
  1026. int rc;
  1027. rc = pci_enable_msi(bp->pdev);
  1028. if (rc) {
  1029. DP(NETIF_MSG_IFUP, "MSI is not attainable\n");
  1030. return -1;
  1031. }
  1032. bp->flags |= USING_MSI_FLAG;
  1033. return 0;
  1034. }
  1035. static int bnx2x_req_irq(struct bnx2x *bp)
  1036. {
  1037. unsigned long flags;
  1038. int rc;
  1039. if (bp->flags & USING_MSI_FLAG)
  1040. flags = 0;
  1041. else
  1042. flags = IRQF_SHARED;
  1043. rc = request_irq(bp->pdev->irq, bnx2x_interrupt, flags,
  1044. bp->dev->name, bp->dev);
  1045. if (!rc)
  1046. bnx2x_fp(bp, 0, state) = BNX2X_FP_STATE_IRQ;
  1047. return rc;
  1048. }
  1049. static void bnx2x_napi_enable(struct bnx2x *bp)
  1050. {
  1051. int i;
  1052. for_each_napi_queue(bp, i)
  1053. napi_enable(&bnx2x_fp(bp, i, napi));
  1054. }
  1055. static void bnx2x_napi_disable(struct bnx2x *bp)
  1056. {
  1057. int i;
  1058. for_each_napi_queue(bp, i)
  1059. napi_disable(&bnx2x_fp(bp, i, napi));
  1060. }
  1061. void bnx2x_netif_start(struct bnx2x *bp)
  1062. {
  1063. int intr_sem;
  1064. intr_sem = atomic_dec_and_test(&bp->intr_sem);
  1065. smp_wmb(); /* Ensure that bp->intr_sem update is SMP-safe */
  1066. if (intr_sem) {
  1067. if (netif_running(bp->dev)) {
  1068. bnx2x_napi_enable(bp);
  1069. bnx2x_int_enable(bp);
  1070. if (bp->state == BNX2X_STATE_OPEN)
  1071. netif_tx_wake_all_queues(bp->dev);
  1072. }
  1073. }
  1074. }
  1075. void bnx2x_netif_stop(struct bnx2x *bp, int disable_hw)
  1076. {
  1077. bnx2x_int_disable_sync(bp, disable_hw);
  1078. bnx2x_napi_disable(bp);
  1079. netif_tx_disable(bp->dev);
  1080. }
  1081. u16 bnx2x_select_queue(struct net_device *dev, struct sk_buff *skb)
  1082. {
  1083. #ifdef BCM_CNIC
  1084. struct bnx2x *bp = netdev_priv(dev);
  1085. if (NO_FCOE(bp))
  1086. return skb_tx_hash(dev, skb);
  1087. else {
  1088. struct ethhdr *hdr = (struct ethhdr *)skb->data;
  1089. u16 ether_type = ntohs(hdr->h_proto);
  1090. /* Skip VLAN tag if present */
  1091. if (ether_type == ETH_P_8021Q) {
  1092. struct vlan_ethhdr *vhdr =
  1093. (struct vlan_ethhdr *)skb->data;
  1094. ether_type = ntohs(vhdr->h_vlan_encapsulated_proto);
  1095. }
  1096. /* If ethertype is FCoE or FIP - use FCoE ring */
  1097. if ((ether_type == ETH_P_FCOE) || (ether_type == ETH_P_FIP))
  1098. return bnx2x_fcoe(bp, index);
  1099. }
  1100. #endif
  1101. /* Select a none-FCoE queue: if FCoE is enabled, exclude FCoE L2 ring
  1102. */
  1103. return __skb_tx_hash(dev, skb,
  1104. dev->real_num_tx_queues - FCOE_CONTEXT_USE);
  1105. }
  1106. void bnx2x_set_num_queues(struct bnx2x *bp)
  1107. {
  1108. switch (bp->multi_mode) {
  1109. case ETH_RSS_MODE_DISABLED:
  1110. bp->num_queues = 1;
  1111. break;
  1112. case ETH_RSS_MODE_REGULAR:
  1113. bp->num_queues = bnx2x_calc_num_queues(bp);
  1114. break;
  1115. default:
  1116. bp->num_queues = 1;
  1117. break;
  1118. }
  1119. /* Add special queues */
  1120. bp->num_queues += NONE_ETH_CONTEXT_USE;
  1121. }
  1122. #ifdef BCM_CNIC
  1123. static inline void bnx2x_set_fcoe_eth_macs(struct bnx2x *bp)
  1124. {
  1125. if (!NO_FCOE(bp)) {
  1126. if (!IS_MF_SD(bp))
  1127. bnx2x_set_fip_eth_mac_addr(bp, 1);
  1128. bnx2x_set_all_enode_macs(bp, 1);
  1129. bp->flags |= FCOE_MACS_SET;
  1130. }
  1131. }
  1132. #endif
  1133. static void bnx2x_release_firmware(struct bnx2x *bp)
  1134. {
  1135. kfree(bp->init_ops_offsets);
  1136. kfree(bp->init_ops);
  1137. kfree(bp->init_data);
  1138. release_firmware(bp->firmware);
  1139. }
  1140. static inline int bnx2x_set_real_num_queues(struct bnx2x *bp)
  1141. {
  1142. int rc, num = bp->num_queues;
  1143. #ifdef BCM_CNIC
  1144. if (NO_FCOE(bp))
  1145. num -= FCOE_CONTEXT_USE;
  1146. #endif
  1147. netif_set_real_num_tx_queues(bp->dev, num);
  1148. rc = netif_set_real_num_rx_queues(bp->dev, num);
  1149. return rc;
  1150. }
  1151. static inline void bnx2x_set_rx_buf_size(struct bnx2x *bp)
  1152. {
  1153. int i;
  1154. for_each_queue(bp, i) {
  1155. struct bnx2x_fastpath *fp = &bp->fp[i];
  1156. /* Always use a mini-jumbo MTU for the FCoE L2 ring */
  1157. if (IS_FCOE_IDX(i))
  1158. /*
  1159. * Although there are no IP frames expected to arrive to
  1160. * this ring we still want to add an
  1161. * IP_HEADER_ALIGNMENT_PADDING to prevent a buffer
  1162. * overrun attack.
  1163. */
  1164. fp->rx_buf_size =
  1165. BNX2X_FCOE_MINI_JUMBO_MTU + ETH_OVREHEAD +
  1166. BNX2X_RX_ALIGN + IP_HEADER_ALIGNMENT_PADDING;
  1167. else
  1168. fp->rx_buf_size =
  1169. bp->dev->mtu + ETH_OVREHEAD + BNX2X_RX_ALIGN +
  1170. IP_HEADER_ALIGNMENT_PADDING;
  1171. }
  1172. }
  1173. /* must be called with rtnl_lock */
  1174. int bnx2x_nic_load(struct bnx2x *bp, int load_mode)
  1175. {
  1176. u32 load_code;
  1177. int i, rc;
  1178. /* Set init arrays */
  1179. rc = bnx2x_init_firmware(bp);
  1180. if (rc) {
  1181. BNX2X_ERR("Error loading firmware\n");
  1182. return rc;
  1183. }
  1184. #ifdef BNX2X_STOP_ON_ERROR
  1185. if (unlikely(bp->panic))
  1186. return -EPERM;
  1187. #endif
  1188. bp->state = BNX2X_STATE_OPENING_WAIT4_LOAD;
  1189. /* Set the initial link reported state to link down */
  1190. bnx2x_acquire_phy_lock(bp);
  1191. memset(&bp->last_reported_link, 0, sizeof(bp->last_reported_link));
  1192. __set_bit(BNX2X_LINK_REPORT_LINK_DOWN,
  1193. &bp->last_reported_link.link_report_flags);
  1194. bnx2x_release_phy_lock(bp);
  1195. /* must be called before memory allocation and HW init */
  1196. bnx2x_ilt_set_info(bp);
  1197. /* zero fastpath structures preserving invariants like napi which are
  1198. * allocated only once
  1199. */
  1200. for_each_queue(bp, i)
  1201. bnx2x_bz_fp(bp, i);
  1202. /* Set the receive queues buffer size */
  1203. bnx2x_set_rx_buf_size(bp);
  1204. for_each_queue(bp, i)
  1205. bnx2x_fp(bp, i, disable_tpa) =
  1206. ((bp->flags & TPA_ENABLE_FLAG) == 0);
  1207. #ifdef BCM_CNIC
  1208. /* We don't want TPA on FCoE L2 ring */
  1209. bnx2x_fcoe(bp, disable_tpa) = 1;
  1210. #endif
  1211. if (bnx2x_alloc_mem(bp))
  1212. return -ENOMEM;
  1213. /* As long as bnx2x_alloc_mem() may possibly update
  1214. * bp->num_queues, bnx2x_set_real_num_queues() should always
  1215. * come after it.
  1216. */
  1217. rc = bnx2x_set_real_num_queues(bp);
  1218. if (rc) {
  1219. BNX2X_ERR("Unable to set real_num_queues\n");
  1220. goto load_error0;
  1221. }
  1222. bnx2x_napi_enable(bp);
  1223. /* Send LOAD_REQUEST command to MCP
  1224. Returns the type of LOAD command:
  1225. if it is the first port to be initialized
  1226. common blocks should be initialized, otherwise - not
  1227. */
  1228. if (!BP_NOMCP(bp)) {
  1229. load_code = bnx2x_fw_command(bp, DRV_MSG_CODE_LOAD_REQ, 0);
  1230. if (!load_code) {
  1231. BNX2X_ERR("MCP response failure, aborting\n");
  1232. rc = -EBUSY;
  1233. goto load_error1;
  1234. }
  1235. if (load_code == FW_MSG_CODE_DRV_LOAD_REFUSED) {
  1236. rc = -EBUSY; /* other port in diagnostic mode */
  1237. goto load_error1;
  1238. }
  1239. } else {
  1240. int path = BP_PATH(bp);
  1241. int port = BP_PORT(bp);
  1242. DP(NETIF_MSG_IFUP, "NO MCP - load counts[%d] %d, %d, %d\n",
  1243. path, load_count[path][0], load_count[path][1],
  1244. load_count[path][2]);
  1245. load_count[path][0]++;
  1246. load_count[path][1 + port]++;
  1247. DP(NETIF_MSG_IFUP, "NO MCP - new load counts[%d] %d, %d, %d\n",
  1248. path, load_count[path][0], load_count[path][1],
  1249. load_count[path][2]);
  1250. if (load_count[path][0] == 1)
  1251. load_code = FW_MSG_CODE_DRV_LOAD_COMMON;
  1252. else if (load_count[path][1 + port] == 1)
  1253. load_code = FW_MSG_CODE_DRV_LOAD_PORT;
  1254. else
  1255. load_code = FW_MSG_CODE_DRV_LOAD_FUNCTION;
  1256. }
  1257. if ((load_code == FW_MSG_CODE_DRV_LOAD_COMMON) ||
  1258. (load_code == FW_MSG_CODE_DRV_LOAD_COMMON_CHIP) ||
  1259. (load_code == FW_MSG_CODE_DRV_LOAD_PORT))
  1260. bp->port.pmf = 1;
  1261. else
  1262. bp->port.pmf = 0;
  1263. DP(NETIF_MSG_LINK, "pmf %d\n", bp->port.pmf);
  1264. /* Initialize HW */
  1265. rc = bnx2x_init_hw(bp, load_code);
  1266. if (rc) {
  1267. BNX2X_ERR("HW init failed, aborting\n");
  1268. bnx2x_fw_command(bp, DRV_MSG_CODE_LOAD_DONE, 0);
  1269. goto load_error2;
  1270. }
  1271. /* Connect to IRQs */
  1272. rc = bnx2x_setup_irqs(bp);
  1273. if (rc) {
  1274. bnx2x_fw_command(bp, DRV_MSG_CODE_LOAD_DONE, 0);
  1275. goto load_error2;
  1276. }
  1277. /* Setup NIC internals and enable interrupts */
  1278. bnx2x_nic_init(bp, load_code);
  1279. if (((load_code == FW_MSG_CODE_DRV_LOAD_COMMON) ||
  1280. (load_code == FW_MSG_CODE_DRV_LOAD_COMMON_CHIP)) &&
  1281. (bp->common.shmem2_base))
  1282. SHMEM2_WR(bp, dcc_support,
  1283. (SHMEM_DCC_SUPPORT_DISABLE_ENABLE_PF_TLV |
  1284. SHMEM_DCC_SUPPORT_BANDWIDTH_ALLOCATION_TLV));
  1285. /* Send LOAD_DONE command to MCP */
  1286. if (!BP_NOMCP(bp)) {
  1287. load_code = bnx2x_fw_command(bp, DRV_MSG_CODE_LOAD_DONE, 0);
  1288. if (!load_code) {
  1289. BNX2X_ERR("MCP response failure, aborting\n");
  1290. rc = -EBUSY;
  1291. goto load_error3;
  1292. }
  1293. }
  1294. bnx2x_dcbx_init(bp);
  1295. bp->state = BNX2X_STATE_OPENING_WAIT4_PORT;
  1296. rc = bnx2x_func_start(bp);
  1297. if (rc) {
  1298. BNX2X_ERR("Function start failed!\n");
  1299. #ifndef BNX2X_STOP_ON_ERROR
  1300. goto load_error3;
  1301. #else
  1302. bp->panic = 1;
  1303. return -EBUSY;
  1304. #endif
  1305. }
  1306. rc = bnx2x_setup_client(bp, &bp->fp[0], 1 /* Leading */);
  1307. if (rc) {
  1308. BNX2X_ERR("Setup leading failed!\n");
  1309. #ifndef BNX2X_STOP_ON_ERROR
  1310. goto load_error3;
  1311. #else
  1312. bp->panic = 1;
  1313. return -EBUSY;
  1314. #endif
  1315. }
  1316. if (!CHIP_IS_E1(bp) &&
  1317. (bp->mf_config[BP_VN(bp)] & FUNC_MF_CFG_FUNC_DISABLED)) {
  1318. DP(NETIF_MSG_IFUP, "mf_cfg function disabled\n");
  1319. bp->flags |= MF_FUNC_DIS;
  1320. }
  1321. #ifdef BCM_CNIC
  1322. /* Enable Timer scan */
  1323. REG_WR(bp, TM_REG_EN_LINEAR0_TIMER + BP_PORT(bp)*4, 1);
  1324. #endif
  1325. for_each_nondefault_queue(bp, i) {
  1326. rc = bnx2x_setup_client(bp, &bp->fp[i], 0);
  1327. if (rc)
  1328. #ifdef BCM_CNIC
  1329. goto load_error4;
  1330. #else
  1331. goto load_error3;
  1332. #endif
  1333. }
  1334. /* Now when Clients are configured we are ready to work */
  1335. bp->state = BNX2X_STATE_OPEN;
  1336. #ifdef BCM_CNIC
  1337. bnx2x_set_fcoe_eth_macs(bp);
  1338. #endif
  1339. bnx2x_set_eth_mac(bp, 1);
  1340. /* Clear MC configuration */
  1341. if (CHIP_IS_E1(bp))
  1342. bnx2x_invalidate_e1_mc_list(bp);
  1343. else
  1344. bnx2x_invalidate_e1h_mc_list(bp);
  1345. /* Clear UC lists configuration */
  1346. bnx2x_invalidate_uc_list(bp);
  1347. if (bp->pending_max) {
  1348. bnx2x_update_max_mf_config(bp, bp->pending_max);
  1349. bp->pending_max = 0;
  1350. }
  1351. if (bp->port.pmf)
  1352. bnx2x_initial_phy_init(bp, load_mode);
  1353. /* Initialize Rx filtering */
  1354. bnx2x_set_rx_mode(bp->dev);
  1355. /* Start fast path */
  1356. switch (load_mode) {
  1357. case LOAD_NORMAL:
  1358. /* Tx queue should be only reenabled */
  1359. netif_tx_wake_all_queues(bp->dev);
  1360. /* Initialize the receive filter. */
  1361. break;
  1362. case LOAD_OPEN:
  1363. netif_tx_start_all_queues(bp->dev);
  1364. smp_mb__after_clear_bit();
  1365. break;
  1366. case LOAD_DIAG:
  1367. bp->state = BNX2X_STATE_DIAG;
  1368. break;
  1369. default:
  1370. break;
  1371. }
  1372. if (!bp->port.pmf)
  1373. bnx2x__link_status_update(bp);
  1374. /* start the timer */
  1375. mod_timer(&bp->timer, jiffies + bp->current_interval);
  1376. #ifdef BCM_CNIC
  1377. bnx2x_setup_cnic_irq_info(bp);
  1378. if (bp->state == BNX2X_STATE_OPEN)
  1379. bnx2x_cnic_notify(bp, CNIC_CTL_START_CMD);
  1380. #endif
  1381. bnx2x_inc_load_cnt(bp);
  1382. bnx2x_release_firmware(bp);
  1383. return 0;
  1384. #ifdef BCM_CNIC
  1385. load_error4:
  1386. /* Disable Timer scan */
  1387. REG_WR(bp, TM_REG_EN_LINEAR0_TIMER + BP_PORT(bp)*4, 0);
  1388. #endif
  1389. load_error3:
  1390. bnx2x_int_disable_sync(bp, 1);
  1391. /* Free SKBs, SGEs, TPA pool and driver internals */
  1392. bnx2x_free_skbs(bp);
  1393. for_each_rx_queue(bp, i)
  1394. bnx2x_free_rx_sge_range(bp, bp->fp + i, NUM_RX_SGE);
  1395. /* Release IRQs */
  1396. bnx2x_free_irq(bp);
  1397. load_error2:
  1398. if (!BP_NOMCP(bp)) {
  1399. bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_REQ_WOL_MCP, 0);
  1400. bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_DONE, 0);
  1401. }
  1402. bp->port.pmf = 0;
  1403. load_error1:
  1404. bnx2x_napi_disable(bp);
  1405. load_error0:
  1406. bnx2x_free_mem(bp);
  1407. bnx2x_release_firmware(bp);
  1408. return rc;
  1409. }
  1410. /* must be called with rtnl_lock */
  1411. int bnx2x_nic_unload(struct bnx2x *bp, int unload_mode)
  1412. {
  1413. int i;
  1414. if (bp->state == BNX2X_STATE_CLOSED) {
  1415. /* Interface has been removed - nothing to recover */
  1416. bp->recovery_state = BNX2X_RECOVERY_DONE;
  1417. bp->is_leader = 0;
  1418. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RESERVED_08);
  1419. smp_wmb();
  1420. return -EINVAL;
  1421. }
  1422. #ifdef BCM_CNIC
  1423. bnx2x_cnic_notify(bp, CNIC_CTL_STOP_CMD);
  1424. #endif
  1425. bp->state = BNX2X_STATE_CLOSING_WAIT4_HALT;
  1426. /* Set "drop all" */
  1427. bp->rx_mode = BNX2X_RX_MODE_NONE;
  1428. bnx2x_set_storm_rx_mode(bp);
  1429. /* Stop Tx */
  1430. bnx2x_tx_disable(bp);
  1431. del_timer_sync(&bp->timer);
  1432. SHMEM_WR(bp, func_mb[BP_FW_MB_IDX(bp)].drv_pulse_mb,
  1433. (DRV_PULSE_ALWAYS_ALIVE | bp->fw_drv_pulse_wr_seq));
  1434. bnx2x_stats_handle(bp, STATS_EVENT_STOP);
  1435. /* Cleanup the chip if needed */
  1436. if (unload_mode != UNLOAD_RECOVERY)
  1437. bnx2x_chip_cleanup(bp, unload_mode);
  1438. else {
  1439. /* Disable HW interrupts, NAPI and Tx */
  1440. bnx2x_netif_stop(bp, 1);
  1441. /* Release IRQs */
  1442. bnx2x_free_irq(bp);
  1443. }
  1444. bp->port.pmf = 0;
  1445. /* Free SKBs, SGEs, TPA pool and driver internals */
  1446. bnx2x_free_skbs(bp);
  1447. for_each_rx_queue(bp, i)
  1448. bnx2x_free_rx_sge_range(bp, bp->fp + i, NUM_RX_SGE);
  1449. bnx2x_free_mem(bp);
  1450. bp->state = BNX2X_STATE_CLOSED;
  1451. /* The last driver must disable a "close the gate" if there is no
  1452. * parity attention or "process kill" pending.
  1453. */
  1454. if ((!bnx2x_dec_load_cnt(bp)) && (!bnx2x_chk_parity_attn(bp)) &&
  1455. bnx2x_reset_is_done(bp))
  1456. bnx2x_disable_close_the_gate(bp);
  1457. /* Reset MCP mail box sequence if there is on going recovery */
  1458. if (unload_mode == UNLOAD_RECOVERY)
  1459. bp->fw_seq = 0;
  1460. return 0;
  1461. }
  1462. int bnx2x_set_power_state(struct bnx2x *bp, pci_power_t state)
  1463. {
  1464. u16 pmcsr;
  1465. /* If there is no power capability, silently succeed */
  1466. if (!bp->pm_cap) {
  1467. DP(NETIF_MSG_HW, "No power capability. Breaking.\n");
  1468. return 0;
  1469. }
  1470. pci_read_config_word(bp->pdev, bp->pm_cap + PCI_PM_CTRL, &pmcsr);
  1471. switch (state) {
  1472. case PCI_D0:
  1473. pci_write_config_word(bp->pdev, bp->pm_cap + PCI_PM_CTRL,
  1474. ((pmcsr & ~PCI_PM_CTRL_STATE_MASK) |
  1475. PCI_PM_CTRL_PME_STATUS));
  1476. if (pmcsr & PCI_PM_CTRL_STATE_MASK)
  1477. /* delay required during transition out of D3hot */
  1478. msleep(20);
  1479. break;
  1480. case PCI_D3hot:
  1481. /* If there are other clients above don't
  1482. shut down the power */
  1483. if (atomic_read(&bp->pdev->enable_cnt) != 1)
  1484. return 0;
  1485. /* Don't shut down the power for emulation and FPGA */
  1486. if (CHIP_REV_IS_SLOW(bp))
  1487. return 0;
  1488. pmcsr &= ~PCI_PM_CTRL_STATE_MASK;
  1489. pmcsr |= 3;
  1490. if (bp->wol)
  1491. pmcsr |= PCI_PM_CTRL_PME_ENABLE;
  1492. pci_write_config_word(bp->pdev, bp->pm_cap + PCI_PM_CTRL,
  1493. pmcsr);
  1494. /* No more memory access after this point until
  1495. * device is brought back to D0.
  1496. */
  1497. break;
  1498. default:
  1499. return -EINVAL;
  1500. }
  1501. return 0;
  1502. }
  1503. /*
  1504. * net_device service functions
  1505. */
  1506. int bnx2x_poll(struct napi_struct *napi, int budget)
  1507. {
  1508. int work_done = 0;
  1509. struct bnx2x_fastpath *fp = container_of(napi, struct bnx2x_fastpath,
  1510. napi);
  1511. struct bnx2x *bp = fp->bp;
  1512. while (1) {
  1513. #ifdef BNX2X_STOP_ON_ERROR
  1514. if (unlikely(bp->panic)) {
  1515. napi_complete(napi);
  1516. return 0;
  1517. }
  1518. #endif
  1519. if (bnx2x_has_tx_work(fp))
  1520. bnx2x_tx_int(fp);
  1521. if (bnx2x_has_rx_work(fp)) {
  1522. work_done += bnx2x_rx_int(fp, budget - work_done);
  1523. /* must not complete if we consumed full budget */
  1524. if (work_done >= budget)
  1525. break;
  1526. }
  1527. /* Fall out from the NAPI loop if needed */
  1528. if (!(bnx2x_has_rx_work(fp) || bnx2x_has_tx_work(fp))) {
  1529. #ifdef BCM_CNIC
  1530. /* No need to update SB for FCoE L2 ring as long as
  1531. * it's connected to the default SB and the SB
  1532. * has been updated when NAPI was scheduled.
  1533. */
  1534. if (IS_FCOE_FP(fp)) {
  1535. napi_complete(napi);
  1536. break;
  1537. }
  1538. #endif
  1539. bnx2x_update_fpsb_idx(fp);
  1540. /* bnx2x_has_rx_work() reads the status block,
  1541. * thus we need to ensure that status block indices
  1542. * have been actually read (bnx2x_update_fpsb_idx)
  1543. * prior to this check (bnx2x_has_rx_work) so that
  1544. * we won't write the "newer" value of the status block
  1545. * to IGU (if there was a DMA right after
  1546. * bnx2x_has_rx_work and if there is no rmb, the memory
  1547. * reading (bnx2x_update_fpsb_idx) may be postponed
  1548. * to right before bnx2x_ack_sb). In this case there
  1549. * will never be another interrupt until there is
  1550. * another update of the status block, while there
  1551. * is still unhandled work.
  1552. */
  1553. rmb();
  1554. if (!(bnx2x_has_rx_work(fp) || bnx2x_has_tx_work(fp))) {
  1555. napi_complete(napi);
  1556. /* Re-enable interrupts */
  1557. DP(NETIF_MSG_HW,
  1558. "Update index to %d\n", fp->fp_hc_idx);
  1559. bnx2x_ack_sb(bp, fp->igu_sb_id, USTORM_ID,
  1560. le16_to_cpu(fp->fp_hc_idx),
  1561. IGU_INT_ENABLE, 1);
  1562. break;
  1563. }
  1564. }
  1565. }
  1566. return work_done;
  1567. }
  1568. /* we split the first BD into headers and data BDs
  1569. * to ease the pain of our fellow microcode engineers
  1570. * we use one mapping for both BDs
  1571. * So far this has only been observed to happen
  1572. * in Other Operating Systems(TM)
  1573. */
  1574. static noinline u16 bnx2x_tx_split(struct bnx2x *bp,
  1575. struct bnx2x_fastpath *fp,
  1576. struct sw_tx_bd *tx_buf,
  1577. struct eth_tx_start_bd **tx_bd, u16 hlen,
  1578. u16 bd_prod, int nbd)
  1579. {
  1580. struct eth_tx_start_bd *h_tx_bd = *tx_bd;
  1581. struct eth_tx_bd *d_tx_bd;
  1582. dma_addr_t mapping;
  1583. int old_len = le16_to_cpu(h_tx_bd->nbytes);
  1584. /* first fix first BD */
  1585. h_tx_bd->nbd = cpu_to_le16(nbd);
  1586. h_tx_bd->nbytes = cpu_to_le16(hlen);
  1587. DP(NETIF_MSG_TX_QUEUED, "TSO split header size is %d "
  1588. "(%x:%x) nbd %d\n", h_tx_bd->nbytes, h_tx_bd->addr_hi,
  1589. h_tx_bd->addr_lo, h_tx_bd->nbd);
  1590. /* now get a new data BD
  1591. * (after the pbd) and fill it */
  1592. bd_prod = TX_BD(NEXT_TX_IDX(bd_prod));
  1593. d_tx_bd = &fp->tx_desc_ring[bd_prod].reg_bd;
  1594. mapping = HILO_U64(le32_to_cpu(h_tx_bd->addr_hi),
  1595. le32_to_cpu(h_tx_bd->addr_lo)) + hlen;
  1596. d_tx_bd->addr_hi = cpu_to_le32(U64_HI(mapping));
  1597. d_tx_bd->addr_lo = cpu_to_le32(U64_LO(mapping));
  1598. d_tx_bd->nbytes = cpu_to_le16(old_len - hlen);
  1599. /* this marks the BD as one that has no individual mapping */
  1600. tx_buf->flags |= BNX2X_TSO_SPLIT_BD;
  1601. DP(NETIF_MSG_TX_QUEUED,
  1602. "TSO split data size is %d (%x:%x)\n",
  1603. d_tx_bd->nbytes, d_tx_bd->addr_hi, d_tx_bd->addr_lo);
  1604. /* update tx_bd */
  1605. *tx_bd = (struct eth_tx_start_bd *)d_tx_bd;
  1606. return bd_prod;
  1607. }
  1608. static inline u16 bnx2x_csum_fix(unsigned char *t_header, u16 csum, s8 fix)
  1609. {
  1610. if (fix > 0)
  1611. csum = (u16) ~csum_fold(csum_sub(csum,
  1612. csum_partial(t_header - fix, fix, 0)));
  1613. else if (fix < 0)
  1614. csum = (u16) ~csum_fold(csum_add(csum,
  1615. csum_partial(t_header, -fix, 0)));
  1616. return swab16(csum);
  1617. }
  1618. static inline u32 bnx2x_xmit_type(struct bnx2x *bp, struct sk_buff *skb)
  1619. {
  1620. u32 rc;
  1621. if (skb->ip_summed != CHECKSUM_PARTIAL)
  1622. rc = XMIT_PLAIN;
  1623. else {
  1624. if (vlan_get_protocol(skb) == htons(ETH_P_IPV6)) {
  1625. rc = XMIT_CSUM_V6;
  1626. if (ipv6_hdr(skb)->nexthdr == IPPROTO_TCP)
  1627. rc |= XMIT_CSUM_TCP;
  1628. } else {
  1629. rc = XMIT_CSUM_V4;
  1630. if (ip_hdr(skb)->protocol == IPPROTO_TCP)
  1631. rc |= XMIT_CSUM_TCP;
  1632. }
  1633. }
  1634. if (skb_is_gso_v6(skb))
  1635. rc |= XMIT_GSO_V6 | XMIT_CSUM_TCP | XMIT_CSUM_V6;
  1636. else if (skb_is_gso(skb))
  1637. rc |= XMIT_GSO_V4 | XMIT_CSUM_V4 | XMIT_CSUM_TCP;
  1638. return rc;
  1639. }
  1640. #if (MAX_SKB_FRAGS >= MAX_FETCH_BD - 3)
  1641. /* check if packet requires linearization (packet is too fragmented)
  1642. no need to check fragmentation if page size > 8K (there will be no
  1643. violation to FW restrictions) */
  1644. static int bnx2x_pkt_req_lin(struct bnx2x *bp, struct sk_buff *skb,
  1645. u32 xmit_type)
  1646. {
  1647. int to_copy = 0;
  1648. int hlen = 0;
  1649. int first_bd_sz = 0;
  1650. /* 3 = 1 (for linear data BD) + 2 (for PBD and last BD) */
  1651. if (skb_shinfo(skb)->nr_frags >= (MAX_FETCH_BD - 3)) {
  1652. if (xmit_type & XMIT_GSO) {
  1653. unsigned short lso_mss = skb_shinfo(skb)->gso_size;
  1654. /* Check if LSO packet needs to be copied:
  1655. 3 = 1 (for headers BD) + 2 (for PBD and last BD) */
  1656. int wnd_size = MAX_FETCH_BD - 3;
  1657. /* Number of windows to check */
  1658. int num_wnds = skb_shinfo(skb)->nr_frags - wnd_size;
  1659. int wnd_idx = 0;
  1660. int frag_idx = 0;
  1661. u32 wnd_sum = 0;
  1662. /* Headers length */
  1663. hlen = (int)(skb_transport_header(skb) - skb->data) +
  1664. tcp_hdrlen(skb);
  1665. /* Amount of data (w/o headers) on linear part of SKB*/
  1666. first_bd_sz = skb_headlen(skb) - hlen;
  1667. wnd_sum = first_bd_sz;
  1668. /* Calculate the first sum - it's special */
  1669. for (frag_idx = 0; frag_idx < wnd_size - 1; frag_idx++)
  1670. wnd_sum +=
  1671. skb_shinfo(skb)->frags[frag_idx].size;
  1672. /* If there was data on linear skb data - check it */
  1673. if (first_bd_sz > 0) {
  1674. if (unlikely(wnd_sum < lso_mss)) {
  1675. to_copy = 1;
  1676. goto exit_lbl;
  1677. }
  1678. wnd_sum -= first_bd_sz;
  1679. }
  1680. /* Others are easier: run through the frag list and
  1681. check all windows */
  1682. for (wnd_idx = 0; wnd_idx <= num_wnds; wnd_idx++) {
  1683. wnd_sum +=
  1684. skb_shinfo(skb)->frags[wnd_idx + wnd_size - 1].size;
  1685. if (unlikely(wnd_sum < lso_mss)) {
  1686. to_copy = 1;
  1687. break;
  1688. }
  1689. wnd_sum -=
  1690. skb_shinfo(skb)->frags[wnd_idx].size;
  1691. }
  1692. } else {
  1693. /* in non-LSO too fragmented packet should always
  1694. be linearized */
  1695. to_copy = 1;
  1696. }
  1697. }
  1698. exit_lbl:
  1699. if (unlikely(to_copy))
  1700. DP(NETIF_MSG_TX_QUEUED,
  1701. "Linearization IS REQUIRED for %s packet. "
  1702. "num_frags %d hlen %d first_bd_sz %d\n",
  1703. (xmit_type & XMIT_GSO) ? "LSO" : "non-LSO",
  1704. skb_shinfo(skb)->nr_frags, hlen, first_bd_sz);
  1705. return to_copy;
  1706. }
  1707. #endif
  1708. static inline void bnx2x_set_pbd_gso_e2(struct sk_buff *skb, u32 *parsing_data,
  1709. u32 xmit_type)
  1710. {
  1711. *parsing_data |= (skb_shinfo(skb)->gso_size <<
  1712. ETH_TX_PARSE_BD_E2_LSO_MSS_SHIFT) &
  1713. ETH_TX_PARSE_BD_E2_LSO_MSS;
  1714. if ((xmit_type & XMIT_GSO_V6) &&
  1715. (ipv6_hdr(skb)->nexthdr == NEXTHDR_IPV6))
  1716. *parsing_data |= ETH_TX_PARSE_BD_E2_IPV6_WITH_EXT_HDR;
  1717. }
  1718. /**
  1719. * bnx2x_set_pbd_gso - update PBD in GSO case.
  1720. *
  1721. * @skb: packet skb
  1722. * @pbd: parse BD
  1723. * @xmit_type: xmit flags
  1724. */
  1725. static inline void bnx2x_set_pbd_gso(struct sk_buff *skb,
  1726. struct eth_tx_parse_bd_e1x *pbd,
  1727. u32 xmit_type)
  1728. {
  1729. pbd->lso_mss = cpu_to_le16(skb_shinfo(skb)->gso_size);
  1730. pbd->tcp_send_seq = swab32(tcp_hdr(skb)->seq);
  1731. pbd->tcp_flags = pbd_tcp_flags(skb);
  1732. if (xmit_type & XMIT_GSO_V4) {
  1733. pbd->ip_id = swab16(ip_hdr(skb)->id);
  1734. pbd->tcp_pseudo_csum =
  1735. swab16(~csum_tcpudp_magic(ip_hdr(skb)->saddr,
  1736. ip_hdr(skb)->daddr,
  1737. 0, IPPROTO_TCP, 0));
  1738. } else
  1739. pbd->tcp_pseudo_csum =
  1740. swab16(~csum_ipv6_magic(&ipv6_hdr(skb)->saddr,
  1741. &ipv6_hdr(skb)->daddr,
  1742. 0, IPPROTO_TCP, 0));
  1743. pbd->global_data |= ETH_TX_PARSE_BD_E1X_PSEUDO_CS_WITHOUT_LEN;
  1744. }
  1745. /**
  1746. * bnx2x_set_pbd_csum_e2 - update PBD with checksum and return header length
  1747. *
  1748. * @bp: driver handle
  1749. * @skb: packet skb
  1750. * @parsing_data: data to be updated
  1751. * @xmit_type: xmit flags
  1752. *
  1753. * 57712 related
  1754. */
  1755. static inline u8 bnx2x_set_pbd_csum_e2(struct bnx2x *bp, struct sk_buff *skb,
  1756. u32 *parsing_data, u32 xmit_type)
  1757. {
  1758. *parsing_data |=
  1759. ((((u8 *)skb_transport_header(skb) - skb->data) >> 1) <<
  1760. ETH_TX_PARSE_BD_E2_TCP_HDR_START_OFFSET_W_SHIFT) &
  1761. ETH_TX_PARSE_BD_E2_TCP_HDR_START_OFFSET_W;
  1762. if (xmit_type & XMIT_CSUM_TCP) {
  1763. *parsing_data |= ((tcp_hdrlen(skb) / 4) <<
  1764. ETH_TX_PARSE_BD_E2_TCP_HDR_LENGTH_DW_SHIFT) &
  1765. ETH_TX_PARSE_BD_E2_TCP_HDR_LENGTH_DW;
  1766. return skb_transport_header(skb) + tcp_hdrlen(skb) - skb->data;
  1767. } else
  1768. /* We support checksum offload for TCP and UDP only.
  1769. * No need to pass the UDP header length - it's a constant.
  1770. */
  1771. return skb_transport_header(skb) +
  1772. sizeof(struct udphdr) - skb->data;
  1773. }
  1774. /**
  1775. * bnx2x_set_pbd_csum - update PBD with checksum and return header length
  1776. *
  1777. * @bp: driver handle
  1778. * @skb: packet skb
  1779. * @pbd: parse BD to be updated
  1780. * @xmit_type: xmit flags
  1781. */
  1782. static inline u8 bnx2x_set_pbd_csum(struct bnx2x *bp, struct sk_buff *skb,
  1783. struct eth_tx_parse_bd_e1x *pbd,
  1784. u32 xmit_type)
  1785. {
  1786. u8 hlen = (skb_network_header(skb) - skb->data) >> 1;
  1787. /* for now NS flag is not used in Linux */
  1788. pbd->global_data =
  1789. (hlen | ((skb->protocol == cpu_to_be16(ETH_P_8021Q)) <<
  1790. ETH_TX_PARSE_BD_E1X_LLC_SNAP_EN_SHIFT));
  1791. pbd->ip_hlen_w = (skb_transport_header(skb) -
  1792. skb_network_header(skb)) >> 1;
  1793. hlen += pbd->ip_hlen_w;
  1794. /* We support checksum offload for TCP and UDP only */
  1795. if (xmit_type & XMIT_CSUM_TCP)
  1796. hlen += tcp_hdrlen(skb) / 2;
  1797. else
  1798. hlen += sizeof(struct udphdr) / 2;
  1799. pbd->total_hlen_w = cpu_to_le16(hlen);
  1800. hlen = hlen*2;
  1801. if (xmit_type & XMIT_CSUM_TCP) {
  1802. pbd->tcp_pseudo_csum = swab16(tcp_hdr(skb)->check);
  1803. } else {
  1804. s8 fix = SKB_CS_OFF(skb); /* signed! */
  1805. DP(NETIF_MSG_TX_QUEUED,
  1806. "hlen %d fix %d csum before fix %x\n",
  1807. le16_to_cpu(pbd->total_hlen_w), fix, SKB_CS(skb));
  1808. /* HW bug: fixup the CSUM */
  1809. pbd->tcp_pseudo_csum =
  1810. bnx2x_csum_fix(skb_transport_header(skb),
  1811. SKB_CS(skb), fix);
  1812. DP(NETIF_MSG_TX_QUEUED, "csum after fix %x\n",
  1813. pbd->tcp_pseudo_csum);
  1814. }
  1815. return hlen;
  1816. }
  1817. /* called with netif_tx_lock
  1818. * bnx2x_tx_int() runs without netif_tx_lock unless it needs to call
  1819. * netif_wake_queue()
  1820. */
  1821. netdev_tx_t bnx2x_start_xmit(struct sk_buff *skb, struct net_device *dev)
  1822. {
  1823. struct bnx2x *bp = netdev_priv(dev);
  1824. struct bnx2x_fastpath *fp;
  1825. struct netdev_queue *txq;
  1826. struct sw_tx_bd *tx_buf;
  1827. struct eth_tx_start_bd *tx_start_bd;
  1828. struct eth_tx_bd *tx_data_bd, *total_pkt_bd = NULL;
  1829. struct eth_tx_parse_bd_e1x *pbd_e1x = NULL;
  1830. struct eth_tx_parse_bd_e2 *pbd_e2 = NULL;
  1831. u32 pbd_e2_parsing_data = 0;
  1832. u16 pkt_prod, bd_prod;
  1833. int nbd, fp_index;
  1834. dma_addr_t mapping;
  1835. u32 xmit_type = bnx2x_xmit_type(bp, skb);
  1836. int i;
  1837. u8 hlen = 0;
  1838. __le16 pkt_size = 0;
  1839. struct ethhdr *eth;
  1840. u8 mac_type = UNICAST_ADDRESS;
  1841. #ifdef BNX2X_STOP_ON_ERROR
  1842. if (unlikely(bp->panic))
  1843. return NETDEV_TX_BUSY;
  1844. #endif
  1845. fp_index = skb_get_queue_mapping(skb);
  1846. txq = netdev_get_tx_queue(dev, fp_index);
  1847. fp = &bp->fp[fp_index];
  1848. if (unlikely(bnx2x_tx_avail(fp) < (skb_shinfo(skb)->nr_frags + 3))) {
  1849. fp->eth_q_stats.driver_xoff++;
  1850. netif_tx_stop_queue(txq);
  1851. BNX2X_ERR("BUG! Tx ring full when queue awake!\n");
  1852. return NETDEV_TX_BUSY;
  1853. }
  1854. DP(NETIF_MSG_TX_QUEUED, "queue[%d]: SKB: summed %x protocol %x "
  1855. "protocol(%x,%x) gso type %x xmit_type %x\n",
  1856. fp_index, skb->ip_summed, skb->protocol, ipv6_hdr(skb)->nexthdr,
  1857. ip_hdr(skb)->protocol, skb_shinfo(skb)->gso_type, xmit_type);
  1858. eth = (struct ethhdr *)skb->data;
  1859. /* set flag according to packet type (UNICAST_ADDRESS is default)*/
  1860. if (unlikely(is_multicast_ether_addr(eth->h_dest))) {
  1861. if (is_broadcast_ether_addr(eth->h_dest))
  1862. mac_type = BROADCAST_ADDRESS;
  1863. else
  1864. mac_type = MULTICAST_ADDRESS;
  1865. }
  1866. #if (MAX_SKB_FRAGS >= MAX_FETCH_BD - 3)
  1867. /* First, check if we need to linearize the skb (due to FW
  1868. restrictions). No need to check fragmentation if page size > 8K
  1869. (there will be no violation to FW restrictions) */
  1870. if (bnx2x_pkt_req_lin(bp, skb, xmit_type)) {
  1871. /* Statistics of linearization */
  1872. bp->lin_cnt++;
  1873. if (skb_linearize(skb) != 0) {
  1874. DP(NETIF_MSG_TX_QUEUED, "SKB linearization failed - "
  1875. "silently dropping this SKB\n");
  1876. dev_kfree_skb_any(skb);
  1877. return NETDEV_TX_OK;
  1878. }
  1879. }
  1880. #endif
  1881. /*
  1882. Please read carefully. First we use one BD which we mark as start,
  1883. then we have a parsing info BD (used for TSO or xsum),
  1884. and only then we have the rest of the TSO BDs.
  1885. (don't forget to mark the last one as last,
  1886. and to unmap only AFTER you write to the BD ...)
  1887. And above all, all pdb sizes are in words - NOT DWORDS!
  1888. */
  1889. pkt_prod = fp->tx_pkt_prod++;
  1890. bd_prod = TX_BD(fp->tx_bd_prod);
  1891. /* get a tx_buf and first BD */
  1892. tx_buf = &fp->tx_buf_ring[TX_BD(pkt_prod)];
  1893. tx_start_bd = &fp->tx_desc_ring[bd_prod].start_bd;
  1894. tx_start_bd->bd_flags.as_bitfield = ETH_TX_BD_FLAGS_START_BD;
  1895. SET_FLAG(tx_start_bd->general_data, ETH_TX_START_BD_ETH_ADDR_TYPE,
  1896. mac_type);
  1897. /* header nbd */
  1898. SET_FLAG(tx_start_bd->general_data, ETH_TX_START_BD_HDR_NBDS, 1);
  1899. /* remember the first BD of the packet */
  1900. tx_buf->first_bd = fp->tx_bd_prod;
  1901. tx_buf->skb = skb;
  1902. tx_buf->flags = 0;
  1903. DP(NETIF_MSG_TX_QUEUED,
  1904. "sending pkt %u @%p next_idx %u bd %u @%p\n",
  1905. pkt_prod, tx_buf, fp->tx_pkt_prod, bd_prod, tx_start_bd);
  1906. if (vlan_tx_tag_present(skb)) {
  1907. tx_start_bd->vlan_or_ethertype =
  1908. cpu_to_le16(vlan_tx_tag_get(skb));
  1909. tx_start_bd->bd_flags.as_bitfield |=
  1910. (X_ETH_OUTBAND_VLAN << ETH_TX_BD_FLAGS_VLAN_MODE_SHIFT);
  1911. } else
  1912. tx_start_bd->vlan_or_ethertype = cpu_to_le16(pkt_prod);
  1913. /* turn on parsing and get a BD */
  1914. bd_prod = TX_BD(NEXT_TX_IDX(bd_prod));
  1915. if (xmit_type & XMIT_CSUM) {
  1916. tx_start_bd->bd_flags.as_bitfield |= ETH_TX_BD_FLAGS_L4_CSUM;
  1917. if (xmit_type & XMIT_CSUM_V4)
  1918. tx_start_bd->bd_flags.as_bitfield |=
  1919. ETH_TX_BD_FLAGS_IP_CSUM;
  1920. else
  1921. tx_start_bd->bd_flags.as_bitfield |=
  1922. ETH_TX_BD_FLAGS_IPV6;
  1923. if (!(xmit_type & XMIT_CSUM_TCP))
  1924. tx_start_bd->bd_flags.as_bitfield |=
  1925. ETH_TX_BD_FLAGS_IS_UDP;
  1926. }
  1927. if (CHIP_IS_E2(bp)) {
  1928. pbd_e2 = &fp->tx_desc_ring[bd_prod].parse_bd_e2;
  1929. memset(pbd_e2, 0, sizeof(struct eth_tx_parse_bd_e2));
  1930. /* Set PBD in checksum offload case */
  1931. if (xmit_type & XMIT_CSUM)
  1932. hlen = bnx2x_set_pbd_csum_e2(bp, skb,
  1933. &pbd_e2_parsing_data,
  1934. xmit_type);
  1935. } else {
  1936. pbd_e1x = &fp->tx_desc_ring[bd_prod].parse_bd_e1x;
  1937. memset(pbd_e1x, 0, sizeof(struct eth_tx_parse_bd_e1x));
  1938. /* Set PBD in checksum offload case */
  1939. if (xmit_type & XMIT_CSUM)
  1940. hlen = bnx2x_set_pbd_csum(bp, skb, pbd_e1x, xmit_type);
  1941. }
  1942. /* Map skb linear data for DMA */
  1943. mapping = dma_map_single(&bp->pdev->dev, skb->data,
  1944. skb_headlen(skb), DMA_TO_DEVICE);
  1945. /* Setup the data pointer of the first BD of the packet */
  1946. tx_start_bd->addr_hi = cpu_to_le32(U64_HI(mapping));
  1947. tx_start_bd->addr_lo = cpu_to_le32(U64_LO(mapping));
  1948. nbd = skb_shinfo(skb)->nr_frags + 2; /* start_bd + pbd + frags */
  1949. tx_start_bd->nbd = cpu_to_le16(nbd);
  1950. tx_start_bd->nbytes = cpu_to_le16(skb_headlen(skb));
  1951. pkt_size = tx_start_bd->nbytes;
  1952. DP(NETIF_MSG_TX_QUEUED, "first bd @%p addr (%x:%x) nbd %d"
  1953. " nbytes %d flags %x vlan %x\n",
  1954. tx_start_bd, tx_start_bd->addr_hi, tx_start_bd->addr_lo,
  1955. le16_to_cpu(tx_start_bd->nbd), le16_to_cpu(tx_start_bd->nbytes),
  1956. tx_start_bd->bd_flags.as_bitfield,
  1957. le16_to_cpu(tx_start_bd->vlan_or_ethertype));
  1958. if (xmit_type & XMIT_GSO) {
  1959. DP(NETIF_MSG_TX_QUEUED,
  1960. "TSO packet len %d hlen %d total len %d tso size %d\n",
  1961. skb->len, hlen, skb_headlen(skb),
  1962. skb_shinfo(skb)->gso_size);
  1963. tx_start_bd->bd_flags.as_bitfield |= ETH_TX_BD_FLAGS_SW_LSO;
  1964. if (unlikely(skb_headlen(skb) > hlen))
  1965. bd_prod = bnx2x_tx_split(bp, fp, tx_buf, &tx_start_bd,
  1966. hlen, bd_prod, ++nbd);
  1967. if (CHIP_IS_E2(bp))
  1968. bnx2x_set_pbd_gso_e2(skb, &pbd_e2_parsing_data,
  1969. xmit_type);
  1970. else
  1971. bnx2x_set_pbd_gso(skb, pbd_e1x, xmit_type);
  1972. }
  1973. /* Set the PBD's parsing_data field if not zero
  1974. * (for the chips newer than 57711).
  1975. */
  1976. if (pbd_e2_parsing_data)
  1977. pbd_e2->parsing_data = cpu_to_le32(pbd_e2_parsing_data);
  1978. tx_data_bd = (struct eth_tx_bd *)tx_start_bd;
  1979. /* Handle fragmented skb */
  1980. for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) {
  1981. skb_frag_t *frag = &skb_shinfo(skb)->frags[i];
  1982. bd_prod = TX_BD(NEXT_TX_IDX(bd_prod));
  1983. tx_data_bd = &fp->tx_desc_ring[bd_prod].reg_bd;
  1984. if (total_pkt_bd == NULL)
  1985. total_pkt_bd = &fp->tx_desc_ring[bd_prod].reg_bd;
  1986. mapping = dma_map_page(&bp->pdev->dev, frag->page,
  1987. frag->page_offset,
  1988. frag->size, DMA_TO_DEVICE);
  1989. tx_data_bd->addr_hi = cpu_to_le32(U64_HI(mapping));
  1990. tx_data_bd->addr_lo = cpu_to_le32(U64_LO(mapping));
  1991. tx_data_bd->nbytes = cpu_to_le16(frag->size);
  1992. le16_add_cpu(&pkt_size, frag->size);
  1993. DP(NETIF_MSG_TX_QUEUED,
  1994. "frag %d bd @%p addr (%x:%x) nbytes %d\n",
  1995. i, tx_data_bd, tx_data_bd->addr_hi, tx_data_bd->addr_lo,
  1996. le16_to_cpu(tx_data_bd->nbytes));
  1997. }
  1998. DP(NETIF_MSG_TX_QUEUED, "last bd @%p\n", tx_data_bd);
  1999. bd_prod = TX_BD(NEXT_TX_IDX(bd_prod));
  2000. /* now send a tx doorbell, counting the next BD
  2001. * if the packet contains or ends with it
  2002. */
  2003. if (TX_BD_POFF(bd_prod) < nbd)
  2004. nbd++;
  2005. if (total_pkt_bd != NULL)
  2006. total_pkt_bd->total_pkt_bytes = pkt_size;
  2007. if (pbd_e1x)
  2008. DP(NETIF_MSG_TX_QUEUED,
  2009. "PBD (E1X) @%p ip_data %x ip_hlen %u ip_id %u lso_mss %u"
  2010. " tcp_flags %x xsum %x seq %u hlen %u\n",
  2011. pbd_e1x, pbd_e1x->global_data, pbd_e1x->ip_hlen_w,
  2012. pbd_e1x->ip_id, pbd_e1x->lso_mss, pbd_e1x->tcp_flags,
  2013. pbd_e1x->tcp_pseudo_csum, pbd_e1x->tcp_send_seq,
  2014. le16_to_cpu(pbd_e1x->total_hlen_w));
  2015. if (pbd_e2)
  2016. DP(NETIF_MSG_TX_QUEUED,
  2017. "PBD (E2) @%p dst %x %x %x src %x %x %x parsing_data %x\n",
  2018. pbd_e2, pbd_e2->dst_mac_addr_hi, pbd_e2->dst_mac_addr_mid,
  2019. pbd_e2->dst_mac_addr_lo, pbd_e2->src_mac_addr_hi,
  2020. pbd_e2->src_mac_addr_mid, pbd_e2->src_mac_addr_lo,
  2021. pbd_e2->parsing_data);
  2022. DP(NETIF_MSG_TX_QUEUED, "doorbell: nbd %d bd %u\n", nbd, bd_prod);
  2023. /*
  2024. * Make sure that the BD data is updated before updating the producer
  2025. * since FW might read the BD right after the producer is updated.
  2026. * This is only applicable for weak-ordered memory model archs such
  2027. * as IA-64. The following barrier is also mandatory since FW will
  2028. * assumes packets must have BDs.
  2029. */
  2030. wmb();
  2031. fp->tx_db.data.prod += nbd;
  2032. barrier();
  2033. DOORBELL(bp, fp->cid, fp->tx_db.raw);
  2034. mmiowb();
  2035. fp->tx_bd_prod += nbd;
  2036. if (unlikely(bnx2x_tx_avail(fp) < MAX_SKB_FRAGS + 3)) {
  2037. netif_tx_stop_queue(txq);
  2038. /* paired memory barrier is in bnx2x_tx_int(), we have to keep
  2039. * ordering of set_bit() in netif_tx_stop_queue() and read of
  2040. * fp->bd_tx_cons */
  2041. smp_mb();
  2042. fp->eth_q_stats.driver_xoff++;
  2043. if (bnx2x_tx_avail(fp) >= MAX_SKB_FRAGS + 3)
  2044. netif_tx_wake_queue(txq);
  2045. }
  2046. fp->tx_pkt++;
  2047. return NETDEV_TX_OK;
  2048. }
  2049. /* called with rtnl_lock */
  2050. int bnx2x_change_mac_addr(struct net_device *dev, void *p)
  2051. {
  2052. struct sockaddr *addr = p;
  2053. struct bnx2x *bp = netdev_priv(dev);
  2054. if (!is_valid_ether_addr((u8 *)(addr->sa_data)))
  2055. return -EINVAL;
  2056. memcpy(dev->dev_addr, addr->sa_data, dev->addr_len);
  2057. if (netif_running(dev))
  2058. bnx2x_set_eth_mac(bp, 1);
  2059. return 0;
  2060. }
  2061. static void bnx2x_free_fp_mem_at(struct bnx2x *bp, int fp_index)
  2062. {
  2063. union host_hc_status_block *sb = &bnx2x_fp(bp, fp_index, status_blk);
  2064. struct bnx2x_fastpath *fp = &bp->fp[fp_index];
  2065. /* Common */
  2066. #ifdef BCM_CNIC
  2067. if (IS_FCOE_IDX(fp_index)) {
  2068. memset(sb, 0, sizeof(union host_hc_status_block));
  2069. fp->status_blk_mapping = 0;
  2070. } else {
  2071. #endif
  2072. /* status blocks */
  2073. if (CHIP_IS_E2(bp))
  2074. BNX2X_PCI_FREE(sb->e2_sb,
  2075. bnx2x_fp(bp, fp_index,
  2076. status_blk_mapping),
  2077. sizeof(struct host_hc_status_block_e2));
  2078. else
  2079. BNX2X_PCI_FREE(sb->e1x_sb,
  2080. bnx2x_fp(bp, fp_index,
  2081. status_blk_mapping),
  2082. sizeof(struct host_hc_status_block_e1x));
  2083. #ifdef BCM_CNIC
  2084. }
  2085. #endif
  2086. /* Rx */
  2087. if (!skip_rx_queue(bp, fp_index)) {
  2088. bnx2x_free_rx_bds(fp);
  2089. /* fastpath rx rings: rx_buf rx_desc rx_comp */
  2090. BNX2X_FREE(bnx2x_fp(bp, fp_index, rx_buf_ring));
  2091. BNX2X_PCI_FREE(bnx2x_fp(bp, fp_index, rx_desc_ring),
  2092. bnx2x_fp(bp, fp_index, rx_desc_mapping),
  2093. sizeof(struct eth_rx_bd) * NUM_RX_BD);
  2094. BNX2X_PCI_FREE(bnx2x_fp(bp, fp_index, rx_comp_ring),
  2095. bnx2x_fp(bp, fp_index, rx_comp_mapping),
  2096. sizeof(struct eth_fast_path_rx_cqe) *
  2097. NUM_RCQ_BD);
  2098. /* SGE ring */
  2099. BNX2X_FREE(bnx2x_fp(bp, fp_index, rx_page_ring));
  2100. BNX2X_PCI_FREE(bnx2x_fp(bp, fp_index, rx_sge_ring),
  2101. bnx2x_fp(bp, fp_index, rx_sge_mapping),
  2102. BCM_PAGE_SIZE * NUM_RX_SGE_PAGES);
  2103. }
  2104. /* Tx */
  2105. if (!skip_tx_queue(bp, fp_index)) {
  2106. /* fastpath tx rings: tx_buf tx_desc */
  2107. BNX2X_FREE(bnx2x_fp(bp, fp_index, tx_buf_ring));
  2108. BNX2X_PCI_FREE(bnx2x_fp(bp, fp_index, tx_desc_ring),
  2109. bnx2x_fp(bp, fp_index, tx_desc_mapping),
  2110. sizeof(union eth_tx_bd_types) * NUM_TX_BD);
  2111. }
  2112. /* end of fastpath */
  2113. }
  2114. void bnx2x_free_fp_mem(struct bnx2x *bp)
  2115. {
  2116. int i;
  2117. for_each_queue(bp, i)
  2118. bnx2x_free_fp_mem_at(bp, i);
  2119. }
  2120. static inline void set_sb_shortcuts(struct bnx2x *bp, int index)
  2121. {
  2122. union host_hc_status_block status_blk = bnx2x_fp(bp, index, status_blk);
  2123. if (CHIP_IS_E2(bp)) {
  2124. bnx2x_fp(bp, index, sb_index_values) =
  2125. (__le16 *)status_blk.e2_sb->sb.index_values;
  2126. bnx2x_fp(bp, index, sb_running_index) =
  2127. (__le16 *)status_blk.e2_sb->sb.running_index;
  2128. } else {
  2129. bnx2x_fp(bp, index, sb_index_values) =
  2130. (__le16 *)status_blk.e1x_sb->sb.index_values;
  2131. bnx2x_fp(bp, index, sb_running_index) =
  2132. (__le16 *)status_blk.e1x_sb->sb.running_index;
  2133. }
  2134. }
  2135. static int bnx2x_alloc_fp_mem_at(struct bnx2x *bp, int index)
  2136. {
  2137. union host_hc_status_block *sb;
  2138. struct bnx2x_fastpath *fp = &bp->fp[index];
  2139. int ring_size = 0;
  2140. /* if rx_ring_size specified - use it */
  2141. int rx_ring_size = bp->rx_ring_size ? bp->rx_ring_size :
  2142. MAX_RX_AVAIL/bp->num_queues;
  2143. /* allocate at least number of buffers required by FW */
  2144. rx_ring_size = max_t(int, fp->disable_tpa ? MIN_RX_SIZE_NONTPA :
  2145. MIN_RX_SIZE_TPA,
  2146. rx_ring_size);
  2147. bnx2x_fp(bp, index, bp) = bp;
  2148. bnx2x_fp(bp, index, index) = index;
  2149. /* Common */
  2150. sb = &bnx2x_fp(bp, index, status_blk);
  2151. #ifdef BCM_CNIC
  2152. if (!IS_FCOE_IDX(index)) {
  2153. #endif
  2154. /* status blocks */
  2155. if (CHIP_IS_E2(bp))
  2156. BNX2X_PCI_ALLOC(sb->e2_sb,
  2157. &bnx2x_fp(bp, index, status_blk_mapping),
  2158. sizeof(struct host_hc_status_block_e2));
  2159. else
  2160. BNX2X_PCI_ALLOC(sb->e1x_sb,
  2161. &bnx2x_fp(bp, index, status_blk_mapping),
  2162. sizeof(struct host_hc_status_block_e1x));
  2163. #ifdef BCM_CNIC
  2164. }
  2165. #endif
  2166. set_sb_shortcuts(bp, index);
  2167. /* Tx */
  2168. if (!skip_tx_queue(bp, index)) {
  2169. /* fastpath tx rings: tx_buf tx_desc */
  2170. BNX2X_ALLOC(bnx2x_fp(bp, index, tx_buf_ring),
  2171. sizeof(struct sw_tx_bd) * NUM_TX_BD);
  2172. BNX2X_PCI_ALLOC(bnx2x_fp(bp, index, tx_desc_ring),
  2173. &bnx2x_fp(bp, index, tx_desc_mapping),
  2174. sizeof(union eth_tx_bd_types) * NUM_TX_BD);
  2175. }
  2176. /* Rx */
  2177. if (!skip_rx_queue(bp, index)) {
  2178. /* fastpath rx rings: rx_buf rx_desc rx_comp */
  2179. BNX2X_ALLOC(bnx2x_fp(bp, index, rx_buf_ring),
  2180. sizeof(struct sw_rx_bd) * NUM_RX_BD);
  2181. BNX2X_PCI_ALLOC(bnx2x_fp(bp, index, rx_desc_ring),
  2182. &bnx2x_fp(bp, index, rx_desc_mapping),
  2183. sizeof(struct eth_rx_bd) * NUM_RX_BD);
  2184. BNX2X_PCI_ALLOC(bnx2x_fp(bp, index, rx_comp_ring),
  2185. &bnx2x_fp(bp, index, rx_comp_mapping),
  2186. sizeof(struct eth_fast_path_rx_cqe) *
  2187. NUM_RCQ_BD);
  2188. /* SGE ring */
  2189. BNX2X_ALLOC(bnx2x_fp(bp, index, rx_page_ring),
  2190. sizeof(struct sw_rx_page) * NUM_RX_SGE);
  2191. BNX2X_PCI_ALLOC(bnx2x_fp(bp, index, rx_sge_ring),
  2192. &bnx2x_fp(bp, index, rx_sge_mapping),
  2193. BCM_PAGE_SIZE * NUM_RX_SGE_PAGES);
  2194. /* RX BD ring */
  2195. bnx2x_set_next_page_rx_bd(fp);
  2196. /* CQ ring */
  2197. bnx2x_set_next_page_rx_cq(fp);
  2198. /* BDs */
  2199. ring_size = bnx2x_alloc_rx_bds(fp, rx_ring_size);
  2200. if (ring_size < rx_ring_size)
  2201. goto alloc_mem_err;
  2202. }
  2203. return 0;
  2204. /* handles low memory cases */
  2205. alloc_mem_err:
  2206. BNX2X_ERR("Unable to allocate full memory for queue %d (size %d)\n",
  2207. index, ring_size);
  2208. /* FW will drop all packets if queue is not big enough,
  2209. * In these cases we disable the queue
  2210. * Min size diferent for TPA and non-TPA queues
  2211. */
  2212. if (ring_size < (fp->disable_tpa ?
  2213. MIN_RX_SIZE_NONTPA : MIN_RX_SIZE_TPA)) {
  2214. /* release memory allocated for this queue */
  2215. bnx2x_free_fp_mem_at(bp, index);
  2216. return -ENOMEM;
  2217. }
  2218. return 0;
  2219. }
  2220. int bnx2x_alloc_fp_mem(struct bnx2x *bp)
  2221. {
  2222. int i;
  2223. /**
  2224. * 1. Allocate FP for leading - fatal if error
  2225. * 2. {CNIC} Allocate FCoE FP - fatal if error
  2226. * 3. Allocate RSS - fix number of queues if error
  2227. */
  2228. /* leading */
  2229. if (bnx2x_alloc_fp_mem_at(bp, 0))
  2230. return -ENOMEM;
  2231. #ifdef BCM_CNIC
  2232. /* FCoE */
  2233. if (bnx2x_alloc_fp_mem_at(bp, FCOE_IDX))
  2234. return -ENOMEM;
  2235. #endif
  2236. /* RSS */
  2237. for_each_nondefault_eth_queue(bp, i)
  2238. if (bnx2x_alloc_fp_mem_at(bp, i))
  2239. break;
  2240. /* handle memory failures */
  2241. if (i != BNX2X_NUM_ETH_QUEUES(bp)) {
  2242. int delta = BNX2X_NUM_ETH_QUEUES(bp) - i;
  2243. WARN_ON(delta < 0);
  2244. #ifdef BCM_CNIC
  2245. /**
  2246. * move non eth FPs next to last eth FP
  2247. * must be done in that order
  2248. * FCOE_IDX < FWD_IDX < OOO_IDX
  2249. */
  2250. /* move FCoE fp */
  2251. bnx2x_move_fp(bp, FCOE_IDX, FCOE_IDX - delta);
  2252. #endif
  2253. bp->num_queues -= delta;
  2254. BNX2X_ERR("Adjusted num of queues from %d to %d\n",
  2255. bp->num_queues + delta, bp->num_queues);
  2256. }
  2257. return 0;
  2258. }
  2259. static int bnx2x_setup_irqs(struct bnx2x *bp)
  2260. {
  2261. int rc = 0;
  2262. if (bp->flags & USING_MSIX_FLAG) {
  2263. rc = bnx2x_req_msix_irqs(bp);
  2264. if (rc)
  2265. return rc;
  2266. } else {
  2267. bnx2x_ack_int(bp);
  2268. rc = bnx2x_req_irq(bp);
  2269. if (rc) {
  2270. BNX2X_ERR("IRQ request failed rc %d, aborting\n", rc);
  2271. return rc;
  2272. }
  2273. if (bp->flags & USING_MSI_FLAG) {
  2274. bp->dev->irq = bp->pdev->irq;
  2275. netdev_info(bp->dev, "using MSI IRQ %d\n",
  2276. bp->pdev->irq);
  2277. }
  2278. }
  2279. return 0;
  2280. }
  2281. void bnx2x_free_mem_bp(struct bnx2x *bp)
  2282. {
  2283. kfree(bp->fp);
  2284. kfree(bp->msix_table);
  2285. kfree(bp->ilt);
  2286. }
  2287. int __devinit bnx2x_alloc_mem_bp(struct bnx2x *bp)
  2288. {
  2289. struct bnx2x_fastpath *fp;
  2290. struct msix_entry *tbl;
  2291. struct bnx2x_ilt *ilt;
  2292. /* fp array */
  2293. fp = kzalloc(L2_FP_COUNT(bp->l2_cid_count)*sizeof(*fp), GFP_KERNEL);
  2294. if (!fp)
  2295. goto alloc_err;
  2296. bp->fp = fp;
  2297. /* msix table */
  2298. tbl = kzalloc((FP_SB_COUNT(bp->l2_cid_count) + 1) * sizeof(*tbl),
  2299. GFP_KERNEL);
  2300. if (!tbl)
  2301. goto alloc_err;
  2302. bp->msix_table = tbl;
  2303. /* ilt */
  2304. ilt = kzalloc(sizeof(*ilt), GFP_KERNEL);
  2305. if (!ilt)
  2306. goto alloc_err;
  2307. bp->ilt = ilt;
  2308. return 0;
  2309. alloc_err:
  2310. bnx2x_free_mem_bp(bp);
  2311. return -ENOMEM;
  2312. }
  2313. static int bnx2x_reload_if_running(struct net_device *dev)
  2314. {
  2315. struct bnx2x *bp = netdev_priv(dev);
  2316. if (unlikely(!netif_running(dev)))
  2317. return 0;
  2318. bnx2x_nic_unload(bp, UNLOAD_NORMAL);
  2319. return bnx2x_nic_load(bp, LOAD_NORMAL);
  2320. }
  2321. /* called with rtnl_lock */
  2322. int bnx2x_change_mtu(struct net_device *dev, int new_mtu)
  2323. {
  2324. struct bnx2x *bp = netdev_priv(dev);
  2325. if (bp->recovery_state != BNX2X_RECOVERY_DONE) {
  2326. printk(KERN_ERR "Handling parity error recovery. Try again later\n");
  2327. return -EAGAIN;
  2328. }
  2329. if ((new_mtu > ETH_MAX_JUMBO_PACKET_SIZE) ||
  2330. ((new_mtu + ETH_HLEN) < ETH_MIN_PACKET_SIZE))
  2331. return -EINVAL;
  2332. /* This does not race with packet allocation
  2333. * because the actual alloc size is
  2334. * only updated as part of load
  2335. */
  2336. dev->mtu = new_mtu;
  2337. return bnx2x_reload_if_running(dev);
  2338. }
  2339. u32 bnx2x_fix_features(struct net_device *dev, u32 features)
  2340. {
  2341. struct bnx2x *bp = netdev_priv(dev);
  2342. /* TPA requires Rx CSUM offloading */
  2343. if (!(features & NETIF_F_RXCSUM) || bp->disable_tpa)
  2344. features &= ~NETIF_F_LRO;
  2345. return features;
  2346. }
  2347. int bnx2x_set_features(struct net_device *dev, u32 features)
  2348. {
  2349. struct bnx2x *bp = netdev_priv(dev);
  2350. u32 flags = bp->flags;
  2351. bool bnx2x_reload = false;
  2352. if (features & NETIF_F_LRO)
  2353. flags |= TPA_ENABLE_FLAG;
  2354. else
  2355. flags &= ~TPA_ENABLE_FLAG;
  2356. if (features & NETIF_F_LOOPBACK) {
  2357. if (bp->link_params.loopback_mode != LOOPBACK_BMAC) {
  2358. bp->link_params.loopback_mode = LOOPBACK_BMAC;
  2359. bnx2x_reload = true;
  2360. }
  2361. } else {
  2362. if (bp->link_params.loopback_mode != LOOPBACK_NONE) {
  2363. bp->link_params.loopback_mode = LOOPBACK_NONE;
  2364. bnx2x_reload = true;
  2365. }
  2366. }
  2367. if (flags ^ bp->flags) {
  2368. bp->flags = flags;
  2369. bnx2x_reload = true;
  2370. }
  2371. if (bnx2x_reload) {
  2372. if (bp->recovery_state == BNX2X_RECOVERY_DONE)
  2373. return bnx2x_reload_if_running(dev);
  2374. /* else: bnx2x_nic_load() will be called at end of recovery */
  2375. }
  2376. return 0;
  2377. }
  2378. void bnx2x_tx_timeout(struct net_device *dev)
  2379. {
  2380. struct bnx2x *bp = netdev_priv(dev);
  2381. #ifdef BNX2X_STOP_ON_ERROR
  2382. if (!bp->panic)
  2383. bnx2x_panic();
  2384. #endif
  2385. /* This allows the netif to be shutdown gracefully before resetting */
  2386. schedule_delayed_work(&bp->reset_task, 0);
  2387. }
  2388. int bnx2x_suspend(struct pci_dev *pdev, pm_message_t state)
  2389. {
  2390. struct net_device *dev = pci_get_drvdata(pdev);
  2391. struct bnx2x *bp;
  2392. if (!dev) {
  2393. dev_err(&pdev->dev, "BAD net device from bnx2x_init_one\n");
  2394. return -ENODEV;
  2395. }
  2396. bp = netdev_priv(dev);
  2397. rtnl_lock();
  2398. pci_save_state(pdev);
  2399. if (!netif_running(dev)) {
  2400. rtnl_unlock();
  2401. return 0;
  2402. }
  2403. netif_device_detach(dev);
  2404. bnx2x_nic_unload(bp, UNLOAD_CLOSE);
  2405. bnx2x_set_power_state(bp, pci_choose_state(pdev, state));
  2406. rtnl_unlock();
  2407. return 0;
  2408. }
  2409. int bnx2x_resume(struct pci_dev *pdev)
  2410. {
  2411. struct net_device *dev = pci_get_drvdata(pdev);
  2412. struct bnx2x *bp;
  2413. int rc;
  2414. if (!dev) {
  2415. dev_err(&pdev->dev, "BAD net device from bnx2x_init_one\n");
  2416. return -ENODEV;
  2417. }
  2418. bp = netdev_priv(dev);
  2419. if (bp->recovery_state != BNX2X_RECOVERY_DONE) {
  2420. printk(KERN_ERR "Handling parity error recovery. Try again later\n");
  2421. return -EAGAIN;
  2422. }
  2423. rtnl_lock();
  2424. pci_restore_state(pdev);
  2425. if (!netif_running(dev)) {
  2426. rtnl_unlock();
  2427. return 0;
  2428. }
  2429. bnx2x_set_power_state(bp, PCI_D0);
  2430. netif_device_attach(dev);
  2431. /* Since the chip was reset, clear the FW sequence number */
  2432. bp->fw_seq = 0;
  2433. rc = bnx2x_nic_load(bp, LOAD_OPEN);
  2434. rtnl_unlock();
  2435. return rc;
  2436. }